import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { AgentToolNames } from '../shared/agentToolNames.js';
/**
 * GetDeploymentEventPlanRunsDefinition - Tool definition for fetching all plan runs triggered by a deployment event.
 */
export const getDeploymentEventPlanRunsParamsSchema = z.object({
    deployment_event_id: z.string().meta({
        description: 'Required. Deployment event ID.',
    }),
    filter_status: z.enum(['all', 'passed', 'failed']).optional().meta({
        description: 'Filter plan runs by status. Default: all',
    }),
    include_test_details: z.boolean().optional().meta({
        description: 'Whether to include individual test run details for each plan run. Default: false',
    }),
});
// Schema for test run summary within a plan run
export const testRunSummarySchema = z.object({
    testRunId: z.string().meta({ description: 'Test run ID' }),
    testName: z.string().optional().meta({ description: 'Name of the test' }),
    status: z.enum(['passed', 'failed', 'skipped', 'running', 'queued']).meta({ description: 'Test run status' }),
    failureReason: z.string().optional().meta({ description: 'Failure reason if test failed' }),
    durationMs: z.number().optional().meta({ description: 'Duration in milliseconds' }),
});
// Schema for individual plan run info
export const planRunInfoSchema = z.object({
    planRunId: z.string().meta({ description: 'Plan run ID' }),
    planId: z.string().optional().meta({ description: 'Plan ID' }),
    planName: z.string().optional().meta({ description: 'Name of the plan' }),
    status: z.enum(['passed', 'failed', 'running', 'cancelled', 'terminated']).meta({
        description: 'Status of the plan run',
    }),
    startTime: z.string().optional().meta({ description: 'Start time as ISO string' }),
    endTime: z.string().optional().meta({ description: 'End time as ISO string' }),
    durationMs: z.number().optional().meta({ description: 'Duration in milliseconds' }),
    testCounts: z
        .object({
        total: z.number().meta({ description: 'Total number of tests' }),
        passed: z.number().meta({ description: 'Number of passed tests' }),
        failed: z.number().meta({ description: 'Number of failed tests' }),
        skipped: z.number().meta({ description: 'Number of skipped tests' }),
    })
        .optional()
        .meta({ description: 'Test count statistics' }),
    passRate: z.number().optional().meta({ description: 'Pass rate as a percentage (0-100)' }),
    failedTests: z.array(testRunSummarySchema).optional().meta({ description: 'Failed test runs (if any)' }),
});
// Schema for failure pattern analysis
export const failurePatternSchema = z.object({
    reason: z.string().meta({ description: 'The failure reason' }),
    count: z.number().meta({ description: 'Number of tests with this failure reason' }),
    planNames: z.array(z.string()).meta({ description: 'Names of plans with this failure reason' }),
});
export const getDeploymentEventPlanRunsResponseSchema = z.object({
    planRuns: z.array(planRunInfoSchema).meta({ description: 'List of plan runs triggered by this deployment' }),
    summary: z
        .object({
        totalPlanRuns: z.number().meta({ description: 'Total number of plan runs' }),
        passedPlanRuns: z.number().meta({ description: 'Number of passed plan runs' }),
        failedPlanRuns: z.number().meta({ description: 'Number of failed plan runs' }),
        runningPlanRuns: z.number().meta({ description: 'Number of running plan runs' }),
        overallPassRate: z.number().optional().meta({ description: 'Overall pass rate as a percentage' }),
        totalTestRuns: z.number().optional().meta({ description: 'Total test runs across all plans' }),
        passedTestRuns: z.number().optional().meta({ description: 'Passed test runs across all plans' }),
        failedTestRuns: z.number().optional().meta({ description: 'Failed test runs across all plans' }),
    })
        .meta({ description: 'Summary of plan run statuses' }),
    failurePatterns: z.array(failurePatternSchema).optional().meta({
        description: 'Analysis of failure patterns across plan runs',
    }),
});
export const GetDeploymentEventPlanRunsToolDefinition = defineTool({
    name: AgentToolNames.GetDeploymentEventPlanRuns,
    description: `Retrieves all plan runs triggered by a deployment event with their status, duration, and test results.

**Do not call without a real deployment_event_id** (same sources as **${AgentToolNames.GetDeploymentEventInfo}** — context artifact, user, **${AgentToolNames.QueryWorkspaceDeploymentEvents}**, or prior tool output).

Use this tool to:
- See which plans ran and their pass/fail status
- Understand which specific plans failed and why
- Identify patterns in test failures across plans
- Get plan run IDs for deeper analysis
- Analyze test execution timing within the deployment

With **include_test_details=true**, failed test rows include **testRunId**, **testName**, and per-test failure fields in addition to each plan run's **planRunId** and **planName**.`,
    argumentsSchema: getDeploymentEventPlanRunsParamsSchema,
    responseSchema: getDeploymentEventPlanRunsResponseSchema,
});
//# sourceMappingURL=GetDeploymentEventPlanRunsDefinition.js.map