feat(agent): enhance agent sharing and selection features

- Updated the AgentSelector component to improve agent selection logic, ensuring accurate representation of selected agents.
- Introduced new AgentShareSettings component for managing agent sharing with organizations, including UI for selecting organizations and displaying shared agents.
- Enhanced API interactions for sharing agents, including new methods for listing and managing agent shares.
- Improved localization support for agent sharing features across multiple languages.
- Updated various components to reflect changes in agent capabilities and sharing status, enhancing user experience and clarity.

This update strengthens the agent management features, providing users with better tools for sharing and selecting agents within organizations.
This commit is contained in:
wizardchen
2026-02-04 20:12:29 +08:00
committed by lyingbug
parent faa4e9e7b5
commit dfaf862bc0
45 changed files with 3606 additions and 477 deletions
+23 -1
View File
@@ -4,6 +4,7 @@ import type {
Organization,
OrganizationMember,
SharedKnowledgeBase,
SharedAgentInfo,
OrganizationPreview
} from '@/api/organization'
import {
@@ -18,7 +19,8 @@ import {
listMembers,
updateMemberRole,
removeMember,
listSharedKnowledgeBases
listSharedKnowledgeBases,
listSharedAgents
} from '@/api/organization'
export const useOrganizationStore = defineStore('organization', () => {
@@ -27,6 +29,7 @@ export const useOrganizationStore = defineStore('organization', () => {
const currentOrganization = ref<Organization | null>(null)
const currentMembers = ref<OrganizationMember[]>([])
const sharedKnowledgeBases = ref<SharedKnowledgeBase[]>([])
const sharedAgents = ref<SharedAgentInfo[]>([])
const previewData = ref<OrganizationPreview | null>(null)
const loading = ref(false)
const error = ref<string | null>(null)
@@ -349,6 +352,22 @@ export const useOrganizationStore = defineStore('organization', () => {
}
}
/**
* Fetch shared agents (shared to me through organizations)
*/
async function fetchSharedAgents() {
try {
const response = await listSharedAgents()
if (response.success && response.data) {
sharedAgents.value = response.data.filter(s => s.agent != null)
return sharedAgents.value
}
return []
} catch (e: any) {
return []
}
}
/**
* Set current organization for detail view
*/
@@ -393,6 +412,7 @@ export const useOrganizationStore = defineStore('organization', () => {
currentOrganization.value = null
currentMembers.value = []
sharedKnowledgeBases.value = []
sharedAgents.value = []
previewData.value = null
error.value = null
}
@@ -403,6 +423,7 @@ export const useOrganizationStore = defineStore('organization', () => {
currentOrganization,
currentMembers,
sharedKnowledgeBases,
sharedAgents,
previewData,
loading,
error,
@@ -426,6 +447,7 @@ export const useOrganizationStore = defineStore('organization', () => {
changeMemberRole,
kickMember,
fetchSharedKnowledgeBases,
fetchSharedAgents,
setCurrentOrganization,
getKBPermission,
canEditKB,
+23 -3
View File
@@ -10,11 +10,13 @@ interface Settings {
agentConfig: AgentConfig;
selectedKnowledgeBases: string[]; // 当前选中的知识库ID列表
selectedFiles: string[]; // 当前选中的文件ID列表
selectedFileKbMap: Record<string, string>; // 文件ID -> 知识库ID,用于刷新后带 kb_id 拉取共享知识库文件
modelConfig: ModelConfig; // 模型配置
ollamaConfig: OllamaConfig; // Ollama配置
webSearchEnabled: boolean; // 网络搜索是否启用
conversationModels: ConversationModels;
selectedAgentId: string; // 当前选中的智能体ID
selectedAgentSourceTenantId: string | null; // 当使用共享智能体时,来源租户 ID(用于后端 model/KB/MCP 解析)
}
// Agent 配置接口
@@ -72,6 +74,7 @@ const defaultSettings: Settings = {
},
selectedKnowledgeBases: [], // 默认为空数组
selectedFiles: [], // 默认为空数组
selectedFileKbMap: {}, // 文件ID -> 知识库ID
modelConfig: {
chatModels: [],
embeddingModels: [],
@@ -89,6 +92,7 @@ const defaultSettings: Settings = {
selectedChatModelId: "", // 用户当前选择的对话模型ID
},
selectedAgentId: BUILTIN_QUICK_ANSWER_ID, // 默认选中快速问答模式
selectedAgentSourceTenantId: null as string | null, // 共享智能体来源租户 ID
};
export const useSettingsStore = defineStore("settings", {
@@ -136,6 +140,8 @@ export const useSettingsStore = defineStore("settings", {
// 当前选中的智能体ID
selectedAgentId: (state) => state.settings.selectedAgentId || BUILTIN_QUICK_ANSWER_ID,
// 共享智能体来源租户 ID(可选)
selectedAgentSourceTenantId: (state) => state.settings.selectedAgentSourceTenantId ?? null,
},
actions: {
@@ -302,11 +308,24 @@ export const useSettingsStore = defineStore("settings", {
removeFile(fileId: string) {
if (!this.settings.selectedFiles) return;
this.settings.selectedFiles = this.settings.selectedFiles.filter((id: string) => id !== fileId);
if (this.settings.selectedFileKbMap) delete this.settings.selectedFileKbMap[fileId];
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
},
clearFiles() {
this.settings.selectedFiles = [];
this.settings.selectedFileKbMap = {};
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
},
setFileKbMap(updates: Record<string, string>) {
if (!this.settings.selectedFileKbMap) this.settings.selectedFileKbMap = {};
Object.assign(this.settings.selectedFileKbMap, updates);
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
},
removeFileKbId(fileId: string) {
if (this.settings.selectedFileKbMap) delete this.settings.selectedFileKbMap[fileId];
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
},
@@ -314,9 +333,10 @@ export const useSettingsStore = defineStore("settings", {
return this.settings.selectedFiles || [];
},
// 选择智能体
selectAgent(agentId: string) {
// 选择智能体(sourceTenantId 仅在使用共享智能体时传入)
selectAgent(agentId: string, sourceTenantId?: string | null) {
this.settings.selectedAgentId = agentId;
this.settings.selectedAgentSourceTenantId = (sourceTenantId != null && sourceTenantId !== "") ? sourceTenantId : null;
// 根据智能体类型自动切换 Agent 模式
if (agentId === BUILTIN_QUICK_ANSWER_ID) {
this.settings.isAgentEnabled = false;
@@ -329,7 +349,7 @@ export const useSettingsStore = defineStore("settings", {
// 因为不同智能体关联的知识库不同,需要清空用户之前的选择
this.settings.selectedKnowledgeBases = [];
this.settings.selectedFiles = [];
this.settings.selectedFileKbMap = {};
localStorage.setItem("WeKnora_settings", JSON.stringify(this.settings));
},