import { resolveProviderModelCandidates, resolveModelFromCandidates, } from '../provider-resolution.js';
export function resolveAgentProviderModel(input) {
    const personaEntry = input.personaProviders?.[input.personaDisplayName ?? ''];
    const provider = resolveProviderModelCandidates([
        { provider: input.cliProvider },
        { provider: personaEntry?.provider },
        { provider: input.localProvider },
        { provider: input.globalProvider },
    ]).provider;
    const model = resolveModelFromCandidates([
        { model: input.cliModel },
        { model: personaEntry?.model },
        { model: input.localModel, provider: input.localProvider },
        { model: input.globalModel, provider: input.globalProvider },
    ], provider);
    return { provider, model };
}
export function resolveStepProviderModel(input) {
    const personaEntry = input.personaProviders?.[input.step.personaDisplayName];
    let provider;
    let providerSource;
    if (input.step.provider !== undefined) {
        provider = input.step.provider;
        providerSource = 'step';
    }
    else if (personaEntry?.provider !== undefined) {
        provider = personaEntry.provider;
        providerSource = 'persona_providers';
    }
    else if (input.provider !== undefined) {
        provider = input.provider;
        providerSource = input.providerSource;
    }
    let model;
    let modelSource;
    if (input.step.model !== undefined) {
        model = input.step.model;
        modelSource = 'step';
    }
    else if (personaEntry?.model !== undefined) {
        model = personaEntry.model;
        modelSource = 'persona_providers';
    }
    else if (input.model !== undefined) {
        model = input.model;
        modelSource = input.modelSource;
    }
    return { provider, model, providerSource, modelSource };
}
export function resolveWorkflowCallProviderModel(input) {
    const provider = resolveProviderModelCandidates([
        { provider: input.workflow.provider },
        { provider: input.provider },
    ]).provider;
    const model = resolveProviderModelCandidates([
        { model: input.workflow.model },
        { model: input.model },
    ]).model;
    return { provider, model };
}
export function resolveLoopMonitorJudgeProviderModel(input) {
    const triggeringStep = resolveStepProviderModel({
        step: input.triggeringStep,
        provider: input.provider,
        model: input.model,
        personaProviders: input.personaProviders,
    });
    return {
        provider: input.judge.provider ?? triggeringStep.provider,
        model: input.judge.model
            ?? (input.judge.provider !== undefined ? undefined : triggeringStep.model),
    };
}
//# sourceMappingURL=provider-resolution.js.map