@janole/ai-sdk-provider-codex-asp 0.1.3 → 0.1.5

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  `@janole/ai-sdk-provider-codex-asp` is a [Vercel AI SDK](https://ai-sdk.dev/) v6 custom provider for the Codex App Server Protocol.
4
4
 
5
- Status: POC feature-complete for language model usage. Currently tested with `codex-cli` 0.104.0.
5
+ Status: POC feature-complete for language model usage. Currently tested with [codex-cli](https://github.com/openai/codex/releases/tag/rust-v0.104.0) 0.104.0.
6
6
 
7
7
  - `LanguageModelV3` provider implementation
8
8
  - Streaming (`streamText`) and non-streaming (`generateText`)
@@ -115,6 +115,7 @@ const codex = createCodexAppServer({
115
115
  defaultThreadSettings?: { cwd?, approvalMode?, sandboxMode? },
116
116
  approvals?: { onCommandApproval?, onFileChangeApproval? },
117
117
  toolTimeoutMs?: number, // default: 30000
118
+ interruptTimeoutMs?: number, // default: 10000
118
119
  });
119
120
 
120
121
  codex(modelId) // returns a language model instance
@@ -150,6 +151,7 @@ npx tsx examples/stream-text.ts
150
151
  - Use Node.js 18+ with global WebSocket support, or use `stdio` transport.
151
152
  - Request timeouts:
152
153
  - Increase `toolTimeoutMs` for long-running dynamic tools.
154
+ - Increase `interruptTimeoutMs` if `turn/interrupt` acks are slow under heavy load.
153
155
  - Empty generated text:
154
156
  - Verify Codex emits `item/agentMessage/delta` and `turn/completed` notifications.
155
157
 
@@ -161,6 +163,18 @@ npm run build # ESM + CJS + .d.ts via tsup
161
163
  npm run qa # lint + typecheck + test (all-in-one)
162
164
  ```
163
165
 
166
+ ### Generated Protocol Types
167
+
168
+ `src/protocol/app-server-protocol/` is gitignored, but selected generated files are intentionally tracked via `git add -f`.
169
+ This keeps protocol diffs visible in PRs and local `git status` after regeneration.
170
+
171
+ When protocol shapes change, clean and regenerate:
172
+
173
+ ```bash
174
+ rm -rf src/protocol/app-server-protocol
175
+ npm run codex:generate-types
176
+ ```
177
+
164
178
  ## License
165
179
 
166
180
  MIT
package/dist/index.cjs CHANGED
@@ -823,14 +823,14 @@ var DynamicToolsDispatcher = class {
823
823
  // package.json
824
824
  var package_default = {
825
825
  name: "@janole/ai-sdk-provider-codex-asp",
826
- version: "0.1.3"};
826
+ version: "0.1.5"};
827
827
 
828
828
  // src/package-info.ts
829
829
  var PACKAGE_NAME = package_default.name;
830
830
  var PACKAGE_VERSION = package_default.version;
831
831
 
832
832
  // src/protocol/provider-metadata.ts
833
- var CODEX_PROVIDER_ID = "codex-app-server";
833
+ var CODEX_PROVIDER_ID = "@janole/ai-sdk-provider-codex-asp";
834
834
  function codexProviderMetadata(threadId) {
835
835
  if (!threadId) {
836
836
  return void 0;
@@ -1377,6 +1377,20 @@ var CodexLanguageModel = class {
1377
1377
  onPacket: packetLogger
1378
1378
  }));
1379
1379
  const mapper = new CodexEventMapper();
1380
+ let activeThreadId;
1381
+ let activeTurnId;
1382
+ const interruptTimeoutMs = this.config.providerSettings.interruptTimeoutMs ?? 1e4;
1383
+ const interruptTurnIfPossible = async () => {
1384
+ if (!activeThreadId || !activeTurnId) {
1385
+ return;
1386
+ }
1387
+ const interruptParams = {
1388
+ threadId: activeThreadId,
1389
+ turnId: activeTurnId
1390
+ };
1391
+ debugLog?.("outbound", "turn/interrupt", interruptParams);
1392
+ await client.request("turn/interrupt", interruptParams, interruptTimeoutMs);
1393
+ };
1380
1394
  const stream = new ReadableStream({
1381
1395
  start: (controller) => {
1382
1396
  let closed = false;
@@ -1404,7 +1418,13 @@ var CodexLanguageModel = class {
1404
1418
  }
1405
1419
  };
1406
1420
  const abortHandler = () => {
1407
- void closeWithError(new DOMException("Aborted", "AbortError"));
1421
+ void (async () => {
1422
+ try {
1423
+ await interruptTurnIfPossible();
1424
+ } catch {
1425
+ }
1426
+ await closeWithError(new DOMException("Aborted", "AbortError"));
1427
+ })();
1408
1428
  };
1409
1429
  if (options.abortSignal) {
1410
1430
  if (options.abortSignal.aborted) {
@@ -1506,7 +1526,7 @@ var CodexLanguageModel = class {
1506
1526
  "thread/resume",
1507
1527
  resumeParams
1508
1528
  );
1509
- threadId = resumeResult.threadId ?? resumeResult.thread?.id ?? resumeThreadId;
1529
+ threadId = resumeResult.thread.id;
1510
1530
  } else {
1511
1531
  const threadStartParams = stripUndefined({
1512
1532
  model: this.config.providerSettings.defaultModel ?? this.modelId,
@@ -1523,6 +1543,7 @@ var CodexLanguageModel = class {
1523
1543
  );
1524
1544
  threadId = extractThreadId(threadStartResult);
1525
1545
  }
1546
+ activeThreadId = threadId;
1526
1547
  mapper.setThreadId(threadId);
1527
1548
  if (hasSdkTools && persistentTransport) {
1528
1549
  this.registerCrossCallToolHandler(
@@ -1539,13 +1560,17 @@ var CodexLanguageModel = class {
1539
1560
  threadId,
1540
1561
  input: turnInput
1541
1562
  });
1542
- extractTurnId(turnStartResult);
1563
+ activeTurnId = extractTurnId(turnStartResult);
1543
1564
  } catch (error) {
1544
1565
  await closeWithError(error);
1545
1566
  }
1546
1567
  })();
1547
1568
  },
1548
1569
  cancel: async () => {
1570
+ try {
1571
+ await interruptTurnIfPossible();
1572
+ } catch {
1573
+ }
1549
1574
  await client.disconnect();
1550
1575
  }
1551
1576
  });
@@ -1637,7 +1662,6 @@ function acquirePersistentPool(settings) {
1637
1662
  }
1638
1663
 
1639
1664
  // src/provider.ts
1640
- var PROVIDER_ID = "codex-app-server";
1641
1665
  function createNoSuchModelError(modelId, modelType) {
1642
1666
  return new provider.NoSuchModelError({ modelId, modelType });
1643
1667
  }
@@ -1677,11 +1701,12 @@ function createCodexAppServer(settings = {}) {
1677
1701
  tools: settings.tools ? { ...settings.tools } : void 0,
1678
1702
  toolHandlers: settings.toolHandlers ? { ...settings.toolHandlers } : void 0,
1679
1703
  toolTimeoutMs: settings.toolTimeoutMs,
1704
+ interruptTimeoutMs: settings.interruptTimeoutMs,
1680
1705
  approvals: settings.approvals ? { ...settings.approvals } : void 0,
1681
1706
  debug: settings.debug ? { ...settings.debug } : void 0
1682
1707
  }));
1683
1708
  const createLanguageModel = (modelId, modelSettings = {}) => new CodexLanguageModel(modelId, modelSettings, {
1684
- provider: PROVIDER_ID,
1709
+ provider: CODEX_PROVIDER_ID,
1685
1710
  providerSettings: resolvedSettings
1686
1711
  });
1687
1712
  const providerFn = ((modelId, modelSettings = {}) => createLanguageModel(modelId, modelSettings));