@goodtiming/baton-sdk 0.3.5 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
 
3
- declare const SDK_VERSION = "ts-0.3.5";
3
+ declare const SDK_VERSION = "ts-0.3.7";
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
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
127
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
127
128
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
128
129
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
129
130
  }, z.core.$strict>;
@@ -145,6 +146,7 @@ declare const ToolCallEndEventSchema: z.ZodObject<{
145
146
  sdk_version: z.ZodDefault<z.ZodString>;
146
147
  agent_runtime: z.ZodDefault<z.ZodString>;
147
148
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
149
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
148
150
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
149
151
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
150
152
  }, z.core.$strict>;
@@ -167,6 +169,7 @@ declare const ToolCallErrorEventSchema: z.ZodObject<{
167
169
  sdk_version: z.ZodDefault<z.ZodString>;
168
170
  agent_runtime: z.ZodDefault<z.ZodString>;
169
171
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
172
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
170
173
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
171
174
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
172
175
  }, z.core.$strict>;
@@ -193,6 +196,7 @@ declare const AnnotationEventSchema: z.ZodObject<{
193
196
  sdk_version: z.ZodDefault<z.ZodString>;
194
197
  agent_runtime: z.ZodDefault<z.ZodString>;
195
198
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
199
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
196
200
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
197
201
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
198
202
  }, z.core.$strict>;
@@ -217,6 +221,7 @@ declare const SurfaceSnapshotEventSchema: z.ZodObject<{
217
221
  sdk_version: z.ZodDefault<z.ZodString>;
218
222
  agent_runtime: z.ZodDefault<z.ZodString>;
219
223
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
224
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
220
225
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
221
226
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
222
227
  }, z.core.$strict>;
@@ -241,6 +246,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
241
246
  sdk_version: z.ZodDefault<z.ZodString>;
242
247
  agent_runtime: z.ZodDefault<z.ZodString>;
243
248
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
249
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
244
250
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
245
251
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
246
252
  }, z.core.$strict>, z.ZodObject<{
@@ -260,6 +266,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
260
266
  sdk_version: z.ZodDefault<z.ZodString>;
261
267
  agent_runtime: z.ZodDefault<z.ZodString>;
262
268
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
269
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
263
270
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
264
271
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
265
272
  }, z.core.$strict>, z.ZodObject<{
@@ -280,6 +287,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
280
287
  sdk_version: z.ZodDefault<z.ZodString>;
281
288
  agent_runtime: z.ZodDefault<z.ZodString>;
282
289
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
290
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
283
291
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
284
292
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
285
293
  }, z.core.$strict>, z.ZodObject<{
@@ -304,6 +312,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
304
312
  sdk_version: z.ZodDefault<z.ZodString>;
305
313
  agent_runtime: z.ZodDefault<z.ZodString>;
306
314
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
315
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
307
316
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
308
317
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
309
318
  }, z.core.$strict>, z.ZodObject<{
@@ -326,6 +335,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
326
335
  sdk_version: z.ZodDefault<z.ZodString>;
327
336
  agent_runtime: z.ZodDefault<z.ZodString>;
328
337
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
338
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
329
339
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
330
340
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
331
341
  }, z.core.$strict>], "event_type">;
