agent.libx.js 0.92.2 → 0.92.3

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,11 +1,11 @@
1
- import { a as AgentOptions, H as Hooks, h as RunResult, A as Agent } from './Agent-BzwprwHr.js';
2
- export { C as ChatFragment, D as DEFAULT_MUTATING, b as Decision, P as PermissionOptions, c as PermissionPolicy, d as PermissionRule, e as PreToolUseDecision, R as ReasoningEffort, f as RecordingHooks, g as RecordingLifecycle, T as ToolUse, i as ToolUseMeta, j as composeHooks, p as planMode, r as reasoningToChatFragment } from './Agent-BzwprwHr.js';
1
+ import { a as AgentOptions, H as Hooks, h as RunResult, A as Agent } from './Agent-QwBA0wu6.js';
2
+ export { C as ChatFragment, D as DEFAULT_MUTATING, b as Decision, P as PermissionOptions, c as PermissionPolicy, d as PermissionRule, e as PreToolUseDecision, R as ReasoningEffort, f as RecordingHooks, g as RecordingLifecycle, T as ToolUse, i as ToolUseMeta, j as composeHooks, p as planMode, r as reasoningToChatFragment } from './Agent-QwBA0wu6.js';
3
3
  import { IFilesystem, FileMetadata } from '@livx.cc/wcli/core';
4
4
  export { CommandExecutor, FileMetadata, IFilesystem, IndexedDbFilesystem, MemFilesystem, registerHeadlessCommands } from '@livx.cc/wcli/core';
5
5
  import { BodDB } from '@bod.ee/db';
6
- import { A as AgentTool, C as ChatLike, a as ChatOptions, b as ChatResponse, h as ToolCall, H as HostBridge, U as UserQuestion, e as MessageContent } from './tools-CeK5AquG.js';
7
- export { c as ContentPart, d as HostEvent, M as Message, R as Role, S as SandboxJobRegistry, f as StreamChunk, T as TodoItem, g as Tool, i as ToolContext, j as bashTool, k as contentText, l as defaultTools, m as editTool, n as exitSessionTool, o as imagePart, p as makeContext, q as makeJobTools, r as readTool, t as toWireTools, s as todoWriteTool, u as toolRegistry, v as toolsByName } from './tools-CeK5AquG.js';
8
- export { M as McpCall, a as McpImage, b as McpToolResult, c as McpToolSearchOptions, d as McpToolSpec, m as makeMcpToolSearch, e as mcpToolToAgentTool, f as mcpToolsToAgentTools } from './mcp-Bn5TlRbV.js';
6
+ import { A as AgentTool, C as ChatLike, a as ChatOptions, b as ChatResponse, h as ToolCall, H as HostBridge, U as UserQuestion, e as MessageContent } from './tools-GPWp7oXq.js';
7
+ export { c as ContentPart, d as HostEvent, M as Message, R as Role, S as SandboxJobRegistry, f as StreamChunk, T as TodoItem, g as Tool, i as ToolContext, j as bashTool, k as contentText, l as defaultTools, m as editTool, n as exitSessionTool, o as imagePart, p as makeContext, q as makeJobTools, r as readTool, t as toWireTools, s as todoWriteTool, u as toolRegistry, v as toolsByName } from './tools-GPWp7oXq.js';
8
+ export { M as McpCall, a as McpImage, b as McpToolResult, c as McpToolSearchOptions, d as McpToolSpec, m as makeMcpToolSearch, e as mcpToolToAgentTool, f as mcpToolsToAgentTools } from './mcp-wwgXyhbi.js';
9
9
  import * as libx_js_src_modules_log from 'libx.js/src/modules/log';
10
10
  export { log } from 'libx.js/src/modules/log';
11
11
 
package/dist/index.js CHANGED
@@ -1391,6 +1391,18 @@ function makeRealShellTool(options) {
1391
1391
  timedOut = true;
1392
1392
  ctl.abort();
1393
1393
  }, timeoutMs);
