MCPcopy Create free account
hub / github.com/cortexkit/magic-context / computePiPressure

Function computePiPressure

packages/pi-plugin/src/pi-pressure.ts:82–94  ·  view source on GitHub ↗
(
	usage: PiAssistantUsage | null,
	contextLimit: number,
)

Source from the content-addressed store, hash-verified

80 * totalInputTokens = info.tokens.input + info.tokens.cache.read + info.tokens.cache.write
81 */
82export function computePiPressure(
83 usage: PiAssistantUsage | null,
84 contextLimit: number,
85): PiPressure | null {
86 if (!usage) return null;
87 const input = usage.input ?? 0;
88 const cacheRead = usage.cacheRead ?? 0;
89 const cacheWrite = usage.cacheWrite ?? 0;
90 const inputTokens = input + cacheRead + cacheWrite;
91 if (inputTokens === 0) return null;
92 const percentage = contextLimit > 0 ? (inputTokens / contextLimit) * 100 : 0;
93 return { inputTokens, percentage };
94}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected