Documentation
¶
Overview ¶
Package api is the HTTP adapter for Waniis's public /v1 API: base URL, bearer and workspace headers, timeouts, retries, idempotency keys and error mapping to exit codes.
Index ¶
- Constants
- func MapError(status int, body []byte, requestID string) *exitcode.Error
- func NewUUID() string
- func Redact(s string) string
- func SleepContext(ctx context.Context, d time.Duration) error
- type Actor
- type ApprovalStatus
- type Client
- func (c *Client) Command(ctx context.Context, id string, body any, key string) (*CommandResult, error)
- func (c *Client) CreateSession(ctx context.Context, in CreateSessionInput, key string) (*CreatedSession, error)
- func (c *Client) Diff(ctx context.Context, id string) (*SessionDiff, error)
- func (c *Client) Do(ctx context.Context, req Request, out any) (*Response, error)
- func (c *Client) Events(ctx context.Context, id string, since int) ([]Event, error)
- func (c *Client) EventsPage(ctx context.Context, id string, eq EventsQuery) (*EventsPage, error)
- func (c *Client) GetSession(ctx context.Context, id string) (*Session, error)
- func (c *Client) GetStatus(ctx context.Context, id string) (*Status, json.RawMessage, error)
- func (c *Client) Invite(ctx context.Context, id, login, role string) (*Person, error)
- func (c *Client) ListSessions(ctx context.Context, f ListFilter) (*SessionPage, error)
- func (c *Client) Me(ctx context.Context) (*Me, error)
- func (c *Client) Models(ctx context.Context) (*Models, error)
- func (c *Client) NetworkAllow(ctx context.Context, id, host, scope, access string) error
- func (c *Client) NetworkDecide(ctx context.Context, id, requestID string, approve bool, scope string) error
- func (c *Client) People(ctx context.Context, id string) ([]Person, error)
- func (c *Client) PreviewURL(ctx context.Context, id, slug string) (string, error)
- func (c *Client) RemovePerson(ctx context.Context, id, userID string) error
- func (c *Client) RevokeShareLink(ctx context.Context, id string) error
- func (c *Client) SearchSessions(ctx context.Context, f ListFilter) (*SessionPage, error)
- func (c *Client) SetShareLink(ctx context.Context, id, role string) (*ShareLink, error)
- func (c *Client) SetVisibility(ctx context.Context, id, visibility, teamID string) error
- func (c *Client) StartWorking(ctx context.Context, id, proposalID string) error
- func (c *Client) Steer(ctx context.Context, id, text, key string) (*CommandResult, error)
- func (c *Client) StopRun(ctx context.Context, id string) error
- func (c *Client) SubmitPrompt(ctx context.Context, id string, p PromptCommand, key string) (*CommandResult, error)
- func (c *Client) Surfaces(ctx context.Context, id string) (*SurfacesView, error)
- func (c *Client) ToolApprovalDecide(ctx context.Context, id, requestID, decision string) error
- type CommandResult
- type CreateSessionInput
- type CreatedSession
- type DiffFile
- type Event
- type EventsPage
- type EventsQuery
- type Interpretation
- type ListFilter
- type Me
- type Model
- type ModelChoice
- type ModelProvider
- type ModelRoute
- type Models
- func (m *Models) Default() string
- func (m *Models) Find(query string) (Model, []Model, bool)
- func (m *Models) Locked() (bool, string)
- func (m *Models) Matches(model Model, query string) bool
- func (m *Models) ProviderTitle(id string) string
- func (m *Models) Routed() bool
- func (m *Models) Sorted() []Model
- func (m *Models) Why(model Model) string
- type OutcomeStatus
- type PRStatus
- type Person
- type PrivateMark
- type PromptCommand
- type PromptInput
- type PullRequest
- type Repo
- type RepoDiff
- type RepoInput
- type Request
- type Response
- type Routing
- type RunCompleted
- type RunStatus
- type SandboxStatus
- type Session
- type SessionDiff
- type SessionPage
- type ShareLink
- type Status
- type Surface
- type SurfacesView
- type TokenSource
Constants ¶
const ( HeaderWorkspace = "x-rafiiq-workspace" HeaderIdempotencyKey = "Idempotency-Key" )
Header names the API reads and writes.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Actor ¶
type Actor struct {
Kind string `json:"kind"`
ID string `json:"id,omitempty"`
SessionID string `json:"sessionId,omitempty"`
Name string `json:"name,omitempty"`
}
Actor says who caused an event.
type ApprovalStatus ¶
type ApprovalStatus struct {
Kind string `json:"kind"` // tool or network
RequestID string `json:"requestId"`
What string `json:"what"`
ExpiresAt string `json:"expiresAt,omitempty"`
}
ApprovalStatus is something waiting for a person (derived from the events by the CLI).
type Client ¶
type Client struct {
BaseURL string
HTTP *http.Client
Tokens TokenSource // nil for unauthenticated calls (device flow)
Workspace string
UserAgent string
Timeout time.Duration
MaxRetries int
BaseDelay time.Duration
Sleep func(context.Context, time.Duration) error
NewKey func() string
Log io.Writer // verbose request log, redacted; nil disables
}
Client talks to the API. Build it with New; the zero value is not usable.
func New ¶
New builds a Client with the defaults: 30 s timeout, 3 retries, real sleeping, random UUID keys.
func (*Client) Command ¶
func (c *Client) Command(ctx context.Context, id string, body any, key string) (*CommandResult, error)
Command is POST /v1/sessions/:id/commands with an Idempotency-Key (key empty: a fresh one).
func (*Client) CreateSession ¶
func (c *Client) CreateSession(ctx context.Context, in CreateSessionInput, key string) (*CreatedSession, error)
CreateSession is POST /v1/sessions with an Idempotency-Key.
func (*Client) Do ¶
Do performs the request and decodes a JSON response into out (when out is not nil).
func (*Client) EventsPage ¶
func (c *Client) EventsPage(ctx context.Context, id string, eq EventsQuery) (*EventsPage, error)
EventsPage is GET /v1/sessions/:id/events.
func (*Client) GetSession ¶
GetSession is GET /v1/sessions/:id.
func (*Client) GetStatus ¶
GetStatus is GET /v1/sessions/:id/status; the raw JSON is returned too, so --json passes every field through.
func (*Client) ListSessions ¶
func (c *Client) ListSessions(ctx context.Context, f ListFilter) (*SessionPage, error)
ListSessions is GET /v1/sessions.
func (*Client) NetworkAllow ¶
NetworkAllow allows a host the sandbox was refused (workspace owners and admins only).
func (*Client) NetworkDecide ¶
func (c *Client) NetworkDecide(ctx context.Context, id, requestID string, approve bool, scope string) error
NetworkDecision answers an agent's request for a host.
func (*Client) PreviewURL ¶
PreviewURL asks for a surface's one-time link (GET /:id/surfaces/:slug/open answers a 302 with a 60-second, single-use ticket) and returns the Location without following it.
func (*Client) RemovePerson ¶
RemovePerson is DELETE /v1/sessions/:id/people/:userId.
func (*Client) RevokeShareLink ¶
RevokeShareLink is DELETE /v1/sessions/:id/share-link.
func (*Client) SearchSessions ¶
func (c *Client) SearchSessions(ctx context.Context, f ListFilter) (*SessionPage, error)
SearchSessions is GET /v1/sessions/search.
func (*Client) SetShareLink ¶
SetShareLink is PUT /v1/sessions/:id/share-link.
func (*Client) SetVisibility ¶
SetVisibility is PUT /v1/sessions/:id/visibility.
func (*Client) StartWorking ¶
StartWorking accepts "Work on this in a sandbox?" (the `session.start_working` command).
func (*Client) SubmitPrompt ¶
func (c *Client) SubmitPrompt(ctx context.Context, id string, p PromptCommand, key string) (*CommandResult, error)
SubmitPrompt appends a prompt: queued when a run is going, started when the session is idle.
type CommandResult ¶
type CommandResult struct {
Events []Event `json:"events"`
PromptID string `json:"promptId"`
RunID string `json:"runId"`
Position *int `json:"position"`
Queued *bool `json:"queued"`
}
CommandResult is the answer to POST /v1/sessions/:id/commands. A prompt.submit answers with the queued prompt (promptId, position, and runId when it started at once) and a run.steer with the run it steered; the events the command produced are kept too, so the ids are also found there when the server only sends events.
func (*CommandResult) Resolve ¶
func (r *CommandResult) Resolve()
Resolve fills PromptID, RunID and Position from the events when the server didn't send them.
type CreateSessionInput ¶
type CreateSessionInput struct {
Title string `json:"title,omitempty"`
Visibility string `json:"visibility,omitempty"`
TeamID string `json:"teamId,omitempty"`
Repos []RepoInput `json:"repos,omitempty"`
Stage string `json:"stage,omitempty"`
Prompt *PromptInput `json:"prompt,omitempty"`
}
CreateSessionInput is the body of POST /v1/sessions (CORE-06 plus G6's first prompt).
type CreatedSession ¶
type CreatedSession struct {
ID string `json:"id"`
Events json.RawMessage `json:"events,omitempty"`
}
CreatedSession is the 201 answer to a create.
type DiffFile ¶
type DiffFile struct {
Path string `json:"path"`
Status string `json:"status"`
Additions int `json:"additions"`
Deletions int `json:"deletions"`
}
DiffFile is one changed file in a session's diff.
type Event ¶
type Event struct {
V int `json:"v,omitempty"`
Seq int `json:"seq"`
Type string `json:"type"`
At string `json:"at"`
Actor *Actor `json:"actor,omitempty"`
Private *PrivateMark `json:"private,omitempty"`
Payload json.RawMessage `json:"payload"`
Raw json.RawMessage `json:"-"`
}
Event is one session event (FND-05): its sequence number, type and payload. Raw keeps the server's own JSON so --json passes every field through.
func (Event) MarshalJSON ¶
MarshalJSON writes the server's own JSON when known.
func (*Event) UnmarshalJSON ¶
UnmarshalJSON decodes an event and keeps the raw bytes.
type EventsPage ¶
type EventsPage struct {
Events []Event `json:"events"`
LastSeq int `json:"lastSeq"`
HasMore bool `json:"hasMore"`
HasLastSeq bool `json:"-"`
}
EventsPage is the events answer: `{events, lastSeq, hasMore}`. The older answer is only `{events}`; HasLastSeq says whether the server sent lastSeq.
type EventsQuery ¶
EventsQuery picks which events GET /v1/sessions/:id/events returns. Since is always sent unless Tail is set; Tail asks for the last N events; Limit and Before page.
type Interpretation ¶
type Interpretation struct {
Repos []string `json:"repos,omitempty"`
People []string `json:"people,omitempty"`
Status []string `json:"status,omitempty"`
Stage string `json:"stage,omitempty"`
Since string `json:"since,omitempty"`
Until string `json:"until,omitempty"`
PRState string `json:"prState,omitempty"`
Text string `json:"text,omitempty"`
Raw json.RawMessage `json:"-"`
}
Interpretation says how a natural-language search was understood (FR-9). The fields are the spec's `interpreted: { repos, since, prState, text }`; the rest are kept in Raw.
func (Interpretation) MarshalJSON ¶
func (i Interpretation) MarshalJSON() ([]byte, error)
MarshalJSON writes the server's own JSON when known.
func (*Interpretation) UnmarshalJSON ¶
func (i *Interpretation) UnmarshalJSON(b []byte) error
UnmarshalJSON decodes the interpretation and keeps the raw bytes.
type ListFilter ¶
type ListFilter struct {
Filter string // mine|shared|archived|all
Status []string
Repo []string
Author string
Stage string
Since string
Until string
HasPR bool
Limit int
Cursor string
Query string // search only: the natural-language text
NoInterpret bool // search only
}
ListFilter is every filter `sessions list` and `sessions search` can send.
type Me ¶
type Me struct {
ID string `json:"id"`
Login string `json:"login"`
Name string `json:"name"`
Workspaces []struct {
ID string `json:"id"`
Name string `json:"name"`
Kind string `json:"kind"`
} `json:"workspaces"`
}
Me is the signed-in person with their workspaces (GET /v1/me).
type Model ¶ added in v0.1.2
type Model struct {
Ref string `json:"ref"`
Provider string `json:"provider"`
Title string `json:"title"`
Tier string `json:"tier"`
Source string `json:"source"`
Available bool `json:"available"`
}
Model is one model the workspace knows (GET /v1/models).
type ModelChoice ¶ added in v0.1.5
ModelChoice says whether people may choose a model; locked means the router always decides.
type ModelProvider ¶ added in v0.1.2
type ModelProvider struct {
ID string `json:"id"`
Title string `json:"title"`
Managed bool `json:"managed"`
Key *struct {
Last4 string `json:"last4"`
} `json:"key"`
}
ModelProvider is a provider and whether the workspace can use it: a key of its own, or one Waniis manages. The key's value is never sent.
type ModelRoute ¶ added in v0.1.2
ModelRoute is the model a role uses, and its fallbacks.
type Models ¶ added in v0.1.2
type Models struct {
Routing *Routing `json:"routing"`
ModelChoice *ModelChoice `json:"modelChoice"`
Providers []ModelProvider `json:"providers"`
Models []Model `json:"models"`
Routes map[string]ModelRoute `json:"routes"`
CanManage bool `json:"canManage"`
}
Models is the workspace's models view.
func (*Models) Default ¶ added in v0.1.2
Default is the model prompts use when none is chosen: the agent role's.
func (*Models) Find ¶ added in v0.1.2
Find resolves what someone typed to one model: its exact ref, its id without the provider ("claude-sonnet-5-5" for "anthropic/claude-sonnet-5-5"), its title, or the only one that matches every word. It returns the candidates when several match.
func (*Models) Locked ¶ added in v0.1.5
Locked says whether the workspace keeps the choice of model to its router, and why.
func (*Models) Matches ¶ added in v0.1.2
Matches says whether every word of query is in the model's ref, title, provider or tier.
func (*Models) ProviderTitle ¶ added in v0.1.2
ProviderTitle is a provider's display name.
type OutcomeStatus ¶
type OutcomeStatus struct {
ID string `json:"id,omitempty"`
Outcome string `json:"outcome"`
Summary string `json:"summary,omitempty"`
At string `json:"at,omitempty"`
}
OutcomeStatus is how the last run ended.
type PRStatus ¶
type PRStatus struct {
Repo string `json:"repo,omitempty"`
Number int `json:"number"`
URL string `json:"url"`
Draft bool `json:"draft"`
State string `json:"state,omitempty"` // only in what the CLI derives itself
}
PRStatus is a session's pull request.
type Person ¶
type Person struct {
ID string `json:"id"`
Name string `json:"name"`
Login string `json:"login"`
Role string `json:"role,omitempty"`
}
Person is someone on a session.
type PrivateMark ¶
type PrivateMark struct {
ID string `json:"id"`
Kind string `json:"kind"`
OwnerID string `json:"ownerId"`
OwnerName string `json:"ownerName,omitempty"`
Server string `json:"server"`
Title string `json:"title"`
Hidden bool `json:"hidden,omitempty"`
}
PrivateMark marks a personal result (DEC-155): only its owner sees the content; everyone else gets a placeholder.
type PromptCommand ¶
type PromptCommand struct {
Type string `json:"type"`
Text string `json:"text"`
Mode string `json:"mode,omitempty"`
Model string `json:"model,omitempty"`
Source string `json:"source"`
}
PromptCommand is a `prompt.submit` command.
type PromptInput ¶
type PromptInput struct {
Type string `json:"type"`
Text string `json:"text"`
Mode string `json:"mode,omitempty"`
Model string `json:"model,omitempty"`
Source string `json:"source"`
}
PromptInput is the first prompt of a new session: a protocol `prompt.submit` command.
type PullRequest ¶
PullRequest is a session's pull request link.
type Repo ¶
type Repo struct {
FullName string `json:"fullName"`
CloneURL string `json:"cloneUrl,omitempty"`
Branch string `json:"branch,omitempty"`
}
Repo is a repository a session works on.
type RepoDiff ¶
type RepoDiff struct {
Repo string `json:"repo"`
Source string `json:"source"`
PullRequest *struct {
Number int `json:"number"`
URL string `json:"url"`
} `json:"pullRequest"`
Files []DiffFile `json:"files"`
TotalFiles int `json:"totalFiles"`
}
RepoDiff is one repo's changes: pushed (from GitHub) or kept (still in the sandbox).
type Request ¶
type Request struct {
Method string
Path string // e.g. "/v1/sessions"
Query url.Values
Body any // marshalled as JSON when not nil
// Idempotent makes the call send an Idempotency-Key (generated unless Key is set) and so
// retry safely on network errors, 429 and 5xx.
Idempotent bool
Key string
// Anonymous skips the Authorization header (the device flow).
Anonymous bool
}
Request describes one API call.
type Routing ¶ added in v0.1.5
type Routing struct {
Mode string `json:"mode"`
}
Routing is the task router's settings: auto picks a tier per task, off uses the role routes.
type RunCompleted ¶
type RunCompleted struct {
RunID string `json:"runId"`
Outcome string `json:"outcome"`
Summary string `json:"summary"`
CostUSD float64 `json:"costUsd"`
}
RunCompleted is the payload of a run.completed event.
type RunStatus ¶
type RunStatus struct {
ID string `json:"id"`
PromptID string `json:"promptId,omitempty"`
Mode string `json:"mode,omitempty"`
Stage string `json:"stage,omitempty"` // starting, working, verifying, publishing
StartedAt string `json:"startedAt,omitempty"`
}
RunStatus is the current run in a Status.
type SandboxStatus ¶
SandboxStatus is the sandbox's state.
type Session ¶
type Session struct {
ID string `json:"id"`
Title string `json:"title"`
Repos []Repo `json:"repos"`
Status string `json:"status"`
Stage string `json:"stage"`
PullRequest *PullRequest `json:"pullRequest"`
CreatedAt time.Time `json:"createdAt"`
LastActiveAt time.Time `json:"lastActiveAt"`
Visibility string `json:"visibility"`
Owner *Person `json:"owner"`
Raw json.RawMessage `json:"-"`
}
Session is the list/summary shape (CORE-06 session index). Raw keeps the server's own JSON so --json passes every field through, including ones this CLI doesn't know yet.
func (Session) MarshalJSON ¶
MarshalJSON writes the server's own JSON when known, so output keeps every field.
func (*Session) UnmarshalJSON ¶
UnmarshalJSON decodes a session and keeps the raw bytes.
type SessionDiff ¶
type SessionDiff struct {
Repos []RepoDiff `json:"repos"`
Gaps []struct {
Source string `json:"source"`
Repo string `json:"repo"`
Reason string `json:"reason"`
} `json:"gaps"`
}
SessionDiff is GET /v1/sessions/:id/diff, without the patches.
type SessionPage ¶
type SessionPage struct {
Items []Session `json:"items"`
Sessions []Session `json:"sessions"`
Next *string `json:"next"`
NextCursor *string `json:"nextCursor"`
Interpreted *Interpretation `json:"interpreted"`
}
SessionPage is one page of sessions. The API's list answers `{sessions, next}` today and `{items, next}` per the CLI spec; both are read.
func (*SessionPage) All ¶
func (p *SessionPage) All() []Session
All returns the page's sessions whichever key the server used.
func (*SessionPage) Cursor ¶
func (p *SessionPage) Cursor() string
Cursor is the cursor for the next page, empty when this was the last.
type ShareLink ¶
type ShareLink struct {
}
ShareLink is the session's share link as its owner sees it.
type Status ¶
type Status struct {
Stage string `json:"stage"` // chat or working
Activity string `json:"activity"` // running or idle
Run *RunStatus `json:"run"`
Queued int `json:"queued"`
LastRun *OutcomeStatus `json:"lastRun"`
PullRequest *PRStatus `json:"pullRequest"`
Sandbox *SandboxStatus `json:"sandbox"`
LastSeq int `json:"lastSeq"`
At string `json:"at,omitempty"`
}
Status is GET /v1/sessions/:id/status: {stage, activity, run, queued, lastRun, pullRequest, sandbox, lastSeq, at}. When the server has no such route the CLI derives the same shape from the session's latest events.
type Surface ¶
type Surface struct {
Port int `json:"port"`
Label string `json:"label"`
Service string `json:"service"`
Listening bool `json:"listening"`
}
Surface is a preview port of a session's sandbox.
type SurfacesView ¶
type SurfacesView struct {
Sandbox string `json:"sandbox"`
Previews bool `json:"previews"`
Ports []Surface `json:"ports"`
}
SurfacesView is GET /v1/sessions/:id/surfaces.