moi-computer 0.0.3 → 0.1.0

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 (214) hide show
  1. package/bunfig.toml +4 -0
  2. package/client/api/workspaces.ts +277 -6
  3. package/client/assets/mcp/agentation.png +0 -0
  4. package/client/assets/mcp/airtable.png +0 -0
  5. package/client/assets/mcp/apollo.png +0 -0
  6. package/client/assets/mcp/asana.png +0 -0
  7. package/client/assets/mcp/box.png +0 -0
  8. package/client/assets/mcp/chrome.svg +33 -0
  9. package/client/assets/mcp/clickup.png +0 -0
  10. package/client/assets/mcp/cloudflare.png +0 -0
  11. package/client/assets/mcp/context7.png +0 -0
  12. package/client/assets/mcp/datadog.png +0 -0
  13. package/client/assets/mcp/dropbox.png +0 -0
  14. package/client/assets/mcp/elevenlabs.png +0 -0
  15. package/client/assets/mcp/exa.png +0 -0
  16. package/client/assets/mcp/firecrawl.png +0 -0
  17. package/client/assets/mcp/gmail.png +0 -0
  18. package/client/assets/mcp/googlecalendar.png +0 -0
  19. package/client/assets/mcp/googledrive.png +0 -0
  20. package/client/assets/mcp/grafana.png +0 -0
  21. package/client/assets/mcp/huggingface.png +0 -0
  22. package/client/assets/mcp/intercom.png +0 -0
  23. package/client/assets/mcp/monday.png +0 -0
  24. package/client/assets/mcp/mongodb.png +0 -0
  25. package/client/assets/mcp/paper.png +0 -0
  26. package/client/assets/mcp/paypal.png +0 -0
  27. package/client/assets/mcp/perplexity.png +0 -0
  28. package/client/assets/mcp/postgresql.png +0 -0
  29. package/client/assets/mcp/posthog.png +0 -0
  30. package/client/assets/mcp/puppeteer.png +0 -0
  31. package/client/assets/mcp/railway.png +0 -0
  32. package/client/assets/mcp/redis.png +0 -0
  33. package/client/assets/mcp/salesforce.png +0 -0
  34. package/client/assets/mcp/shopify.png +0 -0
  35. package/client/assets/mcp/snowflake.png +0 -0
  36. package/client/assets/mcp/telegram.png +0 -0
  37. package/client/assets/mcp/twilio.png +0 -0
  38. package/client/assets/mcp/zapier.png +0 -0
  39. package/client/components/App.tsx +7 -1
  40. package/client/components/ChatInput.tsx +194 -13
  41. package/client/components/ChatPanel.tsx +116 -47
  42. package/client/components/ChatPopup.tsx +1 -1
  43. package/client/components/IconMcp.tsx +21 -0
  44. package/client/components/McpMenu.tsx +125 -0
  45. package/client/components/ModelPicker.tsx +147 -0
  46. package/client/components/Scratchpad.tsx +775 -0
  47. package/client/components/ShimmerText.tsx +20 -0
  48. package/client/components/ThreadSelector.tsx +2 -2
  49. package/client/components/TurnView.tsx +111 -531
  50. package/client/components/WidgetShell.tsx +1 -1
  51. package/client/components/WorkspacesPage.tsx +12 -4
  52. package/client/components/layout/SidebarLayout.tsx +18 -9
  53. package/client/components/playground/ToolCallsPage.tsx +81 -0
  54. package/client/components/routes/workspace/[id].tsx +534 -141
  55. package/client/components/routes/workspace/create.tsx +155 -0
  56. package/client/components/settings/IconPicker.tsx +590 -0
  57. package/client/components/settings/SettingsPages.tsx +307 -0
  58. package/client/components/settings/WorkspaceSettings.tsx +92 -0
  59. package/client/components/tool-group/CodeBlock.tsx +41 -0
  60. package/client/components/tool-group/Collapse.tsx +28 -0
  61. package/client/components/tool-group/ReadImagePreview.tsx +46 -0
  62. package/client/components/tool-group/SubagentCard.tsx +135 -0
  63. package/client/components/tool-group/TimelineRow.tsx +147 -0
  64. package/client/components/tool-group/ToolCallGroup.tsx +231 -0
  65. package/client/components/tool-group/ToolOutput.tsx +139 -0
  66. package/client/components/tool-group/detect.ts +93 -0
  67. package/client/components/tool-group/fixtures.ts +315 -0
  68. package/client/components/tool-group/format.ts +211 -0
  69. package/client/components/tool-group/index.ts +9 -0
  70. package/client/components/ui/dialog.tsx +58 -0
  71. package/client/components/ui/hover-card.tsx +44 -0
  72. package/client/components/ui/switch.tsx +23 -0
  73. package/client/components/ui/tooltip.tsx +54 -0
  74. package/client/externalize-react.ts +6 -0
  75. package/client/hooks/useApplet.ts +117 -0
  76. package/client/hooks/useChat.ts +162 -62
  77. package/client/hooks/useMeiEvents.ts +9 -2
  78. package/client/hooks/useStickToBottom.ts +86 -0
  79. package/client/hooks/useWorkspaceTheme.ts +8 -2
  80. package/client/index.css +48 -2
  81. package/client/index.html +9 -5
  82. package/client/index.tsx +29 -2
  83. package/client/lib/WorkspaceContext.tsx +5 -8
  84. package/client/lib/WorkspaceLayoutContext.tsx +30 -10
  85. package/client/lib/applet-cache.ts +54 -0
  86. package/client/lib/connection.ts +237 -0
  87. package/client/lib/flags.ts +10 -0
  88. package/client/lib/mcp-icons.ts +142 -10
  89. package/client/lib/preview-turn.ts +37 -0
  90. package/client/lib/render-icon.ts +173 -0
  91. package/client/lib/scratch-executor.ts +20 -0
  92. package/client/lib/uploads.ts +18 -0
  93. package/client/main.tsx +5 -0
  94. package/client/store/live.ts +282 -0
  95. package/client/structured-clone-shim.ts +14 -0
  96. package/client/theme.css +2 -2
  97. package/client/vendor/emojibase/en/data.json +1 -0
  98. package/client/vendor/emojibase/en/messages.json +1 -0
  99. package/client/vendor/react/development/_impl/react-dom-client.js +15871 -0
  100. package/client/vendor/react/development/_impl/react-dom.js +223 -0
  101. package/client/vendor/react/development/_impl/react-jsx-dev-runtime.js +256 -0
  102. package/client/vendor/react/development/_impl/react-jsx-runtime.js +260 -0
  103. package/client/vendor/react/development/_impl/react.js +863 -0
  104. package/client/vendor/react/development/react-dom-client.js +6 -0
  105. package/client/vendor/react/development/react-dom.js +17 -0
  106. package/client/vendor/react/development/react-jsx-dev-runtime.js +5 -0
  107. package/client/vendor/react/development/react-jsx-runtime.js +6 -0
  108. package/client/vendor/react/development/react.js +47 -0
  109. package/client/vendor/react/production/_impl/react-dom-client.js +10361 -0
  110. package/client/vendor/react/production/_impl/react-dom.js +184 -0
  111. package/client/vendor/react/production/_impl/react-jsx-dev-runtime.js +37 -0
  112. package/client/vendor/react/production/_impl/react-jsx-runtime.js +60 -0
  113. package/client/vendor/react/production/_impl/react.js +428 -0
  114. package/client/vendor/react/production/react-dom-client.js +6 -0
  115. package/client/vendor/react/production/react-dom.js +17 -0
  116. package/client/vendor/react/production/react-jsx-dev-runtime.js +5 -0
  117. package/client/vendor/react/production/react-jsx-runtime.js +6 -0
  118. package/client/vendor/react/production/react.js +47 -0
  119. package/dist/agentation-4s0nn45p.png +0 -0
  120. package/dist/airtable-hsa66v6q.png +0 -0
  121. package/dist/apollo-2ed5dy2d.png +0 -0
  122. package/dist/asana-tvgtwbx2.png +0 -0
  123. package/dist/box-w3n36t5g.png +0 -0
  124. package/dist/chrome-tspm94rw.svg +33 -0
  125. package/dist/chunk-kc6e9nd4.css +1 -0
  126. package/dist/chunk-yf3p7qg7.js +673 -0
  127. package/dist/clickup-qqrqqvqb.png +0 -0
  128. package/dist/cloudflare-j9p931v6.png +0 -0
  129. package/dist/context7-8ht0xjfy.png +0 -0
  130. package/dist/datadog-70ne3yzt.png +0 -0
  131. package/dist/dropbox-4m5s9mgr.png +0 -0
  132. package/dist/elevenlabs-2nzzej1t.png +0 -0
  133. package/dist/exa-qqj3vr0x.png +0 -0
  134. package/dist/firecrawl-w2t8nehx.png +0 -0
  135. package/dist/gmail-sg6a5v3x.png +0 -0
  136. package/dist/googlecalendar-nqhh2v7r.png +0 -0
  137. package/dist/googledrive-6s8xyab7.png +0 -0
  138. package/dist/grafana-1yfsnwr6.png +0 -0
  139. package/dist/huggingface-kxzaxj83.png +0 -0
  140. package/dist/index.html +10 -6
  141. package/dist/intercom-td763jt8.png +0 -0
  142. package/dist/monday-jdbs4wwf.png +0 -0
  143. package/dist/mongodb-emzxvhd5.png +0 -0
  144. package/dist/paper-zbt34fab.png +0 -0
  145. package/dist/paypal-kwwf7xsc.png +0 -0
  146. package/dist/perplexity-4y63rxvj.png +0 -0
  147. package/dist/postgresql-qsspbsr1.png +0 -0
  148. package/dist/posthog-sphppc4w.png +0 -0
  149. package/dist/puppeteer-2xjt1a9b.png +0 -0
  150. package/dist/railway-834de8d2.png +0 -0
  151. package/dist/redis-spm6w2m1.png +0 -0
  152. package/dist/salesforce-1mk56v4z.png +0 -0
  153. package/dist/shopify-90dadaav.png +0 -0
  154. package/dist/snowflake-hfpykpgy.png +0 -0
  155. package/dist/telegram-v6tjyrs7.png +0 -0
  156. package/dist/twilio-dpyjdwpj.png +0 -0
  157. package/dist/zapier-p67qfch0.png +0 -0
  158. package/lib/attachment-note.ts +48 -0
  159. package/lib/claude-adapter.ts +219 -29
  160. package/lib/format.ts +32 -0
  161. package/lib/types.ts +314 -6
  162. package/package.json +10 -5
  163. package/server/CLAUDE.md +3 -0
  164. package/server/agent.ts +25 -118
  165. package/server/api.ts +593 -0
  166. package/server/applets.ts +396 -0
  167. package/server/build-applet.ts +580 -0
  168. package/server/cc-session.ts +611 -0
  169. package/server/cli-colors.ts +17 -0
  170. package/server/cli-ui.ts +52 -0
  171. package/server/cli.ts +964 -72
  172. package/server/control.ts +166 -19
  173. package/server/debug.ts +10 -0
  174. package/server/events.ts +24 -0
  175. package/server/functions-worker.ts +18 -2
  176. package/server/functions.ts +59 -12
  177. package/server/icon.ts +13 -0
  178. package/server/layout.ts +25 -3
  179. package/server/mcp.ts +125 -0
  180. package/server/moi-scaffold.ts +85 -0
  181. package/server/openclaw-session.ts +41 -10
  182. package/server/openclaw.ts +22 -0
  183. package/server/preview.ts +70 -0
  184. package/server/registry.ts +32 -2
  185. package/server/scratchpad-executor.ts +380 -0
  186. package/server/scratchpad-relay.ts +45 -0
  187. package/server/scratchpad.ts +171 -0
  188. package/server/skill-version.ts +146 -0
  189. package/server/skills-template.ts +6 -1
  190. package/server/state.ts +22 -36
  191. package/server/static.ts +23 -0
  192. package/server/status.ts +94 -0
  193. package/server/thread-config.ts +125 -0
  194. package/server/uploads.ts +0 -0
  195. package/server/vendor.ts +63 -0
  196. package/server/views.ts +0 -0
  197. package/server/web.ts +108 -253
  198. package/server/widgets.ts +52 -142
  199. package/server/workspace-config.ts +37 -0
  200. package/server/workspace-env.ts +407 -0
  201. package/server/workspace-init.ts +66 -0
  202. package/workspace/.claude/skills/moi-workspace/DESIGN.md +109 -0
  203. package/workspace/.claude/skills/moi-workspace/SCRATCHPAD.md +57 -0
  204. package/workspace/.claude/skills/moi-workspace/SKILL.md +252 -0
  205. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +22 -0
  206. package/client/hooks/useWidget.ts +0 -72
  207. package/client/hooks/useWidgetList.ts +0 -30
  208. package/client/lib/ws.ts +0 -129
  209. package/client/store/chat.tsx +0 -162
  210. package/dist/chunk-4615fa69.js +0 -67
  211. package/dist/chunk-582xmy05.css +0 -1
  212. package/server/build-widget.ts +0 -343
  213. package/workspace/.claude/skills/widgets/DESIGN.md +0 -630
  214. package/workspace/.claude/skills/widgets/SKILL.md +0 -176
