moi-computer 0.3.0-next.0 → 0.3.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/bunfig.toml +5 -1
  2. package/client/AGENTS.md +15 -0
  3. package/client/accept-hmr-dependencies.ts +22 -0
  4. package/client/api/http.ts +31 -0
  5. package/client/api/query-options.ts +6 -0
  6. package/client/api/workspace-keys.ts +17 -0
  7. package/client/app/AppRouter.tsx +35 -0
  8. package/client/app/routes/HomeRoute.tsx +13 -0
  9. package/client/app/routes/WorkspaceRoute.tsx +89 -0
  10. package/client/app/shell/SidebarLayout.tsx +191 -0
  11. package/client/assets.d.ts +9 -0
  12. package/client/components/playground/PixelPainter.tsx +10 -21
  13. package/client/components/playground/PlaygroundPage.tsx +9 -11
  14. package/client/components/playground/ToolCallsPage.tsx +9 -11
  15. package/client/components/{BottomPanel.tsx → shared/BottomPanel.tsx} +1 -1
  16. package/client/components/shared/PanelHeader.tsx +9 -0
  17. package/client/components/shared/ReorderableList.tsx +199 -0
  18. package/client/components/ui/button.tsx +10 -7
  19. package/client/components/ui/collapsible.tsx +15 -0
  20. package/client/components/ui/dialog.tsx +2 -2
  21. package/client/components/ui/dropdown-menu.tsx +5 -5
  22. package/client/components/ui/hover-card.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/{components → features/applets}/WidgetErrorBoundary.tsx +1 -1
  28. package/client/{components → features/applets}/WidgetShell.tsx +1 -1
  29. package/client/{hooks → features/applets}/useApplet.ts +6 -7
  30. package/client/{components/ChatInput.tsx → features/chat/ChatComposer.tsx} +29 -23
  31. package/client/features/chat/ChatPanel.tsx +188 -0
  32. package/client/{components → features/chat}/ChatPopup.tsx +23 -12
  33. package/client/{components → features/chat}/MarkdownContent.tsx +1 -1
  34. package/client/{components → features/chat}/ModelPicker.tsx +68 -17
  35. package/client/{components → features/chat}/ThreadSelector.tsx +11 -9
  36. package/client/{components → features/chat}/TurnView.tsx +16 -9
  37. package/client/features/chat/api.ts +78 -0
  38. package/client/features/chat/chat-connection.ts +107 -0
  39. package/client/features/chat/chat-frames.ts +131 -0
  40. package/client/{lib → features/chat}/preview-turn.ts +1 -1
  41. package/client/{components → features/chat}/tool-group/ReadImagePreview.tsx +1 -1
  42. package/client/{components → features/chat}/tool-group/SubagentCard.tsx +12 -10
  43. package/client/{components → features/chat}/tool-group/TimelineRow.tsx +5 -5
  44. package/client/{components → features/chat}/tool-group/ToolCallGroup.tsx +12 -4
  45. package/client/{components → features/chat}/tool-group/ToolOutput.tsx +12 -18
  46. package/client/{hooks → features/chat}/useChat.ts +7 -11
  47. package/client/features/connectors/ConnectorsPage.tsx +92 -0
  48. package/client/features/connectors/McpMenu.tsx +162 -0
  49. package/client/features/connectors/api.ts +28 -0
  50. package/client/features/home/CreateWorkspaceDialog.tsx +224 -0
  51. package/client/features/home/HomePage.tsx +220 -0
  52. package/client/{components → features/home}/WorkspacePreview.tsx +2 -2
  53. package/client/features/home/api.ts +148 -0
  54. package/client/features/home/workspace-presentation.tsx +44 -0
  55. package/client/features/scratchpad/Scratchpad.tsx +312 -0
  56. package/client/features/scratchpad/ScratchpadControls.tsx +503 -0
  57. package/client/features/scratchpad/useScratchpadSnapshot.tsx +115 -0
  58. package/client/features/settings/EnvironmentSettings.tsx +149 -0
  59. package/client/features/settings/GeneralSettings.tsx +90 -0
  60. package/client/{components → features}/settings/IconPicker.tsx +73 -222
  61. package/client/features/settings/SettingsLayout.tsx +53 -0
  62. package/client/{components → features}/settings/WorkspaceSettings.tsx +12 -16
  63. package/client/features/settings/api.ts +88 -0
  64. package/client/features/settings/icon-picker-options.ts +161 -0
  65. package/client/{hooks → features/settings}/useEnvVars.ts +4 -4
  66. package/client/{components → features/widgets}/HiddenPanel.tsx +3 -3
  67. package/client/{components → features/widgets}/WidgetFrame.tsx +3 -8
  68. package/client/{components → features/widgets}/WidgetGrid.tsx +2 -9
  69. package/client/features/widgets/Widgets.tsx +215 -0
  70. package/client/{lib/grid-pack.ts → features/widgets/grid.ts} +7 -1
  71. package/client/{hooks → features/widgets}/useGridReconcile.ts +1 -1
  72. package/client/{components → features/workspace}/CustomizePanel.tsx +5 -6
  73. package/client/{lib → features/workspace}/WorkspaceLayoutContext.tsx +15 -8
  74. package/client/features/workspace/WorkspaceScreen.tsx +536 -0
  75. package/client/features/workspace/WorkspaceTabs.tsx +205 -0
  76. package/client/features/workspace/api.ts +56 -0
  77. package/client/features/workspace/useFitsSplitLayout.ts +37 -0
  78. package/client/global.d.ts +5 -0
  79. package/client/index.css +6 -10
  80. package/client/index.html +1 -1
  81. package/client/index.tsx +14 -31
  82. package/client/lib/ws-url.ts +10 -0
  83. package/client/main.tsx +2 -2
  84. package/client/runtime/hmr-watchdog.ts +39 -0
  85. package/client/{hooks/useMeiEvents.ts → runtime/useWorkspaceEvents.ts} +11 -7
  86. package/client/store/ui.ts +5 -1
  87. package/client/theme.css +0 -2
  88. package/dist/chunk-11cab5dq.css +1 -0
  89. package/dist/chunk-23cgr1tz.css +1 -0
  90. package/dist/chunk-3hy3qy6d.js +10 -0
  91. package/dist/chunk-c4j722at.js +546 -0
  92. package/dist/chunk-dyfaffyz.js +119 -0
  93. package/dist/chunk-kpe40hm8.js +1 -0
  94. package/dist/chunk-p68fnz3q.js +2 -0
  95. package/dist/chunk-pcnahct1.js +5 -0
  96. package/dist/chunk-tqd3pkg8.css +1 -0
  97. package/dist/chunk-ty6dvda0.js +1 -0
  98. package/dist/index.html +2 -2
  99. package/lib/types.ts +18 -7
  100. package/lib/workspace-name.ts +14 -0
  101. package/package.json +3 -2
  102. package/server/api.ts +127 -17
  103. package/server/applets.ts +84 -8
  104. package/server/cli.ts +11 -5
  105. package/server/layout.ts +38 -7
  106. package/server/mcp.ts +72 -15
  107. package/server/moi-scaffold.ts +55 -10
  108. package/server/registry.ts +16 -0
  109. package/server/views.ts +0 -0
  110. package/server/web.ts +1 -0
  111. package/server/widgets.ts +3 -2
  112. package/server/workspace-init.ts +5 -19
  113. package/tsconfig.json +1 -1
  114. package/workspace/.claude/skills/moi-workspace/DESIGN.md +1 -1
  115. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +1 -1
  116. package/client/api/workspaces.ts +0 -427
  117. package/client/components/App.tsx +0 -41
  118. package/client/components/ChatPanel.tsx +0 -275
  119. package/client/components/HomePage.tsx +0 -17
  120. package/client/components/McpMenu.tsx +0 -125
  121. package/client/components/Scratchpad.tsx +0 -935
  122. package/client/components/Widgets.tsx +0 -132
  123. package/client/components/WorkspacesPage.tsx +0 -245
  124. package/client/components/layout/SidebarLayout.tsx +0 -258
  125. package/client/components/routes/workspace/[id].tsx +0 -675
  126. package/client/components/routes/workspace/create.tsx +0 -155
  127. package/client/components/settings/SettingsPages.tsx +0 -255
  128. package/client/hooks/useFitsSidebar.ts +0 -34
  129. package/client/lib/connection.ts +0 -237
  130. package/dist/chunk-07qf2tv1.css +0 -1
  131. package/dist/chunk-c3zjp9ez.js +0 -672
  132. /package/client/components/{playground → shared}/LedLogo.tsx +0 -0
  133. /package/client/{lib → features/applets}/applet-cache.ts +0 -0
  134. /package/client/{components → features/chat}/ShimmerText.tsx +0 -0
  135. /package/client/{store/live.ts → features/chat/chat-store.ts} +0 -0
  136. /package/client/{lib → features/chat}/group-turns.ts +0 -0
  137. /package/client/{components → features/chat}/tool-group/CodeBlock.tsx +0 -0
  138. /package/client/{components → features/chat}/tool-group/Collapse.tsx +0 -0
  139. /package/client/{components → features/chat}/tool-group/detect.ts +0 -0
  140. /package/client/{components → features/chat}/tool-group/fixtures.ts +0 -0
  141. /package/client/{components → features/chat}/tool-group/format.ts +0 -0
  142. /package/client/{components → features/chat}/tool-group/index.ts +0 -0
  143. /package/client/{lib → features/chat}/uploads.ts +0 -0
  144. /package/client/{hooks → features/chat}/useStickToBottom.ts +0 -0
  145. /package/client/{components → features/connectors}/IconMcp.tsx +0 -0
  146. /package/client/{lib → features/connectors}/mcp-icons.ts +0 -0
  147. /package/client/{lib → features/scratchpad}/scratch-executor.ts +0 -0
  148. /package/client/{lib → features/settings}/render-icon.ts +0 -0
  149. /package/client/{lib → features/workspace}/WorkspaceContext.tsx +0 -0
  150. /package/client/{hooks → features/workspace}/useWorkspaceTheme.ts +0 -0
