fix(agent): 12 项 agent 对话链路全栈修复
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

深端到端验证发现 12 个问题,6 Phase 全栈修复:

Phase 5 — 快速 UX 修复:
- #9: SimpleSidebar 添加新对话按钮 (SquarePen + useChatStore)
- #5: 模型列表 JOIN provider_keys 过滤无 API Key 的模型
- #11: AgentOnboardingWizard 焦点领域增加 4 行业选项
  (医疗健康/教育培训/金融财务/法律合规)

Phase 1 — ButlerPanel 记忆修复:
- #2a: MemorySection URI 从 viking://agent/.../memories/ 修正为 agent://.../
- #2b: "立即分析对话"按钮现在触发 extractAndStoreMemories

Phase 2 — FTS5 中文分词:
- #4: FTS5 tokenizer 从 unicode61 切换到 trigram,原生支持 CJK
- 自动迁移:检测旧 unicode61 表并重建索引
- sanitize_fts_query 支持中文引号短语查询

Phase 3 — 跨会话身份持久化:
- #6-8: 重新启用 USER.md 注入系统提示词 (截断前 10 行)

Phase 4 — Agent 面板同步:
- #1,#10: listClones 从 4 字段扩展到完整映射
  (soul/userProfile 解析 nickname/emoji/userName/userRole)
- updateClone 通过 identity 系统同步 nickname→SOUL.md
  和 userName/userRole→USER.md

Phase 6 — Agent 创建容错:
- #12: createFromTemplate 增加 SaaS 不可用 fallback

验证: tsc --noEmit  cargo check 
This commit is contained in:
iven
2026-04-16 09:21:46 +08:00
parent 08af78aa83
commit 3c01754c40
10 changed files with 330 additions and 44 deletions

View File

@@ -4,6 +4,7 @@ import { listVikingResources } from '../../lib/viking-client';
interface MemorySectionProps {
agentId: string;
refreshKey?: number;
}
interface MemoryEntry {
@@ -12,7 +13,7 @@ interface MemoryEntry {
resourceType: string;
}
export function MemorySection({ agentId }: MemorySectionProps) {
export function MemorySection({ agentId, refreshKey }: MemorySectionProps) {
const [memories, setMemories] = useState<MemoryEntry[]>([]);
const [loading, setLoading] = useState(false);
@@ -20,7 +21,8 @@ export function MemorySection({ agentId }: MemorySectionProps) {
if (!agentId) return;
setLoading(true);
listVikingResources(`viking://agent/${agentId}/memories/`)
// 查询 agent:// 下的所有记忆资源 (preferences/knowledge/experience/sessions)
listVikingResources(`agent://${agentId}/`)
.then((entries) => {
setMemories(entries as MemoryEntry[]);
})
@@ -29,7 +31,7 @@ export function MemorySection({ agentId }: MemorySectionProps) {
setMemories([]);
})
.finally(() => setLoading(false));
}, [agentId]);
}, [agentId, refreshKey]);
if (loading) {
return (

View File

@@ -1,7 +1,8 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useCallback } from 'react';
import { useButlerInsights } from '../../hooks/useButlerInsights';
import { useChatStore } from '../../store/chatStore';
import { useIndustryStore } from '../../store/industryStore';
import { extractAndStoreMemories } from '../../lib/viking-client';
import { InsightsSection } from './InsightsSection';
import { ProposalsSection } from './ProposalsSection';
import { MemorySection } from './MemorySection';
@@ -15,6 +16,7 @@ export function ButlerPanel({ agentId }: ButlerPanelProps) {
const messageCount = useChatStore((s) => s.messages.length);
const { accountIndustries, configs, lastSynced, isLoading: industryLoading, fetchIndustries } = useIndustryStore();
const [analyzing, setAnalyzing] = useState(false);
const [memoryRefreshKey, setMemoryRefreshKey] = useState(0);
// Auto-fetch industry configs once per session
useEffect(() => {
@@ -26,15 +28,30 @@ export function ButlerPanel({ agentId }: ButlerPanelProps) {
const hasData = (painPoints?.length ?? 0) > 0 || (proposals?.length ?? 0) > 0;
const canAnalyze = messageCount >= 2;
const handleAnalyze = async () => {
if (!canAnalyze || analyzing) return;
const handleAnalyze = useCallback(async () => {
if (!canAnalyze || analyzing || !agentId) return;
setAnalyzing(true);
try {
// 1. Refresh pain points & proposals
await refresh();
// 2. Extract and store memories from current conversation
const messages = useChatStore.getState().messages;
if (messages.length >= 2) {
const extractionMessages = messages.map((m) => ({
role: m.role as 'user' | 'assistant',
content: typeof m.content === 'string' ? m.content : '',
}));
await extractAndStoreMemories(extractionMessages, agentId);
// Trigger MemorySection to reload
setMemoryRefreshKey((k) => k + 1);
}
} catch {
// Extraction failure should not block UI — insights still refreshed
} finally {
setAnalyzing(false);
}
};
}, [canAnalyze, analyzing, agentId, refresh]);
if (!agentId) {
return (
@@ -107,7 +124,7 @@ export function ButlerPanel({ agentId }: ButlerPanelProps) {
<h3 className="text-sm font-semibold text-gray-900 dark:text-gray-100 mb-2">
</h3>
<MemorySection agentId={agentId} />
<MemorySection agentId={agentId} refreshKey={memoryRefreshKey} />
</div>
{/* Industry section */}