import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { AgentToolNames } from '../shared/agentToolNames.js';
import { DYNAMIC_VALUE_INSTRUCTIONS, TOOL_ELEMENT_DESCRIPTION_INSTRUCTIONS } from '../shared/constants.js';
import { customFindSchema } from '../shared/customFind.js';
const variableToolDescription = `
Creates or sets a variable with the given name and value. Variables can be used in other steps by wrapping the variable name in curly braces with an @ symbol in front of the variable name, e.g. {{@variableName}}. Variable names you create should not have periods and should only be alphanumeric. The variable value can be one that you create or it can be extracted from the text of an element in the application. If you are extracting the value from an element, you should include a good element description in the elementDescription parameter.

You cannot create a variable with arbitrary code. The only options are a direct string value, the use of faker (as described below), or extracting the text of an element in the application.

${DYNAMIC_VALUE_INSTRUCTIONS}
`;
export const executeVariableArgumentsSchema = z.object({
    elementDescription: z
        .string()
        .meta({
        description: TOOL_ELEMENT_DESCRIPTION_INSTRUCTIONS,
    })
        .optional(),
    variableName: z.string().meta({
        description: 'The name of the variable to create or set',
    }),
    variableValue: z.string().meta({
        description: 'The current value of the variable. If extracting the value from an element, this should be the expected value of the variable.',
    }),
    customFind: customFindSchema.optional(),
});
export const executeVariableServerResultSchema = z.object({
    variableName: z.string(),
    variableValue: z.string(),
    elementDescription: z.string().optional(),
    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(),
});
/**
 * Response schema for execute_create_or_set_variable tool.
 * The client should include the confirmed variable name and its actual value
 * to provide context about what was created without requiring a separate lookup.
 */
export const executeVariableClientResponseSchema = z.object({
    success: z.boolean(),
    message: z.string().optional(),
    // Context fields - client should include these after executing the action
    variable_name: z.string().optional().meta({
        description: 'The name of the variable that was created or updated',
    }),
    variable_value: z.string().optional().meta({
        description: 'The actual value assigned to the variable (may differ if extracted from element)',
    }),
});
export const ExecuteVariableToolDefinition = defineTool({
    name: AgentToolNames.ExecuteCreateOrSetVariable,
    description: variableToolDescription,
    argumentsSchema: executeVariableArgumentsSchema,
    serverPrepareResultSchema: executeVariableServerResultSchema,
    responseSchema: executeVariableClientResponseSchema,
});
//# sourceMappingURL=ExecuteVariableDefinition.js.map