import { getProviderOptionsForCapability, resolveModelCapabilityProfile } from '../llm/model-capabilities.js';
import { FULL_RUNTIME_TOOL_NAMES, MATERIAL_RUNTIME_TOOL_NAMES, POST_SYNC_RUNTIME_TOOL_NAMES, SYNTHETIC_RUNTIME_TOOL_NAMES, } from '../tools/toolsets.js';
function buildToolingPolicy(capabilityProfile) {
    switch (capabilityProfile.toolCalling) {
        case 'native':
            return {
                availableToolNames: [...FULL_RUNTIME_TOOL_NAMES],
                allowedToolNamesAfterWorkflowSync: [...POST_SYNC_RUNTIME_TOOL_NAMES],
                toolCallMode: capabilityProfile.supportsParallelToolCalls ? 'parallel' : 'sequential',
                executionCriticalToolNames: [...MATERIAL_RUNTIME_TOOL_NAMES],
            };
        case 'compatible':
            return {
                availableToolNames: [...FULL_RUNTIME_TOOL_NAMES],
                allowedToolNamesAfterWorkflowSync: [...POST_SYNC_RUNTIME_TOOL_NAMES],
                toolCallMode: 'sequential',
                executionCriticalToolNames: [...MATERIAL_RUNTIME_TOOL_NAMES],
            };
        case 'none':
            return {
                availableToolNames: [...SYNTHETIC_RUNTIME_TOOL_NAMES],
                allowedToolNamesAfterWorkflowSync: [...POST_SYNC_RUNTIME_TOOL_NAMES],
                toolCallMode: 'disabled',
                executionCriticalToolNames: [],
            };
    }
}
export function resolveToolRuntimeStrategy(provider, model) {
    const capabilityProfile = resolveModelCapabilityProfile({
        provider: provider ?? 'openai',
        model: model ?? '',
    });
    const base = {
        capabilityProfile,
        tooling: buildToolingPolicy(capabilityProfile),
        executionMode: capabilityProfile.supportsStreamingToolCalls ? 'stream' : 'generate',
        toolCallStreaming: capabilityProfile.supportsStreamingToolCalls,
        providerOptions: getProviderOptionsForCapability(capabilityProfile),
    };
    switch (capabilityProfile.toolCalling) {
        case 'native':
            return {
                ...base,
                inspectMaxSteps: 4,
                executeMaxSteps: 10,
                recoveryMaxSteps: 6,
                inspectDirectives: [],
                executeDirectives: [
                    'Tool calling is natively supported.',
                    'Do not respond with only text or an empty response — you must call a tool to make progress.',
                    'If you already have sufficient context, call writeWorkspaceFile immediately to author the workflow file.',
                    'If you still need node schemas or examples, call searchNodes or n8nac skills first, then write the file.',
                    'After writing the workflow file, use n8nac to validate, push, and verify. Stop only after verify succeeds.',
                ],
                recoveryDirectives: [],
            };
        case 'compatible':
            return {
                ...base,
                inspectMaxSteps: 4,
                executeMaxSteps: 8,
                recoveryMaxSteps: 5,
                inspectDirectives: [
                    'Treat tool use as single-step and conservative. Avoid broad exploration once the required path is clear.',
                ],
                executeDirectives: [
                    'Use one tool at a time when possible.',
                    'Prefer direct workflow actions over repeated workspace searches.',
                    'After push and verify succeed, stop and return the user-facing response.',
                ],
                recoveryDirectives: [
                    'Retry only the failing step; do not restart the whole exploration sequence.',
                ],
            };
        case 'none':
            return {
                ...base,
                executionMode: 'generate',
                toolCallStreaming: false,
                inspectMaxSteps: 1,
                executeMaxSteps: 1,
                recoveryMaxSteps: 1,
                inspectDirectives: [
                    'Do not attempt direct tool use in this mode.',
                    'Infer the smallest possible execution plan without tool calls.',
                ],
                executeDirectives: [
                    'Tool calling is unavailable in this mode.',
                    'Respond with JSON objects only, no markdown and no prose.',
                    'Supported JSON intents are limited to:',
                    '{"tool":"writeWorkspaceFile","path":"<workspace-relative .workflow.ts path>","content":"<full file content>","mode":"overwrite"}',
                    '{"tool":"n8nac","action":"validate","validateFile":"<same .workflow.ts path>"}',
                    '{"tool":"n8nac","action":"push","filename":"<same .workflow.ts path>"}',
                    'Use the smallest sequence needed to complete the task. Prefer one workflow file write, then validate, then push.',
                ],
                recoveryDirectives: [
                    'If the previous JSON intents were invalid, emit a corrected JSON-only sequence.',
                ],
            };
    }
}
//# sourceMappingURL=tool-runtime-strategy.js.map