function textResult(data) {
    const text = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
    return { content: [{ type: 'text', text }] };
}
export function registerPeerTools(server, ipc) {
    registerPeerToolsWithCaller(server, (method, params) => ipc.request(method, params));
}
export function registerPeerToolsDirect(server, router) {
    registerPeerToolsWithCaller(server, (method, params) => router.handle(method, params));
}
function registerPeerToolsWithCaller(server, call) {
    server.tool('brain_peer_status', 'Get Brain peer network status: discovery state, online/offline peers, knowledge summaries', {}, async () => {
        const status = await call('peer.status', {});
        const lines = [
            '# Peer Network Status',
            `**Brain:** ${status.brainName} | **Discovery:** ${status.discoveryActive ? 'Active' : 'Inactive'}`,
            `**Online:** ${status.onlinePeers} | **Offline:** ${status.offlinePeers} | **Total Discovered:** ${status.totalDiscovered}`,
            '',
        ];
        if (status.peers?.length > 0) {
            lines.push('## Discovered Peers');
            lines.push('| Name | Status | Version | Principles | Hypotheses | Experiments | Last Seen |');
            lines.push('|------|--------|---------|------------|------------|-------------|-----------|');
            for (const p of status.peers) {
                const ago = Math.round((Date.now() - p.lastSeen) / 1000);
                lines.push(`| ${p.name} | ${p.status === 'online' ? 'Online' : 'Offline'} | ${p.packageVersion} | ${p.knowledgeSummary?.principles ?? 0} | ${p.knowledgeSummary?.hypotheses ?? 0} | ${p.knowledgeSummary?.experiments ?? 0} | ${ago}s ago |`);
            }
        }
        else {
            lines.push('*No peers discovered yet*');
        }
        return textResult(lines.join('\n'));
    });
    server.tool('brain_peer_list', 'List all discovered Brain peers with connection details', {}, async () => {
        const peers = await call('peer.list', {});
        const lines = ['# Discovered Peers', ''];
        if (peers?.length > 0) {
            for (const p of peers) {
                const ago = Math.round((Date.now() - p.lastSeen) / 1000);
                lines.push(`## ${p.name} (${p.status})`);
                lines.push(`- **Version:** ${p.packageVersion}`);
                lines.push(`- **HTTP Port:** ${p.httpPort}`);
                lines.push(`- **Pipe:** ${p.pipeName}`);
                lines.push(`- **Knowledge:** ${p.knowledgeSummary?.principles ?? 0} principles, ${p.knowledgeSummary?.hypotheses ?? 0} hypotheses, ${p.knowledgeSummary?.experiments ?? 0} experiments`);
                lines.push(`- **Last Seen:** ${ago}s ago`);
                lines.push(`- **Discovered:** ${new Date(p.discoveredAt).toISOString()}`);
                lines.push('');
            }
        }
        else {
            lines.push('*No peers discovered yet*');
        }
        return textResult(lines.join('\n'));
    });
}
//# sourceMappingURL=peer-tools.js.map