@defai.digital/contracts 13.0.3 → 13.1.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.
@@ -21,6 +21,18 @@ export declare const DEFAULT_PROVIDER_TIMEOUT = 60000;
21
21
  export declare const MAX_PROVIDER_TIMEOUT = 300000;
22
22
  /** Default providers for discussions */
23
23
  export declare const DEFAULT_PROVIDERS: readonly ["claude", "glm", "qwen", "gemini"];
24
+ /** Maximum discussion depth for recursive discussions */
25
+ export declare const MAX_DISCUSSION_DEPTH = 4;
26
+ /** Default discussion depth */
27
+ export declare const DEFAULT_DISCUSSION_DEPTH = 2;
28
+ /** Minimum time reserved for synthesis at each level (ms) */
29
+ export declare const MIN_SYNTHESIS_TIME_MS = 10000;
30
+ /** Default total budget for recursive discussions (ms) */
31
+ export declare const DEFAULT_TOTAL_BUDGET_MS = 180000;
32
+ /** Default maximum total provider calls across nested discussions */
33
+ export declare const DEFAULT_MAX_TOTAL_CALLS = 20;
34
+ /** Default cascading confidence threshold for early exit */
35
+ export declare const DEFAULT_CONFIDENCE_THRESHOLD = 0.9;
24
36
  /**
25
37
  * Discussion patterns supported by the system
26
38
  *
@@ -100,6 +112,33 @@ export type ProviderCapability = z.infer<typeof ProviderCapabilitySchema>;
100
112
  * Provider strength mapping (for routing decisions)
101
113
  */
102
114
  export declare const PROVIDER_STRENGTHS: Record<string, ProviderCapability[]>;
115
+ /**
116
+ * Participant in a discussion (provider or agent)
117
+ *
118
+ * Invariants:
119
+ * - INV-DISC-640: Agent participants use providerAffinity.preferred[0]
120
+ * - INV-DISC-641: Agent abilities injected with max 10K tokens
121
+ */
122
+ export declare const DiscussionParticipantSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
123
+ type: z.ZodLiteral<"provider">;
124
+ id: z.ZodString;
125
+ }, "strip", z.ZodTypeAny, {
126
+ type: "provider";
127
+ id: string;
128
+ }, {
129
+ type: "provider";
130
+ id: string;
131
+ }>, z.ZodObject<{
132
+ type: z.ZodLiteral<"agent">;
133
+ id: z.ZodString;
134
+ }, "strip", z.ZodTypeAny, {
135
+ type: "agent";
136
+ id: string;
137
+ }, {
138
+ type: "agent";
139
+ id: string;
140
+ }>]>;
141
+ export type DiscussionParticipant = z.infer<typeof DiscussionParticipantSchema>;
103
142
  /**
104
143
  * Configuration for a discuss workflow step
105
144
  *
@@ -171,6 +210,28 @@ export declare const DiscussStepConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodObj
171
210
  verbose: z.ZodDefault<z.ZodBoolean>;
172
211
  /** Additional context for all providers */
173
212
  context: z.ZodOptional<z.ZodString>;
213
+ /** Mix of providers and agents as participants (alternative to providers array) */
214
+ participants: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
215
+ type: z.ZodLiteral<"provider">;
216
+ id: z.ZodString;
217
+ }, "strip", z.ZodTypeAny, {
218
+ type: "provider";
219
+ id: string;
220
+ }, {
221
+ type: "provider";
222
+ id: string;
223
+ }>, z.ZodObject<{
224
+ type: z.ZodLiteral<"agent">;
225
+ id: z.ZodString;
226
+ }, "strip", z.ZodTypeAny, {
227
+ type: "agent";
228
+ id: string;
229
+ }, {
230
+ type: "agent";
231
+ id: string;
232
+ }>]>, "many">>;
233
+ /** Weight multiplier for agent responses in consensus (default: 1.5x) */
234
+ agentWeightMultiplier: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
174
235
  }, "strip", z.ZodTypeAny, {
175
236
  prompt: string;
176
237
  pattern: "round-robin" | "debate" | "critique" | "voting" | "synthesis";
@@ -188,13 +249,28 @@ export declare const DiscussStepConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodObj
188
249
  providerTimeout: number;
189
250
  continueOnProviderFailure: boolean;
190
251
  minProviders: number;
252
+ agentWeightMultiplier: number;
191
253
  context?: string | undefined;
254
+ participants?: ({
255
+ type: "provider";
256
+ id: string;
257
+ } | {
258
+ type: "agent";
259
+ id: string;
260
+ })[] | undefined;
192
261
  providerPrompts?: Record<string, string> | undefined;
193
262
  roles?: Record<string, "moderator" | "proponent" | "opponent" | "judge" | "neutral"> | undefined;
194
263
  }, {
195
264
  prompt: string;
196
265
  providers: string[];
197
266
  context?: string | undefined;
267
+ participants?: ({
268
+ type: "provider";
269
+ id: string;
270
+ } | {
271
+ type: "agent";
272
+ id: string;
273
+ })[] | undefined;
198
274
  pattern?: "round-robin" | "debate" | "critique" | "voting" | "synthesis" | undefined;
199
275
  rounds?: number | undefined;
200
276
  temperature?: number | undefined;
@@ -211,6 +287,7 @@ export declare const DiscussStepConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodObj
211
287
  providerTimeout?: number | undefined;
212
288
  continueOnProviderFailure?: boolean | undefined;
213
289
  minProviders?: number | undefined;
290
+ agentWeightMultiplier?: number | undefined;
214
291
  }>, {
215
292
  prompt: string;
216
293
  pattern: "round-robin" | "debate" | "critique" | "voting" | "synthesis";
@@ -228,13 +305,28 @@ export declare const DiscussStepConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodObj
228
305
  providerTimeout: number;
229
306
  continueOnProviderFailure: boolean;
230
307
  minProviders: number;
308
+ agentWeightMultiplier: number;
231
309
  context?: string | undefined;
310
+ participants?: ({
311
+ type: "provider";
312
+ id: string;
313
+ } | {
314
+ type: "agent";
315
+ id: string;
316
+ })[] | undefined;
232
317
  providerPrompts?: Record<string, string> | undefined;
233
318
  roles?: Record<string, "moderator" | "proponent" | "opponent" | "judge" | "neutral"> | undefined;
234
319
  }, {
235
320
  prompt: string;
236
321
  providers: string[];
237
322
  context?: string | undefined;
323
+ participants?: ({
324
+ type: "provider";
325
+ id: string;
326
+ } | {
327
+ type: "agent";
328
+ id: string;
329
+ })[] | undefined;
238
330
  pattern?: "round-robin" | "debate" | "critique" | "voting" | "synthesis" | undefined;
239
331
  rounds?: number | undefined;
240
332
  temperature?: number | undefined;
@@ -251,6 +343,7 @@ export declare const DiscussStepConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodObj
251
343
  providerTimeout?: number | undefined;
252
344
  continueOnProviderFailure?: boolean | undefined;
253
345
  minProviders?: number | undefined;
346
+ agentWeightMultiplier?: number | undefined;
254
347
  }>, {
255
348
  prompt: string;
256
349
  pattern: "round-robin" | "debate" | "critique" | "voting" | "synthesis";
@@ -268,13 +361,28 @@ export declare const DiscussStepConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodObj
268
361
  providerTimeout: number;
269
362
  continueOnProviderFailure: boolean;
270
363
  minProviders: number;
364
+ agentWeightMultiplier: number;
271
365
  context?: string | undefined;
366
+ participants?: ({
367
+ type: "provider";
368
+ id: string;
369
+ } | {
370
+ type: "agent";
371
+ id: string;
372
+ })[] | undefined;
272
373
  providerPrompts?: Record<string, string> | undefined;
273
374
  roles?: Record<string, "moderator" | "proponent" | "opponent" | "judge" | "neutral"> | undefined;
274
375
  }, {
275
376
  prompt: string;
276
377
  providers: string[];
277
378
  context?: string | undefined;
379
+ participants?: ({
380
+ type: "provider";
381
+ id: string;
382
+ } | {
383
+ type: "agent";
384
+ id: string;
385
+ })[] | undefined;
278
386
  pattern?: "round-robin" | "debate" | "critique" | "voting" | "synthesis" | undefined;
279
387
  rounds?: number | undefined;
280
388
  temperature?: number | undefined;
@@ -291,6 +399,7 @@ export declare const DiscussStepConfigSchema: z.ZodEffects<z.ZodEffects<z.ZodObj
291
399
  providerTimeout?: number | undefined;
292
400
  continueOnProviderFailure?: boolean | undefined;
293
401
  minProviders?: number | undefined;
402
+ agentWeightMultiplier?: number | undefined;
294
403
  }>;
