"use strict";
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2024-2026 Gracker (Chris)
// This file is part of SmartPerfetto. See LICENSE for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionToolResultRegistry = void 0;
exports.serializeToolResultKey = serializeToolResultKey;
exports.projectedSidecarMissing = projectedSidecarMissing;
function serializeToolResultKey(key) {
    return `${key.sessionId}:${key.runId}:${key.runtime}:${key.invocationId}`;
}
class SessionToolResultRegistry {
    constructor() {
        this.entries = new Map();
        this.aliases = new Map();
    }
    put(key, entry) {
        this.entries.set(serializeToolResultKey(key), {
            ...entry,
            createdAt: Date.now(),
        });
    }
    alias(from, to) {
        this.aliases.set(serializeToolResultKey(from), serializeToolResultKey(to));
    }
    getSidecar(key) {
        const serialized = serializeToolResultKey(key);
        const target = this.aliases.get(serialized) ?? serialized;
        return this.entries.get(target)?.sidecar;
    }
    getLlmPayload(key) {
        const serialized = serializeToolResultKey(key);
        const target = this.aliases.get(serialized) ?? serialized;
        return this.entries.get(target)?.llmPayload;
    }
    clearRun(sessionId, runId) {
        const prefix = `${sessionId}:${runId}:`;
        for (const key of this.entries.keys()) {
            if (key.startsWith(prefix))
                this.entries.delete(key);
        }
        for (const key of this.aliases.keys()) {
            if (key.startsWith(prefix))
                this.aliases.delete(key);
        }
    }
}
exports.SessionToolResultRegistry = SessionToolResultRegistry;
function projectedSidecarMissing(toolName) {
    return {
        toolName,
        chunkRefs: [],
        outcome: 'sidecar_missing',
        legacyPath: false,
    };
}
//# sourceMappingURL=sessionToolResultRegistry.js.map