moi-computer 0.3.0-next.1 → 0.3.0-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/README.md +1 -1
  2. package/bunfig.toml +5 -1
  3. package/client/AGENTS.md +17 -2
  4. package/client/accept-hmr-dependencies.ts +22 -0
  5. package/client/api/http.ts +31 -0
  6. package/client/api/query-options.ts +6 -0
  7. package/client/api/workspace-keys.ts +18 -0
  8. package/client/app/AppRouter.tsx +44 -0
  9. package/client/app/routes/HomeRoute.tsx +13 -0
  10. package/client/app/routes/WorkspaceRoute.tsx +95 -0
  11. package/client/app/shell/SidebarLayout.tsx +196 -0
  12. package/client/assets/openai.svg +3 -0
  13. package/client/assets.d.ts +9 -0
  14. package/client/components/{BottomPanel.tsx → shared/BottomPanel.tsx} +2 -2
  15. package/client/components/shared/PanelHeader.tsx +9 -0
  16. package/client/components/shared/ReorderableList.tsx +199 -0
  17. package/client/components/ui/button.tsx +11 -7
  18. package/client/components/ui/collapsible.tsx +15 -0
  19. package/client/components/ui/dialog.tsx +2 -2
  20. package/client/components/ui/dropdown-menu.tsx +5 -5
  21. package/client/components/ui/hover-card.tsx +1 -1
  22. package/client/components/ui/input.tsx +1 -1
  23. package/client/components/ui/popover.tsx +1 -1
  24. package/client/components/ui/skeleton.tsx +13 -0
  25. package/client/components/ui/tooltip.tsx +1 -1
  26. package/client/externalize-react.ts +7 -1
  27. package/client/features/applets/AppletMount.tsx +44 -0
  28. package/client/{components → features/applets}/WidgetErrorBoundary.tsx +1 -1
  29. package/client/{components → features/applets}/WidgetShell.tsx +5 -2
  30. package/client/{lib → features/applets}/applet-cache.ts +8 -0
  31. package/client/features/applets/applet-styles.ts +61 -0
  32. package/client/{hooks → features/applets}/useApplet.ts +6 -7
  33. package/client/{components/ChatInput.tsx → features/chat/ChatComposer.tsx} +30 -24
  34. package/client/features/chat/ChatPanel.tsx +171 -0
  35. package/client/{components → features/chat}/ChatPopup.tsx +24 -13
  36. package/client/{components/ThreadSelector.tsx → features/chat/ChatSelector.tsx} +15 -13
  37. package/client/{components → features/chat}/MarkdownContent.tsx +1 -1
  38. package/client/{components → features/chat}/ModelPicker.tsx +68 -17
  39. package/client/{components → features/chat}/TurnView.tsx +17 -11
  40. package/client/features/chat/api.ts +78 -0
  41. package/client/features/chat/chat-connection.ts +107 -0
  42. package/client/features/chat/chat-frames.ts +131 -0
  43. package/client/features/chat/chat-send.ts +57 -0
  44. package/client/{lib → features/chat}/preview-turn.ts +1 -1
  45. package/client/{components → features/chat}/tool-group/ReadImagePreview.tsx +1 -1
  46. package/client/{components → features/chat}/tool-group/SubagentCard.tsx +12 -10
  47. package/client/{components → features/chat}/tool-group/TimelineRow.tsx +5 -5
  48. package/client/{components → features/chat}/tool-group/ToolCallGroup.tsx +14 -5
  49. package/client/{components → features/chat}/tool-group/ToolOutput.tsx +12 -18
  50. package/client/{components → features/chat}/tool-group/format.ts +117 -0
  51. package/client/{hooks → features/chat}/useChat.ts +16 -44
  52. package/client/features/connectors/ConnectorsPage.tsx +92 -0
  53. package/client/features/connectors/McpMenu.tsx +145 -0
  54. package/client/features/connectors/api.ts +28 -0
  55. package/client/features/dev/DevRoutes.tsx +18 -0
  56. package/client/features/dev/HarnessDebugPage.tsx +468 -0
  57. package/client/{components/playground → features/dev}/PixelPainter.tsx +10 -21
  58. package/client/{components/playground → features/dev}/PlaygroundPage.tsx +10 -12
  59. package/client/{components/playground → features/dev}/ToolCallsPage.tsx +9 -11
  60. package/client/features/home/CreateWorkspaceDialog.tsx +130 -0
  61. package/client/features/home/CreateWorkspaceDialogSteps.tsx +234 -0
  62. package/client/features/home/HomeLogo.tsx +344 -0
  63. package/client/features/home/HomePage.tsx +214 -0
  64. package/client/{components → features/home}/WorkspacePreview.tsx +4 -4
  65. package/client/features/home/api.ts +156 -0
  66. package/client/features/home/workspace-presentation.tsx +44 -0
  67. package/client/features/scratchpad/Scratchpad.tsx +312 -0
  68. package/client/features/scratchpad/ScratchpadControls.tsx +503 -0
  69. package/client/features/scratchpad/useScratchpadSnapshot.tsx +115 -0
  70. package/client/features/settings/EnvironmentSettings.tsx +149 -0
  71. package/client/features/settings/GeneralSettings.tsx +90 -0
  72. package/client/{components → features}/settings/IconPicker.tsx +76 -224
  73. package/client/features/settings/SettingsLayout.tsx +53 -0
  74. package/client/{components → features}/settings/WorkspaceSettings.tsx +12 -16
  75. package/client/features/settings/api.ts +88 -0
  76. package/client/features/settings/icon-picker-options.ts +30 -0
  77. package/client/{hooks → features/settings}/useEnvVars.ts +4 -4
  78. package/client/features/views/ViewBuilderTab.tsx +153 -0
  79. package/client/features/views/api.ts +124 -0
  80. package/client/features/views/useViewBuilderActions.ts +72 -0
  81. package/client/{components → features/widgets}/HiddenPanel.tsx +3 -3
  82. package/client/{components → features/widgets}/WidgetFrame.tsx +3 -8
  83. package/client/{components → features/widgets}/WidgetGrid.tsx +38 -29
  84. package/client/features/widgets/Widgets.tsx +265 -0
  85. package/client/{lib/grid-pack.ts → features/widgets/grid.ts} +7 -1
  86. package/client/{hooks → features/widgets}/useGridReconcile.ts +1 -1
  87. package/client/{components → features/workspace}/CustomizePanel.tsx +5 -6
  88. package/client/{lib → features/workspace}/WorkspaceLayoutContext.tsx +16 -15
  89. package/client/features/workspace/WorkspaceScreen.tsx +675 -0
  90. package/client/features/workspace/WorkspaceTabs.tsx +205 -0
  91. package/client/features/workspace/api.ts +56 -0
  92. package/client/features/workspace/useFitsSplitLayout.ts +37 -0
  93. package/client/global.d.ts +5 -0
  94. package/client/index.css +6 -45
  95. package/client/index.html +2 -2
  96. package/client/index.tsx +14 -31
  97. package/client/lib/app-icon-registry.ts +145 -0
  98. package/client/main.tsx +2 -2
  99. package/client/runtime/hmr-watchdog.ts +39 -0
  100. package/client/{hooks/useMeiEvents.ts → runtime/useWorkspaceEvents.ts} +12 -7
  101. package/client/store/ui.ts +5 -1
  102. package/client/theme.css +1 -3
  103. package/dist/chunk-11cab5dq.css +1 -0
  104. package/dist/chunk-4vf1t6v1.js +10 -0
  105. package/dist/chunk-6c24yndg.js +61 -0
  106. package/dist/chunk-6c8cwpzc.js +1 -0
  107. package/dist/chunk-b4b276wx.js +15 -0
  108. package/dist/chunk-cs8vbert.js +546 -0
  109. package/dist/chunk-cwqmay73.css +1 -0
  110. package/dist/chunk-kxmvv1ax.js +48 -0
  111. package/dist/chunk-pcnahct1.js +5 -0
  112. package/dist/chunk-rq0ar7vp.js +1 -0
  113. package/dist/chunk-tqd3pkg8.css +1 -0
  114. package/dist/chunk-vkvb3hjm.js +2 -0
  115. package/dist/chunk-zpxrb1ce.js +2 -0
  116. package/dist/index.html +3 -3
  117. package/dist/openai-h13pza4b.svg +3 -0
  118. package/lib/format.ts +2 -2
  119. package/lib/types.ts +56 -9
  120. package/lib/view-builder-meta.ts +35 -0
  121. package/lib/workspace-layout.ts +14 -0
  122. package/lib/workspace-name.ts +14 -0
  123. package/package.json +4 -2
  124. package/server/AGENTS.md +3 -3
  125. package/server/api.ts +279 -60
  126. package/server/applets.ts +1 -1
  127. package/server/bundle-queue.ts +19 -0
  128. package/server/bundler/applet-css.ts +50 -0
  129. package/server/{build-applet.ts → bundler/build-applet.ts} +36 -26
  130. package/server/cli.ts +90 -7
  131. package/server/control.ts +106 -8
  132. package/server/env-apply.ts +2 -2
  133. package/server/harness/README.md +228 -0
  134. package/server/harness/claude-code/NOTES.md +578 -0
  135. package/{lib/claude-adapter.ts → server/harness/claude-code/adapter.ts} +67 -5
  136. package/server/harness/claude-code/index.ts +124 -0
  137. package/server/{mcp.ts → harness/claude-code/mcp.ts} +73 -16
  138. package/server/{cc-session.ts → harness/claude-code/session.ts} +42 -14
  139. package/server/harness/claude-code/sessions.ts +42 -0
  140. package/server/harness/codex/NOTES.md +239 -0
  141. package/server/harness/codex/adapter.ts +414 -0
  142. package/server/harness/codex/client.ts +343 -0
  143. package/server/harness/codex/index.ts +68 -0
  144. package/server/harness/codex/probe.ts +186 -0
  145. package/server/harness/codex/session.ts +617 -0
  146. package/server/harness/debug.ts +57 -0
  147. package/server/harness/openclaw/NOTES.md +316 -0
  148. package/server/{openclaw-adapter.ts → harness/openclaw/adapter.ts} +2 -2
  149. package/server/harness/openclaw/index.ts +93 -0
  150. package/server/{openclaw-session.ts → harness/openclaw/session.ts} +44 -9
  151. package/server/{openclaw-strip.ts → harness/openclaw/strip.ts} +3 -1
  152. package/server/harness/registry.ts +36 -0
  153. package/server/harness/types.ts +87 -0
  154. package/server/layout.ts +36 -11
  155. package/server/moi-scaffold.ts +56 -11
  156. package/server/registry.ts +30 -52
  157. package/server/state.ts +5 -38
  158. package/server/status.ts +7 -46
  159. package/server/vendor.ts +1 -1
  160. package/server/view-builders.ts +428 -0
  161. package/server/views.ts +0 -0
  162. package/server/web.ts +19 -40
  163. package/server/workspace-init.ts +11 -25
  164. package/tsconfig.json +1 -1
  165. package/workspace/.claude/skills/moi-workspace/DESIGN.md +2 -1
  166. package/workspace/.claude/skills/moi-workspace/SKILL.md +28 -7
  167. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +1 -1
  168. package/client/api/workspaces.ts +0 -427
  169. package/client/assets/hermes-nous.png +0 -0
  170. package/client/components/App.tsx +0 -41
  171. package/client/components/ChatPanel.tsx +0 -275
  172. package/client/components/HomePage.tsx +0 -17
  173. package/client/components/McpMenu.tsx +0 -125
  174. package/client/components/Scratchpad.tsx +0 -935
  175. package/client/components/Widgets.tsx +0 -132
  176. package/client/components/WorkspacesPage.tsx +0 -245
  177. package/client/components/layout/SidebarLayout.tsx +0 -258
  178. package/client/components/routes/workspace/[id].tsx +0 -675
  179. package/client/components/routes/workspace/create.tsx +0 -155
  180. package/client/components/settings/SettingsPages.tsx +0 -255
  181. package/client/hooks/useFitsSidebar.ts +0 -34
  182. package/client/hooks/useScrollFade.ts +0 -38
  183. package/client/lib/connection.ts +0 -238
  184. package/dist/chunk-07qf2tv1.css +0 -1
  185. package/dist/chunk-w18801vn.js +0 -672
  186. package/dist/hermes-nous-pznd63x9.png +0 -0
  187. /package/client/components/{playground → shared}/LedLogo.tsx +0 -0
  188. /package/client/{components → features/chat}/ShimmerText.tsx +0 -0
  189. /package/client/{store/live.ts → features/chat/chat-store.ts} +0 -0
  190. /package/client/{lib → features/chat}/group-turns.ts +0 -0
  191. /package/client/{components → features/chat}/tool-group/CodeBlock.tsx +0 -0
  192. /package/client/{components → features/chat}/tool-group/Collapse.tsx +0 -0
  193. /package/client/{components → features/chat}/tool-group/detect.ts +0 -0
  194. /package/client/{components → features/chat}/tool-group/fixtures.ts +0 -0
  195. /package/client/{components → features/chat}/tool-group/index.ts +0 -0
  196. /package/client/{lib → features/chat}/uploads.ts +0 -0
  197. /package/client/{hooks → features/chat}/useStickToBottom.ts +0 -0
  198. /package/client/{components → features/connectors}/IconMcp.tsx +0 -0
  199. /package/client/{lib → features/connectors}/mcp-icons.ts +0 -0
  200. /package/client/{lib → features/scratchpad}/scratch-executor.ts +0 -0
  201. /package/client/{lib → features/settings}/render-icon.ts +0 -0
  202. /package/client/{lib → features/workspace}/WorkspaceContext.tsx +0 -0
  203. /package/client/{hooks → features/workspace}/useWorkspaceTheme.ts +0 -0
  204. /package/server/{agent.ts → harness/claude-code/models.ts} +0 -0
  205. /package/server/{openclaw.ts → harness/openclaw/discovery.ts} +0 -0
  206. /package/server/{openclaw-gateway.ts → harness/openclaw/gateway.ts} +0 -0
