Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
250 lines
7.7 KiB
TypeScript
250 lines
7.7 KiB
TypeScript
import type { ProviderRuntimeModel } from "openclaw/plugin-sdk/plugin-entry";
|
|
import {
|
|
clearLiveCatalogCacheForTests,
|
|
type LiveModelCatalogFetchGuard,
|
|
} from "openclaw/plugin-sdk/provider-catalog-live-runtime";
|
|
import { beforeEach, describe, expect, it, vi, type MockedFunction } from "vitest";
|
|
import {
|
|
buildClawRouterProviderConfig,
|
|
normalizeClawRouterResolvedModel,
|
|
prepareClawRouterRequestModel,
|
|
} from "./provider-catalog.js";
|
|
|
|
const PRICING = {
|
|
inputMicrosPerMillion: 3_000_000,
|
|
outputMicrosPerMillion: 15_000_000,
|
|
cachedInputMicrosPerMillion: 300_000,
|
|
cacheWrite5mInputMicrosPerMillion: 3_750_000,
|
|
maxInputTokens: 1_000_000,
|
|
defaultMaxOutputTokens: 64_000,
|
|
};
|
|
|
|
const CATALOG = {
|
|
version: "clawrouter.client-catalog.v1",
|
|
providers: [
|
|
{
|
|
id: "openai",
|
|
displayName: "OpenAI",
|
|
openaiCompatible: true,
|
|
nativeBaseUrl: "/v1/native/openai",
|
|
routes: [
|
|
{
|
|
path: "/v1/responses",
|
|
methods: ["POST"],
|
|
requestFormat: "openai.responses",
|
|
},
|
|
],
|
|
models: [
|
|
{
|
|
id: "openai/gpt-5.5",
|
|
upstream: "gpt-5.5",
|
|
capabilities: ["llm.responses", "llm.chat"],
|
|
pricing: PRICING,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: "deepseek",
|
|
displayName: "DeepSeek",
|
|
openaiCompatible: true,
|
|
nativeBaseUrl: "/v1/native/deepseek",
|
|
routes: [],
|
|
models: [
|
|
{
|
|
id: "deepseek/deepseek-v4-flash",
|
|
upstream: "deepseek-v4-flash",
|
|
capabilities: ["llm.chat"],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: "anthropic",
|
|
displayName: "Anthropic",
|
|
openaiCompatible: false,
|
|
nativeBaseUrl: "/v1/native/anthropic",
|
|
routes: [
|
|
{
|
|
path: "/v1/messages",
|
|
methods: ["POST"],
|
|
requestFormat: "anthropic.messages",
|
|
},
|
|
],
|
|
models: [
|
|
{
|
|
id: "anthropic/claude-sonnet-4-6",
|
|
upstream: "claude-sonnet-4-6",
|
|
capabilities: ["llm.messages"],
|
|
pricing: PRICING,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: "google-gemini",
|
|
displayName: "Google Gemini",
|
|
openaiCompatible: false,
|
|
nativeBaseUrl: "/v1/native/google-gemini",
|
|
routes: [
|
|
{
|
|
path: "/v1beta/models/${model}:generateContent",
|
|
methods: ["POST"],
|
|
requestFormat: "google.generate_content",
|
|
},
|
|
{
|
|
path: "/v1beta/models/${model}:streamGenerateContent",
|
|
methods: ["POST"],
|
|
requestFormat: "google.generate_content",
|
|
},
|
|
],
|
|
models: [
|
|
{
|
|
id: "google/gemini-3.5-flash",
|
|
upstream: "gemini-3.5-flash",
|
|
capabilities: ["llm.generate", "llm.stream"],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: "cohere",
|
|
displayName: "Cohere",
|
|
openaiCompatible: false,
|
|
nativeBaseUrl: "/v1/native/cohere",
|
|
routes: [
|
|
{
|
|
path: "/v2/chat",
|
|
methods: ["POST"],
|
|
requestFormat: "cohere.chat",
|
|
},
|
|
],
|
|
models: [
|
|
{
|
|
id: "cohere/command-a-plus-05-2026",
|
|
upstream: "command-a-plus-05-2026",
|
|
capabilities: ["llm.chat"],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
function buildFetchGuard(catalog: unknown = CATALOG): {
|
|
fetchGuard: LiveModelCatalogFetchGuard;
|
|
fetchGuardMock: MockedFunction<LiveModelCatalogFetchGuard>;
|
|
} {
|
|
const fetchGuardMock: MockedFunction<LiveModelCatalogFetchGuard> = vi.fn(async () => ({
|
|
response: new Response(JSON.stringify(catalog)),
|
|
finalUrl: "https://clawrouter.example/v1/catalog",
|
|
release: async () => undefined,
|
|
}));
|
|
return { fetchGuard: fetchGuardMock, fetchGuardMock };
|
|
}
|
|
|
|
describe("ClawRouter provider catalog", () => {
|
|
beforeEach(() => {
|
|
clearLiveCatalogCacheForTests();
|
|
});
|
|
|
|
it("maps every supported catalog protocol to its OpenClaw transport", async () => {
|
|
const { fetchGuard, fetchGuardMock } = buildFetchGuard();
|
|
const provider = await buildClawRouterProviderConfig({
|
|
apiKey: "clawrouter-test-key",
|
|
baseUrl: "https://clawrouter.example/v1",
|
|
fetchGuard,
|
|
});
|
|
|
|
expect(fetchGuardMock).toHaveBeenCalledOnce();
|
|
expect(provider.models.map((model) => model.id)).toEqual([
|
|
"anthropic/claude-sonnet-4-6",
|
|
"deepseek/deepseek-v4-flash",
|
|
"google/gemini-3.5-flash",
|
|
"openai/gpt-5.5",
|
|
]);
|
|
expect(provider.models.find((model) => model.id === "openai/gpt-5.5")).toMatchObject({
|
|
api: "openai-responses",
|
|
baseUrl: "https://clawrouter.example/v1",
|
|
reasoning: true,
|
|
input: ["text", "image"],
|
|
cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
|
|
contextWindow: 1_000_000,
|
|
maxTokens: 64_000,
|
|
});
|
|
expect(
|
|
provider.models.find((model) => model.id === "deepseek/deepseek-v4-flash"),
|
|
).toMatchObject({ api: "openai-completions" });
|
|
expect(
|
|
provider.models.find((model) => model.id === "anthropic/claude-sonnet-4-6"),
|
|
).toMatchObject({
|
|
api: "anthropic-messages",
|
|
baseUrl: "https://clawrouter.example/v1/native/anthropic",
|
|
});
|
|
expect(provider.models.find((model) => model.id === "google/gemini-3.5-flash")).toMatchObject({
|
|
api: "google-generative-ai",
|
|
baseUrl: "https://clawrouter.example/v1/native/google-gemini/v1beta",
|
|
});
|
|
expect(provider.models.map((model) => model.id)).not.toContain("cohere/command-a-plus-05-2026");
|
|
});
|
|
|
|
it("rewrites only native protocol model ids at the request boundary", async () => {
|
|
const provider = await buildClawRouterProviderConfig({
|
|
apiKey: "clawrouter-test-key",
|
|
baseUrl: "https://clawrouter.example",
|
|
fetchGuard: buildFetchGuard().fetchGuard,
|
|
});
|
|
const anthropic = provider.models.find((model) => model.id === "anthropic/claude-sonnet-4-6");
|
|
const normalized = normalizeClawRouterResolvedModel({
|
|
...anthropic,
|
|
baseUrl: provider.baseUrl,
|
|
provider: "clawrouter",
|
|
} as ProviderRuntimeModel);
|
|
|
|
expect(normalized).toMatchObject({
|
|
id: "anthropic/claude-sonnet-4-6",
|
|
api: "anthropic-messages",
|
|
});
|
|
expect(prepareClawRouterRequestModel(normalized as ProviderRuntimeModel)).toMatchObject({
|
|
id: "claude-sonnet-4-6",
|
|
params: undefined,
|
|
});
|
|
|
|
const openai = provider.models.find((model) => model.id === "openai/gpt-5.5");
|
|
const normalizedOpenAi = normalizeClawRouterResolvedModel({
|
|
...openai,
|
|
baseUrl: provider.baseUrl,
|
|
provider: "clawrouter",
|
|
} as ProviderRuntimeModel);
|
|
expect(prepareClawRouterRequestModel(normalizedOpenAi as ProviderRuntimeModel).id).toBe(
|
|
"openai/gpt-5.5",
|
|
);
|
|
});
|
|
|
|
it("caches catalog rows per credential scope", async () => {
|
|
const { fetchGuard, fetchGuardMock } = buildFetchGuard();
|
|
const params = {
|
|
apiKey: "clawrouter-test-key",
|
|
baseUrl: "https://clawrouter.example",
|
|
fetchGuard,
|
|
};
|
|
|
|
await buildClawRouterProviderConfig(params);
|
|
await buildClawRouterProviderConfig(params);
|
|
|
|
expect(fetchGuardMock).toHaveBeenCalledOnce();
|
|
const headers = fetchGuardMock.mock.calls[0]?.[0].init?.headers;
|
|
expect(headers).toBeInstanceOf(Headers);
|
|
expect((headers as Headers).get("authorization")).toBe("Bearer clawrouter-test-key");
|
|
});
|
|
|
|
it("does not advertise Gemini without a streaming route", async () => {
|
|
const catalog = structuredClone(CATALOG);
|
|
catalog.providers[3].routes = catalog.providers[3].routes.filter(
|
|
(route) => !route.path.includes(":streamGenerateContent"),
|
|
);
|
|
catalog.providers[3].models[0].capabilities = ["llm.generate"];
|
|
const provider = await buildClawRouterProviderConfig({
|
|
apiKey: "clawrouter-test-key",
|
|
fetchGuard: buildFetchGuard(catalog).fetchGuard,
|
|
});
|
|
|
|
expect(provider.models.map((model) => model.id)).not.toContain("google/gemini-3.5-flash");
|
|
});
|
|
});
|