"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReplayStepsToolDefinition = exports.replayStepsResponseSchema = exports.replayScreenshotInfoSchema = exports.replayedStepDetailSchema = exports.replayStepsArgumentsSchema = void 0;
var zod_1 = require("zod");
var toolDefinition_js_1 = require("../toolDefinition.js");
var agentToolNames_js_1 = require("../shared/agentToolNames.js");
exports.replayStepsArgumentsSchema = zod_1.z.object({
    description: zod_1.z.string().max(100).describe('A brief description of what this step does (max 100 characters)'),
    reasoning: zod_1.z
        .string()
        .optional()
        .describe('Brief explanation of why this action is being taken and what it aims to achieve'),
    start_step_index: zod_1.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: zod_1.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"'),
});
exports.replayedStepDetailSchema = zod_1.z.object({
    step_index: zod_1.z.string().describe('The step index (dot-notation)'),
    step_type: zod_1.z.string().describe('The step action type (e.g. click, assert, enter_text)'),
    description: zod_1.z.string().optional().describe('Human-readable description of the step'),
    status: zod_1.z.enum(['passed', 'failed', 'skipped', 'error']).describe('Execution result status'),
    log_info: zod_1.z.string().optional().describe('Execution log output for the step'),
    duration_ms: zod_1.z.number().optional().describe('Time taken to execute the step in milliseconds'),
    error: zod_1.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.
 */
exports.replayScreenshotInfoSchema = zod_1.z.object({
    stepNumber: zod_1.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: zod_1.z.string().describe('Description of the step this screenshot was captured after'),
    mediaType: zod_1.z.string().describe('Media type of the screenshot'),
});
exports.replayStepsResponseSchema = zod_1.z.object({
    success: zod_1.z.boolean().describe('Whether all replayed steps passed'),
    message: zod_1.z.string().optional().describe('Summary message or error description'),
    steps_executed: zod_1.z.number().optional().describe('Number of steps that were executed'),
    steps_failed: zod_1.z.number().optional().describe('Number of steps that failed during replay'),
    step_details: zod_1.z.array(exports.replayedStepDetailSchema).optional().describe('Detailed results for each replayed step'),
    screenshots: zod_1.z
        .array(exports.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: zod_1.z.string().optional().describe('Base64-encoded PNG screenshot of the page after replay'),
    current_url: zod_1.z.string().optional().describe('The current URL after replay'),
    note: zod_1.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.'),
});
exports.ReplayStepsToolDefinition = (0, toolDefinition_js_1.defineTool)({
    name: agentToolNames_js_1.AgentToolNames.ReplaySteps,
    description: "Re-execute a range of test steps through the full execution pipeline to verify recovery or rebuild state.\n\nUse 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.\n\nStep 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.\n\nObservers are disabled during replay so no side effects (HAR logs, metrics) are recorded.\n\nCommon use cases:\n- After dismissing a popup, replay the failed assertion step to verify it now passes\n- After refreshing the page, replay several steps to rebuild the application state\n- Re-run a single step to confirm a transient issue is resolved\n\nThe client will return a new screenshot after replay to show the updated page state.",
    argumentsSchema: exports.replayStepsArgumentsSchema,
    responseSchema: exports.replayStepsResponseSchema,
});
//# sourceMappingURL=ReplayStepsDefinition.js.map