cliproxyapi

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSubscription added in v0.2.1

func IsSubscription(name string) bool

IsSubscription reports whether name is a subscription provider.

func UserRef

func UserRef(provider, model string) string

UserRef is the reference a user sees for a model the front door served. For the internal OAuth provider the model is already "<name>/<model>" (every OAuth credential carries its provider name as prefix); otherwise it is "<provider>/<model>".

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

func New(baseURL, managementSecret string, hc *http.Client) *Client

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

func (c *Client) CancelOAuth(ctx context.Context, state string) error

CancelOAuth cancels a pending login. Cancelling a finished, failed or unknown login is not an error.

func (*Client) Config

func (c *Client) Config(ctx context.Context) (json.RawMessage, error)

Config returns the engine's persisted configuration as JSON (v8 layout).

func (*Client) CredentialModels

func (c *Client) CredentialModels(ctx context.Context, name string) ([]string, error)

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

func (c *Client) DeleteCredential(ctx context.Context, name string) error

DeleteCredential deletes a credential file.

func (*Client) OAuthStatus

func (c *Client) OAuthStatus(ctx context.Context, state string) (OAuthStatus, error)

OAuthStatus reports a login's status. An unknown or expired state is Status "error", not an error.

func (*Client) PatchConfig

func (c *Client) PatchConfig(ctx context.Context, patch any) error

PatchConfig merges patch (a JSON object) into the engine's configuration. Objects merge; lists and scalars are replaced.

func (*Client) RefreshCredential

func (c *Client) RefreshCredential(ctx context.Context, name string) error

RefreshCredential asks the engine to refresh a credential's tokens now.

func (*Client) ResetCooldown

func (c *Client) ResetCooldown(ctx context.Context, authIndex string) error

ResetCooldown clears the engine's cooldown state for the credential with this auth index.

func (*Client) SetCredentialDisabled

func (c *Client) SetCredentialDisabled(ctx context.Context, name string, disabled bool) error

SetCredentialDisabled disables or enables a credential.

func (*Client) SetCredentialPrefix

func (c *Client) SetCredentialPrefix(ctx context.Context, name, prefix string) error

SetCredentialPrefix sets the model prefix a credential answers to ("<prefix>/<model>").

func (*Client) SetCredentialPriority added in v0.3.0

func (c *Client) SetCredentialPriority(ctx context.Context, name string, priority int) error

SetCredentialPriority sets a credential's priority tier.

func (*Client) StartOAuth

func (c *Client) StartOAuth(ctx context.Context, engineProvider string) (OAuthStart, error)

StartOAuth starts a login for the engine provider id (Provider.Engine).

func (*Client) SubmitOAuthCallback

func (c *Client) SubmitOAuthCallback(ctx context.Context, state, redirectURL string) error

SubmitOAuthCallback hands the engine the address the browser ended on after a paste-flow login. Acceptance does not mean the login finished; poll OAuthStatus.

func (*Client) UploadCredential

func (c *Client) UploadCredential(ctx context.Context, name string, data []byte) error

UploadCredential writes a credential file. name must end in ".json"; data is the file's JSON.

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
	Unavailable    bool           `json:"unavailable"`
	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

type Error struct {
	StatusCode int
	Message    string
}

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.

func (*Error) Error

func (e *Error) Error() string

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

type OAuthStatus struct {
	Status string `json:"status"`
	Error  string `json:"error,omitempty"`
}

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

func ProviderByEngine(engine string) (Provider, bool)

ProviderByEngine finds a provider by the engine's provider id.

func ProviderByName

func ProviderByName(name string) (Provider, bool)

ProviderByName finds a provider by its user-facing name.

func Providers

func Providers() []Provider

Providers returns a copy of the provider table, ordered by name.

type Quota

type Quota struct {
	ObservedAt *time.Time        `json:"observed_at,omitempty"`
	Signals    map[string]string `json:"signals"`
}

Quota is the engine's passive quota observation for a credential.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL