Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/golibrary/builtintool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"syscall"

"github.com/docker/cagent/pkg/agent"
latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/environment"
"github.com/docker/cagent/pkg/model/provider/openai"
"github.com/docker/cagent/pkg/runtime"
Expand Down
2 changes: 1 addition & 1 deletion examples/golibrary/multi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"syscall"

"github.com/docker/cagent/pkg/agent"
latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/environment"
"github.com/docker/cagent/pkg/model/provider/openai"
"github.com/docker/cagent/pkg/runtime"
Expand Down
2 changes: 1 addition & 1 deletion examples/golibrary/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"syscall"

"github.com/docker/cagent/pkg/agent"
latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/environment"
"github.com/docker/cagent/pkg/model/provider/openai"
"github.com/docker/cagent/pkg/runtime"
Expand Down
2 changes: 1 addition & 1 deletion examples/golibrary/stream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"syscall"

"github.com/docker/cagent/pkg/agent"
latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/environment"
"github.com/docker/cagent/pkg/model/provider/openai"
"github.com/docker/cagent/pkg/runtime"
Expand Down
2 changes: 1 addition & 1 deletion examples/golibrary/tool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"syscall"

"github.com/docker/cagent/pkg/agent"
latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/environment"
"github.com/docker/cagent/pkg/model/provider/openai"
"github.com/docker/cagent/pkg/runtime"
Expand Down
2 changes: 1 addition & 1 deletion pkg/acp/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"

