Skip to content

Commit 6ae3c47

Browse files
committed
refactor(chat): split ChatPage into domain hooks under pages/chat
ChatPage.tsx (5937 lines) is now a 1772-line cross-domain wiring layer; all logic moved verbatim into per-domain modules: - queue/useChatTurnQueue: local queue, WebUI remote queue protocol, snapshot publishing - runtime/useSendChatTurn: the full send pipeline (overrides, large-paste import, gateway bridge, title job, abort/error commit, agent/text turns) - gateway/useGatewayRuntimeSnapshots + useGatewayBridgeReadiness + useGatewayStatus: run mirroring, edit_resend rebase/hydration readiness, connection status - history/useSharedHistory + useBranchConversation - workspace/useWorkspaceProjects (+Removal, +ProjectTerminals, +Overlays) - runtime/useChatModelSelection, composer/useComposerDraftCache, hooks/useNotifyToasts, hooks/useTauriFileDrop - pure modules: composerDraftText, providerRuntimeConfig, gatewayRuntimeStatusModel, workspaceProjectsModel, chatPageUtils; tauriTunnelClient moved to lib/tunnels - JSX extractions: WorkspaceOverlayHost (lazy Monaco defs move along), ChatFileDropOverlay Behavior-preserving: tsc clean, 1113 frontend tests green, mirror check passes; verified by mechanical body-hash diff against the old file plus multi-lens adversarial review (instance identity, escaping closures, effect ordering, JSX prop parity). Also un-ignores pages/chat/workspace/ from the bare `workspace` gitignore rule so the new directory is actually tracked.
1 parent 155d0eb commit 6ae3c47

26 files changed

Lines changed: 6053 additions & 4678 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ lerna-debug.log*
1515
workspace
1616
!crates/agent-gui/src-tauri/src/commands/workspace/
1717
!crates/agent-gui/src-tauri/src/commands/workspace/**
18+
!crates/agent-gui/src/pages/chat/workspace/
19+
!crates/agent-gui/src/pages/chat/workspace/**
1820
cert/
1921
node_modules
2022
dist
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { invoke } from "@tauri-apps/api/core";
2+
import { listen } from "@tauri-apps/api/event";
3+
import type {
4+
LocalTunnelClient,
5+
TunnelCreateInput,
6+
TunnelStateSnapshot,
7+
TunnelUpdateInput,
8+
} from "./constants";
9+
10+
export function createTauriTunnelClient(): LocalTunnelClient {
11+
const listeners = new Set<(snapshot: TunnelStateSnapshot) => void>();
12+
let unlistenPromise: Promise<() => void> | null = null;
13+
const normalizeSnapshot = (payload: unknown): TunnelStateSnapshot => {
14+
const raw = (payload ?? {}) as Partial<TunnelStateSnapshot>;
15+
return {
16+
revision: raw.revision ?? 0,
17+
agentOnline: raw.agentOnline === true,
18+
relay: raw.relay ?? null,
19+
tunnels: raw.tunnels ?? [],
20+
gatewayUnsupported: raw.gatewayUnsupported === true,
21+
};
22+
};
23+
return {
24+
subscribeTunnelState: (listener) => {
25+
listeners.add(listener);
26+
if (!unlistenPromise) {
27+
unlistenPromise = listen<TunnelStateSnapshot>("gateway:tunnel-state", (event) => {
28+
const snapshot = normalizeSnapshot(event.payload);
29+
for (const subscriber of [...listeners]) {
30+
subscriber(snapshot);
31+
}
32+
});
33+
}
34+
void invoke<TunnelStateSnapshot>("gateway_tunnel_state")
35+
.then((payload) => {
36+
if (listeners.has(listener)) {
37+
listener(normalizeSnapshot(payload));
38+
}
39+
})
40+
.catch(() => {});
41+
return () => {
42+
listeners.delete(listener);
43+
if (listeners.size === 0 && unlistenPromise) {
44+
const pending = unlistenPromise;
45+
unlistenPromise = null;
46+
void pending.then((unlisten) => unlisten()).catch(() => {});
47+
}
48+
};
49+
},
50+
createTunnel: (input: TunnelCreateInput) => invoke<void>("gateway_tunnel_create", { input }),
51+
updateTunnel: (input: TunnelUpdateInput) => invoke<void>("gateway_tunnel_update", { input }),
52+
closeTunnel: (id: string) => invoke<void>("gateway_tunnel_close", { tunnel_id: id }),
53+
checkTunnel: (id?: string) => invoke<void>("gateway_tunnel_check", { tunnel_id: id }),
54+
};
55+
}

0 commit comments

Comments
 (0)