mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-16 17:09:09 +00:00
fix(sse): stop sending type:"custom" Claude tools to DeepSeek (#16281)
DeepSeek no longer receives Claude tools whose type is custom.
Boarded on release/v3.8.52 at 47688ba5ea. Focused tests: 243 passed, 2 failed. The two failures are in tests/unit/codex-provider-overlay-12782.test.ts and belong to #16242, which was ejected: the assertions expect smol-toml null-prototype tables and the current parser returns plain objects. File-size kept only the inherited executeTargetAttempt.ts overage (1288 > 1284). This pull request does not touch that file.
⚠️ base-red inherited: #15306
This commit is contained in:
committed by
GitHub
parent
0339bcab1d
commit
788cd78d05
@@ -0,0 +1 @@
|
||||
- **fix(sse):** DeepSeek connections on the Claude wire format no longer receive `type: "custom"` tool definitions, which the endpoint rejected with HTTP 400 ([#16281](https://github.com/diegosouzapw/OmniRoute/pull/16281)) — thanks @0xH3li0, @kabeza
|
||||
@@ -53,13 +53,24 @@ export function stripClaudeCustomToolType(tools: unknown): unknown {
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-provider dispatch decision for Claude-format tool normalization. AgentRouter
|
||||
* rejects `type: "custom"` (see stripClaudeCustomToolType) while strict gateways like
|
||||
* Providers whose Anthropic-compatible endpoint rejects the `type: "custom"` tool
|
||||
* discriminator with HTTP 400 "unknown variant `custom`":
|
||||
* - agentrouter: New-API upstream (Rust serde), versioned tool types only.
|
||||
* - deepseek: api.deepseek.com/anthropic, same rejection (port from 9router#3905 / #3952).
|
||||
*/
|
||||
const CLAUDE_CUSTOM_TOOL_TYPE_REJECTING_PROVIDERS: ReadonlySet<string> = new Set([
|
||||
"agentrouter",
|
||||
"deepseek",
|
||||
]);
|
||||
|
||||
/**
|
||||
* Per-provider dispatch decision for Claude-format tool normalization. Some providers
|
||||
* reject `type: "custom"` (see stripClaudeCustomToolType) while strict gateways like
|
||||
* MiniMax REQUIRE the explicit discriminator (#2195) — the two quirks are mutually
|
||||
* exclusive, so the normalization is provider-scoped, never global.
|
||||
*/
|
||||
export function normalizeClaudeToolsForDispatch(tools: unknown, provider: string): unknown {
|
||||
return provider === "agentrouter"
|
||||
return CLAUDE_CUSTOM_TOOL_TYPE_REJECTING_PROVIDERS.has(provider)
|
||||
? stripClaudeCustomToolType(tools)
|
||||
: defaultClaudeToolType(tools);
|
||||
}
|
||||
|
||||
48
tests/unit/deepseek-claude-custom-tool-type-3905.test.ts
Normal file
48
tests/unit/deepseek-claude-custom-tool-type-3905.test.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
// DeepSeek's Anthropic-compatible endpoint (api.deepseek.com/anthropic) only accepts
|
||||
// versioned Claude tool types (web_search_20250305 / web_search_20260209); plain tools
|
||||
// must omit `type`. Backfilling `type: "custom"` (#2195, needed by MiniMax) makes every
|
||||
// Claude-format DeepSeek request with tools fail with HTTP 400
|
||||
// "tools[0]: unknown variant `custom`". (port from 9router#3905 / 9router#3952)
|
||||
|
||||
const { normalizeClaudeToolsForDispatch } =
|
||||
await import("../../open-sse/handlers/chatCore/claudeToolDefaults.ts");
|
||||
|
||||
type Tool = Record<string, unknown>;
|
||||
|
||||
test("deepseek: does NOT backfill type:'custom' on typeless tools", () => {
|
||||
const tools = [{ name: "get_weather", description: "Get weather", input_schema: {} }];
|
||||
const out = normalizeClaudeToolsForDispatch(tools, "deepseek") as Tool[];
|
||||
assert.equal(out[0].type, undefined, "no type:'custom' may be injected for deepseek");
|
||||
assert.equal(out[0].name, "get_weather");
|
||||
});
|
||||
|
||||
test("deepseek: strips a client-declared type:'custom', keeping versioned types", () => {
|
||||
const tools = [
|
||||
{ type: "custom", name: "plain", input_schema: { type: "object" } },
|
||||
{ type: "web_search_20250305", name: "web_search" },
|
||||
];
|
||||
const out = normalizeClaudeToolsForDispatch(tools, "deepseek") as Tool[];
|
||||
assert.equal(out[0].type, undefined, "type:'custom' must be removed for deepseek");
|
||||
assert.deepEqual(out[0].input_schema, { type: "object" });
|
||||
assert.equal(out[1].type, "web_search_20250305");
|
||||
});
|
||||
|
||||
test("minimax still gets the #2195 type:'custom' default", () => {
|
||||
const out = normalizeClaudeToolsForDispatch(
|
||||
[{ name: "t", input_schema: {} }],
|
||||
"minimax"
|
||||
) as Tool[];
|
||||
assert.equal(out[0].type, "custom");
|
||||
});
|
||||
|
||||
test("agentrouter still strips type:'custom'", () => {
|
||||
const out = normalizeClaudeToolsForDispatch(
|
||||
[{ type: "custom", name: "t" }, { name: "u" }],
|
||||
"agentrouter"
|
||||
) as Tool[];
|
||||
assert.equal(out[0].type, undefined);
|
||||
assert.equal(out[1].type, undefined);
|
||||
});
|
||||
Reference in New Issue
Block a user