Files
WechatExplorer/src/main/knowledge/knowledge-service.ts
T
2026-08-06 20:29:25 +08:00

55 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { join } from 'path'
import type {
KnowledgeCapacityPreflight,
KnowledgeCapacityPreflightRequest,
KnowledgeIndexProgress,
KnowledgeIndexRequest,
KnowledgeIndexResult,
KnowledgeRuntimeStatus,
KnowledgeSearchRequest,
KnowledgeSearchResult,
KnowledgeStatusRequest
} from '../../shared/knowledge'
import { KnowledgeWorkerHost } from './knowledge-worker-host'
/** Minimal main-process service; no renderer API is exposed in Task 0Task 2. */
export class KnowledgeService {
private readonly worker: KnowledgeWorkerHost
constructor(userDataPath: string, workerPath: string) {
this.worker = new KnowledgeWorkerHost(workerPath)
this.databaseRoot = join(userDataPath, 'knowledge')
}
private readonly databaseRoot: string
index(
request: Omit<KnowledgeIndexRequest, 'databaseRoot'>,
onProgress?: (progress: KnowledgeIndexProgress) => void
): Promise<KnowledgeIndexResult> {
return this.worker.index({ ...request, databaseRoot: this.databaseRoot }, onProgress)
}
preflight(
request: Omit<KnowledgeCapacityPreflightRequest, 'databaseRoot'>
): Promise<KnowledgeCapacityPreflight> {
return this.worker.preflight({ ...request, databaseRoot: this.databaseRoot })
}
remove(accountId: string): Promise<{ removed: true }> {
return this.worker.remove(accountId, this.databaseRoot)
}
search(request: Omit<KnowledgeSearchRequest, 'databaseRoot'>): Promise<KnowledgeSearchResult> {
return this.worker.search({ ...request, databaseRoot: this.databaseRoot })
}
status(request: Omit<KnowledgeStatusRequest, 'databaseRoot'>): Promise<KnowledgeRuntimeStatus> {
return this.worker.status({ ...request, databaseRoot: this.databaseRoot })
}
dispose(): Promise<void> {
return this.worker.dispose()
}
}