use super::{APIInputMessage, Role};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum OutputItem {
Message(OutputMessage),
#[serde(rename = "file_search_call")]
FileSearch(FileSearchCall),
FunctionCall(FunctionCall),
#[serde(rename = "web_search_call")]
WebSearchResults(WebSearchCall),
#[serde(rename = "computer_call")]
ComputerToolCall(ComputerToolCall),
Reasoning(Reasoning),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum InputItem {
#[serde(rename = "message")]
InputMessage(APIInputMessage),
#[serde(rename = "message")]
OutputMessage(OutputMessage),
#[serde(rename = "file_search_call")]
FileSearch(FileSearchCall),
#[serde(rename = "computer_call")]
ComputerToolCall(ComputerToolCall),
#[serde(rename = "computer_call_output")]
ComputerToolCallOutput(ComputerToolCallOutput),
#[serde(rename = "web_search_call")]
WebSearchResults(WebSearchCall),
FunctionCall(FunctionCall),
FunctionCallOutput(FunctionCallOutput),
Reasoning(Reasoning),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OutputMessage {
pub content: Vec<OutputContent>,
pub id: String,
pub role: Role,
pub status: MessageStatus,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum OutputContent {
#[serde(rename = "output_text")]
Text {
text: String,
annotations: Vec<Annotation>,
},
Refusal {
refusal: String,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Annotation {
FileCitation {
file_id: String,
index: u64,
},
#[serde(rename = "url_citation")]
URLCitation {
end_index: u64,
start_index: u64,
title: String,
url: String,
},
FilePath {
file_id: String,
index: u64,
},
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum MessageStatus {
InProgress,
Completed,
Incomplete,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileSearchCall {
pub id: String,
pub queries: Vec<String>,
pub status: FileSearchStatus,
pub results: Option<Vec<FileSearchResult>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileSearchResult {
pub attributes: HashMap<String, String>,
pub file_id: String,
pub filename: String,
pub score: f32,
pub text: String,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FileSearchStatus {
Completed,
InProgress,
Searching,
Incomplete,
Failed,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionCall {
pub arguments: String,
pub call_id: String,
pub id: String,
pub name: String,
pub status: FunctionCallStatus,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FunctionCallStatus {
InProgress,
Completed,
Incomplete,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionCallOutput {
pub id: Option<String>,
pub status: Option<FunctionCallStatus>,
pub call_id: String,
pub output: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WebSearchCall {
pub id: String,
pub status: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComputerToolCall {
pub action: ComputerAction,
pub call_id: String,
pub pending_safety_checks: Vec<SafetyCheck>,
pub status: ComputerCallStatus,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ComputerAction {
Click {
button: ClickButton,
x: u64,
y: u64,
},
DoubleClick {
x: u64,
y: u64,
},
Drag {
path: Vec<DragCoordinate>,
},
#[serde(rename = "keypress")]
KeyPress {
keys: Vec<String>,
},
Move {
x: u64,
y: u64,
},
Screenshot,
Scroll {
scroll_x: u64,
scroll_y: u64,
x: u64,
y: u64,
},
Type {
text: String,
},
Wait,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ClickButton {
Left,
Right,
Wheel,
Back,
Forward,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DragCoordinate {
pub x: u64,
pub y: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SafetyCheck {
pub code: String,
pub id: String,
pub message: String,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ComputerCallStatus {
InProgress,
Completed,
Incomplete,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComputerToolCallOutput {
pub id: Option<String>,
pub status: Option<ComputerCallStatus>,
pub call_id: String,
pub output: ComputerCallOutput,
pub acknowledged_safety_checks: Option<Vec<SafetyCheck>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ComputerCallOutput {
#[serde(rename = "computer_screenshot")]
Screenshot {
file_id: Option<String>,
image_url: Option<String>,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Reasoning {
pub id: String,
pub summary: Vec<ReasoningSummary>,
pub status: ReasoningStatus,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum ReasoningSummary {
#[serde(rename = "summary_text")]
Text {
text: String,
},
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ReasoningStatus {
InProgress,
Completed,
Incomplete,
}