mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-05-05 09:46:30 +00:00
Expose client-visible Antigravity preview model aliases while resolving them back to upstream IDs for execution and provider discovery. Refresh the Antigravity user agent from cached latest release metadata so model discovery and requests track current CLI versions more reliably. Add configurable Gemini thought signature cache modes in settings to allow validated client-provided signatures in bypass flows while preserving the existing stored-signature behavior by default. Also centralize Anthropics header/version constants, enrich image model catalog metadata with input and output modalities, add dashboard image input support for advanced image providers, and exclude task docs from Next standalone tracing to keep isolated builds stable.
98 lines
4.3 KiB
TypeScript
98 lines
4.3 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const {
|
|
CLAUDE_CODE_COMPATIBLE_DEFAULT_CHAT_PATH,
|
|
CLAUDE_CODE_COMPATIBLE_DEFAULT_MODELS_PATH,
|
|
CLAUDE_CODE_COMPATIBLE_DEFAULT_MAX_TOKENS,
|
|
CLAUDE_CODE_COMPATIBLE_ANTHROPIC_BETA,
|
|
CLAUDE_CODE_COMPATIBLE_STAINLESS_TIMEOUT_SECONDS,
|
|
isClaudeCodeCompatibleProvider,
|
|
stripAnthropicMessagesSuffix,
|
|
stripClaudeCodeCompatibleEndpointSuffix,
|
|
joinBaseUrlAndPath,
|
|
joinClaudeCodeCompatibleUrl,
|
|
buildClaudeCodeCompatibleHeaders,
|
|
buildClaudeCodeCompatibleValidationPayload,
|
|
resolveClaudeCodeCompatibleSessionId,
|
|
} = await import("../../open-sse/services/claudeCodeCompatible.ts");
|
|
|
|
const { isClaudeCodeCompatible } = await import("../../open-sse/services/provider.ts");
|
|
|
|
test("Claude Code compatible provider detection matches the shared prefix contract", () => {
|
|
assert.equal(isClaudeCodeCompatibleProvider("anthropic-compatible-cc-demo"), true);
|
|
assert.equal(isClaudeCodeCompatible("anthropic-compatible-cc-demo"), true);
|
|
assert.equal(isClaudeCodeCompatibleProvider("anthropic-compatible-demo"), false);
|
|
assert.equal(isClaudeCodeCompatible(null), false);
|
|
});
|
|
|
|
test("base URL helpers strip messages suffixes and join canonical paths", () => {
|
|
const baseUrl = "https://cc.example.com/v1/messages?beta=true";
|
|
|
|
assert.equal(stripAnthropicMessagesSuffix(baseUrl), "https://cc.example.com/v1");
|
|
assert.equal(stripClaudeCodeCompatibleEndpointSuffix(baseUrl), "https://cc.example.com");
|
|
assert.equal(
|
|
joinBaseUrlAndPath(baseUrl, CLAUDE_CODE_COMPATIBLE_DEFAULT_MODELS_PATH),
|
|
"https://cc.example.com/v1/models"
|
|
);
|
|
assert.equal(
|
|
joinClaudeCodeCompatibleUrl(baseUrl, CLAUDE_CODE_COMPATIBLE_DEFAULT_CHAT_PATH),
|
|
"https://cc.example.com/v1/messages?beta=true"
|
|
);
|
|
});
|
|
|
|
test("buildClaudeCodeCompatibleHeaders emits stream-aware auth headers and session id", () => {
|
|
const streamHeaders = buildClaudeCodeCompatibleHeaders("sk-demo", true, "session-123");
|
|
const jsonHeaders = buildClaudeCodeCompatibleHeaders("sk-demo", false);
|
|
|
|
assert.equal(streamHeaders.Accept, "text/event-stream");
|
|
assert.equal(streamHeaders["x-api-key"], "sk-demo");
|
|
assert.equal(streamHeaders["X-Claude-Code-Session-Id"], "session-123");
|
|
assert.equal(
|
|
streamHeaders["X-Stainless-Timeout"],
|
|
String(CLAUDE_CODE_COMPATIBLE_STAINLESS_TIMEOUT_SECONDS)
|
|
);
|
|
assert.equal(jsonHeaders.Accept, "application/json");
|
|
assert.equal(jsonHeaders["X-Claude-Code-Session-Id"], undefined);
|
|
});
|
|
|
|
test("Claude Code compatible beta set stays conservative for third-party proxies", () => {
|
|
assert.ok(CLAUDE_CODE_COMPATIBLE_ANTHROPIC_BETA.includes("oauth-2025-04-20"));
|
|
assert.ok(CLAUDE_CODE_COMPATIBLE_ANTHROPIC_BETA.includes("advanced-tool-use-2025-11-20"));
|
|
assert.ok(CLAUDE_CODE_COMPATIBLE_ANTHROPIC_BETA.includes("fast-mode-2026-02-01"));
|
|
assert.ok(CLAUDE_CODE_COMPATIBLE_ANTHROPIC_BETA.includes("token-efficient-tools-2026-03-28"));
|
|
assert.equal(CLAUDE_CODE_COMPATIBLE_ANTHROPIC_BETA.includes("fast-mode-2025-04-01"), false);
|
|
assert.equal(CLAUDE_CODE_COMPATIBLE_ANTHROPIC_BETA.includes("redact-thinking-2025-06-20"), false);
|
|
});
|
|
|
|
test("resolveClaudeCodeCompatibleSessionId prefers explicit session headers and generates a fallback id", () => {
|
|
const headers = new Headers({
|
|
"x-session-id": "legacy-session",
|
|
"x-claude-code-session-id": "preferred-session",
|
|
});
|
|
|
|
assert.equal(resolveClaudeCodeCompatibleSessionId(headers), "preferred-session");
|
|
assert.match(
|
|
resolveClaudeCodeCompatibleSessionId({}),
|
|
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
|
);
|
|
});
|
|
|
|
test("buildClaudeCodeCompatibleValidationPayload produces the expected smoke-test request", () => {
|
|
const payload = buildClaudeCodeCompatibleValidationPayload("claude-sonnet-4-6");
|
|
|
|
assert.equal(payload.model, "claude-sonnet-4-6");
|
|
assert.equal(payload.stream, true);
|
|
assert.equal(payload.max_tokens, 1);
|
|
assert.equal(payload.output_config.effort, "high");
|
|
assert.equal(payload.messages.length, 1);
|
|
assert.deepEqual(payload.messages[0], {
|
|
role: "user",
|
|
content: [{ type: "text", text: "ok" }],
|
|
});
|
|
assert.equal(payload.tools.length, 0);
|
|
assert.equal(payload.system[0].cache_control, undefined);
|
|
assert.ok(JSON.parse(payload.metadata.user_id).session_id);
|
|
assert.ok(payload.system.some((block) => String(block.text).includes(process.cwd())));
|
|
assert.ok(CLAUDE_CODE_COMPATIBLE_DEFAULT_MAX_TOKENS > payload.max_tokens);
|
|
});
|