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(show): register public dep sibling chunks

cyhb2d103e3143e
diff --git a/tests/test_ui_show_pages.py b/tests/test_ui_show_pages.py
index c6af1e84a..275dc1fc7 100644
--- a/tests/test_ui_show_pages.py
+++ b/tests/test_ui_show_pages.py
@@ -381,6 +381,42 @@ def test_show_runtime_public_dep_proxy_is_cacheable(monkeypatch, tmp_path):
assert manager.calls[-1][1] == "/sessions/ses123/app/node_modules/.vite/deps/react.js?v=d6d38251"
+def test_show_runtime_public_dep_proxy_registers_sibling_chunks(monkeypatch, tmp_path):
+ monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
+ _save_config(tmp_path)
+ _create_show_page("ses123", "private")
+ manager = _FakeShowRuntimeManager(
+ body=b'import "./chunk-OUYO74D4.js?v=108951fb";\nexport default {}',
+ extra_headers={
+ "content-type": "text/javascript",
+ "cache-control": "no-cache",
+ },
+ )
+ set_show_runtime_manager_for_tests(manager)
+ try:
+ original = app.test_client().get(
+ "/show/ses123/node_modules/.vite/deps/react-dom_client.js?v=d6d38251",
+ base_url="http://127.0.0.1:5123",
+ )
+ dep = app.test_client().get(
+ "/_show-runtime/deps/d6d38251/react-dom_client.js?v=d6d38251",
+ base_url="http://127.0.0.1:5123",
+ )
+ chunk = app.test_client().get(
+ "/_show-runtime/deps/d6d38251/chunk-OUYO74D4.js?v=108951fb",
+ base_url="http://127.0.0.1:5123",
+ )
+ finally:
+ set_show_runtime_manager_for_tests(None)
+
+ assert original.status_code == 302
+ assert dep.status_code == 200
+ assert b'import "./chunk-OUYO74D4.js?v=108951fb"' in dep.content
+ assert chunk.status_code == 200
+ assert chunk.headers["cache-control"] == "public, max-age=31536000, immutable"
+ assert manager.calls[-1][1] == "/sessions/ses123/app/node_modules/.vite/deps/chunk-OUYO74D4.js?v=108951fb"
+
+
def test_show_runtime_relocated_vendor_deps_are_cacheable(monkeypatch, tmp_path):
monkeypatch.setenv("VIBE_REMOTE_HOME", str(tmp_path))
_save_config(tmp_path)
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 4e97ae828..934cab70a 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -88,6 +88,9 @@ _SHOW_RUNTIME_IMMUTABLE_CACHE_CONTROL = "public, max-age=31536000, immutable"
_SHOW_RUNTIME_PUBLIC_DEP_RE = re.compile(
r"(?P<quote>['\"])(?P<path>(?:\.?/)?(?:node_modules/)?\.vite/deps/[^'\"?#]+)(?:\?v=(?P<version>[A-Za-z0-9_-]+))?(?P<rest>[^'\"]*)(?P=quote)"
)
+_SHOW_RUNTIME_PUBLIC_DEP_SIBLING_RE = re.compile(
+ r"(?P<quote>['\"])\./(?P<name>[A-Za-z0-9_.-]+\.js)(?:\?v=(?P<version>[A-Za-z0-9_-]+))?(?P<rest>[^'\"]*)(?P=quote)"
+)
_SHOW_RUNTIME_PUBLIC_DEP_PREFIX = "/_show-runtime/deps"
_SHOW_RUNTIME_PUBLIC_DEP_REGISTRY: dict[tuple[str, str], str] = {}
@@ -5434,6 +5437,7 @@ async def show_runtime_public_dep(version: str, asset_name: str):
_remove_response_header(response_headers, "cache-control")
_remove_response_header(response_headers, "set-cookie")
response_headers["Cache-Control"] = _SHOW_RUNTIME_IMMUTABLE_CACHE_CONTROL
+ _register_public_show_runtime_dep_siblings(proxied.content, response_headers, version=version, runtime_path=runtime_path)
return FastAPIResponse(content=proxied.content, status_code=proxied.status_code, headers=response_headers)
@@ -5598,6 +5602,29 @@ def _rewrite_show_runtime_public_deps(content: bytes, headers: dict[str, str], *
return rewritten.encode("utf-8")
+def _register_public_show_runtime_dep_siblings(
+ content: bytes,
+ headers: dict[str, str],
+ *,
+ version: str,
+ runtime_path: str,
+) -> None:
+ content_type = _response_header(headers, "content-type") or ""
+ if not _show_response_is_javascript(content_type):
+ return
+ try:
+ text = content.decode("utf-8")
+ except UnicodeDecodeError:
+ return
+ base_runtime_path = runtime_path.split("?", 1)[0].rsplit("/", 1)[0]
+ for match in _SHOW_RUNTIME_PUBLIC_DEP_SIBLING_RE.finditer(text):
+ sibling_name = match.group("name")
+ _SHOW_RUNTIME_PUBLIC_DEP_REGISTRY.setdefault(
+ (version or "unversioned", sibling_name),
+ f"{base_runtime_path}/{quote(sibling_name, safe='')}",
+ )
+
+
def _show_response_is_javascript(content_type: str | None) -> bool:
if not content_type:
return False