client

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package client provides an HTTP client for the BuildMax server API.

Index

Constants

This section is empty.

Variables

View Source
var ErrRefreshRejected = errors.New("refresh token rejected")

ErrRefreshRejected means the server refused the refresh token: it is spent, revoked, expired, or was replayed. The session is over and only a new login will produce another.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
}

Client is a stateless HTTP client for the BuildMax server API.

func NewClient

func NewClient(baseURL string) *Client

NewClient creates a Client for the given server base URL.

func (*Client) ListTeamModels

func (c *Client) ListTeamModels(ctx context.Context, token, teamID string) ([]llmwire.Model, error)

ListTeamModels calls GET /api/teams/{team_id}/llm/models and returns the model aliases the team may use through the managed gateway.

The reply names aliases only. Which provider serves one, and with whose credential, stays on the server.

func (*Client) Login

func (c *Client) Login(ctx context.Context, email, otp, platform string) (*LoginResponse, error)

Login calls POST /api/login with a single-use login code — the recovery path, used to claim a new account or replace a forgotten password. platform identifies the calling client ("cli", "desktop", "portal").

func (*Client) LoginWithPassword

func (c *Client) LoginWithPassword(ctx context.Context, email, password, platform string) (*LoginResponse, error)

LoginWithPassword calls POST /api/login with a password, the everyday way in.

func (*Client) Logout

func (c *Client) Logout(ctx context.Context, refreshToken, accessToken string) error

Logout calls POST /api/logout to revoke the session behind refreshToken.

func (*Client) Refresh

func (c *Client) Refresh(ctx context.Context, refreshToken string) (*RefreshResponse, error)

Refresh calls POST /api/token/refresh, exchanging a refresh token for a new pair.

A rejected token returns ErrRefreshRejected, which the caller must be able to tell apart from the server being unreachable: one means sign in again, the other means try later.

func (*Client) RequestOTP

func (c *Client) RequestOTP(ctx context.Context, email, intent string) error

RequestOTP calls POST /api/otp/request. intent is "login" or "signup".

type LoginResponse

type LoginResponse struct {
	// Token is AccessToken under the name it had before a login returned two
	// credentials. A server older than that split sends only this one.
	Token       string `json:"token"`
	AccessToken string `json:"access_token"`
	// RefreshToken is empty when the server keeps no store for it, which means
	// the login ends when the access token does.
	RefreshToken string    `json:"refresh_token"`
	ExpiresIn    int64     `json:"expires_in"`
	User         LoginUser `json:"user"`
}

LoginResponse is the successful result of POST /api/login.

func (*LoginResponse) Access

func (r *LoginResponse) Access() string

Access returns the access token under whichever name the server used.

type LoginUser

type LoginUser struct {
	ID    string `json:"id"`
	Email string `json:"email"`
	Name  string `json:"name"`
}

LoginUser is the user subset returned in a login response.

type RefreshResponse

type RefreshResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int64  `json:"expires_in"`
}

RefreshResponse is the successful result of POST /api/token/refresh.

Jump to

Keyboard shortcuts

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