moi-computer 0.0.2 → 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 (246) hide show
  1. package/bin/moi.mjs +3 -1
  2. package/bunfig.toml +4 -0
  3. package/client/api/workspaces.ts +277 -6
  4. package/client/assets/mcp/agentation.png +0 -0
  5. package/client/assets/mcp/airtable.png +0 -0
  6. package/client/assets/mcp/apollo.png +0 -0
  7. package/client/assets/mcp/asana.png +0 -0
  8. package/client/assets/mcp/box.png +0 -0
  9. package/client/assets/mcp/chrome.svg +33 -0
  10. package/client/assets/mcp/clickup.png +0 -0
  11. package/client/assets/mcp/cloudflare.png +0 -0
  12. package/client/assets/mcp/context7.png +0 -0
  13. package/client/assets/mcp/datadog.png +0 -0
  14. package/client/assets/mcp/dropbox.png +0 -0
  15. package/client/assets/mcp/elevenlabs.png +0 -0
  16. package/client/assets/mcp/exa.png +0 -0
  17. package/client/assets/mcp/firecrawl.png +0 -0
  18. package/client/assets/mcp/gmail.png +0 -0
  19. package/client/assets/mcp/googlecalendar.png +0 -0
  20. package/client/assets/mcp/googledrive.png +0 -0
  21. package/client/assets/mcp/grafana.png +0 -0
  22. package/client/assets/mcp/huggingface.png +0 -0
  23. package/client/assets/mcp/intercom.png +0 -0
  24. package/client/assets/mcp/monday.png +0 -0
  25. package/client/assets/mcp/mongodb.png +0 -0
  26. package/client/assets/mcp/paper.png +0 -0
  27. package/client/assets/mcp/paypal.png +0 -0
  28. package/client/assets/mcp/perplexity.png +0 -0
  29. package/client/assets/mcp/postgresql.png +0 -0
  30. package/client/assets/mcp/posthog.png +0 -0
  31. package/client/assets/mcp/puppeteer.png +0 -0
  32. package/client/assets/mcp/railway.png +0 -0
  33. package/client/assets/mcp/redis.png +0 -0
  34. package/client/assets/mcp/salesforce.png +0 -0
  35. package/client/assets/mcp/shopify.png +0 -0
  36. package/client/assets/mcp/snowflake.png +0 -0
  37. package/client/assets/mcp/telegram.png +0 -0
  38. package/client/assets/mcp/twilio.png +0 -0
  39. package/client/assets/mcp/zapier.png +0 -0
  40. package/client/components/App.tsx +7 -1
  41. package/client/components/BottomPanel.tsx +2 -2
  42. package/client/components/ChatInput.tsx +195 -14
  43. package/client/components/ChatPanel.tsx +118 -49
  44. package/client/components/ChatPopup.tsx +2 -2
  45. package/client/components/CustomizePanel.tsx +8 -8
  46. package/client/components/HiddenPanel.tsx +1 -1
  47. package/client/components/HomePage.tsx +1 -1
  48. package/client/components/IconMcp.tsx +21 -0
  49. package/client/components/MarkdownContent.tsx +2 -2
  50. package/client/components/McpMenu.tsx +125 -0
  51. package/client/components/ModelPicker.tsx +147 -0
  52. package/client/components/Scratchpad.tsx +775 -0
  53. package/client/components/ShimmerText.tsx +20 -0
  54. package/client/components/ThreadSelector.tsx +2 -2
  55. package/client/components/TurnView.tsx +114 -534
  56. package/client/components/WidgetErrorBoundary.tsx +2 -2
  57. package/client/components/WidgetFrame.tsx +1 -1
  58. package/client/components/WidgetShell.tsx +2 -2
  59. package/client/components/Widgets.tsx +2 -2
  60. package/client/components/WorkspacePreview.tsx +3 -3
  61. package/client/components/WorkspacesPage.tsx +28 -20
  62. package/client/components/layout/SidebarLayout.tsx +24 -15
  63. package/client/components/playground/PixelPainter.tsx +2 -2
  64. package/client/components/playground/PlaygroundPage.tsx +1 -1
  65. package/client/components/playground/ToolCallsPage.tsx +81 -0
  66. package/client/components/routes/workspace/[id].tsx +534 -141
  67. package/client/components/routes/workspace/create.tsx +155 -0
  68. package/client/components/settings/IconPicker.tsx +590 -0
  69. package/client/components/settings/SettingsPages.tsx +307 -0
  70. package/client/components/settings/WorkspaceSettings.tsx +92 -0
  71. package/client/components/tool-group/CodeBlock.tsx +41 -0
  72. package/client/components/tool-group/Collapse.tsx +28 -0
  73. package/client/components/tool-group/ReadImagePreview.tsx +46 -0
  74. package/client/components/tool-group/SubagentCard.tsx +135 -0
  75. package/client/components/tool-group/TimelineRow.tsx +147 -0
  76. package/client/components/tool-group/ToolCallGroup.tsx +231 -0
  77. package/client/components/tool-group/ToolOutput.tsx +139 -0
  78. package/client/components/tool-group/detect.ts +93 -0
  79. package/client/components/tool-group/fixtures.ts +315 -0
  80. package/client/components/tool-group/format.ts +211 -0
  81. package/client/components/tool-group/index.ts +9 -0
  82. package/client/components/ui/button.tsx +4 -4
  83. package/client/components/ui/dialog.tsx +58 -0
  84. package/client/components/ui/dropdown-menu.tsx +9 -9
  85. package/client/components/ui/hover-card.tsx +44 -0
  86. package/client/components/ui/popover.tsx +1 -1
  87. package/client/components/ui/switch.tsx +23 -0
  88. package/client/components/ui/tooltip.tsx +54 -0
  89. package/client/externalize-react.ts +11 -5
  90. package/client/hooks/useApplet.ts +117 -0
  91. package/client/hooks/useChat.ts +162 -62
  92. package/client/hooks/useMeiEvents.ts +9 -2
  93. package/client/hooks/useStickToBottom.ts +86 -0
  94. package/client/hooks/useWorkspaceTheme.ts +8 -2
  95. package/client/index.css +49 -3
  96. package/client/index.html +22 -18
  97. package/client/index.tsx +29 -2
  98. package/client/lib/WorkspaceContext.tsx +5 -8
  99. package/client/lib/WorkspaceLayoutContext.tsx +30 -10
  100. package/client/lib/applet-cache.ts +54 -0
  101. package/client/lib/connection.ts +237 -0
  102. package/client/lib/flags.ts +10 -0
  103. package/client/lib/mcp-icons.ts +142 -10
  104. package/client/lib/preview-turn.ts +37 -0
  105. package/client/lib/render-icon.ts +173 -0
  106. package/client/lib/scratch-executor.ts +20 -0
  107. package/client/lib/uploads.ts +18 -0
  108. package/client/main.tsx +5 -0
  109. package/client/store/live.ts +282 -0
  110. package/client/structured-clone-shim.ts +14 -0
  111. package/client/theme.css +2 -2
  112. package/client/vendor/emojibase/en/data.json +1 -0
  113. package/client/vendor/emojibase/en/messages.json +1 -0
  114. package/client/vendor/react/development/_impl/react-dom-client.js +15871 -0
  115. package/client/vendor/react/development/_impl/react-dom.js +223 -0
  116. package/client/vendor/react/development/_impl/react-jsx-dev-runtime.js +256 -0
  117. package/client/vendor/react/development/_impl/react-jsx-runtime.js +260 -0
  118. package/client/vendor/react/development/_impl/react.js +863 -0
  119. package/client/vendor/react/development/react-dom-client.js +6 -0
  120. package/client/vendor/react/development/react-dom.js +17 -0
  121. package/client/vendor/react/development/react-jsx-dev-runtime.js +5 -0
  122. package/client/vendor/react/development/react-jsx-runtime.js +6 -0
  123. package/client/vendor/react/development/react.js +47 -0
  124. package/client/vendor/react/production/_impl/react-dom-client.js +10361 -0
  125. package/client/vendor/react/production/_impl/react-dom.js +184 -0
  126. package/client/vendor/react/production/_impl/react-jsx-dev-runtime.js +37 -0
  127. package/client/vendor/react/production/_impl/react-jsx-runtime.js +60 -0
  128. package/client/vendor/react/production/_impl/react.js +428 -0
  129. package/client/vendor/react/production/react-dom-client.js +6 -0
  130. package/client/vendor/react/production/react-dom.js +17 -0
  131. package/client/vendor/react/production/react-jsx-dev-runtime.js +5 -0
  132. package/client/vendor/react/production/react-jsx-runtime.js +6 -0
  133. package/client/vendor/react/production/react.js +47 -0
  134. package/dist/agentation-4s0nn45p.png +0 -0
  135. package/dist/airtable-hsa66v6q.png +0 -0
  136. package/dist/apollo-2ed5dy2d.png +0 -0
  137. package/dist/asana-tvgtwbx2.png +0 -0
  138. package/dist/atlassian-b3tq39hs.png +0 -0
  139. package/dist/box-w3n36t5g.png +0 -0
  140. package/dist/chrome-tspm94rw.svg +33 -0
  141. package/dist/chunk-kc6e9nd4.css +1 -0
  142. package/dist/chunk-yf3p7qg7.js +673 -0
  143. package/dist/claude-z2xnay0d.svg +3 -0
  144. package/dist/clickup-qqrqqvqb.png +0 -0
  145. package/dist/cloudflare-j9p931v6.png +0 -0
  146. package/dist/context7-8ht0xjfy.png +0 -0
  147. package/dist/datadog-70ne3yzt.png +0 -0
  148. package/dist/discord-vejhptwx.png +0 -0
  149. package/dist/dropbox-4m5s9mgr.png +0 -0
  150. package/dist/elevenlabs-2nzzej1t.png +0 -0
  151. package/dist/exa-qqj3vr0x.png +0 -0
  152. package/dist/favicon-nbmyjfjh.png +0 -0
  153. package/dist/figma-y9898rry.png +0 -0
  154. package/dist/firecrawl-w2t8nehx.png +0 -0
  155. package/dist/github-av5r5y3e.png +0 -0
  156. package/dist/gitlab-4pv5vm6b.png +0 -0
  157. package/dist/gmail-sg6a5v3x.png +0 -0
  158. package/dist/googlecalendar-nqhh2v7r.png +0 -0
  159. package/dist/googledrive-6s8xyab7.png +0 -0
  160. package/dist/grafana-1yfsnwr6.png +0 -0
  161. package/dist/granola-7j3b0nk2.png +0 -0
  162. package/dist/hermes-nous-pznd63x9.png +0 -0
  163. package/dist/hubspot-hghcmc2t.png +0 -0
  164. package/dist/huggingface-kxzaxj83.png +0 -0
  165. package/dist/index.html +47 -0
  166. package/dist/intercom-td763jt8.png +0 -0
  167. package/dist/linear-v9s3az2d.png +0 -0
  168. package/dist/monday-jdbs4wwf.png +0 -0
  169. package/dist/mongodb-emzxvhd5.png +0 -0
  170. package/dist/neon-zj4qar44.png +0 -0
  171. package/dist/notion-w034c0b8.png +0 -0
  172. package/dist/openclaw-a2pyfhpn.svg +22 -0
  173. package/dist/paper-zbt34fab.png +0 -0
  174. package/dist/paypal-kwwf7xsc.png +0 -0
  175. package/dist/perplexity-4y63rxvj.png +0 -0
  176. package/dist/postgresql-qsspbsr1.png +0 -0
  177. package/dist/posthog-sphppc4w.png +0 -0
  178. package/dist/puppeteer-2xjt1a9b.png +0 -0
  179. package/dist/railway-834de8d2.png +0 -0
  180. package/dist/redis-spm6w2m1.png +0 -0
  181. package/dist/salesforce-1mk56v4z.png +0 -0
  182. package/dist/sentry-hdwpmvek.png +0 -0
  183. package/dist/shopify-90dadaav.png +0 -0
  184. package/dist/slack-1c1wj62s.png +0 -0
  185. package/dist/snowflake-hfpykpgy.png +0 -0
  186. package/dist/stripe-zrfaqbj3.png +0 -0
  187. package/dist/supabase-4vg33zf2.png +0 -0
  188. package/dist/telegram-v6tjyrs7.png +0 -0
  189. package/dist/twilio-dpyjdwpj.png +0 -0
  190. package/dist/vercel-7d0ssw28.png +0 -0
  191. package/dist/zapier-p67qfch0.png +0 -0
  192. package/lib/attachment-note.ts +48 -0
  193. package/lib/claude-adapter.ts +219 -29
  194. package/lib/format.ts +32 -0
  195. package/lib/types.ts +314 -6
  196. package/package.json +21 -31
  197. package/server/CLAUDE.md +3 -0
  198. package/server/agent.ts +25 -118
  199. package/server/api.ts +593 -0
  200. package/server/applets.ts +396 -0
  201. package/server/build-applet.ts +580 -0
  202. package/server/cc-session.ts +611 -0
  203. package/server/cli-colors.ts +17 -0
  204. package/server/cli-ui.ts +52 -0
  205. package/server/cli.ts +970 -72
  206. package/server/control.ts +166 -19
  207. package/server/debug.ts +10 -0
  208. package/server/events.ts +24 -0
  209. package/server/functions-worker.ts +18 -2
  210. package/server/functions.ts +59 -12
  211. package/server/icon.ts +13 -0
  212. package/server/layout.ts +25 -3
  213. package/server/mcp.ts +125 -0
  214. package/server/moi-scaffold.ts +85 -0
  215. package/server/openclaw-session.ts +41 -10
  216. package/server/openclaw.ts +22 -0
  217. package/server/preview.ts +70 -0
  218. package/server/registry.ts +32 -2
  219. package/server/scratchpad-executor.ts +380 -0
  220. package/server/scratchpad-relay.ts +45 -0
  221. package/server/scratchpad.ts +171 -0
  222. package/server/skill-version.ts +146 -0
  223. package/server/skills-template.ts +6 -1
  224. package/server/state.ts +22 -36
  225. package/server/static.ts +23 -0
  226. package/server/status.ts +94 -0
  227. package/server/thread-config.ts +125 -0
  228. package/server/uploads.ts +0 -0
  229. package/server/vendor.ts +63 -0
  230. package/server/views.ts +0 -0
  231. package/server/web.ts +113 -223
  232. package/server/widgets.ts +52 -142
  233. package/server/workspace-config.ts +37 -0
  234. package/server/workspace-env.ts +407 -0
  235. package/server/workspace-init.ts +66 -0
  236. package/workspace/.claude/skills/moi-workspace/DESIGN.md +109 -0
  237. package/workspace/.claude/skills/moi-workspace/SCRATCHPAD.md +57 -0
  238. package/workspace/.claude/skills/moi-workspace/SKILL.md +252 -0
  239. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +22 -0
  240. package/client/hooks/useWidget.ts +0 -72
  241. package/client/hooks/useWidgetList.ts +0 -30
  242. package/client/lib/ws.ts +0 -129
  243. package/client/store/chat.tsx +0 -162
  244. package/server/build-widget.ts +0 -343
  245. package/workspace/.claude/skills/widgets/DESIGN.md +0 -630
  246. package/workspace/.claude/skills/widgets/SKILL.md +0 -176
