moi-computer 0.12.1-next.2 → 0.12.1-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bunfig.toml +1 -5
- package/client/api/app-config.ts +1 -2
- package/client/api/app-ui-keys.ts +3 -1
- package/client/api/http.ts +4 -1
- package/client/api/workspace-keys.ts +3 -3
- package/client/app/app-provider.tsx +22 -2
- package/client/app/app-router.tsx +6 -0
- package/client/app/routes/home-route.tsx +14 -0
- package/client/app/routes/onboarding-route.tsx +11 -0
- package/client/app/routes/settings-route.tsx +10 -0
- package/client/app/routes/workspace-route.tsx +21 -19
- package/client/app/shell/sidebar-layout.tsx +34 -53
- package/client/components/shared/screen-shell.tsx +23 -0
- package/client/components/shared/ultrafast-icon.tsx +61 -0
- package/client/components/shared/workspace-icon.tsx +2 -2
- package/client/features/account/account-menu.tsx +96 -0
- package/client/features/account/account-provider.tsx +142 -0
- package/client/features/account/account-test-utils.tsx +294 -0
- package/client/features/account/api.ts +142 -0
- package/client/features/account/identity.ts +23 -0
- package/client/features/app-settings/api.ts +33 -0
- package/client/features/app-settings/general-settings.tsx +39 -0
- package/client/features/app-settings/profile-settings.tsx +95 -0
- package/client/features/app-settings/settings-page.tsx +48 -0
- package/client/features/app-settings/settings-section.tsx +26 -0
- package/client/features/app-settings/users-settings.tsx +195 -0
- package/client/features/chat/applet-chat-intents.ts +4 -20
- package/client/features/chat/chat-send.ts +17 -13
- package/client/features/chat/composer/model-order.ts +8 -4
- package/client/features/chat/composer/model-picker.tsx +88 -34
- package/client/features/chat/composer/use-workspace-composer-state.tsx +11 -3
- package/client/features/chat/composer/use-workspace-skill-updates.ts +1 -1
- package/client/features/chat/connection/chat-frames.ts +3 -15
- package/client/features/chat/messages/chat-empty-state.tsx +1 -4
- package/client/features/chat/messages/fork-history.ts +5 -5
- package/client/features/chat/messages/turn-view.tsx +3 -12
- package/client/features/chat/messages/user-message-bubble.tsx +63 -0
- package/client/features/chat/sessions/api.ts +121 -80
- package/client/features/chat/sessions/browser-tab-state.ts +14 -12
- package/client/features/chat/sessions/chat-selector.tsx +5 -6
- package/client/features/chat/sessions/use-selected-session.ts +172 -257
- package/client/features/chat/use-chat.ts +14 -19
- package/client/features/collab/applet-api.ts +15 -14
- package/client/features/collab/components/cursors.tsx +61 -24
- package/client/features/collab/components/presence-avatars.tsx +25 -12
- package/client/features/collab/components/presence-frame.tsx +20 -24
- package/client/features/collab/components/presence-group.tsx +15 -7
- package/client/features/collab/components/user-avatar-group.tsx +21 -8
- package/client/features/collab/components/user-avatar.tsx +38 -7
- package/client/features/collab/components/user.tsx +31 -12
- package/client/features/collab/users.ts +0 -5
- package/client/features/collab/workspace-users-menu.tsx +4 -4
- package/client/features/demo/demo-dialog.tsx +11 -3
- package/client/features/dev/collab/collab-playground.tsx +7 -7
- package/client/features/dev/collab/local-user-settings.tsx +7 -53
- package/client/features/dev/dev-index-page.tsx +5 -0
- package/client/features/dev/dev-routes.tsx +2 -0
- package/client/features/dev/harness-debug-page.tsx +3 -3
- package/client/features/dev/onboarding-preview-page.tsx +76 -0
- package/client/features/dev/workspace-setup-mocks.ts +16 -14
- package/client/features/dev/workspace-setup-preview.tsx +11 -17
- package/client/features/harness/api.ts +45 -15
- package/client/features/harness/device-login-steps.tsx +9 -3
- package/client/features/harness/harness-login-panel.tsx +228 -0
- package/client/features/harness/harness-presentation.ts +15 -0
- package/client/features/harness/harness-selector.tsx +119 -0
- package/client/features/harness/use-harness-login.ts +77 -0
- package/client/features/home/home-page.tsx +7 -7
- package/client/features/onboarding/agent-setup-step.tsx +57 -0
- package/client/features/onboarding/api.ts +42 -0
- package/client/features/onboarding/onboarding-idea-disk.tsx +129 -0
- package/client/features/onboarding/onboarding-page.tsx +32 -0
- package/client/features/onboarding/onboarding-screen.tsx +20 -0
- package/client/features/onboarding/onboarding-status.tsx +24 -0
- package/client/features/onboarding/workspace-setup-step.tsx +239 -0
- package/client/features/overview/default/registry.tsx +2 -2
- package/client/features/overview/default/views-widget.tsx +6 -5
- package/client/features/overview/overview.tsx +9 -11
- package/client/features/overview/widget-canvas.tsx +1 -1
- package/client/features/overview/workspace-name.tsx +2 -2
- package/client/features/update/update-control.tsx +1 -1
- package/client/features/views/api.ts +69 -16
- package/client/features/views/pending-view-screen.tsx +30 -9
- package/client/features/views/use-view-actions.ts +19 -20
- package/client/features/views/view-presentation.ts +2 -2
- package/client/features/views/view-submission.ts +28 -41
- package/client/features/workspace/add/api.ts +3 -23
- package/client/features/workspace/add/create-workspace-dialog.tsx +11 -7
- package/client/features/workspace/add/import-workspace-dialog.tsx +3 -3
- package/client/features/workspace/add/workspace-agent-options.ts +11 -12
- package/client/features/workspace/add/workspace-agent-selector.tsx +3 -132
- package/client/features/workspace/api.ts +32 -36
- package/client/features/workspace/harness-transition.ts +88 -0
- package/client/features/{settings → workspace/settings}/api.ts +1 -34
- package/client/features/{settings → workspace/settings}/connectors-settings.tsx +3 -3
- package/client/features/{settings → workspace/settings}/environment-settings.tsx +3 -3
- package/client/features/{settings → workspace/settings}/general-settings.tsx +77 -3
- package/client/features/{settings → workspace/settings}/use-env-vars.ts +1 -1
- package/client/features/{settings → workspace/settings}/workspace-icon-picker.tsx +3 -3
- package/client/features/workspace/setup/workspace-login-state.tsx +37 -156
- package/client/features/workspace/setup/workspace-recovery-states.tsx +0 -12
- package/client/features/workspace/setup/workspace-setup.tsx +34 -14
- package/client/features/workspace/setup/workspace-welcome-state.tsx +2 -2
- package/client/features/workspace/use-workspace-navigation.ts +25 -9
- package/client/features/workspace/workspace-content.tsx +11 -8
- package/client/features/workspace/workspace-frame.tsx +2 -1
- package/client/features/workspace/workspace-layout-context.tsx +5 -2
- package/client/features/workspace/workspace-menu.tsx +12 -8
- package/client/features/workspace/workspace-pending-screen.tsx +10 -10
- package/client/features/workspace/workspace-presentation.tsx +5 -13
- package/client/features/workspace/workspace-state.ts +169 -0
- package/client/features/workspace/workspace-tabs.tsx +22 -2
- package/client/index.css +2 -0
- package/client/index.tsx +3 -3
- package/client/lib/flags.ts +1 -1
- package/client/lib/{app-icon-registry.ts → identity-icon-registry.ts} +10 -14
- package/client/lib/user-display-name.ts +6 -0
- package/client/main.tsx +4 -1
- package/client/runtime/workspace-events.ts +21 -4
- package/client/runtime/workspace-theme.ts +9 -0
- package/client/tailwind-config.ts +43 -0
- package/dist/chunk-0mjzg20x.js +2 -0
- package/dist/chunk-2y59vrxg.js +5 -0
- package/dist/chunk-58dyt9bk.js +2 -0
- package/dist/chunk-5aj040e5.css +1 -0
- package/dist/{chunk-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
- package/dist/chunk-71fn6rmj.js +546 -0
- package/dist/chunk-7yg1m8hx.js +2 -0
- package/dist/chunk-825hys3h.js +1 -0
- package/dist/chunk-9bb8m9rx.js +2 -0
- package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
- package/dist/chunk-g0tcwqxc.js +1 -0
- package/dist/chunk-n0nab26d.js +1 -0
- package/dist/chunk-nf2wkvf9.js +14 -0
- package/dist/chunk-v88n1bay.js +74 -0
- package/dist/index.html +1 -1
- package/lib/harness-instructions.ts +1 -1
- package/lib/{app-icons.ts → identity-icons.ts} +6 -7
- package/lib/onboarding.ts +41 -0
- package/lib/speed-mode.ts +5 -0
- package/lib/types.ts +72 -63
- package/lib/view-build-directives.ts +1 -2
- package/lib/workspace-icon.ts +2 -2
- package/lib/workspace-layout.ts +1 -1
- package/lib/workspace-name.ts +15 -12
- package/package.json +9 -8
- package/server/README.md +27 -25
- package/server/api/harnesses.ts +31 -8
- package/server/api/index.ts +164 -131
- package/server/api/onboarding.ts +46 -0
- package/server/app-config.ts +23 -24
- package/server/app-settings.ts +6 -2
- package/server/applets/config.ts +5 -5
- package/server/applets/views.ts +19 -17
- package/server/cli/commands/init.ts +3 -3
- package/server/cli/commands/skill.ts +16 -17
- package/server/cli/commands/start.ts +8 -34
- package/server/cli/server.ts +18 -6
- package/server/collab/config.ts +1 -2
- package/server/collab/manager.ts +4 -1
- package/server/collab/skill/index.ts +1 -1
- package/server/control.ts +3 -3
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +24 -8
- package/server/harness/acp/session.ts +8 -4
- package/server/harness/auth.ts +14 -17
- package/server/harness/claude-code/NOTES.md +4 -3
- package/server/harness/claude-code/index.ts +2 -0
- package/server/harness/claude-code/models.ts +2 -20
- package/server/harness/claude-code/run-action.ts +123 -0
- package/server/harness/claude-code/session-title.ts +5 -7
- package/server/harness/claude-code/session.ts +24 -16
- package/server/harness/codex/NOTES.md +14 -9
- package/server/harness/codex/adapter.ts +14 -17
- package/server/harness/codex/index.ts +2 -0
- package/server/harness/codex/run-action.ts +93 -0
- package/server/harness/codex/session-title.ts +6 -8
- package/server/harness/codex/session.ts +11 -11
- package/server/harness/command.ts +45 -0
- package/server/harness/executable.ts +5 -0
- package/server/harness/fork.ts +6 -4
- package/server/harness/install.ts +49 -0
- package/server/harness/openclaw/session.ts +1 -2
- package/server/harness/run-action.ts +85 -0
- package/server/harness/session-title.ts +0 -46
- package/server/harness/types.ts +26 -2
- package/server/onboarding/brief.ts +29 -0
- package/server/onboarding/ideas.ts +48 -0
- package/server/onboarding/jobs.ts +291 -0
- package/server/onboarding/prompt.md +49 -0
- package/server/sessions/archive.ts +5 -14
- package/server/sessions/config.ts +17 -16
- package/server/sessions/lifecycle.ts +15 -13
- package/server/sessions/pending-views.ts +79 -108
- package/server/sessions/selected.ts +75 -161
- package/server/sessions/store.ts +40 -113
- package/server/sessions/view-sessions.ts +128 -111
- package/server/skills/locations.ts +82 -0
- package/server/skills/lock.ts +29 -0
- package/server/skills/template.ts +36 -25
- package/server/skills/update.ts +52 -5
- package/server/skills/version.ts +17 -22
- package/server/skills/workspace.ts +121 -0
- package/server/web.ts +23 -8
- package/server/workspace-state/file.ts +177 -0
- package/server/workspace-state/index.ts +162 -0
- package/server/workspace-state/legacy-migration.ts +79 -0
- package/server/workspace-state/lock.ts +42 -0
- package/server/workspace-state/types.ts +16 -0
- package/server/workspaces/change-harness.ts +88 -0
- package/server/workspaces/harness-transition.ts +29 -0
- package/server/workspaces/init.ts +29 -16
- package/server/workspaces/layout.ts +3 -0
- package/server/workspaces/registry.ts +58 -10
- package/{workspace/.claude/skills/moi-workspace → skill}/SKILL.md +7 -5
- package/{workspace/.claude/skills/moi-workspace → skill}/references/COLLAB.md +4 -8
- package/skill/references/DESIGN.md +148 -0
- package/{workspace/.claude/skills/moi-workspace → skill}/references/SCRATCHPAD.md +2 -2
- package/{workspace/.claude/skills/moi-workspace → skill}/references/UI-COMPONENTS.md +3 -0
- package/ui-components/badge.tsx +1 -1
- package/client/accept-hmr-dependencies.ts +0 -22
- package/client/features/workspace/setup/workspace-setup-panel.tsx +0 -18
- package/dist/chunk-00rh9df4.js +0 -2
- package/dist/chunk-4nh7y1hq.css +0 -1
- package/dist/chunk-am4agx6v.js +0 -2
- package/dist/chunk-d7cbm65e.js +0 -2
- package/dist/chunk-hbpdv7vd.js +0 -1
- package/dist/chunk-hmka9rt5.js +0 -2
- package/dist/chunk-hvh9f5h0.js +0 -14
- package/dist/chunk-mjjregkn.js +0 -10
- package/dist/chunk-pcnahct1.js +0 -5
- package/dist/chunk-rt30jbcm.js +0 -1
- package/dist/chunk-vt6zybej.js +0 -2
- package/dist/chunk-wbkwf6cc.js +0 -68
- package/dist/chunk-xjyfyz64.js +0 -1
- package/dist/chunk-y8nbwp21.js +0 -546
- package/dist/chunk-ysfdcew7.js +0 -1
- package/lib/experimental.ts +0 -14
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +0 -157
- /package/client/features/{settings → workspace/settings}/icon-picker-options.ts +0 -0
- /package/client/features/{settings → workspace/settings}/settings-layout.tsx +0 -0
- /package/client/features/{settings → workspace/settings}/workspace-settings-dialog.tsx +0 -0
- /package/{workspace/.claude/skills/moi-workspace → skill}/references/INTENTS.md +0 -0
package/server/api/index.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveWorkspaceEnv } from '../workspaces/env'
|
|
2
|
+
import { changeWorkspaceHarness } from '../workspaces/change-harness'
|
|
3
|
+
import { HarnessTransitionError, reserveWorkspaceOperation } from '../workspaces/harness-transition'
|
|
4
|
+
import { onboarding } from './onboarding'
|
|
5
|
+
import type { SpeedMode } from '@/lib/types'
|
|
6
|
+
import { isSpeedMode } from '@/lib/speed-mode'
|
|
2
7
|
import { isMessageAttachments } from '@/lib/message-attachments'
|
|
3
8
|
import { Hono } from 'hono'
|
|
4
9
|
import { serveStatic } from 'hono/bun'
|
|
5
10
|
import { createMiddleware } from 'hono/factory'
|
|
6
11
|
import { existsSync } from 'node:fs'
|
|
7
|
-
import { basename,
|
|
12
|
+
import { basename, resolve } from 'node:path'
|
|
8
13
|
|
|
9
14
|
import { UPDATE_ACTIVE_AGENT_MESSAGE } from '@/lib/update'
|
|
10
15
|
import { resolveWorkspaceTheme } from '@/lib/themes'
|
|
@@ -16,7 +21,7 @@ import type {
|
|
|
16
21
|
HarnessAvailability,
|
|
17
22
|
SelectedSessionScope,
|
|
18
23
|
UploadInfo,
|
|
19
|
-
|
|
24
|
+
WorkspaceHarness,
|
|
20
25
|
WorkspaceEntry,
|
|
21
26
|
WorkspaceType
|
|
22
27
|
} from '@/lib/types'
|
|
@@ -26,7 +31,7 @@ import { proxyUserState } from '../collab/cloudflare-access'
|
|
|
26
31
|
import { collabManager } from '../collab/manager'
|
|
27
32
|
import { harnessStore } from '../harness/auth'
|
|
28
33
|
import { harnesses } from './harnesses'
|
|
29
|
-
import { clientAppConfig, getAppConfig } from '../app-config'
|
|
34
|
+
import { clientAppConfig, createdWorkspacesRoot, getAppConfig } from '../app-config'
|
|
30
35
|
import { getAppSettings, pickAppSettingsPatch, saveAppSettings } from '../app-settings'
|
|
31
36
|
import { appletForModule, recordAppletError } from '../applets/log'
|
|
32
37
|
import { apiBaseFor, parseAppletTail, serveWorkspaceFile } from '../applets'
|
|
@@ -60,17 +65,16 @@ import {
|
|
|
60
65
|
import { loadScratchpadDoc, saveScratchpadDoc } from '../scratchpad/document'
|
|
61
66
|
import { MAX_ASSET_BYTES, scratchpadAssetFile, storeScratchpadAsset } from '../scratchpad/assets'
|
|
62
67
|
import {
|
|
68
|
+
deselectSession,
|
|
63
69
|
getPinnedSession,
|
|
64
|
-
getSelectedSession,
|
|
65
|
-
getWorkspaceSessionSelection,
|
|
66
70
|
pinSession,
|
|
67
|
-
saveSelectedSession
|
|
71
|
+
saveSelectedSession,
|
|
72
|
+
unpinSession
|
|
68
73
|
} from '../sessions/selected'
|
|
69
|
-
import type { SelectedSessionUpdate } from '../sessions/selected'
|
|
70
74
|
import { saveSessionConfig } from '../sessions/config'
|
|
71
75
|
import type { SessionConfigPatch } from '../sessions/config'
|
|
72
|
-
import { getSessionRecord, withSessionRecords } from '../sessions/store'
|
|
73
76
|
import { archiveWorkspaceSession } from '../sessions/archive'
|
|
77
|
+
import { getWorkspaceState } from '../workspace-state'
|
|
74
78
|
import { DIST_DIR, prebuilt } from '../static'
|
|
75
79
|
import { getWorkspaceSkillsStatus, updateWorkspaceSkills } from '../skills/update'
|
|
76
80
|
import { serveWorkspaceImagePreview } from '../workspaces/preview'
|
|
@@ -94,11 +98,8 @@ import {
|
|
|
94
98
|
import { submitView, ViewStartupError } from '../sessions/view-sessions'
|
|
95
99
|
import { listWidgets, serveWidget } from '../applets/widgets'
|
|
96
100
|
import { getWorkspaceConfig, setWorkspaceConfig } from '../workspaces/config'
|
|
97
|
-
import {
|
|
98
|
-
|
|
99
|
-
provisionWorkspace,
|
|
100
|
-
validateWorkspaceFolderName
|
|
101
|
-
} from '../workspaces/init'
|
|
101
|
+
import { createWorkspaceDirectory, provisionWorkspace } from '../workspaces/init'
|
|
102
|
+
import { validateWorkspaceName } from '@/lib/workspace-name'
|
|
102
103
|
import { resolveWorkspaceImportMetadata } from '../workspaces/import'
|
|
103
104
|
import type { WorkspaceImportMetadata } from '../workspaces/import'
|
|
104
105
|
import { getWorkspaceEnvView, parseEnvUpdate, updateWorkspaceEnv } from '../workspaces/env'
|
|
@@ -121,15 +122,6 @@ function eventOrigin(value: unknown): string | undefined {
|
|
|
121
122
|
return typeof value === 'string' ? value : undefined
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
function publishSelectedSession(workspaceId: string, update: SelectedSessionUpdate): void {
|
|
125
|
-
if (!update.changed) return
|
|
126
|
-
publishEvent({
|
|
127
|
-
type: 'selected-session:updated',
|
|
128
|
-
workspaceId,
|
|
129
|
-
sessionId: update.sessionId
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
|
|
133
125
|
async function handleFunctionCall(
|
|
134
126
|
req: Request,
|
|
135
127
|
tail: string,
|
|
@@ -174,15 +166,37 @@ async function handleFunctionCall(
|
|
|
174
166
|
const withWorkspace = createMiddleware<ApiEnv>(async (c, next) => {
|
|
175
167
|
const id = c.req.param('id')
|
|
176
168
|
if (!id) return c.text('Workspace not found', 404)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
169
|
+
let release: (() => void) | undefined
|
|
170
|
+
try {
|
|
171
|
+
if (c.req.method !== 'GET' && !c.req.path.endsWith('/harness'))
|
|
172
|
+
release = reserveWorkspaceOperation(id)
|
|
173
|
+
const ws = await getWorkspace(id)
|
|
174
|
+
if (!ws) return c.text('Workspace not found', 404)
|
|
175
|
+
c.set('ws', ws)
|
|
176
|
+
await next()
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (error instanceof HarnessTransitionError) return c.text(error.message, 409)
|
|
179
|
+
throw error
|
|
180
|
+
} finally {
|
|
181
|
+
release?.()
|
|
182
|
+
}
|
|
181
183
|
})
|
|
182
184
|
|
|
183
185
|
// ---- single workspace: /api/workspaces/:id/* --------------------------------
|
|
184
186
|
const one = new Hono<ApiEnv>()
|
|
185
187
|
one.use('*', withWorkspace)
|
|
188
|
+
one.patch('/harness', async c => {
|
|
189
|
+
if (getAppConfig().demo) return c.text('Changing agents is unavailable in the demo', 403)
|
|
190
|
+
const body = await c.req.json().catch(() => null)
|
|
191
|
+
if (!body || !['claude-code', 'codex'].includes(body.type))
|
|
192
|
+
return c.text('Invalid agent selection', 400)
|
|
193
|
+
try {
|
|
194
|
+
return c.json(await changeWorkspaceHarness(c.get('ws'), body.type))
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (error instanceof HarnessTransitionError) return c.text(error.message, 409)
|
|
197
|
+
throw error
|
|
198
|
+
}
|
|
199
|
+
})
|
|
186
200
|
|
|
187
201
|
one.get('/widgets', c => listWidgets(c.get('ws').path))
|
|
188
202
|
|
|
@@ -204,7 +218,7 @@ one.get('/views', c => listViews(c.get('ws').path))
|
|
|
204
218
|
one.patch('/views/:viewId', async c => {
|
|
205
219
|
const ws = c.get('ws')
|
|
206
220
|
const body = await c.req.json().catch(() => null)
|
|
207
|
-
if (await getPendingView(ws
|
|
221
|
+
if (await getPendingView(ws, c.req.param('viewId'))) {
|
|
208
222
|
try {
|
|
209
223
|
if (
|
|
210
224
|
typeof body?.requirements !== 'string' &&
|
|
@@ -213,7 +227,7 @@ one.patch('/views/:viewId', async c => {
|
|
|
213
227
|
)
|
|
214
228
|
return c.text('Expected requirements, title, or icon', 400)
|
|
215
229
|
return c.json(
|
|
216
|
-
await updatePendingView(ws
|
|
230
|
+
await updatePendingView(ws, c.req.param('viewId'), {
|
|
217
231
|
requirements: typeof body.requirements === 'string' ? body.requirements : undefined,
|
|
218
232
|
title: typeof body.title === 'string' ? body.title.trim() : undefined,
|
|
219
233
|
icon: typeof body.icon === 'string' ? body.icon : undefined
|
|
@@ -240,7 +254,7 @@ one.delete('/views/:viewId', async c => {
|
|
|
240
254
|
const ws = c.get('ws')
|
|
241
255
|
try {
|
|
242
256
|
const viewId = c.req.param('viewId')
|
|
243
|
-
if (await getPendingView(ws
|
|
257
|
+
if (await getPendingView(ws, viewId)) {
|
|
244
258
|
const active = new Set(
|
|
245
259
|
harnessFor(ws)
|
|
246
260
|
.activeSessions()
|
|
@@ -266,7 +280,7 @@ one.get('/views/*', c => {
|
|
|
266
280
|
|
|
267
281
|
one.post('/views', async c => {
|
|
268
282
|
const ws = c.get('ws')
|
|
269
|
-
return c.json(await createPendingView(ws
|
|
283
|
+
return c.json(await createPendingView(ws), 201)
|
|
270
284
|
})
|
|
271
285
|
|
|
272
286
|
one.post('/views/:viewId/submit', async c => {
|
|
@@ -278,7 +292,7 @@ one.post('/views/:viewId/submit', async c => {
|
|
|
278
292
|
selectedSessionScope?: SelectedSessionScope
|
|
279
293
|
model?: string
|
|
280
294
|
effort?: string
|
|
281
|
-
|
|
295
|
+
speedMode?: SpeedMode
|
|
282
296
|
stream?: boolean
|
|
283
297
|
attachments?: unknown
|
|
284
298
|
}>()
|
|
@@ -314,7 +328,7 @@ one.post('/views/:viewId/submit', async c => {
|
|
|
314
328
|
optimisticId: body.optimisticId,
|
|
315
329
|
model: typeof body.model === 'string' ? body.model : undefined,
|
|
316
330
|
effort: typeof body.effort === 'string' ? body.effort : undefined,
|
|
317
|
-
|
|
331
|
+
speedMode: isSpeedMode(body.speedMode) ? body.speedMode : undefined,
|
|
318
332
|
stream: body.stream === true ? true : undefined
|
|
319
333
|
})
|
|
320
334
|
return c.json(result)
|
|
@@ -482,64 +496,94 @@ one.get('/uploads/:uploadId', c => {
|
|
|
482
496
|
})
|
|
483
497
|
})
|
|
484
498
|
|
|
499
|
+
// Per-user chat state: pin, the chat each tab shows, per-chat settings and
|
|
500
|
+
// fork history, and views being built. Every write below answers with the new
|
|
501
|
+
// state; other clients get it as `state:changed`.
|
|
502
|
+
one.get('/state', async c => c.json(await getWorkspaceState(c.get('ws'))))
|
|
503
|
+
|
|
504
|
+
// The agent's chats. Tab ownership and settings come from `/state`.
|
|
485
505
|
one.get('/sessions', async c => {
|
|
486
506
|
const ws = c.get('ws')
|
|
487
|
-
return c.json(await
|
|
507
|
+
return c.json(await harnessFor(ws).listSessions(ws))
|
|
488
508
|
})
|
|
489
509
|
|
|
490
|
-
one.
|
|
491
|
-
|
|
510
|
+
one.put('/sessions/:sessionId/pin', async c => {
|
|
511
|
+
const ws = c.get('ws')
|
|
512
|
+
const sessionId = c.req.param('sessionId')
|
|
513
|
+
const harness = harnessFor(ws)
|
|
514
|
+
const found = (await harness.listSessions(ws)).some(session => session.sessionId === sessionId)
|
|
515
|
+
const active = harness
|
|
516
|
+
.activeSessions()
|
|
517
|
+
.some(session => session.workspaceId === ws.id && session.sessionId === sessionId)
|
|
518
|
+
if (!found && !active) return c.text('Chat not found', 404)
|
|
519
|
+
await pinSession(ws, sessionId)
|
|
520
|
+
return c.json(await getWorkspaceState(ws))
|
|
492
521
|
})
|
|
493
522
|
|
|
494
|
-
one.
|
|
523
|
+
one.delete('/sessions/:sessionId/pin', async c => {
|
|
495
524
|
const ws = c.get('ws')
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
return c.text('Invalid chat', 400)
|
|
499
|
-
if (body.sessionId) {
|
|
500
|
-
const harness = harnessFor(ws)
|
|
501
|
-
const found = (await harness.listSessions(ws)).some(
|
|
502
|
-
session => session.sessionId === body.sessionId
|
|
503
|
-
)
|
|
504
|
-
const active = harness
|
|
505
|
-
.activeSessions()
|
|
506
|
-
.some(session => session.workspaceId === ws.id && session.sessionId === body.sessionId)
|
|
507
|
-
if (!found && !active) return c.text('Chat not found', 404)
|
|
508
|
-
}
|
|
509
|
-
await pinSession(ws.path, body.sessionId)
|
|
510
|
-
publishEvent({
|
|
511
|
-
type: 'selected-session:updated',
|
|
512
|
-
workspaceId: ws.id,
|
|
513
|
-
sessionId: (await getSelectedSession(ws.path)) ?? null
|
|
514
|
-
})
|
|
515
|
-
return c.json({ pinnedSessionId: body.sessionId })
|
|
525
|
+
await unpinSession(ws, c.req.param('sessionId'))
|
|
526
|
+
return c.json(await getWorkspaceState(ws))
|
|
516
527
|
})
|
|
517
528
|
|
|
518
|
-
|
|
529
|
+
// Show the chat in a tab. `ifMatch` (a chat id, or null for none) applies the
|
|
530
|
+
// change only while the tab still shows that chat.
|
|
531
|
+
one.put('/sessions/:sessionId/selection', async c => {
|
|
519
532
|
const ws = c.get('ws')
|
|
520
533
|
const body: unknown = await c.req.json().catch(() => null)
|
|
521
534
|
if (!body || typeof body !== 'object') return c.text('Bad request', 400)
|
|
535
|
+
const input = body as { tabId?: unknown; ifMatch?: unknown }
|
|
536
|
+
if (!isWorkspaceTabId(input.tabId)) return c.text('Invalid chat tab', 400)
|
|
537
|
+
const hasIfMatch = Object.prototype.hasOwnProperty.call(input, 'ifMatch')
|
|
538
|
+
if (hasIfMatch && input.ifMatch !== null && typeof input.ifMatch !== 'string')
|
|
539
|
+
return c.text('ifMatch must be a chat id or null', 400)
|
|
540
|
+
if (await getPinnedSession(ws)) return c.text('Unpin chat before switching', 409)
|
|
541
|
+
await saveSelectedSession(
|
|
542
|
+
ws,
|
|
543
|
+
c.req.param('sessionId'),
|
|
544
|
+
input.tabId,
|
|
545
|
+
hasIfMatch ? (input.ifMatch as string | null) : undefined
|
|
546
|
+
)
|
|
547
|
+
return c.json(await getWorkspaceState(ws))
|
|
548
|
+
})
|
|
522
549
|
|
|
523
|
-
|
|
524
|
-
|
|
550
|
+
// Stop showing the chat in a tab, which then opens a new chat. A tab showing
|
|
551
|
+
// another chat is left alone.
|
|
552
|
+
one.delete('/sessions/:sessionId/selection', async c => {
|
|
553
|
+
const ws = c.get('ws')
|
|
554
|
+
const body: unknown = await c.req.json().catch(() => null)
|
|
555
|
+
const tabId = (body as { tabId?: unknown } | null)?.tabId
|
|
525
556
|
if (!isWorkspaceTabId(tabId)) return c.text('Invalid chat tab', 400)
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
if (
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
557
|
+
await deselectSession(ws, c.req.param('sessionId'), tabId)
|
|
558
|
+
return c.json(await getWorkspaceState(ws))
|
|
559
|
+
})
|
|
560
|
+
|
|
561
|
+
// Change run settings. Omitted fields stay; null clears one.
|
|
562
|
+
one.patch('/sessions/:sessionId/config', async c => {
|
|
563
|
+
const body = await c.req.json().catch(() => null)
|
|
564
|
+
if (typeof body !== 'object' || body === null) {
|
|
565
|
+
return c.text('Expected a JSON object', 400)
|
|
566
|
+
}
|
|
567
|
+
const patch: SessionConfigPatch = {}
|
|
568
|
+
const record = body as Record<string, unknown>
|
|
569
|
+
for (const key of ['model', 'effort'] as const) {
|
|
570
|
+
if (!(key in record)) continue
|
|
571
|
+
const value = record[key]
|
|
572
|
+
if (value !== null && typeof value !== 'string') {
|
|
573
|
+
return c.text(`${key} must be a string or null`, 400)
|
|
574
|
+
}
|
|
575
|
+
patch[key] = value
|
|
576
|
+
}
|
|
577
|
+
if ('speedMode' in record) {
|
|
578
|
+
const value = record.speedMode
|
|
579
|
+
if (value !== null && !isSpeedMode(value)) {
|
|
580
|
+
return c.text('speedMode must be "normal", "fast", "ultrafast", or null', 400)
|
|
581
|
+
}
|
|
582
|
+
patch.speedMode = value
|
|
583
|
+
}
|
|
584
|
+
const ws = c.get('ws')
|
|
585
|
+
await saveSessionConfig(ws, c.req.param('sessionId'), patch)
|
|
586
|
+
return c.json(await getWorkspaceState(ws))
|
|
543
587
|
})
|
|
544
588
|
|
|
545
589
|
one.post('/sessions/:sessionId/archive', async c => {
|
|
@@ -550,7 +594,7 @@ one.post('/sessions/:sessionId/archive', async c => {
|
|
|
550
594
|
|
|
551
595
|
try {
|
|
552
596
|
await archiveWorkspaceSession(ws, sessionId)
|
|
553
|
-
return c.
|
|
597
|
+
return c.json(await getWorkspaceState(ws))
|
|
554
598
|
} catch (error) {
|
|
555
599
|
console.error(`[api] archive chat failed for ${harness.id}`, error)
|
|
556
600
|
// Harnesses translate backend refusals into actionable one-liners (e.g.
|
|
@@ -567,39 +611,6 @@ one.get('/sessions/:sessionId/events', async c => {
|
|
|
567
611
|
return c.json(await harnessFor(ws).sessionEvents(ws, sessionId))
|
|
568
612
|
})
|
|
569
613
|
|
|
570
|
-
one.get('/sessions/:sessionId', async c => {
|
|
571
|
-
return c.json(await getSessionRecord(c.get('ws').path, c.req.param('sessionId')))
|
|
572
|
-
})
|
|
573
|
-
|
|
574
|
-
// Patch run settings and return the complete session record. null clears a setting.
|
|
575
|
-
one.put('/sessions/:sessionId/config', async c => {
|
|
576
|
-
const body = await c.req.json().catch(() => null)
|
|
577
|
-
if (typeof body !== 'object' || body === null) {
|
|
578
|
-
return c.text('Expected a JSON object', 400)
|
|
579
|
-
}
|
|
580
|
-
const patch: SessionConfigPatch = {}
|
|
581
|
-
const record = body as Record<string, unknown>
|
|
582
|
-
for (const key of ['model', 'effort'] as const) {
|
|
583
|
-
if (!(key in record)) continue
|
|
584
|
-
const value = record[key]
|
|
585
|
-
if (value !== null && typeof value !== 'string') {
|
|
586
|
-
return c.text(`${key} must be a string or null`, 400)
|
|
587
|
-
}
|
|
588
|
-
patch[key] = value
|
|
589
|
-
}
|
|
590
|
-
if ('fastMode' in record) {
|
|
591
|
-
const value = record.fastMode
|
|
592
|
-
if (value !== null && typeof value !== 'boolean') {
|
|
593
|
-
return c.text('fastMode must be a boolean or null', 400)
|
|
594
|
-
}
|
|
595
|
-
patch.fastMode = value
|
|
596
|
-
}
|
|
597
|
-
const workspacePath = c.get('ws').path
|
|
598
|
-
const sessionId = c.req.param('sessionId')
|
|
599
|
-
await saveSessionConfig(workspacePath, sessionId, patch)
|
|
600
|
-
return c.json(await getSessionRecord(workspacePath, sessionId))
|
|
601
|
-
})
|
|
602
|
-
|
|
603
614
|
one.get('/mcp', async c => {
|
|
604
615
|
const ws = c.get('ws')
|
|
605
616
|
return c.json((await harnessFor(ws).mcpStatus?.(ws)) ?? [])
|
|
@@ -664,10 +675,9 @@ one.post('/skills/update', async c => {
|
|
|
664
675
|
return c.json(result.status)
|
|
665
676
|
})
|
|
666
677
|
|
|
667
|
-
//
|
|
668
|
-
//
|
|
669
|
-
|
|
670
|
-
one.get('/agent', async c => {
|
|
678
|
+
// Workspace configuration and models. Shared account status is served by
|
|
679
|
+
// /harnesses/status; only workspace overrides and gateways are probed here.
|
|
680
|
+
one.get('/harness', async c => {
|
|
671
681
|
const ws = c.get('ws')
|
|
672
682
|
const harness = harnessFor(ws)
|
|
673
683
|
const capabilities = {
|
|
@@ -678,18 +688,35 @@ one.get('/agent', async c => {
|
|
|
678
688
|
if (!existsSync(ws.path)) {
|
|
679
689
|
return c.json({
|
|
680
690
|
...capabilities,
|
|
681
|
-
|
|
691
|
+
isFolderMissing: true,
|
|
682
692
|
availability: { status: 'unavailable', reason: 'Workspace folder not found' },
|
|
683
693
|
models: []
|
|
684
|
-
} satisfies
|
|
694
|
+
} satisfies WorkspaceHarness)
|
|
685
695
|
}
|
|
696
|
+
const authEnv =
|
|
697
|
+
harness.id === 'codex'
|
|
698
|
+
? /^(OPENAI_|CODEX_)/
|
|
699
|
+
: /^(ANTHROPIC_|CLAUDE_|AWS_|GOOGLE_|AZURE_|CLOUD_ML_)/
|
|
700
|
+
const hasAuthOverrides =
|
|
701
|
+
harness.authStatus &&
|
|
702
|
+
Object.entries(await resolveWorkspaceEnv(ws.path)).some(
|
|
703
|
+
([key, value]) =>
|
|
704
|
+
value !== process.env[key] &&
|
|
705
|
+
(authEnv.test(key) || /^(HOME|USERPROFILE|XDG_CONFIG_HOME)$/.test(key))
|
|
706
|
+
)
|
|
686
707
|
const refresh = c.req.query('refresh') === 'true'
|
|
687
708
|
if (refresh) await loginShellPath({ refresh: true })
|
|
688
709
|
// A backend that can't answer (codex CLI missing, gateway down) degrades to
|
|
689
710
|
// an empty catalog — the picker hides and chat surfaces the real problem via
|
|
690
711
|
// workspace setup, instead of this endpoint failing on page load.
|
|
691
712
|
const [availability, models] = await Promise.all([
|
|
692
|
-
|
|
713
|
+
// Shared account status comes from /harnesses/status.
|
|
714
|
+
// Gateway-backed harnesses still have workspace-specific readiness.
|
|
715
|
+
harness.authStatus && !hasAuthOverrides
|
|
716
|
+
? Promise.resolve({ status: 'available' as const })
|
|
717
|
+
: refresh
|
|
718
|
+
? harnessStore.refresh(ws)
|
|
719
|
+
: harnessStore.getAvailability(ws),
|
|
693
720
|
harness.listModels(ws).catch(err => {
|
|
694
721
|
console.error(`[api] listModels failed for ${harness.id}`, err)
|
|
695
722
|
return []
|
|
@@ -698,8 +725,9 @@ one.get('/agent', async c => {
|
|
|
698
725
|
return c.json({
|
|
699
726
|
...capabilities,
|
|
700
727
|
availability,
|
|
728
|
+
hasAuthOverrides: Boolean(hasAuthOverrides),
|
|
701
729
|
models
|
|
702
|
-
} satisfies
|
|
730
|
+
} satisfies WorkspaceHarness)
|
|
703
731
|
})
|
|
704
732
|
|
|
705
733
|
// Workspace identity. Uploads use the image route below.
|
|
@@ -885,11 +913,16 @@ one.put('/', async c => {
|
|
|
885
913
|
const body = await c.req.json()
|
|
886
914
|
if (!body || body.version !== 1) return c.text('Bad request', 400)
|
|
887
915
|
// `origin` is the writing tab's id, echoed so that tab skips its own event.
|
|
888
|
-
const { origin, ...layout } = body
|
|
916
|
+
const { origin, harness, ...layout } = body
|
|
889
917
|
// Preserve server-owned identity (name/icon) across a grid/theme save so the
|
|
890
918
|
// client's PUT can't erase a `moi config`-set name. See mergeLayoutForSave.
|
|
891
919
|
const existing = await loadLayout(ws.path)
|
|
892
920
|
const next = mergeLayoutForSave(existing, layout)
|
|
921
|
+
if (harness !== undefined && harness !== (ws.type ?? 'claude-code')) {
|
|
922
|
+
next.selectedModel = existing.selectedModel
|
|
923
|
+
next.selectedEffort = existing.selectedEffort
|
|
924
|
+
next.selectedSpeedMode = existing.selectedSpeedMode
|
|
925
|
+
}
|
|
893
926
|
await saveLayout(next, ws.path)
|
|
894
927
|
if (
|
|
895
928
|
JSON.stringify(resolveWorkspaceTheme(existing.theme)) !==
|
|
@@ -1021,12 +1054,6 @@ async function workspaceTypeAvailability(type: WorkspaceType): Promise<HarnessAv
|
|
|
1021
1054
|
return (await harnessFor(type).availability?.()) ?? { status: 'available' }
|
|
1022
1055
|
}
|
|
1023
1056
|
|
|
1024
|
-
// Both workspace dialogs only need installation facts to offer agent choices.
|
|
1025
|
-
workspaces.get('/create', async c => {
|
|
1026
|
-
c.header('Cache-Control', 'no-store')
|
|
1027
|
-
return c.json({ installed: await detectInstalledHarnesses() })
|
|
1028
|
-
})
|
|
1029
|
-
|
|
1030
1057
|
// Create a brand-new workspace: a fresh folder under createdWorkspacesRoot(),
|
|
1031
1058
|
// provisioned (skills + `.moi/` scaffold) and registered.
|
|
1032
1059
|
workspaces.post('/create', async c => {
|
|
@@ -1042,18 +1069,23 @@ workspaces.post('/create', async c => {
|
|
|
1042
1069
|
}
|
|
1043
1070
|
const availability = await workspaceTypeAvailability(type)
|
|
1044
1071
|
if (availability.status !== 'available') return c.text(availability.reason, 400)
|
|
1045
|
-
const name =
|
|
1046
|
-
|
|
1072
|
+
const name =
|
|
1073
|
+
body?.name === undefined
|
|
1074
|
+
? 'My workspace'
|
|
1075
|
+
: typeof body.name === 'string'
|
|
1076
|
+
? body.name.trim()
|
|
1077
|
+
: ''
|
|
1078
|
+
const invalid = validateWorkspaceName(name)
|
|
1047
1079
|
if (invalid) return c.text(invalid, 400)
|
|
1048
|
-
const path =
|
|
1049
|
-
if (existsSync(path)) return c.text('A folder with that name already exists', 409)
|
|
1080
|
+
const path = await createWorkspaceDirectory(name, createdWorkspacesRoot())
|
|
1050
1081
|
try {
|
|
1051
1082
|
await provisionWorkspace(path, type)
|
|
1052
1083
|
} catch (err) {
|
|
1053
1084
|
const message = err instanceof Error ? err.message : String(err)
|
|
1054
1085
|
return c.text(`Could not create workspace: ${message}`, 500)
|
|
1055
1086
|
}
|
|
1056
|
-
|
|
1087
|
+
await setWorkspaceConfig(path, { name })
|
|
1088
|
+
const entry = await registerWorkspace(path, { id: basename(path), type, name })
|
|
1057
1089
|
// Nudge every connected client (the sidebar list) to refetch.
|
|
1058
1090
|
publishEvent({ type: 'workspaces-list:updated' })
|
|
1059
1091
|
return c.json(entry, 201)
|
|
@@ -1069,6 +1101,7 @@ export const api = new Hono()
|
|
|
1069
1101
|
|
|
1070
1102
|
api.route('/api/workspaces', workspaces)
|
|
1071
1103
|
api.route('/api/harnesses', harnesses)
|
|
1104
|
+
api.route('/api/onboarding', onboarding)
|
|
1072
1105
|
|
|
1073
1106
|
// Startup config (config.json in the data dir + MOI_* env), client-safe
|
|
1074
1107
|
// subset. Immutable for the process lifetime — clients cache it forever.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Hono } from 'hono'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import { getAppConfig } from '../app-config'
|
|
4
|
+
import { getAppSettings } from '../app-settings'
|
|
5
|
+
import { cancelIdeas, createFromIdea, discoverIdeas } from '../onboarding/jobs'
|
|
6
|
+
|
|
7
|
+
const discoverySchema = z.object({
|
|
8
|
+
harness: z.enum(['claude-code', 'codex']),
|
|
9
|
+
runId: z.string().uuid()
|
|
10
|
+
})
|
|
11
|
+
const buildSchema = discoverySchema.extend({
|
|
12
|
+
ideaId: z.string().uuid(),
|
|
13
|
+
operationId: z.string().uuid(),
|
|
14
|
+
retry: z.boolean().optional()
|
|
15
|
+
})
|
|
16
|
+
export const onboarding = new Hono()
|
|
17
|
+
onboarding.use('*', async (c, next) => {
|
|
18
|
+
if (getAppConfig().demo || !getAppSettings().showOnboarding)
|
|
19
|
+
return c.json({ error: 'Onboarding is not enabled' }, 403)
|
|
20
|
+
c.header('Cache-Control', 'no-store')
|
|
21
|
+
await next()
|
|
22
|
+
})
|
|
23
|
+
onboarding.post('/discover', async c => {
|
|
24
|
+
const parsed = discoverySchema.safeParse(await c.req.json().catch(() => undefined))
|
|
25
|
+
if (!parsed.success) return c.json({ error: 'Invalid discovery request' }, 400)
|
|
26
|
+
return c.json(await discoverIdeas(parsed.data))
|
|
27
|
+
})
|
|
28
|
+
onboarding.post('/cancel', async c => {
|
|
29
|
+
const parsed = z
|
|
30
|
+
.object({ runId: z.string().uuid() })
|
|
31
|
+
.safeParse(await c.req.json().catch(() => undefined))
|
|
32
|
+
if (!parsed.success) return c.json({ error: 'Invalid discovery request' }, 400)
|
|
33
|
+
await cancelIdeas(parsed.data.runId)
|
|
34
|
+
return c.json({ status: 'done' })
|
|
35
|
+
})
|
|
36
|
+
onboarding.post('/create', async c => {
|
|
37
|
+
const parsed = buildSchema.safeParse(await c.req.json().catch(() => undefined))
|
|
38
|
+
if (!parsed.success) return c.json({ error: 'Invalid workspace request' }, 400)
|
|
39
|
+
const { harness, runId, ideaId, operationId, retry } = parsed.data
|
|
40
|
+
// Use the validated server result, never a browser-supplied workspace plan.
|
|
41
|
+
const discovery = await discoverIdeas({ harness, runId })
|
|
42
|
+
const idea = discovery.ideas?.find(idea => idea.id === ideaId)
|
|
43
|
+
if (discovery.status !== 'done' || !idea)
|
|
44
|
+
return c.json({ error: 'Choose an available idea' }, 409)
|
|
45
|
+
return c.json(await createFromIdea({ harness, operationId, idea }, retry))
|
|
46
|
+
})
|
package/server/app-config.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs'
|
|
2
|
+
import { homedir } from 'node:os'
|
|
2
3
|
import { isAbsolute, join } from 'path'
|
|
3
4
|
|
|
4
|
-
import type { AppEnvironment, ClientAppConfig
|
|
5
|
-
import { EXPERIMENTAL_DEFAULTS } from '@/lib/experimental'
|
|
5
|
+
import type { AppEnvironment, ClientAppConfig } from '@/lib/types'
|
|
6
6
|
|
|
7
7
|
import { DATA_DIR } from './data-dir'
|
|
8
8
|
|
|
@@ -12,17 +12,16 @@ import { DATA_DIR } from './data-dir'
|
|
|
12
12
|
// runtime): config.json describes the deployment itself — nothing here changes
|
|
13
13
|
// without a server restart, and no API writes it.
|
|
14
14
|
//
|
|
15
|
-
// Resolution: defaults < config.json < env.
|
|
16
|
-
// only by explicit CLI flags.
|
|
15
|
+
// Resolution: defaults < config.json < env.
|
|
17
16
|
// A missing file is the normal local case; a malformed file or wrong-typed key
|
|
18
17
|
// warns on stderr and falls back per-key, so a broken config never takes the
|
|
19
18
|
// CLI or server down with it.
|
|
20
19
|
export type AppConfig = {
|
|
21
20
|
environment: AppEnvironment
|
|
21
|
+
collab: boolean
|
|
22
22
|
// Demo mode: workspace creation is blocked (UI shows the
|
|
23
23
|
// cloud-demo promo dialog instead) and `moi` system commands are disabled.
|
|
24
24
|
demo: boolean
|
|
25
|
-
experimental: ExperimentalFeatures
|
|
26
25
|
// Link target for the cloud-demo promo dialog.
|
|
27
26
|
demoInstallUrl: string
|
|
28
27
|
// Cloudflare Access (Zero Trust) in front of this deployment: each viewer
|
|
@@ -47,12 +46,11 @@ export type CloudflareAccessConfig = {
|
|
|
47
46
|
audience: readonly string[]
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
type DeploymentConfig = Omit<AppConfig, 'experimental'>
|
|
51
|
-
|
|
52
49
|
const DEFAULTS: AppConfig = {
|
|
53
50
|
environment: 'local',
|
|
51
|
+
// Temporarily disabled while collaboration is being reconsidered.
|
|
52
|
+
collab: false,
|
|
54
53
|
demo: false,
|
|
55
|
-
experimental: { ...EXPERIMENTAL_DEFAULTS },
|
|
56
54
|
demoInstallUrl: 'https://moi.computer',
|
|
57
55
|
cloudflareAccess: null,
|
|
58
56
|
workspacesDir: null,
|
|
@@ -196,8 +194,8 @@ function readConfigFile(file: string): Record<string, unknown> {
|
|
|
196
194
|
return parsed as Record<string, unknown>
|
|
197
195
|
}
|
|
198
196
|
|
|
199
|
-
function fileValues(raw: Record<string, unknown>): Partial<
|
|
200
|
-
const out: Partial<
|
|
197
|
+
function fileValues(raw: Record<string, unknown>): Partial<AppConfig> {
|
|
198
|
+
const out: Partial<AppConfig> = {}
|
|
201
199
|
const environment = parseEnvironment(raw.environment)
|
|
202
200
|
if (environment !== undefined) out.environment = environment
|
|
203
201
|
if (raw.demo !== undefined) {
|
|
@@ -220,33 +218,28 @@ function fileValues(raw: Record<string, unknown>): Partial<DeploymentConfig> {
|
|
|
220
218
|
// Pure resolver, exported for tests. `getAppConfig` is the cached entrypoint.
|
|
221
219
|
export function loadAppConfig(
|
|
222
220
|
file: string = APP_CONFIG_FILE,
|
|
223
|
-
env: Record<string, string | undefined> = process.env
|
|
224
|
-
cliExperimental: Partial<ExperimentalFeatures> = {}
|
|
221
|
+
env: Record<string, string | undefined> = process.env
|
|
225
222
|
): AppConfig {
|
|
226
223
|
const raw = readConfigFile(file)
|
|
227
224
|
const fromFile = fileValues(raw)
|
|
228
|
-
const fromEnv: Partial<
|
|
225
|
+
const fromEnv: Partial<AppConfig> = {
|
|
229
226
|
environment: parseEnvironment(env.MOI_ENVIRONMENT),
|
|
230
227
|
demo: parseBool(env.MOI_DEMO),
|
|
231
228
|
demoInstallUrl: parseString(env.MOI_DEMO_INSTALL_URL)
|
|
232
229
|
}
|
|
233
230
|
const merged = { ...DEFAULTS, ...fromFile }
|
|
234
|
-
for (const key of Object.keys(fromEnv) as (keyof
|
|
231
|
+
for (const key of Object.keys(fromEnv) as (keyof AppConfig)[]) {
|
|
235
232
|
if (fromEnv[key] === undefined) delete fromEnv[key]
|
|
236
233
|
}
|
|
237
234
|
const cloudflareAccess = resolveCloudflareAccess(raw.cloudflareAccess, env)
|
|
238
|
-
|
|
239
|
-
...DEFAULTS.experimental,
|
|
240
|
-
...cliExperimental
|
|
241
|
-
})
|
|
242
|
-
return Object.freeze({ ...merged, ...fromEnv, cloudflareAccess, experimental })
|
|
235
|
+
return Object.freeze({ ...merged, ...fromEnv, cloudflareAccess })
|
|
243
236
|
}
|
|
244
237
|
|
|
245
238
|
let _config: AppConfig | null = null
|
|
246
239
|
|
|
247
|
-
//
|
|
248
|
-
export function initializeAppConfig(
|
|
249
|
-
_config = loadAppConfig(
|
|
240
|
+
// Resolve deployment settings before importing the web server.
|
|
241
|
+
export function initializeAppConfig(): void {
|
|
242
|
+
_config = loadAppConfig()
|
|
250
243
|
}
|
|
251
244
|
|
|
252
245
|
export function getAppConfig(): AppConfig {
|
|
@@ -254,6 +247,12 @@ export function getAppConfig(): AppConfig {
|
|
|
254
247
|
return _config
|
|
255
248
|
}
|
|
256
249
|
|
|
250
|
+
// Folder for workspaces created from the UI. Managed machines override it
|
|
251
|
+
// with workspacesDir in config.json.
|
|
252
|
+
export function createdWorkspacesRoot(): string {
|
|
253
|
+
return getAppConfig().workspacesDir ?? join(homedir(), 'moi')
|
|
254
|
+
}
|
|
255
|
+
|
|
257
256
|
// Test seam: drop the cached config so the next getAppConfig() re-resolves
|
|
258
257
|
// (tests point MOI_DATA_DIR elsewhere or set MOI_DEMO).
|
|
259
258
|
export function resetAppConfig(): void {
|
|
@@ -263,6 +262,6 @@ export function resetAppConfig(): void {
|
|
|
263
262
|
// The only shape that reaches the browser (GET /api/config). Server-only keys
|
|
264
263
|
// added to AppConfig later stay out unless explicitly forwarded here.
|
|
265
264
|
export function clientAppConfig(): ClientAppConfig {
|
|
266
|
-
const { environment,
|
|
267
|
-
return { environment,
|
|
265
|
+
const { environment, collab, demo, demoInstallUrl } = getAppConfig()
|
|
266
|
+
return { environment, collab, demo, demoInstallUrl }
|
|
268
267
|
}
|