((pre, cur) => {
return [...pre, ...cur.options];
}, []);
}
export function useFlattenQueryVariableOptions({
nodeId,
nodeIds = [],
variablesExceptOperatorOutputs,
}: {
nodeId?: string;
} & BuildQueryVariableOptions = {}) {
const { getNode } = useGraphStore((state) => state);
const nextOptions = useBuildQueryVariableOptions({
n: getNode(nodeId),
nodeIds,
variablesExceptOperatorOutputs,
});
const flattenOptions = useMemo(() => {
return flatOptions(nextOptions);
}, [nextOptions]);
return flattenOptions;
}
export function useGetVariableLabelOrTypeByValue({
nodeId,
nodeIds = [],
variablesExceptOperatorOutputs,
}: {
nodeId?: string;
} & BuildQueryVariableOptions = {}) {
const flattenOptions = useFlattenQueryVariableOptions({
nodeId,
nodeIds,
variablesExceptOperatorOutputs,
});
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 };
}