UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

98 lines (97 loc) • 3.11 kB
//#region extensions/openai/token-sharing.ts /** These markers describe the grant actually returned by OpenAI, not requested scopes. */ const TOKEN_SHARING_AUTH_FLOW = "chatgpt-token-sharing"; const IDENTITY_AUTH_FLOW = "chatgpt-identity"; const TOKEN_SHARING_RESOURCE = "https://api.openai.com/v1"; const TOKEN_SHARING_ISSUER = "https://auth.openai.com"; const TOKEN_SHARING_REDIRECT_URI = "http://localhost:0/auth/callback"; const TOKEN_SHARING_SCOPE = "openid email profile resource.invoke chatgpt.tokens.use.direct offline_access"; const TOKEN_SHARING_LEGACY_SCOPE = "openid resource.invoke chatgpt.tokens.use.direct offline_access"; const TOKEN_SHARING_CLIENT_ID = "dynamic_agent_client"; function isSIWCAuthFlow(e) { return e === "chatgpt-token-sharing" || e === "chatgpt-identity"; } //#endregion //#region extensions/openai/provider-metadata.ts const noopAuth = async () => ({ profiles: [] }); const OPENAI_ACCOUNT_WIZARD_GROUP = { groupId: "openai", groupLabel: "OpenAI", groupHint: "Codex login, Sign in with ChatGPT, or API key" }; const CODEX_CHATGPT_IMPORT = { migrationProviderId: "codex", itemId: "auth:openai", credentialKind: "oauth" }; const CODEX_API_KEY_IMPORT = { migrationProviderId: "codex", itemId: "auth:openai:api-key", credentialKind: "api_key" }; function createOpenAIProviderMetadata() { return { id: "openai", label: "OpenAI", hookAliases: ["azure-openai", "azure-openai-responses"], docsPath: "/providers/models", envVars: ["OPENAI_API_KEY"], auth: [ { id: "oauth", kind: "oauth", label: "Codex login (browser)", hint: "Sign in to Codex locally with your ChatGPT account", credentialImport: CODEX_CHATGPT_IMPORT, wizard: { choiceId: "openai", assistantPriority: -10 } }, { id: "device-code", kind: "device_code", label: "Codex login (device code)", hint: "Use a browser code when OpenClaw runs on a remote VM", credentialImport: CODEX_CHATGPT_IMPORT, wizard: { choiceId: "openai-device-code", assistantPriority: -40, onboardingFeatured: true } }, { id: "siwc", kind: "oauth", label: "Sign in with ChatGPT", hint: "Use your ChatGPT plan for eligible Responses API requests", wizard: { choiceId: "openai-token-sharing", assistantPriority: 0 } }, { id: "api-key", kind: "api_key", label: "OpenAI API Key", hint: "Use your OpenAI API key directly", credentialImport: CODEX_API_KEY_IMPORT, wizard: { choiceId: "openai-api-key", assistantPriority: 5, onboardingFeatured: true } } ].map((e) => Object.assign({}, e, { run: noopAuth, wizard: { ...e.wizard, choiceLabel: e.label, choiceHint: e.hint, ...OPENAI_ACCOUNT_WIZARD_GROUP } })) }; } //#endregion export { TOKEN_SHARING_ISSUER as a, TOKEN_SHARING_RESOURCE as c, TOKEN_SHARING_CLIENT_ID as i, TOKEN_SHARING_SCOPE as l, IDENTITY_AUTH_FLOW as n, TOKEN_SHARING_LEGACY_SCOPE as o, TOKEN_SHARING_AUTH_FLOW as r, TOKEN_SHARING_REDIRECT_URI as s, createOpenAIProviderMetadata as t, isSIWCAuthFlow as u };