Matthias Nott
2026-03-07 93670c15d9b6542b24078c9cef7b09e09fc8cb47
contexts/ChatContext.tsx
....@@ -6,7 +6,7 @@
66 useRef,
77 useState,
88 } from "react";
9
-import { Message, WsIncoming, WsSession } from "../types";
9
+import { Message, WsIncoming, WsSession, PaiProject } from "../types";
1010 import { useConnection } from "./ConnectionContext";
1111 import { playAudio, encodeAudioToBase64, saveBase64Audio, canAutoplay } from "../services/audio";
1212 import { requestNotificationPermissions, notifyIncomingMessage } from "../services/notifications";
....@@ -128,7 +128,9 @@
128128 switchSession: (sessionId: string) => void;
129129 renameSession: (sessionId: string, name: string) => void;
130130 removeSession: (sessionId: string) => void;
131
- createSession: () => void;
131
+ createSession: (opts?: { project?: string; path?: string }) => void;
132
+ fetchProjects: () => void;
133
+ projects: PaiProject[];
132134 unreadCounts: Record<string, number>;
133135 latestScreenshot: string | null;
134136 requestScreenshot: () => void;
....@@ -151,6 +153,8 @@
151153 const [unreadCounts, setUnreadCounts] = useState<Record<string, number>>({});
152154 // Typing indicator from server
153155 const [isTyping, setIsTyping] = useState(false);
156
+ // PAI projects list
157
+ const [projects, setProjects] = useState<PaiProject[]>([]);
154158
155159 const {
156160 status,
....@@ -386,6 +390,10 @@
386390 // Connection status update — ignore for now
387391 break;
388392 }
393
+ case "projects": {
394
+ setProjects(data.projects ?? []);
395
+ break;
396
+ }
389397 case "error": {
390398 const msg: Message = {
391399 id: generateId(),
....@@ -534,8 +542,12 @@
534542 [sendCommand]
535543 );
536544
537
- const createSession = useCallback(() => {
538
- sendCommand("create");
545
+ const createSession = useCallback((opts?: { project?: string; path?: string }) => {
546
+ sendCommand("create", opts ?? {});
547
+ }, [sendCommand]);
548
+
549
+ const fetchProjects = useCallback(() => {
550
+ sendCommand("projects");
539551 }, [sendCommand]);
540552
541553 // --- Screenshot / navigation ---
....@@ -567,6 +579,8 @@
567579 renameSession,
568580 removeSession,
569581 createSession,
582
+ fetchProjects,
583
+ projects,
570584 unreadCounts,
571585 latestScreenshot,
572586 requestScreenshot,