@goodtiming/baton-sdk 0.3.1 → 0.3.3
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.cjs +299 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +146 -15
- package/dist/index.d.ts +146 -15
- package/dist/index.js +295 -51
- 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.3";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -124,6 +124,7 @@ declare const ToolCallStartEventSchema: z.ZodObject<{
|
|
|
124
124
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
125
125
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
126
126
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
127
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
127
128
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
128
129
|
}, z.core.$strict>;
|
|
129
130
|
type ToolCallStartEvent = z.infer<typeof ToolCallStartEventSchema>;
|
|
@@ -144,6 +145,7 @@ declare const ToolCallEndEventSchema: z.ZodObject<{
|
|
|
144
145
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
145
146
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
146
147
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
148
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
147
149
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
148
150
|
}, z.core.$strict>;
|
|
149
151
|
type ToolCallEndEvent = z.infer<typeof ToolCallEndEventSchema>;
|
|
@@ -165,6 +167,7 @@ declare const ToolCallErrorEventSchema: z.ZodObject<{
|
|
|
165
167
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
166
168
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
167
169
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
170
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
168
171
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
169
172
|
}, z.core.$strict>;
|
|
170
173
|
type ToolCallErrorEvent = z.infer<typeof ToolCallErrorEventSchema>;
|
|
@@ -190,6 +193,7 @@ declare const AnnotationEventSchema: z.ZodObject<{
|
|
|
190
193
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
191
194
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
192
195
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
196
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
193
197
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
194
198
|
}, z.core.$strict>;
|
|
195
199
|
type AnnotationEvent = z.infer<typeof AnnotationEventSchema>;
|
|
@@ -213,6 +217,7 @@ declare const SurfaceSnapshotEventSchema: z.ZodObject<{
|
|
|
213
217
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
214
218
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
215
219
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
220
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
216
221
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
217
222
|
}, z.core.$strict>;
|
|
218
223
|
type SurfaceSnapshotEvent = z.infer<typeof SurfaceSnapshotEventSchema>;
|
|
@@ -236,6 +241,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
236
241
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
237
242
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
238
243
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
244
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
239
245
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
240
246
|
}, z.core.$strict>, z.ZodObject<{
|
|
241
247
|
event_type: z.ZodDefault<z.ZodLiteral<"tool_call_end">>;
|
|
@@ -254,6 +260,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
254
260
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
255
261
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
256
262
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
263
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
257
264
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
258
265
|
}, z.core.$strict>, z.ZodObject<{
|
|
259
266
|
event_type: z.ZodDefault<z.ZodLiteral<"tool_call_error">>;
|
|
@@ -273,6 +280,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
273
280
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
274
281
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
275
282
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
283
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
276
284
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
277
285
|
}, z.core.$strict>, z.ZodObject<{
|
|
278
286
|
event_type: z.ZodDefault<z.ZodLiteral<"annotation">>;
|
|
@@ -296,6 +304,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
296
304
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
297
305
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
298
306
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
307
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
299
308
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
300
309
|
}, z.core.$strict>, z.ZodObject<{
|
|
301
310
|
event_type: z.ZodDefault<z.ZodLiteral<"surface_snapshot">>;
|
|
@@ -317,6 +326,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
317
326
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
318
327
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
319
328
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
329
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
320
330
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
321
331
|
}, z.core.$strict>], "event_type">;
|
|
322
332
|
type Event = ToolCallStartEvent | ToolCallEndEvent | ToolCallErrorEvent | AnnotationEvent | SurfaceSnapshotEvent;
|
|
@@ -531,20 +541,114 @@ declare class HttpSink implements Sink {
|
|
|
531
541
|
private sendWithRetry;
|
|
532
542
|
}
|
|
533
543
|
|
|
534
|
-
/**
|
|
535
|
-
*
|
|
536
|
-
*
|
|
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.
|
|
537
612
|
*/
|
|
538
613
|
|
|
539
|
-
/**
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
|
|
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. */
|
|
543
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. */
|
|
544
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. */
|
|
545
641
|
arguments: Record<string, unknown>;
|
|
546
642
|
}
|
|
547
|
-
|
|
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
|
+
|
|
647
|
+
/**
|
|
648
|
+
* `BatonConfig` — vendor-side configuration for `withBaton`. A trimmed
|
|
649
|
+
* mirror of `baton` (Python)'s `integrations/_config.py::VendorConfig`.
|
|
650
|
+
*/
|
|
651
|
+
|
|
548
652
|
interface BatonConfig {
|
|
549
653
|
/** The packed connection string from /account — one value carrying the
|
|
550
654
|
* ingest host, the workspace, the server and the key that binds them.
|
|
@@ -616,8 +720,6 @@ interface BatonConfig {
|
|
|
616
720
|
consentToken?: string;
|
|
617
721
|
/** Where events go. Defaults to `new StdoutSink()` — zero-config dev mode. */
|
|
618
722
|
sink?: Sink;
|
|
619
|
-
/** Default `agent_runtime` when `_meta` heuristics can't detect one. */
|
|
620
|
-
defaultAgentRuntime?: string;
|
|
621
723
|
/** PII scrubber per SPEC §7, applied to tool params/results, `_meta`,
|
|
622
724
|
* intent strings and error bodies before they reach the sink. Defaults to
|
|
623
725
|
* the shipped default ruleset (`new Scrubber().scrub` — email, bearer,
|
|
@@ -626,9 +728,6 @@ interface BatonConfig {
|
|
|
626
728
|
* so untouched integrations get scrubbing without the operator opting in.
|
|
627
729
|
* Pass `identityScrub` to explicitly opt out, or supply your own. */
|
|
628
730
|
scrubber?: (value: unknown) => unknown;
|
|
629
|
-
/** Optional vendor-supplied session-id resolver, checked BEFORE
|
|
630
|
-
* `extra.sessionId` — mirrors Python's `resolve_session_id` rung 0. */
|
|
631
|
-
resolveSessionId?: ResolveSessionIdHook;
|
|
632
731
|
/** Optional override for the annotation tool name. Default is
|
|
633
732
|
* `{vendorId}_annotate`. */
|
|
634
733
|
annotationToolName?: string;
|
|
@@ -643,6 +742,38 @@ interface BatonConfig {
|
|
|
643
742
|
* nothing. A tool registered with no `inputSchema` at all is left alone
|
|
644
743
|
* regardless of this setting (see `schemaCompat.injectGoalParams`). */
|
|
645
744
|
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:`.
|
|
747
|
+
*
|
|
748
|
+
* Called on every captured tool call and on the annotation tool, with an
|
|
749
|
+
* adapter-neutral {@link UserResolutionContext}: headers folded to ONE
|
|
750
|
+
* case-insensitive shape across both SDK majors, the call's `_meta`, the
|
|
751
|
+
* tool name, and the arguments the vendor's own handler will see. Return a
|
|
752
|
+
* `Principal`, or `null` for "no opinion about this caller".
|
|
753
|
+
*
|
|
754
|
+
* **This is the only identity mechanism on this arm.** MCP auth is HTTP
|
|
755
|
+
* 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
|
|
757
|
+
* (TypeScript's `AuthInfo` carries no `claims`).
|
|
758
|
+
*
|
|
759
|
+
* Never fails a tool call: a hook that throws or returns junk yields an
|
|
760
|
+
* anonymous call. ⚠ It is awaited INLINE with no timeout — a blocking hook
|
|
761
|
+
* stalls its own request. */
|
|
762
|
+
resolveUser?: ResolveUserHook;
|
|
763
|
+
/** `"hashed"` (default) emits a `v1:` per-tenant HMAC pseudonym; `"raw"`
|
|
764
|
+
* emits the subject VERBATIM.
|
|
765
|
+
*
|
|
766
|
+
* `"raw"` puts real end-user identity in the collector's database and is the
|
|
767
|
+
* vendor's deliberate choice — which is why SPEC §11.4 tells a consumer
|
|
768
|
+
* never to treat this field as anonymous. */
|
|
769
|
+
userIdMode?: "hashed" | "raw";
|
|
770
|
+
/** The HMAC secret for hashed mode. Resolved explicit →
|
|
771
|
+
* `BATON_USER_ID_HMAC_KEY` → unset.
|
|
772
|
+
*
|
|
773
|
+
* ⚠ **With none set, hashed mode DROPS `user_id` rather than falling back to
|
|
774
|
+
* raw.** The fallback would be a residency breach that looks like success:
|
|
775
|
+
* the field present, populated, and carrying the subject verbatim. */
|
|
776
|
+
userIdHmacKey?: string | Uint8Array;
|
|
646
777
|
}
|
|
647
778
|
|
|
648
779
|
/**
|
|
@@ -766,4 +897,4 @@ interface SupportedMcpServer {
|
|
|
766
897
|
/** Install Baton into an `McpServer`. See module docstring for usage. */
|
|
767
898
|
declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
|
|
768
899
|
|
|
769
|
-
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
|
|
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 };
|
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.3";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -124,6 +124,7 @@ declare const ToolCallStartEventSchema: z.ZodObject<{
|
|
|
124
124
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
125
125
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
126
126
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
127
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
127
128
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
128
129
|
}, z.core.$strict>;
|
|
129
130
|
type ToolCallStartEvent = z.infer<typeof ToolCallStartEventSchema>;
|
|
@@ -144,6 +145,7 @@ declare const ToolCallEndEventSchema: z.ZodObject<{
|
|
|
144
145
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
145
146
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
146
147
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
148
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
147
149
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
148
150
|
}, z.core.$strict>;
|
|
149
151
|
type ToolCallEndEvent = z.infer<typeof ToolCallEndEventSchema>;
|
|
@@ -165,6 +167,7 @@ declare const ToolCallErrorEventSchema: z.ZodObject<{
|
|
|
165
167
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
166
168
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
167
169
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
170
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
168
171
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
169
172
|
}, z.core.$strict>;
|
|
170
173
|
type ToolCallErrorEvent = z.infer<typeof ToolCallErrorEventSchema>;
|
|
@@ -190,6 +193,7 @@ declare const AnnotationEventSchema: z.ZodObject<{
|
|
|
190
193
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
191
194
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
192
195
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
196
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
193
197
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
194
198
|
}, z.core.$strict>;
|
|
195
199
|
type AnnotationEvent = z.infer<typeof AnnotationEventSchema>;
|
|
@@ -213,6 +217,7 @@ declare const SurfaceSnapshotEventSchema: z.ZodObject<{
|
|
|
213
217
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
214
218
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
215
219
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
220
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
216
221
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
217
222
|
}, z.core.$strict>;
|
|
218
223
|
type SurfaceSnapshotEvent = z.infer<typeof SurfaceSnapshotEventSchema>;
|
|
@@ -236,6 +241,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
236
241
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
237
242
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
238
243
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
244
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
239
245
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
240
246
|
}, z.core.$strict>, z.ZodObject<{
|
|
241
247
|
event_type: z.ZodDefault<z.ZodLiteral<"tool_call_end">>;
|
|
@@ -254,6 +260,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
254
260
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
255
261
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
256
262
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
263
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
257
264
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
258
265
|
}, z.core.$strict>, z.ZodObject<{
|
|
259
266
|
event_type: z.ZodDefault<z.ZodLiteral<"tool_call_error">>;
|
|
@@ -273,6 +280,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
273
280
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
274
281
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
275
282
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
283
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
276
284
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
277
285
|
}, z.core.$strict>, z.ZodObject<{
|
|
278
286
|
event_type: z.ZodDefault<z.ZodLiteral<"annotation">>;
|
|
@@ -296,6 +304,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
296
304
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
297
305
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
298
306
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
307
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
299
308
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
300
309
|
}, z.core.$strict>, z.ZodObject<{
|
|
301
310
|
event_type: z.ZodDefault<z.ZodLiteral<"surface_snapshot">>;
|
|
@@ -317,6 +326,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
317
326
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
318
327
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
319
328
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
329
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
320
330
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
321
331
|
}, z.core.$strict>], "event_type">;
|
|
322
332
|
type Event = ToolCallStartEvent | ToolCallEndEvent | ToolCallErrorEvent | AnnotationEvent | SurfaceSnapshotEvent;
|
|
@@ -531,20 +541,114 @@ declare class HttpSink implements Sink {
|
|
|
531
541
|
private sendWithRetry;
|
|
532
542
|
}
|
|
533
543
|
|
|
534
|
-
/**
|
|
535
|
-
*
|
|
536
|
-
*
|
|
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.
|
|
537
612
|
*/
|
|
538
613
|
|
|
539
|
-
/**
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
|
|
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. */
|
|
543
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. */
|
|
544
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. */
|
|
545
641
|
arguments: Record<string, unknown>;
|
|
546
642
|
}
|
|
547
|
-
|
|
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
|
+
|
|
647
|
+
/**
|
|
648
|
+
* `BatonConfig` — vendor-side configuration for `withBaton`. A trimmed
|
|
649
|
+
* mirror of `baton` (Python)'s `integrations/_config.py::VendorConfig`.
|
|
650
|
+
*/
|
|
651
|
+
|
|
548
652
|
interface BatonConfig {
|
|
549
653
|
/** The packed connection string from /account — one value carrying the
|
|
550
654
|
* ingest host, the workspace, the server and the key that binds them.
|
|
@@ -616,8 +720,6 @@ interface BatonConfig {
|
|
|
616
720
|
consentToken?: string;
|
|
617
721
|
/** Where events go. Defaults to `new StdoutSink()` — zero-config dev mode. */
|
|
618
722
|
sink?: Sink;
|
|
619
|
-
/** Default `agent_runtime` when `_meta` heuristics can't detect one. */
|
|
620
|
-
defaultAgentRuntime?: string;
|
|
621
723
|
/** PII scrubber per SPEC §7, applied to tool params/results, `_meta`,
|
|
622
724
|
* intent strings and error bodies before they reach the sink. Defaults to
|
|
623
725
|
* the shipped default ruleset (`new Scrubber().scrub` — email, bearer,
|
|
@@ -626,9 +728,6 @@ interface BatonConfig {
|
|
|
626
728
|
* so untouched integrations get scrubbing without the operator opting in.
|
|
627
729
|
* Pass `identityScrub` to explicitly opt out, or supply your own. */
|
|
628
730
|
scrubber?: (value: unknown) => unknown;
|
|
629
|
-
/** Optional vendor-supplied session-id resolver, checked BEFORE
|
|
630
|
-
* `extra.sessionId` — mirrors Python's `resolve_session_id` rung 0. */
|
|
631
|
-
resolveSessionId?: ResolveSessionIdHook;
|
|
632
731
|
/** Optional override for the annotation tool name. Default is
|
|
633
732
|
* `{vendorId}_annotate`. */
|
|
634
733
|
annotationToolName?: string;
|
|
@@ -643,6 +742,38 @@ interface BatonConfig {
|
|
|
643
742
|
* nothing. A tool registered with no `inputSchema` at all is left alone
|
|
644
743
|
* regardless of this setting (see `schemaCompat.injectGoalParams`). */
|
|
645
744
|
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:`.
|
|
747
|
+
*
|
|
748
|
+
* Called on every captured tool call and on the annotation tool, with an
|
|
749
|
+
* adapter-neutral {@link UserResolutionContext}: headers folded to ONE
|
|
750
|
+
* case-insensitive shape across both SDK majors, the call's `_meta`, the
|
|
751
|
+
* tool name, and the arguments the vendor's own handler will see. Return a
|
|
752
|
+
* `Principal`, or `null` for "no opinion about this caller".
|
|
753
|
+
*
|
|
754
|
+
* **This is the only identity mechanism on this arm.** MCP auth is HTTP
|
|
755
|
+
* 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
|
|
757
|
+
* (TypeScript's `AuthInfo` carries no `claims`).
|
|
758
|
+
*
|
|
759
|
+
* Never fails a tool call: a hook that throws or returns junk yields an
|
|
760
|
+
* anonymous call. ⚠ It is awaited INLINE with no timeout — a blocking hook
|
|
761
|
+
* stalls its own request. */
|
|
762
|
+
resolveUser?: ResolveUserHook;
|
|
763
|
+
/** `"hashed"` (default) emits a `v1:` per-tenant HMAC pseudonym; `"raw"`
|
|
764
|
+
* emits the subject VERBATIM.
|
|
765
|
+
*
|
|
766
|
+
* `"raw"` puts real end-user identity in the collector's database and is the
|
|
767
|
+
* vendor's deliberate choice — which is why SPEC §11.4 tells a consumer
|
|
768
|
+
* never to treat this field as anonymous. */
|
|
769
|
+
userIdMode?: "hashed" | "raw";
|
|
770
|
+
/** The HMAC secret for hashed mode. Resolved explicit →
|
|
771
|
+
* `BATON_USER_ID_HMAC_KEY` → unset.
|
|
772
|
+
*
|
|
773
|
+
* ⚠ **With none set, hashed mode DROPS `user_id` rather than falling back to
|
|
774
|
+
* raw.** The fallback would be a residency breach that looks like success:
|
|
775
|
+
* the field present, populated, and carrying the subject verbatim. */
|
|
776
|
+
userIdHmacKey?: string | Uint8Array;
|
|
646
777
|
}
|
|
647
778
|
|
|
648
779
|
/**
|
|
@@ -766,4 +897,4 @@ interface SupportedMcpServer {
|
|
|
766
897
|
/** Install Baton into an `McpServer`. See module docstring for usage. */
|
|
767
898
|
declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
|
|
768
899
|
|
|
769
|
-
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
|
|
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 };
|