Download packages/agent-core-v2/src/agent/usage/cacheProbeService.ts from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 2.06 kB
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/agent-core-v2/src/agent/usage/cacheProbeService.ts
- Command line
-
hf download hf://SaylorTwift/kimi-code/packages/agent-core-v2/src/agent/usage/cacheProbeService.ts
-
curl -L -o cacheProbeService.ts https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/agent-core-v2/src/agent/usage/cacheProbeService.ts
2.06 kB
| import { Service } from '#/_base/di/service'; | |
| import { ScopeActivation, registerScopedService } from '#/_base/di/scope'; | |
| import { LifecycleScope } from '#/app/scopes'; | |
| import { IAgentScopeContext } from '#/agent/scopeContext/scopeContext'; | |
| import { ITelemetryService } from '#/app/telemetry/telemetry'; | |
| import { inputTotal } from '#human/llm/usage'; | |
| import { IModelCatalog } from '#/llm-adapter/model/catalog'; | |
| import { ISessionUsageService } from '#/session/usage/sessionUsage'; | |
| import { IAgentCacheProbeService } from './cacheProbe'; | |
| import { type UsageRecordedContext } from './usage'; | |
| export class AgentCacheProbeService extends Service implements IAgentCacheProbeService { | |
| declare readonly _serviceBrand: undefined; | |
| constructor( | |
| usage: ISessionUsageService, | |
| scopeContext: IAgentScopeContext, | |
| private readonly telemetry: ITelemetryService, | |
| private readonly models: IModelCatalog, | |
| ) { | |
| super(); | |
| if (scopeContext.forkedFrom === undefined) return; | |
| this._register( | |
| usage.onDidRecord((e) => { | |
| if (e.agent.agentId === scopeContext.agentId) this.probe(e); | |
| }), | |
| ); | |
| } | |
| private probe(e: UsageRecordedContext): void { | |
| if (!e.firstRecord || e.source?.type !== 'turn') return; | |
| let providerType: string | undefined; | |
| let protocol: string | undefined; | |
| try { | |
| const model = this.models.get(e.model); | |
| providerType = model.providerType ?? model.protocol; | |
| protocol = model.protocol; | |
| } catch { } | |
| this.telemetry.track2('prompt_cache_probe', { | |
| source: 'fork', | |
| turn_id: e.source.turnId, | |
| provider_type: providerType, | |
| protocol, | |
| input_tokens: inputTotal(e.usage), | |
| input_cache_read: e.usage.inputCacheRead, | |
| input_cache_creation: e.usage.inputCacheCreation, | |
| output_tokens: e.usage.output, | |
| }); | |
| } | |
| } | |
| registerScopedService( | |
| LifecycleScope.Agent, | |
| IAgentCacheProbeService, | |
| AgentCacheProbeService, | |
| ScopeActivation.OnScopeCreated, | |
| 'cacheProbe', | |
| ); | |