Files
twenty/packages/twenty-shared/src/logic-function/get-output-schema-from-value.ts
T
martmullandGitHub da064d5e88 Support define is tool logic function (#17926)
- supports isTool and timeout settings in defineLogicFunction in apps
and in setting tabs definition
- compute for all toolInputSchema for logic funciton, in settings and in
code steps

<img width="991" height="802" alt="image"
src="https://github.com/user-attachments/assets/05dc1221-cac9-45a3-87b0-3b13161446fd"
/>
2026-02-16 10:43:29 +01:00

54 lines
1.2 KiB
TypeScript

import { isDefined } from '@/utils';
import {
type BaseOutputSchemaV2,
type LeafType,
} from '@/workflow/workflow-schema/types/base-output-schema.type';
import { isObject } from '@sniptt/guards';
const getValueType = (value: any): LeafType => {
if (!isDefined(value) || value === null) {
return 'unknown';
}
if (typeof value === 'string') {
return 'string';
}
if (typeof value === 'number') {
return 'number';
}
if (typeof value === 'boolean') {
return 'boolean';
}
if (Array.isArray(value)) {
return 'array';
}
return 'unknown';
};
export const getOutputSchemaFromValue = (
testResult: object,
): BaseOutputSchemaV2 => {
return testResult
? Object.entries(testResult).reduce(
(acc: BaseOutputSchemaV2, [key, value]) => {
if (isObject(value) && !Array.isArray(value)) {
acc[key] = {
isLeaf: false,
type: 'object',
label: key,
value: getOutputSchemaFromValue(value),
};
} else {
acc[key] = {
isLeaf: true,
value,
type: getValueType(value),
label: key,
};
}
return acc;
},
{},
)
: {};
};