Completes the objective deletion gate for the UI Service (archie-core-8cda.5.6): go list -deps ./cmd/archie-ui now links zero banned packages -- no modernc.org/sqlite, no internal/store, gateway, channels, memory, secret, agentexec, tools, skill, yaegiutil, curator, or the workflow engine. The closure shrinks from 68 to 26 archie-core packages. Each cut is a producer-side move; no consumer-side defensive shims. - Store contracts (TaskStore family, value types, sentinels) moved from internal/store to internal/domain/storecontract -- the approved contract location per state-store-contract rev. 2d, and NOT internal/contracts: that tree is buf generate output and tools/proto.sh check deletes hand-written files there. internal/store keeps aliases; sentinel message strings are byte-identical and remain the wire contract. - Chat contracts (ChatContract, sessions, turns, streaming, commands) moved from internal/gateway to internal/domain/messaging; gateway keeps aliases. ToolCallEvent rendering helpers become gateway functions (methods cannot live on alias types). - Task vocabulary (Task, statuses, mid-run Store, Definition) split into internal/domain/workflow/task; the pipeline engine stays in package workflow with aliases, so daemon-side callers are unchanged. - overlay.DeniedKeys moved to internal/infrastructure/configuration: webui referenced the constant and that dragged the overlay SQLite store in. - webui.Server's concrete runtime handles become webui-owned view interfaces with daemon-side bootstrap adapters: channel lifecycle (internal/channels/status), MemoryStatus, CuratorStatus, and a SkillCatalog seam replacing the direct skill.DefaultRoots/CatalogRoots calls. Each degrades to an empty page when unwired. - config.SecretRef moved into internal/config (config vocabulary); internal/secret keeps an alias and Registry.Resolve absorbs the zero-value short-circuit. Docs: state-store-contract rev. 2d relocation record; ui-service-boundary deletion gate marked satisfied; ARCHITECTURE.md package map rows.
123 lines
4.1 KiB
Go
123 lines
4.1 KiB
Go
// readiness.go wires the operator readiness probes (internal/domain/health)
|
|
// to their real subsystem dependencies and hands the assembled registry to the
|
|
// dashboard's /health/detailed surface. It is the composition-root bridge:
|
|
// each probe gets the narrowest real input it needs, never the daemon.
|
|
package archied
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"path/filepath"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/samcharles93/archie-core/internal/channels/status"
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/health"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/readiness"
|
|
"github.com/samcharles93/archie-core/internal/webui"
|
|
)
|
|
|
|
// setupReadinessProbes assembles the readiness probes and publishes the
|
|
// registry to the dashboard. It must be called after setupObservability (so
|
|
// b.web.Cfg and b.web.Channels are set) and after the chat wiring (so
|
|
// b.web.Chat exposes the model manager and session store).
|
|
func (b *boot) setupReadinessProbes() {
|
|
cfg := b.cfg
|
|
probes := []health.Probe{
|
|
readiness.NewStoreProbe(b.stateStore),
|
|
readiness.NewConfigProbe(func() config.Config { return b.web.Cfg.Get() }, configuration.Validate),
|
|
readiness.NewDiskProbe(diskProbePath(cfg)),
|
|
readiness.NewModelProbe(b.chatModels.ActiveModel, b.chatModels.Models, modelReachProbe(cfg, b.chatModels.ActiveModel)),
|
|
readiness.NewGatewayProbe(
|
|
func() []readiness.ChannelState { return channelStates(b.web.Channels) },
|
|
func(ctx context.Context) int { return sessionCount(ctx, b.web.Chat) },
|
|
),
|
|
}
|
|
b.web.Health = health.NewRegistry(probes...)
|
|
}
|
|
|
|
// channelStates projects a channel lifecycle snapshot into the readiness
|
|
// probe's view, so the probe does not depend on the channels package's
|
|
// concrete type.
|
|
func channelStates(m *status.Manager) []readiness.ChannelState {
|
|
if m == nil {
|
|
return nil
|
|
}
|
|
snapshot := m.Snapshot()
|
|
states := make([]readiness.ChannelState, 0, len(snapshot))
|
|
for _, s := range snapshot {
|
|
states = append(states, readiness.ChannelState{
|
|
ID: s.ID,
|
|
Configured: s.Configured,
|
|
State: string(s.State),
|
|
})
|
|
}
|
|
return states
|
|
}
|
|
|
|
// sessionCount returns the number of gateway sessions. An unwired chat
|
|
// surface returns 0 rather than reporting a false failure.
|
|
func sessionCount(ctx context.Context, chat *webui.ChatService) int {
|
|
if chat == nil || chat.Contract == nil {
|
|
return 0
|
|
}
|
|
snapshot, err := chat.Contract.Snapshot(ctx)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
return len(snapshot.Sessions)
|
|
}
|
|
|
|
// diskProbePath resolves the filesystem the readiness disk probe inspects:
|
|
// the store database directory first (the data that must fit on disk), then
|
|
// the working directory, then the process cwd.
|
|
func diskProbePath(cfg config.Config) string {
|
|
switch {
|
|
case cfg.DBPath != "":
|
|
return filepath.Dir(cfg.DBPath)
|
|
case cfg.WorkDir != "":
|
|
return cfg.WorkDir
|
|
default:
|
|
return "."
|
|
}
|
|
}
|
|
|
|
// modelReachProbe returns a live reachability check for the active model. It
|
|
// resolves the active model's provider and, when the provider has a custom
|
|
// base URL, performs a short-timeout HTTP request to it: any response
|
|
// (including 401/404) proves the endpoint is reachable, while a network error
|
|
// or an unconfigured provider reports unreachable. A provider using its SDK
|
|
// default endpoint is assumed reachable, because no custom endpoint exists to
|
|
// probe.
|
|
func modelReachProbe(cfg config.Config, active func() string) func(context.Context) error {
|
|
return func(ctx context.Context) error {
|
|
model := active()
|
|
provider, _, _ := strings.Cut(model, "/")
|
|
if provider == "" {
|
|
return fmt.Errorf("active model %q has no provider", model)
|
|
}
|
|
p, ok := cfg.Providers[provider]
|
|
if !ok {
|
|
return fmt.Errorf("provider %q not configured", provider)
|
|
}
|
|
if p.BaseURL == "" {
|
|
return nil
|
|
}
|
|
reqCtx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
|
defer cancel()
|
|
req, err := http.NewRequestWithContext(reqCtx, http.MethodGet, p.BaseURL, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
resp, err := http.DefaultClient.Do(req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
_ = resp.Body.Close()
|
|
return nil
|
|
}
|
|
}
|