@goodtiming/baton-sdk 0.3.3 → 0.3.5

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.3";
3
+ declare const SDK_VERSION = "ts-0.3.5";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -123,7 +123,7 @@ declare const ToolCallStartEventSchema: z.ZodObject<{
123
123
  consent_token: z.ZodString;
124
124
  sdk_version: z.ZodDefault<z.ZodString>;
125
125
  agent_runtime: z.ZodDefault<z.ZodString>;
126
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
126
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
127
127
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
128
128
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
129
129
  }, z.core.$strict>;
@@ -144,7 +144,7 @@ declare const ToolCallEndEventSchema: z.ZodObject<{
144
144
  consent_token: z.ZodString;
145
145
  sdk_version: z.ZodDefault<z.ZodString>;
146
146
  agent_runtime: z.ZodDefault<z.ZodString>;
147
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
147
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
148
148
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
149
149
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
150
150
  }, z.core.$strict>;
@@ -166,7 +166,7 @@ declare const ToolCallErrorEventSchema: z.ZodObject<{
166
166
  consent_token: z.ZodString;
167
167
  sdk_version: z.ZodDefault<z.ZodString>;
168
168
  agent_runtime: z.ZodDefault<z.ZodString>;
169
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
169
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
170
170
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
171
171
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
172
172
  }, z.core.$strict>;
@@ -192,7 +192,7 @@ declare const AnnotationEventSchema: z.ZodObject<{
192
192
  consent_token: z.ZodString;
193
193
  sdk_version: z.ZodDefault<z.ZodString>;
194
194
  agent_runtime: z.ZodDefault<z.ZodString>;
195
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
195
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
196
196
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
197
197
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
198
198
  }, z.core.$strict>;
@@ -216,7 +216,7 @@ declare const SurfaceSnapshotEventSchema: z.ZodObject<{
216
216
  consent_token: z.ZodString;
217
217
  sdk_version: z.ZodDefault<z.ZodString>;
218
218
  agent_runtime: z.ZodDefault<z.ZodString>;
219
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
219
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
220
220
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
221
221
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
222
222
  }, z.core.$strict>;
@@ -240,7 +240,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
240
240
  consent_token: z.ZodString;
241
241
  sdk_version: z.ZodDefault<z.ZodString>;
242
242
  agent_runtime: z.ZodDefault<z.ZodString>;
243
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
243
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
244
244
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
245
245
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
246
246
  }, z.core.$strict>, z.ZodObject<{
@@ -259,7 +259,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
259
259
  consent_token: z.ZodString;
260
260
  sdk_version: z.ZodDefault<z.ZodString>;
261
261
  agent_runtime: z.ZodDefault<z.ZodString>;
262
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
262
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
263
263
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
264
264
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
265
265
  }, z.core.$strict>, z.ZodObject<{
@@ -279,7 +279,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
279
279
  consent_token: z.ZodString;
280
280
  sdk_version: z.ZodDefault<z.ZodString>;
281
281
  agent_runtime: z.ZodDefault<z.ZodString>;
282
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
282
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
283
283
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
284
284
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
285
285
  }, z.core.$strict>, z.ZodObject<{
@@ -303,7 +303,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
303
303
  consent_token: z.ZodString;
304
304
  sdk_version: z.ZodDefault<z.ZodString>;
305
305
  agent_runtime: z.ZodDefault<z.ZodString>;
306
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
306
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
307
307
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
308
308
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
309
309
  }, z.core.$strict>, z.ZodObject<{
@@ -325,7 +325,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
325
325
  consent_token: z.ZodString;
326
326
  sdk_version: z.ZodDefault<z.ZodString>;
327
327
  agent_runtime: z.ZodDefault<z.ZodString>;
328
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
328
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
329
329
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
330
330
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
331
331
  }, z.core.$strict>], "event_type">;
