Farhan Beg commited on
Commit ·
ff3dadd
1
Parent(s): 8da84d4
fix(router): explicit 404 for legacy /api/sessions/<id>/chat/stream
Browse filesThe hermes-workspace capability probe POSTs to that path to detect the
legacy enhanced-fork chat surface. With no rule it fell through to
WebUI, which didn't 404 it cleanly, so the probe set enhancedChat=true,
the workspace then sent chat there at runtime, and the UI showed a
generic 'Authentication error' instead of using /v1/chat/completions.
Returning an explicit 404 makes the workspace's chatMode resolve to
'portable' and route chat through the OpenAI-compat path the Space
actually exposes.
869 unmodified lines870871872873874875869 unmodified lines// 6c. /api/* routes — these are WebUI API calls when Referer isn't the// dashboard. Fall through to the catch-all below.// 7. Anything else -> Hermes WebUI (primary UI) OR HuggingMes status page.// WebUI handles its own auth internally via HERMES_WEBUI_PASSWORD.869 unmodified lines870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905869 unmodified lines// 6c. /api/* routes — these are WebUI API calls when Referer isn't the// dashboard. Fall through to the catch-all below.//// Exception: hermes-workspace probes for the *legacy* enhanced-fork chat// endpoint at POST /api/sessions/<id>/chat/stream. Without this rule the// request falls through to WebUI's catch-all, which doesn't 404 it// cleanly, so the workspace's detector sets `enhancedChat=true`, sends// chat there at runtime, and the UI surfaces a generic "Authentication// error". Returning an explicit 404 here makes the workspace fall back// to the OpenAI-compatible /v1/chat/completions path on the gateway —// which is the only chat surface this Space actually exposes.//// Anything the dashboard or WebUI legitimately need under /api/sessions/// already has a more specific match above (referer check / /hmd// passthrough), so this only fires for cross-origin probes.if (/^\/api\/sessions\/[^/]+\/chat\/stream\/?$/.test(path) &&!refererIsDashboard) {res.writeHead(404, {"content-type": "application/json","cache-control": "no-store",});res.end(JSON.stringify({error: "not_found",message:"Legacy enhanced-fork chat stream is not exposed by this Space. Use /v1/chat/completions.",}),);return;}// 7. Anything else -> Hermes WebUI (primary UI) OR HuggingMes status page.// WebUI handles its own auth internally via HERMES_WEBUI_PASSWORD.
health-server.js+30