@@ -740,10 +750,12 @@ interface BatonConfig {
740
750
  * written into documentation, a prompt or a script. */
741
751
  annotationToolName?: string;
742
752
  /** Per-tool intent-param injection (mirrors baton-extmcp's vendor-neutral
743
- * naming). `"optional"` (default) injects `user_goal`/`expected_result`
744
- * string params on every wrapped tool's advertised schema; `"required"`
745
- * also adds `user_goal` to the schema's required fields (`expected_result`
746
- * stays optional regardless); `"off"` disables injection. Both params are
753
+ * naming). `"required"` (default) injects `user_goal`/`expected_result`/
754
+ * `overall_task` string params on every wrapped tool's advertised schema
755
+ * and ADVERTISES `user_goal` as required in `tools/list`, without enforcing
756
+ * it: a call that omits it still reaches your handler, and its event simply
757
+ * carries no intent. `"optional"` injects the same params and advertises
758
+ * none of them as required. `"off"` disables injection. The params are
747
759
  * stripped before the vendor handler runs, so the tool never sees them.
748
760
  * This is what captures intent on runtimes that drop `instructions`
749
761
  * (notably Claude Desktop) — where the annotation tool alone yields
@@ -845,7 +857,7 @@ declare class BatonHandle {
845
857
  * `intent_source`), and captures a `surface_snapshot`
846
858
  * of the vendor-true surface. Every payload leaving here runs through the
847
859
  * configured scrubber, which defaults to the shipped ruleset (`src/scrub.ts`)
848
- * — see README "What's deferred" for what's still not here (the low-level
860
+ * — see README "What is not here yet" for what's still not here (the low-level
849
861
  * `Server` adapter).
850
862
  *
851
863
  * Interception mechanism: `McpServer` has no middleware API (unlike the
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.5";
3
+ declare const SDK_VERSION = "ts-0.3.7";
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
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
127
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
127
128
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
128
129
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
129
130
  }, z.core.$strict>;
@@ -145,6 +146,7 @@ declare const ToolCallEndEventSchema: z.ZodObject<{
145
146
  sdk_version: z.ZodDefault<z.ZodString>;
146
147
  agent_runtime: z.ZodDefault<z.ZodString>;
147
148
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
149
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
148
150
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
149
151
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
150
152
  }, z.core.$strict>;
@@ -167,6 +169,7 @@ declare const ToolCallErrorEventSchema: z.ZodObject<{
167
169
  sdk_version: z.ZodDefault<z.ZodString>;
168
170
  agent_runtime: z.ZodDefault<z.ZodString>;
169
171
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
172
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
170
173
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
171
174
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
172
175
  }, z.core.$strict>;
@@ -193,6 +196,7 @@ declare const AnnotationEventSchema: z.ZodObject<{
193
196
  sdk_version: z.ZodDefault<z.ZodString>;
194
197
  agent_runtime: z.ZodDefault<z.ZodString>;
195
198
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
199
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
196
200
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
197
201
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
198
202
  }, z.core.$strict>;
@@ -217,6 +221,7 @@ declare const SurfaceSnapshotEventSchema: z.ZodObject<{
217
221
  sdk_version: z.ZodDefault<z.ZodString>;
218
222
  agent_runtime: z.ZodDefault<z.ZodString>;
219
223
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
224
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
220
225
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
221
226
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
222
227
  }, z.core.$strict>;
@@ -241,6 +246,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
241
246
  sdk_version: z.ZodDefault<z.ZodString>;
242
247
  agent_runtime: z.ZodDefault<z.ZodString>;
243
248
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
249
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
244
250
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
245
251
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
246
252
  }, z.core.$strict>, z.ZodObject<{
@@ -260,6 +266,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
260
266
  sdk_version: z.ZodDefault<z.ZodString>;
261
267
  agent_runtime: z.ZodDefault<z.ZodString>;
262
268
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
269
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
263
270
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
264
271
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
265
272
  }, z.core.$strict>, z.ZodObject<{
@@ -280,6 +287,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
280
287
  sdk_version: z.ZodDefault<z.ZodString>;
281
288
  agent_runtime: z.ZodDefault<z.ZodString>;
282
289
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
290
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
283
291
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
284
292
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
285
293
  }, z.core.$strict>, z.ZodObject<{
@@ -304,6 +312,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
304
312
  sdk_version: z.ZodDefault<z.ZodString>;
305
313
  agent_runtime: z.ZodDefault<z.ZodString>;
306
314
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
315
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
307
316
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
308
317
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
309
318
  }, z.core.$strict>, z.ZodObject<{
@@ -326,6 +335,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
326
335
  sdk_version: z.ZodDefault<z.ZodString>;
327
336
  agent_runtime: z.ZodDefault<z.ZodString>;
328
337
  principal_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
338
+ transport_observed: z.ZodDefault<z.ZodNullable<z.ZodString>>;
329
339
  call_id: z.ZodDefault<z.ZodNullable<z.ZodString>>;
330
340
  runtime_meta: z.ZodDefault<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
331
341
  }, z.core.$strict>], "event_type">;
@@ -740,10 +750,12 @@ interface BatonConfig {
740
750
  * written into documentation, a prompt or a script. */
741
751
  annotationToolName?: string;
742
752
  /** Per-tool intent-param injection (mirrors baton-extmcp's vendor-neutral
743
- * naming). `"optional"` (default) injects `user_goal`/`expected_result`
744
- * string params on every wrapped tool's advertised schema; `"required"`
745
- * also adds `user_goal` to the schema's required fields (`expected_result`
746
- * stays optional regardless); `"off"` disables injection. Both params are
753
+ * naming). `"required"` (default) injects `user_goal`/`expected_result`/
754
+ * `overall_task` string params on every wrapped tool's advertised schema
755
+ * and ADVERTISES `user_goal` as required in `tools/list`, without enforcing
756
+ * it: a call that omits it still reaches your handler, and its event simply
757
+ * carries no intent. `"optional"` injects the same params and advertises
758
+ * none of them as required. `"off"` disables injection. The params are
747
759
  * stripped before the vendor handler runs, so the tool never sees them.
748
760
  * This is what captures intent on runtimes that drop `instructions`
749
761
  * (notably Claude Desktop) — where the annotation tool alone yields
@@ -845,7 +857,7 @@ declare class BatonHandle {
845
857
  * `intent_source`), and captures a `surface_snapshot`
846
858
  * of the vendor-true surface. Every payload leaving here runs through the
847
859
  * configured scrubber, which defaults to the shipped ruleset (`src/scrub.ts`)
848
- * — see README "What's deferred" for what's still not here (the low-level
860
+ * — see README "What is not here yet" for what's still not here (the low-level
849
861
  * `Server` adapter).
850
862
  *
851
863
  * Interception mechanism: `McpServer` has no middleware API (unlike the
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SDK_VERSION = "ts-0.3.5";
2
+ var SDK_VERSION = "ts-0.3.7";
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
  principal_id: z.string().nullable().default(null),
56
+ transport_observed: z.string().nullable().default(null),
56
57
  call_id: z.string().nullable().default(null),
57
58
  runtime_meta: z.record(z.string(), z.unknown()).nullable().default(null)
58
59
  };
@@ -393,6 +394,51 @@ import { v7 as uuidv72 } from "uuid";
393
394
  // src/integrations/mcp/annotation.ts
394
395
  import { z as z2 } from "zod";
395
396
 
397
+ // src/metaCoordinates.ts
398
+ var COORD_FIELD_NAMES = /* @__PURE__ */ new Set(["latitude", "longitude"]);
399
+ var DECIMAL_STRING = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/;
400
+ function isPlainObject2(value) {
401
+ if (typeof value !== "object" || value === null) return false;
402
+ const proto = Object.getPrototypeOf(value);
403
+ return proto === Object.prototype || proto === null;
404
+ }
405
+ function toOneDecimal(value) {
406
+ const magnitude = Math.abs(value);
407
+ if (Number.isInteger(magnitude * 4) && !Number.isInteger(magnitude * 2)) {
408
+ const tenths = Math.floor(magnitude * 10);
409
+ const even = tenths % 2 === 0 ? tenths : tenths + 1;
410
+ return (Math.sign(value) * even / 10).toFixed(1);
411
+ }
412
+ return value.toFixed(1);
413
+ }
414
+ function roundCoordinate(value) {
415
+ if (typeof value === "number") {
416
+ return Number.isFinite(value) && !Number.isInteger(value) ? Number(toOneDecimal(value)) : void 0;
417
+ }
418
+ if (typeof value === "string" && DECIMAL_STRING.test(value)) {
419
+ return toOneDecimal(Number(value));
420
+ }
421
+ return void 0;
422
+ }
423
+ function walk(value, depth) {
424
+ if (depth >= DEPTH_LIMIT) return value;
425
+ if (isPlainObject2(value)) {
426
+ const out = {};
427
+ for (const [k, v] of Object.entries(value)) {
428
+ const rounded = COORD_FIELD_NAMES.has(k.toLowerCase()) && depth + 1 < DEPTH_LIMIT ? roundCoordinate(v) : void 0;
429
+ out[k] = rounded ?? walk(v, depth + 1);
430
+ }
431
+ return out;
432
+ }
433
+ if (Array.isArray(value)) {
434
+ return value.map((item) => walk(item, depth + 1));
435
+ }
436
+ return value;
437
+ }
438
+ function roundMetaCoordinates(meta) {
439
+ return walk(meta, 0);
440
+ }
441
+
396
442
  // src/identity.ts
397
443
  import { createHmac } from "crypto";
398
444
 
@@ -502,11 +548,13 @@ var USER_GOAL_PARAM_NAME = "user_goal";
502
548
  var EXPECTED_RESULT_PARAM_NAME = "expected_result";
503
549
  var OVERALL_TASK_PARAM_NAME = "overall_task";
504
550
  var INTENT_SOURCE_PARAM = "injected_param";
505
- var USER_GOAL_PARAM_DESCRIPTION = "OPTIONAL. One sentence: what the user is actually trying to accomplish with this call (their goal, not a restatement of the arguments).";
551
+ var USER_GOAL_PARAM_BODY = "One sentence: what the user is actually trying to accomplish with this call (their goal, not a restatement of the arguments).";
552
+ var USER_GOAL_PARAM_DESCRIPTION = "OPTIONAL. " + USER_GOAL_PARAM_BODY;
553
+ var USER_GOAL_PARAM_DESCRIPTION_REQUIRED = "REQUIRED. " + USER_GOAL_PARAM_BODY;
506
554
  var EXPECTED_RESULT_PARAM_DESCRIPTION = "OPTIONAL. One sentence: what a successful result should look like, so a silent/thin failure can be told apart from success.";
507
555
  var OVERALL_TASK_PARAM_DESCRIPTION = "OPTIONAL. Short stable label for the broader task this call serves (e.g. 'prepare campaign approval'). REPEAT the exact same string on every call serving the same task; change it only when the user starts a different task.";
508
- function buildUserGoalParamDescription() {
509
- return USER_GOAL_PARAM_DESCRIPTION;
556
+ function buildUserGoalParamDescription(options = {}) {
557
+ return options.intentParamMode === "required" ? USER_GOAL_PARAM_DESCRIPTION_REQUIRED : USER_GOAL_PARAM_DESCRIPTION;
510
558
  }
511
559
  function buildOverallTaskParamDescription() {
512
560
  return OVERALL_TASK_PARAM_DESCRIPTION;
@@ -619,6 +667,14 @@ function extraEnvelope(extra) {
619
667
  const envelope = extra.mcpReq?.envelope;
620
668
  return envelope ?? null;
621
669
  }
670
+ function observeTransport(extra) {
671
+ try {
672
+ const carrier = extra.http?.req ?? extra.requestInfo;
673
+ return carrier ? "http" : "no-http-request";
674
+ } catch {
675
+ return "read-failed";
676
+ }
677
+ }
622
678
  function extraHeaders(extra) {
623
679
  const fromV2 = extra.http?.req?.headers;
624
680
  if (fromV2 && typeof fromV2.get === "function") return fromV2;
@@ -776,7 +832,7 @@ function registerAnnotationTool(server, options) {
776
832
  server,
777
833
  scrubber: options.scrubber
778
834
  }) ?? UNKNOWN_AGENT_RUNTIME;
779
- const scrubbedMeta = meta ? options.scrubber(meta) : null;
835
+ const scrubbedMeta = meta ? options.scrubber(roundMetaCoordinates(meta)) : null;
780
836
  const sessionId = await resolveSessionId(options.fallbackSessionId, extra);
781
837
  if (args.signal_type === void 0) {
782
838
  options.tracker?.mark(sessionId);
@@ -801,6 +857,7 @@ function registerAnnotationTool(server, options) {
801
857
  consent_token: options.consentToken,
802
858
  agent_runtime: runtime,
803
859
  principal_id: principalId,
860
+ transport_observed: observeTransport(extra),
804
861
  runtime_meta: scrubbedMeta,
805
862
  payload: {
806
863
  // Agent-facing names -> wire keys, as with `overall_task`
@@ -1328,28 +1385,28 @@ function toJsonSchemaCompat(schema, opts) {
1328
1385
  import { z as zV4 } from "zod";
1329
1386
  import { z as zV3 } from "zod/v3";
1330
1387
  var EMPTY_OBJECT_JSON_SCHEMA = { type: "object", properties: {} };
1331
- function injectGoalParams(inputSchema) {
1388
+ function injectGoalParams(inputSchema, intentParamMode) {
1332
1389
  const objSchema = normalizeObjectSchema(inputSchema);
1333
1390
  if (!objSchema) return { schema: inputSchema, dispositions: {} };
1334
1391
  const existingShape = getObjectShape(objSchema) ?? {};
1335
1392
  const values = Object.values(existingShape);
1336
1393
  const useV4 = values.length === 0 || isZ4Schema(values[0]);
1337
1394
  const zodImpl = useV4 ? zV4 : zV3;
1338
- const { dispositions, toInject } = buildIntentFields(existingShape, zodImpl);
1395
+ const { dispositions, toInject } = buildIntentFields(existingShape, zodImpl, intentParamMode);
1339
1396
  if (Object.keys(toInject).length === 0)
1340
1397
  return { schema: inputSchema, dispositions };
1341
1398
  const mergedShape = { ...existingShape, ...toInject };
1342
1399
  const newSchema = objectFromShape(mergedShape);
1343
1400
  return { schema: newSchema, dispositions };
1344
1401
  }
1345
- function buildIntentFields(existingShape, zodImpl) {
1402
+ function buildIntentFields(existingShape, zodImpl, intentParamMode) {
1346
1403
  const dispositions = {};
1347
1404
  const toInject = {};
1348
1405
  if (USER_GOAL_PARAM_NAME in existingShape) {
1349
1406
  dispositions[USER_GOAL_PARAM_NAME] = "native";
1350
1407
  } else {
1351
1408
  dispositions[USER_GOAL_PARAM_NAME] = "injected";
1352
- toInject[USER_GOAL_PARAM_NAME] = zodImpl.string().optional().describe(buildUserGoalParamDescription());
1409
+ toInject[USER_GOAL_PARAM_NAME] = zodImpl.string().optional().describe(buildUserGoalParamDescription({ intentParamMode }));
1353
1410
  }
1354
1411
  for (const [name, buildDescription] of [
1355
1412
  [EXPECTED_RESULT_PARAM_NAME, buildExpectedResultParamDescription],
@@ -1364,17 +1421,35 @@ function buildIntentFields(existingShape, zodImpl) {
1364
1421
  }
1365
1422
  return { dispositions, toInject };
1366
1423
  }
1367
- function injectGoalParamsV2(inputSchema) {
1424
+ function injectGoalParamsV2(inputSchema, intentParamMode) {
1368
1425
  const candidate = inputSchema;
1369
1426
  const shape = candidate?.shape;
1370
1427
  if (!shape || typeof shape !== "object" || typeof candidate?.extend !== "function") {
1371
1428
  return { schema: inputSchema, dispositions: {} };
1372
1429
  }
1373
- const { dispositions, toInject } = buildIntentFields(shape, zV4);
1430
+ const { dispositions, toInject } = buildIntentFields(shape, zV4, intentParamMode);
1374
1431
  if (Object.keys(toInject).length === 0)
1375
1432
  return { schema: inputSchema, dispositions };
1376
1433
  return { schema: candidate.extend(toInject), dispositions };
1377
1434
  }
1435
+ function advertiseUserGoalRequired(result, isInjected) {
1436
+ const tools = result?.tools;
1437
+ if (!Array.isArray(tools)) return result;
1438
+ let changed = false;
1439
+ const advertised = tools.map((tool) => {
1440
+ const entry = tool;
1441
+ if (typeof entry?.name !== "string" || !isInjected(entry.name)) return tool;
1442
+ const schema = entry.inputSchema;
1443
+ if (!schema || typeof schema !== "object") return tool;
1444
+ const declared = schema.required ?? [];
1445
+ if (!Array.isArray(declared)) return tool;
1446
+ const required = declared;
1447
+ if (required.includes(USER_GOAL_PARAM_NAME)) return tool;
1448
+ changed = true;
1449
+ return { ...entry, inputSchema: { ...schema, required: [...required, USER_GOAL_PARAM_NAME] } };
1450
+ });
1451
+ return changed ? { ...result, tools: advertised } : result;
1452
+ }
1378
1453
  function toolInputJsonSchema(inputSchema) {
1379
1454
  const objSchema = normalizeObjectSchema(inputSchema);
1380
1455
  if (!objSchema) return EMPTY_OBJECT_JSON_SCHEMA;
@@ -1496,7 +1571,7 @@ function batonWrap(nameRef, original, ctx) {
1496
1571
  server: ctx.server,
1497
1572
  scrubber: ctx.scrubber
1498
1573
  }) ?? UNKNOWN_AGENT_RUNTIME;
1499
- const scrubbedMeta = meta ? ctx.scrubber(meta) : null;
1574
+ const scrubbedMeta = meta ? ctx.scrubber(roundMetaCoordinates(meta)) : null;
1500
1575
  const sessionId = await resolveSessionId(ctx.fallbackSessionId, extra);
1501
1576
  const dispositions = ctx.paramRegistry.get(toolName);
1502
1577
  const rawIntent = extractGoalParam(params, USER_GOAL_PARAM_NAME, toolName, dispositions);
@@ -1528,6 +1603,10 @@ function batonWrap(nameRef, original, ctx) {
1528
1603
  // NOT among them: it describes the SERVER and is captured outside any
1529
1604
  // call, so there is no caller to name (register D5).
1530
1605
  principal_id: principalId,
1606
+ // Same four stamps, same exclusion: a surface_snapshot describes the
1607
+ // SERVER and is captured outside any call, so it has no caller's
1608
+ // transport to name any more than it has a caller to name.
1609
+ transport_observed: observeTransport(extra),
1531
1610
  runtime_meta: scrubbedMeta
1532
1611
  };
1533
1612
  if (scrubbedIntent !== null && ctx.tracker.claim(sessionId)) {
@@ -1651,7 +1730,7 @@ function captureAndInject(name, entry, ctx) {
1651
1730
  if (ctx.intentParamMode === "off") return;
1652
1731
  const isV2 = typeof mutable.executor === "function";
1653
1732
  try {
1654
- const { schema, dispositions } = isV2 ? injectGoalParamsV2(mutable.inputSchema) : injectGoalParams(mutable.inputSchema);
1733
+ const { schema, dispositions } = isV2 ? injectGoalParamsV2(mutable.inputSchema, ctx.intentParamMode) : injectGoalParams(mutable.inputSchema, ctx.intentParamMode);
1655
1734
  if (Object.keys(dispositions).length > 0) {
1656
1735
  mutable.inputSchema = schema;
1657
1736
  ctx.bustSchemaMemo(name);
@@ -1662,6 +1741,46 @@ function captureAndInject(name, entry, ctx) {
1662
1741
  } catch {
1663
1742
  }
1664
1743
  }
1744
+ var TOOLS_LIST_METHOD = "tools/list";
1745
+ var TOOLS_LIST_SEAM = /* @__PURE__ */ Symbol("batonToolsListSeam");
1746
+ function installToolsListSeam(lowLevel, ctx) {
1747
+ const table = lowLevel._requestHandlers;
1748
+ const originalSet = lowLevel.setRequestHandler;
1749
+ if (!(table instanceof Map) || typeof originalSet !== "function") return;
1750
+ const handlers = table;
1751
+ const setRequestHandler = originalSet;
1752
+ const isInjected = (toolName) => ctx.paramRegistry.get(toolName)?.[USER_GOAL_PARAM_NAME] === "injected";
1753
+ const advertise = (result) => {
1754
+ try {
1755
+ return advertiseUserGoalRequired(result, isInjected);
1756
+ } catch (err) {
1757
+ process.stderr.write(
1758
+ `baton: tools/list advertisement failed; serving the SDK's own result: ${String(err)}
1759
+ `
1760
+ );
1761
+ return result;
1762
+ }
1763
+ };
1764
+ const wrapCurrent = () => {
1765
+ const handler = handlers.get(TOOLS_LIST_METHOD);
1766
+ if (typeof handler !== "function" || handler[TOOLS_LIST_SEAM]) return;
1767
+ const seamed = (...args) => {
1768
+ const out = handler(...args);
1769
+ return isThenable(out) ? out.then(advertise) : advertise(out);
1770
+ };
1771
+ seamed[TOOLS_LIST_SEAM] = true;
1772
+ handlers.set(TOOLS_LIST_METHOD, seamed);
1773
+ };
1774
+ wrapCurrent();
1775
+ lowLevel.setRequestHandler = (...args) => {
1776
+ const registered = setRequestHandler.apply(lowLevel, args);
1777
+ wrapCurrent();
1778
+ return registered;
1779
+ };
1780
+ }
1781
+ function isThenable(value) {
1782
+ return typeof value?.then === "function";
1783
+ }
1665
1784
  function wrapIfNeeded(nameRef, entry, ctx) {
1666
1785
  if (!entry || typeof entry !== "object") return;
1667
1786
  const mutable = entry;
@@ -1752,7 +1871,7 @@ function withBaton(server, supplied = {}) {
1752
1871
  const config = resolveBatonConfig(supplied, serverName);
1753
1872
  const sink = config.sink ?? new StdoutSink();
1754
1873
  const annotationToolName = resolveAnnotationToolName(serverName, config);
1755
- const intentParamMode = config.intentParamMode ?? "optional";
1874
+ const intentParamMode = config.intentParamMode ?? "required";
1756
1875
  const counter = new SessionCounter();
1757
1876
  const fallbackSessionId = `sdk-${uuidv72()}`;
1758
1877
  const tenantId = resolveTenantId(config.tenantId, config.vendorId);
@@ -1849,6 +1968,7 @@ function withBaton(server, supplied = {}) {
1849
1968
  annotationToolName
1850
1969
  });
1851
1970
  internals.server._instructions = instructions;
1971
+ if (intentParamMode === "required") installToolsListSeam(internals.server, ctx);
1852
1972
  const resolvedAnnotationToolName = registerAnnotationTool(server, {
1853
1973
  sink,
1854
1974
  counter: ctx.counter,