moi-computer 0.11.0 → 0.11.1-dev.be1ed10
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/AGENTS.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/button.tsx +1 -53
- package/client/components/ui/checkbox.tsx +1 -0
- package/client/components/ui/collapsible.tsx +1 -15
- package/client/components/ui/dialog.tsx +1 -58
- package/client/components/ui/dropdown-menu.tsx +1 -254
- package/client/components/ui/hover-card.tsx +1 -44
- package/client/components/ui/inline-input.tsx +84 -0
- package/client/components/ui/input.tsx +1 -21
- package/client/components/ui/popover.tsx +1 -88
- package/client/components/ui/resizable.tsx +1 -40
- package/client/components/ui/skeleton.tsx +1 -13
- package/client/components/ui/slider.tsx +1 -70
- package/client/components/ui/spinner.tsx +1 -18
- package/client/components/ui/switch.tsx +1 -23
- package/client/components/ui/tabs.tsx +1 -0
- package/client/components/ui/textarea.tsx +1 -18
- package/client/components/ui/toast.tsx +2 -2
- package/client/components/ui/tooltip.tsx +1 -51
- 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 +24 -15
- package/client/features/chat/ChatPopup.tsx +9 -5
- package/client/features/chat/applet-chat-intents.ts +170 -0
- package/client/features/chat/chat-send.ts +116 -64
- package/client/features/chat/chat-store.ts +51 -62
- package/client/features/chat/composer/ChatComposer.tsx +43 -128
- package/client/features/chat/composer/ModelPicker.tsx +47 -60
- 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/composer/banners/ErrorBanner.tsx +20 -12
- package/client/features/chat/composer/model-order.ts +15 -0
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
- package/client/features/chat/{chat-connection.ts → connection/chat-connection.ts} +1 -1
- package/client/features/chat/{chat-frames.ts → connection/chat-frames.ts} +10 -8
- 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} +27 -19
- package/client/features/chat/{group-turns.ts → messages/group-turns.ts} +12 -0
- package/client/features/chat/{interleave-notices.ts → messages/interleave-notices.ts} +7 -11
- 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 +2 -5
- package/client/features/chat/{tool-group → messages/tool-group}/format/codex.ts +4 -1
- package/client/features/chat/{ChatSelector.tsx → sessions/ChatSelector.tsx} +3 -3
- package/client/features/chat/{api.ts → sessions/api.ts} +5 -14
- package/client/features/chat/sessions/session-view.ts +53 -0
- package/client/features/chat/useChat.ts +42 -24
- package/client/features/dev/ChatStatesPage.tsx +8 -7
- package/client/features/dev/DevIndexPage.tsx +5 -0
- package/client/features/dev/DevRoutes.tsx +2 -0
- package/client/features/dev/HarnessDebugPage.tsx +11 -8
- package/client/features/dev/ToolCallsPage.tsx +1 -1
- package/client/features/dev/UiComponentPreviews.tsx +855 -0
- package/client/features/dev/UiComponentsPage.tsx +60 -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 +2 -2
- package/client/features/home/workspace-presentation.tsx +1 -11
- package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
- package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +2 -4
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
- 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 +25 -17
- 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 +25 -22
- 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 +210 -162
- package/client/features/workspace/WorkspaceSplitLayout.tsx +7 -2
- package/client/features/workspace/WorkspaceTabs.tsx +2 -0
- package/client/features/workspace/api.ts +2 -30
- 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 +23 -30
- 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-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
- package/dist/chunk-691pqsj6.js +2 -0
- package/dist/chunk-7a5nm4k9.css +1 -0
- package/dist/chunk-amb8y04y.js +1 -0
- package/dist/chunk-cf3pgy7j.js +546 -0
- package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
- package/dist/chunk-mzrgr577.js +5 -0
- package/dist/chunk-nf2wkvf9.js +14 -0
- package/dist/chunk-q6a0g26x.js +1 -0
- package/dist/chunk-twgdemkc.js +74 -0
- package/dist/chunk-x90k0f5c.js +2 -0
- package/dist/chunk-yq00csvd.js +2 -0
- 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 +67 -7
- 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/themes.ts +6 -6
- package/lib/types.ts +91 -34
- package/lib/workspace-icon.ts +20 -0
- package/lib/workspace-layout.ts +22 -2
- package/lib/workspace-tabs.ts +9 -33
- package/package.json +42 -32
- package/registry.json +656 -0
- package/server/AGENTS.md +2 -0
- package/server/agent.ts +1 -1
- package/server/api.ts +139 -66
- package/server/applet-typecheck.ts +95 -0
- package/server/applets/applet-css.ts +55 -0
- package/server/{bundler → applets}/build-applet.ts +13 -242
- package/server/applets/build-worker.ts +178 -0
- package/server/applets/config.ts +226 -0
- package/server/applets/dependencies.ts +206 -0
- package/server/{applets.ts → applets/index.ts} +44 -189
- 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-ui-components.ts +28 -33
- package/server/cli.ts +169 -108
- package/server/control.ts +63 -42
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +45 -50
- package/server/harness/acp/NOTES.md +426 -0
- package/server/harness/acp/adapter.ts +7 -21
- package/server/harness/acp/discovery.ts +27 -30
- package/server/harness/acp/model-state.ts +57 -0
- package/server/harness/acp/session.ts +49 -56
- package/server/harness/claude-code/NOTES.md +54 -13
- package/server/harness/claude-code/adapter.ts +8 -25
- package/server/harness/claude-code/cli.ts +40 -0
- package/server/harness/claude-code/index.ts +13 -5
- package/server/harness/claude-code/models.ts +72 -19
- package/server/harness/claude-code/session.ts +447 -343
- package/server/harness/claude-code/sessions.ts +9 -4
- package/server/harness/codex/NOTES.md +222 -350
- package/server/harness/codex/adapter.ts +102 -52
- package/server/harness/codex/auth.ts +1 -3
- package/server/harness/codex/client.ts +169 -249
- package/server/harness/codex/discovery.ts +9 -17
- package/server/harness/codex/index.ts +3 -1
- package/server/harness/codex/pagination.ts +24 -0
- package/server/harness/codex/permissions.ts +32 -8
- package/server/harness/codex/probe.ts +10 -13
- package/server/harness/codex/session.ts +567 -181
- package/server/harness/codex/transport.ts +184 -0
- package/server/harness/debug.ts +1 -1
- package/server/harness/hermes/NOTES.md +19 -1
- package/server/harness/hermes/discovery.ts +20 -0
- package/server/harness/hermes/index.ts +13 -0
- package/server/harness/hermes/models.ts +28 -8
- 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 +9 -5
- package/server/layout.ts +9 -14
- package/server/moi-scaffold.ts +22 -14
- package/server/navigation-relay.ts +110 -0
- package/server/preview.ts +3 -1
- package/server/registry.ts +71 -41
- package/server/scratchpad-executor.ts +79 -56
- package/server/scratchpad-shape-defaults.ts +82 -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/tldraw-package.d.ts +4 -0
- package/server/ui-components.ts +101 -434
- package/server/uploads.ts +0 -0
- package/server/view-builders.ts +20 -2
- package/server/views.ts +126 -6
- package/server/web.ts +46 -13
- package/server/widgets.ts +12 -5
- package/server/workspace-config.ts +13 -9
- package/server/workspace-env.ts +3 -2
- package/tsconfig.json +0 -1
- package/ui-components/accordion.tsx +71 -0
- package/ui-components/alert-dialog.tsx +165 -0
- package/ui-components/alert.tsx +68 -0
- package/ui-components/attachment.tsx +195 -0
- package/ui-components/avatar.tsx +90 -0
- package/ui-components/badge.tsx +49 -0
- package/ui-components/button-group.tsx +78 -0
- package/ui-components/button.tsx +55 -0
- package/ui-components/calendar.tsx +180 -0
- package/ui-components/card.tsx +84 -0
- package/ui-components/carousel.tsx +235 -0
- package/ui-components/chart.tsx +338 -0
- package/ui-components/checkbox.tsx +28 -0
- package/ui-components/collapsible.tsx +15 -0
- package/ui-components/combobox.tsx +267 -0
- package/ui-components/context-menu.tsx +244 -0
- package/ui-components/dialog.tsx +138 -0
- package/ui-components/docs/accordion.md +463 -0
- package/ui-components/docs/alert-dialog.md +481 -0
- package/ui-components/docs/alert.md +301 -0
- package/ui-components/docs/attachment.md +689 -0
- package/ui-components/docs/avatar.md +495 -0
- package/ui-components/docs/badge.md +258 -0
- package/ui-components/docs/button-group.md +879 -0
- package/ui-components/docs/button.md +26 -0
- package/ui-components/docs/calendar.md +862 -0
- package/ui-components/docs/card.md +265 -0
- package/ui-components/docs/carousel.md +627 -0
- package/ui-components/docs/chart.md +1256 -0
- package/ui-components/docs/checkbox.md +477 -0
- package/ui-components/docs/collapsible.md +446 -0
- package/ui-components/docs/combobox.md +1003 -0
- package/ui-components/docs/context-menu.md +860 -0
- package/ui-components/docs/data-table.md +1580 -0
- package/ui-components/docs/date-picker.md +614 -0
- package/ui-components/docs/dialog.md +414 -0
- package/ui-components/docs/drawer.md +51 -0
- package/ui-components/docs/dropdown-menu.md +1000 -0
- package/ui-components/docs/field.md +1192 -0
- package/ui-components/docs/hover-card.md +275 -0
- package/ui-components/docs/input-group.md +866 -0
- package/ui-components/docs/input.md +456 -0
- package/ui-components/docs/kbd.md +191 -0
- package/ui-components/docs/label.md +295 -0
- package/ui-components/docs/pagination.md +416 -0
- package/ui-components/docs/popover.md +348 -0
- package/ui-components/docs/progress.md +214 -0
- package/ui-components/docs/radio-group.md +389 -0
- package/ui-components/docs/resizable.md +265 -0
- package/ui-components/docs/select.md +616 -0
- package/ui-components/docs/separator.md +216 -0
- package/ui-components/docs/skeleton.md +205 -0
- package/ui-components/docs/slider.md +226 -0
- package/ui-components/docs/spinner.md +332 -0
- package/ui-components/docs/switch.md +236 -0
- package/ui-components/docs/table.md +551 -0
- package/ui-components/docs/tabs.md +379 -0
- package/ui-components/docs/textarea.md +187 -0
- package/ui-components/docs/toggle-group.md +370 -0
- package/ui-components/docs/toggle.md +91 -0
- package/ui-components/docs/tooltip.md +290 -0
- package/ui-components/drawer.tsx +213 -0
- package/ui-components/dropdown-menu.tsx +263 -0
- package/ui-components/field.tsx +224 -0
- package/ui-components/hover-card.tsx +46 -0
- package/ui-components/input-group.tsx +146 -0
- package/ui-components/input.tsx +20 -0
- package/ui-components/kbd.tsx +32 -0
- package/ui-components/label.tsx +17 -0
- package/ui-components/pagination.tsx +124 -0
- package/ui-components/popover.tsx +81 -0
- package/ui-components/progress.tsx +63 -0
- package/ui-components/radio-group.tsx +38 -0
- package/ui-components/resizable.tsx +40 -0
- package/ui-components/scoped-portal.tsx +31 -0
- package/ui-components/select.tsx +195 -0
- package/ui-components/separator.tsx +18 -0
- package/ui-components/skeleton.tsx +15 -0
- package/ui-components/slider.tsx +75 -0
- package/ui-components/spinner.tsx +20 -0
- package/ui-components/switch.tsx +27 -0
- package/ui-components/table.tsx +86 -0
- package/ui-components/tabs.tsx +75 -0
- package/ui-components/textarea.tsx +17 -0
- package/ui-components/toggle-group.tsx +85 -0
- package/ui-components/toggle.tsx +42 -0
- package/ui-components/tooltip.tsx +61 -0
- package/ui-components/utils.ts +8 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +295 -248
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +100 -152
- package/workspace/.claude/skills/moi-workspace/references/INTENTS.md +156 -0
- package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
- 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 -92
- 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 -264
- package/client/features/widgets/useGridReconcile.ts +0 -73
- package/dist/chunk-104m57qw.js +0 -2
- package/dist/chunk-59zf0m6n.js +0 -1
- package/dist/chunk-bj3akjs2.js +0 -1
- package/dist/chunk-c9pjqx9m.js +0 -14
- package/dist/chunk-j2w2vak4.js +0 -546
- package/dist/chunk-k2r9c95m.js +0 -10
- package/dist/chunk-kmbxhgwv.js +0 -1
- package/dist/chunk-p1yqa71k.js +0 -83
- package/dist/chunk-pcnahct1.js +0 -5
- package/dist/chunk-r5xrenjy.css +0 -1
- package/dist/chunk-tny85yt2.js +0 -2
- package/dist/chunk-v7wr1df4.js +0 -2
- package/server/bundler/applet-css.ts +0 -155
- /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/{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/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/{useSelectedSession.ts → sessions/useSelectedSession.ts} +0 -0
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
// workspace-agnostic.
|
|
16
16
|
import { realpathSync, statSync } from 'node:fs'
|
|
17
17
|
import { mkdir, readdir, rm } from 'node:fs/promises'
|
|
18
|
-
import {
|
|
18
|
+
import { join, resolve, sep } from 'path'
|
|
19
19
|
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
import { analyzeDependencies, resolveSource, scanSources } from './dependencies'
|
|
21
|
+
import type { AppletKind } from './build-applet'
|
|
22
|
+
import { buildAppletsInChild } from './build-worker'
|
|
23
|
+
import { APPLET_API_BASE_SENTINEL } from './runtime/base'
|
|
24
|
+
import { pruneAppletThumbnails } from '../thumbnails'
|
|
25
|
+
|
|
26
|
+
export { scanSources } from './dependencies'
|
|
27
27
|
|
|
28
28
|
export type AppletPaths = {
|
|
29
29
|
moiRoot: string
|
|
@@ -55,161 +55,13 @@ export function getAppletRevision(
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
// entries to import, never entry points themselves.
|
|
61
|
-
export async function scanSources(sourceDir: string): Promise<string[]> {
|
|
62
|
-
try {
|
|
63
|
-
const entries = await readdir(sourceDir)
|
|
64
|
-
return entries
|
|
65
|
-
.filter(f => /\.(tsx|ts)$/.test(f) && !f.startsWith('_') && !f.endsWith('.server.ts'))
|
|
66
|
-
.map(f => f.replace(/\.tsx?$/, ''))
|
|
67
|
-
} catch {
|
|
68
|
-
return []
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function resolveSource(sourceDir: string, name: string): Promise<string | null> {
|
|
73
|
-
for (const ext of ['.tsx', '.ts']) {
|
|
74
|
-
const path = join(sourceDir, `${name}${ext}`)
|
|
75
|
-
if (await Bun.file(path).exists()) return path
|
|
76
|
-
}
|
|
77
|
-
return null
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Backstop for pathological graphs: an applet wiring more distinct files than
|
|
81
|
-
// this is reported stale without walking further — stale-but-rebuilt is the
|
|
82
|
-
// safe degradation, and the cap keeps the per-bundle check bounded no matter
|
|
83
|
-
// what the imports look like. Counts every input, images and JSON included, so
|
|
84
|
-
// it sits well above what an asset-heavy applet reaches (the walk never enters
|
|
85
|
-
// node_modules); hitting it means something is off anyway.
|
|
86
|
-
const MAX_GRAPH_FILES = 256
|
|
87
|
-
|
|
88
|
-
// Files the walk keeps descending through — anything Bun treats as a module
|
|
89
|
-
// (`.ts`, `.mjs`, `.cts`, …). Everything else (`.json`, `.css`, images) is a
|
|
90
|
-
// leaf.
|
|
91
|
-
const MODULE_FILE_RE = /\.[mc]?[jt]sx?$/
|
|
92
|
-
// Which transpiler loader lexes a module's imports. Only `.ts`/`.mts`/`.cts`
|
|
93
|
-
// take the `ts` loader: angle-bracket casts (`<string>x`) parse there and are
|
|
94
|
-
// JSX everywhere else. `.js`/`.mjs`/`.cjs` go through `tsx`, which accepts both
|
|
95
|
-
// plain JS and the JSX some of them contain.
|
|
96
|
-
const TS_ONLY_FILE_RE = /\.[mc]?ts$/
|
|
97
|
-
|
|
98
|
-
// A bundle is stale if its entry `index.js` is missing, any file in its local
|
|
99
|
-
// import graph has an mtime >= the built entry's, or one of those imports no
|
|
100
|
-
// longer resolves to a file at all.
|
|
101
|
-
//
|
|
102
|
-
// The graph is one uniform walk over every RELATIVE import the entry reaches:
|
|
103
|
-
// shared `_utils.tsx`, `../lib/*.ts`, `./data.json`, `./logo.png`,
|
|
104
|
-
// `./db.server`. Each is resolved to a real path, mtime-checked, and descended
|
|
105
|
-
// into when it's a module — so an imported image and a transitively imported
|
|
106
|
-
// helper are the same case, not two mechanisms. Bare specifiers (node_modules)
|
|
107
|
-
// are not walked: after a dependency bump, `moi bundle --force`. The bundle
|
|
108
|
-
// itself is React-mode-agnostic (see buildApplet), so it needs no rebuild when
|
|
109
|
-
// the server switches between the development and production React.
|
|
110
|
-
//
|
|
111
|
-
// `.server.ts` modules are walked like anything else, which is deliberately
|
|
112
|
-
// MORE than the bundle needs: their code never ships to the client (only the
|
|
113
|
-
// export list, inlined as RPC stubs), so editing one — or anything it imports
|
|
114
|
-
// — cannot change a byte of `index.js`. We report stale anyway because 'built'
|
|
115
|
-
// is what drives the worker recycle downstream (see `reloadModules`, called
|
|
116
|
-
// from widgets.ts/views.ts for every rebuilt applet). Without it, editing a
|
|
117
|
-
// helper that only a server module imports would leave a live worker serving
|
|
118
|
-
// the old code with nothing to dislodge it. The redundant rebuild is the price
|
|
119
|
-
// of that signal; the alternative is a second staleness channel threaded
|
|
120
|
-
// through the build results.
|
|
58
|
+
// Server dependencies also trigger rebuilds so their function worker is
|
|
59
|
+
// recycled, even when the client bundle's RPC stubs would remain identical.
|
|
121
60
|
async function needsRebuild(buildDir: string, name: string, srcPath: string): Promise<boolean> {
|
|
122
61
|
const built = Bun.file(join(buildDir, name, 'index.js'))
|
|
123
62
|
if (!(await built.exists())) return true
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
const queue = [srcPath]
|
|
127
|
-
const visited = new Set<string>()
|
|
128
|
-
while (queue.length > 0) {
|
|
129
|
-
const path = queue.pop()!
|
|
130
|
-
if (visited.has(path)) continue
|
|
131
|
-
visited.add(path)
|
|
132
|
-
if (visited.size > MAX_GRAPH_FILES) return true
|
|
133
|
-
const file = Bun.file(path)
|
|
134
|
-
if (!(await file.exists())) continue
|
|
135
|
-
if (file.lastModified >= builtMtime) return true
|
|
136
|
-
// Leaves stop at the mtime check above — an asset, JSON, or CSS file can't
|
|
137
|
-
// import anything.
|
|
138
|
-
if (!MODULE_FILE_RE.test(path)) continue
|
|
139
|
-
const source = await file.text()
|
|
140
|
-
const dir = dirname(path)
|
|
141
|
-
for (const specifier of scanRelativeImports(
|
|
142
|
-
source,
|
|
143
|
-
TS_ONLY_FILE_RE.test(path) ? 'ts' : 'tsx'
|
|
144
|
-
)) {
|
|
145
|
-
const resolved = await resolveModuleImport(dir, specifier)
|
|
146
|
-
// Nothing on disk answers this import, so the next build will fail on it.
|
|
147
|
-
// Report stale rather than skip: a helper deleted since the last build
|
|
148
|
-
// would otherwise leave `moi bundle` serving the last good bundle and
|
|
149
|
-
// never surfacing the missing-import error.
|
|
150
|
-
if (!resolved) return true
|
|
151
|
-
queue.push(resolved)
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
return false
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Extensions Bun appends to an extensionless import, in its own preference
|
|
158
|
-
// order (`./data` finds `data.tsx` before `data.ts` before … `data.json`).
|
|
159
|
-
// Doubles as the directory-index set: `./helpers` → `helpers/index.jsx`.
|
|
160
|
-
const RESOLVE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.cjs', '.json', '.mts', '.cts']
|
|
161
|
-
|
|
162
|
-
// TypeScript's output-extension rewrite: an import written against the emitted
|
|
163
|
-
// file name resolves to the source that produces it. (`.cjs` → `.cts` is
|
|
164
|
-
// deliberately absent — Bun doesn't do that one.)
|
|
165
|
-
const TS_EXTENSION_REWRITES: Record<string, string[]> = {
|
|
166
|
-
'.js': ['.ts', '.tsx'],
|
|
167
|
-
'.jsx': ['.tsx'],
|
|
168
|
-
'.mjs': ['.mts']
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Resolve a relative import to the file the bundler will actually read. This
|
|
172
|
-
// mirrors Bun's resolution rather than delegating to `Bun.resolveSync`, which
|
|
173
|
-
// memoizes results for the life of the process: in the long-running server it
|
|
174
|
-
// keeps handing back the path of a dependency that has since been deleted or
|
|
175
|
-
// renamed, which is exactly the case this check has to catch. Every candidate
|
|
176
|
-
// is probed against the filesystem, in Bun's order — literal path, TS
|
|
177
|
-
// extension rewrite, appended extension, then directory (`package.json` main,
|
|
178
|
-
// else `index.*`). Returns null when nothing on disk answers the specifier.
|
|
179
|
-
async function resolveModuleImport(dir: string, specifier: string): Promise<string | null> {
|
|
180
|
-
const base = join(dir, specifier)
|
|
181
|
-
const candidates = [base]
|
|
182
|
-
|
|
183
|
-
// Extension of the final segment only — a dot in a directory name (`./v1.2/x`)
|
|
184
|
-
// is not one.
|
|
185
|
-
const ext = /\.[^./\\]+$/.exec(base)?.[0] ?? ''
|
|
186
|
-
for (const rewrite of TS_EXTENSION_REWRITES[ext] ?? []) {
|
|
187
|
-
candidates.push(base.slice(0, base.length - ext.length) + rewrite)
|
|
188
|
-
}
|
|
189
|
-
for (const e of RESOLVE_EXTENSIONS) candidates.push(base + e)
|
|
190
|
-
|
|
191
|
-
for (const candidate of candidates) {
|
|
192
|
-
if (await Bun.file(candidate).exists()) return candidate
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Directory import. `package.json` main wins over `index.*`, matching Bun;
|
|
196
|
-
// an unreadable or `main`-less manifest just falls through to the indexes.
|
|
197
|
-
const pkg: unknown = await Bun.file(join(base, 'package.json'))
|
|
198
|
-
.json()
|
|
199
|
-
.catch(() => null)
|
|
200
|
-
const main =
|
|
201
|
-
typeof pkg === 'object' && pkg !== null && 'main' in pkg && typeof pkg.main === 'string'
|
|
202
|
-
? pkg.main
|
|
203
|
-
: null
|
|
204
|
-
if (main) {
|
|
205
|
-
const mainPath = join(base, main)
|
|
206
|
-
if (await Bun.file(mainPath).exists()) return mainPath
|
|
207
|
-
}
|
|
208
|
-
for (const e of RESOLVE_EXTENSIONS) {
|
|
209
|
-
const index = join(base, `index${e}`)
|
|
210
|
-
if (await Bun.file(index).exists()) return index
|
|
211
|
-
}
|
|
212
|
-
return null
|
|
63
|
+
const graph = await analyzeDependencies([srcPath], built.lastModified)
|
|
64
|
+
return !graph.complete
|
|
213
65
|
}
|
|
214
66
|
|
|
215
67
|
// Built applet names: subdirectories of `buildDir` that hold an `index.js`
|
|
@@ -580,7 +432,8 @@ export type AppletBuildResult<C> = {
|
|
|
580
432
|
export async function buildApplets<C>(
|
|
581
433
|
workspacePath: string,
|
|
582
434
|
kind: AppletKind,
|
|
583
|
-
force: boolean
|
|
435
|
+
force: boolean,
|
|
436
|
+
target?: string
|
|
584
437
|
): Promise<{ names: string[]; results: AppletBuildResult<C>[]; ms: number }> {
|
|
585
438
|
const t0 = performance.now()
|
|
586
439
|
const { sourceDir, buildDir, moiRoot } = getAppletPaths(workspacePath, kind)
|
|
@@ -600,6 +453,7 @@ export async function buildApplets<C>(
|
|
|
600
453
|
|
|
601
454
|
const jobs = await Promise.all(
|
|
602
455
|
names.map(async name => {
|
|
456
|
+
if (target && name !== target) return { name, status: 'skipped' as const }
|
|
603
457
|
const srcPath = await resolveSource(sourceDir, name)
|
|
604
458
|
if (!srcPath) return { name, status: 'failed' as const, error: 'Source file not found' }
|
|
605
459
|
if (!force && !(await needsRebuild(buildDir, name, srcPath))) {
|
|
@@ -609,35 +463,36 @@ export async function buildApplets<C>(
|
|
|
609
463
|
})
|
|
610
464
|
)
|
|
611
465
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
name: job.name,
|
|
628
|
-
status: 'built',
|
|
629
|
-
serverModules: artifact.serverModules.map(m => m.name),
|
|
630
|
-
config: (artifact.config as C | null) ?? null
|
|
631
|
-
}
|
|
632
|
-
} catch (err) {
|
|
633
|
-
return {
|
|
634
|
-
name: job.name,
|
|
635
|
-
status: 'failed',
|
|
636
|
-
error: err instanceof Error ? err.message : 'Unknown error'
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
})
|
|
466
|
+
// Compile the pending set in a fresh child process (see build-worker.ts:
|
|
467
|
+
// Bun's resolver cache is process-wide and never forgets a failed lookup, so
|
|
468
|
+
// an in-process build could not see packages installed after the server
|
|
469
|
+
// started). The child writes each bundle dir; only the per-job outcome comes
|
|
470
|
+
// back.
|
|
471
|
+
const built = new Map(
|
|
472
|
+
(
|
|
473
|
+
await buildAppletsInChild({
|
|
474
|
+
moiRoot,
|
|
475
|
+
kind,
|
|
476
|
+
jobs: jobs
|
|
477
|
+
.filter(job => job.status === 'pending')
|
|
478
|
+
.map(job => ({ name: job.name, srcPath: job.srcPath!, outDir: join(buildDir, job.name) }))
|
|
479
|
+
})
|
|
480
|
+
).map(r => [r.name, r])
|
|
640
481
|
)
|
|
641
482
|
|
|
483
|
+
const results = jobs.map((job): AppletBuildResult<C> => {
|
|
484
|
+
if (job.status === 'failed') return { name: job.name, status: 'failed', error: job.error }
|
|
485
|
+
if (job.status === 'skipped') return { name: job.name, status: 'skipped' }
|
|
486
|
+
const r = built.get(job.name)
|
|
487
|
+
if (!r) return { name: job.name, status: 'failed', error: 'Build worker returned no result' }
|
|
488
|
+
if (r.status === 'failed') return { name: job.name, status: 'failed', error: r.error }
|
|
489
|
+
return {
|
|
490
|
+
name: job.name,
|
|
491
|
+
status: 'built',
|
|
492
|
+
serverModules: r.serverModules,
|
|
493
|
+
config: (r.config as C | null) ?? null
|
|
494
|
+
}
|
|
495
|
+
})
|
|
496
|
+
|
|
642
497
|
return { names, results, ms: Math.round(performance.now() - t0) }
|
|
643
498
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { AppletBridge, AttachmentInput } from '../../../lib/types'
|
|
2
|
+
|
|
3
|
+
import { APPLET_API_BASE_SENTINEL } from './base'
|
|
4
|
+
|
|
5
|
+
type AppletChatInput = {
|
|
6
|
+
message: string
|
|
7
|
+
attachments?: AttachmentInput[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const BASE = APPLET_API_BASE_SENTINEL
|
|
11
|
+
|
|
12
|
+
let bridge: Partial<AppletBridge> | null = null
|
|
13
|
+
|
|
14
|
+
export function __attachBridge(next: Partial<AppletBridge>): void {
|
|
15
|
+
bridge = next
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function __getBridge(): Partial<AppletBridge> | null {
|
|
19
|
+
return bridge
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function fileUrl(path: string): string {
|
|
23
|
+
const clean = String(path).replace(/^\/+/, '')
|
|
24
|
+
return BASE + '/fs/' + clean.split('/').map(encodeURIComponent).join('/')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function navigate(href: string): void {
|
|
28
|
+
bridge?.navigate?.(href)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function resolveHref(href: string): string {
|
|
32
|
+
return bridge?.resolveHref?.(href) ?? ''
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function addChatAttachment(input: AttachmentInput): void {
|
|
36
|
+
bridge?.addChatAttachment?.(input)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Keep positional calls working for previously built applets.
|
|
40
|
+
export function sendChatMessage(input: AppletChatInput | string, legacyContext?: unknown): void {
|
|
41
|
+
bridge?.sendChatMessage?.(input, legacyContext)
|
|
42
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { parse, stringify } from 'devalue'
|
|
2
|
+
|
|
3
|
+
import { APPLET_API_BASE_SENTINEL } from './base'
|
|
4
|
+
|
|
5
|
+
const BASE = APPLET_API_BASE_SENTINEL
|
|
6
|
+
|
|
7
|
+
export function rpc(module: string, name: string) {
|
|
8
|
+
return async (...args: unknown[]): Promise<unknown> => {
|
|
9
|
+
const res = await fetch(BASE + '/rpc/' + module + '/' + name, {
|
|
10
|
+
method: 'POST',
|
|
11
|
+
headers: { 'Content-Type': 'application/json' },
|
|
12
|
+
body: stringify(args)
|
|
13
|
+
})
|
|
14
|
+
if (!res.ok) throw new Error(await res.text())
|
|
15
|
+
return parse(await res.text())
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { realpath, rm } from 'node:fs/promises'
|
|
2
|
+
import { join, relative, sep } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { analyzeAppletDependencies, collectDependencies, MODULE_FILE_RE } from './dependencies'
|
|
5
|
+
|
|
6
|
+
type ViewSource = {
|
|
7
|
+
path: string
|
|
8
|
+
source: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function readViewSource(
|
|
12
|
+
workspacePath: string,
|
|
13
|
+
viewId: string
|
|
14
|
+
): Promise<ViewSource | null> {
|
|
15
|
+
const directory = join(workspacePath, '.moi', 'views')
|
|
16
|
+
for (const extension of ['.tsx', '.ts']) {
|
|
17
|
+
const path = join(directory, `${viewId}${extension}`)
|
|
18
|
+
const file = Bun.file(path)
|
|
19
|
+
if (await file.exists()) return { path, source: await file.text() }
|
|
20
|
+
}
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class ViewSourceInUseError extends Error {}
|
|
25
|
+
|
|
26
|
+
function isCleanupSource(moiRoot: string, path: string): boolean {
|
|
27
|
+
if (!path.startsWith(moiRoot + sep) || !MODULE_FILE_RE.test(path)) return false
|
|
28
|
+
// Keep data, installed UI components, packages, and generated/hidden files.
|
|
29
|
+
return !relative(moiRoot, path)
|
|
30
|
+
.split(sep)
|
|
31
|
+
.some(part => part.startsWith('.') || ['data', 'ui', 'node_modules'].includes(part))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function deleteViewSourceFiles(workspacePath: string, viewId: string): Promise<void> {
|
|
35
|
+
const workspaceRoot = await realpath(workspacePath)
|
|
36
|
+
const moiRoot = join(workspaceRoot, '.moi')
|
|
37
|
+
const directory = join(moiRoot, 'views')
|
|
38
|
+
const sources = ['tsx', 'ts'].map(extension => join(directory, `${viewId}.${extension}`))
|
|
39
|
+
const roots = new Set([...sources, join(directory, `${viewId}.server.ts`)])
|
|
40
|
+
const remove = new Set(sources)
|
|
41
|
+
const graph = await analyzeAppletDependencies(workspaceRoot).catch(() => null)
|
|
42
|
+
|
|
43
|
+
if (graph?.complete) {
|
|
44
|
+
// A symlink can give one module several identities. Leave helpers behind
|
|
45
|
+
// in that case rather than guessing ownership or doing a more costly scan.
|
|
46
|
+
const canonical = await Promise.all(
|
|
47
|
+
[...graph.modules.keys()].map(async path => (await realpath(path).catch(() => null)) === path)
|
|
48
|
+
)
|
|
49
|
+
if (canonical.every(Boolean)) {
|
|
50
|
+
const candidates = collectDependencies(graph, roots)
|
|
51
|
+
const retained = collectDependencies(graph, [
|
|
52
|
+
...[...graph.entrypoints].filter(path => !roots.has(path)),
|
|
53
|
+
...[...candidates].filter(path => !isCleanupSource(moiRoot, path))
|
|
54
|
+
])
|
|
55
|
+
if (sources.some(path => retained.has(path))) {
|
|
56
|
+
throw new ViewSourceInUseError(
|
|
57
|
+
'Another applet imports this view. Remove that import before deleting it.'
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
for (const path of candidates) {
|
|
61
|
+
if (!retained.has(path) && isCleanupSource(moiRoot, path)) remove.add(path)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
await Promise.all([...remove].map(path => rm(path, { force: true })))
|
|
67
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { appendAttachments, attachmentPart } from '@/lib/moi-attachments'
|
|
2
|
+
import type { MessageAttachment, Part, Attachment } from '@/lib/types'
|
|
3
|
+
import { materializeToPath, resolveUploads, servedUploadUrl } from './uploads'
|
|
4
|
+
|
|
5
|
+
// Native images carry bytes; every file has a readable path.
|
|
6
|
+
type PreparedAttachment =
|
|
7
|
+
| Exclude<Attachment, { type: 'image' }>
|
|
8
|
+
| (Extract<Attachment, { type: 'image' }> & { data: Buffer })
|
|
9
|
+
|
|
10
|
+
export type PreparedAttachmentMessage = {
|
|
11
|
+
text: string
|
|
12
|
+
attachments: PreparedAttachment[]
|
|
13
|
+
parts: Part[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class AttachmentUploadError extends Error {
|
|
17
|
+
constructor() {
|
|
18
|
+
super('Attachment not found or expired')
|
|
19
|
+
this.name = 'AttachmentUploadError'
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function resolveAttachmentUploads(workspaceId: string, inputs: readonly MessageAttachment[]) {
|
|
24
|
+
const ids = inputs.flatMap(input => (input.type === 'upload' ? [input.uploadId] : []))
|
|
25
|
+
const uploads = resolveUploads(workspaceId, ids)
|
|
26
|
+
if (uploads.length !== ids.length) throw new AttachmentUploadError()
|
|
27
|
+
return new Map(uploads.map(upload => [upload.id, upload]))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Path-only harnesses await this before building their message.
|
|
31
|
+
export async function materializeAttachmentPaths(
|
|
32
|
+
workspaceId: string,
|
|
33
|
+
inputs: readonly MessageAttachment[] = []
|
|
34
|
+
): Promise<void> {
|
|
35
|
+
await Promise.all(
|
|
36
|
+
[...resolveAttachmentUploads(workspaceId, inputs).values()].map(materializeToPath)
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Keep construction synchronous so Claude queues a send before an immediate Stop.
|
|
41
|
+
// For path delivery, await materializeAttachmentPaths first.
|
|
42
|
+
export function prepareAttachmentMessage(
|
|
43
|
+
workspaceId: string,
|
|
44
|
+
text: string,
|
|
45
|
+
inputs: readonly MessageAttachment[] = [],
|
|
46
|
+
inlineImages = true
|
|
47
|
+
): PreparedAttachmentMessage {
|
|
48
|
+
const uploads = resolveAttachmentUploads(workspaceId, inputs)
|
|
49
|
+
const attachments: PreparedAttachment[] = []
|
|
50
|
+
const parts: Part[] = []
|
|
51
|
+
for (const input of inputs) {
|
|
52
|
+
if (input.type === 'text') {
|
|
53
|
+
attachments.push(input)
|
|
54
|
+
parts.push(attachmentPart(input))
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
const upload = uploads.get(input.uploadId)
|
|
58
|
+
if (!upload) throw new AttachmentUploadError()
|
|
59
|
+
const metadata = {
|
|
60
|
+
mediaType: upload.mediaType,
|
|
61
|
+
source: input.source
|
|
62
|
+
}
|
|
63
|
+
if (upload.kind === 'image' && inlineImages && upload.data) {
|
|
64
|
+
const attachment: PreparedAttachment = {
|
|
65
|
+
type: 'image',
|
|
66
|
+
...metadata,
|
|
67
|
+
label: upload.filename,
|
|
68
|
+
purpose: input.purpose,
|
|
69
|
+
data: upload.data
|
|
70
|
+
}
|
|
71
|
+
attachments.push(attachment)
|
|
72
|
+
parts.push(attachmentPart(attachment, servedUploadUrl(upload)))
|
|
73
|
+
} else if (upload.path) {
|
|
74
|
+
const attachment: Attachment = {
|
|
75
|
+
type: 'file',
|
|
76
|
+
...metadata,
|
|
77
|
+
path: upload.path,
|
|
78
|
+
...(upload.kind === 'image' ? { purpose: input.purpose } : {})
|
|
79
|
+
}
|
|
80
|
+
attachments.push(attachment)
|
|
81
|
+
parts.push(attachmentPart(attachment))
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const descriptors = attachments.map(attachment => {
|
|
85
|
+
if (!('data' in attachment)) return attachment
|
|
86
|
+
const { data: _data, ...descriptor } = attachment
|
|
87
|
+
return descriptor
|
|
88
|
+
})
|
|
89
|
+
if (text) parts.push({ type: 'text', text })
|
|
90
|
+
return {
|
|
91
|
+
text: appendAttachments(text, descriptors),
|
|
92
|
+
attachments,
|
|
93
|
+
parts
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// CLI face of `moi ui-components` (see server/ui-components.ts for the
|
|
2
|
-
// engine and docs/
|
|
2
|
+
// engine and docs/ui-components.md for the spec). Three verbs:
|
|
3
3
|
//
|
|
4
4
|
// moi ui-components → the curated catalog + installed state
|
|
5
|
-
// moi ui-components add <name…> →
|
|
6
|
-
// moi ui-components docs <name…> →
|
|
5
|
+
// moi ui-components add <name…> → copy registry components to .moi/ui/
|
|
6
|
+
// moi ui-components docs <name…> → component docs as markdown, on stdout
|
|
7
7
|
//
|
|
8
8
|
// The command is deliberately not smart: add never rebuilds and never edits
|
|
9
9
|
// existing files, and installs dependencies only when asked to (--install) —
|
|
@@ -17,15 +17,16 @@ import pc from './cli-pc'
|
|
|
17
17
|
import { resolveCwdWorkspace } from './cli-env'
|
|
18
18
|
import { MOI_PACKAGE_JSON } from './moi-scaffold'
|
|
19
19
|
import {
|
|
20
|
+
type LoadedUiComponents,
|
|
20
21
|
UI_COMPONENTS,
|
|
21
22
|
UI_COMPONENT_NAMES,
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
loadUiComponentDocs,
|
|
24
|
+
loadUiComponents,
|
|
24
25
|
partitionUiWrites,
|
|
25
26
|
planUiWrites,
|
|
26
27
|
resolveUiComponentRequest,
|
|
27
28
|
suggestUiComponents,
|
|
28
|
-
|
|
29
|
+
uiComponentFiles
|
|
29
30
|
} from './ui-components'
|
|
30
31
|
|
|
31
32
|
function uiDirFor(workspacePath: string): string {
|
|
@@ -37,7 +38,7 @@ function exitUnknownNames(unknown: string[]): never {
|
|
|
37
38
|
const hints = suggestUiComponents(name)
|
|
38
39
|
console.error(
|
|
39
40
|
pc.red('✗') +
|
|
40
|
-
` "${name}" is not in the
|
|
41
|
+
` "${name}" is not in the component catalog.` +
|
|
41
42
|
(hints.length ? pc.dim(` Did you mean: ${hints.join(', ')}?`) : '')
|
|
42
43
|
)
|
|
43
44
|
}
|
|
@@ -48,7 +49,7 @@ function exitUnknownNames(unknown: string[]): never {
|
|
|
48
49
|
const add = defineCommand({
|
|
49
50
|
meta: {
|
|
50
51
|
name: 'add',
|
|
51
|
-
description: '
|
|
52
|
+
description: 'Add components from the local registry to .moi/ui/'
|
|
52
53
|
},
|
|
53
54
|
args: {
|
|
54
55
|
name: {
|
|
@@ -74,35 +75,34 @@ const add = defineCommand({
|
|
|
74
75
|
const entry = await resolveCwdWorkspace()
|
|
75
76
|
const uiDir = uiDirFor(entry.path)
|
|
76
77
|
|
|
77
|
-
let
|
|
78
|
+
let loaded: LoadedUiComponents
|
|
78
79
|
try {
|
|
79
|
-
|
|
80
|
+
loaded = await loadUiComponents(request.entries)
|
|
80
81
|
} catch (err) {
|
|
81
82
|
console.error(
|
|
82
83
|
'\n' +
|
|
83
84
|
pc.red('✗') +
|
|
84
|
-
' Could not
|
|
85
|
-
'The command needs network access; offline use is not supported.\n' +
|
|
85
|
+
' Could not load the requested components from the local registry.\n' +
|
|
86
86
|
pc.dim(` ${(err as Error).message}\n`)
|
|
87
87
|
)
|
|
88
88
|
process.exit(1)
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
const plans = planUiWrites({
|
|
92
|
-
files:
|
|
93
|
-
|
|
92
|
+
files: loaded.files,
|
|
93
|
+
requestedFiles: request.entries.flatMap(uiComponentFiles),
|
|
94
94
|
uiDir,
|
|
95
95
|
exists: existsSync
|
|
96
96
|
})
|
|
97
97
|
|
|
98
98
|
// Hand-customized components are never silently overwritten: without
|
|
99
99
|
// --force a requested file that already exists is skipped and reported, so
|
|
100
|
-
// a bulk add still installs everything new. Only when
|
|
101
|
-
//
|
|
102
|
-
// (utils,
|
|
100
|
+
// a bulk add still installs everything new. Only when nothing needs to be
|
|
101
|
+
// written does the add fail. Existing support files
|
|
102
|
+
// (utils, scoped-portal, registry deps that rode along) are kept as-is
|
|
103
103
|
// either way, even under --force.
|
|
104
104
|
const partition = partitionUiWrites(plans, args.force)
|
|
105
|
-
if (partition.
|
|
105
|
+
if (partition.write.length === 0) {
|
|
106
106
|
console.error(
|
|
107
107
|
'\n' +
|
|
108
108
|
pc.red('✗') +
|
|
@@ -118,10 +118,7 @@ const add = defineCommand({
|
|
|
118
118
|
await mkdir(uiDir, { recursive: true })
|
|
119
119
|
const written: string[] = []
|
|
120
120
|
for (const plan of partition.write) {
|
|
121
|
-
|
|
122
|
-
? await transformUiComponentSource(plan.name, plan.content)
|
|
123
|
-
: plan.content
|
|
124
|
-
await Bun.write(plan.path, content)
|
|
121
|
+
await Bun.write(plan.path, plan.content)
|
|
125
122
|
written.push(plan.name)
|
|
126
123
|
}
|
|
127
124
|
const kept = partition.keepSupport.map(plan => plan.name)
|
|
@@ -131,7 +128,7 @@ const add = defineCommand({
|
|
|
131
128
|
// registry specifiers may be versioned (`recharts@3.8.0`), so compare by
|
|
132
129
|
// package name.
|
|
133
130
|
const baseline = new Set(Object.keys(MOI_PACKAGE_JSON.dependencies))
|
|
134
|
-
const deps = [...new Set(
|
|
131
|
+
const deps = [...new Set(loaded.dependencies)]
|
|
135
132
|
.filter(spec => !baseline.has(spec.replace(/@[^@/]+$/, '')))
|
|
136
133
|
.sort()
|
|
137
134
|
|
|
@@ -200,7 +197,7 @@ const add = defineCommand({
|
|
|
200
197
|
const docs = defineCommand({
|
|
201
198
|
meta: {
|
|
202
199
|
name: 'docs',
|
|
203
|
-
description: 'Print
|
|
200
|
+
description: 'Print component docs as markdown'
|
|
204
201
|
},
|
|
205
202
|
args: {
|
|
206
203
|
name: {
|
|
@@ -213,18 +210,16 @@ const docs = defineCommand({
|
|
|
213
210
|
const request = resolveUiComponentRequest(args._)
|
|
214
211
|
if (request.unknown.length > 0) exitUnknownNames(request.unknown)
|
|
215
212
|
|
|
213
|
+
console.log(
|
|
214
|
+
'> Import components relatively from `../ui/<name>` and use `@tabler/icons-react` for icons.\n'
|
|
215
|
+
)
|
|
216
216
|
for (const name of request.entries) {
|
|
217
|
-
const slug = UI_COMPONENTS[name].docsSlug ?? name
|
|
218
|
-
const url = `${UI_DOCS_BASE}/${slug}.md`
|
|
219
217
|
try {
|
|
220
|
-
const
|
|
221
|
-
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
|
218
|
+
const markdown = await loadUiComponentDocs(name)
|
|
222
219
|
if (request.entries.length > 1) console.log(`\n---\n# ${name}\n`)
|
|
223
|
-
console.log(
|
|
220
|
+
console.log(markdown)
|
|
224
221
|
} catch (err) {
|
|
225
|
-
console.error(
|
|
226
|
-
pc.red('✗') + ` Could not fetch docs for "${name}" (${url}): ${(err as Error).message}`
|
|
227
|
-
)
|
|
222
|
+
console.error(pc.red('✗') + ` Could not load docs for "${name}": ${(err as Error).message}`)
|
|
228
223
|
process.exitCode = 1
|
|
229
224
|
}
|
|
230
225
|
}
|
|
@@ -240,7 +235,7 @@ function renderCatalog(uiDir: string, query?: string): void {
|
|
|
240
235
|
if (needle && !name.includes(needle) && !entry.description.toLowerCase().includes(needle)) {
|
|
241
236
|
continue
|
|
242
237
|
}
|
|
243
|
-
const installed =
|
|
238
|
+
const installed = uiComponentFiles(name).every(file => existsSync(join(uiDir, file)))
|
|
244
239
|
rows.push(
|
|
245
240
|
' ' +
|
|
246
241
|
(installed ? pc.green('✓ ') : ' ') +
|