@goodtiming/baton-sdk 0.3.3 → 0.3.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 +1 -1
- package/dist/index.cjs +186 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -9
- package/dist/index.d.ts +18 -9
- package/dist/index.js +186 -97
- 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.4";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -697,10 +697,13 @@ interface BatonConfig {
|
|
|
697
697
|
* annotation tool description — whitelabel obligation (SPEC §5.4): no
|
|
698
698
|
* Baton-branded strings reach the calling agent.
|
|
699
699
|
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
700
|
+
* When a `dsn` is given and this is not, defaults to your server's OWN name
|
|
701
|
+
* (`new McpServer({ name })`), VERBATIM: a string you chose, which makes it
|
|
702
|
+
* the one to put in front of your users. Verbatim rather than prettified
|
|
703
|
+
* for the same reason: a capitalisation you never chose would be a
|
|
704
|
+
* fabricated name. Falls back to the DSN's server segment when the server's
|
|
705
|
+
* name is one a library made up, is blank or unreadable, or would push the
|
|
706
|
+
* server instructions over their cap. With no `dsn`, this is required. */
|
|
704
707
|
vendorDisplayName?: string;
|
|
705
708
|
/** End-user consent token attached to every emitted event per SPEC §2.3 —
|
|
706
709
|
* the Console MUST reject events missing it.
|
|
@@ -728,8 +731,13 @@ interface BatonConfig {
|
|
|
728
731
|
* so untouched integrations get scrubbing without the operator opting in.
|
|
729
732
|
* Pass `identityScrub` to explicitly opt out, or supply your own. */
|
|
730
733
|
scrubber?: (value: unknown) => unknown;
|
|
731
|
-
/** Optional override for the annotation tool name
|
|
732
|
-
*
|
|
734
|
+
/** Optional override for the annotation tool name, and the only thing that
|
|
735
|
+
* pins it. The default is derived from your server's own name, slugged: a
|
|
736
|
+
* server called `"Acme Knowledge Base"` registers
|
|
737
|
+
* `acme-knowledge-base_annotate`. It falls back to `{vendorId}_annotate`
|
|
738
|
+
* when the name is one a library made up, slugs to nothing, is unreadable,
|
|
739
|
+
* or would not fit the server instructions. Set this to keep a name you have
|
|
740
|
+
* written into documentation, a prompt or a script. */
|
|
733
741
|
annotationToolName?: string;
|
|
734
742
|
/** Per-tool intent-param injection (mirrors baton-extmcp's vendor-neutral
|
|
735
743
|
* naming). `"optional"` (default) injects `user_goal`/`expected_result`
|
|
@@ -789,8 +797,9 @@ declare class BatonHandle {
|
|
|
789
797
|
* when no real per-call session id resolves. Not every event necessarily
|
|
790
798
|
* carries this id; see `withBaton`'s session-resolution order. */
|
|
791
799
|
readonly sessionId: string;
|
|
792
|
-
/** The resolved annotation tool name
|
|
793
|
-
*
|
|
800
|
+
/** The resolved annotation tool name: `BatonConfig.annotationToolName` if
|
|
801
|
+
* set, else derived from the server's own name (`{slug}_annotate`), else
|
|
802
|
+
* `{vendorId}_annotate`. */
|
|
794
803
|
readonly annotationToolName: string;
|
|
795
804
|
constructor(options: {
|
|
796
805
|
sink: Sink;
|
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.4";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod schemas + TS types for the Baton event stream per SPEC §11.4.
|
|
@@ -697,10 +697,13 @@ interface BatonConfig {
|
|
|
697
697
|
* annotation tool description — whitelabel obligation (SPEC §5.4): no
|
|
698
698
|
* Baton-branded strings reach the calling agent.
|
|
699
699
|
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
700
|
+
* When a `dsn` is given and this is not, defaults to your server's OWN name
|
|
701
|
+
* (`new McpServer({ name })`), VERBATIM: a string you chose, which makes it
|
|
702
|
+
* the one to put in front of your users. Verbatim rather than prettified
|
|
703
|
+
* for the same reason: a capitalisation you never chose would be a
|
|
704
|
+
* fabricated name. Falls back to the DSN's server segment when the server's
|
|
705
|
+
* name is one a library made up, is blank or unreadable, or would push the
|
|
706
|
+
* server instructions over their cap. With no `dsn`, this is required. */
|
|
704
707
|
vendorDisplayName?: string;
|
|
705
708
|
/** End-user consent token attached to every emitted event per SPEC §2.3 —
|
|
706
709
|
* the Console MUST reject events missing it.
|
|
@@ -728,8 +731,13 @@ interface BatonConfig {
|
|
|
728
731
|
* so untouched integrations get scrubbing without the operator opting in.
|
|
729
732
|
* Pass `identityScrub` to explicitly opt out, or supply your own. */
|
|
730
733
|
scrubber?: (value: unknown) => unknown;
|
|
731
|
-
/** Optional override for the annotation tool name
|
|
732
|
-
*
|
|
734
|
+
/** Optional override for the annotation tool name, and the only thing that
|
|
735
|
+
* pins it. The default is derived from your server's own name, slugged: a
|
|
736
|
+
* server called `"Acme Knowledge Base"` registers
|
|
737
|
+
* `acme-knowledge-base_annotate`. It falls back to `{vendorId}_annotate`
|
|
738
|
+
* when the name is one a library made up, slugs to nothing, is unreadable,
|
|
739
|
+
* or would not fit the server instructions. Set this to keep a name you have
|
|
740
|
+
* written into documentation, a prompt or a script. */
|
|
733
741
|
annotationToolName?: string;
|
|
734
742
|
/** Per-tool intent-param injection (mirrors baton-extmcp's vendor-neutral
|
|
735
743
|
* naming). `"optional"` (default) injects `user_goal`/`expected_result`
|
|
@@ -789,8 +797,9 @@ declare class BatonHandle {
|
|
|
789
797
|
* when no real per-call session id resolves. Not every event necessarily
|
|
790
798
|
* carries this id; see `withBaton`'s session-resolution order. */
|
|
791
799
|
readonly sessionId: string;
|
|
792
|
-
/** The resolved annotation tool name
|
|
793
|
-
*
|
|
800
|
+
/** The resolved annotation tool name: `BatonConfig.annotationToolName` if
|
|
801
|
+
* set, else derived from the server's own name (`{slug}_annotate`), else
|
|
802
|
+
* `{vendorId}_annotate`. */
|
|
794
803
|
readonly annotationToolName: string;
|
|
795
804
|
constructor(options: {
|
|
796
805
|
sink: Sink;
|
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.4";
|
|
3
3
|
|
|
4
4
|
// src/events.ts
|
|
5
5
|
import { z } from "zod";
|
|
@@ -393,19 +393,6 @@ import { v7 as uuidv72 } from "uuid";
|
|
|
393
393
|
// src/integrations/mcp/annotation.ts
|
|
394
394
|
import { z as z2 } from "zod";
|
|
395
395
|
|
|
396
|
-
// src/integrations/mcp/emit.ts
|
|
397
|
-
async function emit(sink, build) {
|
|
398
|
-
let event;
|
|
399
|
-
try {
|
|
400
|
-
event = build();
|
|
401
|
-
} catch (err) {
|
|
402
|
-
process.stderr.write(`baton: event construction failed; event dropped: ${String(err)}
|
|
403
|
-
`);
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
await safeWrite(sink, event);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
396
|
// src/identity.ts
|
|
410
397
|
import { createHmac } from "crypto";
|
|
411
398
|
|
|
@@ -424,7 +411,10 @@ var PYTHON_WHITESPACE = "\\t\\n\\v\\f\\r\\x1c-\\x1f \\x85\\xa0\\u1680\\u2000-\\u
|
|
|
424
411
|
var PYTHON_STRIP = new RegExp(`^[${PYTHON_WHITESPACE}]+|[${PYTHON_WHITESPACE}]+$`, "gu");
|
|
425
412
|
var LONE_SURROGATE = /\p{Surrogate}/u;
|
|
426
413
|
function canonicalize(rawPrincipal) {
|
|
427
|
-
return rawPrincipal.normalize("NFC")
|
|
414
|
+
return pythonStrip(rawPrincipal.normalize("NFC")).toLowerCase();
|
|
415
|
+
}
|
|
416
|
+
function pythonStrip(value) {
|
|
417
|
+
return value.replace(PYTHON_STRIP, "");
|
|
428
418
|
}
|
|
429
419
|
function hashUserId(rawPrincipal, options) {
|
|
430
420
|
const { tenantId, key, issuer = null, scheme } = options;
|
|
@@ -463,6 +453,161 @@ function userIdForPrincipal(principal, options) {
|
|
|
463
453
|
});
|
|
464
454
|
}
|
|
465
455
|
|
|
456
|
+
// src/integrations/mcp/llmText.ts
|
|
457
|
+
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.
|
|
458
|
+
|
|
459
|
+
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}\` again with signal_type (REQUIRED) \u2014 one of failure, retry_loop, dead_end, parameter_confusion, slow_performance, abandonment, feature_gap, other \u2014 and suggested_improvement (REQUIRED whenever you can articulate one).
|
|
460
|
+
|
|
461
|
+
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 signal_type='feature_gap' AND still answer the user with your best inference. Filing the annotation does NOT replace answering.`;
|
|
462
|
+
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.
|
|
463
|
+
|
|
464
|
+
Fields:
|
|
465
|
+
- user_goal: one sentence on what the user is trying to accomplish.
|
|
466
|
+
- expected_result: what a successful result should look like, so a silent/thin failure can be told apart from success.
|
|
467
|
+
- 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.
|
|
468
|
+
- signal_type: reactive-only \u2014 omit on a proactive annotation. Set only once a tool call has returned an unhelpful result. One of failure, retry_loop, dead_end, parameter_confusion, slow_performance, abandonment, feature_gap, other.
|
|
469
|
+
- suggested_improvement: reactive-only \u2014 omit on a proactive. A concrete sentence about what product change would have helped.
|
|
470
|
+
- 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.`;
|
|
471
|
+
var CLAUDE_CODE_TRUNCATION_CAP = 2087;
|
|
472
|
+
var INSTRUCTIONS_LENGTH_CAP = 1500;
|
|
473
|
+
var SIGNAL_TYPES = [
|
|
474
|
+
"failure",
|
|
475
|
+
"retry_loop",
|
|
476
|
+
"dead_end",
|
|
477
|
+
"parameter_confusion",
|
|
478
|
+
"slow_performance",
|
|
479
|
+
"abandonment",
|
|
480
|
+
"feature_gap",
|
|
481
|
+
"other"
|
|
482
|
+
];
|
|
483
|
+
function renderServerInstructions(options) {
|
|
484
|
+
return SERVER_INSTRUCTIONS_TEMPLATE(options.vendorDisplayName, options.annotationToolName);
|
|
485
|
+
}
|
|
486
|
+
function fitsInstructionsCap(options) {
|
|
487
|
+
return renderServerInstructions(options).length <= INSTRUCTIONS_LENGTH_CAP;
|
|
488
|
+
}
|
|
489
|
+
function buildServerInstructions(options) {
|
|
490
|
+
const rendered = renderServerInstructions(options);
|
|
491
|
+
if (rendered.length > INSTRUCTIONS_LENGTH_CAP) {
|
|
492
|
+
throw new Error(
|
|
493
|
+
`Rendered server instructions are ${rendered.length} chars, which exceeds the ${INSTRUCTIONS_LENGTH_CAP}-char safety cap (Claude Code truncates at ~${CLAUDE_CODE_TRUNCATION_CAP}). Shorten vendorDisplayName or annotationToolName.`
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
return rendered;
|
|
497
|
+
}
|
|
498
|
+
function buildAnnotationToolDescription(options) {
|
|
499
|
+
return ANNOTATION_TOOL_DESCRIPTION_TEMPLATE(options.vendorDisplayName);
|
|
500
|
+
}
|
|
501
|
+
var USER_GOAL_PARAM_NAME = "user_goal";
|
|
502
|
+
var EXPECTED_RESULT_PARAM_NAME = "expected_result";
|
|
503
|
+
var OVERALL_TASK_PARAM_NAME = "overall_task";
|
|
504
|
+
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).";
|
|
506
|
+
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
|
+
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;
|
|
510
|
+
}
|
|
511
|
+
function buildOverallTaskParamDescription() {
|
|
512
|
+
return OVERALL_TASK_PARAM_DESCRIPTION;
|
|
513
|
+
}
|
|
514
|
+
function buildExpectedResultParamDescription() {
|
|
515
|
+
return EXPECTED_RESULT_PARAM_DESCRIPTION;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// src/integrations/mcp/annotationName.ts
|
|
519
|
+
var TOOL_NAME_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
520
|
+
var SUFFIX = "_annotate";
|
|
521
|
+
var SLUG_CAP = 30;
|
|
522
|
+
var PLACEHOLDER_LITERALS = /* @__PURE__ */ new Set(["fastmcp", "mcp-server"]);
|
|
523
|
+
var RANDOM_SUFFIX = /-[0-9a-f]{4}$/;
|
|
524
|
+
function isLibraryPlaceholder(serverName, className) {
|
|
525
|
+
const stripped = pythonStrip(serverName);
|
|
526
|
+
if (PLACEHOLDER_LITERALS.has(stripped.toLowerCase())) return true;
|
|
527
|
+
const stem = stripped.replace(RANDOM_SUFFIX, "");
|
|
528
|
+
return stem !== stripped && stem === className;
|
|
529
|
+
}
|
|
530
|
+
function warn(message) {
|
|
531
|
+
if (typeof process !== "undefined" && typeof process.emitWarning === "function") {
|
|
532
|
+
process.emitWarning(message);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
function usableServerName(read) {
|
|
536
|
+
let name;
|
|
537
|
+
let className;
|
|
538
|
+
try {
|
|
539
|
+
({ name, className } = read());
|
|
540
|
+
} catch {
|
|
541
|
+
warn(
|
|
542
|
+
"baton: reading the server name failed; using the DSN's server segment and {vendorId}_annotate instead."
|
|
543
|
+
);
|
|
544
|
+
return void 0;
|
|
545
|
+
}
|
|
546
|
+
if (typeof name !== "string" || pythonStrip(name) === "") return void 0;
|
|
547
|
+
if (isLibraryPlaceholder(name, typeof className === "string" ? className : "")) {
|
|
548
|
+
return void 0;
|
|
549
|
+
}
|
|
550
|
+
return name;
|
|
551
|
+
}
|
|
552
|
+
function slugServerName(serverName) {
|
|
553
|
+
const mapped = pythonStrip(serverName).toLowerCase().replace(/[^a-z0-9-]/gu, "-");
|
|
554
|
+
const collapsed = mapped.replace(/-+/g, "-").replace(/^-+|-+$/g, "");
|
|
555
|
+
return collapsed.slice(0, SLUG_CAP).replace(/^-+|-+$/g, "") || void 0;
|
|
556
|
+
}
|
|
557
|
+
function displayNameFromServer(serverName, tool) {
|
|
558
|
+
if (serverName === void 0) return void 0;
|
|
559
|
+
const fallbackToolName = tool.annotationToolName || `${tool.vendorId}${SUFFIX}`;
|
|
560
|
+
if (!fitsInstructionsCap({ vendorDisplayName: serverName, annotationToolName: fallbackToolName })) {
|
|
561
|
+
warn(
|
|
562
|
+
`baton: the server name (${serverName.length} chars) does not fit the server-instructions budget as the display name; keeping the DSN's server segment. Pass vendorDisplayName to choose a shorter one.`
|
|
563
|
+
);
|
|
564
|
+
return void 0;
|
|
565
|
+
}
|
|
566
|
+
return serverName;
|
|
567
|
+
}
|
|
568
|
+
function annotationToolNameFromServer(serverName, vendorDisplayName) {
|
|
569
|
+
if (serverName === void 0) return void 0;
|
|
570
|
+
const slug = slugServerName(serverName);
|
|
571
|
+
if (slug === void 0) return void 0;
|
|
572
|
+
const candidate = `${slug}${SUFFIX}`;
|
|
573
|
+
if (!TOOL_NAME_PATTERN.test(candidate)) return void 0;
|
|
574
|
+
if (!fitsInstructionsCap({ vendorDisplayName, annotationToolName: candidate })) {
|
|
575
|
+
warn(
|
|
576
|
+
`baton: the server-derived annotation tool name ${JSON.stringify(candidate)} does not fit the server-instructions budget beside the display name (${vendorDisplayName.length} chars); keeping {vendorId}_annotate. A shorter display name gets the readable one.`
|
|
577
|
+
);
|
|
578
|
+
return void 0;
|
|
579
|
+
}
|
|
580
|
+
return candidate;
|
|
581
|
+
}
|
|
582
|
+
function deriveAnnotationToolName(vendorId, override) {
|
|
583
|
+
const name = override || `${vendorId}${SUFFIX}`;
|
|
584
|
+
if (!TOOL_NAME_PATTERN.test(name)) {
|
|
585
|
+
throw new Error(
|
|
586
|
+
`Annotation tool name ${JSON.stringify(name)} violates the cross-runtime pattern ${TOOL_NAME_PATTERN.source} (Claude Desktop and others reject names with dots or other separators).`
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
return name;
|
|
590
|
+
}
|
|
591
|
+
function resolveAnnotationToolName(serverName, config) {
|
|
592
|
+
return deriveAnnotationToolName(
|
|
593
|
+
config.vendorId,
|
|
594
|
+
config.annotationToolName || annotationToolNameFromServer(serverName, config.vendorDisplayName)
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// src/integrations/mcp/emit.ts
|
|
599
|
+
async function emit(sink, build) {
|
|
600
|
+
let event;
|
|
601
|
+
try {
|
|
602
|
+
event = build();
|
|
603
|
+
} catch (err) {
|
|
604
|
+
process.stderr.write(`baton: event construction failed; event dropped: ${String(err)}
|
|
605
|
+
`);
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
await safeWrite(sink, event);
|
|
609
|
+
}
|
|
610
|
+
|
|
466
611
|
// src/integrations/mcp/mcpTypes.ts
|
|
467
612
|
function extraMeta(extra) {
|
|
468
613
|
const direct = extra._meta;
|
|
@@ -534,67 +679,6 @@ async function resolveCallUserId(hook, call, options) {
|
|
|
534
679
|
}
|
|
535
680
|
}
|
|
536
681
|
|
|
537
|
-
// src/integrations/mcp/llmText.ts
|
|
538
|
-
var SERVER_INSTRUCTIONS_TEMPLATE = (vendorDisplayName, annotationToolName) => `This server is wrapped in the ${vendorDisplayName} support-signal SDK. Use \`${annotationToolName}\` to record what the user is trying to do and how each ${vendorDisplayName} tool call went. See that tool's description for field-level detail.
|
|
539
|
-
|
|
540
|
-
BEFORE invoking any ${vendorDisplayName} tool, you MUST call \`${annotationToolName}\` with user_goal (REQUIRED), expected_result (REQUIRED), and overall_task (REQUIRED when the request fits a recognizable broader task, e.g., 'morning meeting prep', 'pre-outreach research').
|
|
541
|
-
|
|
542
|
-
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}\` again with signal_type (REQUIRED) \u2014 one of failure, retry_loop, dead_end, parameter_confusion, slow_performance, abandonment, feature_gap, other \u2014 and suggested_improvement (REQUIRED whenever you can articulate one).
|
|
543
|
-
|
|
544
|
-
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 signal_type='feature_gap' AND still answer the user with your best inference. Filing the annotation does NOT replace answering.`;
|
|
545
|
-
var ANNOTATION_TOOL_DESCRIPTION_TEMPLATE = (vendorDisplayName) => `Record structured signal about a ${vendorDisplayName} tool call \u2014 what the user is trying to do, and how it went. Populate proactively before the call (user_goal + expected_result + overall_task) and reactively after if the result was unhelpful (signal_type + suggested_improvement).
|
|
546
|
-
|
|
547
|
-
Fields:
|
|
548
|
-
- user_goal: one sentence on what the user is trying to accomplish.
|
|
549
|
-
- expected_result: what a successful result should look like, so a silent/thin failure can be told apart from success.
|
|
550
|
-
- overall_task: short stable label for the broader task this call serves, e.g., 'morning meeting prep', 'pre-outreach research', 'personal scheduling'. REPEAT the exact same string on every call serving the same task; change it only when the user starts a different task. Skip when the call doesn't fit a recognizable broader task.
|
|
551
|
-
- signal_type: reactive-only \u2014 omit on a proactive annotation. Set only once a tool call has returned an unhelpful result. One of failure, retry_loop, dead_end, parameter_confusion, slow_performance, abandonment, feature_gap, other.
|
|
552
|
-
- suggested_improvement: reactive-only \u2014 omit on a proactive. A concrete sentence about what product change would have helped.
|
|
553
|
-
- 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.`;
|
|
554
|
-
var CLAUDE_CODE_TRUNCATION_CAP = 2087;
|
|
555
|
-
var INSTRUCTIONS_LENGTH_CAP = 1500;
|
|
556
|
-
var SIGNAL_TYPES = [
|
|
557
|
-
"failure",
|
|
558
|
-
"retry_loop",
|
|
559
|
-
"dead_end",
|
|
560
|
-
"parameter_confusion",
|
|
561
|
-
"slow_performance",
|
|
562
|
-
"abandonment",
|
|
563
|
-
"feature_gap",
|
|
564
|
-
"other"
|
|
565
|
-
];
|
|
566
|
-
function buildServerInstructions(options) {
|
|
567
|
-
const rendered = SERVER_INSTRUCTIONS_TEMPLATE(
|
|
568
|
-
options.vendorDisplayName,
|
|
569
|
-
options.annotationToolName
|
|
570
|
-
);
|
|
571
|
-
if (rendered.length > INSTRUCTIONS_LENGTH_CAP) {
|
|
572
|
-
throw new Error(
|
|
573
|
-
`Rendered server instructions are ${rendered.length} chars, which exceeds the ${INSTRUCTIONS_LENGTH_CAP}-char safety cap (Claude Code truncates at ~${CLAUDE_CODE_TRUNCATION_CAP}). Shorten vendorDisplayName or annotationToolName.`
|
|
574
|
-
);
|
|
575
|
-
}
|
|
576
|
-
return rendered;
|
|
577
|
-
}
|
|
578
|
-
function buildAnnotationToolDescription(options) {
|
|
579
|
-
return ANNOTATION_TOOL_DESCRIPTION_TEMPLATE(options.vendorDisplayName);
|
|
580
|
-
}
|
|
581
|
-
var USER_GOAL_PARAM_NAME = "user_goal";
|
|
582
|
-
var EXPECTED_RESULT_PARAM_NAME = "expected_result";
|
|
583
|
-
var OVERALL_TASK_PARAM_NAME = "overall_task";
|
|
584
|
-
var INTENT_SOURCE_PARAM = "injected_param";
|
|
585
|
-
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).";
|
|
586
|
-
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.";
|
|
587
|
-
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.";
|
|
588
|
-
function buildUserGoalParamDescription() {
|
|
589
|
-
return USER_GOAL_PARAM_DESCRIPTION;
|
|
590
|
-
}
|
|
591
|
-
function buildOverallTaskParamDescription() {
|
|
592
|
-
return OVERALL_TASK_PARAM_DESCRIPTION;
|
|
593
|
-
}
|
|
594
|
-
function buildExpectedResultParamDescription() {
|
|
595
|
-
return EXPECTED_RESULT_PARAM_DESCRIPTION;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
682
|
// src/integrations/mcp/runtimeAdapter.ts
|
|
599
683
|
var CLIENT_INFO_META_KEY = "io.modelcontextprotocol/clientInfo";
|
|
600
684
|
var CLIENT_NAME_MAX_LEN = 128;
|
|
@@ -654,16 +738,6 @@ async function resolveSessionId(fallbackSessionId, extra) {
|
|
|
654
738
|
}
|
|
655
739
|
|
|
656
740
|
// src/integrations/mcp/annotation.ts
|
|
657
|
-
var TOOL_NAME_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
658
|
-
function deriveAnnotationToolName(vendorId, override) {
|
|
659
|
-
const name = override || `${vendorId}_annotate`;
|
|
660
|
-
if (!TOOL_NAME_PATTERN.test(name)) {
|
|
661
|
-
throw new Error(
|
|
662
|
-
`Annotation tool name ${JSON.stringify(name)} violates the cross-runtime pattern ${TOOL_NAME_PATTERN.source} (Claude Desktop and others reject names with dots or other separators).`
|
|
663
|
-
);
|
|
664
|
-
}
|
|
665
|
-
return name;
|
|
666
|
-
}
|
|
667
741
|
function registerAnnotationTool(server, options) {
|
|
668
742
|
const name = deriveAnnotationToolName(options.vendorId, options.annotationToolName);
|
|
669
743
|
const description = buildAnnotationToolDescription({
|
|
@@ -760,7 +834,7 @@ function containsKey(value) {
|
|
|
760
834
|
return sweep(value) !== value;
|
|
761
835
|
}
|
|
762
836
|
var BARE_KEY_HINT = "this looks like a bare key, not a DSN \u2014 copy the full value from /account, which starts with https:// and ends with your server's name";
|
|
763
|
-
function
|
|
837
|
+
function warn2(message) {
|
|
764
838
|
if (typeof process !== "undefined" && typeof process.emitWarning === "function") {
|
|
765
839
|
process.emitWarning(message);
|
|
766
840
|
}
|
|
@@ -824,7 +898,7 @@ function selectDsn(explicit, supplied, door) {
|
|
|
824
898
|
const ambient = dsnFromEnvironment();
|
|
825
899
|
if (ambient === void 0) return void 0;
|
|
826
900
|
if (conflicts.length > 0) {
|
|
827
|
-
|
|
901
|
+
warn2(
|
|
828
902
|
`baton: BATON_DSN is set, but this ${door} supplies ${conflicts.join(", ")} directly, so BATON_DSN is being IGNORED and these events are NOT going to the collector it names. Remove the explicit value to use it, or unset BATON_DSN if it was meant for a different server.`
|
|
829
903
|
);
|
|
830
904
|
return void 0;
|
|
@@ -920,7 +994,7 @@ function parseDsn(raw) {
|
|
|
920
994
|
);
|
|
921
995
|
}
|
|
922
996
|
if (key.startsWith(SECRET_PREFIX)) {
|
|
923
|
-
|
|
997
|
+
warn2(
|
|
924
998
|
`baton: this DSN carries a ${SECRET_PREFIX} key (a workspace SECRET) where a ${PUBLISHABLE_PREFIX} key belongs. It will work. But if this server ships to anyone else, that key reads and writes everything the workspace holds \u2014 mint a publishable key at /account instead.`
|
|
925
999
|
);
|
|
926
1000
|
}
|
|
@@ -963,7 +1037,7 @@ function resolveUserIdHmacKey(explicit) {
|
|
|
963
1037
|
const fromEnv = typeof process !== "undefined" ? process.env?.BATON_USER_ID_HMAC_KEY : void 0;
|
|
964
1038
|
return fromEnv ? fromEnv : void 0;
|
|
965
1039
|
}
|
|
966
|
-
function resolveBatonConfig(config) {
|
|
1040
|
+
function resolveBatonConfig(config, serverName) {
|
|
967
1041
|
const dsnString = selectDsn(
|
|
968
1042
|
config.dsn,
|
|
969
1043
|
{
|
|
@@ -999,7 +1073,14 @@ function resolveBatonConfig(config) {
|
|
|
999
1073
|
// in the server instructions and the annotation tool description, which is
|
|
1000
1074
|
// the whitelabel obligation the validator cites when it refuses the empty
|
|
1001
1075
|
// one. ⚠ Python uses `or` here and still has the inconsistency.
|
|
1002
|
-
|
|
1076
|
+
//
|
|
1077
|
+
// Between the explicit value and the segment sits the server's own name,
|
|
1078
|
+
// under the guards in `annotationName.ts`: the segment is an opaque
|
|
1079
|
+
// `srv-<8 hex>`, and it was what agents were told the vendor is called.
|
|
1080
|
+
vendorDisplayName: config.vendorDisplayName ?? displayNameFromServer(serverName, {
|
|
1081
|
+
vendorId: dsn.vendorId,
|
|
1082
|
+
annotationToolName: config.annotationToolName
|
|
1083
|
+
}) ?? dsn.vendorId,
|
|
1003
1084
|
// `??`, not `||`: an explicit empty string must survive to the validation
|
|
1004
1085
|
// below and be REFUSED there, rather than be quietly replaced by the
|
|
1005
1086
|
// default it was deliberately not left as.
|
|
@@ -1097,8 +1178,9 @@ var BatonHandle = class {
|
|
|
1097
1178
|
* when no real per-call session id resolves. Not every event necessarily
|
|
1098
1179
|
* carries this id; see `withBaton`'s session-resolution order. */
|
|
1099
1180
|
sessionId;
|
|
1100
|
-
/** The resolved annotation tool name
|
|
1101
|
-
*
|
|
1181
|
+
/** The resolved annotation tool name: `BatonConfig.annotationToolName` if
|
|
1182
|
+
* set, else derived from the server's own name (`{slug}_annotate`), else
|
|
1183
|
+
* `{vendorId}_annotate`. */
|
|
1102
1184
|
annotationToolName;
|
|
1103
1185
|
constructor(options) {
|
|
1104
1186
|
this.sink = options.sink;
|
|
@@ -1639,9 +1721,14 @@ function withBaton(server, supplied = {}) {
|
|
|
1639
1721
|
annotationToolName: ""
|
|
1640
1722
|
});
|
|
1641
1723
|
}
|
|
1642
|
-
const
|
|
1724
|
+
const internals = server;
|
|
1725
|
+
const serverName = usableServerName(() => ({
|
|
1726
|
+
name: internals.server._serverInfo?.name,
|
|
1727
|
+
className: internals.constructor.name
|
|
1728
|
+
}));
|
|
1729
|
+
const config = resolveBatonConfig(supplied, serverName);
|
|
1643
1730
|
const sink = config.sink ?? new StdoutSink();
|
|
1644
|
-
const annotationToolName =
|
|
1731
|
+
const annotationToolName = resolveAnnotationToolName(serverName, config);
|
|
1645
1732
|
const intentParamMode = config.intentParamMode ?? "optional";
|
|
1646
1733
|
const counter = new SessionCounter();
|
|
1647
1734
|
const fallbackSessionId = `sdk-${uuidv72()}`;
|
|
@@ -1686,7 +1773,6 @@ function withBaton(server, supplied = {}) {
|
|
|
1686
1773
|
});
|
|
1687
1774
|
await sink.write(event);
|
|
1688
1775
|
};
|
|
1689
|
-
const internals = server;
|
|
1690
1776
|
const bustSchemaMemo = (name) => {
|
|
1691
1777
|
const memo = internals._toolInputSchemaJson;
|
|
1692
1778
|
if (memo && typeof memo === "object") delete memo[name];
|
|
@@ -1758,7 +1844,10 @@ function withBaton(server, supplied = {}) {
|
|
|
1758
1844
|
userIdHmacKey: ctx.userIdHmacKey,
|
|
1759
1845
|
fallbackSessionId: ctx.fallbackSessionId,
|
|
1760
1846
|
scrubber: ctx.scrubber,
|
|
1761
|
-
|
|
1847
|
+
// The RESOLVED name, never `config.annotationToolName`: handing over the
|
|
1848
|
+
// raw override and letting the registration re-derive would register
|
|
1849
|
+
// `srv-..._annotate` while the instructions name the server-derived one.
|
|
1850
|
+
annotationToolName,
|
|
1762
1851
|
tracker
|
|
1763
1852
|
});
|
|
1764
1853
|
const existing = internals._registeredTools;
|