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,427 +0,0 @@
1
- import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
2
-
3
- import { applyEvents } from '@/lib/format'
4
- import type {
5
- DiscoveredWorkspace,
6
- McpServer,
7
- SessionInfo,
8
- StreamEvent,
9
- ThreadConfig,
10
- ViewInfo,
11
- ViewState,
12
- WidgetInfo,
13
- WorkspaceEntry,
14
- WorkspaceEnvView,
15
- WorkspaceLayout,
16
- WorkspaceModels,
17
- WorkspacePreview,
18
- WorkspaceType
19
- } from '@/lib/types'
20
-
21
- // `/api/workspaces/:id` payload: the persisted layout plus server-resolved
22
- // metadata merged in by the route — `name` (settings override or folder name),
23
- // `cwd` (workspace folder), `provider` (agent backend), and `agentId`.
24
- export type WorkspaceLayoutResponse = WorkspaceLayout & {
25
- cwd: string
26
- name: string
27
- provider?: WorkspaceType
28
- agentId?: string
29
- }
30
-
31
- // Central query-key registry for the workspaces domain. Both the `/` view and
32
- // the sidebar read from these keys, so the cache is shared.
33
- export const workspaceKeys = {
34
- all: ['workspaces'] as const,
35
- discover: ['workspaces', 'discover'] as const,
36
- createInfo: ['workspaces', 'create-info'] as const,
37
- preview: (id: string) => ['workspaces', 'preview', id] as const,
38
- layout: (id: string) => ['workspaces', 'layout', id] as const,
39
- widgets: (id: string) => ['workspaces', 'widgets', id] as const,
40
- views: (id: string) => ['workspaces', 'views', id] as const,
41
- sessions: (id: string) => ['workspaces', 'sessions', id] as const,
42
- // Materialized transcript (ViewState) for one thread. The connection manager
43
- // patches this cache with live WS deltas; the `['workspaces','events']`
44
- // prefix lets it invalidate every thread on reconnect.
45
- events: (id: string, sessionId: string) => ['workspaces', 'events', id, sessionId] as const,
46
- threadConfig: (id: string, sessionId: string) =>
47
- ['workspaces', 'threadConfig', id, sessionId] as const,
48
- mcp: (id: string) => ['workspaces', 'mcp', id] as const,
49
- models: (id: string) => ['workspaces', 'models', id] as const,
50
- env: (id: string) => ['workspaces', 'env', id] as const
51
- }
52
-
53
- // Registered workspaces (the contents of workspaces.json).
54
- //
55
- // Cache-first: the list rarely changes, so `staleTime: Infinity` keeps it cached
56
- // indefinitely (no focus/interval refetch churn) and mutations below keep it
57
- // current. `refetchOnMount: 'always'` still fires a background refetch on every
58
- // (re)mount — e.g. when the Sidebar remounts on collapse — while showing the
59
- // cached data immediately, so the rows never flicker empty.
60
- export function useWorkspaces() {
61
- return useQuery<WorkspaceEntry[]>({
62
- queryKey: workspaceKeys.all,
63
- queryFn: () => fetch('/api/workspaces').then(r => r.json()),
64
- staleTime: Infinity,
65
- refetchOnMount: 'always'
66
- })
67
- }
68
-
69
- // Per-workspace dashboard preview (widget grid thumbnail).
70
- export function useWorkspacePreview(workspaceId: string) {
71
- return useQuery<WorkspacePreview>({
72
- queryKey: workspaceKeys.preview(workspaceId),
73
- queryFn: () => fetch(`/api/workspaces/${workspaceId}/preview`).then(r => r.json()),
74
- staleTime: 60_000
75
- })
76
- }
77
-
78
- // Shared freshness policy for a workspace's resources: always considered stale
79
- // (`staleTime: 0`) so every (re)mount and window-focus refetches in the
80
- // background, while `gcTime` keeps the data cached when you switch to another
81
- // workspace and back — so the panel shows instantly, then revalidates.
82
- const WORKSPACE_RESOURCE_OPTS = {
83
- staleTime: 0,
84
- gcTime: 5 * 60_000,
85
- refetchOnMount: true,
86
- refetchOnWindowFocus: true
87
- } as const
88
-
89
- // Persisted layout + workspace metadata for a single workspace.
90
- export function useWorkspaceLayout(workspaceId: string) {
91
- return useQuery<WorkspaceLayoutResponse>({
92
- queryKey: workspaceKeys.layout(workspaceId),
93
- queryFn: () => fetch(`/api/workspaces/${workspaceId}`).then(r => r.json()),
94
- ...WORKSPACE_RESOURCE_OPTS
95
- })
96
- }
97
-
98
- // Widgets declared in a workspace (the endpoint wraps them in `{ widgets }`).
99
- export function useWorkspaceWidgets(workspaceId: string) {
100
- return useQuery<WidgetInfo[]>({
101
- queryKey: workspaceKeys.widgets(workspaceId),
102
- queryFn: () =>
103
- fetch(`/api/workspaces/${workspaceId}/widgets`)
104
- .then(r => r.json())
105
- .then((d: { widgets: WidgetInfo[] }) => d.widgets),
106
- ...WORKSPACE_RESOURCE_OPTS
107
- })
108
- }
109
-
110
- // Views declared in a workspace (the endpoint wraps them in `{ views }`), in
111
- // nav/manifest order.
112
- export function useWorkspaceViews(workspaceId: string) {
113
- return useQuery<ViewInfo[]>({
114
- queryKey: workspaceKeys.views(workspaceId),
115
- queryFn: () =>
116
- fetch(`/api/workspaces/${workspaceId}/views`)
117
- .then(r => r.json())
118
- .then((d: { views: ViewInfo[] }) => d.views),
119
- ...WORKSPACE_RESOURCE_OPTS
120
- })
121
- }
122
-
123
- // Sessions (chat threads) available in a workspace, latest first.
124
- export function useWorkspaceSessions(workspaceId: string) {
125
- return useQuery<SessionInfo[]>({
126
- queryKey: workspaceKeys.sessions(workspaceId),
127
- queryFn: () => fetch(`/api/workspaces/${workspaceId}/sessions`).then(r => r.json()),
128
- ...WORKSPACE_RESOURCE_OPTS
129
- })
130
- }
131
-
132
- // A thread's materialized transcript (ViewState), fetched once from `/events`
133
- // and then kept live by WS deltas the connection manager folds in via
134
- // setQueryData. `staleTime: Infinity` + no focus/mount refetch is deliberate:
135
- // the app-wide socket never drops on navigation, so we never miss deltas while
136
- // navigating and must NOT refetch (which would clobber live state). A real
137
- // socket reconnect invalidates these queries to heal any offline gap. New
138
- // (unsent) sessions are primed via setQueryData, so this never fetches an empty
139
- // transcript over their optimistic turn.
140
- export function useSessionView(workspaceId: string, sessionId: string | null) {
141
- return useQuery<ViewState>({
142
- queryKey: workspaceKeys.events(workspaceId, sessionId ?? ''),
143
- queryFn: async () => {
144
- const res = await fetch(`/api/workspaces/${workspaceId}/sessions/${sessionId}/events`)
145
- const evs: StreamEvent[] = res.ok ? await res.json() : []
146
- return applyEvents(evs)
147
- },
148
- enabled: !!sessionId,
149
- staleTime: Infinity,
150
- gcTime: 5 * 60_000,
151
- refetchOnMount: false,
152
- refetchOnWindowFocus: false
153
- })
154
- }
155
-
156
- // MCP servers configured for a workspace (Claude Code only). Fetching is
157
- // expensive — the server spawns an agent query to probe connection status — so
158
- // this is cache-first: `staleTime`/`gcTime` Infinity means it's fetched once and
159
- // then served from cache, surviving navigation between workspaces (no refetch on
160
- // remount/focus). `enabled` gates it to Claude workspaces.
161
- export function useWorkspaceMcp(workspaceId: string, enabled: boolean) {
162
- return useQuery<McpServer[]>({
163
- queryKey: workspaceKeys.mcp(workspaceId),
164
- queryFn: () => fetch(`/api/workspaces/${workspaceId}/mcp`).then(r => r.json()),
165
- enabled,
166
- staleTime: Infinity,
167
- gcTime: Infinity,
168
- refetchOnMount: false,
169
- refetchOnWindowFocus: false
170
- })
171
- }
172
-
173
- // Models the workspace's agent backend can run (normalized across providers by
174
- // the server). Like MCP status, the list is stable per workspace, so it's
175
- // cache-first — fetched once and served from cache across navigation.
176
- export function useWorkspaceModels(workspaceId: string) {
177
- return useQuery<WorkspaceModels>({
178
- queryKey: workspaceKeys.models(workspaceId),
179
- queryFn: () => fetch(`/api/workspaces/${workspaceId}/models`).then(r => r.json()),
180
- staleTime: Infinity,
181
- gcTime: Infinity,
182
- refetchOnMount: false,
183
- refetchOnWindowFocus: false
184
- })
185
- }
186
-
187
- // Per-thread agent settings (model + reasoning effort). Returns {} for threads
188
- // that never overrode the workspace defaults; the picker falls back to the
189
- // workspace layout defaults for display in that case. Gated on a sessionId so a
190
- // brand-new (unsent) chat — which has no thread id yet — never fetches.
191
- export function useThreadConfig(workspaceId: string, sessionId: string | null) {
192
- return useQuery<ThreadConfig>({
193
- queryKey: workspaceKeys.threadConfig(workspaceId, sessionId ?? ''),
194
- queryFn: () =>
195
- fetch(`/api/workspaces/${workspaceId}/sessions/${sessionId}/config`).then(r => r.json()),
196
- enabled: !!sessionId,
197
- // Cache-first: thread config only changes via this app's own PUTs (which
198
- // write through the cache), so refetching on every picker (re)mount would
199
- // just flash the workspace default before the GET resolves. Fetch once per
200
- // thread, then serve from cache.
201
- staleTime: Infinity,
202
- gcTime: 5 * 60_000,
203
- refetchOnMount: false,
204
- refetchOnWindowFocus: false
205
- })
206
- }
207
-
208
- // Patch a thread's config (PUT returns the merged result). Writes the merged
209
- // config straight into the query cache so the picker reflects it immediately.
210
- export function useSaveThreadConfig(workspaceId: string) {
211
- const qc = useQueryClient()
212
- return useMutation<ThreadConfig, Error, { sessionId: string; patch: ThreadConfig }>({
213
- mutationFn: async ({ patch, sessionId }) => {
214
- const res = await fetch(`/api/workspaces/${workspaceId}/sessions/${sessionId}/config`, {
215
- method: 'PUT',
216
- headers: { 'Content-Type': 'application/json' },
217
- body: JSON.stringify(patch)
218
- })
219
- if (!res.ok) throw new Error('Failed to save thread config')
220
- return res.json()
221
- },
222
- onSuccess: (next, { sessionId }) => {
223
- qc.setQueryData<ThreadConfig>(workspaceKeys.threadConfig(workspaceId, sessionId), next)
224
- }
225
- })
226
- }
227
-
228
- // Persist a workspace's layout (widget grid, chat mode, theme). Callers update
229
- // the layout query cache optimistically and use this to write through to the
230
- // server, so it's a plain fire-and-forget PUT with no extra cache work.
231
- export function useSaveLayout(workspaceId: string) {
232
- return useMutation<void, Error, WorkspaceLayout>({
233
- mutationFn: async layout => {
234
- const res = await fetch(`/api/workspaces/${workspaceId}`, {
235
- method: 'PUT',
236
- headers: { 'Content-Type': 'application/json' },
237
- body: JSON.stringify(layout)
238
- })
239
- if (!res.ok) throw new Error('Failed to save layout')
240
- }
241
- })
242
- }
243
-
244
- // A workspace's effective env view (masked values + discovered `.env`).
245
- export function useWorkspaceEnv(workspaceId: string) {
246
- return useQuery<WorkspaceEnvView>({
247
- queryKey: workspaceKeys.env(workspaceId),
248
- queryFn: () => fetch(`/api/workspaces/${workspaceId}/env`).then(r => r.json()),
249
- ...WORKSPACE_RESOURCE_OPTS
250
- })
251
- }
252
-
253
- // Patch of a workspace's env: set/remove custom secrets, or toggle `.env`
254
- // inheritance. The PUT returns the fresh view (see useUpdateEnv).
255
- export type EnvPatch = {
256
- set?: Record<string, string>
257
- remove?: string[]
258
- inheritDotenv?: boolean
259
- }
260
-
261
- // Apply an env patch. The endpoint returns the recomputed view, which we write
262
- // straight into the cache so the list reflects the change immediately.
263
- export function useUpdateEnv(workspaceId: string) {
264
- const qc = useQueryClient()
265
- return useMutation<WorkspaceEnvView, Error, EnvPatch>({
266
- mutationFn: async patch => {
267
- const res = await fetch(`/api/workspaces/${workspaceId}/env`, {
268
- method: 'PUT',
269
- headers: { 'Content-Type': 'application/json' },
270
- body: JSON.stringify(patch)
271
- })
272
- if (!res.ok) throw new Error(await res.text())
273
- return res.json()
274
- },
275
- onSuccess: next => {
276
- qc.setQueryData<WorkspaceEnvView>(workspaceKeys.env(workspaceId), next)
277
- }
278
- })
279
- }
280
-
281
- // Set (or clear, with `null`) the workspace display-name override. The server
282
- // broadcasts `workspace:updated`, but we also invalidate locally so the modal,
283
- // header, and sidebar reflect the change without waiting on the socket.
284
- export function useSaveWorkspaceName(workspaceId: string) {
285
- const qc = useQueryClient()
286
- return useMutation<void, Error, string | null>({
287
- mutationFn: async name => {
288
- const res = await fetch(`/api/workspaces/${workspaceId}/config`, {
289
- method: 'PUT',
290
- headers: { 'Content-Type': 'application/json' },
291
- body: JSON.stringify({ name })
292
- })
293
- if (!res.ok) throw new Error('Failed to save name')
294
- },
295
- onSuccess: () => {
296
- qc.invalidateQueries({ queryKey: workspaceKeys.layout(workspaceId) })
297
- qc.invalidateQueries({ queryKey: workspaceKeys.all })
298
- }
299
- })
300
- }
301
-
302
- // Upload a raw image as the workspace icon (the server resizes to a 128×128
303
- // WebP and returns the data URL). Used for direct uploads and for the canvas
304
- // rasterized from an emoji/glyph + background.
305
- export function useSaveWorkspaceIcon(workspaceId: string) {
306
- const qc = useQueryClient()
307
- return useMutation<{ icon: string }, Error, Blob>({
308
- mutationFn: async blob => {
309
- const res = await fetch(`/api/workspaces/${workspaceId}/icon`, {
310
- method: 'PUT',
311
- headers: { 'Content-Type': blob.type || 'application/octet-stream' },
312
- body: blob
313
- })
314
- if (!res.ok) throw new Error(await res.text())
315
- return res.json()
316
- },
317
- onSuccess: () => {
318
- qc.invalidateQueries({ queryKey: workspaceKeys.layout(workspaceId) })
319
- qc.invalidateQueries({ queryKey: workspaceKeys.all })
320
- }
321
- })
322
- }
323
-
324
- // Reset the icon back to the provider default.
325
- export function useResetWorkspaceIcon(workspaceId: string) {
326
- const qc = useQueryClient()
327
- return useMutation<void, Error, void>({
328
- mutationFn: async () => {
329
- const res = await fetch(`/api/workspaces/${workspaceId}/icon`, { method: 'DELETE' })
330
- if (!res.ok) throw new Error('Failed to reset icon')
331
- },
332
- onSuccess: () => {
333
- qc.invalidateQueries({ queryKey: workspaceKeys.layout(workspaceId) })
334
- qc.invalidateQueries({ queryKey: workspaceKeys.all })
335
- }
336
- })
337
- }
338
-
339
- // CC / OpenClaw directories found on the machine but not yet registered.
340
- export function useDiscoveredWorkspaces() {
341
- return useQuery<DiscoveredWorkspace[]>({
342
- queryKey: workspaceKeys.discover,
343
- queryFn: () => fetch('/api/workspaces/discover').then(r => r.json())
344
- })
345
- }
346
-
347
- // Import a discovered workspace into the registry (optimistically move it from
348
- // the discover list into the registered list).
349
- export function useAddWorkspace() {
350
- const qc = useQueryClient()
351
- return useMutation<WorkspaceEntry, Error, DiscoveredWorkspace>({
352
- mutationFn: async discovered => {
353
- const res = await fetch('/api/workspaces', {
354
- method: 'POST',
355
- headers: { 'Content-Type': 'application/json' },
356
- body: JSON.stringify(discovered)
357
- })
358
- // The server provisions (skills + `.moi/`) before registering, so a
359
- // failure comes back as a plain-text error, not an entry.
360
- if (!res.ok) throw new Error(await res.text())
361
- return res.json()
362
- },
363
- onSuccess: (entry, suggestion) => {
364
- qc.setQueryData<WorkspaceEntry[]>(workspaceKeys.all, prev => [...(prev ?? []), entry])
365
- qc.setQueryData<DiscoveredWorkspace[]>(workspaceKeys.discover, prev =>
366
- (prev ?? []).filter(s => s.path !== suggestion.path)
367
- )
368
- }
369
- })
370
- }
371
-
372
- // Where `/workspace/create` places new folders on disk. `displayRoot` is the
373
- // home-relative form (e.g. "~/moi") shown in the create form.
374
- export type CreateWorkspaceInfo = {
375
- root: string
376
- displayRoot: string
377
- }
378
-
379
- export function useCreateWorkspaceInfo() {
380
- return useQuery<CreateWorkspaceInfo>({
381
- queryKey: workspaceKeys.createInfo,
382
- queryFn: () => fetch('/api/workspaces/create').then(r => r.json()),
383
- staleTime: Infinity
384
- })
385
- }
386
-
387
- export type CreateWorkspaceInput = {
388
- name: string
389
- type: WorkspaceType
390
- }
391
-
392
- // Create a brand-new workspace folder (server provisions skills + `.moi/` and
393
- // registers it). Non-2xx responses carry a user-facing message in the body.
394
- export function useCreateWorkspace() {
395
- const qc = useQueryClient()
396
- return useMutation<WorkspaceEntry, Error, CreateWorkspaceInput>({
397
- mutationFn: async input => {
398
- const res = await fetch('/api/workspaces/create', {
399
- method: 'POST',
400
- headers: { 'Content-Type': 'application/json' },
401
- body: JSON.stringify(input)
402
- })
403
- if (!res.ok) throw new Error(await res.text())
404
- return res.json()
405
- },
406
- onSuccess: entry => {
407
- qc.setQueryData<WorkspaceEntry[]>(workspaceKeys.all, prev => [...(prev ?? []), entry])
408
- }
409
- })
410
- }
411
-
412
- // Remove a workspace from the registry (re-discovery may surface it again).
413
- export function useRemoveWorkspace() {
414
- const qc = useQueryClient()
415
- return useMutation<void, Error, WorkspaceEntry>({
416
- mutationFn: async entry => {
417
- const res = await fetch(`/api/workspaces/${entry.id}`, { method: 'DELETE' })
418
- if (!res.ok) throw new Error('Failed to remove workspace')
419
- },
420
- onSuccess: (_void, entry) => {
421
- qc.setQueryData<WorkspaceEntry[]>(workspaceKeys.all, prev =>
422
- (prev ?? []).filter(w => w.id !== entry.id)
423
- )
424
- qc.invalidateQueries({ queryKey: workspaceKeys.discover })
425
- }
426
- })
427
- }
@@ -1,41 +0,0 @@
1
- import { useEffect } from 'react'
2
-
3
- import { Route, Switch, useLocation } from 'wouter'
4
-
5
- import { setWorkspaceSwitchHandler } from '@/client/lib/connection'
6
-
7
- import { HomePage } from './HomePage'
8
- import { PlaygroundPage } from './playground/PlaygroundPage'
9
- import { ToolCallsPage } from './playground/ToolCallsPage'
10
- import { WorkspaceRoute } from './routes/workspace/[id]'
11
- import { CreateWorkspacePage } from './routes/workspace/create'
12
-
13
- // Top-level router — sets up all client-side routes
14
- export function AppRouter() {
15
- const [, navigate] = useLocation()
16
-
17
- // When the server broadcasts a workspace:switch (e.g. from `moi start`),
18
- // navigate to that workspace
19
- useEffect(() => {
20
- setWorkspaceSwitchHandler(id => navigate(`/workspace/${id}`))
21
- return () => setWorkspaceSwitchHandler(null)
22
- }, [navigate])
23
-
24
- return (
25
- <Switch>
26
- <Route path="/" component={HomePage} />
27
- <Route path="/playground/tool-calls" component={ToolCallsPage} />
28
- <Route path="/playground" component={PlaygroundPage} />
29
- {/* Must precede `/workspace/:id` — the Switch matches in order, so the
30
- literal route wins over the id pattern. */}
31
- <Route path="/workspace/create" component={CreateWorkspacePage} />
32
- <Route path="/workspace/:id">
33
- {/* Key by id so switching workspaces mounts a fresh subtree — the
34
- per-workspace chat store (and its websocket) tears down and resets
35
- cleanly rather than leaking state across workspaces. Cached React
36
- Query data keeps the remount instant. */}
37
- {(params: { id: string }) => <WorkspaceRoute key={params.id} id={params.id} />}
38
- </Route>
39
- </Switch>
40
- )
41
- }