// Planu — Agent Spec Generator: Contract Builder
// SPEC-016a: Generates and formats agent interaction contracts.
/**
 * Generate Interaction Contract for agent specs.
 * Criteria 3: channels (chat/email/dashboard/notifications), not UI components.
 */
export function generateAgentInteractionContract(title, description) {
    const lower = description.toLowerCase();
    const channels = [];
    if (lower.includes('chat') ||
        lower.includes('conversation') ||
        lower.includes('message') ||
        lower.includes('assistant')) {
        channels.push('chat');
    }
    if (lower.includes('email') || lower.includes('notify') || lower.includes('alert')) {
        channels.push('email');
        channels.push('notifications');
    }
    if (lower.includes('dashboard') ||
        lower.includes('report') ||
        lower.includes('analytics') ||
        lower.includes('monitor')) {
        channels.push('dashboard');
    }
    // Default: chat + notifications if no channel detected
    if (channels.length === 0) {
        channels.push('chat');
        channels.push('notifications');
    }
    const responseFormat = {
        success: 'structured message with result, sources cited, confidence level',
        partial: 'progress update with current step and estimated completion',
        error: 'error description, what was attempted, suggested next steps',
        escalation: 'escalation notice with context for human review',
    };
    const escalationRules = [
        `Escalate when confidence < 0.7 on critical decisions for "${title}"`,
        'Escalate when tool has failed more than once on the same request',
        'Escalate when user expresses frustration or requests human assistance',
        'Escalate when task requires authorization beyond agent permissions',
        'Always include: what was attempted, why it failed, what the human should do',
    ];
    return { channels, responseFormat, escalationRules };
}
/**
 * Format agent interaction contract as markdown for define_ui_contract.
 */
export function formatInteractionContractAsMarkdown(contract, title) {
    const lines = [
        `## Interaction Contract: ${title}`,
        '',
        '> This agent uses an Interaction Contract instead of a UI Contract.',
        '> Defines communication channels, response formats, and escalation rules.',
        '',
        '### Interaction Channels',
        '',
    ];
    for (const channel of contract.channels) {
        const channelDescriptions = {
            chat: 'Real-time conversational interface (web, mobile, messaging platforms)',
            email: 'Asynchronous email-based interactions',
            dashboard: 'Structured output rendered in a dashboard UI',
            notifications: 'Push notifications, webhooks, or alerts',
        };
        lines.push(`- **${channel}**: ${channelDescriptions[channel] ?? channel}`);
    }
    lines.push('', '### Response Formats', '');
    for (const [type, format] of Object.entries(contract.responseFormat)) {
        lines.push(`- **${type}**: ${format}`);
    }
    lines.push('', '### Escalation Rules', '');
    for (const rule of contract.escalationRules) {
        lines.push(`- ${rule}`);
    }
    return lines.join('\n');
}
//# sourceMappingURL=contract-builder.js.map