@dogpile/sdk 0.3.0 → 0.4.0
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 +145 -0
- package/README.md +1 -0
- package/dist/browser/index.js +2270 -507
- package/dist/browser/index.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/providers/openai-compatible.d.ts +11 -0
- package/dist/providers/openai-compatible.d.ts.map +1 -1
- package/dist/providers/openai-compatible.js +87 -2
- package/dist/providers/openai-compatible.js.map +1 -1
- package/dist/runtime/broadcast.d.ts.map +1 -1
- package/dist/runtime/broadcast.js +1 -13
- package/dist/runtime/broadcast.js.map +1 -1
- package/dist/runtime/cancellation.d.ts +26 -0
- package/dist/runtime/cancellation.d.ts.map +1 -1
- package/dist/runtime/cancellation.js +38 -1
- package/dist/runtime/cancellation.js.map +1 -1
- package/dist/runtime/coordinator.d.ts +74 -1
- package/dist/runtime/coordinator.d.ts.map +1 -1
- package/dist/runtime/coordinator.js +929 -34
- package/dist/runtime/coordinator.js.map +1 -1
- package/dist/runtime/decisions.d.ts +25 -3
- package/dist/runtime/decisions.d.ts.map +1 -1
- package/dist/runtime/decisions.js +241 -3
- package/dist/runtime/decisions.js.map +1 -1
- package/dist/runtime/defaults.d.ts +37 -1
- package/dist/runtime/defaults.d.ts.map +1 -1
- package/dist/runtime/defaults.js +347 -0
- package/dist/runtime/defaults.js.map +1 -1
- package/dist/runtime/engine.d.ts.map +1 -1
- package/dist/runtime/engine.js +254 -24
- package/dist/runtime/engine.js.map +1 -1
- package/dist/runtime/ids.d.ts +19 -0
- package/dist/runtime/ids.d.ts.map +1 -0
- package/dist/runtime/ids.js +36 -0
- package/dist/runtime/ids.js.map +1 -0
- package/dist/runtime/logger.d.ts +61 -0
- package/dist/runtime/logger.d.ts.map +1 -0
- package/dist/runtime/logger.js +114 -0
- package/dist/runtime/logger.js.map +1 -0
- package/dist/runtime/retry.d.ts +99 -0
- package/dist/runtime/retry.d.ts.map +1 -0
- package/dist/runtime/retry.js +181 -0
- package/dist/runtime/retry.js.map +1 -0
- package/dist/runtime/sequential.d.ts.map +1 -1
- package/dist/runtime/sequential.js +9 -11
- package/dist/runtime/sequential.js.map +1 -1
- package/dist/runtime/shared.d.ts.map +1 -1
- package/dist/runtime/shared.js +1 -13
- package/dist/runtime/shared.js.map +1 -1
- package/dist/runtime/tools/built-in.d.ts +99 -0
- package/dist/runtime/tools/built-in.d.ts.map +1 -0
- package/dist/runtime/tools/built-in.js +577 -0
- package/dist/runtime/tools/built-in.js.map +1 -0
- package/dist/runtime/tools/vercel-ai.d.ts +67 -0
- package/dist/runtime/tools/vercel-ai.d.ts.map +1 -0
- package/dist/runtime/tools/vercel-ai.js +148 -0
- package/dist/runtime/tools/vercel-ai.js.map +1 -0
- package/dist/runtime/tools.d.ts +5 -268
- package/dist/runtime/tools.d.ts.map +1 -1
- package/dist/runtime/tools.js +7 -770
- package/dist/runtime/tools.js.map +1 -1
- package/dist/runtime/validation.d.ts +10 -0
- package/dist/runtime/validation.d.ts.map +1 -1
- package/dist/runtime/validation.js +73 -0
- package/dist/runtime/validation.js.map +1 -1
- package/dist/types/benchmark.d.ts +276 -0
- package/dist/types/benchmark.d.ts.map +1 -0
- package/dist/types/benchmark.js +2 -0
- package/dist/types/benchmark.js.map +1 -0
- package/dist/types/events.d.ts +816 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/events.js +2 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/replay.d.ts +173 -0
- package/dist/types/replay.d.ts.map +1 -0
- package/dist/types/replay.js +2 -0
- package/dist/types/replay.js.map +1 -0
- package/dist/types.d.ts +135 -938
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +27 -1
- package/src/index.ts +14 -0
- package/src/providers/openai-compatible.ts +82 -3
- package/src/runtime/broadcast.ts +1 -16
- package/src/runtime/cancellation.ts +59 -1
- package/src/runtime/coordinator.ts +1164 -34
- package/src/runtime/decisions.ts +307 -4
- package/src/runtime/defaults.ts +376 -0
- package/src/runtime/engine.ts +363 -24
- package/src/runtime/ids.ts +41 -0
- package/src/runtime/logger.ts +152 -0
- package/src/runtime/retry.ts +270 -0
- package/src/runtime/sequential.ts +10 -13
- package/src/runtime/shared.ts +1 -16
- package/src/runtime/tools/built-in.ts +875 -0
- package/src/runtime/tools/vercel-ai.ts +269 -0
- package/src/runtime/tools.ts +60 -1255
- package/src/runtime/validation.ts +81 -0
- package/src/types/benchmark.ts +300 -0
- package/src/types/events.ts +895 -0
- package/src/types/replay.ts +212 -0
- package/src/types.ts +251 -997
|
@@ -0,0 +1,816 @@
|
|
|
1
|
+
import type { BudgetCaps, BudgetStopReason, CostSummary, JsonObject, ModelRequest, ModelResponse, NormalizedQualityScore, ProtocolName, RunEvaluation, RunResult, RuntimeToolIdentity, RuntimeToolResult, TerminationStopRecord, Trace } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Event emitted when a protocol assigns or records an agent role.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This event normally appears near the beginning of a run and establishes the
|
|
7
|
+
* `agentId`/`role` pair that later turn and transcript records refer to. A
|
|
8
|
+
* renderer can use it to build the participant roster before model output
|
|
9
|
+
* starts streaming.
|
|
10
|
+
*
|
|
11
|
+
* Payload shape:
|
|
12
|
+
*
|
|
13
|
+
* - `type`: always `role-assignment`.
|
|
14
|
+
* - `runId`: stable id shared by every event and trace object for the run.
|
|
15
|
+
* - `at`: ISO-8601 timestamp for when the assignment was emitted.
|
|
16
|
+
* - `agentId`: stable agent id used in events, trace, and transcript entries.
|
|
17
|
+
* - `role`: model-visible role or perspective assigned to that agent.
|
|
18
|
+
*/
|
|
19
|
+
export interface RoleAssignmentEvent {
|
|
20
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
21
|
+
readonly type: "role-assignment";
|
|
22
|
+
/** Stable run id shared by all events in one workflow. */
|
|
23
|
+
readonly runId: string;
|
|
24
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
25
|
+
readonly parentRunIds?: readonly string[];
|
|
26
|
+
/** ISO-8601 event timestamp. */
|
|
27
|
+
readonly at: string;
|
|
28
|
+
/** Agent receiving the role assignment. */
|
|
29
|
+
readonly agentId: string;
|
|
30
|
+
/** Role assigned to the agent. */
|
|
31
|
+
readonly role: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Event emitted when Dogpile is about to ask the configured model provider for
|
|
35
|
+
* one protocol-managed response.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* This event is the request-side model activity counterpart to
|
|
39
|
+
* {@link ModelResponseEvent}. Protocol implementations may omit it when they
|
|
40
|
+
* only expose completed turns, but adapters and researcher harnesses can emit
|
|
41
|
+
* it to make provider calls visible in the same streaming event log as agent
|
|
42
|
+
* turns and final output.
|
|
43
|
+
*/
|
|
44
|
+
export interface ModelRequestEvent {
|
|
45
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
46
|
+
readonly type: "model-request";
|
|
47
|
+
/** Stable run id shared by all events in one workflow. */
|
|
48
|
+
readonly runId: string;
|
|
49
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
50
|
+
readonly parentRunIds?: readonly string[];
|
|
51
|
+
/** ISO-8601 event timestamp. */
|
|
52
|
+
readonly at: string;
|
|
53
|
+
/** Stable provider call id within the run. */
|
|
54
|
+
readonly callId: string;
|
|
55
|
+
/** Configured model provider id receiving the request. */
|
|
56
|
+
readonly providerId: string;
|
|
57
|
+
/** Agent requesting the model call. */
|
|
58
|
+
readonly agentId: string;
|
|
59
|
+
/** Agent role for the active model call. */
|
|
60
|
+
readonly role: string;
|
|
61
|
+
/** Provider-neutral request handed to the model adapter. */
|
|
62
|
+
readonly request: ModelRequest;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Event emitted after the configured model provider returns one response.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* This event records provider-level model activity without forcing callers to
|
|
69
|
+
* infer it from the higher-level {@link TurnEvent}. The response is the same
|
|
70
|
+
* provider-neutral shape captured in replay traces, so it remains portable and
|
|
71
|
+
* JSON-serializable across Node LTS, Bun, and browser ESM runtimes.
|
|
72
|
+
*/
|
|
73
|
+
export interface ModelResponseEvent {
|
|
74
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
75
|
+
readonly type: "model-response";
|
|
76
|
+
/** Stable run id shared by all events in one workflow. */
|
|
77
|
+
readonly runId: string;
|
|
78
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
79
|
+
readonly parentRunIds?: readonly string[];
|
|
80
|
+
/** ISO-8601 event timestamp. */
|
|
81
|
+
readonly at: string;
|
|
82
|
+
/** Stable provider call id within the run. */
|
|
83
|
+
readonly callId: string;
|
|
84
|
+
/** Configured model provider id that produced the response. */
|
|
85
|
+
readonly providerId: string;
|
|
86
|
+
/** Agent that requested the model call. */
|
|
87
|
+
readonly agentId: string;
|
|
88
|
+
/** Agent role for the completed model call. */
|
|
89
|
+
readonly role: string;
|
|
90
|
+
/** Provider-neutral response returned by the model adapter. */
|
|
91
|
+
readonly response: ModelResponse;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Event emitted while a model turn is still generating text.
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* `model-output-chunk` lets streaming callers render provider output before
|
|
98
|
+
* the protocol has enough information to commit the completed `agent-turn`
|
|
99
|
+
* transcript entry. It is emitted only when the configured model provider
|
|
100
|
+
* implements {@link ConfiguredModelProvider.stream}; non-streaming providers
|
|
101
|
+
* continue to produce the existing role/turn/final event sequence.
|
|
102
|
+
*
|
|
103
|
+
* Payload shape:
|
|
104
|
+
*
|
|
105
|
+
* - `type`: always `model-output-chunk`.
|
|
106
|
+
* - `runId`: stable id shared by every event and trace object for the run.
|
|
107
|
+
* - `at`: ISO-8601 timestamp for when the chunk was observed.
|
|
108
|
+
* - `agentId` and `role`: identify the active generating agent.
|
|
109
|
+
* - `input`: prompt text visible to that agent for this turn.
|
|
110
|
+
* - `chunkIndex`: zero-based chunk index within this model turn.
|
|
111
|
+
* - `text`: text delta from the provider.
|
|
112
|
+
* - `output`: accumulated output for this turn after applying the chunk.
|
|
113
|
+
*/
|
|
114
|
+
export interface ModelOutputChunkEvent {
|
|
115
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
116
|
+
readonly type: "model-output-chunk";
|
|
117
|
+
/** Stable run id shared by all events in one workflow. */
|
|
118
|
+
readonly runId: string;
|
|
119
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
120
|
+
readonly parentRunIds?: readonly string[];
|
|
121
|
+
/** ISO-8601 event timestamp. */
|
|
122
|
+
readonly at: string;
|
|
123
|
+
/** Agent currently producing output. */
|
|
124
|
+
readonly agentId: string;
|
|
125
|
+
/** Agent role for the active turn. */
|
|
126
|
+
readonly role: string;
|
|
127
|
+
/** Prompt/input visible to the agent for this turn. */
|
|
128
|
+
readonly input: string;
|
|
129
|
+
/** Zero-based chunk index within the active model turn. */
|
|
130
|
+
readonly chunkIndex: number;
|
|
131
|
+
/** Text delta produced by the model provider. */
|
|
132
|
+
readonly text: string;
|
|
133
|
+
/** Accumulated output for this turn after applying this chunk. */
|
|
134
|
+
readonly output: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Event emitted when a runtime tool is invoked by protocol or model policy.
|
|
138
|
+
*
|
|
139
|
+
* @remarks
|
|
140
|
+
* Tools are caller-owned escape hatches. This request-side event keeps tool
|
|
141
|
+
* invocation observable without making Dogpile core depend on Node-only
|
|
142
|
+
* capabilities, a storage layer, or a provider-specific function-call shape.
|
|
143
|
+
*/
|
|
144
|
+
export interface ToolCallEvent {
|
|
145
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
146
|
+
readonly type: "tool-call";
|
|
147
|
+
/** Stable run id shared by all events in one workflow. */
|
|
148
|
+
readonly runId: string;
|
|
149
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
150
|
+
readonly parentRunIds?: readonly string[];
|
|
151
|
+
/** ISO-8601 event timestamp. */
|
|
152
|
+
readonly at: string;
|
|
153
|
+
/** Stable tool call id within the run. */
|
|
154
|
+
readonly toolCallId: string;
|
|
155
|
+
/** Tool identity selected for execution. */
|
|
156
|
+
readonly tool: RuntimeToolIdentity;
|
|
157
|
+
/** JSON-serializable tool input. */
|
|
158
|
+
readonly input: JsonObject;
|
|
159
|
+
/** Agent that requested the tool, when agent-scoped. */
|
|
160
|
+
readonly agentId?: string;
|
|
161
|
+
/** Agent role that requested the tool, when available. */
|
|
162
|
+
readonly role?: string;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Event emitted after a runtime tool returns a normalized result.
|
|
166
|
+
*
|
|
167
|
+
* @remarks
|
|
168
|
+
* Tool failures are data at the public boundary. The result payload uses the
|
|
169
|
+
* same discriminated union as runtime tool adapters, allowing log consumers to
|
|
170
|
+
* render successful outputs and normalized errors exhaustively.
|
|
171
|
+
*/
|
|
172
|
+
export interface ToolResultEvent {
|
|
173
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
174
|
+
readonly type: "tool-result";
|
|
175
|
+
/** Stable run id shared by all events in one workflow. */
|
|
176
|
+
readonly runId: string;
|
|
177
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
178
|
+
readonly parentRunIds?: readonly string[];
|
|
179
|
+
/** ISO-8601 event timestamp. */
|
|
180
|
+
readonly at: string;
|
|
181
|
+
/** Stable tool call id within the run. */
|
|
182
|
+
readonly toolCallId: string;
|
|
183
|
+
/** Tool identity that produced the result. */
|
|
184
|
+
readonly tool: RuntimeToolIdentity;
|
|
185
|
+
/** Normalized JSON-serializable tool result. */
|
|
186
|
+
readonly result: RuntimeToolResult;
|
|
187
|
+
/** Agent that requested the tool, when agent-scoped. */
|
|
188
|
+
readonly agentId?: string;
|
|
189
|
+
/** Agent role that requested the tool, when available. */
|
|
190
|
+
readonly role?: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Provider-normalized participation decision parsed from paper-style agent output.
|
|
194
|
+
*
|
|
195
|
+
* @remarks
|
|
196
|
+
* Dogpile preserves the raw model text on transcript entries and events. When
|
|
197
|
+
* a model emits the labeled fields `role_selected`, `participation`,
|
|
198
|
+
* `rationale`, and `contribution`, protocols also attach this structured
|
|
199
|
+
* metadata so reproduction harnesses can distinguish contribution from
|
|
200
|
+
* voluntary abstention without reparsing raw text.
|
|
201
|
+
*/
|
|
202
|
+
export interface ParticipateAgentDecision {
|
|
203
|
+
/** Discriminant marking this as a participate-style decision. */
|
|
204
|
+
readonly type: "participate";
|
|
205
|
+
/** Task-specific role selected by the agent for this turn. */
|
|
206
|
+
readonly selectedRole: string;
|
|
207
|
+
/** Whether the agent contributed or voluntarily abstained. */
|
|
208
|
+
readonly participation: AgentParticipation;
|
|
209
|
+
/** Agent-provided rationale for the selected role and participation choice. */
|
|
210
|
+
readonly rationale: string;
|
|
211
|
+
/** Agent-provided contribution text, or abstention explanation. */
|
|
212
|
+
readonly contribution: string;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Decision emitted by a coordinator agent that delegates a sub-mission to a
|
|
216
|
+
* coordination protocol rather than contributing directly. The runtime
|
|
217
|
+
* dispatches a child run when this decision is returned.
|
|
218
|
+
*/
|
|
219
|
+
export interface DelegateAgentDecision {
|
|
220
|
+
/** Discriminant marking this as a delegate-style decision. */
|
|
221
|
+
readonly type: "delegate";
|
|
222
|
+
/** Coordination protocol the child sub-run will execute. */
|
|
223
|
+
readonly protocol: ProtocolName;
|
|
224
|
+
/** Mission text passed to the child sub-run. */
|
|
225
|
+
readonly intent: string;
|
|
226
|
+
/**
|
|
227
|
+
* Optional model provider id assertion. When set, the runtime requires the
|
|
228
|
+
* value to match the parent's `ConfiguredModelProvider.id` (D-11) — child
|
|
229
|
+
* runs always inherit the parent provider instance verbatim.
|
|
230
|
+
*/
|
|
231
|
+
readonly model?: string;
|
|
232
|
+
/** Optional per-decision budget caps applied to the child run. */
|
|
233
|
+
readonly budget?: BudgetCaps;
|
|
234
|
+
/**
|
|
235
|
+
* Optional per-decision child concurrency ceiling. This can only lower the
|
|
236
|
+
* engine/run effective max for the current coordinator fan-out turn (D-05).
|
|
237
|
+
*/
|
|
238
|
+
readonly maxConcurrentChildren?: number;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Discriminated union of structured agent decisions parsed from model output.
|
|
242
|
+
*
|
|
243
|
+
* - `participate`: paper-style turn contribution; carries the four labeled
|
|
244
|
+
* fields (`selectedRole`, `participation`, `rationale`, `contribution`).
|
|
245
|
+
* - `delegate`: coordinator-only delegation to a child sub-run. The runtime
|
|
246
|
+
* dispatches a sub-mission when this branch is returned.
|
|
247
|
+
*
|
|
248
|
+
* Consumers MUST narrow on `decision.type === "participate"` before reading
|
|
249
|
+
* paper-style fields.
|
|
250
|
+
*/
|
|
251
|
+
export type AgentDecision = ParticipateAgentDecision | DelegateAgentDecision;
|
|
252
|
+
/**
|
|
253
|
+
* Agent participation state for a paper-style turn decision.
|
|
254
|
+
*/
|
|
255
|
+
export type AgentParticipation = "contribute" | "abstain";
|
|
256
|
+
/**
|
|
257
|
+
* Event emitted after one agent contributes a model turn.
|
|
258
|
+
*
|
|
259
|
+
* @remarks
|
|
260
|
+
* `agent-turn` is the primary streaming payload for sequential, coordinator,
|
|
261
|
+
* shared-state, and broadcast executions. It captures the exact prompt/input
|
|
262
|
+
* Dogpile supplied to the agent, the text returned by the model provider, and
|
|
263
|
+
* the cumulative cost after applying that response.
|
|
264
|
+
*
|
|
265
|
+
* The corresponding durable transcript record contains the same
|
|
266
|
+
* `agentId`/`role`/`input`/`output` contribution without event timing or cost
|
|
267
|
+
* fields. Use this event for live progress UIs and the transcript for replay
|
|
268
|
+
* or downstream application logic.
|
|
269
|
+
*
|
|
270
|
+
* Payload shape:
|
|
271
|
+
*
|
|
272
|
+
* - `type`: always `agent-turn`.
|
|
273
|
+
* - `runId`: stable id shared by every event and trace object for the run.
|
|
274
|
+
* - `at`: ISO-8601 timestamp for when the turn completed.
|
|
275
|
+
* - `agentId` and `role`: identify the contributing agent.
|
|
276
|
+
* - `input`: prompt text visible to that agent for this turn.
|
|
277
|
+
* - `output`: generated model text produced by the agent.
|
|
278
|
+
* - `cost`: cumulative token and spend accounting after this turn.
|
|
279
|
+
*/
|
|
280
|
+
export interface TurnEvent {
|
|
281
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
282
|
+
readonly type: "agent-turn";
|
|
283
|
+
/** Stable run id shared by all events in one workflow. */
|
|
284
|
+
readonly runId: string;
|
|
285
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
286
|
+
readonly parentRunIds?: readonly string[];
|
|
287
|
+
/** ISO-8601 event timestamp. */
|
|
288
|
+
readonly at: string;
|
|
289
|
+
/** Agent that produced this turn. */
|
|
290
|
+
readonly agentId: string;
|
|
291
|
+
/** Agent role for this turn. */
|
|
292
|
+
readonly role: string;
|
|
293
|
+
/** Prompt/input visible to the agent for this turn. */
|
|
294
|
+
readonly input: string;
|
|
295
|
+
/** Model output produced by the agent. */
|
|
296
|
+
readonly output: string;
|
|
297
|
+
/** Optional structured role/participation decision parsed from model output. */
|
|
298
|
+
readonly decision?: AgentDecision | readonly DelegateAgentDecision[];
|
|
299
|
+
/** Cumulative cost after this turn. */
|
|
300
|
+
readonly cost: CostSummary;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* One independent contribution captured by a broadcast round event.
|
|
304
|
+
*
|
|
305
|
+
* @remarks
|
|
306
|
+
* Broadcast protocols collect one contribution per participating agent before
|
|
307
|
+
* synthesis. The contribution payload is intentionally smaller than
|
|
308
|
+
* {@link TurnEvent}: it is a round-level summary of model outputs, while the
|
|
309
|
+
* complete prompt/output pair for each agent is still available as individual
|
|
310
|
+
* `agent-turn` events and {@link TranscriptEntry} records.
|
|
311
|
+
*
|
|
312
|
+
* Payload shape:
|
|
313
|
+
*
|
|
314
|
+
* - `agentId`: stable id of the contributing agent.
|
|
315
|
+
* - `role`: model-visible role or perspective used for that contribution.
|
|
316
|
+
* - `output`: generated text contributed independently for the round.
|
|
317
|
+
*/
|
|
318
|
+
export interface BroadcastContribution {
|
|
319
|
+
/** Agent that produced the broadcast contribution. */
|
|
320
|
+
readonly agentId: string;
|
|
321
|
+
/** Agent role for the contribution. */
|
|
322
|
+
readonly role: string;
|
|
323
|
+
/** Independent model output produced for the shared mission. */
|
|
324
|
+
readonly output: string;
|
|
325
|
+
/** Optional structured role/participation decision parsed from model output. */
|
|
326
|
+
readonly decision?: AgentDecision | readonly DelegateAgentDecision[];
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Event emitted after agents broadcast independent contributions for a round.
|
|
330
|
+
*
|
|
331
|
+
* @remarks
|
|
332
|
+
* A `broadcast` event marks the coordination moment where independently
|
|
333
|
+
* generated agent outputs are gathered for a shared round. It does not replace
|
|
334
|
+
* per-agent `agent-turn` events; instead, it groups their outputs by round so
|
|
335
|
+
* observers can render the broadcast barrier and replay the paper protocol's
|
|
336
|
+
* independent-contribution step.
|
|
337
|
+
*
|
|
338
|
+
* Payload shape:
|
|
339
|
+
*
|
|
340
|
+
* - `type`: always `broadcast`.
|
|
341
|
+
* - `runId`: stable id shared by every event and trace object for the run.
|
|
342
|
+
* - `at`: ISO-8601 timestamp for when the round finished.
|
|
343
|
+
* - `round`: one-based broadcast round number.
|
|
344
|
+
* - `contributions`: independent outputs collected for this round.
|
|
345
|
+
* - `cost`: cumulative token and spend accounting after the round.
|
|
346
|
+
*/
|
|
347
|
+
export interface BroadcastEvent {
|
|
348
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
349
|
+
readonly type: "broadcast";
|
|
350
|
+
/** Stable run id shared by all events in one workflow. */
|
|
351
|
+
readonly runId: string;
|
|
352
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
353
|
+
readonly parentRunIds?: readonly string[];
|
|
354
|
+
/** ISO-8601 event timestamp. */
|
|
355
|
+
readonly at: string;
|
|
356
|
+
/** One-based broadcast round number. */
|
|
357
|
+
readonly round: number;
|
|
358
|
+
/** Independent contributions collected in this broadcast round. */
|
|
359
|
+
readonly contributions: readonly BroadcastContribution[];
|
|
360
|
+
/** Cumulative cost after this broadcast round. */
|
|
361
|
+
readonly cost: CostSummary;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Event emitted when a workflow halts because a configured budget cap fired.
|
|
365
|
+
*
|
|
366
|
+
* @remarks
|
|
367
|
+
* `budget-stop` records the normalized cap class that stopped execution before
|
|
368
|
+
* the final event closes the run. The detail object is JSON-serializable so
|
|
369
|
+
* callers can persist or replay the exact cap, observed value, and limit.
|
|
370
|
+
*/
|
|
371
|
+
export interface BudgetStopEvent {
|
|
372
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
373
|
+
readonly type: "budget-stop";
|
|
374
|
+
/** Stable run id shared by all events in one workflow. */
|
|
375
|
+
readonly runId: string;
|
|
376
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
377
|
+
readonly parentRunIds?: readonly string[];
|
|
378
|
+
/** ISO-8601 event timestamp. */
|
|
379
|
+
readonly at: string;
|
|
380
|
+
/** Normalized machine-readable budget stop reason. */
|
|
381
|
+
readonly reason: BudgetStopReason;
|
|
382
|
+
/** Total cost at the stop point. */
|
|
383
|
+
readonly cost: CostSummary;
|
|
384
|
+
/** Completed model-turn iterations at the stop point. */
|
|
385
|
+
readonly iteration: number;
|
|
386
|
+
/** Elapsed runtime in milliseconds at the stop point. */
|
|
387
|
+
readonly elapsedMs: number;
|
|
388
|
+
/** Serializable cap diagnostics. */
|
|
389
|
+
readonly detail: JsonObject;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Link from a terminal event to the completed trace transcript.
|
|
393
|
+
*
|
|
394
|
+
* @remarks
|
|
395
|
+
* Final events are emitted before callers await {@link StreamHandle.result},
|
|
396
|
+
* so this compact link tells streaming UIs exactly which transcript artifact
|
|
397
|
+
* the terminal output closes over without duplicating every transcript entry
|
|
398
|
+
* inside the event log.
|
|
399
|
+
*/
|
|
400
|
+
export interface TranscriptLink {
|
|
401
|
+
/** Discriminant for future transcript link variants. */
|
|
402
|
+
readonly kind: "trace-transcript";
|
|
403
|
+
/** Number of transcript entries included in the completed trace. */
|
|
404
|
+
readonly entryCount: number;
|
|
405
|
+
/** Zero-based index of the last transcript entry, or `null` for empty runs. */
|
|
406
|
+
readonly lastEntryIndex: number | null;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Event emitted when a workflow produces its final output.
|
|
410
|
+
*
|
|
411
|
+
* @remarks
|
|
412
|
+
* `final` is the terminal streaming event for a successful run. Its `output`
|
|
413
|
+
* value matches {@link RunResult.output}, and its `cost` value matches the
|
|
414
|
+
* final aggregate cost returned on the result. Its `transcript` link points to
|
|
415
|
+
* the completed {@link Trace.transcript} entries that produced the terminal
|
|
416
|
+
* output.
|
|
417
|
+
*
|
|
418
|
+
* Payload shape:
|
|
419
|
+
*
|
|
420
|
+
* - `type`: always `final`.
|
|
421
|
+
* - `runId`: stable id shared by every event and trace object for the run.
|
|
422
|
+
* - `at`: ISO-8601 timestamp for when final synthesis completed.
|
|
423
|
+
* - `output`: final synthesized answer returned to the caller.
|
|
424
|
+
* - `cost`: total token and spend accounting for the run.
|
|
425
|
+
* - `transcript`: compact link to the completed trace transcript.
|
|
426
|
+
*/
|
|
427
|
+
export interface FinalEvent {
|
|
428
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
429
|
+
readonly type: "final";
|
|
430
|
+
/** Stable run id shared by all events in one workflow. */
|
|
431
|
+
readonly runId: string;
|
|
432
|
+
/** ISO-8601 event timestamp. */
|
|
433
|
+
readonly at: string;
|
|
434
|
+
/** Final synthesized answer returned as `RunResult.output`. */
|
|
435
|
+
readonly output: string;
|
|
436
|
+
/** Total cost at completion. */
|
|
437
|
+
readonly cost: CostSummary;
|
|
438
|
+
/** Link to the completed trace transcript. */
|
|
439
|
+
readonly transcript: TranscriptLink;
|
|
440
|
+
/** Optional normalized quality score supplied by a caller-owned evaluator. */
|
|
441
|
+
readonly quality?: NormalizedQualityScore;
|
|
442
|
+
/** Optional serializable evaluation payload supplied by a caller-owned evaluator. */
|
|
443
|
+
readonly evaluation?: RunEvaluation;
|
|
444
|
+
/** Termination condition that stopped the run, when the run ended by policy. */
|
|
445
|
+
readonly termination?: TerminationStopRecord;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Event emitted when the coordinator dispatches a delegated sub-run.
|
|
449
|
+
*
|
|
450
|
+
* @remarks
|
|
451
|
+
* Recorded immediately before the child run starts executing. Carries the
|
|
452
|
+
* child's run id, the parent decision id that triggered the dispatch, and the
|
|
453
|
+
* resolved protocol/intent/depth. The `recursive` flag marks the diagnostic
|
|
454
|
+
* case where a coordinator delegates to another coordinator (D-16).
|
|
455
|
+
*
|
|
456
|
+
* The event's `runId` is the PARENT run id, matching the existing trace
|
|
457
|
+
* convention; `parentRunId` duplicates it for explicit cross-reference.
|
|
458
|
+
*/
|
|
459
|
+
export interface SubRunStartedEvent {
|
|
460
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
461
|
+
readonly type: "sub-run-started";
|
|
462
|
+
/** Parent run id; matches the surrounding trace runId. */
|
|
463
|
+
readonly runId: string;
|
|
464
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
465
|
+
readonly parentRunIds?: readonly string[];
|
|
466
|
+
/** ISO-8601 event timestamp. */
|
|
467
|
+
readonly at: string;
|
|
468
|
+
/** Child run id assigned to the dispatched sub-run. */
|
|
469
|
+
readonly childRunId: string;
|
|
470
|
+
/** Parent run id (duplicates `runId` for explicit cross-reference). */
|
|
471
|
+
readonly parentRunId: string;
|
|
472
|
+
/** Replay decision id of the parent decision that triggered this sub-run. */
|
|
473
|
+
readonly parentDecisionId: string;
|
|
474
|
+
/**
|
|
475
|
+
* 0-indexed position of this delegate within the fan-out array of its
|
|
476
|
+
* originating coordinator plan-turn (Phase 3 D-10). Single-delegate turns
|
|
477
|
+
* use `0` for backward compatibility. Together with `parentDecisionId`, this
|
|
478
|
+
* uniquely identifies the delegate within a fan-out.
|
|
479
|
+
*/
|
|
480
|
+
readonly parentDecisionArrayIndex: number;
|
|
481
|
+
/** Coordination protocol the child run will execute. */
|
|
482
|
+
readonly protocol: ProtocolName;
|
|
483
|
+
/** Mission intent passed to the child run. */
|
|
484
|
+
readonly intent: string;
|
|
485
|
+
/** Recursion depth of the child run (1 for first-level sub-run). */
|
|
486
|
+
readonly depth: number;
|
|
487
|
+
/**
|
|
488
|
+
* Diagnostic flag set when a coordinator delegates to another coordinator
|
|
489
|
+
* (parent protocol === "coordinator" and child protocol === "coordinator").
|
|
490
|
+
*/
|
|
491
|
+
readonly recursive?: boolean;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Event emitted when a delegated sub-run completes successfully.
|
|
495
|
+
*
|
|
496
|
+
* @remarks
|
|
497
|
+
* Carries the full {@link RunResult} as `subResult`, including the embedded
|
|
498
|
+
* child {@link Trace}. Replay walks the parent event sequence and recurses on
|
|
499
|
+
* `subResult.trace` to rehydrate sub-run accounting without re-invoking the
|
|
500
|
+
* provider (D-08).
|
|
501
|
+
*/
|
|
502
|
+
export interface SubRunCompletedEvent {
|
|
503
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
504
|
+
readonly type: "sub-run-completed";
|
|
505
|
+
/** Parent run id; matches the surrounding trace runId. */
|
|
506
|
+
readonly runId: string;
|
|
507
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
508
|
+
readonly parentRunIds?: readonly string[];
|
|
509
|
+
/** ISO-8601 event timestamp. */
|
|
510
|
+
readonly at: string;
|
|
511
|
+
/** Child run id that produced this result. */
|
|
512
|
+
readonly childRunId: string;
|
|
513
|
+
/** Parent run id (duplicates `runId` for explicit cross-reference). */
|
|
514
|
+
readonly parentRunId: string;
|
|
515
|
+
/** Replay decision id of the parent decision that triggered the sub-run. */
|
|
516
|
+
readonly parentDecisionId: string;
|
|
517
|
+
/**
|
|
518
|
+
* 0-indexed position of this delegate within the fan-out array of its
|
|
519
|
+
* originating coordinator plan-turn (Phase 3 D-10). Single-delegate turns
|
|
520
|
+
* use `0` for backward compatibility. Together with `parentDecisionId`, this
|
|
521
|
+
* uniquely identifies the delegate within a fan-out.
|
|
522
|
+
*/
|
|
523
|
+
readonly parentDecisionArrayIndex: number;
|
|
524
|
+
/** Full child {@link RunResult}, including the embedded child {@link Trace}. */
|
|
525
|
+
readonly subResult: RunResult;
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Event emitted when a delegated sub-run fails before completion.
|
|
529
|
+
*
|
|
530
|
+
* @remarks
|
|
531
|
+
* Captures a structured `error` plus the partial {@link Trace} accumulated
|
|
532
|
+
* before failure. The same `Trace` shape used by completed runs is preserved
|
|
533
|
+
* — consumers can replay or inspect the partial child events without bespoke
|
|
534
|
+
* deserialization logic.
|
|
535
|
+
*/
|
|
536
|
+
export interface SubRunFailedEvent {
|
|
537
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
538
|
+
readonly type: "sub-run-failed";
|
|
539
|
+
/** Parent run id; matches the surrounding trace runId. */
|
|
540
|
+
readonly runId: string;
|
|
541
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
542
|
+
readonly parentRunIds?: readonly string[];
|
|
543
|
+
/** ISO-8601 event timestamp. */
|
|
544
|
+
readonly at: string;
|
|
545
|
+
/** Child run id that failed. */
|
|
546
|
+
readonly childRunId: string;
|
|
547
|
+
/** Parent run id (duplicates `runId` for explicit cross-reference). */
|
|
548
|
+
readonly parentRunId: string;
|
|
549
|
+
/** Replay decision id of the parent decision that triggered the sub-run. */
|
|
550
|
+
readonly parentDecisionId: string;
|
|
551
|
+
/**
|
|
552
|
+
* 0-indexed position of this delegate within the fan-out array of its
|
|
553
|
+
* originating coordinator plan-turn (Phase 3 D-10). Single-delegate turns
|
|
554
|
+
* use `0` for backward compatibility. Together with `parentDecisionId`, this
|
|
555
|
+
* uniquely identifies the delegate within a fan-out.
|
|
556
|
+
*/
|
|
557
|
+
readonly parentDecisionArrayIndex: number;
|
|
558
|
+
/** Structured failure description. */
|
|
559
|
+
readonly error: {
|
|
560
|
+
/** Stable error code (matches DogpileError code shape). */
|
|
561
|
+
readonly code: string;
|
|
562
|
+
/** Human-readable failure description. */
|
|
563
|
+
readonly message: string;
|
|
564
|
+
/** Provider id when the failure originated in a model call. */
|
|
565
|
+
readonly providerId?: string;
|
|
566
|
+
/** Optional structured detail (e.g., the failed delegate decision payload). */
|
|
567
|
+
readonly detail?: JsonObject;
|
|
568
|
+
};
|
|
569
|
+
/** Partial child {@link Trace} accumulated up to the failure point. */
|
|
570
|
+
readonly partialTrace: Trace;
|
|
571
|
+
/**
|
|
572
|
+
* Cost from provider calls completed before the child threw (BUDGET-03 / D-02).
|
|
573
|
+
*
|
|
574
|
+
* Equals `lastCostBearingEventCost(partialTrace.events) ?? emptyCost()`. The
|
|
575
|
+
* parent rolls this into its own `accounting.cost` so failed children
|
|
576
|
+
* contribute their real wallet spend.
|
|
577
|
+
*/
|
|
578
|
+
readonly partialCost: CostSummary;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Event emitted when the parent's `signal` aborts AFTER a sub-run has already
|
|
582
|
+
* completed successfully but BEFORE the parent advances to its next coordinator
|
|
583
|
+
* turn (BUDGET-01 / D-10).
|
|
584
|
+
*
|
|
585
|
+
* @remarks
|
|
586
|
+
* Provides replay/streaming provenance for "parent gave up after a successful
|
|
587
|
+
* child finished." The marker is observable on `Dogpile.stream()` subscribers
|
|
588
|
+
* before the run errors with `code: "aborted"`. Non-streaming `run()` rejects
|
|
589
|
+
* with the abort error and does NOT expose the marker — `engine.ts` does not
|
|
590
|
+
* attach the parent events array to the rejected error (verified at
|
|
591
|
+
* `engine.ts:230-239`). Streaming-subscriber observability is the contract.
|
|
592
|
+
*/
|
|
593
|
+
export interface SubRunParentAbortedEvent {
|
|
594
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
595
|
+
readonly type: "sub-run-parent-aborted";
|
|
596
|
+
/** Parent run id; matches the surrounding trace runId. */
|
|
597
|
+
readonly runId: string;
|
|
598
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
599
|
+
readonly parentRunIds?: readonly string[];
|
|
600
|
+
/** ISO-8601 event timestamp. */
|
|
601
|
+
readonly at: string;
|
|
602
|
+
/** Most-recent completed child run id whose completion preceded the abort. */
|
|
603
|
+
readonly childRunId: string;
|
|
604
|
+
/** Parent run id (duplicates `runId` for explicit cross-reference). */
|
|
605
|
+
readonly parentRunId: string;
|
|
606
|
+
/** Discriminator (currently always "parent-aborted"; reserved for future variants). */
|
|
607
|
+
readonly reason: "parent-aborted";
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Event emitted when a delegated sub-run's requested `budget.timeoutMs`
|
|
611
|
+
* exceeds the parent's remaining deadline and is therefore clamped to the
|
|
612
|
+
* parent's remaining time (BUDGET-02 / D-12).
|
|
613
|
+
*
|
|
614
|
+
* @remarks
|
|
615
|
+
* Emitted on the parent trace BEFORE `sub-run-started`. When the requested
|
|
616
|
+
* decision-level timeout fits within the parent's remaining deadline, the
|
|
617
|
+
* event is NOT emitted (zero-overhead happy path). The parent's deadline is
|
|
618
|
+
* a hard ceiling for the whole tree, so any decision-level override that
|
|
619
|
+
* exceeds it is silently clamped rather than throwing — recording the
|
|
620
|
+
* requested-vs-clamped pair on the trace preserves provenance for replay.
|
|
621
|
+
*/
|
|
622
|
+
export interface SubRunBudgetClampedEvent {
|
|
623
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
624
|
+
readonly type: "sub-run-budget-clamped";
|
|
625
|
+
/** Parent run id; matches the surrounding trace runId. */
|
|
626
|
+
readonly runId: string;
|
|
627
|
+
/** Root-first ancestry chain when bubbled through a parent stream. */
|
|
628
|
+
readonly parentRunIds?: readonly string[];
|
|
629
|
+
/** ISO-8601 event timestamp. */
|
|
630
|
+
readonly at: string;
|
|
631
|
+
/** Child run id whose budget was clamped. */
|
|
632
|
+
readonly childRunId: string;
|
|
633
|
+
/** Parent run id (duplicates `runId` for explicit cross-reference). */
|
|
634
|
+
readonly parentRunId: string;
|
|
635
|
+
/** Replay decision id of the parent decision that triggered the sub-run. */
|
|
636
|
+
readonly parentDecisionId: string;
|
|
637
|
+
/** The decision's originally requested `budget.timeoutMs` value (milliseconds). */
|
|
638
|
+
readonly requestedTimeoutMs: number;
|
|
639
|
+
/** The clamped child timeout actually applied (parent's remaining deadline, in milliseconds). */
|
|
640
|
+
readonly clampedTimeoutMs: number;
|
|
641
|
+
/** Discriminator for the clamp cause (currently always "exceeded-parent-remaining"). */
|
|
642
|
+
readonly reason: "exceeded-parent-remaining";
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Event emitted when a delegated sub-run is enqueued because the
|
|
646
|
+
* coordinator's effective `maxConcurrentChildren` budget is fully in flight
|
|
647
|
+
* (Phase 3 D-07). Emitted ONLY when the slot is not immediately free —
|
|
648
|
+
* no-pressure runs do NOT emit this event.
|
|
649
|
+
*
|
|
650
|
+
* Three-event timeline under pressure: sub-run-queued → sub-run-started →
|
|
651
|
+
* sub-run-completed (or sub-run-failed). Without pressure: sub-run-started
|
|
652
|
+
* → completion (no queued event).
|
|
653
|
+
*/
|
|
654
|
+
export interface SubRunQueuedEvent {
|
|
655
|
+
readonly type: "sub-run-queued";
|
|
656
|
+
readonly runId: string;
|
|
657
|
+
readonly parentRunIds?: readonly string[];
|
|
658
|
+
readonly at: string;
|
|
659
|
+
readonly childRunId: string;
|
|
660
|
+
readonly parentRunId: string;
|
|
661
|
+
readonly parentDecisionId: string;
|
|
662
|
+
readonly parentDecisionArrayIndex: number;
|
|
663
|
+
readonly protocol: ProtocolName;
|
|
664
|
+
readonly intent: string;
|
|
665
|
+
readonly depth: number;
|
|
666
|
+
readonly queuePosition: number;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Event emitted ONCE per run when the runtime detects a `"local"` provider
|
|
670
|
+
* in the coordinator's active tree and clamps `maxConcurrentChildren` to 1
|
|
671
|
+
* (Phase 3 CONCURRENCY-02 / D-12). Emitted at the FIRST delegate dispatch
|
|
672
|
+
* where the local-provider check trips. Subsequent dispatches in the same
|
|
673
|
+
* run do NOT re-emit. Runs with no delegates, or runs with delegates but
|
|
674
|
+
* no local provider, never emit this event.
|
|
675
|
+
*
|
|
676
|
+
* The clamp is silent (no throw, no console output) per D-13 — this event
|
|
677
|
+
* IS the warning surface; subscribers can react via the engine's `emit`
|
|
678
|
+
* callback.
|
|
679
|
+
*/
|
|
680
|
+
export interface SubRunConcurrencyClampedEvent {
|
|
681
|
+
readonly type: "sub-run-concurrency-clamped";
|
|
682
|
+
readonly runId: string;
|
|
683
|
+
readonly parentRunIds?: readonly string[];
|
|
684
|
+
readonly at: string;
|
|
685
|
+
/** The pre-clamp effective max that would have applied (engine/run/decision min). */
|
|
686
|
+
readonly requestedMax: number;
|
|
687
|
+
/** Always 1 — locality-clamp is a fixed cap. */
|
|
688
|
+
readonly effectiveMax: 1;
|
|
689
|
+
readonly reason: "local-provider-detected";
|
|
690
|
+
/** Stable id of the FIRST local provider found during the active-tree walk. */
|
|
691
|
+
readonly providerId: string;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Successful coordination event emitted by Dogpile and persisted in traces.
|
|
695
|
+
*
|
|
696
|
+
* @remarks
|
|
697
|
+
* `RunEvent` is the discriminated union stored in {@link Trace.events} and
|
|
698
|
+
* used by low-level protocol emit callbacks. Switch on `type` to handle each
|
|
699
|
+
* coordination moment exhaustively:
|
|
700
|
+
*
|
|
701
|
+
* - `role-assignment`: participant/role roster was established.
|
|
702
|
+
* - `model-request`: one provider-neutral model request was started.
|
|
703
|
+
* - `model-response`: one provider-neutral model response completed.
|
|
704
|
+
* - `model-output-chunk`: one streaming model text delta arrived.
|
|
705
|
+
* - `tool-call`: one runtime tool invocation was started.
|
|
706
|
+
* - `tool-result`: one runtime tool invocation completed.
|
|
707
|
+
* - `agent-turn`: one agent completed a prompt/response turn.
|
|
708
|
+
* - `broadcast`: a broadcast round gathered independent contributions.
|
|
709
|
+
* - `sub-run-started`: a delegated sub-run was dispatched.
|
|
710
|
+
* - `sub-run-completed`: a delegated sub-run completed and embedded its full result.
|
|
711
|
+
* - `sub-run-failed`: a delegated sub-run failed before completion.
|
|
712
|
+
* - `sub-run-queued`: a delegated sub-run waited for a concurrency slot.
|
|
713
|
+
* - `sub-run-concurrency-clamped`: a local provider forced child concurrency to 1.
|
|
714
|
+
* - `budget-stop`: a configured budget cap halted further model turns.
|
|
715
|
+
* - `final`: the run completed and produced the final output.
|
|
716
|
+
*
|
|
717
|
+
* Every variant is JSON-serializable and includes `runId` plus an ISO-8601
|
|
718
|
+
* `at` timestamp so callers can persist, render, or replay the event log
|
|
719
|
+
* without SDK-owned storage.
|
|
720
|
+
*
|
|
721
|
+
* @example
|
|
722
|
+
* ```ts
|
|
723
|
+
* for await (const event of Dogpile.stream(options)) {
|
|
724
|
+
* switch (event.type) {
|
|
725
|
+
* case "agent-turn":
|
|
726
|
+
* console.log(event.agentId, event.output);
|
|
727
|
+
* break;
|
|
728
|
+
* case "final":
|
|
729
|
+
* console.log(event.output);
|
|
730
|
+
* break;
|
|
731
|
+
* }
|
|
732
|
+
* }
|
|
733
|
+
* ```
|
|
734
|
+
*/
|
|
735
|
+
export type RunEvent = RoleAssignmentEvent | ModelRequestEvent | ModelResponseEvent | ModelOutputChunkEvent | ToolCallEvent | ToolResultEvent | TurnEvent | BroadcastEvent | SubRunStartedEvent | SubRunCompletedEvent | SubRunFailedEvent | SubRunParentAbortedEvent | SubRunBudgetClampedEvent | SubRunQueuedEvent | SubRunConcurrencyClampedEvent | BudgetStopEvent | FinalEvent;
|
|
736
|
+
/**
|
|
737
|
+
* Model activity events yielded by `stream()` and persisted in traces when a
|
|
738
|
+
* protocol exposes provider-call boundaries.
|
|
739
|
+
*/
|
|
740
|
+
export type ModelActivityEvent = ModelRequestEvent | ModelResponseEvent | ModelOutputChunkEvent;
|
|
741
|
+
/**
|
|
742
|
+
* Tool activity events yielded by `stream()` and persisted in traces when a
|
|
743
|
+
* protocol or caller-owned adapter invokes runtime tools.
|
|
744
|
+
*/
|
|
745
|
+
export type ToolActivityEvent = ToolCallEvent | ToolResultEvent;
|
|
746
|
+
/**
|
|
747
|
+
* Lifecycle event yielded by `stream()`.
|
|
748
|
+
*
|
|
749
|
+
* These events describe workflow coordination state rather than model text.
|
|
750
|
+
* Role assignment establishes the participant roster, `budget-stop` records a
|
|
751
|
+
* lifecycle halt before the terminal completion event, and the `sub-run-*`
|
|
752
|
+
* variants surface delegated child-run dispatch boundaries.
|
|
753
|
+
*/
|
|
754
|
+
export type StreamLifecycleEvent = RoleAssignmentEvent | BudgetStopEvent | SubRunStartedEvent | SubRunCompletedEvent | SubRunFailedEvent | SubRunParentAbortedEvent | SubRunBudgetClampedEvent | SubRunQueuedEvent | SubRunConcurrencyClampedEvent | AbortedEvent;
|
|
755
|
+
/**
|
|
756
|
+
* Lifecycle event yielded by `stream()` when a run is aborted.
|
|
757
|
+
*/
|
|
758
|
+
export interface AbortedEvent {
|
|
759
|
+
readonly type: "aborted";
|
|
760
|
+
readonly runId: string;
|
|
761
|
+
readonly at: string;
|
|
762
|
+
readonly reason: "parent-aborted" | "timeout";
|
|
763
|
+
readonly detail?: JsonObject;
|
|
764
|
+
readonly parentRunIds?: readonly string[];
|
|
765
|
+
}
|
|
766
|
+
/**
|
|
767
|
+
* Output event yielded by `stream()`.
|
|
768
|
+
*
|
|
769
|
+
* These events carry generated agent output or grouped round output while a
|
|
770
|
+
* workflow is still running.
|
|
771
|
+
*/
|
|
772
|
+
export type StreamOutputEvent = ModelActivityEvent | ToolActivityEvent | TurnEvent | BroadcastEvent;
|
|
773
|
+
/**
|
|
774
|
+
* Error event yielded by `stream()` when execution rejects.
|
|
775
|
+
*
|
|
776
|
+
* @remarks
|
|
777
|
+
* Stream errors are emitted before {@link StreamHandle.result} rejects so UIs
|
|
778
|
+
* and log collectors can record a terminal failure without wrapping the result
|
|
779
|
+
* promise. The error payload is JSON-serializable and intentionally omits
|
|
780
|
+
* runtime-specific values such as `Error.stack`.
|
|
781
|
+
*/
|
|
782
|
+
export interface StreamErrorEvent {
|
|
783
|
+
/** Discriminant for stream event handling. */
|
|
784
|
+
readonly type: "error";
|
|
785
|
+
/** Stable run id when known; empty when failure happened before protocol startup. */
|
|
786
|
+
readonly runId: string;
|
|
787
|
+
/** ISO-8601 event timestamp. */
|
|
788
|
+
readonly at: string;
|
|
789
|
+
/** Error name when available. */
|
|
790
|
+
readonly name: string;
|
|
791
|
+
/** Human-readable error message. */
|
|
792
|
+
readonly message: string;
|
|
793
|
+
/** Optional serializable diagnostics supplied by the SDK. */
|
|
794
|
+
readonly detail?: JsonObject;
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Completion event yielded by `stream()` after successful execution.
|
|
798
|
+
*/
|
|
799
|
+
export type StreamCompletionEvent = FinalEvent;
|
|
800
|
+
/**
|
|
801
|
+
* Public streaming event union returned by `stream()`.
|
|
802
|
+
*
|
|
803
|
+
* @remarks
|
|
804
|
+
* The union is grouped into lifecycle, output, error, and completion families:
|
|
805
|
+
*
|
|
806
|
+
* - lifecycle: {@link StreamLifecycleEvent}
|
|
807
|
+
* - output: {@link StreamOutputEvent}
|
|
808
|
+
* - error: {@link StreamErrorEvent}
|
|
809
|
+
* - completion: {@link StreamCompletionEvent}
|
|
810
|
+
*
|
|
811
|
+
* Successful stream events are also persisted as {@link RunEvent} values in the
|
|
812
|
+
* completed trace. `error` is stream-only because a failed run has no completed
|
|
813
|
+
* {@link RunResult} trace to return.
|
|
814
|
+
*/
|
|
815
|
+
export type StreamEvent = StreamLifecycleEvent | StreamOutputEvent | StreamErrorEvent | StreamCompletionEvent;
|
|
816
|
+
//# sourceMappingURL=events.d.ts.map
|