@janole/ai-sdk-provider-codex-asp 0.1.4 → 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
@@ -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
 
package/dist/index.cjs CHANGED
@@ -823,7 +823,7 @@ 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.4"};
826
+ version: "0.1.5"};
827
827
 
828
828
  // src/package-info.ts
829
829
  var PACKAGE_NAME = package_default.name;
@@ -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) {
@@ -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
  });
@@ -1676,6 +1701,7 @@ function createCodexAppServer(settings = {}) {
1676
1701
  tools: settings.tools ? { ...settings.tools } : void 0,
1677
1702
  toolHandlers: settings.toolHandlers ? { ...settings.toolHandlers } : void 0,
1678
1703
  toolTimeoutMs: settings.toolTimeoutMs,
1704
+ interruptTimeoutMs: settings.interruptTimeoutMs,
1679
1705
  approvals: settings.approvals ? { ...settings.approvals } : void 0,
1680
1706
  debug: settings.debug ? { ...settings.debug } : void 0
1681
1707
  }));