1use semantic_version::SemanticVersion;
2use serde::{Deserialize, Serialize};
3use std::{fmt::Display, sync::Arc, time::Duration};
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 pub response_latency: Option<Duration>,
97 pub error_message: Option<String>,
98}
99
100#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
101pub struct CpuEvent {
102 pub usage_as_percentage: f32,
103 pub core_count: u32,
104}
105
106#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
107pub struct MemoryEvent {
108 pub memory_in_bytes: u64,
109 pub virtual_memory_in_bytes: u64,
110}
111
112#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
113pub struct ActionEvent {
114 pub source: String,
115 pub action: String,
116}
117
118#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
119pub struct EditEvent {
120 pub duration: i64,
121 pub environment: String,
122}
123
124#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
125pub struct SettingEvent {
126 pub setting: String,
127 pub value: String,
128}
129
130#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
131pub struct ExtensionEvent {
132 pub extension_id: Arc<str>,
133 pub version: Arc<str>,
134}
135
136#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
137pub struct AppEvent {
138 pub operation: String,
139}
140
141#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
142pub struct BacktraceFrame {
143 pub ip: usize,
144 pub symbol_addr: usize,
145 pub base: Option<usize>,
146 pub symbols: Vec<String>,
147}
148
149#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
150pub struct HangReport {
151 pub backtrace: Vec<BacktraceFrame>,
152 pub app_version: Option<SemanticVersion>,
153 pub os_name: String,
154 pub os_version: Option<SemanticVersion>,
155 pub architecture: String,
156 pub installation_id: Option<String>,
157}