chatfiles

package
v2.36.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const MaxStoredFileNameBytes = 255

Variables

View Source
var (
	// ErrStoredFileNameRequired indicates that a durable file name is empty
	// after normalization.
	ErrStoredFileNameRequired = xerrors.New("stored file name is required")
)

Functions

func AllowedPromptInputMediaTypesString added in v2.35.0

func AllowedPromptInputMediaTypesString() string

AllowedPromptInputMediaTypesString returns the supported prompt input media types as a comma-separated list.

func BaseMediaType

func BaseMediaType(mediaType string) string

BaseMediaType strips parameters from a media type.

func ClassifyStoredMediaType

func ClassifyStoredMediaType(name string, data []byte) string

ClassifyStoredMediaType returns the media type that durable chat storage would use for the given filename and bytes. Unsupported or blocked content is returned as its detected media type so callers can report the specific type.

func DetectMediaType

func DetectMediaType(data []byte) string

DetectMediaType detects the base media type of the given file contents.

func HasSVGRootElement

func HasSVGRootElement(data []byte) bool

HasSVGRootElement reports whether the provided file bytes decode to an SVG root element. This catches SVG content even when generic sniffers classify it as text or XML.

func IsAllowedPromptInputMediaType added in v2.35.0

func IsAllowedPromptInputMediaType(mediaType string) bool

IsAllowedPromptInputMediaType reports whether the media type is supported for user-provided prompt input.

func IsCompatibleUploadMediaType

func IsCompatibleUploadMediaType(declaredMediaType, storedMediaType string) bool

IsCompatibleUploadMediaType reports whether an upload request that declared declaredMediaType may be stored as storedMediaType after byte classification. Exact matches are always compatible. Clients that declare application/octet-stream are treated as "unknown", so the classified bytes decide the stored type. The compatibility table also covers explicit refinements like text/plain uploads that safely store as richer text subtypes.

func IsInlineRenderableStoredMediaType

func IsInlineRenderableStoredMediaType(mediaType string) bool

IsInlineRenderableStoredMediaType reports whether a stored chat file may be served with Content-Disposition: inline. PDFs remain storable but download-only because browser PDF viewers have a broader active-content attack surface than the other media types we allow inline.

func NormalizeStoredFileName

func NormalizeStoredFileName(name string) string

NormalizeStoredFileName trims surrounding whitespace, strips control characters, and truncates the name to the durable storage byte limit without splitting UTF-8 runes.

func PrepareRecordingArtifact

func PrepareRecordingArtifact(name, expectedMediaType string, data []byte) (storedName, mediaType string, err error)

PrepareRecordingArtifact normalizes the recording artifact name, rejects empty normalized names, and verifies that the bytes match the expected recording media type.

func PrepareStoredFile

func PrepareStoredFile(name, detectName string, data []byte) (storedName, mediaType string, err error)

PrepareStoredFile normalizes the display name, rejects empty normalized names, and classifies the file bytes using detectName when provided, so callers can apply the right policy for their file source.

Types

This section is empty.

Jump to

Keyboard shortcuts

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