mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-11-30 15:55:49 +08:00
- Added initial server setup with Cargo.toml defining dependencies and project structure. - Created build.rs for generating protobuf bindings and validating wire contracts. - Established database schema with initial migration files for conversations, messages, and runs. - Introduced tools and prompts for Cursor functionality, enhancing user interaction capabilities.
53 lines
1.8 KiB
Rust
53 lines
1.8 KiB
Rust
//! Implements Cursor tab metadata services.
|
|
use axum::{
|
|
body::Body,
|
|
extract::{Extension, State},
|
|
http::{Request, Response},
|
|
routing::post,
|
|
Router,
|
|
};
|
|
|
|
use crate::{api::cursor::proxy, cursor::transport::TransportRegistry, Result};
|
|
|
|
pub const TAB_PATHS: [&str; 17] = [
|
|
"/aiserver.v1.AiService/StreamCpp",
|
|
"/aiserver.v1.AiService/StreamNextCursorPrediction",
|
|
"/aiserver.v1.AiService/GetCppEditClassification",
|
|
"/aiserver.v1.AiService/RefreshTabContext",
|
|
"/aiserver.v1.AiService/CppConfig",
|
|
"/aiserver.v1.AiService/CppEditHistoryStatus",
|
|
"/aiserver.v1.AiService/CppAppend",
|
|
"/aiserver.v1.AiService/CppEditHistoryAppend",
|
|
"/aiserver.v1.AiService/ReportAiCodeChangeMetrics",
|
|
"/aiserver.v1.AiService/WriteGitCommitMessage",
|
|
"/aiserver.v1.AiService/WriteGitBranchName",
|
|
"/aiserver.v1.CppService/AvailableModels",
|
|
"/aiserver.v1.CppService/RecordCppFate",
|
|
"/aiserver.v1.FileSyncService/FSSyncFile",
|
|
"/aiserver.v1.FileSyncService/FSIsEnabledForUser",
|
|
"/aiserver.v1.FileSyncService/FSConfig",
|
|
"/aiserver.v1.FileSyncService/FSUploadFile",
|
|
];
|
|
|
|
pub fn is_tab_path(path: &str) -> bool {
|
|
TAB_PATHS.contains(&path)
|
|
}
|
|
|
|
pub fn router() -> Router<TransportRegistry> {
|
|
TAB_PATHS.into_iter().fold(Router::new(), |router, path| {
|
|
router.route(path, post(forward))
|
|
})
|
|
}
|
|
|
|
async fn forward(
|
|
State(registry): State<TransportRegistry>,
|
|
Extension(upstream): Extension<proxy::CursorProxy>,
|
|
request: Request<Body>,
|
|
) -> Result<Response<Body>> {
|
|
let settings = registry.store().tab_settings().await?;
|
|
match settings.service_url() {
|
|
Some(service_url) => proxy::forward_to_service(&upstream, request, service_url).await,
|
|
None => proxy::forward(Extension(upstream), request).await,
|
|
}
|
|
}
|