import '../shared/base.css'; import { App } from '@modelcontextprotocol/ext-apps'; interface DebateData { topic: string; format: 'oxford' | 'socratic' | 'adversarial'; totalRounds: number; participants: { provider: string; nickname: string; position: string }[]; rounds: { round: number; provider: string; nickname: string; position: string; content: string; }[][]; synthesis: string; synthesizer: string; } const formatMeta: Record = { oxford: { emoji: '\uD83C\uDF93', label: 'Oxford', style: 'oxford' }, socratic: { emoji: '\uD83C\uDFDB\uFE0F', label: 'Socratic', style: 'socratic' }, adversarial: { emoji: '\u2694\uFE0F', label: 'Adversarial', style: 'adversarial' }, }; const positionColors: Record = { pro: '#4caf50', con: '#f44336', neutral: '#9e9e9e', }; const app = new App({ name: 'DuckDebate', version: '1.0.0' }, {}); app.ontoolresult = (params) => { const container = document.getElementById('app')!; if (params.isError) { container.innerHTML = `
Tool execution failed
`; return; } const content = params.content; if (!content || !Array.isArray(content) || content.length < 2) { container.innerHTML = `
No structured data received
`; return; } try { const data: DebateData = JSON.parse((content[1] as { type: string; text: string }).text); render(data); } catch { container.innerHTML = `
Failed to parse debate data
`; } }; function render(data: DebateData) { const container = document.getElementById('app')!; const fmt = formatMeta[data.format] || formatMeta.oxford; let html = `
`; // Header html += `
`; html += `
${fmt.emoji} ${fmt.label} Debate
`; html += `

${esc(data.topic)}

`; html += `
${data.totalRounds} rounds · ${data.participants.length} participants
`; html += `
`; // Participants html += `
`; for (const p of data.participants) { const color = positionColors[p.position] || '#9e9e9e'; html += ``; html += ``; html += `${esc(p.nickname)} (${p.position})`; html += ``; } html += `
`; // Rounds html += `
`; for (let i = 0; i < data.rounds.length; i++) { const round = data.rounds[i]; html += `
`; html += `Round ${i + 1}`; html += `
`; for (const arg of round) { const color = positionColors[arg.position] || '#9e9e9e'; html += `
`; html += `
`; html += `${esc(arg.nickname)}`; html += `${arg.position.toUpperCase()}`; html += `
`; html += `
${esc(arg.content)}
`; html += `
`; } html += `
`; } html += `
`; // Synthesis html += `
`; html += `

Synthesis by ${esc(data.synthesizer)}

`; html += `
${esc(data.synthesis)}
`; html += `
`; html += `
`; container.innerHTML = html; } function esc(s: string): string { const d = document.createElement('div'); d.textContent = s; return d.innerHTML; } app.connect().catch(console.error);