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,85 @@
1
+ // Scaffolding for a workspace's `.moi/` root, laid down by `moi init` (and
2
+ // `moi openclaw init`). Creates `.moi/widgets/`, writes the widget
3
+ // dependency manifest, and installs dependencies — so the agent never has to
4
+ // bootstrap the folder itself.
5
+ import { mkdir } from 'node:fs/promises'
6
+ import { join, resolve, sep } from 'node:path'
7
+
8
+ // Dependency set available to widgets. `react`/`react-dom` are stubs — at
9
+ // runtime they resolve to Moi's locally-vendored ESM via the browser importmap
10
+ // (/vendor/react); they're listed so editors pick up the correct types.
11
+ export const MOI_PACKAGE_JSON = {
12
+ name: 'widgets',
13
+ private: true,
14
+ dependencies: {
15
+ '@tabler/icons-react': '^3.40.0',
16
+ tailwindcss: '^4.0.0',
17
+ react: '^19.0.0',
18
+ 'react-dom': '^19.0.0'
19
+ },
20
+ devDependencies: {
21
+ '@types/react': '^19.0.0',
22
+ '@types/react-dom': '^19.0.0'
23
+ }
24
+ } as const
25
+
26
+ // Ambient types for applets (widgets & views). Editor DX only — the moi
27
+ // bundler resolves the `moi` module and asset imports at build time without any
28
+ // declarations. Lives at `.moi/` root, NOT inside widgets/views, so it isn't
29
+ // picked up by the `.ts` build glob and compiled as an applet.
30
+ export const APPLET_ENV_DTS = `// Auto-generated by \`moi init\`. Ambient types for widgets & views.
31
+ // Editor/\`tsc\` only — the moi bundler needs no declarations.
32
+
33
+ declare module 'moi' {
34
+ // Absolute URL to a workspace file, streamed by the server. Pass a
35
+ // workspace-relative path (e.g. 'clips/001.mp4'). Media/asset files only.
36
+ export function fileUrl(path: string): string
37
+ export type WidgetConfig = {
38
+ rowSpan: 1 | 2 | 3 | 4
39
+ colSpan: 1 | 2 | 3 | 4
40
+ requiredEnv?: string[]
41
+ }
42
+ export type ViewConfig = { title?: string; requiredEnv?: string[] }
43
+ }
44
+
45
+ // Bundled asset imports (\`import logo from './logo.png'\`) resolve to a URL string.
46
+ declare module '*.png' { const s: string; export default s }
47
+ declare module '*.jpg' { const s: string; export default s }
48
+ declare module '*.jpeg' { const s: string; export default s }
49
+ declare module '*.gif' { const s: string; export default s }
50
+ declare module '*.webp' { const s: string; export default s }
51
+ declare module '*.avif' { const s: string; export default s }
52
+ declare module '*.svg' { const s: string; export default s }
53
+ `
54
+
55
+ // Bootstraps `.moi/` ONLY when it doesn't exist yet. Re-running `moi init`
56
+ // on an existing workspace overwrites skills but must leave the user's
57
+ // `.moi/` (their deps, widgets, lockfile) completely untouched.
58
+ // Returns 'exists' when skipped, otherwise the `bun install` exit code.
59
+ export async function scaffoldMoiDir(workspacePath: string): Promise<'exists' | number> {
60
+ // Backstop against the nested-workspace bug: never scaffold a `.moi/` *inside*
61
+ // another workspace's `.moi/` (which produces the junk `.moi/.moi`). Callers
62
+ // (`moi init`) lift to the workspace root via `liftToWorkspaceRoot` first, so
63
+ // this only fires on a programmer error.
64
+ if (resolve(workspacePath).split(sep).includes('.moi')) {
65
+ throw new Error(
66
+ `Refusing to scaffold a workspace inside a .moi directory: ${workspacePath}. ` +
67
+ 'Run from the workspace root.'
68
+ )
69
+ }
70
+ const moiDir = join(workspacePath, '.moi')
71
+ if (await Bun.file(join(moiDir, 'package.json')).exists()) return 'exists'
72
+ // A bare `.moi/` dir without package.json counts as not-bootstrapped —
73
+ // fill in the missing pieces.
74
+
75
+ await mkdir(join(moiDir, 'widgets'), { recursive: true })
76
+ await Bun.write(join(moiDir, 'package.json'), JSON.stringify(MOI_PACKAGE_JSON, null, 2) + '\n')
77
+ await Bun.write(join(moiDir, 'applet-env.d.ts'), APPLET_ENV_DTS)
78
+
79
+ const install = Bun.spawn(['bun', 'install'], {
80
+ cwd: moiDir,
81
+ stdout: 'ignore',
82
+ stderr: 'inherit'
83
+ })
84
+ return await install.exited
85
+ }
@@ -11,8 +11,9 @@
11
11
  // `session.message` rows only, per the design call).
