{"record":{"id":"29735ac74aa99ec5","repo":"linshenkx/prompt-optimizer","slug":"image-at-index-index-is-missing-base64-data","errorCode":null,"errorMessage":"Image at index ${index} is missing base64 data","messagePattern":"Image at index (.+?) is missing base64 data","errorType":"validation","errorClass":"RequestConfigError","httpStatus":null,"severity":"error","filePath":"packages/core/src/services/llm/adapters/abstract-adapter.ts","lineNumber":221,"sourceCode":"    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 } {\n    // 如果内容不包含think标签，直接返回\n    if (!content.includes('<think>')) {\n      return { content }\n    }","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/core/src/services/llm/adapters/abstract-adapter.ts#L203-L239","documentation":"Thrown by validateImageUnderstandingRequest when an image object's b64 field is not a string or is empty/whitespace-only. The adapter requires actual base64 image data for each entry; missing data means the request cannot be encoded. Client-side RequestConfigError that names the failing index.","triggerScenarios":"images[i].b64 is undefined, '', '   ', or a Buffer/Uint8Array instead of a base64 string; reading the wrong property name (base64, data) from an upload result.","commonSituations":"File-read step failed silently and b64 was never set; property name mismatch with backend response (data vs b64); passing a Buffer without .toString('base64').","solutions":["Convert Buffers/ArrayBuffers explicitly: buffer.toString('base64')","Verify the property name is exactly b64 and that file reading succeeded before building the image object","Filter/validate entries with a guard checking typeof b64 === 'string' && b64.trim().length > 0"],"exampleFix":"// before\nimages: [{ b64: fileBuffer }]\n\n// after\nimages: [{ b64: fileBuffer.toString('base64') }]","handlingStrategy":"validation","validationCode":"const images = request.images\n  .filter(i => i && typeof i.b64 === 'string' && i.b64.trim().length > 0)\nif (images.length === 0) throw new Error('no images with data')","typeGuard":"function hasB64Data(i: unknown): i is { b64: string } {\n  return !!i && typeof i === 'object'\n    && typeof (i as { b64: string }).b64 === 'string'\n    && (i as { b64: string }).b64.trim().length > 0\n}","tryCatchPattern":"null","preventionTips":["Convert Buffer/Uint8Array with .toString('base64') before assigning b64","Verify file reads succeeded before building image entries","Confirm the property name is exactly b64"],"tags":["validation","image-understanding","base64"],"backgroundTag":"missing-base64-data","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}