| 1 | import React from "react"; |
| 2 | import { createRoot } from "react-dom/client"; |
| 3 | import { flushSync } from "react-dom"; |
| 4 | import { ChatPaneRegion } from "../src/app-shell/ChatPaneRegion"; |
| 5 | import { LocaleProvider, useT } from "../src/lib/i18n"; |
| 6 | import { initialState } from "../src/lib/useController"; |
| 7 | import type { SessionDraftSurface } from "../src/app-runtime/useSessionDraftSurface"; |
| 8 | import "../src/styles.css"; |
| 9 | |
| 10 | const noop = () => {}; |
| 11 | const failure = "Session runtime could not resolve the configuration path."; |
| 12 | const settings = { model: "fixture/model", mode: "normal", toolApprovalMode: "ask", disabledMcp: {}, mcpOrder: [] }; |
| 13 | const surface: SessionDraftSurface = { |
| 14 | kind: "draft", draft: { id: "draft", workspaceId: "workspace", scope: "project", workspaceRoot: "/fixture", revision: 1, contentJson: "{}", settings, status: "active", updatedAt: 1 }, |
| 15 | content: { text: "Keep my draft", invocations: [], attachments: [], workspaceRefs: [], pastedBlocks: [], openPastedLabels: [], sessionRefs: [], selectedTextRefs: [] }, |
| 16 | settings, commands: [], servers: [], generation: 1, editVersion: 0, pendingTasks: 0, preparingSubmission: false, saveState: "saved", |
| 17 | submissionError: failure, taskError: `Error: ${failure}`, |
| 18 | operation: { operationId: "original", requestId: "request", draftId: "draft", submissionId: "submission", phase: "runtime_failed", revision: 1, updatedAt: 1, |
| 19 | canResume: true, canEdit: false, canCancel: true, canDiscard: false, error: failure }, |
| 20 | }; |
| 21 | let retries = 0; |
| 22 | function Fixture({ pending }: { pending: boolean }) { |
| 23 | const t = useT(); |
| 24 | return <div className="app" style={{ height: "100vh", display: "flex", flexDirection: "column" }}><ChatPaneRegion |
| 25 | transitioning={false} t={t} imDetail={null} remote={undefined} |
| 26 | commands={{ onPrompt: noop, onFork: noop, onLoadOlderHistory: async () => false, onLoadNewerHistory: async () => false, onSurfacePaintReady: noop }} |
| 27 | transcript={{ state: { ...initialState, meta: { ready: true, eventChannel: "fixture" } }, items: [], footerHeight: 0, |
| 28 | transcriptHydrating: false, navigationDataReady: true, readOnly: false, controllerReady: false, hydratePlaceholderActive: false, |
| 29 | clearContextPending: false, availability: { kind: "ready", source: "history" }, rewind: { stateActive: false, committing: false } }} |
| 30 | onRetryHistory={async () => {}} |
| 31 | draft={{ surface: { ...surface, resumingSubmission: pending }, onUseSaved: noop, onKeepLocal: noop, onRetrySave: noop, |
| 32 | onDismissTaskError: noop, onResume: () => { retries++; }, onOpenSession: noop, onCheckSubmission: noop }} |
| 33 | /></div>; |
| 34 | } |
| 35 | const root = createRoot(document.getElementById("root")!); |
| 36 | const paintDraftRecovery = (pending = false) => flushSync(() => root.render(<LocaleProvider><Fixture pending={pending} /></LocaleProvider>)); |
| 37 | Object.assign(window, { paintDraftRecovery, draftRecoveryRetries: () => retries }); |
| 38 | paintDraftRecovery(); |
| 39 |