LlmCall.StreamAssembler (llm_call v0.1.0)

Copy Markdown View Source

Turns streamed tool-call fragments into complete LlmCall.ToolCall values.

Pure and protocol-neutral: it never executes a tool and never sends a result. Pending calls are keyed by LlmCall.StreamEvent.index, so several calls can complete independently and out of order.

The core has no JSON decoder, so new/1 takes one:

assembler = LlmCall.StreamAssembler.new(json_decoder: &JSON.decode/1)

Without a decoder, a call still arrives with its raw_arguments and an arguments_error of :no_json_decoder; it never arrives with invented arguments. The decoder's own message becomes the reason of {:invalid_json, reason}.

Summary

Types

decoder()

@type decoder() :: (String.t() -> {:ok, map()} | {:error, String.t()}) | nil

t()

@opaque t()

Functions

feed(assembler, stream_event)

@spec feed(t(), LlmCall.StreamEvent.t()) :: {:ok, t(), [LlmCall.ToolCall.t()]}

finish(assembler)

@spec finish(t()) :: {:ok, t(), [LlmCall.ToolCall.t()]}

new(opts \\ [])

@spec new(keyword()) :: t()