Spectre.Input.Pipeline (Spectre v0.3.0)

Copy Markdown View Source

Runs input plugs before the Spectre runtime handles a turn.

Input normalization is a boundary concern. By running it before state loading, policy matching, and routing, the rest of the runtime can depend on one internal %Spectre.Input{} shape instead of repeatedly handling raw host payloads.

specs = [
  {Spectre.Input.Plugs.NormalizeText, trim?: true, case: :downcase}
]

{:ok, input} =
  Spectre.Input.Pipeline.run(
    Spectre.Input.new("  HELLO  "),
    %{agent: MyApp.Agent, opts: []},
    specs
  )

Summary

Functions

Initializes input plug specs.

Runs an input through initialized or ad-hoc plug specs.

Types

plug_spec()

@type plug_spec() ::
  module() | {module(), keyword()} | Spectre.Input.Pipeline.Spec.t()

Functions

init_specs(specs, callback_opts \\ [])

@spec init_specs(
  [plug_spec()],
  keyword()
) :: {:ok, [Spectre.Input.Pipeline.Spec.t()]} | {:error, term()}

Initializes input plug specs.

Use this when a host process wants to prepare a reusable pipeline once and run it for many turns.

run(input, context, specs)

@spec run(Spectre.Input.t(), map(), [plug_spec()]) ::
  {:ok, Spectre.Input.t()} | {:error, term()}

Runs an input through initialized or ad-hoc plug specs.

A plug may continue with a new input, halt with a final input, or return an error. Halting is useful when a boundary plug can fully normalize or reject a turn before router/runtime work starts.