moi-computer 0.11.1-next.2 → 0.11.1-next.4
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/README.md +2 -2
- package/client/app/AppRouter.tsx +2 -2
- package/client/app/routes/WorkspaceRoute.tsx +7 -9
- package/client/app/shell/SidebarLayout.tsx +18 -15
- package/client/components/shared/BottomPanel.tsx +26 -14
- package/client/components/shared/PanelHeader.tsx +1 -1
- package/client/components/shared/ReorderableList.tsx +7 -2
- package/client/components/shared/WorkspaceIcon.tsx +92 -0
- package/client/components/ui/alert-dialog.tsx +1 -0
- package/client/components/ui/checkbox.tsx +1 -0
- package/client/components/ui/inline-input.tsx +84 -0
- package/client/components/ui/toast.tsx +2 -2
- package/client/features/applets/AppletMount.tsx +1 -1
- package/client/features/applets/applet-cache.ts +3 -3
- package/client/features/applets/applet-runtime.ts +147 -108
- package/client/features/applets/applet-styles.ts +2 -2
- package/client/features/applets/applet-thumbnail.ts +6 -8
- package/client/features/applets/useApplet.ts +10 -9
- package/client/features/chat/ChatPanel.tsx +19 -10
- package/client/features/chat/ChatPopup.tsx +7 -2
- package/client/features/chat/applet-chat-intents.ts +170 -0
- package/client/features/chat/chat-send.ts +103 -62
- package/client/features/chat/chat-store.ts +50 -59
- package/client/features/chat/composer/ChatComposer.tsx +43 -132
- package/client/features/chat/composer/ModelPicker.tsx +3 -16
- package/client/features/chat/composer/attachments/AttachmentChip.tsx +99 -0
- package/client/features/chat/composer/attachments/DrawingAttachmentChip.tsx +37 -0
- package/client/features/chat/composer/attachments/FileAttachmentChip.tsx +22 -0
- package/client/features/chat/composer/attachments/TextAttachmentChip.tsx +11 -0
- package/client/features/chat/composer/attachments/draft-attachments.ts +168 -0
- package/client/features/chat/composer/attachments/types.ts +25 -0
- package/client/features/chat/composer/attachments/uploads.ts +26 -0
- package/client/features/chat/{chat-connection.ts → connection/chat-connection.ts} +1 -1
- package/client/features/chat/{chat-frames.ts → connection/chat-frames.ts} +2 -2
- package/client/features/chat/{ChatEmptyState.tsx → messages/ChatEmptyState.tsx} +16 -11
- package/client/features/chat/{MarkdownContent.tsx → messages/MarkdownContent.tsx} +16 -1
- package/client/features/chat/{TurnView.tsx → messages/TurnView.tsx} +22 -15
- package/client/features/chat/{tool-group → messages/tool-group}/SubagentCard.tsx +1 -1
- package/client/features/chat/{tool-group → messages/tool-group}/TimelineRow.tsx +2 -2
- package/client/features/chat/{tool-group → messages/tool-group}/ToolCallGroup.tsx +1 -1
- package/client/features/chat/{ChatSelector.tsx → sessions/ChatSelector.tsx} +3 -3
- package/client/features/chat/{api.ts → sessions/api.ts} +1 -1
- package/client/features/chat/useChat.ts +32 -15
- package/client/features/dev/ChatStatesPage.tsx +5 -6
- package/client/features/dev/HarnessDebugPage.tsx +10 -7
- package/client/features/dev/ToolCallsPage.tsx +1 -1
- package/client/features/dev/UiComponentPreviews.tsx +21 -0
- package/client/features/dev/chat-states-fixtures.ts +13 -2
- package/client/features/drawings/useChatAnnotation.ts +17 -17
- package/client/features/drawings/useDrawingLayer.ts +7 -9
- package/client/features/drawings/useViewBuilderSketch.ts +18 -15
- package/client/features/home/HomePage.tsx +8 -7
- package/client/features/home/WorkspacePreview.tsx +1 -1
- package/client/features/home/workspace-presentation.tsx +1 -11
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +2 -4
- package/client/features/overview/HiddenPanel.tsx +109 -0
- package/client/features/overview/Overview.tsx +302 -0
- package/client/features/overview/WidgetCanvas.tsx +164 -0
- package/client/features/{widgets → overview}/WidgetFrame.tsx +24 -16
- package/client/features/overview/WorkspaceName.tsx +60 -0
- package/client/features/overview/api.ts +30 -0
- package/client/features/overview/default/ViewsWidget.tsx +252 -0
- package/client/features/overview/default/registry.tsx +36 -0
- package/client/features/{widgets → overview}/grid.ts +36 -0
- package/client/features/overview/useGridReconcile.ts +94 -0
- package/client/features/scratchpad/Scratchpad.tsx +7 -8
- package/client/features/scratchpad/ScratchpadControls.tsx +0 -1
- package/client/features/scratchpad/useScratchpadSnapshot.tsx +23 -13
- package/client/features/settings/GeneralSettings.tsx +55 -58
- package/client/features/settings/SettingsLayout.tsx +2 -2
- package/client/features/settings/WorkspaceIconPicker.tsx +318 -0
- package/client/features/settings/WorkspaceSettingsDialog.tsx +65 -0
- package/client/features/settings/api.ts +48 -24
- package/client/features/views/ViewBuilder.tsx +5 -4
- package/client/features/views/ViewManager.tsx +11 -13
- package/client/features/views/api.ts +36 -2
- package/client/features/views/useViewBuilderActions.ts +8 -5
- package/client/features/views/useViewBuilderDrafts.ts +23 -21
- package/client/features/views/view-presentation.ts +13 -0
- package/client/features/workspace/{CustomizePanel.tsx → ThemePanel.tsx} +26 -31
- package/client/features/workspace/UnavailablePage.tsx +21 -0
- package/client/features/workspace/WorkspaceLayoutContext.tsx +4 -7
- package/client/features/workspace/WorkspaceScreen.tsx +205 -161
- package/client/features/workspace/WorkspaceSplitLayout.tsx +1 -1
- package/client/features/workspace/WorkspaceTabs.tsx +2 -0
- package/client/features/workspace/api.ts +0 -26
- package/client/features/workspace/moi-context.ts +8 -9
- package/client/features/workspace/tab-resolution.ts +10 -33
- package/client/features/workspace/useWorkspaceNavigation.ts +164 -101
- package/client/index.css +1 -1
- package/client/lib/app-icon-registry.ts +2 -0
- package/client/lib/use-latest-ref.ts +11 -0
- package/client/main.tsx +1 -1
- package/client/runtime/useWorkspaceEvents.ts +59 -14
- package/client/theme.css +5 -5
- package/dist/chunk-2gs8jjx4.css +1 -0
- package/dist/chunk-7vvg5fyz.js +68 -0
- package/dist/chunk-94m3q9ce.js +1 -0
- package/dist/{chunk-w482ew2c.js → chunk-brr0zbeh.js} +73 -73
- package/dist/chunk-by2wqgak.js +1 -0
- package/dist/chunk-m1fvqssh.js +2 -0
- package/dist/chunk-p34hvqt3.js +1 -0
- package/dist/{chunk-4s15axjs.js → chunk-p83f0jnj.js} +2 -2
- package/dist/{chunk-j3wvxjr7.js → chunk-tzz101ea.js} +1 -1
- package/dist/chunk-xg01f6pn.js +10 -0
- package/dist/{chunk-53a7pxcz.js → chunk-zs4mte79.js} +1 -1
- package/dist/index.html +1 -1
- package/lib/app-icons.ts +1 -0
- package/lib/applet-selector.ts +24 -0
- package/lib/chat-title.ts +6 -1
- package/lib/default-widgets.ts +32 -0
- package/lib/format.ts +12 -1
- package/lib/message-attachments.ts +40 -0
- package/lib/moi-attachments.ts +204 -0
- package/lib/moi-context.ts +20 -35
- package/lib/navigation.ts +84 -0
- package/lib/types.ts +81 -25
- package/lib/workspace-icon.ts +20 -0
- package/lib/workspace-layout.ts +22 -2
- package/lib/workspace-tabs.ts +9 -33
- package/package.json +27 -27
- package/registry.json +13 -0
- package/server/AGENTS.md +1 -0
- package/server/api.ts +114 -37
- package/server/applet-typecheck.ts +95 -0
- package/server/{bundler → applets}/build-applet.ts +13 -246
- package/server/applets/config.ts +226 -0
- package/server/applets/dependencies.ts +206 -0
- package/server/{applets.ts → applets/index.ts} +15 -161
- package/server/applets/runtime/base.ts +4 -0
- package/server/applets/runtime/moi.ts +42 -0
- package/server/applets/runtime/rpc.ts +17 -0
- package/server/applets/view-source.ts +67 -0
- package/server/attachment-message.ts +95 -0
- package/server/cli.ts +163 -97
- package/server/control.ts +63 -42
- package/server/harness/README.md +4 -2
- package/server/harness/acp/adapter.ts +7 -21
- package/server/harness/acp/session.ts +31 -50
- package/server/harness/claude-code/NOTES.md +8 -2
- package/server/harness/claude-code/adapter.ts +8 -25
- package/server/harness/claude-code/index.ts +2 -0
- package/server/harness/claude-code/session.ts +42 -47
- package/server/harness/claude-code/sessions.ts +9 -4
- package/server/harness/codex/adapter.ts +8 -7
- package/server/harness/codex/index.ts +1 -0
- package/server/harness/codex/permissions.ts +1 -1
- package/server/harness/codex/session.ts +20 -47
- package/server/harness/hermes/NOTES.md +1 -1
- package/server/harness/hermes/index.ts +4 -0
- package/server/harness/openclaw/NOTES.md +1 -1
- package/server/harness/openclaw/adapter.ts +22 -4
- package/server/harness/openclaw/gateway.ts +5 -3
- package/server/harness/openclaw/session.ts +27 -27
- package/server/harness/types.ts +5 -3
- package/server/layout.ts +9 -14
- package/server/moi-scaffold.ts +21 -13
- package/server/navigation-relay.ts +110 -0
- package/server/registry.ts +8 -0
- package/server/selected-session.ts +24 -4
- package/server/skill-update.ts +5 -3
- package/server/skill-version.ts +4 -7
- package/server/skills-template.ts +48 -9
- package/server/tabs.ts +19 -33
- package/server/uploads.ts +0 -0
- package/server/view-builders.ts +18 -1
- package/server/views.ts +126 -6
- package/server/web.ts +35 -9
- package/server/widgets.ts +12 -5
- package/server/workspace-config.ts +13 -9
- package/ui-components/button.tsx +2 -2
- package/ui-components/docs/kbd.md +191 -0
- package/ui-components/dropdown-menu.tsx +1 -1
- package/ui-components/kbd.tsx +32 -0
- package/ui-components/slider.tsx +1 -1
- package/ui-components/switch.tsx +1 -1
- package/ui-components/tabs.tsx +1 -1
- package/workspace/.claude/skills/moi-workspace/SKILL.md +284 -228
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +100 -153
- package/workspace/.claude/skills/moi-workspace/references/INTENTS.md +156 -0
- package/client/features/chat/attachment-staging.ts +0 -153
- package/client/features/chat/uploads.ts +0 -18
- package/client/features/chat/useAppletChatMessage.ts +0 -68
- package/client/features/settings/IconPicker.tsx +0 -442
- package/client/features/settings/WorkspaceSettings.tsx +0 -95
- package/client/features/settings/render-icon.ts +0 -173
- package/client/features/widgets/HiddenPanel.tsx +0 -80
- package/client/features/widgets/WidgetGrid.tsx +0 -123
- package/client/features/widgets/Widgets.tsx +0 -262
- package/client/features/widgets/useGridReconcile.ts +0 -73
- package/dist/chunk-245wt82v.css +0 -1
- package/dist/chunk-87thzbtw.js +0 -2
- package/dist/chunk-a6jad1a6.js +0 -1
- package/dist/chunk-dghwstd2.js +0 -9
- package/dist/chunk-eg120aca.js +0 -1
- package/dist/chunk-j7hh2ab4.js +0 -70
- package/dist/chunk-y8eyahwx.js +0 -1
- /package/client/features/chat/{ChatPromptBubbles.tsx → messages/ChatPromptBubbles.tsx} +0 -0
- /package/client/features/chat/{ShimmerText.tsx → messages/ShimmerText.tsx} +0 -0
- /package/client/features/chat/{group-turns.ts → messages/group-turns.ts} +0 -0
- /package/client/features/chat/{interleave-notices.ts → messages/interleave-notices.ts} +0 -0
- /package/client/features/chat/{preview-turn.ts → messages/preview-turn.ts} +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/CodeBlock.tsx +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/Collapse.tsx +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/ReadImagePreview.tsx +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/ToolOutput.tsx +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/detect.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/fixtures.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/claude.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/codex.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/hermes.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/index.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/mcp.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/openclaw.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/shared.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/format/shell.ts +0 -0
- /package/client/features/chat/{tool-group → messages/tool-group}/index.ts +0 -0
- /package/client/features/chat/{useStickToBottom.ts → messages/useStickToBottom.ts} +0 -0
- /package/client/features/chat/{session-view.ts → sessions/session-view.ts} +0 -0
- /package/client/features/chat/{useSelectedSession.ts → sessions/useSelectedSession.ts} +0 -0
- /package/server/{bundler → applets}/applet-css.ts +0 -0
- /package/server/{bundler → applets}/build-worker.ts +0 -0
package/server/api.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isMessageAttachments } from '@/lib/message-attachments'
|
|
1
2
|
import { Hono } from 'hono'
|
|
2
3
|
import { serveStatic } from 'hono/bun'
|
|
3
4
|
import { createMiddleware } from 'hono/factory'
|
|
@@ -5,6 +6,8 @@ import { existsSync } from 'node:fs'
|
|
|
5
6
|
import { basename, join, resolve } from 'node:path'
|
|
6
7
|
|
|
7
8
|
import { UPDATE_ACTIVE_AGENT_MESSAGE } from '@/lib/update'
|
|
9
|
+
import { resolveWorkspaceTheme } from '@/lib/themes'
|
|
10
|
+
import { isWorkspaceIcon } from '@/lib/workspace-icon'
|
|
8
11
|
import type {
|
|
9
12
|
AppletKind,
|
|
10
13
|
AppletThumbnailBatch,
|
|
@@ -62,9 +65,16 @@ import type { SessionConfigPatch } from './session-config'
|
|
|
62
65
|
import { DIST_DIR, prebuilt } from './static'
|
|
63
66
|
import { getWorkspaceSkillsStatus, updateWorkspaceSkills } from './skill-update'
|
|
64
67
|
import { serveWorkspaceImagePreview } from './preview'
|
|
65
|
-
import { MAX_UPLOAD_BYTES, addUpload, getUpload } from './uploads'
|
|
68
|
+
import { MAX_UPLOAD_BYTES, addUpload, addWorkspaceFileUpload, getUpload } from './uploads'
|
|
66
69
|
import { requiredEnvFor } from './required-env'
|
|
67
|
-
import {
|
|
70
|
+
import {
|
|
71
|
+
deleteView,
|
|
72
|
+
getViewList,
|
|
73
|
+
listViews,
|
|
74
|
+
serveView,
|
|
75
|
+
updateViewTitle,
|
|
76
|
+
ViewMutationError
|
|
77
|
+
} from './views'
|
|
68
78
|
import {
|
|
69
79
|
ViewBuilderError,
|
|
70
80
|
beginViewBuilder,
|
|
@@ -192,6 +202,31 @@ one.get('/widgets/*', c => {
|
|
|
192
202
|
// lists (in manifest/nav order), `/*` serves one bundle file.
|
|
193
203
|
one.get('/views', c => listViews(c.get('ws').path))
|
|
194
204
|
|
|
205
|
+
one.patch('/views/:viewId', async c => {
|
|
206
|
+
const ws = c.get('ws')
|
|
207
|
+
const body = await c.req.json().catch(() => null)
|
|
208
|
+
const title = typeof body?.title === 'string' ? body.title.trim() : ''
|
|
209
|
+
if (!title) return c.text('Expected { title: string }', 400)
|
|
210
|
+
|
|
211
|
+
try {
|
|
212
|
+
return c.json(await updateViewTitle(publishEvent, ws.id, ws.path, c.req.param('viewId'), title))
|
|
213
|
+
} catch (error) {
|
|
214
|
+
if (error instanceof ViewMutationError) return c.text(error.message, error.status)
|
|
215
|
+
throw error
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
one.delete('/views/:viewId', async c => {
|
|
220
|
+
const ws = c.get('ws')
|
|
221
|
+
try {
|
|
222
|
+
await deleteView(publishEvent, ws.id, ws.path, c.req.param('viewId'))
|
|
223
|
+
return c.body(null, 204)
|
|
224
|
+
} catch (error) {
|
|
225
|
+
if (error instanceof ViewMutationError) return c.text(error.message, error.status)
|
|
226
|
+
throw error
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
|
|
195
230
|
one.get('/views/*', c => {
|
|
196
231
|
const ws = c.get('ws')
|
|
197
232
|
const { name, file } = parseAppletTail(c.req.url, ws.id, 'views')
|
|
@@ -279,15 +314,12 @@ one.post('/view-builders/:builderId/submit', async c => {
|
|
|
279
314
|
const availableIcons = parseAvailableViewIcons(body.availableIcons)
|
|
280
315
|
if (!availableIcons) return c.text('Available view icons are required', 400)
|
|
281
316
|
const attachments = body.attachments ?? []
|
|
282
|
-
if (
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
if (attachments.some(id => getUpload(ws.id, id)?.kind !== 'image')) {
|
|
290
|
-
return c.text('Sketch attachment not found or expired', 400)
|
|
317
|
+
if (!isMessageAttachments(attachments)) return c.text('Invalid attachments', 400)
|
|
318
|
+
for (const attachment of attachments) {
|
|
319
|
+
if (attachment.type !== 'upload') continue
|
|
320
|
+
if (!/^[a-f0-9]{64}$/.test(attachment.uploadId)) return c.text('Invalid upload id', 400)
|
|
321
|
+
if (!getUpload(ws.id, attachment.uploadId))
|
|
322
|
+
return c.text('Attachment not found or expired', 400)
|
|
291
323
|
}
|
|
292
324
|
const availability = await workspaceTypeAvailability(ws.type ?? 'claude-code')
|
|
293
325
|
if (availability.status !== 'available') return c.text(availability.reason, 400)
|
|
@@ -303,11 +335,11 @@ one.post('/view-builders/:builderId/submit', async c => {
|
|
|
303
335
|
// the harness like any other ambient context; the user text stays bare.
|
|
304
336
|
// The user submits from the builder's own tab, so that's the active tab.
|
|
305
337
|
const context: MoiContext = {
|
|
306
|
-
activeTab: `view-
|
|
338
|
+
activeTab: `view-builders/${builder.id}`,
|
|
307
339
|
directives: [
|
|
308
340
|
...viewBuilderDirectives(builder.id, availableIcons),
|
|
309
341
|
...(attachments.length > 0
|
|
310
|
-
? [
|
|
342
|
+
? ['Use the attachments as reference material for the intended view.']
|
|
311
343
|
: [])
|
|
312
344
|
]
|
|
313
345
|
}
|
|
@@ -440,16 +472,16 @@ one.post('/uploads', async c => {
|
|
|
440
472
|
try {
|
|
441
473
|
form = await c.req.formData()
|
|
442
474
|
} catch {
|
|
443
|
-
return c.text('
|
|
475
|
+
return c.text('Choose a file to upload', 400)
|
|
444
476
|
}
|
|
445
477
|
const files = form.getAll('files').filter((f): f is File => f instanceof File)
|
|
446
|
-
if (files.length === 0) return c.text('
|
|
447
|
-
if (files.length > 20) return c.text('
|
|
478
|
+
if (files.length === 0) return c.text('Choose a file to upload', 400)
|
|
479
|
+
if (files.length > 20) return c.text('You can upload up to 20 files at a time', 400)
|
|
448
480
|
|
|
449
481
|
const out: UploadInfo[] = []
|
|
450
482
|
for (const file of files) {
|
|
451
483
|
if (file.size > MAX_UPLOAD_BYTES) {
|
|
452
|
-
return c.text(`
|
|
484
|
+
return c.text(`Files can be up to ${MAX_UPLOAD_BYTES / (1024 * 1024)} MB`, 413)
|
|
453
485
|
}
|
|
454
486
|
try {
|
|
455
487
|
const bytes = Buffer.from(await file.arrayBuffer())
|
|
@@ -461,14 +493,36 @@ one.post('/uploads', async c => {
|
|
|
461
493
|
bytes
|
|
462
494
|
})
|
|
463
495
|
)
|
|
464
|
-
} catch
|
|
465
|
-
|
|
466
|
-
return c.text(`"${file.name}": ${message}`, 400)
|
|
496
|
+
} catch {
|
|
497
|
+
return c.text(`Couldn’t process "${file.name}"`, 400)
|
|
467
498
|
}
|
|
468
499
|
}
|
|
469
500
|
return c.json(out)
|
|
470
501
|
})
|
|
471
502
|
|
|
503
|
+
// Existing workspace documents enter the same upload pipeline without a browser round trip.
|
|
504
|
+
one.post('/uploads/from-path', async c => {
|
|
505
|
+
const body: unknown = await c.req.json().catch(() => null)
|
|
506
|
+
if (!body || typeof body !== 'object' || !('path' in body) || typeof body.path !== 'string') {
|
|
507
|
+
return c.text('Choose a file from this workspace', 400)
|
|
508
|
+
}
|
|
509
|
+
const ws = c.get('ws')
|
|
510
|
+
try {
|
|
511
|
+
return c.json(await addWorkspaceFileUpload(ws.id, ws.path, body.path))
|
|
512
|
+
} catch (error) {
|
|
513
|
+
if (error instanceof Error && 'code' in error) {
|
|
514
|
+
if (error.code === 'ENOENT') return c.text('This file no longer exists', 400)
|
|
515
|
+
if (error.code === 'EACCES' || error.code === 'EPERM')
|
|
516
|
+
return c.text('This file can’t be read by moi', 400)
|
|
517
|
+
return c.text('Something went wrong while adding this file', 400)
|
|
518
|
+
}
|
|
519
|
+
return c.text(
|
|
520
|
+
error instanceof Error ? error.message : 'Something went wrong while adding this file',
|
|
521
|
+
400
|
|
522
|
+
)
|
|
523
|
+
}
|
|
524
|
+
})
|
|
525
|
+
|
|
472
526
|
// Serve an upload's bytes back. Display parts reference this URL instead of a
|
|
473
527
|
// base64 data URL so the transcript broadcast / client cache stay small. The id
|
|
474
528
|
// is content-addressed (sha256), so the response is immutable while it lives —
|
|
@@ -729,21 +783,30 @@ one.get('/agent', async c => {
|
|
|
729
783
|
} satisfies WorkspaceAgent)
|
|
730
784
|
})
|
|
731
785
|
|
|
732
|
-
// Workspace identity
|
|
733
|
-
// `{ name }` sets it (or `null` clears it). Broadcasts so the sidebar and header
|
|
734
|
-
// update live. Icon is handled by the binary route below.
|
|
786
|
+
// Workspace identity. Uploads use the image route below.
|
|
735
787
|
one.get('/config', async c => {
|
|
736
788
|
return c.json(await getWorkspaceConfig(c.get('ws').path))
|
|
737
789
|
})
|
|
738
790
|
|
|
739
791
|
one.put('/config', async c => {
|
|
740
792
|
const ws = c.get('ws')
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
793
|
+
const parsed: unknown = await c.req.json().catch(() => null)
|
|
794
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
795
|
+
return c.text('Expected a workspace config object', 400)
|
|
796
|
+
}
|
|
797
|
+
const body = parsed as Record<string, unknown>
|
|
798
|
+
const name = body.name
|
|
799
|
+
const icon = body.icon
|
|
800
|
+
if (name !== undefined && name !== null && typeof name !== 'string') {
|
|
744
801
|
return c.text('Expected { name: string | null }', 400)
|
|
745
802
|
}
|
|
746
|
-
|
|
803
|
+
if (icon !== undefined && icon !== null && (!isWorkspaceIcon(icon) || icon.type === 'upload')) {
|
|
804
|
+
return c.text('Invalid icon', 400)
|
|
805
|
+
}
|
|
806
|
+
if (name === undefined && icon === undefined) {
|
|
807
|
+
return c.text('Expected a workspace config field', 400)
|
|
808
|
+
}
|
|
809
|
+
await setWorkspaceConfig(ws.path, { name, icon })
|
|
747
810
|
publishEvent({ type: 'workspace:updated' })
|
|
748
811
|
return c.json(await getWorkspaceConfig(ws.path))
|
|
749
812
|
})
|
|
@@ -810,9 +873,8 @@ one.get('/scratchpad/assets/:file', async c => {
|
|
|
810
873
|
})
|
|
811
874
|
})
|
|
812
875
|
|
|
813
|
-
// Workspace
|
|
814
|
-
//
|
|
815
|
-
// provider default. Both broadcast for a live refresh.
|
|
876
|
+
// Workspace upload. PUT resizes an image to a 128×128 WebP. DELETE resets any
|
|
877
|
+
// custom icon to the provider default. Both broadcast for a live refresh.
|
|
816
878
|
one.put('/icon', async c => {
|
|
817
879
|
const ws = c.get('ws')
|
|
818
880
|
const bytes = new Uint8Array(await c.req.arrayBuffer())
|
|
@@ -824,9 +886,10 @@ one.put('/icon', async c => {
|
|
|
824
886
|
const msg = err instanceof Error ? err.message : String(err)
|
|
825
887
|
return c.text(`Invalid image: ${msg}`, 400)
|
|
826
888
|
}
|
|
827
|
-
|
|
889
|
+
const workspaceIcon = { type: 'upload', value: icon } as const
|
|
890
|
+
await setWorkspaceConfig(ws.path, { icon: workspaceIcon })
|
|
828
891
|
publishEvent({ type: 'workspace:updated' })
|
|
829
|
-
return c.json({ icon })
|
|
892
|
+
return c.json({ icon: workspaceIcon })
|
|
830
893
|
})
|
|
831
894
|
|
|
832
895
|
one.delete('/icon', async c => {
|
|
@@ -901,13 +964,22 @@ one.put('/', async c => {
|
|
|
901
964
|
// Preserve server-owned identity (name/icon) across a grid/theme save so the
|
|
902
965
|
// client's PUT can't erase a `moi config`-set name. See mergeLayoutForSave.
|
|
903
966
|
const existing = await loadLayout(ws.path)
|
|
904
|
-
|
|
967
|
+
const next = mergeLayoutForSave(existing, body)
|
|
968
|
+
await saveLayout(next, ws.path)
|
|
969
|
+
if (
|
|
970
|
+
JSON.stringify(resolveWorkspaceTheme(existing.theme)) !==
|
|
971
|
+
JSON.stringify(resolveWorkspaceTheme(next.theme))
|
|
972
|
+
) {
|
|
973
|
+
publishEvent({ type: 'theme:updated' })
|
|
974
|
+
}
|
|
905
975
|
return c.body(null, 204)
|
|
906
976
|
})
|
|
907
977
|
|
|
908
978
|
one.delete('/', async c => {
|
|
909
|
-
const
|
|
979
|
+
const ws = c.get('ws')
|
|
980
|
+
const ok = await removeWorkspace(ws.id)
|
|
910
981
|
if (!ok) return c.text('Workspace not found', 404)
|
|
982
|
+
harnessFor(ws).stopWorkspace?.(ws.path)
|
|
911
983
|
return c.body(null, 204)
|
|
912
984
|
})
|
|
913
985
|
|
|
@@ -918,14 +990,19 @@ async function mergeWorkspaceList(entries: WorkspaceEntry[]) {
|
|
|
918
990
|
return Promise.all(
|
|
919
991
|
entries.map(async e => {
|
|
920
992
|
const layout = await loadLayout(e.path)
|
|
921
|
-
return {
|
|
993
|
+
return {
|
|
994
|
+
...e,
|
|
995
|
+
name: layout.name ?? e.name,
|
|
996
|
+
icon: layout.icon,
|
|
997
|
+
theme: layout.theme
|
|
998
|
+
}
|
|
922
999
|
})
|
|
923
1000
|
)
|
|
924
1001
|
}
|
|
925
1002
|
|
|
926
1003
|
workspaces.get('/', async c => {
|
|
927
|
-
// Merge each workspace's live
|
|
928
|
-
// the
|
|
1004
|
+
// Merge each workspace's live identity and theme over the registry snapshot
|
|
1005
|
+
// so app-wide workspace lists render the same presentation as the workspace.
|
|
929
1006
|
const entries = await listWorkspaces()
|
|
930
1007
|
return c.json(await mergeWorkspaceList(entries))
|
|
931
1008
|
})
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
2
|
+
import { dirname, join } from 'node:path'
|
|
3
|
+
import ts from 'typescript'
|
|
4
|
+
|
|
5
|
+
import type { AppletSelector } from '@/lib/applet-selector'
|
|
6
|
+
|
|
7
|
+
import { writeAppletEnvDts } from './moi-scaffold'
|
|
8
|
+
|
|
9
|
+
export type AppletTypecheckResult = {
|
|
10
|
+
files: string[]
|
|
11
|
+
diagnostics: readonly ts.Diagnostic[]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Bun's ambient types come from the `@types/bun` moi itself depends on — the
|
|
15
|
+
// version moi was tested with, present wherever moi runs. It is found through
|
|
16
|
+
// Bun's resolver from moi's own location rather than a fixed path: `bun
|
|
17
|
+
// install -g` hoists moi's dependencies beside the package, so
|
|
18
|
+
// `../node_modules/@types` only exists in a dev checkout, and TypeScript never
|
|
19
|
+
// falls back to node_modules for `types` entries once `typeRoots` is set. The
|
|
20
|
+
// same root serves the `bun-types` and `@types/node` references inside, so
|
|
21
|
+
// the workspace's own `node_modules` never takes part. `from` is injectable
|
|
22
|
+
// for tests.
|
|
23
|
+
export function resolvePackageTypeRoot(from: string = import.meta.dir): string {
|
|
24
|
+
try {
|
|
25
|
+
return dirname(dirname(Bun.resolveSync('@types/bun/package.json', from)))
|
|
26
|
+
} catch {
|
|
27
|
+
throw new Error("moi's bundled @types/bun is missing — reinstall moi-computer")
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const TYPESCRIPT_FILES = new Bun.Glob('**/*.{ts,tsx}')
|
|
32
|
+
|
|
33
|
+
async function collectTypeScriptFiles(directory: string): Promise<string[]> {
|
|
34
|
+
if (!existsSync(directory)) return []
|
|
35
|
+
const files = await Array.fromAsync(TYPESCRIPT_FILES.scan({ cwd: directory, onlyFiles: true }))
|
|
36
|
+
return files.map(file => join(directory, file)).sort()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function collectAppletFiles(directory: string, id: string): Promise<string[]> {
|
|
40
|
+
const entrypoint = [`${id}.tsx`, `${id}.ts`].map(file => join(directory, file)).find(existsSync)
|
|
41
|
+
if (!entrypoint) return []
|
|
42
|
+
|
|
43
|
+
const server = join(directory, `${id}.server.ts`)
|
|
44
|
+
return existsSync(server) ? [entrypoint, server] : [entrypoint]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function typecheckApplets(
|
|
48
|
+
workspaceRoot: string,
|
|
49
|
+
scope?: AppletSelector
|
|
50
|
+
): Promise<AppletTypecheckResult> {
|
|
51
|
+
const moiRoot = join(workspaceRoot, '.moi')
|
|
52
|
+
const [kind, id] = scope?.split('/') ?? []
|
|
53
|
+
const files = id
|
|
54
|
+
? await collectAppletFiles(join(moiRoot, kind), id)
|
|
55
|
+
: (
|
|
56
|
+
await Promise.all(
|
|
57
|
+
(kind ? [kind] : ['widgets', 'views']).map(directory =>
|
|
58
|
+
collectTypeScriptFiles(join(moiRoot, directory))
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
.flat()
|
|
63
|
+
.sort()
|
|
64
|
+
if (files.length === 0) return { files, diagnostics: [] }
|
|
65
|
+
|
|
66
|
+
await writeAppletEnvDts(workspaceRoot)
|
|
67
|
+
const program = ts.createProgram({
|
|
68
|
+
rootNames: [join(moiRoot, 'applet-env.d.ts'), ...files],
|
|
69
|
+
options: {
|
|
70
|
+
allowImportingTsExtensions: true,
|
|
71
|
+
esModuleInterop: true,
|
|
72
|
+
jsx: ts.JsxEmit.ReactJSX,
|
|
73
|
+
lib: ['lib.esnext.d.ts', 'lib.dom.d.ts', 'lib.dom.iterable.d.ts'],
|
|
74
|
+
module: ts.ModuleKind.ESNext,
|
|
75
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
76
|
+
noEmit: true,
|
|
77
|
+
resolveJsonModule: true,
|
|
78
|
+
skipLibCheck: true,
|
|
79
|
+
strict: true,
|
|
80
|
+
target: ts.ScriptTarget.ESNext,
|
|
81
|
+
typeRoots: [resolvePackageTypeRoot()],
|
|
82
|
+
types: ['bun']
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
return { files, diagnostics: ts.getPreEmitDiagnostics(program) }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function formatAppletTypecheckDiagnostics(diagnostics: readonly ts.Diagnostic[]): string {
|
|
90
|
+
return ts.formatDiagnosticsWithColorAndContext([...diagnostics], {
|
|
91
|
+
getCanonicalFileName: fileName => fileName,
|
|
92
|
+
getCurrentDirectory: () => process.cwd(),
|
|
93
|
+
getNewLine: () => '\n'
|
|
94
|
+
})
|
|
95
|
+
}
|