@autobe/agent 0.25.0 → 0.25.1

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 (184) 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/AutoBeSystemPromptConstant.d.ts +13 -13
  6. package/lib/factory/createAutoBeContext.js +1 -0
  7. package/lib/factory/createAutoBeContext.js.map +1 -1
  8. package/lib/index.mjs +2250 -806
  9. package/lib/index.mjs.map +1 -1
  10. package/lib/orchestrate/common/histories/transformCommonCorrectCastingHistories.js +1 -1
  11. package/lib/orchestrate/common/histories/transformCommonCorrectCastingHistories.js.map +1 -1
  12. package/lib/orchestrate/common/orchestrateCommonCorrectCasting.js +36 -23
  13. package/lib/orchestrate/common/orchestrateCommonCorrectCasting.js.map +1 -1
  14. package/lib/orchestrate/common/structures/IAutoBeCommonCorrectCastingApplication.d.ts +22 -42
  15. package/lib/orchestrate/interface/histories/transformInterfaceCommonPrerequisiteHistories.d.ts +3 -0
  16. package/lib/orchestrate/interface/histories/{transformInterfacePrerequisiteHistories.js → transformInterfaceCommonPrerequisiteHistories.js} +4 -4
  17. package/lib/orchestrate/interface/histories/transformInterfaceCommonPrerequisiteHistories.js.map +1 -0
  18. package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js +2 -2
  19. package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js.map +1 -1
  20. package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js +3 -3
  21. package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js.map +1 -1
  22. package/lib/orchestrate/interface/histories/transformInterfacePrerequisitesHistories.d.ts +3 -0
  23. package/lib/orchestrate/interface/histories/transformInterfacePrerequisitesHistories.js +102 -0
  24. package/lib/orchestrate/interface/histories/transformInterfacePrerequisitesHistories.js.map +1 -0
  25. package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js +1 -1
  26. package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js.map +1 -1
  27. package/lib/orchestrate/interface/histories/transformInterfaceSchemasReviewHistories.js +2 -2
  28. package/lib/orchestrate/interface/histories/transformInterfaceSchemasReviewHistories.js.map +1 -1
  29. package/lib/orchestrate/interface/orchestrateInterface.js +25 -9
  30. package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
  31. package/lib/orchestrate/interface/orchestrateInterfaceAuthorizations.js +260 -29
  32. package/lib/orchestrate/interface/orchestrateInterfaceAuthorizations.js.map +1 -1
  33. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +56 -64
  34. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
  35. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +3 -3
  36. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
  37. package/lib/orchestrate/interface/orchestrateInterfaceGroups.js +2 -2
  38. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +4 -5
  39. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
  40. package/lib/orchestrate/interface/orchestrateInterfaceOperationsReview.js +260 -29
  41. package/lib/orchestrate/interface/orchestrateInterfaceOperationsReview.js.map +1 -1
  42. package/lib/orchestrate/interface/orchestrateInterfacePrerequisites.d.ts +5 -0
  43. package/lib/orchestrate/interface/orchestrateInterfacePrerequisites.js +713 -0
  44. package/lib/orchestrate/interface/orchestrateInterfacePrerequisites.js.map +1 -0
  45. package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js +47 -35
  46. package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js.map +1 -1
  47. package/lib/orchestrate/interface/orchestrateInterfaceSchemasReview.js +41 -7
  48. package/lib/orchestrate/interface/orchestrateInterfaceSchemasReview.js.map +1 -1
  49. package/lib/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.d.ts +0 -38
  50. package/lib/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.d.ts +6 -10
  51. package/lib/orchestrate/interface/structures/IAutoBeInterfacePrerequisitesApplication.d.ts +52 -0
  52. package/lib/orchestrate/interface/structures/IAutoBeInterfacePrerequisitesApplication.js +3 -0
  53. package/lib/orchestrate/interface/structures/IAutoBeInterfacePrerequisitesApplication.js.map +1 -0
  54. package/lib/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.d.ts +0 -33
  55. package/lib/orchestrate/interface/utils/JsonSchemaFactory.d.ts +6 -2
  56. package/lib/orchestrate/interface/utils/JsonSchemaFactory.js +105 -5
  57. package/lib/orchestrate/interface/utils/JsonSchemaFactory.js.map +1 -1
  58. package/lib/orchestrate/interface/utils/JsonSchemaValidator.js +20 -1
  59. package/lib/orchestrate/interface/utils/JsonSchemaValidator.js.map +1 -1
  60. package/lib/orchestrate/interface/utils/OperationValidator.d.ts +3 -4
  61. package/lib/orchestrate/interface/utils/OperationValidator.js +1 -1
  62. package/lib/orchestrate/interface/utils/OperationValidator.js.map +1 -1
  63. package/lib/orchestrate/realize/histories/transformRealizeCorrectCastingHistories.js +9 -10
  64. package/lib/orchestrate/realize/histories/transformRealizeCorrectCastingHistories.js.map +1 -1
  65. package/lib/orchestrate/realize/histories/transformRealizeCorrectHistories.js +14 -22
  66. package/lib/orchestrate/realize/histories/transformRealizeCorrectHistories.js.map +1 -1
  67. package/lib/orchestrate/realize/histories/transformRealizeWriteAuthorizationsHistories.js +6 -6
  68. package/lib/orchestrate/realize/histories/transformRealizeWriteHistories.js +8 -2
  69. package/lib/orchestrate/realize/histories/transformRealizeWriteHistories.js.map +1 -1
  70. package/lib/orchestrate/realize/internal/compileRealizeFiles.js +1 -2
  71. package/lib/orchestrate/realize/internal/compileRealizeFiles.js.map +1 -1
  72. package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.d.ts +2 -1
  73. package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.js +103 -40
  74. package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.js.map +1 -1
  75. package/lib/orchestrate/realize/orchestrateRealize.js +81 -45
  76. package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
  77. package/lib/orchestrate/realize/orchestrateRealizeCorrect.js +117 -87
  78. package/lib/orchestrate/realize/orchestrateRealizeCorrect.js.map +1 -1
  79. package/lib/orchestrate/realize/orchestrateRealizeWrite.d.ts +2 -1
  80. package/lib/orchestrate/realize/orchestrateRealizeWrite.js +117 -54
  81. package/lib/orchestrate/realize/orchestrateRealizeWrite.js.map +1 -1
  82. package/lib/orchestrate/realize/structures/IAutoBeRealizeCorrectApplication.d.ts +52 -26
  83. package/lib/orchestrate/realize/structures/IAutoBeRealizeWriteApplication.d.ts +44 -34
  84. package/lib/orchestrate/realize/utils/InternalFileSystem.js +1 -1
  85. package/lib/orchestrate/realize/utils/InternalFileSystem.js.map +1 -1
  86. package/lib/orchestrate/realize/utils/getRealizeWriteCodeTemplate.d.ts +8 -3
  87. package/lib/orchestrate/realize/utils/getRealizeWriteCodeTemplate.js +44 -17
  88. package/lib/orchestrate/realize/utils/getRealizeWriteCodeTemplate.js.map +1 -1
  89. package/lib/orchestrate/realize/utils/getRealizeWriteImportStatements.d.ts +4 -1
  90. package/lib/orchestrate/realize/utils/getRealizeWriteImportStatements.js +24 -9
  91. package/lib/orchestrate/realize/utils/getRealizeWriteImportStatements.js.map +1 -1
  92. package/lib/orchestrate/realize/utils/printErrorHints.d.ts +8 -0
  93. package/lib/orchestrate/realize/utils/printErrorHints.js +48 -0
  94. package/lib/orchestrate/realize/utils/printErrorHints.js.map +1 -0
  95. package/lib/orchestrate/realize/utils/replaceImportStatements.d.ts +1 -0
  96. package/lib/orchestrate/realize/utils/replaceImportStatements.js +93 -55
  97. package/lib/orchestrate/realize/utils/replaceImportStatements.js.map +1 -1
  98. package/lib/orchestrate/test/histories/transformTestCorrectHistories.js +1 -1
  99. package/lib/orchestrate/test/histories/transformTestCorrectHistories.js.map +1 -1
  100. package/lib/orchestrate/test/histories/transformTestCorrectInvalidRequestHistories.js +1 -1
  101. package/lib/orchestrate/test/histories/transformTestCorrectInvalidRequestHistories.js.map +1 -1
  102. package/lib/orchestrate/test/histories/transformTestScenarioHistories.js +10 -79
  103. package/lib/orchestrate/test/histories/transformTestScenarioHistories.js.map +1 -1
  104. package/lib/orchestrate/test/histories/transformTestScenarioReviewHistories.js +15 -65
  105. package/lib/orchestrate/test/histories/transformTestScenarioReviewHistories.js.map +1 -1
  106. package/lib/orchestrate/test/histories/transformTestWriteHistories.js +1 -1
  107. package/lib/orchestrate/test/histories/transformTestWriteHistories.js.map +1 -1
  108. package/lib/orchestrate/test/orchestrateTestCorrect.js +32 -17
  109. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  110. package/lib/orchestrate/test/orchestrateTestCorrectInvalidRequest.js +31 -13
  111. package/lib/orchestrate/test/orchestrateTestCorrectInvalidRequest.js.map +1 -1
  112. package/lib/orchestrate/test/orchestrateTestScenario.d.ts +1 -1
  113. package/lib/orchestrate/test/orchestrateTestScenario.js +5 -5
  114. package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
  115. package/lib/orchestrate/test/orchestrateTestScenarioReview.js +1 -1
  116. package/lib/orchestrate/test/orchestrateTestScenarioReview.js.map +1 -1
  117. package/lib/orchestrate/test/orchestrateTestWrite.js +37 -21
  118. package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -1
  119. package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.d.ts +9 -5
  120. package/lib/orchestrate/test/structures/IAutoBeTestCorrectInvalidRequestApplication.d.ts +8 -2
  121. package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.d.ts +11 -7
  122. package/lib/orchestrate/test/utils/getPrerequisites.d.ts +5 -0
  123. package/lib/orchestrate/test/utils/getPrerequisites.js +36 -0
  124. package/lib/orchestrate/test/utils/getPrerequisites.js.map +1 -0
  125. package/lib/orchestrate/test/utils/getReferenceIds.js +1 -1
  126. package/lib/orchestrate/test/utils/getReferenceIds.js.map +1 -1
  127. package/package.json +5 -5
  128. package/src/AutoBeAgent.ts +17 -1
  129. package/src/AutoBeMockAgent.ts +1 -0
  130. package/src/constants/AutoBeSystemPromptConstant.ts +13 -13
  131. package/src/factory/createAutoBeContext.ts +1 -0
  132. package/src/orchestrate/common/orchestrateCommonCorrectCasting.ts +2 -2
  133. package/src/orchestrate/common/structures/IAutoBeCommonCorrectCastingApplication.ts +25 -45
  134. package/src/orchestrate/interface/histories/{transformInterfacePrerequisiteHistories.ts → transformInterfaceCommonPrerequisiteHistories.ts} +1 -1
  135. package/src/orchestrate/interface/histories/transformInterfaceGroupHistories.ts +4 -2
  136. package/src/orchestrate/interface/histories/transformInterfacePrerequisitesHistories.ts +118 -0
  137. package/src/orchestrate/interface/orchestrateInterface.ts +43 -17
  138. package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +12 -33
  139. package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +5 -5
  140. package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +7 -6
  141. package/src/orchestrate/interface/orchestrateInterfacePrerequisites.ts +274 -0
  142. package/src/orchestrate/interface/orchestrateInterfaceSchemas.ts +1 -1
  143. package/src/orchestrate/interface/orchestrateInterfaceSchemasReview.ts +1 -1
  144. package/src/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.ts +0 -39
  145. package/src/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.ts +6 -10
  146. package/src/orchestrate/interface/structures/IAutoBeInterfacePrerequisitesApplication.ts +58 -0
  147. package/src/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.ts +0 -34
  148. package/src/orchestrate/interface/utils/JsonSchemaFactory.ts +92 -4
  149. package/src/orchestrate/interface/utils/JsonSchemaValidator.ts +19 -1
  150. package/src/orchestrate/interface/utils/OperationValidator.ts +9 -7
  151. package/src/orchestrate/realize/histories/transformRealizeCorrectCastingHistories.ts +9 -10
  152. package/src/orchestrate/realize/histories/transformRealizeCorrectHistories.ts +13 -24
  153. package/src/orchestrate/realize/histories/transformRealizeWriteAuthorizationsHistories.ts +6 -6
  154. package/src/orchestrate/realize/histories/transformRealizeWriteHistories.ts +6 -4
  155. package/src/orchestrate/realize/internal/compileRealizeFiles.ts +1 -5
  156. package/src/orchestrate/realize/orchestRateRealizeCorrectCasting.ts +84 -17
  157. package/src/orchestrate/realize/orchestrateRealize.ts +125 -74
  158. package/src/orchestrate/realize/orchestrateRealizeCorrect.ts +33 -6
  159. package/src/orchestrate/realize/orchestrateRealizeWrite.ts +14 -4
  160. package/src/orchestrate/realize/structures/IAutoBeRealizeCorrectApplication.ts +54 -29
  161. package/src/orchestrate/realize/structures/IAutoBeRealizeWriteApplication.ts +46 -35
  162. package/src/orchestrate/realize/utils/InternalFileSystem.ts +1 -1
  163. package/src/orchestrate/realize/utils/getRealizeWriteCodeTemplate.ts +54 -22
  164. package/src/orchestrate/realize/utils/getRealizeWriteImportStatements.ts +28 -16
  165. package/src/orchestrate/realize/utils/printErrorHints.ts +55 -0
  166. package/src/orchestrate/realize/utils/replaceImportStatements.ts +99 -102
  167. package/src/orchestrate/test/histories/transformTestScenarioHistories.ts +18 -91
  168. package/src/orchestrate/test/histories/transformTestScenarioReviewHistories.ts +17 -90
  169. package/src/orchestrate/test/orchestrateTestCorrect.ts +7 -6
  170. package/src/orchestrate/test/orchestrateTestCorrectInvalidRequest.ts +13 -1
  171. package/src/orchestrate/test/orchestrateTestScenario.ts +12 -6
  172. package/src/orchestrate/test/orchestrateTestScenarioReview.ts +3 -3
  173. package/src/orchestrate/test/orchestrateTestWrite.ts +7 -6
  174. package/src/orchestrate/test/structures/IAutoBeTestCorrectApplication.ts +9 -228
  175. package/src/orchestrate/test/structures/IAutoBeTestCorrectInvalidRequestApplication.ts +8 -2
  176. package/src/orchestrate/test/structures/IAutoBeTestWriteApplication.ts +11 -78
  177. package/src/orchestrate/test/utils/getPrerequisites.ts +51 -0
  178. package/src/orchestrate/test/utils/getReferenceIds.ts +2 -1
  179. package/lib/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.d.ts +0 -3
  180. package/lib/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.js.map +0 -1
  181. package/lib/orchestrate/interface/utils/OpenApiEndpointComparator.d.ts +0 -6
  182. package/lib/orchestrate/interface/utils/OpenApiEndpointComparator.js +0 -22
  183. package/lib/orchestrate/interface/utils/OpenApiEndpointComparator.js.map +0 -1
  184. package/src/orchestrate/interface/utils/OpenApiEndpointComparator.ts +0 -23
