Skip to content

Commit e6e6775

Browse files
committed
cleanup import strcuture
1 parent aaf6f19 commit e6e6775

File tree

11 files changed

+84
-188
lines changed

11 files changed

+84
-188
lines changed

apps/sim/app/api/cron/cleanup-stale-executions/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export async function GET(request: NextRequest) {
5555
executionData: sql`jsonb_set(
5656
COALESCE(execution_data, '{}'::jsonb),
5757
ARRAY['error'],
58-
to_jsonb(${'Execution terminated: worker timeout or crash after ' + staleDurationMinutes + ' minutes'}::text)
58+
to_jsonb(${`Execution terminated: worker timeout or crash after ${staleDurationMinutes} minutes`}::text)
5959
)`,
6060
})
6161
.where(eq(workflowExecutionLogs.id, execution.id))

apps/sim/app/api/workflows/[id]/execute/route.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import { createStreamingResponse } from '@/lib/workflows/streaming/streaming'
2323
import { createHttpResponseFromBlock, workflowHasResponseBlock } from '@/lib/workflows/utils'
2424
import type { WorkflowExecutionPayload } from '@/background/workflow-execution'
2525
import { normalizeName } from '@/executor/constants'
26-
import { type ExecutionMetadata, ExecutionSnapshot } from '@/executor/execution/snapshot'
26+
import { ExecutionSnapshot } from '@/executor/execution/snapshot'
27+
import type { ExecutionMetadata, IterationContext } from '@/executor/execution/types'
2728
import type { StreamingExecution } from '@/executor/types'
2829
import { Serializer } from '@/serializer'
2930
import { CORE_TRIGGER_TYPES } from '@/stores/logs/filters/types'
30-
import type { SubflowType } from '@/stores/workflows/workflow/types'
3131

3232
const logger = createLogger('WorkflowExecuteAPI')
3333

