"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findAppointmentsWithLLM = void 0;
const prompt_1 = require("./prompt");
const parser_1 = require("./parser");
const findAppointmentsWithLLM = async ({ model, appointments, prompt, metadata, callbacks, evaluateDates = false, }) => {
    const chain = model.pipe(parser_1.parser);
    try {
        const formattedAppointments = JSON.stringify(appointments);
        const systemPrompt = evaluateDates
            ? prompt_1.systemPromptWithDates
            : prompt_1.systemPromptWithoutDates;
        const result = (await chain.invoke(await systemPrompt.format({
            currentDateTime: new Date().toISOString(),
            appointments: formattedAppointments,
            prompt,
        }), {
            metadata,
            runName: 'ElationFindAppointmentsWithLLM',
            callbacks,
        }));
        return {
            appointmentIds: result.appointmentIds,
            explanation: result.explanation,
        };
    }
    catch (error) {
        throw new Error(`Failed to find matching appointments. LLM reported error: ${error instanceof Error ? error.message : 'Unknown error'}`);
    }
};
exports.findAppointmentsWithLLM = findAppointmentsWithLLM;
//# sourceMappingURL=findAppointmentsWithLLM.js.map