Skip to main content

vtcode_desktop_protocol/
interaction.rs

1//! Runtime interaction request/response DTOs.
2
3use serde::{Deserialize, Serialize};
4
5/// Host hotkey signalled back to the service mid-interaction.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "snake_case")]
8pub enum InteractionHotkey {
9    /// Open the pending plan draft in the service-configured external editor.
10    LaunchEditor,
11}
12
13/// User response to a pending runtime interaction.
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct InteractionResponse {
17    /// Selected choice identities grouped by ordered wizard step.
18    #[serde(default)]
19    pub choice_id_groups: Vec<Vec<String>>,
20    /// Session owning the interaction.
21    pub session_id: String,
22    /// Turn that raised the interaction.
23    pub turn_id: String,
24    /// Opaque interaction identity provided by the service.
25    pub interaction_id: String,
26    /// Opaque choice identity provided by the service, if selecting an option.
27    pub choice_id: Option<String>,
28    /// Opaque identities selected for each step in a wizard interaction.
29    #[serde(default)]
30    pub choice_ids: Vec<String>,
31    /// Free-form answer for text questions.
32    pub text: Option<String>,
33    /// Free-form answers for each ordered wizard step.
34    #[serde(default)]
35    pub answer_texts: Vec<Option<String>>,
36    /// Whether the interaction was explicitly cancelled by the user.
37    #[serde(default)]
38    pub cancelled: bool,
39    /// Host hotkey signal for a mid-interaction action. `None` for ordinary
40    /// choice/cancel responses; `Some` asks the service to act mid-interaction
41    /// (e.g. open the plan editor) and follow up with a new request.
42    #[serde(default)]
43    pub hotkey: Option<InteractionHotkey>,
44}
45
46/// Interaction request sent from the service to the desktop client.
47#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
48#[serde(rename_all = "camelCase")]
49pub struct InteractionRequest {
50    /// Session owning the interaction.
51    pub session_id: String,
52    /// Turn that raised the interaction.
53    pub turn_id: String,
54    /// Opaque interaction identity.
55    pub interaction_id: String,
56    /// Kind of interaction required.
57    pub kind: InteractionKind,
58    /// Whether the runtime expects an ordered wizard response.
59    #[serde(default)]
60    pub wizard: bool,
61    /// Dialog title or question prompt.
62    pub title: String,
63    /// Supporting text shown by the client.
64    pub details: Vec<String>,
65    /// Available choices, preserving each runtime's opaque identity.
66    pub choices: Vec<InteractionChoice>,
67    /// Ordered multi-step questions when the runtime request is a wizard.
68    #[serde(default)]
69    pub steps: Vec<InteractionStep>,
70    /// Optional selected choice identity.
71    pub selected_choice_id: Option<String>,
72    /// Optional selected choice identities, one per wizard step.
73    #[serde(default)]
74    pub selected_choice_ids: Vec<String>,
75    /// Full plan markdown for `PlanApproval` prompts, normalized the same
76    /// way as the transcript copy. `None` for other kinds and for payloads
77    /// from older services; clients hide plan-expansion UI rather than
78    /// guessing.
79    #[serde(default)]
80    pub plan_markdown: Option<String>,
81}
82
83/// One ordered step in a question or approval wizard.
84#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
85#[serde(rename_all = "camelCase")]
86pub struct InteractionStep {
87    /// Allow independent checkbox selections.
88    #[serde(default)]
89    pub multi_select: bool,
90    /// Initially checked identities for this step.
91    #[serde(default)]
92    pub selected_choice_ids: Vec<String>,
93    /// Step label.
94    pub title: String,
95    /// Question or instruction for this step.
96    pub question: String,
97    /// Choices preserving exact service-issued identities.
98    pub choices: Vec<InteractionChoice>,
99    /// Optional selected identity.
100    pub selected_choice_id: Option<String>,
101    /// Whether the client may submit a free-form answer.
102    pub allow_freeform: bool,
103}
104
105/// Interaction category understood by native clients.
106#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
107#[serde(rename_all = "snake_case")]
108pub enum InteractionKind {
109    /// A tool or policy approval decision.
110    Approval,
111    /// Plan approval decision.
112    PlanApproval,
113    /// User-facing question requiring a response.
114    Question,
115    /// Non-security choice picker.
116    Choice,
117    /// Unsupported or informational transient request.
118    Other,
119}
120
121/// One display label paired with a stable opaque identity.
122#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
123#[serde(rename_all = "camelCase")]
124pub struct InteractionChoice {
125    /// Opaque identity returned unchanged by the client.
126    pub id: String,
127    /// User-facing label.
128    pub label: String,
129    /// Optional supporting description.
130    pub description: Option<String>,
131    /// Whether the service recommends this option.
132    pub recommended: bool,
133}