refactor: Handle array log results in switchOutputView component

Update the switchOutputView component to handle array log results. If the log results are an array, an error message is logged and the component returns early. This change ensures proper handling of different types of log results and improves the reliability of the component.
This commit is contained in:
ogabrielluiz 2024-06-12 23:51:38 -03:00
commit 3f363bf1f6
3 changed files with 21 additions and 4 deletions

View file

@ -25,8 +25,11 @@ const SwitchOutputView: React.FC<SwitchOutputViewProps> = ({
const flowPoolNode = (flowPool[nodeId] ?? [])[
(flowPool[nodeId]?.length ?? 1) - 1
];
const results = flowPoolNode?.data?.logs[outputName] ?? "";
let results = flowPoolNode?.data?.logs[outputName] ?? "";
if (Array.isArray(results)) {
console.error("Log results are an array", results);
return;
}
const resultType = results?.type;
let resultMessage = results?.message;
const RECORD_TYPES = ["data", "object", "array", "message"];

View file

@ -179,11 +179,16 @@ export type VertexBuildTypeAPI = {
messages: ChatOutputType[] | ChatInputType[];
};
export type LogType = {
message: any;
type: string;
};
// data is the object received by the API
// it has results, artifacts, timedelta, duration
export type VertexDataTypeAPI = {
results: { [key: string]: string };
logs: { message: any; type: string }[];
logs: { [key: string]: LogType | LogType[] };
messages: ChatOutputType[] | ChatInputType[];
inactive?: boolean;
timedelta?: number;

View file

@ -266,9 +266,18 @@ async function buildVertex({
const buildData: VertexBuildTypeAPI = buildRes.data;
if (onBuildUpdate) {
if (!buildData.valid) {
// lots is a dictionary with the key the output field name and the value the log object
// logs: { [key: string]: { message: any; type: string }[] };
const errorMessages = Object.keys(buildData.data.logs).map((key) => {
const logs = buildData.data.logs[key];
if (Array.isArray(logs)) {
return logs.map((log) => log.message);
}
return [logs.message];
});
onBuildError!(
"Error Building Component",
buildData.data.logs.map((log) => log.message),
errorMessages,
verticesIds.map((id) => ({ id }))
);
stopBuild();