mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
Ollama Cloud exposes a native Anthropic-compatible /v1/messages endpoint. A Claude-format client (sourceFormat="claude") is now routed straight to it instead of through the lossy claude->openai->ollama bridge, preserving thinking blocks, tool-use ids, and image fidelity. Narrow, single-provider port — NOT a generic transport-selection framework: - registry: new optional `claudeBaseUrl` on ollama-cloud (mirrors the existing `responsesBaseUrl` precedent) → https://ollama.com/v1/messages. - resolveChatCoreTargetFormat: a Claude-format client on the allowlisted ollama-cloud provider resolves targetFormat="claude" (skips the openai bridge). - resolveExecutionCredentials: stamps a marker read by the executor. - DefaultExecutor.buildUrl/buildHeaders: route to claudeBaseUrl and add the Anthropic-Version header on that path; auth stays Authorization: Bearer. - hasValidContent: recognize image/document-only Claude messages so an attachment-only turn is no longer dropped as empty on the passthrough. TDD regression guards: tests/unit/chatcore-target-format.test.ts, tests/unit/chatcore-execution-credentials.test.ts, tests/unit/executor-ollama-cloud-claude-passthrough.test.ts, tests/unit/translator-helper-branches.test.ts. Co-authored-by: thienpv <pvtcwd@gmail.com> Inspired-by: https://github.com/decolua/9router/pull/2475
132 lines
5.0 KiB
TypeScript
132 lines
5.0 KiB
TypeScript
// tests/unit/chatcore-execution-credentials.test.ts
|
|
// Characterization of resolveExecutionCredentials — the per-execution credentials builder extracted
|
|
// from handleChatCore (chatCore god-file decomposition, #3501). Locks: the native-Codex passthrough
|
|
// endpoint override, the Azure AI / OCI apiType=responses forcing (+ responses-upstream marker) only
|
|
// under the OpenAI Responses target format, respecting an explicit apiType, and the Claude Code
|
|
// session-id threading.
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { resolveExecutionCredentials } from "../../open-sse/handlers/chatCore/executionCredentials.ts";
|
|
|
|
const RESPONSES = "openai-responses";
|
|
|
|
const base = {
|
|
credentials: { providerSpecificData: { foo: "bar" } } as Record<string, unknown>,
|
|
nativeCodexPassthrough: false,
|
|
endpointPath: "/v1/responses",
|
|
targetFormat: "openai",
|
|
provider: "openai",
|
|
ccSessionId: null,
|
|
};
|
|
|
|
test("non-passthrough leaves credentials without a requestEndpointPath", () => {
|
|
const out = resolveExecutionCredentials({ ...base }) as Record<string, unknown>;
|
|
assert.equal("requestEndpointPath" in out, false);
|
|
assert.deepEqual(out.providerSpecificData, { foo: "bar" });
|
|
});
|
|
|
|
test("native Codex passthrough injects requestEndpointPath", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
nativeCodexPassthrough: true,
|
|
}) as Record<string, unknown>;
|
|
assert.equal(out.requestEndpointPath, "/v1/responses");
|
|
});
|
|
|
|
test("azure-ai + responses target forces apiType=responses and the upstream marker", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
provider: "azure-ai",
|
|
targetFormat: RESPONSES,
|
|
}) as Record<string, unknown>;
|
|
const psd = out.providerSpecificData as Record<string, unknown>;
|
|
assert.equal(psd.apiType, "responses");
|
|
assert.equal(psd._omnirouteForceResponsesUpstream, true);
|
|
});
|
|
|
|
test("a non-responses apiType is forced to responses under the responses target", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
provider: "oci",
|
|
targetFormat: RESPONSES,
|
|
credentials: { providerSpecificData: { apiType: "chat" } },
|
|
}) as Record<string, unknown>;
|
|
const psd = out.providerSpecificData as Record<string, unknown>;
|
|
assert.equal(psd.apiType, "responses");
|
|
assert.equal(psd._omnirouteForceResponsesUpstream, true);
|
|
});
|
|
|
|
test("an explicit apiType=responses is preserved (guard short-circuits the reassignment)", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
provider: "oci",
|
|
targetFormat: RESPONSES,
|
|
credentials: { providerSpecificData: { apiType: "responses" } },
|
|
}) as Record<string, unknown>;
|
|
const psd = out.providerSpecificData as Record<string, unknown>;
|
|
assert.equal(psd.apiType, "responses");
|
|
assert.equal(psd._omnirouteForceResponsesUpstream, true);
|
|
});
|
|
|
|
test("non azure/oci providers never get apiType forcing", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
provider: "openai",
|
|
targetFormat: RESPONSES,
|
|
}) as Record<string, unknown>;
|
|
const psd = out.providerSpecificData as Record<string, unknown>;
|
|
assert.equal(psd.apiType, undefined);
|
|
assert.equal(psd._omnirouteForceResponsesUpstream, undefined);
|
|
});
|
|
|
|
test("ccSessionId is threaded into providerSpecificData when present", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
ccSessionId: "sess-123",
|
|
}) as Record<string, unknown>;
|
|
const psd = out.providerSpecificData as Record<string, unknown>;
|
|
assert.equal(psd.ccSessionId, "sess-123");
|
|
assert.equal(psd.foo, "bar");
|
|
});
|
|
|
|
test("missing providerSpecificData defaults to an empty object", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
credentials: { connectionId: "c1" },
|
|
}) as Record<string, unknown>;
|
|
assert.deepEqual(out.providerSpecificData, {});
|
|
});
|
|
|
|
// Port of decolua/9router#2475: ollama-cloud + targetFormat="claude" stamps the marker read by
|
|
// DefaultExecutor.buildUrl/buildHeaders to route to the registry's native claudeBaseUrl instead of
|
|
// the openai bridge.
|
|
test("ollama-cloud + claude target stamps the native-claude-upstream marker", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
provider: "ollama-cloud",
|
|
targetFormat: "claude",
|
|
}) as Record<string, unknown>;
|
|
const psd = out.providerSpecificData as Record<string, unknown>;
|
|
assert.equal(psd._omnirouteOllamaClaudeUpstream, true);
|
|
});
|
|
|
|
test("ollama-cloud + openai target never gets the native-claude-upstream marker", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
provider: "ollama-cloud",
|
|
targetFormat: "openai",
|
|
}) as Record<string, unknown>;
|
|
const psd = out.providerSpecificData as Record<string, unknown>;
|
|
assert.equal(psd._omnirouteOllamaClaudeUpstream, undefined);
|
|
});
|
|
|
|
test("a non-allowlisted provider + claude target never gets the ollama marker", () => {
|
|
const out = resolveExecutionCredentials({
|
|
...base,
|
|
provider: "claude",
|
|
targetFormat: "claude",
|
|
}) as Record<string, unknown>;
|
|
const psd = out.providerSpecificData as Record<string, unknown>;
|
|
assert.equal(psd._omnirouteOllamaClaudeUpstream, undefined);
|
|
});
|