UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

64 lines (63 loc) • 3.08 kB
import { a as coerceSecretRef } from "./types.secrets-BmNLLnHp.mjs"; import { n as findNormalizedProviderValue } from "./provider-id-b5XGSf9C.mjs"; import { t as normalizeOptionalSecretInput } from "./normalize-secret-input-Cxkx67Fv.mjs"; import { a as resolveAuthProfileOrder, f as listProfilesForProvider } from "./order-jOvee2J6.mjs"; import { i as ensureAuthProfileStoreAsync } from "./store-runtime-dW0pXLJI.mjs"; import "./provider-auth-D_oAZ3fr.mjs"; import { i as resolveRequiredConfiguredSecretRefInputString, r as resolveConfiguredSecretInputWithFallback } from "./secret-input-runtime-BgioUt_I.mjs"; import { t as PUBLIC_GITHUB_COPILOT_DOMAIN } from "./domain-CmrCAfb-.mjs"; import { n as PROVIDER_ID } from "./models-BjkArA0g.mjs"; import { i as parseGithubCopilotApiKey, n as formatGithubCopilotApiKey } from "./oauth-_xjlpijO.mjs"; //#region extensions/github-copilot/auth.ts async function resolveFirstGithubToken(e) { const t = await ensureAuthProfileStoreAsync(e.agentDir, { allowKeychainPrompt: false }); const n = listProfilesForProvider(t, PROVIDER_ID); const r = n.length > 0; const i = e.profileId?.trim(); const a = normalizeOptionalSecretInput(e.env.COPILOT_GITHUB_TOKEN) ?? ""; const o = e.config?.models?.providers?.[PROVIDER_ID]; const s = o?.auth === void 0 || o.auth === "api-key" || o.auth === "token"; const c = s && Boolean(coerceSecretRef(o?.apiKey, e.config?.secrets?.defaults)) || o?.auth === "api-key" && Boolean(normalizeOptionalSecretInput(o.apiKey)); if (!i && (e.authProfileMode || c || a || !r)) { if (a && !c) return { githubToken: a }; if (!e.config) return { githubToken: "" }; const t = await resolveConfiguredSecretInputWithFallback({ config: e.config, env: e.env, value: s ? o?.apiKey : normalizeOptionalSecretInput(o?.apiKey), path: `models.providers.${PROVIDER_ID}.apiKey`, readFallback: () => "" }); if (t.secretRefConfigured && !t.value) throw new Error(t.unresolvedRefReason ?? `models.providers.${"github-copilot"}.apiKey SecretRef is unresolved.`); return { githubToken: t.value?.trim() || a }; } const l = findNormalizedProviderValue(t.order, "github-copilot") ?? findNormalizedProviderValue(e.config?.auth?.order, "github-copilot"); const u = i ? n.find((e) => e === i) : l === void 0 ? n[0] : resolveAuthProfileOrder({ cfg: e.config, store: t, provider: PROVIDER_ID })[0]; const d = u ? t.profiles[u] : void 0; if (d?.type === "oauth") { const e = formatGithubCopilotApiKey(d); if (!normalizeOptionalSecretInput(d.refresh)) return { githubToken: "" }; const t = parseGithubCopilotApiKey(e); return { ...t, githubDomain: t.githubDomain ?? "github.com", profileId: u }; } if (d?.type !== "token") return { githubToken: "" }; return { githubToken: (await resolveRequiredConfiguredSecretRefInputString({ config: e.config ?? {}, env: e.env, value: d.tokenRef, path: `providers.github-copilot.authProfiles.${u ?? "default"}.tokenRef` }) ?? d.token ?? "").trim(), profileId: u }; } //#endregion export { resolveFirstGithubToken as t };