Dsxir.LM.StreamChunk (dsxir v0.5.0)

Copy Markdown

Provider-neutral streaming event emitted by a Dsxir.LM implementation when a :stream callback is passed to generate_text/3.

Implementations translate their provider SDK's chunk type into this struct so consumers never depend on a specific provider (the same boundary Dsxir.Cost and Dsxir.Errors.LM.* draw for usage and errors). The :type tag selects what :data carries:

  • :text_deltadata is a String.t() fragment of generated text.
  • :reasoning_deltadata is a String.t() fragment of reasoning text.
  • :tool_call_deltadata is %{id: String.t(), name: String.t() | nil, arguments_delta: String.t()}.

  • :usagedata is a %Dsxir.Cost{} with final token counts.
  • :done — terminal success; data is the final accumulator (often nil).
  • :failed / :incomplete / :cancelled — terminal failure; data is a Dsxir.Errors.LM.* describing why the stream halted.

index disambiguates parallel tool calls or multiple choices when the provider supplies it; it is nil otherwise.

Summary

Types

t()

@type t() :: %Dsxir.LM.StreamChunk{
  data: term(),
  index: non_neg_integer() | nil,
  type: type()
}

type()

@type type() ::
  :text_delta
  | :reasoning_delta
  | :tool_call_delta
  | :usage
  | :done
  | :failed
  | :incomplete
  | :cancelled