api

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package api is the typed HTTP client for the loradex control-plane API. File bytes never pass through here — they move directly to/from presigned URLs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenBrowser

func OpenBrowser(url string) error

OpenBrowser best-effort opens url in the default browser.

func RandomState

func RandomState() string

RandomState returns a random anti-CSRF state token.

Types

type Client

type Client struct {
	Endpoint string // e.g. https://api.loradex.ai
	Web      string // e.g. https://loradex.ai
	Token    string // bearer token for the endpoint host (may be empty)
	Insecure bool   // allow http:// for loopback only
	HTTP     *http.Client
	Log      *output.Printer
}

Client talks to the loradex API.

func New

func New(endpoint, web, token string, insecure bool, log *output.Printer) *Client

New builds a Client with sane transport timeouts.

func (*Client) AuthorizeURL

func (c *Client) AuthorizeURL(callback, state, challenge string) string

AuthorizeURL builds the web authorize URL for the loopback flow.

func (*Client) CheckEndpoint

func (c *Client) CheckEndpoint() error

CheckEndpoint enforces HTTPS unless the endpoint is a loopback host with --insecure.

func (*Client) CreateRepo

func (c *Client) CreateRepo(ctx context.Context, owner string, body CreateRepoBody) (*Repo, error)

CreateRepo creates a repository. 409 if it exists.

func (*Client) Download

func (c *Client) Download(ctx context.Context, owner, repo, version, include string) (*DownloadResp, error)

Download requests presigned GET URLs. include = "weights" or "all" (+samples handled server-side).

func (*Client) Exchange

func (c *Client) Exchange(ctx context.Context, code, verifier string) (*ExchangeResp, error)

Exchange swaps the one-time code for a CLI token (non-idempotent; no retry).

func (*Client) FinalizeUpload

func (c *Client) FinalizeUpload(ctx context.Context, owner, repo string, body FinalizeBody) (*FinalizeResp, error)

FinalizeUpload commits the version. Never auto-retried.

func (*Client) GetRepo

func (c *Client) GetRepo(ctx context.Context, owner, repo string) (*Repo, error)

GetRepo fetches full repo metadata (includes readme).

func (*Client) InitiateUpload

func (c *Client) InitiateUpload(ctx context.Context, owner, repo string, body InitiateBody) (*InitiateResp, error)

InitiateUpload requests presigned upload URLs (non-idempotent).

func (*Client) ListFiles

func (c *Client) ListFiles(ctx context.Context, owner, repo, version string) (string, []File, error)

ListFiles returns the files of a version.

func (*Client) ListRepos

func (c *Client) ListRepos(ctx context.Context, p ListReposParams) (*RepoList, error)

ListRepos lists repositories.

func (*Client) ListVersions

func (c *Client) ListVersions(ctx context.Context, owner, repo string) ([]Version, error)

ListVersions returns the version history.

func (*Client) Me

func (c *Client) Me(ctx context.Context) (*Me, error)

Me returns the current identity (validates the token).

func (*Client) Search

func (c *Client) Search(ctx context.Context, p SearchParams) (*RepoList, error)

Search runs compatibility-first + full-text discovery.

type CreateRepoBody

type CreateRepoBody struct {
	Name              string   `json:"name"`
	Description       string   `json:"description"`
	Visibility        string   `json:"visibility"`
	BaseModel         string   `json:"base_model"`
	Format            string   `json:"format"`
	License           string   `json:"license"`
	TriggerWords      []string `json:"trigger_words"`
	NetworkRank       int      `json:"network_rank"`
	NetworkDim        int      `json:"network_dim"`
	RecommendedWeight float64  `json:"recommended_weight"`
	Tags              []string `json:"tags"`
}

CreateRepoBody is the metadata for creating a repo.

type DownloadFile

type DownloadFile struct {
	Name   string `json:"name"`
	URL    string `json:"url"`
	SHA256 string `json:"sha256"`
	Size   int64  `json:"size"`
}

DownloadFile is a presigned GET target with integrity metadata.

type DownloadResp

type DownloadResp struct {
	Version string         `json:"version"`
	Files   []DownloadFile `json:"files"`
}

DownloadResp lists files to download for a version.

type ExchangeResp

type ExchangeResp struct {
	Token     string `json:"token"`
	Handle    string `json:"handle"`
	ExpiresAt string `json:"expires_at"`
}

ExchangeResp is the result of the CLI token exchange.

type ExtraFile

type ExtraFile struct {
	Name   string `json:"name"`
	Size   int64  `json:"size"`
	SHA256 string `json:"sha256"`
}

ExtraFile describes a non-weights file included in an upload (README, config.json, samples).

type File

type File struct {
	Name   string `json:"name"`
	Type   string `json:"type"`
	Size   int64  `json:"size"`
	SHA256 string `json:"sha256"`
}

File is an entry within a version.

type FinalizeBody

