MCPcopy Index your code
hub / github.com/coder/coder / formatUsageLimitMessage

Function formatUsageLimitMessage

site/src/pages/AgentsPage/utils/usageLimitMessage.ts:89–115  ·  view source on GitHub ↗
(
	data: UsageLimitData,
	fallback = "Your usage limit has been reached.",
)

Source from the content-addressed store, hash-verified

87 * fields are missing or invalid.
88 */
89export function formatUsageLimitMessage(
90 data: UsageLimitData,
91 fallback = "Your usage limit has been reached.",
92): string {
93 const { spent_micros, limit_micros, resets_at } = data;
94
95 // All structured fields must be present and valid for the
96 // detailed message.
97 if (
98 typeof spent_micros !== "number" ||
99 typeof limit_micros !== "number" ||
100 typeof resets_at !== "string" ||
101 !resets_at
102 ) {
103 return fallback;
104 }
105
106 const spent = formatCostMicros(spent_micros);
107 const limit = formatCostMicros(limit_micros);
108 const resetDate = formatResetDate(resets_at);
109
110 if (!resetDate) {
111 return `You've used ${spent} of your ${limit} limit.`;
112 }
113
114 return `You've used ${spent} of your ${limit} limit. Resets ${resetDate}.`;
115}

Callers 3

handleUsageLimitErrorFunction · 0.90
AgentCreateFormFunction · 0.90

Calls 2

formatCostMicrosFunction · 0.90
formatResetDateFunction · 0.85

Tested by

no test coverage detected