295
404
  export type DiscussStepConfig = z.infer<typeof DiscussStepConfigSchema>;
296
405
  /**
@@ -320,30 +429,38 @@ export declare const DiscussionProviderResponseSchema: z.ZodObject<{
320
429
  truncated: z.ZodOptional<z.ZodBoolean>;
321
430
  /** Error if response failed */
322
431
  error: z.ZodOptional<z.ZodString>;
432
+ /** Whether response is from an agent (vs raw provider) */
433
+ isAgent: z.ZodOptional<z.ZodBoolean>;
434
+ /** Agent ID if response is from an agent */
435
+ agentId: z.ZodOptional<z.ZodString>;
323
436
  }, "strip", z.ZodTypeAny, {
324
437
  timestamp: string;
325
438
  durationMs: number;
326
439
  content: string;
327
440
  provider: string;
328
441
  round: number;
442
+ agentId?: string | undefined;
329
443
  error?: string | undefined;
330
444
  role?: "moderator" | "proponent" | "opponent" | "judge" | "neutral" | undefined;
331
445
  tokenCount?: number | undefined;
332
446
  truncated?: boolean | undefined;
333
447
  confidence?: number | undefined;
334
448
  vote?: string | undefined;
449
+ isAgent?: boolean | undefined;
335
450
  }, {
336
451
  timestamp: string;
337
452
  durationMs: number;
338
453
  content: string;
339
454
  provider: string;
340
455
  round: number;
456
+ agentId?: string | undefined;
341
457
  error?: string | undefined;
342
458
  role?: "moderator" | "proponent" | "opponent" | "judge" | "neutral" | undefined;
343
459
  tokenCount?: number | undefined;
344
460
  truncated?: boolean | undefined;
345
461
  confidence?: number | undefined;
346
462
  vote?: string | undefined;
463
+ isAgent?: boolean | undefined;
347
464
  }>;
348
465
  export type DiscussionProviderResponse = z.infer<typeof DiscussionProviderResponseSchema>;
349
466
  /**
@@ -376,30 +493,38 @@ export declare const DiscussionRoundSchema: z.ZodObject<{
376
493
  truncated: z.ZodOptional<z.ZodBoolean>;
377
494
  /** Error if response failed */
378
495
  error: z.ZodOptional<z.ZodString>;
496
+ /** Whether response is from an agent (vs raw provider) */
497
+ isAgent: z.ZodOptional<z.ZodBoolean>;
498
+ /** Agent ID if response is from an agent */
499
+ agentId: z.ZodOptional<z.ZodString>;
379
500
  }, "strip", z.ZodTypeAny, {
380
501
  timestamp: string;
381
502
  durationMs: number;
382
503
  content: string;
383
504
  provider: string;
384
505
  round: number;
506
+ agentId?: string | undefined;
385
507
  error?: string | undefined;
386
508
  role?: "moderator" | "proponent" | "opponent" | "judge" | "neutral" | undefined;
387
509
  tokenCount?: number | undefined;
388
510
  truncated?: boolean | undefined;
389
511
  confidence?: number | undefined;
390
512
  vote?: string | undefined;
513
+ isAgent?: boolean | undefined;
391
514
  }, {
392
515
  timestamp: string;
393
516
  durationMs: number;
394
517
  content: string;
395
518
  provider: string;
396
519
  round: number;
520
+ agentId?: string | undefined;
397
521
  error?: string | undefined;
398
522
  role?: "moderator" | "proponent" | "opponent" | "judge" | "neutral" | undefined;
399
523
  tokenCount?: number | undefined;
400
524
  truncated?: boolean | undefined;
401
525
  confidence?: number | undefined;
402
526
  vote?: string | undefined;
527
+ isAgent?: boolean | undefined;
403
528
  }>, "many">;
