moi-computer 0.5.1 → 0.5.2-next.1
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.
- package/client/app/shell/SidebarLayout.tsx +1 -1
- package/client/components/shared/Composer.tsx +12 -3
- package/client/components/ui/dropdown-menu.tsx +1 -4
- package/client/components/ui/popover.tsx +11 -4
- package/client/components/ui/slider.tsx +70 -0
- package/client/components/ui/tooltip.tsx +1 -1
- package/client/features/applets/applet-cache.ts +10 -1
- package/client/features/applets/useApplet.ts +1 -1
- package/client/features/chat/ChatComposer.tsx +9 -13
- package/client/features/chat/ChatPanel.tsx +8 -8
- package/client/features/chat/ModelPicker.tsx +295 -116
- package/client/features/chat/TurnView.tsx +1 -1
- package/client/features/chat/chat-send.ts +15 -5
- package/client/features/chat/chat-store.ts +9 -22
- package/client/features/chat/model-order.ts +50 -28
- package/client/features/chat/useChat.ts +20 -11
- package/client/features/settings/IconPicker.tsx +2 -2
- package/client/features/views/api.ts +1 -0
- package/client/features/views/useViewBuilderActions.ts +4 -2
- package/client/features/workspace/WorkspaceScreen.tsx +2 -1
- package/client/features/workspace/WorkspaceSkillUpdateBanner.tsx +2 -2
- package/client/index.css +5 -3
- package/client/store/ui.ts +11 -1
- package/dist/chunk-94m3q9ce.js +1 -0
- package/dist/{chunk-v797g6ap.js → chunk-bcrkdhwe.js} +1 -1
- package/dist/{chunk-7bzpmtxp.js → chunk-jvhvme3z.js} +1 -1
- package/dist/chunk-k9dcnd73.js +27 -0
- package/dist/{chunk-jg6ezptn.js → chunk-kfw1qwqe.js} +2 -2
- package/dist/chunk-pk11vfzs.js +9 -0
- package/dist/{chunk-5vaevt8z.js → chunk-r2bqaege.js} +1 -1
- package/dist/{chunk-h3evrtyp.js → chunk-tzz101ea.js} +1 -1
- package/dist/chunk-xwhya7kb.js +1 -0
- package/dist/chunk-y4g8j7mv.css +1 -0
- package/dist/{chunk-m9qja0nx.js → chunk-zs4mte79.js} +1 -1
- package/dist/index.html +1 -1
- package/lib/types.ts +14 -5
- package/package.json +1 -1
- package/server/api.ts +13 -4
- package/server/applets.ts +49 -7
- package/server/harness/claude-code/models.ts +25 -2
- package/server/harness/claude-code/session.ts +28 -5
- package/server/harness/codex/adapter.ts +27 -2
- package/server/harness/codex/client.ts +33 -4
- package/server/harness/codex/session.ts +13 -4
- package/server/harness/types.ts +3 -2
- package/server/thread-config.ts +11 -7
- package/server/web.ts +3 -0
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +38 -42
- package/workspace/.claude/skills/moi-workspace/SKILL.md +1 -1
- package/dist/chunk-4tcmvefj.js +0 -1
- package/dist/chunk-gc2smzc9.js +0 -27
- package/dist/chunk-h0hk61pm.js +0 -9
- package/dist/chunk-k5sjx9s5.js +0 -1
- package/dist/chunk-s7za1qsv.css +0 -1
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { memo, useState } from 'react'
|
|
1
|
+
import { type ComponentProps, type ReactNode, memo, useState } from 'react'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { AnimatePresence, motion } from 'motion/react'
|
|
4
|
+
|
|
5
|
+
import { IconBolt, IconBoltFilled } from '@tabler/icons-react'
|
|
4
6
|
|
|
5
7
|
import { useSaveThreadConfig, useThreadConfig, useWorkspaceModels } from './api'
|
|
6
8
|
import {
|
|
9
|
+
hasEffortChoice,
|
|
7
10
|
resolveDisplayedEffort,
|
|
8
|
-
|
|
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 {
|
|
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 { useLive } from '@/client/features/chat/chat-store'
|
|
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,239 @@ 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
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
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()
|
|
63
281
|
const { data } = useWorkspaceModels(workspaceId)
|
|
282
|
+
|
|
64
283
|
// The SDK prepends a synthetic "default" entry ("Use the default model
|
|
65
|
-
// (currently …)"). Drop it and
|
|
66
|
-
// instead, so the picker shows e.g. "Opus (1M context)" rather than the meta
|
|
67
|
-
// "use default" row.
|
|
284
|
+
// (currently …)"). Drop it and name the concrete model it resolves to.
|
|
68
285
|
const allModels = data?.models ?? []
|
|
69
|
-
const defaultEntry = allModels.find(
|
|
286
|
+
const defaultEntry = allModels.find(model => model.value === 'default')
|
|
70
287
|
const models = data
|
|
71
288
|
? sortModelsByProviderOrder(
|
|
72
289
|
allModels.filter(model => model.value !== 'default'),
|
|
@@ -74,113 +291,75 @@ export const ModelPicker = memo(function ModelPicker({ scope = 'active-chat' }:
|
|
|
74
291
|
)
|
|
75
292
|
: []
|
|
76
293
|
|
|
77
|
-
// The active
|
|
78
|
-
//
|
|
79
|
-
const activeSessionId = useLive(
|
|
80
|
-
scope === 'active-chat' ? (
|
|
294
|
+
// The active chat's stored config is the source of truth. With no active chat,
|
|
295
|
+
// the picker reads and edits workspace defaults.
|
|
296
|
+
const activeSessionId = useLive(state =>
|
|
297
|
+
scope === 'active-chat' ? (state.activeByWorkspace[workspaceId] ?? null) : null
|
|
81
298
|
)
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
|
|
299
|
+
const threadConfig = useThreadConfig(workspaceId, activeSessionId).data
|
|
300
|
+
const saveThreadConfig = useSaveThreadConfig(workspaceId)
|
|
301
|
+
|
|
302
|
+
const selectedModel = (activeSessionId ? threadConfig?.model : undefined) ?? layout.selectedModel
|
|
303
|
+
const selectedEffort =
|
|
304
|
+
(activeSessionId ? threadConfig?.effort : undefined) ?? layout.selectedEffort
|
|
305
|
+
const selectedFastMode =
|
|
306
|
+
(activeSessionId ? threadConfig?.fastMode : undefined) ?? layout.selectedFastMode
|
|
85
307
|
|
|
86
|
-
const
|
|
87
|
-
const selectedEffort = (activeSessionId ? threadCfg?.effort : undefined) ?? layout.selectedEffort
|
|
88
|
-
const setSelected = (value: string) => {
|
|
308
|
+
const setSelectedModel = (value: string) => {
|
|
89
309
|
if (activeSessionId)
|
|
90
|
-
|
|
310
|
+
saveThreadConfig.mutate({ sessionId: activeSessionId, patch: { model: value } })
|
|
91
311
|
else setLayout({ selectedModel: value })
|
|
92
312
|
}
|
|
93
|
-
|
|
313
|
+
|
|
314
|
+
const setSelectedEffort = (value: string) => {
|
|
94
315
|
if (activeSessionId)
|
|
95
|
-
|
|
316
|
+
saveThreadConfig.mutate({ sessionId: activeSessionId, patch: { effort: value } })
|
|
96
317
|
else setLayout({ selectedEffort: value })
|
|
97
318
|
}
|
|
98
319
|
|
|
320
|
+
const setSelectedFastMode = (value: boolean) => {
|
|
321
|
+
if (activeSessionId)
|
|
322
|
+
saveThreadConfig.mutate({ sessionId: activeSessionId, patch: { fastMode: value } })
|
|
323
|
+
else setLayout({ selectedFastMode: value })
|
|
324
|
+
}
|
|
325
|
+
|
|
99
326
|
if (models.length === 0) return null
|
|
100
327
|
|
|
101
|
-
// Show
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
328
|
+
// Show a persisted pick when it still exists. Otherwise name the concrete
|
|
329
|
+
// model behind the SDK default, or fall back to the first available model.
|
|
330
|
+
const persistedModel = models.some(model => model.value === selectedModel)
|
|
331
|
+
? selectedModel
|
|
332
|
+
: undefined
|
|
106
333
|
const defaultModel =
|
|
107
334
|
models.find(
|
|
108
|
-
|
|
335
|
+
model => defaultEntry?.resolvedModel && model.resolvedModel === defaultEntry.resolvedModel
|
|
109
336
|
) ?? models[0]
|
|
110
|
-
const
|
|
111
|
-
const model = models.find(
|
|
112
|
-
const effortLevels =
|
|
113
|
-
model.supportsEffort ? (model.supportedEffortLevels ?? []) : []
|
|
114
|
-
)
|
|
337
|
+
const currentModelValue = persistedModel ?? defaultModel.value
|
|
338
|
+
const model = models.find(item => item.value === currentModelValue) ?? models[0]
|
|
339
|
+
const effortLevels = model.supportsEffort ? (model.supportedEffortLevels ?? []) : []
|
|
115
340
|
const currentEffort = resolveDisplayedEffort(effortLevels, selectedEffort)
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
const showFastMode = !!model.supportsFastMode
|
|
341
|
+
const showEffort = hasEffortChoice(effortLevels) && currentEffort !== undefined
|
|
342
|
+
const fastMode = resolveFastMode(model, selectedFastMode)
|
|
119
343
|
|
|
120
344
|
return (
|
|
121
|
-
<
|
|
122
|
-
<
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
}
|
|
345
|
+
<div className="flex shrink-0 items-center gap-1">
|
|
346
|
+
<ModelDropdown
|
|
347
|
+
current={currentModelValue}
|
|
348
|
+
model={model}
|
|
349
|
+
models={models}
|
|
350
|
+
onValueChange={setSelectedModel}
|
|
136
351
|
/>
|
|
137
|
-
|
|
138
|
-
<
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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>
|
|
352
|
+
{showEffort && (
|
|
353
|
+
<EffortPicker
|
|
354
|
+
key={model.value}
|
|
355
|
+
currentEffort={currentEffort}
|
|
356
|
+
effortLevels={effortLevels}
|
|
357
|
+
fastMode={fastMode}
|
|
358
|
+
showFastMode={model.supportsFastMode === true}
|
|
359
|
+
onFastModeChange={setSelectedFastMode}
|
|
360
|
+
onValueChange={setSelectedEffort}
|
|
361
|
+
/>
|
|
362
|
+
)}
|
|
363
|
+
</div>
|
|
185
364
|
)
|
|
186
365
|
})
|
|
@@ -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-
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import type { QueryClient } from '@tanstack/react-query'
|
|
2
2
|
|
|
3
3
|
import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
4
|
-
import { type ChatAttachment,
|
|
4
|
+
import { attachmentKey, type ChatAttachment, liveStore } from '@/client/features/chat/chat-store'
|
|
5
5
|
import type { MoiUserMessageOptions } from '@/client/features/workspace/moi-context'
|
|
6
6
|
import { STREAM_RESPONSES } from '@/client/lib/flags'
|
|
7
7
|
import { applyEvent, emptyViewState } from '@/lib/format'
|
|
@@ -27,7 +27,7 @@ export function attachmentsForSend(
|
|
|
27
27
|
options?: ChatSendOptions
|
|
28
28
|
): ChatAttachment[] {
|
|
29
29
|
if (!ownsComposerAttachments(options)) return []
|
|
30
|
-
const pending = liveStore.getState().attachments[
|
|
30
|
+
const pending = liveStore.getState().attachments[attachmentKey(workspaceId, sessionId)] ?? []
|
|
31
31
|
return pending.filter(a => a.status === 'ready' && a.upload)
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -65,8 +65,9 @@ export function startOptimisticTurn({
|
|
|
65
65
|
export function resolveChatRunOptions(
|
|
66
66
|
modelsData: WorkspaceModels | undefined,
|
|
67
67
|
pickedModel: string | undefined,
|
|
68
|
-
pickedEffort: string | undefined
|
|
69
|
-
|
|
68
|
+
pickedEffort: string | undefined,
|
|
69
|
+
pickedFastMode?: boolean
|
|
70
|
+
): { model?: string; effort?: string; fastMode?: boolean; stream?: true } {
|
|
70
71
|
const models = modelsData?.models
|
|
71
72
|
const model =
|
|
72
73
|
!pickedModel || !models || models.some(candidate => candidate.value === pickedModel)
|
|
@@ -77,6 +78,15 @@ export function resolveChatRunOptions(
|
|
|
77
78
|
pickedEffort && (!modelInfo || (modelInfo.supportedEffortLevels ?? []).includes(pickedEffort))
|
|
78
79
|
? pickedEffort
|
|
79
80
|
: undefined
|
|
81
|
+
const fastMode =
|
|
82
|
+
pickedFastMode === undefined || !modelInfo || modelInfo.supportsFastMode
|
|
83
|
+
? pickedFastMode
|
|
84
|
+
: false
|
|
80
85
|
const stream = STREAM_RESPONSES && modelsData?.supportsStreaming ? true : undefined
|
|
81
|
-
return {
|
|
86
|
+
return {
|
|
87
|
+
model,
|
|
88
|
+
effort,
|
|
89
|
+
...(fastMode !== undefined ? { fastMode } : {}),
|
|
90
|
+
stream
|
|
91
|
+
}
|
|
82
92
|
}
|
|
@@ -35,11 +35,9 @@ function key(workspaceId: string, sessionId: string): string {
|
|
|
35
35
|
return `${workspaceId}:${sessionId}`
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
//
|
|
39
|
-
// gets a stable `'new'` sentinel
|
|
40
|
-
|
|
41
|
-
// key it reads as the store writes.
|
|
42
|
-
export function draftKey(workspaceId: string, sessionId: string | null): string {
|
|
38
|
+
// Attachments stay with the chat they were added to. A brand-new chat has no
|
|
39
|
+
// session id yet, so it gets a stable `'new'` sentinel until send mints one.
|
|
40
|
+
export function attachmentKey(workspaceId: string, sessionId: string | null): string {
|
|
43
41
|
return key(workspaceId, sessionId ?? 'new')
|
|
44
42
|
}
|
|
45
43
|
|
|
@@ -65,14 +63,8 @@ export type LiveStore = {
|
|
|
65
63
|
// so concurrent streams never collide. Reconciled against the durable
|
|
66
64
|
// transcript: a preview is dropped the instant its finalized turn arrives.
|
|
67
65
|
previews: Record<string, LivePreview>
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
// chat component — so a keystroke re-renders only the composer (which alone
|
|
71
|
-
// subscribes), not the whole workspace, and the draft survives the chat
|
|
72
|
-
// panel's remounts on mode switch.
|
|
73
|
-
drafts: Record<string, string>
|
|
74
|
-
// Composer attachments, keyed per thread exactly like `drafts` (so they follow
|
|
75
|
-
// the active thread and survive composer remounts). Cleared on send.
|
|
66
|
+
// Composer attachments are per chat, survive composer remounts, and clear on
|
|
67
|
+
// send. Draft text is workspace-local persisted UI state (client/store/ui).
|
|
76
68
|
attachments: Record<string, ChatAttachment[]>
|
|
77
69
|
|
|
78
70
|
setActive: (workspaceId: string, sessionId: string | null) => void
|
|
@@ -84,7 +76,6 @@ export type LiveStore = {
|
|
|
84
76
|
sessions: { workspaceId: string; sessionId: string; activity: SessionActivity }[]
|
|
85
77
|
) => void
|
|
86
78
|
setError: (workspaceId: string, sessionId: string, message: string | null) => void
|
|
87
|
-
setDraft: (workspaceId: string, sessionId: string | null, value: string) => void
|
|
88
79
|
addAttachments: (workspaceId: string, sessionId: string | null, items: ChatAttachment[]) => void
|
|
89
80
|
updateAttachment: (
|
|
90
81
|
workspaceId: string,
|
|
@@ -114,7 +105,6 @@ export const liveStore = createStore<LiveStore>()(set => ({
|
|
|
114
105
|
activeByWorkspace: {},
|
|
115
106
|
activity: {},
|
|
116
107
|
errors: {},
|
|
117
|
-
drafts: {},
|
|
118
108
|
previews: {},
|
|
119
109
|
attachments: {},
|
|
120
110
|
|
|
@@ -132,9 +122,6 @@ export const liveStore = createStore<LiveStore>()(set => ({
|
|
|
132
122
|
setError: (workspaceId, sessionId, message) =>
|
|
133
123
|
set(s => ({ errors: { ...s.errors, [key(workspaceId, sessionId)]: message } })),
|
|
134
124
|
|
|
135
|
-
setDraft: (workspaceId, sessionId, value) =>
|
|
136
|
-
set(s => ({ drafts: { ...s.drafts, [draftKey(workspaceId, sessionId)]: value } })),
|
|
137
|
-
|
|
138
125
|
setPreview: frame =>
|
|
139
126
|
set(s => ({
|
|
140
127
|
previews: {
|
|
@@ -182,13 +169,13 @@ export const liveStore = createStore<LiveStore>()(set => ({
|
|
|
182
169
|
|
|
183
170
|
addAttachments: (workspaceId, sessionId, items) =>
|
|
184
171
|
set(s => {
|
|
185
|
-
const k =
|
|
172
|
+
const k = attachmentKey(workspaceId, sessionId)
|
|
186
173
|
return { attachments: { ...s.attachments, [k]: [...(s.attachments[k] ?? []), ...items] } }
|
|
187
174
|
}),
|
|
188
175
|
|
|
189
176
|
updateAttachment: (workspaceId, sessionId, localId, patch) =>
|
|
190
177
|
set(s => {
|
|
191
|
-
const k =
|
|
178
|
+
const k = attachmentKey(workspaceId, sessionId)
|
|
192
179
|
const list = s.attachments[k]
|
|
193
180
|
if (!list) return {}
|
|
194
181
|
return {
|
|
@@ -201,7 +188,7 @@ export const liveStore = createStore<LiveStore>()(set => ({
|
|
|
201
188
|
|
|
202
189
|
removeAttachment: (workspaceId, sessionId, localId) =>
|
|
203
190
|
set(s => {
|
|
204
|
-
const k =
|
|
191
|
+
const k = attachmentKey(workspaceId, sessionId)
|
|
205
192
|
const list = s.attachments[k]
|
|
206
193
|
if (!list) return {}
|
|
207
194
|
const target = list.find(a => a.localId === localId)
|
|
@@ -211,7 +198,7 @@ export const liveStore = createStore<LiveStore>()(set => ({
|
|
|
211
198
|
|
|
212
199
|
clearAttachments: (workspaceId, sessionId) =>
|
|
213
200
|
set(s => {
|
|
214
|
-
const k =
|
|
201
|
+
const k = attachmentKey(workspaceId, sessionId)
|
|
215
202
|
for (const a of s.attachments[k] ?? []) {
|
|
216
203
|
if (a.previewUrl) URL.revokeObjectURL(a.previewUrl)
|
|
217
204
|
}
|