attachment

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package attachment owns bounded Workspace attachment discovery and resolution.

Index

Constants

View Source
const (
	// MaxTextBytes is the largest Workspace text file accepted as prompt context.
	MaxTextBytes = 512 << 10
	// MaxPathBytes bounds Workspace-relative attachment paths and provenance.
	MaxPathBytes = 4 << 10
	// MaxEncodedImageBytes is the largest encoded image accepted at ingress.
	MaxEncodedImageBytes = 20 << 20
	// MaxImageBytes is the largest normalized inline image accepted by Coding.
	MaxImageBytes = 1 << 20
	// MaxImagePixels bounds decoded image work before a full decode is attempted.
	MaxImagePixels = 40_000_000
	// MaxImagesPerMessage bounds images in one assembled user message.
	MaxImagesPerMessage = 4
	// MaxImageBytesPerMessage bounds aggregate inline image data in one message.
	MaxImageBytesPerMessage = 2 << 20
)

Variables

View Source
var (
	// ErrDenied means a path enters private VCS metadata.
	ErrDenied = errors.New("coding attachment: path denied")
	// ErrLimit means a discovery or text-content boundary was exceeded.
	ErrLimit = errors.New("coding attachment: limit exceeded")
	// ErrBinaryText means a selected text file is not valid NUL-free UTF-8.
	ErrBinaryText = errors.New("coding attachment: binary text file")
	// ErrInvalidImage means encoded image data or metadata is malformed.
	ErrInvalidImage = errors.New("coding attachment: invalid image")
	// ErrUnsupportedImage means the encoded image format is not accepted.
	ErrUnsupportedImage = errors.New("coding attachment: unsupported image format")
)

Functions

This section is empty.

Types

type Image

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

Image is immutable normalized inline image data. Byte-returning methods detach their result so callers cannot mutate retained Composer snapshots.

func NormalizeImage

func NormalizeImage(name string, encoded []byte) (Image, error)

NormalizeImage validates and normalizes one encoded PNG, JPEG, or GIF. GIF input uses only its first frame. Valid PNG/JPEG input at or below the inline limit is preserved byte-for-byte; all other accepted input follows a fixed deterministic resize/JPEG sequence.

func NormalizeImageContext

func NormalizeImageContext(ctx context.Context, name string, encoded []byte) (Image, error)

NormalizeImageContext is NormalizeImage with cancellation checks around decode and throughout bounded resize work.

func ResolveImage

func ResolveImage(
	ctx context.Context,
	tree *workspace.Tree,
	reference Reference,
) (Image, error)

ResolveImage opens and normalizes one stable Workspace image reference.

func (Image) Bytes

func (i Image) Bytes() []byte

Bytes returns detached normalized bytes.

func (Image) Clone

func (i Image) Clone() Image

Clone returns a fully detached normalized image.

func (Image) Digest

func (i Image) Digest() [sha256.Size]byte

Digest returns the SHA-256 digest of normalized bytes.

func (Image) Equal

func (i Image) Equal(other Image) bool

Equal reports content and metadata equality.

func (Image) Height

func (i Image) Height() int

Height returns the normalized pixel height.

func (Image) MIMEType

func (i Image) MIMEType() string

MIMEType returns the normalized IANA media type.

func (Image) Name

func (i Image) Name() string

Name returns the bounded display name supplied at ingress.

func (Image) Part

func (i Image) Part() ai.ImagePart

Part returns a provider-neutral inline image part with detached bytes.

func (Image) Size

func (i Image) Size() int

Size returns the normalized encoded byte count.

func (Image) Valid

func (i Image) Valid() bool

Valid reports whether the value was produced by NormalizeImage and remains internally consistent.

func (Image) Width

func (i Image) Width() int

Width returns the normalized pixel width.

type Kind

type Kind uint8

Kind classifies a Workspace attachment without reading its content eagerly.

const (
	KindUnknown Kind = iota
	KindText
	KindImage
)

Attachment kinds.

type Reference

type Reference struct {
	Path string
	Kind Kind
}

Reference is the immutable path and kind retained by a Composer element.

func NormalizeReference

func NormalizeReference(reference Reference) (Reference, error)

NormalizeReference validates a Workspace-relative reference, denies private VCS metadata, and derives its kind from the normalized path.

type Resolved

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

Resolved is one final-handle-resolved Workspace attachment. Exactly one content accessor succeeds according to Kind.

func NewResolvedImage

func NewResolvedImage(reference Reference, image Image) (Resolved, error)

NewResolvedImage validates a normalized Workspace image result for resolver adapters and tests. Production Workspace reads are created by Resolve.

func NewResolvedText

func NewResolvedText(text Text) (Resolved, error)

NewResolvedText validates a detached text result for resolver adapters and tests. Production Workspace reads are created by Resolve.

func Resolve

func Resolve(
	ctx context.Context,
	tree *workspace.Tree,
	reference Reference,
) (Resolved, error)

Resolve opens and resolves one stable Workspace text or image reference.

func (Resolved) Image

func (r Resolved) Image() (Image, bool)

Image returns the immutable normalized image when Kind is KindImage.

func (Resolved) Kind

func (r Resolved) Kind() Kind

Kind returns the resolved content kind.

func (Resolved) Reference

func (r Resolved) Reference() Reference

Reference returns the normalized Workspace reference.

func (Resolved) Text

func (r Resolved) Text() (Text, bool)

Text returns the resolved text when Kind is KindText.

type Snapshot

type Snapshot struct {
	Files     []Summary
	Truncated bool
}

Snapshot is one bounded, detached discovery result.

func Discover

func Discover(ctx context.Context, tree *workspace.Tree) (Snapshot, error)

Discover returns bounded, path-sorted regular Workspace files without following symbolic links or reading file contents.

func DiscoverCandidates

func DiscoverCandidates(
	ctx context.Context,
	tree *workspace.Tree,
	candidates []string,
) (Snapshot, error)

DiscoverCandidates returns bounded metadata for an already filtered set of Workspace-relative file candidates without reading their contents.

func (Snapshot) Clone

func (s Snapshot) Clone() Snapshot

Clone returns a detached discovery snapshot.

type Summary

type Summary struct {
	Path string
	Kind Kind
	Size int64
}

Summary is one content-free Workspace file discovery result.

func (Summary) Reference

func (s Summary) Reference() Reference

Reference returns the immutable Composer reference for a summary.

type Text

type Text struct {
	Reference Reference
	Content   string
}

Text is one final-handle-resolved Workspace text attachment.

func ResolveText

func ResolveText(
	ctx context.Context,
	tree *workspace.Tree,
	reference Reference,
) (Text, error)

ResolveText opens and reads one stable text reference through the Workspace tree.

func (Text) PromptText

func (t Text) PromptText() string

PromptText returns a provider-neutral text part with bounded provenance.

Jump to

Keyboard shortcuts

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