style: format code with cargo fmt and prettier

This commit is contained in:
YoVinchen
2026-01-26 23:51:30 +08:00
Unverified
parent 44fba676d5
commit 5ef6f78fd0
8 changed files with 42 additions and 54 deletions
+2 -8
View File
@@ -275,10 +275,7 @@ fn schema_create_tables_include_pricing_model_columns() {
let multiplier = get_column_info(&conn, "proxy_config", "default_cost_multiplier");
assert_eq!(multiplier.r#type, "TEXT");
assert_eq!(multiplier.notnull, 1);
assert_eq!(
normalize_default(&multiplier.default).as_deref(),
Some("1")
);
assert_eq!(normalize_default(&multiplier.default).as_deref(), Some("1"));
let pricing_source = get_column_info(&conn, "proxy_config", "pricing_model_source");
assert_eq!(pricing_source.r#type, "TEXT");
@@ -310,10 +307,7 @@ fn schema_migration_v4_adds_pricing_model_columns() {
let multiplier = get_column_info(&conn, "proxy_config", "default_cost_multiplier");
assert_eq!(multiplier.r#type, "TEXT");
assert_eq!(multiplier.notnull, 1);
assert_eq!(
normalize_default(&multiplier.default).as_deref(),
Some("1")
);
assert_eq!(normalize_default(&multiplier.default).as_deref(), Some("1"));
let pricing_source = get_column_info(&conn, "proxy_config", "pricing_model_source");
assert_eq!(pricing_source.r#type, "TEXT");
+3 -10
View File
@@ -216,10 +216,7 @@ pub struct ProviderMeta {
#[serde(rename = "costMultiplier", skip_serializing_if = "Option::is_none")]
pub cost_multiplier: Option<String>,
/// 计费模式来源(response/request
#[serde(
rename = "pricingModelSource",
skip_serializing_if = "Option::is_none"
)]
#[serde(rename = "pricingModelSource", skip_serializing_if = "Option::is_none")]
pub pricing_model_source: Option<String>,
/// 每日消费限额(USD
#[serde(rename = "limitDailyUsd", skip_serializing_if = "Option::is_none")]
@@ -688,9 +685,7 @@ mod tests {
json!({ "env": {} }),
None,
);
manager
.providers
.insert("provider-1".to_string(), provider);
manager.providers.insert("provider-1".to_string(), provider);
assert_eq!(manager.get_all_providers().len(), 1);
assert!(manager.get_all_providers().contains_key("provider-1"));
@@ -713,9 +708,7 @@ mod tests {
opus_model: Some("claude-opus".to_string()),
});
let provider = universal
.to_claude_provider()
.expect("claude provider");
let provider = universal.to_claude_provider().expect("claude provider");
assert_eq!(provider.id, "universal-claude-u1");
assert_eq!(provider.name, "Universal");
+3 -3
View File
@@ -452,9 +452,9 @@ async fn log_usage(
use super::usage::logger::UsageLogger;
let logger = UsageLogger::new(&state.db);
let (multiplier, pricing_model_source) = logger
.resolve_pricing_config(provider_id, app_type)
.await;
let (multiplier, pricing_model_source) =
logger.resolve_pricing_config(provider_id, app_type).await;
let pricing_model = if pricing_model_source == "request" {
request_model
} else {
+2 -3
View File
@@ -402,9 +402,8 @@ async fn log_usage_internal(
use super::usage::logger::UsageLogger;
let logger = UsageLogger::new(&state.db);
let (multiplier, pricing_model_source) = logger
.resolve_pricing_config(provider_id, app_type)
.await;
let (multiplier, pricing_model_source) =
logger.resolve_pricing_config(provider_id, app_type).await;
let pricing_model = if pricing_model_source == "request" {
request_model
} else {
+11 -21
View File
@@ -209,9 +209,7 @@ impl<'a> UsageLogger<'a> {
let default_multiplier_raw = match self.db.get_default_cost_multiplier(app_type).await {
Ok(value) => value,
Err(e) => {
log::warn!(
"[USG-003] 获取默认倍率失败 (app_type={app_type}): {e}"
);
log::warn!("[USG-003] 获取默认倍率失败 (app_type={app_type}): {e}");
"1".to_string()
}
};
@@ -228,23 +226,19 @@ impl<'a> UsageLogger<'a> {
let default_pricing_source_raw = match self.db.get_pricing_model_source(app_type).await {
Ok(value) => value,
Err(e) => {
log::warn!(
"[USG-003] 获取默认计费模式失败 (app_type={app_type}): {e}"
);
log::warn!("[USG-003] 获取默认计费模式失败 (app_type={app_type}): {e}");
"response".to_string()
}
};
let default_pricing_source = if matches!(
default_pricing_source_raw.as_str(),
"response" | "request"
) {
default_pricing_source_raw
} else {
log::warn!(
let default_pricing_source =
if matches!(default_pricing_source_raw.as_str(), "response" | "request") {
default_pricing_source_raw
} else {
log::warn!(
"[USG-003] 默认计费模式无效 (app_type={app_type}): {default_pricing_source_raw}"
);
"response".to_string()
};
"response".to_string()
};
let provider = self
.db
@@ -279,9 +273,7 @@ impl<'a> UsageLogger<'a> {
let pricing_model_source = match provider_pricing_source {
Some(value) if matches!(value, "response" | "request") => value.to_string(),
Some(value) => {
log::warn!(
"[USG-003] 供应商计费模式无效 (provider_id={provider_id}): {value}"
);
log::warn!("[USG-003] 供应商计费模式无效 (provider_id={provider_id}): {value}");
default_pricing_source.clone()
}
None => default_pricing_source.clone(),
@@ -312,9 +304,7 @@ impl<'a> UsageLogger<'a> {
let pricing = self.get_model_pricing(&pricing_model)?;
if pricing.is_none() {
log::warn!(
"[USG-002] 模型定价未找到,成本将记录为 0: {pricing_model}"
);
log::warn!("[USG-002] 模型定价未找到,成本将记录为 0: {pricing_model}");
}
let cost = CostCalculator::try_calculate(&usage, pricing.as_ref(), cost_multiplier);
@@ -124,9 +124,7 @@ interface ProviderFormProps {
showButtons?: boolean;
}
const normalizePricingSource = (
value?: string,
): PricingModelSourceOption =>
const normalizePricingSource = (value?: string): PricingModelSourceOption =>
value === "request" || value === "response" ? value : "inherit";
export function ProviderForm({
@@ -970,7 +968,9 @@ export function ProviderForm({
// 添加高级配置
testConfig: testConfig.enabled ? testConfig : undefined,
proxyConfig: proxyConfig.enabled ? proxyConfig : undefined,
costMultiplier: pricingConfig.enabled ? pricingConfig.costMultiplier : undefined,
costMultiplier: pricingConfig.enabled
? pricingConfig.costMultiplier
: undefined,
pricingModelSource:
pricingConfig.enabled && pricingConfig.pricingModelSource !== "inherit"
? pricingConfig.pricingModelSource
+13 -4
View File
@@ -89,7 +89,9 @@ export function PricingConfigPanel() {
return {
app,
multiplier,
source: (source === "request" ? "request" : "response") as PricingModelSource,
source: (source === "request"
? "request"
: "response") as PricingModelSource,
};
}),
);
@@ -153,7 +155,10 @@ export function PricingConfigPanel() {
try {
await Promise.all(
PRICING_APPS.flatMap((app) => [
proxyApi.setDefaultCostMultiplier(app, appConfigs[app].multiplier.trim()),
proxyApi.setDefaultCostMultiplier(
app,
appConfigs[app].multiplier.trim(),
),
proxyApi.setPricingModelSource(app, appConfigs[app].source),
]),
);
@@ -308,10 +313,14 @@ export function PricingConfigPanel() {
</SelectTrigger>
<SelectContent>
<SelectItem value="response">
{t("settings.globalProxy.pricingModelSourceResponse")}
{t(
"settings.globalProxy.pricingModelSourceResponse",
)}
</SelectItem>
<SelectItem value="request">
{t("settings.globalProxy.pricingModelSourceRequest")}
{t(
"settings.globalProxy.pricingModelSourceRequest",
)}
</SelectItem>
</SelectContent>
</Select>
+4 -1
View File
@@ -101,7 +101,10 @@ export const proxyApi = {
},
// 设置默认成本倍率
async setDefaultCostMultiplier(appType: string, value: string): Promise<void> {
async setDefaultCostMultiplier(
appType: string,
value: string,
): Promise<void> {
return invoke("set_default_cost_multiplier", { appType, value });
},