@goodtiming/baton-sdk 0.3.0 → 0.3.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.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
 
3
- declare const SDK_VERSION = "ts-0.3.0";
3
+ declare const SDK_VERSION = "ts-0.3.2";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -83,6 +83,19 @@ declare const SurfaceSnapshotPayloadSchema: z.ZodObject<{
83
83
  seam_augmentations: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
84
84
  }, z.core.$strict>;
85
85
  type SurfaceSnapshotPayload = z.infer<typeof SurfaceSnapshotPayloadSchema>;
86
+ /**
87
+ * What the SDK puts in `consent_token` when the vendor names no other value.
88
+ * Byte-for-byte Python's `baton.events.DEFAULT_CONSENT_TOKEN`, and the two
89
+ * must not drift: a collector comparing the field across arms would see two
90
+ * populations where there is one.
91
+ *
92
+ * **The field stays on the wire and the customer stops carrying it.** SPEC
93
+ * §2.3 governs the envelope, not the config, so defaulting here changes
94
+ * nothing a consumer sees — this is the value the onboarding recipe has been
95
+ * minting into `BATON_CONSENT_TOKEN` all along, now stated once instead of
96
+ * threaded through an environment variable that reads to nobody.
97
+ */
98
+ declare const DEFAULT_CONSENT_TOKEN = "customer-consented";
86
99
  declare const EventTypeSchema: z.ZodEnum<{
87
100
  tool_call_start: "tool_call_start";
88
101
  tool_call_end: "tool_call_end";
@@ -111,6 +124,7 @@ declare const ToolCallStartEventSchema: z.ZodObject<{
111
124
  sdk_version: z.ZodDefault<z.ZodString>;
112
125
  agent_runtime: z.ZodDefault<z.ZodString>;
113
126
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
127
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
114
128
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
115
129
  }, z.core.$strict>;
116
130
  type ToolCallStartEvent = z.infer<typeof ToolCallStartEventSchema>;
@@ -131,6 +145,7 @@ declare const ToolCallEndEventSchema: z.ZodObject<{
131
145
  sdk_version: z.ZodDefault<z.ZodString>;
132
146
  agent_runtime: z.ZodDefault<z.ZodString>;
133
147
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
148
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
134
149
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
135
150
  }, z.core.$strict>;
136
151
  type ToolCallEndEvent = z.infer<typeof ToolCallEndEventSchema>;
@@ -152,6 +167,7 @@ declare const ToolCallErrorEventSchema: z.ZodObject<{
152
167
  sdk_version: z.ZodDefault<z.ZodString>;
153
168
  agent_runtime: z.ZodDefault<z.ZodString>;
154
169
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
170
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
155
171
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
156
172
  }, z.core.$strict>;
157
173
  type ToolCallErrorEvent = z.infer<typeof ToolCallErrorEventSchema>;
@@ -177,6 +193,7 @@ declare const AnnotationEventSchema: z.ZodObject<{
177
193
  sdk_version: z.ZodDefault<z.ZodString>;
178
194
  agent_runtime: z.ZodDefault<z.ZodString>;
179
195
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
196
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
180
197
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
181
198
  }, z.core.$strict>;
182
199
  type AnnotationEvent = z.infer<typeof AnnotationEventSchema>;
@@ -200,6 +217,7 @@ declare const SurfaceSnapshotEventSchema: z.ZodObject<{
200
217
  sdk_version: z.ZodDefault<z.ZodString>;
201
218
  agent_runtime: z.ZodDefault<z.ZodString>;
202
219
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
220
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
203
221
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
204
222
  }, z.core.$strict>;
205
223
  type SurfaceSnapshotEvent = z.infer<typeof SurfaceSnapshotEventSchema>;
@@ -223,6 +241,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
223
241
  sdk_version: z.ZodDefault<z.ZodString>;
224
242
  agent_runtime: z.ZodDefault<z.ZodString>;
225
243
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
244
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
226
245
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
227
246
  }, z.core.$strict>, z.ZodObject<{
228
247
  event_type: z.ZodDefault<z.ZodLiteral<"tool_call_end">>;
@@ -241,6 +260,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
241
260
  sdk_version: z.ZodDefault<z.ZodString>;
242
261
  agent_runtime: z.ZodDefault<z.ZodString>;
243
262
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
263
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
244
264
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
245
265
  }, z.core.$strict>, z.ZodObject<{
246
266
  event_type: z.ZodDefault<z.ZodLiteral<"tool_call_error">>;
@@ -260,6 +280,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
260
280
  sdk_version: z.ZodDefault<z.ZodString>;
261
281
  agent_runtime: z.ZodDefault<z.ZodString>;
262
282
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
283
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
263
284
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
264
285
  }, z.core.$strict>, z.ZodObject<{
265
286
  event_type: z.ZodDefault<z.ZodLiteral<"annotation">>;
@@ -283,6 +304,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
283
304
  sdk_version: z.ZodDefault<z.ZodString>;
284
305
  agent_runtime: z.ZodDefault<z.ZodString>;
285
306
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
307
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
286
308
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
287
309
  }, z.core.$strict>, z.ZodObject<{
288
310
  event_type: z.ZodDefault<z.ZodLiteral<"surface_snapshot">>;
@@ -304,6 +326,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
304
326
  sdk_version: z.ZodDefault<z.ZodString>;
305
327
  agent_runtime: z.ZodDefault<z.ZodString>;
306
328
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
329
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
307
330
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
308
331
  }, z.core.$strict>], "event_type">;
