fix(agent-tab): 修复详情页 Agent tab 数据不同步问题
Some checks failed
CI / Rust Check (push) Has been cancelled
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

- 修复 updateClone 中 role→description 字段映射错误:前端发送 role
  但 Tauri agent_update 期望 description,导致角色描述从未保存
- 修复 listClones 中 userName/userRole 数据不可用:agent_list 不
  返回 userProfile,现通过 agent_get + identity_get_file 双通道
  获取用户配置数据和动态学习数据
- 修复 userAddressing 错误使用 agent nickname 作为用户称呼方式
This commit is contained in:
iven
2026-04-22 22:59:26 +08:00
parent 62578d9df4
commit a09a4c0e0a
2 changed files with 42 additions and 10 deletions

View File

@@ -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)

View File

@@ -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<AgentInfo | null>('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<string | null>('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<string, unknown>;
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<string, unknown>;
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,