Components / agent
ContextGauge builder
How much of a context window a run has used.
A builder is RenderOnce. Construct and mount it in one expression.
use gpui_kit::agent::ContextGauge;
Reviewed in cost-meter.
Construct
new(ident: impl Into<Ident>, used: Reading) -> Self
Options
Chain onto the value.
label(label: impl Into<SharedString>) -> Self
limit(limit: Limit) -> Self
stale(verified: LastVerified) -> Self
Queries
Only answer; they change nothing.
fraction() -> Option<f32>
Example · cost-meter
fn cost_meter(_window: &mut Window, cx: &mut App) -> AnyElement {
let theme = cx.theme().clone();
stack(&theme)
.w(px(520.0))
.child(
CostMeter::new("scene.cost.meter")
.label("This run")
.line(CostLine::new(
"spend",
"Spend",
Reading::measured(1.24, "1.24 credits"),
))
.line(CostLine::new(
"projected",
"Projected at this rate",
Reading::estimated(4.0, "4.00 credits"),
))
.line(
CostLine::new(
"account",
"Account balance",
Reading::measured(112.0, "112.00 credits"),
)
.stale(LastVerified::at("09:41 today")),
)
.line(CostLine::new(
"storage",
"Storage",
Reading::unavailable_because("The billing host refused the request."),
)),
)
.child(
Divider::new()
.id("scene.cost.rule.gauge")
.label("A limit that is known, and one that is not"),
)
.child(
ContextGauge::new(
"scene.cost.context.known",
Reading::measured(48_000.0, "48,000 tokens"),
)
.label("Context used")
.limit(Limit::measured(128_000.0, "128,000 tokens")),
)
.child(
ContextGauge::new(
"scene.cost.context.unknown",
Reading::estimated(48_000.0, "48,000 tokens"),
)
.label("Context used"),
)
.child(
ContextGauge::new("scene.cost.context.unavailable", Reading::unavailable())
.label("Context used")
.limit(Limit::measured(128_000.0, "128,000 tokens")),
)
.into_any_element()
}