feat(webui): chat from the dashboard

Brings the chat surface to the Web UI: /api/chat with its own handlers
and tests, a self-contained ui/src/chat feature folder, and the shared
plumbing to reach the same router Telegram uses.

Includes a dangerous-command approval path (internal/gateway/dangerous.go,
internal/webui/dangerous.go, and the Telegram counterpart) so /rollback
and /stop are gated the same way on both surfaces, persona handling for
web sessions, and release-update formatting split out of the Telegram
service so both can render it.

web_parity_test.go pins that the two surfaces expose the same commands.

Authored in a parallel session; committed here so it lands with the rest
rather than sitting uncommitted while other work builds on top of it.
task check passes with it in place.

Screenshots used while building are gitignored (*.png) rather than
committed, matching the call made on the earlier design reference.
This commit is contained in:
sam committed 2026-08-05 10:48:51 +10:00
1 parent 8ae21f25db
commit 68ba3456ee
29 files changed
+2616 -112

No files matched your search

+44 -10
View File
@@ -262,6 +262,7 @@ func run() int {
log.Error("close store", "err", err)
}
}()
chatSessionStore := makeTelegramSessionStore(telegramSetup{St: st, Cfg: cfg})
if *requeue > 0 {
if err := st.Requeue(context.Background(), *requeue, "manual", ""); err != nil {
@@ -311,15 +312,6 @@ func run() int {
web.Broadcast(e)
}
}()
if l := cfg.Web.Listen; l != "" && l != "off" {
web.Token = webTokenFor(l, cfg.DBPath, log)
go func() {
if err := web.Run(ctx, l); err != nil {
log.Error("web ui failed", "err", err)
}
}()
}
// NATS client (optional -- SQLite flow unchanged when [nats] is absent).
var natsClient *nats.Client
if cfg.NATS.URL != "" {
@@ -384,6 +376,47 @@ func run() int {
requeue: st.Requeue,
transition: st.Transition,
})
updateService := makeUpdateService(telegramSetup{Cfg: cfg})
// The dashboard is another gateway, not a second chat implementation. It
// shares the router, session history, model selection, personas and LLM
// responder with Telegram while using a stable browser channel id.
var restartTelegram func() error
webRouter := gateway.NewRouter(st, nil, "web")
webRouter.Version = fmt.Sprintf("Archie\nGateway: %s\nRuntime: %s", gatewayVersion, runtimeVersion)
if cfg.Chat.Telegram.TokenEnv != "" {
webRouter.Restart = func(context.Context) error {
if restartTelegram == nil {
return fmt.Errorf("telegram gateway is not ready")
}
return restartTelegram()
}
}
webRouter.Models = chatModels
webRouter.Updates = updateService
webRouter.Personas = personas
webRouter.InitSessions(chatSessionStore)
configureTaskCommands(webRouter, chatTasks, chatController, defaultChatIdentity)
webSetup := telegramSetup{
Cfg: cfg, St: st, LLM: llm, ChatModels: chatModels, ToolReg: toolReg,
Personas: personas, ChatTasks: chatTasks, ChatController: chatController,
DefaultChatIdentity: defaultChatIdentity, SessionStore: chatSessionStore,
Log: log,
}
webRouter.LLM, webRouter.LLMStream = makeChatLLMResponder(ctx, "web", webSetup, chatSessionStore, webRouter)
web.Chat = &webui.ChatService{
Router: webRouter, Sessions: chatSessionStore,
Turns: gateway.NewTurns(log),
Models: chatModels, Personas: personas, Updates: updateService,
}
if l := cfg.Web.Listen; l != "" && l != "off" {
web.Token = webTokenFor(l, cfg.DBPath, log)
go func() {
if err := web.Run(ctx, l); err != nil {
log.Error("web ui failed", "err", err)
}
}()
}
// ── Gateways ──────────────────────────────────────────────────────
// Multi-agent collaboration PRD phase C (docs/prds/multi-agent-collaboration.md).
@@ -392,7 +425,8 @@ func run() int {
Cfg: cfg, CfgPath: *cfgPath, OverlayPath: *overlayPath,
St: st, LLM: llm, ChatModels: chatModels, ToolReg: toolReg,
Personas: personas, ChatTasks: chatTasks, ChatController: chatController,
DefaultChatIdentity: defaultChatIdentity, Log: log,
DefaultChatIdentity: defaultChatIdentity, SessionStore: chatSessionStore, Updates: updateService,
RegisterRestart: func(request func() error) { restartTelegram = request }, Log: log,
})
if !ok {
return 1
+29 -7
View File
@@ -39,6 +39,10 @@ type telegramSetup struct {
ChatTasks gateway.TaskCreator
ChatController gateway.TaskController
DefaultChatIdentity string
SessionStore gateway.SessionStore
Updates telegram.UpdateService
Dangerous gateway.DangerousCommandAuthority
RegisterRestart func(func() error)
Log *slog.Logger
}
@@ -59,10 +63,18 @@ func setupTelegramGateway(ctx context.Context, s telegramSetup) (start func(), o
"Add your Telegram user id to chat.telegram.allowed_user_ids to enable the bot.")
}
tg := telegram.New(tgToken, "", "", s.Cfg.Chat.Telegram.AllowedUserIDs, s.Log)
if s.RegisterRestart != nil {
s.RegisterRestart(tg.RequestRestart)
}
tg.Version = func() string {
return fmt.Sprintf("Archie\nGateway: %s\nRuntime: %s", gatewayVersion, runtimeVersion)
}
configureTelegramUpdates(tg, s)
if s.Updates != nil {
tg.Updates = s.Updates
} else {
configureTelegramUpdates(tg, s)
}
tg.Dangerous = s.Dangerous
tg.ReleaseAnnouncements = &releaseannounce.Announcer{
StatePath: releaseAnnouncementStatePath(s.Cfg.WorkDir, s.Cfg.BotUser),
Components: []releaseannounce.Component{
@@ -72,7 +84,10 @@ func setupTelegramGateway(ctx context.Context, s telegramSetup) (start func(), o
}
tg.Reload = makeTelegramReload(s)
sessionStore := makeTelegramSessionStore(s)
sessionStore := s.SessionStore
if sessionStore == nil {
sessionStore = makeTelegramSessionStore(s)
}
router := buildTelegramRouter(ctx, tg, s, sessionStore)
return func() {
go func() {
@@ -85,8 +100,14 @@ func setupTelegramGateway(ctx context.Context, s telegramSetup) (start func(), o
}
func configureTelegramUpdates(tg *telegram.Gateway, s telegramSetup) {
if updates := makeUpdateService(s); updates != nil {
tg.Updates = updates
}
}
func makeUpdateService(s telegramSetup) *releaseupdate.Service {
if len(s.Cfg.Chat.Telegram.UpdateCheckCommand) == 0 {
return
return nil
}
updates := &releaseupdate.Service{
Catalog: releaseupdate.CommandCatalog{Command: s.Cfg.Chat.Telegram.UpdateCheckCommand},
@@ -95,7 +116,7 @@ func configureTelegramUpdates(tg *telegram.Gateway, s telegramSetup) {
if len(s.Cfg.Chat.Telegram.UpdateInstallCommand) != 0 {
updates.Installer = releaseupdate.CommandInstaller{Command: s.Cfg.Chat.Telegram.UpdateInstallCommand}
}
tg.Updates = updates
return updates
}
func makeTelegramReload(s telegramSetup) func(*telegram.Gateway) error {
@@ -134,14 +155,15 @@ func buildTelegramRouter(ctx context.Context, tg *telegram.Gateway, s telegramSe
// captured by reference.
router := gateway.NewRouter(s.St, nil, "telegram")
router.Models = s.ChatModels
router.Updates = s.Updates
router.InitSessions(sessionStore)
configureTaskCommands(router, s.ChatTasks, s.ChatController, s.DefaultChatIdentity)
router.LLM, router.LLMStream = makeTelegramLLMResponder(ctx, tg, s, sessionStore, router)
router.LLM, router.LLMStream = makeChatLLMResponder(ctx, tg.Name(), s, sessionStore, router)
return router
}
func makeTelegramLLMResponder(ctx context.Context, tg *telegram.Gateway, s telegramSetup, sessionStore gateway.SessionStore, router *gateway.Router) (gateway.LLMResponder, gateway.LLMStreamResponder) {
func makeChatLLMResponder(ctx context.Context, channel string, s telegramSetup, sessionStore gateway.SessionStore, router *gateway.Router) (gateway.LLMResponder, gateway.LLMStreamResponder) {
if s.LLM == nil {
return nil, nil
}
@@ -202,7 +224,7 @@ func makeTelegramLLMResponder(ctx context.Context, tg *telegram.Gateway, s teleg
chatModel := s.ChatModels.ActiveModel()
systemPrompt := gateway.BuildSystemPrompt(gateway.SystemPromptConfig{
Persona: s.Personas.GetActive(sk), Tools: toolSummaries(options.Tools),
Channel: tg.Name(), Model: chatModel, SessionID: sk, Now: time.Now(),
Channel: channel, Model: chatModel, SessionID: sk, Now: time.Now(),
Operator: s.Cfg.Chat.Operator,
})
view.Messages = append(