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
@@ -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
+ }
@@ -0,0 +1,18 @@
1
+ import type { UploadInfo } from '@/lib/types'
2
+
3
+ // POST one or more files to a workspace's upload endpoint and return the server's
4
+ // `UploadInfo` for each (in request order). The chat composer calls this as soon
5
+ // as files are added (drop/paste/pick) so the upload ids are ready by send time.
6
+ export async function uploadFiles(workspaceId: string, files: File[]): Promise<UploadInfo[]> {
7
+ const form = new FormData()
8
+ for (const f of files) form.append('files', f)
9
+ const res = await fetch(`/api/workspaces/${workspaceId}/uploads`, {
10
+ method: 'POST',
11
+ body: form
12
+ })
13
+ if (!res.ok) {
14
+ const detail = await res.text().catch(() => '')
15
+ throw new Error(detail || `Upload failed (${res.status})`)
16
+ }
17
+ return res.json()
18
+ }
package/client/main.tsx CHANGED
@@ -3,10 +3,15 @@ import { Agentation } from 'agentation'
3
3
  import { createRoot } from 'react-dom/client'
4
4
  import { Router } from 'wouter'
5
5
 
6
+ import { initConnection } from './lib/connection'
6
7
  import { AppRouter } from './components/App'
7
8
 
8
9
  const queryClient = new QueryClient()
9
10
 
11
+ // Open the single app-wide chat WebSocket once and hand it the query client so
12
+ // live frames fold into the RQ transcript cache. Lives for the page's lifetime.
13
+ initConnection(queryClient)
14
+
10
15
  export function mount(el: HTMLElement) {
11
16
  function Root() {
12
17
  return (