agent

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 9 Imported by: 2 modules, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MediaHandler

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

MediaHandler exposes the Bearer-authenticated agent media endpoints. It reuses the existing MediaService (which already validates files, hashes, dedups, converts to WebP, and builds thumbnail variants) — it never duplicates that logic.

func NewMediaHandler

func NewMediaHandler(s MediaService, logger kernel.Logger, opts ...MediaHandlerOption) *MediaHandler

NewMediaHandler constructs a MediaHandler backed by the given media service. A nil logger degrades to a discard sink so the handler is safe to construct in any context (mirrors NewContentHandler).

func (*MediaHandler) Delete

func (h *MediaHandler) Delete(w http.ResponseWriter, r *http.Request)

Delete handles DELETE /api/v1/media/{id}. It mirrors the browser admin's delete: the caller's role must manage media, then the domain deletes (owner-or-admin — a non-owner gets 403, a ghost id 404). Success answers 204 with no body.

func (*MediaHandler) Get

Get handles GET /api/v1/media/{id}. It returns the media in the envelope, or 404 NOT_FOUND when it does not exist OR the caller is not allowed to see it (ownership scoping: only the owner or an Admin may read a given item — existence is never disclosed, consistent with the content visibility model).

func (*MediaHandler) List

func (h *MediaHandler) List(w http.ResponseWriter, r *http.Request)

List handles GET /api/v1/media. It returns the caller's own media in newest-first order using opaque keyset (cursor) pagination — the SAME contract as the content list. It reuses the agent package's cursor helpers and the response package's SuccessList/ Pagination/ListMeta types (introduced for this reuse in Story 2.2).

func (*MediaHandler) Reencode added in v1.1.3

func (h *MediaHandler) Reencode(w http.ResponseWriter, r *http.Request)

Reencode handles POST /api/v1/media/reencode. It is Admin-only and never automatic: the operator triggers it once after the alpha-quality rollout to rewrite every stored original and variant in place at identical dimensions. A non-admin caller gets 403 (401 when unauthenticated) and nothing is rewritten. Success returns {processed, skipped, bytesBefore, bytesAfter}.

func (*MediaHandler) Upload

func (h *MediaHandler) Upload(w http.ResponseWriter, r *http.Request)

Upload handles POST /api/v1/media. It parses a required `file` part and an optional JSON `metadata` part (carrying altText) from multipart/form-data, maps them onto a mediadomain.UploadRequest, and delegates to the existing MediaService.Upload. A missing `file` part returns 400 VALIDATION_ERROR; the service's own validation (mime/size/alt text) and dedup flow through handleMediaError.

type MediaHandlerOption

type MediaHandlerOption func(*MediaHandler)

MediaHandlerOption configures a MediaHandler. A role service makes the upload capability config-driven; without one every authenticated user may upload (the legacy behavior).

func WithMediaRoleService

func WithMediaRoleService(rs RoleCapabilities) MediaHandlerOption

WithMediaRoleService attaches the config-driven role registry so uploads are gated by the caller's CanMedia capability.

type MediaMetadata

type MediaMetadata struct {
	AltText string `json:"altText,omitempty"`
}

MediaMetadata is the optional JSON `metadata` part of a media upload. altText is the only field today; it is REQUIRED by the media service (ValidateAltText) for accessibility, so agents should always send it.

type MediaProjection

type MediaProjection struct {
	ID               int                                 `json:"id"`
	Filename         string                              `json:"filename"`
	OriginalFilename string                              `json:"originalFilename"`
	MimeType         mediadomain.MimeType                `json:"mimeType"`
	FileSize         int64                               `json:"fileSize"`
	Width            int                                 `json:"width"`
	Height           int                                 `json:"height"`
	AltText          string                              `json:"altText"`
	IsWebP           bool                                `json:"isWebp"`
	Hash             string                              `json:"hash"`
	URL              string                              `json:"url"`
	Variants         map[string]mediadomain.MediaVariant `json:"variants,omitempty"`
	CreatedAt        time.Time                           `json:"createdAt"`
	UpdatedAt        time.Time                           `json:"updatedAt"`
}

MediaProjection is the public, whitelisted view of a media item returned by the agent media endpoints. It deliberately excludes internal/admin-only fields the raw mediadomain.Media carries (the numeric owner id, filePath, uploadedBy) so the programmatic API surface does not over-disclose — mirroring ContentProjection.

type MediaResponse

type MediaResponse struct {
	Media MediaProjection `json:"media"`
}

MediaResponse wraps a projected media item for the agent media responses. Envelope body: {"data":{"media":{...}}}.

func NewMediaResponse

func NewMediaResponse(m *mediadomain.Media) MediaResponse

NewMediaResponse builds a MediaResponse projecting the given media entity to its public fields. A nil entity yields an empty projection (defensive — the service contract returns a non-nil media on success).

type MediaService

type MediaService interface {
	Upload(ctx context.Context, req mediadomain.UploadRequest) (*mediadomain.Media, error)
	GetByID(ctx context.Context, id int) (*mediadomain.Media, error)
	ListByCursor(ctx context.Context, userID int, limit int, beforeID int) ([]*mediadomain.Media, error)
	Delete(ctx context.Context, id int, principal kernel.Principal) error
	ReencodeLibrary(ctx context.Context) (mediadomain.ReencodeSummary, error)
}

MediaService is the narrow slice of the media domain service the agent handlers depend on. *mediadomain.Service satisfies it. It is exported so mockery can generate an exported constructor callable from the package's *_test files (CLAUDE.md mandates *_test packages, which cannot reach an unexported mock).

type RoleCapabilities

type RoleCapabilities interface {
	CanMedia(name string) bool
}

RoleCapabilities is the narrow role-registry seam this handler depends on. Core satisfies it with an adapter over *role.Service (which cannot be imported here); the users module implements it natively when it lands.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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