inject

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package inject implements the HTTP endpoint that receives edge-trigger payloads (from k8s-event-watcher and any other source speaking the envelope.InjectPayload shape) and dispatches them into the mast runtime.

For the v0.1 spike this endpoint is single-session and single-bearer. Multi-session substrate and the X-Asserted-Caller proxy-identity mechanism from core-agent's recipe are deferred.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AbortHandler

type AbortHandler func(ctx context.Context, req AbortRequest) error

AbortHandler applies an abort request. Optional; when nil the /abort route responds 404.

type AbortRequest

type AbortRequest struct {
	// SessionID identifies the session to mark aborted.
	SessionID string `json:"session_id"`

	// Reason is the operator-supplied reason, recorded in the abort
	// marker and surfaced by `mast sessions list/show`.
	Reason string `json:"reason,omitempty"`
}

AbortRequest asks the daemon to mark a session aborted.

Semantics are those of pkg/transcript's Store.Abort — a durable operator-abort marker appended to the session's event log, not preemption of in-flight work. See that method's doc for the full contract (docs/durable-execution-design.md, "Operator-facing surface"; engine-level terminal abort is v0.2).

type Config

type Config struct {
	// Listen is the bind address, e.g. ":7777".
	Listen string

	// BearerToken is the shared secret required in the Authorization
	// header. Empty disables auth (intended only for local development;
	// production deploys must set it).
	BearerToken string

	// Handler is called for each valid inject. Required.
	Handler Handler

	// ResumeHandler is called for each valid resume POST. Optional.
	ResumeHandler ResumeHandler

	// AbortHandler is called for each valid abort POST. Optional.
	AbortHandler AbortHandler

	// Logger is the structured logger. Defaults to slog.Default().
	Logger *slog.Logger

	// Metrics, when non-nil, is served at GET /metrics (Prometheus
	// scrape). Unauthenticated by design — scrape configs don't carry
	// the inject bearer token, and the payload is aggregate counters
	// only. Nil leaves the route unregistered.
	Metrics http.Handler
}

Config configures the inject server.

type Handler

type Handler func(ctx context.Context, payload envelope.InjectPayload) error

Handler receives a validated inject payload and drives the mast runtime. It returns an error if dispatch fails; the server maps that to a 5xx response.

type ResumeHandler

type ResumeHandler func(ctx context.Context, req ResumeRequest) error

ResumeHandler feeds a resume payload into the runtime. Optional; when nil the /resume route responds 404.

type ResumeRequest

type ResumeRequest struct {
	// SessionID identifies the paused session (e.g. "incident-<uid>").
	SessionID string `json:"session_id"`

	// InterruptID matches the pending RequestInput's InterruptID.
	InterruptID string `json:"interrupt_id"`

	// Response is the reply payload; validated against the interrupt's
	// ResponseSchema by the workflow engine on resume.
	Response any `json:"response"`
}

ResumeRequest is the operator's answer to a pending HITL interrupt.

type Server

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

Server is the HTTP inject endpoint.

func New

func New(cfg Config) (*Server, error)

New constructs a Server. It does not start listening; call ListenAndServe.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe blocks serving requests. Returns http.ErrServerClosed on graceful shutdown.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown attempts a graceful stop.

Jump to

Keyboard shortcuts

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