Documentation
¶
Overview ¶
Package attachments reads repository files selected on an integration component and prepares them for upload to a provider Files API (Anthropic, OpenAI). It is a shared helper for integrations rather than an integration itself: the user picks files from the canvas repository, and the backend reads the raw bytes, detects the MIME type, and enforces size/type limits. This mirrors the repo-file + Files-API pattern used by claude.runAgent.
Index ¶
Constants ¶
const ( // MaxFileSize is the per-file cap when reading an attachment from the repo. // The provider Files APIs accept far larger uploads (hundreds of MB), but // attachments are buffered fully in memory here, so the caps bound memory // use and request size rather than what the providers allow. MaxFileSize = 25 * 1024 * 1024 // 25 MB // MaxTotalSize caps the combined size of all attachments on one execution. MaxTotalSize = 50 * 1024 * 1024 // 50 MB // MaxFiles caps how many files one execution may attach; each attachment // costs a separate Files API upload call. MaxFiles = 20 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
type Attachment struct {
Name string // normalized repo path
Mime string // detected MIME type (e.g. image/png, application/pdf, text/plain)
Data []byte // raw file bytes
}
Attachment is a repository file read and classified, ready to upload.
func Read ¶
func Read(files core.RepositoryFilesContext, paths []string) ([]Attachment, error)
Read loads the given repository file paths via the execution's file context, detecting MIME type and enforcing size and type limits. It returns nil when no paths are given. Supported types are images, PDF, and text.
func (Attachment) IsImage ¶
func (a Attachment) IsImage() bool
IsImage reports whether the attachment is an image type.
func (Attachment) IsPDF ¶
func (a Attachment) IsPDF() bool
IsPDF reports whether the attachment is a PDF.
func (Attachment) UploadMIME ¶
func (a Attachment) UploadMIME() string
UploadMIME returns the MIME type to send when uploading to the Files API. Images and PDFs keep their detected type; every other (text) type is normalized to text/plain, since a document content block accepts only PDF and plaintext (Anthropic rejects e.g. text/markdown) and any text file is just plaintext to the model anyway.