versionhttp

package
v1.109.0 Latest Latest
Warning

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

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

Documentation

Overview

Package versionhttp exposes prompt version history, draft review actions, audit-derived usage stats (#1009), and prompt collection management (#1010) over REST. It serves both operator surfaces — the admin API (any prompt, approve/reject) and the portal API (visible prompts, read-only history plus usage for the caller's visible set, collection CRUD and assignment) — from one implementation. It lives beside pkg/prompt rather than inside pkg/admin or pkg/portal so those packages stay within the package-size budget; the composition root (internal/httpserver) mounts it under each surface's path prefix wrapped in that surface's own authentication middleware, and injects the identity accessors, so this package never imports either surface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	Store       prompt.Store
	Versions    prompt.VersionStore
	Usage       prompt.UsageReader
	Registrar   Registrar
	Collections prompt.CollectionStore

	// AdminEmail returns the authenticated admin's email for approval stamps.
	AdminEmail func(r *http.Request) string
	// PortalUser resolves the authenticated portal caller, or nil when the
	// request carries no user.
	PortalUser func(r *http.Request) *PortalIdentity
	// SharedPromptIDs returns the ids of prompts shared person-to-person with
	// the caller, so their usage is as visible as the prompts themselves.
	// Optional: nil when the deployment has no portal share store.
	SharedPromptIDs func(ctx context.Context, userID, email string) ([]string, error)
}

Deps carries the collaborators the version handlers need. Store and Versions are required; Usage is optional (audit disabled leaves usage empty); Registrar is optional; Collections is optional (nil skips the collection routes). AdminEmail and PortalUser are the surface identity accessors injected by the composition root — each Register* call requires its accessor.

type Handler

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

Handler serves the prompt version and usage 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 version routes under prefix (the admin API path prefix, e.g. /api/v1/admin), each wrapped in the admin auth middleware. The composition root registers these on the top-level mux, where their literal patterns take precedence over the admin subtree mount.

func (*Handler) RegisterPortal

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

RegisterPortal mounts the portal version routes, wrapped in the portal auth middleware. Every portal handler goes through portalHandler, which resolves the caller identity and 401s unauthenticated requests in one place.

type PortalIdentity

type PortalIdentity struct {
	UserID  string
	Email   string
	Persona string
	IsAdmin bool
}

PortalIdentity is the portal caller resolved by the injected accessor.

type Registrar

type Registrar interface {
	RegisterRuntimePrompt(p *prompt.Prompt)
	UnregisterRuntimePrompt(name string)
}

Registrar refreshes a prompt's name-keyed runtime metadata after an approved version changes the live row. The prompt layer satisfies it.

Jump to

Keyboard shortcuts

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