broker

package
v0.1.117 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBaseURL = "https://cmux.com"

Variables

This section is empty.

Functions

func DefaultConfigPath

func DefaultConfigPath() (string, error)

func DeleteConfig

func DeleteConfig(path string) error

func SaveConfig

func SaveConfig(path string, config Config) error

Types

type AccountUpload

type AccountUpload map[string]any

type Client

type Client struct {
	Config     Config
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config Config) *Client

func (*Client) DeleteAccount

func (c *Client) DeleteAccount(ctx context.Context, accountID string) error

func (*Client) InvalidateLease

func (c *Client) InvalidateLease(leaseID string)

InvalidateLease removes an access lease from memory before an asynchronous outcome report reaches cmux.com. This closes the window where a second local request could reuse a credential that just returned 401 or 429.

func (*Client) Lease

func (c *Client) Lease(ctx context.Context, input LeaseRequest) (Lease, error)

func (*Client) ListAccounts

func (c *Client) ListAccounts(ctx context.Context) ([]SharedAccount, error)

func (*Client) ListTeams

func (c *Client) ListTeams(ctx context.Context) ([]Team, string, error)

func (*Client) RepairAccount

func (c *Client) RepairAccount(
	ctx context.Context,
	accountID string,
	input AccountUpload,
) (SharedAccount, error)

func (*Client) Report

func (c *Client) Report(
	ctx context.Context,
	leaseID string,
	report LeaseReport,
) error

func (*Client) UploadAccount

func (c *Client) UploadAccount(ctx context.Context, input AccountUpload) (SharedAccount, error)

func (*Client) UsageStatuses added in v0.1.60

func (c *Client) UsageStatuses(ctx context.Context) ([]UsageStatus, error)

type Config

type Config struct {
	Version            int              `json:"version"`
	BaseURL            string           `json:"baseUrl"`
	AccessToken        string           `json:"accessToken"`
	RefreshToken       string           `json:"refreshToken"`
	LocalProxyToken    string           `json:"localProxyToken,omitempty"`
	TeamID             string           `json:"teamId,omitempty"`
	TeamName           string           `json:"teamName,omitempty"`
	CredentialSource   CredentialSource `json:"credentialSource,omitempty"`
	HostedURL          string           `json:"hostedUrl,omitempty"`
	HostedExchangeURL  string           `json:"hostedExchangeUrl,omitempty"`
	TenantKey          string           `json:"tenantKey,omitempty"`
	TenantCapabilities []string         `json:"tenantCapabilities,omitempty"`
	StackAPIURL        string           `json:"stackApiUrl,omitempty"`
	StackProjectID     string           `json:"stackProjectId,omitempty"`
	StackPublishable   string           `json:"stackPublishableClientKey,omitempty"`
}

func LoadConfig

func LoadConfig(path string) (Config, error)

func (Config) EffectiveCredentialSource

func (c Config) EffectiveCredentialSource() CredentialSource

EffectiveCredentialSource keeps existing installations compatible. A pre-source config with a complete cmux.com login was the old signal for team mode; a machine without that config keeps its legacy server behavior.

func (Config) HostedReady added in v0.1.52

func (c Config) HostedReady() bool

func (Config) LoggedIn

func (c Config) LoggedIn() bool

func (Config) Normalized

func (c Config) Normalized() Config

func (Config) Ready

func (c Config) Ready() bool

func (Config) TeamModeReady

func (c Config) TeamModeReady() bool

func (Config) UsesLegacyServer

func (c Config) UsesLegacyServer() bool

func (Config) UsesLocalCredentials

func (c Config) UsesLocalCredentials() bool

func (Config) Validate

func (c Config) Validate() error

type CredentialSource

type CredentialSource string
const (
	CredentialSourceTeam   CredentialSource = "team"
	CredentialSourceLocal  CredentialSource = "local"
	CredentialSourceLegacy CredentialSource = "legacy"
	CredentialSourceHosted CredentialSource = "hosted"
)

type Lease

type Lease struct {
	ID                   string
	Account              account.Account
	CredentialGeneration int
	IssuedAt             time.Time
	ExpiresAt            time.Time
	CredentialExpiresAt  time.Time
}

type LeaseCooldownScope

type LeaseCooldownScope string
const (
	LeaseCooldownAccount LeaseCooldownScope = "account"
	LeaseCooldownQuota   LeaseCooldownScope = "quota"
)

type LeaseOutcome

type LeaseOutcome string
const (
	LeaseSuccess       LeaseOutcome = "success"
	LeaseUnauthorized  LeaseOutcome = "unauthorized"
	LeaseForbidden     LeaseOutcome = "forbidden"
	LeaseRateLimited   LeaseOutcome = "rate_limited"
	LeaseProviderError LeaseOutcome = "provider_error"
)

type LeaseReport

type LeaseReport struct {
	Outcome       LeaseOutcome
	StatusCode    int
	CooldownScope LeaseCooldownScope
	RetryAt       time.Time
}

type LeaseRequest

type LeaseRequest struct {
	Provider         account.Provider
	RequiredAuthMode account.AuthMode
	AgentType        string
	SessionID        string
	UserEmail        string
	PreferAccountID  string
	Model            string
}

type SharedAccount

type SharedAccount struct {
	ID        string `json:"id"`
	Kind      string `json:"kind"`
	Label     string `json:"label,omitempty"`
	CreatedAt string `json:"createdAt,omitempty"`
	Health    *struct {
		OK      bool   `json:"ok"`
		Message string `json:"message,omitempty"`
	} `json:"health,omitempty"`
}

type Team

type Team struct {
	ID             string `json:"id"`
	Name           string `json:"name"`
	Personal       bool   `json:"personal"`
	Use            bool   `json:"-"`
	ManageAccounts bool   `json:"-"`
}

type UsageStatus added in v0.1.60

type UsageStatus struct {
	ID                 string                           `json:"id"`
	Provider           accounts.Provider                `json:"provider"`
	AuthMode           accounts.AuthMode                `json:"auth_mode"`
	Email              string                           `json:"email,omitempty"`
	Source             string                           `json:"source"`
	AuthChecked        bool                             `json:"auth_checked"`
	AuthValid          bool                             `json:"auth_valid"`
	Refreshed          bool                             `json:"refreshed,omitempty"`
	Error              string                           `json:"error,omitempty"`
	Active             bool                             `json:"active,omitempty"`
	PlanType           string                           `json:"plan_type,omitempty"`
	Windows            []accounts.UsageWindow           `json:"windows,omitempty"`
	Credits            *accounts.CreditsInfo            `json:"credits,omitempty"`
	ComplimentaryReset *accounts.ComplimentaryResetInfo `json:"complimentary_reset,omitempty"`
}

Jump to

Keyboard shortcuts

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