scripthttp

package
v1.128.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package scripthttp exposes managed scripts over the admin REST API — the script list, a script's version history, one version with what its code reaches for, schedules, and the run history — and the portal's own script routes.

It lives beside the other version seam (internal/httpserver/versionhttp) rather than inside pkg/admin so that package stays within its size budget; the composition root mounts it under the admin path prefix wrapped in the admin authentication middleware and injects the identity accessor, so this package never imports the admin surface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditRecorder added in v1.123.0

type AuditRecorder interface {
	Log(ctx context.Context, event audit.Event) error
}

AuditRecorder writes one audit event. It is the write half of audit.Logger: this surface records administrative writes and never reads the log back, and a narrower dependency is one less thing a deployment has to supply to mount these routes.

type ConnectionChoice added in v1.122.0

type ConnectionChoice struct {
	Name string `json:"name" example:"warehouse"`
	// Kind is the toolkit serving it.
	Kind        string `json:"kind,omitempty" example:"trino"`
	Description string `json:"description,omitempty" example:"Production Trino cluster"`
}

ConnectionChoice is one connection a parameter may name: the value bound into a run, and what a person needs to pick it by.

type ConnectionEnumerator added in v1.122.0

type ConnectionEnumerator func(ctx context.Context, caller ConnectionScope) []ConnectionChoice

ConnectionEnumerator lists the connections one caller may reach, in the deployment's terms. It is the composition root's, because resolving it means walking the live toolkit registry through the persona boundary and this package holds neither.

Nil leaves the choices route unmounted: a deployment that cannot enumerate its connections should serve no set at all rather than an empty one, which a form would render as "this script may reach nothing".

type ConnectionScope added in v1.122.0

type ConnectionScope struct {
	// Persona is the caller's resolved persona, whose connections rules decide
	// what they may reach. An unresolved persona reaches nothing, which is the
	// same fail-closed default the authorizer applies to a tool call.
	Persona string
	// Unrestricted lifts the persona boundary for an administrator, whose reach
	// over this surface is unrestricted by design.
	Unrestricted bool
}

ConnectionScope is the caller a connection enumeration is narrowed to.

type ContractReader

type ContractReader interface {
	Contract(ctx context.Context, id string) (*script.Contract, error)
}

ContractReader composes one script's contract document: the record, its parameter contract, the cadence, and the last successful run. It is the same document a reference to a script resolves to (#1302), so the portal page and an agent's fetch describe a script identically.

type Deps

type Deps struct {
	Scripts  script.Store
	Versions script.VersionStore
	// Schedules is the cadence store. Nil leaves the schedule routes unmounted,
	// which is the honest shape for a deployment that cannot keep a schedule.
	Schedules script.ScheduleStore

	// Runs is the run history. Nil leaves the portal run routes unmounted: a
	// deployment that keeps no runs has no history to show.
	Runs script.RunStore
	// Contracts composes one script's contract document for the portal detail
	// route. Nil leaves that route unmounted.
	Contracts ContractReader
	// LatestRuns reports each script's most recent run for the portal listing.
	// Nil leaves the listing's last-run column empty rather than unmounting it.
	LatestRuns LatestRunReader

	// States holds each script's one object of state (#1537): what a run
	// reads as run.state and saves with platform.save_state. Nil leaves the
	// state routes unmounted and a draft reading {}, which is the shape of a
	// deployment that keeps no state.
	States script.StateStore

	// DryRuns records and resolves the accounts of draft executions (#1364).
	// Nil runs drafts without keeping an account of them, which leaves every
	// version reading as one nobody dry-ran — the state before the account
	// existed — rather than failing the run.
	DryRuns script.DryRunStore

	// Drafts executes a draft under the calling person's own identity. Nil
	// leaves the dry-run route unmounted; validate needs nothing but the
	// source and stays either way.
	Drafts DraftRunner

	// Destinations is the deployment's declared bucket destination set, which
	// validate and dry-run check a source's named destinations against so an
	// undeclared one is reported before the script's queries run (#1415).
	// Empty means the portal is the only place a script may write, which is
	// what the runtime already reports.
	Destinations []script.Destination

	// Connections enumerates the connections the portal caller's own persona
	// reaches, which a connection-typed parameter is chosen from (#1361). Nil
	// leaves the choices route unmounted.
	Connections ConnectionEnumerator

	// Audit records administrative script writes — today the owner transfer
	// (#1404). Nil leaves the transfer working and unrecorded, which is what a
	// deployment with no audit store has for every other write too.
	Audit AuditRecorder

	// AdminEmail returns the authenticated administrator's email, recorded as
	// the author of an admin-made edit.
	AdminEmail func(r *http.Request) string
	// PortalUser resolves the authenticated portal caller, or nil when the
	// request carries no user. Nil leaves the portal routes unmounted, which is
	// what the admin surface passes.
	PortalUser func(r *http.Request) *PortalIdentity

	// Produced lists everything a script has written across every run (#1569).
	// Nil leaves that route unmounted, which is the shape of a deployment that
	// records no producers.
	Produced ProducedReader
}

