Spectre.Result (Spectre v0.3.0)

Copy Markdown View Source

Output of a handled turn.

Results carry everything the host boundary needs after a turn: user-visible reply text, updated state, effects, awaitables, route metadata, and events for logging.

{:ok, %Spectre.Result{reply_text: text, state: state}} =
  Spectre.ask(MyAgent, "hello")

Summary

Functions

Normalizes the latest terminal action effect into a host-facing outcome.

Returns every terminal lifecycle transition emitted by this result.

Returns the completion with the same precedence used by turn decisions: effect transitions first, then awaitables.

Returns a compact, normalized lifecycle view for host turn dispatch.

Returns the active awaitable from authoritative state, falling back to the transition-local awaitables carried by the result.

Returns the current pending effect from authoritative state, or from a state-less result assembled by a host.

Returns whether the result contains non-blank user-visible reply text.

Types

t()

@type t() :: %Spectre.Result{
  awaitables: [Spectre.Awaitable.t()],
  effects: [Spectre.Effect.t()],
  events: [term()],
  input: Spectre.Input.t() | nil,
  metadata: map(),
  reply_text: String.t(),
  route: Spectre.Route.t() | nil,
  state: Spectre.State.t() | nil
}

Functions

action_outcome(result)

@spec action_outcome(t()) :: Spectre.Effect.outcome()

Normalizes the latest terminal action effect into a host-facing outcome.

completions(result)

@spec completions(t()) :: [Spectre.Effect.t() | Spectre.Awaitable.t()]

Returns every terminal lifecycle transition emitted by this result.

latest_completion(result)

@spec latest_completion(t()) :: Spectre.Effect.t() | Spectre.Awaitable.t() | nil

Returns the completion with the same precedence used by turn decisions: effect transitions first, then awaitables.

lifecycle(result)

@spec lifecycle(t()) :: map()

Returns a compact, normalized lifecycle view for host turn dispatch.

open_awaitable(result)

@spec open_awaitable(t()) :: Spectre.Awaitable.t() | nil

Returns the active awaitable from authoritative state, falling back to the transition-local awaitables carried by the result.

pending_effect(result)

@spec pending_effect(t()) :: Spectre.Effect.t() | nil

Returns the current pending effect from authoritative state, or from a state-less result assembled by a host.

visible_reply?(result)

@spec visible_reply?(t()) :: boolean()

Returns whether the result contains non-blank user-visible reply text.