MCPcopy
hub / github.com/coder/mux / previewGoalAccountingFromUsage

Method previewGoalAccountingFromUsage

src/node/services/agentSession.ts:4309–4339  ·  view source on GitHub ↗
(input: {
    model: string;
    usage: LanguageModelV2Usage | undefined;
    providerMetadata?: Record<string, unknown>;
    metadataModel?: string;
    isCompaction?: boolean;
  })

Source from the content-addressed store, hash-verified

4307 }
4308
4309 private async previewGoalAccountingFromUsage(input: {
4310 model: string;
4311 usage: LanguageModelV2Usage | undefined;
4312 providerMetadata?: Record<string, unknown>;
4313 metadataModel?: string;
4314 isCompaction?: boolean;
4315 }): Promise<void> {
4316 if (!this.workspaceGoalService) {
4317 return;
4318 }
4319 const displayUsage = createDisplayUsage(
4320 input.usage,
4321 input.model,
4322 input.providerMetadata,
4323 input.metadataModel
4324 );
4325 const costUsd = getTotalCost(displayUsage) ?? 0;
4326 try {
4327 await this.workspaceGoalService.previewStreamAccounting({
4328 workspaceId: this.workspaceId,
4329 costUsd,
4330 isCompaction: input.isCompaction === true,
4331 streamStartedAtMs: this.activeStreamStartedAtMs ?? null,
4332 });
4333 } catch (error) {
4334 log.warn("Failed to preview goal stream accounting", {
4335 workspaceId: this.workspaceId,
4336 error: getErrorMessage(error),
4337 });
4338 }
4339 }
4340
4341 private async restoreGoalAccountingSnapshot(): Promise<void> {
4342 if (!this.workspaceGoalService) {

Callers 1

attachAiListenersMethod · 0.95

Calls 4

createDisplayUsageFunction · 0.90
getTotalCostFunction · 0.90
getErrorMessageFunction · 0.90

Tested by

no test coverage detected