moi-computer 0.5.2-next.1 → 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.
- package/client/AGENTS.md +9 -0
- package/client/api/app-ui-keys.ts +4 -0
- package/client/api/workspace-keys.ts +2 -2
- package/client/app/routes/WorkspaceRoute.tsx +8 -28
- package/client/components/shared/Composer.tsx +3 -6
- package/client/components/shared/IconGhost.tsx +130 -0
- package/client/components/ui/dropdown-menu.tsx +1 -1
- package/client/components/ui/spinner.tsx +18 -0
- package/client/components/ui/toast.tsx +220 -0
- package/client/features/chat/ChatComposer.tsx +3 -2
- package/client/features/chat/ChatPanel.tsx +7 -6
- package/client/features/chat/ChatPopup.tsx +10 -4
- package/client/features/chat/ChatSelector.tsx +263 -48
- package/client/features/chat/ModelPicker.tsx +13 -18
- package/client/features/chat/api.ts +36 -9
- package/client/features/chat/chat-frames.ts +35 -6
- package/client/features/chat/chat-send.ts +25 -1
- package/client/features/chat/chat-store.ts +43 -18
- package/client/features/chat/useChat.ts +54 -52
- package/client/features/chat/useSelectedSession.ts +151 -0
- package/client/features/chat/useStickToBottom.ts +3 -3
- package/client/features/home/api.ts +0 -2
- package/client/features/scratchpad/ScratchpadControls.tsx +2 -2
- package/client/features/settings/WorkspaceSettings.tsx +6 -6
- package/client/features/views/ViewBuilderTab.tsx +3 -4
- package/client/features/views/useViewBuilderActions.ts +3 -1
- package/client/features/workspace/WorkspaceScreen.tsx +38 -18
- package/client/features/workspace/WorkspaceTabs.tsx +10 -1
- package/client/main.tsx +2 -0
- package/client/runtime/useWorkspaceEvents.ts +1 -0
- package/client/store/ui.ts +2 -2
- package/dist/{chunk-zs4mte79.js → chunk-0pcdwjkp.js} +1 -1
- package/dist/chunk-55sh4dty.js +2 -0
- package/dist/{chunk-tzz101ea.js → chunk-9y2zbzqz.js} +1 -1
- package/dist/{chunk-jvhvme3z.js → chunk-afgbg75t.js} +1 -1
- package/dist/chunk-agtetn7n.css +1 -0
- package/dist/chunk-bv6vrvqf.js +27 -0
- package/dist/chunk-dfs36zgc.js +1 -0
- package/dist/chunk-exj6hr30.js +9 -0
- package/dist/{chunk-bcrkdhwe.js → chunk-m11ckkxd.js} +1 -1
- package/dist/{chunk-xwhya7kb.js → chunk-n6t40enm.js} +1 -1
- package/dist/{chunk-kfw1qwqe.js → chunk-rxvx4ta9.js} +3 -3
- package/dist/index.html +1 -1
- package/lib/attachment-note.ts +18 -0
- package/lib/chat-title.ts +6 -0
- package/lib/types.ts +24 -10
- package/package.json +1 -1
- package/server/api.ts +90 -9
- package/server/app-settings.ts +1 -1
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +6 -0
- package/server/harness/claude-code/adapter.ts +2 -2
- package/server/harness/claude-code/index.ts +7 -1
- package/server/harness/claude-code/session-title.ts +106 -0
- package/server/harness/claude-code/session.ts +87 -13
- package/server/harness/claude-code/sessions.ts +35 -4
- package/server/harness/codex/client.ts +30 -12
- package/server/harness/codex/index.ts +2 -0
- package/server/harness/codex/session-title.ts +149 -0
- package/server/harness/codex/session.ts +84 -11
- package/server/harness/openclaw/adapter.ts +4 -2
- package/server/harness/openclaw/discovery.ts +2 -0
- package/server/harness/openclaw/session.ts +15 -7
- package/server/harness/session-title.ts +96 -0
- package/server/harness/types.ts +2 -0
- package/server/selected-session.ts +132 -0
- package/server/{thread-config.ts → session-config.ts} +57 -39
- package/server/web.ts +12 -1
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +16 -26
- package/workspace/.claude/skills/moi-workspace/SKILL.md +8 -2
- package/dist/chunk-94m3q9ce.js +0 -1
- package/dist/chunk-k9dcnd73.js +0 -27
- package/dist/chunk-pk11vfzs.js +0 -9
- package/dist/chunk-r2bqaege.js +0 -2
- package/dist/chunk-y4g8j7mv.css +0 -1
|
@@ -1,88 +1,303 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useRef, useState } from 'react'
|
|
2
|
+
import { IconArchive, IconChevronDown, IconEdit } from '@tabler/icons-react'
|
|
2
3
|
|
|
3
|
-
import { useWorkspaceSessions } from './api'
|
|
4
|
+
import { useArchiveWorkspaceSession, useWorkspaceModels, useWorkspaceSessions } from './api'
|
|
4
5
|
import { useWorkspaceId } from '@/client/features/workspace/WorkspaceContext'
|
|
5
6
|
import { cn } from '@/client/lib/cn'
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
hasRunningBackgroundSession,
|
|
9
|
+
isSessionRunning,
|
|
10
|
+
liveStore,
|
|
11
|
+
useLive
|
|
12
|
+
} from '@/client/features/chat/chat-store'
|
|
13
|
+
import type { SessionInfo } from '@/lib/types'
|
|
7
14
|
|
|
8
15
|
import { Button } from '@/client/components/ui/button'
|
|
16
|
+
import { toast } from '@/client/components/ui/toast'
|
|
17
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
|
|
9
18
|
import {
|
|
10
19
|
DropdownMenu,
|
|
11
20
|
DropdownMenuContent,
|
|
12
21
|
DropdownMenuGroup,
|
|
13
22
|
DropdownMenuItem,
|
|
14
|
-
|
|
23
|
+
DropdownMenuLabel,
|
|
24
|
+
DropdownMenuSeparator,
|
|
15
25
|
DropdownMenuTrigger
|
|
16
26
|
} from '@/client/components/ui/dropdown-menu'
|
|
27
|
+
import { Spinner } from '@/client/components/ui/spinner'
|
|
17
28
|
|
|
18
29
|
type ChatSelectorProps = {
|
|
19
|
-
|
|
30
|
+
onSelectSession: (sessionId: string | null) => void
|
|
31
|
+
selectedSessionId: string | null
|
|
20
32
|
}
|
|
21
33
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const yesterday = new Date(now)
|
|
27
|
-
yesterday.setDate(yesterday.getDate() - 1)
|
|
28
|
-
const isYesterday = date.toDateString() === yesterday.toDateString()
|
|
29
|
-
|
|
30
|
-
if (isToday) return date.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' })
|
|
31
|
-
if (isYesterday) return 'Yesterday'
|
|
32
|
-
return date.toLocaleDateString([], { month: 'short', day: 'numeric' })
|
|
34
|
+
type ChatSessionGroup = {
|
|
35
|
+
key: string
|
|
36
|
+
label: string
|
|
37
|
+
sessions: SessionInfo[]
|
|
33
38
|
}
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
type ChatSessionItemProps = {
|
|
41
|
+
active: boolean
|
|
42
|
+
canArchive: boolean
|
|
43
|
+
confirmingArchive: boolean
|
|
44
|
+
onArchive: (sessionId: string) => Promise<void>
|
|
45
|
+
onRequestArchive: (sessionId: string) => void
|
|
46
|
+
onSelect: (sessionId: string) => void
|
|
47
|
+
session: SessionInfo
|
|
48
|
+
workspaceId: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function ChatSessionItem({
|
|
52
|
+
active,
|
|
53
|
+
canArchive,
|
|
54
|
+
confirmingArchive,
|
|
55
|
+
onArchive,
|
|
56
|
+
onRequestArchive,
|
|
57
|
+
onSelect,
|
|
58
|
+
session,
|
|
59
|
+
workspaceId
|
|
60
|
+
}: ChatSessionItemProps) {
|
|
61
|
+
const pendingRef = useRef(false)
|
|
62
|
+
const [pending, setPending] = useState(false)
|
|
63
|
+
const running = useLive(state => isSessionRunning(state.activity, workspaceId, session.sessionId))
|
|
64
|
+
|
|
65
|
+
function handleRequestArchive() {
|
|
66
|
+
onRequestArchive(session.sessionId)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function handleConfirmArchive() {
|
|
70
|
+
if (pendingRef.current) return
|
|
71
|
+
|
|
72
|
+
pendingRef.current = true
|
|
73
|
+
setPending(true)
|
|
74
|
+
try {
|
|
75
|
+
await onArchive(session.sessionId)
|
|
76
|
+
} catch {
|
|
77
|
+
toast.add({ title: 'Couldn’t archive chat', type: 'error' })
|
|
78
|
+
} finally {
|
|
79
|
+
pendingRef.current = false
|
|
80
|
+
setPending(false)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<div className="group/chat relative">
|
|
86
|
+
<DropdownMenuItem
|
|
87
|
+
className={cn(
|
|
88
|
+
'font-medium group-hover/chat:bg-accent group-hover/chat:text-accent-foreground',
|
|
89
|
+
active && 'bg-accent text-accent-foreground'
|
|
90
|
+
)}
|
|
91
|
+
onClick={() => onSelect(session.sessionId)}
|
|
92
|
+
>
|
|
93
|
+
<div
|
|
94
|
+
className={cn(
|
|
95
|
+
'flex min-w-0 flex-1 overflow-hidden',
|
|
96
|
+
(running || pending) && 'mr-4 mask-r-from-[calc(100%-16px)]',
|
|
97
|
+
canArchive &&
|
|
98
|
+
!confirmingArchive &&
|
|
99
|
+
'group-focus-within/chat:mr-4 group-focus-within/chat:mask-r-from-[calc(100%-16px)] group-hover/chat:mr-4 group-hover/chat:mask-r-from-[calc(100%-16px)] [@media(hover:none)]:mr-4 [@media(hover:none)]:mask-r-from-[calc(100%-16px)]',
|
|
100
|
+
confirmingArchive && 'mr-14 mask-r-from-[calc(100%-16px)]'
|
|
101
|
+
)}
|
|
102
|
+
>
|
|
103
|
+
<span
|
|
104
|
+
className={cn(
|
|
105
|
+
'min-w-0 truncate',
|
|
106
|
+
(running || pending) && '-mr-4',
|
|
107
|
+
confirmingArchive
|
|
108
|
+
? '-4'
|
|
109
|
+
: canArchive &&
|
|
110
|
+
'group-focus-within/chat:-mr-4 group-hover/chat:-mr-4 [@media(hover:none)]:-mr-4'
|
|
111
|
+
)}
|
|
112
|
+
>
|
|
113
|
+
{session.summary}
|
|
114
|
+
</span>
|
|
115
|
+
</div>
|
|
116
|
+
</DropdownMenuItem>
|
|
117
|
+
{running && (
|
|
118
|
+
<Spinner
|
|
119
|
+
className={cn(
|
|
120
|
+
'pointer-events-none absolute top-1/2 right-1.5 -translate-y-1/2 text-muted-foreground',
|
|
121
|
+
canArchive &&
|
|
122
|
+
'group-focus-within/chat:hidden group-hover/chat:hidden [@media(hover:none)]:hidden',
|
|
123
|
+
(confirmingArchive || pending) && 'hidden'
|
|
124
|
+
)}
|
|
125
|
+
/>
|
|
126
|
+
)}
|
|
127
|
+
{canArchive && (
|
|
128
|
+
<div
|
|
129
|
+
className={cn(
|
|
130
|
+
'absolute top-1/2 right-0 flex -translate-y-1/2 items-center opacity-100 transition-none',
|
|
131
|
+
!confirmingArchive &&
|
|
132
|
+
'group-focus-within/chat:opacity-100 group-hover/chat:opacity-100 [@media(hover:hover)]:opacity-0',
|
|
133
|
+
pending && 'opacity-100!'
|
|
134
|
+
)}
|
|
135
|
+
>
|
|
136
|
+
{confirmingArchive ? (
|
|
137
|
+
<Button
|
|
138
|
+
type="button"
|
|
139
|
+
variant="secondary"
|
|
140
|
+
size="sm"
|
|
141
|
+
aria-label={`Confirm archive ${session.summary}`}
|
|
142
|
+
tabIndex={-1}
|
|
143
|
+
className="mr-1 h-5 rounded-sm px-1.5 text-xs hover:bg-accent"
|
|
144
|
+
disabled={pending}
|
|
145
|
+
onClick={handleConfirmArchive}
|
|
146
|
+
onPointerDown={event => event.stopPropagation()}
|
|
147
|
+
>
|
|
148
|
+
Confirm
|
|
149
|
+
</Button>
|
|
150
|
+
) : (
|
|
151
|
+
<Tooltip>
|
|
152
|
+
<TooltipTrigger
|
|
153
|
+
render={
|
|
154
|
+
<Button
|
|
155
|
+
type="button"
|
|
156
|
+
variant="ghost"
|
|
157
|
+
size="icon-sm"
|
|
158
|
+
aria-label={`Archive ${session.summary}`}
|
|
159
|
+
tabIndex={-1}
|
|
160
|
+
className="text-muted-foreground hover:bg-transparent hover:text-foreground"
|
|
161
|
+
disabled={pending}
|
|
162
|
+
onClick={handleRequestArchive}
|
|
163
|
+
onPointerDown={event => event.stopPropagation()}
|
|
164
|
+
>
|
|
165
|
+
<IconArchive stroke={1.75} />
|
|
166
|
+
</Button>
|
|
167
|
+
}
|
|
168
|
+
/>
|
|
169
|
+
<TooltipContent side="right">Archive chat</TooltipContent>
|
|
170
|
+
</Tooltip>
|
|
171
|
+
)}
|
|
172
|
+
</div>
|
|
173
|
+
)}
|
|
174
|
+
</div>
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function localDateKey(date: Date): string {
|
|
179
|
+
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function calendarDayNumber(date: Date): number {
|
|
183
|
+
return Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) / 86_400_000
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function formatGroupLabel(date: Date, now: Date): string {
|
|
187
|
+
const daysAgo = calendarDayNumber(now) - calendarDayNumber(date)
|
|
188
|
+
if (daysAgo === 0) return 'Today'
|
|
189
|
+
if (daysAgo === 1) return 'Yesterday'
|
|
190
|
+
if (daysAgo >= 2 && daysAgo <= 5) return `${daysAgo} days ago`
|
|
191
|
+
|
|
192
|
+
return date.toLocaleDateString([], {
|
|
193
|
+
month: 'short',
|
|
194
|
+
day: 'numeric',
|
|
195
|
+
...(date.getFullYear() === now.getFullYear() ? {} : { year: 'numeric' })
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function groupSessionsByDate(sessions: SessionInfo[], now = new Date()): ChatSessionGroup[] {
|
|
200
|
+
const groups = new Map<string, ChatSessionGroup>()
|
|
201
|
+
|
|
202
|
+
for (const session of sessions.slice().sort((a, b) => b.lastModified - a.lastModified)) {
|
|
203
|
+
const date = new Date(session.lastModified)
|
|
204
|
+
const key = localDateKey(date)
|
|
205
|
+
const group = groups.get(key)
|
|
206
|
+
if (group) {
|
|
207
|
+
group.sessions.push(session)
|
|
208
|
+
continue
|
|
209
|
+
}
|
|
210
|
+
groups.set(key, {
|
|
211
|
+
key,
|
|
212
|
+
label: formatGroupLabel(date, now),
|
|
213
|
+
sessions: [session]
|
|
214
|
+
})
|
|
215
|
+
}
|
|
39
216
|
|
|
40
|
-
|
|
217
|
+
return [...groups.values()]
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function ChatSelector({ onSelectSession, selectedSessionId }: ChatSelectorProps) {
|
|
221
|
+
const workspaceId = useWorkspaceId()
|
|
222
|
+
const [confirmingSessionId, setConfirmingSessionId] = useState<string | null>(null)
|
|
223
|
+
const { data: sessions = [] } = useWorkspaceSessions(workspaceId)
|
|
224
|
+
const canArchive = useWorkspaceModels(workspaceId).data?.supportsArchiving === true
|
|
225
|
+
const archiveSession = useArchiveWorkspaceSession(workspaceId)
|
|
226
|
+
const hasRunningBackgroundChat = useLive(state =>
|
|
227
|
+
hasRunningBackgroundSession(state.activity, workspaceId, selectedSessionId)
|
|
228
|
+
)
|
|
229
|
+
const active = sessions.find(s => s.sessionId === selectedSessionId)
|
|
41
230
|
const label = active?.summary ?? 'New chat'
|
|
231
|
+
const sessionGroups = groupSessionsByDate(sessions)
|
|
42
232
|
|
|
43
233
|
function handleSelect(sessionId: string | null) {
|
|
44
|
-
|
|
234
|
+
onSelectSession(sessionId)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function handleMenuOpenChange(open: boolean) {
|
|
238
|
+
if (!open) setConfirmingSessionId(null)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async function handleArchive(sessionId: string) {
|
|
242
|
+
setConfirmingSessionId(null)
|
|
243
|
+
await archiveSession.mutateAsync(sessionId)
|
|
244
|
+
const store = liveStore.getState()
|
|
245
|
+
store.clearAttachments(workspaceId, sessionId)
|
|
246
|
+
store.clearPreviewsForSession(workspaceId, sessionId)
|
|
247
|
+
if (selectedSessionId === sessionId) {
|
|
248
|
+
onSelectSession(null)
|
|
249
|
+
}
|
|
45
250
|
}
|
|
46
251
|
|
|
47
252
|
return (
|
|
48
|
-
<DropdownMenu
|
|
49
|
-
onOpenChange={open => {
|
|
50
|
-
if (open) refetch()
|
|
51
|
-
}}
|
|
52
|
-
>
|
|
253
|
+
<DropdownMenu onOpenChange={handleMenuOpenChange}>
|
|
53
254
|
<DropdownMenuTrigger
|
|
54
255
|
render={
|
|
55
256
|
<Button variant="ghost">
|
|
56
257
|
<span className="max-w-64 truncate">{label}</span>
|
|
57
|
-
|
|
258
|
+
{hasRunningBackgroundChat ? (
|
|
259
|
+
<Spinner className="size-4!" stroke={2} />
|
|
260
|
+
) : (
|
|
261
|
+
<IconChevronDown stroke={1.5} />
|
|
262
|
+
)}
|
|
58
263
|
</Button>
|
|
59
264
|
}
|
|
60
265
|
/>
|
|
61
|
-
<DropdownMenuContent
|
|
266
|
+
<DropdownMenuContent
|
|
267
|
+
align="start"
|
|
268
|
+
className="flex max-h-100 w-max max-w-72 min-w-40 flex-col overflow-hidden"
|
|
269
|
+
>
|
|
62
270
|
<DropdownMenuItem
|
|
63
|
-
className="text-muted-foreground! **:text-muted-foreground!"
|
|
271
|
+
className="shrink-0 gap-1 font-medium text-muted-foreground! **:text-muted-foreground!"
|
|
64
272
|
onClick={() => handleSelect(null)}
|
|
65
273
|
>
|
|
66
|
-
<
|
|
274
|
+
<IconEdit size={16} stroke={1.75} />
|
|
67
275
|
New chat
|
|
68
276
|
</DropdownMenuItem>
|
|
69
|
-
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
277
|
+
{sessionGroups.length > 0 && (
|
|
278
|
+
<>
|
|
279
|
+
<DropdownMenuSeparator className="shrink-0" />
|
|
280
|
+
<div className="no-scrollbar flex min-h-0 flex-1 scroll-fade flex-col gap-1 overflow-y-auto overscroll-contain [--scroll-fade-reveal:8px]">
|
|
281
|
+
{sessionGroups.map(group => (
|
|
282
|
+
<DropdownMenuGroup key={group.key}>
|
|
283
|
+
<DropdownMenuLabel>{group.label}</DropdownMenuLabel>
|
|
284
|
+
{group.sessions.map(session => (
|
|
285
|
+
<ChatSessionItem
|
|
286
|
+
key={session.sessionId}
|
|
287
|
+
session={session}
|
|
288
|
+
active={selectedSessionId === session.sessionId}
|
|
289
|
+
canArchive={canArchive}
|
|
290
|
+
confirmingArchive={confirmingSessionId === session.sessionId}
|
|
291
|
+
onSelect={handleSelect}
|
|
292
|
+
onArchive={handleArchive}
|
|
293
|
+
onRequestArchive={setConfirmingSessionId}
|
|
294
|
+
workspaceId={workspaceId}
|
|
295
|
+
/>
|
|
296
|
+
))}
|
|
297
|
+
</DropdownMenuGroup>
|
|
298
|
+
))}
|
|
299
|
+
</div>
|
|
300
|
+
</>
|
|
86
301
|
)}
|
|
87
302
|
</DropdownMenuContent>
|
|
88
303
|
</DropdownMenu>
|
|
@@ -4,7 +4,7 @@ import { AnimatePresence, motion } from 'motion/react'
|
|
|
4
4
|
|
|
5
5
|
import { IconBolt, IconBoltFilled } from '@tabler/icons-react'
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { useSaveSessionConfig, useSessionConfig, useWorkspaceModels } from './api'
|
|
8
8
|
import {
|
|
9
9
|
hasEffortChoice,
|
|
10
10
|
resolveDisplayedEffort,
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
} from '@/client/components/ui/popover'
|
|
31
31
|
import { Slider } from '@/client/components/ui/slider'
|
|
32
32
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/client/components/ui/tooltip'
|
|
33
|
-
import {
|
|
33
|
+
import { useSelectedSession } from '@/client/features/chat/useSelectedSession'
|
|
34
34
|
import { useWorkspaceLayoutCtx } from '@/client/features/workspace/WorkspaceLayoutContext'
|
|
35
35
|
import { cn } from '@/client/lib/cn'
|
|
36
36
|
import type { Model } from '@/lib/types'
|
|
@@ -278,6 +278,7 @@ type ModelPickerProps = {
|
|
|
278
278
|
// the same defaults that their submit path reads.
|
|
279
279
|
export const ModelPicker = memo(function ModelPicker({ scope = 'active-chat' }: ModelPickerProps) {
|
|
280
280
|
const { workspaceId, layout, setLayout } = useWorkspaceLayoutCtx()
|
|
281
|
+
const [selectedSessionId] = useSelectedSession()
|
|
281
282
|
const { data } = useWorkspaceModels(workspaceId)
|
|
282
283
|
|
|
283
284
|
// The SDK prepends a synthetic "default" entry ("Use the default model
|
|
@@ -291,35 +292,29 @@ export const ModelPicker = memo(function ModelPicker({ scope = 'active-chat' }:
|
|
|
291
292
|
)
|
|
292
293
|
: []
|
|
293
294
|
|
|
294
|
-
// The
|
|
295
|
+
// The selected chat's stored config is the source of truth. With New chat,
|
|
295
296
|
// the picker reads and edits workspace defaults.
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
)
|
|
299
|
-
const threadConfig = useThreadConfig(workspaceId, activeSessionId).data
|
|
300
|
-
const saveThreadConfig = useSaveThreadConfig(workspaceId)
|
|
297
|
+
const sessionId = scope === 'active-chat' ? (selectedSessionId ?? null) : null
|
|
298
|
+
const sessionConfig = useSessionConfig(workspaceId, sessionId).data
|
|
299
|
+
const saveSessionConfig = useSaveSessionConfig(workspaceId)
|
|
301
300
|
|
|
302
|
-
const selectedModel = (
|
|
303
|
-
const selectedEffort =
|
|
304
|
-
(activeSessionId ? threadConfig?.effort : undefined) ?? layout.selectedEffort
|
|
301
|
+
const selectedModel = (sessionId ? sessionConfig?.model : undefined) ?? layout.selectedModel
|
|
302
|
+
const selectedEffort = (sessionId ? sessionConfig?.effort : undefined) ?? layout.selectedEffort
|
|
305
303
|
const selectedFastMode =
|
|
306
|
-
(
|
|
304
|
+
(sessionId ? sessionConfig?.fastMode : undefined) ?? layout.selectedFastMode
|
|
307
305
|
|
|
308
306
|
const setSelectedModel = (value: string) => {
|
|
309
|
-
if (
|
|
310
|
-
saveThreadConfig.mutate({ sessionId: activeSessionId, patch: { model: value } })
|
|
307
|
+
if (sessionId) saveSessionConfig.mutate({ sessionId, patch: { model: value } })
|
|
311
308
|
else setLayout({ selectedModel: value })
|
|
312
309
|
}
|
|
313
310
|
|
|
314
311
|
const setSelectedEffort = (value: string) => {
|
|
315
|
-
if (
|
|
316
|
-
saveThreadConfig.mutate({ sessionId: activeSessionId, patch: { effort: value } })
|
|
312
|
+
if (sessionId) saveSessionConfig.mutate({ sessionId, patch: { effort: value } })
|
|
317
313
|
else setLayout({ selectedEffort: value })
|
|
318
314
|
}
|
|
319
315
|
|
|
320
316
|
const setSelectedFastMode = (value: boolean) => {
|
|
321
|
-
if (
|
|
322
|
-
saveThreadConfig.mutate({ sessionId: activeSessionId, patch: { fastMode: value } })
|
|
317
|
+
if (sessionId) saveSessionConfig.mutate({ sessionId, patch: { fastMode: value } })
|
|
323
318
|
else setLayout({ selectedFastMode: value })
|
|
324
319
|
}
|
|
325
320
|
|
|
@@ -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
|
|
51
|
-
return useQuery<
|
|
52
|
-
queryKey: workspaceKeys.
|
|
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
|
|
89
|
+
export function useSaveSessionConfig(workspaceId: string) {
|
|
63
90
|
const queryClient = useQueryClient()
|
|
64
|
-
return useMutation<
|
|
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<
|
|
73
|
-
workspaceKeys.
|
|
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<
|
|
71
|
-
workspaceKeys.
|
|
90
|
+
const previousConfig = queryClient?.getQueryData<SessionConfig>(
|
|
91
|
+
workspaceKeys.sessionConfig(workspaceId, from)
|
|
72
92
|
)
|
|
73
93
|
if (previousConfig !== undefined) {
|
|
74
|
-
queryClient?.setQueryData(workspaceKeys.
|
|
75
|
-
queryClient?.removeQueries({ queryKey: workspaceKeys.
|
|
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.
|
|
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
|
}
|
|
@@ -4,8 +4,9 @@ import { workspaceKeys } from '@/client/api/workspace-keys'
|
|
|
4
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
|
+
import { formatChatTitle } from '@/lib/chat-title'
|
|
7
8
|
import { applyEvent, emptyViewState } from '@/lib/format'
|
|
8
|
-
import type { Part, ViewState, WorkspaceModels } from '@/lib/types'
|
|
9
|
+
import type { Part, SessionInfo, ViewState, WorkspaceModels } from '@/lib/types'
|
|
9
10
|
|
|
10
11
|
// What a caller may attach to one message beyond its text. All of it is
|
|
11
12
|
// envelope material — the agent sees it, the chat bubble does not.
|
|
@@ -62,6 +63,29 @@ export function startOptimisticTurn({
|
|
|
62
63
|
return optimisticId
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
type StartOptimisticSessionInput = {
|
|
67
|
+
queryClient: QueryClient
|
|
68
|
+
workspaceId: string
|
|
69
|
+
sessionId: string
|
|
70
|
+
text: string
|
|
71
|
+
filenames?: readonly string[]
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function startOptimisticSession({
|
|
75
|
+
queryClient,
|
|
76
|
+
workspaceId,
|
|
77
|
+
sessionId,
|
|
78
|
+
text,
|
|
79
|
+
filenames = []
|
|
80
|
+
}: StartOptimisticSessionInput): void {
|
|
81
|
+
const summary = formatChatTitle(text, filenames)
|
|
82
|
+
if (!summary) return
|
|
83
|
+
queryClient.setQueryData<SessionInfo[]>(workspaceKeys.sessions(workspaceId), current => [
|
|
84
|
+
{ sessionId, summary, lastModified: Date.now() },
|
|
85
|
+
...(current ?? []).filter(session => session.sessionId !== sessionId)
|
|
86
|
+
])
|
|
87
|
+
}
|
|
88
|
+
|
|
65
89
|
export function resolveChatRunOptions(
|
|
66
90
|
modelsData: WorkspaceModels | undefined,
|
|
67
91
|
pickedModel: string | undefined,
|