@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
@@ -0,0 +1,36 @@
1
+ export interface IAutoBeRealizeCoderApplication {
2
+ programing: (next: IAutoBeRealizeCoderApplication.IProps) => void;
3
+ }
4
+
5
+ export namespace IAutoBeRealizeCoderApplication {
6
+ export interface IProps {
7
+ result: RealizeCoderOutput;
8
+ }
9
+
10
+ /**
11
+ * The result of the code generation step, representing a fully generated
12
+ * TypeScript function.
13
+ */
14
+ export interface RealizeCoderOutput {
15
+ /**
16
+ * The name of the function to be generated.
17
+ *
18
+ * This name will be used as the function's identifier and as the export
19
+ * name in the provider file.
20
+ */
21
+ functionName: string;
22
+
23
+ /**
24
+ * The raw TypeScript code string implementing the function.
25
+ *
26
+ * - The implementation must be valid TypeScript code.
27
+ * - It should focus solely on the logic of the function.
28
+ * - Import statements do **not** need to be included. They will be
29
+ * automatically inserted by the system.
30
+ * - Any unused imports will be automatically removed by eslint.
31
+ * - Type annotations (e.g. for parameters and return types) should be omitted
32
+ * if they can be inferred.
33
+ */
34
+ implementationCode: string;
35
+ }
36
+ }
@@ -0,0 +1,136 @@
1
+ import { IAgenticaHistoryJson } from "@agentica/core";
2
+ import { v4 } from "uuid";
3
+
4
+ import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
5
+ import { AutoBeState } from "../../context/AutoBeState";
6
+ import { IAutoBeTestScenarioArtifacts } from "../test/structures/IAutoBeTestScenarioArtifacts";
7
+ import { RealizePlannerOutput } from "./orchestrateRealizePlanner";
8
+
9
+ export const transformRealizeCoderHistories = (
10
+ state: AutoBeState,
11
+ props: RealizePlannerOutput,
12
+ artifacts: IAutoBeTestScenarioArtifacts,
13
+ ): Array<
14
+ IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
15
+ > => {
16
+ if (state.analyze === null)
17
+ return [
18
+ {
19
+ id: v4(),
20
+ created_at: new Date().toISOString(),
21
+ type: "systemMessage",
22
+ text: [
23
+ "Requirement analysis is not yet completed.",
24
+ "Don't call the any tool function,",
25
+ "but say to process the requirement analysis.",
26
+ ].join(" "),
27
+ },
28
+ ];
29
+ else if (state.prisma === null)
30
+ return [
31
+ {
32
+ id: v4(),
33
+ created_at: new Date().toISOString(),
34
+ type: "systemMessage",
35
+ text: [
36
+ "Prisma DB schema generation is not yet completed.",
37
+ "Don't call the any tool function,",
38
+ "but say to process the Prisma DB schema generation.",
39
+ ].join(" "),
40
+ },
41
+ ];
42
+ else if (state.analyze.step !== state.prisma.step)
43
+ return [
44
+ {
45
+ id: v4(),
46
+ created_at: new Date().toISOString(),
47
+ type: "systemMessage",
48
+ text: [
49
+ "Prisma DB schema generation has not been updated",
50
+ "for the latest requirement analysis.",
51
+ "Don't call the any tool function,",
52
+ "but say to re-process the Prisma DB schema generation.",
53
+ ].join(" "),
54
+ },
55
+ ];
56
+ else if (state.prisma.compiled.type !== "success")
57
+ return [
58
+ {
59
+ id: v4(),
60
+ created_at: new Date().toISOString(),
61
+ type: "systemMessage",
62
+ text: [
63
+ "Prisma DB schema generation has not been updated",
64
+ "for the latest requirement analysis.",
65
+ "Don't call the any tool function,",
66
+ "but say to re-process the Prisma DB schema generation.",
67
+ ].join(" "),
68
+ },
69
+ ];
70
+ else if (state.interface === null)
71
+ return [
72
+ {
73
+ id: v4(),
74
+ created_at: new Date().toISOString(),
75
+ type: "systemMessage",
76
+ text: [
77
+ "Interface generation is not yet completed.",
78
+ "Don't call the any tool function,",
79
+ "but say to process the interface generation.",
80
+ ].join(" "),
81
+ },
82
+ ];
83
+
84
+ return [
85
+ {
86
+ id: v4(),
87
+ created_at: new Date().toISOString(),
88
+ type: "systemMessage",
89
+ text: [
90
+ AutoBeSystemPromptConstant.REALIZE_CODER,
91
+ "",
92
+ "# Prisma Schemas",
93
+ "```json",
94
+ JSON.stringify(state.prisma.schemas),
95
+ "```",
96
+ "",
97
+ // "# Prisma Types",
98
+ // "```json",
99
+ // JSON.stringify(state.prisma.compiled.nodeModules),
100
+ // "```",
101
+ "# SDK",
102
+ "",
103
+ "The following is the SDK for the API. Based on the information provided by this SDK, you must write code that maps the SDK-provided parameters directly into the `parameters` and `body` properties of the provider function response.",
104
+ "If there are no parameters, define `parameters` as `Record<string, never>`. Similarly, if there is no body, define `body` as `Record<string, never>`.",
105
+ "**Every function must be implemented to accept both `parameters` and `body`, without exception.**",
106
+ "If any required type information is referenced in the SDK, refer to the definitions in the DTO section.",
107
+ "",
108
+ "```json",
109
+ JSON.stringify(artifacts.sdk),
110
+ "```",
111
+ "",
112
+ "# DTO",
113
+ "if you want to import this files, write this: 'import { something } from '../api/structures/something';'",
114
+ "",
115
+ "```json",
116
+ JSON.stringify(artifacts.dto),
117
+ "```",
118
+ "# Document",
119
+ "```json",
120
+ JSON.stringify(artifacts.document),
121
+ "```",
122
+ ].join("\n"),
123
+ },
124
+ {
125
+ id: v4(),
126
+ created_at: new Date().toISOString(),
127
+ type: "systemMessage",
128
+ text: [
129
+ "write code by following information of operation.",
130
+ "```json",
131
+ JSON.stringify(props),
132
+ "```",
133
+ ].join("\n"),
134
+ },
135
+ ];
136
+ };
@@ -0,0 +1,35 @@
1
+ import { IAutoBeTestScenarioArtifacts } from "../structures/IAutoBeTestScenarioArtifacts";
2
+
3
+ export function completeTestCode(
4
+ artifacts: IAutoBeTestScenarioArtifacts,
5
+ code: string,
6
+ ): string {
7
+ const typeReferences: string[] = Array.from(
8
+ new Set(
9
+ Object.keys(artifacts.document.components.schemas).map(
10
+ (key) => key.split(".")[0]!,
11
+ ),
12
+ ),
13
+ );
14
+
15
+ code = code.replace(/^[ \t]*import\b[\s\S]*?;[ \t]*$/gm, "").trim();
16
+ code = code.replace(/^[ \t]*import\b[\s\S]*?;[ \t]*$/gm, "").trim();
17
+ code = code.replaceAll(
18
+ 'string & Format<"uuid">',
19
+ 'string & tags.Format<"uuid">',
20
+ );
21
+ code = [
22
+ `import { ArrayUtil, RandomGenerator, TestValidator } from "@nestia/e2e";`,
23
+ `import { IConnection } from "@nestia/fetcher";`,
24
+ `import typia, { tags } from "typia";`,
25
+ "",
26
+ `import api from "@ORGANIZATION/PROJECT-api";`,
27
+ ...typeReferences.map(
28
+ (ref) =>
29
+ `import type { ${ref} } from "@ORGANIZATION/PROJECT-api/lib/structures/${ref}";`,
30
+ ),
31
+ "",
32
+ code,
33
+ ].join("\n");
34
+ return code;
35
+ }
@@ -3,7 +3,7 @@ export function filterTestFileName(key: string): boolean {
3
3
  else if (key.startsWith("src/") === true) return true;
4
4
  return (
5
5
  key.startsWith("test/") === true &&
6
- key.startsWith("test/features/") === false &&
6
+ key.startsWith("test/features/") === true &&
7
7
  key.startsWith("test/benchmark/") === false
8
8
  );
9
9
  }
