@livx.cc/agentx 0.99.126 → 0.99.127

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/cli.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env bun
2
- import { w as RouterState, H as Hooks, c as AgentOptions, x as RunResult, f as ChatUsage, R as ReasoningEffort, d as ChannelMode, b as Agent } from './secondChannel-B76KLrf7.js';
2
+ import { w as RouterState, H as Hooks, c as AgentOptions, x as RunResult, f as ChatUsage, R as ReasoningEffort, d as ChannelMode, b as Agent } from './secondChannel-CYU9qqwr.js';
3
3
  import { IFilesystem } from '@livx.cc/wcli/core';
4
4
  import { M as Message, U as UserQuestion, H as HostBridge, c as ContentPart, o as MessageContent } from './tools-DwfeF8VQ.js';
5
5
 
package/dist/cli.js CHANGED
@@ -5326,6 +5326,7 @@ var Agent = class _Agent {
5326
5326
  return texts;
5327
5327
  }
5328
5328
  /** Fold any host-injected messages into the transcript as user turns. Returns true if any landed. */
5329
+ reopen = () => this.drainInjections();
5329
5330
  drainInjections() {
5330
5331
  if (!this.pendingInjections.length) return false;
5331
5332
  for (const content of this.pendingInjections.splice(0)) this.transcript.push({ role: "user", content });
@@ -5596,6 +5597,14 @@ var Agent = class _Agent {
5596
5597
  };
5597
5598
  const overBudget = () => !!o.maxTokens && spent >= o.maxTokens;
5598
5599
  const canNudge = () => steps < o.maxSteps && !overBudget();
5600
+ this.reopen = () => {
5601
+ if (!this.pendingInjections.length) return false;
5602
+ if (steps >= o.maxSteps || overBudget()) {
5603
+ log9.warn(`answer finished with ${this.pendingInjections.length} injection(s) pending and no step/budget left \u2014 they wait for the next run`);
5604
+ return false;
5605
+ }
5606
+ return this.drainInjections();
5607
+ };
5599
5608
  while (true) {
5600
5609
  if (o.signal?.aborted) return kill("aborted");
5601
5610
  if (steps >= o.maxSteps) return kill("max_steps");
@@ -5740,6 +5749,7 @@ var Agent = class _Agent {
5740
5749
  usage.cacheCreationTokens += res.usage.cacheCreationTokens ?? 0;
5741
5750
  usage.cacheReadTokens += res.usage.cacheReadTokens ?? 0;
5742
5751
  const prompt = res.usage.promptTokens ?? 0, cacheRead = res.usage.cacheReadTokens ?? 0;
5752
+ const ctxTokens = res.usage.contextTokens ?? prompt;
5743
5753
  usage.contextTokens = res.usage.contextTokens ?? prompt;
5744
5754
  usage.contextWindow = res.usage.contextWindow || _Agent.contextCap(o);
5745
5755
  if (prevPrompt < 0) {
@@ -5748,7 +5758,7 @@ var Agent = class _Agent {
5748
5758
  }
5749
5759
  const reused = Math.min(prompt, Math.max(cacheRead, prevPrompt));
5750
5760
  spent += (res.usage.totalTokens ?? 0) - 0.9 * reused;
5751
- prevPrompt = stepPrompt = prompt;
5761
+ prevPrompt = stepPrompt = ctxTokens;
5752
5762
  }
5753
5763
  const delegatedTools = res.delegatedTools ?? [];
5754
5764
  if (delegatedTools.length) {
@@ -5788,7 +5798,7 @@ var Agent = class _Agent {
5788
5798
  });
5789
5799
  }
5790
5800
  if (toolCalls.length === 0) {
5791
- if (this.drainInjections()) continue;
5801
+ if (this.reopen()) continue;
5792
5802
  if (emptyTurn && o.failEmptyTurns) {
5793
5803
  if (!emptyNudged && canNudge()) {
5794
5804
  emptyNudged = true;
@@ -5826,7 +5836,7 @@ var Agent = class _Agent {
5826
5836
  const drained = await this.jobs.drain(o.signal);
5827
5837
  if (o.signal?.aborted) return kill("aborted");
5828
5838
  if (drained.length) lastProgressAt = Date.now();
5829
- if (this.drainInjections()) continue;
5839
+ if (this.reopen()) continue;
5830
5840
  this.releaseStaleImages();
5831
5841
  await this.activeHooks?.onStop?.(res.content ?? "");
5832
5842
  const claims = this.survivingClaims();