fix(billing): use actual tokens in nonstreaming ReAct billing

- ai_react_nonstreaming now passes real input/output tokens to billing
- Was passing hardcoded 0,0 despite destructuring token data
- Also fix unused variable warnings
This commit is contained in:
ZhenYi 2026-04-28 11:06:57 +08:00
parent 64ca5eeea1
commit 32d7b3b902
2 changed files with 9 additions and 7 deletions

View File

@ -33,7 +33,7 @@ pub async fn process_message_ai_react_nonstreaming(
.await;
match final_answer {
Ok((response, input_tokens, output_tokens)) => {
Ok((response, _input_tokens, _output_tokens)) => {
if let Err(e) = create_and_publish_ai_message(
&db,
&cache,
@ -66,15 +66,17 @@ pub async fn process_message_ai_react_nonstreaming(
}
// Record billing (non-fatal)
// TODO: ReAct agent does not track token counts yet; billing with 0/0
let _ = super::billing::record_ai_usage(
if let Err(e) = super::billing::record_ai_usage(
&db,
project_id,
model_id,
0,
0,
_input_tokens,
_output_tokens,
)
.await;
.await
{
tracing::warn!(error = %e, "AI billing recording failed");
}
}
}
Err(e) => {

View File

@ -155,7 +155,7 @@ pub async fn process_message_ai_react_streaming(
})
.await;
let (final_content, input_tokens, output_tokens, err_msg, should_log) = match result {
let (final_content, input_tokens, output_tokens, err_msg, _should_log) = match result {
Ok((content, input, output)) => (content, input, output, None, false),
Err(e) => {
let msg = format!("[Agent error: {}]", e);