@goodtiming/baton-sdk 0.5.6 → 0.5.8

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.6";
3
+ declare const SDK_VERSION = "ts-0.5.8";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -20,10 +20,11 @@ declare const SDK_VERSION = "ts-0.5.6";
20
20
  /** Emitted before the vendor handler runs. `params` is PII-scrubbed at
21
21
  * emit-time per SPEC §7.
22
22
  *
23
- * `call_intent` / `call_expected` / `call_workflow` are the values the SDK
24
- * stripped from the injected `user_goal` / `expected_result` /
25
- * `overall_task` params (see `llmText.ts`); they ride as SIBLINGS of
26
- * `params` — `params` stays exactly the vendor-visible arguments.
23
+ * `call_intent` is the value the SDK stripped from the injected `user_goal`
24
+ * param, and `call_expected` / `call_workflow` the retired `expected_result` /
25
+ * `overall_task` a stale client may still send (see `llmText.ts`); they ride
26
+ * as SIBLINGS of `params` — `params` stays exactly the vendor-visible
27
+ * arguments.
27
28
  * `call_intent`/`call_expected` are call-scoped diagnostics;
28
29
  * `call_workflow` is the task-label grouping key (console rung 3b, exact
29
30
  * string continuity). `intent_source` records provenance
@@ -2188,7 +2189,8 @@ interface BatonConfig {
2188
2189
  * for the same reason: a capitalisation you never chose would be a
2189
2190
  * fabricated name. Falls back to the DSN's server segment when the server's
2190
2191
  * name is one a library made up, is blank or unreadable, or would push the
2191
- * server instructions over their cap. With no `dsn`, this is required. */
2192
+ * server instructions over their cap. With no `dsn`, this is required
2193
+ * under `reportMode: "on"`, and unused otherwise. */
2192
2194
  vendorDisplayName?: string;
2193
2195
  /** End-user consent token attached to every emitted event per SPEC §2.3 —
2194
2196
  * the Console MUST reject events missing it.
@@ -2222,21 +2224,29 @@ interface BatonConfig {
2222
2224
  * `acme-knowledge-base_annotate`. It falls back to `{vendorId}_annotate`
2223
2225
  * when the name is one a library made up, slugs to nothing, is unreadable,
2224
2226
  * or would not fit the server instructions. Set this to keep a name you have
2225
- * written into documentation, a prompt or a script. */
2227
+ * written into documentation, a prompt or a script. Has no effect unless
2228
+ * `reportMode: "on"`, and warns if set without it. */
2226
2229
  annotationToolName?: string;
2230
+ /** Whether the agent is given a tool to report a call that went wrong.
2231
+ * `"off"` (the default) registers no annotation tool, and Baton's server
2232
+ * instructions are `INTENT_INSTRUCTIONS` alone, below your own. Each call's
2233
+ * goal still arrives through `user_goal`. `"on"` registers the tool and
2234
+ * serves its instructions. */
2235
+ reportMode?: "on" | "off";
2227
2236
  /** Per-tool intent-param injection (mirrors baton-extmcp's vendor-neutral
2228
- * naming). `"required"` (default) injects `user_goal`/`expected_result`/
2229
- * `overall_task` string params on every wrapped tool's advertised schema
2230
- * and ADVERTISES all three as required in
2231
- * `tools/list`, without enforcing them: a call that omits them still reaches
2237
+ * naming). `"required"` (default) injects a `user_goal` string param on
2238
+ * every wrapped tool's advertised schema and ADVERTISES it as required in
2239
+ * `tools/list`, without enforcing it: a call that omits it still reaches
2232
2240
  * your handler, and its event simply carries no intent. `"optional"` injects
2233
- * the same params and advertises none of them as required. `"off"` disables injection. The params are
2234
- * stripped before the vendor handler runs, so the tool never sees them.
2241
+ * the same param and does not advertise it as required. There is no
2242
+ * `"off"`: this SDK has no proactive reports, so nothing else would capture
2243
+ * what the user is trying to do. The param is stripped before the vendor
2244
+ * handler runs, so the tool never sees it.
2235
2245
  * This is what captures intent on runtimes that drop `instructions`
2236
2246
  * (notably Claude Desktop) — where the annotation tool alone yields
2237
2247
  * nothing. A tool registered with no `inputSchema` at all is left alone
2238
2248
  * regardless of this setting (see `schemaCompat.injectGoalParams`). */
