mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-10-05 12:34:35 +08:00
统一问问微信与 Agent Hub 的查询链路 完善查询覆盖度、新鲜度和部分结果表达,避免索引滞后产生错误结论 基于会话实现真正的增量追新与历史补齐 支持后台同步、取消恢复、重启续传以及同步期间继续查询 优化知识库跨会话检索、同步状态、进度展示和侧栏布局
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
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 0~Task 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 })
|
||
}
|
||
|
||
/** 每个会话已经索引到的源侧时刻(epoch ms);增量 pass 用它跳过没有变化的会话。 */
|
||
highWaterMarks(request: Omit<KnowledgeStatusRequest, 'databaseRoot'>): Promise<Record<string, number>> {
|
||
return this.worker.highWaterMarks({ ...request, databaseRoot: this.databaseRoot })
|
||
}
|
||
|
||
/** 只中止正在跑的索引任务;查询请求不受影响。 */
|
||
cancelIndex(): Promise<boolean> {
|
||
return this.worker.cancelActiveIndex()
|
||
}
|
||
|
||
dispose(): Promise<void> {
|
||
return this.worker.dispose()
|
||
}
|
||
}
|