import { AnimatePresence, motion } from 'framer-motion'; import { memo, useRef, useState } from 'react'; import { createHighlighter, type BundledLanguage, type BundledTheme, type HighlighterGeneric } from 'shiki'; import type { ToolInvocationAnnotation } from '~/types/context'; import { classNames } from '~/utils/classNames'; import { cubicEasingFn } from '~/utils/easings'; import { logger } from '~/utils/logger'; const highlighterOptions = { langs: ['json'], themes: ['light-plus', 'dark-plus'], }; const jsonHighlighter: HighlighterGeneric = import.meta.hot?.data.jsonHighlighter ?? (await createHighlighter(highlighterOptions)); if (import.meta.hot) { import.meta.hot.data.jsonHighlighter = jsonHighlighter; } interface ToolInvocationProps { toolInvocations: ToolInvocationAnnotation[]; } export const ToolInvocation = memo(({ toolInvocations }: ToolInvocationProps) => { const userToggledDetails = useRef(false); const [showDetails, setShowDetails] = useState(false); const toggleDetails = () => { userToggledDetails.current = true; setShowDetails(!showDetails); }; if (toolInvocations.length === 0) { return null; } return (
{showDetails && (
)}
); }); interface JsonCodeBlockProps { className?: string; code: string; } function JsonCodeBlock({ className, code }: JsonCodeBlockProps) { let formattedCode = code; try { if (typeof code !== 'string') { formattedCode = JSON.stringify(code, null, 2); } else if (!code.trim().startsWith('{') && !code.trim().startsWith('[')) { // Not JSON, keep as is } else { formattedCode = JSON.stringify(JSON.parse(code), null, 2); } } catch (e) { // If parsing fails, keep original code logger.error('Failed to parse JSON', { error: e }); } return (
); } interface ToolListProps { toolInvocations: ToolInvocationAnnotation[]; } const toolVariants = { hidden: { opacity: 0, y: 20 }, visible: { opacity: 1, y: 0 }, }; const ToolList = memo(({ toolInvocations }: ToolListProps) => { return (
    {toolInvocations.map((tool, index) => { const isLast = index === toolInvocations.length - 1; return (
    {tool.toolName}
    Parameters:
    Result:
    ); })}
); });