404
529
  /** Round summary (if generated) */
405
530
  summary: z.ZodOptional<z.ZodString>;
@@ -414,12 +539,14 @@ export declare const DiscussionRoundSchema: z.ZodObject<{
414
539
  content: string;
415
540
  provider: string;
416
541
  round: number;
542
+ agentId?: string | undefined;
417
543
  error?: string | undefined;
418
544
  role?: "moderator" | "proponent" | "opponent" | "judge" | "neutral" | undefined;
419
545
  tokenCount?: number | undefined;
420
546
  truncated?: boolean | undefined;
421
547
  confidence?: number | undefined;
422
548
  vote?: string | undefined;
549
+ isAgent?: boolean | undefined;
423
550
  }[];
424
551
  summary?: string | undefined;
425
552
  }, {
@@ -431,12 +558,14 @@ export declare const DiscussionRoundSchema: z.ZodObject<{
431
558
  content: string;
432
559
  provider: string;
433
560
  round: number;
561
+ agentId?: string | undefined;
434
562
  error?: string | undefined;
435
563
  role?: "moderator" | "proponent" | "opponent" | "judge" | "neutral" | undefined;
436
564
  tokenCount?: number | undefined;
437
565
  truncated?: boolean | undefined;
438
566
  confidence?: number | undefined;
439
567
  vote?: string | undefined;
568
+ isAgent?: boolean | undefined;
440
569
  }[];
441
570
  summary?: string | undefined;
442
571
  }>;
@@ -621,6 +750,83 @@ export declare const DiscussionErrorSchema: z.ZodObject<{
621
750
  provider?: string | undefined;
622
751
  }>;
623
752
  export type DiscussionError = z.infer<typeof DiscussionErrorSchema>;
753
+ /**
754
+ * Cost summary for discussion tracking
755
+ *
756
+ * Invariants:
757
+ * - INV-DISC-620: Total calls ≤ maxTotalCalls
758
+ * - INV-DISC-621: Abort if cost budget exceeded
759
+ * - INV-DISC-644: Cost summary included when tracking enabled
760
+ */
761
+ export declare const CostSummarySchema: z.ZodObject<{
762
+ /** Total provider calls made */
763
+ totalCalls: z.ZodNumber;
764
+ /** Total tokens used */
765
+ totalTokens: z.ZodNumber;
766
+ /** Estimated cost in USD */
767
+ estimatedCostUsd: z.ZodNumber;
768
+ /** Breakdown by provider */
769
+ byProvider: z.ZodRecord<z.ZodString, z.ZodObject<{
770
+ calls: z.ZodNumber;
771
+ tokens: z.ZodNumber;
772
+ cost: z.ZodNumber;
773
+ }, "strip", z.ZodTypeAny, {
774
+ tokens: number;
775
+ cost: number;
776
+ calls: number;
777
+ }, {
778
+ tokens: number;
779
+ cost: number;
780
+ calls: number;
781
+ }>>;
782
+ }, "strip", z.ZodTypeAny, {
783
+ totalTokens: number;
784
+ byProvider: Record<string, {
785
+ tokens: number;
786
+ cost: number;
787
+ calls: number;
788
+ }>;
789
+ totalCalls: number;
790
+ estimatedCostUsd: number;
791
+ }, {
792
+ totalTokens: number;
793
+ byProvider: Record<string, {
794
+ tokens: number;
795
+ cost: number;
796
+ calls: number;
797
+ }>;
798
+ totalCalls: number;
799
+ estimatedCostUsd: number;
800
+ }>;
801
+ export type CostSummary = z.infer<typeof CostSummarySchema>;
802
+ /**
803
+ * Early exit decision info
804
+ *
805
+ * Invariants:
806
+ * - INV-DISC-622: Confidence threshold configurable (default 0.9)
807
+ * - INV-DISC-643: Early exit only after minProviders responded
808
+ */
809
+ export declare const EarlyExitInfoSchema: z.ZodObject<{
810
+ /** Whether early exit was triggered */
811
+ triggered: z.ZodBoolean;
812
+ /** Reason for early exit decision */
813
+ reason: z.ZodOptional<z.ZodString>;
814
+ /** Number of providers that had responded when decision was made */
815
+ atProviderCount: z.ZodOptional<z.ZodNumber>;
816
+ /** Confidence score that triggered the exit */
817
+ confidenceScore: z.ZodOptional<z.ZodNumber>;
818
+ }, "strip", z.ZodTypeAny, {
819
+ triggered: boolean;
820
+ reason?: string | undefined;
821
+ atProviderCount?: number | undefined;
822
+ confidenceScore?: number | undefined;
823
+ }, {
824
+ triggered: boolean;
825
+ reason?: string | undefined;
826
+ atProviderCount?: number | undefined;
827
+ confidenceScore?: number | undefined;
828
+ }>;
829
+ export type EarlyExitInfo = z.infer<typeof EarlyExitInfoSchema>;
624
830
  /**
625
831
  * Discussion metadata
626
832
  */
