feat(webui): derive the setup checklist from the caller's organisation and drop the optional chat channel step
This commit is contained in:
1 parent
d5a34005d1
commit
2cf9d435cc
5 files changed
+33
-61
No files matched your search
@@ -19,15 +19,3 @@ func (c ChatConfig) FrontEnds() []ChatFrontEnd {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// AnyFrontEndConfigured reports whether at least one conversational front-end
|
||||
// has credentials. The setup checklist asks this as a yes/no question; every
|
||||
// other consumer wants the per-front-end detail FrontEnds returns.
|
||||
func (c ChatConfig) AnyFrontEndConfigured() bool {
|
||||
for _, frontEnd := range c.FrontEnds() {
|
||||
if frontEnd.Configured {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -152,9 +152,6 @@ type ChatView struct {
|
||||
// [chat]. Empty when unset, which the page renders as no greeting
|
||||
// rather than a hardcoded name.
|
||||
Operator string `json:"operator,omitempty"`
|
||||
// ChannelConfigured reports that at least one conversational
|
||||
// front-end has credentials.
|
||||
ChannelConfigured bool `json:"channel_configured"`
|
||||
}
|
||||
|
||||
// ConfigViewSchema names ConfigView's JSON shape; it changes on incompatible
|
||||
@@ -229,16 +226,11 @@ func BuildConfigView(in ConfigViewInput) ConfigView {
|
||||
MultiIdentity: len(cfg.Identities) > 0,
|
||||
Identities: identityForgesView(cfg.Identities),
|
||||
Catalog: append([]CatalogProviderView{}, in.Catalog...),
|
||||
Chat: ChatView{ShowToolCalls: cfg.Chat.ShowToolCalls, Operator: strings.TrimSpace(cfg.Chat.Operator), ChannelConfigured: chatChannelConfigured(cfg.Chat)},
|
||||
Chat: ChatView{ShowToolCalls: cfg.Chat.ShowToolCalls, Operator: strings.TrimSpace(cfg.Chat.Operator)},
|
||||
Reload: in.Reload,
|
||||
}
|
||||
}
|
||||
|
||||
// chatChannelConfigured reports whether any chat front-end is configured.
|
||||
func chatChannelConfigured(chat config.ChatConfig) bool {
|
||||
return chat.AnyFrontEndConfigured()
|
||||
}
|
||||
|
||||
// RemoteConfigView reads the projection the configuration owner published.
|
||||
// The reading process cannot edit it: it has no update path, and the page is
|
||||
// told so rather than offering a control that would 503.
|
||||
|
||||
+31
-38
@@ -2,7 +2,9 @@ package webui
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/identity"
|
||||
"github.com/samcharles93/archie-core/internal/domain/org"
|
||||
)
|
||||
|
||||
// SetupStep is one item in the dashboard's getting-started checklist. Path is
|
||||
@@ -15,53 +17,44 @@ type SetupStep struct {
|
||||
Path string `json:"path,omitempty"`
|
||||
}
|
||||
|
||||
// handleSetup reports which setup steps are still missing, from live state.
|
||||
// handleSetup reports which setup steps are still missing in the caller's
|
||||
// organisation, from live state. Optional capabilities (a chat channel, a
|
||||
// repository) are set up where they are used, not listed here.
|
||||
func (s *Server) handleSetup(w http.ResponseWriter, r *http.Request) {
|
||||
steps := []SetupStep{}
|
||||
|
||||
// Every step is read from the configuration projection this process
|
||||
// renders, so the checklist works the same whether configuration is
|
||||
// held here or published by its owner.
|
||||
view, found, err := s.configSource()(r.Context())
|
||||
if err != nil || !found {
|
||||
// No configuration available: report nothing rather than
|
||||
// guessing, so the dashboard simply omits the panel.
|
||||
if s.Store == nil {
|
||||
writeJSON(w, map[string]any{"steps": steps})
|
||||
return
|
||||
}
|
||||
|
||||
// The operator's name is deployment data, configured once in [chat]. The
|
||||
// dashboard greets with it rather than hardcoding a name, which would be
|
||||
// wrong on every deployment but one.
|
||||
operator := view.Chat.Operator
|
||||
|
||||
steps = append(steps, SetupStep{
|
||||
Title: "Identity",
|
||||
Detail: "Account Archie commits as.",
|
||||
Done: strings.TrimSpace(view.Identity.BotUser) != "",
|
||||
Path: "/org/agents",
|
||||
})
|
||||
|
||||
steps = append(steps, SetupStep{
|
||||
Title: "Chat channel",
|
||||
Detail: "Chat and approvals.",
|
||||
Done: view.Chat.ChannelConfigured,
|
||||
Path: "/org/channels",
|
||||
})
|
||||
|
||||
// Only meaningful once there is somewhere to run work.
|
||||
if done, ok := s.hasActiveAgent(r); ok {
|
||||
steps = append(steps, SetupStep{Title: "Agent identity", Done: done, Path: "/org/agents"})
|
||||
}
|
||||
if count, err := s.Store.StatusCounts(r.Context()); err == nil {
|
||||
total := 0
|
||||
for _, n := range count {
|
||||
total += n
|
||||
}
|
||||
steps = append(steps, SetupStep{
|
||||
Title: "First task",
|
||||
Detail: "Describe one above.",
|
||||
Done: total > 0,
|
||||
Path: "/tasks",
|
||||
})
|
||||
steps = append(steps, SetupStep{Title: "First task", Done: total > 0, Path: "/tasks"})
|
||||
}
|
||||
writeJSON(w, map[string]any{"steps": steps})
|
||||
}
|
||||
|
||||
writeJSON(w, map[string]any{"steps": steps, "operator": operator})
|
||||
// hasActiveAgent reports whether the caller's org has an active bot or
|
||||
// service account assigned; ok is false when that cannot be read.
|
||||
func (s *Server) hasActiveAgent(r *http.Request) (done, ok bool) {
|
||||
reader, isReader := s.Orgs.(org.AgentAssignments)
|
||||
if !isReader || s.Identities == nil {
|
||||
return false, false
|
||||
}
|
||||
assignments, err := reader.ListOrgAgents(r.Context(), policyOrg(r))
|
||||
if err != nil {
|
||||
return false, false
|
||||
}
|
||||
for _, assignment := range assignments {
|
||||
value, err := s.Identities.Get(r.Context(), assignment.IdentityID)
|
||||
if err == nil && value.Kind.Agent() && value.Lifecycle == identity.LifecycleActive {
|
||||
return true, true
|
||||
}
|
||||
}
|
||||
return false, true
|
||||
}
|
||||
@@ -276,7 +276,7 @@ func (s *Server) Broadcast(e events.Event) {
|
||||
|
||||
func (s *Server) registerCoreRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /api/summary", s.handleSummary)
|
||||
mux.HandleFunc("GET /api/setup", instanceOnly(s.handleSetup))
|
||||
mux.HandleFunc("GET /api/setup", s.handleSetup)
|
||||
mux.HandleFunc("GET /api/workflows", s.handleWorkflows)
|
||||
mux.HandleFunc("PUT /api/workflows/{id}/enabled", s.handleWorkflowEnabled)
|
||||
mux.HandleFunc("POST /api/work-requests", s.handleWorkRequest)
|
||||
|
||||
@@ -10,7 +10,6 @@ export interface SetupStep {
|
||||
|
||||
export interface Setup {
|
||||
steps: SetupStep[];
|
||||
operator?: string;
|
||||
}
|
||||
|
||||
export interface SetupPanelState {
|
||||
|
||||
Reference in new issue
Block a user