@genesislcap/ai-assistant 15.5.0 → 15.6.1

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.
@@ -2793,9 +2793,15 @@ function triggerLabel(trigger) {
2793
2793
  function estimateTokensSaved(origLen, stubLen) {
2794
2794
  return Math.max(0, Math.ceil((origLen - stubLen) / APPROX_CHARS_PER_TOKEN));
2795
2795
  }
2796
+ function marksDiscontinuity(kind) {
2797
+ return kind === "agentEnd" || kind === "phaseEnd";
2798
+ }
2796
2799
  function applyCondensation(history, policies, ctx, onCondensed) {
2797
2800
  if (policies.size === 0) return history;
2798
2801
  const triggersOf = (entry) => Array.isArray(entry.policy.on) ? entry.policy.on : [entry.policy.on];
2802
+ const batchCalls = Math.max(1, Math.floor(ctx.batchCalls ?? 1));
2803
+ const asOf = batchCalls === 1 ? ctx.modelCall : Math.floor(ctx.modelCall / batchCalls) * batchCalls;
2804
+ const withinBatch = (entry) => batchCalls === 1 || entry.iteration <= asOf;
2799
2805
  const latestByKey = /* @__PURE__ */ new Map();
2800
2806
  const nameById = /* @__PURE__ */ new Map();
2801
2807
  for (const msg of history) {
@@ -2803,7 +2809,7 @@ function applyCondensation(history, policies, ctx, onCondensed) {
2803
2809
  for (const tc of msg.toolCalls) {
2804
2810
  nameById.set(tc.id, tc.name);
2805
2811
  const entry = policies.get(tc.id);
2806
- if (!entry) continue;
2812
+ if (!entry || !withinBatch(entry)) continue;
2807
2813
  for (const t of triggersOf(entry)) {
2808
2814
  if (t.kind === "superseded") latestByKey.set(t.by, tc.id);
2809
2815
  }
@@ -2815,7 +2821,7 @@ function applyCondensation(history, policies, ctx, onCondensed) {
2815
2821
  // past the last allowed view: turns:1 → seen once, then gone. Monotonic
2816
2822
  // clock, so this holds across turn boundaries too.
2817
2823
  case "age":
2818
- return ctx.modelCall - entry.iteration > trig.turns;
2824
+ return asOf - entry.iteration > trig.turns;
2819
2825
  case "turnEnd":
2820
2826
  return ctx.turn > entry.turn;
2821
2827
  case "agentEnd":
@@ -2829,7 +2835,9 @@ function applyCondensation(history, policies, ctx, onCondensed) {
2829
2835
  return latestByKey.get(trig.by) !== toolCallId;
2830
2836
  }
2831
2837
  };
2832
- const firstFired = (toolCallId, entry) => triggersOf(entry).find((t) => triggerFires(toolCallId, entry, t));
2838
+ const firstFired = (toolCallId, entry) => triggersOf(entry).find(
2839
+ (t) => (marksDiscontinuity(t.kind) || withinBatch(entry)) && triggerFires(toolCallId, entry, t)
2840
+ );
2833
2841
  return history.map((msg) => {
2834
2842
  if (msg.toolCalls?.length) {
2835
2843
  let changed = false;
@@ -3210,11 +3218,13 @@ var ChatDriver = class _ChatDriver extends EventTarget {
3210
3218
  primerHistory,
3211
3219
  maxToolIterations = DEFAULT_MAX_TOOL_ITERATIONS,
3212
3220
  maxFoldOperations = DEFAULT_MAX_FOLD_OPERATIONS,
3221
+ condenseBatchCalls = 1,
3213
3222
  maxTurnSnapshots = DEFAULT_MAX_TURN_SNAPSHOTS,
3214
3223
  sessionKey = "",
3215
3224
  activityBus = NOOP_ACTIVITY_BUS
3216
3225
  } = config;
3217
3226
  this.maxToolIterations = maxToolIterations;
3227
+ this.condenseBatchCalls = condenseBatchCalls;
3218
3228
  this.sessionKey = sessionKey;
3219
3229
  this.activityBus = activityBus;
3220
3230
  if (typeof toolHandlers === "function") {
@@ -4453,7 +4463,8 @@ Output format (strict):
4453
4463
  activationEnded: (activation) => activation < this.currentActivation,
4454
4464
  // A call's phase has ended once the app declared a later phase epoch
4455
4465
  // current via `endPhase()`.
4456
- phaseEnded: (phaseEpoch) => phaseEpoch < this.currentPhaseEpoch
4466
+ phaseEnded: (phaseEpoch) => phaseEpoch < this.currentPhaseEpoch,
4467
+ batchCalls: this.condenseBatchCalls
4457
4468
  },
4458
4469
  (detail) => recordMetaEvent(this.sessionKey, "context.condensed", detail)
4459
4470
  );