@mariozechner/pi-ai 0.35.0 → 0.36.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 (50) hide show
  1. package/dist/cli.d.ts.map +1 -1
  2. package/dist/cli.js +17 -1
  3. package/dist/cli.js.map +1 -1
  4. package/dist/models.generated.d.ts +640 -43
  5. package/dist/models.generated.d.ts.map +1 -1
  6. package/dist/models.generated.js +673 -76
  7. package/dist/models.generated.js.map +1 -1
  8. package/dist/providers/openai-codex/constants.d.ts +21 -0
  9. package/dist/providers/openai-codex/constants.d.ts.map +1 -0
  10. package/dist/providers/openai-codex/constants.js +21 -0
  11. package/dist/providers/openai-codex/constants.js.map +1 -0
  12. package/dist/providers/openai-codex/prompts/codex-instructions.md +105 -0
  13. package/dist/providers/openai-codex/prompts/codex.d.ts +11 -0
  14. package/dist/providers/openai-codex/prompts/codex.d.ts.map +1 -0
  15. package/dist/providers/openai-codex/prompts/codex.js +184 -0
  16. package/dist/providers/openai-codex/prompts/codex.js.map +1 -0
  17. package/dist/providers/openai-codex/prompts/pi-codex-bridge.d.ts +6 -0
  18. package/dist/providers/openai-codex/prompts/pi-codex-bridge.d.ts.map +1 -0
  19. package/dist/providers/openai-codex/prompts/pi-codex-bridge.js +48 -0
  20. package/dist/providers/openai-codex/prompts/pi-codex-bridge.js.map +1 -0
  21. package/dist/providers/openai-codex/request-transformer.d.ts +41 -0
  22. package/dist/providers/openai-codex/request-transformer.d.ts.map +1 -0
  23. package/dist/providers/openai-codex/request-transformer.js +242 -0
  24. package/dist/providers/openai-codex/request-transformer.js.map +1 -0
  25. package/dist/providers/openai-codex/response-handler.d.ts +19 -0
  26. package/dist/providers/openai-codex/response-handler.d.ts.map +1 -0
  27. package/dist/providers/openai-codex/response-handler.js +107 -0
  28. package/dist/providers/openai-codex/response-handler.js.map +1 -0
  29. package/dist/providers/openai-codex-responses.d.ts +10 -0
  30. package/dist/providers/openai-codex-responses.d.ts.map +1 -0
  31. package/dist/providers/openai-codex-responses.js +528 -0
  32. package/dist/providers/openai-codex-responses.js.map +1 -0
  33. package/dist/stream.d.ts.map +1 -1
  34. package/dist/stream.js +27 -1
  35. package/dist/stream.js.map +1 -1
  36. package/dist/types.d.ts +4 -2
  37. package/dist/types.d.ts.map +1 -1
  38. package/dist/types.js.map +1 -1
  39. package/dist/utils/oauth/index.d.ts +1 -0
  40. package/dist/utils/oauth/index.d.ts.map +1 -1
  41. package/dist/utils/oauth/index.js +11 -0
  42. package/dist/utils/oauth/index.js.map +1 -1
  43. package/dist/utils/oauth/openai-codex.d.ts +20 -0
  44. package/dist/utils/oauth/openai-codex.d.ts.map +1 -0
  45. package/dist/utils/oauth/openai-codex.js +278 -0
  46. package/dist/utils/oauth/openai-codex.js.map +1 -0
  47. package/dist/utils/oauth/types.d.ts +2 -1
  48. package/dist/utils/oauth/types.d.ts.map +1 -1
  49. package/dist/utils/oauth/types.js.map +1 -1
  50. package/package.json +2 -2
