forked from i-am-bee/bee-agent-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchers.ts
28 lines (21 loc) · 780 Bytes
/
matchers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { Callback, Emitter } from "bee-agent-framework/emitter/emitter";
import { BaseLLM } from "bee-agent-framework/llms/base";
interface Events {
update: Callback<{ data: string }>;
}
const emitter = new Emitter<Events>({
namespace: ["app"],
});
// Match events by a concrete name (strictly typed)
emitter.on("update", async (data, event) => {});
// Match all events emitted directly on the instance (not nested)
emitter.match("*", async (data, event) => {});
// Match all events (included nested)
emitter.match("*.*", async (data, event) => {});
// Match events by providing a filter function
emitter.match(
(event) => event.creator instanceof BaseLLM,
async (data, event) => {},
);
// Match events by regex
emitter.match(/watsonx/, async (data, event) => {});