2239
- intentParamMode?: "optional" | "required" | "off";
2249
+ intentParamMode?: "optional" | "required";
2240
2250
  /** Whether tool RESPONSE data is captured at all (SPEC §11.4).
2241
2251
  *
2242
2252
  * `"full"` (the default) captures as it always has. `"off"` means nothing
@@ -2353,10 +2363,9 @@ declare class BatonHandle {
2353
2363
  * MCP's error flag on a 200. Reading only the first is what this package did,
2354
2364
  * and what §6.1's own wording told it to. Injects server `instructions`
2355
2365
  * (SPEC §5.1.2), registers
2356
- * the `<vendor>_annotate` tool (SPEC §5.1.1), injects `user_goal`/
2357
- * `expected_result`/`overall_task` intent params on every wrapped tool's
2358
- * schema (SPEC §11.4.1 `call_intent`/`call_expected`/`call_workflow`/
2359
- * `intent_source`), and captures a `surface_snapshot`
2366
+ * the `<vendor>_annotate` tool under `reportMode: "on"` (SPEC §5.1.1), injects
2367
+ * a `user_goal` intent param on every wrapped tool's schema (SPEC §11.4.1
2368
+ * `call_intent`/`intent_source`), and captures a `surface_snapshot`
2360
2369
  * of the vendor-true surface. Every payload leaving here runs through the
2361
2370
  * configured scrubber, which defaults to the shipped ruleset (`src/scrub.ts`)
2362
2371
  * — see README "What is not here yet" for what's still not here (the low-level
@@ -2478,4 +2487,144 @@ declare function principalFromOAuthSub(context: PrincipalResolutionContext): Pri
2478
2487
  * good enough is the vendor's call. */
2479
2488
  declare function principalFromOAuthEmail(context: PrincipalResolutionContext): Principal | null;
2480
2489
 
