@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
@@ -11,7 +11,8 @@ export namespace JsonSchemaValidator {
11
11
  }
12
12
 
13
13
  export const validateSchemas = (props: IProps): void => {
14
- authorization(props);
14
+ validateAuthorization(props);
15
+ validatePrismaSchema(props.errors);
15
16
  for (const key of Object.keys(props.schemas))
16
17
  validateKey({
17
18
  errors: props.errors,
@@ -41,7 +42,25 @@ export namespace JsonSchemaValidator {
41
42
  it to a valid variable name at the next time.
42
43
  `,
43
44
  });
44
- if (props.key === "IPageIRequest")
45
+ if (props.key.endsWith(".IPage")) {
46
+ const expected: string = `IPage${props.key.substring(0, props.key.length - 6)}`;
47
+ props.errors.push({
48
+ path: `${props.path}[${JSON.stringify(props.key)}]`,
49
+ expected: `"IPage" must be followed by another interface name. Use ${JSON.stringify(expected)} instead.`,
50
+ value: props.key,
51
+ description: StringUtil.trim`
52
+ "IPage" is a reserved type name for pagination response.
53
+ The pagination data type name must be post-fixed after "IPage".
54
+
55
+ However, you've defined ${JSON.stringify(props.key)},
56
+ post-fixing ".IPage" after the pagination data type name.
57
+
58
+ Change it to a valid pagination type name to be
59
+ ${JSON.stringify(expected)} at the next time. Note that,
60
+ this is not a recommendation, but an instruction you must follow.
61
+ `,
62
+ });
63
+ } else if (props.key === "IPageIRequest")
45
64
  props.errors.push({
46
65
  path: `${props.path}[${JSON.stringify(props.key)}]`,
47
66
  expected: `"IPageIRequest" is a mistake. Use "IPage.IRequest" instead.`,
@@ -103,7 +122,7 @@ export namespace JsonSchemaValidator {
103
122
  }
104
123
  };
105
124
 
106
- const authorization = (props: IProps): void => {
125
+ const validateAuthorization = (props: IProps): void => {
107
126
  for (const [key, value] of Object.entries(props.schemas)) {
108
127
  if (!key.endsWith(".IAuthorized")) continue;
109
128
  else if (AutoBeOpenApiTypeChecker.isObject(value) === false) {
@@ -128,4 +147,31 @@ export namespace JsonSchemaValidator {
128
147
  value.required.push("token");
129
148
  }
130
149
  };
150
+
151
+ const validatePrismaSchema = (errors: IValidation.IError[]): void => {
152
+ for (const e of errors) {
153
+ if (e.path.endsWith(`.properties["x-autobe-prisma-schema"]`) === false)
154
+ continue;
155
+ e.expected =
156
+ "undefined value (remove this property and re-define it in the root schema)";
157
+ e.description = StringUtil.trim`
158
+ You have defined a property named "x-autobe-prisma-schema"
159
+ somewhere wrong place.
160
+
161
+ You have defined a property name "x-autobe-prisma-schema" as
162
+ an object type. However, this "x-autobe-prisma-schema" property
163
+ must be defined only in the root schema object as a metadata,
164
+ not in the nested object property.
165
+
166
+ Remove this property at the next time, and re-define it in the
167
+ root object schema.
168
+
169
+ - Current path (wrong): ${e.path}
170
+ - Must be (object root): ${e.path.replace(
171
+ `.properties["x-autobe-prisma-schema"]`,
172
+ `["x-autobe-prisma-schema"]`,
173
+ )}
174
+ `;
175
+ }
176
+ };
131
177
  }
@@ -1,5 +1,5 @@
1
1
  import { AutoBeOpenApi } from "@autobe/interface";
2
- import { AutoBeEndpointComparator, StringUtil } from "@autobe/utils";
2
+ import { AutoBeOpenApiEndpointComparator, StringUtil } from "@autobe/utils";
3
3
  import { HashMap } from "tstl";
4
4
  import { IValidation } from "typia";
5
5
  import { Escaper } from "typia/lib/utils/Escaper";
@@ -8,14 +8,16 @@ import { emplaceMap } from "../../../utils/emplaceMap";
8
8
  import { JsonSchemaValidator } from "./JsonSchemaValidator";
9
9
 
10
10
  export namespace OperationValidator {
11
- export interface IProps {
11
+ export const validate = (props: {
12
12
  errors: IValidation.IError[];
13
13
  path: string;
14
14
  operations: Array<
15
- Omit<AutoBeOpenApi.IOperation, "authorizationRole" | "authorizationType">
15
+ Omit<
16
+ AutoBeOpenApi.IOperation,
17
+ "authorizationRole" | "authorizationType" | "prerequisites"
18
+ >
16
19
  >;
17
- }
18
- export const validate = (props: IProps): void => {
20
+ }): void => {
19
21
  props.operations.forEach((op, i) => {
20
22
  // get method has request body
21
23
  if (op.method === "get" && op.requestBody !== null)
@@ -59,8 +61,8 @@ export namespace OperationValidator {
59
61
 
60
62
  // validate duplicated endpoints
61
63
  const endpoints: HashMap<AutoBeOpenApi.IEndpoint, number[]> = new HashMap(
62
- AutoBeEndpointComparator.hashCode,
63
- AutoBeEndpointComparator.equals,
64
+ AutoBeOpenApiEndpointComparator.hashCode,
65
+ AutoBeOpenApiEndpointComparator.equals,
64
66
  );
65
67
  props.operations.forEach((op, i) => {
66
68
  const key: AutoBeOpenApi.IEndpoint = {
@@ -4,6 +4,7 @@ import { StringUtil } from "@autobe/utils";
4
4
  import { v7 } from "uuid";
5
5
 
6
6
  import { AutoBeSystemPromptConstant } from "../../../constants/AutoBeSystemPromptConstant";
7
+ import { printErrorHints } from "../utils/printErrorHints";
7
8
 
8
9
  interface IFailure {
9
10
  diagnostics: IAutoBeTypeScriptCompileResult.IDiagnostic[];
@@ -20,23 +21,21 @@ export const transformRealizeCorrectCastingHistories = (
20
21
  id: v7(),
21
22
  created_at: new Date().toISOString(),
22
23
  type: "systemMessage",
23
- text: AutoBeSystemPromptConstant.REALIZE_CORRECT_CASTING,
24
+ text: AutoBeSystemPromptConstant.COMMON_CORRECT_CASTING,
24
25
  },
25
26
  ...failures.map(
26
- (f, i, array) =>
27
+ (f) =>
27
28
  ({
28
29
  id: v7(),
29
30
  created_at: new Date().toISOString(),
30
31
  type: "assistantMessage",
31
32
  text: StringUtil.trim`
32
- # ${i === array.length - 1 ? "Latest Failure" : "Previous Failure"}
33
- ## Generated TypeScript Code
34
- \`\`\`typescript
35
- ${f.script}
36
- \`\`\`
37
- ## Compile Errors
38
- \`\`\`json
39
- ${JSON.stringify(f.diagnostics)}
33
+ # Errors
34
+
35
+ This is a past code and an error with the code.
36
+ Please refer to the annotation for the location of the error.
37
+
38
+ ${printErrorHints(f.script, f.diagnostics)}
40
39
  \`\`\`
41
40
  `,
42
41
  }) satisfies IAgenticaHistoryJson.IAssistantMessage,
@@ -7,6 +7,7 @@ import { AutoBeSystemPromptConstant } from "../../../constants/AutoBeSystemPromp
7
7
  import { AutoBeState } from "../../../context/AutoBeState";
8
8
  import { IAutoBeRealizeFunctionFailure } from "../structures/IAutoBeRealizeFunctionFailure";
9
9
  import { IAutoBeRealizeScenarioResult } from "../structures/IAutoBeRealizeScenarioResult";
10
+ import { printErrorHints } from "../utils/printErrorHints";
10
11
  import { transformRealizeWriteHistories } from "./transformRealizeWriteHistories";
11
12
 
12
13
  export function transformRealizeCorrectHistories(props: {
@@ -40,30 +41,18 @@ export function transformRealizeCorrectHistories(props: {
40
41
  `,
41
42
  created_at: new Date().toISOString(),
42
43
  },
43
- ...props.failures.map(
44
- (f) =>
45
- ({
46
- id: v7(),
47
- type: "assistantMessage",
48
- text: StringUtil.trim`
49
-
50
- ## Generated Typescript Code
51
-
52
- \`\`\`typescript
53
- ${f.function.content}
54
- \`\`\`
55
-
56
- ## Compile Errors
57
-
58
- Fix the comilation error in the provided code.
59
-
60
- \`\`\`typescript
61
- ${JSON.stringify(f.diagnostics)}
62
- \`\`\`
63
- `,
64
- created_at: new Date().toISOString(),
65
- }) satisfies IAgenticaHistoryJson.IAssistantMessage,
66
- ),
44
+ ...props.failures.map((f) => {
45
+ return {
46
+ id: v7(),
47
+ type: "assistantMessage",
48
+ text: StringUtil.trim`
49
+ This is a past code and an error with the code. Please refer to the annotation for the location of the error.
50
+
51
+ ${printErrorHints(f.function.content, f.diagnostics)}
52
+ `,
53
+ created_at: new Date().toISOString(),
54
+ } satisfies IAgenticaHistoryJson.IAssistantMessage;
55
+ }),
67
56
  {
68
57
  id: v7(),
69
58
  type: "systemMessage",
@@ -29,13 +29,13 @@ export const transformRealizeWriteAuthorizationsHistories = (
29
29
  - Must NOT require authentication decorator (this endpoint creates authentication)
30
30
  - Should check if user exists and password matches
31
31
 
32
- ### MANDATORY: Use MyGlobal.password for Password Verification
32
+ ### MANDATORY: Use PasswordUtil for Password Verification
33
33
 
34
- **CRITICAL**: You MUST use MyGlobal.password utilities for password verification to ensure consistency with the join operation:
34
+ **CRITICAL**: You MUST use PasswordUtil utilities for password verification to ensure consistency with the join operation:
35
35
 
36
36
  \`\`\`typescript
37
37
  // Example: Password verification in login
38
- const isValid = await MyGlobal.password.verify(
38
+ const isValid = await PasswordUtil.verify(
39
39
  body.password, // plain password from request
40
40
  user.password_hash // hashed password from database
41
41
  );
@@ -126,13 +126,13 @@ export const transformRealizeWriteAuthorizationsHistories = (
126
126
  - Should create a new user record in the database
127
127
  - Must NOT require authentication decorator (public endpoint)
128
128
 
129
- ### MANDATORY: Use MyGlobal.password for Password Hashing
129
+ ### MANDATORY: Use PasswordUtil for Password Hashing
130
130
 
131
- **CRITICAL**: You MUST use MyGlobal.password utilities for password hashing to ensure consistency across all authentication operations:
131
+ **CRITICAL**: You MUST use PasswordUtil utilities for password hashing to ensure consistency across all authentication operations:
132
132
 
133
133
  \`\`\`typescript
134
134
  // Example: Password hashing in join/registration
135
- const hashedPassword = await MyGlobal.password.hash(body.password);
135
+ const hashedPassword = await PasswordUtil.hash(body.password);
136
136
 
137
137
  // Store the hashed password in database
138
138
  await MyGlobal.prisma.users.create({
@@ -100,6 +100,7 @@ export const transformRealizeWriteHistories = (props: {
100
100
  const authorizationHistories = operation.authorizationType
101
101
  ? transformRealizeWriteAuthorizationsHistories(operation, payloads)
102
102
  : [];
103
+ const document = props.state.interface.document;
103
104
 
104
105
  return [
105
106
  {
@@ -127,11 +128,12 @@ export const transformRealizeWriteHistories = (props: {
127
128
  id: v7(),
128
129
  type: "systemMessage",
129
130
  created_at: new Date().toISOString(),
130
- text: getRealizeWriteCodeTemplate(
131
- props.scenario,
131
+ text: getRealizeWriteCodeTemplate({
132
+ authorization: props.authorization,
133
+ scenario: props.scenario,
134
+ schemas: document.components.schemas,
132
135
  operation,
133
- props.authorization,
134
- ),
136
+ }),
135
137
  },
136
138
  {
137
139
  id: v7(),
@@ -47,13 +47,11 @@ export async function compileRealizeFiles<Model extends ILlmSchema.Model>(
47
47
  props.functions.map((el) => [el.location, el.content]),
48
48
  ),
49
49
  };
50
-
51
50
  const compiled: IAutoBeTypeScriptCompileResult =
52
51
  await compiler.typescript.compile({
53
52
  files: files,
54
53
  });
55
-
56
- const event: AutoBeRealizeValidateEvent = {
54
+ return {
57
55
  type: "realizeValidate",
58
56
  id: v7(),
59
57
  files: files,
@@ -61,6 +59,4 @@ export async function compileRealizeFiles<Model extends ILlmSchema.Model>(
61
59
  step: ctx.state().analyze?.step ?? 0,
62
60
  created_at: new Date().toISOString(),
63
61
  };
64
-
65
- return event;
66
62
  }
@@ -17,6 +17,9 @@ import { executeCachedBatch } from "../../utils/executeCachedBatch";
17
17
  import { IAutoBeCommonCorrectCastingApplication } from "../common/structures/IAutoBeCommonCorrectCastingApplication";
18
18
  import { transformRealizeCorrectCastingHistories } from "./histories/transformRealizeCorrectCastingHistories";
19
19
  import { compileRealizeFiles } from "./internal/compileRealizeFiles";
20
+ import { IAutoBeRealizeScenarioResult } from "./structures/IAutoBeRealizeScenarioResult";
21
+ import { getRealizeWriteCodeTemplate } from "./utils/getRealizeWriteCodeTemplate";
22
+ import { replaceImportStatements } from "./utils/replaceImportStatements";
20
23
 
21
24
  /** Result of attempting to correct a single function */
22
25
  type CorrectionResult = {
@@ -28,6 +31,7 @@ export const orchestrateRealizeCorrectCasting = async <
28
31
  Model extends ILlmSchema.Model,
29
32
  >(
30
33
  ctx: AutoBeContext<Model>,
34
+ scenarios: IAutoBeRealizeScenarioResult[],
31
35
  authorizations: AutoBeRealizeAuthorization[],
32
36
  functions: AutoBeRealizeFunction[],
33
37
  progress: AutoBeProgressEventBase,
@@ -40,9 +44,9 @@ export const orchestrateRealizeCorrectCasting = async <
40
44
  functions,
41
45
  },
42
46
  );
43
-
44
47
  return predicate(
45
48
  ctx,
49
+ scenarios,
46
50
  authorizations,
47
51
  functions,
48
52
  [],
@@ -54,6 +58,7 @@ export const orchestrateRealizeCorrectCasting = async <
54
58
 
55
59
  const predicate = async <Model extends ILlmSchema.Model>(
56
60
  ctx: AutoBeContext<Model>,
61
+ scenarios: IAutoBeRealizeScenarioResult[],
57
62
  authorizations: AutoBeRealizeAuthorization[],
58
63
  functions: AutoBeRealizeFunction[],
59
64
  failures: IAutoBeTypeScriptCompileResult.IDiagnostic[],
@@ -63,9 +68,9 @@ const predicate = async <Model extends ILlmSchema.Model>(
63
68
  ): Promise<AutoBeRealizeFunction[]> => {
64
69
  if (event.result.type === "failure") {
65
70
  ctx.dispatch(event);
66
-
67
71
  return await correct(
68
72
  ctx,
73
+ scenarios,
69
74
  authorizations,
70
75
  functions,
71
76
  [...failures, ...event.result.diagnostics],
@@ -79,6 +84,7 @@ const predicate = async <Model extends ILlmSchema.Model>(
79
84
 
80
85
  const correct = async <Model extends ILlmSchema.Model>(
81
86
  ctx: AutoBeContext<Model>,
87
+ scenarios: IAutoBeRealizeScenarioResult[],
82
88
  authorizations: AutoBeRealizeAuthorization[],
83
89
  functions: AutoBeRealizeFunction[],
84
90
  failures: IAutoBeTypeScriptCompileResult.IDiagnostic[],
@@ -94,12 +100,12 @@ const correct = async <Model extends ILlmSchema.Model>(
94
100
  const locations: string[] = diagnose(event).filter((l) =>
95
101
  functions.map((f) => f.location).includes(l),
96
102
  );
97
-
103
+
98
104
  // If no locations to correct, return original functions
99
105
  if (locations.length === 0) {
100
106
  return functions;
101
107
  }
102
-
108
+
103
109
  progress.total += locations.length;
104
110
 
105
111
  const converted: CorrectionResult[] = await executeCachedBatch(
@@ -108,6 +114,13 @@ const correct = async <Model extends ILlmSchema.Model>(
108
114
  (f) => f.location === location,
109
115
  )!;
110
116
 
117
+ const scenario = scenarios.find((s) => s.location === func.location)!;
118
+
119
+ const operation = scenario.operation;
120
+ const authorization = authorizations.find(
121
+ (a) => a.role.name === operation.authorizationRole,
122
+ );
123
+
111
124
  const pointer: IPointer<
112
125
  IAutoBeCommonCorrectCastingApplication.IProps | false | null
113
126
  > = {
@@ -143,18 +156,62 @@ const correct = async <Model extends ILlmSchema.Model>(
143
156
 
144
157
  You don't need to explain me anything, but just fix or give it up
145
158
  immediately without any hesitation, explanation, and questions.
159
+
160
+ The instruction to write at first was as follows, and the code you received is the code you wrote according to this instruction.
161
+ When modifying, modify the entire code, but not the import statement.
162
+
163
+ Below is template code you wrote:
164
+
165
+ ${getRealizeWriteCodeTemplate({
166
+ scenario,
167
+ schemas: ctx.state().interface!.document.components.schemas,
168
+ operation: scenario.operation,
169
+ authorization: authorization ?? null,
170
+ })}
171
+
172
+ Current code is as follows:
173
+
174
+ \`\`\`typescript
175
+ ${func.content}
176
+ \`\`\`
177
+
178
+ Also, never use typia.assert and typia.assertGuard like functions
179
+ to the Prisma types. Your mission is to fix the casting problem of
180
+ primitive types like string or number. Prisma type is not your scope.
181
+
182
+ If you take a mistake that casting the Prisma type with the typia.assert
183
+ function, it would be fallen into the infinite compilation due to extremely
184
+ complicated Prisma type. Note that, the typia.assert function is allowed
185
+ only in the individual property level string or literal type.
186
+
187
+ I repeat that, never assert the Prisma type. It's not your mission.
146
188
  `,
147
189
  });
148
190
  ++progress.completed;
191
+
149
192
  if (pointer.value === null)
150
193
  return { result: "exception" as const, func: func };
151
194
  else if (pointer.value === false)
152
195
  return { result: "ignore" as const, func: func };
153
196
 
197
+ pointer.value.draft = await replaceImportStatements(ctx, {
198
+ schemas: ctx.state().interface!.document.components.schemas,
199
+ operation: operation,
200
+ code: pointer.value.draft,
201
+ decoratorType: authorization?.payload.name,
202
+ });
203
+ if (pointer.value.revise.final)
204
+ pointer.value.revise.final = await replaceImportStatements(ctx, {
205
+ schemas: ctx.state().interface!.document.components.schemas,
206
+ operation: operation,
207
+ code: pointer.value.revise.final,
208
+ decoratorType: authorization?.payload.name,
209
+ });
210
+
154
211
  ctx.dispatch({
155
212
  id: v7(),
156
213
  type: "realizeCorrect",
157
- content: pointer.value.revise.final,
214
+ content: pointer.value.revise.final ?? pointer.value.draft,
158
215
  created_at: new Date().toISOString(),
159
216
  location: func.location,
160
217
  step: ctx.state().analyze?.step ?? 0,
@@ -162,25 +219,38 @@ const correct = async <Model extends ILlmSchema.Model>(
162
219
  completed: progress.completed,
163
220
  total: progress.total,
164
221
  });
165
-
166
222
  return {
167
223
  result: "success" as const,
168
- func: { ...func, content: pointer.value.revise.final },
224
+ func: {
225
+ ...func,
226
+ content: pointer.value.revise.final ?? pointer.value.draft,
227
+ },
169
228
  };
170
229
  }),
171
230
  );
172
231
 
232
+ // Get functions that were not modified (not in locations array)
233
+ const unchangedFunctions: AutoBeRealizeFunction[] = functions.filter(
234
+ (f) => !locations.includes(f.location),
235
+ );
236
+
237
+ // Merge converted functions with unchanged functions for validation
238
+ const allFunctionsForValidation = [
239
+ ...converted.map((c) => c.func),
240
+ ...unchangedFunctions,
241
+ ];
242
+
173
243
  const newValidate: AutoBeRealizeValidateEvent = await compileRealizeFiles(
174
244
  ctx,
175
245
  {
176
246
  authorizations,
177
- functions: converted.map((c) => c.func),
247
+ functions: allFunctionsForValidation,
178
248
  },
179
249
  );
180
250
 
181
251
  const newResult: IAutoBeTypeScriptCompileResult = newValidate.result;
182
252
  if (newResult.type === "success") {
183
- return converted.map((c) => c.func);
253
+ return allFunctionsForValidation;
184
254
  } else if (newResult.type === "exception") {
185
255
  // Compilation exception, return current functions. because retrying won't help.
186
256
  return functions;
@@ -190,7 +260,7 @@ const correct = async <Model extends ILlmSchema.Model>(
190
260
  newResult.diagnostics.every((d) => !d.file?.startsWith("src/providers"))
191
261
  ) {
192
262
  // No diagnostics related to provider functions, stop correcting
193
- return converted.map((c) => c.func);
263
+ return allFunctionsForValidation;
194
264
  }
195
265
 
196
266
  const newLocations: string[] = diagnose(newValidate);
@@ -201,9 +271,9 @@ const correct = async <Model extends ILlmSchema.Model>(
201
271
  newLocations,
202
272
  );
203
273
 
204
- // If no failures to retry, return success and ignored functions
274
+ // If no failures to retry, return all functions
205
275
  if (failed.length === 0) {
206
- return [...success, ...ignored];
276
+ return [...success, ...ignored, ...unchangedFunctions];
207
277
  }
208
278
 
209
279
  // Collect diagnostics relevant to failed functions
@@ -218,6 +288,7 @@ const correct = async <Model extends ILlmSchema.Model>(
218
288
  // Recursively retry failed functions
219
289
  const retriedFunctions: AutoBeRealizeFunction[] = await predicate(
220
290
  ctx,
291
+ scenarios,
221
292
  authorizations,
222
293
  failed,
223
294
  relevantDiagnostics,
@@ -226,11 +297,7 @@ const correct = async <Model extends ILlmSchema.Model>(
226
297
  life - 1,
227
298
  );
228
299
 
229
- // Get functions that were not modified (not in converted array)
230
- const convertedLocations = converted.map(c => c.func.location);
231
- const unchanged = functions.filter(f => !convertedLocations.includes(f.location));
232
-
233
- return [...success, ...ignored, ...retriedFunctions, ...unchanged];
300
+ return [...success, ...ignored, ...retriedFunctions, ...unchangedFunctions];
234
301
  };
235
302
 
236
303
  /**