Jidoka.Stream (Jidoka v0.8.0-beta.1)

Copy Markdown View Source

Request-scoped stream helpers for Jidoka turn events.

The runtime remains terminal-result oriented, but callers that pass stream_to: pid or on_event: fun can observe Jidoka.Event values as the turn runs. This mirrors the request-owned streaming shape from Jidoka v1 without depending on Jido.AI's internal event structs.

Summary

Functions

Waits for the final normalized result for a stream wrapper.

Emits one event to the stream sinks configured for a running turn.

Builds a mailbox-backed enumerable for a request id.

Returns the mailbox tag used for streamed turn events.

Builds a stream wrapper for an async chat request.

Returns true when an event terminates a turn stream.

Extracts a content delta from an :llm_delta event.

Extracts a thinking/reasoning delta from an :llm_delta event.

Types

t()

@type t() :: %Jidoka.Stream{events: Enumerable.t(), request: Jidoka.Chat.Request.t()}

Functions

await(stream, opts \\ [])

@spec await(
  t(),
  keyword()
) :: term()

Waits for the final normalized result for a stream wrapper.

emit(event, opts)

@spec emit(
  Jidoka.Event.t(),
  keyword()
) :: :ok

Emits one event to the stream sinks configured for a running turn.

Custom capabilities can call this when they want to surface incremental provider output, for example :llm_delta events from a streaming model.

events(request_id, opts \\ [])

@spec events(
  String.t(),
  keyword()
) :: Enumerable.t()

Builds a mailbox-backed enumerable for a request id.

This is intentionally small: it consumes already-emitted Jidoka events from the caller mailbox and halts on a terminal event or timeout.

message_tag()

@spec message_tag() :: atom()

Returns the mailbox tag used for streamed turn events.

new(request, opts \\ [])

@spec new(
  Jidoka.Chat.Request.t(),
  keyword()
) :: t()

Builds a stream wrapper for an async chat request.

terminal?(event)

@spec terminal?(Jidoka.Event.t()) :: boolean()

Returns true when an event terminates a turn stream.

text_delta(event)

@spec text_delta(Jidoka.Event.t()) :: String.t() | nil

Extracts a content delta from an :llm_delta event.

thinking_delta(event)

@spec thinking_delta(Jidoka.Event.t()) :: String.t() | nil

Extracts a thinking/reasoning delta from an :llm_delta event.