import { useState } from 'react'; import MarkdownContent from './MarkdownContent'; import Expand from './ui/Expand'; export type ToolCallArgumentValue = | string | number | boolean | null | ToolCallArgumentValue[] | { [key: string]: ToolCallArgumentValue }; interface ToolCallArgumentsProps { args: Record; } export function ToolCallArguments({ args }: ToolCallArgumentsProps) { const [expandedKeys, setExpandedKeys] = useState>({}); const toggleKey = (key: string) => { setExpandedKeys((prev) => ({ ...prev, [key]: !prev[key] })); }; const renderValue = (key: string, value: ToolCallArgumentValue) => { if (typeof value === 'string') { const needsExpansion = value.length > 60; const isExpanded = expandedKeys[key]; if (!needsExpansion) { return (
{key} {value}
); } return (
{isExpanded ? (
) : ( )}
); } // Handle non-string values (arrays, objects, etc.) const content = Array.isArray(value) ? value.map((item, index) => `${index + 1}. ${JSON.stringify(item)}`).join('\n') : typeof value === 'object' && value !== null ? JSON.stringify(value, null, 2) : String(value); return (
{key}
            {content}
          
); }; return (
{Object.entries(args).map(([key, value]) => (
{renderValue(key, value)}
))}
); }