"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tailToolResponseDefinition = void 0;
exports.executeTail = executeTail;
async function executeTail(data, toolCallId, availableIds, options, toolNameMap) {
    if (data === null || data === undefined) {
        const idList = availableIds
            .map((id) => {
            const name = toolNameMap?.[id];
            return name ? `${id} (${name})` : id;
        })
            .join("\n  - ");
        return `Error: No tool response found for toolCallId "${toolCallId}". Call listStoredToolResponses to see all available responses with their tool names.\n\nAvailable toolCallIds:\n  - ${idList || "(none)"}`;
    }
    try {
        const lines = data.split("\n");
        const numLines = options?.lines ?? 10;
        if (numLines <= 0) {
            return "";
        }
        const startIdx = Math.max(0, lines.length - numLines);
        const tailLines = lines.slice(startIdx);
        const formatted = tailLines.map((line, idx) => {
            const lineNum = startIdx + idx + 1;
            return `${lineNum}: ${line}`;
        });
        return formatted.join("\n");
    }
    catch (error) {
        return `Tail Error: ${error.message}`;
    }
}
exports.tailToolResponseDefinition = {
    type: "function",
    function: {
        name: "tailToolResponse",
        description: "Get the last n lines from a stored tool response. Similar to the Unix 'tail' command, useful when a tool response is too large and you only need to see the end. Returns the last n lines with line numbers.",
        parameters: {
            type: "object",
            positional: true,
            properties: {
                toolCallId: {
                    type: "string",
                    description: "The toolCallId of the stored tool response",
                },
                options: {
                    type: "object",
                    description: "Optional tail settings: lines (number, default: 10) - number of lines to return from the end",
                    properties: {
                        lines: {
                            type: "number",
                            description: "Number of lines to return from the end (default: 10)",
                        },
                    },
                },
            },
            required: ["toolCallId"],
        },
    },
};
//# sourceMappingURL=tailToolResponse.js.map