use std::path::PathBuf;
use serde_json::Value;
use tokio_util::sync::CancellationToken;
use crate::model::{ChatMessage, UserAttachment};
#[derive(Debug, Clone, PartialEq, Default)]
pub struct HarnessUsage {
pub input_tokens: u64,
pub output_tokens: u64,
pub cache_read_input_tokens: u64,
pub cache_creation_input_tokens: u64,
pub compaction_input_tokens: u64,
pub compaction_output_tokens: u64,
}
#[derive(Debug, Clone, PartialEq)]
pub enum HarnessInternalEvent {
AssistantTextChunk {
msg_id: String,
delta: String,
},
AssistantThinkingChunk {
msg_id: String,
delta: String,
},
ToolCall {
id: String,
name: String,
input: Value,
},
ToolResult {
id: String,
output: Result<Value, String>,
},
CompactionApplied {
original_message_count: usize,
compacted_message_count: usize,
original_tokens: u64,
compacted_tokens: u64,
},
TurnEnd {
stop_reason: String,
usage: Option<HarnessUsage>,
final_messages: Vec<ChatMessage>,
},
}
#[derive(Debug, Clone)]
pub struct NativeTurnInput {
pub prompt_text: String,
pub system_prompt: Option<String>,
pub attachments: Vec<UserAttachment>,
pub cancel_token: Option<CancellationToken>,
pub prior_messages: Vec<ChatMessage>,
pub context_path: Option<PathBuf>,
}
impl PartialEq for NativeTurnInput {
fn eq(&self, other: &Self) -> bool {
self.prompt_text == other.prompt_text
&& self.system_prompt == other.system_prompt
&& self.attachments == other.attachments
&& self.prior_messages == other.prior_messages
&& self.context_path == other.context_path
}
}
#[derive(Debug, thiserror::Error)]
pub enum NativeHarnessError {
#[error("native harness failed: {0}")]
Failed(String),
#[error("native harness event encode failed: {0}")]
Encode(String),
#[error("native harness channel closed")]
ChannelClosed,
#[error("model rate limit: {0}")]
ModelRateLimit(String),
#[error("model auth error: {0}")]
ModelAuth(String),
#[error("model context overflow: {0}")]
ModelContextOverflow(String),
#[error("model network error: {0}")]
ModelNetwork(String),
#[error("model bad request: {0}")]
ModelBadRequest(String),
#[error("model server error: {0}")]
ModelServerError(String),
#[error("model other error: {0}")]
ModelOther(String),
#[error("tool runtime error: {0}")]
ToolRuntime(String),
}