attachment

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataKeyBotID      = "bot_id"
	MetadataKeyStorageKey = "storage_key"
	MetadataKeyName       = "name"
	MetadataKeySourcePath = "source_path"
	MetadataKeySourceURL  = "source_url"
)

Variables

This section is empty.

Functions

func DataMountPath

func DataMountPath(raw string) string

DataMountPath joins a relative path under the canonical container data mount.

func DataSubpath

func DataSubpath(containerPath string) (string, bool)

DataSubpath strips the canonical /data/ prefix and returns the container-relative path.

func DecodeBase64

func DecodeBase64(input string, maxBytes int64) (io.Reader, error)

DecodeBase64 decodes both raw base64 and data URL base64 content. The returned reader is bounded to maxBytes+1 for caller-side size validation.

func ExtractStorageKey

func ExtractStorageKey(accessPath string) string

ExtractStorageKey derives the media storage key from a consumer-facing media path. The legacy /data/media root remains readable during the transition.

func InferNameFromRef

func InferNameFromRef(raw string) string

InferNameFromRef extracts a filename from a path or URL-like reference.

func InferTypeFromExt

func InferTypeFromExt(raw string) string

InferTypeFromExt infers attachment type from file extension.

func InferTypeFromMime

func InferTypeFromMime(mime string) string

InferTypeFromMime infers attachment type from MIME.

func IsDataPath

func IsDataPath(raw string) bool

IsDataPath reports whether the reference points to the container data mount.

func IsDataURL

func IsDataURL(raw string) bool

IsDataURL reports whether the reference is a data URL.

func IsHTTPURL

func IsHTTPURL(raw string) bool

IsHTTPURL reports whether the reference is an http(s) URL.

func IsMediaAccessPath

func IsMediaAccessPath(raw string) bool

IsMediaAccessPath reports whether raw is under the current or legacy media root. Both roots are managed media during the transition.

func MapMediaType

func MapMediaType(rawType string) media.MediaType

MapMediaType maps attachment type strings to media types.

func MediaAccessPath

func MediaAccessPath(storageKey string) string

MediaAccessPath returns the consumer-facing media access path for a storage key.

func MetadataString

func MetadataString(metadata map[string]any, key string) string

MetadataString returns a trimmed string metadata value.

func MimeFromDataURL

func MimeFromDataURL(raw string) string

MimeFromDataURL extracts MIME from a data URL.

func NormalizeBase64DataURL

func NormalizeBase64DataURL(input, mime string) string

NormalizeBase64DataURL normalizes raw base64 into a data URL.

func NormalizeMime

func NormalizeMime(raw string) string

NormalizeMime normalizes MIME to lowercase token form.

func PrepareReaderAndMime

func PrepareReaderAndMime(reader io.Reader, mediaType media.MediaType, sourceMime string) (io.Reader, string, error)

PrepareReaderAndMime reads a small prefix for MIME sniffing and replays it.

func ResolveMime

func ResolveMime(mediaType media.MediaType, sourceMime, sniffedMime string) string

ResolveMime resolves source MIME and sniffed MIME into final MIME.

For image attachments, content sniffing takes precedence over the platform-reported MIME because platforms sometimes declare the wrong image subtype (e.g. "image/png" for a JPEG file). Using the wrong MIME causes multimodal API rejections (HTTP 400).

Types

type Bundle

type Bundle struct {
	Type           string
	Base64         string
	Path           string
	URL            string
	PlatformKey    string
	SourcePlatform string
	ContentHash    string
	Name           string
	Mime           string
	Size           int64
	DurationMs     int64
	Width          int
	Height         int
	ThumbnailURL   string
	Caption        string
	Metadata       map[string]any
}

Bundle is the internal attachment normalization shape shared across messaging, channel ingress, and gateway preparation. It is intentionally not exposed as a user-facing contract.

func BundleFromMap

func BundleFromMap(item map[string]any) Bundle

BundleFromMap builds a bundle from a generic JSON-like object.

func ParseToolInputBundles

func ParseToolInputBundles(raw any) ([]Bundle, bool)

ParseToolInputBundles normalizes the `send.attachments` argument shape into internal bundles while preserving existing path resolution rules.

func (Bundle) MergeIntoMap

func (b Bundle) MergeIntoMap(item map[string]any) map[string]any

MergeIntoMap applies bundle-owned fields into an existing JSON-like object. Unknown fields are preserved.

func (Bundle) Normalize

func (b Bundle) Normalize() Bundle

Normalize canonicalizes transport fields and fills lightweight derived data such as MIME, name, and inferred type.

func (Bundle) ToMap

func (b Bundle) ToMap() map[string]any

ToMap serializes the internal bundle back into a generic JSON-like object.

func (Bundle) WithAsset

func (b Bundle) WithAsset(botID string, asset media.Asset) Bundle

WithAsset rewrites the bundle into a persisted asset reference while preserving useful source metadata for later resolution and rendering. Callers must guarantee b is already normalized (produced by BundleFromXxx or Normalize()).

func (Bundle) WithAssetAccess

func (b Bundle) WithAssetAccess(botID string, asset media.Asset, accessRef string) Bundle

WithAssetAccess rewrites the bundle into a persisted asset reference and keeps a consumer-accessible path/URL when the caller needs one.

Jump to

Keyboard shortcuts

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