-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprotocol.rs
More file actions
76 lines (68 loc) · 1.97 KB
/
protocol.rs
File metadata and controls
76 lines (68 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use serde::{Deserialize, Serialize};
use serde_json::Value;
/// A JSON-RPC 2.0 request.
#[derive(Debug, Serialize)]
pub struct JsonRpcRequest {
pub jsonrpc: &'static str,
pub id: u64,
pub method: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub params: Option<Value>,
}
impl JsonRpcRequest {
pub fn new(id: u64, method: impl Into<String>, params: Option<Value>) -> Self {
Self { jsonrpc: "2.0", id, method: method.into(), params }
}
}
/// A JSON-RPC 2.0 notification (no id).
#[derive(Debug, Serialize)]
pub struct JsonRpcNotification {
pub jsonrpc: &'static str,
pub method: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub params: Option<Value>,
}
impl JsonRpcNotification {
pub fn new(method: impl Into<String>, params: Option<Value>) -> Self {
Self { jsonrpc: "2.0", method: method.into(), params }
}
}
/// A JSON-RPC 2.0 response.
#[derive(Debug, Deserialize)]
pub struct JsonRpcResponse {
pub jsonrpc: String,
pub id: Option<u64>,
pub result: Option<Value>,
pub error: Option<JsonRpcError>,
}
#[derive(Debug, Deserialize)]
pub struct JsonRpcError {
pub code: i64,
pub message: String,
pub data: Option<Value>,
}
/// Agent turn events streamed from the agent server.
#[derive(Debug, Clone, Deserialize)]
#[serde(tag = "type")]
pub enum TurnEvent {
#[serde(rename = "text_delta")]
TextDelta { delta: String },
#[serde(rename = "tool_call")]
ToolCall { id: String, name: String, arguments: Value },
#[serde(rename = "tool_result")]
ToolResult { id: String, content: Value },
#[serde(rename = "turn_complete")]
TurnComplete { turn_id: String },
#[serde(rename = "error")]
Error { message: String },
#[serde(other)]
Unknown,
}
/// Result of a completed turn.
#[derive(Debug)]
pub enum TurnResult {
Complete,
NeedsToolResponse { tool_call_id: String, tool_name: String, arguments: Value },
Error(String),
AgentExited,
}