@livx.cc/agentx 0.99.46 → 0.99.47

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.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as AgentOptions, H as Hooks, i as RunResult, A as Agent } from './Agent-OcAg2yxA.js';
2
- export { C as ChatFragment, b as CompactResult, D as DEFAULT_MUTATING, c as Decision, P as PermissionOptions, d as PermissionPolicy, e as PermissionRule, f as PreToolUseDecision, R as ReasoningEffort, g as RecordingHooks, h as RecordingLifecycle, T as ToolUse, j as ToolUseMeta, k as composeHooks, l as estimateTokens, p as planMode, r as reasoningToChatFragment } from './Agent-OcAg2yxA.js';
1
+ import { a as AgentOptions, H as Hooks, i as RunResult, A as Agent } from './Agent-BWbQ4Sqp.js';
2
+ export { C as ChatFragment, b as CompactResult, D as DEFAULT_MUTATING, c as Decision, P as PermissionOptions, d as PermissionPolicy, e as PermissionRule, f as PreToolUseDecision, R as ReasoningEffort, g as RecordingHooks, h as RecordingLifecycle, T as ToolUse, j as ToolUseMeta, k as composeHooks, l as estimateTokens, p as planMode, r as reasoningToChatFragment } from './Agent-BWbQ4Sqp.js';
3
3
  export { MODEL_ALIASES, ModelSwitch, ResolveModelSwitchOpts, modelShortLabel, resolveModelAlias, resolveModelSwitch } from './models.js';
4
4
  import { IFilesystem, FileMetadata } from '@livx.cc/wcli/core';
5
5
  export { CommandExecutor, FileMetadata, IFilesystem, IndexedDbFilesystem, MemFilesystem, registerHeadlessCommands } from '@livx.cc/wcli/core';