@@ -637,6 +843,68 @@ export declare const DiscussionMetadataSchema: z.ZodObject<{
637
843
  sessionId: z.ZodOptional<z.ZodString>;
638
844
  /** Trace ID for debugging */
639
845
  traceId: z.ZodOptional<z.ZodString>;
846
+ /** Cost tracking summary */
847
+ costSummary: z.ZodOptional<z.ZodObject<{
848
+ /** Total provider calls made */
849
+ totalCalls: z.ZodNumber;
850
+ /** Total tokens used */
851
+ totalTokens: z.ZodNumber;
852
+ /** Estimated cost in USD */
853
+ estimatedCostUsd: z.ZodNumber;
854
+ /** Breakdown by provider */
855
+ byProvider: z.ZodRecord<z.ZodString, z.ZodObject<{
856
+ calls: z.ZodNumber;
857
+ tokens: z.ZodNumber;
858
+ cost: z.ZodNumber;
859
+ }, "strip", z.ZodTypeAny, {
860
+ tokens: number;
861
+ cost: number;
862
+ calls: number;
863
+ }, {
864
+ tokens: number;
865
+ cost: number;
866
+ calls: number;
867
+ }>>;
868
+ }, "strip", z.ZodTypeAny, {
869
+ totalTokens: number;
870
+ byProvider: Record<string, {
871
+ tokens: number;
872
+ cost: number;
873
+ calls: number;
874
+ }>;
875
+ totalCalls: number;
876
+ estimatedCostUsd: number;
877
+ }, {
878
+ totalTokens: number;
879
+ byProvider: Record<string, {
880
+ tokens: number;
881
+ cost: number;
882
+ calls: number;
883
+ }>;
884
+ totalCalls: number;
885
+ estimatedCostUsd: number;
886
+ }>>;
887
+ /** Early exit information */
888
+ earlyExit: z.ZodOptional<z.ZodObject<{
889
+ /** Whether early exit was triggered */
890
+ triggered: z.ZodBoolean;
891
+ /** Reason for early exit decision */
892
+ reason: z.ZodOptional<z.ZodString>;
893
+ /** Number of providers that had responded when decision was made */
894
+ atProviderCount: z.ZodOptional<z.ZodNumber>;
895
+ /** Confidence score that triggered the exit */
896
+ confidenceScore: z.ZodOptional<z.ZodNumber>;
897
+ }, "strip", z.ZodTypeAny, {
898
+ triggered: boolean;
899
+ reason?: string | undefined;
900
+ atProviderCount?: number | undefined;
901
+ confidenceScore?: number | undefined;
902
+ }, {
903
+ triggered: boolean;
904
+ reason?: string | undefined;
905
+ atProviderCount?: number | undefined;
906
+ confidenceScore?: number | undefined;
907
+ }>>;
640
908
  }, "strip", z.ZodTypeAny, {
641
909
  completedAt: string;
642
910
  startedAt: string;
@@ -644,6 +912,22 @@ export declare const DiscussionMetadataSchema: z.ZodObject<{
644
912
  traceId?: string | undefined;
645
913
  totalTokens?: number | undefined;
646
914
  estimatedCost?: number | undefined;
915
+ costSummary?: {
916
+ totalTokens: number;
917
+ byProvider: Record<string, {
918
+ tokens: number;
919
+ cost: number;
920
+ calls: number;
921
+ }>;
922
+ totalCalls: number;
923
+ estimatedCostUsd: number;
924
+ } | undefined;
925
+ earlyExit?: {
926
+ triggered: boolean;
927
+ reason?: string | undefined;
928
+ atProviderCount?: number | undefined;
929
+ confidenceScore?: number | undefined;
930
+ } | undefined;
647
931
  }, {
648
932
  completedAt: string;
649
933
  startedAt: string;
@@ -651,6 +935,22 @@ export declare const DiscussionMetadataSchema: z.ZodObject<{
651
935
  traceId?: string | undefined;
652
936
  totalTokens?: number | undefined;
653
937
  estimatedCost?: number | undefined;
938
+ costSummary?: {
939
+ totalTokens: number;
940
+ byProvider: Record<string, {
941
+ tokens: number;
942
+ cost: number;
943
+ calls: number;
944
+ }>;
945
+ totalCalls: number;
946
+ estimatedCostUsd: number;
947
+ } | undefined;
948
+ earlyExit?: {
949
+ triggered: boolean;
950
+ reason?: string | undefined;
951
+ atProviderCount?: number | undefined;
952
+ confidenceScore?: number | undefined;
953
+ } | undefined;
654
954
  }>;
655
955
  export type DiscussionMetadata = z.infer<typeof DiscussionMetadataSchema>;
656
956
  /**
@@ -699,30 +999,38 @@ export declare const DiscussionResultSchema: z.ZodObject<{
699
999
  truncated: z.ZodOptional<z.ZodBoolean>;
700
1000
  /** Error if response failed */
701
1001
  error: z.ZodOptional<z.ZodString>;
1002
+ /** Whether response is from an agent (vs raw provider) */
1003
+ isAgent: z.ZodOptional<z.ZodBoolean>;
1004
+ /** Agent ID if response is from an agent */
1005
+ agentId: z.ZodOptional<z.ZodString>;
702
1006
  }, "strip", z.ZodTypeAny, {
703
1007
  timestamp: string;
704
1008
  durationMs: number;
705
1009
  content: string;
706
1010
  provider: string;
707
1011
  round: number;
1012
+ agentId?: string | undefined;
708
1013
  error?: string | undefined;
709
1014
  role?: "moderator" | "proponent" | "opponent" | "judge" | "neutral" | undefined;
710
1015
  tokenCount?: number | undefined;
711
1016
  truncated?: boolean | undefined;
712
1017
  confidence?: number | undefined;
713
1018
  vote?: string | undefined;
1019
+ isAgent?: boolean | undefined;
714
1020
  }, {
715
1021
  timestamp: string;
716
1022
  durationMs: number;
717
1023
  content: string;
718
1024
  provider: string;
719
1025
  round: number;
1026
+ agentId?: string | undefined;
720
1027
  error?: string | undefined;
721
1028
  role?: "moderator" | "proponent" | "opponent" | "judge" | "neutral" | undefined;
722
1029
  tokenCount?: number | undefined;
723
1030
  truncated?: boolean | undefined;
724
1031
  confidence?: number | undefined;
725
1032
  vote?: string | undefined;
1033
+ isAgent?: boolean | undefined;
726
1034
  }>, "many">;
727
1035
  /** Round summary (if generated) */
728
1036
  summary: z.ZodOptional<z.ZodString>;
@@ -737,12 +1045,14 @@ export declare const DiscussionResultSchema: z.ZodObject<{
737
1045
  content: string;
738
1046
  provider: string;
739
1047
  round: number;
1048
+ agentId?: string | undefined;
740
1049
  error?: string | undefined;
741
1050
  role?: "moderator" | "proponent" | "opponent" | "judge" | "neutral" | undefined;
742
1051
  tokenCount?: number | undefined;
743
1052
  truncated?: boolean | undefined;
744
1053
  confidence?: number | undefined;
745
1054
  vote?: string | undefined;
1055
+ isAgent?: boolean | undefined;
746
1056
  }[];
747
1057
  summary?: string | undefined;
748
1058
  }, {
@@ -754,12 +1064,14 @@ export declare const DiscussionResultSchema: z.ZodObject<{
754
1064
  content: string;
755
1065
  provider: string;
756
1066
  round: number;
1067
+ agentId?: string | undefined;
757
1068
  error?: string | undefined;
758
1069
  role?: "moderator" | "proponent" | "opponent" | "judge" | "neutral" | undefined;
759
1070
  tokenCount?: number | undefined;
760
1071
  truncated?: boolean | undefined;
761
1072
  confidence?: number | undefined;
762
1073
  vote?: string | undefined;
1074
+ isAgent?: boolean | undefined;
763
1075
  }[];
764
1076
  summary?: string | undefined;
765
1077
  }>, "many">;
