1use std::fmt::Display;
2
3use serde::{Deserialize, Serialize};
4use util::SemanticVersion;
5
6#[derive(Serialize, Deserialize, Debug)]
7pub struct EventRequestBody {
8 pub installation_id: Option<String>,
9 pub session_id: Option<String>,
10 pub is_staff: Option<bool>,
11 pub app_version: String,
12 pub os_name: String,
13 pub os_version: Option<String>,
14 pub architecture: String,
15 pub release_channel: Option<String>,
16 pub events: Vec<EventWrapper>,
17}
18
19impl EventRequestBody {
20 pub fn semver(&self) -> Option<SemanticVersion> {
21 self.app_version.parse().ok()
22 }
23}
24
25#[derive(Serialize, Deserialize, Debug)]
26pub struct EventWrapper {
27 pub signed_in: bool,
28 pub milliseconds_since_first_event: i64,
29 #[serde(flatten)]
30 pub event: Event,
31}
32
33#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
34#[serde(rename_all = "snake_case")]
35pub enum AssistantKind {
36 Panel,
37 Inline,
38}
39
40impl Display for AssistantKind {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 write!(
43 f,
44 "{}",
45 match self {
46 Self::Panel => "panel",
47 Self::Inline => "inline",
48 }
49 )
50 }
51}
52
53#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
54#[serde(tag = "type")]
55pub enum Event {
56 Editor(EditorEvent),
57 Copilot(CopilotEvent),
58 Call(CallEvent),
59 Assistant(AssistantEvent),
60 Cpu(CpuEvent),
61 Memory(MemoryEvent),
62 App(AppEvent),
63 Setting(SettingEvent),
64 Edit(EditEvent),
65 Action(ActionEvent),
66}
67
68#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
69pub struct EditorEvent {
70 pub operation: String,
71 pub file_extension: Option<String>,
72 pub vim_mode: bool,
73 pub copilot_enabled: bool,
74 pub copilot_enabled_for_language: bool,
75}
76
77#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
78pub struct CopilotEvent {
79 pub suggestion_id: Option<String>,
80 pub suggestion_accepted: bool,
81 pub file_extension: Option<String>,
82}
83
84#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
85pub struct CallEvent {
86 pub operation: String,
87 pub room_id: Option<u64>,
88 pub channel_id: Option<u64>,
89}
90
91#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
92pub struct AssistantEvent {
93 pub conversation_id: Option<String>,
94 pub kind: AssistantKind,
95 pub model: String,
96}
97
98#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
99pub struct CpuEvent {
100 pub usage_as_percentage: f32,
101 pub core_count: u32,
102}
103
104#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
105pub struct MemoryEvent {
106 pub memory_in_bytes: u64,
107 pub virtual_memory_in_bytes: u64,
108}
109
110#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
111pub struct ActionEvent {
112 pub source: String,
113 pub action: String,
114}
115
116#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
117pub struct EditEvent {
118 pub duration: i64,
119 pub environment: String,
120}
121
122#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
123pub struct SettingEvent {
124 pub setting: String,
125 pub value: String,
126}
127
128#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
129pub struct AppEvent {
130 pub operation: String,
131}