Vendor OpenClaw source as Adolf fork baseline
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
This commit is contained in:
2026-07-05 09:36:54 +00:00
parent 3216769225
commit bedb527145
21108 changed files with 6010766 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
# Vercel AI Gateway OpenClaw provider
Official OpenClaw provider plugin for Vercel AI Gateway.
## Install
```sh
openclaw plugins install @openclaw/vercel-ai-gateway-provider
```
## Docs
See `docs/providers/vercel-ai-gateway.md` in the OpenClaw repository, or the published docs at `https://docs.openclaw.ai/providers/vercel-ai-gateway`.

View File

@@ -0,0 +1,13 @@
// Vercel Ai Gateway API module exposes the plugin public contract.
export {
discoverVercelAiGatewayModels,
getStaticVercelAiGatewayModelCatalog,
VERCEL_AI_GATEWAY_BASE_URL,
VERCEL_AI_GATEWAY_DEFAULT_CONTEXT_WINDOW,
VERCEL_AI_GATEWAY_DEFAULT_COST,
VERCEL_AI_GATEWAY_DEFAULT_MAX_TOKENS,
VERCEL_AI_GATEWAY_DEFAULT_MODEL_ID,
VERCEL_AI_GATEWAY_PROVIDER_ID,
} from "./models.js";
export { buildVercelAiGatewayProvider } from "./provider-catalog.js";
export { applyVercelAiGatewayConfig, VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF } from "./onboard.js";

View File

@@ -0,0 +1,22 @@
// Vercel Ai Gateway tests cover provider runtime hooks.
import { registerSingleProviderPlugin } from "openclaw/plugin-sdk/plugin-test-runtime";
import { describe, expect, it } from "vitest";
import plugin from "./index.js";
describe("vercel ai gateway provider hooks", () => {
it("resolves live-only model ids for the embedded runner", async () => {
const provider = await registerSingleProviderPlugin(plugin);
const model = provider.resolveDynamicModel?.({
provider: "vercel-ai-gateway",
modelId: "custom/provider-model",
modelRegistry: { find: () => null },
} as never);
expect(model).toMatchObject({
id: "custom/provider-model",
provider: "vercel-ai-gateway",
api: "anthropic-messages",
baseUrl: "https://ai-gateway.vercel.sh",
});
});
});

View File

@@ -0,0 +1,44 @@
// Vercel Ai Gateway plugin entrypoint registers its OpenClaw integration.
import { defineSingleProviderPluginEntry } from "openclaw/plugin-sdk/provider-entry";
import { applyVercelAiGatewayConfig, VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF } from "./onboard.js";
import {
buildStaticVercelAiGatewayProvider,
buildVercelAiGatewayProvider,
resolveVercelAiGatewayModel,
} from "./provider-catalog.js";
import { resolveVercelAiGatewayThinkingProfile } from "./thinking.js";
const PROVIDER_ID = "vercel-ai-gateway";
export default defineSingleProviderPluginEntry({
id: PROVIDER_ID,
name: "Vercel AI Gateway Provider",
description: "Bundled Vercel AI Gateway provider plugin",
provider: {
label: "Vercel AI Gateway",
docsPath: "/providers/vercel-ai-gateway",
auth: [
{
methodId: "api-key",
label: "Vercel AI Gateway API key",
hint: "API key",
optionKey: "aiGatewayApiKey",
flagName: "--ai-gateway-api-key",
envVar: "AI_GATEWAY_API_KEY",
promptMessage: "Enter Vercel AI Gateway API key",
defaultModel: VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF,
applyConfig: (cfg) => applyVercelAiGatewayConfig(cfg),
wizard: {
choiceId: "ai-gateway-api-key",
groupId: "ai-gateway",
},
},
],
catalog: {
buildProvider: buildVercelAiGatewayProvider,
buildStaticProvider: buildStaticVercelAiGatewayProvider,
},
resolveDynamicModel: ({ modelId }) => resolveVercelAiGatewayModel(modelId),
resolveThinkingProfile: ({ modelId }) => resolveVercelAiGatewayThinkingProfile(modelId),
},
});

