(importData: ExportData, orgId: string, activeWorkspaceId: string, subscriptionId: string)
| 619 | } |
| 620 | |
| 621 | const importData = async (importData: ExportData, orgId: string, activeWorkspaceId: string, subscriptionId: string) => { |
| 622 | // Initialize missing properties with empty arrays to avoid "undefined" errors |
| 623 | importData.AgentFlow = importData.AgentFlow || [] |
| 624 | importData.AgentFlowV2 = importData.AgentFlowV2 || [] |
| 625 | importData.AssistantCustom = importData.AssistantCustom || [] |
| 626 | importData.AssistantFlow = importData.AssistantFlow || [] |
| 627 | importData.AssistantOpenAI = importData.AssistantOpenAI || [] |
| 628 | importData.AssistantAzure = importData.AssistantAzure || [] |
| 629 | importData.ChatFlow = importData.ChatFlow || [] |
| 630 | importData.ChatMessage = importData.ChatMessage || [] |
| 631 | importData.ChatMessageFeedback = importData.ChatMessageFeedback || [] |
| 632 | importData.CustomTemplate = importData.CustomTemplate || [] |
| 633 | importData.DocumentStore = importData.DocumentStore || [] |
| 634 | importData.DocumentStoreFileChunk = importData.DocumentStoreFileChunk || [] |
| 635 | importData.Execution = importData.Execution || [] |
| 636 | importData.Tool = importData.Tool || [] |
| 637 | importData.Variable = importData.Variable || [] |
| 638 | |
| 639 | let queryRunner: QueryRunner |
| 640 | try { |
| 641 | queryRunner = getRunningExpressApp().AppDataSource.createQueryRunner() |
| 642 | await queryRunner.connect() |
| 643 | |
| 644 | try { |
| 645 | if (importData.AgentFlow.length > 0) { |
| 646 | importData.AgentFlow = reduceSpaceForChatflowFlowData(importData.AgentFlow) |
| 647 | importData.AgentFlow = insertWorkspaceId(importData.AgentFlow, activeWorkspaceId) |
| 648 | const existingChatflowCount = await chatflowService.getAllChatflowsCountByOrganization('MULTIAGENT', orgId) |
| 649 | const newChatflowCount = importData.AgentFlow.length |
| 650 | await checkUsageLimit( |
| 651 | 'flows', |
| 652 | subscriptionId, |
| 653 | getRunningExpressApp().usageCacheManager, |
| 654 | existingChatflowCount + newChatflowCount |
| 655 | ) |
| 656 | importData = await replaceDuplicateIdsForChatFlow(queryRunner, importData, importData.AgentFlow) |
| 657 | } |
| 658 | if (importData.AgentFlowV2.length > 0) { |
| 659 | importData.AgentFlowV2 = reduceSpaceForChatflowFlowData(importData.AgentFlowV2) |
| 660 | importData.AgentFlowV2 = insertWorkspaceId(importData.AgentFlowV2, activeWorkspaceId) |
| 661 | const existingChatflowCount = await chatflowService.getAllChatflowsCountByOrganization('AGENTFLOW', orgId) |
| 662 | const newChatflowCount = importData.AgentFlowV2.length |
| 663 | await checkUsageLimit( |
| 664 | 'flows', |
| 665 | subscriptionId, |
| 666 | getRunningExpressApp().usageCacheManager, |
| 667 | existingChatflowCount + newChatflowCount |
| 668 | ) |
| 669 | importData = await replaceDuplicateIdsForChatFlow(queryRunner, importData, importData.AgentFlowV2) |
| 670 | } |
| 671 | if (importData.AssistantCustom.length > 0) { |
| 672 | importData.AssistantCustom = insertWorkspaceId(importData.AssistantCustom, activeWorkspaceId) |
| 673 | const existingAssistantCount = await assistantsService.getAssistantsCountByOrganization('CUSTOM', orgId) |
| 674 | const newAssistantCount = importData.AssistantCustom.length |
| 675 | await checkUsageLimit( |
| 676 | 'flows', |
| 677 | subscriptionId, |
| 678 | getRunningExpressApp().usageCacheManager, |
nothing calls this directly
no test coverage detected