on main help sign in
feat(schema): fix the reflection on provider options
commita06fd0348a10152468600761f57d46a74f17f689 authorKieran Klukas <kieran@dunkirk.sh> dateFri 19 Jun 2026, 12:17 (4 months ago) parent84fb786
3 files changed+52−2
internal/cmd/schema.go+35−1 internal/config/config.go+1−1 internal/discover/enricher.go+16
internal/cmd/schema.go+35−1
@@ -4,7 +4,10 @@ import (
44 "encoding/json"
55 "fmt"
66
7+ "charm.land/catwalk/pkg/catwalk"
8+ "github.com/charmbracelet/crush/internal/agent/hyper"
79 "github.com/charmbracelet/crush/internal/config"
10+ "github.com/charmbracelet/crush/internal/discover"
811 "github.com/invopop/jsonschema"
912 "github.com/spf13/cobra"
1013)
@@ -16,7 +19,9 @@ var schemaCmd = &cobra.Command{
1619 Hidden: true,
1720 RunE: func(cmd *cobra.Command, args []string) error {
1821 reflector := new(jsonschema.Reflector)
19− bts, err := json.MarshalIndent(reflector.Reflect(&config.Config{}), "", " ")
22+ schema := reflector.Reflect(&config.Config{})
23+ setProviderTypeEnum(schema)
24+ bts, err := json.MarshalIndent(schema, "", " ")
2025 if err != nil {
2126 return fmt.Errorf("failed to marshal schema: %w", err)
2227 }
@@ -24,3 +29,32 @@ var schemaCmd = &cobra.Command{
2429 return nil
2530 },
2631}
32+
33+// setProviderTypeEnum overwrites the provider `type` enum with the live set
34+// of accepted values rather than a hand-maintained struct tag. The values
35+// must match exactly what load.go validates against: the catwalk provider
36+// types, the Charm Hyper type, and any locally-discovered providers that
37+// self-register an enricher (e.g. ollama, omlx). Sourcing the enum here keeps
38+// the published schema from drifting as provider types are added or renamed.
39+func setProviderTypeEnum(schema *jsonschema.Schema) {
40+ def, ok := schema.Definitions["ProviderConfig"]
41+ if !ok || def.Properties == nil {
42+ return
43+ }
44+ typeProp, ok := def.Properties.Get("type")
45+ if !ok {
46+ return
47+ }
48+
49+ var types []string
50+ for _, t := range catwalk.KnownProviderTypes() {
51+ types = append(types, string(t))
52+ }
53+ types = append(types, string(hyper.Name))
54+ types = append(types, discover.RegisteredProviderTypes()...)
55+
56+ typeProp.Enum = make([]any, len(types))
57+ for i, t := range types {
58+ typeProp.Enum[i] = t
59+ }
60+}
internal/config/config.go+1−1
@@ -95,7 +95,7 @@ type ProviderConfig struct {
9595 // The provider's API endpoint.
9696 BaseURL string `json:"base_url,omitempty" jsonschema:"description=Base URL for the provider's API,format=uri,example=https://api.openai.com/v1"`
9797 // The provider type, e.g. "openai", "anthropic", etc. if empty it defaults to openai.
98− Type catwalk.Type `json:"type,omitempty" jsonschema:"description=Provider type that determines the API format,enum=openai,enum=openai-compat,enum=anthropic,enum=gemini,enum=azure,enum=vertexai,default=openai"`
98+ Type catwalk.Type `json:"type,omitempty" jsonschema:"description=Provider type that determines the API format,default=openai"`
9999 // The provider's API key.
100100 APIKey string `json:"api_key,omitempty" jsonschema:"description=API key for authentication with the provider,example=$OPENAI_API_KEY"`
101101 // The original API key template before resolution (for re-resolution on auth errors).
internal/discover/enricher.go+16
@@ -2,6 +2,7 @@ package discover
22
33import (
44 "context"
5+ "sort"
56
67 "charm.land/catwalk/pkg/catwalk"
78)
@@ -42,3 +43,18 @@ func GetEnricher(providerType string) Enricher {
4243func IsKnownCustomProvider(providerType string) bool {
4344 return enrichers[providerType] != nil
4445}
46+
47+// RegisteredProviderTypes returns the provider type strings that have a
48+// registered enricher, sorted for stable output. These are the custom,
49+// locally-discovered providers (e.g. ollama, omlx) that Crush accepts as
50+// a `type` value even though they are not catwalk provider types. The
51+// schema generator uses this so the published enum stays in sync with the
52+// registry instead of drifting from a hand-maintained list.
53+func RegisteredProviderTypes() []string {
54+ types := make([]string, 0, len(enrichers))
55+ for providerType := range enrichers {
56+ types = append(types, providerType)
57+ }
58+ sort.Strings(types)
59+ return types
60+}