fix(start): fix start drag from toolbar (#1882)

* Fix start block

* Fix webhook

* Remove comments
This commit is contained in:
Siddharth Ganesan
2025-11-10 20:30:45 -08:00
committed by GitHub
parent 4b37f92f3a
commit cd48cd4de4
4 changed files with 143 additions and 6 deletions

View File

@@ -762,13 +762,39 @@ export function useCollaborativeWorkflow() {
// Generate subBlocks and outputs from the block configuration
const subBlocks: Record<string, any> = {}
// Create subBlocks from the block configuration
if (blockConfig.subBlocks) {
blockConfig.subBlocks.forEach((subBlock) => {
let initialValue: unknown = null
if (typeof subBlock.value === 'function') {
try {
initialValue = subBlock.value({})
} catch (error) {
logger.warn('Failed to resolve dynamic sub-block default value', {
subBlockId: subBlock.id,
error: error instanceof Error ? error.message : String(error),
})
}
} else if (subBlock.defaultValue !== undefined) {
initialValue = subBlock.defaultValue
} else if (subBlock.type === 'input-format') {
initialValue = [
{
id: crypto.randomUUID(),
name: '',
type: 'string',
value: '',
collapsed: false,
},
]
} else if (subBlock.type === 'table') {
initialValue = []
}
subBlocks[subBlock.id] = {
id: subBlock.id,
type: subBlock.type,
value: subBlock.defaultValue ?? null,
value: initialValue,
}
})
}

View File

@@ -37,8 +37,19 @@ function resolveInitialValue(subBlock: SubBlockConfig): unknown {
return cloneDefaultValue(subBlock.defaultValue)
}
// Ensure structured fields are initialized with empty collections by default
if (subBlock.type === 'input-format' || subBlock.type === 'table') {
if (subBlock.type === 'input-format') {
return [
{
id: crypto.randomUUID(),
name: '',
type: 'string',
value: '',
collapsed: false,
},
]
}
if (subBlock.type === 'table') {
return []
}

View File

@@ -124,6 +124,7 @@ export function getAllTriggerBlocks(): TriggerInfo[] {
icon: block.icon,
color: block.bgColor,
category: 'core',
enableTriggerMode: hasTriggerCapability(block),
})
}
// Check if it's a tool with trigger capability (has trigger-config subblock)
@@ -153,9 +154,15 @@ export function getAllTriggerBlocks(): TriggerInfo[] {
* Check if a block has trigger capability (contains trigger mode subblocks)
*/
export function hasTriggerCapability(block: BlockConfig): boolean {
const hasTriggerModeSubBlocks = block.subBlocks.some((subBlock) => subBlock.mode === 'trigger')
if (block.category === 'triggers') {
return hasTriggerModeSubBlocks
}
return (
(block.triggers?.enabled === true && block.triggers.available.length > 0) ||
block.subBlocks.some((subBlock) => subBlock.mode === 'trigger')
hasTriggerModeSubBlocks
)
}

View File

@@ -4,6 +4,7 @@ import { devtools } from 'zustand/middleware'
import { createLogger } from '@/lib/logs/console/logger'
import { getBlockOutputs } from '@/lib/workflows/block-outputs'
import { getBlock } from '@/blocks'
import type { SubBlockConfig } from '@/blocks/types'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
import {
@@ -21,6 +22,72 @@ import { generateLoopBlocks, generateParallelBlocks } from '@/stores/workflows/w
const logger = createLogger('WorkflowStore')
/**
* Creates a deep clone of an initial sub-block value to avoid shared references.
*
* @param value - The value to clone.
* @returns A cloned value suitable for initializing sub-block state.
*/
function cloneInitialSubblockValue(value: unknown): unknown {
if (Array.isArray(value)) {
return value.map((item) => cloneInitialSubblockValue(item))
}
if (value && typeof value === 'object') {
return Object.entries(value as Record<string, unknown>).reduce<Record<string, unknown>>(
(acc, [key, entry]) => {
acc[key] = cloneInitialSubblockValue(entry)
return acc
},
{}
)
}
return value ?? null
}
/**
* Resolves the initial value for a sub-block based on its configuration.
*
* @param config - The sub-block configuration.
* @returns The resolved initial value or null when no defaults are defined.
*/
function resolveInitialSubblockValue(config: SubBlockConfig): unknown {
if (typeof config.value === 'function') {
try {
const resolved = config.value({})
return cloneInitialSubblockValue(resolved)
} catch (error) {
logger.warn('Failed to resolve dynamic sub-block default value', {
subBlockId: config.id,
error: error instanceof Error ? error.message : String(error),
})
}
}
if (config.defaultValue !== undefined) {
return cloneInitialSubblockValue(config.defaultValue)
}
if (config.type === 'input-format') {
return [
{
id: crypto.randomUUID(),
name: '',
type: 'string',
value: '',
collapsed: false,
},
]
}
if (config.type === 'table') {
return []
}
return null
}
const initialState = {
blocks: {},
edges: [],
@@ -106,12 +173,38 @@ export const useWorkflowStore = create<WorkflowStore>()(
}
const subBlocks: Record<string, SubBlockState> = {}
const subBlockStore = useSubBlockStore.getState()
const activeWorkflowId = useWorkflowRegistry.getState().activeWorkflowId
blockConfig.subBlocks.forEach((subBlock) => {
const subBlockId = subBlock.id
const initialValue = resolveInitialSubblockValue(subBlock)
const normalizedValue =
initialValue !== undefined && initialValue !== null ? initialValue : null
subBlocks[subBlockId] = {
id: subBlockId,
type: subBlock.type,
value: null,
value: normalizedValue as SubBlockState['value'],
}
if (activeWorkflowId) {
try {
const valueToStore =
initialValue !== undefined ? cloneInitialSubblockValue(initialValue) : null
subBlockStore.setValue(id, subBlockId, valueToStore)
} catch (error) {
logger.warn('Failed to seed sub-block store value during block creation', {
blockId: id,
subBlockId,
error: error instanceof Error ? error.message : String(error),
})
}
} else {
logger.warn('Cannot seed sub-block store value: activeWorkflowId not available', {
blockId: id,
subBlockId,
})
}
})