[PR #95] [MERGED] fix: 修复 Kiro API 工具调用、流式传输优化及号池错误处理 #260

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

📋 Pull Request Information

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

Base: mainHead: main


📝 Commits (4)

  • b850d58 fix: prevent resource leak - close streams properly and limit connection pool
  • d9e3903 perf: move token counting to end of stream to avoid blocking event loop
  • 369062e feat: return 400 error when no available provider in pool
  • 3976bd2 fix: only throw NoAvailableProviderError for Kiro providers

📊 Changes

3 files changed (+83 additions, -8 deletions)

View changed files

📝 src/claude/claude-kiro.js (+37 -4)
📝 src/common.js (+18 -3)
📝 src/service-manager.js (+28 -1)

📄 Description

概要

修复 Kiro API 集成的多个问题,并添加号池错误处理。

更改内容

工具调用修复

  • 修复嵌套 JSON 解析 - 正确处理包含嵌套对象的 tool_use input
  • 跳过 AWS Event Stream 二进制头部 - 只搜索有效的 JSON payload 模式
  • 处理多部分 toolUse 事件 - Kiro API 分多次发送工具 input,现在正确累积
  • 合并相同 toolUseId 的 toolUse 事件 - 合并为一个 tool_use block
  • 去重 toolResults - 防止重复 toolUseId 导致的验证错误

流式传输修复

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

性能优化

  • 将 token 计算移至流结束后 - 避免在流式传输期间阻塞事件循环
  • 正确关闭流 - 添加 finally 块确保出错或完成时销毁流
  • 限制连接池 - 配置 HTTP/HTTPS agent 的 maxSockets 防止资源泄漏

号池错误处理

  • 号池无可用账号时返回 400 - 不再回退到主配置,返回明确错误消息
  • 新增 NoAvailableProviderError 类 - 用于更好的错误处理

响应格式(号池为空时)

{
"error": {
"type": "no_available_provider",
"message": "号池无可用账号: claude-kiro-oauth"
}
}## 测试

  • 使用 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/95 **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) - [`b850d58`](https://github.com/justlovemaki/AIClient-2-API/commit/b850d586d4e89936757bb9a109af451d4ea14b12) fix: prevent resource leak - close streams properly and limit connection pool - [`d9e3903`](https://github.com/justlovemaki/AIClient-2-API/commit/d9e3903002b640c76fafdc44a3cc1d0e6fd16001) perf: move token counting to end of stream to avoid blocking event loop - [`369062e`](https://github.com/justlovemaki/AIClient-2-API/commit/369062eb4ece17784052353ef7e7695d70384e30) feat: return 400 error when no available provider in pool - [`3976bd2`](https://github.com/justlovemaki/AIClient-2-API/commit/3976bd28e2cb5868685be304ab6d7230e3da08bd) fix: only throw NoAvailableProviderError for Kiro providers ### 📊 Changes **3 files changed** (+83 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `src/claude/claude-kiro.js` (+37 -4) 📝 `src/common.js` (+18 -3) 📝 `src/service-manager.js` (+28 -1) </details> ### 📄 Description ## 概要 修复 Kiro API 集成的多个问题,并添加号池错误处理。 ## 更改内容 ### 工具调用修复 - **修复嵌套 JSON 解析** - 正确处理包含嵌套对象的 tool_use input - **跳过 AWS Event Stream 二进制头部** - 只搜索有效的 JSON payload 模式 - **处理多部分 toolUse 事件** - Kiro API 分多次发送工具 input,现在正确累积 - **合并相同 toolUseId 的 toolUse 事件** - 合并为一个 tool_use block - **去重 toolResults** - 防止重复 toolUseId 导致的验证错误 ### 流式传输修复 - **过滤重复的连续 content 事件** - Kiro API 有时会重复发送相同内容 ### 性能优化 - **将 token 计算移至流结束后** - 避免在流式传输期间阻塞事件循环 - **正确关闭流** - 添加 `finally` 块确保出错或完成时销毁流 - **限制连接池** - 配置 HTTP/HTTPS agent 的 `maxSockets` 防止资源泄漏 ### 号池错误处理 - **号池无可用账号时返回 400** - 不再回退到主配置,返回明确错误消息 - **新增 NoAvailableProviderError 类** - 用于更好的错误处理 ## 响应格式(号池为空时) { "error": { "type": "no_available_provider", "message": "号池无可用账号: claude-kiro-oauth" } }## 测试 - 使用 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:44 +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#260
No description provided.