"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetTestDefinitionToolDefinition = exports.getTestDefinitionResponseSchema = exports.getTestDefinitionParamsSchema = void 0;
var zod_1 = require("zod");
var toolDefinition_js_1 = require("../toolDefinition.js");
var agentToolNames_js_1 = require("../shared/agentToolNames.js");
/**
 * GetTestDefinitionDefinition - Tool definition for fetching test entity and its flow definitions.
 */
exports.getTestDefinitionParamsSchema = zod_1.z.object({
    test_run_id: zod_1.z.string().optional().meta({
        description: 'Test run ID to fetch the test definition for. Either test_run_id or test_id must be provided.',
    }),
    test_id: zod_1.z.string().optional().meta({
        description: 'Test ID (journey ID) to fetch the test definition for directly, without requiring a test run. Either test_run_id or test_id must be provided. Use this when you have a test ID but no test run (e.g., newly authored tests that have not been run yet).',
    }),
    include_nested_flows: zod_1.z.boolean().optional().meta({
        description: 'Whether to recursively fetch nested flow definitions. Default: true',
    }),
    max_flow_depth: zod_1.z.number().optional().meta({
        description: 'Maximum depth for nested flow resolution. Default: 3. Maximum: 5.',
    }),
});
var flowStepInfoSchema = zod_1.z.lazy(function () {
    return zod_1.z.object({
        stepIndex: zod_1.z.number().meta({ description: 'Index of the step within the flow' }),
        stepNumber: zod_1.z.string().optional().meta({
            description: 'Human-readable step number with dotted notation (e.g., "1", "2.1", "2.1.3" for nested steps in step groups or embedded flows)',
        }),
        description: zod_1.z.string().meta({ description: 'Description of what the step does' }),
        isNestedFlow: zod_1.z.boolean().optional().meta({ description: 'Whether this step executes a nested flow' }),
        nestedFlowId: zod_1.z.string().optional().meta({ description: 'ID of the nested flow if this step executes one' }),
        isStepGroup: zod_1.z
            .boolean()
            .optional()
            .meta({ description: 'Whether this step is a step group containing nested steps' }),
        nestedSteps: zod_1.z
            .array(zod_1.z.lazy(function () { return flowStepInfoSchema; }))
            .optional()
            .meta({ description: 'Nested steps within a step group (for step groups only)' }),
        isJavascriptStep: zod_1.z.boolean().optional().meta({ description: 'Whether this step executes JavaScript code' }),
        javascriptCode: zod_1.z
            .string()
            .optional()
            .meta({ description: 'The JavaScript code executed by this step (for inline JS steps)' }),
        snippetId: zod_1.z.string().optional().meta({
            description: 'Invariant ID of the snippet referenced by this step (matches invariant_id in flow snippets array)',
        }),
        note: zod_1.z.string().optional().meta({ description: 'User-provided note/documentation for this step' }),
        autoGeneratedDescription: zod_1.z
            .string()
            .optional()
            .meta({ description: 'AI-generated description of what this step does' }),
        descriptionSource: zod_1.z
            .enum(['user', 'ai', 'default'])
            .optional()
            .meta({ description: 'Source of the step description: user-provided, AI-generated, or default' }),
        featureIds: zod_1.z
            .array(zod_1.z.string())
            .optional()
            .meta({ description: 'IDs of advanced features used by this step (e.g., ai_assertion, visual_change)' }),
    });
});
var snippetInfoSchema = zod_1.z.object({
    invariant_id: zod_1.z.string().meta({ description: 'Snippet invariant ID' }),
    name: zod_1.z.string().optional().meta({ description: 'Snippet name' }),
    description: zod_1.z.string().optional().meta({ description: 'Snippet description' }),
    snippet_type: zod_1.z.string().optional().meta({ description: 'Type of snippet (e.g., javascript)' }),
    body: zod_1.z.string().optional().meta({
        description: 'The decoded body/code of the snippet. Omitted when body_truncated is true — call get_snippet_details with invariant_id to fetch the full body.',
    }),
    body_truncated: zod_1.z.boolean().optional().meta({
        description: 'True when the snippet body was stripped because it exceeded the inline size limit. Fetch the full body via get_snippet_details if you need it for diagnosis.',
    }),
    body_length: zod_1.z.number().optional().meta({
        description: 'The character length of the original body. Only set when body_truncated is true.',
    }),
    parameters: zod_1.z
        .array(zod_1.z.object({
        name: zod_1.z.string(),
        default_value: zod_1.z.string().optional(),
    }))
        .optional()
        .meta({ description: 'Parameters that the snippet accepts' }),
});
var flowDefinitionSchema = zod_1.z.object({
    flowId: zod_1.z.string().meta({ description: 'Flow invariant ID' }),
    description: zod_1.z.string().optional().meta({ description: 'Flow description' }),
    isReusable: zod_1.z
        .boolean()
        .optional()
        .meta({ description: 'Whether this flow is a reusable flow that can be called from other tests' }),
    steps: zod_1.z.array(flowStepInfoSchema).meta({ description: 'Steps in this flow' }),
    parameters: zod_1.z
        .array(zod_1.z.object({
        name: zod_1.z.string(),
        defaultValue: zod_1.z.string().optional(),
    }))
        .optional()
        .meta({ description: 'Parameters that can be passed to this flow' }),
    nestedFlowIds: zod_1.z.array(zod_1.z.string()).optional().meta({ description: 'IDs of flows referenced by this flow' }),
    snippets: zod_1.z
        .array(snippetInfoSchema)
        .optional()
        .meta({ description: 'JavaScript/code snippets referenced by steps in this flow' }),
});
var labelSchema = zod_1.z.object({
    name: zod_1.z.string().meta({ description: 'Label name' }),
    color: zod_1.z.string().optional().meta({ description: 'Label color' }),
});
var tagSchema = zod_1.z.object({
    name: zod_1.z.string().meta({ description: 'Tag name' }),
    value: zod_1.z.string().optional().meta({ description: 'Tag value' }),
});
var testDefinitionSchema = zod_1.z.object({
    testId: zod_1.z.string().meta({ description: 'Test ID' }),
    testInvariantId: zod_1.z.string().optional().meta({ description: 'Test invariant ID' }),
    name: zod_1.z.string().meta({ description: 'Test name' }),
    description: zod_1.z.string().optional().meta({ description: 'Test description' }),
    intent: zod_1.z.string().optional().meta({ description: 'Test intent - what the test is meant to verify' }),
    testType: zod_1.z.string().optional().meta({ description: 'Type of test (browser, api, mobile)' }),
    applicationId: zod_1.z.string().optional().meta({ description: 'Application this test belongs to' }),
    credentialsId: zod_1.z.string().optional().meta({ description: 'ID of the credentials used by this test' }),
    url: zod_1.z.string().optional().meta({ description: 'The URL used when creating this test version' }),
    labels: zod_1.z.array(labelSchema).optional().meta({ description: 'User-provided labels for test organization' }),
    tags: zod_1.z.array(tagSchema).optional().meta({ description: 'Tags associated with this test' }),
    flows: zod_1.z.array(flowDefinitionSchema).meta({ description: 'Flows that make up this test, in execution order' }),
    totalStepsAcrossFlows: zod_1.z.number().meta({ description: 'Total number of steps across all flows' }),
});
exports.getTestDefinitionResponseSchema = zod_1.z.object({
    test: testDefinitionSchema.meta({ description: 'Test definition with all flow details' }),
    nestedFlows: zod_1.z
        .array(flowDefinitionSchema)
        .optional()
        .meta({ description: 'Additional nested flows referenced by the main flows' }),
    formattedStepList: zod_1.z.string().optional().meta({
        description: 'Pre-formatted step list with each step on its own line and proper indentation for nested flows. Use this for display to users.',
    }),
    note: zod_1.z.string().optional().meta({ description: 'Any notes about the response' }),
});
exports.GetTestDefinitionToolDefinition = (0, toolDefinition_js_1.defineTool)({
    name: agentToolNames_js_1.AgentToolNames.GetTestDefinition,
    description: "Retrieves the test definition including all flows, steps, and code snippets.\nAccepts either a test_run_id or a test_id (journey ID). Use test_id when you have a test ID\nbut no test run (e.g., newly authored tests that have not been run yet).\n\nUse this tool to understand:\n- What the test is designed to verify (test intent and description)\n- The test's configuration: credentials, target URL, application\n- The sequence of flows that make up the test\n- What each step in each flow does\n- How flows are nested within other flows\n- Parameters that flows accept\n- JavaScript code executed by steps (inline JS and snippets)\n- Code snippets referenced in the test and their source code\n\nThis provides the \"expected behavior\" of the test, which you can compare against\nactual execution results from get_test_run_info to understand failures.",
    argumentsSchema: exports.getTestDefinitionParamsSchema,
    responseSchema: exports.getTestDefinitionResponseSchema,
});
//# sourceMappingURL=GetTestDefinitionDefinition.js.map