@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.
Files changed (73) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/browser/index.js +784 -562
  3. package/dist/browser/index.js.map +1 -1
  4. package/dist/index.d.ts +4 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +2 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/runtime/broadcast.d.ts.map +1 -1
  9. package/dist/runtime/broadcast.js +1 -13
  10. package/dist/runtime/broadcast.js.map +1 -1
  11. package/dist/runtime/coordinator.d.ts.map +1 -1
  12. package/dist/runtime/coordinator.js +1 -13
  13. package/dist/runtime/coordinator.js.map +1 -1
  14. package/dist/runtime/ids.d.ts +19 -0
  15. package/dist/runtime/ids.d.ts.map +1 -0
  16. package/dist/runtime/ids.js +36 -0
  17. package/dist/runtime/ids.js.map +1 -0
  18. package/dist/runtime/logger.d.ts +61 -0
  19. package/dist/runtime/logger.d.ts.map +1 -0
  20. package/dist/runtime/logger.js +114 -0
  21. package/dist/runtime/logger.js.map +1 -0
  22. package/dist/runtime/retry.d.ts +99 -0
  23. package/dist/runtime/retry.d.ts.map +1 -0
  24. package/dist/runtime/retry.js +181 -0
  25. package/dist/runtime/retry.js.map +1 -0
  26. package/dist/runtime/sequential.d.ts.map +1 -1
  27. package/dist/runtime/sequential.js +1 -10
  28. package/dist/runtime/sequential.js.map +1 -1
  29. package/dist/runtime/shared.d.ts.map +1 -1
  30. package/dist/runtime/shared.js +1 -13
  31. package/dist/runtime/shared.js.map +1 -1
  32. package/dist/runtime/tools/built-in.d.ts +99 -0
  33. package/dist/runtime/tools/built-in.d.ts.map +1 -0
  34. package/dist/runtime/tools/built-in.js +577 -0
  35. package/dist/runtime/tools/built-in.js.map +1 -0
  36. package/dist/runtime/tools/vercel-ai.d.ts +67 -0
  37. package/dist/runtime/tools/vercel-ai.d.ts.map +1 -0
  38. package/dist/runtime/tools/vercel-ai.js +148 -0
  39. package/dist/runtime/tools/vercel-ai.js.map +1 -0
  40. package/dist/runtime/tools.d.ts +5 -268
  41. package/dist/runtime/tools.d.ts.map +1 -1
  42. package/dist/runtime/tools.js +7 -770
  43. package/dist/runtime/tools.js.map +1 -1
  44. package/dist/types/benchmark.d.ts +276 -0
  45. package/dist/types/benchmark.d.ts.map +1 -0
  46. package/dist/types/benchmark.js +2 -0
  47. package/dist/types/benchmark.js.map +1 -0
  48. package/dist/types/events.d.ts +495 -0
  49. package/dist/types/events.d.ts.map +1 -0
  50. package/dist/types/events.js +2 -0
  51. package/dist/types/events.js.map +1 -0
  52. package/dist/types/replay.d.ts +169 -0
  53. package/dist/types/replay.d.ts.map +1 -0
  54. package/dist/types/replay.js +2 -0
  55. package/dist/types/replay.js.map +1 -0
  56. package/dist/types.d.ts +6 -935
  57. package/dist/types.d.ts.map +1 -1
  58. package/package.json +27 -1
  59. package/src/index.ts +4 -0
  60. package/src/runtime/broadcast.ts +1 -16
  61. package/src/runtime/coordinator.ts +1 -16
  62. package/src/runtime/ids.ts +41 -0
  63. package/src/runtime/logger.ts +152 -0
  64. package/src/runtime/retry.ts +270 -0
  65. package/src/runtime/sequential.ts +1 -12
  66. package/src/runtime/shared.ts +1 -16
  67. package/src/runtime/tools/built-in.ts +875 -0
  68. package/src/runtime/tools/vercel-ai.ts +269 -0
  69. package/src/runtime/tools.ts +60 -1255
  70. package/src/types/benchmark.ts +300 -0
  71. package/src/types/events.ts +544 -0
  72. package/src/types/replay.ts +201 -0
  73. package/src/types.ts +104 -994
package/src/types.ts CHANGED
@@ -792,191 +792,30 @@ export interface ModelResponse {
792
792
  readonly metadata?: JsonObject;
793
793
  }
794
794
 
795
- /**
796
- * Version tag for the replay trace artifact schema.
797
- */
798
- export type ReplayTraceSchemaVersion = "1.0";
799
-
800
- /**
801
- * Serializable seed metadata recorded with replay traces.
802
- *
803
- * @remarks
804
- * Most providers do not expose deterministic seed control. Dogpile still
805
- * records an explicit empty seed artifact so replay consumers can distinguish
806
- * "no seed supplied" from a missing trace field.
807
- */
808
- export interface ReplayTraceSeed {
809
- /** Seed artifact discriminant. */
810
- readonly kind: "replay-trace-seed";
811
- /** Seed source visible to replay tooling. */
812
- readonly source: "caller" | "none";
813
- /** Caller-supplied seed value, or `null` when no seed was supplied. */
814
- readonly value: string | number | null;
815
- }
816
-
817
- /**
818
- * Normalized run inputs persisted inside the replay trace artifact.
819
- */
820
- export interface ReplayTraceRunInputs {
821
- /** Run input artifact discriminant. */
822
- readonly kind: "replay-trace-run-inputs";
823
- /** Mission or intent supplied by the caller. */
824
- readonly intent: string;
825
- /** Exact normalized protocol config used for execution. */
826
- readonly protocol: ProtocolConfig;
827
- /** Selected cost/quality tier. */
828
- readonly tier: Tier;
829
- /** Configured model provider id. */
830
- readonly modelProviderId: string;
831
- /** Concrete agent roster visible to the protocol. */
832
- readonly agents: readonly AgentSpec[];
833
- /** Temperature supplied to provider requests. */
834
- readonly temperature: number;
835
- }
836
-
837
- /**
838
- * Budget and stop-policy artifact persisted inside replay traces.
839
- */
840
- export interface ReplayTraceBudget {
841
- /** Budget artifact discriminant. */
842
- readonly kind: "replay-trace-budget";
843
- /** Selected cost/quality tier. */
844
- readonly tier: Tier;
845
- /** Optional hard caps supplied by the caller. */
846
- readonly caps?: Omit<Budget, "tier">;
847
- /** Optional composable termination policy used by the protocol. */
848
- readonly termination?: TerminationCondition;
849
- }
850
-
851
- /**
852
- * Budget state snapshot derived from a cost-bearing trace event.
853
- *
854
- * @remarks
855
- * Replay consumers can inspect this artifact without walking the full event
856
- * log. Entries are emitted for model-turn accounting changes, coordination
857
- * barriers that expose cumulative cost, budget stops, and final completion.
858
- */
859
- export interface ReplayTraceBudgetStateChange {
860
- /** Budget state artifact discriminant. */
861
- readonly kind: "replay-trace-budget-state-change";
862
- /** Zero-based event index that exposed this budget state. */
863
- readonly eventIndex: number;
864
- /** Source event type for the budget state. */
865
- readonly eventType: "agent-turn" | "broadcast" | "budget-stop" | "final";
866
- /** ISO-8601 timestamp from the source event. */
867
- readonly at: string;
868
- /** Cumulative cost visible at this point in the run. */
869
- readonly cost: CostSummary;
870
- /** Completed model-turn iteration count when known. */
871
- readonly iteration?: number;
872
- /** Elapsed runtime in milliseconds when known. */
873
- readonly elapsedMs?: number;
874
- /** Budget stop reason when this state records a halt. */
875
- readonly budgetReason?: BudgetStopReason;
876
- }
795
+ // Replay trace types: see src/types/replay.ts
796
+ import type {
797
+ ReplayTraceBudget,
798
+ ReplayTraceBudgetStateChange,
799
+ ReplayTraceFinalOutput,
800
+ ReplayTraceProtocolDecision,
801
+ ReplayTraceProtocolDecisionType,
802
+ ReplayTraceProviderCall,
803
+ ReplayTraceRunInputs,
804
+ ReplayTraceSchemaVersion,
805
+ ReplayTraceSeed
806
+ } from "./types/replay.js";
807
+ export type {
808
+ ReplayTraceBudget,
809
+ ReplayTraceBudgetStateChange,
810
+ ReplayTraceFinalOutput,
811
+ ReplayTraceProtocolDecision,
812
+ ReplayTraceProtocolDecisionType,
813
+ ReplayTraceProviderCall,
814
+ ReplayTraceRunInputs,
815
+ ReplayTraceSchemaVersion,
816
+ ReplayTraceSeed
817
+ };
877
818
 