View File

@@ -0,0 +1,240 @@
// Vercel Ai Gateway plugin module implements models behavior.
import { parseStrictFiniteNumber } from "openclaw/plugin-sdk/number-runtime";
import {
getCachedLiveProviderModelRows,
LiveModelCatalogHttpError,
} from "openclaw/plugin-sdk/provider-catalog-live-runtime";
import type { ModelDefinitionConfig } from "openclaw/plugin-sdk/provider-model-shared";
import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env";
import { asPositiveSafeInteger } from "openclaw/plugin-sdk/string-coerce-runtime";
export const VERCEL_AI_GATEWAY_PROVIDER_ID = "vercel-ai-gateway";
export const VERCEL_AI_GATEWAY_BASE_URL = "https://ai-gateway.vercel.sh";
export const VERCEL_AI_GATEWAY_DEFAULT_MODEL_ID = "anthropic/claude-opus-4.6";
export const VERCEL_AI_GATEWAY_DEFAULT_CONTEXT_WINDOW = 200_000;
export const VERCEL_AI_GATEWAY_DEFAULT_MAX_TOKENS = 128_000;
export const VERCEL_AI_GATEWAY_DEFAULT_COST = {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
} as const;
const log = createSubsystemLogger("agents/vercel-ai-gateway");
const VERCEL_AI_GATEWAY_DISCOVERY_CACHE_TTL_MS = 60_000;
const VERCEL_AI_GATEWAY_DISCOVERY_TIMEOUT_MS = 5000;
type VercelPricingShape = {
input?: number | string;
output?: number | string;
input_cache_read?: number | string;
input_cache_write?: number | string;
};
type VercelGatewayModelShape = {
id?: string;
name?: string;
context_window?: number;
max_tokens?: number;
tags?: string[];
pricing?: VercelPricingShape;
};
type StaticVercelGatewayModel = Omit<ModelDefinitionConfig, "cost"> & {
cost?: Partial<ModelDefinitionConfig["cost"]>;
};
const STATIC_VERCEL_AI_GATEWAY_MODEL_CATALOG: readonly StaticVercelGatewayModel[] = [
{
id: "anthropic/claude-opus-4.6",
name: "Claude Opus 4.6",
reasoning: true,
input: ["text", "image"],
contextWindow: 1_000_000,
maxTokens: 128_000,
cost: {
input: 5,
output: 25,
cacheRead: 0.5,
cacheWrite: 6.25,
},
},
{
id: "openai/gpt-5.4",
name: "GPT 5.4",
reasoning: true,
input: ["text", "image"],
contextWindow: 200_000,
maxTokens: 128_000,
cost: {
input: 2.5,
output: 15,
cacheRead: 0.25,
},
},
{
id: "openai/gpt-5.4-pro",
name: "GPT 5.4 Pro",
reasoning: true,
input: ["text", "image"],
contextWindow: 200_000,
maxTokens: 128_000,
cost: {
input: 30,
output: 180,
cacheRead: 0,
},
},
{
id: "moonshotai/kimi-k2.6",
name: "Kimi K2.6",
reasoning: true,
input: ["text", "image"],
contextWindow: 262_144,
maxTokens: 262_144,
cost: {
input: 0.95,
output: 4,
cacheRead: 0.16,
},
},
] as const;
function toPerMillionCost(value: number | string | undefined): number {
const numeric =
typeof value === "number"
? value
: typeof value === "string"
? parseStrictFiniteNumber(value)
: undefined;
if (numeric === undefined || numeric < 0) {
return 0;
}
return numeric * 1_000_000;
}
function normalizeCost(pricing?: VercelPricingShape): ModelDefinitionConfig["cost"] {
return {
input: toPerMillionCost(pricing?.input),
output: toPerMillionCost(pricing?.output),
cacheRead: toPerMillionCost(pricing?.input_cache_read),
cacheWrite: toPerMillionCost(pricing?.input_cache_write),
};
}
function buildStaticModelDefinition(model: StaticVercelGatewayModel): ModelDefinitionConfig {
return {
id: model.id,
name: model.name,
reasoning: model.reasoning,
input: model.input,
contextWindow: model.contextWindow,
maxTokens: model.maxTokens,
cost: {
...VERCEL_AI_GATEWAY_DEFAULT_COST,
...model.cost,
},
};
}
function getStaticFallbackModel(id: string): ModelDefinitionConfig | undefined {
const fallback = STATIC_VERCEL_AI_GATEWAY_MODEL_CATALOG.find((model) => model.id === id);
return fallback ? buildStaticModelDefinition(fallback) : undefined;
}
/** Builds runtime metadata for models returned by the live gateway catalog. */
export function resolveVercelAiGatewayDynamicModel(modelId: string): ModelDefinitionConfig {
return (
getStaticFallbackModel(modelId) ?? {
id: modelId,
name: modelId,
reasoning: false,
input: ["text"],
contextWindow: VERCEL_AI_GATEWAY_DEFAULT_CONTEXT_WINDOW,
maxTokens: VERCEL_AI_GATEWAY_DEFAULT_MAX_TOKENS,
cost: VERCEL_AI_GATEWAY_DEFAULT_COST,
}
);
}
export function getStaticVercelAiGatewayModelCatalog(): ModelDefinitionConfig[] {
return STATIC_VERCEL_AI_GATEWAY_MODEL_CATALOG.map(buildStaticModelDefinition);
}
function buildDiscoveredModelDefinition(
model: VercelGatewayModelShape,
): ModelDefinitionConfig | null {
const id = typeof model.id === "string" ? model.id.trim() : "";
if (!id) {
return null;
}
const fallback = getStaticFallbackModel(id);
const contextWindow =
asPositiveSafeInteger(model.context_window) ??
fallback?.contextWindow ??
VERCEL_AI_GATEWAY_DEFAULT_CONTEXT_WINDOW;
const maxTokens =
asPositiveSafeInteger(model.max_tokens) ??
fallback?.maxTokens ??
VERCEL_AI_GATEWAY_DEFAULT_MAX_TOKENS;
const normalizedCost = normalizeCost(model.pricing);
return {
id,
name: (typeof model.name === "string" ? model.name.trim() : "") || fallback?.name || id,
reasoning:
Array.isArray(model.tags) && model.tags.includes("reasoning")
? true
: (fallback?.reasoning ?? false),
input: Array.isArray(model.tags)
? model.tags.includes("vision")
? ["text", "image"]
: ["text"]
: (fallback?.input ?? ["text"]),
contextWindow,
maxTokens,
cost:
normalizedCost.input > 0 ||
normalizedCost.output > 0 ||
normalizedCost.cacheRead > 0 ||
normalizedCost.cacheWrite > 0
? normalizedCost
: (fallback?.cost ?? VERCEL_AI_GATEWAY_DEFAULT_COST),
};
}
function asVercelGatewayModelShape(value: unknown): VercelGatewayModelShape {
if (typeof value !== "object" || value === null || Array.isArray(value)) {
throw new Error("Vercel AI Gateway model list: malformed JSON response");
}
return value as VercelGatewayModelShape;
}
export async function discoverVercelAiGatewayModels(): Promise<ModelDefinitionConfig[]> {
if (process.env.VITEST || process.env.NODE_ENV === "test") {
return getStaticVercelAiGatewayModelCatalog();
}
try {
const data = await getCachedLiveProviderModelRows({
providerId: VERCEL_AI_GATEWAY_PROVIDER_ID,
endpoint: `${VERCEL_AI_GATEWAY_BASE_URL}/v1/models`,
timeoutMs: VERCEL_AI_GATEWAY_DISCOVERY_TIMEOUT_MS,
ttlMs: VERCEL_AI_GATEWAY_DISCOVERY_CACHE_TTL_MS,
auditContext: "vercel-ai-gateway.models",
});
const discovered = data
.map(asVercelGatewayModelShape)
.map(buildDiscoveredModelDefinition)
.filter((entry): entry is ModelDefinitionConfig => entry !== null);
return discovered.length > 0 ? discovered : getStaticVercelAiGatewayModelCatalog();
} catch (error) {
if (error instanceof LiveModelCatalogHttpError) {
log.warn(`Failed to discover Vercel AI Gateway models: HTTP ${error.status}`);
return getStaticVercelAiGatewayModelCatalog();
}
log.warn(`Failed to discover Vercel AI Gateway models: ${String(error)}`);
return getStaticVercelAiGatewayModelCatalog();
}
}

