@darkjd/opencode-openai-codex-auth 4.10.1

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 (90) hide show
  1. package/LICENSE +37 -0
  2. package/README.md +137 -0
  3. package/assets/opencode-logo-ornate-dark.svg +18 -0
  4. package/assets/readme-hero.svg +31 -0
  5. package/dist/index.d.ts +42 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +226 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/lib/auth/auth.d.ts +43 -0
  10. package/dist/lib/auth/auth.d.ts.map +1 -0
  11. package/dist/lib/auth/auth.js +163 -0
  12. package/dist/lib/auth/auth.js.map +1 -0
  13. package/dist/lib/auth/browser.d.ts +17 -0
  14. package/dist/lib/auth/browser.d.ts.map +1 -0
  15. package/dist/lib/auth/browser.js +76 -0
  16. package/dist/lib/auth/browser.js.map +1 -0
  17. package/dist/lib/auth/server.d.ts +10 -0
  18. package/dist/lib/auth/server.d.ts.map +1 -0
  19. package/dist/lib/auth/server.js +78 -0
  20. package/dist/lib/auth/server.js.map +1 -0
  21. package/dist/lib/auth/v2-storage.d.ts +35 -0
  22. package/dist/lib/auth/v2-storage.d.ts.map +1 -0
  23. package/dist/lib/auth/v2-storage.js +79 -0
  24. package/dist/lib/auth/v2-storage.js.map +1 -0
  25. package/dist/lib/config.d.ts +17 -0
  26. package/dist/lib/config.d.ts.map +1 -0
  27. package/dist/lib/config.js +51 -0
  28. package/dist/lib/config.js.map +1 -0
  29. package/dist/lib/constants.d.ts +69 -0
  30. package/dist/lib/constants.d.ts.map +1 -0
  31. package/dist/lib/constants.js +69 -0
  32. package/dist/lib/constants.js.map +1 -0
  33. package/dist/lib/logger.d.ts +21 -0
  34. package/dist/lib/logger.d.ts.map +1 -0
  35. package/dist/lib/logger.js +77 -0
  36. package/dist/lib/logger.js.map +1 -0
  37. package/dist/lib/oauth-success.html +712 -0
  38. package/dist/lib/prompts/codex-opencode-bridge.d.ts +19 -0
  39. package/dist/lib/prompts/codex-opencode-bridge.d.ts.map +1 -0
  40. package/dist/lib/prompts/codex-opencode-bridge.js +157 -0
  41. package/dist/lib/prompts/codex-opencode-bridge.js.map +1 -0
  42. package/dist/lib/prompts/codex.d.ts +27 -0
  43. package/dist/lib/prompts/codex.d.ts.map +1 -0
  44. package/dist/lib/prompts/codex.js +256 -0
  45. package/dist/lib/prompts/codex.js.map +1 -0
  46. package/dist/lib/prompts/opencode-codex.d.ts +21 -0
  47. package/dist/lib/prompts/opencode-codex.d.ts.map +1 -0
  48. package/dist/lib/prompts/opencode-codex.js +91 -0
  49. package/dist/lib/prompts/opencode-codex.js.map +1 -0
  50. package/dist/lib/request/fetch-helpers.d.ts +73 -0
  51. package/dist/lib/request/fetch-helpers.d.ts.map +1 -0
  52. package/dist/lib/request/fetch-helpers.js +231 -0
  53. package/dist/lib/request/fetch-helpers.js.map +1 -0
  54. package/dist/lib/request/helpers/input-utils.d.ts +6 -0
  55. package/dist/lib/request/helpers/input-utils.d.ts.map +1 -0
  56. package/dist/lib/request/helpers/input-utils.js +174 -0
  57. package/dist/lib/request/helpers/input-utils.js.map +1 -0
  58. package/dist/lib/request/helpers/model-map.d.ts +28 -0
  59. package/dist/lib/request/helpers/model-map.d.ts.map +1 -0
  60. package/dist/lib/request/helpers/model-map.js +134 -0
  61. package/dist/lib/request/helpers/model-map.js.map +1 -0
  62. package/dist/lib/request/helpers/model-registry-data.d.ts +86 -0
  63. package/dist/lib/request/helpers/model-registry-data.d.ts.map +1 -0
  64. package/dist/lib/request/helpers/model-registry-data.js +293 -0
  65. package/dist/lib/request/helpers/model-registry-data.js.map +1 -0
  66. package/dist/lib/request/helpers/model-registry.d.ts +45 -0
  67. package/dist/lib/request/helpers/model-registry.d.ts.map +1 -0
  68. package/dist/lib/request/helpers/model-registry.js +208 -0
  69. package/dist/lib/request/helpers/model-registry.js.map +1 -0
  70. package/dist/lib/request/helpers/skill-catalog.d.ts +59 -0
  71. package/dist/lib/request/helpers/skill-catalog.d.ts.map +1 -0
  72. package/dist/lib/request/helpers/skill-catalog.js +81 -0
  73. package/dist/lib/request/helpers/skill-catalog.js.map +1 -0
  74. package/dist/lib/request/request-transformer.d.ts +81 -0
  75. package/dist/lib/request/request-transformer.d.ts.map +1 -0
  76. package/dist/lib/request/request-transformer.js +477 -0
  77. package/dist/lib/request/request-transformer.js.map +1 -0
  78. package/dist/lib/request/response-handler.d.ts +14 -0
  79. package/dist/lib/request/response-handler.d.ts.map +1 -0
  80. package/dist/lib/request/response-handler.js +88 -0
  81. package/dist/lib/request/response-handler.js.map +1 -0
  82. package/dist/lib/types.d.ts +178 -0
  83. package/dist/lib/types.d.ts.map +1 -0
  84. package/dist/lib/types.js +2 -0
  85. package/dist/lib/types.js.map +1 -0
  86. package/dist/v2.d.ts +34 -0
  87. package/dist/v2.d.ts.map +1 -0
  88. package/dist/v2.js +259 -0
  89. package/dist/v2.js.map +1 -0
  90. package/package.json +87 -0
