Skip to content

Commit cf771de

Browse files
committed
SSR for projects
1 parent 64de7ee commit cf771de

File tree

10 files changed

+418
-421
lines changed

10 files changed

+418
-421
lines changed

.vscode/launch.template.jsonc

Lines changed: 372 additions & 395 deletions
Large diffs are not rendered by default.

backend/scripts/dev_run_background_jobs.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ def run_jobs() -> None:
7272
"--queues=docprocessing",
7373
]
7474

75-
cmd_worker_user_files_indexing = [
75+
cmd_worker_user_files = [
7676
"celery",
7777
"-A",
78-
"onyx.background.celery.versioned_apps.docfetching",
78+
"onyx.background.celery.versioned_apps.user_file_processing",
7979
"worker",
8080
"--pool=threads",
8181
"--concurrency=1",
8282
"--prefetch-multiplier=1",
8383
"--loglevel=INFO",
84-
"--hostname=user_files_indexing@%n",
85-
"--queues=user_files_indexing",
84+
"--hostname=user_file_processing@%n",
85+
"--queues=user_file_processing,user_file_project_sync",
8686
]
8787

8888
cmd_worker_monitoring = [
@@ -152,8 +152,8 @@ def run_jobs() -> None:
152152
text=True,
153153
)
154154

155-
worker_user_files_indexing_process = subprocess.Popen(
156-
cmd_worker_user_files_indexing,
155+
worker_user_file_process = subprocess.Popen(
156+
cmd_worker_user_files,
157157
stdout=subprocess.PIPE,
158158
stderr=subprocess.STDOUT,
159159
text=True,
@@ -197,9 +197,9 @@ def run_jobs() -> None:
197197
worker_docprocessing_thread = threading.Thread(
198198
target=monitor_process, args=("DOCPROCESSING", worker_docprocessing_process)
199199
)
200-
worker_user_files_indexing_thread = threading.Thread(
200+
worker_user_file_thread = threading.Thread(
201201
target=monitor_process,
202-
args=("USER_FILES_INDEX", worker_user_files_indexing_process),
202+
args=("USER_FILE_PROCESSING", worker_user_file_process),
203203
)
204204
worker_monitoring_thread = threading.Thread(
205205
target=monitor_process, args=("MONITORING", worker_monitoring_process)
@@ -216,7 +216,7 @@ def run_jobs() -> None:
216216
worker_light_thread.start()
217217
worker_heavy_thread.start()
218218
worker_docprocessing_thread.start()
219-
worker_user_files_indexing_thread.start()
219+
worker_user_file_thread.start()
220220
worker_monitoring_thread.start()
221221
worker_kg_processing_thread.start()
222222
worker_docfetching_thread.start()
@@ -226,7 +226,7 @@ def run_jobs() -> None:
226226
worker_light_thread.join()
227227
worker_heavy_thread.join()
228228
worker_docprocessing_thread.join()
229-
worker_user_files_indexing_thread.join()
229+
worker_user_file_thread.join()
230230
worker_monitoring_thread.join()
231231
worker_kg_processing_thread.join()
232232
worker_docfetching_thread.join()

web/src/app/chat/WrappedChat.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useChatContext } from "@/components/context/ChatContext";
44
import { ChatPage } from "./components/ChatPage";
5+
import { ProjectsProvider } from "./projects/ProjectsContext";
56
import { useCallback, useState } from "react";
67

78
export default function ChatLayout({
@@ -13,7 +14,7 @@ export default function ChatLayout({
1314
// we don't want to show the sidebar by default when the user opens the side panel
1415
defaultSidebarOff?: boolean;
1516
}) {
16-
const { sidebarInitiallyVisible } = useChatContext();
17+
const { sidebarInitiallyVisible, projects } = useChatContext();
1718

1819
const [sidebarVisible, setSidebarVisible] = useState(
1920
(sidebarInitiallyVisible && !defaultSidebarOff) ?? false
@@ -26,14 +27,14 @@ export default function ChatLayout({
2627
}, []);
2728

2829
return (
29-
<>
30+
<ProjectsProvider initialProjects={projects}>
3031
<div className="overscroll-y-contain overflow-y-scroll overscroll-contain left-0 top-0 w-full h-svh">
3132
<ChatPage
3233
toggle={toggle}
3334
sidebarVisible={sidebarVisible}
3435
firstMessage={firstMessage}
3536
/>
3637
</div>
37-
</>
38+
</ProjectsProvider>
3839
);
3940
}

web/src/app/chat/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default async function Layout({
3636
ccPairs,
3737
inputPrompts,
3838
proSearchToggled,
39+
projects,
3940
} = data;
4041

4142
return (
@@ -56,6 +57,7 @@ export default async function Layout({
5657
availableTools,
5758
shouldShowWelcomeModal,
5859
defaultAssistantId,
60+
projects,
5961
}}
6062
>
6163
{children}

web/src/app/chat/page.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { SEARCH_PARAMS } from "@/lib/extension/constants";
22
import ChatLayout from "./WrappedChat";
3-
import { ProjectsProvider } from "./projects/ProjectsContext";
43

54
export default async function Page(props: {
65
searchParams: Promise<{ [key: string]: string }>;
@@ -11,11 +10,9 @@ export default async function Page(props: {
1110
searchParams[SEARCH_PARAMS.DEFAULT_SIDEBAR_OFF] === "true";
1211

1312
return (
14-
<ProjectsProvider>
15-
<ChatLayout
16-
firstMessage={firstMessage}
17-
defaultSidebarOff={defaultSidebarOff}
18-
/>
19-
</ProjectsProvider>
13+
<ChatLayout
14+
firstMessage={firstMessage}
15+
defaultSidebarOff={defaultSidebarOff}
16+
/>
2017
);
2118
}

web/src/app/chat/projects/ProjectsContext.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ const ProjectsContext = createContext<ProjectsContextType | undefined>(
7272

7373
interface ProjectsProviderProps {
7474
children: ReactNode;
75+
initialProjects?: Project[];
7576
}
7677

7778
export const ProjectsProvider: React.FC<ProjectsProviderProps> = ({
7879
children,
80+
initialProjects = [],
7981
}) => {
80-
const [projects, setProjects] = useState<Project[]>([]);
82+
const [projects, setProjects] = useState<Project[]>(initialProjects);
8183
const [recentFiles, setRecentFiles] = useState<ProjectFile[]>([]);
8284
const [currentProjectDetails, setCurrentProjectDetails] =
8385
useState<ProjectDetails | null>(null);
@@ -261,17 +263,17 @@ export const ProjectsProvider: React.FC<ProjectsProviderProps> = ({
261263
);
262264

263265
useEffect(() => {
264-
// Initial load
266+
// Initial load - only fetch recent files since projects come from props
265267
setIsLoading(true);
266-
Promise.all([fetchProjects(), getRecentFiles()])
267-
.then(([, recent]) => {
268+
getRecentFiles()
269+
.then((recent) => {
268270
setRecentFiles(recent);
269271
})
270272
.catch(() => {
271273
// errors captured in individual calls
272274
})
273275
.finally(() => setIsLoading(false));
274-
}, [fetchProjects, getRecentFiles]);
276+
}, [getRecentFiles]);
275277

276278
useEffect(() => {
277279
if (currentProjectId) {

web/src/app/ee/assistants/stats/[id]/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default async function GalleryPage(props: {
3535
defaultAssistantId,
3636
inputPrompts,
3737
proSearchToggled,
38+
projects,
3839
} = data;
3940

4041
return (
@@ -54,6 +55,7 @@ export default async function GalleryPage(props: {
5455
llmProviders,
5556
shouldShowWelcomeModal,
5657
defaultAssistantId,
58+
projects,
5759
}}
5860
>
5961
{shouldShowWelcomeModal && (

web/src/components/admin/Layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export async function Layout({ children }: { children: React.ReactNode }) {
6262
inputPrompts,
6363
proSearchToggled,
6464
availableTools,
65+
projects,
6566
} = data;
6667

6768
return (
@@ -81,6 +82,7 @@ export async function Layout({ children }: { children: React.ReactNode }) {
8182
llmProviders,
8283
shouldShowWelcomeModal,
8384
defaultAssistantId,
85+
projects,
8486
}}
8587
>
8688
<ClientLayout

web/src/components/context/ChatContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { LLMProviderDescriptor } from "@/app/admin/configuration/llm/interfaces"
1212
import { useSearchParams } from "next/navigation";
1313
import { useRouter } from "next/navigation";
1414
import { ToolSnapshot } from "@/lib/tools/interfaces";
15+
import { Project } from "@/app/chat/projects/projectsService";
1516

1617
interface ChatContextProps {
1718
chatSessions: ChatSession[];
@@ -33,6 +34,7 @@ interface ChatContextProps {
3334
refreshInputPrompts: () => Promise<void>;
3435
inputPrompts: InputPrompt[];
3536
proSearchToggled: boolean;
37+
projects: Project[];
3638
}
3739

3840
const ChatContext = createContext<ChatContextProps | undefined>(undefined);

web/src/lib/chat/fetchChatData.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
} from "../constants";
3131
import { ToolSnapshot } from "../tools/interfaces";
3232
import { fetchToolsSS } from "../tools/fetchTools";
33+
import { Project } from "@/app/chat/projects/projectsService";
3334

3435
interface FetchChatDataResult {
3536
user: User | null;
@@ -46,6 +47,7 @@ interface FetchChatDataResult {
4647
shouldShowWelcomeModal: boolean;
4748
inputPrompts: InputPrompt[];
4849
proSearchToggled: boolean;
50+
projects: Project[];
4951
}
5052

5153
export async function fetchChatData(searchParams: {
@@ -62,6 +64,7 @@ export async function fetchChatData(searchParams: {
6264
fetchLLMProvidersSS(),
6365
fetchSS("/input_prompt?include_public=true"),
6466
fetchToolsSS(),
67+
fetchSS("/user/projects/"),
6568
];
6669

6770
let results: (
@@ -75,7 +78,8 @@ export async function fetchChatData(searchParams: {
7578
| null
7679
| InputPrompt[]
7780
| ToolSnapshot[]
78-
)[] = [null, null, null, null, null, null, null, null, null, null];
81+
| Project[]
82+
)[] = [null, null, null, null, null, null, null, null, null, null, null];
7983
try {
8084
results = await Promise.all(tasks);
8185
} catch (e) {
@@ -101,6 +105,13 @@ export async function fetchChatData(searchParams: {
101105

102106
const availableTools = (results[8] || []) as ToolSnapshot[];
103107

108+
let projects: Project[] = [];
109+
if (results[9] instanceof Response && results[9].ok) {
110+
projects = await results[9].json();
111+
} else {
112+
console.log("Failed to fetch projects");
113+
}
114+
104115
const authDisabled = authTypeMetadata?.authType === "disabled";
105116

106117
// TODO Validate need
@@ -241,5 +252,6 @@ export async function fetchChatData(searchParams: {
241252
shouldShowWelcomeModal,
242253
inputPrompts,
243254
proSearchToggled,
255+
projects,
244256
};
245257
}

0 commit comments

Comments
 (0)