Files
archie/internal/daemon/model_egress.go
T
sam f92c5b4536
ci/woodpecker/pr/quality Pipeline was successful
Quality / check (pull_request) Canceled after 7m39s
chore(runtime): delete Kit and external agent harness support (#1877)
Archie runs its own agent loop only. Removes Kit resolution and launch,
the harness runner and adapters, the setup terminal and sandbox view,
harness secrets and OAuth capture (table dropped in migration 0075), the
task-tools contract that only Kit containers reached, and the
sandbox-kit-spec dependency. Agent profiles carry image and tools only.
The egress proxy keeps the model-session path; the sandbox relay code
stays for #1867.
2026-11-12 21:29:05 +11:00

84 lines
3.1 KiB
Go

package daemon
import (
"context"
"fmt"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/storage"
"github.com/samcharles93/archie-core/internal/taskstate"
)
// ModelEgress opens a native task's model proxy session. The container holds
// a sentinel under each provider's key variable and reaches the providers
// through the egress proxy, which swaps in the org's bound key.
type ModelEgress interface {
Open(token, org string, providers map[string]config.Provider) (ModelSession, error)
Close(ctx context.Context, token string)
}
// TaskInstructions answers the instance and organisation instructions for a
// task's org.
type TaskInstructions interface {
TaskInstructions(ctx context.Context, taskID int64) (instance, organisation string, err error)
}
// TaskModels answers what a task's org resolves models against.
type TaskModels interface {
TaskModels(ctx context.Context, taskID int64) (config.OrgModels, error)
}
// taskConfig is task's configuration with its org's model aliases and own
// providers, narrowed to the providers those aliases reach, each carrying the
// variable its credential is read from. A provider no alias names is not part
// of the run at all: requiring its credential would park a task whose models
// never touch it.
func (d *Daemon) taskConfig(ctx context.Context, task *workflow.Task) (config.Config, error) {
cfg := d.configFor(task)
if d.TaskModels != nil {
models, err := d.TaskModels.TaskModels(ctx, task.ID)
if err != nil {
return config.Config{}, fmt.Errorf("resolve the task's models: %w", err)
}
cfg = cfg.WithOrgModels(models)
}
cfg.Providers = cfg.ModelProviders()
return cfg, nil
}
// ModelSession is what a native container needs for its model proxy session.
type ModelSession struct {
Env []string
Mounts []storage.Mount
}
// openModelEgress opens task's model session, or refuses: provider keys
// never reach a container, so without the proxy no model call can run. A
// workflow with no model step needs no session and no provider credential.
func (d *Daemon) openModelEgress(ctx context.Context, task *workflow.Task, credential string) (ModelSession, func(), error) {
if !workflow.UsesModel(task.WorkflowDefinitionYAML) {
return ModelSession{}, func() {}, nil
}
cfg, err := d.taskConfig(ctx, task)
if err != nil {
return ModelSession{}, nil, err
}
if d.ModelEgress == nil {
for _, p := range cfg.Providers {
if p.APIKeyEnv != "" {
return ModelSession{}, nil, blockedPark{taskstate.BlockerModelCredential, fmt.Errorf("model egress proxy is unavailable on this daemon, and provider keys never enter a container")}
}
}
return ModelSession{}, func() {}, nil
}
if credential == "" {
return ModelSession{}, nil, fmt.Errorf("model egress needs a run credential, and no State Store issues one")
}
session, err := d.ModelEgress.Open(credential, task.OrgOrDefault(), cfg.Providers)
if err != nil {
return ModelSession{}, nil, blockedPark{taskstate.BlockerModelCredential, err}
}
return session, func() { d.ModelEgress.Close(ctx, credential) }, nil
}