MCPcopy Create free account
hub / github.com/arctic-cli/interface / formatUsageSummary

Function formatUsageSummary

packages/arctic/src/session/usage-format.ts:51–102  ·  view source on GitHub ↗
(records: UsageRecordSummary[], now = Date.now())

Source from the content-addressed store, hash-verified

49const EXTRA_CARD_SPACE = 2
50
51export function formatUsageSummary(records: UsageRecordSummary[], now = Date.now()): string {
52 const content: string[] = []
53 content.push(`Usage summary · ${new Date(now).toISOString()}`)
54 content.push("")
55 content.push(`Visit ${HELP_URL} for up-to-date`)
56 content.push("information on rate limits and credits")
57
58 if (records.length === 0) {
59 content.push("")
60 content.push("No providers are configured for usage tracking.")
61 return renderCard(content)
62 }
63
64 records.forEach((record, index) => {
65 const plan = record.planType ? ` (plan: ${record.planType})` : ""
66 content.push("")
67 content.push(`${record.providerName}${plan}`)
68
69 if (record.error) {
70 content.push(` Error : ${record.error}`)
71 return
72 }
73
74 content.push(` Access : ${formatAccess(record)}`)
75 if (record.credits) {
76 content.push(` Credits : ${formatCredits(record.credits)}`)
77 }
78
79 const tokensLine = formatTokenUsage(record.tokenUsage)
80 if (tokensLine) {
81 content.push(` Tokens : ${tokensLine}`)
82 }
83
84 const costLine = formatCost(record.costSummary)
85 if (costLine) {
86 content.push(` Cost : ${costLine}`)
87 }
88
89 const limitLines = formatLimits(record.limits, now)
90 if (limitLines) {
91 content.push(" Limits")
92 content.push(...limitLines.map((line) => ` ${line}`))
93 }
94
95 if (index < records.length - 1) {
96 content.push("")
97 content.push(" ───────────────────────────────────────────────")
98 }
99 })
100
101 return renderCard(content)
102}
103
104function renderCard(lines: string[]): string {
105 const measuredWidth = Math.max(...lines.map((line) => line.length), 0)

Callers 2

usage.test.tsFile · 0.90
runFunction · 0.90

Calls 7

renderCardFunction · 0.85
formatAccessFunction · 0.85
formatCreditsFunction · 0.85
formatTokenUsageFunction · 0.85
formatLimitsFunction · 0.85
pushMethod · 0.80
formatCostFunction · 0.70

Tested by

no test coverage detected