(
action: WorkflowAction,
results: Map<string, unknown>,
options: {
componentMetadata?: ComponentMetadataSnapshot;
} = {},
)
| 183 | } |
| 184 | |
| 185 | export function buildActionPayload( |
| 186 | action: WorkflowAction, |
| 187 | results: Map<string, unknown>, |
| 188 | options: { |
| 189 | componentMetadata?: ComponentMetadataSnapshot; |
| 190 | } = {}, |
| 191 | ): { |
| 192 | inputs: Record<string, unknown>; |
| 193 | params: Record<string, unknown>; |
| 194 | warnings: InputWarning[]; |
| 195 | manualOverrides: ManualOverride[]; |
| 196 | } { |
| 197 | const params = { ...(action.params ?? {}) } as Record<string, unknown>; |
| 198 | const inputs = { ...(action.inputOverrides ?? {}) } as Record<string, unknown>; |
| 199 | const warnings: InputWarning[] = []; |
| 200 | const manualOverrides: ManualOverride[] = []; |
| 201 | |
| 202 | const inputMetadata = new Map( |
| 203 | (options.componentMetadata?.inputs ?? []).map((port) => [port.id, port]), |
| 204 | ); |
| 205 | |
| 206 | for (const [targetKey, mapping] of Object.entries(action.inputMappings ?? {})) { |
| 207 | const portMetadata = inputMetadata.get(targetKey); |
| 208 | const preferManual = portMetadata?.valuePriority === 'manual-first'; |
| 209 | const manualProvided = |
| 210 | preferManual && Object.prototype.hasOwnProperty.call(inputs, targetKey) |
| 211 | ? inputs[targetKey] !== undefined |
| 212 | : false; |
| 213 | |
| 214 | if (manualProvided) { |
| 215 | manualOverrides.push({ target: targetKey }); |
| 216 | continue; |
| 217 | } |
| 218 | |
| 219 | const sourceOutput = results.get(mapping.sourceRef); |
| 220 | const resolved = resolveInputValue(sourceOutput, mapping.sourceHandle); |
| 221 | |
| 222 | if (resolved !== undefined) { |
| 223 | if (portMetadata?.connectionType) { |
| 224 | const coercion = coerceValueForConnectionType(portMetadata.connectionType, resolved); |
| 225 | if (coercion.ok) { |
| 226 | inputs[targetKey] = coercion.value; |
| 227 | } else { |
| 228 | warnings.push({ |
| 229 | target: targetKey, |
| 230 | sourceRef: mapping.sourceRef, |
| 231 | sourceHandle: mapping.sourceHandle, |
| 232 | }); |
| 233 | continue; |
| 234 | } |
| 235 | } else { |
| 236 | inputs[targetKey] = resolved; |
| 237 | } |
| 238 | } else { |
| 239 | warnings.push({ |
| 240 | target: targetKey, |
| 241 | sourceRef: mapping.sourceRef, |
| 242 | sourceHandle: mapping.sourceHandle, |
no test coverage detected