session-details.fixture.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import { useState } from "react";
  2. import { createRoot } from "react-dom/client";
  3. import { toolCallRowToLegacyNode } from "@/v4/toolCallRowAdapter.js";
  4. import type { ToolCallRow } from "@zcode/shared/zcode-protocol-v4";
  5. import { ToolPresentation } from "@/ToolCallBlocks/ToolPresentation.js";
  6. import type { TaskChatToolCallTreeNode } from "@/lib/toolCallTree.js";
  7. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  8. import { TooltipProvider } from "@/components/ui/tooltip.js";
  9. import "@/styles.css";
  10. const query = new URLSearchParams(location.search);
  11. const locale = query.get("locale") === "en-US" ? "en-US" : "zh-CN";
  12. const theme = query.get("theme") === "light" ? "light" : "dark";
  13. document.documentElement.className = `${theme} theme-zai-${theme}`;
  14. const session = {
  15. kind: "app",
  16. sessionId: "sess_example-123456789",
  17. workspacePath: "/private/internal-path",
  18. sourceServerId: "internal-source",
  19. };
  20. const summary = { session, title: "Project analysis", status: "running", availableActions: [] };
  21. const budgetCases =
  22. (
  23. window as unknown as {
  24. __sessionBudgetCases?: { id: string; name: string; output: string }[];
  25. }
  26. ).__sessionBudgetCases ?? [];
  27. function Fixture() {
  28. const [done, setDone] = useState(query.get("restored") === "1");
  29. const cases = [
  30. {
  31. id: "list",
  32. name: "ListSessions",
  33. output: {
  34. sessions: [summary],
  35. nextCursor: "private-cursor",
  36. searchScope: {
  37. scopes: [],
  38. unavailableSources: [{ sourceServerId: "secret", reason: "offline" }],
  39. },
  40. },
  41. },
  42. {
  43. id: "read",
  44. name: "ReadSession",
  45. input: { sessionId: session.sessionId },
  46. output: JSON.stringify({
  47. view: "messages",
  48. session,
  49. messages: [{ id: "msg", role: "assistant", text: "Message body\n".repeat(30) }],
  50. nextCursor: "more",
  51. }),
  52. },
  53. { id: "summary", name: "ReadSession", output: { view: "summary", summary } },
  54. {
  55. id: "send",
  56. name: "SendToSession",
  57. input: { sessionId: session.sessionId, prompt: "Please inspect reuse" },
  58. output: { session, admission: "accepted", delivery: "queued" },
  59. },
  60. {
  61. id: "rejected",
  62. name: "SendToSession",
  63. output: { session, admission: "rejected", delivery: "none", reason: "Permission denied" },
  64. },
  65. {
  66. id: "wait",
  67. name: "WaitSessions",
  68. input: { operations: [{ sessionId: session.sessionId, commandId: "private-command" }] },
  69. output: {
  70. status: "timed_out",
  71. operations: [
  72. {
  73. operation: { session, commandId: "private-command" },
  74. status: "needs_attention",
  75. attention: { kind: "question", message: "Choose a target" },
  76. },
  77. ],
  78. },
  79. },
  80. {
  81. id: "running",
  82. name: "ReadSession",
  83. input: { sessionId: session.sessionId },
  84. status: done ? "completed" : "running",
  85. output: done ? { view: "summary", summary } : undefined,
  86. },
  87. {
  88. id: "failed",
  89. name: "SendToSession",
  90. status: "failed",
  91. error: "Execution failed",
  92. output: { session, admission: "accepted", delivery: "queued" },
  93. },
  94. {
  95. id: "stopped",
  96. name: "WaitSessions",
  97. status: "stopped",
  98. output: { status: "completed", operations: [] },
  99. },
  100. {
  101. id: "denied",
  102. name: "SendToSession",
  103. status: "denied",
  104. output: { session, admission: "accepted", delivery: "start_now" },
  105. },
  106. {
  107. id: "unknown",
  108. name: "SendToSession",
  109. output: { session, admission: "unknown", delivery: "unknown" },
  110. },
  111. {
  112. id: "legacy",
  113. name: "ReadSession",
  114. input: { sessionId: session.sessionId },
  115. output: "{broken JSON",
  116. },
  117. ...budgetCases.map((row) => ({
  118. ...row,
  119. input: { operations: [{ sessionId: session.sessionId }] },
  120. })),
  121. {
  122. id: "budget-live",
  123. name: "ReadSession",
  124. status: done ? "completed" : "running",
  125. output: done ? budgetCases[0]?.output : undefined,
  126. },
  127. { id: "budget-legacy", name: "ReadSession", raw: { rawOutput: budgetCases[0]?.output } },
  128. { id: "other", name: "OtherSession", output: { test: "ordinary fallback" } },
  129. ];
  130. return (
  131. <main className="min-h-screen space-y-4 bg-background p-4 text-foreground">
  132. <button data-testid="complete" onClick={() => setDone(true)}>
  133. Complete
  134. </button>
  135. {cases.map(({ id, name, ...fields }) => {
  136. const legacyNode = {
  137. toolCall: { toolId: id, kind: name, toolName: name, status: "completed", ...fields },
  138. childToolCalls: [],
  139. } as TaskChatToolCallTreeNode;
  140. const node =
  141. id === "budget-live" || budgetCases.some((row) => row.id === id)
  142. ? toolCallRowToLegacyNode({
  143. toolCallId: id,
  144. toolName: name,
  145. inputText: "",
  146. input: fields.input,
  147. status: legacyNode.toolCall.status === "running" ? "running" : "success",
  148. output:
  149. typeof fields.output === "string"
  150. ? { text: fields.output, truncated: true }
  151. : undefined,
  152. } as ToolCallRow)
  153. : legacyNode;
  154. return (
  155. <section key={id} data-case={id}>
  156. <ToolPresentation toolCallNode={node} theme={theme} />
  157. </section>
  158. );
  159. })}
  160. </main>
  161. );
  162. }
  163. createRoot(document.getElementById("root")!).render(
  164. <ZCodeIntlProvider initialLocale={locale}>
  165. <TooltipProvider>
  166. <Fixture />
  167. </TooltipProvider>
  168. </ZCodeIntlProvider>,
  169. );