Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changeset/ui-react-default-root-wrappers.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion docs/decisions/session-principals.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
9 changes: 0 additions & 9 deletions packages/ui-react/src/hooks/use-vpn-status.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -43,14 +42,6 @@ async function fetchVpnStatus(root: BrainUiRoot): Promise<VpnReading> {
}
}

/**
* 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);
Expand Down
9 changes: 1 addition & 8 deletions packages/ui-react/src/hooks/use-websocket.ts
Original file line number Diff line number Diff line change
@@ -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]);
Expand Down
2 changes: 0 additions & 2 deletions packages/ui-react/src/lib/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
3 changes: 0 additions & 3 deletions packages/ui-react/src/stores/activity-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 3 additions & 1 deletion packages/ui-react/tests/chat-store-approval-recovery.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/ui-react/tests/chat-store-ask-dedup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand Down
4 changes: 3 additions & 1 deletion packages/ui-react/tests/delta-batching.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down
4 changes: 3 additions & 1 deletion packages/ui-react/tests/render/answer-delivery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
4 changes: 3 additions & 1 deletion packages/ui-react/tests/render/ask-user-list.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 3 additions & 1 deletion packages/ui-react/tests/render/ask-user-rank.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
4 changes: 3 additions & 1 deletion packages/ui-react/tests/render/message-source.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion packages/ui-react/tests/render/streaming-bench.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion packages/ui-react/tests/render/turn-failure.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion packages/ui-react/tests/session-demux.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion scripts/source-browser-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const helperConsumers:Record<string,string>={
// 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=[
{
Expand Down
Loading