UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

112 lines (111 loc) • 3.9 kB
import "./src-H3RMXyFL.mjs"; import { t as expectDefined } from "./expect-DDakjvvQ.mjs"; import { r as normalizeProviderId } from "./provider-id-b5XGSf9C.mjs"; import { s as resolveAgentModelPrimaryValue } from "./model-input-DrM4DWHG.mjs"; import { i as isFeaturedAuthChoiceGroup, n as compareAuthChoiceGroups, t as buildAuthChoiceGroups } from "./auth-choice-options-BjS5hVuU.mjs"; //#region src/commands/auth-choice-prompt.ts const BACK_VALUE = "__back"; const MORE_VALUE = "__more"; const KEEP_CURRENT_AUTH_CHOICE = "__keep-current"; const PROVIDER_SEARCH_MESSAGE = "Model/auth provider\nProvider not listed? Find community provider plugins at https://clawhub.ai/plugins"; function isKeepCurrentAuthChoice(e) { return e === KEEP_CURRENT_AUTH_CHOICE; } function resolveConfiguredProvider(e) { const t = e?.indexOf("/") ?? -1; if (!e || t <= 0) return; return normalizeProviderId(e.slice(0, t)) || void 0; } function groupMatchesProvider(e, t) { if (!t) return false; return [e.value, ...e.providerIds ?? []].some((e) => normalizeProviderId(e) === t); } async function promptAuthChoiceGrouped(e) { const { groups: t, skipOption: n } = buildAuthChoiceGroups(e); const r = (e.allowedChoices ? t.map((t) => ({ ...t, options: t.options.filter((t) => e.allowedChoices?.has(t.value)) })) : t).filter((e) => e.options.length > 0); const i = (e.additionalGroups ?? []).filter((e) => e.options.length > 0); const a = [...r, ...i]; const isDetectedGroup = (t) => [...e.detectedProviderIds ?? []].some((e) => groupMatchesProvider(t, e)); const o = r.filter(isDetectedGroup).toSorted(compareAuthChoiceGroups); const s = [ ...i, ...o, ...r.filter((e) => !isDetectedGroup(e) && isFeaturedAuthChoiceGroup(e)).toSorted(compareAuthChoiceGroups) ]; const c = r.filter((e) => !isDetectedGroup(e) && !isFeaturedAuthChoiceGroup(e)).toSorted(compareAuthChoiceGroups); const l = resolveAgentModelPrimaryValue(e.config?.agents?.defaults?.model); const u = e.allowKeepCurrentProvider ? resolveConfiguredProvider(l) : void 0; const pickMethod = async (t) => { const n = groupMatchesProvider(t, u) ? { value: KEEP_CURRENT_AUTH_CHOICE, label: "Keep current config", ...l ? { hint: `Keep ${l}` } : {} } : void 0; if (t.options.length === 1 && !n) return expectDefined(t.options[0], "options entry at 0").value; return await e.prompter.select({ message: t.methodMessage ?? `${t.label} auth method`, options: [ ...n ? [n] : [], ...t.options, { value: BACK_VALUE, label: "Back" } ] }); }; const d = s.length > 0; let f = false; while (true) { const t = f || !d; const r = (t ? c : s).map((t) => { const n = groupMatchesProvider(t, u); const r = [...[...e.detectedProviderIds ?? []].some((e) => groupMatchesProvider(t, e)) ? ["detected"] : [], ...n ? ["currently configured"] : []]; return { value: t.value, label: r.length > 0 ? `${t.label} (${r.join(", ")})` : t.label, hint: t.hint }; }); if (f) r.push({ value: BACK_VALUE, label: "Back" }); else { if (d && c.length > 0) r.push({ value: MORE_VALUE, label: "More…" }); if (n) r.push({ value: n.value, label: n.label }); } const i = await e.prompter.select({ message: t ? PROVIDER_SEARCH_MESSAGE : "Model/auth provider", options: r, ...t ? { searchable: true } : {} }); if (f && i === BACK_VALUE) { f = false; continue; } if (!f && i === "skip") return "skip"; if (!f && d && i === MORE_VALUE) { f = true; continue; } const o = a.findLast((e) => e.value === i); if (!o || o.options.length === 0) { if (!f) await e.prompter.note("No auth methods available for that provider.", "Model/auth choice"); continue; } const l = await pickMethod(o); if (l !== BACK_VALUE) return l; } } //#endregion export { promptAuthChoiceGrouped as n, isKeepCurrentAuthChoice as t };