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

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 (146) hide show
  1. package/bunfig.toml +5 -1
  2. package/client/AGENTS.md +15 -0
  3. package/client/accept-hmr-dependencies.ts +22 -0
  4. package/client/api/http.ts +31 -0
  5. package/client/api/query-options.ts +6 -0
  6. package/client/api/workspace-keys.ts +17 -0
  7. package/client/app/AppRouter.tsx +35 -0
  8. package/client/app/routes/HomeRoute.tsx +13 -0
  9. package/client/app/routes/WorkspaceRoute.tsx +89 -0
  10. package/client/app/shell/SidebarLayout.tsx +191 -0
  11. package/client/assets.d.ts +9 -0
  12. package/client/components/playground/PixelPainter.tsx +10 -21
  13. package/client/components/playground/PlaygroundPage.tsx +9 -11
  14. package/client/components/playground/ToolCallsPage.tsx +9 -11
  15. package/client/components/{BottomPanel.tsx → shared/BottomPanel.tsx} +1 -1
  16. package/client/components/shared/PanelHeader.tsx +9 -0
  17. package/client/components/shared/ReorderableList.tsx +199 -0
  18. package/client/components/ui/button.tsx +10 -7
  19. package/client/components/ui/collapsible.tsx +15 -0
  20. package/client/components/ui/dialog.tsx +2 -2
  21. package/client/components/ui/dropdown-menu.tsx +5 -5
  22. package/client/components/ui/hover-card.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/{components → features/applets}/WidgetErrorBoundary.tsx +1 -1
  28. package/client/{components → features/applets}/WidgetShell.tsx +1 -1
  29. package/client/{hooks → features/applets}/useApplet.ts +6 -7
  30. package/client/{components/ChatInput.tsx → features/chat/ChatComposer.tsx} +29 -23
  31. package/client/features/chat/ChatPanel.tsx +188 -0
  32. package/client/{components → features/chat}/ChatPopup.tsx +23 -12
  33. package/client/{components → features/chat}/MarkdownContent.tsx +1 -1
  34. package/client/{components → features/chat}/ModelPicker.tsx +68 -17
  35. package/client/{components → features/chat}/ThreadSelector.tsx +11 -9
  36. package/client/{components → features/chat}/TurnView.tsx +16 -9
  37. package/client/features/chat/api.ts +78 -0
  38. package/client/features/chat/chat-connection.ts +107 -0
  39. package/client/features/chat/chat-frames.ts +131 -0
  40. package/client/{lib → features/chat}/preview-turn.ts +1 -1
  41. package/client/{components → features/chat}/tool-group/ReadImagePreview.tsx +1 -1
  42. package/client/{components → features/chat}/tool-group/SubagentCard.tsx +12 -10
  43. package/client/{components → features/chat}/tool-group/TimelineRow.tsx +5 -5
  44. package/client/{components → features/chat}/tool-group/ToolCallGroup.tsx +12 -4
  45. package/client/{components → features/chat}/tool-group/ToolOutput.tsx +12 -18
  46. package/client/{hooks → features/chat}/useChat.ts +7 -11
  47. package/client/features/connectors/ConnectorsPage.tsx +92 -0
  48. package/client/features/connectors/McpMenu.tsx +162 -0
  49. package/client/features/connectors/api.ts +28 -0
  50. package/client/features/home/CreateWorkspaceDialog.tsx +224 -0
  51. package/client/features/home/HomePage.tsx +220 -0
  52. package/client/{components → features/home}/WorkspacePreview.tsx +2 -2
  53. package/client/features/home/api.ts +148 -0
  54. package/client/features/home/workspace-presentation.tsx +44 -0
  55. package/client/features/scratchpad/Scratchpad.tsx +312 -0
  56. package/client/features/scratchpad/ScratchpadControls.tsx +503 -0
  57. package/client/features/scratchpad/useScratchpadSnapshot.tsx +115 -0
  58. package/client/features/settings/EnvironmentSettings.tsx +149 -0
  59. package/client/features/settings/GeneralSettings.tsx +90 -0
  60. package/client/{components → features}/settings/IconPicker.tsx +73 -222
  61. package/client/features/settings/SettingsLayout.tsx +53 -0
  62. package/client/{components → features}/settings/WorkspaceSettings.tsx +12 -16
  63. package/client/features/settings/api.ts +88 -0
  64. package/client/features/settings/icon-picker-options.ts +161 -0
  65. package/client/{hooks → features/settings}/useEnvVars.ts +4 -4
  66. package/client/{components → features/widgets}/HiddenPanel.tsx +3 -3
  67. package/client/{components → features/widgets}/WidgetFrame.tsx +3 -8
  68. package/client/{components → features/widgets}/WidgetGrid.tsx +2 -9
  69. package/client/features/widgets/Widgets.tsx +215 -0
  70. package/client/{lib/grid-pack.ts → features/widgets/grid.ts} +7 -1
  71. package/client/{hooks → features/widgets}/useGridReconcile.ts +1 -1
  72. package/client/{components → features/workspace}/CustomizePanel.tsx +5 -6
  73. package/client/{lib → features/workspace}/WorkspaceLayoutContext.tsx +15 -8
  74. package/client/features/workspace/WorkspaceScreen.tsx +536 -0
  75. package/client/features/workspace/WorkspaceTabs.tsx +205 -0
  76. package/client/features/workspace/api.ts +56 -0
  77. package/client/features/workspace/useFitsSplitLayout.ts +37 -0
  78. package/client/global.d.ts +5 -0
  79. package/client/index.css +6 -10
  80. package/client/index.html +1 -1
  81. package/client/index.tsx +14 -31
  82. package/client/main.tsx +2 -2
  83. package/client/runtime/hmr-watchdog.ts +39 -0
  84. package/client/{hooks/useMeiEvents.ts → runtime/useWorkspaceEvents.ts} +9 -6
  85. package/client/store/ui.ts +5 -1
  86. package/client/theme.css +0 -2
  87. package/dist/chunk-11cab5dq.css +1 -0
  88. package/dist/chunk-23cgr1tz.css +1 -0
  89. package/dist/chunk-3hy3qy6d.js +10 -0
  90. package/dist/chunk-c4j722at.js +546 -0
  91. package/dist/chunk-dyfaffyz.js +119 -0
  92. package/dist/chunk-kpe40hm8.js +1 -0
  93. package/dist/chunk-p68fnz3q.js +2 -0
  94. package/dist/chunk-pcnahct1.js +5 -0
  95. package/dist/chunk-tqd3pkg8.css +1 -0
  96. package/dist/chunk-ty6dvda0.js +1 -0
  97. package/dist/index.html +2 -2
  98. package/lib/types.ts +18 -7
  99. package/lib/workspace-name.ts +14 -0
  100. package/package.json +3 -2
  101. package/server/api.ts +119 -14
  102. package/server/cli.ts +11 -5
  103. package/server/layout.ts +38 -7
  104. package/server/mcp.ts +72 -15
  105. package/server/moi-scaffold.ts +55 -10
  106. package/server/registry.ts +16 -0
  107. package/server/web.ts +1 -0
  108. package/server/workspace-init.ts +5 -19
  109. package/tsconfig.json +1 -1
  110. package/workspace/.claude/skills/moi-workspace/DESIGN.md +1 -1
  111. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +1 -1
  112. package/client/api/workspaces.ts +0 -427
  113. package/client/components/App.tsx +0 -41
  114. package/client/components/ChatPanel.tsx +0 -275
  115. package/client/components/HomePage.tsx +0 -17
  116. package/client/components/McpMenu.tsx +0 -125
  117. package/client/components/Scratchpad.tsx +0 -935
  118. package/client/components/Widgets.tsx +0 -132
  119. package/client/components/WorkspacesPage.tsx +0 -245
  120. package/client/components/layout/SidebarLayout.tsx +0 -258
  121. package/client/components/routes/workspace/[id].tsx +0 -675
  122. package/client/components/routes/workspace/create.tsx +0 -155
  123. package/client/components/settings/SettingsPages.tsx +0 -255
  124. package/client/hooks/useFitsSidebar.ts +0 -34
  125. package/client/lib/connection.ts +0 -238
  126. package/dist/chunk-07qf2tv1.css +0 -1
  127. package/dist/chunk-w18801vn.js +0 -672
  128. /package/client/components/{playground → shared}/LedLogo.tsx +0 -0
  129. /package/client/{lib → features/applets}/applet-cache.ts +0 -0
  130. /package/client/{components → features/chat}/ShimmerText.tsx +0 -0
  131. /package/client/{store/live.ts → features/chat/chat-store.ts} +0 -0
  132. /package/client/{lib → features/chat}/group-turns.ts +0 -0
  133. /package/client/{components → features/chat}/tool-group/CodeBlock.tsx +0 -0
  134. /package/client/{components → features/chat}/tool-group/Collapse.tsx +0 -0
  135. /package/client/{components → features/chat}/tool-group/detect.ts +0 -0
  136. /package/client/{components → features/chat}/tool-group/fixtures.ts +0 -0
  137. /package/client/{components → features/chat}/tool-group/format.ts +0 -0
  138. /package/client/{components → features/chat}/tool-group/index.ts +0 -0
  139. /package/client/{lib → features/chat}/uploads.ts +0 -0
  140. /package/client/{hooks → features/chat}/useStickToBottom.ts +0 -0
  141. /package/client/{components → features/connectors}/IconMcp.tsx +0 -0
  142. /package/client/{lib → features/connectors}/mcp-icons.ts +0 -0
  143. /package/client/{lib → features/scratchpad}/scratch-executor.ts +0 -0
  144. /package/client/{lib → features/settings}/render-icon.ts +0 -0
  145. /package/client/{lib → features/workspace}/WorkspaceContext.tsx +0 -0
  146. /package/client/{hooks → features/workspace}/useWorkspaceTheme.ts +0 -0
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useRef } from 'react'
2
2
 
