-
-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Feat: Add flow versioning system with master-version pattern #5632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AhmedRaafat14
wants to merge
7
commits into
FlowiseAI:main
Choose a base branch
from
AhmedRaafat14:feat/add-flow-versioning
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3e90453
feat: Add flow versioning system with master-version pattern
AhmedRaafat14 f6eb7f8
fix: apply gemini code review to the code
AhmedRaafat14 d3d07f2
Update all BE services to use the new versioning system
AhmedRaafat14 893c38c
Allow predictions query specific version to test unpulished versions
AhmedRaafat14 82e392b
chore: imrpove the code maintainbility
AhmedRaafat14 19f7a57
Improve reusibility of some functions
AhmedRaafat14 6825d11
Merge branch 'main' into feat/add-flow-versioning
AhmedRaafat14 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 218 additions & 0 deletions
218
packages/server/src/controllers/chatflow-versions/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| import { NextFunction, Request, Response } from 'express' | ||
| import { StatusCodes } from 'http-status-codes' | ||
| import { InternalFlowiseError } from '../../errors/internalFlowiseError' | ||
| import chatflowVersionsService from '../../services/chatflow-versions' | ||
|
|
||
| /** | ||
| * Get all versions for a chatflow | ||
| */ | ||
| const getAllVersions = async (req: Request, res: Response, next: NextFunction) => { | ||
| try { | ||
| if (!req.params.id) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.PRECONDITION_FAILED, | ||
| `Error: chatflowVersionsController.getAllVersions - id not provided!` | ||
| ) | ||
| } | ||
|
|
||
| const workspaceId = req.user?.activeWorkspaceId | ||
| if (!workspaceId) { | ||
| throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Error: chatflowVersionsController.getAllVersions - workspace not found!`) | ||
| } | ||
|
|
||
| const apiResponse = await chatflowVersionsService.getAllVersions(req.params.id, workspaceId) | ||
| return res.json(apiResponse) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get a specific version | ||
| */ | ||
| const getVersion = async (req: Request, res: Response, next: NextFunction) => { | ||
| try { | ||
| if (!req.params.id || !req.params.version) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.PRECONDITION_FAILED, | ||
| `Error: chatflowVersionsController.getVersion - id or version not provided!` | ||
| ) | ||
| } | ||
|
|
||
| const workspaceId = req.user?.activeWorkspaceId | ||
| if (!workspaceId) { | ||
| throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Error: chatflowVersionsController.getVersion - workspace not found!`) | ||
| } | ||
|
|
||
| const versionNumber = parseInt(req.params.version, 10) | ||
| if (isNaN(versionNumber)) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.BAD_REQUEST, | ||
| `Error: chatflowVersionsController.getVersion - invalid version number!` | ||
| ) | ||
| } | ||
|
|
||
| const apiResponse = await chatflowVersionsService.getVersion(req.params.id, versionNumber, workspaceId) | ||
| return res.json(apiResponse) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create a new version | ||
| */ | ||
| const createVersion = async (req: Request, res: Response, next: NextFunction) => { | ||
| try { | ||
| if (!req.params.id) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.PRECONDITION_FAILED, | ||
| `Error: chatflowVersionsController.createVersion - id not provided!` | ||
| ) | ||
| } | ||
|
|
||
| if (!req.body) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.PRECONDITION_FAILED, | ||
| `Error: chatflowVersionsController.createVersion - body not provided!` | ||
| ) | ||
| } | ||
|
|
||
| const workspaceId = req.user?.activeWorkspaceId | ||
| if (!workspaceId) { | ||
| throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Error: chatflowVersionsController.createVersion - workspace not found!`) | ||
| } | ||
|
|
||
| const versionData = { | ||
| ...req.body, | ||
| createdBy: req.user?.email || req.user?.name | ||
| } | ||
|
|
||
| const apiResponse = await chatflowVersionsService.createVersion(req.params.id, workspaceId, versionData) | ||
| return res.json(apiResponse) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Update a version | ||
| */ | ||
| const updateVersion = async (req: Request, res: Response, next: NextFunction) => { | ||
| try { | ||
| if (!req.params.id || !req.params.version) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.PRECONDITION_FAILED, | ||
| `Error: chatflowVersionsController.updateVersion - id or version not provided!` | ||
| ) | ||
| } | ||
|
|
||
| if (!req.body) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.PRECONDITION_FAILED, | ||
| `Error: chatflowVersionsController.updateVersion - body not provided!` | ||
| ) | ||
| } | ||
|
|
||
| const workspaceId = req.user?.activeWorkspaceId | ||
| if (!workspaceId) { | ||
| throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Error: chatflowVersionsController.updateVersion - workspace not found!`) | ||
| } | ||
|
|
||
| const versionNumber = parseInt(req.params.version, 10) | ||
| if (isNaN(versionNumber)) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.BAD_REQUEST, | ||
| `Error: chatflowVersionsController.updateVersion - invalid version number!` | ||
| ) | ||
| } | ||
|
|
||
| const apiResponse = await chatflowVersionsService.updateVersion(req.params.id, versionNumber, workspaceId, req.body) | ||
| return res.json(apiResponse) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Set active version | ||
| */ | ||
| const setActiveVersion = async (req: Request, res: Response, next: NextFunction) => { | ||
| try { | ||
| if (!req.params.id) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.PRECONDITION_FAILED, | ||
| `Error: chatflowVersionsController.setActiveVersion - id not provided!` | ||
| ) | ||
| } | ||
|
|
||
| if (!req.body || req.body.version === undefined) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.PRECONDITION_FAILED, | ||
| `Error: chatflowVersionsController.setActiveVersion - version not provided!` | ||
| ) | ||
| } | ||
|
|
||
| const workspaceId = req.user?.activeWorkspaceId | ||
| if (!workspaceId) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.NOT_FOUND, | ||
| `Error: chatflowVersionsController.setActiveVersion - workspace not found!` | ||
| ) | ||
| } | ||
|
|
||
| const versionNumber = parseInt(req.body.version, 10) | ||
| if (isNaN(versionNumber)) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.BAD_REQUEST, | ||
| `Error: chatflowVersionsController.setActiveVersion - invalid version number!` | ||
| ) | ||
| } | ||
|
|
||
| await chatflowVersionsService.setActiveVersion(req.params.id, versionNumber, workspaceId) | ||
| return res.json({ success: true, message: `Version ${versionNumber} is now active` }) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Delete a version | ||
| */ | ||
| const deleteVersion = async (req: Request, res: Response, next: NextFunction) => { | ||
| try { | ||
| if (!req.params.id || !req.params.version) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.PRECONDITION_FAILED, | ||
| `Error: chatflowVersionsController.deleteVersion - id or version not provided!` | ||
| ) | ||
| } | ||
|
|
||
| const workspaceId = req.user?.activeWorkspaceId | ||
| if (!workspaceId) { | ||
| throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Error: chatflowVersionsController.deleteVersion - workspace not found!`) | ||
| } | ||
|
|
||
| const versionNumber = parseInt(req.params.version, 10) | ||
| if (isNaN(versionNumber)) { | ||
| throw new InternalFlowiseError( | ||
| StatusCodes.BAD_REQUEST, | ||
| `Error: chatflowVersionsController.deleteVersion - invalid version number!` | ||
| ) | ||
| } | ||
|
|
||
| await chatflowVersionsService.deleteVersion(req.params.id, versionNumber, workspaceId) | ||
| return res.json({ success: true, message: `Version ${versionNumber} deleted successfully` }) | ||
| } catch (error) { | ||
| next(error) | ||
| } | ||
| } | ||
|
|
||
| export default { | ||
| getAllVersions, | ||
| getVersion, | ||
| createVersion, | ||
| updateVersion, | ||
| setActiveVersion, | ||
| deleteVersion | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.