@goodtiming/baton-sdk 0.5.5 → 0.5.7

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.5.5";
3
+ declare const SDK_VERSION = "ts-0.5.7";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -101,7 +101,6 @@ declare const AnnotationPayloadSchema: z.ZodObject<{
101
101
  workflow: z.ZodDefault<z.ZodNullable<z.ZodString>>;
102
102
  suggested_improvement: z.ZodDefault<z.ZodNullable<z.ZodString>>;
103
103
  context: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
104
- intent_source: z.ZodDefault<z.ZodNullable<z.ZodString>>;
105
104
  tool_name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
106
105
  }, z.core.$strict>;
107
106
  type AnnotationPayload = z.infer<typeof AnnotationPayloadSchema>;
@@ -445,7 +444,6 @@ declare const AnnotationEventSchema: z.ZodObject<{
445
444
  workflow: z.ZodDefault<z.ZodNullable<z.ZodString>>;
446
445
  suggested_improvement: z.ZodDefault<z.ZodNullable<z.ZodString>>;
447
446
  context: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
448
- intent_source: z.ZodDefault<z.ZodNullable<z.ZodString>>;
449
447
  tool_name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
450
448
  }, z.core.$strict>;
451
449
  event_id: z.ZodDefault<z.ZodUUID>;
@@ -1199,7 +1197,6 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1199
1197
  workflow: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1200
1198
  suggested_improvement: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1201
1199
  context: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
1202
- intent_source: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1203
1200
  tool_name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1204
1201
  }, z.core.$strict>;
1205
1202
  event_id: z.ZodDefault<z.ZodUUID>;
@@ -2481,4 +2478,140 @@ declare function principalFromOAuthSub(context: PrincipalResolutionContext): Pri
2481
2478
  * good enough is the vendor's call. */
2482
2479
  declare function principalFromOAuthEmail(context: PrincipalResolutionContext): Principal | null;
2483
2480
 
