@goodtiming/baton-sdk 0.1.0 → 0.3.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/README.md +20 -2
- package/dist/index.cjs +10 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -4
- package/dist/index.d.ts +20 -4
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
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
|
+
declare const SDK_VERSION = "ts-0.3.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
|
|
523
|
-
* `
|
|
524
|
-
*
|
|
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.
|
|
3
|
+
declare const SDK_VERSION = "ts-0.3.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
|
|
523
|
-
* `
|
|
524
|
-
*
|
|
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.
|
|
2
|
+
var SDK_VERSION = "ts-0.3.0";
|
|
3
3
|
|
|
4
4
|
// src/events.ts
|
|
5
5
|
import { z } from "zod";
|
|
@@ -457,11 +457,6 @@ function extraMeta(extra) {
|
|
|
457
457
|
// src/integrations/mcp/runtimeAdapter.ts
|
|
458
458
|
function detectAgentRuntime(meta) {
|
|
459
459
|
if (!meta) return null;
|
|
460
|
-
const batonMeta = meta["baton"];
|
|
461
|
-
if (batonMeta && typeof batonMeta === "object") {
|
|
462
|
-
const runtime = batonMeta["agent_runtime"];
|
|
463
|
-
if (typeof runtime === "string" && runtime) return runtime;
|
|
464
|
-
}
|
|
465
460
|
for (const key of Object.keys(meta)) {
|
|
466
461
|
if (key.startsWith("claudecode/")) return "claude-code";
|
|
467
462
|
}
|
|
@@ -569,6 +564,12 @@ function registerAnnotationTool(server, options) {
|
|
|
569
564
|
// src/integrations/mcp/config.ts
|
|
570
565
|
var VENDOR_ID_PATTERN = /^[a-zA-Z0-9_-]{1,48}$/;
|
|
571
566
|
var INTENT_PARAM_MODES = /* @__PURE__ */ new Set(["optional", "required", "off"]);
|
|
567
|
+
function resolveTenantId(explicit, vendorId) {
|
|
568
|
+
if (explicit) return explicit;
|
|
569
|
+
const fromEnv = typeof process !== "undefined" ? process.env?.BATON_TENANT_ID : void 0;
|
|
570
|
+
if (fromEnv) return fromEnv;
|
|
571
|
+
return vendorId;
|
|
572
|
+
}
|
|
572
573
|
function validateBatonConfig(config) {
|
|
573
574
|
if (!VENDOR_ID_PATTERN.test(config.vendorId)) {
|
|
574
575
|
throw new Error(
|
|
@@ -1114,12 +1115,13 @@ function withBaton(server, config) {
|
|
|
1114
1115
|
const intentParamMode = config.intentParamMode ?? "optional";
|
|
1115
1116
|
const counter = new SessionCounter();
|
|
1116
1117
|
const fallbackSessionId = `sdk-${uuidv72()}`;
|
|
1118
|
+
const tenantId = resolveTenantId(config.tenantId, config.vendorId);
|
|
1117
1119
|
const scrubber = config.scrubber ?? new Scrubber().scrub;
|
|
1118
1120
|
const serverMeta = buildServerMeta(server.server);
|
|
1119
1121
|
const surfaceState = new SurfaceState(serverMeta);
|
|
1120
1122
|
const emitSurface = async (sessionId, digest, snapshot) => {
|
|
1121
1123
|
const event = SurfaceSnapshotEventSchema.parse({
|
|
1122
|
-
tenant_id:
|
|
1124
|
+
tenant_id: tenantId,
|
|
1123
1125
|
vendor_id: config.vendorId,
|
|
1124
1126
|
session_id: sessionId,
|
|
1125
1127
|
consent_token: config.consentToken,
|
|
@@ -1167,7 +1169,7 @@ function withBaton(server, config) {
|
|
|
1167
1169
|
const ctx = {
|
|
1168
1170
|
sink,
|
|
1169
1171
|
counter,
|
|
1170
|
-
tenantId
|
|
1172
|
+
tenantId,
|
|
1171
1173
|
vendorId: config.vendorId,
|
|
1172
1174
|
consentToken: config.consentToken,
|
|
1173
1175
|
fallbackSessionId,
|