mastracode 0.18.1 → 0.19.0-alpha.2

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 (54) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/agents/model.d.ts.map +1 -1
  3. package/dist/auth/index.d.ts +1 -0
  4. package/dist/auth/index.d.ts.map +1 -1
  5. package/dist/auth/providers/openai-codex.d.ts +38 -3
  6. package/dist/auth/providers/openai-codex.d.ts.map +1 -1
  7. package/dist/auth/types.d.ts +20 -0
  8. package/dist/auth/types.d.ts.map +1 -1
  9. package/dist/{chunk-EQBHZCMR.js → chunk-5YJR6NJL.js} +174 -53
  10. package/dist/chunk-5YJR6NJL.js.map +1 -0
  11. package/dist/{chunk-MGQHBND3.cjs → chunk-6BXLJNXS.cjs} +27 -17
  12. package/dist/chunk-6BXLJNXS.cjs.map +1 -0
  13. package/dist/{chunk-36KKPIKN.js → chunk-DA76BPE2.js} +119 -8
  14. package/dist/chunk-DA76BPE2.js.map +1 -0
  15. package/dist/{chunk-NGJXCCTA.js → chunk-EUY6SLJB.js} +96 -8
  16. package/dist/chunk-EUY6SLJB.js.map +1 -0
  17. package/dist/{chunk-RPPH6B6Y.cjs → chunk-FR4SX2VD.cjs} +950 -862
  18. package/dist/chunk-FR4SX2VD.cjs.map +1 -0
  19. package/dist/{chunk-XAU4ESBR.cjs → chunk-J4NTSYKT.cjs} +161 -50
  20. package/dist/chunk-J4NTSYKT.cjs.map +1 -0
  21. package/dist/{chunk-E5U4IMBB.cjs → chunk-LS7LUEZX.cjs} +174 -53
  22. package/dist/chunk-LS7LUEZX.cjs.map +1 -0
  23. package/dist/{chunk-7B7SVMEN.js → chunk-YJMT2SB2.js} +16 -6
  24. package/dist/chunk-YJMT2SB2.js.map +1 -0
  25. package/dist/cli.cjs +19 -19
  26. package/dist/cli.js +4 -4
  27. package/dist/index.cjs +3 -3
  28. package/dist/index.js +1 -1
  29. package/dist/mcp/config.d.ts.map +1 -1
  30. package/dist/mcp/manager.d.ts.map +1 -1
  31. package/dist/mcp/types.d.ts +17 -0
  32. package/dist/mcp/types.d.ts.map +1 -1
  33. package/dist/providers/openai-codex.d.ts.map +1 -1
  34. package/dist/storage-BMQP37FP.js +3 -0
  35. package/dist/{storage-AL27BSBS.js.map → storage-BMQP37FP.js.map} +1 -1
  36. package/dist/storage-JVXQ6DMJ.cjs +24 -0
  37. package/dist/{storage-DB6SRCPR.cjs.map → storage-JVXQ6DMJ.cjs.map} +1 -1
  38. package/dist/tui/commands/login.d.ts.map +1 -1
  39. package/dist/tui/components/login-mode-selector.d.ts +26 -0
  40. package/dist/tui/components/login-mode-selector.d.ts.map +1 -0
  41. package/dist/tui/mastra-tui.d.ts.map +1 -1
  42. package/dist/tui.cjs +19 -19
  43. package/dist/tui.js +2 -2
  44. package/package.json +9 -9
  45. package/dist/chunk-36KKPIKN.js.map +0 -1
  46. package/dist/chunk-7B7SVMEN.js.map +0 -1
  47. package/dist/chunk-E5U4IMBB.cjs.map +0 -1
  48. package/dist/chunk-EQBHZCMR.js.map +0 -1
  49. package/dist/chunk-MGQHBND3.cjs.map +0 -1
  50. package/dist/chunk-NGJXCCTA.js.map +0 -1
  51. package/dist/chunk-RPPH6B6Y.cjs.map +0 -1
  52. package/dist/chunk-XAU4ESBR.cjs.map +0 -1
  53. package/dist/storage-AL27BSBS.js +0 -3
  54. package/dist/storage-DB6SRCPR.cjs +0 -24
