diff --git a/crates/tabby-common/src/events.rs b/crates/tabby-common/src/events.rs index e239ca6..996cf31 100644 --- a/crates/tabby-common/src/events.rs +++ b/crates/tabby-common/src/events.rs @@ -33,6 +33,12 @@ pub struct Choice<'a> { pub text: &'a str, } +#[derive(Serialize)] +#[serde(rename_all = "snake_case")] +pub enum SelectKind { + Line, +} + #[derive(Serialize)] #[serde(rename_all = "snake_case")] pub enum Event<'a> { @@ -43,6 +49,8 @@ pub enum Event<'a> { Select { completion_id: &'a str, choice_index: u32, + #[serde(skip_serializing_if = "Option::is_none")] + kind: Option, }, Completion { completion_id: &'a str, diff --git a/crates/tabby/src/serve/events.rs b/crates/tabby/src/serve/events.rs index 8457497..7c1b4dd 100644 --- a/crates/tabby/src/serve/events.rs +++ b/crates/tabby/src/serve/events.rs @@ -1,7 +1,9 @@ -use axum::Json; +use std::collections::HashMap; + +use axum::{extract::Query, Json}; use hyper::StatusCode; use serde::{Deserialize, Serialize}; -use tabby_common::events; +use tabby_common::events::{self, SelectKind}; use utoipa::ToSchema; #[derive(Serialize, Deserialize, ToSchema, Clone, Debug)] @@ -27,7 +29,10 @@ pub struct LogEventRequest { (status = 400, description = "Bad Request") ) )] -pub async fn log_event(Json(request): Json) -> StatusCode { +pub async fn log_event( + Query(params): Query>, + Json(request): Json, +) -> StatusCode { if request.event_type == "view" { events::Event::View { completion_id: &request.completion_id, @@ -36,9 +41,18 @@ pub async fn log_event(Json(request): Json) -> StatusCode { .log(); StatusCode::OK } else if request.event_type == "select" { + let is_line = params + .get("select_kind") + .map(|x| x == "line") + .unwrap_or(false); events::Event::Select { completion_id: &request.completion_id, choice_index: request.choice_index, + kind: if is_line { + Some(SelectKind::Line) + } else { + None + }, } .log(); StatusCode::OK