diff --git a/.changeset/ui-react-default-root-wrappers.md b/.changeset/ui-react-default-root-wrappers.md new file mode 100644 index 0000000000..c946913b81 --- /dev/null +++ b/.changeset/ui-react-default-root-wrappers.md @@ -0,0 +1,4 @@ +--- +"@schlessera/brain-ui-react": patch +--- +Remove nine internal default-root wrappers that no entry point exported and nothing called. The public API is unchanged. diff --git a/docs/decisions/session-principals.md b/docs/decisions/session-principals.md index 58fc171748..e4928bec7d 100644 --- a/docs/decisions/session-principals.md +++ b/docs/decisions/session-principals.md @@ -111,7 +111,7 @@ Both reviewers verified every row below against the source. | Activity subscriptions | `activity/stream.ts:153` | a **separate** registry keyed on the wrapper, not `ws.raw` | | Rollups | `migrations/007_activity.sql`; `upsertRollup`, `activity/sql.ts:19-24` | `activity_run_rollups` survives span pruning and carries its own origin/session/job | | Client logout | `logout: () =>`, `ui-react/src/lib/api-client.ts:696`; `Sign out everywhere`, `passkey-list.tsx:108-108` | "Sign out everywhere" POSTs `/auth/logout` with no arguments | -| Unauthorized in the UI | `res.status === 401`, `ui-react/src/hooks/use-vpn-status.ts:36` | reached by `/api/vpn-check` returning 401, not by a close code | +| Unauthorized in the UI | `res.status === 401`, `ui-react/src/hooks/use-vpn-status.ts:35` | reached by `/api/vpn-check` returning 401, not by a close code | Two findings that are true today, independent of this plan: diff --git a/packages/ui-react/src/hooks/use-vpn-status.ts b/packages/ui-react/src/hooks/use-vpn-status.ts index 6a9f5466a0..568bcc2672 100644 --- a/packages/ui-react/src/hooks/use-vpn-status.ts +++ b/packages/ui-react/src/hooks/use-vpn-status.ts @@ -1,4 +1,3 @@ -import { defaultRoot } from "../default-root.js"; import { useBrainUiRoot } from "../root-context.js"; import type { BrainUiRoot } from "../root.js"; import { useEffect, useRef, useState } from "react"; @@ -43,14 +42,6 @@ async function fetchVpnStatus(root: BrainUiRoot): Promise { } } -/** - * Ask the mounted connectivity poller for a fresh reading. The poller remains - * the only writer of vpnStatus and serializes this with its scheduled checks. - */ -export function recheckVpnStatus(): void { - defaultRoot.recheckVpn?.(); -} - export function useVpnStatus(localOnly = false) { const root = useBrainUiRoot(); const local = useRef(localOnly); diff --git a/packages/ui-react/src/hooks/use-websocket.ts b/packages/ui-react/src/hooks/use-websocket.ts index 381ac9b5b7..88577a5d70 100644 --- a/packages/ui-react/src/hooks/use-websocket.ts +++ b/packages/ui-react/src/hooks/use-websocket.ts @@ -1,15 +1,8 @@ import { useEffect, useCallback } from "react"; -import type { ClientMessage, ServerMessage } from "@schlessera/brain-ui-sdk/protocol"; -import { defaultRoot } from "../default-root.js"; +import type { ClientMessage } from "@schlessera/brain-ui-sdk/protocol"; import { useBrainUiRoot } from "../root-context.js"; export { runStateForFrame } from "./websocket-handlers/chat.js"; -/** Default-app entry points for callers outside React. */ -export function handleServerMessage(message: ServerMessage) { defaultRoot.connection.handleServerMessage(message); } -export function flushChatDeltas() { defaultRoot.connection.flushChatDeltas(); } -export function sendClientMessage(message: ClientMessage) { return defaultRoot.connection.send(message); } -export function reconnectWebSocketNow() { defaultRoot.connection.reconnectNow(); } - export function useWebSocket() { const root = useBrainUiRoot(); useEffect(() => root.connection.connect(), [root]); diff --git a/packages/ui-react/src/lib/backend.ts b/packages/ui-react/src/lib/backend.ts index 9ad66d603c..891a6f932a 100644 --- a/packages/ui-react/src/lib/backend.ts +++ b/packages/ui-react/src/lib/backend.ts @@ -42,5 +42,3 @@ export function getBackendUrlFor(config: BrainUiConfig, path: string): string { // Existing consumers still address the default configuration. Root-owned // clients use the explicit helpers above, and keep their config in a closure. export function apiBase(): string { return apiBaseFor(uiConfig); } -export function getWsUrl(): string { return getWsUrlFor(uiConfig); } -export function getBackendUrl(path: string): string { return getBackendUrlFor(uiConfig, path); } diff --git a/packages/ui-react/src/stores/activity-store.ts b/packages/ui-react/src/stores/activity-store.ts index 456e823974..949e41e6db 100644 --- a/packages/ui-react/src/stores/activity-store.ts +++ b/packages/ui-react/src/stores/activity-store.ts @@ -9,6 +9,3 @@ export const useActivityStore = Object.assign( }, defaultRoot.stores.activity, ); - -export const loadSessionActivityHistory = defaultRoot.stores.activity.loadSessionActivityHistory; -export const loadSpanPayloads = defaultRoot.stores.activity.loadSpanPayloads; diff --git a/packages/ui-react/tests/chat-store-approval-recovery.test.ts b/packages/ui-react/tests/chat-store-approval-recovery.test.ts index 13b85161cd..9b558fe7cc 100644 --- a/packages/ui-react/tests/chat-store-approval-recovery.test.ts +++ b/packages/ui-react/tests/chat-store-approval-recovery.test.ts @@ -1,7 +1,9 @@ import { beforeEach, describe, expect, test } from "bun:test"; import type { ServerMessage, SessionHistoryMessage } from "@schlessera/brain-ui-sdk/protocol"; import { useChatStore } from "../src/stores/chat-store"; -import { flushChatDeltas, handleServerMessage } from "../src/hooks/use-websocket"; +import { defaultRoot } from "../src/default-root"; + +const { flushChatDeltas, handleServerMessage } = defaultRoot.connection; // Approval recovery in the client (#964, D52 ยง4): a pending approval the host // re-delivers after a replay lands on its own turn, as one card, marked diff --git a/packages/ui-react/tests/chat-store-ask-dedup.test.ts b/packages/ui-react/tests/chat-store-ask-dedup.test.ts index 12e4e82cef..619a634fa2 100644 --- a/packages/ui-react/tests/chat-store-ask-dedup.test.ts +++ b/packages/ui-react/tests/chat-store-ask-dedup.test.ts @@ -9,10 +9,12 @@ */ import { beforeEach, describe, expect, test } from "bun:test"; import type { ServerMessage, SessionHistoryMessage } from "@schlessera/brain-ui-sdk/protocol"; -import { flushChatDeltas, handleServerMessage } from "../src/hooks/use-websocket"; +import { defaultRoot } from "../src/default-root"; import { useChatStore } from "../src/stores/chat-store"; import { matchAskExchanges } from "../src/components/chat/message-bubble"; +const { flushChatDeltas, handleServerMessage } = defaultRoot.connection; + type Kind = "ask_user" | "ask_user_list" | "ask_user_rank" | "ask_user_form"; const KINDS: Kind[] = ["ask_user", "ask_user_list", "ask_user_rank", "ask_user_form"]; diff --git a/packages/ui-react/tests/delta-batching.test.ts b/packages/ui-react/tests/delta-batching.test.ts index 8f5da7c576..dcc237d7a5 100644 --- a/packages/ui-react/tests/delta-batching.test.ts +++ b/packages/ui-react/tests/delta-batching.test.ts @@ -4,7 +4,9 @@ import { describe, test, expect, beforeEach, afterEach } from "bun:test"; import type { ServerMessage } from "@schlessera/brain-ui-sdk/protocol"; import { useChatStore, activeChat } from "../src/stores/chat-store"; -import { handleServerMessage, flushChatDeltas } from "../src/hooks/use-websocket"; +import { defaultRoot } from "../src/default-root"; + +const { handleServerMessage, flushChatDeltas } = defaultRoot.connection; /** Frame callbacks the handler queued, run only when a test says to. */ let frames: FrameRequestCallback[] = []; diff --git a/packages/ui-react/tests/render/answer-delivery.test.tsx b/packages/ui-react/tests/render/answer-delivery.test.tsx index fd5f4f404a..3d78e53b85 100644 --- a/packages/ui-react/tests/render/answer-delivery.test.tsx +++ b/packages/ui-react/tests/render/answer-delivery.test.tsx @@ -7,12 +7,14 @@ import { unregisterAnswerDeliveryDom } from "./answer-delivery-dom.js"; import { afterAll, afterEach, beforeEach, describe, expect, test } from "bun:test"; import { cleanup, render } from "@testing-library/react"; import { MessageBubble } from "../../src/components/chat/message-bubble.js"; -import { flushChatDeltas, handleServerMessage } from "../../src/hooks/use-websocket.js"; +import { defaultRoot } from "../../src/default-root.js"; import { useChatStore } from "../../src/stores/chat-store.js"; import { useUIStore } from "../../src/stores/ui-store.js"; import type { AnswerDelivery, AnswerPayload, DeliveryState } from "../../src/lib/answer-delivery/types.js"; import type { SessionHistoryMessage } from "@schlessera/brain-ui-sdk/protocol"; +const { flushChatDeltas, handleServerMessage } = defaultRoot.connection; + afterEach(cleanup); afterAll(unregisterAnswerDeliveryDom); beforeEach(() => { diff --git a/packages/ui-react/tests/render/ask-user-list.test.tsx b/packages/ui-react/tests/render/ask-user-list.test.tsx index 2071eb76c6..cc4ad9ded7 100644 --- a/packages/ui-react/tests/render/ask-user-list.test.tsx +++ b/packages/ui-react/tests/render/ask-user-list.test.tsx @@ -15,9 +15,11 @@ import { listReaskMessage, } from "../../src/components/chat/ask-user-list-card.js"; import { MessageBubble } from "../../src/components/chat/message-bubble.js"; -import { flushChatDeltas, handleServerMessage } from "../../src/hooks/use-websocket.js"; +import { defaultRoot } from "../../src/default-root.js"; import { useChatStore } from "../../src/stores/chat-store.js"; +const { flushChatDeltas, handleServerMessage } = defaultRoot.connection; + afterEach(cleanup); afterAll(unregisterAskUserListDom); diff --git a/packages/ui-react/tests/render/ask-user-rank.test.tsx b/packages/ui-react/tests/render/ask-user-rank.test.tsx index fb70d0833e..d4d9523836 100644 --- a/packages/ui-react/tests/render/ask-user-rank.test.tsx +++ b/packages/ui-react/tests/render/ask-user-rank.test.tsx @@ -3,11 +3,13 @@ import { afterAll, afterEach, beforeEach, describe, expect, test } from "bun:tes import { act, cleanup, fireEvent, render } from "@testing-library/react"; import { AskUserRankExchangeCard } from "../../src/components/chat/ask-user-rank-card.js"; import { MessageBubble } from "../../src/components/chat/message-bubble.js"; -import { flushChatDeltas, handleServerMessage } from "../../src/hooks/use-websocket.js"; +import { defaultRoot } from "../../src/default-root.js"; import { useChatStore } from "../../src/stores/chat-store.js"; import { useUIStore } from "../../src/stores/ui-store.js"; import type { AskUserRankSpec, SessionHistoryMessage } from "@schlessera/brain-ui-sdk/protocol"; +const { flushChatDeltas, handleServerMessage } = defaultRoot.connection; + afterEach(cleanup); afterAll(unregisterAskUserRankDom); beforeEach(() => { diff --git a/packages/ui-react/tests/render/message-source.test.tsx b/packages/ui-react/tests/render/message-source.test.tsx index 9aa3512829..f1b56d0b0e 100644 --- a/packages/ui-react/tests/render/message-source.test.tsx +++ b/packages/ui-react/tests/render/message-source.test.tsx @@ -11,9 +11,11 @@ import { cleanup, render } from "@testing-library/react"; import type { SessionHistoryMessage } from "@schlessera/brain-ui-sdk/protocol"; import { MessageBubble } from "../../src/components/chat/message-bubble.js"; -import { flushChatDeltas, handleServerMessage } from "../../src/hooks/use-websocket.js"; +import { defaultRoot } from "../../src/default-root.js"; import { useChatStore } from "../../src/stores/chat-store.js"; +const { flushChatDeltas, handleServerMessage } = defaultRoot.connection; + afterEach(cleanup); afterAll(unregisterMessageSourceDom); diff --git a/packages/ui-react/tests/render/streaming-bench.tsx b/packages/ui-react/tests/render/streaming-bench.tsx index 224e9b77a3..bd2b2a0922 100644 --- a/packages/ui-react/tests/render/streaming-bench.tsx +++ b/packages/ui-react/tests/render/streaming-bench.tsx @@ -59,7 +59,8 @@ const { render, cleanup, act } = await import("@testing-library/react"); const { ChatPage } = await import("../../src/components/chat/chat-page.js"); const { useChatStore } = await import("../../src/stores/chat-store.js"); const { useConnectionStore } = await import("../../src/stores/connection-store.js"); -const { handleServerMessage } = await import("../../src/hooks/use-websocket.js"); +const { defaultRoot } = await import("../../src/default-root.js"); +const { handleServerMessage } = defaultRoot.connection; import type { ServerMessage } from "@schlessera/brain-ui-sdk/protocol"; const BODY = `## Section heading diff --git a/packages/ui-react/tests/render/turn-failure.test.tsx b/packages/ui-react/tests/render/turn-failure.test.tsx index debba86866..f7ed13828f 100644 --- a/packages/ui-react/tests/render/turn-failure.test.tsx +++ b/packages/ui-react/tests/render/turn-failure.test.tsx @@ -16,10 +16,12 @@ import { import { useHandoffStore } from "../../src/stores/handoff-store.js"; import { MessageBubble } from "../../src/components/chat/message-bubble.js"; -import { flushChatDeltas, handleServerMessage } from "../../src/hooks/use-websocket.js"; +import { defaultRoot } from "../../src/default-root.js"; import { useChatStore } from "../../src/stores/chat-store.js"; import { failurePresentation } from "../../src/lib/turn-failure.js"; +const { flushChatDeltas, handleServerMessage } = defaultRoot.connection; + afterEach(cleanup); afterAll(unregisterTurnFailureDom); diff --git a/packages/ui-react/tests/session-demux.test.ts b/packages/ui-react/tests/session-demux.test.ts index 0057e2bebe..2eb10dd0e3 100644 --- a/packages/ui-react/tests/session-demux.test.ts +++ b/packages/ui-react/tests/session-demux.test.ts @@ -1,7 +1,10 @@ import { describe, test, expect, beforeEach } from "bun:test"; import type { ServerMessage } from "@schlessera/brain-ui-sdk/protocol"; import { useChatStore, activeChat } from "../src/stores/chat-store"; -import { runStateForFrame, handleServerMessage, flushChatDeltas } from "../src/hooks/use-websocket"; +import { runStateForFrame } from "../src/hooks/use-websocket"; +import { defaultRoot } from "../src/default-root"; + +const { handleServerMessage, flushChatDeltas } = defaultRoot.connection; function reset() { // Text deltas are coalesced into the next animation frame when one exists; diff --git a/scripts/source-browser-dispatch.ts b/scripts/source-browser-dispatch.ts index 7676d58494..df7e200ef0 100644 --- a/scripts/source-browser-dispatch.ts +++ b/scripts/source-browser-dispatch.ts @@ -10,7 +10,7 @@ const helperConsumers:Record={ // Re-audited merged retained-history and stale-chat routing: only runStateForFrame // is imported; neither path acquires or mutates chatFrameHandlers. "packages/ui-react/src/connection.ts":"d1ab0f54089c75972f0597f4c2ca65bec2a0db418bad2ea438d05ccf558847ae", - "packages/ui-react/src/hooks/use-websocket.ts":"ab5208f9edeccee5d30fd3c9c81962d1cba3339222bd3f86b7ea143e0596ffcc" + "packages/ui-react/src/hooks/use-websocket.ts":"6edd8b289fa4dcf7f0a512ce1275bd9e9c70661ce5630e22503b4b1d888cf557" }; const declarations=[ {