From f45c62af3620a5623fa575af0f45a0db406b3231 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Sun, 12 Nov 2023 21:03:46 -0800 Subject: [PATCH] refactor: extract events api --- crates/tabby/src/api/event.rs | 19 +++++++++++++++++++ crates/tabby/src/api/mod.rs | 2 ++ crates/tabby/src/routes/events.rs | 14 ++------------ crates/tabby/src/routes/health.rs | 7 ++----- crates/tabby/src/serve/mod.rs | 2 +- crates/tabby/src/services/health.rs | 3 +-- 6 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 crates/tabby/src/api/event.rs diff --git a/crates/tabby/src/api/event.rs b/crates/tabby/src/api/event.rs new file mode 100644 index 0000000..81193c9 --- /dev/null +++ b/crates/tabby/src/api/event.rs @@ -0,0 +1,19 @@ + + + + +use serde::{Deserialize, Serialize}; + +use utoipa::ToSchema; + +#[derive(Serialize, Deserialize, ToSchema, Clone, Debug)] +pub struct LogEventRequest { + /// Event type, should be `view` or `select`. + #[schema(example = "view")] + #[serde(rename = "type")] + pub event_type: String, + + pub completion_id: String, + + pub choice_index: u32, +} diff --git a/crates/tabby/src/api/mod.rs b/crates/tabby/src/api/mod.rs index 4c48d8b..b099be4 100644 --- a/crates/tabby/src/api/mod.rs +++ b/crates/tabby/src/api/mod.rs @@ -1,3 +1,5 @@ mod code; +mod event; pub use code::*; +pub use event::*; diff --git a/crates/tabby/src/routes/events.rs b/crates/tabby/src/routes/events.rs index 7c1b4dd..e509d15 100644 --- a/crates/tabby/src/routes/events.rs +++ b/crates/tabby/src/routes/events.rs @@ -2,21 +2,11 @@ use std::collections::HashMap; use axum::{extract::Query, Json}; use hyper::StatusCode; -use serde::{Deserialize, Serialize}; + use tabby_common::events::{self, SelectKind}; use utoipa::ToSchema; -#[derive(Serialize, Deserialize, ToSchema, Clone, Debug)] -pub struct LogEventRequest { - /// Event type, should be `view` or `select`. - #[schema(example = "view")] - #[serde(rename = "type")] - event_type: String, - - completion_id: String, - - choice_index: u32, -} +use crate::api::LogEventRequest; #[utoipa::path( post, diff --git a/crates/tabby/src/routes/health.rs b/crates/tabby/src/routes/health.rs index 410c334..3525490 100644 --- a/crates/tabby/src/routes/health.rs +++ b/crates/tabby/src/routes/health.rs @@ -1,10 +1,7 @@ -use std::{sync::Arc}; - +use std::sync::Arc; use axum::{extract::State, Json}; - - -use sysinfo::{SystemExt}; +use sysinfo::SystemExt; use utoipa::ToSchema; use crate::services::health; diff --git a/crates/tabby/src/serve/mod.rs b/crates/tabby/src/serve/mod.rs index 2d01e4c..0422764 100644 --- a/crates/tabby/src/serve/mod.rs +++ b/crates/tabby/src/serve/mod.rs @@ -41,7 +41,7 @@ Install following IDE / Editor extensions to get started with [Tabby](https://gi ), paths(routes::log_event, routes::completions, routes::completions, routes::health, routes::search), components(schemas( - routes::LogEventRequest, + api::LogEventRequest, completions::CompletionRequest, completions::CompletionResponse, completions::Segments, diff --git a/crates/tabby/src/services/health.rs b/crates/tabby/src/services/health.rs index 83dddfe..7db4cf4 100644 --- a/crates/tabby/src/services/health.rs +++ b/crates/tabby/src/services/health.rs @@ -1,7 +1,6 @@ -use std::{env::consts::ARCH}; +use std::env::consts::ARCH; use anyhow::Result; - use nvml_wrapper::Nvml; use serde::{Deserialize, Serialize}; use sysinfo::{CpuExt, System, SystemExt};