[PR #94] [MERGED] fix: 修复 Kiro API 工具调用和流式传输问题 #259

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/94
Author: @MicoMiOvO
Created: 12/3/2025
Status: Merged
Merged: 12/3/2025
Merged by: @justlovemaki

Base: mainHead: main


📝 Commits (10+)

  • 11094f8 fix: remove content deduplication to fix token counting and display
  • 01bc3d4 fix: correct tool calls parsing for streaming - support structured and bracket formats
  • f010267 fix: ensure content is never empty when sending toolResults
  • 6528797 fix: only include history when non-empty
  • f20d860 fix: tools calling failed due to nested JSON parsing
  • 4562af2 fix: skip AWS Event Stream binary headers when parsing JSON
  • 80f8ed7 fix: filter duplicate consecutive content events from Kiro stream
  • cfb41e6 fix: handle multi-part toolUse events (input/stop sent separately)
  • 7b767eb fix: deduplicate toolResults to avoid Kiro API validation error
  • 5cce0a6 fix: merge toolUse events with same toolUseId instead of creating separate blocks

📊 Changes

1 file changed (+211 additions, -35 deletions)

View changed files

📝 src/claude/claude-kiro.js (+211 -35)

📄 Description

概要

修复 Kiro API 集成中工具调用和流式传输的多个问题。

更改内容

工具调用修复

  • 修复嵌套 JSON 解析 - 正确处理包含嵌套对象的 tool_use input,如 {"input":{"path":"..."}}
  • 跳过 AWS Event Stream 二进制头部 - 只搜索有效的 JSON payload 模式({"content":, {"name": 等),避免解析二进制头部字节
  • 处理多部分 toolUse 事件 - Kiro API 分多次发送工具 input(input/stop 分开发送),现在正确累积它们
  • 合并相同 toolUseId 的 toolUse 事件 - 不再为每个 input 片段创建单独的 content block,而是合并为一个 tool_use block
  • 去重 toolResults - 防止 toolResults 中重复的 toolUseId 导致 Kiro API 验证错误

流式传输修复

  • 过滤重复的连续 content 事件 - Kiro API 有时会重复发送相同内容,现已过滤

资源管理

  • 正确关闭流 - 添加 finally 块确保出错或完成时销毁流
  • 限制连接池 - 配置 HTTP/HTTPS agent 的 maxSocketsmaxFreeSockets 防止资源泄漏

测试

  • 使用包含 tools 定义的 curl 命令测试
  • 验证 tool_use block 输出正确合并
  • 验证工具参数(file_path, content)被正确解析

🔄 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/94 **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 (10+) - [`11094f8`](https://github.com/justlovemaki/AIClient-2-API/commit/11094f84c51131be0d5585df1ab00fac6d82d825) fix: remove content deduplication to fix token counting and display - [`01bc3d4`](https://github.com/justlovemaki/AIClient-2-API/commit/01bc3d4b88edbcd0079c84ac5b92c4beeb7349df) fix: correct tool calls parsing for streaming - support structured and bracket formats - [`f010267`](https://github.com/justlovemaki/AIClient-2-API/commit/f0102673f923970b89a2f07091dd3d7b3a11767a) fix: ensure content is never empty when sending toolResults - [`6528797`](https://github.com/justlovemaki/AIClient-2-API/commit/652879712adcf2a491061b36ed8de98e190068d7) fix: only include history when non-empty - [`f20d860`](https://github.com/justlovemaki/AIClient-2-API/commit/f20d86037ff8d75304b1d3e2a6489f6941e93b6f) fix: tools calling failed due to nested JSON parsing - [`4562af2`](https://github.com/justlovemaki/AIClient-2-API/commit/4562af27819744ab7280b857b6a4c16c694f7a0b) fix: skip AWS Event Stream binary headers when parsing JSON - [`80f8ed7`](https://github.com/justlovemaki/AIClient-2-API/commit/80f8ed74733b52a2c6c1f60df4208b55cc9b18fd) fix: filter duplicate consecutive content events from Kiro stream - [`cfb41e6`](https://github.com/justlovemaki/AIClient-2-API/commit/cfb41e63e9ecc6009eb7e4e7633878f01b3558e6) fix: handle multi-part toolUse events (input/stop sent separately) - [`7b767eb`](https://github.com/justlovemaki/AIClient-2-API/commit/7b767ebd805903a37c4a0a87d4e5a25d76150545) fix: deduplicate toolResults to avoid Kiro API validation error - [`5cce0a6`](https://github.com/justlovemaki/AIClient-2-API/commit/5cce0a6767685ea8af2682fc0fb97d1cfd3c3ef2) fix: merge toolUse events with same toolUseId instead of creating separate blocks ### 📊 Changes **1 file changed** (+211 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `src/claude/claude-kiro.js` (+211 -35) </details> ### 📄 Description ## 概要 修复 Kiro API 集成中工具调用和流式传输的多个问题。 ## 更改内容 ### 工具调用修复 - **修复嵌套 JSON 解析** - 正确处理包含嵌套对象的 tool_use input,如 `{"input":{"path":"..."}}` - **跳过 AWS Event Stream 二进制头部** - 只搜索有效的 JSON payload 模式(`{"content":`, `{"name":` 等),避免解析二进制头部字节 - **处理多部分 toolUse 事件** - Kiro API 分多次发送工具 input(input/stop 分开发送),现在正确累积它们 - **合并相同 toolUseId 的 toolUse 事件** - 不再为每个 input 片段创建单独的 content block,而是合并为一个 tool_use block - **去重 toolResults** - 防止 toolResults 中重复的 toolUseId 导致 Kiro API 验证错误 ### 流式传输修复 - **过滤重复的连续 content 事件** - Kiro API 有时会重复发送相同内容,现已过滤 ### 资源管理 - **正确关闭流** - 添加 `finally` 块确保出错或完成时销毁流 - **限制连接池** - 配置 HTTP/HTTPS agent 的 `maxSockets` 和 `maxFreeSockets` 防止资源泄漏 ## 测试 - 使用包含 tools 定义的 curl 命令测试 - 验证 tool_use block 输出正确合并 - 验证工具参数(file_path, content)被正确解析 --- <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#259
No description provided.