Skip to content
Open
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
17 changes: 16 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ GENERAL_TIMEZONE=Asia/Shanghai
# DISABLE_HTTP2=false

# Cursor客户端版本(已弃用)
# CURSOR_CLIENT_VERSION=2.0.0
# CURSOR_CLIENT_VERSION=2.6.0

# 思考标签(已弃用)
# THINKING_TAG=think
Expand Down Expand Up @@ -284,5 +284,20 @@ DURATION_FORMAT=random
# - random : 随机语言 (仅用于测试)
DURATION_LANGUAGE=random

# ====== CLI 后端配置 ======
# 启用 CLI 后端(通过 Cursor 官方 agent CLI 调用)
# 前提: 安装 Cursor CLI (curl https://cursor.com/install -fsS | bash && agent login)
# 启用后通过 /cli/chat/completions 端点调用
CLI_BACKEND_ENABLED=false

# agent 二进制路径
CLI_AGENT_BIN=agent

# CLI 请求超时(毫秒)
CLI_TIMEOUT_MS=300000

# CLI 工作目录
CLI_WORKSPACE=/tmp

# 配置文件路径
CONFIG_FILE=config.toml
2 changes: 1 addition & 1 deletion config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ raw_model_fetch_mode = "truncate"
emulated_platform = "{DEFAULT_PLATFORM}"

