MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / formatContextSummary

Function formatContextSummary

apps/extension/src/shared/context-usage.ts:34–46  ·  view source on GitHub ↗
(
  promptTokens: number,
  contextLength: number | undefined
)

Source from the content-addressed store, hash-verified

32const formatCount = (value: number): string => value.toLocaleString('en-US');
33
34export const formatContextSummary = (
35 promptTokens: number,
36 contextLength: number | undefined
37): string => {
38 if (contextLength === undefined || contextLength <= 0) {
39 return `${formatCount(promptTokens)} tokens`;
40 }
41
42 // Clamp caps the displayed percent at 100% when prompt tokens exceed the context window.
43 const percent = Math.round(clamp01(promptTokens / contextLength) * 100);
44
45 return `${formatCount(promptTokens)} / ${formatCount(contextLength)} tokens (${percent}%)`;
46};

Callers 2

ContextDonutFunction · 0.90

Calls 2

formatCountFunction · 0.70
clamp01Function · 0.70

Tested by

no test coverage detected