fix(sse): skip the stripped proxy_ alias when a declared tool matches it in any case

The stream restorer matches tool names case-insensitively, so a search alias
for a declared proxy_search renamed an upstream SEARCH (a declared tool) to
proxy_search. Add the alias only when no declared name equals the stripped
name ignoring case.
This commit is contained in:
serenity
2026-11-18 22:41:28 -03:00
committed by diegosouzapw
parent 71462bb859
commit 8e72d9176a
2 changed files with 17 additions and 2 deletions

View File

@@ -25,15 +25,18 @@ export function buildClaudePassthroughToolNameMap(
if (!body || !Array.isArray(body.tools)) return null;
const names = declaredToolNames(body.tools);
const lowerNames = new Set(names.map((name) => name.toLowerCase()));
const toolNameMap = new Map<string, string>();
for (const name of names) {
toolNameMap.set(`${CLAUDE_OAUTH_TOOL_PREFIX}${name}`, name);
// The native executor strips a leading `proxy_`, so a tool the client named
// `proxy_x` comes back as `x`. Map it home unless the client also declared `x`.
// `proxy_x` comes back as `x`. Map it home unless the client also declared `x`
// in any casing: the stream restorer matches names case-insensitively, so an
// `x` alias would otherwise rename a declared `X` to `proxy_x`.
const stripped = name.startsWith(CLAUDE_OAUTH_TOOL_PREFIX)
? name.slice(CLAUDE_OAUTH_TOOL_PREFIX.length)
: "";
if (stripped && !names.includes(stripped)) toolNameMap.set(stripped, name);
if (stripped && !lowerNames.has(stripped.toLowerCase())) toolNameMap.set(stripped, name);
}
return toolNameMap.size > 0 ? toolNameMap : null;

View File

@@ -42,6 +42,18 @@ test("a tool without the prefix still restores a prefixed echo and adds no extra
assert.deepEqual([...(ledger ?? [])], [["proxy_get_weather", "get_weather"]]);
});
test("stream: a declared SEARCH stays SEARCH when proxy_search is declared before it", () => {
const tools = [{ name: "proxy_search" }, { name: "SEARCH" }];
const ledger = buildClaudePassthroughToolNameMap({ tools });
const event = {
type: "content_block_start",
index: 0,
content_block: { type: "tool_use", id: "t1", name: "SEARCH", input: {} },
};
restoreClaudePassthroughToolUseName(event, ledger, tools);
assert.equal(event.content_block.name, "SEARCH");
});
test("a client that declares both search and proxy_search keeps search as search", () => {
const ledger = buildClaudePassthroughToolNameMap({
tools: [{ name: "search" }, { name: "proxy_search" }],