fix(web): connect the chat to the daemon end-to-end
- ws auth frame now carries the token top-level (docs §3.3); daemon accepts payload.token too - entries route accepts workspaceId/sessionFile so disk-only sessions page history - chat registers session metadata and pages history for non-live sessions - e2e asserts a real ASSISTANT reply (PONG) and waits up to 180s - visual.sh: real daemon + pairing + Playwright screenshots of the four pages
This commit is contained in:
1 parent
721661177c
commit
854d6d2997
8 files changed
+148
-17
No files matched your search
@@ -15,6 +15,7 @@ import {
|
||||
normalizeSessionsPayload,
|
||||
normalizeSnapshotState,
|
||||
} from "./session-state";
|
||||
import { setSessionMeta } from "./history";
|
||||
import { useChatStore } from "./store";
|
||||
|
||||
export const EMPTY_SESSIONS: SessionState[] = [];
|
||||
@@ -142,6 +143,15 @@ export function useChatSessions(workspaceId: string | undefined, enabled: boolea
|
||||
|
||||
useEffect(() => {
|
||||
if (!workspaceId || !query.data) return;
|
||||
const raw = query.data as { sessions?: Array<{ sessionId?: unknown; sessionFile?: unknown }> } | undefined;
|
||||
for (const row of raw?.sessions ?? []) {
|
||||
if (typeof row?.sessionId === "string") {
|
||||
setSessionMeta(row.sessionId, {
|
||||
workspaceId,
|
||||
sessionFile: typeof row.sessionFile === "string" ? row.sessionFile : undefined,
|
||||
});
|
||||
}
|
||||
}
|
||||
const current = useSessionsStore.getState();
|
||||
const existing = current.byWorkspace[workspaceId] ?? [];
|
||||
const next = normalizeSessionsPayload(query.data, workspaceId, existing);
|
||||
|
||||
@@ -12,7 +12,21 @@ export interface FetchedPage {
|
||||
cursor: { before?: string; hasMore: boolean };
|
||||
}
|
||||
|
||||
/** `GET /api/v1/sessions/:sid/entries?before=&limit=` → raw pi entries + cursor. */
|
||||
/**
|
||||
* Session metadata needed to page a session that is not live in an instance
|
||||
* (disk-only rows): the daemon routes by workspace and the plugin reads the file.
|
||||
* Populated from the sessions list, keyed by session id.
|
||||
*/
|
||||
const sessionMeta = new Map<string, { workspaceId?: string; sessionFile?: string }>();
|
||||
|
||||
export function setSessionMeta(
|
||||
sessionId: string,
|
||||
meta: { workspaceId?: string; sessionFile?: string },
|
||||
): void {
|
||||
sessionMeta.set(sessionId, { ...sessionMeta.get(sessionId), ...meta });
|
||||
}
|
||||
|
||||
/** `GET /api/v1/sessions/:sid/entries?before=&limit=&workspaceId=&sessionFile=` → raw pi entries + cursor. */
|
||||
export async function fetchEntriesPage(
|
||||
sessionId: string,
|
||||
before?: string,
|
||||
@@ -21,6 +35,9 @@ export async function fetchEntriesPage(
|
||||
): Promise<FetchedPage> {
|
||||
const query = new URLSearchParams({ limit: String(limit) });
|
||||
if (before) query.set("before", before);
|
||||
const meta = sessionMeta.get(sessionId);
|
||||
if (meta?.workspaceId) query.set("workspaceId", meta.workspaceId);
|
||||
if (meta?.sessionFile) query.set("sessionFile", meta.sessionFile);
|
||||
const raw = await apiRequest<unknown>(
|
||||
`/api/v1/sessions/${encodeURIComponent(sessionId)}/entries?${query.toString()}`,
|
||||
{ signal },
|
||||
|
||||
+1
-1
@@ -216,7 +216,7 @@ export class PiWsClient {
|
||||
socket.onopen = () => {
|
||||
if (this.socket !== socket) return;
|
||||
this.setState("authenticating");
|
||||
this.send({ v: 1, type: AUTH_FRAME_TYPE, payload: { token: this.token ?? undefined } });
|
||||
this.send({ v: 1, type: AUTH_FRAME_TYPE, token: this.token ?? undefined });
|
||||
this.authTimer = setTimeout(() => {
|
||||
if (this.state !== "authenticating" || this.socket !== socket) return;
|
||||
this.handlers.onError?.(new Error("WebSocket auth timed out"));
|
||||
|
||||
Reference in new issue
Block a user