moi-computer 0.5.2-next.0 → 0.6.0

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 (89) hide show
  1. package/client/AGENTS.md +9 -0
  2. package/client/api/app-ui-keys.ts +4 -0
  3. package/client/api/workspace-keys.ts +2 -2
  4. package/client/app/routes/WorkspaceRoute.tsx +8 -28
  5. package/client/app/shell/SidebarLayout.tsx +1 -1
  6. package/client/components/shared/Composer.tsx +15 -9
  7. package/client/components/shared/IconGhost.tsx +130 -0
  8. package/client/components/ui/dropdown-menu.tsx +2 -5
  9. package/client/components/ui/popover.tsx +11 -4
  10. package/client/components/ui/slider.tsx +70 -0
  11. package/client/components/ui/spinner.tsx +18 -0
  12. package/client/components/ui/toast.tsx +220 -0
  13. package/client/components/ui/tooltip.tsx +1 -1
  14. package/client/features/chat/ChatComposer.tsx +11 -14
  15. package/client/features/chat/ChatPanel.tsx +15 -14
  16. package/client/features/chat/ChatPopup.tsx +10 -4
  17. package/client/features/chat/ChatSelector.tsx +263 -48
  18. package/client/features/chat/ModelPicker.tsx +295 -121
  19. package/client/features/chat/TurnView.tsx +1 -1
  20. package/client/features/chat/api.ts +36 -9
  21. package/client/features/chat/chat-frames.ts +35 -6
  22. package/client/features/chat/chat-send.ts +40 -6
  23. package/client/features/chat/chat-store.ts +52 -40
  24. package/client/features/chat/model-order.ts +50 -28
  25. package/client/features/chat/useChat.ts +71 -60
  26. package/client/features/chat/useSelectedSession.ts +151 -0
  27. package/client/features/chat/useStickToBottom.ts +3 -3
  28. package/client/features/home/api.ts +0 -2
  29. package/client/features/scratchpad/ScratchpadControls.tsx +2 -2
  30. package/client/features/settings/IconPicker.tsx +2 -2
  31. package/client/features/settings/WorkspaceSettings.tsx +6 -6
  32. package/client/features/views/ViewBuilderTab.tsx +3 -4
  33. package/client/features/views/api.ts +1 -0
  34. package/client/features/views/useViewBuilderActions.ts +7 -3
  35. package/client/features/workspace/WorkspaceScreen.tsx +40 -19
  36. package/client/features/workspace/WorkspaceSkillUpdateBanner.tsx +2 -2
  37. package/client/features/workspace/WorkspaceTabs.tsx +10 -1
  38. package/client/index.css +5 -3
  39. package/client/main.tsx +2 -0
  40. package/client/runtime/useWorkspaceEvents.ts +1 -0
  41. package/client/store/ui.ts +13 -3
  42. package/dist/{chunk-m9qja0nx.js → chunk-0pcdwjkp.js} +1 -1
  43. package/dist/chunk-55sh4dty.js +2 -0
  44. package/dist/{chunk-h3evrtyp.js → chunk-9y2zbzqz.js} +1 -1
  45. package/dist/{chunk-7bzpmtxp.js → chunk-afgbg75t.js} +1 -1
  46. package/dist/chunk-agtetn7n.css +1 -0
  47. package/dist/chunk-bv6vrvqf.js +27 -0
  48. package/dist/chunk-dfs36zgc.js +1 -0
  49. package/dist/chunk-exj6hr30.js +9 -0
  50. package/dist/{chunk-v797g6ap.js → chunk-m11ckkxd.js} +1 -1
  51. package/dist/chunk-n6t40enm.js +1 -0
  52. package/dist/{chunk-jg6ezptn.js → chunk-rxvx4ta9.js} +3 -3
  53. package/dist/index.html +1 -1
  54. package/lib/attachment-note.ts +18 -0
  55. package/lib/chat-title.ts +6 -0
  56. package/lib/types.ts +33 -10
  57. package/package.json +1 -1
  58. package/server/api.ts +100 -10
  59. package/server/app-settings.ts +1 -1
  60. package/server/data-dir.ts +1 -1
  61. package/server/harness/README.md +6 -0
  62. package/server/harness/claude-code/adapter.ts +2 -2
  63. package/server/harness/claude-code/index.ts +7 -1
  64. package/server/harness/claude-code/models.ts +25 -2
  65. package/server/harness/claude-code/session-title.ts +106 -0
  66. package/server/harness/claude-code/session.ts +114 -17
  67. package/server/harness/claude-code/sessions.ts +35 -4
  68. package/server/harness/codex/adapter.ts +27 -2
  69. package/server/harness/codex/client.ts +56 -9
  70. package/server/harness/codex/index.ts +2 -0
  71. package/server/harness/codex/session-title.ts +149 -0
  72. package/server/harness/codex/session.ts +96 -14
  73. package/server/harness/openclaw/adapter.ts +4 -2
  74. package/server/harness/openclaw/discovery.ts +2 -0
  75. package/server/harness/openclaw/session.ts +15 -7
  76. package/server/harness/session-title.ts +96 -0
  77. package/server/harness/types.ts +5 -2
  78. package/server/selected-session.ts +132 -0
  79. package/server/session-config.ts +146 -0
  80. package/server/web.ts +15 -1
  81. package/workspace/.claude/skills/moi-workspace/DESIGN.md +54 -68
  82. package/workspace/.claude/skills/moi-workspace/SKILL.md +8 -2
  83. package/dist/chunk-5vaevt8z.js +0 -2
  84. package/dist/chunk-fhhv99bd.js +0 -1
  85. package/dist/chunk-h0hk61pm.js +0 -9
  86. package/dist/chunk-k5sjx9s5.js +0 -1
  87. package/dist/chunk-rs9nb0fr.js +0 -27
  88. package/dist/chunk-s7za1qsv.css +0 -1
  89. package/server/thread-config.ts +0 -124
