@autobe/agent 0.9.1 → 0.10.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 (185) hide show
  1. package/lib/AutoBeAgent.js +16 -5
  2. package/lib/AutoBeAgent.js.map +1 -1
  3. package/lib/constants/AutoBeSystemPromptConstant.d.ts +6 -4
  4. package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
  5. package/lib/context/AutoBeTokenUsage.d.ts +15 -1
  6. package/lib/context/AutoBeTokenUsage.js +56 -1
  7. package/lib/context/AutoBeTokenUsage.js.map +1 -1
  8. package/lib/context/IAutoBeApplicationProps.d.ts +0 -61
  9. package/lib/factory/createAutoBeApplication.js +298 -773
  10. package/lib/factory/createAutoBeApplication.js.map +1 -1
  11. package/lib/index.mjs +5116 -7271
  12. package/lib/index.mjs.map +1 -1
  13. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js +82 -319
  14. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js.map +1 -1
  15. package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js +0 -1
  16. package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js.map +1 -1
  17. package/lib/orchestrate/analyze/orchestrateAnalyze.js +97 -294
  18. package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
  19. package/lib/orchestrate/facade/transformFacadeStateMessage.js +2 -2
  20. package/lib/orchestrate/facade/transformFacadeStateMessage.js.map +1 -1
  21. package/lib/orchestrate/index.d.ts +2 -2
  22. package/lib/orchestrate/index.js +4 -4
  23. package/lib/orchestrate/index.js.map +1 -1
  24. package/lib/orchestrate/interface/orchestrateInterface.js +9 -3
  25. package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
  26. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +56 -142
  27. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
  28. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +195 -199
  29. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +1 -1
  30. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +75 -172
  31. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
  32. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +772 -1097
  33. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
  34. package/lib/orchestrate/interface/transformInterfaceHistories.js +2 -0
  35. package/lib/orchestrate/interface/transformInterfaceHistories.js.map +1 -1
  36. package/lib/orchestrate/prisma/orchestratePrismaComponent.js +64 -175
  37. package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -1
  38. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +552 -1073
  39. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
  40. package/lib/orchestrate/prisma/orchestratePrismaSchema.js +571 -1119
  41. package/lib/orchestrate/prisma/orchestratePrismaSchema.js.map +1 -1
  42. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js +9 -0
  43. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js.map +1 -1
  44. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js +8 -0
  45. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js.map +1 -1
  46. package/lib/orchestrate/realize/orchestrateRealize.d.ts +11 -0
  47. package/lib/orchestrate/realize/orchestrateRealize.js +109 -0
  48. package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -0
  49. package/lib/orchestrate/realize/orchestrateRealizeCoder.d.ts +25 -0
  50. package/lib/orchestrate/realize/orchestrateRealizeCoder.js +337 -0
  51. package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -0
  52. package/lib/orchestrate/realize/orchestrateRealizeIntegrator.d.ts +52 -0
  53. package/lib/orchestrate/realize/orchestrateRealizeIntegrator.js +57 -0
  54. package/lib/orchestrate/realize/orchestrateRealizeIntegrator.js.map +1 -0
  55. package/lib/orchestrate/realize/orchestrateRealizePlanner.d.ts +80 -0
  56. package/lib/orchestrate/realize/orchestrateRealizePlanner.js +53 -0
  57. package/lib/orchestrate/realize/orchestrateRealizePlanner.js.map +1 -0
  58. package/lib/orchestrate/realize/orchestrateRealizeValidator.d.ts +46 -0
  59. package/lib/orchestrate/realize/orchestrateRealizeValidator.js +37 -0
  60. package/lib/orchestrate/realize/orchestrateRealizeValidator.js.map +1 -0
  61. package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.d.ts +33 -0
  62. package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.js +3 -0
  63. package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.js.map +1 -0
  64. package/lib/orchestrate/realize/transformRealizeCoderHistories.d.ts +5 -0
  65. package/lib/orchestrate/realize/transformRealizeCoderHistories.js +127 -0
  66. package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -0
  67. package/lib/orchestrate/test/compile/completeTestCode.d.ts +2 -0
  68. package/lib/orchestrate/test/compile/completeTestCode.js +21 -0
  69. package/lib/orchestrate/test/compile/completeTestCode.js.map +1 -0
  70. package/lib/orchestrate/test/{filterTestFileName.js → compile/filterTestFileName.js} +1 -1
  71. package/lib/orchestrate/test/compile/filterTestFileName.js.map +1 -0
  72. package/lib/orchestrate/test/compile/getTestExternalDeclarations.d.ts +3 -0
  73. package/lib/orchestrate/test/compile/getTestExternalDeclarations.js +27 -0
  74. package/lib/orchestrate/test/compile/getTestExternalDeclarations.js.map +1 -0
  75. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.d.ts +5 -0
  76. package/lib/orchestrate/test/{compileTestScenario.js → compile/getTestScenarioArtifacts.js} +11 -5
  77. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js.map +1 -0
  78. package/lib/orchestrate/test/orchestrateTest.js +14 -9
  79. package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
  80. package/lib/orchestrate/test/orchestrateTestCorrect.d.ts +3 -2
  81. package/lib/orchestrate/test/orchestrateTestCorrect.js +150 -349
  82. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  83. package/lib/orchestrate/test/orchestrateTestScenario.js +323 -566
  84. package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
  85. package/lib/orchestrate/test/orchestrateTestWrite.d.ts +3 -2
  86. package/lib/orchestrate/test/orchestrateTestWrite.js +139 -76
  87. package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -1
  88. package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.d.ts +121 -0
  89. package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.js +3 -0
  90. package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.js.map +1 -0
  91. package/lib/orchestrate/test/structures/IAutoBeTestFunction.d.ts +8 -0
  92. package/lib/{utils/types/BackoffOptions.js → orchestrate/test/structures/IAutoBeTestFunction.js} +1 -1
  93. package/lib/orchestrate/test/structures/IAutoBeTestFunction.js.map +1 -0
  94. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.d.ts +32 -22
  95. package/lib/orchestrate/test/structures/IAutoBeTestScenarioArtifacts.d.ts +2 -0
  96. package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.d.ts +112 -0
  97. package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.js +3 -0
  98. package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.js.map +1 -0
  99. package/lib/orchestrate/test/structures/IAutoBeTestWriteResult.d.ts +7 -0
  100. package/lib/orchestrate/test/structures/IAutoBeTestWriteResult.js +3 -0
  101. package/lib/orchestrate/test/structures/IAutoBeTestWriteResult.js.map +1 -0
  102. package/lib/orchestrate/test/transformTestCorrectHistories.d.ts +3 -2
  103. package/lib/orchestrate/test/transformTestCorrectHistories.js +28 -41
  104. package/lib/orchestrate/test/transformTestCorrectHistories.js.map +1 -1
  105. package/lib/orchestrate/test/transformTestWriteHistories.d.ts +5 -4
  106. package/lib/orchestrate/test/transformTestWriteHistories.js +169 -32
  107. package/lib/orchestrate/test/transformTestWriteHistories.js.map +1 -1
  108. package/lib/structures/IAutoBeConfig.d.ts +11 -0
  109. package/lib/structures/IAutoBeProps.d.ts +12 -1
  110. package/lib/utils/backoffRetry.d.ts +4 -7
  111. package/lib/utils/backoffRetry.js +19 -37
  112. package/lib/utils/backoffRetry.js.map +1 -1
  113. package/lib/utils/forceRetry.d.ts +1 -0
  114. package/lib/{orchestrate/orchestrateRealize.js → utils/forceRetry.js} +15 -8
  115. package/lib/utils/forceRetry.js.map +1 -0
  116. package/package.json +8 -8
  117. package/src/AutoBeAgent.ts +26 -4
  118. package/src/constants/AutoBeSystemPromptConstant.ts +6 -4
  119. package/src/context/AutoBeTokenUsage.ts +85 -1
  120. package/src/context/IAutoBeApplicationProps.ts +0 -62
  121. package/src/factory/createAutoBeApplication.ts +2 -3
  122. package/src/orchestrate/analyze/AutoBeAnalyzeAgent.ts +8 -3
  123. package/src/orchestrate/analyze/AutoBeAnalyzeReviewer.ts +0 -1
  124. package/src/orchestrate/analyze/orchestrateAnalyze.ts +8 -37
  125. package/src/orchestrate/facade/transformFacadeStateMessage.ts +2 -1
  126. package/src/orchestrate/index.ts +2 -2
  127. package/src/orchestrate/interface/orchestrateInterface.ts +7 -0
  128. package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +4 -3
  129. package/src/orchestrate/interface/orchestrateInterfaceComponents.ts +26 -23
  130. package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +6 -4
  131. package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +14 -11
  132. package/src/orchestrate/interface/transformInterfaceHistories.ts +2 -0
  133. package/src/orchestrate/prisma/orchestratePrismaComponent.ts +10 -5
  134. package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +11 -5
  135. package/src/orchestrate/prisma/orchestratePrismaSchema.ts +16 -8
  136. package/src/orchestrate/prisma/transformPrismaComponentsHistories.ts +9 -0
  137. package/src/orchestrate/prisma/transformPrismaSchemaHistories.ts +8 -0
  138. package/src/orchestrate/realize/orchestrateRealize.ts +169 -0
  139. package/src/orchestrate/realize/orchestrateRealizeCoder.ts +156 -0
  140. package/src/orchestrate/realize/orchestrateRealizeIntegrator.ts +75 -0
  141. package/src/orchestrate/realize/orchestrateRealizePlanner.ts +115 -0
  142. package/src/orchestrate/realize/orchestrateRealizeValidator.ts +64 -0
  143. package/src/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.ts +36 -0
  144. package/src/orchestrate/realize/transformRealizeCoderHistories.ts +136 -0
  145. package/src/orchestrate/test/compile/completeTestCode.ts +35 -0
  146. package/src/orchestrate/test/{filterTestFileName.ts → compile/filterTestFileName.ts} +1 -1
  147. package/src/orchestrate/test/compile/getTestExternalDeclarations.ts +24 -0
  148. package/src/orchestrate/test/{compileTestScenario.ts → compile/getTestScenarioArtifacts.ts} +17 -8
  149. package/src/orchestrate/test/experimental/orchestrateTestCorrect.ast +240 -0
  150. package/src/orchestrate/test/experimental/orchestrateTestWrite.ast +316 -0
  151. package/src/orchestrate/test/experimental/transformTestCorrectHistories.ast +52 -0
  152. package/src/orchestrate/test/orchestrateTest.ts +38 -16
  153. package/src/orchestrate/test/orchestrateTestCorrect.ts +111 -338
  154. package/src/orchestrate/test/orchestrateTestScenario.ts +114 -69
  155. package/src/orchestrate/test/orchestrateTestWrite.ts +55 -153
  156. package/src/orchestrate/test/structures/IAutoBeTestCorrectApplication.ts +126 -0
  157. package/src/orchestrate/test/structures/IAutoBeTestFunction.ts +10 -0
  158. package/src/orchestrate/test/structures/IAutoBeTestScenarioApplication.ts +32 -22
  159. package/src/orchestrate/test/structures/IAutoBeTestScenarioArtifacts.ts +3 -0
  160. package/src/orchestrate/test/structures/IAutoBeTestWriteApplication.ts +117 -0
  161. package/src/orchestrate/test/structures/IAutoBeTestWriteResult.ts +9 -0
  162. package/src/orchestrate/test/transformTestCorrectHistories.ts +38 -43
  163. package/src/orchestrate/test/transformTestWriteHistories.ts +89 -35
  164. package/src/structures/IAutoBeConfig.ts +9 -0
  165. package/src/structures/IAutoBeProps.ts +17 -1
  166. package/src/utils/backoffRetry.ts +25 -36
  167. package/src/utils/forceRetry.ts +13 -0
  168. package/lib/factory/invertOpenApiDocument.d.ts +0 -3
  169. package/lib/factory/invertOpenApiDocument.js +0 -51
  170. package/lib/factory/invertOpenApiDocument.js.map +0 -1
  171. package/lib/orchestrate/orchestrateRealize.d.ts +0 -5
  172. package/lib/orchestrate/orchestrateRealize.js.map +0 -1
  173. package/lib/orchestrate/test/compileTestScenario.d.ts +0 -5
  174. package/lib/orchestrate/test/compileTestScenario.js.map +0 -1
  175. package/lib/orchestrate/test/filterTestFileName.js.map +0 -1
  176. package/lib/utils/StringUtil.d.ts +0 -4
  177. package/lib/utils/StringUtil.js +0 -43
  178. package/lib/utils/StringUtil.js.map +0 -1
  179. package/lib/utils/types/BackoffOptions.d.ts +0 -12
  180. package/lib/utils/types/BackoffOptions.js.map +0 -1
  181. package/src/factory/invertOpenApiDocument.ts +0 -63
  182. package/src/orchestrate/orchestrateRealize.ts +0 -18
  183. package/src/utils/StringUtil.ts +0 -45
  184. package/src/utils/types/BackoffOptions.ts +0 -15
  185. /package/lib/orchestrate/test/{filterTestFileName.d.ts → compile/filterTestFileName.d.ts} +0 -0
