UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

117 lines (116 loc) • 4.44 kB
import { b as uniqueStrings } from "./string-normalization-DLmfYZXI.mjs"; import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs"; import { n as isFeaturedProviderAuthChoiceGroup, t as compareProviderAuthChoiceGroups } from "./provider-auth-choice-order-D6QUq1jj.mjs"; import { t as resolveProviderSetupFlowContributions } from "./provider-flow-TE5CeWLa.mjs"; //#region src/commands/auth-choice-options.static.ts const CORE_AUTH_CHOICE_OPTIONS = [{ value: "custom-api-key", label: "Custom Provider", hint: "Any OpenAI or Anthropic compatible endpoint", groupId: "custom", groupLabel: "Custom Provider", groupHint: "Any OpenAI or Anthropic compatible endpoint" }]; /** * Provider-agnostic auth choices that `--token-provider` binds to a concrete * provider method. They stay out of `CORE_AUTH_CHOICE_OPTIONS` because the * interactive picker only offers self-contained choices, but every CLI surface * must advertise and accept them even when no manifest contributes the same id. */ const GENERIC_PROVIDER_AUTH_CHOICES = [ "setup-token", "token", "apiKey" ]; /** Format static auth-choice values for Commander help/validation text. */ function formatStaticAuthChoiceChoicesForCli() { return [ ...CORE_AUTH_CHOICE_OPTIONS.map((e) => e.value), ...GENERIC_PROVIDER_AUTH_CHOICES, "skip" ].join("|"); } //#endregion //#region src/commands/auth-choice-options.ts function compareOptionLabels(e, t) { return e.label.localeCompare(t.label); } /** Keep the first-tier provider list stable; every other group belongs under More. */ function isFeaturedAuthChoiceGroup(e) { return isFeaturedProviderAuthChoiceGroup(e.value); } /** Sort auth-choice groups with featured providers first, then stable labels. */ function compareAuthChoiceGroups(e, t) { return compareProviderAuthChoiceGroups({ id: e.value, label: e.label }, { id: t.value, label: t.label }); } /** * Format every accepted `--auth-choice` value for CLI help and validation. * * This is the single owner of that set: help text, onboard preflight, and the * non-interactive dispatcher all render it, so an advertised value is always an * accepted one. Deprecated aliases stay out; `auth-choice-legacy.ts` normalizes * them before any surface sees them. */ function formatAuthChoiceChoicesForCli(e) { const t = [...formatStaticAuthChoiceChoicesForCli().split("|"), ...resolveProviderSetupFlowContributions({ ...e, scope: "all" }).map((e) => e.option.value)]; return uniqueStrings(t).join("|"); } /** Build grouped auth choices, filtering manual-only methods by default. */ function buildAuthChoiceGroups(e) { const t = new Map(CORE_AUTH_CHOICE_OPTIONS.map((e) => [e.value, e])); for (const { option: { group: n, ...r }, providerId: i } of resolveProviderSetupFlowContributions({ config: e.config, workspaceDir: e.workspaceDir, env: e.env, scope: "text-inference" })) t.set(r.value, { ...r, providerId: i, ...n ? { groupId: n.id, groupLabel: n.label, ...n.hint ? { groupHint: n.hint } : {} } : {} }); const n = new Set([...e.detectedProviderIds ?? []].map(normalizeProviderId)); const r = Array.from(t.values()).toSorted(compareOptionLabels).filter((e) => e.assistantVisibility !== "detected-only" || e.providerId !== void 0 && n.has(normalizeProviderId(e.providerId))).filter((t) => e.assistantVisibleOnly !== false ? t.assistantVisibility !== "manual-only" : true); const i = /* @__PURE__ */ new Map(); for (const e of r) { if (!e.groupId || !e.groupLabel) continue; const t = i.get(e.groupId); if (t) { t.options.push(e); if (e.providerId) t.providerIds = uniqueStrings([...t.providerIds ?? [], e.providerId]); continue; } const n = e.providerId ? [e.providerId] : []; i.set(e.groupId, { value: e.groupId, label: e.groupLabel, ...e.groupHint ? { hint: e.groupHint } : {}, ...n.length > 0 ? { providerIds: n } : {}, options: [e] }); } for (const e of i.values()) e.options = e.options.toSorted((e, t) => { return (e.assistantPriority ?? 0) - (t.assistantPriority ?? 0) || compareOptionLabels(e, t); }); return { groups: Array.from(i.values()).toSorted(compareAuthChoiceGroups), skipOption: e.includeSkip ? { value: "skip", label: "Skip for now" } : void 0 }; } //#endregion export { GENERIC_PROVIDER_AUTH_CHOICES as a, isFeaturedAuthChoiceGroup as i, compareAuthChoiceGroups as n, formatAuthChoiceChoicesForCli as r, buildAuthChoiceGroups as t };