"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.projectRagResultForSseAndLog = projectRagResultForSseAndLog;
const crypto_1 = require("crypto");
function hashSnippet(snippet) {
    return (0, crypto_1.createHash)('sha256').update(snippet).digest('hex').slice(0, 12);
}
function projectRagResultForSseAndLog(toolName, result) {
    let outcome = 'success';
    const chunkRefs = result.hits.map(hit => {
        if (hit.unsupportedReason)
            outcome = hit.unsupportedReason === 'budget_exceeded'
                ? 'budget_exceeded'
                : 'rejected';
        return {
            chunkId: hit.chunkId,
            ...(hit.metadata?.codebaseId ? { codebaseId: hit.metadata.codebaseId } : {}),
            kind: hit.metadata?.kind ?? 'androidperformance.com',
            ...(hit.snippet ? { snippetHash: hashSnippet(hit.snippet), snippetLength: hit.snippet.length } : {}),
            ...(hit.redactedCount !== undefined ? { redactedCount: hit.redactedCount } : {}),
        };
    });
    return {
        toolName,
        chunkRefs,
        outcome,
        legacyPath: result.legacyPath,
    };
}
//# sourceMappingURL=toolResultProjectionFilter.js.map