Documentation
¶
Index ¶
- Constants
- Variables
- func AddCollisionSuffix(name string, n int) string
- func AllowedPromptInputMediaTypesString() string
- func BaseMediaType(mediaType string) string
- func ClassifyStoredMediaType(name string, data []byte) string
- func DetectMediaType(data []byte) string
- func HasSVGRootElement(data []byte) bool
- func IsAllowedPromptInputMediaType(mediaType string) bool
- func IsCompatibleUploadMediaType(declaredMediaType, storedMediaType string) bool
- func IsInlineRenderableStoredMediaType(mediaType string) bool
- func IsRasterImageMediaType(mediaType string) bool
- func IsTextAttachmentMediaType(mediaType string) bool
- func NormalizeStoredFileName(name string) string
- func ParseBaseMediaType(mediaType string) (string, error)
- func PrepareRecordingArtifact(name, expectedMediaType string, data []byte) (storedName, mediaType string, err error)
- func PrepareStoredFile(name, detectName string, data []byte) (storedName, mediaType string, err error)
- func SanitizeWorkspaceUploadName(name string) (string, error)
- func WorkspaceChatDir(homeDir, chatID string) string
- func WorkspaceUploadDir(homeDir, chatID string) string
Constants ¶
const ( // MaxWorkspaceUploadFileNameBytes matches the stored attachment name limit. MaxWorkspaceUploadFileNameBytes = MaxStoredFileNameBytes // WorkspaceChatsDir is the directory under the agent's home directory // that holds per-chat coder artifacts. WorkspaceChatsDir = ".coder/chats" // WorkspaceUploadFilesSubdir is the subdirectory of a chat's // workspace folder that holds uploaded files. WorkspaceUploadFilesSubdir = "files" )
const MaxMediaTypeBytes = 255
MaxMediaTypeBytes bounds client-supplied media types, parameters included.
const MaxStoredFileNameBytes = 255
Variables ¶
var ( // ErrStoredFileNameRequired indicates that a durable file name is empty // after normalization. ErrStoredFileNameRequired = xerrors.New("stored file name is required") )
var ErrWorkspaceUploadNameRequired = xerrors.New("workspace upload file name is required")
ErrWorkspaceUploadNameRequired indicates that a workspace upload name is empty after sanitization.
Functions ¶
func AddCollisionSuffix ¶
AddCollisionSuffix inserts a `_<n>` suffix before the extension when n > 1.
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 ¶
BaseMediaType strips parameters from a media type.
func ClassifyStoredMediaType ¶
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 ¶
DetectMediaType detects the base media type of the given file contents.
func HasSVGRootElement ¶
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
IsAllowedPromptInputMediaType reports whether the media type is supported for user-provided prompt input.
func IsCompatibleUploadMediaType ¶
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 types, including SVG source, which stays download-only once stored.
func IsInlineRenderableStoredMediaType ¶
IsInlineRenderableStoredMediaType reports whether a stored chat file may be served with Content-Disposition: inline. PDF and SVG remain storable but download-only because browsers execute them as top-level documents (PDF viewers, SVG script).
func IsRasterImageMediaType ¶
IsRasterImageMediaType reports whether the media type is a picture that may be drawn or sent to the model as a native image part. Unknown image/ subtypes from tool output keep prefix semantics; only allowlisted text types such as SVG are excluded.
func IsTextAttachmentMediaType ¶
IsTextAttachmentMediaType reports whether the media type is an allowlisted attachment type whose bytes are UTF-8 source the model reads directly. This includes SVG, whose image/ prefix does not make it a picture.
func NormalizeStoredFileName ¶
NormalizeStoredFileName trims surrounding whitespace, strips control characters, and truncates the name to the durable storage byte limit without splitting UTF-8 runes.
func ParseBaseMediaType ¶
ParseBaseMediaType strictly parses a client-supplied media type and returns its lowercased type/subtype without parameters. Unlike BaseMediaType, it rejects values that do not parse instead of returning them unchanged.
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.
func SanitizeWorkspaceUploadName ¶
SanitizeWorkspaceUploadName extracts a basename, normalizes unsafe whitespace, control characters, Windows-invalid punctuation, and shell, quote, and bracket characters to underscores, strips edge dots, and truncates the result to MaxWorkspaceUploadFileNameBytes. It returns ErrWorkspaceUploadNameRequired when no safe name remains.
func WorkspaceChatDir ¶
WorkspaceChatDir returns the per-chat directory under the agent home directory.
func WorkspaceUploadDir ¶
WorkspaceUploadDir returns the per-chat workspace upload directory.
Types ¶
This section is empty.