@@ -0,0 +1,237 @@
1
+ import type { QueryClient } from '@tanstack/react-query'
2
+
3
+ import { workspaceKeys } from '@/client/api/workspaces'
4
+ import { getScratchExecutor } from '@/client/lib/scratch-executor'
5
+ import { liveStore } from '@/client/store/live'
6
+ import { applyEvent } from '@/lib/format'
7
+ import type {
8
+ ClientMessage,
9
+ PreviewFrame,
10
+ ScratchOp,
11
+ StreamEvent,
12
+ ThreadConfig,
13
+ ViewState
14
+ } from '@/lib/types'
15
+
16
+ // App-wide chat connection: ONE WebSocket for the whole client, opened once at
17
+ // startup and never torn down on navigation. Every server frame is tagged with
18
+ // `workspaceId`, so a single socket serves every workspace and the client routes
19
+ // each frame to the right `(workspaceId, sessionId)` slice — live transcript
20
+ // deltas into the React Query cache, status/error/rename into the live store.
21
+ //
22
+ // Socket identity is tracked by a monotonic `generation`: each socket captures
23
+ // the generation at creation and every callback bails if it's no longer current,
24
+ // so a delayed close/open from a superseded socket can't corrupt live state.
25
+
26
+ let qc: QueryClient | null = null
27
+ let socket: WebSocket | null = null
28
+ let generation = 0
29
+ let reconnectTimer: ReturnType<typeof setTimeout> | null = null
30
+ const queue: ClientMessage[] = []
31
+ let onWorkspaceSwitch: ((workspaceId: string) => void) | null = null
32
+ let sweepTimer: ReturnType<typeof setInterval> | null = null
33
+
34
+ // TTL backstop for live previews. Every clear path (turn arrival, run end,
35
+ // reconnect) is exact and should fire first; this only reaps a preview whose
36
+ // clear was somehow missed, so it can be generous.
37
+ const PREVIEW_TTL_MS = 15_000
38
+
39
+ export function initConnection(queryClient: QueryClient) {
40
+ qc = queryClient
41
+ if (!sweepTimer) {
42
+ sweepTimer = setInterval(
43
+ () => liveStore.getState().sweepPreviews(PREVIEW_TTL_MS, Date.now()),
44
+ 5_000
45
+ )
46
+ }
47
+ if (socket) return // already connected (mount/StrictMode re-invoke safety)
48
+ connect()
49
+ }
50
+
51
+ function connect() {
52
+ const myGen = ++generation
53
+ if (reconnectTimer) {
54
+ clearTimeout(reconnectTimer)
55
+ reconnectTimer = null
56
+ }
57
+
58
+ const s = new WebSocket(`ws://${location.host}/ws`)
59
+ socket = s
60
+
61
+ s.onopen = () => {
62
+ if (generation !== myGen) {
63
+ s.close()
64
+ return
65
+ }
66
+ for (const m of queue) s.send(JSON.stringify(m))
67
+ queue.length = 0
68
+ // Heal any deltas missed while disconnected: refetch every live transcript.
69
+ // No-op on the first connect (nothing cached yet).
70
+ qc?.invalidateQueries({ queryKey: ['workspaces', 'events'] })
71
+ // Any in-flight preview from before the drop is superseded by that refetch
72
+ // (which returns the authoritative disk state) — drop them all so a frozen
73
+ // half-streamed preview can't linger over the healed transcript.
74
+ liveStore.getState().clearAllPreviews()
75
+ }
76
+
77
+ s.onmessage = e => {
78
+ if (generation !== myGen) return
79
+ let data: unknown
80
+ try {
81
+ data = JSON.parse(e.data)
82
+ } catch {
83
+ return
84
+ }
85
+ handleFrame(data as Record<string, unknown>)
86
+ }
87
+
88
+ s.onclose = () => {
89
+ if (generation !== myGen) return
90
+ socket = null
91
+ reconnectTimer = setTimeout(connect, 1000)
92
+ }
93
+
94
+ s.onerror = () => s.close()
95
+ }
96
+
97
+ export function handleFrame(data: Record<string, unknown>) {
98
+ const store = liveStore.getState()
99
+
100
+ // Control frames first.
101
+ if (data.type === 'status_snapshot') {
102
+ store.reconcileProcessing(
103
+ (data.running as { workspaceId: string; sessionId: string }[] | undefined) ?? []
104
+ )
105
+ return
106
+ }
107
+ if (data.type === 'status') {
108
+ const workspaceId = data.workspaceId as string
109
+ const sessionId = data.sessionId as string
110
+ const processing = data.processing as boolean
111
+ store.setProcessing(workspaceId, sessionId, processing)
112
+ // Run fully ended → any leftover preview for this session is stale (its
113
+ // finalized turns already arrived). Belt for a per-message clear that was
114
+ // missed (e.g. a turn that carried no apiMessageId).
115
+ if (!processing) store.clearPreviewsForSession(workspaceId, sessionId)
116
+ return
117
+ }
118
+ if (data.type === 'preview') {
119
+ const frame = data as unknown as PreviewFrame
120
+ // Only hold previews for a thread whose transcript is loaded (mirrors
121
+ // patchView): keeps the store bounded and never renders a preview over a
122
+ // history-less background session that would then never refetch.
123
+ const key = workspaceKeys.events(frame.workspaceId, frame.sessionId)
124
+ if (qc?.getQueryData(key) === undefined) return
125
+ store.setPreview({
126
+ workspaceId: frame.workspaceId,
127
+ sessionId: frame.sessionId,
128
+ messageId: frame.messageId,
129
+ parentToolUseId: frame.parentToolUseId,
130
+ blocks: frame.blocks
131
+ })
132
+ return
133
+ }
134
+ if (data.type === 'session_renamed') {
135
+ const workspaceId = data.workspaceId as string
136
+ const from = data.from as string
137
+ const to = data.to as string
138
+ store.renameSession(workspaceId, from, to)
139
+ // Move the cached transcript from the client's temp id to the real one.
140
+ const prev = qc?.getQueryData<ViewState>(workspaceKeys.events(workspaceId, from))
141
+ if (prev !== undefined) {
142
+ qc?.setQueryData(workspaceKeys.events(workspaceId, to), prev)
143
+ qc?.removeQueries({ queryKey: workspaceKeys.events(workspaceId, from) })
144
+ }
145
+ // Likewise move any per-thread config the picker wrote under the temp id, so
146
+ // a model/effort change made before the rename lands isn't stranded. The
147
+ // server migrates the stored config in renameSession to match.
148
+ const cfg = qc?.getQueryData<ThreadConfig>(workspaceKeys.threadConfig(workspaceId, from))
149
+ if (cfg !== undefined) {
150
+ qc?.setQueryData(workspaceKeys.threadConfig(workspaceId, to), cfg)
151
+ qc?.removeQueries({ queryKey: workspaceKeys.threadConfig(workspaceId, from) })
152
+ }
153
+ // The real id now exists on disk — refresh the thread list so it appears.
154
+ qc?.invalidateQueries({ queryKey: workspaceKeys.sessions(workspaceId) })
155
+ return
156
+ }
157
+ if (data.type === 'workspace:switch') {
158
+ onWorkspaceSwitch?.(data.workspaceId as string)
159
+ return
160
+ }
161
+
162
+ // A relayed Scratchpad op from `moi scratch`. Only run it if THIS tab has a
163
+ // live editor for that workspace; otherwise ignore (another tab — or none —
164
+ // handles it, and the server times out if no tab answers). Ids are
165
+ // deterministic, so if several tabs run it they converge; first reply wins.
166
+ if (data.type === 'scratchpad:op') {
167
+ const run = getScratchExecutor(data.workspaceId as string)
168
+ if (!run) return
169
+ const opId = data.opId as string
170
+ run(data.op as ScratchOp).then(
171
+ result => sendMessage({ type: 'scratchpad:op-result', opId, result }),
172
+ err =>
173
+ sendMessage({
174
+ type: 'scratchpad:op-result',
175
+ opId,
176
+ error: err instanceof Error ? err.message : String(err)
177
+ })
178
+ )
179
+ return
180
+ }
181
+
182
+ // StreamEvent frames — tagged with workspaceId + sessionId.
183
+ const workspaceId = data.workspaceId as string | undefined
184
+ const sessionId = data.sessionId as string | undefined
185
+ if (!workspaceId || !sessionId) return
186
+ const kind = data.kind
187
+
188
+ if (kind === 'snapshot' || kind === 'turn' || kind === 'notice' || kind === 'result') {
189
+ patchView(workspaceId, sessionId, data as unknown as StreamEvent)
190
+ // The real turn superseding a live preview is the clean handoff: drop the
191
+ // preview for that exact message id the instant its finalized turn lands, so
192
+ // there's no double-render and no flicker (both updates commit together).
193
+ if (kind === 'turn') {
194
+ const mid = (data as unknown as { turn?: { meta?: { apiMessageId?: string } } }).turn?.meta
195
+ ?.apiMessageId
196
+ if (mid) store.clearPreview(mid)
197
+ }
198
+ // A `result` ends the turn — sweep any preview that never got an exact clear.
199
+ if (kind === 'result') store.clearPreviewsForSession(workspaceId, sessionId)
200
+ }
201
+ if (kind === 'error' && typeof data.content === 'string') {
202
+ store.setError(workspaceId, sessionId, data.content)
203
+ store.clearPreviewsForSession(workspaceId, sessionId)
204
+ }
205
+ if (kind === 'stopped') {
206
+ store.setProcessing(workspaceId, sessionId, false)
207
+ store.clearPreviewsForSession(workspaceId, sessionId)
208
+ }
209
+ }
210
+
211
+ // Fold a delta into a thread's cached transcript — but only if that transcript
212
+ // is already loaded/primed. A never-viewed background session has no cache
213
+ // entry; we deliberately skip it so a stray mid-run delta can't seed a partial,
214
+ // history-less view that would then never refetch. It loads in full from disk
215
+ // when the user actually opens it.
216
+ function patchView(workspaceId: string, sessionId: string, ev: StreamEvent) {
217
+ const queryKey = workspaceKeys.events(workspaceId, sessionId)
218
+ const existing = qc?.getQueryData<ViewState>(queryKey)
219
+ if (existing === undefined) return
220
+ qc?.setQueryData<ViewState>(queryKey, applyEvent(existing, ev))
221
+ }
222
+
223
+ export function sendMessage(msg: ClientMessage) {
224
+ if (socket && socket.readyState === WebSocket.OPEN) socket.send(JSON.stringify(msg))
225
+ else queue.push(msg)
226
+ }
227
+
228
+ export function setWorkspaceSwitchHandler(fn: ((workspaceId: string) => void) | null) {
229
+ onWorkspaceSwitch = fn
230
+ }
231
+
232
+ // Test seam: inject the QueryClient the frame handler reads, without opening a
233
+ // socket (the browser-only `connect()` path). Production always goes through
234
+ // `initConnection`.
235
+ export function __setQueryClientForTests(client: QueryClient | null) {
236
+ qc = client
237
+ }
@@ -0,0 +1,10 @@
1
+ // Personal / dev feature flags — flip these in code, not in the UI.
2
+ //
3
+ // These are compile-time constants (inlined into the client bundle), not
4
+ // per-thread or per-workspace settings. Change one and rebuild the client.
5
+
6
+ // Live token-by-token streaming of assistant responses. When true, the client
7
+ // asks the server to stream partial messages (only honored by providers that
8
+ // report `supportsStreaming` — Claude Code; ignored elsewhere). When false,
9
+ // responses arrive as whole blocks, exactly as before streaming existed.
10
+ export const STREAM_RESPONSES = true
@@ -1,53 +1,185 @@
1
1
  // Icons for known MCP servers. Logos under `client/assets/mcp/` are pulled
