From a09a4c0e0adc4f6165d2129b0fc540d0424b7bd8 Mon Sep 17 00:00:00 2001 From: iven Date: Wed, 22 Apr 2026 22:59:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(agent-tab):=20=E4=BF=AE=E5=A4=8D=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=20Agent=20tab=20=E6=95=B0=E6=8D=AE=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 updateClone 中 role→description 字段映射错误:前端发送 role 但 Tauri agent_update 期望 description,导致角色描述从未保存 - 修复 listClones 中 userName/userRole 数据不可用:agent_list 不 返回 userProfile,现通过 agent_get + identity_get_file 双通道 获取用户配置数据和动态学习数据 - 修复 userAddressing 错误使用 agent nickname 作为用户称呼方式 --- desktop/src/components/RightPanel.tsx | 2 +- desktop/src/lib/kernel-agent.ts | 50 ++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/desktop/src/components/RightPanel.tsx b/desktop/src/components/RightPanel.tsx index 0e2d776..514f68e 100644 --- a/desktop/src/components/RightPanel.tsx +++ b/desktop/src/components/RightPanel.tsx @@ -275,7 +275,7 @@ export function RightPanel({ simpleMode = false }: RightPanelProps) { const runtimeSummary = connected ? '已连接' : connectionState === 'connecting' ? '连接中...' : connectionState === 'reconnecting' ? '重连中...' : '未连接'; const userNameDisplay = selectedClone?.userName || quickConfig.userName || 'User'; - const userAddressing = selectedClone?.nickname || selectedClone?.userName || quickConfig.userName || 'User'; + const userAddressing = selectedClone?.userName || quickConfig.userName || 'User'; const localTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone || '系统时区'; // Extract code blocks from all messages (both from codeBlocks property and content parsing) diff --git a/desktop/src/lib/kernel-agent.ts b/desktop/src/lib/kernel-agent.ts index 9361f28..936c535 100644 --- a/desktop/src/lib/kernel-agent.ts +++ b/desktop/src/lib/kernel-agent.ts @@ -60,7 +60,36 @@ export function installAgentMethods(ClientClass: { prototype: KernelClient }): v */ proto.listClones = async function (this: KernelClient): Promise<{ clones: any[] }> { const agents = await this.listAgents(); - const clones = agents.map((agent) => { + + // Enrich each agent with: (a) full profile from agent_get, (b) identity user_profile file + const enriched = await Promise.all( + agents.map(async (agent) => { + // Fetch full agent data (includes UserProfile from SQLite) + let full: AgentInfo | null = null; + try { + full = await invoke('agent_get', { agentId: agent.id }); + } catch { /* non-critical */ } + + // Fetch identity user_profile file (stores user-configured userName/userRole) + let identityUserName: string | undefined; + let identityUserRole: string | undefined; + try { + const content = await invoke('identity_get_file', { agentId: agent.id, file: 'user_profile' }); + if (content) { + for (const line of content.split('\n')) { + const nameMatch = line.match(/^-\s*姓名[::]\s*(.+)$/); + if (nameMatch?.[1]?.trim()) identityUserName = nameMatch[1].trim(); + const roleMatch = line.match(/^-\s*角色[::]\s*(.+)$/); + if (roleMatch?.[1]?.trim()) identityUserRole = roleMatch[1].trim(); + } + } + } catch { /* non-critical */ } + + return { agent: full || agent, identityUserName, identityUserRole }; + }) + ); + + const clones = enriched.map(({ agent, identityUserName, identityUserRole }) => { // Parse personality/emoji/nickname from SOUL.md content const soulLines = (agent.soul || '').split('\n'); let emoji: string | undefined; @@ -86,13 +115,16 @@ export function installAgentMethods(ClientClass: { prototype: KernelClient }): v } } - // Parse userName/userRole from userProfile - let userName: string | undefined; - let userRole: string | undefined; - if (agent.userProfile && typeof agent.userProfile === 'object') { + // Merge userName/userRole: user-configured (identity files) > learned (UserProfileStore) + let userName = identityUserName; + let userRole = identityUserRole; + if (!userName && agent.userProfile && typeof agent.userProfile === 'object') { const profile = agent.userProfile as Record; - userName = profile.userName as string | undefined || profile.name as string | undefined; - userRole = profile.userRole as string | undefined || profile.role as string | undefined; + userName = (profile.userName || profile.name) as string | undefined; + } + if (!userRole && agent.userProfile && typeof agent.userProfile === 'object') { + const profile = agent.userProfile as Record; + userRole = (profile.userRole || profile.role) as string | undefined; } return { @@ -173,7 +205,7 @@ export function installAgentMethods(ClientClass: { prototype: KernelClient }): v agentId: id, updates: { name: updates.name as string | undefined, - description: updates.description as string | undefined, + description: (updates.role || updates.description) as string | undefined, systemPrompt: updates.systemPrompt as string | undefined, model: updates.model as string | undefined, provider: updates.provider as string | undefined, @@ -257,7 +289,7 @@ export function installAgentMethods(ClientClass: { prototype: KernelClient }): v const clone = { id, name: updates.name, - role: updates.description || updates.role, + role: updates.role || updates.description, nickname: updates.nickname, model: updates.model, emoji: updates.emoji,