moi-computer 0.3.0-next.1 → 0.3.0-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/README.md +1 -1
  2. package/bunfig.toml +5 -1
  3. package/client/AGENTS.md +17 -2
  4. package/client/accept-hmr-dependencies.ts +22 -0
  5. package/client/api/http.ts +31 -0
  6. package/client/api/query-options.ts +6 -0
  7. package/client/api/workspace-keys.ts +18 -0
  8. package/client/app/AppRouter.tsx +44 -0
  9. package/client/app/routes/HomeRoute.tsx +13 -0
  10. package/client/app/routes/WorkspaceRoute.tsx +95 -0
  11. package/client/app/shell/SidebarLayout.tsx +196 -0
  12. package/client/assets/openai.svg +3 -0
  13. package/client/assets.d.ts +9 -0
  14. package/client/components/{BottomPanel.tsx → shared/BottomPanel.tsx} +2 -2
  15. package/client/components/shared/PanelHeader.tsx +9 -0
  16. package/client/components/shared/ReorderableList.tsx +199 -0
  17. package/client/components/ui/button.tsx +11 -7
  18. package/client/components/ui/collapsible.tsx +15 -0
  19. package/client/components/ui/dialog.tsx +2 -2
  20. package/client/components/ui/dropdown-menu.tsx +5 -5
  21. package/client/components/ui/hover-card.tsx +1 -1
  22. package/client/components/ui/input.tsx +1 -1
  23. package/client/components/ui/popover.tsx +1 -1
  24. package/client/components/ui/skeleton.tsx +13 -0
  25. package/client/components/ui/tooltip.tsx +1 -1
  26. package/client/externalize-react.ts +7 -1
  27. package/client/features/applets/AppletMount.tsx +44 -0
  28. package/client/{components → features/applets}/WidgetErrorBoundary.tsx +1 -1
  29. package/client/{components → features/applets}/WidgetShell.tsx +5 -2
  30. package/client/{lib → features/applets}/applet-cache.ts +8 -0
  31. package/client/features/applets/applet-styles.ts +61 -0
  32. package/client/{hooks → features/applets}/useApplet.ts +6 -7
  33. package/client/{components/ChatInput.tsx → features/chat/ChatComposer.tsx} +30 -24
  34. package/client/features/chat/ChatPanel.tsx +171 -0
  35. package/client/{components → features/chat}/ChatPopup.tsx +24 -13
  36. package/client/{components/ThreadSelector.tsx → features/chat/ChatSelector.tsx} +15 -13
  37. package/client/{components → features/chat}/MarkdownContent.tsx +1 -1
  38. package/client/{components → features/chat}/ModelPicker.tsx +68 -17
  39. package/client/{components → features/chat}/TurnView.tsx +17 -11
  40. package/client/features/chat/api.ts +78 -0
  41. package/client/features/chat/chat-connection.ts +107 -0
  42. package/client/features/chat/chat-frames.ts +131 -0
  43. package/client/features/chat/chat-send.ts +57 -0
  44. package/client/{lib → features/chat}/preview-turn.ts +1 -1
  45. package/client/{components → features/chat}/tool-group/ReadImagePreview.tsx +1 -1
  46. package/client/{components → features/chat}/tool-group/SubagentCard.tsx +12 -10
  47. package/client/{components → features/chat}/tool-group/TimelineRow.tsx +5 -5
  48. package/client/{components → features/chat}/tool-group/ToolCallGroup.tsx +14 -5
  49. package/client/{components → features/chat}/tool-group/ToolOutput.tsx +12 -18
  50. package/client/{components → features/chat}/tool-group/format.ts +117 -0
  51. package/client/{hooks → features/chat}/useChat.ts +16 -44
  52. package/client/features/connectors/ConnectorsPage.tsx +92 -0
  53. package/client/features/connectors/McpMenu.tsx +145 -0
  54. package/client/features/connectors/api.ts +28 -0
  55. package/client/features/dev/DevRoutes.tsx +18 -0
  56. package/client/features/dev/HarnessDebugPage.tsx +468 -0
  57. package/client/{components/playground → features/dev}/PixelPainter.tsx +10 -21
  58. package/client/{components/playground → features/dev}/PlaygroundPage.tsx +10 -12
  59. package/client/{components/playground → features/dev}/ToolCallsPage.tsx +9 -11
  60. package/client/features/home/CreateWorkspaceDialog.tsx +130 -0
  61. package/client/features/home/CreateWorkspaceDialogSteps.tsx +234 -0
  62. package/client/features/home/HomeLogo.tsx +344 -0
  63. package/client/features/home/HomePage.tsx +214 -0
  64. package/client/{components → features/home}/WorkspacePreview.tsx +4 -4
  65. package/client/features/home/api.ts +156 -0
  66. package/client/features/home/workspace-presentation.tsx +44 -0
  67. package/client/features/scratchpad/Scratchpad.tsx +312 -0
  68. package/client/features/scratchpad/ScratchpadControls.tsx +503 -0
  69. package/client/features/scratchpad/useScratchpadSnapshot.tsx +115 -0
  70. package/client/features/settings/EnvironmentSettings.tsx +149 -0
  71. package/client/features/settings/GeneralSettings.tsx +90 -0
  72. package/client/{components → features}/settings/IconPicker.tsx +76 -224
  73. package/client/features/settings/SettingsLayout.tsx +53 -0
  74. package/client/{components → features}/settings/WorkspaceSettings.tsx +12 -16
  75. package/client/features/settings/api.ts +88 -0
  76. package/client/features/settings/icon-picker-options.ts +30 -0
  77. package/client/{hooks → features/settings}/useEnvVars.ts +4 -4
  78. package/client/features/views/ViewBuilderTab.tsx +153 -0
  79. package/client/features/views/api.ts +124 -0
  80. package/client/features/views/useViewBuilderActions.ts +72 -0
  81. package/client/{components → features/widgets}/HiddenPanel.tsx +3 -3
  82. package/client/{components → features/widgets}/WidgetFrame.tsx +3 -8
  83. package/client/{components → features/widgets}/WidgetGrid.tsx +38 -29
  84. package/client/features/widgets/Widgets.tsx +265 -0
  85. package/client/{lib/grid-pack.ts → features/widgets/grid.ts} +7 -1
  86. package/client/{hooks → features/widgets}/useGridReconcile.ts +1 -1
  87. package/client/{components → features/workspace}/CustomizePanel.tsx +5 -6
  88. package/client/{lib → features/workspace}/WorkspaceLayoutContext.tsx +16 -15
  89. package/client/features/workspace/WorkspaceScreen.tsx +675 -0
  90. package/client/features/workspace/WorkspaceTabs.tsx +205 -0
  91. package/client/features/workspace/api.ts +56 -0
  92. package/client/features/workspace/useFitsSplitLayout.ts +37 -0
  93. package/client/global.d.ts +5 -0
  94. package/client/index.css +6 -45
  95. package/client/index.html +2 -2
  96. package/client/index.tsx +14 -31
  97. package/client/lib/app-icon-registry.ts +145 -0
  98. package/client/main.tsx +2 -2
  99. package/client/runtime/hmr-watchdog.ts +39 -0
  100. package/client/{hooks/useMeiEvents.ts → runtime/useWorkspaceEvents.ts} +12 -7
  101. package/client/store/ui.ts +5 -1
  102. package/client/theme.css +1 -3
  103. package/dist/chunk-11cab5dq.css +1 -0
  104. package/dist/chunk-4vf1t6v1.js +10 -0
  105. package/dist/chunk-6c24yndg.js +61 -0
  106. package/dist/chunk-6c8cwpzc.js +1 -0
  107. package/dist/chunk-b4b276wx.js +15 -0
  108. package/dist/chunk-cs8vbert.js +546 -0
  109. package/dist/chunk-cwqmay73.css +1 -0
  110. package/dist/chunk-kxmvv1ax.js +48 -0
  111. package/dist/chunk-pcnahct1.js +5 -0
  112. package/dist/chunk-rq0ar7vp.js +1 -0
  113. package/dist/chunk-tqd3pkg8.css +1 -0
  114. package/dist/chunk-vkvb3hjm.js +2 -0
  115. package/dist/chunk-zpxrb1ce.js +2 -0
  116. package/dist/index.html +3 -3
  117. package/dist/openai-h13pza4b.svg +3 -0
  118. package/lib/format.ts +2 -2
  119. package/lib/types.ts +56 -9
  120. package/lib/view-builder-meta.ts +35 -0
  121. package/lib/workspace-layout.ts +14 -0
  122. package/lib/workspace-name.ts +14 -0
  123. package/package.json +4 -2
  124. package/server/AGENTS.md +3 -3
  125. package/server/api.ts +279 -60
  126. package/server/applets.ts +1 -1
  127. package/server/bundle-queue.ts +19 -0
  128. package/server/bundler/applet-css.ts +50 -0
  129. package/server/{build-applet.ts → bundler/build-applet.ts} +36 -26
  130. package/server/cli.ts +90 -7
  131. package/server/control.ts +106 -8
  132. package/server/env-apply.ts +2 -2
  133. package/server/harness/README.md +228 -0
  134. package/server/harness/claude-code/NOTES.md +578 -0
  135. package/{lib/claude-adapter.ts → server/harness/claude-code/adapter.ts} +67 -5
  136. package/server/harness/claude-code/index.ts +124 -0
  137. package/server/{mcp.ts → harness/claude-code/mcp.ts} +73 -16
  138. package/server/{cc-session.ts → harness/claude-code/session.ts} +42 -14
  139. package/server/harness/claude-code/sessions.ts +42 -0
  140. package/server/harness/codex/NOTES.md +239 -0
  141. package/server/harness/codex/adapter.ts +414 -0
  142. package/server/harness/codex/client.ts +343 -0
  143. package/server/harness/codex/index.ts +68 -0
  144. package/server/harness/codex/probe.ts +186 -0
  145. package/server/harness/codex/session.ts +617 -0
  146. package/server/harness/debug.ts +57 -0
  147. package/server/harness/openclaw/NOTES.md +316 -0
  148. package/server/{openclaw-adapter.ts → harness/openclaw/adapter.ts} +2 -2
  149. package/server/harness/openclaw/index.ts +93 -0
  150. package/server/{openclaw-session.ts → harness/openclaw/session.ts} +44 -9
  151. package/server/{openclaw-strip.ts → harness/openclaw/strip.ts} +3 -1
  152. package/server/harness/registry.ts +36 -0
  153. package/server/harness/types.ts +87 -0
  154. package/server/layout.ts +36 -11
  155. package/server/moi-scaffold.ts +56 -11
  156. package/server/registry.ts +30 -52
  157. package/server/state.ts +5 -38
  158. package/server/status.ts +7 -46
  159. package/server/vendor.ts +1 -1
  160. package/server/view-builders.ts +428 -0
  161. package/server/views.ts +0 -0
  162. package/server/web.ts +19 -40
  163. package/server/workspace-init.ts +11 -25
  164. package/tsconfig.json +1 -1
  165. package/workspace/.claude/skills/moi-workspace/DESIGN.md +2 -1
  166. package/workspace/.claude/skills/moi-workspace/SKILL.md +28 -7
  167. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +1 -1
  168. package/client/api/workspaces.ts +0 -427
  169. package/client/assets/hermes-nous.png +0 -0
  170. package/client/components/App.tsx +0 -41
  171. package/client/components/ChatPanel.tsx +0 -275
  172. package/client/components/HomePage.tsx +0 -17
  173. package/client/components/McpMenu.tsx +0 -125
  174. package/client/components/Scratchpad.tsx +0 -935
  175. package/client/components/Widgets.tsx +0 -132
  176. package/client/components/WorkspacesPage.tsx +0 -245
  177. package/client/components/layout/SidebarLayout.tsx +0 -258
  178. package/client/components/routes/workspace/[id].tsx +0 -675
  179. package/client/components/routes/workspace/create.tsx +0 -155
  180. package/client/components/settings/SettingsPages.tsx +0 -255
  181. package/client/hooks/useFitsSidebar.ts +0 -34
  182. package/client/hooks/useScrollFade.ts +0 -38
  183. package/client/lib/connection.ts +0 -238
  184. package/dist/chunk-07qf2tv1.css +0 -1
  185. package/dist/chunk-w18801vn.js +0 -672
  186. package/dist/hermes-nous-pznd63x9.png +0 -0
  187. /package/client/components/{playground → shared}/LedLogo.tsx +0 -0
  188. /package/client/{components → features/chat}/ShimmerText.tsx +0 -0
  189. /package/client/{store/live.ts → features/chat/chat-store.ts} +0 -0
  190. /package/client/{lib → features/chat}/group-turns.ts +0 -0
  191. /package/client/{components → features/chat}/tool-group/CodeBlock.tsx +0 -0
  192. /package/client/{components → features/chat}/tool-group/Collapse.tsx +0 -0
  193. /package/client/{components → features/chat}/tool-group/detect.ts +0 -0
  194. /package/client/{components → features/chat}/tool-group/fixtures.ts +0 -0
  195. /package/client/{components → features/chat}/tool-group/index.ts +0 -0
  196. /package/client/{lib → features/chat}/uploads.ts +0 -0
  197. /package/client/{hooks → features/chat}/useStickToBottom.ts +0 -0
  198. /package/client/{components → features/connectors}/IconMcp.tsx +0 -0
  199. /package/client/{lib → features/connectors}/mcp-icons.ts +0 -0
  200. /package/client/{lib → features/scratchpad}/scratch-executor.ts +0 -0
  201. /package/client/{lib → features/settings}/render-icon.ts +0 -0
  202. /package/client/{lib → features/workspace}/WorkspaceContext.tsx +0 -0
  203. /package/client/{hooks → features/workspace}/useWorkspaceTheme.ts +0 -0
  204. /package/server/{agent.ts → harness/claude-code/models.ts} +0 -0
  205. /package/server/{openclaw.ts → harness/openclaw/discovery.ts} +0 -0
  206. /package/server/{openclaw-gateway.ts → harness/openclaw/gateway.ts} +0 -0
