feat(intelligence): complete migration to Rust backend

- Unify all intelligence modules to use intelligenceClient
- Delete legacy TS implementations (agent-memory, reflection-engine, heartbeat-engine, context-compactor, agent-identity, memory-index)
- Update all consumers to use snake_case backend types
- Remove deprecated llm-integration.test.ts

This eliminates code duplication between frontend and backend, resolves
localStorage limitations, and enables persistent intelligence features.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
iven
2026-03-21 15:17:39 +08:00
parent 17fb1e69aa
commit f3ec3c8d4c
24 changed files with 1172 additions and 3095 deletions

View File

@@ -7,11 +7,11 @@ import {
import { cardHover, defaultTransition } from '../lib/animations';
import { Button, Badge, EmptyState } from './ui';
import {
getMemoryManager,
intelligenceClient,
type MemoryEntry,
type MemoryType,
type MemoryStats,
} from '../lib/agent-memory';
} from '../lib/intelligence-client';
import { useChatStore } from '../store/chatStore';
const TYPE_LABELS: Record<MemoryType, { label: string; emoji: string; color: string }> = {
@@ -34,22 +34,26 @@ export function MemoryPanel() {
const [isExporting, setIsExporting] = useState(false);
const loadMemories = useCallback(async () => {
const mgr = getMemoryManager();
const typeFilter = filterType !== 'all' ? { type: filterType as MemoryType } : {};
if (searchQuery.trim()) {
const results = await mgr.search(searchQuery, {
const results = await intelligenceClient.memory.search({
agentId,
query: searchQuery,
limit: 50,
...typeFilter,
});
setMemories(results);
} else {
const all = await mgr.getAll(agentId, { ...typeFilter, limit: 50 });
setMemories(all);
const results = await intelligenceClient.memory.search({
agentId,
limit: 50,
...typeFilter,
});
setMemories(results);
}
const s = await mgr.stats(agentId);
const s = await intelligenceClient.memory.stats();
setStats(s);
}, [agentId, searchQuery, filterType]);
@@ -58,15 +62,22 @@ export function MemoryPanel() {
}, [loadMemories]);
const handleDelete = async (id: string) => {
await getMemoryManager().forget(id);
await intelligenceClient.memory.delete(id);
loadMemories();
};
const handleExport = async () => {
setIsExporting(true);
try {
const md = await getMemoryManager().exportToMarkdown(agentId);
const blob = new Blob([md], { type: 'text/markdown' });
const memories = await intelligenceClient.memory.export();
const filtered = memories.filter(m => m.agentId === agentId);
const md = filtered.map(m =>
`## [${m.type}] ${m.content}\n` +
`- 重要度: ${m.importance}\n` +
`- 标签: ${m.tags.join(', ') || '无'}\n` +
`- 创建时间: ${m.createdAt}\n`
).join('\n---\n\n');
const blob = new Blob([md || '# 无记忆数据'], { type: 'text/markdown' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
@@ -79,12 +90,20 @@ export function MemoryPanel() {
};
const handlePrune = async () => {
const pruned = await getMemoryManager().prune({
// Find old, low-importance memories and delete them
const memories = await intelligenceClient.memory.search({
agentId,
maxAgeDays: 30,
minImportance: 3,
minImportance: 0,
limit: 1000,
});
if (pruned > 0) {
const thirtyDaysAgo = Date.now() - 30 * 24 * 60 * 60 * 1000;
const toDelete = memories.filter(m =>
new Date(m.createdAt).getTime() < thirtyDaysAgo && m.importance < 3
);
for (const m of toDelete) {
await intelligenceClient.memory.delete(m.id);
}
if (toDelete.length > 0) {
loadMemories();
}
};