api

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 16 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 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

View Source
const (
	HeaderWorkspace      = "x-rafiiq-workspace"
	HeaderIdempotencyKey = "Idempotency-Key"
)

Header names the API reads and writes.

Variables

This section is empty.

Functions

func MapError

func MapError(status int, body []byte, requestID string) *exitcode.Error

MapError turns an HTTP error response into a typed error with the right exit code.

func NewUUID

func NewUUID() string

NewUUID returns a random (version 4) UUID.

func Redact

func Redact(s string) string

Redact removes anything that looks like a token from s.

func SleepContext

func SleepContext(ctx context.Context, d time.Duration) error

SleepContext sleeps for d or until ctx ends.

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

func New(baseURL string, httpClient *http.Client) *Client

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) Diff

func (c *Client) Diff(ctx context.Context, id string) (*SessionDiff, error)

Diff is GET /v1/sessions/:id/diff.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req Request, out any) (*Response, error)

Do performs the request and decodes a JSON response into out (when out is not nil).

func (*Client) Events

func (c *Client) Events(ctx context.Context, id string, since int) ([]Event, error)

Events is GET /v1/sessions/:id/events?since=.

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

func (c *Client) GetSession(ctx context.Context, id string) (*Session, error)

GetSession is GET /v1/sessions/:id.

func (*Client) GetStatus

func (c *Client) GetStatus(ctx context.Context, id string) (*Status, json.RawMessage, error)

GetStatus is GET /v1/sessions/:id/status; the raw JSON is returned too, so --json passes every field through.

func (*Client) Invite

func (c *Client) Invite(ctx context.Context, id, login, role string) (*Person, error)

Invite is POST /v1/sessions/:id/people.

func (*Client) ListSessions

func (c *Client) ListSessions(ctx context.Context, f ListFilter) (*SessionPage, error)

ListSessions is GET /v1/sessions.

func (*Client) Me

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

Me is GET /v1/me.

func (*Client) Models added in v0.1.2

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

Models is GET /v1/models.

func (*Client) NetworkAllow

func (c *Client) NetworkAllow(ctx context.Context, id, host, scope, access string) error

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) People

func (c *Client) People(ctx context.Context, id string) ([]Person, error)

People is GET /v1/sessions/:id/people.

func (*Client) PreviewURL

func (c *Client) PreviewURL(ctx context.Context, id, slug string) (string, error)

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

func (c *Client) RemovePerson(ctx context.Context, id, userID string) error

RemovePerson is DELETE /v1/sessions/:id/people/:userId.

func (c *Client) RevokeShareLink(ctx context.Context, id string) error

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 (c *Client) SetShareLink(ctx context.Context, id, role string) (*ShareLink, error)

SetShareLink is PUT /v1/sessions/:id/share-link.

func (*Client) SetVisibility

func (c *Client) SetVisibility(ctx context.Context, id, visibility, teamID string) error

SetVisibility is PUT /v1/sessions/:id/visibility.

func (*Client) StartWorking

func (c *Client) StartWorking(ctx context.Context, id, proposalID string) error

StartWorking accepts "Work on this in a sandbox?" (the `session.start_working` command).

func (*Client) Steer

func (c *Client) Steer(ctx context.Context, id, text, key string) (*CommandResult, error)

Steer steers the running run.

func (*Client) StopRun

func (c *Client) StopRun(ctx context.Context, id string) error

StopRun is POST /v1/sessions/:id/commands with a run.stop 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.

func (*Client) Surfaces

func (c *Client) Surfaces(ctx context.Context, id string) (*SurfacesView, error)

Surfaces is GET /v1/sessions/:id/surfaces.

func (*Client) ToolApprovalDecide

func (c *Client) ToolApprovalDecide(ctx context.Context, id, requestID, decision string) error

ToolApprovalDecide is the `tool.approval.decide` command: once, session or deny.

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

func (e Event) MarshalJSON() ([]byte, error)

MarshalJSON writes the server's own JSON when known.

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(b []byte) error

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

type EventsQuery struct {
	Since  int
	Tail   int
	Limit  int
	Before int
}

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 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

type ModelRoute struct {
	Model     string   `json:"model"`
	Fallbacks []string `json:"fallbacks"`
}

ModelRoute is the model a role uses, and its fallbacks.

type Models added in v0.1.2

type Models struct {
	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

func (m *Models) Default() string

Default is the model prompts use when none is chosen: the agent role's.

func (*Models) Find added in v0.1.2

func (m *Models) Find(query string) (Model, []Model, bool)

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) Matches added in v0.1.2

func (m *Models) Matches(model Model, query string) bool

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

func (m *Models) ProviderTitle(id string) string

ProviderTitle is a provider's display name.

func (*Models) Sorted added in v0.1.2

func (m *Models) Sorted() []Model

Sorted lists the models: usable ones first, then by provider and title.

func (*Models) Why added in v0.1.2

func (m *Models) Why(model Model) string

Why says why a model can't be used here, or "" when it can.

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"`
	Shared    bool   `json:"shared,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

type PullRequest struct {
	Number int    `json:"number"`
	URL    string `json:"url"`
}

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 RepoInput

type RepoInput struct {
	CloneURL string `json:"cloneUrl"`
	Branch   string `json:"branch,omitempty"`
}

RepoInput is a repository to start a session on.

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 Response

type Response struct {
	Status    int
	Header    http.Header
	RequestID string
}

Response is what a successful call returns besides the decoded body.

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

type SandboxStatus struct {
	Status string `json:"status"`
	Detail string `json:"detail,omitempty"`
}

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

func (s Session) MarshalJSON() ([]byte, error)

MarshalJSON writes the server's own JSON when known, so output keeps every field.

func (*Session) UnmarshalJSON

func (s *Session) UnmarshalJSON(b []byte) error

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 struct {
	Role      string `json:"role"`
	URL       string `json:"url"`
	CreatedAt string `json:"createdAt"`
}

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.

type TokenSource

type TokenSource interface {
	Token(ctx context.Context) (string, error)
	Refresh(ctx context.Context) (string, bool)
}

TokenSource supplies the bearer token for a request. Refresh is called once after a 401 and returns a new token when the credential can be renewed.

Jump to

Keyboard shortcuts

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