@@ -0,0 +1,675 @@
1
+ import { lazy, Suspense, useEffect, useRef, useState } from 'react'
2
+
3
+ import { AnimatePresence, motion } from 'motion/react'
4
+
5
+ import {
6
+ IconArticle,
7
+ IconBrowserPlus,
8
+ IconGhost,
9
+ IconLayout2,
10
+ IconLayoutSidebarRight,
11
+ IconPalette,
12
+ IconSketching
13
+ } from '@tabler/icons-react'
14
+ import { ChatPanel } from '@/client/features/chat/ChatPanel'
15
+ import { ChatPopup } from '@/client/features/chat/ChatPopup'
16
+ import { CustomizePanel } from '@/client/features/workspace/CustomizePanel'
17
+ import { McpMenu } from '@/client/features/connectors/McpMenu'
18
+ import { AppletMount } from '@/client/features/applets/AppletMount'
19
+ import { WidgetErrorBoundary } from '@/client/features/applets/WidgetErrorBoundary'
20
+ import { Widgets } from '@/client/features/widgets/Widgets'
21
+ import { PanelHeader } from '@/client/components/shared/PanelHeader'
22
+ import { workspaceProviderIcon } from '@/client/features/home/workspace-presentation'
23
+ import { Button } from '@/client/components/ui/button'
24
+ import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
25
+ import { WorkspaceSettings } from '@/client/features/settings/WorkspaceSettings'
26
+ import { useChat } from '@/client/features/chat/useChat'
27
+ import { useView } from '@/client/features/applets/useApplet'
28
+ import { ViewBuilderTab } from '@/client/features/views/ViewBuilderTab'
29
+ import { useViewBuilderActions } from '@/client/features/views/useViewBuilderActions'
30
+ import { useFitsSplitLayout } from '@/client/features/workspace/useFitsSplitLayout'
31
+ import { useWorkspaceTheme } from '@/client/features/workspace/useWorkspaceTheme'
32
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
33
+ import { resolveAppIcon } from '@/client/lib/app-icon-registry'
34
+ import { cn } from '@/client/lib/cn'
35
+ import { liveStore } from '@/client/features/chat/chat-store'
36
+ import {
37
+ type CreateWorkspaceTabItem,
38
+ type WorkspaceTabItem,
39
+ WorkspaceTabs
40
+ } from '@/client/features/workspace/WorkspaceTabs'
41
+ import type {
42
+ LayoutMode,
43
+ ViewBuilder,
44
+ ViewInfo,
45
+ WidgetInfo,
46
+ WorkspaceTabId,
47
+ WorkspaceTabsState
48
+ } from '@/lib/types'
49
+ import { createDefaultWorkspaceTabs } from '@/lib/workspace-layout'
50
+
51
+ const Scratchpad = lazy(() =>
52
+ import('@/client/features/scratchpad/Scratchpad').then(module => ({
53
+ default: module.Scratchpad
54
+ }))
55
+ )
56
+
57
+ // Tab label for a view: its configured title, or the file-name id as fallback.
58
+ const viewLabel = (v: ViewInfo) => v.config.title || v.id
59
+
60
+ const viewBuilderIcon = (builder: ViewBuilder) => resolveAppIcon(builder.icon) ?? IconArticle
61
+
62
+ function viewIcon(view: ViewInfo, builders: ViewBuilder[]) {
63
+ const builder = builders.find(candidate => candidate.viewId === view.id)
64
+ return resolveAppIcon(view.config.icon) ?? resolveAppIcon(builder?.icon) ?? IconArticle
65
+ }
66
+
67
+ const DEFAULT_TABS = createDefaultWorkspaceTabs()
68
+
69
+ const viewTabId = (id: string): WorkspaceTabId => `view:${id}`
70
+ const viewIdFromTab = (tab: WorkspaceTabId) => (tab.startsWith('view:') ? tab.slice(5) : null)
71
+ const viewBuilderTabId = (id: string): WorkspaceTabId => `view-builder:${id}`
72
+ const viewBuilderIdFromTab = (tab: WorkspaceTabId) =>
73
+ tab.startsWith('view-builder:') ? tab.slice('view-builder:'.length) : null
74
+
75
+ type SectionControlsProps = {
76
+ mode: LayoutMode
77
+ onToggleMode: () => void
78
+ }
79
+
80
+ // Temporary layout switch: fullscreen tabbed workspace ⇄ legacy split view.
81
+ function SectionControls({ mode, onToggleMode }: SectionControlsProps) {
82
+ const fullscreen = mode === 'fullscreen'
83
+ return (
84
+ <Button
85
+ variant="ghost"
86
+ size="icon-sm"
87
+ onClick={onToggleMode}
88
+ aria-label={fullscreen ? 'Switch to split view' : 'Switch to full-screen view'}
89
+ >
90
+ <IconLayoutSidebarRight stroke={1.75} />
91
+ </Button>
92
+ )
93
+ }
94
+
95
+ type ViewAppProps = {
96
+ view: ViewInfo
97
+ }
98
+
99
+ // A view — an agent-defined app — mounted full-area. The bundle owns its own
100
+ // layout + scroll, so we give it a plain filled box and fade it in (mirroring
101
+ // WidgetShell, but full-area instead of a grid cell).
102
+ function ViewApp({ view }: ViewAppProps) {
103
+ const bundle = useView(view.id)
104
+
105
+ return (
106
+ <div className="relative min-h-0 flex-1 overflow-hidden">
107
+ <AnimatePresence mode="wait" initial={false}>
108
+ {bundle.status === 'ready' && (
109
+ <AppletMount
110
+ asChild
111
+ segment="views"
112
+ name={view.id}
113
+ version={bundle.version}
114
+ key={bundle.version}
115
+ >
116
+ <motion.div
117
+ className="absolute inset-0 overflow-auto"
118
+ initial={{ opacity: 0, filter: 'blur(4px)' }}
119
+ animate={{ opacity: 1, filter: 'blur(0px)' }}
120
+ exit={{ opacity: 0, filter: 'blur(4px)' }}
121
+ transition={{ duration: 0.3, ease: 'easeInOut' }}
122
+ >
123
+ <WidgetErrorBoundary name={view.id} resetKey={bundle.version}>
124
+ <bundle.Component />
125
+ </WidgetErrorBoundary>
126
+ </motion.div>
127
+ </AppletMount>
128
+ )}
129
+ {bundle.status === 'error' && (
130
+ <motion.p
131
+ key={`err-${bundle.version}`}
132
+ className="absolute inset-0 p-4 text-xs text-destructive"
133
+ initial={{ opacity: 0 }}
134
+ animate={{ opacity: 1 }}
135
+ exit={{ opacity: 0 }}
136
+ transition={{ duration: 0.3, ease: 'easeInOut' }}
137
+ >
138
+ {bundle.error}
139
+ </motion.p>
140
+ )}
141
+ </AnimatePresence>
142
+ </div>
143
+ )
144
+ }
145
+
146
+ type WorkspaceCustomizeActionProps = {
147
+ active: boolean
148
+ onToggle: () => void
149
+ }
150
+
151
+ function WorkspaceCustomizeAction({ active, onToggle }: WorkspaceCustomizeActionProps) {
152
+ return (
153
+ <Tooltip delay={50}>
154
+ <TooltipTrigger
155
+ render={
156
+ <Button
157
+ variant={active ? 'secondary' : 'ghost'}
158
+ size="icon-sm"
159
+ aria-label="Customize"
160
+ aria-pressed={active}
161
+ onClick={onToggle}
162
+ >
163
+ <IconPalette stroke={1.75} />
164
+ </Button>
165
+ }
166
+ />
167
+ <TooltipContent>Customize</TooltipContent>
168
+ </Tooltip>
169
+ )
170
+ }
171
+
172
+ type WorkspaceScreenProps = {
173
+ widgets: WidgetInfo[]
174
+ views: ViewInfo[]
175
+ builders: ViewBuilder[]
176
+ }
177
+
178
+ type WidgetMode = 'idle' | 'editing' | 'customizing'
179
+
180
+ function normalizeTabsState(tabs: WorkspaceTabsState | undefined): WorkspaceTabsState {
181
+ if (!tabs || !Array.isArray(tabs.open)) return DEFAULT_TABS
182
+ const open = tabs.open.filter((tab, index, all) => all.indexOf(tab) === index)
183
+ if (open.length === 0) return DEFAULT_TABS
184
+ return { open, active: open.includes(tabs.active) ? tabs.active : open[0] }
185
+ }
186
+
187
+ function tabAvailable(tab: WorkspaceTabId, views: ViewInfo[], builders: ViewBuilder[]) {
188
+ if (tab === 'agent' || tab === 'widgets' || tab === 'scratchpad') return true
189
+ const builderId = viewBuilderIdFromTab(tab)
190
+ if (builderId) return builders.some(builder => builder.id === builderId)
191
+ const viewId = viewIdFromTab(tab)
192
+ return viewId ? views.some(v => v.id === viewId) : false
193
+ }
194
+
195
+ function tabItemFor(
196
+ tab: WorkspaceTabId,
197
+ views: ViewInfo[],
198
+ builders: ViewBuilder[],
199
+ closable: boolean
200
+ ): WorkspaceTabItem | null {
201
+ if (tab === 'agent') {
202
+ return {
203
+ key: tab,
204
+ Icon: IconGhost,
205
+ label: 'Agent',
206
+ closable
207
+ }
208
+ }
209
+ if (tab === 'widgets') {
210
+ return {
211
+ key: tab,
212
+ Icon: IconLayout2,
213
+ label: 'Widgets',
214
+ closable
215
+ }
216
+ }
217
+ if (tab === 'scratchpad') {
218
+ return {
219
+ key: tab,
220
+ Icon: IconSketching,
221
+ label: 'Scratchpad',
222
+ closable
223
+ }
224
+ }
225
+ const builderId = viewBuilderIdFromTab(tab)
226
+ const builder = builderId ? builders.find(candidate => candidate.id === builderId) : null
227
+ if (builder) {
228
+ return {
229
+ key: tab,
230
+ Icon: viewBuilderIcon(builder),
231
+ label: builder.title || builder.viewId || 'New view',
232
+ closable
233
+ }
234
+ }
235
+ const viewId = viewIdFromTab(tab)
236
+ const view = viewId ? views.find(v => v.id === viewId) : null
237
+ return view
238
+ ? {
239
+ key: tab,
240
+ Icon: viewIcon(view, builders),
241
+ label: viewLabel(view),
242
+ closable
243
+ }
244
+ : null
245
+ }
246
+
247
+ function applyVisibleTabOrder(
248
+ open: WorkspaceTabId[],
249
+ visible: WorkspaceTabId[],
250
+ orderedVisible: WorkspaceTabId[]
251
+ ) {
252
+ const visibleSet = new Set(visible)
253
+ let cursor = 0
254
+ return open.map(tab => (visibleSet.has(tab) ? orderedVisible[cursor++] : tab))
255
+ }
256
+
257
+ export function WorkspaceScreen({ widgets, views, builders }: WorkspaceScreenProps) {
258
+ const {
259
+ view,
260
+ previewTurn,
261
+ sessionId,
262
+ processing,
263
+ error,
264
+ send,
265
+ stop,
266
+ switchThread,
267
+ dismissError
268
+ } = useChat()
269
+ const { layout, setLayout, name, icon, provider, workspaceId } = useWorkspaceLayoutCtx()
270
+ const builderActions = useViewBuilderActions()
271
+ const { ref: rowRef, fits: canUseSplit } = useFitsSplitLayout<HTMLDivElement>()
272
+ const [widgetMode, setWidgetMode] = useState<WidgetMode>('idle')
273
+ const [floatingChatOpen, setFloatingChatOpen] = useState(false)
274
+ const [chatFocusRequest, setChatFocusRequest] = useState(0)
275
+
276
+ // Theme is scoped to this wrapper, not :root — the sidebar keeps the default
277
+ // tokens. The floating chat portals into the same element so it inherits them.
278
+ const themeRef = useRef<HTMLDivElement>(null)
279
+ useWorkspaceTheme(layout.theme, themeRef)
280
+
281
+ const tabsState = normalizeTabsState(layout.tabs)
282
+ const tabsStateRef = useRef(tabsState)
283
+ tabsStateRef.current = tabsState
284
+ const availableOpenTabs = tabsState.open.filter(tab => tabAvailable(tab, views, builders))
285
+ const effectiveOpenTabs = availableOpenTabs.length > 0 ? availableOpenTabs : DEFAULT_TABS.open
286
+ const openSet = new Set(tabsState.open)
287
+ const nonAgentOpenTabs = effectiveOpenTabs.filter(tab => tab !== 'agent')
288
+ const hasWorkspaceContent = nonAgentOpenTabs.length > 0
289
+
290
+ // Effective layout mode. Split is only visible with workspace content and
291
+ // enough row width; the saved mode remains the user's intent.
292
+ const wantsSplit = layout.layoutMode === 'split' && hasWorkspaceContent
293
+ const mode: LayoutMode = wantsSplit && canUseSplit ? 'split' : 'fullscreen'
294
+ const dockedSplit = mode === 'split'
295
+
296
+ const setMode = (m: LayoutMode) => {
297
+ if (m === 'split' && tabsState.active === 'agent') {
298
+ setLayout({
299
+ layoutMode: m,
300
+ tabs: {
301
+ open: tabsState.open,
302
+ active: nonAgentOpenTabs[0] ?? tabsState.active
303
+ }
304
+ })
305
+ return
306
+ }
307
+ setLayout({ layoutMode: m })
308
+ }
309
+
310
+ const visibleTabIds = dockedSplit ? nonAgentOpenTabs : effectiveOpenTabs
311
+ const activeTab: WorkspaceTabId = visibleTabIds.includes(tabsState.active)
312
+ ? tabsState.active
313
+ : (visibleTabIds[0] ?? 'agent')
314
+ const canCloseTabs = effectiveOpenTabs.length > 1
315
+ const tabItems = visibleTabIds
316
+ .map(tab =>
317
+ tabItemFor(tab, views, builders, canCloseTabs || viewBuilderIdFromTab(tab) !== null)
318
+ )
319
+ .filter((tab): tab is WorkspaceTabItem => Boolean(tab))
320
+ const activeViewId = viewIdFromTab(activeTab)
321
+ const activeView = activeViewId ? views.find(v => v.id === activeViewId) : undefined
322
+ const activeBuilderId = viewBuilderIdFromTab(activeTab)
323
+ const activeBuilder = activeBuilderId
324
+ ? builders.find(builder => builder.id === activeBuilderId)
325
+ : undefined
326
+
327
+ useEffect(() => {
328
+ const open = tabsState.open.filter(tab => tabAvailable(tab, views, builders))
329
+ if (open.length === tabsState.open.length) return
330
+ const nextOpen = open.length > 0 ? open : DEFAULT_TABS.open
331
+ setLayout({
332
+ tabs: {
333
+ open: nextOpen,
334
+ active: nextOpen.includes(tabsState.active) ? tabsState.active : nextOpen[0]
335
+ }
336
+ })
337
+ }, [builders, setLayout, tabsState.active, tabsState.open, views])
338
+
339
+ useEffect(() => {
340
+ const replacements = new Map<WorkspaceTabId, WorkspaceTabId>()
341
+ for (const builder of builders) {
342
+ if (builder.status !== 'ready' || !builder.viewId) continue
343
+ if (!views.some(view => view.id === builder.viewId)) continue
344
+ replacements.set(viewBuilderTabId(builder.id), viewTabId(builder.viewId))
345
+ }
346
+ if (replacements.size === 0) return
347
+
348
+ const replacementViews = new Set(replacements.values())
349
+ const sourceForView = new Map(
350
+ [...replacements].map(([builderTab, viewTab]) => [viewTab, builderTab])
351
+ )
352
+ const open: WorkspaceTabId[] = []
353
+ let changed = false
354
+ for (const tab of tabsState.open) {
355
+ const source = sourceForView.get(tab)
356
+ if (replacementViews.has(tab) && source && tabsState.open.includes(source)) {
357
+ changed = true
358
+ continue
359
+ }
360
+ const replacement = replacements.get(tab)
361
+ const next = replacement ?? tab
362
+ if (replacement) changed = true
363
+ if (!open.includes(next)) open.push(next)
364
+ }
365
+ if (!changed) return
366
+ const active = replacements.get(tabsState.active) ?? tabsState.active
367
+ setLayout({ tabs: { open: open.length > 0 ? open : ['agent'], active } })
368
+ }, [builders, setLayout, tabsState.active, tabsState.open, views])
369
+
370
+ useEffect(() => {
371
+ const linked = activeBuilder ?? builders.find(builder => builder.viewId === activeViewId)
372
+ if (linked) liveStore.getState().setActive(workspaceId, linked.sessionId)
373
+ }, [activeBuilder, activeViewId, builders, workspaceId])
374
+
375
+ useEffect(() => {
376
+ if (mode !== 'fullscreen' || activeTab === 'agent') {
377
+ setFloatingChatOpen(false)
378
+ }
379
+ }, [activeTab, mode])
380
+
381
+ const setTabs = (tabs: WorkspaceTabsState) => {
382
+ tabsStateRef.current = tabs
383
+ setLayout({ tabs })
384
+ }
385
+
386
+ const openTab = (tab: WorkspaceTabId) => {
387
+ const current = tabsStateRef.current
388
+ const open = current.open.includes(tab) ? current.open : [...current.open, tab]
389
+ setTabs({ open, active: tab })
390
+ if (tab === 'agent') {
391
+ setFloatingChatOpen(false)
392
+ setChatFocusRequest(request => request + 1)
393
+ }
394
+ }
395
+
396
+ const closeTab = (tab: WorkspaceTabId) => {
397
+ const builderId = viewBuilderIdFromTab(tab)
398
+ const builder = builderId ? builders.find(candidate => candidate.id === builderId) : undefined
399
+ if ((!canCloseTabs && !builder) || !openSet.has(tab)) return
400
+ let open = tabsState.open.filter(t => t !== tab)
401
+ if (open.length === 0) open = ['agent']
402
+ let active = tabsState.active
403
+ if (active === tab || !open.includes(active)) {
404
+ const visibleIndex = visibleTabIds.indexOf(tab)
405
+ active =
406
+ visibleTabIds[visibleIndex + 1] ??
407
+ visibleTabIds[visibleIndex - 1] ??
408
+ open.find(t => tabAvailable(t, views, builders)) ??
409
+ 'agent'
410
+ }
411
+ setTabs({ open, active })
412
+ if (builder?.status === 'draft') void builderActions.discard(builder.id)
413
+ }
414
+
415
+ const discardBuilder = (builder: ViewBuilder) => {
416
+ const tab = viewBuilderTabId(builder.id)
417
+ if (openSet.has(tab)) {
418
+ let open = tabsState.open.filter(item => item !== tab)
419
+ if (open.length === 0) open = ['agent']
420
+ setTabs({ open, active: tabsState.active === tab ? open[0] : tabsState.active })
421
+ }
422
+ void builderActions.discard(builder.id)
423
+ }
424
+
425
+ const reorderTabs = (orderedVisibleTabs: WorkspaceTabId[]) => {
426
+ const open = applyVisibleTabOrder(tabsState.open, visibleTabIds, orderedVisibleTabs)
427
+ if (open === tabsState.open) return
428
+ setTabs({ open, active: tabsState.active })
429
+ }
430
+
431
+ const openChat = (intent?: string) => {
432
+ if (intent !== undefined) {
433
+ liveStore.getState().setDraft(workspaceId, sessionId, intent)
434
+ }
435
+ if (mode === 'fullscreen' && activeTab !== 'agent') {
436
+ setFloatingChatOpen(true)
437
+ if (floatingChatOpen) {
438
+ setChatFocusRequest(request => request + 1)
439
+ }
440
+ return
441
+ }
442
+ setChatFocusRequest(request => request + 1)
443
+ }
444
+
445
+ const createItems: CreateWorkspaceTabItem[] = [
446
+ ...(!dockedSplit && !openSet.has('agent')
447
+ ? ([
448
+ {
449
+ key: 'agent',
450
+ Icon: IconGhost,
451
+ label: 'Agent',
452
+ onClick: () => openTab('agent')
453
+ }
454
+ ] satisfies CreateWorkspaceTabItem[])
455
+ : []),
456
+ ...(!openSet.has('widgets')
457
+ ? ([
458
+ {
459
+ key: 'widgets',
460
+ Icon: IconLayout2,
461
+ label: 'Widgets',
462
+ onClick: () => openTab('widgets')
463
+ }
464
+ ] satisfies CreateWorkspaceTabItem[])
465
+ : []),
466
+ ...(!openSet.has('scratchpad')
467
+ ? ([
468
+ {
469
+ key: 'scratchpad',
470
+ Icon: IconSketching,
471
+ label: 'Scratchpad',
472
+ onClick: () => openTab('scratchpad')
473
+ }
474
+ ] satisfies CreateWorkspaceTabItem[])
475
+ : []),
476
+ ...views
477
+ .map(v => ({ view: v, tab: viewTabId(v.id) }))
478
+ .filter(({ tab }) => !openSet.has(tab))
479
+ .map(
480
+ ({ view, tab }): CreateWorkspaceTabItem => ({
481
+ key: tab,
482
+ Icon: viewIcon(view, builders),
483
+ label: viewLabel(view),
484
+ onClick: () => openTab(tab)
485
+ })
486
+ ),
487
+ ...builders
488
+ .filter(builder => builder.status !== 'ready')
489
+ .map(builder => ({ builder, tab: viewBuilderTabId(builder.id) }))
490
+ .filter(({ tab }) => !openSet.has(tab))
491
+ .map(
492
+ ({ builder, tab }): CreateWorkspaceTabItem => ({
493
+ key: tab,
494
+ Icon: viewBuilderIcon(builder),
495
+ label: builder.title || builder.viewId || 'New view',
496
+ onClick: () => openTab(tab)
497
+ })
498
+ ),
499
+ {
500
+ key: 'create-view',
501
+ Icon: IconBrowserPlus,
502
+ label: 'New view',
503
+ onClick: () => {
504
+ void builderActions.create().then(builder => openTab(viewBuilderTabId(builder.id)))
505
+ }
506
+ }
507
+ ]
508
+
509
+ // The docked split chat. Full-screen Agent uses the tabbed chat below.
510
+ const dockedChat = (
511
+ <ChatPanel
512
+ active={mode === 'split'}
513
+ focusRequest={chatFocusRequest}
514
+ view={view}
515
+ previewTurn={previewTurn}
516
+ sessionId={sessionId}
517
+ processing={processing}
518
+ error={error}
519
+ onDismissError={dismissError}
520
+ send={send}
521
+ stop={stop}
522
+ onSwitchThread={switchThread}
523
+ />
524
+ )
525
+
526
+ const tabbedChat = (
527
+ <ChatPanel
528
+ active={mode === 'fullscreen' && activeTab === 'agent'}
529
+ focusRequest={chatFocusRequest}
530
+ view={view}
531
+ previewTurn={previewTurn}
532
+ sessionId={sessionId}
533
+ processing={processing}
534
+ error={error}
535
+ onDismissError={dismissError}
536
+ send={send}
537
+ stop={stop}
538
+ onSwitchThread={switchThread}
539
+ />
540
+ )
541
+
542
+ return (
543
+ // Themed wrapper: scoped CSS vars (bg/fg/font) live here so the panel — and
544
+ // the portaled floating chat — pick up the workspace theme, while the
545
+ // sidebar outside stays default.
546
+ <div
547
+ ref={themeRef}
548
+ className="relative flex h-full min-h-0 flex-col bg-background font-sans text-foreground"
549
+ >
550
+ <div ref={rowRef} className="flex min-h-0 flex-1">
551
+ {/* Full-screen: whole panel. Split: the left content column. */}
552
+ {(mode === 'fullscreen' || hasWorkspaceContent) && (
553
+ <div
554
+ className={cn('flex min-h-0 flex-1 flex-col', mode === 'split' && 'min-w-(--column-w)')}
555
+ >
556
+ <PanelHeader>
557
+ <div className="flex min-w-0 flex-1 items-center gap-4">
558
+ <div className="flex items-center gap-2">
559
+ <img
560
+ src={icon ?? workspaceProviderIcon[provider ?? 'claude-code']}
561
+ alt=""
562
+ className="size-5 shrink-0 rounded-[4px]"
563
+ />
564
+ {name && (
565
+ <span className="truncate text-sm font-medium text-foreground">{name}</span>
566
+ )}
567
+ </div>
568
+ <WorkspaceTabs
569
+ tabs={tabItems}
570
+ active={activeTab}
571
+ createItems={createItems}
572
+ onSelect={openTab}
573
+ onClose={closeTab}
574
+ onReorder={reorderTabs}
575
+ />
576
+ </div>
577
+ <div className="flex shrink-0 items-center gap-1">
578
+ <WorkspaceCustomizeAction
579
+ active={widgetMode === 'customizing'}
580
+ onToggle={() =>
581
+ setWidgetMode(widgetMode === 'customizing' ? 'idle' : 'customizing')
582
+ }
583
+ />
584
+ <McpMenu />
585
+ <WorkspaceSettings />
586
+ {hasWorkspaceContent && canUseSplit && (
587
+ <SectionControls
588
+ mode={mode}
589
+ onToggleMode={() => setMode(mode === 'fullscreen' ? 'split' : 'fullscreen')}
590
+ />
591
+ )}
592
+ </div>
593
+ </PanelHeader>
594
+
595
+ {activeTab === 'agent' ? (
596
+ tabbedChat
597
+ ) : activeTab === 'widgets' ? (
598
+ <Widgets
599
+ editing={widgetMode === 'editing'}
600
+ onEditingChange={editing => setWidgetMode(editing ? 'editing' : 'idle')}
601
+ widgets={widgets}
602
+ onCreateWidget={() => openChat('Create widget')}
603
+ />
604
+ ) : activeTab === 'scratchpad' ? (
605
+ <Suspense fallback={null}>
606
+ <Scratchpad />
607
+ </Suspense>
608
+ ) : activeBuilder ? (
609
+ <ViewBuilderTab
610
+ key={activeBuilder.id}
611
+ builder={activeBuilder}
612
+ onSave={requirements => builderActions.save(activeBuilder.id, requirements)}
613
+ onSubmit={requirements => {
614
+ if (mode === 'fullscreen') setFloatingChatOpen(true)
615
+ return builderActions.submit(activeBuilder, requirements)
616
+ }}
617
+ onOpenChat={() => {
618
+ liveStore.getState().setActive(workspaceId, activeBuilder.sessionId)
619
+ openChat()
620
+ }}
621
+ onDiscard={() => discardBuilder(activeBuilder)}
622
+ />
623
+ ) : activeView ? (
624
+ <ViewApp view={activeView} />
625
+ ) : null}
626
+ </div>
627
+ )}
628
+
629
+ {/* Split: Agent chat as a bounded right column. Full-screen mode uses the
630
+ Agent tab instead. */}
631
+ {mode === 'split' && (
632
+ <div
633
+ className={cn(
634
+ 'flex min-h-0 min-w-(--chat-min) flex-[0_1_var(--chat-max)] flex-col overflow-hidden border-l border-border'
635
+ )}
636
+ >
637
+ {dockedChat}
638
+ </div>
639
+ )}
640
+ </div>
641
+
642
+ <AnimatePresence>{widgetMode === 'customizing' && <CustomizePanel />}</AnimatePresence>
643
+
644
+ {mode === 'fullscreen' && activeTab !== 'agent' && hasWorkspaceContent && (
645
+ <ChatPopup
646
+ open={floatingChatOpen}
647
+ onOpenChange={setFloatingChatOpen}
648
+ onOpenChangeComplete={open => {
649
+ if (open) {
650
+ setChatFocusRequest(request => request + 1)
651
+ }
652
+ }}
653
+ container={themeRef}
654
+ >
655
+ {onClose => (
656
+ <ChatPanel
657
+ active={floatingChatOpen}
658
+ focusRequest={chatFocusRequest}
659
+ view={view}
660
+ previewTurn={previewTurn}
661
+ sessionId={sessionId}
662
+ processing={processing}
663
+ error={error}
664
+ onDismissError={dismissError}
665
+ send={send}
666
+ stop={stop}
667
+ onSwitchThread={switchThread}
668
+ onClose={onClose}
669
+ />
670
+ )}
671
+ </ChatPopup>
672
+ )}
673
+ </div>
674
+ )
675
+ }