- service/agent/billing.rs: 适配新的 BillingResult 枚举类型 - 将 InsufficientBalance 错误转换为 AppError::BadRequest
33 lines
797 B
Rust
33 lines
797 B
Rust
//! Billing — delegates to agent crate.
|
|
|
|
use crate::AppService;
|
|
use crate::error::AppError;
|
|
use uuid::Uuid;
|
|
|
|
impl AppService {
|
|
pub async fn record_ai_usage(
|
|
&self,
|
|
project_uid: Uuid,
|
|
model_id: Uuid,
|
|
input_tokens: i64,
|
|
output_tokens: i64,
|
|
) -> Result<agent::billing::BillingRecord, AppError> {
|
|
use agent::billing::BillingResult;
|
|
|
|
match agent::billing::record_ai_usage(
|
|
&self.db,
|
|
project_uid,
|
|
model_id,
|
|
input_tokens,
|
|
output_tokens,
|
|
)
|
|
.await?
|
|
{
|
|
BillingResult::Success(record) => Ok(record),
|
|
BillingResult::InsufficientBalance { message } => {
|
|
Err(AppError::BadRequest(message))
|
|
}
|
|
}
|
|
}
|
|
}
|