'use client' import React from 'react' import { toPublicErrorPayload } from '@/lib/errors/public-error' // This matches the structure from AI SDK v5 type DynamicToolPart = | { type: 'dynamic-tool' toolCallId: string toolName: string state: 'input-streaming' input: unknown } | { type: 'dynamic-tool' toolCallId: string toolName: string state: 'input-available' input: unknown } | { type: 'dynamic-tool' toolCallId: string toolName: string state: 'output-available' input: unknown output: unknown } | { type: 'dynamic-tool' toolCallId: string toolName: string state: 'output-error' input: unknown errorText: string } interface DynamicToolDisplayProps { part: DynamicToolPart } export function DynamicToolDisplay({ part }: DynamicToolDisplayProps) { // Extract tool type from name const getToolType = (toolName: string) => { if (toolName.startsWith('mcp__')) { return 'MCP Tool' } else if (toolName.startsWith('dynamic__')) { return 'Dynamic Tool' } return 'Custom Tool' } // Extract display name from tool name const getDisplayName = (toolName: string) => { if (toolName.startsWith('mcp__')) { return toolName.substring(5).replace(/__/g, '.') } else if (toolName.startsWith('dynamic__')) { return toolName.substring(9) } return toolName } const toolType = getToolType(part.toolName) const displayName = getDisplayName(part.toolName) const errorMessage = part.state === 'output-error' ? toPublicErrorPayload(part.errorText, { fallbackMessage: 'Tool execution failed' }).error : undefined return (
{toolType} {displayName}
{/* Input display */} {(part.state === 'input-streaming' || part.state === 'input-available' || part.state === 'output-available' || part.state === 'output-error') && (
Input:
            {JSON.stringify(part.input, null, 2)}
          
)} {/* Output display */} {part.state === 'output-available' && (
Output:
            {JSON.stringify(part.output, null, 2)}
          
)} {/* Error display */} {part.state === 'output-error' && (
Error:
{errorMessage}
)} {/* Status indicator */}
{part.state === 'input-streaming' ? 'Streaming...' : part.state === 'input-available' ? 'Processing...' : part.state === 'output-available' ? 'Complete' : part.state === 'output-error' ? 'Failed' : 'Unknown'}
) }