import { resolveAssistantProviderModelFromConfig } from '../../core/config/provider-resolution.js';
import { resolveAssistantConfigLayers } from '../../features/interactive/assistantConfig.js';
import { loadTemplate } from '../../shared/prompts/index.js';
import { getLanguage, resolveConfigValues } from '../config/index.js';
import { getProvider } from '../providers/index.js';
async function autoApproveToolRequest(request) {
    return { behavior: 'allow', updatedInput: request.input };
}
export async function runSyncConflictResolver(options) {
    const lang = getLanguage();
    const systemPrompt = loadTemplate('sync_conflict_resolver_system_prompt', lang);
    const prompt = loadTemplate('sync_conflict_resolver_message', lang, {
        originalInstruction: options.originalInstruction,
    });
    const config = resolveConfigValues(options.projectCwd, ['syncConflictResolver']);
    const resolvedProviderModel = resolveAssistantProviderModelFromConfig(resolveAssistantConfigLayers(options.projectCwd));
    if (!resolvedProviderModel.provider) {
        throw new Error('No provider configured. Set "provider" in ~/.takt/config.yaml');
    }
    const provider = getProvider(resolvedProviderModel.provider);
    const agent = provider.setup({ name: 'conflict-resolver', systemPrompt });
    const onPermissionRequest = config.syncConflictResolver?.autoApproveTools
        ? autoApproveToolRequest
        : undefined;
    return agent.call(prompt, {
        cwd: options.cwd,
        model: resolvedProviderModel.model,
        permissionMode: 'edit',
        onPermissionRequest,
        onStream: options.onStream,
    });
}
//# sourceMappingURL=runSyncConflictResolver.js.map