Skip to content

Commit 335aec4

Browse files
committed
[WIP] SSE working
1 parent 4ad7ee1 commit 335aec4

File tree

6 files changed

+39
-47
lines changed

6 files changed

+39
-47
lines changed

rust-sdk/crates/ag-ui-client/src/http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<StateT: AgentState, FwdPropsT: FwdProps> Agent<StateT, FwdPropsT> for HttpA
5757
.await
5858
.map(|result| match result {
5959
Ok(event) => {
60-
trace!("Received event: {event:?}");
60+
// trace!("Received event: {event:?}");
6161
let event_data: Event<StateT> = serde_json::from_str(&event.data)?;
6262
trace!("Deserialized event: {event_data:?}");
6363
Ok(event_data)

rust-sdk/crates/ag-ui-client/src/sse.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use bytes::Bytes;
22
use futures::{Stream, StreamExt};
33
use reqwest::Response;
4-
use serde::de::DeserializeOwned;
54
use thiserror::Error;
65
use std::future::Future;
76

rust-sdk/crates/ag-ui-client/tests/http_agent_test.rs

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
use std::process::{Child, Command};
2-
use std::time::Duration;
3-
use std::thread::sleep;
4-
51
use ag_ui_client::HttpAgent;
62
use ag_ui_client::agent::{Agent, RunAgentParams};
73
use ag_ui_core::types::message::{Message, Role};
@@ -11,45 +7,11 @@ use reqwest::header::{HeaderMap, HeaderValue};
117
use serde_json::json;
128
use uuid::Uuid;
139

14-
struct ServerProcess {
15-
process: Child,
16-
}
17-
18-
impl ServerProcess {
19-
fn new() -> Self {
20-
// Start the Python server
21-
println!("Starting pydantic_ai_server.py...");
22-
23-
// Get the current directory
24-
let current_dir = std::env::current_dir().expect("Failed to get current directory");
25-
let script_path = current_dir.join("scripts").join("pydantic_ai_server.py");
26-
27-
println!("Script path: {:?}", script_path);
28-
29-
30-
let process = Command::new("uv")
31-
.args(["run", &script_path.to_str().unwrap()])
32-
.spawn()
33-
.expect("Failed to start pydantic_ai_server.py");
34-
35-
// Give the server some time to start up
36-
sleep(Duration::from_secs(5));
37-
38-
Self { process }
39-
}
40-
}
41-
42-
impl Drop for ServerProcess {
43-
fn drop(&mut self) {
44-
println!("Stopping pydantic_ai_server.py...");
45-
let _ = self.process.kill();
46-
}
47-
}
4810

4911
#[tokio::test]
5012
async fn test_http_agent_basic_functionality() {
5113
env_logger::init();
52-
14+
5315
// Create an HttpAgent
5416
let mut headers = HeaderMap::new();
5517
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
@@ -105,9 +67,6 @@ async fn test_http_agent_basic_functionality() {
10567

10668
#[tokio::test]
10769
async fn test_http_agent_tool_calls() {
108-
// Start the server
109-
let _server = ServerProcess::new();
110-
11170
// Create an HttpAgent
11271
let mut headers = HeaderMap::new();
11372
headers.insert("Content-Type", HeaderValue::from_static("application/json"));

rust-sdk/crates/ag-ui-core/src/types/ids.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::ops::Deref;
12
use serde::{Deserialize, Serialize};
23
use uuid::Uuid;
34

@@ -81,4 +82,37 @@ define_id_type!(AgentId);
8182
define_id_type!(ThreadId);
8283
define_id_type!(RunId);
8384
define_id_type!(MessageId);
84-
define_id_type!(ToolCallId);
85+
86+
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize, Clone)]
87+
pub struct ToolCallId(String);
88+
89+
90+
/// Tool Call ID
91+
///
92+
/// Does not follow UUID format, instead uses "call_xxxxxxxx"
93+
impl ToolCallId {
94+
pub fn random() -> Self {
95+
let uuid = &Uuid::new_v4().to_string()[..8];
96+
let id = format!("call_{uuid}");
97+
Self(id)
98+
}
99+
}
100+
101+
impl Deref for ToolCallId {
102+
type Target = str;
103+
fn deref(&self) -> &Self::Target {
104+
&self.0
105+
}
106+
}
107+
108+
#[cfg(test)]
109+
mod tests {
110+
// Test whether tool call ID has same format as rest of AG-UI
111+
#[test]
112+
fn test_tool_call_random() {
113+
let id = super::ToolCallId::random();
114+
assert_eq!(id.0.len(), 5 + 8);
115+
assert!(id.0.starts_with("call_"));
116+
dbg!(id);
117+
}
118+
}

rust-sdk/crates/ag-ui-core/src/types/message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct FunctionCall {
1010
}
1111

1212
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13-
#[serde(tag = "role", rename_all = "lowercase")]
13+
#[serde(rename_all = "lowercase")]
1414
pub enum Role {
1515
Developer,
1616
System,

rust-sdk/crates/ag-ui-core/tests/unit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ mod tests {
6666
arguments: "{}".to_string(),
6767
};
6868

69-
let tool_call = ToolCall::new(Uuid::new_v4(), function_call);
69+
let tool_call = ToolCall::new(ToolCallId::random(), function_call);
7070
assert_eq!(tool_call.call_type, "function");
7171
}
7272

0 commit comments

Comments
 (0)