{"record":{"id":"5bed2782c52b1222","repo":"linshenkx/prompt-optimizer","slug":"image-understanding-service-is-not-initialized","errorCode":null,"errorMessage":"Image understanding service is not initialized","messagePattern":"Image understanding service is not initialized","errorType":"exception","errorClass":"ServiceDependencyError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/prompt/service.ts","lineNumber":887,"sourceCode":"\n    message = message.replace(\n      /data:image\\/[a-z0-9.+-]+;base64,[a-z0-9+/=]+/gi,\n      \"[redacted-image]\",\n    );\n\n    for (const image of inputImages) {\n      const rawB64 = image.b64.trim();\n      if (rawB64 && message.includes(rawB64)) {\n        message = message.split(rawB64).join(\"[redacted-image]\");\n      }\n    }\n\n    return message;\n  }\n\n  private requireImageUnderstandingService(): IImageUnderstandingService {\n    if (!this.imageUnderstandingService) {\n      throw new ServiceDependencyError(\n        \"ImageUnderstandingService\",\n        \"Image understanding service is not initialized\",\n      );\n    }\n    return this.imageUnderstandingService;\n  }\n\n  private buildInputImagesManifest(request: OptimizationRequest): string {\n    if (!this.hasInputImages(request)) {\n      return \"[]\";\n    }\n\n    return JSON.stringify(\n      request.inputImages.map((image, index) => ({\n        index: index + 1,\n        label: `Image ${index + 1}`,\n        mimeType: image.mimeType || \"image/png\",\n      })),","sourceCodeStart":869,"sourceCodeEnd":905,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/prompt/service.ts#L869-L905","documentation":"The prompt service needs an injected IImageUnderstandingService for image/vision workflows; requireImageUnderstandingService throws ServiceDependencyError when it was never initialized. Any path that touches image understanding (optimization with inputImages, testPromptStream with images) goes through this guard.","triggerScenarios":"Calling optimizePrompt/optimizePromptStream with inputImages, or testPromptStream with image content, when the PromptService was constructed without calling the image understanding service initializer/setter.","commonSituations":"DI container wiring forgot to register the image service; running in a minimal/embedded environment where vision support is intentionally not bundled; upgrading to a version where the service must be registered explicitly.","solutions":["Initialize/register the image understanding service on PromptService before making image calls","If running a custom DI setup, verify the IImageUnderstandingService binding exists and is resolved","Gate image features in your UI until the service is confirmed available"],"exampleFix":"// before\nconst svc = new PromptService({ modelManager, templateManager });\nawait svc.optimizePrompt({ targetPrompt, modelKey, inputImages: [blob] });\n\n// after\nconst svc = new PromptService({ modelManager, templateManager, imageUnderstandingService });\nawait svc.optimizePrompt({ targetPrompt, modelKey, inputImages: [blob] });","handlingStrategy":"type-guard","validationCode":"if (!('imageUnderstandingService' in svc) || !svc.imageUnderstandingService) {\n  // skip image features or initialize service first\n}","typeGuard":"const canProcessImages = (svc: PromptService): boolean =>\n  svc.imageUnderstandingService != null;","tryCatchPattern":"try {\n  await svc.optimizePrompt({ ...req, inputImages });\n} catch (e) {\n  if (e instanceof ServiceDependencyError && e.service === 'ImageUnderstandingService') {\n    // hide image upload UI / initialize the service\n  } else throw e;\n}","preventionTips":["Register all dependent services during DI container setup","Feature-detect image support before showing upload controls","Fail fast at startup if vision features are required"],"tags":["dependency-injection","service-initialization","vision"],"backgroundTag":"service-not-initialized","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}