1use serde::{Deserialize, Serialize};
2use std::{fmt::Display, sync::Arc};
3use util::SemanticVersion;
4
5#[derive(Serialize, Deserialize, Debug)]
6pub struct EventRequestBody {
7 pub installation_id: Option<String>,
8 pub session_id: Option<String>,
9 pub is_staff: Option<bool>,
10 pub app_version: String,
11 pub os_name: String,
12 pub os_version: Option<String>,
13 pub architecture: String,
14 pub release_channel: Option<String>,
15 pub events: Vec<EventWrapper>,
16}
17
18impl EventRequestBody {
19 pub fn semver(&self) -> Option<SemanticVersion> {
20 self.app_version.parse().ok()
21 }
22}
23
24#[derive(Serialize, Deserialize, Debug)]
25pub struct EventWrapper {
26 pub signed_in: bool,
27 pub milliseconds_since_first_event: i64,
28 #[serde(flatten)]
29 pub event: Event,
30}
31
32#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
33#[serde(rename_all = "snake_case")]
34pub enum AssistantKind {
35 Panel,
36 Inline,
37}
38
39impl Display for AssistantKind {
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 write!(
42 f,
43 "{}",
44 match self {
45 Self::Panel => "panel",
46 Self::Inline => "inline",
47 }
48 )
49 }
50}
51
52#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
53#[serde(tag = "type")]
54pub enum Event {
55 Editor(EditorEvent),
56 Copilot(CopilotEvent),
57 Call(CallEvent),
58 Assistant(AssistantEvent),
59 Cpu(CpuEvent),
60 Memory(MemoryEvent),
61 App(AppEvent),
62 Setting(SettingEvent),
63 Extension(ExtensionEvent),
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 ExtensionEvent {
130 pub extension_id: Arc<str>,
131 pub version: Arc<str>,
132}
133
134#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
135pub struct AppEvent {
136 pub operation: String,
137}