"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUpstreamTasks = getUpstreamTasks;
exports.getEscalationHistory = getEscalationHistory;
exports.notifyEngineering = notifyEngineering;
exports.getToolTags = getToolTags;
const logger_1 = require("../../../lib/logger");
const ltconfig_1 = require("../../../modules/ltconfig");
const taskService = __importStar(require("../../../services/task"));
const escalationService = __importStar(require("../../../services/escalation"));
// ── Context activities ────────────────────────────────────────
/**
 * Query all tasks sharing an originId.
 * Gives the triage workflow full context of upstream work.
 */
async function getUpstreamTasks(originId) {
    const { tasks } = await taskService.listTasks({
        origin_id: originId,
        limit: 100,
    });
    return tasks;
}
/**
 * Query all escalations sharing an originId.
 * Gives the triage workflow the full conversation history.
 */
async function getEscalationHistory(originId) {
    return escalationService.getEscalationsByOriginId(originId);
}
/**
 * Create an escalation to the engineering team with a recommendation.
 * Used by the triage workflow to surface long-term fixes (non-blocking).
 */
async function notifyEngineering(originId, description, metadata) {
    await escalationService.createEscalation({
        type: 'triage_recommendation',
        subtype: 'pipeline_fix',
        description,
        priority: 3,
        origin_id: originId,
        role: 'engineer',
        envelope: JSON.stringify({}),
        metadata: {
            ...metadata,
            source: 'mcp_triage',
            auto_generated: true,
        },
    });
}
// ── Tool scoping ─────────────────────────────────────────────
/**
 * Look up tool_tags for a workflow type from lt_config_workflows (cached).
 * Returns empty array if the workflow type has no tags configured.
 */
async function getToolTags(workflowType) {
    const tags = await ltconfig_1.ltConfig.getToolTags(workflowType);
    logger_1.loggerRegistry.debug(`[mcpTriage:getToolTags] ${workflowType} → [${tags.join(',')}]`);
    return tags;
}
