From bca88b2d1bba759e2b0bf25f39d4b595dce25960 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Sun, 2 Jun 2024 17:33:55 -0300 Subject: [PATCH] fix api reference of FlowPool --- .../modals/IOModal/components/chatView/index.tsx | 6 ++---- src/frontend/src/stores/flowStore.ts | 11 ++++++----- src/frontend/src/types/api/index.ts | 7 ++++--- src/frontend/src/types/chat/index.ts | 6 +++++- src/frontend/src/types/zustand/flow/index.ts | 16 ++-------------- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/frontend/src/modals/IOModal/components/chatView/index.tsx b/src/frontend/src/modals/IOModal/components/chatView/index.tsx index cf1207397..a2bcc04e4 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/index.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/index.tsx @@ -60,13 +60,11 @@ export default function ChatView({ const chatMessages: ChatMessageType[] = chatOutputResponses .sort((a, b) => Date.parse(a.timestamp) - Date.parse(b.timestamp)) // - .filter( - (output) => output.data.messages && output.data.messages.length > 0, - ) + .filter((output) => output.data.message) .map((output, index) => { try { const { sender, message, sender_name, stream_url, files } = output - .data.messages[0] as ChatOutputType; + .data.message as ChatOutputType; const is_ai = sender === "Machine" || sender === null; return { diff --git a/src/frontend/src/stores/flowStore.ts b/src/frontend/src/stores/flowStore.ts index 0e18eb732..9f420de7c 100644 --- a/src/frontend/src/stores/flowStore.ts +++ b/src/frontend/src/stores/flowStore.ts @@ -23,11 +23,9 @@ import { targetHandleType, } from "../types/flow"; import { - ChatOutputType, FlowPoolObjectType, FlowStoreType, VertexLayerElementType, - chatInputType, } from "../types/zustand/flow"; import { buildVertices } from "../utils/buildUtils"; import { @@ -44,6 +42,7 @@ import { getInputsAndOutputs } from "../utils/storeUtils"; import useAlertStore from "./alertStore"; import { useDarkStore } from "./darkStore"; import useFlowsManagerStore from "./flowsManagerStore"; +import { ChatOutputType, chatInputType } from "../types/chat"; // this is our useStore hook that we can use in our components to get parts of the store and call actions const useFlowStore = create((set, get) => ({ @@ -79,7 +78,7 @@ const useFlowStore = create((set, get) => ({ updateFlowPool: ( nodeId: string, data: VertexBuildTypeAPI | ChatOutputType | chatInputType, - buildId?: string + buildId?: string, ) => { let newFlowPool = cloneDeep({ ...get().flowPool }); if (!newFlowPool[nodeId]) { @@ -95,7 +94,9 @@ const useFlowStore = create((set, get) => ({ } //update data results else { - newFlowPool[nodeId][index].data.messages[0] = (data as ChatOutputType| chatInputType); + newFlowPool[nodeId][index].data.message = data as + | ChatOutputType + | chatInputType; } } get().setFlowPool(newFlowPool); @@ -517,7 +518,7 @@ const useFlowStore = create((set, get) => ({ get().addDataToFlowPool( { ...vertexBuildData, run_id: runId }, - vertexBuildData.id + vertexBuildData.id, ); useFlowStore.getState().updateBuildStatus([vertexBuildData.id], status); diff --git a/src/frontend/src/types/api/index.ts b/src/frontend/src/types/api/index.ts index bcae42d51..a8a63f881 100644 --- a/src/frontend/src/types/api/index.ts +++ b/src/frontend/src/types/api/index.ts @@ -159,9 +159,10 @@ export type VertexBuildTypeAPI = { // data is the object received by the API // it has results, artifacts, timedelta, duration export type VertexDataTypeAPI = { - results: { [key: string]: string }; - logs:{message:string}[]; - messages: ChatOutputType[] | chatInputType[]; + results: { [key: string]: string }; + artifacts?: { [key: string]: string }; + logs: { message: any; type: string }[]; + message: ChatOutputType | chatInputType; inactive?: boolean; timedelta?: number; duration?: string; diff --git a/src/frontend/src/types/chat/index.ts b/src/frontend/src/types/chat/index.ts index 6fc4365c6..c4b322882 100644 --- a/src/frontend/src/types/chat/index.ts +++ b/src/frontend/src/types/chat/index.ts @@ -23,7 +23,11 @@ export type ChatOutputType = { }; export type chatInputType = { - result: string; + message: string; + sender: string; + sender_name: string; + stream_url?: string; + files?: Array<{ path: string; type: string; name: string }>; }; export type FlowPoolObjectType = { diff --git a/src/frontend/src/types/zustand/flow/index.ts b/src/frontend/src/types/zustand/flow/index.ts index 8db400c4d..936cffe90 100644 --- a/src/frontend/src/types/zustand/flow/index.ts +++ b/src/frontend/src/types/zustand/flow/index.ts @@ -10,19 +10,7 @@ import { import { BuildStatus } from "../../../constants/enums"; import { FlowState } from "../../tabs"; import { VertexBuildTypeAPI } from "../../api"; - -export type chatInputType = { - result: string; - files?: string[]; -}; - -export type ChatOutputType = { - message: string; - sender: string; - sender_name: string; - stream_url?: string; - files?: string[]; -}; +import { ChatOutputType, chatInputType } from "../../chat"; export type FlowPoolObjectType = { timestamp: string; @@ -159,7 +147,7 @@ export type FlowStoreType = { updateFlowPool: ( nodeId: string, data: VertexBuildTypeAPI | ChatOutputType | chatInputType, - buildId?: string + buildId?: string, ) => void; getNodePosition: (nodeId: string) => { x: number; y: number }; };