Skip to content

Commit 57e6203

Browse files
committed
fix(multi-trigger): resolution paths for triggers
1 parent d83c418 commit 57e6203

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

apps/sim/executor/utils/block-data.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1-
import { getBlockOutputs } from '@/lib/workflows/blocks/block-outputs'
21
import { normalizeName } from '@/executor/constants'
32
import type { ExecutionContext } from '@/executor/types'
43
import type { OutputSchema } from '@/executor/utils/block-reference'
4+
import type { SerializedBlock } from '@/serializer/types'
5+
import type { ToolConfig } from '@/tools/types'
6+
import { getTool } from '@/tools/utils'
57

68
export interface BlockDataCollection {
79
blockData: Record<string, unknown>
810
blockNameMapping: Record<string, string>
911
blockOutputSchemas: Record<string, OutputSchema>
1012
}
1113

14+
export function getBlockSchema(
15+
block: SerializedBlock,
16+
toolConfig?: ToolConfig
17+
): OutputSchema | undefined {
18+
if (block.outputs && Object.keys(block.outputs).length > 0) {
19+
return block.outputs as OutputSchema
20+
}
21+
22+
if (toolConfig?.outputs && Object.keys(toolConfig.outputs).length > 0) {
23+
return toolConfig.outputs as OutputSchema
24+
}
25+
26+
return undefined
27+
}
28+
1229
export function collectBlockData(ctx: ExecutionContext): BlockDataCollection {
1330
const blockData: Record<string, unknown> = {}
1431
const blockNameMapping: Record<string, string> = {}
@@ -18,24 +35,21 @@ export function collectBlockData(ctx: ExecutionContext): BlockDataCollection {
1835
if (state.output !== undefined) {
1936
blockData[id] = state.output
2037
}
38+
}
2139

22-
const workflowBlock = ctx.workflow?.blocks?.find((b) => b.id === id)
23-
if (!workflowBlock) continue
40+
const workflowBlocks = ctx.workflow?.blocks ?? []
41+
for (const block of workflowBlocks) {
42+
const id = block.id
2443

25-
if (workflowBlock.metadata?.name) {
26-
blockNameMapping[normalizeName(workflowBlock.metadata.name)] = id
44+
if (block.metadata?.name) {
45+
blockNameMapping[normalizeName(block.metadata.name)] = id
2746
}
2847

29-
const blockType = workflowBlock.metadata?.id
30-
if (blockType) {
31-
const params = workflowBlock.config?.params as Record<string, unknown> | undefined
32-
const subBlocks = params
33-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, { value: v }]))
34-
: undefined
35-
const schema = getBlockOutputs(blockType, subBlocks)
36-
if (schema && Object.keys(schema).length > 0) {
37-
blockOutputSchemas[id] = schema
38-
}
48+
const toolId = block.config?.tool
49+
const toolConfig = toolId ? getTool(toolId) : undefined
50+
const schema = getBlockSchema(block, toolConfig)
51+
if (schema && Object.keys(schema).length > 0) {
52+
blockOutputSchemas[id] = schema
3953
}
4054
}
4155

apps/sim/executor/variables/resolvers/block.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { getBlockOutputs } from '@/lib/workflows/blocks/block-outputs'
21
import {
32
isReference,
43
normalizeName,
54
parseReferencePath,
65
SPECIAL_REFERENCE_PREFIXES,
76
} from '@/executor/constants'
7+
import { getBlockSchema } from '@/executor/utils/block-data'
88
import {
99
InvalidFieldError,
1010
type OutputSchema,
@@ -67,15 +67,9 @@ export class BlockResolver implements Resolver {
6767
blockData[blockId] = output
6868
}
6969

70-
const blockType = block.metadata?.id
71-
const params = block.config?.params as Record<string, unknown> | undefined
72-
const subBlocks = params
73-
? Object.fromEntries(Object.entries(params).map(([k, v]) => [k, { value: v }]))
74-
: undefined
7570
const toolId = block.config?.tool
7671
const toolConfig = toolId ? getTool(toolId) : undefined
77-
const outputSchema =
78-
toolConfig?.outputs ?? (blockType ? getBlockOutputs(blockType, subBlocks) : block.outputs)
72+
const outputSchema = getBlockSchema(block, toolConfig)
7973

8074
if (outputSchema && Object.keys(outputSchema).length > 0) {
8175
blockOutputSchemas[blockId] = outputSchema

0 commit comments

Comments
 (0)