@opengeni/codex 0.2.5 → 0.2.7

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.
@@ -25,6 +25,12 @@ var CODEX_MODEL_AUTO_COMPACT_TOKEN_LIMIT = Math.floor(
25
25
  var CODEX_CLIENT_VERSION = "0.144.6";
26
26
  var CODEX_REFRESH_WINDOW_MS = 5 * 60 * 1e3;
27
27
  var CODEX_REFRESH_FALLBACK_MS = 8 * 24 * 60 * 60 * 1e3;
28
+ var CODEX_RESPONSE_HEADERS_TIMEOUT_MS = 4 * 6e4;
29
+ var CODEX_RESPONSE_STREAM_IDLE_TIMEOUT_MS = 5 * 6e4;
30
+ var CODEX_RESPONSE_WHOLE_TIMEOUT_MS = 30 * 6e4;
31
+ var CODEX_RESPONSE_NO_BYTE_RETRIES = 0;
32
+ var CODEX_RESPONSE_RETRY_BACKOFF_MS = 1e3;
33
+ var CODEX_RESPONSE_SDK_OUTER_TIMEOUT_MS = 35 * 6e4;
28
34
  var CODEX_APPS_MCP_SERVER_ID = "codex_apps";
29
35
  var CODEX_APPS_MCP_SERVER_NAME = "codex_apps";
30
36
  var CODEX_APPS_MCP_URL = "https://chatgpt.com/backend-api/ps/mcp";
@@ -54,10 +60,16 @@ export {
54
60
  CODEX_CLIENT_VERSION,
55
61
  CODEX_REFRESH_WINDOW_MS,
56
62
  CODEX_REFRESH_FALLBACK_MS,
63
+ CODEX_RESPONSE_HEADERS_TIMEOUT_MS,
64
+ CODEX_RESPONSE_STREAM_IDLE_TIMEOUT_MS,
65
+ CODEX_RESPONSE_WHOLE_TIMEOUT_MS,
66
+ CODEX_RESPONSE_NO_BYTE_RETRIES,
67
+ CODEX_RESPONSE_RETRY_BACKOFF_MS,
68
+ CODEX_RESPONSE_SDK_OUTER_TIMEOUT_MS,
57
69
  CODEX_APPS_MCP_SERVER_ID,
58
70
  CODEX_APPS_MCP_SERVER_NAME,
59
71
  CODEX_APPS_MCP_URL,
60
72
  CODEX_APPS_STARTUP_TIMEOUT_MS,
61
73
  CODEX_APPS_REQUIRED_SCOPES
62
74
  };
63
- //# sourceMappingURL=chunk-AMRVHBCD.js.map
75
+ //# sourceMappingURL=chunk-YGKQDUY7.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/constants.ts"],"sourcesContent":["// Wire constants for the ChatGPT/Codex subscription backend.\n// Source: CODEX-SUBSCRIPTION-SPEC.md (verified against openai/codex codex-rs).\n\nexport const CODEX_ISSUER = \"https://auth.openai.com\";\nexport const CODEX_CLIENT_ID = \"app_EMoamEEZ73f0CkXaXp7hrann\"; // spec §1.1 (manager.rs:1444)\nexport const CODEX_AUTH_BASE = `${CODEX_ISSUER}/api/accounts`; // device endpoints (device_code_auth.rs:164)\nexport const CODEX_TOKEN_URL = `${CODEX_ISSUER}/oauth/token`; // exchange (form) + refresh (json)\nexport const CODEX_DEVICE_VERIFICATION_URL = `${CODEX_ISSUER}/codex/device`;\nexport const CODEX_DEVICE_REDIRECT_URI = `${CODEX_ISSUER}/deviceauth/callback`;\n\n// Model requests: base already includes /codex; client appends /responses, /models.\nexport const CODEX_RESPONSES_BASE = \"https://chatgpt.com/backend-api/codex\";\n// Usage lives on the WHAM base — NOT under /codex (verified, spec §1.8a).\nexport const CODEX_WHAM_BASE = \"https://chatgpt.com/backend-api\";\n\nexport const CODEX_ORIGINATOR = \"codex_cli_rs\"; // whitelisted originator (spec §1.2)\nexport const CODEX_ID_TOKEN_AUTH_CLAIM = \"https://api.openai.com/auth\";\n\n// Synthetic registry-provider identity. The provider's baseURL is the bare\n// /backend-api (NOT /codex) — codexSubscriptionFetch rewrites /responses ->\n// /codex/responses. Codex model ids are namespaced `codex/<slug>` so they never\n// collide with the built-in OpenAI provider's model ids; the fetch's resolveModel\n// strips the prefix before the slug reaches the backend.\nexport const CODEX_PROVIDER_ID = \"codex-subscription\";\nexport const CODEX_PROVIDER_BASE_URL = \"https://chatgpt.com/backend-api\";\nexport const CODEX_MODEL_ID_PREFIX = \"codex/\";\n\n// The only Codex subscription models OpenGeni exposes. The live GET /models\n// catalog must contain every exact slug; older or internal models never broaden\n// this product allowlist.\nexport const CODEX_FALLBACK_MODEL_SLUGS = [\"gpt-5.6-sol\", \"gpt-5.6-terra\", \"gpt-5.6-luna\"] as const;\n\n// Live Codex model-catalog values for every exposed gpt-5.6 subscription slug.\n// Verified 2026-07-18 against Codex CLI 0.144.6's freshly fetched\n// ~/.codex/models_cache.json and the matching openai/codex core derivations:\n// raw context window = 272,000\n// effective input window (95%) = 258,400\n// automatic compaction limit (90%) = 244,800\n// Keep all three explicit: the effective ceiling is a hard input guard while\n// the lower auto-compact limit is the proactive checkpoint trigger.\nexport const CODEX_MODEL_CONTEXT_WINDOW_TOKENS = 272_000;\nexport const CODEX_EFFECTIVE_CONTEXT_WINDOW_PERCENT = 95;\nexport const CODEX_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS = Math.floor(\n (CODEX_MODEL_CONTEXT_WINDOW_TOKENS * CODEX_EFFECTIVE_CONTEXT_WINDOW_PERCENT) / 100,\n);\nexport const CODEX_AUTO_COMPACTION_PERCENT = 90;\nexport const CODEX_MODEL_AUTO_COMPACT_TOKEN_LIMIT = Math.floor(\n (CODEX_MODEL_CONTEXT_WINDOW_TOKENS * CODEX_AUTO_COMPACTION_PERCENT) / 100,\n);\n\n// Sent as the `version` header and inside the User-Agent. Staging-proven on\n// 2026-07-09: 0.142.4 filtered every GPT-5.6 slug out of GET /models, while the\n// official Codex 0.144.0+ releases return all three exact slugs above. Keep\n// this pinned to the latest stable Codex release we have verified end-to-end.\nexport const CODEX_CLIENT_VERSION = \"0.144.6\";\n\nexport const CODEX_REFRESH_WINDOW_MS = 5 * 60 * 1000; // proactive refresh when within 5 min of exp (spec §1.1)\nexport const CODEX_REFRESH_FALLBACK_MS = 8 * 24 * 60 * 60 * 1000; // 8 days when exp is unparseable\n\n// ── Apps / connectors MCP (spec §1.10, §E) ───────────────────────────────────\n// One server-side MCP exposes ALL the user's ChatGPT/Codex connectors\n// (gmail/github/linear/slack/sentry/drive/calendar/…). Streamable HTTP, always.\nexport const CODEX_APPS_MCP_SERVER_ID = \"codex_apps\"; // tools surface as mcp__codex_apps__<tool>\nexport const CODEX_APPS_MCP_SERVER_NAME = \"codex_apps\"; // MCP `name` — MUST equal the id so the SDK namespaces tools as mcp__codex_apps__*\nexport const CODEX_APPS_MCP_URL = \"https://chatgpt.com/backend-api/ps/mcp\"; // live URL (NOT /codex, NOT the legacy /wham/apps)\nexport const CODEX_APPS_STARTUP_TIMEOUT_MS = 30_000; // startup_timeout 30s (spec §1.10) — maps to timeoutMs on this server only\n// Connector scopes that the apps MCP requires. Present ONLY when granted at\n// browser-authorize time; the device-code path CANNOT be confirmed to grant\n// them, so treat connector availability as runtime-discovered (spec §1.10 / §E).\nexport const CODEX_APPS_REQUIRED_SCOPES = [\"api.connectors.read\", \"api.connectors.invoke\"] as const;\n"],"mappings":";AAGO,IAAM,eAAe;AACrB,IAAM,kBAAkB;AACxB,IAAM,kBAAkB,GAAG,YAAY;AACvC,IAAM,kBAAkB,GAAG,YAAY;AACvC,IAAM,gCAAgC,GAAG,YAAY;AACrD,IAAM,4BAA4B,GAAG,YAAY;AAGjD,IAAM,uBAAuB;AAE7B,IAAM,kBAAkB;AAExB,IAAM,mBAAmB;AACzB,IAAM,4BAA4B;AAOlC,IAAM,oBAAoB;AAC1B,IAAM,0BAA0B;AAChC,IAAM,wBAAwB;AAK9B,IAAM,6BAA6B,CAAC,eAAe,iBAAiB,cAAc;AAUlF,IAAM,oCAAoC;AAC1C,IAAM,yCAAyC;AAC/C,IAAM,8CAA8C,KAAK;AAAA,EAC7D,oCAAoC,yCAA0C;AACjF;AACO,IAAM,gCAAgC;AACtC,IAAM,uCAAuC,KAAK;AAAA,EACtD,oCAAoC,gCAAiC;AACxE;AAMO,IAAM,uBAAuB;AAE7B,IAAM,0BAA0B,IAAI,KAAK;AACzC,IAAM,4BAA4B,IAAI,KAAK,KAAK,KAAK;AAKrD,IAAM,2BAA2B;AACjC,IAAM,6BAA6B;AACnC,IAAM,qBAAqB;AAC3B,IAAM,gCAAgC;AAItC,IAAM,6BAA6B,CAAC,uBAAuB,uBAAuB;","names":[]}
1
+ {"version":3,"sources":["../src/constants.ts"],"sourcesContent":["// Wire constants for the ChatGPT/Codex subscription backend.\n// Source: CODEX-SUBSCRIPTION-SPEC.md (verified against openai/codex codex-rs).\n\nexport const CODEX_ISSUER = \"https://auth.openai.com\";\nexport const CODEX_CLIENT_ID = \"app_EMoamEEZ73f0CkXaXp7hrann\"; // spec §1.1 (manager.rs:1444)\nexport const CODEX_AUTH_BASE = `${CODEX_ISSUER}/api/accounts`; // device endpoints (device_code_auth.rs:164)\nexport const CODEX_TOKEN_URL = `${CODEX_ISSUER}/oauth/token`; // exchange (form) + refresh (json)\nexport const CODEX_DEVICE_VERIFICATION_URL = `${CODEX_ISSUER}/codex/device`;\nexport const CODEX_DEVICE_REDIRECT_URI = `${CODEX_ISSUER}/deviceauth/callback`;\n\n// Model requests: base already includes /codex; client appends /responses, /models.\nexport const CODEX_RESPONSES_BASE = \"https://chatgpt.com/backend-api/codex\";\n// Usage lives on the WHAM base — NOT under /codex (verified, spec §1.8a).\nexport const CODEX_WHAM_BASE = \"https://chatgpt.com/backend-api\";\n\nexport const CODEX_ORIGINATOR = \"codex_cli_rs\"; // whitelisted originator (spec §1.2)\nexport const CODEX_ID_TOKEN_AUTH_CLAIM = \"https://api.openai.com/auth\";\n\n// Synthetic registry-provider identity. The provider's baseURL is the bare\n// /backend-api (NOT /codex) — codexSubscriptionFetch rewrites /responses ->\n// /codex/responses. Codex model ids are namespaced `codex/<slug>` so they never\n// collide with the built-in OpenAI provider's model ids; the fetch's resolveModel\n// strips the prefix before the slug reaches the backend.\nexport const CODEX_PROVIDER_ID = \"codex-subscription\";\nexport const CODEX_PROVIDER_BASE_URL = \"https://chatgpt.com/backend-api\";\nexport const CODEX_MODEL_ID_PREFIX = \"codex/\";\n\n// The only Codex subscription models OpenGeni exposes. The live GET /models\n// catalog must contain every exact slug; older or internal models never broaden\n// this product allowlist.\nexport const CODEX_FALLBACK_MODEL_SLUGS = [\"gpt-5.6-sol\", \"gpt-5.6-terra\", \"gpt-5.6-luna\"] as const;\n\n// Live Codex model-catalog values for every exposed gpt-5.6 subscription slug.\n// Verified 2026-07-18 against Codex CLI 0.144.6's freshly fetched\n// ~/.codex/models_cache.json and the matching openai/codex core derivations:\n// raw context window = 272,000\n// effective input window (95%) = 258,400\n// automatic compaction limit (90%) = 244,800\n// Keep all three explicit: the effective ceiling is a hard input guard while\n// the lower auto-compact limit is the proactive checkpoint trigger.\nexport const CODEX_MODEL_CONTEXT_WINDOW_TOKENS = 272_000;\nexport const CODEX_EFFECTIVE_CONTEXT_WINDOW_PERCENT = 95;\nexport const CODEX_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS = Math.floor(\n (CODEX_MODEL_CONTEXT_WINDOW_TOKENS * CODEX_EFFECTIVE_CONTEXT_WINDOW_PERCENT) / 100,\n);\nexport const CODEX_AUTO_COMPACTION_PERCENT = 90;\nexport const CODEX_MODEL_AUTO_COMPACT_TOKEN_LIMIT = Math.floor(\n (CODEX_MODEL_CONTEXT_WINDOW_TOKENS * CODEX_AUTO_COMPACTION_PERCENT) / 100,\n);\n\n// Sent as the `version` header and inside the User-Agent. Staging-proven on\n// 2026-07-09: 0.142.4 filtered every GPT-5.6 slug out of GET /models, while the\n// official Codex 0.144.0+ releases return all three exact slugs above. Keep\n// this pinned to the latest stable Codex release we have verified end-to-end.\nexport const CODEX_CLIENT_VERSION = \"0.144.6\";\n\nexport const CODEX_REFRESH_WINDOW_MS = 5 * 60 * 1000; // proactive refresh when within 5 min of exp (spec §1.1)\nexport const CODEX_REFRESH_FALLBACK_MS = 8 * 24 * 60 * 60 * 1000; // 8 days when exp is unparseable\n\n// Codex Responses transport deadlines. The OpenAI SDK's own timeout only covers\n// the wait for response headers and erases the underlying timeout class into the\n// bare `Request timed out.` error. Keep the provider-specific budgets here so\n// the transport can enforce and durably report them without enabling the SDK's\n// blind request replay.\nexport const CODEX_RESPONSE_HEADERS_TIMEOUT_MS = 4 * 60_000;\nexport const CODEX_RESPONSE_STREAM_IDLE_TIMEOUT_MS = 5 * 60_000;\nexport const CODEX_RESPONSE_WHOLE_TIMEOUT_MS = 30 * 60_000;\n// Kept as a compatibility-shaped policy field, but automatic replay is disabled\n// until a provider-specific operation receipt can prove non-acceptance or resume\n// the same operation identity. An absent response does not prove that the\n// provider never accepted the request.\nexport const CODEX_RESPONSE_NO_BYTE_RETRIES = 0;\nexport const CODEX_RESPONSE_RETRY_BACKOFF_MS = 1_000;\n// Must exceed the transport-owned whole-response deadline. This SDK guard is a\n// last-resort envelope; the inner transport emits the typed/durable failure.\nexport const CODEX_RESPONSE_SDK_OUTER_TIMEOUT_MS = 35 * 60_000;\n\n// ── Apps / connectors MCP (spec §1.10, §E) ───────────────────────────────────\n// One server-side MCP exposes ALL the user's ChatGPT/Codex connectors\n// (gmail/github/linear/slack/sentry/drive/calendar/…). Streamable HTTP, always.\nexport const CODEX_APPS_MCP_SERVER_ID = \"codex_apps\"; // tools surface as mcp__codex_apps__<tool>\nexport const CODEX_APPS_MCP_SERVER_NAME = \"codex_apps\"; // MCP `name` — MUST equal the id so the SDK namespaces tools as mcp__codex_apps__*\nexport const CODEX_APPS_MCP_URL = \"https://chatgpt.com/backend-api/ps/mcp\"; // live URL (NOT /codex, NOT the legacy /wham/apps)\nexport const CODEX_APPS_STARTUP_TIMEOUT_MS = 30_000; // startup_timeout 30s (spec §1.10) — maps to timeoutMs on this server only\n// Connector scopes that the apps MCP requires. Present ONLY when granted at\n// browser-authorize time; the device-code path CANNOT be confirmed to grant\n// them, so treat connector availability as runtime-discovered (spec §1.10 / §E).\nexport const CODEX_APPS_REQUIRED_SCOPES = [\"api.connectors.read\", \"api.connectors.invoke\"] as const;\n"],"mappings":";AAGO,IAAM,eAAe;AACrB,IAAM,kBAAkB;AACxB,IAAM,kBAAkB,GAAG,YAAY;AACvC,IAAM,kBAAkB,GAAG,YAAY;AACvC,IAAM,gCAAgC,GAAG,YAAY;AACrD,IAAM,4BAA4B,GAAG,YAAY;AAGjD,IAAM,uBAAuB;AAE7B,IAAM,kBAAkB;AAExB,IAAM,mBAAmB;AACzB,IAAM,4BAA4B;AAOlC,IAAM,oBAAoB;AAC1B,IAAM,0BAA0B;AAChC,IAAM,wBAAwB;AAK9B,IAAM,6BAA6B,CAAC,eAAe,iBAAiB,cAAc;AAUlF,IAAM,oCAAoC;AAC1C,IAAM,yCAAyC;AAC/C,IAAM,8CAA8C,KAAK;AAAA,EAC7D,oCAAoC,yCAA0C;AACjF;AACO,IAAM,gCAAgC;AACtC,IAAM,uCAAuC,KAAK;AAAA,EACtD,oCAAoC,gCAAiC;AACxE;AAMO,IAAM,uBAAuB;AAE7B,IAAM,0BAA0B,IAAI,KAAK;AACzC,IAAM,4BAA4B,IAAI,KAAK,KAAK,KAAK;AAOrD,IAAM,oCAAoC,IAAI;AAC9C,IAAM,wCAAwC,IAAI;AAClD,IAAM,kCAAkC,KAAK;AAK7C,IAAM,iCAAiC;AACvC,IAAM,kCAAkC;AAGxC,IAAM,sCAAsC,KAAK;AAKjD,IAAM,2BAA2B;AACjC,IAAM,6BAA6B;AACnC,IAAM,qBAAqB;AAC3B,IAAM,gCAAgC;AAItC,IAAM,6BAA6B,CAAC,uBAAuB,uBAAuB;","names":[]}
@@ -20,10 +20,16 @@ declare const CODEX_MODEL_AUTO_COMPACT_TOKEN_LIMIT: number;
20
20
  declare const CODEX_CLIENT_VERSION = "0.144.6";
21
21
  declare const CODEX_REFRESH_WINDOW_MS: number;
22
22
  declare const CODEX_REFRESH_FALLBACK_MS: number;
23
+ declare const CODEX_RESPONSE_HEADERS_TIMEOUT_MS: number;
24
+ declare const CODEX_RESPONSE_STREAM_IDLE_TIMEOUT_MS: number;
25
+ declare const CODEX_RESPONSE_WHOLE_TIMEOUT_MS: number;
26
+ declare const CODEX_RESPONSE_NO_BYTE_RETRIES = 0;
27
+ declare const CODEX_RESPONSE_RETRY_BACKOFF_MS = 1000;
28
+ declare const CODEX_RESPONSE_SDK_OUTER_TIMEOUT_MS: number;
23
29
  declare const CODEX_APPS_MCP_SERVER_ID = "codex_apps";
24
30
  declare const CODEX_APPS_MCP_SERVER_NAME = "codex_apps";
25
31
  declare const CODEX_APPS_MCP_URL = "https://chatgpt.com/backend-api/ps/mcp";
26
32
  declare const CODEX_APPS_STARTUP_TIMEOUT_MS = 30000;
27
33
  declare const CODEX_APPS_REQUIRED_SCOPES: readonly ["api.connectors.read", "api.connectors.invoke"];
28
34
 
29
- export { CODEX_APPS_MCP_SERVER_ID, CODEX_APPS_MCP_SERVER_NAME, CODEX_APPS_MCP_URL, CODEX_APPS_REQUIRED_SCOPES, CODEX_APPS_STARTUP_TIMEOUT_MS, CODEX_AUTH_BASE, CODEX_AUTO_COMPACTION_PERCENT, CODEX_CLIENT_ID, CODEX_CLIENT_VERSION, CODEX_DEVICE_REDIRECT_URI, CODEX_DEVICE_VERIFICATION_URL, CODEX_EFFECTIVE_CONTEXT_WINDOW_PERCENT, CODEX_FALLBACK_MODEL_SLUGS, CODEX_ID_TOKEN_AUTH_CLAIM, CODEX_ISSUER, CODEX_MODEL_AUTO_COMPACT_TOKEN_LIMIT, CODEX_MODEL_CONTEXT_WINDOW_TOKENS, CODEX_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS, CODEX_MODEL_ID_PREFIX, CODEX_ORIGINATOR, CODEX_PROVIDER_BASE_URL, CODEX_PROVIDER_ID, CODEX_REFRESH_FALLBACK_MS, CODEX_REFRESH_WINDOW_MS, CODEX_RESPONSES_BASE, CODEX_TOKEN_URL, CODEX_WHAM_BASE };
35
+ export { CODEX_APPS_MCP_SERVER_ID, CODEX_APPS_MCP_SERVER_NAME, CODEX_APPS_MCP_URL, CODEX_APPS_REQUIRED_SCOPES, CODEX_APPS_STARTUP_TIMEOUT_MS, CODEX_AUTH_BASE, CODEX_AUTO_COMPACTION_PERCENT, CODEX_CLIENT_ID, CODEX_CLIENT_VERSION, CODEX_DEVICE_REDIRECT_URI, CODEX_DEVICE_VERIFICATION_URL, CODEX_EFFECTIVE_CONTEXT_WINDOW_PERCENT, CODEX_FALLBACK_MODEL_SLUGS, CODEX_ID_TOKEN_AUTH_CLAIM, CODEX_ISSUER, CODEX_MODEL_AUTO_COMPACT_TOKEN_LIMIT, CODEX_MODEL_CONTEXT_WINDOW_TOKENS, CODEX_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS, CODEX_MODEL_ID_PREFIX, CODEX_ORIGINATOR, CODEX_PROVIDER_BASE_URL, CODEX_PROVIDER_ID, CODEX_REFRESH_FALLBACK_MS, CODEX_REFRESH_WINDOW_MS, CODEX_RESPONSES_BASE, CODEX_RESPONSE_HEADERS_TIMEOUT_MS, CODEX_RESPONSE_NO_BYTE_RETRIES, CODEX_RESPONSE_RETRY_BACKOFF_MS, CODEX_RESPONSE_SDK_OUTER_TIMEOUT_MS, CODEX_RESPONSE_STREAM_IDLE_TIMEOUT_MS, CODEX_RESPONSE_WHOLE_TIMEOUT_MS, CODEX_TOKEN_URL, CODEX_WHAM_BASE };
package/dist/constants.js CHANGED
@@ -24,9 +24,15 @@ import {
24
24
  CODEX_REFRESH_FALLBACK_MS,
25
25
  CODEX_REFRESH_WINDOW_MS,
26
26
  CODEX_RESPONSES_BASE,
27
+ CODEX_RESPONSE_HEADERS_TIMEOUT_MS,
28
+ CODEX_RESPONSE_NO_BYTE_RETRIES,
29
+ CODEX_RESPONSE_RETRY_BACKOFF_MS,
30
+ CODEX_RESPONSE_SDK_OUTER_TIMEOUT_MS,
31
+ CODEX_RESPONSE_STREAM_IDLE_TIMEOUT_MS,
32
+ CODEX_RESPONSE_WHOLE_TIMEOUT_MS,
27
33
  CODEX_TOKEN_URL,
28
34
  CODEX_WHAM_BASE
29
- } from "./chunk-AMRVHBCD.js";
35
+ } from "./chunk-YGKQDUY7.js";
30
36
  export {
31
37
  CODEX_APPS_MCP_SERVER_ID,
32
38
  CODEX_APPS_MCP_SERVER_NAME,
@@ -53,6 +59,12 @@ export {
53
59
  CODEX_REFRESH_FALLBACK_MS,
54
60
  CODEX_REFRESH_WINDOW_MS,
55
61
  CODEX_RESPONSES_BASE,
62
+ CODEX_RESPONSE_HEADERS_TIMEOUT_MS,
63
+ CODEX_RESPONSE_NO_BYTE_RETRIES,
64
+ CODEX_RESPONSE_RETRY_BACKOFF_MS,
65
+ CODEX_RESPONSE_SDK_OUTER_TIMEOUT_MS,
66
+ CODEX_RESPONSE_STREAM_IDLE_TIMEOUT_MS,
67
+ CODEX_RESPONSE_WHOLE_TIMEOUT_MS,
56
68
  CODEX_TOKEN_URL,
57
69
  CODEX_WHAM_BASE
58
70
  };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { CODEX_APPS_MCP_SERVER_ID, CODEX_APPS_MCP_SERVER_NAME, CODEX_APPS_MCP_URL, CODEX_APPS_REQUIRED_SCOPES, CODEX_APPS_STARTUP_TIMEOUT_MS, CODEX_AUTH_BASE, CODEX_AUTO_COMPACTION_PERCENT, CODEX_CLIENT_ID, CODEX_CLIENT_VERSION, CODEX_DEVICE_REDIRECT_URI, CODEX_DEVICE_VERIFICATION_URL, CODEX_EFFECTIVE_CONTEXT_WINDOW_PERCENT, CODEX_FALLBACK_MODEL_SLUGS, CODEX_ID_TOKEN_AUTH_CLAIM, CODEX_ISSUER, CODEX_MODEL_AUTO_COMPACT_TOKEN_LIMIT, CODEX_MODEL_CONTEXT_WINDOW_TOKENS, CODEX_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS, CODEX_MODEL_ID_PREFIX, CODEX_ORIGINATOR, CODEX_PROVIDER_BASE_URL, CODEX_PROVIDER_ID, CODEX_REFRESH_FALLBACK_MS, CODEX_REFRESH_WINDOW_MS, CODEX_RESPONSES_BASE, CODEX_TOKEN_URL, CODEX_WHAM_BASE } from './constants.js';
1
+ export { CODEX_APPS_MCP_SERVER_ID, CODEX_APPS_MCP_SERVER_NAME, CODEX_APPS_MCP_URL, CODEX_APPS_REQUIRED_SCOPES, CODEX_APPS_STARTUP_TIMEOUT_MS, CODEX_AUTH_BASE, CODEX_AUTO_COMPACTION_PERCENT, CODEX_CLIENT_ID, CODEX_CLIENT_VERSION, CODEX_DEVICE_REDIRECT_URI, CODEX_DEVICE_VERIFICATION_URL, CODEX_EFFECTIVE_CONTEXT_WINDOW_PERCENT, CODEX_FALLBACK_MODEL_SLUGS, CODEX_ID_TOKEN_AUTH_CLAIM, CODEX_ISSUER, CODEX_MODEL_AUTO_COMPACT_TOKEN_LIMIT, CODEX_MODEL_CONTEXT_WINDOW_TOKENS, CODEX_MODEL_EFFECTIVE_CONTEXT_WINDOW_TOKENS, CODEX_MODEL_ID_PREFIX, CODEX_ORIGINATOR, CODEX_PROVIDER_BASE_URL, CODEX_PROVIDER_ID, CODEX_REFRESH_FALLBACK_MS, CODEX_REFRESH_WINDOW_MS, CODEX_RESPONSES_BASE, CODEX_RESPONSE_HEADERS_TIMEOUT_MS, CODEX_RESPONSE_NO_BYTE_RETRIES, CODEX_RESPONSE_RETRY_BACKOFF_MS, CODEX_RESPONSE_SDK_OUTER_TIMEOUT_MS, CODEX_RESPONSE_STREAM_IDLE_TIMEOUT_MS, CODEX_RESPONSE_WHOLE_TIMEOUT_MS, CODEX_TOKEN_URL, CODEX_WHAM_BASE } from './constants.js';
2
2
  import { AsyncLocalStorage } from 'node:async_hooks';
3
3
 
4
4
  /**
@@ -65,7 +65,7 @@ type CodexRefreshTokens = {
65
65
  refreshToken?: string | undefined;
66
66
  };
67
67
  /** POST {issuer}/oauth/token JSON {client_id, grant_type:"refresh_token", refresh_token}. manager.rs:1336-1340 */
68
- declare function refreshCodexToken(refreshToken: string, fetchImpl?: CodexFetch): Promise<CodexRefreshTokens>;
68
+ declare function refreshCodexToken(refreshToken: string, fetchImpl?: CodexFetch, timeoutMs?: number): Promise<CodexRefreshTokens>;
69
69
  /** Decode a JWT payload (base64url, no signature check). */
70
70
  declare function decodeJwtPayload(jwt: string): Record<string, unknown> | null;
71
71
  /** access-token `exp` claim -> Date | null. token_data.rs:101-105 */
@@ -87,6 +87,40 @@ declare function normalizeCodexRequestBody(body: Record<string, unknown>, resolv
87
87
  */
88
88
  declare function buildModelResolver(liveSlugs: readonly string[], fallbackSlug: string): (slug: string) => string;
89
89
 
90
+ declare const CODEX_RATE_LIMIT_RESET_OUTCOMES: readonly ["reset", "nothingToReset", "noCredit", "alreadyRedeemed"];
91
+ type CodexRateLimitResetOutcome = (typeof CODEX_RATE_LIMIT_RESET_OUTCOMES)[number];
92
+ type CodexRateLimitResetType = "codexRateLimits" | "unknown";
93
+ type CodexRateLimitResetCreditStatus = "available" | "redeeming" | "redeemed" | "unknown";
94
+ type CodexRateLimitResetCredit = {
95
+ id: string;
96
+ resetType: CodexRateLimitResetType;
97
+ status: CodexRateLimitResetCreditStatus;
98
+ /** Unix seconds, matching account/rateLimits/read in Codex v0.144.6. */
99
+ grantedAt: number;
100
+ /** Unix seconds, or null when the provider says the credit does not expire. */
101
+ expiresAt: number | null;
102
+ title: string | null;
103
+ description: string | null;
104
+ };
105
+ type CodexRateLimitResetCreditsDetails = {
106
+ availableCount: number;
107
+ credits: CodexRateLimitResetCredit[];
108
+ };
109
+ type CodexRateLimitResetCreditsSummary = {
110
+ availableCount: number;
111
+ /** null means the provider supplied an authoritative count but no detail rows. */
112
+ credits: null;
113
+ };
114
+ type CodexRateLimitResetConsumeResponse = {
115
+ outcome: CodexRateLimitResetOutcome;
116
+ };
117
+ /** Parse the exact detailed-credit backend response. Unknown rows stay view-only. */
118
+ declare function parseCodexRateLimitResetCreditsDetails(payload: unknown): CodexRateLimitResetCreditsDetails | null;
119
+ /** Parse the count-only summary carried by GET /wham/usage. */
120
+ declare function parseCodexRateLimitResetCreditsSummary(payload: unknown): CodexRateLimitResetCreditsSummary | null;
121
+ /** Parse one of the exact four v0.144.6 consume outcomes. Unknowns fail closed. */
122
+ declare function parseCodexRateLimitResetConsumeResponse(payload: unknown): CodexRateLimitResetConsumeResponse | null;
123
+
90
124
  /** The 5-hour (primary) window's `limit_window_seconds`. */
91
125
  declare const CODEX_FIVE_HOUR_WINDOW_SECONDS = 18000;
92
126
  /** The weekly (secondary) window's `limit_window_seconds`. */
@@ -117,6 +151,11 @@ type CodexUsagePayload = {
117
151
  weekly: CodexUsageWindow | null;
118
152
  limitReached: boolean;
119
153
  fetchedAt: string;
154
+ /**
155
+ * Authoritative count-only reset-credit summary from the usage response.
156
+ * Detail rows are fetched separately and are never synthesized from this.
157
+ */
158
+ rateLimitResetCredits: CodexRateLimitResetCreditsSummary | null;
120
159
  /** Present only on a refresh/auth failure path; carries the precise reason. */
121
160
  reason?: "needs_relogin" | undefined;
122
161
  additionalLimits?: CodexAdditionalLimit[] | undefined;
@@ -149,17 +188,53 @@ type CodexAuthHeaders = {
149
188
  isFedramp: boolean;
150
189
  clientVersion: string;
151
190
  };
191
+ type ResetCreditFetchFailureReason = "http_error" | "invalid_response" | "network_error" | "timeout";
152
192
  /** GET /codex/models — login-check + live catalog. A 200 means the token is accepted. spec §1.4/§F */
153
- declare function fetchCodexModels(a: CodexAuthHeaders, fetchImpl?: CodexFetch): Promise<{
193
+ declare function fetchCodexModels(a: CodexAuthHeaders, fetchImpl?: CodexFetch, timeoutMs?: number): Promise<{
154
194
  ok: boolean;
155
195
  status: number;
156
196
  slugs: string[];
157
197
  }>;
158
198
  /** GET /wham/usage — authoritative limits. NB the WHAM base is /backend-api, NOT /codex (spec §1.8a). */
159
- declare function fetchCodexUsage(a: CodexAuthHeaders, fetchImpl?: CodexFetch): Promise<{
199
+ declare function fetchCodexUsage(a: CodexAuthHeaders, fetchImpl?: CodexFetch, timeoutMs?: number): Promise<{
160
200
  status: number;
161
201
  payload: unknown;
162
202
  }>;
203
+ /**
204
+ * GET /wham/rate-limit-reset-credits — detailed earned reset credits.
205
+ *
206
+ * A non-2xx or malformed body returns an explicit non-ok result. The caller may
207
+ * fall back to the count-only summary embedded in /wham/usage, but must never
208
+ * invent actionable rows from that count.
209
+ */
210
+ declare function fetchCodexRateLimitResetCredits(a: CodexAuthHeaders, fetchImpl?: CodexFetch, timeoutMs?: number): Promise<{
211
+ ok: true;
212
+ status: number;
213
+ details: CodexRateLimitResetCreditsDetails;
214
+ } | {
215
+ ok: false;
216
+ status: number;
217
+ reason: ResetCreditFetchFailureReason;
218
+ }>;
219
+ /**
220
+ * POST /wham/rate-limit-reset-credits/consume with the exact v0.144.6 body.
221
+ * `idempotencyKey` identifies one logical human redemption and MUST be reused
222
+ * by the server on retries. Supplying `creditId` is preferred; omission leaves
223
+ * provider selection in control and is therefore not used by OpenGeni's
224
+ * human-only flow.
225
+ */
226
+ declare function consumeCodexRateLimitResetCredit(a: CodexAuthHeaders, input: {
227
+ idempotencyKey: string;
228
+ creditId?: string | undefined;
229
+ }, fetchImpl?: CodexFetch, timeoutMs?: number): Promise<{
230
+ ok: true;
231
+ status: number;
232
+ result: CodexRateLimitResetConsumeResponse;
233
+ } | {
234
+ ok: false;
235
+ status: number;
236
+ reason: ResetCreditFetchFailureReason | "invalid_request";
237
+ }>;
163
238
 
164
239
  type CodexTokenSnapshot = {
165
240
  accessToken: string;
@@ -182,6 +257,35 @@ type CodexUsageHeaderSnapshot = {
182
257
  secondaryResetAt: Date;
183
258
  checkedAt: Date;
184
259
  };
260
+ type CodexResponseTimeoutClass = "connect" | "headers" | "idle_stream" | "whole_request";
261
+ type CodexResponseTimeoutPolicy = {
262
+ /** Maximum wait for response headers, including DNS/TCP/TLS establishment. */
263
+ headersTimeoutMs: number;
264
+ /** Maximum silence between response-body chunks after headers arrive. */
265
+ streamIdleTimeoutMs: number;
266
+ /** Maximum wall time for one logical Responses request. */
267
+ wholeRequestTimeoutMs: number;
268
+ /**
269
+ * Reserved compatibility field. It is currently normalized to zero because
270
+ * an absent response does not prove that the provider never accepted a
271
+ * request, so automatic replay is not safe without an operation receipt.
272
+ */
273
+ noByteRetries: number;
274
+ retryBackoffMs: number;
275
+ };
276
+ type CodexModelRequestEvent = {
277
+ requestId: string;
278
+ transportAttempt: number;
279
+ phase: "started" | "headers" | "first_byte" | "completed" | "failed" | "timed_out";
280
+ model?: string;
281
+ durationMs: number;
282
+ responseObserved: boolean;
283
+ timeoutPolicy: CodexResponseTimeoutPolicy;
284
+ timeoutClass?: CodexResponseTimeoutClass;
285
+ providerRequestId?: string;
286
+ status?: number;
287
+ willRetry?: boolean;
288
+ };
185
289
  type CodexRequestContext = {
186
290
  clientVersion: string;
187
291
  /**
@@ -210,9 +314,43 @@ type CodexRequestContext = {
210
314
  * P2 usage cache once per turn in its `finally` — packages/codex stays db-free.
211
315
  */
212
316
  onUsageHeaders?: (snapshot: CodexUsageHeaderSnapshot) => void;
317
+ /** Optional per-run override, primarily for deterministic transport tests. */
318
+ responseTimeoutPolicy?: Partial<CodexResponseTimeoutPolicy>;
319
+ /** Worker-owned durable audit sink; payloads never contain request bodies or auth. */
320
+ onModelRequestEvent?: (event: CodexModelRequestEvent) => Promise<void> | void;
321
+ /** Stable request identity supplied by the owning durable execution. */
322
+ nextRequestId?: () => string;
213
323
  };
214
324
  declare const codexRequestStorage: AsyncLocalStorage<CodexRequestContext>;
215
325
 
326
+ declare const CODEX_RESPONSE_TIMEOUT_ERROR_TYPE = "opengeni_codex_response_timeout";
327
+ declare const DEFAULT_CODEX_RESPONSE_TIMEOUT_POLICY: CodexResponseTimeoutPolicy;
328
+ declare function resolveCodexResponseTimeoutPolicy(override: Partial<CodexResponseTimeoutPolicy> | undefined): CodexResponseTimeoutPolicy;
329
+ declare class CodexResponseTimeoutError extends Error {
330
+ readonly timeoutClass: CodexResponseTimeoutClass;
331
+ readonly requestId: string;
332
+ readonly responseObserved: boolean;
333
+ readonly code = "opengeni_codex_response_timeout";
334
+ readonly type = "opengeni_codex_response_timeout";
335
+ constructor(timeoutClass: CodexResponseTimeoutClass, requestId: string, responseObserved: boolean, message?: string);
336
+ }
337
+ type CodexResponseTimeoutInfo = {
338
+ timeoutClass: CodexResponseTimeoutClass;
339
+ requestId: string | null;
340
+ responseObserved: boolean;
341
+ message: string;
342
+ };
343
+ /**
344
+ * Recover structured transport timeouts through SDK wrapping. The optional
345
+ * legacy match is deliberately opt-in: `Request timed out.` alone has no
346
+ * provider provenance and the worker enables it only for a confirmed Codex
347
+ * subscription turn.
348
+ */
349
+ declare function classifyCodexResponseTimeoutError(error: unknown, options?: {
350
+ allowLegacyRequestTimeout?: boolean;
351
+ }): CodexResponseTimeoutInfo | null;
352
+ declare function isPreHeadersTimeoutError(error: unknown): CodexResponseTimeoutClass | null;
353
+
216
354
  type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
217
355
  /**
218
356
  * Internal provenance marker copied onto buffered non-OK Codex responses.
@@ -374,4 +512,4 @@ declare function truncateMiddleWithTokenBudget(value: string, maxTokens: number)
374
512
  declare function boundModelToolOutputItem<T extends ModelHistoryItem>(item: T, policyTokens?: number): T;
375
513
  declare function boundModelToolOutputItems<T extends ModelHistoryItem>(items: readonly T[], policyTokens?: number): T[];
376
514
 
377
- export { CODEX_FIVE_HOUR_WINDOW_SECONDS, CODEX_MODEL_TOOL_OUTPUT_TRUNCATION_TOKENS, CODEX_TOOL_OUTPUT_SERIALIZATION_ALLOWANCE, CODEX_TRANSPORT_ERROR_HEADER, CODEX_USAGE_LIMIT_ERROR_TYPE, CODEX_WEEKLY_WINDOW_SECONDS, type CodexAdditionalLimit, type CodexAuthHeaders, CodexDeviceError, type CodexDeviceStart, type CodexFetch, type CodexPollResult, type CodexRefreshTokens, CodexRefreshTransient, CodexReloginRequired, type CodexRequestContext, type CodexSseFailureProjection, CodexStreamingTerminalError, type CodexTokenSnapshot, type CodexTokens, type CodexUsageHeaderSnapshot, type CodexUsageLimitInfo, type CodexUsagePayload, type CodexUsageStatus, type CodexUsageWindow, DEFAULT_MODEL_TOOL_OUTPUT_TRUNCATION_TOKENS, type FetchLike, MODEL_TOOL_OUTPUT_OPAQUE_PAYLOAD_MAX_BYTES, MODEL_TOOL_OUTPUT_OVERSIZED_IMAGE_CARD_DATA_URL, type ModelHistoryItem, ToolNameMapper, accessTokenExpiry, approximateTokenCount, boundModelToolOutputItem, boundModelToolOutputItems, buildCodexUsageWindowFromCache, buildModelResolver, classifyCodexUsageLimitError, codexAppsSanitizingFetch, codexRequestStorage, codexSubscriptionFetch, decodeJwtPayload, exchangeDeviceCode, fetchCodexModels, fetchCodexUsage, isCodexBilledModel, isCodexTransportError, modelToolOutputSerializationBudgetTokens, normalizeCodexRequestBody, normalizeCodexUsage, parseCodexUsageHeaders, parseIdToken, pollDeviceCode, refreshCodexToken, remapToolCallRequestBody, sanitizeMcpJsonBody, sanitizeMcpSseBody, startDeviceCode, truncateMiddleWithTokenBudget };
515
+ export { CODEX_FIVE_HOUR_WINDOW_SECONDS, CODEX_MODEL_TOOL_OUTPUT_TRUNCATION_TOKENS, CODEX_RATE_LIMIT_RESET_OUTCOMES, CODEX_RESPONSE_TIMEOUT_ERROR_TYPE, CODEX_TOOL_OUTPUT_SERIALIZATION_ALLOWANCE, CODEX_TRANSPORT_ERROR_HEADER, CODEX_USAGE_LIMIT_ERROR_TYPE, CODEX_WEEKLY_WINDOW_SECONDS, type CodexAdditionalLimit, type CodexAuthHeaders, CodexDeviceError, type CodexDeviceStart, type CodexFetch, type CodexModelRequestEvent, type CodexPollResult, type CodexRateLimitResetConsumeResponse, type CodexRateLimitResetCredit, type CodexRateLimitResetCreditStatus, type CodexRateLimitResetCreditsDetails, type CodexRateLimitResetCreditsSummary, type CodexRateLimitResetOutcome, type CodexRateLimitResetType, type CodexRefreshTokens, CodexRefreshTransient, CodexReloginRequired, type CodexRequestContext, type CodexResponseTimeoutClass, CodexResponseTimeoutError, type CodexResponseTimeoutInfo, type CodexResponseTimeoutPolicy, type CodexSseFailureProjection, CodexStreamingTerminalError, type CodexTokenSnapshot, type CodexTokens, type CodexUsageHeaderSnapshot, type CodexUsageLimitInfo, type CodexUsagePayload, type CodexUsageStatus, type CodexUsageWindow, DEFAULT_CODEX_RESPONSE_TIMEOUT_POLICY, DEFAULT_MODEL_TOOL_OUTPUT_TRUNCATION_TOKENS, type FetchLike, MODEL_TOOL_OUTPUT_OPAQUE_PAYLOAD_MAX_BYTES, MODEL_TOOL_OUTPUT_OVERSIZED_IMAGE_CARD_DATA_URL, type ModelHistoryItem, type ResetCreditFetchFailureReason, ToolNameMapper, accessTokenExpiry, approximateTokenCount, boundModelToolOutputItem, boundModelToolOutputItems, buildCodexUsageWindowFromCache, buildModelResolver, classifyCodexResponseTimeoutError, classifyCodexUsageLimitError, codexAppsSanitizingFetch, codexRequestStorage, codexSubscriptionFetch, consumeCodexRateLimitResetCredit, decodeJwtPayload, exchangeDeviceCode, fetchCodexModels, fetchCodexRateLimitResetCredits, fetchCodexUsage, isCodexBilledModel, isCodexTransportError, isPreHeadersTimeoutError, modelToolOutputSerializationBudgetTokens, normalizeCodexRequestBody, normalizeCodexUsage, parseCodexRateLimitResetConsumeResponse, parseCodexRateLimitResetCreditsDetails, parseCodexRateLimitResetCreditsSummary, parseCodexUsageHeaders, parseIdToken, pollDeviceCode, refreshCodexToken, remapToolCallRequestBody, resolveCodexResponseTimeoutPolicy, sanitizeMcpJsonBody, sanitizeMcpSseBody, startDeviceCode, truncateMiddleWithTokenBudget };