3
- import { findFreePosition } from '@/client/lib/grid-pack'
3
+ import { findFreePosition } from '@/client/features/widgets/grid'
4
4
  import type { WidgetInfo, WorkspaceLayout } from '@/lib/types'
5
5
 
6
6
  // Rebalances the widget grid as the (server-authoritative) widget set changes.
@@ -1,12 +1,11 @@
1
1
  import { type Ref, useEffect } from 'react'
2
2
 
3
- import { useWorkspaceLayoutCtx } from '@/client/lib/WorkspaceLayoutContext'
3
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
4
+ import { BottomPanel } from '@/client/components/shared/BottomPanel'
4
5
  import { cn } from '@/client/lib/cn'
5
6
  import { COLOR_THEMES, type ColorThemeConfig, FONT_THEMES } from '@/lib/themes'
6
7
  import type { ColorTheme, FontTheme } from '@/lib/types'
7
8
 
8
- import { BottomPanel } from './BottomPanel'
9
-
10
9
  const ALL_FONT_PREVIEW_ID = 'mei-font-previews'
11
10
  const ALL_FONTS_QUERY = Object.values(FONT_THEMES)
12
11
  .map(f => f.googleFontsQuery)
@@ -63,7 +62,7 @@ export function CustomizePanel({ ref }: CustomizePanelProps) {
63
62
  'flex flex-col items-start rounded-md px-3 py-2 text-left transition-colors',
64
63
  key === currentFont
65
64
  ? 'bg-primary/5 ring-2 ring-primary'
66
- : 'border-transparent hover:bg-muted'
65
+ : 'border-transparent hover:bg-accent'
67
66
  )}
