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,265 @@
1
+ import { useCallback, useState } from 'react'
2
+
3
+ import { AnimatePresence, LayoutGroup, motion } from 'motion/react'
4
+
5
+ import { IconPlus } from '@tabler/icons-react'
6
+
7
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
8
+ import { findFreePosition } from '@/client/features/widgets/grid'
9
+ import type { GridItem } from '@/client/features/widgets/grid'
10
+ import { WidgetShell } from '@/client/features/applets/WidgetShell'
11
+ import { Button } from '@/client/components/ui/button'
12
+ import { Skeleton } from '@/client/components/ui/skeleton'
13
+ import { cn } from '@/client/lib/cn'
14
+ import type { WidgetInfo } from '@/lib/types'
15
+
16
+ import { HiddenPanel } from './HiddenPanel'
17
+ import { WidgetGrid, WidgetGridLayout } from './WidgetGrid'
18
+
19
+ function renderItem(id: string) {
20
+ return <WidgetShell name={id} />
21
+ }
22
+
23
+ const EMPTY_WIDGET_ITEMS: GridItem[] = Array.from({ length: 10 }, (_, index) => ({
24
+ id: `empty-widget-${index}`,
25
+ w: 2,
26
+ h: 1
27
+ }))
28
+
29
+ function renderEmptyWidget() {
30
+ return (
31
+ <Skeleton className="size-full animate-none rounded-2xl [corner-shape:superellipse(1.2)]" />
32
+ )
33
+ }
34
+
35
+ type NoWidgetsCreatedProps = {
36
+ onCreateWidget: () => void
37
+ }
38
+
39
+ function NoWidgetsCreated({ onCreateWidget }: NoWidgetsCreatedProps) {
40
+ return (
41
+ <div className="relative min-h-0 flex-1 pt-7">
42
+ <div aria-hidden="true">
43
+ <WidgetGridLayout items={EMPTY_WIDGET_ITEMS} renderItem={renderEmptyWidget} />
44
+ </div>
45
+
46
+ <div className="absolute inset-0 z-1 flex items-center justify-center p-6">
47
+ <div className="flex h-full w-full max-w-(--column-w) flex-col items-center justify-center gap-4 bg-radial from-background from-50% to-transparent to-75% text-center">
48
+ <div className="flex flex-col gap-1.5">
49
+ <h2 className="font-medium">A little empty here</h2>
50
+ <p className="mx-auto max-w-sm text-sm text-muted-foreground">
51
+ Widgets are small apps that can read data, perform tasks, and show a compact view of
52
+ the information that matters.
53
+ </p>
54
+ </div>
55
+ <Button type="button" variant="secondary" size="sm" onClick={onCreateWidget}>
56
+ <IconPlus data-icon="inline-start" stroke={1.5} />
57
+ Create widget
58
+ </Button>
59
+ </div>
60
+ </div>
61
+ </div>
62
+ )
63
+ }
64
+
65
+ type WidgetActionsProps = {
66
+ editing: boolean
67
+ onCreateWidget: () => void
68
+ onEditingChange: (editing: boolean) => void
69
+ }
70
+
71
+ function WidgetActions({ editing, onCreateWidget, onEditingChange }: WidgetActionsProps) {
72
+ return (
73
+ <div className="mx-auto mb-4 flex w-full max-w-(--column-w) shrink-0 items-center justify-end gap-2">
74
+ {editing && (
75
+ <Button
76
+ type="button"
77
+ variant="ghost"
78
+ size="sm"
79
+ className="mr-auto"
80
+ onClick={onCreateWidget}
81
+ >
82
+ <IconPlus data-icon="inline-start" stroke={1.75} />
83
+ New widget
84
+ </Button>
85
+ )}
86
+ <AnimatePresence mode="popLayout" initial={false}>
87
+ {editing ? (
88
+ <motion.div
89
+ key="done"
90
+ variants={{
91
+ from: { opacity: 0, scale: 0.8, filter: 'blur(4px)' },
92
+ to: { opacity: 1, scale: 1, filter: 'blur(0px)' }
93
+ }}
94
+ initial="from"
95
+ animate="to"
96
+ exit="from"
97
+ transition={{ type: 'spring', duration: 0.3, bounce: 0 }}
98
+ >
99
+ <Button type="button" size="sm" onClick={() => onEditingChange(false)}>
100
+ Done
101
+ </Button>
102
+ </motion.div>
103
+ ) : (
104
+ <motion.div
105
+ key="actions"
106
+ className="flex items-center gap-1"
107
+ variants={{
108
+ from: { opacity: 0, scale: 0.8, filter: 'blur(4px)' },
109
+ to: { opacity: 1, scale: 1, filter: 'blur(0px)' }
110
+ }}
111
+ initial="from"
112
+ animate="to"
113
+ exit="from"
114
+ transition={{ type: 'spring', duration: 0.3, bounce: 0 }}
115
+ >
116
+ <Button
117
+ type="button"
118
+ variant="ghost"
119
+ size="sm"
120
+ className="text-muted-foreground group-hover/widgets:opacity-100 [@media(hover:hover)]:opacity-0"
121
+ onClick={() => onEditingChange(true)}
122
+ >
123
+ Edit widgets
124
+ </Button>
125
+ </motion.div>
126
+ )}
127
+ </AnimatePresence>
128
+ </div>
129
+ )
130
+ }
131
+
132
+ function NoWidgetsAdded() {
133
+ return (
134
+ <div className="flex min-h-0 flex-1 flex-col items-center justify-center gap-3">
135
+ <p className="text-sm text-muted-foreground">No widgets added yet</p>
136
+ </div>
137
+ )
138
+ }
139
+
140
+ // Tracks the rendered (border-box) height of whichever bottom panel is open, so
141
+ // the grid can reserve matching space below it and every card stays reachable.
142
+ function usePanelHeight() {
143
+ const [height, setHeight] = useState(0)
144
+ const ref = useCallback((node: HTMLDivElement | null) => {
145
+ if (!node) return
146
+ const ro = new ResizeObserver(([entry]) => {
147
+ const box = entry.borderBoxSize?.[0]
148
+ setHeight(box ? box.blockSize : entry.contentRect.height)
149
+ })
150
+ ro.observe(node)
151
+ return () => ro.disconnect()
152
+ }, [])
153
+ return [ref, height] as const
154
+ }
155
+
156
+ type WidgetsProps = {
157
+ onCreateWidget: () => void
158
+ editing: boolean
159
+ onEditingChange: (editing: boolean) => void
160
+ // Authoritative widget set from the widgets query; positions come from layout.
161
+ widgets: WidgetInfo[]
162
+ }
163
+
164
+ export function Widgets({ onCreateWidget, editing, onEditingChange, widgets }: WidgetsProps) {
165
+ const { layout, setLayout } = useWorkspaceLayoutCtx()
166
+ const hasWidgets = widgets.length > 0
167
+
168
+ const gridIds = new Set(layout.widgetGrid.map(g => g.i))
169
+
170
+ const visibleItems: GridItem[] = layout.widgetGrid
171
+ .filter(g => widgets.some(w => w.id === g.i))
172
+ .map(g => {
173
+ const widget = widgets.find(w => w.id === g.i)!
174
+ return { id: g.i, w: widget.config.colSpan, h: widget.config.rowSpan, x: g.x, y: g.y }
175
+ })
176
+
177
+ const hiddenItems: GridItem[] = widgets
178
+ .filter(w => !gridIds.has(w.id))
179
+ .map(w => ({ id: w.id, w: w.config.colSpan, h: w.config.rowSpan }))
180
+
181
+ const [panelRef, panelHeight] = usePanelHeight()
182
+ const panelOpen = editing && hiddenItems.length > 0
183
+
184
+ function hide(id: string) {
185
+ setLayout({ widgetGrid: layout.widgetGrid.filter(g => g.i !== id) })
186
+ }
187
+
188
+ function restore(id: string) {
189
+ const widget = widgets.find(w => w.id === id)
190
+ if (!widget) return
191
+ const gridWithSizes = layout.widgetGrid.map(g => {
192
+ const w = widgets.find(w => w.id === g.i)
193
+ return { ...g, w: w?.config.colSpan ?? 1, h: w?.config.rowSpan ?? 1 }
194
+ })
195
+ const pos = findFreePosition(gridWithSizes, widget.config.colSpan, widget.config.rowSpan, 4)
196
+ setLayout({ widgetGrid: [...layout.widgetGrid, { i: id, x: pos.x, y: pos.y }] })
197
+ }
198
+
199
+ return (
200
+ // Shared working area below the header and positioning context for the
201
+ // bottom panel. Created-widget states scroll; the initial empty state clips
202
+ // its fixed-height skeleton grid.
203
+ <div className="group/widgets relative min-h-0 flex-1">
204
+ <LayoutGroup>
205
+ <div
206
+ className={cn(
207
+ 'relative flex h-full flex-col p-4',
208
+ hasWidgets ? 'overflow-y-auto' : 'overflow-hidden'
209
+ )}
210
+ >
211
+ {hasWidgets ? (
212
+ <>
213
+ <WidgetActions
214
+ editing={editing}
215
+ onCreateWidget={onCreateWidget}
216
+ onEditingChange={onEditingChange}
217
+ />
218
+ {visibleItems.length === 0 ? (
219
+ <motion.div
220
+ className="mx-auto flex min-h-0 w-full max-w-[var(--column-w)] flex-1 flex-col"
221
+ animate={{ paddingBottom: panelOpen ? panelHeight : 0 }}
222
+ transition={{ type: 'spring', duration: 0.3, bounce: 0 }}
223
+ >
224
+ <NoWidgetsAdded />
225
+ </motion.div>
226
+ ) : (
227
+ // The open panel's height is reserved below the grid so every card
228
+ // can scroll clear of the panel.
229
+ <motion.div
230
+ animate={{ marginBottom: panelOpen ? panelHeight : 0 }}
231
+ transition={{ type: 'spring', duration: 0.3, bounce: 0 }}
232
+ >
233
+ <WidgetGrid
234
+ items={visibleItems}
235
+ editing={editing}
236
+ renderItem={renderItem}
237
+ onRemove={hide}
238
+ onLayoutChange={items =>
239
+ setLayout({
240
+ widgetGrid: items.map(i => ({ i: i.id, x: i.x ?? 0, y: i.y ?? 0 }))
241
+ })
242
+ }
243
+ />
244
+ </motion.div>
245
+ )}
246
+ </>
247
+ ) : (
248
+ <NoWidgetsCreated onCreateWidget={onCreateWidget} />
249
+ )}
250
+ </div>
251
+
252
+ <AnimatePresence>
253
+ {hasWidgets && editing && hiddenItems.length > 0 && (
254
+ <HiddenPanel
255
+ ref={panelRef}
256
+ items={hiddenItems}
257
+ renderItem={renderItem}
258
+ onRestore={restore}
259
+ />
260
+ )}
261
+ </AnimatePresence>
262
+ </LayoutGroup>
263
+ </div>
264
+ )
265
+ }
@@ -1,6 +1,12 @@
1
1
  import type { LayoutItem } from 'react-grid-layout'
