api

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 23 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 api is the shared authenticated-client layer over github.com/vibexp/api-client-go: a retry/timeout transport, an auth request editor sourced from the credential store, a uniform RFC 7807 error mapper, and team/project resolution. Commands never touch the generated client directly — they go through New.

Index

Constants

View Source
const CodeWriteLocked = "RESOURCE_WRITE_LOCKED"

CodeWriteLocked is the problem code of a write refused because the prompt, blueprint or artifact is locked (423, platform v0.15.0).

Variables

This section is empty.

Functions

func Check

func Check(status int, body []byte) error

Check turns any non-2xx response into an *Error, decoding the shared application/problem+json ErrorResponse body. 2xx returns nil. Non-7807 bodies (proxies, gateways) fall back to the HTTP status text.

func IsUUID

func IsUUID(v string) bool

IsUUID reports whether v is a canonical 36-character UUID (uuid.Validate alone also accepts the urn: and braced forms, which REST paths do not).

func MissingBaseURLError

func MissingBaseURLError(rt *config.Runtime) error

MissingBaseURLError is the usage error for a runtime with no base URL. It names both ways to set one: the environment (natural in containers, next to the API key) and the context.

func New

func New(ctx context.Context, rt *config.Runtime, credStore *cred.Store, getenv func(string) string) (*vibexp.ClientWithResponses, error)

New returns a ready authenticated client for the resolved runtime: base URL, the retry/timeout transport, and an auth request editor sourced from the credential store (API key, env, or a transparently-refreshed OAuth token).

func NewSlugResolver

func NewSlugResolver(ctx context.Context, rt *config.Runtime, creds func() (*cred.Store, error), getenv func(string) string) config.SlugResolver

NewSlugResolver returns the SlugResolver the root installs on the runtime it builds. It is lazy: the credential store is opened and a RawClient built only on the first lookup (then reused), so a command that never resolves a slug — or never needs credentials at all — pays nothing. rt is read at that first lookup, for its base URL, timeout and context. ctx is the root's command context, the parent of every command's own.

func OptionalProject

func OptionalProject(rt *config.Runtime) (string, error)

OptionalProject is Project for commands where the project only narrows the result: it returns "" with no error when no project is set.

func Project

func Project(rt *config.Runtime) (string, error)

Project returns the resolved project id, same precedence and error contract as Team. A slug is looked up within the (resolved) team.

func ReadBody

func ReadBody(resp *http.Response) ([]byte, error)

ReadBody reads and closes a response body (capped) for rendering / error mapping.

func Stream

func Stream(fileField, filename, fileContentType string, r io.Reader, fields map[string]string) (io.ReadCloser, string)

Stream builds a streamed multipart/form-data body. It returns a ReadCloser that yields the encoded body and the request Content-Type (carrying the boundary) to send with it. The file part is streamed from r through an io.Pipe + multipart.Writer running in a goroutine, so process memory stays bounded regardless of file size. Any extra text fields are written before the file part. Encoding errors are propagated to the reader via CloseWithError.

The caller MUST Close the returned body when done: on a normal send the goroutine finishes on its own, but if the request errors before the body is fully read (auth failure, an early 4xx/5xx such as 413), Close unblocks the still-writing goroutine so it cannot leak.

It is owner-agnostic so both team-scoped and (future) artifact-scoped attachment uploads can reuse it.

func Team

func Team(rt *config.Runtime) (string, error)

Team returns the resolved team id for a team-scoped command. The precedence (--team > VIBEXP_TEAM > active-context default) is already applied in config.Resolve. REST paths take only a UUID, so a slug is looked up through the runtime's SlugResolver (installed by the root when it builds the runtime, see NewSlugResolver) and the UUID is written back to rt, so later calls in the same invocation make no request. A missing team is a usage error (exit 2) naming all three ways to set it.

func UserAgent

func UserAgent() string

UserAgent identifies the CLI on every platform request. The platform matches the "VibeXP-CLI/" prefix case-sensitively to attribute API-key reads and writes to the cli channel instead of api (backend/internal/services/resourceaccess/source.go).

