moi-computer 0.12.1-next.3 → 0.12.1-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bunfig.toml +1 -5
- package/client/api/app-config.ts +1 -2
- package/client/api/app-ui-keys.ts +3 -1
- package/client/api/http.ts +4 -1
- package/client/api/workspace-keys.ts +3 -3
- package/client/app/app-provider.tsx +22 -2
- package/client/app/app-router.tsx +4 -0
- package/client/app/routes/home-route.tsx +14 -0
- package/client/app/routes/onboarding-route.tsx +11 -0
- package/client/app/routes/settings-route.tsx +1 -1
- package/client/app/routes/workspace-route.tsx +21 -19
- package/client/components/shared/screen-shell.tsx +23 -0
- package/client/components/shared/ultrafast-icon.tsx +61 -0
- package/client/components/shared/workspace-icon.tsx +2 -2
- package/client/features/account/account-test-utils.tsx +4 -3
- package/client/features/app-settings/api.ts +33 -0
- package/client/features/app-settings/general-settings.tsx +39 -0
- package/client/features/{settings → app-settings}/settings-page.tsx +5 -1
- package/client/features/chat/applet-chat-intents.ts +4 -20
- package/client/features/chat/chat-send.ts +17 -13
- package/client/features/chat/composer/model-order.ts +8 -4
- package/client/features/chat/composer/model-picker.tsx +88 -34
- package/client/features/chat/composer/use-workspace-composer-state.tsx +11 -3
- package/client/features/chat/composer/use-workspace-skill-updates.ts +1 -1
- package/client/features/chat/connection/chat-frames.ts +3 -15
- package/client/features/chat/messages/chat-empty-state.tsx +1 -4
- package/client/features/chat/messages/fork-history.ts +5 -5
- package/client/features/chat/messages/turn-view.tsx +3 -12
- package/client/features/chat/messages/user-message-bubble.tsx +63 -0
- package/client/features/chat/sessions/api.ts +121 -80
- package/client/features/chat/sessions/browser-tab-state.ts +14 -12
- package/client/features/chat/sessions/chat-selector.tsx +5 -6
- package/client/features/chat/sessions/use-selected-session.ts +172 -257
- package/client/features/chat/use-chat.ts +14 -19
- package/client/features/collab/workspace-users-menu.tsx +1 -1
- package/client/features/demo/demo-dialog.tsx +11 -3
- package/client/features/dev/dev-index-page.tsx +5 -0
- package/client/features/dev/dev-routes.tsx +2 -0
- package/client/features/dev/harness-debug-page.tsx +3 -3
- package/client/features/dev/onboarding-preview-page.tsx +76 -0
- package/client/features/dev/workspace-setup-mocks.ts +16 -14
- package/client/features/dev/workspace-setup-preview.tsx +11 -17
- package/client/features/harness/api.ts +45 -15
- package/client/features/harness/device-login-steps.tsx +9 -3
- package/client/features/harness/harness-login-panel.tsx +228 -0
- package/client/features/harness/harness-presentation.ts +15 -0
- package/client/features/harness/harness-selector.tsx +119 -0
- package/client/features/harness/use-harness-login.ts +77 -0
- package/client/features/home/home-page.tsx +7 -7
- package/client/features/onboarding/agent-setup-step.tsx +57 -0
- package/client/features/onboarding/api.ts +42 -0
- package/client/features/onboarding/onboarding-idea-disk.tsx +129 -0
- package/client/features/onboarding/onboarding-page.tsx +32 -0
- package/client/features/onboarding/onboarding-screen.tsx +20 -0
- package/client/features/onboarding/onboarding-status.tsx +24 -0
- package/client/features/onboarding/workspace-setup-step.tsx +239 -0
- package/client/features/overview/default/registry.tsx +2 -2
- package/client/features/overview/default/views-widget.tsx +6 -5
- package/client/features/overview/overview.tsx +9 -11
- package/client/features/overview/widget-canvas.tsx +1 -1
- package/client/features/overview/workspace-name.tsx +2 -2
- package/client/features/views/api.ts +69 -16
- package/client/features/views/pending-view-screen.tsx +30 -9
- package/client/features/views/use-view-actions.ts +19 -20
- package/client/features/views/view-presentation.ts +2 -2
- package/client/features/views/view-submission.ts +28 -41
- package/client/features/workspace/add/api.ts +3 -23
- package/client/features/workspace/add/create-workspace-dialog.tsx +6 -5
- package/client/features/workspace/add/import-workspace-dialog.tsx +3 -3
- package/client/features/workspace/add/workspace-agent-options.ts +11 -12
- package/client/features/workspace/add/workspace-agent-selector.tsx +3 -132
- package/client/features/workspace/api.ts +32 -36
- package/client/features/workspace/harness-transition.ts +88 -0
- package/client/features/{settings → workspace/settings}/api.ts +1 -34
- package/client/features/{settings → workspace/settings}/general-settings.tsx +76 -2
- package/client/features/{settings → workspace/settings}/use-env-vars.ts +1 -1
- package/client/features/{settings → workspace/settings}/workspace-icon-picker.tsx +3 -3
- package/client/features/workspace/setup/workspace-login-state.tsx +37 -156
- package/client/features/workspace/setup/workspace-recovery-states.tsx +0 -12
- package/client/features/workspace/setup/workspace-setup.tsx +34 -14
- package/client/features/workspace/setup/workspace-welcome-state.tsx +2 -2
- package/client/features/workspace/use-workspace-navigation.ts +25 -9
- package/client/features/workspace/workspace-content.tsx +11 -8
- package/client/features/workspace/workspace-frame.tsx +2 -1
- package/client/features/workspace/workspace-layout-context.tsx +5 -2
- package/client/features/workspace/workspace-menu.tsx +12 -8
- package/client/features/workspace/workspace-pending-screen.tsx +10 -10
- package/client/features/workspace/workspace-presentation.tsx +5 -13
- package/client/features/workspace/workspace-state.ts +169 -0
- package/client/features/workspace/workspace-tabs.tsx +22 -2
- package/client/index.css +2 -0
- package/client/index.tsx +3 -3
- package/client/lib/flags.ts +1 -1
- package/client/lib/{app-icon-registry.ts → identity-icon-registry.ts} +10 -14
- package/client/runtime/workspace-events.ts +21 -4
- package/client/runtime/workspace-theme.ts +9 -0
- package/client/tailwind-config.ts +43 -0
- package/dist/chunk-0mjzg20x.js +2 -0
- package/dist/chunk-2y59vrxg.js +5 -0
- package/dist/chunk-58dyt9bk.js +2 -0
- package/dist/chunk-5aj040e5.css +1 -0
- package/dist/{chunk-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
- package/dist/chunk-71fn6rmj.js +546 -0
- package/dist/chunk-7yg1m8hx.js +2 -0
- package/dist/chunk-825hys3h.js +1 -0
- package/dist/chunk-9bb8m9rx.js +2 -0
- package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
- package/dist/chunk-g0tcwqxc.js +1 -0
- package/dist/chunk-n0nab26d.js +1 -0
- package/dist/chunk-nf2wkvf9.js +14 -0
- package/dist/chunk-v88n1bay.js +74 -0
- package/dist/index.html +1 -1
- package/lib/harness-instructions.ts +1 -1
- package/lib/{app-icons.ts → identity-icons.ts} +6 -7
- package/lib/onboarding.ts +41 -0
- package/lib/speed-mode.ts +5 -0
- package/lib/types.ts +71 -62
- package/lib/view-build-directives.ts +1 -2
- package/lib/workspace-icon.ts +2 -2
- package/lib/workspace-layout.ts +1 -1
- package/lib/workspace-name.ts +15 -12
- package/package.json +9 -8
- package/server/README.md +27 -25
- package/server/api/harnesses.ts +31 -8
- package/server/api/index.ts +163 -126
- package/server/api/onboarding.ts +46 -0
- package/server/app-config.ts +16 -24
- package/server/app-settings.ts +6 -2
- package/server/applets/config.ts +5 -5
- package/server/applets/views.ts +19 -17
- package/server/cli/commands/init.ts +3 -3
- package/server/cli/commands/skill.ts +16 -17
- package/server/cli/commands/start.ts +8 -34
- package/server/cli/server.ts +18 -6
- package/server/collab/config.ts +1 -2
- package/server/collab/manager.ts +4 -1
- package/server/collab/skill/index.ts +1 -1
- package/server/control.ts +3 -3
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +24 -8
- package/server/harness/acp/session.ts +8 -4
- package/server/harness/auth.ts +14 -17
- package/server/harness/claude-code/NOTES.md +4 -3
- package/server/harness/claude-code/index.ts +2 -0
- package/server/harness/claude-code/models.ts +2 -20
- package/server/harness/claude-code/run-action.ts +123 -0
- package/server/harness/claude-code/session-title.ts +5 -7
- package/server/harness/claude-code/session.ts +24 -16
- package/server/harness/codex/NOTES.md +14 -9
- package/server/harness/codex/adapter.ts +14 -17
- package/server/harness/codex/index.ts +2 -0
- package/server/harness/codex/run-action.ts +93 -0
- package/server/harness/codex/session-title.ts +6 -8
- package/server/harness/codex/session.ts +11 -11
- package/server/harness/command.ts +45 -0
- package/server/harness/executable.ts +5 -0
- package/server/harness/fork.ts +6 -4
- package/server/harness/install.ts +49 -0
- package/server/harness/openclaw/session.ts +1 -2
- package/server/harness/run-action.ts +85 -0
- package/server/harness/session-title.ts +0 -46
- package/server/harness/types.ts +26 -2
- package/server/onboarding/brief.ts +29 -0
- package/server/onboarding/ideas.ts +48 -0
- package/server/onboarding/jobs.ts +291 -0
- package/server/onboarding/prompt.md +49 -0
- package/server/sessions/archive.ts +5 -14
- package/server/sessions/config.ts +17 -16
- package/server/sessions/lifecycle.ts +15 -13
- package/server/sessions/pending-views.ts +79 -108
- package/server/sessions/selected.ts +75 -161
- package/server/sessions/store.ts +40 -113
- package/server/sessions/view-sessions.ts +128 -111
- package/server/skills/locations.ts +82 -0
- package/server/skills/lock.ts +29 -0
- package/server/skills/template.ts +36 -25
- package/server/skills/update.ts +52 -5
- package/server/skills/version.ts +17 -22
- package/server/skills/workspace.ts +121 -0
- package/server/web.ts +22 -8
- package/server/workspace-state/file.ts +177 -0
- package/server/workspace-state/index.ts +162 -0
- package/server/workspace-state/legacy-migration.ts +79 -0
- package/server/workspace-state/lock.ts +42 -0
- package/server/workspace-state/types.ts +16 -0
- package/server/workspaces/change-harness.ts +88 -0
- package/server/workspaces/harness-transition.ts +29 -0
- package/server/workspaces/init.ts +29 -6
- package/server/workspaces/layout.ts +3 -0
- package/server/workspaces/registry.ts +27 -1
- package/{workspace/.claude/skills/moi-workspace → skill}/SKILL.md +7 -5
- package/{workspace/.claude/skills/moi-workspace → skill}/references/COLLAB.md +4 -8
- package/skill/references/DESIGN.md +148 -0
- package/{workspace/.claude/skills/moi-workspace → skill}/references/SCRATCHPAD.md +2 -2
- package/{workspace/.claude/skills/moi-workspace → skill}/references/UI-COMPONENTS.md +3 -0
- package/ui-components/badge.tsx +1 -1
- package/client/accept-hmr-dependencies.ts +0 -22
- package/client/features/workspace/setup/workspace-setup-panel.tsx +0 -18
- package/dist/chunk-20ynagd4.js +0 -2
- package/dist/chunk-42tde9a6.js +0 -1
- package/dist/chunk-9w543s0r.js +0 -2
- package/dist/chunk-a5372n61.js +0 -546
- package/dist/chunk-aja9y1vn.js +0 -68
- package/dist/chunk-fvcvrh3d.css +0 -1
- package/dist/chunk-gtfjw3nx.js +0 -1
- package/dist/chunk-j39y2aky.js +0 -14
- package/dist/chunk-pcnahct1.js +0 -5
- package/dist/chunk-pja30km3.js +0 -1
- package/dist/chunk-rm894bc2.js +0 -2
- package/dist/chunk-tevvtfbk.js +0 -10
- package/dist/chunk-tgt9zd0r.js +0 -2
- package/dist/chunk-tv5k5z00.js +0 -1
- package/dist/chunk-zq2ae5dx.js +0 -2
- package/lib/experimental.ts +0 -14
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +0 -157
- /package/client/features/{settings → app-settings}/profile-settings.tsx +0 -0
- /package/client/features/{settings → app-settings}/settings-section.tsx +0 -0
- /package/client/features/{settings → app-settings}/users-settings.tsx +0 -0
- /package/client/features/{settings → workspace/settings}/connectors-settings.tsx +0 -0
- /package/client/features/{settings → workspace/settings}/environment-settings.tsx +0 -0
- /package/client/features/{settings → workspace/settings}/icon-picker-options.ts +0 -0
- /package/client/features/{settings → workspace/settings}/settings-layout.tsx +0 -0
- /package/client/features/{settings → workspace/settings}/workspace-settings-dialog.tsx +0 -0
- /package/{workspace/.claude/skills/moi-workspace → skill}/references/INTENTS.md +0 -0
|
@@ -1,39 +1,69 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
2
2
|
import type { QueryClient } from '@tanstack/react-query'
|
|
3
|
-
import { useCallback } from 'react'
|
|
3
|
+
import { useCallback, useMemo } from 'react'
|
|
4
4
|
|
|
5
|
-
import { jsonRequest, requestJson
|
|
6
|
-
import { WORKSPACE_RESOURCE_OPTIONS } from '@/client/api/query-options'
|
|
5
|
+
import { jsonRequest, requestJson } from '@/client/api/http'
|
|
7
6
|
import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
8
7
|
import { sessionViewOptions } from '@/client/features/chat/sessions/session-view'
|
|
9
8
|
import { readSelectedSession, writeSelectedSession } from './browser-tab-state'
|
|
10
9
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
browserTabSelectionKey,
|
|
11
|
+
browserTabSelectionOptions,
|
|
13
12
|
usePinnedSession,
|
|
14
13
|
useSelectedSession
|
|
15
14
|
} from './use-selected-session'
|
|
16
15
|
import { useCollabEnabled } from '@/client/features/collab'
|
|
17
16
|
import { useLatestRef } from '@/client/lib/use-latest-ref'
|
|
18
17
|
import { useWorkspaceId } from '@/client/features/workspace/workspace-context'
|
|
18
|
+
import {
|
|
19
|
+
changeWorkspaceStateCache,
|
|
20
|
+
clearSessionInState,
|
|
21
|
+
useWorkspaceState,
|
|
22
|
+
useWorkspaceStateWrite,
|
|
23
|
+
workspaceStateOptions
|
|
24
|
+
} from '@/client/features/workspace/workspace-state'
|
|
19
25
|
import type {
|
|
20
26
|
SessionConfig,
|
|
21
27
|
SessionInfo,
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
SessionSummary,
|
|
29
|
+
WorkspaceSessionState,
|
|
30
|
+
WorkspaceState,
|
|
24
31
|
WorkspaceTabId
|
|
25
32
|
} from '@/lib/types'
|
|
33
|
+
import type { BrowserTabSelection } from './browser-tab-state'
|
|
26
34
|
|
|
35
|
+
// The agent's chat list. Reading it makes the harness scan transcripts, so
|
|
36
|
+
// mounts within 30 s reuse it; harness `sessions_changed` frames refetch it,
|
|
37
|
+
// and focus picks up chats made outside Moi.
|
|
27
38
|
export function workspaceSessionsOptions(workspaceId: string) {
|
|
28
39
|
return {
|
|
29
40
|
queryKey: workspaceKeys.sessions(workspaceId),
|
|
30
|
-
queryFn: () => requestJson<
|
|
31
|
-
|
|
41
|
+
queryFn: () => requestJson<SessionSummary[]>(`/api/workspaces/${workspaceId}/sessions`),
|
|
42
|
+
staleTime: 30_000,
|
|
43
|
+
gcTime: 5 * 60_000,
|
|
44
|
+
refetchOnMount: true,
|
|
45
|
+
refetchOnWindowFocus: true
|
|
32
46
|
}
|
|
33
47
|
}
|
|
34
48
|
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
const selectSessionEntries = (state: WorkspaceState) => state.sessions
|
|
50
|
+
|
|
51
|
+
// List rows joined with the tab that owns each chat. Undefined until both
|
|
52
|
+
// have loaded, so view chats never flash in the overview.
|
|
53
|
+
export function useWorkspaceSessions(workspaceId: string): { data: SessionInfo[] | undefined } {
|
|
54
|
+
const list = useQuery(workspaceSessionsOptions(workspaceId)).data
|
|
55
|
+
const entries = useWorkspaceState(workspaceId, selectSessionEntries).data
|
|
56
|
+
const data = useMemo(
|
|
57
|
+
() =>
|
|
58
|
+
list && entries
|
|
59
|
+
? list.map(session => {
|
|
60
|
+
const tabId = entries[session.sessionId]?.tabId
|
|
61
|
+
return tabId ? { ...session, tabId } : session
|
|
62
|
+
})
|
|
63
|
+
: undefined,
|
|
64
|
+
[list, entries]
|
|
65
|
+
)
|
|
66
|
+
return { data }
|
|
37
67
|
}
|
|
38
68
|
|
|
39
69
|
// Select the linked chat on the destination tab, unpinning a different chat first.
|
|
@@ -42,47 +72,58 @@ export function useSelectLinkedChat() {
|
|
|
42
72
|
const queryClient = useQueryClient()
|
|
43
73
|
const collabEnabled = useCollabEnabled()
|
|
44
74
|
const [, , selectSessionForTab] = useSelectedSession()
|
|
45
|
-
const {
|
|
46
|
-
const stateRef = useLatestRef({ collabEnabled, selectSessionForTab,
|
|
75
|
+
const { unpinAsync } = usePinnedSession()
|
|
76
|
+
const stateRef = useLatestRef({ collabEnabled, selectSessionForTab, unpinAsync })
|
|
47
77
|
// Stable so selection updates do not restart a pending chat link.
|
|
48
78
|
return useCallback(
|
|
49
|
-
async (
|
|
50
|
-
|
|
79
|
+
async (
|
|
80
|
+
sessionId: string,
|
|
81
|
+
tab: WorkspaceTabId,
|
|
82
|
+
signal: AbortSignal
|
|
83
|
+
): Promise<WorkspaceTabId | undefined> => {
|
|
84
|
+
const { collabEnabled, selectSessionForTab, unpinAsync } = stateRef.current
|
|
51
85
|
signal.throwIfAborted()
|
|
52
86
|
let sessions =
|
|
53
|
-
queryClient.getQueryData<
|
|
87
|
+
queryClient.getQueryData<SessionSummary[]>(workspaceKeys.sessions(workspaceId)) ?? []
|
|
54
88
|
if (!sessions.some(session => session.sessionId === sessionId))
|
|
55
|
-
|
|
89
|
+
// The chat may be newer than a cached list that is still fresh.
|
|
90
|
+
sessions = await queryClient.fetchQuery({
|
|
91
|
+
...workspaceSessionsOptions(workspaceId),
|
|
92
|
+
staleTime: 0
|
|
93
|
+
})
|
|
56
94
|
signal.throwIfAborted()
|
|
57
|
-
if (!sessions.some(session => session.sessionId === sessionId)) return
|
|
58
|
-
await queryClient.ensureQueryData(
|
|
59
|
-
|
|
60
|
-
|
|
95
|
+
if (!sessions.some(session => session.sessionId === sessionId)) return undefined
|
|
96
|
+
const state = await queryClient.ensureQueryData(
|
|
97
|
+
workspaceStateOptions(queryClient, workspaceId)
|
|
98
|
+
)
|
|
99
|
+
if (collabEnabled) await queryClient.ensureQueryData(browserTabSelectionOptions(workspaceId))
|
|
61
100
|
signal.throwIfAborted()
|
|
62
|
-
const pinned =
|
|
63
|
-
|
|
64
|
-
|
|
101
|
+
const pinned = state.pinnedSessionId
|
|
102
|
+
const destination =
|
|
103
|
+
pinned === sessionId ? tab : (state.sessions[sessionId]?.tabId ?? 'overview')
|
|
65
104
|
if (pinned && pinned !== sessionId) {
|
|
66
|
-
await
|
|
105
|
+
await unpinAsync()
|
|
67
106
|
signal.throwIfAborted()
|
|
68
107
|
}
|
|
69
108
|
if (pinned !== sessionId) {
|
|
70
|
-
await selectSessionForTab(sessionId,
|
|
109
|
+
await selectSessionForTab(sessionId, destination)
|
|
71
110
|
signal.throwIfAborted()
|
|
72
111
|
}
|
|
73
|
-
return
|
|
112
|
+
return destination
|
|
74
113
|
},
|
|
75
114
|
[queryClient, stateRef, workspaceId]
|
|
76
115
|
)
|
|
77
116
|
}
|
|
78
117
|
|
|
79
|
-
export function removeArchivedSession(
|
|
80
|
-
sessions:
|
|
118
|
+
export function removeArchivedSession<T extends SessionSummary>(
|
|
119
|
+
sessions: T[] | undefined,
|
|
81
120
|
sessionId: string
|
|
82
|
-
):
|
|
121
|
+
): T[] | undefined {
|
|
83
122
|
return sessions?.filter(session => session.sessionId !== sessionId)
|
|
84
123
|
}
|
|
85
124
|
|
|
125
|
+
// Drop an archived chat everywhere this browser keeps it. The server's state
|
|
126
|
+
// arrives with the archive reply or a `state:changed` event.
|
|
86
127
|
export function applyArchivedSession(
|
|
87
128
|
queryClient: QueryClient,
|
|
88
129
|
workspaceId: string,
|
|
@@ -90,47 +131,39 @@ export function applyArchivedSession(
|
|
|
90
131
|
) {
|
|
91
132
|
const sessionsKey = workspaceKeys.sessions(workspaceId)
|
|
92
133
|
void queryClient.cancelQueries({ queryKey: sessionsKey })
|
|
93
|
-
queryClient.setQueryData<
|
|
134
|
+
queryClient.setQueryData<SessionSummary[]>(sessionsKey, current =>
|
|
94
135
|
removeArchivedSession(current, sessionId)
|
|
95
136
|
)
|
|
96
137
|
queryClient.removeQueries({ queryKey: workspaceKeys.events(workspaceId, sessionId) })
|
|
97
|
-
queryClient
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (scope === 'browser-tab') selected[tabId] = null
|
|
111
|
-
else delete selected[tabId]
|
|
112
|
-
}
|
|
113
|
-
if (!changed) continue
|
|
114
|
-
const next = { selected, pinned: current.pinned === sessionId ? null : current.pinned }
|
|
115
|
-
queryClient.setQueryData(key, next)
|
|
116
|
-
if (scope === 'browser-tab') writeSelectedSession(workspaceId, next)
|
|
117
|
-
}
|
|
118
|
-
void queryClient.invalidateQueries({ queryKey: selectedSessionKey(workspaceId), exact: true })
|
|
138
|
+
changeWorkspaceStateCache(queryClient, workspaceId, draft =>
|
|
139
|
+
clearSessionInState(draft, sessionId)
|
|
140
|
+
)
|
|
141
|
+
const localKey = browserTabSelectionKey(workspaceId)
|
|
142
|
+
const local =
|
|
143
|
+
queryClient.getQueryData<BrowserTabSelection>(localKey) ?? readSelectedSession(workspaceId)
|
|
144
|
+
if (!Object.values(local.selected).includes(sessionId)) return
|
|
145
|
+
// An explicit empty local choice prevents falling back to the server's chat.
|
|
146
|
+
const selected = Object.fromEntries(
|
|
147
|
+
Object.entries(local.selected).map(([tabId, id]) => [tabId, id === sessionId ? null : id])
|
|
148
|
+
)
|
|
149
|
+
queryClient.setQueryData<BrowserTabSelection>(localKey, { selected })
|
|
150
|
+
writeSelectedSession(workspaceId, { selected })
|
|
119
151
|
}
|
|
120
152
|
|
|
121
153
|
export function useArchiveWorkspaceSession(workspaceId: string) {
|
|
122
154
|
const queryClient = useQueryClient()
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
`/api/workspaces/${workspaceId}/sessions/${sessionId}/archive`,
|
|
155
|
+
return useWorkspaceStateWrite<string>(workspaceId, {
|
|
156
|
+
request: sessionId =>
|
|
157
|
+
requestJson<WorkspaceState>(
|
|
158
|
+
`/api/workspaces/${workspaceId}/sessions/${encodeURIComponent(sessionId)}/archive`,
|
|
127
159
|
{ method: 'POST' },
|
|
128
160
|
'Couldn’t archive chat'
|
|
129
161
|
),
|
|
130
|
-
onSuccess: (
|
|
162
|
+
onSuccess: (_state, sessionId) => {
|
|
131
163
|
applyArchivedSession(queryClient, workspaceId, sessionId)
|
|
132
|
-
queryClient.invalidateQueries({ queryKey: workspaceKeys.previews })
|
|
133
|
-
}
|
|
164
|
+
void queryClient.invalidateQueries({ queryKey: workspaceKeys.previews })
|
|
165
|
+
},
|
|
166
|
+
errorTitle: 'Couldn’t archive chat'
|
|
134
167
|
})
|
|
135
168
|
}
|
|
136
169
|
|
|
@@ -141,29 +174,37 @@ export function useSessionView(workspaceId: string, sessionId: string | null) {
|
|
|
141
174
|
})
|
|
142
175
|
}
|
|
143
176
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
refetchOnWindowFocus: false
|
|
153
|
-
})
|
|
177
|
+
const NO_SESSION: WorkspaceSessionState = {}
|
|
178
|
+
|
|
179
|
+
// Moi's record of one chat: tab, settings, fork history. Undefined until the
|
|
180
|
+
// workspace state loads; a chat without a record reads as empty.
|
|
181
|
+
export function useSessionState(workspaceId: string, sessionId: string | null) {
|
|
182
|
+
return useWorkspaceState(workspaceId, state =>
|
|
183
|
+
sessionId ? (state.sessions[sessionId] ?? NO_SESSION) : NO_SESSION
|
|
184
|
+
)
|
|
154
185
|
}
|
|
155
186
|
|
|
187
|
+
// null clears a setting; undefined leaves it unchanged.
|
|
188
|
+
export type SessionConfigPatch = { [Key in keyof SessionConfig]?: SessionConfig[Key] | null }
|
|
189
|
+
|
|
156
190
|
export function useSaveSessionConfig(workspaceId: string) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
jsonRequest('PUT', patch),
|
|
191
|
+
return useWorkspaceStateWrite<{ sessionId: string; patch: SessionConfigPatch }>(workspaceId, {
|
|
192
|
+
request: ({ sessionId, patch }) =>
|
|
193
|
+
requestJson<WorkspaceState>(
|
|
194
|
+
`/api/workspaces/${workspaceId}/sessions/${encodeURIComponent(sessionId)}/config`,
|
|
195
|
+
jsonRequest('PATCH', patch),
|
|
163
196
|
'Failed to save chat settings'
|
|
164
197
|
),
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
198
|
+
optimistic: (draft, { sessionId, patch }) => {
|
|
199
|
+
const session = (draft.sessions[sessionId] ??= {})
|
|
200
|
+
const config: SessionConfig = { ...session.config }
|
|
201
|
+
for (const key of ['model', 'effort', 'speedMode'] as const) {
|
|
202
|
+
const value = patch[key]
|
|
203
|
+
if (value === null) delete config[key]
|
|
204
|
+
else if (value !== undefined) Object.assign(config, { [key]: value })
|
|
205
|
+
}
|
|
206
|
+
session.config = config
|
|
207
|
+
},
|
|
208
|
+
errorTitle: 'Couldn’t save chat settings'
|
|
168
209
|
})
|
|
169
210
|
}
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
const keyFor = (workspaceId: string) => `moi:collab:${workspaceId}:session`
|
|
4
|
-
const emptySelection = (): WorkspaceSessionSelection => ({ selected: {}, pinned: null })
|
|
1
|
+
import type { WorkspaceTabId } from '@/lib/types'
|
|
5
2
|
|
|
6
3
|
// Collab keeps each browser tab's unpinned chat choice, including a separate
|
|
7
4
|
// selection for every workspace tab. The workspace pin remains server-owned.
|
|
8
|
-
export
|
|
5
|
+
export type BrowserTabSelection = {
|
|
6
|
+
// A browser tab can explicitly choose an empty chat (null). An absent key
|
|
7
|
+
// inherits the server selection, including CLI-created view handoffs.
|
|
8
|
+
selected: Partial<Record<WorkspaceTabId, string | null>>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const keyFor = (workspaceId: string) => `moi:collab:${workspaceId}:session`
|
|
12
|
+
const emptySelection = (): BrowserTabSelection => ({ selected: {} })
|
|
13
|
+
|
|
14
|
+
export function readSelectedSession(workspaceId: string): BrowserTabSelection {
|
|
9
15
|
try {
|
|
10
16
|
const saved = sessionStorage.getItem(keyFor(workspaceId))
|
|
11
17
|
if (!saved) return emptySelection()
|
|
12
18
|
// The first Collab build stored only the overview chat ID.
|
|
13
|
-
if (!saved.startsWith('{')) return { selected: { overview: saved }
|
|
19
|
+
if (!saved.startsWith('{')) return { selected: { overview: saved } }
|
|
14
20
|
const value: unknown = JSON.parse(saved)
|
|
15
21
|
if (!value || typeof value !== 'object' || !('selected' in value)) return emptySelection()
|
|
16
22
|
const selected = (value as { selected: unknown }).selected
|
|
@@ -21,18 +27,14 @@ export function readSelectedSession(workspaceId: string): WorkspaceSessionSelect
|
|
|
21
27
|
Object.entries(selected).filter(
|
|
22
28
|
([, sessionId]) => typeof sessionId === 'string' || sessionId === null
|
|
23
29
|
)
|
|
24
|
-
)
|
|
25
|
-
pinned: null
|
|
30
|
+
)
|
|
26
31
|
}
|
|
27
32
|
} catch {
|
|
28
33
|
return emptySelection()
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
export function writeSelectedSession(
|
|
33
|
-
workspaceId: string,
|
|
34
|
-
selection: WorkspaceSessionSelection
|
|
35
|
-
): void {
|
|
37
|
+
export function writeSelectedSession(workspaceId: string, selection: BrowserTabSelection): void {
|
|
36
38
|
try {
|
|
37
39
|
sessionStorage.setItem(keyFor(workspaceId), JSON.stringify({ selected: selection.selected }))
|
|
38
40
|
} catch {
|
|
@@ -2,7 +2,7 @@ import { useRef, useState } from 'react'
|
|
|
2
2
|
import { IconArchive, IconEdit, IconHistory, IconPin, IconPinFilled } from '@tabler/icons-react'
|
|
3
3
|
|
|
4
4
|
import { useArchiveWorkspaceSession, useWorkspaceSessions } from './api'
|
|
5
|
-
import {
|
|
5
|
+
import { useWorkspaceHarness } from '@/client/features/workspace/api'
|
|
6
6
|
import { useWorkspaceId } from '@/client/features/workspace/workspace-context'
|
|
7
7
|
import {
|
|
8
8
|
useSelectedSession,
|
|
@@ -14,7 +14,6 @@ import { isSessionRunning, liveStore, useLive } from '@/client/features/chat/cha
|
|
|
14
14
|
import type { SessionInfo, WorkspaceTabId } from '@/lib/types'
|
|
15
15
|
|
|
16
16
|
import { Button } from '@/client/components/ui/button'
|
|
17
|
-
import { toast } from '@/client/components/ui/toast'
|
|
18
17
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
|
|
19
18
|
import {
|
|
20
19
|
DropdownMenu,
|
|
@@ -89,7 +88,7 @@ export function ChatSessionItem({
|
|
|
89
88
|
try {
|
|
90
89
|
await onArchive(session.sessionId)
|
|
91
90
|
} catch {
|
|
92
|
-
|
|
91
|
+
// The archive request already reported the failure.
|
|
93
92
|
} finally {
|
|
94
93
|
pendingRef.current = false
|
|
95
94
|
setPending(false)
|
|
@@ -248,7 +247,7 @@ export function groupSessionsForTab(
|
|
|
248
247
|
|
|
249
248
|
export function ChatSelector({ className }: ChatSelectorProps) {
|
|
250
249
|
const workspaceId = useWorkspaceId()
|
|
251
|
-
const { pinnedSessionId, loaded, pin } = usePinnedSession()
|
|
250
|
+
const { pinnedSessionId, loaded, pin, unpin } = usePinnedSession()
|
|
252
251
|
const [selectedSessionId] = useSelectedSession()
|
|
253
252
|
const { data: sessions = [] } = useWorkspaceSessions(workspaceId)
|
|
254
253
|
if (!loaded) return null
|
|
@@ -271,7 +270,7 @@ export function ChatSelector({ className }: ChatSelectorProps) {
|
|
|
271
270
|
variant="ghost"
|
|
272
271
|
size="icon-sm"
|
|
273
272
|
className={className}
|
|
274
|
-
onClick={
|
|
273
|
+
onClick={unpin}
|
|
275
274
|
aria-label="Unpin chat"
|
|
276
275
|
aria-pressed={true}
|
|
277
276
|
>
|
|
@@ -316,7 +315,7 @@ function SessionSelector({ className, sessions }: SessionSelectorProps) {
|
|
|
316
315
|
const tabId = useCurrentTabId()
|
|
317
316
|
const [selectedSessionId, selectSession] = useSelectedSession()
|
|
318
317
|
const [confirmingSessionId, setConfirmingSessionId] = useState<string | null>(null)
|
|
319
|
-
const canArchive =
|
|
318
|
+
const canArchive = useWorkspaceHarness(workspaceId).data?.supportsArchiving === true
|
|
320
319
|
const archiveSession = useArchiveWorkspaceSession(workspaceId)
|
|
321
320
|
const sessionGroups = groupSessionsForTab(sessions, tabId)
|
|
322
321
|
|