Switch support agent to mqtt #7090
Conversation
- alter the way we deduce immersive entities in such a way that we have full contextual awareness throughout the app - rough mqtt implementation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7090 +/- ##
=======================================
Coverage 76.58% 76.59%
=======================================
Files 405 405
Lines 20580 20579 -1
Branches 4974 4975 +1
=======================================
Hits 15762 15762
+ Misses 4818 4817 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…cher to unsubscribe from stale topics and re-subscription
…into expert/switch-insights-to-mqtt
…ding messages and tool calls, handle assistant replies based on toolCall
…ig asterisk when re-creating the mqtt client and fixes to the topic builder
…onse method for awaiting responses
…into expert/switch-insights-to-mqtt
|
ready for review, leaving it as draft for the time being because we still need to remove the ci bits that enabled testing on pre-staging |
Steve-Mcl
left a comment
There was a problem hiding this comment.
Acknowledging this is a large PR (unavoidable mostly) but also acknowledging it has been dogfooded by 3 team members over last week it is good to go AFTER CI stuff is deleted.
| const { correlationId } = payloadData | ||
| const inflight = this.pendingRequests.get(correlationId) | ||
| if (inflight) { | ||
| // console.debug('Received response for in-flight request:', { correlationId, originalRequest: inflight.postMessagePayload, response: payloadData }) |
There was a problem hiding this comment.
| // console.debug('Received response for in-flight request:', { correlationId, originalRequest: inflight.postMessagePayload, response: payloadData }) |
Description
This PR switches the Expert assistant's communication layer from HTTP to MQTT for real-time bidirectional messaging, gated behind a PostHog feature flag (
isExpertCommsBetaEnabled). It also introduces admin UI for managing Expert agent MQTT broker credentials, improves contextual awareness across the app, and refactors several UI components.MQTT Communication Layer
MqttExpertTopicHelpercomposable: builds and parses structured MQTT topic paths (ff/v1/expert/<userId>/<sessionId>/<entityType>/<entityId>/<agentChannel>/<topicType>/<topicAction>) with full entity type resolution (application, instance, device, team).MqttService: addsdisconnect,end,reconnect,packetsend,packetreceive, andoutgoingEmptyevent handlers; introducesreconnectGenerationto prevent stale reconnect timers from firing; adds_killStaleClientfor forceful cleanup of zombie MQTT clients; fixes reconnect guard to skip when already connected/connecting; addsconnectHandlerPromiseto serialize connect handler work and prevent publish before subscribe races; switches internal_helpers toprivate; setskeepalive: 45; adds normalized reconnect policy defaults.FATAL_ERROR_CODES,TRANSIENT_ERROR_CODES,THROTTLED_ERROR_CODES,PROTOCOL_BUG_ERROR_CODES, andERRORS_WITHOUT_CODESto drive user facing error messaging with context appropriate language.Expert Store (
product-expert.js)sendQuery): routes throughsendMqttQueryorsendHttpQuerybased on the feature flag.establishMqttCommscreates a keyed MQTT client with dynamic credentials fromuserApi.initiateExpertChat; topic subscriptions happen in_onMqttConnectusing wildcard patterns;_onMqttMessagedispatches tohandleMessageResponse(chat replies) orhandleInFlightRequest(tool call in flight requests).expert:status-message(acks) andautomation:*(proxied to Node RED viainvokeActionAwaitResponse) in flight request types.stopInflightChat: clears in flight requests and updates when the user cancels mid flight.inFlightUpdates: surfaces real time tool call status/tool name updates to the loading indicator.Product Assistant Store
invokeActionAwaitResponse: new method that sends apostMessageto the immersive editor iframe and returns a promise that resolves when the correlated response arrives (or rejects after timeout); usespendingRequestsmap keyed by compositesessionId:chatTransactionId:transactionId.isImmersiveInstance/isImmersiveDevicegetters: replace the oldimmersiveInstance/immersiveDevicegetters to require both entity presence and immersive mode, fixing false positive immersive detection.targetOriginfix: uses contextStore directly instead of the old getters for postMessage target origin.Context Store & Mixins
isImmersiveflag: added to the context store, set/cleared by Instance and Device editors on mount/unmount.applicationin context: newsetApplicationaction; Application mixin now writes the contextual application into the store (and clears on unmount).Admin UI: Expert Agent Credentials
isExpertCommsBetaEnabledflag is active).adminApi.generateExpertAgentCreds()/adminApi.deleteExpertAgentCreds()anduserApi.initiateExpertChat().Infrastructure
projectCountcast to integer inProjectTemplateDB views to fix data type inconsistency.UI Improvements
ToolCallItemextracted into its own Vue component fromToolCalls, with collapsed list limited to 2 items and scrollable/expandable tool list (max 5 collapsed, 15 expanded).Shift+Alt+Dkeyboard shortcut to download expert messages as JSON.hydrateMessages: cleaner switch based logic since tool calls aren't received when ingesting website context.StreamableContent: rendering support for streamable content blocks.Caution
Changes made in
.github/workflows/branch-deploy.yamlandci/ci-values.yamlfiles are exclusive to this pull request and should be reverted before merge.Related Issue(s)
closes #6972
Checklist
flowforge.yml?FlowFuse/helmto update ConfigMap TemplateFlowFuse/CloudProjectto update values for Staging/ProductionLabels
area:migrationlabel