2
2
  // from logo.dev (free pk_ token) — drop a new `<server>.png` into the folder
3
- // and add an import + map entry below.
3
+ // and add an import + map entry below. Google product icons (Gmail/Drive/
4
+ // Calendar) come from the official gstatic product art since logo.dev only
5
+ // resolves company domains, not per-product brands. A few are SVG (e.g.
6
+ // `chrome.svg`) — Bun resolves both `.png` and `.svg` imports to a URL string.
4
7
  //
5
8
  // Server name lookup is case-insensitive so `Notion`, `notion`, and `NOTION`
6
- // all resolve. Unknown servers fall back to a generic tabler icon — see
9
+ // all resolve. Claude-hosted MCPs arrive prefixed (`claude.ai Google Drive`) —
10
+ // that prefix is stripped before lookup so the underlying service resolves.
11
+ // Unknown servers fall back to a generic tabler icon — see
7
12
  // `client/components/TurnView.tsx`.
13
+ import agentationIcon from '@/client/assets/mcp/agentation.png'
14
+ import airtableIcon from '@/client/assets/mcp/airtable.png'
15
+ import apolloIcon from '@/client/assets/mcp/apollo.png'
16
+ import asanaIcon from '@/client/assets/mcp/asana.png'
8
17
  import atlassianIcon from '@/client/assets/mcp/atlassian.png'
