@ai-sdk/harness-codex 1.0.175 → 1.0.177
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/CHANGELOG.md +28 -0
- package/dist/bridge/index.mjs +38 -9
- package/dist/bridge/index.mjs.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/bridge/index.ts +20 -20
- package/src/codex-harness.ts +9 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @ai-sdk/harness-codex
|
|
2
2
|
|
|
3
|
+
## 1.0.177
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a54f0fd: fix(harness): abort a running turn when its host disconnects for good
|
|
8
|
+
- Updated dependencies [8e8033a]
|
|
9
|
+
- Updated dependencies [a54f0fd]
|
|
10
|
+
- @ai-sdk/harness@1.0.175
|
|
11
|
+
|
|
12
|
+
## 1.0.176
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 95c1307: fix(harness-codex): honor caller-provided `codexConfig.model_reasoning_summary` instead of overwriting it with the adapter default
|
|
17
|
+
- Updated dependencies [36802d4]
|
|
18
|
+
- Updated dependencies [e0143b0]
|
|
19
|
+
- Updated dependencies [934100c]
|
|
20
|
+
- Updated dependencies [892af4d]
|
|
21
|
+
- Updated dependencies [3bf70f8]
|
|
22
|
+
- Updated dependencies [89aff56]
|
|
23
|
+
- Updated dependencies [41465fd]
|
|
24
|
+
- Updated dependencies [9754014]
|
|
25
|
+
- Updated dependencies [4bb73b0]
|
|
26
|
+
- Updated dependencies [2e44144]
|
|
27
|
+
- @ai-sdk/provider@4.0.36
|
|
28
|
+
- @ai-sdk/harness@1.0.174
|
|
29
|
+
- @ai-sdk/provider-utils@5.0.75
|
|
30
|
+
|
|
3
31
|
## 1.0.175
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/dist/bridge/index.mjs
CHANGED
|
@@ -200,6 +200,12 @@ const WS_OPEN = 1;
|
|
|
200
200
|
async function runBridge(options) {
|
|
201
201
|
const { bridgeType, bridgeStateDir, onStart, onStop, onDestroy } = options;
|
|
202
202
|
const teardownGraceMs = options.turnTeardownGraceMs ?? 1e4;
|
|
203
|
+
const hostDisconnectTimeoutMs = options.hostDisconnectTimeoutMs != null && Number.isFinite(options.hostDisconnectTimeoutMs) && options.hostDisconnectTimeoutMs > 0 ? Math.min(options.hostDisconnectTimeoutMs, 2147483647) : void 0;
|
|
204
|
+
let hostDisconnectTimer;
|
|
205
|
+
const clearHostDisconnectTimer = () => {
|
|
206
|
+
clearTimeout(hostDisconnectTimer);
|
|
207
|
+
hostDisconnectTimer = void 0;
|
|
208
|
+
};
|
|
203
209
|
const expectedToken = options.token ?? env.BRIDGE_CHANNEL_TOKEN ?? "";
|
|
204
210
|
const bridgeWsPort = options.port ?? parseInt(env.BRIDGE_WS_PORT ?? "0", 10);
|
|
205
211
|
const bridgeMetaPath = `${bridgeStateDir}/bridge-meta.json`;
|
|
@@ -221,6 +227,7 @@ async function runBridge(options) {
|
|
|
221
227
|
* between turns. A new `start` fences on this so turns never overlap.
|
|
222
228
|
*/
|
|
223
229
|
let activeTurn;
|
|
230
|
+
let lastStartId;
|
|
224
231
|
let debugConfig;
|
|
225
232
|
let consoleCaptureInstalled = false;
|
|
226
233
|
const envDebugEnabled = ENV_TRUTHY.has((env.HARNESS_DEBUG ?? "").toLowerCase());
|
|
@@ -364,6 +371,11 @@ async function runBridge(options) {
|
|
|
364
371
|
const handleInbound = async (msg, ws) => {
|
|
365
372
|
switch (msg.type) {
|
|
366
373
|
case "start": {
|
|
374
|
+
const startId = msg.startId;
|
|
375
|
+
if (startId != null) {
|
|
376
|
+
if (startId === lastStartId) return;
|
|
377
|
+
lastStartId = startId;
|
|
378
|
+
}
|
|
367
379
|
for (;;) {
|
|
368
380
|
const pendingTurn = activeTurn;
|
|
369
381
|
if (pendingTurn == null) break;
|
|
@@ -381,6 +393,7 @@ async function runBridge(options) {
|
|
|
381
393
|
const thisTurn = new Promise((resolve) => turnFinished = resolve);
|
|
382
394
|
activeTurn = thisTurn;
|
|
383
395
|
activeSocket = ws;
|
|
396
|
+
clearHostDisconnectTimer();
|
|
384
397
|
const firstTurn = isFirstTurn;
|
|
385
398
|
isFirstTurn = false;
|
|
386
399
|
eventLog = [];
|
|
@@ -447,6 +460,7 @@ async function runBridge(options) {
|
|
|
447
460
|
activeTurn = void 0;
|
|
448
461
|
currentTurnState = "waiting";
|
|
449
462
|
writeBridgeMeta("waiting");
|
|
463
|
+
clearHostDisconnectTimer();
|
|
450
464
|
}
|
|
451
465
|
turnFinished();
|
|
452
466
|
}
|
|
@@ -513,6 +527,7 @@ async function runBridge(options) {
|
|
|
513
527
|
return;
|
|
514
528
|
case "resume":
|
|
515
529
|
activeSocket = ws;
|
|
530
|
+
clearHostDisconnectTimer();
|
|
516
531
|
replay(ws, msg.lastSeenEventId);
|
|
517
532
|
return;
|
|
518
533
|
case "destroy":
|
|
@@ -581,7 +596,10 @@ async function runBridge(options) {
|
|
|
581
596
|
type: "bridge-hello",
|
|
582
597
|
state: currentTurnState,
|
|
583
598
|
lastSeq: seqCounter,
|
|
584
|
-
capabilities: {
|
|
599
|
+
capabilities: {
|
|
600
|
+
idempotentStart: true,
|
|
601
|
+
experimental_userMessageResponses: true
|
|
602
|
+
}
|
|
585
603
|
});
|
|
586
604
|
ws.on("message", (raw) => {
|
|
587
605
|
let parsed;
|
|
@@ -597,8 +615,18 @@ async function runBridge(options) {
|
|
|
597
615
|
}
|
|
598
616
|
handleInbound(parsed, ws);
|
|
599
617
|
});
|
|
600
|
-
ws.on("close", () => {
|
|
601
|
-
if (activeSocket === ws)
|
|
618
|
+
ws.on("close", (_code, reason) => {
|
|
619
|
+
if (activeSocket === ws) {
|
|
620
|
+
activeSocket = void 0;
|
|
621
|
+
if (hostDisconnectTimeoutMs != null && activeTurn != null && reason.toString() !== "suspended") {
|
|
622
|
+
clearHostDisconnectTimer();
|
|
623
|
+
hostDisconnectTimer = setTimeout(() => {
|
|
624
|
+
hostDisconnectTimer = void 0;
|
|
625
|
+
if (activeSocket == null) turnAbort?.abort();
|
|
626
|
+
}, hostDisconnectTimeoutMs);
|
|
627
|
+
hostDisconnectTimer.unref?.();
|
|
628
|
+
}
|
|
629
|
+
}
|
|
602
630
|
});
|
|
603
631
|
ws.on("error", () => {});
|
|
604
632
|
});
|
|
@@ -2120,6 +2148,7 @@ const appServer = createCodexAppServerRuntime();
|
|
|
2120
2148
|
await runBridge({
|
|
2121
2149
|
bridgeType: "codex",
|
|
2122
2150
|
bridgeStateDir,
|
|
2151
|
+
...args.hostDisconnectTimeoutMs !== void 0 ? { hostDisconnectTimeoutMs: args.hostDisconnectTimeoutMs } : {},
|
|
2123
2152
|
onStart: runTurn,
|
|
2124
2153
|
onStop: async () => {
|
|
2125
2154
|
const data = threadState.id ? { threadId: threadState.id } : {};
|
|
@@ -2172,17 +2201,16 @@ async function runTurn(start, turn) {
|
|
|
2172
2201
|
});
|
|
2173
2202
|
}
|
|
2174
2203
|
function resolveCodexRuntime({ start }) {
|
|
2175
|
-
const codexConfig = {
|
|
2176
|
-
...start.codexConfig,
|
|
2177
|
-
developer_instructions: [start.instructions, "Only respond with your `final` message once you have fully addressed the user request."].filter((instruction) => Boolean(instruction)).join("\n\n"),
|
|
2178
|
-
model_reasoning_summary: "detailed"
|
|
2179
|
-
};
|
|
2180
2204
|
const gatewayBaseUrl = env.AI_GATEWAY_BASE_URL;
|
|
2181
2205
|
const hasGatewayAuth = Boolean(env.AI_GATEWAY_API_KEY || gatewayBaseUrl);
|
|
2182
2206
|
if (hasGatewayAuth && !gatewayBaseUrl) throw new Error("AI Gateway auth was selected but AI_GATEWAY_BASE_URL is missing from the Codex bridge environment.");
|
|
2183
2207
|
const apiBaseUrl = hasGatewayAuth ? gatewayBaseUrl : env.OPENAI_BASE_URL ?? (env.CODEX_API_KEY != null || start.headers != null ? "https://api.openai.com/v1" : void 0);
|
|
2184
2208
|
const codexModel = start.model && hasGatewayAuth && !start.model.includes("/") ? `openai/${start.model}` : start.model;
|
|
2185
|
-
|
|
2209
|
+
const codexConfig = {
|
|
2210
|
+
model_reasoning_summary: "detailed",
|
|
2211
|
+
...start.codexConfig,
|
|
2212
|
+
developer_instructions: [start.instructions, "Only respond with your `final` message once you have fully addressed the user request."].filter((instruction) => Boolean(instruction)).join("\n\n")
|
|
2213
|
+
};
|
|
2186
2214
|
if (apiBaseUrl) {
|
|
2187
2215
|
codexConfig.preferred_auth_method = "apikey";
|
|
2188
2216
|
codexConfig.model_provider = "agent_bridge_openai";
|
|
@@ -2212,6 +2240,7 @@ function parseArgs(args) {
|
|
|
2212
2240
|
const out = {};
|
|
2213
2241
|
for (let i = 0; i < args.length; i++) if (args[i] === "--workdir" && i + 1 < args.length) out.workdir = args[++i];
|
|
2214
2242
|
else if (args[i] === "--bridge-state-dir" && i + 1 < args.length) out.bridgeStateDir = args[++i];
|
|
2243
|
+
else if (args[i] === "--host-disconnect-timeout-ms" && i + 1 < args.length) out.hostDisconnectTimeoutMs = Number(args[++i]);
|
|
2215
2244
|
return out;
|
|
2216
2245
|
}
|
|
2217
2246
|
function emitFatal(message) {
|