@opengeni/codex 0.2.20 → 0.2.21-canary.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.
- package/dist/{chunk-UNB34NLA.js → chunk-OJCCJBUL.js} +8 -3
- package/dist/chunk-OJCCJBUL.js.map +1 -0
- package/dist/constants.d.ts +2 -2
- package/dist/constants.js +1 -1
- package/dist/images.d.ts +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/request-context.d.ts +11 -0
- package/package.json +2 -2
- package/src/constants.ts +16 -11
- package/src/fetch.ts +1 -0
- package/src/images.ts +5 -1
- package/src/request-context.ts +12 -0
- package/dist/chunk-UNB34NLA.js.map +0 -1
|
@@ -53,6 +53,12 @@ export type CodexRequestOpaqueArtifacts = {
|
|
|
53
53
|
requestId: string;
|
|
54
54
|
fingerprints: readonly string[];
|
|
55
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* Durable execution fence invoked immediately before a provider request is
|
|
58
|
+
* dispatched. Errors are intentionally not classified here: the owning worker
|
|
59
|
+
* must receive typed lease-loss failures unchanged.
|
|
60
|
+
*/
|
|
61
|
+
export type CodexBeforeProviderDispatch = () => Promise<void> | void;
|
|
56
62
|
export type CodexRequestPreparationPhase = "transport_entry" | "credential_ready" | "wire_request_ready";
|
|
57
63
|
export type CodexRequestContext = {
|
|
58
64
|
clientVersion: string;
|
|
@@ -96,6 +102,11 @@ export type CodexRequestContext = {
|
|
|
96
102
|
onModelRequestEvent?: (event: CodexModelRequestEvent) => Promise<void> | void;
|
|
97
103
|
/** Exact opaque artifacts on the normalized wire request, never their ciphertext. */
|
|
98
104
|
onRequestOpaqueArtifacts?: (artifacts: CodexRequestOpaqueArtifacts) => void;
|
|
105
|
+
/**
|
|
106
|
+
* Durable execution fence. Runs after request preparation and audit, and
|
|
107
|
+
* immediately before each actual provider dispatch, including auth retries.
|
|
108
|
+
*/
|
|
109
|
+
beforeProviderDispatch?: CodexBeforeProviderDispatch;
|
|
99
110
|
/** Stable request identity supplied by the owning durable execution. */
|
|
100
111
|
nextRequestId?: () => string;
|
|
101
112
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeni/codex",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.21-canary.1",
|
|
4
4
|
"description": "ChatGPT/Codex subscription auth + transport: device-code login, token refresh, and the Responses-backend fetch. Pure HTTP + transforms; no database dependency.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"prepublishOnly": "bash ../../scripts/prepublish-guard"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@opengeni/network": "^0.
|
|
44
|
+
"@opengeni/network": "^0.3.0-canary.1",
|
|
45
45
|
"zod": "^4.2.1"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
package/src/constants.ts
CHANGED
|
@@ -25,14 +25,19 @@ export const CODEX_PROVIDER_ID = "codex-subscription";
|
|
|
25
25
|
export const CODEX_PROVIDER_BASE_URL = "https://chatgpt.com/backend-api";
|
|
26
26
|
export const CODEX_MODEL_ID_PREFIX = "codex/";
|
|
27
27
|
|
|
28
|
-
// The only Codex subscription models OpenGeni exposes.
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
|
|
28
|
+
// The only Codex subscription models OpenGeni exposes. Astra is deliberately
|
|
29
|
+
// pre-advertised before an account receives provider rollout access so the
|
|
30
|
+
// picker becomes runnable without another OpenGeni release once access arrives.
|
|
31
|
+
// Older or internal live models never broaden this product allowlist.
|
|
32
|
+
export const CODEX_FALLBACK_MODEL_SLUGS = [
|
|
33
|
+
"gpt-5.6-sol",
|
|
34
|
+
"gpt-5.6-terra",
|
|
35
|
+
"gpt-5.6-luna",
|
|
36
|
+
"gpt-6-astra",
|
|
37
|
+
] as const;
|
|
32
38
|
|
|
33
|
-
// Live Codex model-catalog values for every exposed
|
|
34
|
-
// Verified 2026-
|
|
35
|
-
// ~/.codex/models_cache.json and the matching openai/codex core derivations:
|
|
39
|
+
// Live Codex model-catalog values for every exposed subscription slug.
|
|
40
|
+
// Verified 2026-09-04 against Codex CLI 0.153.2's bundled model catalog:
|
|
36
41
|
// raw context window = 272,000
|
|
37
42
|
// effective input window (95%) = 258,400
|
|
38
43
|
// automatic compaction limit (90%) = 244,800
|
|
@@ -49,10 +54,10 @@ export const CODEX_MODEL_AUTO_COMPACT_TOKEN_LIMIT = Math.floor(
|
|
|
49
54
|
);
|
|
50
55
|
|
|
51
56
|
// Sent as the `version` header and inside the User-Agent. Staging-proven on
|
|
52
|
-
// 2026-07-09: 0.142.4 filtered every GPT-5.6 slug out of GET /models
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
export const CODEX_CLIENT_VERSION = "0.
|
|
57
|
+
// 2026-07-09: 0.142.4 filtered every GPT-5.6 slug out of GET /models. Keep this
|
|
58
|
+
// pinned to the latest stable Codex release whose bundled catalog and transport
|
|
59
|
+
// contract have been reviewed here.
|
|
60
|
+
export const CODEX_CLIENT_VERSION = "0.153.2";
|
|
56
61
|
|
|
57
62
|
// Public OpenGeni selector for native ChatGPT/Codex subscription WebRTC. This
|
|
58
63
|
// remains stable for persisted sessions; the provider's remotely configured
|
package/src/fetch.ts
CHANGED
|
@@ -752,6 +752,7 @@ export function codexSubscriptionFetch(base: FetchLike = globalThis.fetch): Fetc
|
|
|
752
752
|
deferTransportTerminal: !callerWantsStream,
|
|
753
753
|
};
|
|
754
754
|
try {
|
|
755
|
+
await ctx.beforeProviderDispatch?.();
|
|
755
756
|
res = await fetchBeforeHeaders(base, rewritten, nextInit, audit);
|
|
756
757
|
const upstreamRequestId = providerRequestId(res.headers);
|
|
757
758
|
await emitRequestEvent(audit, {
|
package/src/images.ts
CHANGED
|
@@ -61,7 +61,10 @@ export async function generateCodexSubscriptionImage(input: {
|
|
|
61
61
|
prompt: string;
|
|
62
62
|
references?: readonly CodexImageReferenceInput[];
|
|
63
63
|
turnId: string;
|
|
64
|
-
context: Pick<
|
|
64
|
+
context: Pick<
|
|
65
|
+
CodexRequestContext,
|
|
66
|
+
"clientVersion" | "getToken" | "refresh" | "beforeProviderDispatch"
|
|
67
|
+
>;
|
|
65
68
|
abortSignal?: AbortSignal;
|
|
66
69
|
fetch?: FetchLike;
|
|
67
70
|
/** Internal test/host override; one absolute budget covers auth retry and body streaming. */
|
|
@@ -91,6 +94,7 @@ export async function generateCodexSubscriptionImage(input: {
|
|
|
91
94
|
: deadline.signal;
|
|
92
95
|
const request = async (auth: CodexTokenSnapshot): Promise<Response> => {
|
|
93
96
|
const headers = codexImageHeaders(auth, input.context.clientVersion, input.turnId);
|
|
97
|
+
await input.context.beforeProviderDispatch?.();
|
|
94
98
|
return await fetchImpl(
|
|
95
99
|
`${CODEX_RESPONSES_BASE}/${references.length > 0 ? "images/edits" : "images/generations"}`,
|
|
96
100
|
{
|
package/src/request-context.ts
CHANGED
|
@@ -67,6 +67,13 @@ export type CodexRequestOpaqueArtifacts = {
|
|
|
67
67
|
fingerprints: readonly string[];
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Durable execution fence invoked immediately before a provider request is
|
|
72
|
+
* dispatched. Errors are intentionally not classified here: the owning worker
|
|
73
|
+
* must receive typed lease-loss failures unchanged.
|
|
74
|
+
*/
|
|
75
|
+
export type CodexBeforeProviderDispatch = () => Promise<void> | void;
|
|
76
|
+
|
|
70
77
|
export type CodexRequestPreparationPhase =
|
|
71
78
|
| "transport_entry"
|
|
72
79
|
| "credential_ready"
|
|
@@ -114,6 +121,11 @@ export type CodexRequestContext = {
|
|
|
114
121
|
onModelRequestEvent?: (event: CodexModelRequestEvent) => Promise<void> | void;
|
|
115
122
|
/** Exact opaque artifacts on the normalized wire request, never their ciphertext. */
|
|
116
123
|
onRequestOpaqueArtifacts?: (artifacts: CodexRequestOpaqueArtifacts) => void;
|
|
124
|
+
/**
|
|
125
|
+
* Durable execution fence. Runs after request preparation and audit, and
|
|
126
|
+
* immediately before each actual provider dispatch, including auth retries.
|
|
127
|
+
*/
|
|
128
|
+
beforeProviderDispatch?: CodexBeforeProviderDispatch;
|
|
117
129
|
/** Stable request identity supplied by the owning durable execution. */
|
|
118
130
|
nextRequestId?: () => string;
|
|
119
131
|
/**
|
|
@@ -1 +0,0 @@
|
|
|
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.145.0\";\n\n// Public OpenGeni selector for native ChatGPT/Codex subscription WebRTC. This\n// remains stable for persisted sessions; the provider's remotely configured\n// model is resolved separately before call creation.\nexport const CODEX_REALTIME_MODEL = \"gpt-live-1-boulder-alpha\";\nexport const CODEX_REALTIME_VERSION = \"v3\";\nexport const CODEX_REALTIME_DEFAULT_VOICE = \"cove\";\nexport const CODEX_REALTIME_CALL_TIMEOUT_MS = 15_000;\nexport const CODEX_REALTIME_CONFIG_TIMEOUT_MS = 5_000;\nexport const CODEX_REALTIME_CONFIG_ID = \"3566525122\";\n// Verified live on 2026-08-23. Used only when the authenticated remote config\n// is transiently unavailable or malformed; it is not the persisted model id.\nexport const CODEX_REALTIME_PROVIDER_MODEL_FALLBACK = \"gpt-live-1-codex\";\nexport const CODEX_REALTIME_PROVIDER_ARCHITECTURE_FALLBACK = \"avas\";\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;AAK7B,IAAM,uBAAuB;AAC7B,IAAM,yBAAyB;AAC/B,IAAM,+BAA+B;AACrC,IAAM,iCAAiC;AACvC,IAAM,mCAAmC;AACzC,IAAM,2BAA2B;AAGjC,IAAM,yCAAyC;AAC/C,IAAM,gDAAgD;AAEtD,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":[]}
|