@@ -19,6 +19,7 @@ import { IAutoBeRealizeCorrectApplication } from "./structures/IAutoBeRealizeCor
19
19
  import { IAutoBeRealizeFunctionFailure } from "./structures/IAutoBeRealizeFunctionFailure";
20
20
  import { IAutoBeRealizeScenarioResult } from "./structures/IAutoBeRealizeScenarioResult";
21
21
  import { filterDiagnostics } from "./utils/filterDiagnostics";
22
+ import { getRealizeWriteCodeTemplate } from "./utils/getRealizeWriteCodeTemplate";
22
23
  import { getRealizeWriteDto } from "./utils/getRealizeWriteDto";
23
24
  import { replaceImportStatements } from "./utils/replaceImportStatements";
24
25
 
@@ -42,7 +43,9 @@ export async function orchestrateRealizeCorrect<Model extends ILlmSchema.Model>(
42
43
  const diagnostics = event.result.diagnostics;
43
44
 
44
45
  if (
45
- event.result.diagnostics.every((d) => !d.file?.startsWith("src/providers"))
46
+ event.result.diagnostics.every(
47
+ (d) => !d.file?.startsWith("src/providers"),
48
+ ) === true
46
49
  ) {
47
50
  // No diagnostics related to provider functions, stop correcting
48
51
  return functions;
@@ -99,7 +102,6 @@ export async function orchestrateRealizeCorrect<Model extends ILlmSchema.Model>(
99
102
  ),
100
103
  progress,
101
104
  );
102
-
103
105
  return orchestrateRealizeCorrect(
104
106
  ctx,
105
107
  scenarios,
@@ -211,6 +213,23 @@ async function step<Model extends ILlmSchema.Model>(
211
213
  enforceFunctionCall: true,
212
214
  message: StringUtil.trim`
213
215
  Correct the TypeScript code implementation.
216
+
217
+ The instruction to write at first was as follows, and the code you received is the code you wrote according to this instruction.
218
+ When modifying, modify the entire code, but not the import statement.
219
+
220
+ Below is template code you wrote:
221
+
222
+ ${getRealizeWriteCodeTemplate({
223
+ scenario: props.scenario,
224
+ schemas: ctx.state().interface!.document.components.schemas,
225
+ operation: props.scenario.operation,
226
+ authorization: props.authorization ?? null,
227
+ })}
228
+
229
+ Current code is as follows:
230
+ \`\`\`typescript
231
+ ${props.function.content}
232
+ \`\`\`
214
233
  `,
215
234
  });
216
235
 
@@ -218,17 +237,25 @@ async function step<Model extends ILlmSchema.Model>(
218
237
  return null;
219
238
  }
220
239
 
221
- pointer.value.revise.final = await replaceImportStatements(ctx, {
240
+ pointer.value.draft = await replaceImportStatements(ctx, {
222
241
  operation: props.scenario.operation,
223
- code: pointer.value.revise.final,
242
+ schemas: ctx.state().interface!.document.components.schemas,
243
+ code: pointer.value.draft,
224
244
  decoratorType: props.authorization?.payload.name,
225
245
  });
246
+ if (pointer.value.revise.final)
247
+ pointer.value.revise.final = await replaceImportStatements(ctx, {
248
+ operation: props.scenario.operation,
249
+ schemas: ctx.state().interface!.document.components.schemas,
250
+ code: pointer.value.revise.final,
251
+ decoratorType: props.authorization?.payload.name,
252
+ });
226
253
 
227
254
  const event: AutoBeRealizeCorrectEvent = {
228
255
  type: "realizeCorrect",
229
256
  id: v7(),
230
257
  location: props.scenario.location,
231
- content: pointer.value.revise.final,
258
+ content: pointer.value.revise.final ?? pointer.value.draft,
232
259
  tokenUsage,
233
260
  completed: ++props.progress.completed,
234
261
  total: props.progress.total,
@@ -253,7 +280,7 @@ function createController<Model extends ILlmSchema.Model>(props: {
253
280
  name: "Write code",
254
281
  application,
255
282
  execute: {
256
- review: (next) => {
283
+ correct: (next) => {
257
284
  props.build(next);
258
285
  },
259
286
  } satisfies IAutoBeRealizeCorrectApplication,
@@ -1,4 +1,5 @@
1
1
  import {
2
+ AutoBeOpenApi,
2
3
  AutoBeProgressEventBase,
3
4
  AutoBeRealizeAuthorization,
4
5
  AutoBeRealizeWriteEvent,
@@ -20,6 +21,7 @@ import { replaceImportStatements } from "./utils/replaceImportStatements";
20
21
  export async function orchestrateRealizeWrite<Model extends ILlmSchema.Model>(
21
22
  ctx: AutoBeContext<Model>,
22
23
  props: {
24
+ document: AutoBeOpenApi.IDocument;
23
25
  totalAuthorizations: AutoBeRealizeAuthorization[];
24
26
  authorization: AutoBeRealizeAuthorization | null;
25
27
  scenario: IAutoBeRealizeScenarioResult;
@@ -69,17 +71,25 @@ export async function orchestrateRealizeWrite<Model extends ILlmSchema.Model>(
69
71
  });
70
72
  if (pointer.value === null) throw new Error("Failed to write code.");
71
73
 
72
- pointer.value.final = await replaceImportStatements(ctx, {
74
+ pointer.value.draft = await replaceImportStatements(ctx, {
73
75
  operation: props.scenario.operation,
74
- code: pointer.value.final,
76
+ schemas: props.document.components.schemas,
77
+ code: pointer.value.draft,
75
78
  decoratorType: props.authorization?.payload.name,
76
79
  });
80
+ if (pointer.value.revise.final)
81
+ pointer.value.revise.final = await replaceImportStatements(ctx, {
82
+ operation: props.scenario.operation,
83
+ schemas: props.document.components.schemas,
84
+ code: pointer.value.revise.final,
85
+ decoratorType: props.authorization?.payload.name,
86
+ });
77
87
 
78
88
  const event: AutoBeRealizeWriteEvent = {
79
89
  type: "realizeWrite",
80
90
  id: v7(),
81
91
  location: props.scenario.location,
82
- content: pointer.value.final,
92
+ content: pointer.value.revise.final ?? pointer.value.draft,
83
93
  tokenUsage,
84
94
  completed: ++props.progress.completed,
85
95
  total: props.progress.total,
@@ -105,7 +115,7 @@ function createController<Model extends ILlmSchema.Model>(props: {
105
115
  name: "Write code",
106
116
  application,
107
117
  execute: {
108
- coding: (next) => {
118
+ write: (next) => {
109
119
  props.build(next);
110
120
  },
111
121
  } satisfies IAutoBeRealizeWriteApplication,
@@ -1,45 +1,70 @@
1
1
  export interface IAutoBeRealizeCorrectApplication {
2
2
  /**
3
- * Reviews and corrects TypeScript compilation errors.
3
+ * Systematically analyze and correct TypeScript compilation errors.
4
4
  *
5
- * Fixes TypeScript compilation errors while preserving original business
6
- * logic, applying minimal intervention principle.
5
+ * Implements a three-phase workflow (think draft → revise) that balances
6
+ * efficiency for simple errors with thoroughness for complex problems.
7
7
  *
8
- * @param props Properties containing the multi-phase error correction process
8
+ * @param props Three-phase correction properties
9
9
  */
10
- review: (props: IAutoBeRealizeCorrectApplication.IProps) => void;
10
+ correct(props: IAutoBeRealizeCorrectApplication.IProps): void;
11
11
  }
12
12
 
13
13
  export namespace IAutoBeRealizeCorrectApplication {
14
- /**
15
- * Properties for error correction following Chain of Thinking (CoT).
16
- *
17
- * All phases are wrapped in a `revise` object for systematic error
18
- * resolution.
19
- */
20
14
  export interface IProps {
21
- /** Revision process containing all error correction phases. */
22
- revise: IRevise;
23
- }
24
-
25
- export interface IRevise {
26
- /**
27
- * Step 1: TypeScript compilation error analysis and resolution strategy.
28
- * Analyzes TypeScript compiler diagnostics (error codes, messages) to understand
29
- * type mismatches, missing properties, nullable conflicts, and other compilation issues.
15
+ /**
16
+ * Initial error analysis and correction strategy.
17
+ *
18
+ * Analyzes TypeScript compilation errors to understand:
19
+ *
20
+ * - Error patterns and root causes
21
+ * - Required fixes and their impact
22
+ * - Whether quick fixes or deep refactoring is needed
23
+ * - Prisma schema and API contract constraints
30
24
  */
31
- errorAnalysis?: string;
25
+ think: string;
32
26
 
33
- /** Step 2: Provider function implementation plan. */
34
- plan?: string;
27
+ /**
28
+ * First correction attempt.
29
+ *
30
+ * Implements the initial fixes identified in the think phase. For simple
31
+ * errors (typos, missing imports), this may be the final solution. Complex
32
+ * errors may require further refinement.
33
+ */
34
+ draft: string;
35
35
 
36
- /** Step 3: Relevant Prisma schema definitions. */
37
- prismaSchemas?: string;
36
+ /**
37
+ * Revision and finalization phase.
38
+ *
39
+ * Reviews the draft corrections and produces the final, error-free code
40
+ * that maintains all business requirements.
41
+ */
42
+ revise: IReviseProps;
43
+ }
38
44
 
39
- /** Step 4: Refined version with improved completeness. */
40
- review?: string;
45
+ export interface IReviseProps {
46
+ /**
47
+ * Correction review and validation.
48
+ *
49
+ * Analyzes the draft corrections to ensure:
50
+ *
51
+ * - All TypeScript errors are resolved
52
+ * - Business logic remains intact
53
+ * - AutoBE coding standards are maintained
54
+ * - No new errors are introduced
55
+ * - Performance and security are preserved
56
+ */
57
+ review: string;
41
58
 
42
- /** Step 5: Final complete TypeScript function implementation. */
43
- final: string;
59
+ /**
60
+ * Final error-free implementation.
61
+ *
62
+ * The complete, corrected code that passes all TypeScript compilation
63
+ * checks.
64
+ *
65
+ * Returns `null` if the draft corrections are sufficient and need no
66
+ * further changes.
67
+ */
68
+ final: string | null;
44
69
  }
45
70
  }
@@ -1,55 +1,66 @@
1
1
  export interface IAutoBeRealizeWriteApplication {
2
2
  /**
3
- * Generates provider function implementation through multi-phase development.
3
+ * Generate complete provider function implementation using Chain of Thinking.
4
4
  *
5
- * This method implements a systematic approach to generate NestJS provider
6
- * functions that handle business logic for API operations. It follows a
7
- * schema-first approach with multiple refinement phases to ensure type-safe,
8
- * error-free code generation.
5
+ * Follows a 3-phase process: plan draft revise.
9
6
  *
10
- * The generation process includes:
7
+ * Ensures type safety, proper Prisma usage, and API contract compliance.
11
8
  *
12
- * 1. Strategic planning based on Prisma schema analysis
13
- * 2. Schema definition for relevant models
14
- * 3. Review and refinement for completeness
15
- * 4. Final implementation with all validations and type safety
16
- *
17
- * @param next Properties containing the multi-phase implementation plan and
18
- * code
9
+ * @param props Chain of Thinking properties for implementation
19
10
  */
20
- coding: (next: IAutoBeRealizeWriteApplication.IProps) => void;
11
+ write(props: IAutoBeRealizeWriteApplication.IProps): void;
21
12
  }
22
13
 
23
14
  export namespace IAutoBeRealizeWriteApplication {
24
- /**
25
- * Properties for the Realize Write Application following Chain of Thinking
26
- * (CoT).
27
- *
28
- * Each field represents a distinct phase in the implementation process.
29
- * Detailed guidelines are in REALIZE_WRITE.md.
30
- */
31
15
  export interface IProps {
32
16
  /**
33
- * Step 1 - Planning Phase (CoT: Initial Reasoning)
34
- *
35
- * Strategic plan following SCHEMA-FIRST APPROACH:
36
- *
37
- * 1. Verify Prisma schema fields (list existing and non-existing)
38
- * 2. Plan field usage in operations
39
- * 3. Plan type conversions and nullable handling
40
- * 4. Define implementation approach with error handling
17
+ * Implementation plan and strategy.
41
18
  *
42
- * See REALIZE_WRITE.md for detailed requirements.
19
+ * Analyzes the provider function requirements, identifies related Prisma
20
+ * schemas, and outlines the implementation approach. Includes schema
21
+ * validation and API contract verification.
43
22
  */
44
23
  plan: string;
45
24
 
46
- /** Step 2 - Relevant Prisma schema models and fields */
47
- prismaSchemas: string;
25
+ /**
26
+ * Initial implementation draft.
27
+ *
28
+ * The first complete implementation attempt based on the plan. May contain
29
+ * areas that need refinement in the review phase.
30
+ */
31
+ draft: string;
32
+
33
+ /**
34
+ * Revision and finalization phase.
35
+ *
36
+ * Reviews the draft implementation and produces the final code with all
37
+ * improvements and corrections applied.
38
+ */
39
+ revise: IReviseProps;
40
+ }
48
41
 
49
- /** Step 3 - Refined version with real operations */
42
+ export interface IReviseProps {
43
+ /**
44
+ * Review and improvement suggestions.
45
+ *
46
+ * Identifies areas for improvement in the draft code, including:
47
+ *
48
+ * - Type safety enhancements
49
+ * - Prisma query optimizations
50
+ * - Null/undefined handling corrections
51
+ * - Authentication/authorization improvements
52
+ * - Error handling refinements
53
+ */
50
54
  review: string;
51
55
 
52
- /** Step 4 - Final implementation See REALIZE_WRITE.md for requirements */
53
- final: string;
56
+ /**
57
+ * Final implementation code.
58
+ *
59
+ * The complete, production-ready implementation with all review suggestions
60
+ * applied.
61
+ *
62
+ * Returns `null` if the draft is already perfect and needs no changes.
63
+ */
64
+ final: string | null;
54
65
  }
55
66
  }
@@ -7,6 +7,6 @@ export namespace InternalFileSystem {
7
7
  export const DEFAULT = [
8
8
  "src/providers/authorize/jwtAuthorize.ts",
9
9
  "src/MyGlobal.ts",
10
- "src/util/toISOStringSafe.ts",
10
+ "src/utils/toISOStringSafe.ts",
11
11
  ];
12
12
  }
@@ -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
+ }