use serde::{Deserialize, Serialize};
use vigil_types::ApprovalScope;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Capability {
Read,
Write,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "op", content = "args")]
#[non_exhaustive]
pub enum UiCommand {
ListRecentEvents(ListRecentEventsReq),
GetEventDetail(GetEventDetailReq),
FtsSearch(FtsSearchReq),
ListPendingApprovals(ListPendingApprovalsReq),
GetApprovalDetail(GetApprovalDetailReq),
ResolveApproval(ResolveApprovalReq),
ListPrivacyFindings(ListPrivacyFindingsReq),
ListSessions(ListSessionsReq),
ReplaySession(ReplaySessionReq),
VerifyChain,
ExportSessionReplay(ExportSessionReplayReq),
ListServers,
GetServerOnboarding(GetServerOnboardingReq),
ListPendingToolApprovals,
ListDriftedTools,
ListDriftedServers,
ApproveTool(ApproveToolReq),
ApproveToolDrift(ApproveToolDriftReq),
RejectToolDrift(RejectToolDriftReq),
ApproveServerCommandDrift(ApproveServerCommandDriftReq),
RejectServerCommandDrift(RejectServerCommandDriftReq),
ListSandboxProfiles,
GetSandboxProfile(GetSandboxProfileReq),
UpsertSandboxProfile(UpsertSandboxProfileReq),
BindServerSandboxProfile(BindServerSandboxProfileReq),
}
impl UiCommand {
pub fn required_capability(&self) -> Capability {
use UiCommand::*;
match self {
ListRecentEvents(_)
| GetEventDetail(_)
| FtsSearch(_)
| ListPendingApprovals(_)
| GetApprovalDetail(_)
| ListPrivacyFindings(_)
| ListSessions(_)
| ExportSessionReplay(_)
| ReplaySession(_)
| VerifyChain
| ListServers
| GetServerOnboarding(_)
| ListPendingToolApprovals
| ListDriftedTools
| ListDriftedServers
| ListSandboxProfiles
| GetSandboxProfile(_) => Capability::Read,
ResolveApproval(_)
| ApproveTool(_)
| ApproveToolDrift(_)
| RejectToolDrift(_)
| ApproveServerCommandDrift(_)
| RejectServerCommandDrift(_)
| UpsertSandboxProfile(_)
| BindServerSandboxProfile(_) => Capability::Write,
}
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
pub struct ListRecentEventsReq {
pub session_id: Option<String>,
pub event_type_filter: Option<Vec<String>>,
pub limit: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct GetEventDetailReq {
pub event_id: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct FtsSearchReq {
pub query: String,
pub limit: u32,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
pub struct ListPendingApprovalsReq {
pub session_id: Option<String>,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum ExportFormat {
Md,
Html,
}
impl ExportFormat {
pub fn mime(&self) -> &'static str {
match self {
ExportFormat::Md => "text/markdown; charset=utf-8",
ExportFormat::Html => "text/html; charset=utf-8",
}
}
pub fn extension(&self) -> &'static str {
match self {
ExportFormat::Md => "md",
ExportFormat::Html => "html",
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ExportSessionReplayReq {
pub session_id: String,
pub format: ExportFormat,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
pub struct ListPrivacyFindingsReq {
pub limit_recent_scans: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct GetApprovalDetailReq {
pub approval_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ResolveApprovalReq {
pub approval_id: String,
pub action: ApprovalAction,
pub scope: Option<ApprovalScope>,
pub resolved_by: String,
pub reason: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ApprovalAction {
Approve,
Deny,
Cancel,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
pub struct ListSessionsReq {
pub source: Option<String>,
pub limit: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ReplaySessionReq {
pub session_id: String,
pub verify: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct GetServerOnboardingReq {
pub server_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ApproveToolReq {
pub server_id: String,
pub tool_name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ApproveToolDriftReq {
pub server_id: String,
pub tool_name: String,
pub new_hash: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct RejectToolDriftReq {
pub server_id: String,
pub tool_name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct ApproveServerCommandDriftReq {
pub server_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct RejectServerCommandDriftReq {
pub server_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct GetSandboxProfileReq {
pub profile_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct UpsertSandboxProfileReq {
pub profile: vigil_runner_types::SandboxProfile,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct BindServerSandboxProfileReq {
pub server_id: String,
pub profile_id: Option<String>,
}