file-summary.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { useMemo } from "react";
  2. import type { AssistantTextRow, TurnHeaderRow } from "@zcode/shared/zcode-protocol-v4";
  3. import { AssistantPreviewCards } from "@/AssistantPreviewCards.js";
  4. import { DEFAULT_CODE_PREVIEW_SETTINGS } from "@/lib/codePreviewSettings.js";
  5. import { ConversationFileSummaryPanel } from "@/v4/ConversationFileSummaryPanel.js";
  6. import { useAssistantPreviewCardsForAssistantTextRow } from "@/v4/useAssistantPreviewCardsForRow.js";
  7. export function FileSummaryFixture({
  8. path,
  9. root,
  10. mode,
  11. compact,
  12. }: {
  13. path: string;
  14. root: string;
  15. mode: "only" | "mixed" | "ordinary";
  16. compact: boolean;
  17. }) {
  18. const row = useMemo<AssistantTextRow>(
  19. () => ({
  20. rowId: 2,
  21. entityId: "summary-text",
  22. turnId: "summary-turn",
  23. createdAt: 2,
  24. createdAtSeq: 2,
  25. kind: "assistantText",
  26. state: "complete",
  27. text:
  28. mode === "ordinary"
  29. ? `${root}/demo.html`
  30. : `::visualize${JSON.stringify({ path })}\n[可视化](${path})${mode === "mixed" ? `\n${root}/demo.html` : ""}`,
  31. }),
  32. [mode, path, root],
  33. );
  34. const rows = useMemo(() => [row], [row]);
  35. const context = useMemo(
  36. () => ({
  37. workspacePath: root,
  38. workspaceIdentity: "ssh:fixture:/workspace",
  39. workspaceRemoteSessionId: "remote-1",
  40. theme: "system" as const,
  41. codePreviewSettings: DEFAULT_CODE_PREVIEW_SETTINGS,
  42. compactForRemoteControl: compact,
  43. fetchFileChanges: async () => ({
  44. items: [
  45. ...(mode !== "ordinary" ? [{ path, additions: 70, deletions: 1, patches: [] }] : []),
  46. ...(mode !== "only"
  47. ? [{ path: `${root}/demo.html`, additions: 7, deletions: 2, patches: [] }]
  48. : []),
  49. ],
  50. }),
  51. }),
  52. [compact, mode, path, root],
  53. );
  54. const header: TurnHeaderRow = {
  55. rowId: 1,
  56. entityId: "summary-header",
  57. turnId: "summary-turn",
  58. createdAt: 1,
  59. createdAtSeq: 1,
  60. kind: "turnHeader",
  61. origin: "userInput",
  62. state: "completedSuccess",
  63. startedAt: 1,
  64. fileChanges: {
  65. files: mode === "mixed" ? 2 : 1,
  66. additions: mode === "ordinary" ? 7 : mode === "mixed" ? 77 : 70,
  67. deletions: mode === "ordinary" ? 2 : mode === "mixed" ? 3 : 1,
  68. state: "active",
  69. },
  70. };
  71. const cards = useAssistantPreviewCardsForAssistantTextRow({
  72. row,
  73. assistantTextRows: rows,
  74. latestAssistantTextRow: row,
  75. ...context,
  76. fileChangesTarget: { rowId: 1, entityId: "summary-header" },
  77. fileChangesState: "active",
  78. });
  79. return (
  80. <div id="file-summary-fixture">
  81. <div id="file-preview-cards">
  82. <AssistantPreviewCards cards={cards} {...context} />
  83. </div>
  84. <div id="file-summary-panel">
  85. <ConversationFileSummaryPanel header={header} context={context} assistantText={row.text} />
  86. </div>
  87. </div>
  88. );
  89. }