- add test button to workflow code step - add test tab to workflow code step https://github.com/user-attachments/assets/e180a827-7321-49a2-8026-88490c557da2  
25 lines
874 B
TypeScript
25 lines
874 B
TypeScript
import { InputSchema } from '@/workflow/types/InputSchema';
|
|
import { FunctionInput } from '@/workflow/types/FunctionInput';
|
|
import { isDefined } from '~/utils/isDefined';
|
|
|
|
export const getDefaultFunctionInputFromInputSchema = (
|
|
inputSchema: InputSchema,
|
|
): FunctionInput => {
|
|
return inputSchema.map((param) => {
|
|
if (['string', 'number', 'boolean'].includes(param.type)) {
|
|
return param.enum && param.enum.length > 0 ? param.enum[0] : null;
|
|
} else if (param.type === 'object') {
|
|
const result: FunctionInput = {};
|
|
if (isDefined(param.properties)) {
|
|
Object.entries(param.properties).forEach(([key, val]) => {
|
|
result[key] = getDefaultFunctionInputFromInputSchema([val])[0];
|
|
});
|
|
}
|
|
return result;
|
|
} else if (param.type === 'array' && isDefined(param.items)) {
|
|
return [];
|
|
}
|
|
return null;
|
|
});
|
|
};
|