"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetTestRecoverySessionToolDefinition = exports.getTestRecoverySessionResponseSchema = exports.getTestRecoverySessionParamsSchema = exports.MAX_GET_RECOVERY_SESSION_SCREENSHOTS = void 0;
var zod_1 = require("zod");
var toolDefinition_js_1 = require("../toolDefinition.js");
var constants_js_1 = require("./constants.js");
var agentToolNames_js_1 = require("./agentToolNames.js");
/**
 * GetTestRecoverySessionDefinition - Tool definition for fetching details from a TRA session.
 */
exports.MAX_GET_RECOVERY_SESSION_SCREENSHOTS = 10;
exports.getTestRecoverySessionParamsSchema = zod_1.z.object({
    agent_session_id: zod_1.z.string().meta({
        description: 'Required. The agent session ID of the TRA session to fetch (from traSessionId on a test step).',
    }),
});
var screenshotSchema = zod_1.z.object({
    context: zod_1.z.string().optional().meta({
        description: 'Context about when this screenshot was taken (e.g., "initial failure state", "after take_screenshot", "after click_element").',
    }),
});
exports.getTestRecoverySessionResponseSchema = zod_1.z.object({
    createdTime: zod_1.z.string().optional().meta({ description: 'When the session was created (ISO string).' }),
    totalRounds: zod_1.z.number().optional().meta({ description: 'Total number of model message rounds.' }),
    decision: zod_1.z.string().optional().meta({
        description: 'TRA decision: "fail" or "resume". Absent if the TRA did not complete its investigation (e.g. session timed out or was terminated).',
    }),
    failureSummary: zod_1.z.string().optional().meta({
        description: 'Summary of the failure if TRA decided to fail.',
    }),
    evidenceFileContent: zod_1.z
        .string()
        .optional()
        .meta({
        description: "Content of the ".concat(constants_js_1.EVIDENCE_FILENAME, " file documenting TRA's investigation."),
    }),
    reasoningFileContent: zod_1.z
        .string()
        .optional()
        .meta({
        description: "Content of the ".concat(constants_js_1.REASONING_FILENAME, " file documenting TRA's decision reasoning."),
    }),
    screenshots: zod_1.z.array(screenshotSchema).optional().meta({
        description: 'Metadata for each screenshot the TRA saw (order matches images returned alongside this response).',
    }),
    note: zod_1.z.string().optional().meta({
        description: 'Error or warning information if the session could not be fully retrieved.',
    }),
});
exports.GetTestRecoverySessionToolDefinition = (0, toolDefinition_js_1.defineTool)({
    name: agentToolNames_js_1.AgentToolNames.GetTestRecoverySession,
    description: "Fetch details from a Test Recovery Agent (TRA) session.\n\nThe Test Recovery Agent is an AI agent that runs automatically when a test step fails during execution. It investigates the failure by examining the page state, taking screenshots, and attempting recovery actions (clicking, entering text, scrolling, replaying steps, running JavaScript). After investigation, the TRA makes a decision:\n- \"resume\": The TRA successfully recovered from the failure (e.g., the page changed and the TRA found the element or navigated to the right state), and test execution continued from where it left off.\n- \"fail\": The TRA determined the failure is a real issue (e.g., a genuine application bug, missing element, or broken flow) and the test should be marked as failed.\n\nUse this tool when a test step has a traSessionId to understand what the TRA did:\n- What decision it made (fail or resume) and why\n- What evidence it collected (".concat(constants_js_1.EVIDENCE_FILENAME, " file)\n- What reasoning it applied to its decision (").concat(constants_js_1.REASONING_FILENAME, " file)\n- What screenshots it saw during recovery (returned as images in the response, with per-image metadata in screenshots \u2014 capped at ").concat(exports.MAX_GET_RECOVERY_SESSION_SCREENSHOTS, ")\n\nThis is useful for understanding why a step was recovered or failed, and what the application state looked like during the investigation.\n\nWhen summarizing recovery in markdown tables: use a **Recovery session** column for **agent_session_id** (same as **traSessionId**; opaque id ending in **`-as`**). Use **Test run** for **test_run_id** at most once (**id-only** is fine). Do not duplicate **test_run_id** across a **Test** column with app links and a **Test run** column."),
    argumentsSchema: exports.getTestRecoverySessionParamsSchema,
    responseSchema: exports.getTestRecoverySessionResponseSchema,
});
//# sourceMappingURL=GetTestRecoverySessionDefinition.js.map