Strip api/types.rs to just Usage
Killed Message, Role, ToolCall, FunctionCall, MessageContent, ContentPart, ImageUrl — all dead. types.rs is now 8 lines. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
39e6ae350d
commit
9bb626f18c
3 changed files with 3 additions and 161 deletions
|
|
@ -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};
|
||||
|
|
|
|||
|
|
@ -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<ContentPart>),
|
||||
}
|
||||
|
||||
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<MessageContent>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub tool_calls: Option<Vec<ToolCall>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub tool_call_id: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub name: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub timestamp: Option<String>,
|
||||
}
|
||||
|
||||
#[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<String> {
|
||||
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<String>) -> 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<String>) -> 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<String>) -> 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<String>, content: impl Into<String>) -> 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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue