fix(identity): 名字检测从 memory extraction 解耦 — 502 不再阻断面板刷新
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
agent/user name 检测之前放在 extractFromConversation().then() 回调里, memory extractor 502 时整个 .then() 跳过,名字永远不会更新。 现在名字检测独立执行,memory extraction 失败不影响面板刷新。
This commit is contained in:
@@ -366,44 +366,45 @@ function createCompleteHandler(
|
||||
});
|
||||
}
|
||||
|
||||
// Async memory extraction
|
||||
// Detect name changes from last user message (independent of memory extraction)
|
||||
const msgs = chat.getMessages() || [];
|
||||
const lastUserMsg = [...msgs].reverse().find(m => m.role === 'user');
|
||||
const lastContent = typeof lastUserMsg?.content === 'string' ? lastUserMsg.content : '';
|
||||
|
||||
if (lastContent && agentId) {
|
||||
// User name detection (e.g. "叫我小王")
|
||||
const detectedName = detectNameSuggestion(lastContent);
|
||||
if (detectedName) {
|
||||
import('../agentStore').then(({ useAgentStore }) =>
|
||||
useAgentStore.getState().updateClone(agentId, { userName: detectedName })
|
||||
.then(() => log.info(`Updated userName to "${detectedName}" from conversation`))
|
||||
.catch(e => log.warn('Failed to persist detected userName:', e))
|
||||
);
|
||||
}
|
||||
// Agent name detection (e.g. "叫你小马", "名称改为小芳")
|
||||
const detectedAgentName = detectAgentNameSuggestion(lastContent);
|
||||
if (detectedAgentName) {
|
||||
import('../agentStore').then(({ useAgentStore }) =>
|
||||
useAgentStore.getState().updateClone(agentId, { name: detectedAgentName })
|
||||
.then(() => {
|
||||
log.info(`Updated agent name to "${detectedAgentName}" from conversation`);
|
||||
if (typeof window !== 'undefined') {
|
||||
window.dispatchEvent(new CustomEvent('zclaw:agent-profile-updated', {
|
||||
detail: { agentId }
|
||||
}));
|
||||
}
|
||||
})
|
||||
.catch(e => log.warn('Failed to persist detected agent name:', e))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Async memory extraction (independent — failures don't block name detection)
|
||||
const filtered = msgs
|
||||
.filter(m => m.role === 'user' || m.role === 'assistant')
|
||||
.map(m => ({ role: m.role, content: m.content }));
|
||||
const convId = useConversationStore.getState().currentConversationId;
|
||||
getMemoryExtractor().extractFromConversation(filtered, agentId, convId ?? undefined)
|
||||
.then(async () => {
|
||||
// Detect name preference from last user message (e.g. "叫我小马")
|
||||
const lastUserMsg = [...msgs].reverse().find(m => m.role === 'user');
|
||||
const detectedName = lastUserMsg ? detectNameSuggestion(lastUserMsg.content) : undefined;
|
||||
if (detectedName && agentId) {
|
||||
try {
|
||||
const { useAgentStore } = await import('../agentStore');
|
||||
await useAgentStore.getState().updateClone(agentId, { userName: detectedName });
|
||||
log.info(`Updated userName to "${detectedName}" from conversation`);
|
||||
} catch (e) {
|
||||
log.warn('Failed to persist detected userName:', e);
|
||||
}
|
||||
}
|
||||
// Detect agent name change (e.g. "叫你小马", "以后叫你小马", "你就叫小马吧")
|
||||
const lastContent = typeof lastUserMsg?.content === 'string' ? lastUserMsg.content : '';
|
||||
const detectedAgentName = lastContent ? detectAgentNameSuggestion(lastContent) : undefined;
|
||||
if (detectedAgentName && agentId) {
|
||||
try {
|
||||
const { useAgentStore } = await import('../agentStore');
|
||||
await useAgentStore.getState().updateClone(agentId, { name: detectedAgentName });
|
||||
log.info(`Updated agent name to "${detectedAgentName}" from conversation`);
|
||||
} catch (e) {
|
||||
log.warn('Failed to persist detected agent name:', e);
|
||||
}
|
||||
}
|
||||
if (typeof window !== 'undefined') {
|
||||
window.dispatchEvent(new CustomEvent('zclaw:agent-profile-updated', {
|
||||
detail: { agentId }
|
||||
}));
|
||||
}
|
||||
})
|
||||
.catch(err => log.warn('Memory extraction failed:', err));
|
||||
|
||||
intelligenceClient.reflection.recordConversation().catch(err => {
|
||||
|
||||
Reference in New Issue
Block a user