import { AgentScopeRuntimeWebUI, IAgentScopeRuntimeWebUIRef, ChatInput } from '@agentscope-ai/chat'; import OptionsPanel from './OptionsPanel'; import { useMemo, useRef } from 'react'; import defaultConfig from './OptionsPanel/defaultConfig'; import { useLocalStorageState } from 'ahooks'; import { Flex } from 'antd'; import MessageImport from './MessageImport'; export default function () { const chatRef = useRef(null); // @ts-ignore window.chatRef = chatRef; const [optionsConfig, setOptionsConfig] = useLocalStorageState('agent-scope-runtime-webui-options', { defaultValue: defaultConfig(), listenStorageChange: true, }); const options = useMemo(() => { const rightHeader = { setOptionsConfig(prev => ({ ...prev, ...v, })); }} /> ; return { ...optionsConfig, customToolRenderConfig: { // 'weather search mock': Weather, }, session: { multiple: true, }, sender: { ...optionsConfig.sender, beforeUI: { optionsConfig.welcome.prompts.map(prompt => ( { chatRef.current?.input.submit({ query: prompt.value }); }}>{prompt.value} )) } , attachments: optionsConfig.sender.attachments ? { customRequest(options) { // 模拟上传进度 options.onProgress({ percent: 100, }); // 当前是一个 mock 的上传行为 // 实际情况需要具体实现一个文件上传服务,将文件转化为 url options.onSuccess({ url: URL.createObjectURL(options.file as Blob) }); } } : undefined, }, theme: { ...optionsConfig.theme, rightHeader, }, api: { ...optionsConfig.api, cancel: (data) => { console.log('cancel', data); }, }, }; }, [optionsConfig]); return
; }