client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: AGPL-3.0 Imports: 14 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 client is the daemon's HTTP client for the Braid server.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnauthorized = errors.New("unauthorized")

ErrUnauthorized means the server rejected the device token (401).

Functions

This section is empty.

Types

type Backoff

type Backoff struct {
	Min, Max time.Duration
	Rand     func() float64 // [0,1); defaults to math/rand/v2
}

Backoff computes jittered exponential delays.

func (Backoff) Next

func (b Backoff) Next(attempt int) time.Duration

Next returns min(Max, Min*2^attempt) scaled by a jitter factor in [0.5, 1.0).

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the Braid server.

func New

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

New builds a client; a nil hc gets a 120 s timeout.

func (*Client) Files

func (c *Client) Files(ctx context.Context) ([]protocol.RemoteFile, error)

Files lists the files the server knows for this device, following the cursor through all pages.

func (*Client) Ingest

Ingest uploads a batch of file changes.

func (*Client) Revoke

func (c *Client) Revoke(ctx context.Context) error

Revoke revokes this device; already revoked (401) counts as done.

func (*Client) StatsSelf

func (c *Client) StatsSelf(ctx context.Context, session string) (Self, error)

StatsSelf fetches the user's figures for today and, if session is not empty, for that session.

type PermanentError

type PermanentError struct {
	Status int
	Body   string
}

PermanentError is any other non-success status.

func (*PermanentError) Error

func (e *PermanentError) Error() string

type ProtocolMismatchError

type ProtocolMismatchError struct{ Server, Min int }

ProtocolMismatchError is returned on 426.

func (*ProtocolMismatchError) Error

func (e *ProtocolMismatchError) Error() string

type RetryableError

type RetryableError struct {
	Status     int
	RetryAfter time.Duration
	Err        error
}

RetryableError covers network errors, 408, 429 and 5xx.

func (*RetryableError) Error

func (e *RetryableError) Error() string

func (*RetryableError) Unwrap

func (e *RetryableError) Unwrap() error

type Self

type Self struct {
	Today   SelfToday    `json:"today"`
	Session *SelfSession `json:"session"`
	Limit   *SelfLimit   `json:"limit"`
}

Self is the subset of GET /v1/stats/self the CLI uses; unknown fields are ignored.

type SelfLimit

type SelfLimit struct {
	Type     string    `json:"type"`
	ResetsAt time.Time `json:"resets_at"`
}

SelfLimit is the active usage limit.

type SelfSession

type SelfSession struct {
	CostUSD  float64 `json:"cost_usd"`
	Tokens   int64   `json:"tokens"`
	Failures int64   `json:"failures"`
}

SelfSession is one session's figures.

type SelfToday

type SelfToday struct {
	SessionCount int64   `json:"sessions"`
	AgentMs      int64   `json:"agent_ms"`
	CostUSD      float64 `json:"cost_usd"`
	Tokens       int64   `json:"tokens"`
	Failures     int64   `json:"failures"`
}

SelfToday is today's aggregates across devices.

Jump to

Keyboard shortcuts

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