"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExecuteFlowToolDefinition = exports.executeFlowClientResponseSchema = exports.executeFlowServerResultSchema = exports.executeFlowArgumentsSchema = void 0;
var zod_1 = require("zod");
var toolDefinition_js_1 = require("../toolDefinition.js");
var agentToolNames_js_1 = require("../shared/agentToolNames.js");
var iterationConfigSchema = zod_1.z.object({
    iteration_type: zod_1.z.enum(['fixed', 'variable']).meta({
        description: 'How to determine the number of iterations. "fixed" = a literal number, "variable" = the name of a variable that holds a number.',
    }),
    iteration_value: zod_1.z.string().meta({
        description: 'The value for the iteration. For "fixed": a whole-number string (e.g. "3"). For "variable": a variable name without braces (e.g. "itemCount").',
    }),
});
exports.executeFlowArgumentsSchema = zod_1.z.object({
    flow_id: zod_1.z.string().meta({
        description: 'The unique identifier of the flow to execute. Get this from request_flow_tools search results.',
    }),
    parameters: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional().meta({
        description: 'Parameters for the flow as a JSON object. Keys should match the parameter names from the flow. Values can reference variables using {{@variableName}} syntax.',
    }),
    loop: iterationConfigSchema.optional().meta({
        description: 'Optional loop configuration. When provided, the flow step is configured to execute multiple times. Omit this field entirely if the flow should run only once.',
    }),
});
exports.executeFlowServerResultSchema = zod_1.z.object({
    flow_name: zod_1.z.string().optional().meta({
        description: 'The human-readable name of the flow, resolved from the flow ID.',
    }),
    flow_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 defined on the flow, if any.',
    }),
    parameter_warning: zod_1.z.string().optional().meta({
        description: 'Warning message if the flow has parameters but none were provided.',
    }),
});
/**
 * Response schema for execute_flow tool.
 * The client should include the new screenshot and any variables created by the flow
 * to provide context for the next agent decision.
 */
exports.executeFlowClientResponseSchema = zod_1.z.object({
    success: zod_1.z.boolean(),
    message: zod_1.z.string().optional(),
    // Context fields - client should include these after executing the action
    new_screenshot: zod_1.z.string().optional().meta({
        description: 'Base64-encoded PNG screenshot of the page after flow execution',
    }),
    current_url: zod_1.z.string().optional().meta({
        description: 'The current URL after flow execution',
    }),
    created_variables: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional().meta({
        description: 'Variables created or modified by the flow, as name-value pairs',
    }),
});
exports.ExecuteFlowToolDefinition = (0, toolDefinition_js_1.defineTool)({
    name: agentToolNames_js_1.AgentToolNames.ExecuteFlow,
    description: "Executes a mabl flow. A flow is a reusable sequence of steps that automates a task in the application. The client response will include a new screenshot and any variables created by the flow.\n\n**Workflow**:\n1. First, use request_flow_tools to search for flows relevant to your current task\n2. Review the search results to find a flow that matches your needs\n3. Use this tool with the flow_id from the search results\n4. Provide parameters as a JSON object matching the flow's parameter schema\n5. Optionally provide a loop configuration to run the flow multiple times\n\n**Parameter Values**:\n- Parameters can be literal values: {\"username\": \"test@example.com\"}\n- Parameters can reference existing variables: {\"username\": \"{{@email}}\"}\n- Parameter names and requirements are shown in the flow search results\n\n**Loop Configuration**:\n- Omit `loop` entirely if the flow should run only once\n- Use `loop` when you need to repeat the flow a fixed number of times, a variable number of times, or once per item in a list\n- See the flow_loop skill for detailed guidance on when and how to use loops\n\n**Example** (single run):\n{\n  \"flow_id\": \"abc-123-f\",\n  \"parameters\": {\n    \"username\": \"{{@testUser}}\",\n    \"password\": \"{{@testPassword}}\"\n  }\n}\n\n**Example** (loop 3 times):\n{\n  \"flow_id\": \"abc-123-f\",\n  \"parameters\": {},\n  \"loop\": {\n    \"iteration_type\": \"fixed\",\n    \"iteration_value\": \"3\"\n  }\n}",
    argumentsSchema: exports.executeFlowArgumentsSchema,
    serverPrepareResultSchema: exports.executeFlowServerResultSchema,
    responseSchema: exports.executeFlowClientResponseSchema,
});
//# sourceMappingURL=ExecuteFlowDefinition.js.map