"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldsValidationSchema = exports.fields = void 0;
const extensions_core_1 = require("@awell-health/extensions-core");
const lodash_1 = require("lodash");
const zod_1 = __importDefault(require("zod"));
exports.fields = {
    pageUrl: {
        id: 'pageUrl',
        label: 'Page URL',
        description: 'The URL of the page to scrape',
        type: extensions_core_1.FieldType.STRING,
        required: true,
    },
    prompt: {
        id: 'prompt',
        label: 'Prompt',
        description: 'The prompt used to query the page',
        type: extensions_core_1.FieldType.TEXT,
        required: true,
    },
    jsonSchema: {
        id: 'jsonSchema',
        label: 'JSON Schema',
        description: 'Optional JSON schema to guide the AI’s response and force it to return JSON. This can be useful if you want a structured response that is more suitable for automated processing.',
        type: extensions_core_1.FieldType.JSON,
        required: false,
    },
};
exports.FieldsValidationSchema = zod_1.default.object({
    pageUrl: zod_1.default.string().min(1).url(),
    prompt: zod_1.default.string().min(1),
    jsonSchema: zod_1.default
        .string()
        .optional()
        .transform((str, ctx) => {
        if ((0, lodash_1.isNil)(str) || (0, lodash_1.isEmpty)(str))
            return undefined;
        try {
            const parsedJson = JSON.parse(str);
            if ((0, lodash_1.isEmpty)(parsedJson)) {
                return undefined;
            }
            return parsedJson;
        }
        catch (e) {
            ctx.addIssue({
                code: 'custom',
                message: 'Not a valid JSON object',
            });
            return zod_1.default.NEVER;
        }
    }),
});
//# sourceMappingURL=fields.js.map