@byokkit/cmd-provider-openai 0.1.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.
- package/README.md +94 -0
- package/dist/chunk-34MJFIMS.js +90 -0
- package/dist/chunk-34MJFIMS.js.map +1 -0
- package/dist/chunk-J2XEWLRM.js +127 -0
- package/dist/chunk-J2XEWLRM.js.map +1 -0
- package/dist/chunk-NSTLHK7M.js +34 -0
- package/dist/chunk-NSTLHK7M.js.map +1 -0
- package/dist/codex.d.ts +34 -0
- package/dist/codex.js +21 -0
- package/dist/codex.js.map +1 -0
- package/dist/constants-BPm3xKmw.d.ts +20 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +488 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +114 -0
- package/dist/models.js +13 -0
- package/dist/models.js.map +1 -0
- package/dist/server/index.d.ts +28 -0
- package/dist/server/index.js +25 -0
- package/dist/server/index.js.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @byokkit/cmd-provider-openai
|
|
2
|
+
|
|
3
|
+
OpenAI (Codex / ChatGPT) authentication for Command Code, packaged as an external
|
|
4
|
+
[`ProviderModule`](../../plans/providers.plan.md). It ports Command Code's real OpenAI/Codex
|
|
5
|
+
**loopback OAuth** (the flow in `packages/command/src/auth/codex.ts`) onto the harness's reusable
|
|
6
|
+
provider/auth primitives — no core or harness changes required to use it.
|
|
7
|
+
|
|
8
|
+
> The "OpenAI" provider here **is** the Codex / ChatGPT OAuth. It is named for the provider
|
|
9
|
+
> (`openai`), but on the wire it speaks Command Code's `codex` auth lane (see parity note below).
|
|
10
|
+
|
|
11
|
+
## What it does
|
|
12
|
+
|
|
13
|
+
- Declares one provider module: `id: 'openai'`, `displayName: 'OpenAI'`.
|
|
14
|
+
- Transport is the server-routed **gateway** (`{kind: 'gateway', route: '/alpha/generate'}`) — the
|
|
15
|
+
backend picks the real model, so the module declares no model specs and only owns auth.
|
|
16
|
+
- One `oauth` login method using an **autonomous loopback** (RFC 8252) PKCE flow:
|
|
17
|
+
1. `authorize()` starts a local callback server on `127.0.0.1:1455`, builds the OpenAI authorize
|
|
18
|
+
URL (PKCE `S256`, CSRF `state`, and the Codex-specific params
|
|
19
|
+
`id_token_add_organizations` / `codex_cli_simplified_flow` / `originator=codex_cli_rs`), and
|
|
20
|
+
returns a `pending` result with the URL + a `callback()`.
|
|
21
|
+
2. `callback()` awaits the browser redirect (5-minute timeout), validates `state`, then exchanges
|
|
22
|
+
the code for tokens (form-encoded) at `https://auth.openai.com/oauth/token`.
|
|
23
|
+
- A `refresh` method + an `auth.loader` that turns a stored credential into request headers,
|
|
24
|
+
refreshing on the 5-minute expiry skew (single-flight; a failed refresh keeps the existing token).
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import openaiProvider, {createOpenAIProvider} from '@byokkit/cmd-provider-openai';
|
|
30
|
+
import {createProviderRegistry} from '@commandcode/harness';
|
|
31
|
+
|
|
32
|
+
// Default export: a ready-to-register module (global fetch + clock).
|
|
33
|
+
const registry = createProviderRegistry({
|
|
34
|
+
modules: [openaiProvider /* …other modules */],
|
|
35
|
+
transport,
|
|
36
|
+
runtime,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Or build one with injected I/O (tests / custom fetch):
|
|
40
|
+
const custom = createOpenAIProvider({fetchImpl, now: () => Date.now()});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Login is driven through the registry (`registry.authMethods({providerId: 'openai'})` →
|
|
44
|
+
`registry.login({providerId: 'openai', methodId: 'oauth', onPending})`). `onPending` receives the
|
|
45
|
+
`url` + `instructions`; for this autonomous loopback flow it just opens the URL — `callback()`
|
|
46
|
+
resolves on its own once OpenAI redirects back.
|
|
47
|
+
|
|
48
|
+
## Parity with Command Code (`auth/codex.ts`)
|
|
49
|
+
|
|
50
|
+
These values are a faithful port and **must not drift**:
|
|
51
|
+
|
|
52
|
+
| Aspect | Value |
|
|
53
|
+
| --- | --- |
|
|
54
|
+
| OAuth client id | `app_EMoamEEZ73f0CkXaXp7hrann` |
|
|
55
|
+
| Issuer / endpoints | `https://auth.openai.com` → `/oauth/authorize`, `/oauth/token` |
|
|
56
|
+
| Scopes | `openid profile email offline_access` |
|
|
57
|
+
| Redirect URI | `http://localhost:1455/auth/callback` (fixed port; server binds `127.0.0.1`) |
|
|
58
|
+
| Token encoding | form-urlencoded (`application/x-www-form-urlencoded`) |
|
|
59
|
+
| Gateway auth header (token) | `x-oauth-token: Bearer <access>` |
|
|
60
|
+
| **Gateway auth header (provider)** | **`x-oauth-provider: codex`** |
|
|
61
|
+
|
|
62
|
+
> **The provider header value is `codex`, not `openai`.** Command Code's `getOAuthCredentials`
|
|
63
|
+
> sends `oauthProvider = PROVIDER.CODEX = 'codex'` for this flow, and the `/alpha/generate` gateway
|
|
64
|
+
> recognizes OpenAI/Codex traffic by that value. The module's `id` (`openai`) is only the local
|
|
65
|
+
> credential-store / registry key.
|
|
66
|
+
|
|
67
|
+
### Loopback decisions
|
|
68
|
+
|
|
69
|
+
- **Fixed port `1455`, not ephemeral.** OpenAI only accepts the pre-registered native redirect URI
|
|
70
|
+
for the Codex client, so the harness loopback server is pinned to port `1455` / path
|
|
71
|
+
`/auth/callback`. (The harness `createLoopbackCallbackServer` supports overriding its default
|
|
72
|
+
ephemeral port — we override it here.)
|
|
73
|
+
- **Binds `127.0.0.1`, advertises `localhost`.** Exactly like `codex.ts`: the `redirect_uri` host is
|
|
74
|
+
`localhost` (what OpenAI registered) while the server listens on `127.0.0.1`.
|
|
75
|
+
- **CSRF / state check is the module's job.** The harness loopback surfaces the returned `state`; we
|
|
76
|
+
compare it to the value we sent and reject on mismatch.
|
|
77
|
+
|
|
78
|
+
### Minor, intentional divergence
|
|
79
|
+
|
|
80
|
+
- The refresh-token grant omits the optional `scope` parameter that `codex.ts` sends. Per OAuth 2.0,
|
|
81
|
+
a refresh without `scope` returns tokens with the originally granted scopes, so this is functionally
|
|
82
|
+
equivalent; we use the harness's `refreshAccessToken` helper for it.
|
|
83
|
+
- Codex's `chatgpt_account_id` (parsed from the id_token JWT) is not stored. The harness `Credential`
|
|
84
|
+
has no field for it and **it is never sent to the gateway** (`commandAuthHeaders` only emits the
|
|
85
|
+
token + provider headers), so it is irrelevant to wire parity.
|
|
86
|
+
|
|
87
|
+
## Development
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
pnpm install
|
|
91
|
+
pnpm typecheck
|
|
92
|
+
pnpm test # vitest — real loopback over localhost, injected fetch/clock, no external network
|
|
93
|
+
pnpm build
|
|
94
|
+
```
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
3
|
+
var ISSUER = "https://auth.openai.com";
|
|
4
|
+
var AUTHORIZE_ENDPOINT = `${ISSUER}/oauth/authorize`;
|
|
5
|
+
var TOKEN_ENDPOINT = `${ISSUER}/oauth/token`;
|
|
6
|
+
var SCOPE = "openid profile email offline_access";
|
|
7
|
+
var OAUTH_PORT = 1455;
|
|
8
|
+
var CALLBACK_PATH = "/auth/callback";
|
|
9
|
+
var ADVERTISED_HOST = "localhost";
|
|
10
|
+
var BIND_HOST = "127.0.0.1";
|
|
11
|
+
var REDIRECT_URI = `http://${ADVERTISED_HOST}:${OAUTH_PORT}${CALLBACK_PATH}`;
|
|
12
|
+
var CALLBACK_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
13
|
+
var EXPIRY_SKEW_MS = 5 * 60 * 1e3;
|
|
14
|
+
var HEADER_OAUTH_TOKEN = "x-oauth-token";
|
|
15
|
+
var HEADER_OAUTH_PROVIDER = "x-oauth-provider";
|
|
16
|
+
var OAUTH_PROVIDER_VALUE = "codex";
|
|
17
|
+
var PROVIDER_ID = "openai";
|
|
18
|
+
var DISPLAY_NAME = "OpenAI";
|
|
19
|
+
var GATEWAY_ROUTE = "/alpha/generate";
|
|
20
|
+
|
|
21
|
+
// src/codex.ts
|
|
22
|
+
var CODEX_BASE_URL = "https://chatgpt.com/backend-api/codex";
|
|
23
|
+
var CODEX_API_ENDPOINT = `${CODEX_BASE_URL}/responses`;
|
|
24
|
+
var CODEX_HEADERS = {
|
|
25
|
+
originator: "codex_cli_rs",
|
|
26
|
+
"OpenAI-Beta": "responses=experimental"
|
|
27
|
+
};
|
|
28
|
+
var CODEX_UNSUPPORTED_TOOL_TYPES = [
|
|
29
|
+
"web_fetch_20250910",
|
|
30
|
+
"web_search_20250305"
|
|
31
|
+
];
|
|
32
|
+
function extractCodexAccountId(token) {
|
|
33
|
+
const parts = token.split(".");
|
|
34
|
+
const payload = parts[1];
|
|
35
|
+
if (parts.length !== 3 || !payload) return void 0;
|
|
36
|
+
try {
|
|
37
|
+
const claims = JSON.parse(
|
|
38
|
+
Buffer.from(payload, "base64url").toString("utf8")
|
|
39
|
+
);
|
|
40
|
+
return claims.chatgpt_account_id || claims["https://api.openai.com/auth"]?.chatgpt_account_id || claims.organizations?.[0]?.id;
|
|
41
|
+
} catch {
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function stripCodexItemIds(messages) {
|
|
46
|
+
return messages.map((msg) => {
|
|
47
|
+
if (!msg || typeof msg !== "object" || !("id" in msg)) return msg;
|
|
48
|
+
const { id: _id, ...rest } = msg;
|
|
49
|
+
return rest;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function buildCodexProviderOptions(params) {
|
|
53
|
+
return {
|
|
54
|
+
openai: {
|
|
55
|
+
instructions: params.system,
|
|
56
|
+
store: false,
|
|
57
|
+
include: ["reasoning.encrypted_content"],
|
|
58
|
+
...params.sessionId ? { promptCacheKey: params.sessionId } : {}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
CLIENT_ID,
|
|
65
|
+
ISSUER,
|
|
66
|
+
AUTHORIZE_ENDPOINT,
|
|
67
|
+
TOKEN_ENDPOINT,
|
|
68
|
+
SCOPE,
|
|
69
|
+
OAUTH_PORT,
|
|
70
|
+
CALLBACK_PATH,
|
|
71
|
+
ADVERTISED_HOST,
|
|
72
|
+
BIND_HOST,
|
|
73
|
+
REDIRECT_URI,
|
|
74
|
+
CALLBACK_TIMEOUT_MS,
|
|
75
|
+
EXPIRY_SKEW_MS,
|
|
76
|
+
HEADER_OAUTH_TOKEN,
|
|
77
|
+
HEADER_OAUTH_PROVIDER,
|
|
78
|
+
OAUTH_PROVIDER_VALUE,
|
|
79
|
+
PROVIDER_ID,
|
|
80
|
+
DISPLAY_NAME,
|
|
81
|
+
GATEWAY_ROUTE,
|
|
82
|
+
CODEX_BASE_URL,
|
|
83
|
+
CODEX_API_ENDPOINT,
|
|
84
|
+
CODEX_HEADERS,
|
|
85
|
+
CODEX_UNSUPPORTED_TOOL_TYPES,
|
|
86
|
+
extractCodexAccountId,
|
|
87
|
+
stripCodexItemIds,
|
|
88
|
+
buildCodexProviderOptions
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=chunk-34MJFIMS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/codex.ts"],"sourcesContent":["// OpenAI (Codex / ChatGPT) OAuth constants — a faithful port of the values Command Code's\n// `packages/command/src/auth/codex.ts` registers with OpenAI's authorization server. These are NOT\n// free parameters: OpenAI registered the OAuth client `app_EMoamEEZ73f0CkXaXp7hrann` for the Codex\n// CLI flow with the loopback redirect `http://localhost:1455/auth/callback`, so the client id, port,\n// path and redirect URI MUST match byte-for-byte or OpenAI rejects the `redirect_uri`.\n\n// The OAuth client OpenAI registered for the Codex CLI flow.\nexport const CLIENT_ID = 'app_EMoamEEZ73f0CkXaXp7hrann';\n\n// OpenAI's auth issuer + its derived endpoints.\nexport const ISSUER = 'https://auth.openai.com';\nexport const AUTHORIZE_ENDPOINT = `${ISSUER}/oauth/authorize`;\nexport const TOKEN_ENDPOINT = `${ISSUER}/oauth/token`;\n\n// The scopes Codex requests (`offline_access` is what mints the refresh token).\nexport const SCOPE = 'openid profile email offline_access';\n\n// Loopback redirect — a FIXED port (NOT an ephemeral one): OpenAI only accepts this exact,\n// pre-registered URI. The server binds 127.0.0.1 (like codex.ts) but ADVERTISES `localhost`, which\n// is the host OpenAI registered, so the two hosts intentionally differ.\nexport const OAUTH_PORT = 1455;\nexport const CALLBACK_PATH = '/auth/callback';\nexport const ADVERTISED_HOST = 'localhost'; // host in the registered redirect_uri\nexport const BIND_HOST = '127.0.0.1'; // where the loopback server actually listens (matches codex.ts)\nexport const REDIRECT_URI = `http://${ADVERTISED_HOST}:${OAUTH_PORT}${CALLBACK_PATH}`;\n\n// Wait at most this long for the browser to redirect back (mirrors codex.ts CALLBACK_TIMEOUT_MS).\nexport const CALLBACK_TIMEOUT_MS = 5 * 60 * 1000;\n\n// Refresh this long before the access token actually expires (mirrors codex.ts' 5-minute buffer).\nexport const EXPIRY_SKEW_MS = 5 * 60 * 1000;\n\n// The gateway auth headers Command Code sends (mirrors `packages/shared/src/constants.ts` HEADERS).\n// Hardcoded so this plugin stays a standalone external package that never imports command internals.\nexport const HEADER_OAUTH_TOKEN = 'x-oauth-token';\nexport const HEADER_OAUTH_PROVIDER = 'x-oauth-provider';\n\n// CRITICAL parity value. command's `getOAuthCredentials` sends `oauthProvider = PROVIDER.CODEX =\n// 'codex'` for this flow — NOT 'openai'. The `/alpha/generate` gateway keys OpenAI/Codex routing off\n// `'codex'`, so this header value MUST stay `'codex'` even though this module's id is `'openai'`.\nexport const OAUTH_PROVIDER_VALUE = 'codex';\n\n// This module's provider id — the credential-store key + registry lookup key. Deliberately distinct\n// from OAUTH_PROVIDER_VALUE above (store/registry use 'openai'; the gateway header uses 'codex').\nexport const PROVIDER_ID = 'openai';\nexport const DISPLAY_NAME = 'OpenAI';\n\n// Default gateway route (server-routed transport — Command Code routes the real model server-side).\nexport const GATEWAY_ROUTE = '/alpha/generate';\n","// Codex wire constants + pure helpers — DEPENDENCY-FREE on purpose. shared/constants and the\n// API worker both consume these; the AI-SDK-backed factories live in ./server (which imports\n// from here) so browser/Studio consumers never pull '@ai-sdk/openai'.\n//\n// Verified against the open-source `openai/codex` CLI (codex-rs), which is the sanctioned\n// integration path for ChatGPT-subscription tokens: same base URL, originator, beta header, and\n// account-id claim chain. opencode and pi use these exact values too.\n\n// Routes through the chatgpt.com backend. AI SDK's createOpenAI().responses(model) appends\n// \"/responses\" to baseURL, yielding https://chatgpt.com/backend-api/codex/responses.\nexport const CODEX_BASE_URL = 'https://chatgpt.com/backend-api/codex';\nexport const CODEX_API_ENDPOINT = `${CODEX_BASE_URL}/responses`;\n\nexport const CODEX_HEADERS: Record<string, string> = {\n\toriginator: 'codex_cli_rs',\n\t'OpenAI-Beta': 'responses=experimental',\n};\n\nexport const CODEX_UNSUPPORTED_TOOL_TYPES: readonly string[] = [\n\t'web_fetch_20250910',\n\t'web_search_20250305',\n];\n\n// The wire `oauthProvider` value the /alpha/generate gateway + the API worker key Codex routing\n// off (distinct from the module id 'openai'). Re-exported from constants.ts — the CLI sends that\n// constant in the OAUTH_PROVIDER header and the server registry matches on this one, so they must\n// be the SAME string, not two literals that can drift.\nexport {OAUTH_PROVIDER_VALUE as CODEX_OAUTH_PROVIDER_VALUE} from './constants.js';\n\n/**\n * Parse JWT claims to extract the ChatGPT account ID for Codex OAuth.\n * The access_token is a JWT issued by auth.openai.com; claims live in the\n * payload. We only read, never verify — it was just issued to us over TLS.\n */\nexport function extractCodexAccountId(token: string): string | undefined {\n\tconst parts = token.split('.');\n\tconst payload = parts[1];\n\tif (parts.length !== 3 || !payload) return undefined;\n\ttry {\n\t\tconst claims = JSON.parse(\n\t\t\tBuffer.from(payload, 'base64url').toString('utf8'),\n\t\t) as {\n\t\t\tchatgpt_account_id?: string;\n\t\t\torganizations?: Array<{id: string}>;\n\t\t\t'https://api.openai.com/auth'?: {chatgpt_account_id?: string};\n\t\t};\n\t\treturn (\n\t\t\tclaims.chatgpt_account_id ||\n\t\t\tclaims['https://api.openai.com/auth']?.chatgpt_account_id ||\n\t\t\tclaims.organizations?.[0]?.id\n\t\t);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/**\n * Codex (OpenAI Responses API) message scrub: strips item IDs the endpoint rejects. Applied\n * after the api's generic content normalization.\n */\nexport function stripCodexItemIds(messages: readonly unknown[]): unknown[] {\n\treturn messages.map((msg: unknown) => {\n\t\tif (!msg || typeof msg !== 'object' || !('id' in msg)) return msg;\n\t\tconst {id: _id, ...rest} = msg as Record<string, unknown>;\n\t\treturn rest;\n\t});\n}\n\n/**\n * providerOptions.openai for a Codex request. The Responses endpoint takes the system prompt via\n * `instructions` (NOT the `system` param) and rejects `store: true`.\n *\n * `include: reasoning.encrypted_content` mirrors codex-rs/opencode/pi: without it the backend\n * omits the encrypted reasoning items that MUST be replayed on the next turn of a reasoning\n * model, so multi-turn/tool-loop requests fail — the primary suspect for \"OpenAI provider\n * doesn't work\" reports. `promptCacheKey` (session id) opts into prompt caching keyed the same\n * way codex-rs keys it.\n */\nexport function buildCodexProviderOptions(params: {\n\treadonly system: string;\n\treadonly sessionId?: string;\n}): Record<string, Record<string, unknown>> {\n\treturn {\n\t\topenai: {\n\t\t\tinstructions: params.system,\n\t\t\tstore: false,\n\t\t\tinclude: ['reasoning.encrypted_content'],\n\t\t\t...(params.sessionId ? {promptCacheKey: params.sessionId} : {}),\n\t\t},\n\t};\n}\n"],"mappings":";AAOO,IAAM,YAAY;AAGlB,IAAM,SAAS;AACf,IAAM,qBAAqB,GAAG,MAAM;AACpC,IAAM,iBAAiB,GAAG,MAAM;AAGhC,IAAM,QAAQ;AAKd,IAAM,aAAa;AACnB,IAAM,gBAAgB;AACtB,IAAM,kBAAkB;AACxB,IAAM,YAAY;AAClB,IAAM,eAAe,UAAU,eAAe,IAAI,UAAU,GAAG,aAAa;AAG5E,IAAM,sBAAsB,IAAI,KAAK;AAGrC,IAAM,iBAAiB,IAAI,KAAK;AAIhC,IAAM,qBAAqB;AAC3B,IAAM,wBAAwB;AAK9B,IAAM,uBAAuB;AAI7B,IAAM,cAAc;AACpB,IAAM,eAAe;AAGrB,IAAM,gBAAgB;;;ACtCtB,IAAM,iBAAiB;AACvB,IAAM,qBAAqB,GAAG,cAAc;AAE5C,IAAM,gBAAwC;AAAA,EACpD,YAAY;AAAA,EACZ,eAAe;AAChB;AAEO,IAAM,+BAAkD;AAAA,EAC9D;AAAA,EACA;AACD;AAaO,SAAS,sBAAsB,OAAmC;AACxE,QAAM,QAAQ,MAAM,MAAM,GAAG;AAC7B,QAAM,UAAU,MAAM,CAAC;AACvB,MAAI,MAAM,WAAW,KAAK,CAAC,QAAS,QAAO;AAC3C,MAAI;AACH,UAAM,SAAS,KAAK;AAAA,MACnB,OAAO,KAAK,SAAS,WAAW,EAAE,SAAS,MAAM;AAAA,IAClD;AAKA,WACC,OAAO,sBACP,OAAO,6BAA6B,GAAG,sBACvC,OAAO,gBAAgB,CAAC,GAAG;AAAA,EAE7B,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAMO,SAAS,kBAAkB,UAAyC;AAC1E,SAAO,SAAS,IAAI,CAAC,QAAiB;AACrC,QAAI,CAAC,OAAO,OAAO,QAAQ,YAAY,EAAE,QAAQ,KAAM,QAAO;AAC9D,UAAM,EAAC,IAAI,KAAK,GAAG,KAAI,IAAI;AAC3B,WAAO;AAAA,EACR,CAAC;AACF;AAYO,SAAS,0BAA0B,QAGE;AAC3C,SAAO;AAAA,IACN,QAAQ;AAAA,MACP,cAAc,OAAO;AAAA,MACrB,OAAO;AAAA,MACP,SAAS,CAAC,6BAA6B;AAAA,MACvC,GAAI,OAAO,YAAY,EAAC,gBAAgB,OAAO,UAAS,IAAI,CAAC;AAAA,IAC9D;AAAA,EACD;AACD;","names":[]}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// src/models.ts
|
|
2
|
+
var EFFORT_LOW_TO_MAX = [
|
|
3
|
+
"low",
|
|
4
|
+
"medium",
|
|
5
|
+
"high",
|
|
6
|
+
"xhigh",
|
|
7
|
+
"max"
|
|
8
|
+
];
|
|
9
|
+
var EFFORT_LOW_TO_XHIGH = [
|
|
10
|
+
"low",
|
|
11
|
+
"medium",
|
|
12
|
+
"high",
|
|
13
|
+
"xhigh"
|
|
14
|
+
];
|
|
15
|
+
var EFFORT_LOW_TO_HIGH = [
|
|
16
|
+
"low",
|
|
17
|
+
"medium",
|
|
18
|
+
"high"
|
|
19
|
+
];
|
|
20
|
+
var OPENAI_MODEL_OPTIONS = {
|
|
21
|
+
GPT_5_6_SOL: {
|
|
22
|
+
id: "gpt-5.6-sol",
|
|
23
|
+
inputModalities: ["text", "image"],
|
|
24
|
+
provider: "openai",
|
|
25
|
+
spec: "responses",
|
|
26
|
+
label: "GPT-5.6 Sol",
|
|
27
|
+
name: "GPT-5.6 Sol",
|
|
28
|
+
description: "frontier model for complex professional work",
|
|
29
|
+
reasoning: true,
|
|
30
|
+
reasoningEfforts: EFFORT_LOW_TO_MAX,
|
|
31
|
+
contextWindow: 105e4
|
|
32
|
+
},
|
|
33
|
+
GPT_5_6_TERRA: {
|
|
34
|
+
id: "gpt-5.6-terra",
|
|
35
|
+
inputModalities: ["text", "image"],
|
|
36
|
+
provider: "openai",
|
|
37
|
+
spec: "responses",
|
|
38
|
+
label: "GPT-5.6 Terra",
|
|
39
|
+
name: "GPT-5.6 Terra",
|
|
40
|
+
description: "balances intelligence and cost",
|
|
41
|
+
reasoning: true,
|
|
42
|
+
reasoningEfforts: EFFORT_LOW_TO_MAX,
|
|
43
|
+
contextWindow: 105e4
|
|
44
|
+
},
|
|
45
|
+
GPT_5_6_LUNA: {
|
|
46
|
+
id: "gpt-5.6-luna",
|
|
47
|
+
inputModalities: ["text", "image"],
|
|
48
|
+
provider: "openai",
|
|
49
|
+
spec: "responses",
|
|
50
|
+
label: "GPT-5.6 Luna",
|
|
51
|
+
name: "GPT-5.6 Luna",
|
|
52
|
+
description: "optimized for cost-sensitive workloads",
|
|
53
|
+
reasoning: true,
|
|
54
|
+
reasoningEfforts: EFFORT_LOW_TO_MAX,
|
|
55
|
+
contextWindow: 105e4
|
|
56
|
+
},
|
|
57
|
+
GPT_5_5: {
|
|
58
|
+
id: "gpt-5.5",
|
|
59
|
+
inputModalities: ["text", "image"],
|
|
60
|
+
provider: "openai",
|
|
61
|
+
spec: "responses",
|
|
62
|
+
label: "GPT-5.5",
|
|
63
|
+
name: "GPT-5.5",
|
|
64
|
+
description: "latest frontier model for general complex work",
|
|
65
|
+
reasoning: true,
|
|
66
|
+
reasoningEfforts: EFFORT_LOW_TO_XHIGH,
|
|
67
|
+
// 400k like the rest of the 5.x line (harness known-models mirrors this value).
|
|
68
|
+
contextWindow: 4e5
|
|
69
|
+
},
|
|
70
|
+
GPT_5_4: {
|
|
71
|
+
id: "gpt-5.4",
|
|
72
|
+
inputModalities: ["text", "image"],
|
|
73
|
+
provider: "openai",
|
|
74
|
+
spec: "responses",
|
|
75
|
+
label: "GPT-5.4",
|
|
76
|
+
name: "GPT-5.4",
|
|
77
|
+
description: "frontier model for general complex work",
|
|
78
|
+
reasoning: true,
|
|
79
|
+
reasoningEfforts: EFFORT_LOW_TO_XHIGH,
|
|
80
|
+
contextWindow: 4e5
|
|
81
|
+
},
|
|
82
|
+
GPT_5_3_CODEX: {
|
|
83
|
+
id: "gpt-5.3-codex",
|
|
84
|
+
inputModalities: ["text", "image"],
|
|
85
|
+
provider: "openai",
|
|
86
|
+
spec: "responses",
|
|
87
|
+
label: "GPT-5.3 Codex",
|
|
88
|
+
name: "GPT-5.3 Codex",
|
|
89
|
+
description: "frontier coding model",
|
|
90
|
+
reasoning: true,
|
|
91
|
+
reasoningEfforts: EFFORT_LOW_TO_XHIGH,
|
|
92
|
+
contextWindow: 4e5
|
|
93
|
+
},
|
|
94
|
+
GPT_5_4_MINI: {
|
|
95
|
+
id: "gpt-5.4-mini",
|
|
96
|
+
inputModalities: ["text", "image"],
|
|
97
|
+
provider: "openai",
|
|
98
|
+
spec: "responses",
|
|
99
|
+
label: "GPT-5.4 Mini",
|
|
100
|
+
name: "GPT-5.4 Mini",
|
|
101
|
+
description: "fast, cost-effective model for everyday tasks",
|
|
102
|
+
reasoning: true,
|
|
103
|
+
reasoningEfforts: EFFORT_LOW_TO_HIGH,
|
|
104
|
+
contextWindow: 4e5
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var OPENAI_MODEL_IDS = Object.values(
|
|
108
|
+
OPENAI_MODEL_OPTIONS
|
|
109
|
+
).map((option) => option.id);
|
|
110
|
+
var OPENAI_SUPPORTED_MODEL_PROVIDERS = ["openai"];
|
|
111
|
+
var OPENAI_MODEL_SPECS = Object.values(OPENAI_MODEL_OPTIONS).map(
|
|
112
|
+
(option) => ({
|
|
113
|
+
id: option.id,
|
|
114
|
+
provider: "openai",
|
|
115
|
+
contextWindow: "contextWindow" in option ? option.contextWindow : void 0,
|
|
116
|
+
reasoningEfforts: option.reasoningEfforts,
|
|
117
|
+
inputModalities: option.inputModalities
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
export {
|
|
122
|
+
OPENAI_MODEL_OPTIONS,
|
|
123
|
+
OPENAI_MODEL_IDS,
|
|
124
|
+
OPENAI_SUPPORTED_MODEL_PROVIDERS,
|
|
125
|
+
OPENAI_MODEL_SPECS
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=chunk-J2XEWLRM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/models.ts"],"sourcesContent":["// @byokkit/cmd-provider-openai/models — the COMPLETE OpenAI model catalog: /model picker\n// metadata, Responses-vs-ChatComplete spec kinds, context windows, and reasoning efforts.\n// Dependency-free plain data (structural types) so the CLI (via shared/constants), the API\n// worker, and Studio can all consume it, and so this package can move to its own repo without\n// dragging monorepo internals along. Values are a verbatim port from shared/constants.ts +\n// harness/config/known-models.ts — those sites now import from HERE.\n\nexport type OpenAIReasoningEffort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';\n\n// Structural copy of shared's ModelOption (shared `satisfies`-checks on import).\nexport interface OpenAIModelOption {\n\treadonly id: string;\n\treadonly provider: 'openai';\n\treadonly spec: 'responses' | 'chatComplete';\n\treadonly label: string;\n\treadonly name: string;\n\treadonly description: string;\n\treadonly reasoning?: boolean;\n\treadonly reasoningEfforts?: readonly OpenAIReasoningEffort[];\n\treadonly contextWindow?: number;\n\treadonly inputModalities?: readonly ('text' | 'image')[];\n}\n\nconst EFFORT_LOW_TO_MAX: readonly OpenAIReasoningEffort[] = [\n\t'low',\n\t'medium',\n\t'high',\n\t'xhigh',\n\t'max',\n];\n\nconst EFFORT_LOW_TO_XHIGH: readonly OpenAIReasoningEffort[] = [\n\t'low',\n\t'medium',\n\t'high',\n\t'xhigh',\n];\n\nconst EFFORT_LOW_TO_HIGH: readonly OpenAIReasoningEffort[] = [\n\t'low',\n\t'medium',\n\t'high',\n];\n\n// The /model catalog entries (verbatim from shared MODEL_OPTIONS; key names preserved so\n// shared's spread keeps identical keys).\nexport const OPENAI_MODEL_OPTIONS = {\n\tGPT_5_6_SOL: {\n\t\tid: 'gpt-5.6-sol',\n\t\tinputModalities: ['text', 'image'],\n\t\tprovider: 'openai',\n\t\tspec: 'responses',\n\t\tlabel: 'GPT-5.6 Sol',\n\t\tname: 'GPT-5.6 Sol',\n\t\tdescription: 'frontier model for complex professional work',\n\t\treasoning: true,\n\t\treasoningEfforts: EFFORT_LOW_TO_MAX,\n\t\tcontextWindow: 1_050_000,\n\t},\n\tGPT_5_6_TERRA: {\n\t\tid: 'gpt-5.6-terra',\n\t\tinputModalities: ['text', 'image'],\n\t\tprovider: 'openai',\n\t\tspec: 'responses',\n\t\tlabel: 'GPT-5.6 Terra',\n\t\tname: 'GPT-5.6 Terra',\n\t\tdescription: 'balances intelligence and cost',\n\t\treasoning: true,\n\t\treasoningEfforts: EFFORT_LOW_TO_MAX,\n\t\tcontextWindow: 1_050_000,\n\t},\n\tGPT_5_6_LUNA: {\n\t\tid: 'gpt-5.6-luna',\n\t\tinputModalities: ['text', 'image'],\n\t\tprovider: 'openai',\n\t\tspec: 'responses',\n\t\tlabel: 'GPT-5.6 Luna',\n\t\tname: 'GPT-5.6 Luna',\n\t\tdescription: 'optimized for cost-sensitive workloads',\n\t\treasoning: true,\n\t\treasoningEfforts: EFFORT_LOW_TO_MAX,\n\t\tcontextWindow: 1_050_000,\n\t},\n\tGPT_5_5: {\n\t\tid: 'gpt-5.5',\n\t\tinputModalities: ['text', 'image'],\n\t\tprovider: 'openai',\n\t\tspec: 'responses',\n\t\tlabel: 'GPT-5.5',\n\t\tname: 'GPT-5.5',\n\t\tdescription: 'latest frontier model for general complex work',\n\t\treasoning: true,\n\t\treasoningEfforts: EFFORT_LOW_TO_XHIGH,\n\t\t// 400k like the rest of the 5.x line (harness known-models mirrors this value).\n\t\tcontextWindow: 400_000,\n\t},\n\tGPT_5_4: {\n\t\tid: 'gpt-5.4',\n\t\tinputModalities: ['text', 'image'],\n\t\tprovider: 'openai',\n\t\tspec: 'responses',\n\t\tlabel: 'GPT-5.4',\n\t\tname: 'GPT-5.4',\n\t\tdescription: 'frontier model for general complex work',\n\t\treasoning: true,\n\t\treasoningEfforts: EFFORT_LOW_TO_XHIGH,\n\t\tcontextWindow: 400_000,\n\t},\n\tGPT_5_3_CODEX: {\n\t\tid: 'gpt-5.3-codex',\n\t\tinputModalities: ['text', 'image'],\n\t\tprovider: 'openai',\n\t\tspec: 'responses',\n\t\tlabel: 'GPT-5.3 Codex',\n\t\tname: 'GPT-5.3 Codex',\n\t\tdescription: 'frontier coding model',\n\t\treasoning: true,\n\t\treasoningEfforts: EFFORT_LOW_TO_XHIGH,\n\t\tcontextWindow: 400_000,\n\t},\n\tGPT_5_4_MINI: {\n\t\tid: 'gpt-5.4-mini',\n\t\tinputModalities: ['text', 'image'],\n\t\tprovider: 'openai',\n\t\tspec: 'responses',\n\t\tlabel: 'GPT-5.4 Mini',\n\t\tname: 'GPT-5.4 Mini',\n\t\tdescription: 'fast, cost-effective model for everyday tasks',\n\t\treasoning: true,\n\t\treasoningEfforts: EFFORT_LOW_TO_HIGH,\n\t\tcontextWindow: 400_000,\n\t},\n} as const satisfies Record<string, OpenAIModelOption>;\n\n/** Canonical OpenAI model ids, in catalog order. */\nexport const OPENAI_MODEL_IDS: readonly string[] = Object.values(\n\tOPENAI_MODEL_OPTIONS,\n).map(option => option.id);\n\n// The upstream vendors OpenAI serves — the Codex gateway routes a request only when the model's\n// provider is in this set (port of CMD_PROVIDER_REGISTRY['codex'].supportedModelProviders).\nexport const OPENAI_SUPPORTED_MODEL_PROVIDERS: readonly string[] = ['openai'];\n\n/**\n * Harness ModelSpec-shaped catalog (structural — validated on registration by the harness).\n */\nexport const OPENAI_MODEL_SPECS = Object.values(OPENAI_MODEL_OPTIONS).map(\n\toption => ({\n\t\tid: option.id,\n\t\tprovider: 'openai' as const,\n\t\tcontextWindow:\n\t\t\t'contextWindow' in option ? option.contextWindow : undefined,\n\t\treasoningEfforts: option.reasoningEfforts,\n\t\tinputModalities: option.inputModalities,\n\t}),\n);\n"],"mappings":";AAuBA,IAAM,oBAAsD;AAAA,EAC3D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEA,IAAM,sBAAwD;AAAA,EAC7D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AAEA,IAAM,qBAAuD;AAAA,EAC5D;AAAA,EACA;AAAA,EACA;AACD;AAIO,IAAM,uBAAuB;AAAA,EACnC,aAAa;AAAA,IACZ,IAAI;AAAA,IACJ,iBAAiB,CAAC,QAAQ,OAAO;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,WAAW;AAAA,IACX,kBAAkB;AAAA,IAClB,eAAe;AAAA,EAChB;AAAA,EACA,eAAe;AAAA,IACd,IAAI;AAAA,IACJ,iBAAiB,CAAC,QAAQ,OAAO;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,WAAW;AAAA,IACX,kBAAkB;AAAA,IAClB,eAAe;AAAA,EAChB;AAAA,EACA,cAAc;AAAA,IACb,IAAI;AAAA,IACJ,iBAAiB,CAAC,QAAQ,OAAO;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,WAAW;AAAA,IACX,kBAAkB;AAAA,IAClB,eAAe;AAAA,EAChB;AAAA,EACA,SAAS;AAAA,IACR,IAAI;AAAA,IACJ,iBAAiB,CAAC,QAAQ,OAAO;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,WAAW;AAAA,IACX,kBAAkB;AAAA;AAAA,IAElB,eAAe;AAAA,EAChB;AAAA,EACA,SAAS;AAAA,IACR,IAAI;AAAA,IACJ,iBAAiB,CAAC,QAAQ,OAAO;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,WAAW;AAAA,IACX,kBAAkB;AAAA,IAClB,eAAe;AAAA,EAChB;AAAA,EACA,eAAe;AAAA,IACd,IAAI;AAAA,IACJ,iBAAiB,CAAC,QAAQ,OAAO;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,WAAW;AAAA,IACX,kBAAkB;AAAA,IAClB,eAAe;AAAA,EAChB;AAAA,EACA,cAAc;AAAA,IACb,IAAI;AAAA,IACJ,iBAAiB,CAAC,QAAQ,OAAO;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,IACN,aAAa;AAAA,IACb,WAAW;AAAA,IACX,kBAAkB;AAAA,IAClB,eAAe;AAAA,EAChB;AACD;AAGO,IAAM,mBAAsC,OAAO;AAAA,EACzD;AACD,EAAE,IAAI,YAAU,OAAO,EAAE;AAIlB,IAAM,mCAAsD,CAAC,QAAQ;AAKrE,IAAM,qBAAqB,OAAO,OAAO,oBAAoB,EAAE;AAAA,EACrE,aAAW;AAAA,IACV,IAAI,OAAO;AAAA,IACX,UAAU;AAAA,IACV,eACC,mBAAmB,SAAS,OAAO,gBAAgB;AAAA,IACpD,kBAAkB,OAAO;AAAA,IACzB,iBAAiB,OAAO;AAAA,EACzB;AACD;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CODEX_BASE_URL,
|
|
3
|
+
CODEX_HEADERS,
|
|
4
|
+
extractCodexAccountId
|
|
5
|
+
} from "./chunk-34MJFIMS.js";
|
|
6
|
+
|
|
7
|
+
// src/server/index.ts
|
|
8
|
+
import { createOpenAI } from "@ai-sdk/openai";
|
|
9
|
+
function getCodexLanguageModel(params) {
|
|
10
|
+
const accountId = extractCodexAccountId(params.oAuthToken);
|
|
11
|
+
const openai = createOpenAI({
|
|
12
|
+
apiKey: params.oAuthToken,
|
|
13
|
+
baseURL: CODEX_BASE_URL,
|
|
14
|
+
headers: {
|
|
15
|
+
...CODEX_HEADERS,
|
|
16
|
+
Authorization: `Bearer ${params.oAuthToken}`,
|
|
17
|
+
...accountId ? { "ChatGPT-Account-Id": accountId } : {}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
return openai.responses(params.modelId);
|
|
21
|
+
}
|
|
22
|
+
function getOpenAIApiKeyLanguageModel(params) {
|
|
23
|
+
const openai = createOpenAI({
|
|
24
|
+
apiKey: params.apiKey,
|
|
25
|
+
...params.fetch && { fetch: params.fetch }
|
|
26
|
+
});
|
|
27
|
+
return params.spec === "responses" ? openai.responses(params.modelId) : openai.chat(params.modelId);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
getCodexLanguageModel,
|
|
32
|
+
getOpenAIApiKeyLanguageModel
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=chunk-NSTLHK7M.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/index.ts"],"sourcesContent":["// @byokkit/cmd-provider-openai/server — the SERVER half of the OpenAI provider: the Codex\n// (ChatGPT Pro/Plus subscription) gateway wire glue plus the plain API-key path. This is the\n// backend counterpart of the CLI module's Codex OAuth (same registered client the open-source\n// `openai/codex` CLI uses — tokens minted there are honored here). Lives in the provider package,\n// not the api worker, so the WHOLE provider ships as one unit that can move to its own repo.\n//\n// Dependency note: '@ai-sdk/openai' is a real dependency of THIS package. The CLI entry ('.')\n// and the pure ./codex constants never import this subpath, so CLI/Studio bundles don't pull\n// the AI SDK in.\n\nimport {createOpenAI} from '@ai-sdk/openai';\nimport {\n\tCODEX_BASE_URL,\n\tCODEX_HEADERS,\n\textractCodexAccountId,\n} from '../codex.js';\n\nexport {\n\tbuildCodexProviderOptions,\n\tCODEX_API_ENDPOINT,\n\tCODEX_BASE_URL,\n\tCODEX_HEADERS,\n\tCODEX_UNSUPPORTED_TOOL_TYPES,\n\textractCodexAccountId,\n\tstripCodexItemIds,\n} from '../codex.js';\n\nexport interface CodexLanguageModelParams {\n\treadonly modelId: string;\n\t/** The auth.openai.com access token (JWT) from the Codex OAuth flow. */\n\treadonly oAuthToken: string;\n}\n\n/**\n * Build the AI-SDK language model for a Codex (ChatGPT subscription) request. Returned as\n * unknown; the api worker casts to its LanguageModelV3 like it always did.\n */\nexport function getCodexLanguageModel(\n\tparams: CodexLanguageModelParams,\n): unknown {\n\tconst accountId = extractCodexAccountId(params.oAuthToken);\n\tconst openai = createOpenAI({\n\t\tapiKey: params.oAuthToken,\n\t\tbaseURL: CODEX_BASE_URL,\n\t\theaders: {\n\t\t\t...CODEX_HEADERS,\n\t\t\tAuthorization: `Bearer ${params.oAuthToken}`,\n\t\t\t...(accountId ? {'ChatGPT-Account-Id': accountId} : {}),\n\t\t},\n\t});\n\treturn openai.responses(params.modelId);\n}\n\nexport interface OpenAIApiKeyLanguageModelParams {\n\treadonly modelId: string;\n\treadonly apiKey?: string;\n\t/** 'responses' | 'chatComplete' — the catalog's spec kind for this model. */\n\treadonly spec: 'responses' | 'chatComplete';\n\t/**\n\t * Optional fetch override (the api worker wraps global fetch to capture OpenAI's\n\t * cache_write_tokens at the wire — @ai-sdk/openai strips the field during zod parsing).\n\t */\n\treadonly fetch?: typeof globalThis.fetch;\n}\n\n/** Plain OPENAI_API_KEY path (api.openai.com), spec-aware. */\nexport function getOpenAIApiKeyLanguageModel(\n\tparams: OpenAIApiKeyLanguageModelParams,\n): unknown {\n\tconst openai = createOpenAI({\n\t\tapiKey: params.apiKey,\n\t\t...(params.fetch && {fetch: params.fetch}),\n\t});\n\treturn params.spec === 'responses'\n\t\t? openai.responses(params.modelId)\n\t\t: openai.chat(params.modelId);\n}\n"],"mappings":";;;;;;;AAUA,SAAQ,oBAAmB;AA2BpB,SAAS,sBACf,QACU;AACV,QAAM,YAAY,sBAAsB,OAAO,UAAU;AACzD,QAAM,SAAS,aAAa;AAAA,IAC3B,QAAQ,OAAO;AAAA,IACf,SAAS;AAAA,IACT,SAAS;AAAA,MACR,GAAG;AAAA,MACH,eAAe,UAAU,OAAO,UAAU;AAAA,MAC1C,GAAI,YAAY,EAAC,sBAAsB,UAAS,IAAI,CAAC;AAAA,IACtD;AAAA,EACD,CAAC;AACD,SAAO,OAAO,UAAU,OAAO,OAAO;AACvC;AAeO,SAAS,6BACf,QACU;AACV,QAAM,SAAS,aAAa;AAAA,IAC3B,QAAQ,OAAO;AAAA,IACf,GAAI,OAAO,SAAS,EAAC,OAAO,OAAO,MAAK;AAAA,EACzC,CAAC;AACD,SAAO,OAAO,SAAS,cACpB,OAAO,UAAU,OAAO,OAAO,IAC/B,OAAO,KAAK,OAAO,OAAO;AAC9B;","names":[]}
|
package/dist/codex.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export { e as CODEX_OAUTH_PROVIDER_VALUE } from './constants-BPm3xKmw.js';
|
|
2
|
+
|
|
3
|
+
declare const CODEX_BASE_URL = "https://chatgpt.com/backend-api/codex";
|
|
4
|
+
declare const CODEX_API_ENDPOINT = "https://chatgpt.com/backend-api/codex/responses";
|
|
5
|
+
declare const CODEX_HEADERS: Record<string, string>;
|
|
6
|
+
declare const CODEX_UNSUPPORTED_TOOL_TYPES: readonly string[];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Parse JWT claims to extract the ChatGPT account ID for Codex OAuth.
|
|
10
|
+
* The access_token is a JWT issued by auth.openai.com; claims live in the
|
|
11
|
+
* payload. We only read, never verify — it was just issued to us over TLS.
|
|
12
|
+
*/
|
|
13
|
+
declare function extractCodexAccountId(token: string): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Codex (OpenAI Responses API) message scrub: strips item IDs the endpoint rejects. Applied
|
|
16
|
+
* after the api's generic content normalization.
|
|
17
|
+
*/
|
|
18
|
+
declare function stripCodexItemIds(messages: readonly unknown[]): unknown[];
|
|
19
|
+
/**
|
|
20
|
+
* providerOptions.openai for a Codex request. The Responses endpoint takes the system prompt via
|
|
21
|
+
* `instructions` (NOT the `system` param) and rejects `store: true`.
|
|
22
|
+
*
|
|
23
|
+
* `include: reasoning.encrypted_content` mirrors codex-rs/opencode/pi: without it the backend
|
|
24
|
+
* omits the encrypted reasoning items that MUST be replayed on the next turn of a reasoning
|
|
25
|
+
* model, so multi-turn/tool-loop requests fail — the primary suspect for "OpenAI provider
|
|
26
|
+
* doesn't work" reports. `promptCacheKey` (session id) opts into prompt caching keyed the same
|
|
27
|
+
* way codex-rs keys it.
|
|
28
|
+
*/
|
|
29
|
+
declare function buildCodexProviderOptions(params: {
|
|
30
|
+
readonly system: string;
|
|
31
|
+
readonly sessionId?: string;
|
|
32
|
+
}): Record<string, Record<string, unknown>>;
|
|
33
|
+
|
|
34
|
+
export { CODEX_API_ENDPOINT, CODEX_BASE_URL, CODEX_HEADERS, CODEX_UNSUPPORTED_TOOL_TYPES, buildCodexProviderOptions, extractCodexAccountId, stripCodexItemIds };
|
package/dist/codex.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CODEX_API_ENDPOINT,
|
|
3
|
+
CODEX_BASE_URL,
|
|
4
|
+
CODEX_HEADERS,
|
|
5
|
+
CODEX_UNSUPPORTED_TOOL_TYPES,
|
|
6
|
+
OAUTH_PROVIDER_VALUE,
|
|
7
|
+
buildCodexProviderOptions,
|
|
8
|
+
extractCodexAccountId,
|
|
9
|
+
stripCodexItemIds
|
|
10
|
+
} from "./chunk-34MJFIMS.js";
|
|
11
|
+
export {
|
|
12
|
+
CODEX_API_ENDPOINT,
|
|
13
|
+
CODEX_BASE_URL,
|
|
14
|
+
CODEX_HEADERS,
|
|
15
|
+
OAUTH_PROVIDER_VALUE as CODEX_OAUTH_PROVIDER_VALUE,
|
|
16
|
+
CODEX_UNSUPPORTED_TOOL_TYPES,
|
|
17
|
+
buildCodexProviderOptions,
|
|
18
|
+
extractCodexAccountId,
|
|
19
|
+
stripCodexItemIds
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=codex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare const CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
2
|
+
declare const ISSUER = "https://auth.openai.com";
|
|
3
|
+
declare const AUTHORIZE_ENDPOINT = "https://auth.openai.com/oauth/authorize";
|
|
4
|
+
declare const TOKEN_ENDPOINT = "https://auth.openai.com/oauth/token";
|
|
5
|
+
declare const SCOPE = "openid profile email offline_access";
|
|
6
|
+
declare const OAUTH_PORT = 1455;
|
|
7
|
+
declare const CALLBACK_PATH = "/auth/callback";
|
|
8
|
+
declare const ADVERTISED_HOST = "localhost";
|
|
9
|
+
declare const BIND_HOST = "127.0.0.1";
|
|
10
|
+
declare const REDIRECT_URI = "http://localhost:1455/auth/callback";
|
|
11
|
+
declare const CALLBACK_TIMEOUT_MS: number;
|
|
12
|
+
declare const EXPIRY_SKEW_MS: number;
|
|
13
|
+
declare const HEADER_OAUTH_TOKEN = "x-oauth-token";
|
|
14
|
+
declare const HEADER_OAUTH_PROVIDER = "x-oauth-provider";
|
|
15
|
+
declare const OAUTH_PROVIDER_VALUE = "codex";
|
|
16
|
+
declare const PROVIDER_ID = "openai";
|
|
17
|
+
declare const DISPLAY_NAME = "OpenAI";
|
|
18
|
+
declare const GATEWAY_ROUTE = "/alpha/generate";
|
|
19
|
+
|
|
20
|
+
export { ADVERTISED_HOST as A, BIND_HOST as B, CALLBACK_PATH as C, DISPLAY_NAME as D, EXPIRY_SKEW_MS as E, GATEWAY_ROUTE as G, HEADER_OAUTH_PROVIDER as H, ISSUER as I, OAUTH_PORT as O, PROVIDER_ID as P, REDIRECT_URI as R, SCOPE as S, TOKEN_ENDPOINT as T, AUTHORIZE_ENDPOINT as a, CALLBACK_TIMEOUT_MS as b, CLIENT_ID as c, HEADER_OAUTH_TOKEN as d, OAUTH_PROVIDER_VALUE as e };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
type ProviderModuleShape = {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly displayName?: string;
|
|
4
|
+
readonly transport:
|
|
5
|
+
| { readonly kind: 'gateway'; readonly route?: string }
|
|
6
|
+
| {
|
|
7
|
+
readonly kind: 'aisdk';
|
|
8
|
+
buildModel(params: {
|
|
9
|
+
readonly model: string;
|
|
10
|
+
readonly auth: {
|
|
11
|
+
readonly headers?: Record<string, string>;
|
|
12
|
+
readonly fetch?: (...args: never[]) => unknown;
|
|
13
|
+
};
|
|
14
|
+
readonly messages: readonly unknown[];
|
|
15
|
+
readonly threadId?: string;
|
|
16
|
+
}): unknown;
|
|
17
|
+
providerOptions?(params: {
|
|
18
|
+
readonly model: string;
|
|
19
|
+
readonly system: string | undefined;
|
|
20
|
+
readonly threadId: string | undefined;
|
|
21
|
+
}): Record<string, Record<string, unknown>> | undefined;
|
|
22
|
+
readonly omitSystem?: boolean;
|
|
23
|
+
modelMaxOutput?(model: string): number | undefined;
|
|
24
|
+
readonly defaultMaxTokens?: number;
|
|
25
|
+
}
|
|
26
|
+
| { readonly kind: 'direct'; readonly stream: (...args: unknown[]) => Promise<never> };
|
|
27
|
+
readonly [key: string]: unknown;
|
|
28
|
+
};
|
|
29
|
+
type OAuthFetchResponse = {
|
|
30
|
+
readonly ok: boolean;
|
|
31
|
+
readonly status: number;
|
|
32
|
+
json(): Promise<unknown>;
|
|
33
|
+
text?(): Promise<string>;
|
|
34
|
+
};
|
|
35
|
+
type OAuthFetchImpl = (
|
|
36
|
+
url: string,
|
|
37
|
+
init?: {
|
|
38
|
+
readonly method?: string;
|
|
39
|
+
readonly headers?: Record<string, string>;
|
|
40
|
+
readonly body?: string;
|
|
41
|
+
readonly signal?: AbortSignal;
|
|
42
|
+
},
|
|
43
|
+
) => Promise<OAuthFetchResponse>;
|
|
44
|
+
type ProviderModule = ProviderModuleShape;
|
|
45
|
+
declare namespace _commandcode_harness_provider_kit {
|
|
46
|
+
type ProviderModule = ProviderModuleShape;
|
|
47
|
+
}
|
|
48
|
+
export { A as ADVERTISED_HOST, a as AUTHORIZE_ENDPOINT, B as BIND_HOST, C as CALLBACK_PATH, b as CALLBACK_TIMEOUT_MS, c as CLIENT_ID, D as DISPLAY_NAME, E as EXPIRY_SKEW_MS, G as GATEWAY_ROUTE, H as HEADER_OAUTH_PROVIDER, d as HEADER_OAUTH_TOKEN, I as ISSUER, O as OAUTH_PORT, e as OAUTH_PROVIDER_VALUE, P as PROVIDER_ID, R as REDIRECT_URI, S as SCOPE, T as TOKEN_ENDPOINT } from './constants-BPm3xKmw.js';
|
|
49
|
+
|
|
50
|
+
interface CreateOpenAIProviderParams {
|
|
51
|
+
readonly fetchImpl?: OAuthFetchImpl;
|
|
52
|
+
readonly now?: () => number;
|
|
53
|
+
}
|
|
54
|
+
declare function createOpenAIProvider(params?: CreateOpenAIProviderParams): ProviderModule;
|
|
55
|
+
|
|
56
|
+
declare const openaiProvider: _commandcode_harness_provider_kit.ProviderModule;
|
|
57
|
+
|
|
58
|
+
export { type CreateOpenAIProviderParams, createOpenAIProvider, openaiProvider as default };
|