import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { EVIDENCE_FILENAME } from '../shared/constants.js';
import { AgentToolNames } from '../shared/agentToolNames.js';
/**
 * GetTestRunArtifactsDefinition - Tool definition for fetching test run artifacts.
 */
export const getTestRunArtifactsParamsSchema = z.object({
    test_run_id: z.string().meta({
        description: 'Required. Test run ID to fetch artifacts from.',
    }),
    artifact_types: z
        .array(z.enum([
        'chrome_trace',
        'har',
        'console_log',
        'download',
        'network_log',
        'dom_snapshot',
        'full_page_screenshot',
        'variables',
        'accessibility',
        'video',
        'all',
    ]))
        .optional()
        .meta({
        description: 'Types of artifacts to fetch. Default: all. Options: chrome_trace, har, console_log, download, network_log, dom_snapshot, full_page_screenshot, variables, accessibility, video, all',
    }),
    step_index: z.number().optional().meta({
        description: 'If specified, only return artifacts from this specific step index.',
    }),
    include_content: z.boolean().optional().meta({
        description: 'Whether to include artifact content in the response (for text-based artifacts like console logs). Default: false. Only applies to console_log type.',
    }),
    max_artifacts: z.number().optional().meta({
        description: 'Maximum number of artifacts to return. Default: 10. Maximum: 20.',
    }),
});
const artifactInfoSchema = z.object({
    type: z
        .enum([
        'chrome_trace',
        'har',
        'console_log',
        'download',
        'network_log',
        'dom_snapshot',
        'full_page_screenshot',
        'variables',
        'accessibility',
        'video',
        'other',
    ])
        .meta({ description: 'Type of artifact' }),
    name: z.string().meta({ description: 'Name of the artifact' }),
    downloadUrl: z.string().optional().meta({
        description: 'Reserved for optional signed download links. The server does not populate this; use artifactUri (stable gs://) in evidence and markdown.',
    }),
    artifactUri: z
        .string()
        .optional()
        .meta({
        description: `Stable storage URI for the same object (typically gs://). Use this in ${EVIDENCE_FILENAME} and analysis content so HAR/screenshot blocks stay loadable; the UI re-signs it. Prefer over downloadUrl for markdown.`,
    }),
    stepIndex: z
        .number()
        .optional()
        .meta({
        description: `Execution-order step index (0-based). This matches the step indices from ${AgentToolNames.GetTestRunInfo}. For looped flows, each iteration has unique indices.`,
    }),
    nestedStepPath: z
        .array(z.number())
        .optional()
        .meta({
        description: 'Path of step indices for nested steps. Format: [flow_index, step_index_in_flow, ...]. ' +
            'Example: [2, 1] means this step is within flow at index 2, and is step 1 within that flow. ' +
            'For step groups: [flow_index, step_group_index, step_in_group]. ' +
            'Empty or undefined for top-level steps in the main flow.',
    }),
    flowRunIndex: z
        .number()
        .optional()
        .meta({
        description: 'For flows that execute multiple times (loops), the 0-based loop iteration (0=first, 1=second, etc). ' +
            'Only present if the flow ran more than once.',
    }),
});
export const getTestRunArtifactsResponseSchema = z.object({
    artifacts: z.array(artifactInfoSchema).meta({ description: 'List of artifacts' }),
    totalAvailable: z.number().meta({ description: 'Total number of artifacts available' }),
    consoleLogContent: z.string().optional().meta({ description: 'Console log content if include_content is true' }),
    note: z.string().optional().meta({ description: 'Any notes about the response' }),
});
export const GetTestRunArtifactsToolDefinition = defineTool({
    name: AgentToolNames.GetTestRunArtifacts,
    description: `Retrieves artifacts from a test run such as chrome traces, HAR files, console logs, and downloaded files.

Use this tool to:
- Analyze network requests via HAR files
- Review console logs for JavaScript errors or warnings
- Examine chrome traces for performance analysis
- Access files downloaded during the test
- Inspect DOM snapshots or full page screenshots
- Review variable values after step execution
- Check accessibility scan results
- **For API tests**: Use network_log to see request/response details, status codes, and response times

Artifact types:
- chrome_trace: Browser performance traces (browser tests only)
- har: HTTP Archive files with network request details
- console_log: Browser console output (browser tests only)
- network_log: Network request/response logs (useful for both browser and API tests)
- download: Files downloaded during the test
- dom_snapshot: DOM state at a step (browser tests only)
- full_page_screenshot: Full page screenshot (browser tests only)
- variables: Variable values after step execution
- accessibility: Accessibility check results
- video: Video recording of test execution (browser/mobile tests)

For console logs, you can set include_content=true to get the actual log content included in the response.

Each artifact includes **artifactUri** (stable, usually gs://) and **downloadUrl** (signed HTTPS, expires). For evidence files and dashboard-ready markdown (HAR blocks, screenshots), cite **artifactUri** so links remain valid; use **downloadUrl** only for one-off download.`,
    argumentsSchema: getTestRunArtifactsParamsSchema,
    responseSchema: getTestRunArtifactsResponseSchema,
});
//# sourceMappingURL=GetTestRunArtifactsDefinition.js.map