media

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 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

Overview

Package media implements content-addressed storage, magic-byte format detection, per-modality size limits, and lightweight message-block descriptors for multimodal inputs (images, PDFs, and audio).

Index

Constants

View Source
const (
	MaxImageBytes  int64 = 20 << 20 // 20 MiB
	MaxPDFBytes    int64 = 32 << 20 // 32 MiB
	MaxAudioBytes  int64 = 25 << 20 // 25 MiB
	MaxUploadBytes       = MaxPDFBytes
)

Per-modality payload size caps enforced at ingestion time.

View Source
const (
	ExtraSHA256      = api.MediaExtraSHA256
	ExtraByteSize    = api.MediaExtraByteSize
	ExtraDisplayName = api.MediaExtraDisplayName
	ExtraPages       = api.MediaExtraPages
)

Extras keys persisted inside loom media block Extras maps so checkpoints and timelines never store raw binary or base64 payloads.

Variables

View Source
var (
	ErrTooLarge        = errors.New("media: file exceeds maximum allowed size")
	ErrUnsupportedType = errors.New("media: unsupported media type")
	ErrInvalidPages    = errors.New("media: invalid PDF page range")
)

Functions

func BlockFromDescriptor

func BlockFromDescriptor(desc api.Media) (message.Block, error)

BlockFromDescriptor constructs a lightweight loom media block carrying only descriptor metadata in Extras (never raw binary or base64 bytes).

func CanonicalMIME

func CanonicalMIME(mime string) string

CanonicalMIME normalizes equivalent MIME spellings (such as audio/wave -> audio/wav).

func CheckSize

func CheckSize(mod Modality, size int64) error

CheckSize enforces the per-modality byte-size cap.

func FormatViewSummary

func FormatViewSummary(path, mime string, size int64, pages string) string

FormatViewSummary builds the compact metadata text returned for a viewed media file.

func MaxBytesForModality

func MaxBytesForModality(mod Modality) int64

MaxBytesForModality returns the byte-size cap for mod.

func OmittedPlaceholder

func OmittedPlaceholder(mod Modality, desc api.Media) string

OmittedPlaceholder formats the fallback text placeholder used when historical media is unsupported by the current model.

func ParsePages

func ParsePages(raw string) (string, error)

ParsePages validates and normalizes an optional PDF page range specification such as "1-10", "3", or "1-3, 5, 8-10". An empty input returns "", nil.

func UnavailablePlaceholder

func UnavailablePlaceholder(mod Modality, desc api.Media) string

UnavailablePlaceholder formats the fallback text placeholder used when persisted media bytes are missing or unreadable in the session media store.

Types

type Info

type Info struct {
	Modality Modality
	MIMEType string
}

Info describes a detected multimodal file.

func Detect

func Detect(filename string, data []byte) (Info, bool)

Detect inspects filename and header bytes (magic bytes + extension) to identify supported image, PDF, and audio files. SVG files deliberately return false so they remain on the UTF-8 text path for reading and editing.

type Modality

type Modality string

Modality identifies a multimodal input kind matching loom profile modalities.

const (
	ModalityImage Modality = Modality(profile.ModalityImage)
	ModalityPDF   Modality = Modality(profile.ModalityPDF)
	ModalityAudio Modality = Modality(profile.ModalityAudio)
)

func DescriptorFromBlock

func DescriptorFromBlock(b message.Block) (api.Media, Modality, bool)

DescriptorFromBlock extracts a media descriptor and modality from a loom block. It returns ok=true for any ImageBlock, AudioBlock, or PDF DocumentBlock.

func ModalityForMIME

func ModalityForMIME(mime string) (Modality, bool)

ModalityForMIME maps a supported MIME type to its modality.

func ModalityOfBlock

func ModalityOfBlock(b message.Block) (Modality, bool)

ModalityOfBlock returns the input modality represented by block, or "" if text/non-media.

type Store

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

Store manages immutable, content-addressed media blobs under <session-dir>/media/<sha256>.

func NewStore

func NewStore(dir string) (*Store, error)

NewStore returns a Store rooted at dir (typically <session-dir>/media).

func (*Store) Dir

func (s *Store) Dir() string

Dir returns the backing directory path on disk.

func (*Store) Exists

func (s *Store) Exists(sha256Hex string) bool

Exists reports whether sha256Hex is present in the store.

func (*Store) LinkAllFrom

func (s *Store) LinkAllFrom(srcDir string) error

LinkAllFrom hardlinks all content-addressed media blobs from srcDir into s.dir in O(1), falling back to copying if the source and destination reside on different filesystems. Missing srcDir is a no-op.

func (*Store) Put

func (s *Store) Put(ctx context.Context, data []byte) (string, int64, error)

Put writes data into <dir>/<sha256> atomically if not already present, returning the lowercase hex SHA-256 digest and byte size.

func (*Store) Read

func (s *Store) Read(sha256Hex string) ([]byte, error)

Read retrieves the bytes stored for sha256Hex.

Jump to

Keyboard shortcuts

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