UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

77 lines (76 loc) • 2.62 kB
import { c as TOKEN_SHARING_RESOURCE, r as TOKEN_SHARING_AUTH_FLOW } from "./provider-metadata-h9vYLGeZ.mjs"; import { isNonSecretApiKeyMarker } from "openclaw/plugin-sdk/provider-auth-markers"; import { DEFAULT_CONTEXT_TOKENS } from "openclaw/plugin-sdk/provider-model-metadata"; import { asOptionalRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime"; import { LiveModelCatalogHttpError, getCachedLiveProviderModelRows } from "openclaw/plugin-sdk/provider-catalog-live-runtime"; //#region extensions/openai/token-sharing-catalog.ts /** SIWC model discovery uses the already-prepared inference profile, never Codex auth. */ async function buildTokenSharingCatalog(e) { const { auth: t } = e; const n = t.authFlow === TOKEN_SHARING_AUTH_FLOW; let r = n ? e.models.filter((e) => e.api === "openai-responses") : []; let i = n ? "unavailable" : "auth-rejected"; let a; const o = t.preparationFailed ? void 0 : t.discoveryApiKey ?? (t.apiKey && !isNonSecretApiKeyMarker(t.apiKey) ? t.apiKey : void 0); if (n && o) try { const t = await getCachedLiveProviderModelRows({ providerId: "openai", endpoint: `${TOKEN_SHARING_RESOURCE}/models`, discoveryApiKey: o, signal: e.signal, ttlMs: 6e4, auditContext: "openai-model-discovery", readRows: (e) => { const t = asOptionalRecord(e)?.models; if (!Array.isArray(t)) throw new Error("SIWC model discovery response must be { models: [] }"); return t; } }); const n = new Map(r.map((e) => [e.id, e])); r = t.flatMap((e) => { const t = asOptionalRecord(e); const r = normalizeOptionalString(t?.slug); if (t?.visibility !== "list" || !r) return []; return [{ reasoning: false, input: ["text"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: DEFAULT_CONTEXT_TOKENS, maxTokens: 128e3, ...n.get(r), id: r, name: normalizeOptionalString(t.display_name) ?? r, api: "openai-responses", baseUrl: TOKEN_SHARING_RESOURCE }]; }); i = "ready"; } catch (e) { if (e instanceof LiveModelCatalogHttpError && (e.status === 401 || e.status === 403)) { r = []; i = "auth-rejected"; a = e.status === 403 ? "catalog" : void 0; } } return { providers: { openai: { baseUrl: TOKEN_SHARING_RESOURCE, api: "openai-responses", models: r } }, outcomes: [{ provider: "openai", profileId: t.profileId, status: i, ...a ? { rejectionScope: a } : {}, ...i === "ready" ? { modelOrder: r.map(({ id: e }) => e) } : {} }] }; } //#endregion export { buildTokenSharingCatalog };