18
+ import boxIcon from '@/client/assets/mcp/box.png'
19
+ import chromeIcon from '@/client/assets/mcp/chrome.svg'
20
+ import clickupIcon from '@/client/assets/mcp/clickup.png'
21
+ import cloudflareIcon from '@/client/assets/mcp/cloudflare.png'
22
+ import context7Icon from '@/client/assets/mcp/context7.png'
23
+ import datadogIcon from '@/client/assets/mcp/datadog.png'
9
24
  import discordIcon from '@/client/assets/mcp/discord.png'
25
+ import dropboxIcon from '@/client/assets/mcp/dropbox.png'
26
+ import elevenlabsIcon from '@/client/assets/mcp/elevenlabs.png'
27
+ import exaIcon from '@/client/assets/mcp/exa.png'
10
28
  import figmaIcon from '@/client/assets/mcp/figma.png'
29
+ import firecrawlIcon from '@/client/assets/mcp/firecrawl.png'
11
30
  import githubIcon from '@/client/assets/mcp/github.png'
12
31
  import gitlabIcon from '@/client/assets/mcp/gitlab.png'
32
+ import gmailIcon from '@/client/assets/mcp/gmail.png'
33
+ import googlecalendarIcon from '@/client/assets/mcp/googlecalendar.png'
34
+ import googledriveIcon from '@/client/assets/mcp/googledrive.png'
35
+ import grafanaIcon from '@/client/assets/mcp/grafana.png'
13
36
  import granolaIcon from '@/client/assets/mcp/granola.png'