2
2
 
3
- import type { GridItem } from '@/client/components/WidgetGrid'
3
+ export type GridItem = {
4
+ id: string
5
+ w: number
6
+ h: number
7
+ x?: number
8
+ y?: number
9
+ }
4
10
 
5
11
  export function findFreePosition(
6
12
  existing: LayoutItem[],
@@ -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,14 @@ 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
-
13
- const DEFAULT_LAYOUT: WorkspaceLayout = {
14
- version: 1,
15
- widgetGrid: [],
16
- chatMode: 'sidebar'
17
- }
12
+ import { createDefaultWorkspaceLayout } from '@/lib/workspace-layout'
18
13
 
19
14
  type WorkspaceLayoutContextValue = {
20
- // The persisted layout (widget grid, chat mode, theme). Falls back to an
15
+ // The persisted layout (widget grid, layout mode, theme). Falls back to an
21
16
  // empty default while the query is still loading.
22
17
  layout: WorkspaceLayout
23
18
  // Merge a partial update into the layout: updates the query cache immediately
@@ -28,7 +23,7 @@ type WorkspaceLayoutContextValue = {
28
23
  // Custom workspace icon (base64 data URL), or null to use the provider icon.
29
24
  icon: string | null
30
25
  cwd: string | null
31
- // The agent backend (claude-code / openclaw / hermes …). Exposed here so
26
+ // The agent backend (claude-code / openclaw …). Exposed here so
32
27
  // components like McpMenu read it from the shared layout query instead of
33
28
  // spawning their own observer (a second observer that remounts would trigger
34
29
  // `refetchOnMount` and clobber an in-flight optimistic layout update).
@@ -78,13 +73,19 @@ export function WorkspaceLayoutProvider({ id, children }: WorkspaceLayoutProvide
78
73
  const prev = qc.getQueryData<WorkspaceLayoutResponse>(key)
79
74
  if (!prev) return
80
75
  // Optimistic: the grid/theme reflects the change before the PUT lands.
81
- qc.setQueryData<WorkspaceLayoutResponse>(key, { ...prev, ...update })
76
+ const next = { ...prev, ...update }
77
+ qc.setQueryData<WorkspaceLayoutResponse>(key, next)
82
78
 
83
79
  if (timer.current) clearTimeout(timer.current)
80
+ // Persist the value captured at call time, NOT the cache at fire time: a
81
+ // `workspace:updated` broadcast can invalidate + refetch this query inside
82
+ // the debounce window, and reading the cache then would PUT the server's
83
+ // pre-change layout back (reverting the user's edit on disk). Rapid calls
84
+ // still coalesce — each call's `prev` already includes the previous
85
+ // optimistic write.
84
86
  timer.current = setTimeout(() => {
85
87
  timer.current = null
86
- const latest = qc.getQueryData<WorkspaceLayoutResponse>(key)
87
- if (latest) saveRef.current(stripMeta(latest))
88
+ saveRef.current(stripMeta(next))
88
89
  }, 600)
89
90
  },
90
91
  [id, qc]
@@ -96,7 +97,7 @@ export function WorkspaceLayoutProvider({ id, children }: WorkspaceLayoutProvide
96
97
  // is already stable; the rest derive from `query.data`.
97
98
  const value = useMemo<WorkspaceLayoutContextValue>(
98
99
  () => ({
99
- layout: query.data ? stripMeta(query.data) : DEFAULT_LAYOUT,
100
+ layout: query.data ? stripMeta(query.data) : createDefaultWorkspaceLayout(),
100
101
  setLayout,
101
102
  name: query.data?.name ?? null,
102
103
  icon: query.data?.icon ?? null,