"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runScriptSchema = exports.runScriptStepSchema = exports.closePageSchema = exports.listPagesSchema = exports.evaluateSchema = exports.waitForSchema = exports.fillSchema = exports.clickSchema = exports.screenshotSchema = exports.navigateSchema = exports.handleProp = void 0;
const zod_1 = require("zod");
// _handle is accepted by all page-scoped tools. The YAML generator auto-threads
// it between activities. Agentic (LLM) callers can ignore it — page_id works.
exports.handleProp = zod_1.z.object({
    type: zod_1.z.literal('playwright_page'),
    cdp_endpoint: zod_1.z.string().optional(),
    page_id: zod_1.z.string(),
}).optional().describe('Resource handle from a prior Playwright tool call. Enables cross-activity page access.');
exports.navigateSchema = zod_1.z.object({
    _handle: exports.handleProp,
    page_id: zod_1.z.string().optional()
        .describe('Reuse an existing page to preserve session (cookies, auth). If omitted, opens a new page.'),
    url: zod_1.z.string().describe('URL to navigate to'),
    wait_until: zod_1.z.enum(['load', 'domcontentloaded', 'networkidle']).optional()
        .describe('When to consider navigation complete (default: load)'),
});
exports.screenshotSchema = zod_1.z.object({
    _handle: exports.handleProp,
    url: zod_1.z.string().optional()
        .describe('URL to navigate to before screenshotting. When used WITH page_id, navigates the existing page (preserving session). Without page_id, opens a new page.'),
    wait_until: zod_1.z.enum(['load', 'domcontentloaded', 'networkidle']).optional()
        .describe('When to consider navigation complete — only used with url (default: load)'),
    page_id: zod_1.z.string().optional()
        .describe('Page to screenshot (default: most recent). When combined with url, navigates that page first (preserving session/cookies).'),
    path: zod_1.z.string()
        .describe('File path to save the screenshot PNG'),
    full_page: zod_1.z.boolean().optional()
        .describe('Capture the full scrollable page (default: false)'),
    selector: zod_1.z.string().optional()
        .describe('CSS selector to screenshot a specific element'),
    describe: zod_1.z.boolean().optional()
        .describe('When true, automatically analyze the screenshot using a vision LLM and return a description alongside metadata. Use this when you need to understand the page content.'),
});
exports.clickSchema = zod_1.z.object({
    _handle: exports.handleProp,
    page_id: zod_1.z.string().optional()
        .describe('Page to act on (default: most recent)'),
    selector: zod_1.z.string().describe('CSS selector of the element to click'),
});
exports.fillSchema = zod_1.z.object({
    _handle: exports.handleProp,
    page_id: zod_1.z.string().optional()
        .describe('Page to act on (default: most recent)'),
    selector: zod_1.z.string().describe('CSS selector of the input element'),
    value: zod_1.z.string().describe('Value to type into the input'),
});
exports.waitForSchema = zod_1.z.object({
    _handle: exports.handleProp,
    page_id: zod_1.z.string().optional()
        .describe('Page to act on (default: most recent)'),
    selector: zod_1.z.string().describe('CSS selector to wait for'),
    timeout: zod_1.z.number().optional()
        .describe('Max wait time in ms (default: 10000)'),
});
exports.evaluateSchema = zod_1.z.object({
    _handle: exports.handleProp,
    page_id: zod_1.z.string().optional()
        .describe('Page to act on (default: most recent)'),
    script: zod_1.z.string()
        .describe('JavaScript expression to evaluate in the page context'),
});
exports.listPagesSchema = zod_1.z.object({});
exports.closePageSchema = zod_1.z.object({
    _handle: exports.handleProp,
    page_id: zod_1.z.string().describe('Page ID to close'),
});
exports.runScriptStepSchema = zod_1.z.object({
    action: zod_1.z.enum(['navigate', 'screenshot', 'click', 'fill', 'wait_for', 'wait_for_url', 'wait', 'evaluate'])
        .describe('Browser action to perform'),
    url: zod_1.z.string().optional().describe('URL for navigate action, or URL pattern for wait_for_url'),
    wait_until: zod_1.z.enum(['load', 'domcontentloaded', 'networkidle']).optional()
        .describe('Navigation wait strategy (default: load)'),
    path: zod_1.z.string().optional().describe('File path for screenshot action'),
    full_page: zod_1.z.boolean().optional().describe('Full-page screenshot (default: false)'),
    selector: zod_1.z.string().optional().describe('CSS selector for click/fill/wait_for/screenshot'),
    value: zod_1.z.string().optional().describe('Value for fill action'),
    script: zod_1.z.string().optional().describe('JavaScript for evaluate action'),
    timeout: zod_1.z.number().optional().describe('Timeout in ms for wait_for/wait_for_url/wait actions'),
    not: zod_1.z.boolean().optional().describe('For wait_for_url: wait until URL does NOT match (default: false)'),
    describe: zod_1.z.boolean().optional().describe('For screenshot: auto-analyze via vision LLM and include description in result'),
});
exports.runScriptSchema = zod_1.z.object({
    _handle: exports.handleProp,
    steps: zod_1.z.array(exports.runScriptStepSchema)
        .describe('Ordered list of browser actions to execute sequentially on a single page. ' +
        'Preferred for deterministic YAML workflows — encapsulates an entire browser interaction in one activity.'),
});
