@@ -47,34 +47,6 @@ export interface ToolCall {
4747const logger = createLogger ( 'ExecutionLogger' )
4848
4949export class ExecutionLogger implements IExecutionLoggerService {
50- private mergeCostModels (
51- existing : Record < string , any > ,
52- additional : Record < string , any >
53- ) : Record < string , any > {
54- const merged = { ...existing }
55- for ( const [ model , costs ] of Object . entries ( additional ) ) {
56- if ( merged [ model ] ) {
57- merged [ model ] = {
58- input : ( merged [ model ] . input || 0 ) + ( costs . input || 0 ) ,
59- output : ( merged [ model ] . output || 0 ) + ( costs . output || 0 ) ,
60- total : ( merged [ model ] . total || 0 ) + ( costs . total || 0 ) ,
61- tokens : {
62- input :
63- ( merged [ model ] . tokens ?. input || merged [ model ] . tokens ?. prompt || 0 ) +
64- ( costs . tokens ?. input || costs . tokens ?. prompt || 0 ) ,
65- output :
66- ( merged [ model ] . tokens ?. output || merged [ model ] . tokens ?. completion || 0 ) +
67- ( costs . tokens ?. output || costs . tokens ?. completion || 0 ) ,
68- total : ( merged [ model ] . tokens ?. total || 0 ) + ( costs . tokens ?. total || 0 ) ,
69- } ,
70- }
71- } else {
72- merged [ model ] = costs
73- }
74- }
75- return merged
76- }
77-
7850 async startWorkflowExecution ( params : {
7951 workflowId : string
8052 workspaceId : string
@@ -209,7 +181,7 @@ export class ExecutionLogger implements IExecutionLoggerService {
209181 workflowInput ?: any
210182 isResume ?: boolean
211183 level ?: 'info' | 'error'
212- status ?: 'completed' | 'failed' | 'cancelled'
184+ status ?: 'completed' | 'failed' | 'cancelled' | 'pending'
213185 } ) : Promise < WorkflowExecutionLog > {
214186 const {
215187 executionId,
@@ -268,43 +240,19 @@ export class ExecutionLogger implements IExecutionLoggerService {
268240 const redactedTraceSpans = redactApiKeys ( filteredTraceSpans )
269241 const redactedFinalOutput = redactApiKeys ( filteredFinalOutput )
270242
271- // Merge costs if resuming
272- const existingCost = isResume && existingLog ?. cost ? existingLog . cost : null
273- const mergedCost = existingCost
274- ? {
275- // For resume, add only the model costs, NOT the base execution charge again
276- total : ( existingCost . total || 0 ) + costSummary . modelCost ,
277- input : ( existingCost . input || 0 ) + costSummary . totalInputCost ,
278- output : ( existingCost . output || 0 ) + costSummary . totalOutputCost ,
279- tokens : {
280- input :
281- ( existingCost . tokens ?. input || existingCost . tokens ?. prompt || 0 ) +
282- costSummary . totalPromptTokens ,
283- output :
284- ( existingCost . tokens ?. output || existingCost . tokens ?. completion || 0 ) +
285- costSummary . totalCompletionTokens ,
286- total : ( existingCost . tokens ?. total || 0 ) + costSummary . totalTokens ,
287- } ,
288- models : this . mergeCostModels ( existingCost . models || { } , costSummary . models ) ,
289- }
290- : {
291- total : costSummary . totalCost ,
292- input : costSummary . totalInputCost ,
293- output : costSummary . totalOutputCost ,
294- tokens : {
295- input : costSummary . totalPromptTokens ,
296- output : costSummary . totalCompletionTokens ,
297- total : costSummary . totalTokens ,
298- } ,
299- models : costSummary . models ,
300- }
301-
302- // Merge files if resuming
303- const existingFiles = isResume && existingLog ?. files ? existingLog . files : [ ]
304- const mergedFiles = [ ...existingFiles , ...executionFiles ]
243+ const executionCost = {
244+ total : costSummary . totalCost ,
245+ input : costSummary . totalInputCost ,
246+ output : costSummary . totalOutputCost ,
247+ tokens : {
248+ input : costSummary . totalPromptTokens ,
249+ output : costSummary . totalCompletionTokens ,
250+ total : costSummary . totalTokens ,
251+ } ,
252+ models : costSummary . models ,
253+ }
305254
306- // Calculate the actual total duration for resume executions
307- const actualTotalDuration =
255+ const totalDuration =
308256 isResume && existingLog ?. startedAt
309257 ? new Date ( endedAt ) . getTime ( ) - new Date ( existingLog . startedAt ) . getTime ( )
310258 : totalDurationMs
@@ -315,19 +263,19 @@ export class ExecutionLogger implements IExecutionLoggerService {
315263 level,
316264 status,
317265 endedAt : new Date ( endedAt ) ,
318- totalDurationMs : actualTotalDuration ,
319- files : mergedFiles . length > 0 ? mergedFiles : null ,
266+ totalDurationMs : totalDuration ,
267+ files : executionFiles . length > 0 ? executionFiles : null ,
320268 executionData : {
321269 traceSpans : redactedTraceSpans ,
322270 finalOutput : redactedFinalOutput ,
323271 tokens : {
324- input : mergedCost . tokens . input ,
325- output : mergedCost . tokens . output ,
326- total : mergedCost . tokens . total ,
272+ input : executionCost . tokens . input ,
273+ output : executionCost . tokens . output ,
274+ total : executionCost . tokens . total ,
327275 } ,
328- models : mergedCost . models ,
276+ models : executionCost . models ,
329277 } ,
330- cost : mergedCost ,
278+ cost : executionCost ,
331279 } )
332280 . where ( eq ( workflowExecutionLogs . executionId , executionId ) )
333281 . returning ( )
0 commit comments