Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

CodexManagedErrors.ts

92 lines3.3 KB

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