@tangle-network/agent-runtime 0.197.1 → 0.198.1
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 +1 -2
- package/dist/{activation-BxMZybuo.js → activation-CwdO0ml2.js} +2 -2
- package/dist/{activation-BxMZybuo.js.map → activation-CwdO0ml2.js.map} +1 -1
- package/dist/{improve-DZs0KXhK.d.ts → activation-DFRTurvU.d.ts} +99 -5
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +2 -2
- package/dist/candidate-execution/index.d.ts +370 -2
- package/dist/candidate-execution/index.js +828 -4
- package/dist/candidate-execution/index.js.map +1 -0
- package/dist/{coordination-driver-zkCrfEbS.js → coordination-driver-Cf638-6q.js} +2 -5
- package/dist/{coordination-driver-zkCrfEbS.js.map → coordination-driver-Cf638-6q.js.map} +1 -1
- package/dist/{delegate-DHeUYU5E.js → delegate-Bez07Dlh.js} +2 -2
- package/dist/{delegate-DHeUYU5E.js.map → delegate-Bez07Dlh.js.map} +1 -1
- package/dist/durable.d.ts +2 -2
- package/dist/durable.js +4 -5
- package/dist/durable.js.map +1 -1
- package/dist/{graph-51SJOEcw.js → graph-DBk3Unto.js} +3 -3
- package/dist/{graph-51SJOEcw.js.map → graph-DBk3Unto.js.map} +1 -1
- package/dist/{improvement-cycle-Tw5nYT5R.js → improvement-cycle-Bma8TJs-.js} +8 -10
- package/dist/{improvement-cycle-Tw5nYT5R.js.map → improvement-cycle-Bma8TJs-.js.map} +1 -1
- package/dist/{index-CYOJsxSg.d.ts → index-D8LWK3Ha.d.ts} +6 -7
- package/dist/index.d.ts +694 -16
- package/dist/index.js +1780 -17
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +3 -7
- package/dist/intelligence.js +5 -6
- package/dist/intelligence.js.map +1 -1
- package/dist/kernel.d.ts +2 -5
- package/dist/kernel.js +8 -10
- package/dist/{loop-runner-bin-2LQSjRTB.js → loop-runner-bin-Bd3dHQuw.js} +3 -3
- package/dist/{loop-runner-bin-2LQSjRTB.js.map → loop-runner-bin-Bd3dHQuw.js.map} +1 -1
- package/dist/{loop-runner-bin-DwrSB04m.d.ts → loop-runner-bin-Bn-0o_4k.d.ts} +3 -3
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +2 -3
- package/dist/mcp/index.js +4 -5
- package/dist/mcp/index.js.map +1 -1
- package/dist/{prepare-DDGp0-rW.js → prepare-CAO1yXov.js} +2407 -2407
- package/dist/prepare-CAO1yXov.js.map +1 -0
- package/dist/{protected-model-port-DxFN8DLS.js → protected-model-port-B5avcRiQ.js} +2 -2
- package/dist/{protected-model-port-DxFN8DLS.js.map → protected-model-port-B5avcRiQ.js.map} +1 -1
- package/dist/{provision-supervisor-CpMMShE_.js → provision-supervisor-C97q5NN_.js} +3 -6
- package/dist/{provision-supervisor-CpMMShE_.js.map → provision-supervisor-C97q5NN_.js.map} +1 -1
- package/dist/{redact-Cbl2O-4N.js → redact-CVyxp2AU.js} +5232 -2525
- package/dist/redact-CVyxp2AU.js.map +1 -0
- package/dist/{runtime-BSFz2z7h.js → runtime-BrTBBSfC.js} +427 -23
- package/dist/runtime-BrTBBSfC.js.map +1 -0
- package/dist/{server-COXa19sp.js → server-CO4bvAwe.js} +4 -4
- package/dist/{server-COXa19sp.js.map → server-CO4bvAwe.js.map} +1 -1
- package/dist/{types-DFLZMaeh.d.ts → stream-agent-turn-CLOQr497.d.ts} +1986 -6
- package/dist/{structural-rollout-DPbZWgEm.js → structural-rollout-D__lmWXe.js} +1101 -8
- package/dist/structural-rollout-D__lmWXe.js.map +1 -0
- package/dist/{supervise-b93YUaka.js → supervise-KSe4JEcg.js} +3 -5
- package/dist/{supervise-b93YUaka.js.map → supervise-KSe4JEcg.js.map} +1 -1
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +13 -13
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +1 -1
- package/dist/{workspace-archive-Ybomp7AN.js → workspace-archive-BMOnloFf.js} +3 -3
- package/dist/{workspace-archive-Ybomp7AN.js.map → workspace-archive-BMOnloFf.js.map} +1 -1
- package/package.json +1 -28
- package/dist/activation-DyWB0K6E.d.ts +0 -98
- package/dist/authored-code-URmkdgjv.js +0 -37
- package/dist/authored-code-URmkdgjv.js.map +0 -1
- package/dist/candidate-execution-nvqVIMyS.js +0 -829
- package/dist/candidate-execution-nvqVIMyS.js.map +0 -1
- package/dist/conversation-BxJ0SIBM.js +0 -1363
- package/dist/conversation-BxJ0SIBM.js.map +0 -1
- package/dist/conversation.d.ts +0 -2
- package/dist/conversation.js +0 -2
- package/dist/environment-provider-1fKZh2zl.js +0 -2281
- package/dist/environment-provider-1fKZh2zl.js.map +0 -1
- package/dist/environment-provider-B-I2jlQy.d.ts +0 -143
- package/dist/environment-provider.d.ts +0 -2
- package/dist/environment-provider.js +0 -2
- package/dist/graph.d.ts +0 -753
- package/dist/graph.js +0 -2111
- package/dist/graph.js.map +0 -1
- package/dist/index-CUosKU4N.d.ts +0 -372
- package/dist/index-D9mb6fn2.d.ts +0 -691
- package/dist/index-ZnxSe6iK.d.ts +0 -138
- package/dist/jsonl-file-BEpaEYjT.js +0 -141
- package/dist/jsonl-file-BEpaEYjT.js.map +0 -1
- package/dist/knowledge-B_MsOtDG.js +0 -428
- package/dist/knowledge-B_MsOtDG.js.map +0 -1
- package/dist/knowledge.d.ts +0 -2
- package/dist/knowledge.js +0 -2
- package/dist/materialization-Cy0oM8tb.js +0 -672
- package/dist/materialization-Cy0oM8tb.js.map +0 -1
- package/dist/prepare-DDGp0-rW.js.map +0 -1
- package/dist/primeintellect/index.d.ts +0 -218
- package/dist/primeintellect/index.js +0 -739
- package/dist/primeintellect/index.js.map +0 -1
- package/dist/redact-Cbl2O-4N.js.map +0 -1
- package/dist/runtime-0xNaV6TJ.d.ts +0 -1699
- package/dist/runtime-BSFz2z7h.js.map +0 -1
- package/dist/stream-agent-turn-Dt5mZpc3.js +0 -1103
- package/dist/stream-agent-turn-Dt5mZpc3.js.map +0 -1
- package/dist/stream-agent-turn-urHpmO_Z.d.ts +0 -160
- package/dist/structural-rollout-DPbZWgEm.js.map +0 -1
|
@@ -1,672 +0,0 @@
|
|
|
1
|
-
import { m as ValidationError } from "./errors-DodWX-cb.js";
|
|
2
|
-
import { AgentExactRunControlRefSchema, AgentRunCancellationAcknowledgementSchema, AgentRunCancellationRequestSchema, agentProfileSchema, agentRunCancellationAcknowledgementMatchesRequest, agentRunCancellationRequestDigest, canonicalAgentProfileDigest, canonicalCandidateDigest } from "@tangle-network/agent-interface";
|
|
3
|
-
import { randomUUID } from "node:crypto";
|
|
4
|
-
//#region src/runtime/turn-input.ts
|
|
5
|
-
/**
|
|
6
|
-
* Copy only fields that describe a new provider turn.
|
|
7
|
-
*
|
|
8
|
-
* Session, replay, continuation, and transfer coordinates are runtime-owned
|
|
9
|
-
* and are injected by the caller that owns that lifecycle. Keeping this copy
|
|
10
|
-
* explicit also makes JavaScript callers subject to the same boundary.
|
|
11
|
-
*/
|
|
12
|
-
function freshTurnInput(input, runtime) {
|
|
13
|
-
return {
|
|
14
|
-
...input.prompt === void 0 ? {} : { prompt: input.prompt },
|
|
15
|
-
...input.parts === void 0 ? {} : { parts: input.parts },
|
|
16
|
-
...input.model === void 0 ? {} : { model: input.model },
|
|
17
|
-
...input.timeoutMs === void 0 ? {} : { timeoutMs: input.timeoutMs },
|
|
18
|
-
...input.context === void 0 ? {} : { context: input.context },
|
|
19
|
-
...input.interactions === void 0 ? {} : { interactions: input.interactions },
|
|
20
|
-
...input.providerOptions === void 0 ? {} : { providerOptions: input.providerOptions },
|
|
21
|
-
...input.signal === void 0 ? {} : { signal: input.signal },
|
|
22
|
-
turnId: runtime.turnId,
|
|
23
|
-
detach: runtime.detach,
|
|
24
|
-
...runtime.sessionId === void 0 ? {} : { sessionId: runtime.sessionId },
|
|
25
|
-
...runtime.executionId === void 0 ? {} : { executionId: runtime.executionId },
|
|
26
|
-
...runtime.contextTransfer === void 0 ? {} : { contextTransfer: runtime.contextTransfer }
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
/** Project canonical turn parts onto the Sandbox prompt vocabulary once. */
|
|
30
|
-
function promptFromAgentTurnInput(input) {
|
|
31
|
-
if (input.parts !== void 0) return input.parts.map(promptPartFromInputPart);
|
|
32
|
-
return input.prompt ?? providerMessageText(input.providerOptions) ?? "";
|
|
33
|
-
}
|
|
34
|
-
/** Project canonical turn controls onto the Sandbox prompt options once. */
|
|
35
|
-
function promptOptionsFromAgentTurnInput(input) {
|
|
36
|
-
const backend = {
|
|
37
|
-
...(input.providerOptions?.backend && typeof input.providerOptions.backend === "object" && !Array.isArray(input.providerOptions.backend) ? input.providerOptions.backend : void 0) ?? {},
|
|
38
|
-
...input.interactions === void 0 ? {} : { interactions: input.interactions }
|
|
39
|
-
};
|
|
40
|
-
const runControlRef = input.controlRef === void 0 ? void 0 : AgentExactRunControlRefSchema.parse(input.controlRef);
|
|
41
|
-
return {
|
|
42
|
-
...input.sessionId === void 0 ? {} : { sessionId: input.sessionId },
|
|
43
|
-
...input.model === void 0 ? {} : { model: input.model },
|
|
44
|
-
...input.timeoutMs === void 0 ? {} : { timeoutMs: input.timeoutMs },
|
|
45
|
-
...input.context === void 0 ? {} : { context: input.context },
|
|
46
|
-
...input.signal === void 0 ? {} : { signal: input.signal },
|
|
47
|
-
...input.executionId === void 0 ? {} : { executionId: input.executionId },
|
|
48
|
-
...input.lastEventId === void 0 ? {} : { lastEventId: input.lastEventId },
|
|
49
|
-
...input.turnId === void 0 ? {} : { turnId: input.turnId },
|
|
50
|
-
...input.detach === void 0 ? {} : { detach: input.detach },
|
|
51
|
-
...runControlRef === void 0 ? {} : { runControlRef },
|
|
52
|
-
...Object.keys(backend).length === 0 ? {} : { backend }
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
/** Read a text fallback from provider-specific conversation options. */
|
|
56
|
-
function providerMessageText(providerOptions) {
|
|
57
|
-
const messages = providerOptions?.messages;
|
|
58
|
-
if (!Array.isArray(messages)) return void 0;
|
|
59
|
-
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
60
|
-
const message = messages[index];
|
|
61
|
-
if (!message || typeof message !== "object" || Array.isArray(message)) continue;
|
|
62
|
-
if (!("role" in message) || message.role !== "user") continue;
|
|
63
|
-
if (!("content" in message)) continue;
|
|
64
|
-
if (typeof message.content === "string") return message.content;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function promptPartFromInputPart(part) {
|
|
68
|
-
if (part.type === "text" || part.type === "image") return part;
|
|
69
|
-
if (part.content !== void 0 || part.path !== void 0) throw new Error("Sandbox file prompt parts require a URL; inline content and local paths are not representable");
|
|
70
|
-
if (!part.filename || !part.url) throw new Error("Sandbox file prompt parts require both filename and URL");
|
|
71
|
-
return {
|
|
72
|
-
type: "file",
|
|
73
|
-
filename: part.filename,
|
|
74
|
-
...part.mediaType === void 0 ? {} : { mediaType: part.mediaType },
|
|
75
|
-
url: part.url
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/runtime/retained-run-binding.ts
|
|
80
|
-
function exactSession(environment, controlRef) {
|
|
81
|
-
if (environment.id !== controlRef.environmentId || environment.provider !== controlRef.provider) throw new Error("provider reconstructed a different retained environment");
|
|
82
|
-
if (!environment.session || !controlRef.sessionId) throw new Error("retained run control requires a provider session id");
|
|
83
|
-
const session = environment.session(controlRef.sessionId, { controlRef });
|
|
84
|
-
if (session.id !== controlRef.sessionId) throw new Error("provider reconstructed a different session");
|
|
85
|
-
if (session.controlRef === void 0) throw new Error("provider session did not return its provider-owned run control reference");
|
|
86
|
-
const currentControlRef = AgentExactRunControlRefSchema.parse(session.controlRef);
|
|
87
|
-
if (!sameControlCoordinates(currentControlRef, controlRef)) throw new Error("provider session reconstructed a different retained session");
|
|
88
|
-
if (canonicalCandidateDigest(currentControlRef) !== canonicalCandidateDigest(controlRef)) throw new Error("provider session did not retain the exact run control reference");
|
|
89
|
-
return {
|
|
90
|
-
session,
|
|
91
|
-
controlRef: currentControlRef
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function sameControlCoordinates(left, right) {
|
|
95
|
-
return canonicalCandidateDigest(left) === canonicalCandidateDigest(right);
|
|
96
|
-
}
|
|
97
|
-
function freezeControlRef(controlRef) {
|
|
98
|
-
return Object.freeze({ ...AgentExactRunControlRefSchema.parse(controlRef) });
|
|
99
|
-
}
|
|
100
|
-
function copyControlRef(controlRef) {
|
|
101
|
-
return { ...controlRef };
|
|
102
|
-
}
|
|
103
|
-
function exactControlRef(candidate, expected) {
|
|
104
|
-
if (!candidate) throw new Error("provider dispatch returned no durable run control reference");
|
|
105
|
-
const controlRef = AgentExactRunControlRefSchema.parse(candidate);
|
|
106
|
-
if (controlRef.provider !== expected.provider || controlRef.environmentId !== expected.environmentId || controlRef.sessionId !== expected.sessionId) throw new Error("provider dispatch returned control coordinates for another run");
|
|
107
|
-
return controlRef;
|
|
108
|
-
}
|
|
109
|
-
function exactContinuedControlRef(candidate, initial) {
|
|
110
|
-
const controlRef = AgentExactRunControlRefSchema.parse(candidate);
|
|
111
|
-
if (controlRef.provider !== initial.provider || controlRef.environmentId !== initial.environmentId || controlRef.sessionId !== initial.sessionId) throw new Error("provider continuation advanced to another retained session");
|
|
112
|
-
if (controlRef.runId === initial.runId && controlRef.executionId === initial.executionId) throw new Error("provider continuation did not return a new exact run execution");
|
|
113
|
-
return controlRef;
|
|
114
|
-
}
|
|
115
|
-
function assertInteractionBinding(controlRef, command) {
|
|
116
|
-
if (command.binding.runId !== controlRef.runId || command.binding.provider !== controlRef.provider || command.binding.environmentId !== controlRef.environmentId || command.binding.sessionId !== controlRef.sessionId || command.binding.executionId !== controlRef.executionId) throw new Error("interaction response command does not target this retained run");
|
|
117
|
-
}
|
|
118
|
-
function assertBoundaryBinding(controlRef, proof) {
|
|
119
|
-
if (proof.runId !== controlRef.runId || proof.provider !== controlRef.provider || proof.environmentId !== controlRef.environmentId || proof.sessionId !== controlRef.sessionId || proof.executionId !== controlRef.executionId || proof.requestDigest !== controlRef.requestDigest) throw new Error("native context proof does not identify this retained run");
|
|
120
|
-
}
|
|
121
|
-
function assertSequence(value, label) {
|
|
122
|
-
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) throw new Error(`${label} must be a non-negative safe integer`);
|
|
123
|
-
}
|
|
124
|
-
function assertResultBinding(controlRef, result) {
|
|
125
|
-
if (result.sessionId !== controlRef.sessionId) throw new Error("provider returned a result for another retained session");
|
|
126
|
-
const metadata = result.metadata;
|
|
127
|
-
if (controlRef.executionId !== void 0 && metadata?.executionId !== controlRef.executionId) throw new Error("provider returned a result for another retained execution");
|
|
128
|
-
if (metadata?.runId !== controlRef.runId) throw new Error("provider returned a result for another retained run");
|
|
129
|
-
if (metadata?.requestDigest !== controlRef.requestDigest) throw new Error("provider returned a result for another retained request");
|
|
130
|
-
}
|
|
131
|
-
var RetainedRunProviderContractError = class extends Error {
|
|
132
|
-
code;
|
|
133
|
-
constructor(message, options = {}) {
|
|
134
|
-
super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
|
|
135
|
-
this.name = "RetainedRunProviderContractError";
|
|
136
|
-
this.code = options.code ?? "RETAINED_RUN_PROVIDER_CONTRACT_ERROR";
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
function cancellationRequest(controlRef, operationId, reason) {
|
|
140
|
-
const material = {
|
|
141
|
-
operationId,
|
|
142
|
-
run: AgentExactRunControlRefSchema.parse(controlRef),
|
|
143
|
-
...reason === void 0 ? {} : { reason }
|
|
144
|
-
};
|
|
145
|
-
return AgentRunCancellationRequestSchema.parse({
|
|
146
|
-
...material,
|
|
147
|
-
requestDigest: agentRunCancellationRequestDigest(material)
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
async function exactSessionCancel(session, request, options) {
|
|
151
|
-
if (!session.cancelRun) throw new Error("provider session does not expose durable cancellation operations");
|
|
152
|
-
let acknowledgement;
|
|
153
|
-
try {
|
|
154
|
-
acknowledgement = await awaitAbortable(Promise.resolve().then(() => session.cancelRun(request, options)), options.signal);
|
|
155
|
-
} catch (error) {
|
|
156
|
-
if (error instanceof RetainedRunProviderContractError) throw error;
|
|
157
|
-
throw error;
|
|
158
|
-
}
|
|
159
|
-
let exactAcknowledgement;
|
|
160
|
-
try {
|
|
161
|
-
exactAcknowledgement = AgentRunCancellationAcknowledgementSchema.parse(acknowledgement);
|
|
162
|
-
} catch {
|
|
163
|
-
throw new RetainedRunProviderContractError("provider returned an invalid retained cancellation acknowledgement");
|
|
164
|
-
}
|
|
165
|
-
if (!agentRunCancellationAcknowledgementMatchesRequest(request, exactAcknowledgement)) throw new RetainedRunProviderContractError("provider returned a retained cancellation acknowledgement for another request");
|
|
166
|
-
return exactAcknowledgement;
|
|
167
|
-
}
|
|
168
|
-
function hasDurableCancel(session) {
|
|
169
|
-
return typeof session.cancelRun === "function";
|
|
170
|
-
}
|
|
171
|
-
async function awaitAbortable(work, signal) {
|
|
172
|
-
if (signal === void 0) return await work;
|
|
173
|
-
if (signal.aborted) {
|
|
174
|
-
Promise.resolve(work).catch(() => void 0);
|
|
175
|
-
throw abortError(signal.reason);
|
|
176
|
-
}
|
|
177
|
-
return await new Promise((resolve, reject) => {
|
|
178
|
-
let settled = false;
|
|
179
|
-
const cleanup = () => signal.removeEventListener("abort", onAbort);
|
|
180
|
-
const onAbort = () => {
|
|
181
|
-
queueMicrotask(() => {
|
|
182
|
-
if (settled) return;
|
|
183
|
-
settled = true;
|
|
184
|
-
cleanup();
|
|
185
|
-
reject(abortError(signal.reason));
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
189
|
-
Promise.resolve(work).then((value) => {
|
|
190
|
-
if (settled) return;
|
|
191
|
-
settled = true;
|
|
192
|
-
cleanup();
|
|
193
|
-
resolve(value);
|
|
194
|
-
}, (error) => {
|
|
195
|
-
if (settled) return;
|
|
196
|
-
settled = true;
|
|
197
|
-
cleanup();
|
|
198
|
-
reject(error);
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
async function exactSessionResult(session) {
|
|
203
|
-
return session.result();
|
|
204
|
-
}
|
|
205
|
-
function assertEventBinding(source, controlRef) {
|
|
206
|
-
const transport = isRecord(source) ? source : void 0;
|
|
207
|
-
const payload = isRecord(source.data) ? source.data : void 0;
|
|
208
|
-
const providerEvent = isRecord(source.providerEvent) ? source.providerEvent : void 0;
|
|
209
|
-
const bindings = [
|
|
210
|
-
{
|
|
211
|
-
value: transport,
|
|
212
|
-
checkSessionId: true
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
value: payload,
|
|
216
|
-
checkSessionId: source.type !== "session.updated"
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
value: providerEvent,
|
|
220
|
-
checkSessionId: true
|
|
221
|
-
}
|
|
222
|
-
];
|
|
223
|
-
for (const { value, checkSessionId } of bindings) {
|
|
224
|
-
if (value === void 0) continue;
|
|
225
|
-
if (value.runId !== void 0 && value.runId !== controlRef.runId) throw new Error("provider returned an event for another retained run");
|
|
226
|
-
if (value.executionId !== void 0 && value.executionId !== controlRef.executionId) throw new Error("provider returned an event for another retained execution");
|
|
227
|
-
if (checkSessionId && value.sessionId !== void 0 && value.sessionId !== controlRef.sessionId) throw new Error("provider returned an event for another retained session");
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
/** Validate the nested coordinates carried by a canonical interaction request. */
|
|
231
|
-
function assertCanonicalEventBinding(controlRef, event) {
|
|
232
|
-
if (event.type !== "interaction") return;
|
|
233
|
-
const binding = event.request.binding;
|
|
234
|
-
if (binding.runId !== controlRef.runId || binding.provider !== controlRef.provider || binding.environmentId !== controlRef.environmentId || binding.sessionId !== controlRef.sessionId || binding.executionId !== controlRef.executionId || binding.interactionId !== event.request.id) throw new Error("provider returned an interaction for another retained execution");
|
|
235
|
-
}
|
|
236
|
-
function isRecord(value) {
|
|
237
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
238
|
-
}
|
|
239
|
-
function assertStableText(value, label) {
|
|
240
|
-
if (value.length === 0 || value.trim() !== value) throw new Error(`${label} must be non-empty and have no outer whitespace`);
|
|
241
|
-
}
|
|
242
|
-
function abortError(reason) {
|
|
243
|
-
const error = new Error(reason instanceof Error ? reason.message : reason === void 0 ? "aborted" : String(reason));
|
|
244
|
-
error.name = "AbortError";
|
|
245
|
-
return error;
|
|
246
|
-
}
|
|
247
|
-
function assertWaitDuration(value, label) {
|
|
248
|
-
if (!Number.isSafeInteger(value) || value < 0) throw new Error(`${label} must be a non-negative safe integer`);
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Whether a session can still change state.
|
|
252
|
-
*
|
|
253
|
-
* Exhaustive over `AgentSessionStatus` by construction: the map below is `satisfies
|
|
254
|
-
* Record<AgentSessionStatus, boolean>`, so a member added upstream fails to compile here instead of
|
|
255
|
-
* being silently classified as non-terminal. Written as a boolean chain, `stopped` was missing —
|
|
256
|
-
* and a `status({ waitMs })` call on an already-stopped session then polled every 25 ms for the
|
|
257
|
-
* whole wait before returning the answer it already had at the first snapshot.
|
|
258
|
-
*
|
|
259
|
-
* `unknown` is deliberately NOT terminal: it says the provider could not tell us, which is the one
|
|
260
|
-
* state where continuing to poll is the point. That differs from
|
|
261
|
-
* `sandboxSessionStatusFromAgentSessionStatus`, which projects `unknown` to `failed` because a run
|
|
262
|
-
* RESULT must never claim success without proof — a different question about the same word.
|
|
263
|
-
*/
|
|
264
|
-
const sessionStatusIsTerminal = {
|
|
265
|
-
pending: false,
|
|
266
|
-
provisioning: false,
|
|
267
|
-
running: false,
|
|
268
|
-
unknown: false,
|
|
269
|
-
stopped: true,
|
|
270
|
-
completed: true,
|
|
271
|
-
cancelled: true,
|
|
272
|
-
failed: true,
|
|
273
|
-
expired: true
|
|
274
|
-
};
|
|
275
|
-
function isTerminalSessionStatus(status) {
|
|
276
|
-
return status !== null && sessionStatusIsTerminal[status];
|
|
277
|
-
}
|
|
278
|
-
function delay(ms, signal) {
|
|
279
|
-
if (signal?.aborted) return Promise.reject(abortError(signal.reason));
|
|
280
|
-
return new Promise((resolveDelay, rejectDelay) => {
|
|
281
|
-
const timer = setTimeout(finish, ms);
|
|
282
|
-
function finish() {
|
|
283
|
-
signal?.removeEventListener("abort", onAbort);
|
|
284
|
-
resolveDelay();
|
|
285
|
-
}
|
|
286
|
-
function onAbort() {
|
|
287
|
-
clearTimeout(timer);
|
|
288
|
-
signal?.removeEventListener("abort", onAbort);
|
|
289
|
-
rejectDelay(abortError(signal?.reason));
|
|
290
|
-
}
|
|
291
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
//#endregion
|
|
295
|
-
//#region src/runtime/supervise/snapshot.ts
|
|
296
|
-
/** Deeply detach and freeze untrusted data at a runtime decision boundary. The clone prevents the
|
|
297
|
-
* caller from mutating it later; the freeze prevents downstream code from mutating the snapshot. */
|
|
298
|
-
function detachedSnapshot(value, context) {
|
|
299
|
-
try {
|
|
300
|
-
return deepFreeze(structuredClone(value));
|
|
301
|
-
} catch (error) {
|
|
302
|
-
throw new ValidationError(`${context}: input must be structured-cloneable`, { cause: error });
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
/** Detach a value from its caller and freeze it, without the `ValidationError` framing
|
|
306
|
-
* {@link detachedSnapshot} adds. For a boundary that has already validated its input. */
|
|
307
|
-
function detachedFrozen(value) {
|
|
308
|
-
return deepFreeze(structuredClone(value));
|
|
309
|
-
}
|
|
310
|
-
function deepFreeze(value, seen = /* @__PURE__ */ new Set()) {
|
|
311
|
-
if (value === null || typeof value !== "object" || ArrayBuffer.isView(value) || seen.has(value)) return value;
|
|
312
|
-
seen.add(value);
|
|
313
|
-
for (const child of Object.values(value)) deepFreeze(child, seen);
|
|
314
|
-
return Object.freeze(value);
|
|
315
|
-
}
|
|
316
|
-
//#endregion
|
|
317
|
-
//#region src/runtime/supervise/materialization.ts
|
|
318
|
-
const runtimeOwnedExecutorMaterializations = /* @__PURE__ */ new WeakMap();
|
|
319
|
-
const runtimeOwnedScopeOwners = /* @__PURE__ */ new WeakMap();
|
|
320
|
-
const runtimeOwnedExecutorProviderEvidenceState = /* @__PURE__ */ new WeakMap();
|
|
321
|
-
const runtimeOwnedDriveHarnessProviderEvidenceState = /* @__PURE__ */ new WeakMap();
|
|
322
|
-
const declarationKeys = /* @__PURE__ */ new Set([
|
|
323
|
-
"effectiveProfile",
|
|
324
|
-
"authoredProfile",
|
|
325
|
-
"backend",
|
|
326
|
-
"model",
|
|
327
|
-
"execution",
|
|
328
|
-
"materializer",
|
|
329
|
-
"plan",
|
|
330
|
-
"platformAttachments"
|
|
331
|
-
]);
|
|
332
|
-
/**
|
|
333
|
-
* Bind a declaration to a runtime-owned executor without putting an attestable method on the
|
|
334
|
-
* public Executor interface. This module is not a package export: arbitrary caller executors stay
|
|
335
|
-
* unknown even if they add a lookalike `materialization()` property.
|
|
336
|
-
*/
|
|
337
|
-
function attestRuntimeOwnedExecutor(executor, declaration, binding) {
|
|
338
|
-
runtimeOwnedExecutorMaterializations.set(executor, { current: Object.freeze({
|
|
339
|
-
kind: "known",
|
|
340
|
-
declaration: detachedSnapshot(declaration, "runtime-owned executor materialization"),
|
|
341
|
-
...binding === void 0 ? {} : { binding: detachedSnapshot(binding, "runtime-owned executor execution binding") }
|
|
342
|
-
}) });
|
|
343
|
-
ensureProviderEvidenceState(executor);
|
|
344
|
-
return executor;
|
|
345
|
-
}
|
|
346
|
-
/** Brand an external Runtime executor whose exact remote materialization is provable only after
|
|
347
|
-
* its terminal protocol acknowledgement. The declaration is a planned authority check, never a
|
|
348
|
-
* known receipt; callers must finalize this same object after validating the acknowledgement. */
|
|
349
|
-
function attestRuntimeOwnedPendingExecutor(executor, runtime, declaration, binding) {
|
|
350
|
-
runtimeOwnedExecutorMaterializations.set(executor, { current: Object.freeze({
|
|
351
|
-
kind: "pending",
|
|
352
|
-
runtime,
|
|
353
|
-
declaration: detachedSnapshot(declaration, "pending executor materialization"),
|
|
354
|
-
binding: detachedSnapshot(binding, "pending executor execution binding")
|
|
355
|
-
}) });
|
|
356
|
-
return executor;
|
|
357
|
-
}
|
|
358
|
-
/** Replace a private pending brand with terminally acknowledged evidence. A caller-owned executor
|
|
359
|
-
* cannot enter this path because only this module can create the pending WeakMap entry. */
|
|
360
|
-
function finalizeRuntimeOwnedPendingExecutor(executor, declaration, binding) {
|
|
361
|
-
const ref = runtimeOwnedExecutorMaterializations.get(executor);
|
|
362
|
-
if (ref?.current.kind !== "pending" || ref.current.runtime !== executor.runtime) throw new ValidationError("executor materialization: terminal acknowledgement has no matching Runtime-owned pending executor");
|
|
363
|
-
ref.current = Object.freeze({
|
|
364
|
-
kind: "known",
|
|
365
|
-
declaration: detachedSnapshot(declaration, "runtime-owned executor materialization"),
|
|
366
|
-
binding: detachedSnapshot(binding, "runtime-owned executor execution binding")
|
|
367
|
-
});
|
|
368
|
-
return executor;
|
|
369
|
-
}
|
|
370
|
-
/** Mark a runtime-owned orchestration executor whose exact leaf declaration is published through
|
|
371
|
-
* its private nested Scope before the first backend inference. Arbitrary executors cannot opt in. */
|
|
372
|
-
function attestRuntimeOwnedDeferredExecutor(executor, runtime) {
|
|
373
|
-
runtimeOwnedExecutorMaterializations.set(executor, { current: Object.freeze({
|
|
374
|
-
kind: "deferred",
|
|
375
|
-
runtime
|
|
376
|
-
}) });
|
|
377
|
-
return executor;
|
|
378
|
-
}
|
|
379
|
-
/** Preserve the runtime-owned attestation when a trusted wrapper changes result semantics only. */
|
|
380
|
-
function inheritRuntimeOwnedExecutorAttestation(source, wrapper) {
|
|
381
|
-
const ref = runtimeOwnedExecutorMaterializations.get(source);
|
|
382
|
-
if (ref !== void 0) runtimeOwnedExecutorMaterializations.set(wrapper, ref);
|
|
383
|
-
const providerState = ensureProviderEvidenceState(source);
|
|
384
|
-
runtimeOwnedExecutorProviderEvidenceState.set(wrapper, providerState);
|
|
385
|
-
return wrapper;
|
|
386
|
-
}
|
|
387
|
-
function ensureProviderEvidenceState(executor) {
|
|
388
|
-
const existing = runtimeOwnedExecutorProviderEvidenceState.get(executor);
|
|
389
|
-
if (existing !== void 0) return existing;
|
|
390
|
-
const state = { attempts: [] };
|
|
391
|
-
runtimeOwnedExecutorProviderEvidenceState.set(executor, state);
|
|
392
|
-
return state;
|
|
393
|
-
}
|
|
394
|
-
/** Read a declaration only when Runtime itself branded this exact executor object. */
|
|
395
|
-
function runtimeOwnedExecutorMaterialization(executor) {
|
|
396
|
-
const attestation = runtimeOwnedExecutorMaterializations.get(executor)?.current;
|
|
397
|
-
return attestation?.kind === "known" ? attestation.declaration : void 0;
|
|
398
|
-
}
|
|
399
|
-
/** Read one attempt binding only from the private brand on this exact executor object. */
|
|
400
|
-
function runtimeOwnedExecutorExecutionBinding(executor) {
|
|
401
|
-
const attestation = runtimeOwnedExecutorMaterializations.get(executor)?.current;
|
|
402
|
-
return attestation?.kind === "known" ? attestation.binding : void 0;
|
|
403
|
-
}
|
|
404
|
-
/** Read a planned external declaration only for Runtime's private pending brand. This is useful for
|
|
405
|
-
* pre-execution authority checks, but must never be turned into a known durable receipt. */
|
|
406
|
-
function runtimeOwnedPendingExecutorMaterialization(executor) {
|
|
407
|
-
const attestation = runtimeOwnedExecutorMaterializations.get(executor)?.current;
|
|
408
|
-
return attestation?.kind === "pending" ? {
|
|
409
|
-
runtime: attestation.runtime,
|
|
410
|
-
declaration: attestation.declaration,
|
|
411
|
-
binding: attestation.binding
|
|
412
|
-
} : void 0;
|
|
413
|
-
}
|
|
414
|
-
/** Read the expected leaf runtime only for a privately branded deferred orchestration executor. */
|
|
415
|
-
function runtimeOwnedDeferredExecutorRuntime(executor) {
|
|
416
|
-
const attestation = runtimeOwnedExecutorMaterializations.get(executor)?.current;
|
|
417
|
-
return attestation?.kind === "deferred" ? attestation.runtime : void 0;
|
|
418
|
-
}
|
|
419
|
-
/** Propagate trust from a built-in driver adapter to the Agent and recursive executor it owns. */
|
|
420
|
-
function attestRuntimeOwnedScopeOwner(owner, runtime) {
|
|
421
|
-
runtimeOwnedScopeOwners.set(owner, runtime);
|
|
422
|
-
return owner;
|
|
423
|
-
}
|
|
424
|
-
/** Return a built-in scope owner's expected concrete leaf runtime; caller-owned functions/Agents
|
|
425
|
-
* deliberately have no entry even if they add lookalike fields. */
|
|
426
|
-
function runtimeOwnedScopeOwnerRuntime(owner) {
|
|
427
|
-
return runtimeOwnedScopeOwners.get(owner);
|
|
428
|
-
}
|
|
429
|
-
/** Mark one provider inference attempt on a Runtime-owned executor. */
|
|
430
|
-
function recordRuntimeOwnedProviderAttemptStart(executor) {
|
|
431
|
-
ensureProviderEvidenceState(executor).attempts.push({ observations: [] });
|
|
432
|
-
}
|
|
433
|
-
/** Mark the current attempt as rejected before provider dispatch.
|
|
434
|
-
*
|
|
435
|
-
* The caller may use this only after consuming the Router-owned
|
|
436
|
-
* `provider_dispatch: "not_started"` fact. Any other error stays an empty,
|
|
437
|
-
* unknown attempt and must not be upgraded here.
|
|
438
|
-
*/
|
|
439
|
-
function recordRuntimeOwnedProviderDispatchNotStarted(executor) {
|
|
440
|
-
const attempt = ensureProviderEvidenceState(executor).attempts.at(-1);
|
|
441
|
-
if (attempt === void 0) throw new ValidationError("provider dispatch rejection arrived before an attempt started");
|
|
442
|
-
if (attempt.observations.length > 0 || attempt.identityConflict === true) throw new ValidationError("provider dispatch rejection arrived after provider identity evidence was observed");
|
|
443
|
-
attempt.providerDispatch = "not_started";
|
|
444
|
-
}
|
|
445
|
-
/** Record a trusted served model on the current provider attempt. */
|
|
446
|
-
function recordRuntimeOwnedProviderModel(executor, model) {
|
|
447
|
-
const attempt = runtimeOwnedExecutorProviderEvidenceState.get(executor)?.attempts.at(-1);
|
|
448
|
-
if (attempt === void 0) throw new ValidationError("provider model observation arrived before an attempt started");
|
|
449
|
-
if (attempt.observations.at(-1) !== model) attempt.observations.push(model);
|
|
450
|
-
}
|
|
451
|
-
/** Convert process-local provider observations into a frozen, replayable evidence value. */
|
|
452
|
-
function runtimeOwnedExecutorProviderEvidence(executor) {
|
|
453
|
-
const state = runtimeOwnedExecutorProviderEvidenceState.get(executor);
|
|
454
|
-
if (state === void 0 || state.attempts.length === 0) return void 0;
|
|
455
|
-
const attempts = Object.freeze(state.attempts.map((attempt) => Object.freeze({
|
|
456
|
-
observations: Object.freeze([...attempt.observations]),
|
|
457
|
-
...attempt.identityConflict ? { identityConflict: true } : {},
|
|
458
|
-
...attempt.providerDispatch === "not_started" ? { providerDispatch: "not_started" } : {}
|
|
459
|
-
})));
|
|
460
|
-
const models = Object.freeze([...new Set(attempts.flatMap((attempt) => attempt.observations))]);
|
|
461
|
-
const missing = attempts.some((attempt) => attempt.observations.length === 0 && attempt.providerDispatch !== "not_started");
|
|
462
|
-
const conflict = attempts.some((attempt) => attempt.identityConflict === true);
|
|
463
|
-
const served = attempts.some((attempt) => attempt.observations.length > 0);
|
|
464
|
-
return Object.freeze(missing || conflict || !served ? {
|
|
465
|
-
status: "unknown",
|
|
466
|
-
attempts,
|
|
467
|
-
models,
|
|
468
|
-
reason: conflict ? "provider-model-conflict" : "provider-model-missing"
|
|
469
|
-
} : {
|
|
470
|
-
status: "known",
|
|
471
|
-
attempts,
|
|
472
|
-
models
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
/** Mark the current provider attempt unusable after conflicting served identity metadata. */
|
|
476
|
-
function recordRuntimeOwnedProviderIdentityConflict(executor) {
|
|
477
|
-
const attempt = ensureProviderEvidenceState(executor).attempts.at(-1);
|
|
478
|
-
if (attempt === void 0) throw new ValidationError("provider identity conflict arrived before an attempt started");
|
|
479
|
-
attempt.identityConflict = true;
|
|
480
|
-
}
|
|
481
|
-
/** Attach one executor's provider evidence to a Runtime-owned root drive for final projection. */
|
|
482
|
-
function recordRuntimeOwnedDriveHarnessProviderEvidence(owner, evidence) {
|
|
483
|
-
if (evidence === void 0) return;
|
|
484
|
-
const prior = runtimeOwnedDriveHarnessProviderEvidenceState.get(owner);
|
|
485
|
-
if (prior === void 0) {
|
|
486
|
-
runtimeOwnedDriveHarnessProviderEvidenceState.set(owner, evidence);
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
const attempts = Object.freeze([...prior.attempts, ...evidence.attempts]);
|
|
490
|
-
const models = Object.freeze([.../* @__PURE__ */ new Set([...prior.models, ...evidence.models])]);
|
|
491
|
-
const missing = attempts.some((attempt) => attempt.observations.length === 0 && attempt.providerDispatch !== "not_started");
|
|
492
|
-
const conflict = attempts.some((attempt) => attempt.identityConflict === true);
|
|
493
|
-
const served = attempts.some((attempt) => attempt.observations.length > 0);
|
|
494
|
-
runtimeOwnedDriveHarnessProviderEvidenceState.set(owner, Object.freeze(missing || conflict || !served ? {
|
|
495
|
-
status: "unknown",
|
|
496
|
-
attempts,
|
|
497
|
-
models,
|
|
498
|
-
reason: conflict ? "provider-model-conflict" : "provider-model-missing"
|
|
499
|
-
} : {
|
|
500
|
-
status: "known",
|
|
501
|
-
attempts,
|
|
502
|
-
models
|
|
503
|
-
}));
|
|
504
|
-
}
|
|
505
|
-
/** Read provider evidence recorded by a Runtime-owned root drive. */
|
|
506
|
-
function runtimeOwnedDriveHarnessProviderEvidence(owner) {
|
|
507
|
-
return runtimeOwnedDriveHarnessProviderEvidenceState.get(owner);
|
|
508
|
-
}
|
|
509
|
-
/** Build one kernel-owned known receipt from a data-only executor declaration. */
|
|
510
|
-
function knownMaterializationReceipt(input) {
|
|
511
|
-
const declaration = detachedSnapshot(input.declaration, "executor materialization");
|
|
512
|
-
assertExactDeclaration(declaration);
|
|
513
|
-
const effectiveProfile = agentProfileSchema.safeParse(declaration.effectiveProfile);
|
|
514
|
-
if (!effectiveProfile.success) throw new ValidationError("executor materialization: effectiveProfile must be an AgentProfile");
|
|
515
|
-
const authoredProfile = declaration.authoredProfile === void 0 ? effectiveProfile : agentProfileSchema.safeParse(declaration.authoredProfile);
|
|
516
|
-
if (!authoredProfile.success) throw new ValidationError("executor materialization: authoredProfile must be an AgentProfile");
|
|
517
|
-
assertNonEmpty(declaration.backend, "backend");
|
|
518
|
-
assertNonEmpty(declaration.materializer, "materializer");
|
|
519
|
-
assertNonEmpty(declaration.execution?.kind, "execution.kind");
|
|
520
|
-
assertNonEmpty(declaration.execution?.id, "execution.id");
|
|
521
|
-
assertModel(declaration.model);
|
|
522
|
-
let effectiveProfileDigest;
|
|
523
|
-
let materializationPlanDigest;
|
|
524
|
-
let platformAttachmentsDigest;
|
|
525
|
-
try {
|
|
526
|
-
effectiveProfileDigest = canonicalAgentProfileDigest(effectiveProfile.data);
|
|
527
|
-
if (canonicalAgentProfileDigest(authoredProfile.data) !== input.authoredProfileDigest) throw new ValidationError("executor materialization: authoredProfile conflicts with the admitted AgentProfile");
|
|
528
|
-
materializationPlanDigest = canonicalCandidateDigest(jsonWireSnapshot(declaration.plan));
|
|
529
|
-
platformAttachmentsDigest = declaration.platformAttachments === void 0 ? void 0 : canonicalCandidateDigest(jsonWireSnapshot(declaration.platformAttachments));
|
|
530
|
-
} catch (error) {
|
|
531
|
-
throw new ValidationError("executor materialization: profile, plan, and attachments must be finite RFC 8785 JSON", { cause: error });
|
|
532
|
-
}
|
|
533
|
-
return Object.freeze({
|
|
534
|
-
status: "known",
|
|
535
|
-
authoredProfileDigest: input.authoredProfileDigest,
|
|
536
|
-
effectiveProfileDigest,
|
|
537
|
-
materializationPlanDigest,
|
|
538
|
-
...platformAttachmentsDigest === void 0 ? {} : { platformAttachmentsDigest },
|
|
539
|
-
runtime: input.runtime,
|
|
540
|
-
backend: declaration.backend,
|
|
541
|
-
model: declaration.model,
|
|
542
|
-
execution: declaration.execution,
|
|
543
|
-
materializer: declaration.materializer
|
|
544
|
-
});
|
|
545
|
-
}
|
|
546
|
-
/** Build an explicit unknown receipt without fabricating any executor-owned identity. */
|
|
547
|
-
function unknownMaterializationReceipt(input) {
|
|
548
|
-
return Object.freeze({
|
|
549
|
-
status: "unknown",
|
|
550
|
-
...input.authoredProfileDigest === void 0 ? {} : { authoredProfileDigest: input.authoredProfileDigest },
|
|
551
|
-
runtime: input.runtime,
|
|
552
|
-
reason: input.reason
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
/** Mint a process-unique attempt id before executor construction. */
|
|
556
|
-
function newExecutionAttemptId(nodeId) {
|
|
557
|
-
return `${nodeId}:attempt:${randomUUID()}`;
|
|
558
|
-
}
|
|
559
|
-
/** Build the immutable safe receipt for a full, transient execution binding. */
|
|
560
|
-
function knownExecutionBindingReceipt(materialization, bindingInput) {
|
|
561
|
-
const binding = detachedSnapshot(bindingInput, "executor execution binding");
|
|
562
|
-
assertNonEmpty(binding.attemptId, "binding.attemptId");
|
|
563
|
-
assertSafeDescriptor(binding.descriptor);
|
|
564
|
-
let materializationReceiptDigest;
|
|
565
|
-
let bindingDigest;
|
|
566
|
-
try {
|
|
567
|
-
materializationReceiptDigest = canonicalCandidateDigest(materialization);
|
|
568
|
-
bindingDigest = canonicalCandidateDigest(jsonWireSnapshot(binding.binding));
|
|
569
|
-
} catch (error) {
|
|
570
|
-
throw new ValidationError("executor binding must be finite RFC 8785 JSON", { cause: error });
|
|
571
|
-
}
|
|
572
|
-
return Object.freeze({
|
|
573
|
-
status: "known",
|
|
574
|
-
attemptId: binding.attemptId,
|
|
575
|
-
materializationReceiptDigest,
|
|
576
|
-
bindingDigest,
|
|
577
|
-
descriptor: binding.descriptor
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
/** Preserve an attempt boundary even when its caller-owned transport cannot be attested. */
|
|
581
|
-
function unknownExecutionBindingReceipt(materialization, attemptId, reason) {
|
|
582
|
-
assertNonEmpty(attemptId, "binding.attemptId");
|
|
583
|
-
return Object.freeze({
|
|
584
|
-
status: "unknown",
|
|
585
|
-
attemptId,
|
|
586
|
-
materializationReceiptDigest: canonicalCandidateDigest(materialization),
|
|
587
|
-
reason
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
/** Derive an authored-profile digest without turning non-canonical input into a fake identity. */
|
|
591
|
-
function authoredProfileDigest(profile) {
|
|
592
|
-
try {
|
|
593
|
-
return canonicalAgentProfileDigest(agentProfileSchema.parse(profile));
|
|
594
|
-
} catch {
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
function assertExactDeclaration(value) {
|
|
599
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new ValidationError("executor materialization: declaration must be an object");
|
|
600
|
-
const unknown = Object.keys(value).filter((key) => !declarationKeys.has(key));
|
|
601
|
-
if (unknown.length > 0) throw new ValidationError(`executor materialization: unknown declaration fields: ${unknown.sort().join(", ")}`);
|
|
602
|
-
if (!Object.hasOwn(value, "plan")) throw new ValidationError("executor materialization: plan is required");
|
|
603
|
-
}
|
|
604
|
-
function assertModel(model) {
|
|
605
|
-
if (typeof model !== "object" || model === null || Array.isArray(model)) throw new ValidationError("executor materialization: model must be a known/unknown identity");
|
|
606
|
-
const keys = Object.keys(model).sort();
|
|
607
|
-
if (model.status === "known") {
|
|
608
|
-
if (keys.join(",") !== "id,status") throw new ValidationError("executor materialization: known model accepts only status and id");
|
|
609
|
-
assertNonEmpty(model.id, "model.id");
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
if (model.status === "unknown") {
|
|
613
|
-
if (keys.join(",") !== "reason,status") throw new ValidationError("executor materialization: unknown model accepts only status and reason");
|
|
614
|
-
assertNonEmpty(model.reason, "model.reason");
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
throw new ValidationError("executor materialization: model.status must be known or unknown");
|
|
618
|
-
}
|
|
619
|
-
function assertNonEmpty(value, field) {
|
|
620
|
-
if (typeof value !== "string" || value.trim().length === 0) throw new ValidationError(`executor materialization: ${field} must be a non-empty string`);
|
|
621
|
-
}
|
|
622
|
-
function assertSafeDescriptor(descriptor) {
|
|
623
|
-
if (typeof descriptor !== "object" || descriptor === null || Array.isArray(descriptor)) throw new ValidationError("executor binding: descriptor must be an object");
|
|
624
|
-
for (const [key, value] of Object.entries(descriptor)) {
|
|
625
|
-
if (/(url|uri|token|key|secret|bearer|credential|authorization)/i.test(key)) throw new ValidationError(`executor binding: unsafe descriptor key ${JSON.stringify(key)}`);
|
|
626
|
-
if (value !== null && typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") throw new ValidationError(`executor binding: descriptor ${JSON.stringify(key)} must be scalar`);
|
|
627
|
-
if (typeof value === "string" && (value.includes("://") || value.includes("@"))) throw new ValidationError(`executor binding: descriptor ${JSON.stringify(key)} contains transport or credential text`);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
function jsonWireSnapshot(value, path = "$") {
|
|
631
|
-
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
632
|
-
if (typeof value === "number") {
|
|
633
|
-
if (!Number.isFinite(value)) throw new ValidationError(`executor binding: ${path} must be finite`);
|
|
634
|
-
return value;
|
|
635
|
-
}
|
|
636
|
-
if (Array.isArray(value)) return value.map((item, index) => {
|
|
637
|
-
if (item === void 0) throw new ValidationError(`executor binding: ${path}[${index}] cannot be undefined`);
|
|
638
|
-
return jsonWireSnapshot(item, `${path}[${index}]`);
|
|
639
|
-
});
|
|
640
|
-
if (typeof value !== "object" || value === null) throw new ValidationError(`executor binding: ${path} must be JSON data`);
|
|
641
|
-
const prototype = Object.getPrototypeOf(value);
|
|
642
|
-
if (prototype !== Object.prototype && prototype !== null) throw new ValidationError(`executor binding: ${path} must be a plain object`);
|
|
643
|
-
const out = {};
|
|
644
|
-
for (const [key, item] of Object.entries(value)) {
|
|
645
|
-
if (item === void 0) continue;
|
|
646
|
-
out[key] = jsonWireSnapshot(item, `${path}.${key}`);
|
|
647
|
-
}
|
|
648
|
-
return out;
|
|
649
|
-
}
|
|
650
|
-
/**
|
|
651
|
-
* The provider-identity evidence for ONE attempt, from the served model alone. `unknown` with a
|
|
652
|
-
* `provider-model-missing` reason when the attempt produced no model, because an attempt that
|
|
653
|
-
* cannot name what served it is not evidence that nothing did.
|
|
654
|
-
*/
|
|
655
|
-
function providerAttemptEvidence(model) {
|
|
656
|
-
const attempts = Object.freeze([Object.freeze({ observations: Object.freeze(model === void 0 ? [] : [model]) })]);
|
|
657
|
-
const models = Object.freeze(model === void 0 ? [] : [model]);
|
|
658
|
-
return Object.freeze(model === void 0 ? {
|
|
659
|
-
status: "unknown",
|
|
660
|
-
attempts,
|
|
661
|
-
models,
|
|
662
|
-
reason: "provider-model-missing"
|
|
663
|
-
} : {
|
|
664
|
-
status: "known",
|
|
665
|
-
attempts,
|
|
666
|
-
models
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
//#endregion
|
|
670
|
-
export { promptOptionsFromAgentTurnInput as $, assertBoundaryBinding as A, copyControlRef as B, runtimeOwnedScopeOwnerRuntime as C, detachedSnapshot as D, detachedFrozen as E, assertSequence as F, exactSessionCancel as G, exactContinuedControlRef as H, assertStableText as I, hasDurableCancel as J, exactSessionResult as K, assertWaitDuration as L, assertEventBinding as M, assertInteractionBinding as N, RetainedRunProviderContractError as O, assertResultBinding as P, promptFromAgentTurnInput as Q, awaitAbortable as R, runtimeOwnedPendingExecutorMaterialization as S, unknownMaterializationReceipt as T, exactControlRef as U, delay as V, exactSession as W, sameControlCoordinates as X, isTerminalSessionStatus as Y, freshTurnInput as Z, runtimeOwnedDeferredExecutorRuntime as _, authoredProfileDigest as a, runtimeOwnedExecutorMaterialization as b, knownExecutionBindingReceipt as c, providerAttemptEvidence as d, providerMessageText as et, recordRuntimeOwnedDriveHarnessProviderEvidence as f, recordRuntimeOwnedProviderModel as g, recordRuntimeOwnedProviderIdentityConflict as h, attestRuntimeOwnedScopeOwner as i, assertCanonicalEventBinding as j, abortError as k, knownMaterializationReceipt as l, recordRuntimeOwnedProviderDispatchNotStarted as m, attestRuntimeOwnedExecutor as n, finalizeRuntimeOwnedPendingExecutor as o, recordRuntimeOwnedProviderAttemptStart as p, freezeControlRef as q, attestRuntimeOwnedPendingExecutor as r, inheritRuntimeOwnedExecutorAttestation as s, attestRuntimeOwnedDeferredExecutor as t, newExecutionAttemptId as u, runtimeOwnedDriveHarnessProviderEvidence as v, unknownExecutionBindingReceipt as w, runtimeOwnedExecutorProviderEvidence as x, runtimeOwnedExecutorExecutionBinding as y, cancellationRequest as z };
|
|
671
|
-
|
|
672
|
-
//# sourceMappingURL=materialization-Cy0oM8tb.js.map
|