moi-computer 0.13.1-next.1 → 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 -1
- 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 +33 -6
- 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 +15 -9
- package/client/features/account/api.ts +6 -6
- package/client/features/account/profile-actions.ts +5 -7
- 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/members/api.ts +4 -10
- package/client/features/collab/members/hooks.ts +32 -38
- package/client/features/collab/members/store.ts +96 -71
- package/client/features/collab/members/types.ts +5 -3
- package/client/features/collab/presence/client.ts +2 -3
- package/client/features/collab/presence/hooks.tsx +1 -1
- package/client/features/collab/proxy-user.ts +1 -3
- package/client/features/collab/sharing/workspace-members.tsx +0 -8
- package/client/features/dev/chat-states-page.tsx +3 -1
- package/client/features/dev/harness-debug-page.tsx +7 -7
- package/client/features/dev/workspace-setup-mocks.ts +1 -1
- 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 +3 -2
- 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 +22 -20
- 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-th91xfnp.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 -49
- 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/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 -53
- 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 +3 -3
- package/server/collab/skill/index.ts +3 -3
- 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/update.ts +11 -11
- package/server/skills/version.ts +7 -7
- package/server/skills/workspace.ts +13 -11
- package/server/web.ts +11 -8
- 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/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/members/keys.ts +0 -6
- package/client/features/workspace/browser-tab-state.ts +0 -51
- package/client/features/workspace/layout-save.ts +0 -13
- package/dist/chunk-3smkkcfw.js +0 -546
- package/dist/chunk-47h9c2qy.js +0 -2
- package/dist/chunk-8qed2gqp.js +0 -75
- package/dist/chunk-8zy3vesm.js +0 -1
- package/dist/chunk-a47zy276.js +0 -2
- package/dist/chunk-g4c1nte9.css +0 -1
- package/dist/chunk-kcactdr4.js +0 -2
- package/dist/chunk-m8bhx6tw.js +0 -1
- package/dist/chunk-pf19zcrn.js +0 -2
- package/dist/chunk-ygzxah0e.js +0 -1
- package/lib/workspace-types.ts +0 -13
- package/server/workspace-state/legacy-migration.ts +0 -79
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { WorkspaceApiTarget } from '../workspaces/api'
|
|
2
|
+
import { requestWorkspace } from '../workspaces/api'
|
|
1
3
|
import { readdir } from 'node:fs/promises'
|
|
2
4
|
import { join } from 'path'
|
|
3
5
|
|
|
@@ -185,10 +187,10 @@ function extractText(props: unknown): string | undefined {
|
|
|
185
187
|
// them for one image. Ids match with or without the `shape:` prefix (read
|
|
186
188
|
// surfaces them stripped).
|
|
187
189
|
export async function readScratchpadImage(
|
|
188
|
-
|
|
190
|
+
workspace: string | WorkspaceApiTarget,
|
|
189
191
|
id: string
|
|
190
192
|
): Promise<{ src: string } | { error: string }> {
|
|
191
|
-
const { document } = await
|
|
193
|
+
const { document } = await readSnapshot(workspace)
|
|
192
194
|
const store = document?.store
|
|
193
195
|
if (!store || typeof store !== 'object') return { error: `No shape named "${id}"` }
|
|
194
196
|
|
|
@@ -212,12 +214,12 @@ export async function readScratchpadImage(
|
|
|
212
214
|
if (a.typeName === 'asset' && a.id === assetId && typeof a.props?.src === 'string') {
|
|
213
215
|
const fileName = assetSrcFileName(a.props.src)
|
|
214
216
|
if (!fileName) return { src: a.props.src }
|
|
215
|
-
const resolved =
|
|
216
|
-
if (!resolved
|
|
217
|
+
const resolved = await readAsset(workspace, fileName)
|
|
218
|
+
if (!resolved) {
|
|
217
219
|
return { error: `Image "${id}" file is missing from .moi/.scratchpad` }
|
|
218
220
|
}
|
|
219
|
-
const bytes = Buffer.from(await resolved.
|
|
220
|
-
return { src: `data:${resolved.
|
|
221
|
+
const bytes = Buffer.from(await resolved.arrayBuffer())
|
|
222
|
+
return { src: `data:${resolved.type};base64,${bytes.toString('base64')}` }
|
|
221
223
|
}
|
|
222
224
|
}
|
|
223
225
|
return { error: `Image "${id}" has no stored data` }
|
|
@@ -225,8 +227,10 @@ export async function readScratchpadImage(
|
|
|
225
227
|
|
|
226
228
|
// no browser needed. Ids are reported without tldraw's `shape:` prefix so they
|
|
227
229
|
// round-trip with `createShapeId(name)` on the draw side.
|
|
228
|
-
export async function readScratchpadShapes(
|
|
229
|
-
|
|
230
|
+
export async function readScratchpadShapes(
|
|
231
|
+
workspace: string | WorkspaceApiTarget
|
|
232
|
+
): Promise<ScratchShape[]> {
|
|
233
|
+
const { document } = await readSnapshot(workspace)
|
|
230
234
|
const store = document?.store
|
|
231
235
|
if (!store || typeof store !== 'object') return []
|
|
232
236
|
|
|
@@ -244,10 +248,7 @@ export async function readScratchpadShapes(workspacePath: string): Promise<Scrat
|
|
|
244
248
|
if (typeof a.props?.src === 'string') {
|
|
245
249
|
assetSrc.set(a.id, a.props.src)
|
|
246
250
|
const fileName = assetSrcFileName(a.props.src)
|
|
247
|
-
if (fileName)
|
|
248
|
-
const resolved = scratchpadAssetFile(workspacePath, fileName)
|
|
249
|
-
if (!resolved || !(await resolved.file.exists())) assetGone.add(a.id)
|
|
250
|
-
}
|
|
251
|
+
if (fileName && !(await readAsset(workspace, fileName))) assetGone.add(a.id)
|
|
251
252
|
}
|
|
252
253
|
}
|
|
253
254
|
|
|
@@ -289,3 +290,22 @@ export async function readScratchpadShapes(workspacePath: string): Promise<Scrat
|
|
|
289
290
|
}
|
|
290
291
|
return shapes
|
|
291
292
|
}
|
|
293
|
+
|
|
294
|
+
async function readSnapshot(workspace: string | WorkspaceApiTarget): Promise<ScratchpadSnapshot> {
|
|
295
|
+
return typeof workspace === 'string'
|
|
296
|
+
? loadScratchpadDoc(workspace)
|
|
297
|
+
: (await requestWorkspace(workspace, '/scratchpad')).json()
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async function readAsset(
|
|
301
|
+
workspace: string | WorkspaceApiTarget,
|
|
302
|
+
fileName: string
|
|
303
|
+
): Promise<Blob | undefined> {
|
|
304
|
+
if (typeof workspace !== 'string')
|
|
305
|
+
return (
|
|
306
|
+
await requestWorkspace(workspace, `/scratchpad/assets/${encodeURIComponent(fileName)}`)
|
|
307
|
+
).blob()
|
|
308
|
+
const asset = scratchpadAssetFile(workspace, fileName)
|
|
309
|
+
if (!asset || !(await asset.file.exists())) return undefined
|
|
310
|
+
return asset.file.slice(0, asset.file.size, asset.mimeType)
|
|
311
|
+
}
|
|
@@ -231,11 +231,12 @@ const MAX_IMAGE_BYTES = 50 * 1024 * 1024
|
|
|
231
231
|
|
|
232
232
|
async function processCanvasImage(
|
|
233
233
|
path: string,
|
|
234
|
-
quality: ScratchImageQuality
|
|
234
|
+
quality: ScratchImageQuality,
|
|
235
|
+
imageBytes?: Uint8Array
|
|
235
236
|
): Promise<{ data: Buffer; w: number; h: number; mimeType: string; name: string }> {
|
|
236
237
|
const file = Bun.file(path)
|
|
237
|
-
if (!(await file.exists())) throw new Error(`Image file not found: ${path}`)
|
|
238
|
-
const bytes = new Uint8Array(await file.arrayBuffer())
|
|
238
|
+
if (!imageBytes && !(await file.exists())) throw new Error(`Image file not found: ${path}`)
|
|
239
|
+
const bytes = imageBytes ?? new Uint8Array(await file.arrayBuffer())
|
|
239
240
|
if (bytes.length === 0) throw new Error(`Image file is empty: ${path}`)
|
|
240
241
|
if (bytes.length > MAX_IMAGE_BYTES) {
|
|
241
242
|
throw new Error(`Image is too large (${Math.round(bytes.length / 1e6)}MB, max 50MB): ${path}`)
|
|
@@ -256,7 +257,8 @@ async function processCanvasImage(
|
|
|
256
257
|
async function applyAddImage(
|
|
257
258
|
store: HeadlessStore,
|
|
258
259
|
workspacePath: string,
|
|
259
|
-
op: Extract<ScratchOp, { kind: 'add-image' }
|
|
260
|
+
op: Extract<ScratchOp, { kind: 'add-image' }>,
|
|
261
|
+
imageBytes?: Uint8Array
|
|
260
262
|
): Promise<ScratchOpResult> {
|
|
261
263
|
const pageId = firstPageId(store)
|
|
262
264
|
// Re-adding under an existing id replaces that shape; note its current asset so
|
|
@@ -265,7 +267,11 @@ async function applyAddImage(
|
|
|
265
267
|
| { props?: { assetId?: unknown } }
|
|
266
268
|
| undefined
|
|
267
269
|
const prevAssetId = typeof prev?.props?.assetId === 'string' ? prev.props.assetId : undefined
|
|
268
|
-
const { data, w, h, mimeType, name } = await processCanvasImage(
|
|
270
|
+
const { data, w, h, mimeType, name } = await processCanvasImage(
|
|
271
|
+
op.path,
|
|
272
|
+
op.quality ?? 'lo',
|
|
273
|
+
imageBytes
|
|
274
|
+
)
|
|
269
275
|
const { src } = await storeScratchpadAsset(workspacePath, data, mimeType)
|
|
270
276
|
const assetId = AssetRecordType.createId()
|
|
271
277
|
store.put([
|
|
@@ -474,14 +480,17 @@ function withLock<T>(key: string, fn: () => Promise<T>): Promise<T> {
|
|
|
474
480
|
export function executeScratchOp(
|
|
475
481
|
workspacePath: string,
|
|
476
482
|
workspaceId: string,
|
|
477
|
-
op: ScratchOp
|
|
483
|
+
op: ScratchOp,
|
|
484
|
+
imageBytes?: Uint8Array
|
|
478
485
|
): Promise<ScratchOpResult> {
|
|
479
486
|
return withLock(workspacePath, async () => {
|
|
480
487
|
const { document, writer } = await loadScratchpadDoc(workspacePath)
|
|
481
488
|
const store = buildStore(document, writer)
|
|
482
489
|
// add-image decodes/resizes the file first, so it's the one async op.
|
|
483
490
|
const result =
|
|
484
|
-
op.kind === 'add-image'
|
|
491
|
+
op.kind === 'add-image'
|
|
492
|
+
? await applyAddImage(store, workspacePath, op, imageBytes)
|
|
493
|
+
: applyOp(store, op)
|
|
485
494
|
const next = store.getStoreSnapshot() as unknown as ScratchpadDoc
|
|
486
495
|
await saveScratchpadDoc(next, workspacePath)
|
|
487
496
|
publishEvent({ type: 'scratchpad:updated', workspaceId })
|
|
@@ -21,22 +21,25 @@ export async function hasSessionConfig(ws: WorkspaceRef, sessionId: string): Pro
|
|
|
21
21
|
return Object.keys(await getSessionConfig(ws, sessionId)).length > 0
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
// Without a session id, update the personal defaults used by new chats.
|
|
24
25
|
export async function saveSessionConfig(
|
|
25
26
|
ws: WorkspaceRef,
|
|
26
|
-
sessionId: string,
|
|
27
|
+
sessionId: string | undefined,
|
|
27
28
|
patch: SessionConfigPatch
|
|
28
29
|
): Promise<SessionConfig> {
|
|
29
30
|
return updateWorkspaceState(ws, state => {
|
|
30
|
-
const session = (state.sessions[sessionId] ??= {})
|
|
31
|
-
const config: SessionConfig = { ...session.config }
|
|
31
|
+
const session = sessionId ? (state.sessions[sessionId] ??= {}) : undefined
|
|
32
|
+
const config: SessionConfig = { ...(session ? session.config : state.chatDefaults) }
|
|
32
33
|
for (const key of ['model', 'effort', 'speedMode'] as const) {
|
|
33
34
|
if (patch[key] === null) delete config[key]
|
|
34
35
|
}
|
|
35
36
|
if (typeof patch.model === 'string') config.model = patch.model
|
|
36
37
|
if (typeof patch.effort === 'string') config.effort = patch.effort
|
|
37
38
|
if (isSpeedMode(patch.speedMode)) config.speedMode = patch.speedMode
|
|
38
|
-
if (
|
|
39
|
-
|
|
39
|
+
if (session) {
|
|
40
|
+
if (Object.keys(config).length) session.config = config
|
|
41
|
+
else delete session.config
|
|
42
|
+
} else state.chatDefaults = config
|
|
40
43
|
return config
|
|
41
44
|
})
|
|
42
45
|
}
|
|
@@ -2,6 +2,7 @@ import { isIdentityIconId } from '@/lib/identity-icons'
|
|
|
2
2
|
import { newViewId } from '@/lib/ids'
|
|
3
3
|
import type { PendingView, WorkspaceEntry, WorkspaceState } from '@/lib/types'
|
|
4
4
|
import { readWorkspaceState, updateWorkspaceState, type WorkspaceRef } from '../workspace-state'
|
|
5
|
+
import { requestWorkspace } from '../workspaces/api'
|
|
5
6
|
import { archiveViewSessions } from './archive'
|
|
6
7
|
|
|
7
8
|
export class PendingViewError extends Error {
|
|
@@ -108,6 +109,21 @@ export async function completeViewBuild(ws: WorkspaceRef, id: string) {
|
|
|
108
109
|
})
|
|
109
110
|
}
|
|
110
111
|
|
|
112
|
+
// A remote view compiles on its owner, which cannot reach this Moi's state. The
|
|
113
|
+
// visitor's CLI calls this after a build to clear the views the owner now lists.
|
|
114
|
+
export async function completeRemoteViewBuilds(ws: WorkspaceEntry, request = requestWorkspace) {
|
|
115
|
+
if (!ws.remote) return
|
|
116
|
+
if (!Object.keys((await readWorkspaceState(ws)).pendingViews).length) return
|
|
117
|
+
const response = await request({ remote: ws.remote }, '/views', { method: 'GET' })
|
|
118
|
+
if (!response.ok) throw new Error(`Could not list the owner's views (${response.status})`)
|
|
119
|
+
const { views } = (await response.json()) as { views: { id: string }[] }
|
|
120
|
+
const compiled = new Set(views.map(view => view.id))
|
|
121
|
+
await updateWorkspaceState(ws, state => {
|
|
122
|
+
for (const id of Object.keys(state.pendingViews))
|
|
123
|
+
if (compiled.has(id)) delete state.pendingViews[id]
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
111
127
|
// Follow a temporary id's rename in every build that runs in it.
|
|
112
128
|
export function renameBuildSession(state: WorkspaceState, from: string, to: string): void {
|
|
113
129
|
for (const view of Object.values(state.pendingViews)) {
|
|
@@ -2,7 +2,7 @@ import { HarnessTransitionError, reserveWorkspaceOperation } from '../workspaces
|
|
|
2
2
|
import { IDENTITY_ICON_IDS } from '@/lib/identity-icons'
|
|
3
3
|
import { viewBuildDirectives } from '@/lib/view-build-directives'
|
|
4
4
|
import { viewIdFromTab, viewTabId } from '@/lib/workspace-tabs'
|
|
5
|
-
import type { PendingView,
|
|
5
|
+
import type { PendingView, WorkspaceEntry, WorkspaceTabId } from '@/lib/types'
|
|
6
6
|
import { getCollabReferencePath } from '../collab/config'
|
|
7
7
|
import { harnessFor } from '../harness/registry'
|
|
8
8
|
import type { SendMessageInput } from '../harness/types'
|
|
@@ -37,23 +37,23 @@ export class ViewStartupError extends Error {
|
|
|
37
37
|
type BuildSendOptions = Pick<
|
|
38
38
|
SendMessageInput,
|
|
39
39
|
'attachments' | 'optimisticId' | 'model' | 'effort' | 'speedMode' | 'stream'
|
|
40
|
-
>
|
|
40
|
+
>
|
|
41
41
|
export type SubmitViewInput = BuildSendOptions & { requirements: string; sessionId?: string }
|
|
42
42
|
|
|
43
43
|
// Both ordinary chat and initial build requests use this boundary.
|
|
44
44
|
export async function sendWorkspaceMessage(
|
|
45
45
|
ws: WorkspaceEntry,
|
|
46
|
-
input: SendMessageInput & {
|
|
46
|
+
input: SendMessageInput & { viewBuildId?: string }
|
|
47
47
|
) {
|
|
48
48
|
const release = reserveWorkspaceOperation(ws.id)
|
|
49
49
|
try {
|
|
50
50
|
const { getWorkspace } = await import('../workspaces/registry')
|
|
51
51
|
const current = await getWorkspace(ws.id)
|
|
52
|
-
if (current && (current.
|
|
52
|
+
if (current && (current.harness ?? 'claude-code') !== (ws.harness ?? 'claude-code'))
|
|
53
53
|
throw new HarnessTransitionError('Agent changed. Start a new chat')
|
|
54
54
|
const { prepareWorkspaceHarness } = await import('../workspaces/change-harness')
|
|
55
55
|
await prepareWorkspaceHarness(ws)
|
|
56
|
-
const {
|
|
56
|
+
const { viewBuildId, ...message } = input
|
|
57
57
|
const sessionId = resolveRenamedSession(ws.id, input.sessionId)
|
|
58
58
|
const record = await getSessionEntry(ws, sessionId)
|
|
59
59
|
const tabId = input.context?.activeTab?.id ?? record.tabId ?? 'overview'
|
|
@@ -79,13 +79,13 @@ export async function sendWorkspaceMessage(
|
|
|
79
79
|
throw new PendingViewError('This view is already being built in another chat', 409)
|
|
80
80
|
if (input.isNew && record.tabId !== tabId) {
|
|
81
81
|
record.tabId = tabId === 'overview' ? undefined : tabId
|
|
82
|
-
await attachSession(ws, tabId, sessionId, null
|
|
82
|
+
await attachSession(ws, tabId, sessionId, null)
|
|
83
83
|
}
|
|
84
84
|
if (isBuildRequest)
|
|
85
85
|
await patchPendingView(ws, pending.id, {
|
|
86
86
|
buildSessionId: sessionId
|
|
87
87
|
})
|
|
88
|
-
const collabReference = await getCollabReferencePath(ws.path, ws.
|
|
88
|
+
const collabReference = await getCollabReferencePath(ws.path, ws.harness)
|
|
89
89
|
const pinnedSessionId = await getPinnedSession(ws)
|
|
90
90
|
await harnessFor(ws).sendMessage({
|
|
91
91
|
...message,
|
|
@@ -126,11 +126,10 @@ async function attachSession(
|
|
|
126
126
|
ws: WorkspaceEntry,
|
|
127
127
|
tabId: WorkspaceTabId,
|
|
128
128
|
sessionId: string,
|
|
129
|
-
ifMatch?: string | null
|
|
130
|
-
selectedSessionScope: SelectedSessionScope = 'shared'
|
|
129
|
+
ifMatch?: string | null
|
|
131
130
|
) {
|
|
132
131
|
await updateSessionEntry(ws, sessionId, { tabId: tabId === 'overview' ? undefined : tabId })
|
|
133
|
-
|
|
132
|
+
await saveSelectedSession(ws, sessionId, tabId, ifMatch)
|
|
134
133
|
}
|
|
135
134
|
async function sendBuild(
|
|
136
135
|
ws: WorkspaceEntry,
|
|
@@ -176,7 +175,6 @@ async function failStartup(
|
|
|
176
175
|
|
|
177
176
|
export async function submitView(ws: WorkspaceEntry, viewId: string, input: SubmitViewInput) {
|
|
178
177
|
const tabId = viewTabId(viewId)
|
|
179
|
-
const shared = (input.selectedSessionScope ?? 'shared') === 'shared'
|
|
180
178
|
// The build, the chat's tab and the tab's selection start in one write. A
|
|
181
179
|
// pinned chat takes the build and keeps its own tab.
|
|
182
180
|
const { view, sessionId, pinned } = await updateWorkspaceState(ws, state => {
|
|
@@ -191,7 +189,7 @@ export async function submitView(ws: WorkspaceEntry, viewId: string, input: Subm
|
|
|
191
189
|
)
|
|
192
190
|
if (!pinned) {
|
|
193
191
|
setSessionTab(state, sessionId, tabId)
|
|
194
|
-
|
|
192
|
+
selectSessionForTab(state, ws.id, sessionId, tabId)
|
|
195
193
|
}
|
|
196
194
|
return { view, sessionId, pinned }
|
|
197
195
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { lstat, realpath } from 'node:fs/promises'
|
|
2
2
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { HarnessType } from '@/lib/types'
|
|
5
5
|
|
|
6
6
|
import { skillsDirFor } from '../workspaces/init'
|
|
7
7
|
import { bundledSkillNames } from './template'
|
|
@@ -47,10 +47,10 @@ async function inspectDirectory(path: string): Promise<SkillDirectory> {
|
|
|
47
47
|
// their primary destination and include existing Claude/Codex installations.
|
|
48
48
|
export async function resolveSkillLocations(
|
|
49
49
|
workspaceRoot: string,
|
|
50
|
-
|
|
50
|
+
harness?: HarnessType
|
|
51
51
|
): Promise<SkillLocation[]> {
|
|
52
52
|
const root = resolve(workspaceRoot)
|
|
53
|
-
const primary = resolve(skillsDirFor(root,
|
|
53
|
+
const primary = resolve(skillsDirFor(root, harness))
|
|
54
54
|
const directories = [
|
|
55
55
|
...new Set([primary, join(root, '.claude', 'skills'), join(root, '.agents', 'skills')])
|
|
56
56
|
]
|
|
@@ -61,7 +61,7 @@ export async function resolveSkillLocations(
|
|
|
61
61
|
try {
|
|
62
62
|
const inspected = await inspectDirectory(path)
|
|
63
63
|
if (
|
|
64
|
-
usesSharedWorkspaceSkill(
|
|
64
|
+
usesSharedWorkspaceSkill(harness) ||
|
|
65
65
|
directory === primary ||
|
|
66
66
|
inspected.exists ||
|
|
67
67
|
inspected.brokenLink
|
package/server/skills/update.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { basename } from 'node:path'
|
|
2
2
|
|
|
3
|
-
import type { WorkspaceSkillsStatus, WorkspaceSkillStatus,
|
|
3
|
+
import type { WorkspaceSkillsStatus, WorkspaceSkillStatus, HarnessType } from '@/lib/types'
|
|
4
4
|
|
|
5
5
|
import type { AppletDeclarationFile } from '../applets/declarations'
|
|
6
6
|
import { syncAppletDeclarations } from '../applets/declarations'
|
|
@@ -31,29 +31,29 @@ export function summarizeSkillStatuses(skills: WorkspaceSkillStatus[]): Workspac
|
|
|
31
31
|
|
|
32
32
|
export async function getWorkspaceSkillsStatus(
|
|
33
33
|
workspaceRoot: string,
|
|
34
|
-
|
|
34
|
+
harness?: HarnessType
|
|
35
35
|
): Promise<WorkspaceSkillsStatus> {
|
|
36
|
-
return summarizeSkillStatuses(await skillStatuses(workspaceRoot,
|
|
36
|
+
return summarizeSkillStatuses(await skillStatuses(workspaceRoot, harness))
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export async function updateWorkspaceSkills(
|
|
40
40
|
workspaceRoot: string,
|
|
41
|
-
|
|
41
|
+
harness: HarnessType = 'claude-code'
|
|
42
42
|
): Promise<WorkspaceSkillUpdateResult> {
|
|
43
|
-
return withSkillLock(workspaceSkillLockPath(workspaceRoot,
|
|
44
|
-
updateWorkspaceSkillFiles(workspaceRoot,
|
|
43
|
+
return withSkillLock(workspaceSkillLockPath(workspaceRoot, harness), () =>
|
|
44
|
+
updateWorkspaceSkillFiles(workspaceRoot, harness)
|
|
45
45
|
)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
async function updateWorkspaceSkillFiles(
|
|
49
49
|
workspaceRoot: string,
|
|
50
|
-
|
|
50
|
+
harness: HarnessType
|
|
51
51
|
): Promise<WorkspaceSkillUpdateResult> {
|
|
52
|
-
const locations = await resolveSkillLocations(workspaceRoot,
|
|
52
|
+
const locations = await resolveSkillLocations(workspaceRoot, harness)
|
|
53
53
|
const before = await skillStatusesForLocations(locations)
|
|
54
54
|
let changedSkillPaths: string[]
|
|
55
|
-
if (usesSharedWorkspaceSkill(
|
|
56
|
-
changedSkillPaths = await installWorkspaceSkillFiles(workspaceRoot,
|
|
55
|
+
if (usesSharedWorkspaceSkill(harness)) {
|
|
56
|
+
changedSkillPaths = await installWorkspaceSkillFiles(workspaceRoot, harness)
|
|
57
57
|
} else {
|
|
58
58
|
for (const location of locations) {
|
|
59
59
|
if (location.brokenLink) {
|
|
@@ -82,7 +82,7 @@ async function updateWorkspaceSkillFiles(
|
|
|
82
82
|
// Applet declarations ship with the CLI, so refresh installed copies along
|
|
83
83
|
// with skills.
|
|
84
84
|
const updatedAppletTypes = await syncAppletDeclarations(workspaceRoot)
|
|
85
|
-
const skills = await skillStatuses(workspaceRoot,
|
|
85
|
+
const skills = await skillStatuses(workspaceRoot, harness)
|
|
86
86
|
|
|
87
87
|
return {
|
|
88
88
|
before,
|
package/server/skills/version.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// drives both the CLI status and the frontend's automatic update check.
|
|
4
4
|
import { join } from 'node:path'
|
|
5
5
|
|
|
6
|
-
import type { WorkspaceSkillStatus,
|
|
6
|
+
import type { WorkspaceSkillStatus, HarnessType } from '@/lib/types'
|
|
7
7
|
|
|
8
8
|
import { findWorkspaceForPath, liftToWorkspaceRoot, listWorkspaces } from '../workspaces/registry'
|
|
9
9
|
import { bundledSkillDirectory } from './template'
|
|
@@ -74,9 +74,9 @@ export const isBehind = (installed: string | null, bundled: string | null): bool
|
|
|
74
74
|
// Report every installed copy, plus the required primary harness destination.
|
|
75
75
|
export async function skillStatuses(
|
|
76
76
|
workspaceRoot: string,
|
|
77
|
-
|
|
77
|
+
harness?: HarnessType
|
|
78
78
|
): Promise<WorkspaceSkillStatus[]> {
|
|
79
|
-
return skillStatusesForLocations(await resolveSkillLocations(workspaceRoot,
|
|
79
|
+
return skillStatusesForLocations(await resolveSkillLocations(workspaceRoot, harness))
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
export async function skillStatusesForLocations(
|
|
@@ -92,7 +92,7 @@ export async function skillStatusesForLocations(
|
|
|
92
92
|
)
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
export type ResolvedWorkspace = { root: string;
|
|
95
|
+
export type ResolvedWorkspace = { root: string; harness?: HarnessType }
|
|
96
96
|
|
|
97
97
|
// Resolve a path to its workspace root: the registered workspace that owns it
|
|
98
98
|
// (carrying its backend type), else lifted out of any `.moi/`, else the path
|
|
@@ -100,7 +100,7 @@ export type ResolvedWorkspace = { root: string; type?: WorkspaceType }
|
|
|
100
100
|
// the same places.
|
|
101
101
|
export async function resolveWorkspace(cwd: string): Promise<ResolvedWorkspace> {
|
|
102
102
|
const ws = findWorkspaceForPath(await listWorkspaces(), cwd)
|
|
103
|
-
if (ws) return { root: ws.path,
|
|
103
|
+
if (ws) return { root: ws.path, harness: ws.harness }
|
|
104
104
|
return { root: liftToWorkspaceRoot(cwd) }
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -114,8 +114,8 @@ export async function resolveWorkspaceRoot(cwd: string): Promise<string> {
|
|
|
114
114
|
// version checks must not break the command they ride on.
|
|
115
115
|
export async function staleSkillNotice(cwd: string): Promise<string | null> {
|
|
116
116
|
try {
|
|
117
|
-
const { root,
|
|
118
|
-
const stale = (await skillStatuses(root,
|
|
117
|
+
const { root, harness } = await resolveWorkspace(cwd)
|
|
118
|
+
const stale = (await skillStatuses(root, harness)).filter(s =>
|
|
119
119
|
isMinorBehind(s.installed, s.bundled)
|
|
120
120
|
)
|
|
121
121
|
if (stale.length === 0) return null
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { lstat, mkdir, mkdtemp, readlink, realpath, rename, rm, symlink } from 'node:fs/promises'
|
|
2
2
|
import { dirname, join, relative, resolve } from 'node:path'
|
|
3
3
|
|
|
4
|
-
import type {
|
|
4
|
+
import type { HarnessType } from '@/lib/types'
|
|
5
5
|
|
|
6
6
|
import { installBundledSkill, installBundledSkills, matchesBundledSkill } from './template'
|
|
7
7
|
import { skillsDirFor } from '../workspaces/init'
|
|
@@ -9,8 +9,8 @@ import { withSkillLock } from './lock'
|
|
|
9
9
|
|
|
10
10
|
const SKILL_NAME = 'moi-workspace'
|
|
11
11
|
|
|
12
|
-
export function usesSharedWorkspaceSkill(
|
|
13
|
-
return
|
|
12
|
+
export function usesSharedWorkspaceSkill(harness?: HarnessType): boolean {
|
|
13
|
+
return harness === undefined || harness === 'claude-code' || harness === 'codex'
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
async function entryAt(path: string) {
|
|
@@ -31,24 +31,26 @@ async function checkSkillsDirectory(path: string): Promise<void> {
|
|
|
31
31
|
|
|
32
32
|
export async function installWorkspaceSkills(
|
|
33
33
|
root: string,
|
|
34
|
-
|
|
34
|
+
harness?: HarnessType
|
|
35
35
|
): Promise<string[]> {
|
|
36
|
-
return withSkillLock(workspaceSkillLockPath(root,
|
|
37
|
-
installWorkspaceSkillFiles(root,
|
|
36
|
+
return withSkillLock(workspaceSkillLockPath(root, harness), () =>
|
|
37
|
+
installWorkspaceSkillFiles(root, harness)
|
|
38
38
|
)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export function workspaceSkillLockPath(root: string,
|
|
42
|
-
return usesSharedWorkspaceSkill(
|
|
41
|
+
export function workspaceSkillLockPath(root: string, harness?: HarnessType): string {
|
|
42
|
+
return usesSharedWorkspaceSkill(harness)
|
|
43
|
+
? join(root, '.agents', 'skills')
|
|
44
|
+
: skillsDirFor(root, harness)
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
// Callers must hold the workspace skill lock across any surrounding status reads.
|
|
46
48
|
export async function installWorkspaceSkillFiles(
|
|
47
49
|
root: string,
|
|
48
|
-
|
|
50
|
+
harness?: HarnessType
|
|
49
51
|
): Promise<string[]> {
|
|
50
|
-
if (usesSharedWorkspaceSkill(
|
|
51
|
-
const directory = skillsDirFor(root,
|
|
52
|
+
if (usesSharedWorkspaceSkill(harness)) return resetWorkspaceSkill(root)
|
|
53
|
+
const directory = skillsDirFor(root, harness)
|
|
52
54
|
return (await installBundledSkills(directory)).map(name => join(directory, name))
|
|
53
55
|
}
|
|
54
56
|
|
package/server/web.ts
CHANGED
|
@@ -5,6 +5,8 @@ import type { ClientMessage, StatusSnapshotMessage } from '@/lib/types'
|
|
|
5
5
|
import { isMoiContext } from '@/lib/moi-context'
|
|
6
6
|
|
|
7
7
|
import { rm } from 'node:fs/promises'
|
|
8
|
+
import { dirname, join } from 'node:path'
|
|
9
|
+
import { startOperations, stopOperations } from './operations/server'
|
|
8
10
|
|
|
9
11
|
import index from '../client/index.html'
|
|
10
12
|
import devSandbox from '../client/dev/index.html'
|
|
@@ -25,7 +27,6 @@ import { allHarnesses, harnessFor } from './harness/registry'
|
|
|
25
27
|
import { getWorkspace, listWorkspaces } from './workspaces/registry'
|
|
26
28
|
import { failInterruptedViewStarts, sendWorkspaceMessage } from './sessions/view-sessions'
|
|
27
29
|
import { prepareWorkspaceStates } from './workspace-state'
|
|
28
|
-
import { migrateLegacyWorkspaceState } from './workspace-state/legacy-migration'
|
|
29
30
|
import {
|
|
30
31
|
addClient,
|
|
31
32
|
broadcast,
|
|
@@ -55,7 +56,6 @@ function isClientMessage(value: unknown): value is ClientMessage {
|
|
|
55
56
|
sessionId?: unknown
|
|
56
57
|
content?: unknown
|
|
57
58
|
isNew?: unknown
|
|
58
|
-
selectedSessionScope?: unknown
|
|
59
59
|
optimisticId?: unknown
|
|
60
60
|
model?: unknown
|
|
61
61
|
effort?: unknown
|
|
@@ -71,9 +71,6 @@ function isClientMessage(value: unknown): value is ClientMessage {
|
|
|
71
71
|
typeof v.content === 'string' &&
|
|
72
72
|
typeof v.sessionId === 'string' &&
|
|
73
73
|
typeof v.isNew === 'boolean' &&
|
|
74
|
-
(v.selectedSessionScope === undefined ||
|
|
75
|
-
v.selectedSessionScope === 'shared' ||
|
|
76
|
-
v.selectedSessionScope === 'browser-tab') &&
|
|
77
74
|
(v.optimisticId === undefined || typeof v.optimisticId === 'string') &&
|
|
78
75
|
(v.model === undefined || typeof v.model === 'string') &&
|
|
79
76
|
(v.effort === undefined || typeof v.effort === 'string') &&
|
|
@@ -111,7 +108,6 @@ function upgrade(server: Upgradable, req: Request, data: WsData) {
|
|
|
111
108
|
// WebSocket channels (which need Bun's native `server.upgrade` + pub/sub). Every
|
|
112
109
|
// HTTP API route is delegated to the Hono app (`./api`) via `fetch`.
|
|
113
110
|
const registeredWorkspaces = await listWorkspaces()
|
|
114
|
-
await migrateLegacyWorkspaceState(registeredWorkspaces)
|
|
115
111
|
await prepareWorkspaceStates(registeredWorkspaces)
|
|
116
112
|
await Promise.all(registeredWorkspaces.map(failInterruptedViewStarts))
|
|
117
113
|
|
|
@@ -125,6 +121,10 @@ const listen = unixSocket
|
|
|
125
121
|
? { unix: unixSocket }
|
|
126
122
|
: { port: PORT, hostname: process.env.HOST ?? '127.0.0.1' }
|
|
127
123
|
|
|
124
|
+
const operations = unixSocket
|
|
125
|
+
? await startOperations(join(dirname(unixSocket), 'ops.sock'))
|
|
126
|
+
: undefined
|
|
127
|
+
|
|
128
128
|
export const app = Bun.serve<WsData>({
|
|
129
129
|
// Bun types the port and Unix-socket listeners as separate overloads, so a
|
|
130
130
|
// listener picked at runtime is cast to one of them; the runtime takes either.
|
|
@@ -153,6 +153,8 @@ export const app = Bun.serve<WsData>({
|
|
|
153
153
|
|
|
154
154
|
// Client-side routes — serve the SPA shell.
|
|
155
155
|
'/': shell,
|
|
156
|
+
// Demo serves home at /demo (see homePath in client/api/app-config.ts).
|
|
157
|
+
...(getAppConfig().demo ? { '/demo': shell } : {}),
|
|
156
158
|
'/dev': shell,
|
|
157
159
|
'/dev/*': shell,
|
|
158
160
|
// Isolated sandboxes bypass app startup and share the client/dev entry point.
|
|
@@ -174,7 +176,7 @@ export const app = Bun.serve<WsData>({
|
|
|
174
176
|
'/api/workspaces/ws': (req: Request, server: Bun.Server<WsData>) =>
|
|
175
177
|
upgrade(server, req, { channel: 'events', workspaceId: '' }),
|
|
176
178
|
|
|
177
|
-
'/api/workspaces/:id/collab
|
|
179
|
+
'/api/workspaces/:id/collab': async (req: Request, server: Bun.Server<WsData>) => {
|
|
178
180
|
const workspaceId = decodeURIComponent(new URL(req.url).pathname.split('/')[3] ?? '')
|
|
179
181
|
const workspace = await getWorkspace(workspaceId)
|
|
180
182
|
if (!workspace) return new Response('Workspace not found', { status: 404 })
|
|
@@ -246,7 +248,6 @@ export const app = Bun.serve<WsData>({
|
|
|
246
248
|
workspacePath: workspace.path,
|
|
247
249
|
sessionId: data.sessionId,
|
|
248
250
|
isNew: data.isNew,
|
|
249
|
-
selectedSessionScope: data.selectedSessionScope,
|
|
250
251
|
content: data.content.trim(),
|
|
251
252
|
attachments: data.attachments,
|
|
252
253
|
optimisticId: data.optimisticId,
|
|
@@ -321,6 +322,8 @@ async function shutdown() {
|
|
|
321
322
|
shuttingDown = true
|
|
322
323
|
try {
|
|
323
324
|
app.stop(true)
|
|
325
|
+
operations?.stop(true)
|
|
326
|
+
stopOperations()
|
|
324
327
|
} catch {}
|
|
325
328
|
try {
|
|
326
329
|
control.stop(true)
|
|
@@ -97,6 +97,8 @@ export function normalizeWorkspaceState(
|
|
|
97
97
|
const state = emptyWorkspaceState(optionalString(value.workspacePath) ?? workspacePath)
|
|
98
98
|
if (typeof value.revision === 'number' && Number.isSafeInteger(value.revision))
|
|
99
99
|
state.revision = value.revision
|
|
100
|
+
if (isRecord(value.chatDefaults))
|
|
101
|
+
state.chatDefaults = normalizeSession({ config: value.chatDefaults }).config ?? {}
|
|
100
102
|
const pinned = optionalString(value.pinnedSessionId)
|
|
101
103
|
if (pinned) state.pinnedSessionId = pinned
|
|
102
104
|
if (isRecord(value.selected)) {
|
|
@@ -104,10 +104,6 @@ export async function updateWorkspaceState<T>(
|
|
|
104
104
|
})
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
export function hasWorkspaceState(workspaceId: string): boolean {
|
|
108
|
-
return existsSync(statePath(workspaceId))
|
|
109
|
-
}
|
|
110
|
-
|
|
111
107
|
async function listStateIds(): Promise<string[]> {
|
|
112
108
|
try {
|
|
113
109
|
const entries = await readdir(root, { withFileTypes: true })
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RemoteWorkspaceTarget } from '@/lib/workspace-config'
|
|
2
|
+
import { workspaceRequest } from '../remote/client'
|
|
3
|
+
|
|
4
|
+
export type WorkspaceApiTarget = { remote: RemoteWorkspaceTarget }
|
|
5
|
+
|
|
6
|
+
// CLI requests for a linked folder's shared content go to the owner's workspace API.
|
|
7
|
+
// Local workspaces never come through here; their handlers read the folder directly.
|
|
8
|
+
export async function requestWorkspace(
|
|
9
|
+
workspace: WorkspaceApiTarget,
|
|
10
|
+
path: string,
|
|
11
|
+
init?: RequestInit
|
|
12
|
+
): Promise<Response> {
|
|
13
|
+
const { remote } = workspace
|
|
14
|
+
// Serialize multipart bodies once so the signature and content type match the bytes sent.
|
|
15
|
+
const payload = new Request('http://workspace.local', {
|
|
16
|
+
method: init?.method ?? 'POST',
|
|
17
|
+
body: init?.body,
|
|
18
|
+
headers: init?.headers
|
|
19
|
+
})
|
|
20
|
+
// Bun materializes multipart headers lazily; read the boundary before consuming the body.
|
|
21
|
+
const contentType = payload.headers.get('content-type') ?? undefined
|
|
22
|
+
return workspaceRequest(remote.user_id, remote.workspace_id, path, {
|
|
23
|
+
method: init?.method,
|
|
24
|
+
body: init?.body == null ? undefined : new Uint8Array(await payload.arrayBuffer()),
|
|
25
|
+
signal: init?.signal ?? undefined,
|
|
26
|
+
contentType
|
|
27
|
+
})
|
|
28
|
+
}
|