Add Authority jobs task backend

This commit is contained in:
Youzini-afk
2026-04-28 03:53:29 +08:00
parent e28e9a693c
commit 1018376c85
6 changed files with 793 additions and 1 deletions

View File

@@ -1975,6 +1975,23 @@ function _refreshTaskPipelineOverview() {
if (pipelinePersistDeltaMeta) {
persistenceMetaParts.push(pipelinePersistDeltaMeta);
}
const authorityJob = loadInfo.authorityLastJob || {};
const authorityJobParts = [
authorityJob.id || loadInfo.authorityLastJobId
? `job ${authorityJob.id || loadInfo.authorityLastJobId}`
: "",
authorityJob.kind || loadInfo.authorityLastJobKind || "",
authorityJob.status || loadInfo.authorityLastJobStatus || "",
].filter(Boolean);
const authorityJobProgress = Number(
authorityJob.progress ?? loadInfo.authorityLastJobProgress,
);
if (Number.isFinite(authorityJobProgress) && authorityJobProgress > 0) {
authorityJobParts.push(`${Math.round(authorityJobProgress * 100)}%`);
}
if (loadInfo.authorityLastJobError) {
authorityJobParts.push(`error ${loadInfo.authorityLastJobError}`);
}
const persistence = _resolvePipelineStatus({
text: loadInfo.loadState || "unknown",
meta: persistenceMetaParts.join(" · "),
@@ -2026,7 +2043,16 @@ function _refreshTaskPipelineOverview() {
const statusRows = [
{ label: "提取", color: extraction.color, value: extraction.label + (extraction.detail ? `${extraction.detail}` : "") },
{ label: "向量", color: vector.color, value: vector.label + (vector.detail ? `${vector.detail}` : "") },
{
label: "向量",
color: vector.color,
value:
vector.label +
(vector.detail ? `${vector.detail}` : "") +
(authorityJobParts.length
? ` · Authority ${authorityJobParts.join(" · ")}`
: ""),
},
{ label: "召回", color: recall.color, value: recall.label + (recall.detail ? `${recall.detail}` : "") },
{ label: "持久化", color: persistence.color, value: persistence.label + (persistence.detail ? `${persistence.detail}` : "") },
];

View File

@@ -587,6 +587,32 @@ export async function onRebuildVectorIndexController(runtime, range = null) {
const vectorController = runtime.beginStageAbortController("vector");
try {
if (
!range &&
typeof runtime.shouldUseAuthorityJobs === "function" &&
runtime.shouldUseAuthorityJobs(config) &&
typeof runtime.submitAuthorityVectorRebuildJob === "function"
) {
const jobResult = await runtime.submitAuthorityVectorRebuildJob({
config,
purge: true,
range,
signal: vectorController.signal,
});
if (jobResult?.submitted) {
runtime.saveGraphToChat({ reason: "authority-vector-rebuild-job-submitted" });
runtime.toastr.info(
`Authority 向量重建任务已提交:${jobResult.job?.id || "pending"}`,
);
return;
}
if (jobResult?.error) {
runtime.toastr.warning(
`Authority Job 提交失败,已回退本地重建:${jobResult.error}`,
);
}
}
const result = await runtime.syncVectorState({
force: true,
purge:

View File

@@ -146,6 +146,15 @@ export function createGraphPersistenceState() {
authorityMigrationRevision: 0,
authorityMigrationLastError: "",
lastAuthorityMigrationResult: null,
authorityJobsReady: false,
authorityJobQueueState: "idle",
authorityLastJob: null,
authorityLastJobId: "",
authorityLastJobKind: "",
authorityLastJobStatus: "",
authorityLastJobProgress: 0,
authorityLastJobError: "",
authorityLastJobUpdatedAt: "",
localStoreFormatVersion: 1,
localStoreMigrationState: "idle",
opfsWriteLockState: {