From efed9c541e2095263b8aecf9e54ac220081c396e Mon Sep 17 00:00:00 2001 From: aaron <> Date: Sun, 11 May 2025 11:28:42 +0800 Subject: [PATCH] update --- docker-compose.yml | 2 +- src/views/AIAgentView.vue | 199 ++++++++++++++++++++++++-------------- 2 files changed, 128 insertions(+), 73 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 80efca1..060cbc4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: build: context: . dockerfile: Dockerfile - image: tradus-web:1.3 + image: tradus-web:1.4 container_name: tradus-web ports: - '6000:80' diff --git a/src/views/AIAgentView.vue b/src/views/AIAgentView.vue index 220e05b..6bacd4a 100644 --- a/src/views/AIAgentView.vue +++ b/src/views/AIAgentView.vue @@ -133,23 +133,49 @@ const scrollToBottom = async () => { } } +// 添加打字机效果的状态 +const typingText = ref('') +const isTyping = ref(false) +const typingMessageIndex = ref(-1) + +// 打字机效果函数 +const typeMessage = async (message: string, messageIndex: number) => { + isTyping.value = true + typingMessageIndex.value = messageIndex + typingText.value = '' + chatHistory.value[messageIndex].content = '' + + for (let i = 0; i < message.length; i++) { + typingText.value += message[i] + chatHistory.value[messageIndex].content = typingText.value + await new Promise((resolve) => setTimeout(resolve, 50)) + } + + isTyping.value = false + typingMessageIndex.value = -1 + chatHistory.value[messageIndex].content = message + return message +} + // 添加初始问候语 -const addInitialGreeting = (agent: Agent) => { - chatHistory.value = [ - { - role: 'assistant', - content: - agent.hello_prompt || - '你好!我是AI Agent,可以回答你的任何关于Web3的问题。请告诉我你想了解什么?', - files: [], - }, - ] +const addInitialGreeting = async (agent: Agent) => { + const message: ChatMessage = { + role: 'assistant', + content: '', + files: [], + } + chatHistory.value = [message] + + const greetingText = + agent.hello_prompt || + '你好!我是AI Agent,可以回答你的任何关于Web3的问题。请告诉我你想了解什么?' + await typeMessage(greetingText, 0) } // 监听选中的Agent变化 watch(selectedAgent, (newAgent) => { - if (newAgent) { - addInitialGreeting(newAgent) + if (newAgent && chatHistory.value.length === 0) { + addInitialGreeting(newAgent).catch(console.error) } }) @@ -186,18 +212,17 @@ const showConfirm = (title: string, message: string, callback: () => void) => { // 选择Agent const selectAgent = (agent: Agent) => { if (!selectedAgent.value || agent.id !== selectedAgent.value.id) { - // 切换到新的 Agent - showConfirm('切换 Agent', `是否开启新的 Agent:${agent.name}?`, () => { - selectedAgent.value = agent - clearConversationId(agent.id) - chatHistory.value = [] - showConfirmDialog.value = false - }) + // 直接切换到新的 Agent + selectedAgent.value = agent + clearConversationId(agent.id) + chatHistory.value = [] + addInitialGreeting(agent).catch(console.error) } else { - // 点击当前 Agent + // 点击当前 Agent,显示确认框 showConfirm('重新开始对话', '是否重新开启新会话?', () => { clearConversationId(agent.id) chatHistory.value = [] + addInitialGreeting(agent).catch(console.error) showConfirmDialog.value = false }) } @@ -402,7 +427,13 @@ const getIconPath = (agent: Agent) => { : 'ai-message', ]" > -
+
@@ -451,9 +482,8 @@ const getIconPath = (agent: Agent) => { -
-
-

{{ confirmDialogTitle }}

+
+

{{ confirmDialogMessage }}