use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::aws::{ConversationRole, Rest, StopReason};
use super::{
ContentBlockDelta, ContentBlockStart, ConverseMetrics, ConverseStreamTrace,
PerformanceConfiguration, ServiceTier, TokenUsage,
};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
pub enum ConverseStreamEvent {
MessageStart(MessageStartEvent),
ContentBlockStart(ContentBlockStartEvent),
ContentBlockDelta(ContentBlockDeltaEvent),
ContentBlockStop(ContentBlockStopEvent),
MessageStop(MessageStopEvent),
Metadata(Box<ConverseStreamMetadataEvent>),
InternalServerException(StreamException),
ModelStreamErrorException(ModelStreamErrorException),
ValidationException(StreamException),
ThrottlingException(StreamException),
ServiceUnavailableException(StreamException),
Unknown { event_type: String, payload: Value },
}
#[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
pub struct MessageStartEvent {
pub role: ConversationRole,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(gproxy_protocol_macros::WireBuilder)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
pub struct ContentBlockStartEvent {
pub start: ContentBlockStart,
pub content_block_index: u64,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(gproxy_protocol_macros::WireBuilder)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
pub struct ContentBlockDeltaEvent {
pub delta: ContentBlockDelta,
pub content_block_index: u64,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(gproxy_protocol_macros::WireBuilder)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
pub struct ContentBlockStopEvent {
pub content_block_index: u64,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(gproxy_protocol_macros::WireBuilder)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
pub struct MessageStopEvent {
pub stop_reason: StopReason,
#[serde(skip_serializing_if = "Option::is_none")]
pub additional_model_response_fields: Option<Value>,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(gproxy_protocol_macros::WireBuilder)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
pub struct ConverseStreamMetadataEvent {
pub usage: TokenUsage,
pub metrics: ConverseMetrics,
#[serde(skip_serializing_if = "Option::is_none")]
pub performance_config: Option<PerformanceConfiguration>,
#[serde(skip_serializing_if = "Option::is_none")]
pub service_tier: Option<ServiceTier>,
#[serde(skip_serializing_if = "Option::is_none")]
pub trace: Option<ConverseStreamTrace>,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
pub struct StreamException {
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[derive(gproxy_protocol_macros::WireBuilder)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
pub struct ModelStreamErrorException {
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub original_status_code: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none")]
pub original_message: Option<String>,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}