use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum RuntimeMode {
#[default]
Online,
Hybrid,
Offline,
}
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum ToolChoice {
#[default]
Auto,
Required,
None,
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(untagged)]
pub enum Input {
Text(String),
Message(Value),
Messages(Vec<Value>),
}
impl From<&str> for Input {
fn from(value: &str) -> Self {
Self::Text(value.to_owned())
}
}
impl From<String> for Input {
fn from(value: String) -> Self {
Self::Text(value)
}
}
impl From<Value> for Input {
fn from(value: Value) -> Self {
Self::Message(value)
}
}
impl From<Vec<Value>> for Input {
fn from(value: Vec<Value>) -> Self {
Self::Messages(value)
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct RoutingOptions {
pub strategy: Option<String>,
pub max_cost_usd: Option<f64>,
pub target_latency_ms: Option<u64>,
pub timeout_ms: Option<u64>,
#[serde(default)]
pub allowed_models: Vec<String>,
#[serde(default)]
pub allowed_providers: Vec<String>,
#[serde(default = "default_true")]
pub fallback: bool,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct VoiceOptions {
pub output_voice: Option<String>,
pub language: Option<String>,
pub turn_detection: Option<String>,
pub interruptible: Option<bool>,
pub input_format: Option<String>,
pub output_format: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct RuntimeResponse {
pub status: String,
#[serde(default)]
pub output: Value,
pub model: Option<String>,
#[serde(default)]
pub routing: Map<String, Value>,
#[serde(default)]
pub usage: Map<String, Value>,
#[serde(default)]
pub artifacts: Vec<Value>,
#[serde(default)]
pub agent: Map<String, Value>,
#[serde(flatten)]
pub extra: Map<String, Value>,
}
impl RuntimeResponse {
pub fn output_text(&self) -> Option<&str> {
self.output.as_str()
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct RunEvent {
#[serde(rename = "type")]
pub event_type: String,
pub delta: Option<String>,
#[serde(default)]
pub output: Value,
#[serde(default)]
pub data: Map<String, Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
pub struct AgentRun {
pub run_id: String,
pub agent_name: String,
pub parent_run_id: Option<String>,
pub relationship: String,
}
fn default_true() -> bool {
true
}