Skip to main content

vv_agent/app_server/protocol/
mod.rs

1pub mod approval;
2pub mod errors;
3pub mod initialize;
4pub mod item;
5pub mod jsonrpc;
6pub mod model;
7pub mod schema;
8pub mod thread;
9pub mod turn;
10
11use schemars::JsonSchema;
12use serde::{Deserialize, Serialize};
13use ts_rs::TS;
14
15pub use approval::{ApprovalDecision, ApprovalRequestParams, ApprovalResolveParams};
16pub use initialize::{
17    AppClientCapabilities, AppClientInfo, AppServerCapabilities, AppServerInfo, InitializeParams,
18    InitializeResponse,
19};
20pub use item::{
21    map_run_event_to_notifications, AgentMessageDeltaParams, AppItem, AppItemKind, AppItemStatus,
22    ItemCompletedParams, ItemStartedParams, ToolCallDeltaParams,
23};
24pub use model::{AppModelInfo, ModelListParams, ModelListResponse};
25pub use schema::{
26    generate_app_server_json_schema_bundle, generate_app_server_typescript_bundle,
27    AppServerSchemaError, SchemaBundle, SchemaExportResponse,
28};
29pub use thread::{
30    AppThread, ThreadArchiveParams, ThreadArchiveResponse, ThreadArchivedParams, ThreadListParams,
31    ThreadListResponse, ThreadReadParams, ThreadReadResponse, ThreadResumeParams,
32    ThreadResumeResponse, ThreadStartParams, ThreadStartResponse, ThreadStartedParams,
33    ThreadStatus,
34};
35pub use turn::{
36    AppTokenUsage, AppTurn, TurnCompletedParams, TurnInterruptParams, TurnInterruptResponse,
37    TurnStartParams, TurnStartResponse, TurnStartedParams, TurnStatus, TurnSteerParams,
38    TurnSteerResponse, UserInput,
39};
40
41pub use errors::{AppServerError, AppServerErrorCode};
42pub use jsonrpc::{
43    JsonRpcError, JsonRpcErrorBody, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest,
44    JsonRpcResponse, RequestId,
45};
46
47#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, TS)]
48#[serde(tag = "method", content = "params")]
49pub enum ClientRequest {
50    #[serde(rename = "initialize")]
51    Initialize(InitializeParams),
52    #[serde(rename = "thread/start")]
53    ThreadStart(ThreadStartParams),
54    #[serde(rename = "thread/resume")]
55    ThreadResume(ThreadResumeParams),
56    #[serde(rename = "thread/read")]
57    ThreadRead(ThreadReadParams),
58    #[serde(rename = "thread/list")]
59    ThreadList(ThreadListParams),
60    #[serde(rename = "thread/archive")]
61    ThreadArchive(ThreadArchiveParams),
62    #[serde(rename = "turn/start")]
63    TurnStart(TurnStartParams),
64    #[serde(rename = "turn/interrupt")]
65    TurnInterrupt(TurnInterruptParams),
66    #[serde(rename = "turn/steer")]
67    TurnSteer(TurnSteerParams),
68    #[serde(rename = "approval/resolve")]
69    ApprovalResolve(ApprovalResolveParams),
70    #[serde(rename = "model/list")]
71    ModelList(ModelListParams),
72    #[serde(rename = "schema/export")]
73    SchemaExport,
74    #[serde(rename = "initialized")]
75    Initialized,
76}
77
78impl ClientRequest {
79    pub fn stable_method_names() -> Vec<&'static str> {
80        vec![
81            "initialize",
82            "thread/start",
83            "thread/resume",
84            "thread/read",
85            "thread/list",
86            "thread/archive",
87            "turn/start",
88            "turn/interrupt",
89            "turn/steer",
90            "approval/resolve",
91            "model/list",
92            "schema/export",
93            "initialized",
94        ]
95    }
96}
97
98#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, TS)]
99#[serde(tag = "method", content = "params")]
100pub enum ServerNotification {
101    #[serde(rename = "thread/started")]
102    ThreadStarted(ThreadStartedParams),
103    #[serde(rename = "thread/archived")]
104    ThreadArchived(ThreadArchivedParams),
105    #[serde(rename = "turn/started")]
106    TurnStarted(TurnStartedParams),
107    #[serde(rename = "turn/completed")]
108    TurnCompleted(TurnCompletedParams),
109    #[serde(rename = "item/started")]
110    ItemStarted(ItemStartedParams),
111    #[serde(rename = "item/agentMessage/delta")]
112    AgentMessageDelta(AgentMessageDeltaParams),
113    #[serde(rename = "item/toolCall/delta")]
114    ToolCallDelta(ToolCallDeltaParams),
115    #[serde(rename = "item/completed")]
116    ItemCompleted(ItemCompletedParams),
117    #[serde(rename = "approval/requested")]
118    ApprovalRequested(ApprovalRequestParams),
119    #[serde(rename = "approval/resolved")]
120    ApprovalResolved(ApprovalResolveParams),
121    #[serde(rename = "error/warning")]
122    ErrorWarning(WarningParams),
123}
124
125impl ServerNotification {
126    pub fn stable_method_names() -> Vec<&'static str> {
127        vec![
128            "thread/started",
129            "thread/archived",
130            "turn/started",
131            "turn/completed",
132            "item/started",
133            "item/agentMessage/delta",
134            "item/toolCall/delta",
135            "item/completed",
136            "approval/requested",
137            "approval/resolved",
138            "error/warning",
139        ]
140    }
141}
142
143#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, TS)]
144#[serde(tag = "method", content = "params")]
145pub enum ServerRequest {
146    #[serde(rename = "approval/request")]
147    ApprovalRequest(ApprovalRequestParams),
148}
149
150impl ServerRequest {
151    pub fn stable_method_names() -> Vec<&'static str> {
152        vec!["approval/request"]
153    }
154}
155
156#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, TS)]
157#[serde(rename_all = "camelCase")]
158pub struct WarningParams {
159    pub message: String,
160    #[serde(default, skip_serializing_if = "Option::is_none")]
161    pub code: Option<String>,
162}