attachments

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package attachments stores prompt attachments in a cwd-local sandbox and builds ACP resource blocks that point at the stored files.

Defensive helpers for attachment storage paths the production caller cannot realistically trigger. Excluded from coverage via the `_must.go` suffix rule in .covignore.

Index

Constants

View Source
const (
	// DefaultDirName is the attachment directory created inside a session cwd.
	DefaultDirName = ".acp-attachments"
	// DefaultMaxBytes caps a single downloaded or written attachment.
	DefaultMaxBytes int64 = 25 << 20 // 25 MiB
)

Variables

This section is empty.

Functions

func FileResourceLinkBlock

func FileResourceLinkBlock(name, absPath, contentType string) acp.ContentBlock

FileResourceLinkBlock builds a ResourceLink for absPath using a properly escaped file:// URI.

func ResourceLinkBlock

func ResourceLinkBlock(name, uri, contentType string) acp.ContentBlock

ResourceLinkBlock builds an ACP ResourceLink block and sets MimeType when known.

func TextResourceBlock

func TextResourceBlock(uri, text, mimeType string) acp.ContentBlock

TextResourceBlock builds an embedded text Resource block for agents that advertise embedded context support.

func URLResourceLinkBlock

func URLResourceLinkBlock(a Attachment) acp.ContentBlock

URLResourceLinkBlock builds a ResourceLink for an original remote attachment URL.

Types

type Attachment

type Attachment struct {
	URL         string
	Name        string
	ContentType string
}

Attachment is the transport-neutral attachment metadata the store needs.

type File

type File struct {
	Name        string
	Path        string
	URI         string
	ContentType string
	Size        int64
}

File describes one attachment stored on disk.

func (File) ResourceLinkBlock

func (f File) ResourceLinkBlock() acp.ContentBlock

ResourceLinkBlock returns a file:// ResourceLink block for f.

type Store

type Store struct {
	// DirName is created inside the ACP session cwd. Empty => DefaultDirName.
	DirName string
	// MaxBytes caps one attachment. <=0 => DefaultMaxBytes.
	MaxBytes int64
	// Client is used by Download. nil => http.DefaultClient.
	Client *http.Client
}

Store owns the on-disk layout and byte limits for attachments.

func (Store) Download

func (s Store) Download(ctx context.Context, cwd, msgID string, used map[string]struct{}, a Attachment) (File, error)

Download fetches a.URL and writes it under <cwd>/<DirName>/<msgID>/<name>. Names are opened through os.Root, so hostile names cannot escape the message directory. used tracks per-prompt filename collisions; nil is accepted.

func (Store) Write

func (s Store) Write(cwd, msgID string, used map[string]struct{}, a Attachment, r io.Reader) (File, error)

Write copies r into <cwd>/<DirName>/<msgID>/<name>. It returns the final file path and file:// resource URI. The copy is capped by Store.MaxBytes.

Jump to

Keyboard shortcuts

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