mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 20:30:51 +08:00
v6 version first commit
This commit is contained in:
82
sdk/cliproxy/types.go
Normal file
82
sdk/cliproxy/types.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package cliproxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/config"
|
||||
coreauth "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/auth"
|
||||
)
|
||||
|
||||
// TokenClientProvider loads clients backed by stored authentication tokens.
|
||||
type TokenClientProvider interface {
|
||||
Load(ctx context.Context, cfg *config.Config) (*TokenClientResult, error)
|
||||
}
|
||||
|
||||
// TokenClientResult represents clients generated from persisted tokens.
|
||||
type TokenClientResult struct {
|
||||
SuccessfulAuthed int
|
||||
}
|
||||
|
||||
// APIKeyClientProvider loads clients backed directly by configured API keys.
|
||||
type APIKeyClientProvider interface {
|
||||
Load(ctx context.Context, cfg *config.Config) (*APIKeyClientResult, error)
|
||||
}
|
||||
|
||||
// APIKeyClientResult contains API key based clients along with type counts.
|
||||
type APIKeyClientResult struct {
|
||||
GeminiKeyCount int
|
||||
ClaudeKeyCount int
|
||||
CodexKeyCount int
|
||||
OpenAICompatCount int
|
||||
}
|
||||
|
||||
// WatcherFactory creates a watcher for configuration and token changes.
|
||||
// The reload callback now only receives the updated configuration.
|
||||
type WatcherFactory func(configPath, authDir string, reload func(*config.Config)) (*WatcherWrapper, error)
|
||||
|
||||
// WatcherWrapper exposes the subset of watcher methods required by the SDK.
|
||||
type WatcherWrapper struct {
|
||||
start func(ctx context.Context) error
|
||||
stop func() error
|
||||
|
||||
setConfig func(cfg *config.Config)
|
||||
snapshotAuths func() []*coreauth.Auth
|
||||
}
|
||||
|
||||
// Start proxies to the underlying watcher Start implementation.
|
||||
func (w *WatcherWrapper) Start(ctx context.Context) error {
|
||||
if w == nil || w.start == nil {
|
||||
return nil
|
||||
}
|
||||
return w.start(ctx)
|
||||
}
|
||||
|
||||
// Stop proxies to the underlying watcher Stop implementation.
|
||||
func (w *WatcherWrapper) Stop() error {
|
||||
if w == nil || w.stop == nil {
|
||||
return nil
|
||||
}
|
||||
return w.stop()
|
||||
}
|
||||
|
||||
// SetConfig updates the watcher configuration cache.
|
||||
func (w *WatcherWrapper) SetConfig(cfg *config.Config) {
|
||||
if w == nil || w.setConfig == nil {
|
||||
return
|
||||
}
|
||||
w.setConfig(cfg)
|
||||
}
|
||||
|
||||
// SetClients updates the watcher file-backed clients registry.
|
||||
// SetClients and SetAPIKeyClients removed; watcher manages its own caches
|
||||
|
||||
// SnapshotClients returns the current combined clients snapshot from the underlying watcher.
|
||||
// SnapshotClients removed; use SnapshotAuths
|
||||
|
||||
// SnapshotAuths returns the current auth entries derived from legacy clients.
|
||||
func (w *WatcherWrapper) SnapshotAuths() []*coreauth.Auth {
|
||||
if w == nil || w.snapshotAuths == nil {
|
||||
return nil
|
||||
}
|
||||
return w.snapshotAuths()
|
||||
}
|
||||
Reference in New Issue
Block a user