plugin-flow-builder: split, rename and reorganize files and functions#3191
Merged
Iru89 merged 4 commits intoBLT-2254-plugin-flow-builder-allow-go-to-flow-to-aia-gent-as-a-follow-upfrom Mar 30, 2026
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. |
vanbasten17
approved these changes
Mar 26, 2026
…nt-as-a-follow-up' into refactor-split-and-rename-files
…do handoff, do actions and resolve AI Agent response (#3193) ## Description Introduces a unified `processContent()` abstract method in the `ContentFieldsBase` class so that every content type handles its own side effects (handoff, bot action, AI agent response). Alongside this, the AI Agent node is now resolved as a follow-up within any content sequence, and it receives preceding contents as context for better conversation continuity. ## Context Previously, side effects such as triggering a handoff, redirecting via a bot action, or calling the AI Agent inference API were scattered across `FlowBuilderAction.botonicInit()` and helper functions in `action/index.tsx`. This made the flow of execution hard to follow and difficult to extend. Additionally, AI Agent nodes could only be triggered as a top-level flow entry point, preventing them from being combined with other content nodes (e.g., a text message before the agent response). The agent also lacked awareness of previously sent messages in the same interaction. Goals: - Decouple "which contents to show" from "what side effects each content triggers". - Enable AI Agent nodes to be positioned anywhere in a content sequence (as follow-ups). - Pass preceding contents as conversation context to the AI Agent. - Improve code organisation and testability by splitting large files into focused modules. ## Approach taken / Explain the design ### 1. Abstract `processContent()` in `ContentFieldsBase` ```typescript abstract processContent(botContext: BotContext): Promise<void> ``` Each subclass now owns its side effects: | Content class | `processContent` behavior | |---|---| | `FlowHandoff` | Calls `doHandoff()` | | `FlowBotAction` | Calls `doBotAction()` + `trackFlow()` | | `FlowAiAgent` | Calls `resolveAIAgentResponse()` | | Others (text, image, …) | Calls `trackFlow()` | `FlowBuilderAction.prepareContentsToRender()` now iterates filtered contents and calls `content.processContent()` uniformly: ```typescript for (const content of filteredContents) { if (content instanceof FlowAiAgent) { await content.processContent(botContext, contentsBeforeAiAgent) } else { await content.processContent(botContext) } } ``` ### 2. AI Agent resolved as a follow-up `FlowAiAgent` nodes can now appear anywhere in a content sequence. The `splitAiAgentContents()` helper separates the preceding contents from the agent node so they can be forwarded as context: ```typescript export function splitAiAgentContents(contents: FlowContent[]) { const aiAgentIndex = contents.findIndex(c => c instanceof FlowAiAgent) const aiAgentContent = contents[aiAgentIndex] as FlowAiAgent const contentsBeforeAiAgent = contents.slice(0, aiAgentIndex) return { aiAgentContent, contentsBeforeAiAgent } } ``` ### 3. Previous contents forwarded as `previousHubtypeMessages` When calling the inference API, the contents rendered before the agent node are mapped to `HubtypeAssistantMessage` objects and sent as `previousHubtypeMessages`, giving the AI Agent awareness of what was already shown to the user in the same turn. ### 4. File reorganisation The monolithic `action/index.tsx` and `action/ai-agent.ts` were split into focused modules: | New file | Responsibility | |---|---| | `action/context.ts` | `FlowBuilderContext` interface + factory function | | `action/get-contents.ts` | `getContents()` — routing logic to select which flow contents to load | | `action/ai-agent-from-user-input.ts` | `getContentsByAiAgentFromUserInput()` + `splitAiAgentContents()` | | `filters/index.ts` | `ContentFilterExecutor` + `filterContents()` | `FlowAiAgent` now owns tracking (`trackAiAgentResponse`) and response resolution (`resolveAIAgentResponse`, `getAIAgentResponse`, `messagesToBotonicJSXElements`), removing the need for standalone helpers in the action layer. ### 5. Removal of unused Go-To-Flow → AI Agent redirect code Dead code paths that redirected Go-To-Flow nodes to the AI Agents flow were removed from `FlowGoToFlow`, `FlowBuilderApi`, and `BotonicPluginFlowBuilder`. ## To document / Usage example No public API changes. The `processContent()` method is internal to the plugin and does not need to be called by end users. If you implement a custom `ContentFilter`, note that `processContent()` is now called **after** filtering in `prepareContentsToRender()`. Filters should remain pure transformations and must not trigger side effects.
8ec9aa3
into
BLT-2254-plugin-flow-builder-allow-go-to-flow-to-aia-gent-as-a-follow-up
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
Pure structural refactor of
botonic-plugin-flow-builderacross two commits: splits, renames, and relocates files and functions to reduce coupling, improve module boundaries, and align the internal API aroundBotContextinstead ofActionRequest. No logic changes — only file organisation, import updates, and signature alignments.Context
action/index.tsxwas doing too much: it definedFlowBuilderContext, thegetContextfactory,filterContents, and the fullgetContentsrouting logic, all alongside the React component. This forced all action modules (fallback.ts,knowledge-bases.ts,payload.ts, etc.) to import shared types from the entry-point file, creating unnecessary coupling.Additionally,
getContentsand the post-processing pipeline (filter → track → resolveAIAgent → handoff/botAction) were inlined insidebotonicInitandexecuteConversationStart, making them harder to reuse and test independently.Finally,
structured-output/flow-builder-content.tswas buried insideaction/ai-agent/, making it hard to discover and reuse from other modules.Approach taken / Explain the design
Files moved / renamed
action/ai-agent/index.tsaction/ai-agent-from-user-input.tsaction/ai-agent/structured-output/flow-builder-content.tsstructured-output/flow-builder-content.tsNew file:
action/context.tsExtracted from
action/index.tsx. Contains theFlowBuilderContextinterface and thegetFlowBuilderActionContextfactory (formerlygetContext). All action modules now importFlowBuilderContextfrom./contextinstead of./index.filterContentsmoved tofilters/index.tsExtracted from
action/index.tsxand added tofilters/index.ts, next toContentFilterExecutorwhere it logically belongs.Rename:
getContentsByAiAgent→getContentsByAiAgentFromUserInputClarifies that this function only handles the user-input routing path, not all AI agent invocations.
Import updates
fallback.ts,first-interaction.ts,knowledge-bases.ts,payload.ts,flow-ai-agent.tsx, andtypes.tsupdated to point to the new locations.New file:
action/get-contents.tsThe
getContentsrouting function (first interaction → payload → AI agent → knowledge base → fallback) was extracted fromaction/index.tsxinto its own file. Its signature now receivesBotContextinstead ofActionRequest:New static method:
FlowBuilderAction.processContentsThe repeated post-processing pipeline that appeared in both
botonicInitandexecuteConversationStartis now a single reusable method:ActionRequest→BotContextin static methodsexecuteConversationStart,botonicInit,trackAllContents, anddoHandoffAndBotActionsnow all receiveBotContextinstead ofActionRequest. This removes the dependency on the React-layer type from the core action logic and makes the functions usable in non-React contexts.Cleanup in
action/index.tsxRemoved now-unused imports:
INPUT,EMPTY_PAYLOAD,inputHasTextOrTranscript,getContentsByAiAgentFromUserInput,getContentsByFallback,getContentsByKnowledgeBase,getContentsByPayload.Testing
The pull request...