12
12
  // - Disk persistence — the gateway is the source of truth; we re-seed from
13
13
  // `sessions.get` on cold start.
14
+ import { appendAttachmentNote } from '@/lib/attachment-note'
14
15
  import { applyEvent, emptyViewState } from '@/lib/format'
15
- import type { ServerMessage, StreamEvent, ViewState } from '@/lib/types'
16
+ import type { StreamEvent, ViewState } from '@/lib/types'
16
17
 
17
18
  import {
18
19
  type OpenClawMessage,
@@ -27,6 +28,7 @@ import {
27
28
  } from './openclaw-adapter'
28
29
  import { getGateway, onGatewayReconnected } from './openclaw-gateway'
29
30
  import { broadcast } from './state'
31
+ import { materializeToPath, resolveUploads } from './uploads'
30
32
 
31
33
  type OpenClawSessionKey = string // the gateway-side composite key, e.g. `agent:main:main`
32
34
 
@@ -80,12 +82,14 @@ function recKey(workspaceId: string, sessionId: string): string {
80
82
  return `${workspaceId}:${sessionId}`
81
83
  }
82
84
 
83
- export function getOpenClawProcessingSessions(workspaceId: string): string[] {
84
- const out: string[] = []
85
+ // All running OpenClaw sessions across every workspace, for the connect-time
86
+ // status snapshot. Key is `${workspaceId}:${sessionId}` (both are colon-free).
87
+ export function getOpenClawRunningSessions(): { workspaceId: string; sessionId: string }[] {
88
+ const out: { workspaceId: string; sessionId: string }[] = []
85
89
  for (const [k, v] of openclawAgents) {
86
90
  if (!v.processing) continue
87
- if (!k.startsWith(workspaceId + ':')) continue
88
- out.push(k.slice(workspaceId.length + 1))
91
+ const i = k.indexOf(':')
92
+ out.push({ workspaceId: k.slice(0, i), sessionId: k.slice(i + 1) })
89
93
  }
90
94
  return out
91
95
  }
@@ -177,11 +181,7 @@ function emitTurn(rec: SessionRecord, msg: OpenClawMessage, idx: number): void {
177
181
  }
178
182
  }
179
183
  rec.view = applyEvent(rec.view, { kind: 'turn', turn })
180
- broadcast(rec.workspaceId, {
181
- kind: 'turn',
182
- turn,
183
- sessionId: rec.sessionId
184
- } as ServerMessage)
184
+ broadcast(rec.workspaceId, { kind: 'turn', turn, sessionId: rec.sessionId })
185
185
  }
186
186
 
