moi-computer 0.12.0 → 0.12.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/client/AGENTS.md +2 -2
- package/client/api/app-ui-keys.ts +1 -1
- package/client/api/workspace-keys.ts +1 -3
- package/client/app/routes/WorkspaceRoute.tsx +2 -8
- package/client/features/applets/applet-runtime.ts +11 -13
- package/client/features/chat/ChatPanel.tsx +70 -49
- package/client/features/chat/ChatPopup.tsx +81 -8
- package/client/features/chat/applet-chat-intents.ts +31 -12
- package/client/features/chat/chat-send.ts +33 -1
- package/client/features/chat/chat-store.ts +10 -0
- package/client/features/chat/composer/ChatComposer.tsx +24 -27
- package/client/features/chat/composer/ModelPicker.tsx +3 -3
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +3 -3
- package/client/features/chat/connection/chat-frames.ts +14 -7
- package/client/features/chat/messages/ChatEmptyState.tsx +33 -19
- package/client/features/chat/messages/MarkdownContent.tsx +3 -3
- package/client/features/chat/messages/fork-history.ts +14 -0
- package/client/features/chat/sessions/ChatSelector.tsx +138 -79
- package/client/features/chat/sessions/api.ts +109 -19
- package/client/features/chat/sessions/browser-tab-state.ts +30 -7
- package/client/features/chat/sessions/useSelectedSession.ts +217 -51
- package/client/features/chat/useChat.ts +43 -45
- package/client/features/collab/client.ts +10 -11
- package/client/features/collab/hooks.tsx +6 -11
- package/client/features/collab/host-state.ts +57 -128
- package/client/features/collab/provider.tsx +3 -3
- package/client/features/collab/testing/fake-engine.ts +6 -27
- package/client/features/collab/workspace-users-menu.tsx +3 -7
- package/client/features/drawings/{useViewBuilderSketch.ts → useViewSketch.ts} +7 -7
- package/client/features/home/HomePage.tsx +2 -2
- package/client/features/overview/Overview.tsx +3 -6
- package/client/features/overview/default/ViewsWidget.tsx +5 -12
- package/client/features/overview/default/registry.tsx +2 -4
- package/client/features/views/PendingViewScreen.tsx +279 -0
- package/client/features/views/ViewManager.tsx +10 -10
- package/client/features/views/api.ts +63 -130
- package/client/features/views/useViewActions.ts +151 -0
- package/client/features/views/useViewDrafts.ts +79 -0
- package/client/features/views/view-presentation.ts +4 -5
- package/client/features/views/view-submission.ts +88 -0
- package/client/features/workspace/WorkspaceMenu.tsx +63 -0
- package/client/features/workspace/WorkspaceScreen.tsx +180 -375
- package/client/features/workspace/browser-tab-state.ts +16 -9
- package/client/features/workspace/moi-context.ts +13 -15
- package/client/features/workspace/tab-resolution.ts +16 -29
- package/client/features/workspace/useWorkspaceNavigation.ts +146 -104
- package/client/index.tsx +5 -1
- package/client/runtime/useWorkspaceEvents.ts +7 -6
- package/client/store/ui.ts +25 -29
- package/dist/chunk-1zhnhy00.js +1 -0
- package/dist/chunk-27501vke.js +1 -0
- package/dist/{chunk-jf6czgrz.js → chunk-9xtv6djt.js} +2 -2
- package/dist/chunk-am1x230f.js +2 -0
- package/dist/{chunk-nez8sdta.js → chunk-darpsw65.js} +1 -1
- package/dist/{chunk-97eg9mjn.js → chunk-gps4qc38.js} +1 -1
- package/dist/{chunk-3a48fyf7.js → chunk-hzwr8dp8.js} +4 -4
- package/dist/{chunk-efdyz6xp.js → chunk-j905va8r.js} +1 -1
- package/dist/chunk-n33w9y38.js +10 -0
- package/dist/chunk-r63ks44z.js +68 -0
- package/dist/{chunk-vfpsc75k.js → chunk-vqpkqtdr.js} +1 -1
- package/dist/chunk-wd46nk26.css +1 -0
- package/dist/chunk-xgt7vxt9.js +1 -0
- package/dist/{chunk-z3byfve5.js → chunk-yvzhwtfa.js} +2 -2
- package/dist/index.html +1 -1
- package/lib/ids.ts +2 -5
- package/lib/moi-context.ts +100 -73
- package/lib/navigation.ts +48 -87
- package/lib/session-drafts.ts +10 -0
- package/lib/types.ts +64 -31
- package/lib/view-build-directives.ts +12 -0
- package/lib/workspace-layout.ts +1 -1
- package/lib/workspace-tabs.ts +12 -7
- package/package.json +3 -1
- package/server/agent-launcher.ts +27 -0
- package/server/api.ts +119 -209
- package/server/app-config.ts +21 -2
- package/server/applets/build-worker.ts +2 -1
- package/server/applets/view-source.ts +7 -1
- package/server/cli-env.ts +72 -50
- package/server/cli.ts +101 -64
- package/server/control.ts +82 -63
- package/server/data-dir.ts +13 -0
- package/server/functions.ts +2 -1
- package/server/harness/README.md +8 -0
- package/server/harness/acp/adapter.ts +2 -2
- package/server/harness/acp/client.ts +2 -1
- package/server/harness/acp/discovery.ts +3 -3
- package/server/harness/acp/session.ts +6 -9
- package/server/harness/claude-code/adapter.ts +13 -8
- package/server/harness/claude-code/auth.ts +3 -2
- package/server/harness/claude-code/cli.ts +3 -1
- package/server/harness/claude-code/git-worktree.ts +5 -2
- package/server/harness/claude-code/index.ts +5 -0
- package/server/harness/claude-code/mcp.ts +2 -0
- package/server/harness/claude-code/models.ts +2 -0
- package/server/harness/claude-code/session.ts +5 -34
- package/server/harness/claude-code/sessions.ts +8 -12
- package/server/harness/codex/NOTES.md +23 -4
- package/server/harness/codex/adapter.ts +5 -3
- package/server/harness/codex/client.ts +13 -21
- package/server/harness/codex/index.ts +18 -0
- package/server/harness/codex/session.ts +6 -14
- package/server/harness/codex/thread-list.ts +74 -0
- package/server/harness/fork.ts +12 -0
- package/server/harness/openclaw/adapter.ts +3 -3
- package/server/harness/openclaw/session.ts +2 -30
- package/server/harness/session-title.ts +12 -3
- package/server/harness/types.ts +8 -3
- package/server/moi-scaffold.ts +2 -1
- package/server/pending-views.ts +164 -0
- package/server/registry.ts +14 -4
- package/server/selected-session.ts +91 -44
- package/server/service.ts +16 -2
- package/server/session-archive.ts +32 -0
- package/server/session-config.ts +16 -111
- package/server/session-lifecycle.ts +17 -0
- package/server/session-store.ts +127 -0
- package/server/status.ts +3 -1
- package/server/tabs.ts +7 -10
- package/server/view-sessions.ts +267 -0
- package/server/views.ts +30 -41
- package/server/web.ts +47 -45
- package/server/workspace-env.ts +27 -0
- package/server/workspace-init.ts +6 -2
- package/workspace/.claude/skills/moi-workspace/SKILL.md +49 -20
- package/workspace/.claude/skills/moi-workspace/references/COLLAB.md +2 -5
- package/client/features/views/ViewBuilder.tsx +0 -239
- package/client/features/views/useViewBuilderActions.ts +0 -103
- package/client/features/views/useViewBuilderDrafts.ts +0 -68
- package/dist/chunk-2jncyq65.js +0 -1
- package/dist/chunk-e2q5ken7.js +0 -68
- package/dist/chunk-h2kj1ysj.js +0 -1
- package/dist/chunk-nzwgm8vc.css +0 -1
- package/dist/chunk-ph0h6h86.js +0 -1
- package/dist/chunk-ryg9z3kn.js +0 -10
- package/dist/chunk-tpn177bt.js +0 -2
- package/lib/view-builder-directives.ts +0 -16
- package/server/chat-selection.ts +0 -22
- package/server/view-builders.ts +0 -453
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { useCallback, useState } from 'react'
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react'
|
|
2
2
|
|
|
3
3
|
import type { WorkspaceTabsState } from '@/lib/types'
|
|
4
4
|
import { normalizeWorkspaceTabs } from '@/lib/workspace-layout'
|
|
5
|
+
import { useCollabEnabled } from '@/client/features/collab'
|
|
6
|
+
import { useWorkspaceLayoutCtx } from './WorkspaceLayoutContext'
|
|
5
7
|
|
|
6
8
|
const keyFor = (workspaceId: string) => `moi:collab:${workspaceId}:tabs`
|
|
7
9
|
|
|
@@ -25,20 +27,25 @@ export function writeWorkspaceTabs(workspaceId: string, tabs: WorkspaceTabsState
|
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
export function useWorkspaceTabs(
|
|
29
|
-
workspaceId
|
|
30
|
-
enabled
|
|
31
|
-
defaults
|
|
32
|
-
) {
|
|
30
|
+
export function useWorkspaceTabs() {
|
|
31
|
+
const { workspaceId, layout, setLayout } = useWorkspaceLayoutCtx()
|
|
32
|
+
const enabled = useCollabEnabled()
|
|
33
|
+
const defaults = useMemo(() => normalizeWorkspaceTabs(layout.tabs), [layout.tabs])
|
|
33
34
|
const [local, setLocal] = useState<WorkspaceTabsState>(() =>
|
|
34
35
|
enabled ? readWorkspaceTabs(workspaceId, defaults) : defaults
|
|
35
36
|
)
|
|
36
37
|
const setTabs = useCallback(
|
|
37
38
|
(tabs: WorkspaceTabsState) => {
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const next = normalizeWorkspaceTabs(tabs)
|
|
40
|
+
if (enabled) {
|
|
41
|
+
setLocal(next)
|
|
42
|
+
writeWorkspaceTabs(workspaceId, next)
|
|
43
|
+
} else {
|
|
44
|
+
setLayout({ tabs: next })
|
|
45
|
+
}
|
|
46
|
+
return next
|
|
40
47
|
},
|
|
41
|
-
[workspaceId]
|
|
48
|
+
[enabled, setLayout, workspaceId]
|
|
42
49
|
)
|
|
43
50
|
return [enabled ? local : defaults, setTabs] as const
|
|
44
51
|
}
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
// the field in `useMoiUserMessageContext`'s builder below.
|
|
25
25
|
import { useCallback } from 'react'
|
|
26
26
|
|
|
27
|
-
import {
|
|
27
|
+
import { useViews } from '@/client/features/views/api'
|
|
28
28
|
import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
|
|
29
|
-
import type {
|
|
30
|
-
import type {
|
|
29
|
+
import type { AppletContext, MoiContext } from '@/lib/moi-context'
|
|
30
|
+
import type { ViewInfo, WorkspaceTabId } from '@/lib/types'
|
|
31
31
|
|
|
32
32
|
// One-shot directives queued per workspace, drained into the NEXT chat
|
|
33
33
|
// message's `# This message only` section. Module-level (not React state):
|
|
@@ -80,18 +80,15 @@ export function envelopeTabParams(
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
// The UI label of the active tab when it has one beyond its id: a view's
|
|
83
|
-
// configured
|
|
83
|
+
// configured or provisional title.
|
|
84
84
|
// Undefined otherwise (the envelope then falls back to the id, like the tab
|
|
85
85
|
// bar).
|
|
86
86
|
export function activeTabTitle(
|
|
87
87
|
tab: WorkspaceTabId,
|
|
88
|
-
views: ViewInfo[] | undefined
|
|
89
|
-
builders: ViewBuilder[] | undefined
|
|
88
|
+
views: ViewInfo[] | undefined
|
|
90
89
|
): string | undefined {
|
|
91
90
|
if (tab.startsWith('views/'))
|
|
92
|
-
return views?.find(v => v.id === tab.slice('views/'.length))?.
|
|
93
|
-
if (tab.startsWith('view-builders/'))
|
|
94
|
-
return builders?.find(b => b.id === tab.slice('view-builders/'.length))?.title || undefined
|
|
91
|
+
return views?.find(v => v.id === tab.slice('views/'.length))?.title || undefined
|
|
95
92
|
return undefined
|
|
96
93
|
}
|
|
97
94
|
|
|
@@ -100,7 +97,7 @@ export function activeTabTitle(
|
|
|
100
97
|
export type MoiUserMessageOptions = {
|
|
101
98
|
directives?: readonly string[]
|
|
102
99
|
// Present when applet UI sent this message instead of the user typing it.
|
|
103
|
-
applet?:
|
|
100
|
+
applet?: AppletContext
|
|
104
101
|
}
|
|
105
102
|
|
|
106
103
|
// Returns a builder that snapshots the workspace state at call time — invoke
|
|
@@ -113,19 +110,20 @@ export function useMoiUserMessageContext({
|
|
|
113
110
|
}: WorkspaceTabAddress): (options?: MoiUserMessageOptions) => MoiContext {
|
|
114
111
|
const workspaceId = useWorkspaceId()
|
|
115
112
|
const views = useViews(workspaceId).data
|
|
116
|
-
const builders = useViewBuilders(workspaceId).data
|
|
117
113
|
return useCallback(
|
|
118
114
|
(options: MoiUserMessageOptions = {}) => {
|
|
119
115
|
const directives = takeChatDirectives(workspaceId, options.directives ?? [])
|
|
120
116
|
const tabParams = envelopeTabParams(activeTab, appletParams)
|
|
121
117
|
return {
|
|
122
|
-
activeTab
|
|
123
|
-
|
|
124
|
-
|
|
118
|
+
activeTab: {
|
|
119
|
+
id: activeTab,
|
|
120
|
+
title: activeTabTitle(activeTab, views),
|
|
121
|
+
...(tabParams ? { params: tabParams } : {})
|
|
122
|
+
},
|
|
125
123
|
...(options.applet ? { applet: options.applet } : {}),
|
|
126
124
|
...(directives.length > 0 ? { directives } : {})
|
|
127
125
|
}
|
|
128
126
|
},
|
|
129
|
-
[workspaceId, activeTab, appletParams, views
|
|
127
|
+
[workspaceId, activeTab, appletParams, views]
|
|
130
128
|
)
|
|
131
129
|
}
|
|
@@ -2,51 +2,38 @@
|
|
|
2
2
|
// truth for the active tab (`/workspace/:id/views/<id>`, etc.); the persisted layout
|
|
3
3
|
// keeps the open set and the saved DEFAULT tab (`tabs.active`). These helpers
|
|
4
4
|
// turn (URL segment + layout + what actually exists) into the rendered state.
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
7
|
-
import { createDefaultWorkspaceTabs
|
|
5
|
+
import type { ViewInfo, WorkspaceTabId, WorkspaceTabsState } from '@/lib/types'
|
|
6
|
+
import { viewIdFromTab } from '@/lib/workspace-tabs'
|
|
7
|
+
import { createDefaultWorkspaceTabs } from '@/lib/workspace-layout'
|
|
8
8
|
|
|
9
9
|
const DEFAULT_TABS = createDefaultWorkspaceTabs()
|
|
10
10
|
|
|
11
|
-
export function normalizeTabsState(tabs: WorkspaceTabsState | undefined): WorkspaceTabsState {
|
|
12
|
-
return normalizeWorkspaceTabs(tabs)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
11
|
// Whether a tab id points at something that exists: static tabs always do,
|
|
16
|
-
// view
|
|
17
|
-
export function tabAvailable(tab: WorkspaceTabId, views: ViewInfo[]
|
|
18
|
-
if (tab === '
|
|
19
|
-
const builderId = viewBuilderIdFromTab(tab)
|
|
20
|
-
if (builderId) return builders.some(builder => builder.id === builderId)
|
|
12
|
+
// view tabs only while their pending or compiled view exists.
|
|
13
|
+
export function tabAvailable(tab: WorkspaceTabId, views: ViewInfo[]) {
|
|
14
|
+
if (tab === 'overview' || tab === 'scratchpad') return true
|
|
21
15
|
const viewId = viewIdFromTab(tab)
|
|
22
|
-
return viewId ? views.some(
|
|
16
|
+
return viewId ? views.some(view => view.id === viewId) : false
|
|
23
17
|
}
|
|
24
18
|
|
|
25
19
|
// The effective open set: persisted open tabs filtered to what exists, falling
|
|
26
20
|
// back to the defaults when nothing survives.
|
|
27
|
-
export function effectiveOpenTabs(
|
|
28
|
-
tabs
|
|
29
|
-
views: ViewInfo[],
|
|
30
|
-
builders: ViewBuilder[]
|
|
31
|
-
): WorkspaceTabId[] {
|
|
32
|
-
const open = tabs.open.filter(tab => tabAvailable(tab, views, builders))
|
|
21
|
+
export function effectiveOpenTabs(tabs: WorkspaceTabsState, views: ViewInfo[]): WorkspaceTabId[] {
|
|
22
|
+
const open = tabs.open.filter(tab => tabAvailable(tab, views))
|
|
33
23
|
return open.length > 0 ? open : DEFAULT_TABS.open
|
|
34
24
|
}
|
|
35
25
|
|
|
36
26
|
// An explicit URL keeps its destination, including a missing view so the host
|
|
37
|
-
// can show recovery and report the correct address to the agent.
|
|
38
|
-
//
|
|
27
|
+
// can show recovery and report the correct address to the agent. A bare URL
|
|
28
|
+
// uses the saved default.
|
|
39
29
|
export function resolveActiveTab(
|
|
40
|
-
requested: WorkspaceTabId |
|
|
30
|
+
requested: WorkspaceTabId | undefined,
|
|
41
31
|
tabs: WorkspaceTabsState,
|
|
42
|
-
views: ViewInfo[]
|
|
43
|
-
builders: ViewBuilder[],
|
|
44
|
-
split: boolean
|
|
32
|
+
views: ViewInfo[]
|
|
45
33
|
): WorkspaceTabId {
|
|
46
|
-
if (requested !==
|
|
34
|
+
if (requested !== undefined) {
|
|
47
35
|
return requested
|
|
48
36
|
}
|
|
49
|
-
const open = effectiveOpenTabs(tabs, views
|
|
50
|
-
|
|
51
|
-
return visible.includes(tabs.active) ? tabs.active : (visible[0] ?? 'overview')
|
|
37
|
+
const open = effectiveOpenTabs(tabs, views)
|
|
38
|
+
return open.includes(tabs.active) ? tabs.active : (open[0] ?? 'overview')
|
|
52
39
|
}
|
|
@@ -1,111 +1,164 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo } from 'react'
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from 'react'
|
|
2
2
|
import type { MouseEvent } from 'react'
|
|
3
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
3
4
|
import { useLocation, useRouter } from 'wouter'
|
|
4
5
|
import { usePathname, useSearch } from 'wouter/use-browser-location'
|
|
5
6
|
|
|
6
7
|
import { toast } from '@/client/components/ui/toast'
|
|
8
|
+
import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
7
9
|
import { reportAppletError } from '@/client/features/applets/applet-log'
|
|
8
10
|
import { useAppletEvent } from '@/client/features/applets/applet-runtime'
|
|
9
|
-
import { useCollabEnabled } from '@/client/features/collab'
|
|
10
11
|
import { useWorkspaceTabs } from '@/client/features/workspace/browser-tab-state'
|
|
11
|
-
import {
|
|
12
|
+
import { resolveActiveTab, tabAvailable } from './tab-resolution'
|
|
12
13
|
import { useWorkspaceLayoutCtx } from './WorkspaceLayoutContext'
|
|
13
|
-
import { useLatestRef } from '@/client/lib/use-latest-ref'
|
|
14
14
|
import { useNavigationClient } from '@/client/runtime/useWorkspaceEvents'
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
legacyTabFromPath,
|
|
20
|
-
parseMoiHref,
|
|
21
|
-
readViewParams,
|
|
22
|
-
resolveUrl,
|
|
23
|
-
tabFromPath,
|
|
24
|
-
workspacePath
|
|
25
|
-
} from '@/lib/navigation'
|
|
15
|
+
import { useSelectLinkedChat } from '@/client/features/chat/sessions/api'
|
|
16
|
+
import type { ViewInfo, WorkspaceTabId, WorkspaceTabsState } from '@/lib/types'
|
|
17
|
+
import { resolveUrl } from '@/lib/navigation'
|
|
18
|
+
import { isWorkspaceTabId, tabFromPath } from '@/lib/workspace-tabs'
|
|
26
19
|
type NavigationOptions = { replace?: boolean }
|
|
27
20
|
|
|
21
|
+
function canonicalSearch(search: string): string {
|
|
22
|
+
const params = new URLSearchParams(search)
|
|
23
|
+
params.sort()
|
|
24
|
+
const result = params.toString()
|
|
25
|
+
return result ? `?${result}` : ''
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function browserAddress(): string {
|
|
29
|
+
return window.location.pathname + canonicalSearch(window.location.search)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function tabUrl(remembered: ReadonlyMap<WorkspaceTabId, string>, tab: WorkspaceTabId): string {
|
|
33
|
+
return remembered.get(tab) ?? `moi:/${tab}`
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
// A convenience for returning to tabs, never a second source of active state.
|
|
29
37
|
// Memory-only, and scoped by workspace so switching workspaces cannot leak params.
|
|
30
38
|
const rememberedAddresses = new Map<string, Map<WorkspaceTabId, string>>()
|
|
31
39
|
|
|
32
|
-
type UseWorkspaceNavigationOptions = {
|
|
40
|
+
type UseWorkspaceNavigationOptions = {
|
|
41
|
+
views: ViewInfo[]
|
|
42
|
+
onOpenChat: () => void
|
|
43
|
+
}
|
|
33
44
|
|
|
34
|
-
export function useWorkspaceNavigation({ views,
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const [,
|
|
45
|
+
export function useWorkspaceNavigation({ views, onOpenChat }: UseWorkspaceNavigationOptions) {
|
|
46
|
+
const queryClient = useQueryClient()
|
|
47
|
+
const { workspaceId } = useWorkspaceLayoutCtx()
|
|
48
|
+
const [tabsState, saveTabs] = useWorkspaceTabs()
|
|
49
|
+
const latest = useRef({ views, tabsState, onOpenChat })
|
|
50
|
+
useLayoutEffect(() => {
|
|
51
|
+
latest.current = { views, tabsState, onOpenChat }
|
|
52
|
+
}, [views, tabsState, onOpenChat])
|
|
53
|
+
const selectLinkedChat = useSelectLinkedChat()
|
|
54
|
+
const navigationRequest = useRef<{ controller: AbortController; address: string } | null>(null)
|
|
55
|
+
const [, setLocation] = useLocation()
|
|
38
56
|
const router = useRouter()
|
|
39
57
|
const { base } = router
|
|
40
58
|
// wouter's public route/search hooks decode URI escapes already. Read raw
|
|
41
59
|
// browser values so tabFromPath and URLSearchParams each decode only once.
|
|
42
|
-
const
|
|
60
|
+
const prefix = `${base.replace(/\/$/, '')}/workspace/${encodeURIComponent(workspaceId)}/`
|
|
61
|
+
const path = usePathname(router).slice(prefix.length)
|
|
43
62
|
const search = canonicalSearch(useSearch(router))
|
|
44
|
-
const appletParams = useMemo(() =>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
normalizeTabsState(layout.tabs)
|
|
49
|
-
)
|
|
50
|
-
const tabsState = normalizeTabsState(workspaceTabs)
|
|
51
|
-
const tabsStateRef = useLatestRef(tabsState)
|
|
63
|
+
const appletParams = useMemo(() => {
|
|
64
|
+
const params = new URLSearchParams(search)
|
|
65
|
+
return Object.fromEntries(Array.from(params.keys(), key => [key, params.get(key)!]))
|
|
66
|
+
}, [search])
|
|
52
67
|
const remembered = useMemo(() => {
|
|
53
68
|
let entries = rememberedAddresses.get(workspaceId)
|
|
54
69
|
if (!entries) rememberedAddresses.set(workspaceId, (entries = new Map()))
|
|
55
70
|
return entries
|
|
56
71
|
}, [workspaceId])
|
|
57
72
|
const requestedTab = tabFromPath(path)
|
|
58
|
-
const
|
|
59
|
-
const activeTab = resolveActiveTab(requestedTab
|
|
73
|
+
const isChatLink = path === 'chat' || path === 'chats' || path.startsWith('chats/')
|
|
74
|
+
const activeTab = resolveActiveTab(requestedTab, tabsState, views)
|
|
60
75
|
const isUnavailable =
|
|
61
|
-
Boolean(path) && !
|
|
62
|
-
const
|
|
76
|
+
Boolean(path) && !isChatLink && (!requestedTab || !tabAvailable(requestedTab, views))
|
|
77
|
+
const isAvailableTab = requestedTab !== undefined && !isUnavailable
|
|
63
78
|
|
|
64
79
|
const setTabs = useCallback(
|
|
65
80
|
(tabs: WorkspaceTabsState) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
else setLayout({ tabs })
|
|
81
|
+
// Keep same-turn tab changes visible to navigation.
|
|
82
|
+
latest.current = { ...latest.current, tabsState: saveTabs(tabs) }
|
|
69
83
|
},
|
|
70
|
-
[
|
|
84
|
+
[latest, saveTabs]
|
|
71
85
|
)
|
|
72
86
|
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
)
|
|
87
|
+
const currentPage = useCallback(() => {
|
|
88
|
+
const currentTab = tabFromPath(window.location.pathname.slice(prefix.length))
|
|
89
|
+
const { tabsState, views } = latest.current
|
|
90
|
+
const tab = currentTab ?? resolveActiveTab(undefined, tabsState, views)
|
|
91
|
+
const href = currentTab ? `moi:/${tab}${window.location.search}` : tabUrl(remembered, tab)
|
|
92
|
+
return { tab, href }
|
|
93
|
+
}, [latest, prefix, remembered])
|
|
81
94
|
|
|
82
|
-
const
|
|
83
|
-
(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
workspacePath: workspacePath(workspaceId)
|
|
94
|
-
})
|
|
95
|
-
if (href.startsWith('moi:/files/') || !href.startsWith('moi:')) {
|
|
95
|
+
const navigate = useCallback(
|
|
96
|
+
async (
|
|
97
|
+
href: string,
|
|
98
|
+
{ replace = false }: NavigationOptions = {},
|
|
99
|
+
controller = new AbortController()
|
|
100
|
+
) => {
|
|
101
|
+
const target = resolveUrl(href, { workspaceId, base })
|
|
102
|
+
navigationRequest.current?.controller.abort()
|
|
103
|
+
if (!target.startsWith(prefix)) {
|
|
104
|
+
navigationRequest.current = null
|
|
105
|
+
controller.signal.throwIfAborted()
|
|
96
106
|
window.location.assign(target)
|
|
97
107
|
return
|
|
98
108
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
109
|
+
navigationRequest.current = {
|
|
110
|
+
controller,
|
|
111
|
+
address: browserAddress()
|
|
112
|
+
}
|
|
113
|
+
const commit = (url: string) => {
|
|
114
|
+
controller.signal.throwIfAborted()
|
|
115
|
+
navigationRequest.current = null
|
|
116
|
+
if (browserAddress() !== url || window.location.hash) setLocation(`~${url}`, { replace })
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const targetPath = target.slice(prefix.length).split('?', 1)[0]
|
|
120
|
+
if (targetPath === 'chat' || targetPath.startsWith('chats/')) {
|
|
121
|
+
const { tab, href } = currentPage()
|
|
122
|
+
const shouldOpenChat =
|
|
123
|
+
targetPath === 'chat'
|
|
124
|
+
? true
|
|
125
|
+
: await selectLinkedChat(
|
|
126
|
+
decodeURIComponent(targetPath.slice('chats/'.length)),
|
|
127
|
+
tab,
|
|
128
|
+
controller.signal
|
|
129
|
+
)
|
|
130
|
+
commit(resolveUrl(href, { workspaceId, base }))
|
|
131
|
+
if (shouldOpenChat) latest.current.onOpenChat()
|
|
132
|
+
return
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!isWorkspaceTabId(targetPath))
|
|
136
|
+
throw new Error('This destination is unavailable in this workspace')
|
|
137
|
+
const queryKey = workspaceKeys.views(workspaceId)
|
|
138
|
+
let availableViews = queryClient.getQueryData<ViewInfo[]>(queryKey) ?? latest.current.views
|
|
139
|
+
if (!tabAvailable(targetPath, availableViews)) {
|
|
140
|
+
await queryClient.refetchQueries({ queryKey, exact: true }, { throwOnError: true })
|
|
141
|
+
availableViews = queryClient.getQueryData<ViewInfo[]>(queryKey) ?? latest.current.views
|
|
142
|
+
}
|
|
143
|
+
if (!tabAvailable(targetPath, availableViews))
|
|
144
|
+
throw new Error('This destination is unavailable in this workspace')
|
|
145
|
+
commit(target)
|
|
146
|
+
} finally {
|
|
147
|
+
if (navigationRequest.current?.controller === controller) navigationRequest.current = null
|
|
148
|
+
}
|
|
103
149
|
},
|
|
104
|
-
[
|
|
150
|
+
[base, currentPage, latest, prefix, queryClient, selectLinkedChat, setLocation, workspaceId]
|
|
105
151
|
)
|
|
106
152
|
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
const request = navigationRequest.current
|
|
155
|
+
if (request && request.address !== browserAddress()) request.controller.abort()
|
|
156
|
+
}, [path, search, workspaceId])
|
|
157
|
+
useEffect(() => () => navigationRequest.current?.controller.abort(), [])
|
|
158
|
+
|
|
107
159
|
const reportError = useCallback(
|
|
108
160
|
(error: unknown) => {
|
|
161
|
+
if (error instanceof Error && error.name === 'AbortError') return
|
|
109
162
|
const message = error instanceof Error ? error.message : 'Navigation failed'
|
|
110
163
|
toast.add({ type: 'error', title: 'Could not navigate', description: message })
|
|
111
164
|
reportAppletError(workspaceId, { source: 'runtime', message })
|
|
@@ -113,44 +166,42 @@ export function useWorkspaceNavigation({ views, builders, split }: UseWorkspaceN
|
|
|
113
166
|
[workspaceId]
|
|
114
167
|
)
|
|
115
168
|
|
|
169
|
+
const navigateToTab = useCallback(
|
|
170
|
+
(tab: WorkspaceTabId, options: NavigationOptions = {}) => {
|
|
171
|
+
void navigate(tabUrl(remembered, tab), options).catch(reportError)
|
|
172
|
+
},
|
|
173
|
+
[navigate, remembered, reportError]
|
|
174
|
+
)
|
|
175
|
+
|
|
116
176
|
useAppletEvent(workspaceId, 'navigate', href => {
|
|
117
|
-
|
|
118
|
-
navigateHref(href)
|
|
119
|
-
} catch (error) {
|
|
120
|
-
reportError(error)
|
|
121
|
-
}
|
|
177
|
+
void navigate(href).catch(reportError)
|
|
122
178
|
})
|
|
123
|
-
useNavigationClient(workspaceId,
|
|
179
|
+
useNavigationClient(workspaceId, navigate)
|
|
124
180
|
|
|
125
|
-
// Bare workspace URLs, old bookmarks, and hidden singleton chat routes are
|
|
126
|
-
// the only redirects. Missing destinations keep their URL and show recovery.
|
|
127
181
|
useEffect(() => {
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
182
|
+
if (path && !isChatLink) return
|
|
183
|
+
let href = tabUrl(remembered, activeTab)
|
|
184
|
+
if (isChatLink) {
|
|
185
|
+
try {
|
|
186
|
+
href = resolveUrl(`moi:/${path}`)
|
|
187
|
+
} catch {
|
|
188
|
+
// Invalid chat links restore the saved tab without selecting a chat.
|
|
189
|
+
}
|
|
133
190
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
requestedTab,
|
|
141
|
-
search,
|
|
142
|
-
split,
|
|
143
|
-
isUnavailable,
|
|
144
|
-
workspaceId
|
|
145
|
-
])
|
|
191
|
+
const controller = new AbortController()
|
|
192
|
+
void navigate(href, { replace: true }, controller).catch(error => {
|
|
193
|
+
if (!controller.signal.aborted) reportError(error)
|
|
194
|
+
})
|
|
195
|
+
return () => controller.abort()
|
|
196
|
+
}, [activeTab, isChatLink, navigate, path, remembered, reportError, search])
|
|
146
197
|
|
|
147
198
|
useEffect(() => {
|
|
148
|
-
if (!
|
|
149
|
-
remembered.set(activeTab,
|
|
150
|
-
const current =
|
|
199
|
+
if (!isAvailableTab) return
|
|
200
|
+
remembered.set(activeTab, `moi:/${activeTab}${search}`)
|
|
201
|
+
const current = latest.current.tabsState
|
|
151
202
|
const open = current.open.includes(activeTab) ? current.open : [...current.open, activeTab]
|
|
152
203
|
if (open !== current.open || current.active !== activeTab) setTabs({ open, active: activeTab })
|
|
153
|
-
}, [activeTab,
|
|
204
|
+
}, [activeTab, isAvailableTab, latest, remembered, search, setTabs])
|
|
154
205
|
|
|
155
206
|
// React bubbling includes applet/chat portals. Native modified clicks and
|
|
156
207
|
// downloads keep a real href, so the browser can handle them normally.
|
|
@@ -173,22 +224,13 @@ export function useWorkspaceNavigation({ views, builders, split }: UseWorkspaceN
|
|
|
173
224
|
)
|
|
174
225
|
return
|
|
175
226
|
const url = new URL(anchor.href)
|
|
176
|
-
const prefix = workspacePath(workspaceId, base) + '/'
|
|
177
227
|
if (url.origin !== window.location.origin || !url.pathname.startsWith(prefix)) return
|
|
178
228
|
// In-page fragments continue using native browser behavior.
|
|
179
229
|
if (url.hash) return
|
|
180
|
-
const tab = tabFromPath(url.pathname.slice(prefix.length))
|
|
181
|
-
if (!tab) return
|
|
182
230
|
event.preventDefault()
|
|
183
|
-
|
|
184
|
-
if (!tabAvailable(tab, views, builders))
|
|
185
|
-
throw new Error('This destination is unavailable in this workspace')
|
|
186
|
-
go(addressPath(workspaceId, { tab, search: canonicalSearch(url.search) }))
|
|
187
|
-
} catch (error) {
|
|
188
|
-
reportError(error)
|
|
189
|
-
}
|
|
231
|
+
void navigate(`moi:/${url.pathname.slice(prefix.length)}${url.search}`).catch(reportError)
|
|
190
232
|
},
|
|
191
|
-
[
|
|
233
|
+
[navigate, prefix, reportError]
|
|
192
234
|
)
|
|
193
235
|
|
|
194
236
|
return {
|
package/client/index.tsx
CHANGED
|
@@ -23,8 +23,12 @@ if (import.meta.hot) {
|
|
|
23
23
|
startHmrWatchdog()
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
// Installed while this module evaluates, not inside `init`: an outer host's
|
|
27
|
+
// script runs right after this bundle and calls `window.moi.collab.publishUsers`
|
|
28
|
+
// straight away, before the async startup below has finished.
|
|
29
|
+
installHostApi()
|
|
30
|
+
|
|
26
31
|
export async function init(el: HTMLElement) {
|
|
27
|
-
installHostApi()
|
|
28
32
|
// Startup config and any proxy-verified user load in parallel with the
|
|
29
33
|
// main chunk, so both are available synchronously from the first render.
|
|
30
34
|
const [{ mount }, config, proxyUser] = await Promise.all([
|
|
@@ -7,7 +7,6 @@ import type {
|
|
|
7
7
|
AgentLoginState,
|
|
8
8
|
AppSettings,
|
|
9
9
|
HarnessAvailability,
|
|
10
|
-
ViewBuilder,
|
|
11
10
|
ViewInfo,
|
|
12
11
|
WidgetInfo
|
|
13
12
|
} from '@/lib/types'
|
|
@@ -21,8 +20,7 @@ export type WorkspaceEvent =
|
|
|
21
20
|
| { type: 'view:updated'; name: string }
|
|
22
21
|
| { type: 'view-layout:updated'; views: ViewInfo[] }
|
|
23
22
|
| { type: 'view:deleted'; workspaceId: string; name: string }
|
|
24
|
-
| { type: '
|
|
25
|
-
| { type: 'view-builder:deleted'; workspaceId: string; builderId: string }
|
|
23
|
+
| { type: 'views:changed'; workspaceId: string }
|
|
26
24
|
| { type: 'selected-session:updated'; workspaceId: string; sessionId: string | null }
|
|
27
25
|
| { type: 'theme:updated' }
|
|
28
26
|
| { type: 'workspace:updated' }
|
|
@@ -152,7 +150,10 @@ function sendNavigationPresence() {
|
|
|
152
150
|
|
|
153
151
|
// This hook owns presence for the displayed workspace, including reconnects.
|
|
154
152
|
// Requests received after a workspace switch never act on the new workspace.
|
|
155
|
-
export function useNavigationClient(
|
|
153
|
+
export function useNavigationClient(
|
|
154
|
+
workspaceId: string,
|
|
155
|
+
navigate: (href: string) => void | Promise<void>
|
|
156
|
+
) {
|
|
156
157
|
useEffect(() => {
|
|
157
158
|
navigationWorkspace = workspaceId
|
|
158
159
|
sendNavigationPresence()
|
|
@@ -166,12 +167,12 @@ export function useNavigationClient(workspaceId: string, navigate: (href: string
|
|
|
166
167
|
}
|
|
167
168
|
}, [workspaceId])
|
|
168
169
|
|
|
169
|
-
useWorkspaceEvent(event => {
|
|
170
|
+
useWorkspaceEvent(async event => {
|
|
170
171
|
if (event.type !== 'navigation:request' || event.workspaceId !== workspaceId) return
|
|
171
172
|
const socket = ws
|
|
172
173
|
try {
|
|
173
174
|
if (navigationWorkspace !== workspaceId) throw new Error('The browser switched workspaces.')
|
|
174
|
-
navigate(event.href)
|
|
175
|
+
await navigate(event.href)
|
|
175
176
|
socket?.send(
|
|
176
177
|
JSON.stringify({ type: 'navigation:result', requestId: event.requestId, ok: true })
|
|
177
178
|
)
|
package/client/store/ui.ts
CHANGED
|
@@ -9,14 +9,15 @@ type UiStore = {
|
|
|
9
9
|
hasSentMessageFromMoi: boolean
|
|
10
10
|
workspaceIdsPendingAnalysis: string[]
|
|
11
11
|
composerDrafts: Record<string, string>
|
|
12
|
-
viewBuilderDrafts: Record<string, string>
|
|
13
12
|
dockedChatWidth: number
|
|
13
|
+
popupChatWidth: number
|
|
14
14
|
setDiscoveredWorkspacesOpen: (open: boolean) => void
|
|
15
15
|
markWorkspacePendingAnalysis: (workspaceId: string) => void
|
|
16
16
|
markMessageSentFromMoi: (workspaceId: string) => void
|
|
17
|
-
setComposerDraft: (
|
|
18
|
-
|
|
17
|
+
setComposerDraft: (key: string, value: string | null) => void
|
|
18
|
+
moveComposerDraft: (from: string, to: string) => void
|
|
19
19
|
setDockedChatWidth: (width: number) => void
|
|
20
|
+
setPopupChatWidth: (width: number) => void
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export const createUiStore = (storage?: StateStorage) =>
|
|
@@ -27,8 +28,8 @@ export const createUiStore = (storage?: StateStorage) =>
|
|
|
27
28
|
hasSentMessageFromMoi: false,
|
|
28
29
|
workspaceIdsPendingAnalysis: [],
|
|
29
30
|
composerDrafts: {},
|
|
30
|
-
viewBuilderDrafts: {},
|
|
31
31
|
dockedChatWidth: 360,
|
|
32
|
+
popupChatWidth: 440,
|
|
32
33
|
setDiscoveredWorkspacesOpen: open => set({ discoveredWorkspacesOpen: open }),
|
|
33
34
|
markWorkspacePendingAnalysis: workspaceId =>
|
|
34
35
|
set(state => {
|
|
@@ -46,37 +47,32 @@ export const createUiStore = (storage?: StateStorage) =>
|
|
|
46
47
|
id => id !== workspaceId
|
|
47
48
|
)
|
|
48
49
|
})),
|
|
49
|
-
setComposerDraft: (
|
|
50
|
+
setComposerDraft: (key, value) =>
|
|
50
51
|
set(state => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
if (
|
|
53
|
+
value === null ? !(key in state.composerDrafts) : state.composerDrafts[key] === value
|
|
54
|
+
)
|
|
55
|
+
return state
|
|
56
|
+
const composerDrafts = { ...state.composerDrafts }
|
|
57
|
+
if (value === null) delete composerDrafts[key]
|
|
58
|
+
else composerDrafts[key] = value
|
|
54
59
|
return { composerDrafts }
|
|
55
60
|
}),
|
|
56
|
-
|
|
57
|
-
// falls back to the builder's server-saved requirements when no draft
|
|
58
|
-
// exists, and deleting all text must not resurrect them. Pass null to
|
|
59
|
-
// drop the draft (submit, discard).
|
|
60
|
-
setViewBuilderDraft: (builderId, value) =>
|
|
61
|
+
moveComposerDraft: (from, to) =>
|
|
61
62
|
set(state => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return { viewBuilderDrafts }
|
|
68
|
-
}
|
|
69
|
-
if (current[builderId] === value) return state
|
|
70
|
-
return { viewBuilderDrafts: { ...current, [builderId]: value } }
|
|
63
|
+
if (from === to || !(from in state.composerDrafts)) return state
|
|
64
|
+
const composerDrafts = { ...state.composerDrafts }
|
|
65
|
+
composerDrafts[to] ??= composerDrafts[from]
|
|
66
|
+
delete composerDrafts[from]
|
|
67
|
+
return { composerDrafts }
|
|
71
68
|
}),
|
|
72
|
-
setDockedChatWidth: width => set({ dockedChatWidth: width })
|
|
69
|
+
setDockedChatWidth: width => set({ dockedChatWidth: width }),
|
|
70
|
+
setPopupChatWidth: width => set({ popupChatWidth: width })
|
|
73
71
|
}),
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
: { name: 'moi:ui' }
|
|
72
|
+
{
|
|
73
|
+
name: 'moi:ui',
|
|
74
|
+
...(storage ? { storage: createJSONStorage<UiStore>(() => storage) } : {})
|
|
75
|
+
}
|
|
80
76
|
)
|
|
81
77
|
)
|
|
82
78
|
|