FromHeaders reads the budget header. Missing (e.g. local Ollama) yields the zero value and the UI skips the segment. Out-of-range values are clamped, not rejected, so server-side rounding past 1.0 doesn't blank the readout. NaN/±Inf are rejected: NaN slips past the clamp (all comparisons false), an
(h http.Header)
| 66 | // the UI's int(NaN*100+0.5) yields MinInt64 → a garbage percentage. Both are |
| 67 | // treated as "no signal", like a missing header. |
| 68 | func FromHeaders(h http.Header) BudgetStatus { |
| 69 | raw := h.Get(headerRemaining) |
| 70 | if raw == "" { |
| 71 | return BudgetStatus{} |
| 72 | } |
| 73 | v, err := strconv.ParseFloat(raw, 64) |
| 74 | if err != nil { |
| 75 | return BudgetStatus{} |
| 76 | } |
| 77 | if math.IsNaN(v) || math.IsInf(v, 0) { |
| 78 | return BudgetStatus{} |
| 79 | } |
| 80 | switch { |
| 81 | case v < 0: |
| 82 | v = 0 |
| 83 | case v > 1: |
| 84 | v = 1 |
| 85 | } |
| 86 | return BudgetStatus{Set: true, Remaining: v} |
| 87 | } |
| 88 | |
| 89 | // StatusSuffix builds the " · 73% pass" status-bar tail; "" before the first |
| 90 | // snapshot. Rounded to nearest percent so it doesn't jitter on every token. |
no outgoing calls