From 8cbbf57174c42f2c543f11a06a0e3e6891eb34f6 Mon Sep 17 00:00:00 2001 From: Yoahoug Date: Sat, 3 Jan 2026 22:03:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=8D=E6=AC=A1=E4=BF=AE=E5=A4=8Dkiro=20400?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E7=94=A8=E5=8D=A0=E4=BD=8D=E7=AC=A6?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=8E=86=E5=8F=B2=E4=BF=A1=E6=81=AF=E4=B8=AD?= =?UTF-8?q?=E7=9A=84image=EF=BC=8C=E7=BC=A9=E5=B0=8F=E5=8C=85=E4=BD=93?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/claude/claude-kiro.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/claude/claude-kiro.js b/src/claude/claude-kiro.js index eaf8c91..73c165e 100644 --- a/src/claude/claude-kiro.js +++ b/src/claude/claude-kiro.js @@ -668,7 +668,7 @@ async initializeAuth(forceRefresh = false) { modelId: codewhispererModel, origin: KIRO_CONSTANTS.ORIGIN_AI_EDITOR }; - let images = []; + let imageCount = 0; let toolResults = []; if (Array.isArray(message.content)) { @@ -682,22 +682,24 @@ async initializeAuth(forceRefresh = false) { toolUseId: part.tool_use_id }); } else if (part.type === 'image') { - images.push({ - format: part.source.media_type.split('/')[1], - source: { - bytes: part.source.data - } - }); + // 历史消息中的图片不保留 base64 数据,只记录数量 + // 避免请求体过大导致 400 错误 + imageCount++; } } } else { userInputMessage.content = this.getContentText(message); } - // 只添加非空字段,API 不接受空数组或空对象 - if (images.length > 0) { - userInputMessage.images = images; + // 如果历史消息中有图片,添加占位符说明 + if (imageCount > 0) { + const imagePlaceholder = `[此消息包含 ${imageCount} 张图片,已在历史记录中省略]`; + userInputMessage.content = userInputMessage.content + ? `${userInputMessage.content}\n${imagePlaceholder}` + : imagePlaceholder; + console.log(`[Kiro] Replaced ${imageCount} image(s) with placeholder in history message`); } + if (toolResults.length > 0) { // 去重 toolResults - Kiro API 不接受重复的 toolUseId const uniqueToolResults = [];