2481
- 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 };
2490
+ /** The envelope's `client_observed` (SPEC §11.4): what the client said about
2491
+ * itself, sent uninterpreted. The consumer names the client; this SDK does
2492
+ * not, and sends `agent_runtime: "unknown"` on every event. */
2493
+
2494
+ /** Headers as a vendor's server framework holds them: a fetch `Headers`, or a
2495
+ * plain record such as Node's `req.headers`. */
2496
+ type HeaderInput = Headers | Record<string, string | readonly string[] | undefined>;
2497
+
2498
+ /**
2499
+ * The library API (SPEC §5.6): `Client` for a vendor whose agents reach it
2500
+ * through something other than MCP — a REST API, a skill, or a tool loop in
2501
+ * the vendor's own agent. Twin of the Python SDK's `baton.Client`, with the
2502
+ * `with` blocks as callbacks:
2503
+ *
2504
+ * const client = new Client({ dsn: process.env.BATON_DSN });
2505
+ * app.use((req, res, next) =>
2506
+ * client.session({ sessionId: req.get("x-conversation-id") }, () =>
2507
+ * client.trace({ toolName: req.path, params: req.body }, () => next()),
2508
+ * ),
2509
+ * );
2510
+ *
2511
+ * Capture never throws into the vendor's code: a callback's own throw is
2512
+ * recorded and rethrown unchanged, and every failure of ours is logged and
2513
+ * dropped. Only a bad config throws, and only from the constructor.
2514
+ */
2515
+
2516
+ interface ClientOptions {
2517
+ /** The packed connection string from /account. Resolved explicit →
2518
+ * `BATON_DSN`; it builds the sink and supplies `vendorId` and `tenantId`. */
2519
+ dsn?: string;
2520
+ /** Required unless a `dsn` is given. */
2521
+ sink?: Sink;
2522
+ /** Explicit → `BATON_VENDOR_ID`. Required unless a `dsn` supplies it. */
2523
+ vendorId?: string;
2524
+ /** Explicit → `BATON_TENANT_ID` → `vendorId`. */
2525
+ tenantId?: string;
2526
+ /** Explicit → `BATON_CONSENT_TOKEN` → the SDK default. */
2527
+ consentToken?: string;
2528
+ /** Defaults to `new Scrubber().scrub`; pass `identityScrub` to opt out. */
2529
+ scrubber?: (value: unknown) => unknown;
2530
+ /** `"off"` sends no result: see `BatonConfig.resultCaptureMode`. */
2531
+ resultCaptureMode?: ResultCaptureMode;
2532
+ }
2533
+ interface SessionOptions {
2534
+ /** The vendor's own id for the conversation; without one, the block mints one. */
2535
+ sessionId?: string;
2536
+ /** Who the vendor says is calling. */
2537
+ principal?: Principal;
2538
+ /** What the calling client said about itself. */
2539
+ clientInfo?: {
2540
+ name?: string;
2541
+ version?: string;
2542
+ };
2543
+ /** The request's headers; only registered ones are kept. */
2544
+ headers?: HeaderInput;
2545
+ /** The vendor's own id for the user request these calls answer. Pass the
2546
+ * same value to every block that serves it, and those calls stay one turn. */
2547
+ turnId?: string;
2548
+ }
2549
+ interface TraceOptions {
2550
+ toolName: string;
2551
+ intent?: string;
2552
+ expectedOutcome?: string;
2553
+ workflow?: string;
2554
+ params?: Record<string, unknown>;
2555
+ consentToken?: string;
2556
+ }
2557
+ interface AnnotateOptions {
2558
+ whatHappened?: string;
2559
+ toolName?: string;
2560
+ intent?: string;
2561
+ expectedOutcome?: string;
2562
+ workflow?: string;
2563
+ suggestedImprovement?: string;
2564
+ context?: Record<string, unknown>;
2565
+ }
2566
+ interface ObservedError {
2567
+ /** `errorType` and `errorBody` are derived from it unless given. */
2568
+ error?: unknown;
2569
+ errorType?: string;
2570
+ errorBody?: string;
2571
+ }
2572
+ /** One traced call, handed to the `client.trace()` callback. */
2573
+ declare class Trace {
2574
+ #private;
2575
+ private constructor();
2576
+ /** The session this call's events carry. */
2577
+ get sessionId(): string;
2578
+ /** Record the outcome. Without a call, the callback's return value is the
2579
+ * result. `observed(undefined, { error })` records a failure the callback
2580
+ * caught and did not rethrow. The last call wins. */
2581
+ observed(result?: unknown, failure?: ObservedError): this;
2582
+ /** Report on this call, in its session. */
2583
+ annotate(options: AnnotateOptions): Promise<void>;
2584
+ }
2585
+ /** The library API's client. One per process. */
2586
+ declare class Client {
2587
+ #private;
2588
+ constructor(options?: ClientOptions);
2589
+ /** Run `fn` with one session, principal, client and turn for every
2590
+ * `trace()` and `annotate()` inside it, including after its awaits. Open
2591
+ * one per request or conversation. Returns what `fn` returns. */
2592
+ session<T>(options: SessionOptions, fn: () => T): T;
2593
+ /** Run `fn` as one traced tool call and return what it returns. When `fn`
2594
+ * returns a promise or other thenable, the call ends when it settles, and
2595
+ * what comes back is a new native Promise of the same value: `then` is
2596
+ * called exactly once, so a lazy query builder is not run twice. A throw or
2597
+ * rejection is recorded and passed on unchanged. */
2598
+ trace<T>(options: TraceOptions, fn: (trace: Trace) => T): T;
2599
+ /** `fn`, traced on every call. A single plain-object argument is sent as
2600
+ * `params`, as an MCP tool's arguments are; other arguments as
2601
+ * `{ args: [...] }`, unless `options.params` is given. */
2602
+ wrap<A extends unknown[], R>(options: string | TraceOptions, fn: (...args: A) => R): (...args: A) => R;
2603
+ /** Emit an annotation in the open `session()` block, or in a session of its
2604
+ * own outside one. To report on a traced call, use `trace.annotate()`. */
2605
+ annotate(options: AnnotateOptions & {
2606
+ consentToken?: string;
2607
+ }): Promise<void>;
2608
+ /** Wait until every event so far has reached the sink and the sink has flushed. */
2609
+ flush(): Promise<void>;
2610
+ /** Flush, then close the sink. Later events are dropped. */
2611
+ aclose(): Promise<void>;
2612
+ }
2613
+
2614
+ /** The server instructions a vendor serving MCP itself puts in its
2615
+ * `initialize` result beside `user_goal` (SPEC §5.6), and all of Baton's
2616
+ * instructions under `reportMode: "off"`. */
2617
+ declare const INTENT_INSTRUCTIONS: string;
2618
+ /** One injected param, for a vendor adding it to its own API (SPEC §5.6).
2619
+ * `description` is the text an agent reads on an MCP server, without the
2620
+ * leading "OPTIONAL." / "REQUIRED." label: whether the vendor's API requires
2621
+ * it is the vendor's call. `traceOption` is the `client.trace()` option the
2622
+ * agent's answer goes to. */
2623
+ interface IntentParam {
2624
+ readonly name: string;
2625
+ readonly description: string;
2626
+ readonly traceOption: "intent";
2627
+ }
2628
+ declare const INTENT_PARAMS: readonly IntentParam[];
2629
+
2630
+ 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_INSTRUCTIONS, 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.6";
3
+ declare const SDK_VERSION = "ts-0.5.8";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -20,10 +20,11 @@ declare const SDK_VERSION = "ts-0.5.6";
20
20
  /** Emitted before the vendor handler runs. `params` is PII-scrubbed at
21
21
  * emit-time per SPEC §7.
22
22
  *
23
- * `call_intent` / `call_expected` / `call_workflow` are the values the SDK
24
- * stripped from the injected `user_goal` / `expected_result` /
25
- * `overall_task` params (see `llmText.ts`); they ride as SIBLINGS of
26
- * `params` — `params` stays exactly the vendor-visible arguments.
23
+ * `call_intent` is the value the SDK stripped from the injected `user_goal`
24
+ * param, and `call_expected` / `call_workflow` the retired `expected_result` /
25
+ * `overall_task` a stale client may still send (see `llmText.ts`); they ride
26
+ * as SIBLINGS of `params` — `params` stays exactly the vendor-visible
27
+ * arguments.
27
28
  * `call_intent`/`call_expected` are call-scoped diagnostics;
28
29
  * `call_workflow` is the task-label grouping key (console rung 3b, exact
29
30
  * string continuity). `intent_source` records provenance
@@ -2188,7 +2189,8 @@ interface BatonConfig {
2188
2189
  * for the same reason: a capitalisation you never chose would be a
2189
2190
  * fabricated name. Falls back to the DSN's server segment when the server's
2190
2191
  * name is one a library made up, is blank or unreadable, or would push the
2191
- * server instructions over their cap. With no `dsn`, this is required. */
2192
+ * server instructions over their cap. With no `dsn`, this is required
2193
+ * under `reportMode: "on"`, and unused otherwise. */
2192
2194
  vendorDisplayName?: string;
