use serde_json::Value;
use std::pin::Pin;
use vtcode_computer_use::Action;
use super::{FinishReason, LLMError, ToolCall, Usage};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NativeProvider {
OpenAi,
Anthropic,
}
impl NativeProvider {
fn as_str(self) -> &'static str {
match self {
Self::OpenAi => "openai",
Self::Anthropic => "anthropic",
}
}
}
pub struct NativeCall {
pub id: String,
pub provider: NativeProvider,
pub index: usize,
pub body: NativeCallBody,
}
pub enum NativeCallBody {
OpenAi {
replay_item: Value,
actions: Vec<Action>,
},
Anthropic {
name: String,
action: Result<Action, String>,
},
}
pub struct NativeResponse {
pub content: Option<String>,
pub model: String,
pub usage: Option<Usage>,
pub finish_reason: FinishReason,
pub reasoning: Option<String>,
pub tool_calls: Vec<ToolCall>,
pub native_calls: Vec<NativeCall>,
pub assistant_blocks: Vec<Value>,
pub request_id: Option<String>,
pub organization_id: Option<String>,
}
impl std::fmt::Debug for NativeCall {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let body = match &self.body {
NativeCallBody::OpenAi { actions, .. } => format!("openai:{}actions", actions.len()),
NativeCallBody::Anthropic { name, action } => {
format!("anthropic:{name}:{}", if action.is_ok() { "valid" } else { "invalid" })
}
};
f.debug_struct("NativeCall")
.field("id", &self.id)
.field("provider", &self.provider.as_str())
.field("index", &self.index)
.field("body", &body)
.finish()
}
}
impl std::fmt::Debug for NativeResponse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("NativeResponse")
.field("model", &self.model)
.field("finish_reason", &self.finish_reason)
.field("usage", &self.usage)
.field("tool_call_ids", &self.tool_calls.iter().map(|call| call.id.as_str()).collect::<Vec<_>>())
.field("native_calls", &self.native_calls)
.finish()
}
}
pub enum NativeStreamEvent {
TextDelta {
delta: String,
},
ReasoningDelta {
delta: String,
},
Completed(Box<NativeResponse>),
}
impl std::fmt::Debug for NativeStreamEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::TextDelta { delta } => f.debug_struct("TextDelta").field("bytes", &delta.len()).finish(),
Self::ReasoningDelta { delta } => f.debug_struct("ReasoningDelta").field("bytes", &delta.len()).finish(),
Self::Completed(response) => f.debug_tuple("Completed").field(response).finish(),
}
}
}
pub type NativeStream = Pin<Box<dyn futures::Stream<Item = Result<NativeStreamEvent, LLMError>> + Send>>;