14
37
  import hubspotIcon from '@/client/assets/mcp/hubspot.png'
38
+ import huggingfaceIcon from '@/client/assets/mcp/huggingface.png'
39
+ import intercomIcon from '@/client/assets/mcp/intercom.png'
15
40
  import linearIcon from '@/client/assets/mcp/linear.png'
41
+ import mondayIcon from '@/client/assets/mcp/monday.png'
42
+ import mongodbIcon from '@/client/assets/mcp/mongodb.png'
16
43
  import neonIcon from '@/client/assets/mcp/neon.png'
17
44
  import notionIcon from '@/client/assets/mcp/notion.png'
45
+ import paperIcon from '@/client/assets/mcp/paper.png'
46
+ import paypalIcon from '@/client/assets/mcp/paypal.png'
47
+ import perplexityIcon from '@/client/assets/mcp/perplexity.png'
48
+ import postgresqlIcon from '@/client/assets/mcp/postgresql.png'
49
+ import posthogIcon from '@/client/assets/mcp/posthog.png'
50
+ import puppeteerIcon from '@/client/assets/mcp/puppeteer.png'
51
+ import railwayIcon from '@/client/assets/mcp/railway.png'
52
+ import redisIcon from '@/client/assets/mcp/redis.png'
53
+ import salesforceIcon from '@/client/assets/mcp/salesforce.png'
18
54
  import sentryIcon from '@/client/assets/mcp/sentry.png'
55
+ import shopifyIcon from '@/client/assets/mcp/shopify.png'
19
56
  import slackIcon from '@/client/assets/mcp/slack.png'
57
+ import snowflakeIcon from '@/client/assets/mcp/snowflake.png'
20
58
  import stripeIcon from '@/client/assets/mcp/stripe.png'
21
59
  import supabaseIcon from '@/client/assets/mcp/supabase.png'
60
+ import telegramIcon from '@/client/assets/mcp/telegram.png'
61
+ import twilioIcon from '@/client/assets/mcp/twilio.png'
22
62
  import vercelIcon from '@/client/assets/mcp/vercel.png'
63
+ import zapierIcon from '@/client/assets/mcp/zapier.png'
23
64
 
