mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-26 17:12:27 +03:00
* fix(translator): Normalize tool call names from lowercase to PascalCase (#1) * Fix: Map lowercase tool names from Antigravity (Gemini format) to Claude Code expected PascalCase * Fix: toolNameMap in fun restoreClaudePassthroughToolUseName * fix(translator): Normalize tool call names from lowercase to PascalCase when translating upstream responses (OpenAI, Gemini, Antigravity) to Claude Messages API format This resolves `Error: No such tool available: read`/`bash`/`write` errors when using Claude Code CLI with third-party providers that emit lowercase tool names. The fix adds case-insensitive tool name lookups in `openai-to-claude.ts`, `gemini-to-claude.ts`, and related translators, ensuring tool names like `read`/`bash` are mapped to `Read`/`Bash` before being sent to Claude Code. Includes unit tests and comprehensive changelog notes ([#10250](https://github.com/diegosouzapw/OmniRoute/pull/10250)) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> * fix(translator): Parse <tool_call> JSON and TOOL_CALL text formats fr… (#2) * fix(translator): Parse <tool_call> JSON and TOOL_CALL text formats from model output Some models (DeepSeek, Qwen) emit tool calls as text instead of proper tool_calls JSON: either <tool_call>{...}</tool_call> or TOOL_CALL Name: {...}. Extend extractXmlInvokeBlocks to handle all 3 formats in a single scan pass, picking whichever pattern appears first. Includes unit tests for all formats. * fix(translator): Parse text-format tool calls in gemini-to-claude translator Extend the Gemini->Claude translator to detect <invoke>, <tool_call> JSON, and TOOL_CALL text formats emitted inline in text parts (Antigravity/Gemini models), converting them to proper tool_use content blocks instead of leaking raw text to Claude Code. * docs(changelog): Add changelog entry for text tool call parsing fix * fix(translator): consolidate tool name casing normalization and restore thought-signature persistence (#3) * fix(translator): sanitize tool_use.id and tool_result.tool_use_id to match Anthropic schema (#4) Ensure tool IDs from OpenAI-compatible upstreams (which may contain dots, colons, or special characters) are sanitized to ^[a-zA-Z0-9_-]+$ in response translators and passthrough requests before reaching Claude endpoints. * fix(responses): preserve native tools for openai-compatible Responses targets (#5) A Responses-shaped request to a custom openai-compatible connection whose outbound protocol is Responses took a Responses -> Chat -> Responses round trip, so Codex custom tools lost their grammar (`exec`), namespace groups were flattened (`collaboration`), and tool invocations failed upstream. Gate a native Responses passthrough on the connection's configured protocol (`apiType: "responses"` / `_omnirouteForceResponsesUpstream`) so the original tool definitions reach a Responses-capable upstream unchanged. Chat-only connections keep the existing downgrade. Closes #10374 * fix(translator): add support for 'applypatch' tool name in tool call checks * test(translator): add unit test for apply_patch and applypatch tool name remapping * fix(translator): remove no-explicit-any lint errors in tool-use-id-sanitization test Type the openaiToClaudeResponse/translateNonStreamingResponse return values with narrow local shapes instead of `any`, satisfying the repo's no-explicit-any = error rule for tests/. No behavior change — the same 3 assertions still pass. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * test: update 9568 casing regression to match #10392's consolidated fix restoreClaudeToolName's static casing map now normalizes known lowercase tool names to canonical PascalCase unconditionally on the gemini-to-claude and openai-to-claude Claude Messages API paths (not gated behind toolNameMap), superseding the earlier per-map-only fix that the original #9568 regression test locked in as "expected" (it was previously labeled a known bug case). The gemini-to-openai passthrough path is unaffected by #10392 and keeps its original pass-through assertion. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
139 lines
4.2 KiB
TypeScript
139 lines
4.2 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const { geminiToOpenAIResponse } =
|
|
await import("../../open-sse/translator/response/gemini-to-openai.ts");
|
|
const { geminiToClaudeResponse } =
|
|
await import("../../open-sse/translator/response/gemini-to-claude.ts");
|
|
|
|
function flatten(items) {
|
|
return items.flatMap((item) => item || []);
|
|
}
|
|
|
|
// ── Gemini -> OpenAI tool name casing fix (#9568) ──────────────────────
|
|
|
|
test("gemini-to-openai: no toolNameMap — Gemini returns lowercase 'bash', translator outputs 'bash' (bug, unaffected by #10392 — that PR's static casing map applies only to the gemini-to-claude and openai-to-claude Claude Messages API paths, not this OpenAI-compatible passthrough path)", () => {
|
|
const state = { toolCalls: new Map(), toolNameMap: null };
|
|
const result = geminiToOpenAIResponse(
|
|
{
|
|
responseId: "resp-9568-1",
|
|
modelVersion: "gemini-2.5-pro",
|
|
candidates: [
|
|
{
|
|
content: {
|
|
parts: [
|
|
{
|
|
functionCall: { name: "bash", args: { code: "echo hi" } },
|
|
},
|
|
],
|
|
},
|
|
finishReason: "STOP",
|
|
},
|
|
],
|
|
},
|
|
state
|
|
);
|
|
|
|
const toolCall = result.find((c) => c.choices?.[0]?.delta?.tool_calls);
|
|
const name = toolCall?.choices?.[0]?.delta?.tool_calls?.[0]?.function?.name;
|
|
assert.equal(name, "bash", "Without toolNameMap, lowercase tool name should pass through as-is");
|
|
});
|
|
|
|
test("gemini-to-openai: toolNameMap has lowercase alias — Gemini returns 'bash', translator outputs 'Bash' (fix)", () => {
|
|
const state = {
|
|
toolCalls: new Map(),
|
|
toolNameMap: new Map([["bash", "Bash"]]),
|
|
};
|
|
const result = geminiToOpenAIResponse(
|
|
{
|
|
responseId: "resp-9568-2",
|
|
modelVersion: "gemini-2.5-pro",
|
|
candidates: [
|
|
{
|
|
content: {
|
|
parts: [
|
|
{
|
|
functionCall: { name: "bash", args: { code: "echo hi" } },
|
|
},
|
|
],
|
|
},
|
|
finishReason: "STOP",
|
|
},
|
|
],
|
|
},
|
|
state
|
|
);
|
|
|
|
const toolCall = result.find((c) => c.choices?.[0]?.delta?.tool_calls);
|
|
const name = toolCall?.choices?.[0]?.delta?.tool_calls?.[0]?.function?.name;
|
|
assert.equal(
|
|
name,
|
|
"Bash",
|
|
"With toolNameMap={{'bash','Bash'}}, lowercase tool name should be restored to TitleCase"
|
|
);
|
|
});
|
|
|
|
// ── Gemini -> Claude tool name casing fix (#9568) ──────────────────────
|
|
|
|
test("gemini-to-claude: no toolNameMap — Gemini returns 'bash', translator outputs 'Bash' (#10392 consolidated fix)", () => {
|
|
const state = {};
|
|
const result = geminiToClaudeResponse(
|
|
{
|
|
responseId: "resp-9568-3",
|
|
modelVersion: "gemini-2.5-pro",
|
|
candidates: [
|
|
{
|
|
content: {
|
|
parts: [
|
|
{
|
|
functionCall: { name: "bash", args: { code: "echo hi" } },
|
|
},
|
|
],
|
|
},
|
|
finishReason: "STOP",
|
|
},
|
|
],
|
|
},
|
|
state
|
|
);
|
|
|
|
const toolUse = result.find((c) => c.type === "content_block_start");
|
|
assert.equal(
|
|
toolUse?.content_block?.name,
|
|
"Bash",
|
|
"Without toolNameMap, restoreClaudeToolName's static casing map now normalizes known lowercase tool names to canonical PascalCase (gemini-to-claude, #10392 closes this permanently)"
|
|
);
|
|
});
|
|
|
|
test("gemini-to-claude: toolNameMap has lowercase alias — Gemini returns 'bash', translator outputs 'Bash' (fix)", () => {
|
|
const state = {
|
|
toolNameMap: new Map([["bash", "Bash"]]),
|
|
};
|
|
const result = geminiToClaudeResponse(
|
|
{
|
|
responseId: "resp-9568-4",
|
|
modelVersion: "gemini-2.5-pro",
|
|
candidates: [
|
|
{
|
|
content: {
|
|
parts: [
|
|
{
|
|
functionCall: { name: "bash", args: { code: "echo hi" } },
|
|
},
|
|
],
|
|
},
|
|
finishReason: "STOP",
|
|
},
|
|
],
|
|
},
|
|
state
|
|
);
|
|
|
|
const toolUse = result.find((c) => c.type === "content_block_start");
|
|
assert.equal(
|
|
toolUse?.content_block?.name,
|
|
"Bash",
|
|
"With toolNameMap={{'bash','Bash'}}, lowercase tool name should be restored to TitleCase without normalizeToolName reversing it"
|
|
);
|
|
});
|