2193
2195
  /** End-user consent token attached to every emitted event per SPEC §2.3 —
2194
2196
  * the Console MUST reject events missing it.
@@ -2222,21 +2224,29 @@ interface BatonConfig {
2222
2224
  * `acme-knowledge-base_annotate`. It falls back to `{vendorId}_annotate`
2223
2225
  * when the name is one a library made up, slugs to nothing, is unreadable,
2224
2226
  * or would not fit the server instructions. Set this to keep a name you have
2225
- * written into documentation, a prompt or a script. */
2227
+ * written into documentation, a prompt or a script. Has no effect unless
2228
+ * `reportMode: "on"`, and warns if set without it. */
2226
2229
  annotationToolName?: string;
2230
+ /** Whether the agent is given a tool to report a call that went wrong.
2231
+ * `"off"` (the default) registers no annotation tool, and Baton's server
2232
+ * instructions are `INTENT_INSTRUCTIONS` alone, below your own. Each call's
2233
+ * goal still arrives through `user_goal`. `"on"` registers the tool and
2234
+ * serves its instructions. */
2235
+ reportMode?: "on" | "off";
2227
2236
  /** Per-tool intent-param injection (mirrors baton-extmcp's vendor-neutral
2228
- * naming). `"required"` (default) injects `user_goal`/`expected_result`/
2229
- * `overall_task` string params on every wrapped tool's advertised schema
2230
- * and ADVERTISES all three as required in
2231
- * `tools/list`, without enforcing them: a call that omits them still reaches
2237
+ * naming). `"required"` (default) injects a `user_goal` string param on
2238
+ * every wrapped tool's advertised schema and ADVERTISES it as required in
2239
+ * `tools/list`, without enforcing it: a call that omits it still reaches
2232
2240
  * your handler, and its event simply carries no intent. `"optional"` injects
2233
- * the same params and advertises none of them as required. `"off"` disables injection. The params are
2234
- * stripped before the vendor handler runs, so the tool never sees them.
2241
+ * the same param and does not advertise it as required. There is no
2242
+ * `"off"`: this SDK has no proactive reports, so nothing else would capture
2243
+ * what the user is trying to do. The param is stripped before the vendor
2244
+ * handler runs, so the tool never sees it.
2235
2245
  * This is what captures intent on runtimes that drop `instructions`
2236
2246
  * (notably Claude Desktop) — where the annotation tool alone yields
2237
2247
  * nothing. A tool registered with no `inputSchema` at all is left alone
2238
2248
  * regardless of this setting (see `schemaCompat.injectGoalParams`). */
