@autobe/agent 0.7.3 → 0.9.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 (100) hide show
  1. package/lib/AutoBeAgent.d.ts +183 -12
  2. package/lib/AutoBeAgent.js +249 -65
  3. package/lib/AutoBeAgent.js.map +1 -1
  4. package/lib/constants/AutoBeSystemPromptConstant.d.ts +5 -4
  5. package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
  6. package/lib/context/AutoBeContext.d.ts +2 -2
  7. package/lib/factory/index.d.ts +0 -1
  8. package/lib/factory/index.js +0 -1
  9. package/lib/factory/index.js.map +1 -1
  10. package/lib/index.mjs +1024 -663
  11. package/lib/index.mjs.map +1 -1
  12. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js +7 -8
  13. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js.map +1 -1
  14. package/lib/orchestrate/analyze/orchestrateAnalyze.js +2 -5
  15. package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
  16. package/lib/orchestrate/interface/orchestrateInterface.js +1 -1
  17. package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
  18. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +6 -8
  19. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
  20. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +9 -6
  21. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +1 -1
  22. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +3 -1
  23. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
  24. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +5 -8
  25. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
  26. package/lib/orchestrate/prisma/orchestratePrisma.js +1 -1
  27. package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -1
  28. package/lib/orchestrate/prisma/orchestratePrismaComponent.js +5 -1
  29. package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -1
  30. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +3 -6
  31. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
  32. package/lib/orchestrate/prisma/orchestratePrismaSchema.js +11 -7
  33. package/lib/orchestrate/prisma/orchestratePrismaSchema.js.map +1 -1
  34. package/lib/orchestrate/prisma/transformPrismaCorrectHistories.js +1 -1
  35. package/lib/orchestrate/prisma/transformPrismaCorrectHistories.js.map +1 -1
  36. package/lib/orchestrate/test/orchestrateTest.js +4 -8
  37. package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
  38. package/lib/orchestrate/test/orchestrateTestCorrect.d.ts +2 -2
  39. package/lib/orchestrate/test/orchestrateTestCorrect.js +90 -60
  40. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  41. package/lib/orchestrate/test/orchestrateTestProgress.d.ts +3 -2
  42. package/lib/orchestrate/test/orchestrateTestProgress.js +75 -50
  43. package/lib/orchestrate/test/orchestrateTestProgress.js.map +1 -1
  44. package/lib/orchestrate/test/orchestrateTestScenario.d.ts +1 -1
  45. package/lib/orchestrate/test/orchestrateTestScenario.js +617 -208
  46. package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
  47. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.d.ts +123 -0
  48. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.js +3 -0
  49. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.js.map +1 -0
  50. package/lib/orchestrate/test/transformTestCorrectHistories.d.ts +2 -1
  51. package/lib/orchestrate/test/transformTestCorrectHistories.js +14 -10
  52. package/lib/orchestrate/test/transformTestCorrectHistories.js.map +1 -1
  53. package/lib/orchestrate/test/transformTestProgressHistories.d.ts +7 -1
  54. package/lib/orchestrate/test/transformTestProgressHistories.js +20 -20
  55. package/lib/orchestrate/test/transformTestProgressHistories.js.map +1 -1
  56. package/lib/orchestrate/test/transformTestScenarioHistories.d.ts +1 -2
  57. package/lib/orchestrate/test/transformTestScenarioHistories.js +1 -77
  58. package/lib/orchestrate/test/transformTestScenarioHistories.js.map +1 -1
  59. package/lib/structures/IAutoBeConfig.d.ts +48 -10
  60. package/lib/structures/IAutoBeProps.d.ts +87 -0
  61. package/lib/structures/IAutoBeVendor.d.ts +64 -22
  62. package/lib/utils/backoffRetry.d.ts +7 -0
  63. package/lib/utils/backoffRetry.js +73 -0
  64. package/lib/utils/backoffRetry.js.map +1 -0
  65. package/lib/utils/enforceToolCall.d.ts +3 -0
  66. package/lib/utils/enforceToolCall.js +13 -0
  67. package/lib/utils/enforceToolCall.js.map +1 -0
  68. package/lib/utils/types/BackoffOptions.d.ts +12 -0
  69. package/lib/utils/types/BackoffOptions.js +3 -0
  70. package/lib/utils/types/BackoffOptions.js.map +1 -0
  71. package/package.json +5 -5
  72. package/src/AutoBeAgent.ts +252 -52
  73. package/src/constants/AutoBeSystemPromptConstant.ts +5 -4
  74. package/src/context/AutoBeContext.ts +7 -2
  75. package/src/factory/index.ts +0 -1
  76. package/src/orchestrate/analyze/AutoBeAnalyzeAgent.ts +5 -10
  77. package/src/orchestrate/analyze/orchestrateAnalyze.ts +2 -6
  78. package/src/orchestrate/interface/orchestrateInterface.ts +1 -1
  79. package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +12 -11
  80. package/src/orchestrate/interface/orchestrateInterfaceComponents.ts +7 -6
  81. package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +2 -1
  82. package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +4 -9
  83. package/src/orchestrate/prisma/orchestratePrisma.ts +1 -0
  84. package/src/orchestrate/prisma/orchestratePrismaComponent.ts +4 -1
  85. package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +6 -7
  86. package/src/orchestrate/prisma/orchestratePrismaSchema.ts +10 -7
  87. package/src/orchestrate/test/orchestrateTest.ts +6 -13
  88. package/src/orchestrate/test/orchestrateTestCorrect.ts +127 -78
  89. package/src/orchestrate/test/orchestrateTestProgress.ts +88 -47
  90. package/src/orchestrate/test/orchestrateTestScenario.ts +194 -105
  91. package/src/orchestrate/test/structures/IAutoBeTestScenarioApplication.ts +132 -0
  92. package/src/orchestrate/test/transformTestCorrectHistories.ts +14 -10
  93. package/src/orchestrate/test/transformTestProgressHistories.ts +25 -22
  94. package/src/orchestrate/test/transformTestScenarioHistories.ts +0 -79
  95. package/src/structures/IAutoBeConfig.ts +48 -10
  96. package/src/structures/IAutoBeProps.ts +91 -0
  97. package/src/structures/IAutoBeVendor.ts +64 -22
  98. package/src/utils/backoffRetry.ts +84 -0
  99. package/src/utils/enforceToolCall.ts +13 -0
  100. package/src/utils/types/BackoffOptions.ts +15 -0
