feat(byok): add external API for local apps

This commit is contained in:
leokun committed 2026-09-28 19:06:50 +08:00
1 parent 2068ab2051
commit 9a8fde279c
26 files changed
+2920 -74

No files matched your search

+4
View File
@@ -196,6 +196,10 @@ pub fn api_router(service: ControlService) -> Router {
"/__byok-api__/api/settings/ports",
get(settings::get_ports).put(settings::update_ports),
)
.route(
"/__byok-api__/api/settings/external-api",
get(settings::get_external_api).put(settings::update_external_api),
)
.route(
"/__byok-api__/api/settings/storage/statistics",
get(settings::get_storage).delete(settings::clear_storage),
+30 -7
View File
@@ -28,8 +28,8 @@ use crate::{
plugin::{PluginDescriptor, PluginRegistry, PluginRuntime, PluginRuntimeStatus},
provider::{is_valid_response_event, ModelEvent, Provider},
store::{
CommitSettings, DesktopSettings, PortSettings, ProxySettings, ProxySettingsInput,
StatisticsStorage, Store, TabSettings, TokenPricingSettings,
CommitSettings, DesktopSettings, ExternalApiSettings, PortSettings, ProxySettings,
ProxySettingsInput, StatisticsStorage, Store, TabSettings, TokenPricingSettings,
},
Error, Result,
};
@@ -605,10 +605,13 @@ impl ControlService {
.llm_calls(limit)
.await?
.into_iter()
.map(|call| CallSummary {
call,
call_kind: "provider_llm",
route: "local_byok",
.map(|call| {
let route = call_route(&call.run_id);
CallSummary {
call,
call_kind: "provider_llm",
route,
}
})
.collect::<Vec<_>>();
calls.extend(
@@ -626,13 +629,14 @@ impl ControlService {
pub async fn call(&self, call_id: &str) -> Result<CallDetail> {
if let Some(call) = self.store.llm_call(call_id).await? {
let cursor_trace = self.cursor_trace_detail(&call.run_id).await?;
let route = call_route(&call.run_id);
return Ok(CallDetail {
request: self.store.llm_call_request(call_id).await?,
response_chunks: self.store.llm_call_chunks(call_id).await?,
call: CallSummary {
call,
call_kind: "provider_llm",
route: "local_byok",
route,
},
cursor_trace,
});
@@ -691,6 +695,17 @@ impl ControlService {
self.store.port_settings().await
}
pub async fn external_api_settings(&self) -> Result<ExternalApiSettings> {
self.store.external_api_settings().await
}
pub async fn set_external_api_settings(
&self,
settings: ExternalApiSettings,
) -> Result<ExternalApiSettings> {
self.store.set_external_api_settings(settings).await
}
pub async fn set_ports(&self, settings: PortSettings) -> Result<PortSettings> {
self.store.set_port_settings(settings).await?;
Ok(settings)
@@ -761,6 +776,14 @@ impl ControlService {
}
}
fn call_route(run_id: &str) -> &'static str {
if run_id.starts_with("external-api:") {
"external_api"
} else {
"local_byok"
}
}
fn official_call(trace: CursorRunTraceSummary) -> CallSummary {
let model_id = trace.model_id.clone().unwrap_or_else(|| "Cursor".into());
let ttfb = trace
+15 -2
View File
@@ -8,8 +8,8 @@ use axum::{
use serde::{Deserialize, Serialize};
use crate::store::{
CommitPromptLocale, CommitSettings, DesktopSettings, PortSettings, ProxySettings,
ProxySettingsInput, StatisticsStorage, StatisticsStorageScope, TabSettings,
CommitPromptLocale, CommitSettings, DesktopSettings, ExternalApiSettings, PortSettings,
ProxySettings, ProxySettingsInput, StatisticsStorage, StatisticsStorageScope, TabSettings,
TokenPricingSettings,
};
@@ -37,6 +37,19 @@ pub async fn update_ports(
Ok(Json(service.set_ports(settings).await?))
}
pub async fn get_external_api(
State(service): State<ControlService>,
) -> Result<Json<ExternalApiSettings>> {
Ok(Json(service.external_api_settings().await?))
}
pub async fn update_external_api(
State(service): State<ControlService>,
Json(settings): Json<ExternalApiSettings>,
) -> Result<Json<ExternalApiSettings>> {
Ok(Json(service.set_external_api_settings(settings).await?))
}
pub async fn get_storage(State(service): State<ControlService>) -> Result<Json<StatisticsStorage>> {
Ok(Json(service.statistics_storage().await?))
}