How much of a plan's limits a workspace has used.
Team plan · Nov 1 – Nov 30Renews Dec 1
Tasks
18,420 of 20,000 tasks this periodNear the limitResets Dec 1
Runs pause until Dec 1. Running work finishes.
AI credits
2,150 of 5,000 credits this period140 credits on hold
Seats
12 of 12 seatsAt the limit
New members join as guests until a seat frees up.
Storage
41 of 100 GBWebhook calls
1,284,330 calls this period · no limitimport { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { UsageMeter } from "./ui/uicontext/components/kit/Usage.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 44rem)", display: "flex", flexDirection: "column", gap: space.lg, containerType: "inline-size" }, period: { display: "flex", flexWrap: "wrap", justifyContent: "space-between", gap: space.sm, margin: 0, fontSize: font.sm, color: color.muted }, strong: { color: color.fg, fontWeight: 600 }, grid: { display: "grid", gridTemplateColumns: { default: "1fr 1fr", "@container (max-width: 520px)": "1fr" }, gap: space.xl },})export const BillingPeriod = Html.component({ name: "BillingPeriod", model: Schema.Struct({}), message: Schema.Never,}).make({ init: () => ({}), update: ($) => $.model, view: (h) => h.section.attrs({ "aria-label": "Usage this billing period", ...sx(styles.frame) }).children( h.p.attrs(sx(styles.period)).children( h.span.children(h.span.attrs(sx(styles.strong)).children("Team plan"), " · Nov 1 – Nov 30"), h.span.children("Renews Dec 1"), ), h.div.attrs(sx(styles.grid)).children( UsageMeter(h, { label: "Tasks", used: 18_420, limit: 20_000, unit: "tasks", period: "this period", resets: "Resets Dec 1", atLimit: "Runs pause until Dec 1. Running work finishes." }), UsageMeter(h, { label: "AI credits", used: 2_150, limit: 5_000, unit: "credits", period: "this period", held: 140 }), UsageMeter(h, { label: "Seats", used: 12, limit: 12, unit: "seats", atLimit: "New members join as guests until a seat frees up." }), UsageMeter(h, { label: "Storage", used: 41, limit: 100, unit: "GB" }), UsageMeter(h, { label: "Webhook calls", used: 1_284_330, limit: null, unit: "calls", period: "this period" }), ), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/usageUsage
import { UsageMeter } from "./ui/uicontext/components/kit/Usage.ts"export const TaskMeter = <M>(h: Html.H<M>, used: number) => UsageMeter(h, { label: "Tasks", used, limit: 20_000, unit: "tasks", period: "this period", resets: "Resets Dec 1", atLimit: "Runs pause until Dec 1. Running work finishes.", })Examples
A spend limit an admin sets
Change or remove the limit; it saves, says so, and refuses a value outside the allowed range.
Monthly spend
1,640 of 2,000 USD this monthNear the limitResets Dec 1
New runs wait until Dec 1. Work already running finishes.
A new limit applies to the next run.
import { Command, UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Effect, Schema } from "effect"import { accepted, Outcome, pending } from "./ui/uicontext/components/domain/Outcome.ts"import { UsageLimit } from "./ui/uicontext/components/kit/Usage.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 26rem)" } })const Message = UiSchema.TaggedEnum({ SetLimit: { limit: Schema.NullOr(Schema.Number) }, Saved: { limit: Schema.NullOr(Schema.Number) },})// Stands in for the app saving the limit on its server.const SaveLimit = Command.make("SpendLimit.Save", { args: { limit: Schema.NullOr(Schema.Number) } }, ({ limit }) => Effect.sleep("600 millis").pipe(Effect.as(Message.Saved({ limit }))))export const SpendLimit = Html.component({ name: "SpendLimit", model: Schema.Struct({ limit: Schema.NullOr(Schema.Number), outcome: Schema.NullOr(Outcome) }), message: Message,}).make({ init: () => ({ limit: 2_000, outcome: null }), update: { SetLimit: ($, { limit }) => $.evolve({ outcome: pending(limit === null ? "clear" : "limit") }).run(SaveLimit.make({ limit })), Saved: ($, { limit }) => $.evolve({ limit, outcome: accepted(limit === null ? "clear" : "limit") }), }, view: (h, model) => h.div.attrs(sx(styles.frame)).children( UsageLimit(h, { props: { agentId: "spend-limit-demo", label: "Monthly spend", used: 1_640, limit: model.limit, unit: "USD", period: "this month", resets: "Resets Dec 1", atLimit: "New runs wait until Dec 1. Work already running finishes.", can: ["edit", "clear"], min: 100, max: 50_000, step: 50, note: "A new limit applies to the next run.", ...(model.outcome === null ? {} : { outcome: model.outcome }), }, onEmit: { RequestedLimit: ({ limit }) => Message.SetLimit({ limit }), RequestedClearLimit: () => Message.SetLimit({ limit: null }), RequestedMore: () => undefined, }, }), ),})API reference
UsageLimitComponent
Props
| Name | Type | Default | Description |
|---|---|---|---|
agentId | string | — | This editor's id for agents, unique on the page: "spend-limit-workspace" |
labelrequired | string | — | What is counted: "Tasks", "Monthly spend" |
scope | string | — | Whose usage, when there are several: "#design", "Workspace" |
usedrequired | number | — | How much is used so far |
limitrequired | number | null | — | The limit; null for no limit |
unitrequired | string | — | Plural noun: "tasks", "credits", "USD" |
period | string | — | "this month", "this week", "this session" |
held | number | — | Reserved by work in flight, not yet settled: "120 on hold" |
warnAt | number | 0.8 | The fraction of the limit that counts as near it; 0.8 by default |
resets | string | — | When it resets, formatted by the app: "Resets Dec 1" |
atLimit | string | — | What happens at the limit: "New runs pause until the 1st. Running work finishes." |
canrequired | Can(["edit", "clear"]) | — | What this person may do: "edit" sets the limit, "clear" removes it (no limit) |
min | number | — | Bounds for a new limit, also given to the native input |
max | number | — | The largest limit allowed |
step | number | — | The step a new limit moves in |
note | string | — | Said under the editor: "Changing a limit applies to the next run." |
outcome | Outcome | — | The app's answer to the last change: "limit" for RequestedLimit, "clear" for RequestedClearLimit. Pending shows "Saving…"; a refusal shows its reason. |
request | { label, sent } | — | For people who can't edit: "Request more", and whether a request is already waiting |
Events
| Event | Payload | Description |
|---|---|---|
RequestedLimit | { limit: number } | Set this new limit |
RequestedClearLimit | {} | Remove the limit |
RequestedMore | {} | Ask an admin for more: the request button was pressed |
Agent actions
| Action | Description |
|---|---|
SubmittedLimitasks first | Set a new limit, in the meter's unit. Name the current limit as the target. |
ClickedClearLimitasks first | Remove the limit. Name the current limit as the target. |
ClickedRequestMore | Ask an admin for more |
UsageMeterView function
Options
| Name | Type | Description |
|---|---|---|
labelrequired | string | What is counted: "Tasks", "Monthly spend" |
scope | string | Whose usage, when there are several: "#design", "Workspace" |
resets | string | When it resets, formatted by the app: "Resets Dec 1" |
atLimit | string | What happens at the limit: "New runs pause until the 1st. Running work finishes." |
style | Style | Extra StyleX styles for the meter's box |
Accessibility
- Usage is a native
<meter>whose text says the figures, and near or at the limit is said in words too. - The limit editor is a form with a labelled number input; an invalid limit is announced and marked
aria-invalid.