zidane 5.13.26 → 5.14.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/dist/{acp-CjAoILwj.js → acp-24uU2WDs.js} +7 -7
- package/dist/{acp-CjAoILwj.js.map → acp-24uU2WDs.js.map} +1 -1
- package/dist/acp-cli.js +12 -7
- package/dist/acp-cli.js.map +1 -1
- package/dist/acp.d.ts +3 -3
- package/dist/acp.js +1 -1
- package/dist/{tools-B32lZXLE.js → agent-Cch2ayTt.js} +8036 -9460
- package/dist/agent-Cch2ayTt.js.map +1 -0
- package/dist/{agent-DQIL5BFk.d.ts → agent-EFWt6uQ_.d.ts} +368 -209
- package/dist/agent-EFWt6uQ_.d.ts.map +1 -0
- package/dist/agent.d.ts +3 -0
- package/dist/agent.js +5 -0
- package/dist/anthropic-RGqsJlC8.js +807 -0
- package/dist/anthropic-RGqsJlC8.js.map +1 -0
- package/dist/{atomic-write-Bgtr5JPu.js → atomic-write-B7zr1ddF.js} +2 -2
- package/dist/{atomic-write-Bgtr5JPu.js.map → atomic-write-B7zr1ddF.js.map} +1 -1
- package/dist/{auth-DPrSP1YV.js → auth-C-ms5N2x.js} +33 -5
- package/dist/{auth-DPrSP1YV.js.map → auth-C-ms5N2x.js.map} +1 -1
- package/dist/cache-telemetry-BKAwsNxm.js +169 -0
- package/dist/cache-telemetry-BKAwsNxm.js.map +1 -0
- package/dist/chat/pure.d.ts +3 -3
- package/dist/chat/pure.js +1 -1
- package/dist/chat.d.ts +22 -8
- package/dist/chat.d.ts.map +1 -1
- package/dist/chat.js +30 -5
- package/dist/chat.js.map +1 -1
- package/dist/contexts/daytona.d.ts +3 -3
- package/dist/contexts/docker.d.ts +1 -1
- package/dist/contexts/docker.js +0 -1
- package/dist/contexts/docker.js.map +1 -1
- package/dist/contexts/e2b.d.ts +2 -2
- package/dist/contexts/sandbox.d.ts +1 -1
- package/dist/{contexts-BebciJyQ.js → contexts-Lzf5huID.js} +5 -3
- package/dist/contexts-Lzf5huID.js.map +1 -0
- package/dist/contexts.d.ts +3 -3
- package/dist/contexts.js +1 -1
- package/dist/errors-CkTvg97v.d.ts +203 -0
- package/dist/errors-CkTvg97v.d.ts.map +1 -0
- package/dist/errors.d.ts +3 -0
- package/dist/errors.js +3 -0
- package/dist/eval.d.ts +1 -1
- package/dist/eval.js +3 -3
- package/dist/glob-DluQFSw1.js +270 -0
- package/dist/glob-DluQFSw1.js.map +1 -0
- package/dist/headless.d.ts +1 -1
- package/dist/headless.js +406 -1
- package/dist/headless.js.map +1 -0
- package/dist/{index-HQJDOWvo.d.ts → index-B3ciFUZx.d.ts} +2 -2
- package/dist/index-B3ciFUZx.d.ts.map +1 -0
- package/dist/{index-YY3vp2F2.d.ts → index-BtzE3Uaq.d.ts} +89 -419
- package/dist/index-BtzE3Uaq.d.ts.map +1 -0
- package/dist/{index-C5qw3pj7.d.ts → index-tSzOaWNt.d.ts} +3 -3
- package/dist/{index-C5qw3pj7.d.ts.map → index-tSzOaWNt.d.ts.map} +1 -1
- package/dist/index.d.ts +12 -8
- package/dist/index.js +114 -168
- package/dist/index.js.map +1 -1
- package/dist/{logger-C2ngE8CY.d.ts → logger-DGiGf7DW.d.ts} +2 -2
- package/dist/{logger-C2ngE8CY.d.ts.map → logger-DGiGf7DW.d.ts.map} +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/messages-YZQLKaz2.js +1157 -0
- package/dist/messages-YZQLKaz2.js.map +1 -0
- package/dist/oauth-8LqbeI_Q.js +292 -0
- package/dist/oauth-8LqbeI_Q.js.map +1 -0
- package/dist/{messages-Iy_vEycX.js → openai-compat-0Y7jcncn.js} +27 -1379
- package/dist/openai-compat-0Y7jcncn.js.map +1 -0
- package/dist/output/stream-json.d.ts +2 -2
- package/dist/output/stream-json.js +1 -1
- package/dist/output/terminal.d.ts +2 -2
- package/dist/{presets-B9nDwmaz.js → presets-BQWYMHdd.js} +3 -2
- package/dist/{presets-B9nDwmaz.js.map → presets-BQWYMHdd.js.map} +1 -1
- package/dist/presets.d.ts +2 -2
- package/dist/presets.js +1 -1
- package/dist/prompt.d.ts +2 -0
- package/dist/prompt.js +210 -0
- package/dist/prompt.js.map +1 -0
- package/dist/providers/anthropic.d.ts +2 -0
- package/dist/providers/anthropic.js +2 -0
- package/dist/providers/arcee.d.ts +2 -0
- package/dist/providers/arcee.js +42 -0
- package/dist/providers/arcee.js.map +1 -0
- package/dist/providers/baseten.d.ts +2 -0
- package/dist/providers/baseten.js +66 -0
- package/dist/providers/baseten.js.map +1 -0
- package/dist/providers/cerebras.d.ts +2 -0
- package/dist/providers/cerebras.js +31 -0
- package/dist/providers/cerebras.js.map +1 -0
- package/dist/providers/local.d.ts +2 -0
- package/dist/providers/local.js +44 -0
- package/dist/providers/local.js.map +1 -0
- package/dist/providers/openai-compat.d.ts +2 -0
- package/dist/providers/openai-compat.js +2 -0
- package/dist/providers/openai.d.ts +2 -0
- package/dist/providers/openai.js +504 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openrouter.d.ts +2 -0
- package/dist/providers/openrouter.js +52 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/providers/xai.d.ts +2 -0
- package/dist/providers/xai.js +2 -0
- package/dist/providers-DgmdYGKm.js +168 -0
- package/dist/providers-DgmdYGKm.js.map +1 -0
- package/dist/providers.d.ts +1 -1
- package/dist/providers.js +10 -2
- package/dist/restate.d.ts +2 -2
- package/dist/run-summary-DkN8KsHM.d.ts +249 -0
- package/dist/run-summary-DkN8KsHM.d.ts.map +1 -0
- package/dist/run-summary-nD3IQ4ZQ.js +253 -0
- package/dist/run-summary-nD3IQ4ZQ.js.map +1 -0
- package/dist/{sandbox-B-bMq3K6.d.ts → sandbox-Dgy-m6UF.d.ts} +2 -2
- package/dist/{sandbox-B-bMq3K6.d.ts.map → sandbox-Dgy-m6UF.d.ts.map} +1 -1
- package/dist/session/sqlite.d.ts +1 -1
- package/dist/{session-CiA1_8SB.js → session-CqrAFAKJ.js} +2 -2
- package/dist/{session-CiA1_8SB.js.map → session-CqrAFAKJ.js.map} +1 -1
- package/dist/session.d.ts +1 -1
- package/dist/session.js +2 -2
- package/dist/skills.d.ts +2 -2
- package/dist/system-prompt-BlsdjcUi.d.ts +139 -0
- package/dist/system-prompt-BlsdjcUi.d.ts.map +1 -0
- package/dist/timeout-CpFm0jJ6.d.ts +10 -0
- package/dist/timeout-CpFm0jJ6.d.ts.map +1 -0
- package/dist/timeout-kGGSXagK.js +84 -0
- package/dist/timeout-kGGSXagK.js.map +1 -0
- package/dist/{tool-formatters-w5oaoCS4.d.ts → tool-formatters-C6iLgc9f.d.ts} +2 -2
- package/dist/{tool-formatters-w5oaoCS4.d.ts.map → tool-formatters-C6iLgc9f.d.ts.map} +1 -1
- package/dist/tools/fetch-url.d.ts +1 -1
- package/dist/tools/web-search.d.ts +1 -1
- package/dist/tools-CCd8e-HT.js +1739 -0
- package/dist/tools-CCd8e-HT.js.map +1 -0
- package/dist/tools.d.ts +2 -2
- package/dist/tools.js +2 -1
- package/dist/{transcript-anchors-BJ-ESWnm.d.ts → transcript-anchors-CjKRKZVx.d.ts} +4 -4
- package/dist/{transcript-anchors-BJ-ESWnm.d.ts.map → transcript-anchors-CjKRKZVx.d.ts.map} +1 -1
- package/dist/{transcript-anchors-BUtOd-qa.js → transcript-anchors-HyCGJhsK.js} +11 -10
- package/dist/{transcript-anchors-BUtOd-qa.js.map → transcript-anchors-HyCGJhsK.js.map} +1 -1
- package/dist/tui.d.ts +3 -3
- package/dist/tui.js +40 -15
- package/dist/tui.js.map +1 -1
- package/dist/{turn-operations-BSSQHNq1.d.ts → turn-operations-Dw02ZoSQ.d.ts} +3 -3
- package/dist/{turn-operations-BSSQHNq1.d.ts.map → turn-operations-Dw02ZoSQ.d.ts.map} +1 -1
- package/dist/{turn-operations-B_XeuNp-.js → turn-operations-tG0vuBNc.js} +2 -2
- package/dist/{turn-operations-B_XeuNp-.js.map → turn-operations-tG0vuBNc.js.map} +1 -1
- package/dist/{types-Bs2oY7Ux.d.ts → types-BqdTeBaC.d.ts} +9 -1
- package/dist/types-BqdTeBaC.d.ts.map +1 -0
- package/dist/types-CyVGdbia.js.map +1 -1
- package/dist/types.d.ts +6 -5
- package/dist/xai-tPdbAGkq.js +379 -0
- package/dist/xai-tPdbAGkq.js.map +1 -0
- package/docs/ARCHITECTURE.md +6 -3
- package/docs/CHAT.md +4 -0
- package/docs/SKILL.md +33 -7
- package/package.json +63 -1
- package/dist/agent-DQIL5BFk.d.ts.map +0 -1
- package/dist/contexts-BebciJyQ.js.map +0 -1
- package/dist/glob-D56-KpBp.js +0 -118
- package/dist/glob-D56-KpBp.js.map +0 -1
- package/dist/headless-2SH7dvoW.js +0 -656
- package/dist/headless-2SH7dvoW.js.map +0 -1
- package/dist/index-HQJDOWvo.d.ts.map +0 -1
- package/dist/index-YY3vp2F2.d.ts.map +0 -1
- package/dist/messages-Iy_vEycX.js.map +0 -1
- package/dist/providers-BMw1D_lj.js +0 -2332
- package/dist/providers-BMw1D_lj.js.map +0 -1
- package/dist/tools-B32lZXLE.js.map +0 -1
- package/dist/types-Bs2oY7Ux.d.ts.map +0 -1
|
@@ -1,656 +0,0 @@
|
|
|
1
|
-
import { d as createAgent } from "./tools-B32lZXLE.js";
|
|
2
|
-
import { n as createProcessContext } from "./contexts-BebciJyQ.js";
|
|
3
|
-
import { i as documentBlockMarker, n as assertResolvedMediaBlock, s as toolResultToText } from "./types-CyVGdbia.js";
|
|
4
|
-
import { p as toAnthropic, s as ensureToolResultPairing } from "./messages-Iy_vEycX.js";
|
|
5
|
-
import { t as audioFormatFromMediaType } from "./media-sniff-Bn76JxAu.js";
|
|
6
|
-
import { i as statsByModel } from "./stats-DAKBEKjc.js";
|
|
7
|
-
import { i as basic_default } from "./presets-B9nDwmaz.js";
|
|
8
|
-
import { a as createMemoryStore, t as createSession } from "./session-CiA1_8SB.js";
|
|
9
|
-
//#region src/run-summary.ts
|
|
10
|
-
/**
|
|
11
|
-
* Build a run-summary collector. State is created fresh inside each
|
|
12
|
-
* `install()` call, so a single collector instance can be installed
|
|
13
|
-
* across multiple agents without attribution cross-talk. `latest()`
|
|
14
|
-
* returns the most-recent summary across **any** install — install
|
|
15
|
-
* per-agent collectors if you need separate post-run snapshots.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const collector = createRunSummaryCollector({
|
|
20
|
-
* onSummary: s => console.log(JSON.stringify(s)),
|
|
21
|
-
* })
|
|
22
|
-
* const uninstall = collector.install(agent.hooks)
|
|
23
|
-
* try { await agent.run({ prompt }) }
|
|
24
|
-
* finally { uninstall() }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
function createRunSummaryCollector(options = {}) {
|
|
28
|
-
let last;
|
|
29
|
-
return {
|
|
30
|
-
latest: () => last,
|
|
31
|
-
install(hooks) {
|
|
32
|
-
let runId;
|
|
33
|
-
let parentRunId;
|
|
34
|
-
let depth = 0;
|
|
35
|
-
let agentName;
|
|
36
|
-
let startedAt = Date.now();
|
|
37
|
-
let aborted = false;
|
|
38
|
-
const errors = [];
|
|
39
|
-
const blocks = [];
|
|
40
|
-
const validationRejects = [];
|
|
41
|
-
const budgetEvents = [];
|
|
42
|
-
const repeatGuardEvents = [];
|
|
43
|
-
const pairingRepairs = {};
|
|
44
|
-
const children = [];
|
|
45
|
-
function resetForNewRun() {
|
|
46
|
-
aborted = false;
|
|
47
|
-
errors.length = 0;
|
|
48
|
-
blocks.length = 0;
|
|
49
|
-
validationRejects.length = 0;
|
|
50
|
-
budgetEvents.length = 0;
|
|
51
|
-
repeatGuardEvents.length = 0;
|
|
52
|
-
for (const k of Object.keys(pairingRepairs)) delete pairingRepairs[k];
|
|
53
|
-
children.length = 0;
|
|
54
|
-
}
|
|
55
|
-
const unregisters = [];
|
|
56
|
-
unregisters.push(hooks.hook("agent:start", (ctx) => {
|
|
57
|
-
resetForNewRun();
|
|
58
|
-
runId = ctx.runId;
|
|
59
|
-
parentRunId = ctx.parentRunId;
|
|
60
|
-
depth = ctx.depth;
|
|
61
|
-
agentName = ctx.agentName;
|
|
62
|
-
startedAt = ctx.startedAt;
|
|
63
|
-
}));
|
|
64
|
-
unregisters.push(hooks.hook("agent:abort", () => {
|
|
65
|
-
aborted = true;
|
|
66
|
-
}));
|
|
67
|
-
unregisters.push(hooks.hook("stream:error", (ctx) => {
|
|
68
|
-
const msg = ctx.err instanceof Error ? ctx.err.message : String(ctx.err);
|
|
69
|
-
const errorType = ctx.err instanceof Error ? ctx.err.name : "unknown";
|
|
70
|
-
errors.push({
|
|
71
|
-
kind: "stream",
|
|
72
|
-
message: msg,
|
|
73
|
-
errorType,
|
|
74
|
-
turnId: ctx.turnId,
|
|
75
|
-
...ctx.statusCode !== void 0 ? { statusCode: ctx.statusCode } : {},
|
|
76
|
-
...ctx.requestId !== void 0 ? { requestId: ctx.requestId } : {}
|
|
77
|
-
});
|
|
78
|
-
}));
|
|
79
|
-
unregisters.push(hooks.hook("tool:error", (ctx) => {
|
|
80
|
-
errors.push({
|
|
81
|
-
kind: "tool",
|
|
82
|
-
message: ctx.error.message,
|
|
83
|
-
errorType: ctx.error.name,
|
|
84
|
-
turnId: ctx.turnId,
|
|
85
|
-
callId: ctx.callId,
|
|
86
|
-
toolName: ctx.name
|
|
87
|
-
});
|
|
88
|
-
}));
|
|
89
|
-
unregisters.push(hooks.hook("mcp:tool:error", (ctx) => {
|
|
90
|
-
errors.push({
|
|
91
|
-
kind: "mcp-tool",
|
|
92
|
-
message: ctx.error.message,
|
|
93
|
-
errorType: ctx.error.name,
|
|
94
|
-
turnId: ctx.turnId,
|
|
95
|
-
callId: ctx.callId,
|
|
96
|
-
server: ctx.server,
|
|
97
|
-
toolName: ctx.displayName
|
|
98
|
-
});
|
|
99
|
-
}));
|
|
100
|
-
unregisters.push(hooks.hook("mcp:error", (ctx) => {
|
|
101
|
-
errors.push({
|
|
102
|
-
kind: "mcp",
|
|
103
|
-
message: ctx.error.message,
|
|
104
|
-
errorType: ctx.error.name,
|
|
105
|
-
server: ctx.name
|
|
106
|
-
});
|
|
107
|
-
}));
|
|
108
|
-
unregisters.push(hooks.hook("spawn:error", (ctx) => {
|
|
109
|
-
errors.push({
|
|
110
|
-
kind: "spawn",
|
|
111
|
-
message: ctx.error.message,
|
|
112
|
-
errorType: ctx.error.name,
|
|
113
|
-
childId: ctx.id
|
|
114
|
-
});
|
|
115
|
-
}));
|
|
116
|
-
unregisters.push(hooks.hook("tool:dispatched", (ctx) => {
|
|
117
|
-
if (ctx.outcome === "gate-block" || ctx.outcome === "unknown" || ctx.outcome === "invalid-input") blocks.push({
|
|
118
|
-
callId: ctx.callId,
|
|
119
|
-
toolName: ctx.name,
|
|
120
|
-
outcome: ctx.outcome,
|
|
121
|
-
...ctx.reason ? { reason: ctx.reason } : {}
|
|
122
|
-
});
|
|
123
|
-
}));
|
|
124
|
-
unregisters.push(hooks.hook("validation:reject", (ctx) => {
|
|
125
|
-
validationRejects.push({
|
|
126
|
-
callId: ctx.callId,
|
|
127
|
-
toolName: ctx.name,
|
|
128
|
-
reason: ctx.reason
|
|
129
|
-
});
|
|
130
|
-
}));
|
|
131
|
-
unregisters.push(hooks.hook("budget:exceeded", (ctx) => {
|
|
132
|
-
budgetEvents.push({
|
|
133
|
-
kind: "bytes",
|
|
134
|
-
observed: ctx.bytes,
|
|
135
|
-
limit: ctx.budget,
|
|
136
|
-
turnId: ctx.turnId
|
|
137
|
-
});
|
|
138
|
-
}));
|
|
139
|
-
unregisters.push(hooks.hook("tool-budget:exceeded", (ctx) => {
|
|
140
|
-
budgetEvents.push({
|
|
141
|
-
kind: "tool-count",
|
|
142
|
-
toolName: ctx.tool,
|
|
143
|
-
mode: ctx.mode,
|
|
144
|
-
observed: ctx.count,
|
|
145
|
-
limit: ctx.max,
|
|
146
|
-
turnId: ctx.turnId
|
|
147
|
-
});
|
|
148
|
-
}));
|
|
149
|
-
unregisters.push(hooks.hook("repeat-guard:exceeded", (ctx) => {
|
|
150
|
-
repeatGuardEvents.push({
|
|
151
|
-
toolName: ctx.tool,
|
|
152
|
-
count: ctx.count,
|
|
153
|
-
threshold: ctx.threshold,
|
|
154
|
-
action: ctx.action,
|
|
155
|
-
turnId: ctx.turnId
|
|
156
|
-
});
|
|
157
|
-
}));
|
|
158
|
-
unregisters.push(hooks.hook("pairing:repair", (ctx) => {
|
|
159
|
-
pairingRepairs[ctx.mode] = (pairingRepairs[ctx.mode] ?? 0) + 1;
|
|
160
|
-
}));
|
|
161
|
-
unregisters.push(hooks.hook("agent:done", (stats) => {
|
|
162
|
-
const endedAt = Date.now();
|
|
163
|
-
const byModel = [];
|
|
164
|
-
for (const [modelId, usage] of statsByModel(stats)) byModel.push({
|
|
165
|
-
modelId,
|
|
166
|
-
input: usage.input,
|
|
167
|
-
output: usage.output,
|
|
168
|
-
cacheRead: usage.cacheRead,
|
|
169
|
-
cacheCreation: usage.cacheCreation,
|
|
170
|
-
cost: usage.cost,
|
|
171
|
-
turns: usage.turns
|
|
172
|
-
});
|
|
173
|
-
for (const c of stats.children ?? []) children.push(minimalSummaryFromStats(c.stats, {
|
|
174
|
-
depth: c.depth ?? depth + 1,
|
|
175
|
-
status: c.status === "aborted" ? "aborted" : "completed"
|
|
176
|
-
}));
|
|
177
|
-
const summary = {
|
|
178
|
-
...runId ? { runId } : {},
|
|
179
|
-
...parentRunId ? { parentRunId } : {},
|
|
180
|
-
depth,
|
|
181
|
-
...agentName ? { agentName } : {},
|
|
182
|
-
startedAt,
|
|
183
|
-
endedAt,
|
|
184
|
-
durationMs: endedAt - startedAt,
|
|
185
|
-
status: aborted ? "aborted" : "completed",
|
|
186
|
-
turns: stats.turns,
|
|
187
|
-
totals: buildTotals(stats),
|
|
188
|
-
byModel,
|
|
189
|
-
errors: errors.slice(),
|
|
190
|
-
blocks: blocks.slice(),
|
|
191
|
-
validationRejects: validationRejects.slice(),
|
|
192
|
-
budgetEvents: budgetEvents.slice(),
|
|
193
|
-
repeatGuardEvents: repeatGuardEvents.slice(),
|
|
194
|
-
pairingRepairs: { ...pairingRepairs },
|
|
195
|
-
...children.length > 0 ? { children: children.slice() } : {}
|
|
196
|
-
};
|
|
197
|
-
last = summary;
|
|
198
|
-
try {
|
|
199
|
-
options.onSummary?.(summary);
|
|
200
|
-
} catch {}
|
|
201
|
-
}));
|
|
202
|
-
let disposed = false;
|
|
203
|
-
return function uninstall() {
|
|
204
|
-
if (disposed) return;
|
|
205
|
-
disposed = true;
|
|
206
|
-
for (const un of unregisters) try {
|
|
207
|
-
un();
|
|
208
|
-
} catch {}
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
function buildTotals(stats) {
|
|
214
|
-
return {
|
|
215
|
-
input: stats.totalIn,
|
|
216
|
-
output: stats.totalOut,
|
|
217
|
-
cacheRead: stats.totalCacheRead,
|
|
218
|
-
cacheCreation: stats.totalCacheCreation,
|
|
219
|
-
...typeof stats.cost === "number" ? { cost: stats.cost } : {},
|
|
220
|
-
...typeof stats.timeTillFirstTokenMs === "number" ? { ttftMs: stats.timeTillFirstTokenMs } : {}
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
function minimalSummaryFromStats(stats, meta) {
|
|
224
|
-
const byModel = [];
|
|
225
|
-
for (const [modelId, usage] of statsByModel(stats)) byModel.push({
|
|
226
|
-
modelId,
|
|
227
|
-
input: usage.input,
|
|
228
|
-
output: usage.output,
|
|
229
|
-
cacheRead: usage.cacheRead,
|
|
230
|
-
cacheCreation: usage.cacheCreation,
|
|
231
|
-
cost: usage.cost,
|
|
232
|
-
turns: usage.turns
|
|
233
|
-
});
|
|
234
|
-
const children = [];
|
|
235
|
-
for (const c of stats.children ?? []) children.push(minimalSummaryFromStats(c.stats, {
|
|
236
|
-
depth: c.depth ?? meta.depth + 1,
|
|
237
|
-
status: c.status === "aborted" ? "aborted" : "completed"
|
|
238
|
-
}));
|
|
239
|
-
return {
|
|
240
|
-
depth: meta.depth,
|
|
241
|
-
startedAt: 0,
|
|
242
|
-
endedAt: 0,
|
|
243
|
-
durationMs: stats.elapsed,
|
|
244
|
-
status: meta.status,
|
|
245
|
-
turns: stats.turns,
|
|
246
|
-
totals: buildTotals(stats),
|
|
247
|
-
byModel,
|
|
248
|
-
errors: [],
|
|
249
|
-
blocks: [],
|
|
250
|
-
validationRejects: [],
|
|
251
|
-
budgetEvents: [],
|
|
252
|
-
repeatGuardEvents: [],
|
|
253
|
-
pairingRepairs: {},
|
|
254
|
-
...children.length > 0 ? { children } : {}
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
//#endregion
|
|
258
|
-
//#region src/headless.ts
|
|
259
|
-
function exitCodeForHeadlessResult(result) {
|
|
260
|
-
switch (result.status) {
|
|
261
|
-
case "completed": return 0;
|
|
262
|
-
case "timeout": return 124;
|
|
263
|
-
case "aborted": return 130;
|
|
264
|
-
default: return 1;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
/** Serialize one event as a newline-terminated JSON line (stream-json). */
|
|
268
|
-
function headlessEventToJsonl(event) {
|
|
269
|
-
return `${JSON.stringify(event)}\n`;
|
|
270
|
-
}
|
|
271
|
-
function formattedHeadlessTurnEventToJsonl(event) {
|
|
272
|
-
return `${JSON.stringify(event)}\n`;
|
|
273
|
-
}
|
|
274
|
-
function providerTranscriptFormatForProvider(providerName) {
|
|
275
|
-
return providerName === "anthropic" ? "anthropic" : "openai";
|
|
276
|
-
}
|
|
277
|
-
function transcriptToProviderMessages(turns, providerName) {
|
|
278
|
-
if (providerTranscriptFormatForProvider(providerName) === "anthropic") return turns.filter((turn) => turn.role === "user" || turn.role === "assistant").map((turn) => toAnthropic({
|
|
279
|
-
role: turn.role,
|
|
280
|
-
content: turn.content
|
|
281
|
-
}));
|
|
282
|
-
return transcriptToOpenAIMessages(turns, { strictToolPairing: false });
|
|
283
|
-
}
|
|
284
|
-
function formatHeadlessResult(result, options) {
|
|
285
|
-
if (options.format === "zidane") return result;
|
|
286
|
-
return transcriptToProviderMessages(result.transcript, options.providerName);
|
|
287
|
-
}
|
|
288
|
-
function formatHeadlessTurnEvent(event, options) {
|
|
289
|
-
if (options.format === "zidane") return event;
|
|
290
|
-
return transcriptToProviderMessages([event.turn], options.providerName);
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Run a prompt to completion, headless, and return a single serializable
|
|
294
|
-
* {@link HeadlessResult}. Safe to call concurrently for parallel rollouts —
|
|
295
|
-
* each call builds its own agent + session and tears them down in `finally`.
|
|
296
|
-
*/
|
|
297
|
-
async function runHeadless(opts) {
|
|
298
|
-
const startedAt = Date.now();
|
|
299
|
-
const execution = opts.execution ?? createProcessContext({ cwd: opts.cwd });
|
|
300
|
-
const session = opts.session ?? await createSession({ store: opts.store ?? createMemoryStore() });
|
|
301
|
-
const behavior = { ...opts.behavior ?? {} };
|
|
302
|
-
if (opts.maxTurns !== void 0) behavior.maxTurns = opts.maxTurns;
|
|
303
|
-
if (opts.maxTokens !== void 0) behavior.maxTokens = opts.maxTokens;
|
|
304
|
-
if (opts.schema !== void 0) behavior.schema = opts.schema;
|
|
305
|
-
const agent = createAgent({
|
|
306
|
-
...basic_default,
|
|
307
|
-
provider: opts.provider,
|
|
308
|
-
execution,
|
|
309
|
-
session,
|
|
310
|
-
behavior,
|
|
311
|
-
...opts.tools !== void 0 ? { tools: opts.tools } : {},
|
|
312
|
-
...opts.mcpServers !== void 0 ? { mcpServers: opts.mcpServers } : {},
|
|
313
|
-
...opts.skills !== void 0 ? { skills: opts.skills } : {}
|
|
314
|
-
});
|
|
315
|
-
const collector = createRunSummaryCollector();
|
|
316
|
-
const uninstallSummary = collector.install(agent.hooks);
|
|
317
|
-
const uninstallEvents = opts.onEvent ? installHeadlessEventAdapter(agent.hooks, opts.onEvent) : noop;
|
|
318
|
-
const runStartIndex = session.turns.length;
|
|
319
|
-
const controller = new AbortController();
|
|
320
|
-
const onExternalAbort = () => controller.abort(opts.signal.reason);
|
|
321
|
-
if (opts.signal) if (opts.signal.aborted) controller.abort(opts.signal.reason);
|
|
322
|
-
else opts.signal.addEventListener("abort", onExternalAbort, { once: true });
|
|
323
|
-
let timedOut = false;
|
|
324
|
-
const timer = opts.timeoutMs && opts.timeoutMs > 0 ? setTimeout(() => {
|
|
325
|
-
timedOut = true;
|
|
326
|
-
controller.abort(/* @__PURE__ */ new Error(`Headless run timed out after ${opts.timeoutMs}ms`));
|
|
327
|
-
}, opts.timeoutMs) : void 0;
|
|
328
|
-
let stats;
|
|
329
|
-
let error;
|
|
330
|
-
try {
|
|
331
|
-
stats = await agent.run({
|
|
332
|
-
prompt: opts.prompt,
|
|
333
|
-
signal: controller.signal,
|
|
334
|
-
...opts.model !== void 0 ? { model: opts.model } : {},
|
|
335
|
-
...opts.system !== void 0 ? { system: opts.system } : {},
|
|
336
|
-
...opts.thinking !== void 0 ? { thinking: opts.thinking } : {}
|
|
337
|
-
});
|
|
338
|
-
} catch (err) {
|
|
339
|
-
const e = err instanceof Error ? err : new Error(String(err));
|
|
340
|
-
error = {
|
|
341
|
-
message: e.message,
|
|
342
|
-
type: e.name
|
|
343
|
-
};
|
|
344
|
-
} finally {
|
|
345
|
-
if (timer) clearTimeout(timer);
|
|
346
|
-
opts.signal?.removeEventListener("abort", onExternalAbort);
|
|
347
|
-
uninstallEvents();
|
|
348
|
-
uninstallSummary();
|
|
349
|
-
await agent.destroy();
|
|
350
|
-
}
|
|
351
|
-
let status;
|
|
352
|
-
if (error) status = timedOut ? "timeout" : controller.signal.aborted ? "aborted" : "error";
|
|
353
|
-
else if (controller.signal.aborted) status = timedOut ? "timeout" : "aborted";
|
|
354
|
-
else status = "completed";
|
|
355
|
-
const rawTranscript = session.turns.slice(runStartIndex);
|
|
356
|
-
const transcript = opts.includeThinking === false ? stripThinking(rawTranscript) : rawTranscript;
|
|
357
|
-
const summary = collector.latest();
|
|
358
|
-
const result = {
|
|
359
|
-
status,
|
|
360
|
-
finalText: extractFinalText(rawTranscript),
|
|
361
|
-
...stats?.output ? { output: stats.output } : {},
|
|
362
|
-
usage: {
|
|
363
|
-
input: stats?.totalIn ?? 0,
|
|
364
|
-
output: stats?.totalOut ?? 0,
|
|
365
|
-
cacheRead: stats?.totalCacheRead ?? 0,
|
|
366
|
-
cacheCreation: stats?.totalCacheCreation ?? 0,
|
|
367
|
-
...typeof stats?.cost === "number" ? { cost: stats.cost } : {}
|
|
368
|
-
},
|
|
369
|
-
turns: stats?.turns ?? 0,
|
|
370
|
-
durationMs: stats?.elapsed ?? Date.now() - startedAt,
|
|
371
|
-
numToolCalls: countToolCalls(rawTranscript),
|
|
372
|
-
...status !== "aborted" && status !== "timeout" && lastFinishReason(stats) ? { finishReason: lastFinishReason(stats) } : {},
|
|
373
|
-
...error ? { error } : {},
|
|
374
|
-
sessionId: session.id,
|
|
375
|
-
...summary ? { summary } : {},
|
|
376
|
-
transcript
|
|
377
|
-
};
|
|
378
|
-
opts.onEvent?.({
|
|
379
|
-
type: "result",
|
|
380
|
-
result
|
|
381
|
-
});
|
|
382
|
-
return result;
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Convert raw `session.turns` into standard OpenAI chat-completion messages:
|
|
386
|
-
* assistant turns carry `tool_calls`, and each `tool_result` becomes its own
|
|
387
|
-
* `role: 'tool'` message. This is the drop-in shape for an SFT renderer —
|
|
388
|
-
* unlike `toOpenAI` (session/messages.ts), which emits an internal `_tag`
|
|
389
|
-
* envelope meant for re-sending to a provider, not for training data.
|
|
390
|
-
*
|
|
391
|
-
* Fails closed on corrupt raw turns instead of fabricating tool results; silent
|
|
392
|
-
* placeholders would create structurally-valid but semantically-poisoned SFT
|
|
393
|
-
* examples.
|
|
394
|
-
*/
|
|
395
|
-
function transcriptToOpenAIMessages(turns, options = {}) {
|
|
396
|
-
const { strictToolPairing = true } = options;
|
|
397
|
-
const messages = [];
|
|
398
|
-
let chunk = [];
|
|
399
|
-
const flushChunk = () => {
|
|
400
|
-
if (chunk.length === 0) return;
|
|
401
|
-
let paired = chunk;
|
|
402
|
-
if (strictToolPairing) {
|
|
403
|
-
const repairs = [];
|
|
404
|
-
paired = ensureToolResultPairing(chunk, { onRepair: (repair) => repairs.push(repair) });
|
|
405
|
-
if (repairs.length > 0) throw new Error(`Cannot convert transcript to OpenAI messages: tool pairing repair required (${repairs.map((r) => r.mode).join(", ")})`);
|
|
406
|
-
}
|
|
407
|
-
for (const msg of paired) pushOpenAIChatMessage(messages, msg);
|
|
408
|
-
chunk = [];
|
|
409
|
-
};
|
|
410
|
-
for (const turn of turns) {
|
|
411
|
-
if (turn.role === "system") {
|
|
412
|
-
flushChunk();
|
|
413
|
-
messages.push({
|
|
414
|
-
role: "system",
|
|
415
|
-
content: textOf(turn.content)
|
|
416
|
-
});
|
|
417
|
-
continue;
|
|
418
|
-
}
|
|
419
|
-
chunk.push({
|
|
420
|
-
role: turn.role,
|
|
421
|
-
content: turn.content
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
flushChunk();
|
|
425
|
-
return messages;
|
|
426
|
-
}
|
|
427
|
-
function pushOpenAIChatMessage(messages, msg) {
|
|
428
|
-
const text = textOf(msg.content);
|
|
429
|
-
if (msg.role === "assistant") {
|
|
430
|
-
const toolCalls = msg.content.filter((b) => b.type === "tool_call");
|
|
431
|
-
const out = {
|
|
432
|
-
role: "assistant",
|
|
433
|
-
content: text || null
|
|
434
|
-
};
|
|
435
|
-
if (toolCalls.length > 0) out.tool_calls = toolCalls.map((b) => ({
|
|
436
|
-
id: b.id,
|
|
437
|
-
type: "function",
|
|
438
|
-
function: {
|
|
439
|
-
name: b.name,
|
|
440
|
-
arguments: JSON.stringify(b.input)
|
|
441
|
-
}
|
|
442
|
-
}));
|
|
443
|
-
messages.push(out);
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
const userParts = contentPartsFromBlocks(msg.content);
|
|
447
|
-
if (userParts.length > 0) messages.push({
|
|
448
|
-
role: "user",
|
|
449
|
-
content: simplifyOpenAIContent(userParts)
|
|
450
|
-
});
|
|
451
|
-
for (const tr of msg.content.filter((b) => b.type === "tool_result")) {
|
|
452
|
-
const { text, images } = summarizeToolResultForOpenAI(tr.output);
|
|
453
|
-
if (images.length === 0) {
|
|
454
|
-
messages.push({
|
|
455
|
-
role: "tool",
|
|
456
|
-
tool_call_id: tr.callId,
|
|
457
|
-
content: text
|
|
458
|
-
});
|
|
459
|
-
continue;
|
|
460
|
-
}
|
|
461
|
-
const noun = images.length === 1 ? "image" : "images";
|
|
462
|
-
const marker = `[${images.length} ${noun} attached — see next user message]`;
|
|
463
|
-
messages.push({
|
|
464
|
-
role: "tool",
|
|
465
|
-
tool_call_id: tr.callId,
|
|
466
|
-
content: text.length > 0 ? `${text}\n\n${marker}` : marker
|
|
467
|
-
});
|
|
468
|
-
messages.push({
|
|
469
|
-
role: "user",
|
|
470
|
-
content: [...images.map(toOpenAIImagePart), {
|
|
471
|
-
type: "text",
|
|
472
|
-
text: `(${noun} returned by tool call ${tr.callId})`
|
|
473
|
-
}]
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
function noop() {}
|
|
478
|
-
function textOf(content) {
|
|
479
|
-
return content.filter((b) => b.type === "text").map((b) => b.text).join("");
|
|
480
|
-
}
|
|
481
|
-
function contentPartsFromBlocks(content) {
|
|
482
|
-
const parts = [];
|
|
483
|
-
for (const block of content) if (block.type === "image") {
|
|
484
|
-
assertResolvedMediaBlock(block, "OpenAI transcript messages");
|
|
485
|
-
parts.push(toOpenAIImagePart(block));
|
|
486
|
-
} else if (block.type === "audio") parts.push({
|
|
487
|
-
type: "input_audio",
|
|
488
|
-
input_audio: {
|
|
489
|
-
data: block.data,
|
|
490
|
-
format: audioFormatFromMediaType(block.mediaType)
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
else if (block.type === "video") parts.push({
|
|
494
|
-
type: "video_url",
|
|
495
|
-
video_url: { url: `data:${block.mediaType};base64,${block.data}` }
|
|
496
|
-
});
|
|
497
|
-
else if (block.type === "document") {
|
|
498
|
-
assertResolvedMediaBlock(block, "OpenAI transcript messages");
|
|
499
|
-
parts.push({
|
|
500
|
-
type: "text",
|
|
501
|
-
text: documentMarker(block)
|
|
502
|
-
});
|
|
503
|
-
} else if (block.type === "text" && block.text.length > 0) parts.push({
|
|
504
|
-
type: "text",
|
|
505
|
-
text: block.text
|
|
506
|
-
});
|
|
507
|
-
return parts;
|
|
508
|
-
}
|
|
509
|
-
function simplifyOpenAIContent(parts) {
|
|
510
|
-
if (parts.length === 1 && parts[0].type === "text") return parts[0].text;
|
|
511
|
-
return parts;
|
|
512
|
-
}
|
|
513
|
-
function toOpenAIImagePart(image) {
|
|
514
|
-
return {
|
|
515
|
-
type: "image_url",
|
|
516
|
-
image_url: { url: `data:${image.mediaType};base64,${image.data}` }
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
function summarizeToolResultForOpenAI(output) {
|
|
520
|
-
if (typeof output === "string") return {
|
|
521
|
-
text: output,
|
|
522
|
-
images: []
|
|
523
|
-
};
|
|
524
|
-
const texts = [];
|
|
525
|
-
const images = [];
|
|
526
|
-
for (const block of output) if (block.type === "text") texts.push(block.text);
|
|
527
|
-
else if (block.type === "image") {
|
|
528
|
-
assertResolvedMediaBlock(block, "OpenAI transcript messages");
|
|
529
|
-
images.push({
|
|
530
|
-
mediaType: block.mediaType,
|
|
531
|
-
data: block.data
|
|
532
|
-
});
|
|
533
|
-
} else if (block.type === "audio") texts.push(`[audio: ${block.mediaType}]`);
|
|
534
|
-
else if (block.type === "video") texts.push(`[video: ${block.mediaType}]`);
|
|
535
|
-
else {
|
|
536
|
-
assertResolvedMediaBlock(block, "OpenAI transcript messages");
|
|
537
|
-
texts.push(documentMarker(block));
|
|
538
|
-
}
|
|
539
|
-
return {
|
|
540
|
-
text: texts.join("\n"),
|
|
541
|
-
images
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
function documentMarker(doc) {
|
|
545
|
-
return documentBlockMarker(doc, "document omitted");
|
|
546
|
-
}
|
|
547
|
-
function extractFinalText(turns) {
|
|
548
|
-
for (let i = turns.length - 1; i >= 0; i--) {
|
|
549
|
-
const turn = turns[i];
|
|
550
|
-
if (turn.role !== "assistant") continue;
|
|
551
|
-
const text = textOf(turn.content);
|
|
552
|
-
if (text) return text;
|
|
553
|
-
}
|
|
554
|
-
return "";
|
|
555
|
-
}
|
|
556
|
-
function countToolCalls(turns) {
|
|
557
|
-
let n = 0;
|
|
558
|
-
for (const turn of turns) for (const block of turn.content) if (block.type === "tool_call") n++;
|
|
559
|
-
return n;
|
|
560
|
-
}
|
|
561
|
-
function lastFinishReason(stats) {
|
|
562
|
-
const usages = stats?.turnUsage;
|
|
563
|
-
if (!usages) return void 0;
|
|
564
|
-
for (let i = usages.length - 1; i >= 0; i--) if (usages[i].finishReason) return usages[i].finishReason;
|
|
565
|
-
}
|
|
566
|
-
function stripThinking(turns) {
|
|
567
|
-
return turns.map((turn) => ({
|
|
568
|
-
...turn,
|
|
569
|
-
content: turn.content.filter((b) => b.type !== "thinking" && b.type !== "redacted_thinking")
|
|
570
|
-
}));
|
|
571
|
-
}
|
|
572
|
-
function installHeadlessEventAdapter(hooks, onEvent) {
|
|
573
|
-
const unregs = [];
|
|
574
|
-
const emittedTurnIds = /* @__PURE__ */ new Set();
|
|
575
|
-
const emit = (event) => {
|
|
576
|
-
try {
|
|
577
|
-
onEvent(event);
|
|
578
|
-
} catch {}
|
|
579
|
-
};
|
|
580
|
-
unregs.push(hooks.hook("agent:start", (ctx) => emit({
|
|
581
|
-
type: "start",
|
|
582
|
-
runId: ctx.runId,
|
|
583
|
-
...ctx.providerName ? { provider: ctx.providerName } : {}
|
|
584
|
-
})));
|
|
585
|
-
unregs.push(hooks.hook("stream:text", (ctx) => emit({
|
|
586
|
-
type: "text",
|
|
587
|
-
delta: ctx.delta
|
|
588
|
-
})));
|
|
589
|
-
unregs.push(hooks.hook("stream:thinking", (ctx) => emit({
|
|
590
|
-
type: "thinking",
|
|
591
|
-
delta: ctx.delta
|
|
592
|
-
})));
|
|
593
|
-
unregs.push(hooks.hook("tool:before", (ctx) => emit({
|
|
594
|
-
type: "tool_call",
|
|
595
|
-
callId: ctx.callId,
|
|
596
|
-
name: ctx.name,
|
|
597
|
-
input: ctx.input
|
|
598
|
-
})));
|
|
599
|
-
unregs.push(hooks.hook("tool:after", (ctx) => emit({
|
|
600
|
-
type: "tool_result",
|
|
601
|
-
callId: ctx.callId,
|
|
602
|
-
name: ctx.name,
|
|
603
|
-
output: toolResultToText(ctx.result),
|
|
604
|
-
isError: false
|
|
605
|
-
})));
|
|
606
|
-
unregs.push(hooks.hook("tool:error", (ctx) => emit({
|
|
607
|
-
type: "tool_result",
|
|
608
|
-
callId: ctx.callId,
|
|
609
|
-
name: ctx.name,
|
|
610
|
-
output: ctx.error.message,
|
|
611
|
-
isError: true
|
|
612
|
-
})));
|
|
613
|
-
unregs.push(hooks.hook("session:turns", (ctx) => {
|
|
614
|
-
const startIndex = ctx.count - ctx.turns.length;
|
|
615
|
-
ctx.turns.forEach((turn, i) => {
|
|
616
|
-
if (emittedTurnIds.has(turn.id)) return;
|
|
617
|
-
emittedTurnIds.add(turn.id);
|
|
618
|
-
emit({
|
|
619
|
-
type: "turn",
|
|
620
|
-
index: startIndex + i,
|
|
621
|
-
turn
|
|
622
|
-
});
|
|
623
|
-
});
|
|
624
|
-
}));
|
|
625
|
-
unregs.push(hooks.hook("spawn:before", (ctx) => emit({
|
|
626
|
-
type: "spawn",
|
|
627
|
-
event: "before",
|
|
628
|
-
id: ctx.id
|
|
629
|
-
})));
|
|
630
|
-
unregs.push(hooks.hook("spawn:complete", (ctx) => emit({
|
|
631
|
-
type: "spawn",
|
|
632
|
-
event: "complete",
|
|
633
|
-
id: ctx.id,
|
|
634
|
-
info: { status: ctx.status ?? "completed" }
|
|
635
|
-
})));
|
|
636
|
-
unregs.push(hooks.hook("spawn:error", (ctx) => emit({
|
|
637
|
-
type: "spawn",
|
|
638
|
-
event: "error",
|
|
639
|
-
id: ctx.id,
|
|
640
|
-
info: { message: ctx.error.message }
|
|
641
|
-
})));
|
|
642
|
-
unregs.push(hooks.hook("stream:error", (ctx) => emit({
|
|
643
|
-
type: "error",
|
|
644
|
-
message: ctx.err instanceof Error ? ctx.err.message : String(ctx.err),
|
|
645
|
-
...ctx.err instanceof Error ? { errorType: ctx.err.name } : {}
|
|
646
|
-
})));
|
|
647
|
-
return () => {
|
|
648
|
-
for (const un of unregs) try {
|
|
649
|
-
un();
|
|
650
|
-
} catch {}
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
//#endregion
|
|
654
|
-
export { headlessEventToJsonl as a, runHeadless as c, createRunSummaryCollector as d, formattedHeadlessTurnEventToJsonl as i, transcriptToOpenAIMessages as l, formatHeadlessResult as n, installHeadlessEventAdapter as o, formatHeadlessTurnEvent as r, providerTranscriptFormatForProvider as s, exitCodeForHeadlessResult as t, transcriptToProviderMessages as u };
|
|
655
|
-
|
|
656
|
-
//# sourceMappingURL=headless-2SH7dvoW.js.map
|