mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
refactor(frontend): streamline session tool cards
This commit is contained in:
1 parent
3eaa9a2480
commit
28e5a71953
5 files changed
+184
-94
No files matched your search
@@ -53,6 +53,11 @@ export function getRelativePath(filePath: string): string {
|
||||
return filePath
|
||||
}
|
||||
|
||||
function getFileName(filePath: string): string {
|
||||
const normalizedPath = filePath.replace(/\/+$/, '')
|
||||
return normalizedPath.split('/').pop() || filePath
|
||||
}
|
||||
|
||||
interface FileToolRenderProps {
|
||||
part: ToolPart
|
||||
filediff?: FileDiffData
|
||||
@@ -60,14 +65,17 @@ interface FileToolRenderProps {
|
||||
content?: string
|
||||
toolName: string
|
||||
onFileClick?: (filePath: string, lineNumber?: number) => void
|
||||
messageMeta?: {
|
||||
model: string
|
||||
time?: number
|
||||
}
|
||||
}
|
||||
|
||||
export function FileToolRender({ part, filediff, filePath, content, toolName, onFileClick }: FileToolRenderProps) {
|
||||
export function FileToolRender({ part, filediff, filePath, content, toolName, onFileClick, messageMeta }: FileToolRenderProps) {
|
||||
const { preferences } = useSettings()
|
||||
const isReadTool = toolName === 'Read'
|
||||
const isEditTool = toolName === 'Edit'
|
||||
const isWriteTool = toolName === 'Write'
|
||||
const hasExpandableContent = !isReadTool && (filediff || content)
|
||||
const hasExpandableContent = Boolean(filediff || content)
|
||||
|
||||
const isFileMutatingTool = isEditTool || isWriteTool
|
||||
const defaultExpanded = isFileMutatingTool
|
||||
@@ -90,29 +98,38 @@ export function FileToolRender({ part, filediff, filePath, content, toolName, on
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="border border-border rounded-lg overflow-hidden my-2">
|
||||
<div className="border border-orange-500/20 rounded-lg overflow-hidden my-2 bg-orange-500/5">
|
||||
<button
|
||||
onClick={() => hasExpandableContent && setExpanded(!expanded)}
|
||||
className="w-full px-3 py-1.5 bg-card hover:bg-card-hover text-left flex items-center justify-between text-sm gap-2"
|
||||
className="w-full px-3 py-2 hover:bg-orange-500/10 text-left text-sm transition-colors"
|
||||
>
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
<span className="text-green-600 dark:text-green-400 flex-shrink-0">✓</span>
|
||||
<span className="font-medium flex-shrink-0">{toolName}</span>
|
||||
{filePath && (
|
||||
<span
|
||||
onClick={handleFileClick}
|
||||
className="text-blue-600 dark:text-blue-400 text-xs truncate hover:underline cursor-pointer"
|
||||
>
|
||||
{getRelativePath(filePath)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 flex-shrink-0">
|
||||
{filediff && <DiffStats additions={filediff.additions} deletions={filediff.deletions} />}
|
||||
<span className="text-muted-foreground text-xs">{getDuration()}</span>
|
||||
{hasExpandableContent && (
|
||||
expanded ? <ChevronUp className="w-4 h-4 text-muted-foreground" /> : <ChevronDown className="w-4 h-4 text-muted-foreground" />
|
||||
)}
|
||||
{messageMeta && (
|
||||
<div className="mb-1 flex items-center gap-2 text-[11px] text-muted-foreground">
|
||||
<span className="font-medium">{messageMeta.model}</span>
|
||||
{messageMeta.time && <span>{new Date(messageMeta.time).toLocaleTimeString()}</span>}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
<span className="text-orange-600 dark:text-orange-400 flex-shrink-0">✓</span>
|
||||
<span className="font-medium flex-shrink-0">{toolName}</span>
|
||||
{filePath && (
|
||||
<span
|
||||
onClick={handleFileClick}
|
||||
className="text-orange-600 dark:text-orange-400 text-xs truncate hover:underline cursor-pointer"
|
||||
title={getRelativePath(filePath)}
|
||||
>
|
||||
{getFileName(filePath)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 flex-shrink-0">
|
||||
{filediff && <DiffStats additions={filediff.additions} deletions={filediff.deletions} />}
|
||||
<span className="text-muted-foreground text-xs">{getDuration()}</span>
|
||||
{hasExpandableContent && (
|
||||
expanded ? <ChevronUp className="w-4 h-4 text-muted-foreground" /> : <ChevronDown className="w-4 h-4 text-muted-foreground" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
@@ -126,14 +143,14 @@ export function FileToolRender({ part, filediff, filePath, content, toolName, on
|
||||
)
|
||||
}
|
||||
|
||||
export function getToolSpecificRender(part: ToolPart, onFileClick?: (filePath: string) => void): React.ReactElement | null {
|
||||
export function getToolSpecificRender(part: ToolPart, onFileClick?: (filePath: string) => void, messageMeta?: FileToolRenderProps['messageMeta']): React.ReactElement | null {
|
||||
if (part.state.status !== 'completed') return null
|
||||
|
||||
if (part.tool === 'edit') {
|
||||
const filediff = part.state.metadata?.filediff
|
||||
const filePath = part.state.input?.filePath as string | undefined
|
||||
if (filediff && isFileDiff(filediff)) {
|
||||
return <FileToolRender part={part} filediff={filediff} filePath={filePath} toolName="Edit" onFileClick={onFileClick} />
|
||||
return <FileToolRender part={part} filediff={filediff} filePath={filePath} toolName="Edit" onFileClick={onFileClick} messageMeta={messageMeta} />
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,16 +158,16 @@ export function getToolSpecificRender(part: ToolPart, onFileClick?: (filePath: s
|
||||
const filePath = part.state.input?.filePath as string | undefined
|
||||
const content = part.state.input?.content as string | undefined
|
||||
if (filePath) {
|
||||
return <FileToolRender part={part} filePath={filePath} content={content} toolName="Write" onFileClick={onFileClick} />
|
||||
return <FileToolRender part={part} filePath={filePath} content={content} toolName="Write" onFileClick={onFileClick} messageMeta={messageMeta} />
|
||||
}
|
||||
}
|
||||
|
||||
if (part.tool === 'read') {
|
||||
const filePath = part.state.input?.filePath as string | undefined
|
||||
if (filePath) {
|
||||
return <FileToolRender part={part} filePath={filePath} toolName="Read" onFileClick={onFileClick} />
|
||||
return <FileToolRender part={part} filePath={filePath} content={part.state.output} toolName="Read" onFileClick={onFileClick} messageMeta={messageMeta} />
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,10 @@ interface MessagePartProps {
|
||||
onFileClick?: (filePath: string, lineNumber?: number) => void
|
||||
onChildSessionClick?: (sessionId: string) => void
|
||||
messageTextContent?: string
|
||||
messageMeta?: {
|
||||
model: string
|
||||
time?: number
|
||||
}
|
||||
}
|
||||
|
||||
function getCopyableContent(part: Part, allParts?: Part[]): string {
|
||||
@@ -102,7 +106,7 @@ function TTSButton({ messageId, content, className = "" }: TTSButtonProps) {
|
||||
)
|
||||
}
|
||||
|
||||
export const MessagePart = memo(function MessagePart({ part, role, allParts, partIndex, onFileClick, onChildSessionClick, messageTextContent }: MessagePartProps) {
|
||||
export const MessagePart = memo(function MessagePart({ part, role, allParts, partIndex, onFileClick, onChildSessionClick, messageTextContent, messageMeta }: MessagePartProps) {
|
||||
const { preferences } = useSettings()
|
||||
const simpleChatMode = preferences?.simpleChatMode ?? false
|
||||
const showReasoning = preferences?.showReasoning ?? false
|
||||
@@ -123,7 +127,7 @@ export const MessagePart = memo(function MessagePart({ part, role, allParts, par
|
||||
return <PatchPart part={part} onFileClick={onFileClick} />
|
||||
case 'tool':
|
||||
if (simpleChatMode && part.tool !== 'task') return null
|
||||
return <ToolCallPart part={part} onFileClick={onFileClick} onChildSessionClick={onChildSessionClick} />
|
||||
return <ToolCallPart part={part} onFileClick={onFileClick} onChildSessionClick={onChildSessionClick} messageMeta={messageMeta} />
|
||||
case 'reasoning':
|
||||
if (simpleChatMode || !showReasoning) return null
|
||||
return (
|
||||
@@ -176,7 +180,13 @@ export const MessagePart = memo(function MessagePart({ part, role, allParts, par
|
||||
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="my-1 w-full rounded border border-orange-500/20 bg-orange-500/5 px-2 py-1 text-left text-xs text-muted-foreground">
|
||||
{messageMeta && (
|
||||
<div className="mb-1 flex items-center gap-2 text-[11px] text-muted-foreground">
|
||||
<span className="font-medium">{messageMeta.model}</span>
|
||||
{messageMeta.time && <span>{new Date(messageMeta.time).toLocaleTimeString()}</span>}
|
||||
</div>
|
||||
)}
|
||||
<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>
|
||||
|
||||
@@ -69,6 +69,23 @@ const createTaskToolPart = (description: string, sessionId: string | undefined,
|
||||
},
|
||||
})
|
||||
|
||||
const createReadToolPart = (filePath: string, messageId: string) => ({
|
||||
type: 'tool' as const,
|
||||
tool: 'read',
|
||||
sessionID: 'test-session',
|
||||
messageID: messageId,
|
||||
id: 'part-read',
|
||||
callID: 'call-read',
|
||||
state: {
|
||||
status: 'completed' as const,
|
||||
input: { filePath },
|
||||
output: 'const value = true',
|
||||
title: 'Read',
|
||||
metadata: {},
|
||||
time: { start: Date.now(), end: Date.now() + 100 },
|
||||
},
|
||||
})
|
||||
|
||||
const createSubtaskPart = (description: string, messageId: string) => ({
|
||||
type: 'subtask' as const,
|
||||
prompt: 'Please review this',
|
||||
@@ -173,7 +190,7 @@ describe('MessageThread', () => {
|
||||
|
||||
expect(screen.getByText('Review changes')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('test-model')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('test-model')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders assistant message with only task tool part as standalone row without header', () => {
|
||||
@@ -200,7 +217,7 @@ describe('MessageThread', () => {
|
||||
|
||||
expect(screen.getByText('Do something')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('test-model')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('test-model')).toBeInTheDocument()
|
||||
|
||||
const buttons = container.querySelectorAll('button')
|
||||
expect(buttons.length).toBeGreaterThan(0)
|
||||
@@ -208,6 +225,30 @@ describe('MessageThread', () => {
|
||||
expect(onChildSessionClick).toHaveBeenCalledWith('child-session')
|
||||
})
|
||||
|
||||
it('renders assistant message with only read tool part as standalone row without header', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
})
|
||||
|
||||
const messages = [
|
||||
createUserMessage('1', 'Hello'),
|
||||
createAssistantMessage('2', [createReadToolPart('/workspace/repos/opencode-manager/frontend/src/components/message/LongFileName.tsx', '2')]),
|
||||
]
|
||||
|
||||
render(
|
||||
<MessageThread
|
||||
opcodeUrl="http://localhost:5551"
|
||||
sessionID="test-session"
|
||||
messages={messages as any}
|
||||
/>
|
||||
)
|
||||
|
||||
expect(screen.getByText('Read')).toBeInTheDocument()
|
||||
expect(screen.getByText('LongFileName.tsx')).toBeInTheDocument()
|
||||
expect(screen.getByText('test-model')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders assistant task message with empty text and step finish as standalone row', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
@@ -233,7 +274,7 @@ describe('MessageThread', () => {
|
||||
|
||||
expect(screen.getByText('Explore codebase structure')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('test-model')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('test-model')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders assistant task message with hidden reasoning as standalone row', () => {
|
||||
@@ -262,7 +303,7 @@ describe('MessageThread', () => {
|
||||
|
||||
expect(screen.getByText('Explore codebase structure')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('test-model')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('test-model')).toBeInTheDocument()
|
||||
expect(screen.queryByText('I should use the explore agent')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -292,7 +333,7 @@ describe('MessageThread', () => {
|
||||
|
||||
expect(screen.getByText('Explore codebase structure')).toBeInTheDocument()
|
||||
expect(screen.getByText('sub-agent')).toBeInTheDocument()
|
||||
expect(screen.queryByText('test-model')).not.toBeInTheDocument()
|
||||
expect(screen.getByText('test-model')).toBeInTheDocument()
|
||||
expect(screen.queryByText('I should use the explore agent')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -323,7 +364,7 @@ describe('MessageThread', () => {
|
||||
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()
|
||||
expect(screen.getByText('test-model')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders assistant message with text normally with header', () => {
|
||||
|
||||
@@ -78,19 +78,15 @@ const hasRenderableContent = (role: Message['role'], parts: Part[], simpleChatMo
|
||||
})
|
||||
}
|
||||
|
||||
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 isStandaloneActivityPart(part: Part): boolean {
|
||||
return part.type === 'tool' || part.type === 'subtask'
|
||||
}
|
||||
|
||||
function hasTextContent(parts: Part[]): boolean {
|
||||
return parts.some(p => p.type === 'text' && !!(p.text && p.text.trim()))
|
||||
}
|
||||
|
||||
function isIgnorableSubAgentMessagePart(part: Part): boolean {
|
||||
function isIgnorableStandaloneMessagePart(part: Part): boolean {
|
||||
if (part.type === 'step-start' || part.type === 'step-finish' || part.type === 'compaction') {
|
||||
return true
|
||||
}
|
||||
@@ -103,20 +99,20 @@ function isIgnorableSubAgentMessagePart(part: Part): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
function isStandaloneSubAgentMessage(role: Message['role'], parts: Part[]): boolean {
|
||||
function isStandaloneActivityMessage(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)) {
|
||||
const hasStandaloneActivity = parts.some(isStandaloneActivityPart)
|
||||
const allPartsAreActivityOrStructural = parts.every(part => {
|
||||
if (isIgnorableStandaloneMessagePart(part)) {
|
||||
return true
|
||||
}
|
||||
return isSubAgentActivityPart(part)
|
||||
return isStandaloneActivityPart(part)
|
||||
})
|
||||
|
||||
return hasSubAgentActivity && allPartsAreSubAgentOrStructural
|
||||
return hasStandaloneActivity && allPartsAreActivityOrStructural
|
||||
}
|
||||
|
||||
const findLastMessageByRole = (
|
||||
@@ -193,20 +189,25 @@ const MessageRow = memo(function MessageRow({
|
||||
|
||||
const hasContent = hasRenderableContent(msg.role, parts, simpleChatMode, showReasoning)
|
||||
const hasError = msg.role === 'assistant' && 'error' in msg && msg.error
|
||||
const standaloneSubAgentMessage = isStandaloneSubAgentMessage(msg.role, parts)
|
||||
const standaloneActivityMessage = isStandaloneActivityMessage(msg.role, parts)
|
||||
|
||||
if (!hasContent && !hasError) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (standaloneSubAgentMessage) {
|
||||
if (standaloneActivityMessage) {
|
||||
const messageMeta = {
|
||||
model: msg.role === 'assistant' && 'modelID' in msg ? msg.modelID : 'Assistant',
|
||||
time: msg.time?.created,
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
key={msg.id}
|
||||
className="flex flex-col group"
|
||||
>
|
||||
<div className="space-y-1">
|
||||
{parts.filter(isSubAgentActivityPart).map((part, partIndex) => (
|
||||
{parts.filter(isStandaloneActivityPart).map((part, partIndex) => (
|
||||
<div key={`${msg.id}-${part.id}-${partIndex}`}>
|
||||
<MessagePart
|
||||
part={part}
|
||||
@@ -216,6 +217,7 @@ const MessageRow = memo(function MessageRow({
|
||||
onFileClick={onFileClick}
|
||||
onChildSessionClick={onChildSessionClick}
|
||||
messageTextContent={messageTextContent}
|
||||
messageMeta={messageMeta}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
|
||||
@@ -15,6 +15,10 @@ interface ToolCallPartProps {
|
||||
onFileClick?: (filePath: string, lineNumber?: number) => void
|
||||
onChildSessionClick?: (sessionId: string) => void
|
||||
simpleChatMode?: boolean
|
||||
messageMeta?: {
|
||||
model: string
|
||||
time?: number
|
||||
}
|
||||
}
|
||||
|
||||
function getTaskSessionId(part: ToolPart): string | undefined {
|
||||
@@ -65,7 +69,7 @@ function ClickableJson({ json, onFileClick }: { json: unknown; onFileClick?: (fi
|
||||
return <pre className="bg-accent p-2 rounded text-xs overflow-x-auto whitespace-pre-wrap break-words">{parts}</pre>
|
||||
}
|
||||
|
||||
export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCallPartProps) {
|
||||
export function ToolCallPart({ part, onFileClick, onChildSessionClick, messageMeta }: ToolCallPartProps) {
|
||||
const { preferences } = useSettings()
|
||||
const { userBashCommands } = useUserBash()
|
||||
const { getForCallID: getPermissionForCallID } = usePermissions()
|
||||
@@ -92,7 +96,7 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
const getStatusColor = () => {
|
||||
switch (part.state.status) {
|
||||
case 'completed':
|
||||
return 'text-green-600 dark:text-green-400'
|
||||
return 'text-orange-600 dark:text-orange-400'
|
||||
case 'error':
|
||||
return 'text-red-600 dark:text-red-400'
|
||||
case 'running':
|
||||
@@ -158,11 +162,17 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
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" />
|
||||
<Loader2 className="w-3.5 h-3.5 animate-spin text-orange-600 dark:text-orange-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" />}
|
||||
{sessionId && <ExternalLink className="w-3 h-3 shrink-0 text-orange-600 dark:text-orange-400" />}
|
||||
</div>
|
||||
)
|
||||
const meta = messageMeta && (
|
||||
<div className="mb-1 flex items-center gap-2 text-[11px] text-muted-foreground">
|
||||
<span className="font-medium">{messageMeta.model}</span>
|
||||
{messageMeta.time && <span>{new Date(messageMeta.time).toLocaleTimeString()}</span>}
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -170,16 +180,18 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
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"
|
||||
className="my-1 w-full rounded border border-orange-500/20 bg-orange-500/5 px-2 py-1 text-left text-xs text-muted-foreground hover:bg-orange-500/10 transition-colors"
|
||||
title="View subagent session"
|
||||
>
|
||||
{meta}
|
||||
{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">
|
||||
<div className="my-1 rounded border border-orange-500/20 bg-orange-500/5 px-2 py-1 text-xs text-muted-foreground">
|
||||
{meta}
|
||||
{content}
|
||||
</div>
|
||||
)
|
||||
@@ -223,7 +235,7 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
return null
|
||||
}
|
||||
|
||||
const toolSpecificRender = getToolSpecificRender(part, onFileClick)
|
||||
const toolSpecificRender = getToolSpecificRender(part, onFileClick, messageMeta)
|
||||
if (toolSpecificRender) {
|
||||
return toolSpecificRender
|
||||
}
|
||||
@@ -234,7 +246,7 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
return (
|
||||
<div className="my-2">
|
||||
<div className="flex items-center gap-2 text-sm mb-2">
|
||||
<span className="text-green-600 dark:text-green-400">✓</span>
|
||||
<span className="text-orange-600 dark:text-orange-400">✓</span>
|
||||
<span className="font-medium">$</span>
|
||||
<span className="text-foreground">{command}</span>
|
||||
{part.state.status === 'completed' && part.state.time && (
|
||||
@@ -264,9 +276,9 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
case 'error':
|
||||
return 'border-red-500/30'
|
||||
case 'completed':
|
||||
return 'border-border'
|
||||
return 'border-orange-500/20 bg-orange-500/5'
|
||||
default:
|
||||
return 'border-border'
|
||||
return 'border-orange-500/20 bg-orange-500/5'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,45 +286,53 @@ export function ToolCallPart({ part, onFileClick, onChildSessionClick }: ToolCal
|
||||
<div ref={outputRef} className={`border rounded-lg overflow-hidden my-2 transition-all ${getBorderStyle()}`}>
|
||||
<button
|
||||
onClick={() => setExpanded(!expanded)}
|
||||
className="w-full px-4 py-2 bg-card hover:bg-card-hover text-left flex items-center gap-2 text-sm min-w-0"
|
||||
className="w-full px-3 py-2 hover:bg-orange-500/10 text-left text-sm min-w-0 transition-colors"
|
||||
>
|
||||
<span className={getStatusColor()}>{getStatusIcon()}</span>
|
||||
<span className="font-medium">{part.tool}</span>
|
||||
{messageMeta && (
|
||||
<div className="mb-1 flex items-center gap-2 text-[11px] text-muted-foreground">
|
||||
<span className="font-medium">{messageMeta.model}</span>
|
||||
{messageMeta.time && <span>{new Date(messageMeta.time).toLocaleTimeString()}</span>}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center gap-2 min-w-0 w-full">
|
||||
<span className={getStatusColor()}>{getStatusIcon()}</span>
|
||||
<span className="font-medium">{part.tool}</span>
|
||||
|
||||
{previewText && isFileTool ? (
|
||||
<span
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
if (onFileClick && previewText) {
|
||||
onFileClick(previewText)
|
||||
}
|
||||
}}
|
||||
className="text-blue-600 dark:text-blue-400 text-xs truncate hover:text-blue-700 dark:hover:text-blue-300 cursor-pointer underline decoration-dotted"
|
||||
title={`Click to open ${previewText}`}
|
||||
>
|
||||
{previewText}
|
||||
</span>
|
||||
) : previewText ? (
|
||||
<span className="text-muted-foreground text-xs truncate">{previewText}</span>
|
||||
) : null}
|
||||
|
||||
{part.tool === 'task' && (() => {
|
||||
const sessionId = getTaskSessionId(part)
|
||||
return sessionId ? (
|
||||
{previewText && isFileTool ? (
|
||||
<span
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
onChildSessionClick?.(sessionId)
|
||||
if (onFileClick && previewText) {
|
||||
onFileClick(previewText)
|
||||
}
|
||||
}}
|
||||
className="text-purple-600 dark:text-purple-400 text-xs hover:text-purple-700 dark:hover:text-purple-300 cursor-pointer underline decoration-dotted flex items-center gap-1"
|
||||
title="View subagent session"
|
||||
className="text-orange-600 dark:text-orange-400 text-xs truncate hover:underline cursor-pointer"
|
||||
title={`Click to open ${previewText}`}
|
||||
>
|
||||
<ExternalLink className="w-3 h-3" />
|
||||
View Session
|
||||
{previewText}
|
||||
</span>
|
||||
) : null
|
||||
})()}
|
||||
<span className="text-muted-foreground text-xs ml-auto">({isWaitingPermission ? 'awaiting permission' : isWaitingQuestion ? 'awaiting answer' : part.state.status})</span>
|
||||
) : previewText ? (
|
||||
<span className="text-muted-foreground text-xs truncate">{previewText}</span>
|
||||
) : null}
|
||||
|
||||
{part.tool === 'task' && (() => {
|
||||
const sessionId = getTaskSessionId(part)
|
||||
return sessionId ? (
|
||||
<span
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
onChildSessionClick?.(sessionId)
|
||||
}}
|
||||
className="text-orange-600 dark:text-orange-400 text-xs hover:underline cursor-pointer flex items-center gap-1"
|
||||
title="View subagent session"
|
||||
>
|
||||
<ExternalLink className="w-3 h-3" />
|
||||
View Session
|
||||
</span>
|
||||
) : null
|
||||
})()}
|
||||
<span className="text-muted-foreground text-xs ml-auto">({isWaitingPermission ? 'awaiting permission' : isWaitingQuestion ? 'awaiting answer' : part.state.status})</span>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
{expanded && (
|
||||
|
||||
Reference in new issue
Block a user