@tangle-network/agent-runtime 0.143.0 → 0.153.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 +32 -0
- package/dist/{activation-mi8TgSLM.js → activation-Bbic0THc.js} +3 -3
- package/dist/{activation-mi8TgSLM.js.map → activation-Bbic0THc.js.map} +1 -1
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +3 -3
- package/dist/{analyst-loop-CvkmfhUB.js → analyst-loop-Bouu53-l.js} +2 -2
- package/dist/{analyst-loop-CvkmfhUB.js.map → analyst-loop-Bouu53-l.js.map} +1 -1
- package/dist/analyst-loop.js +1 -1
- package/dist/{authoring-DuyShLdw.js → authoring-CcVhJ1lP.js} +2 -2
- package/dist/{authoring-DuyShLdw.js.map → authoring-CcVhJ1lP.js.map} +1 -1
- package/dist/candidate-execution/index.js +4 -4
- package/dist/{candidate-execution-CD5PoNmC.js → candidate-execution-DYOB1juU.js} +4 -4
- package/dist/{candidate-execution-CD5PoNmC.js.map → candidate-execution-DYOB1juU.js.map} +1 -1
- package/dist/{conversation-1hNtDeMM.js → conversation-BHMwAiMo.js} +28 -13
- package/dist/{conversation-1hNtDeMM.js.map → conversation-BHMwAiMo.js.map} +1 -1
- package/dist/conversation.d.ts +1 -1
- package/dist/conversation.js +1 -1
- package/dist/durable.d.ts +102 -4
- package/dist/durable.js +259 -13
- package/dist/durable.js.map +1 -1
- package/dist/{environment-provider-DCBJ13VP.js → environment-provider-3eCszBEm.js} +218 -34
- package/dist/environment-provider-3eCszBEm.js.map +1 -0
- package/dist/{environment-provider-B8eZ85Ga.d.ts → environment-provider-DJG0yIYl.d.ts} +2 -2
- package/dist/environment-provider.d.ts +1 -1
- package/dist/environment-provider.js +1 -1
- package/dist/executable-spec-BUcUcEPk.js +73 -0
- package/dist/executable-spec-BUcUcEPk.js.map +1 -0
- package/dist/{graph-De_XEsfH.js → graph-CIh2HDmH.js} +4 -4
- package/dist/{graph-De_XEsfH.js.map → graph-CIh2HDmH.js.map} +1 -1
- package/dist/{improvement-cycle-Bi-Tf4QF.js → improvement-cycle-GCDSsTN6.js} +7 -7
- package/dist/{improvement-cycle-Bi-Tf4QF.js.map → improvement-cycle-GCDSsTN6.js.map} +1 -1
- package/dist/{index-C2caGomG.d.ts → index-DLn9WI-f.d.ts} +342 -505
- package/dist/{index-B8rKtH3U.d.ts → index-lMADJLfq.d.ts} +4 -4
- package/dist/{index-D4sLkOPY.d.ts → index-rxVSm9-z.d.ts} +6 -4
- package/dist/index.d.ts +7 -7
- package/dist/index.js +13 -13
- package/dist/intelligence.d.ts +4 -4
- package/dist/intelligence.js +6 -6
- package/dist/jsonl-file-CDfsCI5s.js +59 -0
- package/dist/jsonl-file-CDfsCI5s.js.map +1 -0
- package/dist/kernel.d.ts +6 -6
- package/dist/kernel.js +13 -13
- package/dist/{knowledge-CVE6Wk1i.js → knowledge-CaY53BW2.js} +10 -7
- package/dist/{knowledge-CVE6Wk1i.js.map → knowledge-CaY53BW2.js.map} +1 -1
- package/dist/knowledge.d.ts +1 -1
- package/dist/knowledge.js +1 -1
- package/dist/{loop-runner-bin-BoHdQqLm.d.ts → loop-runner-bin-BwPqxKhR.d.ts} +3 -3
- package/dist/{loop-runner-bin-DdaI1nLL.js → loop-runner-bin-Dw43kB_-.js} +4 -4
- package/dist/{loop-runner-bin-DdaI1nLL.js.map → loop-runner-bin-Dw43kB_-.js.map} +1 -1
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/{materialization-P86EciBw.js → materialization-Dl9J8ek4.js} +279 -58
- package/dist/materialization-Dl9J8ek4.js.map +1 -0
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +3 -3
- package/dist/mcp/index.js +6 -6
- package/dist/{model-policy-DgRJIJse.js → model-policy-Sw4ywhtL.js} +68 -6
- package/dist/model-policy-Sw4ywhtL.js.map +1 -0
- package/dist/{openai-tools-BiAWKjh6.js → openai-tools-C4XKuK4t.js} +2 -2
- package/dist/{openai-tools-BiAWKjh6.js.map → openai-tools-C4XKuK4t.js.map} +1 -1
- package/dist/{prepare-D3n7cA39.js → prepare-C5tI-H4o.js} +2 -2
- package/dist/{prepare-D3n7cA39.js.map → prepare-C5tI-H4o.js.map} +1 -1
- package/dist/primeintellect/index.d.ts +1 -1
- package/dist/profiles.js +1 -1
- package/dist/{protected-model-port-bq6bD9YX.js → protected-model-port-DHDKNeY7.js} +2 -2
- package/dist/{protected-model-port-bq6bD9YX.js.map → protected-model-port-DHDKNeY7.js.map} +1 -1
- package/dist/{redact-DexTuAiX.d.ts → redact-NAptmqKw.d.ts} +3 -3
- package/dist/{researcher-CiSY6Wzb.js → researcher-BMFFPwKb.js} +2 -2
- package/dist/{researcher-CiSY6Wzb.js.map → researcher-BMFFPwKb.js.map} +1 -1
- package/dist/{run-layout-Be_Z0dF8.js → run-layout-C2jgwsCq.js} +111 -6
- package/dist/run-layout-C2jgwsCq.js.map +1 -0
- package/dist/{runtime-BnqjbOGX.js → runtime--Jsq8JCC.js} +118 -97
- package/dist/runtime--Jsq8JCC.js.map +1 -0
- package/dist/{runtime-J6Toky8K.d.ts → runtime-B-5dp5Iz.d.ts} +214 -14
- package/dist/{sandbox-events-COwCWUVB.js → sandbox-events-BVjstFgb.js} +70 -3
- package/dist/sandbox-events-BVjstFgb.js.map +1 -0
- package/dist/{spawn-journal-D2HKUImC.js → spawn-journal-BLnveCRS.js} +34 -104
- package/dist/spawn-journal-BLnveCRS.js.map +1 -0
- package/dist/{stream-agent-turn-C1Vs_3B9.d.ts → stream-agent-turn-BGyszuPH.d.ts} +2 -2
- package/dist/{stream-agent-turn-CXRugSGO.js → stream-agent-turn-DYi8ymsU.js} +91 -16
- package/dist/stream-agent-turn-DYi8ymsU.js.map +1 -0
- package/dist/{structural-rollout-CJgj9YXH.js → structural-rollout-D7V-HgXJ.js} +30 -13
- package/dist/structural-rollout-D7V-HgXJ.js.map +1 -0
- package/dist/{supervise-hCgG6ROJ.js → supervise-k_8VOASb.js} +2499 -2171
- package/dist/supervise-k_8VOASb.js.map +1 -0
- package/dist/{supervisor-s8SfZYbW.js → supervisor-CMZsJ7Wn.js} +673 -446
- package/dist/supervisor-CMZsJ7Wn.js.map +1 -0
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +12 -12
- package/dist/{top-app-BMOSKK06.js → top-app-3rYfFPTW.js} +192 -147
- package/dist/top-app-3rYfFPTW.js.map +1 -0
- package/dist/tui/bin.js +1 -1
- package/dist/tui/index.d.ts +32 -5
- package/dist/tui/index.js +1 -1
- package/dist/{types-Df9vulGc.d.ts → types-BPQhQRrC.d.ts} +507 -10
- package/dist/{util-C1bv6yog.js → util-D6ZEuBMi.js} +71 -2
- package/dist/util-D6ZEuBMi.js.map +1 -0
- package/dist/{workspace-archive-C52LjkeN.js → workspace-archive-B9ui4rrR.js} +2 -2
- package/dist/{workspace-archive-C52LjkeN.js.map → workspace-archive-B9ui4rrR.js.map} +1 -1
- package/package.json +7 -7
- package/dist/environment-provider-DCBJ13VP.js.map +0 -1
- package/dist/materialization-P86EciBw.js.map +0 -1
- package/dist/model-policy-DgRJIJse.js.map +0 -1
- package/dist/retained-run-binding-Dp2e8xne.js +0 -268
- package/dist/retained-run-binding-Dp2e8xne.js.map +0 -1
- package/dist/run-layout-Be_Z0dF8.js.map +0 -1
- package/dist/runtime-BnqjbOGX.js.map +0 -1
- package/dist/sandbox-events-COwCWUVB.js.map +0 -1
- package/dist/spawn-journal-D2HKUImC.js.map +0 -1
- package/dist/stream-agent-turn-CXRugSGO.js.map +0 -1
- package/dist/structural-rollout-CJgj9YXH.js.map +0 -1
- package/dist/supervise-hCgG6ROJ.js.map +0 -1
- package/dist/supervisor-s8SfZYbW.js.map +0 -1
- package/dist/top-app-BMOSKK06.js.map +0 -1
- package/dist/util-C1bv6yog.js.map +0 -1
|
@@ -1,8 +1,134 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { n as canonicalStreamEventFromSandboxEvent } from "./sandbox-events-
|
|
1
|
+
import { F as awaitAbortable, X as promptOptionsFromAgentTurnInput, Y as promptFromAgentTurnInput, o as finalizeRuntimeOwnedPendingExecutor, q as sameControlCoordinates, r as attestRuntimeOwnedPendingExecutor, u as newExecutionAttemptId } from "./materialization-Dl9J8ek4.js";
|
|
2
|
+
import { b as zeroTokenUsage } from "./util-D6ZEuBMi.js";
|
|
3
|
+
import { a as isSandboxTerminalEvent, d as sandboxTerminalUsageField, n as canonicalStreamEventFromSandboxEvent, r as createSandboxToolPartState, u as sandboxProgressEvents } from "./sandbox-events-BVjstFgb.js";
|
|
4
|
+
import { a as concreteProfileModel, c as profileModelExecutionSettings, o as enforceTokenLimits } from "./model-policy-Sw4ywhtL.js";
|
|
4
5
|
import { AgentExactRunControlRefSchema, AgentRunCancellationRequestSchema, harnessSystemPromptIntents } from "@tangle-network/agent-interface";
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
5
7
|
import { isDeepStrictEqual } from "node:util";
|
|
8
|
+
//#region src/runtime/supervise/abortable.ts
|
|
9
|
+
/**
|
|
10
|
+
* One abort race, and one abort cascade, for the supervision tree.
|
|
11
|
+
*
|
|
12
|
+
* Every layer that can be cancelled needs the same three things: the reason a signal
|
|
13
|
+
* carries, an `AbortError` built from it, and a settle-once race between the work and
|
|
14
|
+
* the signal. Written per layer, each drifts — a listener stops being removed on one
|
|
15
|
+
* path, a late resolution overwrites a cancellation that already won, or a cascade
|
|
16
|
+
* forwards no reason and renames every downstream death to the layer's own fallback.
|
|
17
|
+
*
|
|
18
|
+
* The fallback message is the only thing a layer supplies, so the error still names
|
|
19
|
+
* which layer cancelled.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* The reason a signal carries, or `fallback` when it states none.
|
|
23
|
+
*
|
|
24
|
+
* A cascade that drops the upstream reason turns every downstream death into its own generic
|
|
25
|
+
* message: the worker's `down` record then says nothing about WHY, which makes a whole class of
|
|
26
|
+
* child mortality undiagnosable from the journal alone.
|
|
27
|
+
*/
|
|
28
|
+
function abortReason(signal, fallback) {
|
|
29
|
+
const reason = signal.reason;
|
|
30
|
+
if (typeof reason === "string" && reason.length > 0) return reason;
|
|
31
|
+
if (reason instanceof Error && reason.name !== "AbortError" && reason.message.length > 0) return reason.message;
|
|
32
|
+
return fallback;
|
|
33
|
+
}
|
|
34
|
+
/** An `AbortError` carrying the signal's own string reason, or `fallback` when it states none. */
|
|
35
|
+
function abortError(signal, fallback) {
|
|
36
|
+
const reason = abortReason(signal, fallback);
|
|
37
|
+
const error = new Error(typeof reason === "string" && reason.length > 0 ? reason : fallback);
|
|
38
|
+
error.name = "AbortError";
|
|
39
|
+
return error;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Cascade N abort signals into one downstream abort that fires when ANY of them does, carrying
|
|
43
|
+
* that signal's own reason ({@link abortReason}). Node-portable: `AbortSignal.any` needs >=20.3
|
|
44
|
+
* and the package floor is >=20, and it would drop the reason anyway.
|
|
45
|
+
*
|
|
46
|
+
* The one cascade every executor uses, so a reason forwarded here reaches every layer below.
|
|
47
|
+
*/
|
|
48
|
+
function linkAbort(...sources) {
|
|
49
|
+
const controller = new AbortController();
|
|
50
|
+
const listeners = [];
|
|
51
|
+
const release = () => {
|
|
52
|
+
for (const { source, onAbort } of listeners) source.removeEventListener("abort", onAbort);
|
|
53
|
+
listeners.length = 0;
|
|
54
|
+
};
|
|
55
|
+
const abort = (reason) => {
|
|
56
|
+
release();
|
|
57
|
+
controller.abort(reason);
|
|
58
|
+
};
|
|
59
|
+
const alreadyAborted = sources.find((source) => source.aborted);
|
|
60
|
+
if (alreadyAborted !== void 0) {
|
|
61
|
+
controller.abort(abortReason(alreadyAborted, "aborted by parent scope"));
|
|
62
|
+
return {
|
|
63
|
+
signal: controller.signal,
|
|
64
|
+
abort,
|
|
65
|
+
release
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
for (const source of sources) {
|
|
69
|
+
const onAbort = () => abort(abortReason(source, "aborted by parent scope"));
|
|
70
|
+
listeners.push({
|
|
71
|
+
source,
|
|
72
|
+
onAbort
|
|
73
|
+
});
|
|
74
|
+
source.addEventListener("abort", onAbort, { once: true });
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
signal: controller.signal,
|
|
78
|
+
abort,
|
|
79
|
+
release
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Settle `act()` against `signal`. The first outcome wins and the listener is always
|
|
84
|
+
* removed, so neither a late resolution nor a late abort can settle the promise twice.
|
|
85
|
+
* The losing promise stays observed, so a late rejection cannot surface as an unhandled
|
|
86
|
+
* process error.
|
|
87
|
+
*
|
|
88
|
+
* The abort rejection is deferred one microtask so a result the action had ALREADY
|
|
89
|
+
* produced still wins. It does not hand the race to a listener the action registers
|
|
90
|
+
* from inside `act()`: this function subscribes before it calls `act()`, so its own
|
|
91
|
+
* abort handler runs first and settles the promise. A caller that must let the action
|
|
92
|
+
* observe the abort itself has to hold a live promise and await that instead.
|
|
93
|
+
*
|
|
94
|
+
* A synchronous throw from `act()` propagates as the rejection, not as an abort.
|
|
95
|
+
*/
|
|
96
|
+
async function runAbortable(act, signal, fallback) {
|
|
97
|
+
if (signal.aborted) throw abortError(signal, fallback);
|
|
98
|
+
return await new Promise((resolve, reject) => {
|
|
99
|
+
let settled = false;
|
|
100
|
+
const cleanup = () => signal.removeEventListener("abort", onAbort);
|
|
101
|
+
const onAbort = () => {
|
|
102
|
+
queueMicrotask(() => {
|
|
103
|
+
if (settled) return;
|
|
104
|
+
settled = true;
|
|
105
|
+
cleanup();
|
|
106
|
+
reject(abortError(signal, fallback));
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
110
|
+
let work;
|
|
111
|
+
try {
|
|
112
|
+
work = Promise.resolve(act());
|
|
113
|
+
} catch (error) {
|
|
114
|
+
cleanup();
|
|
115
|
+
reject(error);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
work.then((value) => {
|
|
119
|
+
if (settled) return;
|
|
120
|
+
settled = true;
|
|
121
|
+
cleanup();
|
|
122
|
+
resolve(value);
|
|
123
|
+
}, (error) => {
|
|
124
|
+
if (settled) return;
|
|
125
|
+
settled = true;
|
|
126
|
+
cleanup();
|
|
127
|
+
reject(error);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
6
132
|
//#region src/runtime/tangle-sandbox-exact-process-provider.ts
|
|
7
133
|
const exactProcessProviderMarker = "agent-runtime.exact-process-provider";
|
|
8
134
|
const exactProcessEgressMarker = "agent-runtime.exact-process-egress";
|
|
@@ -483,32 +609,96 @@ function providerAsExecutor(provider, options = {}) {
|
|
|
483
609
|
return (spec, ctx) => createProviderExecutor(provider, spec.profile, ctx, options);
|
|
484
610
|
}
|
|
485
611
|
function createProviderExecutor(provider, profile, ctx, options) {
|
|
486
|
-
const controller =
|
|
487
|
-
const abortIfSignalled = () => {
|
|
488
|
-
if (ctx.signal.aborted) controller.abort();
|
|
489
|
-
};
|
|
490
|
-
abortIfSignalled();
|
|
491
|
-
if (!ctx.signal.aborted) ctx.signal.addEventListener("abort", abortIfSignalled, { once: true });
|
|
612
|
+
const controller = linkAbort(ctx.signal);
|
|
492
613
|
let environment;
|
|
493
614
|
let artifact;
|
|
494
|
-
|
|
495
|
-
|
|
615
|
+
const runtime = options.runtime ?? provider.name;
|
|
616
|
+
const createProfile = options.profileForCreate?.(profile) ?? profile;
|
|
617
|
+
const executionId = ctx.node?.nodeId ?? `provider-run-${randomUUID()}`;
|
|
618
|
+
const attemptId = ctx.node?.attemptId ?? newExecutionAttemptId(executionId);
|
|
619
|
+
const providerModel = concreteProfileModel(createProfile);
|
|
620
|
+
const tokenLimits = enforceTokenLimits(profileModelExecutionSettings(createProfile, `providerAsExecutor(${provider.name})`).tokenLimits, "provider", `providerAsExecutor(${provider.name})`);
|
|
621
|
+
const plannedDeclaration = {
|
|
622
|
+
effectiveProfile: createProfile,
|
|
623
|
+
backend: provider.name,
|
|
624
|
+
model: providerModel ? {
|
|
625
|
+
status: "known",
|
|
626
|
+
id: providerModel
|
|
627
|
+
} : {
|
|
628
|
+
status: "unknown",
|
|
629
|
+
reason: "provider environment selected its default model"
|
|
630
|
+
},
|
|
631
|
+
execution: {
|
|
632
|
+
kind: "environment",
|
|
633
|
+
id: executionId
|
|
634
|
+
},
|
|
635
|
+
materializer: "environment-provider-create",
|
|
636
|
+
plan: {
|
|
637
|
+
kind: "agent-environment",
|
|
638
|
+
provider: provider.name,
|
|
639
|
+
destroyOnSettle: options.destroyOnSettle ?? true,
|
|
640
|
+
requireTerminalEvent: options.requireTerminalEvent ?? true,
|
|
641
|
+
tokenLimits,
|
|
642
|
+
environmentId: null
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
const plannedBinding = {
|
|
646
|
+
attemptId,
|
|
647
|
+
binding: {
|
|
648
|
+
provider: provider.name,
|
|
649
|
+
executionId,
|
|
650
|
+
model: providerModel ?? null
|
|
651
|
+
},
|
|
652
|
+
descriptor: {
|
|
653
|
+
kind: "agent-environment",
|
|
654
|
+
transport: "provider",
|
|
655
|
+
backend: provider.name
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
let executor;
|
|
659
|
+
executor = {
|
|
660
|
+
runtime,
|
|
496
661
|
execute(task, signal) {
|
|
497
662
|
return streamProviderExecutor({
|
|
498
663
|
provider,
|
|
499
664
|
profile,
|
|
665
|
+
createProfile,
|
|
500
666
|
task,
|
|
501
667
|
signal,
|
|
502
668
|
controller,
|
|
503
669
|
options,
|
|
504
670
|
onEnvironment: (env) => {
|
|
505
671
|
environment = env;
|
|
672
|
+
finalizeRuntimeOwnedPendingExecutor(executor, {
|
|
673
|
+
...plannedDeclaration,
|
|
674
|
+
execution: {
|
|
675
|
+
kind: "environment",
|
|
676
|
+
id: env.id
|
|
677
|
+
},
|
|
678
|
+
plan: {
|
|
679
|
+
...plannedDeclaration.plan,
|
|
680
|
+
environmentId: env.id
|
|
681
|
+
}
|
|
682
|
+
}, plannedBinding);
|
|
506
683
|
},
|
|
507
684
|
onArtifact: (next) => {
|
|
508
685
|
artifact = next;
|
|
509
686
|
}
|
|
510
687
|
});
|
|
511
688
|
},
|
|
689
|
+
async cancel(request) {
|
|
690
|
+
controller.abort();
|
|
691
|
+
return {
|
|
692
|
+
status: "unknown",
|
|
693
|
+
effect: "cancel_requested",
|
|
694
|
+
observedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
695
|
+
detail: `providerAsExecutor(${provider.name}): the streamed turn carries no durable run reference, so the provider acknowledged nothing`,
|
|
696
|
+
evidence: {
|
|
697
|
+
operationId: request.operationId,
|
|
698
|
+
...environment ? { environmentId: environment.id } : {}
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
},
|
|
512
702
|
async teardown(_grace) {
|
|
513
703
|
controller.abort();
|
|
514
704
|
await environment?.destroy?.();
|
|
@@ -519,14 +709,14 @@ function createProviderExecutor(provider, profile, ctx, options) {
|
|
|
519
709
|
return artifact;
|
|
520
710
|
}
|
|
521
711
|
};
|
|
712
|
+
return attestRuntimeOwnedPendingExecutor(executor, runtime, plannedDeclaration, plannedBinding);
|
|
522
713
|
}
|
|
523
714
|
async function* streamProviderExecutor(args) {
|
|
524
715
|
const started = Date.now();
|
|
525
|
-
const linked =
|
|
526
|
-
const createProfile = args.options.profileForCreate?.(args.profile) ?? args.profile;
|
|
716
|
+
const linked = linkAbort(args.signal, args.controller.signal).signal;
|
|
527
717
|
const environment = await args.provider.create({
|
|
528
718
|
...args.options.defaults ?? {},
|
|
529
|
-
profile: createProfile,
|
|
719
|
+
profile: args.createProfile,
|
|
530
720
|
signal: linked
|
|
531
721
|
});
|
|
532
722
|
args.onEnvironment(environment);
|
|
@@ -537,12 +727,17 @@ async function* streamProviderExecutor(args) {
|
|
|
537
727
|
let text = "";
|
|
538
728
|
let terminal = false;
|
|
539
729
|
try {
|
|
730
|
+
const toolParts = createSandboxToolPartState();
|
|
540
731
|
for await (const event of environment.stream({
|
|
541
732
|
...turn,
|
|
542
733
|
signal: linked
|
|
543
734
|
})) {
|
|
544
735
|
events.push(event);
|
|
545
736
|
text += textFromEnvironmentEvent(event);
|
|
737
|
+
for (const progress of sandboxProgressEvents(sandboxEventFromEnvironmentEvent(event), toolParts)) yield {
|
|
738
|
+
kind: "progress",
|
|
739
|
+
progress
|
|
740
|
+
};
|
|
546
741
|
const usage = usageFromEnvironmentEvent(event);
|
|
547
742
|
if (usage.input || usage.output) {
|
|
548
743
|
tokens.input += usage.input;
|
|
@@ -557,7 +752,9 @@ async function* streamProviderExecutor(args) {
|
|
|
557
752
|
usd += usage.usd;
|
|
558
753
|
yield {
|
|
559
754
|
kind: "cost",
|
|
560
|
-
|
|
755
|
+
usdKnown: false,
|
|
756
|
+
usd: usage.usd,
|
|
757
|
+
provenance: "uncaptured"
|
|
561
758
|
};
|
|
562
759
|
}
|
|
563
760
|
if (isTerminalEnvironmentEvent(event)) terminal = true;
|
|
@@ -569,6 +766,7 @@ async function* streamProviderExecutor(args) {
|
|
|
569
766
|
iterations: 1,
|
|
570
767
|
tokens,
|
|
571
768
|
usd,
|
|
769
|
+
usdKnown: false,
|
|
572
770
|
ms: Date.now() - started
|
|
573
771
|
};
|
|
574
772
|
args.onArtifact({
|
|
@@ -1113,7 +1311,7 @@ function isTerminalEnvironmentEvent(event) {
|
|
|
1113
1311
|
return normalized?.type === "status" && (normalized.status === "completed" || normalized.status === "failed");
|
|
1114
1312
|
}
|
|
1115
1313
|
function isTerminalEventShape(type, data) {
|
|
1116
|
-
if (type
|
|
1314
|
+
if (isSandboxTerminalEvent(type)) return true;
|
|
1117
1315
|
if (type.endsWith(".completed") || type.endsWith(".failed")) return true;
|
|
1118
1316
|
if (type !== "status") return false;
|
|
1119
1317
|
return data.status === "completed" || data.status === "failed" || data.status === "cancelled";
|
|
@@ -1121,8 +1319,9 @@ function isTerminalEventShape(type, data) {
|
|
|
1121
1319
|
function isUsageType(type) {
|
|
1122
1320
|
return type === "llm_call" || type === "usage" || type === "cost.usage";
|
|
1123
1321
|
}
|
|
1322
|
+
/** A terminal event whose usage rides `data.usage` — the nested shape this transport unwraps. */
|
|
1124
1323
|
function isNestedUsageType(type) {
|
|
1125
|
-
return type
|
|
1324
|
+
return isSandboxTerminalEvent(type) && sandboxTerminalUsageField(type) === "usage";
|
|
1126
1325
|
}
|
|
1127
1326
|
function usageFromEnvironmentEvent(event) {
|
|
1128
1327
|
const usage = event.usage ?? tokenUsageFromData(event.data);
|
|
@@ -1330,21 +1529,6 @@ function defaultTangleSandboxCapabilities(options) {
|
|
|
1330
1529
|
confidential: true
|
|
1331
1530
|
};
|
|
1332
1531
|
}
|
|
1333
|
-
function mergeAbortSignals(a, b) {
|
|
1334
|
-
const controller = new AbortController();
|
|
1335
|
-
const reasonOf = (signal) => {
|
|
1336
|
-
const reason = signal.reason;
|
|
1337
|
-
if (typeof reason === "string" && reason.length > 0) return reason;
|
|
1338
|
-
if (reason instanceof Error && reason.name !== "AbortError" && reason.message.length > 0) return reason.message;
|
|
1339
|
-
return "aborted by parent scope";
|
|
1340
|
-
};
|
|
1341
|
-
if (a.aborted || b.aborted) controller.abort(reasonOf(a.aborted ? a : b));
|
|
1342
|
-
else {
|
|
1343
|
-
a.addEventListener("abort", () => controller.abort(reasonOf(a)), { once: true });
|
|
1344
|
-
b.addEventListener("abort", () => controller.abort(reasonOf(b)), { once: true });
|
|
1345
|
-
}
|
|
1346
|
-
return controller.signal;
|
|
1347
|
-
}
|
|
1348
1532
|
function contentRef(prefix, value) {
|
|
1349
1533
|
let str;
|
|
1350
1534
|
try {
|
|
@@ -1381,6 +1565,6 @@ function hasExec(box) {
|
|
|
1381
1565
|
return typeof box.exec === "function";
|
|
1382
1566
|
}
|
|
1383
1567
|
//#endregion
|
|
1384
|
-
export { sandboxClientAsProvider as a, resolveAgentEnvironmentProvider as i, providerAsExecutor as n, createTangleSandboxExactProcessProvider as o, providerAsSandboxClient as r, createAgentEnvironmentProviderRegistry as t };
|
|
1568
|
+
export { sandboxClientAsProvider as a, linkAbort as c, resolveAgentEnvironmentProvider as i, runAbortable as l, providerAsExecutor as n, createTangleSandboxExactProcessProvider as o, providerAsSandboxClient as r, abortError as s, createAgentEnvironmentProviderRegistry as t };
|
|
1385
1569
|
|
|
1386
|
-
//# sourceMappingURL=environment-provider-
|
|
1570
|
+
//# sourceMappingURL=environment-provider-3eCszBEm.js.map
|