Skip to content
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
13 changes: 13 additions & 0 deletions crates/flare-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod forward;
pub mod heuristic;
pub mod providers;
pub mod shape_xlat;
pub mod shortcircuit;
pub mod think;

use axum::{
Expand All @@ -23,6 +24,7 @@ pub fn router() -> Router {
.route("/proxy/v1/messages", post(v1_messages_handler))
.with_state(AppState {
config: ProviderConfig::from_env(),
sc_config: shortcircuit::ShortCircuitConfig::from_env(),
client,
})
}
Expand Down Expand Up @@ -53,11 +55,22 @@ async fn v1_messages_handler(
return (StatusCode::UNAUTHORIZED, "invalid or missing proxy token").into_response();
}
}
match shortcircuit::try_short_circuit(&body, &state.sc_config) {
shortcircuit::ShortCircuitOutcome::Match(message) => {
// Internal CLI bookkeeping calls (quota probe, prefix/title/
// suggestion/filepath detection) are sent non-streaming and
// expect a plain Messages JSON body, unlike every other request
// this proxy handles.
return axum::Json(message).into_response();
}
shortcircuit::ShortCircuitOutcome::NoMatch => {}
}
forward::proxy_request(body, &state.config, &state.client).await
}

#[derive(Clone)]
struct AppState {
config: ProviderConfig,
sc_config: shortcircuit::ShortCircuitConfig,
client: reqwest::Client,
}
Loading
Loading