use ts_rs::TS;
use serde::{Deserialize, Serialize};
use crate::types::{JsonSchema, ToolDetails, ToolName};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
#[ts(export)]
pub struct ToolDefinition {
pub name: ToolName,
pub label: String,
pub description: String,
#[ts(type = "object")]
pub parameters: JsonSchema,
#[serde(rename = "execution_mode", default)]
pub execution_mode: ExecutionMode,
}
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, TS, Default)]
#[serde(rename_all = "snake_case")]
pub enum ExecutionMode {
#[default]
Parallel,
Sequential,
}
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, TS, Default)]
#[serde(rename_all = "snake_case")]
pub enum ToolExecutionMode {
#[default]
Parallel,
Sequential,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
pub struct ToolResult {
pub content: Vec<crate::message::Content>,
#[serde(skip_serializing_if = "Option::is_none")]
#[ts(type = "object | undefined")]
pub details: Option<ToolDetails>,
#[serde(skip_serializing_if = "Option::is_none")]
pub terminate: Option<bool>,
}
impl ToolResult {
pub fn text(text: impl Into<String>) -> Self {
Self {
content: vec![crate::message::Content::Text(crate::message::TextContent {
text: text.into(),
})],
details: None,
terminate: None,
}
}
pub fn partial_text(text: impl Into<String>) -> Self {
Self::text(text)
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS, thiserror::Error)]
#[error("tool error: {message}")]
pub struct ToolError {
pub code: String,
pub message: String,
#[serde(skip_serializing_if = "Option::is_none")]
#[ts(type = "object | undefined")]
pub details: Option<ToolDetails>,
}
impl ToolError {
pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self {
Self {
code: code.into(),
message: message.into(),
details: None,
}
}
}