@autobe/agent 0.30.2 → 0.30.4-dev.20260324

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 (89) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +261 -0
  3. package/lib/AutoBeMockAgent.d.ts +2 -1
  4. package/lib/AutoBeMockAgent.js +37 -18
  5. package/lib/AutoBeMockAgent.js.map +1 -1
  6. package/lib/constants/AutoBeConfigConstant.d.ts +1 -1
  7. package/lib/constants/AutoBeSystemPromptConstant.d.ts +12 -11
  8. package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
  9. package/lib/index.mjs +497 -71
  10. package/lib/index.mjs.map +1 -1
  11. package/lib/orchestrate/analyze/histories/transformAnalyzeExtractDecisionsHistory.d.ts +18 -0
  12. package/lib/orchestrate/analyze/histories/transformAnalyzeExtractDecisionsHistory.js +51 -0
  13. package/lib/orchestrate/analyze/histories/transformAnalyzeExtractDecisionsHistory.js.map +1 -0
  14. package/lib/orchestrate/analyze/histories/transformAnalyzeScenarioHistory.js +1 -1
  15. package/lib/orchestrate/analyze/histories/transformAnalyzeScenarioHistory.js.map +1 -1
  16. package/lib/orchestrate/analyze/histories/transformAnalyzeScenarioReviewHistory.js +1 -1
  17. package/lib/orchestrate/analyze/histories/transformAnalyzeScenarioReviewHistory.js.map +1 -1
  18. package/lib/orchestrate/analyze/histories/transformAnalyzeSectionCrossFileReviewHistory.d.ts +1 -0
  19. package/lib/orchestrate/analyze/histories/transformAnalyzeSectionCrossFileReviewHistory.js +15 -1
  20. package/lib/orchestrate/analyze/histories/transformAnalyzeSectionCrossFileReviewHistory.js.map +1 -1
  21. package/lib/orchestrate/analyze/histories/transformAnalyzeSectionReviewHistory.js +1 -1
  22. package/lib/orchestrate/analyze/histories/transformAnalyzeSectionReviewHistory.js.map +1 -1
  23. package/lib/orchestrate/analyze/orchestrateAnalyze.js +48 -13
  24. package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
  25. package/lib/orchestrate/analyze/orchestrateAnalyzeExtractDecisions.d.ts +17 -0
  26. package/lib/orchestrate/analyze/orchestrateAnalyzeExtractDecisions.js +345 -0
  27. package/lib/orchestrate/analyze/orchestrateAnalyzeExtractDecisions.js.map +1 -0
  28. package/lib/orchestrate/analyze/orchestrateAnalyzeScenario.js +2 -2
  29. package/lib/orchestrate/analyze/orchestrateAnalyzeSectionCrossFileReview.d.ts +1 -0
  30. package/lib/orchestrate/analyze/orchestrateAnalyzeSectionCrossFileReview.js +1 -0
  31. package/lib/orchestrate/analyze/orchestrateAnalyzeSectionCrossFileReview.js.map +1 -1
  32. package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeExtractDecisionsApplication.d.ts +91 -0
  33. package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeExtractDecisionsApplication.js +3 -0
  34. package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeExtractDecisionsApplication.js.map +1 -0
  35. package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeScenarioApplication.d.ts +15 -5
  36. package/lib/orchestrate/analyze/utils/buildErrorCodeRegistry.d.ts +0 -9
  37. package/lib/orchestrate/analyze/utils/buildErrorCodeRegistry.js +1 -13
  38. package/lib/orchestrate/analyze/utils/buildErrorCodeRegistry.js.map +1 -1
  39. package/lib/orchestrate/analyze/utils/detectDecisionConflicts.d.ts +63 -0
  40. package/lib/orchestrate/analyze/utils/detectDecisionConflicts.js +105 -0
  41. package/lib/orchestrate/analyze/utils/detectDecisionConflicts.js.map +1 -0
  42. package/lib/orchestrate/common/histories/transformPreliminaryHistory.js +1 -1
  43. package/lib/orchestrate/common/histories/transformPreliminaryHistory.js.map +1 -1
  44. package/lib/orchestrate/interface/histories/transformInterfaceActionEndpointReviewHistory.js +1 -1
  45. package/lib/orchestrate/interface/histories/transformInterfaceActionEndpointReviewHistory.js.map +1 -1
  46. package/lib/orchestrate/interface/histories/transformInterfaceBaseEndpointReviewHistory.js +1 -1
  47. package/lib/orchestrate/interface/histories/transformInterfaceBaseEndpointReviewHistory.js.map +1 -1
  48. package/lib/orchestrate/interface/histories/transformInterfaceSchemaRefineHistory.js +1 -1
  49. package/lib/orchestrate/interface/histories/transformInterfaceSchemaRefineHistory.js.map +1 -1
  50. package/lib/orchestrate/interface/orchestrateInterfaceSchemaRefine.js +1 -2
  51. package/lib/orchestrate/interface/orchestrateInterfaceSchemaRefine.js.map +1 -1
  52. package/lib/orchestrate/interface/orchestrateInterfaceSchemaReview.js +1 -2
  53. package/lib/orchestrate/interface/orchestrateInterfaceSchemaReview.js.map +1 -1
  54. package/lib/orchestrate/interface/utils/AutoBeJsonSchemaValidator.js +316 -283
  55. package/lib/orchestrate/interface/utils/AutoBeJsonSchemaValidator.js.map +1 -1
  56. package/lib/orchestrate/prisma/histories/transformPrismaComponentReviewHistory.js +2 -2
  57. package/lib/orchestrate/prisma/histories/transformPrismaComponentReviewHistory.js.map +1 -1
  58. package/lib/orchestrate/prisma/histories/transformPrismaComponentsHistory.js +1 -1
  59. package/lib/orchestrate/prisma/histories/transformPrismaComponentsHistory.js.map +1 -1
  60. package/lib/orchestrate/prisma/histories/transformPrismaGroupHistory.js +1 -1
  61. package/lib/orchestrate/prisma/histories/transformPrismaGroupHistory.js.map +1 -1
  62. package/lib/orchestrate/prisma/histories/transformPrismaGroupReviewHistory.js +1 -1
  63. package/lib/orchestrate/prisma/histories/transformPrismaGroupReviewHistory.js.map +1 -1
  64. package/lib/orchestrate/prisma/histories/transformPrismaSchemaHistory.js +1 -1
  65. package/lib/orchestrate/prisma/histories/transformPrismaSchemaHistory.js.map +1 -1
  66. package/lib/orchestrate/prisma/histories/transformPrismaSchemaReviewHistory.js +1 -1
  67. package/lib/orchestrate/prisma/histories/transformPrismaSchemaReviewHistory.js.map +1 -1
  68. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +1 -1
  69. package/lib/structures/IAutoBeVendor.d.ts +13 -0
  70. package/package.json +5 -5
  71. package/src/AutoBeMockAgent.ts +283 -254
  72. package/src/constants/AutoBeConfigConstant.ts +1 -1
  73. package/src/constants/AutoBeSystemPromptConstant.ts +12 -11
  74. package/src/orchestrate/analyze/histories/transformAnalyzeExtractDecisionsHistory.ts +69 -0
  75. package/src/orchestrate/analyze/histories/transformAnalyzeSectionCrossFileReviewHistory.ts +20 -0
  76. package/src/orchestrate/analyze/orchestrateAnalyze.ts +58 -1
  77. package/src/orchestrate/analyze/orchestrateAnalyzeExtractDecisions.ts +97 -0
  78. package/src/orchestrate/analyze/orchestrateAnalyzeSectionCrossFileReview.ts +2 -0
  79. package/src/orchestrate/analyze/structures/IAutoBeAnalyzeExtractDecisionsApplication.ts +99 -0
  80. package/src/orchestrate/analyze/structures/IAutoBeAnalyzeScenarioApplication.ts +15 -5
  81. package/src/orchestrate/analyze/utils/buildErrorCodeRegistry.ts +0 -20
  82. package/src/orchestrate/analyze/utils/detectDecisionConflicts.ts +172 -0
  83. package/src/orchestrate/interface/orchestrateInterfaceSchemaRefine.ts +291 -292
  84. package/src/orchestrate/interface/orchestrateInterfaceSchemaReview.ts +309 -310
  85. package/src/orchestrate/interface/utils/AutoBeJsonSchemaValidator.ts +763 -725
  86. package/src/orchestrate/test/experimental/orchestrateTestCorrect.ast +237 -237
  87. package/src/orchestrate/test/experimental/orchestrateTestWrite.ast +322 -322
  88. package/src/orchestrate/test/experimental/transformTestCorrectHistories.ast +52 -52
  89. package/src/structures/IAutoBeVendor.ts +127 -113
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobe/agent",
3
- "version": "0.30.2",
3
+ "version": "0.30.4-dev.20260324",
4
4
  "description": "AI backend server code generator",
