Documentation
¶
Overview ¶
Package attach holds the files a message carries: images and documents attached with @path, a pasted or dropped path, or Ctrl+V. They go to the server inline, as content parts of the message (see docsgpt.Message), and the server stores them as the conversation's attachments.
Index ¶
Constants ¶
const ( MaxFileBytes = 100 << 20 MaxTotalBytes = 100 << 20 MaxFiles = 20 )
Limits: a file at most as large as the server takes one (its default UPLOAD_MAX_FILE_BYTES), and a message at most that much in all, in a handful of files.
Variables ¶
var ErrType = errors.New("not a type the server reads (images: PNG, JPEG, WebP, GIF; documents: PDF, Office, OpenDocument, EPUB, HTML, text)")
ErrType is the error for a file the server cannot read.
Functions ¶
func Paths ¶
Paths returns the files a paste names when it is nothing but paths of existing files, as a terminal pastes the files dropped on it: absolute, shell-escaped (/Users/a/My\ Shot.png), quoted ('/a b.png', "C:\a b.png") or file:// URLs, separated by spaces or lines. Anything else gives nil.
Types ¶
type Clip ¶
Clip is what the system clipboard holds for Ctrl+V: files copied (in Finder or Explorer), else an image (saved as a PNG where Read was told), else text.
type Clipboard ¶
Clipboard reads the system clipboard, an image into a PNG at imagePath.
var System Clipboard = system{}
System is the system clipboard: osascript on macOS, wl-paste or xclip on Linux, PowerShell on Windows; its text through the usual tools.
type File ¶
type File struct {
ID int `json:"id,omitempty"` // the number of its marker
Path string `json:"path"` // absolute
Name string `json:"name"`
Image bool `json:"image,omitempty"`
Size int64 `json:"size"`
SHA256 string `json:"sha256,omitempty"` // of the bytes sent
Ref string `json:"ref,omitempty"` // the @path that attached it, as typed
Clipboard bool `json:"clipboard,omitempty"` // an image pasted from the clipboard
}
File is a file attached to a message. Sessions keep it as it is, never the bytes.
func Open ¶
Open checks that path is a file that can be attached and returns it, unread. ~ stands for the home directory.
func Parts ¶
func Parts(files []File) ([]docsgpt.ContentPart, []File, error)
Parts reads the files into content parts, in order, and returns the files with the hash of what was sent. A GIF goes as a PNG of its first frame: the server reads no GIF.
type Ref ¶
Ref is an @path in a message that names an existing file.
func Refs ¶
Refs returns the @paths of text that name existing files, relative to the working directory (~ for the home directory), once each, in order. A name in quotes may hold spaces; punctuation right after one (@notes.md, …) is not part of it. An @word naming no file is left alone, as is a directory.