68
67
  style={{ fontFamily: config.sans }}
69
68
  >
@@ -91,11 +90,11 @@ export function CustomizePanel({ ref }: CustomizePanelProps) {
91
90
  'flex items-center gap-2 rounded-md border px-3 py-2 transition-colors',
92
91
  active
93
92
  ? 'bg-primary/5 ring-2 ring-primary'
94
- : 'border-transparent hover:bg-muted'
93
+ : 'border-transparent hover:bg-accent'
95
94
  )}
96
95
  >
97
96
  <span
98
- className="size-5 shrink-0 rounded-full border border-black/10"
97
+ className="size-5 shrink-0 rounded-full border border-border"
99
98
  style={{ backgroundColor: preset.background ?? 'oklch(1 0 0)' }}
100
99
  >
101
100
  <span
@@ -5,19 +5,20 @@ import { useQueryClient } from '@tanstack/react-query'
5
5
  import {
6
6
  type WorkspaceLayoutResponse,
7
7
  useSaveLayout,
8
- useWorkspaceLayout,
9
- workspaceKeys
10
- } from '@/client/api/workspaces'
8
+ useWorkspaceLayout
9
+ } from '@/client/features/workspace/api'
10
+ import { workspaceKeys } from '@/client/api/workspace-keys'
11
11
  import type { WorkspaceLayout, WorkspaceType } from '@/lib/types'
12
12
 
13
13
  const DEFAULT_LAYOUT: WorkspaceLayout = {
14
14
  version: 1,
15
15
  widgetGrid: [],
16
- chatMode: 'sidebar'
16
+ layoutMode: 'fullscreen',
17
+ tabs: { open: ['agent'], active: 'agent' }
17
18
  }
18
19
 
