Merge branch 'db' of github.com:logspace-ai/langflow into db
This commit is contained in:
commit
ded204efc9
1 changed files with 12 additions and 10 deletions
|
|
@ -25,6 +25,7 @@ export default function BuildTrigger({
|
||||||
const { updateSSEData } = useSSE();
|
const { updateSSEData } = useSSE();
|
||||||
const { reactFlowInstance } = useContext(typesContext);
|
const { reactFlowInstance } = useContext(typesContext);
|
||||||
const { setErrorData } = useContext(alertContext);
|
const { setErrorData } = useContext(alertContext);
|
||||||
|
const [valid, setValid] = useState(true);
|
||||||
|
|
||||||
async function handleBuild(flow: FlowType) {
|
async function handleBuild(flow: FlowType) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -44,7 +45,9 @@ export default function BuildTrigger({
|
||||||
setIsBuilding(true);
|
setIsBuilding(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const allNodesValid = await streamNodeData(flow);
|
const allNodesValid = await streamNodeData(flow, (isAllNodesValid) => {
|
||||||
|
setIsBuilt(isAllNodesValid);
|
||||||
|
});
|
||||||
await enforceMinimumLoadingTime(startTime, minimumLoadingTime);
|
await enforceMinimumLoadingTime(startTime, minimumLoadingTime);
|
||||||
setIsBuilt(allNodesValid);
|
setIsBuilt(allNodesValid);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -59,15 +62,14 @@ export default function BuildTrigger({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function streamNodeData(flow: FlowType) {
|
async function streamNodeData(flow: FlowType, onStreamComplete) {
|
||||||
// Make a POST request to send the flow data and receive a unique session ID
|
// Make a POST request to send the flow data and receive a unique session ID
|
||||||
const response = await postBuildInit(flow);
|
const response = await postBuildInit(flow);
|
||||||
const { flowId } = response.data;
|
const { flowId } = response.data;
|
||||||
|
|
||||||
// Use the session ID to establish an SSE connection using EventSource
|
// Use the session ID to establish an SSE connection using EventSource
|
||||||
let validationResults = [];
|
|
||||||
const apiUrl = `/api/v1/build/stream/${flowId}`;
|
const apiUrl = `/api/v1/build/stream/${flowId}`;
|
||||||
const eventSource = new EventSource(apiUrl);
|
const eventSource = new EventSource(apiUrl);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
eventSource.onmessage = (event) => {
|
eventSource.onmessage = (event) => {
|
||||||
// If the event is parseable, return
|
// If the event is parseable, return
|
||||||
|
|
@ -78,23 +80,21 @@ export default function BuildTrigger({
|
||||||
// if the event is the end of the stream, close the connection
|
// if the event is the end of the stream, close the connection
|
||||||
if (parsedData.end_of_stream) {
|
if (parsedData.end_of_stream) {
|
||||||
eventSource.close();
|
eventSource.close();
|
||||||
|
onStreamComplete(valid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Otherwise, process the data
|
// Otherwise, process the data
|
||||||
const isValid = processStreamResult(parsedData);
|
processStreamResult(parsedData);
|
||||||
validationResults.push(isValid);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
eventSource.onerror = (error) => {
|
eventSource.onerror = (error) => {
|
||||||
console.error("EventSource failed:", error);
|
console.error("EventSource failed:", error);
|
||||||
eventSource.close();
|
eventSource.close();
|
||||||
|
onStreamComplete(valid);
|
||||||
};
|
};
|
||||||
// Return true if all nodes are valid, false otherwise
|
|
||||||
return validationResults.every((result) => result);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
eventSource.close();
|
eventSource.close();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -106,7 +106,9 @@ export default function BuildTrigger({
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Error parsing stream data: ", err);
|
console.log("Error parsing stream data: ", err);
|
||||||
}
|
}
|
||||||
return parsedData.valid;
|
if (!parsedData.valid) {
|
||||||
|
setValid(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function enforceMinimumLoadingTime(
|
async function enforceMinimumLoadingTime(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue