import { OperateCard, useProviderContext } from '@agentscope-ai/chat'; import { SparkCopyLine, SparkLoadingLine, SparkToolLine, SparkTrueLine } from '@agentscope-ai/icons'; import { CodeBlock, IconButton } from '@agentscope-ai/design'; import { copy } from '../../Util/copy'; import { useRef, useState } from 'react'; function Block(props: { title: string; content: string | Record expandEnabled?: boolean; language?: 'json' | 'text'; }) { const { getPrefixCls } = useProviderContext(); const prefixCls = getPrefixCls('operate-card'); const { expandEnabled = false, language = 'json' } = props; const contentString = typeof props.content === 'string' ? props.content : JSON.stringify(props.content); const [copied, setCopied] = useState(false); const [expanded, setExpanded] = useState(expandEnabled === true ? false : true); const timer = useRef(null); return
{ if (expandEnabled === true) { setExpanded(prev => !prev); } }} > {props.title}
e.stopPropagation()} > : } bordered={false} onClick={() => { copy(contentString).then(() => { clearTimeout(timer.current); setCopied(true); timer.current = setTimeout(() => { setCopied(false); }, 2000); }).catch(() => { console.warn('Copy failed'); }); }} />
{expanded && (
{/* @ts-ignore */}
)}
} export interface IToolCallProps { /** * @description 标题 * @descriptionEn Title * @default 'Call Tool' */ title?: string; /** * @description 副标题 * @descriptionEn Subtitle * @default '' */ subTitle?: string; /** * @description 工具调用入参 * @descriptionEn Tool Call Input * @default '' */ input: string | Record; /** * @description 工具调用输出 * @descriptionEn Tool Call Output * @default '' */ output: string | Record; /** * @description 默认展开 * @descriptionEn Default Open */ defaultOpen?: boolean; /** * @description 是否正在生成 * @descriptionEn Whether is generating * @default false */ loading?: boolean; outputBlock?: { language?: 'json' | 'text' } inputBlock?: { language?: 'json' | 'text' } } export default function (props: IToolCallProps) { const { title = 'Call Tool', subTitle, defaultOpen = true, loading = false } = props; return : , title: title, description: subTitle, }} body={{ defaultOpen: defaultOpen, children: }} > }