| .. | .. |
|---|
| 6 | 6 | useRef, |
|---|
| 7 | 7 | useState, |
|---|
| 8 | 8 | } from "react"; |
|---|
| 9 | | -import { Message, WsIncoming, WsSession } from "../types"; |
|---|
| 9 | +import { Message, WsIncoming, WsSession, PaiProject } from "../types"; |
|---|
| 10 | 10 | import { useConnection } from "./ConnectionContext"; |
|---|
| 11 | 11 | import { playAudio, encodeAudioToBase64, saveBase64Audio, canAutoplay } from "../services/audio"; |
|---|
| 12 | 12 | import { requestNotificationPermissions, notifyIncomingMessage } from "../services/notifications"; |
|---|
| .. | .. |
|---|
| 128 | 128 | switchSession: (sessionId: string) => void; |
|---|
| 129 | 129 | renameSession: (sessionId: string, name: string) => void; |
|---|
| 130 | 130 | removeSession: (sessionId: string) => void; |
|---|
| 131 | | - createSession: () => void; |
|---|
| 131 | + createSession: (opts?: { project?: string; path?: string }) => void; |
|---|
| 132 | + fetchProjects: () => void; |
|---|
| 133 | + projects: PaiProject[]; |
|---|
| 132 | 134 | unreadCounts: Record<string, number>; |
|---|
| 133 | 135 | latestScreenshot: string | null; |
|---|
| 134 | 136 | requestScreenshot: () => void; |
|---|
| .. | .. |
|---|
| 151 | 153 | const [unreadCounts, setUnreadCounts] = useState<Record<string, number>>({}); |
|---|
| 152 | 154 | // Typing indicator from server |
|---|
| 153 | 155 | const [isTyping, setIsTyping] = useState(false); |
|---|
| 156 | + // PAI projects list |
|---|
| 157 | + const [projects, setProjects] = useState<PaiProject[]>([]); |
|---|
| 154 | 158 | |
|---|
| 155 | 159 | const { |
|---|
| 156 | 160 | status, |
|---|
| .. | .. |
|---|
| 386 | 390 | // Connection status update — ignore for now |
|---|
| 387 | 391 | break; |
|---|
| 388 | 392 | } |
|---|
| 393 | + case "projects": { |
|---|
| 394 | + setProjects(data.projects ?? []); |
|---|
| 395 | + break; |
|---|
| 396 | + } |
|---|
| 389 | 397 | case "error": { |
|---|
| 390 | 398 | const msg: Message = { |
|---|
| 391 | 399 | id: generateId(), |
|---|
| .. | .. |
|---|
| 534 | 542 | [sendCommand] |
|---|
| 535 | 543 | ); |
|---|
| 536 | 544 | |
|---|
| 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"); |
|---|
| 539 | 551 | }, [sendCommand]); |
|---|
| 540 | 552 | |
|---|
| 541 | 553 | // --- Screenshot / navigation --- |
|---|
| .. | .. |
|---|
| 567 | 579 | renameSession, |
|---|
| 568 | 580 | removeSession, |
|---|
| 569 | 581 | createSession, |
|---|
| 582 | + fetchProjects, |
|---|
| 583 | + projects, |
|---|
| 570 | 584 | unreadCounts, |
|---|
| 571 | 585 | latestScreenshot, |
|---|
| 572 | 586 | requestScreenshot, |
|---|