opencode-openai-account-switcher 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/LICENSE +151 -0
  2. package/README.md +43 -0
  3. package/dist/auth-store.d.ts +13 -0
  4. package/dist/auth-store.js +43 -0
  5. package/dist/codex-auth-source.d.ts +16 -0
  6. package/dist/codex-auth-source.js +63 -0
  7. package/dist/codex-invalid-account.d.ts +32 -0
  8. package/dist/codex-invalid-account.js +106 -0
  9. package/dist/codex-network-retry.d.ts +2 -0
  10. package/dist/codex-network-retry.js +9 -0
  11. package/dist/codex-status-command.d.ts +56 -0
  12. package/dist/codex-status-command.js +341 -0
  13. package/dist/codex-status-fetcher.d.ts +71 -0
  14. package/dist/codex-status-fetcher.js +300 -0
  15. package/dist/codex-store.d.ts +49 -0
  16. package/dist/codex-store.js +267 -0
  17. package/dist/common-settings-actions.d.ts +15 -0
  18. package/dist/common-settings-actions.js +22 -0
  19. package/dist/common-settings-store.d.ts +17 -0
  20. package/dist/common-settings-store.js +72 -0
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.js +1 -0
  23. package/dist/menu-runtime.d.ts +81 -0
  24. package/dist/menu-runtime.js +141 -0
  25. package/dist/network-retry-engine.d.ts +33 -0
  26. package/dist/network-retry-engine.js +62 -0
  27. package/dist/plugin-hooks.d.ts +49 -0
  28. package/dist/plugin-hooks.js +123 -0
  29. package/dist/plugin.d.ts +2 -0
  30. package/dist/plugin.js +127 -0
  31. package/dist/providers/codex-menu-adapter.d.ts +58 -0
  32. package/dist/providers/codex-menu-adapter.js +429 -0
  33. package/dist/providers/descriptor.d.ts +24 -0
  34. package/dist/providers/descriptor.js +16 -0
  35. package/dist/providers/registry.d.ts +15 -0
  36. package/dist/providers/registry.js +49 -0
  37. package/dist/retry/codex-policy.d.ts +5 -0
  38. package/dist/retry/codex-policy.js +75 -0
  39. package/dist/retry/common-policy.d.ts +37 -0
  40. package/dist/retry/common-policy.js +68 -0
  41. package/dist/store-paths.d.ts +4 -0
  42. package/dist/store-paths.js +22 -0
  43. package/dist/ui/ansi.d.ts +18 -0
  44. package/dist/ui/ansi.js +32 -0
  45. package/dist/ui/confirm.d.ts +1 -0
  46. package/dist/ui/confirm.js +14 -0
  47. package/dist/ui/menu.d.ts +168 -0
  48. package/dist/ui/menu.js +305 -0
  49. package/dist/ui/select.d.ts +36 -0
  50. package/dist/ui/select.js +350 -0
  51. package/dist/upstream/codex-loader-adapter.d.ts +99 -0
  52. package/dist/upstream/codex-loader-adapter.js +80 -0
  53. package/dist/upstream/codex-plugin.snapshot.d.ts +32 -0
  54. package/dist/upstream/codex-plugin.snapshot.js +638 -0
  55. package/package.json +40 -0
  56. package/scripts/sync-codex-upstream.mjs +348 -0
