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
@@ -1,4 +1,4 @@
1
- import { useRef, useState } from 'react'
1
+ import { type RefObject, useRef, useState } from 'react'
2
2
 
3
3
  import {
4
4
  IconArrowUp,
@@ -10,14 +10,20 @@ import {
10
10
  } from '@tabler/icons-react'
11
11
 
12
12
  import { cn } from '@/client/lib/cn'
13
- import { useWorkspaceId } from '@/client/lib/WorkspaceContext'
14
- import { uploadFiles } from '@/client/lib/uploads'
15
- import { type ChatAttachment, draftKey, liveStore, useLive } from '@/client/store/live'
13
+ import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
14
+ import { uploadFiles } from '@/client/features/chat/uploads'
15
+ import {
16
+ type ChatAttachment,
17
+ draftKey,
18
+ liveStore,
19
+ useLive
20
+ } from '@/client/features/chat/chat-store'
16
21
 
17
22
  import { ModelPicker } from './ModelPicker'
18
- import { Button } from './ui/button'
23
+ import { Button } from '@/client/components/ui/button'
19
24
 
20
- type ChatInputProps = {
25
+ type ChatComposerProps = {
26
+ composerRef: RefObject<HTMLTextAreaElement | null>
21
27
  onSend: (text: string) => void
22
28
  onStop: () => void
23
29
  processing: boolean
@@ -28,8 +34,7 @@ type ChatInputProps = {
28
34
  // panel, message list, or surrounding workspace. The draft is keyed by the
29
35
  // active thread, so switching threads swaps the unsent text with you. Attachments
30
36
  // (drag/drop, paste, attach button) are tracked the same way and cleared on send.
31
- export function ChatInput({ onSend, onStop, processing }: ChatInputProps) {
32
- const ref = useRef<HTMLTextAreaElement>(null)
37
+ export function ChatComposer({ composerRef, onSend, onStop, processing }: ChatComposerProps) {
33
38
  const fileRef = useRef<HTMLInputElement>(null)
34
39
  const workspaceId = useWorkspaceId()
35
40
  const sessionId = useLive(s => s.activeByWorkspace[workspaceId] ?? null)
@@ -92,7 +97,7 @@ export function ChatInput({ onSend, onStop, processing }: ChatInputProps) {
92
97
  onMouseDown={e => {
93
98
  if (e.target instanceof HTMLElement && e.target.closest('button')) return
94
99
  e.preventDefault()
95
- ref.current?.focus()
100
+ composerRef.current?.focus()
96
101
  }}
97
102
  onDragOver={e => {
98
103
  if (!e.dataTransfer.types.includes('Files')) return
@@ -111,7 +116,7 @@ export function ChatInput({ onSend, onStop, processing }: ChatInputProps) {
111
116
  addFiles(Array.from(e.dataTransfer.files))
112
117
  }}
113
118
  className={cn(
114
- 'flex w-full cursor-text flex-col gap-1 rounded-lg bg-white p-2 shadow-xs transition-[color,box-shadow] outline-none focus-within:shadow-sm',
119
+ 'flex w-full max-w-(--chat-max-container) cursor-text flex-col gap-1 rounded-lg bg-card p-2 text-card-foreground shadow-xs transition-[color,box-shadow] outline-none focus-within:shadow-sm',
115
120
  dragOver && 'ring-2 ring-ring/60'
116
121
  )}
117
122
  >
@@ -130,7 +135,7 @@ export function ChatInput({ onSend, onStop, processing }: ChatInputProps) {
130
135
  )}
131
136
 
132
137
  <textarea
133
- ref={ref}
138
+ ref={composerRef}
134
139
  id="chat-input"
135
140
  name="message"
136
141
  value={value}
@@ -147,8 +152,7 @@ export function ChatInput({ onSend, onStop, processing }: ChatInputProps) {
147
152
  e.preventDefault()
148
153
  addFiles(files)
149
154
  }}
150
- placeholder={processing ? 'Queue a follow-up...' : 'Ask anything...'}
151
- autoFocus
155
+ placeholder={processing ? 'Queue a follow-up' : 'Do anything'}
152
156
  rows={1}
153
157
  className="field-sizing-content max-h-40 w-full resize-none bg-transparent px-2 py-1 text-sm leading-relaxed outline-none placeholder:text-muted-foreground disabled:opacity-50"
154
158
  />
@@ -204,9 +208,9 @@ function AttachmentChip({ attachment, onRemove }: AttachmentChipProps) {
204
208
  return (
205
209
  <div
206
210
  className={cn(
207
- 'group relative flex items-center gap-2 overflow-hidden rounded-md border border-black/10 bg-black/[0.03]',
211
+ 'group relative flex items-center gap-2 overflow-hidden rounded-md border border-border bg-accent text-accent-foreground',
208
212
  isImage ? 'size-14' : 'h-10 max-w-52 pr-2 pl-2',
209
- status === 'error' && 'border-red-300'
213
+ status === 'error' && 'border-destructive/50'
210
214
  )}
211
215
  title={error ?? name}
212
216
  >
@@ -214,30 +218,32 @@ function AttachmentChip({ attachment, onRemove }: AttachmentChipProps) {
214
218
  <img src={previewUrl} alt={name} className="size-full object-cover" />
215
219
  ) : (
216
220
  <>
217
- <IconFile size={16} stroke={1.5} className="shrink-0 text-muted-foreground" />
218
- <span className="truncate text-xs text-foreground/80">{name}</span>
221
+ <IconFile size={16} stroke={1.75} className="shrink-0 text-muted-foreground" />
222
+ <span className="truncate text-xs">{name}</span>
219
223
  </>
220
224
  )}
221
225
 
222
226
  {status === 'uploading' && (
223
- <div className="absolute inset-0 flex items-center justify-center bg-white/60">
224
- <IconLoader2 size={16} stroke={1.5} className="animate-spin text-muted-foreground" />
227
+ <div className="absolute inset-0 flex items-center justify-center bg-background/70">
228
+ <IconLoader2 size={16} stroke={1.75} className="animate-spin text-muted-foreground" />
225
229
  </div>
226
230
  )}
227
231
  {status === 'error' && (
228
- <div className="absolute inset-0 flex items-center justify-center bg-red-50/80 text-[10px] text-red-700">
232
+ <div className="absolute inset-0 flex items-center justify-center bg-destructive/10 text-[10px] text-destructive">
229
233
  Failed
230
234
  </div>
231
235
  )}
232
236
 
233
- <button
237
+ <Button
234
238
  type="button"
239
+ variant="ghost"
240
+ size="icon-sm"
235
241
  onClick={onRemove}
236
242
  aria-label={`Remove ${name}`}
237
- className="absolute top-0.5 right-0.5 flex size-4 items-center justify-center rounded-full bg-black/60 text-white opacity-0 transition-opacity group-hover:opacity-100"
243
+ className="absolute top-0.5 right-0.5 size-4 rounded-full bg-primary/70 text-primary-foreground opacity-0 transition-opacity group-hover:opacity-100 hover:bg-primary/80 [&_svg]:size-3"
238
244
  >
239
- <IconX size={10} stroke={2} />
240
- </button>
245
+ <IconX stroke={1.75} />
246
+ </Button>
241
247
  </div>
242
248
  )
243
249
  }
@@ -0,0 +1,171 @@
1
+ import { type ReactNode, useCallback, useEffect, useMemo, useRef } from 'react'
2
+
3
+ import { IconChevronDown, IconX } from '@tabler/icons-react'
4
+
5
+ import { useStickToBottom } from '@/client/features/chat/useStickToBottom'
6
+ import { groupTurns } from '@/client/features/chat/group-turns'
7
+ import type { Turn, ViewState } from '@/lib/types'
8
+
9
+ import { ChatComposer } from './ChatComposer'
10
+ import { ChatSelector } from './ChatSelector'
11
+ import { EmptyState, ThinkingIndicator, TurnView } from './TurnView'
12
+ import { Button } from '@/client/components/ui/button'
13
+
14
+ type ChatPanelProps = {
15
+ active?: boolean
16
+ focusRequest?: number
17
+ view: ViewState
18
+ // The live streaming preview as a synthetic assistant turn (or null). Merged
19
+ // into the transcript through the same groupTurns pipeline so a thinking-only
20
+ // preview folds into the current tool group. See client/lib/preview-turn.ts.
21
+ previewTurn?: Turn | null
22
+ // Active thread id — used only as the scroll reset key (jump to bottom on
23
+ // thread switch).
24
+ sessionId?: string | null
25
+ processing: boolean
26
+ error?: string | null
27
+ onDismissError?: () => void
28
+ send: (text: string) => void
29
+ stop: () => void
30
+ onSwitchThread: (sessionId: string | null) => void
31
+ // Extra content for the header's left edge, rendered before the thread
32
+ // selector when the chat is the primary panel.
33
+ headerLeft?: ReactNode
34
+ // Extra controls for the header's right edge — the parent supplies whatever
35
+ // chrome belongs here in the current layout (e.g. the section reopen toggle
36
+ // plus MCP/settings menus when the chat is fullscreen).
37
+ headerRight?: ReactNode
38
+ // Floating popup: render a close (X) button that dismisses the popup.
39
+ onClose?: () => void
40
+ }
41
+
42
+ export function ChatPanel({
43
+ active = true,
44
+ focusRequest = 0,
45
+ view,
46
+ previewTurn,
47
+ sessionId,
48
+ processing,
49
+ error,
50
+ onDismissError,
51
+ send,
52
+ stop,
53
+ onSwitchThread,
54
+ headerLeft,
55
+ headerRight,
56
+ onClose
57
+ }: ChatPanelProps) {
58
+ const composerRef = useRef<HTMLTextAreaElement>(null)
59
+ const scrollRef = useRef<HTMLDivElement>(null)
60
+ const turns = view.turns
61
+ // Visual grouping: fold consecutive tool-only assistant turns into one
62
+ // synthetic turn so OpenAI Codex–style traces (which serialize one
63
+ // assistant message per agent step) don't render with the wider
64
+ // inter-turn gap between every tool call. See `dev/turn-spacing.md`.
65
+ // The live preview turn is appended before grouping, so a thinking-only
66
+ // preview merges into the trailing tool group exactly like its finalized form.
67
+ const groupedTurns = useMemo(
68
+ () => groupTurns(previewTurn ? [...turns, previewTurn] : turns),
69
+ [turns, previewTurn]
70
+ )
71
+
72
+ // Stick to the bottom while pinned; respect scroll-up; jump on thread switch.
73
+ const { atBottom, scrollToBottom } = useStickToBottom(scrollRef, sessionId)
74
+
75
+ // The active chat surface owns initial focus. A monotonically increasing
76
+ // request also refocuses an already-visible composer after intent actions.
77
+ useEffect(() => {
78
+ if (active) composerRef.current?.focus()
79
+ }, [active, focusRequest])
80
+
81
+ // Sending always returns the user to the bottom, even if they'd scrolled up —
82
+ // they expect to see their message and the reply.
83
+ const handleSend = useCallback(
84
+ (text: string) => {
85
+ send(text)
86
+ scrollToBottom()
87
+ },
88
+ [send, scrollToBottom]
89
+ )
90
+
91
+ return (
92
+ <div className="flex min-h-0 flex-1 flex-col pt-2 pb-3">
93
+ <header className="flex items-center justify-between pr-2 pb-2 pl-2">
94
+ <div className="flex min-w-0 items-center gap-2.5">
95
+ {headerLeft}
96
+ <ChatSelector onSwitch={onSwitchThread} />
97
+ </div>
98
+ <div className="flex items-center gap-0.5">
99
+ {headerRight}
100
+ {onClose && (
101
+ <Button variant="ghost" size="icon" onClick={onClose} aria-label="Close chat">
102
+ <IconX stroke={1.5} />
103
+ </Button>
104
+ )}
105
+ </div>
106
+ </header>
107
+
108
+ <div className="relative flex min-h-0 flex-1 flex-col">
109
+ <div
110
+ ref={scrollRef}
111
+ className="flex scrollbar-thin flex-1 scroll-fade flex-col overflow-y-auto overscroll-contain px-5 pt-4 pb-12 [--scroll-fade-reveal:8px]"
112
+ >
113
+ <div className="mx-auto flex w-full max-w-(--chat-max-container) flex-1 flex-col gap-6">
114
+ {turns.length === 0 && !processing && <EmptyState />}
115
+ {groupedTurns.map((turn, i) => (
116
+ <TurnView
117
+ key={turn.id}
118
+ turn={turn}
119
+ processing={processing && i === groupedTurns.length - 1}
120
+ />
121
+ ))}
122
+ {/* Pulsing dots only before the first token — once the preview has
123
+ visible content it renders as a (possibly merged) grouped turn. */}
124
+ {processing && !previewTurn && <ThinkingIndicator />}
125
+ </div>
126
+ </div>
127
+
128
+ {/* Jump to latest — shown only when scrolled up, so following the tail
129
+ never yanks the user while they read history. */}
130
+ {!atBottom && turns.length > 0 && (
131
+ <Button
132
+ type="button"
133
+ variant="outline"
134
+ size="icon"
135
+ onClick={() => scrollToBottom('smooth')}
136
+ aria-label="Jump to latest"
137
+ className="absolute bottom-3 left-1/2 -translate-x-1/2 animate-in rounded-full fade-in slide-in-from-bottom-1"
138
+ >
139
+ <IconChevronDown stroke={1.5} />
140
+ </Button>
141
+ )}
142
+ </div>
143
+
144
+ <div className="mx-auto flex w-full justify-center px-3">
145
+ {error && (
146
+ <div className="mb-2 flex items-start gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
147
+ <span className="flex-1 wrap-break-word">{error}</span>
148
+ {onDismissError && (
149
+ <Button
150
+ type="button"
151
+ variant="ghost"
152
+ size="icon-sm"
153
+ onClick={onDismissError}
154
+ className="-m-1"
155
+ aria-label="Dismiss error"
156
+ >
157
+ <IconX stroke={1.75} />
158
+ </Button>
159
+ )}
160
+ </div>
161
+ )}
162
+ <ChatComposer
163
+ composerRef={composerRef}
164
+ onSend={handleSend}
165
+ onStop={stop}
166
+ processing={processing}
167
+ />
168
+ </div>
169
+ </div>
170
+ )
171
+ }
@@ -1,27 +1,33 @@
1
1
  import type { ReactNode, RefObject } from 'react'
2
- import { useState } from 'react'
3
2
 
4
3
  import { motion } from 'motion/react'
5
4
 
6
- import { IconRobotFace } from '@tabler/icons-react'
5
+ import { IconGhost } from '@tabler/icons-react'
7
6
 
8
- import { Button } from './ui/button'
9
- import { Popover, PopoverContent, PopoverTrigger } from './ui/popover'
7
+ import { Button } from '@/client/components/ui/button'
8
+ import { Popover, PopoverContent, PopoverTrigger } from '@/client/components/ui/popover'
10
9
 
11
10
  type ChatPopupProps = {
12
- defaultOpen?: boolean
11
+ open: boolean
12
+ onOpenChange: (open: boolean) => void
13
+ onOpenChangeComplete: (open: boolean) => void
13
14
  // Portal target for the floating chat — pass the themed workspace wrapper so
14
15
  // the popup inherits its scoped CSS vars instead of landing on a bare body.
15
16
  container?: RefObject<HTMLElement | null>
16
17
  children: (onClose: () => void) => ReactNode
17
18
  }
18
19
 
19
- export function ChatPopup({ defaultOpen = false, container, children }: ChatPopupProps) {
20
- const [open, setOpen] = useState(defaultOpen)
21
- const onClose = () => setOpen(false)
20
+ export function ChatPopup({
21
+ open,
22
+ onOpenChange,
23
+ onOpenChangeComplete,
24
+ container,
25
+ children
26
+ }: ChatPopupProps) {
27
+ const onClose = () => onOpenChange(false)
22
28
 
23
29
  return (
24
- <Popover open={open} onOpenChange={o => setOpen(o)}>
30
+ <Popover open={open} onOpenChange={onOpenChange} onOpenChangeComplete={onOpenChangeComplete}>
25
31
  <PopoverTrigger
26
32
  render={
27
33
  <div className="fixed right-4 bottom-4 sm:right-6 sm:bottom-6">
@@ -35,10 +41,15 @@ export function ChatPopup({ defaultOpen = false, container, children }: ChatPopu
35
41
  animate={open ? 'invisible' : 'to'}
36
42
  transition={{ type: 'spring', duration: 0.3, delay: 0.2, bounce: 0 }}
37
43
  >
38
- {/* Floating over a themed workspace — pin to white so it stays
39
- legible regardless of the active theme's --background. */}
40
- <Button variant="outline" size="lg" className="bg-white hover:bg-white">
41
- <IconRobotFace stroke={1.75} /> Agent
44
+ {/* Floating over a themed workspace — use the card pair so it
45
+ stays legible regardless of the active theme background. */}
46
+ <Button
47
+ variant="outline"
48
+ size="icon-lg"
49
+ className="shadow-md hover:shadow-lg"
50
+ aria-label="Agent"
51
+ >
52
+ <IconGhost stroke={1.75} />
42
53
  </Button>
43
54
  </motion.div>
44
55
  </div>
@@ -1,11 +1,11 @@
1
1
  import { IconChevronDown, IconPlus } from '@tabler/icons-react'
2
2
 
3
- import { useWorkspaceSessions } from '@/client/api/workspaces'
4
- import { useWorkspaceId } from '@/client/lib/WorkspaceContext'
3
+ import { useWorkspaceSessions } from './api'
4
+ import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
5
5
  import { cn } from '@/client/lib/cn'
6
- import { useLive } from '@/client/store/live'
6
+ import { useLive } from '@/client/features/chat/chat-store'
7
7
 
8
- import { Button } from './ui/button'
8
+ import { Button } from '@/client/components/ui/button'
9
9
  import {
10
10
  DropdownMenu,
11
11
  DropdownMenuContent,
@@ -13,9 +13,9 @@ import {
13
13
  DropdownMenuItem,
14
14
  DropdownMenuShortcut,
15
15
  DropdownMenuTrigger
16
- } from './ui/dropdown-menu'
16
+ } from '@/client/components/ui/dropdown-menu'
17
17
 
18
- type ThreadSelectorProps = {
18
+ type ChatSelectorProps = {
19
19
  onSwitch: (sessionId: string | null) => void
20
20
  }
21
21
 
@@ -32,13 +32,13 @@ function formatDate(ms: number) {
32
32
  return date.toLocaleDateString([], { month: 'short', day: 'numeric' })
33
33
  }
34
34
 
35
- export function ThreadSelector({ onSwitch }: ThreadSelectorProps) {
35
+ export function ChatSelector({ onSwitch }: ChatSelectorProps) {
36
36
  const workspaceId = useWorkspaceId()
37
37
  const { data: sessions = [], refetch } = useWorkspaceSessions(workspaceId)
38
38
  const activeSessionId = useLive(s => s.activeByWorkspace[workspaceId] ?? null)
39
39
 
40
40
  const active = sessions.find(s => s.sessionId === activeSessionId)
41
- const label = active?.summary ?? 'New thread'
41
+ const label = active?.summary ?? 'New chat'
42
42
 
43
43
  function handleSelect(sessionId: string | null) {
44
44
  onSwitch(sessionId)
@@ -52,9 +52,9 @@ export function ThreadSelector({ onSwitch }: ThreadSelectorProps) {
52
52
  >
53
53
  <DropdownMenuTrigger
54
54
  render={
55
- <Button variant="ghost" className="-mx-3">
55
+ <Button variant="ghost">
56
56
  <span className="max-w-64 truncate">{label}</span>
57
- <IconChevronDown stroke={1.5} className="text-muted-foreground" />
57
+ <IconChevronDown stroke={1.5} />
58
58
  </Button>
59
59
  }
60
60
  />
@@ -63,15 +63,17 @@ export function ThreadSelector({ onSwitch }: ThreadSelectorProps) {
63
63
  className="text-muted-foreground! **:text-muted-foreground!"
64
64
  onClick={() => handleSelect(null)}
65
65
  >
66
- <IconPlus size={16} stroke={1.5} />
67
- New thread
66
+ <IconPlus size={16} stroke={1.75} />
67
+ New chat
68
68
  </DropdownMenuItem>
69
69
  {sessions.length > 0 && (
70
70
  <DropdownMenuGroup>
71
71
  {sessions.map(s => (
72
72
  <DropdownMenuItem
73
73
  key={s.sessionId}
74
- className={cn(activeSessionId === s.sessionId && 'bg-accent')}
74
+ className={cn(
75
+ activeSessionId === s.sessionId && 'bg-accent text-accent-foreground'
76
+ )}
75
77
  onClick={() => handleSelect(s.sessionId)}
76
78
  >
77
79
  <span className="truncate">{s.summary}</span>
@@ -13,7 +13,7 @@ const components = {
13
13
  pre({ children }: ComponentProps<'pre'>) {
14
14
  return (
15
15
  <div className="not-prose my-2 rounded-md border border-border bg-muted px-3 py-2.5">
16
- <pre className="max-h-[300px] overflow-auto font-mono text-xs leading-relaxed whitespace-pre text-foreground/80">
16
+ <pre className="max-h-[300px] overflow-auto font-mono text-xs leading-relaxed whitespace-pre text-foreground">
17
17
  {children}
18
18
  </pre>
19
19
  </div>
@@ -2,11 +2,12 @@ import { memo, useState } from 'react'
2
2
 
3
3
  import { IconChevronDown } from '@tabler/icons-react'
4
4
 
5
- import { useSaveThreadConfig, useThreadConfig, useWorkspaceModels } from '@/client/api/workspaces'
6
- import { useWorkspaceLayoutCtx } from '@/client/lib/WorkspaceLayoutContext'
7
- import { useLive } from '@/client/store/live'
5
+ import { useSaveThreadConfig, useThreadConfig, useWorkspaceModels } from './api'
6
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
7
+ import { useLive } from '@/client/features/chat/chat-store'
8
+ import type { Model } from '@/lib/types'
8
9
 
9
- import { Button } from './ui/button'
10
+ import { Button } from '@/client/components/ui/button'
10
11
  import {
11
12
  DropdownMenu,
12
13
  DropdownMenuContent,
@@ -19,8 +20,8 @@ import {
19
20
  DropdownMenuSubContent,
20
21
  DropdownMenuSubTrigger,
21
22
  DropdownMenuTrigger
22
- } from './ui/dropdown-menu'
23
- import { Switch } from './ui/switch'
23
+ } from '@/client/components/ui/dropdown-menu'
24
+ import { Switch } from '@/client/components/ui/switch'
24
25
 
25
26
  // Models describe themselves with a " · "-joined blurb; we show only the
26
27
  // headline (e.g. "Opus 4.8 with 1M context · Most capable…" → "Opus 4.8 with 1M context").
@@ -32,6 +33,39 @@ function capitalize(s: string): string {
32
33
  return s.charAt(0).toUpperCase() + s.slice(1)
33
34
  }
34
35
 
36
+ // Display label for a reasoning-effort level. Values stay as the SDK's ids
37
+ // ('low'…'max'); only the label differs — 'xhigh' reads as "Extra".
38
+ function effortLabel(level: string): string {
39
+ return level === 'xhigh' ? 'Extra' : capitalize(level)
40
+ }
41
+
42
+ // Output price ($/Mtok) parsed from a model's "$in/$out per Mtok" blurb.
43
+ function outputPrice(description?: string): number {
44
+ const m = description?.match(/\$\d+(?:\.\d+)?\s*\/\s*\$(\d+(?:\.\d+)?)\s*per Mtok/)
45
+ return m ? Number(m[1]) : -1
46
+ }
47
+
48
+ // Canonical wire id without a context-variant suffix, e.g.
49
+ // 'claude-opus-4-8[1m]' → 'claude-opus-4-8'. Groups a model with its variants.
50
+ function familyOf(m: Model): string | undefined {
51
+ return m.resolvedModel?.replace(/\[[^\]]*\]$/, '')
52
+ }
53
+
54
+ // Sort key ordering models most-capable-first (Fable → Opus → Sonnet → Haiku)
55
+ // from price alone, no hardcoded names. A bare alias that omits its price (e.g.
56
+ // plain 'opus') borrows a same-family variant's price ('opus[1m]'s $/Mtok) so
57
+ // the two group together. Unpriced models (OpenClaw) return -1 → sort last,
58
+ // keeping their original order since they're all equal.
59
+ function sortPrice(m: Model, all: Model[]): number {
60
+ const own = outputPrice(m.description)
61
+ if (own >= 0) return own
62
+ const family = familyOf(m)
63
+ const sibling = all.find(
64
+ x => x !== m && familyOf(x) === family && outputPrice(x.description) >= 0
65
+ )
66
+ return sibling ? outputPrice(sibling.description) : -1
67
+ }
68
+
35
69
  // Model selector for the chat composer. Renders the workspace's available
36
70
  // models from `/api/workspaces/:id/models`. Model + reasoning effort are
37
71
  // persisted PER THREAD (so a thread reopens with the settings it last ran with)
@@ -45,7 +79,17 @@ function capitalize(s: string): string {
45
79
  export const ModelPicker = memo(function ModelPicker() {
46
80
  const { workspaceId, layout, setLayout } = useWorkspaceLayoutCtx()
47
81
  const { data } = useWorkspaceModels(workspaceId)
48
- const models = data?.models ?? []
82
+ // The SDK prepends a synthetic "default" entry ("Use the default model
83
+ // (currently …)"). Drop it and surface the concrete model it resolves to
84
+ // instead, so the picker shows e.g. "Opus (1M context)" rather than the meta
85
+ // "use default" row.
86
+ const allModels = data?.models ?? []
87
+ const defaultEntry = allModels.find(m => m.value === 'default')
88
+ // Drop the "default" entry, then order by price descending. Array.sort is
89
+ // stable, so same-price variants (Opus 1M vs standard) keep the SDK's order.
90
+ const models = allModels
91
+ .filter(m => m.value !== 'default')
92
+ .sort((a, b) => sortPrice(b, allModels) - sortPrice(a, allModels))
49
93
 
50
94
  // The active thread, if any. Its stored config is the source of truth; a new
51
95
  // chat (no active thread) falls back to — and edits — the workspace defaults.
@@ -69,10 +113,16 @@ export const ModelPicker = memo(function ModelPicker() {
69
113
 
70
114
  if (models.length === 0) return null
71
115
 
72
- // Show the persisted pick when it's still in the list; otherwise the first
73
- // model. An unset pick sends no model id, so the run uses the SDK default.
116
+ // Show the persisted pick when it's still in the list; otherwise fall back to
117
+ // the concrete model the SDK default resolves to (matched by resolvedModel),
118
+ // or the first model. An unset pick sends no model id, so the run still uses
119
+ // the SDK default — the display just names it instead of showing "default".
74
120
  const persisted = models.some(m => m.value === selected) ? selected : undefined
75
- const current = persisted ?? models[0].value
121
+ const defaultModel =
122
+ models.find(
123
+ m => defaultEntry?.resolvedModel && m.resolvedModel === defaultEntry.resolvedModel
124
+ ) ?? models[0]
125
+ const current = persisted ?? defaultModel.value
76
126
  const model = models.find(m => m.value === current) ?? models[0]
77
127
  const effortLevels = model.supportsEffort ? (model.supportedEffortLevels ?? []) : []
78
128
  const currentEffort =
@@ -85,14 +135,14 @@ export const ModelPicker = memo(function ModelPicker() {
85
135
  <DropdownMenu>
86
136
  <DropdownMenuTrigger
87
137
  render={
88
- <Button variant="ghost" size="default" className="gap-1.5 px-2.5 text-muted-foreground">
138
+ <Button variant="ghost">
89
139
  <span className="font-normal text-foreground">
90
140
  {headline(model.description) || model.displayName}
91
141
  </span>
92
142
  {currentEffort && (
93
- <span className="text-muted-foreground">{capitalize(currentEffort)}</span>
143
+ <span className="text-muted-foreground">{effortLabel(currentEffort)}</span>
94
144
  )}
95
- <IconChevronDown className="size-3.5! text-muted-foreground/60" stroke={1.5} />
145
+ <IconChevronDown stroke={1.5} />
96
146
  </Button>
97
147
  }
98
148
  />
@@ -116,7 +166,9 @@ export const ModelPicker = memo(function ModelPicker() {
116
166
  <div className="flex flex-1 items-center justify-between">
117
167
  Reasoning
118
168
  {currentEffort && (
119
- <span className="ml-auto text-muted-foreground">{capitalize(currentEffort)}</span>
169
+ <span className="ml-auto text-muted-foreground">
170
+ {effortLabel(currentEffort)}
171
+ </span>
120
172
  )}
121
173
  </div>
122
174
  </DropdownMenuSubTrigger>
@@ -124,7 +176,7 @@ export const ModelPicker = memo(function ModelPicker() {
124
176
  <DropdownMenuRadioGroup value={currentEffort} onValueChange={setEffort}>
125
177
  {effortLevels.map(level => (
126
178
  <DropdownMenuRadioItem key={level} value={level} closeOnClick>
127
- {capitalize(level)}
179
+ {effortLabel(level)}
128
180
  </DropdownMenuRadioItem>
129
181
  ))}
130
182
  </DropdownMenuRadioGroup>
@@ -134,9 +186,8 @@ export const ModelPicker = memo(function ModelPicker() {
134
186
 
135
187
  {showFastMode && (
136
188
  <DropdownMenuGroup className="mt-0.5">
137
- <DropdownMenuLabel>Fast mode</DropdownMenuLabel>
138
189
  <label className="flex cursor-pointer items-center justify-between gap-4 rounded-xs px-2 py-1 text-sm">
139
- Enable fast mode
190
+ Fast mode
140
191
  <Switch checked={fastMode} onCheckedChange={setFastMode} />
141
192
  </label>
142
193
  </DropdownMenuGroup>