@@ -5,6 +5,7 @@ import { BackendSwitcher } from './components/BackendSwitcher'
55import { BackendSwitcherInline } from './components/BackendSwitcherInline'
66import {
77 routeInput ,
8+ routeEventTagInput ,
89 getButlerSystemPrompt ,
910 wrapInputForAgent ,
1011 loadAgentsFromSession ,
@@ -13,7 +14,8 @@ import {
1314 resolveModelForAgent ,
1415 type RoutingDecision ,
1516 type AgentMatch ,
16- type AgentBox
17+ type AgentBox ,
18+ type EventTagRoutingBatch
1719} from './services/processFlow'
1820import { nlpClassifier , type ClassifiedInput } from './nlp'
1921import { inputCoordinator } from './services/InputCoordinator'
@@ -1331,6 +1333,54 @@ function SidepanelOrchestrator() {
13311333 return { processedMessages, ocrText }
13321334 }
13331335
1336+ /**
1337+ * Generate match detection feedback message for Event Tag routing
1338+ * Displays which agents matched which triggers in the chat
1339+ */
1340+ const generateEventTagMatchFeedback = ( batch : EventTagRoutingBatch ) : string => {
1341+ if ( batch . results . length === 0 ) {
1342+ return ''
1343+ }
1344+
1345+ const lines : string [ ] = [ '🟢 **Match Detected**\n' ]
1346+
1347+ for ( const result of batch . results ) {
1348+ const agentNum = result . agentNumber
1349+ ? `#${ String ( result . agentNumber ) . padStart ( 2 , '0' ) } `
1350+ : ''
1351+ const agentLabel = agentNum
1352+ ? `Agent ${ agentNum } (${ result . agentName } )`
1353+ : result . agentName
1354+
1355+ lines . push ( `• **${ agentLabel } ** → matched \`${ result . trigger . tag } \`` )
1356+ lines . push ( ` • Trigger type: Event Trigger (${ result . trigger . type } )` )
1357+
1358+ // Show condition results
1359+ if ( result . conditionResults . conditions . length > 0 ) {
1360+ const conditionSummary = result . conditionResults . allPassed
1361+ ? '✓ All conditions passed'
1362+ : '⚠️ Some conditions not met'
1363+ lines . push ( ` • Conditions: ${ conditionSummary } ` )
1364+ }
1365+
1366+ // Show LLM and destination info
1367+ if ( result . llmConfig . isAvailable ) {
1368+ lines . push ( ` • LLM: ${ result . llmConfig . provider } /${ result . llmConfig . model } ` )
1369+ }
1370+ if ( result . executionConfig . reportTo . length > 0 ) {
1371+ const destinations = result . executionConfig . reportTo . map ( r => r . label ) . join ( ', ' )
1372+ lines . push ( ` • Output: ${ destinations } ` )
1373+ }
1374+
1375+ lines . push ( '' ) // Empty line between agents
1376+ }
1377+
1378+ // Add summary
1379+ lines . push ( `_${ batch . results . length } agent(s) matched from ${ batch . triggersFound . length } trigger(s) detected_` )
1380+
1381+ return lines . join ( '\n' )
1382+ }
1383+
13341384 /**
13351385 * Process input through an agent with reasoning wrapping
13361386 * This is the core of the agent processing path
@@ -1794,6 +1844,42 @@ function SidepanelOrchestrator() {
17941844 )
17951845 } )
17961846
1847+ // =================================================================
1848+ // STEP 3.6: EVENT TAG ROUTING (Input Coordinator)
1849+ // Route through event tag flow to detect matches with agent listeners
1850+ // This checks all agents' triggers (#tags) and displays match feedback
1851+ // =================================================================
1852+ if ( nlpResult . input . triggers . length > 0 ) {
1853+ console . log ( '[Chat] Detected triggers, running Event Tag routing:' , nlpResult . input . triggers )
1854+
1855+ try {
1856+ const eventTagResult = await routeEventTagInput (
1857+ inputTextForNlp ,
1858+ ocrText ? 'ocr' : 'inline_chat' ,
1859+ currentUrl ,
1860+ sessionName
1861+ )
1862+
1863+ console . log ( '[Chat] Event Tag Routing Result:' , {
1864+ matchedAgents : eventTagResult . batch . results . length ,
1865+ triggersFound : eventTagResult . batch . triggersFound ,
1866+ summary : eventTagResult . batch . summary
1867+ } )
1868+
1869+ // Display match detection feedback if any agents matched
1870+ if ( eventTagResult . batch . results . length > 0 ) {
1871+ const matchFeedback = generateEventTagMatchFeedback ( eventTagResult . batch )
1872+ setChatMessages ( prev => [ ...prev , {
1873+ role : 'assistant' as const ,
1874+ text : matchFeedback
1875+ } ] )
1876+ scrollToBottom ( )
1877+ }
1878+ } catch ( eventTagError ) {
1879+ console . warn ( '[Chat] Event Tag routing error (non-fatal):' , eventTagError )
1880+ }
1881+ }
1882+
17971883 // =================================================================
17981884 // STEP 4: HANDLE ROUTING DECISION
17991885 // =================================================================
0 commit comments