1394
+ let pend = "";
1395
+ let flushTimer = null;
1396
+ const flushEmit = (ctx2) => {
1397
+ if (flushTimer) {
1398
+ clearTimeout(flushTimer);
1399
+ flushTimer = null;
1400
+ }
1401
+ if (pend) {
1402
+ ctx2.emit?.(redactSecrets(pend));
1403
+ pend = "";
1404
+ }
1405
+ };
1394
1406
  try {
1395
1407
  return await new Promise((resolve) => {
1396
1408
  let out = "";
@@ -1407,7 +1419,13 @@ function makeRealShellTool(options) {
1407
1419
  return finish(`[exit 1] failed to spawn shell: ${e?.message ?? e}`);
1408
1420
  }
1409
1421
  const collect = (chunk) => {
1410
- out += typeof chunk === "string" ? chunk : chunk?.toString?.("utf8") ?? "";
1422
+ const s = typeof chunk === "string" ? chunk : chunk?.toString?.("utf8") ?? "";
1423
+ out += s;
1424
+ if (ctx.emit && !settled) {
1425
+ pend += s;
1426
+ if (pend.length >= 1024) flushEmit(ctx);
1427
+ else flushTimer ??= setTimeout(() => flushEmit(ctx), 250);
1428
+ }
1411
1429
  };
1412
1430
  proc.stdout?.on("data", collect);
1413
1431
  proc.stderr?.on("data", collect);
@@ -1417,6 +1435,7 @@ function makeRealShellTool(options) {
1417
1435
  finish(`[exit 1] ${err?.message ?? err}${out ? "\n" + clean(out) : ""}`);
1418
1436
  });
1419
1437
  proc.on("close", (code) => {
1438
+ flushEmit(ctx);
1420
1439
  if (ctl.signal.aborted) return finish(reasonFor(timedOut, timeoutMs, clean(out)));
1421
1440
  const body = clean(out);
1422
1441
  if (code && code !== 0) return finish(`[exit ${code}]${body ? "\n" + body : ""}`);
@@ -1425,6 +1444,7 @@ function makeRealShellTool(options) {
1425
1444
  });
1426
1445
  } finally {
1427
1446
  clearTimeout(timer);
1447
+ if (flushTimer) clearTimeout(flushTimer);
1428
1448
  ctx.signal?.removeEventListener("abort", onAbort);
1429
1449
  }
1430
1450
  }
@@ -2405,6 +2425,9 @@ function composeHooks(...list) {
2405
2425
  async postToolUse(call, result, meta) {
2406
2426
  for (const h of hooks) await h.postToolUse?.(call, result, meta);
2407
2427
  },
2428
+ onToolOutput(call, chunk, meta) {
2429
+ for (const h of hooks) h.onToolOutput?.(call, chunk, meta);
2430
+ },
2408
2431
  onStop(text) {
2409
2432
  for (const h of hooks) h.onStop?.(text);
2410
2433
  },
@@ -2915,6 +2938,13 @@ var Agent = class _Agent {
2915
2938
  let threw = false;
2916
2939
  try {
2917
2940
  log3.debug(`${tc.function.name}(${tc.function.arguments})`);
2941
+ this.ctx.emit = hooks?.onToolOutput ? (chunk) => {
2942
+ try {
2943
+ hooks.onToolOutput(call, chunk, meta);
2944
+ } catch (e) {
2945
+ log3.debug(`onToolOutput hook error: ${e}`);
2946
+ }
2947
+ } : void 0;
2918
2948
  const raw = await tool.run(args, this.ctx);
2919
2949
  if (typeof raw === "string") {
2920
2950
  result = raw;
@@ -2927,6 +2957,8 @@ var Agent = class _Agent {
2927
2957
  log3.debug(`${tc.function.name} -> error: ${msg}`);
2928
2958
  result = `Error: ${msg}`;
2929
2959
  threw = true;
2960
+ } finally {
2961
+ this.ctx.emit = void 0;
2930
2962
  }
2931
2963
  if (!threw) result = await this.maybeAutoTest(tc.function.name, result);
2932
2964
  await hooks?.postToolUse?.(call, result, meta);
@@ -3614,6 +3646,10 @@ ${recent}` : brief;
3614
3646
  postToolUse: async (call, result, meta) => {
3615
3647
  await base?.postToolUse?.(call, result, meta);
3616
3648
  report.post(call);
3649
+ },
3650
+ onToolOutput: (call, chunk, meta) => {
3651
+ base?.onToolOutput?.(call, chunk, meta);
3652
+ report.output(chunk);
3617
3653
  }
3618
3654
  } : base;
3619
3655
  const worker = new Agent({
@@ -3650,13 +3686,18 @@ ${recent}` : brief;
3650
3686
  const rec = this.tasks.get(id);
3651
3687
  if (!rec || rec.status !== "running") return clearInterval(timer);
3652
3688
  if (!inflight || !due()) return;
3653
- emit(rec, `still inside ${describeCall(inflight.call)} \u2014 ${Math.round((Date.now() - inflight.at) / 1e3)}s on this step`, inflight.call);
3689
+ const last = inflight.tail.trim().split("\n").filter(Boolean).pop()?.slice(-80);
3690
+ emit(rec, `still inside ${describeCall(inflight.call)} \u2014 ${Math.round((Date.now() - inflight.at) / 1e3)}s on this step${last ? `, last output: ${last}` : ""}`, inflight.call);
3654
3691
  }, Math.max(this.options.progressIntervalMs, 250));
3655
3692
  timer.unref?.();
3656
3693
  return {
3657
3694
  pre: (call) => {
3658
- inflight = { call, at: Date.now() };
3695
+ inflight = { call, at: Date.now(), tail: "" };
3696
+ },
3697
+ output: (chunk) => {
3698
+ if (inflight) inflight.tail = (inflight.tail + chunk).slice(-500);
3659
3699
  },
3700
+ // digest only — NEVER re-voices directly
3660
3701
  post: (call) => {
3661
3702
  steps++;
3662
3703
  inflight = null;
@@ -3881,6 +3922,7 @@ var RecordingHooks = class {
3881
3922
  blocks;
3882
3923
  pre = [];
3883
3924
  post = [];
3925
+ outputs = [];
3884
3926
  stops = [];
3885
3927
  preToolUse(call, meta) {
3886
3928
  this.pre.push({ call, meta });
@@ -3890,6 +3932,9 @@ var RecordingHooks = class {
3890
3932
  postToolUse(call, result, meta) {
3891
3933
  this.post.push({ call, result, meta });
3892
3934
  }
3935
+ onToolOutput(call, chunk, meta) {
3936
+ this.outputs.push({ call, chunk, meta });
3937
+ }
3893
3938
  onStop(finalText) {
3894
3939
  this.stops.push(finalText);
3895
3940
  }