package/bunfig.toml CHANGED
@@ -1,3 +1,7 @@
1
1
 
2
2
  [serve.static]
3
3
  plugins = ["bun-plugin-tailwind", "./client/externalize-react.ts"]
4
+ # Inline only PUBLIC_*-prefixed env vars into the client bundle (e.g. the tldraw
5
+ # license key, PUBLIC_TLDRAW_LICENSE_KEY). The prefix keeps private secrets out
6
+ # of the browser bundle. Mirrored for prod builds in scripts/build-client.ts.
7
+ env = "PUBLIC_*"
@@ -1,19 +1,31 @@
1
1
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
2
2
 
3
+ import { applyEvents } from '@/lib/format'
3
4
  import type {
4
5
  DiscoveredWorkspace,
6
+ EnvScope,
7
+ McpServer,
5
8
  SessionInfo,
9
+ StreamEvent,
10
+ ThreadConfig,
11
+ ViewInfo,
12
+ ViewState,
6
13
  WidgetInfo,
7
14
  WorkspaceEntry,
15
+ WorkspaceEnvView,
8
16
  WorkspaceLayout,
9
- WorkspacePreview
17
+ WorkspaceModels,
18
+ WorkspacePreview,
19
+ WorkspaceType
10
20
  } from '@/lib/types'
