"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetRelatedPlanRunsToolDefinition = exports.getRelatedPlanRunsResponseSchema = exports.planRunInsightsSchema = exports.planRunInfoSchema = exports.getRelatedPlanRunsParamsSchema = void 0;
var zod_1 = require("zod");
var toolDefinition_js_1 = require("../toolDefinition.js");
var agentToolNames_js_1 = require("../shared/agentToolNames.js");
/**
 * GetRelatedPlanRunsDefinition - Tool definition for fetching historical plan runs for comparison.
 */
exports.getRelatedPlanRunsParamsSchema = zod_1.z.object({
    plan_run_id: zod_1.z.string().meta({
        description: 'Required. Plan run ID to find related runs for. When analyzing deployments, use plan_run_id from get_deployment_event_plan_runs results.',
    }),
    limit: zod_1.z.number().optional().meta({
        description: 'Maximum number of plan runs to return. Default: 10, Max: 50',
    }),
    filter_status: zod_1.z.enum(['all', 'passed', 'failed']).optional().meta({
        description: 'Filter plan runs by status. Default: all',
    }),
    include_current: zod_1.z.boolean().optional().meta({
        description: 'Whether to include the current plan run in results. Default: false',
    }),
    include_ad_hoc: zod_1.z.boolean().optional().meta({
        description: 'Whether to include ad-hoc runs. Default: true',
    }),
    time_range: zod_1.z.enum(['recent', 'day', 'week', 'month']).optional().meta({
        description: 'Time range to filter runs. "recent" returns most recent regardless of time, "day" returns from last 24 hours, "week" from last 7 days, "month" from last 30 days. Default: recent',
    }),
});
// Schema for plan run info
exports.planRunInfoSchema = zod_1.z.object({
    planRunId: zod_1.z.string().meta({ description: 'Plan run ID' }),
    status: zod_1.z.enum(['passed', 'failed', 'running', 'cancelled', 'terminated']).meta({ description: 'Plan run status' }),
    startTime: zod_1.z.string().optional().meta({ description: 'Start time as ISO string' }),
    endTime: zod_1.z.string().optional().meta({ description: 'End time as ISO string' }),
    durationMs: zod_1.z.number().optional().meta({ description: 'Duration in milliseconds' }),
    testCounts: zod_1.z
        .object({
        total: zod_1.z.number(),
        passed: zod_1.z.number(),
        failed: zod_1.z.number(),
    })
        .optional()
        .meta({ description: 'Test counts for this plan run' }),
    passRate: zod_1.z.number().optional().meta({ description: 'Pass rate as a percentage (0-100)' }),
    triggerType: zod_1.z.string().optional().meta({ description: 'How the plan run was triggered' }),
});
// Schema for insights
exports.planRunInsightsSchema = zod_1.z.object({
    totalRuns: zod_1.z.number().meta({ description: 'Total number of runs analyzed' }),
    averagePassRate: zod_1.z.number().optional().meta({ description: 'Average pass rate across all runs' }),
    averageDurationMs: zod_1.z.number().optional().meta({ description: 'Average duration in milliseconds' }),
    minDurationMs: zod_1.z.number().optional().meta({ description: 'Minimum duration in milliseconds' }),
    maxDurationMs: zod_1.z.number().optional().meta({ description: 'Maximum duration in milliseconds' }),
    consecutivePasses: zod_1.z.number().optional().meta({ description: 'Number of consecutive passing runs from current' }),
    consecutiveFailures: zod_1.z.number().optional().meta({ description: 'Number of consecutive failing runs from current' }),
    lastPassedRun: exports.planRunInfoSchema.optional().meta({ description: 'Most recent passing plan run' }),
    trend: zod_1.z.enum(['improving', 'declining', 'stable', 'unknown']).optional().meta({
        description: 'Trend based on recent pass rates',
    }),
    isFlaky: zod_1.z.boolean().optional().meta({ description: 'Whether the plan appears to be flaky' }),
    flakinessNote: zod_1.z.string().optional().meta({ description: 'Explanation of flakiness detection result' }),
});
exports.getRelatedPlanRunsResponseSchema = zod_1.z.object({
    currentRun: exports.planRunInfoSchema.meta({ description: 'The current plan run being analyzed' }),
    previousRuns: zod_1.z.array(exports.planRunInfoSchema).meta({ description: 'Historical plan runs for comparison (newest first)' }),
    insights: exports.planRunInsightsSchema.meta({ description: 'Insights from analyzing plan run history' }),
});
exports.GetRelatedPlanRunsToolDefinition = (0, toolDefinition_js_1.defineTool)({
    name: agentToolNames_js_1.AgentToolNames.GetRelatedPlanRuns,
    description: "Retrieves historical plan runs for comparison and trend analysis.\n\nUse this tool to:\n- Compare the current plan run with previous runs\n- Identify trends (improving, declining, stable)\n- Find when failures started occurring\n- Calculate average pass rates and durations\n- Detect if failures are new or recurring",
    argumentsSchema: exports.getRelatedPlanRunsParamsSchema,
    responseSchema: exports.getRelatedPlanRunsResponseSchema,
});
//# sourceMappingURL=GetRelatedPlanRunsDefinition.js.map