attachhttp

package
v1.111.0 Latest Latest
Warning

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

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

Documentation

Overview

Package attachhttp exposes prompt resource attachments (#1013) over REST for both operator surfaces: the portal (a prompt author manages the materials on their own prompts) and the admin API (any prompt). It lives beside pkg/prompt rather than inside pkg/portal or pkg/admin so those packages stay within the package-size budget; the composition root 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.

The scope rule is enforced here at attach time, not only at serve time. The serve-time check protects the reader; this one protects the author, who would otherwise learn that a shared SOP has unreachable materials only from someone else's failed run.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttachmentView

type AttachmentView struct {
	ResourceID  string `json:"resource_id"`
	Position    int    `json:"position"`
	AttachedBy  string `json:"attached_by,omitempty"`
	DisplayName string `json:"display_name,omitempty"`
	Description string `json:"description,omitempty"`
	Category    string `json:"category,omitempty"`
	MIMEType    string `json:"mime_type,omitempty"`
	SizeBytes   int64  `json:"size_bytes,omitempty"`
	URI         string `json:"uri,omitempty"`
	Scope       string `json:"scope,omitempty"`
	ScopeID     string `json:"scope_id,omitempty"`

	// Broken marks an attachment whose resource was deleted. The row stays in
	// the list so an author can see and remove the dangling link; without it a
	// deleted template would simply vanish from the editor while the served
	// prompt kept reporting a missing material.
	Broken bool `json:"broken,omitempty"`

	// Unreadable marks an attachment that exists but that this caller cannot
	// read. It carries the position (so the row renders in place) and nothing
	// else about the resource or its attacher, for the same reason the serving
	// path withholds them.
	Unreadable bool `json:"unreadable,omitempty"`
}

AttachmentView is one attachment as the portal renders it: the link plus enough of the resource to show a row, and a broken flag when the resource behind the link no longer exists.

type Deps

type Deps struct {
	Store       prompt.Store
	Attachments prompt.AttachmentStore
	Resources   resource.Store

	// Caller resolves the authenticated caller's permission claims, or nil when
	// the request carries no user. Injected per surface by the composition root.
	Caller func(r *http.Request) *Identity
}

Deps carries the collaborators the attachment handlers need. Every field except Caller is required; a nil Store, Attachments, or Resources leaves the routes unmounted rather than serving a half-working surface.

type Handler

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

Handler serves the prompt attachment routes.

func New

func New(deps Deps) *Handler

New builds the handler. It returns nil when a required collaborator is missing, so the composition root can skip mounting without a second check.

func (*Handler) Register

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

Register mounts the attachment routes under prefix, each wrapped in the surface's auth middleware. Both surfaces expose the same routes; they differ only in the identity the injected accessor resolves, which is what decides whether the caller may edit the prompt.

type Identity

type Identity = resource.Claims

Identity is the authenticated caller resolved by the injected accessor. It is the resource package's own claims type rather than a local shape, so the read rule applied here is byte-for-byte the one the resources REST surface applies, including the caller's full persona membership.

Jump to

Keyboard shortcuts

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