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
- func Check(status int, body []byte) error
- func IsUUID(v string) bool
- func MissingBaseURLError(rt *config.Runtime) error
- func New(ctx context.Context, rt *config.Runtime, credStore *cred.Store, ...) (*vibexp.ClientWithResponses, error)
- func NewSlugResolver(ctx context.Context, rt *config.Runtime, creds func() (*cred.Store, error), ...) config.SlugResolver
- func OptionalProject(rt *config.Runtime) (string, error)
- func Project(rt *config.Runtime) (string, error)
- func ReadBody(resp *http.Response) ([]byte, error)
- func Stream(fileField, filename, fileContentType string, r io.Reader, ...) (io.ReadCloser, string)
- func Team(rt *config.Runtime) (string, error)
- func UserAgent() string
- func WithDiscoveryCache(ctx context.Context) context.Context
- type Doer
- type Error
- type FieldError
- type Health
- type LockInfo
- type RawClient
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
OptionalProject is Project for commands where the project only narrows the result: it returns "" with no error when no project is set.
func Project ¶
Project returns the resolved project id, same precedence and error contract as Team. A slug is looked up within the (resolved) team.
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 ¶
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 ¶
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.
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).
type FieldError ¶
FieldError is one field-level validation failure.
type Health ¶
Health is the server's /health payload (the version/compat handle).
func FetchHealth ¶
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) 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.