
























@@ -1,3 +1,4 @@
1+import { parseRegistryNpmSpec } from "../../infra/npm-registry-spec.js";
12import { isBlockedObjectKey } from "../../infra/prototype-keys.js";
23import { normalizeOptionalString } from "../../shared/string-coerce.js";
34import { normalizeTrimmedStringList } from "../../shared/string-normalization.js";
@@ -7,7 +8,9 @@ import { normalizeModelCatalogProviderId } from "../refs.js";
78import type { ModelCatalogProvider } from "../types.js";
89import type {
910OpenClawProviderIndex,
11+OpenClawProviderIndexPluginInstall,
1012OpenClawProviderIndexPlugin,
13+OpenClawProviderIndexProviderAuthChoice,
1114OpenClawProviderIndexProvider,
1215} from "./types.js";
1316@@ -18,6 +21,26 @@ function normalizeSafeKey(value: unknown): string {
1821return key && !isBlockedObjectKey(key) ? key : "";
1922}
202324+function normalizeInstall(value: unknown): OpenClawProviderIndexPluginInstall | undefined {
25+if (!isRecord(value)) {
26+return undefined;
27+}
28+const npmSpec = normalizeOptionalString(value.npmSpec);
29+const parsed = npmSpec ? parseRegistryNpmSpec(npmSpec) : null;
30+if (!parsed) {
31+return undefined;
32+}
33+const defaultChoice = value.defaultChoice === "npm" ? "npm" : undefined;
34+const minHostVersion = normalizeOptionalString(value.minHostVersion);
35+const expectedIntegrity = normalizeOptionalString(value.expectedIntegrity);
36+return {
37+npmSpec: parsed.raw,
38+ ...(defaultChoice ? { defaultChoice } : {}),
39+ ...(minHostVersion ? { minHostVersion } : {}),
40+ ...(expectedIntegrity ? { expectedIntegrity } : {}),
41+};
42+}
43+2144function normalizePlugin(value: unknown): OpenClawProviderIndexPlugin | undefined {
2245if (!isRecord(value)) {
2346return undefined;
@@ -28,10 +51,12 @@ function normalizePlugin(value: unknown): OpenClawProviderIndexPlugin | undefine
2851}
2952const packageName = normalizeOptionalString(value.package) ?? "";
3053const source = normalizeOptionalString(value.source) ?? "";
54+const install = normalizeInstall(value.install);
3155return {
3256 id,
3357 ...(packageName ? { package: packageName } : {}),
3458 ...(source ? { source } : {}),
59+ ...(install ? { install } : {}),
3560};
3661}
3762@@ -57,6 +82,83 @@ function normalizePreviewCatalog(params: {
5782return provider;
5883}
598485+function normalizeOnboardingScopes(
86+value: unknown,
87+): OpenClawProviderIndexProviderAuthChoice["onboardingScopes"] | undefined {
88+const scopes = normalizeTrimmedStringList(value).filter(
89+(scope): scope is "text-inference" | "image-generation" =>
90+scope === "text-inference" || scope === "image-generation",
91+);
92+return scopes.length > 0 ? [...new Set(scopes)] : undefined;
93+}
94+95+function normalizeAssistantVisibility(
96+value: unknown,
97+): OpenClawProviderIndexProviderAuthChoice["assistantVisibility"] | undefined {
98+return value === "visible" || value === "manual-only" ? value : undefined;
99+}
100+101+function normalizeFiniteNumber(value: unknown): number | undefined {
102+return typeof value === "number" && Number.isFinite(value) ? value : undefined;
103+}
104+105+function normalizeAuthChoice(params: {
106+providerId: string;
107+providerName: string;
108+value: unknown;
109+}): OpenClawProviderIndexProviderAuthChoice | undefined {
110+if (!isRecord(params.value)) {
111+return undefined;
112+}
113+const method = normalizeSafeKey(params.value.method);
114+const choiceId = normalizeSafeKey(params.value.choiceId);
115+const choiceLabel = normalizeOptionalString(params.value.choiceLabel) ?? "";
116+if (!method || !choiceId || !choiceLabel) {
117+return undefined;
118+}
119+const choiceHint = normalizeOptionalString(params.value.choiceHint);
120+const groupId = normalizeSafeKey(params.value.groupId) || params.providerId;
121+const groupLabel = normalizeOptionalString(params.value.groupLabel) ?? params.providerName;
122+const groupHint = normalizeOptionalString(params.value.groupHint);
123+const optionKey = normalizeSafeKey(params.value.optionKey);
124+const cliFlag = normalizeOptionalString(params.value.cliFlag);
125+const cliOption = normalizeOptionalString(params.value.cliOption);
126+const cliDescription = normalizeOptionalString(params.value.cliDescription);
127+const assistantPriority = normalizeFiniteNumber(params.value.assistantPriority);
128+const assistantVisibility = normalizeAssistantVisibility(params.value.assistantVisibility);
129+const onboardingScopes = normalizeOnboardingScopes(params.value.onboardingScopes);
130+return {
131+ method,
132+ choiceId,
133+ choiceLabel,
134+ ...(choiceHint ? { choiceHint } : {}),
135+ ...(assistantPriority !== undefined ? { assistantPriority } : {}),
136+ ...(assistantVisibility ? { assistantVisibility } : {}),
137+ ...(groupId ? { groupId } : {}),
138+ ...(groupLabel ? { groupLabel } : {}),
139+ ...(groupHint ? { groupHint } : {}),
140+ ...(optionKey ? { optionKey } : {}),
141+ ...(cliFlag ? { cliFlag } : {}),
142+ ...(cliOption ? { cliOption } : {}),
143+ ...(cliDescription ? { cliDescription } : {}),
144+ ...(onboardingScopes ? { onboardingScopes } : {}),
145+};
146+}
147+148+function normalizeAuthChoices(params: {
149+providerId: string;
150+providerName: string;
151+value: unknown;
152+}): readonly OpenClawProviderIndexProviderAuthChoice[] | undefined {
153+if (!Array.isArray(params.value)) {
154+return undefined;
155+}
156+const choices = params.value
157+.map((value) => normalizeAuthChoice({ ...params, value }))
158+.filter((choice): choice is OpenClawProviderIndexProviderAuthChoice => Boolean(choice));
159+return choices.length > 0 ? choices : undefined;
160+}
161+60162function normalizeProvider(
61163rawProviderId: string,
62164value: unknown,
@@ -79,6 +181,11 @@ function normalizeProvider(
79181}
80182const docs = normalizeOptionalString(value.docs) ?? "";
81183const categories = normalizeCategories(value.categories);
184+const authChoices = normalizeAuthChoices({
185+ providerId,
186+providerName: name,
187+value: value.authChoices,
188+});
82189const previewCatalog = normalizePreviewCatalog({
83190 providerId,
84191value: value.previewCatalog,
@@ -89,6 +196,7 @@ function normalizeProvider(
89196 plugin,
90197 ...(docs ? { docs } : {}),
91198 ...(categories.length > 0 ? { categories } : {}),
199+ ...(authChoices ? { authChoices } : {}),
92200 ...(previewCatalog ? { previewCatalog } : {}),
93201};
94202}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。