import React from 'react' import { Code, Terminal, Search, FileCode, Globe, FileText, FileEdit, Image, GalleryHorizontal, Puzzle, Bot, RefreshCw, Eye, Layers, Wrench, } from 'lucide-react' import { cn } from '@/utils/cn' import type { ApiEvent } from '../../types' import { SILENT_ACTION_TYPES } from './utils' export interface ToolCallActionProps { name?: string arguments?: string[] action_type?: string event?: ApiEvent onClick?: (event: ApiEvent) => void } // ─── action_type → { icon, label } ────────────────────────────────────────── const ACTION_TYPE_META: Record = { shell_execute: { icon: , label: '执行命令' }, terminal_operator: { icon: , label: '终端操作' }, code_execute: { icon: , label: '运行代码' }, file_operator: { icon: , label: '文件操作' }, file_create: { icon: , label: '创建文件' }, file_read: { icon: , label: '读取文件' }, file_replace_text: { icon: , label: '编辑文件' }, file_write_text: { icon: , label: '写入文件' }, str_replace: { icon: , label: '替换内容' }, info_search_web: { icon: , label: '搜索网页' }, info_fetch_webpage: { icon: , label: '获取网页' }, news_search: { icon: , label: '新闻搜索' }, image_search: { icon: , label: '图片搜索' }, info_search_custom_knowledge: { icon: , label: '知识检索' }, search_custom_knowledge: { icon: , label: '知识检索' }, browser_use: { icon: , label: '浏览器操作' }, slide_init: { icon: , label: '初始化幻灯片' }, slide_template: { icon: , label: '选择模板' }, slide_create: { icon: , label: '生成幻灯片' }, slide_create_batch: { icon: , label: '批量生成幻灯片' }, slide_present: { icon: , label: '展示幻灯片' }, media_generate_image: { icon: , label: '生成图片' }, media_vision_image: { icon: , label: '识别图片' }, generate_image: { icon: , label: '生成图片' }, call_flow: { icon: , label: '调用流程' }, integrated_app: { icon: , label: '集成应用' }, custom_api: { icon: , label: '自定义工具' }, skill_loader: { icon: , label: '加载技能' }, brand_search: { icon: , label: '品牌检索' }, xiaohongshu_search: { icon: , label: '小红书搜索' }, e_commerce: { icon: , label: '电商搜索' }, experience_query: { icon: , label: '经验查询' }, writer: { icon: , label: '文档创作' }, parallel_map: { icon: , label: '并行任务' }, media_comments: { icon: , label: '媒体搜索' }, system_api: { icon: , label: '系统接口' }, } /** * 工具调用 Action 组件 * - 静默事件类型 → 不渲染 * - name / label / argsText 全空 → 不渲染 * - 点击触发外部 onClick(打开右侧面板) */ export function ToolCallAction({ name, arguments: args, action_type, event, onClick, }: ToolCallActionProps) { // 静默类型直接跳过 if (action_type && SILENT_ACTION_TYPES.has(action_type)) return null const meta = action_type ? ACTION_TYPE_META[action_type] : undefined const icon = meta?.icon ?? const label = name || meta?.label || '' const argsText = args?.filter(Boolean).join(' ') || '' // 没有任何可展示内容时不渲染 if (!label && !argsText) return null const handleClick = () => { if (event && onClick) onClick(event) } const isClickable = !!(event && onClick) return (
{ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault() handleClick() } } : undefined } > {icon} {label && {label}:} {argsText && ( {argsText} )}
) }