@goodtiming/baton-sdk 0.5.8 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
 
3
- declare const SDK_VERSION = "ts-0.5.8";
3
+ declare const SDK_VERSION = "ts-0.6.2";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -119,6 +119,12 @@ declare const SurfaceSnapshotPayloadSchema: z.ZodObject<{
119
119
  seam_augmentations: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
120
120
  }, z.core.$strict>;
121
121
  type SurfaceSnapshotPayload = z.infer<typeof SurfaceSnapshotPayloadSchema>;
122
+ /** This process's lost-event counts by reason, as running totals (SPEC §11.4.7). */
123
+ declare const ClientReportPayloadSchema: z.ZodObject<{
124
+ instance_id: z.ZodUUID;
125
+ dropped: z.ZodRecord<z.ZodString, z.ZodNumber>;
126
+ }, z.core.$strict>;
127
+ type ClientReportPayload = z.infer<typeof ClientReportPayloadSchema>;
122
128
  /**
123
129
  * What the SDK puts in `consent_token` when the vendor names no other value.
124
130
  * Byte-for-byte Python's `baton.events.DEFAULT_CONSENT_TOKEN`, and the two
@@ -161,6 +167,7 @@ declare const EventTypeSchema: z.ZodEnum<{
161
167
  tool_call_error: "tool_call_error";
162
168
  annotation: "annotation";
163
169
  surface_snapshot: "surface_snapshot";
170
+ client_report: "client_report";
164
171
  resource_list_start: "resource_list_start";
165
172
  resource_list_end: "resource_list_end";
166
173
  resource_list_error: "resource_list_error";
@@ -339,6 +346,12 @@ declare const ToolCallStartEventSchema: z.ZodObject<{
339
346
  form: z.ZodString;
340
347
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
341
348
  }, z.core.$strict>>>;
349
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
350
+ id: z.ZodString;
351
+ source: z.ZodString;
352
+ form: z.ZodString;
353
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
354
+ }, z.core.$strict>>>;
342
355
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
343
356
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
344
357
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -378,6 +391,12 @@ declare const ToolCallEndEventSchema: z.ZodObject<{
378
391
  form: z.ZodString;
379
392
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
380
393
  }, z.core.$strict>>>;
394
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
395
+ id: z.ZodString;
396
+ source: z.ZodString;
397
+ form: z.ZodString;
398
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
399
+ }, z.core.$strict>>>;
381
400
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
382
401
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
383
402
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -420,6 +439,12 @@ declare const ToolCallErrorEventSchema: z.ZodObject<{
420
439
  form: z.ZodString;
421
440
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
422
441
  }, z.core.$strict>>>;
442
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
443
+ id: z.ZodString;
444
+ source: z.ZodString;
445
+ form: z.ZodString;
446
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
447
+ }, z.core.$strict>>>;
423
448
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
424
449
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
425
450
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -462,6 +487,12 @@ declare const AnnotationEventSchema: z.ZodObject<{
462
487
  form: z.ZodString;
463
488
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
464
489
  }, z.core.$strict>>>;
490
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
491
+ id: z.ZodString;
492
+ source: z.ZodString;
493
+ form: z.ZodString;
494
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
495
+ }, z.core.$strict>>>;
465
496
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
466
497
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
467
498
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -503,6 +534,12 @@ declare const SurfaceSnapshotEventSchema: z.ZodObject<{
503
534
  form: z.ZodString;
504
535
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
505
536
  }, z.core.$strict>>>;
537
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
538
+ id: z.ZodString;
539
+ source: z.ZodString;
540
+ form: z.ZodString;
541
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
542
+ }, z.core.$strict>>>;
506
543
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
507
544
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
508
545
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -519,6 +556,49 @@ declare const SurfaceSnapshotEventSchema: z.ZodObject<{
519
556
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
520
557
  }, z.core.$strict>;
521
558
  type SurfaceSnapshotEvent = z.infer<typeof SurfaceSnapshotEventSchema>;
559
+ declare const ClientReportEventSchema: z.ZodObject<{
560
+ event_type: z.ZodDefault<z.ZodLiteral<"client_report">>;
561
+ payload: z.ZodObject<{
562
+ instance_id: z.ZodUUID;
563
+ dropped: z.ZodRecord<z.ZodString, z.ZodNumber>;
564
+ }, z.core.$strict>;
565
+ event_id: z.ZodDefault<z.ZodUUID>;
566
+ tenant_id: z.ZodString;
567
+ vendor_id: z.ZodString;
568
+ session_id: z.ZodString;
569
+ sequence_number: z.ZodNumber;
570
+ captured_at: z.ZodString;
571
+ consent_token: z.ZodString;
572
+ sdk_version: z.ZodDefault<z.ZodString>;
573
+ agent_runtime: z.ZodDefault<z.ZodString>;
574
+ principal: z.ZodDefault<z.ZodNullable<z.ZodObject<{
575
+ id: z.ZodString;
576
+ source: z.ZodString;
577
+ form: z.ZodString;
578
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
579
+ }, z.core.$strict>>>;
580
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
581
+ id: z.ZodString;
582
+ source: z.ZodString;
583
+ form: z.ZodString;
584
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
585
+ }, z.core.$strict>>>;
586
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
587
+ session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
588
+ client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
589
+ info: z.ZodOptional<z.ZodObject<{
590
+ name: z.ZodOptional<z.ZodString>;
591
+ version: z.ZodOptional<z.ZodString>;
592
+ }, z.core.$strict>>;
593
+ headers: z.ZodOptional<z.ZodObject<{
594
+ "user-agent": z.ZodOptional<z.ZodString>;
595
+ "x-anthropic-client": z.ZodOptional<z.ZodString>;
596
+ }, z.core.$strict>>;
597
+ }, z.core.$strict>>>;
598
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
599
+ runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
600
+ }, z.core.$strict>;
601
+ type ClientReportEvent = z.infer<typeof ClientReportEventSchema>;
522
602
  declare const ResourceListStartEventSchema: z.ZodObject<{
523
603
  event_type: z.ZodDefault<z.ZodLiteral<"resource_list_start">>;
524
604
  payload: z.ZodObject<{}, z.core.$strict>;
@@ -537,6 +617,12 @@ declare const ResourceListStartEventSchema: z.ZodObject<{
537
617
  form: z.ZodString;
538
618
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
539
619
  }, z.core.$strict>>>;
620
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
621
+ id: z.ZodString;
622
+ source: z.ZodString;
623
+ form: z.ZodString;
624
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
625
+ }, z.core.$strict>>>;
540
626
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
541
627
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
542
628
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -574,6 +660,12 @@ declare const ResourceListEndEventSchema: z.ZodObject<{
574
660
  form: z.ZodString;
575
661
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
576
662
  }, z.core.$strict>>>;
663
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
664
+ id: z.ZodString;
665
+ source: z.ZodString;
666
+ form: z.ZodString;
667
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
668
+ }, z.core.$strict>>>;
577
669
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
578
670
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
579
671
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -612,6 +704,12 @@ declare const ResourceListErrorEventSchema: z.ZodObject<{
612
704
  form: z.ZodString;
613
705
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
614
706
  }, z.core.$strict>>>;
707
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
708
+ id: z.ZodString;
709
+ source: z.ZodString;
710
+ form: z.ZodString;
711
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
712
+ }, z.core.$strict>>>;
615
713
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
616
714
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
617
715
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -649,6 +747,12 @@ declare const ResourceReadStartEventSchema: z.ZodObject<{
649
747
  form: z.ZodString;
650
748
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
651
749
  }, z.core.$strict>>>;
750
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
751
+ id: z.ZodString;
752
+ source: z.ZodString;
753
+ form: z.ZodString;
754
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
755
+ }, z.core.$strict>>>;
652
756
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
653
757
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
654
758
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -686,6 +790,12 @@ declare const ResourceReadEndEventSchema: z.ZodObject<{
686
790
  form: z.ZodString;
687
791
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
688
792
  }, z.core.$strict>>>;
793
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
794
+ id: z.ZodString;
795
+ source: z.ZodString;
796
+ form: z.ZodString;
797
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
798
+ }, z.core.$strict>>>;
689
799
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
690
800
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
691
801
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -725,6 +835,12 @@ declare const ResourceReadErrorEventSchema: z.ZodObject<{
725
835
  form: z.ZodString;
726
836
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
727
837
  }, z.core.$strict>>>;
838
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
839
+ id: z.ZodString;
840
+ source: z.ZodString;
841
+ form: z.ZodString;
842
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
843
+ }, z.core.$strict>>>;
728
844
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
729
845
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
730
846
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -759,6 +875,12 @@ declare const PromptListStartEventSchema: z.ZodObject<{
759
875
  form: z.ZodString;
760
876
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
761
877
  }, z.core.$strict>>>;
878
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
879
+ id: z.ZodString;
880
+ source: z.ZodString;
881
+ form: z.ZodString;
882
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
883
+ }, z.core.$strict>>>;
762
884
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
763
885
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
764
886
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -796,6 +918,12 @@ declare const PromptListEndEventSchema: z.ZodObject<{
796
918
  form: z.ZodString;
797
919
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
798
920
  }, z.core.$strict>>>;
921
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
922
+ id: z.ZodString;
923
+ source: z.ZodString;
924
+ form: z.ZodString;
925
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
926
+ }, z.core.$strict>>>;
799
927
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
800
928
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
801
929
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -834,6 +962,12 @@ declare const PromptListErrorEventSchema: z.ZodObject<{
834
962
  form: z.ZodString;
835
963
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
836
964
  }, z.core.$strict>>>;
965
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
966
+ id: z.ZodString;
967
+ source: z.ZodString;
968
+ form: z.ZodString;
969
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
970
+ }, z.core.$strict>>>;
837
971
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
838
972
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
839
973
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -871,6 +1005,12 @@ declare const PromptGetStartEventSchema: z.ZodObject<{
871
1005
  form: z.ZodString;
872
1006
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
873
1007
  }, z.core.$strict>>>;
1008
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1009
+ id: z.ZodString;
1010
+ source: z.ZodString;
1011
+ form: z.ZodString;
1012
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1013
+ }, z.core.$strict>>>;
874
1014
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
875
1015
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
876
1016
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -908,6 +1048,12 @@ declare const PromptGetEndEventSchema: z.ZodObject<{
908
1048
  form: z.ZodString;
909
1049
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
910
1050
  }, z.core.$strict>>>;
1051
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1052
+ id: z.ZodString;
1053
+ source: z.ZodString;
1054
+ form: z.ZodString;
1055
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1056
+ }, z.core.$strict>>>;
911
1057
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
912
1058
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
913
1059
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -947,6 +1093,12 @@ declare const PromptGetErrorEventSchema: z.ZodObject<{
947
1093
  form: z.ZodString;
948
1094
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
949
1095
  }, z.core.$strict>>>;
1096
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1097
+ id: z.ZodString;
1098
+ source: z.ZodString;
1099
+ form: z.ZodString;
1100
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1101
+ }, z.core.$strict>>>;
950
1102
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
951
1103
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
952
1104
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -981,6 +1133,12 @@ declare const ToolListStartEventSchema: z.ZodObject<{
981
1133
  form: z.ZodString;
982
1134
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
983
1135
  }, z.core.$strict>>>;
1136
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1137
+ id: z.ZodString;
1138
+ source: z.ZodString;
1139
+ form: z.ZodString;
1140
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1141
+ }, z.core.$strict>>>;
984
1142
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
985
1143
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
986
1144
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1018,6 +1176,12 @@ declare const ToolListEndEventSchema: z.ZodObject<{
1018
1176
  form: z.ZodString;
1019
1177
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1020
1178
  }, z.core.$strict>>>;
1179
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1180
+ id: z.ZodString;
1181
+ source: z.ZodString;
1182
+ form: z.ZodString;
1183
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1184
+ }, z.core.$strict>>>;
1021
1185
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1022
1186
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1023
1187
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1056,6 +1220,12 @@ declare const ToolListErrorEventSchema: z.ZodObject<{
1056
1220
  form: z.ZodString;
1057
1221
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1058
1222
  }, z.core.$strict>>>;
1223
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1224
+ id: z.ZodString;
1225
+ source: z.ZodString;
1226
+ form: z.ZodString;
1227
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1228
+ }, z.core.$strict>>>;
1059
1229
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1060
1230
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1061
1231
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1098,6 +1268,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1098
1268
  form: z.ZodString;
1099
1269
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1100
1270
  }, z.core.$strict>>>;
1271
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1272
+ id: z.ZodString;
1273
+ source: z.ZodString;
1274
+ form: z.ZodString;
1275
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1276
+ }, z.core.$strict>>>;
1101
1277
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1102
1278
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1103
1279
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1135,6 +1311,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1135
1311
  form: z.ZodString;
1136
1312
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1137
1313
  }, z.core.$strict>>>;
1314
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1315
+ id: z.ZodString;
1316
+ source: z.ZodString;
1317
+ form: z.ZodString;
1318
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1319
+ }, z.core.$strict>>>;
1138
1320
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1139
1321
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1140
1322
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1175,6 +1357,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1175
1357
  form: z.ZodString;
1176
1358
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1177
1359
  }, z.core.$strict>>>;
1360
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1361
+ id: z.ZodString;
1362
+ source: z.ZodString;
1363
+ form: z.ZodString;
1364
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1365
+ }, z.core.$strict>>>;
1178
1366
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1179
1367
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1180
1368
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1215,6 +1403,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1215
1403
  form: z.ZodString;
1216
1404
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1217
1405
  }, z.core.$strict>>>;
1406
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1407
+ id: z.ZodString;
1408
+ source: z.ZodString;
1409
+ form: z.ZodString;
1410
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1411
+ }, z.core.$strict>>>;
1218
1412
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1219
1413
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1220
1414
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1254,6 +1448,53 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1254
1448
  form: z.ZodString;
1255
1449
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1256
1450
  }, z.core.$strict>>>;
1451
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1452
+ id: z.ZodString;
1453
+ source: z.ZodString;
1454
+ form: z.ZodString;
1455
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1456
+ }, z.core.$strict>>>;
1457
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1458
+ session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1459
+ client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1460
+ info: z.ZodOptional<z.ZodObject<{
1461
+ name: z.ZodOptional<z.ZodString>;
1462
+ version: z.ZodOptional<z.ZodString>;
1463
+ }, z.core.$strict>>;
1464
+ headers: z.ZodOptional<z.ZodObject<{
1465
+ "user-agent": z.ZodOptional<z.ZodString>;
1466
+ "x-anthropic-client": z.ZodOptional<z.ZodString>;
1467
+ }, z.core.$strict>>;
1468
+ }, z.core.$strict>>>;
1469
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1470
+ runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
1471
+ }, z.core.$strict>, z.ZodObject<{
1472
+ event_type: z.ZodDefault<z.ZodLiteral<"client_report">>;
1473
+ payload: z.ZodObject<{
1474
+ instance_id: z.ZodUUID;
1475
+ dropped: z.ZodRecord<z.ZodString, z.ZodNumber>;
1476
+ }, z.core.$strict>;
1477
+ event_id: z.ZodDefault<z.ZodUUID>;
1478
+ tenant_id: z.ZodString;
1479
+ vendor_id: z.ZodString;
1480
+ session_id: z.ZodString;
1481
+ sequence_number: z.ZodNumber;
1482
+ captured_at: z.ZodString;
1483
+ consent_token: z.ZodString;
1484
+ sdk_version: z.ZodDefault<z.ZodString>;
1485
+ agent_runtime: z.ZodDefault<z.ZodString>;
1486
+ principal: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1487
+ id: z.ZodString;
1488
+ source: z.ZodString;
1489
+ form: z.ZodString;
1490
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1491
+ }, z.core.$strict>>>;
1492
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1493
+ id: z.ZodString;
1494
+ source: z.ZodString;
1495
+ form: z.ZodString;
1496
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1497
+ }, z.core.$strict>>>;
1257
1498
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1258
1499
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1259
1500
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1286,6 +1527,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1286
1527
  form: z.ZodString;
1287
1528
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1288
1529
  }, z.core.$strict>>>;
1530
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1531
+ id: z.ZodString;
1532
+ source: z.ZodString;
1533
+ form: z.ZodString;
1534
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1535
+ }, z.core.$strict>>>;
1289
1536
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1290
1537
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1291
1538
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1321,6 +1568,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1321
1568
  form: z.ZodString;
1322
1569
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1323
1570
  }, z.core.$strict>>>;
1571
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1572
+ id: z.ZodString;
1573
+ source: z.ZodString;
1574
+ form: z.ZodString;
1575
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1576
+ }, z.core.$strict>>>;
1324
1577
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1325
1578
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1326
1579
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1357,6 +1610,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1357
1610
  form: z.ZodString;
1358
1611
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1359
1612
  }, z.core.$strict>>>;
1613
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1614
+ id: z.ZodString;
1615
+ source: z.ZodString;
1616
+ form: z.ZodString;
1617
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1618
+ }, z.core.$strict>>>;
1360
1619
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1361
1620
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1362
1621
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1392,6 +1651,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1392
1651
  form: z.ZodString;
1393
1652
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1394
1653
  }, z.core.$strict>>>;
1654
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1655
+ id: z.ZodString;
1656
+ source: z.ZodString;
1657
+ form: z.ZodString;
1658
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1659
+ }, z.core.$strict>>>;
1395
1660
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1396
1661
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1397
1662
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1427,6 +1692,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1427
1692
  form: z.ZodString;
1428
1693
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1429
1694
  }, z.core.$strict>>>;
1695
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1696
+ id: z.ZodString;
1697
+ source: z.ZodString;
1698
+ form: z.ZodString;
1699
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1700
+ }, z.core.$strict>>>;
1430
1701
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1431
1702
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1432
1703
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1464,6 +1735,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1464
1735
  form: z.ZodString;
1465
1736
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1466
1737
  }, z.core.$strict>>>;
1738
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1739
+ id: z.ZodString;
1740
+ source: z.ZodString;
1741
+ form: z.ZodString;
1742
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1743
+ }, z.core.$strict>>>;
1467
1744
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1468
1745
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1469
1746
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1496,6 +1773,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1496
1773
  form: z.ZodString;
1497
1774
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1498
1775
  }, z.core.$strict>>>;
1776
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1777
+ id: z.ZodString;
1778
+ source: z.ZodString;
1779
+ form: z.ZodString;
1780
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1781
+ }, z.core.$strict>>>;
1499
1782
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1500
1783
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1501
1784
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1531,6 +1814,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1531
1814
  form: z.ZodString;
1532
1815
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1533
1816
  }, z.core.$strict>>>;
1817
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1818
+ id: z.ZodString;
1819
+ source: z.ZodString;
1820
+ form: z.ZodString;
1821
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1822
+ }, z.core.$strict>>>;
1534
1823
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1535
1824
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1536
1825
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1567,6 +1856,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1567
1856
  form: z.ZodString;
1568
1857
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1569
1858
  }, z.core.$strict>>>;
1859
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1860
+ id: z.ZodString;
1861
+ source: z.ZodString;
1862
+ form: z.ZodString;
1863
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1864
+ }, z.core.$strict>>>;
1570
1865
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1571
1866
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1572
1867
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1602,6 +1897,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1602
1897
  form: z.ZodString;
1603
1898
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1604
1899
  }, z.core.$strict>>>;
1900
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1901
+ id: z.ZodString;
1902
+ source: z.ZodString;
1903
+ form: z.ZodString;
1904
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1905
+ }, z.core.$strict>>>;
1605
1906
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1606
1907
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1607
1908
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1637,6 +1938,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1637
1938
  form: z.ZodString;
1638
1939
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1639
1940
  }, z.core.$strict>>>;
1941
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1942
+ id: z.ZodString;
1943
+ source: z.ZodString;
1944
+ form: z.ZodString;
1945
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1946
+ }, z.core.$strict>>>;
1640
1947
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1641
1948
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1642
1949
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1674,6 +1981,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1674
1981
  form: z.ZodString;
1675
1982
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1676
1983
  }, z.core.$strict>>>;
1984
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
1985
+ id: z.ZodString;
1986
+ source: z.ZodString;
1987
+ form: z.ZodString;
1988
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1989
+ }, z.core.$strict>>>;
1677
1990
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1678
1991
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1679
1992
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1706,6 +2019,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1706
2019
  form: z.ZodString;
1707
2020
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1708
2021
  }, z.core.$strict>>>;
2022
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
2023
+ id: z.ZodString;
2024
+ source: z.ZodString;
2025
+ form: z.ZodString;
2026
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2027
+ }, z.core.$strict>>>;
1709
2028
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1710
2029
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1711
2030
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1741,6 +2060,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1741
2060
  form: z.ZodString;
1742
2061
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1743
2062
  }, z.core.$strict>>>;
2063
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
2064
+ id: z.ZodString;
2065
+ source: z.ZodString;
2066
+ form: z.ZodString;
2067
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2068
+ }, z.core.$strict>>>;
1744
2069
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1745
2070
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1746
2071
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1777,6 +2102,12 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1777
2102
  form: z.ZodString;
1778
2103
  display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
1779
2104
  }, z.core.$strict>>>;
2105
+ organization: z.ZodDefault<z.ZodNullable<z.ZodObject<{
2106
+ id: z.ZodString;
2107
+ source: z.ZodString;
2108
+ form: z.ZodString;
2109
+ display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2110
+ }, z.core.$strict>>>;
1780
2111
  transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1781
2112
  session_id_origin: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1782
2113
  client_observed: z.ZodDefault<z.ZodNullable<z.ZodObject<{
@@ -1853,6 +2184,7 @@ type Event = z.infer<typeof EventSchema>;
1853
2184
  /** Cap on recursive walk depth. Matches LangSmith's default; protects
1854
2185
  * against pathological inputs without truncating realistic MCP payloads. */
