



















1+// ClawRouter plugin entrypoint registers credential-scoped model routing.
2+import { definePluginEntry, type ProviderAuthMethod } from "openclaw/plugin-sdk/plugin-entry";
3+import { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth-api-key";
4+import { PASSTHROUGH_GEMINI_REPLAY_HOOKS } from "openclaw/plugin-sdk/provider-model-shared";
5+import {
6+buildClawRouterProviderConfig,
7+normalizeClawRouterApiBaseUrl,
8+normalizeClawRouterResolvedModel,
9+resolveDiscoveredClawRouterModel,
10+} from "./provider-catalog.js";
11+12+const PROVIDER_ID = "clawrouter";
13+const ENV_VAR = "CLAWROUTER_API_KEY";
14+15+function buildApiKeyAuth(): ProviderAuthMethod {
16+return createProviderApiKeyAuthMethod({
17+providerId: PROVIDER_ID,
18+methodId: "api-key",
19+label: "ClawRouter proxy key",
20+hint: "Credential-scoped access to approved providers",
21+optionKey: "clawrouterApiKey",
22+flagName: "--clawrouter-api-key",
23+envVar: ENV_VAR,
24+promptMessage: "Enter ClawRouter proxy key",
25+noteTitle: "ClawRouter",
26+noteMessage: [
27+"Use the proxy key issued by your ClawRouter administrator.",
28+"OpenClaw discovers only the models granted to that key.",
29+].join("\n"),
30+wizard: {
31+choiceId: "clawrouter-api-key",
32+choiceLabel: "ClawRouter proxy key",
33+choiceHint: "Approved providers through one managed key",
34+groupId: PROVIDER_ID,
35+groupLabel: "ClawRouter",
36+groupHint: "Managed provider access",
37+},
38+});
39+}
40+41+export default definePluginEntry({
42+id: PROVIDER_ID,
43+name: "ClawRouter Provider",
44+description: "Bundled ClawRouter provider plugin",
45+register(api) {
46+api.registerProvider({
47+id: PROVIDER_ID,
48+label: "ClawRouter",
49+docsPath: "/providers/clawrouter",
50+envVars: [ENV_VAR],
51+auth: [buildApiKeyAuth()],
52+catalog: {
53+order: "simple",
54+run: async (ctx) => {
55+const auth = ctx.resolveProviderApiKey(PROVIDER_ID);
56+const apiKey = auth.apiKey ?? auth.discoveryApiKey;
57+if (!apiKey) {
58+return null;
59+}
60+const configuredBaseUrl = ctx.config.models?.providers?.[PROVIDER_ID]?.baseUrl;
61+try {
62+return {
63+provider: await buildClawRouterProviderConfig({
64+ apiKey,
65+discoveryApiKey: auth.discoveryApiKey,
66+baseUrl: configuredBaseUrl,
67+}),
68+};
69+} catch {
70+return null;
71+}
72+},
73+},
74+normalizeConfig: ({ providerConfig }) => {
75+const baseUrl = normalizeClawRouterApiBaseUrl(providerConfig.baseUrl);
76+return baseUrl !== providerConfig.baseUrl ? { ...providerConfig, baseUrl } : undefined;
77+},
78+resolveDynamicModel: ({ modelId, providerConfig }) =>
79+resolveDiscoveredClawRouterModel({
80+baseUrl: providerConfig?.baseUrl,
81+ modelId,
82+}),
83+normalizeResolvedModel: ({ model }) => normalizeClawRouterResolvedModel(model),
84+ ...PASSTHROUGH_GEMINI_REPLAY_HOOKS,
85+isModernModelRef: () => true,
86+});
87+},
88+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。