refactor: 清理未使用代码并添加未来功能标记
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
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
style: 统一代码格式和注释风格 docs: 更新多个功能文档的完整度和状态 feat(runtime): 添加路径验证工具支持 fix(pipeline): 改进条件判断和变量解析逻辑 test(types): 为ID类型添加全面测试用例 chore: 更新依赖项和Cargo.lock文件 perf(mcp): 优化MCP协议传输和错误处理
This commit is contained in:
@@ -43,10 +43,13 @@ export interface WorkspaceInfo {
|
||||
export interface ChannelInfo {
|
||||
id: string;
|
||||
type: string;
|
||||
name: string;
|
||||
label: string;
|
||||
status: 'active' | 'inactive' | 'error';
|
||||
enabled?: boolean;
|
||||
accounts?: number;
|
||||
error?: string;
|
||||
config?: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface ScheduledTask {
|
||||
@@ -292,12 +295,13 @@ export const useConfigStore = create<ConfigStateSlice & ConfigActionsSlice>((set
|
||||
channels.push({
|
||||
id: 'feishu',
|
||||
type: 'feishu',
|
||||
name: 'feishu',
|
||||
label: '飞书 (Feishu)',
|
||||
status: feishu?.configured ? 'active' : 'inactive',
|
||||
accounts: feishu?.accounts || 0,
|
||||
});
|
||||
} catch {
|
||||
channels.push({ id: 'feishu', type: 'feishu', label: '飞书 (Feishu)', status: 'inactive' });
|
||||
channels.push({ id: 'feishu', type: 'feishu', name: 'feishu', label: '飞书 (Feishu)', status: 'inactive' });
|
||||
}
|
||||
|
||||
set({ channels });
|
||||
|
||||
161
desktop/src/store/meshStore.ts
Normal file
161
desktop/src/store/meshStore.ts
Normal file
@@ -0,0 +1,161 @@
|
||||
/**
|
||||
* Mesh Store - State management for Adaptive Intelligence Mesh
|
||||
*
|
||||
* Manages workflow recommendations and behavior patterns.
|
||||
*/
|
||||
|
||||
import { create } from 'zustand';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import type {
|
||||
WorkflowRecommendation,
|
||||
BehaviorPattern,
|
||||
MeshConfig,
|
||||
MeshAnalysisResult,
|
||||
PatternContext,
|
||||
ActivityType,
|
||||
} from '../lib/intelligence-client';
|
||||
|
||||
// === Types ===
|
||||
|
||||
export interface MeshState {
|
||||
// State
|
||||
recommendations: WorkflowRecommendation[];
|
||||
patterns: BehaviorPattern[];
|
||||
config: MeshConfig;
|
||||
isLoading: boolean;
|
||||
error: string | null;
|
||||
lastAnalysis: string | null;
|
||||
|
||||
// Actions
|
||||
analyze: () => Promise<void>;
|
||||
acceptRecommendation: (recommendationId: string) => Promise<void>;
|
||||
dismissRecommendation: (recommendationId: string) => Promise<void>;
|
||||
recordActivity: (activity: ActivityType, context: PatternContext) => Promise<void>;
|
||||
getPatterns: () => Promise<void>;
|
||||
updateConfig: (config: Partial<MeshConfig>) => Promise<void>;
|
||||
decayPatterns: () => Promise<void>;
|
||||
clearError: () => void;
|
||||
}
|
||||
|
||||
// === Store ===
|
||||
|
||||
export const useMeshStore = create<MeshState>((set, get) => ({
|
||||
// Initial state
|
||||
recommendations: [],
|
||||
patterns: [],
|
||||
config: {
|
||||
enabled: true,
|
||||
min_confidence: 0.6,
|
||||
max_recommendations: 5,
|
||||
analysis_window_hours: 24,
|
||||
},
|
||||
isLoading: false,
|
||||
error: null,
|
||||
lastAnalysis: null,
|
||||
|
||||
// Actions
|
||||
analyze: async () => {
|
||||
set({ isLoading: true, error: null });
|
||||
try {
|
||||
const agentId = localStorage.getItem('currentAgentId') || 'default';
|
||||
const result = await invoke<MeshAnalysisResult>('mesh_analyze', { agentId });
|
||||
|
||||
set({
|
||||
recommendations: result.recommendations,
|
||||
patterns: [], // Will be populated by getPatterns
|
||||
lastAnalysis: result.timestamp,
|
||||
isLoading: false,
|
||||
});
|
||||
|
||||
// Also fetch patterns
|
||||
await get().getPatterns();
|
||||
} catch (err) {
|
||||
set({
|
||||
error: err instanceof Error ? err.message : String(err),
|
||||
isLoading: false,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
acceptRecommendation: async (recommendationId: string) => {
|
||||
try {
|
||||
const agentId = localStorage.getItem('currentAgentId') || 'default';
|
||||
await invoke('mesh_accept_recommendation', { agentId, recommendationId });
|
||||
|
||||
// Remove from local state
|
||||
set((state) => ({
|
||||
recommendations: state.recommendations.filter((r) => r.id !== recommendationId),
|
||||
}));
|
||||
} catch (err) {
|
||||
set({ error: err instanceof Error ? err.message : String(err) });
|
||||
}
|
||||
},
|
||||
|
||||
dismissRecommendation: async (recommendationId: string) => {
|
||||
try {
|
||||
const agentId = localStorage.getItem('currentAgentId') || 'default';
|
||||
await invoke('mesh_dismiss_recommendation', { agentId, recommendationId });
|
||||
|
||||
// Remove from local state
|
||||
set((state) => ({
|
||||
recommendations: state.recommendations.filter((r) => r.id !== recommendationId),
|
||||
}));
|
||||
} catch (err) {
|
||||
set({ error: err instanceof Error ? err.message : String(err) });
|
||||
}
|
||||
},
|
||||
|
||||
recordActivity: async (activity: ActivityType, context: PatternContext) => {
|
||||
try {
|
||||
const agentId = localStorage.getItem('currentAgentId') || 'default';
|
||||
await invoke('mesh_record_activity', { agentId, activityType: activity, context });
|
||||
} catch (err) {
|
||||
console.error('Failed to record activity:', err);
|
||||
}
|
||||
},
|
||||
|
||||
getPatterns: async () => {
|
||||
try {
|
||||
const agentId = localStorage.getItem('currentAgentId') || 'default';
|
||||
const patterns = await invoke<BehaviorPattern[]>('mesh_get_patterns', { agentId });
|
||||
set({ patterns });
|
||||
} catch (err) {
|
||||
console.error('Failed to get patterns:', err);
|
||||
}
|
||||
},
|
||||
|
||||
updateConfig: async (config: Partial<MeshConfig>) => {
|
||||
try {
|
||||
const agentId = localStorage.getItem('currentAgentId') || 'default';
|
||||
const newConfig = { ...get().config, ...config };
|
||||
await invoke('mesh_update_config', { agentId, config: newConfig });
|
||||
set({ config: newConfig });
|
||||
} catch (err) {
|
||||
set({ error: err instanceof Error ? err.message : String(err) });
|
||||
}
|
||||
},
|
||||
|
||||
decayPatterns: async () => {
|
||||
try {
|
||||
const agentId = localStorage.getItem('currentAgentId') || 'default';
|
||||
await invoke('mesh_decay_patterns', { agentId });
|
||||
// Refresh patterns after decay
|
||||
await get().getPatterns();
|
||||
} catch (err) {
|
||||
console.error('Failed to decay patterns:', err);
|
||||
}
|
||||
},
|
||||
|
||||
clearError: () => set({ error: null }),
|
||||
}));
|
||||
|
||||
// === Types for intelligence-client ===
|
||||
|
||||
export type {
|
||||
WorkflowRecommendation,
|
||||
BehaviorPattern,
|
||||
MeshConfig,
|
||||
MeshAnalysisResult,
|
||||
PatternContext,
|
||||
ActivityType,
|
||||
};
|
||||
195
desktop/src/store/personaStore.ts
Normal file
195
desktop/src/store/personaStore.ts
Normal file
@@ -0,0 +1,195 @@
|
||||
/**
|
||||
* Persona Evolution Store
|
||||
*
|
||||
* Manages persona evolution state and proposals.
|
||||
*/
|
||||
|
||||
import { create } from 'zustand';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import type {
|
||||
EvolutionResult,
|
||||
EvolutionProposal,
|
||||
PersonaEvolverConfig,
|
||||
PersonaEvolverState,
|
||||
MemoryEntryForAnalysis,
|
||||
} from '../lib/intelligence-client';
|
||||
|
||||
export interface PersonaEvolutionStore {
|
||||
// State
|
||||
currentAgentId: string;
|
||||
proposals: EvolutionProposal[];
|
||||
history: EvolutionResult[];
|
||||
isLoading: boolean;
|
||||
error: string | null;
|
||||
config: PersonaEvolverConfig | null;
|
||||
state: PersonaEvolverState | null;
|
||||
showProposalsPanel: boolean;
|
||||
|
||||
// Actions
|
||||
setCurrentAgentId: (agentId: string) => void;
|
||||
setShowProposalsPanel: (show: boolean) => void;
|
||||
|
||||
// Evolution Actions
|
||||
runEvolution: (memories: MemoryEntryForAnalysis[]) => Promise<EvolutionResult | null>;
|
||||
loadEvolutionHistory: (limit?: number) => Promise<void>;
|
||||
loadEvolverState: () => Promise<void>;
|
||||
loadEvolverConfig: () => Promise<void>;
|
||||
updateConfig: (config: Partial<PersonaEvolverConfig>) => Promise<void>;
|
||||
|
||||
// Proposal Actions
|
||||
getPendingProposals: () => EvolutionProposal[];
|
||||
applyProposal: (proposal: EvolutionProposal) => Promise<boolean>;
|
||||
dismissProposal: (proposalId: string) => void;
|
||||
clearProposals: () => void;
|
||||
}
|
||||
|
||||
export const usePersonaEvolutionStore = create<PersonaEvolutionStore>((set, get) => ({
|
||||
// Initial State
|
||||
currentAgentId: '',
|
||||
proposals: [],
|
||||
history: [],
|
||||
isLoading: false,
|
||||
error: null,
|
||||
config: null,
|
||||
state: null,
|
||||
showProposalsPanel: false,
|
||||
|
||||
// Setters
|
||||
setCurrentAgentId: (agentId: string) => set({ currentAgentId: agentId }),
|
||||
setShowProposalsPanel: (show: boolean) => set({ showProposalsPanel: show }),
|
||||
|
||||
// Run evolution cycle for current agent
|
||||
runEvolution: async (memories: MemoryEntryForAnalysis[]) => {
|
||||
const { currentAgentId } = get();
|
||||
if (!currentAgentId) {
|
||||
set({ error: 'No agent selected' });
|
||||
return null;
|
||||
}
|
||||
|
||||
set({ isLoading: true, error: null });
|
||||
|
||||
try {
|
||||
const result = await invoke<EvolutionResult>('persona_evolve', {
|
||||
agentId: currentAgentId,
|
||||
memories,
|
||||
});
|
||||
|
||||
// Update state with results
|
||||
set((state) => ({
|
||||
history: [result, ...state.history].slice(0, 20),
|
||||
proposals: [...result.proposals, ...state.proposals],
|
||||
isLoading: false,
|
||||
showProposalsPanel: result.proposals.length > 0,
|
||||
}));
|
||||
|
||||
return result;
|
||||
} catch (err) {
|
||||
const errorMsg = err instanceof Error ? err.message : String(err);
|
||||
set({ error: errorMsg, isLoading: false });
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
// Load evolution history
|
||||
loadEvolutionHistory: async (limit = 10) => {
|
||||
set({ isLoading: true, error: null });
|
||||
|
||||
try {
|
||||
const history = await invoke<EvolutionResult[]>('persona_evolution_history', {
|
||||
limit,
|
||||
});
|
||||
set({ history, isLoading: false });
|
||||
} catch (err) {
|
||||
const errorMsg = err instanceof Error ? err.message : String(err);
|
||||
set({ error: errorMsg, isLoading: false });
|
||||
}
|
||||
},
|
||||
|
||||
// Load evolver state
|
||||
loadEvolverState: async () => {
|
||||
try {
|
||||
const state = await invoke<PersonaEvolverState>('persona_evolver_state');
|
||||
set({ state });
|
||||
} catch (err) {
|
||||
console.error('[PersonaStore] Failed to load evolver state:', err);
|
||||
}
|
||||
},
|
||||
|
||||
// Load evolver config
|
||||
loadEvolverConfig: async () => {
|
||||
try {
|
||||
const config = await invoke<PersonaEvolverConfig>('persona_evolver_config');
|
||||
set({ config });
|
||||
} catch (err) {
|
||||
console.error('[PersonaStore] Failed to load evolver config:', err);
|
||||
}
|
||||
},
|
||||
|
||||
// Update evolver config
|
||||
updateConfig: async (newConfig: Partial<PersonaEvolverConfig>) => {
|
||||
const { config } = get();
|
||||
if (!config) return;
|
||||
|
||||
const updatedConfig = { ...config, ...newConfig };
|
||||
|
||||
try {
|
||||
await invoke('persona_evolver_update_config', { config: updatedConfig });
|
||||
set({ config: updatedConfig });
|
||||
} catch (err) {
|
||||
const errorMsg = err instanceof Error ? err.message : String(err);
|
||||
set({ error: errorMsg });
|
||||
}
|
||||
},
|
||||
|
||||
// Get pending proposals sorted by confidence
|
||||
getPendingProposals: () => {
|
||||
const { proposals } = get();
|
||||
return proposals
|
||||
.filter((p) => p.status === 'pending')
|
||||
.sort((a, b) => b.confidence - a.confidence);
|
||||
},
|
||||
|
||||
// Apply a proposal (approve)
|
||||
applyProposal: async (proposal: EvolutionProposal) => {
|
||||
set({ isLoading: true, error: null });
|
||||
|
||||
try {
|
||||
await invoke('persona_apply_proposal', { proposal });
|
||||
|
||||
// Remove from pending list
|
||||
set((state) => ({
|
||||
proposals: state.proposals.filter((p) => p.id !== proposal.id),
|
||||
isLoading: false,
|
||||
}));
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
const errorMsg = err instanceof Error ? err.message : String(err);
|
||||
set({ error: errorMsg, isLoading: false });
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
// Dismiss a proposal (reject)
|
||||
dismissProposal: (proposalId: string) => {
|
||||
set((state) => ({
|
||||
proposals: state.proposals.filter((p) => p.id !== proposalId),
|
||||
}));
|
||||
},
|
||||
|
||||
// Clear all proposals
|
||||
clearProposals: () => set({ proposals: [] }),
|
||||
}));
|
||||
|
||||
// Export convenience hooks
|
||||
export const usePendingProposals = () =>
|
||||
usePersonaEvolutionStore((state) => state.getPendingProposals());
|
||||
|
||||
export const useEvolutionHistory = () =>
|
||||
usePersonaEvolutionStore((state) => state.history);
|
||||
|
||||
export const useEvolverConfig = () =>
|
||||
usePersonaEvolutionStore((state) => state.config);
|
||||
|
||||
export const useEvolverState = () =>
|
||||
usePersonaEvolutionStore((state) => state.state);
|
||||
Reference in New Issue
Block a user