import { db } from "../../db/database.js"; import { aiRouter } from "../../ai/router.js"; import { marked } from "marked"; import { PresentationRenderer } from "../../utils/presentation-renderer.js"; import { deepResearchLoader } from "../../utils/deep-research-loader.js"; import { presentationLoader } from "../../utils/presentation-loader.js"; import { getApiUrl } from "../../config.js"; import { syncManager } from "../../services/sync-service.js"; import schoolmindSimSource from "../../../public/schoolmind-sim.js?raw"; import { initCanvas, addNode, addEdge } from "../../ai/research-canvas.js"; import { initImageEditor } from "./image-editor.js"; window.youtubeSearchCache = window.youtubeSearchCache || {}; try { if (document.readyState === "complete" || document.readyState === "interactive") { initImageEditor(); } else { document.addEventListener("DOMContentLoaded", initImageEditor); } } catch (e) { console.error("Failed to init image editor", e); } function formatImageGeneration(prompt) { const encodedPrompt = encodeURIComponent(prompt.trim()); return `
${prompt.replace(/
`.trim(); } function formatYoutubeSearch(query) { const cachedId = window.youtubeSearchCache[query]; if (cachedId) { if (cachedId === "NOT_FOUND") { return `
Kein Video gefunden f\xFCr "${query}"
`; } return `
Suchergebnis f\xFCr: "${query}"
`; } if (!window.youtubeSearchCache.hasOwnProperty(query)) { window.youtubeSearchCache[query] = null; fetch(getApiUrl(`/api/youtube-search?q=${encodeURIComponent(query)}&json=1`)).then((res) => res.json()).then((data) => { window.youtubeSearchCache[query] = data.videoId || "NOT_FOUND"; document.dispatchEvent(new CustomEvent("youtube-search-resolved")); }).catch(() => { window.youtubeSearchCache[query] = "NOT_FOUND"; document.dispatchEvent(new CustomEvent("youtube-search-resolved")); }); } return `
Suche Video: "${query}"...
`; } function formatWorksheetInpainting(jsonStr) { const safeJson = jsonStr.replace(/"/g, """).replace(/\n/g, " "); return `
FLUX.1 Inpainting aktiv...
`; } document.addEventListener("youtube-search-resolved", () => { document.querySelectorAll(".yt-loading-placeholder").forEach((el) => { const encodedQuery = el.getAttribute("data-query"); if (!encodedQuery) return; const query = decodeURIComponent(encodedQuery); const cachedId = window.youtubeSearchCache[query]; if (cachedId) { if (cachedId === "NOT_FOUND") { el.outerHTML = `
Kein Video gefunden f\xFCr "${query}"
`; } else { el.outerHTML = `
Suchergebnis f\xFCr: "${query}"
`; } } }); }); const renderer = new marked.Renderer(); const originalImage = renderer.image.bind(renderer); renderer.image = (href, title, text) => { let h = href, t = title, tx = text; if (typeof href === "object" && href !== null) { h = href.href; t = href.title; tx = href.text; } if (tx && (tx.startsWith("KnowledgeCard:") || tx.startsWith("SiriHero:"))) { const isSiriHero = tx.startsWith("SiriHero:"); let rawTitle = tx.replace(/KnowledgeCard:|SiriHero:/, "").trim().replace(/_/g, " "); let parts = rawTitle.split("|"); let cardTitle = parts[0].trim(); let keywords = parts.length > 1 ? parts[1].trim() : ""; const forbiddenMathKeywords = ["koordinatensystem", "gleichung", "funktion", "graph", "wurzel", "mathematik", "rechnung", "vektor", "polynom", "ableitung"]; if (forbiddenMathKeywords.some((kw) => cardTitle.toLowerCase().includes(kw))) { return ""; } if (isSiriHero) { const titleParts = cardTitle.split(" "); if (titleParts.length > 1) { cardTitle = titleParts[0] + "
" + titleParts.slice(1).join(" "); } const imgTag = h === "WIKIPEDIA" ? `${cardTitle}` : `${cardTitle}`; return `
${cardTitle}
${imgTag}
`; } return `
${cardTitle}
${cardTitle}
KI-Wissen
`; } return typeof href === "object" ? originalImage(href) : originalImage(h, t, tx); }; const originalCode = renderer.code.bind(renderer); renderer.code = function(code, language, isEscaped) { let c = code, l = language, e = isEscaped; if (typeof code === "object" && code !== null) { c = code.text; l = code.lang; e = code.escaped; } if (l === "plot") { const encodedData = encodeURIComponent(c); return `
`; } if (l === "plot3d") { const encodedData = encodeURIComponent(c); return `
`; } if (l === "mermaid") { return `
${c}
`; } if (l === "app") { const injectedScript = `