"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.waitTool = void 0;
const ai_1 = require("ai");
const zod_1 = require("zod");
const screenshotHandler_js_1 = require("../utils/screenshotHandler.js");
const waitTool = (v3, mode) => (0, ai_1.tool)({
    description: "Wait for a specified time",
    inputSchema: zod_1.z.object({
        timeMs: zod_1.z.number().describe("Time in milliseconds"),
    }),
    execute: async ({ timeMs }) => {
        v3.logger({
            category: "agent",
            message: `Agent calling tool: wait`,
            level: 1,
            auxiliary: {
                arguments: {
                    value: `Waiting for ${timeMs} milliseconds`,
                    type: "string",
                },
            },
        });
        await new Promise((resolve) => setTimeout(resolve, timeMs));
        if (timeMs > 0) {
            v3.recordAgentReplayStep({ type: "wait", timeMs });
        }
        // Take screenshot after wait in hybrid mode for visual feedback
        if (mode === "hybrid") {
            const page = await v3.context.awaitActivePage();
            const screenshotBase64 = await (0, screenshotHandler_js_1.waitAndCaptureScreenshot)(page, 0);
            return { success: true, waited: timeMs, screenshotBase64 };
        }
        return { success: true, waited: timeMs };
    },
    toModelOutput: (result) => {
        const content = [
            {
                type: "text",
                text: JSON.stringify({
                    success: result.success,
                    waited: result.waited,
                }),
            },
        ];
        if (result.screenshotBase64) {
            content.push({
                type: "media",
                mediaType: "image/png",
                data: result.screenshotBase64,
            });
        }
        return { type: "content", value: content };
    },
});
exports.waitTool = waitTool;
//# sourceMappingURL=wait.js.map