import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { AgentToolNames } from '../shared/agentToolNames.js';
const description = `
Counts the number of elements matching a CSS or XPath selector and stores the count as a numeric variable. Use the resulting variable with execute_assert_variable to assert on the count (greater_than, equals, etc.).

Examples:
- count search results: variableName: 'searchResultCount', selectorType: 'css', selector: '.search-result'
- count cart items: variableName: 'cartItemCount', selectorType: 'css', selector: '[data-test-id="cart-item"]'
- count rows in a table: variableName: 'tableRowCount', selectorType: 'xpath', selector: '//table[@id="orders"]/tbody/tr'

Variable names should be alphanumeric and underscores only, no periods. The count is always a non-negative integer; selectors that match nothing produce 0.
`.trim();
export const executeCountElementsArgumentsSchema = z.object({
    description: z
        .string()
        .max(100)
        .meta({ description: 'A brief description of what this step does (max 100 characters)' }),
    variableName: z
        .string()
        .regex(/^[A-Za-z0-9_]+$/)
        .meta({
        description: 'The name of the variable to store the count in. Alphanumeric and underscores only, no periods.',
    }),
    selectorType: z.enum(['css', 'xpath']).meta({
        description: 'Which selector flavor `selector` is — CSS query or XPath expression.',
    }),
    selector: z.string().min(1).meta({
        description: 'CSS query or XPath expression that matches the elements to count.',
    }),
    reasoning: z.string().optional().meta({ description: 'Brief explanation of why this count is being captured.' }),
});
export const executeCountElementsClientResponseSchema = z.object({
    success: z.boolean(),
    message: z.string().optional(),
    variable_name: z.string().optional().meta({
        description: 'The name of the variable that was created with the element count.',
    }),
    variable_value: z.string().optional().meta({
        description: 'The count value stored in the variable, as a string.',
    }),
});
export const ExecuteCountElementsToolDefinition = defineTool({
    name: AgentToolNames.ExecuteCountElements,
    description,
    argumentsSchema: executeCountElementsArgumentsSchema,
    responseSchema: executeCountElementsClientResponseSchema,
});
//# sourceMappingURL=ExecuteCountElementsDefinition.js.map