import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { AgentToolNames } from '../shared/agentToolNames.js';
export const replayStepsArgumentsSchema = z.object({
    description: z.string().max(100).describe('A brief description of what this step does (max 100 characters)'),
    reasoning: z
        .string()
        .optional()
        .describe('Brief explanation of why this action is being taken and what it aims to achieve'),
    start_step_index: z
        .string()
        .describe('The step index to start replaying from (inclusive). Uses dot-notation for nested steps, e.g. "1", "3.2", "5.1.3"'),
    end_step_index: z
        .string()
        .describe('The step index to stop replaying at (inclusive). Uses dot-notation for nested steps, e.g. "1", "3.2", "5.1.3"'),
});
export const replayedStepDetailSchema = z.object({
    step_index: z.string().describe('The step index (dot-notation)'),
    step_type: z.string().describe('The step action type (e.g. click, assert, enter_text)'),
    description: z.string().optional().describe('Human-readable description of the step'),
    status: z.enum(['passed', 'failed', 'skipped', 'error']).describe('Execution result status'),
    log_info: z.string().optional().describe('Execution log output for the step'),
    duration_ms: z.number().optional().describe('Time taken to execute the step in milliseconds'),
    error: z.string().optional().describe('Error message if the step failed'),
});
/**
 * Metadata for a single screenshot captured during replay.
 * Follows the same pattern as screenshotInfoSchema in GetTestRunScreenshotsDefinition,
 * using the subset of fields available in the replay context.
 */
export const replayScreenshotInfoSchema = z.object({
    stepNumber: z
        .string()
        .describe('Human-readable step number with dotted notation for nested steps (1-based). ' +
        'Examples: "5" for step 5, "3.2" for step 2 inside step group at position 3.'),
    stepDescription: z.string().describe('Description of the step this screenshot was captured after'),
    mediaType: z.string().describe('Media type of the screenshot'),
});
export const replayStepsResponseSchema = z.object({
    success: z.boolean().describe('Whether all replayed steps passed'),
    message: z.string().optional().describe('Summary message or error description'),
    steps_executed: z.number().optional().describe('Number of steps that were executed'),
    steps_failed: z.number().optional().describe('Number of steps that failed during replay'),
    step_details: z.array(replayedStepDetailSchema).optional().describe('Detailed results for each replayed step'),
    screenshots: z
        .array(replayScreenshotInfoSchema)
        .optional()
        .describe('Metadata for each screenshot image returned, in the same order as the image content items. ' +
        'Use this to map each image to the step it was captured after.'),
    new_screenshot: z.string().optional().describe('Base64-encoded PNG screenshot of the page after replay'),
    current_url: z.string().optional().describe('The current URL after replay'),
    note: z
        .string()
        .optional()
        .describe('Maps each returned image to its corresponding step and screenshots array index. ' +
        'Use this to understand which image belongs to which step without parsing the screenshots array.'),
});
export const ReplayStepsToolDefinition = defineTool({
    name: AgentToolNames.ReplaySteps,
    description: `Re-execute a range of test steps through the full execution pipeline to verify recovery or rebuild state.

Use this tool after performing recovery actions (clicking, typing, running JavaScript) to confirm the fix worked by re-running the steps that previously failed or that need to be re-executed to rebuild test state.

Step indices use dot-notation for nested steps and are inclusive. For example, start_step_index="3", end_step_index="5" replays steps 3, 4, and 5. For nested steps, use "3.1", "3.2" etc. to target specific sub-steps within step groups.

Observers are disabled during replay so no side effects (HAR logs, metrics) are recorded.

Common use cases:
- After dismissing a popup, replay the failed assertion step to verify it now passes
- After refreshing the page, replay several steps to rebuild the application state
- Re-run a single step to confirm a transient issue is resolved

The client will return a new screenshot after replay to show the updated page state.`,
    argumentsSchema: replayStepsArgumentsSchema,
    responseSchema: replayStepsResponseSchema,
});
//# sourceMappingURL=ReplayStepsDefinition.js.map