@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/README.md
CHANGED
|
@@ -44,7 +44,7 @@ const server = new McpServer({ name: "your-vendor-mcp", version: "1.0.0" });
|
|
|
44
44
|
const handle = withBaton(server, {
|
|
45
45
|
dsn: "https://baton_pk_...@ingest.goodtiming.ai/ten_7cd4c8cf.../your-vendor",
|
|
46
46
|
});
|
|
47
|
-
// handle.annotationToolName === "your-
|
|
47
|
+
// handle.annotationToolName === "your-vendor-mcp_annotate", from the server's own name
|
|
48
48
|
|
|
49
49
|
// register tools before or after withBaton — both are captured
|
|
50
50
|
server.registerTool("lookup", { inputSchema: { name: z.string() } }, async ({ name }) => {
|
package/dist/index.cjs
CHANGED
|
@@ -58,7 +58,7 @@ __export(index_exports, {
|
|
|
58
58
|
module.exports = __toCommonJS(index_exports);
|
|
59
59
|
|
|
60
60
|
// src/version.ts
|
|
61
|
-
var SDK_VERSION = "ts-0.3.
|
|
61
|
+
var SDK_VERSION = "ts-0.3.4";
|
|
62
62
|
|
|
63
63
|
// src/events.ts
|
|
64
64
|
var import_zod = require("zod");
|
|
@@ -452,19 +452,6 @@ var import_uuid2 = require("uuid");
|
|
|
452
452
|
// src/integrations/mcp/annotation.ts
|
|
453
453
|
var import_zod2 = require("zod");
|
|
454
454
|
|
|
455
|
-
// src/integrations/mcp/emit.ts
|
|
456
|
-
async function emit(sink, build) {
|
|
457
|
-
let event;
|
|
458
|
-
try {
|
|
459
|
-
event = build();
|
|
460
|
-
} catch (err) {
|
|
461
|
-
process.stderr.write(`baton: event construction failed; event dropped: ${String(err)}
|
|
462
|
-
`);
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
await safeWrite(sink, event);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
455
|
// src/identity.ts
|
|
469
456
|
var import_node_crypto = require("crypto");
|
|
470
457
|
|
|
@@ -483,7 +470,10 @@ var PYTHON_WHITESPACE = "\\t\\n\\v\\f\\r\\x1c-\\x1f \\x85\\xa0\\u1680\\u2000-\\u
|
|
|
483
470
|
var PYTHON_STRIP = new RegExp(`^[${PYTHON_WHITESPACE}]+|[${PYTHON_WHITESPACE}]+$`, "gu");
|
|
484
471
|
var LONE_SURROGATE = /\p{Surrogate}/u;
|
|
485
472
|
function canonicalize(rawPrincipal) {
|
|
486
|
-
return rawPrincipal.normalize("NFC")
|
|
473
|
+
return pythonStrip(rawPrincipal.normalize("NFC")).toLowerCase();
|
|
474
|
+
}
|
|
475
|
+
function pythonStrip(value) {
|
|
476
|
+
return value.replace(PYTHON_STRIP, "");
|
|
487
477
|
}
|
|
488
478
|
function hashUserId(rawPrincipal, options) {
|
|
489
479
|
const { tenantId, key, issuer = null, scheme } = options;
|
|
@@ -522,6 +512,161 @@ function userIdForPrincipal(principal, options) {
|
|
|
522
512
|
});
|
|
523
513
|
}
|
|
524
514
|
|
|
515
|
+
// src/integrations/mcp/llmText.ts
|
|
516
|
+
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.
|
|
517
|
+
|
|
518
|
+
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).
|
|
519
|
+
|
|
520
|
+
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.`;
|
|
521
|
+
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.
|
|
522
|
+
|
|
523
|
+
Fields:
|
|
524
|
+
- user_goal: one sentence on what the user is trying to accomplish.
|
|
525
|
+
- expected_result: what a successful result should look like, so a silent/thin failure can be told apart from success.
|
|
526
|
+
- 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.
|
|
527
|
+
- 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.
|
|
528
|
+
- suggested_improvement: reactive-only \u2014 omit on a proactive. A concrete sentence about what product change would have helped.
|
|
529
|
+
- 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.`;
|
|
530
|
+
var CLAUDE_CODE_TRUNCATION_CAP = 2087;
|
|
531
|
+
var INSTRUCTIONS_LENGTH_CAP = 1500;
|
|
532
|
+
var SIGNAL_TYPES = [
|
|
533
|
+
"failure",
|
|
534
|
+
"retry_loop",
|
|
535
|
+
"dead_end",
|
|
536
|
+
"parameter_confusion",
|
|
537
|
+
"slow_performance",
|
|
538
|
+
"abandonment",
|
|
539
|
+
"feature_gap",
|
|
540
|
+
"other"
|
|
541
|
+
];
|
|
542
|
+
function renderServerInstructions(options) {
|
|
543
|
+
return SERVER_INSTRUCTIONS_TEMPLATE(options.vendorDisplayName, options.annotationToolName);
|
|
544
|
+
}
|
|
545
|
+
function fitsInstructionsCap(options) {
|
|
546
|
+
return renderServerInstructions(options).length <= INSTRUCTIONS_LENGTH_CAP;
|
|
547
|
+
}
|
|
548
|
+
function buildServerInstructions(options) {
|
|
549
|
+
const rendered = renderServerInstructions(options);
|
|
550
|
+
if (rendered.length > INSTRUCTIONS_LENGTH_CAP) {
|
|
551
|
+
throw new Error(
|
|
552
|
+
`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.`
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
return rendered;
|
|
556
|
+
}
|
|
557
|
+
function buildAnnotationToolDescription(options) {
|
|
558
|
+
return ANNOTATION_TOOL_DESCRIPTION_TEMPLATE(options.vendorDisplayName);
|
|
559
|
+
}
|
|
560
|
+
var USER_GOAL_PARAM_NAME = "user_goal";
|
|
561
|
+
var EXPECTED_RESULT_PARAM_NAME = "expected_result";
|
|
562
|
+
var OVERALL_TASK_PARAM_NAME = "overall_task";
|
|
563
|
+
var INTENT_SOURCE_PARAM = "injected_param";
|
|
564
|
+
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).";
|
|
565
|
+
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.";
|
|
566
|
+
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.";
|
|
567
|
+
function buildUserGoalParamDescription() {
|
|
568
|
+
return USER_GOAL_PARAM_DESCRIPTION;
|
|
569
|
+
}
|
|
570
|
+
function buildOverallTaskParamDescription() {
|
|
571
|
+
return OVERALL_TASK_PARAM_DESCRIPTION;
|
|
572
|
+
}
|
|
573
|
+
function buildExpectedResultParamDescription() {
|
|
574
|
+
return EXPECTED_RESULT_PARAM_DESCRIPTION;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// src/integrations/mcp/annotationName.ts
|
|
578
|
+
var TOOL_NAME_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
579
|
+
var SUFFIX = "_annotate";
|
|
580
|
+
var SLUG_CAP = 30;
|
|
581
|
+
var PLACEHOLDER_LITERALS = /* @__PURE__ */ new Set(["fastmcp", "mcp-server"]);
|
|
582
|
+
var RANDOM_SUFFIX = /-[0-9a-f]{4}$/;
|
|
583
|
+
function isLibraryPlaceholder(serverName, className) {
|
|
584
|
+
const stripped = pythonStrip(serverName);
|
|
585
|
+
if (PLACEHOLDER_LITERALS.has(stripped.toLowerCase())) return true;
|
|
586
|
+
const stem = stripped.replace(RANDOM_SUFFIX, "");
|
|
587
|
+
return stem !== stripped && stem === className;
|
|
588
|
+
}
|
|
589
|
+
function warn(message) {
|
|
590
|
+
if (typeof process !== "undefined" && typeof process.emitWarning === "function") {
|
|
591
|
+
process.emitWarning(message);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
function usableServerName(read) {
|
|
595
|
+
let name;
|
|
596
|
+
let className;
|
|
597
|
+
try {
|
|
598
|
+
({ name, className } = read());
|
|
599
|
+
} catch {
|
|
600
|
+
warn(
|
|
601
|
+
"baton: reading the server name failed; using the DSN's server segment and {vendorId}_annotate instead."
|
|
602
|
+
);
|
|
603
|
+
return void 0;
|
|
604
|
+
}
|
|
605
|
+
if (typeof name !== "string" || pythonStrip(name) === "") return void 0;
|
|
606
|
+
if (isLibraryPlaceholder(name, typeof className === "string" ? className : "")) {
|
|
607
|
+
return void 0;
|
|
608
|
+
}
|
|
609
|
+
return name;
|
|
610
|
+
}
|
|
611
|
+
function slugServerName(serverName) {
|
|
612
|
+
const mapped = pythonStrip(serverName).toLowerCase().replace(/[^a-z0-9-]/gu, "-");
|
|
613
|
+
const collapsed = mapped.replace(/-+/g, "-").replace(/^-+|-+$/g, "");
|
|
614
|
+
return collapsed.slice(0, SLUG_CAP).replace(/^-+|-+$/g, "") || void 0;
|
|
615
|
+
}
|
|
616
|
+
function displayNameFromServer(serverName, tool) {
|
|
617
|
+
if (serverName === void 0) return void 0;
|
|
618
|
+
const fallbackToolName = tool.annotationToolName || `${tool.vendorId}${SUFFIX}`;
|
|
619
|
+
if (!fitsInstructionsCap({ vendorDisplayName: serverName, annotationToolName: fallbackToolName })) {
|
|
620
|
+
warn(
|
|
621
|
+
`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.`
|
|
622
|
+
);
|
|
623
|
+
return void 0;
|
|
624
|
+
}
|
|
625
|
+
return serverName;
|
|
626
|
+
}
|
|
627
|
+
function annotationToolNameFromServer(serverName, vendorDisplayName) {
|
|
628
|
+
if (serverName === void 0) return void 0;
|
|
629
|
+
const slug = slugServerName(serverName);
|
|
630
|
+
if (slug === void 0) return void 0;
|
|
631
|
+
const candidate = `${slug}${SUFFIX}`;
|
|
632
|
+
if (!TOOL_NAME_PATTERN.test(candidate)) return void 0;
|
|
633
|
+
if (!fitsInstructionsCap({ vendorDisplayName, annotationToolName: candidate })) {
|
|
634
|
+
warn(
|
|
635
|
+
`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.`
|
|
636
|
+
);
|
|
637
|
+
return void 0;
|
|
638
|
+
}
|
|
639
|
+
return candidate;
|
|
640
|
+
}
|
|
641
|
+
function deriveAnnotationToolName(vendorId, override) {
|
|
642
|
+
const name = override || `${vendorId}${SUFFIX}`;
|
|
643
|
+
if (!TOOL_NAME_PATTERN.test(name)) {
|
|
644
|
+
throw new Error(
|
|
645
|
+
`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).`
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
return name;
|
|
649
|
+
}
|
|
650
|
+
function resolveAnnotationToolName(serverName, config) {
|
|
651
|
+
return deriveAnnotationToolName(
|
|
652
|
+
config.vendorId,
|
|
653
|
+
config.annotationToolName || annotationToolNameFromServer(serverName, config.vendorDisplayName)
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/integrations/mcp/emit.ts
|
|
658
|
+
async function emit(sink, build) {
|
|
659
|
+
let event;
|
|
660
|
+
try {
|
|
661
|
+
event = build();
|
|
662
|
+
} catch (err) {
|
|
663
|
+
process.stderr.write(`baton: event construction failed; event dropped: ${String(err)}
|
|
664
|
+
`);
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
await safeWrite(sink, event);
|
|
668
|
+
}
|
|
669
|
+
|
|
525
670
|
// src/integrations/mcp/mcpTypes.ts
|
|
526
671
|
function extraMeta(extra) {
|
|
527
672
|
const direct = extra._meta;
|
|
@@ -593,67 +738,6 @@ async function resolveCallUserId(hook, call, options) {
|
|
|
593
738
|
}
|
|
594
739
|
}
|
|
595
740
|
|
|
596
|
-
// src/integrations/mcp/llmText.ts
|
|
597
|
-
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.
|
|
598
|
-
|
|
599
|
-
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').
|
|
600
|
-
|
|
601
|
-
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).
|
|
602
|
-
|
|
603
|
-
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.`;
|
|
604
|
-
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).
|
|
605
|
-
|
|
606
|
-
Fields:
|
|
607
|
-
- user_goal: one sentence on what the user is trying to accomplish.
|
|
608
|
-
- expected_result: what a successful result should look like, so a silent/thin failure can be told apart from success.
|
|
609
|
-
- 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.
|
|
610
|
-
- 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.
|
|
611
|
-
- suggested_improvement: reactive-only \u2014 omit on a proactive. A concrete sentence about what product change would have helped.
|
|
612
|
-
- 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.`;
|
|
613
|
-
var CLAUDE_CODE_TRUNCATION_CAP = 2087;
|
|
614
|
-
var INSTRUCTIONS_LENGTH_CAP = 1500;
|
|
615
|
-
var SIGNAL_TYPES = [
|
|
616
|
-
"failure",
|
|
617
|
-
"retry_loop",
|
|
618
|
-
"dead_end",
|
|
619
|
-
"parameter_confusion",
|
|
620
|
-
"slow_performance",
|
|
621
|
-
"abandonment",
|
|
622
|
-
"feature_gap",
|
|
623
|
-
"other"
|
|
624
|
-
];
|
|
625
|
-
function buildServerInstructions(options) {
|
|
626
|
-
const rendered = SERVER_INSTRUCTIONS_TEMPLATE(
|
|
627
|
-
options.vendorDisplayName,
|
|
628
|
-
options.annotationToolName
|
|
629
|
-
);
|
|
630
|
-
if (rendered.length > INSTRUCTIONS_LENGTH_CAP) {
|
|
631
|
-
throw new Error(
|
|
632
|
-
`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.`
|
|
633
|
-
);
|
|
634
|
-
}
|
|
635
|
-
return rendered;
|
|
636
|
-
}
|
|
637
|
-
function buildAnnotationToolDescription(options) {
|
|
638
|
-
return ANNOTATION_TOOL_DESCRIPTION_TEMPLATE(options.vendorDisplayName);
|
|
639
|
-
}
|
|
640
|
-
var USER_GOAL_PARAM_NAME = "user_goal";
|
|
641
|
-
var EXPECTED_RESULT_PARAM_NAME = "expected_result";
|
|
642
|
-
var OVERALL_TASK_PARAM_NAME = "overall_task";
|
|
643
|
-
var INTENT_SOURCE_PARAM = "injected_param";
|
|
644
|
-
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).";
|
|
645
|
-
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.";
|
|
646
|
-
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.";
|
|
647
|
-
function buildUserGoalParamDescription() {
|
|
648
|
-
return USER_GOAL_PARAM_DESCRIPTION;
|
|
649
|
-
}
|
|
650
|
-
function buildOverallTaskParamDescription() {
|
|
651
|
-
return OVERALL_TASK_PARAM_DESCRIPTION;
|
|
652
|
-
}
|
|
653
|
-
function buildExpectedResultParamDescription() {
|
|
654
|
-
return EXPECTED_RESULT_PARAM_DESCRIPTION;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
741
|
// src/integrations/mcp/runtimeAdapter.ts
|
|
658
742
|
var CLIENT_INFO_META_KEY = "io.modelcontextprotocol/clientInfo";
|
|
659
743
|
var CLIENT_NAME_MAX_LEN = 128;
|
|
@@ -713,16 +797,6 @@ async function resolveSessionId(fallbackSessionId, extra) {
|
|
|
713
797
|
}
|
|
714
798
|
|
|
715
799
|
// src/integrations/mcp/annotation.ts
|
|
716
|
-
var TOOL_NAME_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
|
|
717
|
-
function deriveAnnotationToolName(vendorId, override) {
|
|
718
|
-
const name = override || `${vendorId}_annotate`;
|
|
719
|
-
if (!TOOL_NAME_PATTERN.test(name)) {
|
|
720
|
-
throw new Error(
|
|
721
|
-
`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).`
|
|
722
|
-
);
|
|
723
|
-
}
|
|
724
|
-
return name;
|
|
725
|
-
}
|
|
726
800
|
function registerAnnotationTool(server, options) {
|
|
727
801
|
const name = deriveAnnotationToolName(options.vendorId, options.annotationToolName);
|
|
728
802
|
const description = buildAnnotationToolDescription({
|
|
@@ -819,7 +893,7 @@ function containsKey(value) {
|
|
|
819
893
|
return sweep(value) !== value;
|
|
820
894
|
}
|
|
821
895
|
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";
|
|
822
|
-
function
|
|
896
|
+
function warn2(message) {
|
|
823
897
|
if (typeof process !== "undefined" && typeof process.emitWarning === "function") {
|
|
824
898
|
process.emitWarning(message);
|
|
825
899
|
}
|
|
@@ -883,7 +957,7 @@ function selectDsn(explicit, supplied, door) {
|
|
|
883
957
|
const ambient = dsnFromEnvironment();
|
|
884
958
|
if (ambient === void 0) return void 0;
|
|
885
959
|
if (conflicts.length > 0) {
|
|
886
|
-
|
|
960
|
+
warn2(
|
|
887
961
|
`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.`
|
|
888
962
|
);
|
|
889
963
|
return void 0;
|
|
@@ -979,7 +1053,7 @@ function parseDsn(raw) {
|
|
|
979
1053
|
);
|
|
980
1054
|
}
|
|
981
1055
|
if (key.startsWith(SECRET_PREFIX)) {
|
|
982
|
-
|
|
1056
|
+
warn2(
|
|
983
1057
|
`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.`
|
|
984
1058
|
);
|
|
985
1059
|
}
|
|
@@ -1022,7 +1096,7 @@ function resolveUserIdHmacKey(explicit) {
|
|
|
1022
1096
|
const fromEnv = typeof process !== "undefined" ? process.env?.BATON_USER_ID_HMAC_KEY : void 0;
|
|
1023
1097
|
return fromEnv ? fromEnv : void 0;
|
|
1024
1098
|
}
|
|
1025
|
-
function resolveBatonConfig(config) {
|
|
1099
|
+
function resolveBatonConfig(config, serverName) {
|
|
1026
1100
|
const dsnString = selectDsn(
|
|
1027
1101
|
config.dsn,
|
|
1028
1102
|
{
|
|
@@ -1058,7 +1132,14 @@ function resolveBatonConfig(config) {
|
|
|
1058
1132
|
// in the server instructions and the annotation tool description, which is
|
|
1059
1133
|
// the whitelabel obligation the validator cites when it refuses the empty
|
|
1060
1134
|
// one. ⚠ Python uses `or` here and still has the inconsistency.
|
|
1061
|
-
|
|
1135
|
+
//
|
|
1136
|
+
// Between the explicit value and the segment sits the server's own name,
|
|
1137
|
+
// under the guards in `annotationName.ts`: the segment is an opaque
|
|
1138
|
+
// `srv-<8 hex>`, and it was what agents were told the vendor is called.
|
|
1139
|
+
vendorDisplayName: config.vendorDisplayName ?? displayNameFromServer(serverName, {
|
|
1140
|
+
vendorId: dsn.vendorId,
|
|
1141
|
+
annotationToolName: config.annotationToolName
|
|
1142
|
+
}) ?? dsn.vendorId,
|
|
1062
1143
|
// `??`, not `||`: an explicit empty string must survive to the validation
|
|
1063
1144
|
// below and be REFUSED there, rather than be quietly replaced by the
|
|
1064
1145
|
// default it was deliberately not left as.
|
|
@@ -1156,8 +1237,9 @@ var BatonHandle = class {
|
|
|
1156
1237
|
* when no real per-call session id resolves. Not every event necessarily
|
|
1157
1238
|
* carries this id; see `withBaton`'s session-resolution order. */
|
|
1158
1239
|
sessionId;
|
|
1159
|
-
/** The resolved annotation tool name
|
|
1160
|
-
*
|
|
1240
|
+
/** The resolved annotation tool name: `BatonConfig.annotationToolName` if
|
|
1241
|
+
* set, else derived from the server's own name (`{slug}_annotate`), else
|
|
1242
|
+
* `{vendorId}_annotate`. */
|
|
1161
1243
|
annotationToolName;
|
|
1162
1244
|
constructor(options) {
|
|
1163
1245
|
this.sink = options.sink;
|
|
@@ -1698,9 +1780,14 @@ function withBaton(server, supplied = {}) {
|
|
|
1698
1780
|
annotationToolName: ""
|
|
1699
1781
|
});
|
|
1700
1782
|
}
|
|
1701
|
-
const
|
|
1783
|
+
const internals = server;
|
|
1784
|
+
const serverName = usableServerName(() => ({
|
|
1785
|
+
name: internals.server._serverInfo?.name,
|
|
1786
|
+
className: internals.constructor.name
|
|
1787
|
+
}));
|
|
1788
|
+
const config = resolveBatonConfig(supplied, serverName);
|
|
1702
1789
|
const sink = config.sink ?? new StdoutSink();
|
|
1703
|
-
const annotationToolName =
|
|
1790
|
+
const annotationToolName = resolveAnnotationToolName(serverName, config);
|
|
1704
1791
|
const intentParamMode = config.intentParamMode ?? "optional";
|
|
1705
1792
|
const counter = new SessionCounter();
|
|
1706
1793
|
const fallbackSessionId = `sdk-${(0, import_uuid2.v7)()}`;
|
|
@@ -1745,7 +1832,6 @@ function withBaton(server, supplied = {}) {
|
|
|
1745
1832
|
});
|
|
1746
1833
|
await sink.write(event);
|
|
1747
1834
|
};
|
|
1748
|
-
const internals = server;
|
|
1749
1835
|
const bustSchemaMemo = (name) => {
|
|
1750
1836
|
const memo = internals._toolInputSchemaJson;
|
|
1751
1837
|
if (memo && typeof memo === "object") delete memo[name];
|
|
@@ -1817,7 +1903,10 @@ function withBaton(server, supplied = {}) {
|
|
|
1817
1903
|
userIdHmacKey: ctx.userIdHmacKey,
|
|
1818
1904
|
fallbackSessionId: ctx.fallbackSessionId,
|
|
1819
1905
|
scrubber: ctx.scrubber,
|
|
1820
|
-
|
|
1906
|
+
// The RESOLVED name, never `config.annotationToolName`: handing over the
|
|
1907
|
+
// raw override and letting the registration re-derive would register
|
|
1908
|
+
// `srv-..._annotate` while the instructions name the server-derived one.
|
|
1909
|
+
annotationToolName,
|
|
1821
1910
|
tracker
|
|
1822
1911
|
});
|
|
1823
1912
|
const existing = internals._registeredTools;
|