mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(chat): group exploration tool calls
Collapse consecutive read, search and fetch tool calls in the chat transcript into one expandable summary line, matching the OpenCode TUI. Adds a groupToolCalls preference (default on) with a Settings toggle.
This commit is contained in:
1 parent
81dd00e89f
commit
02d2e89bca
8 files changed
+242
-10
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import { memo, useState } from 'react'
|
||||
import { ChevronRight, Loader2 } from 'lucide-react'
|
||||
import type { SessionMessageAssistantTool } from '@opencode-manager/shared/opencode'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import { useToolCallPermission } from '@/contexts/EventContext'
|
||||
import { explorationLabel, isExplorationComplete } from '@/lib/explorationGroups'
|
||||
import { MessagePart } from './MessagePart'
|
||||
|
||||
interface ExplorationGroupProps {
|
||||
parts: SessionMessageAssistantTool[]
|
||||
messageID: string
|
||||
directory?: string
|
||||
onFileClick?: (filePath: string, lineNumber?: number) => void
|
||||
onChildSessionClick?: (sessionId: string) => void
|
||||
}
|
||||
|
||||
type MemberProps = Omit<ExplorationGroupProps, 'parts'> & { part: SessionMessageAssistantTool }
|
||||
|
||||
function PermissionBlockedMember(props: MemberProps) {
|
||||
const pendingPermission = useToolCallPermission(props.part.id, props.messageID)
|
||||
if (props.part.state.status !== 'running' || pendingPermission === null) return null
|
||||
return <MessagePart {...props} />
|
||||
}
|
||||
|
||||
/** Collapsed summary of consecutive read, search, and fetch tool calls, expandable to the individual calls. */
|
||||
export const ExplorationGroup = memo(function ExplorationGroup({ parts, ...memberProps }: ExplorationGroupProps) {
|
||||
const { preferences } = useSettings()
|
||||
const [expanded, setExpanded] = useState(preferences?.expandToolCalls ?? false)
|
||||
const completed = isExplorationComplete(parts)
|
||||
|
||||
return (
|
||||
<div className="my-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setExpanded(!expanded)}
|
||||
aria-expanded={expanded}
|
||||
className="group flex w-full min-w-0 items-center gap-2 py-0.5 text-left text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
{completed ? <span className="shrink-0">→</span> : <Loader2 className="w-3.5 h-3.5 shrink-0 animate-spin" />}
|
||||
<span className="truncate">{explorationLabel(parts)}</span>
|
||||
<ChevronRight className={`w-3.5 h-3.5 shrink-0 opacity-0 group-hover:opacity-100 transition-transform ${expanded ? 'rotate-90 opacity-100' : ''}`} />
|
||||
</button>
|
||||
{expanded ? (
|
||||
<div className="ml-1.5 border-l border-border pl-3">
|
||||
{parts.map((part) => (
|
||||
<MessagePart key={part.id} part={part} {...memberProps} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
parts.map((part) => <PermissionBlockedMember key={part.id} part={part} {...memberProps} />)
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})
|
||||
Reference in new issue
Block a user