moi-computer 0.13.1-next.0 → 0.13.1-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/api/app-config.ts +12 -2
- package/client/api/http.ts +11 -1
- package/client/app/app-router.tsx +3 -2
- package/client/app/routes/home-route.tsx +1 -1
- package/client/app/routes/workspace-registration.tsx +68 -0
- package/client/app/routes/workspace-route.tsx +37 -13
- package/client/app/shell/sidebar-layout.tsx +10 -5
- package/client/components/shared/workspace-icon.tsx +8 -17
- package/client/features/account/account-test-utils.tsx +18 -4
- package/client/features/account/api.ts +10 -8
- package/client/features/account/profile-actions.ts +5 -7
- package/client/features/app-settings/avatar-upload.tsx +62 -0
- package/client/features/app-settings/profile-settings.tsx +10 -0
- package/client/features/app-settings/settings-page.tsx +2 -1
- package/client/features/applets/api.ts +6 -6
- package/client/features/applets/applet-cache.ts +6 -5
- package/client/features/applets/applet-log.ts +2 -1
- package/client/features/applets/applet-runtime.ts +2 -1
- package/client/features/applets/use-applet.ts +73 -18
- package/client/features/applets/widget-shell.tsx +4 -2
- package/client/features/chat/applet-chat-intents.ts +5 -13
- package/client/features/chat/chat-popup.tsx +8 -4
- package/client/features/chat/chat-send.ts +2 -2
- package/client/features/chat/composer/model-order.ts +4 -4
- package/client/features/chat/composer/model-picker.tsx +12 -10
- package/client/features/chat/composer/use-workspace-composer-state.tsx +1 -1
- package/client/features/chat/sessions/api.ts +11 -28
- package/client/features/chat/sessions/use-selected-session.ts +18 -100
- package/client/features/chat/use-chat.ts +8 -12
- package/client/features/collab/applet-api.ts +1 -1
- package/client/features/collab/components/cursors.tsx +6 -1
- package/client/features/collab/components/presence-avatars.tsx +1 -1
- package/client/features/collab/components/presence-frame.tsx +1 -1
- package/client/features/collab/components/presence-group.tsx +1 -1
- package/client/features/collab/components/presence-helpers.ts +2 -2
- package/client/features/collab/components/user-avatar-group.tsx +1 -1
- package/client/features/collab/components/user-avatar.tsx +1 -1
- package/client/features/collab/components/user.tsx +1 -1
- package/client/features/collab/index.ts +3 -3
- package/client/features/collab/members/api.ts +17 -0
- package/client/features/collab/members/hooks.ts +97 -0
- package/client/features/collab/members/store.ts +148 -0
- package/client/features/{workspace-members → collab/members}/types.ts +7 -5
- package/client/features/collab/{client.ts → presence/client.ts} +4 -5
- package/client/features/collab/{hooks.tsx → presence/hooks.tsx} +1 -1
- package/client/features/collab/{provider.tsx → presence/provider.tsx} +1 -12
- package/client/features/collab/{users.ts → presence/users.ts} +19 -21
- package/client/features/collab/proxy-user.ts +1 -3
- package/client/features/collab/sharing/agent-invite.tsx +30 -0
- package/client/features/collab/sharing/workspace-members.tsx +269 -0
- package/client/features/collab/sharing/workspace-sharing-menu.tsx +179 -0
- package/client/features/collab/testing/component-fixtures.tsx +3 -3
- package/client/features/collab/testing/fake-engine.ts +2 -2
- package/client/features/dev/chat-states-page.tsx +3 -1
- package/client/features/dev/collab/collab-playground.tsx +2 -2
- package/client/features/dev/dev-index-page.tsx +0 -6
- package/client/features/dev/dev-routes.tsx +0 -2
- package/client/features/dev/harness-debug-page.tsx +7 -7
- package/client/features/dev/workspace-setup-mocks.ts +1 -2
- package/client/features/dev/workspace-setup-preview.tsx +6 -4
- package/client/features/harness/api.ts +13 -10
- package/client/features/harness/harness-login-panel.tsx +9 -5
- package/client/features/harness/harness-presentation.ts +4 -4
- package/client/features/harness/harness-selector.tsx +13 -13
- package/client/features/harness/use-harness-login.ts +5 -5
- package/client/features/home/api.ts +38 -2
- package/client/features/home/home-page.tsx +43 -13
- package/client/features/home/shared-workspaces.tsx +70 -0
- package/client/features/home/workspace-invitations.tsx +101 -0
- package/client/features/identity/host-api.ts +5 -4
- package/client/features/identity/store.ts +1 -7
- package/client/features/onboarding/agent-setup-step.tsx +8 -8
- package/client/features/onboarding/onboarding-page.tsx +3 -2
- package/client/features/onboarding/workspace-setup-step.tsx +1 -1
- package/client/features/overview/api.ts +3 -5
- package/client/features/overview/default/registry.tsx +1 -1
- package/client/features/overview/default/views-widget.tsx +2 -2
- package/client/features/overview/hidden-panel.tsx +7 -5
- package/client/features/overview/overview.tsx +18 -16
- package/client/features/overview/workspace-name.tsx +2 -2
- package/client/features/scratchpad/scratchpad.tsx +9 -7
- package/client/features/scratchpad/use-scratchpad-snapshot.tsx +13 -5
- package/client/features/views/api.ts +34 -16
- package/client/features/views/use-view-actions.ts +10 -20
- package/client/features/views/view-manager.tsx +1 -1
- package/client/features/views/view-submission.ts +2 -21
- package/client/features/workspace/add/api.ts +5 -4
- package/client/features/workspace/add/create-workspace-dialog.tsx +12 -9
- package/client/features/workspace/add/import-workspace-dialog.tsx +7 -7
- package/client/features/workspace/add/use-workspace-import.ts +10 -10
- package/client/features/workspace/add/workspace-agent-options.ts +21 -20
- package/client/features/workspace/add/workspace-agent-selector.tsx +11 -11
- package/client/features/workspace/api.ts +60 -13
- package/client/features/workspace/harness-transition.ts +7 -13
- package/client/features/workspace/remote.ts +25 -0
- package/client/features/workspace/settings/api.ts +7 -12
- package/client/features/workspace/settings/connectors-settings.tsx +3 -3
- package/client/features/workspace/settings/general-settings.tsx +8 -8
- package/client/features/workspace/setup/workspace-login-state.tsx +4 -4
- package/client/features/workspace/setup/workspace-recovery-states.tsx +43 -14
- package/client/features/workspace/setup/workspace-setup.tsx +6 -6
- package/client/features/workspace/tab-resolution.ts +2 -2
- package/client/features/workspace/use-workspace-navigation.ts +7 -4
- package/client/features/workspace/workspace-content.tsx +32 -26
- package/client/features/workspace/workspace-frame.tsx +13 -26
- package/client/features/workspace/workspace-layout-context.tsx +45 -12
- package/client/features/workspace/workspace-menu.tsx +2 -2
- package/client/features/workspace/workspace-pane.tsx +22 -0
- package/client/features/workspace/workspace-pending-screen.tsx +1 -1
- package/client/features/workspace/workspace-preferences.ts +34 -0
- package/client/features/workspace/workspace-presentation.tsx +12 -16
- package/client/features/workspace/workspace-screen.tsx +2 -2
- package/client/features/workspace/workspace-state.ts +2 -1
- package/client/features/workspace/workspace-tabs.tsx +1 -1
- package/client/features/workspace/workspace-test-utils.ts +23 -0
- package/client/runtime/use-workspace-events.ts +14 -0
- package/client/runtime/workspace-events.ts +9 -9
- package/client/store/ui.ts +29 -9
- package/dist/chunk-44khk4sp.js +2 -0
- package/dist/chunk-ba6mz56s.js +72 -0
- package/dist/chunk-ec5ennpv.js +1 -0
- package/dist/chunk-ectsnw81.js +2 -0
- package/dist/chunk-en7w5ypg.js +1 -0
- package/dist/chunk-f695wcx5.js +5 -0
- package/dist/chunk-kffcah9w.css +1 -0
- package/dist/{chunk-kdgk4dac.js → chunk-n0fawy9x.js} +1 -1
- package/dist/chunk-pdt9hxfw.js +2 -0
- package/dist/chunk-rmd0ctfx.js +546 -0
- package/dist/chunk-zv22wv0g.js +1 -0
- package/dist/index.html +1 -1
- package/lib/harness-instructions.ts +4 -4
- package/lib/harness-types.ts +13 -0
- package/lib/types.ts +34 -50
- package/lib/workspace-config.ts +48 -0
- package/lib/workspace-layout.ts +2 -4
- package/package.json +4 -2
- package/server/README.md +29 -27
- package/server/api/harnesses.ts +5 -5
- package/server/api/index.ts +170 -68
- package/server/app-config.ts +2 -7
- package/server/applets/declarations.ts +6 -7
- package/server/applets/index.ts +15 -9
- package/server/applets/views.ts +2 -17
- package/server/applets/widgets.ts +3 -2
- package/server/cli/commands/config.ts +8 -20
- package/server/cli/commands/hermes.ts +2 -2
- package/server/cli/commands/init.ts +96 -64
- package/server/cli/commands/openclaw.ts +2 -2
- package/server/cli/commands/refresh.ts +10 -1
- package/server/cli/commands/remote.ts +228 -0
- package/server/cli/commands/skill.ts +4 -4
- package/server/cli/commands/tabs.ts +5 -12
- package/server/cli/control.ts +35 -4
- package/server/cli/index.ts +10 -6
- package/server/cli/remote-command.ts +77 -0
- package/server/cli/remote-control.ts +70 -0
- package/server/cli/remote-operations.ts +244 -0
- package/server/collab/config.ts +4 -8
- package/server/collab/manager.ts +5 -2
- package/server/collab/skill/index.ts +4 -50
- package/server/control.ts +38 -11
- package/server/harness/acp/session.ts +4 -4
- package/server/harness/auth.ts +26 -31
- package/server/harness/claude-code/index.ts +1 -1
- package/server/harness/codex/discovery.ts +1 -1
- package/server/harness/codex/session.ts +1 -1
- package/server/harness/detect.ts +14 -19
- package/server/harness/executable.ts +10 -10
- package/server/harness/hermes/NOTES.md +2 -2
- package/server/harness/hermes/index.ts +1 -1
- package/server/harness/install.ts +11 -11
- package/server/harness/openclaw/index.ts +1 -1
- package/server/harness/registry.ts +7 -6
- package/server/harness/types.ts +4 -4
- package/server/onboarding/jobs.ts +1 -1
- package/server/operations/commands.ts +46 -0
- package/server/operations/files.ts +148 -0
- package/server/operations/server.ts +206 -0
- package/server/remote/agent.ts +103 -0
- package/server/remote/client.ts +665 -0
- package/server/remote/workspace.ts +34 -0
- package/server/scratchpad/document.ts +32 -12
- package/server/scratchpad/executor.ts +16 -7
- package/server/sessions/config.ts +8 -5
- package/server/sessions/pending-views.ts +16 -0
- package/server/sessions/view-sessions.ts +10 -12
- package/server/skills/locations.ts +4 -4
- package/server/skills/template.ts +3 -2
- package/server/skills/update.ts +12 -12
- package/server/skills/version.ts +7 -7
- package/server/skills/workspace.ts +13 -13
- package/server/web.ts +12 -10
- package/server/workspace-state/file.ts +2 -0
- package/server/workspace-state/index.ts +0 -4
- package/server/workspaces/api.ts +28 -0
- package/server/workspaces/change-harness.ts +15 -26
- package/server/workspaces/import.ts +4 -4
- package/server/workspaces/init.ts +15 -13
- package/server/workspaces/layout.ts +60 -66
- package/server/workspaces/registry.ts +43 -18
- package/server/workspaces/scaffold.ts +1 -0
- package/server/workspaces/shared.ts +74 -0
- package/server/workspaces/tabs.ts +6 -12
- package/skill/SKILL.md +24 -4
- package/client/api/app-ui-keys.ts +0 -6
- package/client/features/chat/sessions/browser-tab-state.ts +0 -43
- package/client/features/collab/workspace-users-menu.tsx +0 -190
- package/client/features/dev/cloud-avatar-upload.tsx +0 -58
- package/client/features/dev/cloud-page.tsx +0 -363
- package/client/features/workspace/browser-tab-state.ts +0 -51
- package/client/features/workspace/layout-save.ts +0 -13
- package/client/features/workspace-members/api.ts +0 -20
- package/client/features/workspace-members/hooks.ts +0 -127
- package/client/features/workspace-members/keys.ts +0 -6
- package/client/features/workspace-members/store.ts +0 -123
- package/dist/chunk-00s35r33.js +0 -546
- package/dist/chunk-7rz6g7g7.js +0 -1
- package/dist/chunk-af2jyddf.js +0 -2
- package/dist/chunk-cekekc3f.css +0 -1
- package/dist/chunk-ep5vh16c.js +0 -75
- package/dist/chunk-s5s1vzdw.js +0 -2
- package/dist/chunk-svxhxfeq.js +0 -2
- package/dist/chunk-t0r0bds1.js +0 -1
- package/dist/chunk-vp2qzc0d.js +0 -1
- package/dist/chunk-wz5qv1bn.js +0 -2
- package/lib/workspace-types.ts +0 -13
- package/server/workspace-state/legacy-migration.ts +0 -79
- /package/client/features/collab/{presence-publisher.ts → presence/presence-publisher.ts} +0 -0
- /package/client/features/collab/{presence-target.ts → presence/presence-target.ts} +0 -0
- /package/client/features/collab/{store.ts → presence/store.ts} +0 -0
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useQueryClient, type QueryClient } from '@tanstack/react-query'
|
|
2
2
|
import { useCallback } from 'react'
|
|
3
3
|
import { useParams } from 'wouter'
|
|
4
4
|
|
|
5
|
-
import { appUiKeys } from '@/client/api/app-ui-keys'
|
|
6
5
|
import { jsonRequest, requestJson } from '@/client/api/http'
|
|
7
|
-
import {
|
|
8
|
-
readSelectedSession,
|
|
9
|
-
writeSelectedSession,
|
|
10
|
-
type BrowserTabSelection
|
|
11
|
-
} from '@/client/features/chat/sessions/browser-tab-state'
|
|
12
|
-
import { useCollabEnabled } from '@/client/features/collab'
|
|
13
6
|
import { useWorkspaceId } from '@/client/features/workspace/workspace-context'
|
|
14
7
|
import {
|
|
15
8
|
changeWorkspaceStateCache,
|
|
@@ -20,7 +13,7 @@ import {
|
|
|
20
13
|
} from '@/client/features/workspace/workspace-state'
|
|
21
14
|
import { useUiStore } from '@/client/store/ui'
|
|
22
15
|
import { composerDraftKey } from '@/lib/session-drafts'
|
|
23
|
-
import type {
|
|
16
|
+
import type { WorkspaceState, WorkspaceTabId } from '@/lib/types'
|
|
24
17
|
import { isWorkspaceTabId } from '@/lib/workspace-tabs'
|
|
25
18
|
|
|
26
19
|
type SetSelectedSession = (sessionId: string | null) => void
|
|
@@ -40,69 +33,22 @@ type SelectionWrite = {
|
|
|
40
33
|
ifMatch?: string | null
|
|
41
34
|
}
|
|
42
35
|
|
|
43
|
-
|
|
44
|
-
return appUiKeys.browserTabSelection(workspaceId)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// sessionStorage is the source; the query only lets React observe it. Dropped
|
|
48
|
-
// on unmount so the next visit reads storage again.
|
|
49
|
-
export function browserTabSelectionOptions(workspaceId: string) {
|
|
50
|
-
return {
|
|
51
|
-
queryKey: browserTabSelectionKey(workspaceId),
|
|
52
|
-
queryFn: () => Promise.resolve(readSelectedSession(workspaceId)),
|
|
53
|
-
staleTime: Infinity,
|
|
54
|
-
gcTime: 0,
|
|
55
|
-
refetchOnMount: false,
|
|
56
|
-
refetchOnWindowFocus: false
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// The chat a tab shows: the pin, then this browser tab's own choice (collab),
|
|
61
|
-
// then the workspace's. Undefined until the state has loaded.
|
|
36
|
+
// The personal pin takes precedence over the chat selected in this workspace tab.
|
|
62
37
|
export function selectedSessionForTab(
|
|
63
38
|
state: WorkspaceState | undefined,
|
|
64
|
-
tabId: WorkspaceTabId
|
|
65
|
-
local?: BrowserTabSelection
|
|
39
|
+
tabId: WorkspaceTabId
|
|
66
40
|
): string | null | undefined {
|
|
67
41
|
if (!state) return undefined
|
|
68
42
|
if (state.pinnedSessionId) return state.pinnedSessionId
|
|
69
|
-
if (local && tabId in local.selected) return local.selected[tabId] ?? null
|
|
70
43
|
return state.selected[tabId] ?? null
|
|
71
44
|
}
|
|
72
45
|
|
|
73
|
-
function cachedBrowserTabSelection(
|
|
74
|
-
queryClient: QueryClient,
|
|
75
|
-
workspaceId: string
|
|
76
|
-
): BrowserTabSelection {
|
|
77
|
-
return (
|
|
78
|
-
queryClient.getQueryData<BrowserTabSelection>(browserTabSelectionKey(workspaceId)) ??
|
|
79
|
-
readSelectedSession(workspaceId)
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// For handlers outside render, which must see a change before React does.
|
|
84
46
|
export function cachedSelectedSession(
|
|
85
47
|
queryClient: QueryClient,
|
|
86
48
|
workspaceId: string,
|
|
87
|
-
tabId: WorkspaceTabId
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return selectedSessionForTab(
|
|
91
|
-
getCachedWorkspaceState(queryClient, workspaceId),
|
|
92
|
-
tabId,
|
|
93
|
-
scope === 'browser-tab' ? cachedBrowserTabSelection(queryClient, workspaceId) : undefined
|
|
94
|
-
)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function setBrowserTabSelection(
|
|
98
|
-
queryClient: QueryClient,
|
|
99
|
-
workspaceId: string,
|
|
100
|
-
change: (selected: BrowserTabSelection['selected']) => void
|
|
101
|
-
): void {
|
|
102
|
-
const selected = { ...cachedBrowserTabSelection(queryClient, workspaceId).selected }
|
|
103
|
-
change(selected)
|
|
104
|
-
queryClient.setQueryData<BrowserTabSelection>(browserTabSelectionKey(workspaceId), { selected })
|
|
105
|
-
writeSelectedSession(workspaceId, { selected })
|
|
49
|
+
tabId: WorkspaceTabId
|
|
50
|
+
) {
|
|
51
|
+
return selectedSessionForTab(getCachedWorkspaceState(queryClient, workspaceId), tabId)
|
|
106
52
|
}
|
|
107
53
|
|
|
108
54
|
function applySelectionWrite(draft: WorkspaceState, input: SelectionWrite): void {
|
|
@@ -111,22 +57,13 @@ function applySelectionWrite(draft: WorkspaceState, input: SelectionWrite): void
|
|
|
111
57
|
}
|
|
112
58
|
|
|
113
59
|
// The request that points `tabId` at `sessionId` (null: a new chat), or
|
|
114
|
-
// undefined when nothing needs saving.
|
|
60
|
+
// undefined when nothing needs saving.
|
|
115
61
|
function selectionChange(
|
|
116
62
|
queryClient: QueryClient,
|
|
117
63
|
workspaceId: string,
|
|
118
64
|
sessionId: string | null,
|
|
119
|
-
tabId: WorkspaceTabId
|
|
120
|
-
scope: SelectedSessionScope
|
|
65
|
+
tabId: WorkspaceTabId
|
|
121
66
|
): SelectionWrite | undefined {
|
|
122
|
-
if (scope === 'browser-tab') {
|
|
123
|
-
const local = cachedBrowserTabSelection(queryClient, workspaceId)
|
|
124
|
-
if (tabId in local.selected && (local.selected[tabId] ?? null) === sessionId) return
|
|
125
|
-
setBrowserTabSelection(queryClient, workspaceId, selected => {
|
|
126
|
-
selected[tabId] = sessionId
|
|
127
|
-
})
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
67
|
const current = getCachedWorkspaceState(queryClient, workspaceId)?.selected[tabId] ?? null
|
|
131
68
|
if (current === sessionId) return
|
|
132
69
|
if (sessionId === null) return current ? { sessionId: current, tabId, show: false } : undefined
|
|
@@ -139,17 +76,11 @@ export function setSelectedSessionInCache(
|
|
|
139
76
|
queryClient: QueryClient,
|
|
140
77
|
workspaceId: string,
|
|
141
78
|
sessionId: string,
|
|
142
|
-
tabId: WorkspaceTabId
|
|
143
|
-
scope: SelectedSessionScope
|
|
79
|
+
tabId: WorkspaceTabId
|
|
144
80
|
): void {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
})
|
|
149
|
-
else
|
|
150
|
-
changeWorkspaceStateCache(queryClient, workspaceId, draft => {
|
|
151
|
-
draft.selected[tabId] = sessionId
|
|
152
|
-
})
|
|
81
|
+
changeWorkspaceStateCache(queryClient, workspaceId, draft => {
|
|
82
|
+
draft.selected[tabId] = sessionId
|
|
83
|
+
})
|
|
153
84
|
}
|
|
154
85
|
|
|
155
86
|
// A harness replaced a temporary chat id with its real one.
|
|
@@ -165,10 +96,6 @@ export function renameSelectedSessionInCache(
|
|
|
165
96
|
changeWorkspaceStateCache(queryClient, workspaceId, draft =>
|
|
166
97
|
renameSessionInState(draft, from, to)
|
|
167
98
|
)
|
|
168
|
-
setBrowserTabSelection(queryClient, workspaceId, selected => {
|
|
169
|
-
for (const [tabId, sessionId] of Object.entries(selected) as [WorkspaceTabId, string | null][])
|
|
170
|
-
if (sessionId === from) selected[tabId] = to
|
|
171
|
-
})
|
|
172
99
|
}
|
|
173
100
|
|
|
174
101
|
export function useCurrentTabId(): WorkspaceTabId {
|
|
@@ -193,40 +120,31 @@ export function useSelectedSession(explicitTabId?: WorkspaceTabId): SelectedSess
|
|
|
193
120
|
const routeTabId = useCurrentTabId()
|
|
194
121
|
const tabId = explicitTabId ?? routeTabId
|
|
195
122
|
const workspaceId = useWorkspaceId()
|
|
196
|
-
const collabEnabled = useCollabEnabled()
|
|
197
|
-
const scope: SelectedSessionScope = collabEnabled ? 'browser-tab' : 'shared'
|
|
198
123
|
const queryClient = useQueryClient()
|
|
199
124
|
const state = useWorkspaceState(workspaceId).data
|
|
200
|
-
const local = useQuery({
|
|
201
|
-
...browserTabSelectionOptions(workspaceId),
|
|
202
|
-
enabled: scope === 'browser-tab'
|
|
203
|
-
}).data
|
|
204
125
|
const { mutate: save, mutateAsync: saveAsync } = useSelectionWrite(workspaceId)
|
|
205
126
|
|
|
206
127
|
const setSelectedSessionId = useCallback<SetSelectedSession>(
|
|
207
128
|
sessionId => {
|
|
208
129
|
// A pinned chat shows in every tab until it is unpinned.
|
|
209
130
|
if (getCachedWorkspaceState(queryClient, workspaceId)?.pinnedSessionId) return
|
|
210
|
-
const input = selectionChange(queryClient, workspaceId, sessionId, tabId
|
|
131
|
+
const input = selectionChange(queryClient, workspaceId, sessionId, tabId)
|
|
211
132
|
if (input) save(input)
|
|
212
133
|
},
|
|
213
|
-
[queryClient, save, workspaceId, tabId
|
|
134
|
+
[queryClient, save, workspaceId, tabId]
|
|
214
135
|
)
|
|
215
136
|
|
|
216
137
|
const selectSessionForTab = useCallback(
|
|
217
138
|
async (sessionId: string, destination: WorkspaceTabId) => {
|
|
218
|
-
const input = selectionChange(queryClient, workspaceId, sessionId, destination
|
|
139
|
+
const input = selectionChange(queryClient, workspaceId, sessionId, destination)
|
|
219
140
|
if (!input) return
|
|
220
141
|
const saved = await saveAsync(input)
|
|
221
142
|
if (saved.selected[destination] !== sessionId) throw new Error('Couldn’t save selected chat')
|
|
222
143
|
},
|
|
223
|
-
[queryClient, saveAsync,
|
|
144
|
+
[queryClient, saveAsync, workspaceId]
|
|
224
145
|
)
|
|
225
146
|
|
|
226
|
-
const selectedSessionId =
|
|
227
|
-
scope === 'browser-tab' && local === undefined
|
|
228
|
-
? undefined
|
|
229
|
-
: selectedSessionForTab(state, tabId, scope === 'browser-tab' ? local : undefined)
|
|
147
|
+
const selectedSessionId = selectedSessionForTab(state, tabId)
|
|
230
148
|
return [selectedSessionId, setSelectedSessionId, selectSessionForTab]
|
|
231
149
|
}
|
|
232
150
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useWorkspaceState } from '@/client/features/workspace/workspace-state'
|
|
1
2
|
import { useCallback, useMemo } from 'react'
|
|
2
3
|
|
|
3
4
|
import { useQueryClient } from '@tanstack/react-query'
|
|
@@ -6,13 +7,11 @@ import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
|
6
7
|
import { useSessionState, useSessionView } from '@/client/features/chat/sessions/api'
|
|
7
8
|
import { useWorkspaceHarness } from '@/client/features/workspace/api'
|
|
8
9
|
import { useSelectedSession } from '@/client/features/chat/sessions/use-selected-session'
|
|
9
|
-
import { useCollabEnabled } from '@/client/features/collab'
|
|
10
10
|
import {
|
|
11
11
|
type WorkspaceTabAddress,
|
|
12
12
|
useMoiUserMessageContext
|
|
13
13
|
} from '@/client/features/workspace/moi-context'
|
|
14
14
|
import { useWorkspaceId } from '@/client/features/workspace/workspace-context'
|
|
15
|
-
import { useWorkspaceLayoutCtx } from '@/client/features/workspace/workspace-layout-context'
|
|
16
15
|
import { sendMessage } from '@/client/features/chat/connection/chat-connection'
|
|
17
16
|
import {
|
|
18
17
|
type ChatSendOptions,
|
|
@@ -51,9 +50,7 @@ const EMPTY: ViewState = emptyViewState()
|
|
|
51
50
|
export function useChat(address: WorkspaceTabAddress) {
|
|
52
51
|
const workspaceId = useWorkspaceId()
|
|
53
52
|
const qc = useQueryClient()
|
|
54
|
-
const { layout } = useWorkspaceLayoutCtx()
|
|
55
53
|
const [selectedSession, selectSession] = useSelectedSession(address.activeTab)
|
|
56
|
-
const collabEnabled = useCollabEnabled()
|
|
57
54
|
const modelsData = useWorkspaceHarness(workspaceId).data
|
|
58
55
|
// A newly forked/native session can precede the provider's session listing.
|
|
59
56
|
// Archive explicitly clears selection; a stale catalog must not do so.
|
|
@@ -75,6 +72,7 @@ export function useChat(address: WorkspaceTabAddress) {
|
|
|
75
72
|
const viewQuery = useSessionView(workspaceId, selectedSessionId)
|
|
76
73
|
const { refetch } = viewQuery
|
|
77
74
|
// Tab, settings and fork history, from the workspace state.
|
|
75
|
+
const defaults = useWorkspaceState(workspaceId).data?.chatDefaults
|
|
78
76
|
const session = useSessionState(workspaceId, selectedSessionId)
|
|
79
77
|
const { refetch: refetchSession } = session
|
|
80
78
|
const retryLoad = useCallback(async () => {
|
|
@@ -156,9 +154,9 @@ export function useChat(address: WorkspaceTabAddress) {
|
|
|
156
154
|
// the picker's concrete model even for an implicit or stale selection;
|
|
157
155
|
// otherwise its config or resumed thread can choose a different model.
|
|
158
156
|
// Validate effort and Fast mode against that same resolved row.
|
|
159
|
-
const pickedModel = sessionConfig?.model ??
|
|
160
|
-
const pickedEffort = sessionConfig?.effort ??
|
|
161
|
-
const pickedSpeedMode = sessionConfig?.speedMode ??
|
|
157
|
+
const pickedModel = sessionConfig?.model ?? defaults?.model
|
|
158
|
+
const pickedEffort = sessionConfig?.effort ?? defaults?.effort
|
|
159
|
+
const pickedSpeedMode = sessionConfig?.speedMode ?? defaults?.speedMode
|
|
162
160
|
const { model, effort, speedMode, stream } = resolveChatRunOptions(
|
|
163
161
|
modelsData,
|
|
164
162
|
pickedModel,
|
|
@@ -171,7 +169,6 @@ export function useChat(address: WorkspaceTabAddress) {
|
|
|
171
169
|
content: text,
|
|
172
170
|
sessionId: sid,
|
|
173
171
|
isNew,
|
|
174
|
-
selectedSessionScope: collabEnabled ? 'browser-tab' : 'shared',
|
|
175
172
|
optimisticId,
|
|
176
173
|
model,
|
|
177
174
|
effort,
|
|
@@ -191,15 +188,14 @@ export function useChat(address: WorkspaceTabAddress) {
|
|
|
191
188
|
selectedSessionId,
|
|
192
189
|
workspaceId,
|
|
193
190
|
qc,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
191
|
+
defaults?.model,
|
|
192
|
+
defaults?.effort,
|
|
193
|
+
defaults?.speedMode,
|
|
197
194
|
buildMoiContext,
|
|
198
195
|
sessionConfig?.model,
|
|
199
196
|
sessionConfig?.effort,
|
|
200
197
|
sessionConfig?.speedMode,
|
|
201
198
|
selectSession,
|
|
202
|
-
collabEnabled,
|
|
203
199
|
modelsData
|
|
204
200
|
]
|
|
205
201
|
)
|
|
@@ -8,7 +8,12 @@ import { IconPointer2 } from '@tabler/icons-react'
|
|
|
8
8
|
import { cn } from '@/client/lib/cn'
|
|
9
9
|
import { Badge } from '@/ui-components/badge'
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
presenceChannels,
|
|
13
|
+
usePresenceChannel,
|
|
14
|
+
usePresencePublisher,
|
|
15
|
+
useUsers
|
|
16
|
+
} from '../presence/hooks'
|
|
12
17
|
import { userDisplayName } from '@/client/lib/user-display-name'
|
|
13
18
|
import { hasPresence } from './presence-helpers'
|
|
14
19
|
|
|
@@ -5,7 +5,7 @@ import type { HTMLAttributes, ReactNode, Ref } from 'react'
|
|
|
5
5
|
import { motion } from 'motion/react'
|
|
6
6
|
import { cn } from '@/client/lib/cn'
|
|
7
7
|
import { PresenceGroupContext, usePresenceTarget, useTargetPresence } from './presence-helpers'
|
|
8
|
-
import { useUsers } from '../hooks'
|
|
8
|
+
import { useUsers } from '../presence/hooks'
|
|
9
9
|
import { UserAvatar } from './user-avatar'
|
|
10
10
|
|
|
11
11
|
export function PresenceAvatarsContainer({
|
|
@@ -5,7 +5,7 @@ import type { HTMLAttributes, ReactNode, Ref } from 'react'
|
|
|
5
5
|
import { cn } from '@/client/lib/cn'
|
|
6
6
|
import type { UserColor } from '@/lib/collab/colors'
|
|
7
7
|
import { Badge } from '@/ui-components/badge'
|
|
8
|
-
import { useUsers } from '../hooks'
|
|
8
|
+
import { useUsers } from '../presence/hooks'
|
|
9
9
|
import { userDisplayName } from '@/client/lib/user-display-name'
|
|
10
10
|
import { usePresenceTarget, useTargetPresence } from './presence-helpers'
|
|
11
11
|
|
|
@@ -2,7 +2,7 @@ import type { PresenceGroupProps as PresenceGroupContainerProps } from 'moi/coll
|
|
|
2
2
|
import type { ReactNode } from 'react'
|
|
3
3
|
import { useContext, useId, useMemo } from 'react'
|
|
4
4
|
import { LayoutGroup, MotionConfig } from 'motion/react'
|
|
5
|
-
import { presenceTarget } from '../presence-target'
|
|
5
|
+
import { presenceTarget } from '../presence/presence-target'
|
|
6
6
|
import { PresenceGroupContext } from './presence-helpers'
|
|
7
7
|
|
|
8
8
|
export function PresenceGroupContainer({ id, children }: PresenceGroupContainerProps) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { JsonValue } from 'moi'
|
|
2
2
|
import { createContext, useContext, useLayoutEffect, useRef } from 'react'
|
|
3
3
|
import type { FocusEvent } from 'react'
|
|
4
|
-
import { presenceChannels, usePresenceChannel, usePresencePublisher } from '../hooks'
|
|
5
|
-
import { presenceTarget } from '../presence-target'
|
|
4
|
+
import { presenceChannels, usePresenceChannel, usePresencePublisher } from '../presence/hooks'
|
|
5
|
+
import { presenceTarget } from '../presence/presence-target'
|
|
6
6
|
|
|
7
7
|
export const hasPresence = (value: JsonValue) => value !== false && value !== null
|
|
8
8
|
|
|
@@ -3,7 +3,7 @@ import type { UserProfile } from '@/lib/collab/types'
|
|
|
3
3
|
import { AvatarGroup as AvatarGroupPrimitive, AvatarGroupCount } from '@/ui-components/avatar'
|
|
4
4
|
import { UserAvatar } from './user-avatar'
|
|
5
5
|
import type { UserAvatarProps } from './user-avatar'
|
|
6
|
-
import { useUsers } from '../hooks'
|
|
6
|
+
import { useUsers } from '../presence/hooks'
|
|
7
7
|
|
|
8
8
|
export function UserAvatarGroupContainer({ ids, ...props }: UserAvatarGroupContainerProps) {
|
|
9
9
|
const users = useUsers([...new Set(ids)])
|
|
@@ -5,7 +5,7 @@ import { Blobatar } from '@blobatar/react'
|
|
|
5
5
|
import { Avatar, AvatarBadge, AvatarFallback, AvatarImage } from '@/ui-components/avatar'
|
|
6
6
|
import { cn } from '@/client/lib/cn'
|
|
7
7
|
import { userDisplayName } from '@/client/lib/user-display-name'
|
|
8
|
-
import { useUser } from '../hooks'
|
|
8
|
+
import { useUser } from '../presence/hooks'
|
|
9
9
|
|
|
10
10
|
export function UserAvatarContainer({
|
|
11
11
|
id,
|
|
@@ -4,7 +4,7 @@ import type { UserProfile } from '@/lib/collab/types'
|
|
|
4
4
|
import { cn } from '@/client/lib/cn'
|
|
5
5
|
import { UserAvatar } from './user-avatar'
|
|
6
6
|
import { userDisplayName } from '@/client/lib/user-display-name'
|
|
7
|
-
import { useMe, useUser } from '../hooks'
|
|
7
|
+
import { useMe, useUser } from '../presence/hooks'
|
|
8
8
|
|
|
9
9
|
export function UserContainer({ id, showStatusBadge, showYouLabel, ...props }: UserContainerProps) {
|
|
10
10
|
const user = useUser(id)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { CollabProvider, AppletPresenceProvider
|
|
2
|
-
export {
|
|
3
|
-
export type { TabInfo } from './workspace-
|
|
1
|
+
export { CollabProvider, AppletPresenceProvider } from './presence/provider'
|
|
2
|
+
export { WorkspaceSharingMenu } from './sharing/workspace-sharing-menu'
|
|
3
|
+
export type { TabInfo } from './sharing/workspace-sharing-menu'
|
|
4
4
|
export { appletCollabApi } from './applet-api'
|
|
5
5
|
export type { AppletCollabApi } from './applet-api'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getWorkspaceApiBase } from '@/client/features/workspace/remote'
|
|
2
|
+
import { cloudRequest } from '../../account/api'
|
|
3
|
+
import { jsonRequest } from '@/client/api/http'
|
|
4
|
+
|
|
5
|
+
export const inviteWorkspaceMember = (id: string, email: string, workspaceName?: string) =>
|
|
6
|
+
cloudRequest(
|
|
7
|
+
`${getWorkspaceApiBase(id)}/invitations`,
|
|
8
|
+
jsonRequest('POST', { email, workspaceName })
|
|
9
|
+
)
|
|
10
|
+
export const removeWorkspaceMember = (id: string, membershipId: string) =>
|
|
11
|
+
cloudRequest(`${getWorkspaceApiBase(id)}/members/${encodeURIComponent(membershipId)}`, {
|
|
12
|
+
method: 'DELETE'
|
|
13
|
+
})
|
|
14
|
+
export const revokeWorkspaceInvitation = (id: string, invitationId: string) =>
|
|
15
|
+
cloudRequest(`${getWorkspaceApiBase(id)}/invitations/${encodeURIComponent(invitationId)}`, {
|
|
16
|
+
method: 'DELETE'
|
|
17
|
+
})
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
2
|
+
import type { WorkspaceLayoutResponse } from '@/lib/types'
|
|
3
|
+
import { useSyncExternalStore } from 'react'
|
|
4
|
+
import { useMutation, useMutationState, useQueryClient } from '@tanstack/react-query'
|
|
5
|
+
import { useWorkspaces } from '../../home/api'
|
|
6
|
+
import { getAccountGeneration } from '../../identity/store'
|
|
7
|
+
import { useIdentity } from '../../identity/use-identity'
|
|
8
|
+
import { getWorkspaceMembers, subscribeWorkspaceDirectory, updateWorkspaceMembers } from './store'
|
|
9
|
+
import { inviteWorkspaceMember, removeWorkspaceMember, revokeWorkspaceInvitation } from './api'
|
|
10
|
+
import type { WorkspaceMembers } from './types'
|
|
11
|
+
|
|
12
|
+
export type MembershipAction =
|
|
13
|
+
| { type: 'invite'; email: string }
|
|
14
|
+
| { type: 'remove'; membershipId: string }
|
|
15
|
+
| { type: 'revoke'; invitationId: string }
|
|
16
|
+
|
|
17
|
+
type PendingAction = { id: number; action: MembershipAction }
|
|
18
|
+
export function applyPendingMembership(
|
|
19
|
+
data: WorkspaceMembers | undefined,
|
|
20
|
+
actions: PendingAction[]
|
|
21
|
+
) {
|
|
22
|
+
if (!data) return undefined
|
|
23
|
+
let { members, invitations } = data
|
|
24
|
+
for (const { id, action } of actions) {
|
|
25
|
+
if (action.type === 'remove')
|
|
26
|
+
members = members.filter(member => member.membershipId !== action.membershipId)
|
|
27
|
+
else if (action.type === 'revoke')
|
|
28
|
+
invitations = invitations.filter(invitation => invitation.id !== action.invitationId)
|
|
29
|
+
else if (!invitations.some(invitation => invitation.email === action.email))
|
|
30
|
+
invitations = [
|
|
31
|
+
...invitations,
|
|
32
|
+
{ id: `pending:${id}`, email: action.email, expiresAt: '', pending: true }
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
return { members, invitations }
|
|
36
|
+
}
|
|
37
|
+
// Member lists are published by the cloud host; this only reads what it last sent.
|
|
38
|
+
export function useWorkspaceMembers(workspaceId: string | undefined) {
|
|
39
|
+
// The owner-only list is built from the identity, so follow it too.
|
|
40
|
+
useIdentity()
|
|
41
|
+
const mutationKey = ['workspace-members-action', getAccountGeneration(), workspaceId]
|
|
42
|
+
const read = () => (workspaceId ? getWorkspaceMembers(workspaceId) : undefined)
|
|
43
|
+
const published = useSyncExternalStore(subscribeWorkspaceDirectory, read, read)
|
|
44
|
+
const pending = useMutationState({
|
|
45
|
+
filters: { mutationKey, status: 'pending', exact: true },
|
|
46
|
+
select: mutation => ({
|
|
47
|
+
id: mutation.state.submittedAt,
|
|
48
|
+
action: mutation.state.variables as MembershipAction
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
const data = applyPendingMembership(published, pending)
|
|
52
|
+
return {
|
|
53
|
+
data,
|
|
54
|
+
members: data?.members,
|
|
55
|
+
invitations: data?.invitations,
|
|
56
|
+
// Unknown until the host publishes its first snapshot for this account.
|
|
57
|
+
isPending: !published,
|
|
58
|
+
isSuccess: !!published
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export function useMembershipAction(workspaceId: string) {
|
|
62
|
+
const workspaces = useWorkspaces()
|
|
63
|
+
|
|
64
|
+
const identity = useIdentity()
|
|
65
|
+
const accountGeneration = getAccountGeneration()
|
|
66
|
+
const client = useQueryClient()
|
|
67
|
+
return useMutation({
|
|
68
|
+
mutationKey: ['workspace-members-action', accountGeneration, workspaceId],
|
|
69
|
+
mutationFn: async (action: MembershipAction) => {
|
|
70
|
+
if (
|
|
71
|
+
!identity ||
|
|
72
|
+
identity.type !== 'user' ||
|
|
73
|
+
identity.isAnonymous ||
|
|
74
|
+
accountGeneration !== getAccountGeneration()
|
|
75
|
+
)
|
|
76
|
+
throw new Error('Sign in to manage workspace members')
|
|
77
|
+
if (action.type === 'invite') {
|
|
78
|
+
const layout = client.getQueryData<WorkspaceLayoutResponse>(
|
|
79
|
+
workspaceKeys.layout(workspaceId)
|
|
80
|
+
)
|
|
81
|
+
const name = layout?.isRemote
|
|
82
|
+
? layout.name
|
|
83
|
+
: workspaces.data?.find(workspace => workspace.id === workspaceId)?.name
|
|
84
|
+
return inviteWorkspaceMember(workspaceId, action.email, name?.trim() || undefined)
|
|
85
|
+
}
|
|
86
|
+
if (action.type === 'remove') return removeWorkspaceMember(workspaceId, action.membershipId)
|
|
87
|
+
return revokeWorkspaceInvitation(workspaceId, action.invitationId)
|
|
88
|
+
},
|
|
89
|
+
// The optimistic overlay ends here, so keep its result until the host's next snapshot.
|
|
90
|
+
onSuccess: (_response, action) => {
|
|
91
|
+
if (accountGeneration !== getAccountGeneration()) return
|
|
92
|
+
updateWorkspaceMembers(workspaceId, current =>
|
|
93
|
+
applyPendingMembership(current, [{ id: Date.now(), action }])
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { replaceEqualDeep } from '@tanstack/query-core'
|
|
2
|
+
import { queryClient } from '@/client/api/query-client'
|
|
3
|
+
import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
4
|
+
import { getWorkspaceAddress } from '@/client/features/workspace/remote'
|
|
5
|
+
import { getIdentity, getAccountGeneration } from '../../identity/store'
|
|
6
|
+
import type { Identity } from '../../identity/types'
|
|
7
|
+
import { collabIdentityId, identityKey } from '../../identity/types'
|
|
8
|
+
import { normalizeUserProfile } from '../host-state'
|
|
9
|
+
import type { UserProfile } from '@/lib/collab/types'
|
|
10
|
+
import { parseWorkspaceMembers, validWorkspaceAddress } from './types'
|
|
11
|
+
import type { WorkspaceMembers, WorkspaceMembersSnapshot } from './types'
|
|
12
|
+
|
|
13
|
+
// The cloud host publishes every member list; Moi never fetches one. Lists are
|
|
14
|
+
// keyed by workspace address: `workspaceId` on the account's own machine,
|
|
15
|
+
// `ownerId:workspaceId` for a workspace someone shared with it.
|
|
16
|
+
type Published = {
|
|
17
|
+
accountGeneration: number
|
|
18
|
+
lists: Map<string, WorkspaceMembers>
|
|
19
|
+
// The host has sent a full snapshot, so a missing list has a meaning.
|
|
20
|
+
complete: boolean
|
|
21
|
+
}
|
|
22
|
+
let published: Published | undefined
|
|
23
|
+
// Lists belong to one account; a switch starts over.
|
|
24
|
+
function current(): Published {
|
|
25
|
+
const accountGeneration = getAccountGeneration()
|
|
26
|
+
if (published?.accountGeneration !== accountGeneration)
|
|
27
|
+
published = { accountGeneration, lists: new Map(), complete: false }
|
|
28
|
+
return published
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Revisions track membership writes so older cloud snapshots cannot replace them.
|
|
32
|
+
let membersRevision = 0
|
|
33
|
+
const listeners = new Set<() => void>()
|
|
34
|
+
function changed() {
|
|
35
|
+
membersRevision++
|
|
36
|
+
listeners.forEach(listener => listener())
|
|
37
|
+
}
|
|
38
|
+
export const getWorkspaceMembersRevision = () => membersRevision
|
|
39
|
+
|
|
40
|
+
const ownerSnapshots = new WeakMap<Identity, WorkspaceMembers>()
|
|
41
|
+
const NO_ACCESS: WorkspaceMembers = { members: [], invitations: [] }
|
|
42
|
+
const directoryCache = new WeakMap<WorkspaceMembers, readonly UserProfile[]>()
|
|
43
|
+
|
|
44
|
+
// No sharing record means owner-only on the account's own machine, and no
|
|
45
|
+
// access to someone else's. Unknown until the host has published its first snapshot.
|
|
46
|
+
function unlistedWorkspaceMembers(address: string): WorkspaceMembers | undefined {
|
|
47
|
+
if (!current().complete) return undefined
|
|
48
|
+
if (address.includes(':')) return NO_ACCESS
|
|
49
|
+
const owner = getIdentity()
|
|
50
|
+
if (owner?.type !== 'user' || owner.isAnonymous) return undefined
|
|
51
|
+
let snapshot = ownerSnapshots.get(owner)
|
|
52
|
+
if (!snapshot) {
|
|
53
|
+
snapshot = { members: [owner], invitations: [] }
|
|
54
|
+
ownerSnapshots.set(owner, snapshot)
|
|
55
|
+
}
|
|
56
|
+
return snapshot
|
|
57
|
+
}
|
|
58
|
+
// An unchanged list keeps its identity, so a repeated snapshot re-renders nothing.
|
|
59
|
+
function store(address: string, data: WorkspaceMembers) {
|
|
60
|
+
const { lists } = current()
|
|
61
|
+
lists.set(address, replaceEqualDeep(lists.get(address), data))
|
|
62
|
+
}
|
|
63
|
+
export function setWorkspaceMembers(address: string, value: WorkspaceMembers): void {
|
|
64
|
+
store(validWorkspaceAddress(address), parseWorkspaceMembers(value))
|
|
65
|
+
changed()
|
|
66
|
+
}
|
|
67
|
+
export function setAllWorkspaceMembers(value: WorkspaceMembersSnapshot[]): void {
|
|
68
|
+
if (!Array.isArray(value)) throw new Error('Invalid workspace members')
|
|
69
|
+
const snapshots = value.map(
|
|
70
|
+
workspace => [validWorkspaceAddress(workspace.id), parseWorkspaceMembers(workspace)] as const
|
|
71
|
+
)
|
|
72
|
+
const addresses = new Set(snapshots.map(([address]) => address))
|
|
73
|
+
if (addresses.size !== snapshots.length) throw new Error('Duplicate workspace id')
|
|
74
|
+
const { lists } = current()
|
|
75
|
+
for (const address of lists.keys()) if (!addresses.has(address)) lists.delete(address)
|
|
76
|
+
for (const [address, data] of snapshots) store(address, data)
|
|
77
|
+
current().complete = true
|
|
78
|
+
changed()
|
|
79
|
+
}
|
|
80
|
+
export function removeWorkspaceMembers(address: string) {
|
|
81
|
+
current().lists.delete(validWorkspaceAddress(address))
|
|
82
|
+
changed()
|
|
83
|
+
}
|
|
84
|
+
export function clearWorkspaceMembers() {
|
|
85
|
+
current().lists.clear()
|
|
86
|
+
changed()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// A confirmed change shows at once; the host's next snapshot replaces it.
|
|
90
|
+
export function updateWorkspaceMembers(
|
|
91
|
+
workspaceId: string,
|
|
92
|
+
update: (current: WorkspaceMembers) => WorkspaceMembers | undefined
|
|
93
|
+
): void {
|
|
94
|
+
const address = getWorkspaceAddress(workspaceId)
|
|
95
|
+
const before = current().lists.get(address) ?? unlistedWorkspaceMembers(address)
|
|
96
|
+
const after = before && update(before)
|
|
97
|
+
if (!after) return
|
|
98
|
+
store(address, after)
|
|
99
|
+
changed()
|
|
100
|
+
}
|
|
101
|
+
// A saved profile reaches the member lists it appears in before the host's event does.
|
|
102
|
+
export function refreshMemberProfile(identity: Identity): void {
|
|
103
|
+
const key = identityKey(identity)
|
|
104
|
+
for (const [address, list] of current().lists)
|
|
105
|
+
store(address, {
|
|
106
|
+
...list,
|
|
107
|
+
members: list.members.map(member =>
|
|
108
|
+
identityKey(member) === key
|
|
109
|
+
? { ...identity, ...(member.membershipId && { membershipId: member.membershipId }) }
|
|
110
|
+
: member
|
|
111
|
+
)
|
|
112
|
+
})
|
|
113
|
+
changed()
|
|
114
|
+
}
|
|
115
|
+
// What the host last published for this workspace; undefined until it has published anything.
|
|
116
|
+
export function getWorkspaceMembers(workspaceId: string): WorkspaceMembers | undefined {
|
|
117
|
+
const address = getWorkspaceAddress(workspaceId)
|
|
118
|
+
return current().lists.get(address) ?? unlistedWorkspaceMembers(address)
|
|
119
|
+
}
|
|
120
|
+
export function getWorkspaceDirectory(workspaceId: string): readonly UserProfile[] | undefined {
|
|
121
|
+
const data = getWorkspaceMembers(workspaceId)
|
|
122
|
+
if (!data) return undefined
|
|
123
|
+
let profiles = directoryCache.get(data)
|
|
124
|
+
if (!profiles) {
|
|
125
|
+
profiles = data.members.map(member =>
|
|
126
|
+
normalizeUserProfile({
|
|
127
|
+
id: collabIdentityId(member),
|
|
128
|
+
name: member.name || undefined,
|
|
129
|
+
avatar: member.avatar,
|
|
130
|
+
email: member.type === 'user' ? member.email || undefined : undefined
|
|
131
|
+
})
|
|
132
|
+
)
|
|
133
|
+
directoryCache.set(data, profiles)
|
|
134
|
+
}
|
|
135
|
+
return profiles
|
|
136
|
+
}
|
|
137
|
+
export function subscribeWorkspaceDirectory(listener: () => void) {
|
|
138
|
+
listeners.add(listener)
|
|
139
|
+
// Workspace info decides which address a workspace's list is published under.
|
|
140
|
+
const unsubscribe = queryClient.getQueryCache().subscribe(event => {
|
|
141
|
+
const [scope, kind] = event.query.queryKey
|
|
142
|
+
if (scope === workspaceKeys.all[0] && kind === 'layout') listener()
|
|
143
|
+
})
|
|
144
|
+
return () => {
|
|
145
|
+
listeners.delete(listener)
|
|
146
|
+
unsubscribe()
|
|
147
|
+
}
|
|
148
|
+
}
|