((pre, cur) => {
return [...pre, ...cur.options];
}, []);
}, [nextOptions]);
return flattenOptions;
}
export function useGetVariableLabelOrTypeByValue(nodeId?: string) {
const flattenOptions = useFlattenQueryVariableOptions(nodeId);
const findAgentStructuredOutputTypeByValue =
useFindAgentStructuredOutputTypeByValue();
const findAgentStructuredOutputLabel =
useFindAgentStructuredOutputLabelByValue();
const getItem = useCallback(
(val?: string) => {
return flattenOptions.find((x) => x.value === val);
},
[flattenOptions],
);
const getLabel = useCallback(
(val?: string) => {
const item = getItem(val);
if (item) {
return (
{item.parentLabel} / {item.label}
);
}
return getItem(val)?.label || findAgentStructuredOutputLabel(val);
},
[findAgentStructuredOutputLabel, getItem],
);
const getType = useCallback(
(val?: string) => {
return getItem(val)?.type || findAgentStructuredOutputTypeByValue(val);
},
[findAgentStructuredOutputTypeByValue, getItem],
);
return { getLabel, getType };
}