Fix: playground input locking forever if getVerticesOrder return an error

This commit is contained in:
igorrCarvalho 2024-06-18 01:44:48 -03:00
commit 00908fbc8f
10 changed files with 19 additions and 25 deletions

View file

@ -86,9 +86,6 @@ export default function IOModal({
const messages = useMessagesStore((state) => state.messages);
const setColumns = useMessagesStore((state) => state.setColumns);
const flowPool = useFlowStore((state) => state.flowPool);
async function updateVertices() {
return updateVerticesOrder(currentFlow!.id, null);
}
async function sendMessage({
repeat = 1,
@ -107,6 +104,7 @@ export default function IOModal({
startNodeId: chatInput?.id,
files: files,
silent: true,
setLockChat,
}).catch((err) => {
console.error(err);
setLockChat(false);

View file

@ -427,12 +427,14 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
input_value,
files,
silent,
setLockChat,
}: {
startNodeId?: string;
stopNodeId?: string;
input_value?: string;
files?: string[];
silent?: boolean;
setLockChat: (lock: boolean) => void;
}) => {
get().setIsBuilding(true);
const currentFlow = useFlowsManagerStore.getState().currentFlow;
@ -534,6 +536,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
flowId: currentFlow!.id,
startNodeId,
stopNodeId,
setLockChat,
onGetOrderSuccess: () => {
if (!silent) {
setNoticeData({ title: "Running components" });

View file

@ -124,7 +124,9 @@ export type FlowStoreType = {
input_value,
files,
silent,
setLockChat
}: {
setLockChat: (lock: boolean) => void;
startNodeId?: string;
stopNodeId?: string;
input_value?: string;

View file

@ -8,6 +8,7 @@ import { VertexBuildTypeAPI } from "../types/api";
import { VertexLayerElementType } from "../types/zustand/flow";
type BuildVerticesParams = {
setLockChat: (lock: boolean) => void;
flowId: string; // Assuming FlowType is the type for your flow
input_value?: any; // Replace any with the actual type if it's not any
files?: string[];
@ -52,6 +53,7 @@ function getInactiveVertexData(vertexId: string): VertexBuildTypeAPI {
export async function updateVerticesOrder(
flowId: string,
setLockChat: (lock: boolean) => void,
startNodeId?: string | null,
stopNodeId?: string | null,
nodes?: Node[],
@ -79,6 +81,7 @@ export async function updateVerticesOrder(
list: [error.response?.data?.detail ?? "Unknown Error"],
});
useFlowStore.getState().setIsBuilding(false);
setLockChat(false);
throw new Error("Invalid nodes");
}
// orderResponse.data.ids,
@ -117,6 +120,7 @@ export async function buildVertices({
onValidateNodes,
nodes,
edges,
setLockChat,
}: BuildVerticesParams) {
// if startNodeId and stopNodeId are provided
// something is wrong
@ -125,6 +129,7 @@ export async function buildVertices({
}
let verticesOrderResponse = await updateVerticesOrder(
flowId,
setLockChat,
startNodeId,
stopNodeId,
nodes,
@ -135,7 +140,7 @@ export async function buildVertices({
onValidateNodes(verticesOrderResponse.verticesToRun);
} catch (e) {
useFlowStore.getState().setIsBuilding(false);
setLockChat(false)
return;
}
}