stitchkit 0.136.0 → 0.136.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/CHANGELOG.md +13 -0
- package/README.md +12 -0
- package/dist/agent-executor/executor-contract.d.ts.map +1 -1
- package/dist/agent-executor/vocabulary.d.ts +80 -0
- package/dist/agent-executor/vocabulary.d.ts.map +1 -1
- package/dist/agent-parts/model.d.ts +94 -0
- package/dist/agent-parts/model.d.ts.map +1 -1
- package/dist/agent-parts/parts.d.ts +176 -0
- package/dist/agent-parts/parts.d.ts.map +1 -1
- package/dist/agent-runtime/browser/browser-control-contract.d.ts +440 -0
- package/dist/agent-runtime/browser/browser-control-contract.d.ts.map +1 -1
- package/dist/agent-runtime/browser/control-schema.d.ts +528 -0
- package/dist/agent-runtime/browser/control-schema.d.ts.map +1 -1
- package/dist/agent-runtime/event-schema.d.ts +704 -0
- package/dist/agent-runtime/event-schema.d.ts.map +1 -1
- package/dist/agent-runtime/history/run-history-parts.d.ts.map +1 -1
- package/dist/agent-runtime/loop/provider-stream-parts.d.ts.map +1 -1
- package/dist/agent-runtime/loop/provider-stream-segments.d.ts +0 -2
- package/dist/agent-runtime/loop/provider-stream-segments.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-approval-signature.d.ts +5 -1
- package/dist/agent-runtime/loop/run-approval-signature.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-loop-events.d.ts +6 -1
- package/dist/agent-runtime/loop/run-loop-events.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-stream-parts.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-stream-recorded.d.ts.map +1 -1
- package/dist/agent-runtime/loop/run-tool-call.d.ts +11 -3
- package/dist/agent-runtime/loop/run-tool-call.d.ts.map +1 -1
- package/dist/agent-runtime/providers/ai-sdk-normalize.d.ts +4 -0
- package/dist/agent-runtime/providers/ai-sdk-normalize.d.ts.map +1 -1
- package/dist/agent-runtime/providers/ai-sdk-tools.d.ts.map +1 -1
- package/dist/agent-runtime/runtime-internals.d.ts +1 -3
- package/dist/agent-runtime/runtime-internals.d.ts.map +1 -1
- package/dist/agent-runtime/schemas-json-projection.d.ts +29 -0
- package/dist/agent-runtime/schemas-json-projection.d.ts.map +1 -0
- package/dist/agent-runtime/schemas-message.d.ts +88 -0
- package/dist/agent-runtime/schemas-message.d.ts.map +1 -1
- package/dist/agent-runtime/schemas-run.d.ts +88 -0
- package/dist/agent-runtime/schemas-run.d.ts.map +1 -1
- package/dist/agent-runtime/stores/branch-messages.d.ts.map +1 -1
- package/dist/agent-runtime/stores/branch-replay.d.ts +264 -0
- package/dist/agent-runtime/stores/branch-replay.d.ts.map +1 -1
- package/dist/agent-runtime/stores/conversations.d.ts +88 -0
- package/dist/agent-runtime/stores/conversations.d.ts.map +1 -1
- package/dist/agent-runtime/stores/sql-rows.d.ts +64 -0
- package/dist/agent-runtime/stores/sql-rows.d.ts.map +1 -1
- package/dist/agent-runtime/stores/store-driver-contract.d.ts +616 -0
- package/dist/agent-runtime/stores/store-driver-contract.d.ts.map +1 -1
- package/dist/agent-runtime/stores/store-events.d.ts +1056 -0
- package/dist/agent-runtime/stores/store-events.d.ts.map +1 -1
- package/dist/agent-runtime/stores/store.d.ts +1232 -0
- package/dist/agent-runtime/stores/store.d.ts.map +1 -1
- package/dist/agent-runtime/terminal-commit.d.ts +69 -5
- package/dist/agent-runtime/terminal-commit.d.ts.map +1 -1
- package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts +164 -36
- package/dist/agent-runtime/testing/store-conformance-lifecycle.d.ts.map +1 -1
- package/dist/agent-runtime/testing/store-conformance-support.d.ts +82 -18
- package/dist/agent-runtime/testing/store-conformance-support.d.ts.map +1 -1
- package/dist/application/diagnostic-journal-manager.d.ts +1 -1
- package/dist/application/diagnostic-journal-manager.d.ts.map +1 -1
- package/dist/application/notification-delivery.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +5 -4
- package/dist/entrypoints/agent-executor/claude-sdk.js +7 -6
- package/dist/entrypoints/agent-executor/claude.js +7 -6
- package/dist/entrypoints/agent-executor/codex.js +6 -5
- package/dist/entrypoints/agent-executor/testing/claude-sdk.js +4 -3
- package/dist/entrypoints/agent-executor/testing.js +7 -6
- package/dist/entrypoints/agent-executor.js +7 -7
- package/dist/entrypoints/agent-runtime/ai-sdk.js +30 -24
- package/dist/entrypoints/agent-runtime/anthropic.js +3 -3
- package/dist/entrypoints/agent-runtime/browser.js +8 -7
- package/dist/entrypoints/agent-runtime/harness.js +14 -14
- package/dist/entrypoints/agent-runtime/openai.js +3 -3
- package/dist/entrypoints/agent-runtime/openrouter.js +3 -3
- package/dist/entrypoints/agent-runtime/postgres.js +9 -9
- package/dist/entrypoints/agent-runtime/realtime.js +9 -8
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +10 -10
- package/dist/entrypoints/agent-runtime/sqlite/node.js +10 -10
- package/dist/entrypoints/agent-runtime/testing.js +8 -8
- package/dist/entrypoints/agent-runtime.js +21 -21
- package/dist/entrypoints/application/diagnostic-journal.js +14 -10
- package/dist/entrypoints/application.js +16 -4
- package/dist/entrypoints/tools/agent.js +2 -2
- package/dist/entrypoints/tools/toolkit.js +1 -1
- package/dist/entrypoints/tools.js +5 -3
- package/dist/index-1psbyyhj.js +21 -0
- package/dist/{index-kzsetgh9.js → index-26v8hjqm.js} +4 -4
- package/dist/{index-4243301z.js → index-2wm9b9vs.js} +5 -5
- package/dist/{index-tb36xawm.js → index-32ew02z1.js} +1 -1
- package/dist/{index-1en7k3q5.js → index-4q9tmzea.js} +3 -3
- package/dist/{index-shte29pg.js → index-8cnfgwg8.js} +148 -106
- package/dist/{index-mkmep637.js → index-9m1m92rg.js} +1 -1
- package/dist/index-a1rjr381.js +114 -0
- package/dist/{index-6kwdfb9m.js → index-akesakvj.js} +23 -4
- package/dist/{index-rg08syp1.js → index-d5mhgx72.js} +7 -5
- package/dist/{index-36mtj8xm.js → index-e4w0sfm1.js} +2 -2
- package/dist/{index-jperyn0c.js → index-gj4wdts6.js} +1 -1
- package/dist/{index-pd9e8rz4.js → index-gvv7y0s4.js} +1 -1
- package/dist/{index-vebzvse6.js → index-jy907kcs.js} +24 -1
- package/dist/{index-54wp467c.js → index-k5azb3v3.js} +4 -21
- package/dist/{index-qcy8et93.js → index-kaq9nb7h.js} +6 -6
- package/dist/{index-vse7x1qt.js → index-knqye3gv.js} +1 -1
- package/dist/{index-tav72wz5.js → index-ks4rhtcc.js} +5 -0
- package/dist/{index-xnqab06h.js → index-mtpcax6d.js} +3 -3
- package/dist/{index-7qza24g1.js → index-px9r6wv1.js} +1 -1
- package/dist/{index-epwvp88y.js → index-r9w7wfgn.js} +1 -1
- package/dist/{index-aacwkve4.js → index-sjq4akrx.js} +3 -5
- package/dist/{index-5dxgx3yj.js → index-tcv71frn.js} +1 -1
- package/dist/{index-1zy31r3b.js → index-v92djygb.js} +1 -1
- package/dist/{index-9f60gnfn.js → index-xaa3603f.js} +4 -11
- package/dist/{index-j3r7r1mh.js → index-yv7d6tav.js} +1 -1
- package/dist/{index-hberxns4.js → index-zagc12j1.js} +5 -5
- package/dist/{index-j5vzhj3d.js → index-zqc64g69.js} +3 -3
- package/dist/{index-hpzhz1vm.js → index-zthekmrt.js} +2 -2
- package/dist/internal/json-stringify.d.ts +37 -0
- package/dist/internal/json-stringify.d.ts.map +1 -0
- package/llms/agent-runtime.5.txt +1 -1
- package/llms/agent-runtime.txt +14 -0
- package/llms/application.2.txt +6 -3
- package/llms/application.3.txt +2 -1
- package/llms/application.txt +4 -1
- package/llms-full.txt +27 -6
- package/llms.txt +2 -2
- package/package.json +1 -1
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentToolModelOutputSchema2,
|
|
3
|
+
AgentRecordedToolModelOutputSchema,
|
|
3
4
|
normalizeAgentInstructions,
|
|
4
5
|
AgentModelMessageSchema2,
|
|
5
6
|
createAgentGeneratedFile
|
|
6
|
-
} from "./index-
|
|
7
|
+
} from "./index-jy907kcs.js";
|
|
7
8
|
import {
|
|
8
9
|
AgentMessagePartSchema2
|
|
9
|
-
} from "./index-
|
|
10
|
+
} from "./index-ks4rhtcc.js";
|
|
10
11
|
import {
|
|
11
12
|
AgentRecordIdSchema2,
|
|
12
13
|
AgentMessageSchema2,
|
|
13
14
|
AgentAssistantPlaceholderSchema2,
|
|
14
15
|
AgentProvenanceSchema2,
|
|
15
16
|
AgentUsageSchema2
|
|
16
|
-
} from "./index-
|
|
17
|
+
} from "./index-yv7d6tav.js";
|
|
17
18
|
import {
|
|
18
19
|
AgentProviderResponseSchema2
|
|
19
|
-
} from "./index-
|
|
20
|
+
} from "./index-px9r6wv1.js";
|
|
20
21
|
import {
|
|
21
22
|
AgentRunOperationSchema2,
|
|
22
23
|
runStateForTerminalReason2,
|
|
23
24
|
AgentRunSchema2,
|
|
24
25
|
AgentSnapshotSchema2
|
|
25
|
-
} from "./index-
|
|
26
|
+
} from "./index-gvv7y0s4.js";
|
|
26
27
|
import {
|
|
27
28
|
InvocationPayloadSchema,
|
|
28
29
|
InvocationExpiredPayloadSchema,
|
|
@@ -41,11 +42,21 @@ import {
|
|
|
41
42
|
canonicalAgentJson2,
|
|
42
43
|
issueRunContext,
|
|
43
44
|
isActiveRunState
|
|
44
|
-
} from "./index-
|
|
45
|
+
} from "./index-kaq9nb7h.js";
|
|
45
46
|
import {
|
|
46
47
|
ToolExecutionControlError2,
|
|
47
48
|
isToolExecutionControlError2
|
|
48
49
|
} from "./index-b9mj31q7.js";
|
|
50
|
+
import {
|
|
51
|
+
AGENT_TOOL_PROGRESS_MESSAGE_MAX2,
|
|
52
|
+
agentDurableEventId2
|
|
53
|
+
} from "./index-4q9tmzea.js";
|
|
54
|
+
import {
|
|
55
|
+
contractOperationEffects2
|
|
56
|
+
} from "./index-werjqesf.js";
|
|
57
|
+
import {
|
|
58
|
+
createLocalStepDurability2
|
|
59
|
+
} from "./index-xrsryvd2.js";
|
|
49
60
|
import {
|
|
50
61
|
withStoreRetries,
|
|
51
62
|
AgentRuntimeConflictError2,
|
|
@@ -55,23 +66,17 @@ import {
|
|
|
55
66
|
terminalOfRunView,
|
|
56
67
|
commitAgentRunTerminal,
|
|
57
68
|
findRun,
|
|
58
|
-
jsonValue,
|
|
59
69
|
providerResponseIdentity,
|
|
60
70
|
abortTerminalReason,
|
|
61
71
|
addUsage,
|
|
62
72
|
mergeModelTotals,
|
|
63
73
|
createIdleDeadline
|
|
64
|
-
} from "./index-
|
|
65
|
-
import {
|
|
66
|
-
AGENT_TOOL_PROGRESS_MESSAGE_MAX2,
|
|
67
|
-
agentDurableEventId2
|
|
68
|
-
} from "./index-1en7k3q5.js";
|
|
74
|
+
} from "./index-xaa3603f.js";
|
|
69
75
|
import {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
} from "./index-xrsryvd2.js";
|
|
76
|
+
describeJsonRefusal,
|
|
77
|
+
projectJson,
|
|
78
|
+
recordedJson
|
|
79
|
+
} from "./index-a1rjr381.js";
|
|
75
80
|
import {
|
|
76
81
|
createToolChronology,
|
|
77
82
|
advanceToolChronology,
|
|
@@ -85,15 +90,17 @@ import {
|
|
|
85
90
|
AgentProviderStreamCutError2,
|
|
86
91
|
classifyProviderFailure2,
|
|
87
92
|
isToolResultFailure2
|
|
88
|
-
} from "./index-
|
|
93
|
+
} from "./index-knqye3gv.js";
|
|
89
94
|
import {
|
|
90
95
|
listContractToolNames2
|
|
91
96
|
} from "./index-fatke81t.js";
|
|
92
97
|
import {
|
|
93
|
-
AgentToolError2,
|
|
94
|
-
isAgentToolError2,
|
|
95
98
|
finalizeAgentToolOutput
|
|
96
|
-
} from "./index-
|
|
99
|
+
} from "./index-k5azb3v3.js";
|
|
100
|
+
import {
|
|
101
|
+
AgentToolError2,
|
|
102
|
+
isAgentToolError2
|
|
103
|
+
} from "./index-1psbyyhj.js";
|
|
97
104
|
import {
|
|
98
105
|
createMutationQueue
|
|
99
106
|
} from "./index-sykb5ag7.js";
|
|
@@ -157,6 +164,40 @@ function statedUsage(usage) {
|
|
|
157
164
|
};
|
|
158
165
|
}
|
|
159
166
|
|
|
167
|
+
// src/agent-runtime/schemas-json-projection.ts
|
|
168
|
+
function projectToolOutput(toolName, output, what = "output") {
|
|
169
|
+
const projected = projectJson(output);
|
|
170
|
+
if (projected.ok)
|
|
171
|
+
return projected.value;
|
|
172
|
+
throw new AgentToolError2({
|
|
173
|
+
message: `Tool "${toolName}" ran, but its ${what} cannot be sent as JSON: ${describeJsonRefusal(projected.refusal)}`
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function projectModelOutput(toolName, output) {
|
|
177
|
+
if (output.type !== "json" && output.type !== "error-json")
|
|
178
|
+
return output;
|
|
179
|
+
return {
|
|
180
|
+
...output,
|
|
181
|
+
value: projectToolOutput(toolName, output.value, "toModelOutput value")
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function defaultToolWireOutput(output) {
|
|
185
|
+
if (typeof output === "string")
|
|
186
|
+
return { type: "text", value: output };
|
|
187
|
+
return { type: "json", value: output };
|
|
188
|
+
}
|
|
189
|
+
function recordedModelOutput(output) {
|
|
190
|
+
const json = projectJson(output);
|
|
191
|
+
if (!json.ok)
|
|
192
|
+
return;
|
|
193
|
+
const parsed = AgentRecordedToolModelOutputSchema.safeParse(json.value);
|
|
194
|
+
return parsed.success ? parsed.data : undefined;
|
|
195
|
+
}
|
|
196
|
+
function agentToolErrorDetail(error) {
|
|
197
|
+
const detail = projectJson(error.output);
|
|
198
|
+
return detail.ok ? detail.value : { message: error.message };
|
|
199
|
+
}
|
|
200
|
+
|
|
160
201
|
// src/agent-runtime/history/run-history-parts.ts
|
|
161
202
|
var INTERRUPTION_NOTE = "[interrupted: this turn was cut off before it finished]";
|
|
162
203
|
var FAILURE_NOTE = "[failed: partial evidence from a run that did not complete successfully]";
|
|
@@ -216,20 +257,24 @@ async function projectToolResultOutput(part, callInput, options) {
|
|
|
216
257
|
output: part.output,
|
|
217
258
|
outcome: part.outcome
|
|
218
259
|
});
|
|
219
|
-
if (resolved !== undefined)
|
|
220
|
-
return AgentToolModelOutputSchema2.parse(resolved);
|
|
260
|
+
if (resolved !== undefined) {
|
|
261
|
+
return AgentToolModelOutputSchema2.parse(projectModelOutput(part.toolName, resolved));
|
|
262
|
+
}
|
|
221
263
|
}
|
|
264
|
+
if (part.outcome === "success" && part.modelOutput)
|
|
265
|
+
return part.modelOutput;
|
|
222
266
|
if (part.outcome === "success" && options.tools && Object.hasOwn(options.tools, part.toolName)) {
|
|
223
267
|
const tool = options.tools[part.toolName];
|
|
224
268
|
if (tool?.toModelOutput) {
|
|
225
|
-
|
|
269
|
+
const output = await tool.toModelOutput({
|
|
226
270
|
toolCallId: part.callId,
|
|
227
271
|
input: callInput,
|
|
228
272
|
output: part.output
|
|
229
|
-
})
|
|
273
|
+
});
|
|
274
|
+
return AgentToolModelOutputSchema2.parse(projectModelOutput(part.toolName, output));
|
|
230
275
|
}
|
|
231
276
|
}
|
|
232
|
-
return part.outcome === "success" ?
|
|
277
|
+
return part.outcome === "success" ? defaultToolWireOutput(part.output ?? null) : { type: "error-json", value: part.output ?? { message: part.outcome } };
|
|
233
278
|
}
|
|
234
279
|
async function projectAssistantMessages(message, marker, options, callInputsById) {
|
|
235
280
|
const rendered = new Set;
|
|
@@ -1064,7 +1109,7 @@ function streamEvidence(limit) {
|
|
|
1064
1109
|
// src/agent-runtime/loop/invocations.ts
|
|
1065
1110
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
1066
1111
|
import { hostname } from "node:os";
|
|
1067
|
-
import { z as
|
|
1112
|
+
import { z as z3 } from "zod";
|
|
1068
1113
|
|
|
1069
1114
|
// src/agent-runtime/loop/invocation-read.ts
|
|
1070
1115
|
import { z as z2 } from "zod";
|
|
@@ -1185,7 +1230,6 @@ async function* ownedProviderStream(input) {
|
|
|
1185
1230
|
}
|
|
1186
1231
|
|
|
1187
1232
|
// src/agent-runtime/loop/provider-stream-segments.ts
|
|
1188
|
-
import { z as z3 } from "zod";
|
|
1189
1233
|
var MAX_CHUNK_TIMESTAMPS = 32768;
|
|
1190
1234
|
function parseProviderToolInput(raw) {
|
|
1191
1235
|
const trimmed = raw.trim();
|
|
@@ -1197,10 +1241,6 @@ function parseProviderToolInput(raw) {
|
|
|
1197
1241
|
return raw;
|
|
1198
1242
|
}
|
|
1199
1243
|
}
|
|
1200
|
-
function safeJsonValue(value) {
|
|
1201
|
-
const parsed = z3.json().safeParse(value);
|
|
1202
|
-
return parsed.success ? parsed.data : { message: "Non-JSON tool output omitted" };
|
|
1203
|
-
}
|
|
1204
1244
|
function toProviderToolError(result) {
|
|
1205
1245
|
if (isAgentToolError2(result))
|
|
1206
1246
|
return result;
|
|
@@ -1335,7 +1375,7 @@ async function handleProviderToolResult(result, part, emit) {
|
|
|
1335
1375
|
type: "tool-result",
|
|
1336
1376
|
toolCallId: part.toolCallId,
|
|
1337
1377
|
toolName: part.toolName,
|
|
1338
|
-
output: { type: "error-json", value:
|
|
1378
|
+
output: { type: "error-json", value: agentToolErrorDetail(providerError) },
|
|
1339
1379
|
...providerOptions && { providerOptions }
|
|
1340
1380
|
},
|
|
1341
1381
|
stepPart: {
|
|
@@ -1348,12 +1388,14 @@ async function handleProviderToolResult(result, part, emit) {
|
|
|
1348
1388
|
});
|
|
1349
1389
|
return;
|
|
1350
1390
|
}
|
|
1391
|
+
const recorded = recordedJson(part.result);
|
|
1351
1392
|
await emit({
|
|
1352
1393
|
type: "tool-result",
|
|
1353
1394
|
toolCallId: part.toolCallId,
|
|
1354
1395
|
toolName: part.toolName,
|
|
1355
1396
|
input: matchingInput,
|
|
1356
1397
|
output: part.result,
|
|
1398
|
+
recorded,
|
|
1357
1399
|
...part.preliminary !== undefined && { preliminary: part.preliminary },
|
|
1358
1400
|
...part.provider && { provider: part.provider }
|
|
1359
1401
|
});
|
|
@@ -1374,7 +1416,7 @@ async function handleProviderToolResult(result, part, emit) {
|
|
|
1374
1416
|
type: "tool-result",
|
|
1375
1417
|
toolCallId: part.toolCallId,
|
|
1376
1418
|
toolName: part.toolName,
|
|
1377
|
-
output: { type: "json", value:
|
|
1419
|
+
output: { type: "json", value: recorded },
|
|
1378
1420
|
...providerOptions && { providerOptions }
|
|
1379
1421
|
},
|
|
1380
1422
|
stepPart: stepResult
|
|
@@ -1835,7 +1877,7 @@ function createModelInvocationLedger2(config) {
|
|
|
1835
1877
|
const appendOnce = store.appendEventOnce?.bind(store);
|
|
1836
1878
|
if (!appendOnce)
|
|
1837
1879
|
throw new TypeError("Model invocations require atomic store.appendEventOnce");
|
|
1838
|
-
const maxPayloadBytes =
|
|
1880
|
+
const maxPayloadBytes = z3.int().min(1024).max(64 * 1024 * 1024).parse(config.maxPayloadBytes ?? 4 * 1024 * 1024);
|
|
1839
1881
|
const payloads = createInvocationPayloads(store, config.payloadKey, maxPayloadBytes);
|
|
1840
1882
|
const authorize = async (input) => InvocationCallerSchema.parse(await config.authorize(input));
|
|
1841
1883
|
const start = async (input) => {
|
|
@@ -1983,8 +2025,8 @@ function createAgentToolFenceLifecycle2(config) {
|
|
|
1983
2025
|
}
|
|
1984
2026
|
|
|
1985
2027
|
// src/agent-runtime/providers/models-driver-telemetry.ts
|
|
1986
|
-
import { z as
|
|
1987
|
-
var AgentModelFinishReasonSchema =
|
|
2028
|
+
import { z as z4 } from "zod";
|
|
2029
|
+
var AgentModelFinishReasonSchema = z4.enum([
|
|
1988
2030
|
"stop",
|
|
1989
2031
|
"length",
|
|
1990
2032
|
"tool-calls",
|
|
@@ -1993,29 +2035,29 @@ var AgentModelFinishReasonSchema = z5.enum([
|
|
|
1993
2035
|
"interrupted",
|
|
1994
2036
|
"other"
|
|
1995
2037
|
]);
|
|
1996
|
-
var AgentModelCostDetailsSchema =
|
|
1997
|
-
promptCostUsd:
|
|
1998
|
-
outputCostUsd:
|
|
1999
|
-
isByok:
|
|
2038
|
+
var AgentModelCostDetailsSchema = z4.strictObject({
|
|
2039
|
+
promptCostUsd: z4.number().nonnegative().optional(),
|
|
2040
|
+
outputCostUsd: z4.number().nonnegative().optional(),
|
|
2041
|
+
isByok: z4.boolean().optional()
|
|
2000
2042
|
});
|
|
2001
|
-
var AgentStepChunkIntervalsSchema =
|
|
2002
|
-
min:
|
|
2003
|
-
p10:
|
|
2004
|
-
median:
|
|
2005
|
-
avg:
|
|
2006
|
-
p90:
|
|
2007
|
-
max:
|
|
2043
|
+
var AgentStepChunkIntervalsSchema = z4.strictObject({
|
|
2044
|
+
min: z4.number().nonnegative(),
|
|
2045
|
+
p10: z4.number().nonnegative(),
|
|
2046
|
+
median: z4.number().nonnegative(),
|
|
2047
|
+
avg: z4.number().nonnegative(),
|
|
2048
|
+
p90: z4.number().nonnegative(),
|
|
2049
|
+
max: z4.number().nonnegative()
|
|
2008
2050
|
});
|
|
2009
|
-
var AgentStepTimingsSchema =
|
|
2010
|
-
stepTimeMs:
|
|
2011
|
-
responseTimeMs:
|
|
2012
|
-
toolExecutionMs:
|
|
2013
|
-
ttftMs:
|
|
2051
|
+
var AgentStepTimingsSchema = z4.strictObject({
|
|
2052
|
+
stepTimeMs: z4.number().nonnegative(),
|
|
2053
|
+
responseTimeMs: z4.number().nonnegative(),
|
|
2054
|
+
toolExecutionMs: z4.number().nonnegative(),
|
|
2055
|
+
ttftMs: z4.number().nonnegative().optional(),
|
|
2014
2056
|
chunkIntervalsMs: AgentStepChunkIntervalsSchema.optional()
|
|
2015
2057
|
});
|
|
2016
2058
|
|
|
2017
2059
|
// src/agent-runtime/loop/run-step-spend.ts
|
|
2018
|
-
import { z as
|
|
2060
|
+
import { z as z5 } from "zod";
|
|
2019
2061
|
|
|
2020
2062
|
// src/agent-runtime/loop/run-execution-state.ts
|
|
2021
2063
|
function adoptSnapshot(state, next) {
|
|
@@ -2152,34 +2194,34 @@ function checkpoint(execution, toolStatus) {
|
|
|
2152
2194
|
|
|
2153
2195
|
// src/agent-runtime/loop/run-step-spend.ts
|
|
2154
2196
|
var DEFAULT_STEP_SPEND_TIMEOUT_MS = 5000;
|
|
2155
|
-
var AgentStepSpendPhaseSchema2 =
|
|
2156
|
-
var AgentStepSpendProviderSchema =
|
|
2157
|
-
key:
|
|
2158
|
-
upstream:
|
|
2197
|
+
var AgentStepSpendPhaseSchema2 = z5.enum(["step", "abandoned-attempt", "compaction"]);
|
|
2198
|
+
var AgentStepSpendProviderSchema = z5.strictObject({
|
|
2199
|
+
key: z5.string().min(1),
|
|
2200
|
+
upstream: z5.string().min(1).optional()
|
|
2159
2201
|
});
|
|
2160
2202
|
var StepSpendBaseShape = {
|
|
2161
2203
|
conversationId: AgentRecordIdSchema2,
|
|
2162
2204
|
runId: AgentRecordIdSchema2,
|
|
2163
|
-
step:
|
|
2164
|
-
attempt:
|
|
2205
|
+
step: z5.int().nonnegative(),
|
|
2206
|
+
attempt: z5.int().nonnegative(),
|
|
2165
2207
|
usage: AgentUsageSchema2,
|
|
2166
2208
|
trace: ModelInvocationTraceSchema2.optional()
|
|
2167
2209
|
};
|
|
2168
2210
|
var ModelStepSpendShape = {
|
|
2169
2211
|
...StepSpendBaseShape,
|
|
2170
|
-
model:
|
|
2212
|
+
model: z5.string().min(1),
|
|
2171
2213
|
provider: AgentStepSpendProviderSchema,
|
|
2172
2214
|
response: AgentProviderResponseSchema2,
|
|
2173
2215
|
finishReason: AgentModelFinishReasonSchema.optional(),
|
|
2174
|
-
rawFinishReason:
|
|
2175
|
-
toolCallCount:
|
|
2216
|
+
rawFinishReason: z5.string().min(1).optional(),
|
|
2217
|
+
toolCallCount: z5.int().nonnegative().optional(),
|
|
2176
2218
|
costDetails: AgentModelCostDetailsSchema.optional(),
|
|
2177
2219
|
timings: AgentStepTimingsSchema.optional()
|
|
2178
2220
|
};
|
|
2179
|
-
var AgentStepSpendSchema2 =
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2221
|
+
var AgentStepSpendSchema2 = z5.discriminatedUnion("phase", [
|
|
2222
|
+
z5.strictObject({ ...ModelStepSpendShape, phase: z5.literal("step") }),
|
|
2223
|
+
z5.strictObject({ ...ModelStepSpendShape, phase: z5.literal("abandoned-attempt") }),
|
|
2224
|
+
z5.strictObject({ ...StepSpendBaseShape, phase: z5.literal("compaction") })
|
|
2183
2225
|
]);
|
|
2184
2226
|
async function callStepSpendHook(name, timeoutMs, call) {
|
|
2185
2227
|
let pending;
|
|
@@ -2367,14 +2409,7 @@ function assertToolApprovalSecret(secret) {
|
|
|
2367
2409
|
throw new TypeError("loop.toolApprovalSecret must be a non-empty string or Uint8Array");
|
|
2368
2410
|
}
|
|
2369
2411
|
function normalizePersistedToolInput(value) {
|
|
2370
|
-
|
|
2371
|
-
return null;
|
|
2372
|
-
try {
|
|
2373
|
-
const serialized = JSON.stringify(value);
|
|
2374
|
-
if (serialized !== undefined)
|
|
2375
|
-
return jsonValue(JSON.parse(serialized));
|
|
2376
|
-
} catch {}
|
|
2377
|
-
return jsonValue(value);
|
|
2412
|
+
return recordedJson(value);
|
|
2378
2413
|
}
|
|
2379
2414
|
function bytesToBase64Url(bytes) {
|
|
2380
2415
|
let binary = "";
|
|
@@ -3303,7 +3338,7 @@ async function applyRecordedPart(execution, part) {
|
|
|
3303
3338
|
envelope: {
|
|
3304
3339
|
schemaVersion: 1,
|
|
3305
3340
|
provider: "raw",
|
|
3306
|
-
data: { value:
|
|
3341
|
+
data: { value: recordedJson(part.rawValue) }
|
|
3307
3342
|
}
|
|
3308
3343
|
}));
|
|
3309
3344
|
}
|
|
@@ -3695,19 +3730,21 @@ async function applyToolPart(execution, part) {
|
|
|
3695
3730
|
input: part.input,
|
|
3696
3731
|
output: part.output
|
|
3697
3732
|
});
|
|
3733
|
+
const output = part.recorded ?? recordedJson(part.output);
|
|
3698
3734
|
state.parts.push(AgentMessagePartSchema2.parse({
|
|
3699
3735
|
type: "tool-result",
|
|
3700
3736
|
callId: part.toolCallId,
|
|
3701
3737
|
toolName: part.toolName,
|
|
3702
3738
|
outcome: "success",
|
|
3703
|
-
output
|
|
3739
|
+
output,
|
|
3740
|
+
...part.modelOutput && { modelOutput: part.modelOutput },
|
|
3704
3741
|
...part.provider && { provider: part.provider }
|
|
3705
3742
|
}));
|
|
3706
3743
|
await checkpoint(execution, {
|
|
3707
3744
|
callId: part.toolCallId,
|
|
3708
3745
|
toolName: part.toolName,
|
|
3709
3746
|
status: "completed",
|
|
3710
|
-
output
|
|
3747
|
+
output
|
|
3711
3748
|
});
|
|
3712
3749
|
} else if (part.type === "tool-error") {
|
|
3713
3750
|
state.settledToolCalls.add(part.toolCallId);
|
|
@@ -3721,7 +3758,7 @@ async function applyToolPart(execution, part) {
|
|
|
3721
3758
|
throw part.error;
|
|
3722
3759
|
}
|
|
3723
3760
|
state.stepGuard.toolFailed = true;
|
|
3724
|
-
const output = isAgentToolError2(part.error) ?
|
|
3761
|
+
const output = isAgentToolError2(part.error) ? agentToolErrorDetail(part.error) : { message: safeToolErrorMessage(part.error) };
|
|
3725
3762
|
state.parts.push(AgentMessagePartSchema2.parse({
|
|
3726
3763
|
type: "tool-result",
|
|
3727
3764
|
callId: part.toolCallId,
|
|
@@ -3963,11 +4000,6 @@ function createCallSlotResult() {
|
|
|
3963
4000
|
toolResults: []
|
|
3964
4001
|
};
|
|
3965
4002
|
}
|
|
3966
|
-
function defaultToolWireOutput(output) {
|
|
3967
|
-
if (typeof output === "string")
|
|
3968
|
-
return { type: "text", value: output };
|
|
3969
|
-
return { type: "json", value: jsonValue(output ?? null) };
|
|
3970
|
-
}
|
|
3971
4003
|
function buildToolDurability(execution, toolName, toolCallId, signal) {
|
|
3972
4004
|
const { config } = execution.dependencies;
|
|
3973
4005
|
if (!config.durability)
|
|
@@ -4014,12 +4046,14 @@ function resolveSingleToolHooks(input) {
|
|
|
4014
4046
|
output: chunk,
|
|
4015
4047
|
preliminary: true
|
|
4016
4048
|
}),
|
|
4017
|
-
onResult: (output) => emit({
|
|
4049
|
+
onResult: ({ output, recorded, modelOutput }) => emit({
|
|
4018
4050
|
type: "tool-result",
|
|
4019
4051
|
toolCallId,
|
|
4020
4052
|
toolName,
|
|
4021
4053
|
input: parsedInput,
|
|
4022
4054
|
output,
|
|
4055
|
+
recorded,
|
|
4056
|
+
...modelOutput && { modelOutput },
|
|
4023
4057
|
preliminary: false
|
|
4024
4058
|
}),
|
|
4025
4059
|
onError: (error) => emit({
|
|
@@ -4073,10 +4107,18 @@ async function runSingleToolExecution(input) {
|
|
|
4073
4107
|
finalValue = last;
|
|
4074
4108
|
}
|
|
4075
4109
|
finalValue = finalizeAgentToolOutput(tool, finalValue, wasAsyncIterable);
|
|
4076
|
-
const
|
|
4110
|
+
const recorded = projectToolOutput(toolName, finalValue);
|
|
4111
|
+
const wireOutput = tool.toModelOutput ? projectModelOutput(toolName, await tool.toModelOutput({ toolCallId, input: parsedInput, output: finalValue })) : defaultToolWireOutput(recorded);
|
|
4077
4112
|
signal.throwIfAborted();
|
|
4078
4113
|
succeeded = !isToolResultFailure2(finalValue);
|
|
4079
|
-
|
|
4114
|
+
const modelOutput = tool.toModelOutput ? recordedModelOutput(wireOutput) : undefined;
|
|
4115
|
+
outcome = {
|
|
4116
|
+
ok: true,
|
|
4117
|
+
output: finalValue,
|
|
4118
|
+
recorded,
|
|
4119
|
+
...modelOutput && { modelOutput },
|
|
4120
|
+
wireOutput
|
|
4121
|
+
};
|
|
4080
4122
|
} catch (error) {
|
|
4081
4123
|
if (emitFailed || signal.aborted || isToolExecutionControlError2(error) || hooks.isFatalError?.(error) === true) {
|
|
4082
4124
|
if (!emitFailed && isToolExecutionControlError2(error)) {
|
|
@@ -4094,7 +4136,7 @@ async function runSingleToolExecution(input) {
|
|
|
4094
4136
|
}
|
|
4095
4137
|
signal.throwIfAborted();
|
|
4096
4138
|
if (outcome.ok) {
|
|
4097
|
-
await hooks.onResult(outcome
|
|
4139
|
+
await hooks.onResult(outcome);
|
|
4098
4140
|
} else {
|
|
4099
4141
|
await hooks.onError(outcome.error);
|
|
4100
4142
|
}
|
|
@@ -4232,7 +4274,7 @@ function createStandaloneToolHooks(sink, toolCallId, toolName, parsedInput) {
|
|
|
4232
4274
|
output: chunk,
|
|
4233
4275
|
preliminary: true
|
|
4234
4276
|
}),
|
|
4235
|
-
onResult: (output) => sink.onToolResult({
|
|
4277
|
+
onResult: ({ output }) => sink.onToolResult({
|
|
4236
4278
|
toolCallId,
|
|
4237
4279
|
toolName,
|
|
4238
4280
|
input: parsedInput,
|
|
@@ -6707,7 +6749,7 @@ async function commitRunTerminal(execution) {
|
|
|
6707
6749
|
import { createHash as createHash4 } from "node:crypto";
|
|
6708
6750
|
|
|
6709
6751
|
// src/agent-runtime/loop/state-slots.ts
|
|
6710
|
-
import { z as
|
|
6752
|
+
import { z as z6 } from "zod";
|
|
6711
6753
|
function defineStateSlot2(input) {
|
|
6712
6754
|
if (input.name.length === 0)
|
|
6713
6755
|
throw new TypeError("State slot name must not be empty");
|
|
@@ -6722,11 +6764,11 @@ function defineStateSlot2(input) {
|
|
|
6722
6764
|
...input.description && { description: input.description }
|
|
6723
6765
|
};
|
|
6724
6766
|
}
|
|
6725
|
-
var StateSetPayloadSchema =
|
|
6726
|
-
name:
|
|
6727
|
-
version:
|
|
6728
|
-
value:
|
|
6729
|
-
actor:
|
|
6767
|
+
var StateSetPayloadSchema = z6.object({
|
|
6768
|
+
name: z6.string().min(1),
|
|
6769
|
+
version: z6.int().positive(),
|
|
6770
|
+
value: z6.json(),
|
|
6771
|
+
actor: z6.enum(["agent", "human", "system"])
|
|
6730
6772
|
}).strict();
|
|
6731
6773
|
function slotRegistry(definitions) {
|
|
6732
6774
|
const result = new Map;
|
|
@@ -6808,18 +6850,18 @@ function renderAgentStateSlots2(values) {
|
|
|
6808
6850
|
var agentGoalStateSlot2 = defineStateSlot2({
|
|
6809
6851
|
name: "goal",
|
|
6810
6852
|
description: "The durable objective and lifecycle of this conversation.",
|
|
6811
|
-
schema:
|
|
6812
|
-
objective:
|
|
6813
|
-
status:
|
|
6853
|
+
schema: z6.object({
|
|
6854
|
+
objective: z6.string().min(1),
|
|
6855
|
+
status: z6.enum(["active", "complete", "blocked"])
|
|
6814
6856
|
}).strict()
|
|
6815
6857
|
});
|
|
6816
6858
|
var agentTodoStateSlot2 = defineStateSlot2({
|
|
6817
6859
|
name: "todo",
|
|
6818
6860
|
description: "The durable ordered work plan for this conversation.",
|
|
6819
|
-
schema:
|
|
6820
|
-
items:
|
|
6821
|
-
step:
|
|
6822
|
-
status:
|
|
6861
|
+
schema: z6.object({
|
|
6862
|
+
items: z6.array(z6.object({
|
|
6863
|
+
step: z6.string().min(1),
|
|
6864
|
+
status: z6.enum(["pending", "in_progress", "completed"])
|
|
6823
6865
|
}).strict())
|
|
6824
6866
|
}).strict()
|
|
6825
6867
|
});
|
|
@@ -7625,9 +7667,9 @@ function createAgentRuntime2(config) {
|
|
|
7625
7667
|
}
|
|
7626
7668
|
|
|
7627
7669
|
// src/agent-runtime/prompt.ts
|
|
7628
|
-
import { z as
|
|
7629
|
-
var AgentTokenCountSchema2 =
|
|
7630
|
-
value:
|
|
7670
|
+
import { z as z7 } from "zod";
|
|
7671
|
+
var AgentTokenCountSchema2 = z7.object({
|
|
7672
|
+
value: z7.int().nonnegative().optional(),
|
|
7631
7673
|
provenance: AgentProvenanceSchema2.extract([
|
|
7632
7674
|
"measured",
|
|
7633
7675
|
"computed",
|
|
@@ -7747,7 +7789,7 @@ function knownValue(value) {
|
|
|
7747
7789
|
}
|
|
7748
7790
|
function composeAgentPrompt2(sections) {
|
|
7749
7791
|
return async (options) => {
|
|
7750
|
-
const event =
|
|
7792
|
+
const event = z7.enum(["session.started", "turn.started"]).parse(options.event ?? "turn.started");
|
|
7751
7793
|
const rendered = [];
|
|
7752
7794
|
let systemTotal = 0;
|
|
7753
7795
|
let userTotal = 0;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// src/internal/json-stringify.ts
|
|
2
|
+
class Refused extends Error {
|
|
3
|
+
refusal;
|
|
4
|
+
constructor(refusal) {
|
|
5
|
+
super(refusal.reason);
|
|
6
|
+
this.refusal = refusal;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
var REFUSAL_TEXT = {
|
|
10
|
+
bigint: "a BigInt",
|
|
11
|
+
cycle: "a cycle",
|
|
12
|
+
threw: "a value whose serialization threw"
|
|
13
|
+
};
|
|
14
|
+
function describeJsonRefusal(refusal) {
|
|
15
|
+
const path = refusal.path.length > MAX_PATH_TEXT ? `${refusal.path.slice(0, MAX_PATH_TEXT)}…` : refusal.path;
|
|
16
|
+
const where = path.length > 0 ? path : "the root";
|
|
17
|
+
return `${REFUSAL_TEXT[refusal.reason]} at ${where}`;
|
|
18
|
+
}
|
|
19
|
+
var MAX_PATH_TEXT = 200;
|
|
20
|
+
function joinPath(path, key) {
|
|
21
|
+
return path.length > 0 ? `${path}.${key}` : key;
|
|
22
|
+
}
|
|
23
|
+
function resolveForJson(value, key) {
|
|
24
|
+
let resolved = value;
|
|
25
|
+
if (typeof resolved === "object" && resolved !== null || typeof resolved === "bigint") {
|
|
26
|
+
const toJSON = Reflect.get(Object(resolved), "toJSON");
|
|
27
|
+
if (typeof toJSON === "function")
|
|
28
|
+
resolved = toJSON.call(resolved, key);
|
|
29
|
+
}
|
|
30
|
+
if (resolved instanceof Number)
|
|
31
|
+
return Number(resolved);
|
|
32
|
+
if (resolved instanceof String)
|
|
33
|
+
return String(resolved);
|
|
34
|
+
if (resolved instanceof Boolean)
|
|
35
|
+
return Boolean.prototype.valueOf.call(resolved);
|
|
36
|
+
if (resolved instanceof BigInt)
|
|
37
|
+
return BigInt.prototype.valueOf.call(resolved);
|
|
38
|
+
return resolved;
|
|
39
|
+
}
|
|
40
|
+
function projectJson(value) {
|
|
41
|
+
const ancestors = new Set;
|
|
42
|
+
const visit = (raw, key, path) => {
|
|
43
|
+
let item;
|
|
44
|
+
try {
|
|
45
|
+
item = resolveForJson(raw, key);
|
|
46
|
+
} catch {
|
|
47
|
+
throw new Refused({ reason: "threw", path });
|
|
48
|
+
}
|
|
49
|
+
if (item === null || typeof item === "string" || typeof item === "boolean")
|
|
50
|
+
return item;
|
|
51
|
+
if (typeof item === "number")
|
|
52
|
+
return Number.isFinite(item) ? item + 0 : null;
|
|
53
|
+
if (typeof item === "bigint")
|
|
54
|
+
throw new Refused({ reason: "bigint", path });
|
|
55
|
+
if (typeof item !== "object")
|
|
56
|
+
return;
|
|
57
|
+
if (ancestors.has(item))
|
|
58
|
+
throw new Refused({ reason: "cycle", path });
|
|
59
|
+
ancestors.add(item);
|
|
60
|
+
try {
|
|
61
|
+
let length;
|
|
62
|
+
try {
|
|
63
|
+
length = Array.isArray(item) ? Number(Reflect.get(item, "length")) : undefined;
|
|
64
|
+
} catch {
|
|
65
|
+
throw new Refused({ reason: "threw", path });
|
|
66
|
+
}
|
|
67
|
+
if (length !== undefined) {
|
|
68
|
+
const out = [];
|
|
69
|
+
for (let index = 0;index < length; index += 1) {
|
|
70
|
+
const entry = readProperty(item, String(index), path);
|
|
71
|
+
out.push(visit(entry, String(index), joinPath(path, String(index))) ?? null);
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
const out = {};
|
|
76
|
+
let names;
|
|
77
|
+
try {
|
|
78
|
+
names = Object.keys(item);
|
|
79
|
+
} catch {
|
|
80
|
+
throw new Refused({ reason: "threw", path });
|
|
81
|
+
}
|
|
82
|
+
for (const name of names) {
|
|
83
|
+
const entry = visit(readProperty(item, name, path), name, joinPath(path, name));
|
|
84
|
+
if (name === "__proto__")
|
|
85
|
+
continue;
|
|
86
|
+
if (entry !== undefined)
|
|
87
|
+
out[name] = entry;
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
} finally {
|
|
91
|
+
ancestors.delete(item);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
try {
|
|
95
|
+
return { ok: true, value: visit(value, "", "") ?? null };
|
|
96
|
+
} catch (error) {
|
|
97
|
+
if (error instanceof Refused)
|
|
98
|
+
return { ok: false, refusal: error.refusal };
|
|
99
|
+
return { ok: false, refusal: { reason: "threw", path: "" } };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function readProperty(holder, key, path) {
|
|
103
|
+
try {
|
|
104
|
+
return Reflect.get(holder, key);
|
|
105
|
+
} catch {
|
|
106
|
+
throw new Refused({ reason: "threw", path: joinPath(path, key) });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function recordedJson(value) {
|
|
110
|
+
const projected = projectJson(value);
|
|
111
|
+
return projected.ok ? projected.value : { unrecordable: describeJsonRefusal(projected.refusal) };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { describeJsonRefusal, projectJson, recordedJson };
|