Deps carries the collaborators the handlers need. Every store except Schedules is required; a deployment without them does not mount these routes.

type DraftRunner added in v1.122.0

type DraftRunner interface {
	Run(ctx context.Context, req scriptdraft.Request) (*scriptdraft.Outcome, error)
}

DraftRunner executes a draft under the calling person's own identity. The composition root supplies it, because building one needs the assembled MCP server. Nil leaves the dry-run route unmounted; validate stays, since parsing needs nothing but the source.

type Handler

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

Handler serves the script routes.

func New

func New(deps Deps) *Handler

New builds the handler.

func (*Handler) RegisterAdmin

func (h *Handler) RegisterAdmin(mux *http.ServeMux, prefix string, wrap func(http.Handler) http.Handler)

RegisterAdmin mounts the admin script routes under prefix, each wrapped in the admin authentication middleware.

func (*Handler) RegisterPortal

func (h *Handler) RegisterPortal(mux *http.ServeMux, wrap func(http.Handler) http.Handler)

RegisterPortal mounts the portal read routes, wrapped in the portal authentication middleware. Every handler goes through portalHandler, which resolves the caller and answers 401 once for all of them.

The run routes are mounted only where the deployment keeps runs, the detail route only where a contract can be composed, and the schedule routes only where the deployment keeps schedules; a deployment missing any of them serves the rest rather than failing per request.

type LatestRunReader

type LatestRunReader interface {
	LatestRuns(ctx context.Context, scriptIDs []string) (map[string]script.Run, error)
}

LatestRunReader returns the most recent run of each named script, keyed by script id and omitting the scripts that have never run. It is a listing capability rather than a history one: the alternative is one query per row.

type PortalIdentity

type PortalIdentity struct {
	UserID  string
	Email   string
	Persona string
	IsAdmin bool
	// Roles is the authority this caller holds. It is recorded on any version
	// they author (#1307): a run of that version presents exactly these roles,
	// which is what keeps a script from holding more access than the person
	// who wrote it.
	Roles []string
	// AuthType is HOW this caller was authenticated. It matters because the
	// dry-run route opens a session on their behalf (#1364): that session must
	// present the authentication the request actually arrived with rather than
	// a kind no authenticator issues.
	AuthType string
}

PortalIdentity is the portal caller, resolved by the accessor the composition root injects. IsAdmin carries the administrator's unrestricted reach into this surface: an admin sees every script and every run, which is the same authority the admin API already gives them.

type ProducedReader added in v1.127.0

type ProducedReader interface {
	Produced(ctx context.Context, scriptID string, limit int) ([]producedview.Item, error)
}

ProducedReader lists what one script has produced, most recently written first, resolving each file to its current name. limit is the cap on rows, non-positive selecting the reader's own default.

Jump to

Keyboard shortcuts

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