moi-computer 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bunfig.toml +4 -0
- package/client/api/workspaces.ts +277 -6
- package/client/assets/mcp/agentation.png +0 -0
- package/client/assets/mcp/airtable.png +0 -0
- package/client/assets/mcp/apollo.png +0 -0
- package/client/assets/mcp/asana.png +0 -0
- package/client/assets/mcp/box.png +0 -0
- package/client/assets/mcp/chrome.svg +33 -0
- package/client/assets/mcp/clickup.png +0 -0
- package/client/assets/mcp/cloudflare.png +0 -0
- package/client/assets/mcp/context7.png +0 -0
- package/client/assets/mcp/datadog.png +0 -0
- package/client/assets/mcp/dropbox.png +0 -0
- package/client/assets/mcp/elevenlabs.png +0 -0
- package/client/assets/mcp/exa.png +0 -0
- package/client/assets/mcp/firecrawl.png +0 -0
- package/client/assets/mcp/gmail.png +0 -0
- package/client/assets/mcp/googlecalendar.png +0 -0
- package/client/assets/mcp/googledrive.png +0 -0
- package/client/assets/mcp/grafana.png +0 -0
- package/client/assets/mcp/huggingface.png +0 -0
- package/client/assets/mcp/intercom.png +0 -0
- package/client/assets/mcp/monday.png +0 -0
- package/client/assets/mcp/mongodb.png +0 -0
- package/client/assets/mcp/paper.png +0 -0
- package/client/assets/mcp/paypal.png +0 -0
- package/client/assets/mcp/perplexity.png +0 -0
- package/client/assets/mcp/postgresql.png +0 -0
- package/client/assets/mcp/posthog.png +0 -0
- package/client/assets/mcp/puppeteer.png +0 -0
- package/client/assets/mcp/railway.png +0 -0
- package/client/assets/mcp/redis.png +0 -0
- package/client/assets/mcp/salesforce.png +0 -0
- package/client/assets/mcp/shopify.png +0 -0
- package/client/assets/mcp/snowflake.png +0 -0
- package/client/assets/mcp/telegram.png +0 -0
- package/client/assets/mcp/twilio.png +0 -0
- package/client/assets/mcp/zapier.png +0 -0
- package/client/components/App.tsx +7 -1
- package/client/components/ChatInput.tsx +194 -13
- package/client/components/ChatPanel.tsx +116 -47
- package/client/components/ChatPopup.tsx +1 -1
- package/client/components/IconMcp.tsx +21 -0
- package/client/components/McpMenu.tsx +125 -0
- package/client/components/ModelPicker.tsx +147 -0
- package/client/components/Scratchpad.tsx +775 -0
- package/client/components/ShimmerText.tsx +20 -0
- package/client/components/ThreadSelector.tsx +2 -2
- package/client/components/TurnView.tsx +111 -531
- package/client/components/WidgetShell.tsx +1 -1
- package/client/components/WorkspacesPage.tsx +12 -4
- package/client/components/layout/SidebarLayout.tsx +18 -9
- package/client/components/playground/ToolCallsPage.tsx +81 -0
- package/client/components/routes/workspace/[id].tsx +534 -141
- package/client/components/routes/workspace/create.tsx +155 -0
- package/client/components/settings/IconPicker.tsx +590 -0
- package/client/components/settings/SettingsPages.tsx +307 -0
- package/client/components/settings/WorkspaceSettings.tsx +92 -0
- package/client/components/tool-group/CodeBlock.tsx +41 -0
- package/client/components/tool-group/Collapse.tsx +28 -0
- package/client/components/tool-group/ReadImagePreview.tsx +46 -0
- package/client/components/tool-group/SubagentCard.tsx +135 -0
- package/client/components/tool-group/TimelineRow.tsx +147 -0
- package/client/components/tool-group/ToolCallGroup.tsx +231 -0
- package/client/components/tool-group/ToolOutput.tsx +139 -0
- package/client/components/tool-group/detect.ts +93 -0
- package/client/components/tool-group/fixtures.ts +315 -0
- package/client/components/tool-group/format.ts +211 -0
- package/client/components/tool-group/index.ts +9 -0
- package/client/components/ui/dialog.tsx +58 -0
- package/client/components/ui/hover-card.tsx +44 -0
- package/client/components/ui/switch.tsx +23 -0
- package/client/components/ui/tooltip.tsx +54 -0
- package/client/externalize-react.ts +6 -0
- package/client/hooks/useApplet.ts +117 -0
- package/client/hooks/useChat.ts +162 -62
- package/client/hooks/useMeiEvents.ts +9 -2
- package/client/hooks/useStickToBottom.ts +86 -0
- package/client/hooks/useWorkspaceTheme.ts +8 -2
- package/client/index.css +48 -2
- package/client/index.html +9 -5
- package/client/index.tsx +29 -2
- package/client/lib/WorkspaceContext.tsx +5 -8
- package/client/lib/WorkspaceLayoutContext.tsx +30 -10
- package/client/lib/applet-cache.ts +54 -0
- package/client/lib/connection.ts +237 -0
- package/client/lib/flags.ts +10 -0
- package/client/lib/mcp-icons.ts +142 -10
- package/client/lib/preview-turn.ts +37 -0
- package/client/lib/render-icon.ts +173 -0
- package/client/lib/scratch-executor.ts +20 -0
- package/client/lib/uploads.ts +18 -0
- package/client/main.tsx +5 -0
- package/client/store/live.ts +282 -0
- package/client/structured-clone-shim.ts +14 -0
- package/client/theme.css +2 -2
- package/client/vendor/emojibase/en/data.json +1 -0
- package/client/vendor/emojibase/en/messages.json +1 -0
- package/client/vendor/react/development/_impl/react-dom-client.js +15871 -0
- package/client/vendor/react/development/_impl/react-dom.js +223 -0
- package/client/vendor/react/development/_impl/react-jsx-dev-runtime.js +256 -0
- package/client/vendor/react/development/_impl/react-jsx-runtime.js +260 -0
- package/client/vendor/react/development/_impl/react.js +863 -0
- package/client/vendor/react/development/react-dom-client.js +6 -0
- package/client/vendor/react/development/react-dom.js +17 -0
- package/client/vendor/react/development/react-jsx-dev-runtime.js +5 -0
- package/client/vendor/react/development/react-jsx-runtime.js +6 -0
- package/client/vendor/react/development/react.js +47 -0
- package/client/vendor/react/production/_impl/react-dom-client.js +10361 -0
- package/client/vendor/react/production/_impl/react-dom.js +184 -0
- package/client/vendor/react/production/_impl/react-jsx-dev-runtime.js +37 -0
- package/client/vendor/react/production/_impl/react-jsx-runtime.js +60 -0
- package/client/vendor/react/production/_impl/react.js +428 -0
- package/client/vendor/react/production/react-dom-client.js +6 -0
- package/client/vendor/react/production/react-dom.js +17 -0
- package/client/vendor/react/production/react-jsx-dev-runtime.js +5 -0
- package/client/vendor/react/production/react-jsx-runtime.js +6 -0
- package/client/vendor/react/production/react.js +47 -0
- package/dist/agentation-4s0nn45p.png +0 -0
- package/dist/airtable-hsa66v6q.png +0 -0
- package/dist/apollo-2ed5dy2d.png +0 -0
- package/dist/asana-tvgtwbx2.png +0 -0
- package/dist/box-w3n36t5g.png +0 -0
- package/dist/chrome-tspm94rw.svg +33 -0
- package/dist/chunk-kc6e9nd4.css +1 -0
- package/dist/chunk-yf3p7qg7.js +673 -0
- package/dist/clickup-qqrqqvqb.png +0 -0
- package/dist/cloudflare-j9p931v6.png +0 -0
- package/dist/context7-8ht0xjfy.png +0 -0
- package/dist/datadog-70ne3yzt.png +0 -0
- package/dist/dropbox-4m5s9mgr.png +0 -0
- package/dist/elevenlabs-2nzzej1t.png +0 -0
- package/dist/exa-qqj3vr0x.png +0 -0
- package/dist/firecrawl-w2t8nehx.png +0 -0
- package/dist/gmail-sg6a5v3x.png +0 -0
- package/dist/googlecalendar-nqhh2v7r.png +0 -0
- package/dist/googledrive-6s8xyab7.png +0 -0
- package/dist/grafana-1yfsnwr6.png +0 -0
- package/dist/huggingface-kxzaxj83.png +0 -0
- package/dist/index.html +10 -6
- package/dist/intercom-td763jt8.png +0 -0
- package/dist/monday-jdbs4wwf.png +0 -0
- package/dist/mongodb-emzxvhd5.png +0 -0
- package/dist/paper-zbt34fab.png +0 -0
- package/dist/paypal-kwwf7xsc.png +0 -0
- package/dist/perplexity-4y63rxvj.png +0 -0
- package/dist/postgresql-qsspbsr1.png +0 -0
- package/dist/posthog-sphppc4w.png +0 -0
- package/dist/puppeteer-2xjt1a9b.png +0 -0
- package/dist/railway-834de8d2.png +0 -0
- package/dist/redis-spm6w2m1.png +0 -0
- package/dist/salesforce-1mk56v4z.png +0 -0
- package/dist/shopify-90dadaav.png +0 -0
- package/dist/snowflake-hfpykpgy.png +0 -0
- package/dist/telegram-v6tjyrs7.png +0 -0
- package/dist/twilio-dpyjdwpj.png +0 -0
- package/dist/zapier-p67qfch0.png +0 -0
- package/lib/attachment-note.ts +48 -0
- package/lib/claude-adapter.ts +219 -29
- package/lib/format.ts +32 -0
- package/lib/types.ts +314 -6
- package/package.json +10 -5
- package/server/CLAUDE.md +3 -0
- package/server/agent.ts +25 -118
- package/server/api.ts +593 -0
- package/server/applets.ts +396 -0
- package/server/build-applet.ts +580 -0
- package/server/cc-session.ts +611 -0
- package/server/cli-colors.ts +17 -0
- package/server/cli-ui.ts +52 -0
- package/server/cli.ts +964 -72
- package/server/control.ts +166 -19
- package/server/debug.ts +10 -0
- package/server/events.ts +24 -0
- package/server/functions-worker.ts +18 -2
- package/server/functions.ts +59 -12
- package/server/icon.ts +13 -0
- package/server/layout.ts +25 -3
- package/server/mcp.ts +125 -0
- package/server/moi-scaffold.ts +85 -0
- package/server/openclaw-session.ts +41 -10
- package/server/openclaw.ts +22 -0
- package/server/preview.ts +70 -0
- package/server/registry.ts +32 -2
- package/server/scratchpad-executor.ts +380 -0
- package/server/scratchpad-relay.ts +45 -0
- package/server/scratchpad.ts +171 -0
- package/server/skill-version.ts +146 -0
- package/server/skills-template.ts +6 -1
- package/server/state.ts +22 -36
- package/server/static.ts +23 -0
- package/server/status.ts +94 -0
- package/server/thread-config.ts +125 -0
- package/server/uploads.ts +0 -0
- package/server/vendor.ts +63 -0
- package/server/views.ts +0 -0
- package/server/web.ts +108 -253
- package/server/widgets.ts +52 -142
- package/server/workspace-config.ts +37 -0
- package/server/workspace-env.ts +407 -0
- package/server/workspace-init.ts +66 -0
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +109 -0
- package/workspace/.claude/skills/moi-workspace/SCRATCHPAD.md +57 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +252 -0
- package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +22 -0
- package/client/hooks/useWidget.ts +0 -72
- package/client/hooks/useWidgetList.ts +0 -30
- package/client/lib/ws.ts +0 -129
- package/client/store/chat.tsx +0 -162
- package/dist/chunk-4615fa69.js +0 -67
- package/dist/chunk-582xmy05.css +0 -1
- package/server/build-widget.ts +0 -343
- package/workspace/.claude/skills/widgets/DESIGN.md +0 -630
- package/workspace/.claude/skills/widgets/SKILL.md +0 -176
package/server/widgets.ts
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 } =
|
|
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 } =
|
|
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
|
|
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
|
-
|
|
111
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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 ${
|
|
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
|
|
72
|
+
return results
|
|
167
73
|
}
|
|
168
74
|
|
|
169
|
-
export
|
|
170
|
-
const { buildDir } =
|
|
171
|
-
|
|
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
|
-
|
|
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
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
+
}
|