@@ -0,0 +1,24 @@
1
+ import { IAutoBeTestCompiler } from "@autobe/interface";
2
+ import { ILlmSchema } from "@samchon/openapi";
3
+ import { Singleton } from "tstl";
4
+
5
+ import { AutoBeContext } from "../../../context/AutoBeContext";
6
+
7
+ export function getTestExternalDeclarations<Model extends ILlmSchema.Model>(
8
+ ctx: AutoBeContext<Model>,
9
+ ): Promise<Record<string, string>> {
10
+ return singleton.get(ctx.compiler.test);
11
+ }
12
+
13
+ const singleton = new Singleton(async (compiler: IAutoBeTestCompiler) => {
14
+ const records: Record<string, string> = await compiler.getExternal();
15
+ const external = (location: string): Record<string, string> => {
16
+ const content: string | undefined = records[location];
17
+ if (content === undefined) throw new Error(`File not found: ${location}`);
18
+ return { [location]: content };
19
+ };
20
+ return {
21
+ ...external("node_modules/@nestia/e2e/lib/TestValidator.d.ts"),
22
+ ...external("node_modules/@nestia/fetcher/lib/IConnection.d.ts"),
23
+ } satisfies Record<string, string>;
24
+ });
@@ -1,12 +1,12 @@
1
1
  import { AutoBeOpenApi, AutoBeTestScenario } from "@autobe/interface";
