@agentica/core 0.7.0-dev.20250224-4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +404 -464
  3. package/package.json +2 -1
  4. package/prompts/cancel.md +4 -4
  5. package/prompts/common.md +2 -2
  6. package/prompts/describe.md +6 -6
  7. package/prompts/execute.md +6 -6
  8. package/prompts/initialize.md +2 -2
  9. package/prompts/select.md +6 -6
  10. package/src/Agentica.ts +322 -322
  11. package/src/chatgpt/ChatGptAgent.ts +71 -71
  12. package/src/chatgpt/ChatGptCallFunctionAgent.ts +445 -445
  13. package/src/chatgpt/ChatGptCancelFunctionAgent.ts +283 -283
  14. package/src/chatgpt/ChatGptDescribeFunctionAgent.ts +51 -51
  15. package/src/chatgpt/ChatGptHistoryDecoder.ts +86 -86
  16. package/src/chatgpt/ChatGptInitializeFunctionAgent.ts +88 -88
  17. package/src/chatgpt/ChatGptSelectFunctionAgent.ts +316 -316
  18. package/src/functional/createHttpLlmApplication.ts +63 -63
  19. package/src/index.ts +19 -19
  20. package/src/internal/AgenticaConstant.ts +4 -4
  21. package/src/internal/AgenticaCostAggregator.ts +35 -35
  22. package/src/internal/AgenticaDefaultPrompt.ts +39 -39
  23. package/src/internal/AgenticaOperationComposer.ts +82 -82
  24. package/src/internal/AgenticaPromptFactory.ts +30 -30
  25. package/src/internal/AgenticaPromptTransformer.ts +83 -83
  26. package/src/internal/MathUtil.ts +3 -3
  27. package/src/internal/Singleton.ts +22 -22
  28. package/src/internal/__map_take.ts +15 -15
  29. package/src/structures/IAgenticaConfig.ts +121 -121
  30. package/src/structures/IAgenticaContext.ts +128 -128
  31. package/src/structures/IAgenticaController.ts +130 -130
  32. package/src/structures/IAgenticaEvent.ts +224 -224
  33. package/src/structures/IAgenticaExecutor.ts +152 -152
  34. package/src/structures/IAgenticaOperation.ts +64 -64
  35. package/src/structures/IAgenticaOperationCollection.ts +50 -50
  36. package/src/structures/IAgenticaOperationSelection.ts +69 -69
  37. package/src/structures/IAgenticaPrompt.ts +173 -173
  38. package/src/structures/IAgenticaProps.ts +64 -64
  39. package/src/structures/IAgenticaProvider.ts +45 -45
  40. package/src/structures/IAgenticaSystemPrompt.ts +122 -122
  41. package/src/structures/IAgenticaTokenUsage.ts +52 -52
  42. package/src/structures/internal/__IChatCancelFunctionsApplication.ts +23 -23
  43. package/src/structures/internal/__IChatFunctionReference.ts +21 -21
  44. package/src/structures/internal/__IChatInitialApplication.ts +15 -15
  45. package/src/structures/internal/__IChatSelectFunctionsApplication.ts +24 -24
  46. package/src/typings/AgenticaSource.ts +6 -6
