Luca448 commited on
Commit
bda66bb
·
1 Parent(s): 8b186d5

Savestate: Switch Web Image Search to Wikimedia API and fix plot-override bug

Browse files
Files changed (4) hide show
  1. index.html +1 -1
  2. src/ai/router.js +1 -1
  3. src/db/database.js +13 -11
  4. src/views/chat/chat-view.js +17 -12
index.html CHANGED
@@ -74,7 +74,7 @@
74
  </head>
75
  <body class="dark-theme in-chat-view">
76
 
77
- <div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.8.234</div>
78
 
79
  <!-- SVG Filters for Liquid Glass Refraction -->
80
  <svg width="0" height="0" style="position: absolute; pointer-events: none;">
 
74
  </head>
75
  <body class="dark-theme in-chat-view">
76
 
77
+ <div id="live-version-badge" style="position: fixed; top: 50px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--text-secondary); opacity: 0.6; z-index: 99999; pointer-events: none; font-weight: 500; font-family: monospace; letter-spacing: 1px; background: rgba(0,0,0,0.2); padding: 2px 8px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.05);">BUILD 1.8.235</div>
78
 
79
  <!-- SVG Filters for Liquid Glass Refraction -->
80
  <svg width="0" height="0" style="position: absolute; pointer-events: none;">
src/ai/router.js CHANGED
@@ -130,7 +130,7 @@ Wenn nein (z.B. simple Matheaufgabe, reine Textübersetzung, unwichtiges Thema),
130
  prompt += `\n\n(WICHTIG: Vergiss nicht den Tag [BILD: ${prompt.substring(0, 50)}] im Text!)`;