2484
- export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type AuthInfo, type Baton, type BatonConfig, BatonHandle, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions, PRINCIPAL_FORM_HASHED, PRINCIPAL_FORM_RAW, PRINCIPAL_SOURCE_ASSERTED, type Principal, type PrincipalForm, type PrincipalResolutionContext, PrincipalWireSchema, type PromptGetEndEvent, PromptGetEndEventSchema, type PromptGetEndPayload, PromptGetEndPayloadSchema, type PromptGetErrorEvent, PromptGetErrorEventSchema, type PromptGetErrorPayload, PromptGetErrorPayloadSchema, type PromptGetStartEvent, PromptGetStartEventSchema, type PromptGetStartPayload, PromptGetStartPayloadSchema, type PromptListEndEvent, PromptListEndEventSchema, type PromptListEndPayload, PromptListEndPayloadSchema, type PromptListErrorEvent, PromptListErrorEventSchema, type PromptListErrorPayload, PromptListErrorPayloadSchema, type PromptListStartEvent, PromptListStartEventSchema, type PromptListStartPayload, PromptListStartPayloadSchema, type ResolvePrincipalHook, type ResourceListEndEvent, ResourceListEndEventSchema, type ResourceListEndPayload, ResourceListEndPayloadSchema, type ResourceListErrorEvent, ResourceListErrorEventSchema, type ResourceListErrorPayload, ResourceListErrorPayloadSchema, type ResourceListStartEvent, ResourceListStartEventSchema, type ResourceListStartPayload, ResourceListStartPayloadSchema, type ResourceReadEndEvent, ResourceReadEndEventSchema, type ResourceReadEndPayload, ResourceReadEndPayloadSchema, type ResourceReadErrorEvent, ResourceReadErrorEventSchema, type ResourceReadErrorPayload, ResourceReadErrorPayloadSchema, type ResourceReadStartEvent, ResourceReadStartEventSchema, type ResourceReadStartPayload, ResourceReadStartPayloadSchema, type ResultCaptureMode, SDK_VERSION, Scrubber, type Sink, StdoutSink, type StdoutSinkOptions, type SupportedMcpServer, type SurfaceSnapshotEvent, SurfaceSnapshotEventSchema, type SurfaceSnapshotPayload, SurfaceSnapshotPayloadSchema, type ToolCallEndEvent, ToolCallEndEventSchema, type ToolCallEndPayload, ToolCallEndPayloadSchema, type ToolCallErrorEvent, ToolCallErrorEventSchema, type ToolCallErrorPayload, ToolCallErrorPayloadSchema, type ToolCallStartEvent, ToolCallStartEventSchema, type ToolCallStartPayload, ToolCallStartPayloadSchema, type ToolListEndEvent, ToolListEndEventSchema, type ToolListEndPayload, ToolListEndPayloadSchema, type ToolListErrorEvent, ToolListErrorEventSchema, type ToolListErrorPayload, ToolListErrorPayloadSchema, type ToolListStartEvent, ToolListStartEventSchema, type ToolListStartPayload, ToolListStartPayloadSchema, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, safeWrite, withBaton };
2481
+ /** The envelope's `client_observed` (SPEC §11.4): what the client said about
2482
+ * itself, sent uninterpreted. The consumer names the client; this SDK does
2483
+ * not, and sends `agent_runtime: "unknown"` on every event. */
2484
+
2485
+ /** Headers as a vendor's server framework holds them: a fetch `Headers`, or a
2486
+ * plain record such as Node's `req.headers`. */
2487
+ type HeaderInput = Headers | Record<string, string | readonly string[] | undefined>;
2488
+
2489
+ /**
2490
+ * The library API (SPEC §5.6): `Client` for a vendor whose agents reach it
2491
+ * through something other than MCP — a REST API, a skill, or a tool loop in
2492
+ * the vendor's own agent. Twin of the Python SDK's `baton.Client`, with the
2493
+ * `with` blocks as callbacks:
2494
+ *
2495
+ * const client = new Client({ dsn: process.env.BATON_DSN });
2496
+ * app.use((req, res, next) =>
2497
+ * client.session({ sessionId: req.get("x-conversation-id") }, () =>
2498
+ * client.trace({ toolName: req.path, params: req.body }, () => next()),
2499
+ * ),
2500
+ * );
2501
+ *
2502
+ * Capture never throws into the vendor's code: a callback's own throw is
2503
+ * recorded and rethrown unchanged, and every failure of ours is logged and
2504
+ * dropped. Only a bad config throws, and only from the constructor.
2505
+ */
2506
+
2507
+ interface ClientOptions {
2508
+ /** The packed connection string from /account. Resolved explicit →
2509
+ * `BATON_DSN`; it builds the sink and supplies `vendorId` and `tenantId`. */
2510
+ dsn?: string;
2511
+ /** Required unless a `dsn` is given. */
2512
+ sink?: Sink;
2513
+ /** Explicit → `BATON_VENDOR_ID`. Required unless a `dsn` supplies it. */
2514
+ vendorId?: string;
2515
+ /** Explicit → `BATON_TENANT_ID` → `vendorId`. */
2516
+ tenantId?: string;
2517
+ /** Explicit → `BATON_CONSENT_TOKEN` → the SDK default. */
2518
+ consentToken?: string;
2519
+ /** Defaults to `new Scrubber().scrub`; pass `identityScrub` to opt out. */
2520
+ scrubber?: (value: unknown) => unknown;
2521
+ /** `"off"` sends no result: see `BatonConfig.resultCaptureMode`. */
2522
+ resultCaptureMode?: ResultCaptureMode;
2523
+ }
2524
+ interface SessionOptions {
2525
+ /** The vendor's own id for the conversation; without one, the block mints one. */
2526
+ sessionId?: string;
2527
+ /** Who the vendor says is calling. */
2528
+ principal?: Principal;
2529
+ /** What the calling client said about itself. */
2530
+ clientInfo?: {
2531
+ name?: string;
2532
+ version?: string;
2533
+ };
2534
+ /** The request's headers; only registered ones are kept. */
2535
+ headers?: HeaderInput;
2536
+ /** The vendor's own id for the user request these calls answer. Pass the
2537
+ * same value to every block that serves it, and those calls stay one turn. */
2538
+ turnId?: string;
2539
+ }
2540
+ interface TraceOptions {
2541
+ toolName: string;
2542
+ intent?: string;
2543
+ expectedOutcome?: string;
2544
+ workflow?: string;
2545
+ params?: Record<string, unknown>;
2546
+ consentToken?: string;
2547
+ }
2548
+ interface AnnotateOptions {
2549
+ whatHappened?: string;
2550
+ toolName?: string;
2551
+ intent?: string;
2552
+ expectedOutcome?: string;
2553
+ workflow?: string;
2554
+ suggestedImprovement?: string;
2555
+ context?: Record<string, unknown>;
2556
+ }
2557
+ interface ObservedError {
2558
+ /** `errorType` and `errorBody` are derived from it unless given. */
2559
+ error?: unknown;
2560
+ errorType?: string;
2561
+ errorBody?: string;
2562
+ }
2563
+ /** One traced call, handed to the `client.trace()` callback. */
2564
+ declare class Trace {
2565
+ #private;
2566
+ private constructor();
2567
+ /** The session this call's events carry. */
2568
+ get sessionId(): string;
2569
+ /** Record the outcome. Without a call, the callback's return value is the
2570
+ * result. `observed(undefined, { error })` records a failure the callback
2571
+ * caught and did not rethrow. The last call wins. */
2572
+ observed(result?: unknown, failure?: ObservedError): this;
2573
+ /** Report on this call, in its session. */
2574
+ annotate(options: AnnotateOptions): Promise<void>;
2575
+ }
2576
+ /** The library API's client. One per process. */
2577
+ declare class Client {
2578
+ #private;
2579
+ constructor(options?: ClientOptions);
2580
+ /** Run `fn` with one session, principal, client and turn for every
2581
+ * `trace()` and `annotate()` inside it, including after its awaits. Open
2582
+ * one per request or conversation. Returns what `fn` returns. */
2583
+ session<T>(options: SessionOptions, fn: () => T): T;
2584
+ /** Run `fn` as one traced tool call and return what it returns. When `fn`
2585
+ * returns a promise or other thenable, the call ends when it settles, and
2586
+ * what comes back is a new native Promise of the same value: `then` is
2587
+ * called exactly once, so a lazy query builder is not run twice. A throw or
2588
+ * rejection is recorded and passed on unchanged. */
2589
+ trace<T>(options: TraceOptions, fn: (trace: Trace) => T): T;
2590
+ /** `fn`, traced on every call. A single plain-object argument is sent as
2591
+ * `params`, as an MCP tool's arguments are; other arguments as
2592
+ * `{ args: [...] }`, unless `options.params` is given. */
2593
+ wrap<A extends unknown[], R>(options: string | TraceOptions, fn: (...args: A) => R): (...args: A) => R;
2594
+ /** Emit an annotation in the open `session()` block, or in a session of its
2595
+ * own outside one. To report on a traced call, use `trace.annotate()`. */
2596
+ annotate(options: AnnotateOptions & {
2597
+ consentToken?: string;
2598
+ }): Promise<void>;
2599
+ /** Wait until every event so far has reached the sink and the sink has flushed. */
2600
+ flush(): Promise<void>;
2601
+ /** Flush, then close the sink. Later events are dropped. */
2602
+ aclose(): Promise<void>;
2603
+ }
2604
+
2605
+ /** One injected param, for a vendor adding it to its own API (SPEC §5.6).
2606
+ * `description` is the text an agent reads on an MCP server, without the
2607
+ * leading "OPTIONAL." / "REQUIRED." label: whether the vendor's API requires
2608
+ * it is the vendor's call. `traceOption` is the `client.trace()` option the
2609
+ * agent's answer goes to. */
2610
+ interface IntentParam {
2611
+ readonly name: string;
2612
+ readonly description: string;
2613
+ readonly traceOption: "intent" | "expectedOutcome" | "workflow";
2614
+ }
2615
+ declare const INTENT_PARAMS: readonly IntentParam[];
2616
+
2617
+ export { type AnnotateOptions, type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type AuthInfo, type Baton, type BatonConfig, BatonHandle, Client, type ClientOptions, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, type HeaderInput, HttpSink, type HttpSinkOptions, INTENT_PARAMS, type IntentParam, type ObservedError, PRINCIPAL_FORM_HASHED, PRINCIPAL_FORM_RAW, PRINCIPAL_SOURCE_ASSERTED, type Principal, type PrincipalForm, type PrincipalResolutionContext, PrincipalWireSchema, type PromptGetEndEvent, PromptGetEndEventSchema, type PromptGetEndPayload, PromptGetEndPayloadSchema, type PromptGetErrorEvent, PromptGetErrorEventSchema, type PromptGetErrorPayload, PromptGetErrorPayloadSchema, type PromptGetStartEvent, PromptGetStartEventSchema, type PromptGetStartPayload, PromptGetStartPayloadSchema, type PromptListEndEvent, PromptListEndEventSchema, type PromptListEndPayload, PromptListEndPayloadSchema, type PromptListErrorEvent, PromptListErrorEventSchema, type PromptListErrorPayload, PromptListErrorPayloadSchema, type PromptListStartEvent, PromptListStartEventSchema, type PromptListStartPayload, PromptListStartPayloadSchema, type ResolvePrincipalHook, type ResourceListEndEvent, ResourceListEndEventSchema, type ResourceListEndPayload, ResourceListEndPayloadSchema, type ResourceListErrorEvent, ResourceListErrorEventSchema, type ResourceListErrorPayload, ResourceListErrorPayloadSchema, type ResourceListStartEvent, ResourceListStartEventSchema, type ResourceListStartPayload, ResourceListStartPayloadSchema, type ResourceReadEndEvent, ResourceReadEndEventSchema, type ResourceReadEndPayload, ResourceReadEndPayloadSchema, type ResourceReadErrorEvent, ResourceReadErrorEventSchema, type ResourceReadErrorPayload, ResourceReadErrorPayloadSchema, type ResourceReadStartEvent, ResourceReadStartEventSchema, type ResourceReadStartPayload, ResourceReadStartPayloadSchema, type ResultCaptureMode, SDK_VERSION, Scrubber, type SessionOptions, type Sink, StdoutSink, type StdoutSinkOptions, type SupportedMcpServer, type SurfaceSnapshotEvent, SurfaceSnapshotEventSchema, type SurfaceSnapshotPayload, SurfaceSnapshotPayloadSchema, type ToolCallEndEvent, ToolCallEndEventSchema, type ToolCallEndPayload, ToolCallEndPayloadSchema, type ToolCallErrorEvent, ToolCallErrorEventSchema, type ToolCallErrorPayload, ToolCallErrorPayloadSchema, type ToolCallStartEvent, ToolCallStartEventSchema, type ToolCallStartPayload, ToolCallStartPayloadSchema, type ToolListEndEvent, ToolListEndEventSchema, type ToolListEndPayload, ToolListEndPayloadSchema, type ToolListErrorEvent, ToolListErrorEventSchema, type ToolListErrorPayload, ToolListErrorPayloadSchema, type ToolListStartEvent, ToolListStartEventSchema, type ToolListStartPayload, ToolListStartPayloadSchema, Trace, type TraceOptions, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, safeWrite, withBaton };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
 
