plugin-flow-builder: create utils folder and split in diferent files#3194
Merged
Iru89 merged 3 commits intorefactor-track-nodes-and-do-handoff-or-actionsfrom Mar 30, 2026
Merged
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
131622f to
d9f832c
Compare
vanbasten17
approved these changes
Mar 27, 2026
packages/botonic-plugin-flow-builder/src/utils/get-flow-builder-plugin.ts
Show resolved
Hide resolved
5946f45
into
refactor-track-nodes-and-do-handoff-or-actions
4 checks passed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR refactors the internal architecture of
botonic-plugin-flow-builderby reorganising utility helpers into a dedicatedutils/folder, splitting the monolithic action orchestration logic into smaller focused modules, and replacingActionRequestwithBotContextacross the board. It also introduces an abstractprocessContentmethod on every content field so that side effects (tracking, handoff, bot actions, AI agent resolution) are encapsulated inside each content type rather than centralised inFlowBuilderAction.Context
The previous code mixed orchestration (which content to fetch) with rendering side effects (tracking events, executing handoffs, resolving AI agent responses) inside
action/index.tsx. This made it hard to follow the execution flow, reuse individual pieces, and unit-test them in isolation. Additionally, helper functions were scattered acrosshelpers.tsand ad-hoc files with no clear grouping strategy. The refactor creates a clean separation of concerns aligned with the existing content-field model.Approach taken / Explain the design
1. New
src/utils/folderFour focused utility modules replace the old
helpers.tscatch-all:utils/get-flow-builder-plugin.tsBotonicPluginFlowBuilderinstance from the plugin registry. Previously lived inhelpers.ts.utils/ai-agent.tssplitAiAgentContents()helper +HubtypeAssistantContentadapter class that convertsFlowContentobjects to plain-text strings for AI assistant context.utils/input.tsinputHasTextOrTranscript,getTextOrTranscript) and NLU shadowing checks (isKeywordsAllowed,isSmartIntentsAllowed,isKnowledgeBasesAllowed).utils/token.tsresolveGetAccessToken()— selects the correct token-retrieval strategy depending onNODE_ENV.2.
action/context.ts— shared context objectExtracts the
FlowBuilderContextinterface (cmsApi,flowBuilderPlugin,request,resolvedLocale,contentID) and its factory functiongetFlowBuilderActionContext()into a standalone module. Every action module now receives a typed context instead of constructing it inline.3.
action/get-contents.ts— content-routing orchestratorMoves the
getContents()routing logic (first interaction, payload, AI agent, knowledge base, fallback) out ofaction/index.tsxinto its own module.FlowBuilderAction.botonicInitnow simply delegates togetContents()+prepareContentsToRender().4.
action/ai-agent-from-user-input.ts— replacesaction/ai-agent/index.tsThe old
getContentsByAiAgentfunction (and its internal structured-output wiring) is replaced by a thingetContentsByAiAgentFromUserInputthat delegates the heavy lifting to theFlowAiAgentcontent field directly. The deleted folderaction/ai-agent/is no longer needed.5. Abstract
processContentonContentFieldsBaseA new abstract method
processContent(botContext: BotContext): Promise<void>is added to the base class. Each content field implements it to perform its own side effects (track event, execute handoff, run bot action, resolve AI agent response).FlowBuilderAction.prepareContentsToRendernow iterates over filtered contents and callscontent.processContent(), makingtrackAllContentsanddoHandoffAndBotActionsunnecessary.6.
FlowAiAgentbecomes self-containedAll AI agent inference logic previously scattered in
action/ai-agent/index.tsis moved intoFlowAiAgent:resolveAIAgentResponse(botContext, previousContents?)— orchestrates inference, tracking, message parsing, and JSX generation.getAIAgentResponse(botContext, previousContents?)— calls the underlying inference API.responsesarray toaiAgentResponse,messages, andjsxElementsfor clearer lifecycle semantics.7.
ActionRequest→BotContextThroughout
ContentFieldsBase,FlowBuilderAction, and every content field,ActionRequest(from@botonic/react) is replaced byBotContext(from@botonic/core) to reduce the dependency on the React layer in pure-logic modules.8. WhatsApp Button List —
toBotonicrenametoBotonicfunctions inflow-whatsapp-button-list-section.tsxandflow-whatsapp-button-list-row.tsxare renamed to be consistent with the rest of the content field naming convention, and a newwhatsapp-button-list/index.tsbarrel is added.