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
@@ -38,7 +38,7 @@ function DropdownMenuContent({
38
38
  <MenuPrimitive.Popup
39
39
  data-slot="dropdown-menu-content"
40
40
  className={cn(
41
- 'max-h-(--available-height) w-(--anchor-width) origin-(--transform-origin) bg-popover text-popover-foreground ring-foreground/10 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:overflow-hidden data-closed:fade-out-0 data-closed:zoom-out-95 z-50 min-w-32 overflow-y-auto overflow-x-hidden rounded-md p-1 shadow-md outline-none ring-1 duration-100',
41
+ 'z-50 max-h-(--available-height) w-(--anchor-width) min-w-32 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-md bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:overflow-hidden data-closed:fade-out-0 data-closed:zoom-out-95',
42
42
  className
43
43
  )}
44
44
  {...props}
@@ -64,7 +64,7 @@ function DropdownMenuLabel({
64
64
  data-slot="dropdown-menu-label"
65
65
  data-inset={inset}
66
66
  className={cn(
67
- 'text-muted-foreground data-inset:pl-7 px-1.5 py-1 text-xs font-medium',
67
+ 'px-1.5 py-1 text-xs font-medium text-muted-foreground data-inset:pl-7',
68
68
  className
69
69
  )}
70
70
  {...props}
@@ -87,7 +87,7 @@ function DropdownMenuItem({
87
87
  data-inset={inset}
88
88
  data-variant={variant}
89
89
  className={cn(
90
- "group/dropdown-menu-item outline-hidden focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 data-[variant=destructive]:*:[svg]:text-destructive rounded-xs relative flex cursor-default select-none items-center gap-2 px-1.5 py-1 text-sm [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
90
+ "group/dropdown-menu-item relative flex cursor-default items-center gap-2 rounded-xs px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive",
91
91
  className
92
92
  )}
93
93
  {...props}
@@ -112,7 +112,7 @@ function DropdownMenuSubTrigger({
112
112
  data-slot="dropdown-menu-sub-trigger"
113
113
  data-inset={inset}
114
114
  className={cn(
115
- "outline-hidden focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-popup-open:bg-accent data-popup-open:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground rounded-xs flex cursor-default select-none items-center gap-2 px-1.5 py-1 text-sm [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
115
+ "flex cursor-default items-center gap-2 rounded-xs px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-popup-open:bg-accent data-popup-open:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
116
116
  className
117
117
  )}
118
118
  {...props}
@@ -135,7 +135,7 @@ function DropdownMenuSubContent({
135
135
  <DropdownMenuContent
136
136
  data-slot="dropdown-menu-sub-content"
137
137
  className={cn(
138
- 'bg-popover text-popover-foreground ring-foreground/10 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 w-auto min-w-[96px] rounded-md p-1 shadow-lg ring-1 duration-100',
138
+ 'w-auto min-w-[96px] rounded-md bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95',
139
139
  className
140
140
  )}
141
141
  align={align}
@@ -161,7 +161,7 @@ function DropdownMenuCheckboxItem({
161
161
  data-slot="dropdown-menu-checkbox-item"
162
162
  data-inset={inset}
163
163
  className={cn(
164
- "outline-hidden focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 rounded-xs relative flex cursor-default select-none items-center gap-2 py-1 pl-2 pr-8 text-sm [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
164
+ "relative flex cursor-default items-center gap-2 rounded-xs py-1 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
165
165
  className
166
166
  )}
167
167
  checked={checked}
@@ -197,7 +197,7 @@ function DropdownMenuRadioItem({
197
197
  data-slot="dropdown-menu-radio-item"
198
198
  data-inset={inset}
199
199
  className={cn(
200
- "outline-hidden focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 rounded-xs relative flex cursor-default select-none items-center gap-2 py-1 pl-2 pr-8 text-sm [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
200
+ "relative flex cursor-default items-center gap-2 rounded-xs py-1 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
201
201
  className
202
202
  )}
203
203
  {...props}
@@ -219,7 +219,7 @@ function DropdownMenuSeparator({ className, ...props }: MenuPrimitive.Separator.
219
219
  return (
220
220
  <MenuPrimitive.Separator
221
221
  data-slot="dropdown-menu-separator"
222
- className={cn('bg-border -mx-1 my-1 h-px', className)}
222
+ className={cn('-mx-1 my-1 h-px bg-border', className)}
223
223
  {...props}
224
224
  />
225
225
  )
@@ -230,7 +230,7 @@ function DropdownMenuShortcut({ className, ...props }: ComponentProps<'span'>) {
230
230
  <span
231
231
  data-slot="dropdown-menu-shortcut"
232
232
  className={cn(
233
- 'text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground ml-auto text-xs tracking-widest',
233
+ 'ml-auto text-xs tracking-widest text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground',
234
234
  className
235
235
  )}
236
236
  {...props}
@@ -0,0 +1,44 @@
1
+ import { PreviewCard as PreviewCardPrimitive } from '@base-ui/react/preview-card'
2
+
3
+ import { cn } from '@/client/lib/cn'
4
+
5
+ function HoverCard({ ...props }: PreviewCardPrimitive.Root.Props) {
6
+ return <PreviewCardPrimitive.Root data-slot="hover-card" {...props} />
7
+ }
8
+
9
+ function HoverCardTrigger({ ...props }: PreviewCardPrimitive.Trigger.Props) {
10
+ return <PreviewCardPrimitive.Trigger data-slot="hover-card-trigger" {...props} />
11
+ }
12
+
13
+ function HoverCardContent({
14
+ className,
15
+ side = 'bottom',
16
+ sideOffset = 4,
17
+ align = 'center',
18
+ alignOffset = 4,
19
+ ...props
20
+ }: PreviewCardPrimitive.Popup.Props &
21
+ Pick<PreviewCardPrimitive.Positioner.Props, 'align' | 'alignOffset' | 'side' | 'sideOffset'>) {
22
+ return (
23
+ <PreviewCardPrimitive.Portal data-slot="hover-card-portal">
24
+ <PreviewCardPrimitive.Positioner
25
+ align={align}
26
+ alignOffset={alignOffset}
27
+ side={side}
28
+ sideOffset={sideOffset}
29
+ className="isolate z-50"
30
+ >
31
+ <PreviewCardPrimitive.Popup
32
+ data-slot="hover-card-content"
33
+ className={cn(
34
+ 'z-50 w-64 origin-(--transform-origin) rounded-lg bg-popover p-2.5 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95',
35
+ className
36
+ )}
37
+ {...props}
38
+ />
39
+ </PreviewCardPrimitive.Positioner>
40
+ </PreviewCardPrimitive.Portal>
41
+ )
42
+ }
43
+
44
+ export { HoverCard, HoverCardTrigger, HoverCardContent }
@@ -36,7 +36,7 @@ function PopoverContent({
36
36
  <PopoverPrimitive.Popup
37
37
  data-slot="popover-content"
38
38
  className={cn(
39
- 'origin-(--transform-origin) bg-popover text-popover-foreground ring-foreground/5 outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 z-50 flex w-72 flex-col gap-2.5 rounded-md p-2.5 text-sm shadow-md ring-1 duration-100',
39
+ 'z-50 flex w-72 origin-(--transform-origin) flex-col gap-2.5 rounded-md bg-popover p-2.5 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/5 outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95',
40
40
  className
41
41
  )}
42
42
  {...props}
@@ -0,0 +1,23 @@
1
+ import { Switch as SwitchPrimitive } from '@base-ui/react/switch'
2
+
3
+ import { cn } from '@/client/lib/cn'
4
+
5
+ function Switch({ className, ...props }: SwitchPrimitive.Root.Props) {
6
+ return (
7
+ <SwitchPrimitive.Root
8
+ data-slot="switch"
9
+ className={cn(
10
+ 'peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border border-transparent shadow-xs transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-checked:bg-primary data-unchecked:bg-input',
11
+ className
12
+ )}
13
+ {...props}
14
+ >
15
+ <SwitchPrimitive.Thumb
16
+ data-slot="switch-thumb"
17
+ className="pointer-events-none block size-4 rounded-full bg-background shadow-sm ring-0 transition-transform data-checked:translate-x-4 data-unchecked:translate-x-0.5"
18
+ />
19
+ </SwitchPrimitive.Root>
20
+ )
21
+ }
22
+
23
+ export { Switch }
@@ -0,0 +1,54 @@
1
+ import { Tooltip as TooltipPrimitive } from '@base-ui/react/tooltip'
2
+
3
+ import { cn } from '@/client/lib/cn'
4
+
5
+ // Self-contained: each Tooltip wraps its own provider so `delay` can be set
6
+ // per-instance (Base UI exposes delay/closeDelay on the provider, not the root).
7
+ function Tooltip({
8
+ delay,
9
+ closeDelay,
10
+ ...props
11
+ }: TooltipPrimitive.Root.Props & { delay?: number; closeDelay?: number }) {
12
+ return (
13
+ <TooltipPrimitive.Provider delay={delay} closeDelay={closeDelay}>
14
+ <TooltipPrimitive.Root data-slot="tooltip" {...props} />
15
+ </TooltipPrimitive.Provider>
16
+ )
17
+ }
18
+
19
+ function TooltipTrigger({ ...props }: TooltipPrimitive.Trigger.Props) {
20
+ return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />
21
+ }
22
+
23
+ function TooltipContent({
24
+ className,
25
+ side = 'top',
26
+ sideOffset = 6,
27
+ align = 'center',
28
+ alignOffset = 0,
29
+ ...props
30
+ }: TooltipPrimitive.Popup.Props &
31
+ Pick<TooltipPrimitive.Positioner.Props, 'align' | 'alignOffset' | 'side' | 'sideOffset'>) {
32
+ return (
33
+ <TooltipPrimitive.Portal>
34
+ <TooltipPrimitive.Positioner
35
+ align={align}
36
+ alignOffset={alignOffset}
37
+ side={side}
38
+ sideOffset={sideOffset}
39
+ className="isolate z-50"
40
+ >
41
+ <TooltipPrimitive.Popup
42
+ data-slot="tooltip-content"
43
+ className={cn(
44
+ 'z-50 origin-(--transform-origin) rounded-sm bg-white px-2 py-1 text-xs font-medium text-primary shadow-md outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-1 data-[side=left]:slide-in-from-right-1 data-[side=right]:slide-in-from-left-1 data-[side=top]:slide-in-from-bottom-1 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95',
45
+ className
46
+ )}
47
+ {...props}
48
+ />
49
+ </TooltipPrimitive.Positioner>
50
+ </TooltipPrimitive.Portal>
51
+ )
52
+ }
53
+
54
+ export { Tooltip, TooltipContent, TooltipTrigger }
@@ -1,29 +1,35 @@
1
1
  import type { BunPlugin } from 'bun'
2
2
 
3
+ // React is not bundled into the app. Each of these specifiers is replaced with a
4
+ // read from `globalThis.__esm`, which the preload in index.html fills by
5
+ // importing them through the importmap (→ the locally-vendored ESM served at
6
+ // /vendor/react, see scripts/build-vendor.ts). This keeps ONE React instance
7
+ // shared between the host app and every applet/widget (which resolve the same
8
+ // importmap) — bundling React in would give each its own copy and break hooks.
3
9
  const esmModules = [
4
10
  'react',
5
11
  'react/jsx-runtime',
6
12
  'react/jsx-dev-runtime',
7
13
  'react-dom',
8
- 'react-dom/client',
14
+ 'react-dom/client'
9
15
  ]
10
16
 
11
17
  const externalizeReact: BunPlugin = {
12
18
  name: 'externalize-react',
13
19
  setup(build) {
14
- build.onResolve({ filter: /^react(-dom)?(\/.*)?$/ }, (args) => {
20
+ build.onResolve({ filter: /^react(-dom)?(\/.*)?$/ }, args => {
15
21
  if (esmModules.includes(args.path)) {
16
22
  return { path: args.path, namespace: 'esm' }
17
23
  }
18
24
  })
19
25
 
20
- build.onLoad({ filter: /.*/, namespace: 'esm' }, (args) => {
26
+ build.onLoad({ filter: /.*/, namespace: 'esm' }, args => {
21
27
  return {
22
28
  contents: `module.exports = globalThis.__esm["${args.path}"];`,
23
- loader: 'js',
29
+ loader: 'js'
24
30
  }
25
31
  })
26
- },
32
+ }
27
33
  }
28
34
 
29
35
  export default externalizeReact
@@ -0,0 +1,117 @@
1
+ import type { ComponentType } from 'react'
2
+ import { useCallback, useEffect, useState } from 'react'
3
+
4
+ import {
5
+ type AppletSegment,
6
+ appletKey,
7
+ appletUrl,
8
+ getCachedApplet,
9
+ invalidateApplet,
10
+ setCachedApplet
11
+ } from '@/client/lib/applet-cache'
12
+ import { useWorkspaceId } from '@/client/lib/WorkspaceContext'
13
+
14
+ import { type MeiEvent, useMeiEvent } from './useMeiEvents'
15
+
16
+ type AppletState =
17
+ | { status: 'loading'; version: number }
18
+ | { status: 'ready'; Component: ComponentType; version: number }
19
+ | { status: 'error'; error: string; version: number }
20
+
21
+ // An applet kind (widget / view) differs only in its URL path segment and which
22
+ // MEI events tell it to reload. Everything else — dynamic import, caching,
23
+ // cache-busting — is shared. An applet is an agent-authored UI unit loaded as an
24
+ // ESM module and mounted into the workspace.
25
+ type AppletKind = {
26
+ segment: AppletSegment
27
+ // True when this MEI event means the named applet should cache-bust + reload.
28
+ shouldReload: (event: MeiEvent, name: string) => boolean
29
+ }
30
+
31
+ const WIDGET_KIND: AppletKind = {
32
+ segment: 'widgets',
33
+ shouldReload: (e, name) =>
34
+ (e.type === 'widget:updated' && e.name === name) || e.type === 'widgets:refresh'
35
+ }
36
+
37
+ const VIEW_KIND: AppletKind = {
38
+ segment: 'views',
39
+ shouldReload: (e, name) => e.type === 'view:updated' && e.name === name
40
+ }
41
+
42
+ function loadApplet(
43
+ segment: AppletSegment,
44
+ workspaceId: string,
45
+ name: string
46
+ ): Promise<ComponentType> {
47
+ const key = appletKey(segment, workspaceId, name)
48
+ const existing = getCachedApplet(key) as Promise<ComponentType> | undefined
49
+ if (existing) return existing
50
+
51
+ // Import the bundle dir's `index.js` at its current `?v`; the version is bumped
52
+ // (and this entry dropped) by `invalidateApplet` on every rebuild — including
53
+ // while this applet is unmounted — so a backgrounded tab never serves stale.
54
+ const promise = import(/* @vite-ignore */ appletUrl(segment, workspaceId, name)).then(mod => {
55
+ if (!mod.default) throw new Error(`"${name}" has no default export`)
56
+ return mod.default as ComponentType
57
+ })
58
+
59
+ setCachedApplet(key, promise)
60
+ return promise
61
+ }
62
+
63
+ function useApplet(kind: AppletKind, name: string): AppletState {
64
+ const workspaceId = useWorkspaceId()
65
+ const [state, setState] = useState<AppletState>({ status: 'loading', version: 0 })
66
+
67
+ const load = useCallback(() => {
68
+ setState(prev => ({ status: 'loading', version: prev.version }))
69
+ loadApplet(kind.segment, workspaceId, name)
70
+ .then(Component =>
71
+ setState(prev => ({ status: 'ready', Component, version: prev.version + 1 }))
72
+ )
73
+ .catch(err =>
74
+ setState(prev => ({ status: 'error', error: String(err), version: prev.version + 1 }))
75
+ )
76
+ }, [kind.segment, workspaceId, name])
77
+
78
+ useEffect(() => {
79
+ load()
80
+ }, [load])
81
+
82
+ // Reload the MOUNTED applet the moment the server says its bundle changed (or,
83
+ // widgets only, `moi refresh`). Invalidate first so we don't re-read a stale
84
+ // cache entry — `useAppletCacheInvalidation` may already have done so for the
85
+ // unmounted case, but doing it here keeps this self-sufficient and
86
+ // order-independent. The bumped version remounts the component and re-runs its
87
+ // `rpc()` calls.
88
+ useMeiEvent(event => {
89
+ if (kind.shouldReload(event, name)) {
90
+ invalidateApplet(kind.segment, workspaceId, name)
91
+ load()
92
+ }
93
+ })
94
+
95
+ return state
96
+ }
97
+
98
+ export function useWidget(name: string): AppletState {
99
+ return useApplet(WIDGET_KIND, name)
100
+ }
101
+
102
+ export function useView(name: string): AppletState {
103
+ return useApplet(VIEW_KIND, name)
104
+ }
105
+
106
+ // Mount once per workspace (in the workspace route). Invalidates the shared
107
+ // applet module cache on every `*:updated` event, regardless of what's currently
108
+ // mounted — so an applet edited while its tab is backgrounded is fetched fresh on
109
+ // the next mount instead of served stale. The per-applet listener above only
110
+ // fires while that applet is on screen; this covers the (common) rest.
111
+ export function useAppletCacheInvalidation(): void {
112
+ const workspaceId = useWorkspaceId()
113
+ useMeiEvent(event => {
114
+ if (event.type === 'view:updated') invalidateApplet('views', workspaceId, event.name)
115
+ else if (event.type === 'widget:updated') invalidateApplet('widgets', workspaceId, event.name)
116
+ })
117
+ }
@@ -1,88 +1,188 @@
1
- import { useCallback, useEffect } from 'react'
2
- import { useState } from 'react'
1
+ import { useCallback, useMemo } from 'react'
3
2
 
3
+ import { useQueryClient } from '@tanstack/react-query'
4
+
5
+ import {
6
+ useSessionView,
7
+ useThreadConfig,
8
+ useWorkspaceModels,
9
+ workspaceKeys
10
+ } from '@/client/api/workspaces'
4
11
  import { useWorkspaceId } from '@/client/lib/WorkspaceContext'
5
- import { connectWs, disconnectWs, sendWs } from '@/client/lib/ws'
6
- import { useChatStore, useChatStoreApi } from '@/client/store/chat'
7
- import { emptyViewState } from '@/lib/format'
8
- import type { ViewState } from '@/lib/types'
12
+ import { useWorkspaceLayoutCtx } from '@/client/lib/WorkspaceLayoutContext'
13
+ import { sendMessage } from '@/client/lib/connection'
14
+ import { STREAM_RESPONSES } from '@/client/lib/flags'
15
+ import { buildPreviewTurn } from '@/client/lib/preview-turn'
16
+ import { draftKey, liveStore, selectPreviews, useLive } from '@/client/store/live'
17
+ import { applyEvent, emptyViewState } from '@/lib/format'
18
+ import type { Part, ViewState } from '@/lib/types'
9
19
 
10
20
  const EMPTY: ViewState = emptyViewState()
11
21
 
22
+ // Thin projection over app-level state: the active thread + spinner/error come
23
+ // from the live store; the transcript comes from the React Query cache (kept
24
+ // current by the connection manager's WS deltas). No socket lifecycle here.
12
25
  export function useChat() {
13
26
  const workspaceId = useWorkspaceId()
14
- const store = useChatStoreApi()
15
- const [input, setInput] = useState('')
27
+ const qc = useQueryClient()
28
+ const { layout } = useWorkspaceLayoutCtx()
29
+ const modelsData = useWorkspaceModels(workspaceId).data
30
+ const models = modelsData?.models
31
+ const supportsStreaming = modelsData?.supportsStreaming ?? false
32
+
33
+ const activeSessionId = useLive(s => s.activeByWorkspace[workspaceId] ?? null)
34
+ const processing = useLive(s =>
35
+ activeSessionId ? (s.processing[`${workspaceId}:${activeSessionId}`] ?? false) : false
36
+ )
37
+ const error = useLive(s =>
38
+ activeSessionId ? (s.errors[`${workspaceId}:${activeSessionId}`] ?? null) : null
39
+ )
16
40
 
17
- const activeSessionId = useChatStore(s => s.activeSessionId)
18
- const setActiveSession = useChatStore(s => s.setActiveSession)
41
+ const view = useSessionView(workspaceId, activeSessionId).data ?? EMPTY
19
42
 
20
- const view = useChatStore(s => s.views[activeSessionId ?? ''] ?? EMPTY)
21
- const processing = useChatStore(s => s.processing[activeSessionId ?? ''] ?? false)
22
- const error = useChatStore(s => s.errors[activeSessionId ?? ''] ?? null)
43
+ // The live streaming preview as a synthetic assistant turn, so the ChatPanel
44
+ // can run it through the SAME groupTurns pipeline as finalized turns — a
45
+ // thinking-only preview then folds into the current tool group instead of
46
+ // rendering as a detached block. Recomputed per delta (the previews slice is
47
+ // stable across other updates); null when there's nothing visible yet.
48
+ const previews = useLive(s => s.previews)
49
+ const previewTurn = useMemo(
50
+ () => buildPreviewTurn(selectPreviews(previews, workspaceId, activeSessionId).root),
51
+ [previews, workspaceId, activeSessionId]
52
+ )
23
53
 
24
- // Persistent WS for live events — reconnects if workspace changes. Hands the
25
- // workspace's chat store to the (non-React) socket layer so it writes there.
26
- useEffect(() => {
27
- connectWs(workspaceId, store)
28
- return () => disconnectWs()
29
- }, [workspaceId, store])
54
+ // The active thread's persisted model/effort. For a brand-new chat (no thread
55
+ // yet) this is empty and `send` falls back to the workspace defaults below.
56
+ const threadCfg = useThreadConfig(workspaceId, activeSessionId).data
30
57
 
31
- // When active session changes and we don't have its events cached, fetch them
32
- useEffect(() => {
33
- if (!activeSessionId) return
34
- if (store.getState().events[activeSessionId] !== undefined) return
35
- store.getState().loadEvents(workspaceId, activeSessionId)
36
- }, [workspaceId, activeSessionId, store])
37
-
38
- const send = useCallback(() => {
39
- const text = input.trim()
40
- if (!text || processing) return
41
-
42
- let sid = activeSessionId
43
- let isNew = false
44
- if (!sid) {
45
- sid = crypto.randomUUID()
46
- isNew = true
47
- store.getState().setEvents(sid, [])
48
- setActiveSession(sid)
49
- }
50
-
51
- // Optimistic user turn — rendered immediately, upserted in place when the
52
- // SDK echoes it back via expectUserEcho on the server.
53
- const optimisticId = `optimistic:${crypto.randomUUID()}`
54
- store.getState().append(sid, {
55
- kind: 'turn',
56
- turn: {
57
- id: optimisticId,
58
- role: 'user',
59
- origin: { kind: 'user-input' },
60
- parts: [{ type: 'text', text }],
61
- timestamp: new Date().toISOString()
58
+ // The composer owns the draft (in the live store) and hands the text in, so a
59
+ // keystroke re-renders only the composer — not this hook's host (WorkspaceView)
60
+ // and its whole subtree. See `ChatInput`.
61
+ const send = useCallback(
62
+ (draft: string) => {
63
+ const text = draft.trim()
64
+ // Attachments for the active thread, keyed exactly like the draft. Only
65
+ // fully-uploaded ones are sent; the composer disables send while any are
66
+ // still uploading, so in practice they're all ready here.
67
+ const pending = liveStore.getState().attachments[draftKey(workspaceId, activeSessionId)] ?? []
68
+ const ready = pending.filter(a => a.status === 'ready' && a.upload)
69
+ // No `processing` guard: sending while a turn is in flight QUEUES the
70
+ // message into the same live server session (streaming-input mode).
71
+ if (!text && ready.length === 0) return
72
+
73
+ let sid = activeSessionId
74
+ let isNew = false
75
+ if (!sid) {
76
+ sid = crypto.randomUUID()
77
+ isNew = true
78
+ liveStore.getState().setActive(workspaceId, sid)
79
+ }
80
+
81
+ // Optimistic user turn — primed into the RQ transcript cache so it renders
82
+ // immediately. The server re-ids the SDK's user echo to optimisticId so it
83
+ // upserts in place rather than duplicating. Image attachments render from
84
+ // their local object URL until the server's broadcast (with a data URL)
85
+ // upserts in place.
86
+ const optimisticId = `optimistic:${crypto.randomUUID()}`
87
+ const parts: Part[] = []
88
+ for (const a of ready) {
89
+ if (a.upload?.kind === 'image' && a.previewUrl) {
90
+ parts.push({ type: 'file', mediaType: a.mediaType, url: a.previewUrl, filename: a.name })
91
+ } else {
92
+ parts.push({ type: 'file', mediaType: a.mediaType, url: '', filename: a.name })
93
+ }
62
94
  }
63
- })
95
+ if (text) parts.push({ type: 'text', text })
96
+ qc.setQueryData<ViewState>(workspaceKeys.events(workspaceId, sid), prev =>
97
+ applyEvent(prev ?? emptyViewState(), {
98
+ kind: 'turn',
99
+ turn: {
100
+ id: optimisticId,
101
+ role: 'user',
102
+ origin: { kind: 'user-input' },
103
+ parts,
104
+ timestamp: new Date().toISOString()
105
+ }
106
+ })
107
+ )
108
+ liveStore.getState().setProcessing(workspaceId, sid, true)
109
+ liveStore.getState().setError(workspaceId, sid, null)
64
110
 
65
- sendWs({ type: 'chat', content: text, sessionId: sid, isNew, optimisticId })
66
- store.getState().setError(sid, null)
67
- setInput('')
68
- }, [input, processing, activeSessionId, setActiveSession, store])
111
+ // The thread's persisted choice (workspace defaults for a new chat). Drop a
112
+ // model the loaded list no longer offers (stale alias) so the SDK doesn't
113
+ // reject model_not_found. Drop an effort the resolved model doesn't support
114
+ // (e.g. model changed under it); when the model is unknown/default we can't
115
+ // check, so pass it through — the SDK silently downgrades unsupported effort.
116
+ const pickedModel = threadCfg?.model ?? layout.selectedModel
117
+ const modelOk = !pickedModel || !models || models.some(m => m.value === pickedModel)
118
+ const model = modelOk ? pickedModel : undefined
119
+ const modelInfo = models?.find(m => m.value === model)
120
+ const pickedEffort = threadCfg?.effort ?? layout.selectedEffort
121
+ const effort =
122
+ pickedEffort &&
123
+ (!modelInfo || (modelInfo.supportedEffortLevels ?? []).includes(pickedEffort))
124
+ ? pickedEffort
125
+ : undefined
126
+ // Live token streaming is a compile-time dev flag (client/lib/flags.ts),
127
+ // gated to providers that support it. Send `true` or omit (never `false`),
128
+ // so a provider that ignores it behaves identically.
129
+ const stream = STREAM_RESPONSES && supportsStreaming ? true : undefined
130
+ sendMessage({
131
+ type: 'chat',
132
+ workspaceId,
133
+ content: text,
134
+ sessionId: sid,
135
+ isNew,
136
+ optimisticId,
137
+ model,
138
+ effort,
139
+ stream,
140
+ ...(ready.length > 0 ? { attachments: ready.map(a => a.upload!.id) } : {})
141
+ })
142
+ // Drop the thread's attachments now that they've been sent (revokes the
143
+ // preview object URLs). Keyed by the pre-mint id, matching where they were
144
+ // stored by the composer.
145
+ liveStore.getState().clearAttachments(workspaceId, activeSessionId)
146
+ },
147
+ [
148
+ activeSessionId,
149
+ workspaceId,
150
+ qc,
151
+ layout.selectedModel,
152
+ layout.selectedEffort,
153
+ threadCfg?.model,
154
+ threadCfg?.effort,
155
+ models,
156
+ supportsStreaming
157
+ ]
158
+ )
69
159
 
70
160
  const dismissError = useCallback(() => {
71
161
  if (!activeSessionId) return
72
- store.getState().setError(activeSessionId, null)
73
- }, [activeSessionId, store])
162
+ liveStore.getState().setError(workspaceId, activeSessionId, null)
163
+ }, [activeSessionId, workspaceId])
74
164
 
75
165
  const stop = useCallback(() => {
76
166
  if (!processing || !activeSessionId) return
77
- sendWs({ type: 'stop', sessionId: activeSessionId })
78
- }, [processing, activeSessionId])
167
+ sendMessage({ type: 'stop', workspaceId, sessionId: activeSessionId })
168
+ }, [processing, activeSessionId, workspaceId])
79
169
 
80
170
  const switchThread = useCallback(
81
171
  (sessionId: string | null) => {
82
- setActiveSession(sessionId)
172
+ liveStore.getState().setActive(workspaceId, sessionId)
83
173
  },
84
- [setActiveSession]
174
+ [workspaceId]
85
175
  )
86
176
 
87
- return { view, processing, error, input, setInput, send, stop, switchThread, dismissError }
177
+ return {
178
+ view,
179
+ previewTurn,
180
+ sessionId: activeSessionId,
181
+ processing,
182
+ error,
183
+ send,
184
+ stop,
185
+ switchThread,
186
+ dismissError
187
+ }
88
188
  }
@@ -1,11 +1,18 @@
1
1
  import { useEffect, useRef } from 'react'
2
2
 
3
- import type { WidgetInfo } from '@/lib/types'
3
+ import type { ViewInfo, WidgetInfo } from '@/lib/types'
4
4
 
5
- type MeiEvent =
5
+ export type MeiEvent =
6
6
  | { type: 'widget:updated'; name: string }
7
7
  | { type: 'widget-layout:updated'; widgets: WidgetInfo[] }
8
+ | { type: 'widgets:refresh' }
9
+ | { type: 'view:updated'; name: string }
10
+ | { type: 'view-layout:updated'; views: ViewInfo[] }
8
11
  | { type: 'theme:updated' }
12
+ | { type: 'workspace:updated' }
13
+ // The Scratchpad canvas for `workspaceId` was saved — open tabs reload from
14
+ // disk. `origin` is the tab that wrote it, so that tab can skip its own echo.
15
+ | { type: 'scratchpad:updated'; workspaceId: string; origin?: string }
9
16
 
10
17
  type MeiEventHandler = (event: MeiEvent) => void
11
18