24
65
  const ICONS: Record<string, string> = {
66
+ agentation: agentationIcon,
67
+ airtable: airtableIcon,
68
+ apollo: apolloIcon,
69
+ asana: asanaIcon,
25
70
  atlassian: atlassianIcon,
71
+ box: boxIcon,
72
+ chrome: chromeIcon,
73
+ 'chrome-devtools': chromeIcon,
74
+ clickup: clickupIcon,
75
+ cloudflare: cloudflareIcon,
76
+ context7: context7Icon,
77
+ datadog: datadogIcon,
26
78
  discord: discordIcon,
79
+ dropbox: dropboxIcon,
80
+ elevenlabs: elevenlabsIcon,
81
+ exa: exaIcon,
27
82
  figma: figmaIcon,
83
+ firecrawl: firecrawlIcon,
28
84
  github: githubIcon,
29
85
  gitlab: gitlabIcon,
86
+ gmail: gmailIcon,
87
+ googlecalendar: googlecalendarIcon,
88
+ googledrive: googledriveIcon,
89
+ grafana: grafanaIcon,
30
90
  granola: granolaIcon,
31
91
  hubspot: hubspotIcon,
92
+ huggingface: huggingfaceIcon,
93
+ intercom: intercomIcon,
32
94
  linear: linearIcon,
95
+ monday: mondayIcon,
96
+ mongodb: mongodbIcon,
33
97
  neon: neonIcon,
34
98
  notion: notionIcon,
99
+ paper: paperIcon,
100
+ paypal: paypalIcon,
101
+ perplexity: perplexityIcon,
102
+ postgresql: postgresqlIcon,
103
+ posthog: posthogIcon,
104
+ puppeteer: puppeteerIcon,
105
+ railway: railwayIcon,
106
+ redis: redisIcon,
107
+ salesforce: salesforceIcon,
35
108
  sentry: sentryIcon,
109
+ shopify: shopifyIcon,
36
110
  slack: slackIcon,
111
+ snowflake: snowflakeIcon,
37
112
  stripe: stripeIcon,
38
113
  supabase: supabaseIcon,
39
- vercel: vercelIcon
114
+ telegram: telegramIcon,
115
+ twilio: twilioIcon,
116
+ vercel: vercelIcon,
117
+ zapier: zapierIcon
40
118
  }
41
119
 
120
+ // Display/server names that don't equal their icon key. Keyed by the lowercased
121
+ // service name (after the `claude.ai ` prefix is stripped).
122
+ const ALIASES: Record<string, string> = {
123
+ 'google drive': 'googledrive',
124
+ 'google calendar': 'googlecalendar',
125
+ gcal: 'googlecalendar',
126
+ gdrive: 'googledrive',
127
+ 'apollo.io': 'apollo',
128
+ 'paper-desktop': 'paper',
129
+ 'granola-mcp': 'granola',
130
+ 'claude-in-chrome': 'chrome',
131
+ postgres: 'postgresql',
132
+ 'hugging face': 'huggingface',
133
+ jira: 'atlassian',
134
+ confluence: 'atlassian'
135
+ }
136
+
137
+ // Strip the `claude.ai` host prefix that Claude-hosted MCPs carry, leaving the
138
+ // bare service name so the icon/label resolve to the real provider. Two forms:
139
+ // - spaced `claude.ai Google Drive` (adapter display name)
140
+ // - encoded `claude_ai_Google_Drive` (Claude Code tool name, where the
141
+ // server is `mcp__claude_ai_<Server>__<tool>` and underscores stand in for
142
+ // spaces/dots in the service name)
143
+ // For the encoded form, turn the separator underscores back into spaces so the
144
+ // bare name matches `ICONS`/`ALIASES` (`Google_Drive` → `Google Drive`). Unknown
145
+ // services (e.g. `claude_ai_Airbed` → `Airbed`) still unwrap and fall back to a
146
+ // generic icon. Names without the prefix pass through unchanged.
147
+ function stripHostPrefix(server: string): string {
148
+ const m = server.match(/^claude[._]ai[._\s]+(.+)$/i)
149
+ if (!m) return server
150
+ return m[1].replace(/_/g, ' ')
151
+ }
152
+
153
+ // Collapse a server name to a comparison key: lowercase, drop every separator so
154
+ // the registry name and the tool-name encoding of the same server compare equal
155
+ // (`claude-in-chrome`, `Claude_in_Chrome`, `claude.in.chrome` → `claudeinchrome`).
156
+ // The same server is encoded inconsistently across surfaces (the header reads it
157
+ // from `mcpServerStatus()`, a tool call embeds it in `mcp__<server>__<tool>`), so
158
+ // matching on the raw string misses; canonicalizing makes both resolve to the
159
+ // same icon.
160
+ function canon(name: string): string {
161
+ return name.toLowerCase().replace(/[\s._-]+/g, '')
162
+ }
163
+
164
+ // Canonicalized lookups, built once from the readable maps above. Alias values
165
+ // are icon keys, so canonicalize both sides.
166
+ const ICONS_BY_CANON = new Map(Object.entries(ICONS).map(([k, v]) => [canon(k), v]))
167
+ const ALIASES_BY_CANON = new Map(Object.entries(ALIASES).map(([k, v]) => [canon(k), canon(v)]))
168
+
42
169
  export function getMcpIcon(server: string): string | undefined {
43
- return ICONS[server.toLowerCase()]
170
+ const key = canon(stripHostPrefix(server))
171
+ return ICONS_BY_CANON.get(ALIASES_BY_CANON.get(key) ?? key)
44
172
  }
45
173
 
46
- // Title-case the server name for display: `notion` → `Notion`, `granola` → `Granola`.
47
- // Names with hyphens or underscores stay readable: `my-server` → `My-Server`.
174
+ // Title-case the server name for display: `notion` → `Notion`, `granola` →
175
+ // `Granola`. Separators (`-`, `_`, `.`, spaces) all become a single space so the
176
+ // variants of one server read the same (`claude-in-chrome` and `Claude_in_Chrome`
177
+ // → `Claude In Chrome`). The Claude-hosted prefix is dropped first so
178
+ // `claude.ai Figma` / `claude_ai_Figma` show as `Figma`.
48
179
  export function formatMcpServerName(server: string): string {
49
- return server
50
- .split(/([_-])/)
51
- .map(part => (part.length > 1 ? part[0].toUpperCase() + part.slice(1) : part))
52
- .join('')
180
+ return stripHostPrefix(server)
181
+ .split(/[\s._-]+/)
182
+ .filter(Boolean)
183
+ .map(part => part[0].toUpperCase() + part.slice(1))
184
+ .join(' ')
53
185
  }
