{"record":{"id":"5ba66d1c6110b2cf","repo":"linshenkx/prompt-optimizer","slug":"config-not-found","errorCode":"CONFIG_NOT_FOUND","errorMessage":"CONFIG_NOT_FOUND","messagePattern":"CONFIG_NOT_FOUND","errorType":"error_code","errorClass":"ImageError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/image/service.ts","lineNumber":91,"sourceCode":"    await this.validateText2ImageRequest(text2image)\n  }\n\n  async validateText2ImageRequest(request: Text2ImageRequest): Promise<void> {\n    // 显式文生图：不允许携带 inputImage（即使调用方用 any 绕过类型）\n    const unsafeInputImage = (request as unknown as { inputImage?: unknown }).inputImage\n    const unsafeInputImages = (request as unknown as { inputImages?: unknown }).inputImages\n    if (unsafeInputImage !== undefined && unsafeInputImage !== null) {\n      throw new ImageError(IMAGE_ERROR_CODES.TEXT2IMAGE_INPUT_IMAGE_NOT_ALLOWED)\n    }\n    if (Array.isArray(unsafeInputImages) && unsafeInputImages.length > 0) {\n      throw new ImageError(IMAGE_ERROR_CODES.TEXT2IMAGE_INPUT_IMAGE_NOT_ALLOWED)\n    }\n\n    await this.validateBaseRequest(request)\n\n    const config = await this.imageModelManager.getConfig(request.configId)\n    if (!config) {\n      throw new ImageError(IMAGE_ERROR_CODES.CONFIG_NOT_FOUND, undefined, { configId: request.configId })\n    }\n\n    // 能力校验：优先使用 config.model（动态/自定义模型），静态列表作为兜底\n    const configModel = config.model\n    const staticModels = this.registry.getStaticModels(config.providerId)\n    const staticModel = staticModels.find(m => m.id === config.modelId)\n    const capabilities = configModel?.capabilities ?? staticModel?.capabilities\n    const modelName = configModel?.name ?? staticModel?.name ?? config.modelId\n\n    if (capabilities && !capabilities.text2image) {\n      // 对于仅支持图生图的模型，给出更明确指引\n      if (capabilities.image2image) {\n        throw new ImageError(IMAGE_ERROR_CODES.MODEL_ONLY_SUPPORTS_IMAGE2IMAGE_NEED_INPUT, undefined, { modelName })\n      }\n      throw new ImageError(IMAGE_ERROR_CODES.MODEL_NOT_SUPPORT_TEXT2IMAGE, undefined, { modelName })\n    }\n  }\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/image/service.ts#L73-L109","documentation":"After base validation passes, validateText2ImageRequest looks up the model config by request.configId via imageModelManager.getConfig. A missing (deleted or never-created) config throws CONFIG_NOT_FOUND with the configId attached.","triggerScenarios":"Calling generateText2Image with a configId that does not exist in the manager: deleted config, typo/uuid mismatch, stale configId persisted in user state after a config was removed, or manager not yet initialized.","commonSituations":"User deleted the model config but the UI still holds the old selection; configId persisted in localStorage/DB from a previous install; race where generate is called before ensureInitialized completes; environment mismatch (configs stored per-profile).","solutions":["List existing configs via imageModelManager and use a valid configId","Refresh the config picker in the UI when a config-delete event fires","Call ensureInitialized() on the manager before first generate","If the stale id came from persisted state, clear it and prompt re-selection"],"exampleFix":"// before\nawait service.generateText2Image({ configId: savedConfigId, prompt })\n\n// after\nconst config = await manager.getConfig(savedConfigId)\nif (!config) throw new Error(`Config ${savedConfigId} no longer exists — re-select a model`)\nawait service.generateText2Image({ configId: config.id, prompt })","handlingStrategy":"validation","validationCode":"const config = await imageModelManager.getConfig(request.configId)\nif (!config) {\n  throw new Error(`Model config ${request.configId} not found — re-select a model`)\n}\nawait service.generateText2Image(request)","typeGuard":null,"tryCatchPattern":"try {\n  await service.generateText2Image(request)\n} catch (e) {\n  if (e instanceof ImageError && e.code === IMAGE_ERROR_CODES.CONFIG_NOT_FOUND) {\n    await refreshConfigList(); promptReselect(); return\n  }\n  throw e\n}","preventionTips":["Call ensureInitialized() on the model manager before the first generate","Invalidate persisted configId selections when configs are deleted","Show config names (not raw ids) in the UI so stale selections are obvious"],"tags":["config-not-found","config-id","validation","image-generation"],"backgroundTag":"entity-not-found","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}