feat(config): model aliases replace model roles, resolved by one resolver
Agent steps, implement, pr-review, MCP sampling, chat, embedding and transcription resolve a model alias (empty means the purpose's default) and fail on an unknown alias instead of falling back. The step editor and chat pick aliases; workflow definitions naming an unknown alias are refused on save.
This commit is contained in:
1 parent
df554b3056
commit
f4e1308b23
45 files changed
+528
-486
No files matched your search
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/ai-sdk/core"
|
||||
"github.com/samcharles93/ai-sdk/runtime"
|
||||
@@ -14,11 +13,6 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/tools/mcp"
|
||||
)
|
||||
|
||||
// taskSamplingModel returns the task's builder model, or "".
|
||||
func taskSamplingModel(cfg config.TaskConfig) string {
|
||||
return strings.TrimSpace(cfg.Models["builder"])
|
||||
}
|
||||
|
||||
// taskSamplingHandler answers MCP sampling requests with the task's model.
|
||||
// Without a runtime or model the request is refused.
|
||||
func taskSamplingHandler(llm *runtime.Runtime, cfg config.TaskConfig) mcp.SamplingHandler {
|
||||
@@ -26,9 +20,9 @@ func taskSamplingHandler(llm *runtime.Runtime, cfg config.TaskConfig) mcp.Sampli
|
||||
if llm == nil {
|
||||
return mcp.SamplingResult{}, errors.New("mcp sampling: no model runtime is configured")
|
||||
}
|
||||
model := taskSamplingModel(cfg)
|
||||
if model == "" {
|
||||
return mcp.SamplingResult{}, errors.New("mcp sampling: no builder model is configured")
|
||||
model, err := config.ResolveModel(cfg.Models, "", config.PurposeAgent)
|
||||
if err != nil {
|
||||
return mcp.SamplingResult{}, fmt.Errorf("mcp sampling: %w", err)
|
||||
}
|
||||
messages, err := modelloop.SamplingMessages(req)
|
||||
if err != nil {
|
||||
|
||||
@@ -679,7 +679,7 @@ func (b *boot) publishConfig(ctx context.Context, cfg config.Config) {
|
||||
}
|
||||
|
||||
func (b *boot) configViewInput() webui.ConfigViewInput {
|
||||
catalog, _ := b.catalogState()
|
||||
catalog := b.catalogState()
|
||||
in := webui.ConfigViewInput{
|
||||
Config: b.cfgHolder.Get(),
|
||||
Catalog: catalogView(catalog),
|
||||
@@ -803,7 +803,7 @@ func (b *boot) addCleanup(fn func()) {
|
||||
b.cleanups = append(b.cleanups, fn)
|
||||
}
|
||||
|
||||
func (b *boot) catalogState() (modelcatalog.Snapshot, []string) { return b.catalog.State() }
|
||||
func (b *boot) catalogState() modelcatalog.Snapshot { return b.catalog.State() }
|
||||
|
||||
// loadCatalog layers the model catalog under the file config. A catalog that
|
||||
// cannot be read leaves the configured providers and models in effect.
|
||||
@@ -815,7 +815,7 @@ func (b *boot) loadCatalog(ctx context.Context) {
|
||||
}
|
||||
models := modelcatalog.Apply(&b.cfg, snapshot)
|
||||
b.cfgHolder.Set(b.cfg.Clone())
|
||||
b.catalog.Set(snapshot, models)
|
||||
b.catalog.Set(snapshot)
|
||||
b.log.Info("model catalog loaded", "providers", len(snapshot.Providers), "models", len(models))
|
||||
}
|
||||
|
||||
@@ -830,7 +830,7 @@ func (b *boot) refreshModelCatalog(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b.catalog.Set(snapshot, models)
|
||||
b.catalog.Set(snapshot)
|
||||
b.publishConfig(ctx, cfg)
|
||||
b.log.Info("model catalog refreshed", "providers", len(snapshot.Providers), "models", len(models))
|
||||
return nil
|
||||
|
||||
@@ -52,7 +52,7 @@ func (b *boot) reloadConfig(ctx context.Context, doc *configuration.Document) er
|
||||
// drop them from the running config even though the file is
|
||||
// unchanged. Re-apply the same merge (idempotent: a catalog that
|
||||
// failed to load merges to identity).
|
||||
catalog, _ := b.catalogState()
|
||||
catalog := b.catalogState()
|
||||
modelcatalog.Apply(&doc.Config, catalog)
|
||||
// Bounded: this runs on the signal loop, which handles nothing else
|
||||
// while it waits, and a State Store that has stopped answering must
|
||||
@@ -264,7 +264,7 @@ func (b *boot) startLiveSettings(ctx context.Context) error {
|
||||
var runtimeResourceKinds = []string{
|
||||
controlplane.TaskPolicyKind,
|
||||
controlplane.ProviderSettingsKind,
|
||||
controlplane.ModelRoleAssignmentsKind,
|
||||
controlplane.ModelAliasesKind,
|
||||
controlplane.RepositoryPoliciesKind,
|
||||
controlplane.SchedulingPolicyKind,
|
||||
controlplane.ToolSettingsKind,
|
||||
@@ -370,7 +370,7 @@ func (b *boot) applyRuntimeResourceUpdate(ctx context.Context, kind string, upda
|
||||
// this read returns can lack the catalog's model limits and discovered
|
||||
// providers. The merge is idempotent, and reloadConfig re-applies it
|
||||
// before layering for the same reason.
|
||||
catalog, _ := b.catalogState()
|
||||
catalog := b.catalogState()
|
||||
modelcatalog.Apply(&base, catalog)
|
||||
cfg, _, err := b.runtimeConfig(ctx, base)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,116 +3,48 @@ package archiegateway
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/modelcatalog"
|
||||
)
|
||||
|
||||
// chatModelManager owns the process-local model selected for interactive chat.
|
||||
// The configured role-to-model map supplies the available catalog; switching
|
||||
// chat models does not rewrite daemon configuration or affect workflow roles.
|
||||
// chatModelManager owns the process-local model alias selected for
|
||||
// interactive chat. Switching it does not rewrite configuration or affect
|
||||
// workflow steps.
|
||||
type chatModelManager struct {
|
||||
mu sync.RWMutex
|
||||
models []string
|
||||
active string
|
||||
// configured, explicit and catalog are the sources the offered set is
|
||||
// derived from: the role assignments (live via SetConfigured), the
|
||||
// [chat].models catalog (fixed for the process), and the model catalog's
|
||||
// own refs (replaced wholesale by SetModelCatalog).
|
||||
configured map[string]string
|
||||
explicit []string
|
||||
catalog []string
|
||||
mu sync.RWMutex
|
||||
aliases map[string]string
|
||||
active string
|
||||
details map[string]gateway.ModelDetails
|
||||
providerNames map[string]string
|
||||
}
|
||||
|
||||
// pickChatDefault is the model the manager starts on: the chat role's
|
||||
// assignment, falling back to the builder role's.
|
||||
func pickChatDefault(configured map[string]string) string {
|
||||
if active := strings.TrimSpace(configured["chat"]); active != "" {
|
||||
return active
|
||||
}
|
||||
return strings.TrimSpace(configured["builder"])
|
||||
}
|
||||
|
||||
// mergeModelRefs is the model set the manager offers: the configured role
|
||||
// assignments plus every catalog, unique and sorted.
|
||||
func mergeModelRefs(configured map[string]string, catalogs ...[]string) []string {
|
||||
unique := make(map[string]struct{}, len(configured))
|
||||
for _, ref := range configured {
|
||||
ref = strings.TrimSpace(ref)
|
||||
if ref != "" {
|
||||
unique[ref] = struct{}{}
|
||||
}
|
||||
}
|
||||
for _, catalog := range catalogs {
|
||||
for _, ref := range catalog {
|
||||
ref = strings.TrimSpace(ref)
|
||||
if ref != "" {
|
||||
unique[ref] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Non-nil: the chat snapshot serialises this as [] when no model is configured.
|
||||
models := slices.AppendSeq(make([]string, 0, len(unique)), maps.Keys(unique))
|
||||
slices.Sort(models)
|
||||
return models
|
||||
}
|
||||
|
||||
func newChatModelManager(configured map[string]string, catalogs ...[]string) *chatModelManager {
|
||||
explicit := make([]string, 0, len(catalogs))
|
||||
for _, catalog := range catalogs {
|
||||
explicit = append(explicit, catalog...)
|
||||
}
|
||||
m := &chatModelManager{
|
||||
configured: configured,
|
||||
explicit: explicit,
|
||||
details: make(map[string]gateway.ModelDetails),
|
||||
providerNames: make(map[string]string),
|
||||
}
|
||||
m.active = pickChatDefault(configured)
|
||||
m.setModelsLocked()
|
||||
func newChatModelManager(aliases map[string]string) *chatModelManager {
|
||||
m := &chatModelManager{details: make(map[string]gateway.ModelDetails), providerNames: make(map[string]string)}
|
||||
m.SetConfigured(aliases)
|
||||
return m
|
||||
}
|
||||
|
||||
// setModelsLocked re-derives the offered set from the three sources and keeps
|
||||
// the active selection when the new set still carries it, falling back the way
|
||||
// construction does when it does not.
|
||||
func (m *chatModelManager) setModelsLocked() {
|
||||
m.models = mergeModelRefs(m.configured, m.explicit, m.catalog)
|
||||
if !slices.Contains(m.models, m.active) {
|
||||
m.active = pickChatDefault(m.configured)
|
||||
// SetConfigured replaces the alias table after a live change to model-aliases.
|
||||
// The active alias survives when it still exists; otherwise chat returns to
|
||||
// the default alias.
|
||||
func (m *chatModelManager) SetConfigured(aliases map[string]string) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.aliases = aliases
|
||||
if !slices.Contains(config.ChatAliases(aliases), m.active) {
|
||||
m.active = config.PurposeChat.DefaultAlias()
|
||||
}
|
||||
}
|
||||
|
||||
// SetConfigured re-derives the model set the manager offers after a live
|
||||
// change to model-role-assignments or provider-settings: the list is built
|
||||
// from the configured roles at construction, so a stored change would leave
|
||||
// the chat surfaces offering refs the runtime can no longer resolve. The
|
||||
// operator's active selection survives when the new roles still carry it; a
|
||||
// removed one falls back the way construction does.
|
||||
func (m *chatModelManager) SetConfigured(configured map[string]string) {
|
||||
// SetModelCatalog replaces the provider display names and per-model details
|
||||
// the catalog publishes.
|
||||
func (m *chatModelManager) SetModelCatalog(snapshot modelcatalog.Snapshot) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.configured = configured
|
||||
m.setModelsLocked()
|
||||
}
|
||||
|
||||
// SetModelCatalog replaces the model catalog's contribution to the manager:
|
||||
// the references it offers, the provider display names and the per-model
|
||||
// details. The previous snapshot's entries are dropped rather than merged --
|
||||
// a model or provider the catalog no longer publishes must stop being offered
|
||||
// and described, and these maps are the manager's own state rather than a
|
||||
// second catalogue to fall back on.
|
||||
func (m *chatModelManager) SetModelCatalog(snapshot modelcatalog.Snapshot, models []string) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.catalog = slices.Clone(models)
|
||||
m.details = make(map[string]gateway.ModelDetails)
|
||||
m.providerNames = make(map[string]string)
|
||||
for _, provider := range snapshot.Providers {
|
||||
@@ -128,7 +60,6 @@ func (m *chatModelManager) SetModelCatalog(snapshot modelcatalog.Snapshot, model
|
||||
}
|
||||
}
|
||||
}
|
||||
m.setModelsLocked()
|
||||
}
|
||||
|
||||
func (m *chatModelManager) ProviderDisplayName(provider string) string {
|
||||
@@ -144,80 +75,36 @@ func (m *chatModelManager) ModelDetails(ref string) (gateway.ModelDetails, bool)
|
||||
return details, ok
|
||||
}
|
||||
|
||||
// Models returns the aliases chat may switch between.
|
||||
func (m *chatModelManager) Models() []string {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
return slices.Clone(m.models)
|
||||
return config.ChatAliases(m.aliases)
|
||||
}
|
||||
|
||||
func (m *chatModelManager) ActiveModel() string {
|
||||
func (m *chatModelManager) ActiveAlias() string {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
return m.active
|
||||
}
|
||||
|
||||
func (m *chatModelManager) SetActiveModel(ctx context.Context, ref string) error {
|
||||
// ActiveModel returns the active alias's model ref, or "" when it is unset.
|
||||
func (m *chatModelManager) ActiveModel() string {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
ref, _ := config.ResolveModel(m.aliases, m.active, config.PurposeChat)
|
||||
return ref
|
||||
}
|
||||
|
||||
func (m *chatModelManager) SetActiveModel(ctx context.Context, alias string) error {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if !slices.Contains(m.models, ref) {
|
||||
return fmt.Errorf("model %q is not configured", ref)
|
||||
if !slices.Contains(config.ChatAliases(m.aliases), alias) {
|
||||
return fmt.Errorf("model alias %q is not configured", alias)
|
||||
}
|
||||
m.active = ref
|
||||
m.active = alias
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *chatModelManager) Providers() []string {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
seen := make(map[string]bool)
|
||||
var providers []string
|
||||
for _, model := range m.models {
|
||||
provider, _, ok := strings.Cut(model, "/")
|
||||
if ok && provider != "" && !seen[provider] {
|
||||
seen[provider] = true
|
||||
providers = append(providers, provider)
|
||||
}
|
||||
}
|
||||
slices.Sort(providers)
|
||||
return providers
|
||||
}
|
||||
|
||||
func (m *chatModelManager) ActiveProvider() string {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
provider, _, _ := strings.Cut(m.active, "/")
|
||||
return provider
|
||||
}
|
||||
|
||||
func (m *chatModelManager) ModelsForProvider(provider string) []string {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
prefix := provider + "/"
|
||||
var models []string
|
||||
for _, model := range m.models {
|
||||
if strings.HasPrefix(model, prefix) {
|
||||
models = append(models, model)
|
||||
}
|
||||
}
|
||||
return models
|
||||
}
|
||||
|
||||
func (m *chatModelManager) SetActiveProvider(ctx context.Context, provider string) error {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
prefix := provider + "/"
|
||||
for _, model := range m.models {
|
||||
if strings.HasPrefix(model, prefix) {
|
||||
m.active = model
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("provider %q is not configured", provider)
|
||||
}
|
||||
@@ -57,9 +57,9 @@ func (b *server) setupTranscriber(cfg config.Config, log *slog.Logger) {
|
||||
})
|
||||
if ok {
|
||||
b.transcriber = client
|
||||
log.Info("voice transcription enabled", "role", transcription.Role)
|
||||
} else if cfg.Models[transcription.Role] != "" {
|
||||
log.Warn("voice transcription configured but unavailable; capability disabled", "role", transcription.Role)
|
||||
log.Info("voice transcription enabled")
|
||||
} else if _, err := config.ResolveModel(cfg.Models, "", config.PurposeTranscription); err == nil {
|
||||
log.Warn("voice transcription configured but unavailable; capability disabled")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,18 +84,18 @@ func (b *server) startRateLimiter(ctx context.Context, cfg config.RateLimitConfi
|
||||
}
|
||||
|
||||
// rebuildChatModelRuntime re-derives the gateway chat runtime's provider set
|
||||
// after a live change to provider-settings or model-role-assignments. The
|
||||
// after a live change to provider-settings or model-aliases. The
|
||||
// turn runner reads the runtime through server.chatLLM, so the swap reaches its
|
||||
// next turn without rebuilding the runner, and the model manager re-derives
|
||||
// the references it offers from the new role assignments and the catalog.
|
||||
// the aliases it offers.
|
||||
func (b *server) rebuildChatModelRuntime(cfg config.Config) {
|
||||
if b.chatModels == nil {
|
||||
return // this process serves no chat turns
|
||||
}
|
||||
b.setLLM(modelloop.NewRuntime(executionProviders(cfg), cfg.ModelLimits))
|
||||
b.chatModels.SetConfigured(cfg.Models)
|
||||
catalog, models := b.catalogState()
|
||||
b.chatModels.SetModelCatalog(catalog, models)
|
||||
catalog := b.catalogState()
|
||||
b.chatModels.SetModelCatalog(catalog)
|
||||
b.log.Info("chat model runtime rebuilt", "providers", len(cfg.Providers), "models", len(cfg.Models))
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ type chatSetup struct {
|
||||
// than the value captured when the runner was built.
|
||||
ToolLimits func() modelloop.ToolLimits
|
||||
// LLM resolves the provider runtime at each use: a live provider-settings
|
||||
// or model-role-assignments update swaps the runtime wholesale (ai-sdk's
|
||||
// or model-aliases update swaps the runtime wholesale (ai-sdk's
|
||||
// Runtime caches the provider instances it built), so the pointer cannot
|
||||
// be captured at construction. nil means no model runtime is configured.
|
||||
LLM func() *runtime.Runtime
|
||||
|
||||
@@ -30,15 +30,15 @@ func (b *server) setupChatRuntime(ctx context.Context, cfg config.Config, actor
|
||||
// non-command message processing.
|
||||
providers := executionProviders(cfg)
|
||||
b.setLLM(modelloop.NewRuntime(providers, cfg.ModelLimits))
|
||||
// Transcription is a model-role capability, like the chat models it sits
|
||||
// Transcription is a model-alias capability, like the chat models it sits
|
||||
// beside: it is built here, on the model-owning side, from this process's
|
||||
// own [models]/[providers]. The Messaging Service carries a voice note's
|
||||
// bytes to the Gateway and never holds the credential.
|
||||
b.setupTranscriber(cfg, b.log)
|
||||
b.toolReg = tools.NewRegistry()
|
||||
chatModels := newChatModelManager(cfg.Models, cfg.Chat.Models)
|
||||
catalog, catalogModels := b.catalogState()
|
||||
chatModels.SetModelCatalog(catalog, catalogModels)
|
||||
chatModels := newChatModelManager(cfg.Models)
|
||||
catalog := b.catalogState()
|
||||
chatModels.SetModelCatalog(catalog)
|
||||
b.chatModels = chatModels
|
||||
|
||||
// ── Persona registry ─────────────────────────────────────────────
|
||||
|
||||
@@ -260,7 +260,7 @@ func (b *server) waitForNATSEndpoint(ctx context.Context) (servicekit.NATSEndpoi
|
||||
}
|
||||
}
|
||||
|
||||
func (b *server) catalogState() (modelcatalog.Snapshot, []string) { return b.catalog.State() }
|
||||
func (b *server) catalogState() modelcatalog.Snapshot { return b.catalog.State() }
|
||||
|
||||
// loadCatalog layers the model catalog under the running config. A catalog
|
||||
// that cannot be read leaves the configured providers and models in effect.
|
||||
@@ -270,9 +270,9 @@ func (b *server) loadCatalog(ctx context.Context) {
|
||||
b.log.Warn("model catalog unavailable; using configured providers and models", "err", err)
|
||||
return
|
||||
}
|
||||
models := modelcatalog.Apply(&b.cfg, snapshot)
|
||||
modelcatalog.Apply(&b.cfg, snapshot)
|
||||
b.cfgHolder.Set(b.cfg.Clone())
|
||||
b.catalog.Set(snapshot, models)
|
||||
b.catalog.Set(snapshot)
|
||||
}
|
||||
|
||||
func (b *server) startModelCatalogRefresh(ctx context.Context) {
|
||||
@@ -283,8 +283,8 @@ func (b *server) startModelCatalogRefresh(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
base := b.cfgHolder.Get().Clone()
|
||||
models := modelcatalog.Apply(&base, snapshot)
|
||||
b.catalog.Set(snapshot, models)
|
||||
modelcatalog.Apply(&base, snapshot)
|
||||
b.catalog.Set(snapshot)
|
||||
if err := b.relayer(ctx, base, ""); err != nil {
|
||||
b.log.Warn("model catalog refresh rejected with the settings; the running settings stay", "err", err)
|
||||
}
|
||||
@@ -295,7 +295,7 @@ func (b *server) startModelCatalogRefresh(ctx context.Context) {
|
||||
// chat runtime and tool providers are built from.
|
||||
var gatewayRuntimeKinds = []string{
|
||||
controlplane.ProviderSettingsKind,
|
||||
controlplane.ModelRoleAssignmentsKind,
|
||||
controlplane.ModelAliasesKind,
|
||||
controlplane.ToolSettingsKind,
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ func (b *server) startRuntimeWatches(ctx context.Context) error {
|
||||
// the providers resolve again.
|
||||
b.engines.OnChange(func() {
|
||||
base := b.cfgHolder.Get()
|
||||
catalog, _ := b.catalogState()
|
||||
catalog := b.catalogState()
|
||||
modelcatalog.Apply(&base, catalog)
|
||||
_ = b.relayer(ctx, base, controlplane.ProviderSettingsKind)
|
||||
})
|
||||
@@ -342,7 +342,7 @@ func (b *server) startRuntimeWatches(ctx context.Context) error {
|
||||
return
|
||||
}
|
||||
base := b.cfgHolder.Get()
|
||||
catalog, _ := b.catalogState()
|
||||
catalog := b.catalogState()
|
||||
modelcatalog.Apply(&base, catalog)
|
||||
lastApplyErr = b.relayer(ctx, base, kind)
|
||||
},
|
||||
|
||||
@@ -23,7 +23,7 @@ const ChannelSettingsKind = controlplanerpc.ChannelSettingsKind
|
||||
func seedChannels(cfg config.Config) any {
|
||||
chat := cfg.Chat
|
||||
return channelSettings{
|
||||
Operator: chat.Operator, Workspace: chat.Workspace, UnrestrictedFilesystem: chat.UnrestrictedFilesystem, ShowToolCalls: chat.ShowToolCalls, MaxSteps: chat.MaxSteps, Models: chat.Models,
|
||||
Operator: chat.Operator, Workspace: chat.Workspace, UnrestrictedFilesystem: chat.UnrestrictedFilesystem, ShowToolCalls: chat.ShowToolCalls, MaxSteps: chat.MaxSteps,
|
||||
Telegram: telegramSettings{AllowedUserIDs: chat.Telegram.AllowedUserIDs, Token: chat.Telegram.Token, CredentialConfigured: chat.Telegram.Token != (config.SecretRef{})},
|
||||
RateLimit: rateLimitSettings{Window: channelDuration(chat.RateLimit.Window), MaxRequests: chat.RateLimit.MaxRequests},
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ package controlplane
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -50,6 +52,7 @@ type Server struct {
|
||||
store ResourceStore
|
||||
definitions map[string]Definition
|
||||
ordered []Definition
|
||||
steps workflow.StepRegistry
|
||||
}
|
||||
|
||||
// NewServer builds the control plane server the State Store serves. steps is
|
||||
@@ -66,7 +69,7 @@ func NewServer(resources ResourceStore, steps *workflow.Manager) (*Server, error
|
||||
for _, definition := range definitions {
|
||||
byKind[definition.Kind] = definition
|
||||
}
|
||||
return &Server{store: resources, definitions: byKind, ordered: definitions}, nil
|
||||
return &Server{store: resources, definitions: byKind, ordered: definitions, steps: registry}, nil
|
||||
}
|
||||
|
||||
func (s *Server) Catalog(context.Context, *pb.CatalogRequest) (*pb.CatalogResponse, error) {
|
||||
@@ -169,6 +172,11 @@ func (s *Server) Command(ctx context.Context, request *pb.CommandRequest) (*pb.C
|
||||
if err != nil {
|
||||
return nil, mapError(err)
|
||||
}
|
||||
if request.Kind == WorkflowDefinitionsKind {
|
||||
if err := s.checkModelAliases(ctx, value); err != nil {
|
||||
return nil, mapError(err)
|
||||
}
|
||||
}
|
||||
resource, err := s.store.PutResource(ctx, storecontract.ResourceWrite{OrgID: requestOrg(ctx), Kind: request.Kind, Value: value, Actor: request.Actor, Source: request.Source, RequestID: request.RequestId, ExpectedVersion: request.ExpectedVersion, At: time.Now().UTC()})
|
||||
if err != nil {
|
||||
return nil, mapError(err)
|
||||
@@ -247,3 +255,26 @@ func mapError(err error) error {
|
||||
return status.Error(codes.Unavailable, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// checkModelAliases refuses workflow definitions whose agent steps name a
|
||||
// model alias the instance does not define.
|
||||
func (s *Server) checkModelAliases(ctx context.Context, value []byte) error {
|
||||
aliases := map[string]string{}
|
||||
resource, err := s.store.Resource(ctx, storecontract.DefaultOrgID, ModelAliasesKind)
|
||||
switch {
|
||||
case err == nil:
|
||||
if err := json.Unmarshal(resource.Value, &aliases); err != nil {
|
||||
return fmt.Errorf("read model aliases: %w", err)
|
||||
}
|
||||
case !errors.Is(err, storecontract.ErrResourceNotFound):
|
||||
return err
|
||||
}
|
||||
var collection workflow.WorkflowDefinitionCollection
|
||||
if err := json.Unmarshal(value, &collection); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := workflow.CheckModelAliases(collection, s.steps, aliases); err != nil {
|
||||
return fmt.Errorf("%w: %w", ErrValidation, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ProviderSettingsKind = "provider-settings"
|
||||
ModelRoleAssignmentsKind = "model-role-assignments"
|
||||
ProviderSettingsKind = "provider-settings"
|
||||
ModelAliasesKind = "model-aliases"
|
||||
)
|
||||
|
||||
var bootDerivedProviderEnv = regexp.MustCompile(`^ARCHIE_PROVIDER_[0-9A-F]{16}_API_KEY$`)
|
||||
@@ -27,7 +27,7 @@ type providerDocument struct {
|
||||
func modelDefinitions() []Definition {
|
||||
return []Definition{
|
||||
{Kind: ProviderSettingsKind, Title: "Providers", ApplyMode: "live", Document: map[string]providerDocument{}, Seed: seedProviders, Validate: validateProviders},
|
||||
{Kind: ModelRoleAssignmentsKind, Title: "Model role assignments", ApplyMode: "live", Document: map[string]string{}, Seed: func(cfg config.Config) any { return cfg.Models }, Validate: validateModelRoles},
|
||||
{Kind: ModelAliasesKind, Title: "Model aliases", ApplyMode: "live", Document: map[string]string{}, Seed: func(cfg config.Config) any { return cfg.Models }, Validate: validateModelAliases},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,12 +66,20 @@ func rejectBootDerivedProviderEnv(name string, provider providerDocument) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateModelRoles(input []byte) error {
|
||||
var modelAliasName = regexp.MustCompile(`^[a-z0-9][a-z0-9._-]*$`)
|
||||
|
||||
func validateModelAliases(input []byte) error {
|
||||
return validateAs(input, func(models map[string]string) error {
|
||||
for role, model := range models {
|
||||
if strings.TrimSpace(role) == "" || !strings.Contains(model, "/") {
|
||||
return fmt.Errorf("model role %q must reference provider/model", role)
|
||||
for alias, model := range models {
|
||||
if !modelAliasName.MatchString(alias) {
|
||||
return fmt.Errorf("model alias %q must be lowercase letters, digits, '.', '_' or '-'", alias)
|
||||
}
|
||||
if provider, name, ok := strings.Cut(model, "/"); !ok || provider == "" || name == "" {
|
||||
return fmt.Errorf("model alias %q must reference provider/model", alias)
|
||||
}
|
||||
}
|
||||
if _, ok := models[config.DefaultModelAlias]; !ok && len(models) > 0 {
|
||||
return fmt.Errorf("model alias %q is required", config.DefaultModelAlias)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -80,9 +80,9 @@ func runtimeConfigFrom(ctx context.Context, reader controlplanerpc.ResourceReade
|
||||
}); err != nil {
|
||||
return config.Config{}, nil, err
|
||||
}
|
||||
// Stored role assignments replace cfg.Models outright.
|
||||
if err := layerResource(ctx, reader, versions, ModelRoleAssignmentsKind, func(roles map[string]string) error {
|
||||
out.Models = roles
|
||||
// Stored aliases replace cfg.Models outright.
|
||||
if err := layerResource(ctx, reader, versions, ModelAliasesKind, func(aliases map[string]string) error {
|
||||
out.Models = aliases
|
||||
return nil
|
||||
}); err != nil {
|
||||
return config.Config{}, nil, err
|
||||
|
||||
+86
-27
@@ -1,40 +1,68 @@
|
||||
{
|
||||
"description": "Shared accept/reject fixtures for the control-plane validators the dashboard hand-mirrors in ui/src/settings/validation.ts. The control plane is the authority: every case's `valid` is what internal/app/controlplane accepts or refuses. The Go test in this package runs the real server validators over these cases; the node test ui/test/control-plane-validator-parity.test.ts runs the real dashboard validators over the same cases. A one-sided change to either rule makes one of the two tests fail, which is the tie that stops the two implementations drifting apart (archie-core-ui-dashboard-3). Add a case here, never only to one side.",
|
||||
"cases": {
|
||||
"model-role-assignments": [
|
||||
"model-aliases": [
|
||||
{
|
||||
"why": "a plain provider/model value",
|
||||
"value": { "builder": "openai/gpt-4o" },
|
||||
"value": {
|
||||
"default": "openai/gpt-4o"
|
||||
},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"why": "a trailing space: the server only asks for a slash, so the dashboard must not refuse it",
|
||||
"value": { "builder": "openai/gpt-4o " },
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"why": "a leading space: the server only asks for a slash, so the dashboard must not refuse it",
|
||||
"value": { "builder": " openai/gpt-4o" },
|
||||
"why": "a trailing space: the server only splits on the slash, so the dashboard must not refuse it",
|
||||
"value": {
|
||||
"default": "openai/gpt-4o "
|
||||
},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"why": "a model id with a colon (a real ollama tag), which a stricter shape would wrongly refuse",
|
||||
"value": { "planner": "ollama/qwen2.5-coder:7b" },
|
||||
"value": {
|
||||
"default": "openai/gpt-4o",
|
||||
"fast": "ollama/qwen2.5-coder:7b"
|
||||
},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"why": "an empty table: nothing configured yet",
|
||||
"value": {},
|
||||
"valid": true
|
||||
},
|
||||
{
|
||||
"why": "no slash at all",
|
||||
"value": { "builder": "gpt-4o" },
|
||||
"value": {
|
||||
"default": "gpt-4o"
|
||||
},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"why": "an empty model half",
|
||||
"value": {
|
||||
"default": "openai/"
|
||||
},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"why": "an empty model: the server refuses it, so the dashboard must too (SystemModelsPage deletes the key rather than storing one)",
|
||||
"value": { "builder": "" },
|
||||
"value": {
|
||||
"default": ""
|
||||
},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"why": "a blank role key",
|
||||
"value": { "": "openai/gpt-4o" },
|
||||
"why": "aliases without the default alias",
|
||||
"value": {
|
||||
"fast": "openai/gpt-4o"
|
||||
},
|
||||
"valid": false
|
||||
},
|
||||
{
|
||||
"why": "an alias name with capitals or spaces",
|
||||
"value": {
|
||||
"default": "openai/gpt-4o",
|
||||
"Fast model": "openai/gpt-4o"
|
||||
},
|
||||
"valid": false
|
||||
}
|
||||
],
|
||||
@@ -45,7 +73,9 @@
|
||||
"poll_interval": "1m0s",
|
||||
"max_retries": 0,
|
||||
"label": "archie",
|
||||
"dispatch": { "trigger": "assignee" }
|
||||
"dispatch": {
|
||||
"trigger": "assignee"
|
||||
}
|
||||
},
|
||||
"valid": true
|
||||
},
|
||||
@@ -54,7 +84,9 @@
|
||||
"value": {
|
||||
"poll_interval": "30s",
|
||||
"max_retries": 3,
|
||||
"dispatch": { "trigger": "assignee" }
|
||||
"dispatch": {
|
||||
"trigger": "assignee"
|
||||
}
|
||||
},
|
||||
"valid": true
|
||||
},
|
||||
@@ -63,7 +95,9 @@
|
||||
"value": {
|
||||
"poll_interval": "1h30m",
|
||||
"label": "archie",
|
||||
"dispatch": { "trigger": "either" }
|
||||
"dispatch": {
|
||||
"trigger": "either"
|
||||
}
|
||||
},
|
||||
"valid": true
|
||||
},
|
||||
@@ -71,7 +105,9 @@
|
||||
"why": "a fractional duration the server's parser accepts",
|
||||
"value": {
|
||||
"poll_interval": "1.5h",
|
||||
"dispatch": { "trigger": "assignee" }
|
||||
"dispatch": {
|
||||
"trigger": "assignee"
|
||||
}
|
||||
},
|
||||
"valid": true
|
||||
},
|
||||
@@ -80,7 +116,9 @@
|
||||
"value": {
|
||||
"poll_interval": "0s",
|
||||
"label": "archie",
|
||||
"dispatch": { "trigger": "assignee" }
|
||||
"dispatch": {
|
||||
"trigger": "assignee"
|
||||
}
|
||||
},
|
||||
"valid": false
|
||||
},
|
||||
@@ -89,7 +127,9 @@
|
||||
"value": {
|
||||
"poll_interval": "nonsense",
|
||||
"label": "archie",
|
||||
"dispatch": { "trigger": "assignee" }
|
||||
"dispatch": {
|
||||
"trigger": "assignee"
|
||||
}
|
||||
},
|
||||
"valid": false
|
||||
},
|
||||
@@ -98,7 +138,9 @@
|
||||
"value": {
|
||||
"poll_interval": "30s",
|
||||
"max_retries": 3,
|
||||
"dispatch": { "trigger": "label" }
|
||||
"dispatch": {
|
||||
"trigger": "label"
|
||||
}
|
||||
},
|
||||
"valid": false
|
||||
},
|
||||
@@ -108,7 +150,9 @@
|
||||
"poll_interval": "30s",
|
||||
"max_retries": 0,
|
||||
"label": "",
|
||||
"dispatch": { "trigger": "either" }
|
||||
"dispatch": {
|
||||
"trigger": "either"
|
||||
}
|
||||
},
|
||||
"valid": false
|
||||
}
|
||||
@@ -120,7 +164,10 @@
|
||||
{
|
||||
"id": "daily",
|
||||
"kind": "workflow",
|
||||
"schedule": { "kind": "interval", "interval": "24h0m0s" }
|
||||
"schedule": {
|
||||
"kind": "interval",
|
||||
"interval": "24h0m0s"
|
||||
}
|
||||
}
|
||||
],
|
||||
"valid": true
|
||||
@@ -132,7 +179,10 @@
|
||||
"id": "nightly",
|
||||
"kind": "workflow",
|
||||
"pool": "parallel",
|
||||
"schedule": { "kind": "cron", "cron": "0 3 * * *" }
|
||||
"schedule": {
|
||||
"kind": "cron",
|
||||
"cron": "0 3 * * *"
|
||||
}
|
||||
}
|
||||
],
|
||||
"valid": true
|
||||
@@ -143,7 +193,10 @@
|
||||
{
|
||||
"id": "",
|
||||
"kind": "workflow",
|
||||
"schedule": { "kind": "interval", "interval": "24h0m0s" }
|
||||
"schedule": {
|
||||
"kind": "interval",
|
||||
"interval": "24h0m0s"
|
||||
}
|
||||
}
|
||||
],
|
||||
"valid": false
|
||||
@@ -154,12 +207,18 @@
|
||||
{
|
||||
"id": "daily",
|
||||
"kind": "workflow",
|
||||
"schedule": { "kind": "interval", "interval": "24h0m0s" }
|
||||
"schedule": {
|
||||
"kind": "interval",
|
||||
"interval": "24h0m0s"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "daily",
|
||||
"kind": "workflow",
|
||||
"schedule": { "kind": "interval", "interval": "1h0m0s" }
|
||||
"schedule": {
|
||||
"kind": "interval",
|
||||
"interval": "1h0m0s"
|
||||
}
|
||||
}
|
||||
],
|
||||
"valid": false
|
||||
|
||||
@@ -348,8 +348,8 @@ type Config struct {
|
||||
Dispatch Dispatch `toml:"dispatch" yaml:"dispatch"`
|
||||
Review Review `toml:"review" yaml:"review"`
|
||||
|
||||
// Models maps a role ("planner", "builder", "triage") to a runtime
|
||||
// model ref ("provider/model").
|
||||
// Models maps a model alias ("default", "fast", "embedding") to a
|
||||
// runtime model ref ("provider/model"). Resolve it with ResolveModel.
|
||||
Models map[string]string `toml:"models" yaml:"models"`
|
||||
|
||||
Providers map[string]Provider `toml:"providers" yaml:"providers"`
|
||||
@@ -513,7 +513,6 @@ func (c Config) Clone() Config {
|
||||
c.Providers = maps.Clone(c.Providers)
|
||||
c.Repos = cloneRepos(c.Repos)
|
||||
c.Identities = cloneIdentities(c.Identities)
|
||||
c.Chat.Models = append([]string(nil), c.Chat.Models...)
|
||||
c.Chat.Telegram.AllowedUserIDs = append([]int64(nil), c.Chat.Telegram.AllowedUserIDs...)
|
||||
c.Bindings.PreviousEncryptionKeys = append([]SecretRef(nil), c.Bindings.PreviousEncryptionKeys...)
|
||||
c.Tools.MCPServers = cloneMCPServers(c.Tools.MCPServers)
|
||||
@@ -864,11 +863,7 @@ type ChatConfig struct {
|
||||
// channel. Off by default.
|
||||
ShowToolCalls bool `toml:"show_tool_calls" yaml:"show_tool_calls"`
|
||||
// MaxSteps caps model/tool round-trips per chat turn. Zero uses the default.
|
||||
MaxSteps int `toml:"max_steps" yaml:"max_steps"`
|
||||
// Models is the optional interactive-chat model catalog. When empty,
|
||||
// chat falls back to the distinct model references assigned to workflow
|
||||
// roles in the top-level [models] table.
|
||||
Models []string `toml:"models" yaml:"models"`
|
||||
MaxSteps int `toml:"max_steps" yaml:"max_steps"`
|
||||
Telegram TelegramConfig `toml:"telegram" yaml:"telegram"`
|
||||
// RateLimit budgets inbound messages per channel and sender. Off unless set.
|
||||
// Seeds the channel-settings resource.
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ModelPurpose is what a model is used for. Each purpose has a default alias
|
||||
// that an empty alias resolves to.
|
||||
type ModelPurpose string
|
||||
|
||||
const (
|
||||
PurposeAgent ModelPurpose = "agent"
|
||||
PurposeChat ModelPurpose = "chat"
|
||||
PurposeEmbedding ModelPurpose = "embedding"
|
||||
PurposeTranscription ModelPurpose = "transcription"
|
||||
)
|
||||
|
||||
// DefaultModelAlias is the alias agent steps and chat use when none is named.
|
||||
const DefaultModelAlias = "default"
|
||||
|
||||
// DefaultAlias is the alias an empty alias means for purpose.
|
||||
func (p ModelPurpose) DefaultAlias() string {
|
||||
switch p {
|
||||
case PurposeEmbedding, PurposeTranscription:
|
||||
return string(p)
|
||||
default:
|
||||
return DefaultModelAlias
|
||||
}
|
||||
}
|
||||
|
||||
// ResolveModel returns the "provider/model" ref aliases maps alias to, or
|
||||
// purpose's default alias when alias is empty. An unknown alias is an error,
|
||||
// never a substitute.
|
||||
func ResolveModel(aliases map[string]string, alias string, purpose ModelPurpose) (string, error) {
|
||||
alias = strings.TrimSpace(alias)
|
||||
if alias == "" {
|
||||
alias = purpose.DefaultAlias()
|
||||
}
|
||||
ref := strings.TrimSpace(aliases[alias])
|
||||
if ref == "" {
|
||||
return "", fmt.Errorf("no model alias %q is configured (Settings > Models)", alias)
|
||||
}
|
||||
return ref, nil
|
||||
}
|
||||
|
||||
// ChatAliases are the aliases chat may switch between: every alias but the
|
||||
// embedding and transcription ones, sorted. Never nil.
|
||||
func ChatAliases(aliases map[string]string) []string {
|
||||
out := make([]string, 0, len(aliases))
|
||||
for _, alias := range slices.Sorted(maps.Keys(aliases)) {
|
||||
if alias != string(PurposeEmbedding) && alias != string(PurposeTranscription) {
|
||||
out = append(out, alias)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -30,10 +30,10 @@ func Processes() []string { return []string{Daemon, Gateway, Messaging} }
|
||||
// Applicability names the consumers of each resource, including boot-only settings.
|
||||
func Applicability() map[string][]string {
|
||||
kinds := map[string][]string{}
|
||||
for _, kind := range []string{"task-policy", "provider-settings", "model-role-assignments", "repository-policies", "scheduling-policy", "tool-settings", "plugin-settings", "review-settings", "channel-settings", "container-runtime-policies", "credential-bindings", "identity-grants", "agent-profiles", "workflow-execution-settings", "extension-settings", "workflow-definitions", "workflow-enablement", "schedules", "eda-playbooks"} {
|
||||
for _, kind := range []string{"task-policy", "provider-settings", "model-aliases", "repository-policies", "scheduling-policy", "tool-settings", "plugin-settings", "review-settings", "channel-settings", "container-runtime-policies", "credential-bindings", "identity-grants", "agent-profiles", "workflow-execution-settings", "extension-settings", "workflow-definitions", "workflow-enablement", "schedules", "eda-playbooks"} {
|
||||
kinds[kind] = []string{Daemon}
|
||||
}
|
||||
for _, kind := range []string{"provider-settings", "model-role-assignments", "tool-settings", "channel-settings", "plugin-settings", "extension-settings", "personas", "soul", "skills", "curators"} {
|
||||
for _, kind := range []string{"provider-settings", "model-aliases", "tool-settings", "channel-settings", "plugin-settings", "extension-settings", "personas", "soul", "skills", "curators"} {
|
||||
kinds[kind] = append(kinds[kind], Gateway)
|
||||
}
|
||||
for _, kind := range []string{"channel-settings", "extension-settings"} {
|
||||
|
||||
@@ -17,9 +17,8 @@ import (
|
||||
// own mission, gate and result handler.
|
||||
type AgentStage struct {
|
||||
Name string
|
||||
// Role selects the model via cfg.Models[Role]; falls back to
|
||||
// cfg.Models["builder"].
|
||||
Role string
|
||||
// Model is the model alias; empty means the default alias.
|
||||
Model string
|
||||
ReadOnly bool
|
||||
// Mission produces the task statement from the current context.
|
||||
Mission func(*TaskContext) string
|
||||
@@ -76,17 +75,9 @@ func (a AgentStage) Stage() Stage {
|
||||
}}
|
||||
}
|
||||
|
||||
// resolveModel picks the model reference for this stage's Role, falling
|
||||
// back to "builder".
|
||||
// resolveModel resolves this stage's model alias.
|
||||
func (a AgentStage) resolveModel(tc *TaskContext) (string, error) {
|
||||
modelRef := tc.Cfg.Models[a.Role]
|
||||
if modelRef == "" {
|
||||
modelRef = tc.Cfg.Models["builder"]
|
||||
}
|
||||
if modelRef == "" {
|
||||
return "", fmt.Errorf("no model configured for role %q (set [models] in config)", a.Role)
|
||||
}
|
||||
return modelRef, nil
|
||||
return config.ResolveModel(tc.Cfg.Models, a.Model, config.PurposeAgent)
|
||||
}
|
||||
|
||||
// buildRequest assembles the agentrun.Request for this stage's run.
|
||||
|
||||
@@ -28,8 +28,8 @@ type agentRunSettings struct {
|
||||
// Mission is what the agent is asked to do. The workflow's inputs are
|
||||
// appended to it as structured data.
|
||||
Mission string `yaml:"mission" doc:"What the agent is asked to do. May reference {{ task.* }}, {{ inputs.* }} and {{ steps.<id>.* }}."`
|
||||
// Role selects the model (cfg.Models[Role]); empty means builder.
|
||||
Role string `yaml:"role" doc:"Which configured model role runs the agent, e.g. builder or planner. Empty means builder."`
|
||||
// Model is the model alias that runs the agent; empty means the default.
|
||||
Model string `yaml:"model" doc:"The model alias that runs the agent, e.g. default or fast. Empty means default."`
|
||||
// ReadOnly restricts the agent to read-only tools.
|
||||
ReadOnly bool `yaml:"read_only" title:"Read only" doc:"Restrict the agent to read-only tools."`
|
||||
// Gate holds the agent to the repository's gate before it may finish:
|
||||
@@ -65,13 +65,9 @@ func newAgentRunStage(settings yaml.Node) (Stage, error) {
|
||||
if err != nil {
|
||||
return Stage{}, fmt.Errorf("%s: settings.result: %w", AgentRunStepName, err)
|
||||
}
|
||||
role := s.Role
|
||||
if role == "" {
|
||||
role = "builder"
|
||||
}
|
||||
agent := AgentStage{
|
||||
Name: AgentRunStepName,
|
||||
Role: role,
|
||||
Model: s.Model,
|
||||
ReadOnly: s.ReadOnly,
|
||||
Mission: func(*TaskContext) string { return s.Mission },
|
||||
ExtraRules: s.ExtraRules,
|
||||
|
||||
@@ -232,3 +232,46 @@ func (step StepRecord) branches() map[string][]StepRecord {
|
||||
}
|
||||
return step.Parallel
|
||||
}
|
||||
|
||||
// CheckModelAliases reports the first agent.run step in collection that names
|
||||
// a model alias aliases does not define. An empty alias means the default and
|
||||
// is resolved at dispatch.
|
||||
func CheckModelAliases(collection WorkflowDefinitionCollection, registry StepRegistry, aliases map[string]string) error {
|
||||
for _, entry := range collection.Definitions {
|
||||
definition, err := ParseDefinition(entry.YAML, registry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := checkStepAliases(entry.ID, definition.Steps, aliases); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkStepAliases(workflowID string, steps []StepRecord, aliases map[string]string) error {
|
||||
for _, step := range steps {
|
||||
if step.Type == AgentRunStepName {
|
||||
var s agentRunSettings
|
||||
if err := step.Settings.Decode(&s); err != nil {
|
||||
return fmt.Errorf("workflow %q step %q: %w", workflowID, step.ID, err)
|
||||
}
|
||||
if s.Model != "" && aliases[s.Model] == "" {
|
||||
return fmt.Errorf("workflow %q step %q: model alias %q is not configured", workflowID, step.ID, s.Model)
|
||||
}
|
||||
}
|
||||
for _, branch := range step.Parallel {
|
||||
if err := checkStepAliases(workflowID, branch, aliases); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if step.Switch != nil {
|
||||
for _, branch := range step.Switch.Cases {
|
||||
if err := checkStepAliases(workflowID, branch, aliases); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/agentrun"
|
||||
"github.com/samcharles93/archie-core/internal/events"
|
||||
)
|
||||
@@ -73,7 +74,10 @@ func runBaselineFix(ctx context.Context, tc *TaskContext, argv []string, out []b
|
||||
clip(extractFailingGateOutput(string(out)), baselineMissionBytes),
|
||||
)
|
||||
|
||||
modelRef := tc.Cfg.Models["builder"]
|
||||
modelRef, err := config.ResolveModel(tc.Cfg.Models, "", config.PurposeAgent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req := agentrun.Request{
|
||||
Version: agentrun.ProtocolVersion,
|
||||
TaskID: tc.Task.ID,
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/agentrun"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/prreview"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
@@ -225,7 +226,7 @@ func scoreAIGenerated(ctx context.Context, tc *TaskContext, meta PRMetadata) (fl
|
||||
"with status \"passed\".",
|
||||
meta.Title, meta.Body, strings.Join(meta.Commits, "\n"),
|
||||
)
|
||||
res, err := runPRReviewAgent(ctx, tc, scratch, "intake-ai-score", "classification", mission, 6, []agentrun.CaptureTool{{
|
||||
res, err := runPRReviewAgent(ctx, tc, scratch, "intake-ai-score", mission, 6, []agentrun.CaptureTool{{
|
||||
Name: "score_ai_generated", Description: "Record the machine-written confidence. Call exactly once, before finish.",
|
||||
Parameters: params, RequiredFields: []string{"confidence"}, MaxCalls: 1,
|
||||
}})
|
||||
@@ -313,7 +314,7 @@ func stagePRAnatomy() Stage {
|
||||
skipPhase(tc, "anatomy")
|
||||
return nil
|
||||
}
|
||||
res, err := runPRReviewAgent(ctx, tc, tc.prReview.snapshotDir, "anatomy", "review", mission, 15, nil)
|
||||
res, err := runPRReviewAgent(ctx, tc, tc.prReview.snapshotDir, "anatomy", mission, 15, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -394,7 +395,7 @@ func runLens(ctx context.Context, tc *TaskContext, name, angle string) ([]prrevi
|
||||
name, angle, tc.prReview.metadata.Title, tc.prReview.metadata.Body, clip(tc.prReview.diff, 60000),
|
||||
operatorInstructionsBlock(tc),
|
||||
)
|
||||
res, err := runPRReviewAgent(ctx, tc, tc.prReview.snapshotDir, "lens-"+name, "review", mission, 15, []agentrun.CaptureTool{{
|
||||
res, err := runPRReviewAgent(ctx, tc, tc.prReview.snapshotDir, "lens-"+name, mission, 15, []agentrun.CaptureTool{{
|
||||
Name: "propose_dimensions", Description: "Record this lens's proposed review dimensions. Call exactly once, before finish.",
|
||||
Parameters: params, RequiredFields: []string{"dimensions"}, MaxCalls: 1,
|
||||
}})
|
||||
@@ -558,9 +559,9 @@ const prReviewMaxSteps = 25
|
||||
func runReviewerAgent(
|
||||
ctx context.Context, tc *TaskContext, name, mission string, captureTools []agentrun.CaptureTool,
|
||||
) (agentrun.Result, error) {
|
||||
modelRef := tc.Cfg.Models["review"]
|
||||
if modelRef == "" {
|
||||
return agentrun.Result{}, fmt.Errorf("no model configured for role %q (set [models] in config)", "review")
|
||||
modelRef, err := config.ResolveModel(tc.Cfg.Models, "", config.PurposeAgent)
|
||||
if err != nil {
|
||||
return agentrun.Result{}, err
|
||||
}
|
||||
req := agentrun.Request{
|
||||
Version: agentrun.ProtocolVersion, TaskID: tc.Task.ID, Attempt: tc.Task.Attempt,
|
||||
@@ -657,7 +658,7 @@ func polishFinding(ctx context.Context, tc *TaskContext, f prreview.ScoredFindin
|
||||
"call finish with status \"passed\".",
|
||||
f.Title, f.Body,
|
||||
)
|
||||
res, err := runPRReviewAgent(ctx, tc, tc.prReview.snapshotDir, "polish", "classification", mission, 4, []agentrun.CaptureTool{{
|
||||
res, err := runPRReviewAgent(ctx, tc, tc.prReview.snapshotDir, "polish", mission, 4, []agentrun.CaptureTool{{
|
||||
Name: "polish", Description: "Record the tightened comment body. Call exactly once, before finish.",
|
||||
Parameters: params, RequiredFields: []string{"body"}, MaxCalls: 1,
|
||||
}})
|
||||
@@ -723,9 +724,9 @@ func postPRReview(ctx context.Context, tc *TaskContext) error {
|
||||
// runPRReviewAgent runs one read-only agent call in workspace and returns an
|
||||
// error for any result that did not pass.
|
||||
func runPRReviewAgent(
|
||||
ctx context.Context, tc *TaskContext, workspace, name, role, mission string, maxSteps int, captureTools []agentrun.CaptureTool,
|
||||
ctx context.Context, tc *TaskContext, workspace, name, mission string, maxSteps int, captureTools []agentrun.CaptureTool,
|
||||
) (agentrun.Result, error) {
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, workspace, name, role, mission, maxSteps, captureTools)
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, workspace, name, mission, maxSteps, captureTools)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
@@ -742,11 +743,11 @@ func runPRReviewAgent(
|
||||
// runPRReviewAgentRecorded builds the request for a pr-review agent call,
|
||||
// records its step, and returns the runtime's result unchanged.
|
||||
func runPRReviewAgentRecorded(
|
||||
ctx context.Context, tc *TaskContext, workspace, name, role, mission string, maxSteps int, captureTools []agentrun.CaptureTool,
|
||||
ctx context.Context, tc *TaskContext, workspace, name, mission string, maxSteps int, captureTools []agentrun.CaptureTool,
|
||||
) (agentrun.Result, error) {
|
||||
modelRef := tc.Cfg.Models[role]
|
||||
if modelRef == "" {
|
||||
return agentrun.Result{}, fmt.Errorf("no model configured for role %q (set [models] in config)", role)
|
||||
modelRef, err := config.ResolveModel(tc.Cfg.Models, "", config.PurposeAgent)
|
||||
if err != nil {
|
||||
return agentrun.Result{}, err
|
||||
}
|
||||
req := agentrun.Request{
|
||||
Version: agentrun.ProtocolVersion, TaskID: tc.Task.ID, Attempt: tc.Task.Attempt,
|
||||
|
||||
@@ -94,7 +94,7 @@ func runPrecisionGate(ctx context.Context, tc *TaskContext, findings []prreview.
|
||||
"finish with status \"passed\".",
|
||||
listing.String(),
|
||||
)
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, tc.prReview.snapshotDir, "precision-gate", "classification", mission, 15, []agentrun.CaptureTool{{
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, tc.prReview.snapshotDir, "precision-gate", mission, 15, []agentrun.CaptureTool{{
|
||||
Name: "precision_gate", Description: "Record each finding's keep/drop verdict. Call exactly once, before finish.",
|
||||
Parameters: precisionGateSchema, RequiredFields: []string{"verdicts"}, MaxCalls: 1,
|
||||
}})
|
||||
@@ -240,7 +240,7 @@ func runEvidenceVerifier(ctx context.Context, tc *TaskContext, findings []prrevi
|
||||
"call finish with status \"passed\".",
|
||||
evidenceListing(tc, candidates),
|
||||
)
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, tc.prReview.snapshotDir, "evidence-verifier", "review", mission, 15, []agentrun.CaptureTool{{
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, tc.prReview.snapshotDir, "evidence-verifier", mission, 15, []agentrun.CaptureTool{{
|
||||
Name: "verify_findings", Description: "Record each finding's evidence verdict. Call exactly once, before finish.",
|
||||
Parameters: verifyFindingsSchema, RequiredFields: []string{"verdicts"}, MaxCalls: 1,
|
||||
}})
|
||||
@@ -366,7 +366,7 @@ func runAdversary(ctx context.Context, tc *TaskContext, findings []prreview.Find
|
||||
"nothing new). Then call finish with status \"passed\".",
|
||||
adversarySkepticism(tc.prReview.aiGenerated), findingsListing(findings),
|
||||
)
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, tc.prReview.snapshotDir, "adversary", "review", mission, 25, []agentrun.CaptureTool{
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, tc.prReview.snapshotDir, "adversary", mission, 25, []agentrun.CaptureTool{
|
||||
{
|
||||
Name: "adversary_verdicts", Description: "Record each finding's adversary verdict. Call exactly once, before finish.",
|
||||
Parameters: adversaryVerdictsSchema, RequiredFields: []string{"verdicts"}, MaxCalls: 1,
|
||||
@@ -450,7 +450,7 @@ func runCompoundClusterCheck(ctx context.Context, tc *TaskContext, clusterID str
|
||||
"once with the indices of the findings that compound (an empty array if none "+
|
||||
"do). Then call finish with status \"passed\".\n\n%s", listing.String(),
|
||||
)
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, tc.prReview.snapshotDir, "compound-"+clusterID, "review", mission, 15, []agentrun.CaptureTool{{
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, tc.prReview.snapshotDir, "compound-"+clusterID, mission, 15, []agentrun.CaptureTool{{
|
||||
Name: "compound_findings", Description: "Record which findings compound. Call exactly once, before finish.",
|
||||
Parameters: params, RequiredFields: []string{"indices"}, MaxCalls: 1,
|
||||
}})
|
||||
@@ -555,7 +555,7 @@ func runConsistencyVerification(ctx context.Context, tc *TaskContext) error {
|
||||
"held), then call finish with status \"passed\".",
|
||||
clip(tc.prReview.diff, 60000),
|
||||
)
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, tc.prReview.snapshotDir, "consistency", "review", mission, 25, []agentrun.CaptureTool{reportFindingsTool})
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, tc.prReview.snapshotDir, "consistency", mission, 25, []agentrun.CaptureTool{reportFindingsTool})
|
||||
if err != nil || res.Status != agentrun.StatusPassed {
|
||||
return nil //nolint:nilerr // a consistency call that could not run reports no broken obligations rather than failing the stage
|
||||
}
|
||||
@@ -613,7 +613,7 @@ func runMergeGateCall(ctx context.Context, tc *TaskContext, f prreview.ScoredFin
|
||||
"Call classify_blocking exactly once, then call finish with status \"passed\".",
|
||||
f.Severity, f.Title, f.File, f.LineStart, f.Body,
|
||||
)
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, tc.prReview.snapshotDir, "merge-gate", "classification", mission, 6, []agentrun.CaptureTool{{
|
||||
res, err := runPRReviewAgentRecorded(ctx, tc, tc.prReview.snapshotDir, "merge-gate", mission, 6, []agentrun.CaptureTool{{
|
||||
Name: "classify_blocking", Description: "Record the blocking verdict. Call exactly once, before finish.",
|
||||
Parameters: mergeGateSchema, RequiredFields: []string{"blocking"}, MaxCalls: 1,
|
||||
}})
|
||||
|
||||
@@ -4,7 +4,6 @@ steps:
|
||||
- id: assess
|
||||
type: agent.run
|
||||
settings:
|
||||
role: planner
|
||||
read_only: true
|
||||
mission: |
|
||||
Assess whether this feature request fits the project {{ task.repository }}.
|
||||
@@ -35,7 +34,6 @@ steps:
|
||||
- id: prd
|
||||
type: agent.run
|
||||
settings:
|
||||
role: planner
|
||||
read_only: true
|
||||
mission: |
|
||||
Write a PRD for this accepted feature request on {{ task.repository }}.
|
||||
|
||||
@@ -7,7 +7,6 @@ steps:
|
||||
- id: plan
|
||||
type: agent.run
|
||||
settings:
|
||||
role: planner
|
||||
read_only: true
|
||||
mission: |
|
||||
Produce a concrete implementation plan for this {{ task.kind }} on the repository {{ task.repository }}.
|
||||
|
||||
@@ -7,7 +7,6 @@ steps:
|
||||
- id: analyse
|
||||
type: agent.run
|
||||
settings:
|
||||
role: planner
|
||||
read_only: true
|
||||
mission: |
|
||||
Analyse this {{ task.kind }} for the repository {{ task.repository }} and determine the problem surface.
|
||||
|
||||
@@ -4,7 +4,6 @@ steps:
|
||||
- id: classify
|
||||
type: agent.run
|
||||
settings:
|
||||
role: planner
|
||||
read_only: true
|
||||
mission: |
|
||||
Triage this {{ task.kind }} on the repository {{ task.repository }}: decide whether it needs a code change at all, and if so which workflow suits it best.
|
||||
|
||||
@@ -47,22 +47,7 @@ func (a *LocalChatAdapter) Snapshot(ctx context.Context) (ChatSnapshot, error) {
|
||||
s := ChatSnapshot{Sessions: sessions, Models: []string{}, Providers: []string{}, Personas: []string{}, ModelsByProvider: map[string][]string{}, ActivePersonas: map[string]string{}, RestartAvailable: a.Router.Restart != nil, CancellationAvailable: a.Turns != nil, PersonasAvailable: a.Personas != nil, VoiceAvailable: a.VoiceAvailable, Version: a.Router.Version}
|
||||
if a.Models != nil {
|
||||
s.Models = slices.Clone(a.Models.Models())
|
||||
s.ActiveModel = a.Models.ActiveModel()
|
||||
if models, ok := a.Models.(ProviderModelManager); ok {
|
||||
s.ActiveProvider = models.ActiveProvider()
|
||||
s.Providers = slices.Clone(models.Providers())
|
||||
for _, provider := range s.Providers {
|
||||
s.ModelsByProvider[provider] = slices.Clone(models.ModelsForProvider(provider))
|
||||
}
|
||||
} else {
|
||||
for _, model := range s.Models {
|
||||
provider, _, ok := strings.Cut(model, "/")
|
||||
if !ok {
|
||||
provider = ""
|
||||
}
|
||||
s.ModelsByProvider[provider] = append(s.ModelsByProvider[provider], model)
|
||||
}
|
||||
}
|
||||
s.ActiveModel = a.Models.ActiveAlias()
|
||||
}
|
||||
if a.Personas != nil {
|
||||
s.Personas = slices.Clone(a.Personas.List())
|
||||
|
||||
+12
-26
@@ -55,24 +55,16 @@ type LLMStreamResponder func(ctx context.Context, in Inbound, stream TurnStream)
|
||||
// runtime provider catalog. When nil on a Router, /model returns a
|
||||
// "not configured" message.
|
||||
type ModelManager interface {
|
||||
// Models returns all available model references in "provider/model" format.
|
||||
// Models returns the model aliases chat may switch between.
|
||||
Models() []string
|
||||
// ActiveModel returns the currently active model reference.
|
||||
// Returns empty string when no model is active.
|
||||
// ActiveAlias returns the active model alias.
|
||||
ActiveAlias() string
|
||||
// ActiveModel returns the active alias's "provider/model" ref, or ""
|
||||
// when the alias is not configured.
|
||||
ActiveModel() string
|
||||
// SetActiveModel switches the active model. Returns an error if the
|
||||
// reference is unknown.
|
||||
SetActiveModel(ctx context.Context, ref string) error
|
||||
}
|
||||
|
||||
// ProviderModelManager is the optional provider-aware extension used by
|
||||
// gateways that offer a provider selector before model selection.
|
||||
type ProviderModelManager interface {
|
||||
ModelManager
|
||||
Providers() []string
|
||||
ActiveProvider() string
|
||||
ModelsForProvider(provider string) []string
|
||||
SetActiveProvider(ctx context.Context, provider string) error
|
||||
// SetActiveModel switches the active alias. Returns an error if the
|
||||
// alias is unknown.
|
||||
SetActiveModel(ctx context.Context, alias string) error
|
||||
}
|
||||
|
||||
// ModelDetails is the catalog metadata rendered after an interactive model
|
||||
@@ -506,15 +498,12 @@ func (r *Router) handleModel(ctx context.Context, arg string) (string, error) {
|
||||
}
|
||||
if arg == "" {
|
||||
models := r.Models.Models()
|
||||
if manager, ok := r.Models.(ProviderModelManager); ok {
|
||||
models = manager.ModelsForProvider(manager.ActiveProvider())
|
||||
}
|
||||
if len(models) == 0 {
|
||||
return "No models configured.\nUsage: /model <provider/model>", nil
|
||||
return "No model aliases configured.\nUsage: /model <alias>", nil
|
||||
}
|
||||
var b strings.Builder
|
||||
b.WriteString("Usage: /model <provider/model>\nAvailable models:\n")
|
||||
active := r.Models.ActiveModel()
|
||||
b.WriteString("Usage: /model <alias>\nAvailable models:\n")
|
||||
active := r.Models.ActiveAlias()
|
||||
for _, m := range models {
|
||||
if m == active {
|
||||
fmt.Fprintf(&b, " %s (active)\n", m)
|
||||
@@ -828,10 +817,7 @@ func extractRuntimeInfo(models ModelManager) (provider, model string) {
|
||||
return "", ""
|
||||
}
|
||||
model = strings.TrimSpace(models.ActiveModel())
|
||||
if pmm, ok := models.(ProviderModelManager); ok {
|
||||
provider = strings.TrimSpace(pmm.ActiveProvider())
|
||||
}
|
||||
if provider == "" && model != "" {
|
||||
if model != "" {
|
||||
if p, _, ok := strings.Cut(model, "/"); ok {
|
||||
provider = p
|
||||
}
|
||||
|
||||
@@ -125,9 +125,7 @@ func RunParams(ctx context.Context, p Prompter, discovery ModelDiscovery, secret
|
||||
return nil, err
|
||||
}
|
||||
add(providerEdits)
|
||||
for _, role := range []string{"triage", "planner", "builder"} {
|
||||
add(tableEdits{"models": {role: tomlwrite.String(model)}})
|
||||
}
|
||||
add(tableEdits{"models": {config.DefaultModelAlias: tomlwrite.String(model)}})
|
||||
|
||||
forgeEdits, err := stepForge(ctx, p, secrets, existing.ForgeHost, params)
|
||||
if err != nil {
|
||||
|
||||
@@ -82,7 +82,6 @@ func RuntimeChatConfigFrom(ctx context.Context, reader ResourceReader, base conf
|
||||
}
|
||||
out = config.ChatConfig{
|
||||
Operator: settings.Operator, ShowToolCalls: settings.ShowToolCalls, MaxSteps: settings.MaxSteps,
|
||||
Models: settings.Models,
|
||||
Telegram: config.TelegramConfig{AllowedUserIDs: settings.Telegram.AllowedUserIDs, Token: settings.Telegram.Token},
|
||||
RateLimit: config.RateLimitConfig{Window: time.Duration(settings.RateLimit.Window), MaxRequests: settings.RateLimit.MaxRequests},
|
||||
UnrestrictedFilesystem: settings.UnrestrictedFilesystem, Workspace: settings.Workspace,
|
||||
|
||||
@@ -18,7 +18,6 @@ type ChannelSettings struct {
|
||||
Operator string `json:"operator"`
|
||||
ShowToolCalls bool `json:"show_tool_calls"`
|
||||
MaxSteps int `json:"max_steps"`
|
||||
Models []string `json:"models"`
|
||||
Telegram TelegramSettings `json:"telegram"`
|
||||
RateLimit RateLimitSettings `json:"rate_limit"`
|
||||
UnrestrictedFilesystem bool `json:"unrestricted_filesystem"`
|
||||
|
||||
@@ -23,11 +23,6 @@ import (
|
||||
domainembedding "github.com/samcharles93/archie-core/internal/domain/embedding"
|
||||
)
|
||||
|
||||
// Role is the [models] key embedding consumers use, matching the
|
||||
// "builder"/"planner"/"triage" role convention chat models already use
|
||||
// (internal/domain/workflow/agent.go).
|
||||
const Role = "embedding"
|
||||
|
||||
// DefaultTimeout bounds one embedding request when Options.Timeout is
|
||||
// unset.
|
||||
const DefaultTimeout = 30 * time.Second
|
||||
@@ -41,7 +36,7 @@ type Options struct {
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
// New builds an embedding client from cfg.Models[Role] and its provider. It
|
||||
// New builds an embedding client from the embedding model alias and its provider. It
|
||||
// returns (nil, false) when unavailable. Provider secrets must already be
|
||||
// resolved.
|
||||
func New(cfg config.Config, opts Options) (domainembedding.Client, bool) {
|
||||
@@ -54,7 +49,11 @@ func New(cfg config.Config, opts Options) (domainembedding.Client, bool) {
|
||||
timeout = DefaultTimeout
|
||||
}
|
||||
|
||||
providerID, modelID, ok := parseModelRef(cfg.Models[Role])
|
||||
ref, err := config.ResolveModel(cfg.Models, "", config.PurposeEmbedding)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
providerID, modelID, ok := parseModelRef(ref)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ type Catalog struct {
|
||||
|
||||
mu sync.RWMutex
|
||||
snapshot Snapshot
|
||||
models []string
|
||||
}
|
||||
|
||||
// NewCatalog caches the catalog beside the config file at cfgPath.
|
||||
@@ -29,18 +28,18 @@ func NewCatalog(cfgPath string) *Catalog {
|
||||
return &Catalog{cachePath: filepath.Join(filepath.Dir(cfgPath), "models.json")}
|
||||
}
|
||||
|
||||
// State returns the loaded snapshot and its model references.
|
||||
func (c *Catalog) State() (Snapshot, []string) {
|
||||
// State returns the loaded snapshot.
|
||||
func (c *Catalog) State() Snapshot {
|
||||
c.mu.RLock()
|
||||
defer c.mu.RUnlock()
|
||||
return c.snapshot, c.models
|
||||
return c.snapshot
|
||||
}
|
||||
|
||||
// Set records a loaded snapshot and its model references.
|
||||
func (c *Catalog) Set(snapshot Snapshot, models []string) {
|
||||
// Set records a loaded snapshot.
|
||||
func (c *Catalog) Set(snapshot Snapshot) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.snapshot, c.models = snapshot, models
|
||||
c.snapshot = snapshot
|
||||
}
|
||||
|
||||
// Fetch reads the catalog, resolving provider keys through getenv.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Package transcription implements the internal/domain/messaging.Transcriber
|
||||
// contract over the ai-sdk provider SDKs already vendored for chat, so voice
|
||||
// notes are transcribed through the same providers table and model-role
|
||||
// convention chat models and the embedding capability already use.
|
||||
// notes are transcribed through the same providers table and model aliases
|
||||
// chat and embedding use.
|
||||
package transcription
|
||||
|
||||
import (
|
||||
@@ -20,11 +20,6 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
)
|
||||
|
||||
// Role is the [models] key transcription consumers use, matching the
|
||||
// "builder"/"planner"/"triage" role convention chat models and the
|
||||
// embedding capability already use.
|
||||
const Role = "transcription"
|
||||
|
||||
// DefaultTimeout bounds one transcription request when Options.Timeout is
|
||||
// unset. It is generous relative to a chat request because transcription
|
||||
// uploads the whole audio file before the provider answers.
|
||||
@@ -42,7 +37,7 @@ type Options struct {
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
// New builds a transcription client from models[Role] and its provider, or
|
||||
// New builds a transcription client from the transcription model alias and its provider, or
|
||||
// returns (nil, false) when unavailable.
|
||||
func New(models map[string]string, providers map[string]config.Provider, opts Options) (messaging.Transcriber, bool) {
|
||||
getenv := opts.Getenv
|
||||
@@ -54,7 +49,11 @@ func New(models map[string]string, providers map[string]config.Provider, opts Op
|
||||
timeout = DefaultTimeout
|
||||
}
|
||||
|
||||
providerID, modelID, ok := parseModelRef(models[Role])
|
||||
ref, err := config.ResolveModel(models, "", config.PurposeTranscription)
|
||||
if err != nil {
|
||||
return nil, false
|
||||
}
|
||||
providerID, modelID, ok := parseModelRef(ref)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user