package/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # mastracode
2
2
 
3
+ ## 0.19.0-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`bdb4cbf`](https://github.com/mastra-ai/mastra/commit/bdb4cbf8ba4b685d7481f28bb9dc3de6c79c9ed2)]:
8
+ - @mastra/core@1.34.0-alpha.2
9
+
10
+ ## 0.19.0-alpha.1
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [[`fceae1f`](https://github.com/mastra-ai/mastra/commit/fceae1f5f5db4722cb078a663c6eb4bd22944123), [`97fe629`](https://github.com/mastra-ai/mastra/commit/97fe629d07b0a9952e6657b1e6334ca4d9aa15ce), [`bf02acb`](https://github.com/mastra-ai/mastra/commit/bf02acbb8a6110f638ac844e89f1ebf04cb7fe74), [`0fd3fbe`](https://github.com/mastra-ai/mastra/commit/0fd3fbe40fb63657aedd72f6e7b38c8e8ee6940d), [`fed0475`](https://github.com/mastra-ai/mastra/commit/fed0475ccfea31e4fc251469ac05640d0742c1f0), [`522f44d`](https://github.com/mastra-ai/mastra/commit/522f44d947214bfc06cff50599bae1ef3494880d)]:
15
+ - @mastra/core@1.34.0-alpha.1
16
+ - @mastra/memory@1.18.1-alpha.0
17
+
18
+ ## 0.19.0-alpha.0
19
+
20
+ ### Minor Changes
21
+
22
+ - Improved OpenAI Codex OAuth support in Mastra Code. When you select the Codex provider in `/login` or during onboarding, Mastra Code now asks how to sign in — **Browser (local callback)** or **Device code (headless)** — so the device-code flow is discoverable without setting an env var. `MASTRACODE_OPENAI_CODEX_AUTH_MODE=device` still works as a preselect for scripted environments. ([#16548](https://github.com/mastra-ai/mastra/pull/16548))
23
+
24
+ HTTP MCP server config can now pass OAuth client metadata to `@mastra/mcp` and store per-server OAuth state without sharing tokens across projects:
25
+
26
+ ```json
27
+ {
28
+ "mcpServers": {
29
+ "remote-api": {
30
+ "url": "https://mcp.example.com/mcp",
31
+ "oauth": {
32
+ "redirectUrl": "http://localhost:3000/oauth/callback"
33
+ }
34
+ }
35
+ }
36
+ }
37
+ ```
38
+
39
+ ### Patch Changes
40
+
41
+ - Updated dependencies [[`20787de`](https://github.com/mastra-ai/mastra/commit/20787de5965234a1af28fe35f49437c537dbfa0d), [`784ad98`](https://github.com/mastra-ai/mastra/commit/784ad989549de91dc5d33ab8ef36caa6f7dcd34e), [`0d53730`](https://github.com/mastra-ai/mastra/commit/0d53730c1ed87ef80c87caa5701c4170ea8028e6)]:
42
+ - @mastra/core@1.34.0-alpha.0
43
+
3
44
  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B,CAAC,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,cAAc,CAAA;CAAE,GACzG,aAAa,CAuJf;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,EAAE,cAAc,EAAE,EAAE;IAAE,cAAc,EAAE,cAAc,CAAA;CAAE,GAAG,aAAa,CAWrG"}
@@ -5,4 +5,5 @@ export * from './types.js';
5
5
  export * from './storage.js';
6
6
  export { anthropicOAuthProvider } from './providers/anthropic.js';
7
7
  export { githubCopilotOAuthProvider } from './providers/github-copilot.js';
8
+ export { openaiCodexOAuthProvider } from './providers/openai-codex.js';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC"}
@@ -7,7 +7,26 @@
7
7
  * NOTE: This module uses Node.js crypto and http for the OAuth callback.
8
8
  * It is only intended for CLI use, not browser environments.
9
9
  */
10
- import type { OAuthCredentials, OAuthPrompt, OAuthProviderInterface } from '../types.js';
10
+ import type { AuthMode, OAuthCredentials, OAuthPrompt, OAuthProviderInterface } from '../types.js';
11
+ export declare const OPENAI_CODEX_AUTH_MODES: ReadonlyArray<AuthMode>;
12
+ declare const JWT_CLAIM_PATH = "https://api.openai.com/auth";
13
+ type JwtPayload = {
14
+ chatgpt_account_id?: string;
15
+ [JWT_CLAIM_PATH]?: {
16
+ chatgpt_account_id?: string;
17
+ };
18
+ [key: string]: unknown;
19
+ };
20
+ declare function decodeJwt(token: string): JwtPayload | null;
21
+ declare function extractAccountIdFromClaims(payload: JwtPayload | null | undefined): string | null;
22
+ declare function getAccountId(tokens: {
23
+ idToken?: string;
24
+ access: string;
25
+ }, fallback?: string): string | undefined;
26
+ declare function requireAccountId(tokens: {
27
+ idToken?: string;
28
+ access: string;
29
+ }, fallback?: string): string;
11
30
  declare function createAuthorizationFlow(redirectUri: string, state: string, originator?: string): Promise<{
12
31
  verifier: string;
13
32
  url: string;
@@ -26,6 +45,15 @@ type CallbackPorts = {
26
45
  fallbackPort: number;
27
46
  };
28
47
  declare function startLocalOAuthServer(state: string, ports?: CallbackPorts): Promise<OAuthServerInfo>;
48
+ declare function loginOpenAICodexDevice(options: {
49
+ onAuth: (info: {
50
+ url: string;
51
+ instructions?: string;
52
+ }) => void;
53
+ onProgress?: (message: string) => void;
54
+ signal?: AbortSignal;
55
+ sleep?: (ms: number) => Promise<void>;
56
+ }): Promise<OAuthCredentials>;
29
57
  /**
30
58
  * Login with OpenAI Codex OAuth
31
59
  *
@@ -35,7 +63,7 @@ declare function startLocalOAuthServer(state: string, ports?: CallbackPorts): Pr
35
63
  * @param options.onManualCodeInput - Optional promise that resolves with user-pasted code.
36
64
  * Races with browser callback - whichever completes first wins.
37
65
  * Useful for showing paste input immediately alongside browser flow.
38
- * @param options.originator - OAuth originator parameter (defaults to "pi")
66
+ * @param options.originator - OAuth originator parameter (defaults to "mastracode")
39
67
  */
40
68
  export declare function loginOpenAICodex(options: {
41
69
  onAuth: (info: {
@@ -45,16 +73,23 @@ export declare function loginOpenAICodex(options: {
45
73
  onPrompt: (prompt: OAuthPrompt) => Promise<string>;
46
74
  onProgress?: (message: string) => void;
47
75
  onManualCodeInput?: () => Promise<string>;
76
+ signal?: AbortSignal;
48
77
  originator?: string;
78
+ mode?: 'browser' | 'device';
49
79
  }): Promise<OAuthCredentials>;
50
80
  export declare const __testing: {
51
81
  createAuthorizationFlow: typeof createAuthorizationFlow;
82
+ decodeJwt: typeof decodeJwt;
83
+ extractAccountIdFromClaims: typeof extractAccountIdFromClaims;
84
+ getAccountId: typeof getAccountId;
85
+ loginOpenAICodexDevice: typeof loginOpenAICodexDevice;
86
+ requireAccountId: typeof requireAccountId;
52
87
  startLocalOAuthServer: typeof startLocalOAuthServer;
53
88
  };
54
89
  /**
55
90
  * Refresh OpenAI Codex OAuth token
56
91
  */
57
- export declare function refreshOpenAICodexToken(refreshToken: string): Promise<OAuthCredentials>;
92
+ export declare function refreshOpenAICodexToken(refreshToken: string, previousAccountId?: string): Promise<OAuthCredentials>;
58
93
  export declare const openaiCodexOAuthProvider: OAuthProviderInterface;
59
94
  export {};
60
95
  //# sourceMappingURL=openai-codex.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"openai-codex.d.ts","sourceRoot":"","sources":["../../../src/auth/providers/openai-codex.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAyBH,OAAO,KAAK,EAAE,gBAAgB,EAAuB,WAAW,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAyK9G,iBAAe,uBAAuB,CACpC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,UAAU,GAAE,MAAa,GACxB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAgB5C;AAED,KAAK,eAAe,GAAG;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,WAAW,EAAE,MAAM,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,I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AC,EAAE,MAAM,GACzB,OAAO,CAAC,gBAAgB,CAAC,CAc3B;AAED,eAAO,MAAM,wBAAwB,EAAE,sBAyBtC,CAAC"}
@@ -17,18 +17,38 @@ export interface OAuthPrompt {
17
17
  placeholder?: string;
18
18
  allowEmpty?: boolean;
19
19
  }
20
+ /**
21
+ * A selectable authentication mode for an OAuth provider.
22
+ * Providers that support multiple flows (e.g. browser callback vs. device code)
23
+ * advertise them via `OAuthProviderInterface.authModes`. The TUI shows a
24
+ * sub-selector when more than one mode is available so users don't need to
25
+ * discover the flow through environment variables.
26
+ */
27
+ export interface AuthMode {
28
+ id: string;
29
+ name: string;
30
+ description?: string;
31
+ }
20
32
  export interface OAuthLoginCallbacks {
21
33
  onAuth: (info: OAuthAuthInfo) => void;
22
34
  onPrompt: (prompt: OAuthPrompt) => Promise<string>;
23
35
  onProgress?: (message: string) => void;
24
36
  onManualCodeInput?: () => Promise<string>;
25
37
  signal?: AbortSignal;
38
+ /** Selected authentication mode id (matches one of `OAuthProviderInterface.authModes`). */
39
+ authMode?: string;
26
40
  }
27
41
  export interface OAuthProviderInterface {
28
42
  readonly id: OAuthProviderId;
29
43
  readonly name: string;
30
44
  /** Whether this provider uses a local callback server (vs manual code paste) */
31
45
  readonly usesCallbackServer?: boolean;
46
+ /**
47
+ * Optional list of selectable auth flows. When set with two or more entries,
48
+ * the TUI prompts the user to pick a mode before starting the login flow and
49
+ * forwards the choice via `OAuthLoginCallbacks.authMode`.
50
+ */
51
+ readonly authModes?: ReadonlyArray<AuthMode>;
32
52
  /** Run the login flow, return credentials to persist */
33
53
  login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;
34
54
  /** Refresh expired credentials, return updated credentials to persist */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,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C;IACrB,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,EAAE,eAAe,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,gFAAgF;IAChF,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAEtC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAE7C,wDAAwD;IACxD,KAAK,CAAC,SAAS,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAEjE,yEAAyE;IACzE,YAAY,CAAC,WAAW,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAEvE,6DAA6D;IAC7D,SAAS,CAAC,WAAW,EAAE,gBAAgB,GAAG,MAAM,CAAC;CAClD;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,OAAO,CAAC;CACf,GAAG,gBAAgB,CAAC;AAErB,MAAM,MAAM,cAAc,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC"}
@@ -674,23 +674,44 @@ var githubCopilotOAuthProvider = {
674
674
 
675
675
  // src/auth/providers/openai-codex.ts
676
676
  var _randomBytes = null;
677
+ var _cryptoPromise = null;
677
678
  var _httpPromise = null;
678
679
  var _http = null;
679
680
  if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) {
680
- import('crypto').then((m) => {
681
+ _cryptoPromise = import('crypto').then((m) => {
681
682
  _randomBytes = m.randomBytes;
683
+ return m;
682
684
  });
683
685
  _httpPromise = import('http').then((m) => {
684
686
  _http = m;
685
687
  return m;
686
688
  });
687
689
  }
690
+ var OPENAI_CODEX_AUTH_MODES = [
691
+ {
692
+ id: "browser",
693
+ name: "Browser (local callback)",
694
+ description: "Opens the browser and waits for the OAuth callback on localhost."
695
+ },
696
+ {
697
+ id: "device",
698
+ name: "Device code (headless)",
699
+ description: "Shows a code to enter at openai.com \u2014 for SSH, remote, or no-browser environments."
700
+ }
701
+ ];
688
702
  var CLIENT_ID3 = "app_EMoamEEZ73f0CkXaXp7hrann";
689
- var AUTHORIZE_URL2 = "https://auth.openai.com/oauth/authorize";
690
- var TOKEN_URL2 = "https://auth.openai.com/oauth/token";
703
+ var ISSUER = "https://auth.openai.com";
704
+ var AUTHORIZE_URL2 = `${ISSUER}/oauth/authorize`;
705
+ var TOKEN_URL2 = `${ISSUER}/oauth/token`;
706
+ var DEVICE_USER_CODE_URL = `${ISSUER}/api/accounts/deviceauth/usercode`;
707
+ var DEVICE_TOKEN_URL = `${ISSUER}/api/accounts/deviceauth/token`;
708
+ var DEVICE_AUTHORIZE_URL = `${ISSUER}/codex/device`;
709
+ var DEVICE_REDIRECT_URI = `${ISSUER}/deviceauth/callback`;
691
710
  var DEFAULT_CALLBACK_PORT = 1455;
692
711
  var FALLBACK_CALLBACK_PORT = 1457;
693
- var SCOPE = "openid profile email offline_access";
712
+ var DEFAULT_TOKEN_EXPIRES_IN_SECONDS = 3600;
713
+ var DEVICE_AUTH_TIMEOUT_MS = 15 * 60 * 1e3;
714
+ var SCOPE = "openid profile email offline_access api.connectors.read api.connectors.invoke";
694
715
  var JWT_CLAIM_PATH = "https://api.openai.com/auth";
695
716
  var SUCCESS_HTML = `<!doctype html>
696
717
  <html lang="en">
@@ -703,11 +724,9 @@ var SUCCESS_HTML = `<!doctype html>
703
724
  <p>Authentication successful. Return to your terminal to continue.</p>
704
725
  </body>
705
726
  </html>`;
706
- function createState() {
707
- if (!_randomBytes) {
708
- throw new Error("OpenAI Codex OAuth is only available in Node.js environments");
709
- }
710
- return _randomBytes(16).toString("hex");
727
+ async function createState() {
728
+ const randomBytes = await getRandomBytes();
729
+ return randomBytes(16).toString("hex");
711
730
  }
712
731
  function parseAuthorizationInput(input) {
713
732
  const value = input.trim();
@@ -738,12 +757,45 @@ function decodeJwt(token) {
738
757
  const parts = token.split(".");
739
758
  if (parts.length !== 3) return null;
740
759
  const payload = parts[1] ?? "";
741
- const decoded = atob(payload);
760
+ const padded = payload.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(payload.length / 4) * 4, "=");
761
+ const decoded = atob(padded);
742
762
  return JSON.parse(decoded);
743
763
  } catch {
744
764
  return null;
745
765
  }
746
766
  }
767
+ function extractAccountIdFromClaims(payload) {
768
+ if (!payload) return null;
769
+ const accountId = payload.chatgpt_account_id ?? payload[JWT_CLAIM_PATH]?.chatgpt_account_id;
770
+ return typeof accountId === "string" && accountId.length > 0 ? accountId : null;
771
+ }
772
+ function getAccountId(tokens, fallback) {
773
+ const fromIdToken = tokens.idToken ? extractAccountIdFromClaims(decodeJwt(tokens.idToken)) : null;
774
+ if (fromIdToken) return fromIdToken;
775
+ const fromAccessToken = extractAccountIdFromClaims(decodeJwt(tokens.access));
776
+ if (fromAccessToken) return fromAccessToken;
777
+ return fallback;
778
+ }
779
+ function requireAccountId(tokens, fallback) {
780
+ const accountId = getAccountId(tokens, fallback);
781
+ if (!accountId) {
782
+ throw new Error("Failed to extract ChatGPT account id from OpenAI Codex token");
783
+ }
784
+ return accountId;
785
+ }
786
+ function tokenResponseToResult(json, logPrefix) {
787
+ if (!json.access_token || !json.refresh_token) {
788
+ console.error(`[openai-codex] ${logPrefix} response missing fields:`, json);
789
+ return { type: "failed" };
790
+ }
791
+ return {
792
+ type: "success",
793
+ access: json.access_token,
794
+ refresh: json.refresh_token,
795
+ expires: Date.now() + (json.expires_in ?? DEFAULT_TOKEN_EXPIRES_IN_SECONDS) * 1e3,
796
+ idToken: json.id_token
797
+ };
798
+ }
747
799
  async function exchangeAuthorizationCode(code, verifier, redirectUri) {
748
800
  const response = await fetch(TOKEN_URL2, {
749
801
  method: "POST",
@@ -761,17 +813,7 @@ async function exchangeAuthorizationCode(code, verifier, redirectUri) {
761
813
  console.error("[openai-codex] code->token failed:", response.status, text);
762
814
  return { type: "failed" };
763
815
  }
764
- const json = await response.json();
765
- if (!json.access_token || !json.refresh_token || typeof json.expires_in !== "number") {
766
- console.error("[openai-codex] token response missing fields:", json);
767
- return { type: "failed" };
768
- }
769
- return {
770
- type: "success",
771
- access: json.access_token,
772
- refresh: json.refresh_token,
773
- expires: Date.now() + json.expires_in * 1e3
774
- };
816
+ return tokenResponseToResult(await response.json(), "token");
775
817
  }
776
818
  async function refreshAccessToken(refreshToken) {
777
819
  try {
@@ -789,23 +831,22 @@ async function refreshAccessToken(refreshToken) {
789
831
  console.error("[openai-codex] Token refresh failed:", response.status, text);
790
832
  return { type: "failed" };
791
833
  }
792
- const json = await response.json();
793
- if (!json.access_token || !json.refresh_token || typeof json.expires_in !== "number") {
794
- console.error("[openai-codex] Token refresh response missing fields:", json);
795
- return { type: "failed" };
796
- }
797
- return {
798
- type: "success",
799
- access: json.access_token,
800
- refresh: json.refresh_token,
801
- expires: Date.now() + json.expires_in * 1e3
802
- };
834
+ return tokenResponseToResult(await response.json(), "Token refresh");
803
835
  } catch (error) {
804
836
  console.error("[openai-codex] Token refresh error:", error);
805
837
  return { type: "failed" };
806
838
  }
807
839
  }
808
- async function createAuthorizationFlow(redirectUri, state, originator = "pi") {
840
+ async function getRandomBytes() {
841
+ if (!_randomBytes && _cryptoPromise) {
842
+ _randomBytes = (await _cryptoPromise).randomBytes;
843
+ }
844
+ if (!_randomBytes) {
845
+ throw new Error("OpenAI Codex OAuth is only available in Node.js environments");
846
+ }
847
+ return _randomBytes;
848
+ }
849
+ async function createAuthorizationFlow(redirectUri, state, originator = "mastracode") {
809
850
  const { verifier, challenge } = await generatePKCE();
810
851
  const url = new URL(AUTHORIZE_URL2);
811
852
  url.searchParams.set("response_type", "code");
@@ -935,19 +976,100 @@ async function startLocalOAuthServer(state, ports = CODEX_CALLBACK_PORTS) {
935
976
  });
936
977
  });
937
978
  }
938
- function getAccountId(accessToken) {
939
- const payload = decodeJwt(accessToken);
940
- const auth = payload?.[JWT_CLAIM_PATH];
941
- const accountId = auth?.chatgpt_account_id;
942
- return typeof accountId === "string" && accountId.length > 0 ? accountId : null;
979
+ async function loginOpenAICodexDevice(options) {
980
+ const response = await fetch(DEVICE_USER_CODE_URL, {
981
+ method: "POST",
982
+ headers: {
983
+ "Content-Type": "application/json",
984
+ "User-Agent": "mastracode"
985
+ },
986
+ body: JSON.stringify({ client_id: CLIENT_ID3, originator: "mastracode" }),
987
+ signal: options.signal
988
+ });
989
+ if (!response.ok) {
990
+ throw new Error(`Failed to initiate OpenAI Codex device authorization: ${response.status}`);
991
+ }
992
+ const deviceData = await response.json();
993
+ const userCode = deviceData.user_code ?? deviceData.usercode;
994
+ if (!deviceData.device_auth_id || !userCode) {
995
+ throw new Error("OpenAI Codex device authorization response missing required fields");
996
+ }
997
+ const intervalSeconds = typeof deviceData.interval === "number" ? deviceData.interval : Number.parseInt(deviceData.interval ?? "", 10) || 5;
998
+ const pollDelayMs = Math.max(intervalSeconds, 1) * 1e3;
999
+ const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
1000
+ const startedAt = Date.now();
1001
+ options.onAuth({
1002
+ url: DEVICE_AUTHORIZE_URL,
1003
+ instructions: `Enter code: ${userCode}`
1004
+ });
1005
+ while (true) {
1006
+ if (options.signal?.aborted) {
1007
+ throw new Error("Login cancelled");
1008
+ }
1009
+ if (Date.now() - startedAt >= DEVICE_AUTH_TIMEOUT_MS) {
1010
+ throw new Error("OpenAI Codex device authorization timed out after 15 minutes");
1011
+ }
1012
+ const pollResponse = await fetch(DEVICE_TOKEN_URL, {
1013
+ method: "POST",
1014
+ headers: {
1015
+ "Content-Type": "application/json",
1016
+ "User-Agent": "mastracode"
1017
+ },
1018
+ body: JSON.stringify({
1019
+ device_auth_id: deviceData.device_auth_id,
1020
+ user_code: userCode
1021
+ }),
1022
+ signal: options.signal
1023
+ });
1024
+ if (pollResponse.ok) {
1025
+ const data = await pollResponse.json();
1026
+ if (!data.authorization_code || !data.code_verifier) {
1027
+ throw new Error("OpenAI Codex device token response missing required fields");
1028
+ }
1029
+ const tokenResult = await exchangeAuthorizationCode(
1030
+ data.authorization_code,
1031
+ data.code_verifier,
1032
+ DEVICE_REDIRECT_URI
1033
+ );
1034
+ if (tokenResult.type !== "success") {
1035
+ throw new Error("Token exchange failed");
1036
+ }
1037
+ const accountId = requireAccountId(tokenResult);
1038
+ return {
1039
+ access: tokenResult.access,
1040
+ refresh: tokenResult.refresh,
1041
+ expires: tokenResult.expires,
1042
+ accountId
1043
+ };
1044
+ }
1045
+ if (pollResponse.status !== 403 && pollResponse.status !== 404) {
1046
+ const text = await pollResponse.text().catch(() => "");
1047
+ throw new Error(`OpenAI Codex device authorization failed: ${pollResponse.status}${text ? ` ${text}` : ""}`);
1048
+ }
1049
+ options.onProgress?.("Waiting for OpenAI Codex device authorization...");
1050
+ await sleep(pollDelayMs);
1051
+ }
943
1052
  }
944
1053
  async function loginOpenAICodex(options) {
945
- const state = createState();
1054
+ const envMode = typeof process !== "undefined" && process.env?.MASTRACODE_OPENAI_CODEX_AUTH_MODE === "device" ? "device" : void 0;
1055
+ const mode = options.mode ?? envMode ?? "browser";
1056
+ if (mode === "device") {
1057
+ return loginOpenAICodexDevice({
1058
+ onAuth: options.onAuth,
1059
+ onProgress: options.onProgress,
1060
+ signal: options.signal
1061
+ });
1062
+ }
1063
+ const state = await createState();
946
1064
  const server = await startLocalOAuthServer(state);
947
1065
  if (server.warning) {
948
1066
  options.onProgress?.(server.warning);
949
1067
  }
950
- const { verifier, url } = await createAuthorizationFlow(server.redirectUri, state, options.originator);
1068
+ const { verifier, url } = await createAuthorizationFlow(
1069
+ server.redirectUri,
1070
+ state,
1071
+ options.originator ?? "mastracode"
1072
+ );
951
1073
  options.onAuth({
952
1074
  url,
953
1075
  instructions: server.warning ? `${server.warning} You can still paste the authorization code or full redirect URL manually.` : "A browser window should open. Complete login to finish."
@@ -1013,10 +1135,7 @@ async function loginOpenAICodex(options) {
1013
1135
  if (tokenResult.type !== "success") {
1014
1136
  throw new Error("Token exchange failed");
1015
1137
  }
1016
- const accountId = getAccountId(tokenResult.access);
1017
- if (!accountId) {
1018
- throw new Error("Failed to extract accountId from token");
1019
- }
1138
+ const accountId = requireAccountId(tokenResult);
1020
1139
  return {
1021
1140
  access: tokenResult.access,
1022
1141
  refresh: tokenResult.refresh,
@@ -1027,15 +1146,12 @@ async function loginOpenAICodex(options) {
1027
1146
  server.close();
1028
1147
  }
1029
1148
  }
1030
- async function refreshOpenAICodexToken(refreshToken) {
1149
+ async function refreshOpenAICodexToken(refreshToken, previousAccountId) {
1031
1150
  const result = await refreshAccessToken(refreshToken);
1032
1151
  if (result.type !== "success") {
1033
1152
  throw new Error("Failed to refresh OpenAI Codex token");
1034
1153
  }
1035
- const accountId = getAccountId(result.access);
1036
- if (!accountId) {
1037
- throw new Error("Failed to extract accountId from token");
1038
- }
1154
+ const accountId = requireAccountId(result, previousAccountId);
1039
1155
  return {
1040
1156
  access: result.access,
1041
1157
  refresh: result.refresh,
@@ -1047,16 +1163,20 @@ var openaiCodexOAuthProvider = {
1047
1163
  id: "openai-codex",
1048
1164
  name: "ChatGPT Plus/Pro (Codex Subscription)",
1049
1165
  usesCallbackServer: true,
1166
+ authModes: OPENAI_CODEX_AUTH_MODES,
1050
1167
  async login(callbacks) {
1168
+ const mode = callbacks.authMode === "device" || callbacks.authMode === "browser" ? callbacks.authMode : void 0;
1051
1169
  return loginOpenAICodex({
1052
1170
  onAuth: callbacks.onAuth,
1053
1171
  onPrompt: callbacks.onPrompt,
1054
1172
  onProgress: callbacks.onProgress,
1055
- onManualCodeInput: callbacks.onManualCodeInput
1173
+ onManualCodeInput: callbacks.onManualCodeInput,
1174
+ signal: callbacks.signal,
1175
+ mode
1056
1176
  });
1057
1177
  },
1058
1178
  async refreshToken(credentials) {
1059
- return refreshOpenAICodexToken(credentials.refresh);
1179
+ return refreshOpenAICodexToken(credentials.refresh, credentials.accountId);
1060
1180
  },
1061
1181
  getApiKey(credentials) {
1062
1182
  return credentials.access;
@@ -1088,6 +1208,7 @@ var AuthStorage = class {
1088
1208
  this.authPath = authPath;
1089
1209
  this.reload();
1090
1210
  }
1211
+ authPath;
1091
1212
  data = {};
1092
1213
  /**
1093
1214
  * Reload credentials from disk.
@@ -1239,5 +1360,5 @@ var AuthStorage = class {
1239
1360
  };
1240
1361
 
1241
1362
  export { AuthStorage, COPILOT_HEADERS, PROVIDER_DEFAULT_MODELS, detectProject, fetchCopilotModels, getAppDataDir, getCurrentGitBranch, getDatabasePath, getGitHubCopilotBaseUrl, getOAuthProvider, getOAuthProviders, getObservabilityDatabasePath, getOmScope, getResourceIdOverride, getStorageConfig, getUserId, getUserName, getVectorDatabasePath };
1242
- //# sourceMappingURL=chunk-EQBHZCMR.js.map
1243
- //# sourceMappingURL=chunk-EQBHZCMR.js.map
1363
+ //# sourceMappingURL=chunk-5YJR6NJL.js.map
1364
+ //# sourceMappingURL=chunk-5YJR6NJL.js.map