@autobe/agent 0.25.0 → 0.25.2

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 (199) hide show
  1. package/lib/AutoBeAgent.js +11 -1
  2. package/lib/AutoBeAgent.js.map +1 -1
  3. package/lib/AutoBeMockAgent.js +1 -0
  4. package/lib/AutoBeMockAgent.js.map +1 -1
  5. package/lib/constants/AutoBeConfigConstant.d.ts +1 -1
  6. package/lib/constants/AutoBeSystemPromptConstant.d.ts +13 -13
  7. package/lib/factory/createAutoBeContext.js +32 -3
  8. package/lib/factory/createAutoBeContext.js.map +1 -1
  9. package/lib/index.mjs +2585 -1009
  10. package/lib/index.mjs.map +1 -1
  11. package/lib/orchestrate/analyze/orchestrateAnalyzeScenario.js +8 -8
  12. package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeScenarioApplication.d.ts +2 -2
  13. package/lib/orchestrate/common/histories/transformCommonCorrectCastingHistories.js +1 -1
  14. package/lib/orchestrate/common/histories/transformCommonCorrectCastingHistories.js.map +1 -1
  15. package/lib/orchestrate/common/orchestrateCommonCorrectCasting.js +36 -23
  16. package/lib/orchestrate/common/orchestrateCommonCorrectCasting.js.map +1 -1
  17. package/lib/orchestrate/common/structures/IAutoBeCommonCorrectCastingApplication.d.ts +22 -42
  18. package/lib/orchestrate/interface/histories/transformInterfaceCommonPrerequisiteHistories.d.ts +3 -0
  19. package/lib/orchestrate/interface/histories/{transformInterfacePrerequisiteHistories.js → transformInterfaceCommonPrerequisiteHistories.js} +4 -4
  20. package/lib/orchestrate/interface/histories/transformInterfaceCommonPrerequisiteHistories.js.map +1 -0
  21. package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js +2 -2
  22. package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js.map +1 -1
  23. package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js +3 -3
  24. package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js.map +1 -1
  25. package/lib/orchestrate/interface/histories/transformInterfacePrerequisitesHistories.d.ts +3 -0
  26. package/lib/orchestrate/interface/histories/transformInterfacePrerequisitesHistories.js +102 -0
  27. package/lib/orchestrate/interface/histories/transformInterfacePrerequisitesHistories.js.map +1 -0
  28. package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js +1 -1
  29. package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js.map +1 -1
  30. package/lib/orchestrate/interface/histories/transformInterfaceSchemasReviewHistories.js +2 -2
  31. package/lib/orchestrate/interface/histories/transformInterfaceSchemasReviewHistories.js.map +1 -1
  32. package/lib/orchestrate/interface/orchestrateInterface.js +25 -9
  33. package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
  34. package/lib/orchestrate/interface/orchestrateInterfaceAuthorizations.js +278 -47
  35. package/lib/orchestrate/interface/orchestrateInterfaceAuthorizations.js.map +1 -1
  36. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +96 -70
  37. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
  38. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +3 -3
  39. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
  40. package/lib/orchestrate/interface/orchestrateInterfaceGroups.js +2 -2
  41. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +29 -30
  42. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
  43. package/lib/orchestrate/interface/orchestrateInterfaceOperationsReview.js +278 -47
  44. package/lib/orchestrate/interface/orchestrateInterfaceOperationsReview.js.map +1 -1
  45. package/lib/orchestrate/interface/orchestrateInterfacePrerequisites.d.ts +5 -0
  46. package/lib/orchestrate/interface/orchestrateInterfacePrerequisites.js +713 -0
  47. package/lib/orchestrate/interface/orchestrateInterfacePrerequisites.js.map +1 -0
  48. package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js +88 -42
  49. package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js.map +1 -1
  50. package/lib/orchestrate/interface/orchestrateInterfaceSchemasReview.js +82 -14
  51. package/lib/orchestrate/interface/orchestrateInterfaceSchemasReview.js.map +1 -1
  52. package/lib/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.d.ts +0 -38
  53. package/lib/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.d.ts +6 -10
  54. package/lib/orchestrate/interface/structures/IAutoBeInterfaceOperationApplication.d.ts +3 -3
  55. package/lib/orchestrate/interface/structures/IAutoBeInterfacePrerequisitesApplication.d.ts +52 -0
  56. package/lib/orchestrate/interface/structures/IAutoBeInterfacePrerequisitesApplication.js +3 -0
  57. package/lib/orchestrate/interface/structures/IAutoBeInterfacePrerequisitesApplication.js.map +1 -0
  58. package/lib/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.d.ts +0 -33
  59. package/lib/orchestrate/interface/utils/JsonSchemaFactory.d.ts +6 -2
  60. package/lib/orchestrate/interface/utils/JsonSchemaFactory.js +114 -9
  61. package/lib/orchestrate/interface/utils/JsonSchemaFactory.js.map +1 -1
  62. package/lib/orchestrate/interface/utils/JsonSchemaValidator.js +46 -3
  63. package/lib/orchestrate/interface/utils/JsonSchemaValidator.js.map +1 -1
  64. package/lib/orchestrate/interface/utils/OperationValidator.d.ts +3 -4
  65. package/lib/orchestrate/interface/utils/OperationValidator.js +1 -1
  66. package/lib/orchestrate/interface/utils/OperationValidator.js.map +1 -1
  67. package/lib/orchestrate/prisma/orchestratePrismaComponent.js +8 -8
  68. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +20 -20
  69. package/lib/orchestrate/prisma/orchestratePrismaReview.js +20 -20
  70. package/lib/orchestrate/prisma/orchestratePrismaSchemas.js +30 -30
  71. package/lib/orchestrate/realize/histories/transformRealizeCorrectCastingHistories.js +9 -10
  72. package/lib/orchestrate/realize/histories/transformRealizeCorrectCastingHistories.js.map +1 -1
  73. package/lib/orchestrate/realize/histories/transformRealizeCorrectHistories.js +14 -22
  74. package/lib/orchestrate/realize/histories/transformRealizeCorrectHistories.js.map +1 -1
  75. package/lib/orchestrate/realize/histories/transformRealizeWriteAuthorizationsHistories.js +6 -6
  76. package/lib/orchestrate/realize/histories/transformRealizeWriteHistories.js +8 -2
  77. package/lib/orchestrate/realize/histories/transformRealizeWriteHistories.js.map +1 -1
  78. package/lib/orchestrate/realize/internal/compileRealizeFiles.js +1 -2
  79. package/lib/orchestrate/realize/internal/compileRealizeFiles.js.map +1 -1
  80. package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.d.ts +2 -1
  81. package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.js +103 -40
  82. package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.js.map +1 -1
  83. package/lib/orchestrate/realize/orchestrateRealize.js +79 -45
  84. package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
  85. package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js +16 -16
  86. package/lib/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.js +12 -12
  87. package/lib/orchestrate/realize/orchestrateRealizeCorrect.js +117 -87
  88. package/lib/orchestrate/realize/orchestrateRealizeCorrect.js.map +1 -1
  89. package/lib/orchestrate/realize/orchestrateRealizeWrite.d.ts +2 -1
  90. package/lib/orchestrate/realize/orchestrateRealizeWrite.js +117 -54
  91. package/lib/orchestrate/realize/orchestrateRealizeWrite.js.map +1 -1
  92. package/lib/orchestrate/realize/structures/IAutoBeRealizeAuthorizationApplication.d.ts +21 -13
  93. package/lib/orchestrate/realize/structures/IAutoBeRealizeCorrectApplication.d.ts +52 -26
  94. package/lib/orchestrate/realize/structures/IAutoBeRealizeWriteApplication.d.ts +44 -34
  95. package/lib/orchestrate/realize/utils/InternalFileSystem.js +1 -1
  96. package/lib/orchestrate/realize/utils/InternalFileSystem.js.map +1 -1
  97. package/lib/orchestrate/realize/utils/getRealizeWriteCodeTemplate.d.ts +8 -3
  98. package/lib/orchestrate/realize/utils/getRealizeWriteCodeTemplate.js +44 -17
  99. package/lib/orchestrate/realize/utils/getRealizeWriteCodeTemplate.js.map +1 -1
  100. package/lib/orchestrate/realize/utils/getRealizeWriteImportStatements.d.ts +4 -1
  101. package/lib/orchestrate/realize/utils/getRealizeWriteImportStatements.js +24 -9
  102. package/lib/orchestrate/realize/utils/getRealizeWriteImportStatements.js.map +1 -1
  103. package/lib/orchestrate/realize/utils/printErrorHints.d.ts +8 -0
  104. package/lib/orchestrate/realize/utils/printErrorHints.js +48 -0
  105. package/lib/orchestrate/realize/utils/printErrorHints.js.map +1 -0
  106. package/lib/orchestrate/realize/utils/replaceImportStatements.d.ts +1 -0
  107. package/lib/orchestrate/realize/utils/replaceImportStatements.js +93 -55
  108. package/lib/orchestrate/realize/utils/replaceImportStatements.js.map +1 -1
  109. package/lib/orchestrate/test/histories/transformTestCorrectHistories.js +1 -1
  110. package/lib/orchestrate/test/histories/transformTestCorrectHistories.js.map +1 -1
  111. package/lib/orchestrate/test/histories/transformTestCorrectInvalidRequestHistories.js +1 -1
  112. package/lib/orchestrate/test/histories/transformTestCorrectInvalidRequestHistories.js.map +1 -1
  113. package/lib/orchestrate/test/histories/transformTestScenarioHistories.js +10 -79
  114. package/lib/orchestrate/test/histories/transformTestScenarioHistories.js.map +1 -1
  115. package/lib/orchestrate/test/histories/transformTestScenarioReviewHistories.js +15 -65
  116. package/lib/orchestrate/test/histories/transformTestScenarioReviewHistories.js.map +1 -1
  117. package/lib/orchestrate/test/histories/transformTestWriteHistories.js +1 -1
  118. package/lib/orchestrate/test/histories/transformTestWriteHistories.js.map +1 -1
  119. package/lib/orchestrate/test/orchestrateTestCorrect.js +32 -17
  120. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  121. package/lib/orchestrate/test/orchestrateTestCorrectInvalidRequest.js +31 -13
  122. package/lib/orchestrate/test/orchestrateTestCorrectInvalidRequest.js.map +1 -1
  123. package/lib/orchestrate/test/orchestrateTestScenario.d.ts +1 -1
  124. package/lib/orchestrate/test/orchestrateTestScenario.js +5 -5
  125. package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
  126. package/lib/orchestrate/test/orchestrateTestScenarioReview.js +1 -1
  127. package/lib/orchestrate/test/orchestrateTestScenarioReview.js.map +1 -1
  128. package/lib/orchestrate/test/orchestrateTestWrite.js +37 -21
  129. package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -1
  130. package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.d.ts +9 -5
  131. package/lib/orchestrate/test/structures/IAutoBeTestCorrectInvalidRequestApplication.d.ts +8 -2
  132. package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.d.ts +11 -7
  133. package/lib/orchestrate/test/utils/getPrerequisites.d.ts +5 -0
  134. package/lib/orchestrate/test/utils/getPrerequisites.js +36 -0
  135. package/lib/orchestrate/test/utils/getPrerequisites.js.map +1 -0
  136. package/lib/orchestrate/test/utils/getReferenceIds.js +1 -1
  137. package/lib/orchestrate/test/utils/getReferenceIds.js.map +1 -1
  138. package/package.json +5 -5
  139. package/src/AutoBeAgent.ts +17 -1
  140. package/src/AutoBeMockAgent.ts +1 -0
  141. package/src/constants/AutoBeConfigConstant.ts +1 -1
  142. package/src/constants/AutoBeSystemPromptConstant.ts +13 -13
  143. package/src/factory/createAutoBeContext.ts +33 -3
  144. package/src/orchestrate/analyze/structures/IAutoBeAnalyzeScenarioApplication.ts +2 -2
  145. package/src/orchestrate/common/orchestrateCommonCorrectCasting.ts +2 -2
  146. package/src/orchestrate/common/structures/IAutoBeCommonCorrectCastingApplication.ts +25 -45
  147. package/src/orchestrate/interface/histories/{transformInterfacePrerequisiteHistories.ts → transformInterfaceCommonPrerequisiteHistories.ts} +1 -1
  148. package/src/orchestrate/interface/histories/transformInterfaceGroupHistories.ts +4 -2
  149. package/src/orchestrate/interface/histories/transformInterfacePrerequisitesHistories.ts +118 -0
  150. package/src/orchestrate/interface/orchestrateInterface.ts +43 -17
  151. package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +12 -33
  152. package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +5 -5
  153. package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +7 -6
  154. package/src/orchestrate/interface/orchestrateInterfacePrerequisites.ts +274 -0
  155. package/src/orchestrate/interface/orchestrateInterfaceSchemas.ts +1 -1
  156. package/src/orchestrate/interface/orchestrateInterfaceSchemasReview.ts +1 -1
  157. package/src/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.ts +0 -39
  158. package/src/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.ts +6 -10
  159. package/src/orchestrate/interface/structures/IAutoBeInterfaceOperationApplication.ts +4 -5
  160. package/src/orchestrate/interface/structures/IAutoBeInterfacePrerequisitesApplication.ts +58 -0
  161. package/src/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.ts +0 -34
  162. package/src/orchestrate/interface/utils/JsonSchemaFactory.ts +92 -4
  163. package/src/orchestrate/interface/utils/JsonSchemaValidator.ts +49 -3
  164. package/src/orchestrate/interface/utils/OperationValidator.ts +9 -7
  165. package/src/orchestrate/realize/histories/transformRealizeCorrectCastingHistories.ts +9 -10
  166. package/src/orchestrate/realize/histories/transformRealizeCorrectHistories.ts +13 -24
  167. package/src/orchestrate/realize/histories/transformRealizeWriteAuthorizationsHistories.ts +6 -6
  168. package/src/orchestrate/realize/histories/transformRealizeWriteHistories.ts +6 -4
  169. package/src/orchestrate/realize/internal/compileRealizeFiles.ts +1 -5
  170. package/src/orchestrate/realize/orchestRateRealizeCorrectCasting.ts +84 -17
  171. package/src/orchestrate/realize/orchestrateRealize.ts +123 -74
  172. package/src/orchestrate/realize/orchestrateRealizeCorrect.ts +33 -6
  173. package/src/orchestrate/realize/orchestrateRealizeWrite.ts +14 -4
  174. package/src/orchestrate/realize/structures/IAutoBeRealizeAuthorizationApplication.ts +21 -13
  175. package/src/orchestrate/realize/structures/IAutoBeRealizeCorrectApplication.ts +54 -29
  176. package/src/orchestrate/realize/structures/IAutoBeRealizeWriteApplication.ts +46 -35
  177. package/src/orchestrate/realize/utils/InternalFileSystem.ts +1 -1
  178. package/src/orchestrate/realize/utils/getRealizeWriteCodeTemplate.ts +54 -22
  179. package/src/orchestrate/realize/utils/getRealizeWriteImportStatements.ts +28 -16
  180. package/src/orchestrate/realize/utils/printErrorHints.ts +55 -0
  181. package/src/orchestrate/realize/utils/replaceImportStatements.ts +99 -102
  182. package/src/orchestrate/test/histories/transformTestScenarioHistories.ts +18 -91
  183. package/src/orchestrate/test/histories/transformTestScenarioReviewHistories.ts +17 -90
  184. package/src/orchestrate/test/orchestrateTestCorrect.ts +7 -6
  185. package/src/orchestrate/test/orchestrateTestCorrectInvalidRequest.ts +13 -1
  186. package/src/orchestrate/test/orchestrateTestScenario.ts +12 -6
  187. package/src/orchestrate/test/orchestrateTestScenarioReview.ts +3 -3
  188. package/src/orchestrate/test/orchestrateTestWrite.ts +7 -6
  189. package/src/orchestrate/test/structures/IAutoBeTestCorrectApplication.ts +9 -228
  190. package/src/orchestrate/test/structures/IAutoBeTestCorrectInvalidRequestApplication.ts +8 -2
  191. package/src/orchestrate/test/structures/IAutoBeTestWriteApplication.ts +11 -78
  192. package/src/orchestrate/test/utils/getPrerequisites.ts +51 -0
  193. package/src/orchestrate/test/utils/getReferenceIds.ts +2 -1
  194. package/lib/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.d.ts +0 -3
  195. package/lib/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.js.map +0 -1
  196. package/lib/orchestrate/interface/utils/OpenApiEndpointComparator.d.ts +0 -6
  197. package/lib/orchestrate/interface/utils/OpenApiEndpointComparator.js +0 -22
  198. package/lib/orchestrate/interface/utils/OpenApiEndpointComparator.js.map +0 -1
  199. package/src/orchestrate/interface/utils/OpenApiEndpointComparator.ts +0 -23