package/dist/index.js CHANGED
@@ -4030,6 +4030,14 @@ var Agent = class _Agent {
4030
4030
  /** The hold is bounded by the transport tool deadline: a host tool that never settles (the helper already gave
4031
4031
  * up on it) must not disable stall protection for the rest of the request — or this instance. */
4032
4032
  hostToolHoldUntil = 0;
4033
+ /** Delegated-runtime NATIVE tools (cursor's own shell/mcp/task) seen `running` but not yet `completed`/`error`,
4034
+ * id → hold-until. The runtime streams nothing while one runs, so it holds the watchdog like a host tool —
4035
+ * bounded by the same tool deadline (`toolHoldMs`) so a lost `completed` event can't disable it. */
4036
+ nativeToolsInFlight = /* @__PURE__ */ new Map();
4037
+ toolHoldMs = 0;
4038
+ /** A tool (host or native) already executed in the current step attempt: a stall retry replays the step
4039
+ * from the pre-step transcript, which would re-run it — so such a stall is not retried. */
4040
+ toolRanThisAttempt = false;
4033
4041
  /** Resets the active request's stall timer; a host tool's completion restarts the model's idle window. */
4034
4042
  stallPoke;
4035
4043
  /** Advertised tools this run's text claimed to have used while the ledger showed zero calls. */
@@ -4360,6 +4368,7 @@ var Agent = class _Agent {
4360
4368
  const hostToolTimeoutMs = o.providerOptions?.toolTimeoutMs;
4361
4369
  const derivedToolTimeoutMs = Math.max(TRANSPORT_TOOL_TIMEOUT_FLOOR_MS, ...this.activeTools.map(transportHeadroomMs));
4362
4370
  const effectiveToolTimeoutMs = typeof hostToolTimeoutMs === "number" ? Math.max(hostToolTimeoutMs, derivedToolTimeoutMs) : derivedToolTimeoutMs;
4371
+ this.toolHoldMs = effectiveToolTimeoutMs;
4363
4372
  if (isCursorWithTools) {
4364
4373
  if (typeof hostToolTimeoutMs === "number" && effectiveToolTimeoutMs !== hostToolTimeoutMs) {
4365
4374
  log6.warn(`providerOptions.toolTimeoutMs=${hostToolTimeoutMs}ms is below what the registered tools need \u2014 RAISED to ${effectiveToolTimeoutMs}ms. ${toolTimeoutViolations(this.activeTools, hostToolTimeoutMs).length} tool(s) could outlive it, and the transport would have destroyed their results. To lower it, lower the tools' own maxDurationMs (e.g. the Shell tool's maxTimeoutMs) instead.`);
@@ -4376,6 +4385,7 @@ var Agent = class _Agent {
4376
4385
  return await this.dispatch(tc);
4377
4386
  } finally {
4378
4387
  this.hostToolsInFlight--;
4388
+ this.toolRanThisAttempt = true;
4379
4389
  this.stallPoke?.();
4380
4390
  }
4381
4391
  }
@@ -4388,6 +4398,8 @@ var Agent = class _Agent {
4388
4398
  };
4389
4399
  try {
4390
4400
  for (let attempt = 0; ; attempt++) {
4401
+ this.nativeToolsInFlight.clear();
4402
+ this.toolRanThisAttempt = false;
4391
4403
  try {
4392
4404
  if (useStream) {
4393
4405
  const stall = this.armStallWatchdog(o.signal, o.stallMs);
@@ -4417,7 +4429,9 @@ var Agent = class _Agent {
4417
4429
  const stalled = err?.code === "stall";
4418
4430
  const empty = err?.code === "empty" || err?.code === "cursor_silent";
4419
4431
  const maxAttempts = empty ? Math.max(o.emptyRetries, 0) : 2;
4420
- const transient = !o.signal?.aborted && !isAbortError(err) && attempt < maxAttempts && (network || serverSide || stalled || empty);
4432
+ const replaysTool = stalled && this.toolRanThisAttempt;
4433
+ if (replaysTool) log6.warn("model stall after tool(s) already ran this step \u2014 not retrying (a retry would replay them)");
4434
+ const transient = !o.signal?.aborted && !isAbortError(err) && !replaysTool && attempt < maxAttempts && (network || serverSide || stalled || empty);
4421
4435
  if (!transient) throw err;
4422
4436
  const waitMs = (empty ? o.emptyRetryBaseMs : 1e3) * (attempt + 1);
4423
4437
  log6.warn(`${empty ? "empty model turn" : stalled ? "model stall" : "network drop"} mid-step (${err?.message ?? err}) \u2014 retrying in ${waitMs}ms`);
@@ -4600,7 +4614,7 @@ var Agent = class _Agent {
4600
4614
  if (!stallMs) return;
4601
4615
  if (timer) clearTimeout(timer);
4602
4616
  timer = setTimeout(() => {
4603
- if (this.hostToolsInFlight > 0 && Date.now() < this.hostToolHoldUntil) return poke();
4617
+ if (this.toolHoldActive()) return poke();
4604
4618
  fired = true;
4605
4619
  ac.abort(stallError());
4606
4620
  }, stallMs);
@@ -4620,6 +4634,13 @@ var Agent = class _Agent {
4620
4634
  reclassify: (err) => stalled() ? stallError() : err
4621
4635
  };
4622
4636
  }
4637
+ /** A host or native delegated tool is running within its deadline — the provider is quiet, not stalled. */
4638
+ toolHoldActive() {
4639
+ const now3 = Date.now();
4640
+ if (this.hostToolsInFlight > 0 && now3 < this.hostToolHoldUntil) return true;
4641
+ for (const until of this.nativeToolsInFlight.values()) if (now3 < until) return true;
4642
+ return false;
4643
+ }
4623
4644
  /** A clean-stop turn that carries no assistant text AND no tool calls (native or delegated) — a
4624
4645
  * non-result the model produced by going silent. Callers retry it rather than report "done". */
4625
4646
  isEmptyStop(res) {
@@ -4658,6 +4679,12 @@ var Agent = class _Agent {
4658
4679
  if (a.output !== void 0) prev.output = a.output;
4659
4680
  prev.status = a.status;
4660
4681
  }
4682
+ if (a.status === "running") {
4683
+ if (a.id) this.nativeToolsInFlight.set(a.id, Date.now() + this.toolHoldMs);
4684
+ } else {
4685
+ if (a.id) this.nativeToolsInFlight.delete(a.id);
4686
+ this.toolRanThisAttempt = true;
4687
+ }
4661
4688
  sawTool = true;
4662
4689
  this.invokedTools.add(a.name);
4663
4690
  trailing = "";