type FinalizeBody struct {
	UploadID string     `json:"upload_id"`
	SHA256   string     `json:"sha256"`
	Parts    []PartETag `json:"parts"`
}

FinalizeBody commits the version after upload.

type FinalizeResp

type FinalizeResp struct {
	Version string `json:"version"`
}

FinalizeResp returns the assigned version tag.

type InitiateBody

type InitiateBody struct {
	SHA256          string      `json:"sha256"`
	Size            int64       `json:"size"`
	Filename        string      `json:"filename"`
	ExplicitVersion *string     `json:"explicit_version"`
	ExtraFiles      []ExtraFile `json:"extra_files"`
}

InitiateBody requests presigned upload targets.

type InitiateResp

type InitiateResp struct {
	UploadID    string         `json:"upload_id"`
	Uploads     []UploadTarget `json:"uploads"`
	DuplicateOf *string        `json:"duplicate_of"`
}

InitiateResp is the presigned-upload plan.

type ListReposParams

type ListReposParams struct {
	Owner      string
	Visibility string
	Starred    bool
	Sort       string
	Limit      int
	Page       int
}

ListReposParams filters the list endpoint.

type LoopbackServer

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

LoopbackServer captures the browser redirect on a random localhost port.

func StartLoopback

func StartLoopback() (*LoopbackServer, error)

StartLoopback binds 127.0.0.1:0 and serves /callback.

func (*LoopbackServer) CallbackURL

func (s *LoopbackServer) CallbackURL() string

CallbackURL is the redirect target the web flow must call.

func (*LoopbackServer) Port

func (s *LoopbackServer) Port() int

Port returns the bound port.

func (*LoopbackServer) Shutdown

func (s *LoopbackServer) Shutdown()

Shutdown stops the loopback server.

func (*LoopbackServer) Wait

func (s *LoopbackServer) Wait(ctx context.Context, wantState string, timeout time.Duration) (string, error)

Wait blocks until the callback fires, verifying state, or times out.

type Me

type Me struct {
	Handle       string `json:"handle"`
	Plan         string `json:"plan"`
	StorageUsed  int64  `json:"storage_used"`
	StorageQuota int64  `json:"storage_quota"`
}

Me is the authenticated identity + storage usage.

type PKCE

type PKCE struct {
	Verifier  string
	Challenge string
}

PKCE holds a verifier and its S256 challenge.

func NewPKCE

func NewPKCE() PKCE

NewPKCE generates a PKCE verifier/challenge pair.

type Part

type Part struct {
	PartNumber int    `json:"part_number"`
	URL        string `json:"url"`
	Size       int64  `json:"size"`
}

Part is one presigned part of a multipart upload.

type PartETag

type PartETag struct {
	PartNumber int    `json:"part_number"`
	ETag       string `json:"etag"`
}

PartETag is a completed multipart part.

type Repo

type Repo struct {
	Owner             string   `json:"owner"`
	Name              string   `json:"name"`
	Description       string   `json:"description"`
	Visibility        string   `json:"visibility"`
	BaseModel         string   `json:"base_model"`
	Format            string   `json:"format"`
	License           string   `json:"license"`
	TriggerWords      []string `json:"trigger_words"`
	NetworkRank       int      `json:"network_rank"`
	NetworkDim        int      `json:"network_dim"`
	RecommendedWeight float64  `json:"recommended_weight"`
	Tags              []string `json:"tags"`
	Downloads         int64    `json:"downloads"`
	Stars             int64    `json:"stars"`
	LatestVersion     string   `json:"latest_version"`
	Size              int64    `json:"size"`
	UpdatedAt         string   `json:"updated_at"`
	Readme            string   `json:"readme,omitempty"`
}

Repo is repository metadata. `readme` is present on detail responses only.

type RepoList

type RepoList struct {
	Items []Repo `json:"items"`
	Page  int    `json:"page"`
	Total int    `json:"total"`
}

RepoList is the standard paginated envelope.

type SearchParams

type SearchParams struct {
	Query  string
	Base   []string
	Format []string
	Tag    []string
	Sort   string
	Limit  int
	Page   int
}

SearchParams filters the search endpoint. base/format/tag are repeatable.

type UploadTarget

type UploadTarget struct {
	Name        string            `json:"name"`
	Method      string            `json:"method"`
	URL         string            `json:"url"`
	Headers     map[string]string `json:"headers"`
	Parts       []Part            `json:"parts"`        // multipart (large files)
	CompleteURL string            `json:"complete_url"` // multipart completion
}

UploadTarget is a presigned destination for a single file.

type Version

type Version struct {
	Tag       string `json:"tag"`
	CreatedAt string `json:"created_at"`
	Size      int64  `json:"size"`
	SHA256    string `json:"sha256"`
	Notes     string `json:"notes"`
}

Version is an immutable published version.

Jump to

Keyboard shortcuts

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