@goodtiming/baton-sdk 1.0.1 → 1.1.1

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-1.0.1";
3
+ declare const SDK_VERSION = "ts-1.1.1";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -2406,9 +2406,8 @@ declare function identityScrub(value: unknown): unknown;
2406
2406
  *
2407
2407
  * The same four sinks as `sinks.py`:
2408
2408
  *
2409
- * - `StdoutSink` — JSONL to a writable stream (default `process.stderr`,
2410
- * for the same reason as Python: MCP stdio transport reserves stdout for
2411
- * JSON-RPC framing).
2409
+ * - `StdoutSink` — JSONL to stderr, or to a stream the vendor passes (MCP
2410
+ * stdio transport reserves stdout for JSON-RPC framing).
2412
2411
  * - `FileSink` — JSONL appended to a file.
2413
2412
  * - `HttpSink` — POST batches to any HTTP endpoint with bearer auth;
2414
2413
  * bounded buffer, retry with backoff, circuit breaker. This is the contract a
@@ -2434,9 +2433,10 @@ declare class SinkClosedError extends Error {
2434
2433
  name: string;
2435
2434
  }
2436
2435
  interface StdoutSinkOptions {
2437
- /** Defaults to `process.stderr` — stdio MCP transport reserves stdout for
2438
- * JSON-RPC framing. Pass `process.stdout` explicitly for non-MCP (library
2439
- * API) use if preferred. */
2436
+ /** Defaults to stderr (`console.warn` where `process.stderr` is missing or
2437
+ * cannot write): the MCP
2438
+ * stdio transport reserves stdout for JSON-RPC framing. Pass
2439
+ * `process.stdout` for non-MCP (library API) use if preferred. */
2440
2440
  stream?: NodeJS.WritableStream;
2441
2441
  }
