@genesislcap/ai-assistant 15.10.3 → 15.10.5

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.
@@ -3044,10 +3044,11 @@ function triggerReason(trigger) {
3044
3044
  return "superseded";
3045
3045
  }
3046
3046
  }
3047
- function condenseStub(target, tool, trigger, origLen) {
3047
+ function condenseStub(target, tool, trigger, origLen, restorable) {
3048
3048
  const what = target === "args" ? "args" : "result";
3049
3049
  const key = trigger.kind === "superseded" ? ` ${trigger.by}` : "";
3050
- return `[${tool}${key} \u2014 ${what} elided, ~${origLen} chars (${triggerReason(trigger)}); re-call to restore]`;
3050
+ const restore = restorable ? "; re-call to restore" : "";
3051
+ return `[${tool}${key} \u2014 ${what} elided, ~${origLen} chars (${triggerReason(trigger)})${restore}]`;
3051
3052
  }
3052
3053
  function triggerLabel(trigger) {
3053
3054
  switch (trigger.kind) {
@@ -3104,9 +3105,14 @@ function applyCondensation(history, policies, ctx, onCondensed) {
3104
3105
  return latestByKey.get(trig.by) !== toolCallId;
3105
3106
  }
3106
3107
  };
3107
- const firstFired = (toolCallId, entry) => triggersOf(entry).find(
3108
- (t) => (marksDiscontinuity(t.kind) || withinBatch(entry)) && triggerFires(toolCallId, entry, t)
3109
- );
3108
+ const firstFired = (toolCallId, entry) => {
3109
+ if (entry.firedTrigger) return entry.firedTrigger;
3110
+ const fired = triggersOf(entry).find(
3111
+ (t) => (marksDiscontinuity(t.kind) || withinBatch(entry)) && triggerFires(toolCallId, entry, t)
3112
+ );
3113
+ if (fired) entry.firedTrigger = fired;
3114
+ return fired;
3115
+ };
3110
3116
  return history.map((msg) => {
3111
3117
  if (msg.toolCalls?.length) {
3112
3118
  let changed = false;
@@ -3119,8 +3125,8 @@ function applyCondensation(history, policies, ctx, onCondensed) {
3119
3125
  if (origLen < CONDENSE_MIN_CHARS) return tc;
3120
3126
  changed = true;
3121
3127
  const result = entry.policy.args;
3122
- const args = result === "drop" ? {} : {
3123
- [CONDENSED_ARGS_KEY]: result === "pointer" ? condenseStub("args", tc.name, fired, origLen) : result.replaceWith
3128
+ const args = {
3129
+ [CONDENSED_ARGS_KEY]: result === "drop" || result === "pointer" ? condenseStub("args", tc.name, fired, origLen, result === "pointer") : result.replaceWith
3124
3130
  };
3125
3131
  if (!entry.reportedArgs) {
3126
3132
  entry.reportedArgs = true;
@@ -3146,7 +3152,7 @@ function applyCondensation(history, policies, ctx, onCondensed) {
3146
3152
  if (entry && fired && origLen >= CONDENSE_MIN_CHARS) {
3147
3153
  const tool = nameById.get(msg.toolResult.toolCallId) ?? msg.toolResult.toolCallId;
3148
3154
  const result = entry.policy.response;
3149
- const content = result === "drop" ? "[elided]" : result === "pointer" ? condenseStub("response", tool, fired, origLen) : result.replaceWith;
3155
+ const content = result === "drop" || result === "pointer" ? condenseStub("response", tool, fired, origLen, result === "pointer") : result.replaceWith;
3150
3156
  if (!entry.reportedResponse) {
3151
3157
  entry.reportedResponse = true;
3152
3158
  onCondensed({
@@ -3520,13 +3526,13 @@ var ChatDriver = class _ChatDriver extends EventTarget {
3520
3526
  maxTurnSnapshots = DEFAULT_MAX_TURN_SNAPSHOTS,
3521
3527
  sessionKey = "",
3522
3528
  activityBus = NOOP_ACTIVITY_BUS,
3523
- budgetExhaustedMessage = DEFAULT_BUDGET_EXHAUSTED_MESSAGE
3529
+ budgetExhaustedMessage
3524
3530
  } = config;
3525
3531
  this.maxToolIterations = maxToolIterations;
3526
3532
  this.condenseBatchCalls = condenseBatchCalls;
3527
3533
  this.sessionKey = sessionKey;
3528
3534
  this.activityBus = activityBus;
3529
- this.budgetExhaustedMessage = budgetExhaustedMessage;
3535
+ this.budgetExhaustedMessageOverride = budgetExhaustedMessage;
3530
3536
  if (typeof toolHandlers === "function") {
3531
3537
  this.toolHandlersFactory = toolHandlers;
3532
3538
  this.toolHandlers = {};
@@ -3663,6 +3669,12 @@ var ChatDriver = class _ChatDriver extends EventTarget {
3663
3669
  *
3664
3670
  * @internal
3665
3671
  */
3672
+ budgetExhaustedBubble(wall) {
3673
+ if (this.budgetExhaustedMessageOverride != null) return this.budgetExhaustedMessageOverride;
3674
+ if (wall?.otherVendorAvailable !== true) return DEFAULT_BUDGET_EXHAUSTED_MESSAGE;
3675
+ const subject = wall?.vendorLabel ? `${wall.vendorLabel}'s AI usage limit` : "your AI usage limit";
3676
+ return `You've reached ${subject}. Switch to another AI provider in Settings to keep going, or contact your administrator to raise it.`;
3677
+ }
3666
3678
  reportBudgetExhausted(e, pendingUserMessage) {
3667
3679
  if (pendingUserMessage) this.appendToHistory(pendingUserMessage);
3668
3680
  this.budgetExhaustedThisTurn = true;
@@ -3681,7 +3693,7 @@ var ChatDriver = class _ChatDriver extends EventTarget {
3681
3693
  spentUsd: e.spentUsd,
3682
3694
  isSubAgent: this.isSubAgent
3683
3695
  });
3684
- this.appendToHistory({ role: "assistant", content: this.budgetExhaustedMessage });
3696
+ this.appendToHistory({ role: "assistant", content: this.budgetExhaustedBubble(e) });
3685
3697
  return this.turnDone("budget-exhausted", budgetDetailOf(e));
3686
3698
  }
3687
3699
  /** The typed failure reason on a loop result, or `undefined` for a clean turn / handoff. */
@@ -4810,7 +4822,10 @@ Output format (strict):
4810
4822
  if (this.isSubAgent) {
4811
4823
  this.failSubAgent("budget_exhausted", this.budgetWallDetail);
4812
4824
  } else {
4813
- this.appendToHistory({ role: "assistant", content: this.budgetExhaustedMessage });
4825
+ this.appendToHistory({
4826
+ role: "assistant",
4827
+ content: this.budgetExhaustedBubble(this.budgetWallDetail)
4828
+ });
4814
4829
  }
4815
4830
  return this.turnDone("budget-exhausted", this.budgetWallDetail);
4816
4831
  }