3
- declare const SDK_VERSION = "ts-0.5.5";
3
+ declare const SDK_VERSION = "ts-0.5.7";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -101,7 +101,6 @@ declare const AnnotationPayloadSchema: z.ZodObject<{
101
101
  workflow: z.ZodDefault<z.ZodNullable<z.ZodString>>;
102
102
  suggested_improvement: z.ZodDefault<z.ZodNullable<z.ZodString>>;
103
103
  context: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
104
- intent_source: z.ZodDefault<z.ZodNullable<z.ZodString>>;
105
104
  tool_name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
106
105
  }, z.core.$strict>;
107
106
  type AnnotationPayload = z.infer<typeof AnnotationPayloadSchema>;
@@ -445,7 +444,6 @@ declare const AnnotationEventSchema: z.ZodObject<{
445
444
  workflow: z.ZodDefault<z.ZodNullable<z.ZodString>>;
446
445
  suggested_improvement: z.ZodDefault<z.ZodNullable<z.ZodString>>;
447
446
  context: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
448
- intent_source: z.ZodDefault<z.ZodNullable<z.ZodString>>;
449
447
  tool_name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
450
448
  }, z.core.$strict>;
451
449
  event_id: z.ZodDefault<z.ZodUUID>;
@@ -1199,7 +1197,6 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1199
1197
  workflow: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1200
