Documentation
¶
Overview ¶
Package runnerapi holds the wire types of Beekeeper's runner API, which a runner speaks to Beekeeper over HTTP and JSON under /runner/v1.
A runner authenticates every request with its key, `Authorization: Bearer <runner key>`, and its host's current OIDC token in HostTokenHeader. It holds one stream open (GET /stream), on which Beekeeper sends one Message per line, and answers offers and reports with POSTs.
Index ¶
Constants ¶
const ( PathRegister = "/register" PathDeregister = "/deregister" PathStream = "/stream" PathAnswer = "/answer" PathStatus = "/status" PathSession = "/session" PathUsage = "/usage" )
The endpoints, under PathPrefix.
const HostTokenHeader = "X-Beekeeper-Host-Token" // #nosec G101 -- a header's name, not a credential.
HostTokenHeader carries the host's OIDC ID token on every runner request.
const PathPrefix = "/runner/v1"
PathPrefix is the runner API's path.
const PingInterval = 25 * time.Second
PingInterval is how often Beekeeper pings an open stream.
const StreamContentType = "application/x-ndjson"
StreamContentType is the stream's content type: one JSON Message per line.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Answer ¶
type Answer struct {
Task string `json:"task"`
Accept bool `json:"accept"`
// Reason says why the runner declined.
Reason string `json:"reason,omitempty"`
// Model is the model the session will use.
Model string `json:"model,omitempty"`
}
Answer accepts or declines an offer.
type AnswerResponse ¶
type AnswerResponse struct {
Session string `json:"session,omitempty"`
}
AnswerResponse names the session an accepted offer started.
type DeregisterRequest ¶
type DeregisterRequest struct {
Organization string `json:"organization"`
Runner string `json:"runner"`
}
DeregisterRequest deregisters a runner. Its host may, with their own token, and so may the runner, with its key.
type Duration ¶
Duration is a time.Duration written as a string, such as "10s".
func (Duration) MarshalJSON ¶
MarshalJSON writes the duration as a string.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON reads a duration string.
type Harness ¶
type Harness struct {
// Name is the harness, such as claude.
Name string `json:"name"`
// Subscription is the Subscription the harness is logged in to.
Subscription string `json:"subscription"`
// Provider is the subscription's provider, such as anthropic. It is
// needed when the Subscription doesn't exist yet: registering creates
// it.
Provider string `json:"provider,omitempty"`
}
Harness is an agent CLI a runner registers, logged in to a subscription.
type Message ¶
type Message struct {
Type MessageType `json:"type"`
// Runner, HeartbeatInterval and Lease are a hello's.
Runner string `json:"runner,omitempty"`
HeartbeatInterval *Duration `json:"heartbeatInterval,omitempty"`
Lease *Duration `json:"lease,omitempty"`
// Offer is an offer's.
Offer *Offer `json:"offer,omitempty"`
// Task is a cancel's or a withdraw's, and Reason a cancel's.
Task string `json:"task,omitempty"`
Reason string `json:"reason,omitempty"`
}
Message is one line of the stream.
type MessageType ¶
type MessageType string
MessageType is the kind of a stream message.
const ( // MessageHello is the first message: the runner's name, how often to // send a heartbeat for each started session, and the lease. MessageHello MessageType = "hello" // MessageOffer offers a task. Answer it within the offer-answer lease. MessageOffer MessageType = "offer" // MessageCancel cancels a started task: stop its session and report // Canceled. MessageCancel MessageType = "cancel" // MessageWithdraw withdraws an offer: the task is no longer the // runner's to answer. MessageWithdraw MessageType = "withdraw" // MessagePing keeps the stream open, every PingInterval. MessagePing MessageType = "ping" )
The stream's messages.
type Offer ¶
type Offer struct {
Task string `json:"task"`
Kind string `json:"kind"`
Class v1alpha1.TaskClass `json:"class"`
Subject string `json:"subject"`
Repo string `json:"repo,omitempty"`
Branch string `json:"branch,omitempty"`
Harness string `json:"harness"`
Subscription string `json:"subscription"`
Provider string `json:"provider"`
// Context is a reference to the task's context bundle, which the runner
// fetches once it accepted.
Context string `json:"context,omitempty"`
// Inputs are further arguments for the session, as the run passed them.
Inputs json.RawMessage `json:"inputs,omitempty"`
// Deadline is the latest time the session may start.
Deadline *time.Time `json:"deadline,omitempty"`
}
Offer is a task offered to the runner, with where to run it.
type RegisterRequest ¶
type RegisterRequest struct {
Organization string `json:"organization"`
Name string `json:"name"`
Kind v1alpha1.RunnerKind `json:"kind,omitempty"`
Slots int32 `json:"slots"`
Focus string `json:"focus,omitempty"`
Purposes []string `json:"purposes,omitempty"`
Harnesses []Harness `json:"harnesses,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
Limits v1alpha1.PressureLimits `json:"limits,omitempty"`
// Replace rotates the key of the host's runner of the same name.
// Without it, a runner of that name is a conflict.
Replace bool `json:"replace,omitempty"`
}
RegisterRequest registers a runner. The caller is a member of the organization, with their own token, and becomes the runner's host. The installation comes from Beekeeper's configuration.
type RegisterResponse ¶
RegisterResponse is a registered runner and its key. The key is shown once: Beekeeper keeps only its hash.
type SessionReport ¶
type SessionReport struct {
Task string `json:"task"`
// Phase is Running, or the outcome: Succeeded, Failed or Canceled.
Phase v1alpha1.SessionPhase `json:"phase"`
Progress v1alpha1.Progress `json:"progress,omitempty"`
Result *v1alpha1.Result `json:"result,omitempty"`
Reason string `json:"reason,omitempty"`
Transcript v1alpha1.Transcript `json:"transcript,omitempty"`
}
SessionReport is a started session's state. Every report is the session's heartbeat: the runner sends one per started session at least every heartbeat interval.
type StatusReport ¶
StatusReport is the runner's pressure, sent whenever it changes. Any request also refreshes the host token Beekeeper keeps.
type UsageReport ¶
type UsageReport struct {
Subscription string `json:"subscription"`
Weekly float64 `json:"weekly"`
ShortWindow float64 `json:"shortWindow"`
WeeklyResetsAt time.Time `json:"weeklyResetsAt"`
ShortWindowResetsAt *time.Time `json:"shortWindowResetsAt,omitempty"`
ObservedAt time.Time `json:"observedAt"`
}
UsageReport is a reading of one of the runner's harnesses' subscriptions.
type UsageResponse ¶
type UsageResponse struct {
Kept bool `json:"kept"`
}
UsageResponse says whether Beekeeper kept the reading: it ignores one older than the reading it has.