"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProviderSchema = exports.ProvidersSchema = exports.ApiProviderSchema = exports.ProviderOptionsSchema = void 0;
const zod_1 = require("zod");
const env_1 = require("../types/env");
const prompts_1 = require("./prompts");
const shared_1 = require("./shared");
exports.ProviderOptionsSchema = zod_1.z
    .object({
    id: zod_1.z.custom().optional(),
    label: zod_1.z.custom().optional(),
    config: zod_1.z.any().optional(),
    prompts: zod_1.z.array(zod_1.z.string()).optional(),
    transform: zod_1.z.string().optional(),
    delay: zod_1.z.number().optional(),
    env: env_1.ProviderEnvOverridesSchema.optional(),
})
    .strict();
const CallApiContextParamsSchema = zod_1.z.object({
    fetchWithCache: zod_1.z.optional(zod_1.z.any()),
    filters: shared_1.NunjucksFilterMapSchema.optional(),
    getCache: zod_1.z.optional(zod_1.z.any()),
    logger: zod_1.z.optional(zod_1.z.any()),
    originalProvider: zod_1.z.optional(zod_1.z.any()),
    prompt: prompts_1.PromptSchema,
    vars: zod_1.z.record(zod_1.z.union([zod_1.z.string(), zod_1.z.object({})])),
});
const CallApiOptionsParamsSchema = zod_1.z.object({
    includeLogProbs: zod_1.z.optional(zod_1.z.boolean()),
});
const CallApiFunctionSchema = zod_1.z
    .function()
    .args(zod_1.z.string().describe('prompt'), CallApiContextParamsSchema.optional(), CallApiOptionsParamsSchema.optional())
    .returns(zod_1.z.promise(zod_1.z.custom()))
    .and(zod_1.z.object({ label: zod_1.z.string().optional() }));
exports.ApiProviderSchema = zod_1.z.object({
    id: zod_1.z.function().returns(zod_1.z.string()),
    callApi: zod_1.z.custom(),
    callEmbeddingApi: zod_1.z
        .function()
        .args(zod_1.z.string())
        .returns(zod_1.z.promise(zod_1.z.custom()))
        .optional(),
    callClassificationApi: zod_1.z
        .function()
        .args(zod_1.z.string())
        .returns(zod_1.z.promise(zod_1.z.custom()))
        .optional(),
    label: zod_1.z.custom().optional(),
    transform: zod_1.z.string().optional(),
    delay: zod_1.z.number().optional(),
    config: zod_1.z.any().optional(),
});
exports.ProvidersSchema = zod_1.z.union([
    zod_1.z.string(),
    CallApiFunctionSchema,
    zod_1.z.array(zod_1.z.union([
        zod_1.z.string(),
        zod_1.z.record(zod_1.z.string(), exports.ProviderOptionsSchema),
        exports.ProviderOptionsSchema,
        CallApiFunctionSchema,
    ])),
]);
exports.ProviderSchema = zod_1.z.union([zod_1.z.string(), exports.ProviderOptionsSchema, exports.ApiProviderSchema]);
//# sourceMappingURL=providers.js.map