media

package
v0.3.26 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 17 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 AgentDisplayPath added in v0.3.23

func AgentDisplayPath(ws cw.Service, path string) string

AgentDisplayPath is AgentLLMPath without request context; prefer AgentLLMPath when ctx carries tenant workspace.

func AgentLLMPath added in v0.3.23

func AgentLLMPath(ctx context.Context, ws cw.Service, path string) string

AgentLLMPath formats a path for model-facing text and session storage. local:/global: appear only in configuration. Paths under the agent work directory are relative to that directory (e.g. upload/foo, same as shell cwd and fs root); global and out-of-work files use absolute paths.

func CanonicalStoredPath added in v0.3.23

func CanonicalStoredPath(ws cw.Service, rel string) string

CanonicalStoredPath normalizes attachment paths for session JSONL (no local:/global: prefixes).

func CanonicalWorkPath added in v0.3.23

func CanonicalWorkPath(ws cw.Service, rel string) string

CanonicalWorkPath returns the agent-facing path under the configured work layout.

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 or re-encoding fails, the original bytes are returned unchanged.

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, maxPayloadBytes int) ([]byte, string, error)

LoadWorkspaceImage reads a workspace image and tries FitForVision before LLM vision input. When fitting fails, the original file bytes are returned (up to DefaultMaxWorkspaceImageReadBytes). workRel is relative to work/ (e.g. upload/foo.png or work/upload/foo.png). maxPayloadBytes caps the returned payload after fitting; 0 uses DefaultMaxVisionPayloadBytes. Files larger than DefaultMaxWorkspaceImageReadBytes are skipped (empty result).

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(ws cw.Service, rel string) string

NormalizeWorkRel strips the configured work-dir prefix from a tenant-local relative path.

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 RewritePathsInText added in v0.3.23

func RewritePathsInText(ctx context.Context, ws cw.Service, text string) string

RewritePathsInText replaces scoped workspace path tokens in free text for LLM history.

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