diff --git a/ui/src/archie/App.vue b/ui/src/archie/App.vue index 87fcc823a..ca2a40e98 100644 --- a/ui/src/archie/App.vue +++ b/ui/src/archie/App.vue @@ -1,16 +1,23 @@ diff --git a/ui/src/archie/ComposerView.vue b/ui/src/archie/ComposerView.vue index 181dfba67..80401cee5 100644 --- a/ui/src/archie/ComposerView.vue +++ b/ui/src/archie/ComposerView.vue @@ -1,287 +1,25 @@ diff --git a/ui/src/archie/api.ts b/ui/src/archie/api.ts index af38405ce..67663e369 100644 --- a/ui/src/archie/api.ts +++ b/ui/src/archie/api.ts @@ -688,3 +688,120 @@ export async function* composerStream(signal: AbortSignal, onConnected?: () => P reader.releaseLock(); } } + +/** One conversation, as GET /api/chat/sessions lists it. */ +export interface ChatSession { + session_id: string; + title: string; + created_at: string; + updated_at: string; +} + +export interface ChatSessions { + sessions: ChatSession[]; + active_model: string; + model_error?: string; +} + +/** A tool the agent called and what came of it. */ +export interface ChatToolCall { + id: string; + name: string; + parameters: string; + text: string; + failed?: boolean; + duration_ms: number; + text_offset: number; +} + +/** An action judgement held and put to people. */ +export interface ChatApproval { + request_id: string; + action: string; + summary: string; + level: string; + deadline: string; +} + +/** What became of a held action once its approval was answered. */ +export interface ChatActionDone { + request_id: string; + state: "succeeded" | "failed" | "unknown" | "denied" | "expired"; + result?: string; +} + +export interface ChatNavigation { + path: string; + label: string; +} + +/** One message and Archie's reply, with what the turn did. */ +export interface ChatTurn { + id: string; + session_id: string; + seq: number; + state: "queued" | "running" | "succeeded" | "failed" | "cancelled"; + text: string; + page?: string; + page_label?: string; + reply: string; + reasoning?: string; + error?: string; + tool_calls: ChatToolCall[]; + approvals: ChatApproval[]; + actions: ChatActionDone[]; + navigate: ChatNavigation[]; + created_at: string; + finished_at?: string; +} + +/** One recorded event of a turn, as its stream sends it. */ +export type ChatEvent = { seq: number } & ( + | { type: "reasoning" | "delta" | "done" | "error" | "cancelled"; text: string } + | ({ type: "tool" } & ChatToolCall) + | ({ type: "navigate" } & ChatNavigation) + | ({ type: "approval" } & ChatApproval) + | ({ type: "action" } & ChatActionDone) +); + +const sessionPath = (id: string) => `/api/chat/sessions/${encodeURIComponent(id)}`; +const turnPath = (id: string) => `/api/chat/turns/${encodeURIComponent(id)}`; + +export const chatSessions = (signal?: AbortSignal) => get("/api/chat/sessions", signal); +export const createChatSession = () => send("POST", "/api/chat/sessions"); +export const renameChatSession = (id: string, title: string) => send("PATCH", sessionPath(id), { title }); +export const deleteChatSession = (id: string) => send("DELETE", sessionPath(id)); +export const chatTurns = (id: string, signal?: AbortSignal) => get(`${sessionPath(id)}/turns`, signal); +export const chatTurn = (id: string, signal?: AbortSignal) => get(turnPath(id), signal); +export const sendChatTurn = (sessionID: string, text: string, page?: { page: string; page_label: string }) => + send("POST", `${sessionPath(sessionID)}/turns`, { text, ...page }); +export const cancelChatTurn = (id: string) => send("POST", `${turnPath(id)}/cancel`); + +/** + * Yields a turn's recorded events after the cursor until the turn ends. The + * stream ends after a done, error or cancelled event; a dropped connection + * ends it early, and the caller reconnects from the last seq it saw. + */ +export async function* chatTurnEvents(id: string, after: number, signal: AbortSignal): AsyncGenerator { + const res = await request(`${turnPath(id)}/events?after=${after}`, signal); + if (!res.body) return; + const reader = res.body.pipeThrough(new TextDecoderStream()).getReader(); + let buffered = ""; + try { + for (;;) { + const { value, done } = await reader.read(); + if (done) return; + buffered += value; + let end: number; + while ((end = buffered.indexOf("\n\n")) >= 0) { + const frame = buffered.slice(0, end); + buffered = buffered.slice(end + 2); + const data = frame.split("\n").find((line) => line.startsWith("data: ")); + if (data) yield JSON.parse(data.slice(6)) as ChatEvent; + } + } + } finally { + void reader.cancel().catch(() => undefined); + reader.releaseLock(); + } +} diff --git a/ui/src/archie/chat/ChatApprovalCard.vue b/ui/src/archie/chat/ChatApprovalCard.vue new file mode 100644 index 000000000..7eddc085b --- /dev/null +++ b/ui/src/archie/chat/ChatApprovalCard.vue @@ -0,0 +1,94 @@ + + + diff --git a/ui/src/archie/chat/ChatBar.vue b/ui/src/archie/chat/ChatBar.vue new file mode 100644 index 000000000..5d4ffd356 --- /dev/null +++ b/ui/src/archie/chat/ChatBar.vue @@ -0,0 +1,59 @@ + + + diff --git a/ui/src/archie/chat/ChatBubble.vue b/ui/src/archie/chat/ChatBubble.vue new file mode 100644 index 000000000..565213d8b --- /dev/null +++ b/ui/src/archie/chat/ChatBubble.vue @@ -0,0 +1,118 @@ + + + diff --git a/ui/src/archie/chat/ChatComposer.vue b/ui/src/archie/chat/ChatComposer.vue new file mode 100644 index 000000000..76746b708 --- /dev/null +++ b/ui/src/archie/chat/ChatComposer.vue @@ -0,0 +1,241 @@ + + +