generated from nhcarrigan/template
fix: ensure permission/stats persist until explicit disconnect #110
@@ -717,16 +717,32 @@ fn process_json_line(
|
||||
|
||||
// Only update stats if we have usage information
|
||||
if let Some(usage) = &message.usage {
|
||||
if let Some(model) = &message.model {
|
||||
// Get model from message, or fall back to last known model from stats
|
||||
let model = message.model.clone().or_else(|| {
|
||||
let stats_guard = stats.read();
|
||||
stats_guard.model.clone()
|
||||
}).unwrap_or_else(|| {
|
||||
println!("[WARNING] No model info available for cost calculation, using default");
|
||||
"claude-sonnet-4-5-20250929".to_string()
|
||||
});
|
||||
|
||||
// Calculate cost for historical tracking (including cache tokens)
|
||||
let cost_usd = calculate_cost(
|
||||
usage.input_tokens,
|
||||
usage.output_tokens,
|
||||
model,
|
||||
&model,
|
||||
usage.cache_creation_input_tokens,
|
||||
usage.cache_read_input_tokens,
|
||||
);
|
||||
|
||||
println!("Assistant message tokens - input: {}, output: {}, cache_creation: {:?}, cache_read: {:?}, cost: ${:.4}",
|
||||
usage.input_tokens,
|
||||
usage.output_tokens,
|
||||
usage.cache_creation_input_tokens,
|
||||
usage.cache_read_input_tokens,
|
||||
cost_usd
|
||||
);
|
||||
|
||||
// Store cost for later use in output events
|
||||
message_cost = Some(MessageCost {
|
||||
input_tokens: usage.input_tokens,
|
||||
@@ -741,7 +757,7 @@ fn process_json_line(
|
||||
stats_guard.add_usage(
|
||||
usage.input_tokens,
|
||||
usage.output_tokens,
|
||||
model,
|
||||
&model,
|
||||
usage.cache_creation_input_tokens,
|
||||
usage.cache_read_input_tokens,
|
||||
);
|
||||
@@ -771,10 +787,6 @@ fn process_json_line(
|
||||
// Just increment message count if no usage info
|
||||
stats.write().increment_messages();
|
||||
}
|
||||
} else {
|
||||
// Just increment message count if no usage info
|
||||
stats.write().increment_messages();
|
||||
}
|
||||
|
||||
for block in &message.content {
|
||||
match block {
|
||||
|
||||
Reference in New Issue
Block a user