Toolnexus.Answer (toolnexus v0.20.0)

Copy Markdown View Source

A §10 answer: {id, ok, data?} — keys byte-identical across ports.

Summary

Functions

The answer to a §10 suspension the human REFUSED (addendum A9). reason is carried verbatim; "declined" is the spelling an MCP elicitation maps back to a decline action, anything else maps to cancel.

The answer to a §10 kind: "input" suspension: the resolution IS the payload.

Coerce an %Answer{} or a plain atom/string-keyed map into an %Answer{}.

Decode from a JSON-shaped map (string keys).

Read a §10 answer's fields from an %Answer{} OR a plain map with ATOM or STRING keys. §10 fixes the key spelling across every port, so a host resuming out of a JSON column must not crash on %{"ok" => true} (ADR 0026 / D4).

True when this answer resolves the request affirmatively (atom or string keys).

Types

t()

@type t() :: %Toolnexus.Answer{
  data: map() | nil,
  id: String.t(),
  ok: boolean(),
  reason: String.t() | nil
}

Functions

answer_declined(id, reason \\ "declined")

@spec answer_declined(String.t(), String.t() | nil) :: t()

The answer to a §10 suspension the human REFUSED (addendum A9). reason is carried verbatim; "declined" is the spelling an MCP elicitation maps back to a decline action, anything else maps to cancel.

iex> Toolnexus.Answer.answer_declined("req-1", "declined").ok
false

answer_output(id, output)

@spec answer_output(String.t(), String.t()) :: t()

The answer to a §10 kind: "input" suspension: the resolution IS the payload.

Hand-building %{id: id, ok: true, data: %{"output" => value}} is the one place a host had to know an unwritten required key (ADR 0026); this constructor removes it. output must be a STRING — anything else raises rather than degrading to "".

iex> Toolnexus.Answer.answer_output("req-1", "42").data
%{"output" => "42"}

coerce(a)

@spec coerce(t() | map()) :: t()

Coerce an %Answer{} or a plain atom/string-keyed map into an %Answer{}.

from_map(m)

@spec from_map(map()) :: t()

Decode from a JSON-shaped map (string keys).

get(a, key)

@spec get(t() | map(), :id | :ok | :data | :reason) :: term()

Read a §10 answer's fields from an %Answer{} OR a plain map with ATOM or STRING keys. §10 fixes the key spelling across every port, so a host resuming out of a JSON column must not crash on %{"ok" => true} (ADR 0026 / D4).

ok?(a)

@spec ok?(t() | map() | term()) :: boolean()

True when this answer resolves the request affirmatively (atom or string keys).