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.

feat(ui): Show Page toggle in the chat header

cyh96e1a9dad127
diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsx
index 00ad1f9f3..857f393f7 100644
--- a/ui/src/components/workbench/ChatPage.tsx
+++ b/ui/src/components/workbench/ChatPage.tsx
@@ -1,7 +1,7 @@
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
-import { ArrowLeft, Bell, Bot, ChevronDown, Clock, Info, Loader2, MessageSquare, Pencil, UploadCloud, X } from 'lucide-react';
+import { AppWindow, ArrowLeft, Bell, Bot, ChevronDown, Clock, Info, Loader2, MessageSquare, Pencil, UploadCloud, X } from 'lucide-react';
import clsx from 'clsx';
import { useApi } from '../../context/ApiContext';
@@ -123,6 +123,15 @@ export const ChatPage: React.FC = () => {
);
useRegisterComposerTarget(composerTarget);
+ // Show Page toggle: swap the chat surface (transcript + composer, NOT the
+ // header bar) for this session's Show Page in an iframe, and back. Resets to
+ // chat view on session change so a freshly-opened chat starts in chat mode.
+ const [showPageMode, setShowPageMode] = useState(false);
+ const [showPageBusy, setShowPageBusy] = useState(false);
+ useEffect(() => {
+ setShowPageMode(false);
+ }, [sessionId]);
+
// Back returns to the page the user came from, not a hardcoded inbox.
// location.key === 'default' means /chat was the first history entry (deep
// link / refresh) with nothing to pop back to — fall back to the inbox then.
@@ -721,6 +730,29 @@ export const ChatPage: React.FC = () => {
[api, sessionId],
);
+ // Toggle the chat surface ↔ the session's Show Page (iframe). The first open
+ // 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;
+ 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.');
+ }
+ setShowPageMode(true);
+ } catch {
+ // apiFetch already surfaced a toast; stay in chat view.
+ } finally {
+ setShowPageBusy(false);
+ }
+ }, [sessionId, showPageMode, api, sendMessage]);
+
// A quick-reply click sends the chosen label as a normal user turn, tagged with
// the agent message it answers so the group can lock + highlight the choice on
// reload (the answered state is derived from this metadata).
@@ -972,39 +1004,54 @@ export const ChatPage: React.FC = () => {
onPatch={patch}
onBack={goBack}
working={working}
+ showPageMode={showPageMode}
+ showPageBusy={showPageBusy}
+ onToggleShowPage={toggleShowPage}
/>
- {error && (
- <div className="mx-auto mt-3 w-full max-w-[1080px] rounded-md border border-destructive/40 bg-destructive/[0.06] px-3 py-2 text-[12px] text-destructive">
- {error}
- </div>
- )}
+ {showPageMode && sessionId ? (
+ // The session's Show Page replaces the transcript + composer (the header
+ // bar stays). Same-origin /show/<id>/ inherits the workbench's auth.
+ <iframe
+ title={t('chat.showPage.title')}
+ src={`/show/${encodeURIComponent(sessionId)}/`}
+ className="min-h-0 w-full flex-1 border-0 bg-background"
+ />
+ ) : (
+ <>
+ {error && (
+ <div className="mx-auto mt-3 w-full max-w-[1080px] rounded-md border border-destructive/40 bg-destructive/[0.06] px-3 py-2 text-[12px] text-destructive">
+ {error}
+ </div>
+ )}
- <Transcript
- messages={messages}
- session={session}
- working={working}
- hasOlder={!!olderCursor}
- loadingOlder={loadingOlder}
- onLoadOlder={loadOlderMessages}
- messageFontSize={messageFontSize}
- onQuickReply={handleQuickReply}
- />
- <QueueStrip queue={queue} onRemove={removeQueued} onSendNow={sendQueueNow} />
- {/* key by session so the composer remounts per session — its draft-seeding
- + local value reset, instead of carrying across sessions (Codex P2). */}
- <Compose
- key={sessionId}
- composerRef={composerRef}
- onSend={(text, attachments, references) => sendMessage(text, attachments, undefined, references)}
- onStop={stopMessage}
- busy={working}
- sessionId={sessionId ?? ''}
- initialDraft={initialDraft}
- onDraftChange={onDraftChange}
- onSearchAgents={searchAgents}
- onSearchSessions={searchSessions}
- />
+ <Transcript
+ messages={messages}
+ session={session}
+ working={working}
+ hasOlder={!!olderCursor}
+ loadingOlder={loadingOlder}
+ onLoadOlder={loadOlderMessages}
+ messageFontSize={messageFontSize}
+ onQuickReply={handleQuickReply}
+ />
+ <QueueStrip queue={queue} onRemove={removeQueued} onSendNow={sendQueueNow} />
+ {/* key by session so the composer remounts per session — its draft-seeding
+ + local value reset, instead of carrying across sessions (Codex P2). */}
+ <Compose
+ key={sessionId}
+ composerRef={composerRef}
+ onSend={(text, attachments, references) => sendMessage(text, attachments, undefined, references)}
+ onStop={stopMessage}
+ busy={working}
+ sessionId={sessionId ?? ''}
+ initialDraft={initialDraft}
+ onDraftChange={onDraftChange}
+ onSearchAgents={searchAgents}
+ onSearchSessions={searchSessions}
+ />
+ </>
+ )}
</div>
</FileViewerProvider>
</ImageViewerProvider>
@@ -1098,9 +1145,12 @@ interface ChatHeaderBarProps {
onPatch: (changes: Partial<WorkbenchSession>) => Promise<void>;
onBack: () => void;
working: boolean;
+ showPageMode: boolean;
+ showPageBusy: boolean;
+ onToggleShowPage: () => void;
}
-const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, defaultAgentName, onPatch, onBack, working }) => {
+const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, defaultAgentName, onPatch, onBack, working, showPageMode, showPageBusy, onToggleShowPage }) => {
const { t } = useTranslation();
const defaultAgent = defaultAgentName ? agents.find((agent) => agent.name === defaultAgentName) : null;
// Backend locks once a NATIVE conversation exists — a native can only be
@@ -1171,6 +1221,27 @@ const ChatHeaderBar: React.FC<ChatHeaderBarProps> = ({ session, agents, defaultA
IM-launched users often land straight in a chat. Renders only on iOS
Safari + not-installed; null otherwise. */}
<InstallHint />
+ {/* Show Page toggle: swaps the chat surface for the session's Show Page
+ (the header bar stays). First open initializes the page + prompts the
+ agent. Pushed to the far right of the header row. */}
+ <Button
+ type="button"
+ variant={showPageMode ? 'secondary' : 'ghost'}
+ size="icon"
+ onClick={onToggleShowPage}
+ disabled={showPageBusy}
+ aria-label={showPageMode ? t('chat.showPage.backToChat') : t('chat.showPage.open')}
+ title={showPageMode ? t('chat.showPage.backToChat') : t('chat.showPage.open')}
+ className="ml-auto size-7 shrink-0"
+ >
+ {showPageBusy ? (
+ <Loader2 className="size-3.5 animate-spin" />
+ ) : showPageMode ? (
+ <MessageSquare className="size-3.5" />
+ ) : (
+ <AppWindow className="size-3.5" />
+ )}
+ </Button>
</div>
</div>
);
diff --git a/ui/src/context/ApiContext.tsx b/ui/src/context/ApiContext.tsx
index 4b6f5436e..b6efa0b57 100644
--- a/ui/src/context/ApiContext.tsx
+++ b/ui/src/context/ApiContext.tsx
@@ -38,6 +38,8 @@ export type ApiContextType = {
unsubscribeWebPush: (endpoint: string) => Promise<{ ok: boolean; disabled: boolean }>;
sendWebPushTest: (payload?: { title?: string; body?: string; url?: string; endpoint?: string }) => Promise<WebPushTestResult>;
setShowPageVisibility: (sessionId: string, visibility: string) => Promise<any>;
+ /** Create the session's Show Page if absent; resolves to `{ existed, ... }`. */
+ ensureShowPage: (sessionId: string) => Promise<any>;
rotateShowPageShare: (sessionId: string) => Promise<any>;
getBindCodes: () => Promise<any>;
createBindCode: (type: string, expiresAt?: string) => Promise<any>;
@@ -1513,6 +1515,7 @@ export const ApiProvider: React.FC<{ children: React.ReactNode }> = ({ children
unsubscribeWebPush: (endpoint) => deleteJson('/api/web-push/subscriptions', { endpoint }),
sendWebPushTest: (payload) => postJson('/api/web-push/test', payload ?? {}),
setShowPageVisibility: (sessionId, visibility) => postJson(`/api/show-pages/${encodeURIComponent(sessionId)}/visibility`, { visibility }),
+ ensureShowPage: (sessionId) => postJson(`/api/show-pages/${encodeURIComponent(sessionId)}/ensure`, {}),
rotateShowPageShare: (sessionId) => postJson(`/api/show-pages/${encodeURIComponent(sessionId)}/rotate-share`, {}),
getBindCodes: () => getJson('/api/bind-codes'),
createBindCode: (type, expiresAt) => postJson('/api/bind-codes', { type, expires_at: expiresAt }),
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index dcd7263fc..30c3e12a0 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -1755,6 +1755,11 @@
"chat": {
"back": "Back",
"untitled": "Untitled session",
+ "showPage": {
+ "open": "View Show Page",
+ "backToChat": "Back to chat",
+ "title": "Show Page"
+ },
"titlePlaceholder": "Session title",
"pickAgent": "Pick an agent",
"noAgents": "No enabled agents. Create one on the Agents page.",
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 121ed8210..decce4147 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -1754,6 +1754,11 @@
"chat": {
"back": "返回",
"untitled": "未命名会话",
+ "showPage": {
+ "open": "查看 Show Page",
+ "backToChat": "返回对话",
+ "title": "Show Page"
+ },
"titlePlaceholder": "会话标题",
"pickAgent": "选择 Agent",
"noAgents": "暂无已启用的 Agent。请先在 Agents 页创建。",
diff --git a/vibe/api.py b/vibe/api.py
index 33e65bf8e..21fa160a4 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -1001,6 +1001,26 @@ def set_show_page_visibility(session_id: str, visibility: str) -> dict:
return {"ok": True, **_apply_session_meta([payload])[0]}
+def ensure_show_page(session_id: str) -> dict:
+ """Create the session's Show Page if it doesn't exist yet; report which.
+
+ ``existed`` tells the caller whether the page was already initialized, so the
+ 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
+
+ config = V2Config.load()
+ store = ShowPageStore()
+ try:
+ existed = store.get(session_id) is not None
+ page = store.ensure(session_id)
+ payload = show_page_payload(page, config=config)
+ finally:
+ store.close()
+ return {"ok": True, "existed": existed, **_apply_session_meta([payload])[0]}
+
+
def rotate_show_page_share(session_id: str) -> dict:
"""Revoke the current public link and issue a new one (public pages only)."""
from core.show_pages import ShowPageStore, show_page_payload
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 3b6298ea0..591323be9 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -2298,6 +2298,17 @@ def show_page_visibility_post(session_id):
return _show_page_error_response(exc)
[email protected]("/api/show-pages/<session_id>/ensure", methods=["POST"])
+def show_page_ensure_post(session_id):
+ from core.show_pages import ShowPageError
+ from vibe import api
+
+ try:
+ return jsonify(api.ensure_show_page(session_id))
+ except ShowPageError as exc:
+ return _show_page_error_response(exc)
+
+
@app.route("/api/show-pages/<session_id>/rotate-share", methods=["POST"])
def show_page_rotate_share_post(session_id):
from core.show_pages import ShowPageError