import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { EVIDENCE_FILENAME, REASONING_FILENAME } from './constants.js';
import { AgentToolNames } from './agentToolNames.js';
/**
 * GetTestRecoverySessionDefinition - Tool definition for fetching details from a TRA session.
 */
export const MAX_GET_RECOVERY_SESSION_SCREENSHOTS = 10;
export const getTestRecoverySessionParamsSchema = z.object({
    agent_session_id: z.string().meta({
        description: 'Required. The agent session ID of the TRA session to fetch (from traSessionId on a test step).',
    }),
});
const screenshotSchema = z.object({
    context: z.string().optional().meta({
        description: 'Context about when this screenshot was taken (e.g., "initial failure state", "after take_screenshot", "after click_element").',
    }),
});
export const getTestRecoverySessionResponseSchema = z.object({
    createdTime: z.string().optional().meta({ description: 'When the session was created (ISO string).' }),
    totalRounds: z.number().optional().meta({ description: 'Total number of model message rounds.' }),
    decision: 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: z.string().optional().meta({
        description: 'Summary of the failure if TRA decided to fail.',
    }),
    evidenceFileContent: z
        .string()
        .optional()
        .meta({
        description: `Content of the ${EVIDENCE_FILENAME} file documenting TRA's investigation.`,
    }),
    reasoningFileContent: z
        .string()
        .optional()
        .meta({
        description: `Content of the ${REASONING_FILENAME} file documenting TRA's decision reasoning.`,
    }),
    screenshots: z.array(screenshotSchema).optional().meta({
        description: 'Metadata for each screenshot the TRA saw (order matches images returned alongside this response).',
    }),
    note: z.string().optional().meta({
        description: 'Error or warning information if the session could not be fully retrieved.',
    }),
});
export const GetTestRecoverySessionToolDefinition = defineTool({
    name: AgentToolNames.GetTestRecoverySession,
    description: `Fetch details from a Test Recovery Agent (TRA) session.

The 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:
- "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.
- "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.

Use this tool when a test step has a traSessionId to understand what the TRA did:
- What decision it made (fail or resume) and why
- What evidence it collected (${EVIDENCE_FILENAME} file)
- What reasoning it applied to its decision (${REASONING_FILENAME} file)
- What screenshots it saw during recovery (returned as images in the response, with per-image metadata in screenshots — capped at ${MAX_GET_RECOVERY_SESSION_SCREENSHOTS})

This is useful for understanding why a step was recovered or failed, and what the application state looked like during the investigation.

When 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: getTestRecoverySessionParamsSchema,
    responseSchema: getTestRecoverySessionResponseSchema,
});
//# sourceMappingURL=GetTestRecoverySessionDefinition.js.map