Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a new event type:dismiss. Add view_id and elapsed in event body. #1144

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion crates/tabby-common/src/api/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ use utoipa::ToSchema;

#[derive(Serialize, Deserialize, ToSchema, Clone, Debug)]
pub struct LogEventRequest {
/// Event type, should be `view` or `select`.
/// Event type, should be `view`, `select` or `dismiss`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use an enum to model this, or Discriminant<Event>? I believe I forgot to modify this comment when adding the Completion variant - using Discriminant<Event> would make it clear through the type system what this is, and not require updating the comment every time a new event is added.

Copy link
Member

@wsxiaoys wsxiaoys Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no need to modify this, completion event are not logged through this route. (they're part of logic in side /completion)

#[schema(example = "view")]
#[serde(rename = "type")]
pub event_type: String,

pub completion_id: String,

pub choice_index: u32,

pub view_id: Option<String>,

pub elapsed: Option<u32>,
}

#[derive(Serialize)]
Expand All @@ -31,13 +35,30 @@ pub enum Event {
View {
completion_id: String,
choice_index: u32,

#[serde(skip_serializing_if = "Option::is_none")]
view_id: Option<String>,
},
Select {
completion_id: String,
choice_index: u32,

#[serde(skip_serializing_if = "Option::is_none")]
kind: Option<SelectKind>,

#[serde(skip_serializing_if = "Option::is_none")]
view_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
elapsed: Option<u32>,
},
Dismiss {
completion_id: String,
choice_index: u32,

#[serde(skip_serializing_if = "Option::is_none")]
view_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
elapsed: Option<u32>,
},
Completion {
completion_id: String,
Expand Down
11 changes: 11 additions & 0 deletions crates/tabby/src/routes/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub async fn log_event(
logger.log(Event::View {
completion_id: request.completion_id,
choice_index: request.choice_index,
view_id: request.view_id,
});
StatusCode::OK
} else if request.event_type == "select" {
Expand All @@ -45,6 +46,16 @@ pub async fn log_event(
} else {
None
},
view_id: request.view_id,
elapsed: request.elapsed,
});
StatusCode::OK
} else if request.event_type == "dismiss" {
logger.log(Event::Dismiss {
completion_id: request.completion_id,
choice_index: request.choice_index,
view_id: request.view_id,
elapsed: request.elapsed,
});
StatusCode::OK
} else {
Expand Down
Loading