refactor(chat + workspace): chat和workspace重构,子路由、懒加载等
This commit is contained in:
1 parent
0a647a0b79
commit
1f1f7236b0
57 files changed
+4356
-3798
No files matched your search
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* features/chat/composables/useChatHistory.ts
|
||||
* 跨 Agent 聊天历史列表(工作台 History 页 / 移动端 Tab)。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { getAuthHeaders } from '@/utils/auth';
|
||||
import { requestJson } from '@/api/client';
|
||||
import type { ChatCrossAgentHistoryItem } from '../types/chat.types';
|
||||
|
||||
export function useChatHistory() {
|
||||
const chatHistories = ref<ChatCrossAgentHistoryItem[]>([]);
|
||||
const isLoadingHistories = ref(false);
|
||||
|
||||
const loadChatHistories = async () => {
|
||||
isLoadingHistories.value = true;
|
||||
try {
|
||||
const agentList = await requestJson<Array<{ id: number; name: string }>>('/api/agents', {
|
||||
headers: getAuthHeaders(),
|
||||
});
|
||||
const allHistories: ChatCrossAgentHistoryItem[] = [];
|
||||
await Promise.all(
|
||||
(Array.isArray(agentList) ? agentList : []).map(async (agent) => {
|
||||
try {
|
||||
const sessions = await requestJson<ChatCrossAgentHistoryItem[]>(
|
||||
`/api/chat/sessions?agent_id=${agent.id}`,
|
||||
{ headers: getAuthHeaders() },
|
||||
);
|
||||
for (const s of Array.isArray(sessions) ? sessions : []) {
|
||||
allHistories.push({ ...s, agent_id: agent.id, agent_name: agent.name });
|
||||
}
|
||||
} catch {
|
||||
// ignore per-agent failures
|
||||
}
|
||||
}),
|
||||
);
|
||||
allHistories.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
|
||||
chatHistories.value = allHistories;
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
isLoadingHistories.value = false;
|
||||
};
|
||||
|
||||
return { chatHistories, isLoadingHistories, loadChatHistories };
|
||||
}
|
||||
Reference in new issue
Block a user