(alreadyBilled: Map<string, number>)
| 1324 | // (delta 0 at terminal) and only genuinely new usage is charged. A future |
| 1325 | // change that relabels historical spans would break this invariant. |
| 1326 | const buildDeltaEntries = (alreadyBilled: Map<string, number>) => { |
| 1327 | const entries: Array<{ |
| 1328 | category: 'model' | 'fixed' | 'tool' |
| 1329 | source: 'workflow' |
| 1330 | description: string |
| 1331 | cost: number |
| 1332 | eventKey: string |
| 1333 | metadata?: ModelUsageMetadata | null |
| 1334 | }> = [] |
| 1335 | for (const line of targets) { |
| 1336 | const billed = alreadyBilled.get(`${line.category}::${line.description}`) ?? 0 |
| 1337 | const delta = line.target - billed |
| 1338 | if (delta <= COST_EPSILON) continue |
| 1339 | entries.push({ |
| 1340 | category: line.category, |
| 1341 | source: 'workflow', |
| 1342 | description: line.description, |
| 1343 | cost: delta, |
| 1344 | eventKey: stableEventKey({ |
| 1345 | executionId: executionId ?? '', |
| 1346 | category: line.category, |
| 1347 | description: line.description, |
| 1348 | billedBefore: billed.toFixed(8), |
| 1349 | }), |
| 1350 | ...(line.metadata !== undefined ? { metadata: line.metadata } : {}), |
| 1351 | }) |
| 1352 | } |
| 1353 | return entries |
| 1354 | } |
| 1355 | |
| 1356 | if (executionId) { |
| 1357 | // Serialize concurrent completion boundaries for this execution so the |
nothing calls this directly
no test coverage detected