feat(controlplane): per-org model access, org aliases and org providers
The system org sets each org's allowed models and whether it may add its own providers (org-model-policy); an org with no entry may use nothing. An org's aliases and providers are checked against that policy on save and filtered by it at resolution. Tasks get their org's providers, keyed by the org's credential binding through the egress proxy. Org Settings gains a Models tab; instance Models gains Org access.
This commit is contained in:
1 parent
ea52c8622e
commit
75b4eecfde
25 files changed
+1135
-516
No files matched your search
@@ -1842,7 +1842,7 @@ func (d *Daemon) acquireTaskContainer(
|
||||
return nil, "", nil, false
|
||||
}
|
||||
|
||||
model, closeModel, err := d.openModelEgress(task, credential)
|
||||
model, closeModel, err := d.openModelEgress(ctx, task, credential)
|
||||
if err != nil {
|
||||
revokeCredential()
|
||||
d.teardownStorage(ctx, task, repo, workDir)
|
||||
@@ -1943,14 +1943,10 @@ func (d *Daemon) recordPark(ctx context.Context, taskID int64, reason string) {
|
||||
// credential is the task's run credential; the agent presents it to push the
|
||||
// task's branch.
|
||||
func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo config.Repo, profile config.AgentProfile, harness *agentrun.HarnessSpec, credential string) {
|
||||
cfg := d.configFor(task)
|
||||
if d.TaskModels != nil {
|
||||
_, aliases, err := d.TaskModels.TaskModelAliases(ctx, task.ID)
|
||||
if err != nil {
|
||||
d.parkRunningTask(ctx, task.ID, "resolve the task's model aliases: "+err.Error(), taskstate.ParkTransient)
|
||||
return
|
||||
}
|
||||
cfg.Models = aliases
|
||||
cfg, err := d.taskConfig(ctx, task)
|
||||
if err != nil {
|
||||
d.parkRunningTask(ctx, task.ID, err.Error(), taskstate.ParkTransient)
|
||||
return
|
||||
}
|
||||
taskCfg := cfg.ForTask()
|
||||
d.captureAttemptConfig(ctx, task, taskCfg)
|
||||
|
||||
@@ -122,9 +122,23 @@ type ModelEgress interface {
|
||||
Close(token string)
|
||||
}
|
||||
|
||||
// TaskModels answers a task's org and the model aliases it resolves against.
|
||||
// TaskModels answers what a task's org resolves models against.
|
||||
type TaskModels interface {
|
||||
TaskModelAliases(ctx context.Context, taskID int64) (org string, aliases map[string]string, err error)
|
||||
TaskModels(ctx context.Context, taskID int64) (config.OrgModels, error)
|
||||
}
|
||||
|
||||
// taskConfig is task's configuration with its org's model aliases and own
|
||||
// providers.
|
||||
func (d *Daemon) taskConfig(ctx context.Context, task *workflow.Task) (config.Config, error) {
|
||||
cfg := d.configFor(task)
|
||||
if d.TaskModels == nil {
|
||||
return cfg, nil
|
||||
}
|
||||
models, err := d.TaskModels.TaskModels(ctx, task.ID)
|
||||
if err != nil {
|
||||
return config.Config{}, fmt.Errorf("resolve the task's models: %w", err)
|
||||
}
|
||||
return cfg.WithOrgModels(models), nil
|
||||
}
|
||||
|
||||
// ModelSession is what a native container needs for its model proxy session.
|
||||
@@ -135,8 +149,11 @@ type ModelSession struct {
|
||||
|
||||
// openModelEgress opens task's model session, or refuses: provider keys
|
||||
// never reach a container, so without the proxy no model call can run.
|
||||
func (d *Daemon) openModelEgress(task *workflow.Task, credential string) (ModelSession, func(), error) {
|
||||
cfg := d.configFor(task)
|
||||
func (d *Daemon) openModelEgress(ctx context.Context, task *workflow.Task, credential string) (ModelSession, func(), error) {
|
||||
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 != "" {
|
||||
|
||||
Reference in new issue
Block a user