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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(show-pages): preserve authorization recovery states
Maxd314024569f0
diff --git a/ui/eslint-baseline.json b/ui/eslint-baseline.jsonindex 35666b912..a8695b048 100644--- a/ui/eslint-baseline.json+++ b/ui/eslint-baseline.json@@ -4,7 +4,7 @@"@typescript-eslint/no-explicit-any": "The untyped edge of the Python API. Each one is a response body, an SSE event payload or a third-party callback that reaches the UI as `any`. Typing them is a per-endpoint contract change against the backend, not a lint fix, and doing it as one sweep would produce a diff nobody can review. The ratchet's job here is to stop a NEW endpoint from landing untyped; the recorded ones come down endpoint by endpoint.","react-hooks/set-state-in-effect": "Legitimate-looking `reset derived state when the subject changes` and prop-mirroring effects in components with no test coverage. Each rewrite changes when a render happens, so each needs its own regression test first; batching them behind a lint deadline is how a subtle render-order bug ships.","react-hooks/preserve-manual-memoization": "Advice for adopting the React Compiler, not a defect. `babel-plugin-react-compiler` is not in this project's Vite plugin list, so no shipped behaviour depends on these; they become actionable in the change that turns the compiler on.",- "react-refresh/only-export-components": "`src/context/ApiContext.tsx` only. Every other context module in the UI now splits its handle from its provider, but this one is 3142 lines with ~78 consumers, and the split means relocating the ~1200-line provider in the single most contended file in the repository (36 unmerged branches currently modify it). The cost is a merge conflict for everyone else, and the benefit is hot-reload for one file \u2014 so it belongs in a change that owns ApiContext, not in a lint cleanup.",+ "react-refresh/only-export-components": "`src/context/ApiContext.tsx` only. Every other context module in the UI now splits its handle from its provider, but this one is 3142 lines with ~78 consumers, and the split means relocating the ~1200-line provider in the single most contended file in the repository (36 unmerged branches currently modify it). The cost is a merge conflict for everyone else, and the benefit is hot-reload for one file — so it belongs in a change that owns ApiContext, not in a lint cleanup.","react-hooks/exhaustive-deps": "Inline `eslint-disable` comments predating this cleanup. Each one also opts its component out of the compiler-backed hook analysis, so the suppressed count is a direct measure of the UI the other react-hooks rules cannot see: removing all 43 raises the error count rather than lowering it. Frozen here so that area cannot grow while it is retired component by component.","react-hooks/refs": "Inline suppressions of the render-phase ref rule, in the same unanalysable area as the exhaustive-deps ones above. Frozen so no new render-phase ref access can be hidden behind a comment."},@@ -126,7 +126,7 @@"@typescript-eslint/no-explicit-any": 5},"src/context/ApiContext.tsx": {- "@typescript-eslint/no-explicit-any": 52,+ "@typescript-eslint/no-explicit-any": 51,"react-refresh/only-export-components": 1},"src/context/DockProvider.tsx": {diff --git a/ui/src/components/useShowPages.ts b/ui/src/components/useShowPages.tsindex 73a3ca026..5061834de 100644--- a/ui/src/components/useShowPages.ts+++ b/ui/src/components/useShowPages.ts@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';import { useApi } from '../context/ApiContext';import { useToast } from '../context/ToastContext';import type { ShowPageLinkInfo } from '../lib/showPageLinks';+import { isShowPageVisibilityPayload } from '../lib/showPageAccess';import {getShowPagesInventoryStore,type ShowPage,@@ -38,6 +39,7 @@ export function useShowPageInventory(enabled = true) {loading,loaded,mergePage: store.mergePage,+ removePage: store.removePage,replaceTitleIfCurrent: store.replaceTitleIfCurrent,reload,};@@ -51,7 +53,7 @@ export function useShowPages() {const api = useApi();const { showToast } = useToast();const { t } = useTranslation();- const { pages, loading, loaded, mergePage, replaceTitleIfCurrent, reload } =+ const { pages, loading, loaded, mergePage, removePage, replaceTitleIfCurrent, reload } =useShowPageInventory();const [busyId, setBusyId] = useState<string | null>(null);@@ -59,8 +61,16 @@ export function useShowPages() {if (page.visibility === visibility || busyId) return;setBusyId(page.session_id);try {- const res = await api.setShowPageVisibility(page.session_id, visibility);- mergePage(res);+ const res = await api.setShowPageVisibility<ShowPage>(page.session_id, visibility);+ if (isShowPageVisibilityPayload(res)) {+ mergePage(res);+ } else {+ // The caller lost page-use access between render and mutation. The+ // metadata-only response deliberately contains no page identifiers or+ // links, so withdraw the retained inventory row immediately.+ removePage(page.session_id);+ reload();+ }showToast(t('showPages.toast.updated'));} catch {// ApiContext surfaces a toast on failure.diff --git a/ui/src/components/workbench/ChatPage.tsx b/ui/src/components/workbench/ChatPage.tsxindex 090d27d38..2464b0763 100644--- a/ui/src/components/workbench/ChatPage.tsx+++ b/ui/src/components/workbench/ChatPage.tsx@@ -25,7 +25,9 @@ import { isVaultApprovalRequest, placeVaultProvisionRequests } from '../../lib/vimport { localPath, type ShowPageLinkInfo } from '../../lib/showPageLinks';import {showPageHeaderAccess,+ showPageRestoreAccessDecision,type ShowPageAccess,+ type ShowPageAccessProbe,} from '../../lib/showPageAccess';import { showPageEmbeddedPath } from '../../apps/showPageAvatar';import { downloadFile, fileMeta } from '../../lib/filesApi';@@ -199,15 +201,20 @@ export const ChatPage: React.FC = () => {const canChat = capabilities.can_chat && sessionCanChat;const [showPageAccessResult, setShowPageAccessResult] = useState<{sessionId: string;- access: ShowPageAccess | null;+ probe: ShowPageAccessProbe;} | null>(null);const showPageAccessProbeGenerationRef = useRef(0);- const showPageAccess = capabilities.can_use_show_pages+ const currentShowPageAccessProbe = capabilities.can_use_show_pages&& showPageAccessResult?.sessionId === sessionId- ? showPageAccessResult?.access ?? null+ ? showPageAccessResult?.probe ?? null: null;- const showPageAccessResolved = capabilities.can_manage_instance- || showPageAccessResult?.sessionId === sessionId;+ const showPageAccess = currentShowPageAccessProbe?.status === 'granted'+ ? currentShowPageAccessProbe.access+ : null;+ const showPageRestoreAccess = showPageRestoreAccessDecision(+ capabilities.can_manage_instance,+ currentShowPageAccessProbe,+ );const { canOpen: canOpenShowPage, canManage: canManageShowPage } = showPageHeaderAccess(capabilities.can_manage_instance,showPageAccess,@@ -306,12 +313,15 @@ export const ChatPage: React.FC = () => {const probeShowPageAccess = useCallback(async (targetSessionId: string) => {const generation = ++showPageAccessProbeGenerationRef.current;try {- const nextAccess = await api.probeShowPageAccess(targetSessionId);+ const nextProbe = await api.probeShowPageAccess(targetSessionId);if (generation !== showPageAccessProbeGenerationRef.current) return;- setShowPageAccessResult({ sessionId: targetSessionId, access: nextAccess });+ setShowPageAccessResult({ sessionId: targetSessionId, probe: nextProbe });} catch {if (generation !== showPageAccessProbeGenerationRef.current) return;- setShowPageAccessResult({ sessionId: targetSessionId, access: null });+ setShowPageAccessResult({+ sessionId: targetSessionId,+ probe: { status: 'error', access: null },+ });}}, [api]);useEffect(() => {@@ -1644,14 +1654,14 @@ export const ChatPage: React.FC = () => {showPageRestoreAttemptRef.current = sid;return;}- if (!showPageAccessResolved) return;+ if (showPageRestoreAccess === 'wait') return;showPageRestoreAttemptRef.current = sid;- if (!canOpenShowPage) {+ if (showPageRestoreAccess === 'deny') {writeChatViewMode(sid, 'chat');return;}void openShowPage(sid);- }, [canOpenShowPage, deepLinkMessageId, openShowPage, readOnly, session?.id, sessionId, showChatSignal, showPageAccessResolved]);+ }, [deepLinkMessageId, openShowPage, readOnly, session?.id, sessionId, showChatSignal, showPageRestoreAccess]);// When the share control resolves the page (open) or flips its visibility, the// serving route changes (private → /show/, public → /p/). Re-point the iframediff --git a/ui/src/components/workbench/ShowPageShareControl.tsx b/ui/src/components/workbench/ShowPageShareControl.tsxindex c43df7aed..492cd1d60 100644--- a/ui/src/components/workbench/ShowPageShareControl.tsx+++ b/ui/src/components/workbench/ShowPageShareControl.tsx@@ -14,6 +14,7 @@ import { isIosDevice, isRealMobileSafari, isStandalonePwa } from '../../lib/platimport { copyHref, type ShowPageLinkInfo } from '../../lib/showPageLinks';import {canChangeShowPagePublicLink,+ isShowPageVisibilityPayload,showPageShareCapabilities,type ShowPageAccess,} from '../../lib/showPageAccess';@@ -48,7 +49,7 @@ export const ShowPageShareControl: React.FC<{const { t } = useTranslation();const api = useApi();const dock = useDock();- const { pages, mergePage, reload } = useShowPageInventory();+ const { pages, mergePage, removePage, reload } = useShowPageInventory();const inventoryPage = pages.find((page) => page.session_id === sessionId);const [open, setOpen] = useState(false);const [workspaceConfirmationOpen, setWorkspaceConfirmationOpen] = useState(false);@@ -180,14 +181,27 @@ export const ShowPageShareControl: React.FC<{const setVisibilityTo = (next: string) => {setBusy(true);api- .setShowPageVisibility(sessionId, next)- .then((res: ShowPagePayload) => {+ .setShowPageVisibility<ShowPagePayload>(sessionId, next)+ .then((res) => {// Authoritative server state: always apply it, and invalidate any// in-flight refresh read so a stale read can't revert us afterwards.- applyPayload(res);+ const canReadResult = isShowPageVisibilityPayload(res);+ if (canReadResult) {+ applyPayload(res);+ } else {+ // Access changed after this popover rendered. A metadata-only result+ // intentionally carries no page path, link, share id, or session id;+ // withdraw every retained copy before revalidating the inventory.+ setLocalPayload(null);+ removePage(sessionId);+ reload();+ }setAccess((current) => current ? {...current,- public_link_enabled: next === 'public',+ can_use: canReadResult ? current.can_use : false,+ public_link_enabled: canReadResult+ ? next === 'public'+ : res.public_link_enabled,} : current);reqSeq.current += 1;})diff --git a/ui/src/components/workbench/ShowPageWorkspaceAccessControl.test.tsx b/ui/src/components/workbench/ShowPageWorkspaceAccessControl.test.tsxindex 313d6e630..b6ffbf04e 100644--- a/ui/src/components/workbench/ShowPageWorkspaceAccessControl.test.tsx+++ b/ui/src/components/workbench/ShowPageWorkspaceAccessControl.test.tsx@@ -2,7 +2,10 @@ import { renderToStaticMarkup } from 'react-dom/server';import { describe, expect, it, vi } from 'vitest';import type { ShowPageAccess } from '@/lib/showPageAccess';-import { ShowPageWorkspaceAccessControl } from './ShowPageWorkspaceAccessControl';+import {+ ShowPageOrganizationAuthorizationPrompt,+ ShowPageWorkspaceAccessControl,+} from './ShowPageWorkspaceAccessControl';vi.mock('react-i18next', () => ({useTranslation: () => ({ t: (key: string) => key }),@@ -35,6 +38,26 @@ const renderControl = (value: ShowPageAccess) => renderToStaticMarkup();describe('ShowPageWorkspaceAccessControl', () => {+ it('offers explicit reauthorization after an Organization subject mismatch', () => {+ const html = renderToStaticMarkup(+ <ShowPageOrganizationAuthorizationPrompt gate="subject_mismatch" onAuthorize={() => undefined} />,+ );++ expect(html).toContain('chat.showPage.organizationSubjectMismatch');+ expect(html).toContain('chat.showPage.organizationSignInAgain');+ expect(html).toContain('<button');+ });++ it('keeps the normal Organization sign-in action on the same recovery component', () => {+ const html = renderToStaticMarkup(+ <ShowPageOrganizationAuthorizationPrompt gate="authorization_required" onAuthorize={() => undefined} />,+ );++ expect(html).toContain('chat.showPage.organizationSignInDesc');+ expect(html).toContain('chat.showPage.organizationSignIn');+ expect(html).toContain('<button');+ });+it('renders Personal as a fixed Private audience without Organization choices', () => {const html = renderControl(access({mode: 'personal',diff --git a/ui/src/components/workbench/ShowPageWorkspaceAccessControl.tsx b/ui/src/components/workbench/ShowPageWorkspaceAccessControl.tsxindex ad82ed08a..b2551b1f6 100644--- a/ui/src/components/workbench/ShowPageWorkspaceAccessControl.tsx+++ b/ui/src/components/workbench/ShowPageWorkspaceAccessControl.tsx@@ -52,6 +52,7 @@ type ManagementGate =| 'error';type ResourceResponse = { resource: OrganizationResource };+type OrganizationAuthorizationGate = 'authorization_required' | 'subject_mismatch';const LEVEL_ICONS = {private: LockKeyhole,@@ -75,6 +76,44 @@ function sessionGate(session: CloudManagementSession): ManagementGate {return session.state;}+export function ShowPageOrganizationAuthorizationPrompt({+ gate,+ onAuthorize,+}: {+ gate: OrganizationAuthorizationGate;+ onAuthorize: () => void;+}) {+ const { t } = useTranslation();+ const subjectMismatch = gate === 'subject_mismatch';+ return (+ <div className="flex items-center justify-between gap-2 border-t border-border pt-2">+ <span className={clsx(+ 'flex min-w-0 items-start gap-1.5 text-[11px] leading-snug',+ subjectMismatch ? 'text-destructive' : 'text-muted',+ )}>+ {subjectMismatch ? <TriangleAlert className="mt-0.5 size-3.5 shrink-0" /> : null}+ <span>+ {t(subjectMismatch+ ? 'chat.showPage.organizationSubjectMismatch'+ : 'chat.showPage.organizationSignInDesc')}+ </span>+ </span>+ <Button+ type="button"+ size="sm"+ variant="outline"+ className="h-7 shrink-0"+ onClick={onAuthorize}+ >+ <LogIn className="size-3.5" />+ {t(subjectMismatch+ ? 'chat.showPage.organizationSignInAgain'+ : 'chat.showPage.organizationSignIn')}+ </Button>+ </div>+ );+}+export function ShowPageWorkspaceAccessControl({access,active,@@ -327,17 +366,14 @@ export function ShowPageWorkspaceAccessControl({</div>) : null}- {access?.mode === 'organization' && canManage && gate === 'authorization_required' ? (- <div className="flex items-center justify-between gap-2 border-t border-border pt-2">- <span className="text-[11px] leading-snug text-muted">- {t('chat.showPage.organizationSignInDesc')}- </span>- <Button type="button" size="sm" variant="outline" className="h-7 shrink-0" onClick={() => void startAuthorization()}>- <LogIn className="size-3.5" />- {t('chat.showPage.organizationSignIn')}- </Button>- </div>- ) : null}+ {access?.mode === 'organization'+ && canManage+ && (gate === 'authorization_required' || gate === 'subject_mismatch') ? (+ <ShowPageOrganizationAuthorizationPrompt+ gate={gate}+ onAuthorize={() => void startAuthorization()}+ />+ ) : null}{access?.mode === 'organization' && canManage && gate === 'cloud_not_connected' ? (<div className="flex items-start gap-1.5 text-[11px] leading-snug text-muted">@@ -346,13 +382,6 @@ export function ShowPageWorkspaceAccessControl({</div>) : null}- {access?.mode === 'organization' && canManage && gate === 'subject_mismatch' ? (- <div className="flex items-start gap-1.5 text-[11px] leading-snug text-destructive">- <TriangleAlert className="mt-0.5 size-3.5 shrink-0" />- {t('chat.showPage.organizationSubjectMismatch')}- </div>- ) : null}-{access?.mode === 'organization' && canManage && ['conflict', 'unreachable', 'error'].includes(gate) ? (<div className="flex items-center justify-between gap-2 border-t border-border pt-2"><span className="text-[11px] leading-snug text-destructive">diff --git a/ui/src/context/ApiContext.tsx b/ui/src/context/ApiContext.tsxindex 79c1e6037..ccdfb79d3 100644--- a/ui/src/context/ApiContext.tsx+++ b/ui/src/context/ApiContext.tsx@@ -7,8 +7,14 @@ import type { TurnActivityGroupWire } from '../lib/agentActivity';import type { AgentGraphParams, AgentGraphResult, AgentGraphVisibility } from '../lib/agentGraph';import { visibilityActivityEvents } from '../lib/sessionVisibilityEvents';import { normalizeSessionInfo, type InstanceCapabilities, type SessionInfo } from '../lib/sessionInfo';+import type { ShowPageLinkInfo } from '../lib/showPageLinks';import type { VaultSessionPolicy } from '../lib/vaultSandboxPolicy';-import type { ShowPageAccess } from '../lib/showPageAccess';+import {+ classifyShowPageAccessProbe,+ type ShowPageAccess,+ type ShowPageAccessProbe,+ type ShowPageVisibilityResult,+} from '../lib/showPageAccess';import {WorkbenchEventReconnectLoop,type WorkbenchEventConnectionState,@@ -491,7 +497,7 @@ export type ApiContextType = {removeUser: (userId: string, platform?: string) => Promise<any>;getShowPages: () => Promise<any>;getShowPageAccess: (sessionId: string) => Promise<ShowPageAccess>;- probeShowPageAccess: (sessionId: string) => Promise<ShowPageAccess | null>;+ probeShowPageAccess: (sessionId: string) => Promise<ShowPageAccessProbe>;getWebPushStatus: (payload?: WebPushStatusPayload) => Promise<WebPushStatus>;getWebPushVapidPublicKey: () => Promise<{ ok: boolean; public_key: string }>;subscribeWebPush: (@@ -502,7 +508,10 @@ export type ApiContextType = {) => Promise<WebPushSubscriptionResult>;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>;+ setShowPageVisibility: <Payload extends ShowPageLinkInfo = ShowPageLinkInfo>(+ sessionId: string,+ visibility: string,+ ) => Promise<ShowPageVisibilityResult<Payload>>;/** Create the session's Show Page if absent; resolves to `{ existed, ... }`. */ensureShowPage: (sessionId: string) => Promise<any>;rotateShowPageShare: (sessionId: string) => Promise<any>;@@ -2809,11 +2818,18 @@ export const ApiProvider: React.FC<{ children: React.ReactNode }> = ({ childrengetShowPages: () => getJson('/api/show-pages'),getShowPageAccess: (sessionId) => getJson(`/api/show-pages/${encodeURIComponent(sessionId)}/access`),probeShowPageAccess: async (sessionId) => {- const payload = await getJson(- `/api/show-pages/${encodeURIComponent(sessionId)}/access`,- { handleError: false },- );- return payload?.ok === true ? payload as ShowPageAccess : null;+ try {+ const response = await apiFetch(`/api/show-pages/${encodeURIComponent(sessionId)}/access`);+ let payload: unknown;+ try {+ payload = await response.json();+ } catch {+ return { status: 'error', access: null };+ }+ return classifyShowPageAccessProbe(response.status, payload);+ } catch {+ return { status: 'error', access: null };+ }},getWebPushStatus: (payload) =>payload ? postJson('/api/web-push/status', payload) : getJson('/api/web-push/status'),diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex 059bedb52..c15e01e5a 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -3187,6 +3187,7 @@"loadingWorkspaceAccess": "Loading Organization access…","workspaceReadOnly": "Only the Show Page owner or an Organization manager can change this audience.","organizationSignIn": "Sign in",+ "organizationSignInAgain": "Sign in again","organizationSignInDesc": "Sign in to avibe.bot to change the Organization audience.","organizationUnavailable": "This Avibe is not connected to avibe.bot Organization management.","organizationSubjectMismatch": "The signed-in avibe.bot account does not match this Avibe session.",diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.jsonindex 8504cab64..b22c3f80f 100644--- a/ui/src/i18n/zh.json+++ b/ui/src/i18n/zh.json@@ -3187,6 +3187,7 @@"loadingWorkspaceAccess": "正在加载组织权限…","workspaceReadOnly": "只有页面所有者或组织管理者可以修改此访问范围。","organizationSignIn": "登录",+ "organizationSignInAgain": "重新登录","organizationSignInDesc": "登录 avibe.bot 后才能修改组织访问范围。","organizationUnavailable": "当前 Avibe 尚未连接 avibe.bot 的组织管理功能。","organizationSubjectMismatch": "当前登录的 avibe.bot 账号与此 Avibe 会话不一致。",diff --git a/ui/src/lib/showPageAccess.test.ts b/ui/src/lib/showPageAccess.test.tsindex dfcd34e6f..1a01e45c8 100644--- a/ui/src/lib/showPageAccess.test.ts+++ b/ui/src/lib/showPageAccess.test.ts@@ -4,10 +4,13 @@ import { isRevisionConflict, OrganizationApiError } from '@/features/organizatioimport {buildShowPageAccessPatch,canChangeShowPagePublicLink,+ classifyShowPageAccessProbe,+ isShowPageVisibilityPayload,showPageShareCapabilities,showPageHeaderAccess,showPageAudienceLabelKey,showPageAudienceLevels,+ showPageRestoreAccessDecision,showPageSyncPresentation,type ShowPageAccess,} from './showPageAccess';@@ -96,6 +99,36 @@ describe('Show Page access policy helpers', () => {expect(showPageHeaderAccess(true, null)).toEqual({ canOpen: true, canManage: true });});+ it('keeps transient access probe failures distinct from definitive denials', () => {+ const granted = classifyShowPageAccessProbe(200, access());+ const managerOnly = classifyShowPageAccessProbe(200, access({ can_use: false }));+ const denied = classifyShowPageAccessProbe(403, { error: 'resource_access_forbidden' });+ const missing = classifyShowPageAccessProbe(404, { error: 'show_page_not_found' });+ const unavailable = classifyShowPageAccessProbe(503, { error: 'backend_unavailable' });++ expect(showPageRestoreAccessDecision(false, granted)).toBe('allow');+ expect(showPageRestoreAccessDecision(false, managerOnly)).toBe('deny');+ expect(showPageRestoreAccessDecision(false, denied)).toBe('deny');+ expect(showPageRestoreAccessDecision(false, missing)).toBe('deny');+ expect(showPageRestoreAccessDecision(false, unavailable)).toBe('wait');+ expect(showPageRestoreAccessDecision(false, { status: 'error', access: null })).toBe('wait');+ expect(showPageRestoreAccessDecision(true, null)).toBe('allow');+ });++ it('distinguishes metadata-only visibility results from readable page payloads', () => {+ expect(isShowPageVisibilityPayload({+ ok: true,+ public_link_enabled: false,+ })).toBe(false);+ expect(isShowPageVisibilityPayload({+ ok: true,+ session_id: 'session-1',+ visibility: 'private',+ active_url: '/show/session-1/',+ share_id: null,+ })).toBe(true);+ });+it('distinguishes pending, offline, and error sync states', () => {expect(showPageSyncPresentation('pending')).toEqual({key: 'chat.showPage.workspaceSync.pending',diff --git a/ui/src/lib/showPageAccess.ts b/ui/src/lib/showPageAccess.tsindex c43a9d494..d4dc62710 100644--- a/ui/src/lib/showPageAccess.ts+++ b/ui/src/lib/showPageAccess.ts@@ -1,4 +1,5 @@import type { ResourceAccessLevel, SyncStatus } from '@/features/organization/api/types';+import type { ShowPageLinkInfo } from './showPageLinks';export type ShowPageAccess = {ok: true;@@ -15,6 +16,63 @@ export type ShowPageAccess = {public_link_enabled: boolean;};+export type ShowPageAccessProbe =+ | { status: 'granted'; access: ShowPageAccess }+ | { status: 'denied'; access: null }+ | { status: 'error'; access: null };++export type ShowPageVisibilityMetadata = {+ ok: true;+ public_link_enabled: boolean;+};++export type ShowPageVisibilityPayload<Payload extends ShowPageLinkInfo = ShowPageLinkInfo> = {+ ok: true;+} & Payload;+export type ShowPageVisibilityResult<Payload extends ShowPageLinkInfo = ShowPageLinkInfo> =+ | ShowPageVisibilityPayload<Payload>+ | ShowPageVisibilityMetadata;++function isShowPageAccess(value: unknown): value is ShowPageAccess {+ if (!value || typeof value !== 'object') return false;+ const candidate = value as Partial<ShowPageAccess>;+ return candidate.ok === true+ && (candidate.mode === 'personal' || candidate.mode === 'organization')+ && typeof candidate.can_use === 'boolean'+ && typeof candidate.can_manage === 'boolean'+ && typeof candidate.can_publish_public === 'boolean'+ && typeof candidate.public_link_enabled === 'boolean';+}++export function classifyShowPageAccessProbe(+ status: number,+ payload: unknown,+): ShowPageAccessProbe {+ if (status >= 200 && status < 300 && isShowPageAccess(payload)) {+ return { status: 'granted', access: payload };+ }+ if (status === 403 || status === 404) {+ return { status: 'denied', access: null };+ }+ return { status: 'error', access: null };+}++export function showPageRestoreAccessDecision(+ canManageInstance: boolean,+ probe: ShowPageAccessProbe | null,+): 'allow' | 'deny' | 'wait' {+ if (canManageInstance) return 'allow';+ if (!probe || probe.status === 'error') return 'wait';+ if (probe.status === 'denied') return 'deny';+ return probe.access.can_use ? 'allow' : 'deny';+}++export function isShowPageVisibilityPayload<Payload extends ShowPageLinkInfo>(+ result: ShowPageVisibilityResult<Payload>,+): result is ShowPageVisibilityPayload<Payload> {+ return 'session_id' in result && typeof result.session_id === 'string';+}+export function showPageHeaderAccess(canManageInstance: boolean,access: ShowPageAccess | null,diff --git a/ui/src/lib/showPagesStore.test.ts b/ui/src/lib/showPagesStore.test.tsindex 55dd8eb54..f7a3bda6b 100644--- a/ui/src/lib/showPagesStore.test.ts+++ b/ui/src/lib/showPagesStore.test.ts@@ -89,6 +89,19 @@ describe('ShowPagesInventoryStore', () => {release();});+ it('withdraws a retained page immediately when access is lost', async () => {+ const store = new ShowPagesInventoryStore({+ getShowPages: vi.fn().mockResolvedValue({ pages: [page()] }),+ connectWorkbenchEvents: vi.fn(() => vi.fn()),+ });++ await store.reload();+ expect(store.getSnapshot().pages).toHaveLength(1);++ store.removePage('session-1');+ expect(store.getSnapshot().pages).toEqual([]);+ });+it('serves stale icon metadata immediately on reopen and revalidates in the background', async () => {const initial = deferred<{ pages: ShowPage[] }>();const refresh = deferred<{ pages: ShowPage[] }>();