@@ -2,13 +2,20 @@ import { memo } from 'react'
2
2
 
3
3
  import { IconFile } from '@tabler/icons-react'
4
4
 
5
- import { MarkdownContent } from '@/client/components/MarkdownContent'
6
- import { ToolCallGroup } from '@/client/components/tool-group/ToolCallGroup'
7
- import { useWorkspaceLayoutCtx } from '@/client/lib/WorkspaceLayoutContext'
5
+ import { MarkdownContent } from '@/client/features/chat/MarkdownContent'
6
+ import { ToolCallGroup } from '@/client/features/chat/tool-group/ToolCallGroup'
7
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
8
8
  import type { Part, Turn } from '@/lib/types'
9
9
 
10
10
  export function EmptyState() {
11
- return <div className="flex flex-1 flex-col items-center justify-center" />
11
+ return (
12
+ <div className="flex flex-1 flex-col items-center justify-center gap-1.5 text-center">
13
+ <h2 className="font-medium">Every journey starts somewhere</h2>
14
+ <p className="mx-auto max-w-sm text-sm text-muted-foreground">
15
+ Chat with your agent, create widgets and views, and manage your workspace context from here.
16
+ </p>
17
+ </div>
18
+ )
12
19
  }
13
20
 
14
21
  export function ThinkingIndicator() {
@@ -87,9 +94,8 @@ export function TurnParts({ parts, cwd, processing = false }: TurnPartsProps) {
87
94
  type TurnViewProps = { turn: Turn; processing?: boolean }
88
95
 
89
96
  // Memoized: the message list maps over grouped turns (stable identities — see
90
- // `groupTurns` in ChatPanel), so a parent re-render (e.g. the scroll-fade state
91
- // toggling on every scroll) no longer re-renders every row — only rows whose
92
- // `turn` or `processing` actually changed.
97
+ // `groupTurns` in ChatPanel), so parent re-renders only update rows whose `turn`
98
+ // or `processing` actually changed.
93
99
  export const TurnView = memo(function TurnView({ turn, processing = false }: TurnViewProps) {
94
100
  const cwd = useWorkspaceLayoutCtx().cwd
95
101
 
@@ -118,7 +124,7 @@ export const TurnView = memo(function TurnView({ turn, processing = false }: Tur
118
124
  <FilePart key={i} mediaType={p.mediaType} url={p.url} filename={p.filename} />
119
125
  ))}
120
126
  {text && (
121
- <p className="rounded-md bg-black/[0.07] px-4 py-2 text-sm leading-normal whitespace-pre-wrap">
127
+ <p className="rounded-md bg-accent px-4 py-2 text-sm leading-normal whitespace-pre-wrap text-accent-foreground">
122
128
  {text}
123
129
  </p>
124
130
  )}
@@ -164,13 +170,13 @@ function FilePart({ mediaType, url, filename }: FilePartProps) {
164
170
  <img
165
171
  src={url}
166
172
  alt={filename ?? 'attachment'}
167
- className="max-h-64 max-w-full rounded-md border border-black/10 object-contain"
173
+ className="max-h-64 max-w-full rounded-md border border-border object-contain"
168
174
  />
169
175
  )
170
176
  }
171
177
  return (
172
- <div className="flex items-center gap-1.5 rounded-md border border-black/10 bg-black/[0.03] px-2.5 py-1.5 text-xs text-muted-foreground">
173
- <IconFile size={14} stroke={1.5} />
178
+ <div className="flex items-center gap-1.5 rounded-md border border-border bg-accent px-2.5 py-1.5 text-xs text-accent-foreground">
179
+ <IconFile size={16} stroke={1.75} />
174
180
  <span className="truncate">{filename ?? mediaType}</span>
175
181
  </div>
176
182
  )
@@ -0,0 +1,78 @@
1
+ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
2
+
3
+ import { jsonRequest, requestJson } from '@/client/api/http'
4
+ import { WORKSPACE_RESOURCE_OPTIONS } from '@/client/api/query-options'
5
+ import { workspaceKeys } from '@/client/api/workspace-keys'
6
+ import { applyEvents } from '@/lib/format'
7
+ import type {
8
+ SessionInfo,
9
+ StreamEvent,
10
+ ThreadConfig,
11
+ ViewState,
12
+ WorkspaceModels
13
+ } from '@/lib/types'
14
+
15
+ export function useWorkspaceSessions(workspaceId: string) {
16
+ return useQuery<SessionInfo[]>({
17
+ queryKey: workspaceKeys.sessions(workspaceId),
18
+ queryFn: () => requestJson(`/api/workspaces/${workspaceId}/sessions`),
19
+ ...WORKSPACE_RESOURCE_OPTIONS
20
+ })
21
+ }
22
+
23
+ export function useSessionView(workspaceId: string, sessionId: string | null) {
24
+ return useQuery<ViewState>({
25
+ queryKey: workspaceKeys.events(workspaceId, sessionId ?? ''),
26
+ queryFn: async () => {
27
+ const response = await fetch(`/api/workspaces/${workspaceId}/sessions/${sessionId}/events`)
28
+ const events: StreamEvent[] = response.ok ? await response.json() : []
29
+ return applyEvents(events)
30
+ },
31
+ enabled: Boolean(sessionId),
32
+ staleTime: Infinity,
33
+ gcTime: 5 * 60_000,
34
+ refetchOnMount: false,
35
+ refetchOnWindowFocus: false
36
+ })
37
+ }
38
+
39
+ export function useWorkspaceModels(workspaceId: string) {
40
+ return useQuery<WorkspaceModels>({
41
+ queryKey: workspaceKeys.models(workspaceId),
42
+ queryFn: () => requestJson(`/api/workspaces/${workspaceId}/models`),
43
+ staleTime: Infinity,
44
+ gcTime: Infinity,
45
+ refetchOnMount: false,
46
+ refetchOnWindowFocus: false
47
+ })
48
+ }
49
+
50
+ export function useThreadConfig(workspaceId: string, sessionId: string | null) {
51
+ return useQuery<ThreadConfig>({
52
+ queryKey: workspaceKeys.threadConfig(workspaceId, sessionId ?? ''),
53
+ queryFn: () => requestJson(`/api/workspaces/${workspaceId}/sessions/${sessionId}/config`),
54
+ enabled: Boolean(sessionId),
55
+ staleTime: Infinity,
56
+ gcTime: 5 * 60_000,
57
+ refetchOnMount: false,
58
+ refetchOnWindowFocus: false
59
+ })
60
+ }
61
+
62
+ export function useSaveThreadConfig(workspaceId: string) {
63
+ const queryClient = useQueryClient()
64
+ return useMutation<ThreadConfig, Error, { sessionId: string; patch: ThreadConfig }>({
65
+ mutationFn: ({ patch, sessionId }) =>
66
+ requestJson(
67
+ `/api/workspaces/${workspaceId}/sessions/${sessionId}/config`,
68
+ jsonRequest('PUT', patch),
69
+ 'Failed to save chat settings'
70
+ ),
71
+ onSuccess: (next, { sessionId }) => {
72
+ queryClient.setQueryData<ThreadConfig>(
73
+ workspaceKeys.threadConfig(workspaceId, sessionId),
74
+ next
75
+ )
76
+ }
77
+ })
78
+ }
@@ -0,0 +1,107 @@
1
+ import type { QueryClient } from '@tanstack/react-query'
2
+
3
+ import { wsUrl } from '@/client/lib/ws-url'
4
+ import { liveStore } from '@/client/features/chat/chat-store'
5
+ import { reduceChatFrame } from '@/client/features/chat/chat-frames'
6
+ import type { ClientMessage } from '@/lib/types'
7
+
8
+ // App-wide chat connection: ONE WebSocket for the whole client, opened once at
9
+ // startup and never torn down on navigation. Every server frame is tagged with
10
+ // `workspaceId`, so a single socket serves every workspace and the client routes
11
+ // each frame to the right `(workspaceId, sessionId)` slice — live transcript
12
+ // deltas into the React Query cache, status/error/rename into the live store.
13
+ //
14
+ // Socket identity is tracked by a monotonic `generation`: each socket captures
15
+ // the generation at creation and every callback bails if it's no longer current,
16
+ // so a delayed close/open from a superseded socket can't corrupt live state.
17
+
18
+ let qc: QueryClient | null = null
19
+ let socket: WebSocket | null = null
20
+ let generation = 0
21
+ let reconnectTimer: ReturnType<typeof setTimeout> | null = null
22
+ const queue: ClientMessage[] = []
23
+ let onWorkspaceSwitch: ((workspaceId: string) => void) | null = null
24
+ let sweepTimer: ReturnType<typeof setInterval> | null = null
25
+
26
+ // TTL backstop for live previews. Every clear path (turn arrival, run end,
27
+ // reconnect) is exact and should fire first; this only reaps a preview whose
28
+ // clear was somehow missed, so it can be generous.
29
+ const PREVIEW_TTL_MS = 15_000
30
+
31
+ export function initConnection(queryClient: QueryClient) {
32
+ qc = queryClient
33
+ if (!sweepTimer) {
34
+ sweepTimer = setInterval(
35
+ () => liveStore.getState().sweepPreviews(PREVIEW_TTL_MS, Date.now()),
36
+ 5_000
37
+ )
38
+ }
39
+ if (socket) return // already connected (mount/StrictMode re-invoke safety)
40
+ connect()
41
+ }
42
+
43
+ function connect() {
44
+ const myGen = ++generation
45
+ if (reconnectTimer) {
46
+ clearTimeout(reconnectTimer)
47
+ reconnectTimer = null
48
+ }
49
+
50
+ const s = new WebSocket(wsUrl('/ws'))
51
+ socket = s
52
+
53
+ s.onopen = () => {
54
+ if (generation !== myGen) {
55
+ s.close()
56
+ return
57
+ }
58
+ for (const m of queue) s.send(JSON.stringify(m))
59
+ queue.length = 0
60
+ // Heal any deltas missed while disconnected: refetch every live transcript.
61
+ // No-op on the first connect (nothing cached yet).
62
+ qc?.invalidateQueries({ queryKey: ['workspaces', 'events'] })
63
+ // Any in-flight preview from before the drop is superseded by that refetch
64
+ // (which returns the authoritative disk state) — drop them all so a frozen
65
+ // half-streamed preview can't linger over the healed transcript.
66
+ liveStore.getState().clearAllPreviews()
67
+ }
68
+
69
+ s.onmessage = e => {
70
+ if (generation !== myGen) return
71
+ let data: unknown
72
+ try {
73
+ data = JSON.parse(e.data)
74
+ } catch {
75
+ return
76
+ }
77
+ handleFrame(data as Record<string, unknown>)
78
+ }
79
+
80
+ s.onclose = () => {
81
+ if (generation !== myGen) return
82
+ socket = null
83
+ reconnectTimer = setTimeout(connect, 1000)
84
+ }
85
+
86
+ s.onerror = () => s.close()
87
+ }
88
+
89
+ export function handleFrame(data: Record<string, unknown>) {
90
+ reduceChatFrame(data, { queryClient: qc, sendMessage, onWorkspaceSwitch })
91
+ }
92
+
93
+ export function sendMessage(msg: ClientMessage) {
94
+ if (socket && socket.readyState === WebSocket.OPEN) socket.send(JSON.stringify(msg))
95
+ else queue.push(msg)
96
+ }
97
+
98
+ export function setWorkspaceSwitchHandler(fn: ((workspaceId: string) => void) | null) {
99
+ onWorkspaceSwitch = fn
100
+ }
101
+
102
+ // Test seam: inject the QueryClient the frame handler reads, without opening a
103
+ // socket (the browser-only `connect()` path). Production always goes through
104
+ // `initConnection`.
105
+ export function __setQueryClientForTests(client: QueryClient | null) {
106
+ qc = client
107
+ }
@@ -0,0 +1,131 @@
1
+ import type { QueryClient } from '@tanstack/react-query'
2
+
3
+ import { workspaceKeys } from '@/client/api/workspace-keys'
4
+ import { getScratchExecutor } from '@/client/features/scratchpad/scratch-executor'
5
+ import { liveStore } from '@/client/features/chat/chat-store'
6
+ import { applyEvent } from '@/lib/format'
7
+ import type {
8
+ ClientMessage,
9
+ PreviewFrame,
10
+ ScratchOp,
11
+ StreamEvent,
12
+ ThreadConfig,
13
+ ViewState
14
+ } from '@/lib/types'
15
+
16
+ type ChatFrameContext = {
17
+ queryClient: QueryClient | null
18
+ sendMessage: (message: ClientMessage) => void
19
+ onWorkspaceSwitch: ((workspaceId: string) => void) | null
20
+ }
21
+
22
+ export function reduceChatFrame(data: Record<string, unknown>, context: ChatFrameContext) {
23
+ const { queryClient, sendMessage, onWorkspaceSwitch } = context
24
+ const store = liveStore.getState()
25
+
26
+ if (data.type === 'status_snapshot') {
27
+ store.reconcileProcessing(
28
+ (data.running as { workspaceId: string; sessionId: string }[] | undefined) ?? []
29
+ )
30
+ return
31
+ }
32
+ if (data.type === 'status') {
33
+ const workspaceId = data.workspaceId as string
34
+ const sessionId = data.sessionId as string
35
+ const processing = data.processing as boolean
36
+ store.setProcessing(workspaceId, sessionId, processing)
37
+ if (!processing) store.clearPreviewsForSession(workspaceId, sessionId)
38
+ return
39
+ }
40
+ if (data.type === 'preview') {
41
+ const frame = data as unknown as PreviewFrame
42
+ const key = workspaceKeys.events(frame.workspaceId, frame.sessionId)
43
+ if (queryClient?.getQueryData(key) === undefined) return
44
+ store.setPreview({
45
+ workspaceId: frame.workspaceId,
46
+ sessionId: frame.sessionId,
47
+ messageId: frame.messageId,
48
+ parentToolUseId: frame.parentToolUseId,
49
+ blocks: frame.blocks
50
+ })
51
+ return
52
+ }
53
+ if (data.type === 'session_renamed') {
54
+ const workspaceId = data.workspaceId as string
55
+ const from = data.from as string
56
+ const to = data.to as string
57
+ store.renameSession(workspaceId, from, to)
58
+
59
+ const previousView = queryClient?.getQueryData<ViewState>(
60
+ workspaceKeys.events(workspaceId, from)
61
+ )
62
+ if (previousView !== undefined) {
63
+ queryClient?.setQueryData(workspaceKeys.events(workspaceId, to), previousView)
64
+ queryClient?.removeQueries({ queryKey: workspaceKeys.events(workspaceId, from) })
65
+ }
66
+
67
+ const previousConfig = queryClient?.getQueryData<ThreadConfig>(
68
+ workspaceKeys.threadConfig(workspaceId, from)
69
+ )
70
+ if (previousConfig !== undefined) {
71
+ queryClient?.setQueryData(workspaceKeys.threadConfig(workspaceId, to), previousConfig)
72
+ queryClient?.removeQueries({ queryKey: workspaceKeys.threadConfig(workspaceId, from) })
73
+ }
74
+ queryClient?.invalidateQueries({ queryKey: workspaceKeys.sessions(workspaceId) })
75
+ return
76
+ }
77
+ if (data.type === 'workspace:switch') {
78
+ onWorkspaceSwitch?.(data.workspaceId as string)
79
+ return
80
+ }
81
+ if (data.type === 'scratchpad:op') {
82
+ const run = getScratchExecutor(data.workspaceId as string)
83
+ if (!run) return
84
+ const opId = data.opId as string
85
+ run(data.op as ScratchOp).then(
86
+ result => sendMessage({ type: 'scratchpad:op-result', opId, result }),
87
+ error =>
88
+ sendMessage({
89
+ type: 'scratchpad:op-result',
90
+ opId,
91
+ error: error instanceof Error ? error.message : String(error)
92
+ })
93
+ )
94
+ return
95
+ }
96
+
97
+ const workspaceId = data.workspaceId as string | undefined
98
+ const sessionId = data.sessionId as string | undefined
99
+ if (!workspaceId || !sessionId) return
100
+ const kind = data.kind
101
+
102
+ if (kind === 'snapshot' || kind === 'turn' || kind === 'notice' || kind === 'result') {
103
+ patchView(queryClient, workspaceId, sessionId, data as unknown as StreamEvent)
104
+ if (kind === 'turn') {
105
+ const messageId = (data as unknown as { turn?: { meta?: { apiMessageId?: string } } }).turn
106
+ ?.meta?.apiMessageId
107
+ if (messageId) store.clearPreview(messageId)
108
+ }
109
+ if (kind === 'result') store.clearPreviewsForSession(workspaceId, sessionId)
110
+ }
111
+ if (kind === 'error' && typeof data.content === 'string') {
112
+ store.setError(workspaceId, sessionId, data.content)
113
+ store.clearPreviewsForSession(workspaceId, sessionId)
114
+ }
115
+ if (kind === 'stopped') {
116
+ store.setProcessing(workspaceId, sessionId, false)
117
+ store.clearPreviewsForSession(workspaceId, sessionId)
118
+ }
119
+ }
120
+
121
+ function patchView(
122
+ queryClient: QueryClient | null,
123
+ workspaceId: string,
124
+ sessionId: string,
125
+ event: StreamEvent
126
+ ) {
127
+ const queryKey = workspaceKeys.events(workspaceId, sessionId)
128
+ const existing = queryClient?.getQueryData<ViewState>(queryKey)
129
+ if (existing === undefined) return
130
+ queryClient?.setQueryData<ViewState>(queryKey, applyEvent(existing, event))
131
+ }
@@ -0,0 +1,57 @@
1
+ import type { QueryClient } from '@tanstack/react-query'
2
+
3
+ import { workspaceKeys } from '@/client/api/workspace-keys'
4
+ import { liveStore } from '@/client/features/chat/chat-store'
5
+ import { STREAM_RESPONSES } from '@/client/lib/flags'
6
+ import { applyEvent, emptyViewState } from '@/lib/format'
7
+ import type { Part, ViewState, WorkspaceModels } from '@/lib/types'
8
+
9
+ type StartOptimisticTurnInput = {
10
+ queryClient: QueryClient
11
+ workspaceId: string
12
+ sessionId: string
13
+ parts: Part[]
14
+ }
15
+
16
+ export function startOptimisticTurn({
17
+ queryClient,
18
+ workspaceId,
19
+ sessionId,
20
+ parts
21
+ }: StartOptimisticTurnInput): string {
22
+ const optimisticId = `optimistic:${crypto.randomUUID()}`
23
+ queryClient.setQueryData<ViewState>(workspaceKeys.events(workspaceId, sessionId), current =>
24
+ applyEvent(current ?? emptyViewState(), {
25
+ kind: 'turn',
26
+ turn: {
27
+ id: optimisticId,
28
+ role: 'user',
29
+ origin: { kind: 'user-input' },
30
+ parts,
31
+ timestamp: new Date().toISOString()
32
+ }
33
+ })
34
+ )
35
+ liveStore.getState().setProcessing(workspaceId, sessionId, true)
36
+ liveStore.getState().setError(workspaceId, sessionId, null)
37
+ return optimisticId
38
+ }
39
+
40
+ export function resolveChatRunOptions(
41
+ modelsData: WorkspaceModels | undefined,
42
+ pickedModel: string | undefined,
43
+ pickedEffort: string | undefined
44
+ ): { model?: string; effort?: string; stream?: true } {
45
+ const models = modelsData?.models
46
+ const model =
47
+ !pickedModel || !models || models.some(candidate => candidate.value === pickedModel)
48
+ ? pickedModel
49
+ : undefined
50
+ const modelInfo = models?.find(candidate => candidate.value === model)
51
+ const effort =
52
+ pickedEffort && (!modelInfo || (modelInfo.supportedEffortLevels ?? []).includes(pickedEffort))
53
+ ? pickedEffort
54
+ : undefined
55
+ const stream = STREAM_RESPONSES && modelsData?.supportsStreaming ? true : undefined
56
+ return { model, effort, stream }
57
+ }
@@ -5,7 +5,7 @@
5
5
  // its finalized form groups); a preview with text stands alone as its own turn.
6
6
  // The moment the real turn lands, the preview is cleared and the real turn takes
7
7
  // its place in the same pipeline, so the swap is seamless.
8
- import type { LivePreview } from '@/client/store/live'
8
+ import type { LivePreview } from '@/client/features/chat/chat-store'
9
9
  import type { Part, PreviewBlock, Turn } from '@/lib/types'
10
10
 
11
11
  // Stable id for the synthetic live turn — keeps React's key steady across deltas
@@ -1,6 +1,6 @@
1
1
  import { useState } from 'react'
2
2
 
3
- import { useWorkspaceId } from '@/client/lib/WorkspaceContext'
3
+ import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
4
4
  import type { ToolCall } from '@/lib/types'
5
5
 
6
6
  // Image extensions the server's preview route can render (see server/preview.ts).
@@ -6,17 +6,16 @@
6
6
  // sub-timeline, then its final summary. The `subagent` record
7
7
  // (progress/status/usage/transcript) is built live from `task_*` events and isn't
8
8
  // persisted, so a finished/replayed call shows only the header.
9
- import { useEffect, useState } from 'react'
9
+ import { type ReactNode, useEffect, useState } from 'react'
10
10
 
11
11
  import { IconPlayBasketball, IconPlayFootball, IconPlayVolleyball } from '@tabler/icons-react'
12
12
 
13
- import { ShimmerText } from '@/client/components/ShimmerText'
13
+ import { ShimmerText } from '@/client/features/chat/ShimmerText'
14
14
  import { cn } from '@/client/lib/cn'
15
- import type { ToolCall } from '@/lib/types'
15
+ import type { Part, ToolCall } from '@/lib/types'
16
16
 
17
17
  import { Collapse } from './Collapse'
18
18
  import { NodeBox, type RowPosition, RowChevron, TimelineRow } from './TimelineRow'
19
- import { ToolCallGroup } from './ToolCallGroup'
20
19
  import { formatDuration } from './format'
21
20
 
22
21
  // While a subagent runs, its node cycles through "playing sport" glyphs — a
@@ -36,8 +35,13 @@ function RunningSportNode() {
36
35
  )
37
36
  }
38
37
 
39
- type SubagentCardProps = RowPosition & { call: ToolCall; cwd: string | null }
40
- export function SubagentCard({ call, cwd, isFirst, isLast }: SubagentCardProps) {
38
+ type SubagentCardProps = RowPosition & {
39
+ call: ToolCall
40
+ cwd: string | null
41
+ renderNestedParts: (parts: Part[], cwd: string | null) => ReactNode
42
+ }
43
+
44
+ export function SubagentCard({ call, cwd, isFirst, isLast, renderNestedParts }: SubagentCardProps) {
41
45
  const [open, setOpen] = useState(false)
42
46
  const sub = call.subagent
43
47
  const input = (call.input ?? {}) as { description?: string }
@@ -94,7 +98,7 @@ export function SubagentCard({ call, cwd, isFirst, isLast }: SubagentCardProps)
94
98
  {formatDuration(durationMs)}
95
99
  </span>
96
100
  )}
97
- {status === 'failed' && <span className="shrink-0 text-xs text-red-600">✗</span>}
101
+ {status === 'failed' && <span className="shrink-0 text-xs text-destructive">✗</span>}
98
102
  {status === 'stopped' && (
99
103
  <span className="shrink-0 text-xs text-muted-foreground">✗</span>
100
104
  )}
@@ -112,9 +116,7 @@ export function SubagentCard({ call, cwd, isFirst, isLast }: SubagentCardProps)
112
116
  summary, so a steps-only card has no trailing border. */}