View File

@@ -0,0 +1,12 @@
{
"name": "@openclaw/vercel-ai-gateway-provider",
"version": "2026.6.11",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@openclaw/vercel-ai-gateway-provider",
"version": "2026.6.11"
}
}
}

View File

@@ -0,0 +1,33 @@
// Vercel Ai Gateway setup module handles plugin onboarding behavior.
import {
applyAgentDefaultModelPrimary,
type OpenClawConfig,
} from "openclaw/plugin-sdk/provider-onboard";
export const VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF = "vercel-ai-gateway/anthropic/claude-opus-4.6";
function applyVercelAiGatewayProviderConfig(cfg: OpenClawConfig): OpenClawConfig {
const models = { ...cfg.agents?.defaults?.models };
models[VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF] = {
...models[VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF],
alias: models[VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF]?.alias ?? "Vercel AI Gateway",
};
return {
...cfg,
agents: {
...cfg.agents,
defaults: {
...cfg.agents?.defaults,
models,
},
},
};
}
export function applyVercelAiGatewayConfig(cfg: OpenClawConfig): OpenClawConfig {
return applyAgentDefaultModelPrimary(
applyVercelAiGatewayProviderConfig(cfg),
VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF,
);
}

View File

@@ -0,0 +1,65 @@
{
"id": "vercel-ai-gateway",
"icon": "https://cdn.simpleicons.org/vercel",
"activation": {
"onStartup": false
},
"enabledByDefault": true,
"providers": ["vercel-ai-gateway"],
"modelIdNormalization": {
"providers": {
"vercel-ai-gateway": {
"aliases": {
"opus-4.6": "claude-opus-4-6",
"sonnet-4.6": "claude-sonnet-4-6"
},
"prefixWhenBareAfterAliasStartsWith": [
{
"modelPrefix": "claude-",
"prefix": "anthropic"
}
]
}
}
},
"modelPricing": {
"providers": {
"vercel-ai-gateway": {
"openRouter": {
"passthroughProviderModel": true
},
"liteLLM": {
"passthroughProviderModel": true
}
}
}
},
"setup": {
"providers": [
{
"id": "vercel-ai-gateway",
"envVars": ["AI_GATEWAY_API_KEY"]
}
]
},
"providerAuthChoices": [
{
"provider": "vercel-ai-gateway",
"method": "api-key",
"choiceId": "ai-gateway-api-key",
"choiceLabel": "Vercel AI Gateway API key",
"groupId": "ai-gateway",
"groupLabel": "Vercel AI Gateway",
"groupHint": "API key",
"optionKey": "aiGatewayApiKey",
"cliFlag": "--ai-gateway-api-key",
"cliOption": "--ai-gateway-api-key <key>",
"cliDescription": "Vercel AI Gateway API key"
}
],
"configSchema": {
"type": "object",
"additionalProperties": false,
"properties": {}
}
}

