controlplane

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 14 Imported by: 1 module, 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 controlplane implements the runtime-facing Speko control-plane contract. It only performs setup and recovery-boundary calls; it is never a dependency of the audio or text hot path.

Index

Constants

View Source
const InstanceProtocolHeader = "Speko-Instance-Protocol"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client obtains signed session plans and exchanges fallback plans at explicit recovery boundaries.

func New

func New(config Config) (*Client, error)

New constructs a control-plane client.

func (*Client) CreateSessionPlan

func (c *Client) CreateSessionPlan(ctx context.Context, request protocol.SessionPlanRequest, options CreateOptions) (protocol.SessionPlan, string, error)

CreateSessionPlan calls POST /v1/session-plans and returns the exact signed plan issued by the control plane. Verification remains a separate mandatory runtime step so callers cannot accidentally trust HTTP transport alone.

func (*Client) CreateSessionPlanBatch

func (c *Client) CreateSessionPlanBatch(ctx context.Context, request protocol.SessionPlanRequest, count int, options CreateOptions) ([]protocol.SessionPlan, string, error)

CreateSessionPlanBatch calls POST /v1/session-plan-batches and returns several independently signed plans.

It exists so a gateway can keep plans warm ahead of demand. The latency a caller actually feels is between their first audio frame and the provider socket opening, and a plan fetched at that moment puts a full control-plane round trip inside it. Fetching plans in advance moves that round trip off the path entirely, and fetching them one at a time would only relocate it.

func (*Client) DeregisterInstance

func (c *Client) DeregisterInstance(ctx context.Context, instanceID string) error

DeregisterInstance marks one authenticated runtime instance offline without deleting its historical identity from the customer dashboard.

func (*Client) DeregisterInstanceV2

func (c *Client) DeregisterInstanceV2(ctx context.Context, instanceID string, lifetime InstanceLifetimeV2) error

DeregisterInstanceV2 closes only the specified lifetime. A timeout is retried with this exact body; successful DELETE is terminal for that incarnation.

func (*Client) DeregisterInstanceV3

func (c *Client) DeregisterInstanceV3(ctx context.Context, instanceID string, h InstanceLifetimeV2) error

func (*Client) EntitlementClock added in v0.3.1

func (c *Client) EntitlementClock(ctx context.Context, plan protocol.SessionPlan) (time.Time, error)

EntitlementClock samples the cell's SQL clock without reserving or minting. Callers account for the full round trip before using this sample.

func (*Client) ExchangeFallbackPlan

func (c *Client) ExchangeFallbackPlan(ctx context.Context, current protocol.SessionPlan, request FallbackRequest, idempotencyKey string) (protocol.SessionPlan, string, error)

ExchangeFallbackPlan obtains a newly signed plan only at a known recovery boundary. The exchange URL is itself signed inside the current plan and is therefore used verbatim after validation by the caller.

func (*Client) RefreshCredential

RefreshCredential obtains a freshly minted provider credential for the plan's own attempt: same route, same reservation, no new attempt or plan. It exists for managed providers whose credential is single-use per connection (ElevenLabs text-to-dialogue), so an adapter that must redial mid-session can authenticate the new socket. The control plane caps it per attempt.

func (*Client) RenewEntitlement added in v0.3.1

func (c *Client) RenewEntitlement(ctx context.Context, plan protocol.SessionPlan, request EntitlementRenewalRequest, idempotencyKey string) (EntitlementRenewal, string, error)

RenewEntitlement funds and mints the next Google realtime slice. The caller must first verify the signed plan. Its plan token authenticates this call; the setup API key is never substituted. A retry must keep both the request and key unchanged. Admission timing is decided by the cell's clock.

func (*Client) ReportInstance

func (c *Client) ReportInstance(ctx context.Context, instanceID string, heartbeat InstanceHeartbeat) error

ReportInstance upserts one authenticated runtime instance heartbeat.

func (*Client) ReportInstanceV2

func (c *Client) ReportInstanceV2(ctx context.Context, instanceID string, heartbeat InstanceHeartbeatV2) error

ReportInstanceV2 requires explicit server acknowledgement. It never falls back to an unversioned report, which could undo a lifetime fence.

func (*Client) ReportInstanceV3

func (c *Client) ReportInstanceV3(ctx context.Context, instanceID string, h InstanceHeartbeatV3) error

type Config

type Config struct {
	BaseURL           string
	APIKey            string
	HTTPClient        *http.Client
	UserAgent         string
	AllowInsecureHTTP bool
}

Config configures an authenticated control-plane client. The Speko API key authenticates setup calls and is never sent to an upstream model provider.

type CreateOptions

type CreateOptions struct {
	IdempotencyKey string
}

CreateOptions provides per-request metadata. IdempotencyKey is required so timeout retries cannot reserve two concurrent sessions.

