agentToolCallBlock.test.ts 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  1. import type { IBroadcastService, IServiceAccessor } from "@zcode/services";
  2. import { createElement } from "react";
  3. import { renderToStaticMarkup } from "react-dom/server";
  4. import { testId, TID_TOOL_SUMMARY_TRIGGER } from "@zcode/shared";
  5. import { afterEach, describe, expect, it, vi } from "vitest";
  6. import { ServiceProvider } from "@/hooks/useServices.js";
  7. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  8. import { StoreProvider } from "@/store/StoreProvider.js";
  9. import { useSubagentsStore } from "@/store/subagentsStore.js";
  10. import { AgentToolCallBlock } from "../src/ToolCallBlocks/renderers/agent.js";
  11. const localStorageState = new Map<string, string>();
  12. Object.defineProperty(globalThis, "localStorage", {
  13. configurable: true,
  14. value: {
  15. getItem: (key: string) => localStorageState.get(key) ?? null,
  16. setItem: (key: string, value: string) => {
  17. localStorageState.set(key, value);
  18. },
  19. removeItem: (key: string) => {
  20. localStorageState.delete(key);
  21. },
  22. clear: () => {
  23. localStorageState.clear();
  24. },
  25. },
  26. });
  27. Object.defineProperty(globalThis, "document", {
  28. configurable: true,
  29. value: {
  30. documentElement: {
  31. classList: {
  32. contains: () => false,
  33. toggle: () => {},
  34. },
  35. },
  36. },
  37. });
  38. const mockBroadcastService: IBroadcastService = {
  39. send: async () => {},
  40. onMessage: () => ({ dispose: () => {} }),
  41. };
  42. const mockServices = {
  43. fileService: {
  44. readMediaPreview: async () => ({
  45. path: "/workspace/assets/logo.png",
  46. mediaType: "image/png",
  47. dataBase64: "",
  48. totalBytes: 0,
  49. }),
  50. },
  51. } as IServiceAccessor;
  52. describe("AgentToolCallBlock", () => {
  53. afterEach(() => {
  54. useSubagentsStore.setState({ agents: [] });
  55. });
  56. it("keeps an Agent without a persisted child as a static one-line summary", () => {
  57. const html = renderToStaticMarkup(
  58. createElement(
  59. ZCodeIntlProvider,
  60. { initialLocale: "zh-CN" },
  61. createElement(
  62. ServiceProvider,
  63. { services: mockServices },
  64. createElement(
  65. StoreProvider,
  66. { broadcastService: mockBroadcastService },
  67. createElement(AgentToolCallBlock, {
  68. toolCallNode: {
  69. toolCall: {
  70. toolId: "tool-agent-running",
  71. kind: "think",
  72. title: "Inspect workspace",
  73. input: {
  74. prompt: "分析当前工作区并继续拆分任务",
  75. subagent_type: "Explore",
  76. },
  77. output: [],
  78. status: "running",
  79. raw: {
  80. _meta: {
  81. zcode: {
  82. toolName: "Agent",
  83. },
  84. },
  85. },
  86. },
  87. childToolCalls: [],
  88. },
  89. workspacePath: "/workspace",
  90. displayModel: {
  91. inlinePreview: { type: "none" },
  92. planResult: null,
  93. viewerSource: null,
  94. viewerLabelId: "codeViewer.viewCode",
  95. showSummaryFileLink: false,
  96. showInput: false,
  97. showOutput: false,
  98. showKind: false,
  99. },
  100. viewerSource: null,
  101. rawFileSummaries: [],
  102. isRunning: true,
  103. statusLabel: "执行中",
  104. errorText: undefined,
  105. childToolList: null,
  106. showIcon: true,
  107. forceOpen: false,
  108. onOpenCodeViewer: undefined,
  109. onOpenBrowserUrl: undefined,
  110. }),
  111. ),
  112. ),
  113. ),
  114. );
  115. expect(html).toContain(testId(TID_TOOL_SUMMARY_TRIGGER, "tool-agent-running"));
  116. expect(html).toContain("Inspect workspace");
  117. expect(html).not.toContain('role="button"');
  118. expect(html).not.toContain("aria-expanded");
  119. expect(html).not.toContain("lucide-chevron-right");
  120. expect(html).not.toMatch(/提示词|Prompt/);
  121. expect(html).not.toContain("分析当前工作区并继续拆分任务");
  122. });
  123. it("uses a side-pane summary action instead of expandable details", () => {
  124. const html = renderToStaticMarkup(
  125. createElement(
  126. ZCodeIntlProvider,
  127. { initialLocale: "zh-CN" },
  128. createElement(
  129. ServiceProvider,
  130. { services: mockServices },
  131. createElement(
  132. StoreProvider,
  133. { broadcastService: mockBroadcastService },
  134. createElement(AgentToolCallBlock, {
  135. toolCallNode: {
  136. toolCall: {
  137. toolId: "tool-agent-summary-action",
  138. kind: "think",
  139. title: "Inspect workspace",
  140. input: {
  141. prompt: "分析当前工作区并继续拆分任务",
  142. subagent_type: "Explore",
  143. },
  144. output: [],
  145. status: "running",
  146. raw: {
  147. _meta: {
  148. zcode: {
  149. toolName: "Agent",
  150. },
  151. },
  152. },
  153. },
  154. childToolCalls: [],
  155. },
  156. workspacePath: "/workspace",
  157. displayModel: {
  158. inlinePreview: { type: "none" },
  159. planResult: null,
  160. viewerSource: null,
  161. viewerLabelId: "codeViewer.viewCode",
  162. showSummaryFileLink: false,
  163. showInput: false,
  164. showOutput: false,
  165. showKind: false,
  166. },
  167. viewerSource: null,
  168. rawFileSummaries: [],
  169. isRunning: true,
  170. statusLabel: "执行中",
  171. errorText: undefined,
  172. childToolList: null,
  173. showIcon: true,
  174. agentSummaryAction: {
  175. onActivate: vi.fn(),
  176. testId: "v4-subagent-open-side-pane-child-session",
  177. },
  178. onOpenCodeViewer: undefined,
  179. onOpenBrowserUrl: undefined,
  180. }),
  181. ),
  182. ),
  183. ),
  184. );
  185. expect(html).toContain('data-testid="v4-subagent-open-side-pane-child-session"');
  186. expect(html).toContain('aria-label="在右侧打开"');
  187. expect(html).not.toContain("aria-expanded");
  188. expect(html).not.toContain("lucide-chevron-right");
  189. expect(html).not.toContain("subagent-output-preview");
  190. expect(html).not.toContain("分析当前工作区并继续拆分任务");
  191. });
  192. it("never falls back to inline prompt or child output", () => {
  193. const html = renderToStaticMarkup(
  194. createElement(
  195. ZCodeIntlProvider,
  196. { initialLocale: "zh-CN" },
  197. createElement(
  198. ServiceProvider,
  199. { services: mockServices },
  200. createElement(
  201. StoreProvider,
  202. { broadcastService: mockBroadcastService },
  203. createElement(AgentToolCallBlock, {
  204. toolCallNode: {
  205. toolCall: {
  206. toolId: "tool-agent-drilldown-slot",
  207. kind: "think",
  208. title: "Inspect workspace",
  209. input: {
  210. prompt: "分析当前工作区并继续拆分任务",
  211. subagent_type: "Explore",
  212. },
  213. output: [],
  214. status: "running",
  215. raw: {
  216. _meta: {
  217. zcode: {
  218. toolName: "Agent",
  219. },
  220. },
  221. },
  222. },
  223. childToolCalls: [],
  224. },
  225. workspacePath: "/workspace",
  226. displayModel: {
  227. inlinePreview: { type: "none" },
  228. planResult: null,
  229. viewerSource: null,
  230. viewerLabelId: "codeViewer.viewCode",
  231. showSummaryFileLink: false,
  232. showInput: false,
  233. showOutput: false,
  234. showKind: false,
  235. },
  236. viewerSource: null,
  237. rawFileSummaries: [],
  238. isRunning: true,
  239. statusLabel: "执行中",
  240. errorText: undefined,
  241. childToolList: null,
  242. showIcon: true,
  243. forceOpen: true,
  244. onOpenCodeViewer: undefined,
  245. onOpenBrowserUrl: undefined,
  246. }),
  247. ),
  248. ),
  249. ),
  250. );
  251. expect(html).not.toMatch(/提示词|Prompt/);
  252. expect(html).not.toContain("分析当前工作区并继续拆分任务");
  253. expect(html).not.toContain("subagent-output-preview");
  254. expect(html).not.toContain("aria-expanded");
  255. expect(html).not.toContain("lucide-chevron-right");
  256. expect(html).not.toContain("在右侧打开");
  257. expect(html).not.toContain("子会话");
  258. });
  259. it("colors the subagent name from the configured agent color", () => {
  260. useSubagentsStore.setState({
  261. agents: [
  262. {
  263. id: "agent-explore",
  264. name: "Explore",
  265. description: "Explore workspace",
  266. systemPrompt: "Explore",
  267. color: "red",
  268. path: "/workspace/.zcode/agents/explore.md",
  269. scope: "user",
  270. source: "user",
  271. enabled: true,
  272. },
  273. ],
  274. });
  275. const html = renderToStaticMarkup(
  276. createElement(
  277. ZCodeIntlProvider,
  278. { initialLocale: "zh-CN" },
  279. createElement(
  280. ServiceProvider,
  281. { services: mockServices },
  282. createElement(
  283. StoreProvider,
  284. { broadcastService: mockBroadcastService },
  285. createElement(AgentToolCallBlock, {
  286. toolCallNode: {
  287. toolCall: {
  288. toolId: "tool-agent-configured-color",
  289. kind: "think",
  290. title: "Agent",
  291. input: {
  292. prompt: "检查工作区",
  293. subagent_type: "Explore",
  294. },
  295. output: [],
  296. status: "completed",
  297. raw: {},
  298. },
  299. childToolCalls: [],
  300. },
  301. workspacePath: "/workspace",
  302. displayModel: {
  303. inlinePreview: { type: "none" },
  304. planResult: null,
  305. viewerSource: null,
  306. viewerLabelId: "codeViewer.viewCode",
  307. showSummaryFileLink: false,
  308. showInput: false,
  309. showOutput: false,
  310. showKind: false,
  311. },
  312. viewerSource: null,
  313. rawFileSummaries: [],
  314. isRunning: false,
  315. statusLabel: "完成",
  316. errorText: undefined,
  317. childToolList: null,
  318. showIcon: true,
  319. forceOpen: false,
  320. onOpenCodeViewer: undefined,
  321. onOpenBrowserUrl: undefined,
  322. }),
  323. ),
  324. ),
  325. ),
  326. );
  327. expect(html).toContain("Explore");
  328. expect(html).toContain("text-rose-700");
  329. expect(html).toContain("inline-flex max-w-36 items-center");
  330. expect(html).toContain("leading-[1.5]");
  331. expect(html).not.toContain("leading-none");
  332. });
  333. it("keeps the agent type blank while subagent_type may still be streaming", () => {
  334. const html = renderToStaticMarkup(
  335. createElement(
  336. ZCodeIntlProvider,
  337. { initialLocale: "zh-CN" },
  338. createElement(
  339. ServiceProvider,
  340. { services: mockServices },
  341. createElement(
  342. StoreProvider,
  343. { broadcastService: mockBroadcastService },
  344. createElement(AgentToolCallBlock, {
  345. toolCallNode: {
  346. toolCall: {
  347. toolId: "tool-agent-streaming-type",
  348. kind: "Agent",
  349. title: "Agent",
  350. input: {
  351. description: "检查流式参数",
  352. prompt: "等待完整输入",
  353. },
  354. output: "",
  355. status: "pending",
  356. raw: {
  357. toolName: "Agent",
  358. inputPreviewComplete: false,
  359. },
  360. },
  361. childToolCalls: [],
  362. },
  363. workspacePath: "/workspace",
  364. displayModel: {
  365. inlinePreview: { type: "none" },
  366. planResult: null,
  367. viewerSource: null,
  368. viewerLabelId: "codeViewer.viewCode",
  369. showSummaryFileLink: false,
  370. showInput: false,
  371. showOutput: false,
  372. showKind: false,
  373. },
  374. viewerSource: null,
  375. rawFileSummaries: [],
  376. isRunning: true,
  377. statusLabel: "等待中",
  378. errorText: undefined,
  379. childToolList: null,
  380. showIcon: true,
  381. forceOpen: false,
  382. onOpenCodeViewer: undefined,
  383. onOpenBrowserUrl: undefined,
  384. }),
  385. ),
  386. ),
  387. ),
  388. );
  389. expect(html).toContain("检查流式参数");
  390. expect(html).not.toContain("general-purpose");
  391. });
  392. it("falls back to the default general-purpose agent type only after complete input omits subagent_type", () => {
  393. const html = renderToStaticMarkup(
  394. createElement(
  395. ZCodeIntlProvider,
  396. { initialLocale: "zh-CN" },
  397. createElement(
  398. ServiceProvider,
  399. { services: mockServices },
  400. createElement(
  401. StoreProvider,
  402. { broadcastService: mockBroadcastService },
  403. createElement(AgentToolCallBlock, {
  404. toolCallNode: {
  405. toolCall: {
  406. toolId: "tool-agent-default-type",
  407. kind: "Agent",
  408. title: "Agent",
  409. input: {
  410. description: "抓取 bettingexpert 赔率",
  411. prompt: "获取赔率信息",
  412. run_in_background: true,
  413. },
  414. output: "Async agent launched successfully.",
  415. status: "running",
  416. raw: {
  417. inputPreviewComplete: true,
  418. _meta: {
  419. zcode: {
  420. toolName: "Agent",
  421. },
  422. },
  423. },
  424. },
  425. childToolCalls: [],
  426. },
  427. workspacePath: "/workspace",
  428. displayModel: {
  429. inlinePreview: { type: "none" },
  430. planResult: null,
  431. viewerSource: null,
  432. viewerLabelId: "codeViewer.viewCode",
  433. showSummaryFileLink: false,
  434. showInput: false,
  435. showOutput: false,
  436. showKind: false,
  437. },
  438. viewerSource: null,
  439. rawFileSummaries: [],
  440. isRunning: true,
  441. statusLabel: "执行中",
  442. errorText: undefined,
  443. childToolList: null,
  444. showIcon: true,
  445. forceOpen: false,
  446. onOpenCodeViewer: undefined,
  447. onOpenBrowserUrl: undefined,
  448. }),
  449. ),
  450. ),
  451. ),
  452. );
  453. expect(html).toContain("general-purpose");
  454. });
  455. it("uses the latest child tool summary for a collapsed running subagent", () => {
  456. const html = renderToStaticMarkup(
  457. createElement(
  458. ZCodeIntlProvider,
  459. { initialLocale: "zh-CN" },
  460. createElement(
  461. ServiceProvider,
  462. { services: mockServices },
  463. createElement(
  464. StoreProvider,
  465. { broadcastService: mockBroadcastService },
  466. createElement(AgentToolCallBlock, {
  467. toolCallNode: {
  468. toolCall: {
  469. toolId: "tool-agent-child-summary",
  470. kind: "Agent",
  471. title: "Agent",
  472. input: {
  473. prompt: "读取核心入口文件",
  474. subagent_type: "Explore",
  475. },
  476. output: "",
  477. status: "running",
  478. raw: {
  479. _meta: {
  480. zcode: {
  481. toolName: "Agent",
  482. },
  483. },
  484. },
  485. },
  486. childToolCalls: [
  487. {
  488. toolCall: {
  489. toolId: "tool-agent-child-read",
  490. kind: "read",
  491. title: "Read",
  492. input: {
  493. path: "/workspace/src/App.tsx",
  494. },
  495. output: "",
  496. status: "running",
  497. raw: {},
  498. },
  499. childToolCalls: [],
  500. },
  501. ],
  502. },
  503. workspacePath: "/workspace",
  504. displayModel: {
  505. inlinePreview: { type: "none" },
  506. planResult: null,
  507. viewerSource: null,
  508. viewerLabelId: "codeViewer.viewCode",
  509. showSummaryFileLink: false,
  510. showInput: false,
  511. showOutput: false,
  512. showKind: false,
  513. },
  514. viewerSource: null,
  515. rawFileSummaries: [],
  516. isRunning: true,
  517. statusLabel: "执行中",
  518. errorText: undefined,
  519. childToolList: null,
  520. showIcon: true,
  521. forceOpen: false,
  522. onOpenCodeViewer: undefined,
  523. onOpenBrowserUrl: undefined,
  524. }),
  525. ),
  526. ),
  527. ),
  528. );
  529. // Bugfix: Agent 收起态参考普通 active Explore 聚合,使用最新子工具摘要,
  530. // 同时外层仍展示子智能体,而不是把子智能体类型 Explore 当 kind label。
  531. expect(html).toContain("lucide-bot");
  532. expect(html).toMatch(/>(SubAgent|子智能体)</);
  533. expect(html).toContain("·");
  534. expect(html).toContain("正在读取");
  535. expect(html).toContain("App.tsx");
  536. expect(html).toContain("/workspace/src");
  537. expect(html).not.toContain("读取核心入口文件");
  538. });
  539. it("does not keep a completed subagent visually running while a child tool is running", () => {
  540. const html = renderToStaticMarkup(
  541. createElement(
  542. ZCodeIntlProvider,
  543. { initialLocale: "zh-CN" },
  544. createElement(
  545. ServiceProvider,
  546. { services: mockServices },
  547. createElement(
  548. StoreProvider,
  549. { broadcastService: mockBroadcastService },
  550. createElement(AgentToolCallBlock, {
  551. toolCallNode: {
  552. toolCall: {
  553. toolId: "tool-agent-completed-child-running",
  554. kind: "Agent",
  555. title: "Agent",
  556. input: {
  557. prompt: "读取核心入口文件",
  558. subagent_type: "Explore",
  559. },
  560. output: "",
  561. status: "completed",
  562. raw: {
  563. _meta: {
  564. zcode: {
  565. toolName: "Agent",
  566. },
  567. },
  568. },
  569. },
  570. childToolCalls: [
  571. {
  572. toolCall: {
  573. toolId: "tool-agent-child-read-still-running",
  574. kind: "read",
  575. title: "Read",
  576. input: {
  577. path: "/workspace/src/App.tsx",
  578. },
  579. output: "",
  580. status: "in_progress",
  581. raw: {},
  582. },
  583. childToolCalls: [],
  584. },
  585. ],
  586. },
  587. workspacePath: "/workspace",
  588. displayModel: {
  589. inlinePreview: { type: "none" },
  590. planResult: null,
  591. viewerSource: null,
  592. viewerLabelId: "codeViewer.viewCode",
  593. showSummaryFileLink: false,
  594. showInput: false,
  595. showOutput: false,
  596. showKind: false,
  597. },
  598. viewerSource: null,
  599. rawFileSummaries: [],
  600. isRunning: false,
  601. statusLabel: "已执行",
  602. errorText: undefined,
  603. childToolList: null,
  604. showIcon: true,
  605. forceOpen: false,
  606. onOpenCodeViewer: undefined,
  607. onOpenBrowserUrl: undefined,
  608. }),
  609. ),
  610. ),
  611. ),
  612. );
  613. // Bugfix: 父 Agent 的完成态只看父 tool 生命周期;
  614. // 子工具属于展开区明细,不能让 completed 父块继续显示 running 渐变。
  615. expect(html).toMatch(/>(SubAgent|子智能体)</);
  616. expect(html).toContain("Explore");
  617. expect(html).not.toContain("正在读取");
  618. expect(html).not.toContain("App.tsx");
  619. expect(html).not.toContain("animated-gradient-text");
  620. expect(html).not.toContain("读取核心入口文件");
  621. });
  622. it("allows disabling subagent summary roll animation", () => {
  623. const html = renderToStaticMarkup(
  624. createElement(
  625. ZCodeIntlProvider,
  626. { initialLocale: "zh-CN" },
  627. createElement(
  628. ServiceProvider,
  629. { services: mockServices },
  630. createElement(
  631. StoreProvider,
  632. { broadcastService: mockBroadcastService },
  633. createElement(AgentToolCallBlock, {
  634. toolCallNode: {
  635. toolCall: {
  636. toolId: "tool-agent-animation-disabled",
  637. kind: "Agent",
  638. title: "Agent",
  639. input: {
  640. prompt: "读取核心入口文件",
  641. subagent_type: "Explore",
  642. },
  643. output: "",
  644. status: "running",
  645. raw: {
  646. _meta: {
  647. zcode: {
  648. toolName: "Agent",
  649. },
  650. },
  651. },
  652. },
  653. childToolCalls: [
  654. {
  655. toolCall: {
  656. toolId: "tool-agent-animation-disabled-child",
  657. kind: "read",
  658. title: "Read",
  659. input: {
  660. path: "/workspace/src/App.tsx",
  661. },
  662. output: "",
  663. status: "in_progress",
  664. raw: {},
  665. },
  666. childToolCalls: [],
  667. },
  668. ],
  669. },
  670. workspacePath: "/workspace",
  671. displayModel: {
  672. inlinePreview: { type: "none" },
  673. planResult: null,
  674. viewerSource: null,
  675. viewerLabelId: "codeViewer.viewCode",
  676. showSummaryFileLink: false,
  677. showInput: false,
  678. showOutput: false,
  679. showKind: false,
  680. },
  681. viewerSource: null,
  682. rawFileSummaries: [],
  683. isRunning: true,
  684. statusLabel: "执行中",
  685. errorText: undefined,
  686. childToolList: null,
  687. showIcon: true,
  688. forceOpen: false,
  689. disableSummaryContentAnimation: true,
  690. onOpenCodeViewer: undefined,
  691. onOpenBrowserUrl: undefined,
  692. }),
  693. ),
  694. ),
  695. ),
  696. );
  697. expect(html).toContain("正在读取");
  698. expect(html).toContain("App.tsx");
  699. expect(html).not.toContain("overflow-hidden align-middle");
  700. });
  701. it("keeps the child action label for completed subagent child summaries", () => {
  702. const html = renderToStaticMarkup(
  703. createElement(
  704. ZCodeIntlProvider,
  705. { initialLocale: "zh-CN" },
  706. createElement(
  707. ServiceProvider,
  708. { services: mockServices },
  709. createElement(
  710. StoreProvider,
  711. { broadcastService: mockBroadcastService },
  712. createElement(AgentToolCallBlock, {
  713. toolCallNode: {
  714. toolCall: {
  715. toolId: "tool-agent-completed-child-summary",
  716. kind: "Agent",
  717. title: "Agent",
  718. input: {
  719. prompt: "读取核心入口文件",
  720. subagent_type: "Explore",
  721. },
  722. output: "",
  723. status: "running",
  724. raw: {
  725. _meta: {
  726. zcode: {
  727. toolName: "Agent",
  728. },
  729. },
  730. },
  731. },
  732. childToolCalls: [
  733. {
  734. toolCall: {
  735. toolId: "tool-agent-completed-child-read",
  736. kind: "read",
  737. title: "Read",
  738. input: {
  739. path: "/workspace/src/App.tsx",
  740. },
  741. output: "",
  742. status: "completed",
  743. raw: {},
  744. },
  745. childToolCalls: [],
  746. },
  747. ],
  748. },
  749. workspacePath: "/workspace",
  750. displayModel: {
  751. inlinePreview: { type: "none" },
  752. planResult: null,
  753. viewerSource: null,
  754. viewerLabelId: "codeViewer.viewCode",
  755. showSummaryFileLink: false,
  756. showInput: false,
  757. showOutput: false,
  758. showKind: false,
  759. },
  760. viewerSource: null,
  761. rawFileSummaries: [],
  762. isRunning: true,
  763. statusLabel: "执行中",
  764. errorText: undefined,
  765. childToolList: null,
  766. showIcon: true,
  767. forceOpen: false,
  768. onOpenCodeViewer: undefined,
  769. onOpenBrowserUrl: undefined,
  770. }),
  771. ),
  772. ),
  773. ),
  774. );
  775. expect(html).toContain("·");
  776. expect(html).toContain("App.tsx");
  777. expect(html).toContain("正在读取");
  778. });
  779. it("summarizes TodoWrite child tools with todo progress and active content", () => {
  780. const html = renderToStaticMarkup(
  781. createElement(
  782. ZCodeIntlProvider,
  783. { initialLocale: "zh-CN" },
  784. createElement(
  785. ServiceProvider,
  786. { services: mockServices },
  787. createElement(
  788. StoreProvider,
  789. { broadcastService: mockBroadcastService },
  790. createElement(AgentToolCallBlock, {
  791. toolCallNode: {
  792. toolCall: {
  793. toolId: "tool-agent-todo-child-summary",
  794. kind: "Agent",
  795. title: "Agent",
  796. input: {
  797. prompt: "实现 toolcall 摘要优化",
  798. subagent_type: "Explore",
  799. },
  800. output: "",
  801. status: "running",
  802. raw: {
  803. _meta: {
  804. zcode: {
  805. toolName: "Agent",
  806. },
  807. },
  808. },
  809. },
  810. childToolCalls: [
  811. {
  812. toolCall: {
  813. toolId: "tool-agent-child-todo",
  814. toolName: "TodoWrite",
  815. kind: "TodoWrite",
  816. title: "TodoWrite",
  817. input: {
  818. todos: [
  819. {
  820. content: "确认现有 Agent 摘要行为",
  821. status: "completed",
  822. },
  823. {
  824. content: "补齐待办子工具摘要",
  825. status: "in_progress",
  826. },
  827. {
  828. content: "跑回归测试",
  829. status: "pending",
  830. },
  831. ],
  832. },
  833. output: "",
  834. status: "running",
  835. raw: {},
  836. },
  837. childToolCalls: [],
  838. },
  839. ],
  840. },
  841. workspacePath: "/workspace",
  842. displayModel: {
  843. inlinePreview: { type: "none" },
  844. planResult: null,
  845. viewerSource: null,
  846. viewerLabelId: "codeViewer.viewCode",
  847. showSummaryFileLink: false,
  848. showInput: false,
  849. showOutput: false,
  850. showKind: false,
  851. },
  852. viewerSource: null,
  853. rawFileSummaries: [],
  854. isRunning: true,
  855. statusLabel: "执行中",
  856. errorText: undefined,
  857. childToolList: null,
  858. showIcon: true,
  859. forceOpen: false,
  860. onOpenCodeViewer: undefined,
  861. onOpenBrowserUrl: undefined,
  862. }),
  863. ),
  864. ),
  865. ),
  866. );
  867. expect(html).toContain("·");
  868. expect(html).toContain("更新待办");
  869. expect(html).toContain("1/3");
  870. expect(html).toContain("补齐待办子工具摘要");
  871. expect(html).not.toContain("Running TodoWrite");
  872. });
  873. it("uses SubAgent as the outer kind instead of the resolved agent type", () => {
  874. const html = renderToStaticMarkup(
  875. createElement(
  876. ZCodeIntlProvider,
  877. { initialLocale: "zh-CN" },
  878. createElement(
  879. ServiceProvider,
  880. { services: mockServices },
  881. createElement(
  882. StoreProvider,
  883. { broadcastService: mockBroadcastService },
  884. createElement(AgentToolCallBlock, {
  885. toolCallNode: {
  886. toolCall: {
  887. toolId: "tool-agent-numbered",
  888. kind: "think",
  889. title: "Agent",
  890. input: {
  891. description: "Explore project structure",
  892. prompt: "搜索国际与商业新闻",
  893. },
  894. output: JSON.stringify({
  895. status: "completed",
  896. agentId: "agent_6e358228-a52f-427a-b1ae-d30b5cd9899e",
  897. agentType: "Explore",
  898. description: "Explore project structure",
  899. }),
  900. status: "completed",
  901. raw: {
  902. _meta: {
  903. zcode: {
  904. toolName: "Agent",
  905. },
  906. },
  907. },
  908. },
  909. childToolCalls: [],
  910. },
  911. workspacePath: "/workspace",
  912. displayModel: {
  913. inlinePreview: { type: "none" },
  914. planResult: null,
  915. viewerSource: null,
  916. viewerLabelId: "codeViewer.viewCode",
  917. showSummaryFileLink: false,
  918. showInput: false,
  919. showOutput: false,
  920. showKind: false,
  921. },
  922. viewerSource: null,
  923. rawFileSummaries: [],
  924. isRunning: false,
  925. statusLabel: "已执行",
  926. errorText: undefined,
  927. childToolList: null,
  928. showIcon: true,
  929. forceOpen: false,
  930. sourceLabel: "SubAgent",
  931. onOpenCodeViewer: undefined,
  932. onOpenBrowserUrl: undefined,
  933. }),
  934. ),
  935. ),
  936. ),
  937. );
  938. // 外层 kind 固定显示 SubAgent;真实子智能体类型作为彩色名称展示。
  939. expect(html).toMatch(/>(SubAgent|子智能体)</);
  940. expect(html).toContain("·");
  941. expect(html).toContain("Explore project structure");
  942. expect(html).not.toContain("子智能体 2");
  943. expect(html).not.toMatch(/>Agent</);
  944. expect(html).toMatch(/>Explore</);
  945. });
  946. it("uses spawn_agent subagent nickname as the summary primary text", () => {
  947. const html = renderToStaticMarkup(
  948. createElement(
  949. ZCodeIntlProvider,
  950. { initialLocale: "zh-CN" },
  951. createElement(
  952. ServiceProvider,
  953. { services: mockServices },
  954. createElement(
  955. StoreProvider,
  956. { broadcastService: mockBroadcastService },
  957. createElement(AgentToolCallBlock, {
  958. toolCallNode: {
  959. toolCall: {
  960. toolId: "tool-spawn-agent-locke",
  961. kind: "spawn_agent",
  962. title: "spawn_agent",
  963. input: {
  964. agent_type: "explorer",
  965. message: "在当前项目里做只读结构检查",
  966. },
  967. output: "",
  968. status: "completed",
  969. raw: {
  970. name: "spawn_agent",
  971. _meta: {
  972. zcode: {
  973. toolName: "spawn_agent",
  974. nickname: "Locke",
  975. },
  976. },
  977. },
  978. },
  979. childToolCalls: [],
  980. },
  981. workspacePath: "/workspace",
  982. displayModel: {
  983. inlinePreview: { type: "none" },
  984. planResult: null,
  985. viewerSource: null,
  986. viewerLabelId: "codeViewer.viewCode",
  987. showSummaryFileLink: false,
  988. showInput: false,
  989. showOutput: false,
  990. showKind: false,
  991. },
  992. viewerSource: null,
  993. rawFileSummaries: [],
  994. isRunning: false,
  995. statusLabel: "已执行",
  996. errorText: undefined,
  997. childToolList: null,
  998. showIcon: true,
  999. forceOpen: false,
  1000. onOpenCodeViewer: undefined,
  1001. onOpenBrowserUrl: undefined,
  1002. }),
  1003. ),
  1004. ),
  1005. ),
  1006. );
  1007. // Bugfix: provider 原生子 agent 工具名 spawn_agent 直接展示会暴露实现细节;
  1008. // 外层 kind 固定为 SubAgent,nickname 作为彩色名称和摘要正文展示。
  1009. expect(html).not.toMatch(/>explorer</);
  1010. expect(html).toMatch(/>(SubAgent|子智能体)</);
  1011. expect(html).toContain("Locke");
  1012. expect(html).not.toContain("子智能体 1");
  1013. expect(html).not.toContain("spawn_agent");
  1014. expect(html).not.toContain("在当前项目里做只读结构检查");
  1015. });
  1016. it("falls back to spawn_agent agent_type when nickname is not available", () => {
  1017. const html = renderToStaticMarkup(
  1018. createElement(
  1019. ZCodeIntlProvider,
  1020. { initialLocale: "zh-CN" },
  1021. createElement(
  1022. ServiceProvider,
  1023. { services: mockServices },
  1024. createElement(
  1025. StoreProvider,
  1026. { broadcastService: mockBroadcastService },
  1027. createElement(AgentToolCallBlock, {
  1028. toolCallNode: {
  1029. toolCall: {
  1030. toolId: "tool-spawn-agent-explorer",
  1031. kind: "spawn_agent",
  1032. title: "spawn_agent",
  1033. input: {
  1034. agent_type: "explorer",
  1035. message: "在当前项目里做只读结构检查",
  1036. },
  1037. output: "",
  1038. status: "pending",
  1039. raw: {
  1040. name: "spawn_agent",
  1041. },
  1042. },
  1043. childToolCalls: [],
  1044. },
  1045. workspacePath: "/workspace",
  1046. displayModel: {
  1047. inlinePreview: { type: "none" },
  1048. planResult: null,
  1049. viewerSource: null,
  1050. viewerLabelId: "codeViewer.viewCode",
  1051. showSummaryFileLink: false,
  1052. showInput: false,
  1053. showOutput: false,
  1054. showKind: false,
  1055. },
  1056. viewerSource: null,
  1057. rawFileSummaries: [],
  1058. isRunning: true,
  1059. statusLabel: "执行中",
  1060. errorText: undefined,
  1061. childToolList: null,
  1062. showIcon: true,
  1063. forceOpen: false,
  1064. onOpenCodeViewer: undefined,
  1065. onOpenBrowserUrl: undefined,
  1066. }),
  1067. ),
  1068. ),
  1069. ),
  1070. );
  1071. expect(html).toContain("explorer");
  1072. expect(html).toMatch(/>(SubAgent|子智能体)</);
  1073. expect(html).not.toContain("子智能体 1");
  1074. expect(html).not.toContain("spawn_agent");
  1075. });
  1076. it("renders prompt and child tool calls without result content", () => {
  1077. const html = renderToStaticMarkup(
  1078. createElement(
  1079. ZCodeIntlProvider,
  1080. { initialLocale: "zh-CN" },
  1081. createElement(
  1082. ServiceProvider,
  1083. { services: mockServices },
  1084. createElement(
  1085. StoreProvider,
  1086. { broadcastService: mockBroadcastService },
  1087. createElement(AgentToolCallBlock, {
  1088. toolCallNode: {
  1089. toolCall: {
  1090. toolId: "tool-agent-render",
  1091. kind: "think",
  1092. title: "Explore project structure",
  1093. input: {
  1094. prompt: "请分析项目结构并列出入口点",
  1095. subagent_type: "Explore",
  1096. },
  1097. output: [
  1098. {
  1099. type: "text",
  1100. text: "这段结果不应该直接展示在 Agent 展开区",
  1101. },
  1102. ],
  1103. status: "completed",
  1104. raw: {
  1105. _meta: {
  1106. zcode: {
  1107. toolName: "Agent",
  1108. },
  1109. },
  1110. },
  1111. },
  1112. childToolCalls: [
  1113. {
  1114. toolCall: {
  1115. toolId: "tool-agent-child",
  1116. kind: "search",
  1117. title: "Find package.json",
  1118. input: {
  1119. query: "package.json",
  1120. },
  1121. output: "...",
  1122. status: "completed",
  1123. raw: {},
  1124. },
  1125. childToolCalls: [],
  1126. },
  1127. ],
  1128. },
  1129. workspacePath: "/workspace",
  1130. displayModel: {
  1131. inlinePreview: { type: "none" },
  1132. planResult: null,
  1133. viewerSource: null,
  1134. viewerLabelId: "codeViewer.viewCode",
  1135. showSummaryFileLink: false,
  1136. showInput: false,
  1137. showOutput: false,
  1138. showKind: false,
  1139. },
  1140. viewerSource: null,
  1141. rawFileSummaries: [],
  1142. isRunning: false,
  1143. statusLabel: "已执行",
  1144. errorText: undefined,
  1145. childToolList: null,
  1146. showIcon: true,
  1147. forceOpen: true,
  1148. onOpenCodeViewer: undefined,
  1149. onOpenBrowserUrl: undefined,
  1150. }),
  1151. ),
  1152. ),
  1153. ),
  1154. );
  1155. // Agent/Task 在消息流中固定为单行;详情只通过持久化 child session 打开。
  1156. expect(html).toMatch(/>(SubAgent|子智能体)</);
  1157. expect(html).toMatch(/>Explore</);
  1158. expect(html).toContain("Explore project structure");
  1159. expect(html).not.toMatch(/提示词|Prompt/);
  1160. expect(html).not.toContain("请分析项目结构并列出入口点");
  1161. expect(html).not.toContain("Find package.json");
  1162. expect(html).not.toContain("aria-expanded");
  1163. expect(html).not.toContain("这段结果不应该直接展示在 Agent 展开区");
  1164. });
  1165. it("keeps background agent internals out of the static summary", () => {
  1166. const html = renderToStaticMarkup(
  1167. createElement(
  1168. ZCodeIntlProvider,
  1169. { initialLocale: "zh-CN" },
  1170. createElement(
  1171. ServiceProvider,
  1172. { services: mockServices },
  1173. createElement(
  1174. StoreProvider,
  1175. { broadcastService: mockBroadcastService },
  1176. createElement(AgentToolCallBlock, {
  1177. toolCallNode: {
  1178. toolCall: {
  1179. toolId: "tool-background-agent",
  1180. kind: "think",
  1181. title: "Task",
  1182. input: {
  1183. prompt: "搜索今日新闻",
  1184. run_in_background: true,
  1185. },
  1186. output: [
  1187. {
  1188. type: "text",
  1189. text: "Async agent launched successfully.\nagentId: internal-agent-id (internal ID - do not mention to user.)\noutput_file: /tmp/background-agent.output\n",
  1190. },
  1191. ],
  1192. status: "completed",
  1193. raw: {
  1194. _meta: {
  1195. zcode: {
  1196. toolName: "Agent",
  1197. backgroundAgent: {
  1198. runInBackground: true,
  1199. agentId: "internal-agent-id",
  1200. outputFile: "/tmp/background-agent.output",
  1201. },
  1202. },
  1203. },
  1204. },
  1205. },
  1206. childToolCalls: [],
  1207. },
  1208. workspacePath: "/workspace",
  1209. displayModel: {
  1210. inlinePreview: { type: "none" },
  1211. planResult: null,
  1212. viewerSource: null,
  1213. viewerLabelId: "codeViewer.viewCode",
  1214. showSummaryFileLink: false,
  1215. showInput: false,
  1216. showOutput: false,
  1217. showKind: false,
  1218. },
  1219. viewerSource: null,
  1220. rawFileSummaries: [],
  1221. isRunning: false,
  1222. statusLabel: "已执行",
  1223. errorText: undefined,
  1224. childToolList: null,
  1225. showIcon: true,
  1226. forceOpen: true,
  1227. onOpenCodeViewer: undefined,
  1228. onOpenBrowserUrl: undefined,
  1229. }),
  1230. ),
  1231. ),
  1232. ),
  1233. );
  1234. expect(html).toMatch(/子智能体|SubAgent/);
  1235. expect(html).not.toContain("/tmp/background-agent.output");
  1236. expect(html).not.toContain("internal-agent-id");
  1237. });
  1238. it("does not inline background child activity", () => {
  1239. const html = renderToStaticMarkup(
  1240. createElement(
  1241. ZCodeIntlProvider,
  1242. { initialLocale: "zh-CN" },
  1243. createElement(
  1244. ServiceProvider,
  1245. { services: mockServices },
  1246. createElement(
  1247. StoreProvider,
  1248. { broadcastService: mockBroadcastService },
  1249. createElement(AgentToolCallBlock, {
  1250. toolCallNode: {
  1251. toolCall: {
  1252. toolId: "tool-background-agent-activity",
  1253. kind: "think",
  1254. title: "Task",
  1255. input: {
  1256. prompt: "后台调研项目结构",
  1257. run_in_background: true,
  1258. },
  1259. output: "",
  1260. content: "已读取 package.json,继续分析入口文件。",
  1261. thought: "先确认项目结构。",
  1262. status: "completed",
  1263. raw: {
  1264. _meta: {
  1265. zcode: {
  1266. toolName: "Agent",
  1267. backgroundAgent: {
  1268. runInBackground: true,
  1269. },
  1270. },
  1271. },
  1272. },
  1273. },
  1274. childToolCalls: [],
  1275. },
  1276. workspacePath: "/workspace",
  1277. displayModel: {
  1278. inlinePreview: { type: "none" },
  1279. planResult: null,
  1280. viewerSource: null,
  1281. viewerLabelId: "codeViewer.viewCode",
  1282. showSummaryFileLink: false,
  1283. showInput: false,
  1284. showOutput: false,
  1285. showKind: false,
  1286. },
  1287. viewerSource: null,
  1288. rawFileSummaries: [],
  1289. isRunning: false,
  1290. statusLabel: "已执行",
  1291. errorText: undefined,
  1292. childToolList: null,
  1293. showIcon: true,
  1294. forceOpen: true,
  1295. onOpenCodeViewer: undefined,
  1296. onOpenBrowserUrl: undefined,
  1297. }),
  1298. ),
  1299. ),
  1300. ),
  1301. );
  1302. expect(html).not.toContain("先确认项目结构。");
  1303. expect(html).not.toContain("已读取 package.json");
  1304. expect(html).not.toContain("data-markdown-table-sticky-scrollbar");
  1305. });
  1306. it("does not inline either task notification or raw background transcript", () => {
  1307. const html = renderToStaticMarkup(
  1308. createElement(
  1309. ZCodeIntlProvider,
  1310. { initialLocale: "zh-CN" },
  1311. createElement(
  1312. ServiceProvider,
  1313. { services: mockServices },
  1314. createElement(
  1315. StoreProvider,
  1316. { broadcastService: mockBroadcastService },
  1317. createElement(AgentToolCallBlock, {
  1318. toolCallNode: {
  1319. toolCall: {
  1320. toolId: "tool-background-agent-summary",
  1321. kind: "think",
  1322. title: "Implement Todo types and components",
  1323. input: {
  1324. prompt: "实现 Todo 类型和组件",
  1325. run_in_background: true,
  1326. },
  1327. output: "",
  1328. content: '{"isSidechain":true,"message":"raw transcript"}',
  1329. status: "completed",
  1330. raw: {
  1331. _meta: {
  1332. zcode: {
  1333. toolName: "Agent",
  1334. backgroundAgent: {
  1335. runInBackground: true,
  1336. },
  1337. taskNotification: {
  1338. outputFile: "/tmp/background-agent.output",
  1339. result: "All files are created and the project builds successfully.",
  1340. },
  1341. },
  1342. },
  1343. },
  1344. },
  1345. childToolCalls: [],
  1346. },
  1347. workspacePath: "/workspace",
  1348. displayModel: {
  1349. inlinePreview: { type: "none" },
  1350. planResult: null,
  1351. viewerSource: null,
  1352. viewerLabelId: "codeViewer.viewCode",
  1353. showSummaryFileLink: false,
  1354. showInput: false,
  1355. showOutput: false,
  1356. showKind: false,
  1357. },
  1358. viewerSource: null,
  1359. rawFileSummaries: [],
  1360. isRunning: false,
  1361. statusLabel: "已执行",
  1362. errorText: undefined,
  1363. childToolList: null,
  1364. showIcon: true,
  1365. forceOpen: true,
  1366. onOpenCodeViewer: undefined,
  1367. onOpenBrowserUrl: undefined,
  1368. }),
  1369. ),
  1370. ),
  1371. ),
  1372. );
  1373. expect(html).not.toContain("All files are created and the project builds successfully.");
  1374. expect(html).not.toContain("raw transcript");
  1375. });
  1376. });