5
5
  "main": "lib/index.js",
6
6
  "author": "Wrtn Technologies",
@@ -31,8 +31,8 @@
31
31
  "typia": "^12.0.1",
32
32
  "uuid": "^11.1.0",
33
33
  "yaml": "^2.8.2",
34
- "@autobe/interface": "^0.30.2",
35
- "@autobe/utils": "^0.30.2"
34
+ "@autobe/utils": "^0.30.4-dev.20260324",
35
+ "@autobe/interface": "^0.30.4-dev.20260324"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@rollup/plugin-json": "^6.1.0",
@@ -44,8 +44,8 @@
44
44
  "rollup": "^4.40.1",
45
45
  "ts-node": "^10.9.2",
46
46
  "typescript": "~5.9.3",
47
- "@autobe/filesystem": "^0.30.2",
48
- "@autobe/compiler": "^0.30.2"
47
+ "@autobe/filesystem": "^0.30.4-dev.20260324",
48
+ "@autobe/compiler": "^0.30.4-dev.20260324"
49
49
  },
50
50
  "keywords": [
51
51
  "ai",
@@ -1,254 +1,283 @@
1
- import {
2
- AutoBeAssistantMessageHistory,
3
- AutoBeEvent,
4
- AutoBeEventSnapshot,
5
- AutoBeHistory,
6
- AutoBePhase,
7
- AutoBeUserConversateContent,
8
- AutoBeUserMessageHistory,
9
- IAutoBeAgent,
10
- IAutoBeCompiler,
11
- IAutoBeCompilerListener,
12
- IAutoBeGetFilesOptions,
13
- IAutoBePlaygroundReplay,
14
- } from "@autobe/interface";
15
- import { Singleton, randint, sleep_for } from "tstl";
16
- import { v7 } from "uuid";
17
-
18
- import { AutoBeAgentBase } from "./AutoBeAgentBase";
19
- import { AutoBeState } from "./context/AutoBeState";
20
- import { AutoBeTokenUsage } from "./context/AutoBeTokenUsage";
21
- import { createAutoBeUserMessageContent } from "./factory/createAutoBeMessageContent";
22
- import { createAutoBeState } from "./factory/createAutoBeState";
23
- import { getAutoBeGenerated } from "./factory/getAutoBeGenerated";
24
-
25
- /** @internal */
26
- export class AutoBeMockAgent extends AutoBeAgentBase implements IAutoBeAgent {
27
- private readonly props_: AutoBeMockAgent.IProps;
28
- private readonly histories_: AutoBeHistory[];
29
- private readonly compiler_: Singleton<Promise<IAutoBeCompiler>>;
30
- private token_usage_: AutoBeTokenUsage;
31
-
32
- public constructor(props: AutoBeMockAgent.IProps) {
33
- super();
34
- this.props_ = props;
35
- this.histories_ = [];
36
- this.compiler_ = new Singleton(async () =>
37
- props.compiler({
38
- realize: {
39
- test: {
40
- onOperation: async () => {},
41
- onReset: async () => {},
42
- },
43
- },
44
- }),
45
- );
46
- this.token_usage_ = new AutoBeTokenUsage();
47
- }
48
-
49
- public async conversate(
50
- content:
51
- | string
52
- | AutoBeUserConversateContent
53
- | AutoBeUserConversateContent[],
54
- ): Promise<AutoBeHistory[]> {
55
- const contents: AutoBeUserConversateContent[] =
56
- typeof content === "string"
57
- ? [
58
- {
59
- type: "text",
60
- text: content,
61
- },
62
- ]
63
- : Array.isArray(content)
64
- ? content
65
- : [content];
66
- // THE USER-MESSAGE
67
- const userMessage: AutoBeUserMessageHistory = {
68
- id: v7(),
69
- type: "userMessage",
70
- contents: contents.map((c) =>
71
- createAutoBeUserMessageContent({ content: c }),
72
- ),
73
- created_at: new Date().toISOString(),
74
- };
75
- void this.dispatch(userMessage).catch(() => {});
76
-
77
- // ALREADY REALIZED CASE
78
- const state: AutoBeState = createAutoBeState(this.histories_);
79
- if (state.realize !== null) {
80
- await sleep_for(2_000);
81
- const assistantMessage: AutoBeAssistantMessageHistory = {
82
- id: v7(),
83
- type: "assistantMessage",
84
- text: [
85
- "AutoBE has successfully realized the application.",
86
- "",
87
- "Thanks for using AutoBE!",
88
- ].join("\n"),
89
- created_at: new Date().toISOString(),
90
- completed_at: new Date().toISOString(),
91
- };
92
- void this.dispatch(assistantMessage).catch(() => {});
93
- this.histories_.push(userMessage, assistantMessage);
94
- return this.histories_;
95
- }
96
- const take = async (type: AutoBePhase): Promise<void> => {
97
- const snapshots: AutoBeEventSnapshot[] | null =
98
- this.getEventSnapshots(type);
99
- if (snapshots === null) {
100
- this.histories_.push(userMessage);
101
- this.histories_.push({
102
- id: v7(),
103
- type: "assistantMessage",
104
- text: [
105
- "The histories are prepared until current state.",
106
- "",
107
- "Thanks for using AutoBE!",
108
- ].join("\n"),
109
- created_at: new Date().toISOString(),
110
- completed_at: new Date().toISOString(),
111
- });
112
- return;
113
- }
114
- for (const s of snapshots) {
115
- const time: number = sleepMap[s.event.type] ?? 500;
116
- await sleep_for(randint(time * 0.2, time * 1.8));
117
- void this.dispatch(s.event).catch(() => {});
118
- this.token_usage_ = new AutoBeTokenUsage(s.tokenUsage);
119
- }
120
- this.histories_.push(userMessage);
121
- this.histories_.push(
122
- this.props_.replay.histories.find((h) => h.type === type)!,
123
- );
124
- };
125
- if (state.analyze === null) await take("analyze");
126
- else if (state.database === null) await take("database");
127
- else if (state.interface === null) await take("interface");
128
- else if (state.test === null) await take("test");
129
- else if (state.realize === null) await take("realize");
130
- return this.histories_;
131
- }
132
-
133
- public getHistories(): AutoBeHistory[] {
134
- return this.histories_;
135
- }
136
-
137
- public getTokenUsage(): AutoBeTokenUsage {
138
- return this.token_usage_;
139
- }
140
-
141
- public async getFiles(
142
- options?: IAutoBeGetFilesOptions,
143
- ): Promise<Record<string, string>> {
144
- return await getAutoBeGenerated({
145
- compiler: await this.compiler_.get(),
146
- state: createAutoBeState(this.histories_),
147
- histories: this.getHistories(),
148
- tokenUsage: this.getTokenUsage(),
149
- options,
150
- });
151
- }
152
-
153
- public getPhase(): AutoBePhase | null {
154
- const state: AutoBeState = createAutoBeState(this.histories_);
155
- if (state.analyze === null) return null;
156
- else if (state.realize?.step === state.analyze.step) return "realize";
157
- else if (state.test?.step === state.analyze.step) return "test";
158
- else if (state.interface?.step === state.analyze.step) return "interface";
159
- else if (state.database?.step === state.analyze.step) return "database";
160
- return "analyze";
161
- }
162
-
163
- private getEventSnapshots(state: AutoBePhase): AutoBeEventSnapshot[] | null {
164
- return this.props_.replay[state] ?? null;
165
- }
166
- }
167
- export namespace AutoBeMockAgent {
168
- export interface IProps {
169
- compiler: (
170
- listener: IAutoBeCompilerListener,
171
- ) => IAutoBeCompiler | Promise<IAutoBeCompiler>;
172
- replay: IAutoBePlaygroundReplay;
173
- }
174
- }
175
-
176
- const sleepMap: Record<AutoBeEvent.Type, number> = {
177
- userMessage: 1_000,
178
- assistantMessage: 1_000,
179
- vendorRequest: 0,
180
- vendorResponse: 0,
181
- vendorTimeout: 0,
182
- jsonParseError: 0,
183
- jsonValidateError: 0,
184
- consentFunctionCall: 0,
185
- preliminary: 0,
186
- // DESCRIBE
187
- imageDescribeStart: 1_000,
188
- imageDescribeDraft: 300,
189
- imageDescribeComplete: 1_000,
190
- // ANALYZE
191
- analyzeStart: 1_000,
192
- analyzeScenario: 1_000,
193
- analyzeWriteModule: 500,
194
- analyzeWriteUnit: 500,
195
- analyzeWriteSection: 500,
196
- analyzeModuleReview: 300,
197
- analyzeUnitReview: 300,
198
- analyzeSectionReview: 300,
199
- analyzeScenarioReview: 300,
200
- analyzeComplete: 1_000,
201
- // PRISMA
202
- databaseStart: 1_000,
203
- databaseGroup: 1_000,
204
- databaseGroupReview: 1_000,
205
- databaseAuthorization: 1_000,
206
- databaseAuthorizationReview: 500,
207
- databaseComponent: 1_000,
208
- databaseComponentReview: 500,
209
- databaseSchema: 500,
210
- databaseSchemaReview: 500,
211
- databaseValidate: 2_000,
212
- databaseCorrect: 500,
213
- databaseComplete: 1_000,
214
- // INTERFACE
215
- interfaceStart: 1_000,
216
- interfaceGroup: 1_000,
217
- interfaceEndpoint: 1_000,
218
- interfaceEndpointReview: 1_000,
219
- interfaceOperation: 400,
220
- interfaceOperationReview: 400,
221
- interfaceAuthorization: 400,
222
- interfaceSchema: 400,
223
- interfaceSchemaCasting: 400,
224
- interfaceSchemaRefine: 400,
225
- interfaceSchemaReview: 200,
226
- interfaceSchemaRename: 200,
227
- interfaceSchemaComplement: 2_000,
228
- interfaceComplete: 1_000,
229
- interfacePrerequisite: 400,
230
- // TEST
231
- testStart: 1_000,
232
- testScenario: 40,
233
- testScenarioReview: 40,
234
- testWrite: 40,
235
- testValidate: 100,
236
- testCorrect: 100,
237
- testComplete: 1_000,
238
- // REALIZE
239
- realizeStart: 1_000,
240
- realizeComplete: 1_000,
241
- realizePlan: 80,
242
- realizeWrite: 80,
243
- realizeCorrect: 80,
244
- realizeValidate: 200,
245
- realizeAuthorizationStart: 1_000,
246
- realizeAuthorizationWrite: 200,
247
- realizeAuthorizationValidate: 200,
248
- realizeAuthorizationCorrect: 200,
249
- realizeAuthorizationComplete: 1_000,
250
- realizeTestStart: 1_000,
251
- realizeTestReset: 2_500,
252
- realizeTestOperation: 400,
253
- realizeTestComplete: 1_000,
254
- };
1
+ import {
2
+ AutoBeAssistantMessageHistory,
3
+ AutoBeEvent,
4
+ AutoBeEventSnapshot,
5
+ AutoBeHistory,
6
+ AutoBePhase,
7
+ AutoBeUserConversateContent,
8
+ AutoBeUserMessageHistory,
9
+ IAutoBeAgent,
10
+ IAutoBeCompiler,
11
+ IAutoBeCompilerListener,
12
+ IAutoBeGetFilesOptions,
13
+ IAutoBePlaygroundReplay,
14
+ } from "@autobe/interface";
15
+ import { Singleton, randint, sleep_for } from "tstl";
16
+ import { v7 } from "uuid";
17
+
18
+ import { AutoBeAgentBase } from "./AutoBeAgentBase";
19
+ import { AutoBeState } from "./context/AutoBeState";
20
+ import { AutoBeTokenUsage } from "./context/AutoBeTokenUsage";
21
+ import { createAutoBeUserMessageContent } from "./factory/createAutoBeMessageContent";
22
+ import { createAutoBeState } from "./factory/createAutoBeState";
23
+ import { getAutoBeGenerated } from "./factory/getAutoBeGenerated";
24
+
25
+ /** @internal */
26
+ export class AutoBeMockAgent extends AutoBeAgentBase implements IAutoBeAgent {
27
+ private readonly props_: AutoBeMockAgent.IProps;
28
+ private readonly histories_: AutoBeHistory[];
29
+ private readonly compiler_: Singleton<Promise<IAutoBeCompiler>>;
30
+ private token_usage_: AutoBeTokenUsage;
31
+
32
+ public constructor(props: AutoBeMockAgent.IProps) {
33
+ super();
34
+ this.props_ = props;
35
+ this.histories_ = [];
36
+ this.compiler_ = new Singleton(async () =>
37
+ props.compiler({
38
+ realize: {
39
+ test: {
40
+ onOperation: async () => {},
41
+ onReset: async () => {},
42
+ },
43
+ },
44
+ }),
45
+ );
46
+ this.token_usage_ = new AutoBeTokenUsage();
47
+ }
48
+
49
+ public async conversate(
50
+ content:
51
+ | string
52
+ | AutoBeUserConversateContent
53
+ | AutoBeUserConversateContent[],
54
+ ): Promise<AutoBeHistory[]> {
55
+ const contents: AutoBeUserConversateContent[] =
56
+ typeof content === "string"
57
+ ? [
58
+ {
59
+ type: "text",
60
+ text: content,
61
+ },
62
+ ]
63
+ : Array.isArray(content)
64
+ ? content
65
+ : [content];
66
+ // ALREADY REALIZED CASE
67
+ const state: AutoBeState = createAutoBeState(this.histories_);
68
+ if (state.realize !== null) {
69
+ const userMessage: AutoBeUserMessageHistory = {
70
+ id: v7(),
71
+ type: "userMessage",
72
+ contents: contents.map((c) =>
73
+ createAutoBeUserMessageContent({ content: c }),
74
+ ),
75
+ created_at: new Date().toISOString(),
76
+ };
77
+ void this.dispatch(userMessage).catch(() => {});
78
+ await sleep_for(2_000);
79
+ const assistantMessage: AutoBeAssistantMessageHistory = {
80
+ id: v7(),
81
+ type: "assistantMessage",
82
+ text: [
83
+ "AutoBE has successfully realized the application.",
84
+ "",
85
+ "Thanks for using AutoBE!",
86
+ ].join("\n"),
87
+ created_at: new Date().toISOString(),
88
+ completed_at: new Date().toISOString(),
89
+ };
90
+ void this.dispatch(assistantMessage).catch(() => {});
91
+ this.histories_.push(userMessage, assistantMessage);
92
+ return this.histories_;
93
+ }
94
+ const take = async (type: AutoBePhase): Promise<void> => {
95
+ const snapshots: AutoBeEventSnapshot[] | null =
96
+ this.getEventSnapshots(type);
97
+ if (snapshots === null) {
98
+ this.histories_.push({
99
+ id: v7(),
100
+ type: "userMessage",
101
+ contents: contents.map((c) =>
102
+ createAutoBeUserMessageContent({ content: c }),
103
+ ),
104
+ created_at: new Date().toISOString(),
105
+ });
106
+ this.histories_.push({
107
+ id: v7(),
108
+ type: "assistantMessage",
109
+ text: [
110
+ "The histories are prepared until current state.",
111
+ "",
112
+ "Thanks for using AutoBE!",
113
+ ].join("\n"),
114
+ created_at: new Date().toISOString(),
115
+ completed_at: new Date().toISOString(),
116
+ });
117
+ return;
118
+ }
119
+ // Find the nearest user message that led into this phase for history
120
+ // tracking. There may be assistant messages between the user request
121
+ // and the resulting phase history, so we search backwards.
122
+ const phaseIndex = this.props_.replay.histories.findIndex(
123
+ (h) => h.type === type,
124
+ );
125
+ const originalUserMessage: AutoBeHistory | undefined =
126
+ phaseIndex > 0
127
+ ? this.props_.replay.histories
128
+ .slice(0, phaseIndex)
129
+ .reverse()
130
+ .find((h) => h.type === "userMessage")
131
+ : undefined;
132
+ for (const s of snapshots) {
133
+ const time: number =
134
+ this.props_.delay?.(s.event.type) ?? sleepMap[s.event.type] ?? 500;
135
+ await sleep_for(randint(time * 0.2, time * 1.8));
136
+ void this.dispatch(s.event).catch(() => {});
137
+ this.token_usage_ = new AutoBeTokenUsage(s.tokenUsage);
138
+ }
139
+ this.histories_.push(
140
+ originalUserMessage?.type === "userMessage"
141
+ ? originalUserMessage
142
+ : {
143
+ id: v7(),
144
+ type: "userMessage",
145
+ contents: contents.map((c) =>
146
+ createAutoBeUserMessageContent({ content: c }),
147
+ ),
148
+ created_at: new Date().toISOString(),
149
+ },
150
+ );
151
+ this.histories_.push(
152
+ this.props_.replay.histories.find((h) => h.type === type)!,
153
+ );
154
+ };
155
+ if (state.analyze === null) await take("analyze");
156
+ else if (state.database === null) await take("database");
157
+ else if (state.interface === null) await take("interface");
158
+ else if (state.test === null) await take("test");
159
+ else if (state.realize === null) await take("realize");
160
+ return this.histories_;
161
+ }
162
+
163
+ public getHistories(): AutoBeHistory[] {
164
+ return this.histories_;
165
+ }
166
+
167
+ public getTokenUsage(): AutoBeTokenUsage {
168
+ return this.token_usage_;
169
+ }
170
+
171
+ public async getFiles(
172
+ options?: IAutoBeGetFilesOptions,
173
+ ): Promise<Record<string, string>> {
174
+ return await getAutoBeGenerated({
175
+ compiler: await this.compiler_.get(),
176
+ state: createAutoBeState(this.histories_),
177
+ histories: this.getHistories(),
178
+ tokenUsage: this.getTokenUsage(),
179
+ options,
180
+ });
181
+ }
182
+
183
+ public getPhase(): AutoBePhase | null {
184
+ const state: AutoBeState = createAutoBeState(this.histories_);
185
+ if (state.analyze === null) return null;
186
+ else if (state.realize?.step === state.analyze.step) return "realize";
187
+ else if (state.test?.step === state.analyze.step) return "test";
188
+ else if (state.interface?.step === state.analyze.step) return "interface";
189
+ else if (state.database?.step === state.analyze.step) return "database";
190
+ return "analyze";
191
+ }
192
+
193
+ private getEventSnapshots(state: AutoBePhase): AutoBeEventSnapshot[] | null {
194
+ return this.props_.replay[state] ?? null;
195
+ }
196
+ }
197
+ export namespace AutoBeMockAgent {
198
+ export interface IProps {
199
+ compiler: (
200
+ listener: IAutoBeCompilerListener,
201
+ ) => IAutoBeCompiler | Promise<IAutoBeCompiler>;
202
+ replay: IAutoBePlaygroundReplay;
203
+ delay?: ((type: AutoBeEvent.Type) => number | undefined) | undefined;
204
+ }
205
+ }
206
+
207
+ const sleepMap: Record<AutoBeEvent.Type, number> = {
208
+ userMessage: 1_000,
209
+ assistantMessage: 1_000,
210
+ vendorRequest: 0,
211
+ vendorResponse: 0,
212
+ vendorTimeout: 0,
213
+ jsonParseError: 0,
214
+ jsonValidateError: 0,
215
+ consentFunctionCall: 0,
216
+ preliminary: 0,
217
+ // DESCRIBE
218
+ imageDescribeStart: 1_000,
219
+ imageDescribeDraft: 300,
220
+ imageDescribeComplete: 1_000,
221
+ // ANALYZE
222
+ analyzeStart: 1_000,
223
+ analyzeScenario: 1_000,
224
+ analyzeWriteModule: 500,
225
+ analyzeWriteUnit: 250,
226
+ analyzeWriteSection: 200,
227
+ analyzeSectionReview: 300,
228
+ analyzeScenarioReview: 300,
229
+ analyzeComplete: 1_000,
230
+ // PRISMA
231
+ databaseStart: 1_000,
232
+ databaseGroup: 1_000,
233
+ databaseGroupReview: 1_000,
234
+ databaseAuthorization: 1_000,
235
+ databaseAuthorizationReview: 500,
236
+ databaseComponent: 1_000,
237
+ databaseComponentReview: 500,
238
+ databaseSchema: 500,
239
+ databaseSchemaReview: 500,
240
+ databaseValidate: 2_000,
241
+ databaseCorrect: 500,
242
+ databaseComplete: 1_000,
243
+ // INTERFACE
244
+ interfaceStart: 1_000,
245
+ interfaceGroup: 1_000,
246
+ interfaceEndpoint: 500,
247
+ interfaceEndpointReview: 1_000,
248
+ interfaceOperation: 400,
249
+ interfaceOperationReview: 500,
250
+ interfaceAuthorization: 400,
251
+ interfaceSchema: 400,
252
+ interfaceSchemaCasting: 400,
253
+ interfaceSchemaRefine: 400,
254
+ interfaceSchemaReview: 200,
255
+ interfaceSchemaRename: 200,
256
+ interfaceSchemaComplement: 2_000,
257
+ interfaceComplete: 1_000,
258
+ interfacePrerequisite: 400,
259
+ // TEST
260
+ testStart: 1_000,
261
+ testScenario: 40,
262
+ testScenarioReview: 40,
263
+ testWrite: 40,
264
+ testValidate: 100,
265
+ testCorrect: 100,
266
+ testComplete: 1_000,
267
+ // REALIZE
268
+ realizeStart: 1_000,
269
+ realizeComplete: 1_000,
270
+ realizePlan: 80,
271
+ realizeWrite: 80,
272
+ realizeCorrect: 80,
273
+ realizeValidate: 200,
274
+ realizeAuthorizationStart: 1_000,
275
+ realizeAuthorizationWrite: 200,
276
+ realizeAuthorizationValidate: 200,
277
+ realizeAuthorizationCorrect: 200,
278
+ realizeAuthorizationComplete: 1_000,
279
+ realizeTestStart: 1_000,
280
+ realizeTestReset: 2_500,
281
+ realizeTestOperation: 400,
282
+ realizeTestComplete: 1_000,
283
+ };
@@ -66,7 +66,7 @@ export const enum AutoBeConfigConstant {
66
66
  * while still providing a reasonable bound to prevent infinite correction
67
67
  * loops.
68
68
  */
69
- DATABASE_CORRECT_RETRY = 20,
69
+ DATABASE_CORRECT_RETRY = 30,
70
70
 
71
71
  /**
72
72
  * Retry attempts for LLM function-calling execution flows.