@@ -1,10 +1,7 @@
1
1
  import { IAgenticaController, MicroAgentica } from "@agentica/core";
2
2
  import {
3
- AutoBeTestFile,
4
- AutoBeTestScenario,
5
3
  AutoBeTestValidateEvent,
6
- AutoBeTestWriteEvent,
7
- IAutoBeTypeScriptCompilerResult,
4
+ IAutoBeTypeScriptCompileResult,
8
5
  } from "@autobe/interface";
9
6
  import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
10
7
  import { IPointer } from "tstl";
@@ -12,317 +9,147 @@ import typia from "typia";
12
9
 
13
10
  import { AutoBeContext } from "../../context/AutoBeContext";
14
11
  import { assertSchemaModel } from "../../context/assertSchemaModel";
15
- import { randomBackoffRetry } from "../../utils/backoffRetry";
16
12
  import { enforceToolCall } from "../../utils/enforceToolCall";
17
- import { compileTestScenario } from "./compileTestScenario";
18
- import { filterTestFileName } from "./filterTestFileName";
13
+ import { forceRetry } from "../../utils/forceRetry";
14
+ import { completeTestCode } from "./compile/completeTestCode";
15
+ import { IAutoBeTestCorrectApplication } from "./structures/IAutoBeTestCorrectApplication";
16
+ import { IAutoBeTestFunction } from "./structures/IAutoBeTestFunction";
19
17
  import { IAutoBeTestScenarioArtifacts } from "./structures/IAutoBeTestScenarioArtifacts";
