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
package/server/widgets.ts CHANGED
@@ -1,23 +1,18 @@
1
- import { mkdir, readdir, unlink } from 'node:fs/promises'
2
- import { join } from 'path'
1
+ import { existsSync } from 'node:fs'
3
2
 
4
3
  import type { WidgetConfig, WidgetInfo } from '@/lib/types'
5
4
 
6
- import { buildWidget } from './build-widget'
5
+ import { buildApplets, getAppletPaths, listBuilt, serveApplet } from './applets'
7
6
  import { reloadModules } from './functions'
8
7
 
9
8
  const DEFAULT_CONFIG: WidgetConfig = { rowSpan: 1, colSpan: 2 }
10
9
  const VALID_SPANS = [1, 2, 3, 4]
11
10
 
12
- function getWidgetPaths(workspacePath: string) {
13
- const sourceDir = join(workspacePath, '.widgets')
14
- const buildDir = join(sourceDir, '.build', 'widgets')
15
- const manifestPath = join(buildDir, 'manifest.json')
16
- return { sourceDir, buildDir, manifestPath }
17
- }
18
-
11
+ // The widget applet kind. Sources in `.moi/widgets/`, compiled output +
12
+ // manifest in `.moi/.build/widgets/`; the shared mechanics live in
13
+ // `applets.ts`. Manifest shape: `{ config: { <name>: WidgetConfig } }`.
19
14
  async function readManifest(workspacePath: string): Promise<Record<string, WidgetConfig>> {
20
- const { manifestPath } = getWidgetPaths(workspacePath)
15
+ const { manifestPath } = getAppletPaths(workspacePath, 'widget')
21
16
  try {
22
17
  const data = JSON.parse(await Bun.file(manifestPath).text())
23
18
  return data.config ?? {}
@@ -30,62 +25,10 @@ async function writeManifest(
30
25
  workspacePath: string,
31
26
  configs: Record<string, WidgetConfig>
32
27
  ): Promise<void> {
33
- const { manifestPath } = getWidgetPaths(workspacePath)
28
+ const { manifestPath } = getAppletPaths(workspacePath, 'widget')
34
29
  await Bun.write(manifestPath, JSON.stringify({ config: configs }, null, 2))
35
30
  }
36
31
 
37
- async function scanWidgets(workspacePath: string): Promise<string[]> {
38
- const { sourceDir } = getWidgetPaths(workspacePath)
39
- try {
40
- const entries = await readdir(sourceDir)
41
- return entries
42
- .filter(f => /\.(tsx|ts)$/.test(f) && !f.endsWith('.server.ts'))
43
- .map(f => f.replace(/\.tsx?$/, ''))
44
- } catch {
45
- return []
46
- }
47
- }
48
-
49
- async function resolveWidgetSource(workspacePath: string, name: string): Promise<string | null> {
50
- const { sourceDir } = getWidgetPaths(workspacePath)
51
- for (const ext of ['.tsx', '.ts']) {
52
- const path = join(sourceDir, `${name}${ext}`)
53
- if (await Bun.file(path).exists()) return path
54
- }
55
- return null
56
- }
57
-
58
- async function needsRebuild(
59
- workspacePath: string,
60
- name: string,
61
- srcPath: string
62
- ): Promise<boolean> {
63
- const { sourceDir, buildDir } = getWidgetPaths(workspacePath)
64
- const built = Bun.file(join(buildDir, `${name}.js`))
65
- if (!(await built.exists())) return true
66
- // Also stat the sibling `<name>.server.ts` if it exists. The main `.tsx`
67
- // imports `./<name>.server` and the build inlines RPC stubs for its
68
- // exports, so a server-only edit must trigger a rebuild — but its mtime
69
- // lives on a different file than `srcPath`.
70
- const serverPath = join(sourceDir, `${name}.server.ts`)
71
- const serverFile = Bun.file(serverPath)
72
- const serverMtime = (await serverFile.exists()) ? serverFile.lastModified : 0
73
- const sourceMtime = Math.max(Bun.file(srcPath).lastModified, serverMtime)
74
- return sourceMtime >= built.lastModified
75
- }
76
-
77
- async function pruneStaleBuilds(workspacePath: string, sourceNames: Set<string>) {
78
- const built = await listBuiltWidgets(workspacePath)
79
- const { buildDir } = getWidgetPaths(workspacePath)
80
- for (const name of built) {
81
- if (!sourceNames.has(name)) {
82
- try {
83
- await unlink(join(buildDir, `${name}.js`))
84
- } catch {}
85
- }
86
- }
87
- }
88
-
89
32
  export type WidgetBuildResult = {
90
33
  name: string
91
34
  status: 'built' | 'skipped' | 'failed'
@@ -98,64 +41,27 @@ export async function buildAllWidgets(
98
41
  workspacePath: string,
99
42
  force = false
100
43
  ): Promise<WidgetBuildResult[]> {
101
- const t0 = performance.now()
102
- const { buildDir } = getWidgetPaths(workspacePath)
103
- const names = await scanWidgets(workspacePath)
104
-
105
- await mkdir(buildDir, { recursive: true })
106
- await pruneStaleBuilds(workspacePath, new Set(names))
44
+ const { names, results, ms } = await buildApplets<WidgetConfig>(workspacePath, 'widget', force)
107
45
 
108
46
  const manifest = await readManifest(workspacePath)
109
-
110
- const jobs = await Promise.all(
111
- names.map(async name => {
112
- const srcPath = await resolveWidgetSource(workspacePath, name)
113
- if (!srcPath) {
114
- return { name, status: 'failed' as const, error: 'Source file not found' }
115
- }
116
- if (!force && !(await needsRebuild(workspacePath, name, srcPath))) {
117
- return { name, status: 'skipped' as const }
118
- }
119
- return { name, srcPath, status: 'pending' as const }
120
- })
121
- )
122
-
123
- const buildResults = await Promise.all(
124
- jobs.map(async (job): Promise<WidgetBuildResult> => {
125
- if (job.status === 'failed') return { name: job.name, status: 'failed', error: job.error }
126
- if (job.status === 'skipped') return { name: job.name, status: 'skipped' }
127
-
128
- const { buildDir: bd } = getWidgetPaths(workspacePath)
129
- try {
130
- const artifact = await buildWidget(job.srcPath!)
131
- await Bun.write(join(bd, `${job.name}.js`), artifact.js)
132
- manifest[job.name] = artifact.config ?? DEFAULT_CONFIG
133
- return {
134
- name: job.name,
135
- status: 'built',
136
- serverModules: artifact.serverModules.map(m => m.name),
137
- config: artifact.config
138
- }
139
- } catch (err) {
140
- return {
141
- name: job.name,
142
- status: 'failed',
143
- error: err instanceof Error ? err.message : 'Unknown error'
144
- }
145
- }
146
- })
147
- )
148
-
47
+ for (const r of results) {
48
+ if (r.status === 'built') manifest[r.name] = r.config ?? DEFAULT_CONFIG
49
+ }
149
50
  for (const key of Object.keys(manifest)) {
150
51
  if (!names.includes(key)) delete manifest[key]
151
52
  }
152
-
153
- await writeManifest(workspacePath, manifest)
154
-
155
- const builtCount = buildResults.filter(r => r.status === 'built').length
156
- const failed = buildResults.filter(r => r.status === 'failed')
53
+ // Persist only when there's a build dir to hold the manifest. `buildApplets`
54
+ // creates it only when ≥1 source exists; skipping the write here keeps a
55
+ // workspace with no widgets a true no-op on disk (no scaffolded `.build/`),
56
+ // while a previously-built workspace whose sources were all deleted still gets
57
+ // its emptied manifest rewritten.
58
+ const { buildDir } = getAppletPaths(workspacePath, 'widget')
59
+ if (existsSync(buildDir)) await writeManifest(workspacePath, manifest)
60
+
61
+ const builtCount = results.filter(r => r.status === 'built').length
62
+ const failed = results.filter(r => r.status === 'failed')
157
63
  console.log(
158
- `[bundle] ${builtCount}/${names.length} built in ${Math.round(performance.now() - t0)}ms` +
64
+ `[bundle] ${builtCount}/${names.length} widgets built in ${ms}ms` +
159
65
  (failed.length ? `, ${failed.length} failed` : '') +
160
66
  (force ? ' (forced)' : '')
161
67
  )
@@ -163,17 +69,12 @@ export async function buildAllWidgets(
163
69
  console.error(`[bundle] ${r.name}:\n${r.error}`)
164
70
  }
165
71
 
166
- return buildResults
72
+ return results
167
73
  }
168
74
 
169
- export async function listBuiltWidgets(workspacePath: string): Promise<string[]> {
170
- const { buildDir } = getWidgetPaths(workspacePath)
171
- try {
172
- const entries = await readdir(buildDir)
173
- return entries.filter(f => f.endsWith('.js')).map(f => f.replace(/\.js$/, ''))
174
- } catch {
175
- return []
176
- }
75
+ export function listBuiltWidgets(workspacePath: string): Promise<string[]> {
76
+ const { buildDir } = getAppletPaths(workspacePath, 'widget')
77
+ return listBuilt(buildDir)
177
78
  }
178
79
 
179
80
  async function getWidgetList(workspacePath: string): Promise<WidgetInfo[]> {
@@ -185,10 +86,28 @@ async function getWidgetList(workspacePath: string): Promise<WidgetInfo[]> {
185
86
  const raw = manifest[id] ?? {}
186
87
  const rowSpan = VALID_SPANS.includes(raw.rowSpan) ? raw.rowSpan : DEFAULT_CONFIG.rowSpan
187
88
  const colSpan = VALID_SPANS.includes(raw.colSpan) ? raw.colSpan : DEFAULT_CONFIG.colSpan
188
- return { id, config: { rowSpan, colSpan } as WidgetConfig }
89
+ const requiredEnv = Array.isArray(raw.requiredEnv) ? raw.requiredEnv : undefined
90
+ return {
91
+ id,
92
+ config: { rowSpan, colSpan, ...(requiredEnv ? { requiredEnv } : {}) } as WidgetConfig
93
+ }
189
94
  })
190
95
  }
191
96
 
97
+ // Collect env vars declared via widget `config.requiredEnv`, mapping each key to
98
+ // the widget ids that asked for it. Feeds the env API's "required" view.
99
+ export async function collectRequiredEnv(workspacePath: string): Promise<Record<string, string[]>> {
100
+ const manifest = await readManifest(workspacePath)
101
+ const out: Record<string, string[]> = {}
102
+ for (const [id, cfg] of Object.entries(manifest)) {
103
+ if (!Array.isArray(cfg.requiredEnv)) continue
104
+ for (const key of cfg.requiredEnv) {
105
+ ;(out[key] ??= []).push(id)
106
+ }
107
+ }
108
+ return out
109
+ }
110
+
192
111
  export async function listWidgets(workspacePath: string): Promise<Response> {
193
112
  return Response.json({ widgets: await getWidgetList(workspacePath) })
194
113
  }
@@ -235,20 +154,11 @@ export async function handleBundle(
235
154
  return results
236
155
  }
237
156
 
238
- export async function serveWidget(name: string, workspacePath: string): Promise<Response> {
239
- if (!/^[a-zA-Z0-9_-]+$/.test(name)) {
240
- return new Response('Invalid widget name', { status: 400 })
241
- }
242
-
243
- const { buildDir } = getWidgetPaths(workspacePath)
244
- const buildPath = join(buildDir, `${name}.js`)
245
- const file = Bun.file(buildPath)
246
-
247
- if (!(await file.exists())) {
248
- return new Response(`Widget "${name}" not built. Run: moi bundle`, { status: 404 })
249
- }
250
-
251
- return new Response(file, {
252
- headers: { 'Content-Type': 'application/javascript' }
253
- })
157
+ export function serveWidget(
158
+ name: string,
159
+ file: string,
160
+ workspacePath: string,
161
+ apiBase: string
162
+ ): Promise<Response> {
163
+ return serveApplet('widget', name, file, workspacePath, apiBase)
254
164
  }
@@ -0,0 +1,37 @@
1
+ import type { WorkspaceLayout } from '@/lib/types'
2
+
3
+ import { loadLayout, saveLayout } from './layout'
4
+
5
+ // Workspace identity stored in the layout: a display-name override and an icon
6
+ // (base64 data URL). Both optional; absent values fall back to provider/folder
7
+ // defaults at the API layer.
8
+ export type WorkspaceConfig = {
9
+ name?: string
10
+ icon?: string
11
+ }
12
+
13
+ export async function getWorkspaceConfig(workspacePath: string): Promise<WorkspaceConfig> {
14
+ const layout = await loadLayout(workspacePath)
15
+ return { name: layout.name, icon: layout.icon }
16
+ }
17
+
18
+ // Apply a name/icon patch to the workspace layout. For each field: a value
19
+ // sets it, `null` clears it, and `undefined` leaves it unchanged. Callers
20
+ // broadcast `workspace:updated` afterwards to refresh connected clients.
21
+ export async function setWorkspaceConfig(
22
+ workspacePath: string,
23
+ patch: { name?: string | null; icon?: string | null }
24
+ ): Promise<WorkspaceLayout> {
25
+ const layout = await loadLayout(workspacePath)
26
+ const next: WorkspaceLayout = { ...layout }
27
+ if (patch.name !== undefined) {
28
+ if (patch.name) next.name = patch.name
29
+ else delete next.name
30
+ }
31
+ if (patch.icon !== undefined) {
32
+ if (patch.icon) next.icon = patch.icon
33
+ else delete next.icon
34
+ }
35
+ await saveLayout(next, workspacePath)
36
+ return next
37
+ }