@standardagents/cli 0.41.21 → 0.41.26
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/chat/next/app/page.tsx +3 -4
- package/chat/package.json +9 -3
- package/chat/src/App.tsx +2 -1
- package/chat/src/components/Chat.tsx +17 -2
- package/chat/src/components/EmptyState.tsx +52 -86
- package/chat/src/components/Login.tsx +56 -3
- package/chat/src/components/Markdown.tsx +53 -26
- package/chat/src/components/MessageInput.tsx +11 -11
- package/chat/src/components/MessageList.tsx +245 -322
- package/chat/src/components/Sidebar.tsx +12 -8
- package/chat/src/hooks/useAuth.tsx +104 -54
- package/chat/src/hooks/useThreads.ts +57 -64
- package/chat/src/lib/api.ts +53 -0
- package/chat/src/lib/streamingMarkdown.test.ts +34 -0
- package/chat/src/lib/streamingMarkdown.ts +59 -0
- package/chat/vite/main.tsx +5 -6
- package/chat/vite/vite.config.ts +35 -20
- package/dist/index.js +48 -13
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/chat/src/components/AgentSelector.tsx +0 -102
|
@@ -2,55 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useRef, useMemo, useState, useCallback } from 'react'
|
|
4
4
|
import { createPortal } from 'react-dom'
|
|
5
|
-
import { useThread } from '@standardagents/react'
|
|
6
|
-
import type {
|
|
5
|
+
import { useThread, parseAttachments } from '@standardagents/react'
|
|
6
|
+
import type {
|
|
7
|
+
AttachmentRef,
|
|
8
|
+
GroupedThreadMessage,
|
|
9
|
+
Message,
|
|
10
|
+
StatusMessage,
|
|
11
|
+
SubagentBlockMessage,
|
|
12
|
+
SubagentGroupBlockMessage,
|
|
13
|
+
WorkMessage,
|
|
14
|
+
} from '@standardagents/react'
|
|
15
|
+
import { apiUrl } from '../lib/api'
|
|
7
16
|
import { Markdown } from './Markdown'
|
|
8
17
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const isVite = typeof import.meta !== 'undefined' && import.meta.env
|
|
12
|
-
const baseUrl = isVite
|
|
13
|
-
? (import.meta.env.VITE_AGENTBUILDER_URL || '')
|
|
14
|
-
: (process.env.NEXT_PUBLIC_AGENTBUILDER_URL || '')
|
|
15
|
-
|
|
16
|
-
// Token is stored in localStorage by auth flow
|
|
17
|
-
const token = typeof localStorage !== 'undefined'
|
|
18
|
-
? localStorage.getItem('agentbuilder_auth_token') || ''
|
|
19
|
-
: ''
|
|
20
|
-
|
|
21
|
-
return { baseUrl, token }
|
|
18
|
+
function isWorkMessage(msg: GroupedThreadMessage): msg is WorkMessage {
|
|
19
|
+
return 'type' in msg && msg.type === 'workblock'
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
id: string
|
|
27
|
-
type: 'file'
|
|
28
|
-
path: string
|
|
29
|
-
name: string
|
|
30
|
-
mimeType: string
|
|
31
|
-
size?: number
|
|
32
|
-
width?: number
|
|
33
|
-
height?: number
|
|
34
|
-
description?: string
|
|
35
|
-
localPreviewUrl?: string // Optimistic preview data URL for images
|
|
22
|
+
function isSubagentBlock(msg: GroupedThreadMessage): msg is SubagentBlockMessage {
|
|
23
|
+
return 'type' in msg && msg.type === 'subagent_block'
|
|
36
24
|
}
|
|
37
25
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
attachments?: Attachment[] | null
|
|
26
|
+
function isSubagentGroup(msg: GroupedThreadMessage): msg is SubagentGroupBlockMessage {
|
|
27
|
+
return 'type' in msg && msg.type === 'subagent_group_block'
|
|
41
28
|
}
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return 'type' in msg && msg.type === 'workblock'
|
|
30
|
+
function isStatusMessage(msg: GroupedThreadMessage): msg is StatusMessage {
|
|
31
|
+
return 'type' in msg && msg.type === 'status'
|
|
46
32
|
}
|
|
47
33
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const isVite = typeof import.meta !== 'undefined' && import.meta.env
|
|
51
|
-
return isVite
|
|
52
|
-
? (import.meta.env.VITE_AGENTBUILDER_URL || '')
|
|
53
|
-
: (process.env.NEXT_PUBLIC_AGENTBUILDER_URL || '')
|
|
34
|
+
function isChatMessage(msg: GroupedThreadMessage): msg is Message {
|
|
35
|
+
return !('type' in msg)
|
|
54
36
|
}
|
|
55
37
|
|
|
56
38
|
// Type for OpenAI-style multipart content
|
|
@@ -134,14 +116,6 @@ function parseMessageContent(content: string | null): { text: string | null; ima
|
|
|
134
116
|
}
|
|
135
117
|
|
|
136
118
|
// Icon components for workblocks
|
|
137
|
-
function ToolIcon({ className }: { className?: string }) {
|
|
138
|
-
return (
|
|
139
|
-
<svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={1.5}>
|
|
140
|
-
<path strokeLinecap="round" strokeLinejoin="round" d="M11.42 15.17L17.25 21A2.652 2.652 0 0021 17.25l-5.877-5.877M11.42 15.17l2.496-3.03c.317-.384.74-.626 1.208-.766M11.42 15.17l-4.655 5.653a2.548 2.548 0 11-3.586-3.586l6.837-5.63m5.108-.233c.55-.164 1.163-.188 1.743-.14a4.5 4.5 0 004.486-6.336l-3.276 3.277a3.004 3.004 0 01-2.25-2.25l3.276-3.276a4.5 4.5 0 00-6.336 4.486c.091 1.076-.071 2.264-.904 2.95l-.102.085m-1.745 1.437L5.909 7.5H4.5L2.25 3.75l1.5-1.5L7.5 4.5v1.409l4.26 4.26m-1.745 1.437l1.745-1.437m6.615 8.206L15.75 15.75M4.867 19.125h.008v.008h-.008v-.008z" />
|
|
141
|
-
</svg>
|
|
142
|
-
)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
119
|
function CheckIcon({ className }: { className?: string }) {
|
|
146
120
|
return (
|
|
147
121
|
<svg className={className} fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
|
@@ -187,27 +161,6 @@ function TrashIcon({ className }: { className?: string }) {
|
|
|
187
161
|
)
|
|
188
162
|
}
|
|
189
163
|
|
|
190
|
-
function RewindIcon({ className }: { className?: string }) {
|
|
191
|
-
return (
|
|
192
|
-
<svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
|
|
193
|
-
<path d="M1 4v6h6" />
|
|
194
|
-
<path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10" />
|
|
195
|
-
</svg>
|
|
196
|
-
)
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function BranchIcon({ className }: { className?: string }) {
|
|
200
|
-
return (
|
|
201
|
-
<svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2} strokeLinecap="round" strokeLinejoin="round">
|
|
202
|
-
<path d="M6 3v12" />
|
|
203
|
-
<circle cx="18" cy="6" r="3" />
|
|
204
|
-
<circle cx="6" cy="18" r="3" />
|
|
205
|
-
<path d="M18 9a9 9 0 0 1-9 9" />
|
|
206
|
-
</svg>
|
|
207
|
-
)
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Format tool name for display
|
|
211
164
|
function formatToolName(name: string | undefined): string {
|
|
212
165
|
if (!name) return 'Running tool'
|
|
213
166
|
// Convert snake_case or camelCase to Title Case
|
|
@@ -249,12 +202,17 @@ function ChevronIcon({ className, expanded }: { className?: string; expanded: bo
|
|
|
249
202
|
function Workblock({ workblock, isLast, threadLoading }: { workblock: WorkMessage; isLast?: boolean; threadLoading?: boolean }) {
|
|
250
203
|
const [isExpanded, setIsExpanded] = useState(false)
|
|
251
204
|
const { text } = parseMessageContent(workblock.content)
|
|
252
|
-
const isPending = workblock.status === 'pending'
|
|
253
205
|
|
|
254
206
|
// Group work items by tool_call_id to pair calls with results
|
|
255
207
|
const toolCalls = workblock.workItems.filter(item => item.type === 'tool_call')
|
|
256
208
|
const toolResults = workblock.workItems.filter(item => item.type === 'tool_result')
|
|
257
209
|
|
|
210
|
+
// The SDK marks a workblock completed once the assistant message carrying
|
|
211
|
+
// the tool calls is saved; a call without a result is still executing
|
|
212
|
+
// while the run is live.
|
|
213
|
+
const isPending = workblock.status === 'pending'
|
|
214
|
+
|| (!!threadLoading && toolCalls.some(item => item.status === 'pending'))
|
|
215
|
+
|
|
258
216
|
// Count completed vs total and check for errors
|
|
259
217
|
const completedCount = toolCalls.filter(item => item.status === 'success' || item.status === 'error').length
|
|
260
218
|
const errorCount = toolCalls.filter(item => item.status === 'error').length
|
|
@@ -367,7 +325,7 @@ function ImageAttachment({ url, name, width, height, onLoad }: { url: string; na
|
|
|
367
325
|
}
|
|
368
326
|
|
|
369
327
|
// File attachment component (for non-image files)
|
|
370
|
-
function FileAttachment({ name,
|
|
328
|
+
function FileAttachment({ name, url }: { name: string; url: string }) {
|
|
371
329
|
return (
|
|
372
330
|
<a
|
|
373
331
|
href={url}
|
|
@@ -383,31 +341,20 @@ function FileAttachment({ name, mimeType, url }: { name: string; mimeType: strin
|
|
|
383
341
|
)
|
|
384
342
|
}
|
|
385
343
|
|
|
386
|
-
//
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
if (attachment.localPreviewUrl)
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
// Otherwise use the server path
|
|
393
|
-
if (attachment.path) {
|
|
394
|
-
const endpoint = getApiEndpoint()
|
|
395
|
-
// Remove leading slash from path if present for clean join
|
|
396
|
-
const cleanPath = attachment.path.startsWith('/') ? attachment.path.slice(1) : attachment.path
|
|
397
|
-
return `${endpoint}/api/threads/${threadId}/fs/${cleanPath}`
|
|
398
|
-
}
|
|
399
|
-
// Fallback - shouldn't happen
|
|
400
|
-
return ''
|
|
344
|
+
// Optimistic previews come from the SDK; committed files are served from the
|
|
345
|
+
// thread filesystem (same-origin, so the session cookie authorizes the image).
|
|
346
|
+
function getAttachmentUrl(threadId: string, attachment: AttachmentRef): string {
|
|
347
|
+
if (attachment.localPreviewUrl) return attachment.localPreviewUrl
|
|
348
|
+
const cleanPath = attachment.path.replace(/^\/+/, '')
|
|
349
|
+
return apiUrl(`/api/threads/${threadId}/fs/${cleanPath}`)
|
|
401
350
|
}
|
|
402
351
|
|
|
403
|
-
|
|
404
|
-
function AttachmentList({ attachments, threadId, onImageLoad }: { attachments: Attachment[]; threadId: string; onImageLoad?: () => void }) {
|
|
352
|
+
function AttachmentList({ attachments, threadId, onImageLoad }: { attachments: AttachmentRef[]; threadId: string; onImageLoad?: () => void }) {
|
|
405
353
|
const imageAttachments = attachments.filter(a => a.mimeType.startsWith('image/'))
|
|
406
354
|
const otherAttachments = attachments.filter(a => !a.mimeType.startsWith('image/'))
|
|
407
355
|
|
|
408
356
|
return (
|
|
409
357
|
<div className="space-y-2">
|
|
410
|
-
{/* Image attachments */}
|
|
411
358
|
{imageAttachments.length > 0 && (
|
|
412
359
|
<div className="flex flex-wrap gap-2">
|
|
413
360
|
{imageAttachments.map((attachment) => (
|
|
@@ -423,14 +370,12 @@ function AttachmentList({ attachments, threadId, onImageLoad }: { attachments: A
|
|
|
423
370
|
</div>
|
|
424
371
|
)}
|
|
425
372
|
|
|
426
|
-
{/* Other file attachments */}
|
|
427
373
|
{otherAttachments.length > 0 && (
|
|
428
374
|
<div className="flex flex-wrap gap-2">
|
|
429
375
|
{otherAttachments.map((attachment) => (
|
|
430
376
|
<FileAttachment
|
|
431
377
|
key={attachment.id}
|
|
432
378
|
name={attachment.name}
|
|
433
|
-
mimeType={attachment.mimeType}
|
|
434
379
|
url={getAttachmentUrl(threadId, attachment)}
|
|
435
380
|
/>
|
|
436
381
|
))}
|
|
@@ -440,29 +385,12 @@ function AttachmentList({ attachments, threadId, onImageLoad }: { attachments: A
|
|
|
440
385
|
)
|
|
441
386
|
}
|
|
442
387
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
message: Message
|
|
446
|
-
threadId: string
|
|
447
|
-
allMessages: ThreadMessage[]
|
|
448
|
-
onBranchCreated?: (newThreadId: string) => void
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
function MessageActions({ message, threadId, allMessages, onBranchCreated }: MessageActionsProps) {
|
|
388
|
+
function MessageActions({ message }: { message: Message }) {
|
|
389
|
+
const { deleteMessage } = useThread()
|
|
452
390
|
const [copied, setCopied] = useState(false)
|
|
453
391
|
const [showDeleteWarning, setShowDeleteWarning] = useState(false)
|
|
454
|
-
const [showRewindWarning, setShowRewindWarning] = useState(false)
|
|
455
392
|
const [isDeleting, setIsDeleting] = useState(false)
|
|
456
|
-
const [isBranching, setIsBranching] = useState(false)
|
|
457
|
-
|
|
458
|
-
const { baseUrl, token } = getApiConfig()
|
|
459
|
-
const headers = useMemo(() => {
|
|
460
|
-
const h: Record<string, string> = { 'Content-Type': 'application/json' }
|
|
461
|
-
if (token) h['Authorization'] = `Bearer ${token}`
|
|
462
|
-
return h
|
|
463
|
-
}, [token])
|
|
464
393
|
|
|
465
|
-
// Copy message content to clipboard
|
|
466
394
|
const handleCopy = useCallback(async () => {
|
|
467
395
|
const { text } = parseMessageContent(message.content)
|
|
468
396
|
if (text) {
|
|
@@ -472,108 +400,24 @@ function MessageActions({ message, threadId, allMessages, onBranchCreated }: Mes
|
|
|
472
400
|
}
|
|
473
401
|
}, [message.content])
|
|
474
402
|
|
|
475
|
-
// Delete this message - show confirmation first
|
|
476
|
-
const handleDelete = useCallback(() => {
|
|
477
|
-
setShowDeleteWarning(true)
|
|
478
|
-
}, [])
|
|
479
|
-
|
|
480
403
|
const confirmDelete = useCallback(async () => {
|
|
481
404
|
setShowDeleteWarning(false)
|
|
482
405
|
setIsDeleting(true)
|
|
483
406
|
try {
|
|
484
|
-
//
|
|
485
|
-
|
|
486
|
-
method: 'DELETE',
|
|
487
|
-
headers,
|
|
488
|
-
})
|
|
489
|
-
if (!response.ok) {
|
|
490
|
-
// If that fails, the endpoint might not exist yet
|
|
491
|
-
console.error('Failed to delete message:', response.status, response.statusText)
|
|
492
|
-
alert('Delete functionality is not yet available.')
|
|
493
|
-
}
|
|
494
|
-
// The thread will auto-refresh via WebSocket
|
|
407
|
+
// The SDK removes the message locally; the live stream confirms it.
|
|
408
|
+
await deleteMessage(message.id)
|
|
495
409
|
} catch (error) {
|
|
496
410
|
console.error('Failed to delete message:', error)
|
|
497
|
-
alert('Delete functionality is not yet available.')
|
|
498
411
|
} finally {
|
|
499
412
|
setIsDeleting(false)
|
|
500
413
|
}
|
|
501
|
-
}, [
|
|
502
|
-
|
|
503
|
-
// Rewind thread to this point (stub - endpoint not implemented yet)
|
|
504
|
-
const handleRewind = useCallback(() => {
|
|
505
|
-
setShowRewindWarning(true)
|
|
506
|
-
}, [])
|
|
507
|
-
|
|
508
|
-
const confirmRewind = useCallback(() => {
|
|
509
|
-
// TODO: Implement when endpoint is available
|
|
510
|
-
console.warn('Rewind endpoint not yet implemented')
|
|
511
|
-
alert('Rewind functionality is not yet available. This feature will be implemented soon.')
|
|
512
|
-
setShowRewindWarning(false)
|
|
513
|
-
}, [])
|
|
514
|
-
|
|
515
|
-
// Branch: Create new thread with messages up to this point
|
|
516
|
-
const handleBranch = useCallback(async () => {
|
|
517
|
-
setIsBranching(true)
|
|
518
|
-
try {
|
|
519
|
-
// Get all messages up to and including this message
|
|
520
|
-
const messageIndex = allMessages.findIndex(m => 'id' in m && m.id === message.id)
|
|
521
|
-
if (messageIndex === -1) return
|
|
522
|
-
|
|
523
|
-
// Filter to only regular messages (not workblocks) up to this point
|
|
524
|
-
const messagesToCopy = allMessages
|
|
525
|
-
.slice(0, messageIndex + 1)
|
|
526
|
-
.filter((m): m is Message => !isWorkMessage(m) && m.role !== 'system' && m.role !== 'tool')
|
|
527
|
-
|
|
528
|
-
// Get the agent_id from the current thread
|
|
529
|
-
const threadResponse = await fetch(`${baseUrl}/api/threads/${threadId}`, { headers })
|
|
530
|
-
if (!threadResponse.ok) throw new Error('Failed to get thread info')
|
|
531
|
-
const threadData = await threadResponse.json()
|
|
532
|
-
|
|
533
|
-
// Create new thread
|
|
534
|
-
const createResponse = await fetch(`${baseUrl}/api/threads`, {
|
|
535
|
-
method: 'POST',
|
|
536
|
-
headers,
|
|
537
|
-
body: JSON.stringify({ agent_id: threadData.agent_id }),
|
|
538
|
-
})
|
|
539
|
-
if (!createResponse.ok) throw new Error('Failed to create new thread')
|
|
540
|
-
const newThread = await createResponse.json()
|
|
541
|
-
const newThreadId = newThread.threadId
|
|
542
|
-
|
|
543
|
-
// Copy messages to new thread
|
|
544
|
-
for (const msg of messagesToCopy) {
|
|
545
|
-
await fetch(`${baseUrl}/api/threads/${newThreadId}/messages`, {
|
|
546
|
-
method: 'POST',
|
|
547
|
-
headers,
|
|
548
|
-
body: JSON.stringify({
|
|
549
|
-
role: msg.role,
|
|
550
|
-
content: msg.content,
|
|
551
|
-
}),
|
|
552
|
-
})
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
// Navigate to new thread
|
|
556
|
-
if (onBranchCreated) {
|
|
557
|
-
onBranchCreated(newThreadId)
|
|
558
|
-
} else {
|
|
559
|
-
// Fallback: update URL
|
|
560
|
-
const url = new URL(window.location.href)
|
|
561
|
-
url.searchParams.set('thread', newThreadId)
|
|
562
|
-
window.location.href = url.toString()
|
|
563
|
-
}
|
|
564
|
-
} catch (error) {
|
|
565
|
-
console.error('Failed to branch thread:', error)
|
|
566
|
-
} finally {
|
|
567
|
-
setIsBranching(false)
|
|
568
|
-
}
|
|
569
|
-
}, [baseUrl, threadId, message.id, allMessages, headers, onBranchCreated])
|
|
414
|
+
}, [deleteMessage, message.id])
|
|
570
415
|
|
|
571
416
|
const iconClass = "w-[18px] h-[18px]"
|
|
572
417
|
const buttonClass = "p-1 text-[var(--text-muted)] hover:text-[var(--text-secondary)] transition-colors disabled:opacity-50"
|
|
573
418
|
|
|
574
419
|
return (
|
|
575
420
|
<div className="flex items-center gap-1 mt-2">
|
|
576
|
-
{/* Copy */}
|
|
577
421
|
<button
|
|
578
422
|
onClick={handleCopy}
|
|
579
423
|
className={buttonClass}
|
|
@@ -586,9 +430,8 @@ function MessageActions({ message, threadId, allMessages, onBranchCreated }: Mes
|
|
|
586
430
|
)}
|
|
587
431
|
</button>
|
|
588
432
|
|
|
589
|
-
{/* Delete */}
|
|
590
433
|
<button
|
|
591
|
-
onClick={
|
|
434
|
+
onClick={() => setShowDeleteWarning(true)}
|
|
592
435
|
disabled={isDeleting}
|
|
593
436
|
className={buttonClass}
|
|
594
437
|
title="Delete"
|
|
@@ -600,30 +443,6 @@ function MessageActions({ message, threadId, allMessages, onBranchCreated }: Mes
|
|
|
600
443
|
)}
|
|
601
444
|
</button>
|
|
602
445
|
|
|
603
|
-
{/* Rewind */}
|
|
604
|
-
<button
|
|
605
|
-
onClick={handleRewind}
|
|
606
|
-
className={buttonClass}
|
|
607
|
-
title="Rewind to here"
|
|
608
|
-
>
|
|
609
|
-
<RewindIcon className={iconClass} />
|
|
610
|
-
</button>
|
|
611
|
-
|
|
612
|
-
{/* Branch */}
|
|
613
|
-
<button
|
|
614
|
-
onClick={handleBranch}
|
|
615
|
-
disabled={isBranching}
|
|
616
|
-
className={buttonClass}
|
|
617
|
-
title="Branch from here"
|
|
618
|
-
>
|
|
619
|
-
{isBranching ? (
|
|
620
|
-
<SpinnerIcon className={iconClass} />
|
|
621
|
-
) : (
|
|
622
|
-
<BranchIcon className={iconClass} />
|
|
623
|
-
)}
|
|
624
|
-
</button>
|
|
625
|
-
|
|
626
|
-
{/* Delete confirmation dialog */}
|
|
627
446
|
{showDeleteWarning && createPortal(
|
|
628
447
|
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50">
|
|
629
448
|
<div className="bg-[var(--bg-elevated)] border border-[var(--border-primary)] rounded-xl p-4 max-w-sm mx-4 shadow-xl">
|
|
@@ -649,50 +468,18 @@ function MessageActions({ message, threadId, allMessages, onBranchCreated }: Mes
|
|
|
649
468
|
</div>,
|
|
650
469
|
document.body
|
|
651
470
|
)}
|
|
652
|
-
|
|
653
|
-
{/* Rewind confirmation dialog */}
|
|
654
|
-
{showRewindWarning && createPortal(
|
|
655
|
-
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50">
|
|
656
|
-
<div className="bg-[var(--bg-elevated)] border border-[var(--border-primary)] rounded-xl p-4 max-w-sm mx-4 shadow-xl">
|
|
657
|
-
<h3 className="text-[var(--text-primary)] font-medium mb-2">Rewind Thread</h3>
|
|
658
|
-
<p className="text-sm text-[var(--text-secondary)] mb-4">
|
|
659
|
-
This will remove all messages after this point. This action cannot be undone.
|
|
660
|
-
</p>
|
|
661
|
-
<div className="flex gap-2 justify-end">
|
|
662
|
-
<button
|
|
663
|
-
onClick={() => setShowRewindWarning(false)}
|
|
664
|
-
className="px-3 py-1.5 text-sm text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors"
|
|
665
|
-
>
|
|
666
|
-
Cancel
|
|
667
|
-
</button>
|
|
668
|
-
<button
|
|
669
|
-
onClick={confirmRewind}
|
|
670
|
-
className="px-3 py-1.5 text-sm bg-red-600 text-white rounded-lg hover:bg-red-500 transition-colors"
|
|
671
|
-
>
|
|
672
|
-
Rewind
|
|
673
|
-
</button>
|
|
674
|
-
</div>
|
|
675
|
-
</div>
|
|
676
|
-
</div>,
|
|
677
|
-
document.body
|
|
678
|
-
)}
|
|
679
471
|
</div>
|
|
680
472
|
)
|
|
681
473
|
}
|
|
682
474
|
|
|
683
|
-
|
|
684
|
-
function MessageBubble({ message, threadId, allMessages, onBranchCreated, onImageLoad }: { message: Message; threadId: string; allMessages: ThreadMessage[]; onBranchCreated?: (newThreadId: string) => void; onImageLoad?: () => void }) {
|
|
475
|
+
function MessageBubble({ message, threadId, onImageLoad }: { message: Message; threadId: string; onImageLoad?: () => void }) {
|
|
685
476
|
const isUser = message.role === 'user'
|
|
686
477
|
const { text, images: inlineImages } = parseMessageContent(message.content)
|
|
687
|
-
|
|
688
|
-
// Get attachments from the message (cast to extended type)
|
|
689
|
-
const rawAttachments = (message as MessageWithAttachments).attachments
|
|
690
|
-
const attachments = Array.isArray(rawAttachments) ? rawAttachments : []
|
|
478
|
+
const attachments = parseAttachments(message)
|
|
691
479
|
const hasAttachments = attachments.length > 0
|
|
692
480
|
|
|
693
481
|
return (
|
|
694
482
|
<div className={`animate-fade-in ${isUser ? 'flex flex-col items-end' : ''}`}>
|
|
695
|
-
{/* Attachments shown above message bubble for user messages */}
|
|
696
483
|
{isUser && hasAttachments && (
|
|
697
484
|
<div className="mb-2 max-w-[85%]">
|
|
698
485
|
<AttachmentList attachments={attachments} threadId={threadId} onImageLoad={onImageLoad} />
|
|
@@ -707,7 +494,6 @@ function MessageBubble({ message, threadId, allMessages, onBranchCreated, onImag
|
|
|
707
494
|
</div>
|
|
708
495
|
)}
|
|
709
496
|
|
|
710
|
-
{/* Inline images from content (fallback) */}
|
|
711
497
|
{inlineImages.length > 0 && (
|
|
712
498
|
<div className={`${text ? 'mt-2' : ''} space-y-2`}>
|
|
713
499
|
{inlineImages.map((url, index) => (
|
|
@@ -719,12 +505,11 @@ function MessageBubble({ message, threadId, allMessages, onBranchCreated, onImag
|
|
|
719
505
|
) : (
|
|
720
506
|
<div className="max-w-[85%] text-[var(--text-primary)]">
|
|
721
507
|
{text && (
|
|
722
|
-
<Markdown className="text-[15px] leading-relaxed">
|
|
508
|
+
<Markdown className="text-[15px] leading-relaxed" streaming={message.status === 'pending'}>
|
|
723
509
|
{text}
|
|
724
510
|
</Markdown>
|
|
725
511
|
)}
|
|
726
512
|
|
|
727
|
-
{/* Inline images from content (fallback) */}
|
|
728
513
|
{inlineImages.length > 0 && (
|
|
729
514
|
<div className={`${text ? 'mt-2' : ''} space-y-2`}>
|
|
730
515
|
{inlineImages.map((url, index) => (
|
|
@@ -733,30 +518,168 @@ function MessageBubble({ message, threadId, allMessages, onBranchCreated, onImag
|
|
|
733
518
|
</div>
|
|
734
519
|
)}
|
|
735
520
|
|
|
736
|
-
{/* Attachments shown below content for assistant messages */}
|
|
737
521
|
{hasAttachments && (
|
|
738
522
|
<div className="mt-2">
|
|
739
523
|
<AttachmentList attachments={attachments} threadId={threadId} onImageLoad={onImageLoad} />
|
|
740
524
|
</div>
|
|
741
525
|
)}
|
|
742
526
|
|
|
743
|
-
{
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
527
|
+
{message.status !== 'pending' && <MessageActions message={message} />}
|
|
528
|
+
</div>
|
|
529
|
+
)}
|
|
530
|
+
</div>
|
|
531
|
+
)
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Subagent registry status, read the way the builder UI reads it: no status
|
|
536
|
+
* yet means the child is still working; `idle`/`terminated` mean it settled.
|
|
537
|
+
*/
|
|
538
|
+
function subagentStatusLabel(status: string | null | undefined): { label: string; color: string; active: boolean } {
|
|
539
|
+
switch ((status || 'running').toLowerCase()) {
|
|
540
|
+
case 'pending':
|
|
541
|
+
case 'queued':
|
|
542
|
+
return { label: 'Queued', color: 'text-[var(--text-tertiary)]', active: true }
|
|
543
|
+
case 'awaiting_human':
|
|
544
|
+
return { label: 'Needs input', color: 'text-amber-500', active: false }
|
|
545
|
+
case 'failed':
|
|
546
|
+
case 'error':
|
|
547
|
+
return { label: 'Failed', color: 'text-red-500', active: false }
|
|
548
|
+
case 'idle':
|
|
549
|
+
case 'terminated':
|
|
550
|
+
return { label: 'Done', color: 'text-emerald-500', active: false }
|
|
551
|
+
default:
|
|
552
|
+
return { label: 'Running', color: 'text-violet-500', active: true }
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function subagentTitle(block: SubagentBlockMessage): string {
|
|
557
|
+
return block.subagent_thread_name
|
|
558
|
+
|| block.subagent_title
|
|
559
|
+
|| block.subagent_relationship
|
|
560
|
+
|| block.subagent_name
|
|
561
|
+
|| 'Subagent'
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// A subagent's conversation, collapsed into a card inside the parent thread.
|
|
565
|
+
function SubagentBlock({ block, threadId }: { block: SubagentBlockMessage; threadId: string }) {
|
|
566
|
+
const [isExpanded, setIsExpanded] = useState(false)
|
|
567
|
+
const { label, color, active } = subagentStatusLabel(block.subagent_status)
|
|
568
|
+
const visible = block.messages.filter(m => (m.role === 'user' || m.role === 'assistant') && m.content)
|
|
569
|
+
const lastText = [...visible].reverse().find(m => m.role === 'assistant')
|
|
570
|
+
const preview = lastText ? parseMessageContent(lastText.content).text : null
|
|
571
|
+
|
|
572
|
+
return (
|
|
573
|
+
<div className={`bg-[var(--bg-tertiary)] border border-[var(--border-primary)] rounded-xl overflow-hidden ${active ? 'workblock-shimmer' : ''}`}>
|
|
574
|
+
<button
|
|
575
|
+
onClick={() => setIsExpanded(!isExpanded)}
|
|
576
|
+
className="w-full px-3 py-2 bg-[var(--bg-hover)] flex items-center gap-2 hover:bg-[var(--bg-tertiary)] transition-colors text-left"
|
|
577
|
+
>
|
|
578
|
+
<ChevronIcon className="w-3.5 h-3.5 text-[var(--text-tertiary)] shrink-0" expanded={isExpanded} />
|
|
579
|
+
<span className="text-sm font-medium text-[var(--text-primary)] truncate">{subagentTitle(block)}</span>
|
|
580
|
+
<span className={`text-xs font-medium uppercase tracking-wide shrink-0 ${color}`}>{label}</span>
|
|
581
|
+
{active && <SpinnerIcon className="w-3 h-3 text-violet-500 shrink-0" />}
|
|
582
|
+
{!isExpanded && preview && (
|
|
583
|
+
<span className="ml-auto text-xs text-[var(--text-tertiary)] truncate max-w-[240px]">{preview}</span>
|
|
584
|
+
)}
|
|
585
|
+
</button>
|
|
586
|
+
{isExpanded && (
|
|
587
|
+
<div className="border-t border-[var(--border-primary)] bg-[var(--bg-secondary)] px-4 py-3 space-y-3 max-h-[420px] overflow-y-auto">
|
|
588
|
+
{block.subagent_description && (
|
|
589
|
+
<p className="text-xs text-[var(--text-tertiary)]">{block.subagent_description}</p>
|
|
751
590
|
)}
|
|
591
|
+
{visible.length === 0 ? (
|
|
592
|
+
<p className="text-sm text-[var(--text-muted)] italic">No messages yet</p>
|
|
593
|
+
) : visible.map(m => (
|
|
594
|
+
<div key={m.id} className="text-sm">
|
|
595
|
+
<div className="text-[10px] uppercase tracking-wide text-[var(--text-muted)] mb-0.5">
|
|
596
|
+
{m.silent ? 'Result' : m.role === 'user' ? 'Task' : 'Response'}
|
|
597
|
+
</div>
|
|
598
|
+
<Markdown className="text-[13px] leading-relaxed text-[var(--text-secondary)]">
|
|
599
|
+
{parseMessageContent(m.content).text || ''}
|
|
600
|
+
</Markdown>
|
|
601
|
+
{parseAttachments(m).length > 0 && (
|
|
602
|
+
<div className="mt-2">
|
|
603
|
+
<AttachmentList attachments={parseAttachments(m)} threadId={threadId} />
|
|
604
|
+
</div>
|
|
605
|
+
)}
|
|
606
|
+
</div>
|
|
607
|
+
))}
|
|
752
608
|
</div>
|
|
753
609
|
)}
|
|
610
|
+
</div>
|
|
611
|
+
)
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function SubagentGroup({ group, threadId }: { group: SubagentGroupBlockMessage; threadId: string }) {
|
|
615
|
+
const running = group.subagents.filter(b => subagentStatusLabel(b.subagent_status).active).length
|
|
616
|
+
return (
|
|
617
|
+
<div className="space-y-2">
|
|
618
|
+
<div className="text-xs text-[var(--text-tertiary)]">
|
|
619
|
+
{group.subagents.length} subagents{running > 0 ? ` · ${running} running` : ''}
|
|
620
|
+
</div>
|
|
621
|
+
{group.subagents.map(block => (
|
|
622
|
+
<SubagentBlock key={block.id} block={block} threadId={threadId} />
|
|
623
|
+
))}
|
|
624
|
+
</div>
|
|
625
|
+
)
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Files produced during the run (tool results such as generate_image, and
|
|
630
|
+
* silent runtime messages that carry an asset) belong in the conversation,
|
|
631
|
+
* not hidden inside a collapsed workblock. Each path is shown once, at its
|
|
632
|
+
* first appearance.
|
|
633
|
+
*/
|
|
634
|
+
function useSurfacedAttachments(messages: GroupedThreadMessage[]): Map<string, AttachmentRef[]> {
|
|
635
|
+
const { messages: rawMessages } = useThread()
|
|
636
|
+
return useMemo(() => {
|
|
637
|
+
const byToolCall = new Map<string, AttachmentRef[]>()
|
|
638
|
+
for (const m of rawMessages) {
|
|
639
|
+
if (m.role === 'tool' && m.tool_call_id) {
|
|
640
|
+
const refs = parseAttachments(m)
|
|
641
|
+
if (refs.length > 0) byToolCall.set(m.tool_call_id, refs)
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
const seen = new Set<string>()
|
|
646
|
+
const surfaced = new Map<string, AttachmentRef[]>()
|
|
647
|
+
const take = (id: string, refs: AttachmentRef[]) => {
|
|
648
|
+
const fresh = refs.filter(ref => !seen.has(ref.path))
|
|
649
|
+
fresh.forEach(ref => seen.add(ref.path))
|
|
650
|
+
if (fresh.length > 0) surfaced.set(id, fresh)
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
for (const msg of messages) {
|
|
654
|
+
if (isWorkMessage(msg)) {
|
|
655
|
+
take(msg.id, msg.workItems.flatMap(item =>
|
|
656
|
+
item.type === 'tool_result' && item.tool_call_id ? byToolCall.get(item.tool_call_id) ?? [] : []
|
|
657
|
+
))
|
|
658
|
+
} else if (isChatMessage(msg)) {
|
|
659
|
+
const refs = parseAttachments(msg)
|
|
660
|
+
if (msg.silent) {
|
|
661
|
+
take(msg.id, refs)
|
|
662
|
+
} else {
|
|
663
|
+
// Visible messages render their own attachments.
|
|
664
|
+
refs.forEach(ref => seen.add(ref.path))
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return surfaced
|
|
669
|
+
}, [messages, rawMessages])
|
|
670
|
+
}
|
|
754
671
|
|
|
672
|
+
// Runtime lifecycle markers (stops, subagent starts) — informational, not chat.
|
|
673
|
+
function StatusLine({ status }: { status: StatusMessage }) {
|
|
674
|
+
return (
|
|
675
|
+
<div className="flex items-center gap-3 text-xs text-[var(--text-muted)]">
|
|
676
|
+
<div className="h-px flex-1 bg-[var(--border-primary)]" />
|
|
677
|
+
<span className="shrink-0">{status.content}</span>
|
|
678
|
+
<div className="h-px flex-1 bg-[var(--border-primary)]" />
|
|
755
679
|
</div>
|
|
756
680
|
)
|
|
757
681
|
}
|
|
758
682
|
|
|
759
|
-
// Thinking indicator component
|
|
760
683
|
function ThinkingIndicator() {
|
|
761
684
|
return (
|
|
762
685
|
<div className="animate-fade-in">
|
|
@@ -768,8 +691,17 @@ function ThinkingIndicator() {
|
|
|
768
691
|
)
|
|
769
692
|
}
|
|
770
693
|
|
|
694
|
+
function RunFailed({ reason }: { reason?: string | null }) {
|
|
695
|
+
return (
|
|
696
|
+
<div className="px-4 py-3 rounded-xl border border-red-500/20 bg-red-500/10 text-sm text-red-400">
|
|
697
|
+
The agent stopped with an error{reason ? ` (${reason})` : ''}. Send another message to try again.
|
|
698
|
+
</div>
|
|
699
|
+
)
|
|
700
|
+
}
|
|
701
|
+
|
|
771
702
|
export function MessageList() {
|
|
772
|
-
const {
|
|
703
|
+
const { groupedMessages: messages, loading, threadId, runStatus } = useThread()
|
|
704
|
+
const surfacedAttachments = useSurfacedAttachments(messages)
|
|
773
705
|
const bottomRef = useRef<HTMLDivElement>(null)
|
|
774
706
|
|
|
775
707
|
const scrollToBottom = useCallback(() => {
|
|
@@ -778,42 +710,16 @@ export function MessageList() {
|
|
|
778
710
|
|
|
779
711
|
useEffect(() => {
|
|
780
712
|
scrollToBottom()
|
|
781
|
-
}, [messages,
|
|
713
|
+
}, [messages, runStatus, scrollToBottom])
|
|
782
714
|
|
|
783
|
-
//
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
|
|
715
|
+
// Run status is pushed by the runtime (snapshot on connect, then each change).
|
|
716
|
+
const isRunning = runStatus?.state === 'running'
|
|
717
|
+
const somethingStreaming = useMemo(() => messages.some(m =>
|
|
718
|
+
(isWorkMessage(m) && m.status === 'pending')
|
|
719
|
+
|| (isChatMessage(m) && m.role === 'assistant' && m.status === 'pending' && !!m.content)
|
|
720
|
+
), [messages])
|
|
787
721
|
|
|
788
|
-
|
|
789
|
-
const visibleMessages = messages.filter(msg => {
|
|
790
|
-
if (isWorkMessage(msg)) return true
|
|
791
|
-
return msg.role !== 'system' && msg.role !== 'tool'
|
|
792
|
-
})
|
|
793
|
-
|
|
794
|
-
if (visibleMessages.length === 0) return false
|
|
795
|
-
|
|
796
|
-
const lastMessage = visibleMessages[visibleMessages.length - 1]
|
|
797
|
-
|
|
798
|
-
// If last message is from user and we're loading, we're waiting for response
|
|
799
|
-
if (!isWorkMessage(lastMessage) && lastMessage.role === 'user' && loading) {
|
|
800
|
-
return true
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
// If last message is a pending workblock, we're still working
|
|
804
|
-
if (isWorkMessage(lastMessage) && lastMessage.status === 'pending') {
|
|
805
|
-
return true
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
// If last assistant message is pending
|
|
809
|
-
if (!isWorkMessage(lastMessage) && lastMessage.role === 'assistant' && lastMessage.status === 'pending') {
|
|
810
|
-
return true
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
return false
|
|
814
|
-
}, [messages, loading])
|
|
815
|
-
|
|
816
|
-
if (messages.length === 0 && !loading) {
|
|
722
|
+
if (messages.length === 0 && !loading && !isRunning) {
|
|
817
723
|
return (
|
|
818
724
|
<div className="flex-1 flex items-center justify-center">
|
|
819
725
|
<p className="text-[var(--text-muted)] text-sm">Send a message to start the conversation</p>
|
|
@@ -824,25 +730,42 @@ export function MessageList() {
|
|
|
824
730
|
return (
|
|
825
731
|
<div className="py-6 px-4 space-y-6">
|
|
826
732
|
{messages.map((msg, index) => {
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
}
|
|
733
|
+
const surfaced = surfacedAttachments.get(msg.id)
|
|
734
|
+
const surfacedList = surfaced && (
|
|
735
|
+
<div className="max-w-[85%] mt-3 animate-fade-in">
|
|
736
|
+
<AttachmentList attachments={surfaced} threadId={threadId} onImageLoad={scrollToBottom} />
|
|
737
|
+
</div>
|
|
738
|
+
)
|
|
739
|
+
if (isWorkMessage(msg)) {
|
|
740
|
+
return (
|
|
741
|
+
<div key={msg.id}>
|
|
742
|
+
<Workblock workblock={msg} isLast={index === messages.length - 1} threadLoading={isRunning} />
|
|
743
|
+
{surfacedList}
|
|
744
|
+
</div>
|
|
745
|
+
)
|
|
746
|
+
}
|
|
747
|
+
if (isSubagentBlock(msg)) {
|
|
748
|
+
return <div key={msg.id} className="animate-fade-in max-w-[85%]"><SubagentBlock block={msg} threadId={threadId} /></div>
|
|
749
|
+
}
|
|
750
|
+
if (isSubagentGroup(msg)) {
|
|
751
|
+
return <div key={msg.id} className="animate-fade-in max-w-[85%]"><SubagentGroup group={msg} threadId={threadId} /></div>
|
|
752
|
+
}
|
|
753
|
+
if (isStatusMessage(msg)) {
|
|
754
|
+
return <StatusLine key={msg.id} status={msg} />
|
|
755
|
+
}
|
|
756
|
+
// Silent messages stay hidden except for any files they carry.
|
|
757
|
+
if (msg.silent) {
|
|
758
|
+
return surfacedList ? <div key={msg.id}>{surfacedList}</div> : null
|
|
759
|
+
}
|
|
760
|
+
// Tool messages are shown in workblocks; system messages are not chat.
|
|
761
|
+
if (msg.role === 'system' || msg.role === 'tool') {
|
|
762
|
+
return null
|
|
763
|
+
}
|
|
764
|
+
return <MessageBubble key={msg.id} message={msg} threadId={threadId} onImageLoad={scrollToBottom} />
|
|
765
|
+
})}
|
|
841
766
|
|
|
842
|
-
{
|
|
843
|
-
{
|
|
844
|
-
<ThinkingIndicator />
|
|
845
|
-
)}
|
|
767
|
+
{isRunning && !somethingStreaming && <ThinkingIndicator />}
|
|
768
|
+
{runStatus?.state === 'failed' && <RunFailed reason={runStatus.reason} />}
|
|
846
769
|
|
|
847
770
|
<div ref={bottomRef} className="h-4" />
|
|
848
771
|
</div>
|