Documentation
¶
Overview ¶
Package core is the devbox gateway proper (sections 4.6 to 4.6b): it serves devbox.v1.Gateway through the KAS tunnel, drives instance lifecycles on Substrate, forwards daemon events to console, proxies history reads to the box that holds the transcript, executes suspends and backstops, and resolves actors for the egress package.
Index ¶
- Variables
- func ActorName(instanceID string) string
- func AutonomyOf(l v1alpha1.DevboxAutonomyLevel) devboxv1.Autonomy
- func Registered() bool
- func SnapshotTagName(snapshotID string) string
- type Config
- type CredentialService
- type Deps
- type Egress
- type Gateway
- func (g *Gateway) AddRepository(ctx context.Context, req *devboxv1.AddRepositoryRequest) (*devboxv1.AddRepositoryResponse, error)
- func (g *Gateway) CancelInstance(ctx context.Context, req *devboxv1.InstanceActionRequest) (*devboxv1.InstanceActionResponse, error)
- func (g *Gateway) CancelPrompt(ctx context.Context, req *devboxv1.CancelPromptRequest) (*devboxv1.CancelPromptResponse, error)
- func (g *Gateway) CloseThread(ctx context.Context, req *devboxv1.ThreadActionRequest) (*devboxv1.ThreadResponse, error)
- func (g *Gateway) CountByStatus(st devboxv1.InstanceStatus) int
- func (g *Gateway) CreateInstance(ctx context.Context, req *devboxv1.CreateInstanceRequest) (*devboxv1.CreateInstanceResponse, error)
- func (g *Gateway) CreateThread(ctx context.Context, req *devboxv1.CreateThreadRequest) (*devboxv1.ThreadResponse, error)
- func (g *Gateway) DeleteSnapshot(ctx context.Context, req *devboxv1.DeleteSnapshotRequest) (*devboxv1.DeleteSnapshotResponse, error)
- func (g *Gateway) DeleteThread(ctx context.Context, req *devboxv1.ThreadActionRequest) (*devboxv1.DeleteThreadResponse, error)
- func (g *Gateway) ForkThread(ctx context.Context, req *devboxv1.ForkThreadRequest) (*devboxv1.ThreadResponse, error)
- func (g *Gateway) GetBranchDiffStat(ctx context.Context, req *devboxv1.BranchDiffStatRequest) (*devboxv1.BranchDiffStatResponse, error)
- func (g *Gateway) GetChanges(ctx context.Context, req *devboxv1.GetChangesRequest) (*devboxv1.GetChangesResponse, error)
- func (g *Gateway) GetSessions(ctx context.Context, req *devboxv1.GetSessionsRequest) (*devboxv1.GetSessionsResponse, error)
- func (g *Gateway) GetTimeline(ctx context.Context, req *devboxv1.GetTimelineRequest) (*devboxv1.GetTimelineResponse, error)
- func (g *Gateway) ImportThread(ctx context.Context, req *devboxv1.ImportThreadRequest) (*devboxv1.ThreadResponse, error)
- func (g *Gateway) InvalidateAllowlist(ctx context.Context, req *devboxv1.InvalidateAllowlistRequest) (*devboxv1.InvalidateAllowlistResponse, error)
- func (g *Gateway) ListCommands(ctx context.Context, req *devboxv1.ListCommandsRequest) (*devboxv1.ListCommandsResponse, error)
- func (g *Gateway) ListFiles(ctx context.Context, req *devboxv1.ListFilesRequest) (*devboxv1.ListFilesResponse, error)
- func (g *Gateway) ListRepositories(ctx context.Context, req *devboxv1.ListRepositoriesRequest) (*devboxv1.ListRepositoriesResponse, error)
- func (g *Gateway) ListThreads(ctx context.Context, req *devboxv1.ListThreadsRequest) (*devboxv1.ListThreadsResponse, error)
- func (g *Gateway) OpenStream(ctx context.Context, req *devboxv1.OpenStreamRequest) (*devboxv1.OpenStreamResponse, error)
- func (g *Gateway) PreparePullRequest(ctx context.Context, req *devboxv1.PreparePullRequestRequest) (*devboxv1.PreparePullRequestResponse, error)
- func (g *Gateway) Prompt(ctx context.Context, req *devboxv1.PromptRequest) (*devboxv1.PromptResponse, error)
- func (g *Gateway) ProxyStream(stream devboxv1.Gateway_ProxyStreamServer) error
- func (g *Gateway) ReadFile(ctx context.Context, req *devboxv1.ReadFileRequest) (*devboxv1.ReadFileResponse, error)
- func (g *Gateway) Register(s grpc.ServiceRegistrar)
- func (g *Gateway) RegisterSandboxCredentials(s grpc.ServiceRegistrar)
- func (g *Gateway) ResolveActor(ctx context.Context, actorID string) (*egress.InstanceInfo, error)
- func (g *Gateway) RespondInteraction(ctx context.Context, req *devboxv1.RespondInteractionRequest) (*devboxv1.RespondInteractionResponse, error)
- func (g *Gateway) ResumeInstance(ctx context.Context, req *devboxv1.InstanceActionRequest) (*devboxv1.InstanceActionResponse, error)
- func (g *Gateway) ResumeThread(ctx context.Context, req *devboxv1.ResumeThreadRequest) (*devboxv1.ThreadResponse, error)
- func (g *Gateway) Run(ctx context.Context) error
- func (g *Gateway) SetAgentBilling(ctx context.Context, req *devboxv1.SetAgentBillingRequest) (*devboxv1.SetAgentBillingResponse, error)
- func (g *Gateway) SetInstanceLeases(ctx context.Context, req *devboxv1.SetInstanceLeasesRequest) (*devboxv1.SetInstanceLeasesResponse, error)
- func (g *Gateway) SetThreadConfigOption(ctx context.Context, req *devboxv1.SetThreadConfigOptionRequest) (*devboxv1.SetThreadConfigOptionResponse, error)
- func (g *Gateway) Shutdown()
- func (g *Gateway) SnapshotInstance(_ context.Context, req *devboxv1.SnapshotInstanceRequest) (*devboxv1.SnapshotInstanceResponse, error)
- func (g *Gateway) StartFromSnapshot(ctx context.Context, req *devboxv1.StartFromSnapshotRequest) (*devboxv1.CreateInstanceResponse, error)
- func (g *Gateway) SuspendInstance(ctx context.Context, req *devboxv1.InstanceActionRequest) (*devboxv1.InstanceActionResponse, error)
- func (g *Gateway) UpdateQueuedPrompt(ctx context.Context, req *devboxv1.UpdateQueuedPromptRequest) (*devboxv1.UpdateQueuedPromptResponse, error)
- func (g *Gateway) UseEgress(e Egress, c CredentialService)
- func (g *Gateway) WriteFile(ctx context.Context, req *devboxv1.WriteFileRequest) (*devboxv1.WriteFileResponse, error)
- type Instance
- type KubeRecords
- type KubeRunners
- type MemoryRecords
- type Record
- type Records
- type Router
- type Runner
- type RunnerRevision
- type Runners
- type StaticRunners
Constants ¶
This section is empty.
Variables ¶
var Capabilities = []string{"acp-v2", "claude-oauth", "egress-pr-observation", "snapshots"}
Capabilities are reported on registration.
var ErrRunnerNotReady = errors.New("devbox runner has no ready revision")
ErrRunnerNotReady means the runner has no ready revision to start instances from.
Functions ¶
func ActorName ¶
ActorName is the Substrate actor name of an instance: a DNS label derived from the instance ID.
func AutonomyOf ¶
func AutonomyOf(l v1alpha1.DevboxAutonomyLevel) devboxv1.Autonomy
AutonomyOf converts a CRD autonomy level.
func Registered ¶
func Registered() bool
Registered reports whether this process has registered with console at least once since it started.
func SnapshotTagName ¶
SnapshotTagName is the Substrate tag of a snapshot.
Types ¶
type Config ¶
type Config struct {
GatewayID string
Version string
SubstrateVersion string
// ClusterID is the console cluster, used until RegisterGateway reports it.
ClusterID string
// CredentialProviderRegistered and EgressAuthzRegistered are reported on registration.
CredentialProviderRegistered bool
EgressAuthzRegistered bool
// Harness endpoints handed to daemons in Initialize.
ConsoleURL string
AIProxyURL string
// WorkbenchMCPURL is the base of console's workbench MCP; each instance gets <base>/<workbench-id>.
WorkbenchMCPURL string
// GatewayURL is where sandboxes reach the gateway's devbox MCP (GatewayURL + /mcp) and SandboxCredentials
// (GatewayURL), through egress which injects the actor JWT.
GatewayURL string
// RequestTokenJWKS is passed to daemons to validate devbox-request-token. Empty disables validation.
RequestTokenJWKS []byte
HeartbeatInterval time.Duration
ReadyTimeout time.Duration
PrepareTimeout time.Duration
DrainTimeout time.Duration
SnapshotTimeout time.Duration
FlushInterval time.Duration
MaxBatch int
DeltaInterval time.Duration
MaxDeltaBatch int
BackstopInterval time.Duration
EvictionInterval time.Duration
UnresponsiveAfter time.Duration
StreamTokenTTL time.Duration
RegistrationBackoff time.Duration
}
Config tunes the core. Zero values take the defaults below.
type CredentialService ¶
type CredentialService interface {
VerifyActorJWT(ctx context.Context, raw string) (*egress.Caller, error)
InstanceCredential(ctx context.Context, instanceID string, sel *devboxv1.CredentialSelector) (*devboxv1.InstanceCredential, error)
}
CredentialService verifies sandbox callers and serves cached OIDC credentials (egress.Service).
type Deps ¶
type Deps struct {
Ingest devboxv1.IngestClient
Actors *actors.Client
Router Router
Records Records
Runners Runners
// Egress is optional; when set, instance changes invalidate its caches.
Egress Egress
// Credentials is optional; SandboxCredentials needs it.
Credentials CredentialService
Log logr.Logger
Now func() time.Time
}
Deps are the core's collaborators.
type Egress ¶
type Egress interface {
Invalidate(instanceID string)
}
Egress is what the core needs from the egress package.
type Gateway ¶
type Gateway struct {
devboxv1.UnimplementedGatewayServer
// contains filtered or unexported fields
}
Gateway is the core.
func (*Gateway) AddRepository ¶
func (g *Gateway) AddRepository(ctx context.Context, req *devboxv1.AddRepositoryRequest) (*devboxv1.AddRepositoryResponse, error)
func (*Gateway) CancelInstance ¶
func (g *Gateway) CancelInstance(ctx context.Context, req *devboxv1.InstanceActionRequest) (*devboxv1.InstanceActionResponse, error)
func (*Gateway) CancelPrompt ¶
func (g *Gateway) CancelPrompt(ctx context.Context, req *devboxv1.CancelPromptRequest) (*devboxv1.CancelPromptResponse, error)
func (*Gateway) CloseThread ¶
func (g *Gateway) CloseThread(ctx context.Context, req *devboxv1.ThreadActionRequest) (*devboxv1.ThreadResponse, error)
func (*Gateway) CountByStatus ¶
func (g *Gateway) CountByStatus(st devboxv1.InstanceStatus) int
CountByStatus counts managed instances in a status (metrics).
func (*Gateway) CreateInstance ¶
func (g *Gateway) CreateInstance(ctx context.Context, req *devboxv1.CreateInstanceRequest) (*devboxv1.CreateInstanceResponse, error)
func (*Gateway) CreateThread ¶
func (g *Gateway) CreateThread(ctx context.Context, req *devboxv1.CreateThreadRequest) (*devboxv1.ThreadResponse, error)
func (*Gateway) DeleteSnapshot ¶
func (g *Gateway) DeleteSnapshot(ctx context.Context, req *devboxv1.DeleteSnapshotRequest) (*devboxv1.DeleteSnapshotResponse, error)
func (*Gateway) DeleteThread ¶
func (g *Gateway) DeleteThread(ctx context.Context, req *devboxv1.ThreadActionRequest) (*devboxv1.DeleteThreadResponse, error)
func (*Gateway) ForkThread ¶
func (g *Gateway) ForkThread(ctx context.Context, req *devboxv1.ForkThreadRequest) (*devboxv1.ThreadResponse, error)
func (*Gateway) GetBranchDiffStat ¶
func (g *Gateway) GetBranchDiffStat(ctx context.Context, req *devboxv1.BranchDiffStatRequest) (*devboxv1.BranchDiffStatResponse, error)
func (*Gateway) GetChanges ¶
func (g *Gateway) GetChanges(ctx context.Context, req *devboxv1.GetChangesRequest) (*devboxv1.GetChangesResponse, error)
func (*Gateway) GetSessions ¶
func (g *Gateway) GetSessions(ctx context.Context, req *devboxv1.GetSessionsRequest) (*devboxv1.GetSessionsResponse, error)
func (*Gateway) GetTimeline ¶
func (g *Gateway) GetTimeline(ctx context.Context, req *devboxv1.GetTimelineRequest) (*devboxv1.GetTimelineResponse, error)
func (*Gateway) ImportThread ¶
func (g *Gateway) ImportThread(ctx context.Context, req *devboxv1.ImportThreadRequest) (*devboxv1.ThreadResponse, error)
func (*Gateway) InvalidateAllowlist ¶
func (g *Gateway) InvalidateAllowlist(ctx context.Context, req *devboxv1.InvalidateAllowlistRequest) (*devboxv1.InvalidateAllowlistResponse, error)
func (*Gateway) ListCommands ¶
func (g *Gateway) ListCommands(ctx context.Context, req *devboxv1.ListCommandsRequest) (*devboxv1.ListCommandsResponse, error)
func (*Gateway) ListFiles ¶
func (g *Gateway) ListFiles(ctx context.Context, req *devboxv1.ListFilesRequest) (*devboxv1.ListFilesResponse, error)
func (*Gateway) ListRepositories ¶
func (g *Gateway) ListRepositories(ctx context.Context, req *devboxv1.ListRepositoriesRequest) (*devboxv1.ListRepositoriesResponse, error)
func (*Gateway) ListThreads ¶
func (g *Gateway) ListThreads(ctx context.Context, req *devboxv1.ListThreadsRequest) (*devboxv1.ListThreadsResponse, error)
func (*Gateway) OpenStream ¶
func (g *Gateway) OpenStream(ctx context.Context, req *devboxv1.OpenStreamRequest) (*devboxv1.OpenStreamResponse, error)
OpenStream prepares a terminal, VNC or preview target and registers it under a fresh stream ID (DBX-33).
func (*Gateway) PreparePullRequest ¶
func (g *Gateway) PreparePullRequest(ctx context.Context, req *devboxv1.PreparePullRequestRequest) (*devboxv1.PreparePullRequestResponse, error)
func (*Gateway) Prompt ¶
func (g *Gateway) Prompt(ctx context.Context, req *devboxv1.PromptRequest) (*devboxv1.PromptResponse, error)
func (*Gateway) ProxyStream ¶
func (g *Gateway) ProxyStream(stream devboxv1.Gateway_ProxyStreamServer) error
ProxyStream carries one browser WebSocket (or preview HTTP request) to the daemon through atenet-router, as HTTP-over-gRPC: header, data*, trailer, then upgrade data both ways after a 101.
func (*Gateway) ReadFile ¶
func (g *Gateway) ReadFile(ctx context.Context, req *devboxv1.ReadFileRequest) (*devboxv1.ReadFileResponse, error)
func (*Gateway) Register ¶
func (g *Gateway) Register(s grpc.ServiceRegistrar)
Register adds the Gateway service to a gRPC server (the tunnel's in-process server).
func (*Gateway) RegisterSandboxCredentials ¶
func (g *Gateway) RegisterSandboxCredentials(s grpc.ServiceRegistrar)
RegisterSandboxCredentials adds SandboxCredentials to a server.
func (*Gateway) ResolveActor ¶
ResolveActor implements egress.ActorResolver: it maps "<atespace>/<actor>" to the instance's egress view.
func (*Gateway) RespondInteraction ¶
func (g *Gateway) RespondInteraction(ctx context.Context, req *devboxv1.RespondInteractionRequest) (*devboxv1.RespondInteractionResponse, error)
func (*Gateway) ResumeInstance ¶
func (g *Gateway) ResumeInstance(ctx context.Context, req *devboxv1.InstanceActionRequest) (*devboxv1.InstanceActionResponse, error)
func (*Gateway) ResumeThread ¶
func (g *Gateway) ResumeThread(ctx context.Context, req *devboxv1.ResumeThreadRequest) (*devboxv1.ThreadResponse, error)
func (*Gateway) Run ¶
Run runs registration, heartbeats, backstops and eviction polling until ctx is done, then stops event forwarders and waits for background operations.
func (*Gateway) SetAgentBilling ¶
func (g *Gateway) SetAgentBilling(ctx context.Context, req *devboxv1.SetAgentBillingRequest) (*devboxv1.SetAgentBillingResponse, error)
func (*Gateway) SetInstanceLeases ¶
func (g *Gateway) SetInstanceLeases(ctx context.Context, req *devboxv1.SetInstanceLeasesRequest) (*devboxv1.SetInstanceLeasesResponse, error)
func (*Gateway) SetThreadConfigOption ¶
func (g *Gateway) SetThreadConfigOption(ctx context.Context, req *devboxv1.SetThreadConfigOptionRequest) (*devboxv1.SetThreadConfigOptionResponse, error)
func (*Gateway) Shutdown ¶
func (g *Gateway) Shutdown()
Shutdown stops forwarders and background operations. Instances keep running on Substrate.
func (*Gateway) SnapshotInstance ¶
func (g *Gateway) SnapshotInstance(_ context.Context, req *devboxv1.SnapshotInstanceRequest) (*devboxv1.SnapshotInstanceResponse, error)
func (*Gateway) StartFromSnapshot ¶
func (g *Gateway) StartFromSnapshot(ctx context.Context, req *devboxv1.StartFromSnapshotRequest) (*devboxv1.CreateInstanceResponse, error)
func (*Gateway) SuspendInstance ¶
func (g *Gateway) SuspendInstance(ctx context.Context, req *devboxv1.InstanceActionRequest) (*devboxv1.InstanceActionResponse, error)
func (*Gateway) UpdateQueuedPrompt ¶
func (g *Gateway) UpdateQueuedPrompt(ctx context.Context, req *devboxv1.UpdateQueuedPromptRequest) (*devboxv1.UpdateQueuedPromptResponse, error)
func (*Gateway) UseEgress ¶
func (g *Gateway) UseEgress(e Egress, c CredentialService)
UseEgress wires the egress service, which itself needs the Gateway as its actor resolver. Call it before Run.
func (*Gateway) WriteFile ¶
func (g *Gateway) WriteFile(ctx context.Context, req *devboxv1.WriteFileRequest) (*devboxv1.WriteFileResponse, error)
type Instance ¶
type Instance struct {
ID string
// contains filtered or unexported fields
}
Instance is one devbox instance managed by this gateway.
type KubeRecords ¶
KubeRecords keeps one ConfigMap per instance in the gateway's namespace. Records hold no credentials.
type KubeRunners ¶
type KubeRunners struct {
Client client.Reader
// Namespace holds v1alpha1.DevboxRunnerEnvSecret; empty disables secret env.
Namespace string
TTL time.Duration
// contains filtered or unexported fields
}
KubeRunners reads DevboxRunners (cluster-scoped) with a short cache.
func (*KubeRunners) Invalidate ¶
func (k *KubeRunners) Invalidate(name string)
Invalidate drops a cached runner.
type MemoryRecords ¶
type MemoryRecords struct {
// contains filtered or unexported fields
}
MemoryRecords keeps records in memory (tests and local development).
type Record ¶
type Record struct {
InstanceID string `json:"instanceId"`
DevboxID string `json:"devboxId"`
WorkbenchID string `json:"workbenchId,omitempty"`
OwnerID string `json:"ownerId,omitempty"`
Runner string `json:"runner"`
Atespace string `json:"atespace"`
Actor string `json:"actor"`
Template string `json:"template,omitempty"`
TemplateRevision int64 `json:"templateRevision,omitempty"`
ImageDigest string `json:"imageDigest,omitempty"`
Status string `json:"status"`
SuspendReason string `json:"suspendReason,omitempty"`
Message string `json:"message,omitempty"`
RestoredFrom string `json:"restoredFrom,omitempty"`
RestoreFidelity string `json:"restoreFidelity,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
SuspendedAt time.Time `json:"suspendedAt,omitempty"`
// Request is the protojson CreateInstanceRequest, kept current with allowlist and billing changes.
Request json.RawMessage `json:"request"`
}
Record is the durable state of an instance (see Records), so a restarted gateway can reconcile with console's RegisterGateway summaries.
type Records ¶
type Records interface {
Put(ctx context.Context, rec *Record) error
Get(ctx context.Context, id string) (*Record, error)
List(ctx context.Context) ([]*Record, error)
Delete(ctx context.Context, id string) error
}
Records persists instance records so a restarted gateway can reconcile with console's RegisterGateway summaries. Get returns nil, nil for an unknown instance.
type Router ¶
type Router interface {
Daemon(actor string) devboxv1.DaemonClient
NewRequest(ctx context.Context, actor, method, pathAndQuery string) (*http.Request, error)
RoundTrip(req *http.Request) (*http.Response, error)
}
Router reaches daemons through atenet-router (see package router).
type Runner ¶
type Runner struct {
Name string
Atespace string
// Template, Revision and GoldenTag describe the revision new instances start from.
Template string
Revision int64
GoldenTag string
ImageDigest string
// Revisions maps every revision that still exists to its template and golden tag.
Revisions map[int64]RunnerRevision
AllowedRepositories []string
HTTPAllowlist []egress.AllowEntry
CloudIdentities []*devboxv1.CloudIdentity
CloudIdentityHosts []string
IdlePolicy *devboxv1.IdlePolicy
Autonomy *devboxv1.AutonomyPolicy
// Env is the runner's resolved secret env vars, sent with every Initialize.
Env map[string]string
}
Runner is what the gateway needs from a DevboxRunner.
func RunnerFromCRD ¶
func RunnerFromCRD(obj *v1alpha1.DevboxRunner) *Runner
RunnerFromCRD converts a DevboxRunner.