| 1 | import { requestSessionVersions } from "../lib/sessionRecoveryVersionHostBridge"; |
| 2 | import type { AppOverlayHostProps } from "./AppOverlayHost"; |
| 3 | import type { HistoryViewState } from "../app-runtime/historyViewProjection"; |
| 4 | import type { useHistoryCommands } from "../app-runtime/useHistoryCommands"; |
| 5 | import type { useSessionNavigationCommands } from "../app-runtime/useSessionNavigationCommands"; |
| 6 | import type { useAppChromeCommands } from "../app-runtime/useAppChromeCommands"; |
| 7 | import type { useOnboardingCommands } from "../app-runtime/useOnboardingCommands"; |
| 8 | import type { useWorktreeMergeCommands } from "../app-runtime/useWorktreeMergeCommands"; |
| 9 | import type { useAppShellStores } from "../app-runtime/useAppShellStores"; |
| 10 | import type { TabMeta } from "../lib/types"; |
| 11 | import type { Translator } from "../lib/i18n"; |
| 12 | |
| 13 | type HistoryCommands = ReturnType<typeof useHistoryCommands>; |
| 14 | type NavigationCommands = ReturnType<typeof useSessionNavigationCommands>; |
| 15 | type ChromeCommands = ReturnType<typeof useAppChromeCommands>; |
| 16 | type OnboardingCommands = ReturnType<typeof useOnboardingCommands>; |
| 17 | type WorktreeMergeCommands = ReturnType<typeof useWorktreeMergeCommands>; |
| 18 | |
| 19 | type OverlayPalette = NonNullable<AppOverlayHostProps["palette"]>; |
| 20 | type ShellStores = ReturnType<typeof useAppShellStores>; |
| 21 | |
| 22 | /** Pure prop assembly for AppOverlayHost; overlay visibility flags come from |
| 23 | * the caller's stores, command identity from its owner hooks. */ |
| 24 | export function buildOverlayHostProps(input: { |
| 25 | t: Translator; |
| 26 | running: boolean; |
| 27 | histView: HistoryViewState | null; |
| 28 | pageKind: string; |
| 29 | automationTopic: NonNullable<AppOverlayHostProps["automation"]>["commands"]["onOpenTopic"]; |
| 30 | shell: ShellStores; |
| 31 | activeTab: TabMeta | undefined; |
| 32 | activeTabId: string | undefined; |
| 33 | cwd: string | undefined; |
| 34 | paletteItems: OverlayPalette["view"]["items"]; |
| 35 | startupSplashHold: boolean; |
| 36 | history: HistoryCommands; |
| 37 | navigation: NavigationCommands; |
| 38 | chrome: ChromeCommands; |
| 39 | onboarding: OnboardingCommands; |
| 40 | worktree: WorktreeMergeCommands; |
| 41 | prefillSubagentCommand: (command: string) => void; |
| 42 | |
| 43 | sessionActions: { |
| 44 | previewSession: NonNullable<AppOverlayHostProps["history"]>["commands"]["onPreview"]; |
| 45 | listTrashedSessions: NonNullable<AppOverlayHostProps["trash"]>["commands"]["list"]; |
| 46 | restoreSession: NonNullable<AppOverlayHostProps["trash"]>["commands"]["restore"]; |
| 47 | purgeTrashedSession: NonNullable<AppOverlayHostProps["trash"]>["commands"]["purge"]; |
| 48 | }; |
| 49 | setSettingsTarget: NonNullable<AppOverlayHostProps["settings"]>["commands"]["onNavigate"]; |
| 50 | }): AppOverlayHostProps { |
| 51 | const { t, history, navigation, chrome, worktree, shell, sessionActions } = input; |
| 52 | const histView = input.histView; |
| 53 | const settingsTarget = shell.settingsTarget; |
| 54 | return { |
| 55 | history: histView ? { |
| 56 | view: { kind: histView.kind, sessions: histView.sessions, running: input.running }, |
| 57 | commands: { |
| 58 | onResume: navigation.onResumeSession, onPreview: sessionActions.previewSession, onDelete: history.onDeleteSession, |
| 59 | onRename: history.onRenameHistorySession, |
| 60 | onInspectVersions: requestSessionVersions, onClose: history.closeHistory, |
| 61 | }, |
| 62 | } : undefined, |
| 63 | trash: shell.visitedTrash ? { view: { active: input.pageKind === "trash" }, |
| 64 | commands: { onBack: shell.returnToWorkspace, onOpenSession: navigation.openCanonicalSession, list: sessionActions.listTrashedSessions, restore: sessionActions.restoreSession, purge: sessionActions.purgeTrashedSession } } : undefined, |
| 65 | automation: shell.visitedAutomation ? { view: { active: input.pageKind === "automation" }, |
| 66 | commands: { onBack: shell.returnToWorkspace, onOpenTopic: input.automationTopic } } : undefined, |
| 67 | recovery: { |
| 68 | view: { sessions: histView?.sessions }, |
| 69 | commands: { onResumeSession: navigation.onResumeSession, onRecoveryCreated: navigation.onRecoveryCreated, onLineageChanged: navigation.onRecoveryLineageChanged }, |
| 70 | }, |
| 71 | settings: settingsTarget ? { |
| 72 | view: { |
| 73 | initialTab: settingsTarget, initialFocus: shell.settingsFocus ?? undefined, |
| 74 | agentRunning: input.running, desktopPlatform: shell.desktopPlatform, |
| 75 | activeWorkspaceKey: `${input.activeTab?.id ?? input.activeTabId ?? ""}\u0000${input.activeTab?.workspaceRoot ?? input.activeTab?.cwd ?? input.cwd ?? ""}`, |
| 76 | }, |
| 77 | commands: { onUseSubagent: input.prefillSubagentCommand, onClose: chrome.closeSettings, onNavigate: input.setSettingsTarget, onChanged: chrome.handleSettingsChanged }, |
| 78 | } : undefined, |
| 79 | palette: shell.paletteOpen ? { |
| 80 | view: { open: true, items: input.paletteItems, placeholder: t("palette.placeholder"), emptyText: t("palette.empty") }, |
| 81 | commands: { onClose: () => shell.setPaletteOpen(false) }, |
| 82 | } : undefined, |
| 83 | shortcuts: { |
| 84 | view: { open: shell.shortcutsOpen, platform: shell.desktopPlatform, t }, |
| 85 | commands: { onClose: () => shell.setShortcutsOpen(false) }, |
| 86 | }, |
| 87 | startup: shell.startupSplashVisible ? { |
| 88 | view: { hold: input.startupSplashHold }, commands: { onDone: () => shell.setStartupSplashVisible(false) }, |
| 89 | } : undefined, |
| 90 | worktree: worktree.worktreeMergeTabId ? { |
| 91 | view: { tabId: worktree.worktreeMergeTabId, isOpen: true }, |
| 92 | commands: { onClose: worktree.closeWorktreeMerge, onMerged: worktree.handleWorktreeMerged }, |
| 93 | } : undefined, |
| 94 | }; |
| 95 | } |
| 96 |