@autobe/agent 0.8.0 → 0.9.1

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 (91) hide show
  1. package/lib/AutoBeAgent.d.ts +183 -12
  2. package/lib/AutoBeAgent.js +247 -65
  3. package/lib/AutoBeAgent.js.map +1 -1
  4. package/lib/constants/AutoBeSystemPromptConstant.d.ts +4 -3
  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 +1195 -834
  11. package/lib/index.mjs.map +1 -1
  12. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js +1 -1
  13. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js.map +1 -1
  14. package/lib/orchestrate/interface/orchestrateInterface.js +1 -1
  15. package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
  16. package/lib/orchestrate/prisma/orchestratePrisma.js +1 -1
  17. package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -1
  18. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +1 -1
  19. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
  20. package/lib/orchestrate/test/compileTestScenario.d.ts +5 -0
  21. package/lib/orchestrate/test/compileTestScenario.js +56 -0
  22. package/lib/orchestrate/test/compileTestScenario.js.map +1 -0
  23. package/lib/orchestrate/test/filterTestFileName.d.ts +1 -0
  24. package/lib/orchestrate/test/filterTestFileName.js +13 -0
  25. package/lib/orchestrate/test/filterTestFileName.js.map +1 -0
  26. package/lib/orchestrate/test/orchestrateTest.js +10 -11
  27. package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
  28. package/lib/orchestrate/test/orchestrateTestCorrect.d.ts +2 -2
  29. package/lib/orchestrate/test/orchestrateTestCorrect.js +91 -73
  30. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  31. package/lib/orchestrate/test/orchestrateTestScenario.d.ts +2 -2
  32. package/lib/orchestrate/test/orchestrateTestScenario.js +616 -237
  33. package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
  34. package/lib/orchestrate/test/orchestrateTestWrite.d.ts +4 -0
  35. package/lib/orchestrate/test/{orchestrateTestProgress.js → orchestrateTestWrite.js} +37 -51
  36. package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -0
  37. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.d.ts +123 -0
  38. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.js +3 -0
  39. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.js.map +1 -0
  40. package/lib/orchestrate/test/structures/IAutoBeTestScenarioArtifacts.d.ts +5 -0
  41. package/lib/orchestrate/test/structures/IAutoBeTestScenarioArtifacts.js +3 -0
  42. package/lib/orchestrate/test/structures/IAutoBeTestScenarioArtifacts.js.map +1 -0
  43. package/lib/orchestrate/test/transformTestCorrectHistories.d.ts +2 -1
  44. package/lib/orchestrate/test/transformTestCorrectHistories.js +4 -4
  45. package/lib/orchestrate/test/transformTestCorrectHistories.js.map +1 -1
  46. package/lib/orchestrate/test/transformTestScenarioHistories.d.ts +1 -2
  47. package/lib/orchestrate/test/transformTestScenarioHistories.js +1 -77
  48. package/lib/orchestrate/test/transformTestScenarioHistories.js.map +1 -1
  49. package/lib/orchestrate/test/transformTestWriteHistories.d.ts +7 -0
  50. package/lib/orchestrate/test/transformTestWriteHistories.js +47 -0
  51. package/lib/orchestrate/test/transformTestWriteHistories.js.map +1 -0
  52. package/lib/structures/IAutoBeConfig.d.ts +48 -10
  53. package/lib/structures/IAutoBeProps.d.ts +87 -0
  54. package/lib/structures/IAutoBeVendor.d.ts +64 -22
  55. package/lib/utils/backoffRetry.d.ts +7 -0
  56. package/lib/utils/backoffRetry.js +73 -0
  57. package/lib/utils/backoffRetry.js.map +1 -0
  58. package/lib/utils/types/BackoffOptions.d.ts +12 -0
  59. package/lib/utils/types/BackoffOptions.js +3 -0
  60. package/lib/utils/types/BackoffOptions.js.map +1 -0
  61. package/package.json +4 -4
  62. package/src/AutoBeAgent.ts +251 -51
  63. package/src/constants/AutoBeSystemPromptConstant.ts +4 -3
  64. package/src/context/AutoBeContext.ts +7 -2
  65. package/src/factory/index.ts +0 -1
  66. package/src/orchestrate/analyze/AutoBeAnalyzeAgent.ts +1 -1
  67. package/src/orchestrate/interface/orchestrateInterface.ts +1 -1
  68. package/src/orchestrate/prisma/orchestratePrisma.ts +1 -0
  69. package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +4 -2
  70. package/src/orchestrate/test/compileTestScenario.ts +63 -0
  71. package/src/orchestrate/test/filterTestFileName.ts +9 -0
  72. package/src/orchestrate/test/orchestrateTest.ts +11 -17
  73. package/src/orchestrate/test/orchestrateTestCorrect.ts +152 -100
  74. package/src/orchestrate/test/orchestrateTestScenario.ts +195 -151
  75. package/src/orchestrate/test/{orchestrateTestProgress.ts → orchestrateTestWrite.ts} +29 -44
  76. package/src/orchestrate/test/structures/IAutoBeTestScenarioApplication.ts +132 -0
  77. package/src/orchestrate/test/structures/IAutoBeTestScenarioArtifacts.ts +5 -0
  78. package/src/orchestrate/test/transformTestCorrectHistories.ts +4 -4
  79. package/src/orchestrate/test/transformTestScenarioHistories.ts +0 -79
  80. package/src/orchestrate/test/transformTestWriteHistories.ts +53 -0
  81. package/src/structures/IAutoBeConfig.ts +48 -10
  82. package/src/structures/IAutoBeProps.ts +91 -0
  83. package/src/structures/IAutoBeVendor.ts +64 -22
  84. package/src/utils/backoffRetry.ts +84 -0
  85. package/src/utils/types/BackoffOptions.ts +15 -0
  86. package/lib/orchestrate/test/orchestrateTestProgress.d.ts +0 -4
  87. package/lib/orchestrate/test/orchestrateTestProgress.js.map +0 -1
  88. package/lib/orchestrate/test/transformTestProgressHistories.d.ts +0 -2
  89. package/lib/orchestrate/test/transformTestProgressHistories.js +0 -47
  90. package/lib/orchestrate/test/transformTestProgressHistories.js.map +0 -1
  91. package/src/orchestrate/test/transformTestProgressHistories.ts +0 -51
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.randomBackoffRetry = randomBackoffRetry;
13
+ /**
14
+ * @param fn Function to Apply the retry logic.
15
+ * @param maxRetries How many time to try. Max Retry is 5.
16
+ * @returns
17
+ */
18
+ function randomBackoffRetry(fn_1) {
19
+ return __awaiter(this, arguments, void 0, function* (fn, options = {}) {
20
+ const { maxRetries = 5, baseDelay = 4000, maxDelay = 60000, jitter = 0.8, handleError = isRetryError, } = options;
21
+ let lastError;
22
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
23
+ try {
24
+ return yield fn();
25
+ }
26
+ catch (err) {
27
+ lastError = err;
28
+ if (attempt === maxRetries - 1)
29
+ throw err;
30
+ if (!handleError(err))
31
+ throw err;
32
+ const tempDelay = Math.min(baseDelay * 2 ** attempt, maxDelay);
33
+ const delay = tempDelay * (1 + Math.random() * jitter);
34
+ yield new Promise((res) => setTimeout(res, delay));
35
+ }
36
+ }
37
+ throw lastError;
38
+ });
39
+ }
40
+ function isRetryError(error) {
41
+ var _a, _b, _c;
42
+ // 1) Quota exceeded → No retry
43
+ if ((error === null || error === void 0 ? void 0 : error.code) === "insufficient_quota" ||
44
+ ((_a = error === null || error === void 0 ? void 0 : error.error) === null || _a === void 0 ? void 0 : _a.type) === "insufficient_quota") {
45
+ return false;
46
+ }
47
+ // 2) 5xx / server_error → Retry
48
+ if ((typeof (error === null || error === void 0 ? void 0 : error.status) === "number" && error.status >= 500) ||
49
+ ((_b = error === null || error === void 0 ? void 0 : error.error) === null || _b === void 0 ? void 0 : _b.type) === "server_error") {
50
+ return true;
51
+ }
52
+ // 3) HTTP 429
53
+ if ((error === null || error === void 0 ? void 0 : error.status) === 429) {
54
+ return true;
55
+ }
56
+ // 4) undici / network related
57
+ const code = (error === null || error === void 0 ? void 0 : error.code) || ((_c = error === null || error === void 0 ? void 0 : error.cause) === null || _c === void 0 ? void 0 : _c.code);
58
+ if ([
59
+ "UND_ERR_SOCKET",
60
+ "UND_ERR_CONNECT_TIMEOUT",
61
+ "ETIMEDOUT",
62
+ "ECONNRESET",
63
+ "EPIPE",
64
+ ].includes(code)) {
65
+ return true;
66
+ }
67
+ // 5) fetch abort
68
+ if ((error === null || error === void 0 ? void 0 : error.message) === "terminated" || (error === null || error === void 0 ? void 0 : error.name) === "AbortError") {
69
+ return true;
70
+ }
71
+ return false;
72
+ }
73
+ //# sourceMappingURL=backoffRetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backoffRetry.js","sourceRoot":"","sources":["../../src/utils/backoffRetry.ts"],"names":[],"mappings":";;;;;;;;;;;AAOA,gDAgCC;AArCD;;;;GAIG;AACH,SAAsB,kBAAkB;yDACtC,EAAoB,EACpB,UAAiC,EAAE;QAEnC,MAAM,EACJ,UAAU,GAAG,CAAC,EACd,SAAS,GAAG,IAAK,EACjB,QAAQ,GAAG,KAAM,EACjB,MAAM,GAAG,GAAG,EACZ,WAAW,GAAG,YAAY,GAC3B,GAAG,OAAO,CAAC;QAEZ,IAAI,SAAkB,CAAC;QAEvB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;YACtD,IAAI,CAAC;gBACH,OAAO,MAAM,EAAE,EAAE,CAAC;YACpB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,SAAS,GAAG,GAAG,CAAC;gBAEhB,IAAI,OAAO,KAAK,UAAU,GAAG,CAAC;oBAAE,MAAM,GAAG,CAAC;gBAE1C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;oBAAE,MAAM,GAAG,CAAC;gBAEjC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,IAAI,OAAO,EAAE,QAAQ,CAAC,CAAC;gBAC/D,MAAM,KAAK,GAAG,SAAS,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC;gBAEvD,MAAM,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;YACrD,CAAC;QACH,CAAC;QAED,MAAM,SAAS,CAAC;IAClB,CAAC;CAAA;AAED,SAAS,YAAY,CAAC,KAAU;;IAC9B,+BAA+B;IAC/B,IACE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,oBAAoB;QACpC,CAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,0CAAE,IAAI,MAAK,oBAAoB,EAC3C,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,gCAAgC;IAChC,IACE,CAAC,OAAO,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,CAAA,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC;QAC1D,CAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,0CAAE,IAAI,MAAK,cAAc,EACrC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,cAAc;IACd,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,MAAK,GAAG,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,8BAA8B;IAC9B,MAAM,IAAI,GAAG,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAI,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,0CAAE,IAAI,CAAA,CAAC;IAC/C,IACE;QACE,gBAAgB;QAChB,yBAAyB;QACzB,WAAW;QACX,YAAY;QACZ,OAAO;KACR,CAAC,QAAQ,CAAC,IAAI,CAAC,EAChB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iBAAiB;IACjB,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,MAAK,YAAY,IAAI,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,YAAY,EAAE,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,12 @@
1
+ export interface RetryOptions {
2
+ /** Maximum number of retry attempts (default: 5) */
3
+ maxRetries: number;
4
+ /** Base delay in milliseconds (default: 2000) */
5
+ baseDelay: number;
6
+ /** Maximum delay in milliseconds (default: 60_000) */
7
+ maxDelay: number;
8
+ /** Jitter factor for randomization (0-1, default: 0.3) */
9
+ jitter: number;
10
+ /** Function to determine if error should trigger retry (default: isRetryError) */
11
+ handleError: (error: any) => boolean;
12
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=BackoffOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BackoffOptions.js","sourceRoot":"","sources":["../../../src/utils/types/BackoffOptions.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobe/agent",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "AI backend server code generator",
5
5
  "main": "lib/index.js",
6
6
  "author": "Wrtn Technologies",
@@ -30,7 +30,7 @@
30
30
  "tstl": "^3.0.0",
31
31
  "typia": "^9.3.1",
32
32
  "uuid": "^11.1.0",
33
- "@autobe/interface": "^0.8.0"
33
+ "@autobe/interface": "^0.9.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@rollup/plugin-terser": "^0.4.4",
@@ -43,8 +43,8 @@
43
43
  "ts-node": "^10.9.2",
44
44
  "ts-patch": "^3.3.0",
45
45
  "typescript": "~5.8.3",
46
- "@autobe/filesystem": "^0.8.0",
47
- "@autobe/compiler": "^0.8.0"
46
+ "@autobe/filesystem": "^0.9.1",
47
+ "@autobe/compiler": "^0.9.1"
48
48
  },
