@goodtiming/baton-sdk 0.3.2 → 0.3.4
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/README.md +1 -1
- package/dist/index.cjs +305 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +154 -10
- package/dist/index.d.ts +154 -10
- package/dist/index.js +301 -43
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
+
declare const SDK_VERSION = "ts-0.3.4";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -541,6 +541,109 @@ declare class HttpSink implements Sink {
|
|
|
541
541
|
private sendWithRetry;
|
|
542
542
|
}
|
|
543
543
|
|
|
544
|
+
/** The ASSERTED derivation tag — a principal a vendor's own hook supplied.
|
|
545
|
+
*
|
|
546
|
+
* Deliberately outside the `h*` family: `h2:` is reserved for HMAC key
|
|
547
|
+
* rotation, so a vendor assertion must never be mistakable for an
|
|
548
|
+
* attestation (SPEC §11.4's registered-set rule). */
|
|
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. */
|
|
554
|
+
interface Principal {
|
|
555
|
+
/** The subject — a stable per-person identifier from the vendor's own
|
|
556
|
+
* system. Never an application id: that names the app and is identical for
|
|
557
|
+
* every one of its users, which merges them into one actor. */
|
|
558
|
+
userId: string;
|
|
559
|
+
/** The issuing authority, where one exists (the OIDC `iss`). Folded into
|
|
560
|
+
* the hash because a subject is unique only within the provider that minted
|
|
561
|
+
* it, so two identity providers behind one vendor can hand the same subject
|
|
562
|
+
* to different people. */
|
|
563
|
+
issuer?: string | null | undefined;
|
|
564
|
+
}
|
|
565
|
+
/** HMAC-SHA256 a raw principal into a console-safe, per-tenant `user_id`.
|
|
566
|
+
*
|
|
567
|
+
* `tenantId` is folded into the HMAC MESSAGE (not just the key) so the same
|
|
568
|
+
* principal under two tenants can never collide or be cross-tenant-correlated.
|
|
569
|
+
* Returns `"<scheme>:<hex>"`.
|
|
570
|
+
*
|
|
571
|
+
* `scheme` tags the DERIVATION and only the tag changes — the digest for a
|
|
572
|
+
* given `(tenantId, principal, issuer)` is identical under every scheme,
|
|
573
|
+
* because the tag is not part of the message. That is deliberate: the same
|
|
574
|
+
* person reached by two provenances is meant to be recognisably the same hex
|
|
575
|
+
* under two tags, not two unrelated values.
|
|
576
|
+
*
|
|
577
|
+
* ⚠ **`issuer` null/undefined MUST hash byte-identically to the pre-issuer
|
|
578
|
+
* form** — the append-only message layout is what guarantees it, and every
|
|
579
|
+
* hash baton-proxy and baton-extmcp have produced since 0.5.0 was issuer-less.
|
|
580
|
+
*/
|
|
581
|
+
declare function hashUserId(rawPrincipal: string, options: {
|
|
582
|
+
tenantId: string;
|
|
583
|
+
key: Uint8Array | string;
|
|
584
|
+
issuer?: string | null | undefined;
|
|
585
|
+
/** ⚠ **REQUIRED, and deliberately NOT defaulted the way Python's is.**
|
|
586
|
+
* Python defaults to `HASH_SCHEME` (`h1:`), which is right there because
|
|
587
|
+
* that arm emits both provenances. This arm emits ONLY `v1:` — it has no
|
|
588
|
+
* attested rung — so an `h1:` default would hand the documented
|
|
589
|
+
* "recompute the pseudonym to join your own records against Console data"
|
|
590
|
+
* use a value matching nothing we ever wrote, forever, with an equality
|
|
591
|
+
* join silently returning zero rows. The hex halves are identical under
|
|
592
|
+
* both tags, so it fails in the most confusing way available. Naming the
|
|
593
|
+
* provenance is one word and removes the whole failure. */
|
|
594
|
+
scheme: string;
|
|
595
|
+
}): string;
|
|
596
|
+
|
|
597
|
+
/** `BatonConfig.resolveUser` — the ASSERTED identity provenance.
|
|
598
|
+
*
|
|
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.
|
|
603
|
+
*
|
|
604
|
+
* **Hook only — there is deliberately no attested (`h1:`) rung here yet.**
|
|
605
|
+
* Python reads `claims["sub"]` off a verified access token; TypeScript's
|
|
606
|
+
* `AuthInfo` has no `claims` field at all (it is
|
|
607
|
+
* `{token, clientId, scopes, expiresAt?, resource?, extra?}`), so the nearest
|
|
608
|
+
* carrier is the untyped `extra` bag and nothing specifies that `sub` lives
|
|
609
|
+
* there. Reading it would mean guessing where a subject lives, vendor by
|
|
610
|
+
* vendor — and a wrong guess is how two people end up as one actor. Recorded
|
|
611
|
+
* as a divergence rather than filled with a guess.
|
|
612
|
+
*/
|
|
613
|
+
|
|
614
|
+
/** What a vendor's `resolveUser` hook is handed.
|
|
615
|
+
*
|
|
616
|
+
* Adapter-neutral BY CONSTRUCTION rather than by convention — the peers' own
|
|
617
|
+
* handler-context objects differ in shape between the two majors, and this
|
|
618
|
+
* type is what makes one hook portable across them. The prior art takes the
|
|
619
|
+
* opposite approach: AgentCat's `identify()` receives the raw per-major object
|
|
620
|
+
* behind `{ sessionId?: string; [key: string]: any }`, documented as "only
|
|
621
|
+
* `sessionId` is common to both; everything else is SDK-version-specific".
|
|
622
|
+
* That is the divergence handed to the vendor as `any`; this is the divergence
|
|
623
|
+
* absorbed by us.
|
|
624
|
+
*/
|
|
625
|
+
interface UserResolutionContext {
|
|
626
|
+
/** The call's HTTP headers, case-insensitive on BOTH majors — see
|
|
627
|
+
* `extraHeaders` for the two shapes it reconciles.
|
|
628
|
+
*
|
|
629
|
+
* `null` means NO HTTP REQUEST (every stdio call, the common case), never
|
|
630
|
+
* "the client sent no headers". The distinction matters: the first is us
|
|
631
|
+
* telling you the question does not apply, the second would be a claim about
|
|
632
|
+
* the caller that we are not in a position to make. */
|
|
633
|
+
headers: Headers | null;
|
|
634
|
+
/** The call's `_meta`, from wherever this major keeps it. */
|
|
635
|
+
meta: Record<string, unknown> | null;
|
|
636
|
+
/** The tool being called — the annotation tool's own name on that path, so a
|
|
637
|
+
* hook can answer differently per call rather than per install. */
|
|
638
|
+
toolName: string;
|
|
639
|
+
/** The call's arguments, AFTER Baton's injected intent params are stripped,
|
|
640
|
+
* so a hook sees exactly what the vendor's own handler will. */
|
|
641
|
+
arguments: Record<string, unknown>;
|
|
642
|
+
}
|
|
643
|
+
/** A vendor's per-request identity resolver. Sync or async; returning `null`
|
|
644
|
+
* means "no opinion about this caller", which is not an error. */
|
|
645
|
+
type ResolveUserHook = (context: UserResolutionContext) => Principal | null | Promise<Principal | null>;
|
|
646
|
+
|
|
544
647
|
/**
|
|
545
648
|
* `BatonConfig` — vendor-side configuration for `withBaton`. A trimmed
|
|
546
649
|
* mirror of `baton` (Python)'s `integrations/_config.py::VendorConfig`.
|
|
@@ -594,10 +697,13 @@ interface BatonConfig {
|
|
|
594
697
|
* annotation tool description — whitelabel obligation (SPEC §5.4): no
|
|
595
698
|
* Baton-branded strings reach the calling agent.
|
|
596
699
|
*
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
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. */
|
|
601
707
|
vendorDisplayName?: string;
|
|
602
708
|
/** End-user consent token attached to every emitted event per SPEC §2.3 —
|
|
603
709
|
* the Console MUST reject events missing it.
|
|
@@ -625,8 +731,13 @@ interface BatonConfig {
|
|
|
625
731
|
* so untouched integrations get scrubbing without the operator opting in.
|
|
626
732
|
* Pass `identityScrub` to explicitly opt out, or supply your own. */
|
|
627
733
|
scrubber?: (value: unknown) => unknown;
|
|
628
|
-
/** Optional override for the annotation tool name
|
|
629
|
-
*
|
|
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. */
|
|
630
741
|
annotationToolName?: string;
|
|
631
742
|
/** Per-tool intent-param injection (mirrors baton-extmcp's vendor-neutral
|
|
632
743
|
* naming). `"optional"` (default) injects `user_goal`/`expected_result`
|
|
@@ -639,6 +750,38 @@ interface BatonConfig {
|
|
|
639
750
|
* nothing. A tool registered with no `inputSchema` at all is left alone
|
|
640
751
|
* regardless of this setting (see `schemaCompat.injectGoalParams`). */
|
|
641
752
|
intentParamMode?: "optional" | "required" | "off";
|
|
753
|
+
/** Per-request end-user identity — the ASSERTED provenance behind the
|
|
754
|
+
* envelope's `user_id` (SPEC §11.4 rung 0), tagged `v1:`.
|
|
755
|
+
*
|
|
756
|
+
* Called on every captured tool call and on the annotation tool, with an
|
|
757
|
+
* adapter-neutral {@link UserResolutionContext}: headers folded to ONE
|
|
758
|
+
* case-insensitive shape across both SDK majors, the call's `_meta`, the
|
|
759
|
+
* tool name, and the arguments the vendor's own handler will see. Return a
|
|
760
|
+
* `Principal`, or `null` for "no opinion about this caller".
|
|
761
|
+
*
|
|
762
|
+
* **This is the only identity mechanism on this arm.** MCP auth is HTTP
|
|
763
|
+
* middleware, so a stdio server has no token at all; and unlike Python, no
|
|
764
|
+
* attested rung is implemented here — see `userResolution.ts` for why
|
|
765
|
+
* (TypeScript's `AuthInfo` carries no `claims`).
|
|
766
|
+
*
|
|
767
|
+
* Never fails a tool call: a hook that throws or returns junk yields an
|
|
768
|
+
* anonymous call. ⚠ It is awaited INLINE with no timeout — a blocking hook
|
|
769
|
+
* stalls its own request. */
|
|
770
|
+
resolveUser?: ResolveUserHook;
|
|
771
|
+
/** `"hashed"` (default) emits a `v1:` per-tenant HMAC pseudonym; `"raw"`
|
|
772
|
+
* emits the subject VERBATIM.
|
|
773
|
+
*
|
|
774
|
+
* `"raw"` puts real end-user identity in the collector's database and is the
|
|
775
|
+
* vendor's deliberate choice — which is why SPEC §11.4 tells a consumer
|
|
776
|
+
* never to treat this field as anonymous. */
|
|
777
|
+
userIdMode?: "hashed" | "raw";
|
|
778
|
+
/** The HMAC secret for hashed mode. Resolved explicit →
|
|
779
|
+
* `BATON_USER_ID_HMAC_KEY` → unset.
|
|
780
|
+
*
|
|
781
|
+
* ⚠ **With none set, hashed mode DROPS `user_id` rather than falling back to
|
|
782
|
+
* raw.** The fallback would be a residency breach that looks like success:
|
|
783
|
+
* the field present, populated, and carrying the subject verbatim. */
|
|
784
|
+
userIdHmacKey?: string | Uint8Array;
|
|
642
785
|
}
|
|
643
786
|
|
|
644
787
|
/**
|
|
@@ -654,8 +797,9 @@ declare class BatonHandle {
|
|
|
654
797
|
* when no real per-call session id resolves. Not every event necessarily
|
|
655
798
|
* carries this id; see `withBaton`'s session-resolution order. */
|
|
656
799
|
readonly sessionId: string;
|
|
657
|
-
/** The resolved annotation tool name
|
|
658
|
-
*
|
|
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`. */
|
|
659
803
|
readonly annotationToolName: string;
|
|
660
804
|
constructor(options: {
|
|
661
805
|
sink: Sink;
|
|
@@ -762,4 +906,4 @@ interface SupportedMcpServer {
|
|
|
762
906
|
/** Install Baton into an `McpServer`. See module docstring for usage. */
|
|
763
907
|
declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
|
|
764
908
|
|
|
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 };
|
|
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 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 };
|
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
|
+
declare const SDK_VERSION = "ts-0.3.4";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -541,6 +541,109 @@ declare class HttpSink implements Sink {
|
|
|
541
541
|
private sendWithRetry;
|
|
542
542
|
}
|
|
543
543
|
|
|
544
|
+
/** The ASSERTED derivation tag — a principal a vendor's own hook supplied.
|
|
545
|
+
*
|
|
546
|
+
* Deliberately outside the `h*` family: `h2:` is reserved for HMAC key
|
|
547
|
+
* rotation, so a vendor assertion must never be mistakable for an
|
|
548
|
+
* attestation (SPEC §11.4's registered-set rule). */
|
|
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. */
|
|
554
|
+
interface Principal {
|
|
555
|
+
/** The subject — a stable per-person identifier from the vendor's own
|
|
556
|
+
* system. Never an application id: that names the app and is identical for
|
|
557
|
+
* every one of its users, which merges them into one actor. */
|
|
558
|
+
userId: string;
|
|
559
|
+
/** The issuing authority, where one exists (the OIDC `iss`). Folded into
|
|
560
|
+
* the hash because a subject is unique only within the provider that minted
|
|
561
|
+
* it, so two identity providers behind one vendor can hand the same subject
|
|
562
|
+
* to different people. */
|
|
563
|
+
issuer?: string | null | undefined;
|
|
564
|
+
}
|
|
565
|
+
/** HMAC-SHA256 a raw principal into a console-safe, per-tenant `user_id`.
|
|
566
|
+
*
|
|
567
|
+
* `tenantId` is folded into the HMAC MESSAGE (not just the key) so the same
|
|
568
|
+
* principal under two tenants can never collide or be cross-tenant-correlated.
|
|
569
|
+
* Returns `"<scheme>:<hex>"`.
|
|
570
|
+
*
|
|
571
|
+
* `scheme` tags the DERIVATION and only the tag changes — the digest for a
|
|
572
|
+
* given `(tenantId, principal, issuer)` is identical under every scheme,
|
|
573
|
+
* because the tag is not part of the message. That is deliberate: the same
|
|
574
|
+
* person reached by two provenances is meant to be recognisably the same hex
|
|
575
|
+
* under two tags, not two unrelated values.
|
|
576
|
+
*
|
|
577
|
+
* ⚠ **`issuer` null/undefined MUST hash byte-identically to the pre-issuer
|
|
578
|
+
* form** — the append-only message layout is what guarantees it, and every
|
|
579
|
+
* hash baton-proxy and baton-extmcp have produced since 0.5.0 was issuer-less.
|
|
580
|
+
*/
|
|
581
|
+
declare function hashUserId(rawPrincipal: string, options: {
|
|
582
|
+
tenantId: string;
|
|
583
|
+
key: Uint8Array | string;
|
|
584
|
+
issuer?: string | null | undefined;
|
|
585
|
+
/** ⚠ **REQUIRED, and deliberately NOT defaulted the way Python's is.**
|
|
586
|
+
* Python defaults to `HASH_SCHEME` (`h1:`), which is right there because
|
|
587
|
+
* that arm emits both provenances. This arm emits ONLY `v1:` — it has no
|
|
588
|
+
* attested rung — so an `h1:` default would hand the documented
|
|
589
|
+
* "recompute the pseudonym to join your own records against Console data"
|
|
590
|
+
* use a value matching nothing we ever wrote, forever, with an equality
|
|
591
|
+
* join silently returning zero rows. The hex halves are identical under
|
|
592
|
+
* both tags, so it fails in the most confusing way available. Naming the
|
|
593
|
+
* provenance is one word and removes the whole failure. */
|
|
594
|
+
scheme: string;
|
|
595
|
+
}): string;
|
|
596
|
+
|
|
597
|
+
/** `BatonConfig.resolveUser` — the ASSERTED identity provenance.
|
|
598
|
+
*
|
|
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.
|
|
603
|
+
*
|
|
604
|
+
* **Hook only — there is deliberately no attested (`h1:`) rung here yet.**
|
|
605
|
+
* Python reads `claims["sub"]` off a verified access token; TypeScript's
|
|
606
|
+
* `AuthInfo` has no `claims` field at all (it is
|
|
607
|
+
* `{token, clientId, scopes, expiresAt?, resource?, extra?}`), so the nearest
|
|
608
|
+
* carrier is the untyped `extra` bag and nothing specifies that `sub` lives
|
|
609
|
+
* there. Reading it would mean guessing where a subject lives, vendor by
|
|
610
|
+
* vendor — and a wrong guess is how two people end up as one actor. Recorded
|
|
611
|
+
* as a divergence rather than filled with a guess.
|
|
612
|
+
*/
|
|
613
|
+
|
|
614
|
+
/** What a vendor's `resolveUser` hook is handed.
|
|
615
|
+
*
|
|
616
|
+
* Adapter-neutral BY CONSTRUCTION rather than by convention — the peers' own
|
|
617
|
+
* handler-context objects differ in shape between the two majors, and this
|
|
618
|
+
* type is what makes one hook portable across them. The prior art takes the
|
|
619
|
+
* opposite approach: AgentCat's `identify()` receives the raw per-major object
|
|
620
|
+
* behind `{ sessionId?: string; [key: string]: any }`, documented as "only
|
|
621
|
+
* `sessionId` is common to both; everything else is SDK-version-specific".
|
|
622
|
+
* That is the divergence handed to the vendor as `any`; this is the divergence
|
|
623
|
+
* absorbed by us.
|
|
624
|
+
*/
|
|
625
|
+
interface UserResolutionContext {
|
|
626
|
+
/** The call's HTTP headers, case-insensitive on BOTH majors — see
|
|
627
|
+
* `extraHeaders` for the two shapes it reconciles.
|
|
628
|
+
*
|
|
629
|
+
* `null` means NO HTTP REQUEST (every stdio call, the common case), never
|
|
630
|
+
* "the client sent no headers". The distinction matters: the first is us
|
|
631
|
+
* telling you the question does not apply, the second would be a claim about
|
|
632
|
+
* the caller that we are not in a position to make. */
|
|
633
|
+
headers: Headers | null;
|
|
634
|
+
/** The call's `_meta`, from wherever this major keeps it. */
|
|
635
|
+
meta: Record<string, unknown> | null;
|
|
636
|
+
/** The tool being called — the annotation tool's own name on that path, so a
|
|
637
|
+
* hook can answer differently per call rather than per install. */
|
|
638
|
+
toolName: string;
|
|
639
|
+
/** The call's arguments, AFTER Baton's injected intent params are stripped,
|
|
640
|
+
* so a hook sees exactly what the vendor's own handler will. */
|
|
641
|
+
arguments: Record<string, unknown>;
|
|
642
|
+
}
|
|
643
|
+
/** A vendor's per-request identity resolver. Sync or async; returning `null`
|
|
644
|
+
* means "no opinion about this caller", which is not an error. */
|
|
645
|
+
type ResolveUserHook = (context: UserResolutionContext) => Principal | null | Promise<Principal | null>;
|
|
646
|
+
|
|
544
647
|
/**
|
|
545
648
|
* `BatonConfig` — vendor-side configuration for `withBaton`. A trimmed
|
|
546
649
|
* mirror of `baton` (Python)'s `integrations/_config.py::VendorConfig`.
|
|
@@ -594,10 +697,13 @@ interface BatonConfig {
|
|
|
594
697
|
* annotation tool description — whitelabel obligation (SPEC §5.4): no
|
|
595
698
|
* Baton-branded strings reach the calling agent.
|
|
596
699
|
*
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
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. */
|
|
601
707
|
vendorDisplayName?: string;
|
|
602
708
|
/** End-user consent token attached to every emitted event per SPEC §2.3 —
|
|
603
709
|
* the Console MUST reject events missing it.
|
|
@@ -625,8 +731,13 @@ interface BatonConfig {
|
|
|
625
731
|
* so untouched integrations get scrubbing without the operator opting in.
|
|
626
732
|
* Pass `identityScrub` to explicitly opt out, or supply your own. */
|
|
627
733
|
scrubber?: (value: unknown) => unknown;
|
|
628
|
-
/** Optional override for the annotation tool name
|
|
629
|
-
*
|
|
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. */
|
|
630
741
|
annotationToolName?: string;
|
|
631
742
|
/** Per-tool intent-param injection (mirrors baton-extmcp's vendor-neutral
|
|
632
743
|
* naming). `"optional"` (default) injects `user_goal`/`expected_result`
|
|
@@ -639,6 +750,38 @@ interface BatonConfig {
|
|
|
639
750
|
* nothing. A tool registered with no `inputSchema` at all is left alone
|
|
640
751
|
* regardless of this setting (see `schemaCompat.injectGoalParams`). */
|
|
641
752
|
intentParamMode?: "optional" | "required" | "off";
|
|
753
|
+
/** Per-request end-user identity — the ASSERTED provenance behind the
|
|
754
|
+
* envelope's `user_id` (SPEC §11.4 rung 0), tagged `v1:`.
|
|
755
|
+
*
|
|
756
|
+
* Called on every captured tool call and on the annotation tool, with an
|
|
757
|
+
* adapter-neutral {@link UserResolutionContext}: headers folded to ONE
|
|
758
|
+
* case-insensitive shape across both SDK majors, the call's `_meta`, the
|
|
759
|
+
* tool name, and the arguments the vendor's own handler will see. Return a
|
|
760
|
+
* `Principal`, or `null` for "no opinion about this caller".
|
|
761
|
+
*
|
|
762
|
+
* **This is the only identity mechanism on this arm.** MCP auth is HTTP
|
|
763
|
+
* middleware, so a stdio server has no token at all; and unlike Python, no
|
|
764
|
+
* attested rung is implemented here — see `userResolution.ts` for why
|
|
765
|
+
* (TypeScript's `AuthInfo` carries no `claims`).
|
|
766
|
+
*
|
|
767
|
+
* Never fails a tool call: a hook that throws or returns junk yields an
|
|
768
|
+
* anonymous call. ⚠ It is awaited INLINE with no timeout — a blocking hook
|
|
769
|
+
* stalls its own request. */
|
|
770
|
+
resolveUser?: ResolveUserHook;
|
|
771
|
+
/** `"hashed"` (default) emits a `v1:` per-tenant HMAC pseudonym; `"raw"`
|
|
772
|
+
* emits the subject VERBATIM.
|
|
773
|
+
*
|
|
774
|
+
* `"raw"` puts real end-user identity in the collector's database and is the
|
|
775
|
+
* vendor's deliberate choice — which is why SPEC §11.4 tells a consumer
|
|
776
|
+
* never to treat this field as anonymous. */
|
|
777
|
+
userIdMode?: "hashed" | "raw";
|
|
778
|
+
/** The HMAC secret for hashed mode. Resolved explicit →
|
|
779
|
+
* `BATON_USER_ID_HMAC_KEY` → unset.
|
|
780
|
+
*
|
|
781
|
+
* ⚠ **With none set, hashed mode DROPS `user_id` rather than falling back to
|
|
782
|
+
* raw.** The fallback would be a residency breach that looks like success:
|
|
783
|
+
* the field present, populated, and carrying the subject verbatim. */
|
|
784
|
+
userIdHmacKey?: string | Uint8Array;
|
|
642
785
|
}
|
|
643
786
|
|
|
644
787
|
/**
|
|
@@ -654,8 +797,9 @@ declare class BatonHandle {
|
|
|
654
797
|
* when no real per-call session id resolves. Not every event necessarily
|
|
655
798
|
* carries this id; see `withBaton`'s session-resolution order. */
|
|
656
799
|
readonly sessionId: string;
|
|
657
|
-
/** The resolved annotation tool name
|
|
658
|
-
*
|
|
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`. */
|
|
659
803
|
readonly annotationToolName: string;
|
|
660
804
|
constructor(options: {
|
|
661
805
|
sink: Sink;
|
|
@@ -762,4 +906,4 @@ interface SupportedMcpServer {
|
|
|
762
906
|
/** Install Baton into an `McpServer`. See module docstring for usage. */
|
|
763
907
|
declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
|
|
764
908
|
|
|
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 };
|
|
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 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 };
|