2
2
  import { ILlmSchema, OpenApiTypeChecker } from "@samchon/openapi";
3
3
 
4
- import { AutoBeContext } from "../../context/AutoBeContext";
5
- import { IAutoBeTestScenarioArtifacts } from "./structures/IAutoBeTestScenarioArtifacts";
4
+ import { AutoBeContext } from "../../../context/AutoBeContext";
5
+ import { IAutoBeTestScenarioArtifacts } from "../structures/IAutoBeTestScenarioArtifacts";
6
6
 
7
- export async function compileTestScenario<Model extends ILlmSchema.Model>(
7
+ export async function getTestScenarioArtifacts<Model extends ILlmSchema.Model>(
8
8
  ctx: AutoBeContext<Model>,
9
- scenario: AutoBeTestScenario,
9
+ scenario: Pick<AutoBeTestScenario, "endpoint" | "dependencies">,
10
10
  ): Promise<IAutoBeTestScenarioArtifacts> {
11
11
  const document: AutoBeOpenApi.IDocument = filterDocument(
12
12
  scenario,
@@ -15,17 +15,26 @@ export async function compileTestScenario<Model extends ILlmSchema.Model>(
15
15
  const entries: [string, string][] = Object.entries(
16
16
  await ctx.compiler.interface.compile(document),
17
17
  );
18
- const filter = (prefix: string) =>
19
- Object.fromEntries(entries.filter(([key]) => key.startsWith(prefix)));
18
+ const filter = (prefix: string, exclude?: string) => {
19
+ const result: [string, string][] = entries.filter(
20
+ ([key]) => key.startsWith(prefix) === true,
21
+ );
22
+ return Object.fromEntries(
23
+ exclude
24
+ ? result.filter(([key]) => key.startsWith(exclude) === false)
25
+ : result,
26
+ );
27
+ };
20
28
  return {
21
- sdk: filter("src/api/functional"),
29
+ document,
30
+ sdk: filter("src/api", "src/api/structures"),
22
31
  dto: filter("src/api/structures"),
23
32
  e2e: filter("test/features"),
24
33
  };
25
34
  }
26
35
 
27
36
  function filterDocument(
28
- scenario: AutoBeTestScenario,
37
+ scenario: Pick<AutoBeTestScenario, "endpoint" | "dependencies">,
29
38
  document: AutoBeOpenApi.IDocument,
30
39
  ): AutoBeOpenApi.IDocument {
31
40
  const operations: AutoBeOpenApi.IOperation[] = document.operations.filter(
@@ -0,0 +1,240 @@
1
+ import {
2
+ AgenticaSystemPrompt,
3
+ IAgenticaController,
4
+ MicroAgentica,
5
+ } from "@agentica/core";
6
+ import {
7
+ AutoBeTest,
8
+ AutoBeTestValidateEvent,
9
+ IAutoBeTypeScriptCompileResult,
10
+ } from "@autobe/interface";
11
+ import {
12
+ ILlmApplication,
13
+ ILlmSchema,
14
+ OpenApi,
15
+ OpenApiTypeChecker,
16
+ } from "@samchon/openapi";
17
+ import { IPointer } from "tstl";
18
+ import typia, { IJsonSchemaUnit } from "typia";
19
+
20
+ import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
21
+ import { AutoBeContext } from "../../context/AutoBeContext";
22
+ import { assertSchemaModel } from "../../context/assertSchemaModel";
23
+ import { enforceToolCall } from "../../utils/enforceToolCall";
24
+ import { IAutoBeTestWriteResult } from "./structures/IAutoBeTestWriteResult";
25
+ import { transformTestCorrectHistories } from "./transformTestCorrectHistories";
26
+
27
+ export function orchestrateTestCorrect<Model extends ILlmSchema.Model>(
28
+ ctx: AutoBeContext<Model>,
29
+ results: IAutoBeTestWriteResult[],
30
+ life: number = 4,
31
+ ): Promise<AutoBeTestValidateEvent[]> {
32
+ return Promise.all(
33
+ results.map(async (written) => {
34
+ const event: AutoBeTestValidateEvent = await compile(ctx, written);
35
+ return predicate(ctx, written, event, life);
36
+ }),
37
+ );
38
+ }
39
+
40
+ async function predicate<Model extends ILlmSchema.Model>(
41
+ ctx: AutoBeContext<Model>,
42
+ written: IAutoBeTestWriteResult,
43
+ event: AutoBeTestValidateEvent,
44
+ life: number,
45
+ ): Promise<AutoBeTestValidateEvent> {
46
+ ctx.dispatch(event);
47
+ return event.result.type === "failure"
48
+ ? correct(ctx, written, event, life - 1)
49
+ : event;
50
+ }
51
+
52
+ async function correct<Model extends ILlmSchema.Model>(
53
+ ctx: AutoBeContext<Model>,
54
+ written: IAutoBeTestWriteResult,
55
+ event: AutoBeTestValidateEvent,
56
+ life: number,
57
+ ): Promise<AutoBeTestValidateEvent> {
58
+ if (event.result.type !== "failure") return event;
59
+ else if (--life <= 0) return event;
60
+
61
+ const pointer: IPointer<ICorrectTestFunctionProps | null> = {
62
+ value: null,
63
+ };
64
+ const agentica = new MicroAgentica({
65
+ model: ctx.model,
66
+ vendor: { ...ctx.vendor },
67
+ config: {
68
+ ...(ctx.config ?? {}),
69
+ executor: {
70
+ describe: null,
71
+ },
72
+ systemPrompt: {
73
+ validate: (events) =>
74
+ [
75
+ AgenticaSystemPrompt.VALIDATE_REPEATED.replace(
76
+ "${{HISTORICAL_ERRORS}}",
77
+ JSON.stringify(events.map((e) => e.result.errors)),
78
+ ),
79
+ AutoBeSystemPromptConstant.TEST_VALIDATE.replace(
80
+ "${{AutoBeTest.IStatement}}",
81
+ getUnionTypeName(typia.json.schema<AutoBeTest.IStatement>()),
82
+ ).replace(
83
+ "${{AutoBeTest.IExpression}}",
84
+ getUnionTypeName(typia.json.schema<AutoBeTest.IExpression>()),
85
+ ),
86
+ ].join("\n\n"),
87
+ },
88
+ retry: 4,
89
+ },
90
+ histories: transformTestCorrectHistories(written, event.result),
91
+ controllers: [
92
+ createApplication({
93
+ model: ctx.model,
94
+ build: (next) => {
95
+ pointer.value = next;
96
+ },
97
+ }),
98
+ ],
99
+ });
100
+ enforceToolCall(agentica);
101
+
102
+ await agentica
103
+ .conversate(
104
+ "Fix the `AutoBeTest.IFunction` data to resolve the compilation error.",
105
+ )
106
+ .finally(() => {
107
+ const tokenUsage = agentica.getTokenUsage();
108
+ ctx.usage().record(tokenUsage, ["test"]);
109
+ });
110
+ if (pointer.value === null) throw new Error("Failed to modify test code.");
111
+ event = await compile(ctx, {
112
+ ...written,
113
+ file: {
114
+ ...written.file,
115
+ function: pointer.value.function,
116
+ },
117
+ });
118
+ return predicate(ctx, written, event, life);
119
+ }
120
+
121
+ async function compile<Model extends ILlmSchema.Model>(
122
+ ctx: AutoBeContext<Model>,
123
+ written: IAutoBeTestWriteResult,
124
+ ): Promise<AutoBeTestValidateEvent> {
125
+ const compiled: IAutoBeTypeScriptCompileResult =
126
+ await ctx.compiler.test.compile({
127
+ files: {
128
+ ...written.artifacts.dto,
129
+ ...written.artifacts.sdk,
130
+ [written.file.location]: written.file.content,
131
+ },
132
+ });
133
+ return {
134
+ type: "testValidate",
135
+ file: written.file,
136
+ result: compiled,
137
+ created_at: new Date().toISOString(),
138
+ step: ctx.state().analyze?.step ?? 0,
139
+ };
140
+ }
141
+
142
+ function getUnionTypeName(unit: IJsonSchemaUnit): string {
143
+ if (OpenApiTypeChecker.isReference(unit.schema) === false) return "unknown";
144
+
145
+ const typeName: string = unit.schema.$ref.split("/").pop() ?? "";
146
+ const schema: OpenApi.IJsonSchema | undefined =
147
+ unit.components.schemas?.[typeName];
148
+ if (schema === undefined || OpenApiTypeChecker.isOneOf(schema) === false)
149
+ return "unknown";
150
+ return schema.oneOf
151
+ .filter(OpenApiTypeChecker.isReference)
152
+ .map((r) => r.$ref.split("/").pop() ?? "")
153
+ .join(" | ");
154
+ }
155
+
156
+ function createApplication<Model extends ILlmSchema.Model>(props: {
157
+ model: Model;
158
+ build: (next: ICorrectTestFunctionProps) => void;
159
+ }): IAgenticaController.IClass<Model> {
160
+ assertSchemaModel(props.model);
161
+
162
+ const application: ILlmApplication<Model> = collection[
163
+ props.model
164
+ ] as unknown as ILlmApplication<Model>;
165
+ return {
166
+ protocol: "class",
167
+ name: "Modify Test Code",
168
+ application,
169
+ execute: {
170
+ correctTestCode: (next) => {
171
+ props.build(next);
172
+ },
173
+ } satisfies IApplication,
174
+ };
175
+ }
176
+
177
+ const claude = typia.llm.application<
178
+ IApplication,
179
+ "claude",
180
+ {
181
+ reference: true;
182
+ }
183
+ >();
184
+ const collection = {
185
+ chatgpt: typia.llm.application<
186
+ IApplication,
187
+ "chatgpt",
188
+ { reference: true }
189
+ >(),
190
+ claude,
191
+ llama: claude,
192
+ deepseek: claude,
193
+ "3.1": claude,
194
+ };
195
+
196
+ interface IApplication {
197
+ correctTestCode(props: ICorrectTestFunctionProps): void;
198
+ }
199
+
200
+ interface ICorrectTestFunctionProps {
201
+ /**
202
+ * Step 1: Initial self-reflection on the source code without compiler error
203
+ * context.
204
+ *
205
+ * The AI agent analyzes the previously generated test code to identify
206
+ * potential issues, relying solely on its understanding of TypeScript syntax,
207
+ * testing patterns, and best practices.
208
+ *
209
+ * This encourages the agent to develop independent debugging skills before
210
+ * being influenced by external error messages.
211
+ */
212
+ think_without_compile_error: string;
213
+
214
+ /**
215
+ * Step 2: Re-evaluation of the code with compiler error messages as
216
+ * additional context.
217
+ *
218
+ * After the initial analysis, the AI agent reviews the same code again, this
219
+ * time incorporating the specific TypeScript compiler error messages.
220
+ *
221
+ * This allows the agent to correlate its initial observations with concrete
222
+ * compilation failures and refine its understanding of what went wrong.
223
+ */
224
+ think_again_with_compile_error: string;
225
+
226
+ /**
227
+ * Step 3: Concrete action plan for fixing the identified issues.
228
+ *
229
+ * Based on the analysis from steps 1 and 2, the AI agent formulates a
230
+ * specific, step-by-step solution strategy.
231
+ *
232
+ * This should include what changes need to be made, why those changes are
233
+ * necessary, and how they will resolve the compilation errors while
234
+ * maintaining the test's intended functionality.
235
+ */
236
+ solution: string;
237
+
238
+ /** Re-written AST data to fix the compilation error. */
239
+ function: AutoBeTest.IFunction;
240
+ }