View File

@@ -0,0 +1,35 @@
{
"name": "@openclaw/vercel-ai-gateway-provider",
"version": "2026.6.11",
"description": "OpenClaw Vercel AI Gateway provider plugin",
"type": "module",
"devDependencies": {
"@openclaw/plugin-sdk": "workspace:*"
},
"openclaw": {
"extensions": [
"./index.ts"
],
"install": {
"clawhubSpec": "clawhub:@openclaw/vercel-ai-gateway-provider",
"npmSpec": "@openclaw/vercel-ai-gateway-provider",
"defaultChoice": "npm",
"minHostVersion": ">=2026.6.9"
},
"compat": {
"pluginApi": ">=2026.6.11"
},
"build": {
"openclawVersion": "2026.6.11",
"bundledDist": false
},
"release": {
"publishToClawHub": true,
"publishToNpm": true
}
},
"repository": {
"type": "git",
"url": "https://github.com/openclaw/openclaw"
}
}

View File

@@ -0,0 +1,189 @@
// Vercel Ai Gateway tests cover provider catalog plugin behavior.
import { clearLiveCatalogCacheForTests } from "openclaw/plugin-sdk/provider-catalog-live-runtime";
import { afterEach, describe, expect, it, vi } from "vitest";
const { fetchWithSsrFGuardMock } = vi.hoisted(() => ({
fetchWithSsrFGuardMock: vi.fn(),
}));
vi.mock("openclaw/plugin-sdk/ssrf-runtime", () => ({
fetchWithSsrFGuard: fetchWithSsrFGuardMock,
ssrfPolicyFromHttpBaseUrlAllowedHostname: (baseUrl: string) => ({
allowedHostnames: [new URL(baseUrl).hostname],
}),
}));
import {
discoverVercelAiGatewayModels,
getStaticVercelAiGatewayModelCatalog,
VERCEL_AI_GATEWAY_BASE_URL,
VERCEL_AI_GATEWAY_DEFAULT_CONTEXT_WINDOW,
VERCEL_AI_GATEWAY_DEFAULT_MAX_TOKENS,
} from "./api.js";
import { resolveVercelAiGatewayDynamicModel } from "./models.js";
import {
buildStaticVercelAiGatewayProvider,
buildVercelAiGatewayProvider,
resolveVercelAiGatewayModel,
} from "./provider-catalog.js";
const STATIC_MODEL_IDS = [
"anthropic/claude-opus-4.6",
"openai/gpt-5.4",
"openai/gpt-5.4-pro",
"moonshotai/kimi-k2.6",
];
function restoreEnvVar(name: "NODE_ENV" | "VITEST", value: string | undefined): void {
if (value === undefined) {
delete process.env[name];
} else {
process.env[name] = value;
}
}
async function withLiveDiscovery<T>(run: () => Promise<T>): Promise<T> {
const oldNodeEnv = process.env.NODE_ENV;
const oldVitest = process.env.VITEST;
delete process.env.NODE_ENV;
delete process.env.VITEST;
try {
return await run();
} finally {
restoreEnvVar("NODE_ENV", oldNodeEnv);
restoreEnvVar("VITEST", oldVitest);
}
}
function jsonResponse(payload: unknown, init: ResponseInit = {}): Response {
return new Response(JSON.stringify(payload), {
status: 200,
headers: { "Content-Type": "application/json" },
...init,
});
}
afterEach(() => {
clearLiveCatalogCacheForTests();
fetchWithSsrFGuardMock.mockReset();
});
describe("vercel ai gateway provider catalog", () => {
it("builds the bundled Vercel AI Gateway defaults", async () => {
const provider = await buildVercelAiGatewayProvider();
expect(provider).toStrictEqual({
baseUrl: VERCEL_AI_GATEWAY_BASE_URL,
api: "anthropic-messages",
models: getStaticVercelAiGatewayModelCatalog(),
});
});
it("exposes the static fallback model catalog", () => {
expect(getStaticVercelAiGatewayModelCatalog().map((model) => model.id)).toStrictEqual(
STATIC_MODEL_IDS,
);
});
it("builds an offline static provider catalog", () => {
expect(buildStaticVercelAiGatewayProvider()).toStrictEqual({
baseUrl: VERCEL_AI_GATEWAY_BASE_URL,
api: "anthropic-messages",
models: getStaticVercelAiGatewayModelCatalog(),
});
});
it("builds runtime metadata for live-only model ids", () => {
expect(resolveVercelAiGatewayDynamicModel("custom/provider-model")).toEqual({
id: "custom/provider-model",
name: "custom/provider-model",
reasoning: false,
input: ["text"],
contextWindow: VERCEL_AI_GATEWAY_DEFAULT_CONTEXT_WINDOW,
maxTokens: VERCEL_AI_GATEWAY_DEFAULT_MAX_TOKENS,
cost: {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
},
});
});
it("adds transport metadata for runtime model resolution", () => {
expect(resolveVercelAiGatewayModel("custom/provider-model")).toMatchObject({
id: "custom/provider-model",
provider: "vercel-ai-gateway",
api: "anthropic-messages",
baseUrl: VERCEL_AI_GATEWAY_BASE_URL,
});
});
it("preserves provider thinking metadata for known live-only upstream models", () => {
expect(resolveVercelAiGatewayModel("openai/gpt-5.5")).toMatchObject({
reasoning: true,
input: ["text", "image"],
});
expect(resolveVercelAiGatewayModel("anthropic/claude-sonnet-4-6")).toMatchObject({
input: ["text", "image"],
});
});
it("falls back to the static catalog for malformed successful model list payloads", async () => {
for (const payload of [[], { data: {} }, { data: [null] }]) {
clearLiveCatalogCacheForTests();
fetchWithSsrFGuardMock.mockReset();
fetchWithSsrFGuardMock.mockResolvedValueOnce({
response: jsonResponse(payload),
release: async () => {},
finalUrl: `${VERCEL_AI_GATEWAY_BASE_URL}/v1/models`,
});
await withLiveDiscovery(async () => {
expect(await discoverVercelAiGatewayModels()).toStrictEqual(
getStaticVercelAiGatewayModelCatalog(),
);
});
}
});
it("falls back from malformed live token metadata", async () => {
fetchWithSsrFGuardMock.mockResolvedValueOnce({
response: jsonResponse({
data: [
{
id: "anthropic/claude-opus-4.6",
name: "Claude Opus 4.6",
context_window: -1,
max_tokens: 128_000.5,
tags: ["vision", "reasoning"],
},
{
id: "custom/provider-model",
name: "Custom model",
context_window: Number.POSITIVE_INFINITY,
max_tokens: 0,
tags: ["reasoning"],
},
],
}),
release: async () => {},
finalUrl: `${VERCEL_AI_GATEWAY_BASE_URL}/v1/models`,
});
await withLiveDiscovery(async () => {
const models = await discoverVercelAiGatewayModels();
expect(models[0]).toMatchObject({
id: "anthropic/claude-opus-4.6",
contextWindow: 1_000_000,
maxTokens: 128_000,
});
expect(models[1]).toMatchObject({
id: "custom/provider-model",
contextWindow: VERCEL_AI_GATEWAY_DEFAULT_CONTEXT_WINDOW,
maxTokens: VERCEL_AI_GATEWAY_DEFAULT_MAX_TOKENS,
});
});
});
});

