MCPcopy
hub / github.com/FlowiseAI/Flowise / createAssistant

Function createAssistant

packages/server/src/controllers/assistants/index.ts:9–44  ·  view source on GitHub ↗
(req: Request, res: Response, next: NextFunction)

Source from the content-addressed store, hash-verified

7import { checkUsageLimit } from '../../utils/quotaUsage'
8
9const createAssistant = async (req: Request, res: Response, next: NextFunction) => {
10 try {
11 if (!req.body) {
12 throw new InternalFlowiseError(
13 StatusCodes.PRECONDITION_FAILED,
14 `Error: assistantsController.createAssistant - body not provided!`
15 )
16 }
17 const body = req.body
18 const orgId = req.user?.activeOrganizationId
19 if (!orgId) {
20 throw new InternalFlowiseError(
21 StatusCodes.NOT_FOUND,
22 `Error: assistantsController.createAssistant - organization ${orgId} not found!`
23 )
24 }
25 const workspaceId = req.user?.activeWorkspaceId
26 if (!workspaceId) {
27 throw new InternalFlowiseError(
28 StatusCodes.NOT_FOUND,
29 `Error: assistantsController.createAssistant - workspace ${workspaceId} not found!`
30 )
31 }
32 const subscriptionId = req.user?.activeOrganizationSubscriptionId || ''
33
34 const existingAssistantCount = await assistantsService.getAssistantsCountByOrganization(body.type, orgId)
35 const newAssistantCount = 1
36 await checkUsageLimit('flows', subscriptionId, getRunningExpressApp().usageCacheManager, existingAssistantCount + newAssistantCount)
37
38 const apiResponse = await assistantsService.createAssistant(body, orgId, workspaceId)
39
40 return res.json(apiResponse)
41 } catch (error) {
42 next(error)
43 }
44}
45
46const deleteAssistant = async (req: Request, res: Response, next: NextFunction) => {
47 try {

Callers

nothing calls this directly

Calls 2

checkUsageLimitFunction · 0.90
getRunningExpressAppFunction · 0.90

Tested by

no test coverage detected