Skip to content

Commit d3d096c

Browse files
Refactor chat into composable workspace shell
- Add workspace document storage and store tests - Route terminal and command-palette actions through workspace surfaces - Update chat layout, sidebar, and thread terminal handling
1 parent c9b07d6 commit d3d096c

20 files changed

Lines changed: 3741 additions & 485 deletions

‎apps/web/src/clientPersistenceStorage.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,54 @@ describe("clientPersistenceStorage", () => {
7777
],
7878
});
7979
});
80+
81+
it("reads and writes workspace documents as JSON blobs", async () => {
82+
const testWindow = getTestWindow();
83+
const {
84+
WORKSPACE_DOCUMENT_STORAGE_KEY,
85+
readBrowserWorkspaceDocument,
86+
writeBrowserWorkspaceDocument,
87+
} = await import("./clientPersistenceStorage");
88+
const workspaceDocument = {
89+
version: 1 as const,
90+
layoutEngine: "split" as const,
91+
rootNodeId: "node-1",
92+
nodesById: {
93+
"node-1": {
94+
id: "node-1",
95+
kind: "window" as const,
96+
windowId: "window-1",
97+
},
98+
},
99+
windowsById: {
100+
"window-1": {
101+
id: "window-1",
102+
tabIds: ["surface-1"],
103+
activeTabId: "surface-1",
104+
},
105+
},
106+
surfacesById: {
107+
"surface-1": {
108+
id: "surface-1",
109+
kind: "thread" as const,
110+
input: {
111+
scope: "server" as const,
112+
threadRef: {
113+
environmentId: testEnvironmentId,
114+
threadId: "thread-1",
115+
},
116+
},
117+
},
118+
},
119+
focusedWindowId: "window-1",
120+
mobileActiveWindowId: "window-1",
121+
};
122+
123+
writeBrowserWorkspaceDocument(workspaceDocument);
124+
125+
expect(readBrowserWorkspaceDocument<typeof workspaceDocument>()).toEqual(workspaceDocument);
126+
expect(JSON.parse(testWindow.localStorage.getItem(WORKSPACE_DOCUMENT_STORAGE_KEY)!)).toEqual(
127+
workspaceDocument,
128+
);
129+
});
80130
});

‎apps/web/src/clientPersistenceStorage.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { getLocalStorageItem, setLocalStorageItem } from "./hooks/useLocalStorag
1111

1212
export const CLIENT_SETTINGS_STORAGE_KEY = "t3code:client-settings:v1";
1313
export const SAVED_ENVIRONMENT_REGISTRY_STORAGE_KEY = "t3code:saved-environment-registry:v1";
14+
export const WORKSPACE_DOCUMENT_STORAGE_KEY = "t3code:workspace-document:v1";
1415

1516
const BrowserSavedEnvironmentRecordSchema = Schema.Struct({
1617
environmentId: EnvironmentId,
@@ -34,6 +35,34 @@ function hasWindow(): boolean {
3435
return typeof window !== "undefined";
3536
}
3637

38+
function readBrowserJsonDocument<T>(storageKey: string): T | null {
39+
if (!hasWindow()) {
40+
return null;
41+
}
42+
43+
try {
44+
const raw = window.localStorage.getItem(storageKey);
45+
if (!raw) {
46+
return null;
47+
}
48+
return JSON.parse(raw) as T;
49+
} catch {
50+
return null;
51+
}
52+
}
53+
54+
function writeBrowserJsonDocument<T>(storageKey: string, document: T): void {
55+
if (!hasWindow()) {
56+
return;
57+
}
58+
59+
try {
60+
window.localStorage.setItem(storageKey, JSON.stringify(document));
61+
} catch {
62+
// Ignore quota/storage errors to avoid breaking the app.
63+
}
64+
}
65+
3766
function toPersistedSavedEnvironmentRecord(
3867
record: PersistedSavedEnvironmentRecord,
3968
): PersistedSavedEnvironmentRecord {
@@ -192,3 +221,11 @@ export function removeBrowserSavedEnvironmentSecret(environmentId: EnvironmentId
192221
}),
193222
});
194223
}
224+
225+
export function readBrowserWorkspaceDocument<T>(): T | null {
226+
return readBrowserJsonDocument<T>(WORKSPACE_DOCUMENT_STORAGE_KEY);
227+
}
228+
229+
export function writeBrowserWorkspaceDocument<T>(document: T): void {
230+
writeBrowserJsonDocument(WORKSPACE_DOCUMENT_STORAGE_KEY, document);
231+
}
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
import { create } from "zustand";
22

3+
export interface CommandPaletteWorkspaceTarget {
4+
disposition: "split-right" | "split-down";
5+
}
6+
37
interface CommandPaletteStore {
48
open: boolean;
9+
workspaceTarget: CommandPaletteWorkspaceTarget | null;
510
setOpen: (open: boolean) => void;
611
toggleOpen: () => void;
12+
openWorkspaceTarget: (target: CommandPaletteWorkspaceTarget) => void;
13+
clearWorkspaceTarget: () => void;
714
}
815

916
export const useCommandPaletteStore = create<CommandPaletteStore>((set) => ({
1017
open: false,
11-
setOpen: (open) => set({ open }),
12-
toggleOpen: () => set((state) => ({ open: !state.open })),
18+
workspaceTarget: null,
19+
setOpen: (open) => set({ open, ...(open ? {} : { workspaceTarget: null }) }),
20+
toggleOpen: () =>
21+
set((state) => ({
22+
open: !state.open,
23+
...(!state.open ? {} : { workspaceTarget: null }),
24+
})),
25+
openWorkspaceTarget: (target) => set({ open: true, workspaceTarget: target }),
26+
clearWorkspaceTarget: () => set({ workspaceTarget: null }),
1327
}));

0 commit comments

Comments
 (0)