agentbox-sdk 0.1.601 → 0.1.603
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/agents/index.d.ts +2 -2
- package/dist/agents/index.js +1 -1
- package/dist/{chunk-ZITMGTVR.js → chunk-JO6LTAAD.js} +218 -67
- package/dist/events/index.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{types-ChkpU7Lf.d.ts → types-B_oR4A4a.d.ts} +11 -0
- package/package.json +1 -1
package/dist/agents/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { o as AgentProviderName, h as AgentOptions, t as AgentRunConfig, s as AgentRun, r as AgentResult, al as RawAgentEvent, b as AgentAttachRequest, B as AttachedRun, as as SetupLayout, ay as UserContent } from '../types-
|
|
2
|
-
export { a as AgentApprovalMode, c as AgentCommandConfig, d as AgentCostData, e as AgentExecutionRequest, f as AgentLocalMcpConfig, g as AgentMcpConfig, i as AgentOptionsBase, j as AgentOptionsMap, k as AgentPermissionDecision, l as AgentPermissionKind, m as AgentPermissionResponse, n as AgentProviderAdapter, p as AgentReasoningEffort, q as AgentRemoteMcpConfig, u as AgentRunSink, v as AgentSetupRequest, w as AgentSkillConfig, x as AgentSubAgentConfig, y as AgentUserAnswer, z as AgentUserQuestion, E as ClaudeCodeAgentOptions, F as ClaudeCodeHookConfig, G as ClaudeCodeHookEvent, H as ClaudeCodeHookHandler, I as ClaudeCodeHookMatcherGroup, J as ClaudeCodeHooksConfig, K as ClaudeCodeProviderOptions, L as CodexAgentOptions, M as CodexCommandHook, N as CodexHookEvent, O as CodexHookMatcherGroup, P as CodexHooksConfig, Q as CodexModelProviderConfig, R as CodexProviderOptions, S as CodexSkillEntry, T as DataContent, U as EmbeddedSkillConfig, V as FilePart, W as HarnessCommandDescriptor, X as HarnessCommandInvocation, Y as HarnessCommandSource, _ as ImagePart, $ as MAX_HARNESS_COMMANDS, a0 as MAX_HARNESS_COMMAND_ARGUMENT_HINT, a1 as MAX_HARNESS_COMMAND_DESCRIPTION, a2 as MAX_HARNESS_COMMAND_NAME, a6 as NativeParkBackgroundWork, ab as OpenCodeAgentOptions, ac as OpenCodeCommandEntry, ad as OpenCodePluginConfig, ae as OpenCodePluginEvent, af as OpenCodePluginHookConfig, ag as OpenCodeProviderOptions, ah as OpenCodeSkillEntry, ai as OpenRouterPlugin, an as RepoSkillConfig, au as TextPart, az as UserContentPart, aA as builtinHarnessCommands, aB as claudeHarnessCommands, aC as codexHarnessCommands, aD as codexSkillMention, aG as openCodeHarnessCommands, aH as parseHarnessCommandInvocation, aI as skillDirective } from '../types-
|
|
1
|
+
import { o as AgentProviderName, h as AgentOptions, t as AgentRunConfig, s as AgentRun, r as AgentResult, al as RawAgentEvent, b as AgentAttachRequest, B as AttachedRun, as as SetupLayout, ay as UserContent } from '../types-B_oR4A4a.js';
|
|
2
|
+
export { a as AgentApprovalMode, c as AgentCommandConfig, d as AgentCostData, e as AgentExecutionRequest, f as AgentLocalMcpConfig, g as AgentMcpConfig, i as AgentOptionsBase, j as AgentOptionsMap, k as AgentPermissionDecision, l as AgentPermissionKind, m as AgentPermissionResponse, n as AgentProviderAdapter, p as AgentReasoningEffort, q as AgentRemoteMcpConfig, u as AgentRunSink, v as AgentSetupRequest, w as AgentSkillConfig, x as AgentSubAgentConfig, y as AgentUserAnswer, z as AgentUserQuestion, E as ClaudeCodeAgentOptions, F as ClaudeCodeHookConfig, G as ClaudeCodeHookEvent, H as ClaudeCodeHookHandler, I as ClaudeCodeHookMatcherGroup, J as ClaudeCodeHooksConfig, K as ClaudeCodeProviderOptions, L as CodexAgentOptions, M as CodexCommandHook, N as CodexHookEvent, O as CodexHookMatcherGroup, P as CodexHooksConfig, Q as CodexModelProviderConfig, R as CodexProviderOptions, S as CodexSkillEntry, T as DataContent, U as EmbeddedSkillConfig, V as FilePart, W as HarnessCommandDescriptor, X as HarnessCommandInvocation, Y as HarnessCommandSource, _ as ImagePart, $ as MAX_HARNESS_COMMANDS, a0 as MAX_HARNESS_COMMAND_ARGUMENT_HINT, a1 as MAX_HARNESS_COMMAND_DESCRIPTION, a2 as MAX_HARNESS_COMMAND_NAME, a6 as NativeParkBackgroundWork, ab as OpenCodeAgentOptions, ac as OpenCodeCommandEntry, ad as OpenCodePluginConfig, ae as OpenCodePluginEvent, af as OpenCodePluginHookConfig, ag as OpenCodeProviderOptions, ah as OpenCodeSkillEntry, ai as OpenRouterPlugin, an as RepoSkillConfig, au as TextPart, az as UserContentPart, aA as builtinHarnessCommands, aB as claudeHarnessCommands, aC as codexHarnessCommands, aD as codexSkillMention, aG as openCodeHarnessCommands, aH as parseHarnessCommandInvocation, aI as skillDirective } from '../types-B_oR4A4a.js';
|
|
3
3
|
import { S as Sandbox } from '../Sandbox-DcKAU-E3.js';
|
|
4
4
|
export { AgentProvider } from '../enums.js';
|
|
5
5
|
import 'e2b';
|
package/dist/agents/index.js
CHANGED
|
@@ -2193,6 +2193,11 @@ function asArray(value) {
|
|
|
2193
2193
|
}
|
|
2194
2194
|
var SCHEDULE_TOOLS = /* @__PURE__ */ new Set(["CronCreate", "ScheduleWakeup"]);
|
|
2195
2195
|
var DONE_STATUSES = /* @__PURE__ */ new Set(["completed", "failed", "killed"]);
|
|
2196
|
+
var SUBAGENT_TASK_TYPES = /* @__PURE__ */ new Set(["local_agent", "local_workflow", "subagent"]);
|
|
2197
|
+
var SUBAGENT_RESULT_GRACE_MS = 6e4;
|
|
2198
|
+
function holdsBackgroundCeiling(tasks, exemptSubagents) {
|
|
2199
|
+
return exemptSubagents === true && tasks.some((task) => SUBAGENT_TASK_TYPES.has(task.type));
|
|
2200
|
+
}
|
|
2196
2201
|
var BackgroundTaskTracker = class {
|
|
2197
2202
|
tasks = /* @__PURE__ */ new Map();
|
|
2198
2203
|
wakeups = /* @__PURE__ */ new Map();
|
|
@@ -2371,21 +2376,42 @@ function withTimeout(promise, ms) {
|
|
|
2371
2376
|
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
2372
2377
|
}
|
|
2373
2378
|
var BackgroundWait = class {
|
|
2374
|
-
constructor(graceMs, ceilingMs) {
|
|
2379
|
+
constructor(graceMs, ceilingMs, held = false) {
|
|
2375
2380
|
this.graceMs = graceMs;
|
|
2381
|
+
this.ceilingMs = ceilingMs;
|
|
2376
2382
|
this.expired = new Promise((resolve) => {
|
|
2377
2383
|
this.expire = resolve;
|
|
2378
2384
|
});
|
|
2379
|
-
if (
|
|
2380
|
-
|
|
2381
|
-
}
|
|
2385
|
+
if (held) this.heldSince = this.startedAt;
|
|
2386
|
+
else this.armCeiling();
|
|
2382
2387
|
}
|
|
2383
2388
|
graceMs;
|
|
2389
|
+
ceilingMs;
|
|
2384
2390
|
expired;
|
|
2385
2391
|
expire;
|
|
2386
2392
|
grace;
|
|
2387
2393
|
ceiling;
|
|
2388
2394
|
startedAt = Date.now();
|
|
2395
|
+
heldMs = 0;
|
|
2396
|
+
heldSince;
|
|
2397
|
+
/** Stop the ceiling while a subagent is live; resume it with what is left once none is. */
|
|
2398
|
+
hold(held) {
|
|
2399
|
+
if (held === (this.heldSince !== void 0)) return;
|
|
2400
|
+
if (held) {
|
|
2401
|
+
clearTimeout(this.ceiling);
|
|
2402
|
+
this.ceiling = void 0;
|
|
2403
|
+
this.heldSince = Date.now();
|
|
2404
|
+
return;
|
|
2405
|
+
}
|
|
2406
|
+
this.heldMs += Date.now() - this.heldSince;
|
|
2407
|
+
this.heldSince = void 0;
|
|
2408
|
+
this.armCeiling(SUBAGENT_RESULT_GRACE_MS);
|
|
2409
|
+
}
|
|
2410
|
+
armCeiling(floorMs = 0) {
|
|
2411
|
+
if (!Number.isFinite(this.ceilingMs)) return;
|
|
2412
|
+
const leftMs = Math.max(floorMs, this.ceilingMs - this.elapsedMs());
|
|
2413
|
+
this.ceiling = setTimeout(() => this.expire("ceiling"), Math.min(leftMs, MAX_TIMER_MS));
|
|
2414
|
+
}
|
|
2389
2415
|
/** Arm the grace timer while nothing is live; disarm it once a task appears. */
|
|
2390
2416
|
setIdle(idle) {
|
|
2391
2417
|
if (!idle) {
|
|
@@ -2399,8 +2425,11 @@ var BackgroundWait = class {
|
|
|
2399
2425
|
finish() {
|
|
2400
2426
|
this.expire("finished");
|
|
2401
2427
|
}
|
|
2428
|
+
/** Time counted against the budget: held time excluded. */
|
|
2402
2429
|
elapsedMs() {
|
|
2403
|
-
|
|
2430
|
+
const now = Date.now();
|
|
2431
|
+
const held = this.heldMs + (this.heldSince === void 0 ? 0 : now - this.heldSince);
|
|
2432
|
+
return now - this.startedAt - held;
|
|
2404
2433
|
}
|
|
2405
2434
|
clear() {
|
|
2406
2435
|
clearTimeout(this.grace);
|
|
@@ -2453,9 +2482,14 @@ var NativeClaudeSession = class {
|
|
|
2453
2482
|
iterator;
|
|
2454
2483
|
handlers;
|
|
2455
2484
|
parked;
|
|
2456
|
-
//
|
|
2457
|
-
//
|
|
2458
|
-
|
|
2485
|
+
// The background budget, carried across parks so a CLI that is adopted and
|
|
2486
|
+
// parked again cannot extend its own ceiling: what was left of it at
|
|
2487
|
+
// `budgetSince`, and it runs from then on. Unset while a subagent holds it.
|
|
2488
|
+
budgetLeftMs = Infinity;
|
|
2489
|
+
budgetSince = Date.now();
|
|
2490
|
+
exemptSubagents = false;
|
|
2491
|
+
// What is live in the CLI, from every message it produces.
|
|
2492
|
+
tasks = new BackgroundTaskTracker();
|
|
2459
2493
|
buffer = [];
|
|
2460
2494
|
bufferedBytes = 0;
|
|
2461
2495
|
bufferedResults = 0;
|
|
@@ -2503,30 +2537,59 @@ var NativeClaudeSession = class {
|
|
|
2503
2537
|
* Keep the CLI after the attached run settles. `inflight` is a read that
|
|
2504
2538
|
* run started but never consumed; its message is buffered, not lost.
|
|
2505
2539
|
*/
|
|
2506
|
-
park(tasks, ttlMs, parking, inflight) {
|
|
2540
|
+
park(tasks, ttlMs, parking, inflight, options = {}) {
|
|
2507
2541
|
if (this.ending || !this.iterator) return false;
|
|
2508
2542
|
this.handlers = void 0;
|
|
2509
|
-
this.
|
|
2510
|
-
this.
|
|
2511
|
-
Number.isFinite(ttlMs) ?
|
|
2543
|
+
this.budgetLeftMs = Math.min(
|
|
2544
|
+
this.budgetLeft(),
|
|
2545
|
+
Number.isFinite(ttlMs) ? Math.max(0, ttlMs) : Infinity
|
|
2512
2546
|
);
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
() => {
|
|
2517
|
-
if (this.parked !== parked) return;
|
|
2518
|
-
debugClaude("\u2605 parked CLI ran out of background budget; ending it");
|
|
2519
|
-
void this.end();
|
|
2520
|
-
},
|
|
2521
|
-
Math.min(Math.max(0, this.parkDeadline - Date.now()), 2147483647)
|
|
2522
|
-
);
|
|
2523
|
-
parked.timer.unref?.();
|
|
2524
|
-
}
|
|
2525
|
-
this.parked = parked;
|
|
2547
|
+
if (this.budgetSince !== void 0) this.budgetSince = Date.now();
|
|
2548
|
+
this.exemptSubagents = options.exemptSubagents === true;
|
|
2549
|
+
this.parked = { tasks, parking, waking: false, wokeAt: 0 };
|
|
2526
2550
|
parkedSessions.set(this.sessionId, this);
|
|
2551
|
+
this.updateBudget();
|
|
2552
|
+
this.armBudget();
|
|
2527
2553
|
void this.pump(inflight);
|
|
2528
2554
|
return true;
|
|
2529
2555
|
}
|
|
2556
|
+
budgetLeft() {
|
|
2557
|
+
return this.budgetSince === void 0 ? this.budgetLeftMs : this.budgetLeftMs - (Date.now() - this.budgetSince);
|
|
2558
|
+
}
|
|
2559
|
+
/** Hold the budget while an exempt subagent is live. True when that changed. */
|
|
2560
|
+
updateBudget() {
|
|
2561
|
+
const held = holdsBackgroundCeiling(
|
|
2562
|
+
this.tasks.liveTasks(),
|
|
2563
|
+
this.exemptSubagents
|
|
2564
|
+
);
|
|
2565
|
+
if (held === (this.budgetSince === void 0)) return false;
|
|
2566
|
+
if (held) {
|
|
2567
|
+
this.budgetLeftMs = this.budgetLeft();
|
|
2568
|
+
this.budgetSince = void 0;
|
|
2569
|
+
} else {
|
|
2570
|
+
this.budgetLeftMs = Math.max(this.budgetLeftMs, SUBAGENT_RESULT_GRACE_MS);
|
|
2571
|
+
this.budgetSince = Date.now();
|
|
2572
|
+
}
|
|
2573
|
+
return true;
|
|
2574
|
+
}
|
|
2575
|
+
/** While parked, end the CLI once a running budget is spent. */
|
|
2576
|
+
armBudget() {
|
|
2577
|
+
const parked = this.parked;
|
|
2578
|
+
if (!parked) return;
|
|
2579
|
+
clearTimeout(parked.timer);
|
|
2580
|
+
parked.timer = void 0;
|
|
2581
|
+
if (this.budgetSince === void 0 || !Number.isFinite(this.budgetLeftMs))
|
|
2582
|
+
return;
|
|
2583
|
+
parked.timer = setTimeout(
|
|
2584
|
+
() => {
|
|
2585
|
+
if (this.parked !== parked) return;
|
|
2586
|
+
debugClaude("\u2605 parked CLI ran out of background budget; ending it");
|
|
2587
|
+
void this.end();
|
|
2588
|
+
},
|
|
2589
|
+
Math.min(Math.max(0, this.budgetLeft()), MAX_TIMER_MS)
|
|
2590
|
+
);
|
|
2591
|
+
parked.timer.unref?.();
|
|
2592
|
+
}
|
|
2530
2593
|
/**
|
|
2531
2594
|
* A later run takes the parked CLI over: it learns what was live and how
|
|
2532
2595
|
* many results precede its own turn, then reads what was buffered. An
|
|
@@ -2540,7 +2603,8 @@ var NativeClaudeSession = class {
|
|
|
2540
2603
|
clearTimeout(parked.timer);
|
|
2541
2604
|
this.parked = void 0;
|
|
2542
2605
|
parkedSessions.delete(this.sessionId);
|
|
2543
|
-
const
|
|
2606
|
+
const left = this.budgetLeft();
|
|
2607
|
+
const budgetLeftMs = Number.isFinite(left) ? Math.max(0, left) : null;
|
|
2544
2608
|
const preamble = [
|
|
2545
2609
|
{ _parked: { tasks: parked.tasks, turns, budgetLeftMs } },
|
|
2546
2610
|
...this.buffer
|
|
@@ -2575,6 +2639,8 @@ var NativeClaudeSession = class {
|
|
|
2575
2639
|
const { started, ended } = turnEdges(result.value);
|
|
2576
2640
|
if (started) this.turnActive = true;
|
|
2577
2641
|
if (ended) this.turnActive = false;
|
|
2642
|
+
this.tasks.ingest(result.value);
|
|
2643
|
+
if (this.updateBudget()) this.armBudget();
|
|
2578
2644
|
}
|
|
2579
2645
|
return result;
|
|
2580
2646
|
});
|
|
@@ -4045,6 +4111,10 @@ async function consumeClaudeMessages(request, sink, messages, executeStartedAt,
|
|
|
4045
4111
|
const timeoutMs = resolveBackgroundTaskTimeoutMs(
|
|
4046
4112
|
request.options.backgroundTaskTimeoutMs
|
|
4047
4113
|
);
|
|
4114
|
+
const holdsCeiling = (live) => holdsBackgroundCeiling(
|
|
4115
|
+
live,
|
|
4116
|
+
request.options.exemptSubagentsFromBackgroundTimeout
|
|
4117
|
+
);
|
|
4048
4118
|
const graceMs = wait.graceMs ?? BACKGROUND_TASK_GRACE_MS;
|
|
4049
4119
|
let pendingWait;
|
|
4050
4120
|
let waitedMs = 0;
|
|
@@ -4077,8 +4147,9 @@ async function consumeClaudeMessages(request, sink, messages, executeStartedAt,
|
|
|
4077
4147
|
const tryPark = async (inflight) => {
|
|
4078
4148
|
const live = tracker.liveTasks();
|
|
4079
4149
|
const ttlMs = budgetLeftMs();
|
|
4080
|
-
|
|
4081
|
-
|
|
4150
|
+
const held = holdsCeiling(live);
|
|
4151
|
+
if (!wait.park || live.length === 0 || isAborted()) return false;
|
|
4152
|
+
if (held ? !wait.parkHoldsSubagents : ttlMs <= 0) return false;
|
|
4082
4153
|
parked = await wait.park(live, ttlMs, inflight).catch(() => false);
|
|
4083
4154
|
if (parked)
|
|
4084
4155
|
debugClaude(
|
|
@@ -4174,6 +4245,7 @@ async function consumeClaudeMessages(request, sink, messages, executeStartedAt,
|
|
|
4174
4245
|
endWait();
|
|
4175
4246
|
}
|
|
4176
4247
|
emitTasks(tracker.liveTasks(), pendingWait !== void 0);
|
|
4248
|
+
pendingWait?.hold(holdsCeiling(tracker.liveTasks()));
|
|
4177
4249
|
const sessionState = message.type === "system" && message.subtype === "session_state_changed" ? message.state : void 0;
|
|
4178
4250
|
if (sessionState) sawSessionState = true;
|
|
4179
4251
|
pendingWait?.setIdle(
|
|
@@ -4342,7 +4414,11 @@ async function consumeClaudeMessages(request, sink, messages, executeStartedAt,
|
|
|
4342
4414
|
);
|
|
4343
4415
|
endWait();
|
|
4344
4416
|
pendingWait = finishWait.watch(
|
|
4345
|
-
new BackgroundWait(
|
|
4417
|
+
new BackgroundWait(
|
|
4418
|
+
graceMs,
|
|
4419
|
+
Math.max(0, timeoutMs - waitedMs),
|
|
4420
|
+
holdsCeiling(live)
|
|
4421
|
+
)
|
|
4346
4422
|
);
|
|
4347
4423
|
pendingWait.setIdle(!sawSessionState && live.length === 0);
|
|
4348
4424
|
emitTasks(live, true);
|
|
@@ -4667,7 +4743,10 @@ async function executeNativeClaude(request, sink, wait = {}) {
|
|
|
4667
4743
|
);
|
|
4668
4744
|
},
|
|
4669
4745
|
...parking && owned ? {
|
|
4670
|
-
park: async (tasks, ttlMs, inflight) => parked = owned.park(tasks, ttlMs, parking, inflight
|
|
4746
|
+
park: async (tasks, ttlMs, inflight) => parked = owned.park(tasks, ttlMs, parking, inflight, {
|
|
4747
|
+
exemptSubagents: request.options.exemptSubagentsFromBackgroundTimeout
|
|
4748
|
+
}),
|
|
4749
|
+
parkHoldsSubagents: true,
|
|
4671
4750
|
// The CLI lives on in the session; nothing to let go of.
|
|
4672
4751
|
detach: async () => void 0
|
|
4673
4752
|
} : {}
|
|
@@ -4912,6 +4991,18 @@ function codexConfigDir(options) {
|
|
|
4912
4991
|
var REMOTE_CODEX_APP_SERVER_PORT = 43181;
|
|
4913
4992
|
var REMOTE_CODEX_APP_SERVER_ID = "shared-app-server";
|
|
4914
4993
|
var CODEX_APP_SERVER_TOKEN_FILENAME = "codex-app-server-token";
|
|
4994
|
+
var MAX_CODEX_RECONNECTS = 3;
|
|
4995
|
+
var CODEX_RECONNECT_TIMEOUT_MS = 3e4;
|
|
4996
|
+
function missedCodexNotifications(thread, threadId, turnId, seenItemIds) {
|
|
4997
|
+
const active = thread.status?.type === "active";
|
|
4998
|
+
const turn = turnId ? thread.turns?.find((candidate) => candidate.id === turnId) : void 0;
|
|
4999
|
+
if (!turn) return active ? [] : void 0;
|
|
5000
|
+
const ended = turn.status === "completed" || turn.status === "failed";
|
|
5001
|
+
if (!ended && (turn.status !== "inProgress" || !active)) return void 0;
|
|
5002
|
+
const missed = (turn.items ?? []).filter((item) => typeof item.id === "string" && !seenItemIds.has(item.id) && item.status !== "inProgress").map((item) => ({ method: "item/completed", params: { threadId, turnId, item } }));
|
|
5003
|
+
if (ended) missed.push({ method: "turn/completed", params: { threadId, turn: { ...turn, items: [] } } });
|
|
5004
|
+
return missed;
|
|
5005
|
+
}
|
|
4915
5006
|
function defaultRemoteCodexTokenPath() {
|
|
4916
5007
|
return path10.posix.join(
|
|
4917
5008
|
agentboxRoot(AgentProvider.Codex, true),
|
|
@@ -5742,25 +5833,28 @@ async function createRuntime(request, inputParts) {
|
|
|
5742
5833
|
() => sandbox.getPreviewLink(REMOTE_CODEX_APP_SERVER_PORT)
|
|
5743
5834
|
);
|
|
5744
5835
|
const token = await getCodexAppServerToken(sandbox);
|
|
5745
|
-
const
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5751
|
-
|
|
5752
|
-
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5760
|
-
|
|
5761
|
-
|
|
5762
|
-
|
|
5836
|
+
const connect = async () => {
|
|
5837
|
+
const transport = await connectRemoteCodexAppServer(
|
|
5838
|
+
toRemoteCodexWebSocketUrl(previewUrl),
|
|
5839
|
+
withCodexAppServerAuthHeaders(sandbox.previewHeaders, token)
|
|
5840
|
+
);
|
|
5841
|
+
return {
|
|
5842
|
+
source: transport.source,
|
|
5843
|
+
writeLine: transport.send,
|
|
5844
|
+
cleanup: async () => {
|
|
5845
|
+
await transport.close().catch(() => void 0);
|
|
5846
|
+
},
|
|
5847
|
+
raw: {
|
|
5848
|
+
transport: transport.raw,
|
|
5849
|
+
previewUrl,
|
|
5850
|
+
port: REMOTE_CODEX_APP_SERVER_PORT,
|
|
5851
|
+
codexDir
|
|
5852
|
+
}
|
|
5853
|
+
};
|
|
5763
5854
|
};
|
|
5855
|
+
const connection = await connect();
|
|
5856
|
+
debugCodex("\u2605 codex transport established");
|
|
5857
|
+
return { ...connection, reconnect: connect, inputItems };
|
|
5764
5858
|
}
|
|
5765
5859
|
const binary = options.provider?.binary ?? "codex";
|
|
5766
5860
|
if (options.sandbox) {
|
|
@@ -5927,7 +6021,7 @@ var CodexAgentAdapter = class {
|
|
|
5927
6021
|
runId: request.runId
|
|
5928
6022
|
})
|
|
5929
6023
|
);
|
|
5930
|
-
|
|
6024
|
+
let client = runtime.client ?? new JsonRpcLineClient(
|
|
5931
6025
|
runtime.source,
|
|
5932
6026
|
runtime.writeLine
|
|
5933
6027
|
);
|
|
@@ -5985,6 +6079,8 @@ var CodexAgentAdapter = class {
|
|
|
5985
6079
|
const pendingFileChanges = /* @__PURE__ */ new Map();
|
|
5986
6080
|
const fileItemKey = (params, itemId) => typeof params?.threadId === "string" && typeof params.turnId === "string" && typeof itemId === "string" ? `${params.threadId}:${params.turnId}:${itemId}` : void 0;
|
|
5987
6081
|
let streamedText = "";
|
|
6082
|
+
const completedItemIds = /* @__PURE__ */ new Set();
|
|
6083
|
+
const replayedItemIds = /* @__PURE__ */ new Set();
|
|
5988
6084
|
const timeoutMs = resolveBackgroundTaskTimeoutMs(request.options.backgroundTaskTimeoutMs);
|
|
5989
6085
|
const isRootThread = (params) => !params?.threadId || params.threadId === rootThreadId;
|
|
5990
6086
|
let goalStatus = request.run.goal ? "active" : void 0;
|
|
@@ -6021,29 +6117,82 @@ var CodexAgentAdapter = class {
|
|
|
6021
6117
|
};
|
|
6022
6118
|
void (async () => {
|
|
6023
6119
|
let firstClientMessageLogged = false;
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6120
|
+
let iterator = client.messages()[Symbol.asyncIterator]();
|
|
6121
|
+
let next;
|
|
6122
|
+
const replay = [];
|
|
6123
|
+
let reconnects = 0;
|
|
6124
|
+
const reconnect = async (cause) => {
|
|
6125
|
+
if (!runtime.reconnect || abortInvoked || !rootThreadId || reconnects >= MAX_CODEX_RECONNECTS) return false;
|
|
6126
|
+
reconnects++;
|
|
6127
|
+
debugCodex("\u2605 transport lost (%o); reconnecting (attempt %d)", cause, reconnects);
|
|
6128
|
+
let connection;
|
|
6027
6129
|
try {
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6130
|
+
connection = await runtime.reconnect();
|
|
6131
|
+
const nextClient = new JsonRpcLineClient(connection.source, connection.writeLine);
|
|
6132
|
+
const resumed = await withTimeout((async () => {
|
|
6133
|
+
await initializeCodexClient(nextClient);
|
|
6134
|
+
return nextClient.request("thread/resume", { threadId: rootThreadId });
|
|
6135
|
+
})(), CODEX_RECONNECT_TIMEOUT_MS);
|
|
6136
|
+
const missed = resumed?.thread && missedCodexNotifications(resumed.thread, rootThreadId, turnId, completedItemIds);
|
|
6137
|
+
if (!missed || abortInvoked) throw new Error("Codex thread could not be rejoined.");
|
|
6138
|
+
const previous = runtime;
|
|
6139
|
+
runtime = { ...runtime, ...connection };
|
|
6140
|
+
await previous.cleanup().catch(() => void 0);
|
|
6141
|
+
client = nextClient;
|
|
6142
|
+
iterator = client.messages()[Symbol.asyncIterator]();
|
|
6143
|
+
sink.setRaw(runtime.raw);
|
|
6144
|
+
replay.push(...missed);
|
|
6145
|
+
debugCodex("\u2605 rejoined thread %s; replaying %d notification(s)", rootThreadId, missed.length);
|
|
6146
|
+
return true;
|
|
6032
6147
|
} catch (error) {
|
|
6033
|
-
|
|
6034
|
-
|
|
6148
|
+
debugCodex("\u2605 reconnect failed: %o", error);
|
|
6149
|
+
await connection?.cleanup().catch(() => void 0);
|
|
6150
|
+
return false;
|
|
6035
6151
|
}
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6152
|
+
};
|
|
6153
|
+
for (; ; ) {
|
|
6154
|
+
let step;
|
|
6155
|
+
const replayed = replay.shift();
|
|
6156
|
+
if (replayed) {
|
|
6157
|
+
step = { result: { done: false, value: replayed } };
|
|
6158
|
+
} else {
|
|
6159
|
+
const read = next ??= iterator.next();
|
|
6160
|
+
try {
|
|
6161
|
+
step = pendingWait ? await Promise.race([
|
|
6162
|
+
read.then((result) => ({ result })),
|
|
6163
|
+
pendingWait.expired.then((reason) => ({ reason }))
|
|
6164
|
+
]) : { result: await read };
|
|
6165
|
+
} catch (error) {
|
|
6166
|
+
next = void 0;
|
|
6167
|
+
if (settleOnFailure(error)) return;
|
|
6168
|
+
if (await reconnect(error)) continue;
|
|
6169
|
+
throw error;
|
|
6041
6170
|
}
|
|
6042
|
-
|
|
6043
|
-
|
|
6171
|
+
if ("reason" in step) {
|
|
6172
|
+
if (!abortInvoked) {
|
|
6173
|
+
debugCodex("\u2605 native goal wait over (%s)", step.reason);
|
|
6174
|
+
settle();
|
|
6175
|
+
return;
|
|
6176
|
+
}
|
|
6177
|
+
endWait();
|
|
6178
|
+
step = { result: await read };
|
|
6179
|
+
}
|
|
6180
|
+
next = void 0;
|
|
6181
|
+
}
|
|
6182
|
+
if (step.result.done) {
|
|
6183
|
+
if (pendingWait && lastTurn) break;
|
|
6184
|
+
if (await reconnect(new Error("Codex transport closed."))) continue;
|
|
6185
|
+
break;
|
|
6044
6186
|
}
|
|
6045
|
-
if (step.result.done) break;
|
|
6046
6187
|
const message = step.result.value;
|
|
6188
|
+
if (message.method === "item/completed") {
|
|
6189
|
+
const id = message.params?.item?.id;
|
|
6190
|
+
if (typeof id === "string") {
|
|
6191
|
+
if (replayed) replayedItemIds.add(id);
|
|
6192
|
+
else if (replayedItemIds.has(id)) continue;
|
|
6193
|
+
completedItemIds.add(id);
|
|
6194
|
+
}
|
|
6195
|
+
}
|
|
6047
6196
|
if (!firstClientMessageLogged) {
|
|
6048
6197
|
firstClientMessageLogged = true;
|
|
6049
6198
|
debugCodex(
|
|
@@ -7197,7 +7346,9 @@ var OpenCodeAgentAdapter = class {
|
|
|
7197
7346
|
);
|
|
7198
7347
|
const wait = new BackgroundWait(
|
|
7199
7348
|
BACKGROUND_TASK_GRACE_MS,
|
|
7200
|
-
Math.max(0, backgroundTimeoutMs - waitedMs)
|
|
7349
|
+
Math.max(0, backgroundTimeoutMs - waitedMs),
|
|
7350
|
+
// Every child waited on here is a subagent.
|
|
7351
|
+
request.options.exemptSubagentsFromBackgroundTimeout === true
|
|
7201
7352
|
);
|
|
7202
7353
|
pendingWait = wait;
|
|
7203
7354
|
void wait.expired.then((reason) => {
|
package/dist/events/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AISDKEvent, C as BackgroundTask, D as BackgroundTasksEvent, Z as HarnessCommandsEvent, a3 as MessageCompletedEvent, a4 as MessageInjectedEvent, a5 as MessageStartedEvent, a7 as NativePlanEvent, a8 as NormalizedAgentEvent, a9 as NormalizedAgentEventBase, aa as NormalizedAgentEventType, aj as PermissionRequestedEvent, ak as PermissionResolvedEvent, al as RawAgentEvent, am as ReasoningDeltaEvent, ao as RunCancelledEvent, ap as RunCompletedEvent, aq as RunErrorEvent, ar as RunStartedEvent, at as TextDeltaEvent, av as ToolCallCompletedEvent, aw as ToolCallDeltaEvent, ax as ToolCallStartedEvent, aE as createNormalizedEvent, aF as normalizeRawAgentEvent, aJ as toAISDKEvent, aK as toAISDKStream } from '../types-
|
|
1
|
+
export { A as AISDKEvent, C as BackgroundTask, D as BackgroundTasksEvent, Z as HarnessCommandsEvent, a3 as MessageCompletedEvent, a4 as MessageInjectedEvent, a5 as MessageStartedEvent, a7 as NativePlanEvent, a8 as NormalizedAgentEvent, a9 as NormalizedAgentEventBase, aa as NormalizedAgentEventType, aj as PermissionRequestedEvent, ak as PermissionResolvedEvent, al as RawAgentEvent, am as ReasoningDeltaEvent, ao as RunCancelledEvent, ap as RunCompletedEvent, aq as RunErrorEvent, ar as RunStartedEvent, at as TextDeltaEvent, av as ToolCallCompletedEvent, aw as ToolCallDeltaEvent, ax as ToolCallStartedEvent, aE as createNormalizedEvent, aF as normalizeRawAgentEvent, aJ as toAISDKEvent, aK as toAISDKStream } from '../types-B_oR4A4a.js';
|
|
2
2
|
import { AgentProvider } from '../enums.js';
|
|
3
3
|
import '../Sandbox-DcKAU-E3.js';
|
|
4
4
|
import 'e2b';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AISDKEvent, a as AgentApprovalMode, b as AgentAttachRequest, c as AgentCommandConfig, d as AgentCostData, e as AgentExecutionRequest, f as AgentLocalMcpConfig, g as AgentMcpConfig, h as AgentOptions, i as AgentOptionsBase, j as AgentOptionsMap, k as AgentPermissionDecision, l as AgentPermissionKind, m as AgentPermissionResponse, n as AgentProviderAdapter, o as AgentProviderName, p as AgentReasoningEffort, q as AgentRemoteMcpConfig, r as AgentResult, s as AgentRun, t as AgentRunConfig, u as AgentRunSink, v as AgentSetupRequest, w as AgentSkillConfig, x as AgentSubAgentConfig, y as AgentUserAnswer, z as AgentUserQuestion, B as AttachedRun, C as BackgroundTask, D as BackgroundTasksEvent, E as ClaudeCodeAgentOptions, F as ClaudeCodeHookConfig, G as ClaudeCodeHookEvent, H as ClaudeCodeHookHandler, I as ClaudeCodeHookMatcherGroup, J as ClaudeCodeHooksConfig, K as ClaudeCodeProviderOptions, L as CodexAgentOptions, M as CodexCommandHook, N as CodexHookEvent, O as CodexHookMatcherGroup, P as CodexHooksConfig, Q as CodexModelProviderConfig, R as CodexProviderOptions, S as CodexSkillEntry, T as DataContent, U as EmbeddedSkillConfig, V as FilePart, W as HarnessCommandDescriptor, X as HarnessCommandInvocation, Y as HarnessCommandSource, Z as HarnessCommandsEvent, _ as ImagePart, $ as MAX_HARNESS_COMMANDS, a0 as MAX_HARNESS_COMMAND_ARGUMENT_HINT, a1 as MAX_HARNESS_COMMAND_DESCRIPTION, a2 as MAX_HARNESS_COMMAND_NAME, a3 as MessageCompletedEvent, a4 as MessageInjectedEvent, a5 as MessageStartedEvent, a6 as NativeParkBackgroundWork, a7 as NativePlanEvent, a8 as NormalizedAgentEvent, a9 as NormalizedAgentEventBase, aa as NormalizedAgentEventType, ab as OpenCodeAgentOptions, ac as OpenCodeCommandEntry, ad as OpenCodePluginConfig, ae as OpenCodePluginEvent, af as OpenCodePluginHookConfig, ag as OpenCodeProviderOptions, ah as OpenCodeSkillEntry, ai as OpenRouterPlugin, aj as PermissionRequestedEvent, ak as PermissionResolvedEvent, al as RawAgentEvent, am as ReasoningDeltaEvent, an as RepoSkillConfig, ao as RunCancelledEvent, ap as RunCompletedEvent, aq as RunErrorEvent, ar as RunStartedEvent, as as SetupLayout, at as TextDeltaEvent, au as TextPart, av as ToolCallCompletedEvent, aw as ToolCallDeltaEvent, ax as ToolCallStartedEvent, ay as UserContent, az as UserContentPart, aA as builtinHarnessCommands, aB as claudeHarnessCommands, aC as codexHarnessCommands, aD as codexSkillMention, aE as createNormalizedEvent, aF as normalizeRawAgentEvent, aG as openCodeHarnessCommands, aH as parseHarnessCommandInvocation, aI as skillDirective, aJ as toAISDKEvent, aK as toAISDKStream } from './types-
|
|
1
|
+
export { A as AISDKEvent, a as AgentApprovalMode, b as AgentAttachRequest, c as AgentCommandConfig, d as AgentCostData, e as AgentExecutionRequest, f as AgentLocalMcpConfig, g as AgentMcpConfig, h as AgentOptions, i as AgentOptionsBase, j as AgentOptionsMap, k as AgentPermissionDecision, l as AgentPermissionKind, m as AgentPermissionResponse, n as AgentProviderAdapter, o as AgentProviderName, p as AgentReasoningEffort, q as AgentRemoteMcpConfig, r as AgentResult, s as AgentRun, t as AgentRunConfig, u as AgentRunSink, v as AgentSetupRequest, w as AgentSkillConfig, x as AgentSubAgentConfig, y as AgentUserAnswer, z as AgentUserQuestion, B as AttachedRun, C as BackgroundTask, D as BackgroundTasksEvent, E as ClaudeCodeAgentOptions, F as ClaudeCodeHookConfig, G as ClaudeCodeHookEvent, H as ClaudeCodeHookHandler, I as ClaudeCodeHookMatcherGroup, J as ClaudeCodeHooksConfig, K as ClaudeCodeProviderOptions, L as CodexAgentOptions, M as CodexCommandHook, N as CodexHookEvent, O as CodexHookMatcherGroup, P as CodexHooksConfig, Q as CodexModelProviderConfig, R as CodexProviderOptions, S as CodexSkillEntry, T as DataContent, U as EmbeddedSkillConfig, V as FilePart, W as HarnessCommandDescriptor, X as HarnessCommandInvocation, Y as HarnessCommandSource, Z as HarnessCommandsEvent, _ as ImagePart, $ as MAX_HARNESS_COMMANDS, a0 as MAX_HARNESS_COMMAND_ARGUMENT_HINT, a1 as MAX_HARNESS_COMMAND_DESCRIPTION, a2 as MAX_HARNESS_COMMAND_NAME, a3 as MessageCompletedEvent, a4 as MessageInjectedEvent, a5 as MessageStartedEvent, a6 as NativeParkBackgroundWork, a7 as NativePlanEvent, a8 as NormalizedAgentEvent, a9 as NormalizedAgentEventBase, aa as NormalizedAgentEventType, ab as OpenCodeAgentOptions, ac as OpenCodeCommandEntry, ad as OpenCodePluginConfig, ae as OpenCodePluginEvent, af as OpenCodePluginHookConfig, ag as OpenCodeProviderOptions, ah as OpenCodeSkillEntry, ai as OpenRouterPlugin, aj as PermissionRequestedEvent, ak as PermissionResolvedEvent, al as RawAgentEvent, am as ReasoningDeltaEvent, an as RepoSkillConfig, ao as RunCancelledEvent, ap as RunCompletedEvent, aq as RunErrorEvent, ar as RunStartedEvent, as as SetupLayout, at as TextDeltaEvent, au as TextPart, av as ToolCallCompletedEvent, aw as ToolCallDeltaEvent, ax as ToolCallStartedEvent, ay as UserContent, az as UserContentPart, aA as builtinHarnessCommands, aB as claudeHarnessCommands, aC as codexHarnessCommands, aD as codexSkillMention, aE as createNormalizedEvent, aF as normalizeRawAgentEvent, aG as openCodeHarnessCommands, aH as parseHarnessCommandInvocation, aI as skillDirective, aJ as toAISDKEvent, aK as toAISDKStream } from './types-B_oR4A4a.js';
|
|
2
2
|
export { AGENT_RESERVED_PORTS, Agent, HarnessCapabilities, HarnessCommand, agentboxRoot, collectAllAgentReservedPorts, getAgentLayout, harnessCapabilities, resolveHarnessCommand } from './agents/index.js';
|
|
3
3
|
export { A as AsyncCommandHandle, C as CommandEvent, a as CommandOptions, b as CommandResult, D as DaytonaProviderOptions, c as DaytonaSandboxOptions, E as E2bProviderOptions, d as E2bSandboxOptions, G as GitCloneOptions, L as LocalDockerProviderOptions, e as LocalDockerSandboxOptions, M as ModalProviderOptions, f as ModalSandboxOptions, S as Sandbox, g as SandboxDescriptor, h as SandboxListOptions, i as SandboxOptions, j as SandboxOptionsBase, k as SandboxOptionsMap, l as SandboxProviderName, m as SandboxRaw, n as SandboxRawMap, o as SandboxResourceSpec, T as TarballEntry, V as VercelGitSource, p as VercelProviderOptions, q as VercelSandboxOptions } from './Sandbox-DcKAU-E3.js';
|
|
4
4
|
export { SandboxAdapter, buildGitCloneCommand } from './sandboxes/index.js';
|
package/dist/index.js
CHANGED
|
@@ -625,6 +625,17 @@ interface AgentOptionsBase {
|
|
|
625
625
|
* settles immediately.
|
|
626
626
|
*/
|
|
627
627
|
backgroundTaskTimeoutMs?: number;
|
|
628
|
+
/**
|
|
629
|
+
* Leave background subagents out of {@link backgroundTaskTimeoutMs}: while
|
|
630
|
+
* one is live (Claude Code background agents and workflows, OpenCode
|
|
631
|
+
* background children) the budget does not run, so the ceiling never stops
|
|
632
|
+
* a working subagent. Shells, monitors and scheduled wakeups are still
|
|
633
|
+
* bounded once no subagent is live. Covers the run's own waits and native
|
|
634
|
+
* Claude Code parks; a sandbox run keeps waiting instead of parking while a
|
|
635
|
+
* subagent is live, since the daemon's park TTL cannot be held. Default
|
|
636
|
+
* `false`. `backgroundTaskTimeoutMs: 0` still abandons everything.
|
|
637
|
+
*/
|
|
638
|
+
exemptSubagentsFromBackgroundTimeout?: boolean;
|
|
628
639
|
/**
|
|
629
640
|
* Keep every normalized and raw event in memory for the life of the run so
|
|
630
641
|
* {@link AgentResult.events} / {@link AgentResult.rawEvents} can replay it
|