878
- /**
879
- * Provider-neutral protocol decision kinds recorded for replay.
880
- */
881
- export type ReplayTraceProtocolDecisionType =
882
- | "assign-role"
883
- | "select-agent-turn"
884
- | "start-model-call"
885
- | "complete-model-call"
886
- | "observe-model-output"
887
- | "start-tool-call"
888
- | "complete-tool-call"
889
- | "collect-broadcast-round"
890
- | "stop-for-budget"
891
- | "finalize-output";
892
-
893
- /**
894
- * Protocol-level decision appended during execution.
895
- */
896
- export interface ReplayTraceProtocolDecision {
897
- /** Decision artifact discriminant. */
898
- readonly kind: "replay-trace-protocol-decision";
899
- /** Zero-based event index that produced this decision. */
900
- readonly eventIndex: number;
901
- /** Event type that records the decision. */
902
- readonly eventType: RunEvent["type"];
903
- /** Coordination protocol that made the decision. */
904
- readonly protocol: Protocol;
905
- /** Provider-neutral decision kind for replay tooling. */
906
- readonly decision: ReplayTraceProtocolDecisionType;
907
- /** ISO-8601 timestamp from the source event. */
908
- readonly at: string;
909
- /** Agent involved in the decision, when agent-scoped. */
910
- readonly agentId?: string;
911
- /** Role involved in the decision, when agent-scoped. */
912
- readonly role?: string;
913
- /** Provider call involved in the decision, when model-scoped. */
914
- readonly callId?: string;
915
- /** Provider involved in the decision, when model-scoped. */
916
- readonly providerId?: string;
917
- /** Tool call involved in the decision, when tool-scoped. */
918
- readonly toolCallId?: string;
919
- /** Tool identity involved in the decision, when tool-scoped. */
920
- readonly tool?: RuntimeToolIdentity;
921
- /** One-based protocol turn for turn-scoped decisions. */
922
- readonly turn?: number;
923
- /** Coordinator phase for coordinator protocol turn decisions. */
924
- readonly phase?: "plan" | "worker" | "final-synthesis";
925
- /** One-based broadcast round for grouped broadcast decisions. */
926
- readonly round?: number;
927
- /** Number of transcript entries visible after this decision. */
928
- readonly transcriptEntryCount?: number;
929
- /** Number of contributions collected at a broadcast barrier. */
930
- readonly contributionCount?: number;
931
- /** Prompt/input associated with turn decisions. */
932
- readonly input?: string;
933
- /** Output associated with turn or final decisions. */
934
- readonly output?: string;
935
- /** Cumulative cost visible at this decision point. */
936
- readonly cost?: CostSummary;
937
- /** Normalized budget stop reason for budget-stop decisions. */
938
- readonly budgetReason?: BudgetStopReason;
939
- }
940
-
941
- /**
942
- * Provider call metadata and response captured for replay inspection.
943
- */
944
- export interface ReplayTraceProviderCall {
945
- /** Provider call artifact discriminant. */
946
- readonly kind: "replay-trace-provider-call";
947
- /** Stable call id within the run. */
948
- readonly callId: string;
949
- /** Configured model provider id. */
950
- readonly providerId: string;
951
- /** ISO-8601 timestamp before the provider call started. */
952
- readonly startedAt: string;
953
- /** ISO-8601 timestamp after the provider call completed. */
954
- readonly completedAt: string;
955
- /** Agent that requested this provider call. */
956
- readonly agentId: string;
957
- /** Role that requested this provider call. */
958
- readonly role: string;
959
- /** Request handed to the configured model provider. */
960
- readonly request: ModelRequest;
961
- /** Response returned by the configured model provider. */
962
- readonly response: ModelResponse;
963
- }
964
-
965
- /**
966
- * Final output artifact persisted inside replay traces.
967
- */
968
- export interface ReplayTraceFinalOutput {
969
- /** Final output artifact discriminant. */
970
- readonly kind: "replay-trace-final-output";
971
- /** Final synthesized output returned by the run. */
972
- readonly output: string;
973
- /** Total cost at completion. */
974
- readonly cost: CostSummary;
975
- /** ISO-8601 completion timestamp from the terminal event. */
976
- readonly completedAt: string;
977
- /** Link to the completed transcript artifact. */
978
- readonly transcript: TranscriptLink;
979
- }
980
819
 
