mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-16 05:30:46 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
12
openclaw/extensions/vercel-ai-gateway/api.ts
Normal file
12
openclaw/extensions/vercel-ai-gateway/api.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
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";
|
||||
35
openclaw/extensions/vercel-ai-gateway/index.ts
Normal file
35
openclaw/extensions/vercel-ai-gateway/index.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { defineSingleProviderPluginEntry } from "openclaw/plugin-sdk/provider-entry";
|
||||
import { applyVercelAiGatewayConfig, VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF } from "./onboard.js";
|
||||
import { buildVercelAiGatewayProvider } from "./provider-catalog.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,
|
||||
},
|
||||
},
|
||||
});
|
||||
197
openclaw/extensions/vercel-ai-gateway/models.ts
Normal file
197
openclaw/extensions/vercel-ai-gateway/models.ts
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
import type { ModelDefinitionConfig } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import { createSubsystemLogger } from "openclaw/plugin-sdk/runtime-env";
|
||||
|
||||
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_MODEL_REF = `${VERCEL_AI_GATEWAY_PROVIDER_ID}/${VERCEL_AI_GATEWAY_DEFAULT_MODEL_ID}`;
|
||||
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");
|
||||
|
||||
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 VercelGatewayModelsResponse = {
|
||||
data?: VercelGatewayModelShape[];
|
||||
};
|
||||
|
||||
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,
|
||||
},
|
||||
},
|
||||
] as const;
|
||||
|
||||
function toPerMillionCost(value: number | string | undefined): number {
|
||||
const numeric =
|
||||
typeof value === "number"
|
||||
? value
|
||||
: typeof value === "string"
|
||||
? Number.parseFloat(value)
|
||||
: Number.NaN;
|
||||
if (!Number.isFinite(numeric) || 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;
|
||||
}
|
||||
|
||||
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 =
|
||||
typeof model.context_window === "number" && Number.isFinite(model.context_window)
|
||||
? model.context_window
|
||||
: (fallback?.contextWindow ?? VERCEL_AI_GATEWAY_DEFAULT_CONTEXT_WINDOW);
|
||||
const maxTokens =
|
||||
typeof model.max_tokens === "number" && Number.isFinite(model.max_tokens)
|
||||
? 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),
|
||||
};
|
||||
}
|
||||
|
||||
export async function discoverVercelAiGatewayModels(): Promise<ModelDefinitionConfig[]> {
|
||||
if (process.env.VITEST || process.env.NODE_ENV === "test") {
|
||||
return getStaticVercelAiGatewayModelCatalog();
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${VERCEL_AI_GATEWAY_BASE_URL}/v1/models`, {
|
||||
signal: AbortSignal.timeout(5000),
|
||||
});
|
||||
if (!response.ok) {
|
||||
log.warn(`Failed to discover Vercel AI Gateway models: HTTP ${response.status}`);
|
||||
return getStaticVercelAiGatewayModelCatalog();
|
||||
}
|
||||
const data = (await response.json()) as VercelGatewayModelsResponse;
|
||||
const discovered = (data.data ?? [])
|
||||
.map(buildDiscoveredModelDefinition)
|
||||
.filter((entry): entry is ModelDefinitionConfig => entry !== null);
|
||||
return discovered.length > 0 ? discovered : getStaticVercelAiGatewayModelCatalog();
|
||||
} catch (error) {
|
||||
log.warn(`Failed to discover Vercel AI Gateway models: ${String(error)}`);
|
||||
return getStaticVercelAiGatewayModelCatalog();
|
||||
}
|
||||
}
|
||||
32
openclaw/extensions/vercel-ai-gateway/onboard.ts
Normal file
32
openclaw/extensions/vercel-ai-gateway/onboard.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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";
|
||||
|
||||
export 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,
|
||||
);
|
||||
}
|
||||
28
openclaw/extensions/vercel-ai-gateway/openclaw.plugin.json
Normal file
28
openclaw/extensions/vercel-ai-gateway/openclaw.plugin.json
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"id": "vercel-ai-gateway",
|
||||
"enabledByDefault": true,
|
||||
"providers": ["vercel-ai-gateway"],
|
||||
"providerAuthEnvVars": {
|
||||
"vercel-ai-gateway": ["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": {}
|
||||
}
|
||||
}
|
||||
15
openclaw/extensions/vercel-ai-gateway/package.json
Normal file
15
openclaw/extensions/vercel-ai-gateway/package.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "@openclaw/vercel-ai-gateway-provider",
|
||||
"version": "2026.4.20",
|
||||
"private": true,
|
||||
"description": "OpenClaw Vercel AI Gateway provider plugin",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@openclaw/plugin-sdk": "workspace:*"
|
||||
},
|
||||
"openclaw": {
|
||||
"extensions": [
|
||||
"./index.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { getStaticVercelAiGatewayModelCatalog, VERCEL_AI_GATEWAY_BASE_URL } from "./api.js";
|
||||
import { buildVercelAiGatewayProvider } from "./provider-catalog.js";
|
||||
|
||||
describe("vercel ai gateway provider catalog", () => {
|
||||
it("builds the bundled Vercel AI Gateway defaults", async () => {
|
||||
const provider = await buildVercelAiGatewayProvider();
|
||||
|
||||
expect(provider.baseUrl).toBe(VERCEL_AI_GATEWAY_BASE_URL);
|
||||
expect(provider.api).toBe("anthropic-messages");
|
||||
expect(provider.models?.map((model) => model.id)).toEqual(
|
||||
expect.arrayContaining(["anthropic/claude-opus-4.6", "openai/gpt-5.4", "openai/gpt-5.4-pro"]),
|
||||
);
|
||||
});
|
||||
|
||||
it("exposes the static fallback model catalog", () => {
|
||||
expect(getStaticVercelAiGatewayModelCatalog().map((model) => model.id)).toEqual(
|
||||
expect.arrayContaining(["anthropic/claude-opus-4.6", "openai/gpt-5.4", "openai/gpt-5.4-pro"]),
|
||||
);
|
||||
});
|
||||
});
|
||||
10
openclaw/extensions/vercel-ai-gateway/provider-catalog.ts
Normal file
10
openclaw/extensions/vercel-ai-gateway/provider-catalog.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import type { ModelProviderConfig } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import { discoverVercelAiGatewayModels, VERCEL_AI_GATEWAY_BASE_URL } from "./models.js";
|
||||
|
||||
export async function buildVercelAiGatewayProvider(): Promise<ModelProviderConfig> {
|
||||
return {
|
||||
baseUrl: VERCEL_AI_GATEWAY_BASE_URL,
|
||||
api: "anthropic-messages",
|
||||
models: await discoverVercelAiGatewayModels(),
|
||||
};
|
||||
}
|
||||
16
openclaw/extensions/vercel-ai-gateway/tsconfig.json
Normal file
16
openclaw/extensions/vercel-ai-gateway/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue