Skip to content

Commit 2673aed

Browse files
committed
make it work with start block
1 parent 6d1b93e commit 2673aed

File tree

4 files changed

+46
-16
lines changed

4 files changed

+46
-16
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/input-mapping/input-mapping.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface InputFormatField {
1414
}
1515

1616
interface InputTriggerBlock {
17-
type: 'input_trigger'
17+
type: 'input_trigger' | 'start_trigger'
1818
subBlocks?: {
1919
inputFormat?: { value?: InputFormatField[] }
2020
}
@@ -33,8 +33,9 @@ interface StarterBlockLegacy {
3333
}
3434

3535
function isInputTriggerBlock(value: unknown): value is InputTriggerBlock {
36+
const type = (value as { type?: unknown }).type
3637
return (
37-
!!value && typeof value === 'object' && (value as { type?: unknown }).type === 'input_trigger'
38+
!!value && typeof value === 'object' && (type === 'input_trigger' || type === 'start_trigger')
3839
)
3940
}
4041

@@ -74,7 +75,7 @@ export function InputMapping({
7475

7576
// Fetch child workflow state via registry API endpoint, using cached metadata when possible
7677
// Here we rely on live store; the serializer/executor will resolve at runtime too.
77-
// We only need the inputFormat from an Input Trigger in the selected child workflow state.
78+
// We only need the inputFormat from a Start or Input Trigger in the selected child workflow state.
7879
const [childInputFields, setChildInputFields] = useState<Array<{ name: string; type?: string }>>(
7980
[]
8081
)
@@ -97,7 +98,7 @@ export function InputMapping({
9798
}
9899
const { data } = await res.json()
99100
const blocks = (data?.state?.blocks as Record<string, unknown>) || {}
100-
// Prefer new input_trigger
101+
// Prefer start_trigger or input_trigger
101102
const triggerEntry = Object.entries(blocks).find(([, b]) => isInputTriggerBlock(b))
102103
if (triggerEntry && isInputTriggerBlock(triggerEntry[1])) {
103104
const inputFormat = triggerEntry[1].subBlocks?.inputFormat?.value

apps/sim/blocks/blocks/workflow_input.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ const getAvailableWorkflows = (): Array<{ label: string; id: string }> => {
1919
export const WorkflowInputBlock: BlockConfig = {
2020
type: 'workflow_input',
2121
name: 'Workflow',
22-
description: 'Execute another workflow and map variables to its Input Form Trigger schema.',
23-
longDescription: `Execute another child workflow and map variables to its Input Form Trigger schema. Helps with modularizing workflows.`,
22+
description: 'Execute another workflow and map variables to its Start trigger schema.',
23+
longDescription: `Execute another child workflow and map variables to its Start trigger schema. Helps with modularizing workflows.`,
2424
bestPractices: `
2525
- Usually clarify/check if the user has tagged a workflow to use as the child workflow. Understand the child workflow to determine the logical position of this block in the workflow.
26-
- Remember, that the start point of the child workflow is the Input Form Trigger block.
26+
- Remember, that the start point of the child workflow is the Start block.
2727
`,
2828
category: 'blocks',
2929
bgColor: '#6366F1', // Indigo - modern and professional
@@ -36,14 +36,14 @@ export const WorkflowInputBlock: BlockConfig = {
3636
options: getAvailableWorkflows,
3737
required: true,
3838
},
39-
// Renders dynamic mapping UI based on selected child workflow's Input Trigger inputFormat
39+
// Renders dynamic mapping UI based on selected child workflow's Start trigger inputFormat
4040
{
4141
id: 'inputMapping',
4242
title: 'Input Mapping',
4343
type: 'input-mapping',
4444
layout: 'full',
4545
description:
46-
"Map fields defined in the child workflow's Input Trigger to variables/values in this workflow.",
46+
"Map fields defined in the child workflow's Start block to variables/values in this workflow.",
4747
dependsOn: ['workflowId'],
4848
},
4949
],

apps/sim/executor/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,17 +783,21 @@ export class Executor {
783783
if (!initBlock) {
784784
if (this.isChildExecution) {
785785
const inputTriggerBlocks = this.actualWorkflow.blocks.filter(
786-
(block) => block.metadata?.id === 'input_trigger'
786+
(block) =>
787+
block.metadata?.id === 'input_trigger' || block.metadata?.id === 'start_trigger'
787788
)
788789
if (inputTriggerBlocks.length === 1) {
789790
initBlock = inputTriggerBlocks[0]
790791
} else if (inputTriggerBlocks.length > 1) {
791-
throw new Error('Child workflow has multiple Input Trigger blocks. Keep only one.')
792+
throw new Error(
793+
'Child workflow has multiple trigger blocks. Keep only one Start block.'
794+
)
792795
}
793796
} else {
794797
// Parent workflows can use any trigger block (dedicated or trigger-mode)
795798
const triggerBlocks = this.actualWorkflow.blocks.filter(
796799
(block) =>
800+
block.metadata?.id === 'start_trigger' ||
797801
block.metadata?.id === 'input_trigger' ||
798802
block.metadata?.id === 'api_trigger' ||
799803
block.metadata?.id === 'chat_trigger' ||

apps/sim/stores/workflows/registry/store.ts

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,36 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
442442
deploymentStatuses: {},
443443
}
444444
} else {
445-
// If no state in DB, use empty state - server should have created start block
445+
// If no state in DB, create a default Start block
446+
const starterId = crypto.randomUUID()
446447
workflowState = {
447-
blocks: {},
448+
blocks: {
449+
[starterId]: {
450+
id: starterId,
451+
type: 'start_trigger',
452+
name: 'Start',
453+
position: { x: 200, y: 300 },
454+
enabled: true,
455+
horizontalHandles: true,
456+
isWide: false,
457+
advancedMode: false,
458+
triggerMode: false,
459+
height: 0,
460+
subBlocks: {
461+
inputFormat: {
462+
id: 'inputFormat',
463+
type: 'input-format',
464+
value: [],
465+
},
466+
},
467+
outputs: {
468+
input: { type: 'string', description: 'Primary user input or message' },
469+
conversationId: { type: 'string', description: 'Conversation thread identifier' },
470+
files: { type: 'files', description: 'User uploaded files' },
471+
},
472+
data: {},
473+
},
474+
},
448475
edges: [],
449476
loops: {},
450477
parallels: {},
@@ -454,9 +481,7 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
454481
lastSaved: Date.now(),
455482
}
456483

457-
logger.warn(
458-
`Workflow ${id} has no state in DB - this should not happen with server-side start block creation`
459-
)
484+
logger.info(`Created default Start block for empty workflow ${id}`)
460485
}
461486

462487
if (workflowData?.isDeployed || workflowData?.deployedAt) {

0 commit comments

Comments
 (0)