@goodtiming/baton-sdk 0.1.0 → 0.2.0

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.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
 
3
- declare const SDK_VERSION = "ts-0.1.0";
3
+ declare const SDK_VERSION = "ts-0.2.0";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -519,10 +519,26 @@ interface SessionResolutionContext {
519
519
  }
520
520
  type ResolveSessionIdHook = (context: SessionResolutionContext) => string | null | undefined | Promise<string | null | undefined>;
521
521
  interface BatonConfig {
522
- /** Short stable identifier for the vendor (e.g. `"acme"`). Also used as
523
- * `tenant_id` on every emitted event (vendor-mode tenancy) and as the
524
- * default annotation tool name prefix (`{vendorId}_annotate`). */
522
+ /** Short stable identifier for the SERVER whose surface is captured
523
+ * (e.g. `"acme"`). Also the default annotation tool name prefix
524
+ * (`{vendorId}_annotate`). This is not the account — see `tenantId`. */
525
525
  vendorId: string;
526
+ /** Account identifier for the envelope's `tenant_id` (SPEC §11.4).
527
+ *
528
+ * **This is not `vendorId`, and conflating them is the bug this field
529
+ * exists to fix.** `tenantId` names the ACCOUNT the collector
530
+ * authenticates; `vendorId` names the SERVER whose surface is being
531
+ * captured. One account wraps many servers, so sending the account id in
532
+ * both slots collapses them: two servers in one workspace render as one,
533
+ * whose label flips to whichever deployed last, and a server ends up
534
+ * naming itself with its workspace's opaque id.
535
+ *
536
+ * Resolved explicit → `BATON_TENANT_ID` → `vendorId`. That last fallback
537
+ * exists for our own fixtures during the change, not for anyone's install
538
+ * — a wrap block states this value on its own line, because it is the diff
539
+ * a customer reviews in their pull request. The environment read is
540
+ * guarded, so this package still loads on runtimes with no `process`. */
541
+ tenantId?: string;
526
542
  /** Human-readable vendor name used in server instructions and the
527
543
  * annotation tool description — whitelabel obligation (SPEC §5.4): no
528
544
  * Baton-branded strings reach the calling agent. */
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.1.0";
3
+ declare const SDK_VERSION = "ts-0.2.0";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
@@ -519,10 +519,26 @@ interface SessionResolutionContext {
519
519
  }
520
520
  type ResolveSessionIdHook = (context: SessionResolutionContext) => string | null | undefined | Promise<string | null | undefined>;
521
521
  interface BatonConfig {
522
- /** Short stable identifier for the vendor (e.g. `"acme"`). Also used as
523
- * `tenant_id` on every emitted event (vendor-mode tenancy) and as the
524
- * default annotation tool name prefix (`{vendorId}_annotate`). */
522
+ /** Short stable identifier for the SERVER whose surface is captured
523
+ * (e.g. `"acme"`). Also the default annotation tool name prefix
524
+ * (`{vendorId}_annotate`). This is not the account — see `tenantId`. */
525
525
  vendorId: string;
526
+ /** Account identifier for the envelope's `tenant_id` (SPEC §11.4).
527
+ *
528
+ * **This is not `vendorId`, and conflating them is the bug this field
529
+ * exists to fix.** `tenantId` names the ACCOUNT the collector
530
+ * authenticates; `vendorId` names the SERVER whose surface is being
531
+ * captured. One account wraps many servers, so sending the account id in
532
+ * both slots collapses them: two servers in one workspace render as one,
533
+ * whose label flips to whichever deployed last, and a server ends up
534
+ * naming itself with its workspace's opaque id.
535
+ *
536
+ * Resolved explicit → `BATON_TENANT_ID` → `vendorId`. That last fallback
537
+ * exists for our own fixtures during the change, not for anyone's install
538
+ * — a wrap block states this value on its own line, because it is the diff
539
+ * a customer reviews in their pull request. The environment read is
540
+ * guarded, so this package still loads on runtimes with no `process`. */
541
+ tenantId?: string;
526
542
  /** Human-readable vendor name used in server instructions and the
527
543
  * annotation tool description — whitelabel obligation (SPEC §5.4): no
528
544
  * Baton-branded strings reach the calling agent. */
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SDK_VERSION = "ts-0.1.0";
2
+ var SDK_VERSION = "ts-0.2.0";
3
3
 
4
4
  // src/events.ts
5
5
  import { z } from "zod";
@@ -569,6 +569,12 @@ function registerAnnotationTool(server, options) {
569
569
  // src/integrations/mcp/config.ts
570
570
  var VENDOR_ID_PATTERN = /^[a-zA-Z0-9_-]{1,48}$/;
571
571
  var INTENT_PARAM_MODES = /* @__PURE__ */ new Set(["optional", "required", "off"]);
572
+ function resolveTenantId(explicit, vendorId) {
573
+ if (explicit) return explicit;
574
+ const fromEnv = typeof process !== "undefined" ? process.env?.BATON_TENANT_ID : void 0;
575
+ if (fromEnv) return fromEnv;
576
+ return vendorId;
577
+ }
572
578
  function validateBatonConfig(config) {
573
579
  if (!VENDOR_ID_PATTERN.test(config.vendorId)) {
574
580
  throw new Error(
@@ -1114,12 +1120,13 @@ function withBaton(server, config) {
1114
1120
  const intentParamMode = config.intentParamMode ?? "optional";
1115
1121
  const counter = new SessionCounter();
1116
1122
  const fallbackSessionId = `sdk-${uuidv72()}`;
1123
+ const tenantId = resolveTenantId(config.tenantId, config.vendorId);
1117
1124
  const scrubber = config.scrubber ?? new Scrubber().scrub;
1118
1125
  const serverMeta = buildServerMeta(server.server);
1119
1126
  const surfaceState = new SurfaceState(serverMeta);
1120
1127
  const emitSurface = async (sessionId, digest, snapshot) => {
1121
1128
  const event = SurfaceSnapshotEventSchema.parse({
1122
- tenant_id: config.vendorId,
1129
+ tenant_id: tenantId,
1123
1130
  vendor_id: config.vendorId,
1124
1131
  session_id: sessionId,
1125
1132
  consent_token: config.consentToken,
@@ -1167,7 +1174,7 @@ function withBaton(server, config) {
1167
1174
  const ctx = {
1168
1175
  sink,
1169
1176
  counter,
1170
- tenantId: config.vendorId,
1177
+ tenantId,
1171
1178
  vendorId: config.vendorId,
1172
1179
  consentToken: config.consentToken,
1173
1180
  fallbackSessionId,