workflow-status.fixture.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import "@/styles.css";
  2. import { useState } from "react";
  3. import { createRoot } from "react-dom/client";
  4. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  5. import { TooltipProvider } from "@/components/ui/tooltip.js";
  6. import { GetWorkflowRunToolCallBlock } from "@/ToolCallBlocks/renderers/get-workflow-run.js";
  7. import type { ToolCallBlockRenderContext } from "@/ToolCallBlocks/shared.js";
  8. // 情势截面的手工样本(spec: docs/dynamic-workflow/launch.md「`GetWorkflowRun`」「Their cards」):
  9. // 年龄一律对 `generatedAt` 算,所以这里写成相对偏移——固定的快照时刻让截图逐像素可复现。
  10. const G = 1_800_000_000_000;
  11. const SITUATION = {
  12. summary:
  13. "Running for 15m 00s, in phase 2 of 3 (judge), 5 steps settled, 2 running (1 executing, 1 parked), last progress 40s ago.",
  14. generatedAt: G,
  15. phases: [
  16. {
  17. name: "collect",
  18. state: "done",
  19. rounds: 1,
  20. nodesSettled: 3,
  21. nodesRunning: 0,
  22. enteredAt: G - 900_000,
  23. exitedAt: G - 600_000,
  24. },
  25. {
  26. name: "judge",
  27. state: "current",
  28. rounds: 2,
  29. nodesSettled: 2,
  30. nodesRunning: 2,
  31. enteredAt: G - 600_000,
  32. },
  33. { name: "report", state: "ahead", rounds: 0, nodesSettled: 0, nodesRunning: 0 },
  34. ],
  35. subagents: [
  36. {
  37. siteId: "agent#1",
  38. ordinal: 1,
  39. name: "scout",
  40. state: "executing",
  41. phaseName: "judge",
  42. instructionsHead:
  43. "Check the release notes for regressions and list every step that changed behaviour",
  44. startedAt: G - 310_000,
  45. turn: 3,
  46. toolCalls: 7,
  47. lastTool: { name: "Bash", target: "pnpm test", at: G - 20_000 },
  48. stepsSettled: 2,
  49. stepsFailed: 0,
  50. tokens: 4_200,
  51. },
  52. {
  53. siteId: "agent#2",
  54. ordinal: 2,
  55. state: "parked",
  56. phaseName: "judge",
  57. parkedOn: "q_7",
  58. stepsSettled: 1,
  59. stepsFailed: 0,
  60. tokens: 900,
  61. },
  62. {
  63. siteId: "agent#3",
  64. ordinal: 3,
  65. name: "drafter",
  66. state: "waiting",
  67. phaseName: "judge",
  68. waitCause: "backoff",
  69. retryAfterMs: 45_000,
  70. waitSince: G - 65_000,
  71. stepsSettled: 0,
  72. stepsFailed: 0,
  73. tokens: 0,
  74. },
  75. ],
  76. health: {
  77. lastProgressAt: G - 40_000,
  78. concurrency: { effective: 2, cap: 4, reason: "rate_limited", since: G - 130_000 },
  79. consecutiveFailures: 2,
  80. cachedSteps: 3,
  81. pendingQuestionsKnown: true,
  82. },
  83. logTail: [{ sequence: 9, message: "fan-out complete", at: G - 95_000 }],
  84. };
  85. /** 进程死在半路:leftover 说明 + 未完结的相位词,且没有「到现在为止」的时长。 */
  86. const STOPPED_SITUATION = {
  87. stopReason: "interrupted",
  88. summary: "Stopped 2h 15m ago in phase judge, 1 step settled, 1 still marked running.",
  89. generatedAt: G,
  90. phases: [
  91. {
  92. name: "judge",
  93. state: "unfinished",
  94. rounds: 1,
  95. nodesSettled: 1,
  96. nodesRunning: 1,
  97. enteredAt: G - 8_100_000,
  98. },
  99. ],
  100. subagents: [
  101. {
  102. siteId: "agent#1",
  103. ordinal: 1,
  104. name: "scout",
  105. state: "unfinished",
  106. phaseName: "judge",
  107. startedAt: G - 8_000_000,
  108. turn: 2,
  109. stepsSettled: 1,
  110. stepsFailed: 1,
  111. tokens: 1_500,
  112. },
  113. ],
  114. health: {
  115. lastProgressAt: G - 8_000_000,
  116. consecutiveFailures: 0,
  117. cachedSteps: 0,
  118. leftoverRunning: 1,
  119. pendingQuestionsKnown: false,
  120. },
  121. logTail: [],
  122. truncated: true,
  123. };
  124. function Fixture() {
  125. const [state, setState] = useState("fetching");
  126. const display = {
  127. kind: "get_workflow_run",
  128. runId: "status-run",
  129. label: "Status workflow",
  130. status:
  131. state === "completed"
  132. ? "completed"
  133. : state === "run-failed"
  134. ? "failed"
  135. : state === "situation-stopped"
  136. ? "stopped"
  137. : "running",
  138. usage: {
  139. spentTokens: 100,
  140. nodesObserved: 3,
  141. nodesCompleted: 1,
  142. nodesFailed: 0,
  143. nodesRunning: 2,
  144. },
  145. actors: [],
  146. logTail: [],
  147. ...(state === "completed"
  148. ? { result: JSON.stringify(Array.from({ length: 40 }, (_, i) => `result ${i}`)) }
  149. : {}),
  150. ...(state === "run-failed" ? { error: { code: "RUN_ERROR", message: "Actor failed" } } : {}),
  151. // 情势截面只挂在新增的两个态上:原有四个态是「情势上线前的老载荷」的手工样本,
  152. // 它们必须继续画成今天这样(既有 e2e 就钉在这上面)。
  153. ...(state === "situation" ? SITUATION : {}),
  154. ...(state === "situation-stopped" ? STOPPED_SITUATION : {}),
  155. };
  156. const context = {
  157. toolCallNode: {
  158. toolCall: {
  159. toolId: "status",
  160. status: state === "query-failed" ? "failed" : "completed",
  161. raw: { display },
  162. },
  163. childToolCalls: [],
  164. },
  165. isRunning: state === "fetching",
  166. forceOpen: false,
  167. canToggle: true,
  168. errorText: state === "query-failed" ? "Query denied" : undefined,
  169. onOpenWorkflowRun: () => {
  170. document.body.dataset.open = "true";
  171. },
  172. } as unknown as ToolCallBlockRenderContext;
  173. return (
  174. <ZCodeIntlProvider initialLocale="en-US">
  175. <TooltipProvider>
  176. {[
  177. "running",
  178. "completed",
  179. "run-failed",
  180. "query-failed",
  181. "situation",
  182. "situation-stopped",
  183. ].map((s) => (
  184. <button key={s} onClick={() => setState(s)}>
  185. {s}
  186. </button>
  187. ))}
  188. <GetWorkflowRunToolCallBlock {...context} />
  189. </TooltipProvider>
  190. </ZCodeIntlProvider>
  191. );
  192. }
  193. createRoot(document.getElementById("root")!).render(<Fixture />);