2442
2442
  declare class StdoutSink implements Sink {
@@ -2488,7 +2488,8 @@ interface HttpSinkOptions {
2488
2488
  /** How long the flush at process exit, or an explicit `flush()` or
2489
2489
  * `aclose()`, may take in total, in ms, at most 2^31 - 1. Default 3000. */
2490
2490
  shutdownFlushTimeoutMs?: number;
2491
- /** The longest an event waits before its batch is sent, in ms. Default 5000. */
2491
+ /** The longest an event waits before its batch is sent, in ms. Default
2492
+ * 5000, or 0 on Cloudflare Workers. At 0 a write sends at once. */
2492
2493
  flushIntervalMs?: number;
2493
2494
  /** Injectable for tests; defaults to the global `fetch`. */
2494
2495
  fetchImpl?: typeof fetch;
@@ -2544,13 +2545,19 @@ declare class HttpSink implements Sink {
2544
2545
  /** Whether the queued pass sends everything waiting, not only what is due. */
2545
2546
  private forceNext;
2546
2547
  private flushTimer;
2547
- /** Set by a failed batch: only the timer, a flush or a close tries again. */
2548
+ /** Set by a failed batch: only the timer, a flush, a close or, at
2549
+ * `flushIntervalMs` 0, a write after `retryFrom` tries again. */
2548
2550
  private waitForTimer;
2551
+ /** When a failed batch may be tried again. At `flushIntervalMs` 0 the
2552
+ * first write from then retries, as a Worker may drop the timer. */
2553
+ private retryFrom;
2549
2554
  /** Nothing is sent before this `Date.now()`, from a 429's `Retry-After`. */
2550
2555
  private retryAt;
2551
2556
  /** Set for the life of the sink by a 404 or 405 on the batch path. */
2552
2557
  private batchless;
2553
2558
  private exitHooks;
2559
+ /** The `process` the exit hooks were last tried on, so a refusal is not retried per write. */
2560
+ private exitHooksTriedOn;
2554
2561
  /** The least time between two of this sink's loss reports. */
2555
2562
  private static reportIntervalMs;
2556
2563
  /** Totals only grow, so their sum tells whether they changed. */
@@ -2998,6 +3005,13 @@ interface BatonConfig {
2998
3005
  * what a page shows. A vendor who must not send real identities hashes
2999
3006
  * inside the hook and returns `form: "hashed"`. */
3000
3007
  resolvePrincipal?: ResolvePrincipalHook;
3008
+ /** A low-level `Server`'s tools, as its `tools/list` answers them, or a
3009
+ * function that returns them. Read once per `withBaton` or `createBaton`.
3010
+ * Without it Baton learns the tools from the lists its servers serve, so a
3011
+ * process that has served none yet, such as a fresh worker, takes
3012
+ * `user_goal` off every call, even from a tool that declares its own. An
3013
+ * `McpServer` does not read it. */
3014
+ tools?: readonly unknown[] | (() => readonly unknown[]);
3001
3015
  }
3002
3016
 
3003
3017
  /**
@@ -3068,9 +3082,9 @@ declare class BatonHandle {
3068
3082
  * a `user_goal` intent param on every wrapped tool's schema (SPEC §11.4.1
3069
3083
  * `call_intent`/`intent_source`), and captures a `surface_snapshot`
3070
3084
  * of the vendor-true surface. Every payload leaving here runs through the
3071
- * configured scrubber, which defaults to the shipped ruleset (`src/scrub.ts`)
3072
- * — see README "What is not here yet" for what's still not here (the low-level
3073
- * `Server` adapter).
3085
+ * configured scrubber, which defaults to the shipped ruleset (`src/scrub.ts`).
3086
+ * On a low-level `Server`, which has no tool registry, the same is done at its
3087
+ * `tools/list` and `tools/call` handlers: see `installLowLevelToolSeams`.
3074
3088
  *
3075
3089
  * Interception mechanism: `McpServer` has no middleware API (unlike the
3076
3090
  * standalone `fastmcp` library's `Middleware`/`CallNext`), so this patches
@@ -3127,12 +3141,19 @@ interface SupportedMcpServer {
3127
3141
  readonly server: unknown;
3128
3142
  registerTool(name: string, ...rest: unknown[]): unknown;
3129
3143
  }
3130
- /** Install Baton into an `McpServer`. See module docstring for usage. */
3131
- declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
3144
+ /** The official SDK's low-level `Server`, 1.x or v2, on which the vendor sets
3145
+ * its own `tools/list` and `tools/call` handlers. */
3146
+ interface SupportedLowLevelServer {
3147
+ setRequestHandler(method: unknown, ...rest: unknown[]): unknown;
3148
+ }
3149
+ type SupportedServer = SupportedMcpServer | SupportedLowLevelServer;
3150
+ /** Install Baton into an `McpServer` or a low-level `Server`. See module
3151
+ * docstring for usage. */
3152
+ declare function withBaton(server: SupportedServer, supplied?: BatonConfig): BatonHandle;
3132
3153
  /** One Baton for a process that builds a new `McpServer` for every request.
3133
3154
  * Owns the sink, so a request has nothing to close. */
3134
3155
  interface Baton {
3135
- wrap(server: SupportedMcpServer): void;
3156
+ wrap(server: SupportedServer): void;
3136
3157
  flush(): Promise<void>;
3137
3158
  aclose(): Promise<void>;
3138
3159
  }
@@ -3370,4 +3391,4 @@ interface IntentParam {
3370
3391
  }
3371
3392
  declare const INTENT_PARAMS: readonly IntentParam[];
3372
3393
 
3373
- export { type AnnotateOptions, type AnnotationEvent, type AnnotationPayload, type AuthInfo, type Baton, type BatonConfig, BatonHandle, type CaptureObserved, Client, type ClientOptions, type ClientReportEvent, type ClientReportPayload, type Event, EventSchema, type EventType, FileSink, type HeaderInput, HttpSink, type HttpSinkOptions, INTENT_INSTRUCTIONS, INTENT_PARAMS, type IntentParam, type ListToolsOptions, MultiSink, type ObservedError, type Organization, type Principal, type PrincipalForm, type PrincipalResolutionContext, type PromptGetEndEvent, type PromptGetEndPayload, type PromptGetErrorEvent, type PromptGetErrorPayload, type PromptGetStartEvent, type PromptGetStartPayload, type PromptListEndEvent, type PromptListEndPayload, type PromptListErrorEvent, type PromptListErrorPayload, type PromptListStartEvent, type PromptListStartPayload, type ReportTool, type ResolvePrincipalHook, type ResourceListEndEvent, type ResourceListEndPayload, type ResourceListErrorEvent, type ResourceListErrorPayload, type ResourceListStartEvent, type ResourceListStartPayload, type ResourceReadEndEvent, type ResourceReadEndPayload, type ResourceReadErrorEvent, type ResourceReadErrorPayload, type ResourceReadStartEvent, type ResourceReadStartPayload, type ResultCaptureMode, SDK_VERSION, Scrubber, type SessionOptions, type Sink, SinkClosedError, StdoutSink, type StdoutSinkOptions, type SupportedMcpServer, type SurfaceSnapshotEvent, type SurfaceSnapshotPayload, type ToolCallEndEvent, type ToolCallEndPayload, type ToolCallErrorEvent, type ToolCallErrorPayload, type ToolCallStartEvent, type ToolCallStartPayload, type ToolListEndEvent, type ToolListEndPayload, type ToolListErrorEvent, type ToolListErrorPayload, type ToolListStartEvent, type ToolListStartPayload, Trace, type TraceOptions, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, reportTool, withBaton };
3394
+ export { type AnnotateOptions, type AnnotationEvent, type AnnotationPayload, type AuthInfo, type Baton, type BatonConfig, BatonHandle, type CaptureObserved, Client, type ClientOptions, type ClientReportEvent, type ClientReportPayload, type Event, EventSchema, type EventType, FileSink, type HeaderInput, HttpSink, type HttpSinkOptions, INTENT_INSTRUCTIONS, INTENT_PARAMS, type IntentParam, type ListToolsOptions, MultiSink, type ObservedError, type Organization, type Principal, type PrincipalForm, type PrincipalResolutionContext, type PromptGetEndEvent, type PromptGetEndPayload, type PromptGetErrorEvent, type PromptGetErrorPayload, type PromptGetStartEvent, type PromptGetStartPayload, type PromptListEndEvent, type PromptListEndPayload, type PromptListErrorEvent, type PromptListErrorPayload, type PromptListStartEvent, type PromptListStartPayload, type ReportTool, type ResolvePrincipalHook, type ResourceListEndEvent, type ResourceListEndPayload, type ResourceListErrorEvent, type ResourceListErrorPayload, type ResourceListStartEvent, type ResourceListStartPayload, type ResourceReadEndEvent, type ResourceReadEndPayload, type ResourceReadErrorEvent, type ResourceReadErrorPayload, type ResourceReadStartEvent, type ResourceReadStartPayload, type ResultCaptureMode, SDK_VERSION, Scrubber, type SessionOptions, type Sink, SinkClosedError, StdoutSink, type StdoutSinkOptions, type SupportedLowLevelServer, type SupportedMcpServer, type SupportedServer, type SurfaceSnapshotEvent, type SurfaceSnapshotPayload, type ToolCallEndEvent, type ToolCallEndPayload, type ToolCallErrorEvent, type ToolCallErrorPayload, type ToolCallStartEvent, type ToolCallStartPayload, type ToolListEndEvent, type ToolListEndPayload, type ToolListErrorEvent, type ToolListErrorPayload, type ToolListStartEvent, type ToolListStartPayload, Trace, type TraceOptions, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, reportTool, 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-1.0.1";
3
+ declare const SDK_VERSION = "ts-1.1.1";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -2406,9 +2406,8 @@ declare function identityScrub(value: unknown): unknown;
2406
2406
  *
2407
2407
  * The same four sinks as `sinks.py`:
2408
2408
  *
2409
- * - `StdoutSink` — JSONL to a writable stream (default `process.stderr`,
2410
- * for the same reason as Python: MCP stdio transport reserves stdout for
2411
- * JSON-RPC framing).
2409
+ * - `StdoutSink` — JSONL to stderr, or to a stream the vendor passes (MCP
2410
+ * stdio transport reserves stdout for JSON-RPC framing).
2412
2411
  * - `FileSink` — JSONL appended to a file.
2413
2412
  * - `HttpSink` — POST batches to any HTTP endpoint with bearer auth;
2414
2413
  * bounded buffer, retry with backoff, circuit breaker. This is the contract a
@@ -2434,9 +2433,10 @@ declare class SinkClosedError extends Error {
2434
2433
  name: string;
2435
2434
  }
2436
2435
  interface StdoutSinkOptions {
2437
- /** Defaults to `process.stderr` — stdio MCP transport reserves stdout for
2438
- * JSON-RPC framing. Pass `process.stdout` explicitly for non-MCP (library
2439
- * API) use if preferred. */
2436
+ /** Defaults to stderr (`console.warn` where `process.stderr` is missing or
2437
+ * cannot write): the MCP
2438
+ * stdio transport reserves stdout for JSON-RPC framing. Pass
2439
+ * `process.stdout` for non-MCP (library API) use if preferred. */
2440
2440
  stream?: NodeJS.WritableStream;
2441
2441
  }
2442
2442
  declare class StdoutSink implements Sink {
@@ -2488,7 +2488,8 @@ interface HttpSinkOptions {
2488
2488
  /** How long the flush at process exit, or an explicit `flush()` or
2489
2489
  * `aclose()`, may take in total, in ms, at most 2^31 - 1. Default 3000. */
2490
2490
  shutdownFlushTimeoutMs?: number;
2491
- /** The longest an event waits before its batch is sent, in ms. Default 5000. */
2491
+ /** The longest an event waits before its batch is sent, in ms. Default
2492
+ * 5000, or 0 on Cloudflare Workers. At 0 a write sends at once. */
2492
2493
  flushIntervalMs?: number;
2493
2494
  /** Injectable for tests; defaults to the global `fetch`. */
2494
2495
  fetchImpl?: typeof fetch;
@@ -2544,13 +2545,19 @@ declare class HttpSink implements Sink {
2544
2545
  /** Whether the queued pass sends everything waiting, not only what is due. */
2545
2546
  private forceNext;
2546
2547
  private flushTimer;
2547
- /** Set by a failed batch: only the timer, a flush or a close tries again. */
2548
+ /** Set by a failed batch: only the timer, a flush, a close or, at
2549
+ * `flushIntervalMs` 0, a write after `retryFrom` tries again. */
2548
2550
  private waitForTimer;
2551
+ /** When a failed batch may be tried again. At `flushIntervalMs` 0 the
2552
+ * first write from then retries, as a Worker may drop the timer. */
2553
+ private retryFrom;
2549
2554
  /** Nothing is sent before this `Date.now()`, from a 429's `Retry-After`. */
2550
2555
  private retryAt;
2551
2556
  /** Set for the life of the sink by a 404 or 405 on the batch path. */
2552
2557
  private batchless;
2553
2558
  private exitHooks;
2559
+ /** The `process` the exit hooks were last tried on, so a refusal is not retried per write. */
2560
+ private exitHooksTriedOn;
2554
2561
  /** The least time between two of this sink's loss reports. */
2555
2562
  private static reportIntervalMs;
2556
2563
  /** Totals only grow, so their sum tells whether they changed. */
@@ -2998,6 +3005,13 @@ interface BatonConfig {
2998
3005
  * what a page shows. A vendor who must not send real identities hashes
2999
3006
  * inside the hook and returns `form: "hashed"`. */
3000
3007
  resolvePrincipal?: ResolvePrincipalHook;
3008
+ /** A low-level `Server`'s tools, as its `tools/list` answers them, or a
3009
+ * function that returns them. Read once per `withBaton` or `createBaton`.
3010
+ * Without it Baton learns the tools from the lists its servers serve, so a
3011
+ * process that has served none yet, such as a fresh worker, takes
3012
+ * `user_goal` off every call, even from a tool that declares its own. An
3013
+ * `McpServer` does not read it. */
3014
+ tools?: readonly unknown[] | (() => readonly unknown[]);
3001
3015
  }
3002
3016
 
3003
3017
  /**
@@ -3068,9 +3082,9 @@ declare class BatonHandle {
3068
3082
  * a `user_goal` intent param on every wrapped tool's schema (SPEC §11.4.1
3069
3083
  * `call_intent`/`intent_source`), and captures a `surface_snapshot`
3070
3084
  * of the vendor-true surface. Every payload leaving here runs through the
3071
- * configured scrubber, which defaults to the shipped ruleset (`src/scrub.ts`)
3072
- * — see README "What is not here yet" for what's still not here (the low-level
3073
- * `Server` adapter).
3085
+ * configured scrubber, which defaults to the shipped ruleset (`src/scrub.ts`).
3086
+ * On a low-level `Server`, which has no tool registry, the same is done at its
3087
+ * `tools/list` and `tools/call` handlers: see `installLowLevelToolSeams`.
3074
3088
  *
3075
3089
  * Interception mechanism: `McpServer` has no middleware API (unlike the
3076
3090
  * standalone `fastmcp` library's `Middleware`/`CallNext`), so this patches
@@ -3127,12 +3141,19 @@ interface SupportedMcpServer {
3127
3141
  readonly server: unknown;
3128
3142
  registerTool(name: string, ...rest: unknown[]): unknown;
3129
3143
  }
3130
- /** Install Baton into an `McpServer`. See module docstring for usage. */
3131
- declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
3144
+ /** The official SDK's low-level `Server`, 1.x or v2, on which the vendor sets
3145
+ * its own `tools/list` and `tools/call` handlers. */
3146
+ interface SupportedLowLevelServer {
3147
+ setRequestHandler(method: unknown, ...rest: unknown[]): unknown;
3148
+ }
3149
+ type SupportedServer = SupportedMcpServer | SupportedLowLevelServer;
3150
+ /** Install Baton into an `McpServer` or a low-level `Server`. See module
3151
+ * docstring for usage. */
3152
+ declare function withBaton(server: SupportedServer, supplied?: BatonConfig): BatonHandle;
3132
3153
  /** One Baton for a process that builds a new `McpServer` for every request.
3133
3154
  * Owns the sink, so a request has nothing to close. */
3134
3155
  interface Baton {
3135
- wrap(server: SupportedMcpServer): void;
3156
+ wrap(server: SupportedServer): void;
3136
3157
  flush(): Promise<void>;
3137
3158
  aclose(): Promise<void>;
3138
3159
  }
@@ -3370,4 +3391,4 @@ interface IntentParam {
3370
3391
  }
3371
3392
  declare const INTENT_PARAMS: readonly IntentParam[];
3372
3393
 
3373
- export { type AnnotateOptions, type AnnotationEvent, type AnnotationPayload, type AuthInfo, type Baton, type BatonConfig, BatonHandle, type CaptureObserved, Client, type ClientOptions, type ClientReportEvent, type ClientReportPayload, type Event, EventSchema, type EventType, FileSink, type HeaderInput, HttpSink, type HttpSinkOptions, INTENT_INSTRUCTIONS, INTENT_PARAMS, type IntentParam, type ListToolsOptions, MultiSink, type ObservedError, type Organization, type Principal, type PrincipalForm, type PrincipalResolutionContext, type PromptGetEndEvent, type PromptGetEndPayload, type PromptGetErrorEvent, type PromptGetErrorPayload, type PromptGetStartEvent, type PromptGetStartPayload, type PromptListEndEvent, type PromptListEndPayload, type PromptListErrorEvent, type PromptListErrorPayload, type PromptListStartEvent, type PromptListStartPayload, type ReportTool, type ResolvePrincipalHook, type ResourceListEndEvent, type ResourceListEndPayload, type ResourceListErrorEvent, type ResourceListErrorPayload, type ResourceListStartEvent, type ResourceListStartPayload, type ResourceReadEndEvent, type ResourceReadEndPayload, type ResourceReadErrorEvent, type ResourceReadErrorPayload, type ResourceReadStartEvent, type ResourceReadStartPayload, type ResultCaptureMode, SDK_VERSION, Scrubber, type SessionOptions, type Sink, SinkClosedError, StdoutSink, type StdoutSinkOptions, type SupportedMcpServer, type SurfaceSnapshotEvent, type SurfaceSnapshotPayload, type ToolCallEndEvent, type ToolCallEndPayload, type ToolCallErrorEvent, type ToolCallErrorPayload, type ToolCallStartEvent, type ToolCallStartPayload, type ToolListEndEvent, type ToolListEndPayload, type ToolListErrorEvent, type ToolListErrorPayload, type ToolListStartEvent, type ToolListStartPayload, Trace, type TraceOptions, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, reportTool, withBaton };
3394
+ export { type AnnotateOptions, type AnnotationEvent, type AnnotationPayload, type AuthInfo, type Baton, type BatonConfig, BatonHandle, type CaptureObserved, Client, type ClientOptions, type ClientReportEvent, type ClientReportPayload, type Event, EventSchema, type EventType, FileSink, type HeaderInput, HttpSink, type HttpSinkOptions, INTENT_INSTRUCTIONS, INTENT_PARAMS, type IntentParam, type ListToolsOptions, MultiSink, type ObservedError, type Organization, type Principal, type PrincipalForm, type PrincipalResolutionContext, type PromptGetEndEvent, type PromptGetEndPayload, type PromptGetErrorEvent, type PromptGetErrorPayload, type PromptGetStartEvent, type PromptGetStartPayload, type PromptListEndEvent, type PromptListEndPayload, type PromptListErrorEvent, type PromptListErrorPayload, type PromptListStartEvent, type PromptListStartPayload, type ReportTool, type ResolvePrincipalHook, type ResourceListEndEvent, type ResourceListEndPayload, type ResourceListErrorEvent, type ResourceListErrorPayload, type ResourceListStartEvent, type ResourceListStartPayload, type ResourceReadEndEvent, type ResourceReadEndPayload, type ResourceReadErrorEvent, type ResourceReadErrorPayload, type ResourceReadStartEvent, type ResourceReadStartPayload, type ResultCaptureMode, SDK_VERSION, Scrubber, type SessionOptions, type Sink, SinkClosedError, StdoutSink, type StdoutSinkOptions, type SupportedLowLevelServer, type SupportedMcpServer, type SupportedServer, type SurfaceSnapshotEvent, type SurfaceSnapshotPayload, type ToolCallEndEvent, type ToolCallEndPayload, type ToolCallErrorEvent, type ToolCallErrorPayload, type ToolCallStartEvent, type ToolCallStartPayload, type ToolListEndEvent, type ToolListEndPayload, type ToolListErrorEvent, type ToolListErrorPayload, type ToolListStartEvent, type ToolListStartPayload, Trace, type TraceOptions, createBaton, identityScrub, principalFromOAuthEmail, principalFromOAuthSub, reportTool, withBaton };