From 9bb626f18c6b3052bafb026476bd27def64de3c1 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 8 Apr 2026 15:12:28 -0400 Subject: [PATCH] Strip api/types.rs to just Usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Killed Message, Role, ToolCall, FunctionCall, MessageContent, ContentPart, ImageUrl — all dead. types.rs is now 8 lines. Co-Authored-By: Proof of Concept --- src/agent/api/mod.rs | 3 +- src/agent/api/types.rs | 158 +---------------------------------------- src/agent/tools/mod.rs | 3 +- 3 files changed, 3 insertions(+), 161 deletions(-) diff --git a/src/agent/api/mod.rs b/src/agent/api/mod.rs index f3989df..d336816 100644 --- a/src/agent/api/mod.rs +++ b/src/agent/api/mod.rs @@ -10,8 +10,7 @@ pub mod http; mod types; mod openai; -// Transitional — these will go away as callers migrate to AstNode -pub use types::{Message, MessageContent, ContentPart, ImageUrl, Role, ToolCall, FunctionCall, Usage}; +pub use types::Usage; use anyhow::Result; use std::time::{Duration, Instant}; diff --git a/src/agent/api/types.rs b/src/agent/api/types.rs index 534cd63..8b000af 100644 --- a/src/agent/api/types.rs +++ b/src/agent/api/types.rs @@ -1,84 +1,4 @@ -// api/types.rs — API wire types -// -// Types that still exist here are transitional — they'll be killed -// as callers migrate to context_new::AstNode. - -use chrono::Utc; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct FunctionCall { - pub name: String, - pub arguments: String, -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct ToolCall { - pub id: String, - #[serde(rename = "type")] - pub call_type: String, - pub function: FunctionCall, -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(untagged)] -pub enum MessageContent { - Text(String), - Parts(Vec), -} - -impl MessageContent { - pub fn as_text(&self) -> &str { - match self { - MessageContent::Text(s) => s, - MessageContent::Parts(parts) => { - for part in parts { - if let ContentPart::Text { text } = part { - return text; - } - } - "" - } - } - } -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(tag = "type")] -pub enum ContentPart { - #[serde(rename = "text")] - Text { text: String }, - #[serde(rename = "image_url")] - ImageUrl { image_url: ImageUrl }, -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct ImageUrl { - pub url: String, -} - -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct Message { - pub role: Role, - pub content: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub tool_calls: Option>, - #[serde(skip_serializing_if = "Option::is_none")] - pub tool_call_id: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub name: Option, - #[serde(default, skip_serializing_if = "Option::is_none")] - pub timestamp: Option, -} - -#[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq)] -#[serde(rename_all = "lowercase")] -pub enum Role { - System, - User, - Assistant, - Tool, -} +use serde::Deserialize; #[derive(Debug, Clone, Deserialize)] pub struct Usage { @@ -86,79 +6,3 @@ pub struct Usage { pub completion_tokens: u32, pub total_tokens: u32, } - -impl Message { - pub fn content_text(&self) -> &str { - self.content.as_ref().map_or("", |c| c.as_text()) - } - - pub fn role_str(&self) -> &str { - match self.role { - Role::System => "system", - Role::User => "user", - Role::Assistant => "assistant", - Role::Tool => "tool", - } - } - - fn now() -> Option { - Some(Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true)) - } - - pub fn stamp(&mut self) { - if self.timestamp.is_none() { - self.timestamp = Self::now(); - } - } - - pub fn system(content: impl Into) -> Self { - Self { - role: Role::System, - content: Some(MessageContent::Text(content.into())), - tool_calls: None, tool_call_id: None, name: None, - timestamp: Self::now(), - } - } - - pub fn user(content: impl Into) -> Self { - Self { - role: Role::User, - content: Some(MessageContent::Text(content.into())), - tool_calls: None, tool_call_id: None, name: None, - timestamp: Self::now(), - } - } - - pub fn user_with_images(text: &str, image_data_uris: &[String]) -> Self { - let mut parts = vec![ContentPart::Text { text: text.to_string() }]; - for uri in image_data_uris { - parts.push(ContentPart::ImageUrl { - image_url: ImageUrl { url: uri.clone() }, - }); - } - Self { - role: Role::User, - content: Some(MessageContent::Parts(parts)), - tool_calls: None, tool_call_id: None, name: None, - timestamp: Self::now(), - } - } - - pub fn assistant(content: impl Into) -> Self { - Self { - role: Role::Assistant, - content: Some(MessageContent::Text(content.into())), - tool_calls: None, tool_call_id: None, name: None, - timestamp: Self::now(), - } - } - - pub fn tool_result(id: impl Into, content: impl Into) -> Self { - Self { - role: Role::Tool, - content: Some(MessageContent::Text(content.into())), - tool_calls: None, tool_call_id: Some(id.into()), name: None, - timestamp: Self::now(), - } - } -} diff --git a/src/agent/tools/mod.rs b/src/agent/tools/mod.rs index eef1eb4..a9bf65e 100644 --- a/src/agent/tools/mod.rs +++ b/src/agent/tools/mod.rs @@ -57,8 +57,7 @@ impl Tool { } } -// Re-export API wire types used by the agent turn loop -use super::api::ToolCall; + /// A tool call in flight — metadata for TUI + JoinHandle for /// result collection and cancellation.