@@ -1,16 +1,17 @@
1
- import { memo, useState } from 'react'
1
+ import { type ComponentProps, type ReactNode, memo, useState } from 'react'
2
2
 
3
- import { IconChevronDown } from '@tabler/icons-react'
3
+ import { AnimatePresence, motion } from 'motion/react'
4
4
 
5
- import { useSaveThreadConfig, useThreadConfig, useWorkspaceModels } from './api'
5
+ import { IconBolt, IconBoltFilled } from '@tabler/icons-react'
6
+
7
+ import { useSaveSessionConfig, useSessionConfig, useWorkspaceModels } from './api'
6
8
  import {
9
+ hasEffortChoice,
7
10
  resolveDisplayedEffort,
8
- reverseEffortLevels,
11
+ resolveEffortIndex,
12
+ resolveFastMode,
9
13
  sortModelsByProviderOrder
10
14
  } from './model-order'
11
- import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
12
- import { useLive } from '@/client/features/chat/chat-store'
13
-
14
15
  import { Button } from '@/client/components/ui/button'
15
16
  import {
16
17
  DropdownMenu,
@@ -19,13 +20,20 @@ import {
19
20
  DropdownMenuLabel,
20
21
  DropdownMenuRadioGroup,
21
22
  DropdownMenuRadioItem,
22
- DropdownMenuSeparator,
23
- DropdownMenuSub,
24
- DropdownMenuSubContent,
25
- DropdownMenuSubTrigger,
26
23
  DropdownMenuTrigger
27
24
  } from '@/client/components/ui/dropdown-menu'
28
- import { Switch } from '@/client/components/ui/switch'
25
+ import {
26
+ Popover,
27
+ PopoverContent,
28
+ PopoverHeader,
29
+ PopoverTrigger
30
+ } from '@/client/components/ui/popover'
31
+ import { Slider } from '@/client/components/ui/slider'
32
+ import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
33
+ import { useSelectedSession } from '@/client/features/chat/useSelectedSession'
34
+ import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
35
+ import { cn } from '@/client/lib/cn'
36
+ import type { Model } from '@/lib/types'
29
37
 
30
38
  // Models describe themselves with a " · "-joined blurb; we show only the
31
39
  // headline (e.g. "Opus 4.8 with 1M context · Most capable…" → "Opus 4.8 with 1M context").
@@ -43,30 +51,240 @@ function effortLabel(level: string): string {
43
51
  return level === 'xhigh' ? 'Extra' : capitalize(level)
44
52
  }
45
53
 
54
+ function singleSliderValue(value: number | readonly number[]): number {
55
+ return typeof value === 'number' ? value : (value[0] ?? 0)
56
+ }
57
+
58
+ const effortHeaderVariants = {
59
+ from: { opacity: 0, filter: 'blur(4px)' },
60
+ to: { opacity: 1, filter: 'blur(0px)' }
61
+ }
62
+
63
+ const effortHeaderTransition = { type: 'spring', duration: 0.3, delay: 0.1, bounce: 0 } as const
64
+
65
+ type PickerTriggerProps = Omit<ComponentProps<typeof Button>, 'children' | 'variant'> & {
66
+ label: string
67
+ leadingIcon?: ReactNode
68
+ }
69
+
70
+ function PickerTrigger({ label, leadingIcon, className, ...props }: PickerTriggerProps) {
71
+ return (
72
+ <Button
73
+ {...props}
74
+ variant="ghost"
75
+ className={cn(
76
+ 'group/picker max-w-56 min-w-0 px-2 text-muted-foreground hover:text-muted-foreground',
77
+ className
78
+ )}
79
+ >
80
+ {leadingIcon}
81
+ <span className="truncate font-normal">{label}</span>
82
+ </Button>
83
+ )
84
+ }
85
+
86
+ type ModelDropdownProps = {
87
+ current: string
88
+ model: Model
89
+ models: readonly Model[]
90
+ onValueChange: (value: string) => void
91
+ }
92
+
93
+ function ModelDropdown({ current, model, models, onValueChange }: ModelDropdownProps) {
94
+ const label = headline(model.description) || model.displayName
95
+
96
+ return (
97
+ <DropdownMenu>
98
+ <DropdownMenuTrigger
99
+ render={<PickerTrigger label={label} aria-label={`Model: ${label}`} />}
100
+ />
101
+ <DropdownMenuContent align="end" side="top" className="w-max max-w-64 min-w-40">
102
+ <DropdownMenuGroup>
103
+ <DropdownMenuLabel>Models</DropdownMenuLabel>
104
+ <DropdownMenuRadioGroup value={current} onValueChange={onValueChange}>
105
+ {models.map(item => (
106
+ <DropdownMenuRadioItem key={item.value} value={item.value} closeOnClick>
107
+ {headline(item.description) || item.displayName}
108
+ </DropdownMenuRadioItem>
109
+ ))}
110
+ </DropdownMenuRadioGroup>
111
+ </DropdownMenuGroup>
112
+ </DropdownMenuContent>
113
+ </DropdownMenu>
114
+ )
115
+ }
116
+
117
+ type EffortPickerProps = {
118
+ currentEffort: string
119
+ effortLevels: readonly string[]
120
+ fastMode: boolean
121
+ showFastMode: boolean
122
+ onFastModeChange: (value: boolean) => void
123
+ onValueChange: (value: string) => void
124
+ }
125
+
126
+ function EffortPicker({
127
+ currentEffort,
128
+ effortLevels,
129
+ fastMode,
130
+ showFastMode,
131
+ onFastModeChange,
132
+ onValueChange
133
+ }: EffortPickerProps) {
134
+ const currentIndex = resolveEffortIndex(effortLevels, currentEffort)
135
+ const [open, setOpen] = useState(false)
136
+ const [draftIndex, setDraftIndex] = useState(currentIndex)
137
+ const [dragging, setDragging] = useState(false)
138
+ const displayedIndex = open ? draftIndex : currentIndex
139
+ const displayedEffort = effortLevels[displayedIndex] ?? currentEffort
140
+ const displayedLabel = effortLabel(displayedEffort)
141
+
142
+ const handleOpenChange = (nextOpen: boolean) => {
143
+ if (nextOpen) setDraftIndex(currentIndex)
144
+ else setDragging(false)
145
+ setOpen(nextOpen)
146
+ }
147
+
148
+ const commitEffort = (index: number) => {
149
+ const nextEffort = effortLevels[index]
150
+ if (nextEffort && nextEffort !== currentEffort) onValueChange(nextEffort)
151
+ }
152
+
153
+ return (
154
+ <Popover open={open} onOpenChange={handleOpenChange}>
155
+ <PopoverTrigger
156
+ render={
157
+ <PickerTrigger
158
+ label={displayedLabel}
159
+ leadingIcon={fastMode ? <IconBolt stroke={1.5} /> : undefined}
160
+ aria-label={`Effort: ${displayedLabel}`}
161
+ />
162
+ }
163
+ />
164
+ <PopoverContent align="end" side="top" className="w-64" disableAnchorTracking>
165
+ <PopoverHeader className="relative h-5 flex-row items-center">
166
+ <AnimatePresence mode="popLayout" initial={false}>
167
+ {dragging ? (
168
+ <motion.div
169
+ key="range"
170
+ className="flex h-5 w-full items-center justify-between text-sm text-muted-foreground"
171
+ aria-hidden="true"
172
+ variants={effortHeaderVariants}
173
+ initial="from"
174
+ animate="to"
175
+ exit="from"
176
+ transition={effortHeaderTransition}
177
+ >
178
+ <span>Faster</span>
179
+ <span>Smarter</span>
180
+ </motion.div>
181
+ ) : (
182
+ <motion.div
183
+ key="effort"
184
+ className="flex h-5 w-full items-center justify-between gap-2"
185
+ variants={effortHeaderVariants}
186
+ initial="from"
187
+ animate="to"
188
+ exit="from"
189
+ transition={effortHeaderTransition}
190
+ >
191
+ <div className="flex items-center gap-1">
192
+ <span className="text-muted-foreground">Effort</span>
193
+ <output aria-live="polite">{displayedLabel}</output>
194
+ </div>
195
+ {showFastMode && (
196
+ <Tooltip>
197
+ <TooltipTrigger
198
+ render={
199
+ <Button
200
+ type="button"
201
+ variant="ghost"
202
+ size="icon-sm"
203
+ aria-label={fastMode ? 'Turn off Fast mode' : 'Turn on Fast mode'}
204
+ aria-pressed={fastMode}
205
+ onClick={() => onFastModeChange(!fastMode)}
206
+ className="-my-1 -mr-1"
207
+ >
208
+ {fastMode ? (
209
+ <IconBoltFilled className="text-primary" />
210
+ ) : (
211
+ <IconBolt className="text-muted-foreground" stroke={1.5} />
212
+ )}
213
+ </Button>
214
+ }
215
+ />
216
+ <TooltipContent align="center" className="flex-col gap-0">
217
+ <span>Fast mode</span>
218
+ <span className="font-normal text-muted-foreground">More usage</span>
219
+ </TooltipContent>
220
+ </Tooltip>
221
+ )}
222
+ </motion.div>
223
+ )}
224
+ </AnimatePresence>
225
+ </PopoverHeader>
226
+ <label className="block">
227
+ <span className="sr-only">Reasoning effort</span>
228
+ <Slider
229
+ value={draftIndex}
230
+ min={0}
231
+ max={effortLevels.length - 1}
232
+ step={1}
233
+ onPointerDown={event => {
234
+ if (event.button === 0) setDragging(true)
235
+ }}
236
+ onPointerCancel={() => setDragging(false)}
237
+ onValueChange={value => setDraftIndex(singleSliderValue(value))}
238
+ onValueCommitted={value => {
239
+ setDragging(false)
240
+ commitEffort(singleSliderValue(value))
241
+ }}
242
+ className={cn(
243
+ '**:data-[slot=slider-track]:h-6 **:data-[slot=slider-track]:rounded-sm',
244
+ '**:data-[slot=slider-thumb]:h-6 **:data-[slot=slider-thumb]:w-5 **:data-[slot=slider-thumb]:rounded-sm **:data-[slot=slider-thumb]:border-0 **:data-[slot=slider-thumb]:bg-card **:data-[slot=slider-thumb]:shadow-xs **:data-[slot=slider-thumb]:ring-0'
245
+ )}
246
+ >
247
+ <span
248
+ data-slot="slider-marks"
249
+ aria-hidden="true"
250
+ className="absolute inset-x-2 flex items-center justify-between"
251
+ >
252
+ {Array.from({ length: effortLevels.length }, (_, index) => (
253
+ <span
254
+ key={index}
255
+ className={cn(
256
+ 'size-1 rounded-full',
257
+ index <= draftIndex ? 'bg-primary-foreground/30' : 'bg-foreground/30'
258
+ )}
259
+ />
260
+ ))}
261
+ </span>
262
+ </Slider>
263
+ </label>
264
+ </PopoverContent>
265
+ </Popover>
266
+ )
267
+ }
268
+
46
269
  type ModelPickerProps = {
47
270
  scope?: 'active-chat' | 'workspace'
48
271
  }
49
272
 
50
- // Model selector for the chat composer. Renders the workspace's available
51
- // models from `/api/workspaces/:id/models`. Model + reasoning effort are
52
- // persisted PER THREAD (so a thread reopens with the settings it last ran with)
53
- // once a thread exists; while no thread is open (a brand-new chat) the picker
54
- // edits the workspace defaults, which seed the new thread. Both are sent with
55
- // each chat frame (see useChat); leaving them untouched runs on the SDK default.
56
- // Fast mode remains local-only for now.
57
- // The workspace scope gives new-chat surfaces such as the view builder the same
58
- // defaults that their submit path reads. The active-chat scope persists per
59
- // thread once one exists.
60
- // Memoized because composer text changes should not re-render the picker.
273
+ // Model selector for composer surfaces. The workspace's available models come
274
+ // from `/api/workspaces/:id/models`; effort options follow the selected model.
275
+ // Model, effort, and Fast mode persist per chat once one exists. A new chat
276
+ // edits the workspace defaults that seed it. All values are sent with each chat
277
+ // frame. The workspace scope gives new-chat surfaces such as the view builder
278
+ // the same defaults that their submit path reads.
61
279
  export const ModelPicker = memo(function ModelPicker({ scope = 'active-chat' }: ModelPickerProps) {
62
280
  const { workspaceId, layout, setLayout } = useWorkspaceLayoutCtx()
281
+ const [selectedSessionId] = useSelectedSession()
63
282
  const { data } = useWorkspaceModels(workspaceId)
283
+
64
284
  // The SDK prepends a synthetic "default" entry ("Use the default model
65
- // (currently …)"). Drop it and surface the concrete model it resolves to
66
- // instead, so the picker shows e.g. "Opus (1M context)" rather than the meta
67
- // "use default" row.
285
+ // (currently …)"). Drop it and name the concrete model it resolves to.
68
286
  const allModels = data?.models ?? []
69
- const defaultEntry = allModels.find(m => m.value === 'default')
287
+ const defaultEntry = allModels.find(model => model.value === 'default')
70
288
  const models = data
71
289
  ? sortModelsByProviderOrder(
72
290
  allModels.filter(model => model.value !== 'default'),
@@ -74,113 +292,69 @@ export const ModelPicker = memo(function ModelPicker({ scope = 'active-chat' }:
74
292
  )
75
293
  : []
76
294
 
77
- // The active thread, if any. Its stored config is the source of truth; a new
78
- // chat (no active thread) falls back to — and edits — the workspace defaults.
79
- const activeSessionId = useLive(s =>
80
- scope === 'active-chat' ? (s.activeByWorkspace[workspaceId] ?? null) : null
81
- )
82
- const threadCfg = useThreadConfig(workspaceId, activeSessionId).data
83
- const saveThreadCfg = useSaveThreadConfig(workspaceId)
84
- const [fastMode, setFastMode] = useState(false)
85
-
86
- const selected = (activeSessionId ? threadCfg?.model : undefined) ?? layout.selectedModel
87
- const selectedEffort = (activeSessionId ? threadCfg?.effort : undefined) ?? layout.selectedEffort
88
- const setSelected = (value: string) => {
89
- if (activeSessionId)
90
- saveThreadCfg.mutate({ sessionId: activeSessionId, patch: { model: value } })
295
+ // The selected chat's stored config is the source of truth. With New chat,
296
+ // the picker reads and edits workspace defaults.
297
+ const sessionId = scope === 'active-chat' ? (selectedSessionId ?? null) : null
298
+ const sessionConfig = useSessionConfig(workspaceId, sessionId).data
299
+ const saveSessionConfig = useSaveSessionConfig(workspaceId)
300
+
301
+ const selectedModel = (sessionId ? sessionConfig?.model : undefined) ?? layout.selectedModel
302
+ const selectedEffort = (sessionId ? sessionConfig?.effort : undefined) ?? layout.selectedEffort
303
+ const selectedFastMode =
304
+ (sessionId ? sessionConfig?.fastMode : undefined) ?? layout.selectedFastMode
305
+
306
+ const setSelectedModel = (value: string) => {
307
+ if (sessionId) saveSessionConfig.mutate({ sessionId, patch: { model: value } })
91
308
  else setLayout({ selectedModel: value })
92
309
  }
93
- const setEffort = (value: string) => {
94
- if (activeSessionId)
95
- saveThreadCfg.mutate({ sessionId: activeSessionId, patch: { effort: value } })
310
+
311
+ const setSelectedEffort = (value: string) => {
312
+ if (sessionId) saveSessionConfig.mutate({ sessionId, patch: { effort: value } })
96
313
  else setLayout({ selectedEffort: value })
97
314
  }
98
315
 
316
+ const setSelectedFastMode = (value: boolean) => {
317
+ if (sessionId) saveSessionConfig.mutate({ sessionId, patch: { fastMode: value } })
318
+ else setLayout({ selectedFastMode: value })
319
+ }
320
+
99
321
  if (models.length === 0) return null
100
322
 
101
- // Show the persisted pick when it's still in the list; otherwise fall back to
102
- // the concrete model the SDK default resolves to (matched by resolvedModel),
103
- // or the first model. An unset pick sends no model id, so the run still uses
104
- // the SDK default — the display just names it instead of showing "default".
105
- const persisted = models.some(m => m.value === selected) ? selected : undefined
323
+ // Show a persisted pick when it still exists. Otherwise name the concrete
324
+ // model behind the SDK default, or fall back to the first available model.
325
+ const persistedModel = models.some(model => model.value === selectedModel)
326
+ ? selectedModel
327
+ : undefined
106
328
  const defaultModel =
107
329
  models.find(
108
- m => defaultEntry?.resolvedModel && m.resolvedModel === defaultEntry.resolvedModel
330
+ model => defaultEntry?.resolvedModel && model.resolvedModel === defaultEntry.resolvedModel
109
331
  ) ?? models[0]
110
- const current = persisted ?? defaultModel.value
111
- const model = models.find(m => m.value === current) ?? models[0]
112
- const effortLevels = reverseEffortLevels(
113
- model.supportsEffort ? (model.supportedEffortLevels ?? []) : []
114
- )
332
+ const currentModelValue = persistedModel ?? defaultModel.value
333
+ const model = models.find(item => item.value === currentModelValue) ?? models[0]
334
+ const effortLevels = model.supportsEffort ? (model.supportedEffortLevels ?? []) : []
115
335
  const currentEffort = resolveDisplayedEffort(effortLevels, selectedEffort)
116
- const showReasoning = effortLevels.length > 0
117
- // Fast mode is Claude-only (Opus); OpenClaw models never report supportsFastMode.
118
- const showFastMode = !!model.supportsFastMode
336
+ const showEffort = hasEffortChoice(effortLevels) && currentEffort !== undefined
337
+ const fastMode = resolveFastMode(model, selectedFastMode)
119
338
 
120
339
  return (
121
- <DropdownMenu>
122
- <DropdownMenuTrigger
123
- render={
124
- <Button variant="ghost">
125
- <span className="font-normal text-foreground">
126
- {headline(model.description) || model.displayName}
127
- </span>
128
- {currentEffort && (
129
- <span className="font-normal text-muted-foreground">
130
- {effortLabel(currentEffort)}
131
- </span>
132
- )}
133
- <IconChevronDown stroke={1.5} className="text-muted-foreground" />
134
- </Button>
135
- }
340
+ <div className="flex shrink-0 items-center gap-1">
341
+ <ModelDropdown
342
+ current={currentModelValue}
343
+ model={model}
344
+ models={models}
345
+ onValueChange={setSelectedModel}
136
346
  />
137
- <DropdownMenuContent align="start" side="top" className="min-w-56">
138
- <DropdownMenuGroup>
139
- <DropdownMenuLabel>Models</DropdownMenuLabel>
140
- <DropdownMenuRadioGroup value={current} onValueChange={setSelected}>
141
- {models.map(m => (
142
- <DropdownMenuRadioItem key={m.value} value={m.value} closeOnClick>
143
- {headline(m.description) || m.displayName}
144
- </DropdownMenuRadioItem>
145
- ))}
146
- </DropdownMenuRadioGroup>
147
- </DropdownMenuGroup>
148
-
149
- {(showReasoning || showFastMode) && <DropdownMenuSeparator />}
150
-
151
- {showReasoning && (
152
- <DropdownMenuSub>
153
- <DropdownMenuSubTrigger>
154
- <div className="flex flex-1 items-center justify-between">
155
- Reasoning
156
- {currentEffort && (
157
- <span className="ml-auto text-muted-foreground">
158
- {effortLabel(currentEffort)}
159
- </span>
160
- )}
161
- </div>
162
- </DropdownMenuSubTrigger>
163
- <DropdownMenuSubContent>
164
- <DropdownMenuRadioGroup value={currentEffort} onValueChange={setEffort}>
165
- {effortLevels.map(level => (
166
- <DropdownMenuRadioItem key={level} value={level} closeOnClick>
167
- {effortLabel(level)}
168
- </DropdownMenuRadioItem>
169
- ))}
170
- </DropdownMenuRadioGroup>
171
- </DropdownMenuSubContent>
172
- </DropdownMenuSub>
173
- )}
174
-
175
- {showFastMode && (
176
- <DropdownMenuGroup className="mt-0.5">
177
- <label className="flex cursor-pointer items-center justify-between gap-4 rounded-md px-2 py-1 text-sm">
178
- Fast mode
179
- <Switch checked={fastMode} onCheckedChange={setFastMode} />
180
- </label>
181
- </DropdownMenuGroup>
182
- )}
183
- </DropdownMenuContent>
184
- </DropdownMenu>
347
+ {showEffort && (
348
+ <EffortPicker
349
+ key={model.value}
350
+ currentEffort={currentEffort}
351
+ effortLevels={effortLevels}
352
+ fastMode={fastMode}
353
+ showFastMode={model.supportsFastMode === true}
354
+ onFastModeChange={setSelectedFastMode}
355
+ onValueChange={setSelectedEffort}
356
+ />
357
+ )}
358
+ </div>
185
359
  )
186
360
  })
@@ -113,7 +113,7 @@ export const TurnView = memo(function TurnView({ turn, processing = false }: Tur
113
113
  <FilePart key={i} mediaType={p.mediaType} url={p.url} filename={p.filename} />
114
114
  ))}
115
115
  {text && (
116
- <p className="max-w-full min-w-0 rounded-lg bg-accent px-4 py-2 text-sm leading-normal wrap-anywhere whitespace-pre-wrap text-accent-foreground">
116
+ <p className="max-w-full min-w-0 rounded-lg bg-accent px-3 py-2 text-sm leading-normal wrap-anywhere whitespace-pre-wrap text-accent-foreground">
117
117
  {text}
118
118
  </p>
119
119
  )}
@@ -1,13 +1,13 @@
1
1
  import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
2
2
 
3
- import { jsonRequest, requestJson } from '@/client/api/http'
3
+ import { jsonRequest, requestJson, requestVoid } from '@/client/api/http'
4
4
  import { WORKSPACE_RESOURCE_OPTIONS } from '@/client/api/query-options'
5
5
  import { workspaceKeys } from '@/client/api/workspace-keys'
6
6
  import { applyEvents } from '@/lib/format'
7
7
  import type {
8
+ SessionConfig,
8
9
  SessionInfo,
9
10
  StreamEvent,
10
- ThreadConfig,
11
11
  ViewState,
12
12
  WorkspaceModels
13
13
  } from '@/lib/types'
@@ -20,6 +20,33 @@ export function useWorkspaceSessions(workspaceId: string) {
20
20
  })
21
21
  }
22
22
 
23
+ export function removeArchivedSession(
24
+ sessions: SessionInfo[] | undefined,
25
+ sessionId: string
26
+ ): SessionInfo[] | undefined {
27
+ return sessions?.filter(session => session.sessionId !== sessionId)
28
+ }
29
+
30
+ export function useArchiveWorkspaceSession(workspaceId: string) {
31
+ const queryClient = useQueryClient()
32
+ return useMutation<void, Error, string>({
33
+ mutationFn: sessionId =>
34
+ requestVoid(
35
+ `/api/workspaces/${workspaceId}/sessions/${sessionId}/archive`,
36
+ { method: 'POST' },
37
+ 'Couldn’t archive chat'
38
+ ),
39
+ onSuccess: (_, sessionId) => {
40
+ queryClient.setQueryData<SessionInfo[]>(workspaceKeys.sessions(workspaceId), current =>
41
+ removeArchivedSession(current, sessionId)
42
+ )
43
+ queryClient.removeQueries({ queryKey: workspaceKeys.events(workspaceId, sessionId) })
44
+ queryClient.removeQueries({ queryKey: workspaceKeys.sessionConfig(workspaceId, sessionId) })
45
+ queryClient.invalidateQueries({ queryKey: workspaceKeys.preview(workspaceId) })
46
+ }
47
+ })
48
+ }
49
+
23
50
  export function useSessionView(workspaceId: string, sessionId: string | null) {
24
51
  return useQuery<ViewState>({
25
52
  queryKey: workspaceKeys.events(workspaceId, sessionId ?? ''),
@@ -47,9 +74,9 @@ export function useWorkspaceModels(workspaceId: string) {
47
74
  })
48
75
  }
49
76
 
50
- export function useThreadConfig(workspaceId: string, sessionId: string | null) {
51
- return useQuery<ThreadConfig>({
52
- queryKey: workspaceKeys.threadConfig(workspaceId, sessionId ?? ''),
77
+ export function useSessionConfig(workspaceId: string, sessionId: string | null) {
78
+ return useQuery<SessionConfig>({
79
+ queryKey: workspaceKeys.sessionConfig(workspaceId, sessionId ?? ''),
53
80
  queryFn: () => requestJson(`/api/workspaces/${workspaceId}/sessions/${sessionId}/config`),
54
81
  enabled: Boolean(sessionId),
55
82
  staleTime: Infinity,
@@ -59,9 +86,9 @@ export function useThreadConfig(workspaceId: string, sessionId: string | null) {
59
86
  })
60
87
  }
61
88
 
62
- export function useSaveThreadConfig(workspaceId: string) {
89
+ export function useSaveSessionConfig(workspaceId: string) {
63
90
  const queryClient = useQueryClient()
64
- return useMutation<ThreadConfig, Error, { sessionId: string; patch: ThreadConfig }>({
91
+ return useMutation<SessionConfig, Error, { sessionId: string; patch: SessionConfig }>({
65
92
  mutationFn: ({ patch, sessionId }) =>
66
93
  requestJson(
67
94
  `/api/workspaces/${workspaceId}/sessions/${sessionId}/config`,
@@ -69,8 +96,8 @@ export function useSaveThreadConfig(workspaceId: string) {
69
96
  'Failed to save chat settings'
70
97
  ),
71
98
  onSuccess: (next, { sessionId }) => {
72
- queryClient.setQueryData<ThreadConfig>(
73
- workspaceKeys.threadConfig(workspaceId, sessionId),
99
+ queryClient.setQueryData<SessionConfig>(
100
+ workspaceKeys.sessionConfig(workspaceId, sessionId),
74
101
  next
75
102
  )
76
103
  }
@@ -3,14 +3,16 @@ import type { QueryClient } from '@tanstack/react-query'
3
3
  import { workspaceKeys } from '@/client/api/workspace-keys'
4
4
  import { getScratchExecutor } from '@/client/features/scratchpad/scratch-executor'
5
5
  import { liveStore } from '@/client/features/chat/chat-store'
6
+ import { renameSelectedSessionInCache } from '@/client/features/chat/useSelectedSession'
6
7
  import { applyEvent } from '@/lib/format'
7
8
  import type {
8
9
  ClientMessage,
9
10
  PreviewFrame,
10
11
  ScratchOp,
11
12
  SessionActivity,
13
+ SessionConfig,
14
+ SessionInfo,
12
15
  StreamEvent,
13
- ThreadConfig,
14
16
  ViewState
15
17
  } from '@/lib/types'
16
18
 
@@ -57,7 +59,25 @@ export function reduceChatFrame(data: Record<string, unknown>, context: ChatFram
57
59
  const workspaceId = data.workspaceId as string
58
60
  const from = data.from as string
59
61
  const to = data.to as string
62
+ const sessionsKey = workspaceKeys.sessions(workspaceId)
63
+ const cachedSessions = queryClient?.getQueryData<SessionInfo[]>(sessionsKey)
64
+ const cachedSession = cachedSessions?.find(
65
+ session => session.sessionId === from || session.sessionId === to
66
+ )
67
+ if (cachedSession) {
68
+ void queryClient?.cancelQueries({ queryKey: sessionsKey })
69
+ }
60
70
  store.renameSession(workspaceId, from, to)
71
+ if (queryClient) renameSelectedSessionInCache(queryClient, workspaceId, from, to)
72
+ if (cachedSession) {
73
+ queryClient?.setQueryData<SessionInfo[]>(sessionsKey, current => [
74
+ {
75
+ ...cachedSession,
76
+ sessionId: to
77
+ },
78
+ ...(current ?? []).filter(session => session.sessionId !== from && session.sessionId !== to)
79
+ ])
80
+ }
61
81
 
62
82
  const previousView = queryClient?.getQueryData<ViewState>(
63
83
  workspaceKeys.events(workspaceId, from)
@@ -67,14 +87,23 @@ export function reduceChatFrame(data: Record<string, unknown>, context: ChatFram
67
87
  queryClient?.removeQueries({ queryKey: workspaceKeys.events(workspaceId, from) })
68
88
  }
69
89
 
70
- const previousConfig = queryClient?.getQueryData<ThreadConfig>(
71
- workspaceKeys.threadConfig(workspaceId, from)
90
+ const previousConfig = queryClient?.getQueryData<SessionConfig>(
91
+ workspaceKeys.sessionConfig(workspaceId, from)
72
92
  )
73
93
  if (previousConfig !== undefined) {
74
- queryClient?.setQueryData(workspaceKeys.threadConfig(workspaceId, to), previousConfig)
75
- queryClient?.removeQueries({ queryKey: workspaceKeys.threadConfig(workspaceId, from) })
94
+ queryClient?.setQueryData(workspaceKeys.sessionConfig(workspaceId, to), previousConfig)
95
+ queryClient?.removeQueries({ queryKey: workspaceKeys.sessionConfig(workspaceId, from) })
96
+ }
97
+ if (!cachedSession) {
98
+ queryClient?.invalidateQueries({ queryKey: sessionsKey })
76
99
  }
77
- queryClient?.invalidateQueries({ queryKey: workspaceKeys.sessions(workspaceId) })
100
+ queryClient?.invalidateQueries({ queryKey: workspaceKeys.preview(workspaceId) })
101
+ return
102
+ }
103
+ if (data.type === 'sessions_changed') {
104
+ const workspaceId = data.workspaceId as string
105
+ const sessionsKey = workspaceKeys.sessions(workspaceId)
106
+ queryClient?.invalidateQueries({ queryKey: sessionsKey })
78
107
  queryClient?.invalidateQueries({ queryKey: workspaceKeys.preview(workspaceId) })
79
108
  return
80
109
  }