use crate::{ApiError, ClientError};
use std::fmt::Display;
#[derive(Debug, thiserror::Error)]
pub enum MessagesError {
#[error(transparent)]
ClientError(#[from] ClientError),
#[error(transparent)]
ApiError(#[from] ApiError),
#[error("Stream option mismatch")]
StreamOptionMismatch,
}
#[derive(Debug, thiserror::Error)]
pub enum StreamError {
#[error(transparent)]
ReqwestError(#[from] reqwest::Error),
#[error(transparent)]
StringDecodingError(#[from] std::string::FromUtf8Error),
#[error(transparent)]
MessageChunkTypeError(#[from] MessageChunkTypeError),
#[error("Parse chunk string error: {0}")]
ParseChunkStringError(String),
#[error(transparent)]
ChunkDataDeserializationError(#[from] serde_json::Error),
}
#[derive(Debug, thiserror::Error)]
pub struct MessageChunkTypeError {
pub chunk_type: String,
}
impl Display for MessageChunkTypeError {
fn fmt(
&self,
f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
write!(
f,
"Not supported message chunk type: {}",
self.chunk_type
)
}
}
#[derive(Debug, PartialEq, thiserror::Error)]
pub enum ContentFlatteningError {
#[error("The multiple content block is empty")]
Empty,
#[error("Not found target block")]
NotFoundTargetBlock,
}
#[derive(Debug, PartialEq, thiserror::Error)]
pub enum ImageMediaTypeParseError {
#[error("The extension is not supported: {0}")]
NotSupported(String),
#[error("Extension is not found")]
NotFound,
}
#[derive(Debug, PartialEq, thiserror::Error)]
pub enum ToolCallError {
#[error("Tool name mismatch")]
ToolNameMismatch,
#[error("Tool parameter not found: {0}")]
ParameterNotFound(String),
#[error("Tool parameter parse failed: {0}")]
ParameterParseFailed(String),
#[error("Tool not found: {0}")]
ToolNotFound(String),
}