Documentation
¶
Overview ¶
Package cliproxyapi is remora's client for the OAuth engine's v8 management API. It speaks to the engine over loopback HTTP with the management secret remora generated. Nothing it returns is meant for a remora user, and its errors never carry the engine's name.
Index ¶
- func IsSubscription(name string) bool
- func UserRef(provider, model string) string
- type APICallRequest
- type APICallResponse
- type Client
- func (c *Client) APICall(ctx context.Context, in APICallRequest) (APICallResponse, error)
- func (c *Client) AwaitCredentialModels(ctx context.Context, name, prefix string, wait time.Duration) ([]string, error)
- func (c *Client) CancelOAuth(ctx context.Context, state string) error
- func (c *Client) Config(ctx context.Context) (json.RawMessage, error)
- func (c *Client) CredentialModels(ctx context.Context, name string) ([]string, error)
- func (c *Client) Credentials(ctx context.Context) ([]Credential, error)
- func (c *Client) DeleteCredential(ctx context.Context, name string) error
- func (c *Client) OAuthStatus(ctx context.Context, state string) (OAuthStatus, error)
- func (c *Client) PatchConfig(ctx context.Context, patch any) error
- func (c *Client) RefreshCredential(ctx context.Context, name string) error
- func (c *Client) ResetCooldown(ctx context.Context, authIndex string) error
- func (c *Client) SetCredentialDisabled(ctx context.Context, name string, disabled bool) error
- func (c *Client) SetCredentialPrefix(ctx context.Context, name, prefix string) error
- func (c *Client) SetCredentialPriority(ctx context.Context, name string, priority int) error
- func (c *Client) StartOAuth(ctx context.Context, engineProvider string) (OAuthStart, error)
- func (c *Client) SubmitOAuthCallback(ctx context.Context, state, redirectURL string) error
- func (c *Client) UploadCredential(ctx context.Context, name string, data []byte) error
- type Cooldown
- type Credential
- type Error
- type IDTokenClaims
- type OAuthStart
- type OAuthStatus
- type Provider
- type Quota
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsSubscription ¶ added in v0.2.1
IsSubscription reports whether name is a subscription provider.
Types ¶
type APICallRequest ¶ added in v0.3.0
type APICallRequest struct {
AuthIndex string `json:"auth_index"`
Method string `json:"method"`
URL string `json:"url"`
Header map[string]string `json:"header,omitempty"`
Data string `json:"data,omitempty"`
ProxyURL string `json:"proxy_url,omitempty"`
}
APICallRequest asks the engine to send one HTTP request upstream as a credential. "$TOKEN$" in Header or Data becomes the credential's token.
type APICallResponse ¶ added in v0.3.0
type APICallResponse struct {
StatusCode int `json:"status_code"`
Header map[string][]string `json:"header"`
Body string `json:"body"`
}
APICallResponse is the upstream's answer; a non-2xx StatusCode is an answer, not an error.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the OAuth engine's management API.
func New ¶
New returns a client for the engine at baseURL (for example "http://127.0.0.1:18317"). A nil hc uses a fresh http.Client with no timeout; callers bound each call with its context.
func (*Client) APICall ¶ added in v0.3.0
func (c *Client) APICall(ctx context.Context, in APICallRequest) (APICallResponse, error)
APICall sends one request upstream as the credential in.AuthIndex and returns the upstream's answer.
func (*Client) AwaitCredentialModels ¶ added in v0.2.0
func (c *Client) AwaitCredentialModels(ctx context.Context, name, prefix string, wait time.Duration) ([]string, error)
AwaitCredentialModels waits up to wait for a just-written credential to list models and returns them. The engine can drop the model registration of a credential it is still busy with (its upload handler races its file watcher), leaving it with none until it next changes. Setting the prefix again, to the same value, makes the engine register the credential anew, so an empty round is followed by that nudge. After modelRounds rounds the list is returned empty.
func (*Client) CancelOAuth ¶
CancelOAuth cancels a pending login. Cancelling a finished, failed or unknown login is not an error.
func (*Client) CredentialModels ¶
CredentialModels lists the model ids a credential serves (without its prefix). An unknown name has none.
func (*Client) Credentials ¶
func (c *Client) Credentials(ctx context.Context) ([]Credential, error)
Credentials lists the engine's credentials, ordered by name.
func (*Client) DeleteCredential ¶
DeleteCredential deletes a credential file.
func (*Client) OAuthStatus ¶
OAuthStatus reports a login's status. An unknown or expired state is Status "error", not an error.
func (*Client) PatchConfig ¶
PatchConfig merges patch (a JSON object) into the engine's configuration. Objects merge; lists and scalars are replaced.
func (*Client) RefreshCredential ¶
RefreshCredential asks the engine to refresh a credential's tokens now.
func (*Client) ResetCooldown ¶
ResetCooldown clears the engine's cooldown state for the credential with this auth index.
func (*Client) SetCredentialDisabled ¶
SetCredentialDisabled disables or enables a credential.
func (*Client) SetCredentialPrefix ¶
SetCredentialPrefix sets the model prefix a credential answers to ("<prefix>/<model>").
func (*Client) SetCredentialPriority ¶ added in v0.3.0
SetCredentialPriority sets a credential's priority tier.
func (*Client) StartOAuth ¶
StartOAuth starts a login for the engine provider id (Provider.Engine).
func (*Client) SubmitOAuthCallback ¶
SubmitOAuthCallback hands the engine the address the browser ended on after a paste-flow login. Acceptance does not mean the login finished; poll OAuthStatus.
type Cooldown ¶
type Cooldown struct {
Scope string `json:"scope"`
ModelKey string `json:"model_key,omitempty"`
Reason string `json:"reason"`
RetryAt time.Time `json:"retry_at"`
RemainingSeconds int64 `json:"remaining_seconds"`
HTTPStatus int `json:"http_status,omitempty"`
}
Cooldown is one unexpired retry restriction on a credential (scope "credential") or one of its models (scope "model", ModelKey set).
type Credential ¶
type Credential struct {
ID string `json:"id"`
AuthIndex string `json:"auth_index"`
Name string `json:"name"`
Provider string `json:"provider"`
Label string `json:"label"`
Email string `json:"email,omitempty"`
ProjectID string `json:"project_id,omitempty"`
IDToken *IDTokenClaims `json:"id_token,omitempty"`
Status string `json:"status"`
StatusMessage string `json:"status_message"`
Disabled bool `json:"disabled"`
Priority int `json:"priority"` // absent = 0; the highest available tier serves
NextRetryAfter *time.Time `json:"next_retry_after,omitempty"`
Quota Quota `json:"quota"`
Cooldowns []Cooldown `json:"cooldowns"`
Success int64 `json:"success"`
Failed int64 `json:"failed"`
UpdatedAt time.Time `json:"updated_at"`
}
Credential is one entry of GET /credentials. Name is the credential file name; Provider is the engine's provider id (for example "xai", which remora shows as "grok"). Fields the engine sends but remora does not use are dropped.
type Error ¶
Error is a non-2xx answer from the engine. Message is the body's "error" field, followed by its "message" field when the engine sends one. Neither its text nor the engine's name ever reaches a remora user.
type IDTokenClaims ¶ added in v0.3.0
type IDTokenClaims struct {
ChatGPTAccountID string `json:"chatgpt_account_id"`
PlanType string `json:"plan_type"`
}
IDTokenClaims are the Codex id_token claims the engine lists with a credential.
type OAuthStart ¶
type OAuthStart struct {
URL string `json:"url"`
State string `json:"state"`
Flow string `json:"flow,omitempty"`
UserCode string `json:"user_code,omitempty"`
ExpiresIn int `json:"expires_in,omitempty"`
}
OAuthStart answers GET /oauth/auth-url. A paste flow has URL and State; a device flow also has Flow "device", UserCode and ExpiresIn (seconds).
type OAuthStatus ¶
OAuthStatus answers GET /oauth/status. Status is "wait", "ok" or "error"; Error explains "error". The engine answers 200 for every status, including an unknown or expired state.
type Provider ¶
type Provider struct{ Name, Engine, Mode string }
Provider is one subscription provider remora offers. Name is what users see and the model prefix they send ("codex/gpt-x"); Engine is the OAuth engine's provider id; Mode is "paste" (the user pastes the address the browser ends on) or "device" (the user enters a code on the provider's page).
func ProviderByEngine ¶
ProviderByEngine finds a provider by the engine's provider id.
func ProviderByName ¶
ProviderByName finds a provider by its user-facing name.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cliproxyapitest is an in-memory fake of the OAuth engine's v8 management API for tests.
|
Package cliproxyapitest is an in-memory fake of the OAuth engine's v8 management API for tests. |