更新功能

This commit is contained in:
Your Name
2026-07-17 17:28:25 +08:00
parent 80b0c89a72
commit 7803c46b96
18 changed files with 3118 additions and 440 deletions
+16 -3
View File
@@ -55,6 +55,7 @@ export const useChatStore = defineStore('chat', () => {
const sidebarOpen = ref(false)
/** 侧边栏当前选中的模型,发送/新建会话都会使用它 */
const selectedModelId = ref(null)
const selectedAgentId = ref(localStorage.getItem('selected_agent_id') || null)
let pendingPollTimer = null
let pendingPollInFlight = false
@@ -183,7 +184,16 @@ export const useChatStore = defineStore('chat', () => {
}
}
async function sendMessage(content, attachments = []) {
function setSelectedAgent(agentId) {
selectedAgentId.value = agentId || null
if (selectedAgentId.value) {
localStorage.setItem('selected_agent_id', selectedAgentId.value)
} else {
localStorage.removeItem('selected_agent_id')
}
}
async function sendMessage(content, attachments = [], agentId = selectedAgentId.value) {
if (!currentId.value) {
await createConversation(selectedModelId.value)
} else if (selectedModelId.value != null) {
@@ -207,7 +217,7 @@ export const useChatStore = defineStore('chat', () => {
streamingAttachments.value = []
try {
await streamChat(content, attachments)
await streamChat(content, attachments, agentId)
await loadMessages()
} catch (e) {
// 连接断开/代理超时:任务可能已落库为 pending,先同步再决定是否抛错
@@ -225,7 +235,7 @@ export const useChatStore = defineStore('chat', () => {
}
}
async function streamChat(content, attachments) {
async function streamChat(content, attachments, agentId = null) {
const token = localStorage.getItem('token')
const response = await fetch('/api/chat/completions', {
method: 'POST',
@@ -237,6 +247,7 @@ export const useChatStore = defineStore('chat', () => {
conversation_id: currentId.value,
content,
attachments,
agent_id: agentId || null,
stream: true
})
})
@@ -350,10 +361,12 @@ export const useChatStore = defineStore('chat', () => {
streamingAttachments,
sidebarOpen,
selectedModelId,
selectedAgentId,
fetchConversations,
createConversation,
selectConversation,
setSelectedModel,
setSelectedAgent,
deleteConversation,
sendMessage,
loadMessages,