82`;
83
84// --- UTILITY FUNCTIONS ---
85function extractAndParseJson<T>(text: string): T {
86 const jsonMatch = text.match(/\{[\s\S]*\}/);
87 if (!jsonMatch) {
100}
101
102async function callAgent<T>(
103 openai: OpenAI,
104 systemPrompt: string,
122
123// --- HTML & FRONTEND ---
124function generateHtml(sourceUrl: string) {
125 return `<!DOCTYPE html>
126<html lang="en">
212 };
213
214 function createPlaceholder(title) {
215 const card = document.createElement('div');
216 card.className = 'report-card visible';
222 }
223
224 function setupPlaceholders() {
225 resultsGrid.innerHTML = '';
226 finalReportContainer.innerHTML = '';
250 eventSource = new EventSource(url);
251
252 eventSource.onmessage = function(event) {
253 const { agent, data } = JSON.parse(event.data);
254 updateUI(agent, data);
255 };
256
257 eventSource.onerror = function(err) {
258 console.error("EventSource failed:", err);
259 alert('An error occurred during analysis. Check the console.');
264 });
265
266 function updateUI(agent, data) {
267 if (agent === 'done') {
268 eventSource.close();