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): Show Page toggle — framing, archived guard, public route, stale toggle

cyhc602e253fd50
diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsx
index 857f393f7..cf43139cd 100644
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@ -128,8 +128,10 @@ export const ChatPage: React.FC = () => {
// chat view on session change so a freshly-opened chat starts in chat mode.
const [showPageMode, setShowPageMode] = useState(false);
const [showPageBusy, setShowPageBusy] = useState(false);
+ const [showPageUrl, setShowPageUrl] = useState<string | null>(null);
useEffect(() => {
setShowPageMode(false);
+ setShowPageUrl(null);
}, [sessionId]);
// Back returns to the page the user came from, not a hardcoded inbox.
@@ -734,22 +736,35 @@ export const ChatPage: React.FC = () => {
// ensures the page exists; if it was just created, ask the agent to build the
// visualization. Errors surface via the apiFetch toast layer.
const toggleShowPage = useCallback(async () => {
- if (!sessionId) return;
+ const sid = sessionId;
+ if (!sid) return;
if (showPageMode) {
setShowPageMode(false);
return;
}
setShowPageBusy(true);
try {
- const res = await api.ensureShowPage(sessionId);
- if (res?.ok && res.existed === false) {
- void sendMessage('Please visualize this session as a Show Page.');
+ const res = await api.ensureShowPage(sid);
+ // Bail if the user switched chats while ensure was in flight — otherwise a
+ // stale resolve would flip the NEW chat into iframe mode + send its prompt.
+ if (sessionIdRef.current !== sid) return;
+ if (res?.ok) {
+ // Public pages are served under /p/<share_id>/; private under /show/<id>/.
+ setShowPageUrl(
+ res.visibility === 'public' && res.share_id
+ ? `/p/${encodeURIComponent(res.share_id)}/`
+ : `/show/${encodeURIComponent(sid)}/`,
+ );
+ // Only a freshly-created page needs the agent to build the visualization.
+ if (res.existed === false) {
+ void sendMessage('Please visualize this session as a Show Page.');
+ }
+ setShowPageMode(true);
}
- setShowPageMode(true);
} catch {
// apiFetch already surfaced a toast; stay in chat view.
} finally {
- setShowPageBusy(false);
+ if (sessionIdRef.current === sid) setShowPageBusy(false);
}
}, [sessionId, showPageMode, api, sendMessage]);
@@ -1009,12 +1024,13 @@ export const ChatPage: React.FC = () => {
onToggleShowPage={toggleShowPage}
/>
- {showPageMode && sessionId ? (
+ {showPageMode && showPageUrl ? (
// The session's Show Page replaces the transcript + composer (the header
- // bar stays). Same-origin /show/<id>/ inherits the workbench's auth.
+ // bar stays). Same-origin (/show/<id>/ private or /p/<share>/ public) so
+ // it inherits the workbench's auth; URL is resolved from ensureShowPage.
<iframe
title={t('chat.showPage.title')}
- src={`/show/${encodeURIComponent(sessionId)}/`}
+ src={showPageUrl}
className="min-h-0 w-full flex-1 border-0 bg-background"
/>
) : (
diff --git a/vibe/api.py b/vibe/api.py
index 21fa160a4..16e9835cc 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -1008,12 +1008,21 @@ def ensure_show_page(session_id: str) -> dict:
workbench can ALSO send the "visualize this session" prompt only on first
creation. Mirrors the CLI ``vibe show path`` (ensure + return).
"""
- from core.show_pages import ShowPageStore, show_page_payload
+ from core.show_pages import ShowPageError, ShowPageStore, show_page_payload
config = V2Config.load()
store = ShowPageStore()
try:
existed = store.get(session_id) is not None
+ # Don't materialize a fresh page row for an archived (terminal) session —
+ # /show/<id>/ serves private pages without re-checking archived state, so
+ # creating one would resurrect it. Mirrors update_visibility's guard. An
+ # already-existing page is returned as-is (archive took it offline).
+ if not existed and store._is_archived(session_id):
+ raise ShowPageError(
+ "Cannot create a Show Page for an archived session.",
+ code="session_archived",
+ )
page = store.ensure(session_id)
payload = show_page_payload(page, config=config)
finally:
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 591323be9..d900f1e5e 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -6698,7 +6698,11 @@ def _rewrite_show_runtime_location(session_id: str, location: str, *, external_p
def _with_show_event_write_cookie(response: Response, session_id: str, *, enabled: bool) -> Response:
if enabled:
- response.headers["Content-Security-Policy"] = "frame-ancestors 'none'"
+ # 'self' (not 'none') so the workbench can frame a private Show Page in the
+ # chat view — same origin as the page — while cross-origin clickjacking
+ # stays blocked. Direct navigation is unaffected (frame-ancestors only
+ # governs framing).
+ response.headers["Content-Security-Policy"] = "frame-ancestors 'self'"
response.set_cookie(
SHOW_EVENT_WRITE_TOKEN_COOKIE,
show_event_write_token(session_id),