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): complete compat route and response handling

cyha5ac74e42d2f
diff --git a/tests/test_ui_server_fastapi.py b/tests/test_ui_server_fastapi.py
index 9658514fd..a77c94d08 100644
--- a/tests/test_ui_server_fastapi.py
+++ b/tests/test_ui_server_fastapi.py
@@ -1,6 +1,6 @@
import pytest
-from vibe.ui_compat import CompatApp, run_maybe_async, request
+from vibe.ui_compat import CompatApp, normalize_response, route_path_to_fastapi, run_maybe_async, request
from starlette.websockets import WebSocketDisconnect
from vibe.ui_server import app
@@ -33,6 +33,31 @@ def test_fastapi_schema_routes_are_not_exposed():
assert client.get("/openapi.json").status_code != 200
+def test_route_path_to_fastapi_converts_named_path_converter():
+ assert route_path_to_fastapi("/files/<path:file_path>") == "/files/{file_path:path}"
+
+
+def test_compat_app_matches_named_path_converter():
+ compat_app = CompatApp()
+
+ @compat_app.route("/files/<path:file_path>")
+ def get_file(file_path):
+ return {"file_path": file_path}
+
+ response = compat_app.test_client().get("/files/nested/example.txt")
+
+ assert response.status_code == 200
+ assert response.get_json() == {"file_path": "nested/example.txt"}
+
+
+def test_normalize_response_supports_body_headers_tuple():
+ response = normalize_response(("ok", {"X-Test": "yes"}))
+
+ assert response.status_code == 200
+ assert response.headers["X-Test"] == "yes"
+ assert response.body == b"ok"
+
+
def test_run_maybe_async_offloads_sync_handlers_without_losing_context():
import asyncio
import threading
diff --git a/vibe/ui_compat.py b/vibe/ui_compat.py
index 404b1905f..541c901e0 100644
--- a/vibe/ui_compat.py
+++ b/vibe/ui_compat.py
@@ -160,7 +160,7 @@ def route_path_to_regex(path: str) -> re.Pattern[str]:
def route_path_to_fastapi(path: str) -> str:
- converted = path.replace("<path:path>", "{path:path}")
+ converted = re.sub(r"<path:([A-Za-z_][A-Za-z0-9_]*)>", r"{\1:path}", path)
return re.sub(r"<([A-Za-z_][A-Za-z0-9_]*)>", r"{\1}", converted)
@@ -171,7 +171,10 @@ def normalize_response(value: Any) -> Response:
if isinstance(value, tuple):
body = value[0]
if len(value) > 1:
- status_code = int(value[1])
+ if isinstance(value[1], (dict, list, tuple)):
+ headers = dict(value[1])
+ else:
+ status_code = int(value[1])
if len(value) > 2:
headers = dict(value[2])
if isinstance(body, StarletteResponse):