This commit is contained in:
aaron 2025-05-11 11:28:42 +08:00
parent 8da9e6750c
commit efed9c541e
2 changed files with 128 additions and 73 deletions

View File

@ -5,7 +5,7 @@ services:
build: build:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile
image: tradus-web:1.3 image: tradus-web:1.4
container_name: tradus-web container_name: tradus-web
ports: ports:
- '6000:80' - '6000:80'

View File

@ -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) => { const addInitialGreeting = async (agent: Agent) => {
chatHistory.value = [ const message: ChatMessage = {
{
role: 'assistant', role: 'assistant',
content: content: '',
agent.hello_prompt ||
'你好我是AI Agent可以回答你的任何关于Web3的问题。请告诉我你想了解什么',
files: [], files: [],
}, }
] chatHistory.value = [message]
const greetingText =
agent.hello_prompt ||
'你好我是AI Agent可以回答你的任何关于Web3的问题。请告诉我你想了解什么'
await typeMessage(greetingText, 0)
} }
// Agent // Agent
watch(selectedAgent, (newAgent) => { watch(selectedAgent, (newAgent) => {
if (newAgent) { if (newAgent && chatHistory.value.length === 0) {
addInitialGreeting(newAgent) addInitialGreeting(newAgent).catch(console.error)
} }
}) })
@ -186,18 +212,17 @@ const showConfirm = (title: string, message: string, callback: () => void) => {
// Agent // Agent
const selectAgent = (agent: Agent) => { const selectAgent = (agent: Agent) => {
if (!selectedAgent.value || agent.id !== selectedAgent.value.id) { if (!selectedAgent.value || agent.id !== selectedAgent.value.id) {
// Agent // Agent
showConfirm('切换 Agent', `是否开启新的 Agent${agent.name}`, () => {
selectedAgent.value = agent selectedAgent.value = agent
clearConversationId(agent.id) clearConversationId(agent.id)
chatHistory.value = [] chatHistory.value = []
showConfirmDialog.value = false addInitialGreeting(agent).catch(console.error)
})
} else { } else {
// Agent // Agent
showConfirm('重新开始对话', '是否重新开启新会话?', () => { showConfirm('重新开始对话', '是否重新开启新会话?', () => {
clearConversationId(agent.id) clearConversationId(agent.id)
chatHistory.value = [] chatHistory.value = []
addInitialGreeting(agent).catch(console.error)
showConfirmDialog.value = false showConfirmDialog.value = false
}) })
} }
@ -402,7 +427,13 @@ const getIconPath = (agent: Agent) => {
: 'ai-message', : 'ai-message',
]" ]"
> >
<div class="message-content"> <div
class="message-content"
:class="{
typing:
isTyping && typingMessageIndex === index && message.role === 'assistant',
}"
>
<div v-html="renderMarkdown(message.content)"></div> <div v-html="renderMarkdown(message.content)"></div>
</div> </div>
</div> </div>
@ -451,9 +482,8 @@ const getIconPath = (agent: Agent) => {
</div> </div>
<!-- 添加确认对话框 --> <!-- 添加确认对话框 -->
<div v-if="showConfirmDialog" class="confirm-dialog"> <div v-if="showConfirmDialog" class="confirm-popup">
<div class="confirm-dialog-content"> <div class="confirm-popup-content">
<h3>{{ confirmDialogTitle }}</h3>
<p>{{ confirmDialogMessage }}</p> <p>{{ confirmDialogMessage }}</p>
<div class="confirm-actions"> <div class="confirm-actions">
<button <button
@ -683,10 +713,29 @@ const getIconPath = (agent: Agent) => {
white-space: pre-wrap; white-space: pre-wrap;
box-sizing: border-box; box-sizing: border-box;
background-clip: padding-box; background-clip: padding-box;
overflow: hidden;
line-height: 1.4; line-height: 1.4;
} }
.message-content.typing :deep(.markdown-body) {
display: inline;
}
.message-content :deep(p) {
margin: 0;
line-height: 1.4;
display: inline;
}
.message-content :deep(p:not(:last-child)) {
display: block;
margin-bottom: 0.75em;
}
/* 确保markdown内容正确显示 */
:deep(.markdown-body) {
display: inline;
}
.user-message .message-content { .user-message .message-content {
background-color: var(--color-accent); background-color: var(--color-accent);
color: white; color: white;
@ -1099,90 +1148,96 @@ const getIconPath = (agent: Agent) => {
} }
/* 添加确认对话框样式 */ /* 添加确认对话框样式 */
.confirm-dialog { .confirm-popup {
position: fixed; position: fixed;
top: 0; top: 20px;
left: 0; left: 50%;
right: 0; transform: translateX(-50%);
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 1000; z-index: 1000;
backdrop-filter: blur(4px); animation: slideDown 0.3s ease-out;
} }
.confirm-dialog-content { .confirm-popup-content {
background-color: #ffffff; background-color: #ffffff;
color: #000000; padding: 1rem 1.5rem;
padding: 2rem; border-radius: 8px;
border-radius: var(--border-radius); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
max-width: 400px; display: flex;
width: calc(100% - 2rem); align-items: center;
margin: 1rem; gap: 1rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); min-width: 300px;
border: 1px solid #e5e7eb; max-width: 90vw;
} }
.confirm-dialog-content h3 { .confirm-popup-content p {
font-size: 1.5rem; margin: 0;
margin-bottom: 1rem;
color: #000000; color: #000000;
} font-size: 0.95rem;
flex: 1;
.confirm-dialog-content p {
color: #4b5563;
margin-bottom: 2rem;
line-height: 1.5;
} }
.confirm-actions { .confirm-actions {
display: flex; display: flex;
justify-content: center; gap: 0.5rem;
gap: 1rem;
} }
.confirm-actions button { .confirm-actions button {
padding: 0.8rem 2rem; padding: 0.4rem 0.8rem;
border-radius: var(--border-radius); border-radius: 6px;
font-size: 0.9rem;
font-weight: 500; font-weight: 500;
cursor: pointer; cursor: pointer;
transition: all 0.2s ease; transition: all 0.2s ease;
min-width: 100px; border: none;
background: none;
} }
.confirm-actions button:first-child { .confirm-actions button:first-child {
background-color: var(--color-accent); color: var(--color-accent);
color: white;
border: none;
} }
.confirm-actions button:first-child:hover { .confirm-actions button:first-child:hover {
background-color: var(--color-accent-hover); background-color: rgba(51, 85, 255, 0.1);
} }
.confirm-actions button:last-child { .confirm-actions button:last-child {
background-color: #f3f4f6; color: #666666;
color: #000000;
border: 1px solid #e5e7eb;
} }
.confirm-actions button:last-child:hover { .confirm-actions button:last-child:hover {
background-color: #e5e7eb; background-color: #f3f4f6;
}
@keyframes slideDown {
from {
transform: translate(-50%, -100%);
opacity: 0;
}
to {
transform: translate(-50%, 0);
opacity: 1;
}
} }
@media (max-width: 480px) { @media (max-width: 480px) {
.confirm-dialog-content { .confirm-popup {
padding: 1.5rem; top: 10px;
width: calc(100% - 20px);
} }
.confirm-dialog-content h3 { .confirm-popup-content {
font-size: 1.3rem; padding: 0.8rem 1rem;
min-width: auto;
} }
}
.confirm-actions button { @keyframes blink {
padding: 0.6rem 1.5rem; 0%,
100% {
opacity: 1;
}
50% {
opacity: 0;
} }
} }
</style> </style>