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:
@@ -1,11 +1,8 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
import { getGatewayClient, AgentStreamDelta } from '../lib/gateway-client';
|
||||
import { getMemoryManager } from '../lib/agent-memory';
|
||||
import { getAgentIdentityManager } from '../lib/agent-identity';
|
||||
import { intelligenceClient } from '../lib/intelligence-client';
|
||||
import { getMemoryExtractor } from '../lib/memory-extractor';
|
||||
import { getContextCompactor } from '../lib/context-compactor';
|
||||
import { getReflectionEngine } from '../lib/reflection-engine';
|
||||
import { getAgentSwarm } from '../lib/agent-swarm';
|
||||
import { getSkillDiscovery } from '../lib/skill-discovery';
|
||||
|
||||
@@ -300,21 +297,26 @@ export const useChatStore = create<ChatState>()(
|
||||
|
||||
// Check context compaction threshold before adding new message
|
||||
try {
|
||||
const compactor = getContextCompactor();
|
||||
const check = compactor.checkThreshold(get().messages.map(m => ({ role: m.role, content: m.content })));
|
||||
if (check.shouldCompact) {
|
||||
console.log(`[Chat] Context compaction triggered (${check.urgency}): ${check.currentTokens} tokens`);
|
||||
const result = await compactor.compact(
|
||||
get().messages.map(m => ({ role: m.role, content: m.content, id: m.id, timestamp: m.timestamp })),
|
||||
const messages = get().messages.map(m => ({ role: m.role, content: m.content }));
|
||||
const check = await intelligenceClient.compactor.checkThreshold(messages);
|
||||
if (check.should_compact) {
|
||||
console.log(`[Chat] Context compaction triggered (${check.urgency}): ${check.current_tokens} tokens`);
|
||||
const result = await intelligenceClient.compactor.compact(
|
||||
get().messages.map(m => ({
|
||||
role: m.role,
|
||||
content: m.content,
|
||||
id: m.id,
|
||||
timestamp: m.timestamp instanceof Date ? m.timestamp.toISOString() : m.timestamp
|
||||
})),
|
||||
agentId,
|
||||
get().currentConversationId ?? undefined
|
||||
);
|
||||
// Replace messages with compacted version
|
||||
const compactedMsgs: Message[] = result.compactedMessages.map((m, i) => ({
|
||||
const compactedMsgs: Message[] = result.compacted_messages.map((m, i) => ({
|
||||
id: m.id || `compacted_${i}_${Date.now()}`,
|
||||
role: m.role as Message['role'],
|
||||
content: m.content,
|
||||
timestamp: m.timestamp || new Date(),
|
||||
timestamp: m.timestamp ? new Date(m.timestamp) : new Date(),
|
||||
}));
|
||||
set({ messages: compactedMsgs });
|
||||
}
|
||||
@@ -325,17 +327,16 @@ export const useChatStore = create<ChatState>()(
|
||||
// Build memory-enhanced content
|
||||
let enhancedContent = content;
|
||||
try {
|
||||
const memoryMgr = getMemoryManager();
|
||||
const identityMgr = getAgentIdentityManager();
|
||||
const relevantMemories = await memoryMgr.search(content, {
|
||||
const relevantMemories = await intelligenceClient.memory.search({
|
||||
agentId,
|
||||
query: content,
|
||||
limit: 8,
|
||||
minImportance: 3,
|
||||
});
|
||||
const memoryContext = relevantMemories.length > 0
|
||||
? `\n\n## 相关记忆\n${relevantMemories.map(m => `- [${m.type}] ${m.content}`).join('\n')}`
|
||||
: '';
|
||||
const systemPrompt = identityMgr.buildSystemPrompt(agentId, memoryContext);
|
||||
const systemPrompt = await intelligenceClient.identity.buildPrompt(agentId, memoryContext);
|
||||
if (systemPrompt) {
|
||||
enhancedContent = `<context>\n${systemPrompt}\n</context>\n\n${content}`;
|
||||
}
|
||||
@@ -426,13 +427,16 @@ export const useChatStore = create<ChatState>()(
|
||||
console.warn('[Chat] Memory extraction failed:', err)
|
||||
);
|
||||
// Track conversation for reflection trigger
|
||||
const reflectionEngine = getReflectionEngine();
|
||||
reflectionEngine.recordConversation();
|
||||
if (reflectionEngine.shouldReflect()) {
|
||||
reflectionEngine.reflect(agentId).catch(err =>
|
||||
console.warn('[Chat] Reflection failed:', err)
|
||||
);
|
||||
}
|
||||
intelligenceClient.reflection.recordConversation().catch(err =>
|
||||
console.warn('[Chat] Recording conversation failed:', err)
|
||||
);
|
||||
intelligenceClient.reflection.shouldReflect().then(shouldReflect => {
|
||||
if (shouldReflect) {
|
||||
intelligenceClient.reflection.reflect(agentId, []).catch(err =>
|
||||
console.warn('[Chat] Reflection failed:', err)
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
onError: (error: string) => {
|
||||
set((state) => ({
|
||||
|
||||
@@ -136,6 +136,7 @@ export interface ConfigStateSlice {
|
||||
modelsError: string | null;
|
||||
error: string | null;
|
||||
client: ConfigStoreClient | null;
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
// === Store Actions Slice ===
|
||||
@@ -208,6 +209,7 @@ export const useConfigStore = create<ConfigStateSlice & ConfigActionsSlice>((set
|
||||
modelsError: null,
|
||||
error: null,
|
||||
client: null,
|
||||
isLoading: false,
|
||||
|
||||
// Client Injection
|
||||
setConfigStoreClient: (client: ConfigStoreClient) => {
|
||||
|
||||
@@ -24,8 +24,6 @@ import {
|
||||
type LocalGatewayStatus,
|
||||
} from '../lib/tauri-gateway';
|
||||
import {
|
||||
performHealthCheck,
|
||||
createHealthCheckScheduler,
|
||||
type HealthCheckResult,
|
||||
type HealthStatus,
|
||||
} from '../lib/health-check';
|
||||
@@ -165,6 +163,8 @@ export const useConnectionStore = create<ConnectionStore>((set, get) => {
|
||||
localGateway: getUnsupportedLocalGatewayStatus(),
|
||||
localGatewayBusy: false,
|
||||
isLoading: false,
|
||||
healthStatus: 'unknown',
|
||||
healthCheckResult: null,
|
||||
client,
|
||||
|
||||
// === Actions ===
|
||||
|
||||
@@ -6,7 +6,11 @@
|
||||
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
import { getMemoryManager, type MemoryEntry, type MemoryType } from '../lib/agent-memory';
|
||||
import {
|
||||
intelligenceClient,
|
||||
type MemoryEntry,
|
||||
type MemoryType,
|
||||
} from '../lib/intelligence-client';
|
||||
|
||||
export type { MemoryType };
|
||||
|
||||
@@ -184,8 +188,10 @@ export const useMemoryGraphStore = create<MemoryGraphStore>()(
|
||||
set({ isLoading: true, error: null });
|
||||
|
||||
try {
|
||||
const mgr = getMemoryManager();
|
||||
const memories = await mgr.getAll(agentId, { limit: 200 });
|
||||
const memories = await intelligenceClient.memory.search({
|
||||
agentId,
|
||||
limit: 200,
|
||||
});
|
||||
|
||||
const nodes = memories.map((m, i) => memoryToNode(m, i, memories.length));
|
||||
const edges = findRelatedMemories(memories);
|
||||
|
||||
Reference in New Issue
Block a user