fix(translator): keep tool-result images, restore Kiro tool names, preserve thinking display
Forward images inside tool_result to OpenAI and Kiro upstreams via following user messages, restore original client tool names on Kiro responses via _toolNameMap, and preserve thinking display settings across translations.
This commit is contained in:
@@ -46,6 +46,14 @@ function convertFinishReason(reason) {
|
||||
* Convert one OpenAI-format chunk (from KiroExecutor) into Claude SSE events.
|
||||
* Returns an array of Claude events, or null when the chunk yields nothing.
|
||||
*/
|
||||
// Kiro only accepts sanitized tool names; the request translator leaves the
|
||||
// reverse map on the stream state so calls come back under the client's names.
|
||||
function restoreToolName(state, name) {
|
||||
const raw = name || "";
|
||||
const map = state?.toolNameMap;
|
||||
return map && typeof map.get === "function" && map.has(raw) ? map.get(raw) : raw;
|
||||
}
|
||||
|
||||
export function kiroToClaudeResponse(chunk, state) {
|
||||
// KiroExecutor emits chat.completion.chunk objects; tolerate string chunks
|
||||
// by attempting a parse (defensive — the direct path is always objects).
|
||||
@@ -161,7 +169,7 @@ export function kiroToClaudeResponse(chunk, state) {
|
||||
const toolBlockIndex = state.nextBlockIndex++;
|
||||
state.toolCalls.set(idx, {
|
||||
id: tc.id,
|
||||
name: tc.function?.name || "",
|
||||
name: restoreToolName(state, tc.function?.name),
|
||||
blockIndex: toolBlockIndex,
|
||||
});
|
||||
results.push({
|
||||
@@ -170,7 +178,7 @@ export function kiroToClaudeResponse(chunk, state) {
|
||||
content_block: {
|
||||
type: "tool_use",
|
||||
id: tc.id,
|
||||
name: tc.function?.name || "",
|
||||
name: restoreToolName(state, tc.function?.name),
|
||||
input: {},
|
||||
},
|
||||
});
|
||||
@@ -246,7 +254,7 @@ export function kiroToClaudeNonStreaming(data) {
|
||||
content.push({
|
||||
type: "tool_use",
|
||||
id: tc.id || `toolu_${Date.now()}`,
|
||||
name: tc.function?.name || "",
|
||||
name: restoreToolName(state, tc.function?.name),
|
||||
input,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user