MCPcopy Index your code
hub / github.com/anomalyco/opencode / formatUsage

Function formatUsage

packages/opencode/src/cli/cmd/run/session-data.ts:134–161  ·  view source on GitHub ↗
(
  tokens: Tokens | undefined,
  limit: number | undefined,
  cost: number | undefined,
)

Source from the content-addressed store, hash-verified

132}
133
134function formatUsage(
135 tokens: Tokens | undefined,
136 limit: number | undefined,
137 cost: number | undefined,
138): string | undefined {
139 const total =
140 (tokens?.input ?? 0) +
141 (tokens?.output ?? 0) +
142 (tokens?.reasoning ?? 0) +
143 (tokens?.cache?.read ?? 0) +
144 (tokens?.cache?.write ?? 0)
145
146 if (total <= 0) {
147 if (typeof cost === "number" && cost > 0) {
148 return money.format(cost)
149 }
150 return undefined
151 }
152
153 const text =
154 limit && limit > 0 ? `${Locale.number(total)} (${Math.round((total / limit) * 100)}%)` : Locale.number(total)
155
156 if (typeof cost === "number" && cost > 0) {
157 return `${text} · ${money.format(cost)}`
158 }
159
160 return text
161}
162
163export function formatError(error: {
164 name?: string

Callers 1

reduceSessionDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected