AshAi.Transcript.Codec (ash_ai v1.5.6)

Copy Markdown View Source

Encodes Elixir terms as JSON-safe values and back, without losing atoms, tuples, binaries, or ReqLLM structs.

Provider metadata on ReqLLM messages uses atom keys and values (for example %{provider: :anthropic, signature: "..."}) that a JSON round trip would turn into strings, which the provider encoders would then ignore. Values that JSON can't represent are wrapped in a single-key object:

  • atoms: %{"$atom" => "anthropic"}
  • maps with atom keys: %{"$atoms" => %{"provider" => ...}}
  • other maps with non-string keys: %{"$map" => [[key, value], ...]}
  • tuples: %{"$tuple" => [...]}
  • non-UTF-8 binaries: %{"$binary" => base64}
  • ReqLLM structs: %{"$struct" => "ReqLLM.Message", "fields" => ...}

Decoding only creates existing atoms and only rebuilds the ReqLLM structs listed here; any other value decodes to plain data.

Summary

Functions

Decodes a value produced by encode/1.

Encodes a term as a JSON-safe value.

Functions

decode(value)

@spec decode(term()) :: term()

Decodes a value produced by encode/1.

encode(value)

@spec encode(term()) :: term()

Encodes a term as a JSON-safe value.