// engine/provider-adapters/adapters/gpt4.ts — SPEC-670: GPT-4 / Codex renderer.
//
// Emits AGENTS.md-compatible markdown:
//  • Header `# AGENTS.md — <title>`
//  • `<thinking>...</thinking>` blocks rewritten as `> Reasoning: ...` quote blocks
//  • Tools listed using OpenAI's `### Tool: name\n**Parameters:** ...\n**Returns:** ...` shape
import { estimateTokens } from '../shared/token-estimator.js';
import { replaceThinkingBlocks } from '../shared/markdown-utils.js';
export class GPT4Renderer {
    kind = 'gpt4';
    render(input) {
        const { loadedSpec } = input;
        const { spec, specBody, signatures, warnings } = loadedSpec;
        const lines = [];
        lines.push(`# AGENTS.md — ${spec.title}`);
        lines.push('');
        if (specBody.trim().length === 0) {
            lines.push(`_(spec body is empty — author has not yet filled in problem/criteria)_`);
        }
        else {
            lines.push(replaceThinkingBlocks(specBody.trim()));
        }
        if (signatures.length > 0) {
            lines.push('');
            lines.push('## Tools');
            lines.push('');
            for (const sig of signatures) {
                lines.push(`### Tool: ${sig.name}`);
                lines.push(`**Parameters:** ${formatParameters(sig.signature)}`);
                lines.push(`**Returns:** ${formatReturn(sig.signature)}`);
                lines.push('');
            }
        }
        const content = lines.join('\n').replace(/\n{3,}/g, '\n\n');
        const tokenEstimate = estimateTokens(content);
        return Promise.resolve({
            provider: 'gpt4',
            content,
            tokenEstimate,
            extras: warnings.length > 0 ? { warnings } : undefined,
        });
    }
}
function formatParameters(signature) {
    const m = /\(([^)]*)\)/.exec(signature);
    if (!m?.[1]) {
        return 'none';
    }
    return m[1].trim() || 'none';
}
function formatReturn(signature) {
    const m = /\)\s*:\s*([^=]+?)(?:\s*=>|\s*\{|\s*$)/.exec(signature);
    if (m?.[1]) {
        return m[1].trim();
    }
    if (/\binterface\b|\btype\b/.test(signature)) {
        return signature.split(/\s+/).slice(0, 3).join(' ');
    }
    return 'unspecified';
}
//# sourceMappingURL=gpt4.js.map