11
21
 
12
- // Layout endpoint payload: the persisted layout plus server-resolved metadata
13
- // (`cwd`, `name`, `agentId`) merged in by the route.
22
+ // `/api/workspaces/:id` payload: the persisted layout plus server-resolved
23
+ // metadata merged in by the route — `name` (settings override or folder name),
24
+ // `cwd` (workspace folder), `provider` (agent backend), and `agentId`.
14
25
  export type WorkspaceLayoutResponse = WorkspaceLayout & {
15
26
  cwd: string
16
27
  name: string
28
+ provider?: WorkspaceType
17
29
  agentId?: string
18
30
  }
19
31
 
@@ -22,10 +34,21 @@ export type WorkspaceLayoutResponse = WorkspaceLayout & {
22
34
  export const workspaceKeys = {
23
35
  all: ['workspaces'] as const,
24
36
  discover: ['workspaces', 'discover'] as const,
37
+ createInfo: ['workspaces', 'create-info'] as const,
25
38
  preview: (id: string) => ['workspaces', 'preview', id] as const,
26
39
  layout: (id: string) => ['workspaces', 'layout', id] as const,
27
40
  widgets: (id: string) => ['workspaces', 'widgets', id] as const,
28
- sessions: (id: string) => ['workspaces', 'sessions', id] as const
41
+ views: (id: string) => ['workspaces', 'views', id] as const,
42
+ sessions: (id: string) => ['workspaces', 'sessions', id] as const,
43
+ // Materialized transcript (ViewState) for one thread. The connection manager
44
+ // patches this cache with live WS deltas; the `['workspaces','events']`
45
+ // prefix lets it invalidate every thread on reconnect.
46
+ events: (id: string, sessionId: string) => ['workspaces', 'events', id, sessionId] as const,
47
+ threadConfig: (id: string, sessionId: string) =>
48
+ ['workspaces', 'threadConfig', id, sessionId] as const,
49
+ mcp: (id: string) => ['workspaces', 'mcp', id] as const,
50
+ models: (id: string) => ['workspaces', 'models', id] as const,
51
+ env: (id: string) => ['workspaces', 'env', id] as const
29
52
  }
30
53
 
31
54
  // Registered workspaces (the contents of workspaces.json).
@@ -68,7 +91,7 @@ const WORKSPACE_RESOURCE_OPTS = {
68
91
  export function useWorkspaceLayout(workspaceId: string) {
69
92
  return useQuery<WorkspaceLayoutResponse>({
70
93
  queryKey: workspaceKeys.layout(workspaceId),
71
- queryFn: () => fetch(`/api/workspaces/${workspaceId}/layout`).then(r => r.json()),
94
+ queryFn: () => fetch(`/api/workspaces/${workspaceId}`).then(r => r.json()),
72
95
  ...WORKSPACE_RESOURCE_OPTS
73
96
  })
74
97
  }
@@ -85,6 +108,19 @@ export function useWorkspaceWidgets(workspaceId: string) {
85
108
  })
86
109
  }
