From 87602f7887284eadee80c00e3e4aa02fa0dee148 Mon Sep 17 00:00:00 2001 From: Dorian Date: Sat, 7 Mar 2026 23:22:30 +0000 Subject: [PATCH] fix: add max_tokens default and mock web-search endpoint for demo - Inject max_tokens: 4096 in Claude API proxy when AIUI omits it - Add /aiui/api/web-search stub returning empty results (no search backend in demo) - Add nginx proxy rule for web-search endpoint Co-Authored-By: Claude Opus 4.6 --- neode-ui/docker/nginx-demo.conf | 8 ++++++++ neode-ui/mock-backend.js | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/neode-ui/docker/nginx-demo.conf b/neode-ui/docker/nginx-demo.conf index 4381040d..2c918631 100644 --- a/neode-ui/docker/nginx-demo.conf +++ b/neode-ui/docker/nginx-demo.conf @@ -78,6 +78,14 @@ http { } } + # Proxy AIUI API requests (web-search, claude) to backend + location /aiui/api/web-search { + proxy_pass http://neode-backend:5959; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + # Proxy Claude API requests to backend (which handles API key + streaming) location /aiui/api/claude/ { proxy_pass http://neode-backend:5959; diff --git a/neode-ui/mock-backend.js b/neode-ui/mock-backend.js index 4340e12d..8e560485 100755 --- a/neode-ui/mock-backend.js +++ b/neode-ui/mock-backend.js @@ -1017,6 +1017,12 @@ app.get('/app/filebrowser/api/raw/*', (req, res) => { }) // ============================================================================= +// AIUI Web Search stub (demo mode — no real search backend) +// ============================================================================= +app.get('/aiui/api/web-search', (req, res) => { + res.json({ results: [] }) +}) + // Claude API Proxy (reads ANTHROPIC_API_KEY from environment) // ============================================================================= import https from 'https' @@ -1031,7 +1037,14 @@ app.post('/aiui/api/claude/*', (req, res) => { } const apiPath = '/' + req.params[0] - const bodyStr = JSON.stringify(req.body) + + // Ensure max_tokens is set — Claude API requires it but AIUI may omit it + const body = req.body + if (body && !body.max_tokens) { + body.max_tokens = 4096 + } + + const bodyStr = JSON.stringify(body) const options = { hostname: 'api.anthropic.com', @@ -1098,7 +1111,7 @@ wss.on('connection', (ws, req) => { const heartbeatInterval = setInterval(() => { if (ws.readyState === 1) { try { - ws.send(JSON.stringify({ rev: Date.now(), patch: [] })) + ws.send(JSON.stringify({ type: 'heartbeat', rev: Date.now() })) } catch { /* ignore */ } } }, 45000) // Every 45s (client expects data within 60s)