@@ -0,0 +1,178 @@
1
+ import type { Auth, Provider, Model } from "@opencode-ai/sdk";
2
+ /**
3
+ * Plugin configuration from ~/.opencode/openai-codex-auth-config.json
4
+ */
5
+ export interface PluginConfig {
6
+ /**
7
+ * Enable CODEX_MODE (Codex-OpenCode bridge prompt instead of tool remap)
8
+ * @default true
9
+ */
10
+ codexMode?: boolean;
11
+ /**
12
+ * Optional URL to a remotely-hosted model registry overlay (JSON array of
13
+ * ModelRegistryEntry objects — see lib/request/helpers/model-registry-data.ts).
14
+ * When set, the plugin periodically (every 15 min, ETag-cached) checks this
15
+ * URL for updates and merges them with the bundled model registry, so a
16
+ * maintainer can ship recognition for a new model without a full npm
17
+ * release. Opt-in only — unset by default. Can also be set via the
18
+ * OPENCODE_CODEX_MODEL_REGISTRY_URL environment variable, which takes
19
+ * precedence over this field.
20
+ */
21
+ modelRegistryUrl?: string;
22
+ }
23
+ /**
24
+ * User configuration structure from opencode.json
25
+ */
26
+ export interface UserConfig {
27
+ global: ConfigOptions;
28
+ models: {
29
+ [modelName: string]: {
30
+ options?: ConfigOptions;
31
+ variants?: Record<string, (ConfigOptions & {
32
+ disabled?: boolean;
33
+ }) | undefined>;
34
+ [key: string]: unknown;
35
+ };
36
+ };
37
+ }
38
+ /**
39
+ * Configuration options for reasoning and text settings
40
+ */
41
+ export interface ConfigOptions {
42
+ reasoningEffort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
43
+ reasoningSummary?: "auto" | "concise" | "detailed" | "off" | "on";
44
+ textVerbosity?: "low" | "medium" | "high";
45
+ include?: string[];
46
+ }
47
+ /**
48
+ * Reasoning configuration for requests
49
+ */
50
+ export interface ReasoningConfig {
51
+ effort: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
52
+ summary: "auto" | "concise" | "detailed" | "off" | "on";
53
+ }
54
+ /**
55
+ * OAuth server information
56
+ */
57
+ export interface OAuthServerInfo {
58
+ port: number;
59
+ ready: boolean;
60
+ close: () => void;
61
+ waitForCode: (state: string) => Promise<{
62
+ code: string;
63
+ } | null>;
64
+ }
65
+ /**
66
+ * PKCE challenge and verifier
67
+ */
68
+ export interface PKCEPair {
69
+ challenge: string;
70
+ verifier: string;
71
+ }
72
+ /**
73
+ * Authorization flow result
74
+ */
75
+ export interface AuthorizationFlow {
76
+ pkce: PKCEPair;
77
+ state: string;
78
+ url: string;
79
+ }
80
+ /**
81
+ * Token exchange success result
82
+ */
83
+ export interface TokenSuccess {
84
+ type: "success";
85
+ access: string;
86
+ refresh: string;
87
+ expires: number;
88
+ }
89
+ /**
90
+ * Token exchange failure result
91
+ */
92
+ export interface TokenFailure {
93
+ type: "failed";
94
+ }
95
+ /**
96
+ * Token exchange result
97
+ */
98
+ export type TokenResult = TokenSuccess | TokenFailure;
99
+ /**
100
+ * Parsed authorization input
101
+ */
102
+ export interface ParsedAuthInput {
103
+ code?: string;
104
+ state?: string;
105
+ }
106
+ /**
107
+ * JWT payload with ChatGPT account info
108
+ */
109
+ export interface JWTPayload {
110
+ "https://api.openai.com/auth"?: {
111
+ chatgpt_account_id?: string;
112
+ };
113
+ [key: string]: unknown;
114
+ }
115
+ /**
116
+ * Message input item
117
+ */
118
+ export interface InputItem {
119
+ id?: string;
120
+ type: string;
121
+ role: string;
122
+ content?: unknown;
123
+ [key: string]: unknown;
124
+ }
125
+ /**
126
+ * Request body structure
127
+ */
128
+ export interface RequestBody {
129
+ model: string;
130
+ store?: boolean;
131
+ stream?: boolean;
132
+ instructions?: string;
133
+ input?: InputItem[];
134
+ tools?: unknown;
135
+ reasoning?: Partial<ReasoningConfig>;
136
+ text?: {
137
+ verbosity?: "low" | "medium" | "high";
138
+ };
139
+ include?: string[];
140
+ providerOptions?: {
141
+ openai?: Partial<ConfigOptions> & {
142
+ store?: boolean;
143
+ include?: string[];
144
+ };
145
+ [key: string]: unknown;
146
+ };
147
+ /** Stable key to enable prompt-token caching on Codex backend */
148
+ prompt_cache_key?: string;
149
+ max_output_tokens?: number;
150
+ max_completion_tokens?: number;
151
+ [key: string]: unknown;
152
+ }
153
+ /**
154
+ * SSE event data structure
155
+ */
156
+ export interface SSEEventData {
157
+ type: string;
158
+ response?: unknown;
159
+ [key: string]: unknown;
160
+ }
161
+ /**
162
+ * Cache metadata for Codex instructions
163
+ */
164
+ export interface CacheMetadata {
165
+ etag: string | null;
166
+ tag: string;
167
+ lastChecked: number;
168
+ url: string;
169
+ }
170
+ /**
171
+ * GitHub release data
172
+ */
173
+ export interface GitHubRelease {
174
+ tag_name: string;
175
+ [key: string]: unknown;
176
+ }
177
+ export type { Auth, Provider, Model };
178
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;;OAGG;IACH,SAAS,CAAC,E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0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":""}
package/dist/v2.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * OpenCode 2 native plugin entrypoint.
3
+ *
4
+ * V1 plugin implementations (a bare async function default export) do not
5
+ * run under OpenCode 2 at all — the loader rejects them with a SchemaError
6
+ * before any of their code runs. This file is a from-scratch V2 port that
7
+ * reuses every existing business-logic module under lib/ unchanged (model
8
+ * normalization, Codex instructions, CODEX_MODE bridge, skill-catalog
9
+ * passthrough, SSE→JSON conversion, etc.) behind V2's native `http.request`
10
+ * / `http.response` session hooks instead of a custom `fetch` override.
11
+ *
12
+ * The V1 entrypoint remains available unchanged at "./legacy" for users
13
+ * still running OpenCode 1 (see package.json's dual "exports").
14
+ *
15
+ * See specs/opencode-v2-plugin-port.md for the root-cause investigation
16
+ * (confirmed empirically against a real OpenCode 2.0.15 instance) and
17
+ * design rationale behind every choice below.
18
+ */
19
+ import { Plugin } from "@opencode/plugin";
20
+ import type { SessionHttpRequest, SessionHttpResponse } from "@opencode/plugin/promise/session";
21
+ import { type V2Credentials } from "./lib/auth/v2-storage.js";
22
+ /**
23
+ * Exported separately so hook wiring can be exercised in tests without a
24
+ * live OpenCode 2 host (same pattern as dark-auth's createV2Hooks()).
25
+ */
26
+ export declare function createV2Hooks(): {
27
+ request: (event: SessionHttpRequest) => Promise<void>;
28
+ response: (event: SessionHttpResponse) => Promise<void>;
29
+ getCredentials: () => V2Credentials | null;
30
+ ensureFreshCredentials: () => Promise<V2Credentials | null>;
31
+ };
32
+ declare const _default: Plugin.Plugin;
33
+ export default _default;
34
+ //# sourceMappingURL=v2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v2.d.ts","sourceRoot":"","sources":["../v2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,MAAM,EAAmB,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EACX,kBAAkB,EAClB,mBAAmB,EACnB,MAAM,kCAAkC,CAAC;AAU1C,OAAO,EAIN,KAAK,aAAa,EAClB,MAAM,0BAA0B,CAAC;AAmDlC;;;GAGG;AACH,wBAAgB,aAAa;qBAuDE,kBAAkB,KAAG,OAAO,CAAC,IAAI,CAAC;sBAsDjC,mBAAmB,KAAG,OAAO,CAAC,IAAI,CAAC;0BAnGvC,aAAa,GAAG,IAAI;kCAeN,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;EAgGtE;;AAED,wBAoGG"}
package/dist/v2.js ADDED
@@ -0,0 +1,259 @@
1
+ /**
2
+ * OpenCode 2 native plugin entrypoint.
3
+ *
4
+ * V1 plugin implementations (a bare async function default export) do not
5
+ * run under OpenCode 2 at all — the loader rejects them with a SchemaError
6
+ * before any of their code runs. This file is a from-scratch V2 port that
7
+ * reuses every existing business-logic module under lib/ unchanged (model
8
+ * normalization, Codex instructions, CODEX_MODE bridge, skill-catalog
9
+ * passthrough, SSE→JSON conversion, etc.) behind V2's native `http.request`
10
+ * / `http.response` session hooks instead of a custom `fetch` override.
11
+ *
12
+ * The V1 entrypoint remains available unchanged at "./legacy" for users
13
+ * still running OpenCode 1 (see package.json's dual "exports").
14
+ *
15
+ * See specs/opencode-v2-plugin-port.md for the root-cause investigation
16
+ * (confirmed empirically against a real OpenCode 2.0.15 instance) and
17
+ * design rationale behind every choice below.
18
+ */
19
+ import { Plugin } from "@opencode/plugin";
20
+ import { createAuthorizationFlow, decodeJWT, exchangeAuthorizationCode, parseAuthorizationInput, refreshAccessToken, } from "./lib/auth/auth.js";
21
+ import { openBrowserUrl } from "./lib/auth/browser.js";
22
+ import { startLocalOAuthServer } from "./lib/auth/server.js";
23
+ import { importLegacyV1Credentials, loadV2Credentials, saveV2Credentials, } from "./lib/auth/v2-storage.js";
24
+ import { getCodexMode, loadPluginConfig } from "./lib/config.js";
25
+ import { configureModelRegistrySource } from "./lib/request/helpers/model-registry.js";
26
+ import { AUTH_LABELS, JWT_CLAIM_PATH, URL_PATHS, } from "./lib/constants.js";
27
+ import { logDebug } from "./lib/logger.js";
28
+ import { createCodexHeaders, handleErrorResponse, handleSuccessResponse, rewriteUrlForCodex, transformRequestForCodex, } from "./lib/request/fetch-helpers.js";
29
+ /** Distinct from OpenCode's own built-in "chatgpt-browser"/"chatgpt-headless" methods. */
30
+ const METHOD_ID = "codex-auth";
31
+ const INTEGRATION_ID = "openai";
32
+ /**
33
+ * Matches an outgoing OpenAI Responses API request before Codex-backend URL
34
+ * rewriting. Mirrors the intent of the V1 fetch()'s URL_PATHS.RESPONSES
35
+ * check, and (like dark-auth's anthropicMessages() helper) guards every
36
+ * hook against firing for unrelated "openai" traffic.
37
+ */
38
+ function isResponsesRequest(request) {
39
+ try {
40
+ const url = new URL(request.url);
41
+ return (request.method === "POST" &&
42
+ url.pathname.includes(URL_PATHS.RESPONSES));
43
+ }
44
+ catch {
45
+ return false;
46
+ }
47
+ }
48
+ function toOAuthCredential(creds) {
49
+ return {
50
+ type: "oauth",
51
+ methodID: METHOD_ID,
52
+ access: creds.access,
53
+ refresh: creds.refresh,
54
+ expires: creds.expires,
55
+ };
56
+ }
57
+ /**
58
+ * Exported separately so hook wiring can be exercised in tests without a
59
+ * live OpenCode 2 host (same pattern as dark-auth's createV2Hooks()).
60
+ */
61
+ export function createV2Hooks() {
62
+ // Per-session streaming flag, set in the request hook and consumed once
63
+ // by the matching response hook. Request bodies are one-shot streams, so
64
+ // this is cheaper than re-reading event.request in the response hook.
65
+ const streamingBySession = new Map();
66
+ let cachedCredentials = null;
67
+ let cachedAccountId;
68
+ let refreshPromise = null;
69
+ function getCredentials() {
70
+ if (cachedCredentials)
71
+ return cachedCredentials;
72
+ cachedCredentials = loadV2Credentials() ?? importLegacyV1Credentials();
73
+ return cachedCredentials;
74
+ }
75
+ function accountIdFor(creds) {
76
+ if (creds.accountId)
77
+ return creds.accountId;
78
+ if (cachedAccountId)
79
+ return cachedAccountId;
80
+ const decoded = decodeJWT(creds.access);
81
+ const accountId = decoded?.[JWT_CLAIM_PATH]?.chatgpt_account_id;
82
+ if (accountId)
83
+ cachedAccountId = accountId;
84
+ return accountId;
85
+ }
86
+ async function ensureFreshCredentials() {
87
+ const current = getCredentials();
88
+ if (!current)
89
+ return null;
90
+ if (current.expires > Date.now() + 60_000)
91
+ return current;
92
+ if (!refreshPromise) {
93
+ refreshPromise = (async () => {
94
+ const result = await refreshAccessToken(current.refresh);
95
+ if (result.type !== "success")
96
+ return null;
97
+ const updated = {
98
+ access: result.access,
99
+ refresh: result.refresh,
100
+ expires: result.expires,
101
+ accountId: cachedAccountId,
102
+ };
103
+ cachedCredentials = updated;
104
+ saveV2Credentials(updated);
105
+ return updated;
106
+ })().finally(() => {
107
+ refreshPromise = null;
108
+ });
109
+ }
110
+ return refreshPromise;
111
+ }
112
+ const pluginConfig = loadPluginConfig();
113
+ const codexMode = getCodexMode(pluginConfig);
114
+ configureModelRegistrySource(pluginConfig.modelRegistryUrl);
115
+ const userConfig = { global: {}, models: {} };
116
+ async function request(event) {
117
+ if (!isResponsesRequest(event.request))
118
+ return;
119
+ const credentials = await ensureFreshCredentials();
120
+ if (!credentials) {
121
+ throw new Error("[openai-codex-plugin] No ChatGPT/Codex credentials found. Authenticate via the 'ChatGPT Plus/Pro (Codex Auth)' method first.");
122
+ }
123
+ const accountId = accountIdFor(credentials);
124
+ if (!accountId) {
125
+ throw new Error("[openai-codex-plugin] Failed to extract accountId from token.");
126
+ }
127
+ const original = event.request;
128
+ const originalBody = original.body ? await original.clone().text() : "";
129
+ const parsedBody = originalBody ? JSON.parse(originalBody) : {};
130
+ const isStreaming = parsedBody.stream === true;
131
+ streamingBySession.set(event.sessionID, isStreaming);
132
+ const url = rewriteUrlForCodex(original.url);
133
+ const transformation = await transformRequestForCodex({ body: originalBody }, url, userConfig, codexMode);
134
+ const transformedBody = transformation?.body;
135
+ const finalBody = transformedBody
136
+ ? JSON.stringify(transformedBody)
137
+ : originalBody;
138
+ const headers = createCodexHeaders({ headers: original.headers }, accountId, credentials.access, {
139
+ model: transformedBody?.model,
140
+ promptCacheKey: transformedBody
141
+ ?.prompt_cache_key,
142
+ });
143
+ event.request = new Request(url, {
144
+ method: original.method,
145
+ headers,
146
+ body: finalBody,
147
+ signal: original.signal,
148
+ redirect: original.redirect,
149
+ });
150
+ }
151
+ async function response(event) {
152
+ if (!event.request.url.includes(URL_PATHS.CODEX_RESPONSES))
153
+ return;
154
+ const isStreaming = streamingBySession.get(event.sessionID) ?? false;
155
+ streamingBySession.delete(event.sessionID);
156
+ event.response = event.response.ok
157
+ ? await handleSuccessResponse(event.response, isStreaming)
158
+ : await handleErrorResponse(event.response);
159
+ }
160
+ return { request, response, getCredentials, ensureFreshCredentials };
161
+ }
162
+ export default Plugin.define({
163
+ id: "opencode-openai-codex-auth",
164
+ async setup(ctx) {
165
+ const hooks = createV2Hooks();
166
+ await ctx.session.hook("http.request", hooks.request, {
167
+ providerID: INTEGRATION_ID,
168
+ });
169
+ await ctx.session.hook("http.response", hooks.response, {
170
+ providerID: INTEGRATION_ID,
171
+ });
172
+ // V2's integration method can own new logins; there is no public API
173
+ // to import an existing OAuth credential into its connection store at
174
+ // setup (same limitation documented by dark-auth for Anthropic). This
175
+ // plugin's own file-based store (lib/auth/v2-storage.ts) is what the
176
+ // http.request hook above actually reads from, independent of which
177
+ // method OpenCode 2 shows as "active" for the integration — but the
178
+ // user must still complete THIS method once so OpenCode 2 treats
179
+ // "openai" as connected and routes model requests through it.
180
+ await ctx.integration.transform((editor) => {
181
+ if (!editor.get(INTEGRATION_ID))
182
+ return;
183
+ editor.method.update({
184
+ integrationID: INTEGRATION_ID,
185
+ method: {
186
+ id: METHOD_ID,
187
+ type: "oauth",
188
+ label: AUTH_LABELS.OAUTH_V2,
189
+ },
190
+ authorize: async () => {
191
+ const { pkce, state, url } = await createAuthorizationFlow();
192
+ const serverInfo = await startLocalOAuthServer({ state });
193
+ if (!serverInfo.ready) {
194
+ return {
195
+ url,
196
+ instructions: AUTH_LABELS.INSTRUCTIONS_MANUAL,
197
+ mode: "code",
198
+ callback: async (code) => {
199
+ const parsed = parseAuthorizationInput(code);
200
+ if (!parsed.code)
201
+ throw new Error("[openai-codex-plugin] Missing authorization code");
202
+ const tokens = await exchangeAuthorizationCode(parsed.code, pkce.verifier);
203
+ if (tokens.type !== "success") {
204
+ throw new Error("[openai-codex-plugin] OAuth exchange failed");
205
+ }
206
+ const creds = {
207
+ access: tokens.access,
208
+ refresh: tokens.refresh,
209
+ expires: tokens.expires,
210
+ };
211
+ saveV2Credentials(creds);
212
+ return toOAuthCredential(creds);
213
+ },
214
+ };
215
+ }
216
+ openBrowserUrl(url);
217
+ const callback = (async () => {
218
+ const result = await serverInfo.waitForCode(state);
219
+ serverInfo.close();
220
+ if (!result)
221
+ throw new Error("[openai-codex-plugin] OAuth callback timed out");
222
+ const tokens = await exchangeAuthorizationCode(result.code, pkce.verifier);
223
+ if (tokens.type !== "success") {
224
+ throw new Error("[openai-codex-plugin] OAuth exchange failed");
225
+ }
226
+ const creds = {
227
+ access: tokens.access,
228
+ refresh: tokens.refresh,
229
+ expires: tokens.expires,
230
+ };
231
+ saveV2Credentials(creds);
232
+ return toOAuthCredential(creds);
233
+ })();
234
+ return {
235
+ url,
236
+ instructions: AUTH_LABELS.INSTRUCTIONS,
237
+ mode: "auto",
238
+ callback,
239
+ };
240
+ },
241
+ refresh: async (credential) => {
242
+ const result = await refreshAccessToken(credential.refresh);
243
+ if (result.type !== "success") {
244
+ throw new Error("[openai-codex-plugin] OAuth refresh failed");
245
+ }
246
+ const creds = {
247
+ access: result.access,
248
+ refresh: result.refresh,
249
+ expires: result.expires,
250
+ };
251
+ saveV2Credentials(creds);
252
+ return toOAuthCredential(creds);
253
+ },
254
+ });
255
+ });
256
+ logDebug("[openai-codex-plugin] V2 plugin setup complete");
257
+ },
258
+ });
259
+ //# sourceMappingURL=v2.js.map
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C,4CAA4C,CAAC,CAAC;oBAC/D,CAAC;oBACD,MAAM,KAAK,GAAkB;wBAC5B,MAAM,EAAE,MAAM,CAAC,MAAM;wBACrB,OAAO,EAAE,MAAM,CAAC,OAAO;wBACvB,OAAO,EAAE,MAAM,CAAC,OAAO;qBACvB,CAAC;oBACF,iBAAiB,CAAC,KAAK,CAAC,CAAC;oBACzB,OAAO,iBAAiB,CAAC,KAAK,CAAC,CAAC;gBACjC,CAAC;aACD,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,gDAAgD,CAAC,CAAC;IAC5D,CAAC;CACD,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "@darkjd/opencode-openai-codex-auth",
3
+ "version": "4.10.1",
4
+ "description": "OpenAI ChatGPT (Codex backend) OAuth auth plugin for opencode - use your ChatGPT Plus/Pro subscription instead of API credits",
5
+ "main": "./dist/v2.js",
6
+ "types": "./dist/v2.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/v2.d.ts",
10
+ "default": "./dist/v2.js"
11
+ },
12
+ "./legacy": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ }
16
+ },
17
+ "type": "module",
18
+ "license": "MIT",
19
+ "author": "Numman Ali",
20
+ "contributors": [
21
+ "JDis03 (active fork maintainer — https://github.com/JDis03)"
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/JDis03/opencode-openai-codex-auth.git"
26
+ },
27
+ "keywords": [
28
+ "opencode",
29
+ "openai",
30
+ "codex",
31
+ "chatgpt",
32
+ "oauth",
33
+ "gpt-5",
34
+ "plugin",
35
+ "auth",
36
+ "chatgpt-plus",
37
+ "chatgpt-pro"
38
+ ],
39
+ "homepage": "https://github.com/JDis03/opencode-openai-codex-auth#readme",
40
+ "bugs": {
41
+ "url": "https://github.com/JDis03/opencode-openai-codex-auth/issues"
42
+ },
43
+ "scripts": {
44
+ "build": "tsc && cp lib/oauth-success.html dist/lib/",
45
+ "typecheck": "tsc --noEmit",
46
+ "test": "vitest run",
47
+ "test:watch": "vitest",
48
+ "test:ui": "vitest --ui",
49
+ "test:coverage": "vitest run --coverage"
50
+ },
51
+ "files": [
52
+ "dist/",
53
+ "assets/",
54
+ "README.md",
55
+ "LICENSE"
56
+ ],
57
+ "engines": {
58
+ "node": ">=20.0.0"
59
+ },
60
+ "peerDependencies": {
61
+ "@opencode-ai/plugin": "^1.0.150"
62
+ },
63
+ "peerDependenciesMeta": {
64
+ "@opencode-ai/plugin": {
65
+ "optional": true
66
+ }
67
+ },
68
+ "devDependencies": {
69
+ "@opencode-ai/plugin": "^1.0.150",
70
+ "@opencode-ai/sdk": "^1.0.150",
71
+ "@opencode/plugin": "^2.0.16",
72
+ "@types/node": "^24.6.2",
73
+ "@vitest/ui": "^3.2.4",
74
+ "typescript": "^5.9.3",
75
+ "vitest": "^3.2.4"
76
+ },
77
+ "dependencies": {
78
+ "@opencode/plugin": "^2.0.15",
79
+ "@openauthjs/openauth": "^0.4.3",
80
+ "hono": "^4.10.4",
81
+ "jsonc-parser": "^3.3.1"
82
+ },
83
+ "overrides": {
84
+ "hono": "^4.10.4",
85
+ "vite": "^7.1.12"
86
+ }
87
+ }