The code now handles exceptions that may occur while building the flow. A final response is added to the event stream to indicate the end of the stream.
The try-except block was added to handle exceptions that may occur in the init_build function. If an exception occurs, it is logged and an HTTPException with a status code of 500 is returned. This ensures that the server does not crash and provides a more informative error message to the client.
The init_build endpoint now returns a status code of 201 to indicate that a new resource has been created. This improves the consistency of the API and makes it easier for clients to understand the response.
🚀 feat(vite.config.ts): add new API route for build stream
The API endpoint for the build stream has been updated to `/api/v1/build/stream/${flowId}` to improve consistency with the naming conventions. The `vite.config.ts` file has been updated to include the new API route for the build stream.
✨ feat(API): add postBuildInit function to handle POST requests to /api/v1/build/init
The chatComponent file had unused imports and variables that were removed to improve code readability. The postBuildInit function was extracted to the API controller to improve code organization and maintainability. The function handles POST requests to /api/v1/build/init.
🚀 feat(chat.py): add response models to /build/init and /build/{flow_id}/status endpoints
The InitResponse and BuiltResponse models are now imported from the schemas module to improve code organization. The /build/init and /build/{flow_id}/status endpoints now have response models to provide a clear understanding of the expected response.
The function stream_build was returning a JSONResponse with an error message when an exception was raised. This is not the correct way to handle errors in FastAPI. Instead, we should raise an HTTPException with the appropriate status code and error message.
The React import is not used in the file, so it has been removed to improve code readability. The link to the source of the Loading component was broken, so it has been fixed to ensure that the component can be used properly.
🔥 chore(loading.tsx): remove unused React import
The unused imports and exception handling for WebSocketDisconnect and WebSocketException were removed from the chat.py file. The code was reformatted to improve readability.
🔥 refactor(chat.py): remove unused imports and exception handling
This change fixes a bug where the validationStatus state was not being set to null when relevantData was null. This caused the validationStatus to retain its previous value, which could lead to incorrect validation results being displayed.
✨ feat(chat.py): add build_status endpoint to check if flow_id is in flow_data_store
The function name websocket_endpoint was renamed to chat to improve semantics. The new build_status endpoint was added to check if a flow_id is in the flow_data_store. This endpoint returns a JSON response with a boolean value indicating whether the flow_id is built or not. If the flow_id is not in the flow_data_store, a JSON response with a value of False is returned. If an exception occurs, a 500 HTTPException is raised with the exception message as the detail.
The import for the postBuild function was removed as it was not being used in the BuildTrigger component. This improves the code's readability and maintainability.
🚀 feat(chatComponent): add useEffect hook to fetch build status and update state
An async function was added to fetch the build status of the flow and update the state of the isBuilt variable. This allows the component to display the correct state of the build trigger button.
👌 refactor(chatComponent): refactor useEffect hook to update isBuilt state when nodes change
The useEffect hook was refactored to update the isBuilt state when the nodes change. This ensures that the build trigger button is disabled when the nodes change, as the flow needs to be rebuilt before it can be triggered again.
🔥 chore(intComponent): remove console.log statement
The console.log statement was removed from the onKeyDown event listener in the IntComponent component. This improves the code's cleanliness and readability.
The BuildStatusTypeAPI was added to the API types to support the new getBuildStatus function. The getBuildStatus function retrieves the build status of a flow by making a GET request to the server. This function is useful for updating the UI with the current status of a flow.
The getWebSocketUrl function was extracted to improve the readability and maintainability of the code. It takes the chatId and isDevelopment flag as parameters and returns the WebSocket URL based on the current environment. The function uses the window.location object to determine the protocol and host, and the chatEndpoint to construct the URL.
🚨 test(test_websocket.py): add tests for build init, stream, and websocket endpoint
The `basic_graph_data` fixture is added to load the basic example data. The `test_init_build`, `test_stream_build`, and `test_websocket_endpoint` tests are added to test the build init, stream, and websocket endpoint. The `test_websocket_endpoint_after_build` test is added to test the websocket endpoint after the build.
The build method call in the for loop of the build_vertices method is unnecessary as the vertices are already sorted and built in the topological_sort method. The yield from statement is used to return the sorted vertices.
🚀 feat(buildTrigger): add waiting for stream to finish and return validation results for each node
The allNodesValid variable has been changed to a validationResults array to store the validation results for each node. A finished variable has been added to improve readability and to wait for the stream to finish. The function now returns an array of validation results for each node.
The changes in this commit handle exceptions that may occur when creating a streaming response. The try-except block ensures that any exceptions are caught and an appropriate response is returned. Additionally, the SSE response has been improved by adding a valid flag and node id to the response. This provides more information to the client about the status of the node build and allows for better error handling.
🐛 fix(chat.py): handle exceptions when creating a streaming response
The commented out code for the /build/{client_id} endpoint has been removed as it is no longer needed. The new implementation uses the /build/init endpoint to initiate the build process and then establishes an SSE connection using EventSource to stream the build process. This allows for a more efficient and responsive build process as the client can receive updates in real-time.
🔥 chore(chat.py, index.tsx): remove commented out code for /build/{client_id} endpoint
✨ feat(chat.py): add support for storing graph data and returning a unique session ID for building langchain object
✨ feat(chat.py): add support for streaming the build process based on stored flow data
The fix adds a check for the client_id in the in_memory_cache before handling the websocket. This ensures that the flow has been built before sending messages.
The first feature adds support for storing graph data and returning a unique session ID for building the langchain object. This allows the user to build the flow and then send messages.
The second feature adds support for streaming the build process based on stored flow data. This allows the user to see the progress of the build process.
The test_chat_history test is outdated and no longer works with the current implementation of the application. It has been removed to avoid confusion and to keep the test suite clean.
🐛 fix(chatComponent): fix issue with progressEvent not being properly destructured
🚀 feat(chatComponent): add minimum loading time to improve user experience
The handleBuild function was refactored to use async/await and constants were extracted to improve readability. The issue with progressEvent not being properly destructured was fixed. A minimum loading time was added to improve user experience by ensuring that the loading spinner is displayed for at least a certain amount of time.
The return type of the generator_build method has been changed from List[Vertex] to Generator to improve the semantics of the method. The method now yields each vertex in the graph instead of returning a list of vertices.
🔥 refactor(utils.py): remove unused imports and dependencies
The changes remove unused imports and dependencies from the codebase, which improves the code's readability and maintainability.
The console.log statements were commented out in the tabsContext.tsx, EditNodeModal/index.tsx, NodeToolbarComponent/index.tsx, and FlowPage/index.tsx files to remove unnecessary logging in the console.
The handleBuild function has been refactored to process data in chunks instead of waiting for the entire response to be received. This improves the performance of the function and allows for real-time updates. The SSE context has been added to update the data in real-time as it is received.
🔨 refactor(chatComponent): refactor handleBuild function to process data in chunks
🎉 feat(SSEContext.tsx): add SSEContext and SSEProvider components to handle server-sent events
The SSEProvider component was added to the App component to provide the SSEContext to the TabsManagerComponent. The SSEContext component was also added to handle server-sent events. The SSEContext component provides a way to update the sseData state and to access the sseData state from any component that uses the useSSE hook.
🐛 fix(chat.py): fix generator_build method to yield node_repr and node_id
✨ feat(chat.py): add valid and id fields to error response to improve error handling
🔧 refactor(manager.py): change logger.exception to logger.error to log exceptions
🔧 refactor(graph/base.py): add logging to generator_build method to improve debugging
🔧 refactor(vertex/base.py): rename cache.base to cache.utils to improve semantics
The post_build method in chat.py was renamed to stream_build to better reflect its functionality. The generator_build method in graph/base.py was fixed to yield node_repr and node_id instead of node._built_object_repr() and node.id. The error response in chat.py now includes valid and id fields to improve error handling. logger.exception in manager.py was changed to logger.error to log exceptions. The generator_build method in graph/base.py now logs the sorted vertices to improve debugging. The cache.base module in vertex/base.py was renamed to cache.utils to better reflect its functionality.
✨ feat(chat.py): add SSE support to post_build endpoint to stream build progress to the client
The post_build endpoint now returns a StreamingResponse object that streams Server-Sent Events (SSE) to the client. This allows the client to receive build progress updates in real-time. The event_stream function is responsible for generating the SSE events and is called by the StreamingResponse object. The SSE events contain information about the build progress, including whether the build was successful or not, the parameters used to build each node, and the node ID. The chat_manager.set_cache method is called to cache the built graph object.
🔥 refactor(manager.py): remove unused build method and rename set_cache to set_client_cache
🚀 chore(manager.py): add async keyword to close_connection method
The close_connection method now accepts an integer as the status parameter instead of a status enum. The build method was removed as it was not being used. The set_cache method was renamed to set_client_cache to improve semantics. The close_connection method was updated to be an async method.
🚀 feat(base.py): add generator_build method to build each node in the graph and yield it
The topological_sort method performs a topological sort of the vertices in the graph, returning a list of vertices in topological order. The generator_build method builds each node in the graph and yields it. These methods are useful for building the graph in a specific order, which is important for certain algorithms that rely on the order of the nodes.
✨ feat(chatComponent): add loading animation to build trigger component
The BuildTrigger component is added to the chatComponent to allow users to build a flow. The component is triggered by clicking on a button and sends a POST request to the server to build the flow. A loading animation is added to the component to indicate that the flow is being built. The postBuild function is added to the API controller to handle the POST request.
✨ feat(chatComponent): add BuildTrigger component to check if flow is built before showing ChatTrigger component
The ChatTrigger component now checks if the flow is built before allowing the user to open the chat. If the flow is not built, an error message is displayed instead. The BuildTrigger component is added to check if the flow is built before showing the ChatTrigger component. This improves the user experience by preventing the user from opening the chat before the flow is built.