@@ -20,9 +20,9 @@ import { getRealizeWriteImportStatements } from "./getRealizeWriteImportStatemen
20
20
  * import { MyGlobal } from "../MyGlobal";
21
21
  * // ... other imports
22
22
  *
23
- * async function post__users_create(
23
+ * async function post__users_create(props: {
24
24
  * body: IUserCreateRequest
25
- * ): Promise<IUserResponse> {
25
+ * }): Promise<IUserResponse> {
26
26
  * ...
27
27
  * }
28
28
  * ```;
@@ -32,35 +32,31 @@ import { getRealizeWriteImportStatements } from "./getRealizeWriteImportStatemen
32
32
  * @param authorization - Authorization context if endpoint is authenticated
33
33
  * @returns Complete TypeScript code template as a formatted string
34
34
  */
35
- export function getRealizeWriteCodeTemplate(
36
- scenario: IAutoBeRealizeScenarioResult,
37
- operation: AutoBeOpenApi.IOperation,
38
- authorization: AutoBeRealizeAuthorization | null,
39
- ): string {
35
+ export function getRealizeWriteCodeTemplate(props: {
36
+ scenario: IAutoBeRealizeScenarioResult;
37
+ operation: AutoBeOpenApi.IOperation;
38
+ schemas: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>;
39
+ authorization: AutoBeRealizeAuthorization | null;
40
+ }): string {
40
41
  // Collect all function parameters in order
41
42
  const functionParameters: string[] = [];
42
43
 
43
44
  // Add authentication parameter if needed (e.g., user: IUser, admin: IAdmin)
44
- if (authorization && authorization.role.name) {
45
+ if (props.authorization && props.authorization.role.name) {
45
46
  // Debug: Log the values to check what's being used
46
- const authParameter = `${authorization.role.name}: ${authorization.payload.name}`;
47
+ const authParameter = `${props.authorization.role.name}: ${props.authorization.payload.name}`;
47
48
  functionParameters.push(authParameter);
48
49
  }
49
50
 
50
51
  // Add path parameters (e.g., id, postId, etc.)
51
- const pathParameters = operation.parameters.map((param) => {
52
- const paramType = param.schema.type;
53
- const paramFormat =
54
- "format" in param.schema
55
- ? ` & tags.Format<'${param.schema.format}'>`
56
- : "";
57
- return `${param.name}: ${paramType}${paramFormat}`;
52
+ const pathParameters = props.operation.parameters.map((param) => {
53
+ return `${param.name}: ${writeParameterType(param.schema)}`;
58
54
  });
59
55
  functionParameters.push(...pathParameters);
60
56
 
61
57
  // Add request body parameter if present
62
- if (operation.requestBody?.typeName) {
63
- const bodyParameter = `body: ${operation.requestBody.typeName}`;
58
+ if (props.operation.requestBody?.typeName) {
59
+ const bodyParameter = `body: ${props.operation.requestBody.typeName}`;
64
60
  functionParameters.push(bodyParameter);
65
61
  }
66
62
 
@@ -79,19 +75,55 @@ export function getRealizeWriteCodeTemplate(
79
75
  }
80
76
 
81
77
  // Determine return type
82
- const returnType = operation.responseBody?.typeName ?? "void";
78
+ const returnType = props.operation.responseBody?.typeName ?? "void";
83
79
 
84
80
  // Generate the complete template
85
81
  return StringUtil.trim`
86
82
  Complete the code below, disregard the import part and return only the function part.
87
83
 
88
84
  \`\`\`typescript
89
- ${getRealizeWriteImportStatements(operation).join("\n")}
85
+ ${getRealizeWriteImportStatements(props).join("\n")}
90
86
 
91
- // ONLY YOU HAVE TO WRITE THIS, AND USE IMPORTED.
92
- export async function ${scenario.functionName}(${formattedSignature}): Promise<${returnType}> {
87
+ // DON'T CHANGE FUNCTION NAME AND PARAMETERS,
88
+ // ONLY YOU HAVE TO WRITE THIS FUNCTION BODY, AND USE IMPORTED.
89
+ export async function ${props.scenario.functionName}(${formattedSignature}): Promise<${returnType}> {
93
90
  ...
94
91
  }
95
92
  \`\`\`
96
93
  `;
97
94
  }