@@ -0,0 +1,99 @@
1
+ export type CodexAuthState = {
2
+ type: string;
3
+ refresh?: string;
4
+ access?: string;
5
+ expires?: number;
6
+ accountId?: string;
7
+ };
8
+ export type CodexProviderModel = {
9
+ id?: string;
10
+ api?: {
11
+ id?: string;
12
+ url?: string;
13
+ npm?: string;
14
+ };
15
+ cost?: {
16
+ input: number;
17
+ output: number;
18
+ cache: {
19
+ read: number;
20
+ write: number;
21
+ };
22
+ };
23
+ };
24
+ export type CodexProviderConfig = {
25
+ models: Record<string, CodexProviderModel>;
26
+ };
27
+ export type OfficialCodexConfig = {
28
+ apiKey: string;
29
+ fetch: (request: Request | URL | string, init?: RequestInit) => Promise<Response>;
30
+ };
31
+ export type OfficialCodexChatHeadersHook = (input: {
32
+ sessionID: string;
33
+ model: {
34
+ providerID: string;
35
+ };
36
+ }, output: {
37
+ headers: Record<string, string>;
38
+ }) => Promise<void>;
39
+ type OfficialCodexAuthResult = {
40
+ type: "success";
41
+ refresh: string;
42
+ access: string;
43
+ expires: number;
44
+ accountId?: string;
45
+ } | {
46
+ type: "failed";
47
+ };
48
+ type OfficialCodexAuthorizePending = {
49
+ url: string;
50
+ instructions?: string;
51
+ method?: string;
52
+ callback?: () => Promise<OfficialCodexAuthResult>;
53
+ };
54
+ export type OfficialCodexAuthMethod = {
55
+ label: string;
56
+ type: string;
57
+ authorize?: () => Promise<OfficialCodexAuthorizePending>;
58
+ };
59
+ export declare function loadOfficialCodexAuthMethods(input?: {
60
+ client?: {
61
+ auth?: {
62
+ set?: (value: unknown) => Promise<unknown>;
63
+ };
64
+ };
65
+ baseFetch?: typeof fetch;
66
+ version?: string;
67
+ }): Promise<OfficialCodexAuthMethod[]>;
68
+ export declare function loadOfficialCodexConfig(input: {
69
+ getAuth: () => Promise<CodexAuthState | undefined>;
70
+ provider?: CodexProviderConfig;
71
+ baseFetch?: typeof fetch;
72
+ version?: string;
73
+ client?: {
74
+ auth?: {
75
+ set?: (value: unknown) => Promise<unknown>;
76
+ };
77
+ };
78
+ }): Promise<OfficialCodexConfig | undefined>;
79
+ export declare function createOfficialCodexFetchAdapter(input: {
80
+ getAuth: () => Promise<CodexAuthState | undefined>;
81
+ provider?: CodexProviderConfig;
82
+ baseFetch?: typeof fetch;
83
+ version?: string;
84
+ client?: {
85
+ auth?: {
86
+ set?: (value: unknown) => Promise<unknown>;
87
+ };
88
+ };
89
+ }): (request: Request | URL | string, init?: RequestInit) => Promise<Response>;
90
+ export declare function loadOfficialCodexChatHeaders(input?: {
91
+ client?: {
92
+ auth?: {
93
+ set?: (value: unknown) => Promise<unknown>;
94
+ };
95
+ };
96
+ baseFetch?: typeof fetch;
97
+ version?: string;
98
+ }): Promise<OfficialCodexChatHeadersHook>;
99
+ export {};
@@ -0,0 +1,80 @@
1
+ import { CodexAuthPlugin, officialCodexExportBridge } from "./codex-plugin.snapshot.js";
2
+ function runWithOfficialBridge(input, fn) {
3
+ return officialCodexExportBridge.run({
4
+ fetchImpl: input.baseFetch ?? globalThis.fetch,
5
+ version: input.version,
6
+ }, fn);
7
+ }
8
+ async function loadOfficialHooks(input) {
9
+ return runWithOfficialBridge(input, async () => {
10
+ const hooks = await CodexAuthPlugin({
11
+ client: input.client,
12
+ });
13
+ return hooks;
14
+ });
15
+ }
16
+ export async function loadOfficialCodexAuthMethods(input = {}) {
17
+ const hooks = await loadOfficialHooks(input);
18
+ const methods = hooks.auth?.methods;
19
+ if (!Array.isArray(methods)) {
20
+ return [];
21
+ }
22
+ return methods.map((method) => {
23
+ if (typeof method.authorize !== "function") {
24
+ return method;
25
+ }
26
+ return {
27
+ ...method,
28
+ authorize: async () => {
29
+ const pending = await runWithOfficialBridge(input, () => method.authorize());
30
+ if (!pending || typeof pending.callback !== "function") {
31
+ return pending;
32
+ }
33
+ return {
34
+ ...pending,
35
+ callback: () => runWithOfficialBridge(input, () => pending.callback()),
36
+ };
37
+ },
38
+ };
39
+ });
40
+ }
41
+ export async function loadOfficialCodexConfig(input) {
42
+ const hooks = await loadOfficialHooks({
43
+ client: input.client,
44
+ baseFetch: input.baseFetch,
45
+ version: input.version,
46
+ });
47
+ const loader = hooks.auth?.loader;
48
+ if (typeof loader !== "function") {
49
+ return undefined;
50
+ }
51
+ const provider = input.provider ?? { models: {} };
52
+ const result = await runWithOfficialBridge(input, async () => loader(input.getAuth, provider));
53
+ if (!("fetch" in result) || typeof result.fetch !== "function") {
54
+ return undefined;
55
+ }
56
+ return {
57
+ apiKey: result.apiKey,
58
+ fetch(request, init) {
59
+ return runWithOfficialBridge(input, async () => result.fetch(request, init));
60
+ },
61
+ };
62
+ }
63
+ export function createOfficialCodexFetchAdapter(input) {
64
+ return async function fetchWithOfficialHeaders(request, init) {
65
+ const config = await loadOfficialCodexConfig(input);
66
+ const fallback = input.baseFetch ?? fetch;
67
+ if (!config) {
68
+ return fallback(request, init);
69
+ }
70
+ return config.fetch(request, init);
71
+ };
72
+ }
73
+ export async function loadOfficialCodexChatHeaders(input = {}) {
74
+ const hooks = await loadOfficialHooks(input);
75
+ const chatHeaders = hooks["chat.headers"];
76
+ if (typeof chatHeaders !== "function") {
77
+ throw new Error("Official Codex plugin is missing chat.headers hook");
78
+ }
79
+ return async (hookInput, output) => runWithOfficialBridge(input, async () => chatHeaders(hookInput, output));
80
+ }
@@ -0,0 +1,32 @@
1
+ type RequestInfo = Request | URL | string;
2
+ type Hooks = any;
3
+ type PluginInput = any;
4
+ declare const officialCodexExportBridge: {
5
+ version: string;
6
+ fetchImpl(request: RequestInfo | URL, init?: RequestInit): Promise<Response>;
7
+ run(options: {
8
+ fetchImpl?: typeof globalThis.fetch;
9
+ version?: string;
10
+ } | undefined, fn: () => Promise<any>): Promise<any>;
11
+ };
12
+ export interface IdTokenClaims {
13
+ chatgpt_account_id?: string;
14
+ organizations?: Array<{
15
+ id: string;
16
+ }>;
17
+ email?: string;
18
+ "https://api.openai.com/auth"?: {
19
+ chatgpt_account_id?: string;
20
+ };
21
+ }
22
+ export declare function parseJwtClaims(token: string): IdTokenClaims | undefined;
23
+ export declare function extractAccountIdFromClaims(claims: IdTokenClaims): string | undefined;
24
+ export declare function extractAccountId(tokens: TokenResponse): string | undefined;
25
+ interface TokenResponse {
26
+ id_token: string;
27
+ access_token: string;
28
+ refresh_token: string;
29
+ expires_in?: number;
30
+ }
31
+ export declare function CodexAuthPlugin(input: PluginInput): Promise<Hooks>;
32
+ export { officialCodexExportBridge };