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
4 changes: 2 additions & 2 deletions internal/provider/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

func NewRegistry() (*provider.Registry, error) {
registry := provider.NewRegistry()
if err := Register(registry); err != nil {
if err := register(registry); err != nil {
return nil, err
}
return registry, nil
}

func Register(registry *provider.Registry) error {
func register(registry *provider.Registry) error {
if registry == nil {
return errors.New("builtin provider registry is nil")
}
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/builtin/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestRegister(t *testing.T) {

t.Run("nil registry", func(t *testing.T) {
t.Parallel()
err := Register(nil)
err := register(nil)
if err == nil {
t.Fatal("expected error for nil registry")
}
Expand All @@ -39,7 +39,7 @@ func TestRegister(t *testing.T) {
t.Run("valid registry", func(t *testing.T) {
t.Parallel()
registry := provider.NewRegistry()
err := Register(registry)
err := register(registry)
if err != nil {
t.Fatalf("Register() error = %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/catalog/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Service struct {

func NewService(baseDir string, registry *provider.Registry, store Store) *Service {
if store == nil && strings.TrimSpace(baseDir) != "" {
store = NewJSONStore(baseDir)
store = newJSONStore(baseDir)
}

return &Service{
Expand Down Expand Up @@ -174,7 +174,7 @@ func (s *Service) discoverAndPersist(ctx context.Context, providerCfg config.Pro

now := s.now()
_ = s.store.Save(ctx, ModelCatalog{
SchemaVersion: SchemaVersion,
SchemaVersion: schemaVersion,
Identity: identity,
FetchedAt: now,
ExpiresAt: now.Add(s.catalogTTL),
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/catalog/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestListProviderModelsReturnsStaleCacheAndRefreshesInBackground(t *testing.
store := newMemoryStore()
now := time.Date(2026, 4, 2, 12, 0, 0, 0, time.UTC)
if err := store.Save(context.Background(), ModelCatalog{
SchemaVersion: SchemaVersion,
SchemaVersion: schemaVersion,
Identity: identity,
FetchedAt: now.Add(-48 * time.Hour),
ExpiresAt: now.Add(-24 * time.Hour),
Expand Down Expand Up @@ -234,8 +234,8 @@ func containsModelDescriptorID(models []config.ModelDescriptor, modelID string)

type catalogTestProvider struct{}

func (catalogTestProvider) Chat(ctx context.Context, req provider.ChatRequest, events chan<- provider.StreamEvent) (provider.ChatResponse, error) {
return provider.ChatResponse{}, nil
func (catalogTestProvider) Chat(ctx context.Context, req provider.ChatRequest, events chan<- provider.StreamEvent) error {
return nil
}

type memoryStore struct {
Expand Down
18 changes: 9 additions & 9 deletions internal/provider/catalog/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"neo-code/internal/config"
)

const SchemaVersion = 1
const schemaVersion = 1

var ErrCatalogNotFound = errors.New("provider: model catalog not found")

Expand All @@ -39,18 +39,18 @@ type Store interface {
Save(ctx context.Context, catalog ModelCatalog) error
}

type JSONStore struct {
type jsonStore struct {
dir string
mu sync.RWMutex
}

func NewJSONStore(baseDir string) *JSONStore {
return &JSONStore{
func newJSONStore(baseDir string) *jsonStore {
return &jsonStore{
dir: filepath.Join(strings.TrimSpace(baseDir), "cache", "models"),
}
}

func (s *JSONStore) Load(ctx context.Context, identity config.ProviderIdentity) (ModelCatalog, error) {
func (s *jsonStore) Load(ctx context.Context, identity config.ProviderIdentity) (ModelCatalog, error) {
if err := ctx.Err(); err != nil {
return ModelCatalog{}, err
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func (s *JSONStore) Load(ctx context.Context, identity config.ProviderIdentity)
return normalizeCatalog(modelCatalog), nil
}

func (s *JSONStore) Save(ctx context.Context, catalog ModelCatalog) error {
func (s *jsonStore) Save(ctx context.Context, catalog ModelCatalog) error {
if err := ctx.Err(); err != nil {
return err
}
Expand Down Expand Up @@ -111,18 +111,18 @@ func (s *JSONStore) Save(ctx context.Context, catalog ModelCatalog) error {

func normalizeCatalog(modelCatalog ModelCatalog) ModelCatalog {
if modelCatalog.SchemaVersion == 0 {
modelCatalog.SchemaVersion = SchemaVersion
modelCatalog.SchemaVersion = schemaVersion
}
modelCatalog.Models = config.MergeModelDescriptors(modelCatalog.Models)
return modelCatalog
}

func (s *JSONStore) catalogPath(identity config.ProviderIdentity) string {
func (s *jsonStore) catalogPath(identity config.ProviderIdentity) string {
sum := sha256.Sum256([]byte(identity.Key()))
return filepath.Join(s.dir, hex.EncodeToString(sum[:])+".json")
}

func (s *JSONStore) writeCatalogFile(path string, data []byte) error {
func (s *jsonStore) writeCatalogFile(path string, data []byte) error {
if err := os.MkdirAll(s.dir, 0o755); err != nil {
return fmt.Errorf("provider: create model catalog dir: %w", err)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/provider/catalog/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
func TestJSONStoreRoundTrip(t *testing.T) {
t.Parallel()

store := NewJSONStore(t.TempDir())
store := newJSONStore(t.TempDir())
identity, err := config.NewProviderIdentity("openai", "https://api.openai.com/v1")
if err != nil {
t.Fatalf("NewProviderIdentity() error = %v", err)
}

expected := ModelCatalog{
SchemaVersion: SchemaVersion,
SchemaVersion: schemaVersion,
Identity: identity,
FetchedAt: time.Date(2026, 4, 2, 10, 0, 0, 0, time.UTC),
ExpiresAt: time.Date(2026, 4, 3, 10, 0, 0, 0, time.UTC),
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestJSONStoreRoundTrip(t *testing.T) {
func TestJSONStoreMissingCatalog(t *testing.T) {
t.Parallel()

store := NewJSONStore(t.TempDir())
store := newJSONStore(t.TempDir())
identity, err := config.NewProviderIdentity("openai", "https://api.openai.com/v1")
if err != nil {
t.Fatalf("NewProviderIdentity() error = %v", err)
Expand All @@ -86,14 +86,14 @@ func TestJSONStoreSaveReplacesExistingCatalogWithoutTempLeak(t *testing.T) {
t.Parallel()

baseDir := t.TempDir()
store := NewJSONStore(baseDir)
store := newJSONStore(baseDir)
identity, err := config.NewProviderIdentity("openai", "https://api.openai.com/v1")
if err != nil {
t.Fatalf("NewProviderIdentity() error = %v", err)
}

first := ModelCatalog{
SchemaVersion: SchemaVersion,
SchemaVersion: schemaVersion,
Identity: identity,
FetchedAt: time.Date(2026, 4, 2, 10, 0, 0, 0, time.UTC),
ExpiresAt: time.Date(2026, 4, 3, 10, 0, 0, 0, time.UTC),
Expand All @@ -102,7 +102,7 @@ func TestJSONStoreSaveReplacesExistingCatalogWithoutTempLeak(t *testing.T) {
},
}
second := ModelCatalog{
SchemaVersion: SchemaVersion,
SchemaVersion: schemaVersion,
Identity: identity,
FetchedAt: time.Date(2026, 4, 4, 10, 0, 0, 0, time.UTC),
ExpiresAt: time.Date(2026, 4, 5, 10, 0, 0, 0, time.UTC),
Expand Down
Loading
Loading