workflow-digest-fixed.fixture.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { AvatarCluster, SpineRail } from "@/app-shell/WorkflowRunSpineParts.js";
  2. import { buildWorkflowTimeline } from "@/components/workflow-timeline/timeline-model.js";
  3. import "@/styles.css";
  4. import { createRoot } from "react-dom/client";
  5. import type { WorkflowRunState } from "@zcode/shared/zcode-protocol-v4";
  6. import type { WorkflowRunCardSummary } from "@/ToolCallBlocks/shared.js";
  7. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  8. import { TooltipProvider } from "@/components/ui/tooltip.js";
  9. import { WorkflowRunDigest } from "@/components/workflow-timeline/WorkflowRunDigest.js";
  10. const LOOP_GRAPH = {
  11. steps: [
  12. {
  13. id: "ask#1",
  14. kind: "ask",
  15. label: "plan",
  16. line: 2,
  17. column: 21,
  18. lane: "actor#1",
  19. phase: "phase#a",
  20. },
  21. {
  22. id: "ask#2",
  23. kind: "ask",
  24. label: "verify",
  25. line: 5,
  26. column: 21,
  27. lane: "actor#2",
  28. phase: "phase#b",
  29. },
  30. ],
  31. lanes: [
  32. { id: "actor#1", name: "planner", line: 1, column: 11 },
  33. { id: "actor#2", name: "checker", line: 4, column: 11 },
  34. ],
  35. participants: [
  36. { id: "phase#a:actor#1", phase: "phase#a", lane: "actor#1", steps: ["ask#1"] },
  37. { id: "phase#b:actor#2", phase: "phase#b", lane: "actor#2", steps: ["ask#2"] },
  38. ],
  39. handoffs: [],
  40. phases: [
  41. { id: "phase#a", name: "plan", line: 1 },
  42. { id: "phase#b", name: "verify", line: 4 },
  43. ],
  44. phaseEdges: [
  45. { from: "phase#a", to: "phase#b" },
  46. { from: "phase#b", to: "phase#a", back: true },
  47. ],
  48. exits: ["phase#b"],
  49. } as const;
  50. function runState(overrides: Partial<WorkflowRunState> = {}): WorkflowRunState {
  51. return {
  52. runId: "dwfrun-42",
  53. toolCallId: "tool-create-workflow",
  54. status: "running",
  55. usage: { spentTokens: 1_234, nodesUsed: 2 },
  56. actors: [
  57. { siteId: "actor#1", ordinal: 1, name: "Ada", sessionId: "s-1", status: "completed" },
  58. { siteId: "actor#2", ordinal: 1, name: "Bob", sessionId: "s-2", status: "running" },
  59. ],
  60. nodes: [
  61. {
  62. siteId: "ask#1",
  63. ordinal: 1,
  64. phase: "settled",
  65. outcome: "ok",
  66. actorSiteId: "actor#1",
  67. actorOrdinal: 1,
  68. },
  69. { siteId: "ask#2", ordinal: 1, phase: "executing", actorSiteId: "actor#2", actorOrdinal: 1 },
  70. ] as WorkflowRunState["nodes"],
  71. lastEventSequence: 7,
  72. ...overrides,
  73. };
  74. }
  75. function joined(
  76. overrides: Partial<WorkflowRunState> = {},
  77. extra: Partial<WorkflowRunCardSummary> = {},
  78. ): WorkflowRunCardSummary {
  79. const run = runState(overrides);
  80. return {
  81. runId: run.runId,
  82. toolCallId: run.toolCallId,
  83. status: run.status,
  84. nodesSettled: run.nodes.filter((node) => node.phase === "settled").length,
  85. nodesTotal: run.nodes.length,
  86. run,
  87. ...extra,
  88. };
  89. }
  90. createRoot(document.getElementById("root")!).render(
  91. <ZCodeIntlProvider initialLocale="en-US">
  92. <TooltipProvider>
  93. <div className="relative h-8" data-testid="spine-preview">
  94. <SpineRail ink="march" position="above" />
  95. </div>
  96. <AvatarCluster
  97. pills={buildWorkflowTimeline(LOOP_GRAPH, runState()).stations.flatMap(
  98. (station) => station.pills,
  99. )}
  100. nameOf={(pill) => pill.runtimeName ?? pill.lane.name}
  101. />
  102. <WorkflowRunDigest
  103. graph={LOOP_GRAPH}
  104. runId={joined().runId}
  105. summary={joined()}
  106. name="Fixed workflow"
  107. testIdKey="fixed"
  108. onOpenPill={() => {
  109. document.body.dataset.agentOpened = "true";
  110. }}
  111. onOpenRun={() => {
  112. document.body.dataset.open = "true";
  113. }}
  114. />
  115. <WorkflowRunDigest
  116. graph={undefined}
  117. runId={joined().runId}
  118. summary={joined({ status: "stopped", stopReason: "user" }, { resumable: true })}
  119. name="Resume workflow"
  120. testIdKey="resume"
  121. onResume={() => {
  122. document.body.dataset.resumed = "true";
  123. }}
  124. />
  125. </TooltipProvider>
  126. </ZCodeIntlProvider>,
  127. );