export class LocalKnowledgeIndexingRegistry {
    runsByCapsule = new Map();
    runsByJobId = new Map();
    start(capsuleId) {
        this.complete(capsuleId);
        const controller = new AbortController();
        this.runsByCapsule.set(capsuleId, { capsuleId, controller });
        return controller;
    }
    attachJobId(capsuleId, jobId) {
        const run = this.runsByCapsule.get(capsuleId);
        if (run === undefined) {
            return;
        }
        if (run.jobId !== undefined) {
            this.runsByJobId.delete(run.jobId);
        }
        run.jobId = jobId;
        this.runsByJobId.set(jobId, run);
    }
    cancel(capsuleId) {
        const run = this.runsByCapsule.get(capsuleId);
        if (run === undefined) {
            return false;
        }
        run.controller.abort();
        return true;
    }
    isActiveCapsule(capsuleId) {
        return this.runsByCapsule.has(capsuleId);
    }
    isActiveJob(jobId) {
        return this.runsByJobId.has(jobId);
    }
    complete(capsuleId) {
        const run = this.runsByCapsule.get(capsuleId);
        if (run === undefined) {
            return;
        }
        if (run.jobId !== undefined) {
            this.runsByJobId.delete(run.jobId);
        }
        this.runsByCapsule.delete(capsuleId);
    }
    reset() {
        for (const run of this.runsByCapsule.values()) {
            run.controller.abort();
        }
        this.runsByCapsule.clear();
        this.runsByJobId.clear();
    }
}
export const localKnowledgeIndexingRegistry = new LocalKnowledgeIndexingRegistry();
