//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `consent/decision`. Version: `1.0`.
/// Why this specification version is deprecated (SPEC "Superseded and
/// Withdrawn Versions"), or `None` while it is current.
pub const DEPRECATION: Option<&str> = None;
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
/// Error types.
pub mod error {
/// Error from a `TryFrom` or `FromStr` implementation.
pub struct ConversionError(::std::borrow::Cow<'static, str>);
impl ::std::error::Error for ConversionError {}
impl ::std::fmt::Display for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Display::fmt(&self.0, f)
}
}
impl ::std::fmt::Debug for ConversionError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> Result<(), ::std::fmt::Error> {
::std::fmt::Debug::fmt(&self.0, f)
}
}
impl From<&'static str> for ConversionError {
fn from(value: &'static str) -> Self {
Self(value.into())
}
}
impl From<String> for ConversionError {
fn from(value: String) -> Self {
Self(value.into())
}
}
}
///The platform-agnostic identifier of WHAT is being consented to: one conversation, for one agent.
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct ConsentSubject {
///VID (DID) of the AI agent the conversation would reach.
pub agent: ConsentSubjectAgent,
///The bridge's OPAQUE conversation handle (e.g. "sig-1a2b3c4d"). NEVER the raw platform address — the VTA never learns the phone number / chat id.
#[serde(rename = "conversationRef")]
pub conversation_ref: ConsentSubjectConversationRef,
pub kind: Kind,
///Messaging-platform tag, e.g. "signal", "whatsapp", "slack".
pub platform: ConsentSubjectPlatform,
}
impl ConsentSubject {
pub fn builder() -> builder::ConsentSubject {
Default::default()
}
}
///VID (DID) of the AI agent the conversation would reach.
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ConsentSubjectAgent(::std::string::String);
impl ::std::ops::Deref for ConsentSubjectAgent {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ConsentSubjectAgent> for ::std::string::String {
fn from(value: ConsentSubjectAgent) -> Self {
value.0
}
}
impl ::std::str::FromStr for ConsentSubjectAgent {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ConsentSubjectAgent {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ConsentSubjectAgent {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ConsentSubjectAgent {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ConsentSubjectAgent {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///The bridge's OPAQUE conversation handle (e.g. "sig-1a2b3c4d"). NEVER the raw platform address — the VTA never learns the phone number / chat id.
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ConsentSubjectConversationRef(::std::string::String);
impl ::std::ops::Deref for ConsentSubjectConversationRef {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ConsentSubjectConversationRef> for ::std::string::String {
fn from(value: ConsentSubjectConversationRef) -> Self {
value.0
}
}
impl ::std::str::FromStr for ConsentSubjectConversationRef {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ConsentSubjectConversationRef {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ConsentSubjectConversationRef {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ConsentSubjectConversationRef {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ConsentSubjectConversationRef {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Messaging-platform tag, e.g. "signal", "whatsapp", "slack".
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ConsentSubjectPlatform(::std::string::String);
impl ::std::ops::Deref for ConsentSubjectPlatform {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ConsentSubjectPlatform> for ::std::string::String {
fn from(value: ConsentSubjectPlatform) -> Self {
value.0
}
}
impl ::std::str::FromStr for ConsentSubjectPlatform {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 1usize {
return Err("shorter than 1 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ConsentSubjectPlatform {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ConsentSubjectPlatform {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ConsentSubjectPlatform {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ConsentSubjectPlatform {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Whether the subject is permitted. The ABSENCE of any grant is treated as `deny` (default-deny).
///
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum Effect {
#[serde(rename = "allow")]
Allow,
#[serde(rename = "deny")]
Deny,
}
impl ::std::fmt::Display for Effect {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Allow => f.write_str("allow"),
Self::Deny => f.write_str("deny"),
}
}
}
impl ::std::str::FromStr for Effect {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"allow" => Ok(Self::Allow),
"deny" => Ok(Self::Deny),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for Effect {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for Effect {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for Effect {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(transparent)]
pub struct Ext(pub ::std::collections::HashMap<ExtKey, ::serde_json::Value>);
impl ::std::ops::Deref for Ext {
type Target = ::std::collections::HashMap<ExtKey, ::serde_json::Value>;
fn deref(&self) -> &::std::collections::HashMap<ExtKey, ::serde_json::Value> {
&self.0
}
}
impl ::std::convert::From<Ext> for ::std::collections::HashMap<ExtKey, ::serde_json::Value> {
fn from(value: Ext) -> Self {
value.0
}
}
impl ::std::convert::From<::std::collections::HashMap<ExtKey, ::serde_json::Value>> for Ext {
fn from(value: ::std::collections::HashMap<ExtKey, ::serde_json::Value>) -> Self {
Self(value)
}
}
///`ExtKey`
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ExtKey(::std::string::String);
impl ::std::ops::Deref for ExtKey {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ExtKey> for ::std::string::String {
fn from(value: ExtKey) -> Self {
value.0
}
}
impl ::std::str::FromStr for ExtKey {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
static PATTERN: ::std::sync::LazyLock<::regress::Regex> =
::std::sync::LazyLock::new(|| {
::regress::Regex::new("^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$").unwrap()
});
if PATTERN.find(value).is_none() {
return Err("doesn't match pattern \"^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$\"".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ExtKey {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ExtKey {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///The interaction kind: a 1:1 direct message, a multi-party group, or a broadcast channel.
///
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum Kind {
#[serde(rename = "dm")]
Dm,
#[serde(rename = "group")]
Group,
#[serde(rename = "channel")]
Channel,
}
impl ::std::fmt::Display for Kind {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Dm => f.write_str("dm"),
Self::Group => f.write_str("group"),
Self::Channel => f.write_str("channel"),
}
}
}
impl ::std::str::FromStr for Kind {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"dm" => Ok(Self::Dm),
"group" => Ok(Self::Group),
"channel" => Ok(Self::Channel),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for Kind {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for Kind {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for Kind {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///An approver allows or denies an AI agent's access to a messaging conversation.
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Payload {
///Echoes the consent/request challenge this decision answers. Omit only for an operator-initiated pre-authorization.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub challenge: ::std::option::Option<PayloadChallenge>,
pub effect: Effect,
///Optional grant TTL; after it the subject must be re-consented.
#[serde(
rename = "expiresAt",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub expires_at: ::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///Granted scope. REQUIRED when `effect` is `allow`.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub scope: ::std::option::Option<Scope>,
pub subject: ConsentSubject,
}
impl Payload {
pub fn builder() -> builder::Payload {
Default::default()
}
}
///Echoes the consent/request challenge this decision answers. Omit only for an operator-initiated pre-authorization.
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadChallenge(::std::string::String);
impl ::std::ops::Deref for PayloadChallenge {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadChallenge> for ::std::string::String {
fn from(value: PayloadChallenge) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadChallenge {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() < 16usize {
return Err("shorter than 16 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for PayloadChallenge {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for PayloadChallenge {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for PayloadChallenge {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for PayloadChallenge {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///Acknowledgement that the decision was recorded (or rejected).
///
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
pub struct Response {
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///The VTA's id for the recorded grant (set when recorded).
#[serde(
rename = "grantId",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub grant_id: ::std::option::Option<::std::string::String>,
///Required when status is `rejected`.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub reason: ::std::option::Option<ResponseReason>,
///`recorded` = a grant was written. `rejected` = not accepted; `reason` MUST be set.
pub status: ResponseStatus,
}
impl Response {
pub fn builder() -> builder::Response {
Default::default()
}
}
///Required when status is `rejected`.
///
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ResponseReason(::std::string::String);
impl ::std::ops::Deref for ResponseReason {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ResponseReason> for ::std::string::String {
fn from(value: ResponseReason) -> Self {
value.0
}
}
impl ::std::str::FromStr for ResponseReason {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
if value.chars().count() > 1024usize {
return Err("longer than 1024 characters".into());
}
Ok(Self(value.to_string()))
}
}
impl ::std::convert::TryFrom<&str> for ResponseReason {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ResponseReason {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ResponseReason {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl<'de> ::serde::Deserialize<'de> for ResponseReason {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
where
D: ::serde::Deserializer<'de>,
{
::std::string::String::deserialize(deserializer)?
.parse()
.map_err(|e: self::error::ConversionError| {
<D::Error as ::serde::de::Error>::custom(e.to_string())
})
}
}
///`recorded` = a grant was written. `rejected` = not accepted; `reason` MUST be set.
///
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum ResponseStatus {
#[serde(rename = "recorded")]
Recorded,
#[serde(rename = "rejected")]
Rejected,
}
impl ::std::fmt::Display for ResponseStatus {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Recorded => f.write_str("recorded"),
Self::Rejected => f.write_str("rejected"),
}
}
}
impl ::std::str::FromStr for ResponseStatus {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"recorded" => Ok(Self::Recorded),
"rejected" => Ok(Self::Rejected),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for ResponseStatus {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for ResponseStatus {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for ResponseStatus {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///What the agent may do: `receive` = read inbound on this conversation; `converse` = read and reply.
///
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
#[non_exhaustive]
pub enum Scope {
#[serde(rename = "receive")]
Receive,
#[serde(rename = "converse")]
Converse,
}
impl ::std::fmt::Display for Scope {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Receive => f.write_str("receive"),
Self::Converse => f.write_str("converse"),
}
}
}
impl ::std::str::FromStr for Scope {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"receive" => Ok(Self::Receive),
"converse" => Ok(Self::Converse),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for Scope {
type Error = self::error::ConversionError;
fn try_from(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<&::std::string::String> for Scope {
type Error = self::error::ConversionError;
fn try_from(
value: &::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
impl ::std::convert::TryFrom<::std::string::String> for Scope {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
/// Types for composing complex structures.
pub mod builder {
#[derive(Clone, Debug)]
pub struct ConsentSubject {
agent: ::std::result::Result<super::ConsentSubjectAgent, ::std::string::String>,
conversation_ref:
::std::result::Result<super::ConsentSubjectConversationRef, ::std::string::String>,
kind: ::std::result::Result<super::Kind, ::std::string::String>,
platform: ::std::result::Result<super::ConsentSubjectPlatform, ::std::string::String>,
}
impl ::std::default::Default for ConsentSubject {
fn default() -> Self {
Self {
agent: Err("no value supplied for agent".to_string()),
conversation_ref: Err("no value supplied for conversation_ref".to_string()),
kind: Err("no value supplied for kind".to_string()),
platform: Err("no value supplied for platform".to_string()),
}
}
}
impl ConsentSubject {
pub fn agent<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ConsentSubjectAgent>,
T::Error: ::std::fmt::Display,
{
self.agent = value
.try_into()
.map_err(|e| format!("error converting supplied value for agent: {e}"));
self
}
pub fn conversation_ref<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ConsentSubjectConversationRef>,
T::Error: ::std::fmt::Display,
{
self.conversation_ref = value
.try_into()
.map_err(|e| format!("error converting supplied value for conversation_ref: {e}"));
self
}
pub fn kind<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::Kind>,
T::Error: ::std::fmt::Display,
{
self.kind = value
.try_into()
.map_err(|e| format!("error converting supplied value for kind: {e}"));
self
}
pub fn platform<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ConsentSubjectPlatform>,
T::Error: ::std::fmt::Display,
{
self.platform = value
.try_into()
.map_err(|e| format!("error converting supplied value for platform: {e}"));
self
}
}
impl ::std::convert::TryFrom<ConsentSubject> for super::ConsentSubject {
type Error = super::error::ConversionError;
fn try_from(
value: ConsentSubject,
) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
agent: value.agent?,
conversation_ref: value.conversation_ref?,
kind: value.kind?,
platform: value.platform?,
})
}
}
impl ::std::convert::From<super::ConsentSubject> for ConsentSubject {
fn from(value: super::ConsentSubject) -> Self {
Self {
agent: Ok(value.agent),
conversation_ref: Ok(value.conversation_ref),
kind: Ok(value.kind),
platform: Ok(value.platform),
}
}
}
#[derive(Clone, Debug)]
pub struct Payload {
challenge: ::std::result::Result<
::std::option::Option<super::PayloadChallenge>,
::std::string::String,
>,
effect: ::std::result::Result<super::Effect, ::std::string::String>,
expires_at: ::std::result::Result<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
::std::string::String,
>,
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
scope: ::std::result::Result<::std::option::Option<super::Scope>, ::std::string::String>,
subject: ::std::result::Result<super::ConsentSubject, ::std::string::String>,
}
impl ::std::default::Default for Payload {
fn default() -> Self {
Self {
challenge: Ok(Default::default()),
effect: Err("no value supplied for effect".to_string()),
expires_at: Ok(Default::default()),
ext: Ok(Default::default()),
scope: Ok(Default::default()),
subject: Err("no value supplied for subject".to_string()),
}
}
}
impl Payload {
pub fn challenge<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::PayloadChallenge>>,
T::Error: ::std::fmt::Display,
{
self.challenge = value
.try_into()
.map_err(|e| format!("error converting supplied value for challenge: {e}"));
self
}
pub fn effect<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::Effect>,
T::Error: ::std::fmt::Display,
{
self.effect = value
.try_into()
.map_err(|e| format!("error converting supplied value for effect: {e}"));
self
}
pub fn expires_at<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<
::std::option::Option<::chrono::DateTime<::chrono::offset::Utc>>,
>,
T::Error: ::std::fmt::Display,
{
self.expires_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for expires_at: {e}"));
self
}
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn scope<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Scope>>,
T::Error: ::std::fmt::Display,
{
self.scope = value
.try_into()
.map_err(|e| format!("error converting supplied value for scope: {e}"));
self
}
pub fn subject<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ConsentSubject>,
T::Error: ::std::fmt::Display,
{
self.subject = value
.try_into()
.map_err(|e| format!("error converting supplied value for subject: {e}"));
self
}
}
impl ::std::convert::TryFrom<Payload> for super::Payload {
type Error = super::error::ConversionError;
fn try_from(value: Payload) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
challenge: value.challenge?,
effect: value.effect?,
expires_at: value.expires_at?,
ext: value.ext?,
scope: value.scope?,
subject: value.subject?,
})
}
}
impl ::std::convert::From<super::Payload> for Payload {
fn from(value: super::Payload) -> Self {
Self {
challenge: Ok(value.challenge),
effect: Ok(value.effect),
expires_at: Ok(value.expires_at),
ext: Ok(value.ext),
scope: Ok(value.scope),
subject: Ok(value.subject),
}
}
}
#[derive(Clone, Debug)]
pub struct Response {
ext: ::std::result::Result<::std::option::Option<super::Ext>, ::std::string::String>,
grant_id: ::std::result::Result<
::std::option::Option<::std::string::String>,
::std::string::String,
>,
reason: ::std::result::Result<
::std::option::Option<super::ResponseReason>,
::std::string::String,
>,
status: ::std::result::Result<super::ResponseStatus, ::std::string::String>,
}
impl ::std::default::Default for Response {
fn default() -> Self {
Self {
ext: Ok(Default::default()),
grant_id: Ok(Default::default()),
reason: Ok(Default::default()),
status: Err("no value supplied for status".to_string()),
}
}
}
impl Response {
pub fn ext<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::Ext>>,
T::Error: ::std::fmt::Display,
{
self.ext = value
.try_into()
.map_err(|e| format!("error converting supplied value for ext: {e}"));
self
}
pub fn grant_id<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<::std::string::String>>,
T::Error: ::std::fmt::Display,
{
self.grant_id = value
.try_into()
.map_err(|e| format!("error converting supplied value for grant_id: {e}"));
self
}
pub fn reason<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<::std::option::Option<super::ResponseReason>>,
T::Error: ::std::fmt::Display,
{
self.reason = value
.try_into()
.map_err(|e| format!("error converting supplied value for reason: {e}"));
self
}
pub fn status<T>(mut self, value: T) -> Self
where
T: ::std::convert::TryInto<super::ResponseStatus>,
T::Error: ::std::fmt::Display,
{
self.status = value
.try_into()
.map_err(|e| format!("error converting supplied value for status: {e}"));
self
}
}
impl ::std::convert::TryFrom<Response> for super::Response {
type Error = super::error::ConversionError;
fn try_from(value: Response) -> ::std::result::Result<Self, super::error::ConversionError> {
Ok(Self {
ext: value.ext?,
grant_id: value.grant_id?,
reason: value.reason?,
status: value.status?,
})
}
}
impl ::std::convert::From<super::Response> for Response {
fn from(value: super::Response) -> Self {
Self {
ext: Ok(value.ext),
grant_id: Ok(value.grant_id),
reason: Ok(value.reason),
status: Ok(value.status),
}
}
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/consent/decision/1.0";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\"$defs\":{\"ConsentSubject\":{\"additionalProperties\":false,\"description\":\"The platform-agnostic identifier of WHAT is being consented to: one conversation, for one agent.\",\"properties\":{\"agent\":{\"description\":\"VID (DID) of the AI agent the conversation would reach.\",\"minLength\":1,\"type\":\"string\"},\"conversationRef\":{\"description\":\"The bridge's OPAQUE conversation handle (e.g. \\\"sig-1a2b3c4d\\\"). NEVER the raw platform address — the VTA never learns the phone number / chat id.\",\"minLength\":1,\"type\":\"string\"},\"kind\":{\"$ref\":\"#/$defs/Kind\"},\"platform\":{\"description\":\"Messaging-platform tag, e.g. \\\"signal\\\", \\\"whatsapp\\\", \\\"slack\\\".\",\"minLength\":1,\"type\":\"string\"}},\"required\":[\"platform\",\"conversationRef\",\"kind\",\"agent\"],\"type\":\"object\"},\"Effect\":{\"description\":\"Whether the subject is permitted. The ABSENCE of any grant is treated as `deny` (default-deny).\",\"enum\":[\"allow\",\"deny\"],\"type\":\"string\"},\"Ext\":{\"additionalProperties\":true,\"description\":\"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\"minProperties\":1,\"propertyNames\":{\"pattern\":\"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"},\"title\":\"Ext\",\"type\":\"object\"},\"Kind\":{\"description\":\"The interaction kind: a 1:1 direct message, a multi-party group, or a broadcast channel.\",\"enum\":[\"dm\",\"group\",\"channel\"],\"type\":\"string\"},\"Response\":{\"$anchor\":\"response\",\"additionalProperties\":false,\"description\":\"Acknowledgement that the decision was recorded (or rejected).\",\"properties\":{\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"grantId\":{\"description\":\"The VTA's id for the recorded grant (set when recorded).\",\"type\":\"string\"},\"reason\":{\"description\":\"Required when status is `rejected`.\",\"maxLength\":1024,\"type\":\"string\"},\"status\":{\"description\":\"`recorded` = a grant was written. `rejected` = not accepted; `reason` MUST be set.\",\"enum\":[\"recorded\",\"rejected\"],\"type\":\"string\"}},\"required\":[\"status\"],\"title\":\"Consent Decision — response payload\",\"type\":\"object\"},\"Scope\":{\"description\":\"What the agent may do: `receive` = read inbound on this conversation; `converse` = read and reply.\",\"enum\":[\"receive\",\"converse\"],\"type\":\"string\"}},\"$id\":\"https://trusttasks.org/spec/consent/decision/1.0\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"additionalProperties\":false,\"description\":\"An approver allows or denies an AI agent's access to a messaging conversation.\",\"properties\":{\"challenge\":{\"description\":\"Echoes the consent/request challenge this decision answers. Omit only for an operator-initiated pre-authorization.\",\"minLength\":16,\"type\":\"string\"},\"effect\":{\"$ref\":\"#/$defs/Effect\"},\"expiresAt\":{\"description\":\"Optional grant TTL; after it the subject must be re-consented.\",\"format\":\"date-time\",\"type\":\"string\"},\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"scope\":{\"$ref\":\"#/$defs/Scope\",\"description\":\"Granted scope. REQUIRED when `effect` is `allow`.\"},\"subject\":{\"$ref\":\"#/$defs/ConsentSubject\"}},\"required\":[\"subject\",\"effect\"],\"title\":\"Consent Decision — payload\",\"type\":\"object\"}\n",
);
}
impl crate::Payload for Response {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/consent/decision/1.0#response";
const IS_PROOF_REQUIRED: bool = true;
const IS_ISSUED_AT_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
const PAYLOAD_SCHEMA: Option<&'static str> = Some(
"{\"$defs\":{\"ConsentSubject\":{\"additionalProperties\":false,\"description\":\"The platform-agnostic identifier of WHAT is being consented to: one conversation, for one agent.\",\"properties\":{\"agent\":{\"description\":\"VID (DID) of the AI agent the conversation would reach.\",\"minLength\":1,\"type\":\"string\"},\"conversationRef\":{\"description\":\"The bridge's OPAQUE conversation handle (e.g. \\\"sig-1a2b3c4d\\\"). NEVER the raw platform address — the VTA never learns the phone number / chat id.\",\"minLength\":1,\"type\":\"string\"},\"kind\":{\"$ref\":\"#/$defs/Kind\"},\"platform\":{\"description\":\"Messaging-platform tag, e.g. \\\"signal\\\", \\\"whatsapp\\\", \\\"slack\\\".\",\"minLength\":1,\"type\":\"string\"}},\"required\":[\"platform\",\"conversationRef\",\"kind\",\"agent\"],\"type\":\"object\"},\"Effect\":{\"description\":\"Whether the subject is permitted. The ABSENCE of any grant is treated as `deny` (default-deny).\",\"enum\":[\"allow\",\"deny\"],\"type\":\"string\"},\"Ext\":{\"additionalProperties\":true,\"description\":\"Vendor-namespaced extension object per SPEC.md §4.5.1. Each immediate key MUST be a reverse-DNS namespace; structure under each namespace is opaque to the framework.\",\"minProperties\":1,\"propertyNames\":{\"pattern\":\"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"},\"title\":\"Ext\",\"type\":\"object\"},\"Kind\":{\"description\":\"The interaction kind: a 1:1 direct message, a multi-party group, or a broadcast channel.\",\"enum\":[\"dm\",\"group\",\"channel\"],\"type\":\"string\"},\"Response\":{\"$anchor\":\"response\",\"additionalProperties\":false,\"description\":\"Acknowledgement that the decision was recorded (or rejected).\",\"properties\":{\"ext\":{\"$ref\":\"#/$defs/Ext\"},\"grantId\":{\"description\":\"The VTA's id for the recorded grant (set when recorded).\",\"type\":\"string\"},\"reason\":{\"description\":\"Required when status is `rejected`.\",\"maxLength\":1024,\"type\":\"string\"},\"status\":{\"description\":\"`recorded` = a grant was written. `rejected` = not accepted; `reason` MUST be set.\",\"enum\":[\"recorded\",\"rejected\"],\"type\":\"string\"}},\"required\":[\"status\"],\"title\":\"Consent Decision — response payload\",\"type\":\"object\"},\"Scope\":{\"description\":\"What the agent may do: `receive` = read inbound on this conversation; `converse` = read and reply.\",\"enum\":[\"receive\",\"converse\"],\"type\":\"string\"}},\"$ref\":\"#/$defs/Response\",\"$schema\":\"https://json-schema.org/draft/2020-12/schema\"}\n",
);
}
impl crate::RequestPayload for Payload {
type Response = Response;
}
/// The earlier `MAJOR.MINOR` of this slug that this version declares it
/// extends (front matter `extends`, SPEC §5.2 "Declared extension"), or
/// `None`. Only the direct declaration; walk a chain with
/// [`crate::extension::extends_for`].
pub const EXTENDS: Option<&str> = None;
/// The extended error codes this specification declares (SPEC §7.3 item 9,
/// §8.5), in declaration order. Empty when it declares none.
pub const ERROR_CODES: &[crate::DeclaredErrorCode] = &[
error_codes::NOT_AUTHORIZED,
error_codes::CHALLENGE_MISMATCH,
error_codes::SUBJECT_INVALID,
];
/// One constant per extended error code this specification declares
/// (SPEC §7.3 item 9), named for its local part.
///
/// Emit these rather than a string literal: the code is read from the
/// specification, so it cannot name a code the specification never
/// declared.
pub mod error_codes {
/// `consent/decision:notAuthorized`
///
/// The issuer is not an approver for this subject's platform/context.
///
/// Declared `retryable: false`.
pub const NOT_AUTHORIZED: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "consent/decision:notAuthorized",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `consent/decision:challengeMismatch`
///
/// The echoed challenge does not match any pending consent request for the subject.
///
/// Declared `retryable: false`.
pub const CHALLENGE_MISMATCH: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "consent/decision:challengeMismatch",
retryable: false,
details_schema: ::core::option::Option::None,
};
/// `consent/decision:subjectInvalid`
///
/// The subject is malformed or unknown.
///
/// Declared `retryable: false`.
pub const SUBJECT_INVALID: crate::DeclaredErrorCode = crate::DeclaredErrorCode {
code: "consent/decision:subjectInvalid",
retryable: false,
details_schema: ::core::option::Option::None,
};
}