mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat: add sub-agent task rendering and improve task tool display
This commit is contained in:
1 parent
9c8811dbc7
commit
98c198e0e0
5 files changed
+655
-9
No files matched your search
@@ -341,7 +341,16 @@ describe('MessagePart', () => {
|
||||
sessionID: 'test-session',
|
||||
})
|
||||
|
||||
it('renders null for tool part when simpleChatMode is true', () => {
|
||||
const createSubtaskPart = (): MessagePartType => ({
|
||||
type: 'subtask',
|
||||
prompt: 'Please review this change',
|
||||
description: 'Review changes',
|
||||
agent: 'auditor',
|
||||
command: 'review',
|
||||
sessionID: 'test-session',
|
||||
})
|
||||
|
||||
it('renders null for non-task tool part when simpleChatMode is true', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: true,
|
||||
showReasoning: false,
|
||||
@@ -358,6 +367,78 @@ describe('MessagePart', () => {
|
||||
expect(container.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders a compact clickable task row when simpleChatMode is true', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: true,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
const part = {
|
||||
...createToolPart(),
|
||||
tool: 'task',
|
||||
callID: 'call-1',
|
||||
metadata: { sessionId: 'child-session' },
|
||||
state: {
|
||||
status: 'completed',
|
||||
input: { description: 'Review changes' },
|
||||
output: 'done',
|
||||
time: { start: Date.now(), end: Date.now() + 100 },
|
||||
},
|
||||
} as MessagePartType
|
||||
const onChildSessionClick = vi.fn()
|
||||
|
||||
render(<MessagePart part={part} onChildSessionClick={onChildSessionClick} />)
|
||||
|
||||
expect(screen.getByText('Review changes')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('View details')).not.toBeInTheDocument()
|
||||
fireEvent.click(screen.getByRole('button'))
|
||||
expect(onChildSessionClick).toHaveBeenCalledWith('child-session')
|
||||
})
|
||||
|
||||
it('renders a compact subtask row when simpleChatMode is true', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: true,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
render(<MessagePart part={createSubtaskPart()} />)
|
||||
|
||||
expect(screen.getByText('Review changes')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('auditor')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Please review this change')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders the same compact subtask row when simpleChatMode is false', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
expandToolCalls: false,
|
||||
expandDiffs: true,
|
||||
autoScroll: true,
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
})
|
||||
|
||||
render(<MessagePart part={createSubtaskPart()} />)
|
||||
|
||||
expect(screen.getByText('Review changes')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Sub-agent: auditor')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Please review this change')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders null for patch part when simpleChatMode is true', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: true,
|
||||
|
||||
@@ -43,6 +43,8 @@ function getCopyableContent(part: Part, allParts?: Part[]): string {
|
||||
return part.snapshot || ''
|
||||
case 'agent':
|
||||
return `Agent: ${part.name}`
|
||||
case 'subtask':
|
||||
return `${part.agent}: ${part.description}\n\n${part.prompt}`.trim()
|
||||
case 'step-finish':
|
||||
if (allParts) {
|
||||
return allParts
|
||||
@@ -120,7 +122,7 @@ export const MessagePart = memo(function MessagePart({ part, role, allParts, par
|
||||
if (simpleChatMode) return null
|
||||
return <PatchPart part={part} onFileClick={onFileClick} />
|
||||
case 'tool':
|
||||
if (simpleChatMode) return null
|
||||
if (simpleChatMode && part.tool !== 'task') return null
|
||||
return <ToolCallPart part={part} onFileClick={onFileClick} onChildSessionClick={onChildSessionClick} />
|
||||
case 'reasoning':
|
||||
if (simpleChatMode || !showReasoning) return null
|
||||
@@ -171,7 +173,21 @@ export const MessagePart = memo(function MessagePart({ part, role, allParts, par
|
||||
)
|
||||
case 'retry':
|
||||
return <RetryPart part={part as RetryPartType} />
|
||||
case 'subtask': {
|
||||
const label = part.description || part.prompt || 'Sub-agent task'
|
||||
return (
|
||||
<div className="my-1 w-full rounded border border-purple-500/20 bg-purple-500/5 px-2 py-1 text-left text-xs text-muted-foreground">
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
<span className="truncate">{label}</span>
|
||||
<span className="ml-auto shrink-0 text-[11px] text-muted-foreground">sub-agent</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
case 'step-start':
|
||||
case 'compaction':
|
||||
return null
|
||||
default:
|
||||
return
|
||||
return null
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,400 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { MessageThread } from './MessageThread'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
useSessionStatus: vi.fn(),
|
||||
useSessionTodos: vi.fn(),
|
||||
useSettings: vi.fn(),
|
||||
usePermissions: vi.fn(),
|
||||
useQuestions: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/stores/sessionStatusStore', () => ({
|
||||
useSessionStatusForSession: () => mocks.useSessionStatus(),
|
||||
}))
|
||||
|
||||
vi.mock('@/stores/sessionTodosStore', () => ({
|
||||
useSessionTodos: mocks.useSessionTodos,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSettings', () => ({
|
||||
useSettings: mocks.useSettings,
|
||||
}))
|
||||
|
||||
vi.mock('@/contexts/EventContext', () => ({
|
||||
usePermissions: () => mocks.usePermissions(),
|
||||
useQuestions: () => mocks.useQuestions(),
|
||||
}))
|
||||
|
||||
interface MockSettingsReturn {
|
||||
preferences: {
|
||||
simpleChatMode: boolean
|
||||
showReasoning: boolean
|
||||
} | undefined
|
||||
}
|
||||
|
||||
const setupSettings = (preferences: MockSettingsReturn['preferences']) => {
|
||||
mocks.useSettings.mockReturnValue({
|
||||
preferences,
|
||||
isLoading: false,
|
||||
updateSettings: vi.fn(),
|
||||
isUpdating: false,
|
||||
})
|
||||
}
|
||||
|
||||
const createTextPart = (text: string, messageId: string) => ({
|
||||
type: 'text' as const,
|
||||
text,
|
||||
sessionID: 'test-session',
|
||||
messageID: messageId,
|
||||
id: 'part-1',
|
||||
})
|
||||
|
||||
const createTaskToolPart = (description: string, sessionId: string | undefined, messageId: string) => ({
|
||||
type: 'tool' as const,
|
||||
tool: 'task',
|
||||
sessionID: 'test-session',
|
||||
messageID: messageId,
|
||||
id: 'part-2',
|
||||
callID: 'call-1',
|
||||
metadata: sessionId ? { sessionId } : undefined,
|
||||
state: {
|
||||
status: 'completed' as const,
|
||||
input: { description },
|
||||
output: 'done',
|
||||
title: 'Task',
|
||||
metadata: {},
|
||||
time: { start: Date.now(), end: Date.now() + 100 },
|
||||
},
|
||||
})
|
||||
|
||||
const createSubtaskPart = (description: string, messageId: string) => ({
|
||||
type: 'subtask' as const,
|
||||
prompt: 'Please review this',
|
||||
description,
|
||||
agent: 'reviewer',
|
||||
sessionID: 'test-session',
|
||||
messageID: messageId,
|
||||
id: 'part-3',
|
||||
})
|
||||
|
||||
const createStepFinishPart = (messageId: string) => ({
|
||||
type: 'step-finish' as const,
|
||||
sessionID: 'test-session',
|
||||
messageID: messageId,
|
||||
id: 'part-4',
|
||||
reason: 'stop',
|
||||
cost: 0,
|
||||
tokens: {
|
||||
input: 0,
|
||||
output: 0,
|
||||
reasoning: 0,
|
||||
cache: { read: 0, write: 0 },
|
||||
},
|
||||
})
|
||||
|
||||
const createReasoningPart = (text: string, messageId: string) => ({
|
||||
type: 'reasoning' as const,
|
||||
text,
|
||||
sessionID: 'test-session',
|
||||
messageID: messageId,
|
||||
id: 'part-5',
|
||||
})
|
||||
|
||||
const createAssistantMessage = (
|
||||
id: string,
|
||||
parts: unknown[],
|
||||
modelID?: string
|
||||
) => ({
|
||||
info: {
|
||||
id,
|
||||
role: 'assistant' as const,
|
||||
sessionID: 'test-session',
|
||||
parentID: 'parent-1',
|
||||
providerID: 'test-provider',
|
||||
mode: 'build',
|
||||
time: {
|
||||
created: Date.now(),
|
||||
completed: Date.now() + 100,
|
||||
},
|
||||
modelID: modelID || 'test-model',
|
||||
},
|
||||
parts,
|
||||
})
|
||||
|
||||
const createUserMessage = (id: string, text: string) => ({
|
||||
info: {
|
||||
id,
|
||||
role: 'user' as const,
|
||||
sessionID: 'test-session',
|
||||
agent: 'test-agent',
|
||||
model: 'test-model',
|
||||
time: {
|
||||
created: Date.now(),
|
||||
},
|
||||
},
|
||||
parts: [createTextPart(text, id)],
|
||||
})
|
||||
|
||||
describe('MessageThread', () => {
|
||||
beforeEach(() => {
|
||||
mocks.useSessionStatus.mockReturnValue({ type: 'idle' })
|
||||
mocks.useSessionTodos.mockReturnValue({ setTodos: vi.fn() })
|
||||
mocks.usePermissions.mockReturnValue({
|
||||
getForCallID: vi.fn(() => null),
|
||||
})
|
||||
mocks.useQuestions.mockReturnValue({
|
||||
getForCallID: vi.fn(() => null),
|
||||
})
|
||||
})
|
||||
|
||||
it('renders assistant message with only subtask part as standalone row without header', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
})
|
||||
|
||||
const messages = [
|
||||
createUserMessage('1', 'Hello'),
|
||||
createAssistantMessage('2', [createSubtaskPart('Review changes', '2')]),
|
||||
]
|
||||
|
||||
const onChildSessionClick = vi.fn()
|
||||
|
||||
render(
|
||||
<MessageThread
|
||||
opcodeUrl="http://localhost:5551"
|
||||
sessionID="test-session"
|
||||
messages={messages as any}
|
||||
onChildSessionClick={onChildSessionClick}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText('Review changes')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('test-model')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders assistant message with only task tool part as standalone row without header', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
})
|
||||
|
||||
const messages = [
|
||||
createUserMessage('1', 'Hello'),
|
||||
createAssistantMessage('2', [createTaskToolPart('Do something', 'child-session', '2')]),
|
||||
]
|
||||
|
||||
const onChildSessionClick = vi.fn()
|
||||
|
||||
const { container } = render(
|
||||
<MessageThread
|
||||
opcodeUrl="http://localhost:5551"
|
||||
sessionID="test-session"
|
||||
messages={messages as any}
|
||||
onChildSessionClick={onChildSessionClick}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText('Do something')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('test-model')).not.toBeInTheDocument()
|
||||
|
||||
const buttons = container.querySelectorAll('button')
|
||||
expect(buttons.length).toBeGreaterThan(0)
|
||||
fireEvent.click(buttons[buttons.length - 1])
|
||||
expect(onChildSessionClick).toHaveBeenCalledWith('child-session')
|
||||
})
|
||||
|
||||
it('renders assistant task message with empty text and step finish as standalone row', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
})
|
||||
|
||||
const messages = [
|
||||
createUserMessage('1', 'Hello'),
|
||||
createAssistantMessage('2', [
|
||||
createTextPart(' ', '2'),
|
||||
createTaskToolPart('Explore codebase structure', 'child-session', '2'),
|
||||
createStepFinishPart('2'),
|
||||
]),
|
||||
]
|
||||
|
||||
render(
|
||||
<MessageThread
|
||||
opcodeUrl="http://localhost:5551"
|
||||
sessionID="test-session"
|
||||
messages={messages as any}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText('Explore codebase structure')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('test-model')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders assistant task message with hidden reasoning as standalone row', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
})
|
||||
|
||||
const messages = [
|
||||
createUserMessage('1', 'Hello'),
|
||||
createAssistantMessage('2', [
|
||||
createReasoningPart('I should use the explore agent', '2'),
|
||||
createTextPart('\n\n', '2'),
|
||||
createTaskToolPart('Explore codebase structure', 'child-session', '2'),
|
||||
createStepFinishPart('2'),
|
||||
]),
|
||||
]
|
||||
|
||||
render(
|
||||
<MessageThread
|
||||
opcodeUrl="http://localhost:5551"
|
||||
sessionID="test-session"
|
||||
messages={messages as any}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText('Explore codebase structure')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('test-model')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('I should use the explore agent')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders assistant task message with simple-chat reasoning setting as standalone row', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: true,
|
||||
showReasoning: true,
|
||||
})
|
||||
|
||||
const messages = [
|
||||
createUserMessage('1', 'Hello'),
|
||||
createAssistantMessage('2', [
|
||||
createReasoningPart('I should use the explore agent', '2'),
|
||||
createTextPart('\n\n', '2'),
|
||||
createTaskToolPart('Explore codebase structure', 'child-session', '2'),
|
||||
createStepFinishPart('2'),
|
||||
]),
|
||||
]
|
||||
|
||||
render(
|
||||
<MessageThread
|
||||
opcodeUrl="http://localhost:5551"
|
||||
sessionID="test-session"
|
||||
messages={messages as any}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText('Explore codebase structure')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('test-model')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('I should use the explore agent')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders assistant task message with visible reasoning as standalone row when no text exists', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: true,
|
||||
})
|
||||
|
||||
const messages = [
|
||||
createUserMessage('1', 'Hello'),
|
||||
createAssistantMessage('2', [
|
||||
createReasoningPart('I should use the explore agent', '2'),
|
||||
createTextPart('\n\n', '2'),
|
||||
createTaskToolPart('Explore codebase structure', 'child-session', '2'),
|
||||
createStepFinishPart('2'),
|
||||
]),
|
||||
]
|
||||
|
||||
render(
|
||||
<MessageThread
|
||||
opcodeUrl="http://localhost:5551"
|
||||
sessionID="test-session"
|
||||
messages={messages as any}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText('Explore codebase structure')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('I should use the explore agent')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('test-model')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders assistant message with text normally with header', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
})
|
||||
|
||||
const messages = [
|
||||
createUserMessage('1', 'Hello'),
|
||||
createAssistantMessage('2', [createTextPart('This is a response', '2')]),
|
||||
]
|
||||
|
||||
render(
|
||||
<MessageThread
|
||||
opcodeUrl="http://localhost:5551"
|
||||
sessionID="test-session"
|
||||
messages={messages as any}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText('This is a response')).toBeInTheDocument()
|
||||
expect(screen.getByText('test-model')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders assistant message with text and subtask normally with header', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
})
|
||||
|
||||
const messages = [
|
||||
createUserMessage('1', 'Hello'),
|
||||
createAssistantMessage('2', [
|
||||
createTextPart('Here is the analysis', '2'),
|
||||
createSubtaskPart('Review changes', '2'),
|
||||
]),
|
||||
]
|
||||
|
||||
render(
|
||||
<MessageThread
|
||||
opcodeUrl="http://localhost:5551"
|
||||
sessionID="test-session"
|
||||
messages={messages as any}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText('Here is the analysis')).toBeInTheDocument()
|
||||
expect(screen.getByText('Review changes')).toBeInTheDocument()
|
||||
expect(screen.getByText('test-model')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders user messages normally', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
})
|
||||
|
||||
const messages = [
|
||||
createUserMessage('1', 'Hello'),
|
||||
]
|
||||
|
||||
render(
|
||||
<MessageThread
|
||||
opcodeUrl="http://localhost:5551"
|
||||
sessionID="test-session"
|
||||
messages={messages as any}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText('Hello')).toBeInTheDocument()
|
||||
expect(screen.getByText('You')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -47,6 +47,78 @@ const compareMessageIds = (id1: string, id2: string): number => {
|
||||
return id1.localeCompare(id2)
|
||||
}
|
||||
|
||||
const hasRenderableContent = (role: Message['role'], parts: Part[], simpleChatMode: boolean, showReasoning: boolean): boolean => {
|
||||
if (!parts || parts.length === 0) return false
|
||||
|
||||
return parts.some(part => {
|
||||
switch (part.type) {
|
||||
case 'text':
|
||||
return !!(part.text && part.text.trim())
|
||||
case 'reasoning':
|
||||
return !simpleChatMode && showReasoning && !!(part.text && part.text.trim())
|
||||
case 'file':
|
||||
return role === 'user'
|
||||
case 'patch':
|
||||
case 'snapshot':
|
||||
case 'agent':
|
||||
return !simpleChatMode
|
||||
case 'tool':
|
||||
return !simpleChatMode || part.tool === 'task'
|
||||
case 'retry':
|
||||
return true
|
||||
case 'step-finish':
|
||||
case 'step-start':
|
||||
case 'compaction':
|
||||
return false
|
||||
case 'subtask':
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function isTaskToolPart(part: Part): part is components['schemas']['ToolPart'] {
|
||||
return part.type === 'tool' && part.tool === 'task'
|
||||
}
|
||||
|
||||
function isSubAgentActivityPart(part: Part): boolean {
|
||||
return part.type === 'subtask' || isTaskToolPart(part)
|
||||
}
|
||||
|
||||
function hasTextContent(parts: Part[]): boolean {
|
||||
return parts.some(p => p.type === 'text' && !!(p.text && p.text.trim()))
|
||||
}
|
||||
|
||||
function isIgnorableSubAgentMessagePart(part: Part): boolean {
|
||||
if (part.type === 'step-start' || part.type === 'step-finish' || part.type === 'compaction') {
|
||||
return true
|
||||
}
|
||||
if (part.type === 'text') {
|
||||
return !part.text?.trim()
|
||||
}
|
||||
if (part.type === 'reasoning') {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
function isStandaloneSubAgentMessage(role: Message['role'], parts: Part[]): boolean {
|
||||
if (role !== 'assistant') return false
|
||||
if (parts.length === 0) return false
|
||||
if (hasTextContent(parts)) return false
|
||||
|
||||
const hasSubAgentActivity = parts.some(isSubAgentActivityPart)
|
||||
const allPartsAreSubAgentOrStructural = parts.every(part => {
|
||||
if (isIgnorableSubAgentMessagePart(part)) {
|
||||
return true
|
||||
}
|
||||
return isSubAgentActivityPart(part)
|
||||
})
|
||||
|
||||
return hasSubAgentActivity && allPartsAreSubAgentOrStructural
|
||||
}
|
||||
|
||||
const findLastMessageByRole = (
|
||||
messages: MessageWithParts[],
|
||||
role: 'user' | 'assistant',
|
||||
@@ -80,6 +152,7 @@ interface MessageRowProps {
|
||||
handleCancelEdit: () => void
|
||||
model?: string
|
||||
simpleChatMode: boolean
|
||||
showReasoning: boolean
|
||||
}
|
||||
|
||||
const MessageRow = memo(function MessageRow({
|
||||
@@ -101,6 +174,7 @@ const MessageRow = memo(function MessageRow({
|
||||
handleCancelEdit,
|
||||
model,
|
||||
simpleChatMode,
|
||||
showReasoning,
|
||||
}: MessageRowProps) {
|
||||
const msg = msgWithParts.info
|
||||
const parts = msgWithParts.parts
|
||||
@@ -117,6 +191,39 @@ const MessageRow = memo(function MessageRow({
|
||||
|
||||
const isEditingThisMessage = editingUserMessageId === msg.id
|
||||
|
||||
const hasContent = hasRenderableContent(msg.role, parts, simpleChatMode, showReasoning)
|
||||
const hasError = msg.role === 'assistant' && 'error' in msg && msg.error
|
||||
const standaloneSubAgentMessage = isStandaloneSubAgentMessage(msg.role, parts)
|
||||
|
||||
if (!hasContent && !hasError) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (standaloneSubAgentMessage) {
|
||||
return (
|
||||
<div
|
||||
key={msg.id}
|
||||
className="flex flex-col group"
|
||||
>
|
||||
<div className="space-y-1">
|
||||
{parts.filter(isSubAgentActivityPart).map((part, partIndex) => (
|
||||
<div key={`${msg.id}-${part.id}-${partIndex}`}>
|
||||
<MessagePart
|
||||
part={part}
|
||||
role={msg.role}
|
||||
allParts={parts}
|
||||
partIndex={partIndex}
|
||||
onFileClick={onFileClick}
|
||||
onChildSessionClick={onChildSessionClick}
|
||||
messageTextContent={messageTextContent}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
key={msg.id}
|
||||
@@ -209,7 +316,7 @@ const MessageRow = memo(function MessageRow({
|
||||
</div>
|
||||
))
|
||||
) : null}
|
||||
{msg.role === 'assistant' && 'error' in msg && msg.error && (
|
||||
{hasError && (
|
||||
<MessageError error={msg.error as OpenCodeError} />
|
||||
)}
|
||||
</div>
|
||||
@@ -233,6 +340,7 @@ export const MessageThread = memo(function MessageThread({
|
||||
const sessionStatus = useSessionStatusForSession(sessionID)
|
||||
const { preferences } = useSettings()
|
||||
const simpleChatMode = preferences?.simpleChatMode ?? false
|
||||
const showReasoning = preferences?.showReasoning ?? false
|
||||
|
||||
const pendingAssistantId = useMemo(() => {
|
||||
if (!messages) return undefined
|
||||
@@ -328,6 +436,7 @@ export const MessageThread = memo(function MessageThread({
|
||||
handleCancelEdit={handleCancelEdit}
|
||||
model={model}
|
||||
simpleChatMode={simpleChatMode}
|
||||
showReasoning={showReasoning}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -14,6 +14,15 @@ interface ToolCallPartProps {
|
||||
part: ToolPart
|
||||
onFileClick?: (filePath: string, lineNumber?: number) => void
|
||||
onChildSessionClick?: (sessionId: string) => void
|
||||
simpleChatMode?: boolean
|
||||
}
|
||||
|
||||
function getTaskSessionId(part: ToolPart): string | undefined {
|
||||
let sessionId = part.metadata?.sessionId as string | undefined
|
||||
if (!sessionId && part.state.status !== 'pending' && 'metadata' in part.state) {
|
||||
sessionId = part.state.metadata?.sessionId as string | undefined
|
||||
}
|
||||
return sessionId
|
||||
}
|
||||
|
||||
function ClickableJson({ json, onFileClick }: { json: unknown; onFileClick?: (filePath: string) => void }) {
|
||||
@@ -142,6 +151,40 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
const previewText = getPreviewText()
|
||||
const isFileTool = ['read', 'write', 'edit'].includes(part.tool)
|
||||
|
||||
if (part.tool === 'task') {
|
||||
const sessionId = getTaskSessionId(part)
|
||||
const description = previewText || 'Sub-agent task'
|
||||
const isRunning = part.state.status === 'running' || part.state.status === 'pending'
|
||||
const content = (
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
{isRunning ? (
|
||||
<Loader2 className="w-3.5 h-3.5 animate-spin text-purple-600 dark:text-purple-400" />
|
||||
) : null}
|
||||
<span className="font-medium text-foreground truncate">{description}</span>
|
||||
<span className="text-[11px] text-muted-foreground ml-auto shrink-0">sub-agent</span>
|
||||
{sessionId && <ExternalLink className="w-3 h-3 shrink-0 text-purple-600 dark:text-purple-400" />}
|
||||
</div>
|
||||
)
|
||||
|
||||
if (sessionId) {
|
||||
return (
|
||||
<button
|
||||
onClick={() => onChildSessionClick?.(sessionId)}
|
||||
className="my-1 w-full rounded border border-purple-500/20 bg-purple-500/5 px-2 py-1 text-left text-xs text-muted-foreground hover:bg-purple-500/10 transition-colors"
|
||||
title="View subagent session"
|
||||
>
|
||||
{content}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="my-1 rounded border border-purple-500/20 bg-purple-500/5 px-2 py-1 text-xs text-muted-foreground">
|
||||
{content}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isTodoTool) {
|
||||
if (part.state.status === 'pending') {
|
||||
return (
|
||||
@@ -254,10 +297,7 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
) : null}
|
||||
|
||||
{part.tool === 'task' && (() => {
|
||||
let sessionId: string | undefined = part.metadata?.sessionId as string | undefined
|
||||
if (!sessionId && part.state.status !== 'pending' && 'metadata' in part.state) {
|
||||
sessionId = part.state.metadata?.sessionId as string | undefined
|
||||
}
|
||||
const sessionId = getTaskSessionId(part)
|
||||
return sessionId ? (
|
||||
<span
|
||||
onClick={(e) => {
|
||||
@@ -372,4 +412,4 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user