Skip to content

Commit 4ca1b78

Browse files
refactor(transcribe-proxy): typed PipelineStatus and extract parse_keywords (#3984)
- Add PipelineStatus enum (Processing, Done, Error) replacing string literals - Add QueryParams::parse_keywords() for keyword/kwargs parsing - Use parse_keywords in batch and streaming routes Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent fb187b2 commit 4ca1b78

File tree

7 files changed

+38
-44
lines changed

7 files changed

+38
-44
lines changed

crates/transcribe-proxy/src/query_params.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ impl QueryParams {
7777
})
7878
.unwrap_or_default()
7979
}
80+
81+
pub fn parse_keywords(&self) -> Vec<String> {
82+
self.get("keyword")
83+
.or_else(|| self.get("keywords"))
84+
.map(|v| {
85+
v.iter()
86+
.flat_map(|s| s.split(','))
87+
.map(|k| k.trim().to_string())
88+
.collect()
89+
})
90+
.unwrap_or_default()
91+
}
8092
}
8193

8294
impl Deref for QueryParams {

crates/transcribe-proxy/src/routes/batch.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use owhisper_interface::batch::Response as BatchResponse;
1919

2020
use crate::hyprnote_routing::{RetryConfig, is_retryable_error, should_use_hyprnote_routing};
2121
use crate::provider_selector::SelectedProvider;
22-
use crate::query_params::{QueryParams, QueryValue};
22+
use crate::query_params::QueryParams;
2323

2424
use super::AppState;
2525

@@ -204,22 +204,10 @@ async fn transcribe_with_retry(
204204
}
205205

206206
fn build_listen_params(params: &QueryParams) -> ListenParams {
207-
let model = params.get_first("model").map(|s| s.to_string());
208-
let languages = params.get_languages();
209-
210-
let keywords: Vec<String> = params
211-
.get("keyword")
212-
.or_else(|| params.get("keywords"))
213-
.map(|v| match v {
214-
QueryValue::Single(s) => s.split(',').map(|k| k.trim().to_string()).collect(),
215-
QueryValue::Multi(vec) => vec.iter().map(|k| k.trim().to_string()).collect(),
216-
})
217-
.unwrap_or_default();
218-
219207
ListenParams {
220-
model,
221-
languages,
222-
keywords,
208+
model: params.get_first("model").map(|s| s.to_string()),
209+
languages: params.get_languages(),
210+
keywords: params.parse_keywords(),
223211
..Default::default()
224212
}
225213
}

crates/transcribe-proxy/src/routes/callback.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::Deserialize;
88
use hypr_supabase_storage::SupabaseStorage;
99

1010
use super::{AppState, RouteError, parse_async_provider};
11-
use crate::supabase::SupabaseClient;
11+
use crate::supabase::{PipelineStatus, SupabaseClient};
1212

1313
#[derive(Deserialize)]
1414
pub(crate) struct CallbackQuery {
@@ -69,12 +69,12 @@ pub async fn handler(
6969

7070
let update = match &outcome {
7171
CallbackResult::Done(raw_result) => serde_json::json!({
72-
"status": "done",
72+
"status": PipelineStatus::Done,
7373
"raw_result": raw_result,
7474
"updated_at": chrono::Utc::now().to_rfc3339(),
7575
}),
7676
CallbackResult::ProviderError(message) => serde_json::json!({
77-
"status": "error",
77+
"status": PipelineStatus::Error,
7878
"error": message,
7979
"updated_at": chrono::Utc::now().to_rfc3339(),
8080
}),

crates/transcribe-proxy/src/routes/start.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
66
use hypr_supabase_storage::SupabaseStorage;
77

88
use super::{AppState, RouteError, parse_async_provider};
9-
use crate::supabase::{SupabaseClient, TranscriptionJob};
9+
use crate::supabase::{PipelineStatus, SupabaseClient, TranscriptionJob};
1010

1111
#[derive(Deserialize, utoipa::ToSchema)]
1212
#[serde(rename_all = "camelCase")]
@@ -110,7 +110,7 @@ pub async fn handler(
110110
user_id,
111111
file_id: body.file_id,
112112
provider: provider_str.to_string(),
113-
status: "processing".to_string(),
113+
status: PipelineStatus::Processing,
114114
provider_request_id: Some(provider_request_id),
115115
raw_result: None,
116116
error: None,

crates/transcribe-proxy/src/routes/status.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use axum::{Json, extract::Path};
22
use serde::Serialize;
33

44
use super::RouteError;
5-
use crate::supabase::SupabaseClient;
5+
use crate::supabase::{PipelineStatus, SupabaseClient};
66

77
#[derive(Debug, Clone, Serialize, utoipa::ToSchema)]
88
#[serde(rename_all = "camelCase")]
99
pub struct SttStatusResponse {
10-
pub status: String,
10+
pub status: PipelineStatus,
1111
#[serde(skip_serializing_if = "Option::is_none")]
1212
pub provider: Option<String>,
1313
#[serde(skip_serializing_if = "Option::is_none")]

crates/transcribe-proxy/src/routes/streaming/hyprnote.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use owhisper_interface::ListenParams;
99

1010
use crate::config::SttProxyConfig;
1111
use crate::provider_selector::SelectedProvider;
12-
use crate::query_params::{QueryParams, QueryValue};
12+
use crate::query_params::QueryParams;
1313
use crate::relay::WebSocketProxy;
1414
use crate::routes::AppState;
1515

@@ -18,26 +18,12 @@ use super::common::{ProxyBuildError, build_proxy_with_url, finalize_proxy_builde
1818
use super::session::init_session;
1919

2020
fn build_listen_params(params: &QueryParams) -> ListenParams {
21-
let model = params.get_first("model").map(|s| s.to_string());
22-
let languages = params.get_languages();
23-
let sample_rate: u32 = parse_param(params, "sample_rate", 16000);
24-
let channels: u8 = parse_param(params, "channels", 1);
25-
26-
let keywords: Vec<String> = params
27-
.get("keyword")
28-
.or_else(|| params.get("keywords"))
29-
.map(|v| match v {
30-
QueryValue::Single(s) => s.split(',').map(|k| k.trim().to_string()).collect(),
31-
QueryValue::Multi(vec) => vec.iter().map(|k| k.trim().to_string()).collect(),
32-
})
33-
.unwrap_or_default();
34-
3521
ListenParams {
36-
model,
37-
languages,
38-
sample_rate,
39-
channels,
40-
keywords,
22+
model: params.get_first("model").map(|s| s.to_string()),
23+
languages: params.get_languages(),
24+
sample_rate: parse_param(params, "sample_rate", 16000),
25+
channels: parse_param(params, "channels", 1),
26+
keywords: params.parse_keywords(),
4127
..Default::default()
4228
}
4329
}

crates/transcribe-proxy/src/supabase.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ use serde::{Deserialize, Serialize};
22

33
type BoxError = Box<dyn std::error::Error + Send + Sync>;
44

5+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, utoipa::ToSchema)]
6+
#[serde(rename_all = "lowercase")]
7+
pub enum PipelineStatus {
8+
Processing,
9+
Done,
10+
Error,
11+
}
12+
513
#[derive(Debug, Clone, Serialize, Deserialize)]
614
pub struct TranscriptionJob {
715
pub id: String,
816
pub user_id: String,
917
pub file_id: String,
1018
pub provider: String,
11-
pub status: String,
19+
pub status: PipelineStatus,
1220
#[serde(skip_serializing_if = "Option::is_none")]
1321
pub provider_request_id: Option<String>,
1422
#[serde(skip_serializing_if = "Option::is_none")]

0 commit comments

Comments
 (0)