Documentation
¶
Overview ¶
Package imageinput is the single shared loader for local image files used by every input surface (CLI exec --image, TUI /image). It reads a file, sniffs + normalizes its media type against the allow-list, enforces the per-image size cap, and returns a raw-bytes ImageBlock. Keeping it here means the CLI and TUI never duplicate the read/sniff/normalize/cap logic.
Index ¶
Constants ¶
const MaxDocumentBytes = 32 << 20
MaxDocumentBytes is the per-document raw-file cap (32 MiB). PDFs are routinely larger than the image cap, but we still bound the file before it is read into memory or handed to a parser so an unbounded file never reaches a provider.
const MaxDocumentTextBytes = 256 << 10
MaxDocumentTextBytes caps the EXTRACTED text we hand to a model (256 KiB). Unlike the raw-file cap (which rejects), an over-cap text layer is truncated with documentTruncatedMarker so a large-but-valid spec is still partially usable instead of refused outright.
const MaxImageBytes = 10 << 20
MaxImageBytes is the per-image decoded-size cap (10 MiB). Bytes above this are rejected at every input boundary so an unbounded request body never reaches a provider.
Variables ¶
This section is empty.
Functions ¶
func IsProbablyDocumentPath ¶
IsProbablyDocumentPath reports whether a path looks like a document ZERO can ingest (currently: a ".pdf" extension, case-insensitive). It is only a routing hint for input surfaces deciding whether to call LoadDocument vs LoadFile; LoadDocument re-verifies the real content via magic bytes.
func LoadFile ¶
func LoadFile(path string, workspaceRoot string) (zeroruntime.ImageBlock, error)
LoadFile reads the image at path (resolved against workspaceRoot when relative), validates its type and size, and returns a raw-bytes ImageBlock. Errors are plain (callers wrap them into surface-specific usage/notice text).
func LooksLikeDocumentFile ¶
LooksLikeDocumentFile reports whether the file at path is a PDF by content, reading only its leading magic bytes. It lets input surfaces route a real PDF to LoadDocument even when its name lacks a ".pdf" extension, so detection is content-based rather than extension-only. It opens nothing it cannot stat as a regular file and never reads more than the magic prefix; any I/O error (missing file, permission, non-regular) simply reports false and lets the normal path surface a precise error. Relative paths resolve against workspaceRoot.
func ReadClipboardImage ¶
ReadClipboardImage returns the raw image bytes and media type from the OS clipboard, or (nil, "", nil) when the clipboard has no image. Called when text clipboard is empty (the user pasted a screenshot). The media type is sniffed from the bytes, not trusted from the clipboard.
Types ¶
type Document ¶
type Document struct {
Text string
Images []zeroruntime.ImageBlock
Pages int
Truncated bool
}
Document is the result of ingesting a PDF: the extracted text layer (always populated when a text layer exists) plus, on the optional vision path, one ImageBlock per rendered page. Pages is the page count the parser reported; Truncated is set when Text was capped at MaxDocumentTextBytes.
func LoadDocument ¶
func LoadDocument(path string, workspaceRoot string, opts DocumentOptions) (Document, error)
LoadDocument reads the PDF at path (resolved against workspaceRoot when relative), enforces the per-document size cap, and extracts its text layer. With opts.Vision and an available rasterizer it also renders the first N pages to ImageBlocks. The file is identified by magic bytes, not its extension, so a ".pdf"-named non-PDF is rejected with a clear error. A PDF with no text layer and no rasterization/OCR available returns an explicit "no extractable text" error rather than a silent empty success. Errors are plain (callers wrap them into surface-specific notice text).
type DocumentOptions ¶
type DocumentOptions struct {
// Vision asks for page rasterization (ImageBlocks) in addition to text, for a
// vision-capable model. It is best-effort: when no rasterizer is available the
// load degrades to the text layer rather than erroring.
Vision bool
// MaxPages bounds how many pages the vision path renders. Zero means
// defaultMaxRasterPages.
MaxPages int
// contains filtered or unexported fields
}
DocumentOptions tunes how a PDF is ingested.