@@ -0,0 +1,278 @@
1
+ /**
2
+ * OpenAI Codex (ChatGPT OAuth) flow
3
+ */
4
+ import { randomBytes } from "node:crypto";
5
+ import http from "node:http";
6
+ import { generatePKCE } from "./pkce.js";
7
+ const CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann";
8
+ const AUTHORIZE_URL = "https://auth.openai.com/oauth/authorize";
9
+ const TOKEN_URL = "https://auth.openai.com/oauth/token";
10
+ const REDIRECT_URI = "http://localhost:1455/auth/callback";
11
+ const SCOPE = "openid profile email offline_access";
12
+ const JWT_CLAIM_PATH = "https://api.openai.com/auth";
13
+ const SUCCESS_HTML = `<!doctype html>
14
+ <html lang="en">
15
+ <head>
16
+ <meta charset="utf-8" />
17
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
18
+ <title>Authentication successful</title>
19
+ </head>
20
+ <body>
21
+ <p>Authentication successful. Return to your terminal to continue.</p>
22
+ </body>
23
+ </html>`;
24
+ function createState() {
25
+ return randomBytes(16).toString("hex");
26
+ }
27
+ function parseAuthorizationInput(input) {
28
+ const value = input.trim();
29
+ if (!value)
30
+ return {};
31
+ try {
32
+ const url = new URL(value);
33
+ return {
34
+ code: url.searchParams.get("code") ?? undefined,
35
+ state: url.searchParams.get("state") ?? undefined,
36
+ };
37
+ }
38
+ catch {
39
+ // not a URL
40
+ }
41
+ if (value.includes("#")) {
42
+ const [code, state] = value.split("#", 2);
43
+ return { code, state };
44
+ }
45
+ if (value.includes("code=")) {
46
+ const params = new URLSearchParams(value);
47
+ return {
48
+ code: params.get("code") ?? undefined,
49
+ state: params.get("state") ?? undefined,
50
+ };
51
+ }
52
+ return { code: value };
53
+ }
54
+ function decodeJwt(token) {
55
+ try {
56
+ const parts = token.split(".");
57
+ if (parts.length !== 3)
58
+ return null;
59
+ const payload = parts[1] ?? "";
60
+ const decoded = Buffer.from(payload, "base64").toString("utf-8");
61
+ return JSON.parse(decoded);
62
+ }
63
+ catch {
64
+ return null;
65
+ }
66
+ }
67
+ async function exchangeAuthorizationCode(code, verifier, redirectUri = REDIRECT_URI) {
68
+ const response = await fetch(TOKEN_URL, {
69
+ method: "POST",
70
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
71
+ body: new URLSearchParams({
72
+ grant_type: "authorization_code",
73
+ client_id: CLIENT_ID,
74
+ code,
75
+ code_verifier: verifier,
76
+ redirect_uri: redirectUri,
77
+ }),
78
+ });
79
+ if (!response.ok) {
80
+ const text = await response.text().catch(() => "");
81
+ console.error("[openai-codex] code->token failed:", response.status, text);
82
+ return { type: "failed" };
83
+ }
84
+ const json = (await response.json());
85
+ if (!json.access_token || !json.refresh_token || typeof json.expires_in !== "number") {
86
+ console.error("[openai-codex] token response missing fields:", json);
87
+ return { type: "failed" };
88
+ }
89
+ return {
90
+ type: "success",
91
+ access: json.access_token,
92
+ refresh: json.refresh_token,
93
+ expires: Date.now() + json.expires_in * 1000,
94
+ };
95
+ }
96
+ async function refreshAccessToken(refreshToken) {
97
+ try {
98
+ const response = await fetch(TOKEN_URL, {
99
+ method: "POST",
100
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
101
+ body: new URLSearchParams({
102
+ grant_type: "refresh_token",
103
+ refresh_token: refreshToken,
104
+ client_id: CLIENT_ID,
105
+ }),
106
+ });
107
+ if (!response.ok) {
108
+ const text = await response.text().catch(() => "");
109
+ console.error("[openai-codex] Token refresh failed:", response.status, text);
110
+ return { type: "failed" };
111
+ }
112
+ const json = (await response.json());
113
+ if (!json.access_token || !json.refresh_token || typeof json.expires_in !== "number") {
114
+ console.error("[openai-codex] Token refresh response missing fields:", json);
115
+ return { type: "failed" };
116
+ }
117
+ return {
118
+ type: "success",
119
+ access: json.access_token,
120
+ refresh: json.refresh_token,
121
+ expires: Date.now() + json.expires_in * 1000,
122
+ };
123
+ }
124
+ catch (error) {
125
+ console.error("[openai-codex] Token refresh error:", error);
126
+ return { type: "failed" };
127
+ }
128
+ }
129
+ async function createAuthorizationFlow() {
130
+ const { verifier, challenge } = await generatePKCE();
131
+ const state = createState();
132
+ const url = new URL(AUTHORIZE_URL);
133
+ url.searchParams.set("response_type", "code");
134
+ url.searchParams.set("client_id", CLIENT_ID);
135
+ url.searchParams.set("redirect_uri", REDIRECT_URI);
136
+ url.searchParams.set("scope", SCOPE);
137
+ url.searchParams.set("code_challenge", challenge);
138
+ url.searchParams.set("code_challenge_method", "S256");
139
+ url.searchParams.set("state", state);
140
+ url.searchParams.set("id_token_add_organizations", "true");
141
+ url.searchParams.set("codex_cli_simplified_flow", "true");
142
+ url.searchParams.set("originator", "codex_cli_rs");
143
+ return { verifier, state, url: url.toString() };
144
+ }
145
+ function startLocalOAuthServer(state) {
146
+ let lastCode = null;
147
+ const server = http.createServer((req, res) => {
148
+ try {
149
+ const url = new URL(req.url || "", "http://localhost");
150
+ if (url.pathname !== "/auth/callback") {
151
+ res.statusCode = 404;
152
+ res.end("Not found");
153
+ return;
154
+ }
155
+ if (url.searchParams.get("state") !== state) {
156
+ res.statusCode = 400;
157
+ res.end("State mismatch");
158
+ return;
159
+ }
160
+ const code = url.searchParams.get("code");
161
+ if (!code) {
162
+ res.statusCode = 400;
163
+ res.end("Missing authorization code");
164
+ return;
165
+ }
166
+ res.statusCode = 200;
167
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
168
+ res.end(SUCCESS_HTML);
169
+ lastCode = code;
170
+ }
171
+ catch {
172
+ res.statusCode = 500;
173
+ res.end("Internal error");
174
+ }
175
+ });
176
+ return new Promise((resolve) => {
177
+ server
178
+ .listen(1455, "127.0.0.1", () => {
179
+ resolve({
180
+ close: () => server.close(),
181
+ waitForCode: async () => {
182
+ const sleep = () => new Promise((r) => setTimeout(r, 100));
183
+ for (let i = 0; i < 600; i += 1) {
184
+ if (lastCode)
185
+ return { code: lastCode };
186
+ await sleep();
187
+ }
188
+ return null;
189
+ },
190
+ });
191
+ })
192
+ .on("error", (err) => {
193
+ console.error("[openai-codex] Failed to bind http://127.0.0.1:1455 (", err.code, ") Falling back to manual paste.");
194
+ resolve({
195
+ close: () => {
196
+ try {
197
+ server.close();
198
+ }
199
+ catch {
200
+ // ignore
201
+ }
202
+ },
203
+ waitForCode: async () => null,
204
+ });
205
+ });
206
+ });
207
+ }
208
+ function getAccountId(accessToken) {
209
+ const payload = decodeJwt(accessToken);
210
+ const auth = payload?.[JWT_CLAIM_PATH];
211
+ const accountId = auth?.chatgpt_account_id;
212
+ return typeof accountId === "string" && accountId.length > 0 ? accountId : null;
213
+ }
214
+ /**
215
+ * Login with OpenAI Codex OAuth
216
+ */
217
+ export async function loginOpenAICodex(options) {
218
+ const { verifier, state, url } = await createAuthorizationFlow();
219
+ const server = await startLocalOAuthServer(state);
220
+ options.onAuth({ url, instructions: "A browser window should open. Complete login to finish." });
221
+ let code;
222
+ try {
223
+ const result = await server.waitForCode();
224
+ if (result?.code) {
225
+ code = result.code;
226
+ }
227
+ if (!code) {
228
+ const input = await options.onPrompt({
229
+ message: "Paste the authorization code (or full redirect URL):",
230
+ });
231
+ const parsed = parseAuthorizationInput(input);
232
+ if (parsed.state && parsed.state !== state) {
233
+ throw new Error("State mismatch");
234
+ }
235
+ code = parsed.code;
236
+ }
237
+ if (!code) {
238
+ throw new Error("Missing authorization code");
239
+ }
240
+ const tokenResult = await exchangeAuthorizationCode(code, verifier);
241
+ if (tokenResult.type !== "success") {
242
+ throw new Error("Token exchange failed");
243
+ }
244
+ const accountId = getAccountId(tokenResult.access);
245
+ if (!accountId) {
246
+ throw new Error("Failed to extract accountId from token");
247
+ }
248
+ return {
249
+ access: tokenResult.access,
250
+ refresh: tokenResult.refresh,
251
+ expires: tokenResult.expires,
252
+ accountId,
253
+ };
254
+ }
255
+ finally {
256
+ server.close();
257
+ }
258
+ }
259
+ /**
260
+ * Refresh OpenAI Codex OAuth token
261
+ */
262
+ export async function refreshOpenAICodexToken(refreshToken) {
263
+ const result = await refreshAccessToken(refreshToken);
264
+ if (result.type !== "success") {
265
+ throw new Error("Failed to refresh OpenAI Codex token");
266
+ }
267
+ const accountId = getAccountId(result.access);
268
+ if (!accountId) {
269
+ throw new Error("Failed to extract accountId from token");
270
+ }
271
+ return {
272
+ access: result.access,
273
+ refresh: result.refresh,
274
+ expires: result.expires,
275
+ accountId,
276
+ };
277
+ }
278
+ //# sourceMappingURL=openai-codex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-codex.js","sourceRoot":"","sources":["../../../src/utils/oauth/openai-codex.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,MAAM,SAAS,GAAG,8BAA8B,CAAC;AACjD,MAAM,aAAa,GAAG,yCAAyC,CAAC;AAChE,MAAM,SAAS,GAAG,qCAAqC,CAAC;AACxD,MAAM,YAAY,GAAG,qCAAqC,CAAC;AAC3D,MAAM,KAAK,GAAG,qCAAqC,CAAC;AACpD,MAAM,cAAc,G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AAC;IAED,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC9C,IAAI,CAAC,SAAS,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO;QACN,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,SAAS;KACT,CAAC;AAAA,CACF","sourcesContent":["/**\n * OpenAI Codex (ChatGPT OAuth) flow\n */\n\nimport { randomBytes } from \"node:crypto\";\nimport http from \"node:http\";\nimport { generatePKCE } from \"./pkce.js\";\nimport type { OAuthCredentials, OAuthPrompt } from \"./types.js\";\n\nconst CLIENT_ID = \"app_EMoamEEZ73f0CkXaXp7hrann\";\nconst AUTHORIZE_URL = \"https://auth.openai.com/oauth/authorize\";\nconst TOKEN_URL = \"https://auth.openai.com/oauth/token\";\nconst REDIRECT_URI = \"http://localhost:1455/auth/callback\";\nconst SCOPE = \"openid profile email offline_access\";\nconst JWT_CLAIM_PATH = \"https://api.openai.com/auth\";\n\nconst SUCCESS_HTML = `<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>Authentication successful</title>\n</head>\n<body>\n <p>Authentication successful. Return to your terminal to continue.</p>\n</body>\n</html>`;\n\ntype TokenSuccess = { type: \"success\"; access: string; refresh: string; expires: number };\ntype TokenFailure = { type: \"failed\" };\ntype TokenResult = TokenSuccess | TokenFailure;\n\ntype JwtPayload = {\n\t[JWT_CLAIM_PATH]?: {\n\t\tchatgpt_account_id?: string;\n\t};\n\t[key: string]: unknown;\n};\n\nfunction createState(): string {\n\treturn randomBytes(16).toString(\"hex\");\n}\n\nfunction parseAuthorizationInput(input: string): { code?: string; state?: string } {\n\tconst value = input.trim();\n\tif (!value) return {};\n\n\ttry {\n\t\tconst url = new URL(value);\n\t\treturn {\n\t\t\tcode: url.searchParams.get(\"code\") ?? undefined,\n\t\t\tstate: url.searchParams.get(\"state\") ?? undefined,\n\t\t};\n\t} catch {\n\t\t// not a URL\n\t}\n\n\tif (value.includes(\"#\")) {\n\t\tconst [code, state] = value.split(\"#\", 2);\n\t\treturn { code, state };\n\t}\n\n\tif (value.includes(\"code=\")) {\n\t\tconst params = new URLSearchParams(value);\n\t\treturn {\n\t\t\tcode: params.get(\"code\") ?? undefined,\n\t\t\tstate: params.get(\"state\") ?? undefined,\n\t\t};\n\t}\n\n\treturn { code: value };\n}\n\nfunction decodeJwt(token: string): JwtPayload | null {\n\ttry {\n\t\tconst parts = token.split(\".\");\n\t\tif (parts.length !== 3) return null;\n\t\tconst payload = parts[1] ?? \"\";\n\t\tconst decoded = Buffer.from(payload, \"base64\").toString(\"utf-8\");\n\t\treturn JSON.parse(decoded) as JwtPayload;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nasync function exchangeAuthorizationCode(\n\tcode: string,\n\tverifier: string,\n\tredirectUri: string = REDIRECT_URI,\n): Promise<TokenResult> {\n\tconst response = await fetch(TOKEN_URL, {\n\t\tmethod: \"POST\",\n\t\theaders: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n\t\tbody: new URLSearchParams({\n\t\t\tgrant_type: \"authorization_code\",\n\t\t\tclient_id: CLIENT_ID,\n\t\t\tcode,\n\t\t\tcode_verifier: verifier,\n\t\t\tredirect_uri: redirectUri,\n\t\t}),\n\t});\n\n\tif (!response.ok) {\n\t\tconst text = await response.text().catch(() => \"\");\n\t\tconsole.error(\"[openai-codex] code->token failed:\", response.status, text);\n\t\treturn { type: \"failed\" };\n\t}\n\n\tconst json = (await response.json()) as {\n\t\taccess_token?: string;\n\t\trefresh_token?: string;\n\t\texpires_in?: number;\n\t};\n\n\tif (!json.access_token || !json.refresh_token || typeof json.expires_in !== \"number\") {\n\t\tconsole.error(\"[openai-codex] token response missing fields:\", json);\n\t\treturn { type: \"failed\" };\n\t}\n\n\treturn {\n\t\ttype: \"success\",\n\t\taccess: json.access_token,\n\t\trefresh: json.refresh_token,\n\t\texpires: Date.now() + json.expires_in * 1000,\n\t};\n}\n\nasync function refreshAccessToken(refreshToken: string): Promise<TokenResult> {\n\ttry {\n\t\tconst response = await fetch(TOKEN_URL, {\n\t\t\tmethod: \"POST\",\n\t\t\theaders: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n\t\t\tbody: new URLSearchParams({\n\t\t\t\tgrant_type: \"refresh_token\",\n\t\t\t\trefresh_token: refreshToken,\n\t\t\t\tclient_id: CLIENT_ID,\n\t\t\t}),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tconst text = await response.text().catch(() => \"\");\n\t\t\tconsole.error(\"[openai-codex] Token refresh failed:\", response.status, text);\n\t\t\treturn { type: \"failed\" };\n\t\t}\n\n\t\tconst json = (await response.json()) as {\n\t\t\taccess_token?: string;\n\t\t\trefresh_token?: string;\n\t\t\texpires_in?: number;\n\t\t};\n\n\t\tif (!json.access_token || !json.refresh_token || typeof json.expires_in !== \"number\") {\n\t\t\tconsole.error(\"[openai-codex] Token refresh response missing fields:\", json);\n\t\t\treturn { type: \"failed\" };\n\t\t}\n\n\t\treturn {\n\t\t\ttype: \"success\",\n\t\t\taccess: json.access_token,\n\t\t\trefresh: json.refresh_token,\n\t\t\texpires: Date.now() + json.expires_in * 1000,\n\t\t};\n\t} catch (error) {\n\t\tconsole.error(\"[openai-codex] Token refresh error:\", error);\n\t\treturn { type: \"failed\" };\n\t}\n}\n\nasync function createAuthorizationFlow(): Promise<{ verifier: string; state: string; url: string }> {\n\tconst { verifier, challenge } = await generatePKCE();\n\tconst state = createState();\n\n\tconst url = new URL(AUTHORIZE_URL);\n\turl.searchParams.set(\"response_type\", \"code\");\n\turl.searchParams.set(\"client_id\", CLIENT_ID);\n\turl.searchParams.set(\"redirect_uri\", REDIRECT_URI);\n\turl.searchParams.set(\"scope\", SCOPE);\n\turl.searchParams.set(\"code_challenge\", challenge);\n\turl.searchParams.set(\"code_challenge_method\", \"S256\");\n\turl.searchParams.set(\"state\", state);\n\turl.searchParams.set(\"id_token_add_organizations\", \"true\");\n\turl.searchParams.set(\"codex_cli_simplified_flow\", \"true\");\n\turl.searchParams.set(\"originator\", \"codex_cli_rs\");\n\n\treturn { verifier, state, url: url.toString() };\n}\n\ntype OAuthServerInfo = {\n\tclose: () => void;\n\twaitForCode: () => Promise<{ code: string } | null>;\n};\n\nfunction startLocalOAuthServer(state: string): Promise<OAuthServerInfo> {\n\tlet lastCode: string | null = null;\n\tconst server = http.createServer((req, res) => {\n\t\ttry {\n\t\t\tconst url = new URL(req.url || \"\", \"http://localhost\");\n\t\t\tif (url.pathname !== \"/auth/callback\") {\n\t\t\t\tres.statusCode = 404;\n\t\t\t\tres.end(\"Not found\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (url.searchParams.get(\"state\") !== state) {\n\t\t\t\tres.statusCode = 400;\n\t\t\t\tres.end(\"State mismatch\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst code = url.searchParams.get(\"code\");\n\t\t\tif (!code) {\n\t\t\t\tres.statusCode = 400;\n\t\t\t\tres.end(\"Missing authorization code\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tres.statusCode = 200;\n\t\t\tres.setHeader(\"Content-Type\", \"text/html; charset=utf-8\");\n\t\t\tres.end(SUCCESS_HTML);\n\t\t\tlastCode = code;\n\t\t} catch {\n\t\t\tres.statusCode = 500;\n\t\t\tres.end(\"Internal error\");\n\t\t}\n\t});\n\n\treturn new Promise((resolve) => {\n\t\tserver\n\t\t\t.listen(1455, \"127.0.0.1\", () => {\n\t\t\t\tresolve({\n\t\t\t\t\tclose: () => server.close(),\n\t\t\t\t\twaitForCode: async () => {\n\t\t\t\t\t\tconst sleep = () => new Promise((r) => setTimeout(r, 100));\n\t\t\t\t\t\tfor (let i = 0; i < 600; i += 1) {\n\t\t\t\t\t\t\tif (lastCode) return { code: lastCode };\n\t\t\t\t\t\t\tawait sleep();\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t})\n\t\t\t.on(\"error\", (err: NodeJS.ErrnoException) => {\n\t\t\t\tconsole.error(\n\t\t\t\t\t\"[openai-codex] Failed to bind http://127.0.0.1:1455 (\",\n\t\t\t\t\terr.code,\n\t\t\t\t\t\") Falling back to manual paste.\",\n\t\t\t\t);\n\t\t\t\tresolve({\n\t\t\t\t\tclose: () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tserver.close();\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// ignore\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\twaitForCode: async () => null,\n\t\t\t\t});\n\t\t\t});\n\t});\n}\n\nfunction getAccountId(accessToken: string): string | null {\n\tconst payload = decodeJwt(accessToken);\n\tconst auth = payload?.[JWT_CLAIM_PATH];\n\tconst accountId = auth?.chatgpt_account_id;\n\treturn typeof accountId === \"string\" && accountId.length > 0 ? accountId : null;\n}\n\n/**\n * Login with OpenAI Codex OAuth\n */\nexport async function loginOpenAICodex(options: {\n\tonAuth: (info: { url: string; instructions?: string }) => void;\n\tonPrompt: (prompt: OAuthPrompt) => Promise<string>;\n\tonProgress?: (message: string) => void;\n}): Promise<OAuthCredentials> {\n\tconst { verifier, state, url } = await createAuthorizationFlow();\n\tconst server = await startLocalOAuthServer(state);\n\n\toptions.onAuth({ url, instructions: \"A browser window should open. Complete login to finish.\" });\n\n\tlet code: string | undefined;\n\ttry {\n\t\tconst result = await server.waitForCode();\n\t\tif (result?.code) {\n\t\t\tcode = result.code;\n\t\t}\n\n\t\tif (!code) {\n\t\t\tconst input = await options.onPrompt({\n\t\t\t\tmessage: \"Paste the authorization code (or full redirect URL):\",\n\t\t\t});\n\t\t\tconst parsed = parseAuthorizationInput(input);\n\t\t\tif (parsed.state && parsed.state !== state) {\n\t\t\t\tthrow new Error(\"State mismatch\");\n\t\t\t}\n\t\t\tcode = parsed.code;\n\t\t}\n\n\t\tif (!code) {\n\t\t\tthrow new Error(\"Missing authorization code\");\n\t\t}\n\n\t\tconst tokenResult = await exchangeAuthorizationCode(code, verifier);\n\t\tif (tokenResult.type !== \"success\") {\n\t\t\tthrow new Error(\"Token exchange failed\");\n\t\t}\n\n\t\tconst accountId = getAccountId(tokenResult.access);\n\t\tif (!accountId) {\n\t\t\tthrow new Error(\"Failed to extract accountId from token\");\n\t\t}\n\n\t\treturn {\n\t\t\taccess: tokenResult.access,\n\t\t\trefresh: tokenResult.refresh,\n\t\t\texpires: tokenResult.expires,\n\t\t\taccountId,\n\t\t};\n\t} finally {\n\t\tserver.close();\n\t}\n}\n\n/**\n * Refresh OpenAI Codex OAuth token\n */\nexport async function refreshOpenAICodexToken(refreshToken: string): Promise<OAuthCredentials> {\n\tconst result = await refreshAccessToken(refreshToken);\n\tif (result.type !== \"success\") {\n\t\tthrow new Error(\"Failed to refresh OpenAI Codex token\");\n\t}\n\n\tconst accountId = getAccountId(result.access);\n\tif (!accountId) {\n\t\tthrow new Error(\"Failed to extract accountId from token\");\n\t}\n\n\treturn {\n\t\taccess: result.access,\n\t\trefresh: result.refresh,\n\t\texpires: result.expires,\n\t\taccountId,\n\t};\n}\n"]}
@@ -5,8 +5,9 @@ export type OAuthCredentials = {
5
5
  enterpriseUrl?: string;
6
6
  projectId?: string;
7
7
  email?: string;
8
+ accountId?: string;
8
9
  };