@@ -1,10 +1,11 @@
1
- import { MicroAgentica } from "@agentica/core";
1
+ import { IAgenticaVendor, MicroAgentica } from "@agentica/core";
2
2
  import {
3
3
  AutoBeAssistantMessageHistory,
4
4
  AutoBeEvent,
5
5
  AutoBeHistory,
6
6
  AutoBeUserMessageContent,
7
7
  AutoBeUserMessageHistory,
8
+ IAutoBeGetFilesOptions,
8
9
  } from "@autobe/interface";
9
10
  import { ILlmSchema } from "@samchon/openapi";
10
11
  import { Semaphore } from "tstl";
@@ -20,12 +21,47 @@ import { transformFacadeStateMessage } from "./orchestrate/facade/transformFacad
20
21
  import { IAutoBeProps } from "./structures/IAutoBeProps";
21
22
  import { emplaceMap } from "./utils/emplaceMap";
22
23
 
24
+ /**
25
+ * Main agent class that orchestrates the entire vibe coding pipeline through
26
+ * conversation-driven development.
27
+ *
28
+ * The AutoBeAgent serves as the central coordinator for the waterfall-based
29
+ * development process with spiral model iterative improvements. It manages the
30
+ * five specialized agents (Analyze, Prisma, Interface, Test, Realize) that
31
+ * transform user conversations into complete working applications through a
32
+ * sophisticated AST-based compilation infrastructure.
33
+ *
34
+ * The agent operates through natural language conversation, supporting
35
+ * multimodal input including text, images, files, and audio. It maintains
36
+ * conversation history, tracks development progress through real-time events,
37
+ * and provides access to all generated artifacts including requirements
38
+ * documentation, database schemas, API specifications, test suites, and
39
+ * implementation code.
40
+ *
41
+ * The vibe coding approach eliminates traditional development barriers by
42
+ * enabling users to express requirements naturally while the agent handles all
43
+ * technical implementation details through validated AST transformations and
44
+ * continuous quality assurance feedback loops.
45
+ *
46
+ * @author Samchon
47
+ */
23
48
  export class AutoBeAgent<Model extends ILlmSchema.Model> {
49
+ /** @internal */
50
+ private readonly props_: IAutoBeProps<Model>;
51
+
52
+ /** @internal */
24
53
  private readonly agentica_: MicroAgentica<Model>;
54
+
55
+ /** @internal */
25
56
  private readonly histories_: AutoBeHistory[];
57
+
58
+ /** @internal */
26
59
  private readonly context_: AutoBeContext<Model>;
27
60
 
61
+ /** @internal */
28
62
  private readonly state_: AutoBeState;
63
+
64
+ /** @internal */
29
65
  private readonly listeners_: Map<
30
66
  string,
31
67
  Set<(event: AutoBeEvent) => Promise<void> | void>
@@ -35,34 +71,50 @@ export class AutoBeAgent<Model extends ILlmSchema.Model> {
35
71
  CONSTRUCTOR
36
72
  ----------------------------------------------------------- */
37
73
  /**
38
- * Initializer constructor.
74
+ * Initializes a new AutoBeAgent instance with the specified configuration.
39
75
  *
40
- * @param props Properties to construct the agent
76
+ * Creates and configures the agent with AI vendor settings, behavioral
77
+ * context (locale/timezone), and compilation infrastructure. The agent can
78
+ * optionally resume from previous conversation histories to continue
79
+ * development sessions or build upon existing work.
80
+ *
81
+ * The constructor sets up the internal MicroAgentica engine, initializes the
82
+ * development state from provided histories, and establishes the event
83
+ * dispatch system for real-time progress notifications. The agent becomes
84
+ * ready for conversation-driven development immediately after construction.
85
+ *
86
+ * @param props Configuration properties including AI vendor settings,
87
+ * behavioral context, compilation tools, and optional conversation
88
+ * histories for session continuation
41
89
  */
42
- public constructor(private readonly props: IAutoBeProps<Model>) {
90
+ public constructor(props: IAutoBeProps<Model>) {
91
+ // INITIALIZE MEMBERS
92
+ this.props_ = props;
43
93
  this.histories_ = props.histories?.slice() ?? [];
44
94
  this.state_ = createAutoBeState(this.histories_);
95
+ this.listeners_ = new Map();
96
+
97
+ // CONSTRUCT AGENTICA
98
+ const vendor: IAgenticaVendor = {
99
+ ...props.vendor,
100
+ semaphore: new Semaphore(props.vendor.semaphore ?? 16),
101
+ };
45
102
  this.context_ = {
103
+ vendor,
46
104
  model: props.model,
47
- vendor: props.vendor,
48
105
  config: props.config,
49
106
  compiler: props.compiler,
50
107
  histories: () => this.histories_,
51
108
  state: () => this.state_,
52
109
  usage: () => this.agentica_.getTokenUsage(),
53
- files: () => this.getFiles(),
110
+ files: (options) => this.getFiles(options),
54
111
  dispatch: (event) => {
55
112
  this.dispatch(event).catch(() => {});
56
113
  },
57
114
  };
58
- this.listeners_ = new Map();
59
-
60
115
  this.agentica_ = new MicroAgentica({
116
+ vendor,
61
117
  model: props.model,
62
- vendor: {
63
- ...props.vendor,
64
- semaphore: new Semaphore(props.vendor.semaphore ?? 16),
65
- },
66
118
  config: {
67
119
  ...(props.config ?? {}),
68
120
  executor: {
@@ -105,41 +157,47 @@ export class AutoBeAgent<Model extends ILlmSchema.Model> {
105
157
  created_at: history.created_at,
106
158
  }).catch(() => {});
107
159
  });
160
+ this.agentica_.on("request", (e) => {
161
+ if (e.body.parallel_tool_calls !== undefined)
162
+ delete e.body.parallel_tool_calls;
163
+ });
108
164
  }
109
165
 
110
166
  /** @internal */
111
167
  public clone(): AutoBeAgent<Model> {
112
168
  return new AutoBeAgent<Model>({
113
- ...this.props,
169
+ ...this.props_,
114
170
  histories: this.histories_.slice(),
115
171
  });
116
172
  }
117
173
 
118
- public on<Type extends AutoBeEvent.Type>(
119
- type: Type,
120
- listener: (event: AutoBeEvent.Mapper[Type]) => Promise<void> | void,
121
- ): this {
122
- emplaceMap(this.listeners_, type, () => new Set()).add(
123
- listener as (event: AutoBeEvent) => any,
124
- );
125
- return this;
126
- }
127
-
128
- public off<Type extends AutoBeEvent.Type>(
129
- type: Type,
130
- listener: (event: AutoBeEvent.Mapper[Type]) => Promise<void> | void,
131
- ): this {
132
- const set = this.listeners_.get(type);
133
- if (set === undefined) return this;
134
-
135
- set.delete(listener as (event: AutoBeEvent) => any);
136
- if (set.size === 0) this.listeners_.delete(type);
137
- return this;
138
- }
139
-
140
174
  /* -----------------------------------------------------------
141
175
  ACCESSORS
142
176
  ----------------------------------------------------------- */
177
+ /**
178
+ * Engages in conversation with the agent to drive the vibe coding process.
179
+ *
180
+ * Accepts user input in multiple formats including simple text strings,
181
+ * single multimodal content items, or arrays of content supporting text,
182
+ * images, file uploads, and audio input. The conversation serves as the
183
+ * primary interface for expressing requirements, providing feedback, and
184
+ * guiding the development process through natural language interaction.
185
+ *
186
+ * The agent analyzes the conversation context to determine appropriate
187
+ * actions, potentially activating specialized agents (Analyze, Prisma,
188
+ * Interface, Test, Realize) through function calling based on user needs.
189
+ * Real-time progress events are fired through registered listeners while the
190
+ * conversation processes.
191
+ *
192
+ * Returns all history records generated during this conversation turn,
193
+ * including user messages, assistant responses, and any development
194
+ * activities triggered by the interaction. This enables clients to track both
195
+ * conversational flow and development progress.
196
+ *
197
+ * @param content User input as text, single content item, or multimodal array
198
+ * @returns Promise resolving to array of history records from this
199
+ * conversation
200
+ */
143
201
  public async conversate(
144
202
  content: string | AutoBeUserMessageContent | AutoBeUserMessageContent[],
145
203
  ): Promise<AutoBeHistory[]> {
@@ -167,7 +225,54 @@ export class AutoBeAgent<Model extends ILlmSchema.Model> {
167
225
  return this.histories_.slice(index);
168
226
  }
169
227
 
170
- public getFiles(): Record<string, string> {
228
+ /**
229
+ * Retrieves all generated files from the current development session.
230
+ *
231
+ * Transforms the complete conversation-driven development process into a
232
+ * comprehensive collection of deployable artifacts, including requirements
233
+ * documentation, database schemas, API specifications, NestJS implementation
234
+ * code, and test suites. The generated files represent a fully functional
235
+ * backend application ready for immediate deployment or further
236
+ * customization.
237
+ *
238
+ * The method produces a meticulously organized project structure that
239
+ * reflects professional software development standards. Requirements analysis
240
+ * documents capture and formalize your conversational input into structured
241
+ * technical specifications, providing clear traceability from user intent to
242
+ * final implementation. Database artifacts include Prisma schemas with
243
+ * precise type definitions, relationships, and constraints, along with
244
+ * migration files for proper database initialization and evolution.
245
+ *
246
+ * The API layer emerges through comprehensive OpenAPI specifications
247
+ * documenting every endpoint, request format, response structure, and error
248
+ * condition. Generated NestJS controllers, DTOs, and service classes
249
+ * implement these specifications with TypeScript's strong typing system
250
+ * providing compile-time safety. Quality assurance is embedded throughout
251
+ * with complete test suites covering both unit and end-to-end scenarios.
252
+ *
253
+ * The database configuration specified through the `dbms` option
254
+ * fundamentally shapes the entire generated codebase. PostgreSQL
255
+ * configuration produces production-ready code with robust connection pooling
256
+ * and enterprise-grade optimizations, while SQLite generates lightweight code
257
+ * perfect for local development and rapid prototyping without external
258
+ * dependencies.
259
+ *
260
+ * All artifacts maintain perfect consistency across the chosen database
261
+ * system, from Prisma configurations and connection strings to Docker compose
262
+ * files and environment templates. This deep integration ensures immediate
263
+ * deployment compatibility without manual configuration adjustments.
264
+ *
265
+ * @param options Configuration specifying the target database management
266
+ * system and other code generation preferences that influence the structure
267
+ * and characteristics of the generated project files
268
+ * @returns Promise resolving to key-value pairs mapping logical file paths to
269
+ * complete file contents for all generated development artifacts, ready for
270
+ * immediate file system operations, build integration, or deployment
271
+ * workflows
272
+ */
273
+ public async getFiles(
274
+ options?: Partial<IAutoBeGetFilesOptions>,
275
+ ): Promise<Record<string, string>> {
171
276
  const files: Record<string, string> = {
172
277
  ...Object.fromEntries(
173
278
  this.state_.analyze
@@ -178,14 +283,19 @@ export class AutoBeAgent<Model extends ILlmSchema.Model> {
178
283
  : [],
179
284
  ),
180
285
  ...Object.fromEntries(
181
- this.state_.prisma?.result.success === true
286
+ !!this.state_.prisma?.result
182
287
  ? [
183
- ...Object.entries(this.state_.prisma.schemas).map(
184
- ([key, value]) => [
185
- `prisma/schema/${key.split("/").at(-1)}`,
186
- value,
187
- ],
188
- ),
288
+ ...Object.entries(
289
+ (options?.dbms ?? "postgres") === "postgres"
290
+ ? this.state_.prisma.schemas
291
+ : await this.context_.compiler.prisma.write(
292
+ this.state_.prisma.result.data,
293
+ options!.dbms!,
294
+ ),
295
+ ).map(([key, value]) => [
296
+ `prisma/schema/${key.split("/").at(-1)}`,
297
+ value,
298
+ ]),
189
299
  ...(this.state_.prisma.compiled.type === "success"
190
300
  ? [["docs/ERD.md", this.state_.prisma.compiled.document]]
191
301
  : []),
@@ -205,12 +315,8 @@ export class AutoBeAgent<Model extends ILlmSchema.Model> {
205
315
  : [],
206
316
  ),
207
317
  ...(this.state_.interface ? this.state_.interface.files : {}),
208
- ...(this.state_.test?.compiled.type === "success"
209
- ? this.state_.test.files
210
- : {}),
211
- ...(this.state_.realize?.compiled.type === "success"
212
- ? this.state_.realize.files
213
- : {}),
318
+ ...(this.state_.test ? this.state_.test.files : {}),
319
+ ...(this.state_.realize ? this.state_.realize.files : {}),
214
320
  "autobe/histories.json": JSON.stringify(this.histories_, null, 2),
215
321
  "autobe/tokenUsage.json": JSON.stringify(this.getTokenUsage(), null, 2),
216
322
  ...(this.state_.interface
@@ -231,22 +337,116 @@ export class AutoBeAgent<Model extends ILlmSchema.Model> {
231
337
  );
232
338
  }
233
339
 
340
+ /**
341
+ * Retrieves the complete conversation and development history.
342
+ *
343
+ * Returns the chronologically ordered record of all events from the current
344
+ * session including user messages, assistant responses, development phase
345
+ * activities, progress events, and completion notifications. This
346
+ * comprehensive history enables conversation replay, development process
347
+ * analysis, and understanding of how requirements evolved into working
348
+ * software.
349
+ *
350
+ * The history provides complete transparency into the vibe coding process,
351
+ * showing both conversational interactions and behind-the-scenes development
352
+ * activities. This information is valuable for debugging, process
353
+ * improvement, and educational purposes to understand the agent's
354
+ * decision-making process.
355
+ *
356
+ * @returns Chronologically ordered array of all history records including
357
+ * messages, events, and development activities
358
+ */
234
359
  public getHistories(): AutoBeHistory[] {
235
360
  return this.histories_;
236
361
  }
237
362
 
363
+ /**
364
+ * Retrieves comprehensive AI token usage statistics for the current session.
365
+ *
366
+ * Returns detailed breakdown of token consumption across all specialized
367
+ * agents and processing phases, enabling cost monitoring, performance
368
+ * analysis, and optimization of AI resource utilization. Statistics include
369
+ * aggregate totals and component-specific breakdowns with input/output
370
+ * categorization, caching analysis, and reasoning token tracking.
371
+ *
372
+ * Token usage data is essential for understanding the computational costs of
373
+ * different development phases and optimizing AI efficiency. The breakdown
374
+ * helps identify which agents or operations consume the most resources,
375
+ * enabling targeted optimization efforts while maintaining development
376
+ * quality.
377
+ *
378
+ * @returns Comprehensive token usage statistics with detailed breakdowns by
379
+ * agent, operation type, and consumption category
380
+ */
238
381
  public getTokenUsage(): AutoBeTokenUsage {
239
382
  return this.agentica_.getTokenUsage();
240
383
  }
241
384
 
242
- /* -----------------------------------------------------------
243
- CONTEXTS
244
- ----------------------------------------------------------- */
245
385
  /** @internal */
246
386
  public getContext(): AutoBeContext<Model> {
247
387
  return this.context_;
248
388
  }
249
389
 
390
+ /* -----------------------------------------------------------
391
+ EVENT HANDLERS
392
+ ----------------------------------------------------------- */
393
+ /**
394
+ * Registers an event listener for specific development phase events.
395
+ *
396
+ * Enables client applications to receive real-time notifications about
397
+ * conversation flow, development progress, and completion events throughout
398
+ * the vibe coding pipeline. Event listeners provide visibility into agent
399
+ * activities and enable responsive user interfaces that can display progress,
400
+ * handle artifacts, and provide feedback.
401
+ *
402
+ * The type-safe event system ensures that listeners receive properly typed
403
+ * events corresponding to their registration type, enabling robust event
404
+ * handling without runtime type issues. Multiple listeners can be registered
405
+ * for the same event type to support complex notification requirements.
406
+ *
407
+ * @param type Event type to listen for (e.g., "analyzeComplete",
408
+ * "prismaStart")
409
+ * @param listener Callback function that receives the typed event when fired
410
+ * @returns The agent instance for method chaining
411
+ */
412
+ public on<Type extends AutoBeEvent.Type>(
413
+ type: Type,
414
+ listener: (event: AutoBeEvent.Mapper[Type]) => Promise<void> | void,
415
+ ): this {
416
+ emplaceMap(this.listeners_, type, () => new Set()).add(
417
+ listener as (event: AutoBeEvent) => any,
418
+ );
419
+ return this;
420
+ }
421
+
422
+ /**
423
+ * Unregisters a previously registered event listener.
424
+ *
425
+ * Removes the specified event listener from the agent's notification system,
426
+ * stopping further event notifications for that particular listener function.
427
+ * This is useful for cleanup, dynamic listener management, or when components
428
+ * no longer need to receive specific event notifications.
429
+ *
430
+ * The listener function reference must exactly match the function that was
431
+ * originally registered with {@link on} for successful removal. If no matching
432
+ * listener is found, the operation has no effect.
433
+ *
434
+ * @param type Event type the listener was registered for
435
+ * @param listener The exact listener function reference to remove
436
+ * @returns The agent instance for method chaining
437
+ */
438
+ public off<Type extends AutoBeEvent.Type>(
439
+ type: Type,
440
+ listener: (event: AutoBeEvent.Mapper[Type]) => Promise<void> | void,
441
+ ): this {
442
+ const set = this.listeners_.get(type);
443
+ if (set === undefined) return this;
444
+
445
+ set.delete(listener as (event: AutoBeEvent) => any);
446
+ if (set.size === 0) this.listeners_.delete(type);
447
+ return this;
448
+ }
449
+
250
450
  /** @internal */
251
451
  private async dispatch(event: AutoBeEvent): Promise<void> {
252
452
  const set = this.listeners_.get(event.type);