1use serde::{Deserialize, Serialize};
11use vigil_types::ApprovalScope;
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
15#[serde(rename_all = "lowercase")]
16pub enum Capability {
17 Read,
19 Write,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
25#[serde(tag = "op", content = "args")]
26#[non_exhaustive]
27pub enum UiCommand {
28 ListRecentEvents(ListRecentEventsReq),
31 GetEventDetail(GetEventDetailReq),
33 FtsSearch(FtsSearchReq),
35
36 ListPendingApprovals(ListPendingApprovalsReq),
39 GetApprovalDetail(GetApprovalDetailReq),
41 ResolveApproval(ResolveApprovalReq),
43
44 ListPrivacyFindings(ListPrivacyFindingsReq),
47
48 ListSessions(ListSessionsReq),
51 ReplaySession(ReplaySessionReq),
53 VerifyChain,
55 ExportSessionReplay(ExportSessionReplayReq),
59
60 ListServers,
63 GetServerOnboarding(GetServerOnboardingReq),
65 ListPendingToolApprovals,
67 ListDriftedTools,
69 ListDriftedServers,
71 ApproveTool(ApproveToolReq),
73 ApproveToolDrift(ApproveToolDriftReq),
75 RejectToolDrift(RejectToolDriftReq),
77 ApproveServerCommandDrift(ApproveServerCommandDriftReq),
79 RejectServerCommandDrift(RejectServerCommandDriftReq),
81
82 ListSandboxProfiles,
85 GetSandboxProfile(GetSandboxProfileReq),
87 UpsertSandboxProfile(UpsertSandboxProfileReq),
89 BindServerSandboxProfile(BindServerSandboxProfileReq),
91}
92
93impl UiCommand {
94 pub fn required_capability(&self) -> Capability {
96 use UiCommand::*;
97 match self {
98 ListRecentEvents(_)
100 | GetEventDetail(_)
101 | FtsSearch(_)
102 | ListPendingApprovals(_)
103 | GetApprovalDetail(_)
104 | ListPrivacyFindings(_)
105 | ListSessions(_)
106 | ExportSessionReplay(_)
107 | ReplaySession(_)
108 | VerifyChain
109 | ListServers
110 | GetServerOnboarding(_)
111 | ListPendingToolApprovals
112 | ListDriftedTools
113 | ListDriftedServers
114 | ListSandboxProfiles
115 | GetSandboxProfile(_) => Capability::Read,
116 ResolveApproval(_)
118 | ApproveTool(_)
119 | ApproveToolDrift(_)
120 | RejectToolDrift(_)
121 | ApproveServerCommandDrift(_)
122 | RejectServerCommandDrift(_)
123 | UpsertSandboxProfile(_)
124 | BindServerSandboxProfile(_) => Capability::Write,
125 }
126 }
127}
128
129#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
133pub struct ListRecentEventsReq {
134 pub session_id: Option<String>,
136 pub event_type_filter: Option<Vec<String>>,
138 pub limit: u32,
140}
141
142#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
144pub struct GetEventDetailReq {
145 pub event_id: i64,
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
151pub struct FtsSearchReq {
152 pub query: String,
154 pub limit: u32,
156}
157
158#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
160pub struct ListPendingApprovalsReq {
161 pub session_id: Option<String>,
163}
164
165#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
169#[serde(rename_all = "lowercase")]
170pub enum ExportFormat {
171 Md,
173 Html,
175}
176
177impl ExportFormat {
178 pub fn mime(&self) -> &'static str {
180 match self {
181 ExportFormat::Md => "text/markdown; charset=utf-8",
182 ExportFormat::Html => "text/html; charset=utf-8",
183 }
184 }
185 pub fn extension(&self) -> &'static str {
187 match self {
188 ExportFormat::Md => "md",
189 ExportFormat::Html => "html",
190 }
191 }
192}
193
194#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
196pub struct ExportSessionReplayReq {
197 pub session_id: String,
199 pub format: ExportFormat,
201}
202
203#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
205pub struct ListPrivacyFindingsReq {
206 pub limit_recent_scans: u32,
209}
210
211#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
213pub struct GetApprovalDetailReq {
214 pub approval_id: String,
216}
217
218#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
220pub struct ResolveApprovalReq {
221 pub approval_id: String,
223 pub action: ApprovalAction,
225 pub scope: Option<ApprovalScope>,
227 pub resolved_by: String,
229 pub reason: Option<String>,
231}
232
233#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
235#[serde(rename_all = "lowercase")]
236pub enum ApprovalAction {
237 Approve,
239 Deny,
241 Cancel,
243}
244
245#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
247pub struct ListSessionsReq {
248 pub source: Option<String>,
250 pub limit: u32,
252}
253
254#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
256pub struct ReplaySessionReq {
257 pub session_id: String,
259 pub verify: bool,
261}
262
263#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
265pub struct GetServerOnboardingReq {
266 pub server_id: String,
268}
269
270#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
272pub struct ApproveToolReq {
273 pub server_id: String,
275 pub tool_name: String,
277}
278
279#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
281pub struct ApproveToolDriftReq {
282 pub server_id: String,
284 pub tool_name: String,
286 pub new_hash: String,
288}
289
290#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
292pub struct RejectToolDriftReq {
293 pub server_id: String,
295 pub tool_name: String,
297}
298
299#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
301pub struct ApproveServerCommandDriftReq {
302 pub server_id: String,
304}
305
306#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
308pub struct RejectServerCommandDriftReq {
309 pub server_id: String,
311}
312
313#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
315pub struct GetSandboxProfileReq {
316 pub profile_id: String,
318}
319
320#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
322pub struct UpsertSandboxProfileReq {
323 pub profile: vigil_runner_types::SandboxProfile,
325}
326
327#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
329pub struct BindServerSandboxProfileReq {
330 pub server_id: String,
332 pub profile_id: Option<String>,
334}