fileutil

package
v0.140.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FileTokenPattern = regexp.MustCompile(`@"[^"]+"|@[^\s]+`)

FileTokenPattern matches @file references in user text. Supports:

  • @"path with spaces.txt" (quoted)
  • @path/to/file.txt (unquoted, no spaces)

It is shared with the renderer that highlights these tokens, so what is highlighted is always exactly what gets attached.

Functions

This section is empty.

Types

type FileAttachmentResult added in v0.51.0

type FileAttachmentResult struct {
	// ProcessedText is the user's text with @file tokens replaced:
	// text files become XML-wrapped content, binary file tokens are removed.
	ProcessedText string
	// FileParts contains binary file attachments extracted from @file
	// references. Empty when all referenced files are text.
	FileParts []FilePart
}

FileAttachmentResult is the result of processing @file references in user input. Text files are inlined as XML in ProcessedText; binary files (images, audio, video, PDFs) are returned as FileParts for multimodal submission.

func ProcessFileAttachments

func ProcessFileAttachments(text string, cwd string, mcpReader ...MCPResourceReader) FileAttachmentResult

ProcessFileAttachments scans the user's input text for @file references, reads each referenced file, and returns a result containing the processed text and any binary file attachments. Text files are XML-wrapped inline; binary files (images, audio, etc.) are extracted as FileParts for multimodal submission. Non-file @ tokens (like email addresses) are left unchanged.

MCP resources are supported via @mcp:server:uri tokens. The optional mcpReader callback is used to resolve them; pass nil to skip MCP resources.

type FilePart added in v0.51.0

type FilePart struct {
	// Filename is the basename of the file (e.g. "photo.png").
	Filename string
	// Data is the raw file bytes.
	Data []byte
	// MediaType is the MIME type (e.g. "image/png", "audio/wav").
	MediaType string
}

FilePart represents a binary file attachment (image, audio, etc.) extracted from an @file reference. Callers convert this to kit.LLMFilePart before sending to the LLM. Defined here to avoid a circular dependency on pkg/kit.

type MCPResourceReader added in v0.51.0

type MCPResourceReader func(serverName, uri string) (text string, blobData []byte, mimeType string, isBlob bool, err error)

MCPResourceReader is a callback function that reads an MCP resource by server name and URI. Returns text content, binary data, MIME type, and error. Used by ProcessFileAttachments to resolve @mcp:server:uri tokens.

Jump to

Keyboard shortcuts

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