113
117
  <div className="mt-1 mb-1 overflow-hidden rounded-md border border-border">
114
118
  {nestedParts.length > 0 && (
115
- <div className="py-1.5 pr-2 pl-3">
116
- <ToolCallGroup parts={nestedParts} cwd={cwd} />
117
- </div>
119
+ <div className="py-1.5 pr-2 pl-3">{renderNestedParts(nestedParts, cwd)}</div>
118
120
  )}
119
121
  {summary && (
120
122
  <div
@@ -8,7 +8,7 @@ import type { ReactNode } from 'react'
8
8
  import { IconChevronRight, IconLoader2, IconPackage } from '@tabler/icons-react'
9
9
  import { motion } from 'motion/react'
10
10
 
11
- import { IconMcp } from '@/client/components/IconMcp'
11
+ import { IconMcp } from '@/client/features/connectors/IconMcp'
12
12
  import { cn } from '@/client/lib/cn'
13
13
 
14
14
  // Where a row sits in the group — drives which rail segments to draw so the rule
@@ -59,14 +59,14 @@ export function TimelineRow({
59
59
  ) : loading ? (
60
60
  // A spinner node stands in for the dot; bg-background carves the rule.
61
61
  <span className="absolute top-[15px] left-1/2 z-10 flex -translate-x-1/2 -translate-y-1/2 rounded-full bg-background p-0.5">
62
- <IconLoader2 size={10} stroke={2.75} className="animate-spin text-ring" />
62
+ <IconLoader2 size={12} stroke={1.75} className="animate-spin text-ring" />
63
63
  </span>
64
64
  ) : (
65
65
  // Background-colored ring carves a gap in the rule around the dot.
66
66
  <span
67
67
  className={cn(
68
68
  'absolute top-[15px] left-1/2 z-10 size-[5px] -translate-x-1/2 -translate-y-1/2 rounded-full ring-3 ring-background',
69
- isError ? 'bg-red-400' : 'bg-border'
69
+ isError ? 'bg-destructive' : 'bg-border'
70
70
  )}
71
71
  />
72
72
  )}
@@ -90,7 +90,7 @@ export function RowChevron({ open }: { open: boolean }) {
90
90
  open ? 'opacity-100' : 'opacity-0 group-hover/row:opacity-100'
91
91
  )}
92
92
  >
93
- <IconChevronRight size={12} stroke={2.2} />
93
+ <IconChevronRight size={12} stroke={1.75} />
94
94
  </motion.span>
95
95
  )
