fallback-details.fixture.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { useState } from "react";
  2. import { createRoot } from "react-dom/client";
  3. import { FallbackToolCallBlock } from "@/ToolCallBlocks/renderers/fallback.js";
  4. import type { ToolCallBlockRenderContext } from "@/ToolCallBlocks/shared.js";
  5. import { buildToolDisplayModel } from "@/lib/toolDisplay.js";
  6. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  7. import { TooltipProvider } from "@/components/ui/tooltip.js";
  8. import "@/styles.css";
  9. const query = new URLSearchParams(location.search);
  10. const locale = query.get("locale") === "en-US" ? "en-US" : "zh-CN";
  11. const theme = query.get("theme") === "light" ? "light" : "dark";
  12. document.documentElement.className = `${theme} theme-zai-${theme}`;
  13. function Fixture() {
  14. const [completed, setCompleted] = useState(false);
  15. const cases = [
  16. {
  17. id: "simple",
  18. input: { session_id: "example-session", limit: 0, active: false },
  19. output: "Found 2 sessions",
  20. },
  21. { id: "empty", input: {}, output: "No sessions found" },
  22. { id: "complex", input: { filters: { states: ["running"] } }, output: [{ id: "example" }] },
  23. { id: "failed", input: {}, output: "STALE_SUCCESS", error: "Access denied", status: "failed" },
  24. {
  25. id: "running",
  26. input: {},
  27. output: completed ? "Result arrived" : undefined,
  28. status: completed ? "completed" : "running",
  29. },
  30. { id: "zero", output: 0 },
  31. { id: "false", output: false },
  32. { id: "null", output: null },
  33. { id: "blank", output: "" },
  34. { id: "absent" },
  35. {
  36. id: "long",
  37. input: { ["long_field_".repeat(12)]: "value".repeat(80) },
  38. output: "Long result line\n".repeat(80),
  39. },
  40. ];
  41. return (
  42. <main className="min-h-screen space-y-4 bg-background p-4 text-foreground">
  43. <button data-testid="complete" onClick={() => setCompleted(true)}>
  44. Complete
  45. </button>
  46. {cases.map(({ id, ...fields }) => {
  47. const toolCall = {
  48. toolId: id,
  49. name: "ListSessions",
  50. kind: "other",
  51. title: "ListSessions",
  52. status: "completed",
  53. raw: { secret: "internal-metadata" },
  54. ...fields,
  55. } as ToolCallBlockRenderContext["toolCallNode"]["toolCall"];
  56. const context = {
  57. toolCallNode: { toolCall, childToolCalls: [] },
  58. workspacePath: "/example",
  59. isRunning: toolCall.status === "running",
  60. statusLabel: toolCall.status,
  61. errorText: toolCall.error,
  62. childToolList: null,
  63. displayModel: buildToolDisplayModel(toolCall, "/example"),
  64. theme,
  65. } as ToolCallBlockRenderContext;
  66. return (
  67. <section key={id} data-case={id}>
  68. <FallbackToolCallBlock {...context} />
  69. </section>
  70. );
  71. })}
  72. </main>
  73. );
  74. }
  75. createRoot(document.getElementById("root")!).render(
  76. <ZCodeIntlProvider initialLocale={locale}>
  77. <TooltipProvider>
  78. <Fixture />
  79. </TooltipProvider>
  80. </ZCodeIntlProvider>,
  81. );