[PR #93] [MERGED] fix: 修复 Kiro API currentMessage 必须为 userInputMessage 类型的问题 #257

Closed
opened 2026-02-27 07:18:43 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/justlovemaki/AIClient-2-API/pull/93
Author: @MicoMiOvO
Created: 12/3/2025
Status: Merged
Merged: 12/3/2025
Merged by: @justlovemaki

Base: mainHead: main


📝 Commits (4)

  • 826e6ba fix: Kiro API currentMessage must be userInputMessage type
  • 26b5091 fix: remove null/empty values from Kiro API request
  • c4a1d0a feat: implement real streaming for Kiro API using AWS Event Stream
  • dcfa9e9 perf: optimize stream parsing to avoid duplicates and improve efficiency

📊 Changes

1 file changed (+331 additions, -73 deletions)

View changed files

📝 src/claude/claude-kiro.js (+331 -73)

📄 Description

问题描述

当对话中最后一条消息来自 assistant 角色时,buildCodewhispererRequest 方法会错误地将 assistantResponseMessage 作为 currentMessage 构建请求。

这会导致 Amazon CodeWhisperer API 返回 400 Bad Request 错误:
{ "message": "Improperly formed request.", "reason": null }## 根本原因

CodeWhisperer API 要求 currentMessage 必须是 userInputMessage 类型。之前的实现在最后一条消息是 assistant 时,会将 currentMessage 设置为 assistantResponseMessage,这不是有效的请求格式。

解决方案

当最后一条消息来自 assistant 角色时:

  1. 将该 assistant 消息移入 history 数组
  2. 创建一个内容为 "Continue" 的 userInputMessage 作为 currentMessage

这确保了 currentMessage 始终是有效的 userInputMessage 类型,符合 API 的要求。

修改内容

  • 修改了 src/claude/claude-kiro.js 中的 buildCodewhispererRequest() 方法
  • 添加了处理对话末尾 assistant 消息的逻辑
  • 确保 currentMessage 始终为 userInputMessage 类型

测试

  • 已测试以 assistant 消息结尾的对话场景
  • 验证 400 Bad Request 错误不再出现

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/justlovemaki/AIClient-2-API/pull/93 **Author:** [@MicoMiOvO](https://github.com/MicoMiOvO) **Created:** 12/3/2025 **Status:** ✅ Merged **Merged:** 12/3/2025 **Merged by:** [@justlovemaki](https://github.com/justlovemaki) **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (4) - [`826e6ba`](https://github.com/justlovemaki/AIClient-2-API/commit/826e6bad90b0049f7c0acf00707e58fa960dc69f) fix: Kiro API currentMessage must be userInputMessage type - [`26b5091`](https://github.com/justlovemaki/AIClient-2-API/commit/26b509173d027e6fd163d5fe3fef166214ceacb7) fix: remove null/empty values from Kiro API request - [`c4a1d0a`](https://github.com/justlovemaki/AIClient-2-API/commit/c4a1d0a0c0ee8ab96593cce056a3cf315b2dc789) feat: implement real streaming for Kiro API using AWS Event Stream - [`dcfa9e9`](https://github.com/justlovemaki/AIClient-2-API/commit/dcfa9e9a3b9444d67f92e1272edfa1697f1c7e4d) perf: optimize stream parsing to avoid duplicates and improve efficiency ### 📊 Changes **1 file changed** (+331 additions, -73 deletions) <details> <summary>View changed files</summary> 📝 `src/claude/claude-kiro.js` (+331 -73) </details> ### 📄 Description ## 问题描述 当对话中最后一条消息来自 `assistant` 角色时,`buildCodewhispererRequest` 方法会错误地将 `assistantResponseMessage` 作为 `currentMessage` 构建请求。 这会导致 Amazon CodeWhisperer API 返回 **400 Bad Request** 错误: { "message": "Improperly formed request.", "reason": null }## 根本原因 CodeWhisperer API 要求 `currentMessage` 必须是 `userInputMessage` 类型。之前的实现在最后一条消息是 assistant 时,会将 `currentMessage` 设置为 `assistantResponseMessage`,这不是有效的请求格式。 ## 解决方案 当最后一条消息来自 `assistant` 角色时: 1. 将该 assistant 消息移入 `history` 数组 2. 创建一个内容为 "Continue" 的 `userInputMessage` 作为 `currentMessage` 这确保了 `currentMessage` 始终是有效的 `userInputMessage` 类型,符合 API 的要求。 ## 修改内容 - 修改了 `src/claude/claude-kiro.js` 中的 `buildCodewhispererRequest()` 方法 - 添加了处理对话末尾 assistant 消息的逻辑 - 确保 `currentMessage` 始终为 `userInputMessage` 类型 ## 测试 - 已测试以 assistant 消息结尾的对话场景 - 验证 400 Bad Request 错误不再出现 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 07:18:43 +03:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/AIClient-2-API-justlovemaki#257
No description provided.