"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SearchSnapshotToolDefinition = exports.searchSnapshotResponseSchema = exports.searchSnapshotArgumentsSchema = void 0;
var zod_1 = require("zod");
var toolDefinition_js_1 = require("../toolDefinition.js");
var agentToolNames_js_1 = require("./agentToolNames.js");
exports.searchSnapshotArgumentsSchema = zod_1.z.object({
    reasoning: zod_1.z.string().optional().describe('Brief explanation of what you are looking for and why'),
    pattern: zod_1.z.string().describe("Regex pattern to match against lines of the page element listing. Case-insensitive.\n\nThe element listing is a YAML-shaped tree where each line describes one element on the page:\n  - <role> \"<accessible name>\" [ref=eN] [attr=value]\nRoles are aria-style ('button', 'textbox', 'link', 'dialog', 'heading', ...). Indentation shows parent/child nesting, so a textbox indented under a form belongs to that form. Link targets appear on their own child line as `- /url: <href>`.\n\nExample patterns:\n  - 'button.*[Ss]ubmit'        find submit-style buttons\n  - 'textbox.*[Ee]mail'        find email inputs\n  - '\\[ref=e42\\]'             locate a specific element by ref\n  - 'dialog|alertdialog'       find modal containers\n  - '/url:.*login'             find links whose href contains \"login\""),
    context_lines: zod_1.z
        .number()
        .int()
        .min(0)
        .max(20)
        .optional()
        .describe('How many surrounding lines of the element listing to include around each match, so ancestor and sibling elements are visible. Defaults to 5.'),
    limit: zod_1.z.number().int().min(1).max(50).optional().describe('Maximum number of hits to return. Defaults to 10.'),
});
var searchSnapshotHitSchema = zod_1.z.object({
    line_number: zod_1.z.number().int().describe('1-based line number of the matching line in the full element listing'),
    match: zod_1.z.string().describe('The matching line from the element listing'),
    context: zod_1.z
        .string()
        .describe('The matching line plus surrounding lines joined by newlines, preserving original indentation so parent/child nesting is readable'),
    refs_in_context: zod_1.z
        .array(zod_1.z.string())
        .describe('Element refs (e.g. "e42") that appear anywhere in the returned context block. Use these refs with element-action tools to operate on the matching elements.'),
});
exports.searchSnapshotResponseSchema = zod_1.z.object({
    success: zod_1.z.boolean().describe('Whether the search ran without error'),
    hits: zod_1.z.array(searchSnapshotHitSchema).describe('Matches in line order, truncated to `limit`'),
    total_matched: zod_1.z
        .number()
        .int()
        .describe('Total number of lines that matched before applying `limit`, so the agent knows when to narrow the pattern'),
    snapshot_total_lines: zod_1.z.number().int().describe('Total number of lines in the full page element listing'),
    message: zod_1.z
        .string()
        .optional()
        .describe('Error description if the search failed (invalid regex, element listing unavailable, etc.)'),
});
exports.SearchSnapshotToolDefinition = (0, toolDefinition_js_1.defineTool)({
    name: agentToolNames_js_1.AgentToolNames.SearchSnapshot,
    description: "Search the page's element listing with a regex and return matching lines with surrounding context.\n\nThe element listing is a textual, indented tree of every interactive and semantic element currently rendered on the page \u2014 buttons, inputs, links, headings, dialogs, list items, and so on. Each line describes one element by its role, its accessible name, and attributes like `[ref=eN]` that can be passed to element-action tools. Indentation shows parent/child nesting, so an element indented under a `dialog` lives inside that dialog. The listing is computed live from the page DOM each time the tool runs, so it always reflects the current state.\n\nUse this tool to:\n- Discover what's actually on the page when a step failed to find or interact with an element\n- Locate a specific control by role + accessible name (e.g. find the real \"Submit\" button after a label change)\n- Confirm whether an obstacle (modal, dialog, banner, overlay) is present before deciding how to recover\n- Pull the ref of a candidate element so an action tool can operate on it\n\nTips for effective queries:\n- Start with the role plus a fragment of the visible name, e.g. `button.*[Ss]ubmit`\n- Use `context_lines` to see the surrounding form / section / dialog ancestry \u2014 the default is usually enough\n- If `total_matched` is high, narrow the pattern; refs and ancestry in the existing hits are usually enough to act on\n- An invalid regex returns `success: false` with a `message` \u2014 fix the pattern and retry",
    argumentsSchema: exports.searchSnapshotArgumentsSchema,
    responseSchema: exports.searchSnapshotResponseSchema,
});
//# sourceMappingURL=SearchSnapshotDefinition.js.map