View File

@@ -0,0 +1,58 @@
// Vercel Ai Gateway provider module implements model/runtime integration.
import type { ModelProviderConfig } from "openclaw/plugin-sdk/provider-model-shared";
import {
discoverVercelAiGatewayModels,
getStaticVercelAiGatewayModelCatalog,
resolveVercelAiGatewayDynamicModel,
VERCEL_AI_GATEWAY_BASE_URL,
VERCEL_AI_GATEWAY_PROVIDER_ID,
} from "./models.js";
import { resolveVercelAiGatewayThinkingProfile } from "./thinking.js";
const VERCEL_AI_GATEWAY_IMAGE_MODEL_IDS = new Set([
"openai/gpt-5.5",
"openai/gpt-5.5-pro",
"openai/gpt-5.4",
"openai/gpt-5.4-pro",
"openai/gpt-5.4-mini",
"openai/gpt-5.4-nano",
"openai/gpt-5.3-codex",
"openai/gpt-5.3-codex-spark",
"openai/gpt-5.2",
"openai/gpt-5.2-codex",
"openai/gpt-5.1-codex",
]);
export function resolveVercelAiGatewayModel(modelId: string) {
const model = resolveVercelAiGatewayDynamicModel(modelId);
const input: Array<"text" | "image"> = model.input.includes("image")
? ["text", "image"]
: VERCEL_AI_GATEWAY_IMAGE_MODEL_IDS.has(modelId) ||
/^anthropic\/claude-(?:opus|sonnet|haiku)-/.test(modelId)
? ["text", "image"]
: ["text"];
return {
...model,
reasoning: model.reasoning || Boolean(resolveVercelAiGatewayThinkingProfile(modelId)),
input,
api: "anthropic-messages" as const,
provider: VERCEL_AI_GATEWAY_PROVIDER_ID,
baseUrl: VERCEL_AI_GATEWAY_BASE_URL,
};
}
export function buildStaticVercelAiGatewayProvider(): ModelProviderConfig {
return {
baseUrl: VERCEL_AI_GATEWAY_BASE_URL,
api: "anthropic-messages",
models: getStaticVercelAiGatewayModelCatalog(),
};
}
export async function buildVercelAiGatewayProvider(): Promise<ModelProviderConfig> {
return {
baseUrl: VERCEL_AI_GATEWAY_BASE_URL,
api: "anthropic-messages",
models: await discoverVercelAiGatewayModels(),
};
}

