attach

package
v1.10.3 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 25 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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 Expand

func Expand(path string) string

Expand replaces a leading ~ with the home directory.

func Paths

func Paths(paste string) []string

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.

func Show

func Show(text string, files []File) string

Show replaces the @path of each file attached by one (its Ref) with the file's marker: a message as shown.

func Size

func Size(n int64) string

Size renders n bytes: 512 B, 240 KB, 1.2 MB.

Types

type Clip

type Clip struct {
	Files []string
	Image bool
	Text  string
}

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

type Clipboard interface {
	Read(imagePath string) (Clip, error)
}

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

func Open(path string) (File, error)

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.

func Paste

func Paste(cb Clipboard) (files []File, text string, err error)

Paste reads cb for Ctrl+V: the files it holds or its image (saved in the temporary directory) as attachments, else its text.

func (File) Marker

func (f File) Marker() string

Marker is how the file shows in a message: [image #1 · 240 KB], [image #2 · shot.png · 240 KB] or [file #3 · spec.pdf · 1.2 MB].

type Ref

type Ref struct {
	Token string // as written: @docs/a.md, @"My Shot.png"
	Path  string // absolute
}

Ref is an @path in a message that names an existing file.

func Refs

func Refs(text string) []Ref

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.

Jump to

Keyboard shortcuts

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