@goodtiming/baton-sdk 1.0.1 → 1.1.0

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.0";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -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,8 +2545,12 @@ 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. */
@@ -2998,6 +3003,13 @@ interface BatonConfig {
2998
3003
  * what a page shows. A vendor who must not send real identities hashes
2999
3004
  * inside the hook and returns `form: "hashed"`. */
3000
3005
  resolvePrincipal?: ResolvePrincipalHook;
3006
+ /** A low-level `Server`'s tools, as its `tools/list` answers them, or a
3007
+ * function that returns them. Read once per `withBaton` or `createBaton`.
3008
+ * Without it Baton learns the tools from the lists its servers serve, so a
3009
+ * process that has served none yet, such as a fresh worker, takes
3010
+ * `user_goal` off every call, even from a tool that declares its own. An
3011
+ * `McpServer` does not read it. */
3012
+ tools?: readonly unknown[] | (() => readonly unknown[]);
3001
3013
  }
3002
3014
 
3003
3015
  /**
@@ -3068,9 +3080,9 @@ declare class BatonHandle {
3068
3080
  * a `user_goal` intent param on every wrapped tool's schema (SPEC §11.4.1
3069
3081
  * `call_intent`/`intent_source`), and captures a `surface_snapshot`
3070
3082
  * 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).
3083
+ * configured scrubber, which defaults to the shipped ruleset (`src/scrub.ts`).
3084
+ * On a low-level `Server`, which has no tool registry, the same is done at its
3085
+ * `tools/list` and `tools/call` handlers: see `installLowLevelToolSeams`.
3074
3086
  *
3075
3087
  * Interception mechanism: `McpServer` has no middleware API (unlike the
3076
3088
  * standalone `fastmcp` library's `Middleware`/`CallNext`), so this patches
@@ -3127,12 +3139,19 @@ interface SupportedMcpServer {
3127
3139
  readonly server: unknown;
3128
3140
  registerTool(name: string, ...rest: unknown[]): unknown;
3129
3141
  }
3130
- /** Install Baton into an `McpServer`. See module docstring for usage. */
3131
- declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
3142
+ /** The official SDK's low-level `Server`, 1.x or v2, on which the vendor sets
3143
+ * its own `tools/list` and `tools/call` handlers. */
3144
+ interface SupportedLowLevelServer {
3145
+ setRequestHandler(method: unknown, ...rest: unknown[]): unknown;
3146
+ }
3147
+ type SupportedServer = SupportedMcpServer | SupportedLowLevelServer;
3148
+ /** Install Baton into an `McpServer` or a low-level `Server`. See module
3149
+ * docstring for usage. */
3150
+ declare function withBaton(server: SupportedServer, supplied?: BatonConfig): BatonHandle;
3132
3151
  /** One Baton for a process that builds a new `McpServer` for every request.
3133
3152
  * Owns the sink, so a request has nothing to close. */
3134
3153
  interface Baton {
3135
- wrap(server: SupportedMcpServer): void;
3154
+ wrap(server: SupportedServer): void;
3136
3155
  flush(): Promise<void>;
3137
3156
  aclose(): Promise<void>;
3138
3157
  }
@@ -3370,4 +3389,4 @@ interface IntentParam {
3370
3389
  }
3371
3390
  declare const INTENT_PARAMS: readonly IntentParam[];
3372
3391
 
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 };
3392
+ 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.0";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -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,8 +2545,12 @@ 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. */
@@ -2998,6 +3003,13 @@ interface BatonConfig {
2998
3003
  * what a page shows. A vendor who must not send real identities hashes
2999
3004
  * inside the hook and returns `form: "hashed"`. */
3000
3005
  resolvePrincipal?: ResolvePrincipalHook;
3006
+ /** A low-level `Server`'s tools, as its `tools/list` answers them, or a
3007
+ * function that returns them. Read once per `withBaton` or `createBaton`.
3008
+ * Without it Baton learns the tools from the lists its servers serve, so a
3009
+ * process that has served none yet, such as a fresh worker, takes
3010
+ * `user_goal` off every call, even from a tool that declares its own. An
3011
+ * `McpServer` does not read it. */
3012
+ tools?: readonly unknown[] | (() => readonly unknown[]);
3001
3013
  }
3002
3014
 
3003
3015
  /**
@@ -3068,9 +3080,9 @@ declare class BatonHandle {
3068
3080
  * a `user_goal` intent param on every wrapped tool's schema (SPEC §11.4.1
3069
3081
  * `call_intent`/`intent_source`), and captures a `surface_snapshot`
3070
3082
  * 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).
3083
+ * configured scrubber, which defaults to the shipped ruleset (`src/scrub.ts`).
3084
+ * On a low-level `Server`, which has no tool registry, the same is done at its
3085
+ * `tools/list` and `tools/call` handlers: see `installLowLevelToolSeams`.
3074
3086
  *
3075
3087
  * Interception mechanism: `McpServer` has no middleware API (unlike the
3076
3088
  * standalone `fastmcp` library's `Middleware`/`CallNext`), so this patches
@@ -3127,12 +3139,19 @@ interface SupportedMcpServer {
3127
3139
  readonly server: unknown;
3128
3140
  registerTool(name: string, ...rest: unknown[]): unknown;
3129
3141
  }
3130
- /** Install Baton into an `McpServer`. See module docstring for usage. */
3131
- declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
3142
+ /** The official SDK's low-level `Server`, 1.x or v2, on which the vendor sets
3143
+ * its own `tools/list` and `tools/call` handlers. */
3144
+ interface SupportedLowLevelServer {
3145
+ setRequestHandler(method: unknown, ...rest: unknown[]): unknown;
3146
+ }
3147
+ type SupportedServer = SupportedMcpServer | SupportedLowLevelServer;
3148
+ /** Install Baton into an `McpServer` or a low-level `Server`. See module
3149
+ * docstring for usage. */
3150
+ declare function withBaton(server: SupportedServer, supplied?: BatonConfig): BatonHandle;
3132
3151
  /** One Baton for a process that builds a new `McpServer` for every request.
3133
3152
  * Owns the sink, so a request has nothing to close. */
3134
3153
  interface Baton {
3135
- wrap(server: SupportedMcpServer): void;
3154
+ wrap(server: SupportedServer): void;
3136
3155
  flush(): Promise<void>;
3137
3156
  aclose(): Promise<void>;
3138
3157
  }
@@ -3370,4 +3389,4 @@ interface IntentParam {
3370
3389
  }
3371
3390
  declare const INTENT_PARAMS: readonly IntentParam[];
3372
3391
 
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 };
3392
+ 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 };