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
Batch 1 — User-facing fixes: - B1-1: Pipeline verified end-to-end (14 Rust commands, 8 frontend invoke, fully connected) - B1-2: MessageSearch restored to ChatArea with search button in DeerFlow header - B1-3: Viking cleanup — removed 5 orphan invokes (no Rust impl), added addWithMetadata + storeWithSummaries methods + summary generation UI - B1-4: api-fallbacks transparency — added _isFallback markers + console.warn to all 6 fallback functions Batch 2 — System health: - B2-1: Document drift calibration — TRUTH.md/README.md numbers verified and updated - B2-2: @reserved annotations on 15 SaaS handler functions with no frontend callers - B2-3: Scheduled Task Admin V2 — new service + page + route + sidebar navigation - B2-4: TRUTH.md Pipeline/Viking/ScheduledTask records corrected Batch 3 — Long-term quality: - B3-1: hand_run_status/hand_run_list verified as fully implemented (not stubs) - B3-2: Identity snapshot rollback UI added to RightPanel - B3-3: P2 code quality — 4 fixes (TODO comments, fire-and-forget notes, design notes, table name validation), 2 verified N/A, 1 upstream - B3-4: Config PATCH→PUT alignment (admin-v2 config.ts matched to SaaS backend)
220 lines
4.6 KiB
TypeScript
220 lines
4.6 KiB
TypeScript
/**
|
|
* 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 metadata (keywords + importance)
|
|
*/
|
|
export async function addVikingResourceWithMetadata(
|
|
uri: string,
|
|
content: string,
|
|
keywords: string[],
|
|
importance?: number
|
|
): Promise<VikingAddResult> {
|
|
return invoke<VikingAddResult>('viking_add_with_metadata', { uri, content, keywords, importance });
|
|
}
|
|
|
|
/**
|
|
* 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 });
|
|
}
|
|
|
|
// === Summary Generation Functions ===
|
|
|
|
/**
|
|
* Store a resource and auto-generate L0/L1 summaries via configured LLM driver
|
|
*/
|
|
export async function storeWithSummaries(
|
|
uri: string,
|
|
content: string
|
|
): Promise<VikingAddResult> {
|
|
return invoke<VikingAddResult>('viking_store_with_summaries', { uri, content });
|
|
}
|
|
|
|
// === Memory Extraction Functions ===
|
|
|
|
export interface ChatMessageForExtraction {
|
|
role: string;
|
|
content: string;
|
|
timestamp?: string;
|
|
}
|
|
|
|
export interface ExtractedMemory {
|
|
category: 'user_preference' | 'user_fact' | 'agent_lesson' | 'agent_pattern' | 'task';
|
|
content: string;
|
|
tags: string[];
|
|
importance: number;
|
|
suggestedUri: string;
|
|
reasoning?: string;
|
|
}
|
|
|
|
export interface ExtractionResult {
|
|
memories: ExtractedMemory[];
|
|
summary: string;
|
|
tokensSaved?: number;
|
|
extractionTimeMs: number;
|
|
}
|
|
|
|
/**
|
|
* Extract memories from conversation session
|
|
*/
|
|
export async function extractSessionMemories(
|
|
messages: ChatMessageForExtraction[],
|
|
agentId: string
|
|
): Promise<ExtractionResult> {
|
|
return invoke<ExtractionResult>('extract_session_memories', { messages, agentId });
|
|
}
|
|
|
|
/**
|
|
* Extract memories and store to SqliteStorage in one call
|
|
*/
|
|
export async function extractAndStoreMemories(
|
|
messages: ChatMessageForExtraction[],
|
|
agentId: string,
|
|
llmEndpoint?: string,
|
|
llmApiKey?: string
|
|
): Promise<ExtractionResult> {
|
|
return invoke<ExtractionResult>('extract_and_store_memories', {
|
|
messages,
|
|
agentId,
|
|
llmEndpoint,
|
|
llmApiKey,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Inject relevant memories into prompt for enhanced context
|
|
*/
|
|
export async function injectVikingPrompt(
|
|
agentId: string,
|
|
basePrompt: string,
|
|
userInput: string,
|
|
maxTokens?: number
|
|
): Promise<string> {
|
|
return invoke<string>('viking_inject_prompt', {
|
|
agentId,
|
|
basePrompt,
|
|
userInput,
|
|
maxTokens,
|
|
});
|
|
}
|