fix(#4): remove dead total_cost_usd field; map model enums to readable names

This commit is contained in:
Nikketryhard
2026-02-14 15:54:03 -06:00
parent dd7b12a97d
commit 2ccc4b46f8
4 changed files with 54 additions and 20 deletions

View File

@@ -86,7 +86,6 @@ impl GrpcUsage {
api_provider: self.api_provider,
grpc_method: Some(grpc_method),
stop_reason: None,
total_cost_usd: None,
captured_at: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
@@ -419,8 +418,9 @@ fn try_extract_usage(fields: &[ProtoField]) -> Option<GrpcUsage> {
if let ProtoValue::Varint(v) = &field.value {
match field.number {
1 => {
// Model enum — we don't have the mapping, store as number
usage.model = Some(format!("model_enum_{v}"));
// Model proto enum → human-readable name
// See docs/ls-binary-analysis.md for full mapping
usage.model = Some(model_enum_name(*v).to_string());
}
6 => {
// APIProvider enum
@@ -475,6 +475,50 @@ pub fn parse_grpc_response_for_usage(body: &[u8]) -> Option<GrpcUsage> {
None
}
// ─── Model enum → name mapping ──────────────────────────────────────────────
/// Map a proto model enum number to a human-readable name.
///
/// Numbers extracted from extension.js protobuf definitions.
/// See `docs/ls-binary-analysis.md` for full catalog.
fn model_enum_name(enum_val: u64) -> &'static str {
match enum_val {
// Placeholder models (1000 + N)
1007 => "gemini-3-pro", // MODEL_PLACEHOLDER_M7
1008 => "gemini-3-pro-high", // MODEL_PLACEHOLDER_M8
1012 => "claude-opus-4.5", // MODEL_PLACEHOLDER_M12
1018 => "gemini-3-flash", // MODEL_PLACEHOLDER_M18
1026 => "claude-opus-4.6", // MODEL_PLACEHOLDER_M26
// Claude models (named)
281 => "claude-4-sonnet",
282 => "claude-4-sonnet-thinking",
290 => "claude-4-opus",
291 => "claude-4-opus-thinking",
333 => "claude-4.5-sonnet",
334 => "claude-4.5-sonnet-thinking",
340 => "claude-4.5-haiku",
341 => "claude-4.5-haiku-thinking",
// Google models (named)
246 => "gemini-2.5-pro",
312 => "gemini-2.5-flash",
313 => "gemini-2.5-flash-thinking",
329 => "gemini-2.5-flash-thinking-tools",
330 => "gemini-2.5-flash-lite",
335 => "gemini-computer-use-experimental",
342 => "openai-gpt-oss-120b",
346 => "jarvis-proxy",
348 => "gemini-riftrunner",
352 => "gemini-riftrunner-thinking-low",
353 => "gemini-riftrunner-thinking-high",
// Unknown — return a static leak to avoid format!() in a &'static str context
// This is fine because the match arm handles it
_ => Box::leak(format!("model_enum_{enum_val}").into_boxed_str()),
}
}
#[cfg(test)]
mod tests {
use super::*;