/**
 * @license
 * Copyright 2025 ReverseCraft
 * SPDX-License-Identifier: Apache-2.0
 */
import { zod } from '../third-party/index.js';
import { ToolCategory } from './categories.js';
import { defineTool } from './tool-definition.js';
const FILTERABLE_MESSAGE_TYPES = [
    'log',
    'debug',
    'info',
    'error',
    'warn',
    'dir',
    'dirxml',
    'table',
    'trace',
    'clear',
    'startGroup',
    'startGroupCollapsed',
    'endGroup',
    'assert',
    'profile',
    'profileEnd',
    'count',
    'timeEnd',
    'verbose',
    'issue',
];
/**
 * Tool to list all console messages for the currently selected page.
 */
export const listConsoleMessages = defineTool({
    name: 'list_console_messages',
    description: 'List all console messages for the currently selected page since the last navigation.',
    annotations: {
        category: ToolCategory.DEBUGGING,
        readOnlyHint: true,
    },
    schema: {
        pageSize: zod
            .number()
            .int()
            .positive()
            .optional()
            .describe('Maximum number of messages to return. When omitted, returns all requests.'),
        pageIdx: zod
            .number()
            .int()
            .min(0)
            .optional()
            .describe('Page number to return (0-based). When omitted, returns the first page.'),
        types: zod
            .array(zod.enum(FILTERABLE_MESSAGE_TYPES))
            .optional()
            .describe('Filter messages to only return messages of the specified resource types. When omitted or empty, returns all messages.'),
        includePreservedMessages: zod
            .boolean()
            .default(false)
            .optional()
            .describe('Set to true to return the preserved messages over the last 3 navigations.'),
        savePath: zod
            .string()
            .optional()
            .describe('File path to save console messages. When provided, messages are saved to this file.'),
        maxLineLength: zod
            .number()
            .int()
            .positive()
            .optional()
            .describe('Maximum length of each console message line. Messages exceeding this length will be truncated. Default is 500.'),
    },
    handler: async (request, response) => {
        response.setIncludeConsoleData(true, {
            pageSize: request.params.pageSize,
            pageIdx: request.params.pageIdx,
            types: request.params.types,
            includePreservedMessages: request.params.includePreservedMessages,
            savePath: request.params.savePath,
            maxLineLength: request.params.maxLineLength,
        });
    },
});
/**
 * Tool to get a specific console message by its ID.
 */
export const getConsoleMessage = defineTool({
    name: 'get_console_message',
    description: `Gets a console message by its ID. You can get all messages by calling ${listConsoleMessages.name}.`,
    annotations: {
        category: ToolCategory.DEBUGGING,
        readOnlyHint: true,
    },
    schema: {
        msgid: zod
            .number()
            .describe('The msgid of a console message on the page from the listed console messages'),
    },
    handler: async (request, response) => {
        response.attachConsoleMessage(request.params.msgid);
    },
});
//# sourceMappingURL=console.js.map