Documentation
¶
Index ¶
- func BuildRefreshPayload(updated *coreauth.Auth) ([]byte, error)
- func ClaudeNativeToolSearchSupported(auth *coreauth.Auth, upstreamModel string) bool
- func SanitizeAuthForDownstream(auth *coreauth.Auth) *coreauth.Auth
- type ClusterAdapter
- type ConcurrencyAdmissionRequest
- type ConcurrencyAdmissionResult
- type ConcurrencyAdmitter
- type ConcurrencyAdmitterFunc
- type DispatchConcurrencyContext
- type DispatchModelInfo
- type DispatchResponsePreparer
- type DispatchResult
- type KVGetResult
- type ModelInfo
- type PluginPlatform
- type Runtime
- func (r *Runtime) AddToken(ctx context.Context, rawJSON string) (string, error)
- func (r *Runtime) ApplyConfigFromCluster(ctx context.Context, cfg *config.Config) error
- func (r *Runtime) Authenticate(ctx context.Context, headers http.Header) (*access.Result, *access.AuthError)
- func (r *Runtime) AuthenticateHTTPRequest(ctx context.Context, req *http.Request) (*access.Result, *access.AuthError)
- func (r *Runtime) BuildPluginSyncPlan(ctx context.Context, request pluginstore.PluginSyncRequest) (pluginstore.PluginSyncResponse, error)
- func (r *Runtime) Config() *config.Config
- func (r *Runtime) ConfigPath() string
- func (r *Runtime) CoreManager() *coreauth.Manager
- func (r *Runtime) DispatchForAPIKey(ctx context.Context, reqModel string, headers http.Header, apiKey string) (*DispatchResult, error)
- func (r *Runtime) DispatchForAPIKeyWithConcurrency(ctx context.Context, reqModel string, headers http.Header, apiKey string, ...) (*DispatchResult, error)
- func (r *Runtime) HasPluginAuthProvider(provider string) bool
- func (r *Runtime) HasScheduler() bool
- func (r *Runtime) KVCompareAndSwap(ctx context.Context, key string, expected []byte, expectedExists bool, ...) (bool, error)
- func (r *Runtime) KVDel(ctx context.Context, keys []string) (int64, error)
- func (r *Runtime) KVExpire(ctx context.Context, key string, ttl time.Duration) (bool, error)
- func (r *Runtime) KVGet(ctx context.Context, key string) ([]byte, bool, error)
- func (r *Runtime) KVIncrBy(ctx context.Context, key string, delta int64) (int64, error)
- func (r *Runtime) KVMGet(ctx context.Context, keys []string) ([]KVGetResult, error)
- func (r *Runtime) KVMSet(ctx context.Context, pairs map[string][]byte) error
- func (r *Runtime) KVSet(ctx context.Context, key string, value []byte, ttl time.Duration, mode string) (bool, error)
- func (r *Runtime) KVTTL(ctx context.Context, key string) (int64, error)
- func (r *Runtime) ListPendingPluginTasks(ctx context.Context, nodeType string, nodeID string) ([]node.PluginTask, error)
- func (r *Runtime) ParseAuth(ctx context.Context, req pluginapi.AuthParseRequest) (*homeauth.Auth, bool, error)
- func (r *Runtime) ParseAuths(ctx context.Context, req pluginapi.AuthParseRequest) ([]*homeauth.Auth, bool, error)
- func (r *Runtime) PersistAppLogPayload(ctx context.Context, clientIP string, payload string) (bool, error)
- func (r *Runtime) PersistClusterUsagePayload(ctx context.Context, payload string, receivedAt time.Time) (bool, error)
- func (r *Runtime) PickAuth(ctx context.Context, req pluginapi.SchedulerPickRequest) (pluginapi.SchedulerPickResponse, bool, error)
- func (r *Runtime) PluginHost() *sdkpluginhost.Host
- func (r *Runtime) PluginLoginAuths(resp pluginapi.AuthLoginPollResponse) ([]*homeauth.Auth, error)
- func (r *Runtime) PluginSyncNodeActive(ctx context.Context, nodeID string, fingerprint string) (bool, error)
- func (r *Runtime) PollPluginLogin(ctx context.Context, provider, state string, metadata map[string]any) (pluginapi.AuthLoginPollResponse, bool, error)
- func (r *Runtime) PublishConfigYAML(payload []byte)
- func (r *Runtime) ReadConfigYAMLContext(ctx context.Context) ([]byte, error)
- func (r *Runtime) RecordUsagePayload(ctx context.Context, payload string)
- func (r *Runtime) RefreshAuth(ctx context.Context, auth *homeauth.Auth) (*homeauth.Auth, bool, error)
- func (r *Runtime) RefreshClusterAuthIndex(ctx context.Context, uuid string) error
- func (r *Runtime) RefreshNow(ctx context.Context, authIndex string) ([]byte, error)
- func (r *Runtime) RefreshNowLocal(ctx context.Context, authIndex string) ([]byte, error)
- func (r *Runtime) RefreshNowLocalObserved(ctx context.Context, authIndex, observedAccessTokenSHA256 string) ([]byte, error)
- func (r *Runtime) RefreshNowObserved(ctx context.Context, authIndex, observedAccessTokenSHA256 string) ([]byte, error)
- func (r *Runtime) RegisteredPlugins() []sdkpluginhost.RegisteredPluginInfo
- func (r *Runtime) ReloadAuths(ctx context.Context) error
- func (r *Runtime) ReplacePluginStatus(ctx context.Context, nodeType string, status node.PluginTaskStatus) error
- func (r *Runtime) SetClusterAdapter(adapter ClusterAdapter)
- func (r *Runtime) SetClusterRefreshHandler(handler func(context.Context, string, string) ([]byte, error))
- func (r *Runtime) SetConcurrencyAdmitter(admitter ConcurrencyAdmitter)
- func (r *Runtime) SetPluginStoreAuthResolver(resolver func(context.Context) ([]pluginstore.ResolvedAuthConfig, error))
- func (r *Runtime) SetPluginSyncConfigLoader(loader func(context.Context) (*config.Config, error))
- func (r *Runtime) SetPluginSyncNodeActive(check func(context.Context, string, string) (bool, error))
- func (r *Runtime) Start(ctx context.Context, configPath string) error
- func (r *Runtime) StartAutoRefresh(ctx context.Context)
- func (r *Runtime) StartPluginLogin(ctx context.Context, provider, baseURL string) (pluginapi.AuthLoginStartResponse, bool, error)
- func (r *Runtime) Stop()
- func (r *Runtime) StopAutoRefresh()
- func (r *Runtime) SubscribeConfigYAML(subscriber func(payload []byte) error) (unsubscribe func())
- func (r *Runtime) UpdateAuthInMemory(ctx context.Context, auth *coreauth.Auth) (*coreauth.Auth, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildRefreshPayload ¶ added in v1.0.2
BuildRefreshPayload builds a build refresh payload.
func ClaudeNativeToolSearchSupported ¶ added in v1.1.1
ClaudeNativeToolSearchSupported reports whether a Claude credential can take Codex tool_search as Anthropic native tool search for an upstream model. It mirrors ClaudeExecutor.SupportsNativeToolSearch in CLIProxyAPI: Anthropic's own origin qualifies, a custom base URL needs native_tool_search, and models that predate tool search never qualify.
Types ¶
type ClusterAdapter ¶ added in v1.0.2
type ConcurrencyAdmissionRequest ¶ added in v1.0.61
type ConcurrencyAdmissionRequest struct {
CredentialID string
Model string
Fingerprint string
ConnectedAt time.Time
Controlled bool
ProtocolVersion int
}
ConcurrencyAdmissionRequest identifies a dispatch request for atomic admission.
type ConcurrencyAdmissionResult ¶ added in v1.0.61
ConcurrencyAdmissionResult describes the credential and model admitted by the limiter.
type ConcurrencyAdmitter ¶ added in v1.0.61
type ConcurrencyAdmitter interface {
AdmitCredentialConcurrency(context.Context, ConcurrencyAdmissionRequest) (ConcurrencyAdmissionResult, error)
}
ConcurrencyAdmitter atomically reserves a credential concurrency slot.
type ConcurrencyAdmitterFunc ¶ added in v1.0.61
type ConcurrencyAdmitterFunc func(context.Context, ConcurrencyAdmissionRequest) (ConcurrencyAdmissionResult, error)
ConcurrencyAdmitterFunc adapts a function to ConcurrencyAdmitter.
func (ConcurrencyAdmitterFunc) AdmitCredentialConcurrency ¶ added in v1.0.61
func (f ConcurrencyAdmitterFunc) AdmitCredentialConcurrency(ctx context.Context, req ConcurrencyAdmissionRequest) (ConcurrencyAdmissionResult, error)
type DispatchConcurrencyContext ¶ added in v1.0.61
type DispatchConcurrencyContext struct {
Fingerprint string
ConnectedAt time.Time
Controlled bool
ProtocolVersion int
// RetryRound carries the zero-based CPA request retry round.
RetryRound int
// RetryRoundPresent distinguishes an explicit wire retry_round=0 from an
// omitted field used by legacy CPA nodes.
RetryRoundPresent bool
PrepareResponse DispatchResponsePreparer
}
DispatchConcurrencyContext carries the RESP connection identity required for admission.
type DispatchModelInfo ¶ added in v1.0.73
type DispatchModelInfo struct {
ID string `json:"id"`
Type string `json:"type,omitempty"`
InputTokenLimit int `json:"inputTokenLimit,omitempty"`
OutputTokenLimit int `json:"outputTokenLimit,omitempty"`
ContextLength int `json:"context_length,omitempty"`
MaxCompletionTokens int `json:"max_completion_tokens,omitempty"`
Thinking *registry.ThinkingSupport `json:"thinking,omitempty"`
NativeCapabilities *registry.NativeCapabilities `json:"native_capabilities,omitempty"`
SupportConfigurationUpdate bool `json:"support_configuration_update"`
UserDefined bool `json:"user_defined"`
}
DispatchModelInfo carries the selected model capabilities needed by CPA at execution time.
type DispatchResponsePreparer ¶ added in v1.0.61
type DispatchResponsePreparer func(*DispatchResult) (unaccounted []byte, accounted []byte, err error)
DispatchResponsePreparer prebuilds both dispatch response variants before admission.
type DispatchResult ¶
type DispatchResult struct {
Model string
AccessToken string
BaseURL string
APIKey string
RequestRetry int
ForceMapping bool
OriginalAlias string
ModelInfo *DispatchModelInfo
AuthID string
Provider string
Auth *coreauth.Auth
Concurrency ConcurrencyAdmissionResult
UnaccountedReply []byte
AccountedReply []byte
AdmissionFenceFailure error
}
type KVGetResult ¶ added in v1.0.34
type PluginPlatform ¶ added in v1.0.39
func CurrentPluginPlatform ¶ added in v1.0.39
func CurrentPluginPlatform() PluginPlatform
CurrentPluginPlatform reports the platform used by Home plugin discovery.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
func NewRuntime ¶
NewRuntime creates a new runtime.
func (*Runtime) AddToken ¶
AddToken stores a credential JSON blob into the auth directory and schedules it for use. It returns the created (or existing) auth file name under auth-dir.
func (*Runtime) ApplyConfigFromCluster ¶ added in v1.0.2
ApplyConfigFromCluster updates apply config from cluster.
func (*Runtime) Authenticate ¶
func (r *Runtime) Authenticate(ctx context.Context, headers http.Header) (*access.Result, *access.AuthError)
Authenticate validates request credentials and returns the access result.
func (*Runtime) AuthenticateHTTPRequest ¶ added in v1.0.34
func (r *Runtime) AuthenticateHTTPRequest(ctx context.Context, req *http.Request) (*access.Result, *access.AuthError)
AuthenticateHTTPRequest validates request credentials from a complete HTTP request.
func (*Runtime) BuildPluginSyncPlan ¶ added in v1.0.57
func (r *Runtime) BuildPluginSyncPlan(ctx context.Context, request pluginstore.PluginSyncRequest) (pluginstore.PluginSyncResponse, error)
func (*Runtime) ConfigPath ¶
ConfigPath handles a config path.
func (*Runtime) CoreManager ¶
CoreManager handles a core manager.
func (*Runtime) DispatchForAPIKey ¶ added in v1.0.20
func (r *Runtime) DispatchForAPIKey(ctx context.Context, reqModel string, headers http.Header, apiKey string) (*DispatchResult, error)
DispatchForAPIKey processes dispatch with API-key channel restrictions.
func (*Runtime) DispatchForAPIKeyWithConcurrency ¶ added in v1.0.61
func (r *Runtime) DispatchForAPIKeyWithConcurrency(ctx context.Context, reqModel string, headers http.Header, apiKey string, credentialPolicy string, excludedAuthIDs []string, pinnedAuthID string, concurrencyCtx DispatchConcurrencyContext) (*DispatchResult, error)
DispatchForAPIKeyWithConcurrency performs dispatch and atomic admission for a RESP request while applying retry-round exclusions and an optional pinned credential constraint.
func (*Runtime) HasPluginAuthProvider ¶ added in v1.0.49
HasPluginAuthProvider reports whether a Home-loaded plugin owns provider login.
func (*Runtime) HasScheduler ¶ added in v1.0.39
HasScheduler reports whether a Home-loaded plugin supplies auth scheduling.
func (*Runtime) KVCompareAndSwap ¶ added in v1.0.65
func (r *Runtime) KVCompareAndSwap(ctx context.Context, key string, expected []byte, expectedExists bool, value []byte, ttl time.Duration) (bool, error)
KVCompareAndSwap writes a KV value to the cluster store only when the active state matches the expected state.
func (*Runtime) KVMGet ¶ added in v1.0.34
KVMGet returns KV values in request order from the cluster store.
func (*Runtime) KVSet ¶ added in v1.0.34
func (r *Runtime) KVSet(ctx context.Context, key string, value []byte, ttl time.Duration, mode string) (bool, error)
KVSet writes a KV value to the cluster store.
func (*Runtime) KVTTL ¶ added in v1.0.34
KVTTL returns a Redis-compatible KV TTL from the cluster store.
func (*Runtime) ListPendingPluginTasks ¶ added in v1.0.39
func (r *Runtime) ListPendingPluginTasks(ctx context.Context, nodeType string, nodeID string) ([]node.PluginTask, error)
ListPendingPluginTasks returns pending plugin tasks for a node.
func (*Runtime) ParseAuth ¶ added in v1.0.39
func (r *Runtime) ParseAuth(ctx context.Context, req pluginapi.AuthParseRequest) (*homeauth.Auth, bool, error)
ParseAuth lets Home auth synthesis use provider plugins.
func (*Runtime) ParseAuths ¶ added in v1.0.39
func (r *Runtime) ParseAuths(ctx context.Context, req pluginapi.AuthParseRequest) ([]*homeauth.Auth, bool, error)
ParseAuths lets Home auth synthesis use provider plugins that expand one file into multiple auths.
func (*Runtime) PersistAppLogPayload ¶ added in v1.0.25
func (r *Runtime) PersistAppLogPayload(ctx context.Context, clientIP string, payload string) (bool, error)
PersistAppLogPayload stores a CPA app log payload in the runtime database.
func (*Runtime) PersistClusterUsagePayload ¶ added in v1.0.2
func (r *Runtime) PersistClusterUsagePayload(ctx context.Context, payload string, receivedAt time.Time) (bool, error)
PersistClusterUsagePayload stores a cluster usage payload with its trusted receive time.
func (*Runtime) PickAuth ¶ added in v1.0.39
func (r *Runtime) PickAuth(ctx context.Context, req pluginapi.SchedulerPickRequest) (pluginapi.SchedulerPickResponse, bool, error)
PickAuth lets Home dispatch use scheduler plugins.
func (*Runtime) PluginHost ¶ added in v1.0.75
func (r *Runtime) PluginHost() *sdkpluginhost.Host
PluginHost exposes the Home-owned host to management operations. Credentials supplied to it are loaded from the Home repository, not an SDK file store.
func (*Runtime) PluginLoginAuths ¶ added in v1.0.49
PluginLoginAuths converts auth records returned by a successful plugin login.
func (*Runtime) PluginSyncNodeActive ¶ added in v1.0.57
func (*Runtime) PollPluginLogin ¶ added in v1.0.49
func (r *Runtime) PollPluginLogin(ctx context.Context, provider, state string, metadata map[string]any) (pluginapi.AuthLoginPollResponse, bool, error)
PollPluginLogin polls an OAuth flow through a Home-loaded auth provider plugin.
func (*Runtime) PublishConfigYAML ¶
PublishConfigYAML handles a publish config yaml.
func (*Runtime) ReadConfigYAMLContext ¶ added in v1.0.2
ReadConfigYAMLContext loads read config yaml context.
func (*Runtime) RecordUsagePayload ¶
RecordUsagePayload applies downstream usage status to the scheduler auth state.
func (*Runtime) RefreshAuth ¶ added in v1.0.39
func (r *Runtime) RefreshAuth(ctx context.Context, auth *homeauth.Auth) (*homeauth.Auth, bool, error)
RefreshAuth lets Home refresh provider plugin credentials.
func (*Runtime) RefreshClusterAuthIndex ¶ added in v1.0.2
RefreshClusterAuthIndex refreshes refresh cluster auth index.
func (*Runtime) RefreshNow ¶ added in v1.0.2
RefreshNow refreshes refresh now.
func (*Runtime) RefreshNowLocal ¶ added in v1.0.2
RefreshNowLocal refreshes refresh now local.
func (*Runtime) RefreshNowLocalObserved ¶ added in v1.0.65
func (r *Runtime) RefreshNowLocalObserved(ctx context.Context, authIndex, observedAccessTokenSHA256 string) ([]byte, error)
RefreshNowLocalObserved refreshes a local credential unless it is already newer.
func (*Runtime) RefreshNowObserved ¶ added in v1.0.65
func (r *Runtime) RefreshNowObserved(ctx context.Context, authIndex, observedAccessTokenSHA256 string) ([]byte, error)
RefreshNowObserved refreshes unless Home already replaced the observed token.
func (*Runtime) RegisteredPlugins ¶ added in v1.0.49
func (r *Runtime) RegisteredPlugins() []sdkpluginhost.RegisteredPluginInfo
RegisteredPlugins returns Home-loaded plugin metadata for management clients.
func (*Runtime) ReloadAuths ¶ added in v1.0.2
ReloadAuths handles a reload auths.
func (*Runtime) ReplacePluginStatus ¶ added in v1.0.39
func (r *Runtime) ReplacePluginStatus(ctx context.Context, nodeType string, status node.PluginTaskStatus) error
ReplacePluginStatus stores the latest plugin status report in the cluster store.
func (*Runtime) SetClusterAdapter ¶ added in v1.0.2
func (r *Runtime) SetClusterAdapter(adapter ClusterAdapter)
SetClusterAdapter sets a cluster adapter.
func (*Runtime) SetClusterRefreshHandler ¶ added in v1.0.2
func (r *Runtime) SetClusterRefreshHandler(handler func(context.Context, string, string) ([]byte, error))
SetClusterRefreshHandler sets a cluster refresh handler.
func (*Runtime) SetConcurrencyAdmitter ¶ added in v1.0.61
func (r *Runtime) SetConcurrencyAdmitter(admitter ConcurrencyAdmitter)
SetConcurrencyAdmitter sets the admission backend used for concurrency-aware dispatch.
func (*Runtime) SetPluginStoreAuthResolver ¶ added in v1.0.57
func (r *Runtime) SetPluginStoreAuthResolver(resolver func(context.Context) ([]pluginstore.ResolvedAuthConfig, error))
func (*Runtime) SetPluginSyncConfigLoader ¶ added in v1.0.57
func (*Runtime) SetPluginSyncNodeActive ¶ added in v1.0.57
func (*Runtime) StartAutoRefresh ¶ added in v1.0.2
StartAutoRefresh starts an auto refresh.
func (*Runtime) StartPluginLogin ¶ added in v1.0.49
func (r *Runtime) StartPluginLogin(ctx context.Context, provider, baseURL string) (pluginapi.AuthLoginStartResponse, bool, error)
StartPluginLogin starts an OAuth flow through a Home-loaded auth provider plugin.
func (*Runtime) StopAutoRefresh ¶ added in v1.0.2
func (r *Runtime) StopAutoRefresh()
StopAutoRefresh stops an auto refresh.
func (*Runtime) SubscribeConfigYAML ¶
SubscribeConfigYAML handles a subscribe config yaml.