9
- export type OAuthProvider = "anthropic" | "github-copilot" | "google-gemini-cli" | "google-antigravity";
10
+ export type OAuthProvider = "anthropic" | "github-copilot" | "google-gemini-cli" | "google-antigravity" | "openai-codex";
10
11
  export type OAuthPrompt = {
11
12
  message: string;
12
13
  placeholder?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/oauth/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,gBAAgB,GAAG,mBAAmB,GAAG,oBAAoB,CAAC;AAExG,MAAM,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,WAAW,iBAAiB;IACjC,EAAE,EAAE,aAAa,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;CACnB","sourcesContent":["export type OAuthCredentials = {\n\trefresh: string;\n\taccess: string;\n\texpires: number;\n\tenterpriseUrl?: string;\n\tprojectId?: string;\n\temail?: string;\n};\n\nexport type OAuthProvider = \"anthropic\" | \"github-copilot\" | \"google-gemini-cli\" | \"google-antigravity\";\n\nexport type OAuthPrompt = {\n\tmessage: string;\n\tplaceholder?: string;\n\tallowEmpty?: boolean;\n};\n\nexport type OAuthAuthInfo = {\n\turl: string;\n\tinstructions?: string;\n};\n\nexport interface OAuthProviderInfo {\n\tid: OAuthProvider;\n\tname: string;\n\tavailable: boolean;\n}\n"]}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/oauth/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,aAAa,GACtB,WAAW,GACX,gBAAgB,GAChB,mBAAmB,GACnB,oBAAoB,GACpB,cAAc,CAAC;AAElB,MAAM,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,WAAW,iBAAiB;IACjC,EAAE,EAAE,aAAa,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;CACnB","sourcesContent":["export type OAuthCredentials = {\n\trefresh: string;\n\taccess: string;\n\texpires: number;\n\tenterpriseUrl?: string;\n\tprojectId?: string;\n\temail?: string;\n\taccountId?: string;\n};\n\nexport type OAuthProvider =\n\t| \"anthropic\"\n\t| \"github-copilot\"\n\t| \"google-gemini-cli\"\n\t| \"google-antigravity\"\n\t| \"openai-codex\";\n\nexport type OAuthPrompt = {\n\tmessage: string;\n\tplaceholder?: string;\n\tallowEmpty?: boolean;\n};\n\nexport type OAuthAuthInfo = {\n\turl: string;\n\tinstructions?: string;\n};\n\nexport interface OAuthProviderInfo {\n\tid: OAuthProvider;\n\tname: string;\n\tavailable: boolean;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/oauth/types.ts"],"names":[],"mappings":"","sourcesContent":["export type OAuthCredentials = {\n\trefresh: string;\n\taccess: string;\n\texpires: number;\n\tenterpriseUrl?: string;\n\tprojectId?: string;\n\temail?: string;\n};\n\nexport type OAuthProvider = \"anthropic\" | \"github-copilot\" | \"google-gemini-cli\" | \"google-antigravity\";\n\nexport type OAuthPrompt = {\n\tmessage: string;\n\tplaceholder?: string;\n\tallowEmpty?: boolean;\n};\n\nexport type OAuthAuthInfo = {\n\turl: string;\n\tinstructions?: string;\n};\n\nexport interface OAuthProviderInfo {\n\tid: OAuthProvider;\n\tname: string;\n\tavailable: boolean;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/oauth/types.ts"],"names":[],"mappings":"","sourcesContent":["export type OAuthCredentials = {\n\trefresh: string;\n\taccess: string;\n\texpires: number;\n\tenterpriseUrl?: string;\n\tprojectId?: string;\n\temail?: string;\n\taccountId?: string;\n};\n\nexport type OAuthProvider =\n\t| \"anthropic\"\n\t| \"github-copilot\"\n\t| \"google-gemini-cli\"\n\t| \"google-antigravity\"\n\t| \"openai-codex\";\n\nexport type OAuthPrompt = {\n\tmessage: string;\n\tplaceholder?: string;\n\tallowEmpty?: boolean;\n};\n\nexport type OAuthAuthInfo = {\n\turl: string;\n\tinstructions?: string;\n};\n\nexport interface OAuthProviderInfo {\n\tid: OAuthProvider;\n\tname: string;\n\tavailable: boolean;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mariozechner/pi-ai",
3
- "version": "0.35.0",
3
+ "version": "0.36.0",
4
4
  "description": "Unified LLM API with automatic model discovery and provider configuration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "scripts": {
16
16
  "clean": "rm -rf dist",
17
17
  "generate-models": "npx tsx scripts/generate-models.ts",
18
- "build": "npm run generate-models && tsgo -p tsconfig.build.json",
18
+ "build": "npm run generate-models && tsgo -p tsconfig.build.json && node scripts/copy-assets.js",
19
19
  "dev": "tsgo -p tsconfig.build.json --watch --preserveWatchOutput",
20
20
  "dev:tsc": "tsgo -p tsconfig.build.json --watch --preserveWatchOutput",
21
21
  "test": "vitest --run",