@dogpile/sdk 0.3.0 → 0.3.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 +9 -0
- package/dist/browser/index.js +784 -562
- package/dist/browser/index.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.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/coordinator.d.ts.map +1 -1
- package/dist/runtime/coordinator.js +1 -13
- package/dist/runtime/coordinator.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 +1 -10
- 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/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 +495 -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 +169 -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 +6 -935
- package/dist/types.d.ts.map +1 -1
- package/package.json +27 -1
- package/src/index.ts +4 -0
- package/src/runtime/broadcast.ts +1 -16
- package/src/runtime/coordinator.ts +1 -16
- 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 +1 -12
- 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/types/benchmark.ts +300 -0
- package/src/types/events.ts +544 -0
- package/src/types/replay.ts +201 -0
- package/src/types.ts +104 -994
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BudgetStopReason,
|
|
3
|
+
CostSummary,
|
|
4
|
+
JsonObject,
|
|
5
|
+
JsonValue,
|
|
6
|
+
ModelFinishReason,
|
|
7
|
+
ModelOutputChunk,
|
|
8
|
+
ModelRequest,
|
|
9
|
+
ModelResponse,
|
|
10
|
+
NormalizedQualityScore,
|
|
11
|
+
Protocol,
|
|
12
|
+
RunEvaluation,
|
|
13
|
+
RuntimeToolIdentity,
|
|
14
|
+
RuntimeToolPermission,
|
|
15
|
+
RuntimeToolResult,
|
|
16
|
+
TerminationStopRecord
|
|
17
|
+
} from "../types.js";
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Event emitted when a protocol assigns or records an agent role.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* This event normally appears near the beginning of a run and establishes the
|
|
25
|
+
* `agentId`/`role` pair that later turn and transcript records refer to. A
|
|
26
|
+
* renderer can use it to build the participant roster before model output
|
|
27
|
+
* starts streaming.
|
|
28
|
+
*
|
|
29
|
+
* Payload shape:
|
|
30
|
+
*
|
|
31
|
+
* - `type`: always `role-assignment`.
|
|
32
|
+
* - `runId`: stable id shared by every event and trace object for the run.
|
|
33
|
+
* - `at`: ISO-8601 timestamp for when the assignment was emitted.
|
|
34
|
+
* - `agentId`: stable agent id used in events, trace, and transcript entries.
|
|
35
|
+
* - `role`: model-visible role or perspective assigned to that agent.
|
|
36
|
+
*/
|
|
37
|
+
export interface RoleAssignmentEvent {
|
|
38
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
39
|
+
readonly type: "role-assignment";
|
|
40
|
+
/** Stable run id shared by all events in one workflow. */
|
|
41
|
+
readonly runId: string;
|
|
42
|
+
/** ISO-8601 event timestamp. */
|
|
43
|
+
readonly at: string;
|
|
44
|
+
/** Agent receiving the role assignment. */
|
|
45
|
+
readonly agentId: string;
|
|
46
|
+
/** Role assigned to the agent. */
|
|
47
|
+
readonly role: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Event emitted when Dogpile is about to ask the configured model provider for
|
|
52
|
+
* one protocol-managed response.
|
|
53
|
+
*
|
|
54
|
+
* @remarks
|
|
55
|
+
* This event is the request-side model activity counterpart to
|
|
56
|
+
* {@link ModelResponseEvent}. Protocol implementations may omit it when they
|
|
57
|
+
* only expose completed turns, but adapters and researcher harnesses can emit
|
|
58
|
+
* it to make provider calls visible in the same streaming event log as agent
|
|
59
|
+
* turns and final output.
|
|
60
|
+
*/
|
|
61
|
+
export interface ModelRequestEvent {
|
|
62
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
63
|
+
readonly type: "model-request";
|
|
64
|
+
/** Stable run id shared by all events in one workflow. */
|
|
65
|
+
readonly runId: string;
|
|
66
|
+
/** ISO-8601 event timestamp. */
|
|
67
|
+
readonly at: string;
|
|
68
|
+
/** Stable provider call id within the run. */
|
|
69
|
+
readonly callId: string;
|
|
70
|
+
/** Configured model provider id receiving the request. */
|
|
71
|
+
readonly providerId: string;
|
|
72
|
+
/** Agent requesting the model call. */
|
|
73
|
+
readonly agentId: string;
|
|
74
|
+
/** Agent role for the active model call. */
|
|
75
|
+
readonly role: string;
|
|
76
|
+
/** Provider-neutral request handed to the model adapter. */
|
|
77
|
+
readonly request: ModelRequest;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Event emitted after the configured model provider returns one response.
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* This event records provider-level model activity without forcing callers to
|
|
85
|
+
* infer it from the higher-level {@link TurnEvent}. The response is the same
|
|
86
|
+
* provider-neutral shape captured in replay traces, so it remains portable and
|
|
87
|
+
* JSON-serializable across Node LTS, Bun, and browser ESM runtimes.
|
|
88
|
+
*/
|
|
89
|
+
export interface ModelResponseEvent {
|
|
90
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
91
|
+
readonly type: "model-response";
|
|
92
|
+
/** Stable run id shared by all events in one workflow. */
|
|
93
|
+
readonly runId: string;
|
|
94
|
+
/** ISO-8601 event timestamp. */
|
|
95
|
+
readonly at: string;
|
|
96
|
+
/** Stable provider call id within the run. */
|
|
97
|
+
readonly callId: string;
|
|
98
|
+
/** Configured model provider id that produced the response. */
|
|
99
|
+
readonly providerId: string;
|
|
100
|
+
/** Agent that requested the model call. */
|
|
101
|
+
readonly agentId: string;
|
|
102
|
+
/** Agent role for the completed model call. */
|
|
103
|
+
readonly role: string;
|
|
104
|
+
/** Provider-neutral response returned by the model adapter. */
|
|
105
|
+
readonly response: ModelResponse;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Event emitted while a model turn is still generating text.
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* `model-output-chunk` lets streaming callers render provider output before
|
|
113
|
+
* the protocol has enough information to commit the completed `agent-turn`
|
|
114
|
+
* transcript entry. It is emitted only when the configured model provider
|
|
115
|
+
* implements {@link ConfiguredModelProvider.stream}; non-streaming providers
|
|
116
|
+
* continue to produce the existing role/turn/final event sequence.
|
|
117
|
+
*
|
|
118
|
+
* Payload shape:
|
|
119
|
+
*
|
|
120
|
+
* - `type`: always `model-output-chunk`.
|
|
121
|
+
* - `runId`: stable id shared by every event and trace object for the run.
|
|
122
|
+
* - `at`: ISO-8601 timestamp for when the chunk was observed.
|
|
123
|
+
* - `agentId` and `role`: identify the active generating agent.
|
|
124
|
+
* - `input`: prompt text visible to that agent for this turn.
|
|
125
|
+
* - `chunkIndex`: zero-based chunk index within this model turn.
|
|
126
|
+
* - `text`: text delta from the provider.
|
|
127
|
+
* - `output`: accumulated output for this turn after applying the chunk.
|
|
128
|
+
*/
|
|
129
|
+
export interface ModelOutputChunkEvent {
|
|
130
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
131
|
+
readonly type: "model-output-chunk";
|
|
132
|
+
/** Stable run id shared by all events in one workflow. */
|
|
133
|
+
readonly runId: string;
|
|
134
|
+
/** ISO-8601 event timestamp. */
|
|
135
|
+
readonly at: string;
|
|
136
|
+
/** Agent currently producing output. */
|
|
137
|
+
readonly agentId: string;
|
|
138
|
+
/** Agent role for the active turn. */
|
|
139
|
+
readonly role: string;
|
|
140
|
+
/** Prompt/input visible to the agent for this turn. */
|
|
141
|
+
readonly input: string;
|
|
142
|
+
/** Zero-based chunk index within the active model turn. */
|
|
143
|
+
readonly chunkIndex: number;
|
|
144
|
+
/** Text delta produced by the model provider. */
|
|
145
|
+
readonly text: string;
|
|
146
|
+
/** Accumulated output for this turn after applying this chunk. */
|
|
147
|
+
readonly output: string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Event emitted when a runtime tool is invoked by protocol or model policy.
|
|
152
|
+
*
|
|
153
|
+
* @remarks
|
|
154
|
+
* Tools are caller-owned escape hatches. This request-side event keeps tool
|
|
155
|
+
* invocation observable without making Dogpile core depend on Node-only
|
|
156
|
+
* capabilities, a storage layer, or a provider-specific function-call shape.
|
|
157
|
+
*/
|
|
158
|
+
export interface ToolCallEvent {
|
|
159
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
160
|
+
readonly type: "tool-call";
|
|
161
|
+
/** Stable run id shared by all events in one workflow. */
|
|
162
|
+
readonly runId: string;
|
|
163
|
+
/** ISO-8601 event timestamp. */
|
|
164
|
+
readonly at: string;
|
|
165
|
+
/** Stable tool call id within the run. */
|
|
166
|
+
readonly toolCallId: string;
|
|
167
|
+
/** Tool identity selected for execution. */
|
|
168
|
+
readonly tool: RuntimeToolIdentity;
|
|
169
|
+
/** JSON-serializable tool input. */
|
|
170
|
+
readonly input: JsonObject;
|
|
171
|
+
/** Agent that requested the tool, when agent-scoped. */
|
|
172
|
+
readonly agentId?: string;
|
|
173
|
+
/** Agent role that requested the tool, when available. */
|
|
174
|
+
readonly role?: string;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Event emitted after a runtime tool returns a normalized result.
|
|
179
|
+
*
|
|
180
|
+
* @remarks
|
|
181
|
+
* Tool failures are data at the public boundary. The result payload uses the
|
|
182
|
+
* same discriminated union as runtime tool adapters, allowing log consumers to
|
|
183
|
+
* render successful outputs and normalized errors exhaustively.
|
|
184
|
+
*/
|
|
185
|
+
export interface ToolResultEvent {
|
|
186
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
187
|
+
readonly type: "tool-result";
|
|
188
|
+
/** Stable run id shared by all events in one workflow. */
|
|
189
|
+
readonly runId: string;
|
|
190
|
+
/** ISO-8601 event timestamp. */
|
|
191
|
+
readonly at: string;
|
|
192
|
+
/** Stable tool call id within the run. */
|
|
193
|
+
readonly toolCallId: string;
|
|
194
|
+
/** Tool identity that produced the result. */
|
|
195
|
+
readonly tool: RuntimeToolIdentity;
|
|
196
|
+
/** Normalized JSON-serializable tool result. */
|
|
197
|
+
readonly result: RuntimeToolResult;
|
|
198
|
+
/** Agent that requested the tool, when agent-scoped. */
|
|
199
|
+
readonly agentId?: string;
|
|
200
|
+
/** Agent role that requested the tool, when available. */
|
|
201
|
+
readonly role?: string;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Provider-normalized participation decision parsed from paper-style agent output.
|
|
206
|
+
*
|
|
207
|
+
* @remarks
|
|
208
|
+
* Dogpile preserves the raw model text on transcript entries and events. When
|
|
209
|
+
* a model emits the labeled fields `role_selected`, `participation`,
|
|
210
|
+
* `rationale`, and `contribution`, protocols also attach this structured
|
|
211
|
+
* metadata so reproduction harnesses can distinguish contribution from
|
|
212
|
+
* voluntary abstention without reparsing raw text.
|
|
213
|
+
*/
|
|
214
|
+
export interface AgentDecision {
|
|
215
|
+
/** Task-specific role selected by the agent for this turn. */
|
|
216
|
+
readonly selectedRole: string;
|
|
217
|
+
/** Whether the agent contributed or voluntarily abstained. */
|
|
218
|
+
readonly participation: AgentParticipation;
|
|
219
|
+
/** Agent-provided rationale for the selected role and participation choice. */
|
|
220
|
+
readonly rationale: string;
|
|
221
|
+
/** Agent-provided contribution text, or abstention explanation. */
|
|
222
|
+
readonly contribution: string;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Agent participation state for a paper-style turn decision.
|
|
227
|
+
*/
|
|
228
|
+
export type AgentParticipation = "contribute" | "abstain";
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Event emitted after one agent contributes a model turn.
|
|
232
|
+
*
|
|
233
|
+
* @remarks
|
|
234
|
+
* `agent-turn` is the primary streaming payload for sequential, coordinator,
|
|
235
|
+
* shared-state, and broadcast executions. It captures the exact prompt/input
|
|
236
|
+
* Dogpile supplied to the agent, the text returned by the model provider, and
|
|
237
|
+
* the cumulative cost after applying that response.
|
|
238
|
+
*
|
|
239
|
+
* The corresponding durable transcript record contains the same
|
|
240
|
+
* `agentId`/`role`/`input`/`output` contribution without event timing or cost
|
|
241
|
+
* fields. Use this event for live progress UIs and the transcript for replay
|
|
242
|
+
* or downstream application logic.
|
|
243
|
+
*
|
|
244
|
+
* Payload shape:
|
|
245
|
+
*
|
|
246
|
+
* - `type`: always `agent-turn`.
|
|
247
|
+
* - `runId`: stable id shared by every event and trace object for the run.
|
|
248
|
+
* - `at`: ISO-8601 timestamp for when the turn completed.
|
|
249
|
+
* - `agentId` and `role`: identify the contributing agent.
|
|
250
|
+
* - `input`: prompt text visible to that agent for this turn.
|
|
251
|
+
* - `output`: generated model text produced by the agent.
|
|
252
|
+
* - `cost`: cumulative token and spend accounting after this turn.
|
|
253
|
+
*/
|
|
254
|
+
export interface TurnEvent {
|
|
255
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
256
|
+
readonly type: "agent-turn";
|
|
257
|
+
/** Stable run id shared by all events in one workflow. */
|
|
258
|
+
readonly runId: string;
|
|
259
|
+
/** ISO-8601 event timestamp. */
|
|
260
|
+
readonly at: string;
|
|
261
|
+
/** Agent that produced this turn. */
|
|
262
|
+
readonly agentId: string;
|
|
263
|
+
/** Agent role for this turn. */
|
|
264
|
+
readonly role: string;
|
|
265
|
+
/** Prompt/input visible to the agent for this turn. */
|
|
266
|
+
readonly input: string;
|
|
267
|
+
/** Model output produced by the agent. */
|
|
268
|
+
readonly output: string;
|
|
269
|
+
/** Optional structured role/participation decision parsed from model output. */
|
|
270
|
+
readonly decision?: AgentDecision;
|
|
271
|
+
/** Cumulative cost after this turn. */
|
|
272
|
+
readonly cost: CostSummary;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* One independent contribution captured by a broadcast round event.
|
|
277
|
+
*
|
|
278
|
+
* @remarks
|
|
279
|
+
* Broadcast protocols collect one contribution per participating agent before
|
|
280
|
+
* synthesis. The contribution payload is intentionally smaller than
|
|
281
|
+
* {@link TurnEvent}: it is a round-level summary of model outputs, while the
|
|
282
|
+
* complete prompt/output pair for each agent is still available as individual
|
|
283
|
+
* `agent-turn` events and {@link TranscriptEntry} records.
|
|
284
|
+
*
|
|
285
|
+
* Payload shape:
|
|
286
|
+
*
|
|
287
|
+
* - `agentId`: stable id of the contributing agent.
|
|
288
|
+
* - `role`: model-visible role or perspective used for that contribution.
|
|
289
|
+
* - `output`: generated text contributed independently for the round.
|
|
290
|
+
*/
|
|
291
|
+
export interface BroadcastContribution {
|
|
292
|
+
/** Agent that produced the broadcast contribution. */
|
|
293
|
+
readonly agentId: string;
|
|
294
|
+
/** Agent role for the contribution. */
|
|
295
|
+
readonly role: string;
|
|
296
|
+
/** Independent model output produced for the shared mission. */
|
|
297
|
+
readonly output: string;
|
|
298
|
+
/** Optional structured role/participation decision parsed from model output. */
|
|
299
|
+
readonly decision?: AgentDecision;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Event emitted after agents broadcast independent contributions for a round.
|
|
304
|
+
*
|
|
305
|
+
* @remarks
|
|
306
|
+
* A `broadcast` event marks the coordination moment where independently
|
|
307
|
+
* generated agent outputs are gathered for a shared round. It does not replace
|
|
308
|
+
* per-agent `agent-turn` events; instead, it groups their outputs by round so
|
|
309
|
+
* observers can render the broadcast barrier and replay the paper protocol's
|
|
310
|
+
* independent-contribution step.
|
|
311
|
+
*
|
|
312
|
+
* Payload shape:
|
|
313
|
+
*
|
|
314
|
+
* - `type`: always `broadcast`.
|
|
315
|
+
* - `runId`: stable id shared by every event and trace object for the run.
|
|
316
|
+
* - `at`: ISO-8601 timestamp for when the round finished.
|
|
317
|
+
* - `round`: one-based broadcast round number.
|
|
318
|
+
* - `contributions`: independent outputs collected for this round.
|
|
319
|
+
* - `cost`: cumulative token and spend accounting after the round.
|
|
320
|
+
*/
|
|
321
|
+
export interface BroadcastEvent {
|
|
322
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
323
|
+
readonly type: "broadcast";
|
|
324
|
+
/** Stable run id shared by all events in one workflow. */
|
|
325
|
+
readonly runId: string;
|
|
326
|
+
/** ISO-8601 event timestamp. */
|
|
327
|
+
readonly at: string;
|
|
328
|
+
/** One-based broadcast round number. */
|
|
329
|
+
readonly round: number;
|
|
330
|
+
/** Independent contributions collected in this broadcast round. */
|
|
331
|
+
readonly contributions: readonly BroadcastContribution[];
|
|
332
|
+
/** Cumulative cost after this broadcast round. */
|
|
333
|
+
readonly cost: CostSummary;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Event emitted when a workflow halts because a configured budget cap fired.
|
|
338
|
+
*
|
|
339
|
+
* @remarks
|
|
340
|
+
* `budget-stop` records the normalized cap class that stopped execution before
|
|
341
|
+
* the final event closes the run. The detail object is JSON-serializable so
|
|
342
|
+
* callers can persist or replay the exact cap, observed value, and limit.
|
|
343
|
+
*/
|
|
344
|
+
export interface BudgetStopEvent {
|
|
345
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
346
|
+
readonly type: "budget-stop";
|
|
347
|
+
/** Stable run id shared by all events in one workflow. */
|
|
348
|
+
readonly runId: string;
|
|
349
|
+
/** ISO-8601 event timestamp. */
|
|
350
|
+
readonly at: string;
|
|
351
|
+
/** Normalized machine-readable budget stop reason. */
|
|
352
|
+
readonly reason: BudgetStopReason;
|
|
353
|
+
/** Total cost at the stop point. */
|
|
354
|
+
readonly cost: CostSummary;
|
|
355
|
+
/** Completed model-turn iterations at the stop point. */
|
|
356
|
+
readonly iteration: number;
|
|
357
|
+
/** Elapsed runtime in milliseconds at the stop point. */
|
|
358
|
+
readonly elapsedMs: number;
|
|
359
|
+
/** Serializable cap diagnostics. */
|
|
360
|
+
readonly detail: JsonObject;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Link from a terminal event to the completed trace transcript.
|
|
365
|
+
*
|
|
366
|
+
* @remarks
|
|
367
|
+
* Final events are emitted before callers await {@link StreamHandle.result},
|
|
368
|
+
* so this compact link tells streaming UIs exactly which transcript artifact
|
|
369
|
+
* the terminal output closes over without duplicating every transcript entry
|
|
370
|
+
* inside the event log.
|
|
371
|
+
*/
|
|
372
|
+
export interface TranscriptLink {
|
|
373
|
+
/** Discriminant for future transcript link variants. */
|
|
374
|
+
readonly kind: "trace-transcript";
|
|
375
|
+
/** Number of transcript entries included in the completed trace. */
|
|
376
|
+
readonly entryCount: number;
|
|
377
|
+
/** Zero-based index of the last transcript entry, or `null` for empty runs. */
|
|
378
|
+
readonly lastEntryIndex: number | null;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Event emitted when a workflow produces its final output.
|
|
383
|
+
*
|
|
384
|
+
* @remarks
|
|
385
|
+
* `final` is the terminal streaming event for a successful run. Its `output`
|
|
386
|
+
* value matches {@link RunResult.output}, and its `cost` value matches the
|
|
387
|
+
* final aggregate cost returned on the result. Its `transcript` link points to
|
|
388
|
+
* the completed {@link Trace.transcript} entries that produced the terminal
|
|
389
|
+
* output.
|
|
390
|
+
*
|
|
391
|
+
* Payload shape:
|
|
392
|
+
*
|
|
393
|
+
* - `type`: always `final`.
|
|
394
|
+
* - `runId`: stable id shared by every event and trace object for the run.
|
|
395
|
+
* - `at`: ISO-8601 timestamp for when final synthesis completed.
|
|
396
|
+
* - `output`: final synthesized answer returned to the caller.
|
|
397
|
+
* - `cost`: total token and spend accounting for the run.
|
|
398
|
+
* - `transcript`: compact link to the completed trace transcript.
|
|
399
|
+
*/
|
|
400
|
+
export interface FinalEvent {
|
|
401
|
+
/** Discriminant for event rendering and exhaustive switches. */
|
|
402
|
+
readonly type: "final";
|
|
403
|
+
/** Stable run id shared by all events in one workflow. */
|
|
404
|
+
readonly runId: string;
|
|
405
|
+
/** ISO-8601 event timestamp. */
|
|
406
|
+
readonly at: string;
|
|
407
|
+
/** Final synthesized answer returned as `RunResult.output`. */
|
|
408
|
+
readonly output: string;
|
|
409
|
+
/** Total cost at completion. */
|
|
410
|
+
readonly cost: CostSummary;
|
|
411
|
+
/** Link to the completed trace transcript. */
|
|
412
|
+
readonly transcript: TranscriptLink;
|
|
413
|
+
/** Optional normalized quality score supplied by a caller-owned evaluator. */
|
|
414
|
+
readonly quality?: NormalizedQualityScore;
|
|
415
|
+
/** Optional serializable evaluation payload supplied by a caller-owned evaluator. */
|
|
416
|
+
readonly evaluation?: RunEvaluation;
|
|
417
|
+
/** Termination condition that stopped the run, when the run ended by policy. */
|
|
418
|
+
readonly termination?: TerminationStopRecord;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Successful coordination event emitted by Dogpile and persisted in traces.
|
|
423
|
+
*
|
|
424
|
+
* @remarks
|
|
425
|
+
* `RunEvent` is the discriminated union stored in {@link Trace.events} and
|
|
426
|
+
* used by low-level protocol emit callbacks. Switch on `type` to handle each
|
|
427
|
+
* coordination moment exhaustively:
|
|
428
|
+
*
|
|
429
|
+
* - `role-assignment`: participant/role roster was established.
|
|
430
|
+
* - `model-request`: one provider-neutral model request was started.
|
|
431
|
+
* - `model-response`: one provider-neutral model response completed.
|
|
432
|
+
* - `model-output-chunk`: one streaming model text delta arrived.
|
|
433
|
+
* - `tool-call`: one runtime tool invocation was started.
|
|
434
|
+
* - `tool-result`: one runtime tool invocation completed.
|
|
435
|
+
* - `agent-turn`: one agent completed a prompt/response turn.
|
|
436
|
+
* - `broadcast`: a broadcast round gathered independent contributions.
|
|
437
|
+
* - `budget-stop`: a configured budget cap halted further model turns.
|
|
438
|
+
* - `final`: the run completed and produced the final output.
|
|
439
|
+
*
|
|
440
|
+
* Every variant is JSON-serializable and includes `runId` plus an ISO-8601
|
|
441
|
+
* `at` timestamp so callers can persist, render, or replay the event log
|
|
442
|
+
* without SDK-owned storage.
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```ts
|
|
446
|
+
* for await (const event of Dogpile.stream(options)) {
|
|
447
|
+
* switch (event.type) {
|
|
448
|
+
* case "agent-turn":
|
|
449
|
+
* console.log(event.agentId, event.output);
|
|
450
|
+
* break;
|
|
451
|
+
* case "final":
|
|
452
|
+
* console.log(event.output);
|
|
453
|
+
* break;
|
|
454
|
+
* }
|
|
455
|
+
* }
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
458
|
+
export type RunEvent =
|
|
459
|
+
| RoleAssignmentEvent
|
|
460
|
+
| ModelRequestEvent
|
|
461
|
+
| ModelResponseEvent
|
|
462
|
+
| ModelOutputChunkEvent
|
|
463
|
+
| ToolCallEvent
|
|
464
|
+
| ToolResultEvent
|
|
465
|
+
| TurnEvent
|
|
466
|
+
| BroadcastEvent
|
|
467
|
+
| BudgetStopEvent
|
|
468
|
+
| FinalEvent;
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Model activity events yielded by `stream()` and persisted in traces when a
|
|
472
|
+
* protocol exposes provider-call boundaries.
|
|
473
|
+
*/
|
|
474
|
+
export type ModelActivityEvent = ModelRequestEvent | ModelResponseEvent | ModelOutputChunkEvent;
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Tool activity events yielded by `stream()` and persisted in traces when a
|
|
478
|
+
* protocol or caller-owned adapter invokes runtime tools.
|
|
479
|
+
*/
|
|
480
|
+
export type ToolActivityEvent = ToolCallEvent | ToolResultEvent;
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Lifecycle event yielded by `stream()`.
|
|
484
|
+
*
|
|
485
|
+
* These events describe workflow coordination state rather than model text.
|
|
486
|
+
* Role assignment establishes the participant roster, while `budget-stop`
|
|
487
|
+
* records a lifecycle halt before the terminal completion event.
|
|
488
|
+
*/
|
|
489
|
+
export type StreamLifecycleEvent = RoleAssignmentEvent | BudgetStopEvent;
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Output event yielded by `stream()`.
|
|
493
|
+
*
|
|
494
|
+
* These events carry generated agent output or grouped round output while a
|
|
495
|
+
* workflow is still running.
|
|
496
|
+
*/
|
|
497
|
+
export type StreamOutputEvent = ModelActivityEvent | ToolActivityEvent | TurnEvent | BroadcastEvent;
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Error event yielded by `stream()` when execution rejects.
|
|
501
|
+
*
|
|
502
|
+
* @remarks
|
|
503
|
+
* Stream errors are emitted before {@link StreamHandle.result} rejects so UIs
|
|
504
|
+
* and log collectors can record a terminal failure without wrapping the result
|
|
505
|
+
* promise. The error payload is JSON-serializable and intentionally omits
|
|
506
|
+
* runtime-specific values such as `Error.stack`.
|
|
507
|
+
*/
|
|
508
|
+
export interface StreamErrorEvent {
|
|
509
|
+
/** Discriminant for stream event handling. */
|
|
510
|
+
readonly type: "error";
|
|
511
|
+
/** Stable run id when known; empty when failure happened before protocol startup. */
|
|
512
|
+
readonly runId: string;
|
|
513
|
+
/** ISO-8601 event timestamp. */
|
|
514
|
+
readonly at: string;
|
|
515
|
+
/** Error name when available. */
|
|
516
|
+
readonly name: string;
|
|
517
|
+
/** Human-readable error message. */
|
|
518
|
+
readonly message: string;
|
|
519
|
+
/** Optional serializable diagnostics supplied by the SDK. */
|
|
520
|
+
readonly detail?: JsonObject;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Completion event yielded by `stream()` after successful execution.
|
|
525
|
+
*/
|
|
526
|
+
export type StreamCompletionEvent = FinalEvent;
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Public streaming event union returned by `stream()`.
|
|
530
|
+
*
|
|
531
|
+
* @remarks
|
|
532
|
+
* The union is grouped into lifecycle, output, error, and completion families:
|
|
533
|
+
*
|
|
534
|
+
* - lifecycle: {@link StreamLifecycleEvent}
|
|
535
|
+
* - output: {@link StreamOutputEvent}
|
|
536
|
+
* - error: {@link StreamErrorEvent}
|
|
537
|
+
* - completion: {@link StreamCompletionEvent}
|
|
538
|
+
*
|
|
539
|
+
* Successful stream events are also persisted as {@link RunEvent} values in the
|
|
540
|
+
* completed trace. `error` is stream-only because a failed run has no completed
|
|
541
|
+
* {@link RunResult} trace to return.
|
|
542
|
+
*/
|
|
543
|
+
export type StreamEvent = StreamLifecycleEvent | StreamOutputEvent | StreamErrorEvent | StreamCompletionEvent;
|
|
544
|
+
|