pub struct InteractionDefinition {
pub schema: DefinitionTag,
pub kind: InteractionKind,
pub revision: Revision,
pub markdown: String,
pub controls: Vec<Control>,
pub features: Vec<FeatureDemand>,
pub note: Option<String>,
}Expand description
The immutable semantic model of one interaction.
Identity is a DefinitionId — a ContentId over the canonical
encoding of this whole record, which is also its exact form digest.
Fields§
§schema: DefinitionTagVersioned type tag; see DEFINITION_SCHEMA_V1.
kind: InteractionKindWhat kind of interaction this is.
revision: RevisionWhich revision of this definition’s authoring lineage this is.
markdown: StringThe readable body — canonical Markdown, the fallback every surface
can render (ADR law 1). Held as text; parsing belongs to
newt_core::markup, not to the protocol layer.
controls: Vec<Control>The controls, in presentation order.
features: Vec<FeatureDemand>What a surface must be able to do to present this faithfully, each demand marked required or optional.
note: Option<String>A subordinate line beneath the body — a control hint, a danger
warning. Readable content like markdown, kept separate because
surfaces place it differently and the legacy prompt already
distinguishes the two.
Omitted when absent, so a definition without one is byte-identical to one written before this field existed.
Implementations§
Source§impl InteractionDefinition
impl InteractionDefinition
Sourcepub fn is_decision_shaped(&self) -> bool
pub fn is_decision_shaped(&self) -> bool
Whether this definition can ONLY be a binary decision: one
ControlKind::Choice control offering exactly two options, one
granting and the other refusing or backing out.
Keys on SemanticRole, never on the option count. Allow + Deny
is a decision, Allow + Cancel is a decision that offers a way out,
and Value + Value is a two-way pick and not a decision at all.
Deliberately narrower than “is a yes/no”, and the gap is the point.
A lone ControlKind::Toggle is also a yes/no — and it is the case
that settles #1912, because InteractionKind::Choice means “pick one
of a fixed, DISPLAYED set” and a toggle displays no set, so Choice
cannot describe it and Confirm is not redundant with it.
But a lone toggle is ALSO a one-field form — “remember this? [ ]” — and
nothing in the shape says which. So the toggle case is admitted by
InteractionKind::Confirm and never required of it. This predicate
reports only what a shape can prove, which is why the guard in
InteractionDefinition::new enforces one direction and not both.
Sourcepub fn new(
kind: InteractionKind,
markdown: impl Into<String>,
controls: Vec<Control>,
) -> Self
pub fn new( kind: InteractionKind, markdown: impl Into<String>, controls: Vec<Control>, ) -> Self
Build a definition carrying the current schema tag.
Sourcepub fn definition_id(&self) -> Result<DefinitionId, ProtocolError>
pub fn definition_id(&self) -> Result<DefinitionId, ProtocolError>
This definition’s identity, which is also its exact form digest.
§Errors
Propagates a canonical-encoding failure.
Sourcepub fn schema_tag(&self) -> &'static str
pub fn schema_tag(&self) -> &'static str
The schema tag, as a string.
Reading it needs no check: the tag is a TYPE that deserializes from
exactly one value, so a record of this type cannot carry any other
one. What used to be a runtime ensure_known_schema is now a thing
the wire cannot express — and the published schema says so with a
const, so a foreign implementor validating against the wrong
record’s schema fails instead of passing.
Trait Implementations§
Source§impl Clone for InteractionDefinition
impl Clone for InteractionDefinition
Source§impl ContentAddressable for InteractionDefinition
impl ContentAddressable for InteractionDefinition
Source§fn canonical_form(&self) -> Result<Vec<u8>, ContentError>
fn canonical_form(&self) -> Result<Vec<u8>, ContentError>
Source§fn content_id(&self) -> Result<ContentId, ContentError>
fn content_id(&self) -> Result<ContentId, ContentError>
Source§fn verify(&self, expected: &ContentId) -> Result<bool, ContentError>
fn verify(&self, expected: &ContentId) -> Result<bool, ContentError>
expected id. Read moreSource§fn ensure_content_id(&self, expected: &ContentId) -> Result<(), ContentError>
fn ensure_content_id(&self, expected: &ContentId) -> Result<(), ContentError>
Ok(false). Read moreSource§fn from_canonical_form(bytes: &[u8]) -> Result<Self, ContentError>where
Self: Sized + DeserializeOwned,
fn from_canonical_form(bytes: &[u8]) -> Result<Self, ContentError>where
Self: Sized + DeserializeOwned,
canonical_form. Read more