981
820
  /**
982
821
  * Incremental text produced by a streaming model provider.
@@ -1411,817 +1250,88 @@ export interface RuntimeToolAdapterContract<Input extends object = JsonObject, O
1411
1250
  validateInput(input: Readonly<Input>): RuntimeToolValidationResult;
1412
1251
  }
1413
1252
 
1414
- /**
1415
- * Required output artifact for a benchmark task.
1416
- */
1417
- export interface BenchmarkRequiredArtifact {
1418
- /** Stable artifact name used by scorers and reports. */
1419
- readonly name: string;
1420
- /** Fixture-defined artifact shape, for example `enum` or `markdown_table`. */
1421
- readonly type: string;
1422
- /** Optional human-readable artifact requirement. */
1423
- readonly description?: string;
1424
- /** Optional allowed values for constrained artifacts. */
1425
- readonly allowedValues?: readonly string[];
1426
- }
1427
-
1428
- /**
1429
- * Serializable task input shared by benchmark protocol runners.
1430
- */
1431
- export interface BenchmarkTaskInput {
1432
- /** Stable benchmark task id. */
1433
- readonly id: string;
1434
- /** Mission text supplied to protocol runners. */
1435
- readonly intent: string;
1436
- /** Optional task title for reports. */
1437
- readonly title?: string;
1438
- /** Optional benchmark difficulty or paper task level, such as `L3`. */
1439
- readonly level?: string;
1440
- /** Required artifacts the run output must contain. */
1441
- readonly requiredArtifacts?: readonly BenchmarkRequiredArtifact[];
1442
- /** Serializable scoring rubric or fixture-specific judging metadata. */
1443
- readonly rubric?: JsonObject;
1444
- /** Additional serializable fixture metadata. */
1445
- readonly metadata?: JsonObject;
1446
- }
1447
-
1448
- /**
1449
- * Benchmark budget controls shared by all protocol runners in one comparison.
1450
- */
1451
- export interface BenchmarkBudget {
1452
- /** Named cost/quality tier selected for the benchmark run. */
1453
- readonly tier: Tier;
1454
- /** Optional maximum spend in US dollars. */
1455
- readonly maxUsd?: number;
1456
- /** Optional maximum input token count. */
1457
- readonly maxInputTokens?: number;
1458
- /** Optional maximum output token count. */
1459
- readonly maxOutputTokens?: number;
1460
- /** Optional maximum total token count. */
1461
- readonly maxTotalTokens?: number;
1462
- /** Optional quality preference in the inclusive range `0..1`. */
1463
- readonly qualityWeight?: number;
1464
- }
1465
-
1466
- /**
1467
- * Benchmark model settings shared across protocol runners.
1468
- *
1469
- * @remarks
1470
- * Research and reproduction workflows use this object to hold provider
1471
- * settings constant while changing only the coordination protocol. The
1472
- * `metadata` field is for serializable experiment labels such as corpus id,
1473
- * prompt template version, model family, or paper reproduction condition.
1474
- */
1475
- export interface BenchmarkModelSettings {
1476
- /** Caller-configured model provider, typically backed by the Vercel AI SDK. */
1477
- readonly provider: ConfiguredModelProvider;
1478
- /** Optional fixed temperature for controlled reproduction runs. */
1479
- readonly temperature?: number;
1480
- /** Optional deterministic seed recorded for provider adapters that support it. */
1481
- readonly seed?: number;
1482
- /** Additional serializable provider or run metadata. */
1483
- readonly metadata?: JsonObject;
1484
- }
1253
+ // Benchmark types: see src/types/benchmark.ts
1254
+ import type {
1255
+ BenchmarkBudget,
1256
+ BenchmarkCostAccounting,
1257
+ BenchmarkModelSettings,
1258
+ BenchmarkProtocolArtifact,
1259
+ BenchmarkProtocolScore,
1260
+ BenchmarkReproducibilityArtifact,
1261
+ BenchmarkRequiredArtifact,
1262
+ BenchmarkRunArtifact,
1263
+ BenchmarkRunnerConfig,
1264
+ BenchmarkScoreDimension,
1265
+ BenchmarkStreamingEventLog,
1266
+ BenchmarkTaskInput,
1267
+ ProtocolBenchmarkRunConfig
1268
+ } from "./types/benchmark.js";
1269
+ export type {
1270
+ BenchmarkBudget,
1271
+ BenchmarkCostAccounting,
1272
+ BenchmarkModelSettings,
1273
+ BenchmarkProtocolArtifact,
1274
+ BenchmarkProtocolScore,
1275
+ BenchmarkReproducibilityArtifact,
1276
+ BenchmarkRequiredArtifact,
1277
+ BenchmarkRunArtifact,
1278
+ BenchmarkRunnerConfig,
1279
+ BenchmarkScoreDimension,
1280
+ BenchmarkStreamingEventLog,
1281
+ BenchmarkTaskInput,
1282
+ ProtocolBenchmarkRunConfig
1283
+ };
1284
+
1285
+ // Events: see src/types/events.ts
1286
+ import type {
1287
+ AgentDecision,
1288
+ AgentParticipation,
1289
+ BroadcastContribution,
1290
+ BroadcastEvent,
1291
+ BudgetStopEvent,
1292
+ FinalEvent,
1293
+ ModelActivityEvent,
1294
+ ModelOutputChunkEvent,
1295
+ ModelRequestEvent,
1296
+ ModelResponseEvent,
1297
+ RoleAssignmentEvent,
1298
+ RunEvent,
1299
+ StreamCompletionEvent,
1300
+ StreamErrorEvent,
1301
+ StreamEvent,
1302
+ StreamLifecycleEvent,
1303
+ StreamOutputEvent,
1304
+ ToolActivityEvent,
1305
+ ToolCallEvent,
1306
+ ToolResultEvent,
1307
+ TranscriptLink,
1308
+ TurnEvent
1309
+ } from "./types/events.js";
1310
+ export type {
1311
+ AgentDecision,
1312
+ AgentParticipation,
1313
+ BroadcastContribution,
1314
+ BroadcastEvent,
1315
+ BudgetStopEvent,
1316
+ FinalEvent,
1317
+ ModelActivityEvent,
1318
+ ModelOutputChunkEvent,
1319
+ ModelRequestEvent,
1320
+ ModelResponseEvent,
1321
+ RoleAssignmentEvent,
1322
+ RunEvent,
1323
+ StreamCompletionEvent,
1324
+ StreamErrorEvent,
1325
+ StreamEvent,
1326
+ StreamLifecycleEvent,
1327
+ StreamOutputEvent,
1328
+ ToolActivityEvent,
1329
+ ToolCallEvent,
1330
+ ToolResultEvent,
1331
+ TranscriptLink,
1332
+ TurnEvent
1333
+ };
1485
1334
 