View File

@@ -0,0 +1,101 @@
// Vercel Ai Gateway tests cover thinking plugin behavior.
import {
registerProviderPlugin,
requireRegisteredProvider,
} from "openclaw/plugin-sdk/plugin-test-runtime";
import { describe, expect, it } from "vitest";
import plugin from "./index.js";
function collectLegacyExtendedLevelIds(levels: readonly { id: string }[] | undefined): string[] {
const ids: string[] = [];
for (const level of levels ?? []) {
if (level.id === "xhigh" || level.id === "max") {
ids.push(level.id);
}
}
return ids;
}
const OPENAI_XHIGH_LEVELS = [
{ id: "off" },
{ id: "minimal" },
{ id: "low" },
{ id: "medium" },
{ id: "high" },
{ id: "xhigh" },
];
const CLAUDE_ADAPTIVE_LEVELS = [
{ id: "off" },
{ id: "minimal" },
{ id: "low" },
{ id: "medium" },
{ id: "high" },
{ id: "adaptive" },
];
describe("vercel ai gateway thinking profile", () => {
async function getProvider() {
const { providers } = await registerProviderPlugin({
plugin,
id: "vercel-ai-gateway",
name: "Vercel AI Gateway Provider",
});
return requireRegisteredProvider(providers, "vercel-ai-gateway");
}
it("exposes xhigh for trusted OpenAI upstream refs", async () => {
const provider = await getProvider();
const profile = provider.resolveThinkingProfile?.({
provider: "vercel-ai-gateway",
modelId: "openai/gpt-5.4",
});
expect(profile).toStrictEqual({ levels: OPENAI_XHIGH_LEVELS });
});
it("exposes Codex xhigh through the OpenAI upstream prefix", async () => {
const provider = await getProvider();
const profile = provider.resolveThinkingProfile?.({
provider: "vercel-ai-gateway",
modelId: "openai/gpt-5.3-codex-spark",
});
expect(profile).toStrictEqual({ levels: OPENAI_XHIGH_LEVELS });
});
it("reuses Claude thinking defaults for trusted Anthropic upstream refs", async () => {
const provider = await getProvider();
const profile = provider.resolveThinkingProfile?.({
provider: "vercel-ai-gateway",
modelId: "anthropic/claude-opus-4.6",
});
expect(profile).toStrictEqual({
levels: CLAUDE_ADAPTIVE_LEVELS,
defaultLevel: "adaptive",
});
expect(collectLegacyExtendedLevelIds(profile?.levels)).toStrictEqual([]);
});
it("falls through for unsupported OpenAI or untrusted namespaced refs", async () => {
const provider = await getProvider();
const resolveThinkingProfile = provider.resolveThinkingProfile!;
expect(
resolveThinkingProfile({
provider: "vercel-ai-gateway",
modelId: "openai/gpt-4.1",
}),
).toBeUndefined();
expect(
resolveThinkingProfile({
provider: "vercel-ai-gateway",
modelId: "acme/gpt-5.4",
}),
).toBeUndefined();
});
});

