Spaces:
Paused
Paused
feat(notes): add /api/notes/wolfram proxy route
Browse filesForwards queries to the Wolfram|Alpha LLM API with WOLFRAM_APPID kept
server-side, behind the same access check as the other notes routes.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
server.js
CHANGED
|
@@ -343,6 +343,37 @@ app.post('/api/notes/search', async (req, res) => {
|
|
| 343 |
}
|
| 344 |
});
|
| 345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
// Web Search Proxy
|
| 347 |
app.get('/api/proxy/search', async (req, res) => {
|
| 348 |
const query = req.query.q;
|
|
|
|
| 343 |
}
|
| 344 |
});
|
| 345 |
|
| 346 |
+
// Wolfram|Alpha Proxy (LLM-API) - keeps WOLFRAM_APPID server-side.
|
| 347 |
+
// Exact maths/physics/chemistry answers for the Notes agent's wolfram_alpha
|
| 348 |
+
// tool. The LLM-API returns plain text already shaped for a model.
|
| 349 |
+
app.post('/api/notes/wolfram', async (req, res) => {
|
| 350 |
+
if (!checkNotesAccess(req, res)) return;
|
| 351 |
+
|
| 352 |
+
const appId = process.env.WOLFRAM_APPID;
|
| 353 |
+
if (!appId) {
|
| 354 |
+
return res.status(500).json({ error: { message: 'WOLFRAM_APPID ist im Space nicht gesetzt' } });
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
const query = String(req.body?.query || '').trim().slice(0, 500);
|
| 358 |
+
if (!query) return res.status(400).json({ error: { message: 'query fehlt' } });
|
| 359 |
+
|
| 360 |
+
try {
|
| 361 |
+
const params = new URLSearchParams({ input: query, appid: appId, maxchars: '3000' });
|
| 362 |
+
const upstream = await fetch(`https://www.wolframalpha.com/api/v1/llm-api?${params}`, {
|
| 363 |
+
signal: AbortSignal.timeout(15000),
|
| 364 |
+
});
|
| 365 |
+
const result = (await upstream.text()).trim();
|
| 366 |
+
// 501 = Wolfram konnte die Eingabe nicht deuten; der Text erklärt warum.
|
| 367 |
+
if (!upstream.ok && upstream.status !== 501) {
|
| 368 |
+
return res.status(502).json({ error: { message: `Wolfram-Fehler ${upstream.status}` } });
|
| 369 |
+
}
|
| 370 |
+
res.json({ result: result.slice(0, 3000) });
|
| 371 |
+
} catch (error) {
|
| 372 |
+
console.error('Notes wolfram proxy error:', error);
|
| 373 |
+
res.status(502).json({ error: { message: `Wolfram nicht erreichbar: ${error.message}` } });
|
| 374 |
+
}
|
| 375 |
+
});
|
| 376 |
+
|
| 377 |
// Web Search Proxy
|
| 378 |
app.get('/api/proxy/search', async (req, res) => {
|
| 379 |
const query = req.query.q;
|