//! Generated by `trust-tasks-codegen` — do not edit by hand.
//!
//! Spec slug: `chat/message`. Version: `1.0`.
#[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())
}
}
}
///`AttachmentRef`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "object",
/// "required": [
/// "id",
/// "mediaType"
/// ],
/// "properties": {
/// "digest": {
/// "description": "OPTIONAL. Multihash digest of the attachment bytes, so the reference is itself verifiable and tamper-evident.",
/// "type": "string",
/// "minLength": 1
/// },
/// "filename": {
/// "description": "OPTIONAL. Suggested filename.",
/// "type": "string"
/// },
/// "id": {
/// "description": "Opaque attachment id, resolvable via the bridge's attachment fetch.",
/// "type": "string",
/// "minLength": 1
/// },
/// "mediaType": {
/// "description": "IANA media type (e.g. `image/jpeg`).",
/// "type": "string",
/// "minLength": 1
/// },
/// "sizeBytes": {
/// "description": "OPTIONAL. Size in bytes, if known ahead of fetch.",
/// "type": "integer",
/// "minimum": 0.0
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct AttachmentRef {
///OPTIONAL. Multihash digest of the attachment bytes, so the reference is itself verifiable and tamper-evident.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub digest: ::std::option::Option<AttachmentRefDigest>,
///OPTIONAL. Suggested filename.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub filename: ::std::option::Option<::std::string::String>,
///Opaque attachment id, resolvable via the bridge's attachment fetch.
pub id: AttachmentRefId,
///IANA media type (e.g. `image/jpeg`).
#[serde(rename = "mediaType")]
pub media_type: AttachmentRefMediaType,
///OPTIONAL. Size in bytes, if known ahead of fetch.
#[serde(
rename = "sizeBytes",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub size_bytes: ::std::option::Option<u64>,
}
///OPTIONAL. Multihash digest of the attachment bytes, so the reference is itself verifiable and tamper-evident.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "OPTIONAL. Multihash digest of the attachment bytes, so the reference is itself verifiable and tamper-evident.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct AttachmentRefDigest(::std::string::String);
impl ::std::ops::Deref for AttachmentRefDigest {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<AttachmentRefDigest> for ::std::string::String {
fn from(value: AttachmentRefDigest) -> Self {
value.0
}
}
impl ::std::str::FromStr for AttachmentRefDigest {
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 AttachmentRefDigest {
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 AttachmentRefDigest {
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 AttachmentRefDigest {
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 AttachmentRefDigest {
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())
})
}
}
///Opaque attachment id, resolvable via the bridge's attachment fetch.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Opaque attachment id, resolvable via the bridge's attachment fetch.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct AttachmentRefId(::std::string::String);
impl ::std::ops::Deref for AttachmentRefId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<AttachmentRefId> for ::std::string::String {
fn from(value: AttachmentRefId) -> Self {
value.0
}
}
impl ::std::str::FromStr for AttachmentRefId {
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 AttachmentRefId {
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 AttachmentRefId {
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 AttachmentRefId {
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 AttachmentRefId {
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())
})
}
}
///IANA media type (e.g. `image/jpeg`).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "IANA media type (e.g. `image/jpeg`).",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct AttachmentRefMediaType(::std::string::String);
impl ::std::ops::Deref for AttachmentRefMediaType {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<AttachmentRefMediaType> for ::std::string::String {
fn from(value: AttachmentRefMediaType) -> Self {
value.0
}
}
impl ::std::str::FromStr for AttachmentRefMediaType {
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 AttachmentRefMediaType {
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 AttachmentRefMediaType {
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 AttachmentRefMediaType {
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 AttachmentRefMediaType {
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())
})
}
}
///`ChainLink`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "object",
/// "required": [
/// "digest",
/// "id"
/// ],
/// "properties": {
/// "digest": {
/// "description": "Multihash digest (e.g. `sha-256`) over the previous document, so a gap, reorder, or removal in the chain is detectable.",
/// "type": "string",
/// "minLength": 1
/// },
/// "id": {
/// "description": "The `id` of the previous `chat/message` Trust Task document in this conversation.",
/// "type": "string",
/// "minLength": 1
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct ChainLink {
///Multihash digest (e.g. `sha-256`) over the previous document, so a gap, reorder, or removal in the chain is detectable.
pub digest: ChainLinkDigest,
///The `id` of the previous `chat/message` Trust Task document in this conversation.
pub id: ChainLinkId,
}
///Multihash digest (e.g. `sha-256`) over the previous document, so a gap, reorder, or removal in the chain is detectable.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Multihash digest (e.g. `sha-256`) over the previous document, so a gap, reorder, or removal in the chain is detectable.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ChainLinkDigest(::std::string::String);
impl ::std::ops::Deref for ChainLinkDigest {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ChainLinkDigest> for ::std::string::String {
fn from(value: ChainLinkDigest) -> Self {
value.0
}
}
impl ::std::str::FromStr for ChainLinkDigest {
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 ChainLinkDigest {
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 ChainLinkDigest {
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 ChainLinkDigest {
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 ChainLinkDigest {
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 `id` of the previous `chat/message` Trust Task document in this conversation.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "The `id` of the previous `chat/message` Trust Task document in this conversation.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct ChainLinkId(::std::string::String);
impl ::std::ops::Deref for ChainLinkId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<ChainLinkId> for ::std::string::String {
fn from(value: ChainLinkId) -> Self {
value.0
}
}
impl ::std::str::FromStr for ChainLinkId {
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 ChainLinkId {
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 ChainLinkId {
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 ChainLinkId {
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 ChainLinkId {
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())
})
}
}
///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.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "title": "Ext",
/// "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.",
/// "type": "object",
/// "minProperties": 1,
/// "additionalProperties": true,
/// "propertyNames": {
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
/// }
///}
/// ```
/// </details>
#[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`
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "type": "string",
/// "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9-]+)+$"
///}
/// ```
/// </details>
#[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())
})
}
}
///A conversational message exchanged between an AI agent and a messaging-platform bridge. Signed by its author (via the document `proof`) and hash-linked to the previous message in the conversation (`prev`), so a third party can verify each message's author and ordering after the transport has closed — for audit and dispute resolution. Conversations and contacts are referenced by opaque, bridge-issued handles, never raw platform addresses.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "$id": "https://trusttasks.org/spec/chat/message/1.0",
/// "title": "Payload",
/// "description": "A conversational message exchanged between an AI agent and a messaging-platform bridge. Signed by its author (via the document `proof`) and hash-linked to the previous message in the conversation (`prev`), so a third party can verify each message's author and ordering after the transport has closed — for audit and dispute resolution. Conversations and contacts are referenced by opaque, bridge-issued handles, never raw platform addresses.",
/// "type": "object",
/// "required": [
/// "conversationId",
/// "direction",
/// "sentAt"
/// ],
/// "properties": {
/// "attachments": {
/// "description": "OPTIONAL. Attachments carried by reference, never inline.",
/// "type": "array",
/// "items": {
/// "$ref": "#/definitions/AttachmentRef"
/// }
/// },
/// "conversationId": {
/// "description": "Opaque, bridge-issued conversation handle. MUST NOT be a raw platform address (phone number, chat id).",
/// "type": "string",
/// "minLength": 1
/// },
/// "direction": {
/// "description": "`inbound` = platform → agent (the bridge attests what it received and normalized); `outbound` = agent → platform (authored by the agent).",
/// "type": "string",
/// "enum": [
/// "inbound",
/// "outbound"
/// ]
/// },
/// "ext": {
/// "$ref": "#/definitions/Ext"
/// },
/// "platform": {
/// "description": "OPTIONAL. Platform key the message belongs to (e.g. `signal`, `whatsapp`). Advisory.",
/// "type": "string",
/// "minLength": 1
/// },
/// "prev": {
/// "description": "OPTIONAL on the first message in a conversation; present on every message thereafter. Links to the previous message so the conversation forms a verifiable, ordered chain.",
/// "$ref": "#/definitions/ChainLink"
/// },
/// "replyToId": {
/// "description": "OPTIONAL. The `id` of the message this one replies to.",
/// "type": "string",
/// "minLength": 1
/// },
/// "sentAt": {
/// "description": "RFC 3339 timestamp the author asserts for this message.",
/// "type": "string",
/// "format": "date-time"
/// },
/// "text": {
/// "description": "OPTIONAL. Plain-text body. Absent for attachment-only messages.",
/// "type": "string"
/// }
/// },
/// "additionalProperties": false
///}
/// ```
/// </details>
#[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct Payload {
///OPTIONAL. Attachments carried by reference, never inline.
#[serde(default, skip_serializing_if = "::std::vec::Vec::is_empty")]
pub attachments: ::std::vec::Vec<AttachmentRef>,
///Opaque, bridge-issued conversation handle. MUST NOT be a raw platform address (phone number, chat id).
#[serde(rename = "conversationId")]
pub conversation_id: PayloadConversationId,
///`inbound` = platform → agent (the bridge attests what it received and normalized); `outbound` = agent → platform (authored by the agent).
pub direction: PayloadDirection,
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub ext: ::std::option::Option<Ext>,
///OPTIONAL. Platform key the message belongs to (e.g. `signal`, `whatsapp`). Advisory.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub platform: ::std::option::Option<PayloadPlatform>,
///OPTIONAL on the first message in a conversation; present on every message thereafter. Links to the previous message so the conversation forms a verifiable, ordered chain.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub prev: ::std::option::Option<ChainLink>,
///OPTIONAL. The `id` of the message this one replies to.
#[serde(
rename = "replyToId",
default,
skip_serializing_if = "::std::option::Option::is_none"
)]
pub reply_to_id: ::std::option::Option<PayloadReplyToId>,
///RFC 3339 timestamp the author asserts for this message.
#[serde(rename = "sentAt")]
pub sent_at: ::chrono::DateTime<::chrono::offset::Utc>,
///OPTIONAL. Plain-text body. Absent for attachment-only messages.
#[serde(default, skip_serializing_if = "::std::option::Option::is_none")]
pub text: ::std::option::Option<::std::string::String>,
}
///Opaque, bridge-issued conversation handle. MUST NOT be a raw platform address (phone number, chat id).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "Opaque, bridge-issued conversation handle. MUST NOT be a raw platform address (phone number, chat id).",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadConversationId(::std::string::String);
impl ::std::ops::Deref for PayloadConversationId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadConversationId> for ::std::string::String {
fn from(value: PayloadConversationId) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadConversationId {
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 PayloadConversationId {
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 PayloadConversationId {
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 PayloadConversationId {
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 PayloadConversationId {
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())
})
}
}
///`inbound` = platform → agent (the bridge attests what it received and normalized); `outbound` = agent → platform (authored by the agent).
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "`inbound` = platform → agent (the bridge attests what it received and normalized); `outbound` = agent → platform (authored by the agent).",
/// "type": "string",
/// "enum": [
/// "inbound",
/// "outbound"
/// ]
///}
/// ```
/// </details>
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
)]
pub enum PayloadDirection {
#[serde(rename = "inbound")]
Inbound,
#[serde(rename = "outbound")]
Outbound,
}
impl ::std::fmt::Display for PayloadDirection {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
Self::Inbound => f.write_str("inbound"),
Self::Outbound => f.write_str("outbound"),
}
}
}
impl ::std::str::FromStr for PayloadDirection {
type Err = self::error::ConversionError;
fn from_str(value: &str) -> ::std::result::Result<Self, self::error::ConversionError> {
match value {
"inbound" => Ok(Self::Inbound),
"outbound" => Ok(Self::Outbound),
_ => Err("invalid value".into()),
}
}
}
impl ::std::convert::TryFrom<&str> for PayloadDirection {
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 PayloadDirection {
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 PayloadDirection {
type Error = self::error::ConversionError;
fn try_from(
value: ::std::string::String,
) -> ::std::result::Result<Self, self::error::ConversionError> {
value.parse()
}
}
///OPTIONAL. Platform key the message belongs to (e.g. `signal`, `whatsapp`). Advisory.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "OPTIONAL. Platform key the message belongs to (e.g. `signal`, `whatsapp`). Advisory.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadPlatform(::std::string::String);
impl ::std::ops::Deref for PayloadPlatform {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadPlatform> for ::std::string::String {
fn from(value: PayloadPlatform) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadPlatform {
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 PayloadPlatform {
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 PayloadPlatform {
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 PayloadPlatform {
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 PayloadPlatform {
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())
})
}
}
///OPTIONAL. The `id` of the message this one replies to.
///
/// <details><summary>JSON schema</summary>
///
/// ```json
///{
/// "description": "OPTIONAL. The `id` of the message this one replies to.",
/// "type": "string",
/// "minLength": 1
///}
/// ```
/// </details>
#[derive(::serde::Serialize, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[serde(transparent)]
pub struct PayloadReplyToId(::std::string::String);
impl ::std::ops::Deref for PayloadReplyToId {
type Target = ::std::string::String;
fn deref(&self) -> &::std::string::String {
&self.0
}
}
impl ::std::convert::From<PayloadReplyToId> for ::std::string::String {
fn from(value: PayloadReplyToId) -> Self {
value.0
}
}
impl ::std::str::FromStr for PayloadReplyToId {
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 PayloadReplyToId {
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 PayloadReplyToId {
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 PayloadReplyToId {
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 PayloadReplyToId {
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())
})
}
}
impl crate::Payload for Payload {
const TYPE_URI: &'static str = "https://trusttasks.org/spec/chat/message/1.0";
const IS_PROOF_REQUIRED: bool = true;
const IS_RECIPIENT_REQUIRED: bool = true;
}
#[cfg(feature = "validate")]
impl crate::validate::ValidatedPayload for Payload {
const SCHEMA_JSON: &'static str = "{\n \"$defs\": {\n \"AttachmentRef\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"digest\": {\n \"description\": \"OPTIONAL. Multihash digest of the attachment bytes, so the reference is itself verifiable and tamper-evident.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"filename\": {\n \"description\": \"OPTIONAL. Suggested filename.\",\n \"type\": \"string\"\n },\n \"id\": {\n \"description\": \"Opaque attachment id, resolvable via the bridge's attachment fetch.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"mediaType\": {\n \"description\": \"IANA media type (e.g. `image/jpeg`).\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"sizeBytes\": {\n \"description\": \"OPTIONAL. Size in bytes, if known ahead of fetch.\",\n \"minimum\": 0,\n \"type\": \"integer\"\n }\n },\n \"required\": [\n \"id\",\n \"mediaType\"\n ],\n \"type\": \"object\"\n },\n \"ChainLink\": {\n \"additionalProperties\": false,\n \"properties\": {\n \"digest\": {\n \"description\": \"Multihash digest (e.g. `sha-256`) over the previous document, so a gap, reorder, or removal in the chain is detectable.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"id\": {\n \"description\": \"The `id` of the previous `chat/message` Trust Task document in this conversation.\",\n \"minLength\": 1,\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"id\",\n \"digest\"\n ],\n \"type\": \"object\"\n },\n \"Ext\": {\n \"additionalProperties\": true,\n \"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.\",\n \"minProperties\": 1,\n \"propertyNames\": {\n \"pattern\": \"^[a-z][a-z0-9-]*(\\\\.[a-z0-9-]+)+$\"\n },\n \"title\": \"Ext\",\n \"type\": \"object\"\n }\n },\n \"$id\": \"https://trusttasks.org/spec/chat/message/1.0\",\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"additionalProperties\": false,\n \"description\": \"A conversational message exchanged between an AI agent and a messaging-platform bridge. Signed by its author (via the document `proof`) and hash-linked to the previous message in the conversation (`prev`), so a third party can verify each message's author and ordering after the transport has closed — for audit and dispute resolution. Conversations and contacts are referenced by opaque, bridge-issued handles, never raw platform addresses.\",\n \"properties\": {\n \"attachments\": {\n \"description\": \"OPTIONAL. Attachments carried by reference, never inline.\",\n \"items\": {\n \"$ref\": \"#/$defs/AttachmentRef\"\n },\n \"type\": \"array\"\n },\n \"conversationId\": {\n \"description\": \"Opaque, bridge-issued conversation handle. MUST NOT be a raw platform address (phone number, chat id).\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"direction\": {\n \"description\": \"`inbound` = platform → agent (the bridge attests what it received and normalized); `outbound` = agent → platform (authored by the agent).\",\n \"enum\": [\n \"inbound\",\n \"outbound\"\n ],\n \"type\": \"string\"\n },\n \"ext\": {\n \"$ref\": \"#/$defs/Ext\"\n },\n \"platform\": {\n \"description\": \"OPTIONAL. Platform key the message belongs to (e.g. `signal`, `whatsapp`). Advisory.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"prev\": {\n \"$ref\": \"#/$defs/ChainLink\",\n \"description\": \"OPTIONAL on the first message in a conversation; present on every message thereafter. Links to the previous message so the conversation forms a verifiable, ordered chain.\"\n },\n \"replyToId\": {\n \"description\": \"OPTIONAL. The `id` of the message this one replies to.\",\n \"minLength\": 1,\n \"type\": \"string\"\n },\n \"sentAt\": {\n \"description\": \"RFC 3339 timestamp the author asserts for this message.\",\n \"format\": \"date-time\",\n \"type\": \"string\"\n },\n \"text\": {\n \"description\": \"OPTIONAL. Plain-text body. Absent for attachment-only messages.\",\n \"type\": \"string\"\n }\n },\n \"required\": [\n \"conversationId\",\n \"direction\",\n \"sentAt\"\n ],\n \"title\": \"Chat Message — payload\",\n \"type\": \"object\"\n}\n";
}
#[cfg(test)]
mod conformance {
//! Round-trip tests harvested from the spec's `spec.md`,
//! plus a `rejects_invalid_examples` test for any fixtures
//! in `payload.invalid-examples.json` (validate feature).
/// Each fixture in `payload.invalid-examples.json` MUST be
/// rejected by at least one of: serde deserialization, or
/// JSON-Schema validation under the `validate` feature. The
/// fixture file documents the producer-side bug class that
/// each payload exemplifies; this generated test pins it.
#[cfg(feature = "validate")]
#[test]
fn rejects_invalid_examples() {
use crate::validate::ValidatedPayload;
let fixtures: &[(&str, &str)] = &[
(
"Empty payload omits required member(s): conversationId, direction, sentAt.",
"{}",
),
(
"Unknown top-level member is rejected (additionalProperties: false).",
"{\n \"__notARealMember__\": true,\n \"conversationId\": \"c-1\",\n \"direction\": \"outbound\",\n \"sentAt\": \"2026-06-16T00:00:00Z\"\n}",
),
(
"`direction` must be one of the enum values (inbound | outbound).",
"{\n \"conversationId\": \"c-1\",\n \"direction\": \"sideways\",\n \"sentAt\": \"2026-06-16T00:00:00Z\"\n}",
),
(
"`conversationId` has the wrong type (expected string).",
"{\n \"conversationId\": 12345,\n \"direction\": \"inbound\",\n \"sentAt\": \"2026-06-16T00:00:00Z\"\n}",
),
(
"`prev` is missing its required `digest` (an unverifiable chain link is rejected).",
"{\n \"conversationId\": \"c-1\",\n \"direction\": \"outbound\",\n \"prev\": {\n \"id\": \"urn:uuid:prev\"\n },\n \"sentAt\": \"2026-06-16T00:00:00Z\"\n}",
),
(
"An attachment reference omits the required `mediaType`.",
"{\n \"attachments\": [\n {\n \"id\": \"att-1\"\n }\n ],\n \"conversationId\": \"c-1\",\n \"direction\": \"inbound\",\n \"sentAt\": \"2026-06-16T00:00:00Z\"\n}",
),
];
for (i, (note, raw)) in fixtures.iter().enumerate() {
let value: serde_json::Value = match serde_json::from_str(raw) {
Ok(v) => v,
Err(_) => continue,
};
let serde_ok = serde_json::from_value::<super::Payload>(value.clone()).is_ok();
let schema_ok = super::Payload::validate_value(&value).is_ok();
assert!(
!(serde_ok && schema_ok),
"invalid-example #{} ({:?}) was accepted by both serde and JSON Schema; \
the fixture's stated failure class is no longer caught:\n{}",
i + 1,
note,
raw
);
}
}
}