update
This commit is contained in:
parent
318f7eb08f
commit
73741dd583
@ -5,7 +5,7 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
image: tradus-web:1.1
|
image: tradus-web:1.2
|
||||||
container_name: tradus-web
|
container_name: tradus-web
|
||||||
ports:
|
ports:
|
||||||
- '6000:80'
|
- '6000:80'
|
||||||
|
|||||||
@ -153,6 +153,54 @@ watch(selectedAgent, (newAgent) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 获取当前agent的会话ID
|
||||||
|
const getConversationId = (agentId: string) => {
|
||||||
|
const key = `conversation_${agentId}`
|
||||||
|
return localStorage.getItem(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存当前agent的会话ID
|
||||||
|
const saveConversationId = (agentId: string, conversationId: string) => {
|
||||||
|
const key = `conversation_${agentId}`
|
||||||
|
localStorage.setItem(key, conversationId)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清除当前agent的会话ID
|
||||||
|
const clearConversationId = (agentId: string) => {
|
||||||
|
const key = `conversation_${agentId}`
|
||||||
|
localStorage.removeItem(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
const showConfirmDialog = ref(false)
|
||||||
|
const confirmDialogTitle = ref('')
|
||||||
|
const confirmDialogMessage = ref('')
|
||||||
|
const confirmCallback = ref<(() => void) | null>(null)
|
||||||
|
|
||||||
|
const showConfirm = (title: string, message: string, callback: () => void) => {
|
||||||
|
confirmDialogTitle.value = title
|
||||||
|
confirmDialogMessage.value = message
|
||||||
|
confirmCallback.value = callback
|
||||||
|
showConfirmDialog.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选择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)
|
||||||
|
showConfirmDialog.value = false
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// 点击当前 Agent
|
||||||
|
showConfirm('重新开始对话', '是否重新开启新会话?', () => {
|
||||||
|
clearConversationId(agent.id)
|
||||||
|
showConfirmDialog.value = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const sendMessage = async () => {
|
const sendMessage = async () => {
|
||||||
if (!userInput.value.trim() || isLoading.value || !isAuthenticated.value || !selectedAgent.value)
|
if (!userInput.value.trim() || isLoading.value || !isAuthenticated.value || !selectedAgent.value)
|
||||||
return
|
return
|
||||||
@ -191,11 +239,13 @@ const sendMessage = async () => {
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加认证头
|
|
||||||
if (userStore.authHeader) {
|
if (userStore.authHeader) {
|
||||||
headers['Authorization'] = userStore.authHeader
|
headers['Authorization'] = userStore.authHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取当前agent的会话ID
|
||||||
|
const conversationId = selectedAgent.value ? getConversationId(selectedAgent.value.id) : null
|
||||||
|
|
||||||
// 调用流式接口
|
// 调用流式接口
|
||||||
const response = await fetch(`${apiBaseUrl}/agent/chat`, {
|
const response = await fetch(`${apiBaseUrl}/agent/chat`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -203,6 +253,7 @@ const sendMessage = async () => {
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
user_prompt: currentInput,
|
user_prompt: currentInput,
|
||||||
agent_id: selectedAgent.value.id,
|
agent_id: selectedAgent.value.id,
|
||||||
|
conversation_id: conversationId,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -231,6 +282,11 @@ const sendMessage = async () => {
|
|||||||
try {
|
try {
|
||||||
const data = JSON.parse(line.slice(6))
|
const data = JSON.parse(line.slice(6))
|
||||||
|
|
||||||
|
// 处理 conversation_id
|
||||||
|
if (data.conversation_id && selectedAgent.value) {
|
||||||
|
saveConversationId(selectedAgent.value.id, data.conversation_id)
|
||||||
|
}
|
||||||
|
|
||||||
switch (data.event) {
|
switch (data.event) {
|
||||||
case 'agent_message':
|
case 'agent_message':
|
||||||
if (data.answer) {
|
if (data.answer) {
|
||||||
@ -285,11 +341,6 @@ const sendMessage = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 选择Agent
|
|
||||||
const selectAgent = (agent: Agent) => {
|
|
||||||
selectedAgent.value = agent
|
|
||||||
}
|
|
||||||
|
|
||||||
// 在 script 部分添加图标渲染函数
|
// 在 script 部分添加图标渲染函数
|
||||||
const getAgentIcon = (agent: Agent) => {
|
const getAgentIcon = (agent: Agent) => {
|
||||||
// 根据 agent 类型返回对应的 SVG 图标
|
// 根据 agent 类型返回对应的 SVG 图标
|
||||||
@ -396,6 +447,27 @@ const getIconPath = (agent: Agent) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- 添加确认对话框 -->
|
||||||
|
<div v-if="showConfirmDialog" class="confirm-dialog">
|
||||||
|
<div class="confirm-dialog-content">
|
||||||
|
<h3>{{ confirmDialogTitle }}</h3>
|
||||||
|
<p>{{ confirmDialogMessage }}</p>
|
||||||
|
<div class="confirm-actions">
|
||||||
|
<button
|
||||||
|
@click="
|
||||||
|
() => {
|
||||||
|
confirmCallback?.()
|
||||||
|
showConfirmDialog = false
|
||||||
|
}
|
||||||
|
"
|
||||||
|
>
|
||||||
|
确认
|
||||||
|
</button>
|
||||||
|
<button @click="showConfirmDialog = false">取消</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -1023,4 +1095,92 @@ const getIconPath = (agent: Agent) => {
|
|||||||
color: white;
|
color: white;
|
||||||
background-color: rgba(255, 255, 255, 0.1);
|
background-color: rgba(255, 255, 255, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 添加确认对话框样式 */
|
||||||
|
.confirm-dialog {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
z-index: 1000;
|
||||||
|
backdrop-filter: blur(4px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-dialog-content {
|
||||||
|
background-color: #ffffff;
|
||||||
|
color: #000000;
|
||||||
|
padding: 2rem;
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
max-width: 400px;
|
||||||
|
width: calc(100% - 2rem);
|
||||||
|
margin: 1rem;
|
||||||
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-dialog-content h3 {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
color: #000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-dialog-content p {
|
||||||
|
color: #4b5563;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-actions button {
|
||||||
|
padding: 0.8rem 2rem;
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
font-weight: 500;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
min-width: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-actions button:first-child {
|
||||||
|
background-color: var(--color-accent);
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-actions button:first-child:hover {
|
||||||
|
background-color: var(--color-accent-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-actions button:last-child {
|
||||||
|
background-color: #f3f4f6;
|
||||||
|
color: #000000;
|
||||||
|
border: 1px solid #e5e7eb;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-actions button:last-child:hover {
|
||||||
|
background-color: #e5e7eb;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.confirm-dialog-content {
|
||||||
|
padding: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-dialog-content h3 {
|
||||||
|
font-size: 1.3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirm-actions button {
|
||||||
|
padding: 0.6rem 1.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user