conversation-hook-footer.fixture.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { createRoot } from "react-dom/client";
  2. import type { ConversationRow } from "@zcode/shared/zcode-protocol-v4";
  3. import { TooltipProvider } from "@/components/ui/tooltip.js";
  4. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  5. import { DEFAULT_CODE_PREVIEW_SETTINGS } from "@/lib/codePreviewSettings.js";
  6. import { ConversationTurnGroup } from "@/v4/ConversationTurnGroup.js";
  7. import { buildConversationTurnRenderUnits } from "@/v4/conversationTurnRenderUnits.js";
  8. import "@/styles.css";
  9. const query = new URLSearchParams(location.search);
  10. const mobile = query.get("mobile") === "true";
  11. const highspeed = query.get("highspeed") === "true";
  12. const theme = query.get("theme") === "light" ? "light" : "dark";
  13. document.documentElement.className = `${theme} theme-zai-${theme}`;
  14. const base = { turnId: "hook-footer", createdAt: 1_700_000_000_000, createdAtSeq: 1 };
  15. const rows: ConversationRow[] = [
  16. {
  17. ...base,
  18. rowId: 1,
  19. kind: "turnHeader",
  20. origin: "userInput",
  21. state: highspeed ? "completedInterrupted" : "completedSuccess",
  22. startedAt: base.createdAt,
  23. },
  24. {
  25. ...base,
  26. rowId: 2,
  27. kind: "userInput",
  28. origin: "realUser",
  29. text: "nihao",
  30. ...(highspeed
  31. ? {
  32. highspeed: {
  33. schemaVersion: 1,
  34. cardId: "hsc-hooks",
  35. taskId: "hook-footer",
  36. provider: "zai",
  37. model: "glm-5",
  38. issuedAt: 1_000,
  39. expiresAt: 10_000,
  40. },
  41. }
  42. : {}),
  43. },
  44. {
  45. ...base,
  46. rowId: 3,
  47. kind: "hookInvocation",
  48. entityId: "hook-1",
  49. productTurnId: base.turnId,
  50. visibility: "visible",
  51. hookInvocationId: "hook-1",
  52. hookEventName: "UserPromptSubmit",
  53. hookCount: 1,
  54. state: "completed",
  55. startedAt: base.createdAt,
  56. endedAt: base.createdAt + 25,
  57. durationMs: 25,
  58. lane: "assistantWork",
  59. executions: [
  60. {
  61. hookRunId: "execution-1",
  62. hookIndex: 0,
  63. didExecute: true,
  64. state: "completed",
  65. outcome: "success",
  66. sourceKind: "user",
  67. startedAt: base.createdAt,
  68. endedAt: base.createdAt + 25,
  69. durationMs: 25,
  70. },
  71. ],
  72. },
  73. ...(!highspeed
  74. ? [
  75. {
  76. ...base,
  77. rowId: 4,
  78. kind: "assistantText" as const,
  79. state: "complete" as const,
  80. entityId: "assistant-1",
  81. text: "你好!我是 ZCode,有什么可以帮你的吗?\n\n直接告诉我你想做什么就行。",
  82. },
  83. ]
  84. : []),
  85. ];
  86. const [unit] = buildConversationTurnRenderUnits(rows);
  87. // 真实组件、主题与点击行为;只读投影输入固定,不建立 runtime 或远控连接。
  88. createRoot(document.getElementById("root")!).render(
  89. <TooltipProvider>
  90. <ZCodeIntlProvider initialLocale={mobile ? "en-US" : "zh-CN"}>
  91. <main className="min-h-dvh bg-background text-foreground @container/conversation">
  92. <ConversationTurnGroup
  93. unit={{ ...unit!, showHighspeedOutputFooter: highspeed }}
  94. context={{
  95. workspacePath: "/fixture",
  96. theme,
  97. codePreviewSettings: DEFAULT_CODE_PREVIEW_SETTINGS,
  98. compactForRemoteControl: mobile,
  99. }}
  100. onFeedbackChange={() => undefined}
  101. />
  102. </main>
  103. </ZCodeIntlProvider>
  104. </TooltipProvider>,
  105. );