96
96
  }
@@ -117,7 +117,7 @@ export function NodeBox({ children, className }: { children: ReactNode; classNam
117
117
  export function IconMarker({
118
118
  icon: Icon,
119
119
  size = 12,
120
- stroke = 1.5
120
+ stroke = 1.75
121
121
  }: {
122
122
  icon: typeof IconPackage
123
123
  size?: number
@@ -15,7 +15,7 @@ import { type ReactNode, useState } from 'react'
15
15
  import { IconLoader2, IconPackage } from '@tabler/icons-react'
16
16
 
17
17
  import { cn } from '@/client/lib/cn'
18
- import { formatMcpServerName, getMcpIcon } from '@/client/lib/mcp-icons'
18
+ import { formatMcpServerName, getMcpIcon } from '@/client/features/connectors/mcp-icons'
19
19
  import type { Part, ToolCall } from '@/lib/types'
20
20
 
21
21
  import { Collapse } from './Collapse'
@@ -32,6 +32,7 @@ import {
32
32
  import { ToolOutput } from './ToolOutput'
33
33
  import {
34
34
  formatInputBrief,
35
+ parseCodexMcp,
35
36
  formatMcpTool,
36
37
  getToolDisplayName,
37
38
  parseMcporterCall,
@@ -113,7 +114,7 @@ function ToolRow({ isFirst, isLast, call, leading, marker, name, brief, preview
113
114
  {/* Dotted rows spin at the node instead; only icon (MCP) rows, whose
114
115
  node can't spin, keep a header spinner. */}
115
116
  {isRunning && marker && (
116
- <IconLoader2 size={12} stroke={1.5} className="shrink-0 animate-spin text-ring" />
117
+ <IconLoader2 size={12} stroke={1.75} className="shrink-0 animate-spin text-ring" />
117
118
  )}
118
119
  {hasBody && <RowChevron open={open} />}
119
120
  </button>
@@ -170,7 +171,15 @@ function ReasoningRow({ isFirst, isLast, text, inProgress = false }: ReasoningRo
170
171
  type ToolCallCardProps = RowPosition & { call: ToolCall; cwd: string | null }
171
172
  function ToolCallCard({ call, cwd, isFirst, isLast }: ToolCallCardProps) {
172
173
  if (call.caller === 'subagent') {
173
- return <SubagentCard call={call} cwd={cwd} isFirst={isFirst} isLast={isLast} />
174
+ return (
175
+ <SubagentCard
176
+ call={call}
177
+ cwd={cwd}
178
+ isFirst={isFirst}
179
+ isLast={isLast}
180
+ renderNestedParts={(parts, nestedCwd) => <ToolCallGroup parts={parts} cwd={nestedCwd} />}
181
+ />
182
+ )
174
183
  }
175
184
  if (call.name === 'Skill' && call.skill) {
176
185
  // On success, swap the timeline dot for a package icon node (same box as the
@@ -181,13 +190,13 @@ function ToolCallCard({ call, cwd, isFirst, isLast }: ToolCallCardProps) {
181
190
  isFirst={isFirst}
182
191
  isLast={isLast}
183
192
  call={call}
184
- marker={succeeded ? <IconMarker icon={IconPackage} size={14} stroke={1.75} /> : undefined}
193
+ marker={succeeded ? <IconMarker icon={IconPackage} size={16} stroke={1.75} /> : undefined}
185
194
  name="Loading Skill"
186
195
  brief={call.skill.skillName}
187
196
  />
188
197
  )
189
198
  }
190
- const mcp = parseMcporterCall(call) ?? parseNativeMcp(call)
199
+ const mcp = parseMcporterCall(call) ?? parseNativeMcp(call) ?? parseCodexMcp(call)
191
200
  if (mcp) {
192
201
  const fn = formatMcpTool(mcp.server, mcp.tool)
193
202
  return (