func WithDiscoveryCache

func WithDiscoveryCache(ctx context.Context) context.Context

WithDiscoveryCache returns a copy of ctx carrying an OAuth discovery cache, so every client built under it — the command's own and the slug resolver's — discovers a base URL once. The root installs it for each invocation.

Types

type Doer

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

Doer implements the generated HttpRequestDoer interface, adding a request timeout, a User-Agent, and bounded exponential-backoff retries for transient failures on safe (retryable) methods only.

func NewDoer

func NewDoer(timeout time.Duration) *Doer

NewDoer builds a Doer with the given per-request timeout (0 → default 30s).

func (*Doer) Do

func (d *Doer) Do(req *http.Request) (*http.Response, error)

Do sends the request, retrying transient failures (429 / 5xx / transport errors) on retryable methods with exponential backoff + jitter, honoring Retry-After.

type Error

type Error struct {
	Status    int
	Code      string
	Detail    string
	RequestID string
	Fields    []FieldError
	// Lock is the lock that refused the write; set only for a 423
	// RESOURCE_WRITE_LOCKED, from the problem's metadata.
	Lock *LockInfo
}

Error is the single uniform CLI error produced from any non-2xx API response. It carries the RFC 7807 problem detail, field-level validation errors, and the request id (always surfaced for supportability).

func (*Error) Error

func (e *Error) Error() string

Error renders the problem for the user: detail, then any field errors, then the request id.

func (*Error) ExitCode

func (e *Error) ExitCode() int

ExitCode maps the HTTP status to a CLI exit code: 401/403 → auth (4), everything else → runtime (1). Satisfies exitcode.ExitCoder.

type FieldError

type FieldError struct {
	Field   string
	Message string
	Code    string
}

FieldError is one field-level validation failure.

type Health

type Health struct {
	Status string `json:"status"`
	Sha    string `json:"sha"`
}

Health is the server's /health payload (the version/compat handle).

func FetchHealth

func FetchHealth(ctx context.Context, hc *http.Client, baseURL string) (*Health, error)

FetchHealth performs an unauthenticated GET <baseURL>/health. It is used by `vibexp version` to report the server release sha, and degrades gracefully (the caller ignores the error) when the server is unreachable.

type LockInfo

type LockInfo struct {
	ResourceType string `json:"resource_type"`
	// Field is the frozen field the update tried to change; empty on a delete.
	Field    string `json:"field"`
	Comment  string `json:"comment"`
	LockedBy struct {
		DisplayName string `json:"display_name"`
	} `json:"locked_by"`
}

LockInfo is the lock named in a RESOURCE_WRITE_LOCKED problem's metadata.

type RawClient

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

RawClient issues authenticated requests to arbitrary paths against the active context, reusing the same transport (timeout/retry/UA) and auth editor as the generated client. It backs `vibexp api`.

func NewRaw

func NewRaw(ctx context.Context, rt *config.Runtime, credStore *cred.Store, getenv func(string) string) (*RawClient, error)

NewRaw builds a RawClient for the resolved runtime. It does not touch rt.

func (*RawClient) BaseURL

func (c *RawClient) BaseURL() string

BaseURL returns the client's base URL.

func (*RawClient) Do

func (c *RawClient) Do(ctx context.Context, method, path string, body []byte, headers http.Header) (*http.Response, error)

Do builds, authenticates, and sends a request. path must be a server-relative path (may include a query string); body may be nil. Default headers are set first, then caller headers override, then auth is applied last.

func (*RawClient) DoStream

func (c *RawClient) DoStream(ctx context.Context, method, path, contentType string, r io.Reader) (*http.Response, error)

DoStream sends a request whose body is streamed from r with an explicit Content-Type (e.g. a multipart boundary type from Stream). Unlike Do it never buffers the body into memory, so it is safe for large uploads. The body is not replayable; this is used only with non-idempotent methods (POST), which the Doer never retries.

Jump to

Keyboard shortcuts

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