import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { STEP_INDEX_DESCRIPTION } from './shared/stepIndexDescription.js';
export const executePlayStepsArgumentsSchema = z
    .object({
    description: z.string().max(100).describe('Brief description of why replaying these steps'),
    start_step_index: z
        .string()
        .optional()
        .meta({
        description: `${STEP_INDEX_DESCRIPTION} First step to replay (inclusive). Either start_step_index or step_id must be provided; if both are provided, step_id takes precedence.`,
    }),
    end_step_index: z
        .string()
        .optional()
        .meta({
        description: `${STEP_INDEX_DESCRIPTION} Last step to replay (inclusive — this step WILL be replayed). Either end_step_index or end_step_id must be provided; if both are provided, end_step_id takes precedence.`,
    }),
    step_id: z.string().optional().meta({
        description: 'Stable canonical step id of the first step to replay (inclusive). Preferred over start_step_index when the test execution state exposes step ids — ids survive list mutations and avoid stale-index races. When both step_id and start_step_index are provided, step_id wins.',
    }),
    end_step_id: z.string().optional().meta({
        description: 'Stable canonical step id of the last step to replay (inclusive). Preferred over end_step_index when the test execution state exposes step ids. When both end_step_id and end_step_index are provided, end_step_id wins.',
    }),
    continue_on_failure: z.boolean().optional().meta({
        description: 'If true, continue replaying subsequent steps even if a step fails. Default: false (stop on first failure).',
    }),
})
    .superRefine((value, ctx) => {
    if (value.start_step_index === undefined && value.step_id === undefined) {
        ctx.addIssue({
            code: 'custom',
            path: ['start_step_index'],
            message: 'Provide either start_step_index or step_id to identify the first step to replay.',
        });
    }
    if (value.end_step_index === undefined && value.end_step_id === undefined) {
        ctx.addIssue({
            code: 'custom',
            path: ['end_step_index'],
            message: 'Provide either end_step_index or end_step_id to identify the last step to replay.',
        });
    }
});
export const executePlayStepsResponseSchema = z.object({
    success: z.boolean(),
    message: z.string().optional(),
    failed_steps: z
        .array(z.string())
        .optional()
        .describe('Dot-notation indices of steps that failed during replay. Only present when continue_on_failure is true and failures occurred.'),
});
export const ExecutePlayStepsToolDefinition = defineTool({
    name: 'execute_play_steps',
    description: 'Replays a range of existing steps in the test. Identify the range with either dot-notation indices (start_step_index / end_step_index) or stable step ids (step_id / end_step_id); the id-based form wins when both are provided. Both ends of the range are INCLUSIVE — the last identified step WILL be replayed. All identifiers must refer to steps that actually exist in the test (check the step list first). After replay, the cursor moves to the position after the last replayed step. The response includes the cursor position. Set continue_on_failure to true to replay all steps even if some fail.',
    argumentsSchema: executePlayStepsArgumentsSchema,
    responseSchema: executePlayStepsResponseSchema,
});
//# sourceMappingURL=ExecutePlayStepsDefinition.js.map