//! JSON-RPC 2.0 protocol types.
use serde::{Deserialize, Serialize};
/// JSON-RPC request.
#[derive(Debug, Clone, Serialize)]
pub struct Request {
pub jsonrpc: &'static str,
pub id: u64,
pub method: String,
pub params: serde_json::Value,
}
impl Request {
pub fn new(id: u64, method: &str, params: serde_json::Value) -> Self {
Self {
jsonrpc: "2.0",
id,
method: method.to_string(),
params,
}
}
}
/// JSON-RPC response.
#[derive(Debug, Clone, Deserialize)]
pub struct Response {
pub jsonrpc: String,
pub id: Option<u64>,
#[serde(default)]
pub result: Option<serde_json::Value>,
#[serde(default)]
pub error: Option<RpcError>,
}
/// JSON-RPC error.
#[derive(Debug, Clone, Deserialize)]
pub struct RpcError {
pub code: i32,
pub message: String,
#[serde(default)]
pub data: Option<serde_json::Value>,
}
/// Transcription request parameters.
#[derive(Debug, Clone, Serialize)]
pub struct TranscribeParams {
/// Base64-encoded audio data
pub audio_b64: String,
/// Sample rate
pub sample_rate: u32,
}
/// Transcription result.
#[derive(Debug, Clone, Deserialize)]
pub struct TranscribeResult {
/// Transcribed text
pub text: String,
/// Detected emotion (if SER enabled)
#[serde(default)]
pub emotion: Option<String>,
/// Emotion confidence
#[serde(default)]
pub emotion_confidence: Option<f32>,
}
/// Speak request parameters.
#[derive(Debug, Clone, Serialize)]
pub struct SpeakParams {
/// Text to speak
pub text: String,
/// Voice/character name
#[serde(skip_serializing_if = "Option::is_none")]
pub voice: Option<String>,
/// Emotion to use
#[serde(skip_serializing_if = "Option::is_none")]
pub emotion: Option<String>,
}
/// Audio chunk notification (streamed from server).
#[derive(Debug, Clone, Deserialize)]
pub struct AudioChunkNotification {
/// Base64-encoded audio chunk
pub chunk_b64: String,
/// Sample rate
pub sample_rate: u32,
/// Is this the final chunk?
pub r#final: bool,
}
/// Chat request parameters.
#[derive(Debug, Clone, Serialize)]
pub struct ChatParams {
/// User message
pub message: String,
/// Detected emotion from user speech
#[serde(skip_serializing_if = "Option::is_none")]
pub user_emotion: Option<String>,
}
/// Chat response.
#[derive(Debug, Clone, Deserialize)]
pub struct ChatResult {
/// Assistant response
pub response: String,
/// Tokens used
#[serde(default)]
pub tokens_in: u32,
#[serde(default)]
pub tokens_out: u32,
}
/// Server status.
#[derive(Debug, Clone, Deserialize)]
pub struct ServerStatus {
/// Is server ready
pub ready: bool,
/// Loaded models
pub models: LoadedModels,
/// Current skill
pub skill: Option<String>,
}
/// Loaded models info.
#[derive(Debug, Clone, Deserialize)]
pub struct LoadedModels {
pub tts: Option<String>,
pub asr: Option<String>,
pub ser: Option<String>,
pub llm: Option<String>,
}
/// VAD (Voice Activity Detection) result.
#[derive(Debug, Clone, Deserialize)]
pub struct VadResult {
/// Is speech detected
pub is_speech: bool,
/// Average speech probability
pub probability: f32,
/// Maximum speech probability in the audio
pub max_probability: f32,
}
/// Skill info for listing.
#[derive(Debug, Clone, Deserialize)]
pub struct SkillInfo {
/// Skill ID
pub id: String,
/// Display name
pub name: String,
/// Description
pub description: String,
}
/// Skill list result.
#[derive(Debug, Clone, Deserialize)]
pub struct SkillListResult {
/// Available skills
pub skills: Vec<SkillInfo>,
}