import { z } from 'zod';
function textResult(data) {
    const text = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
    return { content: [{ type: 'text', text }] };
}
export function registerEmotionalTools(server, ipc) {
    registerEmotionalToolsWithCaller(server, (method, params) => ipc.request(method, params));
}
export function registerEmotionalToolsDirect(server, router) {
    registerEmotionalToolsWithCaller(server, (method, params) => router.handle(method, params));
}
function registerEmotionalToolsWithCaller(server, call) {
    server.tool('brain_emotional_status', 'Get the current emotional state of the brain — mood, dimensions (frustration, curiosity, surprise, confidence, satisfaction, stress, momentum, creativity), and overall status.', {}, async () => {
        const status = await call('emotional.status');
        const mood = status.currentMood;
        const dims = mood.dimensions;
        const lines = [
            `## Brain Emotional Status`,
            `**Mood:** ${mood.mood} (score: ${(mood.score * 100).toFixed(0)}%)`,
            `**Valence:** ${mood.valence > 0 ? '+' : ''}${mood.valence.toFixed(2)} | **Arousal:** ${mood.arousal.toFixed(2)}`,
            '',
            '### Dimensions',
            ...Object.entries(dims).map(([k, v]) => `- **${k}:** ${(v * 100).toFixed(0)}%`),
            '',
            `Cycles: ${status.cycleCount} | History: ${status.historyCount} entries`,
        ];
        return textResult(lines.join('\n'));
    });
    server.tool('brain_mood_history', 'Get the emotional history of the brain over time — shows how mood and dimensions changed across cycles.', { limit: z.number().optional().default(20).describe('Number of history entries to return') }, async ({ limit }) => {
        const history = await call('emotional.history', { limit });
        if (history.length === 0)
            return textResult('No emotional history yet.');
        const lines = ['## Brain Mood History', ''];
        for (const entry of history) {
            lines.push(`**Cycle ${entry.cycle_number}** — ${entry.dominant_mood} (${(entry.mood_score * 100).toFixed(0)}%) | ${entry.timestamp}`);
        }
        return textResult(lines.join('\n'));
    });
    server.tool('brain_mood_influences', 'See what caused recent mood changes — which engines triggered emotional dimension shifts.', { limit: z.number().optional().default(10).describe('Number of influences to return') }, async ({ limit }) => {
        const influences = await call('emotional.influences', { limit });
        if (influences.length === 0)
            return textResult('No mood influences recorded yet.');
        const lines = ['## Brain Mood Influences', ''];
        for (const inf of influences) {
            const delta = inf.delta;
            const arrow = delta > 0 ? '↑' : '↓';
            lines.push(`${arrow} **${inf.dimension}** ${(inf.old_value * 100).toFixed(0)}% → ${(inf.new_value * 100).toFixed(0)}% (${delta > 0 ? '+' : ''}${(delta * 100).toFixed(1)}%) — ${inf.source_engine}`);
        }
        return textResult(lines.join('\n'));
    });
    server.tool('brain_mood_advice', 'Get behavior recommendations based on the current emotional state — what should the brain do given its mood?', {}, async () => {
        const mood = await call('emotional.mood');
        const recs = await call('emotional.recommendations');
        const lines = [
            `## Mood Advice (${mood.mood})`,
            '',
            ...recs.map((r, i) => `${i + 1}. ${r}`),
        ];
        return textResult(lines.join('\n'));
    });
}
//# sourceMappingURL=emotional-tools.js.map