1855
2186
  declare const DEPTH_LIMIT = 10;
2187
+ declare const DEPTH_MARKER = "[REDACTED:depth-limit]";
1856
2188
  /**
1857
2189
  * Stateful recursive scrubber with the default ruleset baked in.
1858
2190
  *
@@ -1868,12 +2200,14 @@ declare const DEPTH_LIMIT = 10;
1868
2200
  */
1869
2201
  declare class Scrubber {
1870
2202
  readonly counts: Map<string, number>;
2203
+ private warnedDepth;
1871
2204
  /** Bound so `new Scrubber().scrub` can be passed as a bare function
1872
2205
  * reference — the closest TS gets to Python's `__call__`. */
1873
2206
  readonly scrub: (value: unknown) => unknown;
1874
2207
  /** Python's `Counter[category]` zero-default read. */
1875
2208
  count(category: string): number;
1876
2209
  private bump;
2210
+ private pastTheDepthLimit;
1877
2211
  private walk;
1878
2212
  private scrubString;
1879
2213
  }
@@ -1892,18 +2226,16 @@ declare function identityScrub(value: unknown): unknown;
1892
2226
  * A `Sink` is the egress side of the SDK; `withBaton` hands fully-formed
1893
2227
  * `Event` envelopes to a sink and the sink decides what to do with them.