95
+
96
+ const writeParameterType = (
97
+ schema: AutoBeOpenApi.IParameter["schema"],
98
+ ): string => {
99
+ const elements: string[] =
100
+ schema.type === "integer"
101
+ ? ["number", `tags.Type<"int32">`]
102
+ : [schema.type];
103
+ if (schema.type === "number") {
104
+ if (schema.minimum !== undefined)
105
+ elements.push(`tags.Minimum<${schema.minimum}>`);
106
+ if (schema.maximum !== undefined)
107
+ elements.push(`tags.Maximum<${schema.maximum}>`);
108
+ if (schema.exclusiveMinimum !== undefined)
109
+ elements.push(`tags.ExclusiveMinimum<${schema.exclusiveMinimum}>`);
110
+ if (schema.exclusiveMaximum !== undefined)
111
+ elements.push(`tags.ExclusiveMaximum<${schema.exclusiveMaximum}>`);
112
+ if (schema.multipleOf !== undefined)
113
+ elements.push(`tags.MultipleOf<${schema.multipleOf}>`);
114
+ } else if (schema.type === "string") {
115
+ if (schema.format !== undefined)
116
+ elements.push(`tags.Format<${JSON.stringify(schema.format)}>`);
117
+ if (schema.contentMediaType !== undefined)
118
+ elements.push(
119
+ `tags.ContentMediaType<${JSON.stringify(schema.contentMediaType)}>`,
120
+ );
121
+ if (schema.pattern !== undefined)
122
+ elements.push(`tags.Pattern<${JSON.stringify(schema.pattern)}>`);
123
+ if (schema.minLength !== undefined)
124
+ elements.push(`tags.MinLength<${schema.minLength}>`);
125
+ if (schema.maxLength !== undefined)
126
+ elements.push(`tags.MaxLength<${schema.maxLength}>`);
127
+ }
128
+ return elements.join(" & ");
129
+ };
@@ -1,30 +1,42 @@
1
1
  import { AutoBeOpenApi } from "@autobe/interface";