@@ -887,6 +1199,68 @@ export declare const DiscussionResultSchema: z.ZodObject<{
887
1199
  sessionId: z.ZodOptional<z.ZodString>;
888
1200
  /** Trace ID for debugging */
889
1201
  traceId: z.ZodOptional<z.ZodString>;
1202
+ /** Cost tracking summary */
1203
+ costSummary: z.ZodOptional<z.ZodObject<{
1204
+ /** Total provider calls made */
1205
+ totalCalls: z.ZodNumber;
1206
+ /** Total tokens used */
1207
+ totalTokens: z.ZodNumber;
1208
+ /** Estimated cost in USD */
1209
+ estimatedCostUsd: z.ZodNumber;
1210
+ /** Breakdown by provider */
1211
+ byProvider: z.ZodRecord<z.ZodString, z.ZodObject<{
1212
+ calls: z.ZodNumber;
1213
+ tokens: z.ZodNumber;
1214
+ cost: z.ZodNumber;
1215
+ }, "strip", z.ZodTypeAny, {
1216
+ tokens: number;
1217
+ cost: number;
1218
+ calls: number;
1219
+ }, {
1220
+ tokens: number;
1221
+ cost: number;
1222
+ calls: number;
1223
+ }>>;
1224
+ }, "strip", z.ZodTypeAny, {
1225
+ totalTokens: number;
1226
+ byProvider: Record<string, {
1227
+ tokens: number;
1228
+ cost: number;
1229
+ calls: number;
1230
+ }>;
1231
+ totalCalls: number;
1232
+ estimatedCostUsd: number;
1233
+ }, {
1234
+ totalTokens: number;
1235
+ byProvider: Record<string, {
1236
+ tokens: number;
1237
+ cost: number;
1238
+ calls: number;
1239
+ }>;
1240
+ totalCalls: number;
1241
+ estimatedCostUsd: number;
1242
+ }>>;
1243
+ /** Early exit information */
1244
+ earlyExit: z.ZodOptional<z.ZodObject<{
1245
+ /** Whether early exit was triggered */
1246
+ triggered: z.ZodBoolean;
1247
+ /** Reason for early exit decision */
1248
+ reason: z.ZodOptional<z.ZodString>;
1249
+ /** Number of providers that had responded when decision was made */
1250
+ atProviderCount: z.ZodOptional<z.ZodNumber>;
1251
+ /** Confidence score that triggered the exit */
1252
+ confidenceScore: z.ZodOptional<z.ZodNumber>;
1253
+ }, "strip", z.ZodTypeAny, {
1254
+ triggered: boolean;
1255
+ reason?: string | undefined;
1256
+ atProviderCount?: number | undefined;
1257
+ confidenceScore?: number | undefined;
1258
+ }, {
1259
+ triggered: boolean;
1260
+ reason?: string | undefined;
1261
+ atProviderCount?: number | undefined;
1262
+ confidenceScore?: number | undefined;
1263
+ }>>;
890
1264
  }, "strip", z.ZodTypeAny, {
891
1265
  completedAt: string;
892
1266
  startedAt: string;
@@ -894,6 +1268,22 @@ export declare const DiscussionResultSchema: z.ZodObject<{
894
1268
  traceId?: string | undefined;
895
1269
  totalTokens?: number | undefined;
896
1270
  estimatedCost?: number | undefined;
1271
+ costSummary?: {
1272
+ totalTokens: number;
1273
+ byProvider: Record<string, {
1274
+ tokens: number;
1275
+ cost: number;
1276
+ calls: number;
1277
+ }>;
1278
+ totalCalls: number;
1279
+ estimatedCostUsd: number;
1280
+ } | undefined;
1281
+ earlyExit?: {
1282
+ triggered: boolean;
1283
+ reason?: string | undefined;
1284
+ atProviderCount?: number | undefined;
1285
+ confidenceScore?: number | undefined;
1286
+ } | undefined;
897
1287
  }, {
898
1288
  completedAt: string;
899
1289
  startedAt: string;
@@ -901,6 +1291,22 @@ export declare const DiscussionResultSchema: z.ZodObject<{
901
1291
  traceId?: string | undefined;
902
1292
  totalTokens?: number | undefined;
903
1293
  estimatedCost?: number | undefined;
1294
+ costSummary?: {
1295
+ totalTokens: number;
1296
+ byProvider: Record<string, {
1297
+ tokens: number;
1298
+ cost: number;
1299
+ calls: number;
1300
+ }>;
1301
+ totalCalls: number;
1302
+ estimatedCostUsd: number;
1303
+ } | undefined;
1304
+ earlyExit?: {
1305
+ triggered: boolean;
1306
+ reason?: string | undefined;
1307
+ atProviderCount?: number | undefined;
1308
+ confidenceScore?: number | undefined;
1309
+ } | undefined;
904
1310
  }>;
905
1311
  /** Error if discussion failed */
906
1312
  error: z.ZodOptional<z.ZodObject<{
@@ -931,6 +1337,22 @@ export declare const DiscussionResultSchema: z.ZodObject<{
931
1337
  traceId?: string | undefined;
932
1338
  totalTokens?: number | undefined;
933
1339
  estimatedCost?: number | undefined;
1340
+ costSummary?: {
1341
+ totalTokens: number;
1342
+ byProvider: Record<string, {
1343
+ tokens: number;
1344
+ cost: number;
1345
+ calls: number;
1346
+ }>;
1347
+ totalCalls: number;
1348
+ estimatedCostUsd: number;
1349
+ } | undefined;
1350
+ earlyExit?: {
1351
+ triggered: boolean;
1352
+ reason?: string | undefined;
1353
+ atProviderCount?: number | undefined;
1354
+ confidenceScore?: number | undefined;
1355
+ } | undefined;
934
1356
  };
935
1357
  success: boolean;
936
1358
  totalDurationMs: number;
@@ -944,12 +1366,14 @@ export declare const DiscussionResultSchema: z.ZodObject<{
944
1366
  content: string;
945
1367
  provider: string;
946
1368
  round: number;
1369
+ agentId?: string | undefined;
947
1370
  error?: string | undefined;
948
1371
  role?: "moderator" | "proponent" | "opponent" | "judge" | "neutral" | undefined;
949
1372
  tokenCount?: number | undefined;
950
1373
  truncated?: boolean | undefined;
951
1374
  confidence?: number | undefined;
952
1375
  vote?: string | undefined;
1376
+ isAgent?: boolean | undefined;
953
1377
  }[];
954
1378
  summary?: string | undefined;
955
1379
  }[];
@@ -995,6 +1419,22 @@ export declare const DiscussionResultSchema: z.ZodObject<{
995
1419
  traceId?: string | undefined;
996
1420
  totalTokens?: number | undefined;
997
1421
  estimatedCost?: number | undefined;
1422
+ costSummary?: {
1423
+ totalTokens: number;
1424
+ byProvider: Record<string, {
1425
+ tokens: number;
1426
+ cost: number;
1427
+ calls: number;
1428
+ }>;
1429
+ totalCalls: number;
1430
+ estimatedCostUsd: number;
1431
+ } | undefined;
1432
+ earlyExit?: {
1433
+ triggered: boolean;
1434
+ reason?: string | undefined;
1435
+ atProviderCount?: number | undefined;
1436
+ confidenceScore?: number | undefined;
1437
+ } | undefined;
998
1438
  };
999
1439
  success: boolean;
1000
1440
  totalDurationMs: number;
@@ -1008,12 +1448,14 @@ export declare const DiscussionResultSchema: z.ZodObject<{
1008
1448
  content: string;
1009
1449
  provider: string;
1010
1450
  round: number;
1451
+ agentId?: string | undefined;
1011
1452
  error?: string | undefined;
1012
1453
  role?: "moderator" | "proponent" | "opponent" | "judge" | "neutral" | undefined;
1013
1454
  tokenCount?: number | undefined;
1014
1455
  truncated?: boolean | undefined;
1015
1456
  confidence?: number | undefined;
1016
1457
  vote?: string | undefined;
1458
+ isAgent?: boolean | undefined;
1017
1459
  }[];
1018
1460
  summary?: string | undefined;
1019
1461
  }[];
@@ -1116,8 +1558,236 @@ export declare const DiscussionErrorCodes: {
1116
1558
  readonly INVALID_CONFIG: "DISCUSSION_INVALID_CONFIG";
1117
1559
  /** Provider not found */
1118
1560
  readonly PROVIDER_NOT_FOUND: "DISCUSSION_PROVIDER_NOT_FOUND";
1561
+ /** Maximum discussion depth exceeded */
1562
+ readonly MAX_DEPTH_EXCEEDED: "DISCUSSION_MAX_DEPTH_EXCEEDED";
1563
+ /** Circular discussion chain detected */
1564
+ readonly CIRCULAR_DISCUSSION: "DISCUSSION_CIRCULAR_DISCUSSION";
1565
+ /** Timeout budget exhausted */
1566
+ readonly BUDGET_EXHAUSTED: "DISCUSSION_BUDGET_EXHAUSTED";
1567
+ /** Maximum total calls exceeded */
1568
+ readonly MAX_CALLS_EXCEEDED: "DISCUSSION_MAX_CALLS_EXCEEDED";
1569
+ /** Cost budget exceeded */
1570
+ readonly COST_BUDGET_EXCEEDED: "DISCUSSION_COST_BUDGET_EXCEEDED";
1119
1571
  };
1120
1572
  export type DiscussionErrorCode = (typeof DiscussionErrorCodes)[keyof typeof DiscussionErrorCodes];
1573
+ /**
1574
+ * Timeout strategy for recursive discussions
1575
+ *
1576
+ * - fixed: Each level gets the same timeout
1577
+ * - cascade: Each level gets reduced timeout (parent × 0.5)
1578
+ * - budget: Total budget divided across levels
1579
+ */
1580
+ export declare const TimeoutStrategySchema: z.ZodEnum<["fixed", "cascade", "budget"]>;
1581
+ export type TimeoutStrategy = z.infer<typeof TimeoutStrategySchema>;
1582
+ /**
1583
+ * Timeout configuration for recursive discussions
1584
+ *
1585
+ * Invariants:
1586
+ * - INV-DISC-610: Child timeout ≤ parent remaining budget
1587
+ * - INV-DISC-611: Minimum time reserved for synthesis
1588
+ * - INV-DISC-612: Total timeout includes all nested calls
1589
+ */
1590
+ export declare const TimeoutConfigSchema: z.ZodObject<{
1591
+ /** Timeout strategy */
1592
+ strategy: z.ZodDefault<z.ZodEnum<["fixed", "cascade", "budget"]>>;
1593
+ /** Total budget in milliseconds */
1594
+ totalBudgetMs: z.ZodDefault<z.ZodNumber>;
1595
+ /** Minimum time reserved for synthesis at each level */
1596
+ minSynthesisMs: z.ZodDefault<z.ZodNumber>;
1597
+ /** Override timeouts per level (optional) */
1598
+ levelTimeouts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
1599
+ }, "strip", z.ZodTypeAny, {
1600
+ strategy: "budget" | "fixed" | "cascade";
1601
+ totalBudgetMs: number;
1602
+ minSynthesisMs: number;
1603
+ levelTimeouts?: Record<string, number> | undefined;
1604
+ }, {
1605
+ strategy?: "budget" | "fixed" | "cascade" | undefined;
1606
+ totalBudgetMs?: number | undefined;
1607
+ minSynthesisMs?: number | undefined;
1608
+ levelTimeouts?: Record<string, number> | undefined;
1609
+ }>;
1610
+ export type TimeoutConfig = z.infer<typeof TimeoutConfigSchema>;
1611
+ /**
1612
+ * Cascading confidence configuration for early exit
1613
+ *
1614
+ * Invariants:
1615
+ * - INV-DISC-622: Threshold configurable (default 0.9)
1616
+ * - INV-DISC-623: Minimum 2 providers for quality
1617
+ */
1618
+ export declare const CascadingConfidenceConfigSchema: z.ZodObject<{
1619
+ /** Enable early exit when first provider is highly confident */
1620
+ enabled: z.ZodDefault<z.ZodBoolean>;
1621
+ /** Confidence threshold for early exit (0-1) */
1622
+ threshold: z.ZodDefault<z.ZodNumber>;
1623
+ /** Minimum providers to call regardless of confidence */
1624
+ minProviders: z.ZodDefault<z.ZodNumber>;
1625
+ }, "strip", z.ZodTypeAny, {
1626
+ enabled: boolean;
1627
+ threshold: number;
1628
+ minProviders: number;
1629
+ }, {
1630
+ enabled?: boolean | undefined;
1631
+ threshold?: number | undefined;
1632
+ minProviders?: number | undefined;
1633
+ }>;
1634
+ export type CascadingConfidenceConfig = z.infer<typeof CascadingConfidenceConfigSchema>;
1635
+ /**
1636
+ * Cost control configuration for recursive discussions
1637
+ *
1638
+ * Invariants:
1639
+ * - INV-DISC-620: Total calls ≤ maxTotalCalls
1640
+ * - INV-DISC-621: Abort if cost budget exceeded
1641
+ */
1642
+ export declare const CostControlConfigSchema: z.ZodObject<{
1643
+ /** Maximum total provider calls across all nested discussions */
1644
+ maxTotalCalls: z.ZodDefault<z.ZodNumber>;
1645
+ /** Optional hard cost limit in USD */
1646
+ budgetUsd: z.ZodOptional<z.ZodNumber>;
1647
+ /** Cascading confidence configuration */
1648
+ cascadingConfidence: z.ZodDefault<z.ZodObject<{
1649
+ /** Enable early exit when first provider is highly confident */
1650
+ enabled: z.ZodDefault<z.ZodBoolean>;
1651
+ /** Confidence threshold for early exit (0-1) */
1652
+ threshold: z.ZodDefault<z.ZodNumber>;
1653
+ /** Minimum providers to call regardless of confidence */
1654
+ minProviders: z.ZodDefault<z.ZodNumber>;
1655
+ }, "strip", z.ZodTypeAny, {
1656
+ enabled: boolean;
1657
+ threshold: number;
1658
+ minProviders: number;
1659
+ }, {
1660
+ enabled?: boolean | undefined;
1661
+ threshold?: number | undefined;
1662
+ minProviders?: number | undefined;
1663
+ }>>;
1664
+ }, "strip", z.ZodTypeAny, {
1665
+ maxTotalCalls: number;
1666
+ cascadingConfidence: {
1667
+ enabled: boolean;
1668
+ threshold: number;
1669
+ minProviders: number;
1670
+ };
1671
+ budgetUsd?: number | undefined;
1672
+ }, {
1673
+ maxTotalCalls?: number | undefined;
1674
+ budgetUsd?: number | undefined;
1675
+ cascadingConfidence?: {
1676
+ enabled?: boolean | undefined;
1677
+ threshold?: number | undefined;
1678
+ minProviders?: number | undefined;
1679
+ } | undefined;
1680
+ }>;
1681
+ export type CostControlConfig = z.infer<typeof CostControlConfigSchema>;
1682
+ /**
1683
+ * Recursive discussion configuration
1684
+ *
1685
+ * Invariants:
1686
+ * - INV-DISC-600: Depth MUST NOT exceed maxDepth
1687
+ * - INV-DISC-601: No circular provider chains
1688
+ * - INV-DISC-602: Root discussion is always depth 0
1689
+ */
1690
+ export declare const RecursiveConfigSchema: z.ZodObject<{
1691
+ /** Enable recursive sub-discussions */
1692
+ enabled: z.ZodDefault<z.ZodBoolean>;
1693
+ /** Maximum discussion depth (1-4) */
1694
+ maxDepth: z.ZodDefault<z.ZodNumber>;
1695
+ /** Providers allowed in sub-discussions (defaults to all) */
1696
+ allowedProviders: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
1697
+ /** Whether providers can spawn sub-discussions */
1698
+ allowSubDiscussions: z.ZodDefault<z.ZodBoolean>;
1699
+ }, "strip", z.ZodTypeAny, {
1700
+ enabled: boolean;
1701
+ maxDepth: number;
1702
+ allowSubDiscussions: boolean;
1703
+ allowedProviders?: string[] | undefined;
1704
+ }, {
1705
+ enabled?: boolean | undefined;
1706
+ maxDepth?: number | undefined;
1707
+ allowedProviders?: string[] | undefined;
1708
+ allowSubDiscussions?: boolean | undefined;
1709
+ }>;
1710
+ export type RecursiveConfig = z.infer<typeof RecursiveConfigSchema>;
1711
+ /**
1712
+ * Discussion context for tracking recursion state
1713
+ *
1714
+ * Invariants:
1715
+ * - INV-DISC-600: depth < maxDepth for sub-discussions
1716
+ * - INV-DISC-601: discussionChain has no duplicates
1717
+ */
1718
+ export declare const DiscussionContextSchema: z.ZodObject<{
1719
+ /** Current discussion depth (0 = root) */
1720
+ depth: z.ZodDefault<z.ZodNumber>;
1721
+ /** Maximum allowed depth */
1722
+ maxDepth: z.ZodDefault<z.ZodNumber>;
1723
+ /** Chain of discussion IDs (for circular detection) */
1724
+ discussionChain: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
1725
+ /** Parent discussion ID (undefined for root) */
1726
+ parentDiscussionId: z.ZodOptional<z.ZodString>;
1727
+ /** Root discussion ID */
1728
+ rootDiscussionId: z.ZodString;
1729
+ /** Remaining timeout budget in milliseconds */
1730
+ remainingBudgetMs: z.ZodNumber;
1731
+ /** Total provider calls made so far */
1732
+ totalCalls: z.ZodDefault<z.ZodNumber>;
1733
+ /** Maximum total calls allowed */
1734
+ maxTotalCalls: z.ZodDefault<z.ZodNumber>;
1735
+ /** When the root discussion started */
1736
+ startedAt: z.ZodString;
1737
+ }, "strip", z.ZodTypeAny, {
1738
+ startedAt: string;
1739
+ maxDepth: number;
1740
+ totalCalls: number;
1741
+ maxTotalCalls: number;
1742
+ depth: number;
1743
+ discussionChain: string[];
1744
+ rootDiscussionId: string;
1745
+ remainingBudgetMs: number;
1746
+ parentDiscussionId?: string | undefined;
1747
+ }, {
1748
+ startedAt: string;
1749
+ rootDiscussionId: string;
1750
+ remainingBudgetMs: number;
1751
+ maxDepth?: number | undefined;
1752
+ totalCalls?: number | undefined;
1753
+ maxTotalCalls?: number | undefined;
1754
+ depth?: number | undefined;
1755
+ discussionChain?: string[] | undefined;
1756
+ parentDiscussionId?: string | undefined;
1757
+ }>;
1758
+ export type DiscussionContext = z.infer<typeof DiscussionContextSchema>;
1759
+ /**
1760
+ * Sub-discussion result embedded in provider response
1761
+ */
1762
+ export declare const SubDiscussionResultSchema: z.ZodObject<{
1763
+ /** Sub-discussion ID */
1764
+ discussionId: z.ZodString;
1765
+ /** Topic of sub-discussion */
1766
+ topic: z.ZodString;
1767
+ /** Providers that participated */
1768
+ participatingProviders: z.ZodArray<z.ZodString, "many">;
1769
+ /** Synthesized result */
1770
+ synthesis: z.ZodString;
1771
+ /** Duration in milliseconds */
1772
+ durationMs: z.ZodNumber;
1773
+ /** Depth at which this occurred */
1774
+ depth: z.ZodNumber;
1775
+ }, "strip", z.ZodTypeAny, {
1776
+ durationMs: number;
1777
+ topic: string;
1778
+ participatingProviders: string[];
1779
+ synthesis: string;
1780
+ depth: number;
1781
+ discussionId: string;
1782
+ }, {
1783
+ durationMs: number;
1784
+ topic: string;
1785
+ participatingProviders: string[];
1786
+ synthesis: string;
1787
+ depth: number;
1788
+ discussionId: string;
1789
+ }>;
1790
+ export type SubDiscussionResult = z.infer<typeof SubDiscussionResultSchema>;
1121
1791
  /**
1122
1792
  * Validates discussion step configuration
1123
1793
  * @throws ZodError if validation fails
@@ -1183,4 +1853,37 @@ export declare function createEmptyDiscussionResult(pattern: DiscussionPattern,
1183
1853
  * Creates a failed discussion result
1184
1854
  */
1185
1855
  export declare function createFailedDiscussionResult(pattern: DiscussionPattern, topic: string, errorCode: DiscussionErrorCode, errorMessage: string, startedAt: string): DiscussionResult;
1856
+ /**
1857
+ * Creates a root discussion context
1858
+ */
1859
+ export declare function createRootDiscussionContext(discussionId: string, config?: {
1860
+ maxDepth?: number;
1861
+ totalBudgetMs?: number;
1862
+ maxTotalCalls?: number;
1863
+ }): DiscussionContext;
1864
+ /**
1865
+ * Creates a child discussion context from a parent context
1866
+ *
1867
+ * @throws Error if max depth exceeded or circular discussion detected
1868
+ */
1869
+ export declare function createChildDiscussionContext(parentContext: DiscussionContext, childDiscussionId: string, elapsedMs: number, callsMade: number): DiscussionContext;
1870
+ /**
1871
+ * Check if sub-discussion is allowed given current context
1872
+ */
1873
+ export declare function canSpawnSubDiscussion(context: DiscussionContext, minBudgetMs?: number): {
1874
+ allowed: boolean;
1875
+ reason?: string;
1876
+ };
1877
+ /**
1878
+ * Calculate timeout for a given depth using cascade strategy
1879
+ */
1880
+ export declare function calculateCascadeTimeout(totalBudgetMs: number, depth: number, minSynthesisMs?: number): number;
1881
+ /**
1882
+ * Calculate timeout for a given depth using budget strategy
1883
+ */
1884
+ export declare function calculateBudgetTimeout(totalBudgetMs: number, maxDepth: number, depth: number, minSynthesisMs?: number): number;
1885
+ /**
1886
+ * Get timeout for a level based on strategy
1887
+ */
1888
+ export declare function getTimeoutForLevel(config: TimeoutConfig, depth: number, maxDepth: number): number;
1186
1889
  //# sourceMappingURL=schema.d.ts.map