1198
  suggested_improvement: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1201
1199
  context: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
1202
- intent_source: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1203
1200
  tool_name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
1204
1201
  }, z.core.$strict>;
1205
1202
  event_id: z.ZodDefault<z.ZodUUID>;
@@ -2481,4 +2478,140 @@ declare function principalFromOAuthSub(context: PrincipalResolutionContext): Pri
2481
2478
  * good enough is the vendor's call. */
2482
2479
  declare function principalFromOAuthEmail(context: PrincipalResolutionContext): Principal | null;
2483
2480
 
2484
- export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type AuthInfo, type Baton, type BatonConfig, BatonHandle, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions, PRINCIPAL_FORM_HASHED, PRINCIPAL_FORM_RAW, PRINCIPAL_SOURCE_ASSERTED, type Principal, type PrincipalForm, type PrincipalResolutionContext, PrincipalWireSchema, type PromptGetEndEvent, PromptGetEndEventSchema, type PromptGetEndPayload, PromptGetEndPayloadSchema, type PromptGetErrorEvent, PromptGetErrorEventSchema, type PromptGetErrorPayload, PromptGetErrorPayloadSchema, type PromptGetStartEvent, PromptGetStartEventSchema, type PromptGetStartPayload, PromptGetStartPayloadSchema, type PromptListEndEvent, PromptListEndEventSchema, type PromptListEndPayload, PromptListEndPayloadSchema, type PromptListErrorEvent, PromptListErrorEventSchema, type PromptListErrorPayload, PromptListErrorPayloadSchema, type PromptListStartEvent, PromptListStartEventSchema, type PromptListStartPayload, PromptListStartPayloadSchema, type ResolvePrincipalHook, type ResourceListEndEvent, ResourceListEndEventSchema, type ResourceListEndPayload, ResourceListEndPayloadSchema, type ResourceListErrorEvent, ResourceListErrorEventSchema, type ResourceListErrorPayload, ResourceListErrorPayloadSchema, type ResourceListStartEvent, ResourceListStartEventSchema, type ResourceListStartPayload, ResourceListStartPayloadSchema, type ResourceReadEndEvent, ResourceReadEndEventSchema, type ResourceReadEndPayload, ResourceReadEndPayloadSchema, type ResourceReadErrorEvent, ResourceReadErrorEventSchema, type ResourceReadErrorPayload, ResourceReadErrorPayloadSchema, type ResourceReadStartEvent, ResourceReadStartEventSchema, type ResourceReadStartPayload, ResourceReadStartPayloadSchema, type ResultCaptureMode, SDK_VERSION, Scrubber, type Sink, StdoutSink, type StdoutSinkOptions, type SupportedMcpServer, type SurfaceSnapshotEvent, SurfaceSnapshotEventSchema, type SurfaceSnapshotPayload, SurfaceSnapshotPayloadSchema, type ToolCallEndEvent, ToolCallEndEventSchema, type ToolCallEndPayload, ToolCallEndPayloadSchema, type ToolCallErrorEvent, ToolCallErrorEventSchema, type ToolCallErrorPayload, ToolCallErrorPayloadSchema, type ToolCallStartEvent, ToolCallStartEventSchema, type ToolCallStartPayload, ToolCallStartPayloadSchema, type ToolListEndEvent, ToolListEndEventSchema, type ToolListEndPayload, ToolListEndPayloadSchema, type ToolListErrorEvent, ToolListErrorEventSchema, type ToolListErrorPayload, ToolListErrorPayloadSchema, type ToolListStartEvent, ToolListStartEventSchema, type ToolListStartPayload, ToolListStartPayloadSchema, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, safeWrite, withBaton };
2481
+ /** The envelope's `client_observed` (SPEC §11.4): what the client said about
2482
+ * itself, sent uninterpreted. The consumer names the client; this SDK does
2483
+ * not, and sends `agent_runtime: "unknown"` on every event. */
2484
+
2485
+ /** Headers as a vendor's server framework holds them: a fetch `Headers`, or a
2486
+ * plain record such as Node's `req.headers`. */
2487
+ type HeaderInput = Headers | Record<string, string | readonly string[] | undefined>;
2488
+
2489
+ /**
2490
+ * The library API (SPEC §5.6): `Client` for a vendor whose agents reach it
2491
+ * through something other than MCP — a REST API, a skill, or a tool loop in
2492
+ * the vendor's own agent. Twin of the Python SDK's `baton.Client`, with the
2493
+ * `with` blocks as callbacks:
2494
+ *
2495
+ * const client = new Client({ dsn: process.env.BATON_DSN });
2496
+ * app.use((req, res, next) =>
2497
+ * client.session({ sessionId: req.get("x-conversation-id") }, () =>
2498
+ * client.trace({ toolName: req.path, params: req.body }, () => next()),
2499
+ * ),
2500
+ * );
2501
+ *
2502
+ * Capture never throws into the vendor's code: a callback's own throw is
2503
+ * recorded and rethrown unchanged, and every failure of ours is logged and
2504
+ * dropped. Only a bad config throws, and only from the constructor.
2505
+ */
2506
+
2507
+ interface ClientOptions {
2508
+ /** The packed connection string from /account. Resolved explicit →
2509
+ * `BATON_DSN`; it builds the sink and supplies `vendorId` and `tenantId`. */
2510
+ dsn?: string;
2511
+ /** Required unless a `dsn` is given. */
2512
+ sink?: Sink;
2513
+ /** Explicit → `BATON_VENDOR_ID`. Required unless a `dsn` supplies it. */
2514
+ vendorId?: string;
2515
+ /** Explicit → `BATON_TENANT_ID` → `vendorId`. */
2516
+ tenantId?: string;
2517
+ /** Explicit → `BATON_CONSENT_TOKEN` → the SDK default. */
2518
+ consentToken?: string;
2519
+ /** Defaults to `new Scrubber().scrub`; pass `identityScrub` to opt out. */
2520
+ scrubber?: (value: unknown) => unknown;
2521
+ /** `"off"` sends no result: see `BatonConfig.resultCaptureMode`. */
2522
+ resultCaptureMode?: ResultCaptureMode;
2523
+ }
2524
+ interface SessionOptions {
2525
+ /** The vendor's own id for the conversation; without one, the block mints one. */
2526
+ sessionId?: string;
2527
+ /** Who the vendor says is calling. */
2528
+ principal?: Principal;
2529
+ /** What the calling client said about itself. */
2530
+ clientInfo?: {
2531
+ name?: string;
2532
+ version?: string;
2533
+ };
2534
+ /** The request's headers; only registered ones are kept. */
2535
+ headers?: HeaderInput;
2536
+ /** The vendor's own id for the user request these calls answer. Pass the
2537
+ * same value to every block that serves it, and those calls stay one turn. */
2538
+ turnId?: string;
2539
+ }
2540
+ interface TraceOptions {
2541
+ toolName: string;
2542
+ intent?: string;
2543
+ expectedOutcome?: string;
2544
+ workflow?: string;
2545
+ params?: Record<string, unknown>;
2546
+ consentToken?: string;
2547
+ }
2548
+ interface AnnotateOptions {
2549
+ whatHappened?: string;
2550
+ toolName?: string;
2551
+ intent?: string;
2552
+ expectedOutcome?: string;
2553
+ workflow?: string;
2554
+ suggestedImprovement?: string;
2555
+ context?: Record<string, unknown>;
2556
+ }
2557
+ interface ObservedError {
2558
+ /** `errorType` and `errorBody` are derived from it unless given. */
2559
+ error?: unknown;
2560
+ errorType?: string;
2561
+ errorBody?: string;
2562
+ }
2563
+ /** One traced call, handed to the `client.trace()` callback. */
2564
+ declare class Trace {
2565
+ #private;
2566
+ private constructor();
2567
+ /** The session this call's events carry. */
2568
+ get sessionId(): string;
2569
+ /** Record the outcome. Without a call, the callback's return value is the
2570
+ * result. `observed(undefined, { error })` records a failure the callback
2571
+ * caught and did not rethrow. The last call wins. */
2572
+ observed(result?: unknown, failure?: ObservedError): this;
2573
+ /** Report on this call, in its session. */
2574
+ annotate(options: AnnotateOptions): Promise<void>;
2575
+ }
2576
+ /** The library API's client. One per process. */
2577
+ declare class Client {
2578
+ #private;
2579
+ constructor(options?: ClientOptions);
2580
+ /** Run `fn` with one session, principal, client and turn for every
2581
+ * `trace()` and `annotate()` inside it, including after its awaits. Open
2582
+ * one per request or conversation. Returns what `fn` returns. */
2583
+ session<T>(options: SessionOptions, fn: () => T): T;
2584
+ /** Run `fn` as one traced tool call and return what it returns. When `fn`
2585
+ * returns a promise or other thenable, the call ends when it settles, and
2586
+ * what comes back is a new native Promise of the same value: `then` is
2587
+ * called exactly once, so a lazy query builder is not run twice. A throw or
2588
+ * rejection is recorded and passed on unchanged. */
2589
+ trace<T>(options: TraceOptions, fn: (trace: Trace) => T): T;
2590
+ /** `fn`, traced on every call. A single plain-object argument is sent as
2591
+ * `params`, as an MCP tool's arguments are; other arguments as
2592
+ * `{ args: [...] }`, unless `options.params` is given. */
2593
+ wrap<A extends unknown[], R>(options: string | TraceOptions, fn: (...args: A) => R): (...args: A) => R;
2594
+ /** Emit an annotation in the open `session()` block, or in a session of its
2595
+ * own outside one. To report on a traced call, use `trace.annotate()`. */
2596
+ annotate(options: AnnotateOptions & {
2597
+ consentToken?: string;
2598
+ }): Promise<void>;
2599
+ /** Wait until every event so far has reached the sink and the sink has flushed. */
2600
+ flush(): Promise<void>;
2601
+ /** Flush, then close the sink. Later events are dropped. */
2602
+ aclose(): Promise<void>;
2603
+ }
2604
+
2605
+ /** One injected param, for a vendor adding it to its own API (SPEC §5.6).
2606
+ * `description` is the text an agent reads on an MCP server, without the
2607
+ * leading "OPTIONAL." / "REQUIRED." label: whether the vendor's API requires
2608
+ * it is the vendor's call. `traceOption` is the `client.trace()` option the
2609
+ * agent's answer goes to. */
2610
+ interface IntentParam {
2611
+ readonly name: string;
2612
+ readonly description: string;
2613
+ readonly traceOption: "intent" | "expectedOutcome" | "workflow";
2614
+ }
2615
+ declare const INTENT_PARAMS: readonly IntentParam[];
2616
+
2617
+ export { type AnnotateOptions, type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type AuthInfo, type Baton, type BatonConfig, BatonHandle, Client, type ClientOptions, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, type HeaderInput, HttpSink, type HttpSinkOptions, INTENT_PARAMS, type IntentParam, type ObservedError, PRINCIPAL_FORM_HASHED, PRINCIPAL_FORM_RAW, PRINCIPAL_SOURCE_ASSERTED, type Principal, type PrincipalForm, type PrincipalResolutionContext, PrincipalWireSchema, type PromptGetEndEvent, PromptGetEndEventSchema, type PromptGetEndPayload, PromptGetEndPayloadSchema, type PromptGetErrorEvent, PromptGetErrorEventSchema, type PromptGetErrorPayload, PromptGetErrorPayloadSchema, type PromptGetStartEvent, PromptGetStartEventSchema, type PromptGetStartPayload, PromptGetStartPayloadSchema, type PromptListEndEvent, PromptListEndEventSchema, type PromptListEndPayload, PromptListEndPayloadSchema, type PromptListErrorEvent, PromptListErrorEventSchema, type PromptListErrorPayload, PromptListErrorPayloadSchema, type PromptListStartEvent, PromptListStartEventSchema, type PromptListStartPayload, PromptListStartPayloadSchema, type ResolvePrincipalHook, type ResourceListEndEvent, ResourceListEndEventSchema, type ResourceListEndPayload, ResourceListEndPayloadSchema, type ResourceListErrorEvent, ResourceListErrorEventSchema, type ResourceListErrorPayload, ResourceListErrorPayloadSchema, type ResourceListStartEvent, ResourceListStartEventSchema, type ResourceListStartPayload, ResourceListStartPayloadSchema, type ResourceReadEndEvent, ResourceReadEndEventSchema, type ResourceReadEndPayload, ResourceReadEndPayloadSchema, type ResourceReadErrorEvent, ResourceReadErrorEventSchema, type ResourceReadErrorPayload, ResourceReadErrorPayloadSchema, type ResourceReadStartEvent, ResourceReadStartEventSchema, type ResourceReadStartPayload, ResourceReadStartPayloadSchema, type ResultCaptureMode, SDK_VERSION, Scrubber, type SessionOptions, type Sink, StdoutSink, type StdoutSinkOptions, type SupportedMcpServer, type SurfaceSnapshotEvent, SurfaceSnapshotEventSchema, type SurfaceSnapshotPayload, SurfaceSnapshotPayloadSchema, type ToolCallEndEvent, ToolCallEndEventSchema, type ToolCallEndPayload, ToolCallEndPayloadSchema, type ToolCallErrorEvent, ToolCallErrorEventSchema, type ToolCallErrorPayload, ToolCallErrorPayloadSchema, type ToolCallStartEvent, ToolCallStartEventSchema, type ToolCallStartPayload, ToolCallStartPayloadSchema, type ToolListEndEvent, ToolListEndEventSchema, type ToolListEndPayload, ToolListEndPayloadSchema, type ToolListErrorEvent, ToolListErrorEventSchema, type ToolListErrorPayload, ToolListErrorPayloadSchema, type ToolListStartEvent, ToolListStartEventSchema, type ToolListStartPayload, ToolListStartPayloadSchema, Trace, type TraceOptions, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, safeWrite, withBaton };