feat: terminal 执行中增量输出走 SSE(tool_output),工具卡实时滚动

This commit is contained in:
2026-11-20 11:03:18 +08:00
parent 02c154ae24
commit ba20a4f39d
5 changed files with 42 additions and 5 deletions
+6 -2
View File
@@ -905,7 +905,7 @@ async function toolTerminal(ctx, args) {
// 配了 executor.url(或 env EXECUTOR_URL):命令交给远端 agent-executor 执行,文本拼回与本地完全一致。
if (rexec.isRemote(cfg)) {
const r = await rexec.run(cfg, { command: args.command, cwd, timeout_ms: timeout, run: ctx.run });
const r = await rexec.run(cfg, { command: args.command, cwd, timeout_ms: timeout, run: ctx.run, onChunk: ctx.onOutput });
r.out = drainUiCards(r.out, ctx);
let text = selectOutput(r.out.replace(/\n+$/, ''), args.head_lines, args.tail_lines);
if (r.killed_by === 'timeout') {
@@ -931,7 +931,11 @@ async function toolTerminal(ctx, args) {
killGroup(child);
}, timeout);
const onData = (d) => { out += d.toString(); };
const onData = (d) => {
const s = d.toString();
out += s;
if (ctx.onOutput) { try { ctx.onOutput(s); } catch (_) {} }
};
child.stdout.on('data', onData);
child.stderr.on('data', onData);