UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

38 lines (37 loc) • 1.95 kB
import { t as createOpenAIProviderMetadata, u as isSIWCAuthFlow } from "./provider-metadata-h9vYLGeZ.mjs"; import { i as resolveServiceTiers, r as resolveFastModeSupport } from "./provider-policy-api-Bmb4R8Si.mjs"; import { asNonArrayRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime"; import { decodeOpenAICodexJwtPayload } from "openclaw/plugin-sdk/provider-oauth-runtime"; //#region extensions/openai/provider-contract-api.ts const matchesTokenSharingAccount = (e, t) => { if (e.type !== "oauth" || t.type !== "oauth" || e.provider !== "openai" || t.provider !== "openai" || !isSIWCAuthFlow(e.authFlow) || !isSIWCAuthFlow(t.authFlow) || !e.idToken || !t.idToken || !e.clientId || e.clientId !== t.clientId) return false; const n = decodeOpenAICodexJwtPayload(e.idToken); const r = decodeOpenAICodexJwtPayload(t.idToken); return Boolean(n?.sub && n.sub === r?.sub && n.iss === r?.iss); }; function accountSubject(e) { const t = asNonArrayRecord(decodeOpenAICodexJwtPayload(e)?.["https://api.openai.com/auth"]); const n = normalizeOptionalString(t.chatgpt_account_id); const r = normalizeOptionalString(t.chatgpt_user_id) ?? normalizeOptionalString(t.user_id); return n && r ? { accountId: n, userId: r } : void 0; } const matchesPersonalAccount = (e, t) => { if (e.type !== "oauth" || t.type !== "oauth" || e.provider !== "openai" || t.provider !== e.provider) return false; const n = accountSubject(e.access); const r = accountSubject(t.access); return Boolean(n && r?.accountId === n.accountId && r.userId === n.userId); }; function createOpenAIProvider() { const e = createOpenAIProviderMetadata(); for (const t of e.auth) if (t.kind === "oauth" || t.kind === "device_code") t.matchesPersonalAccount = t.id === "siwc" ? matchesTokenSharingAccount : matchesPersonalAccount; return { ...e, resolveFastModeSupport, resolveServiceTiers }; } //#endregion export { createOpenAIProvider as t };