diff --git a/agent-queue/agent-queue.sh b/agent-queue/agent-queue.sh index d9d7dec..4a26bfa 100755 --- a/agent-queue/agent-queue.sh +++ b/agent-queue/agent-queue.sh @@ -1260,8 +1260,23 @@ parse_usage() { [[ "${dti:-0}" -gt 0 ]] && echo "tokens_in=$dti" [[ "${dto:-0}" -gt 0 ]] && echo "tokens_out=$dto" [[ "${dtc:-0}" -gt 0 ]] && echo "tokens_cached=$dtc" - # NOTE: Devin's export carries token counts but not USD cost; cost_usd is - # left unset (the dashboard shows tokens + model; cost stays blank). + # Devin's export has tokens but no USD cost. Approximate it from a model + # price map ($/1M tokens: input/output/cache-read) and flag it as estimated + # (the dashboard renders it as "approx"). Rates are indicative, edit here. + local pin pout pcache + case "$dmodel" in + *Opus*) pin=15; pout=75; pcache=1.5;; + *Sonnet*) pin=3; pout=15; pcache=0.3;; + *Haiku*) pin=0.8; pout=4; pcache=0.08;; + *) pin=""; pout=""; pcache="";; + esac + if [[ -n "$pin" ]]; then + local dcost + dcost=$(awk -v i="${dti:-0}" -v o="${dto:-0}" -v c="${dtc:-0}" -v pi="$pin" -v po="$pout" -v pc="$pcache" \ + 'BEGIN{printf "%.4f",(i*pi+o*po+c*pc)/1000000}') + echo "cost_usd=$dcost" + echo "usage_estimated=true" + fi fi ;; copilot) : ;; # TODO: GitHub Copilot CLI usage format not yet documented here.