19
20
  type WorkspaceLayoutContextValue = {
20
- // The persisted layout (widget grid, chat mode, theme). Falls back to an
21
+ // The persisted layout (widget grid, layout mode, theme). Falls back to an
21
22
  // empty default while the query is still loading.
22
23
  layout: WorkspaceLayout
23
24
  // Merge a partial update into the layout: updates the query cache immediately
@@ -78,13 +79,19 @@ export function WorkspaceLayoutProvider({ id, children }: WorkspaceLayoutProvide
78
79
  const prev = qc.getQueryData<WorkspaceLayoutResponse>(key)
79
80
  if (!prev) return
80
81
  // Optimistic: the grid/theme reflects the change before the PUT lands.
81
- qc.setQueryData<WorkspaceLayoutResponse>(key, { ...prev, ...update })
82
+ const next = { ...prev, ...update }
83
+ qc.setQueryData<WorkspaceLayoutResponse>(key, next)
82
84
 
83
85
  if (timer.current) clearTimeout(timer.current)
86
+ // Persist the value captured at call time, NOT the cache at fire time: a
87
+ // `workspace:updated` broadcast can invalidate + refetch this query inside
88
+ // the debounce window, and reading the cache then would PUT the server's
89
+ // pre-change layout back (reverting the user's edit on disk). Rapid calls
90
+ // still coalesce — each call's `prev` already includes the previous
91
+ // optimistic write.
84
92
  timer.current = setTimeout(() => {
85
93
  timer.current = null
86
- const latest = qc.getQueryData<WorkspaceLayoutResponse>(key)
87
- if (latest) saveRef.current(stripMeta(latest))
94
+ saveRef.current(stripMeta(next))
88
95
  }, 600)
89
96
  },
90
97
  [id, qc]
@@ -0,0 +1,536 @@
1
+ import { lazy, Suspense, useEffect, useRef, useState } from 'react'
2
+
3
+ import { AnimatePresence, motion } from 'motion/react'
4
+
5
+ import {
6
+ IconAppWindow,
7
+ IconArtboard,
8
+ IconLayoutGrid,
9
+ IconLayoutSidebarRight,
10
+ IconPalette,
11
+ IconRobotFace
12
+ } from '@tabler/icons-react'
13
+ import { ChatPanel } from '@/client/features/chat/ChatPanel'
14
+ import { ChatPopup } from '@/client/features/chat/ChatPopup'
15
+ import { CustomizePanel } from '@/client/features/workspace/CustomizePanel'
16
+ import { McpMenu } from '@/client/features/connectors/McpMenu'
17
+ import { WidgetErrorBoundary } from '@/client/features/applets/WidgetErrorBoundary'
18
+ import { Widgets } from '@/client/features/widgets/Widgets'
19
+ import { PanelHeader } from '@/client/components/shared/PanelHeader'
20
+ import { workspaceProviderIcon } from '@/client/features/home/workspace-presentation'
21
+ import { Button } from '@/client/components/ui/button'
22
+ import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
23
+ import { WorkspaceSettings } from '@/client/features/settings/WorkspaceSettings'
24
+ import { useChat } from '@/client/features/chat/useChat'
25
+ import { useView } from '@/client/features/applets/useApplet'
26
+ import { useFitsSplitLayout } from '@/client/features/workspace/useFitsSplitLayout'
27
+ import { useWorkspaceTheme } from '@/client/features/workspace/useWorkspaceTheme'
28
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
29
+ import { cn } from '@/client/lib/cn'
30
+ import { liveStore } from '@/client/features/chat/chat-store'
31
+ import {
32
+ type CreateWorkspaceTabItem,
33
+ type WorkspaceTabItem,
34
+ WorkspaceTabs
35
+ } from '@/client/features/workspace/WorkspaceTabs'
36
+ import type {
37
+ LayoutMode,
38
+ ViewInfo,
39
+ WidgetInfo,
40
+ WorkspaceTabId,
41
+ WorkspaceTabsState
42
+ } from '@/lib/types'
43
+
44
+ const Scratchpad = lazy(() =>
45
+ import('@/client/features/scratchpad/Scratchpad').then(module => ({
46
+ default: module.Scratchpad
47
+ }))
48
+ )
49
+
50
+ // Tab label for a view: its configured title, or the file-name id as fallback.
51
+ const viewLabel = (v: ViewInfo) => v.config.title || v.id
52
+
53
+ const DEFAULT_TABS: WorkspaceTabsState = { open: ['agent'], active: 'agent' }
54
+
55
+ const viewTabId = (id: string): WorkspaceTabId => `view:${id}`
56
+ const viewIdFromTab = (tab: WorkspaceTabId) => (tab.startsWith('view:') ? tab.slice(5) : null)
57
+
58
+ type SectionControlsProps = {
59
+ mode: LayoutMode
60
+ onToggleMode: () => void
61
+ }
62
+
63
+ // Temporary layout switch: fullscreen tabbed workspace ⇄ legacy split view.
64
+ function SectionControls({ mode, onToggleMode }: SectionControlsProps) {
65
+ const fullscreen = mode === 'fullscreen'
66
+ return (
67
+ <Button
68
+ variant="ghost"
69
+ size="icon-sm"
70
+ onClick={onToggleMode}
71
+ aria-label={fullscreen ? 'Switch to split view' : 'Switch to full-screen view'}
72
+ >
73
+ <IconLayoutSidebarRight stroke={1.75} />
74
+ </Button>
75
+ )
76
+ }
77
+
78
+ type ViewAppProps = {
79
+ view: ViewInfo
80
+ }
81
+
82
+ // A view — an agent-defined app — mounted full-area. The bundle owns its own
83
+ // layout + scroll, so we give it a plain filled box and fade it in (mirroring
84
+ // WidgetShell, but full-area instead of a grid cell).
85
+ function ViewApp({ view }: ViewAppProps) {
86
+ const bundle = useView(view.id)
87
+
88
+ return (
89
+ <div className="relative min-h-0 flex-1 overflow-hidden">
90
+ <AnimatePresence mode="wait" initial={false}>
91
+ {bundle.status === 'ready' && (
92
+ <motion.div
93
+ key={bundle.version}
94
+ className="absolute inset-0 overflow-auto"
95
+ initial={{ opacity: 0, filter: 'blur(4px)' }}
96
+ animate={{ opacity: 1, filter: 'blur(0px)' }}
97
+ exit={{ opacity: 0, filter: 'blur(4px)' }}
98
+ transition={{ duration: 0.3, ease: 'easeInOut' }}
99
+ >
100
+ <WidgetErrorBoundary name={view.id} resetKey={bundle.version}>
101
+ <bundle.Component />
102
+ </WidgetErrorBoundary>
103
+ </motion.div>
104
+ )}
105
+ {bundle.status === 'error' && (
106
+ <motion.p
107
+ key={`err-${bundle.version}`}
108
+ className="absolute inset-0 p-4 text-xs text-destructive"
109
+ initial={{ opacity: 0 }}
110
+ animate={{ opacity: 1 }}
111
+ exit={{ opacity: 0 }}
112
+ transition={{ duration: 0.3, ease: 'easeInOut' }}
113
+ >
114
+ {bundle.error}
115
+ </motion.p>
116
+ )}
117
+ </AnimatePresence>
118
+ </div>
119
+ )
120
+ }
121
+
122
+ type WorkspaceCustomizeActionProps = {
123
+ active: boolean
124
+ onToggle: () => void
125
+ }
126
+
127
+ function WorkspaceCustomizeAction({ active, onToggle }: WorkspaceCustomizeActionProps) {
128
+ return (
129
+ <Tooltip delay={50}>
130
+ <TooltipTrigger
131
+ render={
132
+ <Button
133
+ variant={active ? 'secondary' : 'ghost'}
134
+ size="icon-sm"
135
+ aria-label="Customize"
136
+ aria-pressed={active}
137
+ onClick={onToggle}
138
+ >
139
+ <IconPalette stroke={1.75} />
140
+ </Button>
141
+ }
142
+ />
143
+ <TooltipContent>Customize</TooltipContent>
144
+ </Tooltip>
145
+ )
146
+ }
147
+
148
+ type WorkspaceScreenProps = {
149
+ widgets: WidgetInfo[]
150
+ views: ViewInfo[]
151
+ }
152
+
153
+ type WidgetMode = 'idle' | 'editing' | 'customizing'
154
+
155
+ function normalizeTabsState(tabs: WorkspaceTabsState | undefined): WorkspaceTabsState {
156
+ if (!tabs || !Array.isArray(tabs.open)) return DEFAULT_TABS
157
+ const open = tabs.open.filter((tab, index, all) => all.indexOf(tab) === index)
158
+ if (open.length === 0) return DEFAULT_TABS
159
+ return { open, active: open.includes(tabs.active) ? tabs.active : open[0] }
160
+ }
161
+
162
+ function tabAvailable(tab: WorkspaceTabId, views: ViewInfo[]) {
163
+ if (tab === 'agent' || tab === 'widgets' || tab === 'scratchpad') return true
164
+ const viewId = viewIdFromTab(tab)
165
+ return viewId ? views.some(v => v.id === viewId) : false
166
+ }
167
+
168
+ function tabItemFor(
169
+ tab: WorkspaceTabId,
170
+ views: ViewInfo[],
171
+ closable: boolean
172
+ ): WorkspaceTabItem | null {
173
+ if (tab === 'agent') {
174
+ return {
175
+ key: tab,
176
+ Icon: IconRobotFace,
177
+ label: 'Agent',
178
+ closable
179
+ }
180
+ }
181
+ if (tab === 'widgets') {
182
+ return {
183
+ key: tab,
184
+ Icon: IconLayoutGrid,
185
+ label: 'Widgets',
186
+ closable
187
+ }
188
+ }
189
+ if (tab === 'scratchpad') {
190
+ return {
191
+ key: tab,
192
+ Icon: IconArtboard,
193
+ label: 'Scratchpad',
194
+ closable
195
+ }
196
+ }
197
+ const viewId = viewIdFromTab(tab)
198
+ const view = viewId ? views.find(v => v.id === viewId) : null
199
+ return view
200
+ ? {
201
+ key: tab,
202
+ Icon: IconAppWindow,
203
+ label: viewLabel(view),
204
+ closable
205
+ }
206
+ : null
207
+ }
208
+
209
+ function applyVisibleTabOrder(
210
+ open: WorkspaceTabId[],
211
+ visible: WorkspaceTabId[],
212
+ orderedVisible: WorkspaceTabId[]
213
+ ) {
214
+ const visibleSet = new Set(visible)
215
+ let cursor = 0
216
+ return open.map(tab => (visibleSet.has(tab) ? orderedVisible[cursor++] : tab))
217
+ }
218
+
219
+ export function WorkspaceScreen({ widgets, views }: WorkspaceScreenProps) {
220
+ const {
221
+ view,
222
+ previewTurn,
223
+ sessionId,
224
+ processing,
225
+ error,
226
+ send,
227
+ stop,
228
+ switchThread,
229
+ dismissError
230
+ } = useChat()
231
+ const { layout, setLayout, name, icon, provider, workspaceId } = useWorkspaceLayoutCtx()
232
+ const { ref: rowRef, fits: canUseSplit } = useFitsSplitLayout<HTMLDivElement>()
233
+ const [widgetMode, setWidgetMode] = useState<WidgetMode>('idle')
234
+ const [floatingChatOpen, setFloatingChatOpen] = useState(false)
235
+ const [chatFocusRequest, setChatFocusRequest] = useState(0)
236
+
237
+ // Theme is scoped to this wrapper, not :root — the sidebar keeps the default
238
+ // tokens. The floating chat portals into the same element so it inherits them.
239
+ const themeRef = useRef<HTMLDivElement>(null)
240
+ useWorkspaceTheme(layout.theme, themeRef)
241
+
242
+ const tabsState = normalizeTabsState(layout.tabs)
243
+ const availableOpenTabs = tabsState.open.filter(tab => tabAvailable(tab, views))
244
+ const effectiveOpenTabs = availableOpenTabs.length > 0 ? availableOpenTabs : DEFAULT_TABS.open
245
+ const openSet = new Set(tabsState.open)
246
+ const nonAgentOpenTabs = effectiveOpenTabs.filter(tab => tab !== 'agent')
247
+ const hasWorkspaceContent = nonAgentOpenTabs.length > 0
248
+
249
+ // Effective layout mode. Split is only visible with workspace content and
250
+ // enough row width; the saved mode remains the user's intent.
251
+ const wantsSplit = layout.layoutMode === 'split' && hasWorkspaceContent
252
+ const mode: LayoutMode = wantsSplit && canUseSplit ? 'split' : 'fullscreen'
253
+ const dockedSplit = mode === 'split'
254
+
255
+ const setMode = (m: LayoutMode) => {
256
+ if (m === 'split' && tabsState.active === 'agent') {
257
+ setLayout({
258
+ layoutMode: m,
259
+ tabs: {
260
+ open: tabsState.open,
261
+ active: nonAgentOpenTabs[0] ?? tabsState.active
262
+ }
263
+ })
264
+ return
265
+ }
266
+ setLayout({ layoutMode: m })
267
+ }
268
+
269
+ const visibleTabIds = dockedSplit ? nonAgentOpenTabs : effectiveOpenTabs
270
+ const activeTab: WorkspaceTabId = visibleTabIds.includes(tabsState.active)
271
+ ? tabsState.active
272
+ : (visibleTabIds[0] ?? 'agent')
273
+ const canCloseTabs = effectiveOpenTabs.length > 1
274
+ const tabItems = visibleTabIds
275
+ .map(tab => tabItemFor(tab, views, canCloseTabs))
276
+ .filter((tab): tab is WorkspaceTabItem => Boolean(tab))
277
+ const activeViewId = viewIdFromTab(activeTab)
278
+ const activeView = activeViewId ? views.find(v => v.id === activeViewId) : undefined
279
+
280
+ useEffect(() => {
281
+ if (mode !== 'fullscreen' || activeTab === 'agent') {
282
+ setFloatingChatOpen(false)
283
+ }
284
+ }, [activeTab, mode])
285
+
286
+ const setTabs = (tabs: WorkspaceTabsState) => setLayout({ tabs })
287
+
288
+ const openTab = (tab: WorkspaceTabId) => {
289
+ const open = openSet.has(tab) ? tabsState.open : [...tabsState.open, tab]
290
+ setTabs({ open, active: tab })
291
+ if (tab === 'agent') {
292
+ setFloatingChatOpen(false)
293
+ setChatFocusRequest(request => request + 1)
294
+ }
295
+ }
296
+
297
+ const closeTab = (tab: WorkspaceTabId) => {
298
+ if (!canCloseTabs || !openSet.has(tab)) return
299
+ const open = tabsState.open.filter(t => t !== tab)
300
+ let active = tabsState.active
301
+ if (active === tab || !open.includes(active)) {
302
+ const visibleIndex = visibleTabIds.indexOf(tab)
303
+ active =
304
+ visibleTabIds[visibleIndex + 1] ??
305
+ visibleTabIds[visibleIndex - 1] ??
306
+ open.find(t => tabAvailable(t, views)) ??
307
+ 'agent'
308
+ }
309
+ setTabs({ open, active })
310
+ }
311
+
312
+ const reorderTabs = (orderedVisibleTabs: WorkspaceTabId[]) => {
313
+ const open = applyVisibleTabOrder(tabsState.open, visibleTabIds, orderedVisibleTabs)
314
+ if (open === tabsState.open) return
315
+ setTabs({ open, active: tabsState.active })
316
+ }
317
+
318
+ const openChat = (intent?: string) => {
319
+ if (intent !== undefined) {
320
+ liveStore.getState().setDraft(workspaceId, sessionId, intent)
321
+ }
322
+ if (mode === 'fullscreen' && activeTab !== 'agent') {
323
+ setFloatingChatOpen(true)
324
+ if (floatingChatOpen) {
325
+ setChatFocusRequest(request => request + 1)
326
+ }
327
+ return
328
+ }
329
+ setChatFocusRequest(request => request + 1)
330
+ }
331
+
332
+ const createItems: CreateWorkspaceTabItem[] = [
333
+ ...(!dockedSplit && !openSet.has('agent')
334
+ ? ([
335
+ {
336
+ key: 'agent',
337
+ Icon: IconRobotFace,
338
+ label: 'Agent',
339
+ onClick: () => openTab('agent')
340
+ }
341
+ ] satisfies CreateWorkspaceTabItem[])
342
+ : []),
343
+ ...(!openSet.has('widgets')
344
+ ? ([
345
+ {
346
+ key: 'widgets',
347
+ Icon: IconLayoutGrid,
348
+ label: 'Widgets',
349
+ onClick: () => openTab('widgets')
350
+ }
351
+ ] satisfies CreateWorkspaceTabItem[])
352
+ : []),
353
+ ...(!openSet.has('scratchpad')
354
+ ? ([
355
+ {
356
+ key: 'scratchpad',
357
+ Icon: IconArtboard,
358
+ label: 'Scratchpad',
359
+ onClick: () => openTab('scratchpad')
360
+ }
361
+ ] satisfies CreateWorkspaceTabItem[])
362
+ : []),
363
+ ...views
364
+ .map(v => ({ view: v, tab: viewTabId(v.id) }))
365
+ .filter(({ tab }) => !openSet.has(tab))
366
+ .map(
367
+ ({ view, tab }): CreateWorkspaceTabItem => ({
368
+ key: tab,
369
+ Icon: IconAppWindow,
370
+ label: viewLabel(view),
371
+ onClick: () => openTab(tab)
372
+ })
373
+ ),
374
+ {
375
+ key: 'create-view',
376
+ Icon: IconAppWindow,
377
+ label: 'View',
378
+ onClick: () => openChat('Create view')
379
+ }
380
+ ]
381
+
382
+ // The docked split chat. Full-screen Agent uses the tabbed chat below.
383
+ const dockedChat = (
384
+ <ChatPanel
385
+ active={mode === 'split'}
386
+ focusRequest={chatFocusRequest}
387
+ view={view}
388
+ previewTurn={previewTurn}
389
+ sessionId={sessionId}
390
+ processing={processing}
391
+ error={error}
392
+ onDismissError={dismissError}
393
+ send={send}
394
+ stop={stop}
395
+ onSwitchThread={switchThread}
396
+ />
397
+ )
398
+
399
+ const tabbedChat = (
400
+ <ChatPanel
401
+ active={mode === 'fullscreen' && activeTab === 'agent'}
402
+ focusRequest={chatFocusRequest}
403
+ view={view}
404
+ previewTurn={previewTurn}
405
+ sessionId={sessionId}
406
+ processing={processing}
407
+ error={error}
408
+ onDismissError={dismissError}
409
+ send={send}
410
+ stop={stop}
411
+ onSwitchThread={switchThread}
412
+ />
413
+ )
414
+
415
+ return (
416
+ // Themed wrapper: scoped CSS vars (bg/fg/font) live here so the panel — and
417
+ // the portaled floating chat — pick up the workspace theme, while the
418
+ // sidebar outside stays default.
419
+ <div
420
+ ref={themeRef}
421
+ className="relative flex h-full min-h-0 flex-col bg-background font-sans text-foreground"
422
+ >
423
+ <div ref={rowRef} className="flex min-h-0 flex-1">
424
+ {/* Full-screen: whole panel. Split: the left content column. */}
425
+ {(mode === 'fullscreen' || hasWorkspaceContent) && (
426
+ <div
427
+ className={cn(
428
+ 'flex min-h-0 flex-1 flex-col',
429
+ mode === 'split' && 'min-w-[var(--column-w)]'
430
+ )}
431
+ >
432
+ <PanelHeader>
433
+ <div className="flex min-w-0 flex-1 items-center gap-4">
434
+ <div className="flex items-center gap-2">
435
+ <img
436
+ src={icon ?? workspaceProviderIcon[provider ?? 'claude-code']}
437
+ alt=""
438
+ className="size-5 shrink-0 rounded-[4px]"
439
+ />
440
+ {name && (
441
+ <span className="truncate text-sm font-medium text-foreground">{name}</span>
442
+ )}
443
+ </div>
444
+ <WorkspaceTabs
445
+ tabs={tabItems}
446
+ active={activeTab}
447
+ createItems={createItems}
448
+ onSelect={openTab}
449
+ onClose={closeTab}
450
+ onReorder={reorderTabs}
451
+ />
452
+ </div>
453
+ <div className="flex shrink-0 items-center gap-1">
454
+ <WorkspaceCustomizeAction
455
+ active={widgetMode === 'customizing'}
456
+ onToggle={() =>
457
+ setWidgetMode(widgetMode === 'customizing' ? 'idle' : 'customizing')
458
+ }
459
+ />
460
+ <McpMenu />
461
+ <WorkspaceSettings />
462
+ {hasWorkspaceContent && canUseSplit && (
463
+ <SectionControls
464
+ mode={mode}
465
+ onToggleMode={() => setMode(mode === 'fullscreen' ? 'split' : 'fullscreen')}
466
+ />
467
+ )}
468
+ </div>
469
+ </PanelHeader>
470
+
471
+ {activeTab === 'agent' ? (
472
+ tabbedChat
473
+ ) : activeTab === 'widgets' ? (
474
+ <Widgets
475
+ editing={widgetMode === 'editing'}
476
+ onEditingChange={editing => setWidgetMode(editing ? 'editing' : 'idle')}
477
+ widgets={widgets}
478
+ onCreateWidget={() => openChat('Create widget')}
479
+ />
480
+ ) : activeTab === 'scratchpad' ? (
481
+ <Suspense fallback={null}>
482
+ <Scratchpad />
483
+ </Suspense>
484
+ ) : activeView ? (
485
+ <ViewApp view={activeView} />
486
+ ) : null}
487
+ </div>
488
+ )}
489
+
490
+ {/* Split: Agent chat as a bounded right column. Full-screen mode uses the
491
+ Agent tab instead. */}
492
+ {mode === 'split' && (
493
+ <div
494
+ className={cn(
495
+ 'flex min-h-0 min-w-[var(--chat-min)] flex-[0_1_var(--chat-max)] flex-col overflow-hidden border-l border-border'
496
+ )}
497
+ >
498
+ {dockedChat}
499
+ </div>
500
+ )}
501
+ </div>
502
+
503
+ <AnimatePresence>{widgetMode === 'customizing' && <CustomizePanel />}</AnimatePresence>
504
+
505
+ {mode === 'fullscreen' && activeTab !== 'agent' && hasWorkspaceContent && (
506
+ <ChatPopup
507
+ open={floatingChatOpen}
508
+ onOpenChange={setFloatingChatOpen}
509
+ onOpenChangeComplete={open => {
510
+ if (open) {
511
+ setChatFocusRequest(request => request + 1)
512
+ }
513
+ }}
514
+ container={themeRef}
515
+ >
516
+ {onClose => (
517
+ <ChatPanel
518
+ active={floatingChatOpen}
519
+ focusRequest={chatFocusRequest}
520
+ view={view}
521
+ previewTurn={previewTurn}
522
+ sessionId={sessionId}
523
+ processing={processing}
524
+ error={error}
525
+ onDismissError={dismissError}
526
+ send={send}
527
+ stop={stop}
528
+ onSwitchThread={switchThread}
529
+ onClose={onClose}
530
+ />
531
+ )}
532
+ </ChatPopup>
533
+ )}
534
+ </div>
535
+ )
536
+ }