This commit is contained in:
2026-07-06 00:01:34 +07:00
parent 2729408ef3
commit e7470e955e
108 changed files with 4131 additions and 529 deletions

View File

@@ -25,7 +25,10 @@ function emitFunctionCall(functionCall, state) {
type: OPENAI_BLOCK.FUNCTION,
function: { name: fcName, arguments: JSON.stringify(fcArgs) },
};
state.toolCalls.set(toolCallIndex, toolCall);
// Keep Gemini bookkeeping separate from the shared translator state.toolCalls map.
// The downstream OpenAI→Claude translator uses state.toolCalls for Claude block
// metadata; pre-populating it here makes Anthropic tool deltas lose index.
state.geminiToolCallCount = (state.geminiToolCallCount || 0) + 1;
return buildChunk(chunkMeta(state), { tool_calls: [toolCall] }, null);
}
@@ -46,6 +49,7 @@ export function geminiToOpenAIResponse(chunk, state) {
state.messageId = response.responseId || `msg_${Date.now()}`;
state.model = response.modelVersion || "gemini";
state.functionIndex = 0;
state.geminiToolCallCount = 0;
results.push(buildChunk(chunkMeta(state), { role: ROLE.ASSISTANT }, null));
}
@@ -117,7 +121,7 @@ export function geminiToOpenAIResponse(chunk, state) {
// Finish reason - include usage in final chunk
if (candidate.finishReason) {
let finishReason = toOpenAIFinish(candidate.finishReason, "gemini");
if (finishReason === OPENAI_FINISH.STOP && state.toolCalls.size > 0) {
if (finishReason === OPENAI_FINISH.STOP && state.geminiToolCallCount > 0) {
finishReason = OPENAI_FINISH.TOOL_CALLS;
}