import { providerSupportsStructuredOutput } from '../../infra/providers/provider-capabilities.js';
import { DefaultStructuredCaller } from './default-structured-caller.js';
import { PromptBasedStructuredCaller } from './prompt-based-structured-caller.js';
function resolveProvider(provider, resolvedProvider) {
    return resolvedProvider ?? provider;
}
function shouldUsePromptBased(provider) {
    return provider !== undefined && !providerSupportsStructuredOutput(provider);
}
export class CapabilityAwareStructuredCaller extends DefaultStructuredCaller {
    promptBased = new PromptBasedStructuredCaller();
    async judgeStatus(structuredInstruction, tagInstruction, rules, options) {
        const provider = resolveProvider(options.provider, options.resolvedProvider);
        if (shouldUsePromptBased(provider)) {
            return this.promptBased.judgeStatus(structuredInstruction, tagInstruction, rules, options);
        }
        return super.judgeStatus(structuredInstruction, tagInstruction, rules, options);
    }
    async evaluateCondition(agentOutput, conditions, options) {
        const provider = resolveProvider(options.provider, options.resolvedProvider);
        if (shouldUsePromptBased(provider)) {
            return this.promptBased.evaluateCondition(agentOutput, conditions, options);
        }
        return super.evaluateCondition(agentOutput, conditions, options);
    }
    async decomposeTask(instruction, maxParts, options) {
        const provider = resolveProvider(options.provider, options.resolvedProvider);
        if (shouldUsePromptBased(provider)) {
            return this.promptBased.decomposeTask(instruction, maxParts, options);
        }
        return super.decomposeTask(instruction, maxParts, options);
    }
    async requestMoreParts(originalInstruction, allResults, existingIds, maxAdditionalParts, options) {
        const provider = resolveProvider(options.provider, options.resolvedProvider);
        if (shouldUsePromptBased(provider)) {
            return this.promptBased.requestMoreParts(originalInstruction, allResults, existingIds, maxAdditionalParts, options);
        }
        return super.requestMoreParts(originalInstruction, allResults, existingIds, maxAdditionalParts, options);
    }
}
//# sourceMappingURL=capability-aware-structured-caller.js.map