187
187
  function ingest(rec: SessionRecord, msg: OpenClawMessage): void {
@@ -362,6 +362,37 @@ export function viewAsEvents(rec: SessionRecord): StreamEvent[] {
362
362
  }
363
363
 
364
364
  export async function sendOpenClawMessage(input: {
365
+ workspaceId: string
366
+ workspacePath: string
367
+ agentId: string
368
+ sessionId: string
369
+ isNew: boolean
370
+ content: string
371
+ // Upload ids. Basic support: the gateway's `sessions.send` only takes a string
372
+ // message, so we materialize each upload to a temp file and append the paths
373
+ // for the agent to read. Rich vision blocks await a gateway content-block API
374
+ // (see dev/file-uploads.md).
375
+ attachments?: string[]
376
+ optimisticId?: string
377
+ }): Promise<void> {
378
+ // Fold any attachments into the message text as file-path references.
379
+ let content = input.content
380
+ if (input.attachments?.length) {
381
+ const uploads = resolveUploads(input.workspaceId, input.attachments)
382
+ const files: { filename: string; path: string }[] = []
383
+ for (const u of uploads) {
384
+ const p = await materializeToPath(u)
385
+ if (p) files.push({ filename: u.filename, path: p })
386
+ }
387
+ content = appendAttachmentNote(input.content, files)
388
+ }
389
+ // Attachment-only send whose ids all expired → nothing to say; don't open a
390
+ // session for an empty message.
391
+ if (!content) return
392
+ return sendOpenClawMessageImpl({ ...input, content })
393
+ }
394
+
395
+ async function sendOpenClawMessageImpl(input: {
365
396
  workspaceId: string
366
397
  workspacePath: string
367
398
  agentId: string
@@ -2,6 +2,8 @@ import { readFile } from 'node:fs/promises'
2
2
  import { homedir } from 'node:os'
3
3
  import { join, resolve } from 'node:path'
4
4
 
5
+ import type { Model } from '@/lib/types'
6
+
5
7
  export type OpenClawAgent = {
6
8
  path: string
7
9
  agentId: string
@@ -204,3 +206,23 @@ export async function getOpenClawSessionMessages(
204
206
  })
205
207
  return out ?? null
206
208
  }
209
+
210
+ // One entry from the gateway's `models.list` catalog. The catalog is
211
+ // gateway-wide (no per-agent param) — the allowed model set filtered by config.
212
+ type OpenClawModelChoice = {
213
+ id: string
214
+ name: string
215
+ provider: string
216
+ alias?: string
217
+ contextWindow?: number
218
+ reasoning?: boolean
219
+ }
220
+
221
+ export async function getOpenClawModels(): Promise<Model[]> {
222
+ const out = await withGatewayClient(async rpc => {
223
+ const res = await rpc<{ models: OpenClawModelChoice[] }>('models.list')
224
+ return res.models
225
+ })
226
+ // Map the gateway catalog onto the raw Model shape (value/displayName).
227
+ return (out ?? []).map(m => ({ value: m.id, displayName: m.name }))
228
+ }
@@ -0,0 +1,70 @@
1
+ // Downscaled image previews of workspace files.
2
+ //
3
+ // Backs GET /api/workspaces/:id/preview/<path>, used by the chat's expanded
4
+ // tool rows: when the agent `Read`s an image from the workspace, the row shows
5
+ // the actual picture instead of just the path. Same hard guards as the raw
6
+ // `/fs/` stream (resolveWorkspaceMediaFile), but scoped to image extensions and
7
+ // resized server-side so a huge screenshot doesn't ship megabytes to render a
8
+ // 300px-tall preview.
9
+ //
10
+ // Workspace files change under the agent, so responses are revalidated instead
11
+ // of cached blindly: ETag from (size, mtime) + `no-cache`, so an unchanged file
12
+ // costs a 304 and an edited one re-renders.
13
+ import { statSync } from 'node:fs'
14
+
15
+ import sharp from 'sharp'
16
+
17
+ import { resolveWorkspaceMediaFile } from './applets'
18
+
19
+ // Long edge of the rendered preview. 2× the ~300px display size keeps it crisp
20
+ // on retina without shipping the original.
21
+ const PREVIEW_MAX_EDGE = 800
22
+
23
+ // Everything sharp can decode gets resized + re-encoded to webp. SVG and GIF
24
+ // stream raw instead: SVG scales for free, and resizing a GIF would drop its
25
+ // animation.
26
+ const RESIZE_RE = /\.(png|jpe?g|webp|avif)$/i
27
+ const PASSTHROUGH_RE = /\.(gif|svg)$/i
28
+
29
+ export async function serveWorkspaceImagePreview(
30
+ workspaceRoot: string,
31
+ tail: string,
32
+ ifNoneMatch?: string | null
33
+ ): Promise<Response> {
34
+ const resize = RESIZE_RE.test(tail)
35
+ if (!resize && !PASSTHROUGH_RE.test(tail)) {
36
+ return new Response('Not an image', { status: 415 })
37
+ }
38
+ const realTarget = resolveWorkspaceMediaFile(workspaceRoot, tail)
39
+ if (realTarget instanceof Response) return realTarget
40
+
41
+ let stat: ReturnType<typeof statSync>
42
+ try {
43
+ stat = statSync(realTarget)
44
+ } catch {
45
+ return new Response('Not found', { status: 404 })
46
+ }
47
+ const etag = `"${stat.size}-${Math.trunc(stat.mtimeMs)}${resize ? `-${PREVIEW_MAX_EDGE}` : ''}"`
48
+ const headers: Record<string, string> = { ETag: etag, 'Cache-Control': 'private, no-cache' }
49
+ if (ifNoneMatch === etag) return new Response(null, { status: 304, headers })
50
+
51
+ if (!resize) {
52
+ const file = Bun.file(realTarget)
53
+ return new Response(file, {
54
+ headers: { ...headers, 'Content-Type': file.type || 'application/octet-stream' }
55
+ })
56
+ }
57
+
58
+ try {
59
+ const data = await sharp(realTarget)
60
+ .rotate()
61
+ .resize(PREVIEW_MAX_EDGE, PREVIEW_MAX_EDGE, { fit: 'inside', withoutEnlargement: true })
62
+ .webp({ quality: 80 })
63
+ .toBuffer()
64
+ return new Response(data, { headers: { ...headers, 'Content-Type': 'image/webp' } })
65
+ } catch {
66
+ // Undecodable (corrupt, or an unsupported codec despite the extension) —
67
+ // there's no preview to show; the client hides the <img> on error.
68
+ return new Response('Preview failed', { status: 415 })
69
+ }
70
+ }
@@ -1,7 +1,7 @@
1
1
  import envPaths from 'env-paths'
2
2
  import { mkdir } from 'node:fs/promises'
3
3
  import { homedir } from 'node:os'
4
- import { join, resolve } from 'path'
4
+ import { join, resolve, sep } from 'path'
5
5
 
6
6
  import type { DiscoveredWorkspace, WorkspaceEntry, WorkspaceType } from '@/lib/types'
7
7
 
@@ -9,7 +9,7 @@ import { type OpenClawAgent, discoverOpenClawAgents } from './openclaw'
9
9
 
10
10
  // Replace the home-dir prefix with `~` for display. Keeps the original
11
11
  // absolute path in place; callers should put the result in `displayPath`.
12
- function tildify(absPath: string): string {
12
+ export function tildify(absPath: string): string {
13
13
  const home = homedir()
14
14
  if (!home) return absPath
15
15
  if (absPath === home) return '~'
@@ -93,6 +93,36 @@ export async function listWorkspaces(): Promise<WorkspaceEntry[]> {
93
93
  return entries.map(withDisplayPath)
94
94
  }
95
95
 
96
+ // Resolve a path to the registered workspace that *contains* it: the entry
97
+ // whose path equals `reqPath` or is its nearest ancestor (longest matching
98
+ // prefix, git-style). This lets workspace-scoped commands (e.g. `moi bundle`)
99
+ // run from `.moi/` or any subdirectory and still target the real root, instead
100
+ // of treating the CWD as a workspace and scaffolding a phantom nested `.moi/`.
101
+ // Returns null when the path is not inside any registered workspace.
102
+ export function findWorkspaceForPath<T extends { path: string }>(
103
+ workspaces: T[],
104
+ reqPath: string
105
+ ): T | null {
106
+ const normal = resolve(reqPath)
107
+ const matches = workspaces.filter(w => normal === w.path || normal.startsWith(w.path + sep))
108
+ if (matches.length === 0) return null
109
+ return matches.reduce((best, w) => (w.path.length > best.path.length ? w : best))
110
+ }
111
+
112
+ // If `p` lies inside a workspace's `.moi/` directory, return the workspace root
113
+ // (the directory that contains that `.moi`); otherwise return `p` unchanged.
114
+ // Cuts at the FIRST `.moi` segment, so an accidentally-nested `.moi/.moi/…`
115
+ // path lifts all the way back to the real root. Pure (no filesystem access) —
116
+ // `moi init` uses it so running from inside `.moi` never creates a nested
117
+ // workspace, and the command always targets the real workspace root.
118
+ export function liftToWorkspaceRoot(p: string): string {
119
+ const normal = resolve(p)
120
+ const segments = normal.split(sep)
121
+ const i = segments.indexOf('.moi')
122
+ if (i === -1) return normal
123
+ return segments.slice(0, i).join(sep) || sep
124
+ }
125
+
96
126
  // Discover CC-active directories not yet in the registry
97
127
  async function discoverFromCC(registeredPaths: Set<string>): Promise<string[]> {
98
128
  try {