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, 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,
31    ThreadClosedParams, ThreadListParams, ThreadListResponse, ThreadReadParams, ThreadReadResponse,
32    ThreadResumeParams, ThreadResumeResponse, ThreadStartParams, ThreadStartResponse,
33    ThreadStartedParams, ThreadStatus, ThreadStatusChangedParams, ThreadUnsubscribeParams,
34    ThreadUnsubscribeResponse,
35};
36pub use turn::{
37    AppCacheUsage, AppTokenUsage, AppTurn, CheckpointSummary, CheckpointSummaryStatus,
38    InterruptionIdempotencySupport, InterruptionOperationKind, InterruptionSummary,
39    TurnCompletedParams, TurnControlResponse, TurnFollowUpParams, TurnFollowUpResponse,
40    TurnInterruptParams, TurnInterruptResponse, TurnResumeParams, TurnResumeResponse,
41    TurnStartParams, TurnStartResponse, TurnStartedParams, TurnStatus, TurnSteerParams,
42    TurnSteerResponse, UserInput,
43};
44
45pub use errors::{AppServerError, AppServerErrorCode};
46pub use jsonrpc::{
47    JsonRpcError, JsonRpcErrorBody, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest,
48    JsonRpcResponse, RequestId,
49};
50
51#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, TS)]
52#[serde(tag = "method", content = "params")]
53pub enum ClientRequest {
54    #[serde(rename = "initialize")]
55    Initialize(InitializeParams),
56    #[serde(rename = "thread/start")]
57    ThreadStart(ThreadStartParams),
58    #[serde(rename = "thread/resume")]
59    ThreadResume(ThreadResumeParams),
60    #[serde(rename = "thread/read")]
61    ThreadRead(ThreadReadParams),
62    #[serde(rename = "thread/list")]
63    ThreadList(ThreadListParams),
64    #[serde(rename = "thread/archive")]
65    ThreadArchive(ThreadArchiveParams),
66    #[serde(rename = "thread/unsubscribe")]
67    ThreadUnsubscribe(ThreadUnsubscribeParams),
68    #[serde(rename = "turn/start")]
69    TurnStart(TurnStartParams),
70    #[serde(rename = "turn/resume")]
71    TurnResume(TurnResumeParams),
72    #[serde(rename = "turn/interrupt")]
73    TurnInterrupt(TurnInterruptParams),
74    #[serde(rename = "turn/steer")]
75    TurnSteer(TurnSteerParams),
76    #[serde(rename = "turn/followUp")]
77    TurnFollowUp(TurnFollowUpParams),
78    #[serde(rename = "approval/resolve")]
79    ApprovalResolve(ApprovalResolveParams),
80    #[serde(rename = "model/list")]
81    ModelList(ModelListParams),
82    #[serde(rename = "schema/export")]
83    SchemaExport,
84    #[serde(rename = "initialized")]
85    Initialized,
86}
87
88impl ClientRequest {
89    pub fn stable_method_names() -> Vec<&'static str> {
90        vec![
91            "initialize",
92            "thread/start",
93            "thread/resume",
94            "thread/read",
95            "thread/list",
96            "thread/archive",
97            "thread/unsubscribe",
98            "turn/start",
99            "turn/resume",
100            "turn/interrupt",
101            "turn/steer",
102            "turn/followUp",
103            "approval/resolve",
104            "model/list",
105            "schema/export",
106            "initialized",
107        ]
108    }
109}
110
111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, TS)]
112#[allow(clippy::large_enum_variant)] // Preserve the stable unboxed protocol enum API.
113#[serde(tag = "method", content = "params")]
114pub enum ServerNotification {
115    #[serde(rename = "thread/started")]
116    ThreadStarted(ThreadStartedParams),
117    #[serde(rename = "thread/archived")]
118    ThreadArchived(ThreadArchivedParams),
119    #[serde(rename = "thread/closed")]
120    ThreadClosed(ThreadClosedParams),
121    #[serde(rename = "thread/status/changed")]
122    ThreadStatusChanged(ThreadStatusChangedParams),
123    #[serde(rename = "turn/started")]
124    TurnStarted(TurnStartedParams),
125    #[serde(rename = "turn/completed")]
126    TurnCompleted(TurnCompletedParams),
127    #[serde(rename = "item/started")]
128    ItemStarted(ItemStartedParams),
129    #[serde(rename = "item/agentMessage/delta")]
130    AgentMessageDelta(AgentMessageDeltaParams),
131    #[serde(rename = "item/toolCall/delta")]
132    ToolCallDelta(ToolCallDeltaParams),
133    #[serde(rename = "item/completed")]
134    ItemCompleted(ItemCompletedParams),
135    #[serde(rename = "approval/requested")]
136    ApprovalRequested(ApprovalRequestParams),
137    #[serde(rename = "approval/resolved")]
138    ApprovalResolved(ApprovalResolveParams),
139    #[serde(rename = "error/warning")]
140    ErrorWarning(WarningParams),
141}
142
143impl ServerNotification {
144    pub fn stable_method_names() -> Vec<&'static str> {
145        vec![
146            "thread/started",
147            "thread/archived",
148            "thread/closed",
149            "thread/status/changed",
150            "turn/started",
151            "turn/completed",
152            "item/started",
153            "item/agentMessage/delta",
154            "item/toolCall/delta",
155            "item/completed",
156            "approval/requested",
157            "approval/resolved",
158            "error/warning",
159        ]
160    }
161}
162
163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, TS)]
164#[serde(tag = "method", content = "params")]
165pub enum ServerRequest {
166    #[serde(rename = "approval/request")]
167    ApprovalRequest(ApprovalRequestParams),
168}
169
170impl ServerRequest {
171    pub fn stable_method_names() -> Vec<&'static str> {
172        vec!["approval/request"]
173    }
174}
175
176#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, TS)]
177#[serde(rename_all = "camelCase")]
178pub struct WarningParams {
179    pub message: String,
180    #[serde(default, skip_serializing_if = "Option::is_none")]
181    pub code: Option<String>,
182}