@goodtiming/baton-sdk 0.5.3 → 0.5.4
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/README.md +4 -1
- package/dist/index.cjs +45 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -11
- package/dist/index.d.ts +14 -11
- package/dist/index.js +45 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -110,7 +110,7 @@ withBaton(server, {
|
|
|
110
110
|
|
|
111
111
|
⚠ **They read the claims from `authInfo.extra`.** The MCP SDK's `AuthInfo` has no `claims` field, so these hooks expect your token verifier to put the decoded JWT claims (`sub`, `iss`, `email`) at the top level of `extra`. If yours keeps them elsewhere, write the three-line hook that reads them from there. A token exists only on HTTP with auth configured; on stdio, write a hook that names the user from whatever you authenticated them with.
|
|
112
112
|
|
|
113
|
-
The hook runs on every tool call
|
|
113
|
+
The hook runs on every tool call, every `tools/list` request and every resource and prompt request (list, read, get), before your handler. On a request that is not a tool call `toolName` is `null` and `arguments` is empty, so a hook that names the person from the headers or `authInfo` needs no change. If it has not answered after 5 seconds, the SDK stops waiting and that request is sent without a principal. That covers an async hook waiting on a slow lookup. A hook that blocks synchronously cannot be interrupted, so keep the work in it async.
|
|
114
114
|
|
|
115
115
|
The id is sent exactly as your hook returns it, so the hook decides what is safe to send. To send a pseudonym instead, hash the id inside your hook and return `form: "hashed"` with it.
|
|
116
116
|
|
|
@@ -190,6 +190,9 @@ with `could not parse ${body.slice(0, 200)}`, that content leaves your process
|
|
|
190
190
|
under a mode you set to stop exactly that. Throw a message that names the
|
|
191
191
|
resource, not its contents.
|
|
192
192
|
|
|
193
|
+
These events carry the principal your `resolvePrincipal` hook returns
|
|
194
|
+
([Who is calling](#who-is-calling)).
|
|
195
|
+
|
|
193
196
|
## Tool listings
|
|
194
197
|
|
|
195
198
|
Every `tools/list` request emits a `tool_list_start` and then a
|
package/dist/index.cjs
CHANGED
|
@@ -93,7 +93,7 @@ __export(index_exports, {
|
|
|
93
93
|
module.exports = __toCommonJS(index_exports);
|
|
94
94
|
|
|
95
95
|
// src/version.ts
|
|
96
|
-
var SDK_VERSION = "ts-0.5.
|
|
96
|
+
var SDK_VERSION = "ts-0.5.4";
|
|
97
97
|
|
|
98
98
|
// src/events.ts
|
|
99
99
|
var import_zod = require("zod");
|
|
@@ -199,6 +199,7 @@ var ToolCallErrorPayloadSchema = import_zod.z.object({
|
|
|
199
199
|
var AnnotationPayloadSchema = import_zod.z.object({
|
|
200
200
|
intent: import_zod.z.string().nullable().default(null),
|
|
201
201
|
expected_outcome: import_zod.z.string().nullable().default(null),
|
|
202
|
+
what_happened: import_zod.z.string().nullable().default(null),
|
|
202
203
|
signal_type: import_zod.z.string().nullable().default(null),
|
|
203
204
|
workflow: import_zod.z.string().nullable().default(null),
|
|
204
205
|
suggested_improvement: import_zod.z.string().nullable().default(null),
|
|
@@ -864,30 +865,21 @@ function principalFor(principal, onUnregisteredForm) {
|
|
|
864
865
|
// src/integrations/mcp/llmText.ts
|
|
865
866
|
var SERVER_INSTRUCTIONS_TEMPLATE = (vendorDisplayName, annotationToolName) => `This server is wrapped in the ${vendorDisplayName} usage and friction SDK. Use \`${annotationToolName}\` to report when a ${vendorDisplayName} tool call goes wrong, or when a tool you needed does not exist, so ${vendorDisplayName} can improve their product. See that tool's description for field-level detail.
|
|
866
867
|
|
|
867
|
-
AFTER any ${vendorDisplayName} tool errors, times out, returns an unhelpful or contradictory result, or the user shows signs of giving up, you MUST call \`${annotationToolName}\`
|
|
868
|
+
AFTER any ${vendorDisplayName} tool errors, times out, returns an unhelpful or contradictory result, or the user shows signs of giving up, you MUST call \`${annotationToolName}\` with what_happened (REQUIRED, your own words, NOT a category), tool_name (REQUIRED) and suggested_improvement (REQUIRED whenever you can articulate one).
|
|
868
869
|
|
|
869
|
-
IF a ${vendorDisplayName} tool response lacks a structured field for what the user asked about, OR you satisfied the user's intent via a workaround because no tool matched what they asked for, OR the user asked for something this server can't do \u2014 you MUST call \`${annotationToolName}\` with
|
|
870
|
+
IF a ${vendorDisplayName} tool response lacks a structured field for what the user asked about, OR you satisfied the user's intent via a workaround because no tool matched what they asked for, OR the user asked for something this server can't do \u2014 you MUST call \`${annotationToolName}\` once per user request, not per call, with what_happened and tool_name (none if no tool) AND still answer the user with your best inference. Filing the annotation does NOT replace answering.`;
|
|
870
871
|
var ANNOTATION_TOOL_DESCRIPTION_TEMPLATE = (vendorDisplayName) => `Report a ${vendorDisplayName} tool call that went wrong \u2014 call this AFTER a call returns an unhelpful, empty, failed or contradictory result, or when no tool covers what the user asked for. Do NOT call it before a tool call or to narrate normal successful work.
|
|
871
872
|
|
|
872
873
|
Fields:
|
|
873
874
|
- user_goal: one sentence on what the user is trying to accomplish.
|
|
875
|
+
- what_happened: REQUIRED on a report. 1-2 plain sentences in YOUR OWN WORDS: what you asked for, what came back, and why it was unusable. Do NOT pick a category or invent a label \u2014 describe it.
|
|
876
|
+
- tool_name: REQUIRED on a report. The ${vendorDisplayName} tool that went wrong. Write none if no tool exists for the request.
|
|
874
877
|
- expected_result: what a successful result should look like, so a silent/thin failure can be told apart from success.
|
|
875
878
|
- overall_task: short stable label for the broader task this call serves, e.g., 'morning meeting prep', 'pre-outreach research'. REPEAT the exact same string on every call serving the same task; change it only when the user starts a different task.
|
|
876
|
-
-
|
|
877
|
-
-
|
|
878
|
-
- context: supplementary info not covered above. Common keys: plan, alternatives_considered, likely_cause, user_impact, error_class, downstream_blocked, confidence_in_intent. For signal_type='feature_gap' also missing_capability_field and requested_capability.`;
|
|
879
|
+
- suggested_improvement: A concrete sentence about what product change would have helped.
|
|
880
|
+
- context: supplementary info not covered above. Common keys: plan, alternatives_considered, likely_cause, user_impact, error_class, downstream_blocked, confidence_in_intent. When no tool covers the request also missing_capability_field and requested_capability.`;
|
|
879
881
|
var CLAUDE_CODE_TRUNCATION_CAP = 2087;
|
|
880
882
|
var INSTRUCTIONS_LENGTH_CAP = 1500;
|
|
881
|
-
var SIGNAL_TYPES = [
|
|
882
|
-
"failure",
|
|
883
|
-
"retry_loop",
|
|
884
|
-
"dead_end",
|
|
885
|
-
"parameter_confusion",
|
|
886
|
-
"slow_performance",
|
|
887
|
-
"abandonment",
|
|
888
|
-
"feature_gap",
|
|
889
|
-
"other"
|
|
890
|
-
];
|
|
891
883
|
function renderServerInstructions(options) {
|
|
892
884
|
return SERVER_INSTRUCTIONS_TEMPLATE(options.vendorDisplayName, options.annotationToolName);
|
|
893
885
|
}
|
|
@@ -1226,6 +1218,10 @@ async function resolveSessionId(fallbackSessionId, extra) {
|
|
|
1226
1218
|
}
|
|
1227
1219
|
|
|
1228
1220
|
// src/integrations/mcp/annotation.ts
|
|
1221
|
+
var TOOL_NAME_PARAM_NAME = "tool_name";
|
|
1222
|
+
function isReport(whatHappened) {
|
|
1223
|
+
return typeof whatHappened === "string" && whatHappened.trim() !== "";
|
|
1224
|
+
}
|
|
1229
1225
|
function registerAnnotationTool(server, options) {
|
|
1230
1226
|
const name = deriveAnnotationToolName(options.vendorId, options.annotationToolName);
|
|
1231
1227
|
const description = buildAnnotationToolDescription({
|
|
@@ -1238,13 +1234,31 @@ function registerAnnotationTool(server, options) {
|
|
|
1238
1234
|
inputSchema: {
|
|
1239
1235
|
user_goal: import_zod2.z.string(),
|
|
1240
1236
|
expected_result: import_zod2.z.string().optional(),
|
|
1241
|
-
|
|
1237
|
+
what_happened: import_zod2.z.string().optional(),
|
|
1238
|
+
// Nullable so a report whose agent sends an explicit null is taken,
|
|
1239
|
+
// not rejected by validation.
|
|
1240
|
+
tool_name: import_zod2.z.string().nullable().optional(),
|
|
1242
1241
|
overall_task: import_zod2.z.string().optional(),
|
|
1243
1242
|
suggested_improvement: import_zod2.z.string().optional(),
|
|
1244
1243
|
context: import_zod2.z.record(import_zod2.z.string(), import_zod2.z.unknown()).optional()
|
|
1245
1244
|
}
|
|
1246
1245
|
},
|
|
1247
1246
|
async (args, extra) => {
|
|
1247
|
+
const whatHappened = args.what_happened;
|
|
1248
|
+
if (!isReport(whatHappened)) {
|
|
1249
|
+
return {
|
|
1250
|
+
content: [
|
|
1251
|
+
{
|
|
1252
|
+
type: "text",
|
|
1253
|
+
text: JSON.stringify({
|
|
1254
|
+
ok: false,
|
|
1255
|
+
error: `${name} is reactive-only on this server. Call it only AFTER a tool call returns an unhelpful, empty, failed or contradictory result, or when no tool covers what the user asked for. What the user is trying to do is already recorded on each tool call, so no pre-call annotation is needed \u2014 nothing was lost. If a tool call really went wrong, or no tool covers the request, call this again and say what_happened. If neither is true, do NOT re-send: that would file a report for a call that did not go wrong.`
|
|
1256
|
+
})
|
|
1257
|
+
}
|
|
1258
|
+
]
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
const reportedTool = args.tool_name ?? null;
|
|
1248
1262
|
const meta = extraMeta(extra);
|
|
1249
1263
|
const scrubbedMeta = scrubOrNull(
|
|
1250
1264
|
options.scrubber,
|
|
@@ -1252,9 +1266,6 @@ function registerAnnotationTool(server, options) {
|
|
|
1252
1266
|
"_meta"
|
|
1253
1267
|
);
|
|
1254
1268
|
const sessionId = await resolveSessionId(options.fallbackSessionId, extra);
|
|
1255
|
-
if (args.signal_type === void 0) {
|
|
1256
|
-
options.tracker?.mark(sessionId);
|
|
1257
|
-
}
|
|
1258
1269
|
const principal = await resolveCallPrincipal(
|
|
1259
1270
|
options.resolvePrincipal,
|
|
1260
1271
|
{ extra, toolName: name, arguments: args }
|
|
@@ -1279,15 +1290,10 @@ function registerAnnotationTool(server, options) {
|
|
|
1279
1290
|
// eslint-disable-next-line no-restricted-syntax -- inside the emit() build thunk: a throw is already contained, and null here would fabricate a shape
|
|
1280
1291
|
intent: options.scrubber(args.user_goal),
|
|
1281
1292
|
expected_outcome: args.expected_result ? options.scrubber(args.expected_result) : null,
|
|
1282
|
-
//
|
|
1283
|
-
|
|
1284
|
-
//
|
|
1285
|
-
|
|
1286
|
-
// gap found 2026-08-11, fixed here and flagged for the sibling
|
|
1287
|
-
// rather than mirrored. Not a wire divergence: scrubbing changes
|
|
1288
|
-
// content, not shape, and it's deterministic, so the
|
|
1289
|
-
// exact-string continuity rung 3b groups on survives.
|
|
1290
|
-
signal_type: args.signal_type ?? null,
|
|
1293
|
+
// eslint-disable-next-line no-restricted-syntax -- inside the emit() build thunk: a throw is already contained, and null here would fabricate a shape
|
|
1294
|
+
what_happened: options.scrubber(whatHappened),
|
|
1295
|
+
// eslint-disable-next-line no-restricted-syntax -- inside the emit() build thunk: a throw is already contained, and null here would fabricate a shape
|
|
1296
|
+
tool_name: reportedTool ? options.scrubber(reportedTool) : reportedTool,
|
|
1291
1297
|
// Agent-facing param `overall_task` -> wire key `workflow`, the same
|
|
1292
1298
|
// split the injected params use (`overall_task` -> `call_workflow`):
|
|
1293
1299
|
// renaming the param must not move the key the console groups on.
|
|
@@ -1757,11 +1763,6 @@ var ProactiveTracker = class {
|
|
|
1757
1763
|
this.emitted.add(sessionId);
|
|
1758
1764
|
return true;
|
|
1759
1765
|
}
|
|
1760
|
-
/** Mark the slot claimed without emitting here (the annotation tool's own
|
|
1761
|
-
* handler already emitted the annotation event itself). */
|
|
1762
|
-
mark(sessionId) {
|
|
1763
|
-
this.emitted.add(sessionId);
|
|
1764
|
-
}
|
|
1765
1766
|
};
|
|
1766
1767
|
|
|
1767
1768
|
// src/integrations/mcp/sessionCounter.ts
|
|
@@ -2373,8 +2374,8 @@ function installRequestSeam(lowLevel, method, seamTag, wrap) {
|
|
|
2373
2374
|
};
|
|
2374
2375
|
}
|
|
2375
2376
|
function installToolsListSeam(lowLevel, ctx) {
|
|
2376
|
-
const names = requiredParamNames(ctx.intentParamMode);
|
|
2377
|
-
const isInjected = (toolName, paramName) => ctx.paramRegistry.get(toolName)?.[paramName] === "injected";
|
|
2377
|
+
const names = [...requiredParamNames(ctx.intentParamMode), TOOL_NAME_PARAM_NAME];
|
|
2378
|
+
const isInjected = (toolName, paramName) => toolName === ctx.annotationToolName ? paramName === TOOL_NAME_PARAM_NAME : ctx.paramRegistry.get(toolName)?.[paramName] === "injected";
|
|
2378
2379
|
const advertise = (result) => {
|
|
2379
2380
|
try {
|
|
2380
2381
|
return advertiseIntentParamsRequired(result, names, isInjected);
|
|
@@ -2443,7 +2444,11 @@ function installLifecycleSeam(lowLevel, ctx, spec) {
|
|
|
2443
2444
|
async function openLifecycleCall(ctx, spec, requestParams, extra) {
|
|
2444
2445
|
try {
|
|
2445
2446
|
const parts = await resolveEnvelopeParts(ctx, extra);
|
|
2446
|
-
const principal =
|
|
2447
|
+
const principal = await resolveCallPrincipal(ctx.resolvePrincipal, {
|
|
2448
|
+
extra,
|
|
2449
|
+
toolName: null,
|
|
2450
|
+
arguments: {}
|
|
2451
|
+
});
|
|
2447
2452
|
return {
|
|
2448
2453
|
sessionId: parts.sessionId,
|
|
2449
2454
|
subject: spec.subjectKey === void 0 ? {} : { [spec.subjectKey]: stringSubject(requestParams[spec.subjectKey]) },
|
|
@@ -2537,8 +2542,7 @@ var LIFECYCLE_SPECS = [
|
|
|
2537
2542
|
error: ToolListErrorEventSchema
|
|
2538
2543
|
},
|
|
2539
2544
|
countKey: "tools",
|
|
2540
|
-
startParams: NO_PARAMS
|
|
2541
|
-
resolvesPrincipal: true
|
|
2545
|
+
startParams: NO_PARAMS
|
|
2542
2546
|
}
|
|
2543
2547
|
];
|
|
2544
2548
|
function installLifecycleSeams(lowLevel, ctx) {
|
|
@@ -2868,7 +2872,7 @@ function install(server, supplied, resolved, emittedSurfaceHashes) {
|
|
|
2868
2872
|
intentParamMode
|
|
2869
2873
|
});
|
|
2870
2874
|
internals.server._instructions = instructions;
|
|
2871
|
-
|
|
2875
|
+
installToolsListSeam(internals.server, ctx);
|
|
2872
2876
|
installToolsCallSeam(
|
|
2873
2877
|
internals.server,
|
|
2874
2878
|
// ⚠ `Object.hasOwn`, never a bare index. `_registeredTools` is a plain
|
|
@@ -2898,8 +2902,7 @@ function install(server, supplied, resolved, emittedSurfaceHashes) {
|
|
|
2898
2902
|
// The RESOLVED name, never `config.annotationToolName`: handing over the
|
|
2899
2903
|
// raw override and letting the registration re-derive would register
|
|
2900
2904
|
// `srv-..._annotate` while the instructions name the server-derived one.
|
|
2901
|
-
annotationToolName
|
|
2902
|
-
tracker
|
|
2905
|
+
annotationToolName
|
|
2903
2906
|
});
|
|
2904
2907
|
const existing = internals._registeredTools;
|
|
2905
2908
|
if (existing) {
|