import React from 'react'; import { Card } from './ui/card'; import Box from './ui/Box'; import { ToolCallArguments } from './ToolCallArguments'; import MarkdownContent from './MarkdownContent'; import { LoadingPlaceholder } from './LoadingPlaceholder'; import { ChevronUp } from 'lucide-react'; import { Content, ToolRequestMessageContent, ToolResponseMessageContent } from '../types/message'; import { snakeToTitleCase } from '../utils'; interface ToolCallWithResponseProps { isCancelledMessage: boolean; toolRequest: ToolRequestMessageContent; toolResponse?: ToolResponseMessageContent; } export default function ToolCallWithResponse({ isCancelledMessage, toolRequest, toolResponse, }: ToolCallWithResponseProps) { const toolCall = toolRequest.toolCall.status === 'success' ? toolRequest.toolCall.value : null; if (!toolCall) { return null; } return (
{!isCancelledMessage ? ( toolResponse ? ( ) : ( ) ) : undefined}
); } interface ToolCallViewProps { toolCall: { name: string; arguments: Record; }; } function ToolCallView({ toolCall }: ToolCallViewProps) { return (
{snakeToTitleCase(toolCall.name.substring(toolCall.name.lastIndexOf('__') + 2))}
{toolCall.arguments && }
); } interface ToolResultViewProps { result?: Content[]; } function ToolResultView({ result }: ToolResultViewProps) { // State to track expanded items const [expandedItems, setExpandedItems] = React.useState([]); // If no result info, don't show anything if (!result) return null; // Find results where either audience is not set, or it's set to a list that includes user const filteredResults = result.filter((item) => { // Check audience (which may not be in the type) const audience = item.annotations?.audience; return !audience || audience.includes('user'); }); if (filteredResults.length === 0) return null; const toggleExpand = (index: number) => { setExpandedItems((prev) => prev.includes(index) ? prev.filter((i) => i !== index) : [...prev, index] ); }; const shouldShowExpanded = (item: Content, index: number) => { return ( (item.annotations && item.annotations.priority !== undefined && item.annotations.priority >= 0.5) || expandedItems.includes(index) ); }; return (
{filteredResults.map((item, index) => { const isExpanded = shouldShowExpanded(item, index); const shouldMinimize = !item.annotations || item.annotations.priority === undefined || item.annotations.priority < 0.5; return (
{shouldMinimize && ( )} {(isExpanded || !shouldMinimize) && ( <> {item.text && ( )} )}
); })}
); }