@goodtiming/baton-sdk 1.3.0 → 1.3.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.cjs CHANGED
@@ -53,7 +53,7 @@ __export(index_exports, {
53
53
  module.exports = __toCommonJS(index_exports);
54
54
 
55
55
  // src/version.ts
56
- var SDK_VERSION = "ts-1.3.0";
56
+ var SDK_VERSION = "ts-1.3.1";
57
57
 
58
58
  // src/events.ts
59
59
  var import_zod = require("zod");
@@ -3241,19 +3241,29 @@ var ANNOTATION_INPUT_SHAPE = {
3241
3241
  // zod renders "any value" as `{}`, which some MCP clients refuse (reportToolSchema.test.ts).
3242
3242
  context: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()).meta({ additionalProperties: true }).nullable().optional()
3243
3243
  };
3244
+ var ANNOTATION_ARGS = import_zod3.z.object(ANNOTATION_INPUT_SHAPE);
3244
3245
  function isReport(whatHappened) {
3245
3246
  return typeof whatHappened === "string" && !isBlank(whatHappened);
3246
3247
  }
3247
- function registerAnnotationTool(server, options) {
3248
+ var INVALID_PARAMS = -32602;
3249
+ function registerAnnotationTool(server, options, callArguments) {
3248
3250
  const tool = buildAnnotationTool(server, options);
3249
- server.registerTool(
3250
- tool.name,
3251
- { description: tool.description, inputSchema: ANNOTATION_INPUT_SHAPE },
3252
- tool.handler
3253
- );
3254
- return tool.name;
3251
+ if (callArguments === void 0) {
3252
+ server.registerTool(tool.name, { description: tool.description, inputSchema: ANNOTATION_INPUT_SHAPE }, tool.handler);
3253
+ return;
3254
+ }
3255
+ server.registerTool(tool.name, { description: tool.description }, async (extra) => {
3256
+ const args = callArguments();
3257
+ const { validateToolInput } = server;
3258
+ let parsed;
3259
+ try {
3260
+ parsed = await validateToolInput?.call(server, { inputSchema: ANNOTATION_ARGS }, args, tool.name);
3261
+ } catch (err) {
3262
+ if (err?.code === INVALID_PARAMS) throw err;
3263
+ }
3264
+ return isRecord(parsed) ? tool.handler(parsed, extra) : callAnnotationTool(tool, args, extra);
3265
+ });
3255
3266
  }
3256
- var ANNOTATION_ARGS = import_zod3.z.object(ANNOTATION_INPUT_SHAPE);
3257
3267
  function annotationInputJsonSchema(major) {
3258
3268
  return annotationJsonSchemas[major] ??= (major === 2 ? standardInputJsonSchema(ANNOTATION_ARGS) : void 0) ?? toolInputJsonSchema(ANNOTATION_INPUT_SHAPE);
3259
3269
  }
@@ -4472,11 +4482,9 @@ var TOOLS_LIST_SEAM = /* @__PURE__ */ Symbol("batonToolsListSeam");
4472
4482
  var TOOLS_CALL_METHOD = "tools/call";
4473
4483
  var TOOLS_CALL_SEAM = /* @__PURE__ */ Symbol("batonToolsCallSeam");
4474
4484
  function installRequestSeam(lowLevel, method, seamTag, wrap) {
4475
- const table = lowLevel._requestHandlers;
4476
- const originalSet = lowLevel.setRequestHandler;
4477
- if (!(table instanceof Map) || typeof originalSet !== "function") return;
4478
- const handlers = table;
4479
- const setRequestHandler = originalSet;
4485
+ if (!takesRequestSeams(lowLevel)) return;
4486
+ const handlers = lowLevel._requestHandlers;
4487
+ const setRequestHandler = lowLevel.setRequestHandler;
4480
4488
  const wrapCurrent = () => {
4481
4489
  const handler = handlers.get(method);
4482
4490
  if (typeof handler !== "function" || handler[seamTag]) return;
@@ -4492,18 +4500,24 @@ function installRequestSeam(lowLevel, method, seamTag, wrap) {
4492
4500
  return registered;
4493
4501
  };
4494
4502
  }
4503
+ function takesRequestSeams(lowLevel) {
4504
+ return lowLevel._requestHandlers instanceof Map && typeof lowLevel.setRequestHandler === "function";
4505
+ }
4495
4506
  function installToolsListSeam(lowLevel, ctx, listsOwnReportTool) {
4496
4507
  const names = [...requiredParamNames(ctx.intentParamMode), TOOL_NAME_PARAM_NAME];
4497
4508
  const isInjected = (toolName, paramName) => toolName === ctx.annotationToolName ? paramName === TOOL_NAME_PARAM_NAME : ctx.paramRegistry.get(toolName)?.[paramName] === "injected";
4498
4509
  const advertise = (result) => {
4510
+ let served = result;
4499
4511
  try {
4500
- const served = listsOwnReportTool || ctx.annotationToolName === "" ? result : withToolInputSchema(result, ctx.annotationToolName, annotationInputJsonSchema(lowLevelMajor(lowLevel)));
4512
+ if (!listsOwnReportTool && ctx.annotationToolName !== "") {
4513
+ served = withToolInputSchema(result, ctx.annotationToolName, annotationInputJsonSchema(lowLevelMajor(lowLevel)));
4514
+ }
4501
4515
  return advertiseIntentParamsRequired(served, names, isInjected);
4502
4516
  } catch (err) {
4503
4517
  stderrLine(
4504
- `baton: tools/list advertisement failed; serving the SDK's own result: ${String(err)}`
4518
+ `baton: tools/list advertisement failed; serving the list without it: ${String(err)}`
4505
4519
  );
4506
- return result;
4520
+ return served;
4507
4521
  }
4508
4522
  };
4509
4523
  installRequestSeam(lowLevel, TOOLS_LIST_METHOD, TOOLS_LIST_SEAM, (handler) => (...args) => {
@@ -4901,14 +4915,15 @@ function installToolsCallSeam(lowLevel, toolEntry, ctx) {
4901
4915
  (handler) => async (...args) => {
4902
4916
  const request = args[0];
4903
4917
  const name = request?.params?.name;
4918
+ const toolArgs = request?.params?.arguments;
4904
4919
  const slot = {
4905
4920
  innerFired: false,
4906
4921
  flushTerminal: null,
4907
4922
  stripped: stripIntentParams(request?.params, ctx),
4908
4923
  strippedFor: typeof name === "string" ? name : null,
4909
- validation: "unseen"
4924
+ validation: "unseen",
4925
+ arguments: name === ctx.annotationToolName ? toolArgs : void 0
4910
4926
  };
4911
- const toolArgs = request?.params?.arguments;
4912
4927
  if (typeof name === "string" && toolEntry(name) != null && await hiddenFrom(slot, name, isRecord(toolArgs) ? toolArgs : {}, args[1], ctx)) {
4913
4928
  return answerHidden(lowLevel, name, (outcome2) => settleCall(slot, outcome2, args, toolEntry, ctx, "tool_hidden"));
4914
4929
  }
@@ -5403,7 +5418,13 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
5403
5418
  checkGivenTools?.();
5404
5419
  return handle(annotationToolName);
5405
5420
  }
5406
- const resolvedAnnotationToolName = annotationOptions ? registerAnnotationTool(server, annotationOptions) : "";
5421
+ if (annotationOptions) {
5422
+ registerAnnotationTool(
5423
+ server,
5424
+ annotationOptions,
5425
+ takesRequestSeams(lowLevel) ? () => callSlots.getStore()?.arguments : void 0
5426
+ );
5427
+ }
5407
5428
  const existing = internals._registeredTools;
5408
5429
  if (existing) {
5409
5430
  for (const [name, entry] of Object.entries(existing)) {
@@ -5416,7 +5437,7 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned4, co
5416
5437
  wireEntry(String(args[0]), registered, ctx);
5417
5438
  return registered;
5418
5439
  };
5419
- return handle(resolvedAnnotationToolName);
5440
+ return handle(annotationToolName);
5420
5441
  }
5421
5442
  function reportsFor(config) {
5422
5443
  if (config.reportMode !== "on") return void 0;