mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
Added support for external hooks to observe model registry events using the `ModelRegistryHook` interface. Implemented thread-safe, non-blocking execution of hooks with panic recovery. Comprehensive tests added to verify hook behavior during registration, unregistration, blocking, and panic scenarios.
31 lines
1.1 KiB
Go
31 lines
1.1 KiB
Go
package cliproxy
|
|
|
|
import "github.com/router-for-me/CLIProxyAPI/v6/internal/registry"
|
|
|
|
// ModelInfo re-exports the registry model info structure.
|
|
type ModelInfo = registry.ModelInfo
|
|
|
|
// ModelRegistryHook re-exports the registry hook interface for external integrations.
|
|
type ModelRegistryHook = registry.ModelRegistryHook
|
|
|
|
// ModelRegistry describes registry operations consumed by external callers.
|
|
type ModelRegistry interface {
|
|
RegisterClient(clientID, clientProvider string, models []*ModelInfo)
|
|
UnregisterClient(clientID string)
|
|
SetModelQuotaExceeded(clientID, modelID string)
|
|
ClearModelQuotaExceeded(clientID, modelID string)
|
|
ClientSupportsModel(clientID, modelID string) bool
|
|
GetAvailableModels(handlerType string) []map[string]any
|
|
GetAvailableModelsByProvider(provider string) []*ModelInfo
|
|
}
|
|
|
|
// GlobalModelRegistry returns the shared registry instance.
|
|
func GlobalModelRegistry() ModelRegistry {
|
|
return registry.GetGlobalRegistry()
|
|
}
|
|
|
|
// SetGlobalModelRegistryHook registers an optional hook on the shared global registry instance.
|
|
func SetGlobalModelRegistryHook(hook ModelRegistryHook) {
|
|
registry.GetGlobalRegistry().SetHook(hook)
|
|
}
|