1use serde::{Deserialize, Serialize};
4
5#[non_exhaustive]
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7#[serde(tag = "role")]
8pub enum Message {
9 #[serde(rename = "user")]
10 User(UserMessage),
11 #[serde(rename = "assistant")]
12 Assistant(AssistantMessage),
13 #[serde(rename = "tool_result")]
14 ToolResult(ToolResultMessage),
15}
16
17#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
18pub struct UserMessage {
19 pub content: Vec<InputContent>,
20 pub timestamp_ms: i64,
21}
22
23#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
24pub struct AssistantMessage {
25 pub content: Vec<AssistantContent>,
26 pub api: crate::ApiKind,
27 pub provider: String,
28 pub model: String,
29 pub response_model: Option<String>,
30 pub response_id: Option<String>,
31 pub usage: crate::stream::Usage,
32 pub stop_reason: crate::stream::StopReason,
33 pub error_message: Option<String>,
34 pub timestamp_ms: i64,
35}
36
37#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
38pub struct ToolResultMessage {
39 pub tool_call_id: String,
40 pub tool_name: String,
41 pub content: Vec<OutputContent>,
42 pub details: Option<serde_json::Value>,
43 pub is_error: bool,
44 pub timestamp_ms: i64,
45}
46
47#[non_exhaustive]
48#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
49#[serde(tag = "type")]
50pub enum InputContent {
51 #[serde(rename = "text")]
52 Text { text: String },
53}
54
55#[non_exhaustive]
56#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
57#[serde(tag = "type")]
58pub enum AssistantContent {
59 #[serde(rename = "text")]
60 Text { text: String },
61 #[serde(rename = "thinking")]
62 Thinking { thinking: String },
63 #[serde(rename = "tool_call")]
64 ToolCall { tool_call: ToolCall },
65}
66
67#[non_exhaustive]
68#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
69#[serde(tag = "type")]
70pub enum OutputContent {
71 #[serde(rename = "text")]
72 Text { text: String },
73}
74
75#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
76pub struct ToolCall {
77 pub id: String,
78 pub name: String,
79 pub arguments: String,
80}
81
82#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
83pub struct ToolDef {
84 pub name: String,
85 pub description: String,
86 pub input_schema: serde_json::Value,
87}