@goodtiming/baton-sdk 0.6.5 → 0.6.7

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.6.5";
3
+ declare const SDK_VERSION = "ts-0.6.7";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
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.6.5";
3
+ declare const SDK_VERSION = "ts-0.6.7";
4
4
 
5
5
  /**
6
6
  * Zod schemas + TS types for the Baton event stream per SPEC §11.4.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var SDK_VERSION = "ts-0.6.5";
2
+ var SDK_VERSION = "ts-0.6.7";
3
3
 
4
4
  // src/events.ts
5
5
  import { z } from "zod";
@@ -599,9 +599,11 @@ var PROCESS_DROPS = new DropCounts();
599
599
 
600
600
  // src/sequence.ts
601
601
  var lastSequence = 0;
602
+ function nowMicros() {
603
+ return Math.floor((performance.timeOrigin + performance.now()) * 1e3);
604
+ }
602
605
  function nextClockSequence() {
603
- const nowMicros = Math.floor((performance.timeOrigin + performance.now()) * 1e3);
604
- lastSequence = Math.max(lastSequence + 1, nowMicros);
606
+ lastSequence = Math.max(lastSequence + 1, nowMicros());
605
607
  return lastSequence;
606
608
  }
607
609
 
@@ -2574,17 +2576,20 @@ var BatonHandle = class {
2574
2576
  };
2575
2577
 
2576
2578
  // src/integrations/mcp/sessionCounter.ts
2579
+ var SESSION_CAP = 4096;
2577
2580
  var SessionCounter = class {
2578
2581
  counters = /* @__PURE__ */ new Map();
2579
- /** A per-call session is numbered by the clock: a counter would keep an
2580
- * entry for every request the process serves. */
2582
+ /** A per-call session is numbered by the clock: a counter would fill with
2583
+ * sessions that never come back and push out live ones. */
2581
2584
  nextFor(session) {
2582
- return session.perCall ? nextClockSequence() : this.next(session.sessionId);
2585
+ return session.perCall ? nextClockSequence() : this.next(session.sessionId, session.origin === "observed");
2583
2586
  }
2584
- next(sessionId) {
2585
- const current2 = this.counters.get(sessionId) ?? 0;
2586
- const next = current2 + 1;
2587
+ next(sessionId, observed) {
2588
+ const previous = this.counters.get(sessionId) ?? 0;
2589
+ const next = observed ? Math.max(previous + 1, nowMicros()) : previous + 1;
2590
+ this.counters.delete(sessionId);
2587
2591
  this.counters.set(sessionId, next);
2592
+ if (this.counters.size > SESSION_CAP) this.counters.delete(this.counters.keys().next().value);
2588
2593
  return next;
2589
2594
  }
2590
2595
  };
@@ -2597,8 +2602,8 @@ var ServerCounter = class extends SessionCounter {
2597
2602
  shared;
2598
2603
  ownSessionId;
2599
2604
  ownSequence = 0;
2600
- next(sessionId) {
2601
- return sessionId === this.ownSessionId ? ++this.ownSequence : this.shared.next(sessionId);
2605
+ next(sessionId, observed) {
2606
+ return sessionId === this.ownSessionId ? ++this.ownSequence : this.shared.next(sessionId, observed);
2602
2607
  }
2603
2608
  };
2604
2609
 
@@ -3273,10 +3278,9 @@ function installLifecycleSeam(lowLevel, ctx, spec) {
3273
3278
  } catch (err) {
3274
3279
  await fire(spec.schemas.error, {
3275
3280
  error_type: errorTypeOf(err),
3276
- // KEPT under every capture mode: a failed FETCH's message is the
3277
- // producer's own diagnostic, not anything a resource returned, so
3278
- // nothing here is result-derived (SPEC §11.4.4). The scrub and the cap
3279
- // are `scrubLifecyclePayload`'s, in that order.
3281
+ // KEPT under every capture mode (SPEC §11.4.4), though it can quote what
3282
+ // the handler fetched, so `"off"` warns instead: `warnAboutSettings`.
3283
+ // The scrub and the cap are `scrubLifecyclePayload`'s, in that order.
3280
3284
  error_body: messageOf(err),
3281
3285
  duration_ms: elapsed()
3282
3286
  });
@@ -3613,9 +3617,9 @@ function withBaton(server, supplied = {}) {
3613
3617
  return inertHandle(supplied.sink ?? new DisabledSink(), "baton-disabled");
3614
3618
  }
3615
3619
  const { resolved, unconfigured } = resolveInstallConfig(supplied);
3616
- if (!unconfigured) warnUnusedReportSettings(resolved);
3617
3620
  const handle = install(server, supplied, resolved, newBatonState(resolved), unconfigured);
3618
3621
  if (unconfigured) logUnconfigured("withBaton");
3622
+ else warnAboutSettings(resolved);
3619
3623
  return handle;
3620
3624
  }
3621
3625
  function createBaton(supplied = {}) {
@@ -3633,7 +3637,7 @@ function createBaton(supplied = {}) {
3633
3637
  const { resolved, unconfigured } = resolveInstallConfig(supplied);
3634
3638
  if (resolved.reportMode === "on") deriveAnnotationToolName(resolved.vendorId, supplied.annotationToolName);
3635
3639
  if (unconfigured) logUnconfigured("createBaton");
3636
- else warnUnusedReportSettings(resolved);
3640
+ else warnAboutSettings(resolved);
3637
3641
  const sink = unconfigured ? new DisabledSink() : resolved.sink ?? new StdoutSink();
3638
3642
  const config = {
3639
3643
  ...resolved,
@@ -3694,7 +3698,7 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned3, co
3694
3698
  session_id: sessionId,
3695
3699
  session_id_origin: "minted",
3696
3700
  consent_token: config.consentToken,
3697
- sequence_number: counter2.next(sessionId),
3701
+ sequence_number: counter2.next(sessionId, false),
3698
3702
  captured_at: (/* @__PURE__ */ new Date()).toISOString(),
3699
3703
  payload: {
3700
3704
  surface_hash: digest,
@@ -3839,13 +3843,18 @@ function reportsFor(config) {
3839
3843
  if (config.reportMode !== "on") return void 0;
3840
3844
  return { vendorDisplayName: config.vendorDisplayName ?? "" };
3841
3845
  }
3842
- function warnUnusedReportSettings(config) {
3846
+ function warnAboutSettings(config) {
3843
3847
  if (config.reportMode !== "on" && config.annotationToolName !== void 0) {
3844
3848
  process.stderr.write(
3845
3849
  `baton: annotationToolName=${JSON.stringify(config.annotationToolName)} has no effect with reportMode: "off", because no annotation tool is registered
3846
3850
  `
3847
3851
  );
3848
3852
  }
3853
+ if (config.resultCaptureMode === WITHHELD) {
3854
+ warn(
3855
+ 'baton: resultCaptureMode "off" does not withhold the message of a failed resource or prompt request. resource_list_error, resource_read_error, prompt_list_error and prompt_get_error carry that message, which can quote what your handler fetched. Throw a message that names the resource or prompt, not its contents.'
3856
+ );
3857
+ }
3849
3858
  }
3850
3859
 
3851
3860
  // src/integrations/mcp/oauthHooks.ts