Summary
A compiled-regex event listener only fires when the pattern matches from the start of the event path, so patterns meant to match a path segment never match.
Details
Emitter._create_matcher (python/beeai_framework/emitter/emitter.py) handles the re.Pattern case with:
matchers.append(lambda event: matcher.match(event.path) is not None)
re.Pattern.match is anchored at the start of the string. The TypeScript sibling uses matcher.test() (search anywhere), and the shipped example does:
emitter.on(re.compile(r"watsonx"), ...) # examples/emitter/matchers.py
which is intended to match an event path like backend.watsonx.chat.start. With .match() it never fires.
Reproduction
import asyncio, re
from beeai_framework.emitter import Emitter, EmitterOptions
async def main():
root = Emitter.root(); hits = []
root.on(re.compile(r"watsonx"), lambda _, e: hits.append(e.path), EmitterOptions(match_nested=True))
await root.child(namespace=["backend", "watsonx", "chat"]).emit("start", 1)
print(hits) # [] — expected ["backend.watsonx.chat.start"]
asyncio.run(main())
Expected
A compiled regex matches anywhere in the event path (like the TS .test()), so the listener fires.
Fix
Use matcher.search() instead of matcher.match() (.search is a superset of .match, so anchored patterns still match). PR to follow.
Summary
A compiled-regex event listener only fires when the pattern matches from the start of the event path, so patterns meant to match a path segment never match.
Details
Emitter._create_matcher(python/beeai_framework/emitter/emitter.py) handles there.Patterncase with:re.Pattern.matchis anchored at the start of the string. The TypeScript sibling usesmatcher.test()(search anywhere), and the shipped example does:which is intended to match an event path like
backend.watsonx.chat.start. With.match()it never fires.Reproduction
Expected
A compiled regex matches anywhere in the event path (like the TS
.test()), so the listener fires.Fix
Use
matcher.search()instead ofmatcher.match()(.searchis a superset of.match, so anchored patterns still match). PR to follow.