49
49
  "keywords": [
50
50
  "ai",
@@ -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: {
@@ -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.props,
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
- 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>> {
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.success === true
286
+ !!this.state_.prisma?.result
186
287
  ? [
187
- ...Object.entries(this.state_.prisma.schemas).map(
188
- ([key, value]) => [
189
- `prisma/schema/${key.split("/").at(-1)}`,
190
- value,
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,12 @@ export class AutoBeAgent<Model extends ILlmSchema.Model> {
209
315
  : [],
210
316
  ),
211
317
  ...(this.state_.interface ? this.state_.interface.files : {}),
212
- ...(this.state_.test?.compiled.type === "success"
213
- ? this.state_.test.files
214
- : {}),
215
- ...(this.state_.realize?.compiled.type === "success"
216
- ? this.state_.realize.files
318
+ ...(this.state_.test
319
+ ? Object.fromEntries(
320
+ this.state_.test.files.map((f) => [f.location, f.content]),
321
+ )
217
322
  : {}),
323
+ ...(this.state_.realize ? this.state_.realize.files : {}),
218
324
  "autobe/histories.json": JSON.stringify(this.histories_, null, 2),
219
325
  "autobe/tokenUsage.json": JSON.stringify(this.getTokenUsage(), null, 2),
220
326
  ...(this.state_.interface
@@ -235,22 +341,116 @@ export class AutoBeAgent<Model extends ILlmSchema.Model> {
235
341
  );
236
342
  }
237
343
 
344
+ /**
345
+ * Retrieves the complete conversation and development history.
346
+ *
347
+ * Returns the chronologically ordered record of all events from the current
348
+ * session including user messages, assistant responses, development phase
349
+ * activities, progress events, and completion notifications. This
350
+ * comprehensive history enables conversation replay, development process
351
+ * analysis, and understanding of how requirements evolved into working
352
+ * software.
353
+ *
354
+ * The history provides complete transparency into the vibe coding process,
355
+ * showing both conversational interactions and behind-the-scenes development
356
+ * activities. This information is valuable for debugging, process
357
+ * improvement, and educational purposes to understand the agent's
358
+ * decision-making process.
359
+ *
360
+ * @returns Chronologically ordered array of all history records including
361
+ * messages, events, and development activities
362
+ */
238
363
  public getHistories(): AutoBeHistory[] {
239
364
  return this.histories_;
240
365
  }
241
366
 
367
+ /**
368
+ * Retrieves comprehensive AI token usage statistics for the current session.
369
+ *
370
+ * Returns detailed breakdown of token consumption across all specialized
371
+ * agents and processing phases, enabling cost monitoring, performance
372
+ * analysis, and optimization of AI resource utilization. Statistics include
373
+ * aggregate totals and component-specific breakdowns with input/output
374
+ * categorization, caching analysis, and reasoning token tracking.
375
+ *
376
+ * Token usage data is essential for understanding the computational costs of
377
+ * different development phases and optimizing AI efficiency. The breakdown
378
+ * helps identify which agents or operations consume the most resources,
379
+ * enabling targeted optimization efforts while maintaining development
380
+ * quality.
381
+ *
382
+ * @returns Comprehensive token usage statistics with detailed breakdowns by
383
+ * agent, operation type, and consumption category
384
+ */
242
385
  public getTokenUsage(): AutoBeTokenUsage {
243
386
  return this.agentica_.getTokenUsage();
244
387
  }
245
388
 
246
- /* -----------------------------------------------------------
247
- CONTEXTS
248
- ----------------------------------------------------------- */
249
389
  /** @internal */
250
390
  public getContext(): AutoBeContext<Model> {
251
391
  return this.context_;
252
392
  }
253
393
 
394
+ /* -----------------------------------------------------------
395
+ EVENT HANDLERS
396
+ ----------------------------------------------------------- */
397
+ /**
398
+ * Registers an event listener for specific development phase events.
399
+ *
400
+ * Enables client applications to receive real-time notifications about
401
+ * conversation flow, development progress, and completion events throughout
402
+ * the vibe coding pipeline. Event listeners provide visibility into agent
403
+ * activities and enable responsive user interfaces that can display progress,
404
+ * handle artifacts, and provide feedback.
405
+ *
406
+ * The type-safe event system ensures that listeners receive properly typed
407
+ * events corresponding to their registration type, enabling robust event
408
+ * handling without runtime type issues. Multiple listeners can be registered
409
+ * for the same event type to support complex notification requirements.
410
+ *
411
+ * @param type Event type to listen for (e.g., "analyzeComplete",
412
+ * "prismaStart")
413
+ * @param listener Callback function that receives the typed event when fired
414
+ * @returns The agent instance for method chaining
415
+ */
416
+ public on<Type extends AutoBeEvent.Type>(
417
+ type: Type,
418
+ listener: (event: AutoBeEvent.Mapper[Type]) => Promise<void> | void,
419
+ ): this {
420
+ emplaceMap(this.listeners_, type, () => new Set()).add(
421
+ listener as (event: AutoBeEvent) => any,
422
+ );
423
+ return this;
424
+ }
425
+
426
+ /**
427
+ * Unregisters a previously registered event listener.
428
+ *
429
+ * Removes the specified event listener from the agent's notification system,
430
+ * stopping further event notifications for that particular listener function.
431
+ * This is useful for cleanup, dynamic listener management, or when components
432
+ * no longer need to receive specific event notifications.
433
+ *
434
+ * The listener function reference must exactly match the function that was
435
+ * originally registered with {@link on} for successful removal. If no matching
436
+ * listener is found, the operation has no effect.
437
+ *
438
+ * @param type Event type the listener was registered for
439
+ * @param listener The exact listener function reference to remove
440
+ * @returns The agent instance for method chaining
441
+ */
442
+ public off<Type extends AutoBeEvent.Type>(
443
+ type: Type,
444
+ listener: (event: AutoBeEvent.Mapper[Type]) => Promise<void> | void,
445
+ ): this {
446
+ const set = this.listeners_.get(type);
447
+ if (set === undefined) return this;
448
+
449
+ set.delete(listener as (event: AutoBeEvent) => any);
450
+ if (set.size === 0) this.listeners_.delete(type);
451
+ return this;
452
+ }
453
+
254
454
  /** @internal */
255
455
  private async dispatch(event: AutoBeEvent): Promise<void> {
256
456
  const set = this.listeners_.get(event.type);