"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../../../src/utils");
const core_1 = require("./core");
const codeExample = `{
    "name": {
        "type": "string",
        "required": true,
        "description": "Name of the item"
    },
    "date": {
        "type": "string",
        "description": "Date of the item"
    }
}`;
class RequestsPost_Tools {
    constructor() {
        this.label = 'Requests Post';
        this.name = 'requestsPost';
        this.version = 2.0;
        this.type = 'RequestsPost';
        this.icon = 'post.png';
        this.category = 'Tools';
        this.description = 'Execute HTTP POST requests';
        this.baseClasses = [this.type, ...(0, utils_1.getBaseClasses)(core_1.RequestsPostTool), 'Tool'];
        this.inputs = [
            {
                label: 'URL',
                name: 'requestsPostUrl',
                type: 'string',
                acceptVariable: true
            },
            {
                label: 'Name',
                name: 'requestsPostName',
                type: 'string',
                default: 'requests_post',
                description: 'Name of the tool',
                additionalParams: true,
                optional: true
            },
            {
                label: 'Description',
                name: 'requestsPostDescription',
                type: 'string',
                rows: 4,
                default: core_1.desc,
                description: 'Describe to LLM when it should use this tool',
                additionalParams: true,
                optional: true
            },
            {
                label: 'Headers',
                name: 'requestsPostHeaders',
                type: 'string',
                rows: 4,
                acceptVariable: true,
                additionalParams: true,
                optional: true,
                placeholder: `{
    "Authorization": "Bearer <token>"
}`
            },
            {
                label: 'Body',
                name: 'requestPostBody',
                type: 'string',
                rows: 4,
                description: 'JSON body for the POST request. This will override the body generated by the LLM',
                additionalParams: true,
                acceptVariable: true,
                optional: true,
                placeholder: `{
    "name": "John Doe",
    "age": 30
}`
            },
            {
                label: 'Body Schema',
                name: 'requestsPostBodySchema',
                type: 'code',
                description: 'Description of the available body params to enable LLM to figure out which body params to use',
                placeholder: `{
    "name": {
        "type": "string",
        "required": true,
        "description": "Name of the item"
    },
    "date": {
        "type": "string",
        "description": "Date of the item"
    }
}`,
                optional: true,
                hideCodeExecute: true,
                additionalParams: true,
                codeExample: codeExample
            },
            {
                label: 'Max Output Length',
                name: 'requestsPostMaxOutputLength',
                type: 'number',
                description: 'Max length of the output. Remove this if you want to return the entire response',
                default: '2000',
                step: 1,
                optional: true,
                additionalParams: true
            }
        ];
    }
    async init(nodeData) {
        const headers = nodeData.inputs?.headers || nodeData.inputs?.requestsPostHeaders;
        const url = nodeData.inputs?.url || nodeData.inputs?.requestsPostUrl;
        const name = nodeData.inputs?.name || nodeData.inputs?.requestsPostName;
        const description = nodeData.inputs?.description || nodeData.inputs?.requestsPostDescription;
        const body = nodeData.inputs?.body || nodeData.inputs?.requestPostBody;
        const bodySchema = nodeData.inputs?.requestsPostBodySchema;
        const maxOutputLength = nodeData.inputs?.maxOutputLength || nodeData.inputs?.requestsPostMaxOutputLength;
        const obj = {};
        if (url)
            obj.url = (0, utils_1.stripHTMLFromToolInput)(url);
        if (description)
            obj.description = description;
        if (name)
            obj.name = name
                .toLowerCase()
                .replace(/ /g, '_')
                .replace(/[^a-z0-9_-]/g, '');
        if (bodySchema)
            obj.bodySchema = (0, utils_1.stripHTMLFromToolInput)(bodySchema);
        if (maxOutputLength)
            obj.maxOutputLength = parseInt(maxOutputLength, 10);
        if (headers) {
            const parsedHeaders = typeof headers === 'object' ? headers : (0, utils_1.parseJsonBody)((0, utils_1.stripHTMLFromToolInput)(headers));
            obj.headers = parsedHeaders;
        }
        if (body) {
            const parsedBody = typeof body === 'object' ? body : (0, utils_1.parseJsonBody)(body);
            obj.body = parsedBody;
        }
        return new core_1.RequestsPostTool(obj);
    }
}
module.exports = { nodeClass: RequestsPost_Tools };
//# sourceMappingURL=RequestsPost.js.map