2239
- intentParamMode?: "optional" | "required" | "off";
2249
+ intentParamMode?: "optional" | "required";
2240
2250
  /** Whether tool RESPONSE data is captured at all (SPEC §11.4).
2241
2251
  *
2242
2252
  * `"full"` (the default) captures as it always has. `"off"` means nothing
@@ -2353,10 +2363,9 @@ declare class BatonHandle {
2353
2363
  * MCP's error flag on a 200. Reading only the first is what this package did,
2354
2364
  * and what §6.1's own wording told it to. Injects server `instructions`
2355
2365
  * (SPEC §5.1.2), registers
2356
- * the `<vendor>_annotate` tool (SPEC §5.1.1), injects `user_goal`/
2357
- * `expected_result`/`overall_task` intent params on every wrapped tool's
2358
- * schema (SPEC §11.4.1 `call_intent`/`call_expected`/`call_workflow`/
2359
- * `intent_source`), and captures a `surface_snapshot`
2366
+ * the `<vendor>_annotate` tool under `reportMode: "on"` (SPEC §5.1.1), injects
2367
+ * a `user_goal` intent param on every wrapped tool's schema (SPEC §11.4.1
2368
+ * `call_intent`/`intent_source`), and captures a `surface_snapshot`
2360
2369
  * of the vendor-true surface. Every payload leaving here runs through the
2361
2370
  * configured scrubber, which defaults to the shipped ruleset (`src/scrub.ts`)
2362
2371
  * — see README "What is not here yet" for what's still not here (the low-level
@@ -2478,4 +2487,144 @@ declare function principalFromOAuthSub(context: PrincipalResolutionContext): Pri
2478
2487
  * good enough is the vendor's call. */
