@goodtiming/baton-sdk 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +118 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -16
- package/dist/index.d.ts +12 -16
- package/dist/index.js +118 -43
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
declare const SDK_VERSION = "ts-0.3.
|
|
3
|
+
declare const SDK_VERSION = "ts-0.3.2";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -124,6 +124,7 @@ declare const ToolCallStartEventSchema: z.ZodObject<{
|
|
|
124
124
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
125
125
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
126
126
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
127
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
127
128
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
128
129
|
}, z.core.$strict>;
|
|
129
130
|
type ToolCallStartEvent = z.infer<typeof ToolCallStartEventSchema>;
|
|
@@ -144,6 +145,7 @@ declare const ToolCallEndEventSchema: z.ZodObject<{
|
|
|
144
145
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
145
146
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
146
147
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
148
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
147
149
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
148
150
|
}, z.core.$strict>;
|
|
149
151
|
type ToolCallEndEvent = z.infer<typeof ToolCallEndEventSchema>;
|
|
@@ -165,6 +167,7 @@ declare const ToolCallErrorEventSchema: z.ZodObject<{
|
|
|
165
167
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
166
168
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
167
169
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
170
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
168
171
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
169
172
|
}, z.core.$strict>;
|
|
170
173
|
type ToolCallErrorEvent = z.infer<typeof ToolCallErrorEventSchema>;
|
|
@@ -190,6 +193,7 @@ declare const AnnotationEventSchema: z.ZodObject<{
|
|
|
190
193
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
191
194
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
192
195
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
196
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
193
197
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
194
198
|
}, z.core.$strict>;
|
|
195
199
|
type AnnotationEvent = z.infer<typeof AnnotationEventSchema>;
|
|
@@ -213,6 +217,7 @@ declare const SurfaceSnapshotEventSchema: z.ZodObject<{
|
|
|
213
217
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
214
218
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
215
219
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
220
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
216
221
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
217
222
|
}, z.core.$strict>;
|
|
218
223
|
type SurfaceSnapshotEvent = z.infer<typeof SurfaceSnapshotEventSchema>;
|
|
@@ -236,6 +241,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
236
241
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
237
242
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
238
243
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
244
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
239
245
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
240
246
|
}, z.core.$strict>, z.ZodObject<{
|
|
241
247
|
event_type: z.ZodDefault<z.ZodLiteral<"tool_call_end">>;
|
|
@@ -254,6 +260,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
254
260
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
255
261
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
256
262
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
263
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
257
264
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
258
265
|
}, z.core.$strict>, z.ZodObject<{
|
|
259
266
|
event_type: z.ZodDefault<z.ZodLiteral<"tool_call_error">>;
|
|
@@ -273,6 +280,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
273
280
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
274
281
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
275
282
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
283
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
276
284
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
277
285
|
}, z.core.$strict>, z.ZodObject<{
|
|
278
286
|
event_type: z.ZodDefault<z.ZodLiteral<"annotation">>;
|
|
@@ -296,6 +304,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
296
304
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
297
305
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
298
306
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
307
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
299
308
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
300
309
|
}, z.core.$strict>, z.ZodObject<{
|
|
301
310
|
event_type: z.ZodDefault<z.ZodLiteral<"surface_snapshot">>;
|
|
@@ -317,6 +326,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
317
326
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
318
327
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
319
328
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
329
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
320
330
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
321
331
|
}, z.core.$strict>], "event_type">;
|
|
322
332
|
type Event = ToolCallStartEvent | ToolCallEndEvent | ToolCallErrorEvent | AnnotationEvent | SurfaceSnapshotEvent;
|
|
@@ -536,15 +546,6 @@ declare class HttpSink implements Sink {
|
|
|
536
546
|
* mirror of `baton` (Python)'s `integrations/_config.py::VendorConfig`.
|
|
537
547
|
*/
|
|
538
548
|
|
|
539
|
-
/** Normalized input to `BatonConfig.resolveSessionId`. Deliberately doesn't
|
|
540
|
-
* carry the raw MCP SDK `extra` object — this shape is stable across
|
|
541
|
-
* whatever the TS MCP ecosystem does with its request-handler signature. */
|
|
542
|
-
interface SessionResolutionContext {
|
|
543
|
-
meta: Record<string, unknown> | null;
|
|
544
|
-
toolName: string;
|
|
545
|
-
arguments: Record<string, unknown>;
|
|
546
|
-
}
|
|
547
|
-
type ResolveSessionIdHook = (context: SessionResolutionContext) => string | null | undefined | Promise<string | null | undefined>;
|
|
548
549
|
interface BatonConfig {
|
|
549
550
|
/** The packed connection string from /account — one value carrying the
|
|
550
551
|
* ingest host, the workspace, the server and the key that binds them.
|
|
@@ -616,8 +617,6 @@ interface BatonConfig {
|
|
|
616
617
|
consentToken?: string;
|
|
617
618
|
/** Where events go. Defaults to `new StdoutSink()` — zero-config dev mode. */
|
|
618
619
|
sink?: Sink;
|
|
619
|
-
/** Default `agent_runtime` when `_meta` heuristics can't detect one. */
|
|
620
|
-
defaultAgentRuntime?: string;
|
|
621
620
|
/** PII scrubber per SPEC §7, applied to tool params/results, `_meta`,
|
|
622
621
|
* intent strings and error bodies before they reach the sink. Defaults to
|
|
623
622
|
* the shipped default ruleset (`new Scrubber().scrub` — email, bearer,
|
|
@@ -626,9 +625,6 @@ interface BatonConfig {
|
|
|
626
625
|
* so untouched integrations get scrubbing without the operator opting in.
|
|
627
626
|
* Pass `identityScrub` to explicitly opt out, or supply your own. */
|
|
628
627
|
scrubber?: (value: unknown) => unknown;
|
|
629
|
-
/** Optional vendor-supplied session-id resolver, checked BEFORE
|
|
630
|
-
* `extra.sessionId` — mirrors Python's `resolve_session_id` rung 0. */
|
|
631
|
-
resolveSessionId?: ResolveSessionIdHook;
|
|
632
628
|
/** Optional override for the annotation tool name. Default is
|
|
633
629
|
* `{vendorId}_annotate`. */
|
|
634
630
|
annotationToolName?: string;
|
|
@@ -766,4 +762,4 @@ interface SupportedMcpServer {
|
|
|
766
762
|
/** Install Baton into an `McpServer`. See module docstring for usage. */
|
|
767
763
|
declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
|
|
768
764
|
|
|
769
|
-
export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type BatonConfig, BatonHandle, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions,
|
|
765
|
+
export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type BatonConfig, BatonHandle, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions, 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, identityScrub, safeWrite, withBaton };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
|
-
declare const SDK_VERSION = "ts-0.3.
|
|
3
|
+
declare const SDK_VERSION = "ts-0.3.2";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -124,6 +124,7 @@ declare const ToolCallStartEventSchema: z.ZodObject<{
|
|
|
124
124
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
125
125
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
126
126
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
127
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
127
128
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
128
129
|
}, z.core.$strict>;
|
|
129
130
|
type ToolCallStartEvent = z.infer<typeof ToolCallStartEventSchema>;
|
|
@@ -144,6 +145,7 @@ declare const ToolCallEndEventSchema: z.ZodObject<{
|
|
|
144
145
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
145
146
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
146
147
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
148
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
147
149
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
148
150
|
}, z.core.$strict>;
|
|
149
151
|
type ToolCallEndEvent = z.infer<typeof ToolCallEndEventSchema>;
|
|
@@ -165,6 +167,7 @@ declare const ToolCallErrorEventSchema: z.ZodObject<{
|
|
|
165
167
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
166
168
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
167
169
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
170
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
168
171
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
169
172
|
}, z.core.$strict>;
|
|
170
173
|
type ToolCallErrorEvent = z.infer<typeof ToolCallErrorEventSchema>;
|
|
@@ -190,6 +193,7 @@ declare const AnnotationEventSchema: z.ZodObject<{
|
|
|
190
193
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
191
194
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
192
195
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
196
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
193
197
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
194
198
|
}, z.core.$strict>;
|
|
195
199
|
type AnnotationEvent = z.infer<typeof AnnotationEventSchema>;
|
|
@@ -213,6 +217,7 @@ declare const SurfaceSnapshotEventSchema: z.ZodObject<{
|
|
|
213
217
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
214
218
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
215
219
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
220
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
216
221
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
217
222
|
}, z.core.$strict>;
|
|
218
223
|
type SurfaceSnapshotEvent = z.infer<typeof SurfaceSnapshotEventSchema>;
|
|
@@ -236,6 +241,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
236
241
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
237
242
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
238
243
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
244
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
239
245
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
240
246
|
}, z.core.$strict>, z.ZodObject<{
|
|
241
247
|
event_type: z.ZodDefault<z.ZodLiteral<"tool_call_end">>;
|
|
@@ -254,6 +260,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
254
260
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
255
261
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
256
262
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
263
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
257
264
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
258
265
|
}, z.core.$strict>, z.ZodObject<{
|
|
259
266
|
event_type: z.ZodDefault<z.ZodLiteral<"tool_call_error">>;
|
|
@@ -273,6 +280,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
273
280
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
274
281
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
275
282
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
283
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
276
284
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
277
285
|
}, z.core.$strict>, z.ZodObject<{
|
|
278
286
|
event_type: z.ZodDefault<z.ZodLiteral<"annotation">>;
|
|
@@ -296,6 +304,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
296
304
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
297
305
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
298
306
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
307
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
299
308
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
300
309
|
}, z.core.$strict>, z.ZodObject<{
|
|
301
310
|
event_type: z.ZodDefault<z.ZodLiteral<"surface_snapshot">>;
|
|
@@ -317,6 +326,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
317
326
|
sdk_version: z.ZodDefault<z.ZodString>;
|
|
318
327
|
agent_runtime: z.ZodDefault<z.ZodString>;
|
|
319
328
|
user_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
329
|
+
call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
320
330
|
runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
321
331
|
}, z.core.$strict>], "event_type">;
|
|
322
332
|
type Event = ToolCallStartEvent | ToolCallEndEvent | ToolCallErrorEvent | AnnotationEvent | SurfaceSnapshotEvent;
|
|
@@ -536,15 +546,6 @@ declare class HttpSink implements Sink {
|
|
|
536
546
|
* mirror of `baton` (Python)'s `integrations/_config.py::VendorConfig`.
|
|
537
547
|
*/
|
|
538
548
|
|
|
539
|
-
/** Normalized input to `BatonConfig.resolveSessionId`. Deliberately doesn't
|
|
540
|
-
* carry the raw MCP SDK `extra` object — this shape is stable across
|
|
541
|
-
* whatever the TS MCP ecosystem does with its request-handler signature. */
|
|
542
|
-
interface SessionResolutionContext {
|
|
543
|
-
meta: Record<string, unknown> | null;
|
|
544
|
-
toolName: string;
|
|
545
|
-
arguments: Record<string, unknown>;
|
|
546
|
-
}
|
|
547
|
-
type ResolveSessionIdHook = (context: SessionResolutionContext) => string | null | undefined | Promise<string | null | undefined>;
|
|
548
549
|
interface BatonConfig {
|
|
549
550
|
/** The packed connection string from /account — one value carrying the
|
|
550
551
|
* ingest host, the workspace, the server and the key that binds them.
|
|
@@ -616,8 +617,6 @@ interface BatonConfig {
|
|
|
616
617
|
consentToken?: string;
|
|
617
618
|
/** Where events go. Defaults to `new StdoutSink()` — zero-config dev mode. */
|
|
618
619
|
sink?: Sink;
|
|
619
|
-
/** Default `agent_runtime` when `_meta` heuristics can't detect one. */
|
|
620
|
-
defaultAgentRuntime?: string;
|
|
621
620
|
/** PII scrubber per SPEC §7, applied to tool params/results, `_meta`,
|
|
622
621
|
* intent strings and error bodies before they reach the sink. Defaults to
|
|
623
622
|
* the shipped default ruleset (`new Scrubber().scrub` — email, bearer,
|
|
@@ -626,9 +625,6 @@ interface BatonConfig {
|
|
|
626
625
|
* so untouched integrations get scrubbing without the operator opting in.
|
|
627
626
|
* Pass `identityScrub` to explicitly opt out, or supply your own. */
|
|
628
627
|
scrubber?: (value: unknown) => unknown;
|
|
629
|
-
/** Optional vendor-supplied session-id resolver, checked BEFORE
|
|
630
|
-
* `extra.sessionId` — mirrors Python's `resolve_session_id` rung 0. */
|
|
631
|
-
resolveSessionId?: ResolveSessionIdHook;
|
|
632
628
|
/** Optional override for the annotation tool name. Default is
|
|
633
629
|
* `{vendorId}_annotate`. */
|
|
634
630
|
annotationToolName?: string;
|
|
@@ -766,4 +762,4 @@ interface SupportedMcpServer {
|
|
|
766
762
|
/** Install Baton into an `McpServer`. See module docstring for usage. */
|
|
767
763
|
declare function withBaton(server: SupportedMcpServer, supplied?: BatonConfig): BatonHandle;
|
|
768
764
|
|
|
769
|
-
export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type BatonConfig, BatonHandle, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions,
|
|
765
|
+
export { type AnnotationEvent, AnnotationEventSchema, type AnnotationPayload, AnnotationPayloadSchema, type BatonConfig, BatonHandle, DEFAULT_CONSENT_TOKEN, DEPTH_LIMIT, type Event, EventSchema, type EventType, EventTypeSchema, HttpSink, type HttpSinkOptions, 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, identityScrub, safeWrite, withBaton };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var SDK_VERSION = "ts-0.3.
|
|
2
|
+
var SDK_VERSION = "ts-0.3.2";
|
|
3
3
|
|
|
4
4
|
// src/events.ts
|
|
5
5
|
import { z } from "zod";
|
|
@@ -53,6 +53,7 @@ var envelopeShape = {
|
|
|
53
53
|
sdk_version: z.string().default(SDK_VERSION),
|
|
54
54
|
agent_runtime: z.string().default("unknown"),
|
|
55
55
|
user_id: z.string().nullable().default(null),
|
|
56
|
+
call_id: z.string().nullable().default(null),
|
|
56
57
|
runtime_meta: z.record(z.string(), z.unknown()).nullable().default(null)
|
|
57
58
|
};
|
|
58
59
|
var EventTypeSchema = z.enum([
|
|
@@ -473,25 +474,65 @@ function extraMeta(extra) {
|
|
|
473
474
|
const nested = extra.mcpReq?._meta;
|
|
474
475
|
return nested ?? null;
|
|
475
476
|
}
|
|
477
|
+
function extraEnvelope(extra) {
|
|
478
|
+
const envelope = extra.mcpReq?.envelope;
|
|
479
|
+
return envelope ?? null;
|
|
480
|
+
}
|
|
476
481
|
|
|
477
482
|
// src/integrations/mcp/runtimeAdapter.ts
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
483
|
+
var CLIENT_INFO_META_KEY = "io.modelcontextprotocol/clientInfo";
|
|
484
|
+
var CLIENT_NAME_MAX_LEN = 128;
|
|
485
|
+
var UNKNOWN_AGENT_RUNTIME = "unknown";
|
|
486
|
+
function clean(name, scrubber) {
|
|
487
|
+
if (typeof name !== "string" || !name) return null;
|
|
488
|
+
let cleaned = name;
|
|
489
|
+
if (scrubber) {
|
|
490
|
+
const scrubbed = scrubber(cleaned);
|
|
491
|
+
if (typeof scrubbed !== "string") return null;
|
|
492
|
+
cleaned = scrubbed;
|
|
493
|
+
}
|
|
494
|
+
if (!cleaned) return null;
|
|
495
|
+
return [...cleaned].slice(0, CLIENT_NAME_MAX_LEN).join("");
|
|
496
|
+
}
|
|
497
|
+
function declaredOnRequest(meta, envelope) {
|
|
498
|
+
for (const source of [envelope, meta]) {
|
|
499
|
+
if (!source) continue;
|
|
500
|
+
const info = source[CLIENT_INFO_META_KEY];
|
|
501
|
+
if (info && typeof info === "object") {
|
|
502
|
+
const name = info.name;
|
|
503
|
+
if (name !== void 0) return name;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return void 0;
|
|
507
|
+
}
|
|
508
|
+
function declaredOnConnection(options) {
|
|
509
|
+
try {
|
|
510
|
+
const server = options.server;
|
|
511
|
+
if (!server) return void 0;
|
|
512
|
+
const inner = server.server;
|
|
513
|
+
const holder = inner ?? server;
|
|
514
|
+
if (typeof holder.getClientVersion !== "function") return void 0;
|
|
515
|
+
return holder.getClientVersion()?.name;
|
|
516
|
+
} catch {
|
|
517
|
+
return void 0;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function detectAgentRuntime(meta, options = {}) {
|
|
521
|
+
const { envelope, scrubber } = options;
|
|
522
|
+
const onRequest = clean(declaredOnRequest(meta, envelope), scrubber);
|
|
523
|
+
if (onRequest !== null) return onRequest;
|
|
524
|
+
const onConnection = clean(declaredOnConnection(options), scrubber);
|
|
525
|
+
if (onConnection !== null) return onConnection;
|
|
526
|
+
if (meta) {
|
|
527
|
+
for (const key of Object.keys(meta)) {
|
|
528
|
+
if (key.startsWith("claudecode/")) return "claude-code";
|
|
529
|
+
}
|
|
482
530
|
}
|
|
483
531
|
return null;
|
|
484
532
|
}
|
|
485
533
|
|
|
486
534
|
// src/integrations/mcp/sessionResolution.ts
|
|
487
|
-
async function resolveSessionId(
|
|
488
|
-
if (hook) {
|
|
489
|
-
try {
|
|
490
|
-
const hookResult = await hook({ meta, toolName, arguments: args });
|
|
491
|
-
if (typeof hookResult === "string" && hookResult) return hookResult;
|
|
492
|
-
} catch {
|
|
493
|
-
}
|
|
494
|
-
}
|
|
535
|
+
async function resolveSessionId(fallbackSessionId, extra) {
|
|
495
536
|
if (typeof extra.sessionId === "string" && extra.sessionId) return extra.sessionId;
|
|
496
537
|
return fallbackSessionId;
|
|
497
538
|
}
|
|
@@ -527,16 +568,13 @@ function registerAnnotationTool(server, options) {
|
|
|
527
568
|
},
|
|
528
569
|
async (args, extra) => {
|
|
529
570
|
const meta = extraMeta(extra);
|
|
530
|
-
const runtime = detectAgentRuntime(meta
|
|
571
|
+
const runtime = detectAgentRuntime(meta, {
|
|
572
|
+
envelope: extraEnvelope(extra),
|
|
573
|
+
server,
|
|
574
|
+
scrubber: options.scrubber
|
|
575
|
+
}) ?? UNKNOWN_AGENT_RUNTIME;
|
|
531
576
|
const scrubbedMeta = meta ? options.scrubber(meta) : null;
|
|
532
|
-
const sessionId = await resolveSessionId(
|
|
533
|
-
options.resolveSessionId,
|
|
534
|
-
options.fallbackSessionId,
|
|
535
|
-
extra,
|
|
536
|
-
meta,
|
|
537
|
-
name,
|
|
538
|
-
args
|
|
539
|
-
);
|
|
577
|
+
const sessionId = await resolveSessionId(options.fallbackSessionId, extra);
|
|
540
578
|
if (args.signal_type === void 0) {
|
|
541
579
|
options.tracker?.mark(sessionId);
|
|
542
580
|
}
|
|
@@ -583,7 +621,7 @@ function registerAnnotationTool(server, options) {
|
|
|
583
621
|
|
|
584
622
|
// src/dsn.ts
|
|
585
623
|
var VENDOR_ID_PATTERN = /^[a-zA-Z0-9_-]{1,48}$/;
|
|
586
|
-
var WORKSPACE_PATTERN = /^ten_[0-9a-fA-F]{32}$/;
|
|
624
|
+
var WORKSPACE_PATTERN = /^ten_(?:[0-9a-fA-F]{8}|[0-9a-fA-F]{32})$/;
|
|
587
625
|
var NOT_IN_A_HOST = /[\\\s\x00-\x1f\x7f]/;
|
|
588
626
|
var NOT_IN_A_KEY = /[\x00\n\r]/;
|
|
589
627
|
var PUBLISHABLE_PREFIX = "baton_pk_";
|
|
@@ -624,7 +662,11 @@ function splitDsn(raw) {
|
|
|
624
662
|
function splitKeyFromAuthority(netloc) {
|
|
625
663
|
const index = netloc.lastIndexOf("@");
|
|
626
664
|
if (index === -1) return { key: "", at: false, authority: netloc };
|
|
627
|
-
return {
|
|
665
|
+
return {
|
|
666
|
+
key: netloc.slice(0, index),
|
|
667
|
+
at: true,
|
|
668
|
+
authority: netloc.slice(index + 1)
|
|
669
|
+
};
|
|
628
670
|
}
|
|
629
671
|
function redact(raw) {
|
|
630
672
|
const parts = splitDsn(raw);
|
|
@@ -704,6 +746,11 @@ function parseDsn(raw) {
|
|
|
704
746
|
if (!authority) {
|
|
705
747
|
fail(`dsn ${safe} has no host`);
|
|
706
748
|
}
|
|
749
|
+
if (containsKey(authority)) {
|
|
750
|
+
fail(
|
|
751
|
+
`dsn ${safe} has the KEY where the host belongs. The order is key, @, host \u2014 check whether the two are the wrong way round: https://baton_pk_...@host/ten_.../<server>`
|
|
752
|
+
);
|
|
753
|
+
}
|
|
707
754
|
if (NOT_IN_A_HOST.test(authority)) {
|
|
708
755
|
fail(
|
|
709
756
|
`dsn ${safe} has whitespace, a control character or a backslash inside its host. Those are silently REMOVED or reinterpreted when a URL is parsed, so the address dialled would not be the one you wrote \u2014 check for a line wrap or a stray space where the value was copied.`
|
|
@@ -723,7 +770,7 @@ function parseDsn(raw) {
|
|
|
723
770
|
const [workspace, server, ...extra] = segments;
|
|
724
771
|
if (workspace === void 0 || server === void 0 || extra.length > 0) {
|
|
725
772
|
fail(
|
|
726
|
-
`dsn ${safe} must carry exactly two path segments \u2014 the workspace and the server, as in /ten_
|
|
773
|
+
`dsn ${safe} must carry exactly two path segments \u2014 the workspace and the server, as in /ten_.../<server>. A missing server is never defaulted: it is what the key is bound to.`
|
|
727
774
|
);
|
|
728
775
|
}
|
|
729
776
|
for (const [slot, segment] of [
|
|
@@ -732,13 +779,13 @@ function parseDsn(raw) {
|
|
|
732
779
|
]) {
|
|
733
780
|
if (containsKey(segment)) {
|
|
734
781
|
fail(
|
|
735
|
-
`dsn ${safe} has a KEY in the ${slot} slot. The key goes before the @, and the path carries the workspace and the server: https://baton_pk_...@host/ten_
|
|
782
|
+
`dsn ${safe} has a KEY in the ${slot} slot. The key goes before the @, and the path carries the workspace and the server: https://baton_pk_...@host/ten_.../<server>`
|
|
736
783
|
);
|
|
737
784
|
}
|
|
738
785
|
}
|
|
739
786
|
if (!WORKSPACE_PATTERN.test(workspace)) {
|
|
740
787
|
fail(
|
|
741
|
-
`dsn ${safe} has ${JSON.stringify(workspace)} where the workspace belongs \u2014 expected ten_ followed by 32 hex characters. If the two path segments are the right way round, this is not a Baton DSN.`
|
|
788
|
+
`dsn ${safe} has ${JSON.stringify(workspace)} where the workspace belongs \u2014 expected ten_ followed by 8 or 32 hex characters. If the two path segments are the right way round, this is not a Baton DSN.`
|
|
742
789
|
);
|
|
743
790
|
}
|
|
744
791
|
if (!VENDOR_ID_PATTERN.test(server)) {
|
|
@@ -759,8 +806,16 @@ function parseDsn(raw) {
|
|
|
759
806
|
});
|
|
760
807
|
}
|
|
761
808
|
function sealKey(dsn) {
|
|
762
|
-
const shown = {
|
|
763
|
-
|
|
809
|
+
const shown = {
|
|
810
|
+
origin: dsn.origin,
|
|
811
|
+
tenantId: dsn.tenantId,
|
|
812
|
+
vendorId: dsn.vendorId,
|
|
813
|
+
key: "<key>"
|
|
814
|
+
};
|
|
815
|
+
Object.defineProperty(dsn, "toJSON", {
|
|
816
|
+
value: () => shown,
|
|
817
|
+
enumerable: false
|
|
818
|
+
});
|
|
764
819
|
Object.defineProperty(dsn, /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom"), {
|
|
765
820
|
value: () => shown,
|
|
766
821
|
enumerable: false
|
|
@@ -1183,16 +1238,18 @@ function batonWrap(nameRef, original, ctx) {
|
|
|
1183
1238
|
const extra = callArgs[callArgs.length - 1];
|
|
1184
1239
|
const params = (callArgs.length > 1 ? callArgs[0] : void 0) ?? {};
|
|
1185
1240
|
const meta = extraMeta(extra);
|
|
1186
|
-
const runtime = detectAgentRuntime(meta
|
|
1241
|
+
const runtime = detectAgentRuntime(meta, {
|
|
1242
|
+
// v2 lifts the reserved `io.modelcontextprotocol/*` keys out of
|
|
1243
|
+
// `_meta`; 1.x leaves them in. Both are handed over — see
|
|
1244
|
+
// `mcpTypes.extraEnvelope`.
|
|
1245
|
+
envelope: extraEnvelope(extra),
|
|
1246
|
+
// Tier 2's carrier: neither peer puts client identity on the
|
|
1247
|
+
// handler context, both expose the cached handshake on the server.
|
|
1248
|
+
server: ctx.server,
|
|
1249
|
+
scrubber: ctx.scrubber
|
|
1250
|
+
}) ?? UNKNOWN_AGENT_RUNTIME;
|
|
1187
1251
|
const scrubbedMeta = meta ? ctx.scrubber(meta) : null;
|
|
1188
|
-
const sessionId = await resolveSessionId(
|
|
1189
|
-
ctx.resolveSessionId,
|
|
1190
|
-
ctx.fallbackSessionId,
|
|
1191
|
-
extra,
|
|
1192
|
-
meta,
|
|
1193
|
-
toolName,
|
|
1194
|
-
params
|
|
1195
|
-
);
|
|
1252
|
+
const sessionId = await resolveSessionId(ctx.fallbackSessionId, extra);
|
|
1196
1253
|
const dispositions = ctx.paramRegistry.get(toolName);
|
|
1197
1254
|
const rawIntent = extractGoalParam(params, USER_GOAL_PARAM_NAME, toolName, dispositions);
|
|
1198
1255
|
const rawExpected = extractGoalParam(
|
|
@@ -1205,6 +1262,7 @@ function batonWrap(nameRef, original, ctx) {
|
|
|
1205
1262
|
const scrubbedIntent = rawIntent !== null ? ctx.scrubber(rawIntent) : null;
|
|
1206
1263
|
const scrubbedExpected = rawExpected !== null ? ctx.scrubber(rawExpected) : null;
|
|
1207
1264
|
const scrubbedWorkflow = rawWorkflow !== null ? ctx.scrubber(rawWorkflow) : null;
|
|
1265
|
+
const callId = uuidv72();
|
|
1208
1266
|
const common = {
|
|
1209
1267
|
tenant_id: ctx.tenantId,
|
|
1210
1268
|
vendor_id: ctx.vendorId,
|
|
@@ -1233,6 +1291,7 @@ function batonWrap(nameRef, original, ctx) {
|
|
|
1233
1291
|
ctx.sink,
|
|
1234
1292
|
() => ToolCallStartEventSchema.parse({
|
|
1235
1293
|
...common,
|
|
1294
|
+
call_id: callId,
|
|
1236
1295
|
sequence_number: ctx.counter.next(sessionId),
|
|
1237
1296
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1238
1297
|
payload: {
|
|
@@ -1256,6 +1315,7 @@ function batonWrap(nameRef, original, ctx) {
|
|
|
1256
1315
|
ctx.sink,
|
|
1257
1316
|
() => ToolCallErrorEventSchema.parse({
|
|
1258
1317
|
...common,
|
|
1318
|
+
call_id: callId,
|
|
1259
1319
|
sequence_number: ctx.counter.next(sessionId),
|
|
1260
1320
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1261
1321
|
payload: {
|
|
@@ -1273,6 +1333,7 @@ function batonWrap(nameRef, original, ctx) {
|
|
|
1273
1333
|
ctx.sink,
|
|
1274
1334
|
() => ToolCallEndEventSchema.parse({
|
|
1275
1335
|
...common,
|
|
1336
|
+
call_id: callId,
|
|
1276
1337
|
sequence_number: ctx.counter.next(sessionId),
|
|
1277
1338
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1278
1339
|
payload: { tool_name: toolName, result: ctx.scrubber(result), duration_ms: durationMs }
|
|
@@ -1442,7 +1503,24 @@ function withBaton(server, supplied = {}) {
|
|
|
1442
1503
|
consent_token: config.consentToken,
|
|
1443
1504
|
sequence_number: counter.next(sessionId),
|
|
1444
1505
|
captured_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1445
|
-
|
|
1506
|
+
// Deliberately the literal, NOT the ladder — and an earlier comment
|
|
1507
|
+
// here justified that by saying no call is in scope, which is false:
|
|
1508
|
+
// `maybeEmitSurfaceSnapshot` is the first line of `batonWrap`, so the
|
|
1509
|
+
// handshake has happened and tier 2's carrier is live in this closure.
|
|
1510
|
+
// The real reason is that the snapshot describes the VENDOR'S SURFACE,
|
|
1511
|
+
// which is the same whoever is calling. It is hashed and emitted at
|
|
1512
|
+
// most once per process per surface, so the client that happens to
|
|
1513
|
+
// trigger it is whichever one called first — attributing the surface to
|
|
1514
|
+
// that client would read as a fact about the surface and be an accident
|
|
1515
|
+
// of timing. Python hardcodes it from the same in-call position
|
|
1516
|
+
// (`_tool_wrap.py`), so this is parity, not a gap.
|
|
1517
|
+
//
|
|
1518
|
+
// ⚠ Consequence worth knowing: one session emits `surface_snapshot`
|
|
1519
|
+
// with `unknown` and everything else with the client's name, so a
|
|
1520
|
+
// consumer grouping on `agent_runtime` alone sees two runtimes for one
|
|
1521
|
+
// client. Intended; group surfaces on `(tenant_id, vendor_id,
|
|
1522
|
+
// surface_hash)`, which is what the Console's table is keyed on.
|
|
1523
|
+
agent_runtime: UNKNOWN_AGENT_RUNTIME,
|
|
1446
1524
|
payload: {
|
|
1447
1525
|
surface_hash: digest,
|
|
1448
1526
|
server_info: snapshot.server_info,
|
|
@@ -1488,9 +1566,8 @@ function withBaton(server, supplied = {}) {
|
|
|
1488
1566
|
vendorId: config.vendorId,
|
|
1489
1567
|
consentToken: config.consentToken,
|
|
1490
1568
|
fallbackSessionId,
|
|
1491
|
-
|
|
1569
|
+
server,
|
|
1492
1570
|
scrubber,
|
|
1493
|
-
resolveSessionId: config.resolveSessionId,
|
|
1494
1571
|
annotationToolName,
|
|
1495
1572
|
intentParamMode,
|
|
1496
1573
|
paramRegistry: /* @__PURE__ */ new Map(),
|
|
@@ -1513,9 +1590,7 @@ function withBaton(server, supplied = {}) {
|
|
|
1513
1590
|
vendorDisplayName: config.vendorDisplayName,
|
|
1514
1591
|
consentToken: ctx.consentToken,
|
|
1515
1592
|
fallbackSessionId: ctx.fallbackSessionId,
|
|
1516
|
-
defaultAgentRuntime: ctx.defaultAgentRuntime,
|
|
1517
1593
|
scrubber: ctx.scrubber,
|
|
1518
|
-
resolveSessionId: ctx.resolveSessionId,
|
|
1519
1594
|
annotationToolName: config.annotationToolName,
|
|
1520
1595
|
tracker
|
|
1521
1596
|
});
|