{"record":{"id":"9956f34db8141946","repo":"linshenkx/prompt-optimizer","slug":"model-is-not-enabled-9956f3","errorCode":null,"errorMessage":"Model is not enabled","messagePattern":"Model is not enabled","errorType":"validation","errorClass":"RequestConfigError","httpStatus":null,"severity":"warning","filePath":"packages/core/src/services/llm/service.ts","lineNumber":75,"sourceCode":"   * 验证模型配置\n   */\n  private validateModelConfig(\n    modelConfig: TextModelConfig,\n    options: { allowDisabled?: boolean } = {}\n  ): void {\n    if (!modelConfig) {\n      throw new RequestConfigError('Model config cannot be empty');\n    }\n    if (!modelConfig.providerMeta || !modelConfig.providerMeta.id) {\n      throw new RequestConfigError('Model provider metadata cannot be empty');\n    }\n    if (!modelConfig.modelMeta || !modelConfig.modelMeta.id) {\n      throw new RequestConfigError('Model metadata cannot be empty');\n    }\n    // Default behavior: disabled models cannot be used for normal requests.\n    // Connection testing is allowed to bypass this check (align with image model test behavior).\n    if (!options.allowDisabled && !modelConfig.enabled) {\n      throw new RequestConfigError('Model is not enabled');\n    }\n  }\n\n  /**\n   * 发送消息（结构化格式）\n   */\n  async sendMessageStructured(messages: Message[], provider: string): Promise<LLMResponse> {\n    try {\n      if (!provider) {\n        throw new RequestConfigError('Model provider cannot be empty');\n      }\n\n      const modelConfig = await this.modelManager.getModel(provider);\n      if (!modelConfig) {\n        throw new RequestConfigError(`Model ${provider} not found`);\n      }\n\n      this.validateModelConfig(modelConfig);","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/llm/service.ts#L57-L93","documentation":"Thrown by validateModelConfig when the model config is not enabled, unless the caller passes { allowDisabled: true }. Disabled models are deliberately blocked from normal requests so users don't accidentally hit deactivated providers; only connection testing bypasses the check.","triggerScenarios":"Calling sendMessageStructured, sendMessageStream, or sendMessageStreamWithTools on a model whose config.enabled is false (or undefined, which is falsy). testConnection does not throw this because it calls validateModelConfig with allowDisabled: true.","commonSituations":"User disabled a provider in the settings UI but a chat session still references it; a persisted config where the enabled flag defaults to false; toggling a model off while background jobs still use its id.","solutions":["Enable the model in your model manager / settings before sending messages (config.enabled = true)","If the disabled state is unexpected, inspect the stored config to see why enabled is false or missing","Ensure new model configs are created with enabled explicitly set to true when they should be usable"],"exampleFix":"// before\nawait modelManager.updateModel('openai', { enabled: false });\nawait llmService.sendMessageStream(msgs, 'openai', onChunk); // throws\n\n// after\nawait modelManager.updateModel('openai', { enabled: true });\nawait llmService.sendMessageStream(msgs, 'openai', onChunk);","handlingStrategy":"validation","validationCode":"const cfg = await modelManager.getModel(provider);\nif (!cfg?.enabled) {\n  await modelManager.updateModel(provider, { enabled: true }); // or block the send\n}","typeGuard":"const isEnabledModel = (c?: ModelConfig | null): c is ModelConfig => !!c && c.enabled === true;","tryCatchPattern":"catch (e) { if (e instanceof RequestConfigError && e.message === 'Model is not enabled') { promptUserToEnable(provider); } }","preventionTips":["Check config.enabled before sending; surface disabled state in the UI","Persist sessions with a fallback model in case the primary is disabled","Use testConnection(provider) for health checks — it tolerates disabled models"],"tags":["llm","configuration","disabled-model","feature-flag"],"backgroundTag":"feature-not-enabled","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}