type CredentialRefreshRequest

type CredentialRefreshRequest struct {
	Reason string `json:"reason"`
}

CredentialRefreshRequest asks the control plane to re-credential a live attempt. Reason is audit metadata only.

type EntitlementRenewal added in v0.3.1

type EntitlementRenewal struct {
	EntitlementID       string                       `json:"entitlement_id"`
	SessionID           string                       `json:"session_id"`
	AttemptID           string                       `json:"attempt_id"`
	ReservationID       string                       `json:"reservation_id"`
	Sequence            int64                        `json:"sequence"`
	PreviousExpiresAt   time.Time                    `json:"previous_expires_at"`
	LeaseExpiresAt      time.Time                    `json:"lease_expires_at"`
	AuthorizedUnits     int64                        `json:"authorized_units"`
	MaximumAmountMicros int64                        `json:"maximum_amount_micros"`
	Currency            string                       `json:"currency"`
	Credential          protocol.DelegatedCredential `json:"credential"`
}

EntitlementRenewal is one newly funded slice, using the original price. MaximumAmountMicros describes this slice, not a cumulative charge. Only the cell computes money. Obtaining it alone does not extend a running session: its credential must be adopted before advancing the runtime's lease.

func (EntitlementRenewal) Validate added in v0.3.1

func (r EntitlementRenewal) Validate(plan protocol.SessionPlan, previous time.Time) error

Validate checks a continuation against the original verified plan. It does not verify a plan or grant authority to open a different attempt.

type EntitlementRenewalRequest added in v0.3.1

type EntitlementRenewalRequest struct {
	PreviousExpiresAt time.Time `json:"previous_expires_at"`
}

EntitlementRenewalRequest identifies the last funded horizon. Preserve it and the idempotency key when retrying a request whose acknowledgment was lost.

type FallbackRequest

type FallbackRequest struct {
	AttemptID      string `json:"attempt_id"`
	Reason         string `json:"reason"`
	ProviderCode   string `json:"provider_code,omitempty"`
	ProviderStatus int    `json:"provider_status,omitempty"`
}

FallbackRequest explains a recovery-boundary exchange without sending raw media, transcripts, or provider credential values to the control plane.

type HTTPError

type HTTPError struct {
	Status    int
	RequestID string
	Code      string
	Message   string
}

HTTPError is returned for non-2xx responses. RequestID allows live canaries and support tooling to correlate the control-plane decision without logging bearer credentials or response bodies. Code carries the control plane's own machine-readable refusal (`no_eligible_route`, `credit_exhausted`, …): a caller who pinned a provider the control plane cannot serve needs to see THAT, not a generic plan failure that reads like an outage.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type InstanceHeartbeat

type InstanceHeartbeat struct {
	// Local snapshot is serialized only by the explicit v3 envelope.
	Capacity         *protocol.CapacitySnapshot `json:"-"`
	RuntimeName      string                     `json:"runtime_name"`
	RuntimeVersion   string                     `json:"runtime_version"`
	WorkloadType     string                     `json:"workload_type,omitempty"`
	WorkloadID       string                     `json:"workload_id,omitempty"`
	StartedAt        time.Time                  `json:"started_at"`
	ActiveSessions   int64                      `json:"active_sessions"`
	PendingSessions  int                        `json:"pending_sessions"`
	SessionCapacity  int                        `json:"session_capacity"`
	SessionsTotal    uint64                     `json:"sessions_total"`
	TelemetryDropped uint64                     `json:"telemetry_dropped"`
	Draining         bool                       `json:"draining"`
	Labels           map[string]string          `json:"labels,omitempty"`
}

InstanceHeartbeat is the content-free process state exposed in the customer dashboard. Workload identity is optional because one gateway may serve framework-neutral sessions or several workloads.

type InstanceHeartbeatV2

type InstanceHeartbeatV2 struct {
	InstanceHeartbeat
	IncarnationID string `json:"incarnation_id"`
	Sequence      uint32 `json:"sequence"`
}

InstanceHeartbeatV2 opts into lifetime fencing, not capacity attribution. Callers serialize mutations and retain the same sequence/body on retries.

type InstanceHeartbeatV3

type InstanceHeartbeatV3 struct {
	InstanceHeartbeatV2
	Capacity protocol.CapacitySnapshot `json:"capacity"`
}

InstanceLifetimeV2 identifies one process for a terminal DELETE. Reserve a sequence for shutdown and never wrap it under one incarnation.

type InstanceLifetimeV2

type InstanceLifetimeV2 struct {
	IncarnationID string    `json:"incarnation_id"`
	StartedAt     time.Time `json:"started_at"`
	Sequence      uint32    `json:"sequence"`
}

Jump to

Keyboard shortcuts

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