import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { AgentToolNames } from './agentToolNames.js';
import { TOOL_ELEMENT_DESCRIPTION_INSTRUCTIONS } from './constants.js';
import { customFindSchema } from './customFind.js';
export const executeEnterTextArgumentsSchema = z.object({
    description: z.string().max(100).describe('A brief description of what this step does (max 100 characters)'),
    elementDescription: z.string().meta({
        description: TOOL_ELEMENT_DESCRIPTION_INSTRUCTIONS,
    }),
    text: z.string().meta({
        description: `The text to enter in the element. Supports {{@variableName}} syntax to reference test variables — the client resolves variables before typing. Use ${AgentToolNames.GetAvailableVariables} to verify a variable exists before referencing it.`,
    }),
    customFind: customFindSchema.optional(),
    reasoning: z
        .string()
        .optional()
        .describe('Brief explanation of why this action is being taken and what it aims to achieve'),
});
export const executeEnterTextServerResultSchema = z.object({
    elementDescription: z.string(),
    text: z.string(),
    elementBoundingBox: z
        .object({
        top: z.number(),
        left: z.number(),
        bottom: z.number(),
        right: z.number(),
    })
        .optional(),
    elementTargetPoint: z
        .object({
        x: z.number(),
        y: z.number(),
    })
        .optional(),
    // Application-level enter-text preference (the `enter_text_mode` field on the
    // Application). The server passes the enum value through verbatim; the client
    // (mabl-cli) translates it into the matching descriptor shape. Absent means
    // "no preference; client uses its own default" (fill since mabl-cli #3493).
    // Per-step user overrides in the trainer UI still win — this only seeds new
    // steps.
    enterTextMode: z.enum(['fill', 'press']).optional(),
});
/**
 * Response schema for execute_enter_text tool.
 * The client should include the new screenshot and current URL after the text entry
 * to provide context for the next agent decision without requiring a separate user prompt.
 */
export const executeEnterTextClientResponseSchema = z.object({
    success: z.boolean(),
    message: z.string().optional(),
    // Context fields - client should include these after executing the action
    new_screenshot: z.string().optional().meta({
        description: 'Base64-encoded PNG screenshot of the page after entering text',
    }),
    current_url: z.string().optional().meta({
        description: 'The current URL after the action (in case of form submission or navigation)',
    }),
});
export const ExecuteEnterTextToolDefinition = defineTool({
    name: AgentToolNames.ExecuteEnterText,
    description: `Enters text into an input field in the app identified by the provided description to uniquely identify it in the screenshot. Supports {{@variableName}} syntax — variables are resolved to their current values before typing. Use ${AgentToolNames.GetAvailableVariables} to confirm a variable exists before referencing it. Can also be used for certain dropdown elements when click fails. The client response will include a new screenshot showing the result.`,
    argumentsSchema: executeEnterTextArgumentsSchema,
    serverPrepareResultSchema: executeEnterTextServerResultSchema,
    responseSchema: executeEnterTextClientResponseSchema,
});
//# sourceMappingURL=ExecuteEnterTextDefinition.js.map