18
+ import { IAutoBeTestWriteResult } from "./structures/IAutoBeTestWriteResult";
20
19
  import { transformTestCorrectHistories } from "./transformTestCorrectHistories";
21
20
 
22
- export async function orchestrateTestCorrect<Model extends ILlmSchema.Model>(
21
+ export const orchestrateTestCorrect = async <Model extends ILlmSchema.Model>(
23
22
  ctx: AutoBeContext<Model>,
24
- codes: AutoBeTestWriteEvent[],
25
- scenarios: AutoBeTestScenario[],
23
+ writeResult: IAutoBeTestWriteResult[],
26
24
  life: number = 4,
27
- ): Promise<AutoBeTestValidateEvent> {
28
- const files: AutoBeTestFile[] = codes.map(
29
- ({ filename, content }, index): AutoBeTestFile => {
30
- const scenario: AutoBeTestScenario = scenarios[index];
31
- return { location: filename, content, scenario };
32
- },
33
- );
34
-
35
- // 1) Build map of new test files from progress events
36
- const testFiles: Record<string, string> = Object.fromEntries(
37
- codes.map((c) => [c.filename, c.content]),
38
- );
39
-
40
- // 2) Keep only files outside the test directory from current state
41
- const retainedFiles: Record<string, string> = Object.fromEntries(
42
- Object.entries(ctx.state().interface?.files ?? {}).filter(([key]) =>
43
- filterTestFileName(key),
25
+ ): Promise<AutoBeTestValidateEvent[]> =>
26
+ Promise.all(
27
+ writeResult.map((w) =>
28
+ forceRetry(async () => {
29
+ const event: AutoBeTestValidateEvent = await compile(ctx, {
30
+ artifacts: w.artifacts,
31
+ scenario: w.scenario,
32
+ location: w.event.location,
33
+ script: w.event.final,
34
+ });
35
+ return predicate(
36
+ ctx,
37
+ {
38
+ artifacts: w.artifacts,
39
+ scenario: w.scenario,
40
+ location: w.event.location,
41
+ script: w.event.final,
42
+ },
43
+ event,
44
+ life,
45
+ );
46
+ }),
44
47
  ),
45
48
  );
46
49
 
47
- // 3) Merge and filter: keep .ts/.json, drop anything under "benchmark"
48
- const external = async (
49
- location: string,
50
- ): Promise<Record<string, string>> => {
51
- const content: string | undefined =
52
- await ctx.compiler.typescript.getExternal(location);
53
- if (content === undefined) throw new Error(`File not found: ${location}`);
54
- return { [location]: content };
55
- };
56
- const mergedFiles: Record<string, string> = {
57
- ...retainedFiles,
58
- ...testFiles,
59
- ...(await external("node_modules/@nestia/e2e/lib/TestValidator.d.ts")),
60
- ...(await external("node_modules/@nestia/fetcher/lib/IConnection.d.ts")),
61
- };
62
-
63
- // 4) Ask the LLM to correct the filtered file set
64
- const response: AutoBeTestValidateEvent = await step(
65
- ctx,
66
- mergedFiles,
67
- files,
68
- life,
69
- );
70
-
71
- // 5) Combine original + corrected files and dispatch event
72
- const event: AutoBeTestValidateEvent = {
73
- ...response,
74
- type: "testValidate",
75
- files: [
76
- ...Object.entries(mergedFiles).map(
77
- ([filename, content]): AutoBeTestFile => {
78
- return {
79
- location: filename,
80
- content,
81
- };
82
- },
83
- ),
84
- ...response.files,
85
- ],
86
- };
87
- return event;
88
- }
89
-
90
- /**
91
- * Modifies test code for each file and checks for compilation errors. When
92
- * compilation errors occur, it uses LLM to fix the code and attempts
93
- * recompilation. This process repeats up to the maximum retry count until
94
- * compilation succeeds.
95
- *
96
- * The function is a critical part of the test generation pipeline that ensures
97
- * all generated test files are syntactically correct and compilable.
98
- *
99
- * @param ctx AutoBe context object
100
- * @param entireFiles Map of all files to compile (filename: content)
101
- * @param testFiles Map of files to compile (filename: content)
102
- * @param life Number of remaining retry attempts
103
- * @returns Event object containing successful compilation result and modified
104
- * files
105
- */
106
- async function step<Model extends ILlmSchema.Model>(
50
+ const compile = async <Model extends ILlmSchema.Model>(
107
51
  ctx: AutoBeContext<Model>,
108
- entireFiles: Record<string, string>,
109
- testFiles: AutoBeTestFile[],
110
- life: number,
111
- ): Promise<AutoBeTestValidateEvent> {
112
- // COMPILE TEST CODE
113
- const result: IAutoBeTypeScriptCompilerResult =
114
- await ctx.compiler.typescript.compile({
115
- files: entireFiles,
116
- });
117
-
118
- if (result.type === "success") {
119
- // SUCCESS
120
- return {
121
- type: "testValidate",
122
- created_at: new Date().toISOString(),
123
- files: testFiles,
124
- result,
125
- step: ctx.state().interface?.step ?? 0,
126
- };
127
- }
128
-
129
- // EXCEPTION ERROR
130
- if (result.type === "exception") {
131
- ctx.dispatch({
132
- type: "testValidate",
133
- created_at: new Date().toISOString(),
134
- files: testFiles,
135
- result,
136
- step: ctx.state().interface?.step ?? 0,
137
- });
138
- throw new Error(JSON.stringify(result.error, null, 2));
139
- }
140
-
141
- // Make the diagnostics object (e.g. { "test/features/api/article.ts": [error1, error2] })
142
- const diagnostics: Record<
143
- string,
144
- IAutoBeTypeScriptCompilerResult.IDiagnostic[]
145
- > = {};
146
-
147
- result.diagnostics.forEach((d) => {
148
- if (d.file === null) return;
149
-
150
- diagnostics[d.file] = diagnostics[d.file] ?? [];
151
- diagnostics[d.file].push(d);
152
- });
153
-
154
- if (Object.keys(diagnostics).length === 0) {
155
- /**
156
- * SUCCESS (Because typescript compiler can't success to compile the json
157
- * files, so result could be failure. but it's success to compile the ts
158
- * files.)
159
- */
160
- return {
161
- type: "testValidate",
162
- created_at: new Date().toISOString(),
163
- files: testFiles,
164
- result: {
165
- ...result,
166
- type: "success",
52
+ func: IAutoBeTestFunction,
53
+ ): Promise<AutoBeTestValidateEvent> => {
54
+ const compiled: IAutoBeTypeScriptCompileResult =
55
+ await ctx.compiler.test.compile({
56
+ files: {
57
+ ...func.artifacts.dto,
58
+ ...func.artifacts.sdk,
59
+ [func.location]: func.script,
167
60
  },
168
- step: ctx.state().interface?.step ?? 0,
169
- };
170
- }
171
-
172
- // Compile Failed
173
- ctx.dispatch({
61
+ });
62
+ return {
174
63
  type: "testValidate",
64
+ file: {
65
+ scenario: func.scenario,
66
+ location: func.location,
67
+ content: func.script,
68
+ },
69
+ result: compiled,
175
70
  created_at: new Date().toISOString(),
176
- files: testFiles,
177
- result,
178
- step: ctx.state().interface?.step ?? 0,
179
- });
180
-
181
- if (life <= 0)
182
- return {
183
- type: "testValidate",
184
- created_at: new Date().toISOString(),
185
- files: testFiles,
186
- result,
187
- step: ctx.state().interface?.step ?? 0,
188
- };
189
-
190
- // VALIDATION FAILED
191
- const validatedFiles: AutoBeTestFile[] = await Promise.all(
192
- Object.entries(diagnostics).map(
193
- async ([filename, d]): Promise<AutoBeTestFile> => {
194
- const file = testFiles.find((f) => f.location === filename);
195
- const code: string = file?.content!;
196
- const scenario = file?.scenario!;
197
-
198
- const response: ICorrectTestFunctionProps = await process(
199
- ctx,
200
- d,
201
- code,
202
- scenario,
203
- );
204
- ctx.dispatch({
205
- type: "testCorrect",
206
- created_at: new Date().toISOString(),
207
- files: { ...testFiles, [filename]: response.content },
208
- result,
209
- solution: response.solution,
210
- think_without_compile_error: response.think_without_compile_error,
211
- think_again_with_compile_error:
212
- response.think_again_with_compile_error,
213
- step: ctx.state().interface?.step ?? 0,
214
- });
215
-
216
- return { location: filename, content: code, scenario: scenario };
217
- },
218
- ),
219
- );
71
+ step: ctx.state().analyze?.step ?? 0,
72
+ };
73
+ };
220
74
 
221
- return step(
222
- ctx,
223
- entireFiles,
224
- testFiles.map((f) => {
225
- const validated = validatedFiles.find((v) => v.location === f.location);
226
- return validated ? validated : f;
227
- }),
228
- life - 1,
229
- );
230
- }
75
+ const predicate = async <Model extends ILlmSchema.Model>(
76
+ ctx: AutoBeContext<Model>,
77
+ content: IAutoBeTestFunction,
78
+ event: AutoBeTestValidateEvent,
79
+ life: number,
80
+ ): Promise<AutoBeTestValidateEvent> => {
81
+ ctx.dispatch(event);
82
+ return event.result.type === "failure"
83
+ ? correct(ctx, content, event, life - 1)
84
+ : event;
85
+ };
231
86
 
232
- /**
233
- * Modifies the code of test files where errors occurred. This function
234
- * processes TypeScript compiler diagnostics and attempts to fix compilation
235
- * errors.
236
- *
237
- * @param ctx The AutoBeContext containing application state and configuration
238
- * @param diagnostics Array of TypeScript compiler diagnostics for the errors
239
- * @param code The source code content to be fixed
240
- * @returns Promise resolving to corrected test function properties
241
- */
242
- async function process<Model extends ILlmSchema.Model>(
87
+ const correct = async <Model extends ILlmSchema.Model>(
243
88
  ctx: AutoBeContext<Model>,
244
- diagnostics: IAutoBeTypeScriptCompilerResult.IDiagnostic[],
245
- code: string,
246
- scenario: AutoBeTestScenario,
247
- ): Promise<ICorrectTestFunctionProps> {
248
- const pointer: IPointer<ICorrectTestFunctionProps | null> = {
89
+ content: IAutoBeTestFunction,
90
+ validate: AutoBeTestValidateEvent,
91
+ life: number,
92
+ ): Promise<AutoBeTestValidateEvent> => {
93
+ if (validate.result.type !== "failure") return validate;
94
+ else if (--life <= 0) return validate;
95
+
96
+ const pointer: IPointer<IAutoBeTestCorrectApplication.IProps | null> = {
249
97
  value: null,
250
98
  };
251
- const artifacts: IAutoBeTestScenarioArtifacts = await compileTestScenario(
252
- ctx,
253
- scenario,
254
- );
255
-
256
99
  const agentica = new MicroAgentica({
257
100
  model: ctx.model,
258
- vendor: { ...ctx.vendor },
101
+ vendor: ctx.vendor,
259
102
  config: {
260
103
  ...(ctx.config ?? {}),
104
+ executor: {
105
+ describe: null,
106
+ },
107
+ retry: 4,
261
108
  },
262
- histories: transformTestCorrectHistories(artifacts),
109
+ histories: transformTestCorrectHistories(content, validate.result),
263
110
  controllers: [
264
111
  createApplication({
265
112
  model: ctx.model,
113
+ artifacts: content.artifacts,
266
114
  build: (next) => {
267
115
  pointer.value = next;
268
116
  },
269
117
  }),
270
118
  ],
271
- tokenUsage: ctx.usage(),
272
119
  });
273
120
  enforceToolCall(agentica);
274
121
 
275
- await randomBackoffRetry(async () => {
276
- await agentica.conversate(
277
- [
278
- "Fix the compilation error in the provided code.",
279
- "",
280
- "## Original Code",
281
- "```typescript",
282
- code,
283
- "```",
284
- "",
285
- diagnostics.map((diagnostic) => {
286
- if (diagnostic.start === undefined || diagnostic.length === undefined)
287
- return "";
288
-
289
- const checkDtoRegexp = `Cannot find module '@ORGANIZATION/template-api/lib/structures/IBbsArticleComment' or its corresponding type declarations.`;
290
- const [group] = [
291
- ...checkDtoRegexp.matchAll(
292
- /Cannot find module '(.*lib\/structures\/.*)'/g,
293
- ),
294
- ];
295
-
296
- const [_, filename] = group ?? [];
122
+ await agentica
123
+ .conversate(
124
+ "Fix the `AutoBeTest.IFunction` data to resolve the compilation error.",
125
+ )
126
+ .finally(() => {
127
+ const tokenUsage = agentica.getTokenUsage();
128
+ ctx.usage().record(tokenUsage, ["test"]);
129
+ });
130
+ if (pointer.value === null) throw new Error("Failed to modify test code.");
297
131
 
298
- return [
299
- "## Error Information",
300
- `- Position: Characters ${diagnostic.start} to ${diagnostic.start + diagnostic.length}`,
301
- `- Error Message: ${diagnostic.messageText}`,
302
- `- Problematic Code: \`${code.substring(diagnostic.start, diagnostic.start + diagnostic.length)}\``,
303
- filename
304
- ? `The type files located under **/lib/structures are declared in '@ORGANIZATION/PROJECT-api/lib/structures'.\n` +
305
- `Note: '@ORGANIZATION/PROJECT-api' must be written exactly as is and should not be replaced.\n`
306
- : "",
307
- ].join("\n");
308
- }),
309
- "## Instructions",
310
- "1. Focus on the specific error location and message",
311
- "2. Provide the corrected TypeScript code",
312
- "3. Ensure the fix resolves the compilation error",
313
- "",
314
- "Return only the fixed code without explanations.",
315
- ].join("\n"),
316
- );
132
+ ctx.dispatch({
133
+ type: "testCorrect",
134
+ created_at: new Date().toISOString(),
135
+ file: validate.file,
136
+ result: validate.result,
137
+ step: ctx.state().analyze?.step ?? 0,
138
+ ...pointer.value,
317
139
  });
318
- if (pointer.value === null) throw new Error("Failed to modify test code.");
319
- return pointer.value;
320
- }
140
+ const newContent: IAutoBeTestFunction = {
141
+ ...content,
142
+ script: pointer.value.final,
143
+ };
144
+ const newValidate: AutoBeTestValidateEvent = await compile(ctx, newContent);
145
+ return predicate(ctx, newContent, newValidate, life);
146
+ };
321
147
 
322
- function createApplication<Model extends ILlmSchema.Model>(props: {
148
+ const createApplication = <Model extends ILlmSchema.Model>(props: {
323
149
  model: Model;
324
- build: (next: ICorrectTestFunctionProps) => void;
325
- }): IAgenticaController.IClass<Model> {
150
+ artifacts: IAutoBeTestScenarioArtifacts;
151
+ build: (next: IAutoBeTestCorrectApplication.IProps) => void;
152
+ }): IAgenticaController.IClass<Model> => {
326
153
  assertSchemaModel(props.model);
327
154
 
328
155
  const application: ILlmApplication<Model> = collection[
@@ -333,15 +160,17 @@ function createApplication<Model extends ILlmSchema.Model>(props: {
333
160
  name: "Modify Test Code",
334
161
  application,
335
162
  execute: {
336
- correctTestCode: (next) => {
163
+ rewrite: (next) => {
164
+ next.draft = completeTestCode(props.artifacts, next.draft);
165
+ next.final = completeTestCode(props.artifacts, next.final);
337
166
  props.build(next);
338
167
  },
339
- } satisfies IApplication,
168
+ } satisfies IAutoBeTestCorrectApplication,
340
169
  };
341
- }
170
+ };
342
171
 
343
172
  const claude = typia.llm.application<
344
- IApplication,
173
+ IAutoBeTestCorrectApplication,
345
174
  "claude",
346
175
  {
347
176
  reference: true;
@@ -349,7 +178,7 @@ const claude = typia.llm.application<
349
178
  >();
350
179
  const collection = {
351
180
  chatgpt: typia.llm.application<
352
- IApplication,
181
+ IAutoBeTestCorrectApplication,
353
182
  "chatgpt",
354
183
  { reference: true }
355
184
  >(),
@@ -357,60 +186,4 @@ const collection = {
357
186
  llama: claude,
358
187
  deepseek: claude,
359
188
  "3.1": claude,
360
- "3.0": typia.llm.application<IApplication, "3.0">(),
361
189
  };
362
-
363
- interface IApplication {
364
- correctTestCode(props: ICorrectTestFunctionProps): void;
365
- }
366
-
367
- interface ICorrectTestFunctionProps {
368
- /**
369
- * Step 1: Initial self-reflection on the source code without compiler error
370
- * context.
371
- *
372
- * The AI agent analyzes the previously generated test code to identify
373
- * potential issues, relying solely on its understanding of TypeScript syntax,
374
- * testing patterns, and best practices.
375
- *
376
- * This encourages the agent to develop independent debugging skills before
377
- * being influenced by external error messages.
378
- */
379
- think_without_compile_error: string;
380
-
381
- /**
382
- * Step 2: Re-evaluation of the code with compiler error messages as
383
- * additional context.
384
- *
385
- * After the initial analysis, the AI agent reviews the same code again, this
386
- * time incorporating the specific TypeScript compiler error messages.
387
- *
388
- * This allows the agent to correlate its initial observations with concrete
389
- * compilation failures and refine its understanding of what went wrong.
390
- */
391
- think_again_with_compile_error: string;
392
-
393
- /**
394
- * Step 3: Concrete action plan for fixing the identified issues.
395
- *
396
- * Based on the analysis from steps 1 and 2, the AI agent formulates a
397
- * specific, step-by-step solution strategy.
398
- *
399
- * This should include what changes need to be made, why those changes are
400
- * necessary, and how they will resolve the compilation errors while
401
- * maintaining the test's intended functionality.
402
- */
403
- solution: string;
404
-
405
- /**
406
- * Step 4: The corrected TypeScript test code.
407
- *
408
- * The final, properly fixed TypeScript code that should compile without
409
- * errors.
410
- *
411
- * This represents the implementation of the solution plan from step 3,
412
- * containing all necessary corrections to make the test code syntactically
413
- * valid and functionally correct.
414
- */
415
- content: string;
416
- }