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:
@@ -128,8 +128,142 @@ export type {
|
||||
IdentityFiles,
|
||||
IdentityChangeProposal,
|
||||
IdentitySnapshot,
|
||||
MemoryEntryForAnalysis,
|
||||
} from './intelligence-backend';
|
||||
|
||||
// === Mesh Types ===
|
||||
|
||||
export interface BehaviorPattern {
|
||||
id: string;
|
||||
pattern_type: PatternTypeVariant;
|
||||
frequency: number;
|
||||
last_occurrence: string;
|
||||
first_occurrence: string;
|
||||
confidence: number;
|
||||
context: PatternContext;
|
||||
}
|
||||
|
||||
export function getPatternTypeString(patternType: PatternTypeVariant): string {
|
||||
if (typeof patternType === 'string') {
|
||||
return patternType;
|
||||
}
|
||||
return patternType.type;
|
||||
}
|
||||
|
||||
export type PatternTypeVariant =
|
||||
| { type: 'SkillCombination'; skill_ids: string[] }
|
||||
| { type: 'TemporalTrigger'; hand_id: string; time_pattern: string }
|
||||
| { type: 'TaskPipelineMapping'; task_type: string; pipeline_id: string }
|
||||
| { type: 'InputPattern'; keywords: string[]; intent: string };
|
||||
|
||||
export interface PatternContext {
|
||||
skill_ids?: string[];
|
||||
recent_topics?: string[];
|
||||
intent?: string;
|
||||
time_of_day?: number;
|
||||
day_of_week?: number;
|
||||
}
|
||||
|
||||
export interface WorkflowRecommendation {
|
||||
id: string;
|
||||
pipeline_id: string;
|
||||
confidence: number;
|
||||
reason: string;
|
||||
suggested_inputs: Record<string, unknown>;
|
||||
patterns_matched: string[];
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
export interface MeshConfig {
|
||||
enabled: boolean;
|
||||
min_confidence: number;
|
||||
max_recommendations: number;
|
||||
analysis_window_hours: number;
|
||||
}
|
||||
|
||||
export interface MeshAnalysisResult {
|
||||
recommendations: WorkflowRecommendation[];
|
||||
patterns_detected: number;
|
||||
timestamp: string;
|
||||
}
|
||||
|
||||
export type ActivityType =
|
||||
| { type: 'skill_used'; skill_ids: string[] }
|
||||
| { type: 'pipeline_executed'; task_type: string; pipeline_id: string }
|
||||
| { type: 'input_received'; keywords: string[]; intent: string };
|
||||
|
||||
// === Persona Evolver Types ===
|
||||
|
||||
export type EvolutionChangeType =
|
||||
| 'instruction_addition'
|
||||
| 'instruction_refinement'
|
||||
| 'trait_addition'
|
||||
| 'style_adjustment'
|
||||
| 'domain_expansion';
|
||||
|
||||
export type InsightCategory =
|
||||
| 'communication_style'
|
||||
| 'technical_expertise'
|
||||
| 'task_efficiency'
|
||||
| 'user_preference'
|
||||
| 'knowledge_gap';
|
||||
|
||||
export type IdentityFileType = 'soul' | 'instructions';
|
||||
export type ProposalStatus = 'pending' | 'approved' | 'rejected';
|
||||
|
||||
export interface EvolutionProposal {
|
||||
id: string;
|
||||
agent_id: string;
|
||||
target_file: IdentityFileType;
|
||||
change_type: EvolutionChangeType;
|
||||
reason: string;
|
||||
current_content: string;
|
||||
proposed_content: string;
|
||||
confidence: number;
|
||||
evidence: string[];
|
||||
status: ProposalStatus;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface ProfileUpdate {
|
||||
section: string;
|
||||
previous: string;
|
||||
updated: string;
|
||||
source: string;
|
||||
}
|
||||
|
||||
export interface EvolutionInsight {
|
||||
category: InsightCategory;
|
||||
observation: string;
|
||||
recommendation: string;
|
||||
confidence: number;
|
||||
}
|
||||
|
||||
export interface EvolutionResult {
|
||||
agent_id: string;
|
||||
timestamp: string;
|
||||
profile_updates: ProfileUpdate[];
|
||||
proposals: EvolutionProposal[];
|
||||
insights: EvolutionInsight[];
|
||||
evolved: boolean;
|
||||
}
|
||||
|
||||
export interface PersonaEvolverConfig {
|
||||
auto_profile_update: boolean;
|
||||
min_preferences_for_update: number;
|
||||
min_conversations_for_evolution: number;
|
||||
enable_instruction_refinement: boolean;
|
||||
enable_soul_evolution: boolean;
|
||||
max_proposals_per_cycle: number;
|
||||
}
|
||||
|
||||
export interface PersonaEvolverState {
|
||||
last_evolution: string | null;
|
||||
total_evolutions: number;
|
||||
pending_proposals: number;
|
||||
profile_enrichment_score: number;
|
||||
}
|
||||
|
||||
// === Type Conversion Utilities ===
|
||||
|
||||
/**
|
||||
|
||||
@@ -753,36 +753,210 @@ export class KernelClient {
|
||||
});
|
||||
}
|
||||
|
||||
// === Triggers API (stubs for compatibility) ===
|
||||
// === Triggers API ===
|
||||
|
||||
async listTriggers(): Promise<{ triggers?: { id: string; type: string; enabled: boolean }[] }> {
|
||||
return { triggers: [] };
|
||||
/**
|
||||
* List all triggers
|
||||
* Returns empty array on error for graceful degradation
|
||||
*/
|
||||
async listTriggers(): Promise<{
|
||||
triggers?: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
handId: string;
|
||||
triggerType: string;
|
||||
enabled: boolean;
|
||||
createdAt: string;
|
||||
modifiedAt: string;
|
||||
description?: string;
|
||||
tags: string[];
|
||||
}>
|
||||
}> {
|
||||
try {
|
||||
const triggers = await invoke<Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
handId: string;
|
||||
triggerType: string;
|
||||
enabled: boolean;
|
||||
createdAt: string;
|
||||
modifiedAt: string;
|
||||
description?: string;
|
||||
tags: string[];
|
||||
}>>('trigger_list');
|
||||
return { triggers };
|
||||
} catch (error) {
|
||||
this.log('error', `[TriggersAPI] listTriggers failed: ${this.formatError(error)}`);
|
||||
return { triggers: [] };
|
||||
}
|
||||
}
|
||||
|
||||
async getTrigger(_id: string): Promise<{ id: string; type: string; enabled: boolean } | null> {
|
||||
return null;
|
||||
/**
|
||||
* Get a single trigger by ID
|
||||
* Returns null on error for graceful degradation
|
||||
*/
|
||||
async getTrigger(id: string): Promise<{
|
||||
id: string;
|
||||
name: string;
|
||||
handId: string;
|
||||
triggerType: string;
|
||||
enabled: boolean;
|
||||
createdAt: string;
|
||||
modifiedAt: string;
|
||||
description?: string;
|
||||
tags: string[];
|
||||
} | null> {
|
||||
try {
|
||||
return await invoke<{
|
||||
id: string;
|
||||
name: string;
|
||||
handId: string;
|
||||
triggerType: string;
|
||||
enabled: boolean;
|
||||
createdAt: string;
|
||||
modifiedAt: string;
|
||||
description?: string;
|
||||
tags: string[];
|
||||
} | null>('trigger_get', { id });
|
||||
} catch (error) {
|
||||
this.log('error', `[TriggersAPI] getTrigger(${id}) failed: ${this.formatError(error)}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async createTrigger(_trigger: { type: string; name?: string; enabled?: boolean; config?: Record<string, unknown>; handName?: string; workflowId?: string }): Promise<{ id?: string } | null> {
|
||||
return null;
|
||||
/**
|
||||
* Create a new trigger
|
||||
* Returns null on error for graceful degradation
|
||||
*/
|
||||
async createTrigger(trigger: {
|
||||
id: string;
|
||||
name: string;
|
||||
handId: string;
|
||||
triggerType: { type: string; cron?: string; pattern?: string; path?: string; secret?: string; events?: string[] };
|
||||
enabled?: boolean;
|
||||
description?: string;
|
||||
tags?: string[];
|
||||
}): Promise<{
|
||||
id: string;
|
||||
name: string;
|
||||
handId: string;
|
||||
triggerType: string;
|
||||
enabled: boolean;
|
||||
createdAt: string;
|
||||
modifiedAt: string;
|
||||
description?: string;
|
||||
tags: string[];
|
||||
} | null> {
|
||||
try {
|
||||
return await invoke<{
|
||||
id: string;
|
||||
name: string;
|
||||
handId: string;
|
||||
triggerType: string;
|
||||
enabled: boolean;
|
||||
createdAt: string;
|
||||
modifiedAt: string;
|
||||
description?: string;
|
||||
tags: string[];
|
||||
}>('trigger_create', { request: trigger });
|
||||
} catch (error) {
|
||||
this.log('error', `[TriggersAPI] createTrigger(${trigger.id}) failed: ${this.formatError(error)}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async updateTrigger(_id: string, _updates: { name?: string; enabled?: boolean; config?: Record<string, unknown>; handName?: string; workflowId?: string }): Promise<{ id: string }> {
|
||||
throw new Error('Triggers not implemented');
|
||||
/**
|
||||
* Update an existing trigger
|
||||
* Throws on error as this is a mutation operation that callers need to handle
|
||||
*/
|
||||
async updateTrigger(id: string, updates: {
|
||||
name?: string;
|
||||
enabled?: boolean;
|
||||
handId?: string;
|
||||
triggerType?: { type: string; cron?: string; pattern?: string; path?: string; secret?: string; events?: string[] };
|
||||
}): Promise<{
|
||||
id: string;
|
||||
name: string;
|
||||
handId: string;
|
||||
triggerType: string;
|
||||
enabled: boolean;
|
||||
createdAt: string;
|
||||
modifiedAt: string;
|
||||
description?: string;
|
||||
tags: string[];
|
||||
}> {
|
||||
try {
|
||||
return await invoke<{
|
||||
id: string;
|
||||
name: string;
|
||||
handId: string;
|
||||
triggerType: string;
|
||||
enabled: boolean;
|
||||
createdAt: string;
|
||||
modifiedAt: string;
|
||||
description?: string;
|
||||
tags: string[];
|
||||
}>('trigger_update', { id, updates });
|
||||
} catch (error) {
|
||||
this.log('error', `[TriggersAPI] updateTrigger(${id}) failed: ${this.formatError(error)}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async deleteTrigger(_id: string): Promise<{ status: string }> {
|
||||
throw new Error('Triggers not implemented');
|
||||
/**
|
||||
* Delete a trigger
|
||||
* Throws on error as this is a destructive operation that callers need to handle
|
||||
*/
|
||||
async deleteTrigger(id: string): Promise<void> {
|
||||
try {
|
||||
await invoke('trigger_delete', { id });
|
||||
} catch (error) {
|
||||
this.log('error', `[TriggersAPI] deleteTrigger(${id}) failed: ${this.formatError(error)}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// === Approvals API (stubs for compatibility) ===
|
||||
|
||||
async listApprovals(_status?: string): Promise<{ approvals?: unknown[] }> {
|
||||
return { approvals: [] };
|
||||
/**
|
||||
* Execute a trigger
|
||||
* Throws on error as callers need to know if execution failed
|
||||
*/
|
||||
async executeTrigger(id: string, input?: Record<string, unknown>): Promise<Record<string, unknown>> {
|
||||
try {
|
||||
return await invoke<Record<string, unknown>>('trigger_execute', { id, input: input || {} });
|
||||
} catch (error) {
|
||||
this.log('error', `[TriggersAPI] executeTrigger(${id}) failed: ${this.formatError(error)}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async respondToApproval(_approvalId: string, _approved: boolean, _reason?: string): Promise<{ status: string }> {
|
||||
throw new Error('Approvals not implemented');
|
||||
// === Approvals API ===
|
||||
|
||||
async listApprovals(_status?: string): Promise<{
|
||||
approvals: Array<{
|
||||
id: string;
|
||||
handId: string;
|
||||
status: string;
|
||||
createdAt: string;
|
||||
input: Record<string, unknown>;
|
||||
}>
|
||||
}> {
|
||||
try {
|
||||
const approvals = await invoke<Array<{
|
||||
id: string;
|
||||
handId: string;
|
||||
status: string;
|
||||
createdAt: string;
|
||||
input: Record<string, unknown>;
|
||||
}>>('approval_list');
|
||||
return { approvals };
|
||||
} catch (error) {
|
||||
console.error('[kernel-client] listApprovals error:', error);
|
||||
return { approvals: [] };
|
||||
}
|
||||
}
|
||||
|
||||
async respondToApproval(approvalId: string, approved: boolean, reason?: string): Promise<void> {
|
||||
return invoke('approval_respond', { id: approvalId, approved, reason });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -871,6 +1045,16 @@ export class KernelClient {
|
||||
private log(level: string, message: string): void {
|
||||
this.onLog?.(level, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format error for consistent logging
|
||||
*/
|
||||
private formatError(error: unknown): string {
|
||||
if (error instanceof Error) {
|
||||
return error.message;
|
||||
}
|
||||
return String(error);
|
||||
}
|
||||
}
|
||||
|
||||
// === Singleton ===
|
||||
|
||||
@@ -139,7 +139,6 @@ export class PipelineRecommender {
|
||||
}
|
||||
|
||||
const recommendations: PipelineRecommendation[] = [];
|
||||
const messageLower = message.toLowerCase();
|
||||
|
||||
for (const pattern of INTENT_PATTERNS) {
|
||||
const matches = pattern.keywords
|
||||
|
||||
174
desktop/src/lib/viking-client.ts
Normal file
174
desktop/src/lib/viking-client.ts
Normal file
@@ -0,0 +1,174 @@
|
||||
/**
|
||||
* OpenViking Client - Semantic Memory Operations
|
||||
*
|
||||
* Client for interacting with OpenViking CLI sidecar.
|
||||
* Provides semantic search, resource management, and knowledge base operations.
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
|
||||
// === Types ===
|
||||
|
||||
export interface VikingStatus {
|
||||
available: boolean;
|
||||
version?: string;
|
||||
dataDir?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface VikingResource {
|
||||
uri: string;
|
||||
name: string;
|
||||
resourceType: string;
|
||||
size?: number;
|
||||
modifiedAt?: string;
|
||||
}
|
||||
|
||||
export interface VikingFindResult {
|
||||
uri: string;
|
||||
score: number;
|
||||
content: string;
|
||||
level: string;
|
||||
overview?: string;
|
||||
}
|
||||
|
||||
export interface VikingGrepResult {
|
||||
uri: string;
|
||||
line: number;
|
||||
content: string;
|
||||
matchStart: number;
|
||||
matchEnd: number;
|
||||
}
|
||||
|
||||
export interface VikingAddResult {
|
||||
uri: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
// === Client Functions ===
|
||||
|
||||
/**
|
||||
* Check if OpenViking CLI is available
|
||||
*/
|
||||
export async function getVikingStatus(): Promise<VikingStatus> {
|
||||
return invoke<VikingStatus>('viking_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a resource to OpenViking from file
|
||||
*/
|
||||
export async function addVikingResource(
|
||||
uri: string,
|
||||
content: string
|
||||
): Promise<VikingAddResult> {
|
||||
return invoke<VikingAddResult>('viking_add', { uri, content });
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a resource with inline content
|
||||
*/
|
||||
export async function addVikingResourceInline(
|
||||
uri: string,
|
||||
content: string
|
||||
): Promise<VikingAddResult> {
|
||||
return invoke<VikingAddResult>('viking_add_inline', { uri, content });
|
||||
}
|
||||
|
||||
/**
|
||||
* Find resources by semantic search
|
||||
*/
|
||||
export async function findVikingResources(
|
||||
query: string,
|
||||
scope?: string,
|
||||
limit?: number
|
||||
): Promise<VikingFindResult[]> {
|
||||
return invoke<VikingFindResult[]>('viking_find', { query, scope, limit });
|
||||
}
|
||||
|
||||
/**
|
||||
* Grep resources by pattern
|
||||
*/
|
||||
export async function grepVikingResources(
|
||||
pattern: string,
|
||||
uri?: string,
|
||||
caseSensitive?: boolean,
|
||||
limit?: number
|
||||
): Promise<VikingGrepResult[]> {
|
||||
return invoke<VikingGrepResult[]>('viking_grep', {
|
||||
pattern,
|
||||
uri,
|
||||
caseSensitive,
|
||||
limit,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* List resources at a path
|
||||
*/
|
||||
export async function listVikingResources(path: string): Promise<VikingResource[]> {
|
||||
return invoke<VikingResource[]>('viking_ls', { path });
|
||||
}
|
||||
|
||||
/**
|
||||
* Read resource content
|
||||
*/
|
||||
export async function readVikingResource(
|
||||
uri: string,
|
||||
level?: string
|
||||
): Promise<string> {
|
||||
return invoke<string>('viking_read', { uri, level });
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a resource
|
||||
*/
|
||||
export async function removeVikingResource(uri: string): Promise<void> {
|
||||
return invoke<void>('viking_remove', { uri });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resource tree
|
||||
*/
|
||||
export async function getVikingTree(
|
||||
path: string,
|
||||
depth?: number
|
||||
): Promise<Record<string, unknown>> {
|
||||
return invoke<Record<string, unknown>>('viking_tree', { path, depth });
|
||||
}
|
||||
|
||||
// === Server Functions ===
|
||||
|
||||
export interface VikingServerStatus {
|
||||
running: boolean;
|
||||
port?: number;
|
||||
pid?: number;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Viking server status
|
||||
*/
|
||||
export async function getVikingServerStatus(): Promise<VikingServerStatus> {
|
||||
return invoke<VikingServerStatus>('viking_server_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Viking server
|
||||
*/
|
||||
export async function startVikingServer(): Promise<void> {
|
||||
return invoke<void>('viking_server_start');
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop Viking server
|
||||
*/
|
||||
export async function stopVikingServer(): Promise<void> {
|
||||
return invoke<void>('viking_server_stop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Restart Viking server
|
||||
*/
|
||||
export async function restartVikingServer(): Promise<void> {
|
||||
return invoke<void>('viking_server_restart');
|
||||
}
|
||||
Reference in New Issue
Block a user