@@ -547,22 +547,22 @@ declare class HttpSink implements Sink {
547
547
  * rotation, so a vendor assertion must never be mistakable for an
548
548
  * attestation (SPEC §11.4's registered-set rule). */
549
549
  declare const VENDOR_HASH_SCHEME = "v1";
550
- declare const USER_ID_MODE_HASHED = "hashed";
551
- declare const USER_ID_MODE_RAW = "raw";
552
- type UserIdMode = typeof USER_ID_MODE_HASHED | typeof USER_ID_MODE_RAW;
553
- /** A raw, UNHASHED end-user principal, as a resolver produced it. */
550
+ declare const PRINCIPAL_ID_MODE_HASHED = "hashed";
551
+ declare const PRINCIPAL_ID_MODE_RAW = "raw";
552
+ type PrincipalIdMode = typeof PRINCIPAL_ID_MODE_HASHED | typeof PRINCIPAL_ID_MODE_RAW;
553
+ /** A raw, UNHASHED principal, as a resolver produced it. */
554
554
  interface Principal {
555
- /** The subject — a stable per-person identifier from the vendor's own
555
+ /** The subject — a stable identifier from the vendor's own
556
556
  * system. Never an application id: that names the app and is identical for
557
557
  * every one of its users, which merges them into one actor. */
558
- userId: string;
558
+ principalId: string;
559
559
  /** The issuing authority, where one exists (the OIDC `iss`). Folded into
560
560
  * the hash because a subject is unique only within the provider that minted
561
561
  * it, so two identity providers behind one vendor can hand the same subject
562
562
  * to different people. */
563
563
  issuer?: string | null | undefined;
564
564
  }
565
- /** HMAC-SHA256 a raw principal into a console-safe, per-tenant `user_id`.
565
+ /** HMAC-SHA256 a raw principal into a console-safe, per-tenant `principal_id`.
566
566
  *
567
567
  * `tenantId` is folded into the HMAC MESSAGE (not just the key) so the same
568
568
  * principal under two tenants can never collide or be cross-tenant-correlated.
@@ -578,7 +578,7 @@ interface Principal {
578
578
  * form** — the append-only message layout is what guarantees it, and every
579
579
  * hash baton-proxy and baton-extmcp have produced since 0.5.0 was issuer-less.
580
580
  */
581
- declare function hashUserId(rawPrincipal: string, options: {
581
+ declare function hashPrincipalId(rawPrincipal: string, options: {
582
582
  tenantId: string;
583
583
  key: Uint8Array | string;
584
584
  issuer?: string | null | undefined;
@@ -594,12 +594,12 @@ declare function hashUserId(rawPrincipal: string, options: {
594
594
  scheme: string;
595
595
  }): string;
596
596
 
597
- /** `BatonConfig.resolveUser` — the ASSERTED identity provenance.
597
+ /** `BatonConfig.resolvePrincipal` — the ASSERTED identity provenance.
598
598
  *
599
599
  * The TypeScript half of Python's `integrations/identity_adapter.py`, built to
600
- * close register D6: `user_id` has been on this SDK's envelope since 0.3.0 and
601
- * NOTHING could populate it, so a partition that works on one of two SDKs is
602
- * not a partition.
600
+ * close register D6: the field (`user_id` until 0.3.5) had been on this SDK's
601
+ * envelope since 0.3.0 and NOTHING could populate it, so a partition that
602
+ * works on one of two SDKs is not a partition.
603
603
  *
604
604
  * **Hook only — there is deliberately no attested (`h1:`) rung here yet.**
605
605
  * Python reads `claims["sub"]` off a verified access token; TypeScript's
@@ -611,7 +611,7 @@ declare function hashUserId(rawPrincipal: string, options: {
611
611
  * as a divergence rather than filled with a guess.
612
612
  */
613
613
 
614
- /** What a vendor's `resolveUser` hook is handed.
614
+ /** What a vendor's `resolvePrincipal` hook is handed.
615
615
  *
616
616
  * Adapter-neutral BY CONSTRUCTION rather than by convention — the peers' own
617
617
  * handler-context objects differ in shape between the two majors, and this
@@ -622,7 +622,7 @@ declare function hashUserId(rawPrincipal: string, options: {
622
622
  * That is the divergence handed to the vendor as `any`; this is the divergence
623
623
  * absorbed by us.
624
624
  */
625
- interface UserResolutionContext {
625
+ interface PrincipalResolutionContext {
626
626
  /** The call's HTTP headers, case-insensitive on BOTH majors — see
627
627
  * `extraHeaders` for the two shapes it reconciles.
628
628
  *
@@ -642,7 +642,7 @@ interface UserResolutionContext {
642
642
  }
643
643
  /** A vendor's per-request identity resolver. Sync or async; returning `null`
644
644
  * means "no opinion about this caller", which is not an error. */
645
- type ResolveUserHook = (context: UserResolutionContext) => Principal | null | Promise<Principal | null>;
645
+ type ResolvePrincipalHook = (context: PrincipalResolutionContext) => Principal | null | Promise<Principal | null>;
646
646
 
647
647
  /**
648
648
  * `BatonConfig` — vendor-side configuration for `withBaton`. A trimmed
@@ -697,10 +697,13 @@ interface BatonConfig {
697
697
  * annotation tool description — whitelabel obligation (SPEC §5.4): no
698
698
  * Baton-branded strings reach the calling agent.
699
699
  *
700
- * Defaults to the DSN's server segment VERBATIM when a `dsn` is given and
701
- * this is not. Verbatim rather than prettified: this string reaches the
702
- * calling agent, so inventing a capitalisation the vendor never chose would
703
- * put a fabricated name in front of their users. */
700
+ * When a `dsn` is given and this is not, defaults to your server's OWN name
701
+ * (`new McpServer({ name })`), VERBATIM: a string you chose, which makes it
702
+ * the one to put in front of your users. Verbatim rather than prettified
703
+ * for the same reason: a capitalisation you never chose would be a
704
+ * fabricated name. Falls back to the DSN's server segment when the server's
705
+ * name is one a library made up, is blank or unreadable, or would push the
706
+ * server instructions over their cap. With no `dsn`, this is required. */
704
707
  vendorDisplayName?: string;
705
708
  /** End-user consent token attached to every emitted event per SPEC §2.3 —
706
709
  * the Console MUST reject events missing it.
@@ -728,8 +731,13 @@ interface BatonConfig {
728
731
  * so untouched integrations get scrubbing without the operator opting in.
729
732
  * Pass `identityScrub` to explicitly opt out, or supply your own. */
730
733
  scrubber?: (value: unknown) => unknown;
731
- /** Optional override for the annotation tool name. Default is
732
- * `{vendorId}_annotate`. */
734
+ /** Optional override for the annotation tool name, and the only thing that
735
+ * pins it. The default is derived from your server's own name, slugged: a
736
+ * server called `"Acme Knowledge Base"` registers
737
+ * `acme-knowledge-base_annotate`. It falls back to `{vendorId}_annotate`
738
+ * when the name is one a library made up, slugs to nothing, is unreadable,
739
+ * or would not fit the server instructions. Set this to keep a name you have
740
+ * written into documentation, a prompt or a script. */
733
741
  annotationToolName?: string;
734
742
  /** Per-tool intent-param injection (mirrors baton-extmcp's vendor-neutral
735
743
  * naming). `"optional"` (default) injects `user_goal`/`expected_result`
@@ -742,38 +750,38 @@ interface BatonConfig {
742
750
  * nothing. A tool registered with no `inputSchema` at all is left alone
743
751
  * regardless of this setting (see `schemaCompat.injectGoalParams`). */
744
752
  intentParamMode?: "optional" | "required" | "off";
745
- /** Per-request end-user identity — the ASSERTED provenance behind the
746
- * envelope's `user_id` (SPEC §11.4 rung 0), tagged `v1:`.
753
+ /** Per-request principal identity — the ASSERTED provenance behind the
754
+ * envelope's `principal_id` (SPEC §11.4 rung 0), tagged `v1:`.
747
755
  *
748
756
  * Called on every captured tool call and on the annotation tool, with an
749
- * adapter-neutral {@link UserResolutionContext}: headers folded to ONE
757
+ * adapter-neutral {@link PrincipalResolutionContext}: headers folded to ONE
750
758
  * case-insensitive shape across both SDK majors, the call's `_meta`, the
751
759
  * tool name, and the arguments the vendor's own handler will see. Return a
752
760
  * `Principal`, or `null` for "no opinion about this caller".
753
761
  *
754
762
  * **This is the only identity mechanism on this arm.** MCP auth is HTTP
755
763
  * middleware, so a stdio server has no token at all; and unlike Python, no
756
- * attested rung is implemented here — see `userResolution.ts` for why
764
+ * attested rung is implemented here — see `principalResolution.ts` for why
757
765
  * (TypeScript's `AuthInfo` carries no `claims`).
758
766
  *
759
767
  * Never fails a tool call: a hook that throws or returns junk yields an
760
768
  * anonymous call. ⚠ It is awaited INLINE with no timeout — a blocking hook
761
769
  * stalls its own request. */
762
- resolveUser?: ResolveUserHook;
770
+ resolvePrincipal?: ResolvePrincipalHook;
763
771
  /** `"hashed"` (default) emits a `v1:` per-tenant HMAC pseudonym; `"raw"`
764
772
  * emits the subject VERBATIM.
765
773
  *
766
- * `"raw"` puts real end-user identity in the collector's database and is the
774
+ * `"raw"` puts real identity in the collector's database and is the
767
775
  * vendor's deliberate choice — which is why SPEC §11.4 tells a consumer
768
776
  * never to treat this field as anonymous. */
769
- userIdMode?: "hashed" | "raw";
777
+ principalIdMode?: "hashed" | "raw";
770
778
  /** The HMAC secret for hashed mode. Resolved explicit →
771
- * `BATON_USER_ID_HMAC_KEY` → unset.
779
+ * `BATON_PRINCIPAL_ID_HMAC_KEY` → unset.
772
780
  *
773
- * ⚠ **With none set, hashed mode DROPS `user_id` rather than falling back to
781
+ * ⚠ **With none set, hashed mode DROPS `principal_id` rather than falling back to
774
782
  * raw.** The fallback would be a residency breach that looks like success:
775
783
  * the field present, populated, and carrying the subject verbatim. */
776
- userIdHmacKey?: string | Uint8Array;
784
+ principalIdHmacKey?: string | Uint8Array;
777
785
  }
778
786
 
779
787
  /**
@@ -789,8 +797,9 @@ declare class BatonHandle {
789
797
  * when no real per-call session id resolves. Not every event necessarily
790
798
  * carries this id; see `withBaton`'s session-resolution order. */
791
799
  readonly sessionId: string;
792
- /** The resolved annotation tool name (`{vendorId}_annotate` unless
793
- * overridden via `BatonConfig.annotationToolName`). */
800
+ /** The resolved annotation tool name: `BatonConfig.annotationToolName` if
801
+ * set, else derived from the server's own name (`{slug}_annotate`), else
802
+ * `{vendorId}_annotate`. */
794
803
  readonly annotationToolName: string;
795
804
  constructor(options: {
796
805
  sink: Sink;
@@ -897,4 +906,4 @@ interface SupportedMcpServer {
897
906
  /** Install Baton into an `McpServer`. See module docstring for usage. */
898
907
  declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
899
908
 
900
- export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type BatonConfig, BatonHandle, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions, type Principal, type ResolveUserHook, 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, type UserIdMode, type UserResolutionContext, VENDOR_HASH_SCHEME, hashUserId, identityScrub, safeWrite, withBaton };
909
+ export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type BatonConfig, BatonHandle, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions, type Principal, type PrincipalIdMode, type PrincipalResolutionContext, type ResolvePrincipalHook, 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, VENDOR_HASH_SCHEME, hashPrincipalId, 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.3";
3
+ declare const SDK_VERSION = "ts-0.3.5";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -123,7 +123,7 @@ declare const ToolCallStartEventSchema: z.ZodObject<{
123
123
  consent_token: z.ZodString;
124
124
  sdk_version: z.ZodDefault<z.ZodString>;
125
125
  agent_runtime: z.ZodDefault<z.ZodString>;
126
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
126
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
127
127
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
128
128
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
129
129
  }, z.core.$strict>;
@@ -144,7 +144,7 @@ declare const ToolCallEndEventSchema: z.ZodObject<{
144
144
  consent_token: z.ZodString;
145
145
  sdk_version: z.ZodDefault<z.ZodString>;
146
146
  agent_runtime: z.ZodDefault<z.ZodString>;
147
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
147
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
148
148
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
149
149
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
150
150
  }, z.core.$strict>;
@@ -166,7 +166,7 @@ declare const ToolCallErrorEventSchema: z.ZodObject<{
166
166
  consent_token: z.ZodString;
167
167
  sdk_version: z.ZodDefault<z.ZodString>;
168
168
  agent_runtime: z.ZodDefault<z.ZodString>;
169
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
169
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
170
170
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
171
171
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
172
172
  }, z.core.$strict>;
@@ -192,7 +192,7 @@ declare const AnnotationEventSchema: z.ZodObject<{
192
192
  consent_token: z.ZodString;
193
193
  sdk_version: z.ZodDefault<z.ZodString>;
194
194
  agent_runtime: z.ZodDefault<z.ZodString>;
195
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
195
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
196
196
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
197
197
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
198
198
  }, z.core.$strict>;
@@ -216,7 +216,7 @@ declare const SurfaceSnapshotEventSchema: z.ZodObject<{
216
216
  consent_token: z.ZodString;
217
217
  sdk_version: z.ZodDefault<z.ZodString>;
218
218
  agent_runtime: z.ZodDefault<z.ZodString>;
219
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
219
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
220
220
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
221
221
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
222
222
  }, z.core.$strict>;
@@ -240,7 +240,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
240
240
  consent_token: z.ZodString;
241
241
  sdk_version: z.ZodDefault<z.ZodString>;
242
242
  agent_runtime: z.ZodDefault<z.ZodString>;
243
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
243
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
244
244
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
245
245
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
246
246
  }, z.core.$strict>, z.ZodObject<{
@@ -259,7 +259,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
259
259
  consent_token: z.ZodString;
260
260
  sdk_version: z.ZodDefault<z.ZodString>;
261
261
  agent_runtime: z.ZodDefault<z.ZodString>;
262
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
262
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
263
263
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
264
264
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
265
265
  }, z.core.$strict>, z.ZodObject<{
@@ -279,7 +279,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
279
279
  consent_token: z.ZodString;
280
280
  sdk_version: z.ZodDefault<z.ZodString>;
281
281
  agent_runtime: z.ZodDefault<z.ZodString>;
282
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
282
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
283
283
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
284
284
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
285
285
  }, z.core.$strict>, z.ZodObject<{
@@ -303,7 +303,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
303
303
  consent_token: z.ZodString;
304
304
  sdk_version: z.ZodDefault<z.ZodString>;
305
305
  agent_runtime: z.ZodDefault<z.ZodString>;
306
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
306
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
307
307
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
308
308
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
309
309
  }, z.core.$strict>, z.ZodObject<{
@@ -325,7 +325,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
325
325
  consent_token: z.ZodString;
326
326
  sdk_version: z.ZodDefault<z.ZodString>;
327
327
  agent_runtime: z.ZodDefault<z.ZodString>;
328
- user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
328
+ principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
329
329
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
330
330
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
331
331
  }, z.core.$strict>], "event_type">;
@@ -547,22 +547,22 @@ declare class HttpSink implements Sink {
547
547
  * rotation, so a vendor assertion must never be mistakable for an
548
548
  * attestation (SPEC §11.4's registered-set rule). */
549
549
  declare const VENDOR_HASH_SCHEME = "v1";
550
- declare const USER_ID_MODE_HASHED = "hashed";
551
- declare const USER_ID_MODE_RAW = "raw";
552
- type UserIdMode = typeof USER_ID_MODE_HASHED | typeof USER_ID_MODE_RAW;
553
- /** A raw, UNHASHED end-user principal, as a resolver produced it. */
550
+ declare const PRINCIPAL_ID_MODE_HASHED = "hashed";
551
+ declare const PRINCIPAL_ID_MODE_RAW = "raw";
552
+ type PrincipalIdMode = typeof PRINCIPAL_ID_MODE_HASHED | typeof PRINCIPAL_ID_MODE_RAW;
553
+ /** A raw, UNHASHED principal, as a resolver produced it. */
554
554
  interface Principal {
555
- /** The subject — a stable per-person identifier from the vendor's own
555
+ /** The subject — a stable identifier from the vendor's own
556
556
  * system. Never an application id: that names the app and is identical for
557
557
  * every one of its users, which merges them into one actor. */
558
- userId: string;
558
+ principalId: string;
559
559
  /** The issuing authority, where one exists (the OIDC `iss`). Folded into
560
560
  * the hash because a subject is unique only within the provider that minted
561
561
  * it, so two identity providers behind one vendor can hand the same subject
562
562
  * to different people. */
563
563
  issuer?: string | null | undefined;
564
564
  }
565
- /** HMAC-SHA256 a raw principal into a console-safe, per-tenant `user_id`.
565
+ /** HMAC-SHA256 a raw principal into a console-safe, per-tenant `principal_id`.
566
566
  *
567
567
  * `tenantId` is folded into the HMAC MESSAGE (not just the key) so the same
568
568
  * principal under two tenants can never collide or be cross-tenant-correlated.
@@ -578,7 +578,7 @@ interface Principal {
578
578
  * form** — the append-only message layout is what guarantees it, and every
579
579
  * hash baton-proxy and baton-extmcp have produced since 0.5.0 was issuer-less.
580
580
  */
581
- declare function hashUserId(rawPrincipal: string, options: {
581
+ declare function hashPrincipalId(rawPrincipal: string, options: {
582
582
  tenantId: string;
583
583
  key: Uint8Array | string;
584
584
  issuer?: string | null | undefined;
@@ -594,12 +594,12 @@ declare function hashUserId(rawPrincipal: string, options: {
594
594
  scheme: string;
595
595
  }): string;
596
596
 
597
- /** `BatonConfig.resolveUser` — the ASSERTED identity provenance.
597
+ /** `BatonConfig.resolvePrincipal` — the ASSERTED identity provenance.
598
598
  *
599
599
  * The TypeScript half of Python's `integrations/identity_adapter.py`, built to
600
- * close register D6: `user_id` has been on this SDK's envelope since 0.3.0 and
601
- * NOTHING could populate it, so a partition that works on one of two SDKs is
602
- * not a partition.
600
+ * close register D6: the field (`user_id` until 0.3.5) had been on this SDK's
601
+ * envelope since 0.3.0 and NOTHING could populate it, so a partition that
602
+ * works on one of two SDKs is not a partition.
603
603
  *
604
604
  * **Hook only — there is deliberately no attested (`h1:`) rung here yet.**
605
605
  * Python reads `claims["sub"]` off a verified access token; TypeScript's
@@ -611,7 +611,7 @@ declare function hashUserId(rawPrincipal: string, options: {
611
611
  * as a divergence rather than filled with a guess.
612
612
  */
613
613
 
614
- /** What a vendor's `resolveUser` hook is handed.
614
+ /** What a vendor's `resolvePrincipal` hook is handed.
615
615
  *
616
616
  * Adapter-neutral BY CONSTRUCTION rather than by convention — the peers' own
617
617
  * handler-context objects differ in shape between the two majors, and this
@@ -622,7 +622,7 @@ declare function hashUserId(rawPrincipal: string, options: {
622
622
  * That is the divergence handed to the vendor as `any`; this is the divergence
623
623
  * absorbed by us.
624
624
  */
625
- interface UserResolutionContext {
625
+ interface PrincipalResolutionContext {
626
626
  /** The call's HTTP headers, case-insensitive on BOTH majors — see
627
627
  * `extraHeaders` for the two shapes it reconciles.
628
628
  *
@@ -642,7 +642,7 @@ interface UserResolutionContext {
642
642
  }
643
643
  /** A vendor's per-request identity resolver. Sync or async; returning `null`
644
644
  * means "no opinion about this caller", which is not an error. */
645
- type ResolveUserHook = (context: UserResolutionContext) => Principal | null | Promise<Principal | null>;
645
+ type ResolvePrincipalHook = (context: PrincipalResolutionContext) => Principal | null | Promise<Principal | null>;
646
646
 
647
647
  /**
648
648
  * `BatonConfig` — vendor-side configuration for `withBaton`. A trimmed
@@ -697,10 +697,13 @@ interface BatonConfig {
697
697
  * annotation tool description — whitelabel obligation (SPEC §5.4): no
698
698
  * Baton-branded strings reach the calling agent.
699
699
  *
700
- * Defaults to the DSN's server segment VERBATIM when a `dsn` is given and
701
- * this is not. Verbatim rather than prettified: this string reaches the
702
- * calling agent, so inventing a capitalisation the vendor never chose would
703
- * put a fabricated name in front of their users. */
700
+ * When a `dsn` is given and this is not, defaults to your server's OWN name
701
+ * (`new McpServer({ name })`), VERBATIM: a string you chose, which makes it
702
+ * the one to put in front of your users. Verbatim rather than prettified
703
+ * for the same reason: a capitalisation you never chose would be a
704
+ * fabricated name. Falls back to the DSN's server segment when the server's
705
+ * name is one a library made up, is blank or unreadable, or would push the
706
+ * server instructions over their cap. With no `dsn`, this is required. */
704
707
  vendorDisplayName?: string;
705
708
  /** End-user consent token attached to every emitted event per SPEC §2.3 —
706
709
  * the Console MUST reject events missing it.
@@ -728,8 +731,13 @@ interface BatonConfig {
728
731
  * so untouched integrations get scrubbing without the operator opting in.
729
732
  * Pass `identityScrub` to explicitly opt out, or supply your own. */
730
733
  scrubber?: (value: unknown) => unknown;
731
- /** Optional override for the annotation tool name. Default is
732
- * `{vendorId}_annotate`. */
734
+ /** Optional override for the annotation tool name, and the only thing that
735
+ * pins it. The default is derived from your server's own name, slugged: a
736
+ * server called `"Acme Knowledge Base"` registers
737
+ * `acme-knowledge-base_annotate`. It falls back to `{vendorId}_annotate`
738
+ * when the name is one a library made up, slugs to nothing, is unreadable,
739
+ * or would not fit the server instructions. Set this to keep a name you have
740
+ * written into documentation, a prompt or a script. */
733
741
  annotationToolName?: string;
734
742
  /** Per-tool intent-param injection (mirrors baton-extmcp's vendor-neutral
735
743
  * naming). `"optional"` (default) injects `user_goal`/`expected_result`
@@ -742,38 +750,38 @@ interface BatonConfig {
742
750
  * nothing. A tool registered with no `inputSchema` at all is left alone
743
751
  * regardless of this setting (see `schemaCompat.injectGoalParams`). */
744
752
  intentParamMode?: "optional" | "required" | "off";
745
- /** Per-request end-user identity — the ASSERTED provenance behind the
746
- * envelope's `user_id` (SPEC §11.4 rung 0), tagged `v1:`.
753
+ /** Per-request principal identity — the ASSERTED provenance behind the
754
+ * envelope's `principal_id` (SPEC §11.4 rung 0), tagged `v1:`.
747
755
  *
748
756
  * Called on every captured tool call and on the annotation tool, with an
749
- * adapter-neutral {@link UserResolutionContext}: headers folded to ONE
757
+ * adapter-neutral {@link PrincipalResolutionContext}: headers folded to ONE
750
758
  * case-insensitive shape across both SDK majors, the call's `_meta`, the
751
759
  * tool name, and the arguments the vendor's own handler will see. Return a
752
760
  * `Principal`, or `null` for "no opinion about this caller".
753
761
  *
754
762
  * **This is the only identity mechanism on this arm.** MCP auth is HTTP
755
763
  * middleware, so a stdio server has no token at all; and unlike Python, no
756
- * attested rung is implemented here — see `userResolution.ts` for why
764
+ * attested rung is implemented here — see `principalResolution.ts` for why
757
765
  * (TypeScript's `AuthInfo` carries no `claims`).
758
766
  *
759
767
  * Never fails a tool call: a hook that throws or returns junk yields an
760
768
  * anonymous call. ⚠ It is awaited INLINE with no timeout — a blocking hook
761
769
  * stalls its own request. */
762
- resolveUser?: ResolveUserHook;
770
+ resolvePrincipal?: ResolvePrincipalHook;
763
771
  /** `"hashed"` (default) emits a `v1:` per-tenant HMAC pseudonym; `"raw"`
764
772
  * emits the subject VERBATIM.
765
773
  *
766
- * `"raw"` puts real end-user identity in the collector's database and is the
774
+ * `"raw"` puts real identity in the collector's database and is the
767
775
  * vendor's deliberate choice — which is why SPEC §11.4 tells a consumer
768
776
  * never to treat this field as anonymous. */
769
- userIdMode?: "hashed" | "raw";
777
+ principalIdMode?: "hashed" | "raw";
770
778
  /** The HMAC secret for hashed mode. Resolved explicit →
771
- * `BATON_USER_ID_HMAC_KEY` → unset.
779
+ * `BATON_PRINCIPAL_ID_HMAC_KEY` → unset.
772
780
  *
773
- * ⚠ **With none set, hashed mode DROPS `user_id` rather than falling back to
781
+ * ⚠ **With none set, hashed mode DROPS `principal_id` rather than falling back to
774
782
  * raw.** The fallback would be a residency breach that looks like success:
775
783
  * the field present, populated, and carrying the subject verbatim. */
776
- userIdHmacKey?: string | Uint8Array;
784
+ principalIdHmacKey?: string | Uint8Array;
777
785
  }
778
786
 
779
787
  /**
@@ -789,8 +797,9 @@ declare class BatonHandle {
789
797
  * when no real per-call session id resolves. Not every event necessarily
790
798
  * carries this id; see `withBaton`'s session-resolution order. */
791
799
  readonly sessionId: string;
792
- /** The resolved annotation tool name (`{vendorId}_annotate` unless
793
- * overridden via `BatonConfig.annotationToolName`). */
800
+ /** The resolved annotation tool name: `BatonConfig.annotationToolName` if
801
+ * set, else derived from the server's own name (`{slug}_annotate`), else
802
+ * `{vendorId}_annotate`. */
794
803
  readonly annotationToolName: string;
795
804
  constructor(options: {
796
805
  sink: Sink;
@@ -897,4 +906,4 @@ interface SupportedMcpServer {
897
906
  /** Install Baton into an `McpServer`. See module docstring for usage. */
898
907
  declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
899
908
 
900
- export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type BatonConfig, BatonHandle, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions, type Principal, type ResolveUserHook, 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, type UserIdMode, type UserResolutionContext, VENDOR_HASH_SCHEME, hashUserId, identityScrub, safeWrite, withBaton };
909
+ export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type BatonConfig, BatonHandle, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions, type Principal, type PrincipalIdMode, type PrincipalResolutionContext, type ResolvePrincipalHook, 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, VENDOR_HASH_SCHEME, hashPrincipalId, identityScrub, safeWrite, withBaton };