{"record":{"id":"58209ce504024963","repo":"linshenkx/prompt-optimizer","slug":"image-at-index-index-is-invalid","errorCode":null,"errorMessage":"Image at index ${index} is invalid","messagePattern":"Image at index (.+?) is invalid","errorType":"validation","errorClass":"RequestConfigError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/llm/adapters/abstract-adapter.ts","lineNumber":217,"sourceCode":"    }\n  }\n\n  protected validateImageUnderstandingRequest(request: ImageUnderstandingRequest): void {\n    if (!request || typeof request !== 'object') {\n      throw new RequestConfigError('Image understanding request cannot be empty')\n    }\n\n    if (typeof request.userPrompt !== 'string' || !request.userPrompt.trim()) {\n      throw new RequestConfigError('Image understanding user prompt cannot be empty')\n    }\n\n    if (!Array.isArray(request.images) || request.images.length === 0) {\n      throw new RequestConfigError('Image understanding request requires at least one image')\n    }\n\n    request.images.forEach((image, index) => {\n      if (!image || typeof image !== 'object') {\n        throw new RequestConfigError(`Image at index ${index} is invalid`)\n      }\n\n      if (typeof image.b64 !== 'string' || !image.b64.trim()) {\n        throw new RequestConfigError(`Image at index ${index} is missing base64 data`)\n      }\n    })\n  }\n\n  // ===== 工具方法 =====\n\n  /**\n   * 处理<think>标签，分离推理内容和主要内容\n   * 从现有service.ts中的processStreamContentWithThinkTags逻辑迁移\n   *\n   * @param content 原始内容\n   * @returns 处理后的结果 {content: 主要内容, reasoning?: 推理内容}\n   */\n  protected processThinkTags(content: string): { content: string; reasoning?: string } {","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/llm/adapters/abstract-adapter.ts#L199-L235","documentation":"Thrown by validateImageUnderstandingRequest during per-image validation when images[index] is null/undefined or not an object. Each element must be an image object (with a b64 field); primitives or holes in the array are rejected. Client-side RequestConfigError including the offending index.","triggerScenarios":"An array containing null, undefined, a string, or a number, e.g. images: [base64String] (a bare string instead of { b64 }), or sparse arrays from forEach/map chains.","commonSituations":"Passing raw base64 strings directly as array elements instead of wrapping in { b64 } objects; JSON payloads with null entries; map over failed uploads returning undefined.","solutions":["Wrap each raw base64 string: images.map(b64 => ({ b64 }))","Filter out null/undefined entries before calling: images.filter(Boolean)","Add a type guard isImageInput to validate each element before the call"],"exampleFix":"// before\nimages: [base64String]\n\n// after\nimages: [{ b64: base64String }]","handlingStrategy":"validation","validationCode":"const images = request.images.filter(i => i && typeof i === 'object')\nif (images.length === 0) throw new Error('no valid images')","typeGuard":"function isImageInput(i: unknown): i is { b64: string } {\n  return !!i && typeof i === 'object' && typeof (i as { b64: string }).b64 === 'string'\n}","tryCatchPattern":"null","preventionTips":["Wrap raw base64 strings in { b64 } objects","filter(Boolean) on image arrays built from upload results"],"tags":["validation","image-understanding","type-mismatch"],"backgroundTag":"invalid-image-entry","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}