Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(ui_server): /agents serves SPA for browser, JSON for API

cyh715c6cf0b23f
diff --git a/ui/src/lib/apiFetch.ts b/ui/src/lib/apiFetch.ts
index a30f36812..33e9ac8e2 100644
--- a/ui/src/lib/apiFetch.ts
+++ b/ui/src/lib/apiFetch.ts
@@ -51,13 +51,20 @@ export async function ensureCsrfToken(): Promise<string> {
export async function apiFetch(input: RequestInfo | URL, init: RequestInit = {}): Promise<Response> {
const method = (init.method || 'GET').toUpperCase();
const nextInit: RequestInit = { ...init };
+ const headers = new Headers(init.headers || {});
+
+ // Be explicit about wanting JSON so endpoints that double as SPA
+ // mountpoints (e.g. /agents) keep returning JSON for programmatic
+ // callers regardless of how the runtime guesses the default Accept.
+ if (!headers.has('Accept')) {
+ headers.set('Accept', 'application/json');
+ }
if (MUTATING_METHODS.has(method)) {
const token = await ensureCsrfToken();
- const headers = new Headers(init.headers || {});
headers.set(CSRF_HEADER_NAME, token);
- nextInit.headers = headers;
}
+ nextInit.headers = headers;
return fetch(input, nextInit);
}
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index f049f712d..ca9a5334b 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -1318,6 +1318,21 @@ def _vibe_agent_result_response(result: dict):
def vibe_agents_get():
from vibe import api
+ # /agents collides between the JSON API and the SPA route at the same
+ # URL. Browser navigation (Accept: text/html,...) should land on the
+ # React Agents page; programmatic fetches stay on the JSON payload.
+ # CompatRequest doesn't expose Werkzeug's `accept_mimetypes`, so read
+ # the raw header. Treat a request as browser-shaped when text/html
+ # appears before application/json (the canonical browser order).
+ accept = (request.headers.get("Accept") or "").lower()
+ if "text/html" in accept and "application/json" not in accept.split("text/html", 1)[0]:
+ from pathlib import Path
+
+ ui_dist = get_ui_dist_path()
+ index_path = Path(ui_dist) / "index.html"
+ if index_path.exists():
+ return send_file(index_path, mimetype="text/html")
+
try:
include_disabled = str(request.args.get("include_disabled") or request.args.get("all") or "").lower() in {
"1",