(input: {
model: string;
usage: StreamEndEvent["metadata"]["usage"];
providerMetadata?: Record<string, unknown>;
metadataModel?: string;
isCompaction?: boolean;
goalKind?: GoalSyntheticMessageKind;
agentInitiated?: boolean;
})
| 4363 | } |
| 4364 | |
| 4365 | private async recordGoalAccountingFromUsage(input: { |
| 4366 | model: string; |
| 4367 | usage: StreamEndEvent["metadata"]["usage"]; |
| 4368 | providerMetadata?: Record<string, unknown>; |
| 4369 | metadataModel?: string; |
| 4370 | isCompaction?: boolean; |
| 4371 | goalKind?: GoalSyntheticMessageKind; |
| 4372 | agentInitiated?: boolean; |
| 4373 | }): Promise<void> { |
| 4374 | if (!this.workspaceGoalService) { |
| 4375 | return; |
| 4376 | } |
| 4377 | |
| 4378 | const displayUsage = createDisplayUsage( |
| 4379 | input.usage, |
| 4380 | input.model, |
| 4381 | input.providerMetadata, |
| 4382 | input.metadataModel |
| 4383 | ); |
| 4384 | const streamOriginKind = getGoalStreamOriginKind(input); |
| 4385 | const costUsd = getTotalCost(displayUsage) ?? 0; |
| 4386 | try { |
| 4387 | await this.workspaceGoalService.recordStreamAccounting({ |
| 4388 | workspaceId: this.workspaceId, |
| 4389 | costUsd, |
| 4390 | isCompaction: input.isCompaction === true, |
| 4391 | streamOriginKind, |
| 4392 | streamStartedAtMs: this.activeStreamStartedAtMs ?? null, |
| 4393 | }); |
| 4394 | } catch (error) { |
| 4395 | log.warn("Failed to record goal stream accounting", { |
| 4396 | workspaceId: this.workspaceId, |
| 4397 | error: getErrorMessage(error), |
| 4398 | }); |
| 4399 | } |
| 4400 | } |
| 4401 | |
| 4402 | private resetActiveStreamState(): void { |
| 4403 | this.activeStreamContext = undefined; |
no test coverage detected