1486
- /**
1487
- * Shared benchmark runner configuration before selecting a protocol.
1488
- *
1489
- * @remarks
1490
- * This contract carries the task input, budget policy, and model settings that
1491
- * must stay constant when comparing multiple coordination protocols. It is the
1492
- * researcher-facing escape hatch for paper-faithfulness checks: callers can
1493
- * project one task into Sequential, Broadcast, Shared, and Coordinator runs
1494
- * while preserving the same agents, tier, caps, model, and fixture metadata.
1495
- *
1496
- * The object is intentionally JSON-adjacent and storage-free. Persist benchmark
1497
- * inputs, run manifests, and traces in caller-owned systems.
1498
- */
1499
- export interface BenchmarkRunnerConfig {
1500
- /** Serializable benchmark task input. */
1501
- readonly task: BenchmarkTaskInput;
1502
- /** Shared budget and cap policy. */
1503
- readonly budget: BenchmarkBudget;
1504
- /** Shared model provider and generation settings. */
1505
- readonly model: BenchmarkModelSettings;
1506
- /** Optional explicit agents; defaults are used when omitted. */
1507
- readonly agents?: readonly AgentSpec[];
1508
- /** Additional serializable benchmark metadata. */
1509
- readonly metadata?: JsonObject;
1510
- }
1511
-
1512
- /**
1513
- * Benchmark configuration for one concrete protocol runner invocation.
1514
- *
1515
- * @remarks
1516
- * Use this derived shape after selecting the protocol under test. It preserves
1517
- * the shared benchmark controls from {@link BenchmarkRunnerConfig} and adds a
1518
- * named or explicit {@link ProtocolConfig}, which lets reproduction code tune
1519
- * protocol-native parameters without widening the high-level API.
1520
- */
1521
- export interface ProtocolBenchmarkRunConfig extends BenchmarkRunnerConfig {
1522
- /** Protocol being evaluated under the shared benchmark settings. */
1523
- readonly protocol: Protocol | ProtocolConfig;
1524
- }
1525
-
1526
- /**
1527
- * Serializable benchmark protocol descriptor persisted with run artifacts.
1528
- *
1529
- * @remarks
1530
- * Benchmark artifacts record both the normalized protocol name and the exact
1531
- * caller-supplied protocol config so a reproduction harness can distinguish
1532
- * `"sequential"` defaults from `{ kind: "sequential", maxTurns: 4 }`.
1533
- */
1534
- export interface BenchmarkProtocolArtifact {
1535
- /** Normalized protocol name used for comparison grouping. */
1536
- readonly kind: Protocol;
1537
- /** Exact protocol value supplied to the runner. */
1538
- readonly config: Protocol | ProtocolConfig;
1539
- }
1540
-
1541
- /**
1542
- * Reproducibility metadata persisted with every benchmark run artifact.
1543
- *
1544
- * @remarks
1545
- * This shape intentionally stores provider identity and serializable model
1546
- * settings, but not the provider implementation itself. Callers own provider
1547
- * construction and external storage; Dogpile owns the portable artifact shape.
1548
- */
1549
- export interface BenchmarkReproducibilityArtifact {
1550
- /** Benchmark task input used for this run. */
1551
- readonly task: BenchmarkTaskInput;
1552
- /** Shared budget and cap policy used for this run. */
1553
- readonly budget: BenchmarkBudget;
1554
- /** Protocol selected for this run. */
1555
- readonly protocol: BenchmarkProtocolArtifact;
1556
- /** Provider id recorded from the configured model. */
1557
- readonly modelProviderId: string;
1558
- /** Optional fixed temperature used for the run. */
1559
- readonly temperature?: number;
1560
- /** Optional deterministic seed recorded for provider adapters that support it. */
1561
- readonly seed?: number;
1562
- /** Additional serializable provider or run metadata. */
1563
- readonly modelMetadata?: JsonObject;
1564
- /** Concrete agent roster used for the run. */
1565
- readonly agents: readonly AgentSpec[];
1566
- /** Additional serializable benchmark metadata. */
1567
- readonly benchmarkMetadata?: JsonObject;
1568
- }
1569
-
1570
- /**
1571
- * Cost and budget metadata recorded for one benchmark run.
1572
- *
1573
- * @remarks
1574
- * This accounting block is intentionally duplicated from the run result and
1575
- * benchmark controls so benchmark reports can group, filter, and audit spend
1576
- * without unpacking the full trace or reproduction object. Utilization fields
1577
- * are only present when the corresponding cap was configured.
1578
- */
1579
- export interface BenchmarkCostAccounting {
1580
- /** Accounting artifact discriminant for future benchmark metadata unions. */
1581
- readonly kind: "benchmark-cost-accounting";
1582
- /** Named budget/cost tier selected for this benchmark run. */
1583
- readonly tier: Tier;
1584
- /** Shared benchmark budget and cap policy used for this run. */
1585
- readonly budget: BenchmarkBudget;
1586
- /** Total token and spend accounting observed for this run. */
1587
- readonly cost: CostSummary;
1588
- /** Fraction of the configured USD cap consumed, when `maxUsd` is present. */
1589
- readonly usdCapUtilization?: number;
1590
- /** Fraction of the configured total-token cap consumed, when `maxTotalTokens` is present. */
1591
- readonly totalTokenCapUtilization?: number;
1592
- }
1593
-
1594
- /**
1595
- * Structured streaming event log captured for one benchmark run.
1596
- *
1597
- * @remarks
1598
- * Benchmark artifacts keep this log beside the full trace so reproduction
1599
- * harnesses can inspect exactly what the streaming API yielded during the run
1600
- * without unpacking unrelated trace metadata. The `events` array must match
1601
- * `trace.events` for completed runs.
1602
- */
1603
- export interface BenchmarkStreamingEventLog {
1604
- /** Event-log discriminant for future benchmark observability artifacts. */
1605
- readonly kind: "benchmark-streaming-event-log";
1606
- /** Stable run id shared by the benchmark artifact and trace. */
1607
- readonly runId: string;
1608
- /** Protocol whose streaming events were captured. */
1609
- readonly protocol: Protocol;
1610
- /** Ordered event kinds for compact coverage checks. */
1611
- readonly eventTypes: readonly RunEvent["type"][];
1612
- /** Number of streaming events captured. */
1613
- readonly eventCount: number;
1614
- /** Complete ordered streaming events yielded by the run. */
1615
- readonly events: readonly RunEvent[];
1616
- }
1617
-
1618
- /**
1619
- * Serializable score persisted for one protocol benchmark artifact.
1620
- *
1621
- * @remarks
1622
- * The score is protocol-scoped because paper reproduction reports compare the
1623
- * same task across protocol variants. When a judge supplies
1624
- * {@link RunResult.quality}, the benchmark score records that value on a
1625
- * 0..100 scale. Otherwise Dogpile computes a conservative artifact-completeness
1626
- * score from the captured output, transcript, streaming event log, and budget
1627
- * accounting so unjudged benchmark artifacts still carry an auditable score
1628
- * derived from stored data.
1629
- */
1630
- export interface BenchmarkProtocolScore {
1631
- /** Score artifact discriminant for future benchmark scoring variants. */
1632
- readonly kind: "benchmark-protocol-score";
1633
- /** Protocol this score belongs to. */
1634
- readonly protocol: Protocol;
1635
- /** Score in the inclusive range `0..100`. */
1636
- readonly score: number;
1637
- /** Normalized score in the inclusive range `0..1`. */
1638
- readonly normalizedScore: number;
1639
- /** Maximum score for the current scoring scale. */
1640
- readonly maxScore: 100;
1641
- /** How the score was derived. */
1642
- readonly source: "run-quality" | "artifact-completeness";
1643
- /** Compact scoring dimensions used to compute the stored score. */
1644
- readonly dimensions: readonly BenchmarkScoreDimension[];
1645
- }
1646
-
1647
- /**
1648
- * One serializable dimension contributing to a benchmark protocol score.
1649
- */
1650
- export interface BenchmarkScoreDimension {
1651
- /** Stable dimension name for reports. */
1652
- readonly name: string;
1653
- /** Earned points for this dimension. */
1654
- readonly score: number;
1655
- /** Maximum points available for this dimension. */
1656
- readonly maxScore: number;
1657
- }
1658
-
1659
- /**
1660
- * Reproducible benchmark output artifact for one protocol run.
1661
- *
1662
- * @remarks
1663
- * This is the storage-free persistence contract for reproduction workflows:
1664
- * callers can write the object to JSON, NDJSON, object storage, or a database
1665
- * without Dogpile depending on Node-only filesystem APIs. It contains the final
1666
- * output, full transcript, a structured streaming event log, full trace, cost
1667
- * summary, and all serializable controls needed to replay the run in
1668
- * caller-managed infrastructure.
1669
- */
1670
- export interface BenchmarkRunArtifact {
1671
- /** Artifact discriminant for future benchmark artifact unions. */
1672
- readonly kind: "benchmark-run";
1673
- /** Schema version for reproducible artifact consumers. */
1674
- readonly schemaVersion: "1.0";
1675
- /** Stable run id from the trace. */
1676
- readonly runId: string;
1677
- /** ISO-8601 timestamp derived from the first trace event when available. */
1678
- readonly startedAt: string;
1679
- /** ISO-8601 timestamp derived from the final trace event when available. */
1680
- readonly completedAt: string;
1681
- /** Reproduction controls and serializable fixture inputs. */
1682
- readonly reproducibility: BenchmarkReproducibilityArtifact;
1683
- /** Final output produced by the protocol. */
1684
- readonly output: string;
1685
- /** Complete normalized transcript for this run. */
1686
- readonly transcript: readonly TranscriptEntry[];
1687
- /** Structured streaming event log captured for this benchmark run. */
1688
- readonly eventLog: BenchmarkStreamingEventLog;
1689
- /** Full serializable event log and trace for this run. */
1690
- readonly trace: Trace;
1691
- /** Cost, tier, and benchmark budget metadata for this run. */
1692
- readonly accounting: BenchmarkCostAccounting;
1693
- /** Per-protocol benchmark score computed from the captured artifact data. */
1694
- readonly score: BenchmarkProtocolScore;
1695
- /** Total token and spend accounting for this run. */
1696
- readonly cost: CostSummary;
1697
- /** Optional normalized quality score in the inclusive range `0..1`. */
1698
- readonly quality?: number;
1699
- }
1700
-
1701
- /**
1702
- * Event emitted when a protocol assigns or records an agent role.
1703
- *
1704
- * @remarks
1705
- * This event normally appears near the beginning of a run and establishes the
1706
- * `agentId`/`role` pair that later turn and transcript records refer to. A
1707
- * renderer can use it to build the participant roster before model output
1708
- * starts streaming.
1709
- *
1710
- * Payload shape:
1711
- *
1712
- * - `type`: always `role-assignment`.
1713
- * - `runId`: stable id shared by every event and trace object for the run.
1714
- * - `at`: ISO-8601 timestamp for when the assignment was emitted.
1715
- * - `agentId`: stable agent id used in events, trace, and transcript entries.
1716
- * - `role`: model-visible role or perspective assigned to that agent.
1717
- */
1718
- export interface RoleAssignmentEvent {
1719
- /** Discriminant for event rendering and exhaustive switches. */
1720
- readonly type: "role-assignment";
1721
- /** Stable run id shared by all events in one workflow. */
1722
- readonly runId: string;
1723
- /** ISO-8601 event timestamp. */
1724
- readonly at: string;
1725
- /** Agent receiving the role assignment. */
1726
- readonly agentId: string;
1727
- /** Role assigned to the agent. */
1728
- readonly role: string;
1729
- }
1730
-
1731
- /**
1732
- * Event emitted when Dogpile is about to ask the configured model provider for
1733
- * one protocol-managed response.
1734
- *
1735
- * @remarks
1736
- * This event is the request-side model activity counterpart to
1737
- * {@link ModelResponseEvent}. Protocol implementations may omit it when they
1738
- * only expose completed turns, but adapters and researcher harnesses can emit
1739
- * it to make provider calls visible in the same streaming event log as agent
1740
- * turns and final output.
1741
- */
1742
- export interface ModelRequestEvent {
1743
- /** Discriminant for event rendering and exhaustive switches. */
1744
- readonly type: "model-request";
1745
- /** Stable run id shared by all events in one workflow. */
1746
- readonly runId: string;
1747
- /** ISO-8601 event timestamp. */
1748
- readonly at: string;
1749
- /** Stable provider call id within the run. */
1750
- readonly callId: string;
1751
- /** Configured model provider id receiving the request. */
1752
- readonly providerId: string;
1753
- /** Agent requesting the model call. */
1754
- readonly agentId: string;
1755
- /** Agent role for the active model call. */
1756
- readonly role: string;
1757
- /** Provider-neutral request handed to the model adapter. */
1758
- readonly request: ModelRequest;
1759
- }
1760
-
1761
- /**
1762
- * Event emitted after the configured model provider returns one response.
1763
- *
1764
- * @remarks
1765
- * This event records provider-level model activity without forcing callers to
1766
- * infer it from the higher-level {@link TurnEvent}. The response is the same
1767
- * provider-neutral shape captured in replay traces, so it remains portable and
1768
- * JSON-serializable across Node LTS, Bun, and browser ESM runtimes.
1769
- */
1770
- export interface ModelResponseEvent {
1771
- /** Discriminant for event rendering and exhaustive switches. */
1772
- readonly type: "model-response";
1773
- /** Stable run id shared by all events in one workflow. */
1774
- readonly runId: string;
1775
- /** ISO-8601 event timestamp. */
1776
- readonly at: string;
1777
- /** Stable provider call id within the run. */
1778
- readonly callId: string;
1779
- /** Configured model provider id that produced the response. */
1780
- readonly providerId: string;
1781
- /** Agent that requested the model call. */
1782
- readonly agentId: string;
1783
- /** Agent role for the completed model call. */
1784
- readonly role: string;
1785
- /** Provider-neutral response returned by the model adapter. */
1786
- readonly response: ModelResponse;
1787
- }
1788
-
1789
- /**
1790
- * Event emitted while a model turn is still generating text.
1791
- *
1792
- * @remarks
1793
- * `model-output-chunk` lets streaming callers render provider output before
1794
- * the protocol has enough information to commit the completed `agent-turn`
1795
- * transcript entry. It is emitted only when the configured model provider
1796
- * implements {@link ConfiguredModelProvider.stream}; non-streaming providers
1797
- * continue to produce the existing role/turn/final event sequence.
1798
- *
1799
- * Payload shape:
1800
- *
1801
- * - `type`: always `model-output-chunk`.
1802
- * - `runId`: stable id shared by every event and trace object for the run.
1803
- * - `at`: ISO-8601 timestamp for when the chunk was observed.
1804
- * - `agentId` and `role`: identify the active generating agent.
1805
- * - `input`: prompt text visible to that agent for this turn.
1806
- * - `chunkIndex`: zero-based chunk index within this model turn.
1807
- * - `text`: text delta from the provider.
1808
- * - `output`: accumulated output for this turn after applying the chunk.
1809
- */
1810
- export interface ModelOutputChunkEvent {
1811
- /** Discriminant for event rendering and exhaustive switches. */
1812
- readonly type: "model-output-chunk";
1813
- /** Stable run id shared by all events in one workflow. */
1814
- readonly runId: string;
1815
- /** ISO-8601 event timestamp. */
1816
- readonly at: string;
1817
- /** Agent currently producing output. */
1818
- readonly agentId: string;
1819
- /** Agent role for the active turn. */
1820
- readonly role: string;
1821
- /** Prompt/input visible to the agent for this turn. */
1822
- readonly input: string;
1823
- /** Zero-based chunk index within the active model turn. */
1824
- readonly chunkIndex: number;
1825
- /** Text delta produced by the model provider. */
1826
- readonly text: string;
1827
- /** Accumulated output for this turn after applying this chunk. */
1828
- readonly output: string;
1829
- }
1830
-
1831
- /**
1832
- * Event emitted when a runtime tool is invoked by protocol or model policy.
1833
- *
1834
- * @remarks
1835
- * Tools are caller-owned escape hatches. This request-side event keeps tool
1836
- * invocation observable without making Dogpile core depend on Node-only
1837
- * capabilities, a storage layer, or a provider-specific function-call shape.
1838
- */
1839
- export interface ToolCallEvent {
1840
- /** Discriminant for event rendering and exhaustive switches. */
1841
- readonly type: "tool-call";
1842
- /** Stable run id shared by all events in one workflow. */
1843
- readonly runId: string;
1844
- /** ISO-8601 event timestamp. */
1845
- readonly at: string;
1846
- /** Stable tool call id within the run. */
1847
- readonly toolCallId: string;
1848
- /** Tool identity selected for execution. */
1849
- readonly tool: RuntimeToolIdentity;
1850
- /** JSON-serializable tool input. */
1851
- readonly input: JsonObject;
1852
- /** Agent that requested the tool, when agent-scoped. */
1853
- readonly agentId?: string;
1854
- /** Agent role that requested the tool, when available. */
1855
- readonly role?: string;
1856
- }
1857
-
1858
- /**
1859
- * Event emitted after a runtime tool returns a normalized result.
1860
- *
1861
- * @remarks
1862
- * Tool failures are data at the public boundary. The result payload uses the
1863
- * same discriminated union as runtime tool adapters, allowing log consumers to
1864
- * render successful outputs and normalized errors exhaustively.
1865
- */
1866
- export interface ToolResultEvent {
1867
- /** Discriminant for event rendering and exhaustive switches. */
1868
- readonly type: "tool-result";
1869
- /** Stable run id shared by all events in one workflow. */
1870
- readonly runId: string;
1871
- /** ISO-8601 event timestamp. */
1872
- readonly at: string;
1873
- /** Stable tool call id within the run. */
1874
- readonly toolCallId: string;
1875
- /** Tool identity that produced the result. */
1876
- readonly tool: RuntimeToolIdentity;
1877
- /** Normalized JSON-serializable tool result. */
1878
- readonly result: RuntimeToolResult;
1879
- /** Agent that requested the tool, when agent-scoped. */
1880
- readonly agentId?: string;
1881
- /** Agent role that requested the tool, when available. */
1882
- readonly role?: string;
1883
- }
1884
-
1885
- /**
1886
- * Provider-normalized participation decision parsed from paper-style agent output.
1887
- *
1888
- * @remarks
1889
- * Dogpile preserves the raw model text on transcript entries and events. When
1890
- * a model emits the labeled fields `role_selected`, `participation`,
1891
- * `rationale`, and `contribution`, protocols also attach this structured
1892
- * metadata so reproduction harnesses can distinguish contribution from
1893
- * voluntary abstention without reparsing raw text.
1894
- */
1895
- export interface AgentDecision {
1896
- /** Task-specific role selected by the agent for this turn. */
1897
- readonly selectedRole: string;
1898
- /** Whether the agent contributed or voluntarily abstained. */
1899
- readonly participation: AgentParticipation;
1900
- /** Agent-provided rationale for the selected role and participation choice. */
1901
- readonly rationale: string;
1902
- /** Agent-provided contribution text, or abstention explanation. */
1903
- readonly contribution: string;
1904
- }
1905
-
1906
- /**
1907
- * Agent participation state for a paper-style turn decision.
1908
- */
1909
- export type AgentParticipation = "contribute" | "abstain";
1910
-
1911
- /**
1912
- * Event emitted after one agent contributes a model turn.
1913
- *
1914
- * @remarks
1915
- * `agent-turn` is the primary streaming payload for sequential, coordinator,
1916
- * shared-state, and broadcast executions. It captures the exact prompt/input
1917
- * Dogpile supplied to the agent, the text returned by the model provider, and
1918
- * the cumulative cost after applying that response.
1919
- *
1920
- * The corresponding durable transcript record contains the same
1921
- * `agentId`/`role`/`input`/`output` contribution without event timing or cost
1922
- * fields. Use this event for live progress UIs and the transcript for replay
1923
- * or downstream application logic.
1924
- *
1925
- * Payload shape:
1926
- *
1927
- * - `type`: always `agent-turn`.
1928
- * - `runId`: stable id shared by every event and trace object for the run.
1929
- * - `at`: ISO-8601 timestamp for when the turn completed.
1930
- * - `agentId` and `role`: identify the contributing agent.
1931
- * - `input`: prompt text visible to that agent for this turn.
1932
- * - `output`: generated model text produced by the agent.
1933
- * - `cost`: cumulative token and spend accounting after this turn.
1934
- */
1935
- export interface TurnEvent {
1936
- /** Discriminant for event rendering and exhaustive switches. */
1937
- readonly type: "agent-turn";
1938
- /** Stable run id shared by all events in one workflow. */
1939
- readonly runId: string;
1940
- /** ISO-8601 event timestamp. */
1941
- readonly at: string;
1942
- /** Agent that produced this turn. */
1943
- readonly agentId: string;
1944
- /** Agent role for this turn. */
1945
- readonly role: string;
1946
- /** Prompt/input visible to the agent for this turn. */
1947
- readonly input: string;
1948
- /** Model output produced by the agent. */
1949
- readonly output: string;
1950
- /** Optional structured role/participation decision parsed from model output. */
1951
- readonly decision?: AgentDecision;
1952
- /** Cumulative cost after this turn. */
1953
- readonly cost: CostSummary;
1954
- }
1955
-
1956
- /**
1957
- * One independent contribution captured by a broadcast round event.
1958
- *
1959
- * @remarks
1960
- * Broadcast protocols collect one contribution per participating agent before
1961
- * synthesis. The contribution payload is intentionally smaller than
1962
- * {@link TurnEvent}: it is a round-level summary of model outputs, while the
1963
- * complete prompt/output pair for each agent is still available as individual
1964
- * `agent-turn` events and {@link TranscriptEntry} records.
1965
- *
1966
- * Payload shape:
1967
- *
1968
- * - `agentId`: stable id of the contributing agent.
1969
- * - `role`: model-visible role or perspective used for that contribution.
1970
- * - `output`: generated text contributed independently for the round.
1971
- */
1972
- export interface BroadcastContribution {
1973
- /** Agent that produced the broadcast contribution. */
1974
- readonly agentId: string;
1975
- /** Agent role for the contribution. */
1976
- readonly role: string;
1977
- /** Independent model output produced for the shared mission. */
1978
- readonly output: string;
1979
- /** Optional structured role/participation decision parsed from model output. */
1980
- readonly decision?: AgentDecision;
1981
- }
1982
-
1983
- /**
1984
- * Event emitted after agents broadcast independent contributions for a round.
1985
- *
1986
- * @remarks
1987
- * A `broadcast` event marks the coordination moment where independently
1988
- * generated agent outputs are gathered for a shared round. It does not replace
1989
- * per-agent `agent-turn` events; instead, it groups their outputs by round so
1990
- * observers can render the broadcast barrier and replay the paper protocol's
1991
- * independent-contribution step.
1992
- *
1993
- * Payload shape:
1994
- *
1995
- * - `type`: always `broadcast`.
1996
- * - `runId`: stable id shared by every event and trace object for the run.
1997
- * - `at`: ISO-8601 timestamp for when the round finished.
1998
- * - `round`: one-based broadcast round number.
1999
- * - `contributions`: independent outputs collected for this round.
2000
- * - `cost`: cumulative token and spend accounting after the round.
2001
- */
2002
- export interface BroadcastEvent {
2003
- /** Discriminant for event rendering and exhaustive switches. */
2004
- readonly type: "broadcast";
2005
- /** Stable run id shared by all events in one workflow. */
2006
- readonly runId: string;
2007
- /** ISO-8601 event timestamp. */
2008
- readonly at: string;
2009
- /** One-based broadcast round number. */
2010
- readonly round: number;
2011
- /** Independent contributions collected in this broadcast round. */
2012
- readonly contributions: readonly BroadcastContribution[];
2013
- /** Cumulative cost after this broadcast round. */
2014
- readonly cost: CostSummary;
2015
- }
2016
-
2017
- /**
2018
- * Event emitted when a workflow halts because a configured budget cap fired.
2019
- *
2020
- * @remarks
2021
- * `budget-stop` records the normalized cap class that stopped execution before
2022
- * the final event closes the run. The detail object is JSON-serializable so
2023
- * callers can persist or replay the exact cap, observed value, and limit.
2024
- */
2025
- export interface BudgetStopEvent {
2026
- /** Discriminant for event rendering and exhaustive switches. */
2027
- readonly type: "budget-stop";
2028
- /** Stable run id shared by all events in one workflow. */
2029
- readonly runId: string;
2030
- /** ISO-8601 event timestamp. */
2031
- readonly at: string;
2032
- /** Normalized machine-readable budget stop reason. */
2033
- readonly reason: BudgetStopReason;
2034
- /** Total cost at the stop point. */
2035
- readonly cost: CostSummary;
2036
- /** Completed model-turn iterations at the stop point. */
2037
- readonly iteration: number;
2038
- /** Elapsed runtime in milliseconds at the stop point. */
2039
- readonly elapsedMs: number;
2040
- /** Serializable cap diagnostics. */
2041
- readonly detail: JsonObject;
2042
- }
2043
-
2044
- /**
2045
- * Link from a terminal event to the completed trace transcript.
2046
- *
2047
- * @remarks
2048
- * Final events are emitted before callers await {@link StreamHandle.result},
2049
- * so this compact link tells streaming UIs exactly which transcript artifact
2050
- * the terminal output closes over without duplicating every transcript entry
2051
- * inside the event log.
2052
- */
2053
- export interface TranscriptLink {
2054
- /** Discriminant for future transcript link variants. */
2055
- readonly kind: "trace-transcript";
2056
- /** Number of transcript entries included in the completed trace. */
2057
- readonly entryCount: number;
2058
- /** Zero-based index of the last transcript entry, or `null` for empty runs. */
2059
- readonly lastEntryIndex: number | null;
2060
- }
2061
-
2062
- /**
2063
- * Event emitted when a workflow produces its final output.
2064
- *
2065
- * @remarks
2066
- * `final` is the terminal streaming event for a successful run. Its `output`
2067
- * value matches {@link RunResult.output}, and its `cost` value matches the
2068
- * final aggregate cost returned on the result. Its `transcript` link points to
2069
- * the completed {@link Trace.transcript} entries that produced the terminal
2070
- * output.
2071
- *
2072
- * Payload shape:
2073
- *
2074
- * - `type`: always `final`.
2075
- * - `runId`: stable id shared by every event and trace object for the run.
2076
- * - `at`: ISO-8601 timestamp for when final synthesis completed.
2077
- * - `output`: final synthesized answer returned to the caller.
2078
- * - `cost`: total token and spend accounting for the run.
2079
- * - `transcript`: compact link to the completed trace transcript.
2080
- */
2081
- export interface FinalEvent {
2082
- /** Discriminant for event rendering and exhaustive switches. */
2083
- readonly type: "final";
2084
- /** Stable run id shared by all events in one workflow. */
2085
- readonly runId: string;
2086
- /** ISO-8601 event timestamp. */
2087
- readonly at: string;
2088
- /** Final synthesized answer returned as `RunResult.output`. */
2089
- readonly output: string;
2090
- /** Total cost at completion. */
2091
- readonly cost: CostSummary;
2092
- /** Link to the completed trace transcript. */
2093
- readonly transcript: TranscriptLink;
2094
- /** Optional normalized quality score supplied by a caller-owned evaluator. */
2095
- readonly quality?: NormalizedQualityScore;
2096
- /** Optional serializable evaluation payload supplied by a caller-owned evaluator. */
2097
- readonly evaluation?: RunEvaluation;
2098
- /** Termination condition that stopped the run, when the run ended by policy. */
2099
- readonly termination?: TerminationStopRecord;
2100
- }
2101
-
2102
- /**
2103
- * Successful coordination event emitted by Dogpile and persisted in traces.
2104
- *
2105
- * @remarks
2106
- * `RunEvent` is the discriminated union stored in {@link Trace.events} and
2107
- * used by low-level protocol emit callbacks. Switch on `type` to handle each
2108
- * coordination moment exhaustively:
2109
- *
2110
- * - `role-assignment`: participant/role roster was established.
2111
- * - `model-request`: one provider-neutral model request was started.
2112
- * - `model-response`: one provider-neutral model response completed.
2113
- * - `model-output-chunk`: one streaming model text delta arrived.
2114
- * - `tool-call`: one runtime tool invocation was started.
2115
- * - `tool-result`: one runtime tool invocation completed.
2116
- * - `agent-turn`: one agent completed a prompt/response turn.
2117
- * - `broadcast`: a broadcast round gathered independent contributions.
2118
- * - `budget-stop`: a configured budget cap halted further model turns.
2119
- * - `final`: the run completed and produced the final output.
2120
- *
2121
- * Every variant is JSON-serializable and includes `runId` plus an ISO-8601
2122
- * `at` timestamp so callers can persist, render, or replay the event log
2123
- * without SDK-owned storage.
2124
- *
2125
- * @example
2126
- * ```ts
2127
- * for await (const event of Dogpile.stream(options)) {
2128
- * switch (event.type) {
2129
- * case "agent-turn":
2130
- * console.log(event.agentId, event.output);
2131
- * break;
2132
- * case "final":
2133
- * console.log(event.output);
2134
- * break;
2135
- * }
2136
- * }
2137
- * ```
2138
- */
2139
- export type RunEvent =
2140
- | RoleAssignmentEvent
2141
- | ModelRequestEvent
2142
- | ModelResponseEvent
2143
- | ModelOutputChunkEvent
2144
- | ToolCallEvent
2145
- | ToolResultEvent
2146
- | TurnEvent
2147
- | BroadcastEvent
2148
- | BudgetStopEvent
2149
- | FinalEvent;
2150
-
2151
- /**
2152
- * Model activity events yielded by `stream()` and persisted in traces when a
2153
- * protocol exposes provider-call boundaries.
2154
- */
2155
- export type ModelActivityEvent = ModelRequestEvent | ModelResponseEvent | ModelOutputChunkEvent;
2156
-
2157
- /**
2158
- * Tool activity events yielded by `stream()` and persisted in traces when a
2159
- * protocol or caller-owned adapter invokes runtime tools.
2160
- */
2161
- export type ToolActivityEvent = ToolCallEvent | ToolResultEvent;
2162
-
2163
- /**
2164
- * Lifecycle event yielded by `stream()`.
2165
- *
2166
- * These events describe workflow coordination state rather than model text.
2167
- * Role assignment establishes the participant roster, while `budget-stop`
2168
- * records a lifecycle halt before the terminal completion event.
2169
- */
2170
- export type StreamLifecycleEvent = RoleAssignmentEvent | BudgetStopEvent;
2171
-
2172
- /**
2173
- * Output event yielded by `stream()`.
2174
- *
2175
- * These events carry generated agent output or grouped round output while a
2176
- * workflow is still running.
2177
- */
2178
- export type StreamOutputEvent = ModelActivityEvent | ToolActivityEvent | TurnEvent | BroadcastEvent;
2179
-
2180
- /**
2181
- * Error event yielded by `stream()` when execution rejects.
2182
- *
2183
- * @remarks
2184
- * Stream errors are emitted before {@link StreamHandle.result} rejects so UIs
2185
- * and log collectors can record a terminal failure without wrapping the result
2186
- * promise. The error payload is JSON-serializable and intentionally omits
2187
- * runtime-specific values such as `Error.stack`.
2188
- */
2189
- export interface StreamErrorEvent {
2190
- /** Discriminant for stream event handling. */
2191
- readonly type: "error";
2192
- /** Stable run id when known; empty when failure happened before protocol startup. */
2193
- readonly runId: string;
2194
- /** ISO-8601 event timestamp. */
2195
- readonly at: string;
2196
- /** Error name when available. */
2197
- readonly name: string;
2198
- /** Human-readable error message. */
2199
- readonly message: string;
2200
- /** Optional serializable diagnostics supplied by the SDK. */
2201
- readonly detail?: JsonObject;
2202
- }
2203
-
2204
- /**
2205
- * Completion event yielded by `stream()` after successful execution.
2206
- */
2207
- export type StreamCompletionEvent = FinalEvent;
2208
-
2209
- /**
2210
- * Public streaming event union returned by `stream()`.
2211
- *
2212
- * @remarks
2213
- * The union is grouped into lifecycle, output, error, and completion families:
2214
- *
2215
- * - lifecycle: {@link StreamLifecycleEvent}
2216
- * - output: {@link StreamOutputEvent}
2217
- * - error: {@link StreamErrorEvent}
2218
- * - completion: {@link StreamCompletionEvent}
2219
- *
2220
- * Successful stream events are also persisted as {@link RunEvent} values in the
2221
- * completed trace. `error` is stream-only because a failed run has no completed
2222
- * {@link RunResult} trace to return.
2223
- */
2224
- export type StreamEvent = StreamLifecycleEvent | StreamOutputEvent | StreamErrorEvent | StreamCompletionEvent;
2225
1335
 
2226
1336
  /**
2227
1337
  * Lifecycle status for a live {@link StreamHandle}.