"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ariaTreeTool = void 0;
const ai_1 = require("ai");
const zod_1 = require("zod");
const ariaTreeTool = (v3) => (0, ai_1.tool)({
    description: "gets the accessibility (ARIA) hybrid tree text for the current page. use this to understand structure and content.",
    inputSchema: zod_1.z.object({}),
    execute: async () => {
        v3.logger({
            category: "agent",
            message: `Agent calling tool: ariaTree`,
            level: 1,
        });
        const page = await v3.context.awaitActivePage();
        const { pageText } = (await v3.extract());
        const pageUrl = page.url();
        let content = pageText;
        const MAX_TOKENS = 70000; // rough cap, assume ~4 chars per token for conservative truncation
        const estimatedTokens = Math.ceil(content.length / 4);
        if (estimatedTokens > MAX_TOKENS) {
            const maxChars = MAX_TOKENS * 4;
            content =
                content.substring(0, maxChars) +
                    "\n\n[CONTENT TRUNCATED: Exceeded 70,000 token limit]";
        }
        return { content, pageUrl };
    },
    toModelOutput: (result) => ({
        type: "content",
        value: [{ type: "text", text: `Accessibility Tree:\n${result.content}` }],
    }),
});
exports.ariaTreeTool = ariaTreeTool;
//# sourceMappingURL=ariaTree.js.map