package/src/Agentica.ts CHANGED
@@ -1,322 +1,322 @@
1
- import OpenAI from "openai";
2
-
3
- import { ChatGptAgent } from "./chatgpt/ChatGptAgent";
4
- import { AgenticaCostAggregator } from "./internal/AgenticaCostAggregator";
5
- import { AgenticaOperationComposer } from "./internal/AgenticaOperationComposer";
6
- import { AgenticaPromptTransformer } from "./internal/AgenticaPromptTransformer";
7
- import { __map_take } from "./internal/__map_take";
8
- import { IAgenticaConfig } from "./structures/IAgenticaConfig";
9
- import { IAgenticaContext } from "./structures/IAgenticaContext";
10
- import { IAgenticaController } from "./structures/IAgenticaController";
11
- import { IAgenticaEvent } from "./structures/IAgenticaEvent";
12
- import { IAgenticaOperation } from "./structures/IAgenticaOperation";
13
- import { IAgenticaOperationCollection } from "./structures/IAgenticaOperationCollection";
14
- import { IAgenticaOperationSelection } from "./structures/IAgenticaOperationSelection";
15
- import { IAgenticaPrompt } from "./structures/IAgenticaPrompt";
16
- import { IAgenticaProps } from "./structures/IAgenticaProps";
17
- import { IAgenticaProvider } from "./structures/IAgenticaProvider";
18
- import { IAgenticaTokenUsage } from "./structures/IAgenticaTokenUsage";
19
-
20
- /**
21
- * Nestia A.I. chatbot agent.
22
- *
23
- * `Agentica` is a facade class for the super A.I. chatbot agent
24
- * which performs the {@link converstate user's conversation function}
25
- * with LLM (Large Language Model) function calling and manages the
26
- * {@link getPromptHistories prompt histories}.
27
- *
28
- * To understand and compose the `Agentica` class exactly, reference
29
- * below types concentrating on the documentation comments please.
30
- * Especially, you have to be careful about the {@link IAgenticaProps}
31
- * type which is used in the {@link constructor} function.
32
- *
33
- * - Constructors
34
- * - {@link IAgenticaProps}
35
- * - {@link IAgenticaProvider}
36
- * - {@link IAgenticaController}
37
- * - {@link IAgenticaConfig}
38
- * - {@link IAgenticaSystemPrompt}
39
- * - Accessors
40
- * - {@link IAgenticaOperation}
41
- * - {@link IAgenticaPrompt}
42
- * - {@link IAgenticaEvent}
43
- * - {@link IAgenticaTokenUsage}
44
- *
45
- * @author Samchon
46
- */
47
- export class Agentica {
48
- // THE OPERATIONS
49
- private readonly operations_: IAgenticaOperationCollection;
50
-
51
- // STACK
52
- private readonly stack_: IAgenticaOperationSelection[];
53
- private readonly prompt_histories_: IAgenticaPrompt[];
54
- private readonly listeners_: Map<string, Set<Function>>;
55
-
56
- // STATUS
57
- private readonly token_usage_: IAgenticaTokenUsage;
58
- private ready_: boolean;
59
- private readonly executor_: (
60
- ctx: IAgenticaContext,
61
- ) => Promise<IAgenticaPrompt[]>;
62
-
63
- /* -----------------------------------------------------------
64
- CONSTRUCTOR
65
- ----------------------------------------------------------- */
66
- /**
67
- * Initializer constructor.
68
- *
69
- * @param props Properties to construct the agent
70
- */
71
- public constructor(private readonly props: IAgenticaProps) {
72
- // OPERATIONS
73
- this.operations_ = AgenticaOperationComposer.compose({
74
- controllers: props.controllers,
75
- config: props.config,
76
- });
77
-
78
- // STATUS
79
- this.stack_ = [];
80
- this.listeners_ = new Map();
81
- this.prompt_histories_ = (props.histories ?? []).map((input) =>
82
- AgenticaPromptTransformer.transform({
83
- operations: this.operations_.group,
84
- input,
85
- }),
86
- );
87
-
88
- // STATUS
89
- this.token_usage_ = {
90
- total: 0,
91
- prompt: {
92
- total: 0,
93
- audio: 0,
94
- cached: 0,
95
- },
96
- completion: {
97
- total: 0,
98
- accepted_prediction: 0,
99
- audio: 0,
100
- reasoning: 0,
101
- rejected_prediction: 0,
102
- },
103
- };
104
- this.ready_ = false;
105
- this.executor_ =
106
- typeof props.config?.executor === "function"
107
- ? props.config.executor
108
- : ChatGptAgent.execute(props.config?.executor ?? null);
109
- }
110
-
111
- /**
112
- * @internal
113
- */
114
- public clone(): Agentica {
115
- return new Agentica({
116
- ...this.props,
117
- histories: this.props.histories?.slice(),
118
- });
119
- }
120
-
121
- /* -----------------------------------------------------------
122
- ACCESSORS
123
- ----------------------------------------------------------- */
124
- /**
125
- * Conversate with the A.I. chatbot.
126
- *
127
- * User talks to the A.I. chatbot with the content.
128
- *
129
- * When the user's conversation implies the A.I. chatbot to execute a
130
- * function calling, the returned chat prompts will contain the
131
- * function calling information like {@link IAgenticaPrompt.IExecute}.
132
- *
133
- * @param content The content to talk
134
- * @returns List of newly created chat prompts
135
- */
136
- public async conversate(content: string): Promise<IAgenticaPrompt[]> {
137
- const prompt: IAgenticaPrompt.IText<"user"> = {
138
- type: "text",
139
- role: "user",
140
- text: content,
141
- };
142
- await this.dispatch(prompt);
143
-
144
- const newbie: IAgenticaPrompt[] = await this.executor_(
145
- this.getContext({
146
- prompt,
147
- usage: this.token_usage_,
148
- }),
149
- );
150
- this.prompt_histories_.push(prompt, ...newbie);
151
- return [prompt, ...newbie];
152
- }
153
-
154
- /**
155
- * Get configuration.
156
- */
157
- public getConfig(): IAgenticaConfig | undefined {
158
- return this.props.config;
159
- }
160
-
161
- /**
162
- * Get LLM Provider.
163
- */
164
- public getProvider(): IAgenticaProvider {
165
- return this.props.provider;
166
- }
167
-
168
- /**
169
- * Get controllers.
170
- *
171
- * Get list of controllers, which are the collection of functions that
172
- * the "Super A.I. Chatbot" can execute.
173
- */
174
- public getControllers(): ReadonlyArray<IAgenticaController> {
175
- return this.props.controllers;
176
- }
177
-
178
- /**
179
- * Get operations.
180
- *
181
- * Get list of operations, which has capsuled the pair of controller
182
- * and function from the {@link getControllers controllers}.
183
- *
184
- * @returns
185
- */
186
- public getOperations(): ReadonlyArray<IAgenticaOperation> {
187
- return this.operations_.array;
188
- }
189
-
190
- /**
191
- * Get the chatbot's prompt histories.
192
- *
193
- * Get list of chat prompts that the chatbot has been conversated.
194
- *
195
- * @returns List of chat prompts
196
- */
197
- public getPromptHistories(): IAgenticaPrompt[] {
198
- return this.prompt_histories_;
199
- }
200
-
201
- /**
202
- * Get token usage of the A.I. chatbot.
203
- *
204
- * Entire token usage of the A.I. chatbot during the conversating
205
- * with the user by {@link conversate} method callings.
206
- *
207
- * @returns Cost of the A.I. chatbot
208
- */
209
- public getTokenUsage(): IAgenticaTokenUsage {
210
- return this.token_usage_;
211
- }
212
-
213
- /**
214
- * @internal
215
- */
216
- public getContext(props: {
217
- prompt: IAgenticaPrompt.IText<"user">;
218
- usage: IAgenticaTokenUsage;
219
- }): IAgenticaContext {
220
- const dispatch = (event: IAgenticaEvent) => this.dispatch(event);
221
- return {
222
- // APPLICATION
223
- operations: this.operations_,
224
- config: this.props.config,
225
-
226
- // STATES
227
- histories: this.prompt_histories_,
228
- stack: this.stack_,
229
- ready: () => this.ready_,
230
- prompt: props.prompt,
231
-
232
- // HANDLERS
233
- dispatch,
234
- request: async (source, body) => {
235
- // request information
236
- const event: IAgenticaEvent.IRequest = {
237
- type: "request",
238
- source,
239
- body: {
240
- ...body,
241
- model: this.props.provider.model,
242
- },
243
- options: this.props.provider.options,
244
- };
245
- await dispatch(event);
246
-
247
- // completion
248
- const value: OpenAI.ChatCompletion =
249
- await this.props.provider.api.chat.completions.create(
250
- event.body,
251
- event.options,
252
- );
253
- AgenticaCostAggregator.aggregate(props.usage, value);
254
- await dispatch({
255
- type: "response",
256
- source,
257
- body: event.body,
258
- options: event.options,
259
- value,
260
- });
261
- return value;
262
- },
263
- initialize: async () => {
264
- this.ready_ = true;
265
- await dispatch({
266
- type: "initialize",
267
- });
268
- },
269
- };
270
- }
271
-
272
- /* -----------------------------------------------------------
273
- EVENT HANDLERS
274
- ----------------------------------------------------------- */
275
- /**
276
- * Add an event listener.
277
- *
278
- * Add an event listener to be called whenever the event is emitted.
279
- *
280
- * @param type Type of event
281
- * @param listener Callback function to be called whenever the event is emitted
282
- */
283
- public on<Type extends IAgenticaEvent.Type>(
284
- type: Type,
285
- listener: (event: IAgenticaEvent.Mapper[Type]) => void | Promise<void>,
286
- ): void {
287
- __map_take(this.listeners_, type, () => new Set()).add(listener);
288
- }
289
-
290
- /**
291
- * Erase an event listener.
292
- *
293
- * Erase an event listener to stop calling the callback function.
294
- *
295
- * @param type Type of event
296
- * @param listener Callback function to erase
297
- */
298
- public off<Type extends IAgenticaEvent.Type>(
299
- type: Type,
300
- listener: (event: IAgenticaEvent.Mapper[Type]) => void | Promise<void>,
301
- ): void {
302
- const set: Set<Function> | undefined = this.listeners_.get(type);
303
- if (set) {
304
- set.delete(listener);
305
- if (set.size === 0) this.listeners_.delete(type);
306
- }
307
- }
308
-
309
- private async dispatch<Event extends IAgenticaEvent>(
310
- event: Event,
311
- ): Promise<void> {
312
- const set: Set<Function> | undefined = this.listeners_.get(event.type);
313
- if (set)
314
- await Promise.all(
315
- Array.from(set).map(async (listener) => {
316
- try {
317
- await listener(event);
318
- } catch {}
319
- }),
320
- );
321
- }
322
- }
1
+ import OpenAI from "openai";
2
+
3
+ import { ChatGptAgent } from "./chatgpt/ChatGptAgent";
4
+ import { AgenticaCostAggregator } from "./internal/AgenticaCostAggregator";
5
+ import { AgenticaOperationComposer } from "./internal/AgenticaOperationComposer";
6
+ import { AgenticaPromptTransformer } from "./internal/AgenticaPromptTransformer";
7
+ import { __map_take } from "./internal/__map_take";
8
+ import { IAgenticaConfig } from "./structures/IAgenticaConfig";
9
+ import { IAgenticaContext } from "./structures/IAgenticaContext";
10
+ import { IAgenticaController } from "./structures/IAgenticaController";
11
+ import { IAgenticaEvent } from "./structures/IAgenticaEvent";
12
+ import { IAgenticaOperation } from "./structures/IAgenticaOperation";
13
+ import { IAgenticaOperationCollection } from "./structures/IAgenticaOperationCollection";
14
+ import { IAgenticaOperationSelection } from "./structures/IAgenticaOperationSelection";
15
+ import { IAgenticaPrompt } from "./structures/IAgenticaPrompt";
16
+ import { IAgenticaProps } from "./structures/IAgenticaProps";
17
+ import { IAgenticaProvider } from "./structures/IAgenticaProvider";
18
+ import { IAgenticaTokenUsage } from "./structures/IAgenticaTokenUsage";
19
+
20
+ /**
21
+ * Nestia A.I. chatbot agent.
22
+ *
23
+ * `Agentica` is a facade class for the super A.I. chatbot agent
24
+ * which performs the {@link converstate user's conversation function}
25
+ * with LLM (Large Language Model) function calling and manages the
26
+ * {@link getPromptHistories prompt histories}.
27
+ *
28
+ * To understand and compose the `Agentica` class exactly, reference
29
+ * below types concentrating on the documentation comments please.
30
+ * Especially, you have to be careful about the {@link IAgenticaProps}
31
+ * type which is used in the {@link constructor} function.
32
+ *
33
+ * - Constructors
34
+ * - {@link IAgenticaProps}
35
+ * - {@link IAgenticaProvider}
36
+ * - {@link IAgenticaController}
37
+ * - {@link IAgenticaConfig}
38
+ * - {@link IAgenticaSystemPrompt}
39
+ * - Accessors
40
+ * - {@link IAgenticaOperation}
41
+ * - {@link IAgenticaPrompt}
42
+ * - {@link IAgenticaEvent}
43
+ * - {@link IAgenticaTokenUsage}
44
+ *
45
+ * @author Samchon
46
+ */
47
+ export class Agentica {
48
+ // THE OPERATIONS
49
+ private readonly operations_: IAgenticaOperationCollection;
50
+
51
+ // STACK
52
+ private readonly stack_: IAgenticaOperationSelection[];
53
+ private readonly prompt_histories_: IAgenticaPrompt[];
54
+ private readonly listeners_: Map<string, Set<Function>>;
55
+
56
+ // STATUS
57
+ private readonly token_usage_: IAgenticaTokenUsage;
58
+ private ready_: boolean;
59
+ private readonly executor_: (
60
+ ctx: IAgenticaContext,
61
+ ) => Promise<IAgenticaPrompt[]>;
62
+
63
+ /* -----------------------------------------------------------
64
+ CONSTRUCTOR
65
+ ----------------------------------------------------------- */
66
+ /**
67
+ * Initializer constructor.
68
+ *
69
+ * @param props Properties to construct the agent
70
+ */
71
+ public constructor(private readonly props: IAgenticaProps) {
72
+ // OPERATIONS
73
+ this.operations_ = AgenticaOperationComposer.compose({
74
+ controllers: props.controllers,
75
+ config: props.config,
76
+ });
77
+
78
+ // STATUS
79
+ this.stack_ = [];
80
+ this.listeners_ = new Map();
81
+ this.prompt_histories_ = (props.histories ?? []).map((input) =>
82
+ AgenticaPromptTransformer.transform({
83
+ operations: this.operations_.group,
84
+ input,
85
+ }),
86
+ );
87
+
88
+ // STATUS
89
+ this.token_usage_ = {
90
+ total: 0,
91
+ prompt: {
92
+ total: 0,
93
+ audio: 0,
94
+ cached: 0,
95
+ },
96
+ completion: {
97
+ total: 0,
98
+ accepted_prediction: 0,
99
+ audio: 0,
100
+ reasoning: 0,
101
+ rejected_prediction: 0,
102
+ },
103
+ };
104
+ this.ready_ = false;
105
+ this.executor_ =
106
+ typeof props.config?.executor === "function"
107
+ ? props.config.executor
108
+ : ChatGptAgent.execute(props.config?.executor ?? null);
109
+ }
110
+
111
+ /**
112
+ * @internal
113
+ */
114
+ public clone(): Agentica {
115
+ return new Agentica({
116
+ ...this.props,
117
+ histories: this.props.histories?.slice(),
118
+ });
119
+ }
120
+
121
+ /* -----------------------------------------------------------
122
+ ACCESSORS
123
+ ----------------------------------------------------------- */
124
+ /**
125
+ * Conversate with the A.I. chatbot.
126
+ *
127
+ * User talks to the A.I. chatbot with the content.
128
+ *
129
+ * When the user's conversation implies the A.I. chatbot to execute a
130
+ * function calling, the returned chat prompts will contain the
131
+ * function calling information like {@link IAgenticaPrompt.IExecute}.
132
+ *
133
+ * @param content The content to talk
134
+ * @returns List of newly created chat prompts
135
+ */
136
+ public async conversate(content: string): Promise<IAgenticaPrompt[]> {
137
+ const prompt: IAgenticaPrompt.IText<"user"> = {
138
+ type: "text",
139
+ role: "user",
140
+ text: content,
141
+ };
142
+ await this.dispatch(prompt);
143
+
144
+ const newbie: IAgenticaPrompt[] = await this.executor_(
145
+ this.getContext({
146
+ prompt,
147
+ usage: this.token_usage_,
148
+ }),
149
+ );
150
+ this.prompt_histories_.push(prompt, ...newbie);
151
+ return [prompt, ...newbie];
152
+ }
153
+
154
+ /**
155
+ * Get configuration.
156
+ */
157
+ public getConfig(): IAgenticaConfig | undefined {
158
+ return this.props.config;
159
+ }
160
+
161
+ /**
162
+ * Get LLM Provider.
163
+ */
164
+ public getProvider(): IAgenticaProvider {
165
+ return this.props.provider;
166
+ }
167
+
168
+ /**
169
+ * Get controllers.
170
+ *
171
+ * Get list of controllers, which are the collection of functions that
172
+ * the "Super A.I. Chatbot" can execute.
173
+ */
174
+ public getControllers(): ReadonlyArray<IAgenticaController> {
175
+ return this.props.controllers;
176
+ }
177
+
178
+ /**
179
+ * Get operations.
180
+ *
181
+ * Get list of operations, which has capsuled the pair of controller
182
+ * and function from the {@link getControllers controllers}.
183
+ *
184
+ * @returns
185
+ */
186
+ public getOperations(): ReadonlyArray<IAgenticaOperation> {
187
+ return this.operations_.array;
188
+ }
189
+
190
+ /**
191
+ * Get the chatbot's prompt histories.
192
+ *
193
+ * Get list of chat prompts that the chatbot has been conversated.
194
+ *
195
+ * @returns List of chat prompts
196
+ */
197
+ public getPromptHistories(): IAgenticaPrompt[] {
198
+ return this.prompt_histories_;
199
+ }
200
+
201
+ /**
202
+ * Get token usage of the A.I. chatbot.
203
+ *
204
+ * Entire token usage of the A.I. chatbot during the conversating
205
+ * with the user by {@link conversate} method callings.
206
+ *
207
+ * @returns Cost of the A.I. chatbot
208
+ */
209
+ public getTokenUsage(): IAgenticaTokenUsage {
210
+ return this.token_usage_;
211
+ }
212
+
213
+ /**
214
+ * @internal
215
+ */
216
+ public getContext(props: {
217
+ prompt: IAgenticaPrompt.IText<"user">;
218
+ usage: IAgenticaTokenUsage;
219
+ }): IAgenticaContext {
220
+ const dispatch = (event: IAgenticaEvent) => this.dispatch(event);
221
+ return {
222
+ // APPLICATION
223
+ operations: this.operations_,
224
+ config: this.props.config,
225
+
226
+ // STATES
227
+ histories: this.prompt_histories_,
228
+ stack: this.stack_,
229
+ ready: () => this.ready_,
230
+ prompt: props.prompt,
231
+
232
+ // HANDLERS
233
+ dispatch,
234
+ request: async (source, body) => {
235
+ // request information
236
+ const event: IAgenticaEvent.IRequest = {
237
+ type: "request",
238
+ source,
239
+ body: {
240
+ ...body,
241
+ model: this.props.provider.model,
242
+ },
243
+ options: this.props.provider.options,
244
+ };
245
+ await dispatch(event);
246
+
247
+ // completion
248
+ const value: OpenAI.ChatCompletion =
249
+ await this.props.provider.api.chat.completions.create(
250
+ event.body,
251
+ event.options,
252
+ );
253
+ AgenticaCostAggregator.aggregate(props.usage, value);
254
+ await dispatch({
255
+ type: "response",
256
+ source,
257
+ body: event.body,
258
+ options: event.options,
259
+ value,
260
+ });
261
+ return value;
262
+ },
263
+ initialize: async () => {
264
+ this.ready_ = true;
265
+ await dispatch({
266
+ type: "initialize",
267
+ });
268
+ },
269
+ };
270
+ }
271
+
272
+ /* -----------------------------------------------------------
273
+ EVENT HANDLERS
274
+ ----------------------------------------------------------- */
275
+ /**
276
+ * Add an event listener.
277
+ *
278
+ * Add an event listener to be called whenever the event is emitted.
279
+ *
280
+ * @param type Type of event
281
+ * @param listener Callback function to be called whenever the event is emitted
282
+ */
283
+ public on<Type extends IAgenticaEvent.Type>(
284
+ type: Type,
285
+ listener: (event: IAgenticaEvent.Mapper[Type]) => void | Promise<void>,
286
+ ): void {
287
+ __map_take(this.listeners_, type, () => new Set()).add(listener);
288
+ }
289
+
290
+ /**
291
+ * Erase an event listener.
292
+ *
293
+ * Erase an event listener to stop calling the callback function.
294
+ *
295
+ * @param type Type of event
296
+ * @param listener Callback function to erase
297
+ */
298
+ public off<Type extends IAgenticaEvent.Type>(
299
+ type: Type,
300
+ listener: (event: IAgenticaEvent.Mapper[Type]) => void | Promise<void>,
301
+ ): void {
302
+ const set: Set<Function> | undefined = this.listeners_.get(type);
303
+ if (set) {
304
+ set.delete(listener);
305
+ if (set.size === 0) this.listeners_.delete(type);
306
+ }
307
+ }
308
+
309
+ private async dispatch<Event extends IAgenticaEvent>(
310
+ event: Event,
311
+ ): Promise<void> {
312
+ const set: Set<Function> | undefined = this.listeners_.get(event.type);
313
+ if (set)
314
+ await Promise.all(
315
+ Array.from(set).map(async (listener) => {
316
+ try {
317
+ await listener(event);
318
+ } catch {}
319
+ }),
320
+ );
321
+ }
322
+ }