131
  } else {
132
  if (onStatus) onStatus('Suche visuelles Material...');
133
- const imageInfo = `\n\n--- VISUELLE UNTERSTÜTZUNG ---\nEin passendes Diagramm zum Thema '${queryOrPrompt}' wird aus dem Internet geladen. Du MUSST zwingend exakt den Text [WEB-IMAGE: ${queryOrPrompt}] an der Stelle in deinem fließenden Antwort-Text platzieren, wo das visuelle Beispiel dem Schüler am meisten hilft (z.B. direkt nach einer Definition). \nRegel 1: Das Bild darf NICHT ganz am Anfang stehen.`;
134
  if (typeof systemInstruction === 'string') {
135
  systemInstruction += imageInfo;
136
  } else if (systemInstruction && systemInstruction.parts) {
 
130
  prompt += `\n\n(WICHTIG: Vergiss nicht den Tag [BILD: ${prompt.substring(0, 50)}] im Text!)`;
131
  } else {
132
  if (onStatus) onStatus('Suche visuelles Material...');
133
+ const imageInfo = `\n\n--- VISUELLE UNTERSTÜTZUNG ---\nEin passendes Diagramm zum Thema '${queryOrPrompt}' wird aus dem Internet geladen. Du MUSST zwingend exakt den Text [WEB-IMAGE: ${queryOrPrompt}] an der Stelle in deinem fließenden Antwort-Text platzieren, wo das visuelle Beispiel dem Schüler am meisten hilft (z.B. direkt nach einer Definition). \nRegel 1: Das Bild darf NICHT ganz am Anfang stehen.\nRegel 2: Zeichne NIEMALS einen eigenen mathematischen Graphen (\`\`\`plot) als Ersatz für diese Skizze! Der \`\`\`plot Befehl ist NUR für mathematische Funktionen (y=f(x)) gedacht, nicht für Skizzen.`;
134
  if (typeof systemInstruction === 'string') {
135
  systemInstruction += imageInfo;
136
  } else if (systemInstruction && systemInstruction.parts) {
src/db/database.js CHANGED
@@ -209,17 +209,19 @@ class Database {
209
 
210
  // Migration: Rebuild previews to new 150 character limit and clean out SiriHero tags
211
  try {
212
- const convos = this.exec("SELECT id FROM conversations");
213
- for (const row of convos) {
214
- const cid = row.id;
215
- const lastMsg = this.exec("SELECT content FROM messages WHERE conversation_id = ? ORDER BY created_at DESC LIMIT 1", [cid]);
216
- if (lastMsg.length > 0) {
217
- let cleanContent = lastMsg[0].content.replace(/!\[.*?\]\((data:image\/[^)]+)\)/g, '[Bild] ');
218
- cleanContent = cleanContent.replace(/!\[(?:SiriHero|KnowledgeCard)[^\]]*\]\([^)]*\)/gi, '');
219
- cleanContent = cleanContent.replace(/!(?:SiriHero|KnowledgeCard):[^\n]+/gi, '');
220
- cleanContent = cleanContent.replace(/[*_#`\[\]]/g, '').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
221
- const preview = cleanContent.length > 150 ? cleanContent.substring(0, 150) + '...' : cleanContent;
222
- this.exec("UPDATE conversations SET preview = ? WHERE id = ?", [preview, cid]);
 
 
223
  }
224
  }
225
  } catch(e) { console.error('Preview Migration failed', e); }
 
209
 
210
  // Migration: Rebuild previews to new 150 character limit and clean out SiriHero tags
211
  try {
212
+ if (this.isReady) {
213
+ const convos = this.exec("SELECT id FROM conversations");
214
+ for (const row of convos) {
215
+ const cid = row.id;
216
+ const lastMsg = this.exec("SELECT content FROM messages WHERE conversation_id = ? ORDER BY created_at DESC LIMIT 1", [cid]);
217
+ if (lastMsg.length > 0) {
218
+ let cleanContent = lastMsg[0].content.replace(/!\[.*?\]\((data:image\/[^)]+)\)/g, '[Bild] ');
219
+ cleanContent = cleanContent.replace(/!\[(?:SiriHero|KnowledgeCard)[^\]]*\]\([^)]*\)/gi, '');
220
+ cleanContent = cleanContent.replace(/!(?:SiriHero|KnowledgeCard):[^\n]+/gi, '');
221
+ cleanContent = cleanContent.replace(/[*_#`\[\]]/g, '').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
222
+ const preview = cleanContent.length > 150 ? cleanContent.substring(0, 150) + '...' : cleanContent;
223
+ this.exec("UPDATE conversations SET preview = ? WHERE id = ?", [preview, cid]);
224
+ }
225
  }
226
  }
227
  } catch(e) { console.error('Preview Migration failed', e); }
src/views/chat/chat-view.js CHANGED
@@ -4500,23 +4500,28 @@ body { margin: 0; padding: 0; background: #000; overflow: hidden; display: flex;
4500
  img.classList.add('processed');
4501
  const query = img.getAttribute('data-query');
4502
  try {
4503
- const response = await fetch('/api/search-image?q=' + encodeURIComponent(query));
4504
  if (response.ok) {
4505
  const data = await response.json();
4506
- if (data.imageUrl) {
4507
- img.src = data.imageUrl;
4508
-
4509
- // Show source link
4510
- const sourceLink = img.parentElement.querySelector('.source-link');
4511
- if (sourceLink) {
4512
- sourceLink.href = data.sourceLink;
4513
- sourceLink.style.display = 'block';
 
 
 
 
 
 
4514
  }
4515
  }
4516
- } else {
4517
- console.warn("Web Image API returned error", response.status);
4518
- img.parentElement.style.display = 'none';
4519
  }
 
 
4520
  } catch (e) {
4521
  console.error("Web Image processing failed", e);
4522
  img.parentElement.style.display = 'none';
 
4500
  img.classList.add('processed');
4501
  const query = img.getAttribute('data-query');
4502
  try {
4503
+ const response = await fetch(`https://de.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=${encodeURIComponent(query)}&gsrlimit=1&prop=pageimages&format=json&pithumbsize=1000&origin=*`);
4504
  if (response.ok) {
4505
  const data = await response.json();
4506
+ if (data.query && data.query.pages) {
4507
+ const pageId = Object.keys(data.query.pages)[0];
4508
+ const page = data.query.pages[pageId];
4509
+ if (page.thumbnail && page.thumbnail.source) {
4510
+ img.src = page.thumbnail.source;
4511
+
4512
+ const sourceLink = img.parentElement.querySelector('.source-link');
4513
+ if (sourceLink) {
4514
+ sourceLink.href = `https://de.wikipedia.org/wiki/${encodeURIComponent(page.title.replace(/ /g, '_'))}`;
4515
+ sourceLink.innerHTML = '<i data-lucide="external-link"></i> Quelle: Wikipedia';
4516
+ sourceLink.style.display = 'block';
4517
+ lucide.createIcons();
4518
+ }
4519
+ continue;
4520
  }
4521
  }
 
 
 
4522
  }
4523
+ console.warn("Web Image API returned no image");
4524
+ img.parentElement.style.display = 'none';
4525
  } catch (e) {
4526
  console.error("Web Image processing failed", e);
4527
  img.parentElement.style.display = 'none';