zidane 5.8.5 → 5.9.2
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 +3 -1
- package/dist/{agent-CL4nT5Ti.d.ts → agent-CDFbxbHd.d.ts} +46 -15
- package/dist/agent-CDFbxbHd.d.ts.map +1 -0
- package/dist/chat/pure.d.ts +3 -3
- package/dist/chat.d.ts +6 -6
- package/dist/chat.js +2 -2
- package/dist/contexts/docker.d.ts +1 -1
- package/dist/contexts/docker.js +11 -0
- package/dist/contexts/docker.js.map +1 -1
- package/dist/contexts.d.ts +3 -3
- package/dist/eval.d.ts +2 -0
- package/dist/eval.js +1323 -0
- package/dist/eval.js.map +1 -0
- package/dist/{headless-c7MDO-iF.js → headless-C596K-Lk.js} +3 -3
- package/dist/{headless-c7MDO-iF.js.map → headless-C596K-Lk.js.map} +1 -1
- package/dist/headless.d.ts +1 -1
- package/dist/headless.js +1 -1
- package/dist/{index-CZOwAJIX.d.ts → index-ClYUGpmF.d.ts} +2 -2
- package/dist/{index-CZOwAJIX.d.ts.map → index-ClYUGpmF.d.ts.map} +1 -1
- package/dist/{index-DtLfTUXt.d.ts → index-DWw_PtJH.d.ts} +3 -3
- package/dist/{index-DtLfTUXt.d.ts.map → index-DWw_PtJH.d.ts.map} +1 -1
- package/dist/{index-BDMVtgHD.d.ts → index-D_i2Nhts.d.ts} +446 -4
- package/dist/index-D_i2Nhts.d.ts.map +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/{login-DYQ6LgLP.js → login-Ujwd1HEb.js} +2 -2
- package/dist/{login-DYQ6LgLP.js.map → login-Ujwd1HEb.js.map} +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/{presets-6SoIBrzL.js → presets-ga6dMRVd.js} +2 -2
- package/dist/{presets-6SoIBrzL.js.map → presets-ga6dMRVd.js.map} +1 -1
- package/dist/presets.d.ts +2 -2
- package/dist/presets.js +1 -1
- package/dist/{providers-ByITfqRA.js → providers-CezC9my7.js} +29 -3
- package/dist/providers-CezC9my7.js.map +1 -0
- package/dist/providers.d.ts +1 -1
- package/dist/providers.js +1 -1
- package/dist/restate.d.ts +67 -4
- package/dist/restate.d.ts.map +1 -1
- package/dist/restate.js +226 -25
- package/dist/restate.js.map +1 -1
- package/dist/session/sqlite.d.ts +1 -1
- package/dist/session.d.ts +1 -1
- package/dist/skills.d.ts +2 -2
- package/dist/{tool-formatters-D-aWpu2N.d.ts → tool-formatters-B3fSafpr.d.ts} +2 -2
- package/dist/{tool-formatters-D-aWpu2N.d.ts.map → tool-formatters-B3fSafpr.d.ts.map} +1 -1
- package/dist/tools/fetch-url.d.ts +1 -1
- package/dist/tools/web-search.d.ts +1 -1
- package/dist/{tools-DOUtulS5.js → tools-CAdllmWO.js} +402 -9
- package/dist/tools-CAdllmWO.js.map +1 -0
- package/dist/tools.d.ts +2 -2
- package/dist/tools.js +1 -1
- package/dist/{transcript-anchors-DYsnGyel.d.ts → transcript-anchors-BHVVVhR0.d.ts} +4 -4
- package/dist/{transcript-anchors-DYsnGyel.d.ts.map → transcript-anchors-BHVVVhR0.d.ts.map} +1 -1
- package/dist/{transcript-anchors-B2h3qt3S.js → transcript-anchors-DFknQ4ew.js} +4 -4
- package/dist/{transcript-anchors-B2h3qt3S.js.map → transcript-anchors-DFknQ4ew.js.map} +1 -1
- package/dist/tui.d.ts +3 -3
- package/dist/tui.js +3 -3
- package/dist/{turn-operations-D-fypW6K.d.ts → turn-operations-BMxugnqg.d.ts} +3 -3
- package/dist/{turn-operations-D-fypW6K.d.ts.map → turn-operations-BMxugnqg.d.ts.map} +1 -1
- package/dist/types-BPw_i5vb.js.map +1 -1
- package/dist/{types-CEAMIUXw.d.ts → types-CB1J-DQw.d.ts} +14 -2
- package/dist/types-CB1J-DQw.d.ts.map +1 -0
- package/dist/types.d.ts +4 -4
- package/docs/RESTATE.md +75 -19
- package/docs/SKILL.md +2 -2
- package/package.json +15 -3
- package/scripts/eval.ts +140 -0
- package/dist/agent-CL4nT5Ti.d.ts.map +0 -1
- package/dist/index-BDMVtgHD.d.ts.map +0 -1
- package/dist/providers-ByITfqRA.js.map +0 -1
- package/dist/tools-DOUtulS5.js.map +0 -1
- package/dist/types-CEAMIUXw.d.ts.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as formatTaskStatus, f as buildContextBreakdown, h as utf8ByteLength, l as formatTaskSummary, n as stripLineNumberPrefixes, r as styleReplacementForVia, s as formatDuration, t as resolveOldString, u as previewLine } from "./edit-utils-DnfNoj16.js";
|
|
2
|
-
import { a as createCursorOAuthProvider, c as anthropic, d as ANTHROPIC_EXTRA_MODELS, f as FAST_MODE_OPTIONS, n as openai, o as generatePkce, r as local, s as cerebras, t as openrouter } from "./providers-
|
|
2
|
+
import { a as createCursorOAuthProvider, c as anthropic, d as ANTHROPIC_EXTRA_MODELS, f as FAST_MODE_OPTIONS, n as openai, o as generatePkce, r as local, s as cerebras, t as openrouter } from "./providers-CezC9my7.js";
|
|
3
3
|
import { i as AgentProviderError, l as errorMessage, n as AgentBudgetExceededError, o as AgentToolPairingError, p as toTypedError, t as AgentAbortedError } from "./errors-B-GeaKTX.js";
|
|
4
4
|
import { E as appendStaticSection, a as detectTurnInterruption, c as filterUnresolvedToolUses, k as renderSystemForWire, n as SYNTHETIC_TOOL_RESULT_PLACEHOLDER, o as ensureEndsWithUserMessage, s as ensureToolResultPairing } from "./messages-Dhva-Ewy.js";
|
|
5
5
|
import { t as reconcileImageMediaType } from "./image-sniff-B7uFSNO1.js";
|
|
@@ -3022,7 +3022,7 @@ async function executeTurn(ctx, turn, priorUsage) {
|
|
|
3022
3022
|
const totalBytes = toolResults.reduce((sum, r) => {
|
|
3023
3023
|
if (excludeSet && nameById) {
|
|
3024
3024
|
const name = nameById.get(r.id);
|
|
3025
|
-
if (name
|
|
3025
|
+
if (typeof name === "string" && excludeSet.has(name)) return sum;
|
|
3026
3026
|
}
|
|
3027
3027
|
return sum + toolOutputByteLength(r.content);
|
|
3028
3028
|
}, 0);
|
|
@@ -3307,6 +3307,7 @@ async function runSingleToolDispatch(ctx, call, turnId, fixed) {
|
|
|
3307
3307
|
isError = true;
|
|
3308
3308
|
} else {
|
|
3309
3309
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
3310
|
+
if (ctx.shouldRethrowToolError?.(error)) throw error;
|
|
3310
3311
|
const errorCtx = {
|
|
3311
3312
|
...buildToolHookBase(ctx, turnId, callId, call.name, displayName, effectiveInput),
|
|
3312
3313
|
error
|
|
@@ -3492,6 +3493,381 @@ function resolveConcurrencySafe(def, input) {
|
|
|
3492
3493
|
* AND carries the shell-cascade signal — siblings see one signal source.
|
|
3493
3494
|
*/
|
|
3494
3495
|
async function executeToolBatch(ctx, toolCalls, turnId) {
|
|
3496
|
+
if (ctx.toolBatchExecutor) return executeCustomToolBatch(ctx, toolCalls, turnId, ctx.toolBatchExecutor);
|
|
3497
|
+
return executeNativeToolBatch(ctx, toolCalls, turnId);
|
|
3498
|
+
}
|
|
3499
|
+
async function executeCustomToolBatch(ctx, toolCalls, turnId, executor) {
|
|
3500
|
+
if (toolCalls.length === 0) return [];
|
|
3501
|
+
const N = toolCalls.length;
|
|
3502
|
+
const maxConcurrent = Math.max(1, ctx.maxConcurrentTools ?? DEFAULT_MAX_CONCURRENT_TOOLS);
|
|
3503
|
+
const safe = Array.from({ length: N });
|
|
3504
|
+
for (let i = 0; i < N; i++) safe[i] = resolveConcurrencySafe(ctx.tools[toolCalls[i].name], toolCalls[i].input);
|
|
3505
|
+
const siblingAbort = new AbortController();
|
|
3506
|
+
let parentAbortListener;
|
|
3507
|
+
if (ctx.signal.aborted) siblingAbort.abort(ctx.signal.reason ?? "parent-aborted");
|
|
3508
|
+
else {
|
|
3509
|
+
parentAbortListener = () => siblingAbort.abort(ctx.signal.reason ?? "parent-aborted");
|
|
3510
|
+
ctx.signal.addEventListener("abort", parentAbortListener, { once: true });
|
|
3511
|
+
}
|
|
3512
|
+
const childCtx = {
|
|
3513
|
+
...ctx,
|
|
3514
|
+
signal: siblingAbort.signal,
|
|
3515
|
+
toolBatchExecutor: void 0
|
|
3516
|
+
};
|
|
3517
|
+
const cancelMessage = () => {
|
|
3518
|
+
if (ctx.signal.aborted) return INTERRUPT_MESSAGE_FOR_TOOL_USE;
|
|
3519
|
+
if (siblingAbort.signal.reason === SHELL_CASCADE_REASON) return SHELL_CASCADE_CANCEL_MESSAGE;
|
|
3520
|
+
return INTERRUPT_MESSAGE_FOR_TOOL_USE;
|
|
3521
|
+
};
|
|
3522
|
+
const execute = async (index) => {
|
|
3523
|
+
const call = toolCalls[index];
|
|
3524
|
+
try {
|
|
3525
|
+
const { result } = await executeSingleTool(childCtx, call, turnId);
|
|
3526
|
+
const isUserCancel = typeof result.content === "string" && result.content === "[Tool call cancelled by user]";
|
|
3527
|
+
if (result.isError && !isUserCancel && call.name === SHELL_TOOL_NAME && !siblingAbort.signal.aborted) siblingAbort.abort(SHELL_CASCADE_REASON);
|
|
3528
|
+
return result;
|
|
3529
|
+
} catch (err) {
|
|
3530
|
+
if (ctx.shouldRethrowToolError?.(err)) throw err;
|
|
3531
|
+
const isAbort = siblingAbort.signal.aborted || ctx.signal.aborted || err instanceof Error && err.name === "AbortError";
|
|
3532
|
+
return {
|
|
3533
|
+
id: call.id,
|
|
3534
|
+
content: isAbort ? cancelMessage() : `Error: ${errorMessage(err)}`,
|
|
3535
|
+
isError: true
|
|
3536
|
+
};
|
|
3537
|
+
}
|
|
3538
|
+
};
|
|
3539
|
+
const executeDurable = async (indices, all) => {
|
|
3540
|
+
const starts = [];
|
|
3541
|
+
const results = /* @__PURE__ */ new Map();
|
|
3542
|
+
try {
|
|
3543
|
+
for (const index of indices) {
|
|
3544
|
+
const started = await startDurableToolExecution(childCtx, toolCalls[index], turnId, index);
|
|
3545
|
+
if (started.kind === "result") results.set(index, started.result);
|
|
3546
|
+
else starts.push(started.start);
|
|
3547
|
+
}
|
|
3548
|
+
if (starts.length > 0) {
|
|
3549
|
+
const settledPromises = [];
|
|
3550
|
+
for (const start of starts) {
|
|
3551
|
+
if (!hasDurableMap(start.promise)) throw new TypeError(`Tool ${start.name} is marked durable but did not return a mappable durable promise. Wrap the tool with the runtime adapter before enabling durable parallel scheduling.`);
|
|
3552
|
+
settledPromises.push(start.promise.map((value, failure) => {
|
|
3553
|
+
if (failure !== void 0) return {
|
|
3554
|
+
ok: false,
|
|
3555
|
+
error: serializeToolFailure(failure)
|
|
3556
|
+
};
|
|
3557
|
+
return {
|
|
3558
|
+
ok: true,
|
|
3559
|
+
value: value ?? ""
|
|
3560
|
+
};
|
|
3561
|
+
}));
|
|
3562
|
+
}
|
|
3563
|
+
const settlements = await all(settledPromises);
|
|
3564
|
+
for (let i = 0; i < starts.length; i++) {
|
|
3565
|
+
const start = starts[i];
|
|
3566
|
+
const settlement = settlements[i];
|
|
3567
|
+
if (settlement.ok) {
|
|
3568
|
+
const result = await completeDurableToolExecution(childCtx, start, settlement.value);
|
|
3569
|
+
results.set(start.index, result);
|
|
3570
|
+
const isUserCancel = typeof result.content === "string" && result.content === "[Tool call cancelled by user]";
|
|
3571
|
+
if (result.isError && !isUserCancel && start.call.name === SHELL_TOOL_NAME && !siblingAbort.signal.aborted) siblingAbort.abort(SHELL_CASCADE_REASON);
|
|
3572
|
+
} else {
|
|
3573
|
+
const result = await failDurableToolExecution(childCtx, start, errorFromSerializedFailure(settlement.error), cancelMessage);
|
|
3574
|
+
results.set(start.index, result);
|
|
3575
|
+
}
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
return indices.map((index) => results.get(index) ?? {
|
|
3579
|
+
id: toolCalls[index].id,
|
|
3580
|
+
content: "Error: durable tool execution did not produce a result",
|
|
3581
|
+
isError: true
|
|
3582
|
+
});
|
|
3583
|
+
} finally {
|
|
3584
|
+
for (const start of starts) childCtx.pendingToolCancels?.delete(start.callId);
|
|
3585
|
+
}
|
|
3586
|
+
};
|
|
3587
|
+
const executionCtx = {
|
|
3588
|
+
toolCalls,
|
|
3589
|
+
turnId,
|
|
3590
|
+
maxConcurrentTools: maxConcurrent,
|
|
3591
|
+
signal: ctx.signal,
|
|
3592
|
+
steeringQueue: ctx.steeringQueue,
|
|
3593
|
+
isConcurrencySafe: (index) => safe[index] === true,
|
|
3594
|
+
execute,
|
|
3595
|
+
canExecuteDurably: (index) => typeof ctx.tools[toolCalls[index].name]?.durableExecute === "function",
|
|
3596
|
+
executeDurable,
|
|
3597
|
+
interruptedResult: (index) => ({
|
|
3598
|
+
id: toolCalls[index].id,
|
|
3599
|
+
content: INTERRUPT_MESSAGE_FOR_TOOL_USE,
|
|
3600
|
+
isError: true
|
|
3601
|
+
}),
|
|
3602
|
+
skippedResult: (index) => ({
|
|
3603
|
+
id: toolCalls[index].id,
|
|
3604
|
+
content: TOOL_USE_SKIPPED_MESSAGE,
|
|
3605
|
+
isError: true
|
|
3606
|
+
})
|
|
3607
|
+
};
|
|
3608
|
+
try {
|
|
3609
|
+
return await executor(executionCtx);
|
|
3610
|
+
} finally {
|
|
3611
|
+
if (parentAbortListener) ctx.signal.removeEventListener("abort", parentAbortListener);
|
|
3612
|
+
}
|
|
3613
|
+
}
|
|
3614
|
+
async function startDurableToolExecution(ctx, call, turnId, index) {
|
|
3615
|
+
const toolDef = ctx.tools[call.name];
|
|
3616
|
+
const durableExecute = toolDef?.durableExecute;
|
|
3617
|
+
const callId = call.id;
|
|
3618
|
+
const displayName = toWireName(call.name, ctx.aliasMaps);
|
|
3619
|
+
const runToolCounts = Object.freeze({ ...ctx.runToolCounts });
|
|
3620
|
+
const perCallAbort = new AbortController();
|
|
3621
|
+
ctx.pendingToolCancels?.set(callId, perCallAbort);
|
|
3622
|
+
const cleanupResult = (result) => {
|
|
3623
|
+
ctx.pendingToolCancels?.delete(callId);
|
|
3624
|
+
return {
|
|
3625
|
+
kind: "result",
|
|
3626
|
+
result
|
|
3627
|
+
};
|
|
3628
|
+
};
|
|
3629
|
+
const gateCtx = {
|
|
3630
|
+
...buildToolHookBase(ctx, turnId, callId, call.name, displayName, call.input),
|
|
3631
|
+
block: false,
|
|
3632
|
+
reason: "Tool execution was blocked",
|
|
3633
|
+
runToolCounts
|
|
3634
|
+
};
|
|
3635
|
+
await ctx.hooks.callHook("tool:gate", gateCtx);
|
|
3636
|
+
if (gateCtx.block) {
|
|
3637
|
+
await fireDispatched(ctx, {
|
|
3638
|
+
turnId,
|
|
3639
|
+
callId,
|
|
3640
|
+
name: call.name,
|
|
3641
|
+
displayName,
|
|
3642
|
+
input: gateCtx.input,
|
|
3643
|
+
outcome: "gate-block",
|
|
3644
|
+
reason: gateCtx.reason,
|
|
3645
|
+
runToolCounts
|
|
3646
|
+
});
|
|
3647
|
+
return cleanupResult({
|
|
3648
|
+
id: callId,
|
|
3649
|
+
content: `Blocked: ${gateCtx.reason}`,
|
|
3650
|
+
isError: true
|
|
3651
|
+
});
|
|
3652
|
+
}
|
|
3653
|
+
ctx.runToolCounts[call.name] = (ctx.runToolCounts[call.name] ?? 0) + 1;
|
|
3654
|
+
if (gateCtx.result !== void 0) {
|
|
3655
|
+
await fireDispatched(ctx, {
|
|
3656
|
+
turnId,
|
|
3657
|
+
callId,
|
|
3658
|
+
name: call.name,
|
|
3659
|
+
displayName,
|
|
3660
|
+
input: gateCtx.input,
|
|
3661
|
+
outcome: "gate-substitute",
|
|
3662
|
+
runToolCounts
|
|
3663
|
+
});
|
|
3664
|
+
const emitted = await emitToolResult(ctx, {
|
|
3665
|
+
turnId,
|
|
3666
|
+
callId,
|
|
3667
|
+
name: call.name,
|
|
3668
|
+
displayName,
|
|
3669
|
+
input: gateCtx.input,
|
|
3670
|
+
output: gateCtx.result,
|
|
3671
|
+
isError: false,
|
|
3672
|
+
runToolCounts
|
|
3673
|
+
});
|
|
3674
|
+
return cleanupResult({
|
|
3675
|
+
id: callId,
|
|
3676
|
+
content: emitted.output,
|
|
3677
|
+
...emitted.isError ? { isError: true } : {}
|
|
3678
|
+
});
|
|
3679
|
+
}
|
|
3680
|
+
let effectiveInput = gateCtx.input;
|
|
3681
|
+
if (!toolDef || !durableExecute) return cleanupResult({
|
|
3682
|
+
id: callId,
|
|
3683
|
+
content: `Tool error: ${toolDef ? "Tool is not durable-execution capable" : `Unknown tool: ${call.name}`}`,
|
|
3684
|
+
isError: true
|
|
3685
|
+
});
|
|
3686
|
+
const validation = validateToolArgs(effectiveInput, toolDef.spec.inputSchema);
|
|
3687
|
+
if (!validation.valid) {
|
|
3688
|
+
await ctx.hooks.callHook("validation:reject", {
|
|
3689
|
+
...buildToolHookBase(ctx, turnId, callId, call.name, displayName, effectiveInput),
|
|
3690
|
+
reason: validation.error ?? "invalid input",
|
|
3691
|
+
schema: toolDef.spec.inputSchema
|
|
3692
|
+
});
|
|
3693
|
+
await fireDispatched(ctx, {
|
|
3694
|
+
turnId,
|
|
3695
|
+
callId,
|
|
3696
|
+
name: call.name,
|
|
3697
|
+
displayName,
|
|
3698
|
+
input: effectiveInput,
|
|
3699
|
+
outcome: "invalid-input",
|
|
3700
|
+
runToolCounts
|
|
3701
|
+
});
|
|
3702
|
+
return cleanupResult({
|
|
3703
|
+
id: callId,
|
|
3704
|
+
content: `Validation error: ${validation.error}`,
|
|
3705
|
+
isError: true
|
|
3706
|
+
});
|
|
3707
|
+
}
|
|
3708
|
+
effectiveInput = validation.coercedInput ?? effectiveInput;
|
|
3709
|
+
const coercions = validation.coercions && validation.coercions.length > 0 ? validation.coercions : void 0;
|
|
3710
|
+
if (coercions) await ctx.hooks.callHook("validation:coerce", {
|
|
3711
|
+
...buildToolHookBase(ctx, turnId, callId, call.name, displayName, effectiveInput),
|
|
3712
|
+
coercions,
|
|
3713
|
+
schema: toolDef.spec.inputSchema
|
|
3714
|
+
});
|
|
3715
|
+
await fireDispatched(ctx, {
|
|
3716
|
+
turnId,
|
|
3717
|
+
callId,
|
|
3718
|
+
name: call.name,
|
|
3719
|
+
displayName,
|
|
3720
|
+
input: effectiveInput,
|
|
3721
|
+
outcome: "execute",
|
|
3722
|
+
runToolCounts
|
|
3723
|
+
});
|
|
3724
|
+
await ctx.hooks.callHook("tool:before", {
|
|
3725
|
+
...buildToolHookBase(ctx, turnId, callId, call.name, displayName, effectiveInput),
|
|
3726
|
+
runToolCounts,
|
|
3727
|
+
...coercions ? { coercions } : {}
|
|
3728
|
+
});
|
|
3729
|
+
const childSignal = typeof AbortSignal.any === "function" ? AbortSignal.any([ctx.signal, perCallAbort.signal]) : ctx.signal;
|
|
3730
|
+
let reportedOutcome;
|
|
3731
|
+
const toolCtx = {
|
|
3732
|
+
provider: ctx.provider,
|
|
3733
|
+
signal: childSignal,
|
|
3734
|
+
execution: ctx.execution,
|
|
3735
|
+
handle: ctx.handle,
|
|
3736
|
+
hooks: ctx.hooks,
|
|
3737
|
+
tools: ctx.agentTools,
|
|
3738
|
+
...ctx.agentName !== void 0 ? { name: ctx.agentName } : {},
|
|
3739
|
+
...ctx.agentSystem !== void 0 ? { system: ctx.agentSystem } : {},
|
|
3740
|
+
...ctx.agentToolAliases !== void 0 ? { toolAliases: ctx.agentToolAliases } : {},
|
|
3741
|
+
...ctx.agentMcpServers !== void 0 ? { mcpServers: ctx.agentMcpServers } : {},
|
|
3742
|
+
...ctx.agentSkills !== void 0 ? { skills: ctx.agentSkills } : {},
|
|
3743
|
+
...ctx.agentBehavior !== void 0 ? { behavior: ctx.agentBehavior } : {},
|
|
3744
|
+
turnId,
|
|
3745
|
+
callId,
|
|
3746
|
+
runId: ctx.runId,
|
|
3747
|
+
...ctx.parentRunId !== void 0 ? { parentRunId: ctx.parentRunId } : {},
|
|
3748
|
+
...ctx.session ? { session: ctx.session } : {},
|
|
3749
|
+
...ctx.readState ? { readState: ctx.readState } : {},
|
|
3750
|
+
...typeof ctx.depth === "number" ? { depth: ctx.depth } : {},
|
|
3751
|
+
clock: ctx.clock,
|
|
3752
|
+
reportOutcome: (outcome) => {
|
|
3753
|
+
reportedOutcome = outcome;
|
|
3754
|
+
}
|
|
3755
|
+
};
|
|
3756
|
+
return {
|
|
3757
|
+
kind: "start",
|
|
3758
|
+
start: {
|
|
3759
|
+
index,
|
|
3760
|
+
call,
|
|
3761
|
+
turnId,
|
|
3762
|
+
callId,
|
|
3763
|
+
name: call.name,
|
|
3764
|
+
displayName,
|
|
3765
|
+
input: effectiveInput,
|
|
3766
|
+
runToolCounts,
|
|
3767
|
+
perCallAbort,
|
|
3768
|
+
...coercions ? { coercions } : {},
|
|
3769
|
+
promise: durableExecute(effectiveInput, toolCtx),
|
|
3770
|
+
reportedOutcome: () => reportedOutcome
|
|
3771
|
+
}
|
|
3772
|
+
};
|
|
3773
|
+
}
|
|
3774
|
+
async function completeDurableToolExecution(ctx, start, output) {
|
|
3775
|
+
const reportedOutcome = start.reportedOutcome();
|
|
3776
|
+
const emitted = await emitToolResult(ctx, {
|
|
3777
|
+
turnId: start.turnId,
|
|
3778
|
+
callId: start.callId,
|
|
3779
|
+
name: start.name,
|
|
3780
|
+
displayName: start.displayName,
|
|
3781
|
+
input: start.input,
|
|
3782
|
+
output,
|
|
3783
|
+
isError: false,
|
|
3784
|
+
runToolCounts: start.runToolCounts,
|
|
3785
|
+
...start.coercions ? { coercions: start.coercions } : {},
|
|
3786
|
+
...reportedOutcome ? { outcome: reportedOutcome } : {}
|
|
3787
|
+
});
|
|
3788
|
+
return {
|
|
3789
|
+
id: start.callId,
|
|
3790
|
+
content: emitted.output,
|
|
3791
|
+
...emitted.isError ? { isError: true } : {}
|
|
3792
|
+
};
|
|
3793
|
+
}
|
|
3794
|
+
async function failDurableToolExecution(ctx, start, err, cancelMessage) {
|
|
3795
|
+
if (ctx.shouldRethrowToolError?.(err)) throw err;
|
|
3796
|
+
const isAbortError = err instanceof Error && err.name === "AbortError";
|
|
3797
|
+
if (isAbortError && start.perCallAbort.signal.aborted) {
|
|
3798
|
+
const reason = typeof start.perCallAbort.signal.reason === "string" ? start.perCallAbort.signal.reason : "cancelled-by-user";
|
|
3799
|
+
await ctx.hooks.callHook("tool:cancelled", {
|
|
3800
|
+
...buildToolHookBase(ctx, start.turnId, start.callId, start.name, start.displayName, start.input),
|
|
3801
|
+
reason,
|
|
3802
|
+
runToolCounts: start.runToolCounts
|
|
3803
|
+
});
|
|
3804
|
+
return {
|
|
3805
|
+
id: start.callId,
|
|
3806
|
+
content: TOOL_USE_CANCELLED_MESSAGE,
|
|
3807
|
+
isError: true
|
|
3808
|
+
};
|
|
3809
|
+
}
|
|
3810
|
+
if (ctx.signal.aborted || isAbortError) return {
|
|
3811
|
+
id: start.callId,
|
|
3812
|
+
content: cancelMessage(),
|
|
3813
|
+
isError: true
|
|
3814
|
+
};
|
|
3815
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
3816
|
+
const errorCtx = {
|
|
3817
|
+
...buildToolHookBase(ctx, start.turnId, start.callId, start.name, start.displayName, start.input),
|
|
3818
|
+
error
|
|
3819
|
+
};
|
|
3820
|
+
await ctx.hooks.callHook("tool:error", errorCtx);
|
|
3821
|
+
const emitted = await emitToolResult(ctx, {
|
|
3822
|
+
turnId: start.turnId,
|
|
3823
|
+
callId: start.callId,
|
|
3824
|
+
name: start.name,
|
|
3825
|
+
displayName: start.displayName,
|
|
3826
|
+
input: start.input,
|
|
3827
|
+
output: errorCtx.result ?? `Tool error: ${error.message}`,
|
|
3828
|
+
isError: true,
|
|
3829
|
+
runToolCounts: start.runToolCounts,
|
|
3830
|
+
...start.coercions ? { coercions: start.coercions } : {}
|
|
3831
|
+
});
|
|
3832
|
+
return {
|
|
3833
|
+
id: start.callId,
|
|
3834
|
+
content: emitted.output,
|
|
3835
|
+
...emitted.isError ? { isError: true } : {}
|
|
3836
|
+
};
|
|
3837
|
+
}
|
|
3838
|
+
function serializeToolFailure(failure) {
|
|
3839
|
+
if (failure instanceof Error) {
|
|
3840
|
+
const codeValue = Reflect.get(failure, "code");
|
|
3841
|
+
const code = typeof codeValue === "number" ? codeValue : void 0;
|
|
3842
|
+
return {
|
|
3843
|
+
name: failure.name,
|
|
3844
|
+
message: failure.message,
|
|
3845
|
+
...code !== void 0 ? { code } : {},
|
|
3846
|
+
constructorName: failure.constructor?.name
|
|
3847
|
+
};
|
|
3848
|
+
}
|
|
3849
|
+
return {
|
|
3850
|
+
name: "Error",
|
|
3851
|
+
message: String(failure)
|
|
3852
|
+
};
|
|
3853
|
+
}
|
|
3854
|
+
function hasDurableMap(promise) {
|
|
3855
|
+
return typeof Reflect.get(promise, "map") === "function";
|
|
3856
|
+
}
|
|
3857
|
+
function errorFromSerializedFailure(failure) {
|
|
3858
|
+
const error = new Error(failure.message);
|
|
3859
|
+
error.name = failure.name;
|
|
3860
|
+
if (failure.code !== void 0) Object.defineProperty(error, "code", {
|
|
3861
|
+
value: failure.code,
|
|
3862
|
+
enumerable: true
|
|
3863
|
+
});
|
|
3864
|
+
if (failure.constructorName && failure.constructorName !== failure.name) Object.defineProperty(error, "constructorName", {
|
|
3865
|
+
value: failure.constructorName,
|
|
3866
|
+
enumerable: true
|
|
3867
|
+
});
|
|
3868
|
+
return error;
|
|
3869
|
+
}
|
|
3870
|
+
async function executeNativeToolBatch(ctx, toolCalls, turnId) {
|
|
3495
3871
|
if (toolCalls.length === 0) return [];
|
|
3496
3872
|
const N = toolCalls.length;
|
|
3497
3873
|
const maxConcurrent = Math.max(1, ctx.maxConcurrentTools ?? DEFAULT_MAX_CONCURRENT_TOOLS);
|
|
@@ -3530,6 +3906,7 @@ async function executeToolBatch(ctx, toolCalls, turnId) {
|
|
|
3530
3906
|
const isUserCancel = typeof result.content === "string" && result.content === "[Tool call cancelled by user]";
|
|
3531
3907
|
if (result.isError && !isUserCancel && call.name === SHELL_TOOL_NAME && !siblingAbort.signal.aborted) siblingAbort.abort(SHELL_CASCADE_REASON);
|
|
3532
3908
|
}, (err) => {
|
|
3909
|
+
if (ctx.shouldRethrowToolError?.(err)) throw err;
|
|
3533
3910
|
const isAbort = siblingAbort.signal.aborted || ctx.signal.aborted || err instanceof Error && err.name === "AbortError";
|
|
3534
3911
|
results[index] = {
|
|
3535
3912
|
id: call.id,
|
|
@@ -5104,6 +5481,8 @@ async function synthesizeMissingToolResults(turns, syntheticTurnId, runId, provi
|
|
|
5104
5481
|
function resolveBehavior(agentBehavior, runBehavior) {
|
|
5105
5482
|
return {
|
|
5106
5483
|
maxConcurrentTools: runBehavior?.maxConcurrentTools ?? agentBehavior?.maxConcurrentTools,
|
|
5484
|
+
toolBatchExecutor: runBehavior?.toolBatchExecutor ?? agentBehavior?.toolBatchExecutor,
|
|
5485
|
+
shouldRethrowToolError: runBehavior?.shouldRethrowToolError ?? agentBehavior?.shouldRethrowToolError,
|
|
5107
5486
|
maxTurns: runBehavior?.maxTurns ?? agentBehavior?.maxTurns,
|
|
5108
5487
|
maxCostUsd: runBehavior?.maxCostUsd ?? agentBehavior?.maxCostUsd,
|
|
5109
5488
|
retry: runBehavior?.retry ?? agentBehavior?.retry,
|
|
@@ -5437,11 +5816,15 @@ function createAgent({ provider, name: agentName, system: agentSystem, tools: ag
|
|
|
5437
5816
|
abortController = new AbortController();
|
|
5438
5817
|
syncRunCounter();
|
|
5439
5818
|
const runId = `run_${++runCounter}`;
|
|
5819
|
+
const runStartedAt = await clock.now();
|
|
5820
|
+
const mintTurnId = async () => session ? await session.generateTurnId() : clock.randomUUID();
|
|
5440
5821
|
const promptLabel = typeof options.prompt === "string" ? options.prompt : Array.isArray(options.prompt) ? options.prompt.filter((p) => p.type === "text").map((p) => p.text).join("\n") : "";
|
|
5441
5822
|
session?.startRun(runId, promptLabel, {
|
|
5442
5823
|
...options.parentRunId ? { parentRunId: options.parentRunId } : {},
|
|
5443
5824
|
depth: typeof options.depth === "number" ? options.depth : 0
|
|
5444
5825
|
});
|
|
5826
|
+
const sessionRun = session?.runs.find((r) => r.id === runId);
|
|
5827
|
+
if (sessionRun) sessionRun.startedAt = runStartedAt;
|
|
5445
5828
|
if (session) {
|
|
5446
5829
|
await session.updateStatus("running");
|
|
5447
5830
|
await hooks.callHook("session:start", {
|
|
@@ -5450,7 +5833,6 @@ function createAgent({ provider, name: agentName, system: agentSystem, tools: ag
|
|
|
5450
5833
|
prompt: promptLabel
|
|
5451
5834
|
});
|
|
5452
5835
|
}
|
|
5453
|
-
const runStartedAt = await clock.now();
|
|
5454
5836
|
await hooks.callHook("agent:start", {
|
|
5455
5837
|
runId,
|
|
5456
5838
|
...options.parentRunId ? { parentRunId: options.parentRunId } : {},
|
|
@@ -5511,7 +5893,7 @@ function createAgent({ provider, name: agentName, system: agentSystem, tools: ag
|
|
|
5511
5893
|
const thinking = options.thinking ?? "off";
|
|
5512
5894
|
const model = options.model ?? provider.meta.defaultModel;
|
|
5513
5895
|
const resolvedBehavior = resolveBehavior(agentBehavior, options.behavior);
|
|
5514
|
-
const { maxConcurrentTools, maxTurns, maxCostUsd, maxTotalTokens, maxTokens, retry, thinkingBudget, modelOptions: behaviorModelOptions, schema, cache, toolOutputBudget, toolOutputBudgetExcludeTools, compactStrategy, compactThreshold, compactKeepTurns, thinkingDecay, dedupTools, toolBudgets, repeatGuard, elideStaleReads, toolDisclosure, toolSearch, surfaceMcpInstructions, persistThreshold, persistExcludeTools, persistDir, persistMaxBytes, strictToolPairing, maxConsecutivePauseTurns, persistTurns } = resolvedBehavior;
|
|
5896
|
+
const { maxConcurrentTools, toolBatchExecutor, shouldRethrowToolError, maxTurns, maxCostUsd, maxTotalTokens, maxTokens, retry, thinkingBudget, modelOptions: behaviorModelOptions, schema, cache, toolOutputBudget, toolOutputBudgetExcludeTools, compactStrategy, compactThreshold, compactKeepTurns, thinkingDecay, dedupTools, toolBudgets, repeatGuard, elideStaleReads, toolDisclosure, toolSearch, surfaceMcpInstructions, persistThreshold, persistExcludeTools, persistDir, persistMaxBytes, strictToolPairing, maxConsecutivePauseTurns, persistTurns } = resolvedBehavior;
|
|
5515
5897
|
const modelOptions = options.modelOptions ?? behaviorModelOptions;
|
|
5516
5898
|
let system = options.system || agentSystem || "You are a helpful assistant.";
|
|
5517
5899
|
const baseSystemForBreakdown = renderSystemForWire(system);
|
|
@@ -5683,7 +6065,7 @@ function createAgent({ provider, name: agentName, system: agentSystem, tools: ag
|
|
|
5683
6065
|
const promptMsg = promptParts ? buildPromptMessage(provider, promptParts) : null;
|
|
5684
6066
|
const content = [...drainedNotifications, ...promptMsg ? promptMsg.content : []];
|
|
5685
6067
|
turns.push({
|
|
5686
|
-
id:
|
|
6068
|
+
id: await mintTurnId(),
|
|
5687
6069
|
runId,
|
|
5688
6070
|
role: promptMsg ? promptMsg.role : "user",
|
|
5689
6071
|
content,
|
|
@@ -5718,7 +6100,7 @@ function createAgent({ provider, name: agentName, system: agentSystem, tools: ag
|
|
|
5718
6100
|
const unregisterToolResultsSync = perTurnSync ? hooks.hook("tool-results:after", persistPendingTurns) : void 0;
|
|
5719
6101
|
async function flushTurns(opts = {}) {
|
|
5720
6102
|
if (!session) return;
|
|
5721
|
-
if (opts.failureFallback) await synthesizeMissingToolResults(turns, await
|
|
6103
|
+
if (opts.failureFallback) await synthesizeMissingToolResults(turns, await mintTurnId(), runId, provider, hooks, clock);
|
|
5722
6104
|
const remaining = turns.slice(lastPersistedTurnCount);
|
|
5723
6105
|
if (remaining.length > 0) {
|
|
5724
6106
|
await session.appendTurns(remaining);
|
|
@@ -5748,12 +6130,16 @@ function createAgent({ provider, name: agentName, system: agentSystem, tools: ag
|
|
|
5748
6130
|
turnRange: [runTurnStart, turns.length - 1]
|
|
5749
6131
|
});
|
|
5750
6132
|
}
|
|
6133
|
+
async function stampSessionRunEnd() {
|
|
6134
|
+
const run = session?.runs.find((r) => r.id === runId);
|
|
6135
|
+
if (run) run.endedAt = await clock.now();
|
|
6136
|
+
}
|
|
5751
6137
|
const uninstallAllowedToolsGate = installAllowedToolsGate(hooks, skillActivationState);
|
|
5752
6138
|
const uninstallToolBudgets = installToolBudgetsGate(hooks, () => toolBudgets, (msg) => steeringQueue.push(msg));
|
|
5753
6139
|
const uninstallRepeatGuard = installRepeatGuard(hooks, () => repeatGuard, () => abortController?.abort());
|
|
5754
6140
|
const uninstallDedupTools = installDedupToolsGate(hooks, () => dedupTools, () => session ?? void 0);
|
|
5755
6141
|
const uninstallLazyDisclosureGate = installLazyDisclosureGate(hooks, disclosure.lazyCanonicalNames, unlocked, discoveryToolName);
|
|
5756
|
-
const runStartMs =
|
|
6142
|
+
const runStartMs = runStartedAt;
|
|
5757
6143
|
const runDepth = typeof options.depth === "number" ? options.depth : 0;
|
|
5758
6144
|
try {
|
|
5759
6145
|
const stats = await runLoop({
|
|
@@ -5774,6 +6160,8 @@ function createAgent({ provider, name: agentName, system: agentSystem, tools: ag
|
|
|
5774
6160
|
system,
|
|
5775
6161
|
thinking,
|
|
5776
6162
|
...maxConcurrentTools !== void 0 ? { maxConcurrentTools } : {},
|
|
6163
|
+
...toolBatchExecutor !== void 0 ? { toolBatchExecutor } : {},
|
|
6164
|
+
...shouldRethrowToolError !== void 0 ? { shouldRethrowToolError } : {},
|
|
5777
6165
|
signal: abortController.signal,
|
|
5778
6166
|
execution: executionContext,
|
|
5779
6167
|
handle: executionHandle,
|
|
@@ -5781,7 +6169,7 @@ function createAgent({ provider, name: agentName, system: agentSystem, tools: ag
|
|
|
5781
6169
|
followUpQueue,
|
|
5782
6170
|
turns,
|
|
5783
6171
|
runId,
|
|
5784
|
-
generateTurnId:
|
|
6172
|
+
generateTurnId: mintTurnId,
|
|
5785
6173
|
clock,
|
|
5786
6174
|
maxTurns,
|
|
5787
6175
|
...maxCostUsd !== void 0 ? { maxCostUsd } : {},
|
|
@@ -5846,6 +6234,7 @@ function createAgent({ provider, name: agentName, system: agentSystem, tools: ag
|
|
|
5846
6234
|
turnUsage: stats.turnUsage,
|
|
5847
6235
|
cost: parentTurnCost > 0 ? parentTurnCost : void 0
|
|
5848
6236
|
});
|
|
6237
|
+
await stampSessionRunEnd();
|
|
5849
6238
|
await finalizeSession("aborted");
|
|
5850
6239
|
await hooks.callHook("agent:done", finalStats);
|
|
5851
6240
|
return finalStats;
|
|
@@ -5857,6 +6246,7 @@ function createAgent({ provider, name: agentName, system: agentSystem, tools: ag
|
|
|
5857
6246
|
turnUsage: stats.turnUsage,
|
|
5858
6247
|
cost: parentTurnCost > 0 ? parentTurnCost : void 0
|
|
5859
6248
|
});
|
|
6249
|
+
await stampSessionRunEnd();
|
|
5860
6250
|
await finalizeSession("completed");
|
|
5861
6251
|
await hooks.callHook("agent:done", finalStats);
|
|
5862
6252
|
return finalStats;
|
|
@@ -5869,6 +6259,7 @@ function createAgent({ provider, name: agentName, system: agentSystem, tools: ag
|
|
|
5869
6259
|
...typeof abortReason === "string" && abortReason.length > 0 ? { reason: abortReason } : {}
|
|
5870
6260
|
});
|
|
5871
6261
|
session?.abortRun(runId);
|
|
6262
|
+
await stampSessionRunEnd();
|
|
5872
6263
|
await finalizeSession("aborted");
|
|
5873
6264
|
const stats = {
|
|
5874
6265
|
totalIn: 0,
|
|
@@ -5883,6 +6274,7 @@ function createAgent({ provider, name: agentName, system: agentSystem, tools: ag
|
|
|
5883
6274
|
}
|
|
5884
6275
|
if (err instanceof AgentBudgetExceededError) {
|
|
5885
6276
|
session?.abortRun(runId);
|
|
6277
|
+
await stampSessionRunEnd();
|
|
5886
6278
|
await finalizeSession("aborted");
|
|
5887
6279
|
await hooks.callHook("agent:done", {
|
|
5888
6280
|
totalIn: 0,
|
|
@@ -5895,6 +6287,7 @@ function createAgent({ provider, name: agentName, system: agentSystem, tools: ag
|
|
|
5895
6287
|
throw err;
|
|
5896
6288
|
}
|
|
5897
6289
|
session?.errorRun(runId, errorMessage(err));
|
|
6290
|
+
await stampSessionRunEnd();
|
|
5898
6291
|
await finalizeSession("error");
|
|
5899
6292
|
throw err;
|
|
5900
6293
|
} finally {
|
|
@@ -7752,4 +8145,4 @@ const writeFile$1 = {
|
|
|
7752
8145
|
//#endregion
|
|
7753
8146
|
export { resolveTasksDir as A, effectiveContextWindow as B, PERSISTED_STUB_PREFIX as C, maybePersistToolResult as D, cleanupPersistedSession as E, BUILTIN_PROVIDERS as F, modelOptionsFor as G, getContextWindow as H, OUTPUT_RESERVE_TOKENS as I, openaiDescriptor as J, modelSupportsReasoning as K, anthropicDescriptor as L, hashContent as M, readStateKey as N, resolveMcpWarningsDir as O, resolveReadStateMap as P, cerebrasDescriptor as R, validateToolArgs as S, buildPersistedStub as T, getModelInfo as U, enabledModelOptions as V, localDescriptor as W, piIdOf as X, openrouterDescriptor as Y, restoreModelOptions as Z, shell as _, multiEdit as a, TOOL_USE_CANCELLED_MESSAGE as b, grep as c, createAgent as d, createToolSearchTool as f, createShellTool as g, createSkillsReadTool as h, readFile$1 as i, getReadState as j, resolvePersistDir as k, glob$1 as l, createSkillsRunScriptTool as m, createSpawnTool as n, listFiles as o, createSkillsUseTool as p, modelsForDescriptor as q, shellKill as r, createInteractionTool as s, writeFile$1 as t, edit as u, INTERRUPT_MESSAGE_FOR_TOOL_USE as v, PERSISTENCE_PREVIEW_BYTES as w, TOOL_USE_SKIPPED_MESSAGE as x, SHELL_CASCADE_CANCEL_MESSAGE as y, credKeyOf as z };
|
|
7754
8147
|
|
|
7755
|
-
//# sourceMappingURL=tools-
|
|
8148
|
+
//# sourceMappingURL=tools-CAdllmWO.js.map
|