# Cursor客户端版本
cursor_client_version = "2.0.0"
cursor_client_version = "2.6.0"
1 change: 1 addition & 0 deletions src/app/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def_pub_const!(
ROUTE_RAW_MODELS_PATH = "/raw/models",
ROUTE_MODELS_PATH = "/v1/models",
ROUTE_CHAT_COMPLETIONS_PATH = "/v1/chat/completions",
ROUTE_CLI_CHAT_COMPLETIONS_PATH = "/cli/chat/completions",
ROUTE_MESSAGES_PATH = "/v1/messages",
ROUTE_MESSAGES_COUNT_TOKENS_PATH = "/v1/messages/count_tokens",
);
Expand Down
4 changes: 2 additions & 2 deletions src/app/constant/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def_header_value! {
(TRAILERS, "trailers"),
(U_EQ_0, "u=0"),
(U_EQ_1_I, "u=1, i"),
(CONNECT_ES, "connect-es/1.6.1"),
(NOT_A_BRAND, "\"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"138\""),
(CONNECT_ES, "connect-es/2.1.1"),
(NOT_A_BRAND, "\"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"140\""),
(MOBILE_NO, "?0"),
(VSCODE_ORIGIN, "vscode-file://vscode-app"),
(CROSS_SITE, "cross-site"),
Expand Down
10 changes: 5 additions & 5 deletions src/app/constant/header/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ use manually_init::ManuallyInit;
crate::define_typed_constants! {
&'static str => {
/// 默认的客户端版本号
DEFAULT_CLIENT_VERSION = "2.0.0",
DEFAULT_CLIENT_VERSION = "2.6.0",
/// 环境变量名:Cursor 客户端版本
ENV_CURSOR_CLIENT_VERSION = "CURSOR_CLIENT_VERSION",
/// Chrome 版本信息
CHROME_VERSION_INFO = " Chrome/138.0.7204.251 Electron/37.7.0 Safari/537.36",
CHROME_VERSION_INFO = " Chrome/140.0.7339.41 Electron/38.0.0 Safari/537.36",
/// User-Agent 前缀
UA_PREFIX = cfg_select! {
target_os = "windows" => {"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/"}
Expand All @@ -31,9 +31,9 @@ crate::define_typed_constants! {
},
/// 默认的 User-Agent
DEFAULT_UA = cfg_select! {
target_os = "windows" => {"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/2.0.0 Chrome/138.0.7204.251 Electron/37.7.0 Safari/537.36"}
target_os = "macos" => {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/2.0.0 Chrome/138.0.7204.251 Electron/37.7.0 Safari/537.36"}
target_os = "linux" => {"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/2.0.0 Chrome/138.0.7204.251 Electron/37.7.0 Safari/537.36"}
target_os = "windows" => {"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/2.6.0 Chrome/140.0.7339.41 Electron/38.0.0 Safari/537.36"}
target_os = "macos" => {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/2.6.0 Chrome/140.0.7339.41 Electron/38.0.0 Safari/537.36"}
target_os = "linux" => {"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/2.6.0 Chrome/140.0.7339.41 Electron/38.0.0 Safari/537.36"}
},
}

Expand Down
1 change: 1 addition & 0 deletions src/app/model/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl AppConfig {
super::context_fill_mode::init();
}
crate::core::constant::create_models();
crate::core::service::cli_backend::init();

let (content, config) = if let Ok(s) = std::fs::read_to_string(&*CONFIG_FILE_PATH) {
match toml::from_str(&s) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/model/cursor_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Version {
}

impl Default for Version {
fn default() -> Self { Self { major: 2, minor: 0, patch: 0 } }
fn default() -> Self { Self { major: 2, minor: 6, patch: 0 } }
}

impl<'de> serde::Deserialize<'de> for Version {
Expand Down
16 changes: 8 additions & 8 deletions src/app/model/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,28 @@ impl PlatformType {
}

/// User-Agent 后缀
pub const UA_SUFFIX: &'static str = " Chrome/138.0.7204.251 Electron/37.7.0 Safari/537.36";
pub const UA_SUFFIX: &'static str = " Chrome/140.0.7339.41 Electron/38.0.0 Safari/537.36";

// const UA_SUFFIX_LEN: usize = " Chrome/138.0.7204.251 Electron/37.7.0 Safari/537.36".len();
// const UA_SUFFIX_LEN: usize = " Chrome/140.0.7339.41 Electron/38.0.0 Safari/537.36".len();

static PLATFORMS: Platforms = Platforms {
windows: Platform {
web_ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
web_ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36",
string: "\"Windows\"",
ua_prefix: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/",
// default_ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/2.0.0 Chrome/138.0.7204.251 Electron/37.7.0 Safari/537.36",
// default_ua: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/2.6.0 Chrome/140.0.7339.41 Electron/38.0.0 Safari/537.36",
},
macos: Platform {
web_ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
web_ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36",
string: "\"macOS\"",
ua_prefix: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/",
// default_ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/2.0.0 Chrome/138.0.7204.251 Electron/37.7.0 Safari/537.36",
// default_ua: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/2.6.0 Chrome/140.0.7339.41 Electron/38.0.0 Safari/537.36",
},
linux: Platform {
web_ua: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
web_ua: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36",
string: "\"Linux\"",
ua_prefix: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/",
// default_ua: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/2.0.0 Chrome/138.0.7204.251 Electron/37.7.0 Safari/537.36",
// default_ua: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cursor/2.6.0 Chrome/140.0.7339.41 Electron/38.0.0 Safari/537.36",
},
};

Expand Down
9 changes: 8 additions & 1 deletion src/app/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ pub use json::{InfallibleSerialize, InfallibleJson, GenericJson, OpenAiJson, Ant

use super::{
constant::{
ROUTE_BUILD_KEY_PATH, ROUTE_CHAT_COMPLETIONS_PATH, ROUTE_CONFIG_EXAMPLE_PATH,
ROUTE_BUILD_KEY_PATH, ROUTE_CHAT_COMPLETIONS_PATH, ROUTE_CLI_CHAT_COMPLETIONS_PATH,
ROUTE_CONFIG_EXAMPLE_PATH,
ROUTE_CONFIG_GET_PATH, ROUTE_CONFIG_RELOAD_PATH, ROUTE_CONFIG_SET_PATH,
ROUTE_CONFIG_VERSION_GET_PATH, ROUTE_CPP_CONFIG_PATH, ROUTE_CPP_MODELS_PATH,
ROUTE_CPP_STREAM_PATH, ROUTE_ENV_EXAMPLE_PATH, ROUTE_FILE_SYNC_PATH,
Expand Down Expand Up @@ -41,6 +42,7 @@ use crate::{
handle_update_tokens_config_version, handle_update_tokens_profile,
},
service::{
cli_backend::handle_cli_chat_completions,
cpp::{
handle_cpp_config, handle_cpp_models, handle_stream_cpp, handle_sync_file,
handle_upload_file,
Expand Down Expand Up @@ -141,6 +143,11 @@ pub fn create_router(state: Arc<AppState>) -> Router {
post(handle_chat_completions)
.route_layer(middleware::from_fn_with_state(state.clone(), v1_auth_middleware)),
)
.route(
exchange_map.resolve(ROUTE_CLI_CHAT_COMPLETIONS_PATH),
post(handle_cli_chat_completions)
.route_layer(middleware::from_fn(admin_auth_middleware)),
)
.route(
exchange_map.resolve(ROUTE_MESSAGES_COUNT_TOKENS_PATH),
post(handle_messages_count_tokens)
Expand Down
1 change: 1 addition & 0 deletions src/core/service.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// mod backend;
// mod context;
pub mod cli_backend;
pub mod cpp;

use crate::{
Expand Down
Loading