From 731417ab487dceb84af7157c9b35f88cd893afb4 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Fri, 20 Nov 2026 01:45:35 +1100 Subject: [PATCH] feat(ui/chat): run the Vue chat on the archie binary (#2023) Sessions, turns, streamed replies, thinking and tool cards, held-action approvals and resume now use modules/chat; /api/stream forwards the chat topic. Sub-features the binary can't back yet stay hidden. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- internal/app/archie/api.go | 6 +- internal/app/archie/run.go | 1 + modules/dashboard/stream.go | 84 ++++-- modules/governance/accounts_api.go | 4 +- ui/src/App.vue | 4 +- ui/src/chat/ChatAskCard.vue | 10 +- ui/src/chat/ChatSessionActions.vue | 40 ++- ui/src/chat/ChatSettings.vue | 4 + ui/src/chat/ChatTranscript.vue | 3 + ui/src/chat/state.ts | 411 +++++++++++++++++------------ ui/src/chat/turn.ts | 2 + ui/src/copy/errors/chat.ts | 2 + ui/src/lib/api.ts | 87 ++++-- ui/test/chat-more-menu.test.ts | 68 +++-- ui/test/chat-thinking.test.ts | 22 +- 15 files changed, 481 insertions(+), 267 deletions(-) diff --git a/internal/app/archie/api.go b/internal/app/archie/api.go index 5a08adb3c..bce4c83db 100644 --- a/internal/app/archie/api.go +++ b/internal/app/archie/api.go @@ -7,6 +7,7 @@ import ( "github.com/samcharles93/archie-core/internal/buildinfo" "github.com/samcharles93/archie-core/internal/platform/httpapi" + "github.com/samcharles93/archie-core/internal/platform/hub" "github.com/samcharles93/archie-core/modules/approvals" "github.com/samcharles93/archie-core/modules/chat" "github.com/samcharles93/archie-core/modules/connectors" @@ -34,6 +35,7 @@ type apiModules struct { engine *runs.Engine chat *chat.Module drafts *drafts.Module + live *hub.Hub } func (m apiModules) register(api huma.API) { @@ -50,7 +52,7 @@ func (m apiModules) register(api huma.API) { m.engine.Register(api, orgID, m.hear, m.judge, m.allow) m.drafts.Register(api) m.chat.Register(api) - dashboard.Register(api) + dashboard.Register(api, m.live) } // Document returns the API's OpenAPI document as YAML. It makes the same @@ -63,7 +65,7 @@ func Document() ([]byte, error) { settings: settings, conns: &connectors.Module{}, system: &system.Module{}, tell: &deliveries.Module{}, allow: &approvals.Module{}, classes: &judgement.Classes{}, policies: &judgement.Policies{}, hear: &events.Module{}, judge: &judgement.Module{}, - engine: &runs.Engine{}, chat: &chat.Module{}, drafts: &drafts.Module{}, + engine: &runs.Engine{}, chat: &chat.Module{}, drafts: &drafts.Module{}, live: hub.New(), }.register(api) return api.OpenAPI().YAML() } diff --git a/internal/app/archie/run.go b/internal/app/archie/run.go index 9c4204258..69d495f8f 100644 --- a/internal/app/archie/run.go +++ b/internal/app/archie/run.go @@ -115,6 +115,7 @@ func Run(ctx context.Context, configPath string) error { apiModules{ settings: settings, conns: conns, system: sys, tell: tell, allow: allow, classes: classes, policies: policies, hear: hear, judge: judge, engine: engine, chat: talk, drafts: drafts.NewModule(db, log.With("module", "drafts"), orgID, hear, engine, policies), + live: live, }.register(api) dashboard.Routes(mux, ui.DistDirFS) diff --git a/modules/dashboard/stream.go b/modules/dashboard/stream.go index 3823b5cea..6a1829b8b 100644 --- a/modules/dashboard/stream.go +++ b/modules/dashboard/stream.go @@ -9,18 +9,27 @@ import ( "github.com/danielgtaylor/huma/v2" "github.com/samcharles93/archie-core/internal/platform/httpapi" + "github.com/samcharles93/archie-core/internal/platform/hub" + "github.com/samcharles93/archie-core/modules/governance" ) // keepalive is how often an idle stream writes a comment, so proxies keep // the connection open and the browser notices one that died. const keepalive = 25 * time.Second +// chatTopic is the hub topic the chat module publishes when an action a +// conversation held settles after its turn ended. +const chatTopic = "chat" + +// chatOutcome is the frame the dashboard re-reads the open conversation on. +const chatOutcome = `data: {"topic":"tasks","data":{"kind":"chat_outcome"}}` + "\n\n" + // Register adds the dashboard's live stream: the one EventSource the SPA -// keeps open, framing each update as `data: {"topic":…,"data":…}`. Nothing -// this binary publishes has a dashboard reader yet, so the stream carries -// only keepalives; it still tells the connection indicator the server is -// up, and a reconnect still makes every mounted page re-read. -func Register(api huma.API) { +// keeps open, framing each update as `data: {"topic":…,"data":…}`. A settled +// chat action is the only update with a dashboard reader; a turn's own reply +// streams from the chat API. Keepalives tell the connection indicator the +// server is up, and a reconnect makes every mounted page re-read. +func Register(api huma.API, h *hub.Hub) { huma.Register(api, httpapi.SignedIn(huma.Operation{ OperationID: "stream-dashboard", Method: http.MethodGet, Path: "/api/stream", Summary: "Stream live dashboard updates", Tags: []string{"Dashboard"}, @@ -28,33 +37,50 @@ func Register(api huma.API) { Description: "Server-sent events: one data frame of {\"topic\", \"data\"} per update, and a keepalive comment while idle", Content: map[string]*huma.MediaType{"text/event-stream": {Schema: &huma.Schema{Type: huma.TypeString}}}, }}, - }), stream) + }), func(ctx context.Context, _ *struct{}) (*huma.StreamResponse, error) { + // Chat is an administrator's; nobody else hears that it changed. + var chat <-chan hub.Note + stop := func() {} + if p, _ := governance.PrincipalFromContext(ctx); p.InstanceAdmin() { + chat, stop = h.Subscribe(chatTopic) + } + return &huma.StreamResponse{Body: func(hc huma.Context) { + defer stop() + serve(hc, chat) + }}, nil + }) } -func stream(_ context.Context, _ *struct{}) (*huma.StreamResponse, error) { - return &huma.StreamResponse{Body: func(hc huma.Context) { - w := hc.BodyWriter() - flusher, ok := w.(http.Flusher) - if !ok { - hc.SetStatus(http.StatusInternalServerError) +func serve(hc huma.Context, chat <-chan hub.Note) { + w := hc.BodyWriter() + flusher, ok := w.(http.Flusher) + if !ok { + hc.SetStatus(http.StatusInternalServerError) + return + } + hc.SetHeader("Content-Type", "text/event-stream") + hc.SetHeader("Cache-Control", "no-store") + hc.SetStatus(http.StatusOK) + flusher.Flush() + tick := time.NewTicker(keepalive) + defer tick.Stop() + for { + frame := ": keepalive\n\n" + select { + case <-hc.Context().Done(): + return + case <-tick.C: + case _, ok := <-chat: + if !ok { + // The hub dropped a reader that fell behind; it reconnects + // and re-reads. + return + } + frame = chatOutcome + } + if _, err := fmt.Fprint(w, frame); err != nil { return } - hc.SetHeader("Content-Type", "text/event-stream") - hc.SetHeader("Cache-Control", "no-store") - hc.SetStatus(http.StatusOK) flusher.Flush() - tick := time.NewTicker(keepalive) - defer tick.Stop() - for { - select { - case <-hc.Context().Done(): - return - case <-tick.C: - if _, err := fmt.Fprint(w, ": keepalive\n\n"); err != nil { - return - } - flusher.Flush() - } - } - }}, nil + } } diff --git a/modules/governance/accounts_api.go b/modules/governance/accounts_api.go index cf7d7c222..2a106b343 100644 --- a/modules/governance/accounts_api.go +++ b/modules/governance/accounts_api.go @@ -610,12 +610,12 @@ func (m *Module) capabilities(ctx context.Context, _ *struct{}) (*httpapi.Reply[ p, _ := PrincipalFromContext(ctx) sections := map[string]bool{} for _, name := range []string{ - "settings", "events", "workflows", "runs", "credentials", "extensions", "secret_engines", "models", "controls", + "settings", "events", "workflows", "runs", "credentials", "extensions", "secret_engines", "models", "controls", "chat", } { sections[name] = p.InstanceAdmin() } for _, name := range []string{ - "home", "tasks", "work_requests", "chat", "logs", "skills", "curators", "channels", + "home", "tasks", "work_requests", "logs", "skills", "curators", "channels", "captures", "mappings", "bindings", "workflow_editor", "extension_catalogue", "model_aliases", "system_status", "task_execution", "organisations", "tools", "plugins", "container_runtime", "agent_profiles", "org", "org_members", "org_agents", "org_workspaces", "org_policies", "org_denials", "org_audit", "org_usage", "org_config", diff --git a/ui/src/App.vue b/ui/src/App.vue index 18c4c6c91..ad6a95d2f 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -121,7 +121,7 @@ watch(() => accounts.status?.user, (user) => { - + @@ -146,7 +146,7 @@ watch(() => accounts.status?.user, (user) => { - + diff --git a/ui/src/chat/ChatAskCard.vue b/ui/src/chat/ChatAskCard.vue index dafda83f4..1518ce78f 100644 --- a/ui/src/chat/ChatAskCard.vue +++ b/ui/src/chat/ChatAskCard.vue @@ -7,9 +7,9 @@ import { Input } from "@/components/ui/input"; import { Item, ItemActions, ItemContent, ItemDescription, ItemMedia, ItemTitle } from "@/components/ui/item"; import { ReadError } from "@/components/ui/read-error"; import ChatQuestionnaire from "./ChatQuestionnaire.vue"; -import { answerAsk, askError, type ChatAsk } from "./state"; +import { answerAsk, askError, askErrorID, type ChatAsk } from "./state"; -defineProps<{ ask: ChatAsk }>(); +const props = defineProps<{ ask: ChatAsk }>(); const reply = ref(""); // The last answer tried, so a failed send can be retried from the error. @@ -17,7 +17,7 @@ const lastAnswer = ref(""); async function answer(value: string): Promise { lastAnswer.value = value; - return answerAsk(value); + return answerAsk(value, props.ask); } async function sendReply(): Promise { @@ -33,7 +33,7 @@ function retry(): void { diff --git a/ui/src/chat/ChatSettings.vue b/ui/src/chat/ChatSettings.vue index 507ac33ee..b69770a60 100644 --- a/ui/src/chat/ChatSettings.vue +++ b/ui/src/chat/ChatSettings.vue @@ -34,12 +34,16 @@ const groups = computed(() => { ? entries : [["", selectorData.value.models || []] as [string, string[]]]; }); +// The model is chosen here only when the server offers a choice. +const choosable = computed(() => groups.value.some(([, models]) => models.length));