moi-computer 0.13.1-next.1 → 0.13.1-next.3
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 +14 -109
- 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 +66 -23
- package/client/features/views/use-view-actions.ts +10 -41
- 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 +1 -8
- package/client/features/workspace/use-workspace-navigation.ts +11 -7
- package/client/features/workspace/workspace-content.tsx +24 -31
- 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 +91 -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 +42 -16
- 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 +24 -9
- package/client/store/workspace-session.ts +30 -0
- package/dist/chunk-0h4zypgf.js +1 -0
- package/dist/chunk-1tksq43z.js +72 -0
- package/dist/chunk-6gxf0xr8.js +5 -0
- package/dist/chunk-a865c7x4.js +1 -0
- package/dist/chunk-f44cs6mw.js +2 -0
- package/dist/chunk-h3qag4a6.js +2 -0
- package/dist/chunk-kffcah9w.css +1 -0
- package/dist/chunk-q2tpy0h7.js +2 -0
- package/dist/chunk-r95acex1.js +546 -0
- package/dist/chunk-w5h9grdr.js +1 -0
- package/dist/{chunk-th91xfnp.js → chunk-xj1pjhng.js} +1 -1
- package/dist/index.html +1 -1
- package/lib/harness-instructions.ts +4 -4
- package/lib/harness-types.ts +13 -0
- package/lib/moi-context.ts +19 -5
- package/lib/types.ts +38 -54
- package/lib/workspace-config.ts +48 -0
- package/lib/workspace-layout.ts +5 -24
- package/package.json +5 -2
- package/server/AGENTS.md +1 -1
- package/server/README.md +36 -31
- package/server/api/harnesses.ts +5 -5
- package/server/api/index.ts +268 -162
- 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 +102 -54
- package/server/cli/commands/openclaw.ts +2 -2
- package/server/cli/commands/refresh.ts +10 -1
- package/server/cli/commands/remote.ts +330 -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 +73 -0
- package/server/cli/remote-operations.ts +247 -0
- package/server/collab/config.ts +3 -3
- package/server/collab/skill/index.ts +3 -3
- package/server/control.ts +47 -12
- 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 +2 -2
- 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/broker-client.ts +76 -0
- package/server/remote/broker.ts +81 -0
- package/server/remote/client.ts +725 -0
- package/server/remote/errors.ts +2 -0
- package/server/remote/routes.ts +121 -0
- package/server/remote/workspace.ts +34 -0
- package/server/scratchpad/document.ts +33 -12
- package/server/scratchpad/executor.ts +16 -7
- package/server/sessions/config.ts +8 -5
- package/server/sessions/pending-views.ts +17 -0
- package/server/sessions/send-message.ts +102 -0
- package/server/sessions/view-sessions.ts +9 -101
- 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 +13 -9
- package/server/workspace-state/file.ts +4 -0
- package/server/workspace-state/index.ts +0 -4
- package/server/workspaces/api.ts +24 -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 +5 -12
- package/skill/SKILL.md +80 -19
- package/skill/references/SCRATCHPAD.md +4 -0
- package/skill/references/UI-COMPONENTS.md +1 -1
- 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 { WorkspacePendingScreen } from './workspace-pending-screen'
|
|
2
|
+
import { WorkspaceOpenError, WorkspaceLoadingState } from './setup/workspace-recovery-states'
|
|
1
3
|
import { type ReactNode, createContext, useCallback, useContext, useMemo, useRef } from 'react'
|
|
2
4
|
|
|
3
5
|
import { useQueryClient } from '@tanstack/react-query'
|
|
@@ -9,13 +11,13 @@ import {
|
|
|
9
11
|
} from '@/client/features/workspace/api'
|
|
10
12
|
import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
11
13
|
import { useLatestRef } from '@/client/lib/use-latest-ref'
|
|
12
|
-
import type { WorkspaceLayout,
|
|
14
|
+
import type { WorkspaceLayout, HarnessType } from '@/lib/types'
|
|
13
15
|
import { createDefaultWorkspaceLayout } from '@/lib/workspace-layout'
|
|
14
16
|
|
|
15
|
-
import {
|
|
17
|
+
import { useWorkspaceState } from './workspace-state'
|
|
16
18
|
|
|
17
19
|
export type WorkspaceLayoutContextValue = {
|
|
18
|
-
//
|
|
20
|
+
// Shared widget layout and theme. Falls back to an
|
|
19
21
|
// empty default while the query is still loading.
|
|
20
22
|
layout: WorkspaceLayout
|
|
21
23
|
// Merge a partial update into the layout: updates the query cache immediately
|
|
@@ -27,10 +29,12 @@ export type WorkspaceLayoutContextValue = {
|
|
|
27
29
|
// The agent backend (claude-code / openclaw …). Exposed here so descendants
|
|
28
30
|
// can reuse the shared layout query instead of spawning another observer
|
|
29
31
|
// that could refetch on mount and clobber an optimistic layout update.
|
|
30
|
-
|
|
32
|
+
harness: HarnessType | null
|
|
31
33
|
// The workspace's registry id (the route param), so descendants can key
|
|
32
34
|
// their own queries (e.g. the model picker) without prop-drilling.
|
|
33
35
|
workspaceId: string
|
|
36
|
+
apiBase: string
|
|
37
|
+
isRemote: boolean
|
|
34
38
|
isLoading: boolean
|
|
35
39
|
}
|
|
36
40
|
|
|
@@ -55,7 +59,15 @@ export function useWorkspaceThemeSetting(): WorkspaceLayout['theme'] {
|
|
|
55
59
|
// Strip the server-only metadata so what we PUT back (and expose as `layout`)
|
|
56
60
|
// is just the persisted `WorkspaceLayout`.
|
|
57
61
|
function stripMeta(data: WorkspaceLayoutResponse): WorkspaceLayout {
|
|
58
|
-
const {
|
|
62
|
+
const {
|
|
63
|
+
cwd: _cwd,
|
|
64
|
+
name: _name,
|
|
65
|
+
harness: _harness,
|
|
66
|
+
agentId: _agentId,
|
|
67
|
+
apiBase: _apiBase,
|
|
68
|
+
isRemote: _isRemote,
|
|
69
|
+
...layout
|
|
70
|
+
} = data
|
|
59
71
|
return layout
|
|
60
72
|
}
|
|
61
73
|
|
|
@@ -70,12 +82,13 @@ export function WorkspaceLayoutProvider({ id, children }: WorkspaceLayoutProvide
|
|
|
70
82
|
const qc = useQueryClient()
|
|
71
83
|
const query = useWorkspaceLayout(id)
|
|
72
84
|
const save = useSaveLayout(id)
|
|
85
|
+
const personal = useWorkspaceState(id)
|
|
73
86
|
|
|
74
87
|
// `setLayout` must be referentially stable (it feeds effect deps in the grid
|
|
75
88
|
// reconcile), so reach the latest mutate via a ref instead of closing over it.
|
|
76
89
|
const saveRef = useLatestRef(save.mutate)
|
|
77
90
|
const timer = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
78
|
-
const pendingSave = useRef<
|
|
91
|
+
const pendingSave = useRef<WorkspaceLayout | null>(null)
|
|
79
92
|
|
|
80
93
|
const setLayout = useCallback(
|
|
81
94
|
(update: Partial<WorkspaceLayout>) => {
|
|
@@ -87,10 +100,7 @@ export function WorkspaceLayoutProvider({ id, children }: WorkspaceLayoutProvide
|
|
|
87
100
|
// Optimistic: the grid/theme reflects the change before the PUT lands.
|
|
88
101
|
const next = { ...prev, ...update }
|
|
89
102
|
qc.setQueryData<WorkspaceLayoutResponse>(key, next)
|
|
90
|
-
pendingSave.current =
|
|
91
|
-
...accumulateLayoutSave(stripMeta(next), update, pendingSave.current),
|
|
92
|
-
harness: next.provider ?? 'claude-code'
|
|
93
|
-
}
|
|
103
|
+
pendingSave.current = stripMeta(next)
|
|
94
104
|
|
|
95
105
|
if (timer.current) clearTimeout(timer.current)
|
|
96
106
|
// Persist the value captured at call time, NOT the cache at fire time: a
|
|
@@ -119,12 +129,35 @@ export function WorkspaceLayoutProvider({ id, children }: WorkspaceLayoutProvide
|
|
|
119
129
|
setLayout,
|
|
120
130
|
name: query.data?.name ?? null,
|
|
121
131
|
cwd: query.data?.cwd ?? null,
|
|
122
|
-
|
|
132
|
+
harness: query.data ? (query.data.harness ?? 'claude-code') : null,
|
|
123
133
|
workspaceId: id,
|
|
134
|
+
apiBase: query.data?.apiBase ?? '',
|
|
135
|
+
isRemote: query.data?.isRemote ?? false,
|
|
124
136
|
isLoading: query.isLoading
|
|
125
137
|
}),
|
|
126
138
|
[query.data, query.isLoading, setLayout, id]
|
|
127
139
|
)
|
|
128
140
|
|
|
129
|
-
return
|
|
141
|
+
return (
|
|
142
|
+
<WorkspaceLayoutContext value={value}>
|
|
143
|
+
{query.isPending || personal.isPending ? (
|
|
144
|
+
<WorkspacePendingScreen>
|
|
145
|
+
<WorkspaceLoadingState />
|
|
146
|
+
</WorkspacePendingScreen>
|
|
147
|
+
) : (query.isError && !query.data) || (personal.isError && !personal.data) ? (
|
|
148
|
+
<WorkspacePendingScreen setupRequired>
|
|
149
|
+
<WorkspaceOpenError
|
|
150
|
+
error={query.error ?? personal.error!}
|
|
151
|
+
retrying={query.isFetching || personal.isFetching}
|
|
152
|
+
onRetry={() => {
|
|
153
|
+
void query.refetch()
|
|
154
|
+
void personal.refetch()
|
|
155
|
+
}}
|
|
156
|
+
/>
|
|
157
|
+
</WorkspacePendingScreen>
|
|
158
|
+
) : (
|
|
159
|
+
children
|
|
160
|
+
)}
|
|
161
|
+
</WorkspaceLayoutContext>
|
|
162
|
+
)
|
|
130
163
|
}
|
|
@@ -21,7 +21,7 @@ type WorkspaceMenuProps = {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export function WorkspaceMenu({ onOpenTheme }: WorkspaceMenuProps) {
|
|
24
|
-
const { layout, name,
|
|
24
|
+
const { layout, name, harness } = useWorkspaceLayoutCtx()
|
|
25
25
|
const [iconHovered, setIconHovered] = useState(false)
|
|
26
26
|
|
|
27
27
|
return (
|
|
@@ -38,7 +38,7 @@ export function WorkspaceMenu({ onOpenTheme }: WorkspaceMenuProps) {
|
|
|
38
38
|
) : (
|
|
39
39
|
<WorkspaceIcon
|
|
40
40
|
icon={layout.icon}
|
|
41
|
-
|
|
41
|
+
harness={harness}
|
|
42
42
|
workspaceTheme={layout.theme}
|
|
43
43
|
className="size-5 rounded-sm"
|
|
44
44
|
/>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { cn } from '@/client/lib/cn'
|
|
3
|
+
import type { LayoutMode } from '@/lib/types'
|
|
4
|
+
|
|
5
|
+
type WorkspacePaneProps = {
|
|
6
|
+
mode: LayoutMode
|
|
7
|
+
children: ReactNode
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function WorkspacePane({ mode, children }: WorkspacePaneProps) {
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
data-slot="workspace-pane"
|
|
14
|
+
className={cn(
|
|
15
|
+
'@container/workspace relative flex h-full min-h-0 min-w-0 flex-1 flex-col-reverse overflow-hidden bg-background shadow-md transition-[border-radius,background-color] duration-100 ease-out motion-reduce:transition-none',
|
|
16
|
+
mode === 'split' && 'rounded-xl'
|
|
17
|
+
)}
|
|
18
|
+
>
|
|
19
|
+
{children}
|
|
20
|
+
</div>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from 'react'
|
|
2
2
|
|
|
3
3
|
import { ScreenShell } from '@/client/components/shared/screen-shell'
|
|
4
|
-
import { WorkspacePane } from './workspace-
|
|
4
|
+
import { WorkspacePane } from './workspace-pane'
|
|
5
5
|
|
|
6
6
|
type WorkspacePendingScreenProps = {
|
|
7
7
|
setupRequired?: boolean
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react'
|
|
2
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
3
|
+
import { jsonRequest, requestJson } from '@/client/api/http'
|
|
4
|
+
import { useUiStore, defaultWorkspaceUi, type WorkspaceUi } from '@/client/store/ui'
|
|
5
|
+
import { useWorkspaceSessionStore } from '@/client/store/workspace-session'
|
|
6
|
+
import { normalizeOpenTabs } from '@/lib/workspace-layout'
|
|
7
|
+
import type { ViewInfo, WorkspaceState, WorkspaceTabId, WorkspaceTabsState } from '@/lib/types'
|
|
8
|
+
import { useWorkspaceLayoutCtx } from './workspace-layout-context'
|
|
9
|
+
import {
|
|
10
|
+
getCachedWorkspaceState,
|
|
11
|
+
useWorkspaceState,
|
|
12
|
+
useWorkspaceStateWrite
|
|
13
|
+
} from './workspace-state'
|
|
14
|
+
import { tabAvailable } from './tab-resolution'
|
|
15
|
+
import { viewTabId } from '@/lib/workspace-tabs'
|
|
16
|
+
|
|
17
|
+
// Per-browser preferences for one workspace, local or remote. See client/store/ui.ts.
|
|
18
|
+
export function useWorkspaceUi() {
|
|
19
|
+
const { workspaceId } = useWorkspaceLayoutCtx()
|
|
20
|
+
const saved = useUiStore(state => state.workspaces[workspaceId])
|
|
21
|
+
// Entries saved before a field existed fall back to its default.
|
|
22
|
+
const ui = useMemo(() => ({ ...defaultWorkspaceUi, ...saved }), [saved])
|
|
23
|
+
const setWorkspaceUi = useUiStore(state => state.setWorkspaceUi)
|
|
24
|
+
const save = useCallback(
|
|
25
|
+
(patch: Partial<WorkspaceUi>) => setWorkspaceUi(workspaceId, patch),
|
|
26
|
+
[workspaceId, setWorkspaceUi]
|
|
27
|
+
)
|
|
28
|
+
return [ui, save] as const
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useFloatingChatOpen() {
|
|
32
|
+
const { workspaceId } = useWorkspaceLayoutCtx()
|
|
33
|
+
const open = useWorkspaceSessionStore(state => state.workspaces[workspaceId]?.chatOpen ?? false)
|
|
34
|
+
const save = useWorkspaceSessionStore(state => state.setWorkspaceSession)
|
|
35
|
+
const setOpen = useCallback(
|
|
36
|
+
(chatOpen: boolean) => save(workspaceId, { chatOpen }),
|
|
37
|
+
[workspaceId, save]
|
|
38
|
+
)
|
|
39
|
+
return [open, setOpen] as const
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function sameTabs(a: WorkspaceTabId[] | undefined, b: WorkspaceTabId[]) {
|
|
43
|
+
return a?.length === b.length && a.every((tab, index) => tab === b[index])
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Requires loaded personal state and views.
|
|
47
|
+
export function useWorkspaceTabs(views: ViewInfo[]) {
|
|
48
|
+
const { workspaceId } = useWorkspaceLayoutCtx()
|
|
49
|
+
const queryClient = useQueryClient()
|
|
50
|
+
const { data } = useWorkspaceState(workspaceId)
|
|
51
|
+
const active = useWorkspaceSessionStore(
|
|
52
|
+
state => state.workspaces[workspaceId]?.activeTab ?? 'overview'
|
|
53
|
+
)
|
|
54
|
+
const saveSession = useWorkspaceSessionStore(state => state.setWorkspaceSession)
|
|
55
|
+
const setActiveTab = useCallback(
|
|
56
|
+
(activeTab: WorkspaceTabId) => saveSession(workspaceId, { activeTab }),
|
|
57
|
+
[workspaceId, saveSession]
|
|
58
|
+
)
|
|
59
|
+
const { mutate } = useWorkspaceStateWrite<WorkspaceTabId[]>(workspaceId, {
|
|
60
|
+
request: openTabs =>
|
|
61
|
+
requestJson<WorkspaceState>(
|
|
62
|
+
`/api/workspaces/${workspaceId}/state/tabs`,
|
|
63
|
+
jsonRequest('PUT', { openTabs })
|
|
64
|
+
),
|
|
65
|
+
optimistic: (draft, openTabs) => {
|
|
66
|
+
draft.openTabs = openTabs
|
|
67
|
+
},
|
|
68
|
+
errorTitle: 'Couldn’t save workspace tabs'
|
|
69
|
+
})
|
|
70
|
+
// Deleted views leave the saved list on the next tab change.
|
|
71
|
+
const open = useMemo(() => {
|
|
72
|
+
const all: WorkspaceTabId[] = ['scratchpad', ...views.map(view => viewTabId(view.id))]
|
|
73
|
+
return [
|
|
74
|
+
'overview',
|
|
75
|
+
...normalizeOpenTabs(data?.openTabs ?? all).filter(tab => tabAvailable(tab, views))
|
|
76
|
+
] satisfies WorkspaceTabId[]
|
|
77
|
+
}, [data?.openTabs, views])
|
|
78
|
+
const tabs = useMemo(() => ({ open, active }), [open, active])
|
|
79
|
+
|
|
80
|
+
const setTabs = useCallback(
|
|
81
|
+
(tabs: WorkspaceTabsState) => {
|
|
82
|
+
const openTabs = normalizeOpenTabs(tabs.open)
|
|
83
|
+
setActiveTab(tabs.active)
|
|
84
|
+
if (!sameTabs(getCachedWorkspaceState(queryClient, workspaceId)?.openTabs, openTabs))
|
|
85
|
+
mutate(openTabs)
|
|
86
|
+
return tabs
|
|
87
|
+
},
|
|
88
|
+
[workspaceId, setActiveTab, queryClient, mutate]
|
|
89
|
+
)
|
|
90
|
+
return [tabs, setTabs, setActiveTab] as const
|
|
91
|
+
}
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { DiscoveredWorkspace, WorkspaceEntry,
|
|
1
|
+
import { harnessIcon } from '@/client/components/shared/workspace-icon'
|
|
2
|
+
import type { DiscoveredWorkspace, WorkspaceEntry, HarnessType } from '@/lib/types'
|
|
3
3
|
|
|
4
|
-
import { harnessLabel
|
|
5
|
-
export {
|
|
6
|
-
harnessLabel as workspaceTypeLabel,
|
|
7
|
-
harnessDescription as workspaceTypeDescription
|
|
8
|
-
} from '@/client/features/harness/harness-presentation'
|
|
4
|
+
import { harnessLabel } from '@/client/features/harness/harness-presentation'
|
|
9
5
|
|
|
10
6
|
type WorkspaceAgentIconsProps = {
|
|
11
|
-
|
|
7
|
+
harnesses: HarnessType[]
|
|
12
8
|
}
|
|
13
9
|
|
|
14
|
-
export function WorkspaceAgentIcons({
|
|
15
|
-
const label =
|
|
10
|
+
export function WorkspaceAgentIcons({ harnesses }: WorkspaceAgentIconsProps) {
|
|
11
|
+
const label = harnesses.map(harness => harnessLabel[harness]).join(', ')
|
|
16
12
|
|
|
17
13
|
return (
|
|
18
14
|
<span role="img" aria-label={label} className="inline-flex shrink-0 items-center -space-x-0.5">
|
|
19
|
-
{
|
|
15
|
+
{harnesses.map(harness => (
|
|
20
16
|
<img
|
|
21
|
-
key={
|
|
22
|
-
src={
|
|
17
|
+
key={harness}
|
|
18
|
+
src={harnessIcon[harness]}
|
|
23
19
|
alt=""
|
|
24
20
|
className="size-4 shrink-0 rounded-full bg-muted ring-2 ring-muted"
|
|
25
21
|
/>
|
|
@@ -31,9 +27,9 @@ export function WorkspaceAgentIcons({ types }: WorkspaceAgentIconsProps) {
|
|
|
31
27
|
type WorkspaceDisplaySource = WorkspaceEntry | DiscoveredWorkspace
|
|
32
28
|
|
|
33
29
|
export function workspaceDisplayName(workspace: WorkspaceDisplaySource): string {
|
|
34
|
-
if ('
|
|
30
|
+
if ('harnesses' in workspace) return workspace.path.split('/').pop() || workspace.path
|
|
35
31
|
if (workspace.name) return workspace.name
|
|
36
|
-
if (workspace.
|
|
37
|
-
if (workspace.
|
|
32
|
+
if (workspace.harness === 'openclaw') return workspace.agentId ?? 'OpenClaw agent'
|
|
33
|
+
if (workspace.harness === 'hermes') return workspace.agentId ?? 'Hermes agent'
|
|
38
34
|
return workspace.path.split('/').pop() || workspace.path
|
|
39
35
|
}
|
|
@@ -12,11 +12,11 @@ type WorkspaceScreenProps = {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function WorkspaceScreen({ contentPending, widgets, views }: WorkspaceScreenProps) {
|
|
15
|
-
const { layout, workspaceId, name,
|
|
15
|
+
const { layout, workspaceId, name, harness } = useWorkspaceLayoutCtx()
|
|
16
16
|
const { content, ready, setupRequired } = useWorkspaceSetup(workspaceId, contentPending, {
|
|
17
17
|
name: name ?? 'Workspace',
|
|
18
18
|
icon: layout.icon,
|
|
19
|
-
|
|
19
|
+
harness: harness,
|
|
20
20
|
workspaceTheme: layout.theme
|
|
21
21
|
})
|
|
22
22
|
|
|
@@ -6,7 +6,7 @@ import { toast } from '@/client/components/ui/toast'
|
|
|
6
6
|
import { useWorkspaceEvent } from '@/client/runtime/use-workspace-events'
|
|
7
7
|
import type { WorkspaceState } from '@/lib/types'
|
|
8
8
|
|
|
9
|
-
//
|
|
9
|
+
// Personal state for one workspace: tabs, pin, selected chats, chat
|
|
10
10
|
// settings and fork history, and views being built. One cache, kept current by
|
|
11
11
|
// write replies and `state:changed` events instead of refetches.
|
|
12
12
|
|
|
@@ -24,6 +24,15 @@ function writesInFlight(queryClient: QueryClient, workspaceId: string): number {
|
|
|
24
24
|
return queryClient.isMutating({ mutationKey: writeKey(workspaceId) })
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
// The newest server update received while an optimistic write is visible.
|
|
28
|
+
const deferredStates = new WeakMap<QueryClient, Map<string, WorkspaceState>>()
|
|
29
|
+
|
|
30
|
+
function deferWorkspaceState(client: QueryClient, workspaceId: string, state: WorkspaceState) {
|
|
31
|
+
let states = deferredStates.get(client)
|
|
32
|
+
if (!states) deferredStates.set(client, (states = new Map()))
|
|
33
|
+
states.set(workspaceId, newer(states.get(workspaceId), state))
|
|
34
|
+
}
|
|
35
|
+
|
|
27
36
|
// Keep the newer copy. A reply or event can arrive after a newer one.
|
|
28
37
|
function newer(current: WorkspaceState | undefined, next: WorkspaceState): WorkspaceState {
|
|
29
38
|
return current && current.revision > next.revision ? current : next
|
|
@@ -40,12 +49,16 @@ export function workspaceStateOptions(queryClient: QueryClient, workspaceId: str
|
|
|
40
49
|
const current = queryClient.getQueryData<WorkspaceState>(queryKey)
|
|
41
50
|
// A write in flight already shows its change; its reply brings the
|
|
42
51
|
// server's copy.
|
|
43
|
-
if (current && writesInFlight(queryClient, workspaceId) > 0)
|
|
52
|
+
if (current && writesInFlight(queryClient, workspaceId) > 0) {
|
|
53
|
+
deferWorkspaceState(queryClient, workspaceId, next)
|
|
54
|
+
return current
|
|
55
|
+
}
|
|
44
56
|
return newer(current, next)
|
|
45
57
|
},
|
|
46
58
|
// Events keep the cache current, so new observers never refetch. A focus
|
|
47
59
|
// refetch heals anything missed while the socket was down.
|
|
48
60
|
staleTime: 0,
|
|
61
|
+
retry: false,
|
|
49
62
|
gcTime: 5 * 60_000,
|
|
50
63
|
refetchOnMount: false,
|
|
51
64
|
refetchOnWindowFocus: true
|
|
@@ -86,27 +99,33 @@ export function receiveWorkspaceState(
|
|
|
86
99
|
workspaceId: string,
|
|
87
100
|
next: WorkspaceState
|
|
88
101
|
): void {
|
|
102
|
+
if (writesInFlight(queryClient, workspaceId) > 0) {
|
|
103
|
+
deferWorkspaceState(queryClient, workspaceId, next)
|
|
104
|
+
return
|
|
105
|
+
}
|
|
89
106
|
queryClient.setQueryData<WorkspaceState>(workspaceStateKey(workspaceId), current =>
|
|
90
107
|
newer(current, next)
|
|
91
108
|
)
|
|
92
109
|
}
|
|
93
110
|
|
|
94
|
-
type
|
|
95
|
-
|
|
111
|
+
type StateReply = WorkspaceState | { state: WorkspaceState }
|
|
112
|
+
|
|
113
|
+
type WorkspaceStateWriteOptions<Input, Result extends StateReply> = {
|
|
114
|
+
request: (input: Input) => Promise<Result>
|
|
96
115
|
optimistic?: (draft: WorkspaceState, input: Input) => void
|
|
97
|
-
onSuccess?: (state:
|
|
116
|
+
onSuccess?: (state: Result, input: Input) => void
|
|
98
117
|
errorTitle: string
|
|
99
118
|
}
|
|
100
119
|
|
|
101
120
|
// A write that answers with the new state. Writes to one workspace run in
|
|
102
|
-
// order; the
|
|
103
|
-
export function useWorkspaceStateWrite<Input>(
|
|
121
|
+
// order; the newest reply or event becomes the cache, and a failure refetches it.
|
|
122
|
+
export function useWorkspaceStateWrite<Input, Result extends StateReply = WorkspaceState>(
|
|
104
123
|
workspaceId: string,
|
|
105
|
-
{ request, optimistic, onSuccess, errorTitle }: WorkspaceStateWriteOptions<Input>
|
|
124
|
+
{ request, optimistic, onSuccess, errorTitle }: WorkspaceStateWriteOptions<Input, Result>
|
|
106
125
|
) {
|
|
107
126
|
const queryClient = useQueryClient()
|
|
108
127
|
const queryKey = workspaceStateKey(workspaceId)
|
|
109
|
-
return useMutation<
|
|
128
|
+
return useMutation<Result, Error, Input>({
|
|
110
129
|
mutationKey: writeKey(workspaceId),
|
|
111
130
|
scope: { id: `workspace-state:${workspaceId}` },
|
|
112
131
|
mutationFn: request,
|
|
@@ -115,15 +134,23 @@ export function useWorkspaceStateWrite<Input>(
|
|
|
115
134
|
await queryClient.cancelQueries({ queryKey, exact: true })
|
|
116
135
|
changeWorkspaceStateCache(queryClient, workspaceId, draft => optimistic(draft, input))
|
|
117
136
|
},
|
|
118
|
-
onSuccess: (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
receiveWorkspaceState(queryClient, workspaceId, state)
|
|
122
|
-
onSuccess?.(state, input)
|
|
137
|
+
onSuccess: (result, input) => {
|
|
138
|
+
receiveWorkspaceState(queryClient, workspaceId, 'state' in result ? result.state : result)
|
|
139
|
+
onSuccess?.(result, input)
|
|
123
140
|
},
|
|
124
141
|
onError: error => {
|
|
125
142
|
toast.add({ title: errorTitle, description: error.message, type: 'error' })
|
|
126
|
-
|
|
143
|
+
},
|
|
144
|
+
onSettled: (_result, error) => {
|
|
145
|
+
// This mutation still counts as pending until onSettled returns.
|
|
146
|
+
if (writesInFlight(queryClient, workspaceId) === 1) {
|
|
147
|
+
const states = deferredStates.get(queryClient)
|
|
148
|
+
const latest = states?.get(workspaceId)
|
|
149
|
+
states?.delete(workspaceId)
|
|
150
|
+
if (latest)
|
|
151
|
+
queryClient.setQueryData<WorkspaceState>(queryKey, current => newer(current, latest))
|
|
152
|
+
}
|
|
153
|
+
if (error) void queryClient.invalidateQueries({ queryKey, exact: true })
|
|
127
154
|
}
|
|
128
155
|
})
|
|
129
156
|
}
|
|
@@ -135,7 +162,6 @@ export function useWorkspaceStateSync(): void {
|
|
|
135
162
|
useWorkspaceEvent(event => {
|
|
136
163
|
if (event.type !== 'state:changed') return
|
|
137
164
|
if (!getCachedWorkspaceState(queryClient, event.workspaceId)) return
|
|
138
|
-
if (writesInFlight(queryClient, event.workspaceId) > 0) return
|
|
139
165
|
receiveWorkspaceState(queryClient, event.workspaceId, event.state)
|
|
140
166
|
})
|
|
141
167
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { queryClient as appQueryClient } from '@/client/api/query-client'
|
|
2
|
+
import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
3
|
+
import type { QueryClient } from '@tanstack/react-query'
|
|
4
|
+
import { createDefaultWorkspaceLayout } from '@/lib/workspace-layout'
|
|
5
|
+
import { workspaceApiBase, type RemoteWorkspaceTarget } from '@/lib/workspace-config'
|
|
6
|
+
import type { WorkspaceLayoutResponse } from '@/lib/types'
|
|
7
|
+
|
|
8
|
+
// Seed the info response for tests that mount a consumer without the workspace loader.
|
|
9
|
+
export function seedWorkspaceInfo(
|
|
10
|
+
id: string,
|
|
11
|
+
remote?: RemoteWorkspaceTarget,
|
|
12
|
+
client: QueryClient = appQueryClient
|
|
13
|
+
): WorkspaceLayoutResponse {
|
|
14
|
+
const info: WorkspaceLayoutResponse = {
|
|
15
|
+
...createDefaultWorkspaceLayout(),
|
|
16
|
+
name: id,
|
|
17
|
+
cwd: `/workspaces/${id}`,
|
|
18
|
+
apiBase: workspaceApiBase(remote?.workspace_id ?? id, remote?.user_id),
|
|
19
|
+
isRemote: !!remote
|
|
20
|
+
}
|
|
21
|
+
client.setQueryData(workspaceKeys.layout(id), info)
|
|
22
|
+
return info
|
|
23
|
+
}
|
|
@@ -16,6 +16,20 @@ export function useWorkspaceEvent(handler: WorkspaceEventHandler) {
|
|
|
16
16
|
useEffect(() => events?.subscribe(event => handlerRef.current(event)), [events, handlerRef])
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
// Listen to events for one workspace. Events that name no workspace (such as
|
|
20
|
+
// `moi refresh`) reach every open workspace.
|
|
21
|
+
export function useWorkspaceScopedEvent(workspaceId: string, handler: WorkspaceEventHandler) {
|
|
22
|
+
useWorkspaceEvent(event => {
|
|
23
|
+
if (
|
|
24
|
+
'workspaceId' in event &&
|
|
25
|
+
event.workspaceId !== undefined &&
|
|
26
|
+
event.workspaceId !== workspaceId
|
|
27
|
+
)
|
|
28
|
+
return
|
|
29
|
+
handler(event)
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
|
|
19
33
|
// This hook owns presence for the displayed workspace, including reconnects.
|
|
20
34
|
// Requests received after a workspace switch never act on the new workspace.
|
|
21
35
|
export function useNavigationClient(
|
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
HarnessAvailability,
|
|
6
6
|
HarnessStatus,
|
|
7
7
|
WidgetInfo,
|
|
8
|
-
|
|
8
|
+
HarnessType,
|
|
9
9
|
WorkspaceState
|
|
10
10
|
} from '@/lib/types'
|
|
11
11
|
|
|
@@ -13,16 +13,16 @@ export type WorkspaceEvent =
|
|
|
13
13
|
| { type: 'connection:opened' }
|
|
14
14
|
| {
|
|
15
15
|
type: 'harness-status:changed'
|
|
16
|
-
harness:
|
|
16
|
+
harness: HarnessType
|
|
17
17
|
status: HarnessStatus
|
|
18
18
|
}
|
|
19
|
-
| { type: 'workspace-harness:switched'; workspaceId: string; harness:
|
|
20
|
-
| { type: 'widget:updated'; name: string }
|
|
21
|
-
| { type: 'widget-layout:updated'; widgets: WidgetInfo[] }
|
|
19
|
+
| { type: 'workspace-harness:switched'; workspaceId: string; harness: HarnessType }
|
|
20
|
+
| { type: 'widget:updated'; workspaceId?: string; name: string }
|
|
21
|
+
| { type: 'widget-layout:updated'; workspaceId: string; widgets: WidgetInfo[] }
|
|
22
22
|
// `moi refresh` — cache-bust and re-fetch applets without a rebuild. `only`
|
|
23
23
|
// narrows to one kind; absent means both widgets and views.
|
|
24
|
-
| { type: 'applets:refresh'; only?: 'widgets' | 'views' }
|
|
25
|
-
| { type: 'view:updated'; name: string }
|
|
24
|
+
| { type: 'applets:refresh'; workspaceId?: string; only?: 'widgets' | 'views' }
|
|
25
|
+
| { type: 'view:updated'; workspaceId?: string; name: string }
|
|
26
26
|
| { type: 'view-layout:updated'; workspaceId: string; views: CompiledView[] }
|
|
27
27
|
| { type: 'view:deleted'; workspaceId: string; name: string }
|
|
28
28
|
// A workspace's chat state changed (pin, selection, chat settings, views
|
|
@@ -31,8 +31,8 @@ export type WorkspaceEvent =
|
|
|
31
31
|
// `origin` on an event is the browser tab whose write caused it (absent for
|
|
32
32
|
// CLI and agent changes), so that tab can skip its own echo. See
|
|
33
33
|
// client/lib/browser-tab-id.ts.
|
|
34
|
-
| { type: 'theme:updated'; origin?: string }
|
|
35
|
-
| { type: 'workspace:updated'; origin?: string }
|
|
34
|
+
| { type: 'theme:updated'; workspaceId: string; origin?: string }
|
|
35
|
+
| { type: 'workspace:updated'; workspaceId: string; origin?: string }
|
|
36
36
|
// The registry list changed (reorder, create) without touching any open
|
|
37
37
|
// workspace's layout — clients refetch just the sidebar list.
|
|
38
38
|
| { type: 'workspaces-list:updated'; origin?: string }
|
package/client/store/ui.ts
CHANGED
|
@@ -1,35 +1,52 @@
|
|
|
1
|
+
import type { LayoutMode } from '@/lib/types'
|
|
1
2
|
import { create } from 'zustand'
|
|
2
3
|
import { createJSONStorage, persist } from 'zustand/middleware'
|
|
3
4
|
import type { StateStorage } from 'zustand/middleware'
|
|
4
5
|
|
|
5
6
|
// Per-browser UI preferences and onboarding markers, persisted to localStorage
|
|
6
7
|
// so they survive reloads. Server-backed per-user app state belongs in DATA_DIR.
|
|
8
|
+
export type WorkspaceUi = {
|
|
9
|
+
layoutMode: LayoutMode
|
|
10
|
+
dockedChatWidth: number
|
|
11
|
+
popupChatWidth: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const defaultWorkspaceUi: WorkspaceUi = {
|
|
15
|
+
layoutMode: 'split',
|
|
16
|
+
dockedChatWidth: 360,
|
|
17
|
+
popupChatWidth: 440
|
|
18
|
+
}
|
|
19
|
+
|
|
7
20
|
type UiStore = {
|
|
21
|
+
workspaces: Record<string, WorkspaceUi>
|
|
22
|
+
setWorkspaceUi: (workspaceId: string, patch: Partial<WorkspaceUi>) => void
|
|
8
23
|
discoveredWorkspacesOpen: boolean
|
|
9
24
|
hasSentMessageFromMoi: boolean
|
|
10
25
|
workspaceIdsPendingAnalysis: string[]
|
|
11
26
|
composerDrafts: Record<string, string>
|
|
12
|
-
dockedChatWidth: number
|
|
13
|
-
popupChatWidth: number
|
|
14
27
|
setDiscoveredWorkspacesOpen: (open: boolean) => void
|
|
15
28
|
markWorkspacePendingAnalysis: (workspaceId: string) => void
|
|
16
29
|
markMessageSentFromMoi: (workspaceId: string) => void
|
|
17
30
|
setComposerDraft: (key: string, value: string | null) => void
|
|
18
31
|
moveComposerDraft: (from: string, to: string) => void
|
|
19
|
-
setDockedChatWidth: (width: number) => void
|
|
20
|
-
setPopupChatWidth: (width: number) => void
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
export const createUiStore = (storage?: StateStorage) =>
|
|
24
35
|
create<UiStore>()(
|
|
25
36
|
persist(
|
|
26
37
|
set => ({
|
|
38
|
+
workspaces: {},
|
|
39
|
+
setWorkspaceUi: (workspaceId, patch) =>
|
|
40
|
+
set(state => ({
|
|
41
|
+
workspaces: {
|
|
42
|
+
...state.workspaces,
|
|
43
|
+
[workspaceId]: { ...defaultWorkspaceUi, ...state.workspaces[workspaceId], ...patch }
|
|
44
|
+
}
|
|
45
|
+
})),
|
|
27
46
|
discoveredWorkspacesOpen: true,
|
|
28
47
|
hasSentMessageFromMoi: false,
|
|
29
48
|
workspaceIdsPendingAnalysis: [],
|
|
30
49
|
composerDrafts: {},
|
|
31
|
-
dockedChatWidth: 360,
|
|
32
|
-
popupChatWidth: 440,
|
|
33
50
|
setDiscoveredWorkspacesOpen: open => set({ discoveredWorkspacesOpen: open }),
|
|
34
51
|
markWorkspacePendingAnalysis: workspaceId =>
|
|
35
52
|
set(state => {
|
|
@@ -65,9 +82,7 @@ export const createUiStore = (storage?: StateStorage) =>
|
|
|
65
82
|
composerDrafts[to] ??= composerDrafts[from]
|
|
66
83
|
delete composerDrafts[from]
|
|
67
84
|
return { composerDrafts }
|
|
68
|
-
})
|
|
69
|
-
setDockedChatWidth: width => set({ dockedChatWidth: width }),
|
|
70
|
-
setPopupChatWidth: width => set({ popupChatWidth: width })
|
|
85
|
+
})
|
|
71
86
|
}),
|
|
72
87
|
{
|
|
73
88
|
name: 'moi:ui',
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { WorkspaceTabId } from '@/lib/types'
|
|
2
|
+
import { create } from 'zustand'
|
|
3
|
+
import { createJSONStorage, persist } from 'zustand/middleware'
|
|
4
|
+
|
|
5
|
+
type WorkspaceSession = {
|
|
6
|
+
activeTab?: WorkspaceTabId
|
|
7
|
+
chatOpen?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type WorkspaceSessionStore = {
|
|
11
|
+
workspaces: Record<string, WorkspaceSession>
|
|
12
|
+
setWorkspaceSession: (workspaceId: string, patch: WorkspaceSession) => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Per-browser-tab UI state that survives reloads.
|
|
16
|
+
export const useWorkspaceSessionStore = create<WorkspaceSessionStore>()(
|
|
17
|
+
persist(
|
|
18
|
+
set => ({
|
|
19
|
+
workspaces: {},
|
|
20
|
+
setWorkspaceSession: (workspaceId, patch) =>
|
|
21
|
+
set(state => ({
|
|
22
|
+
workspaces: {
|
|
23
|
+
...state.workspaces,
|
|
24
|
+
[workspaceId]: { ...state.workspaces[workspaceId], ...patch }
|
|
25
|
+
}
|
|
26
|
+
}))
|
|
27
|
+
}),
|
|
28
|
+
{ name: 'moi:workspace-session', storage: createJSONStorage(() => sessionStorage) }
|
|
29
|
+
)
|
|
30
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Qn}from"/chunk-xj1pjhng.js";export{Qn as sanitizeSvg};
|