@@ -0,0 +1,188 @@
1
+ import { type ReactNode, useCallback, useEffect, useMemo, useRef } from 'react'
2
+
3
+ import { IconChevronDown, IconX } from '@tabler/icons-react'
4
+
5
+ import { useScrollFade } from '@/client/hooks/useScrollFade'
6
+ import { useStickToBottom } from '@/client/features/chat/useStickToBottom'
7
+ import { cn } from '@/client/lib/cn'
8
+ import { groupTurns } from '@/client/features/chat/group-turns'
9
+ import type { Turn, ViewState } from '@/lib/types'
10
+
11
+ import { ChatComposer } from './ChatComposer'
12
+ import { ThreadSelector } from './ThreadSelector'
13
+ import { EmptyState, ThinkingIndicator, TurnView } from './TurnView'
14
+ import { Button } from '@/client/components/ui/button'
15
+
16
+ type ChatPanelProps = {
17
+ active?: boolean
18
+ focusRequest?: number
19
+ view: ViewState
20
+ // The live streaming preview as a synthetic assistant turn (or null). Merged
21
+ // into the transcript through the same groupTurns pipeline so a thinking-only
22
+ // preview folds into the current tool group. See client/lib/preview-turn.ts.
23
+ previewTurn?: Turn | null
24
+ // Active thread id — used only as the scroll reset key (jump to bottom on
25
+ // thread switch).
26
+ sessionId?: string | null
27
+ processing: boolean
28
+ error?: string | null
29
+ onDismissError?: () => void
30
+ send: (text: string) => void
31
+ stop: () => void
32
+ // Constrain the scrollable history and the composer to a centered max-width
33
+ // column (var --chat-max-container) while the header still spans full width.
34
+ // Always on for now; will be toggled per layout mode later.
35
+ contained?: boolean
36
+ onSwitchThread: (sessionId: string | null) => void
37
+ // Extra content for the header's left edge, rendered before the thread
38
+ // selector when the chat is the primary panel.
39
+ headerLeft?: ReactNode
40
+ // Extra controls for the header's right edge — the parent supplies whatever
41
+ // chrome belongs here in the current layout (e.g. the section reopen toggle
42
+ // plus MCP/settings menus when the chat is fullscreen).
43
+ headerRight?: ReactNode
44
+ // Floating popup: render a close (X) button that dismisses the popup.
45
+ onClose?: () => void
46
+ }
47
+
48
+ export function ChatPanel({
49
+ active = true,
50
+ focusRequest = 0,
51
+ view,
52
+ previewTurn,
53
+ sessionId,
54
+ processing,
55
+ error,
56
+ onDismissError,
57
+ send,
58
+ stop,
59
+ contained = true,
60
+ onSwitchThread,
61
+ headerLeft,
62
+ headerRight,
63
+ onClose
64
+ }: ChatPanelProps) {
65
+ const composerRef = useRef<HTMLTextAreaElement>(null)
66
+ const { ref: scrollRef, showTopFade, showBottomFade } = useScrollFade()
67
+ const turns = view.turns
68
+ // Visual grouping: fold consecutive tool-only assistant turns into one
69
+ // synthetic turn so OpenAI Codex–style traces (which serialize one
70
+ // assistant message per agent step) don't render with the wider
71
+ // inter-turn gap between every tool call. See `dev/turn-spacing.md`.
72
+ // The live preview turn is appended before grouping, so a thinking-only
73
+ // preview merges into the trailing tool group exactly like its finalized form.
74
+ const groupedTurns = useMemo(
75
+ () => groupTurns(previewTurn ? [...turns, previewTurn] : turns),
76
+ [turns, previewTurn]
77
+ )
78
+
79
+ // Stick to the bottom while pinned; respect scroll-up; jump on thread switch.
80
+ const { atBottom, scrollToBottom } = useStickToBottom(scrollRef, sessionId)
81
+
82
+ // The active chat surface owns initial focus. A monotonically increasing
83
+ // request also refocuses an already-visible composer after intent actions.
84
+ useEffect(() => {
85
+ if (active) composerRef.current?.focus()
86
+ }, [active, focusRequest])
87
+
88
+ // Sending always returns the user to the bottom, even if they'd scrolled up —
89
+ // they expect to see their message and the reply.
90
+ const handleSend = useCallback(
91
+ (text: string) => {
92
+ send(text)
93
+ scrollToBottom()
94
+ },
95
+ [send, scrollToBottom]
96
+ )
97
+
98
+ return (
99
+ <div className="flex min-h-0 flex-1 flex-col pt-2 pb-4">
100
+ <header className="flex items-center justify-between pr-2 pb-2 pl-2">
101
+ <div className="flex min-w-0 items-center gap-2.5">
102
+ {headerLeft}
103
+ <ThreadSelector onSwitch={onSwitchThread} />
104
+ </div>
105
+ <div className="flex items-center gap-0.5">
106
+ {headerRight}
107
+ {onClose && (
108
+ <Button variant="ghost" size="icon" onClick={onClose} aria-label="Close chat">
109
+ <IconX stroke={1.5} />
110
+ </Button>
111
+ )}
112
+ </div>
113
+ </header>
114
+
115
+ <div className="relative flex min-h-0 flex-1 flex-col">
116
+ <div
117
+ ref={scrollRef}
118
+ className={cn(
119
+ 'flex scrollbar-thin flex-1 flex-col overflow-y-auto overscroll-contain px-5 pt-4 pb-12',
120
+ showTopFade && showBottomFade && 'mask-fade-y',
121
+ showTopFade && !showBottomFade && 'mask-fade-top',
122
+ !showTopFade && showBottomFade && 'mask-fade-bottom'
123
+ )}
124
+ >
125
+ <div
126
+ className={cn(
127
+ 'flex flex-1 flex-col gap-6',
128
+ contained && 'mx-auto w-full max-w-[var(--chat-max-container)]'
129
+ )}
130
+ >
131
+ {turns.length === 0 && !processing && <EmptyState />}
132
+ {groupedTurns.map((turn, i) => (
133
+ <TurnView
134
+ key={turn.id}
135
+ turn={turn}
136
+ processing={processing && i === groupedTurns.length - 1}
137
+ />
138
+ ))}
139
+ {/* Pulsing dots only before the first token — once the preview has
140
+ visible content it renders as a (possibly merged) grouped turn. */}
141
+ {processing && !previewTurn && <ThinkingIndicator />}
142
+ </div>
143
+ </div>
144
+
145
+ {/* Jump to latest — shown only when scrolled up, so following the tail
146
+ never yanks the user while they read history. */}
147
+ {!atBottom && turns.length > 0 && (
148
+ <Button
149
+ type="button"
150
+ variant="outline"
151
+ size="icon"
152
+ onClick={() => scrollToBottom('smooth')}
153
+ aria-label="Jump to latest"
154
+ className="absolute bottom-3 left-1/2 -translate-x-1/2 animate-in rounded-full fade-in slide-in-from-bottom-1"
155
+ >
156
+ <IconChevronDown stroke={1.5} />
157
+ </Button>
158
+ )}
159
+ </div>
160
+
161
+ <div className={cn(contained && 'mx-auto w-full max-w-[var(--chat-max-container)] px-3')}>
162
+ {error && (
163
+ <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">
164
+ <span className="flex-1 break-words">{error}</span>
165
+ {onDismissError && (
166
+ <Button
167
+ type="button"
168
+ variant="ghost"
169
+ size="icon-sm"
170
+ onClick={onDismissError}
171
+ className="-m-1"
172
+ aria-label="Dismiss error"
173
+ >
174
+ <IconX stroke={1.75} />
175
+ </Button>
176
+ )}
177
+ </div>
178
+ )}
179
+ <ChatComposer
180
+ composerRef={composerRef}
181
+ onSend={handleSend}
182
+ onStop={stop}
183
+ processing={processing}
184
+ />
185
+ </div>
186
+ </div>
187
+ )
188
+ }
@@ -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
5
  import { IconRobotFace } 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="bg-card text-card-foreground hover:bg-card"
