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,86 @@
1
+ import { type RefObject, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
2
+
3
+ // Best-practice chat scroll behavior — "stick to bottom, but respect the user":
4
+ // • Pinned to the bottom by default: new content (new turns, streaming tokens,
5
+ // images loading) keeps the latest line in view.
6
+ // • The moment the user scrolls up, un-pin — never yank them back down while
7
+ // they read history.
8
+ // • Re-pin automatically when they scroll back to (near) the bottom.
9
+ // • `scrollToBottom()` for the "jump to latest" button and for send.
10
+ // • On mount and whenever `resetKey` changes (thread switch), jump to bottom.
11
+ //
12
+ // Content growth is followed via a ResizeObserver on the scroll content, so we
13
+ // don't depend on React deps to know when to scroll — it just works for any
14
+ // height change, including per-token streaming.
15
+
16
+ // Within this many px of the bottom still counts as "at the bottom" — covers
17
+ // sub-pixel rounding and lets a small overscroll keep the pin.
18
+ const STICK_THRESHOLD_PX = 48
19
+
20
+ type StickToBottom = {
21
+ // True when pinned to (near) the bottom — drives the jump-to-latest button.
22
+ atBottom: boolean
23
+ // Scroll to the bottom and re-pin. `smooth` for user-initiated jumps.
24
+ scrollToBottom: (behavior?: ScrollBehavior) => void
25
+ }
26
+
27
+ export function useStickToBottom(
28
+ scrollRef: RefObject<HTMLElement | null>,
29
+ resetKey?: unknown
30
+ ): StickToBottom {
31
+ // Ref (not state) so the scroll/resize handlers read the latest value without
32
+ // re-subscribing; `atBottom` state mirrors it for rendering the button.
33
+ const pinnedRef = useRef(true)
34
+ const [atBottom, setAtBottom] = useState(true)
35
+
36
+ const setPinned = useCallback((pinned: boolean) => {
37
+ pinnedRef.current = pinned
38
+ setAtBottom(prev => (prev === pinned ? prev : pinned))
39
+ }, [])
40
+
41
+ const scrollToBottom = useCallback(
42
+ (behavior: ScrollBehavior = 'auto') => {
43
+ const el = scrollRef.current
44
+ if (!el) return
45
+ setPinned(true)
46
+ el.scrollTo({ top: el.scrollHeight, behavior })
47
+ },
48
+ [scrollRef, setPinned]
49
+ )
50
+
51
+ // Track whether the user is at the bottom. A programmatic scroll-to-bottom
52
+ // also fires this with distance ≈ 0, so pinned stays true — no fight.
53
+ useEffect(() => {
54
+ const el = scrollRef.current
55
+ if (!el) return
56
+ const onScroll = () => {
57
+ const distance = el.scrollHeight - el.scrollTop - el.clientHeight
58
+ setPinned(distance <= STICK_THRESHOLD_PX)
59
+ }
60
+ el.addEventListener('scroll', onScroll, { passive: true })
61
+ return () => el.removeEventListener('scroll', onScroll)
62
+ }, [scrollRef, setPinned])
63
+
64
+ // Follow content growth while pinned. Observing the content element catches
65
+ // every height change (new turns, streaming text, images) without React deps.
66
+ // Setting scrollTop doesn't change the observed size, so there's no RO loop.
67
+ useEffect(() => {
68
+ const el = scrollRef.current
69
+ if (!el) return
70
+ const content = el.firstElementChild ?? el
71
+ const ro = new ResizeObserver(() => {
72
+ if (pinnedRef.current) el.scrollTop = el.scrollHeight
73
+ })
74
+ ro.observe(content)
75
+ return () => ro.disconnect()
76
+ }, [scrollRef])
77
+
78
+ // Jump to bottom on mount and on thread switch (before paint, so no flash).
79
+ // If the new thread's content is still loading, the ResizeObserver above lands
80
+ // us at the bottom once it arrives (pin is set here).
81
+ useLayoutEffect(() => {
82
+ scrollToBottom('auto')
83
+ }, [resetKey, scrollToBottom])
84
+
85
+ return { atBottom, scrollToBottom }
86
+ }
@@ -22,6 +22,11 @@ export function useWorkspaceTheme(
22
22
  target: RefObject<HTMLElement | null>
23
23
  ) {
24
24
  const font = theme?.font ?? 'default'
25
+ // Read the scoped color overrides up front so the color effect below depends
26
+ // on these exact values rather than the whole `theme` object (it accesses
27
+ // them via a dynamic key, which the deps linter can't see through).
28
+ const background = theme?.background
29
+ const foreground = theme?.foreground
25
30
 
26
31
  useEffect(() => {
27
32
  const el = target.current
@@ -58,8 +63,9 @@ export function useWorkspaceTheme(
58
63
  useEffect(() => {
59
64
  const el = target.current
60
65
  if (!el) return
66
+ const overrides = { background, foreground }
61
67
  for (const key of COLOR_OVERRIDES) {
62
- const value = theme?.[key]
68
+ const value = overrides[key]
63
69
  if (value) {
64
70
  el.style.setProperty(`--${key}`, value)
65
71
  } else {
@@ -69,7 +75,7 @@ export function useWorkspaceTheme(
69
75
  return () => {
70
76
  for (const key of COLOR_OVERRIDES) el.style.removeProperty(`--${key}`)
71
77
  }
72
- }, [theme?.background, theme?.foreground, target])
78
+ }, [background, foreground, target])
73
79
 
74
80
  // Drop the shared font <link> when the workspace unmounts.
75
81
  useEffect(() => () => document.getElementById(FONT_LINK_ID)?.remove(), [])
package/client/index.css CHANGED
@@ -9,7 +9,7 @@
9
9
  padding: 0;
10
10
  }
11
11
 
12
- @plugin "@tailwindcss/typography";
12
+ @plugin '@tailwindcss/typography';
13
13
 
14
14
  @custom-variant dark (&:is(.dark *));
15
15
 
@@ -39,8 +39,9 @@
39
39
  equivalents. (The app sidebar's own widths live in SidebarLayout.tsx.) */
40
40
  --page-pad: 2rem; /* padding around the working area */
41
41
  --column-w: 40rem; /* grid content width; also the widget area's min before the chat yields */
42
- --chat-min: 400px; /* docked chat min width — narrower than this and it floats */
43
- --chat-max: 520px; /* docked chat max width on wide screens */
42
+ --chat-min: 380px; /* docked chat min width — narrower than this and it floats */
43
+ --chat-max: 460px; /* docked chat max width on wide screens */
44
+ --chat-max-container: 640px; /* contained ChatPanel: max width of the centered history + composer column */
44
45
  }
45
46
 
46
47
  @media (max-width: 1024px) {
@@ -134,6 +135,18 @@
134
135
  }
135
136
  }
136
137
 
138
+ /* Text shimmer — a brighter band sweeps left→right across muted text to signal
139
+ activity. Pair with `bg-clip-text text-transparent` and a 200%-wide gradient
140
+ whose highlight sits in the middle (see <ShimmerText>). */
141
+ @keyframes text-shimmer {
142
+ 0% {
143
+ background-position: -100% center;
144
+ }
145
+ 100% {
146
+ background-position: 100% center;
147
+ }
148
+ }
149
+
137
150
  @utility prose-inherit {
138
151
  --tw-prose-body: inherit;
139
152
  --tw-prose-headings: inherit;
@@ -170,6 +183,39 @@
170
183
  mask-repeat: no-repeat;
171
184
  }
172
185
 
186
+ /* Hide the scrollbar entirely (e.g. the MCP hover card, which signals overflow
187
+ with top/bottom mask fades instead — see useScrollFade + mask-fade-*). */
188
+ @utility scrollbar-none {
189
+ scrollbar-width: none;
190
+ &::-webkit-scrollbar {
191
+ display: none;
192
+ }
193
+ }
194
+
195
+ /* Slim, unobtrusive scrollbar — keeps a clear scroll affordance while taming
196
+ the chunky macOS "always show" scrollbar (a transparent border insets the
197
+ thumb into a thin floating pill). */
198
+ @utility scrollbar-thin {
199
+ scrollbar-width: thin;
200
+ scrollbar-color: rgb(0 0 0 / 0.2) transparent;
201
+ &::-webkit-scrollbar {
202
+ width: 10px;
203
+ height: 10px;
204
+ }
205
+ &::-webkit-scrollbar-track {
206
+ background: transparent;
207
+ }
208
+ &::-webkit-scrollbar-thumb {
209
+ background-color: rgb(0 0 0 / 0.2);
210
+ border-radius: 9999px;
211
+ border: 3px solid transparent;
212
+ background-clip: padding-box;
213
+ }
214
+ &::-webkit-scrollbar-thumb:hover {
215
+ background-color: rgb(0 0 0 / 0.32);
216
+ }
217
+ }
218
+
173
219
  /* Tool details toggle */
174
220
  details > summary {
175
221
  list-style: none;
package/client/index.html CHANGED
@@ -5,14 +5,18 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>moi.computer</title>
7
7
  <link rel="icon" type="image/png" href="./assets/favicon.png" />
8
+ <!-- React is vendored locally (client/vendor/react, generated by
9
+ scripts/build-vendor.ts) and served by the /vendor/react route, so Moi
10
+ runs fully offline — no CDN fetch. The server picks the development or
11
+ production build per environment behind these stable URLs. -->
8
12
  <script type="importmap">
9
13
  {
10
14
  "imports": {
11
- "react": "https://esm.sh/react@19?dev",
12
- "react/jsx-runtime": "https://esm.sh/react@19/jsx-runtime?dev",
13
- "react/jsx-dev-runtime": "https://esm.sh/react@19/jsx-dev-runtime?dev",
14
- "react-dom": "https://esm.sh/react-dom@19?dev",
15
- "react-dom/client": "https://esm.sh/react-dom@19/client?dev"
15
+ "react": "/vendor/react/react.js",
16
+ "react/jsx-runtime": "/vendor/react/react-jsx-runtime.js",
17
+ "react/jsx-dev-runtime": "/vendor/react/react-jsx-dev-runtime.js",
18
+ "react-dom": "/vendor/react/react-dom.js",
19
+ "react-dom/client": "/vendor/react/react-dom-client.js"
16
20
  }
17
21
  }
18
22
  </script>
@@ -23,20 +27,20 @@
23
27
  <script type="module" src="./index.tsx"></script>
24
28
  <script type="module">
25
29
  const [react, jsxRuntime, jsxDevRuntime, reactDom, reactDomClient] = await Promise.all([
26
- import("react"),
27
- import("react/jsx-runtime"),
28
- import("react/jsx-dev-runtime"),
29
- import("react-dom"),
30
- import("react-dom/client"),
31
- ]);
30
+ import('react'),
31
+ import('react/jsx-runtime'),
32
+ import('react/jsx-dev-runtime'),
33
+ import('react-dom'),
34
+ import('react-dom/client')
35
+ ])
32
36
  globalThis.__esm = {
33
- "react": react,
34
- "react/jsx-runtime": jsxRuntime,
35
- "react/jsx-dev-runtime": jsxDevRuntime,
36
- "react-dom": reactDom,
37
- "react-dom/client": reactDomClient,
38
- };
39
- globalThis.__init(document.getElementById("root"));
37
+ react: react,
38
+ 'react/jsx-runtime': jsxRuntime,
39
+ 'react/jsx-dev-runtime': jsxDevRuntime,
40
+ 'react-dom': reactDom,
41
+ 'react-dom/client': reactDomClient
42
+ }
43
+ globalThis.__init(document.getElementById('root'))
40
44
  //# sourceURL=react-preload.js
41
45
  </script>
42
46
  </body>
package/client/index.tsx CHANGED
@@ -1,13 +1,40 @@
1
+ // Must run before any tldraw module loads — see the file for why.
2
+ import './structured-clone-shim'
3
+
1
4
  import './index.css'
2
5
 
3
- // React is externalized to esm.sh (see client/externalize-react.ts + the importmap
4
- // in index.html), so Bun's bundled Fast Refresh runtime isn't bound to the React
6
+ // React is externalized to the locally-vendored ESM (see client/externalize-react.ts
7
+ // + the importmap in index.html → /vendor/react), so Bun's bundled Fast Refresh
8
+ // runtime isn't bound to the React
5
9
  // instance that actually renders the app: it registers component families but
6
10
  // performReactRefresh() no-ops, leaving stale modules mounted after an edit.
7
11
  // Downgrade HMR to plain live-reload — every hot update triggers a full page
8
12
  // reload, which re-fetches a clean bundle. Dead-code-eliminated in production.
9
13
  if (import.meta.hot) {
10
14
  import.meta.hot.on('bun:beforeUpdate', () => location.reload())
15
+
16
+ // Bun's HMR client (≤1.3.14) never re-arms `onclose` on the socket it
17
+ // creates while reconnecting, so the second disconnect in a tab's life
18
+ // (e.g. laptop sleep, then a dev-supervisor restart) silently kills
19
+ // live-reload and the tab serves a stale bundle forever. Watchdog: poll
20
+ // the shell and hard-reload when the served script generation no longer
21
+ // matches the one this page is running.
22
+ const devScript = document.querySelector<HTMLScriptElement>('[data-bun-dev-server-script]')
23
+ if (devScript) {
24
+ const scriptPath = new URL(devScript.src).pathname
25
+ const checkStale = async () => {
26
+ try {
27
+ const html = await (await fetch('/', { cache: 'no-store' })).text()
28
+ if (!html.includes(scriptPath)) location.reload()
29
+ } catch {
30
+ // server mid-restart — the next tick will catch it
31
+ }
32
+ }
33
+ setInterval(checkStale, 5_000)
34
+ document.addEventListener('visibilitychange', () => {
35
+ if (document.visibilityState === 'visible') checkStale()
36
+ })
37
+ }
11
38
  }
12
39
 
13
40
  export async function init(el: HTMLElement) {
@@ -1,4 +1,4 @@
1
- import { type ReactNode, createContext, useContext, useEffect } from 'react'
1
+ import { type ReactNode, createContext, useContext } from 'react'
2
2
 
3
3
  const WorkspaceContext = createContext<string>('default')
4
4
 
@@ -11,14 +11,11 @@ type WorkspaceProps = {
11
11
  children: ReactNode
12
12
  }
13
13
 
14
- // Provides the active workspace id to the tree (read by chat + widget hooks).
14
+ // Provides the active workspace id to the tree (read by chat + applet hooks).
15
15
  // Data loading lives in React Query now (see WorkspaceLayoutProvider and the
16
- // useWorkspace* query hooks) — this only carries the id.
16
+ // useWorkspace* query hooks) — this only carries the id. Applet bundles no
17
+ // longer read a window global for their workspace: the serve route bakes the
18
+ // API base into each bundle's RPC/fileUrl calls.
17
19
  export function Workspace({ id, children }: WorkspaceProps) {
18
- useEffect(() => {
19
- // Expose to widget RPC bundles
20
- ;(window as unknown as Record<string, unknown>).__MEI_WS__ = id
21
- }, [id])
22
-
23
20
  return <WorkspaceContext value={id}>{children}</WorkspaceContext>
24
21
  }
@@ -1,4 +1,4 @@
1
- import { type ReactNode, createContext, useCallback, useContext, useRef } from 'react'
1
+ import { type ReactNode, createContext, useCallback, useContext, useMemo, useRef } from 'react'
2
2
 
3
3
  import { useQueryClient } from '@tanstack/react-query'
4
4
 
@@ -8,7 +8,7 @@ import {
8
8
  useWorkspaceLayout,
9
9
  workspaceKeys
10
10
  } from '@/client/api/workspaces'
11
- import type { WorkspaceLayout } from '@/lib/types'
11
+ import type { WorkspaceLayout, WorkspaceType } from '@/lib/types'
12
12
 
13
13
  const DEFAULT_LAYOUT: WorkspaceLayout = {
14
14
  version: 1,
@@ -25,7 +25,17 @@ type WorkspaceLayoutContextValue = {
25
25
  setLayout: (update: Partial<WorkspaceLayout>) => void
26
26
  // Workspace metadata that rides along on the layout endpoint.
27
27
  name: string | null
28
+ // Custom workspace icon (base64 data URL), or null to use the provider icon.
29
+ icon: string | null
28
30
  cwd: string | null
31
+ // The agent backend (claude-code / openclaw / hermes …). Exposed here so
32
+ // components like McpMenu read it from the shared layout query instead of
33
+ // spawning their own observer (a second observer that remounts would trigger
34
+ // `refetchOnMount` and clobber an in-flight optimistic layout update).
35
+ provider: WorkspaceType | null
36
+ // The workspace's registry id (the route param), so descendants can key
37
+ // their own queries (e.g. the model picker) without prop-drilling.
38
+ workspaceId: string
29
39
  isLoading: boolean
30
40
  }
31
41
 
@@ -40,7 +50,7 @@ export function useWorkspaceLayoutCtx(): WorkspaceLayoutContextValue {
40
50
  // Strip the server-only metadata so what we PUT back (and expose as `layout`)
41
51
  // is just the persisted `WorkspaceLayout`.
42
52
  function stripMeta(data: WorkspaceLayoutResponse): WorkspaceLayout {
43
- const { cwd: _cwd, name: _name, agentId: _agentId, ...layout } = data
53
+ const { cwd: _cwd, name: _name, provider: _provider, agentId: _agentId, ...layout } = data
44
54
  return layout
45
55
  }
46
56
 
@@ -80,13 +90,23 @@ export function WorkspaceLayoutProvider({ id, children }: WorkspaceLayoutProvide
80
90
  [id, qc]
81
91
  )
82
92
 
83
- const value: WorkspaceLayoutContextValue = {
84
- layout: query.data ? stripMeta(query.data) : DEFAULT_LAYOUT,
85
- setLayout,
86
- name: query.data?.name ?? null,
87
- cwd: query.data?.cwd ?? null,
88
- isLoading: query.isLoading
89
- }
93
+ // Memoized so the context value keeps a stable identity across unrelated
94
+ // renders — otherwise every consumer (WorkspaceView, Widgets, ModelPicker,
95
+ // TurnView, …) would re-render whenever this provider re-renders. `setLayout`
96
+ // is already stable; the rest derive from `query.data`.
97
+ const value = useMemo<WorkspaceLayoutContextValue>(
98
+ () => ({
99
+ layout: query.data ? stripMeta(query.data) : DEFAULT_LAYOUT,
100
+ setLayout,
101
+ name: query.data?.name ?? null,
102
+ icon: query.data?.icon ?? null,
103
+ cwd: query.data?.cwd ?? null,
104
+ provider: query.data?.provider ?? null,
105
+ workspaceId: id,
106
+ isLoading: query.isLoading
107
+ }),
108
+ [query.data, query.isLoading, setLayout, id]
109
+ )
90
110
 
91
111
  return <WorkspaceLayoutContext value={value}>{children}</WorkspaceLayoutContext>
92
112
  }
@@ -0,0 +1,54 @@
1
+ // Shared load cache for agent-authored applets (widgets / views).
2
+ //
3
+ // An applet is loaded as an ESM module via dynamic `import()`. The browser
4
+ // memoizes a module by its exact URL forever, so to pick up a rebuilt bundle the
5
+ // URL must change — we vary a `?v=<n>` per applet. The catch: a workspace shows
6
+ // one view (or the widget grid) at a time, so most applets are UNMOUNTED at any
7
+ // moment. If invalidation lived only in the mounted component, an applet rebuilt
8
+ // while its tab is in the background would never bump its version and would be
9
+ // served stale from cache on the next mount.
10
+ //
11
+ // So the cache + version registry live here, module-level and mount-independent:
12
+ // a workspace-wide listener invalidates on every `*:updated` event (see
13
+ // `useAppletCacheInvalidation`), and the per-applet hook invalidates the mounted
14
+ // one too. Either path bumps the version + drops the cached module, so the next
15
+ // load() fetches the rebuilt bundle.
16
+ export type AppletSegment = 'widgets' | 'views'
17
+
18
+ // `${segment}/${workspaceId}/${name}` — namespaced so a widget and a view (or
19
+ // two workspaces) sharing a name never collide.
20
+ export function appletKey(segment: AppletSegment, workspaceId: string, name: string): string {
21
+ return `${segment}/${workspaceId}/${name}`
22
+ }
23
+
24
+ const versions = new Map<string, number>()
25
+ const moduleCache = new Map<string, Promise<unknown>>()
26
+
27
+ export function appletVersion(segment: AppletSegment, workspaceId: string, name: string): number {
28
+ return versions.get(appletKey(segment, workspaceId, name)) ?? 0
29
+ }
30
+
31
+ // The cache-busting import URL for an applet's entry at its current version.
32
+ // Assets + chunks resolve module-relative from the entry (via import.meta.url),
33
+ // so they don't inherit `?v` and aren't re-fetched needlessly.
34
+ export function appletUrl(segment: AppletSegment, workspaceId: string, name: string): string {
35
+ return `/api/workspaces/${workspaceId}/${segment}/${name}/index.js?v=${appletVersion(segment, workspaceId, name)}`
36
+ }
37
+
38
+ export function getCachedApplet(key: string): Promise<unknown> | undefined {
39
+ return moduleCache.get(key)
40
+ }
41
+
42
+ export function setCachedApplet(key: string, mod: Promise<unknown>): void {
43
+ moduleCache.set(key, mod)
44
+ }
45
+
46
+ // Drop the cached module and bump the load version for one applet, so the next
47
+ // load() — including a fresh mount of a previously-backgrounded tab — fetches the
48
+ // rebuilt bundle instead of the memoized old one. Safe (and intended) to call
49
+ // when nothing for this applet is mounted.
50
+ export function invalidateApplet(segment: AppletSegment, workspaceId: string, name: string): void {
51
+ const key = appletKey(segment, workspaceId, name)
52
+ moduleCache.delete(key)
53
+ versions.set(key, (versions.get(key) ?? 0) + 1)
54
+ }