@@ -0,0 +1,37 @@
1
+ // Turns the live streaming preview into a synthetic assistant Turn so it flows
2
+ // through the SAME groupTurns + rendering pipeline as finalized turns — instead
3
+ // of being rendered by a separate component that can't merge into the current
4
+ // group. A thinking-only preview folds into the ongoing tool group (matching how
5
+ // its finalized form groups); a preview with text stands alone as its own turn.
6
+ // The moment the real turn lands, the preview is cleared and the real turn takes
7
+ // its place in the same pipeline, so the swap is seamless.
8
+ import type { LivePreview } from '@/client/store/live'
9
+ import type { Part, PreviewBlock, Turn } from '@/lib/types'
10
+
11
+ // Stable id for the synthetic live turn — keeps React's key steady across deltas
12
+ // (when it stands alone; when it merges, the group keeps the prior turn's id).
13
+ export const LIVE_PREVIEW_TURN_ID = 'live-preview'
14
+
15
+ // Map preview blocks to display parts, dropping not-yet-visible (empty) blocks so
16
+ // a just-opened block doesn't prematurely collapse the live thinking. Order is
17
+ // preserved, so reasoning-before-text folds/collapses the same as a real turn.
18
+ export function previewBlocksToParts(blocks: PreviewBlock[]): Part[] {
19
+ return blocks
20
+ .filter(b => b.text.length > 0)
21
+ .map(b =>
22
+ b.kind === 'reasoning' ? { type: 'reasoning', text: b.text } : { type: 'text', text: b.text }
23
+ )
24
+ }
25
+
26
+ // Build the synthetic turn for the current root preview, or null when there's
27
+ // nothing visible yet (the caller shows the "Thinking" dots in that case).
28
+ export function buildPreviewTurn(root: LivePreview | null): Turn | null {
29
+ const parts = previewBlocksToParts(root?.blocks ?? [])
30
+ if (parts.length === 0) return null
31
+ return {
32
+ id: LIVE_PREVIEW_TURN_ID,
33
+ role: 'assistant',
34
+ origin: { kind: 'user-input' },
35
+ parts
36
+ }
37
+ }
@@ -0,0 +1,173 @@
1
+ // Rasterizes a workspace icon (emoji or Tabler glyph, over an optional gradient
2
+ // background) into a PNG Blob, ready to PUT to `/api/workspaces/:id/icon` — the
3
+ // server normalizes it to a 128×128 WebP. Keeping everything in the existing
4
+ // image pipeline means the sidebar and header keep rendering icons as a plain
5
+ // `<img>`, with no schema change for emoji/glyph modes.
6
+
7
+ // A gradient background: a CSS-style angle (0deg = up, clockwise) and 2–3 hex
8
+ // stops, ordered light → dark. Rendered identically by the DOM preview
9
+ // (`gradientCss`) and the canvas rasterizer (`paintGradient`), both of which
10
+ // finish with a soft radial sheen for depth.
11
+ export type IconGradient = {
12
+ angle: number
13
+ stops: string[]
14
+ }
15
+
16
+ // Hand-tuned presets shown as swatches. `randomGradient()` below generates
17
+ // endless extras in the same family.
18
+ export const GRADIENT_PRESETS: { id: string; gradient: IconGradient }[] = [
19
+ { id: 'sunrise', gradient: { angle: 140, stops: ['#FFE29F', '#FFA99F', '#FF719A'] } },
20
+ { id: 'ocean', gradient: { angle: 135, stops: ['#67E8F9', '#3B82F6', '#4F46E5'] } },
21
+ { id: 'meadow', gradient: { angle: 135, stops: ['#A7F3D0', '#34D399', '#059669'] } },
22
+ { id: 'dusk', gradient: { angle: 120, stops: ['#C471F5', '#FA71CD'] } },
23
+ { id: 'midnight', gradient: { angle: 135, stops: ['#30CFD0', '#330867'] } }
24
+ ]
25
+
26
+ // OKLCH → sRGB hex. Generating in OKLCH keeps random gradients perceptually
27
+ // even — equal lightness/chroma reads equally vivid at any hue, which is what
28
+ // makes the shuffle output feel curated rather than arbitrary.
29
+ function oklchToHex(l: number, c: number, h: number): string {
30
+ const hr = (h * Math.PI) / 180
31
+ const a = c * Math.cos(hr)
32
+ const b = c * Math.sin(hr)
33
+ const l_ = (l + 0.3963377774 * a + 0.2158037573 * b) ** 3
34
+ const m_ = (l - 0.1055613458 * a - 0.0638541728 * b) ** 3
35
+ const s_ = (l - 0.0894841775 * a - 1.291485548 * b) ** 3
36
+ const channels = [
37
+ 4.0767416621 * l_ - 3.3077115913 * m_ + 0.2309699292 * s_,
38
+ -1.2684380046 * l_ + 2.6097574011 * m_ - 0.3413193965 * s_,
39
+ -0.0041960863 * l_ - 0.7034186147 * m_ + 1.707614701 * s_
40
+ ]
41
+ return `#${channels
42
+ .map(x => {
43
+ const clamped = Math.min(1, Math.max(0, x))
44
+ const srgb = clamped <= 0.0031308 ? 12.92 * clamped : 1.055 * clamped ** (1 / 2.4) - 0.055
45
+ return Math.round(srgb * 255)
46
+ .toString(16)
47
+ .padStart(2, '0')
48
+ })
49
+ .join('')}`
50
+ }
51
+
52
+ // Generate a fresh gradient: random hue, a 35–90° hue swing toward the dark
53
+ // end, light→dark diagonal. A third mid-stop drops in ~40% of the time for
54
+ // richer blends.
55
+ export function randomGradient(): IconGradient {
56
+ const hue = Math.random() * 360
57
+ const swing = (35 + Math.random() * 55) * (Math.random() < 0.5 ? -1 : 1)
58
+ const angle = Math.round(115 + Math.random() * 55)
59
+ const light = oklchToHex(0.83 + Math.random() * 0.06, 0.09 + Math.random() * 0.06, hue)
60
+ const dark = oklchToHex(0.5 + Math.random() * 0.14, 0.17 + Math.random() * 0.07, hue + swing)
61
+ if (Math.random() < 0.4) {
62
+ const mid = oklchToHex(0.7 + Math.random() * 0.05, 0.15, hue + swing / 2)
63
+ return { angle, stops: [light, mid, dark] }
64
+ }
65
+ return { angle, stops: [light, dark] }
66
+ }
67
+
68
+ // Sheen shared by the DOM preview and the canvas: a soft white radial glow off
69
+ // the top-left, like light hitting a rounded app icon.
70
+ const SHEEN_CSS =
71
+ 'radial-gradient(120% 100% at 28% 12%, rgba(255,255,255,0.32), rgba(255,255,255,0) 58%)'
72
+
73
+ // CSS `background` value for previewing a gradient in the DOM. Colors are
74
+ // runtime-generated (shuffle), so this goes through a style attribute — a
75
+ // static Tailwind class can't express it.
76
+ export function gradientCss(g: IconGradient): string {
77
+ return `${SHEEN_CSS}, linear-gradient(${g.angle}deg, ${g.stops.join(', ')})`
78
+ }
79
+
80
+ // Rendered at 2× the server's target so the downscale to 128 stays crisp.
81
+ const SIZE = 256
82
+
83
+ function paintGradient(ctx: CanvasRenderingContext2D, g: IconGradient) {
84
+ // CSS angle semantics: 0deg points up, rotating clockwise. The gradient line
85
+ // runs through the center, long enough to cover the square's projection.
86
+ const rad = (g.angle * Math.PI) / 180
87
+ const dx = Math.sin(rad)
88
+ const dy = -Math.cos(rad)
89
+ const half = (SIZE * (Math.abs(dx) + Math.abs(dy))) / 2
90
+ const c = SIZE / 2
91
+ const lin = ctx.createLinearGradient(c - dx * half, c - dy * half, c + dx * half, c + dy * half)
92
+ const last = g.stops.length - 1
93
+ g.stops.forEach((stop, i) => lin.addColorStop(last === 0 ? 0 : i / last, stop))
94
+ ctx.fillStyle = lin
95
+ ctx.fillRect(0, 0, SIZE, SIZE)
96
+
97
+ const sheen = ctx.createRadialGradient(
98
+ SIZE * 0.28,
99
+ SIZE * 0.12,
100
+ 0,
101
+ SIZE * 0.28,
102
+ SIZE * 0.12,
103
+ SIZE * 1.1
104
+ )
105
+ sheen.addColorStop(0, 'rgba(255,255,255,0.32)')
106
+ sheen.addColorStop(0.58, 'rgba(255,255,255,0)')
107
+ ctx.fillStyle = sheen
108
+ ctx.fillRect(0, 0, SIZE, SIZE)
109
+ }
110
+
111
+ function toBlob(canvas: HTMLCanvasElement): Promise<Blob> {
112
+ return new Promise((resolve, reject) => {
113
+ canvas.toBlob(
114
+ blob => (blob ? resolve(blob) : reject(new Error('Canvas is empty'))),
115
+ 'image/png'
116
+ )
117
+ })
118
+ }
119
+
120
+ function newCanvas(): [HTMLCanvasElement, CanvasRenderingContext2D] {
121
+ const canvas = document.createElement('canvas')
122
+ canvas.width = SIZE
123
+ canvas.height = SIZE
124
+ const ctx = canvas.getContext('2d')
125
+ if (!ctx) throw new Error('2D canvas unavailable')
126
+ return [canvas, ctx]
127
+ }
128
+
129
+ // Emoji fill ratios: full-bleed on a transparent background (the emoji IS the
130
+ // icon), padded when sitting on a gradient tile.
131
+ const EMOJI_BARE = 0.92
132
+ const EMOJI_ON_GRADIENT = 0.68
133
+
134
+ // Rasterize a single emoji centered over the chosen background (null = none).
135
+ export async function renderEmojiIcon(emoji: string, bg: IconGradient | null): Promise<Blob> {
136
+ const [canvas, ctx] = newCanvas()
137
+ if (bg) paintGradient(ctx, bg)
138
+ ctx.textAlign = 'center'
139
+ ctx.textBaseline = 'middle'
140
+ const scale = bg ? EMOJI_ON_GRADIENT : EMOJI_BARE
141
+ ctx.font = `${Math.round(SIZE * scale)}px "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif`
142
+ // Nudge down slightly — emoji glyphs sit high of the geometric center.
143
+ ctx.fillText(emoji, SIZE / 2, SIZE / 2 + SIZE * 0.04)
144
+ return toBlob(canvas)
145
+ }
146
+
147
+ function loadImage(src: string): Promise<HTMLImageElement> {
148
+ return new Promise((resolve, reject) => {
149
+ const img = new Image()
150
+ img.onload = () => resolve(img)
151
+ img.onerror = () => reject(new Error('Failed to load SVG'))
152
+ img.src = src
153
+ })
154
+ }
155
+
156
+ // Glyph fill ratios, matching the emoji treatment.
157
+ const GLYPH_BARE = 0.78
158
+ const GLYPH_ON_GRADIENT = 0.6
159
+
160
+ // Rasterize a Tabler glyph (passed as serialized SVG markup) centered over the
161
+ // chosen background. The glyph is recolored white on a gradient, near-black when
162
+ // the background is transparent, so it reads in either case.
163
+ export async function renderGlyphIcon(svg: string, bg: IconGradient | null): Promise<Blob> {
164
+ const [canvas, ctx] = newCanvas()
165
+ if (bg) paintGradient(ctx, bg)
166
+ const color = bg ? '#ffffff' : '#18181b'
167
+ const colored = svg.replace(/currentColor/g, color)
168
+ const img = await loadImage(`data:image/svg+xml;utf8,${encodeURIComponent(colored)}`)
169
+ const glyph = SIZE * (bg ? GLYPH_ON_GRADIENT : GLYPH_BARE)
170
+ const offset = (SIZE - glyph) / 2
171
+ ctx.drawImage(img, offset, offset, glyph, glyph)
172
+ return toBlob(canvas)
173
+ }
@@ -0,0 +1,20 @@
1
+ import type { ScratchOp, ScratchOpResult } from '@/lib/types'
2
+
3
+ // A live Scratchpad editor registers an executor here while it's mounted, keyed
4
+ // by workspace id. The chat-socket frame handler (connection.ts) looks one up
5
+ // when a `scratchpad:op` arrives and runs it against the tab's tldraw editor.
6
+ // Only the tab actually showing a workspace's canvas has an entry, so ops from
7
+ // `moi scratch` reach the right editor (and no-op everywhere else).
8
+
9
+ type ScratchExecutor = (op: ScratchOp) => Promise<ScratchOpResult>
10
+
11
+ const executors = new Map<string, ScratchExecutor>()
12
+
13
+ export function setScratchExecutor(workspaceId: string, fn: ScratchExecutor | null) {
14
+ if (fn) executors.set(workspaceId, fn)
15
+ else executors.delete(workspaceId)
16
+ }
17
+
18
+ export function getScratchExecutor(workspaceId: string): ScratchExecutor | undefined {
19
+ return executors.get(workspaceId)
20
+ }