History

Merge pull request #536 from AoaoMH/feature/auth-model-check

Luis Pater committed 11 months agov6.6.12

Commit 5a75ef82 parents 71f788b 07279f81 file · +35 −5Browse files

Unified · Split

internal/registry/model_registry.go+35−5
@@ -90,6 +90,9 @@ type ModelRegistry struct { · 89 unmodified lines
9090 models map[string]*ModelRegistration
9191 // clientModels maps client ID to the models it provides
9292 clientModels map[string][]string
93+ // clientModelInfos maps client ID to a map of model ID -> ModelInfo
94+ // This preserves the original model info provided by each client
95+ clientModelInfos map[string]map[string]*ModelInfo
9396 // clientProviders maps client ID to its provider identifier
9497 clientProviders map[string]string
9598 // mutex ensures thread-safe access to the registry
@@ -104,10 +107,11 @@ var registryOnce sync.Once · 8 unmodified lines
104107 func GetGlobalRegistry() *ModelRegistry {
105108 registryOnce.Do(func() {
106109 globalRegistry = &ModelRegistry{
107− models: make(map[string]*ModelRegistration),
108− clientModels: make(map[string][]string),
109− clientProviders: make(map[string]string),
110− mutex: &sync.RWMutex{},
110+ models: make(map[string]*ModelRegistration),
111+ clientModels: make(map[string][]string),
112+ clientModelInfos: make(map[string]map[string]*ModelInfo),
113+ clientProviders: make(map[string]string),
114+ mutex: &sync.RWMutex{},
111115 }
112116 })
113117 return globalRegistry
@@ -144,6 +148,7 @@ func (r *ModelRegistry) RegisterClient(clientID, clientProvider string, models [ · 30 unmodified lines
144148 // No models supplied; unregister existing client state if present.
145149 r.unregisterClientInternal(clientID)
146150 delete(r.clientModels, clientID)
151+ delete(r.clientModelInfos, clientID)
147152 delete(r.clientProviders, clientID)
148153 misc.LogCredentialSeparator()
149154 return
@@ -152,7 +157,7 @@ func (r *ModelRegistry) RegisterClient(clientID, clientProvider string, models [ · 2 unmodified lines
152157 now := time.Now()
153158
154159 oldModels, hadExisting := r.clientModels[clientID]
155− oldProvider, _ := r.clientProviders[clientID]
160+ oldProvider := r.clientProviders[clientID]
156161 providerChanged := oldProvider != provider
157162 if !hadExisting {
158163 // Pure addition path.
@@ -161,6 +166,12 @@ func (r *ModelRegistry) RegisterClient(clientID, clientProvider string, models [ · 2 unmodified lines
161166 r.addModelRegistration(modelID, provider, model, now)
162167 }
163168 r.clientModels[clientID] = append([]string(nil), rawModelIDs...)
169+ // Store client's own model infos
170+ clientInfos := make(map[string]*ModelInfo, len(newModels))
171+ for id, m := range newModels {
172+ clientInfos[id] = cloneModelInfo(m)
173+ }
174+ r.clientModelInfos[clientID] = clientInfos
164175 if provider != "" {
165176 r.clientProviders[clientID] = provider
166177 } else {
@@ -287,6 +298,12 @@ func (r *ModelRegistry) RegisterClient(clientID, clientProvider string, models [ · 120 unmodified lines
287298 if len(rawModelIDs) > 0 {
288299 r.clientModels[clientID] = append([]string(nil), rawModelIDs...)
289300 }
301+ // Update client's own model infos
302+ clientInfos := make(map[string]*ModelInfo, len(newModels))
303+ for id, m := range newModels {
304+ clientInfos[id] = cloneModelInfo(m)
305+ }
306+ r.clientModelInfos[clientID] = clientInfos
290307 if provider != "" {
291308 r.clientProviders[clientID] = provider
292309 } else {
@@ -436,6 +453,7 @@ func (r *ModelRegistry) unregisterClientInternal(clientID string) { · 143 unmodified lines
436453 }
437454
438455 delete(r.clientModels, clientID)
456+ delete(r.clientModelInfos, clientID)
439457 if hasProvider {
440458 delete(r.clientProviders, clientID)
441459 }
@@ -887,6 +905,9 @@ func (r *ModelRegistry) GetModelsForClient(clientID string) []*ModelInfo { · 445 unmodified lines
887905 return nil
888906 }
889907
908+ // Try to use client-specific model infos first
909+ clientInfos := r.clientModelInfos[clientID]
910+
890911 seen := make(map[string]struct{})
891912 result := make([]*ModelInfo, 0, len(modelIDs))
892913 for _, modelID := range modelIDs {
@@ -894,6 +915,15 @@ func (r *ModelRegistry) GetModelsForClient(clientID string) []*ModelInfo { · 1 unmodified line
894915 continue
895916 }
896917 seen[modelID] = struct{}{}
918+
919+ // Prefer client's own model info to preserve original type/owned_by
920+ if clientInfos != nil {
921+ if info, ok := clientInfos[modelID]; ok && info != nil {
922+ result = append(result, info)
923+ continue
924+ }
925+ }
926+ // Fallback to global registry (for backwards compatibility)
897927 if reg, ok := r.models[modelID]; ok && reg.Info != nil {
898928 result = append(result, reg.Info)
899929 }