@autobe/agent 0.9.2 → 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 (175) hide show
  1. package/lib/AutoBeAgent.js +11 -4
  2. package/lib/AutoBeAgent.js.map +1 -1
  3. package/lib/constants/AutoBeSystemPromptConstant.d.ts +6 -6
  4. package/lib/context/AutoBeTokenUsage.d.ts +15 -1
  5. package/lib/context/AutoBeTokenUsage.js +56 -1
  6. package/lib/context/AutoBeTokenUsage.js.map +1 -1
  7. package/lib/factory/createAutoBeApplication.js +288 -643
  8. package/lib/factory/createAutoBeApplication.js.map +1 -1
  9. package/lib/index.mjs +5057 -7211
  10. package/lib/index.mjs.map +1 -1
  11. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js +82 -319
  12. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js.map +1 -1
  13. package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js +0 -1
  14. package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js.map +1 -1
  15. package/lib/orchestrate/analyze/orchestrateAnalyze.js +95 -266
  16. package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
  17. package/lib/orchestrate/facade/transformFacadeStateMessage.js +2 -2
  18. package/lib/orchestrate/facade/transformFacadeStateMessage.js.map +1 -1
  19. package/lib/orchestrate/index.d.ts +2 -2
  20. package/lib/orchestrate/index.js +4 -4
  21. package/lib/orchestrate/index.js.map +1 -1
  22. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +56 -142
  23. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
  24. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +195 -199
  25. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +1 -1
  26. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +75 -172
  27. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
  28. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +772 -1097
  29. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
  30. package/lib/orchestrate/interface/transformInterfaceHistories.js +2 -0
  31. package/lib/orchestrate/interface/transformInterfaceHistories.js.map +1 -1
  32. package/lib/orchestrate/prisma/orchestratePrismaComponent.js +64 -175
  33. package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -1
  34. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +552 -1073
  35. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
  36. package/lib/orchestrate/prisma/orchestratePrismaSchema.js +571 -1119
  37. package/lib/orchestrate/prisma/orchestratePrismaSchema.js.map +1 -1
  38. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js +9 -0
  39. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js.map +1 -1
  40. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js +8 -0
  41. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js.map +1 -1
  42. package/lib/orchestrate/realize/orchestrateRealize.d.ts +11 -0
  43. package/lib/orchestrate/realize/orchestrateRealize.js +109 -0
  44. package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -0
  45. package/lib/orchestrate/realize/orchestrateRealizeCoder.d.ts +25 -0
  46. package/lib/orchestrate/realize/orchestrateRealizeCoder.js +337 -0
  47. package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -0
  48. package/lib/orchestrate/realize/orchestrateRealizeIntegrator.d.ts +52 -0
  49. package/lib/orchestrate/realize/orchestrateRealizeIntegrator.js +57 -0
  50. package/lib/orchestrate/realize/orchestrateRealizeIntegrator.js.map +1 -0
  51. package/lib/orchestrate/realize/orchestrateRealizePlanner.d.ts +80 -0
  52. package/lib/orchestrate/realize/orchestrateRealizePlanner.js +53 -0
  53. package/lib/orchestrate/realize/orchestrateRealizePlanner.js.map +1 -0
  54. package/lib/orchestrate/realize/orchestrateRealizeValidator.d.ts +46 -0
  55. package/lib/orchestrate/realize/orchestrateRealizeValidator.js +37 -0
  56. package/lib/orchestrate/realize/orchestrateRealizeValidator.js.map +1 -0
  57. package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.d.ts +33 -0
  58. package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.js +3 -0
  59. package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.js.map +1 -0
  60. package/lib/orchestrate/realize/transformRealizeCoderHistories.d.ts +5 -0
  61. package/lib/orchestrate/realize/transformRealizeCoderHistories.js +127 -0
  62. package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -0
  63. package/lib/orchestrate/test/compile/completeTestCode.d.ts +2 -0
  64. package/lib/orchestrate/test/compile/completeTestCode.js +21 -0
  65. package/lib/orchestrate/test/compile/completeTestCode.js.map +1 -0
  66. package/lib/orchestrate/test/{filterTestFileName.js → compile/filterTestFileName.js} +1 -1
  67. package/lib/orchestrate/test/compile/filterTestFileName.js.map +1 -0
  68. package/lib/orchestrate/test/compile/getTestExternalDeclarations.d.ts +3 -0
  69. package/lib/orchestrate/test/compile/getTestExternalDeclarations.js +27 -0
  70. package/lib/orchestrate/test/compile/getTestExternalDeclarations.js.map +1 -0
  71. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.d.ts +5 -0
  72. package/lib/orchestrate/test/{compileTestScenario.js → compile/getTestScenarioArtifacts.js} +10 -5
  73. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js.map +1 -0
  74. package/lib/orchestrate/test/orchestrateTest.js +14 -9
  75. package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
  76. package/lib/orchestrate/test/orchestrateTestCorrect.d.ts +3 -2
  77. package/lib/orchestrate/test/orchestrateTestCorrect.js +150 -448
  78. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  79. package/lib/orchestrate/test/orchestrateTestScenario.js +272 -530
  80. package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
  81. package/lib/orchestrate/test/orchestrateTestWrite.d.ts +3 -2
  82. package/lib/orchestrate/test/orchestrateTestWrite.js +139 -90
  83. package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -1
  84. package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.d.ts +121 -0
  85. package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.js +3 -0
  86. package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.js.map +1 -0
  87. package/lib/orchestrate/test/structures/IAutoBeTestFunction.d.ts +8 -0
  88. package/lib/{utils/types/BackoffOptions.js → orchestrate/test/structures/IAutoBeTestFunction.js} +1 -1
  89. package/lib/orchestrate/test/structures/IAutoBeTestFunction.js.map +1 -0
  90. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.d.ts +14 -2
  91. package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.d.ts +112 -0
  92. package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.js +3 -0
  93. package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.js.map +1 -0
  94. package/lib/orchestrate/test/structures/IAutoBeTestWriteResult.d.ts +7 -0
  95. package/lib/orchestrate/test/structures/IAutoBeTestWriteResult.js +3 -0
  96. package/lib/orchestrate/test/structures/IAutoBeTestWriteResult.js.map +1 -0
  97. package/lib/orchestrate/test/transformTestCorrectHistories.d.ts +3 -2
  98. package/lib/orchestrate/test/transformTestCorrectHistories.js +28 -67
  99. package/lib/orchestrate/test/transformTestCorrectHistories.js.map +1 -1
  100. package/lib/orchestrate/test/transformTestWriteHistories.d.ts +5 -4
  101. package/lib/orchestrate/test/transformTestWriteHistories.js +168 -43
  102. package/lib/orchestrate/test/transformTestWriteHistories.js.map +1 -1
  103. package/lib/structures/IAutoBeConfig.d.ts +11 -0
  104. package/lib/utils/backoffRetry.d.ts +4 -7
  105. package/lib/utils/backoffRetry.js +19 -37
  106. package/lib/utils/backoffRetry.js.map +1 -1
  107. package/lib/utils/forceRetry.d.ts +1 -0
  108. package/lib/{orchestrate/orchestrateRealize.js → utils/forceRetry.js} +15 -8
  109. package/lib/utils/forceRetry.js.map +1 -0
  110. package/package.json +8 -7
  111. package/src/AutoBeAgent.ts +17 -3
  112. package/src/constants/AutoBeSystemPromptConstant.ts +6 -6
  113. package/src/context/AutoBeTokenUsage.ts +85 -1
  114. package/src/factory/createAutoBeApplication.ts +2 -3
  115. package/src/orchestrate/analyze/AutoBeAnalyzeAgent.ts +8 -3
  116. package/src/orchestrate/analyze/AutoBeAnalyzeReviewer.ts +0 -1
  117. package/src/orchestrate/analyze/orchestrateAnalyze.ts +6 -5
  118. package/src/orchestrate/facade/transformFacadeStateMessage.ts +2 -1
  119. package/src/orchestrate/index.ts +2 -2
  120. package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +4 -3
  121. package/src/orchestrate/interface/orchestrateInterfaceComponents.ts +26 -23
  122. package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +6 -4
  123. package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +14 -11
  124. package/src/orchestrate/interface/transformInterfaceHistories.ts +2 -0
  125. package/src/orchestrate/prisma/orchestratePrismaComponent.ts +10 -5
  126. package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +11 -5
  127. package/src/orchestrate/prisma/orchestratePrismaSchema.ts +16 -8
  128. package/src/orchestrate/prisma/transformPrismaComponentsHistories.ts +9 -0
  129. package/src/orchestrate/prisma/transformPrismaSchemaHistories.ts +8 -0
  130. package/src/orchestrate/realize/orchestrateRealize.ts +169 -0
  131. package/src/orchestrate/realize/orchestrateRealizeCoder.ts +156 -0
  132. package/src/orchestrate/realize/orchestrateRealizeIntegrator.ts +75 -0
  133. package/src/orchestrate/realize/orchestrateRealizePlanner.ts +115 -0
  134. package/src/orchestrate/realize/orchestrateRealizeValidator.ts +64 -0
  135. package/src/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.ts +36 -0
  136. package/src/orchestrate/realize/transformRealizeCoderHistories.ts +136 -0
  137. package/src/orchestrate/test/compile/completeTestCode.ts +35 -0
  138. package/src/orchestrate/test/{filterTestFileName.ts → compile/filterTestFileName.ts} +1 -1
  139. package/src/orchestrate/test/compile/getTestExternalDeclarations.ts +24 -0
  140. package/src/orchestrate/test/{compileTestScenario.ts → compile/getTestScenarioArtifacts.ts} +16 -8
  141. package/src/orchestrate/test/experimental/orchestrateTestCorrect.ast +240 -0
  142. package/src/orchestrate/test/experimental/orchestrateTestWrite.ast +316 -0
  143. package/src/orchestrate/test/experimental/transformTestCorrectHistories.ast +52 -0
  144. package/src/orchestrate/test/orchestrateTest.ts +33 -16
  145. package/src/orchestrate/test/orchestrateTestCorrect.ts +109 -497
  146. package/src/orchestrate/test/orchestrateTestScenario.ts +102 -71
  147. package/src/orchestrate/test/orchestrateTestWrite.ts +55 -181
  148. package/src/orchestrate/test/structures/IAutoBeTestCorrectApplication.ts +126 -0
  149. package/src/orchestrate/test/structures/IAutoBeTestFunction.ts +10 -0
  150. package/src/orchestrate/test/structures/IAutoBeTestScenarioApplication.ts +14 -2
  151. package/src/orchestrate/test/structures/IAutoBeTestWriteApplication.ts +117 -0
  152. package/src/orchestrate/test/structures/IAutoBeTestWriteResult.ts +9 -0
  153. package/src/orchestrate/test/transformTestCorrectHistories.ts +38 -71
  154. package/src/orchestrate/test/transformTestWriteHistories.ts +88 -46
  155. package/src/structures/IAutoBeConfig.ts +9 -0
  156. package/src/utils/backoffRetry.ts +25 -36
  157. package/src/utils/forceRetry.ts +13 -0
  158. package/lib/factory/invertOpenApiDocument.d.ts +0 -3
  159. package/lib/factory/invertOpenApiDocument.js +0 -51
  160. package/lib/factory/invertOpenApiDocument.js.map +0 -1
  161. package/lib/orchestrate/orchestrateRealize.d.ts +0 -5
  162. package/lib/orchestrate/orchestrateRealize.js.map +0 -1
  163. package/lib/orchestrate/test/compileTestScenario.d.ts +0 -5
  164. package/lib/orchestrate/test/compileTestScenario.js.map +0 -1
  165. package/lib/orchestrate/test/filterTestFileName.js.map +0 -1
  166. package/lib/utils/StringUtil.d.ts +0 -4
  167. package/lib/utils/StringUtil.js +0 -43
  168. package/lib/utils/StringUtil.js.map +0 -1
  169. package/lib/utils/types/BackoffOptions.d.ts +0 -12
  170. package/lib/utils/types/BackoffOptions.js.map +0 -1
  171. package/src/factory/invertOpenApiDocument.ts +0 -63
  172. package/src/orchestrate/orchestrateRealize.ts +0 -18
  173. package/src/utils/StringUtil.ts +0 -45
  174. package/src/utils/types/BackoffOptions.ts +0 -15
  175. /package/lib/orchestrate/test/{filterTestFileName.d.ts → compile/filterTestFileName.d.ts} +0 -0
@@ -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,18 +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
29
  document,
22
- sdk: filter("src/api/functional"),
30
+ sdk: filter("src/api", "src/api/structures"),
23
31
  dto: filter("src/api/structures"),
24
32
  e2e: filter("test/features"),
25
33
  };
26
34
  }
27
35
 
28
36
  function filterDocument(
29
- scenario: AutoBeTestScenario,
37
+ scenario: Pick<AutoBeTestScenario, "endpoint" | "dependencies">,
30
38
  document: AutoBeOpenApi.IDocument,
31
39
  ): AutoBeOpenApi.IDocument {
32
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
+ }