Download packages/agent-core-v2/src/human/llm/usage.ts from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 1.21 kB
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/agent-core-v2/src/human/llm/usage.ts
- Command line
-
hf download hf://SaylorTwift/kimi-code/packages/agent-core-v2/src/human/llm/usage.ts
-
curl -L -o usage.ts https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/agent-core-v2/src/human/llm/usage.ts
1.21 kB
| export interface TokenUsage { | |
| inputOther: number; | |
| output: number; | |
| inputCacheRead: number; | |
| inputCacheCreation: number; | |
| raw?: Record<string, unknown>; | |
| } | |
| export function emptyUsage(): TokenUsage { | |
| return { inputOther: 0, output: 0, inputCacheRead: 0, inputCacheCreation: 0 }; | |
| } | |
| export function inputTotal(usage: TokenUsage): number { | |
| return usage.inputOther + usage.inputCacheRead + usage.inputCacheCreation; | |
| } | |
| export function grandTotal(usage: TokenUsage): number { | |
| return inputTotal(usage) + usage.output; | |
| } | |
| export function addUsage(a: TokenUsage, b: TokenUsage): TokenUsage { | |
| return { | |
| inputOther: a.inputOther + b.inputOther, | |
| output: a.output + b.output, | |
| inputCacheRead: a.inputCacheRead + b.inputCacheRead, | |
| inputCacheCreation: a.inputCacheCreation + b.inputCacheCreation, | |
| }; | |
| } | |
| export function mergeUsagePatch( | |
| base: TokenUsage | undefined, | |
| patch: Partial<TokenUsage>, | |
| ): TokenUsage { | |
| return { | |
| inputOther: patch.inputOther ?? base?.inputOther ?? 0, | |
| output: patch.output ?? base?.output ?? 0, | |
| inputCacheRead: patch.inputCacheRead ?? base?.inputCacheRead ?? 0, | |
| inputCacheCreation: patch.inputCacheCreation ?? base?.inputCacheCreation ?? 0, | |
| }; | |
| } | |