1894
2228
  *
1895
- * Two sinks ship, mirroring `sinks.py`'s core pair:
2229
+ * The same four sinks as `sinks.py`:
1896
2230
  *
1897
2231
  * - `StdoutSink` — JSONL to a writable stream (default `process.stderr`,
1898
2232
  * for the same reason as Python: MCP stdio transport reserves stdout for
1899
2233
  * JSON-RPC framing).
2234
+ * - `FileSink` — JSONL appended to a file.
1900
2235
  * - `HttpSink` — POST to any HTTP endpoint with bearer auth; bounded
1901
2236
  * buffer, retry with backoff, circuit breaker. This is the contract a
1902
2237
  * Console or any compatible collector consumes.
1903
- *
1904
- * `FileSink` / `MultiSink` are deferred per design-notes/typescript_sdk.md
1905
- * ("HttpSink + StdoutSink covers all real use cases") — add them if a real
1906
- * need shows up rather than porting them speculatively.
2238
+ * - `MultiSink` — every event to each of several sinks.
1907
2239
  */
1908
2240
 
1909
2241
  interface Sink {
@@ -1939,6 +2271,31 @@ declare class StdoutSink implements Sink {
1939
2271
  flush(): Promise<void>;
1940
2272
  aclose(): Promise<void>;
1941
2273
  }
2274
+ /** Appends one JSON envelope per line to a file, opened on the first write so
2275
+ * an unused sink creates no file. Each line reaches the file before `write`
2276
+ * resolves, so `tail -f` sees it at once. */
2277
+ declare class FileSink implements Sink {
2278
+ private readonly path;
2279
+ private fd;
2280
+ private closed;
2281
+ constructor(path: string);
2282
+ write(event: Event): Promise<void>;
2283
+ flush(): Promise<void>;
2284
+ aclose(): Promise<void>;
2285
+ }
2286
+ /** Sends each event to every sink, e.g. `new MultiSink([new StdoutSink(),
2287
+ * new HttpSink(...)])` to watch what is shipped. Every sink is tried even when
2288
+ * one fails; one failure is rethrown as is, several as an `AggregateError`. */
2289
+ declare class MultiSink implements Sink {
2290
+ private readonly sinks;
2291
+ constructor(sinks: readonly Sink[]);
2292
+ write(event: Event): Promise<void>;
2293
+ flush(): Promise<void>;
2294
+ aclose(): Promise<void>;
2295
+ private flushWithin;
2296
+ private acloseWithin;
2297
+ private fanOut;
2298
+ }
1942
2299
  interface HttpSinkOptions {
1943
2300
  apiKey: string;
1944
2301
  bufferSize?: number;
@@ -1948,6 +2305,9 @@ interface HttpSinkOptions {
1948
2305
  backoffMaxMs?: number;
1949
2306
  circuitBreakerThreshold?: number;
1950
2307
  circuitBreakerResetMs?: number;
2308
+ /** How long the flush at process exit, or an explicit `flush()` or
2309
+ * `aclose()`, may take in total, in ms, at most 2^31 - 1. Default 3000. */
2310
+ shutdownFlushTimeoutMs?: number;
1951
2311
  /** Injectable for tests; defaults to the global `fetch`. */
1952
2312
  fetchImpl?: typeof fetch;
1953
2313
  }
@@ -1965,15 +2325,37 @@ declare class HttpSink implements Sink {
1965
2325
  private readonly apiKey;
1966
2326
  private readonly buffer;
1967
2327
  private readonly bufferSize;
2328
+ private readonly requestTimeoutMs;
2329
+ private readonly shutdownFlushTimeoutMs;
2330
+ /** Set when an exit pass ends; cleared once a normal drain empties the
2331
+ * buffer, which means the process went on. */
2332
+ private exitPassRan;
2333
+ /** Whether the exit pass warned about every event now buffered. */
2334
+ private unsentWarned;
1968
2335
  private readonly maxRetries;
1969
2336
  private readonly backoffBaseMs;
1970
2337
  private readonly backoffMaxMs;
1971
2338
  private readonly circuit;
1972
2339
  private readonly fetchImpl;
1973
2340
  private overflowWarned;
1974
- private closed;
2341
+ /** Per status, so a new kind of refusal, such as a 401 after a 422, still warns. */
2342
+ private readonly refusals;
2343
+ /** Aborted once `aclose()` returns: nothing Baton started may keep the
2344
+ * process alive after the vendor closed it. */
2345
+ private readonly closing;
2346
+ /** The drain chain's tail when a flush() or aclose() gave up waiting, until it settles. */
2347
+ private stalledDrain;
2348
+ private skipWarnedFor;
2349
+ private closeOnce;
1975
2350
  private drainChain;
1976
- private beforeExitHandler;
2351
+ private exitHooks;
2352
+ /** The least time between two of this sink's loss reports. */
2353
+ private static reportIntervalMs;
2354
+ /** Totals only grow, so their sum tells whether they changed. */
2355
+ private reportedSum;
2356
+ private lastReportAt;
2357
+ private reportsStopped;
2358
+ private reportInFlight;
1977
2359
  constructor(url: string, options: HttpSinkOptions);
1978
2360
  /**
1979
2361
  * What this sink shows when something prints it — never the bearer.
@@ -1981,17 +2363,28 @@ declare class HttpSink implements Sink {
1981
2363
  * ⚠ **A sink built from a DSN holds a key the vendor never typed**, and it
1982
2364
  * hangs off `BatonHandle.sink` and off the resolved config, so
1983
2365
  * `console.log(handle.sink)` or a structured logger serialising either one
1984
- * wrote a publishable key into the vendor's logs. Found by the S2 test that
1985
- * asserts the DSN's own string does not survive resolution: it does not, and
1986
- * the key was one field further down. Same treatment as the parsed DSN —
2366
+ * would write a publishable key into the vendor's logs. Same treatment as the parsed DSN —
1987
2367
  * `toJSON` for serialisers, the inspect symbol for `console.log`, and
1988
2368
  * `Symbol.for` rather than importing `node:util`, since this package runs on
1989
2369
  * runtimes that have no such module.
1990
2370
  */
1991
2371
  toJSON(): Record<string, unknown>;
2372
+ private get closed();
1992
2373
  write(event: Event): Promise<void>;
1993
2374
  flush(): Promise<void>;
2375
+ /** A second call waits for the first (SPEC §11.2 rule 7). */
1994
2376
  aclose(): Promise<void>;
2377
+ private flushWithin;
2378
+ private acloseWithin;
2379
+ private close;
2380
+ /** SPEC §11.2 rule 7: an explicit flush or close returns within `ms` and
2381
+ * never rejects. While an earlier wait's drain is still stuck, a flush
2382
+ * returns at once, without queuing a pass, and a close gives it `ms`. The
2383
+ * drain is not cancelled here, so after `flush()` it goes on sending;
2384
+ * `aclose()` stops it. */
2385
+ private drainWithinBudget;
2386
+ /** A full buffer may already have pushed `event` out while it was being sent. */
2387
+ private dequeue;
1995
2388
  private enqueue;
1996
2389
  /** Serializes every call to `drainLocked` — from `write()`'s background
1997
2390
  * drain and from explicit `flush()` alike — onto one promise chain, so
@@ -2000,18 +2393,44 @@ declare class HttpSink implements Sink {
2000
2393
  * `shift()`. Mirrors Python's `asyncio.Lock` around `_drain_locked`. */
2001
2394
  private scheduleDrain;
2002
2395
  /** Best-effort flush when the process is about to exit without an
2003
- * explicit `aclose()`. Node re-runs `beforeExit` if new async work is
2004
- * scheduled during it, so an in-flight flush here can complete normally —
2005
- * unlike Python's synchronous `atexit`, no separate sync-client fallback
2006
- * is needed. Real residual gap, not fixable in-process: SIGKILL, or
2007
- * SIGTERM with no installed handler, skip `beforeExit` entirely. A vendor
2008
- * needing that guarantee must call `aclose()` from their own handler. */
2009
- private ensureBeforeExitRegistered;
2396
+ * explicit `aclose()`. SIGKILL, or SIGTERM with no installed handler, skip
2397
+ * both hooks: a vendor needing that guarantee must call `aclose()` from
2398
+ * their own handler. */
2399
+ private ensureExitHooksRegistered;
2400
+ /** One attempt per event, no retry, within `shutdownFlushTimeoutMs` in
2401
+ * total (SPEC §11.2); what is left is reported, not sent. */
2402
+ private exitPass;
2403
+ private unsentAtExit;
2010
2404
  private events_url;
2011
2405
  private authHeaders;
2012
2406
  private static classifyStatus;
2407
+ /** A refused event is otherwise dropped silently, which looks the same from
2408
+ * the vendor's process as an accepted one. The collector's own message is
2409
+ * logged because it names the field at fault; it is capped and escaped
2410
+ * because it is a remote server's text landing in the vendor's log. */
2411
+ private static logRefusal;
2412
+ private warnUnloggedRefusals;
2413
+ /** How many refusals with `status` went unlogged before this one, or `null`
2414
+ * when this one goes unlogged too. */
2415
+ private refusalToLog;
2416
+ /** Enough of the body for `REFUSAL_BODY_MAX_LEN` code points; the rest is
2417
+ * cancelled unread, so a large error page does not hold the drain. */
2418
+ private static readHead;
2013
2419
  private drainLocked;
2420
+ /** Starts a report of this process's loss totals (SPEC §11.4.7) beside the
2421
+ * drain and outside the buffer, so it never delays an event and is never
2422
+ * counted as one. */
2423
+ private maybeReport;
2424
+ private stopReports;
2425
+ private sendReport;
2014
2426
  private sendWithRetry;
2427
+ /** `null`, with a warning, for an event `JSON.stringify` rejects. */
2428
+ private encode;
2429
+ private sleepUnlessClosed;
2430
+ /** Aborted by the timeout or by `aclose()`. Built by hand: `AbortSignal.any`
2431
+ * is missing before Node 20.3, and on some later versions it keeps every
2432
+ * combined signal alive as long as the long-lived `closing` signal. */
2433
+ private postOnce;
2015
2434
  }
2016
2435
 
2017
2436
  /** Principal identity — what a vendor's resolver hands back, and how it goes
@@ -2051,6 +2470,17 @@ interface Principal {
2051
2470
  * show, and it is personal data whatever `form` says. An unusable value is
2052
2471
  * dropped alone — see `wireDisplayName`. */
2053
2472
  displayName?: string | null | undefined;
2473
+ /** The company this principal belongs to. Sent as `organization`, and
2474
+ * dropped alone when unusable (SPEC §11.4). */
2475
+ organization?: Organization | null | undefined;
2476
+ }
2477
+ /** The company or workspace the caller belongs to, as the vendor sees it.
2478
+ * Sent as `organization` (SPEC §11.4), beside `principal` or alone. It is
2479
+ * never counted as a person. `form` describes `organizationId` alone. */
2480
+ interface Organization {
2481
+ organizationId: string;
2482
+ form?: PrincipalForm | undefined;
2483
+ displayName?: string | null | undefined;
2054
2484
  }
2055
2485
 
2056
2486
  /** A validated access token, as both majors declare it
@@ -2117,7 +2547,7 @@ interface PrincipalResolutionContext {
2117
2547
  }
2118
2548
  /** A vendor's per-request identity resolver. Sync or async; returning `null`
2119
2549
  * means "no opinion about this caller", which is not an error. */
2120
- type ResolvePrincipalHook = (context: PrincipalResolutionContext) => Principal | null | Promise<Principal | null>;
2550
+ type ResolvePrincipalHook = (context: PrincipalResolutionContext) => Principal | Organization | null | Promise<Principal | Organization | null>;
2121
2551
 
2122
2552
  /** The registered values of `resultCaptureMode` (SPEC §11.4), and the single
2123
2553
  * source of truth for them.
@@ -2239,8 +2669,7 @@ interface BatonConfig {
2239
2669
  * `tools/list`, without enforcing it: a call that omits it still reaches
2240
2670
  * your handler, and its event simply carries no intent. `"optional"` injects
2241
2671
  * the same param and does not advertise it as required. There is no
2242
- * `"off"`: this SDK has no proactive reports, so nothing else would capture
2243
- * what the user is trying to do. The param is stripped before the vendor
2672
+ * `"off"`: nothing else would capture what the user is trying to do. The param is stripped before the vendor
2244
2673
  * handler runs, so the tool never sees it.
2245
2674
  * This is what captures intent on runtimes that drop `instructions`
2246
2675
  * (notably Claude Desktop) — where the annotation tool alone yields
@@ -2260,10 +2689,8 @@ interface BatonConfig {
2260
2689
  *
2261
2690
  * **Requests are unaffected**: `params` are captured in both modes.
2262
2691
  *
2263
- * ⚠ The message of an error your handler THROWS is KEPT — it is your own code
2264
- * speaking about a call that never returned, so it is not result-derived
2265
- * (SPEC §11.4.3). Thrown messages are a classic leak channel; if that is also
2266
- * a problem for you, say so and the mode grows a stricter value.
2692
+ * The message of an error your handler THROWS is withheld too (SPEC
2693
+ * §11.4.3): the MCP SDK has no tool-error class to mark one public.
2267
2694
  *
2268
2695
  * Not a scrubber rule, deliberately (SPEC §7): a scrubber TRANSFORMS a value
2269
2696
  * that still crosses the network, this DECLARES that nothing crosses. Under
@@ -2313,9 +2740,9 @@ interface BatonConfig {
2313
2740
  declare class BatonHandle {
2314
2741
  readonly sink: Sink;
2315
2742
  readonly vendorId: string;
2316
- /** Process-lifetime fallback session id — the value events fall back to
2317
- * when no real per-call session id resolves. Not every event necessarily
2318
- * carries this id; see `withBaton`'s session-resolution order. */
2743
+ /** The install's own session id: what stdio and in-memory calls, and the
2744
+ * surface snapshot, carry when no session id resolves. A call over HTTP
2745
+ * with no session to read gets a per-request id instead (SPEC §3.4 rung 5). */
2319
2746
  readonly sessionId: string;
2320
2747
  /** The resolved annotation tool name: `BatonConfig.annotationToolName` if
2321
2748
  * set, else derived from the server's own name (`{slug}_annotate`), else
@@ -2327,9 +2754,10 @@ declare class BatonHandle {
2327
2754
  sessionId: string;
2328
2755
  annotationToolName: string;
2329
2756
  });
2330
- /** Flush any pending events held by the sink. */
2757
+ /** Flush any pending events held by the sink. Never rejects; returns within
2758
+ * the shutdown budget (SPEC §11.2 rule 7). */
2331
2759
  flush(): Promise<void>;
2332
- /** Flush and release sink resources. Subsequent writes reject. */
2760
+ /** Flush and release sink resources, on the same terms as `flush()`. */
2333
2761
  aclose(): Promise<void>;
2334
2762
  }
