moi-computer 0.13.1-next.3 → 0.13.1-next.5
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 +1 -1
- package/bin/moi.mjs +10 -6
- package/dist/{chunk-a865c7x4.js → chunk-0xy5nenk.js} +1 -1
- package/dist/chunk-4arsawe0.js +2 -0
- package/dist/chunk-5eb7n6xw.js +1 -0
- package/dist/chunk-6aq60rm2.js +5 -0
- package/dist/chunk-9ffaaaw3.css +1 -0
- package/dist/{chunk-xj1pjhng.js → chunk-9vy2z8hd.js} +1 -1
- package/dist/{chunk-r95acex1.js → chunk-cb2a4cjk.js} +78 -78
- package/dist/{chunk-f44cs6mw.js → chunk-ghyzbqgb.js} +2 -2
- package/dist/chunk-j3djs7ta.js +72 -0
- package/dist/chunk-v0w55vnq.js +2 -0
- package/dist/chunk-yff16m73.js +1 -0
- package/dist/dot-2bdkpg3k.png +0 -0
- package/dist/duet-3ab8xyzd.png +0 -0
- package/dist/grok-bot-yv07qj9f.png +0 -0
- package/dist/index.html +1 -1
- package/dist/instinct-ypmq6t0w.png +0 -0
- package/dist/muse-qr7zwsvf.png +0 -0
- package/package.json +39 -40
- package/runtime/applets/chunk-bzxakh65.js +2 -0
- package/runtime/applets/chunk-qhjskz2m.js +2 -0
- package/runtime/applets/collab.js +1 -0
- package/runtime/applets/moi.js +1 -0
- package/runtime/applets/rpc.js +2 -0
- package/runtime/assets/shadcn.css +629 -0
- package/runtime/assets/tw-animate.css +1 -0
- package/runtime/build-worker-entry.js +2 -0
- package/runtime/chunk-30dzwptp.js +2 -0
- package/runtime/chunk-4wj1jzhr.js +3 -0
- package/runtime/chunk-67h4jd69.js +78 -0
- package/runtime/chunk-7c0zbz74.js +3 -0
- package/runtime/chunk-8jg7v8y7.js +3 -0
- package/runtime/chunk-9dr0dhxj.js +83 -0
- package/runtime/chunk-ewc55jga.js +32623 -0
- package/runtime/chunk-f56xzjzw.js +26 -0
- package/runtime/chunk-fdbkvdht.js +128 -0
- package/runtime/chunk-g9saang0.js +3 -0
- package/runtime/chunk-ggphq7nk.js +66 -0
- package/runtime/chunk-hrtaxw37.js +3 -0
- package/runtime/chunk-j0nd7kw0.js +52 -0
- package/runtime/chunk-k049dtaq.js +3 -0
- package/runtime/chunk-kjp60rqs.js +3 -0
- package/runtime/chunk-mjwz158z.js +2 -0
- package/runtime/chunk-pt32r350.js +2 -0
- package/runtime/chunk-q06m17nb.js +3 -0
- package/runtime/chunk-q2t18c1t.js +3 -0
- package/runtime/chunk-sdyqhxe1.js +10 -0
- package/runtime/chunk-w1fx9tsc.js +3 -0
- package/runtime/chunk-zm7k0v1c.js +3 -0
- package/runtime/chunk-zwvtkb81.js +139 -0
- package/runtime/cli.js +246 -0
- package/runtime/functions-worker.js +2 -0
- package/runtime/gateway-client.js +2 -0
- package/runtime/third-party-notices.txt +6830 -0
- package/runtime/worker.js +2 -0
- package/runtime/xdg-open +1267 -0
- package/bunfig.toml +0 -7
- package/client/AGENTS.md +0 -40
- package/client/api/app-config.ts +0 -58
- package/client/api/http.ts +0 -44
- package/client/api/query-client.ts +0 -5
- package/client/api/query-options.ts +0 -6
- package/client/api/workspace-keys.ts +0 -18
- package/client/app/app-provider.tsx +0 -45
- package/client/app/app-router.tsx +0 -60
- package/client/app/routes/home-route.tsx +0 -27
- package/client/app/routes/onboarding-route.tsx +0 -11
- package/client/app/routes/settings-route.tsx +0 -10
- package/client/app/routes/workspace-registration.tsx +0 -68
- package/client/app/routes/workspace-route.tsx +0 -110
- package/client/app/shell/sidebar-layout.tsx +0 -252
- package/client/assets/claude.svg +0 -3
- package/client/assets/favicon.png +0 -0
- package/client/assets/floppy-disk.webp +0 -0
- package/client/assets/hermes.png +0 -0
- package/client/assets/mcp/.gitkeep +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/atlassian.png +0 -0
- package/client/assets/mcp/box.png +0 -0
- package/client/assets/mcp/chrome.svg +0 -33
- 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/discord.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/figma.png +0 -0
- package/client/assets/mcp/firecrawl.png +0 -0
- package/client/assets/mcp/github.png +0 -0
- package/client/assets/mcp/gitlab.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/granola.png +0 -0
- package/client/assets/mcp/hubspot.png +0 -0
- package/client/assets/mcp/huggingface.png +0 -0
- package/client/assets/mcp/intercom.png +0 -0
- package/client/assets/mcp/linear.png +0 -0
- package/client/assets/mcp/monday.png +0 -0
- package/client/assets/mcp/mongodb.png +0 -0
- package/client/assets/mcp/neon.png +0 -0
- package/client/assets/mcp/notion.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/sentry.png +0 -0
- package/client/assets/mcp/shopify.png +0 -0
- package/client/assets/mcp/slack.png +0 -0
- package/client/assets/mcp/snowflake.png +0 -0
- package/client/assets/mcp/stripe.png +0 -0
- package/client/assets/mcp/supabase.png +0 -0
- package/client/assets/mcp/telegram.png +0 -0
- package/client/assets/mcp/twilio.png +0 -0
- package/client/assets/mcp/vercel.png +0 -0
- package/client/assets/mcp/zapier.png +0 -0
- package/client/assets/moi-logo.svg +0 -11
- package/client/assets/openai.svg +0 -1
- package/client/assets/openclaw.svg +0 -22
- package/client/assets.d.ts +0 -14
- package/client/components/shared/agent-blobatar.tsx +0 -93
- package/client/components/shared/bottom-panel.tsx +0 -65
- package/client/components/shared/composer.tsx +0 -125
- package/client/components/shared/led-logo.tsx +0 -181
- package/client/components/shared/panel-header.tsx +0 -16
- package/client/components/shared/reorderable-list.tsx +0 -204
- package/client/components/shared/screen-shell.tsx +0 -23
- package/client/components/shared/ultrafast-icon.tsx +0 -61
- package/client/components/shared/workspace-icon.tsx +0 -83
- package/client/components/ui/alert-dialog.tsx +0 -1
- package/client/components/ui/button.tsx +0 -1
- package/client/components/ui/checkbox.tsx +0 -1
- package/client/components/ui/collapsible.tsx +0 -1
- package/client/components/ui/dialog.tsx +0 -1
- package/client/components/ui/dropdown-menu.tsx +0 -1
- package/client/components/ui/hover-card.tsx +0 -1
- package/client/components/ui/inline-input.tsx +0 -84
- package/client/components/ui/input.tsx +0 -1
- package/client/components/ui/popover.tsx +0 -1
- package/client/components/ui/resizable.tsx +0 -1
- package/client/components/ui/skeleton.tsx +0 -1
- package/client/components/ui/slider.tsx +0 -1
- package/client/components/ui/spinner.tsx +0 -1
- package/client/components/ui/switch.tsx +0 -1
- package/client/components/ui/tabs.tsx +0 -1
- package/client/components/ui/textarea.tsx +0 -1
- package/client/components/ui/toast.tsx +0 -220
- package/client/components/ui/tooltip.tsx +0 -1
- package/client/dev/index.html +0 -43
- package/client/dev/index.ts +0 -15
- package/client/externalize-react.ts +0 -41
- package/client/features/account/account-menu.tsx +0 -96
- package/client/features/account/account-provider.tsx +0 -93
- package/client/features/account/account-test-utils.tsx +0 -310
- package/client/features/account/api.ts +0 -67
- package/client/features/account/profile-actions.ts +0 -29
- package/client/features/app-settings/api.ts +0 -33
- package/client/features/app-settings/avatar-upload.tsx +0 -62
- package/client/features/app-settings/general-settings.tsx +0 -39
- package/client/features/app-settings/profile-settings.tsx +0 -105
- package/client/features/app-settings/settings-page.tsx +0 -45
- package/client/features/app-settings/settings-section.tsx +0 -26
- package/client/features/applets/api.ts +0 -38
- package/client/features/applets/applet-cache.ts +0 -96
- package/client/features/applets/applet-container.tsx +0 -33
- package/client/features/applets/applet-log.ts +0 -81
- package/client/features/applets/applet-runtime.ts +0 -325
- package/client/features/applets/applet-styles.ts +0 -81
- package/client/features/applets/applet-thumbnail.ts +0 -294
- package/client/features/applets/use-applet.ts +0 -212
- package/client/features/applets/widget-error-boundary.tsx +0 -62
- package/client/features/applets/widget-shell.tsx +0 -56
- package/client/features/chat/applet-chat-intents.ts +0 -173
- package/client/features/chat/chat-panel.tsx +0 -326
- package/client/features/chat/chat-popup.tsx +0 -175
- package/client/features/chat/chat-send.ts +0 -259
- package/client/features/chat/chat-store.ts +0 -328
- package/client/features/chat/composer/attachments/attachment-chip.tsx +0 -99
- package/client/features/chat/composer/attachments/draft-attachments.ts +0 -185
- package/client/features/chat/composer/attachments/drawing-attachment-chip.tsx +0 -37
- package/client/features/chat/composer/attachments/file-attachment-chip.tsx +0 -22
- package/client/features/chat/composer/attachments/text-attachment-chip.tsx +0 -11
- package/client/features/chat/composer/attachments/types.ts +0 -25
- package/client/features/chat/composer/attachments/uploads.ts +0 -26
- package/client/features/chat/composer/banners/composer-banner.tsx +0 -16
- package/client/features/chat/composer/banners/error-banner.tsx +0 -36
- package/client/features/chat/composer/banners/skill-update-banner.tsx +0 -93
- package/client/features/chat/composer/chat-composer.tsx +0 -290
- package/client/features/chat/composer/model-order.ts +0 -110
- package/client/features/chat/composer/model-picker.tsx +0 -408
- package/client/features/chat/composer/use-workspace-composer-state.tsx +0 -69
- package/client/features/chat/composer/use-workspace-skill-updates.ts +0 -160
- package/client/features/chat/connection/chat-connection.ts +0 -107
- package/client/features/chat/connection/chat-frames.ts +0 -165
- package/client/features/chat/messages/chat-empty-state.tsx +0 -294
- package/client/features/chat/messages/chat-prompt-bubbles.tsx +0 -72
- package/client/features/chat/messages/fork-history.ts +0 -14
- package/client/features/chat/messages/group-turns.ts +0 -74
- package/client/features/chat/messages/interleave-notices.ts +0 -80
- package/client/features/chat/messages/markdown-content.tsx +0 -89
- package/client/features/chat/messages/preview-turn.ts +0 -37
- package/client/features/chat/messages/shimmer-text.tsx +0 -20
- package/client/features/chat/messages/tool-group/code-block.tsx +0 -41
- package/client/features/chat/messages/tool-group/collapse.tsx +0 -28
- package/client/features/chat/messages/tool-group/detect.ts +0 -93
- package/client/features/chat/messages/tool-group/fixtures.ts +0 -309
- package/client/features/chat/messages/tool-group/format/claude.ts +0 -49
- package/client/features/chat/messages/tool-group/format/codex.ts +0 -130
- package/client/features/chat/messages/tool-group/format/hermes.ts +0 -69
- package/client/features/chat/messages/tool-group/format/index.ts +0 -34
- package/client/features/chat/messages/tool-group/format/mcp.ts +0 -68
- package/client/features/chat/messages/tool-group/format/openclaw.ts +0 -120
- package/client/features/chat/messages/tool-group/format/shared.ts +0 -49
- package/client/features/chat/messages/tool-group/format/shell.ts +0 -162
- package/client/features/chat/messages/tool-group/index.ts +0 -9
- package/client/features/chat/messages/tool-group/read-image-preview.tsx +0 -46
- package/client/features/chat/messages/tool-group/subagent-card.tsx +0 -138
- package/client/features/chat/messages/tool-group/timeline-row.tsx +0 -159
- package/client/features/chat/messages/tool-group/tool-call-group.tsx +0 -279
- package/client/features/chat/messages/tool-group/tool-output.tsx +0 -125
- package/client/features/chat/messages/turn-view.tsx +0 -270
- package/client/features/chat/messages/use-stick-to-bottom.ts +0 -96
- package/client/features/chat/messages/user-message-bubble.tsx +0 -63
- package/client/features/chat/sessions/api.ts +0 -193
- package/client/features/chat/sessions/chat-selector.tsx +0 -399
- package/client/features/chat/sessions/session-view.ts +0 -53
- package/client/features/chat/sessions/use-selected-session.ts +0 -171
- package/client/features/chat/use-chat.ts +0 -229
- package/client/features/collab/applet-api.ts +0 -35
- package/client/features/collab/components/cursors.tsx +0 -241
- package/client/features/collab/components/presence-avatars.tsx +0 -74
- package/client/features/collab/components/presence-frame.tsx +0 -122
- package/client/features/collab/components/presence-group.tsx +0 -31
- package/client/features/collab/components/presence-helpers.ts +0 -50
- package/client/features/collab/components/user-avatar-group.tsx +0 -35
- package/client/features/collab/components/user-avatar.tsx +0 -65
- package/client/features/collab/components/user.tsx +0 -69
- package/client/features/collab/host-state.ts +0 -160
- package/client/features/collab/index.ts +0 -5
- package/client/features/collab/local-user.ts +0 -46
- package/client/features/collab/members/api.ts +0 -17
- package/client/features/collab/members/hooks.ts +0 -97
- package/client/features/collab/members/store.ts +0 -148
- package/client/features/collab/members/types.ts +0 -55
- package/client/features/collab/presence/client.ts +0 -262
- package/client/features/collab/presence/hooks.tsx +0 -160
- package/client/features/collab/presence/presence-publisher.ts +0 -30
- package/client/features/collab/presence/presence-target.ts +0 -8
- package/client/features/collab/presence/provider.tsx +0 -68
- package/client/features/collab/presence/store.ts +0 -156
- package/client/features/collab/presence/users.ts +0 -87
- package/client/features/collab/proxy-user.ts +0 -28
- package/client/features/collab/sharing/agent-invite.tsx +0 -30
- package/client/features/collab/sharing/workspace-members.tsx +0 -269
- package/client/features/collab/sharing/workspace-sharing-menu.tsx +0 -179
- package/client/features/collab/testing/component-fixtures.tsx +0 -54
- package/client/features/collab/testing/fake-engine.ts +0 -120
- package/client/features/connectors/api.ts +0 -25
- package/client/features/connectors/icon-mcp.tsx +0 -21
- package/client/features/connectors/mcp-icons.ts +0 -183
- package/client/features/connectors/mcp-server-cards.tsx +0 -105
- package/client/features/connectors/read-connectors.ts +0 -35
- package/client/features/demo/demo-dialog.tsx +0 -194
- package/client/features/dev/blobatar-shapes-page.tsx +0 -344
- package/client/features/dev/chat-states-fixtures.ts +0 -755
- package/client/features/dev/chat-states-page.tsx +0 -476
- package/client/features/dev/collab/collab-page.tsx +0 -24
- package/client/features/dev/collab/collab-playground.tsx +0 -614
- package/client/features/dev/collab/local-user-settings.tsx +0 -120
- package/client/features/dev/collab/playground-room.ts +0 -33
- package/client/features/dev/dev-index-page.tsx +0 -83
- package/client/features/dev/dev-routes.tsx +0 -43
- package/client/features/dev/harness-debug-page.tsx +0 -607
- package/client/features/dev/onboarding-preview-page.tsx +0 -76
- package/client/features/dev/texture-lab-page.tsx +0 -149
- package/client/features/dev/tool-calls-page.tsx +0 -79
- package/client/features/dev/ui-components/ui-component-previews.tsx +0 -855
- package/client/features/dev/ui-components/ui-components-page.tsx +0 -60
- package/client/features/dev/workspace-setup-mocks.ts +0 -103
- package/client/features/dev/workspace-setup-page.tsx +0 -11
- package/client/features/dev/workspace-setup-preview.tsx +0 -249
- package/client/features/drawings/capture-element.ts +0 -57
- package/client/features/drawings/drawing-layer.tsx +0 -49
- package/client/features/drawings/drawing-toolbar.tsx +0 -95
- package/client/features/drawings/use-chat-annotation.ts +0 -228
- package/client/features/drawings/use-drawing-layer.ts +0 -756
- package/client/features/drawings/use-view-sketch.ts +0 -154
- package/client/features/harness/api.ts +0 -69
- package/client/features/harness/device-login-steps.tsx +0 -103
- package/client/features/harness/harness-login-panel.tsx +0 -232
- package/client/features/harness/harness-presentation.ts +0 -15
- package/client/features/harness/harness-selector.tsx +0 -119
- package/client/features/harness/use-harness-login.ts +0 -77
- package/client/features/home/api.ts +0 -135
- package/client/features/home/home-logo.tsx +0 -344
- package/client/features/home/home-page.tsx +0 -305
- package/client/features/home/shared-workspaces.tsx +0 -70
- package/client/features/home/workspace-invitations.tsx +0 -101
- package/client/features/home/workspace-preview.tsx +0 -213
- package/client/features/identity/host-api.ts +0 -35
- package/client/features/identity/store.ts +0 -26
- package/client/features/identity/types.ts +0 -41
- package/client/features/identity/use-identity.ts +0 -6
- package/client/features/onboarding/agent-setup-step.tsx +0 -57
- package/client/features/onboarding/api.ts +0 -42
- package/client/features/onboarding/onboarding-idea-disk.tsx +0 -129
- package/client/features/onboarding/onboarding-page.tsx +0 -33
- package/client/features/onboarding/onboarding-screen.tsx +0 -20
- package/client/features/onboarding/onboarding-status.tsx +0 -24
- package/client/features/onboarding/workspace-setup-step.tsx +0 -239
- package/client/features/overview/api.ts +0 -28
- package/client/features/overview/default/registry.tsx +0 -34
- package/client/features/overview/default/views-widget.tsx +0 -246
- package/client/features/overview/grid.ts +0 -77
- package/client/features/overview/hidden-panel.tsx +0 -111
- package/client/features/overview/overview.tsx +0 -299
- package/client/features/overview/use-grid-reconcile.ts +0 -94
- package/client/features/overview/widget-canvas.tsx +0 -166
- package/client/features/overview/widget-frame.tsx +0 -77
- package/client/features/overview/workspace-name.tsx +0 -55
- package/client/features/scratchpad/scratch-executor.ts +0 -20
- package/client/features/scratchpad/scratch-session.ts +0 -71
- package/client/features/scratchpad/scratchpad-controls.tsx +0 -516
- package/client/features/scratchpad/scratchpad.tsx +0 -351
- package/client/features/scratchpad/use-scratchpad-snapshot.tsx +0 -133
- package/client/features/update/api.ts +0 -35
- package/client/features/update/update-control.tsx +0 -102
- package/client/features/views/api.ts +0 -189
- package/client/features/views/pending-view-screen.tsx +0 -303
- package/client/features/views/use-view-actions.ts +0 -119
- package/client/features/views/use-view-drafts.ts +0 -88
- package/client/features/views/view-manager.tsx +0 -293
- package/client/features/views/view-presentation.ts +0 -12
- package/client/features/views/view-residency.ts +0 -77
- package/client/features/views/view-submission.ts +0 -56
- package/client/features/workspace/add/api.ts +0 -61
- package/client/features/workspace/add/create-workspace-dialog.tsx +0 -230
- package/client/features/workspace/add/import-workspace-dialog.tsx +0 -81
- package/client/features/workspace/add/use-workspace-import.ts +0 -61
- package/client/features/workspace/add/workspace-agent-options.ts +0 -53
- package/client/features/workspace/add/workspace-agent-selector.tsx +0 -96
- package/client/features/workspace/add/workspace-dialog-content.tsx +0 -22
- package/client/features/workspace/api.ts +0 -185
- package/client/features/workspace/harness-transition.ts +0 -83
- package/client/features/workspace/moi-context.ts +0 -129
- package/client/features/workspace/remote.ts +0 -25
- package/client/features/workspace/settings/api.ts +0 -112
- package/client/features/workspace/settings/connectors-settings.tsx +0 -110
- package/client/features/workspace/settings/environment-settings.tsx +0 -149
- package/client/features/workspace/settings/general-settings.tsx +0 -180
- package/client/features/workspace/settings/icon-picker-options.ts +0 -30
- package/client/features/workspace/settings/settings-layout.tsx +0 -53
- package/client/features/workspace/settings/use-env-vars.ts +0 -20
- package/client/features/workspace/settings/workspace-icon-picker.tsx +0 -318
- package/client/features/workspace/settings/workspace-settings-dialog.tsx +0 -65
- package/client/features/workspace/setup/workspace-login-state.tsx +0 -56
- package/client/features/workspace/setup/workspace-recovery-states.tsx +0 -142
- package/client/features/workspace/setup/workspace-setup.tsx +0 -98
- package/client/features/workspace/setup/workspace-welcome-state.tsx +0 -81
- package/client/features/workspace/tab-resolution.ts +0 -32
- package/client/features/workspace/theme-panel.tsx +0 -191
- package/client/features/workspace/unavailable-page.tsx +0 -21
- package/client/features/workspace/use-fits-split-layout.ts +0 -69
- package/client/features/workspace/use-workspace-navigation.ts +0 -265
- package/client/features/workspace/workspace-content.tsx +0 -601
- package/client/features/workspace/workspace-context.tsx +0 -21
- package/client/features/workspace/workspace-frame.tsx +0 -64
- package/client/features/workspace/workspace-identity.tsx +0 -40
- package/client/features/workspace/workspace-layout-context.tsx +0 -163
- package/client/features/workspace/workspace-menu.tsx +0 -67
- package/client/features/workspace/workspace-pane.tsx +0 -22
- package/client/features/workspace/workspace-pending-screen.tsx +0 -26
- package/client/features/workspace/workspace-preferences.ts +0 -91
- package/client/features/workspace/workspace-presentation.tsx +0 -35
- package/client/features/workspace/workspace-screen.tsx +0 -28
- package/client/features/workspace/workspace-split-layout.tsx +0 -116
- package/client/features/workspace/workspace-state.ts +0 -195
- package/client/features/workspace/workspace-tabs.tsx +0 -233
- package/client/features/workspace/workspace-test-utils.ts +0 -23
- package/client/global.d.ts +0 -5
- package/client/index.css +0 -247
- package/client/index.html +0 -81
- package/client/index.tsx +0 -45
- package/client/lib/agent-availability.ts +0 -14
- package/client/lib/browser-tab-id.ts +0 -4
- package/client/lib/cn.ts +0 -6
- package/client/lib/flags.ts +0 -11
- package/client/lib/identity-icon-registry.ts +0 -150
- package/client/lib/rate-limit.ts +0 -77
- package/client/lib/use-latest-ref.ts +0 -11
- package/client/lib/user-display-name.ts +0 -6
- package/client/lib/ws-url.ts +0 -10
- package/client/main.tsx +0 -43
- package/client/runtime/app-context.ts +0 -20
- package/client/runtime/hmr-watchdog.ts +0 -39
- package/client/runtime/use-workspace-events.ts +0 -70
- package/client/runtime/workspace-events.ts +0 -168
- package/client/runtime/workspace-theme.ts +0 -175
- package/client/store/ui.ts +0 -94
- package/client/store/workspace-session.ts +0 -30
- package/client/structured-clone-shim.ts +0 -14
- package/client/tailwind-config.ts +0 -43
- package/dist/chunk-0h4zypgf.js +0 -1
- package/dist/chunk-1tksq43z.js +0 -72
- package/dist/chunk-6gxf0xr8.js +0 -5
- package/dist/chunk-h3qag4a6.js +0 -2
- package/dist/chunk-kffcah9w.css +0 -1
- package/dist/chunk-q2tpy0h7.js +0 -2
- package/dist/chunk-w5h9grdr.js +0 -1
- package/lib/applet-selector.ts +0 -24
- package/lib/attachment-note.ts +0 -66
- package/lib/chat-title.ts +0 -11
- package/lib/collab/colors.ts +0 -30
- package/lib/collab/protocol.ts +0 -84
- package/lib/collab/types.ts +0 -52
- package/lib/default-widgets.ts +0 -32
- package/lib/format.ts +0 -348
- package/lib/harness-instructions.ts +0 -30
- package/lib/harness-types.ts +0 -13
- package/lib/identity-icons.ts +0 -73
- package/lib/ids.ts +0 -39
- package/lib/message-attachments.ts +0 -40
- package/lib/moi-attachments.ts +0 -204
- package/lib/moi-context.ts +0 -305
- package/lib/navigation.ts +0 -65
- package/lib/onboarding.ts +0 -41
- package/lib/scratchpad-skew.ts +0 -64
- package/lib/session-drafts.ts +0 -10
- package/lib/speed-mode.ts +0 -5
- package/lib/system-messages.ts +0 -241
- package/lib/themes.ts +0 -241
- package/lib/types.ts +0 -779
- package/lib/update.ts +0 -2
- package/lib/view-build-directives.ts +0 -11
- package/lib/workspace-config.ts +0 -48
- package/lib/workspace-icon.ts +0 -20
- package/lib/workspace-layout.ts +0 -15
- package/lib/workspace-name.ts +0 -17
- package/lib/workspace-tabs.ts +0 -29
- package/server/AGENTS.md +0 -17
- package/server/README.md +0 -109
- package/server/agent-caller.ts +0 -16
- package/server/agent-launcher.ts +0 -27
- package/server/api/harnesses.ts +0 -79
- package/server/api/index.ts +0 -1332
- package/server/api/onboarding.ts +0 -46
- package/server/app-config.ts +0 -264
- package/server/app-settings.ts +0 -69
- package/server/applets/api-base.ts +0 -4
- package/server/applets/applet-css.ts +0 -55
- package/server/applets/build-applet.ts +0 -475
- package/server/applets/build-worker.ts +0 -179
- package/server/applets/bundle-queue.ts +0 -19
- package/server/applets/config.ts +0 -226
- package/server/applets/declarations.ts +0 -45
- package/server/applets/dependencies.ts +0 -206
- package/server/applets/functions-worker.ts +0 -121
- package/server/applets/functions.ts +0 -392
- package/server/applets/index.ts +0 -504
- package/server/applets/log.ts +0 -149
- package/server/applets/runtime/collab.ts +0 -94
- package/server/applets/runtime/moi.ts +0 -35
- package/server/applets/runtime/rpc.ts +0 -15
- package/server/applets/thumbnails.ts +0 -200
- package/server/applets/typecheck.ts +0 -100
- package/server/applets/ui-components.ts +0 -241
- package/server/applets/view-source.ts +0 -73
- package/server/applets/views.ts +0 -322
- package/server/applets/widgets.ts +0 -180
- package/server/cli/applet-selector.ts +0 -19
- package/server/cli/args.ts +0 -5
- package/server/cli/colors.ts +0 -20
- package/server/cli/commands/bundle.ts +0 -119
- package/server/cli/commands/call-server-fn.ts +0 -42
- package/server/cli/commands/check.ts +0 -53
- package/server/cli/commands/config.ts +0 -120
- package/server/cli/commands/debug.ts +0 -119
- package/server/cli/commands/env.ts +0 -162
- package/server/cli/commands/hermes.ts +0 -149
- package/server/cli/commands/init.ts +0 -323
- package/server/cli/commands/navigate.ts +0 -35
- package/server/cli/commands/openclaw.ts +0 -168
- package/server/cli/commands/refresh.ts +0 -48
- package/server/cli/commands/remote.ts +0 -330
- package/server/cli/commands/scratch.ts +0 -496
- package/server/cli/commands/service.ts +0 -298
- package/server/cli/commands/skill.ts +0 -121
- package/server/cli/commands/start.ts +0 -112
- package/server/cli/commands/status.ts +0 -80
- package/server/cli/commands/tabs.ts +0 -36
- package/server/cli/commands/theme.ts +0 -192
- package/server/cli/commands/ui-components.ts +0 -15
- package/server/cli/commands/update.ts +0 -192
- package/server/cli/commands/version.ts +0 -9
- package/server/cli/commands/views.ts +0 -87
- package/server/cli/control.ts +0 -120
- package/server/cli/env.ts +0 -259
- package/server/cli/index.ts +0 -175
- package/server/cli/pc.ts +0 -20
- package/server/cli/provider.ts +0 -25
- package/server/cli/remote-command.ts +0 -77
- package/server/cli/remote-control.ts +0 -73
- package/server/cli/remote-operations.ts +0 -247
- package/server/cli/server-version.ts +0 -16
- package/server/cli/server.ts +0 -93
- package/server/cli/ui-components.ts +0 -294
- package/server/cli/ui.ts +0 -52
- package/server/cli.ts +0 -3
- package/server/collab/cloudflare-access.ts +0 -78
- package/server/collab/config.ts +0 -13
- package/server/collab/manager.ts +0 -413
- package/server/collab/service.ts +0 -136
- package/server/collab/skill/index.ts +0 -7
- package/server/collab/worker-messages.ts +0 -10
- package/server/collab/worker.ts +0 -52
- package/server/constants.ts +0 -13
- package/server/control-client.ts +0 -124
- package/server/control.ts +0 -581
- package/server/data-dir.ts +0 -22
- package/server/debug.ts +0 -10
- package/server/events.ts +0 -24
- package/server/harness/README.md +0 -381
- package/server/harness/acp/NOTES.md +0 -426
- package/server/harness/acp/adapter.ts +0 -206
- package/server/harness/acp/archived.ts +0 -88
- package/server/harness/acp/client.ts +0 -329
- package/server/harness/acp/discovery.ts +0 -127
- package/server/harness/acp/model-state.ts +0 -57
- package/server/harness/acp/run-durations.ts +0 -68
- package/server/harness/acp/session.ts +0 -782
- package/server/harness/acp/wire.ts +0 -132
- package/server/harness/auth.ts +0 -295
- package/server/harness/claude-code/NOTES.md +0 -651
- package/server/harness/claude-code/adapter.ts +0 -876
- package/server/harness/claude-code/auth.ts +0 -178
- package/server/harness/claude-code/cli.ts +0 -42
- package/server/harness/claude-code/git-worktree.ts +0 -35
- package/server/harness/claude-code/index.ts +0 -171
- package/server/harness/claude-code/mcp.ts +0 -152
- package/server/harness/claude-code/models.ts +0 -102
- package/server/harness/claude-code/permissions.ts +0 -34
- package/server/harness/claude-code/run-action.ts +0 -123
- package/server/harness/claude-code/session-title.ts +0 -104
- package/server/harness/claude-code/session.ts +0 -965
- package/server/harness/claude-code/sessions.ts +0 -153
- package/server/harness/codex/NOTES.md +0 -259
- package/server/harness/codex/adapter.ts +0 -633
- package/server/harness/codex/auth.ts +0 -140
- package/server/harness/codex/client.ts +0 -439
- package/server/harness/codex/connectors.ts +0 -92
- package/server/harness/codex/discovery.ts +0 -106
- package/server/harness/codex/index.ts +0 -107
- package/server/harness/codex/pagination.ts +0 -27
- package/server/harness/codex/permissions.ts +0 -80
- package/server/harness/codex/probe.ts +0 -183
- package/server/harness/codex/run-action.ts +0 -93
- package/server/harness/codex/session-title.ts +0 -147
- package/server/harness/codex/session.ts +0 -1188
- package/server/harness/codex/status.ts +0 -31
- package/server/harness/codex/thread-list.ts +0 -78
- package/server/harness/codex/transport.ts +0 -191
- package/server/harness/command.ts +0 -45
- package/server/harness/debug.ts +0 -57
- package/server/harness/detect.ts +0 -164
- package/server/harness/executable.ts +0 -125
- package/server/harness/fork.ts +0 -14
- package/server/harness/hermes/NOTES.md +0 -833
- package/server/harness/hermes/discovery.ts +0 -175
- package/server/harness/hermes/index.ts +0 -167
- package/server/harness/hermes/models.ts +0 -99
- package/server/harness/install.ts +0 -49
- package/server/harness/openclaw/NOTES.md +0 -749
- package/server/harness/openclaw/adapter.ts +0 -336
- package/server/harness/openclaw/compat.ts +0 -95
- package/server/harness/openclaw/cron-view.ts +0 -78
- package/server/harness/openclaw/discovery.ts +0 -456
- package/server/harness/openclaw/gateway.ts +0 -467
- package/server/harness/openclaw/index.ts +0 -125
- package/server/harness/openclaw/session.ts +0 -1508
- package/server/harness/openclaw/strip.ts +0 -184
- package/server/harness/openclaw/thinking.ts +0 -150
- package/server/harness/registry.ts +0 -39
- package/server/harness/run-action.ts +0 -85
- package/server/harness/session-title.ts +0 -59
- package/server/harness/shell-path.ts +0 -89
- package/server/harness/types.ts +0 -170
- package/server/navigation-relay.ts +0 -110
- package/server/onboarding/brief.ts +0 -29
- package/server/onboarding/ideas.ts +0 -48
- package/server/onboarding/jobs.ts +0 -291
- package/server/open-browser.ts +0 -7
- package/server/operations/commands.ts +0 -46
- package/server/operations/files.ts +0 -148
- package/server/operations/server.ts +0 -206
- package/server/remote/agent.ts +0 -103
- package/server/remote/broker-client.ts +0 -76
- package/server/remote/broker.ts +0 -81
- package/server/remote/client.ts +0 -725
- package/server/remote/errors.ts +0 -2
- package/server/remote/routes.ts +0 -121
- package/server/remote/workspace.ts +0 -34
- package/server/scratchpad/assets.ts +0 -258
- package/server/scratchpad/document.ts +0 -312
- package/server/scratchpad/executor.ts +0 -499
- package/server/scratchpad/relay.ts +0 -44
- package/server/scratchpad/shape-defaults.ts +0 -82
- package/server/server-cwd.ts +0 -23
- package/server/service.ts +0 -800
- package/server/sessions/archive.ts +0 -23
- package/server/sessions/attachment-message.ts +0 -95
- package/server/sessions/config.ts +0 -45
- package/server/sessions/lifecycle.ts +0 -19
- package/server/sessions/pending-views.ts +0 -152
- package/server/sessions/selected.ts +0 -113
- package/server/sessions/send-message.ts +0 -102
- package/server/sessions/store.ts +0 -54
- package/server/sessions/view-sessions.ts +0 -192
- package/server/skills/locations.ts +0 -82
- package/server/skills/lock.ts +0 -29
- package/server/skills/template.ts +0 -94
- package/server/skills/update.ts +0 -94
- package/server/skills/version.ts +0 -129
- package/server/skills/workspace.ts +0 -121
- package/server/state.ts +0 -40
- package/server/static.ts +0 -25
- package/server/status.ts +0 -110
- package/server/tldraw-package.d.ts +0 -4
- package/server/update.ts +0 -429
- package/server/uploads.ts +0 -290
- package/server/vendor.ts +0 -63
- package/server/version.ts +0 -41
- package/server/web.ts +0 -340
- package/server/workspace-state/file.ts +0 -181
- package/server/workspace-state/index.ts +0 -158
- package/server/workspace-state/lock.ts +0 -42
- package/server/workspace-state/types.ts +0 -16
- package/server/workspaces/api.ts +0 -24
- package/server/workspaces/change-harness.ts +0 -77
- package/server/workspaces/config.ts +0 -41
- package/server/workspaces/env-apply.ts +0 -20
- package/server/workspaces/env.ts +0 -424
- package/server/workspaces/harness-transition.ts +0 -29
- package/server/workspaces/icon.ts +0 -13
- package/server/workspaces/import.ts +0 -74
- package/server/workspaces/init.ts +0 -74
- package/server/workspaces/layout.ts +0 -157
- package/server/workspaces/preview.ts +0 -72
- package/server/workspaces/registry.ts +0 -330
- package/server/workspaces/required-env.ts +0 -19
- package/server/workspaces/scaffold.ts +0 -189
- package/server/workspaces/shared.ts +0 -74
- package/server/workspaces/tabs.ts +0 -35
- package/server/workspaces/theme.ts +0 -58
- package/tsconfig.json +0 -20
package/server/api/index.ts
DELETED
|
@@ -1,1332 +0,0 @@
|
|
|
1
|
-
import { openSharedWorkspace } from '../workspaces/shared'
|
|
2
|
-
import { executeScratchOp } from '../scratchpad/executor'
|
|
3
|
-
import type { ScratchOp, WorkspaceInfoResponse } from '@/lib/types'
|
|
4
|
-
import { workspaceApiBase, parseRemoteWorkspaceTarget } from '@/lib/workspace-config'
|
|
5
|
-
import { loadWorkspaceFileConfig } from '../workspaces/layout'
|
|
6
|
-
import { resolveWorkspaceEnv } from '../workspaces/env'
|
|
7
|
-
import { changeWorkspaceHarness } from '../workspaces/change-harness'
|
|
8
|
-
import { HarnessTransitionError, reserveWorkspaceOperation } from '../workspaces/harness-transition'
|
|
9
|
-
import { onboarding } from './onboarding'
|
|
10
|
-
import type { SpeedMode } from '@/lib/types'
|
|
11
|
-
import { isSpeedMode } from '@/lib/speed-mode'
|
|
12
|
-
import { isMessageAttachments } from '@/lib/message-attachments'
|
|
13
|
-
import { Hono } from 'hono'
|
|
14
|
-
import { serveStatic } from 'hono/bun'
|
|
15
|
-
import { createMiddleware } from 'hono/factory'
|
|
16
|
-
import { existsSync } from 'node:fs'
|
|
17
|
-
import { basename, resolve } from 'node:path'
|
|
18
|
-
|
|
19
|
-
import { UPDATE_ACTIVE_AGENT_MESSAGE } from '@/lib/update'
|
|
20
|
-
import { resolveWorkspaceTheme } from '@/lib/themes'
|
|
21
|
-
import { isWorkspaceIcon } from '@/lib/workspace-icon'
|
|
22
|
-
import type {
|
|
23
|
-
AppletKind,
|
|
24
|
-
AppletThumbnailBatch,
|
|
25
|
-
AppSettings,
|
|
26
|
-
HarnessAvailability,
|
|
27
|
-
UploadInfo,
|
|
28
|
-
WorkspaceHarness,
|
|
29
|
-
WorkspaceEntry,
|
|
30
|
-
HarnessType
|
|
31
|
-
} from '@/lib/types'
|
|
32
|
-
import { isWorkspaceTabId } from '@/lib/workspace-tabs'
|
|
33
|
-
|
|
34
|
-
import { proxyUserState } from '../collab/cloudflare-access'
|
|
35
|
-
import { collabManager } from '../collab/manager'
|
|
36
|
-
import { harnessStore } from '../harness/auth'
|
|
37
|
-
import { harnesses } from './harnesses'
|
|
38
|
-
import { clientAppConfig, createdWorkspacesRoot, getAppConfig } from '../app-config'
|
|
39
|
-
import { getAppSettings, pickAppSettingsPatch, saveAppSettings } from '../app-settings'
|
|
40
|
-
import { appletForModule, recordAppletError } from '../applets/log'
|
|
41
|
-
import { parseAppletTail, serveWorkspaceFile } from '../applets'
|
|
42
|
-
import { applyEnvChanged } from '../workspaces/env-apply'
|
|
43
|
-
import { publishEvent } from '../events'
|
|
44
|
-
import { callFunction, parseFunctionPath } from '../applets/functions'
|
|
45
|
-
import { processIcon } from '../workspaces/icon'
|
|
46
|
-
import {
|
|
47
|
-
getWorkspacePreview,
|
|
48
|
-
loadLayout,
|
|
49
|
-
mergeLayoutForSave,
|
|
50
|
-
saveLayout
|
|
51
|
-
} from '../workspaces/layout'
|
|
52
|
-
import {
|
|
53
|
-
getAppletThumbnailRecords,
|
|
54
|
-
isValidAppletId,
|
|
55
|
-
saveAppletThumbnails,
|
|
56
|
-
serveAppletThumbnail
|
|
57
|
-
} from '../applets/thumbnails'
|
|
58
|
-
import { getClientFrameLog, getWireLog } from '../harness/debug'
|
|
59
|
-
import { loginShellPath } from '../harness/shell-path'
|
|
60
|
-
import { allHarnesses, harnessFor, isHarnessType } from '../harness/registry'
|
|
61
|
-
import {
|
|
62
|
-
discoverWorkspaces,
|
|
63
|
-
getWorkspace,
|
|
64
|
-
listWorkspaces,
|
|
65
|
-
registerWorkspace,
|
|
66
|
-
removeWorkspace,
|
|
67
|
-
reorderWorkspaces
|
|
68
|
-
} from '../workspaces/registry'
|
|
69
|
-
import { loadScratchpadDoc, saveScratchpadDoc } from '../scratchpad/document'
|
|
70
|
-
import { MAX_ASSET_BYTES, scratchpadAssetFile, storeScratchpadAsset } from '../scratchpad/assets'
|
|
71
|
-
import {
|
|
72
|
-
deselectSession,
|
|
73
|
-
getPinnedSession,
|
|
74
|
-
pinSession,
|
|
75
|
-
saveSelectedSession,
|
|
76
|
-
unpinSession
|
|
77
|
-
} from '../sessions/selected'
|
|
78
|
-
import { saveSessionConfig } from '../sessions/config'
|
|
79
|
-
import type { SessionConfigPatch } from '../sessions/config'
|
|
80
|
-
import { archiveWorkspaceSession } from '../sessions/archive'
|
|
81
|
-
import { getWorkspaceState, updateWorkspaceState } from '../workspace-state'
|
|
82
|
-
import { normalizeOpenTabs } from '@/lib/workspace-layout'
|
|
83
|
-
import { DIST_DIR, prebuilt } from '../static'
|
|
84
|
-
import { getWorkspaceSkillsStatus, updateWorkspaceSkills } from '../skills/update'
|
|
85
|
-
import { serveWorkspaceImagePreview } from '../workspaces/preview'
|
|
86
|
-
import { MAX_UPLOAD_BYTES, addUpload, addWorkspaceFileUpload, getUpload } from '../uploads'
|
|
87
|
-
import { requiredEnvFor } from '../workspaces/required-env'
|
|
88
|
-
import {
|
|
89
|
-
deleteView,
|
|
90
|
-
listCompiledViews,
|
|
91
|
-
getWorkspaceViews,
|
|
92
|
-
listViews,
|
|
93
|
-
serveView,
|
|
94
|
-
updateViewTitle,
|
|
95
|
-
ViewMutationError
|
|
96
|
-
} from '../applets/views'
|
|
97
|
-
import {
|
|
98
|
-
createPendingView,
|
|
99
|
-
discardPendingView,
|
|
100
|
-
getPendingView,
|
|
101
|
-
updatePendingView,
|
|
102
|
-
PendingViewError
|
|
103
|
-
} from '../sessions/pending-views'
|
|
104
|
-
import { submitView, ViewStartupError } from '../sessions/view-sessions'
|
|
105
|
-
import { listWidgets, serveWidget } from '../applets/widgets'
|
|
106
|
-
import { getWorkspaceConfig, setWorkspaceConfig } from '../workspaces/config'
|
|
107
|
-
import { createWorkspaceDirectory, provisionWorkspace } from '../workspaces/init'
|
|
108
|
-
import { validateWorkspaceName } from '@/lib/workspace-name'
|
|
109
|
-
import { resolveWorkspaceImportMetadata } from '../workspaces/import'
|
|
110
|
-
import type { WorkspaceImportMetadata } from '../workspaces/import'
|
|
111
|
-
import { getWorkspaceEnvView, parseEnvUpdate, updateWorkspaceEnv } from '../workspaces/env'
|
|
112
|
-
import {
|
|
113
|
-
getCachedUpdateStatus,
|
|
114
|
-
hasRunningAgentSessions,
|
|
115
|
-
installUpdate,
|
|
116
|
-
restartPendingForUpdate,
|
|
117
|
-
scheduleRestartForUpdate,
|
|
118
|
-
updateInProgress
|
|
119
|
-
} from '../update'
|
|
120
|
-
|
|
121
|
-
// The resolved workspace is stashed on the context by the workspace middleware, so every
|
|
122
|
-
// `/api/workspaces/:id/*` handler can read it without re-querying the registry.
|
|
123
|
-
type ApiEnv = { Variables: { ws: WorkspaceEntry } }
|
|
124
|
-
|
|
125
|
-
// The writing browser tab's id from a request body, echoed on the resulting
|
|
126
|
-
// event so that tab can skip it. See client/lib/browser-tab-id.ts.
|
|
127
|
-
function eventOrigin(value: unknown): string | undefined {
|
|
128
|
-
return typeof value === 'string' ? value : undefined
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
async function handleFunctionCall(
|
|
132
|
-
req: Request,
|
|
133
|
-
tail: string,
|
|
134
|
-
workspacePath: string
|
|
135
|
-
): Promise<Response> {
|
|
136
|
-
// Module keys may contain slashes (`widgets/hello/getWeather`), so the
|
|
137
|
-
// tail is parsed on the last slash — see parseFunctionPath.
|
|
138
|
-
const parsed = parseFunctionPath(tail)
|
|
139
|
-
if (!parsed) {
|
|
140
|
-
return new Response('Invalid module or function name', { status: 400 })
|
|
141
|
-
}
|
|
142
|
-
const { module, name } = parsed
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
const contentLength = Number(req.headers.get('content-length') ?? 0)
|
|
146
|
-
if (contentLength > 1_000_000) {
|
|
147
|
-
return new Response('Request body too large', { status: 413 })
|
|
148
|
-
}
|
|
149
|
-
const args = await req.text()
|
|
150
|
-
const result = await callFunction(module, name, args, workspacePath)
|
|
151
|
-
return new Response(result, {
|
|
152
|
-
headers: { 'Content-Type': 'application/json' }
|
|
153
|
-
})
|
|
154
|
-
} catch (err) {
|
|
155
|
-
const message = err instanceof Error ? err.message : 'Unknown error'
|
|
156
|
-
// Journal the failure so the agent can find it via `moi debug logs` — the
|
|
157
|
-
// 500 body below only reaches the browser (see docs/self-correction.md).
|
|
158
|
-
recordAppletError(workspacePath, {
|
|
159
|
-
source: 'rpc',
|
|
160
|
-
...(appletForModule(module) ?? {}),
|
|
161
|
-
module,
|
|
162
|
-
fn: name,
|
|
163
|
-
message
|
|
164
|
-
})
|
|
165
|
-
return new Response(message, { status: 500 })
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Resolve the workspace and enforce the route's storage boundary. Personal
|
|
170
|
-
// routes use this Moi's chats, agent and pending views, including for a remote
|
|
171
|
-
// reference. Shared content must be requested at the owner's workspace address.
|
|
172
|
-
function workspaceAccess(
|
|
173
|
-
scope: 'personal' | 'owner',
|
|
174
|
-
{ reserveOperation = true }: { reserveOperation?: boolean } = {}
|
|
175
|
-
) {
|
|
176
|
-
return createMiddleware<ApiEnv>(async (c, next) => {
|
|
177
|
-
const id = c.req.param('id')
|
|
178
|
-
if (!id) return c.text('Workspace not found', 404)
|
|
179
|
-
let release: (() => void) | undefined
|
|
180
|
-
try {
|
|
181
|
-
if (reserveOperation && c.req.method !== 'GET') release = reserveWorkspaceOperation(id)
|
|
182
|
-
const ws = await getWorkspace(id)
|
|
183
|
-
if (!ws) return c.text('Workspace not found', 404)
|
|
184
|
-
if (ws.remote && getAppConfig().environment !== 'cloud')
|
|
185
|
-
return c.text('Remote workspaces require Cloud mode', 403)
|
|
186
|
-
if (ws.remote && scope === 'owner') return c.text('Use the owner workspace address', 404)
|
|
187
|
-
c.set('ws', ws)
|
|
188
|
-
await next()
|
|
189
|
-
} catch (error) {
|
|
190
|
-
if (error instanceof HarnessTransitionError) return c.text(error.message, 409)
|
|
191
|
-
throw error
|
|
192
|
-
} finally {
|
|
193
|
-
release?.()
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const personalWorkspace = workspaceAccess('personal')
|
|
199
|
-
const ownerWorkspace = workspaceAccess('owner')
|
|
200
|
-
|
|
201
|
-
// ---- single workspace: /api/workspaces/:id/* --------------------------------
|
|
202
|
-
const one = new Hono<ApiEnv>()
|
|
203
|
-
// Switching agents takes its own exclusive lock.
|
|
204
|
-
one.patch('/harness', workspaceAccess('personal', { reserveOperation: false }), async c => {
|
|
205
|
-
if (getAppConfig().demo) return c.text('Changing agents is unavailable in the demo', 403)
|
|
206
|
-
const body = await c.req.json().catch(() => null)
|
|
207
|
-
if (!body || !['claude-code', 'codex'].includes(body.harness))
|
|
208
|
-
return c.text('Invalid agent selection', 400)
|
|
209
|
-
try {
|
|
210
|
-
return c.json(await changeWorkspaceHarness(c.get('ws'), body.harness))
|
|
211
|
-
} catch (error) {
|
|
212
|
-
if (error instanceof HarnessTransitionError) return c.text(error.message, 409)
|
|
213
|
-
throw error
|
|
214
|
-
}
|
|
215
|
-
})
|
|
216
|
-
|
|
217
|
-
one.get('/widgets', ownerWorkspace, c => listWidgets(c.get('ws').path))
|
|
218
|
-
|
|
219
|
-
// Widget bundle: the compiled ESM for one widget, dynamically imported by the
|
|
220
|
-
// client (useWidget). Sits beside the GET .../widgets list above — the exact
|
|
221
|
-
// path lists, `/*` serves a file from the bundle dir (`<name>/<file>`:
|
|
222
|
-
// index.js, a chunk, or a hashed asset).
|
|
223
|
-
one.get('/widgets/*', ownerWorkspace, c => {
|
|
224
|
-
const ws = c.get('ws')
|
|
225
|
-
const { name, file } = parseAppletTail(c.req.url, ws.id, 'widgets')
|
|
226
|
-
if (!name) return c.text('Not found', 404)
|
|
227
|
-
return serveWidget(name, file, ws.path, workspaceApiBase(ws.id), c.req.header('if-none-match'))
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
// Views — full-screen agent apps. Mirrors the widget pair above: the exact path
|
|
231
|
-
// lists (in manifest/nav order), `/*` serves one bundle file.
|
|
232
|
-
one.get('/views', ownerWorkspace, async c =>
|
|
233
|
-
c.req.query('includePending') === 'true'
|
|
234
|
-
? c.json({ views: await getWorkspaceViews(c.get('ws')) })
|
|
235
|
-
: listViews(c.get('ws').path)
|
|
236
|
-
)
|
|
237
|
-
|
|
238
|
-
const OWNER_VIEW = 'Use the owner workspace address for compiled views'
|
|
239
|
-
|
|
240
|
-
// Pending views are personal; these handlers also accept compiled views on the owner.
|
|
241
|
-
one.patch('/views/:viewId', personalWorkspace, async c => {
|
|
242
|
-
const ws = c.get('ws')
|
|
243
|
-
const body = await c.req.json().catch(() => null)
|
|
244
|
-
if (await getPendingView(ws, c.req.param('viewId'))) {
|
|
245
|
-
try {
|
|
246
|
-
if (
|
|
247
|
-
typeof body?.requirements !== 'string' &&
|
|
248
|
-
typeof body?.title !== 'string' &&
|
|
249
|
-
typeof body?.icon !== 'string'
|
|
250
|
-
)
|
|
251
|
-
return c.text('Expected requirements, title, or icon', 400)
|
|
252
|
-
return c.json(
|
|
253
|
-
await updatePendingView(ws, c.req.param('viewId'), {
|
|
254
|
-
requirements: typeof body.requirements === 'string' ? body.requirements : undefined,
|
|
255
|
-
title: typeof body.title === 'string' ? body.title.trim() : undefined,
|
|
256
|
-
icon: typeof body.icon === 'string' ? body.icon : undefined
|
|
257
|
-
})
|
|
258
|
-
)
|
|
259
|
-
} catch (error) {
|
|
260
|
-
if (error instanceof PendingViewError) return c.text(error.message, error.status)
|
|
261
|
-
throw error
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
if (ws.remote) return c.text(OWNER_VIEW, 404)
|
|
265
|
-
const title = typeof body?.title === 'string' ? body.title.trim() : ''
|
|
266
|
-
if (!title) return c.text('Expected { title: string }', 400)
|
|
267
|
-
|
|
268
|
-
try {
|
|
269
|
-
return c.json(await updateViewTitle(publishEvent, ws.id, ws.path, c.req.param('viewId'), title))
|
|
270
|
-
} catch (error) {
|
|
271
|
-
if (error instanceof ViewMutationError || error instanceof PendingViewError)
|
|
272
|
-
return c.text(error.message, error.status)
|
|
273
|
-
throw error
|
|
274
|
-
}
|
|
275
|
-
})
|
|
276
|
-
|
|
277
|
-
one.delete('/views/:viewId', personalWorkspace, async c => {
|
|
278
|
-
const ws = c.get('ws')
|
|
279
|
-
try {
|
|
280
|
-
const viewId = c.req.param('viewId')
|
|
281
|
-
if (await getPendingView(ws, viewId)) {
|
|
282
|
-
const active = new Set(
|
|
283
|
-
harnessFor(ws)
|
|
284
|
-
.activeSessions()
|
|
285
|
-
.filter(session => session.workspaceId === ws.id)
|
|
286
|
-
.map(session => session.sessionId)
|
|
287
|
-
)
|
|
288
|
-
await discardPendingView(ws, viewId, active)
|
|
289
|
-
} else if (ws.remote) return c.text(OWNER_VIEW, 404)
|
|
290
|
-
else await deleteView(publishEvent, ws, viewId)
|
|
291
|
-
return c.body(null, 204)
|
|
292
|
-
} catch (error) {
|
|
293
|
-
if (error instanceof ViewMutationError || error instanceof PendingViewError)
|
|
294
|
-
return c.text(error.message, error.status)
|
|
295
|
-
throw error
|
|
296
|
-
}
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
one.get('/views/*', ownerWorkspace, c => {
|
|
300
|
-
const ws = c.get('ws')
|
|
301
|
-
const { name, file } = parseAppletTail(c.req.url, ws.id, 'views')
|
|
302
|
-
if (!name) return c.text('Not found', 404)
|
|
303
|
-
return serveView(name, file, ws.path, workspaceApiBase(ws.id), c.req.header('if-none-match'))
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
one.post('/views', personalWorkspace, async c => {
|
|
307
|
-
const ws = c.get('ws')
|
|
308
|
-
return c.json(await createPendingView(ws), 201)
|
|
309
|
-
})
|
|
310
|
-
|
|
311
|
-
one.post('/views/:viewId/submit', personalWorkspace, async c => {
|
|
312
|
-
const ws = c.get('ws')
|
|
313
|
-
const body = await c.req.json<{
|
|
314
|
-
requirements?: string
|
|
315
|
-
sessionId?: string
|
|
316
|
-
optimisticId?: string
|
|
317
|
-
model?: string
|
|
318
|
-
effort?: string
|
|
319
|
-
speedMode?: SpeedMode
|
|
320
|
-
stream?: boolean
|
|
321
|
-
attachments?: unknown
|
|
322
|
-
}>()
|
|
323
|
-
if (typeof body?.requirements !== 'string') {
|
|
324
|
-
return c.text('Expected { requirements: string }', 400)
|
|
325
|
-
}
|
|
326
|
-
if (body.optimisticId !== undefined && typeof body.optimisticId !== 'string') {
|
|
327
|
-
return c.text('Invalid optimisticId', 400)
|
|
328
|
-
}
|
|
329
|
-
const attachments = body.attachments ?? []
|
|
330
|
-
if (!isMessageAttachments(attachments)) return c.text('Invalid attachments', 400)
|
|
331
|
-
for (const attachment of attachments) {
|
|
332
|
-
if (attachment.type !== 'upload') continue
|
|
333
|
-
if (!/^[a-f0-9]{64}$/.test(attachment.uploadId)) return c.text('Invalid upload id', 400)
|
|
334
|
-
if (!getUpload(ws.id, attachment.uploadId))
|
|
335
|
-
return c.text('Attachment not found or expired', 400)
|
|
336
|
-
}
|
|
337
|
-
const availability = await harnessTypeAvailability(ws.harness ?? 'claude-code')
|
|
338
|
-
if (availability.status !== 'available') return c.text(availability.reason, 400)
|
|
339
|
-
try {
|
|
340
|
-
const result = await submitView(ws, c.req.param('viewId'), {
|
|
341
|
-
requirements: body.requirements,
|
|
342
|
-
sessionId: typeof body.sessionId === 'string' ? body.sessionId : undefined,
|
|
343
|
-
attachments,
|
|
344
|
-
optimisticId: body.optimisticId,
|
|
345
|
-
model: typeof body.model === 'string' ? body.model : undefined,
|
|
346
|
-
effort: typeof body.effort === 'string' ? body.effort : undefined,
|
|
347
|
-
speedMode: isSpeedMode(body.speedMode) ? body.speedMode : undefined,
|
|
348
|
-
stream: body.stream === true ? true : undefined
|
|
349
|
-
})
|
|
350
|
-
return c.json({ ...result, state: await getWorkspaceState(ws) })
|
|
351
|
-
} catch (err) {
|
|
352
|
-
if (err instanceof PendingViewError) return c.text(err.message, err.status)
|
|
353
|
-
if (err instanceof ViewStartupError)
|
|
354
|
-
return c.json({ error: err.message, viewId: err.viewId, sessionId: err.sessionId }, 500)
|
|
355
|
-
throw err
|
|
356
|
-
}
|
|
357
|
-
})
|
|
358
|
-
|
|
359
|
-
// Workspace file stream — `resolveUrl('moi:/files/...')` resolves here. Streams a
|
|
360
|
-
// media file from the workspace root (range-enabled). Guarded: traversal and
|
|
361
|
-
// dotfiles (`.env`, `.moi`, `.git`) are rejected and only media/asset extensions
|
|
362
|
-
// are allowed — the workspace holds secrets, and this route is unauthenticated.
|
|
363
|
-
// localhost binding is NOT the guard.
|
|
364
|
-
one.get('/files/*', ownerWorkspace, c => {
|
|
365
|
-
const ws = c.get('ws')
|
|
366
|
-
const tail = new URL(c.req.url).pathname.split(`${workspaceApiBase(ws.id)}/files/`)[1] ?? ''
|
|
367
|
-
return serveWorkspaceFile(ws.path, tail, c.req.header('range'), c.req.header('if-none-match'))
|
|
368
|
-
})
|
|
369
|
-
|
|
370
|
-
// Applet RPC — the home for server-function calls from a bundle. The bundle's
|
|
371
|
-
// sentinel base resolves to `/api/workspaces/<id>`, so it POSTs to
|
|
372
|
-
// `…/rpc/<module>/<fn>`.
|
|
373
|
-
one.post('/rpc/*', ownerWorkspace, c => {
|
|
374
|
-
const ws = c.get('ws')
|
|
375
|
-
const tail = new URL(c.req.url).pathname.split(`${workspaceApiBase(ws.id)}/rpc/`)[1] ?? ''
|
|
376
|
-
return handleFunctionCall(c.req.raw, tail, ws.path)
|
|
377
|
-
})
|
|
378
|
-
|
|
379
|
-
// Browser-side applet errors (module load failures, render crashes, window
|
|
380
|
-
// errors attributed to a bundle) reported into the workspace's error journal —
|
|
381
|
-
// `moi debug logs` reads it back (docs/self-correction.md). Unauthenticated
|
|
382
|
-
// localhost route, so treat the payload as hostile: whitelist the browser-only
|
|
383
|
-
// sources (`build`/`rpc` are server-recorded and can't be spoofed by a tab),
|
|
384
|
-
// pattern-check the applet name, cap the batch size; applets/log.ts caps string
|
|
385
|
-
// lengths.
|
|
386
|
-
one.post('/applet-log', ownerWorkspace, async c => {
|
|
387
|
-
let body: { events?: unknown }
|
|
388
|
-
try {
|
|
389
|
-
body = await c.req.json()
|
|
390
|
-
} catch {
|
|
391
|
-
return c.text('Invalid JSON', 400)
|
|
392
|
-
}
|
|
393
|
-
const events = Array.isArray(body.events) ? body.events.slice(0, 10) : []
|
|
394
|
-
for (const raw of events) {
|
|
395
|
-
const e = raw as {
|
|
396
|
-
source?: unknown
|
|
397
|
-
kind?: unknown
|
|
398
|
-
name?: unknown
|
|
399
|
-
message?: unknown
|
|
400
|
-
stack?: unknown
|
|
401
|
-
}
|
|
402
|
-
if (
|
|
403
|
-
e.source !== 'load' &&
|
|
404
|
-
e.source !== 'render' &&
|
|
405
|
-
e.source !== 'window' &&
|
|
406
|
-
e.source !== 'runtime'
|
|
407
|
-
)
|
|
408
|
-
continue
|
|
409
|
-
// `runtime` entries may be unattributed (a stale link to a deleted view
|
|
410
|
-
// names no applet), so attribution is optional there and dropped when
|
|
411
|
-
// malformed — every other source must name the applet that broke.
|
|
412
|
-
const attributed = (e.kind === 'widget' || e.kind === 'view') && typeof e.name === 'string'
|
|
413
|
-
const named = attributed && /^[a-zA-Z0-9_-]+$/.test(e.name as string)
|
|
414
|
-
if (!named && e.source !== 'runtime') continue
|
|
415
|
-
if (typeof e.message !== 'string' || !e.message) continue
|
|
416
|
-
recordAppletError(c.get('ws').path, {
|
|
417
|
-
source: e.source,
|
|
418
|
-
...(named ? { kind: e.kind as AppletKind, name: e.name as string } : {}),
|
|
419
|
-
message: e.message,
|
|
420
|
-
...(typeof e.stack === 'string' ? { stack: e.stack } : {})
|
|
421
|
-
})
|
|
422
|
-
}
|
|
423
|
-
return c.body(null, 204)
|
|
424
|
-
})
|
|
425
|
-
|
|
426
|
-
// Downscaled image preview of a workspace file. The chat's expanded tool rows
|
|
427
|
-
// use this to show the picture an agent `Read` — same guards as /files/ above,
|
|
428
|
-
// images only, resized server-side (see server/workspaces/preview.ts).
|
|
429
|
-
one.get('/preview/*', personalWorkspace, c => {
|
|
430
|
-
const ws = c.get('ws')
|
|
431
|
-
const tail = new URL(c.req.url).pathname.split(`${workspaceApiBase(ws.id)}/preview/`)[1] ?? ''
|
|
432
|
-
return serveWorkspaceImagePreview(ws.path, tail, c.req.header('if-none-match'))
|
|
433
|
-
})
|
|
434
|
-
|
|
435
|
-
// Chat attachments. The composer POSTs files here (drag/drop, paste, or the
|
|
436
|
-
// attach button) ahead of sending; we process + stash them and hand back opaque
|
|
437
|
-
// upload ids the chat WS frame references. Images are downscaled and inlined as
|
|
438
|
-
// vision blocks at send time; other files are referenced by a temp path. See
|
|
439
|
-
// server/uploads.ts and dev/file-uploads.md.
|
|
440
|
-
one.post('/uploads', personalWorkspace, async c => {
|
|
441
|
-
const ws = c.get('ws')
|
|
442
|
-
let form: FormData
|
|
443
|
-
try {
|
|
444
|
-
form = await c.req.formData()
|
|
445
|
-
} catch {
|
|
446
|
-
return c.text('Choose a file to upload', 400)
|
|
447
|
-
}
|
|
448
|
-
const files = form.getAll('files').filter((f): f is File => f instanceof File)
|
|
449
|
-
if (files.length === 0) return c.text('Choose a file to upload', 400)
|
|
450
|
-
if (files.length > 20) return c.text('You can upload up to 20 files at a time', 400)
|
|
451
|
-
|
|
452
|
-
const out: UploadInfo[] = []
|
|
453
|
-
for (const file of files) {
|
|
454
|
-
if (file.size > MAX_UPLOAD_BYTES) {
|
|
455
|
-
return c.text(`Files can be up to ${MAX_UPLOAD_BYTES / (1024 * 1024)} MB`, 413)
|
|
456
|
-
}
|
|
457
|
-
try {
|
|
458
|
-
const bytes = Buffer.from(await file.arrayBuffer())
|
|
459
|
-
out.push(
|
|
460
|
-
await addUpload({
|
|
461
|
-
workspaceId: ws.id,
|
|
462
|
-
filename: file.name || 'file',
|
|
463
|
-
mediaType: file.type || 'application/octet-stream',
|
|
464
|
-
bytes
|
|
465
|
-
})
|
|
466
|
-
)
|
|
467
|
-
} catch {
|
|
468
|
-
return c.text(`Couldn’t process "${file.name}"`, 400)
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
return c.json(out)
|
|
472
|
-
})
|
|
473
|
-
|
|
474
|
-
// Existing workspace documents enter the same upload pipeline without a browser round trip.
|
|
475
|
-
one.post('/uploads/from-path', personalWorkspace, async c => {
|
|
476
|
-
const body: unknown = await c.req.json().catch(() => null)
|
|
477
|
-
if (!body || typeof body !== 'object' || !('path' in body) || typeof body.path !== 'string') {
|
|
478
|
-
return c.text('Choose a file from this workspace', 400)
|
|
479
|
-
}
|
|
480
|
-
const ws = c.get('ws')
|
|
481
|
-
try {
|
|
482
|
-
return c.json(await addWorkspaceFileUpload(ws.id, ws.path, body.path))
|
|
483
|
-
} catch (error) {
|
|
484
|
-
if (error instanceof Error && 'code' in error) {
|
|
485
|
-
if (error.code === 'ENOENT') return c.text('This file no longer exists', 400)
|
|
486
|
-
if (error.code === 'EACCES' || error.code === 'EPERM')
|
|
487
|
-
return c.text('This file can’t be read by Moi', 400)
|
|
488
|
-
return c.text('Something went wrong while adding this file', 400)
|
|
489
|
-
}
|
|
490
|
-
return c.text(
|
|
491
|
-
error instanceof Error ? error.message : 'Something went wrong while adding this file',
|
|
492
|
-
400
|
|
493
|
-
)
|
|
494
|
-
}
|
|
495
|
-
})
|
|
496
|
-
|
|
497
|
-
// Serve an upload's bytes back. Display parts reference this URL instead of a
|
|
498
|
-
// base64 data URL so the transcript broadcast / client cache stay small. The id
|
|
499
|
-
// is content-addressed (sha256), so the response is immutable while it lives —
|
|
500
|
-
// let the browser cache it for the store's TTL.
|
|
501
|
-
one.get('/uploads/:uploadId', personalWorkspace, c => {
|
|
502
|
-
const u = getUpload(c.get('ws').id, c.req.param('uploadId'))
|
|
503
|
-
if (!u) return c.text('Not found or expired', 404)
|
|
504
|
-
const body = u.data ? new Uint8Array(u.data) : u.path ? Bun.file(u.path) : null
|
|
505
|
-
if (!body) return c.text('Not found or expired', 404)
|
|
506
|
-
return new Response(body, {
|
|
507
|
-
headers: {
|
|
508
|
-
'Content-Type': u.mediaType,
|
|
509
|
-
'Content-Disposition': `inline; filename="${u.filename.replaceAll('"', '')}"`,
|
|
510
|
-
'Cache-Control': 'private, max-age=1800, immutable'
|
|
511
|
-
}
|
|
512
|
-
})
|
|
513
|
-
})
|
|
514
|
-
|
|
515
|
-
// Personal state writes return the latest snapshot and publish `state:changed`.
|
|
516
|
-
one.get('/state', personalWorkspace, async c => c.json(await getWorkspaceState(c.get('ws'))))
|
|
517
|
-
|
|
518
|
-
one.put('/state/tabs', personalWorkspace, async c => {
|
|
519
|
-
const body = await c.req.json().catch(() => null)
|
|
520
|
-
const ws = c.get('ws')
|
|
521
|
-
await updateWorkspaceState(ws, state => {
|
|
522
|
-
state.openTabs = normalizeOpenTabs(body?.openTabs)
|
|
523
|
-
})
|
|
524
|
-
return c.json(await getWorkspaceState(ws))
|
|
525
|
-
})
|
|
526
|
-
|
|
527
|
-
// The agent's chats. Tab ownership and settings come from `/state`.
|
|
528
|
-
one.get('/sessions', personalWorkspace, async c => {
|
|
529
|
-
const ws = c.get('ws')
|
|
530
|
-
return c.json(await harnessFor(ws).listSessions(ws))
|
|
531
|
-
})
|
|
532
|
-
|
|
533
|
-
one.put('/sessions/:sessionId/pin', personalWorkspace, async c => {
|
|
534
|
-
const ws = c.get('ws')
|
|
535
|
-
const sessionId = c.req.param('sessionId')
|
|
536
|
-
const harness = harnessFor(ws)
|
|
537
|
-
const found = (await harness.listSessions(ws)).some(session => session.sessionId === sessionId)
|
|
538
|
-
const active = harness
|
|
539
|
-
.activeSessions()
|
|
540
|
-
.some(session => session.workspaceId === ws.id && session.sessionId === sessionId)
|
|
541
|
-
if (!found && !active) return c.text('Chat not found', 404)
|
|
542
|
-
await pinSession(ws, sessionId)
|
|
543
|
-
return c.json(await getWorkspaceState(ws))
|
|
544
|
-
})
|
|
545
|
-
|
|
546
|
-
one.delete('/sessions/:sessionId/pin', personalWorkspace, async c => {
|
|
547
|
-
const ws = c.get('ws')
|
|
548
|
-
await unpinSession(ws, c.req.param('sessionId'))
|
|
549
|
-
return c.json(await getWorkspaceState(ws))
|
|
550
|
-
})
|
|
551
|
-
|
|
552
|
-
// Show the chat in a tab. `ifMatch` (a chat id, or null for none) applies the
|
|
553
|
-
// change only while the tab still shows that chat.
|
|
554
|
-
one.put('/sessions/:sessionId/selection', personalWorkspace, async c => {
|
|
555
|
-
const ws = c.get('ws')
|
|
556
|
-
const body: unknown = await c.req.json().catch(() => null)
|
|
557
|
-
if (!body || typeof body !== 'object') return c.text('Bad request', 400)
|
|
558
|
-
const input = body as { tabId?: unknown; ifMatch?: unknown }
|
|
559
|
-
if (!isWorkspaceTabId(input.tabId)) return c.text('Invalid chat tab', 400)
|
|
560
|
-
const hasIfMatch = Object.prototype.hasOwnProperty.call(input, 'ifMatch')
|
|
561
|
-
if (hasIfMatch && input.ifMatch !== null && typeof input.ifMatch !== 'string')
|
|
562
|
-
return c.text('ifMatch must be a chat id or null', 400)
|
|
563
|
-
if (await getPinnedSession(ws)) return c.text('Unpin chat before switching', 409)
|
|
564
|
-
await saveSelectedSession(
|
|
565
|
-
ws,
|
|
566
|
-
c.req.param('sessionId'),
|
|
567
|
-
input.tabId,
|
|
568
|
-
hasIfMatch ? (input.ifMatch as string | null) : undefined
|
|
569
|
-
)
|
|
570
|
-
return c.json(await getWorkspaceState(ws))
|
|
571
|
-
})
|
|
572
|
-
|
|
573
|
-
// Stop showing the chat in a tab, which then opens a new chat. A tab showing
|
|
574
|
-
// another chat is left alone.
|
|
575
|
-
one.delete('/sessions/:sessionId/selection', personalWorkspace, async c => {
|
|
576
|
-
const ws = c.get('ws')
|
|
577
|
-
const body: unknown = await c.req.json().catch(() => null)
|
|
578
|
-
const tabId = (body as { tabId?: unknown } | null)?.tabId
|
|
579
|
-
if (!isWorkspaceTabId(tabId)) return c.text('Invalid chat tab', 400)
|
|
580
|
-
await deselectSession(ws, c.req.param('sessionId'), tabId)
|
|
581
|
-
return c.json(await getWorkspaceState(ws))
|
|
582
|
-
})
|
|
583
|
-
|
|
584
|
-
// Change run settings. Omitted fields stay; null clears one.
|
|
585
|
-
one.on(
|
|
586
|
-
'PATCH',
|
|
587
|
-
['/sessions/:sessionId/config', '/state/chat-defaults'],
|
|
588
|
-
personalWorkspace,
|
|
589
|
-
async c => {
|
|
590
|
-
const body = await c.req.json().catch(() => null)
|
|
591
|
-
if (typeof body !== 'object' || body === null) {
|
|
592
|
-
return c.text('Expected a JSON object', 400)
|
|
593
|
-
}
|
|
594
|
-
const patch: SessionConfigPatch = {}
|
|
595
|
-
const record = body as Record<string, unknown>
|
|
596
|
-
for (const key of ['model', 'effort'] as const) {
|
|
597
|
-
if (!(key in record)) continue
|
|
598
|
-
const value = record[key]
|
|
599
|
-
if (value !== null && typeof value !== 'string') {
|
|
600
|
-
return c.text(`${key} must be a string or null`, 400)
|
|
601
|
-
}
|
|
602
|
-
patch[key] = value
|
|
603
|
-
}
|
|
604
|
-
if ('speedMode' in record) {
|
|
605
|
-
const value = record.speedMode
|
|
606
|
-
if (value !== null && !isSpeedMode(value)) {
|
|
607
|
-
return c.text('speedMode must be "normal", "fast", "ultrafast", or null', 400)
|
|
608
|
-
}
|
|
609
|
-
patch.speedMode = value
|
|
610
|
-
}
|
|
611
|
-
const ws = c.get('ws')
|
|
612
|
-
await saveSessionConfig(ws, c.req.param('sessionId'), patch)
|
|
613
|
-
return c.json(await getWorkspaceState(ws))
|
|
614
|
-
}
|
|
615
|
-
)
|
|
616
|
-
|
|
617
|
-
one.post('/sessions/:sessionId/archive', personalWorkspace, async c => {
|
|
618
|
-
const ws = c.get('ws')
|
|
619
|
-
const harness = harnessFor(ws)
|
|
620
|
-
const sessionId = c.req.param('sessionId')
|
|
621
|
-
if (!harness.archiveSession) return c.text('Chat archiving is not supported', 501)
|
|
622
|
-
|
|
623
|
-
try {
|
|
624
|
-
await archiveWorkspaceSession(ws, sessionId)
|
|
625
|
-
return c.json(await getWorkspaceState(ws))
|
|
626
|
-
} catch (error) {
|
|
627
|
-
console.error(`[api] archive chat failed for ${harness.id}`, error)
|
|
628
|
-
// Harnesses translate backend refusals into actionable one-liners (e.g.
|
|
629
|
-
// OpenClaw: main chat not archivable, gateway too old) — surface them.
|
|
630
|
-
const message =
|
|
631
|
-
error instanceof Error && error.message ? error.message : 'Couldn’t archive chat'
|
|
632
|
-
return c.text(message, 500)
|
|
633
|
-
}
|
|
634
|
-
})
|
|
635
|
-
|
|
636
|
-
one.get('/sessions/:sessionId/events', personalWorkspace, async c => {
|
|
637
|
-
const ws = c.get('ws')
|
|
638
|
-
const sessionId = c.req.param('sessionId')
|
|
639
|
-
return c.json(await harnessFor(ws).sessionEvents(ws, sessionId))
|
|
640
|
-
})
|
|
641
|
-
|
|
642
|
-
one.get('/mcp', personalWorkspace, async c => {
|
|
643
|
-
const ws = c.get('ws')
|
|
644
|
-
const harness = harnessFor(ws)
|
|
645
|
-
if (c.req.query('stream') !== 'true') return c.json((await harness.mcpStatus?.(ws)) ?? [])
|
|
646
|
-
let cancelled = false
|
|
647
|
-
const encoder = new TextEncoder()
|
|
648
|
-
return new Response(
|
|
649
|
-
new ReadableStream({
|
|
650
|
-
async start(controller) {
|
|
651
|
-
const emit = (frame: unknown) => {
|
|
652
|
-
if (!cancelled) controller.enqueue(encoder.encode(JSON.stringify(frame) + '\n'))
|
|
653
|
-
}
|
|
654
|
-
try {
|
|
655
|
-
const connectors =
|
|
656
|
-
(await harness.mcpStatus?.(ws, connectors => emit({ connectors }))) ?? []
|
|
657
|
-
emit({ connectors, done: true })
|
|
658
|
-
} catch {
|
|
659
|
-
emit({ error: 'Could not load connectors' })
|
|
660
|
-
} finally {
|
|
661
|
-
if (!cancelled) controller.close()
|
|
662
|
-
}
|
|
663
|
-
},
|
|
664
|
-
cancel() {
|
|
665
|
-
cancelled = true
|
|
666
|
-
}
|
|
667
|
-
}),
|
|
668
|
-
{ headers: { 'Content-Type': 'application/x-ndjson', 'Cache-Control': 'no-store' } }
|
|
669
|
-
)
|
|
670
|
-
})
|
|
671
|
-
|
|
672
|
-
// Harness debug tap for /dev/harness: the backend's native wire frames
|
|
673
|
-
// (Codex: app-server JSON-RPC, both directions; Claude Code: raw SDK messages
|
|
674
|
-
// + enqueued inputs) and the exact frames the server pushed to chat clients.
|
|
675
|
-
// `sinceWire`/`sinceBroadcast` are seq cursors so the page can poll deltas.
|
|
676
|
-
one.get('/harness/debug', personalWorkspace, async c => {
|
|
677
|
-
const ws = c.get('ws')
|
|
678
|
-
const harness = harnessFor(ws)
|
|
679
|
-
const sinceWire = Number(c.req.query('sinceWire') ?? 0) || 0
|
|
680
|
-
const sinceBroadcast = Number(c.req.query('sinceBroadcast') ?? 0) || 0
|
|
681
|
-
return c.json({
|
|
682
|
-
harness: harness.id,
|
|
683
|
-
process: (await harness.debugInfo?.(ws)) ?? null,
|
|
684
|
-
wire: getWireLog(harness.wireScope?.(ws) ?? ws.id, sinceWire),
|
|
685
|
-
broadcasts: getClientFrameLog(ws.id, sinceBroadcast)
|
|
686
|
-
})
|
|
687
|
-
})
|
|
688
|
-
|
|
689
|
-
// Per-workspace env vars. GET returns the effective view (discovered `.env` + UI
|
|
690
|
-
// custom secrets + scopes + declared-required keys; values masked).
|
|
691
|
-
one.get('/env', personalWorkspace, async c => {
|
|
692
|
-
const ws = c.get('ws')
|
|
693
|
-
// Unawaited on purpose: getWorkspaceEnvView loads it in parallel with the
|
|
694
|
-
// env stores (manifest reads and env reads are independent).
|
|
695
|
-
return c.json(await getWorkspaceEnvView(ws.path, requiredEnvFor(ws.path)))
|
|
696
|
-
})
|
|
697
|
-
|
|
698
|
-
// PUT patches custom secrets (set/remove) and/or the inheritDotenv mode,
|
|
699
|
-
// then reaps the workspace's function worker and idle agent sessions so the next
|
|
700
|
-
// call/message picks up the change (env is frozen at spawn — a hard restart is
|
|
701
|
-
// the only way).
|
|
702
|
-
one.put('/env', personalWorkspace, async c => {
|
|
703
|
-
const ws = c.get('ws')
|
|
704
|
-
const patch = parseEnvUpdate(await c.req.json().catch(() => null))
|
|
705
|
-
if (typeof patch === 'string') return c.text(patch, 400)
|
|
706
|
-
|
|
707
|
-
// Skip the write + reaps for a no-op PUT (no recognized fields) so an empty
|
|
708
|
-
// body doesn't needlessly kill warm workers / idle sessions.
|
|
709
|
-
const hasChange =
|
|
710
|
-
patch.set !== undefined || patch.remove !== undefined || patch.inheritDotenv !== undefined
|
|
711
|
-
if (hasChange) {
|
|
712
|
-
await updateWorkspaceEnv(ws.path, patch)
|
|
713
|
-
// Frozen-at-spawn: reap workers/idle sessions and tell other clients.
|
|
714
|
-
applyEnvChanged(ws)
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
return c.json(await getWorkspaceEnvView(ws.path, requiredEnvFor(ws.path)))
|
|
718
|
-
})
|
|
719
|
-
|
|
720
|
-
one.get('/skills', personalWorkspace, async c => {
|
|
721
|
-
const ws = c.get('ws')
|
|
722
|
-
return c.json(await getWorkspaceSkillsStatus(ws.path, ws.harness))
|
|
723
|
-
})
|
|
724
|
-
|
|
725
|
-
one.post('/skills/update', personalWorkspace, async c => {
|
|
726
|
-
const ws = c.get('ws')
|
|
727
|
-
const result = await updateWorkspaceSkills(ws.path, ws.harness ?? 'claude-code')
|
|
728
|
-
return c.json(result.status)
|
|
729
|
-
})
|
|
730
|
-
|
|
731
|
-
// Workspace configuration and models. Shared account status is served by
|
|
732
|
-
// /harnesses/status; only workspace overrides and gateways are probed here.
|
|
733
|
-
one.get('/harness', personalWorkspace, async c => {
|
|
734
|
-
const ws = c.get('ws')
|
|
735
|
-
const harness = harnessFor(ws)
|
|
736
|
-
const capabilities = {
|
|
737
|
-
harness: harness.id,
|
|
738
|
-
supportsStreaming: harness.capabilities.supportsStreaming,
|
|
739
|
-
supportsArchiving: Boolean(harness.archiveSession)
|
|
740
|
-
}
|
|
741
|
-
if (!existsSync(ws.path)) {
|
|
742
|
-
return c.json({
|
|
743
|
-
...capabilities,
|
|
744
|
-
isFolderMissing: true,
|
|
745
|
-
availability: { status: 'unavailable', reason: 'Workspace folder not found' },
|
|
746
|
-
models: []
|
|
747
|
-
} satisfies WorkspaceHarness)
|
|
748
|
-
}
|
|
749
|
-
const authEnv =
|
|
750
|
-
harness.id === 'codex'
|
|
751
|
-
? /^(OPENAI_|CODEX_)/
|
|
752
|
-
: /^(ANTHROPIC_|CLAUDE_|AWS_|GOOGLE_|AZURE_|CLOUD_ML_)/
|
|
753
|
-
const hasAuthOverrides =
|
|
754
|
-
harness.authStatus &&
|
|
755
|
-
Object.entries(await resolveWorkspaceEnv(ws.path)).some(
|
|
756
|
-
([key, value]) =>
|
|
757
|
-
value !== process.env[key] &&
|
|
758
|
-
(authEnv.test(key) || /^(HOME|USERPROFILE|XDG_CONFIG_HOME)$/.test(key))
|
|
759
|
-
)
|
|
760
|
-
const refresh = c.req.query('refresh') === 'true'
|
|
761
|
-
if (refresh) await loginShellPath({ refresh: true })
|
|
762
|
-
// A backend that can't answer (codex CLI missing, gateway down) degrades to
|
|
763
|
-
// an empty catalog — the picker hides and chat surfaces the real problem via
|
|
764
|
-
// workspace setup, instead of this endpoint failing on page load.
|
|
765
|
-
const [availability, models] = await Promise.all([
|
|
766
|
-
// Shared account status comes from /harnesses/status.
|
|
767
|
-
// Gateway-backed harnesses still have workspace-specific readiness.
|
|
768
|
-
harness.authStatus && !hasAuthOverrides
|
|
769
|
-
? Promise.resolve({ status: 'available' as const })
|
|
770
|
-
: refresh
|
|
771
|
-
? harnessStore.refresh(ws)
|
|
772
|
-
: harnessStore.getAvailability(ws),
|
|
773
|
-
harness.listModels(ws).catch(err => {
|
|
774
|
-
console.error(`[api] listModels failed for ${harness.id}`, err)
|
|
775
|
-
return []
|
|
776
|
-
})
|
|
777
|
-
])
|
|
778
|
-
return c.json({
|
|
779
|
-
...capabilities,
|
|
780
|
-
availability,
|
|
781
|
-
hasAuthOverrides: Boolean(hasAuthOverrides),
|
|
782
|
-
models
|
|
783
|
-
} satisfies WorkspaceHarness)
|
|
784
|
-
})
|
|
785
|
-
|
|
786
|
-
// Workspace identity. Uploads use the image route below.
|
|
787
|
-
one.get('/config', ownerWorkspace, async c => {
|
|
788
|
-
return c.json(await getWorkspaceConfig(c.get('ws').path))
|
|
789
|
-
})
|
|
790
|
-
|
|
791
|
-
one.put('/config', ownerWorkspace, async c => {
|
|
792
|
-
const ws = c.get('ws')
|
|
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') {
|
|
801
|
-
return c.text('Expected { name: string | null }', 400)
|
|
802
|
-
}
|
|
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 })
|
|
810
|
-
publishEvent({ type: 'workspace:updated', workspaceId: ws.id, origin: eventOrigin(body.origin) })
|
|
811
|
-
return c.json(await getWorkspaceConfig(ws.path))
|
|
812
|
-
})
|
|
813
|
-
|
|
814
|
-
// Scratchpad canvas. GET returns the persisted tldraw document snapshot
|
|
815
|
-
// ({ document } or { document: null } when empty) for hydration; PUT saves a new
|
|
816
|
-
// snapshot ({ document, origin }) and broadcasts so other open tabs reload.
|
|
817
|
-
// `origin` is the writing tab's id — echoed in the broadcast so that tab can
|
|
818
|
-
// ignore its own save. This is the browser's write path; the agent's draws are
|
|
819
|
-
// written server-side (see server/scratchpad/executor.ts). See docs/moi-scratchpad.md.
|
|
820
|
-
one.post('/scratchpad/ops', ownerWorkspace, async c => {
|
|
821
|
-
try {
|
|
822
|
-
const form = await c.req.formData()
|
|
823
|
-
const op = JSON.parse(String(form.get('op'))) as ScratchOp | null
|
|
824
|
-
if (!op || typeof op.kind !== 'string') return c.text('Invalid scratchpad edit', 400)
|
|
825
|
-
let imageBytes: Uint8Array | undefined
|
|
826
|
-
if (op.kind === 'add-image') {
|
|
827
|
-
const image = form.get('image')
|
|
828
|
-
if (!(image instanceof File)) return c.text('Image file is required', 400)
|
|
829
|
-
imageBytes = new Uint8Array(await image.arrayBuffer())
|
|
830
|
-
}
|
|
831
|
-
const ws = c.get('ws')
|
|
832
|
-
return c.json(await executeScratchOp(ws.path, ws.id, op, imageBytes))
|
|
833
|
-
} catch (error) {
|
|
834
|
-
return c.text(error instanceof Error ? error.message : 'Scratchpad edit failed', 400)
|
|
835
|
-
}
|
|
836
|
-
})
|
|
837
|
-
|
|
838
|
-
one.get('/scratchpad', ownerWorkspace, async c => {
|
|
839
|
-
return c.json(await loadScratchpadDoc(c.get('ws').path))
|
|
840
|
-
})
|
|
841
|
-
|
|
842
|
-
one.put('/scratchpad', ownerWorkspace, async c => {
|
|
843
|
-
const ws = c.get('ws')
|
|
844
|
-
const body = await c.req.json().catch(() => null)
|
|
845
|
-
if (!body || typeof body !== 'object' || !body.document) {
|
|
846
|
-
return c.text('Expected { document }', 400)
|
|
847
|
-
}
|
|
848
|
-
await saveScratchpadDoc(body.document, ws.path)
|
|
849
|
-
publishEvent({
|
|
850
|
-
type: 'scratchpad:updated',
|
|
851
|
-
workspaceId: ws.id,
|
|
852
|
-
origin: eventOrigin(body.origin)
|
|
853
|
-
})
|
|
854
|
-
return c.body(null, 204)
|
|
855
|
-
})
|
|
856
|
-
|
|
857
|
-
// Scratchpad assets: pasted/dropped image bytes live as content-addressed files
|
|
858
|
-
// in `.moi/.scratchpad/`, referenced from the snapshot by `asset:` srcs —
|
|
859
|
-
// never inlined as base64 in the JSON (see server/scratchpad/assets.ts). The
|
|
860
|
-
// browser's TLAssetStore POSTs the raw file here on paste and resolves `asset:`
|
|
861
|
-
// srcs back through the GET when rendering.
|
|
862
|
-
one.post('/scratchpad/assets', ownerWorkspace, async c => {
|
|
863
|
-
const length = Number(c.req.header('content-length') ?? 0)
|
|
864
|
-
if (length > MAX_ASSET_BYTES) {
|
|
865
|
-
return c.text(`Asset too large (max ${MAX_ASSET_BYTES / (1024 * 1024)} MB)`, 413)
|
|
866
|
-
}
|
|
867
|
-
const bytes = new Uint8Array(await c.req.arrayBuffer())
|
|
868
|
-
if (bytes.length === 0) return c.text('Empty body', 400)
|
|
869
|
-
if (bytes.length > MAX_ASSET_BYTES) {
|
|
870
|
-
return c.text(`Asset too large (max ${MAX_ASSET_BYTES / (1024 * 1024)} MB)`, 413)
|
|
871
|
-
}
|
|
872
|
-
const mimeType = c.req.header('content-type') ?? 'application/octet-stream'
|
|
873
|
-
return c.json(await storeScratchpadAsset(c.get('ws').path, bytes, mimeType))
|
|
874
|
-
})
|
|
875
|
-
|
|
876
|
-
// The file name is content-addressed (sha256 of the bytes), so a hit is
|
|
877
|
-
// immutable — let the browser cache it indefinitely.
|
|
878
|
-
one.get('/scratchpad/assets/:file', ownerWorkspace, async c => {
|
|
879
|
-
const resolved = scratchpadAssetFile(c.get('ws').path, c.req.param('file'))
|
|
880
|
-
if (!resolved || !(await resolved.file.exists())) return c.text('Not found', 404)
|
|
881
|
-
return new Response(resolved.file, {
|
|
882
|
-
headers: {
|
|
883
|
-
'Content-Type': resolved.mimeType,
|
|
884
|
-
'Cache-Control': 'public, max-age=31536000, immutable',
|
|
885
|
-
// Assets are only ever consumed via <img>/<video>/fetch (which all ignore
|
|
886
|
-
// this), so force a download on direct navigation and block MIME sniffing:
|
|
887
|
-
// a pasted/uploaded SVG must not execute as script in the app origin.
|
|
888
|
-
'Content-Disposition': 'attachment',
|
|
889
|
-
'X-Content-Type-Options': 'nosniff'
|
|
890
|
-
}
|
|
891
|
-
})
|
|
892
|
-
})
|
|
893
|
-
|
|
894
|
-
// Workspace upload. PUT resizes an image to a 128×128 WebP. DELETE resets any
|
|
895
|
-
// custom icon to the provider default. Both broadcast for a live refresh.
|
|
896
|
-
one.put('/icon', ownerWorkspace, async c => {
|
|
897
|
-
const ws = c.get('ws')
|
|
898
|
-
const bytes = new Uint8Array(await c.req.arrayBuffer())
|
|
899
|
-
if (bytes.length === 0) return c.text('Empty image body', 400)
|
|
900
|
-
let icon: string
|
|
901
|
-
try {
|
|
902
|
-
icon = await processIcon(bytes)
|
|
903
|
-
} catch (err) {
|
|
904
|
-
const msg = err instanceof Error ? err.message : String(err)
|
|
905
|
-
return c.text(`Invalid image: ${msg}`, 400)
|
|
906
|
-
}
|
|
907
|
-
const workspaceIcon = { type: 'upload', value: icon } as const
|
|
908
|
-
await setWorkspaceConfig(ws.path, { icon: workspaceIcon })
|
|
909
|
-
publishEvent({ type: 'workspace:updated', workspaceId: c.get('ws').id })
|
|
910
|
-
return c.json({ icon: workspaceIcon })
|
|
911
|
-
})
|
|
912
|
-
|
|
913
|
-
one.delete('/icon', ownerWorkspace, async c => {
|
|
914
|
-
await setWorkspaceConfig(c.get('ws').path, { icon: null })
|
|
915
|
-
publishEvent({ type: 'workspace:updated', workspaceId: c.get('ws').id })
|
|
916
|
-
return c.body(null, 204)
|
|
917
|
-
})
|
|
918
|
-
|
|
919
|
-
// All info about a single workspace: its persisted layout (widget grid, layout
|
|
920
|
-
// mode, theme) plus server-resolved metadata. GET reads, PUT writes the layout,
|
|
921
|
-
// DELETE unregisters.
|
|
922
|
-
one.get('/', personalWorkspace, async c => {
|
|
923
|
-
const ws = c.get('ws')
|
|
924
|
-
const config = await loadWorkspaceFileConfig(ws.path)
|
|
925
|
-
if (config.remote) {
|
|
926
|
-
return c.json({
|
|
927
|
-
version: 2,
|
|
928
|
-
remote: config.remote,
|
|
929
|
-
apiBase: workspaceApiBase(config.remote.workspace_id, config.remote.user_id),
|
|
930
|
-
isRemote: true,
|
|
931
|
-
cwd: ws.path,
|
|
932
|
-
// The agent belongs to this visitor, not to the owner's workspace.
|
|
933
|
-
harness: ws.harness,
|
|
934
|
-
agentId: ws.agentId
|
|
935
|
-
} satisfies WorkspaceInfoResponse)
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
const layout = config
|
|
939
|
-
return c.json({
|
|
940
|
-
...layout,
|
|
941
|
-
apiBase: workspaceApiBase(ws.id),
|
|
942
|
-
isRemote: false,
|
|
943
|
-
// Resolved display name: the settings override, or the folder name.
|
|
944
|
-
name: layout.name || basename(ws.path),
|
|
945
|
-
cwd: ws.path,
|
|
946
|
-
harness: ws.harness,
|
|
947
|
-
agentId: ws.agentId
|
|
948
|
-
} satisfies WorkspaceInfoResponse)
|
|
949
|
-
})
|
|
950
|
-
|
|
951
|
-
// Thumbnail freshness records, without image bytes — the capture hook compares
|
|
952
|
-
// these against live bundle revisions. Images are served per-applet below.
|
|
953
|
-
one.get('/applet-thumbnails', ownerWorkspace, async c =>
|
|
954
|
-
c.json({ thumbnails: await getAppletThumbnailRecords(c.get('ws').path) })
|
|
955
|
-
)
|
|
956
|
-
|
|
957
|
-
one.get('/applet-thumbnails/:kind/:name', ownerWorkspace, c => {
|
|
958
|
-
const kind = c.req.param('kind')
|
|
959
|
-
if (kind !== 'widget' && kind !== 'view') return c.text('Not found', 404)
|
|
960
|
-
// `<id>` or `<id>:<version>`. Applet ids never contain `:`, and the version
|
|
961
|
-
// lives in the path rather than a query string so every CDN keys on it.
|
|
962
|
-
const [id, version] = c.req.param('name').split(':')
|
|
963
|
-
return serveAppletThumbnail(
|
|
964
|
-
c.get('ws').path,
|
|
965
|
-
kind,
|
|
966
|
-
id!,
|
|
967
|
-
c.req.header('if-none-match'),
|
|
968
|
-
version !== undefined
|
|
969
|
-
)
|
|
970
|
-
})
|
|
971
|
-
|
|
972
|
-
// Settled widget and view visits share one batch endpoint and storage path.
|
|
973
|
-
one.put('/applet-thumbnails', ownerWorkspace, async c => {
|
|
974
|
-
const body: unknown = await c.req.json().catch(() => null)
|
|
975
|
-
if (!body || typeof body !== 'object' || Array.isArray(body)) return c.text('Bad request', 400)
|
|
976
|
-
const input = body as AppletThumbnailBatch
|
|
977
|
-
const valid =
|
|
978
|
-
(input.kind === 'widget' || input.kind === 'view') &&
|
|
979
|
-
Array.isArray(input.thumbnails) &&
|
|
980
|
-
input.thumbnails.every(
|
|
981
|
-
thumbnail =>
|
|
982
|
-
thumbnail &&
|
|
983
|
-
typeof thumbnail === 'object' &&
|
|
984
|
-
!Array.isArray(thumbnail) &&
|
|
985
|
-
typeof thumbnail.id === 'string' &&
|
|
986
|
-
isValidAppletId(thumbnail.id) &&
|
|
987
|
-
typeof thumbnail.revision === 'string' &&
|
|
988
|
-
(thumbnail.image === undefined ||
|
|
989
|
-
thumbnail.image === null ||
|
|
990
|
-
typeof thumbnail.image === 'string') &&
|
|
991
|
-
(thumbnail.captureMs === undefined || typeof thumbnail.captureMs === 'number')
|
|
992
|
-
)
|
|
993
|
-
if (!valid) return c.text('Bad request', 400)
|
|
994
|
-
await saveAppletThumbnails(c.get('ws').path, input.kind, input.thumbnails)
|
|
995
|
-
return c.body(null, 204)
|
|
996
|
-
})
|
|
997
|
-
|
|
998
|
-
one.put('/', personalWorkspace, async c => {
|
|
999
|
-
const ws = c.get('ws')
|
|
1000
|
-
if (ws.remote) {
|
|
1001
|
-
return c.text(
|
|
1002
|
-
'Remote references contain only the owner address; save shared content to the owner',
|
|
1003
|
-
403
|
|
1004
|
-
)
|
|
1005
|
-
}
|
|
1006
|
-
const body = await c.req.json()
|
|
1007
|
-
if (!body || body.version !== 2) return c.text('Bad request', 400)
|
|
1008
|
-
// `origin` is the writing tab's id, echoed so that tab skips its own event.
|
|
1009
|
-
const { origin } = body
|
|
1010
|
-
// Only widgets and theme are taken from the body, so a grid/theme save can't
|
|
1011
|
-
// erase a `moi config`-set name or icon. See mergeLayoutForSave.
|
|
1012
|
-
const existing = await loadLayout(ws.path)
|
|
1013
|
-
const next = mergeLayoutForSave(existing, body)
|
|
1014
|
-
await saveLayout(next, ws.path)
|
|
1015
|
-
if (
|
|
1016
|
-
JSON.stringify(resolveWorkspaceTheme(existing.theme)) !==
|
|
1017
|
-
JSON.stringify(resolveWorkspaceTheme(next.theme))
|
|
1018
|
-
) {
|
|
1019
|
-
publishEvent({ type: 'theme:updated', workspaceId: ws.id, origin: eventOrigin(origin) })
|
|
1020
|
-
}
|
|
1021
|
-
return c.body(null, 204)
|
|
1022
|
-
})
|
|
1023
|
-
|
|
1024
|
-
one.delete('/', personalWorkspace, async c => {
|
|
1025
|
-
const ws = c.get('ws')
|
|
1026
|
-
if (ws.remote) return c.text('Leaving remote workspaces is not available yet', 403)
|
|
1027
|
-
const ok = await removeWorkspace(ws.id)
|
|
1028
|
-
if (!ok) return c.text('Workspace not found', 404)
|
|
1029
|
-
harnessFor(ws).stopWorkspace?.(ws.path)
|
|
1030
|
-
await collabManager.stopWorkspace(ws.path)
|
|
1031
|
-
return c.body(null, 204)
|
|
1032
|
-
})
|
|
1033
|
-
|
|
1034
|
-
// ---- workspace collection: /api/workspaces ----------------------------------
|
|
1035
|
-
const workspaces = new Hono<ApiEnv>()
|
|
1036
|
-
|
|
1037
|
-
// Standalone Moi lists local workspaces only; remote references need Cloud.
|
|
1038
|
-
function visibleWorkspaces(entries: WorkspaceEntry[]) {
|
|
1039
|
-
return getAppConfig().environment === 'cloud' ? entries : entries.filter(entry => !entry.remote)
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
async function mergeWorkspaceList(entries: WorkspaceEntry[]) {
|
|
1043
|
-
return Promise.all(
|
|
1044
|
-
entries.map(async e => {
|
|
1045
|
-
const layout = await loadWorkspaceFileConfig(e.path).catch(() => null)
|
|
1046
|
-
if (!layout) return e
|
|
1047
|
-
if (layout.remote) {
|
|
1048
|
-
return { ...e, remote: layout.remote, name: layout.remote.workspace_id }
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
return {
|
|
1052
|
-
...e,
|
|
1053
|
-
name: layout.name ?? e.name,
|
|
1054
|
-
icon: layout.icon,
|
|
1055
|
-
theme: layout.theme
|
|
1056
|
-
}
|
|
1057
|
-
})
|
|
1058
|
-
)
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
workspaces.get('/', async c => {
|
|
1062
|
-
// Merge each workspace's live identity and theme over the registry snapshot
|
|
1063
|
-
// so app-wide workspace lists render the same presentation as the workspace.
|
|
1064
|
-
const entries = await listWorkspaces()
|
|
1065
|
-
return c.json(await mergeWorkspaceList(visibleWorkspaces(entries)))
|
|
1066
|
-
})
|
|
1067
|
-
|
|
1068
|
-
workspaces.put('/order', async c => {
|
|
1069
|
-
const body = await c.req.json()
|
|
1070
|
-
if (!Array.isArray(body?.ids) || body.ids.some((id: unknown) => typeof id !== 'string')) {
|
|
1071
|
-
return c.text('Expected { ids: string[] }', 400)
|
|
1072
|
-
}
|
|
1073
|
-
try {
|
|
1074
|
-
// Hidden remote references keep their place after the visible ones.
|
|
1075
|
-
const all = await listWorkspaces()
|
|
1076
|
-
const visible = new Set(visibleWorkspaces(all).map(entry => entry.id))
|
|
1077
|
-
const hiddenIds = all.filter(entry => !visible.has(entry.id)).map(entry => entry.id)
|
|
1078
|
-
const entries = await reorderWorkspaces([...body.ids, ...hiddenIds])
|
|
1079
|
-
// List-only change: a narrow event so clients refetch just the sidebar
|
|
1080
|
-
// list, not every per-workspace query (`workspace:updated` also triggers
|
|
1081
|
-
// layout refetches in open workspaces).
|
|
1082
|
-
publishEvent({ type: 'workspaces-list:updated', origin: eventOrigin(body.origin) })
|
|
1083
|
-
return c.json(await mergeWorkspaceList(visibleWorkspaces(entries)))
|
|
1084
|
-
} catch (err) {
|
|
1085
|
-
const message = err instanceof Error ? err.message : String(err)
|
|
1086
|
-
return c.text(message, 400)
|
|
1087
|
-
}
|
|
1088
|
-
})
|
|
1089
|
-
|
|
1090
|
-
// One message for both creation routes: in the cloud demo the instance is
|
|
1091
|
-
// provisioned with its workspaces; the UI never sends these requests (it opens
|
|
1092
|
-
// the cloud demo promo dialog instead), so a 403 here means the API was called
|
|
1093
|
-
// directly.
|
|
1094
|
-
const DEMO_CREATE_BLOCKED = 'Workspace creation is not available in the Moi demo'
|
|
1095
|
-
|
|
1096
|
-
workspaces.post('/', async c => {
|
|
1097
|
-
if (getAppConfig().demo) return c.text(DEMO_CREATE_BLOCKED, 403)
|
|
1098
|
-
const body = await c.req.json().catch(() => null)
|
|
1099
|
-
if (body && typeof body === 'object' && 'remote' in body) {
|
|
1100
|
-
if (getAppConfig().environment !== 'cloud')
|
|
1101
|
-
return c.text('Shared workspaces require Cloud mode', 403)
|
|
1102
|
-
if (Object.keys(body).some(key => key !== 'remote' && key !== 'harness'))
|
|
1103
|
-
return c.text('Remote registration expects only remote and harness', 400)
|
|
1104
|
-
let remote
|
|
1105
|
-
try {
|
|
1106
|
-
remote = parseRemoteWorkspaceTarget(body.remote)
|
|
1107
|
-
} catch (error) {
|
|
1108
|
-
return c.text(error instanceof Error ? error.message : 'Invalid remote workspace', 400)
|
|
1109
|
-
}
|
|
1110
|
-
// The visitor's own agent. Omitted, the reference falls back to the same
|
|
1111
|
-
// default as any other workspace without a stored harness.
|
|
1112
|
-
const requested: unknown = body.harness
|
|
1113
|
-
if (requested !== undefined) {
|
|
1114
|
-
if (requested !== 'claude-code' && requested !== 'codex')
|
|
1115
|
-
return c.text('Unknown workspace type', 400)
|
|
1116
|
-
const availability = await harnessTypeAvailability(requested)
|
|
1117
|
-
if (availability.status !== 'available') return c.text(availability.reason, 400)
|
|
1118
|
-
}
|
|
1119
|
-
try {
|
|
1120
|
-
return c.json(await openSharedWorkspace(remote, requested), 201)
|
|
1121
|
-
} catch (error) {
|
|
1122
|
-
return c.text(error instanceof Error ? error.message : 'Could not open shared workspace', 503)
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
if (!body?.path) return c.text('Missing path', 400)
|
|
1126
|
-
const requestedHarness: unknown = body?.harness ?? 'claude-code'
|
|
1127
|
-
if (!isHarnessType(requestedHarness)) return c.text('Unknown workspace type', 400)
|
|
1128
|
-
const harness: HarnessType = requestedHarness
|
|
1129
|
-
const availability = await harnessTypeAvailability(harness)
|
|
1130
|
-
if (availability.status !== 'available') return c.text(availability.reason, 400)
|
|
1131
|
-
const path = resolve(String(body.path))
|
|
1132
|
-
let metadata: WorkspaceImportMetadata
|
|
1133
|
-
try {
|
|
1134
|
-
metadata = await resolveWorkspaceImportMetadata(path, harness)
|
|
1135
|
-
} catch (err) {
|
|
1136
|
-
const message = err instanceof Error ? err.message : String(err)
|
|
1137
|
-
return c.text(message, 400)
|
|
1138
|
-
}
|
|
1139
|
-
// Importing IS initializing: lay down the bundled skills (in the backend's
|
|
1140
|
-
// skills dir) and the `.moi/` scaffold, exactly like `moi init` — a workspace
|
|
1141
|
-
// added from the UI must be indistinguishable from one added via the CLI.
|
|
1142
|
-
try {
|
|
1143
|
-
await provisionWorkspace(path, harness)
|
|
1144
|
-
} catch (err) {
|
|
1145
|
-
const message = err instanceof Error ? err.message : String(err)
|
|
1146
|
-
return c.text(`Could not initialize workspace: ${message}`, 500)
|
|
1147
|
-
}
|
|
1148
|
-
const entry = await registerWorkspace(path, {
|
|
1149
|
-
harness,
|
|
1150
|
-
...metadata
|
|
1151
|
-
})
|
|
1152
|
-
return c.json((await mergeWorkspaceList([entry]))[0], 201)
|
|
1153
|
-
})
|
|
1154
|
-
|
|
1155
|
-
workspaces.get('/discover', async c => c.json(await discoverWorkspaces()))
|
|
1156
|
-
|
|
1157
|
-
// Home-card previews for every workspace in one request, keyed by id, so the
|
|
1158
|
-
// home page fetches them beside the list instead of one per card after it.
|
|
1159
|
-
workspaces.get('/previews', async c => {
|
|
1160
|
-
const entries = await listWorkspaces()
|
|
1161
|
-
const previews = await Promise.all(
|
|
1162
|
-
entries.map(async ws => {
|
|
1163
|
-
// A remote reference has no local content to preview.
|
|
1164
|
-
if (ws.remote) return [ws.id, { thumbnails: [] }] as const
|
|
1165
|
-
const views = await listCompiledViews(ws.path).catch(() => [])
|
|
1166
|
-
const preview = await getWorkspacePreview(ws.path, {
|
|
1167
|
-
getHarnessPreview: includeFirstUserMessage =>
|
|
1168
|
-
harnessFor(ws).workspacePreview(ws, includeFirstUserMessage),
|
|
1169
|
-
viewIds: views.map(view => view.id),
|
|
1170
|
-
// Capture time in base36 keeps the versioned segment short and URL-safe.
|
|
1171
|
-
thumbnailUrl: (kind, id, capturedAt) =>
|
|
1172
|
-
`/api/workspaces/${ws.id}/applet-thumbnails/${kind}/${id}:${Date.parse(capturedAt).toString(36)}`
|
|
1173
|
-
})
|
|
1174
|
-
return [ws.id, preview] as const
|
|
1175
|
-
})
|
|
1176
|
-
)
|
|
1177
|
-
return c.json(Object.fromEntries(previews))
|
|
1178
|
-
})
|
|
1179
|
-
|
|
1180
|
-
// Backends the create dialog can provision from scratch. OpenClaw workspaces
|
|
1181
|
-
// belong to their agents and arrive via discovery.
|
|
1182
|
-
const CREATABLE_HARNESSES = new Set<HarnessType>(['claude-code', 'codex'])
|
|
1183
|
-
|
|
1184
|
-
async function harnessTypeAvailability(harness: HarnessType): Promise<HarnessAvailability> {
|
|
1185
|
-
return (await harnessFor(harness).availability?.()) ?? { status: 'available' }
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
// Create a brand-new workspace: a fresh folder under createdWorkspacesRoot(),
|
|
1189
|
-
// provisioned (skills + `.moi/` scaffold) and registered.
|
|
1190
|
-
workspaces.post('/create', async c => {
|
|
1191
|
-
if (getAppConfig().demo) return c.text(DEMO_CREATE_BLOCKED, 403)
|
|
1192
|
-
const body = await c.req.json()
|
|
1193
|
-
const requestedHarness: unknown = body?.harness ?? 'claude-code'
|
|
1194
|
-
if (!isHarnessType(requestedHarness)) {
|
|
1195
|
-
return c.text('Unknown workspace type', 400)
|
|
1196
|
-
}
|
|
1197
|
-
const harness: HarnessType = requestedHarness
|
|
1198
|
-
if (!CREATABLE_HARNESSES.has(harness)) {
|
|
1199
|
-
return c.text('Workspaces of this type arrive through discovery, not creation', 400)
|
|
1200
|
-
}
|
|
1201
|
-
const availability = await harnessTypeAvailability(harness)
|
|
1202
|
-
if (availability.status !== 'available') return c.text(availability.reason, 400)
|
|
1203
|
-
const name =
|
|
1204
|
-
body?.name === undefined
|
|
1205
|
-
? 'My workspace'
|
|
1206
|
-
: typeof body.name === 'string'
|
|
1207
|
-
? body.name.trim()
|
|
1208
|
-
: ''
|
|
1209
|
-
const invalid = validateWorkspaceName(name)
|
|
1210
|
-
if (invalid) return c.text(invalid, 400)
|
|
1211
|
-
const path = await createWorkspaceDirectory(name, createdWorkspacesRoot())
|
|
1212
|
-
try {
|
|
1213
|
-
await provisionWorkspace(path, harness)
|
|
1214
|
-
} catch (err) {
|
|
1215
|
-
const message = err instanceof Error ? err.message : String(err)
|
|
1216
|
-
return c.text(`Could not create workspace: ${message}`, 500)
|
|
1217
|
-
}
|
|
1218
|
-
await setWorkspaceConfig(path, { name })
|
|
1219
|
-
const entry = await registerWorkspace(path, { id: basename(path), harness, name })
|
|
1220
|
-
// Nudge every connected client (the sidebar list) to refetch.
|
|
1221
|
-
publishEvent({ type: 'workspaces-list:updated' })
|
|
1222
|
-
return c.json(entry, 201)
|
|
1223
|
-
})
|
|
1224
|
-
|
|
1225
|
-
// `/:id` is registered after the static `/discover` so the literal path wins.
|
|
1226
|
-
// `/api/workspaces/ws` (the live-event WebSocket) is intercepted by Bun's routes
|
|
1227
|
-
// table before it ever reaches Hono, so it never collides with `:id`.
|
|
1228
|
-
workspaces.route('/:id', one)
|
|
1229
|
-
|
|
1230
|
-
// ---- top-level API ----------------------------------------------------------
|
|
1231
|
-
export const api = new Hono()
|
|
1232
|
-
|
|
1233
|
-
api.route('/api/workspaces', workspaces)
|
|
1234
|
-
api.route('/api/harnesses', harnesses)
|
|
1235
|
-
api.route('/api/onboarding', onboarding)
|
|
1236
|
-
|
|
1237
|
-
// Startup config (config.json in the data dir + MOI_* env), client-safe
|
|
1238
|
-
// subset. Immutable for the process lifetime — clients cache it forever.
|
|
1239
|
-
api.get('/api/config', c => c.json(clientAppConfig()))
|
|
1240
|
-
|
|
1241
|
-
// The viewer's profile as verified by a configured proxy (Cloudflare Access).
|
|
1242
|
-
// It differs per request, so neither browsers nor Cloudflare's edge may cache it.
|
|
1243
|
-
api.get('/api/proxy-user', async c => {
|
|
1244
|
-
c.header('Cache-Control', 'private, no-store')
|
|
1245
|
-
return c.json(await proxyUserState(c.req.raw))
|
|
1246
|
-
})
|
|
1247
|
-
|
|
1248
|
-
// Served from a lazily-refreshed cache: this handler is a memory read, and the
|
|
1249
|
-
// registry is consulted on the schedule `getCachedUpdateStatus` owns rather
|
|
1250
|
-
// than once per request. `no-store` keeps the browser from adding a second,
|
|
1251
|
-
// unrelated cache on top of it.
|
|
1252
|
-
api.get('/api/update', async c => {
|
|
1253
|
-
c.header('Cache-Control', 'no-store')
|
|
1254
|
-
return c.json(await getCachedUpdateStatus())
|
|
1255
|
-
})
|
|
1256
|
-
|
|
1257
|
-
api.post('/api/update', async c => {
|
|
1258
|
-
if (updateInProgress()) {
|
|
1259
|
-
return c.text(
|
|
1260
|
-
restartPendingForUpdate()
|
|
1261
|
-
? 'An update is installed — Moi is restarting.'
|
|
1262
|
-
: 'An update is already in progress.',
|
|
1263
|
-
409
|
|
1264
|
-
)
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
const agentRunning = hasRunningAgentSessions(
|
|
1268
|
-
allHarnesses().flatMap(harness => harness.activeSessions())
|
|
1269
|
-
)
|
|
1270
|
-
if (agentRunning) {
|
|
1271
|
-
return c.text(UPDATE_ACTIVE_AGENT_MESSAGE, 409)
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
try {
|
|
1275
|
-
const result = await installUpdate()
|
|
1276
|
-
if (!result) return c.text('This Moi cannot be updated from the app', 409)
|
|
1277
|
-
const response = c.json(result)
|
|
1278
|
-
scheduleRestartForUpdate()
|
|
1279
|
-
return response
|
|
1280
|
-
} catch (error) {
|
|
1281
|
-
return c.text(error instanceof Error ? error.message : 'Could not update moi.', 500)
|
|
1282
|
-
}
|
|
1283
|
-
})
|
|
1284
|
-
|
|
1285
|
-
// App-wide settings (settings.json in the data dir). GET returns every key
|
|
1286
|
-
// with defaults applied; PATCH merges a partial body and returns the result.
|
|
1287
|
-
api.get('/api/settings', c => c.json(getAppSettings()))
|
|
1288
|
-
|
|
1289
|
-
api.patch('/api/settings', async c => {
|
|
1290
|
-
let body: unknown
|
|
1291
|
-
try {
|
|
1292
|
-
body = await c.req.json()
|
|
1293
|
-
} catch {
|
|
1294
|
-
return c.text('Invalid JSON body', 400)
|
|
1295
|
-
}
|
|
1296
|
-
if (!body || typeof body !== 'object' || Array.isArray(body)) {
|
|
1297
|
-
return c.text('Settings patch must be an object', 400)
|
|
1298
|
-
}
|
|
1299
|
-
// app-settings whitelists the updatable fields; the conf schema validates
|
|
1300
|
-
// the values on save, rejecting the whole patch before anything persists.
|
|
1301
|
-
let settings: AppSettings
|
|
1302
|
-
try {
|
|
1303
|
-
settings = saveAppSettings(pickAppSettingsPatch(body as Record<string, unknown>))
|
|
1304
|
-
} catch (error) {
|
|
1305
|
-
return c.text(error instanceof Error ? error.message : 'Invalid settings patch', 400)
|
|
1306
|
-
}
|
|
1307
|
-
// Other open clients hold these in a query cache with no polling; broadcast
|
|
1308
|
-
// the new value so an app-wide preference applies everywhere immediately.
|
|
1309
|
-
publishEvent({ type: 'settings:updated', settings })
|
|
1310
|
-
return c.json(settings)
|
|
1311
|
-
})
|
|
1312
|
-
|
|
1313
|
-
// Everything else: in production, serve the prebuilt client from `dist/` via
|
|
1314
|
-
// Hono's static handler (mime types, traversal-safe, optional precompression).
|
|
1315
|
-
// Hashed assets (`/chunk-….js`, `/favicon-….png`, …) are pinned immutable; the
|
|
1316
|
-
// unhashed `index.html` is not. Never mounted in dev — the live bundler serves
|
|
1317
|
-
// assets via the HTML route before Bun's `fetch` ever delegates here.
|
|
1318
|
-
if (prebuilt) {
|
|
1319
|
-
api.get(
|
|
1320
|
-
'*',
|
|
1321
|
-
serveStatic({
|
|
1322
|
-
root: DIST_DIR,
|
|
1323
|
-
onFound: (path, c) => {
|
|
1324
|
-
c.header(
|
|
1325
|
-
'Cache-Control',
|
|
1326
|
-
path.endsWith('index.html') ? 'no-cache' : 'public, max-age=31536000, immutable'
|
|
1327
|
-
)
|
|
1328
|
-
}
|
|
1329
|
-
})
|
|
1330
|
-
)
|
|
1331
|
-
}
|
|
1332
|
-
api.notFound(c => c.text('Not found', 404))
|