@goodtiming/baton-sdk 0.3.4 → 0.3.6

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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SDK_VERSION = "ts-0.3.4";
2
+ var SDK_VERSION = "ts-0.3.6";
3
3
 
4
4
  // src/events.ts
5
5
  import { z } from "zod";
@@ -52,7 +52,7 @@ var envelopeShape = {
52
52
  consent_token: z.string(),
53
53
  sdk_version: z.string().default(SDK_VERSION),
54
54
  agent_runtime: z.string().default("unknown"),
55
- user_id: z.string().nullable().default(null),
55
+ principal_id: z.string().nullable().default(null),
56
56
  call_id: z.string().nullable().default(null),
57
57
  runtime_meta: z.record(z.string(), z.unknown()).nullable().default(null)
58
58
  };
@@ -404,9 +404,9 @@ function capCodePoints(value, max) {
404
404
 
405
405
  // src/identity.ts
406
406
  var VENDOR_HASH_SCHEME = "v1";
407
- var RAW_USER_ID_MAX_LEN = 128;
408
- var USER_ID_MODE_HASHED = "hashed";
409
- var USER_ID_MODE_RAW = "raw";
407
+ var RAW_PRINCIPAL_ID_MAX_LEN = 128;
408
+ var PRINCIPAL_ID_MODE_HASHED = "hashed";
409
+ var PRINCIPAL_ID_MODE_RAW = "raw";
410
410
  var PYTHON_WHITESPACE = "\\t\\n\\v\\f\\r\\x1c-\\x1f \\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
411
411
  var PYTHON_STRIP = new RegExp(`^[${PYTHON_WHITESPACE}]+|[${PYTHON_WHITESPACE}]+$`, "gu");
412
412
  var LONE_SURROGATE = /\p{Surrogate}/u;
@@ -416,7 +416,7 @@ function canonicalize(rawPrincipal) {
416
416
  function pythonStrip(value) {
417
417
  return value.replace(PYTHON_STRIP, "");
418
418
  }
419
- function hashUserId(rawPrincipal, options) {
419
+ function hashPrincipalId(rawPrincipal, options) {
420
420
  const { tenantId, key, issuer = null, scheme } = options;
421
421
  let message = `${tenantId}\0${canonicalize(rawPrincipal)}`;
422
422
  if (issuer !== null) {
@@ -429,19 +429,19 @@ function hashUserId(rawPrincipal, options) {
429
429
  function normalizePrincipal(result) {
430
430
  if (result === null || typeof result !== "object") return null;
431
431
  const candidate = result;
432
- if (typeof candidate.userId !== "string") return null;
433
- if (LONE_SURROGATE.test(candidate.userId)) return null;
434
- if (canonicalize(candidate.userId) === "") return null;
432
+ if (typeof candidate.principalId !== "string") return null;
433
+ if (LONE_SURROGATE.test(candidate.principalId)) return null;
434
+ if (canonicalize(candidate.principalId) === "") return null;
435
435
  const issuerRaw = typeof candidate.issuer === "string" && candidate.issuer ? candidate.issuer : null;
436
436
  const issuer = issuerRaw !== null && !LONE_SURROGATE.test(issuerRaw) ? issuerRaw : null;
437
- return { userId: candidate.userId, issuer };
437
+ return { principalId: candidate.principalId, issuer };
438
438
  }
439
- function userIdForPrincipal(principal, options) {
440
- if (options.mode === USER_ID_MODE_RAW) {
441
- return capCodePoints(principal.userId, RAW_USER_ID_MAX_LEN);
439
+ function principalIdFor(principal, options) {
440
+ if (options.mode === PRINCIPAL_ID_MODE_RAW) {
441
+ return capCodePoints(principal.principalId, RAW_PRINCIPAL_ID_MAX_LEN);
442
442
  }
443
443
  if (options.key === null || options.key === void 0) return null;
444
- return hashUserId(principal.userId, {
444
+ return hashPrincipalId(principal.principalId, {
445
445
  tenantId: options.tenantId,
446
446
  key: options.key,
447
447
  issuer: principal.issuer ?? null,
@@ -502,11 +502,13 @@ var USER_GOAL_PARAM_NAME = "user_goal";
502
502
  var EXPECTED_RESULT_PARAM_NAME = "expected_result";
503
503
  var OVERALL_TASK_PARAM_NAME = "overall_task";
504
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).";
505
+ 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).";
506
+ var USER_GOAL_PARAM_DESCRIPTION = "OPTIONAL. " + USER_GOAL_PARAM_BODY;
507
+ var USER_GOAL_PARAM_DESCRIPTION_REQUIRED = "REQUIRED. " + USER_GOAL_PARAM_BODY;
506
508
  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
509
  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
+ function buildUserGoalParamDescription(options = {}) {
511
+ return options.intentParamMode === "required" ? USER_GOAL_PARAM_DESCRIPTION_REQUIRED : USER_GOAL_PARAM_DESCRIPTION;
510
512
  }
511
513
  function buildOverallTaskParamDescription() {
512
514
  return OVERALL_TASK_PARAM_DESCRIPTION;
@@ -639,8 +641,8 @@ function extraHeaders(extra) {
639
641
  return null;
640
642
  }
641
643
 
642
- // src/integrations/mcp/userResolution.ts
643
- function buildUserResolutionContext(extra, toolName, args) {
644
+ // src/integrations/mcp/principalResolution.ts
645
+ function buildPrincipalResolutionContext(extra, toolName, args) {
644
646
  return {
645
647
  headers: extraHeaders(extra),
646
648
  meta: extraMeta(extra),
@@ -649,27 +651,40 @@ function buildUserResolutionContext(extra, toolName, args) {
649
651
  };
650
652
  }
651
653
  function warnIfIdentityCannotResolve(config) {
652
- if (config.resolveUser === void 0) return;
653
- if (config.userIdMode !== USER_ID_MODE_HASHED) return;
654
- if (config.userIdHmacKey !== void 0) return;
654
+ if (config.resolvePrincipal === void 0) return;
655
+ if (config.principalIdMode !== PRINCIPAL_ID_MODE_HASHED) return;
656
+ if (config.principalIdHmacKey !== void 0) return;
655
657
  if (typeof process === "undefined" || typeof process.emitWarning !== "function") return;
658
+ const renamed = process.env?.BATON_USER_ID_HMAC_KEY ? "BATON_USER_ID_HMAC_KEY is set, but it was renamed to BATON_PRINCIPAL_ID_HMAC_KEY in 0.3.5 and is no longer read. " : "";
656
659
  process.emitWarning(
657
- 'baton: resolveUser is configured but no user_id HMAC key is set, so user_id is dropped from every event (events still emit). Set BATON_USER_ID_HMAC_KEY or BatonConfig.userIdHmacKey, or pass userIdMode: "raw" if you intend to emit the subject verbatim.'
660
+ `baton: resolvePrincipal is configured but no principal_id HMAC key is set, so principal_id is dropped from every event (events still emit). ${renamed}Set BATON_PRINCIPAL_ID_HMAC_KEY or BatonConfig.principalIdHmacKey, or pass principalIdMode: "raw" if you intend to emit the subject verbatim.`
658
661
  );
659
662
  }
660
- async function resolveCallUserId(hook, call, options) {
663
+ var warnedPreRenameShape = false;
664
+ function warnIfPreRenameShape(result) {
665
+ const userId = result?.userId;
666
+ if (warnedPreRenameShape || typeof userId !== "string") return;
667
+ warnedPreRenameShape = true;
668
+ warn(
669
+ "baton: resolvePrincipal returned { userId }, which was renamed to { principalId } in 0.3.5, so principal_id is dropped from every event until the hook returns the new key."
670
+ );
671
+ }
672
+ async function resolveCallPrincipalId(hook, call, options) {
661
673
  if (hook === void 0) return null;
662
674
  let result;
663
675
  try {
664
- const context = buildUserResolutionContext(call.extra, call.toolName, call.arguments);
676
+ const context = buildPrincipalResolutionContext(call.extra, call.toolName, call.arguments);
665
677
  result = await hook(context);
666
678
  } catch {
667
679
  return null;
668
680
  }
669
681
  const principal = normalizePrincipal(result);
670
- if (principal === null) return null;
682
+ if (principal === null) {
683
+ warnIfPreRenameShape(result);
684
+ return null;
685
+ }
671
686
  try {
672
- return userIdForPrincipal(principal, {
687
+ return principalIdFor(principal, {
673
688
  mode: options.mode,
674
689
  tenantId: options.tenantId,
675
690
  key: options.key
@@ -768,13 +783,13 @@ function registerAnnotationTool(server, options) {
768
783
  if (args.signal_type === void 0) {
769
784
  options.tracker?.mark(sessionId);
770
785
  }
771
- const userId = await resolveCallUserId(
772
- options.resolveUser,
786
+ const principalId = await resolveCallPrincipalId(
787
+ options.resolvePrincipal,
773
788
  { extra, toolName: name, arguments: args },
774
789
  {
775
- mode: options.userIdMode,
790
+ mode: options.principalIdMode,
776
791
  tenantId: options.tenantId,
777
- key: options.userIdHmacKey
792
+ key: options.principalIdHmacKey
778
793
  }
779
794
  );
780
795
  await emit(
@@ -787,7 +802,7 @@ function registerAnnotationTool(server, options) {
787
802
  captured_at: (/* @__PURE__ */ new Date()).toISOString(),
788
803
  consent_token: options.consentToken,
789
804
  agent_runtime: runtime,
790
- user_id: userId,
805
+ principal_id: principalId,
791
806
  runtime_meta: scrubbedMeta,
792
807
  payload: {
793
808
  // Agent-facing names -> wire keys, as with `overall_task`
@@ -1025,16 +1040,16 @@ function sealKey(dsn) {
1025
1040
 
1026
1041
  // src/integrations/mcp/config.ts
1027
1042
  var INTENT_PARAM_MODES = /* @__PURE__ */ new Set(["optional", "required", "off"]);
1028
- var USER_ID_MODES = /* @__PURE__ */ new Set(["hashed", "raw"]);
1043
+ var PRINCIPAL_ID_MODES = /* @__PURE__ */ new Set(["hashed", "raw"]);
1029
1044
  function resolveTenantId(explicit, vendorId) {
1030
1045
  if (explicit) return explicit;
1031
1046
  const fromEnv = typeof process !== "undefined" ? process.env?.BATON_TENANT_ID : void 0;
1032
1047
  if (fromEnv) return fromEnv;
1033
1048
  return vendorId;
1034
1049
  }
1035
- function resolveUserIdHmacKey(explicit) {
1050
+ function resolvePrincipalIdHmacKey(explicit) {
1036
1051
  if (explicit !== void 0) return explicit;
1037
- const fromEnv = typeof process !== "undefined" ? process.env?.BATON_USER_ID_HMAC_KEY : void 0;
1052
+ const fromEnv = typeof process !== "undefined" ? process.env?.BATON_PRINCIPAL_ID_HMAC_KEY : void 0;
1038
1053
  return fromEnv ? fromEnv : void 0;
1039
1054
  }
1040
1055
  function resolveBatonConfig(config, serverName) {
@@ -1094,7 +1109,17 @@ function resolveBatonConfig(config, serverName) {
1094
1109
  sink: new HttpSink(dsn.origin, { apiKey: dsn.key })
1095
1110
  };
1096
1111
  }
1112
+ var RENAMED_KEYS = {
1113
+ resolveUser: "resolvePrincipal",
1114
+ userIdMode: "principalIdMode",
1115
+ userIdHmacKey: "principalIdHmacKey"
1116
+ };
1097
1117
  function validateBatonConfig(config) {
1118
+ for (const [was, now] of Object.entries(RENAMED_KEYS)) {
1119
+ if (was in config) {
1120
+ throw new Error(`BatonConfig.${was} was renamed to ${now} in 0.3.5.`);
1121
+ }
1122
+ }
1098
1123
  if (!config.vendorId) {
1099
1124
  throw new Error(
1100
1125
  "BatonConfig needs a vendorId \u2014 either directly, or via a dsn whose last path segment names the server (see /account)."
@@ -1125,15 +1150,15 @@ function validateBatonConfig(config) {
1125
1150
  `BatonConfig.intentParamMode ${JSON.stringify(config.intentParamMode)} must be one of ${JSON.stringify([...INTENT_PARAM_MODES].sort())}.`
1126
1151
  );
1127
1152
  }
1128
- if (config.resolveUser !== void 0 && typeof config.resolveUser !== "function") {
1129
- throw new Error("BatonConfig.resolveUser must be a function.");
1153
+ if (config.resolvePrincipal !== void 0 && typeof config.resolvePrincipal !== "function") {
1154
+ throw new Error("BatonConfig.resolvePrincipal must be a function.");
1130
1155
  }
1131
- if (config.userIdHmacKey !== void 0 && typeof config.userIdHmacKey !== "string" && !(config.userIdHmacKey instanceof Uint8Array)) {
1132
- throw new Error("BatonConfig.userIdHmacKey must be a string or a Uint8Array.");
1156
+ if (config.principalIdHmacKey !== void 0 && typeof config.principalIdHmacKey !== "string" && !(config.principalIdHmacKey instanceof Uint8Array)) {
1157
+ throw new Error("BatonConfig.principalIdHmacKey must be a string or a Uint8Array.");
1133
1158
  }
1134
- if (config.userIdMode !== void 0 && !USER_ID_MODES.has(config.userIdMode)) {
1159
+ if (config.principalIdMode !== void 0 && !PRINCIPAL_ID_MODES.has(config.principalIdMode)) {
1135
1160
  throw new Error(
1136
- `BatonConfig.userIdMode ${JSON.stringify(config.userIdMode)} must be one of ${JSON.stringify([...USER_ID_MODES].sort())}.`
1161
+ `BatonConfig.principalIdMode ${JSON.stringify(config.principalIdMode)} must be one of ${JSON.stringify([...PRINCIPAL_ID_MODES].sort())}.`
1137
1162
  );
1138
1163
  }
1139
1164
  }
@@ -1305,28 +1330,28 @@ function toJsonSchemaCompat(schema, opts) {
1305
1330
  import { z as zV4 } from "zod";
1306
1331
  import { z as zV3 } from "zod/v3";
1307
1332
  var EMPTY_OBJECT_JSON_SCHEMA = { type: "object", properties: {} };
1308
- function injectGoalParams(inputSchema) {
1333
+ function injectGoalParams(inputSchema, intentParamMode) {
1309
1334
  const objSchema = normalizeObjectSchema(inputSchema);
1310
1335
  if (!objSchema) return { schema: inputSchema, dispositions: {} };
1311
1336
  const existingShape = getObjectShape(objSchema) ?? {};
1312
1337
  const values = Object.values(existingShape);
1313
1338
  const useV4 = values.length === 0 || isZ4Schema(values[0]);
1314
1339
  const zodImpl = useV4 ? zV4 : zV3;
1315
- const { dispositions, toInject } = buildIntentFields(existingShape, zodImpl);
1340
+ const { dispositions, toInject } = buildIntentFields(existingShape, zodImpl, intentParamMode);
1316
1341
  if (Object.keys(toInject).length === 0)
1317
1342
  return { schema: inputSchema, dispositions };
1318
1343
  const mergedShape = { ...existingShape, ...toInject };
1319
1344
  const newSchema = objectFromShape(mergedShape);
1320
1345
  return { schema: newSchema, dispositions };
1321
1346
  }
1322
- function buildIntentFields(existingShape, zodImpl) {
1347
+ function buildIntentFields(existingShape, zodImpl, intentParamMode) {
1323
1348
  const dispositions = {};
1324
1349
  const toInject = {};
1325
1350
  if (USER_GOAL_PARAM_NAME in existingShape) {
1326
1351
  dispositions[USER_GOAL_PARAM_NAME] = "native";
1327
1352
  } else {
1328
1353
  dispositions[USER_GOAL_PARAM_NAME] = "injected";
1329
- toInject[USER_GOAL_PARAM_NAME] = zodImpl.string().optional().describe(buildUserGoalParamDescription());
1354
+ toInject[USER_GOAL_PARAM_NAME] = zodImpl.string().optional().describe(buildUserGoalParamDescription({ intentParamMode }));
1330
1355
  }
1331
1356
  for (const [name, buildDescription] of [
1332
1357
  [EXPECTED_RESULT_PARAM_NAME, buildExpectedResultParamDescription],
@@ -1341,17 +1366,35 @@ function buildIntentFields(existingShape, zodImpl) {
1341
1366
  }
1342
1367
  return { dispositions, toInject };
1343
1368
  }
1344
- function injectGoalParamsV2(inputSchema) {
1369
+ function injectGoalParamsV2(inputSchema, intentParamMode) {
1345
1370
  const candidate = inputSchema;
1346
1371
  const shape = candidate?.shape;
1347
1372
  if (!shape || typeof shape !== "object" || typeof candidate?.extend !== "function") {
1348
1373
  return { schema: inputSchema, dispositions: {} };
1349
1374
  }
1350
- const { dispositions, toInject } = buildIntentFields(shape, zV4);
1375
+ const { dispositions, toInject } = buildIntentFields(shape, zV4, intentParamMode);
1351
1376
  if (Object.keys(toInject).length === 0)
1352
1377
  return { schema: inputSchema, dispositions };
1353
1378
  return { schema: candidate.extend(toInject), dispositions };
1354
1379
  }
1380
+ function advertiseUserGoalRequired(result, isInjected) {
1381
+ const tools = result?.tools;
1382
+ if (!Array.isArray(tools)) return result;
1383
+ let changed = false;
1384
+ const advertised = tools.map((tool) => {
1385
+ const entry = tool;
1386
+ if (typeof entry?.name !== "string" || !isInjected(entry.name)) return tool;
1387
+ const schema = entry.inputSchema;
1388
+ if (!schema || typeof schema !== "object") return tool;
1389
+ const declared = schema.required ?? [];
1390
+ if (!Array.isArray(declared)) return tool;
1391
+ const required = declared;
1392
+ if (required.includes(USER_GOAL_PARAM_NAME)) return tool;
1393
+ changed = true;
1394
+ return { ...entry, inputSchema: { ...schema, required: [...required, USER_GOAL_PARAM_NAME] } };
1395
+ });
1396
+ return changed ? { ...result, tools: advertised } : result;
1397
+ }
1355
1398
  function toolInputJsonSchema(inputSchema) {
1356
1399
  const objSchema = normalizeObjectSchema(inputSchema);
1357
1400
  if (!objSchema) return EMPTY_OBJECT_JSON_SCHEMA;
@@ -1488,10 +1531,10 @@ function batonWrap(nameRef, original, ctx) {
1488
1531
  const scrubbedExpected = rawExpected !== null ? ctx.scrubber(rawExpected) : null;
1489
1532
  const scrubbedWorkflow = rawWorkflow !== null ? ctx.scrubber(rawWorkflow) : null;
1490
1533
  const callId = uuidv72();
1491
- const userId = await resolveCallUserId(
1492
- ctx.resolveUser,
1534
+ const principalId = await resolveCallPrincipalId(
1535
+ ctx.resolvePrincipal,
1493
1536
  { extra, toolName, arguments: params },
1494
- { mode: ctx.userIdMode, tenantId: ctx.tenantId, key: ctx.userIdHmacKey }
1537
+ { mode: ctx.principalIdMode, tenantId: ctx.tenantId, key: ctx.principalIdHmacKey }
1495
1538
  );
1496
1539
  const common = {
1497
1540
  tenant_id: ctx.tenantId,
@@ -1504,7 +1547,7 @@ function batonWrap(nameRef, original, ctx) {
1504
1547
  // (`middleware.py` 481/524/562/606). `surface_snapshot` is deliberately
1505
1548
  // NOT among them: it describes the SERVER and is captured outside any
1506
1549
  // call, so there is no caller to name (register D5).
1507
- user_id: userId,
1550
+ principal_id: principalId,
1508
1551
  runtime_meta: scrubbedMeta
1509
1552
  };
1510
1553
  if (scrubbedIntent !== null && ctx.tracker.claim(sessionId)) {
@@ -1628,7 +1671,7 @@ function captureAndInject(name, entry, ctx) {
1628
1671
  if (ctx.intentParamMode === "off") return;
1629
1672
  const isV2 = typeof mutable.executor === "function";
1630
1673
  try {
1631
- const { schema, dispositions } = isV2 ? injectGoalParamsV2(mutable.inputSchema) : injectGoalParams(mutable.inputSchema);
1674
+ const { schema, dispositions } = isV2 ? injectGoalParamsV2(mutable.inputSchema, ctx.intentParamMode) : injectGoalParams(mutable.inputSchema, ctx.intentParamMode);
1632
1675
  if (Object.keys(dispositions).length > 0) {
1633
1676
  mutable.inputSchema = schema;
1634
1677
  ctx.bustSchemaMemo(name);
@@ -1639,6 +1682,46 @@ function captureAndInject(name, entry, ctx) {
1639
1682
  } catch {
1640
1683
  }
1641
1684
  }
1685
+ var TOOLS_LIST_METHOD = "tools/list";
1686
+ var TOOLS_LIST_SEAM = /* @__PURE__ */ Symbol("batonToolsListSeam");
1687
+ function installToolsListSeam(lowLevel, ctx) {
1688
+ const table = lowLevel._requestHandlers;
1689
+ const originalSet = lowLevel.setRequestHandler;
1690
+ if (!(table instanceof Map) || typeof originalSet !== "function") return;
1691
+ const handlers = table;
1692
+ const setRequestHandler = originalSet;
1693
+ const isInjected = (toolName) => ctx.paramRegistry.get(toolName)?.[USER_GOAL_PARAM_NAME] === "injected";
1694
+ const advertise = (result) => {
1695
+ try {
1696
+ return advertiseUserGoalRequired(result, isInjected);
1697
+ } catch (err) {
1698
+ process.stderr.write(
1699
+ `baton: tools/list advertisement failed; serving the SDK's own result: ${String(err)}
1700
+ `
1701
+ );
1702
+ return result;
1703
+ }
1704
+ };
1705
+ const wrapCurrent = () => {
1706
+ const handler = handlers.get(TOOLS_LIST_METHOD);
1707
+ if (typeof handler !== "function" || handler[TOOLS_LIST_SEAM]) return;
1708
+ const seamed = (...args) => {
1709
+ const out = handler(...args);
1710
+ return isThenable(out) ? out.then(advertise) : advertise(out);
1711
+ };
1712
+ seamed[TOOLS_LIST_SEAM] = true;
1713
+ handlers.set(TOOLS_LIST_METHOD, seamed);
1714
+ };
1715
+ wrapCurrent();
1716
+ lowLevel.setRequestHandler = (...args) => {
1717
+ const registered = setRequestHandler.apply(lowLevel, args);
1718
+ wrapCurrent();
1719
+ return registered;
1720
+ };
1721
+ }
1722
+ function isThenable(value) {
1723
+ return typeof value?.then === "function";
1724
+ }
1642
1725
  function wrapIfNeeded(nameRef, entry, ctx) {
1643
1726
  if (!entry || typeof entry !== "object") return;
1644
1727
  const mutable = entry;
@@ -1729,7 +1812,7 @@ function withBaton(server, supplied = {}) {
1729
1812
  const config = resolveBatonConfig(supplied, serverName);
1730
1813
  const sink = config.sink ?? new StdoutSink();
1731
1814
  const annotationToolName = resolveAnnotationToolName(serverName, config);
1732
- const intentParamMode = config.intentParamMode ?? "optional";
1815
+ const intentParamMode = config.intentParamMode ?? "required";
1733
1816
  const counter = new SessionCounter();
1734
1817
  const fallbackSessionId = `sdk-${uuidv72()}`;
1735
1818
  const tenantId = resolveTenantId(config.tenantId, config.vendorId);
@@ -1811,9 +1894,9 @@ function withBaton(server, supplied = {}) {
1811
1894
  annotationToolName,
1812
1895
  intentParamMode,
1813
1896
  paramRegistry: /* @__PURE__ */ new Map(),
1814
- resolveUser: config.resolveUser,
1815
- userIdMode: config.userIdMode ?? "hashed",
1816
- userIdHmacKey: resolveUserIdHmacKey(config.userIdHmacKey),
1897
+ resolvePrincipal: config.resolvePrincipal,
1898
+ principalIdMode: config.principalIdMode ?? "hashed",
1899
+ principalIdHmacKey: resolvePrincipalIdHmacKey(config.principalIdHmacKey),
1817
1900
  vendorToolJsonSchema,
1818
1901
  bustSchemaMemo,
1819
1902
  tracker,
@@ -1826,6 +1909,7 @@ function withBaton(server, supplied = {}) {
1826
1909
  annotationToolName
1827
1910
  });
1828
1911
  internals.server._instructions = instructions;
1912
+ if (intentParamMode === "required") installToolsListSeam(internals.server, ctx);
1829
1913
  const resolvedAnnotationToolName = registerAnnotationTool(server, {
1830
1914
  sink,
1831
1915
  counter: ctx.counter,
@@ -1834,14 +1918,14 @@ function withBaton(server, supplied = {}) {
1834
1918
  vendorDisplayName: config.vendorDisplayName,
1835
1919
  consentToken: ctx.consentToken,
1836
1920
  // Read off `ctx`, never re-resolved from `config`: the two paths must
1837
- // agree on the actor, and `userIdMode`/`userIdHmacKey` each have a
1921
+ // agree on the actor, and `principalIdMode`/`principalIdHmacKey` each have a
1838
1922
  // default and an env fallback that a second resolution could take
1839
1923
  // differently. Required (not optional) on the options type ON PURPOSE —
1840
1924
  // the compiler then refuses a registration that forgets them, which is
1841
1925
  // the mechanical version of "wiring two of four call sites".
1842
- resolveUser: ctx.resolveUser,
1843
- userIdMode: ctx.userIdMode,
1844
- userIdHmacKey: ctx.userIdHmacKey,
1926
+ resolvePrincipal: ctx.resolvePrincipal,
1927
+ principalIdMode: ctx.principalIdMode,
1928
+ principalIdHmacKey: ctx.principalIdHmacKey,
1845
1929
  fallbackSessionId: ctx.fallbackSessionId,
1846
1930
  scrubber: ctx.scrubber,
1847
1931
  // The RESOLVED name, never `config.annotationToolName`: handing over the
@@ -1890,7 +1974,7 @@ export {
1890
1974
  ToolCallStartEventSchema,
1891
1975
  ToolCallStartPayloadSchema,
1892
1976
  VENDOR_HASH_SCHEME,
1893
- hashUserId,
1977
+ hashPrincipalId,
1894
1978
  identityScrub,
1895
1979
  safeWrite,
1896
1980
  withBaton