309
332
  type Event = ToolCallStartEvent | ToolCallEndEvent | ToolCallErrorEvent | AnnotationEvent | SurfaceSnapshotEvent;
@@ -479,6 +502,20 @@ declare class HttpSink implements Sink {
479
502
  private drainChain;
480
503
  private beforeExitHandler;
481
504
  constructor(url: string, options: HttpSinkOptions);
505
+ /**
506
+ * What this sink shows when something prints it — never the bearer.
507
+ *
508
+ * ⚠ **A sink built from a DSN holds a key the vendor never typed**, and it
509
+ * hangs off `BatonHandle.sink` and off the resolved config, so
510
+ * `console.log(handle.sink)` or a structured logger serialising either one
511
+ * wrote a publishable key into the vendor's logs. Found by the S2 test that
512
+ * asserts the DSN's own string does not survive resolution: it does not, and
513
+ * the key was one field further down. Same treatment as the parsed DSN —
514
+ * `toJSON` for serialisers, the inspect symbol for `console.log`, and
515
+ * `Symbol.for` rather than importing `node:util`, since this package runs on
516
+ * runtimes that have no such module.
517
+ */
518
+ toJSON(): Record<string, unknown>;
482
519
  write(event: Event): Promise<void>;
483
520
  flush(): Promise<void>;
484
521
  aclose(): Promise<void>;
@@ -509,20 +546,34 @@ declare class HttpSink implements Sink {
509
546
  * mirror of `baton` (Python)'s `integrations/_config.py::VendorConfig`.
510
547
  */
511
548
 
512
- /** Normalized input to `BatonConfig.resolveSessionId`. Deliberately doesn't
513
- * carry the raw MCP SDK `extra` object — this shape is stable across
514
- * whatever the TS MCP ecosystem does with its request-handler signature. */
515
- interface SessionResolutionContext {
516
- meta: Record<string, unknown> | null;
517
- toolName: string;
518
- arguments: Record<string, unknown>;
519
- }
520
- type ResolveSessionIdHook = (context: SessionResolutionContext) => string | null | undefined | Promise<string | null | undefined>;
521
549
  interface BatonConfig {
550
+ /** The packed connection string from /account — one value carrying the
551
+ * ingest host, the workspace, the server and the key that binds them.
552
+ *
553
+ * `withBaton(server, { dsn })` is the whole wrap block a DISTRIBUTABLE
554
+ * server ships with, and that is the case it exists for: a stdio server
555
+ * runs on every user's machine, so five `BATON_*` variables are five values
556
+ * that never arrive. Resolved explicit → `BATON_DSN` → unset.
557
+ *
558
+ * **Environment variables do not override it.** A server being re-onboarded
559
+ * has last install's `.env` beside the new inline DSN, and if these values
560
+ * fell through to `BATON_TENANT_ID` the way an unset field does, the stale
561
+ * file would win silently and the events would arrive under the previous
562
+ * server's name.
563
+ *
564
+ * Passing a dsn AND an explicit `vendorId`, `tenantId` or `sink` throws:
565
+ * two sources for one value cannot be reconciled without guessing, and a
566
+ * wrong guess routes a server's traffic under someone else's identity.
567
+ * Everything else — the display name, the scrubber, the injection modes,
568
+ * every identity option — is unaffected; set them alongside a dsn freely. */
569
+ dsn?: string;
522
570
  /** Short stable identifier for the SERVER whose surface is captured
523
571
  * (e.g. `"acme"`). Also the default annotation tool name prefix
524
- * (`{vendorId}_annotate`). This is not the account — see `tenantId`. */
525
- vendorId: string;
572
+ * (`{vendorId}_annotate`). This is not the account — see `tenantId`.
573
+ *
574
+ * Required unless a `dsn` supplies it — the DSN's last path segment IS this
575
+ * value, and it is what the key is BOUND to. */
576
+ vendorId?: string;
526
577
  /** Account identifier for the envelope's `tenant_id` (SPEC §11.4).
527
578
  *
528
579
  * **This is not `vendorId`, and conflating them is the bug this field
@@ -541,15 +592,31 @@ interface BatonConfig {
541
592
  tenantId?: string;
542
593
  /** Human-readable vendor name used in server instructions and the
543
594
  * annotation tool description — whitelabel obligation (SPEC §5.4): no
544
- * Baton-branded strings reach the calling agent. */
545
- vendorDisplayName: string;
595
+ * Baton-branded strings reach the calling agent.
596
+ *
597
+ * Defaults to the DSN's server segment VERBATIM when a `dsn` is given and
598
+ * this is not. Verbatim rather than prettified: this string reaches the
599
+ * calling agent, so inventing a capitalisation the vendor never chose would
600
+ * put a fabricated name in front of their users. */
601
+ vendorDisplayName?: string;
546
602
  /** End-user consent token attached to every emitted event per SPEC §2.3 —
547
- * required, the Console MUST reject events missing it. */
548
- consentToken: string;
603
+ * the Console MUST reject events missing it.
604
+ *
605
+ * **Defaulted, so the customer never has to carry it** — see
606
+ * `DEFAULT_CONSENT_TOKEN` for why the field stays on the wire regardless.
607
+ * Passing `""` explicitly still throws: a value the vendor deliberately
608
+ * emptied is a mistake, not a request for the default.
609
+ *
610
+ * ⚠ **No environment variable is read for this, and that is parity rather
611
+ * than a gap.** Python reads `BATON_CONSENT_TOKEN` on its `Client` door
612
+ * only; its `VendorConfig` — the door this package mirrors — takes a plain
613
+ * default, and the `os.environ["BATON_CONSENT_TOKEN"]` in its install
614
+ * examples is the RECIPE passing a value explicitly, not the SDK reading
615
+ * one. Adding the read here would make this arm honour a variable the
616
+ * equivalent Python door ignores. */
617
+ consentToken?: string;
549
618
  /** Where events go. Defaults to `new StdoutSink()` — zero-config dev mode. */
550
619
  sink?: Sink;
551
- /** Default `agent_runtime` when `_meta` heuristics can't detect one. */
552
- defaultAgentRuntime?: string;
553
620
  /** PII scrubber per SPEC §7, applied to tool params/results, `_meta`,
554
621
  * intent strings and error bodies before they reach the sink. Defaults to
555
622
  * the shipped default ruleset (`new Scrubber().scrub` — email, bearer,
@@ -558,9 +625,6 @@ interface BatonConfig {
558
625
  * so untouched integrations get scrubbing without the operator opting in.
559
626
  * Pass `identityScrub` to explicitly opt out, or supply your own. */
560
627
  scrubber?: (value: unknown) => unknown;
561
- /** Optional vendor-supplied session-id resolver, checked BEFORE
562
- * `extra.sessionId` — mirrors Python's `resolve_session_id` rung 0. */
563
- resolveSessionId?: ResolveSessionIdHook;
564
628
  /** Optional override for the annotation tool name. Default is
565
629
  * `{vendorId}_annotate`. */
566
630
  annotationToolName?: string;
@@ -696,6 +760,6 @@ interface SupportedMcpServer {
696
760
  registerTool(name: string, ...rest: unknown[]): unknown;
697
761
  }
698
762
  /** Install Baton into an `McpServer`. See module docstring for usage. */
699
- declare function withBaton(server: SupportedMcpServer, config: BatonConfig): BatonHandle;
763
+ declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
700
764
 
701
- export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type BatonConfig, BatonHandle, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions, type ResolveSessionIdHook, SDK_VERSION, Scrubber, type SessionResolutionContext, 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, identityScrub, safeWrite, withBaton };
765
+ export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type BatonConfig, BatonHandle, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions, SDK_VERSION, Scrubber, 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, identityScrub, safeWrite, withBaton };
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.3.0";
3
+ declare const SDK_VERSION = "ts-0.3.2";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -83,6 +83,19 @@ declare const SurfaceSnapshotPayloadSchema: z.ZodObject<{
83
83
  seam_augmentations: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
84
84
  }, z.core.$strict>;
85
85
  type SurfaceSnapshotPayload = z.infer<typeof SurfaceSnapshotPayloadSchema>;
86
+ /**
87
+ * What the SDK puts in `consent_token` when the vendor names no other value.
88
+ * Byte-for-byte Python's `baton.events.DEFAULT_CONSENT_TOKEN`, and the two
89
+ * must not drift: a collector comparing the field across arms would see two
90
+ * populations where there is one.
91
+ *
92
+ * **The field stays on the wire and the customer stops carrying it.** SPEC
93
+ * §2.3 governs the envelope, not the config, so defaulting here changes
94
+ * nothing a consumer sees — this is the value the onboarding recipe has been
95
+ * minting into `BATON_CONSENT_TOKEN` all along, now stated once instead of
96
+ * threaded through an environment variable that reads to nobody.
97
+ */
98
+ declare const DEFAULT_CONSENT_TOKEN = "customer-consented";
86
99
  declare const EventTypeSchema: z.ZodEnum<{
87
100
  tool_call_start: "tool_call_start";
88
101
  tool_call_end: "tool_call_end";
@@ -111,6 +124,7 @@ declare const ToolCallStartEventSchema: z.ZodObject<{
111
124
  sdk_version: z.ZodDefault<z.ZodString>;
112
125
  agent_runtime: z.ZodDefault<z.ZodString>;
113
126
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
127
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
114
128
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
115
129
  }, z.core.$strict>;
116
130
  type ToolCallStartEvent = z.infer<typeof ToolCallStartEventSchema>;
@@ -131,6 +145,7 @@ declare const ToolCallEndEventSchema: z.ZodObject<{
131
145
  sdk_version: z.ZodDefault<z.ZodString>;
132
146
  agent_runtime: z.ZodDefault<z.ZodString>;
133
147
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
148
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
134
149
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
135
150
  }, z.core.$strict>;
136
151
  type ToolCallEndEvent = z.infer<typeof ToolCallEndEventSchema>;
@@ -152,6 +167,7 @@ declare const ToolCallErrorEventSchema: z.ZodObject<{
152
167
  sdk_version: z.ZodDefault<z.ZodString>;
153
168
  agent_runtime: z.ZodDefault<z.ZodString>;
154
169
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
170
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
155
171
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
156
172
  }, z.core.$strict>;
157
173
  type ToolCallErrorEvent = z.infer<typeof ToolCallErrorEventSchema>;
@@ -177,6 +193,7 @@ declare const AnnotationEventSchema: z.ZodObject<{
177
193
  sdk_version: z.ZodDefault<z.ZodString>;
178
194
  agent_runtime: z.ZodDefault<z.ZodString>;
179
195
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
196
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
180
197
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
181
198
  }, z.core.$strict>;
182
199
  type AnnotationEvent = z.infer<typeof AnnotationEventSchema>;
@@ -200,6 +217,7 @@ declare const SurfaceSnapshotEventSchema: z.ZodObject<{
200
217
  sdk_version: z.ZodDefault<z.ZodString>;
201
218
  agent_runtime: z.ZodDefault<z.ZodString>;
202
219
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
220
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
203
221
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
204
222
  }, z.core.$strict>;
205
223
  type SurfaceSnapshotEvent = z.infer<typeof SurfaceSnapshotEventSchema>;
@@ -223,6 +241,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
223
241
  sdk_version: z.ZodDefault<z.ZodString>;
224
242
  agent_runtime: z.ZodDefault<z.ZodString>;
225
243
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
244
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
226
245
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
227
246
  }, z.core.$strict>, z.ZodObject<{
228
247
  event_type: z.ZodDefault<z.ZodLiteral<"tool_call_end">>;
@@ -241,6 +260,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
241
260
  sdk_version: z.ZodDefault<z.ZodString>;
242
261
  agent_runtime: z.ZodDefault<z.ZodString>;
243
262
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
263
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
244
264
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
245
265
  }, z.core.$strict>, z.ZodObject<{
246
266
  event_type: z.ZodDefault<z.ZodLiteral<"tool_call_error">>;
@@ -260,6 +280,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
260
280
  sdk_version: z.ZodDefault<z.ZodString>;
261
281
  agent_runtime: z.ZodDefault<z.ZodString>;
262
282
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
283
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
263
284
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
264
285
  }, z.core.$strict>, z.ZodObject<{
265
286
  event_type: z.ZodDefault<z.ZodLiteral<"annotation">>;
@@ -283,6 +304,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
283
304
  sdk_version: z.ZodDefault<z.ZodString>;
284
305
  agent_runtime: z.ZodDefault<z.ZodString>;
285
306
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
307
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
286
308
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
287
309
  }, z.core.$strict>, z.ZodObject<{
288
310
  event_type: z.ZodDefault<z.ZodLiteral<"surface_snapshot">>;
@@ -304,6 +326,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
304
326
  sdk_version: z.ZodDefault<z.ZodString>;
305
327
  agent_runtime: z.ZodDefault<z.ZodString>;
306
328
  user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
329
+ call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
307
330
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
308
331
  }, z.core.$strict>], "event_type">;