@@ -541,11 +541,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
541541
blockId: string,
542542
blockName: string,
543543
blockType: string,
544-
iterationContext?: {
545-
iterationCurrent: number
546-
iterationTotal: number
547-
iterationType: SubflowType
548-
}
544+
iterationContext?: IterationContext
549545
) => {
550546
logger.info(`[${requestId}] 🔷 onBlockStart called:`, { blockId, blockName, blockType })
551547
sendEvent({
@@ -571,11 +567,7 @@ export async function POST(req: NextRequest, { params }: { params: Promise<{ id:
571567
blockName: string,
572568
blockType: string,
573569
callbackData: any,
574-
iterationContext?: {
575-
iterationCurrent: number
576-
iterationTotal: number
577-
iterationType: SubflowType
578-
}
570+
iterationContext?: IterationContext
579571
) => {
580572
const hasError = callbackData.output?.error
581573

apps/sim/background/schedule-execution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import {
2323
getSubBlockValue,
2424
} from '@/lib/workflows/schedules/utils'
2525
import { REFERENCE } from '@/executor/constants'
26-
import { type ExecutionMetadata, ExecutionSnapshot } from '@/executor/execution/snapshot'
26+
import { ExecutionSnapshot } from '@/executor/execution/snapshot'
27+
import type { ExecutionMetadata } from '@/executor/execution/types'
2728
import type { ExecutionResult } from '@/executor/types'
2829
import { createEnvVarPattern } from '@/executor/utils/reference-validation'
2930
import { mergeSubblockState } from '@/stores/workflows/server-utils'

apps/sim/background/webhook-execution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
loadWorkflowFromNormalizedTables,
1818
} from '@/lib/workflows/persistence/utils'
1919
import { getWorkflowById } from '@/lib/workflows/utils'
20-
import { type ExecutionMetadata, ExecutionSnapshot } from '@/executor/execution/snapshot'
20+
import { ExecutionSnapshot } from '@/executor/execution/snapshot'
21+
import type { ExecutionMetadata } from '@/executor/execution/types'
2122
import type { ExecutionResult } from '@/executor/types'
2223
import { Serializer } from '@/serializer'
2324
import { mergeSubblockState } from '@/stores/workflows/server-utils'

apps/sim/background/workflow-execution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { buildTraceSpans } from '@/lib/logs/execution/trace-spans/trace-spans'
77
import { executeWorkflowCore } from '@/lib/workflows/executor/execution-core'
88
import { PauseResumeManager } from '@/lib/workflows/executor/human-in-the-loop-manager'
99
import { getWorkflowById } from '@/lib/workflows/utils'
10-
import { type ExecutionMetadata, ExecutionSnapshot } from '@/executor/execution/snapshot'
10+
import { ExecutionSnapshot } from '@/executor/execution/snapshot'
11+
import type { ExecutionMetadata } from '@/executor/execution/types'
1112
import type { ExecutionResult } from '@/executor/types'
1213

1314
const logger = createLogger('TriggerWorkflowExecution')

apps/sim/executor/execution/snapshot-serializer.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import type { DAG } from '@/executor/dag/builder'
2-
import {
3-
type ExecutionMetadata,
4-
ExecutionSnapshot,
5-
type SerializableExecutionState,
6-
} from '@/executor/execution/snapshot'
2+
import { ExecutionSnapshot } from '@/executor/execution/snapshot'
3+
import type { ExecutionMetadata, SerializableExecutionState } from '@/executor/execution/types'
74
import type { ExecutionContext, SerializedSnapshot } from '@/executor/types'
85

96
function mapFromEntries<T>(map?: Map<string, T>): Record<string, T> | undefined {

apps/sim/executor/execution/snapshot.ts

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,4 @@
1-
import type { Edge } from 'reactflow'
2-
import type { BlockLog, BlockState } from '@/executor/types'
3-
4-
export interface ExecutionMetadata {
5-
requestId: string
6-
executionId: string
7-
workflowId: string
8-
workspaceId: string
9-
userId: string
10-
sessionUserId?: string
11-
workflowUserId?: string
12-
triggerType: string
13-
triggerBlockId?: string
14-
useDraftState: boolean
15-
startTime: string
16-
isClientSession?: boolean
17-
pendingBlocks?: string[]
18-
resumeFromSnapshot?: boolean
19-
workflowStateOverride?: {
20-
blocks: Record<string, any>
21-
edges: Edge[]
22-
loops?: Record<string, any>
23-
parallels?: Record<string, any>
24-
deploymentVersionId?: string // ID of deployment version if this is deployed state
25-
}
26-
}
27-
28-
export interface ExecutionCallbacks {
29-
onStream?: (streamingExec: any) => Promise<void>
30-
onBlockStart?: (blockId: string, blockName: string, blockType: string) => Promise<void>
31-
onBlockComplete?: (
32-
blockId: string,
33-
blockName: string,
34-
blockType: string,
35-
output: any,
36-
iterationContext?: {
37-
iterationCurrent: number
38-
iterationTotal: number
39-
iterationType: 'loop' | 'parallel'
40-
}
41-
) => Promise<void>
42-
}
43-
44-
export interface SerializableExecutionState {
45-
blockStates: Record<string, BlockState>
46-
executedBlocks: string[]
47-
blockLogs: BlockLog[]
48-
decisions: {
49-
router: Record<string, string>
50-
condition: Record<string, string>
51-
}
52-
completedLoops: string[]
53-
loopExecutions?: Record<string, any>
54-
parallelExecutions?: Record<string, any>
55-
parallelBlockMapping?: Record<string, any>
56-
activeExecutionPath: string[]
57-
pendingQueue?: string[]
58-
remainingEdges?: Edge[]
59-
dagIncomingEdges?: Record<string, string[]>
60-
completedPauseContexts?: string[]
61-
}
1+
import type { ExecutionMetadata, SerializableExecutionState } from '@/executor/execution/types'
622

633
export class ExecutionSnapshot {
644
constructor(

apps/sim/executor/execution/types.ts

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,68 @@
1-
import type { ExecutionMetadata, SerializableExecutionState } from '@/executor/execution/snapshot'
2-
import type { BlockState, NormalizedBlockOutput } from '@/executor/types'
1+
import type { Edge } from 'reactflow'
2+
import type { BlockLog, BlockState, NormalizedBlockOutput } from '@/executor/types'
33
import type { SubflowType } from '@/stores/workflows/workflow/types'
44

5+
export interface ExecutionMetadata {
6+
requestId: string
7+
executionId: string
8+
workflowId: string
9+
workspaceId: string
10+
userId: string
11+
sessionUserId?: string
12+
workflowUserId?: string
13+
triggerType: string
14+
triggerBlockId?: string
15+
useDraftState: boolean
16+
startTime: string
17+
isClientSession?: boolean
18+
pendingBlocks?: string[]
19+
resumeFromSnapshot?: boolean
20+
workflowStateOverride?: {
21+
blocks: Record<string, any>
22+
edges: Edge[]
23+
loops?: Record<string, any>
24+
parallels?: Record<string, any>
25+
deploymentVersionId?: string
26+
}
27+
}
28+
29+
export interface SerializableExecutionState {
30+
blockStates: Record<string, BlockState>
31+
executedBlocks: string[]
32+
blockLogs: BlockLog[]
33+
decisions: {
34+
router: Record<string, string>
35+
condition: Record<string, string>
36+
}
37+
completedLoops: string[]
38+
loopExecutions?: Record<string, any>
39+
parallelExecutions?: Record<string, any>
40+
parallelBlockMapping?: Record<string, any>
41+
activeExecutionPath: string[]
42+
pendingQueue?: string[]
43+
remainingEdges?: Edge[]
44+
dagIncomingEdges?: Record<string, string[]>
45+
completedPauseContexts?: string[]
46+
}
47+
48+
export interface IterationContext {
49+
iterationCurrent: number
50+
iterationTotal: number
51+
iterationType: SubflowType
52+
}
53+
54+
export interface ExecutionCallbacks {
55+
onStream?: (streamingExec: any) => Promise<void>
56+
onBlockStart?: (blockId: string, blockName: string, blockType: string) => Promise<void>
57+
onBlockComplete?: (
58+
blockId: string,
59+
blockName: string,
60+
blockType: string,
61+
output: any,
62+
iterationContext?: IterationContext
63+
) => Promise<void>
64+
}
65+
566
export interface ContextExtensions {
667
workspaceId?: string
768
executionId?: string
@@ -32,22 +93,14 @@ export interface ContextExtensions {
3293
blockId: string,
3394
blockName: string,
3495
blockType: string,
35-
iterationContext?: {
36-
iterationCurrent: number
37-
iterationTotal: number
38-
iterationType: SubflowType
39-
}
96+
iterationContext?: IterationContext
4097
) => Promise<void>
4198
onBlockComplete?: (
4299
blockId: string,
43100
blockName: string,
44101
blockType: string,
45102
output: { input?: any; output: NormalizedBlockOutput; executionTime: number },
46-
iterationContext?: {
47-
iterationCurrent: number
48-
iterationTotal: number
49-
iterationType: SubflowType
50-
}
103+
iterationContext?: IterationContext
51104
) => Promise<void>
52105
}
53106

apps/sim/lib/logs/execution/logger.test.ts

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -313,95 +313,4 @@ describe('ExecutionLogger', () => {
313313
expect(files[0].name).toBe('nested.json')
314314
})
315315
})
316-
317-
describe('cost model merging', () => {
318-
test('should merge cost models correctly', () => {
319-
const loggerInstance = new ExecutionLogger()
320-
const mergeCostModelsMethod = (loggerInstance as any).mergeCostModels.bind(loggerInstance)
321-
322-
const existing = {
323-
'gpt-4': {
324-
input: 0.01,
325-
output: 0.02,
326-
total: 0.03,
327-
tokens: { input: 100, output: 200, total: 300 },
328-
},
329-
}
330-
331-
const additional = {
332-
'gpt-4': {
333-
input: 0.005,
334-
output: 0.01,
335-
total: 0.015,
336-
tokens: { input: 50, output: 100, total: 150 },
337-
},
338-
'gpt-3.5-turbo': {
339-
input: 0.001,
340-
output: 0.002,
341-
total: 0.003,
342-
tokens: { input: 10, output: 20, total: 30 },
343-
},
344-
}
345-
346-
const merged = mergeCostModelsMethod(existing, additional)
347-
348-
expect(merged['gpt-4'].input).toBe(0.015)
349-
expect(merged['gpt-4'].output).toBe(0.03)
350-
expect(merged['gpt-4'].total).toBe(0.045)
351-
expect(merged['gpt-4'].tokens.input).toBe(150)
352-
expect(merged['gpt-4'].tokens.output).toBe(300)
353-
expect(merged['gpt-4'].tokens.total).toBe(450)
354-
355-
expect(merged['gpt-3.5-turbo']).toBeDefined()
356-
expect(merged['gpt-3.5-turbo'].total).toBe(0.003)
357-
})
358-
359-
test('should handle prompt/completion token aliases', () => {
360-
const loggerInstance = new ExecutionLogger()
361-
const mergeCostModelsMethod = (loggerInstance as any).mergeCostModels.bind(loggerInstance)
362-
363-
const existing = {
364-
'gpt-4': {
365-
input: 0.01,
366-
output: 0.02,
367-
total: 0.03,
368-
tokens: { prompt: 100, completion: 200, total: 300 },
369-
},
370-
}
371-
372-
const additional = {
373-
'gpt-4': {
374-
input: 0.005,
375-
output: 0.01,
376-
total: 0.015,
377-
tokens: { input: 50, output: 100, total: 150 },
378-
},
379-
}
380-
381-
const merged = mergeCostModelsMethod(existing, additional)
382-
383-
expect(merged['gpt-4'].tokens.input).toBe(150)
384-
expect(merged['gpt-4'].tokens.output).toBe(300)
385-
})
386-
387-
test('should handle empty existing models', () => {
388-
const loggerInstance = new ExecutionLogger()
389-
const mergeCostModelsMethod = (loggerInstance as any).mergeCostModels.bind(loggerInstance)
390-
391-
const existing = {}
392-
const additional = {
393-
'claude-3': {
394-
input: 0.02,
395-
output: 0.04,
396-
total: 0.06,
397-
tokens: { input: 200, output: 400, total: 600 },
398-
},
399-
}
400-
401-
const merged = mergeCostModelsMethod(existing, additional)
402-
403-
expect(merged['claude-3']).toBeDefined()
404-
expect(merged['claude-3'].total).toBe(0.06)
405-
})
406-
})
407316
})

apps/sim/lib/workflows/executor/execute-workflow.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { v4 as uuidv4 } from 'uuid'
33
import { LoggingSession } from '@/lib/logs/execution/logging-session'
44
import { executeWorkflowCore } from '@/lib/workflows/executor/execution-core'
55
import { PauseResumeManager } from '@/lib/workflows/executor/human-in-the-loop-manager'
6-
import { type ExecutionMetadata, ExecutionSnapshot } from '@/executor/execution/snapshot'
6+
import { ExecutionSnapshot } from '@/executor/execution/snapshot'
7+
import type { ExecutionMetadata } from '@/executor/execution/types'
78

89
const logger = createLogger('WorkflowExecution')
910

0 commit comments

Comments
 (0)