@goodtiming/baton-sdk 0.6.6 → 0.6.8

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.6";
3
+ declare const SDK_VERSION = "ts-0.6.8";
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.6";
3
+ declare const SDK_VERSION = "ts-0.6.8";
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.6";
2
+ var SDK_VERSION = "ts-0.6.8";
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
 
@@ -3693,7 +3698,7 @@ function install(server, supplied, resolved, { sentSurfaces, warned: warned3, co
3693
3698
  session_id: sessionId,
3694
3699
  session_id_origin: "minted",
3695
3700
  consent_token: config.consentToken,
3696
- sequence_number: counter2.next(sessionId),
3701
+ sequence_number: counter2.next(sessionId, false),
3697
3702
  captured_at: (/* @__PURE__ */ new Date()).toISOString(),
3698
3703
  payload: {
3699
3704
  surface_hash: digest,
@@ -3847,7 +3852,7 @@ function warnAboutSettings(config) {
3847
3852
  }
3848
3853
  if (config.resultCaptureMode === WITHHELD) {
3849
3854
  warn(
3850
- '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.'
3855
+ 'baton: resultCaptureMode "off" does not withhold the message of a failed tool list, resource or prompt request. tool_list_error, resource_list_error, resource_read_error, prompt_list_error and prompt_get_error carry that message, which can include text your handler or middleware threw. Throw a message that does not quote what your code fetched.'
3851
3856
  );
3852
3857
  }
3853
3858
  }