"github.com/docker/cagent/pkg/config"
latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/teamloader"
"github.com/docker/cagent/pkg/tools"
)
Expand Down
3 changes: 2 additions & 1 deletion pkg/agentfile/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/docker/cagent/pkg/aliases"
"github.com/docker/cagent/pkg/cli"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/content"
"github.com/docker/cagent/pkg/oci"
)
Expand Down Expand Up @@ -489,7 +490,7 @@ func TestResolveAgentFile_OCIRef_HasAVersion(t *testing.T) {

storedContent, err := os.ReadFile(resolved)
require.NoError(t, err)
assert.Equal(t, `version: "3"
assert.Equal(t, `version: "`+latest.Version+`"
agents:
root:
model: auto
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"time"

"github.com/docker/cagent/pkg/chat"
latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/session"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
import (
"context"

latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/environment"
)

Expand Down
59 changes: 11 additions & 48 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import (

"github.com/goccy/go-yaml"

v0 "github.com/docker/cagent/pkg/config/v0"
v1 "github.com/docker/cagent/pkg/config/v1"
v2 "github.com/docker/cagent/pkg/config/v2"
latest "github.com/docker/cagent/pkg/config/v3" //nolint:staticcheck // This is used everywhere we reference the latest version
v3 "github.com/docker/cagent/pkg/config/v3" //nolint:staticcheck // This is used for migrations to v3
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/environment"
"github.com/docker/cagent/pkg/filesystem"
)
Expand Down Expand Up @@ -76,57 +72,24 @@ func CheckRequiredEnvVars(ctx context.Context, cfg *latest.Config, modelsGateway
}

func parseCurrentVersion(data []byte, version string) (any, error) {
options := []yaml.DecodeOption{yaml.Strict()}

switch version {
case v0.Version:
var cfg v0.Config
err := yaml.UnmarshalWithOptions(data, &cfg, options...)
return cfg, err
case v1.Version:
var cfg v1.Config
err := yaml.UnmarshalWithOptions(data, &cfg, options...)
return cfg, err
case v2.Version:
var cfg v2.Config
err := yaml.UnmarshalWithOptions(data, &cfg, options...)
return cfg, err
case v3.Version:
var cfg v3.Config
err := yaml.UnmarshalWithOptions(data, &cfg, options...)
return cfg, err
default:
parser, found := Parsers()[version]
if !found {
return nil, fmt.Errorf("unsupported config version: %v", version)
}
return parser(data)
}

func migrateToLatestConfig(c any) (latest.Config, error) {
var err error
for {
if old, ok := c.(v0.Config); ok {
c, err = v1.UpgradeFrom(old)
if err != nil {
return latest.Config{}, err
}
continue
}
if old, ok := c.(v1.Config); ok {
c, err = v2.UpgradeFrom(old)
if err != nil {
return latest.Config{}, err
}
continue
}
if old, ok := c.(v2.Config); ok {
c, err = v3.UpgradeFrom(old)
if err != nil {
return latest.Config{}, err
}
continue
}

return c.(latest.Config), nil
for _, upgrade := range Upgrades() {
c, err = upgrade(c)
if err != nil {
return latest.Config{}, err
}
}

return c.(latest.Config), nil
}

func validateConfig(cfg *latest.Config) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/environment"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/config/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/xeipuuv/gojsonschema"

latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/filesystem"
"github.com/docker/cagent/pkg/modelsdev"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sort"
"strings"

latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/environment"
"github.com/docker/cagent/pkg/gateway"
"github.com/docker/cagent/pkg/model/provider"
Expand Down
9 changes: 9 additions & 0 deletions pkg/config/latest/parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package latest

import "github.com/goccy/go-yaml"

func Parse(data []byte) (Config, error) {
var cfg Config
err := yaml.UnmarshalWithOptions(data, &cfg, yaml.Strict())
return cfg, err
}
2 changes: 1 addition & 1 deletion pkg/config/v3/types.go → pkg/config/latest/types.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v3
package latest

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v3
package latest

import (
"testing"
Expand Down
17 changes: 17 additions & 0 deletions pkg/config/latest/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package latest

import (
"github.com/docker/cagent/pkg/config/types"
previous "github.com/docker/cagent/pkg/config/v2"
)

func UpgradeIfNeeded(c any) (any, error) {
old, ok := c.(previous.Config)
if !ok {
return c, nil
}

var config Config
types.CloneThroughJSON(old, &config)
return config, nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v3
package latest

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
)

// ApplyModelOverrides applies CLI model overrides to the configuration
Expand Down
9 changes: 9 additions & 0 deletions pkg/config/v0/parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v0

import "github.com/goccy/go-yaml"

func Parse(data []byte) (Config, error) {
var cfg Config
err := yaml.UnmarshalWithOptions(data, &cfg, yaml.Strict())
return cfg, err
}
5 changes: 5 additions & 0 deletions pkg/config/v0/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package v0

func UpgradeIfNeeded(old any) (any, error) {
return old, nil
}
9 changes: 9 additions & 0 deletions pkg/config/v1/parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v1

import "github.com/goccy/go-yaml"

func Parse(data []byte) (Config, error) {
var cfg Config
err := yaml.UnmarshalWithOptions(data, &cfg, yaml.Strict())
return cfg, err
}
9 changes: 7 additions & 2 deletions pkg/config/v1/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ package v1

import (
"github.com/docker/cagent/pkg/config/types"
v0 "github.com/docker/cagent/pkg/config/v0"
previous "github.com/docker/cagent/pkg/config/v0"
)

func UpgradeFrom(old v0.Config) (Config, error) {
func UpgradeIfNeeded(c any) (any, error) {
old, ok := c.(previous.Config)
if !ok {
return c, nil
}

var config Config
types.CloneThroughJSON(old, &config)

Expand Down
9 changes: 9 additions & 0 deletions pkg/config/v2/parse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v2

import "github.com/goccy/go-yaml"

func Parse(data []byte) (Config, error) {
var cfg Config
err := yaml.UnmarshalWithOptions(data, &cfg, yaml.Strict())
return cfg, err
}
9 changes: 7 additions & 2 deletions pkg/config/v2/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import (
"errors"

"github.com/docker/cagent/pkg/config/types"
v1 "github.com/docker/cagent/pkg/config/v1"
previous "github.com/docker/cagent/pkg/config/v1"
)

func UpgradeFrom(old v1.Config) (Config, error) {
func UpgradeIfNeeded(c any) (any, error) {
old, ok := c.(previous.Config)
if !ok {
return c, nil
}

if len(old.Env) > 0 {
return Config{}, errors.New("top-level Env is not supported anymore")
}
Expand Down
12 changes: 0 additions & 12 deletions pkg/config/v3/upgrade.go

This file was deleted.

28 changes: 28 additions & 0 deletions pkg/config/versions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package config

import (
"github.com/docker/cagent/pkg/config/latest"
v0 "github.com/docker/cagent/pkg/config/v0"
v1 "github.com/docker/cagent/pkg/config/v1"
v2 "github.com/docker/cagent/pkg/config/v2"
)

func Parsers() map[string]func([]byte) (any, error) {
return map[string]func([]byte) (any, error){
v0.Version: func(d []byte) (any, error) { return v0.Parse(d) },
v1.Version: func(d []byte) (any, error) { return v1.Parse(d) },
v2.Version: func(d []byte) (any, error) { return v2.Parse(d) },

latest.Version: func(d []byte) (any, error) { return latest.Parse(d) },
}
}

func Upgrades() []func(any) (any, error) {
return []func(any) (any, error){
v0.UpgradeIfNeeded,
v1.UpgradeIfNeeded,
v2.UpgradeIfNeeded,

latest.UpgradeIfNeeded,
}
}
2 changes: 1 addition & 1 deletion pkg/creator/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/docker/cagent/pkg/agent"
"github.com/docker/cagent/pkg/config"
latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/environment"
"github.com/docker/cagent/pkg/model/provider/anthropic"
"github.com/docker/cagent/pkg/model/provider/options"
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/provider/anthropic/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/anthropics/anthropic-sdk-go/packages/param"

"github.com/docker/cagent/pkg/chat"
latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/environment"
"github.com/docker/cagent/pkg/httpclient"
"github.com/docker/cagent/pkg/model/provider/base"
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/provider/base/base.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package base

import (
latest "github.com/docker/cagent/pkg/config/v3"
"github.com/docker/cagent/pkg/config/latest"
"github.com/docker/cagent/pkg/environment"
"github.com/docker/cagent/pkg/model/provider/options"
)
Expand Down
Loading
Loading