media

package
v0.3.22 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const ContentTypeAttachmentRef = "attachment_ref"

ContentTypeAttachmentRef is persisted in session history for stripped attachments.

View Source
const DefaultMaxVisionEdgePixels = 2048

DefaultMaxVisionEdgePixels limits the longest image edge when FitForVision is enabled.

View Source
const DefaultMaxVisionPayloadBytes = 1 << 20

DefaultMaxVisionPayloadBytes is used when FitForVision is enabled (optional).

View Source
const DefaultMaxWorkspaceImageBytes = 10 << 20

DefaultMaxWorkspaceImageBytes caps raw image bytes sent to vision models.

View Source
const DefaultMaxWorkspaceImageReadBytes = 10 << 20

DefaultMaxWorkspaceImageReadBytes is the largest workspace image file tools and hydrate may load.

Variables

This section is empty.

Functions

func DataURL

func DataURL(mime string, data []byte) string

DataURL builds a data URL for vision models.

func DetectMIME

func DetectMIME(path string, data []byte) string

DetectMIME guesses image MIME type from path and magic bytes.

func EnsureInboundFileName added in v0.3.22

func EnsureInboundFileName(name, mime string, data []byte) string

EnsureInboundFileName adds a standard image extension when MIME or content indicates an image.

func ExtensionForMIME added in v0.3.22

func ExtensionForMIME(mime string) string

ExtensionForMIME maps an image MIME type to a file extension including the dot.

func FitForVision added in v0.3.22

func FitForVision(data []byte, mime string, opt VisionFitOptions) ([]byte, string, error)

FitForVision downscales and re-encodes images that exceed vision limits. When the input is already within limits, it is returned unchanged. If decoding fails but the payload is within MaxBytes, the original bytes are returned.

func FormatReadImageResult

func FormatReadImageResult(path, mime string, size int64) string

FormatReadImageResult is the read-tool metadata format hydrated before LLM calls.

func FormatReadImageTooLarge

func FormatReadImageTooLarge(path string, size, max int64) string

FormatReadImageTooLarge explains why a workspace image cannot be viewed.

func IsImage

func IsImage(mimeType, path string) bool

IsImage reports whether a file looks like an image from MIME type and/or path.

func IsImageMIME

func IsImageMIME(mime string) bool

IsImageMIME reports whether a MIME type is an image.

func IsImagePath

func IsImagePath(path string) bool

IsImagePath reports whether a workspace-relative path looks like an image file.

func LoadWorkspaceImage

func LoadWorkspaceImage(ctx context.Context, ws workspace.Service, workRel string, maxBytes int) ([]byte, string, error)

LoadWorkspaceImage reads an image from the tenant work tree for vision models. workRel is relative to work/ (e.g. upload/foo.png or work/upload/foo.png).

func LooksLikeImageData added in v0.3.22

func LooksLikeImageData(data []byte) bool

LooksLikeImageData reports whether bytes begin with a known image signature.

func NormalizeWorkRel

func NormalizeWorkRel(rel string) string

NormalizeWorkRel strips leading slashes and an optional work/ prefix.

func ParseReadImagePath

func ParseReadImagePath(content string) string

ParseReadImagePath extracts a workspace image path from a read-tool result.

func ReadFileHead added in v0.3.22

func ReadFileHead(path string, n int) ([]byte, error)

ReadFileHead reads up to n bytes from a file for content sniffing.

func WorkspaceFileMayBeImage added in v0.3.22

func WorkspaceFileMayBeImage(ctx context.Context, ws workspace.Service, workRel string) (bool, error)

WorkspaceFileMayBeImage reports whether a work-relative path should be hydrated as vision.

Types

type VisionFitOptions added in v0.3.22

type VisionFitOptions struct {
	MaxBytes int
	MaxEdge  int
}

VisionFitOptions controls downscaling and re-encoding for LLM vision input.

func DefaultVisionFitOptions added in v0.3.22

func DefaultVisionFitOptions() VisionFitOptions

DefaultVisionFitOptions returns the standard vision payload limits.

Jump to

Keyboard shortcuts

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