attachment

package
v1.58.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package attachment provides MIME-aware routing for document attachments.

It defines how a chat.Document should be sent to a model: either dropped (unsupported), wrapped in a plain-text envelope (StrategyTXT), or encoded as inline base64 data (StrategyB64).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TXTEnvelope

func TXTEnvelope(name, mimeType, body string) string

TXTEnvelope wraps text content in a unique XML-like tag derived from the document name and MIME type. The tag name is a slug of both, making accidental tag break-out in the content practically impossible without escaping the body.

Example: a document named "report.md" with MIME "text/markdown" produces:

<document-report-md-text-markdown>
…body…
</document-report-md-text-markdown>

Types

type Strategy

type Strategy int

Strategy describes how an attachment should be handled before sending to the provider.

const (
	// StrategyDrop means the attachment is not supported by the model or has no
	// inline content, and should be silently skipped (with a log warning).
	StrategyDrop Strategy = iota

	// StrategyTXT means the attachment should be wrapped in a TXTEnvelope and
	// sent as plain text.  Used for text/* MIME types whose content is already
	// in Source.InlineText.
	StrategyTXT

	// StrategyB64 means the attachment content (Source.InlineData) should be
	// base64-encoded and sent as a native provider image/document block.
	StrategyB64
)

func Decide

Decide returns the routing Strategy for a document given the current model's capabilities.

Algorithm:

  1. If the model does not support the document's MIME type → (Drop, reason).
  2. If Source.InlineData is non-empty → (B64, "").
  3. If Source.InlineText is non-empty → (TXT, "").
  4. Otherwise → (Drop, "no inline content").

Directories

Path Synopsis
Package modelcaps provides model capability queries for the attachment system.
Package modelcaps provides model capability queries for the attachment system.

Jump to

Keyboard shortcuts

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