@autobe/agent 0.8.0 → 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.
- package/lib/AutoBeAgent.d.ts +183 -12
- package/lib/AutoBeAgent.js +245 -65
- package/lib/AutoBeAgent.js.map +1 -1
- package/lib/constants/AutoBeSystemPromptConstant.d.ts +4 -3
- package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
- package/lib/context/AutoBeContext.d.ts +2 -2
- package/lib/factory/index.d.ts +0 -1
- package/lib/factory/index.js +0 -1
- package/lib/factory/index.js.map +1 -1
- package/lib/index.mjs +976 -633
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js +1 -1
- package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterface.js +1 -1
- package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrisma.js +1 -1
- package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTest.js +4 -8
- package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestCorrect.d.ts +2 -2
- package/lib/orchestrate/test/orchestrateTestCorrect.js +89 -57
- package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestProgress.d.ts +3 -2
- package/lib/orchestrate/test/orchestrateTestProgress.js +73 -46
- package/lib/orchestrate/test/orchestrateTestProgress.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestScenario.d.ts +2 -2
- package/lib/orchestrate/test/orchestrateTestScenario.js +616 -237
- package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
- package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.d.ts +123 -0
- package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.js +3 -0
- package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.js.map +1 -0
- package/lib/orchestrate/test/transformTestCorrectHistories.d.ts +2 -1
- package/lib/orchestrate/test/transformTestCorrectHistories.js +14 -10
- package/lib/orchestrate/test/transformTestCorrectHistories.js.map +1 -1
- package/lib/orchestrate/test/transformTestProgressHistories.d.ts +7 -1
- package/lib/orchestrate/test/transformTestProgressHistories.js +20 -20
- package/lib/orchestrate/test/transformTestProgressHistories.js.map +1 -1
- package/lib/orchestrate/test/transformTestScenarioHistories.d.ts +1 -2
- package/lib/orchestrate/test/transformTestScenarioHistories.js +1 -77
- package/lib/orchestrate/test/transformTestScenarioHistories.js.map +1 -1
- package/lib/structures/IAutoBeConfig.d.ts +48 -10
- package/lib/structures/IAutoBeProps.d.ts +87 -0
- package/lib/structures/IAutoBeVendor.d.ts +64 -22
- package/lib/utils/backoffRetry.d.ts +7 -0
- package/lib/utils/backoffRetry.js +73 -0
- package/lib/utils/backoffRetry.js.map +1 -0
- package/lib/utils/types/BackoffOptions.d.ts +12 -0
- package/lib/utils/types/BackoffOptions.js +3 -0
- package/lib/utils/types/BackoffOptions.js.map +1 -0
- package/package.json +4 -4
- package/src/AutoBeAgent.ts +248 -52
- package/src/constants/AutoBeSystemPromptConstant.ts +4 -3
- package/src/context/AutoBeContext.ts +7 -2
- package/src/factory/index.ts +0 -1
- package/src/orchestrate/analyze/AutoBeAnalyzeAgent.ts +1 -1
- package/src/orchestrate/interface/orchestrateInterface.ts +1 -1
- package/src/orchestrate/prisma/orchestratePrisma.ts +1 -0
- package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +4 -2
- package/src/orchestrate/test/orchestrateTest.ts +6 -13
- package/src/orchestrate/test/orchestrateTestCorrect.ts +125 -72
- package/src/orchestrate/test/orchestrateTestProgress.ts +86 -42
- package/src/orchestrate/test/orchestrateTestScenario.ts +192 -151
- package/src/orchestrate/test/structures/IAutoBeTestScenarioApplication.ts +132 -0
- package/src/orchestrate/test/transformTestCorrectHistories.ts +14 -10
- package/src/orchestrate/test/transformTestProgressHistories.ts +25 -22
- package/src/orchestrate/test/transformTestScenarioHistories.ts +0 -79
- package/src/structures/IAutoBeConfig.ts +48 -10
- package/src/structures/IAutoBeProps.ts +91 -0
- package/src/structures/IAutoBeVendor.ts +64 -22
- package/src/utils/backoffRetry.ts +84 -0
- package/src/utils/types/BackoffOptions.ts +15 -0
package/src/AutoBeAgent.ts
CHANGED
|
@@ -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
|
-
*
|
|
74
|
+
* Initializes a new AutoBeAgent instance with the specified configuration.
|
|
39
75
|
*
|
|
40
|
-
*
|
|
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(
|
|
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: {
|
|
@@ -114,36 +166,38 @@ export class AutoBeAgent<Model extends ILlmSchema.Model> {
|
|
|
114
166
|
/** @internal */
|
|
115
167
|
public clone(): AutoBeAgent<Model> {
|
|
116
168
|
return new AutoBeAgent<Model>({
|
|
117
|
-
...this.
|
|
169
|
+
...this.props_,
|
|
118
170
|
histories: this.histories_.slice(),
|
|
119
171
|
});
|
|
120
172
|
}
|
|
121
173
|
|
|
122
|
-
public on<Type extends AutoBeEvent.Type>(
|
|
123
|
-
type: Type,
|
|
124
|
-
listener: (event: AutoBeEvent.Mapper[Type]) => Promise<void> | void,
|
|
125
|
-
): this {
|
|
126
|
-
emplaceMap(this.listeners_, type, () => new Set()).add(
|
|
127
|
-
listener as (event: AutoBeEvent) => any,
|
|
128
|
-
);
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
public off<Type extends AutoBeEvent.Type>(
|
|
133
|
-
type: Type,
|
|
134
|
-
listener: (event: AutoBeEvent.Mapper[Type]) => Promise<void> | void,
|
|
135
|
-
): this {
|
|
136
|
-
const set = this.listeners_.get(type);
|
|
137
|
-
if (set === undefined) return this;
|
|
138
|
-
|
|
139
|
-
set.delete(listener as (event: AutoBeEvent) => any);
|
|
140
|
-
if (set.size === 0) this.listeners_.delete(type);
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
174
|
/* -----------------------------------------------------------
|
|
145
175
|
ACCESSORS
|
|
146
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
|
+
*/
|
|
147
201
|
public async conversate(
|
|
148
202
|
content: string | AutoBeUserMessageContent | AutoBeUserMessageContent[],
|
|
149
203
|
): Promise<AutoBeHistory[]> {
|
|
@@ -171,7 +225,54 @@ export class AutoBeAgent<Model extends ILlmSchema.Model> {
|
|
|
171
225
|
return this.histories_.slice(index);
|
|
172
226
|
}
|
|
173
227
|
|
|
174
|
-
|
|
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>> {
|
|
175
276
|
const files: Record<string, string> = {
|
|
176
277
|
...Object.fromEntries(
|
|
177
278
|
this.state_.analyze
|
|
@@ -182,14 +283,19 @@ export class AutoBeAgent<Model extends ILlmSchema.Model> {
|
|
|
182
283
|
: [],
|
|
183
284
|
),
|
|
184
285
|
...Object.fromEntries(
|
|
185
|
-
this.state_.prisma?.result
|
|
286
|
+
!!this.state_.prisma?.result
|
|
186
287
|
? [
|
|
187
|
-
...Object.entries(
|
|
188
|
-
(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
+
]),
|
|
193
299
|
...(this.state_.prisma.compiled.type === "success"
|
|
194
300
|
? [["docs/ERD.md", this.state_.prisma.compiled.document]]
|
|
195
301
|
: []),
|
|
@@ -209,12 +315,8 @@ export class AutoBeAgent<Model extends ILlmSchema.Model> {
|
|
|
209
315
|
: [],
|
|
210
316
|
),
|
|
211
317
|
...(this.state_.interface ? this.state_.interface.files : {}),
|
|
212
|
-
...(this.state_.test
|
|
213
|
-
|
|
214
|
-
: {}),
|
|
215
|
-
...(this.state_.realize?.compiled.type === "success"
|
|
216
|
-
? this.state_.realize.files
|
|
217
|
-
: {}),
|
|
318
|
+
...(this.state_.test ? this.state_.test.files : {}),
|
|
319
|
+
...(this.state_.realize ? this.state_.realize.files : {}),
|
|
218
320
|
"autobe/histories.json": JSON.stringify(this.histories_, null, 2),
|
|
219
321
|
"autobe/tokenUsage.json": JSON.stringify(this.getTokenUsage(), null, 2),
|
|
220
322
|
...(this.state_.interface
|
|
@@ -235,22 +337,116 @@ export class AutoBeAgent<Model extends ILlmSchema.Model> {
|
|
|
235
337
|
);
|
|
236
338
|
}
|
|
237
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
|
+
*/
|
|
238
359
|
public getHistories(): AutoBeHistory[] {
|
|
239
360
|
return this.histories_;
|
|
240
361
|
}
|
|
241
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
|
+
*/
|
|
242
381
|
public getTokenUsage(): AutoBeTokenUsage {
|
|
243
382
|
return this.agentica_.getTokenUsage();
|
|
244
383
|
}
|
|
245
384
|
|
|
246
|
-
/* -----------------------------------------------------------
|
|
247
|
-
CONTEXTS
|
|
248
|
-
----------------------------------------------------------- */
|
|
249
385
|
/** @internal */
|
|
250
386
|
public getContext(): AutoBeContext<Model> {
|
|
251
387
|
return this.context_;
|
|
252
388
|
}
|
|
253
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
|
+
|
|
254
450
|
/** @internal */
|
|
255
451
|
private async dispatch(event: AutoBeEvent): Promise<void> {
|
|
256
452
|
const set = this.listeners_.get(event.type);
|