50
+ aria-label="Agent"
51
+ >
52
+ <IconRobotFace stroke={1.5} />
42
53
  </Button>
43
54
  </motion.div>
44
55
  </div>
@@ -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>
@@ -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,7 +13,7 @@ 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
18
  type ThreadSelectorProps = {
19
19
  onSwitch: (sessionId: string | null) => void
@@ -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,7 +63,7 @@ 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} />
66
+ <IconPlus size={16} stroke={1.75} />
67
67
  New thread
68
68
  </DropdownMenuItem>
69
69
  {sessions.length > 0 && (
@@ -71,7 +71,9 @@ export function ThreadSelector({ onSwitch }: ThreadSelectorProps) {
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>
@@ -1,14 +1,21 @@
1
1
  import { memo } from 'react'
2
2
 
3
- import { IconFile } from '@tabler/icons-react'
3
+ import { IconFile, IconRobotFace } 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-3 text-center">
13
+ <div className="flex size-12 items-center justify-center rounded-xl border border-border bg-muted/40 text-muted-foreground">
14
+ <IconRobotFace size={24} stroke={1.5} />
15
+ </div>
16
+ <p className="text-lg font-medium text-foreground">What do you want to build?</p>
17
+ </div>
18
+ )
12
19
  }
13
20
 
14
21
  export function ThinkingIndicator() {
@@ -118,7 +125,7 @@ export const TurnView = memo(function TurnView({ turn, processing = false }: Tur
118
125
  <FilePart key={i} mediaType={p.mediaType} url={p.url} filename={p.filename} />
119
126
  ))}
120
127
  {text && (
121
- <p className="rounded-md bg-black/[0.07] px-4 py-2 text-sm leading-normal whitespace-pre-wrap">
128
+ <p className="rounded-md bg-accent px-4 py-2 text-sm leading-normal whitespace-pre-wrap text-accent-foreground">
122
129
  {text}
123
130
  </p>
124
131
  )}
@@ -164,13 +171,13 @@ function FilePart({ mediaType, url, filename }: FilePartProps) {
164
171
  <img
165
172
  src={url}
166
173
  alt={filename ?? 'attachment'}
167
- className="max-h-64 max-w-full rounded-md border border-black/10 object-contain"
174
+ className="max-h-64 max-w-full rounded-md border border-border object-contain"
168
175
  />
169
176
  )
170
177
  }
171
178
  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} />
179
+ <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">
180
+ <IconFile size={16} stroke={1.75} />
174
181
  <span className="truncate">{filename ?? mediaType}</span>
175
182
  </div>
176
183
  )
@@ -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 thread config'
70
+ ),
71
+ onSuccess: (next, { sessionId }) => {
72
+ queryClient.setQueryData<ThreadConfig>(
73
+ workspaceKeys.threadConfig(workspaceId, sessionId),
74
+ next
75
+ )
76
+ }
77
+ })
78
+ }