Download packages/agent-core-v2/src/agent/usage/usageOps.ts from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/agent-core-v2/src/agent/usage/usageOps.ts
- Command line
-
hf download hf://SaylorTwift/kimi-code/packages/agent-core-v2/src/agent/usage/usageOps.ts
-
curl -L -o usageOps.ts https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/agent-core-v2/src/agent/usage/usageOps.ts
1.12 kB
| /* oxlint-disable typescript-eslint/no-unsafe-declaration-merging, eslint-plugin-import/namespace -- Event2 class+payload-interface declaration merging is the sanctioned event-declaration idiom. */ | |
| import { z } from 'zod'; | |
| import { AgentEvent2 } from '#/app/event/event2'; | |
| import { type TokenUsage } from '#human/llm/usage'; | |
| export type UsageRecordScope = 'session' | 'turn'; | |
| export interface UsageModelState { | |
| readonly byModel: Record<string, TokenUsage>; | |
| } | |
| const usageRecordSchema = z.object({ | |
| agentId: z.string(), | |
| model: z.string(), | |
| usage: z.custom<TokenUsage>(), | |
| usageScope: z.custom<UsageRecordScope>().optional(), | |
| }); | |
| export class UsageRecord extends AgentEvent2<z.infer<typeof usageRecordSchema>> { | |
| static override readonly type = 'usage.record'; | |
| static override readonly durable = true; | |
| static override readonly schema = usageRecordSchema; | |
| } | |
| export interface UsageRecord { | |
| readonly agentId: string; | |
| readonly model: string; | |
| readonly usage: TokenUsage; | |
| readonly usageScope?: UsageRecordScope; | |
| } | |
| export function copyUsage(usage: TokenUsage): TokenUsage { | |
| return { ...usage }; | |
| } | |