(nodeData: NodeDataSchema, newNodeId: string, isAgentflow = true)
| 133 | * canvas-ready NodeData (where inputParams is the schema and inputs is key-value values). |
| 134 | */ |
| 135 | export function initNode(nodeData: NodeDataSchema, newNodeId: string, isAgentflow = true): NodeData { |
| 136 | const inputAnchors: Array<{ id: string; name: string; label: string; type: string }> = [] |
| 137 | const inputDefinitions: Array<{ id: string; name: string; label: string; type: string; default?: unknown; optional?: boolean }> = [] |
| 138 | |
| 139 | // Get input definitions from API response (nodeData.inputs contains InputParam[] from API) |
| 140 | const inputDefs = nodeData.inputs || nodeData.inputAnchors || [] |
| 141 | |
| 142 | const whitelistTypes = [ |
| 143 | 'asyncOptions', |
| 144 | 'asyncMultiOptions', |
| 145 | 'options', |
| 146 | 'multiOptions', |
| 147 | 'array', |
| 148 | 'datagrid', |
| 149 | 'string', |
| 150 | 'number', |
| 151 | 'boolean', |
| 152 | 'password', |
| 153 | 'json', |
| 154 | 'code', |
| 155 | 'date', |
| 156 | 'file', |
| 157 | 'folder', |
| 158 | 'tabs', |
| 159 | 'conditionFunction' |
| 160 | ] |
| 161 | |
| 162 | // Process input definitions - separate into anchors vs parameters |
| 163 | for (const input of inputDefs) { |
| 164 | const newInput = { |
| 165 | ...input, |
| 166 | id: `${newNodeId}-input-${input.name}-${input.type}` |
| 167 | } |
| 168 | if (whitelistTypes.includes(input.type)) { |
| 169 | inputDefinitions.push(newInput) |
| 170 | } else { |
| 171 | inputAnchors.push(newInput) |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | // Credential — extract top-level credential property and prepend to input definitions. |
| 176 | // When coming from the API, credential is the schema object; after user selection it |
| 177 | // becomes a string ID. Only the schema object form is relevant here (initNode is called |
| 178 | // during node creation from the API payload, not after credential selection). |
| 179 | const rawCredential = typeof nodeData.credential === 'object' ? nodeData.credential : undefined |
| 180 | |
| 181 | if (rawCredential?.credentialNames?.length) { |
| 182 | inputDefinitions.unshift({ |
| 183 | ...rawCredential, |
| 184 | id: `${newNodeId}-input-FLOWISE_CREDENTIAL_ID-credential`, |
| 185 | name: 'FLOWISE_CREDENTIAL_ID', |
| 186 | label: rawCredential.label ?? 'Credential', |
| 187 | type: 'credential' |
| 188 | }) |
| 189 | } |
| 190 | |
| 191 | // Initialize default input values from definitions using initializeDefaultNodeData |
| 192 | const initialInputValues = initializeDefaultNodeData(inputDefinitions) |
no test coverage detected