fix(kiro): 修复 tool_use 的 input 字段序列化问题

将 tool_use 块的 input 字段从 JSON 字符串解析为对象,
修复 Claude SDK 校验不通过的问题。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Clansty 2025-12-26 21:28:29 +08:00
parent 2a69ca81c3
commit 839731fd48

View file

@ -1639,8 +1639,9 @@ async initializeAuth(forceRefresh = false) {
toolCalls.forEach((tc, index) => { toolCalls.forEach((tc, index) => {
let inputObject; let inputObject;
try { try {
// Arguments should be a stringified JSON object. // Arguments should be a stringified JSON object, need to parse it
inputObject = tc.function.arguments; const args = tc.function.arguments;
inputObject = typeof args === 'string' ? JSON.parse(args) : args;
} catch (e) { } catch (e) {
console.warn(`[Kiro] Invalid JSON for tool call arguments. Wrapping in raw_arguments. Error: ${e.message}`, tc.function.arguments); console.warn(`[Kiro] Invalid JSON for tool call arguments. Wrapping in raw_arguments. Error: ${e.message}`, tc.function.arguments);
// If parsing fails, wrap the raw string in an object as a fallback, // If parsing fails, wrap the raw string in an object as a fallback,
@ -1666,7 +1667,7 @@ async initializeAuth(forceRefresh = false) {
index: index, index: index,
delta: { delta: {
type: "input_json_delta", type: "input_json_delta",
partial_json: inputObject partial_json: JSON.stringify(inputObject)
} }
}); });
@ -1706,8 +1707,9 @@ async initializeAuth(forceRefresh = false) {
for (const tc of toolCalls) { for (const tc of toolCalls) {
let inputObject; let inputObject;
try { try {
// Arguments should be a stringified JSON object. // Arguments should be a stringified JSON object, need to parse it
inputObject = tc.function.arguments; const args = tc.function.arguments;
inputObject = typeof args === 'string' ? JSON.parse(args) : args;
} catch (e) { } catch (e) {
console.warn(`[Kiro] Invalid JSON for tool call arguments. Wrapping in raw_arguments. Error: ${e.message}`, tc.function.arguments); console.warn(`[Kiro] Invalid JSON for tool call arguments. Wrapping in raw_arguments. Error: ${e.message}`, tc.function.arguments);
// If parsing fails, wrap the raw string in an object as a fallback, // If parsing fails, wrap the raw string in an object as a fallback,