87
110
 
111
+ // Views declared in a workspace (the endpoint wraps them in `{ views }`), in
112
+ // nav/manifest order.
113
+ export function useWorkspaceViews(workspaceId: string) {
114
+ return useQuery<ViewInfo[]>({
115
+ queryKey: workspaceKeys.views(workspaceId),
116
+ queryFn: () =>
117
+ fetch(`/api/workspaces/${workspaceId}/views`)
118
+ .then(r => r.json())
119
+ .then((d: { views: ViewInfo[] }) => d.views),
120
+ ...WORKSPACE_RESOURCE_OPTS
121
+ })
122
+ }
123
+
88
124
  // Sessions (chat threads) available in a workspace, latest first.
89
125
  export function useWorkspaceSessions(workspaceId: string) {
90
126
  return useQuery<SessionInfo[]>({
@@ -94,13 +130,109 @@ export function useWorkspaceSessions(workspaceId: string) {
94
130
  })
95
131
  }
96
132
 
133
+ // A thread's materialized transcript (ViewState), fetched once from `/events`
134
+ // and then kept live by WS deltas the connection manager folds in via
135
+ // setQueryData. `staleTime: Infinity` + no focus/mount refetch is deliberate:
136
+ // the app-wide socket never drops on navigation, so we never miss deltas while
137
+ // navigating and must NOT refetch (which would clobber live state). A real
138
+ // socket reconnect invalidates these queries to heal any offline gap. New
139
+ // (unsent) sessions are primed via setQueryData, so this never fetches an empty
140
+ // transcript over their optimistic turn.
141
+ export function useSessionView(workspaceId: string, sessionId: string | null) {
142
+ return useQuery<ViewState>({
143
+ queryKey: workspaceKeys.events(workspaceId, sessionId ?? ''),
144
+ queryFn: async () => {
145
+ const res = await fetch(`/api/workspaces/${workspaceId}/sessions/${sessionId}/events`)
146
+ const evs: StreamEvent[] = res.ok ? await res.json() : []
147
+ return applyEvents(evs)
148
+ },
149
+ enabled: !!sessionId,
150
+ staleTime: Infinity,
151
+ gcTime: 5 * 60_000,
152
+ refetchOnMount: false,
153
+ refetchOnWindowFocus: false
154
+ })
155
+ }
156
+
157
+ // MCP servers configured for a workspace (Claude Code only). Fetching is
158
+ // expensive — the server spawns an agent query to probe connection status — so
159
+ // this is cache-first: `staleTime`/`gcTime` Infinity means it's fetched once and
160
+ // then served from cache, surviving navigation between workspaces (no refetch on
161
+ // remount/focus). `enabled` gates it to Claude workspaces.
162
+ export function useWorkspaceMcp(workspaceId: string, enabled: boolean) {
163
+ return useQuery<McpServer[]>({
164
+ queryKey: workspaceKeys.mcp(workspaceId),
165
+ queryFn: () => fetch(`/api/workspaces/${workspaceId}/mcp`).then(r => r.json()),
166
+ enabled,
167
+ staleTime: Infinity,
168
+ gcTime: Infinity,
169
+ refetchOnMount: false,
170
+ refetchOnWindowFocus: false
171
+ })
172
+ }
173
+
174
+ // Models the workspace's agent backend can run (normalized across providers by
175
+ // the server). Like MCP status, the list is stable per workspace, so it's
176
+ // cache-first — fetched once and served from cache across navigation.
177
+ export function useWorkspaceModels(workspaceId: string) {
178
+ return useQuery<WorkspaceModels>({
179
+ queryKey: workspaceKeys.models(workspaceId),
180
+ queryFn: () => fetch(`/api/workspaces/${workspaceId}/models`).then(r => r.json()),
181
+ staleTime: Infinity,
182
+ gcTime: Infinity,
183
+ refetchOnMount: false,
184
+ refetchOnWindowFocus: false
185
+ })
186
+ }
187
+
188
+ // Per-thread agent settings (model + reasoning effort). Returns {} for threads
189
+ // that never overrode the workspace defaults; the picker falls back to the
190
+ // workspace layout defaults for display in that case. Gated on a sessionId so a
191
+ // brand-new (unsent) chat — which has no thread id yet — never fetches.
192
+ export function useThreadConfig(workspaceId: string, sessionId: string | null) {
193
+ return useQuery<ThreadConfig>({
194
+ queryKey: workspaceKeys.threadConfig(workspaceId, sessionId ?? ''),
195
+ queryFn: () =>
196
+ fetch(`/api/workspaces/${workspaceId}/sessions/${sessionId}/config`).then(r => r.json()),
197
+ enabled: !!sessionId,
198
+ // Cache-first: thread config only changes via this app's own PUTs (which
199
+ // write through the cache), so refetching on every picker (re)mount would
200
+ // just flash the workspace default before the GET resolves. Fetch once per
201
+ // thread, then serve from cache.
202
+ staleTime: Infinity,
203
+ gcTime: 5 * 60_000,
204
+ refetchOnMount: false,
205
+ refetchOnWindowFocus: false
206
+ })
207
+ }
208
+
209
+ // Patch a thread's config (PUT returns the merged result). Writes the merged
210
+ // config straight into the query cache so the picker reflects it immediately.
211
+ export function useSaveThreadConfig(workspaceId: string) {
212
+ const qc = useQueryClient()
213
+ return useMutation<ThreadConfig, Error, { sessionId: string; patch: ThreadConfig }>({
214
+ mutationFn: async ({ patch, sessionId }) => {
215
+ const res = await fetch(`/api/workspaces/${workspaceId}/sessions/${sessionId}/config`, {
216
+ method: 'PUT',
217
+ headers: { 'Content-Type': 'application/json' },
218
+ body: JSON.stringify(patch)
219
+ })
220
+ if (!res.ok) throw new Error('Failed to save thread config')
221
+ return res.json()
222
+ },
223
+ onSuccess: (next, { sessionId }) => {
224
+ qc.setQueryData<ThreadConfig>(workspaceKeys.threadConfig(workspaceId, sessionId), next)
225
+ }
226
+ })
227
+ }
228
+
97
229
  // Persist a workspace's layout (widget grid, chat mode, theme). Callers update
98
230
  // the layout query cache optimistically and use this to write through to the
99
231
  // server, so it's a plain fire-and-forget PUT with no extra cache work.
100
232
  export function useSaveLayout(workspaceId: string) {
101
233
  return useMutation<void, Error, WorkspaceLayout>({
102
234
  mutationFn: async layout => {
103
- const res = await fetch(`/api/workspaces/${workspaceId}/layout`, {
235
+ const res = await fetch(`/api/workspaces/${workspaceId}`, {
104
236
  method: 'PUT',
105
237
  headers: { 'Content-Type': 'application/json' },
106
238
  body: JSON.stringify(layout)
@@ -110,6 +242,102 @@ export function useSaveLayout(workspaceId: string) {
110
242
  })
111
243
  }
112
244
 
245
+ // A workspace's effective env view (masked values + scopes + discovered `.env`).
246
+ export function useWorkspaceEnv(workspaceId: string) {
247
+ return useQuery<WorkspaceEnvView>({
248
+ queryKey: workspaceKeys.env(workspaceId),
249
+ queryFn: () => fetch(`/api/workspaces/${workspaceId}/env`).then(r => r.json()),
250
+ ...WORKSPACE_RESOURCE_OPTS
251
+ })
252
+ }
253
+
254
+ // Patch of a workspace's env: set/remove custom secrets, change scopes, or
255
+ // toggle `.env` inheritance. The PUT returns the fresh view (see useUpdateEnv).
256
+ export type EnvPatch = {
257
+ set?: Record<string, string>
258
+ remove?: string[]
259
+ scopes?: Record<string, EnvScope>
260
+ inheritDotenv?: boolean
261
+ }
262
+
263
+ // Apply an env patch. The endpoint returns the recomputed view, which we write
264
+ // straight into the cache so the list reflects the change immediately.
265
+ export function useUpdateEnv(workspaceId: string) {
266
+ const qc = useQueryClient()
267
+ return useMutation<WorkspaceEnvView, Error, EnvPatch>({
268
+ mutationFn: async patch => {
269
+ const res = await fetch(`/api/workspaces/${workspaceId}/env`, {
270
+ method: 'PUT',
271
+ headers: { 'Content-Type': 'application/json' },
272
+ body: JSON.stringify(patch)
273
+ })
274
+ if (!res.ok) throw new Error(await res.text())
275
+ return res.json()
276
+ },
277
+ onSuccess: next => {
278
+ qc.setQueryData<WorkspaceEnvView>(workspaceKeys.env(workspaceId), next)
279
+ }
280
+ })
281
+ }
282
+
283
+ // Set (or clear, with `null`) the workspace display-name override. The server
284
+ // broadcasts `workspace:updated`, but we also invalidate locally so the modal,
285
+ // header, and sidebar reflect the change without waiting on the socket.
286
+ export function useSaveWorkspaceName(workspaceId: string) {
287
+ const qc = useQueryClient()
288
+ return useMutation<void, Error, string | null>({
289
+ mutationFn: async name => {
290
+ const res = await fetch(`/api/workspaces/${workspaceId}/config`, {
291
+ method: 'PUT',
292
+ headers: { 'Content-Type': 'application/json' },
293
+ body: JSON.stringify({ name })
294
+ })
295
+ if (!res.ok) throw new Error('Failed to save name')
296
+ },
297
+ onSuccess: () => {
298
+ qc.invalidateQueries({ queryKey: workspaceKeys.layout(workspaceId) })
299
+ qc.invalidateQueries({ queryKey: workspaceKeys.all })
300
+ }
301
+ })
302
+ }
303
+
304
+ // Upload a raw image as the workspace icon (the server resizes to a 128×128
305
+ // WebP and returns the data URL). Used for direct uploads and for the canvas
306
+ // rasterized from an emoji/glyph + background.
307
+ export function useSaveWorkspaceIcon(workspaceId: string) {
308
+ const qc = useQueryClient()
309
+ return useMutation<{ icon: string }, Error, Blob>({
310
+ mutationFn: async blob => {
311
+ const res = await fetch(`/api/workspaces/${workspaceId}/icon`, {
312
+ method: 'PUT',
313
+ headers: { 'Content-Type': blob.type || 'application/octet-stream' },
314
+ body: blob
315
+ })
316
+ if (!res.ok) throw new Error(await res.text())
317
+ return res.json()
318
+ },
319
+ onSuccess: () => {
320
+ qc.invalidateQueries({ queryKey: workspaceKeys.layout(workspaceId) })
321
+ qc.invalidateQueries({ queryKey: workspaceKeys.all })
322
+ }
323
+ })
324
+ }
325
+
326
+ // Reset the icon back to the provider default.
327
+ export function useResetWorkspaceIcon(workspaceId: string) {
328
+ const qc = useQueryClient()
329
+ return useMutation<void, Error, void>({
330
+ mutationFn: async () => {
331
+ const res = await fetch(`/api/workspaces/${workspaceId}/icon`, { method: 'DELETE' })
332
+ if (!res.ok) throw new Error('Failed to reset icon')
333
+ },
334
+ onSuccess: () => {
335
+ qc.invalidateQueries({ queryKey: workspaceKeys.layout(workspaceId) })
336
+ qc.invalidateQueries({ queryKey: workspaceKeys.all })
337
+ }
338
+ })
339
+ }
340
+
113
341
  // CC / OpenClaw directories found on the machine but not yet registered.
114
342
  export function useDiscoveredWorkspaces() {
115
343
  return useQuery<DiscoveredWorkspace[]>({
@@ -129,6 +357,9 @@ export function useAddWorkspace() {
129
357
  headers: { 'Content-Type': 'application/json' },
130
358
  body: JSON.stringify(discovered)
131
359
  })
360
+ // The server provisions (skills + `.moi/`) before registering, so a
361
+ // failure comes back as a plain-text error, not an entry.
362
+ if (!res.ok) throw new Error(await res.text())
132
363
  return res.json()
133
364
  },
134
365
  onSuccess: (entry, suggestion) => {
@@ -140,6 +371,46 @@ export function useAddWorkspace() {
140
371
  })
141
372
  }
142
373
 
374
+ // Where `/workspace/create` places new folders on disk. `displayRoot` is the
375
+ // home-relative form (e.g. "~/moi") shown in the create form.
376
+ export type CreateWorkspaceInfo = {
377
+ root: string
378
+ displayRoot: string
379
+ }
380
+
381
+ export function useCreateWorkspaceInfo() {
382
+ return useQuery<CreateWorkspaceInfo>({
383
+ queryKey: workspaceKeys.createInfo,
384
+ queryFn: () => fetch('/api/workspaces/create').then(r => r.json()),
385
+ staleTime: Infinity
386
+ })
387
+ }
388
+
389
+ export type CreateWorkspaceInput = {
390
+ name: string
391
+ type: WorkspaceType
392
+ }
393
+
394
+ // Create a brand-new workspace folder (server provisions skills + `.moi/` and
395
+ // registers it). Non-2xx responses carry a user-facing message in the body.
396
+ export function useCreateWorkspace() {
397
+ const qc = useQueryClient()
398
+ return useMutation<WorkspaceEntry, Error, CreateWorkspaceInput>({
399
+ mutationFn: async input => {
400
+ const res = await fetch('/api/workspaces/create', {
401
+ method: 'POST',
402
+ headers: { 'Content-Type': 'application/json' },
403
+ body: JSON.stringify(input)
404
+ })
405
+ if (!res.ok) throw new Error(await res.text())
406
+ return res.json()
407
+ },
408
+ onSuccess: entry => {
409
+ qc.setQueryData<WorkspaceEntry[]>(workspaceKeys.all, prev => [...(prev ?? []), entry])
410
+ }
411
+ })
412
+ }
413
+
143
414
  // Remove a workspace from the registry (re-discovery may surface it again).
144
415
  export function useRemoveWorkspace() {
145
416
  const qc = useQueryClient()
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,33 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="15.5 15.5 224.5 224.5">
2
+ <defs>
3
+ <radialGradient cy="0" cx="0.5" id="r">
4
+ <stop offset="0" stop-color="#f06b59"/>
5
+ <stop offset="1" stop-color="#df2227"/>
6
+ </radialGradient>
7
+ <radialGradient r="0.76" cy="0.3" cx="0.65" id="g">
8
+ <stop offset="0.65" stop-color="#4cb749"/>
9
+ <stop offset="1" stop-color="#388b41"/>
10
+ </radialGradient>
11
+ <radialGradient r="0.8" cy="0.25" cx="0.36" id="y">
12
+ <stop offset="0.6" stop-color="#FCD209"/>
13
+ <stop offset="0.7" stop-color="#f7c616"/>
14
+ <stop offset="1" stop-color="#bc821e"/>
15
+ </radialGradient>
16
+ <radialGradient r="1" cy="0" cx="0.5" spreadMethod="pad" id="cf">
17
+ <stop offset="0.1" stop-color="#7FB3DF"/>
18
+ <stop offset="0.9" stop-color="#0F5B94"/>
19
+ </radialGradient>
20
+ <radialGradient id="cb" r="1" cy="0" cx="0.5">
21
+ <stop offset="0" stop-color="#F6F0EE"/>
22
+ <stop offset="1" stop-color="#ddd"/>
23
+ </radialGradient>
24
+ </defs>
25
+ <path d="m198,148a70,70 0 0 0 -140,0l20,0a50,50 0 0 1 100,0" fill-opacity="0.1"/>
26
+ <circle r="45" cx="127.5" cy="127.6" fill="url(#cf)" stroke="url(#cb)" stroke-width="9" />
27
+ <path d="m228,78a112,112 0 0 0 -193,-13l45,78a50,50 0 0 1 47,-65" fill="url(#r)"/>
28
+ <path d="m35,65a112,112 0 0 0 84,174l47,-80a50,50 0 0 1 -86,-16" fill="url(#g)"/>
29
+ <path d="m119,239a112,112 0 0 0 109,-161l-101,0a50,50 0 0 1 39,81" fill="url(#y)"/>
30
+ <path d="m35,65l45,78a50,50 0 0 1 2,-34l-45,-47" opacity="0.075"/>
31
+ <path d="m119,239l47,-80a50,50 0 0 1 -29,17l-20,63" opacity="0.05"/>
32
+ <path d="m228,78l-101,0a50,50 0 0 1 39,19l64,-16" opacity="0.05"/>
33
+ </svg>
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -2,11 +2,13 @@ import { useEffect } from 'react'
2
2
 
3
3
  import { Route, Switch, useLocation } from 'wouter'
4
4
 
5
- import { setWorkspaceSwitchHandler } from '@/client/lib/ws'
5
+ import { setWorkspaceSwitchHandler } from '@/client/lib/connection'
6
6
 
7
7
  import { HomePage } from './HomePage'
8
8
  import { PlaygroundPage } from './playground/PlaygroundPage'
9
+ import { ToolCallsPage } from './playground/ToolCallsPage'
9
10
  import { WorkspaceRoute } from './routes/workspace/[id]'
11
+ import { CreateWorkspacePage } from './routes/workspace/create'
10
12
 
11
13
  // Top-level router — sets up all client-side routes
12
14
  export function AppRouter() {
@@ -22,7 +24,11 @@ export function AppRouter() {
22
24
  return (
23
25
  <Switch>
24
26
  <Route path="/" component={HomePage} />
27
+ <Route path="/playground/tool-calls" component={ToolCallsPage} />
25
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} />
26
32
  <Route path="/workspace/:id">
27
33
  {/* Key by id so switching workspaces mounts a fresh subtree — the
28
34
  per-workspace chat store (and its websocket) tears down and resets