blun-king-cli 9.1.641 → 9.1.642
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 +15 -0
- package/bin/blun.js +0 -0
- package/bin/core-bootstrap.js +0 -0
- package/bin/king.js +0 -0
- package/bin/launcher-mode.js +0 -0
- package/bin/launcher-runtime.js +0 -0
- package/bin/managed-node.js +0 -0
- package/bin/native-command-runner.js +0 -0
- package/bin/native-module-repair.js +0 -0
- package/bin/node-runtime.js +0 -0
- package/bin/node-version.js +0 -0
- package/bin/plugin-bootstrap.js +0 -0
- package/bin/private-paths.js +0 -0
- package/bin/standard-tools-bootstrap.js +0 -0
- package/bin/update-copy.js +0 -0
- package/bin/update-lease.js +0 -0
- package/bin/update-notice.js +0 -0
- package/blun.mjs +1117 -85
- package/package.json +1 -1
- package/telegram-plugin/dist/bridge.mjs +8 -0
- package/worker-host.mjs +237 -54
package/worker-host.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// BLUN_BUILD_INPUT_SHA256:
|
|
2
|
+
// BLUN_BUILD_INPUT_SHA256:e50c78300e52dc6fc7d8003478fe2fa01fe7fdff8b1a749e108e6627de244e7e
|
|
3
3
|
/*! wasm-webp 0.1.0
|
|
4
4
|
MIT License
|
|
5
5
|
|
|
@@ -21308,7 +21308,7 @@ const FLAG_DEFINITIONS = [
|
|
|
21308
21308
|
title: "Session queue policies",
|
|
21309
21309
|
description: "Apply explicitly persisted session queue admission rules.",
|
|
21310
21310
|
env: "BLUN_EXPERIMENTAL_QUEUE_POLICIES",
|
|
21311
|
-
default:
|
|
21311
|
+
default: true,
|
|
21312
21312
|
surface: "core"
|
|
21313
21313
|
},
|
|
21314
21314
|
{
|
|
@@ -29638,6 +29638,59 @@ var DenyAllPermissionPolicy = class {
|
|
|
29638
29638
|
};
|
|
29639
29639
|
}
|
|
29640
29640
|
};
|
|
29641
|
+
var InputControl = class {
|
|
29642
|
+
epoch = 0;
|
|
29643
|
+
stopped = false;
|
|
29644
|
+
provider;
|
|
29645
|
+
preparations = /* @__PURE__ */ new Set();
|
|
29646
|
+
listeners = /* @__PURE__ */ new Set();
|
|
29647
|
+
onChange(listener) {
|
|
29648
|
+
this.listeners.add(listener);
|
|
29649
|
+
return () => {
|
|
29650
|
+
this.listeners.delete(listener);
|
|
29651
|
+
};
|
|
29652
|
+
}
|
|
29653
|
+
changed(stop = false) {
|
|
29654
|
+
this.epoch++;
|
|
29655
|
+
this.stopped ||= stop;
|
|
29656
|
+
this.provider?.abort(new DOMException("INPUT_SUPERSEDED", "AbortError"));
|
|
29657
|
+
for (const controller of this.preparations) controller.abort(new DOMException("INPUT_SUPERSEDED", "AbortError"));
|
|
29658
|
+
for (const listener of this.listeners) listener();
|
|
29659
|
+
}
|
|
29660
|
+
async prepare(signal, operation) {
|
|
29661
|
+
const controller = new AbortController();
|
|
29662
|
+
this.preparations.add(controller);
|
|
29663
|
+
const preparationSignal = AbortSignal.any([signal, controller.signal]);
|
|
29664
|
+
try {
|
|
29665
|
+
return await abortable(Promise.resolve().then(() => {
|
|
29666
|
+
preparationSignal.throwIfAborted();
|
|
29667
|
+
return operation(preparationSignal);
|
|
29668
|
+
}), preparationSignal);
|
|
29669
|
+
} finally {
|
|
29670
|
+
this.preparations.delete(controller);
|
|
29671
|
+
}
|
|
29672
|
+
}
|
|
29673
|
+
beginProvider() {
|
|
29674
|
+
const controller = new AbortController();
|
|
29675
|
+
this.provider = controller;
|
|
29676
|
+
return controller;
|
|
29677
|
+
}
|
|
29678
|
+
endProvider(controller) {
|
|
29679
|
+
if (this.provider === controller) this.provider = void 0;
|
|
29680
|
+
}
|
|
29681
|
+
};
|
|
29682
|
+
var controls = /* @__PURE__ */ new WeakMap();
|
|
29683
|
+
function inputControl(signal) {
|
|
29684
|
+
let control = controls.get(signal);
|
|
29685
|
+
if (control === void 0) {
|
|
29686
|
+
control = new InputControl();
|
|
29687
|
+
controls.set(signal, control);
|
|
29688
|
+
}
|
|
29689
|
+
return control;
|
|
29690
|
+
}
|
|
29691
|
+
function inheritInputControl(signal, control) {
|
|
29692
|
+
if (control !== void 0) controls.set(signal, control);
|
|
29693
|
+
}
|
|
29641
29694
|
function migrateToolCall(toolCall) {
|
|
29642
29695
|
const { function: fn, ...rest } = toolCall;
|
|
29643
29696
|
return {
|
|
@@ -29924,8 +29977,11 @@ var FileSystemAgentRecordPersistence = class {
|
|
|
29924
29977
|
this.shouldClear = false;
|
|
29925
29978
|
const content = (this.options.blobStore !== void 0 ? await Promise.all(batch.map((record) => this.options.blobStore.offload(record))) : batch).map((e) => JSON.stringify(e) + "\n").join("");
|
|
29926
29979
|
const directory = dirname$3(this.filePath);
|
|
29927
|
-
await mkdir(directory, {
|
|
29928
|
-
|
|
29980
|
+
await mkdir(directory, {
|
|
29981
|
+
recursive: true,
|
|
29982
|
+
mode: 448
|
|
29983
|
+
});
|
|
29984
|
+
const fh = await open(this.filePath, shouldClear ? "w" : "a", 384);
|
|
29929
29985
|
try {
|
|
29930
29986
|
const before = await fh.stat();
|
|
29931
29987
|
if (shouldClear || before.size === 0) this.persistedRecordCount = 0;
|
|
@@ -183420,7 +183476,13 @@ function getSubagentExecutionCompletion(handle) {
|
|
|
183420
183476
|
var SessionSubagentHost = class {
|
|
183421
183477
|
session;
|
|
183422
183478
|
ownerAgentId;
|
|
183423
|
-
|
|
183479
|
+
inputLeases = /* @__PURE__ */ new WeakMap();
|
|
183480
|
+
assertInputLease(options) {
|
|
183481
|
+
const lease = this.inputLeases.get(options);
|
|
183482
|
+
if (lease?.active?.runInBackground) return;
|
|
183483
|
+
if (lease !== void 0 && (lease.control.stopped || lease.control.epoch !== lease.epoch)) throw new DOMException("INPUT_SUPERSEDED", "AbortError");
|
|
183484
|
+
}
|
|
183485
|
+
admissionClosed = false;
|
|
183424
183486
|
operations = new ExecutionLedger();
|
|
183425
183487
|
childExecutions = new ExecutionLedger();
|
|
183426
183488
|
preparedDisposers = /* @__PURE__ */ new Set();
|
|
@@ -183455,8 +183517,16 @@ var SessionSubagentHost = class {
|
|
|
183455
183517
|
assertAdmissionOpen() {
|
|
183456
183518
|
if (this.admissionClosed) throw new Error("Subagent admission is closed for quiescence");
|
|
183457
183519
|
}
|
|
183458
|
-
runOperation(id, operation) {
|
|
183520
|
+
runOperation(id, operation, input) {
|
|
183459
183521
|
this.assertAdmissionOpen();
|
|
183522
|
+
if (input !== void 0) {
|
|
183523
|
+
const control = inputControl(input.signal);
|
|
183524
|
+
this.inputLeases.set(input, {
|
|
183525
|
+
control,
|
|
183526
|
+
epoch: control.epoch
|
|
183527
|
+
});
|
|
183528
|
+
this.assertInputLease(input);
|
|
183529
|
+
}
|
|
183460
183530
|
const completion = operation();
|
|
183461
183531
|
this.operations.track(id, completion);
|
|
183462
183532
|
return completion;
|
|
@@ -183490,7 +183560,7 @@ var SessionSubagentHost = class {
|
|
|
183490
183560
|
return this.session.getReadyAgent(currentId);
|
|
183491
183561
|
}
|
|
183492
183562
|
async spawn(options) {
|
|
183493
|
-
return this.runOperation("spawn", () => this.spawnInner(options));
|
|
183563
|
+
return this.runOperation("spawn", () => this.spawnInner(options), options);
|
|
183494
183564
|
}
|
|
183495
183565
|
async spawnInner(options) {
|
|
183496
183566
|
options.signal.throwIfAborted();
|
|
@@ -183522,7 +183592,7 @@ var SessionSubagentHost = class {
|
|
|
183522
183592
|
});
|
|
183523
183593
|
}
|
|
183524
183594
|
async resume(agentId, options) {
|
|
183525
|
-
return this.runOperation("resume", () => this.resumeInner(agentId, options));
|
|
183595
|
+
return this.runOperation("resume", () => this.resumeInner(agentId, options), options);
|
|
183526
183596
|
}
|
|
183527
183597
|
async resumeInner(agentId, options) {
|
|
183528
183598
|
options.signal.throwIfAborted();
|
|
@@ -183549,7 +183619,7 @@ var SessionSubagentHost = class {
|
|
|
183549
183619
|
});
|
|
183550
183620
|
}
|
|
183551
183621
|
async retry(agentId, options) {
|
|
183552
|
-
return this.runOperation("retry", () => this.retryInner(agentId, options));
|
|
183622
|
+
return this.runOperation("retry", () => this.retryInner(agentId, options), options);
|
|
183553
183623
|
}
|
|
183554
183624
|
async retryInner(agentId, options) {
|
|
183555
183625
|
options.signal.throwIfAborted();
|
|
@@ -183561,6 +183631,7 @@ var SessionSubagentHost = class {
|
|
|
183561
183631
|
modelAlias: parent.config.modelAlias,
|
|
183562
183632
|
actionStyle: parent.config.actionStyle
|
|
183563
183633
|
});
|
|
183634
|
+
this.assertInputLease(runOptions);
|
|
183564
183635
|
this.emitSubagentStarted(parent, agentId);
|
|
183565
183636
|
if (child.turn.retry("agent-host") === null) throw new Error(`Agent instance "${agentId}" could not start a retry turn`);
|
|
183566
183637
|
this.observeFirstRequest(child, runOptions);
|
|
@@ -183627,7 +183698,7 @@ var SessionSubagentHost = class {
|
|
|
183627
183698
|
const { parent, child, profileName } = await this.ensureIdleSubagent(agentId, token);
|
|
183628
183699
|
signal?.throwIfAborted();
|
|
183629
183700
|
const source = child.records.fileSource;
|
|
183630
|
-
if (source === void 0 || resolve(source.path) !== wire || source.protocolVersion !== "1.4" || child.context.history.length === 0 || child.config.systemPrompt.length === 0) throw new Error("Preserved subagent context could not be verified.");
|
|
183701
|
+
if (source === void 0 || resolve(source.path$1) !== wire || source.protocolVersion !== "1.4" || child.context.history.length === 0 || child.config.systemPrompt.length === 0) throw new Error("Preserved subagent context could not be verified.");
|
|
183631
183702
|
await sourceReference.refreshAfterReplay();
|
|
183632
183703
|
this.assertAdmissionOpen();
|
|
183633
183704
|
const reference = createHash("sha256").update(JSON.stringify([
|
|
@@ -183675,7 +183746,7 @@ var SessionSubagentHost = class {
|
|
|
183675
183746
|
completion,
|
|
183676
183747
|
update: (message) => this.updateActiveRun(agentId, completion, message)
|
|
183677
183748
|
});
|
|
183678
|
-
})
|
|
183749
|
+
}, options)
|
|
183679
183750
|
};
|
|
183680
183751
|
} catch (error) {
|
|
183681
183752
|
await dispose();
|
|
@@ -183763,6 +183834,7 @@ var SessionSubagentHost = class {
|
|
|
183763
183834
|
}
|
|
183764
183835
|
runWithActiveChild(childId, options, run) {
|
|
183765
183836
|
this.assertAdmissionOpen();
|
|
183837
|
+
this.assertInputLease(options);
|
|
183766
183838
|
if (this.activeChildren.has(childId)) throw new Error(`Agent instance "${childId}" is already running`);
|
|
183767
183839
|
const controller = new AbortController();
|
|
183768
183840
|
const unlinkAbortSignal = linkAbortSignal(options.signal, controller);
|
|
@@ -183771,10 +183843,22 @@ var SessionSubagentHost = class {
|
|
|
183771
183843
|
runInBackground: options.runInBackground
|
|
183772
183844
|
};
|
|
183773
183845
|
this.activeChildren.set(childId, active);
|
|
183774
|
-
const
|
|
183846
|
+
const runOptions = {
|
|
183775
183847
|
...options,
|
|
183776
183848
|
signal: controller.signal
|
|
183777
|
-
}
|
|
183849
|
+
};
|
|
183850
|
+
const lease = this.inputLeases.get(options);
|
|
183851
|
+
if (lease !== void 0) {
|
|
183852
|
+
lease.active = active;
|
|
183853
|
+
this.inputLeases.set(runOptions, lease);
|
|
183854
|
+
}
|
|
183855
|
+
const unlinkInput = lease?.control.onChange(() => {
|
|
183856
|
+
if (active.runInBackground) return;
|
|
183857
|
+
const child = this.session.getReadyAgent(childId);
|
|
183858
|
+
if (child !== void 0) child.turn.stop(child.turn.currentId);
|
|
183859
|
+
});
|
|
183860
|
+
const completion = run(runOptions).finally(() => {
|
|
183861
|
+
unlinkInput?.();
|
|
183778
183862
|
unlinkAbortSignal();
|
|
183779
183863
|
if (this.activeChildren.get(childId) === active) this.activeChildren.delete(childId);
|
|
183780
183864
|
});
|
|
@@ -183800,6 +183884,7 @@ var SessionSubagentHost = class {
|
|
|
183800
183884
|
}
|
|
183801
183885
|
async runPromptTurn(parent, childId, child, profileName, options) {
|
|
183802
183886
|
options.signal.throwIfAborted();
|
|
183887
|
+
this.assertInputLease(options);
|
|
183803
183888
|
await this.triggerSubagentStart(parent, profileName, options.prompt, options.signal);
|
|
183804
183889
|
options.signal.throwIfAborted();
|
|
183805
183890
|
let childPrompt = options.prompt;
|
|
@@ -183807,6 +183892,7 @@ var SessionSubagentHost = class {
|
|
|
183807
183892
|
const gitContext = await collectGitContext(child.kaos, child.config.cwd);
|
|
183808
183893
|
if (gitContext) childPrompt = `${gitContext}\n\n${childPrompt}`;
|
|
183809
183894
|
}
|
|
183895
|
+
this.assertInputLease(options);
|
|
183810
183896
|
this.emitSubagentStarted(parent, childId);
|
|
183811
183897
|
if (child.turn.prompt([{
|
|
183812
183898
|
type: "text",
|
|
@@ -183822,6 +183908,7 @@ var SessionSubagentHost = class {
|
|
|
183822
183908
|
while (remainingContinuations > 0 && result.length < SUMMARY_MIN_LENGTH) {
|
|
183823
183909
|
remainingContinuations -= 1;
|
|
183824
183910
|
options.signal.throwIfAborted();
|
|
183911
|
+
this.assertInputLease(options);
|
|
183825
183912
|
child.turn.prompt([{
|
|
183826
183913
|
type: "text",
|
|
183827
183914
|
text: summary_continuation_default
|
|
@@ -247986,6 +248073,11 @@ async function prepareSkippedToolCall(step, call) {
|
|
|
247986
248073
|
await dispatchToolCall(step, call, call.args);
|
|
247987
248074
|
return makeResolvedToolCallTask(makeErrorToolResult(call, call.args, output));
|
|
247988
248075
|
}
|
|
248076
|
+
function waitForPreparationBoundary(step, operation) {
|
|
248077
|
+
if (step.canStart?.() === false) return Promise.reject(new DOMException("INPUT_SUPERSEDED", "AbortError"));
|
|
248078
|
+
if (step.inputControl === void 0) return waitForToolBoundary(step, () => operation(step.signal));
|
|
248079
|
+
return step.inputControl.prepare(step.signal, (signal) => operation(signal));
|
|
248080
|
+
}
|
|
247989
248081
|
function waitForToolBoundary(step, operation) {
|
|
247990
248082
|
if (step.programmaticParentCallId === void 0) return Promise.resolve(operation());
|
|
247991
248083
|
step.signal.throwIfAborted();
|
|
@@ -248013,6 +248105,11 @@ function makeResolvedToolCallTask(result) {
|
|
|
248013
248105
|
async function runPrepareToolExecutionHook(step, call) {
|
|
248014
248106
|
const { hooks, signal, turnId, currentStep, llm } = step;
|
|
248015
248107
|
const { toolCall, args } = call;
|
|
248108
|
+
if (step.canStart?.() === false) return {
|
|
248109
|
+
kind: "blocked",
|
|
248110
|
+
args,
|
|
248111
|
+
output: "INPUT_SUPERSEDED"
|
|
248112
|
+
};
|
|
248016
248113
|
const hook = hooks?.prepareToolExecution;
|
|
248017
248114
|
if (hook === void 0) return {
|
|
248018
248115
|
kind: "allowed",
|
|
@@ -248064,7 +248161,7 @@ async function runAuthorizeToolExecutionHook(step, call, args, execution) {
|
|
|
248064
248161
|
const hook = hooks?.authorizeToolExecution;
|
|
248065
248162
|
if (hook === void 0) return void 0;
|
|
248066
248163
|
try {
|
|
248067
|
-
return await
|
|
248164
|
+
return await waitForPreparationBoundary(step, (preparationSignal) => hook({
|
|
248068
248165
|
toolCall: call.toolCall,
|
|
248069
248166
|
toolCalls: step.toolCalls,
|
|
248070
248167
|
tool: call.tool,
|
|
@@ -248072,7 +248169,7 @@ async function runAuthorizeToolExecutionHook(step, call, args, execution) {
|
|
|
248072
248169
|
execution,
|
|
248073
248170
|
turnId,
|
|
248074
248171
|
stepNumber: currentStep,
|
|
248075
|
-
signal,
|
|
248172
|
+
signal: preparationSignal,
|
|
248076
248173
|
llm
|
|
248077
248174
|
}));
|
|
248078
248175
|
} catch (error) {
|
|
@@ -248126,6 +248223,7 @@ async function runRunnableToolCall(step, call, effectiveArgs, metadata, executio
|
|
|
248126
248223
|
function createNestedToolInvoker(step, parent) {
|
|
248127
248224
|
const controller = new AbortController();
|
|
248128
248225
|
const parentSignal = AbortSignal.any([step.signal, controller.signal]);
|
|
248226
|
+
inheritInputControl(parentSignal, step.inputControl);
|
|
248129
248227
|
let accepting = true;
|
|
248130
248228
|
let stopped = false;
|
|
248131
248229
|
let sequence = 0;
|
|
@@ -248152,6 +248250,7 @@ function createNestedToolInvoker(step, parent) {
|
|
|
248152
248250
|
while (reservedIds.has(id));
|
|
248153
248251
|
reservedIds.add(id);
|
|
248154
248252
|
const signal = input.signal === void 0 ? parentSignal : AbortSignal.any([parentSignal, input.signal]);
|
|
248253
|
+
inheritInputControl(signal, step.inputControl);
|
|
248155
248254
|
const run = async () => {
|
|
248156
248255
|
if (stopped) throw new Error("A nested tool stopped the turn.");
|
|
248157
248256
|
signal.throwIfAborted();
|
|
@@ -248241,6 +248340,10 @@ async function finalizePendingToolResult(step, pendingResult) {
|
|
|
248241
248340
|
async function executeTool(step, execution, toolCall, toolName, metadata, invokeTool) {
|
|
248242
248341
|
const { dispatchEvent, signal, turnId } = step;
|
|
248243
248342
|
signal.throwIfAborted();
|
|
248343
|
+
if (step.canStart?.() === false) return {
|
|
248344
|
+
output: "INPUT_SUPERSEDED",
|
|
248345
|
+
isError: true
|
|
248346
|
+
};
|
|
248244
248347
|
const executePromise = execution.execute({
|
|
248245
248348
|
turnId,
|
|
248246
248349
|
toolCallId: toolCall.id,
|
|
@@ -248394,6 +248497,8 @@ async function dispatchToolCall(step, call, args, displayFields) {
|
|
|
248394
248497
|
*/
|
|
248395
248498
|
async function executeLoopStep(deps) {
|
|
248396
248499
|
const { turnId, signal, buildMessages, buildMessagesStrict, dispatchEvent, llm, tools, hooks, executionObserver, log, currentStep, maxRetryAttempts, checkpointBeforeRetry, recordUsage, onStepStarted } = deps;
|
|
248500
|
+
const control = inputControl(signal);
|
|
248501
|
+
const inputEpoch = control.epoch;
|
|
248397
248502
|
if (hooks?.beforeStep !== void 0) {
|
|
248398
248503
|
const beforeStep = await hooks.beforeStep({
|
|
248399
248504
|
turnId,
|
|
@@ -248412,10 +248517,13 @@ async function executeLoopStep(deps) {
|
|
|
248412
248517
|
turnId,
|
|
248413
248518
|
currentStep,
|
|
248414
248519
|
stepUuid,
|
|
248415
|
-
onStepStarted
|
|
248520
|
+
onStepStarted,
|
|
248521
|
+
acceptOutput: () => !control.stopped && control.epoch === inputEpoch
|
|
248416
248522
|
});
|
|
248417
248523
|
const prepareRequestBoundary = llm.prepareRequestBoundary?.bind(llm);
|
|
248418
248524
|
const step = {
|
|
248525
|
+
inputControl: control,
|
|
248526
|
+
canStart: () => !control.stopped && control.epoch === inputEpoch,
|
|
248419
248527
|
tools,
|
|
248420
248528
|
hooks,
|
|
248421
248529
|
executionObserver,
|
|
@@ -248431,6 +248539,7 @@ async function executeLoopStep(deps) {
|
|
|
248431
248539
|
messages,
|
|
248432
248540
|
tools: tools ?? [],
|
|
248433
248541
|
signal,
|
|
248542
|
+
boundarySignal: signal,
|
|
248434
248543
|
...stepEvents.callbacks
|
|
248435
248544
|
};
|
|
248436
248545
|
if (prepareRequestBoundary === void 0) await stepEvents.start();
|
|
@@ -248480,6 +248589,12 @@ async function executeLoopStep(deps) {
|
|
|
248480
248589
|
log
|
|
248481
248590
|
};
|
|
248482
248591
|
let response;
|
|
248592
|
+
const provider = control.beginProvider();
|
|
248593
|
+
chatParams = {
|
|
248594
|
+
...chatParams,
|
|
248595
|
+
signal: AbortSignal.any([signal, provider.signal])
|
|
248596
|
+
};
|
|
248597
|
+
if (control.stopped || control.epoch !== inputEpoch) provider.abort();
|
|
248483
248598
|
try {
|
|
248484
248599
|
response = await chatWithRetry({
|
|
248485
248600
|
...retryInput,
|
|
@@ -248487,35 +248602,50 @@ async function executeLoopStep(deps) {
|
|
|
248487
248602
|
});
|
|
248488
248603
|
} catch (error) {
|
|
248489
248604
|
await stepEvents.drain();
|
|
248490
|
-
if (
|
|
248491
|
-
|
|
248492
|
-
|
|
248493
|
-
turnStep: `${turnId}.${String(currentStep)}`,
|
|
248494
|
-
model: llm.modelName
|
|
248495
|
-
});
|
|
248496
|
-
const strictMessages = await buildMessagesStrict();
|
|
248497
|
-
signal.throwIfAborted();
|
|
248498
|
-
let strictParams = {
|
|
248499
|
-
...chatParams,
|
|
248500
|
-
messages: strictMessages
|
|
248605
|
+
if (provider.signal.aborted && !signal.aborted) response = {
|
|
248606
|
+
toolCalls: [],
|
|
248607
|
+
usage: emptyUsage()
|
|
248501
248608
|
};
|
|
248502
|
-
if (
|
|
248503
|
-
|
|
248504
|
-
|
|
248505
|
-
|
|
248506
|
-
...retryInput,
|
|
248507
|
-
params: strictParams
|
|
248508
|
-
});
|
|
248509
|
-
} catch (strictError) {
|
|
248510
|
-
log?.error("strict resend still rejected by provider; request remains wire-invalid", {
|
|
248609
|
+
else if (buildMessagesStrict === void 0 || !isRecoverableRequestStructureError(error) || prepareRequestBoundary !== void 0 && stepEvents.hasOutput) throw error;
|
|
248610
|
+
else try {
|
|
248611
|
+
signal.throwIfAborted();
|
|
248612
|
+
log?.warn("provider rejected request structure; resending with strict projection", {
|
|
248511
248613
|
turnStep: `${turnId}.${String(currentStep)}`,
|
|
248512
|
-
model: llm.modelName
|
|
248513
|
-
originalError: errorMessage$4(error),
|
|
248514
|
-
strictError: errorMessage$4(strictError)
|
|
248614
|
+
model: llm.modelName
|
|
248515
248615
|
});
|
|
248516
|
-
|
|
248616
|
+
const strictMessages = await buildMessagesStrict();
|
|
248617
|
+
signal.throwIfAborted();
|
|
248618
|
+
let strictParams = {
|
|
248619
|
+
...chatParams,
|
|
248620
|
+
messages: strictMessages
|
|
248621
|
+
};
|
|
248622
|
+
if (prepareRequestBoundary !== void 0) strictParams = await prepareRequestBoundary(strictParams, buildMessagesStrict);
|
|
248623
|
+
signal.throwIfAborted();
|
|
248624
|
+
try {
|
|
248625
|
+
response = await chatWithRetry({
|
|
248626
|
+
...retryInput,
|
|
248627
|
+
params: strictParams
|
|
248628
|
+
});
|
|
248629
|
+
} catch (strictError) {
|
|
248630
|
+
if (provider.signal.aborted) throw strictError;
|
|
248631
|
+
log?.error("strict resend still rejected by provider; request remains wire-invalid", {
|
|
248632
|
+
turnStep: `${turnId}.${String(currentStep)}`,
|
|
248633
|
+
model: llm.modelName,
|
|
248634
|
+
originalError: errorMessage$4(error),
|
|
248635
|
+
strictError: errorMessage$4(strictError)
|
|
248636
|
+
});
|
|
248637
|
+
throw strictError;
|
|
248638
|
+
}
|
|
248639
|
+
log?.info("recovered after strict resend", { turnStep: `${turnId}.${String(currentStep)}` });
|
|
248640
|
+
} catch (strictBoundaryError) {
|
|
248641
|
+
if (!provider.signal.aborted || signal.aborted) throw strictBoundaryError;
|
|
248642
|
+
response = {
|
|
248643
|
+
toolCalls: [],
|
|
248644
|
+
usage: emptyUsage()
|
|
248645
|
+
};
|
|
248517
248646
|
}
|
|
248518
|
-
|
|
248647
|
+
} finally {
|
|
248648
|
+
control.endProvider(provider);
|
|
248519
248649
|
}
|
|
248520
248650
|
await stepEvents.start();
|
|
248521
248651
|
await stepEvents.drain();
|
|
@@ -248526,6 +248656,7 @@ async function executeLoopStep(deps) {
|
|
|
248526
248656
|
if (effectiveStopReason === "tool_use") {
|
|
248527
248657
|
if ((await runToolCallBatch(step, response)).stopTurn) effectiveStopReason = "end_turn";
|
|
248528
248658
|
}
|
|
248659
|
+
if (control.epoch !== inputEpoch) effectiveStopReason = control.stopped ? "end_turn" : "tool_use";
|
|
248529
248660
|
signal.throwIfAborted();
|
|
248530
248661
|
await dispatchEvent({
|
|
248531
248662
|
type: "step.end",
|
|
@@ -248636,8 +248767,10 @@ function createStepEventGate(deps) {
|
|
|
248636
248767
|
return startPromise;
|
|
248637
248768
|
};
|
|
248638
248769
|
const enqueue = (dispatch) => {
|
|
248770
|
+
if (!deps.acceptOutput()) return Promise.resolve();
|
|
248639
248771
|
hasOutput = true;
|
|
248640
248772
|
const queued = eventQueue.then(async () => {
|
|
248773
|
+
if (!deps.acceptOutput()) return;
|
|
248641
248774
|
await start();
|
|
248642
248775
|
await dispatch();
|
|
248643
248776
|
});
|
|
@@ -248741,6 +248874,10 @@ async function runTurn(input) {
|
|
|
248741
248874
|
try {
|
|
248742
248875
|
while (true) {
|
|
248743
248876
|
signal.throwIfAborted();
|
|
248877
|
+
if (inputControl(signal).stopped) {
|
|
248878
|
+
stopReason = "aborted";
|
|
248879
|
+
break;
|
|
248880
|
+
}
|
|
248744
248881
|
if (maxSteps !== void 0 && maxSteps > 0 && steps >= maxSteps) throw createMaxStepsExceededError(maxSteps);
|
|
248745
248882
|
steps += 1;
|
|
248746
248883
|
const stepNumber = steps;
|
|
@@ -248762,6 +248899,10 @@ async function runTurn(input) {
|
|
|
248762
248899
|
onStepStarted: setActiveStep.bind(void 0, stepNumber)
|
|
248763
248900
|
});
|
|
248764
248901
|
activeStep = void 0;
|
|
248902
|
+
if (inputControl(signal).stopped) {
|
|
248903
|
+
stopReason = "aborted";
|
|
248904
|
+
break;
|
|
248905
|
+
}
|
|
248765
248906
|
if (stepResult.stopReason === "tool_use") continue;
|
|
248766
248907
|
const terminalStopReason = stepResult.stopReason;
|
|
248767
248908
|
stopReason = terminalStopReason;
|
|
@@ -249455,7 +249596,8 @@ var init_prompt = __esmMin((() => {
|
|
|
249455
249596
|
sessionAdmissionSteerRequestSchema = admissionReadIdentitySchema.omit({ timeout_ms: true }).extend({ expected_turn_id: admissionTurnSchema });
|
|
249456
249597
|
sessionAdmissionCancelRequestSchema = object({
|
|
249457
249598
|
scope: admissionIdentitySchema,
|
|
249458
|
-
turn_id: admissionTurnSchema
|
|
249599
|
+
turn_id: admissionTurnSchema,
|
|
249600
|
+
graceful: boolean$1().optional()
|
|
249459
249601
|
}).strict();
|
|
249460
249602
|
sessionAdmissionCancelResponseSchema = sessionAdmissionCancelRequestSchema.extend({
|
|
249461
249603
|
session_id: string().min(1),
|
|
@@ -265214,6 +265356,7 @@ var TurnFlow = class {
|
|
|
265214
265356
|
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 2147483647) throw new Error("INVALID_PROMPT_TIMEOUT");
|
|
265215
265357
|
}
|
|
265216
265358
|
this.assertAdmissionOpen();
|
|
265359
|
+
this.stopRequested = false;
|
|
265217
265360
|
this.agent.records.logRecord({
|
|
265218
265361
|
type: "turn.prompt",
|
|
265219
265362
|
input,
|
|
@@ -265230,6 +265373,7 @@ var TurnFlow = class {
|
|
|
265230
265373
|
}
|
|
265231
265374
|
steer(input, origin = USER_PROMPT_ORIGIN) {
|
|
265232
265375
|
this.assertAdmissionOpen();
|
|
265376
|
+
this.stopRequested = false;
|
|
265233
265377
|
this.agent.records.logRecord({
|
|
265234
265378
|
type: "turn.steer",
|
|
265235
265379
|
input,
|
|
@@ -265243,7 +265387,7 @@ var TurnFlow = class {
|
|
|
265243
265387
|
}
|
|
265244
265388
|
/** Buffer only into the currently active turn; never launch from an idle state. */
|
|
265245
265389
|
steerActive(input, expectedTurnId, origin = USER_PROMPT_ORIGIN, onDisposition) {
|
|
265246
|
-
if (this.admissionClosed) return null;
|
|
265390
|
+
if (this.admissionClosed || this.stopRequested) return null;
|
|
265247
265391
|
const active = this.activeTurn;
|
|
265248
265392
|
if (active === null || active === "resuming" || !active.acceptingSteers || expectedTurnId !== void 0 && expectedTurnId !== this.currentId) return null;
|
|
265249
265393
|
this.agent.records.logRecord({
|
|
@@ -265334,7 +265478,19 @@ var TurnFlow = class {
|
|
|
265334
265478
|
this.turnId += 1;
|
|
265335
265479
|
this.activeTurn = "resuming";
|
|
265336
265480
|
}
|
|
265337
|
-
|
|
265481
|
+
stopRequested = false;
|
|
265482
|
+
stop(turnId) {
|
|
265483
|
+
const active = this.activeTurn;
|
|
265484
|
+
if (turnId !== this.currentId) return;
|
|
265485
|
+
this.stopRequested = true;
|
|
265486
|
+
if (active === null || active === "resuming") return;
|
|
265487
|
+
this.agent.records.logRecord({
|
|
265488
|
+
type: "turn.cancel",
|
|
265489
|
+
turnId
|
|
265490
|
+
});
|
|
265491
|
+
inputControl(active.controller.signal).changed(true);
|
|
265492
|
+
}
|
|
265493
|
+
cancel(turnId, reason) {
|
|
265338
265494
|
this.agent.records.logRecord({
|
|
265339
265495
|
type: "turn.cancel",
|
|
265340
265496
|
turnId
|
|
@@ -265405,6 +265561,8 @@ var TurnFlow = class {
|
|
|
265405
265561
|
timeoutMs
|
|
265406
265562
|
});
|
|
265407
265563
|
this.nextSteerSequence += 1;
|
|
265564
|
+
const active = this.activeTurn;
|
|
265565
|
+
if (origin.kind !== "background_task" && active !== null && active !== "resuming") inputControl(active.controller.signal).changed();
|
|
265408
265566
|
}
|
|
265409
265567
|
flushSteerBuffer(turnId = this.currentId, throughSequence = Number.POSITIVE_INFINITY) {
|
|
265410
265568
|
if (this.steerBuffer.length === 0) return false;
|
|
@@ -265465,7 +265623,7 @@ var TurnFlow = class {
|
|
|
265465
265623
|
* draining into it via `flushSteerBuffer`.
|
|
265466
265624
|
*/
|
|
265467
265625
|
onCompactionFinished() {
|
|
265468
|
-
if (this.admissionClosed) return;
|
|
265626
|
+
if (this.admissionClosed || this.stopRequested) return;
|
|
265469
265627
|
if (this.steerBuffer.length === 0) return;
|
|
265470
265628
|
if (this.activeTurn !== null) return;
|
|
265471
265629
|
const next = this.steerBuffer.shift();
|
|
@@ -265494,7 +265652,7 @@ var TurnFlow = class {
|
|
|
265494
265652
|
try {
|
|
265495
265653
|
if (this.agent.goal.getGoal().goal?.status === "active") return finish(await this.driveGoal(firstTurnId, input, origin, signal));
|
|
265496
265654
|
const end = await this.runOneTurn(firstTurnId, input, origin, signal, true);
|
|
265497
|
-
if (this.agent.goal.getGoal().goal?.status === "active" && end.event.reason !== "cancelled" && end.event.reason !== "failed" && end.event.reason !== "filtered") return finish(await this.driveGoal(this.allocateTurnId(), [{
|
|
265655
|
+
if (this.agent.goal.getGoal().goal?.status === "active" && !inputControl(signal).stopped && end.event.reason !== "cancelled" && end.event.reason !== "failed" && end.event.reason !== "filtered") return finish(await this.driveGoal(this.allocateTurnId(), [{
|
|
265498
265656
|
type: "text",
|
|
265499
265657
|
text: GOAL_CONTINUATION_PROMPT
|
|
265500
265658
|
}], goalContinuationOrigin(origin), signal));
|
|
@@ -265532,6 +265690,11 @@ var TurnFlow = class {
|
|
|
265532
265690
|
let turnInput = input;
|
|
265533
265691
|
let turnOrigin = origin;
|
|
265534
265692
|
while (true) {
|
|
265693
|
+
if (inputControl(signal).stopped) return { event: {
|
|
265694
|
+
type: "turn.ended",
|
|
265695
|
+
turnId,
|
|
265696
|
+
reason: "cancelled"
|
|
265697
|
+
} };
|
|
265535
265698
|
const goalBeforeTurn = this.agent.goal.getGoal().goal;
|
|
265536
265699
|
if (goalBeforeTurn?.status === "active" && goalBeforeTurn.budget.overBudget) {
|
|
265537
265700
|
await this.agent.goal.markBlocked({ reason: "A configured budget was reached" });
|
|
@@ -265621,7 +265784,13 @@ var TurnFlow = class {
|
|
|
265621
265784
|
let completedResponse;
|
|
265622
265785
|
let errorEvent;
|
|
265623
265786
|
try {
|
|
265787
|
+
const checkStop = () => {
|
|
265788
|
+
signal.throwIfAborted();
|
|
265789
|
+
if (inputControl(signal).stopped) throw new DOMException("INPUT_STOPPED", "AbortError");
|
|
265790
|
+
};
|
|
265791
|
+
checkStop();
|
|
265624
265792
|
const promptHookEnded = await this.applyUserPromptHook(turnId, input, origin, signal, startedAt);
|
|
265793
|
+
checkStop();
|
|
265625
265794
|
if (promptHookEnded !== void 0) {
|
|
265626
265795
|
ended = promptHookEnded.event;
|
|
265627
265796
|
blockedByUserPromptHook = promptHookEnded.blocked;
|
|
@@ -265640,6 +265809,7 @@ var TurnFlow = class {
|
|
|
265640
265809
|
this.agent.log.warn("Turn-start observation failed");
|
|
265641
265810
|
}
|
|
265642
265811
|
signal.throwIfAborted();
|
|
265812
|
+
checkStop();
|
|
265643
265813
|
const stopReason = await this.runStepLoop(turnId, signal, input, origin, (response) => {
|
|
265644
265814
|
completedResponse = response;
|
|
265645
265815
|
});
|
|
@@ -265892,7 +266062,7 @@ var TurnFlow = class {
|
|
|
265892
266062
|
},
|
|
265893
266063
|
settleStep: async ({ signal: stepSignal }) => {
|
|
265894
266064
|
if (stopForGoalBudget) this.setActiveSteerAcceptance(turnId, false);
|
|
265895
|
-
await this.agent.fullCompaction.afterStep(stepSignal);
|
|
266065
|
+
if (!inputControl(stepSignal).stopped) await this.agent.fullCompaction.afterStep(stepSignal);
|
|
265896
266066
|
},
|
|
265897
266067
|
afterStep: async () => {
|
|
265898
266068
|
deduper.endStep();
|
|
@@ -269945,7 +270115,7 @@ var Agent$1 = class {
|
|
|
269945
270115
|
messages: await rebuildMessages()
|
|
269946
270116
|
};
|
|
269947
270117
|
let systemPrompt = this.effectiveSystemPrompt;
|
|
269948
|
-
const compacted = await this.fullCompaction.beforeStep(params.signal, {
|
|
270118
|
+
const compacted = await this.fullCompaction.beforeStep(params.boundarySignal ?? params.signal, {
|
|
269949
270119
|
messages: params.messages,
|
|
269950
270120
|
additionalMessages: steers.messages,
|
|
269951
270121
|
rebuildMessages,
|
|
@@ -270110,6 +270280,12 @@ var Agent$1 = class {
|
|
|
270110
270280
|
};
|
|
270111
270281
|
},
|
|
270112
270282
|
cancel: (payload) => {
|
|
270283
|
+
if (payload.graceful === true) {
|
|
270284
|
+
if (payload.turnId === void 0) throw new Error("STOP_TURN_REQUIRED");
|
|
270285
|
+
if (payload.turnId !== this.turn.currentId) return;
|
|
270286
|
+
this.turn.stop(payload.turnId);
|
|
270287
|
+
return Promise.all([this.turn.waitForExecutionEnd(), this.fullCompaction.waitForExecutionEnd()]).then(() => void 0);
|
|
270288
|
+
}
|
|
270113
270289
|
const waitForExecution = this.experimentalFlags.enabled("queue_policies") && payload.turnId !== void 0 && payload.turnId === this.turn.currentId;
|
|
270114
270290
|
if (this.turn.hasActiveTurn) this.telemetry.track("cancel", { from: "streaming" });
|
|
270115
270291
|
this.turn.cancel(payload.turnId, payload.cancellationReason === "timeout" ? new DOMException("Prompt execution timed out", "TimeoutError") : void 0);
|
|
@@ -335322,7 +335498,10 @@ async function appendSessionIndexEntry(homeDir, entry) {
|
|
|
335322
335498
|
recursive: true,
|
|
335323
335499
|
mode: 448
|
|
335324
335500
|
});
|
|
335325
|
-
await appendFile(indexPath, `${JSON.stringify(entry)}\n`,
|
|
335501
|
+
await appendFile(indexPath, `${JSON.stringify(entry)}\n`, {
|
|
335502
|
+
encoding: "utf-8",
|
|
335503
|
+
mode: 384
|
|
335504
|
+
});
|
|
335326
335505
|
}
|
|
335327
335506
|
async function readSessionIndex(homeDir, sessionsDir) {
|
|
335328
335507
|
let raw;
|
|
@@ -343390,12 +343569,14 @@ let SessionService = class SessionService extends Disposable {
|
|
|
343390
343569
|
sessionId: id,
|
|
343391
343570
|
agentId: "main",
|
|
343392
343571
|
expectedScope: request.scope,
|
|
343393
|
-
turnId: request.turn_id
|
|
343572
|
+
turnId: request.turn_id,
|
|
343573
|
+
graceful: request.graceful
|
|
343394
343574
|
});
|
|
343395
343575
|
return {
|
|
343396
343576
|
session_id: id,
|
|
343397
343577
|
scope: request.scope,
|
|
343398
343578
|
turn_id: request.turn_id,
|
|
343579
|
+
graceful: request.graceful,
|
|
343399
343580
|
settled: true
|
|
343400
343581
|
};
|
|
343401
343582
|
}
|
|
@@ -346436,13 +346617,14 @@ var Session = class {
|
|
|
346436
346617
|
this.ensureOpen();
|
|
346437
346618
|
await this.trackLocalInputRequest(() => this.rpc.cancel({ sessionId: this.id }));
|
|
346438
346619
|
}
|
|
346439
|
-
async cancelTurn(turnId, expectedScope) {
|
|
346620
|
+
async cancelTurn(turnId, expectedScope, graceful) {
|
|
346440
346621
|
this.ensureOpen();
|
|
346441
346622
|
if (!Number.isSafeInteger(turnId) || turnId < 0) throw new Error("INVALID_TURN_ID");
|
|
346442
346623
|
await this.trackLocalInputRequest(() => this.rpc.cancelTurn({
|
|
346443
346624
|
sessionId: this.id,
|
|
346444
346625
|
turnId,
|
|
346445
|
-
expectedScope
|
|
346626
|
+
expectedScope,
|
|
346627
|
+
graceful
|
|
346446
346628
|
}));
|
|
346447
346629
|
}
|
|
346448
346630
|
async setModel(model, options) {
|
|
@@ -347917,7 +348099,8 @@ var SDKRpcClientBase = class {
|
|
|
347917
348099
|
sessionId: input.sessionId,
|
|
347918
348100
|
agentId,
|
|
347919
348101
|
turnId: input.turnId,
|
|
347920
|
-
expectedScope: input.expectedScope
|
|
348102
|
+
expectedScope: input.expectedScope,
|
|
348103
|
+
graceful: input.graceful
|
|
347921
348104
|
});
|
|
347922
348105
|
}
|
|
347923
348106
|
async registerTool(input) {
|
|
@@ -350223,7 +350406,7 @@ function optionalBuildString(value) {
|
|
|
350223
350406
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
350224
350407
|
}
|
|
350225
350408
|
const BLUN_BUILD_INFO = {
|
|
350226
|
-
version: optionalBuildString("9.1.
|
|
350409
|
+
version: optionalBuildString("9.1.642"),
|
|
350227
350410
|
channel: typeof __BLUN_CHANNEL__ === "string" ? optionalBuildString(__BLUN_CHANNEL__) : void 0,
|
|
350228
350411
|
commit: typeof __BLUN_COMMIT__ === "string" ? optionalBuildString(__BLUN_COMMIT__) : void 0,
|
|
350229
350412
|
buildTarget: typeof __BLUN_BUILD_TARGET__ === "string" ? optionalBuildString(__BLUN_BUILD_TARGET__) : void 0
|