View File

@@ -0,0 +1,78 @@
// Vercel Ai Gateway plugin module implements thinking behavior.
import type { ProviderThinkingProfile } from "openclaw/plugin-sdk/core";
import {
matchesExactOrPrefix,
resolveClaudeThinkingProfile,
} from "openclaw/plugin-sdk/provider-model-shared";
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
const UPSTREAM_OPENAI_PREFIX = "openai/";
const UPSTREAM_ANTHROPIC_PREFIX = "anthropic/";
const BASE_OPENAI_THINKING_LEVELS = [
{ id: "off" },
{ id: "minimal" },
{ id: "low" },
{ id: "medium" },
{ id: "high" },
] as const satisfies ProviderThinkingProfile["levels"];
const VERCEL_OPENAI_XHIGH_MODEL_IDS = [
"gpt-5.5",
"gpt-5.5-pro",
"gpt-5.4",
"gpt-5.4-pro",
"gpt-5.4-mini",
"gpt-5.4-nano",
"gpt-5.3-codex",
"gpt-5.2",
"gpt-5.2-codex",
"gpt-5.1-codex",
] as const;
function stripTrustedUpstreamPrefix(modelId: string, prefix: string): string | null {
const normalized = normalizeLowercaseStringOrEmpty(modelId);
if (!normalized.startsWith(prefix)) {
return null;
}
const upstreamModelId = normalized.slice(prefix.length).trim();
return upstreamModelId || null;
}
function resolveOpenAiThinkingProfile(modelId: string): ProviderThinkingProfile | undefined {
if (!matchesExactOrPrefix(modelId, VERCEL_OPENAI_XHIGH_MODEL_IDS)) {
return undefined;
}
return {
levels: [...BASE_OPENAI_THINKING_LEVELS, { id: "xhigh" }],
};
}
function hasVercelSpecificClaudeProfile(profile: ProviderThinkingProfile): boolean {
return Boolean(
profile.defaultLevel ||
profile.levels.some(
(level) => level.id === "adaptive" || level.id === "xhigh" || level.id === "max",
),
);
}
export function resolveVercelAiGatewayThinkingProfile(
modelId: string,
): ProviderThinkingProfile | undefined {
const openAiModelId = stripTrustedUpstreamPrefix(modelId, UPSTREAM_OPENAI_PREFIX);
if (openAiModelId) {
return resolveOpenAiThinkingProfile(openAiModelId);
}
const anthropicModelId = stripTrustedUpstreamPrefix(modelId, UPSTREAM_ANTHROPIC_PREFIX);
if (anthropicModelId) {
const profile = resolveClaudeThinkingProfile(anthropicModelId);
// Returning a base-only provider profile would hide catalog compat metadata
// from generic thinking resolution. Only take over when Claude has an
// upstream-specific default or elevated level set.
return hasVercelSpecificClaudeProfile(profile) ? profile : undefined;
}
return undefined;
}

View File

@@ -0,0 +1,16 @@
{
"extends": "../tsconfig.package-boundary.base.json",
"compilerOptions": {
"rootDir": "."
},
"include": ["./*.ts", "./src/**/*.ts"],
"exclude": [
"./**/*.test.ts",
"./dist/**",
"./node_modules/**",
"./src/test-support/**",
"./src/**/*test-helpers.ts",
"./src/**/*test-harness.ts",
"./src/**/*test-support.ts"
]
}