flowchart LR %% Define colors for modules classDef mainServiceAiStyle fill:#e3f2fd,stroke:#1976d2,stroke-width:3px classDef serviceExtractionStyle fill:#fce4ec,stroke:#c2185b,stroke-width:3px classDef serviceGenerationStyle fill:#e0f2f1,stroke:#00796b,stroke-width:3px classDef serviceUtilsStyle fill:#fff9e0,stroke:#f57f17,stroke-width:3px classDef interfacesStyle fill:#f3e5f5,stroke:#7b1fa2,stroke-width:3px %% Declare all function nodes first callAiPlanning[callAiPlanning] callAiDocuments[callAiDocuments] callAiText[callAiText] _ensureAiObjectsInitialized[_ensureAiObjectsInitialized] _initializeSubmodules[_initializeSubmodules] _buildPromptWithPlaceholders[_buildPromptWithPlaceholders] _analyzePromptAndCreateOptions[_analyzePromptAndCreateOptions] _callAiWithLooping[_callAiWithLooping] _extractSectionsFromResponse[_extractSectionsFromResponse] _shouldContinueGeneration[_shouldContinueGeneration] _buildFinalResultFromSections[_buildFinalResultFromSections] create[create] ExtractionServiceExtract[ExtractionService.extractContent] mergeAiResults[ExtractionService.mergeAiResults] _mergeConcatenate[ExtractionService._mergeConcatenate] _mergeHierarchical[ExtractionService._mergeHierarchical] _mergeIntelligent[ExtractionService._mergeIntelligent] _mergeTextIntelligent[ExtractionService._mergeTextIntelligent] _mergeTableIntelligent[ExtractionService._mergeTableIntelligent] _mergeStructureIntelligent[ExtractionService._mergeStructureIntelligent] processDocumentsPerChunk[processDocumentsPerChunk] _processPartsWithMapping[_processPartsWithMapping] _mergePartResults[_mergePartResults] runExtraction[subPipeline.runExtraction] _applyMerging[_applyMerging] GenerationServiceRender[GenerationService.renderReport] processActionResultDocuments[GenerationService.processActionResultDocuments] processSingleDocument[GenerationService.processSingleDocument] createDocumentsFromActionResult[GenerationService.createDocumentsFromActionResult] _setDocumentWorkflowContext[GenerationService._setDocumentWorkflowContext] _createDocument[GenerationService._createDocument] _getFileInfo[GenerationService._getFileInfo] _getWorkflowContext[GenerationService._getWorkflowContext] _getWorkflowStats[GenerationService._getWorkflowStats] getAdaptiveExtractionPrompt[GenerationService.getAdaptiveExtractionPrompt] _getFormatRenderer[GenerationService._getFormatRenderer] buildGenerationPrompt[buildGenerationPrompt] sanitizePromptContent[sanitizePromptContent] writeDebugFile[writeDebugFile] jsonExtractString[jsonExtractString] eventRegisterCron[eventRegisterCron] eventRegisterInterval[eventRegisterInterval] eventRemove[eventRemove] configGet[configGet] timestampGetUtc[timestampGetUtc] debugLogToFile[debugLogToFile] storeDebugMessageAndDocuments[storeDebugMessageAndDocuments] writeDebugArtifact[writeDebugArtifact] jsonStripCodeFences[jsonStripCodeFences] jsonExtractFirstBalanced[jsonExtractFirstBalanced] jsonNormalizeText[jsonNormalizeText] jsonTryParse[jsonTryParse] jsonParseOrRaise[jsonParseOrRaise] jsonMergeRootLists[jsonMergeRootLists] mapToEnum[mapToEnum] AiObjectsCall[AiObjects.call] _discoverAndRegisterConnectors[AiObjects._discoverAndRegisterConnectors] _selectModel[AiObjects._selectModel] _callWithTextContext[AiObjects._callWithTextContext] _callWithContentParts[AiObjects._callWithContentParts] _processContentPartWithFallback[AiObjects._processContentPartWithFallback] _chunkContentPart[AiObjects._chunkContentPart] _mergePartResultsInterface[AiObjects._mergePartResults] _mergeChunkResults[AiObjects._mergeChunkResults] _createErrorResponse[AiObjects._createErrorResponse] _callWithModel[AiObjects._callWithModel] listAvailableModels[listAvailableModels] getModelInfo[getModelInfo] getModelsByTag[getModelsByTag] %% Module subgraphs with functions subgraph mainServiceAi[mainServiceAi] callAiPlanning callAiDocuments callAiText create _ensureAiObjectsInitialized _initializeSubmodules _buildPromptWithPlaceholders _analyzePromptAndCreateOptions _callAiWithLooping _extractSectionsFromResponse _shouldContinueGeneration _buildFinalResultFromSections end subgraph serviceExtraction[serviceExtraction] ExtractionServiceExtract mergeAiResults _mergeConcatenate _mergeHierarchical _mergeIntelligent _mergeTextIntelligent _mergeTableIntelligent _mergeStructureIntelligent processDocumentsPerChunk _processPartsWithMapping _mergePartResults runExtraction end subgraph serviceGeneration[serviceGeneration] GenerationServiceRender processActionResultDocuments processSingleDocument createDocumentsFromActionResult _setDocumentWorkflowContext _createDocument _getFileInfo _getWorkflowContext _getWorkflowStats getAdaptiveExtractionPrompt _getFormatRenderer buildGenerationPrompt end subgraph serviceUtils[serviceUtils] sanitizePromptContent writeDebugFile jsonExtractString eventRegisterCron eventRegisterInterval eventRemove configGet timestampGetUtc debugLogToFile storeDebugMessageAndDocuments writeDebugArtifact jsonStripCodeFences jsonExtractFirstBalanced jsonNormalizeText jsonTryParse jsonParseOrRaise jsonMergeRootLists mapToEnum end subgraph interfaces[interfaces] AiObjectsCall _discoverAndRegisterConnectors _selectModel _callWithTextContext _callWithContentParts _processContentPartWithFallback _chunkContentPart _mergePartResultsInterface _mergeChunkResults _createErrorResponse _callWithModel _applyMerging listAvailableModels getModelInfo getModelsByTag end %% Apply colors to subgraphs class mainServiceAi mainServiceAiStyle class serviceExtraction serviceExtractionStyle class serviceGeneration serviceGenerationStyle class serviceUtils serviceUtilsStyle class interfaces interfacesStyle %% mainServiceAi function calls (USED FUNCTIONS) callAiPlanning --> _ensureAiObjectsInitialized callAiPlanning --> _buildPromptWithPlaceholders callAiPlanning --> AiObjectsCall callAiPlanning --> writeDebugFile callAiDocuments --> _ensureAiObjectsInitialized callAiDocuments --> _analyzePromptAndCreateOptions callAiDocuments --> AiObjectsCall callAiDocuments --> _callAiWithLooping callAiDocuments --> callAiText callAiDocuments --> buildGenerationPrompt callAiDocuments --> GenerationServiceRender callAiDocuments --> writeDebugFile callAiDocuments --> jsonExtractString callAiText --> _ensureAiObjectsInitialized callAiText --> processDocumentsPerChunk create --> AiObjectsCall create --> ExtractionServiceExtract _ensureAiObjectsInitialized --> _initializeSubmodules _initializeSubmodules --> ExtractionServiceExtract _analyzePromptAndCreateOptions --> AiObjectsCall _analyzePromptAndCreateOptions --> sanitizePromptContent _callAiWithLooping --> AiObjectsCall _callAiWithLooping --> _extractSectionsFromResponse _callAiWithLooping --> _shouldContinueGeneration _callAiWithLooping --> _buildFinalResultFromSections _callAiWithLooping --> writeDebugFile _buildPromptWithPlaceholders --> sanitizePromptContent _extractSectionsFromResponse --> writeDebugFile %% serviceExtraction function calls (USED FUNCTIONS) ExtractionServiceExtract --> runExtraction ExtractionServiceExtract --> writeDebugFile runExtraction --> _applyMerging processDocumentsPerChunk --> ExtractionServiceExtract processDocumentsPerChunk --> _processPartsWithMapping processDocumentsPerChunk --> _mergePartResults processDocumentsPerChunk --> writeDebugFile _processPartsWithMapping --> AiObjectsCall _mergePartResults --> _applyMerging runExtraction --> _applyMerging mergeAiResults --> _mergeConcatenate mergeAiResults --> _mergeHierarchical mergeAiResults --> _mergeIntelligent _mergeIntelligent --> _mergeTextIntelligent _mergeIntelligent --> _mergeTableIntelligent _mergeIntelligent --> _mergeStructureIntelligent _mergeTextIntelligent --> _mergeConcatenate _mergeTableIntelligent --> _mergeConcatenate _mergeStructureIntelligent --> _mergeConcatenate %% serviceGeneration function calls (USED FUNCTIONS) GenerationServiceRender --> _getFormatRenderer processActionResultDocuments --> processSingleDocument createDocumentsFromActionResult --> processActionResultDocuments createDocumentsFromActionResult --> _createDocument createDocumentsFromActionResult --> _setDocumentWorkflowContext _createDocument --> _getFileInfo _setDocumentWorkflowContext --> _getWorkflowContext _setDocumentWorkflowContext --> _getWorkflowStats _getWorkflowStats --> _getWorkflowContext getAdaptiveExtractionPrompt --> buildGenerationPrompt %% interfaces function calls (USED FUNCTIONS) AiObjectsCall --> _callWithTextContext AiObjectsCall --> _callWithContentParts _callWithTextContext --> _selectModel _callWithTextContext --> _callWithModel _callWithContentParts --> _processContentPartWithFallback _callWithContentParts --> _mergePartResultsInterface _processContentPartWithFallback --> _chunkContentPart _processContentPartWithFallback --> _callWithModel _processContentPartWithFallback --> _mergeChunkResults _mergePartResultsInterface --> _applyMerging _mergeChunkResults --> _applyMerging