| 1 | const legacyFailures = { |
| 2 | subscription_sharing_v2_user_not_eligible: { |
| 3 | message: |
| 4 | "ChatGPT sharing is unavailable for this account or workspace. Use another provider or check its sharing policy.", |
| 5 | revoke: false, |
| 6 | }, |
| 7 | subscription_sharing_usage_limit_exceeded: { |
| 8 | message: |
| 9 | "Your ChatGPT usage limit was reached. Check ChatGPT Usage settings for your available allowance.", |
| 10 | revoke: false, |
| 11 | }, |
| 12 | subscription_sharing_usage_unavailable: { |
| 13 | message: "ChatGPT usage is temporarily unavailable. Try again shortly.", |
| 14 | revoke: false, |
| 15 | }, |
| 16 | subscription_sharing_unsupported_capability: { |
| 17 | message: |
| 18 | "Codex used a feature that ChatGPT sharing does not support. Use another provider for this request.", |
| 19 | revoke: false, |
| 20 | }, |
| 21 | subscription_sharing_v2_client_not_enabled: { |
| 22 | message: |
| 23 | "This app is not enabled for this ChatGPT connection. Use your existing CLI or another provider.", |
| 24 | revoke: false, |
| 25 | }, |
| 26 | subscription_sharing_v2_route_not_supported: { |
| 27 | message: "ChatGPT does not support this request route.", |
| 28 | revoke: false, |
| 29 | }, |
| 30 | subscription_sharing_v2_invalid_user: { |
| 31 | message: |
| 32 | "ChatGPT could not validate this connection. Check the selected account and sharing permissions.", |
| 33 | revoke: false, |
| 34 | }, |
| 35 | subscription_sharing_v2_user_unavailable: { |
| 36 | message: "ChatGPT is temporarily unavailable. Try again shortly.", |
| 37 | revoke: false, |
| 38 | }, |
| 39 | } as const; |
| 40 | const failures = { |
| 41 | ...legacyFailures, |
| 42 | subscription_sharing_user_not_eligible: legacyFailures.subscription_sharing_v2_user_not_eligible, |
| 43 | subscription_sharing_route_not_supported: |
| 44 | legacyFailures.subscription_sharing_v2_route_not_supported, |
| 45 | subscription_sharing_invalid_user: legacyFailures.subscription_sharing_v2_invalid_user, |
| 46 | subscription_sharing_user_unavailable: legacyFailures.subscription_sharing_v2_user_unavailable, |
| 47 | chatpass_v2_scope_not_authorized: { |
| 48 | message: |
| 49 | "This ChatGPT grant does not authorize the request. Check the connection's sharing permissions.", |
| 50 | revoke: false, |
| 51 | }, |
| 52 | chatpass_v2_invalid_authorization_context: { |
| 53 | message: |
| 54 | "ChatGPT could not authorize this connection. Check the client and sharing permissions.", |
| 55 | revoke: false, |
| 56 | }, |
| 57 | }; |
| 58 | export function classifyCodexManagedError(value: unknown) { |
| 59 | let text: string; |
| 60 | try { |
| 61 | text = typeof value === "string" ? value : JSON.stringify(value); |
| 62 | } catch { |
| 63 | return undefined; |
| 64 | } |
| 65 | if (typeof text !== "string") return undefined; |
| 66 | for (const [code, failure] of Object.entries(failures)) { |
| 67 | if (!text.includes(code)) continue; |
| 68 | if (code === "subscription_sharing_unsupported_capability") { |
| 69 | if (text.includes("tool 'namespace'")) |
| 70 | return { |
| 71 | ...failure, |
| 72 | code, |
| 73 | message: |
| 74 | "Codex sent a tool namespace that ChatGPT sharing does not support. Use another provider for this request.", |
| 75 | }; |
| 76 | if (text.includes("additional_tools")) |
| 77 | return { |
| 78 | ...failure, |
| 79 | code, |
| 80 | message: |
| 81 | "Codex sent an input item that ChatGPT sharing does not support. Use another provider for this request.", |
| 82 | }; |
| 83 | } |
| 84 | return { ...failure, code }; |
| 85 | } |
| 86 | return undefined; |
| 87 | } |