feat: 新增智能体功能模块,支持自定义智能体创建、配置和选择

This commit is contained in:
wizardchen
2025-12-24 10:34:41 +08:00
parent 236b190b26
commit d0c5c4f6b0
36 changed files with 5195 additions and 672 deletions
+5 -4
View File
@@ -18,6 +18,7 @@ const createMenuChildren = () => reactive<MenuChild[]>([])
export const useMenuStore = defineStore('menuStore', () => {
const menuArr = reactive<MenuItem[]>([
{ title: '', titleKey: 'menu.knowledgeBase', icon: 'zhishiku', path: 'knowledge-bases' },
{ title: '', titleKey: 'menu.agents', icon: 'agent', path: 'agents' },
{
title: '',
titleKey: 'menu.chat',
@@ -52,14 +53,14 @@ export const useMenuStore = defineStore('menuStore', () => {
)
const clearMenuArr = () => {
const chatMenu = menuArr[1]
const chatMenu = menuArr[2]
if (chatMenu && chatMenu.children) {
chatMenu.children = createMenuChildren()
}
}
const updatemenuArr = (obj: any) => {
const chatMenu = menuArr[1]
const chatMenu = menuArr[2]
if (!chatMenu.children) {
chatMenu.children = createMenuChildren()
}
@@ -70,7 +71,7 @@ export const useMenuStore = defineStore('menuStore', () => {
}
const updataMenuChildren = (item: MenuChild) => {
const chatMenu = menuArr[1]
const chatMenu = menuArr[2]
if (!chatMenu.children) {
chatMenu.children = createMenuChildren()
}
@@ -78,7 +79,7 @@ export const useMenuStore = defineStore('menuStore', () => {
}
const updatasessionTitle = (sessionId: string, title: string) => {
const chatMenu = menuArr[1]
const chatMenu = menuArr[2]
chatMenu.children?.forEach((item: MenuChild) => {
if (item.id === sessionId) {
item.title = title
+24 -1
View File
@@ -13,6 +13,7 @@ interface Settings {
ollamaConfig: OllamaConfig; // Ollama配置
webSearchEnabled: boolean; // 网络搜索是否启用
conversationModels: ConversationModels;
selectedAgentId: string; // 当前选中的智能体ID
}
// Agent 配置接口
@@ -89,7 +90,8 @@ const defaultSettings: Settings = {
summaryModelId: "",
rerankModelId: "",
selectedChatModelId: "", // 用户当前选择的对话模型ID
}
},
selectedAgentId: "builtin-normal", // 默认选中普通模式
};
export const useSettingsStore = defineStore("settings", {
@@ -124,6 +126,9 @@ export const useSettingsStore = defineStore("settings", {
// 网络搜索是否启用
isWebSearchEnabled: (state) => state.settings.webSearchEnabled || false,
// 当前选中的智能体ID
selectedAgentId: (state) => state.settings.selectedAgentId || "builtin-normal",
},
actions: {
@@ -301,6 +306,24 @@ export const useSettingsStore = defineStore("settings", {
getSelectedFiles(): string[] {
return this.settings.selectedFiles || [];
},
// 选择智能体
selectAgent(agentId: string) {
this.settings.selectedAgentId = agentId;
// 根据智能体类型自动切换 Agent 模式
if (agentId === "builtin-normal") {
this.settings.isAgentEnabled = false;
} else if (agentId === "builtin-agent") {
this.settings.isAgentEnabled = true;
}
// 自定义智能体需要根据其配置来决定
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
},
// 获取选中的智能体ID
getSelectedAgentId(): string {
return this.settings.selectedAgentId || "builtin-normal";
},
},
});