309
332
  type Event = ToolCallStartEvent | ToolCallEndEvent | ToolCallErrorEvent | AnnotationEvent | SurfaceSnapshotEvent;
@@ -479,6 +502,20 @@ declare class HttpSink implements Sink {
479
502
  private drainChain;
480
503
  private beforeExitHandler;
481
504
  constructor(url: string, options: HttpSinkOptions);
505
+ /**
506
+ * What this sink shows when something prints it — never the bearer.
507
+ *
508
+ * ⚠ **A sink built from a DSN holds a key the vendor never typed**, and it
509
+ * hangs off `BatonHandle.sink` and off the resolved config, so
510
+ * `console.log(handle.sink)` or a structured logger serialising either one
511
+ * wrote a publishable key into the vendor's logs. Found by the S2 test that
512
+ * asserts the DSN's own string does not survive resolution: it does not, and
513
+ * the key was one field further down. Same treatment as the parsed DSN —
514
+ * `toJSON` for serialisers, the inspect symbol for `console.log`, and
515
+ * `Symbol.for` rather than importing `node:util`, since this package runs on
516
+ * runtimes that have no such module.
517
+ */
518
+ toJSON(): Record<string, unknown>;
482
519
  write(event: Event): Promise<void>;
483
520
  flush(): Promise<void>;
484
521
  aclose(): Promise<void>;
@@ -509,20 +546,34 @@ declare class HttpSink implements Sink {
509
546
  * mirror of `baton` (Python)'s `integrations/_config.py::VendorConfig`.
510
547
  */
511
548
 
512
- /** Normalized input to `BatonConfig.resolveSessionId`. Deliberately doesn't
513
- * carry the raw MCP SDK `extra` object — this shape is stable across
514
- * whatever the TS MCP ecosystem does with its request-handler signature. */
515
- interface SessionResolutionContext {
516
- meta: Record<string, unknown> | null;
517
- toolName: string;
518
- arguments: Record<string, unknown>;
519
- }
520
- type ResolveSessionIdHook = (context: SessionResolutionContext) => string | null | undefined | Promise<string | null | undefined>;
521
549
  interface BatonConfig {
550
+ /** The packed connection string from /account — one value carrying the
551
+ * ingest host, the workspace, the server and the key that binds them.
552
+ *
553
+ * `withBaton(server, { dsn })` is the whole wrap block a DISTRIBUTABLE
554
+ * server ships with, and that is the case it exists for: a stdio server
555
+ * runs on every user's machine, so five `BATON_*` variables are five values
556
+ * that never arrive. Resolved explicit → `BATON_DSN` → unset.
557
+ *
558
+ * **Environment variables do not override it.** A server being re-onboarded
559
+ * has last install's `.env` beside the new inline DSN, and if these values
560
+ * fell through to `BATON_TENANT_ID` the way an unset field does, the stale
561
+ * file would win silently and the events would arrive under the previous
562
+ * server's name.
563
+ *
564
+ * Passing a dsn AND an explicit `vendorId`, `tenantId` or `sink` throws:
565
+ * two sources for one value cannot be reconciled without guessing, and a
566
+ * wrong guess routes a server's traffic under someone else's identity.
567
+ * Everything else — the display name, the scrubber, the injection modes,
568
+ * every identity option — is unaffected; set them alongside a dsn freely. */
569
+ dsn?: string;
522
570
  /** Short stable identifier for the SERVER whose surface is captured
523
571
  * (e.g. `"acme"`). Also the default annotation tool name prefix
524
- * (`{vendorId}_annotate`). This is not the account — see `tenantId`. */
525
- vendorId: string;
572
+ * (`{vendorId}_annotate`). This is not the account — see `tenantId`.
573
+ *
574
+ * Required unless a `dsn` supplies it — the DSN's last path segment IS this
575
+ * value, and it is what the key is BOUND to. */
576
+ vendorId?: string;
526
577
  /** Account identifier for the envelope's `tenant_id` (SPEC §11.4).
527
578
  *
528
579
  * **This is not `vendorId`, and conflating them is the bug this field
@@ -541,15 +592,31 @@ interface BatonConfig {
541
592
  tenantId?: string;
542
593
  /** Human-readable vendor name used in server instructions and the
543
594
  * annotation tool description — whitelabel obligation (SPEC §5.4): no
544
- * Baton-branded strings reach the calling agent. */
545
- vendorDisplayName: string;
595
+ * Baton-branded strings reach the calling agent.
596
+ *
597
+ * Defaults to the DSN's server segment VERBATIM when a `dsn` is given and
598
+ * this is not. Verbatim rather than prettified: this string reaches the
599
+ * calling agent, so inventing a capitalisation the vendor never chose would
600
+ * put a fabricated name in front of their users. */
601
+ vendorDisplayName?: string;
546
602
  /** End-user consent token attached to every emitted event per SPEC §2.3 —
547
- * required, the Console MUST reject events missing it. */
548
- consentToken: string;
603
+ * the Console MUST reject events missing it.
604
+ *
605
+ * **Defaulted, so the customer never has to carry it** — see
606
+ * `DEFAULT_CONSENT_TOKEN` for why the field stays on the wire regardless.
607
+ * Passing `""` explicitly still throws: a value the vendor deliberately
608
+ * emptied is a mistake, not a request for the default.
609
+ *
610
+ * ⚠ **No environment variable is read for this, and that is parity rather
611
+ * than a gap.** Python reads `BATON_CONSENT_TOKEN` on its `Client` door
612
+ * only; its `VendorConfig` — the door this package mirrors — takes a plain
613
+ * default, and the `os.environ["BATON_CONSENT_TOKEN"]` in its install
614
+ * examples is the RECIPE passing a value explicitly, not the SDK reading
615
+ * one. Adding the read here would make this arm honour a variable the
616
+ * equivalent Python door ignores. */
617
+ consentToken?: string;
549
618
  /** Where events go. Defaults to `new StdoutSink()` — zero-config dev mode. */
550
619
  sink?: Sink;
551
- /** Default `agent_runtime` when `_meta` heuristics can't detect one. */
552
- defaultAgentRuntime?: string;
553
620
  /** PII scrubber per SPEC §7, applied to tool params/results, `_meta`,
554
621
  * intent strings and error bodies before they reach the sink. Defaults to
555
622
  * the shipped default ruleset (`new Scrubber().scrub` — email, bearer,
@@ -558,9 +625,6 @@ interface BatonConfig {
558
625
  * so untouched integrations get scrubbing without the operator opting in.
559
626
  * Pass `identityScrub` to explicitly opt out, or supply your own. */
560
627
  scrubber?: (value: unknown) => unknown;
561
- /** Optional vendor-supplied session-id resolver, checked BEFORE
562
- * `extra.sessionId` — mirrors Python's `resolve_session_id` rung 0. */
563
- resolveSessionId?: ResolveSessionIdHook;
564
628
  /** Optional override for the annotation tool name. Default is
565
629
  * `{vendorId}_annotate`. */
566
630
  annotationToolName?: string;
@@ -696,6 +760,6 @@ interface SupportedMcpServer {
696
760
  registerTool(name: string, ...rest: unknown[]): unknown;
697
761
  }
698
762
  /** Install Baton into an `McpServer`. See module docstring for usage. */
699
- declare function withBaton(server: SupportedMcpServer, config: BatonConfig): BatonHandle;
763
+ declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
700
764
 
701
- export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type BatonConfig, BatonHandle, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions, type ResolveSessionIdHook, SDK_VERSION, Scrubber, type SessionResolutionContext, 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, identityScrub, safeWrite, withBaton };
765
+ export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type BatonConfig, BatonHandle, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions, SDK_VERSION, Scrubber, 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, identityScrub, safeWrite, withBaton };