moi-computer 0.12.1-next.2 → 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.
Files changed (243) hide show
  1. package/bunfig.toml +1 -5
  2. package/client/api/app-config.ts +1 -2
  3. package/client/api/app-ui-keys.ts +3 -1
  4. package/client/api/http.ts +4 -1
  5. package/client/api/workspace-keys.ts +3 -3
  6. package/client/app/app-provider.tsx +22 -2
  7. package/client/app/app-router.tsx +6 -0
  8. package/client/app/routes/home-route.tsx +14 -0
  9. package/client/app/routes/onboarding-route.tsx +11 -0
  10. package/client/app/routes/settings-route.tsx +10 -0
  11. package/client/app/routes/workspace-route.tsx +21 -19
  12. package/client/app/shell/sidebar-layout.tsx +34 -53
  13. package/client/components/shared/screen-shell.tsx +23 -0
  14. package/client/components/shared/ultrafast-icon.tsx +61 -0
  15. package/client/components/shared/workspace-icon.tsx +2 -2
  16. package/client/features/account/account-menu.tsx +96 -0
  17. package/client/features/account/account-provider.tsx +142 -0
  18. package/client/features/account/account-test-utils.tsx +294 -0
  19. package/client/features/account/api.ts +142 -0
  20. package/client/features/account/identity.ts +23 -0
  21. package/client/features/app-settings/api.ts +33 -0
  22. package/client/features/app-settings/general-settings.tsx +39 -0
  23. package/client/features/app-settings/profile-settings.tsx +95 -0
  24. package/client/features/app-settings/settings-page.tsx +48 -0
  25. package/client/features/app-settings/settings-section.tsx +26 -0
  26. package/client/features/app-settings/users-settings.tsx +195 -0
  27. package/client/features/chat/applet-chat-intents.ts +4 -20
  28. package/client/features/chat/chat-send.ts +17 -13
  29. package/client/features/chat/composer/model-order.ts +8 -4
  30. package/client/features/chat/composer/model-picker.tsx +88 -34
  31. package/client/features/chat/composer/use-workspace-composer-state.tsx +11 -3
  32. package/client/features/chat/composer/use-workspace-skill-updates.ts +1 -1
  33. package/client/features/chat/connection/chat-frames.ts +3 -15
  34. package/client/features/chat/messages/chat-empty-state.tsx +1 -4
  35. package/client/features/chat/messages/fork-history.ts +5 -5
  36. package/client/features/chat/messages/turn-view.tsx +3 -12
  37. package/client/features/chat/messages/user-message-bubble.tsx +63 -0
  38. package/client/features/chat/sessions/api.ts +121 -80
  39. package/client/features/chat/sessions/browser-tab-state.ts +14 -12
  40. package/client/features/chat/sessions/chat-selector.tsx +5 -6
  41. package/client/features/chat/sessions/use-selected-session.ts +172 -257
  42. package/client/features/chat/use-chat.ts +14 -19
  43. package/client/features/collab/applet-api.ts +15 -14
  44. package/client/features/collab/components/cursors.tsx +61 -24
  45. package/client/features/collab/components/presence-avatars.tsx +25 -12
  46. package/client/features/collab/components/presence-frame.tsx +20 -24
  47. package/client/features/collab/components/presence-group.tsx +15 -7
  48. package/client/features/collab/components/user-avatar-group.tsx +21 -8
  49. package/client/features/collab/components/user-avatar.tsx +38 -7
  50. package/client/features/collab/components/user.tsx +31 -12
  51. package/client/features/collab/users.ts +0 -5
  52. package/client/features/collab/workspace-users-menu.tsx +4 -4
  53. package/client/features/demo/demo-dialog.tsx +11 -3
  54. package/client/features/dev/collab/collab-playground.tsx +7 -7
  55. package/client/features/dev/collab/local-user-settings.tsx +7 -53
  56. package/client/features/dev/dev-index-page.tsx +5 -0
  57. package/client/features/dev/dev-routes.tsx +2 -0
  58. package/client/features/dev/harness-debug-page.tsx +3 -3
  59. package/client/features/dev/onboarding-preview-page.tsx +76 -0
  60. package/client/features/dev/workspace-setup-mocks.ts +16 -14
  61. package/client/features/dev/workspace-setup-preview.tsx +11 -17
  62. package/client/features/harness/api.ts +45 -15
  63. package/client/features/harness/device-login-steps.tsx +9 -3
  64. package/client/features/harness/harness-login-panel.tsx +228 -0
  65. package/client/features/harness/harness-presentation.ts +15 -0
  66. package/client/features/harness/harness-selector.tsx +119 -0
  67. package/client/features/harness/use-harness-login.ts +77 -0
  68. package/client/features/home/home-page.tsx +7 -7
  69. package/client/features/onboarding/agent-setup-step.tsx +57 -0
  70. package/client/features/onboarding/api.ts +42 -0
  71. package/client/features/onboarding/onboarding-idea-disk.tsx +129 -0
  72. package/client/features/onboarding/onboarding-page.tsx +32 -0
  73. package/client/features/onboarding/onboarding-screen.tsx +20 -0
  74. package/client/features/onboarding/onboarding-status.tsx +24 -0
  75. package/client/features/onboarding/workspace-setup-step.tsx +239 -0
  76. package/client/features/overview/default/registry.tsx +2 -2
  77. package/client/features/overview/default/views-widget.tsx +6 -5
  78. package/client/features/overview/overview.tsx +9 -11
  79. package/client/features/overview/widget-canvas.tsx +1 -1
  80. package/client/features/overview/workspace-name.tsx +2 -2
  81. package/client/features/update/update-control.tsx +1 -1
  82. package/client/features/views/api.ts +69 -16
  83. package/client/features/views/pending-view-screen.tsx +30 -9
  84. package/client/features/views/use-view-actions.ts +19 -20
  85. package/client/features/views/view-presentation.ts +2 -2
  86. package/client/features/views/view-submission.ts +28 -41
  87. package/client/features/workspace/add/api.ts +3 -23
  88. package/client/features/workspace/add/create-workspace-dialog.tsx +11 -7
  89. package/client/features/workspace/add/import-workspace-dialog.tsx +3 -3
  90. package/client/features/workspace/add/workspace-agent-options.ts +11 -12
  91. package/client/features/workspace/add/workspace-agent-selector.tsx +3 -132
  92. package/client/features/workspace/api.ts +32 -36
  93. package/client/features/workspace/harness-transition.ts +88 -0
  94. package/client/features/{settings → workspace/settings}/api.ts +1 -34
  95. package/client/features/{settings → workspace/settings}/connectors-settings.tsx +3 -3
  96. package/client/features/{settings → workspace/settings}/environment-settings.tsx +3 -3
  97. package/client/features/{settings → workspace/settings}/general-settings.tsx +77 -3
  98. package/client/features/{settings → workspace/settings}/use-env-vars.ts +1 -1
  99. package/client/features/{settings → workspace/settings}/workspace-icon-picker.tsx +3 -3
  100. package/client/features/workspace/setup/workspace-login-state.tsx +37 -156
  101. package/client/features/workspace/setup/workspace-recovery-states.tsx +0 -12
  102. package/client/features/workspace/setup/workspace-setup.tsx +34 -14
  103. package/client/features/workspace/setup/workspace-welcome-state.tsx +2 -2
  104. package/client/features/workspace/use-workspace-navigation.ts +25 -9
  105. package/client/features/workspace/workspace-content.tsx +11 -8
  106. package/client/features/workspace/workspace-frame.tsx +2 -1
  107. package/client/features/workspace/workspace-layout-context.tsx +5 -2
  108. package/client/features/workspace/workspace-menu.tsx +12 -8
  109. package/client/features/workspace/workspace-pending-screen.tsx +10 -10
  110. package/client/features/workspace/workspace-presentation.tsx +5 -13
  111. package/client/features/workspace/workspace-state.ts +169 -0
  112. package/client/features/workspace/workspace-tabs.tsx +22 -2
  113. package/client/index.css +2 -0
  114. package/client/index.tsx +3 -3
  115. package/client/lib/flags.ts +1 -1
  116. package/client/lib/{app-icon-registry.ts → identity-icon-registry.ts} +10 -14
  117. package/client/lib/user-display-name.ts +6 -0
  118. package/client/main.tsx +4 -1
  119. package/client/runtime/workspace-events.ts +21 -4
  120. package/client/runtime/workspace-theme.ts +9 -0
  121. package/client/tailwind-config.ts +43 -0
  122. package/dist/chunk-0mjzg20x.js +2 -0
  123. package/dist/chunk-2y59vrxg.js +5 -0
  124. package/dist/chunk-58dyt9bk.js +2 -0
  125. package/dist/chunk-5aj040e5.css +1 -0
  126. package/dist/{chunk-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
  127. package/dist/chunk-71fn6rmj.js +546 -0
  128. package/dist/chunk-7yg1m8hx.js +2 -0
  129. package/dist/chunk-825hys3h.js +1 -0
  130. package/dist/chunk-9bb8m9rx.js +2 -0
  131. package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
  132. package/dist/chunk-g0tcwqxc.js +1 -0
  133. package/dist/chunk-n0nab26d.js +1 -0
  134. package/dist/chunk-nf2wkvf9.js +14 -0
  135. package/dist/chunk-v88n1bay.js +74 -0
  136. package/dist/index.html +1 -1
  137. package/lib/harness-instructions.ts +1 -1
  138. package/lib/{app-icons.ts → identity-icons.ts} +6 -7
  139. package/lib/onboarding.ts +41 -0
  140. package/lib/speed-mode.ts +5 -0
  141. package/lib/types.ts +72 -63
  142. package/lib/view-build-directives.ts +1 -2
  143. package/lib/workspace-icon.ts +2 -2
  144. package/lib/workspace-layout.ts +1 -1
  145. package/lib/workspace-name.ts +15 -12
  146. package/package.json +9 -8
  147. package/server/README.md +27 -25
  148. package/server/api/harnesses.ts +31 -8
  149. package/server/api/index.ts +164 -131
  150. package/server/api/onboarding.ts +46 -0
  151. package/server/app-config.ts +23 -24
  152. package/server/app-settings.ts +6 -2
  153. package/server/applets/config.ts +5 -5
  154. package/server/applets/views.ts +19 -17
  155. package/server/cli/commands/init.ts +3 -3
  156. package/server/cli/commands/skill.ts +16 -17
  157. package/server/cli/commands/start.ts +8 -34
  158. package/server/cli/server.ts +18 -6
  159. package/server/collab/config.ts +1 -2
  160. package/server/collab/manager.ts +4 -1
  161. package/server/collab/skill/index.ts +1 -1
  162. package/server/control.ts +3 -3
  163. package/server/data-dir.ts +1 -1
  164. package/server/harness/README.md +24 -8
  165. package/server/harness/acp/session.ts +8 -4
  166. package/server/harness/auth.ts +14 -17
  167. package/server/harness/claude-code/NOTES.md +4 -3
  168. package/server/harness/claude-code/index.ts +2 -0
  169. package/server/harness/claude-code/models.ts +2 -20
  170. package/server/harness/claude-code/run-action.ts +123 -0
  171. package/server/harness/claude-code/session-title.ts +5 -7
  172. package/server/harness/claude-code/session.ts +24 -16
  173. package/server/harness/codex/NOTES.md +14 -9
  174. package/server/harness/codex/adapter.ts +14 -17
  175. package/server/harness/codex/index.ts +2 -0
  176. package/server/harness/codex/run-action.ts +93 -0
  177. package/server/harness/codex/session-title.ts +6 -8
  178. package/server/harness/codex/session.ts +11 -11
  179. package/server/harness/command.ts +45 -0
  180. package/server/harness/executable.ts +5 -0
  181. package/server/harness/fork.ts +6 -4
  182. package/server/harness/install.ts +49 -0
  183. package/server/harness/openclaw/session.ts +1 -2
  184. package/server/harness/run-action.ts +85 -0
  185. package/server/harness/session-title.ts +0 -46
  186. package/server/harness/types.ts +26 -2
  187. package/server/onboarding/brief.ts +29 -0
  188. package/server/onboarding/ideas.ts +48 -0
  189. package/server/onboarding/jobs.ts +291 -0
  190. package/server/onboarding/prompt.md +49 -0
  191. package/server/sessions/archive.ts +5 -14
  192. package/server/sessions/config.ts +17 -16
  193. package/server/sessions/lifecycle.ts +15 -13
  194. package/server/sessions/pending-views.ts +79 -108
  195. package/server/sessions/selected.ts +75 -161
  196. package/server/sessions/store.ts +40 -113
  197. package/server/sessions/view-sessions.ts +128 -111
  198. package/server/skills/locations.ts +82 -0
  199. package/server/skills/lock.ts +29 -0
  200. package/server/skills/template.ts +36 -25
  201. package/server/skills/update.ts +52 -5
  202. package/server/skills/version.ts +17 -22
  203. package/server/skills/workspace.ts +121 -0
  204. package/server/web.ts +23 -8
  205. package/server/workspace-state/file.ts +177 -0
  206. package/server/workspace-state/index.ts +162 -0
  207. package/server/workspace-state/legacy-migration.ts +79 -0
  208. package/server/workspace-state/lock.ts +42 -0
  209. package/server/workspace-state/types.ts +16 -0
  210. package/server/workspaces/change-harness.ts +88 -0
  211. package/server/workspaces/harness-transition.ts +29 -0
  212. package/server/workspaces/init.ts +29 -16
  213. package/server/workspaces/layout.ts +3 -0
  214. package/server/workspaces/registry.ts +58 -10
  215. package/{workspace/.claude/skills/moi-workspace → skill}/SKILL.md +7 -5
  216. package/{workspace/.claude/skills/moi-workspace → skill}/references/COLLAB.md +4 -8
  217. package/skill/references/DESIGN.md +148 -0
  218. package/{workspace/.claude/skills/moi-workspace → skill}/references/SCRATCHPAD.md +2 -2
  219. package/{workspace/.claude/skills/moi-workspace → skill}/references/UI-COMPONENTS.md +3 -0
  220. package/ui-components/badge.tsx +1 -1
  221. package/client/accept-hmr-dependencies.ts +0 -22
  222. package/client/features/workspace/setup/workspace-setup-panel.tsx +0 -18
  223. package/dist/chunk-00rh9df4.js +0 -2
  224. package/dist/chunk-4nh7y1hq.css +0 -1
  225. package/dist/chunk-am4agx6v.js +0 -2
  226. package/dist/chunk-d7cbm65e.js +0 -2
  227. package/dist/chunk-hbpdv7vd.js +0 -1
  228. package/dist/chunk-hmka9rt5.js +0 -2
  229. package/dist/chunk-hvh9f5h0.js +0 -14
  230. package/dist/chunk-mjjregkn.js +0 -10
  231. package/dist/chunk-pcnahct1.js +0 -5
  232. package/dist/chunk-rt30jbcm.js +0 -1
  233. package/dist/chunk-vt6zybej.js +0 -2
  234. package/dist/chunk-wbkwf6cc.js +0 -68
  235. package/dist/chunk-xjyfyz64.js +0 -1
  236. package/dist/chunk-y8nbwp21.js +0 -546
  237. package/dist/chunk-ysfdcew7.js +0 -1
  238. package/lib/experimental.ts +0 -14
  239. package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +0 -157
  240. /package/client/features/{settings → workspace/settings}/icon-picker-options.ts +0 -0
  241. /package/client/features/{settings → workspace/settings}/settings-layout.tsx +0 -0
  242. /package/client/features/{settings → workspace/settings}/workspace-settings-dialog.tsx +0 -0
  243. /package/{workspace/.claude/skills/moi-workspace → skill}/references/INTENTS.md +0 -0
@@ -1,31 +1,27 @@
1
- import { useCollabEnabled } from '@/client/features/collab'
2
- import {
3
- readSelectedSession,
4
- writeSelectedSession
5
- } from '@/client/features/chat/sessions/browser-tab-state'
6
- import { useCallback, useMemo } from 'react'
1
+ import { useQuery, useQueryClient, type QueryClient } from '@tanstack/react-query'
2
+ import { useCallback } from 'react'
7
3
  import { useParams } from 'wouter'
8
- import { isWorkspaceTabId } from '@/lib/workspace-tabs'
9
- import type { WorkspaceSessionSelection, WorkspaceTabId } from '@/lib/types'
10
- import { composerDraftKey } from '@/lib/session-drafts'
11
- import { useUiStore } from '@/client/store/ui'
12
-
13
- import { useIsMutating, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
14
- import type { QueryClient } from '@tanstack/react-query'
15
4
 
16
5
  import { appUiKeys } from '@/client/api/app-ui-keys'
17
6
  import { jsonRequest, requestJson } from '@/client/api/http'
18
- import { toast } from '@/client/components/ui/toast'
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'
19
13
  import { useWorkspaceId } from '@/client/features/workspace/workspace-context'
20
- import { useWorkspaceEvent } from '@/client/runtime/use-workspace-events'
21
- import type { SelectedSessionScope, SelectedSessionState } from '@/lib/types'
22
-
23
- type SaveSelectedSessionInput = {
24
- sessionId: string | null
25
- previousSessionId: string | null
26
- tabId: WorkspaceTabId
27
- scope: SelectedSessionScope
28
- }
14
+ import {
15
+ changeWorkspaceStateCache,
16
+ getCachedWorkspaceState,
17
+ renameSessionInState,
18
+ useWorkspaceState,
19
+ useWorkspaceStateWrite
20
+ } from '@/client/features/workspace/workspace-state'
21
+ import { useUiStore } from '@/client/store/ui'
22
+ import { composerDraftKey } from '@/lib/session-drafts'
23
+ import type { SelectedSessionScope, WorkspaceState, WorkspaceTabId } from '@/lib/types'
24
+ import { isWorkspaceTabId } from '@/lib/workspace-tabs'
29
25
 
30
26
  type SetSelectedSession = (sessionId: string | null) => void
31
27
 
@@ -35,23 +31,25 @@ type SelectedSessionResult = readonly [
35
31
  selectSessionForTab: (sessionId: string, tabId: WorkspaceTabId) => Promise<void>
36
32
  ]
37
33
 
38
- export type SelectedSessionSaveResult = 'applied' | 'conflict' | 'ignored'
34
+ // PUT shows `sessionId` in the tab (only while it still shows `ifMatch`, when
35
+ // given); DELETE clears the tab if it still shows `sessionId`.
36
+ type SelectionWrite = {
37
+ sessionId: string
38
+ tabId: WorkspaceTabId
39
+ show: boolean
40
+ ifMatch?: string | null
41
+ }
39
42
 
40
- export function selectedSessionKey(workspaceId: string, scope: SelectedSessionScope = 'shared') {
41
- const key = appUiKeys.sessionSelection(workspaceId)
42
- return scope === 'browser-tab' ? ([...key, 'browser-tab'] as const) : key
43
+ export function browserTabSelectionKey(workspaceId: string) {
44
+ return appUiKeys.browserTabSelection(workspaceId)
43
45
  }
44
46
 
45
- export function selectedSessionOptions(
46
- workspaceId: string,
47
- scope: SelectedSessionScope = 'shared'
48
- ) {
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) {
49
50
  return {
50
- queryKey: selectedSessionKey(workspaceId, scope),
51
- queryFn: () =>
52
- scope === 'browser-tab'
53
- ? Promise.resolve(readSelectedSession(workspaceId))
54
- : requestJson<WorkspaceSessionSelection>(`/api/workspaces/${workspaceId}/selected-session`),
51
+ queryKey: browserTabSelectionKey(workspaceId),
52
+ queryFn: () => Promise.resolve(readSelectedSession(workspaceId)),
55
53
  staleTime: Infinity,
56
54
  gcTime: 0,
57
55
  refetchOnMount: false,
@@ -59,77 +57,102 @@ export function selectedSessionOptions(
59
57
  }
60
58
  }
61
59
 
62
- function selectedSessionMutationKey(workspaceId: string, scope: SelectedSessionScope) {
63
- return [...selectedSessionKey(workspaceId, scope), 'save'] as const
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.
62
+ export function selectedSessionForTab(
63
+ state: WorkspaceState | undefined,
64
+ tabId: WorkspaceTabId,
65
+ local?: BrowserTabSelection
66
+ ): string | null | undefined {
67
+ if (!state) return undefined
68
+ if (state.pinnedSessionId) return state.pinnedSessionId
69
+ if (local && tabId in local.selected) return local.selected[tabId] ?? null
70
+ return state.selected[tabId] ?? null
71
+ }
72
+
73
+ function cachedBrowserTabSelection(
74
+ queryClient: QueryClient,
75
+ workspaceId: string
76
+ ): BrowserTabSelection {
77
+ return (
78
+ queryClient.getQueryData<BrowserTabSelection>(browserTabSelectionKey(workspaceId)) ??
79
+ readSelectedSession(workspaceId)
80
+ )
64
81
  }
65
82
 
66
- export function optimisticallySetSelectedSession(
83
+ // For handlers outside render, which must see a change before React does.
84
+ export function cachedSelectedSession(
67
85
  queryClient: QueryClient,
68
86
  workspaceId: string,
69
- sessionId: string | null,
70
87
  tabId: WorkspaceTabId,
71
- scope: SelectedSessionScope = 'shared'
72
- ): SaveSelectedSessionInput | null {
73
- const queryKey = selectedSessionKey(workspaceId, scope)
74
- const current = queryClient.getQueryData<WorkspaceSessionSelection>(queryKey)
75
- const previousSessionId = current?.selected[tabId] ?? null
76
- if (
77
- current &&
78
- previousSessionId === sessionId &&
79
- (scope === 'shared' || tabId in current.selected)
88
+ scope: SelectedSessionScope
89
+ ): string | null | undefined {
90
+ return selectedSessionForTab(
91
+ getCachedWorkspaceState(queryClient, workspaceId),
92
+ tabId,
93
+ scope === 'browser-tab' ? cachedBrowserTabSelection(queryClient, workspaceId) : undefined
80
94
  )
81
- return null
82
-
83
- const selected = { ...current?.selected }
84
- if (sessionId === null && scope === 'shared') delete selected[tabId]
85
- else selected[tabId] = sessionId
86
- queryClient.setQueryData<WorkspaceSessionSelection>(queryKey, {
87
- selected,
88
- pinned: current?.pinned ?? null
89
- })
90
- if (scope === 'browser-tab') writeSelectedSession(workspaceId, { selected, pinned: null })
91
- return { sessionId, previousSessionId, tabId, scope }
92
95
  }
93
96
 
94
- export function settleSelectedSessionSave(
97
+ function setBrowserTabSelection(
95
98
  queryClient: QueryClient,
96
99
  workspaceId: string,
97
- saved: SelectedSessionState,
98
- input: SaveSelectedSessionInput
99
- ): SelectedSessionSaveResult {
100
- const queryKey = selectedSessionKey(workspaceId, input.scope)
101
- const current = queryClient.getQueryData<WorkspaceSessionSelection>(queryKey)
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 })
106
+ }
102
107
 
103
- const currentSessionId = current?.selected[input.tabId] ?? null
104
- if (saved.sessionId !== input.sessionId && currentSessionId !== saved.sessionId) {
105
- return 'conflict'
106
- }
107
- if (currentSessionId !== input.sessionId && currentSessionId !== input.previousSessionId) {
108
- return 'ignored'
109
- }
108
+ function applySelectionWrite(draft: WorkspaceState, input: SelectionWrite): void {
109
+ if (input.show) draft.selected[input.tabId] = input.sessionId
110
+ else if (draft.selected[input.tabId] === input.sessionId) delete draft.selected[input.tabId]
111
+ }
110
112
 
111
- const selected = { ...current?.selected }
112
- if (saved.sessionId === null && input.scope === 'shared') delete selected[input.tabId]
113
- else selected[input.tabId] = saved.sessionId
114
- queryClient.setQueryData<WorkspaceSessionSelection>(queryKey, {
115
- selected,
116
- pinned: current?.pinned ?? null
117
- })
118
- return 'applied'
113
+ // The request that points `tabId` at `sessionId` (null: a new chat), or
114
+ // undefined when nothing needs saving. Collab saves locally right here.
115
+ function selectionChange(
116
+ queryClient: QueryClient,
117
+ workspaceId: string,
118
+ sessionId: string | null,
119
+ tabId: WorkspaceTabId,
120
+ scope: SelectedSessionScope
121
+ ): 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
+ const current = getCachedWorkspaceState(queryClient, workspaceId)?.selected[tabId] ?? null
131
+ if (current === sessionId) return
132
+ if (sessionId === null) return current ? { sessionId: current, tabId, show: false } : undefined
133
+ return { sessionId, tabId, show: true, ifMatch: current }
119
134
  }
120
135
 
121
- export function applySelectedSessionEvent(
136
+ // Show a chat in a tab before the server confirms it, without a request: for
137
+ // flows whose own request makes the server select it (view submission).
138
+ export function setSelectedSessionInCache(
122
139
  queryClient: QueryClient,
123
140
  workspaceId: string,
124
- hasPendingSave: boolean
141
+ sessionId: string,
142
+ tabId: WorkspaceTabId,
143
+ scope: SelectedSessionScope
125
144
  ): void {
126
- if (hasPendingSave) return
127
- void queryClient.invalidateQueries({
128
- queryKey: appUiKeys.sessionSelection(workspaceId),
129
- exact: true
130
- })
145
+ if (scope === 'browser-tab')
146
+ setBrowserTabSelection(queryClient, workspaceId, selected => {
147
+ selected[tabId] = sessionId
148
+ })
149
+ else
150
+ changeWorkspaceStateCache(queryClient, workspaceId, draft => {
151
+ draft.selected[tabId] = sessionId
152
+ })
131
153
  }
132
154
 
155
+ // A harness replaced a temporary chat id with its real one.
133
156
  export function renameSelectedSessionInCache(
134
157
  queryClient: QueryClient,
135
158
  workspaceId: string,
@@ -139,29 +162,12 @@ export function renameSelectedSessionInCache(
139
162
  useUiStore
140
163
  .getState()
141
164
  .moveComposerDraft(composerDraftKey(workspaceId, from), composerDraftKey(workspaceId, to))
142
- for (const scope of ['shared', 'browser-tab'] as const) {
143
- queryClient.setQueryData<WorkspaceSessionSelection>(
144
- selectedSessionKey(workspaceId, scope),
145
- current =>
146
- current
147
- ? {
148
- selected: Object.fromEntries(
149
- Object.entries(current.selected).map(([tabId, id]) => [
150
- tabId,
151
- id === from ? to : id
152
- ])
153
- ),
154
- pinned: current.pinned === from ? to : current.pinned
155
- }
156
- : current
157
- )
158
- }
159
- const local = readSelectedSession(workspaceId)
160
- writeSelectedSession(workspaceId, {
161
- selected: Object.fromEntries(
162
- Object.entries(local.selected).map(([tabId, id]) => [tabId, id === from ? to : id])
163
- ),
164
- pinned: null
165
+ changeWorkspaceStateCache(queryClient, workspaceId, draft =>
166
+ renameSessionInState(draft, from, to)
167
+ )
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
165
171
  })
166
172
  }
167
173
 
@@ -170,15 +176,17 @@ export function useCurrentTabId(): WorkspaceTabId {
170
176
  return isWorkspaceTabId(tab) ? tab : 'overview'
171
177
  }
172
178
 
173
- export function selectedSessionForTab(
174
- shared: WorkspaceSessionSelection | undefined,
175
- tabId: WorkspaceTabId,
176
- local?: WorkspaceSessionSelection
177
- ): string | null | undefined {
178
- if (!shared) return undefined
179
- if (shared.pinned) return shared.pinned
180
- if (local && tabId in local.selected) return local.selected[tabId] ?? null
181
- return shared.selected[tabId] ?? null
179
+ function useSelectionWrite(workspaceId: string) {
180
+ return useWorkspaceStateWrite<SelectionWrite>(workspaceId, {
181
+ request: ({ sessionId, tabId, show, ifMatch }) =>
182
+ requestJson<WorkspaceState>(
183
+ `/api/workspaces/${workspaceId}/sessions/${encodeURIComponent(sessionId)}/selection`,
184
+ jsonRequest(show ? 'PUT' : 'DELETE', show ? { tabId, ifMatch } : { tabId }),
185
+ 'Couldn’t save selected chat'
186
+ ),
187
+ optimistic: applySelectionWrite,
188
+ errorTitle: 'Couldn’t save selected chat'
189
+ })
182
190
  }
183
191
 
184
192
  export function useSelectedSession(explicitTabId?: WorkspaceTabId): SelectedSessionResult {
@@ -188,164 +196,71 @@ export function useSelectedSession(explicitTabId?: WorkspaceTabId): SelectedSess
188
196
  const collabEnabled = useCollabEnabled()
189
197
  const scope: SelectedSessionScope = collabEnabled ? 'browser-tab' : 'shared'
190
198
  const queryClient = useQueryClient()
191
- const queryKey = useMemo(() => selectedSessionKey(workspaceId, scope), [workspaceId, scope])
192
- const mutationKey = useMemo(
193
- () => selectedSessionMutationKey(workspaceId, scope),
194
- [workspaceId, scope]
195
- )
196
- const pendingSaves = useIsMutating({ mutationKey, exact: true })
197
-
198
- // WorkspaceContent remains an observer for the active workspace. Nested hook
199
- // users reuse its result without refetching; once the route unmounts, dropping
200
- // the cache makes the next visit load the server-owned selection again.
201
- const query = useQuery(selectedSessionOptions(workspaceId, scope))
202
- // A pin is shared with CLI creation and applies to every workspace tab.
203
- const sharedSelection = useWorkspaceSessionSelection().data
204
-
205
- const { mutate: saveSelectedSession, mutateAsync: saveSelectedSessionAsync } = useMutation<
206
- SelectedSessionState,
207
- Error,
208
- SaveSelectedSessionInput
209
- >({
210
- mutationKey,
211
- scope: { id: `selected-session:${workspaceId}` },
212
- mutationFn: input => {
213
- if (input.scope === 'browser-tab') {
214
- writeSelectedSession(
215
- workspaceId,
216
- queryClient.getQueryData<WorkspaceSessionSelection>(queryKey) ??
217
- readSelectedSession(workspaceId)
218
- )
219
- return Promise.resolve({ sessionId: input.sessionId })
220
- }
221
- return requestJson<SelectedSessionState>(
222
- `/api/workspaces/${workspaceId}/selected-session`,
223
- jsonRequest('PUT', input),
224
- 'Couldn’t save selected chat'
225
- )
226
- },
227
- onSuccess: (saved, input) => {
228
- const result = settleSelectedSessionSave(queryClient, workspaceId, saved, input)
229
- if (result !== 'conflict') return
230
-
231
- toast.add({ title: 'Couldn’t save selected chat', type: 'error' })
232
- void queryClient.invalidateQueries({ queryKey, exact: true })
233
- },
234
- onError: (_error, input) => {
235
- const current = queryClient.getQueryData<WorkspaceSessionSelection>(queryKey)
236
- if ((current?.selected[input.tabId] ?? null) !== input.sessionId) return
237
-
238
- toast.add({ title: 'Couldn’t save selected chat', type: 'error' })
239
- void queryClient.invalidateQueries({ queryKey, exact: true })
240
- },
241
- onSettled: () => {
242
- if (scope === 'shared' && queryClient.isMutating({ mutationKey, exact: true }) === 1)
243
- void queryClient.invalidateQueries({ queryKey, exact: true })
244
- }
245
- })
199
+ const state = useWorkspaceState(workspaceId).data
200
+ const local = useQuery({
201
+ ...browserTabSelectionOptions(workspaceId),
202
+ enabled: scope === 'browser-tab'
203
+ }).data
204
+ const { mutate: save, mutateAsync: saveAsync } = useSelectionWrite(workspaceId)
246
205
 
247
206
  const setSelectedSessionId = useCallback<SetSelectedSession>(
248
207
  sessionId => {
249
- if (
250
- queryClient.getQueryData<WorkspaceSessionSelection>(selectedSessionKey(workspaceId))?.pinned
251
- )
252
- return
253
- const input = optimisticallySetSelectedSession(
254
- queryClient,
255
- workspaceId,
256
- sessionId,
257
- tabId,
258
- scope
259
- )
260
- if (input) saveSelectedSession(input)
208
+ // A pinned chat shows in every tab until it is unpinned.
209
+ if (getCachedWorkspaceState(queryClient, workspaceId)?.pinnedSessionId) return
210
+ const input = selectionChange(queryClient, workspaceId, sessionId, tabId, scope)
211
+ if (input) save(input)
261
212
  },
262
- [queryClient, saveSelectedSession, workspaceId, tabId, scope]
213
+ [queryClient, save, workspaceId, tabId, scope]
263
214
  )
264
215
 
265
216
  const selectSessionForTab = useCallback(
266
217
  async (sessionId: string, destination: WorkspaceTabId) => {
267
- const input = optimisticallySetSelectedSession(
268
- queryClient,
269
- workspaceId,
270
- sessionId,
271
- destination,
272
- scope
273
- )
218
+ const input = selectionChange(queryClient, workspaceId, sessionId, destination, scope)
274
219
  if (!input) return
275
- const saved = await saveSelectedSessionAsync(input)
276
- if (
277
- saved.sessionId !== sessionId ||
278
- queryClient.getQueryData<WorkspaceSessionSelection>(queryKey)?.selected[destination] !==
279
- sessionId
280
- )
281
- throw new Error('Couldn’t save selected chat')
220
+ const saved = await saveAsync(input)
221
+ if (saved.selected[destination] !== sessionId) throw new Error('Couldn’t save selected chat')
282
222
  },
283
- [queryClient, queryKey, saveSelectedSessionAsync, scope, workspaceId]
223
+ [queryClient, saveAsync, scope, workspaceId]
284
224
  )
285
225
 
286
- useWorkspaceEvent(event => {
287
- if (event.type !== 'selected-session:updated' || event.workspaceId !== workspaceId) return
288
- applySelectedSessionEvent(queryClient, workspaceId, scope === 'shared' && pendingSaves > 0)
289
- })
290
-
291
226
  const selectedSessionId =
292
- query.data === undefined || sharedSelection === undefined
227
+ scope === 'browser-tab' && local === undefined
293
228
  ? undefined
294
- : selectedSessionForTab(
295
- sharedSelection,
296
- tabId,
297
- scope === 'browser-tab' ? query.data : undefined
298
- )
229
+ : selectedSessionForTab(state, tabId, scope === 'browser-tab' ? local : undefined)
299
230
  return [selectedSessionId, setSelectedSessionId, selectSessionForTab]
300
231
  }
301
232
 
302
- function useWorkspaceSessionSelection() {
303
- const workspaceId = useWorkspaceId()
304
- return useQuery(selectedSessionOptions(workspaceId))
305
- }
306
-
307
233
  export function usePinnedSession() {
308
234
  const workspaceId = useWorkspaceId()
309
235
  const queryClient = useQueryClient()
310
- const { data } = useWorkspaceSessionSelection()
311
- const mutation = useMutation({
312
- scope: { id: `pinned-session:${workspaceId}` },
313
- mutationFn: (sessionId: string | null) =>
314
- requestJson<{ pinnedSessionId: string | null }>(
315
- `/api/workspaces/${workspaceId}/pinned-session`,
316
- jsonRequest('PUT', { sessionId })
317
- ),
318
- onMutate: sessionId => {
319
- const queryKey = appUiKeys.sessionSelection(workspaceId)
320
- const previousPinnedSessionId =
321
- queryClient.getQueryData<WorkspaceSessionSelection>(queryKey)?.pinned ?? null
322
- queryClient.setQueryData<WorkspaceSessionSelection>(queryKey, current => ({
323
- selected: current?.selected ?? {},
324
- pinned: sessionId
325
- }))
326
- return previousPinnedSessionId
327
- },
328
- onError: (_error, sessionId, previousPinnedSessionId) => {
329
- queryClient.setQueryData<WorkspaceSessionSelection>(
330
- appUiKeys.sessionSelection(workspaceId),
331
- current =>
332
- current?.pinned === sessionId
333
- ? { ...current, pinned: previousPinnedSessionId ?? null }
334
- : current
335
- )
336
- toast.add({ title: 'Couldn’t pin chat', type: 'error' })
337
- },
338
- onSettled: () => {
339
- void queryClient.invalidateQueries({
340
- queryKey: appUiKeys.sessionSelection(workspaceId),
341
- exact: true
342
- })
236
+ const state = useWorkspaceState(workspaceId).data
237
+ const { mutate, mutateAsync } = useWorkspaceStateWrite<{ sessionId: string; pinned: boolean }>(
238
+ workspaceId,
239
+ {
240
+ request: ({ sessionId, pinned }) =>
241
+ requestJson<WorkspaceState>(
242
+ `/api/workspaces/${workspaceId}/sessions/${encodeURIComponent(sessionId)}/pin`,
243
+ { method: pinned ? 'PUT' : 'DELETE' },
244
+ pinned ? 'Couldn’t pin chat' : 'Couldn’t unpin chat'
245
+ ),
246
+ optimistic: (draft, { sessionId, pinned }) => {
247
+ if (pinned) draft.pinnedSessionId = sessionId
248
+ else if (draft.pinnedSessionId === sessionId) delete draft.pinnedSessionId
249
+ },
250
+ errorTitle: 'Couldn’t change the pinned chat'
343
251
  }
344
- })
252
+ )
253
+ const pin = useCallback((sessionId: string) => mutate({ sessionId, pinned: true }), [mutate])
254
+ const unpinAsync = useCallback(async () => {
255
+ const pinned = getCachedWorkspaceState(queryClient, workspaceId)?.pinnedSessionId
256
+ if (pinned) await mutateAsync({ sessionId: pinned, pinned: false })
257
+ }, [mutateAsync, queryClient, workspaceId])
258
+ const unpin = useCallback(() => void unpinAsync().catch(() => {}), [unpinAsync])
345
259
  return {
346
- pinnedSessionId: data?.pinned ?? null,
347
- loaded: data !== undefined,
348
- pin: mutation.mutate,
349
- pinAsync: mutation.mutateAsync
260
+ pinnedSessionId: state?.pinnedSessionId,
261
+ loaded: state !== undefined,
262
+ pin,
263
+ unpin,
264
+ unpinAsync
350
265
  }
351
266
  }
@@ -3,12 +3,8 @@ import { useCallback, useMemo } from 'react'
3
3
  import { useQueryClient } from '@tanstack/react-query'
4
4
 
5
5
  import { workspaceKeys } from '@/client/api/workspace-keys'
6
- import {
7
- useSession,
8
- useSessionView,
9
- useWorkspaceSessions
10
- } from '@/client/features/chat/sessions/api'
11
- import { useWorkspaceAgent } from '@/client/features/workspace/api'
6
+ import { useSessionState, useSessionView } from '@/client/features/chat/sessions/api'
7
+ import { useWorkspaceHarness } from '@/client/features/workspace/api'
12
8
  import { useSelectedSession } from '@/client/features/chat/sessions/use-selected-session'
13
9
  import { useCollabEnabled } from '@/client/features/collab'
14
10
  import {
@@ -58,8 +54,7 @@ export function useChat(address: WorkspaceTabAddress) {
58
54
  const { layout } = useWorkspaceLayoutCtx()
59
55
  const [selectedSession, selectSession] = useSelectedSession(address.activeTab)
60
56
  const collabEnabled = useCollabEnabled()
61
- const modelsData = useWorkspaceAgent(workspaceId).data
62
- const sessions = useWorkspaceSessions(workspaceId).data
57
+ const modelsData = useWorkspaceHarness(workspaceId).data
63
58
  // A newly forked/native session can precede the provider's session listing.
64
59
  // Archive explicitly clears selection; a stale catalog must not do so.
65
60
  const selectedSessionId = selectedSession ?? null
@@ -79,20 +74,20 @@ export function useChat(address: WorkspaceTabAddress) {
79
74
 
80
75
  const viewQuery = useSessionView(workspaceId, selectedSessionId)
81
76
  const { refetch } = viewQuery
82
- const session = useSession(workspaceId, selectedSessionId)
77
+ // Tab, settings and fork history, from the workspace state.
78
+ const session = useSessionState(workspaceId, selectedSessionId)
83
79
  const { refetch: refetchSession } = session
84
80
  const retryLoad = useCallback(async () => {
85
81
  await refetch()
86
82
  await refetchSession()
87
83
  }, [refetch, refetchSession])
88
- const forkedFromSessionId = session.data?.forkedFromSessionId
84
+ const fork = session.data?.fork
89
85
  const sessionReady = !selectedSessionId || session.data !== undefined
90
86
  let view = sessionReady ? (viewQuery.data ?? EMPTY) : EMPTY
91
- if (viewQuery.data && forkedFromSessionId) view = visibleForkHistory(viewQuery.data, session.data)
87
+ if (viewQuery.data && fork) view = visibleForkHistory(viewQuery.data, fork)
92
88
  const chatLoaded =
93
89
  selectedSession !== undefined &&
94
90
  sessionReady &&
95
- sessions !== undefined &&
96
91
  (selectedSessionId === null || viewQuery.data !== undefined)
97
92
 
98
93
  // The live streaming preview as a synthetic assistant turn, so the ChatPanel
@@ -163,12 +158,12 @@ export function useChat(address: WorkspaceTabAddress) {
163
158
  // Validate effort and Fast mode against that same resolved row.
164
159
  const pickedModel = sessionConfig?.model ?? layout.selectedModel
165
160
  const pickedEffort = sessionConfig?.effort ?? layout.selectedEffort
166
- const pickedFastMode = sessionConfig?.fastMode ?? layout.selectedFastMode
167
- const { model, effort, fastMode, stream } = resolveChatRunOptions(
161
+ const pickedSpeedMode = sessionConfig?.speedMode ?? layout.selectedSpeedMode
162
+ const { model, effort, speedMode, stream } = resolveChatRunOptions(
168
163
  modelsData,
169
164
  pickedModel,
170
165
  pickedEffort,
171
- pickedFastMode
166
+ pickedSpeedMode
172
167
  )
173
168
  sendMessage({
174
169
  type: 'chat',
@@ -180,7 +175,7 @@ export function useChat(address: WorkspaceTabAddress) {
180
175
  optimisticId,
181
176
  model,
182
177
  effort,
183
- fastMode,
178
+ speedMode,
184
179
  stream,
185
180
  context: buildMoiContext(options),
186
181
  ...(attachments.length > 0 ? { attachments } : {})
@@ -198,11 +193,11 @@ export function useChat(address: WorkspaceTabAddress) {
198
193
  qc,
199
194
  layout.selectedModel,
200
195
  layout.selectedEffort,
201
- layout.selectedFastMode,
196
+ layout.selectedSpeedMode,
202
197
  buildMoiContext,
203
198
  sessionConfig?.model,
204
199
  sessionConfig?.effort,
205
- sessionConfig?.fastMode,
200
+ sessionConfig?.speedMode,
206
201
  selectSession,
207
202
  collabEnabled,
208
203
  modelsData
@@ -221,7 +216,7 @@ export function useChat(address: WorkspaceTabAddress) {
221
216
 
222
217
  return {
223
218
  view,
224
- forkedFromSessionId,
219
+ forkedFromSessionId: fork?.fromSessionId,
225
220
  chatLoaded,
226
221
  previewTurn,
227
222
  sessionId: selectedSessionId,
@@ -1,11 +1,11 @@
1
1
  import type * as CollabApi from 'moi/collab'
2
- import { UserAvatarGroup } from './components/user-avatar-group'
3
- import { User } from './components/user'
4
- import { UserAvatar } from './components/user-avatar'
5
- import { Cursors } from './components/cursors'
6
- import { PresenceFrame } from './components/presence-frame'
7
- import { PresenceGroup } from './components/presence-group'
8
- import { PresenceAvatars } from './components/presence-avatars'
2
+ import { UserAvatarGroupContainer } from './components/user-avatar-group'
3
+ import { UserContainer } from './components/user'
4
+ import { UserAvatarContainer } from './components/user-avatar'
5
+ import { CursorsContainer } from './components/cursors'
6
+ import { PresenceFrameContainer } from './components/presence-frame'
7
+ import { PresenceGroupContainer } from './components/presence-group'
8
+ import { PresenceAvatarsContainer } from './components/presence-avatars'
9
9
  import {
10
10
  useMe,
11
11
  usePeers,
@@ -17,14 +17,15 @@ import {
17
17
 
18
18
  export type AppletCollabApi = typeof CollabApi
19
19
 
20
+ // SDK components resolve collaboration data; host UI can import the plain components.
20
21
  export const appletCollabApi = {
21
- Cursors,
22
- User,
23
- UserAvatar,
24
- UserAvatarGroup,
25
- PresenceFrame,
26
- PresenceAvatars,
27
- PresenceGroup,
22
+ Cursors: CursorsContainer,
23
+ User: UserContainer,
24
+ UserAvatar: UserAvatarContainer,
25
+ UserAvatarGroup: UserAvatarGroupContainer,
26
+ PresenceFrame: PresenceFrameContainer,
27
+ PresenceAvatars: PresenceAvatarsContainer,
28
+ PresenceGroup: PresenceGroupContainer,
28
29
  useMe,
29
30
  usePeers,
30
31
  useUser,