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 one bearer, `Authorization: Bearer <token>`: its host's own OIDC ID token, or its projected ServiceAccount token for Beekeeper's audience. It names itself in RunnerHeader. 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 ( // ReasonTokenInvalid is a bearer that doesn't verify, or isn't a // person's or a ServiceAccount's. ReasonTokenInvalid = "token_invalid" // ReasonTokenExpired is a person's token past its expiry. ReasonTokenExpired = "token_expired" // #nosec G101 -- a reason, not a credential. // ReasonNotRegistered is a runner that isn't registered, or isn't bound // to the ServiceAccount that calls. ReasonNotRegistered = "not_registered" // ReasonRunnerMismatch is a credential that isn't the named runner's: // another person's token, or another ServiceAccount. ReasonRunnerMismatch = "runner_mismatch" )
The reasons of a 403 about a runner's credential or registration. A runner waits and tries again after the first three: a new token or a registration ends them.
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 RunnerHeader = "Beekeeper-Runner"
RunnerHeader names the runner a request is for, as `<organization>/<name>`, on every endpoint but PathRegister and PathDeregister, whose bodies name it.
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 itself.
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 the task's bundle reference. Host references use the runner's resolver.
Context string `json:"context,omitempty"`
// Bundle is the JSON assembled by the coordinator for a bk1. context.
Bundle json.RawMessage `json:"bundle,omitempty"`
// Inputs are further arguments for the session, as the workflow 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"`
// ServiceAccount binds a cluster runner to the ServiceAccount, in the
// organization's namespace, it authenticates as. Only with kind cluster.
ServiceAccount string `json:"serviceAccount,omitempty"`
}
RegisterRequest registers a runner, or updates the registered one. A member of the organization, with their own token, creates or updates their runner and becomes its host. A cluster runner's ServiceAccount updates only the offer of the runner bound to it: slots, focus, purposes, harnesses, capabilities and limits. The installation comes from Beekeeper's configuration.
type RegisterResponse ¶
RegisterResponse is the registered runner, and whether registering created it.
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 of a runner that authenticates as its host 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.