2
+ import { OpenApiTypeChecker } from "@samchon/openapi";
2
3
 
3
- export function getRealizeWriteImportStatements(
4
- operation: AutoBeOpenApi.IOperation,
5
- ) {
6
- const typeReferences: string[] = Array.from(
7
- new Set(
8
- [operation.requestBody, operation.responseBody]
9
- .filter((el) => el !== null)
10
- .map((el) => el.typeName.split(".")[0]!),
11
- ),
12
- );
4
+ export function getRealizeWriteImportStatements(props: {
5
+ operation: AutoBeOpenApi.IOperation;
6
+ schemas: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>;
7
+ }): string[] {
8
+ const typeReferences: Set<string> = new Set();
9
+ const visit = (key: string) =>
10
+ OpenApiTypeChecker.visit({
11
+ schema: {
12
+ $ref: `#/components/schemas/${key}`,
13
+ },
14
+ components: { schemas: props.schemas },
15
+ closure: (next) => {
16
+ if (OpenApiTypeChecker.isReference(next))
17
+ typeReferences.add(next.$ref.split("/").pop()!.split(".")[0]!);
18
+ },
19
+ });
20
+ if (props.operation.requestBody) visit(props.operation.requestBody.typeName);
21
+ if (props.operation.responseBody)
22
+ visit(props.operation.responseBody.typeName);
13
23
 
14
24
  // Build the standard imports
15
25
  const imports = [
26
+ 'import { HttpException } from "@nestjs/common";',
27
+ 'import { Prisma } from "@prisma/client";',
16
28
  'import jwt from "jsonwebtoken";',
17
- 'import { MyGlobal } from "../MyGlobal";',
18
29
  'import typia, { tags } from "typia";',
19
- 'import { Prisma } from "@prisma/client";',
20
30
  'import { v4 } from "uuid";',
21
- 'import { toISOStringSafe } from "../util/toISOStringSafe"',
22
- 'import { HttpException } from "@nestjs/common";',
23
- ...typeReferences.map(
31
+
32
+ 'import { MyGlobal } from "../MyGlobal";',
33
+ 'import { PasswordUtil } from "../utils/PasswordUtil";',
34
+ 'import { toISOStringSafe } from "../utils/toISOStringSafe"',
35
+ "",
36
+ ...Array.from(typeReferences).map(
24
37
  (ref) =>
25
38
  `import { ${ref} } from "@ORGANIZATION/PROJECT-api/lib/structures/${ref}";`,
26
39
  ),
27
40
  ];
28
-
29
41
  return imports;
30
42
  }
@@ -0,0 +1,55 @@
1
+ import { IAutoBeTypeScriptCompileResult } from "@autobe/interface";
2
+ import { StringUtil } from "@autobe/utils";
3
+
4
+ /**
5
+ * Prints error hints for a given code and its diagnostics.
6
+ *
7
+ * @param code The code to analyze.
8
+ * @param diagnostics The diagnostics to use for error hinting.
9
+ */
10
+ export function printErrorHints(
11
+ code: string,
12
+ diagnostics: IAutoBeTypeScriptCompileResult.IDiagnostic[],
13
+ ): string {
14
+ const lines: string[] = code.split("\n");
15
+
16
+ let cursor: number = 0;
17
+ const hints: string[] = [];
18
+ lines.forEach((line, index, arr) => {
19
+ const lineStart = cursor;
20
+ cursor += line.length + 1; // +1 for the newline character
21
+
22
+ diagnostics.forEach((diag) => {
23
+ if (diag.start === null || diag.start === undefined) {
24
+ return;
25
+ }
26
+
27
+ // Check if the diagnostic start position falls within the current line
28
+ if (diag.start >= lineStart && diag.start < cursor) {
29
+ // Handle multi-line error messages by escaping newlines
30
+ const errorMessage = String(diag.messageText).replace(/\n/g, "\\n");
31
+ const targetLine = line + " // error: " + errorMessage;
32
+
33
+ // targetLine만 덮어써서 새로운 배열을 만들어야 한다.
34
+ const hint: string = arr
35
+ .slice(0, index)
36
+ .concat(targetLine)
37
+ .concat(arr.slice(index + 1))
38
+ .join("\n");
39
+
40
+ hints.push(hint);
41
+ }
42
+ });
43
+ });
44
+
45
+ return hints
46
+ .map((h, i) => {
47
+ return StringUtil.trim`
48
+ hint #${i + 1}:
49
+ \`\`\`typescript
50
+ ${h}
51
+ \`\`\`
52
+ `;
53
+ })
54
+ .join("\n");
55
+ }
@@ -4,124 +4,121 @@ import { ILlmSchema } from "@samchon/openapi";
4
4
  import { AutoBeContext } from "../../../context/AutoBeContext";
5
5
  import { getRealizeWriteImportStatements } from "./getRealizeWriteImportStatements";
6
6
 
7
- /**
8
- * Removes all import statements that LLM might have incorrectly added. This
9
- * includes standard library imports, auto-injected imports, and any API
10
- * structure imports with wrong paths.
11
- *
12
- * @param code - The code containing imports to remove
13
- * @param typeReferences - List of type names to specifically remove
14
- * @param decoratorType - Optional decorator type to remove
15
- * @returns Code with all imports removed
16
- */
17
- function removeAllImports(
18
- code: string,
19
- typeReferences: string[],
20
- decoratorType?: string,
21
- ): string {
22
- // Remove standard library and auto-injected imports
23
- let cleanedCode = code
24
- // MyGlobal - often with wrong path
25
- .replace(
26
- /import\s*{\s*MyGlobal\s*}\s*from\s*["']\.\.\/MyGlobal["']\s*;?\s*/gm,
27
- "",
28
- )
29
- // typia - various import patterns
30
- .replace(
31
- /import\s+typia\s*,\s*{\s*tags\s*}\s*from\s*["']typia["']\s*;?\s*/gm,
32
- "",
33
- )
34
- .replace(/import\s*{\s*tags\s*}\s*from\s*["']typia["']\s*;?\s*/gm, "")
35
- .replace(
36
- /import\s*{\s*tags\s*,\s*typia\s*}\s*from\s*["']typia["']\s*;?\s*/gm,
37
- "",
38
- )
39
- .replace(/import\s+typia\s*from\s*["']typia["']\s*;?\s*/gm, "")
40
- // Prisma client
41
- .replace(
42
- /import\s*{\s*Prisma\s*}\s*from\s*["']@prisma\/client["']\s*;?\s*/gm,
43
- "",
44
- )
45
- // uuid
46
- .replace(/import\s*{\s*v4\s*}\s*from\s*["']uuid["']\s*;?\s*/gm, "")
47
- // toISOStringSafe utility
48
- .replace(
49
- /import\s*{\s*toISOStringSafe\s*}\s*from\s*["']\.\.\/util\/toISOStringSafe["']\s*;?\s*/gm,
50
- "",
51
- )
52
- // JWT imports (if LLM adds them)
53
- .replace(/import\s+jwt\s+from\s*["']jsonwebtoken["']\s*;?\s*/gm, "")
54
- .replace(
55
- /import\s*\*\s*as\s+jwt\s+from\s*["']jsonwebtoken["']\s*;?\s*/gm,
56
- "",
57
- )
58
- // NestJS HttpException
59
- .replace(
60
- /import\s*{\s*HttpException\s*}\s*from\s*["']@nestjs\/common["']\s*;?\s*/gm,
61
- "",
62
- );
63
-
64
- // Remove API structure imports with wrong paths
65
- // Pattern 1: ../api/structures path (LLM often uses this wrong path)
66
- cleanedCode = cleanedCode.replace(
67
- /import\s*(?:type\s*)?{\s*[^}]+\s*}\s*from\s*["']\.\.\/api\/structures\/[^"']+["']\s*;?\s*/gm,
68
- "",
69
- );
70
- // Pattern 2: @ORGANIZATION/PROJECT-api path (correct path but LLM shouldn't write it)
71
- cleanedCode = cleanedCode.replace(
72
- /import\s*(?:type\s*)?{\s*[^}]+\s*}\s*from\s*["']@ORGANIZATION\/PROJECT-api\/lib\/structures\/[^"']+["']\s*;?\s*/gm,
73
- "",
74
- );
75
-
76
- // Remove specific type imports that match our typeReferences
77
- for (const ref of typeReferences) {
78
- const typeImportRegex = new RegExp(
79
- `import\\s*(?:type\\s*)?{\\s*${ref}\\s*}\\s*from\\s*["'][^"']+["']\\s*;?\\s*`,
80
- "gm",
81
- );
82
- cleanedCode = cleanedCode.replace(typeImportRegex, "");
83
- }
84
-
85
- // Remove decorator type imports if LLM mistakenly added them
86
- if (decoratorType) {
87
- const decoratorTypeRegex = new RegExp(
88
- `import\\s*(?:type\\s*)?{\\s*${decoratorType}\\s*}\\s*from\\s*["']\\.\\.\/decorators\/payload\/${decoratorType}["']\\s*;?\\s*`,
89
- "gm",
90
- );
91
- cleanedCode = cleanedCode.replace(decoratorTypeRegex, "");
92
- }
93
-
94
- return cleanedCode;
95
- }
7
+ // /**
8
+ // * Removes all import statements that LLM might have incorrectly added. This
9
+ // * includes standard library imports, auto-injected imports, and any API
10
+ // * structure imports with wrong paths.
11
+ // *
12
+ // * @param code - The code containing imports to remove
13
+ // * @param typeReferences - List of type names to specifically remove
14
+ // * @param decoratorType - Optional decorator type to remove
15
+ // * @returns Code with all imports removed
16
+ // */
17
+ // function removeAllImports(
18
+ // code: string,
19
+ // typeReferences: string[],
20
+ // decoratorType?: string,
21
+ // ): string {
22
+ // // Remove standard library and auto-injected imports
23
+ // let cleanedCode = code
24
+ // // MyGlobal - often with wrong path
25
+ // .replace(
26
+ // /import\s*{\s*MyGlobal\s*}\s*from\s*["']\.\.\/MyGlobal["']\s*;?\s*/gm,
27
+ // "",
28
+ // )
29
+ // // typia - various import patterns
30
+ // .replace(
31
+ // /import\s+typia\s*,\s*{\s*tags\s*}\s*from\s*["']typia["']\s*;?\s*/gm,
32
+ // "",
33
+ // )
34
+ // .replace(/import\s*{\s*tags\s*}\s*from\s*["']typia["']\s*;?\s*/gm, "")
35
+ // .replace(
36
+ // /import\s*{\s*tags\s*,\s*typia\s*}\s*from\s*["']typia["']\s*;?\s*/gm,
37
+ // "",
38
+ // )
39
+ // .replace(/import\s+typia\s*from\s*["']typia["']\s*;?\s*/gm, "")
40
+ // // Prisma client
41
+ // .replace(
42
+ // /import\s*{\s*Prisma\s*}\s*from\s*["']@prisma\/client["']\s*;?\s*/gm,
43
+ // "",
44
+ // )
45
+ // // uuid
46
+ // .replace(/import\s*{\s*v4\s*}\s*from\s*["']uuid["']\s*;?\s*/gm, "")
47
+ // // toISOStringSafe utility
48
+ // .replace(
49
+ // /import\s*{\s*toISOStringSafe\s*}\s*from\s*["']\.\.\/utils\/toISOStringSafe["']\s*;?\s*/gm,
50
+ // "",
51
+ // )
52
+ // // JWT imports (if LLM adds them)
53
+ // .replace(/import\s+jwt\s+from\s*["']jsonwebtoken["']\s*;?\s*/gm, "")
54
+ // .replace(
55
+ // /import\s*\*\s*as\s+jwt\s+from\s*["']jsonwebtoken["']\s*;?\s*/gm,
56
+ // "",
57
+ // )
58
+ // // NestJS HttpException
59
+ // .replace(
60
+ // /import\s*{\s*HttpException\s*}\s*from\s*["']@nestjs\/common["']\s*;?\s*/gm,
61
+ // "",
62
+ // );
63
+
64
+ // // Remove API structure imports with wrong paths
65
+ // // Pattern 1: ../api/structures path (LLM often uses this wrong path)
66
+ // cleanedCode = cleanedCode.replace(
67
+ // /import\s*(?:type\s*)?{\s*[^}]+\s*}\s*from\s*["']\.\.\/api\/structures\/[^"']+["']\s*;?\s*/gm,
68
+ // "",
69
+ // );
70
+ // // Pattern 2: @ORGANIZATION/PROJECT-api path (correct path but LLM shouldn't write it)
71
+ // cleanedCode = cleanedCode.replace(
72
+ // /import\s*(?:type\s*)?{\s*[^}]+\s*}\s*from\s*["']@ORGANIZATION\/PROJECT-api\/lib\/structures\/[^"']+["']\s*;?\s*/gm,
73
+ // "",
74
+ // );
75
+
76
+ // // Remove specific type imports that match our typeReferences
77
+ // for (const ref of typeReferences) {
78
+ // const typeImportRegex = new RegExp(
79
+ // `import\\s*(?:type\\s*)?{\\s*${ref}\\s*}\\s*from\\s*["'][^"']+["']\\s*;?\\s*`,
80
+ // "gm",
81
+ // );
82
+ // cleanedCode = cleanedCode.replace(typeImportRegex, "");
83
+ // }
84
+
85
+ // // Remove decorator type imports if LLM mistakenly added them
86
+ // if (decoratorType) {
87
+ // const decoratorTypeRegex = new RegExp(
88
+ // `import\\s*(?:type\\s*)?{\\s*${decoratorType}\\s*}\\s*from\\s*["']\\.\\.\/decorators\/payload\/${decoratorType}["']\\s*;?\\s*`,
89
+ // "gm",
90
+ // );
91
+ // cleanedCode = cleanedCode.replace(decoratorTypeRegex, "");
92
+ // }
93
+
94
+ // return cleanedCode;
95
+ // }
96
96
 
97
97
  export async function replaceImportStatements<Model extends ILlmSchema.Model>(
98
98
  ctx: AutoBeContext<Model>,
99
99
  props: {
100
100
  operation: AutoBeOpenApi.IOperation;
101
+ schemas: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>;
101
102
  code: string;
102
103
  decoratorType?: string;
103
104
  },
104
- ) {
105
- let { operation, code, decoratorType } = props;
106
-
107
- // Extract type references from operation
108
- const typeReferences: string[] = Array.from(
109
- new Set(
110
- [operation.requestBody, operation.responseBody]
111
- .filter((el) => el !== null)
112
- .map((el) => el.typeName.split(".")[0]!),
113
- ),
114
- );
105
+ ): Promise<string> {
106
+ let { code, decoratorType } = props;
115
107
 
116
108
  // Beautify code first for consistent formatting
117
109
  const compiler: IAutoBeCompiler = await ctx.compiler();
118
110
  code = await compiler.typescript.beautify(code);
119
111
 
120
112
  // Remove all LLM-generated imports
121
- code = removeAllImports(code, typeReferences, decoratorType);
113
+ code = code
114
+ .split("\r\n")
115
+ .join("\n")
116
+ .split("\n")
117
+ .filter((str) => str.trim().startsWith("import") === false)
118
+ .join("\n");
122
119
 
123
120
  // Build the standard imports
124
- const imports = getRealizeWriteImportStatements(operation);
121
+ const imports = getRealizeWriteImportStatements(props);
125
122
 
126
123
  // Only add decoratorType import if it exists
127
124
  if (decoratorType) {
@@ -6,7 +6,7 @@ import { v7 } from "uuid";
6
6
  import { AutoBeSystemPromptConstant } from "../../../constants/AutoBeSystemPromptConstant";
7
7
  import { AutoBeState } from "../../../context/AutoBeState";
8
8
  import { IAutoBeTestScenarioAuthorizationRole } from "../structures/IAutoBeTestScenarioAuthorizationRole";
9
- import { getReferenceIds } from "../utils/getReferenceIds";
9
+ import { getPrerequisites } from "../utils/getPrerequisites";
10
10
 
11
11
  export const transformTestScenarioHistories = (props: {
12
12
  state: AutoBeState;
@@ -17,26 +17,10 @@ export const transformTestScenarioHistories = (props: {
17
17
  }): Array<
18
18
  IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
19
19
  > => {
20
- interface IRelationship {
21
- endpoint: AutoBeOpenApi.IEndpoint;
22
- ids: string[];
23
- }
24
20
  const authorizations: AutoBeInterfaceAuthorization[] =
25
21
  props.state.interface?.authorizations ?? [];
26
22
  const authorizationRoles: Map<string, IAutoBeTestScenarioAuthorizationRole> =
27
23
  new Map();
28
- const relationships: IRelationship[] = props.document.operations
29
- .map((operation) => ({
30
- endpoint: {
31
- method: operation.method,
32
- path: operation.path,
33
- },
34
- ids: getReferenceIds({
35
- document: props.document,
36
- operation,
37
- }),
38
- }))
39
- .filter((v) => v.ids.length !== 0);
40
24
 
41
25
  for (const authorization of authorizations) {
42
26
  for (const op of authorization.operations) {
@@ -92,10 +76,6 @@ export const transformTestScenarioHistories = (props: {
92
76
  You may write multiple scenarios for a single included endpoint.
93
77
  Focus on business-logic-oriented E2E flows rather than trivial CRUD.
94
78
 
95
- Please analyze the operations to identify all dependencies required for testing.
96
- Pay close attention to IDs and related values in the API,
97
- and ensure you identify all dependencies between endpoints.
98
-
99
79
  \`\`\`json
100
80
  ${JSON.stringify({
101
81
  operations: props.document.operations,
@@ -109,46 +89,20 @@ export const transformTestScenarioHistories = (props: {
109
89
  When testing endpoints that require authentication, ensure you include the corresponding
110
90
  join/login operations in your test scenario to establish proper authentication context.
111
91
 
112
- Generate test scenarios only for these included endpoints. Do not create scenarios for excluded endpoints. Operations not listed here may be used only as dependencies.
113
-
114
- ${props.include
115
- .map((el, i) => {
116
- const roles = Array.from(authorizationRoles.values()).filter(
117
- (role) => role.name === el.authorizationRole,
118
- );
119
-
120
- const requiredIds = getReferenceIds({
92
+ \`\`\`json
93
+ ${JSON.stringify(
94
+ props.include.map((el) => ({
95
+ ...el,
96
+ prerequisites: getPrerequisites({
121
97
  document: props.document,
122
- operation: el,
123
- });
124
- return StringUtil.trim`
125
- ## ${i + 1}. ${el.method.toUpperCase()} ${el.path}
126
-
127
- Related Authentication APIs:
128
-
129
- ${
130
- roles.length > 0
131
- ? roles
132
- .map((role) => {
133
- return StringUtil.trim`
134
- - ${role.join?.method.toUpperCase()}: ${role.join?.path}
135
- - ${role.login?.method.toUpperCase()}: ${role.login?.path}
136
- `;
137
- })
138
- .join("\n")
139
- : "- None"
140
- }
141
-
142
- Required IDs:
143
-
144
- - ${
145
- requiredIds.length > 0
146
- ? requiredIds.map((id) => `\`${id}\``).join(", ")
147
- : "None"
148
- }
149
- `;
150
- })
151
- .join("\n")}
98
+ endpoint: el,
99
+ }),
100
+ authorizationRoles: Array.from(authorizationRoles.values()).filter(
101
+ (role) => role.name === el.authorizationRole,
102
+ ),
103
+ })),
104
+ )}
105
+ \`\`\`
152
106
 
153
107
  ## Excluded from Test Plan
154
108
 
@@ -156,37 +110,10 @@ export const transformTestScenarioHistories = (props: {
156
110
  These endpoints do not need to be tested again.
157
111
  However, it is allowed to reference or depend on these endpoints when writing test codes for other purposes.
158
112
 
159
- ${props.exclude
160
- .map((el) => `- ${el.method.toUpperCase()}: ${el.path}`)
161
- .join("\n")}
162
-
163
- ## Candidate Dependencies
164
-
165
- List of candidate dependencies extracted from path parameters and request bodies.
166
-
167
- Apply dependency resolution to the target endpoint from "Included in Test Plan" and to dependencies found recursively from it.
168
- For each required ID, locate the operation that creates the resource. Include the creator only if that operation exists in the provided operations list. Do not assume or invent operations. If no creator exists, treat the ID as an external or pre-existing input.
169
-
170
- Dependency resolution steps:
171
- 1. Starting from the target endpoint, collect required IDs.
172
- 2. For each ID, search for a creator operation (typically POST).
173
- 3. If found, add it to the dependency chain in execution order and repeat for its own required IDs.
174
- 4. Stop when no further creators exist or are needed.
175
-
176
- For each some_entity_id pattern, use the same approach: include a creator only when it is present in the operations list.
177
-
178
- Endpoint | Required IDs (MUST be created by other APIs)
179
- ---------|---------------------------------------------------
180
- ${relationships
181
- .map((r) =>
182
- [
183
- `\`${r.endpoint.method} ${r.endpoint.path}\``,
184
- r.ids.map((id) => `\`${id}\``).join(", "),
185
- ].join(" | "),
186
- )
187
- .join("\n")}
188
-
189
- Example: If an endpoint requires \`articleId\` and \`POST /articles\` exists, include it in dependencies
113
+ \`\`\`json
114
+ ${JSON.stringify(props.exclude)}
115
+ \`\`\`
116
+
190
117
  `,
191
118
  } satisfies IAgenticaHistoryJson.IAssistantMessage,
192
119
  ];