2479
2488
  declare function principalFromOAuthEmail(context: PrincipalResolutionContext): Principal | null;
2480
2489
 
2481
- 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 };
2490
+ /** The envelope's `client_observed` (SPEC §11.4): what the client said about
2491
+ * itself, sent uninterpreted. The consumer names the client; this SDK does
2492
+ * not, and sends `agent_runtime: "unknown"` on every event. */
2493
+
2494
+ /** Headers as a vendor's server framework holds them: a fetch `Headers`, or a
2495
+ * plain record such as Node's `req.headers`. */
2496
+ type HeaderInput = Headers | Record<string, string | readonly string[] | undefined>;
2497
+
2498
+ /**
2499
+ * The library API (SPEC §5.6): `Client` for a vendor whose agents reach it
2500
+ * through something other than MCP — a REST API, a skill, or a tool loop in
2501
+ * the vendor's own agent. Twin of the Python SDK's `baton.Client`, with the
2502
+ * `with` blocks as callbacks:
2503
+ *
2504
+ * const client = new Client({ dsn: process.env.BATON_DSN });
2505
+ * app.use((req, res, next) =>
2506
+ * client.session({ sessionId: req.get("x-conversation-id") }, () =>
2507
+ * client.trace({ toolName: req.path, params: req.body }, () => next()),
2508
+ * ),
2509
+ * );
2510
+ *
2511
+ * Capture never throws into the vendor's code: a callback's own throw is
2512
+ * recorded and rethrown unchanged, and every failure of ours is logged and
2513
+ * dropped. Only a bad config throws, and only from the constructor.
2514
+ */
2515
+
2516
+ interface ClientOptions {
2517
+ /** The packed connection string from /account. Resolved explicit →
2518
+ * `BATON_DSN`; it builds the sink and supplies `vendorId` and `tenantId`. */
2519
+ dsn?: string;
2520
+ /** Required unless a `dsn` is given. */
2521
+ sink?: Sink;
2522
+ /** Explicit → `BATON_VENDOR_ID`. Required unless a `dsn` supplies it. */
2523
+ vendorId?: string;
2524
+ /** Explicit → `BATON_TENANT_ID` → `vendorId`. */
2525
+ tenantId?: string;
2526
+ /** Explicit → `BATON_CONSENT_TOKEN` → the SDK default. */
2527
+ consentToken?: string;
2528
+ /** Defaults to `new Scrubber().scrub`; pass `identityScrub` to opt out. */
2529
+ scrubber?: (value: unknown) => unknown;
2530
+ /** `"off"` sends no result: see `BatonConfig.resultCaptureMode`. */
2531
+ resultCaptureMode?: ResultCaptureMode;
2532
+ }
2533
+ interface SessionOptions {
2534
+ /** The vendor's own id for the conversation; without one, the block mints one. */
2535
+ sessionId?: string;
2536
+ /** Who the vendor says is calling. */
2537
+ principal?: Principal;
2538
+ /** What the calling client said about itself. */
2539
+ clientInfo?: {
2540
+ name?: string;
2541
+ version?: string;
2542
+ };
2543
+ /** The request's headers; only registered ones are kept. */
2544
+ headers?: HeaderInput;
2545
+ /** The vendor's own id for the user request these calls answer. Pass the
2546
+ * same value to every block that serves it, and those calls stay one turn. */
2547
+ turnId?: string;
2548
+ }
2549
+ interface TraceOptions {
2550
+ toolName: string;
2551
+ intent?: string;
2552
+ expectedOutcome?: string;
2553
+ workflow?: string;
2554
+ params?: Record<string, unknown>;
2555
+ consentToken?: string;
2556
+ }
2557
+ interface AnnotateOptions {
2558
+ whatHappened?: string;
2559
+ toolName?: string;
2560
+ intent?: string;
2561
+ expectedOutcome?: string;
2562
+ workflow?: string;
2563
+ suggestedImprovement?: string;
2564
+ context?: Record<string, unknown>;
2565
+ }
2566
+ interface ObservedError {
2567
+ /** `errorType` and `errorBody` are derived from it unless given. */
2568
+ error?: unknown;
2569
+ errorType?: string;
2570
+ errorBody?: string;
2571
+ }
2572
+ /** One traced call, handed to the `client.trace()` callback. */
2573
+ declare class Trace {
2574
+ #private;
2575
+ private constructor();
2576
+ /** The session this call's events carry. */
2577
+ get sessionId(): string;
2578
+ /** Record the outcome. Without a call, the callback's return value is the
2579
+ * result. `observed(undefined, { error })` records a failure the callback
2580
+ * caught and did not rethrow. The last call wins. */
2581
+ observed(result?: unknown, failure?: ObservedError): this;
2582
+ /** Report on this call, in its session. */
2583
+ annotate(options: AnnotateOptions): Promise<void>;
2584
+ }
2585
+ /** The library API's client. One per process. */
2586
+ declare class Client {
2587
+ #private;
2588
+ constructor(options?: ClientOptions);
2589
+ /** Run `fn` with one session, principal, client and turn for every
2590
+ * `trace()` and `annotate()` inside it, including after its awaits. Open
2591
+ * one per request or conversation. Returns what `fn` returns. */
2592
+ session<T>(options: SessionOptions, fn: () => T): T;
2593
+ /** Run `fn` as one traced tool call and return what it returns. When `fn`
2594
+ * returns a promise or other thenable, the call ends when it settles, and
2595
+ * what comes back is a new native Promise of the same value: `then` is
2596
+ * called exactly once, so a lazy query builder is not run twice. A throw or
2597
+ * rejection is recorded and passed on unchanged. */
2598
+ trace<T>(options: TraceOptions, fn: (trace: Trace) => T): T;
2599
+ /** `fn`, traced on every call. A single plain-object argument is sent as
2600
+ * `params`, as an MCP tool's arguments are; other arguments as
2601
+ * `{ args: [...] }`, unless `options.params` is given. */
2602
+ wrap<A extends unknown[], R>(options: string | TraceOptions, fn: (...args: A) => R): (...args: A) => R;
2603
+ /** Emit an annotation in the open `session()` block, or in a session of its
2604
+ * own outside one. To report on a traced call, use `trace.annotate()`. */
2605
+ annotate(options: AnnotateOptions & {
2606
+ consentToken?: string;
2607
+ }): Promise<void>;
2608
+ /** Wait until every event so far has reached the sink and the sink has flushed. */
2609
+ flush(): Promise<void>;
2610
+ /** Flush, then close the sink. Later events are dropped. */
2611
+ aclose(): Promise<void>;
2612
+ }
2613
+
2614
+ /** The server instructions a vendor serving MCP itself puts in its
2615
+ * `initialize` result beside `user_goal` (SPEC §5.6), and all of Baton's
2616
+ * instructions under `reportMode: "off"`. */
2617
+ declare const INTENT_INSTRUCTIONS: string;
2618
+ /** One injected param, for a vendor adding it to its own API (SPEC §5.6).
2619
+ * `description` is the text an agent reads on an MCP server, without the
2620
+ * leading "OPTIONAL." / "REQUIRED." label: whether the vendor's API requires
2621
+ * it is the vendor's call. `traceOption` is the `client.trace()` option the
2622
+ * agent's answer goes to. */
2623
+ interface IntentParam {
2624
+ readonly name: string;
2625
+ readonly description: string;
2626
+ readonly traceOption: "intent";
2627
+ }
2628
+ declare const INTENT_PARAMS: readonly IntentParam[];
2629
+
2630
+ 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_INSTRUCTIONS, 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 };