Spectre.Prompt.Fragment (Spectre v0.3.0)

Copy Markdown View Source

Resolved or canonical prompt content with its composition metadata.

Runtime fragments are built with new/3. Content-addressed Definition fragments are built with canonical/1; those fragments reject EEx and use a closed {{path.to.value}} placeholder grammar with an explicit schema.

Summary

Functions

Builds the base task fragment selected by ask.

Builds a governed, digest-addressed prompt fragment.

Builds a canonical fragment or raises with its stable validation reason.

Returns the portable data included in a canonical fragment digest.

Migrates the safe subset of compiled .text.heex assets to closed templates.

Builds a resolved prompt fragment from an operation.

Types

t()

@type t() :: %Spectre.Prompt.Fragment{
  budget_class: :small | :standard | :large,
  condition_ref: map() | nil,
  content: String.t() | nil,
  digest: String.t() | nil,
  granted_priority: :low | :normal | :high,
  id: term(),
  metadata: map(),
  placeholders: map(),
  position: Spectre.Prompt.Operation.position(),
  provenance: map(),
  requested_priority: :low | :normal | :high,
  schema_version: pos_integer(),
  scope: term(),
  source: Spectre.Prompt.Operation.source() | :base | map(),
  target: Spectre.Prompt.Operation.target(),
  token_cap: pos_integer() | nil,
  trust: :instruction | :data,
  visibility: :private | :agent | :operator | :public
}

Functions

base(content)

@spec base(String.t()) :: t()

Builds the base task fragment selected by ask.

canonical(fragment)

@spec canonical(map() | keyword()) :: {:ok, t()} | {:error, term()}

Builds a governed, digest-addressed prompt fragment.

Canonical content may be static text or a template containing only declared {{path.to.value}} placeholders. Dynamic providers use content: nil and must remain context:data fragments.

canonical!(attrs)

@spec canonical!(map() | keyword()) :: t()

Builds a canonical fragment or raises with its stable validation reason.

canonical_data(fragment)

@spec canonical_data(t()) :: map()

Returns the portable data included in a canonical fragment digest.

close_template(content)

@spec close_template(String.t()) :: {:ok, String.t(), map()} | {:error, term()}

Migrates the safe subset of compiled .text.heex assets to closed templates.

Only direct assign paths such as <%= @input.text %> are accepted. Any remaining EEx tag is rejected instead of being copied into runtime data.

new(operation, content, metadata \\ %{})

@spec new(Spectre.Prompt.Operation.t(), String.t(), map()) :: t()

Builds a resolved prompt fragment from an operation.