moi-computer 0.13.1-next.0 → 0.13.1-next.2
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/client/api/app-config.ts +12 -2
- package/client/api/http.ts +11 -1
- package/client/app/app-router.tsx +3 -2
- package/client/app/routes/home-route.tsx +1 -1
- package/client/app/routes/workspace-registration.tsx +68 -0
- package/client/app/routes/workspace-route.tsx +37 -13
- package/client/app/shell/sidebar-layout.tsx +10 -5
- package/client/components/shared/workspace-icon.tsx +8 -17
- package/client/features/account/account-test-utils.tsx +18 -4
- package/client/features/account/api.ts +10 -8
- package/client/features/account/profile-actions.ts +5 -7
- package/client/features/app-settings/avatar-upload.tsx +62 -0
- package/client/features/app-settings/profile-settings.tsx +10 -0
- package/client/features/app-settings/settings-page.tsx +2 -1
- package/client/features/applets/api.ts +6 -6
- package/client/features/applets/applet-cache.ts +6 -5
- package/client/features/applets/applet-log.ts +2 -1
- package/client/features/applets/applet-runtime.ts +2 -1
- package/client/features/applets/use-applet.ts +73 -18
- package/client/features/applets/widget-shell.tsx +4 -2
- package/client/features/chat/applet-chat-intents.ts +5 -13
- package/client/features/chat/chat-popup.tsx +8 -4
- package/client/features/chat/chat-send.ts +2 -2
- package/client/features/chat/composer/model-order.ts +4 -4
- package/client/features/chat/composer/model-picker.tsx +12 -10
- package/client/features/chat/composer/use-workspace-composer-state.tsx +1 -1
- package/client/features/chat/sessions/api.ts +11 -28
- package/client/features/chat/sessions/use-selected-session.ts +18 -100
- package/client/features/chat/use-chat.ts +8 -12
- package/client/features/collab/applet-api.ts +1 -1
- package/client/features/collab/components/cursors.tsx +6 -1
- package/client/features/collab/components/presence-avatars.tsx +1 -1
- package/client/features/collab/components/presence-frame.tsx +1 -1
- package/client/features/collab/components/presence-group.tsx +1 -1
- package/client/features/collab/components/presence-helpers.ts +2 -2
- package/client/features/collab/components/user-avatar-group.tsx +1 -1
- package/client/features/collab/components/user-avatar.tsx +1 -1
- package/client/features/collab/components/user.tsx +1 -1
- package/client/features/collab/index.ts +3 -3
- package/client/features/collab/members/api.ts +17 -0
- package/client/features/collab/members/hooks.ts +97 -0
- package/client/features/collab/members/store.ts +148 -0
- package/client/features/{workspace-members → collab/members}/types.ts +7 -5
- package/client/features/collab/{client.ts → presence/client.ts} +4 -5
- package/client/features/collab/{hooks.tsx → presence/hooks.tsx} +1 -1
- package/client/features/collab/{provider.tsx → presence/provider.tsx} +1 -12
- package/client/features/collab/{users.ts → presence/users.ts} +19 -21
- package/client/features/collab/proxy-user.ts +1 -3
- package/client/features/collab/sharing/agent-invite.tsx +30 -0
- package/client/features/collab/sharing/workspace-members.tsx +269 -0
- package/client/features/collab/sharing/workspace-sharing-menu.tsx +179 -0
- package/client/features/collab/testing/component-fixtures.tsx +3 -3
- package/client/features/collab/testing/fake-engine.ts +2 -2
- package/client/features/dev/chat-states-page.tsx +3 -1
- package/client/features/dev/collab/collab-playground.tsx +2 -2
- package/client/features/dev/dev-index-page.tsx +0 -6
- package/client/features/dev/dev-routes.tsx +0 -2
- package/client/features/dev/harness-debug-page.tsx +7 -7
- package/client/features/dev/workspace-setup-mocks.ts +1 -2
- package/client/features/dev/workspace-setup-preview.tsx +6 -4
- package/client/features/harness/api.ts +13 -10
- package/client/features/harness/harness-login-panel.tsx +9 -5
- package/client/features/harness/harness-presentation.ts +4 -4
- package/client/features/harness/harness-selector.tsx +13 -13
- package/client/features/harness/use-harness-login.ts +5 -5
- package/client/features/home/api.ts +38 -2
- package/client/features/home/home-page.tsx +43 -13
- package/client/features/home/shared-workspaces.tsx +70 -0
- package/client/features/home/workspace-invitations.tsx +101 -0
- package/client/features/identity/host-api.ts +5 -4
- package/client/features/identity/store.ts +1 -7
- package/client/features/onboarding/agent-setup-step.tsx +8 -8
- package/client/features/onboarding/onboarding-page.tsx +3 -2
- package/client/features/onboarding/workspace-setup-step.tsx +1 -1
- package/client/features/overview/api.ts +3 -5
- package/client/features/overview/default/registry.tsx +1 -1
- package/client/features/overview/default/views-widget.tsx +2 -2
- package/client/features/overview/hidden-panel.tsx +7 -5
- package/client/features/overview/overview.tsx +18 -16
- package/client/features/overview/workspace-name.tsx +2 -2
- package/client/features/scratchpad/scratchpad.tsx +9 -7
- package/client/features/scratchpad/use-scratchpad-snapshot.tsx +13 -5
- package/client/features/views/api.ts +34 -16
- package/client/features/views/use-view-actions.ts +10 -20
- package/client/features/views/view-manager.tsx +1 -1
- package/client/features/views/view-submission.ts +2 -21
- package/client/features/workspace/add/api.ts +5 -4
- package/client/features/workspace/add/create-workspace-dialog.tsx +12 -9
- package/client/features/workspace/add/import-workspace-dialog.tsx +7 -7
- package/client/features/workspace/add/use-workspace-import.ts +10 -10
- package/client/features/workspace/add/workspace-agent-options.ts +21 -20
- package/client/features/workspace/add/workspace-agent-selector.tsx +11 -11
- package/client/features/workspace/api.ts +60 -13
- package/client/features/workspace/harness-transition.ts +7 -13
- package/client/features/workspace/remote.ts +25 -0
- package/client/features/workspace/settings/api.ts +7 -12
- package/client/features/workspace/settings/connectors-settings.tsx +3 -3
- package/client/features/workspace/settings/general-settings.tsx +8 -8
- package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
- package/client/features/workspace/setup/workspace-recovery-states.tsx +43 -14
- package/client/features/workspace/setup/workspace-setup.tsx +6 -6
- package/client/features/workspace/tab-resolution.ts +2 -2
- package/client/features/workspace/use-workspace-navigation.ts +7 -4
- package/client/features/workspace/workspace-content.tsx +32 -26
- package/client/features/workspace/workspace-frame.tsx +13 -26
- package/client/features/workspace/workspace-layout-context.tsx +45 -12
- package/client/features/workspace/workspace-menu.tsx +2 -2
- package/client/features/workspace/workspace-pane.tsx +22 -0
- package/client/features/workspace/workspace-pending-screen.tsx +1 -1
- package/client/features/workspace/workspace-preferences.ts +34 -0
- package/client/features/workspace/workspace-presentation.tsx +12 -16
- package/client/features/workspace/workspace-screen.tsx +2 -2
- package/client/features/workspace/workspace-state.ts +2 -1
- package/client/features/workspace/workspace-tabs.tsx +1 -1
- package/client/features/workspace/workspace-test-utils.ts +23 -0
- package/client/runtime/use-workspace-events.ts +14 -0
- package/client/runtime/workspace-events.ts +9 -9
- package/client/store/ui.ts +29 -9
- package/dist/chunk-44khk4sp.js +2 -0
- package/dist/chunk-ba6mz56s.js +72 -0
- package/dist/chunk-ec5ennpv.js +1 -0
- package/dist/chunk-ectsnw81.js +2 -0
- package/dist/chunk-en7w5ypg.js +1 -0
- package/dist/chunk-f695wcx5.js +5 -0
- package/dist/chunk-kffcah9w.css +1 -0
- package/dist/{chunk-kdgk4dac.js → chunk-n0fawy9x.js} +1 -1
- package/dist/chunk-pdt9hxfw.js +2 -0
- package/dist/chunk-rmd0ctfx.js +546 -0
- package/dist/chunk-zv22wv0g.js +1 -0
- package/dist/index.html +1 -1
- package/lib/harness-instructions.ts +4 -4
- package/lib/harness-types.ts +13 -0
- package/lib/types.ts +34 -50
- package/lib/workspace-config.ts +48 -0
- package/lib/workspace-layout.ts +2 -4
- package/package.json +4 -2
- package/server/README.md +29 -27
- package/server/api/harnesses.ts +5 -5
- package/server/api/index.ts +170 -68
- package/server/app-config.ts +2 -7
- package/server/applets/declarations.ts +6 -7
- package/server/applets/index.ts +15 -9
- package/server/applets/views.ts +2 -17
- package/server/applets/widgets.ts +3 -2
- package/server/cli/commands/config.ts +8 -20
- package/server/cli/commands/hermes.ts +2 -2
- package/server/cli/commands/init.ts +96 -64
- package/server/cli/commands/openclaw.ts +2 -2
- package/server/cli/commands/refresh.ts +10 -1
- package/server/cli/commands/remote.ts +228 -0
- package/server/cli/commands/skill.ts +4 -4
- package/server/cli/commands/tabs.ts +5 -12
- package/server/cli/control.ts +35 -4
- package/server/cli/index.ts +10 -6
- package/server/cli/remote-command.ts +77 -0
- package/server/cli/remote-control.ts +70 -0
- package/server/cli/remote-operations.ts +244 -0
- package/server/collab/config.ts +4 -8
- package/server/collab/manager.ts +5 -2
- package/server/collab/skill/index.ts +4 -50
- package/server/control.ts +38 -11
- package/server/harness/acp/session.ts +4 -4
- package/server/harness/auth.ts +26 -31
- package/server/harness/claude-code/index.ts +1 -1
- package/server/harness/codex/discovery.ts +1 -1
- package/server/harness/codex/session.ts +1 -1
- package/server/harness/detect.ts +14 -19
- package/server/harness/executable.ts +10 -10
- package/server/harness/hermes/NOTES.md +2 -2
- package/server/harness/hermes/index.ts +1 -1
- package/server/harness/install.ts +11 -11
- package/server/harness/openclaw/index.ts +1 -1
- package/server/harness/registry.ts +7 -6
- package/server/harness/types.ts +4 -4
- package/server/onboarding/jobs.ts +1 -1
- package/server/operations/commands.ts +46 -0
- package/server/operations/files.ts +148 -0
- package/server/operations/server.ts +206 -0
- package/server/remote/agent.ts +103 -0
- package/server/remote/client.ts +665 -0
- package/server/remote/workspace.ts +34 -0
- package/server/scratchpad/document.ts +32 -12
- package/server/scratchpad/executor.ts +16 -7
- package/server/sessions/config.ts +8 -5
- package/server/sessions/pending-views.ts +16 -0
- package/server/sessions/view-sessions.ts +10 -12
- package/server/skills/locations.ts +4 -4
- package/server/skills/template.ts +3 -2
- package/server/skills/update.ts +12 -12
- package/server/skills/version.ts +7 -7
- package/server/skills/workspace.ts +13 -13
- package/server/web.ts +12 -10
- package/server/workspace-state/file.ts +2 -0
- package/server/workspace-state/index.ts +0 -4
- package/server/workspaces/api.ts +28 -0
- package/server/workspaces/change-harness.ts +15 -26
- package/server/workspaces/import.ts +4 -4
- package/server/workspaces/init.ts +15 -13
- package/server/workspaces/layout.ts +60 -66
- package/server/workspaces/registry.ts +43 -18
- package/server/workspaces/scaffold.ts +1 -0
- package/server/workspaces/shared.ts +74 -0
- package/server/workspaces/tabs.ts +6 -12
- package/skill/SKILL.md +24 -4
- package/client/api/app-ui-keys.ts +0 -6
- package/client/features/chat/sessions/browser-tab-state.ts +0 -43
- package/client/features/collab/workspace-users-menu.tsx +0 -190
- package/client/features/dev/cloud-avatar-upload.tsx +0 -58
- package/client/features/dev/cloud-page.tsx +0 -363
- package/client/features/workspace/browser-tab-state.ts +0 -51
- package/client/features/workspace/layout-save.ts +0 -13
- package/client/features/workspace-members/api.ts +0 -20
- package/client/features/workspace-members/hooks.ts +0 -127
- package/client/features/workspace-members/keys.ts +0 -6
- package/client/features/workspace-members/store.ts +0 -123
- package/dist/chunk-00s35r33.js +0 -546
- package/dist/chunk-7rz6g7g7.js +0 -1
- package/dist/chunk-af2jyddf.js +0 -2
- package/dist/chunk-cekekc3f.css +0 -1
- package/dist/chunk-ep5vh16c.js +0 -75
- package/dist/chunk-s5s1vzdw.js +0 -2
- package/dist/chunk-svxhxfeq.js +0 -2
- package/dist/chunk-t0r0bds1.js +0 -1
- package/dist/chunk-vp2qzc0d.js +0 -1
- package/dist/chunk-wz5qv1bn.js +0 -2
- package/lib/workspace-types.ts +0 -13
- package/server/workspace-state/legacy-migration.ts +0 -79
- /package/client/features/collab/{presence-publisher.ts → presence/presence-publisher.ts} +0 -0
- /package/client/features/collab/{presence-target.ts → presence/presence-target.ts} +0 -0
- /package/client/features/collab/{store.ts → presence/store.ts} +0 -0
package/server/api/index.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
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'
|
|
1
6
|
import { resolveWorkspaceEnv } from '../workspaces/env'
|
|
2
7
|
import { changeWorkspaceHarness } from '../workspaces/change-harness'
|
|
3
8
|
import { HarnessTransitionError, reserveWorkspaceOperation } from '../workspaces/harness-transition'
|
|
@@ -19,11 +24,10 @@ import type {
|
|
|
19
24
|
AppletThumbnailBatch,
|
|
20
25
|
AppSettings,
|
|
21
26
|
HarnessAvailability,
|
|
22
|
-
SelectedSessionScope,
|
|
23
27
|
UploadInfo,
|
|
24
28
|
WorkspaceHarness,
|
|
25
29
|
WorkspaceEntry,
|
|
26
|
-
|
|
30
|
+
HarnessType
|
|
27
31
|
} from '@/lib/types'
|
|
28
32
|
import { isWorkspaceTabId } from '@/lib/workspace-tabs'
|
|
29
33
|
|
|
@@ -34,7 +38,7 @@ import { harnesses } from './harnesses'
|
|
|
34
38
|
import { clientAppConfig, createdWorkspacesRoot, getAppConfig } from '../app-config'
|
|
35
39
|
import { getAppSettings, pickAppSettingsPatch, saveAppSettings } from '../app-settings'
|
|
36
40
|
import { appletForModule, recordAppletError } from '../applets/log'
|
|
37
|
-
import {
|
|
41
|
+
import { parseAppletTail, serveWorkspaceFile } from '../applets'
|
|
38
42
|
import { applyEnvChanged } from '../workspaces/env-apply'
|
|
39
43
|
import { publishEvent } from '../events'
|
|
40
44
|
import { callFunction, parseFunctionPath } from '../applets/functions'
|
|
@@ -83,6 +87,7 @@ import { requiredEnvFor } from '../workspaces/required-env'
|
|
|
83
87
|
import {
|
|
84
88
|
deleteView,
|
|
85
89
|
listCompiledViews,
|
|
90
|
+
getWorkspaceViews,
|
|
86
91
|
listViews,
|
|
87
92
|
serveView,
|
|
88
93
|
updateViewTitle,
|
|
@@ -160,6 +165,14 @@ async function handleFunctionCall(
|
|
|
160
165
|
}
|
|
161
166
|
}
|
|
162
167
|
|
|
168
|
+
// Routes that describe the person using a workspace, not the workspace itself:
|
|
169
|
+
// their chats, their agent and what that agent runs with. A visitor's Moi answers
|
|
170
|
+
// them from its own folder; an owner never serves them to visitors.
|
|
171
|
+
const PERSONAL_ROUTE_RE = /^\/(?:sessions|state|harness|skills|env|mcp|uploads|preview)(?:\/|$)/
|
|
172
|
+
// A view being built belongs to the chat building it, so its lifecycle is
|
|
173
|
+
// personal too. Compiled views stay with the owner.
|
|
174
|
+
const PENDING_VIEW_ROUTE_RE = /^\/views(?:\/[^/]+(?:\/submit)?)?$/
|
|
175
|
+
|
|
163
176
|
// Resolve `:id` to a registered workspace once, 404 if unknown, and stash it on
|
|
164
177
|
// the context. Mounted on the single-workspace sub-app so every nested route
|
|
165
178
|
// shares the lookup instead of repeating `getWorkspace(...) ?? 404`.
|
|
@@ -172,6 +185,19 @@ const withWorkspace = createMiddleware<ApiEnv>(async (c, next) => {
|
|
|
172
185
|
release = reserveWorkspaceOperation(id)
|
|
173
186
|
const ws = await getWorkspace(id)
|
|
174
187
|
if (!ws) return c.text('Workspace not found', 404)
|
|
188
|
+
const suffix = (c.req.path.split(`/workspaces/${encodeURIComponent(id)}`)[1] ?? '').replace(
|
|
189
|
+
/\/$/,
|
|
190
|
+
''
|
|
191
|
+
)
|
|
192
|
+
const personal =
|
|
193
|
+
PERSONAL_ROUTE_RE.test(suffix) ||
|
|
194
|
+
(c.req.method !== 'GET' && PENDING_VIEW_ROUTE_RE.test(suffix))
|
|
195
|
+
if (ws.remote && suffix === '' && c.req.method === 'DELETE')
|
|
196
|
+
return c.text('Leaving remote workspaces is not available yet', 403)
|
|
197
|
+
if (ws.remote && getAppConfig().environment !== 'cloud')
|
|
198
|
+
return c.text('Remote workspaces require Cloud mode', 403)
|
|
199
|
+
if (ws.remote && suffix !== '' && !personal)
|
|
200
|
+
return c.text('Use the owner workspace address', 404)
|
|
175
201
|
c.set('ws', ws)
|
|
176
202
|
await next()
|
|
177
203
|
} catch (error) {
|
|
@@ -188,10 +214,10 @@ one.use('*', withWorkspace)
|
|
|
188
214
|
one.patch('/harness', async c => {
|
|
189
215
|
if (getAppConfig().demo) return c.text('Changing agents is unavailable in the demo', 403)
|
|
190
216
|
const body = await c.req.json().catch(() => null)
|
|
191
|
-
if (!body || !['claude-code', 'codex'].includes(body.
|
|
217
|
+
if (!body || !['claude-code', 'codex'].includes(body.harness))
|
|
192
218
|
return c.text('Invalid agent selection', 400)
|
|
193
219
|
try {
|
|
194
|
-
return c.json(await changeWorkspaceHarness(c.get('ws'), body.
|
|
220
|
+
return c.json(await changeWorkspaceHarness(c.get('ws'), body.harness))
|
|
195
221
|
} catch (error) {
|
|
196
222
|
if (error instanceof HarnessTransitionError) return c.text(error.message, 409)
|
|
197
223
|
throw error
|
|
@@ -208,12 +234,18 @@ one.get('/widgets/*', c => {
|
|
|
208
234
|
const ws = c.get('ws')
|
|
209
235
|
const { name, file } = parseAppletTail(c.req.url, ws.id, 'widgets')
|
|
210
236
|
if (!name) return c.text('Not found', 404)
|
|
211
|
-
return serveWidget(name, file, ws.path,
|
|
237
|
+
return serveWidget(name, file, ws.path, workspaceApiBase(ws.id), c.req.header('if-none-match'))
|
|
212
238
|
})
|
|
213
239
|
|
|
214
240
|
// Views — full-screen agent apps. Mirrors the widget pair above: the exact path
|
|
215
241
|
// lists (in manifest/nav order), `/*` serves one bundle file.
|
|
216
|
-
one.get('/views', c =>
|
|
242
|
+
one.get('/views', async c =>
|
|
243
|
+
c.req.query('includePending') === 'true'
|
|
244
|
+
? c.json({ views: await getWorkspaceViews(c.get('ws')) })
|
|
245
|
+
: listViews(c.get('ws').path)
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
const OWNER_VIEW = 'Use the owner workspace address for compiled views'
|
|
217
249
|
|
|
218
250
|
one.patch('/views/:viewId', async c => {
|
|
219
251
|
const ws = c.get('ws')
|
|
@@ -238,6 +270,7 @@ one.patch('/views/:viewId', async c => {
|
|
|
238
270
|
throw error
|
|
239
271
|
}
|
|
240
272
|
}
|
|
273
|
+
if (ws.remote) return c.text(OWNER_VIEW, 404)
|
|
241
274
|
const title = typeof body?.title === 'string' ? body.title.trim() : ''
|
|
242
275
|
if (!title) return c.text('Expected { title: string }', 400)
|
|
243
276
|
|
|
@@ -262,7 +295,8 @@ one.delete('/views/:viewId', async c => {
|
|
|
262
295
|
.map(session => session.sessionId)
|
|
263
296
|
)
|
|
264
297
|
await discardPendingView(ws, viewId, active)
|
|
265
|
-
} else
|
|
298
|
+
} else if (ws.remote) return c.text(OWNER_VIEW, 404)
|
|
299
|
+
else await deleteView(publishEvent, ws, viewId)
|
|
266
300
|
return c.body(null, 204)
|
|
267
301
|
} catch (error) {
|
|
268
302
|
if (error instanceof ViewMutationError || error instanceof PendingViewError)
|
|
@@ -275,7 +309,7 @@ one.get('/views/*', c => {
|
|
|
275
309
|
const ws = c.get('ws')
|
|
276
310
|
const { name, file } = parseAppletTail(c.req.url, ws.id, 'views')
|
|
277
311
|
if (!name) return c.text('Not found', 404)
|
|
278
|
-
return serveView(name, file, ws.path,
|
|
312
|
+
return serveView(name, file, ws.path, workspaceApiBase(ws.id), c.req.header('if-none-match'))
|
|
279
313
|
})
|
|
280
314
|
|
|
281
315
|
one.post('/views', async c => {
|
|
@@ -289,7 +323,6 @@ one.post('/views/:viewId/submit', async c => {
|
|
|
289
323
|
requirements?: string
|
|
290
324
|
sessionId?: string
|
|
291
325
|
optimisticId?: string
|
|
292
|
-
selectedSessionScope?: SelectedSessionScope
|
|
293
326
|
model?: string
|
|
294
327
|
effort?: string
|
|
295
328
|
speedMode?: SpeedMode
|
|
@@ -302,13 +335,6 @@ one.post('/views/:viewId/submit', async c => {
|
|
|
302
335
|
if (body.optimisticId !== undefined && typeof body.optimisticId !== 'string') {
|
|
303
336
|
return c.text('Invalid optimisticId', 400)
|
|
304
337
|
}
|
|
305
|
-
if (
|
|
306
|
-
body.selectedSessionScope !== undefined &&
|
|
307
|
-
body.selectedSessionScope !== 'shared' &&
|
|
308
|
-
body.selectedSessionScope !== 'browser-tab'
|
|
309
|
-
) {
|
|
310
|
-
return c.text('Invalid selectedSessionScope', 400)
|
|
311
|
-
}
|
|
312
338
|
const attachments = body.attachments ?? []
|
|
313
339
|
if (!isMessageAttachments(attachments)) return c.text('Invalid attachments', 400)
|
|
314
340
|
for (const attachment of attachments) {
|
|
@@ -317,13 +343,12 @@ one.post('/views/:viewId/submit', async c => {
|
|
|
317
343
|
if (!getUpload(ws.id, attachment.uploadId))
|
|
318
344
|
return c.text('Attachment not found or expired', 400)
|
|
319
345
|
}
|
|
320
|
-
const availability = await
|
|
346
|
+
const availability = await harnessTypeAvailability(ws.harness ?? 'claude-code')
|
|
321
347
|
if (availability.status !== 'available') return c.text(availability.reason, 400)
|
|
322
348
|
try {
|
|
323
349
|
const result = await submitView(ws, c.req.param('viewId'), {
|
|
324
350
|
requirements: body.requirements,
|
|
325
351
|
sessionId: typeof body.sessionId === 'string' ? body.sessionId : undefined,
|
|
326
|
-
selectedSessionScope: body.selectedSessionScope,
|
|
327
352
|
attachments,
|
|
328
353
|
optimisticId: body.optimisticId,
|
|
329
354
|
model: typeof body.model === 'string' ? body.model : undefined,
|
|
@@ -347,7 +372,7 @@ one.post('/views/:viewId/submit', async c => {
|
|
|
347
372
|
// localhost binding is NOT the guard.
|
|
348
373
|
one.get('/files/*', c => {
|
|
349
374
|
const ws = c.get('ws')
|
|
350
|
-
const tail = new URL(c.req.url).pathname.split(
|
|
375
|
+
const tail = new URL(c.req.url).pathname.split(`${workspaceApiBase(ws.id)}/files/`)[1] ?? ''
|
|
351
376
|
return serveWorkspaceFile(ws.path, tail, c.req.header('range'), c.req.header('if-none-match'))
|
|
352
377
|
})
|
|
353
378
|
|
|
@@ -356,7 +381,7 @@ one.get('/files/*', c => {
|
|
|
356
381
|
// `…/rpc/<module>/<fn>`.
|
|
357
382
|
one.post('/rpc/*', c => {
|
|
358
383
|
const ws = c.get('ws')
|
|
359
|
-
const tail = new URL(c.req.url).pathname.split(
|
|
384
|
+
const tail = new URL(c.req.url).pathname.split(`${workspaceApiBase(ws.id)}/rpc/`)[1] ?? ''
|
|
360
385
|
return handleFunctionCall(c.req.raw, tail, ws.path)
|
|
361
386
|
})
|
|
362
387
|
|
|
@@ -412,7 +437,7 @@ one.post('/applet-log', async c => {
|
|
|
412
437
|
// images only, resized server-side (see server/workspaces/preview.ts).
|
|
413
438
|
one.get('/preview/*', c => {
|
|
414
439
|
const ws = c.get('ws')
|
|
415
|
-
const tail = new URL(c.req.url).pathname.split(
|
|
440
|
+
const tail = new URL(c.req.url).pathname.split(`${workspaceApiBase(ws.id)}/preview/`)[1] ?? ''
|
|
416
441
|
return serveWorkspaceImagePreview(ws.path, tail, c.req.header('if-none-match'))
|
|
417
442
|
})
|
|
418
443
|
|
|
@@ -559,7 +584,7 @@ one.delete('/sessions/:sessionId/selection', async c => {
|
|
|
559
584
|
})
|
|
560
585
|
|
|
561
586
|
// Change run settings. Omitted fields stay; null clears one.
|
|
562
|
-
one.
|
|
587
|
+
one.on('PATCH', ['/sessions/:sessionId/config', '/state/chat-defaults'], async c => {
|
|
563
588
|
const body = await c.req.json().catch(() => null)
|
|
564
589
|
if (typeof body !== 'object' || body === null) {
|
|
565
590
|
return c.text('Expected a JSON object', 400)
|
|
@@ -651,7 +676,7 @@ one.get('/harness/debug', async c => {
|
|
|
651
676
|
const sinceWire = Number(c.req.query('sinceWire') ?? 0) || 0
|
|
652
677
|
const sinceBroadcast = Number(c.req.query('sinceBroadcast') ?? 0) || 0
|
|
653
678
|
return c.json({
|
|
654
|
-
|
|
679
|
+
harness: harness.id,
|
|
655
680
|
process: (await harness.debugInfo?.(ws)) ?? null,
|
|
656
681
|
wire: getWireLog(harness.wireScope?.(ws) ?? ws.id, sinceWire),
|
|
657
682
|
broadcasts: getClientFrameLog(ws.id, sinceBroadcast)
|
|
@@ -691,12 +716,12 @@ one.put('/env', async c => {
|
|
|
691
716
|
|
|
692
717
|
one.get('/skills', async c => {
|
|
693
718
|
const ws = c.get('ws')
|
|
694
|
-
return c.json(await getWorkspaceSkillsStatus(ws.path, ws.
|
|
719
|
+
return c.json(await getWorkspaceSkillsStatus(ws.path, ws.harness))
|
|
695
720
|
})
|
|
696
721
|
|
|
697
722
|
one.post('/skills/update', async c => {
|
|
698
723
|
const ws = c.get('ws')
|
|
699
|
-
const result = await updateWorkspaceSkills(ws.path, ws.
|
|
724
|
+
const result = await updateWorkspaceSkills(ws.path, ws.harness ?? 'claude-code')
|
|
700
725
|
return c.json(result.status)
|
|
701
726
|
})
|
|
702
727
|
|
|
@@ -706,7 +731,7 @@ one.get('/harness', async c => {
|
|
|
706
731
|
const ws = c.get('ws')
|
|
707
732
|
const harness = harnessFor(ws)
|
|
708
733
|
const capabilities = {
|
|
709
|
-
|
|
734
|
+
harness: harness.id,
|
|
710
735
|
supportsStreaming: harness.capabilities.supportsStreaming,
|
|
711
736
|
supportsArchiving: Boolean(harness.archiveSession)
|
|
712
737
|
}
|
|
@@ -779,7 +804,7 @@ one.put('/config', async c => {
|
|
|
779
804
|
return c.text('Expected a workspace config field', 400)
|
|
780
805
|
}
|
|
781
806
|
await setWorkspaceConfig(ws.path, { name, icon })
|
|
782
|
-
publishEvent({ type: 'workspace:updated', origin: eventOrigin(body.origin) })
|
|
807
|
+
publishEvent({ type: 'workspace:updated', workspaceId: ws.id, origin: eventOrigin(body.origin) })
|
|
783
808
|
return c.json(await getWorkspaceConfig(ws.path))
|
|
784
809
|
})
|
|
785
810
|
|
|
@@ -789,6 +814,24 @@ one.put('/config', async c => {
|
|
|
789
814
|
// `origin` is the writing tab's id — echoed in the broadcast so that tab can
|
|
790
815
|
// ignore its own save. This is the browser's write path; the agent's draws are
|
|
791
816
|
// written server-side (see server/scratchpad/executor.ts). See docs/moi-scratchpad.md.
|
|
817
|
+
one.post('/scratchpad/ops', async c => {
|
|
818
|
+
try {
|
|
819
|
+
const form = await c.req.formData()
|
|
820
|
+
const op = JSON.parse(String(form.get('op'))) as ScratchOp | null
|
|
821
|
+
if (!op || typeof op.kind !== 'string') return c.text('Invalid scratchpad edit', 400)
|
|
822
|
+
let imageBytes: Uint8Array | undefined
|
|
823
|
+
if (op.kind === 'add-image') {
|
|
824
|
+
const image = form.get('image')
|
|
825
|
+
if (!(image instanceof File)) return c.text('Image file is required', 400)
|
|
826
|
+
imageBytes = new Uint8Array(await image.arrayBuffer())
|
|
827
|
+
}
|
|
828
|
+
const ws = c.get('ws')
|
|
829
|
+
return c.json(await executeScratchOp(ws.path, ws.id, op, imageBytes))
|
|
830
|
+
} catch (error) {
|
|
831
|
+
return c.text(error instanceof Error ? error.message : 'Scratchpad edit failed', 400)
|
|
832
|
+
}
|
|
833
|
+
})
|
|
834
|
+
|
|
792
835
|
one.get('/scratchpad', async c => {
|
|
793
836
|
return c.json(await loadScratchpadDoc(c.get('ws').path))
|
|
794
837
|
})
|
|
@@ -860,13 +903,13 @@ one.put('/icon', async c => {
|
|
|
860
903
|
}
|
|
861
904
|
const workspaceIcon = { type: 'upload', value: icon } as const
|
|
862
905
|
await setWorkspaceConfig(ws.path, { icon: workspaceIcon })
|
|
863
|
-
publishEvent({ type: 'workspace:updated' })
|
|
906
|
+
publishEvent({ type: 'workspace:updated', workspaceId: c.get('ws').id })
|
|
864
907
|
return c.json({ icon: workspaceIcon })
|
|
865
908
|
})
|
|
866
909
|
|
|
867
910
|
one.delete('/icon', async c => {
|
|
868
911
|
await setWorkspaceConfig(c.get('ws').path, { icon: null })
|
|
869
|
-
publishEvent({ type: 'workspace:updated' })
|
|
912
|
+
publishEvent({ type: 'workspace:updated', workspaceId: c.get('ws').id })
|
|
870
913
|
return c.body(null, 204)
|
|
871
914
|
})
|
|
872
915
|
|
|
@@ -875,15 +918,31 @@ one.delete('/icon', async c => {
|
|
|
875
918
|
// DELETE unregisters.
|
|
876
919
|
one.get('/', async c => {
|
|
877
920
|
const ws = c.get('ws')
|
|
878
|
-
const
|
|
921
|
+
const config = await loadWorkspaceFileConfig(ws.path)
|
|
922
|
+
if (config.remote) {
|
|
923
|
+
return c.json({
|
|
924
|
+
version: 2,
|
|
925
|
+
remote: config.remote,
|
|
926
|
+
apiBase: workspaceApiBase(config.remote.workspace_id, config.remote.user_id),
|
|
927
|
+
isRemote: true,
|
|
928
|
+
cwd: ws.path,
|
|
929
|
+
// The agent belongs to this visitor, not to the owner's workspace.
|
|
930
|
+
harness: ws.harness,
|
|
931
|
+
agentId: ws.agentId
|
|
932
|
+
} satisfies WorkspaceInfoResponse)
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
const layout = config
|
|
879
936
|
return c.json({
|
|
880
937
|
...layout,
|
|
938
|
+
apiBase: workspaceApiBase(ws.id),
|
|
939
|
+
isRemote: false,
|
|
881
940
|
// Resolved display name: the settings override, or the folder name.
|
|
882
941
|
name: layout.name || basename(ws.path),
|
|
883
942
|
cwd: ws.path,
|
|
884
|
-
|
|
943
|
+
harness: ws.harness,
|
|
885
944
|
agentId: ws.agentId
|
|
886
|
-
})
|
|
945
|
+
} satisfies WorkspaceInfoResponse)
|
|
887
946
|
})
|
|
888
947
|
|
|
889
948
|
// Thumbnail freshness records, without image bytes — the capture hook compares
|
|
@@ -935,25 +994,26 @@ one.put('/applet-thumbnails', async c => {
|
|
|
935
994
|
|
|
936
995
|
one.put('/', async c => {
|
|
937
996
|
const ws = c.get('ws')
|
|
997
|
+
if (ws.remote) {
|
|
998
|
+
return c.text(
|
|
999
|
+
'Remote references contain only the owner address; save shared content to the owner',
|
|
1000
|
+
403
|
|
1001
|
+
)
|
|
1002
|
+
}
|
|
938
1003
|
const body = await c.req.json()
|
|
939
|
-
if (!body || body.version !==
|
|
1004
|
+
if (!body || body.version !== 2) return c.text('Bad request', 400)
|
|
940
1005
|
// `origin` is the writing tab's id, echoed so that tab skips its own event.
|
|
941
|
-
const { origin
|
|
942
|
-
//
|
|
943
|
-
//
|
|
1006
|
+
const { origin } = body
|
|
1007
|
+
// Only widgets and theme are taken from the body, so a grid/theme save can't
|
|
1008
|
+
// erase a `moi config`-set name or icon. See mergeLayoutForSave.
|
|
944
1009
|
const existing = await loadLayout(ws.path)
|
|
945
|
-
const next = mergeLayoutForSave(existing,
|
|
946
|
-
if (harness !== undefined && harness !== (ws.type ?? 'claude-code')) {
|
|
947
|
-
next.selectedModel = existing.selectedModel
|
|
948
|
-
next.selectedEffort = existing.selectedEffort
|
|
949
|
-
next.selectedSpeedMode = existing.selectedSpeedMode
|
|
950
|
-
}
|
|
1010
|
+
const next = mergeLayoutForSave(existing, body)
|
|
951
1011
|
await saveLayout(next, ws.path)
|
|
952
1012
|
if (
|
|
953
1013
|
JSON.stringify(resolveWorkspaceTheme(existing.theme)) !==
|
|
954
1014
|
JSON.stringify(resolveWorkspaceTheme(next.theme))
|
|
955
1015
|
) {
|
|
956
|
-
publishEvent({ type: 'theme:updated', origin: eventOrigin(origin) })
|
|
1016
|
+
publishEvent({ type: 'theme:updated', workspaceId: ws.id, origin: eventOrigin(origin) })
|
|
957
1017
|
}
|
|
958
1018
|
return c.body(null, 204)
|
|
959
1019
|
})
|
|
@@ -970,10 +1030,20 @@ one.delete('/', async c => {
|
|
|
970
1030
|
// ---- workspace collection: /api/workspaces ----------------------------------
|
|
971
1031
|
const workspaces = new Hono<ApiEnv>()
|
|
972
1032
|
|
|
1033
|
+
// Standalone Moi lists local workspaces only; remote references need Cloud.
|
|
1034
|
+
function visibleWorkspaces(entries: WorkspaceEntry[]) {
|
|
1035
|
+
return getAppConfig().environment === 'cloud' ? entries : entries.filter(entry => !entry.remote)
|
|
1036
|
+
}
|
|
1037
|
+
|
|
973
1038
|
async function mergeWorkspaceList(entries: WorkspaceEntry[]) {
|
|
974
1039
|
return Promise.all(
|
|
975
1040
|
entries.map(async e => {
|
|
976
|
-
const layout = await
|
|
1041
|
+
const layout = await loadWorkspaceFileConfig(e.path).catch(() => null)
|
|
1042
|
+
if (!layout) return e
|
|
1043
|
+
if (layout.remote) {
|
|
1044
|
+
return { ...e, remote: layout.remote, name: layout.remote.workspace_id }
|
|
1045
|
+
}
|
|
1046
|
+
|
|
977
1047
|
return {
|
|
978
1048
|
...e,
|
|
979
1049
|
name: layout.name ?? e.name,
|
|
@@ -988,7 +1058,7 @@ workspaces.get('/', async c => {
|
|
|
988
1058
|
// Merge each workspace's live identity and theme over the registry snapshot
|
|
989
1059
|
// so app-wide workspace lists render the same presentation as the workspace.
|
|
990
1060
|
const entries = await listWorkspaces()
|
|
991
|
-
return c.json(await mergeWorkspaceList(entries))
|
|
1061
|
+
return c.json(await mergeWorkspaceList(visibleWorkspaces(entries)))
|
|
992
1062
|
})
|
|
993
1063
|
|
|
994
1064
|
workspaces.put('/order', async c => {
|
|
@@ -997,12 +1067,16 @@ workspaces.put('/order', async c => {
|
|
|
997
1067
|
return c.text('Expected { ids: string[] }', 400)
|
|
998
1068
|
}
|
|
999
1069
|
try {
|
|
1000
|
-
|
|
1070
|
+
// Hidden remote references keep their place after the visible ones.
|
|
1071
|
+
const all = await listWorkspaces()
|
|
1072
|
+
const visible = new Set(visibleWorkspaces(all).map(entry => entry.id))
|
|
1073
|
+
const hiddenIds = all.filter(entry => !visible.has(entry.id)).map(entry => entry.id)
|
|
1074
|
+
const entries = await reorderWorkspaces([...body.ids, ...hiddenIds])
|
|
1001
1075
|
// List-only change: a narrow event so clients refetch just the sidebar
|
|
1002
1076
|
// list, not every per-workspace query (`workspace:updated` also triggers
|
|
1003
1077
|
// layout refetches in open workspaces).
|
|
1004
1078
|
publishEvent({ type: 'workspaces-list:updated', origin: eventOrigin(body.origin) })
|
|
1005
|
-
return c.json(await mergeWorkspaceList(entries))
|
|
1079
|
+
return c.json(await mergeWorkspaceList(visibleWorkspaces(entries)))
|
|
1006
1080
|
} catch (err) {
|
|
1007
1081
|
const message = err instanceof Error ? err.message : String(err)
|
|
1008
1082
|
return c.text(message, 400)
|
|
@@ -1017,17 +1091,43 @@ const DEMO_CREATE_BLOCKED = 'Workspace creation is not available in the Moi demo
|
|
|
1017
1091
|
|
|
1018
1092
|
workspaces.post('/', async c => {
|
|
1019
1093
|
if (getAppConfig().demo) return c.text(DEMO_CREATE_BLOCKED, 403)
|
|
1020
|
-
const body = await c.req.json()
|
|
1094
|
+
const body = await c.req.json().catch(() => null)
|
|
1095
|
+
if (body && typeof body === 'object' && 'remote' in body) {
|
|
1096
|
+
if (getAppConfig().environment !== 'cloud')
|
|
1097
|
+
return c.text('Shared workspaces require Cloud mode', 403)
|
|
1098
|
+
if (Object.keys(body).some(key => key !== 'remote' && key !== 'harness'))
|
|
1099
|
+
return c.text('Remote registration expects only remote and harness', 400)
|
|
1100
|
+
let remote
|
|
1101
|
+
try {
|
|
1102
|
+
remote = parseRemoteWorkspaceTarget(body.remote)
|
|
1103
|
+
} catch (error) {
|
|
1104
|
+
return c.text(error instanceof Error ? error.message : 'Invalid remote workspace', 400)
|
|
1105
|
+
}
|
|
1106
|
+
// The visitor's own agent. Omitted, the reference falls back to the same
|
|
1107
|
+
// default as any other workspace without a stored harness.
|
|
1108
|
+
const requested: unknown = body.harness
|
|
1109
|
+
if (requested !== undefined) {
|
|
1110
|
+
if (requested !== 'claude-code' && requested !== 'codex')
|
|
1111
|
+
return c.text('Unknown workspace type', 400)
|
|
1112
|
+
const availability = await harnessTypeAvailability(requested)
|
|
1113
|
+
if (availability.status !== 'available') return c.text(availability.reason, 400)
|
|
1114
|
+
}
|
|
1115
|
+
try {
|
|
1116
|
+
return c.json(await openSharedWorkspace(remote, requested), 201)
|
|
1117
|
+
} catch (error) {
|
|
1118
|
+
return c.text(error instanceof Error ? error.message : 'Could not open shared workspace', 503)
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1021
1121
|
if (!body?.path) return c.text('Missing path', 400)
|
|
1022
|
-
const
|
|
1023
|
-
if (!isHarnessType(
|
|
1024
|
-
const
|
|
1025
|
-
const availability = await
|
|
1122
|
+
const requestedHarness: unknown = body?.harness ?? 'claude-code'
|
|
1123
|
+
if (!isHarnessType(requestedHarness)) return c.text('Unknown workspace type', 400)
|
|
1124
|
+
const harness: HarnessType = requestedHarness
|
|
1125
|
+
const availability = await harnessTypeAvailability(harness)
|
|
1026
1126
|
if (availability.status !== 'available') return c.text(availability.reason, 400)
|
|
1027
1127
|
const path = resolve(String(body.path))
|
|
1028
1128
|
let metadata: WorkspaceImportMetadata
|
|
1029
1129
|
try {
|
|
1030
|
-
metadata = await resolveWorkspaceImportMetadata(path,
|
|
1130
|
+
metadata = await resolveWorkspaceImportMetadata(path, harness)
|
|
1031
1131
|
} catch (err) {
|
|
1032
1132
|
const message = err instanceof Error ? err.message : String(err)
|
|
1033
1133
|
return c.text(message, 400)
|
|
@@ -1036,16 +1136,16 @@ workspaces.post('/', async c => {
|
|
|
1036
1136
|
// skills dir) and the `.moi/` scaffold, exactly like `moi init` — a workspace
|
|
1037
1137
|
// added from the UI must be indistinguishable from one added via the CLI.
|
|
1038
1138
|
try {
|
|
1039
|
-
await provisionWorkspace(path,
|
|
1139
|
+
await provisionWorkspace(path, harness)
|
|
1040
1140
|
} catch (err) {
|
|
1041
1141
|
const message = err instanceof Error ? err.message : String(err)
|
|
1042
1142
|
return c.text(`Could not initialize workspace: ${message}`, 500)
|
|
1043
1143
|
}
|
|
1044
1144
|
const entry = await registerWorkspace(path, {
|
|
1045
|
-
|
|
1145
|
+
harness,
|
|
1046
1146
|
...metadata
|
|
1047
1147
|
})
|
|
1048
|
-
return c.json(entry, 201)
|
|
1148
|
+
return c.json((await mergeWorkspaceList([entry]))[0], 201)
|
|
1049
1149
|
})
|
|
1050
1150
|
|
|
1051
1151
|
workspaces.get('/discover', async c => c.json(await discoverWorkspaces()))
|
|
@@ -1056,9 +1156,11 @@ workspaces.get('/previews', async c => {
|
|
|
1056
1156
|
const entries = await listWorkspaces()
|
|
1057
1157
|
const previews = await Promise.all(
|
|
1058
1158
|
entries.map(async ws => {
|
|
1159
|
+
// A remote reference has no local content to preview.
|
|
1160
|
+
if (ws.remote) return [ws.id, { thumbnails: [] }] as const
|
|
1059
1161
|
const views = await listCompiledViews(ws.path).catch(() => [])
|
|
1060
1162
|
const preview = await getWorkspacePreview(ws.path, {
|
|
1061
|
-
|
|
1163
|
+
getHarnessPreview: includeFirstUserMessage =>
|
|
1062
1164
|
harnessFor(ws).workspacePreview(ws, includeFirstUserMessage),
|
|
1063
1165
|
viewIds: views.map(view => view.id),
|
|
1064
1166
|
// Capture time in base36 keeps the versioned segment short and URL-safe.
|
|
@@ -1073,10 +1175,10 @@ workspaces.get('/previews', async c => {
|
|
|
1073
1175
|
|
|
1074
1176
|
// Backends the create dialog can provision from scratch. OpenClaw workspaces
|
|
1075
1177
|
// belong to their agents and arrive via discovery.
|
|
1076
|
-
const
|
|
1178
|
+
const CREATABLE_HARNESSES = new Set<HarnessType>(['claude-code', 'codex'])
|
|
1077
1179
|
|
|
1078
|
-
async function
|
|
1079
|
-
return (await harnessFor(
|
|
1180
|
+
async function harnessTypeAvailability(harness: HarnessType): Promise<HarnessAvailability> {
|
|
1181
|
+
return (await harnessFor(harness).availability?.()) ?? { status: 'available' }
|
|
1080
1182
|
}
|
|
1081
1183
|
|
|
1082
1184
|
// Create a brand-new workspace: a fresh folder under createdWorkspacesRoot(),
|
|
@@ -1084,15 +1186,15 @@ async function workspaceTypeAvailability(type: WorkspaceType): Promise<HarnessAv
|
|
|
1084
1186
|
workspaces.post('/create', async c => {
|
|
1085
1187
|
if (getAppConfig().demo) return c.text(DEMO_CREATE_BLOCKED, 403)
|
|
1086
1188
|
const body = await c.req.json()
|
|
1087
|
-
const
|
|
1088
|
-
if (!isHarnessType(
|
|
1189
|
+
const requestedHarness: unknown = body?.harness ?? 'claude-code'
|
|
1190
|
+
if (!isHarnessType(requestedHarness)) {
|
|
1089
1191
|
return c.text('Unknown workspace type', 400)
|
|
1090
1192
|
}
|
|
1091
|
-
const
|
|
1092
|
-
if (!
|
|
1193
|
+
const harness: HarnessType = requestedHarness
|
|
1194
|
+
if (!CREATABLE_HARNESSES.has(harness)) {
|
|
1093
1195
|
return c.text('Workspaces of this type arrive through discovery, not creation', 400)
|
|
1094
1196
|
}
|
|
1095
|
-
const availability = await
|
|
1197
|
+
const availability = await harnessTypeAvailability(harness)
|
|
1096
1198
|
if (availability.status !== 'available') return c.text(availability.reason, 400)
|
|
1097
1199
|
const name =
|
|
1098
1200
|
body?.name === undefined
|
|
@@ -1104,13 +1206,13 @@ workspaces.post('/create', async c => {
|
|
|
1104
1206
|
if (invalid) return c.text(invalid, 400)
|
|
1105
1207
|
const path = await createWorkspaceDirectory(name, createdWorkspacesRoot())
|
|
1106
1208
|
try {
|
|
1107
|
-
await provisionWorkspace(path,
|
|
1209
|
+
await provisionWorkspace(path, harness)
|
|
1108
1210
|
} catch (err) {
|
|
1109
1211
|
const message = err instanceof Error ? err.message : String(err)
|
|
1110
1212
|
return c.text(`Could not create workspace: ${message}`, 500)
|
|
1111
1213
|
}
|
|
1112
1214
|
await setWorkspaceConfig(path, { name })
|
|
1113
|
-
const entry = await registerWorkspace(path, { id: basename(path),
|
|
1215
|
+
const entry = await registerWorkspace(path, { id: basename(path), harness, name })
|
|
1114
1216
|
// Nudge every connected client (the sidebar list) to refetch.
|
|
1115
1217
|
publishEvent({ type: 'workspaces-list:updated' })
|
|
1116
1218
|
return c.json(entry, 201)
|
package/server/app-config.ts
CHANGED
|
@@ -18,7 +18,6 @@ import { DATA_DIR } from './data-dir'
|
|
|
18
18
|
// CLI or server down with it.
|
|
19
19
|
export type AppConfig = {
|
|
20
20
|
environment: AppEnvironment
|
|
21
|
-
collab: boolean
|
|
22
21
|
// Demo mode: workspace creation is blocked (UI shows the
|
|
23
22
|
// cloud-demo promo dialog instead) and `moi` system commands are disabled.
|
|
24
23
|
demo: boolean
|
|
@@ -48,8 +47,6 @@ export type CloudflareAccessConfig = {
|
|
|
48
47
|
|
|
49
48
|
const DEFAULTS: AppConfig = {
|
|
50
49
|
environment: 'local',
|
|
51
|
-
// Experimental; deployments opt in explicitly.
|
|
52
|
-
collab: false,
|
|
53
50
|
demo: false,
|
|
54
51
|
demoInstallUrl: 'https://moi.computer',
|
|
55
52
|
cloudflareAccess: null,
|
|
@@ -198,7 +195,6 @@ function fileValues(raw: Record<string, unknown>): Partial<AppConfig> {
|
|
|
198
195
|
const out: Partial<AppConfig> = {}
|
|
199
196
|
const environment = parseEnvironment(raw.environment)
|
|
200
197
|
if (environment !== undefined) out.environment = environment
|
|
201
|
-
if (typeof raw.collab === 'boolean') out.collab = raw.collab
|
|
202
198
|
if (raw.demo !== undefined) {
|
|
203
199
|
if (typeof raw.demo === 'boolean') out.demo = raw.demo
|
|
204
200
|
else warn('ignoring "demo" — expected a boolean')
|
|
@@ -226,7 +222,6 @@ export function loadAppConfig(
|
|
|
226
222
|
const fromEnv: Partial<AppConfig> = {
|
|
227
223
|
environment: parseEnvironment(env.MOI_ENVIRONMENT),
|
|
228
224
|
demo: parseBool(env.MOI_DEMO),
|
|
229
|
-
collab: parseBool(env.MOI_COLLAB),
|
|
230
225
|
demoInstallUrl: parseString(env.MOI_DEMO_INSTALL_URL)
|
|
231
226
|
}
|
|
232
227
|
const merged = { ...DEFAULTS, ...fromFile }
|
|
@@ -264,6 +259,6 @@ export function resetAppConfig(): void {
|
|
|
264
259
|
// The only shape that reaches the browser (GET /api/config). Server-only keys
|
|
265
260
|
// added to AppConfig later stay out unless explicitly forwarded here.
|
|
266
261
|
export function clientAppConfig(): ClientAppConfig {
|
|
267
|
-
const { environment,
|
|
268
|
-
return { environment,
|
|
262
|
+
const { environment, demo, demoInstallUrl } = getAppConfig()
|
|
263
|
+
return { environment, demo, demoInstallUrl }
|
|
269
264
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mkdir, stat } from 'node:fs/promises'
|
|
2
|
+
import { getAppConfig } from '../app-config'
|
|
2
3
|
import { dirname, join } from 'node:path'
|
|
3
4
|
|
|
4
5
|
export const BASE_DECLARATION_SOURCE_PATH = join(import.meta.dir, 'declarations', 'base.d.ts')
|
|
@@ -33,14 +34,12 @@ export async function syncAppletDeclarations(
|
|
|
33
34
|
const updated: AppletDeclarationFile[] = []
|
|
34
35
|
if (await writeDeclaration(workspacePath, 'base.d.ts')) updated.push('base.d.ts')
|
|
35
36
|
|
|
36
|
-
//
|
|
37
|
-
if (
|
|
37
|
+
// Keep existing applets typecheckable when a cloud workspace is opened locally.
|
|
38
|
+
if (
|
|
39
|
+
getAppConfig().environment === 'cloud' ||
|
|
40
|
+
(await Bun.file(appletDeclarationPath(workspacePath, 'collab.d.ts')).exists())
|
|
41
|
+
) {
|
|
38
42
|
if (await writeDeclaration(workspacePath, 'collab.d.ts')) updated.push('collab.d.ts')
|
|
39
43
|
}
|
|
40
44
|
return updated
|
|
41
45
|
}
|
|
42
|
-
|
|
43
|
-
export async function installCollabDeclaration(workspacePath: string): Promise<void> {
|
|
44
|
-
await writeDeclaration(workspacePath, 'base.d.ts')
|
|
45
|
-
await writeDeclaration(workspacePath, 'collab.d.ts')
|
|
46
|
-
}
|
package/server/applets/index.ts
CHANGED
|
@@ -182,13 +182,24 @@ export async function serveApplet(
|
|
|
182
182
|
if (HASHED_FILE_RE.test(file)) {
|
|
183
183
|
cache = { 'Cache-Control': IMMUTABLE_CACHE }
|
|
184
184
|
} else {
|
|
185
|
-
|
|
185
|
+
// The served representation also depends on the API-base substitution format.
|
|
186
|
+
const etag = `"${bunFile.size}-${Math.trunc(bunFile.lastModified)}-${Bun.hash(apiBase)}-url-base-v2"`
|
|
186
187
|
cache = { ETag: etag, 'Cache-Control': 'private, no-cache' }
|
|
187
188
|
if (ifNoneMatch === etag) return new Response(null, { status: 304, headers: cache })
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
if (CODE_FILE_RE.test(file)) {
|
|
191
|
-
const
|
|
192
|
+
const runtimeBase = `(new URL(import.meta.url).pathname.match(/^\\/api\\/workspaces\\/[^/]+/)?.[0] ?? ${JSON.stringify(apiBase)})`
|
|
193
|
+
const swapped = (await bunFile.text()).replace(
|
|
194
|
+
/(["'])([^"'\n]*%%MOI_APPLET_API_BASE%%[^"'\n]*)\1/g,
|
|
195
|
+
(_match, _quote: string, value: string) =>
|
|
196
|
+
'(' +
|
|
197
|
+
value
|
|
198
|
+
.split(APPLET_API_BASE_SENTINEL)
|
|
199
|
+
.map(part => JSON.stringify(part))
|
|
200
|
+
.join(' + ' + runtimeBase + ' + ') +
|
|
201
|
+
')'
|
|
202
|
+
)
|
|
192
203
|
return new Response(swapped, { headers: { 'Content-Type': JS_CONTENT_TYPE, ...cache } })
|
|
193
204
|
}
|
|
194
205
|
return new Response(bunFile, {
|
|
@@ -200,12 +211,6 @@ export async function serveApplet(
|
|
|
200
211
|
// Pure helpers behind the applet/files/rpc HTTP routes, kept here (not web.ts) so
|
|
201
212
|
// they're unit-testable without importing web.ts — which binds ports on load.
|
|
202
213
|
|
|
203
|
-
// The API base a served bundle's sentinel is rewritten to. RPC and workspace
|
|
204
|
-
// file addresses resolved by `resolveUrl()` use this prefix.
|
|
205
|
-
export function apiBaseFor(id: string): string {
|
|
206
|
-
return `/api/workspaces/${id}`
|
|
207
|
-
}
|
|
208
|
-
|
|
209
214
|
// The entry's real name in the bundle dir (`.build/<kind>/<name>/index.js`).
|
|
210
215
|
const ENTRY_DISK_FILE = 'index.js'
|
|
211
216
|
|
|
@@ -241,7 +246,8 @@ export function parseAppletTail(
|
|
|
241
246
|
id: string,
|
|
242
247
|
segment: 'widgets' | 'views'
|
|
243
248
|
): { name: string; file: string } {
|
|
244
|
-
const tail =
|
|
249
|
+
const tail =
|
|
250
|
+
new URL(url).pathname.split(`/workspaces/${encodeURIComponent(id)}/${segment}/`)[1] ?? ''
|
|
245
251
|
const slash = tail.indexOf('/')
|
|
246
252
|
if (slash === -1) return { name: tail.replace(/\.js$/, ''), file: ENTRY_DISK_FILE }
|
|
247
253
|
const file = tail.slice(slash + 1)
|