Jido.Chat.MediaType (Jido Chat v1.2.0)

Copy Markdown View Source

Resolves media types without applying a provider-independent default.

Adapters should use evidence in this order:

  1. A valid MIME value declared by the provider.
  2. A default that the provider contract guarantees for the downloadable file.
  3. A valid HTTP Content-Type, when it comes from the media download response.
  4. A file signature, when the bytes have already been downloaded.
  5. A filename or URL extension as a best-effort hint.

Pass the provider payload value as the first argument to resolve/2. Pass a download response Content-Type as :response_media_type. A provider default is never added unless the caller supplies :provider_default. Normalization and MIME resolution do not change media bytes.

Summary

Functions

Returns a MIME hint from a filename, path, or URL extension.

Returns the canonical media kind from MIME data or a reference hint.

Returns a normalized MIME value or nil for blank and invalid values.

Resolves the best available MIME value.

Detects common binary formats from their file signatures.

Types

kind()

@type kind() :: :image | :audio | :video | :file

Functions

from_filename(value)

@spec from_filename(term()) :: String.t() | nil

Returns a MIME hint from a filename, path, or URL extension.

kind(media_type, reference \\ nil)

@spec kind(term(), term()) :: kind()

Returns the canonical media kind from MIME data or a reference hint.

normalize(value)

@spec normalize(term()) :: String.t() | nil

Returns a normalized MIME value or nil for blank and invalid values.

resolve(provider_value, opts \\ [])

@spec resolve(
  term(),
  keyword()
) :: String.t() | nil

Resolves the best available MIME value.

Supported options are :provider_default, :response_media_type, :data, :filename, :url, and :path. Filename and reference values are hints and have the lowest priority.

sniff(arg1)

@spec sniff(term()) :: String.t() | nil

Detects common binary formats from their file signatures.