2335
2763
 
@@ -2487,6 +2915,16 @@ declare function principalFromOAuthSub(context: PrincipalResolutionContext): Pri
2487
2915
  * good enough is the vendor's call. */
2488
2916
  declare function principalFromOAuthEmail(context: PrincipalResolutionContext): Principal | null;
2489
2917
 
2918
+ /** The library's `listTools`: the tool list a vendor serving MCP itself hands
2919
+ * its agents, and the `surface_snapshot` of the list it started from (SPEC
2920
+ * §5.6, §11.4.2). */
2921
+ /** The vendor's own `initialize` values, as it serves them. */
2922
+ interface ListToolsOptions {
2923
+ serverInfo?: Record<string, unknown> | null;
2924
+ capabilities?: Record<string, unknown> | null;
2925
+ instructions?: string | null;
2926
+ }
2927
+
2490
2928
  /** The envelope's `client_observed` (SPEC §11.4): what the client said about
2491
2929
  * itself, sent uninterpreted. The consumer names the client; this SDK does
2492
2930
  * not, and sends `agent_runtime: "unknown"` on every event. */
@@ -2533,8 +2971,11 @@ interface ClientOptions {
2533
2971
  interface SessionOptions {
2534
2972
  /** The vendor's own id for the conversation; without one, the block mints one. */
2535
2973
  sessionId?: string;
2536
- /** Who the vendor says is calling. */
2537
- principal?: Principal;
2974
+ /** Who the vendor says is calling: a `Principal`, which may carry its
2975
+ * `organization`, or an `Organization` alone when only the company is known.
2976
+ * A block with only a company and no `sessionId` is never joined to another
2977
+ * (SPEC §11.5.1), so pass your own `sessionId` then. */
2978
+ principal?: Principal | Organization;
2538
2979
  /** What the calling client said about itself. */
2539
2980
  clientInfo?: {
2540
2981
  name?: string;
@@ -2545,6 +2986,9 @@ interface SessionOptions {
2545
2986
  /** The vendor's own id for the user request these calls answer. Pass the
2546
2987
  * same value to every block that serves it, and those calls stay one turn. */
2547
2988
  turnId?: string;
2989
+ /** The request's MCP `_meta`, for a vendor serving MCP itself. It is sent
2990
+ * as `runtime_meta`, and a client declaration in it wins over `clientInfo`. */
2991
+ meta?: Record<string, unknown>;
2548
2992
  }
2549
2993
  interface TraceOptions {
2550
2994
  toolName: string;
@@ -2605,7 +3049,19 @@ declare class Client {
2605
3049
  annotate(options: AnnotateOptions & {
2606
3050
  consentToken?: string;
2607
3051
  }): Promise<void>;
2608
- /** Wait until every event so far has reached the sink and the sink has flushed. */
3052
+ /** `tools`, the vendor's own `tools/list` entries, with `user_goal` added
3053
+ * to each `inputSchema` as `withBaton` adds it, and a `surface_snapshot`
3054
+ * of `tools` as passed, sent once per distinct surface. For a vendor
3055
+ * serving MCP itself (SPEC §5.6).
3056
+ *
3057
+ * Pass the tools before anything of Baton's is added, so the snapshot
3058
+ * describes the vendor's own surface. `options` holds the vendor's own
3059
+ * `initialize` values. The input is not changed. Never rejects over the
3060
+ * tool list: one it cannot read is returned as it came. Does not wait for
3061
+ * the snapshot to be sent; `flush()` does. */
3062
+ listTools<T>(tools: readonly T[], options?: ListToolsOptions): Promise<T[]>;
3063
+ /** Wait for events so far to reach the sink, then flush it. Never rejects;
3064
+ * returns within the sink's shutdown budget plus 250 ms (SPEC §11.2 rule 7). */
2609
3065
  flush(): Promise<void>;
2610
3066
  /** Flush, then close the sink. Later events are dropped. */
2611
3067
  aclose(): Promise<void>;
@@ -2627,4 +3083,4 @@ interface IntentParam {
2627
3083
  }
2628
3084
  declare const INTENT_PARAMS: readonly IntentParam[];
2629
3085
 
2630
- export { type AnnotateOptions, type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type AuthInfo, type Baton, type BatonConfig, BatonHandle, Client, type ClientOptions, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, type HeaderInput, HttpSink, type HttpSinkOptions, INTENT_INSTRUCTIONS, INTENT_PARAMS, type IntentParam, type ObservedError, PRINCIPAL_FORM_HASHED, PRINCIPAL_FORM_RAW, PRINCIPAL_SOURCE_ASSERTED, type Principal, type PrincipalForm, type PrincipalResolutionContext, PrincipalWireSchema, type PromptGetEndEvent, PromptGetEndEventSchema, type PromptGetEndPayload, PromptGetEndPayloadSchema, type PromptGetErrorEvent, PromptGetErrorEventSchema, type PromptGetErrorPayload, PromptGetErrorPayloadSchema, type PromptGetStartEvent, PromptGetStartEventSchema, type PromptGetStartPayload, PromptGetStartPayloadSchema, type PromptListEndEvent, PromptListEndEventSchema, type PromptListEndPayload, PromptListEndPayloadSchema, type PromptListErrorEvent, PromptListErrorEventSchema, type PromptListErrorPayload, PromptListErrorPayloadSchema, type PromptListStartEvent, PromptListStartEventSchema, type PromptListStartPayload, PromptListStartPayloadSchema, type ResolvePrincipalHook, type ResourceListEndEvent, ResourceListEndEventSchema, type ResourceListEndPayload, ResourceListEndPayloadSchema, type ResourceListErrorEvent, ResourceListErrorEventSchema, type ResourceListErrorPayload, ResourceListErrorPayloadSchema, type ResourceListStartEvent, ResourceListStartEventSchema, type ResourceListStartPayload, ResourceListStartPayloadSchema, type ResourceReadEndEvent, ResourceReadEndEventSchema, type ResourceReadEndPayload, ResourceReadEndPayloadSchema, type ResourceReadErrorEvent, ResourceReadErrorEventSchema, type ResourceReadErrorPayload, ResourceReadErrorPayloadSchema, type ResourceReadStartEvent, ResourceReadStartEventSchema, type ResourceReadStartPayload, ResourceReadStartPayloadSchema, type ResultCaptureMode, SDK_VERSION, Scrubber, type SessionOptions, type Sink, StdoutSink, type StdoutSinkOptions, type SupportedMcpServer, type SurfaceSnapshotEvent, SurfaceSnapshotEventSchema, type SurfaceSnapshotPayload, SurfaceSnapshotPayloadSchema, type ToolCallEndEvent, ToolCallEndEventSchema, type ToolCallEndPayload, ToolCallEndPayloadSchema, type ToolCallErrorEvent, ToolCallErrorEventSchema, type ToolCallErrorPayload, ToolCallErrorPayloadSchema, type ToolCallStartEvent, ToolCallStartEventSchema, type ToolCallStartPayload, ToolCallStartPayloadSchema, type ToolListEndEvent, ToolListEndEventSchema, type ToolListEndPayload, ToolListEndPayloadSchema, type ToolListErrorEvent, ToolListErrorEventSchema, type ToolListErrorPayload, ToolListErrorPayloadSchema, type ToolListStartEvent, ToolListStartEventSchema, type ToolListStartPayload, ToolListStartPayloadSchema, Trace, type TraceOptions, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, safeWrite, withBaton };
3086
+ export { type AnnotateOptions, type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type AuthInfo, type Baton, type BatonConfig, BatonHandle, Client, type ClientOptions, type ClientReportEvent, ClientReportEventSchema, type ClientReportPayload, ClientReportPayloadSchema, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, DEPTH_MARKER, type Event, EventSchema, type EventType, EventTypeSchema, FileSink, type HeaderInput, HttpSink, type HttpSinkOptions, INTENT_INSTRUCTIONS, INTENT_PARAMS, type IntentParam, type ListToolsOptions, MultiSink, type ObservedError, type Organization, PRINCIPAL_FORM_HASHED, PRINCIPAL_FORM_RAW, PRINCIPAL_SOURCE_ASSERTED, type Principal, type PrincipalForm, type PrincipalResolutionContext, PrincipalWireSchema, type PromptGetEndEvent, PromptGetEndEventSchema, type PromptGetEndPayload, PromptGetEndPayloadSchema, type PromptGetErrorEvent, PromptGetErrorEventSchema, type PromptGetErrorPayload, PromptGetErrorPayloadSchema, type PromptGetStartEvent, PromptGetStartEventSchema, type PromptGetStartPayload, PromptGetStartPayloadSchema, type PromptListEndEvent, PromptListEndEventSchema, type PromptListEndPayload, PromptListEndPayloadSchema, type PromptListErrorEvent, PromptListErrorEventSchema, type PromptListErrorPayload, PromptListErrorPayloadSchema, type PromptListStartEvent, PromptListStartEventSchema, type PromptListStartPayload, PromptListStartPayloadSchema, type ResolvePrincipalHook, type ResourceListEndEvent, ResourceListEndEventSchema, type ResourceListEndPayload, ResourceListEndPayloadSchema, type ResourceListErrorEvent, ResourceListErrorEventSchema, type ResourceListErrorPayload, ResourceListErrorPayloadSchema, type ResourceListStartEvent, ResourceListStartEventSchema, type ResourceListStartPayload, ResourceListStartPayloadSchema, type ResourceReadEndEvent, ResourceReadEndEventSchema, type ResourceReadEndPayload, ResourceReadEndPayloadSchema, type ResourceReadErrorEvent, ResourceReadErrorEventSchema, type ResourceReadErrorPayload, ResourceReadErrorPayloadSchema, type ResourceReadStartEvent, ResourceReadStartEventSchema, type ResourceReadStartPayload, ResourceReadStartPayloadSchema, type ResultCaptureMode, SDK_VERSION, Scrubber, type SessionOptions, type Sink, StdoutSink, type StdoutSinkOptions, type SupportedMcpServer, type SurfaceSnapshotEvent, SurfaceSnapshotEventSchema, type SurfaceSnapshotPayload, SurfaceSnapshotPayloadSchema, type ToolCallEndEvent, ToolCallEndEventSchema, type ToolCallEndPayload, ToolCallEndPayloadSchema, type ToolCallErrorEvent, ToolCallErrorEventSchema, type ToolCallErrorPayload, ToolCallErrorPayloadSchema, type ToolCallStartEvent, ToolCallStartEventSchema, type ToolCallStartPayload, ToolCallStartPayloadSchema, type ToolListEndEvent, ToolListEndEventSchema, type ToolListEndPayload, ToolListEndPayloadSchema, type ToolListErrorEvent, ToolListErrorEventSchema, type ToolListErrorPayload, ToolListErrorPayloadSchema, type ToolListStartEvent, ToolListStartEventSchema, type ToolListStartPayload, ToolListStartPayloadSchema, Trace, type TraceOptions, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, safeWrite, withBaton };