Skip to content

Commit 99e9a1a

Browse files
committed
Make it easier to bump the schema version
Signed-off-by: David Gageot <david.gageot@docker.com>
1 parent be4fa6d commit 99e9a1a

54 files changed

Lines changed: 155 additions & 107 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/golibrary/builtintool/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"syscall"
1010

1111
"github.com/docker/cagent/pkg/agent"
12-
latest "github.com/docker/cagent/pkg/config/v3"
12+
"github.com/docker/cagent/pkg/config/latest"
1313
"github.com/docker/cagent/pkg/environment"
1414
"github.com/docker/cagent/pkg/model/provider/openai"
1515
"github.com/docker/cagent/pkg/runtime"

examples/golibrary/multi/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"syscall"
99

1010
"github.com/docker/cagent/pkg/agent"
11-
latest "github.com/docker/cagent/pkg/config/v3"
11+
"github.com/docker/cagent/pkg/config/latest"
1212
"github.com/docker/cagent/pkg/environment"
1313
"github.com/docker/cagent/pkg/model/provider/openai"
1414
"github.com/docker/cagent/pkg/runtime"

examples/golibrary/simple/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"syscall"
99

1010
"github.com/docker/cagent/pkg/agent"
11-
latest "github.com/docker/cagent/pkg/config/v3"
11+
"github.com/docker/cagent/pkg/config/latest"
1212
"github.com/docker/cagent/pkg/environment"
1313
"github.com/docker/cagent/pkg/model/provider/openai"
1414
"github.com/docker/cagent/pkg/runtime"

examples/golibrary/stream/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"syscall"
88

99
"github.com/docker/cagent/pkg/agent"
10-
latest "github.com/docker/cagent/pkg/config/v3"
10+
"github.com/docker/cagent/pkg/config/latest"
1111
"github.com/docker/cagent/pkg/environment"
1212
"github.com/docker/cagent/pkg/model/provider/openai"
1313
"github.com/docker/cagent/pkg/runtime"

examples/golibrary/tool/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"syscall"
1010

1111
"github.com/docker/cagent/pkg/agent"
12-
latest "github.com/docker/cagent/pkg/config/v3"
12+
"github.com/docker/cagent/pkg/config/latest"
1313
"github.com/docker/cagent/pkg/environment"
1414
"github.com/docker/cagent/pkg/model/provider/openai"
1515
"github.com/docker/cagent/pkg/runtime"

pkg/acp/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"os"
66

77
"github.com/docker/cagent/pkg/config"
8-
latest "github.com/docker/cagent/pkg/config/v3"
8+
"github.com/docker/cagent/pkg/config/latest"
99
"github.com/docker/cagent/pkg/teamloader"
1010
"github.com/docker/cagent/pkg/tools"
1111
)

pkg/agentfile/resolver_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/docker/cagent/pkg/aliases"
1515
"github.com/docker/cagent/pkg/cli"
16+
"github.com/docker/cagent/pkg/config/latest"
1617
"github.com/docker/cagent/pkg/content"
1718
"github.com/docker/cagent/pkg/oci"
1819
)
@@ -489,7 +490,7 @@ func TestResolveAgentFile_OCIRef_HasAVersion(t *testing.T) {
489490

490491
storedContent, err := os.ReadFile(resolved)
491492
require.NoError(t, err)
492-
assert.Equal(t, `version: "3"
493+
assert.Equal(t, `version: "`+latest.Version+`"
493494
agents:
494495
root:
495496
model: auto

pkg/api/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"time"
55

66
"github.com/docker/cagent/pkg/chat"
7-
latest "github.com/docker/cagent/pkg/config/v3"
7+
"github.com/docker/cagent/pkg/config/latest"
88
"github.com/docker/cagent/pkg/session"
99
)
1010

pkg/config/auto.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package config
33
import (
44
"context"
55

6-
latest "github.com/docker/cagent/pkg/config/v3"
6+
"github.com/docker/cagent/pkg/config/latest"
77
"github.com/docker/cagent/pkg/environment"
88
)
99

pkg/config/config.go

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import (
77

88
"github.com/goccy/go-yaml"
99

10-
v0 "github.com/docker/cagent/pkg/config/v0"
11-
v1 "github.com/docker/cagent/pkg/config/v1"
12-
v2 "github.com/docker/cagent/pkg/config/v2"
13-
latest "github.com/docker/cagent/pkg/config/v3" //nolint:staticcheck // This is used everywhere we reference the latest version
14-
v3 "github.com/docker/cagent/pkg/config/v3" //nolint:staticcheck // This is used for migrations to v3
10+
"github.com/docker/cagent/pkg/config/latest"
1511
"github.com/docker/cagent/pkg/environment"
1612
"github.com/docker/cagent/pkg/filesystem"
1713
)
@@ -76,57 +72,24 @@ func CheckRequiredEnvVars(ctx context.Context, cfg *latest.Config, modelsGateway
7672
}
7773

7874
func parseCurrentVersion(data []byte, version string) (any, error) {
79-
options := []yaml.DecodeOption{yaml.Strict()}
80-
81-
switch version {
82-
case v0.Version:
83-
var cfg v0.Config
84-
err := yaml.UnmarshalWithOptions(data, &cfg, options...)
85-
return cfg, err
86-
case v1.Version:
87-
var cfg v1.Config
88-
err := yaml.UnmarshalWithOptions(data, &cfg, options...)
89-
return cfg, err
90-
case v2.Version:
91-
var cfg v2.Config
92-
err := yaml.UnmarshalWithOptions(data, &cfg, options...)
93-
return cfg, err
94-
case v3.Version:
95-
var cfg v3.Config
96-
err := yaml.UnmarshalWithOptions(data, &cfg, options...)
97-
return cfg, err
98-
default:
75+
parser, found := Parsers()[version]
76+
if !found {
9977
return nil, fmt.Errorf("unsupported config version: %v", version)
10078
}
79+
return parser(data)
10180
}
10281

10382
func migrateToLatestConfig(c any) (latest.Config, error) {
10483
var err error
105-
for {
106-
if old, ok := c.(v0.Config); ok {
107-
c, err = v1.UpgradeFrom(old)
108-
if err != nil {
109-
return latest.Config{}, err
110-
}
111-
continue
112-
}
113-
if old, ok := c.(v1.Config); ok {
114-
c, err = v2.UpgradeFrom(old)
115-
if err != nil {
116-
return latest.Config{}, err
117-
}
118-
continue
119-
}
120-
if old, ok := c.(v2.Config); ok {
121-
c, err = v3.UpgradeFrom(old)
122-
if err != nil {
123-
return latest.Config{}, err
124-
}
125-
continue
126-
}
12784

128-
return c.(latest.Config), nil
85+
for _, upgrade := range Upgrades() {
86+
c, err = upgrade(c)
87+
if err != nil {
88+
return latest.Config{}, err
89+
}
12990
}
91+
92+
return c.(latest.Config), nil
13093
}
13194

13295
func validateConfig(cfg *latest.Config) error {

0 commit comments

Comments
 (0)