@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
@@ -5,6 +5,7 @@ import {
5
5
  AutoBeRealizeAuthorization,
6
6
  AutoBeRealizeFunction,
7
7
  AutoBeRealizeHistory,
8
+ AutoBeRealizeValidateEvent,
8
9
  AutoBeRealizeWriteEvent,
9
10
  IAutoBeCompiler,
10
11
  } from "@autobe/interface";
@@ -29,9 +30,9 @@ export const orchestrateRealize =
29
30
  props: IAutoBeApplicationProps,
30
31
  ): Promise<AutoBeAssistantMessageHistory | AutoBeRealizeHistory> => {
31
32
  // PREDICATION
32
- const operations: AutoBeOpenApi.IOperation[] | undefined =
33
- ctx.state().interface?.document.operations;
34
- if (!operations)
33
+ const document: AutoBeOpenApi.IDocument | undefined =
34
+ ctx.state().interface?.document;
35
+ if (document === undefined)
35
36
  throw new Error("Can't do realize agent because operations are nothing.");
36
37
 
37
38
  const start: Date = new Date();
@@ -55,102 +56,150 @@ export const orchestrateRealize =
55
56
  step: ctx.state().test?.step ?? 0,
56
57
  });
57
58
 
58
- // AUTHORIZATIONS
59
+ // PREPARE ASSETS
60
+ const compiler: IAutoBeCompiler = await ctx.compiler();
59
61
  const authorizations: AutoBeRealizeAuthorization[] =
60
62
  await orchestrateRealizeAuthorization(ctx);
61
63
 
62
- // SCENARIOS
63
- const scenarios: IAutoBeRealizeScenarioResult[] = operations.map(
64
- (operation) => generateRealizeScenario(ctx, operation, authorizations),
65
- );
66
-
67
64
  const writeProgress: AutoBeProgressEventBase = {
68
- total: scenarios.length,
65
+ total: document.operations.length,
66
+ completed: 0,
67
+ };
68
+ const correctProgress: AutoBeProgressEventBase = {
69
+ total: document.operations.length,
69
70
  completed: 0,
70
71
  };
71
- const writeEvents: (AutoBeRealizeWriteEvent | null)[] =
72
- await executeCachedBatch(
73
- scenarios.map((scenario) => async (promptCacheKey) => {
74
- const props = {
75
- totalAuthorizations: authorizations,
76
- authorization: scenario.decoratorEvent ?? null,
77
- scenario,
78
- progress: writeProgress,
79
- promptCacheKey,
80
- };
81
-
82
- const code: AutoBeRealizeWriteEvent | null =
83
- await orchestrateRealizeWrite(ctx, props).catch(() => {
84
- return orchestrateRealizeWrite(ctx, props).catch(() => null);
85
- });
86
72
 
87
- return code;
88
- }),
73
+ const process = async (
74
+ artifacts: IAutoBeRealizeScenarioResult[],
75
+ ): Promise<IBucket> => {
76
+ const writes: AutoBeRealizeWriteEvent[] = (
77
+ await executeCachedBatch(
78
+ artifacts.map((art) => async (promptCacheKey) => {
79
+ const write = async (): Promise<AutoBeRealizeWriteEvent | null> => {
80
+ try {
81
+ return await orchestrateRealizeWrite(ctx, {
82
+ totalAuthorizations: authorizations,
83
+ authorization: art.decoratorEvent ?? null,
84
+ scenario: art,
85
+ document,
86
+ progress: writeProgress,
87
+ promptCacheKey,
88
+ });
89
+ } catch {
90
+ return null;
91
+ }
92
+ };
93
+ return (await write()) ?? (await write());
94
+ }),
95
+ )
96
+ ).filter((w) => w !== null);
97
+ const functions: AutoBeRealizeFunction[] = Object.entries(
98
+ Object.fromEntries(writes.map((w) => [w.location, w.content])),
99
+ ).map(([location, content]) => {
100
+ const scenario: IAutoBeRealizeScenarioResult = artifacts.find(
101
+ (el) => el.location === location,
102
+ )!;
103
+ return {
104
+ location,
105
+ content,
106
+ endpoint: {
107
+ method: scenario.operation.method,
108
+ path: scenario.operation.path,
109
+ },
110
+ name: scenario.functionName,
111
+ };
112
+ });
113
+ const corrected: AutoBeRealizeFunction[] =
114
+ await orchestrateRealizeCorrectCasting(
115
+ ctx,
116
+ artifacts,
117
+ authorizations,
118
+ functions,
119
+ correctProgress,
120
+ ).then(async (res) => {
121
+ return await orchestrateRealizeCorrect(
122
+ ctx,
123
+ artifacts,
124
+ authorizations,
125
+ res,
126
+ [],
127
+ correctProgress,
128
+ );
129
+ });
130
+ const validate: AutoBeRealizeValidateEvent = await compileRealizeFiles(
131
+ ctx,
132
+ {
133
+ authorizations,
134
+ functions: corrected,
135
+ },
89
136
  );
90
-
91
- const functions: AutoBeRealizeFunction[] = Object.entries(
92
- Object.fromEntries(
93
- writeEvents
94
- .filter((w) => w !== null)
95
- .map((event) => [event.location, event.content]),
96
- ),
97
- ).map(([location, content]) => {
98
- const scenario = scenarios.find((el) => el.location === location)!;
99
137
  return {
100
- location,
101
- content,
102
- endpoint: {
103
- method: scenario.operation.method,
104
- path: scenario.operation.path,
105
- },
106
- name: scenario.functionName,
138
+ corrected,
139
+ validate,
107
140
  };
108
- });
109
-
110
- const reviewProgress: AutoBeProgressEventBase = {
111
- total: writeEvents.length,
112
- completed: writeEvents.length,
113
141
  };
114
142
 
115
- const totalCorrected: AutoBeRealizeFunction[] =
116
- await orchestrateRealizeCorrectCasting(
117
- ctx,
118
- authorizations,
119
- functions,
120
- reviewProgress,
121
- ).then(async (res) => {
122
- return orchestrateRealizeCorrect(
123
- ctx,
124
- scenarios,
125
- authorizations,
126
- res,
127
- [],
128
- reviewProgress,
129
- );
130
- });
143
+ // SCENARIOS
144
+ const entireScenarios: IAutoBeRealizeScenarioResult[] =
145
+ document.operations.map((operation) =>
146
+ generateRealizeScenario(ctx, operation, authorizations),
147
+ );
148
+ let bucket: IBucket = await process(entireScenarios);
149
+ for (let i: number = 0; i < 2; ++i) {
150
+ if (bucket.validate.result.type !== "failure") break;
151
+
152
+ const failedScenarios: IAutoBeRealizeScenarioResult[] = Array.from(
153
+ new Set(bucket.validate.result.diagnostics.map((f) => f.file)),
154
+ )
155
+ .map((location) =>
156
+ bucket.corrected.find((f) => f.location === location),
157
+ )
158
+ .filter((f) => f !== undefined)
159
+ .map((f) =>
160
+ entireScenarios.find(
161
+ (s) =>
162
+ s.operation.path === f.endpoint.path &&
163
+ s.operation.method === f.endpoint.method,
164
+ ),
165
+ )
166
+ .filter((o) => o !== undefined);
167
+ if (failedScenarios.length === 0) break;
168
+
169
+ writeProgress.total += failedScenarios.length;
170
+ correctProgress.total += failedScenarios.length;
171
+
172
+ const newBucket: IBucket = await process(failedScenarios);
173
+ const corrected: Map<string, AutoBeRealizeFunction> = new Map([
174
+ ...bucket.corrected.map((f) => [f.location, f] as const),
175
+ ...newBucket.corrected.map((f) => [f.location, f] as const),
176
+ ]);
177
+ bucket = {
178
+ corrected: Array.from(corrected.values()),
179
+ validate: newBucket.validate,
180
+ };
181
+ }
131
182
 
132
- const compiler: IAutoBeCompiler = await ctx.compiler();
133
183
  const controllers: Record<string, string> =
134
184
  await compiler.realize.controller({
135
185
  document: ctx.state().interface!.document,
136
- functions: totalCorrected,
186
+ functions: bucket.corrected,
137
187
  authorizations,
138
188
  });
139
-
140
- const { result } = await compileRealizeFiles(ctx, {
141
- authorizations,
142
- functions: totalCorrected,
143
- });
144
-
145
189
  return ctx.dispatch({
146
190
  type: "realizeComplete",
147
191
  id: v7(),
148
192
  created_at: new Date().toISOString(),
149
- functions: totalCorrected,
193
+ functions: bucket.corrected,
150
194
  authorizations,
151
195
  controllers,
152
- compiled: result,
196
+ compiled: bucket.validate.result,
153
197
  step: ctx.state().analyze?.step ?? 0,
154
198
  elapsed: new Date().getTime() - start.getTime(),
155
199
  });
156
200
  };
201
+
202
+ interface IBucket {
203
+ corrected: AutoBeRealizeFunction[];
204
+ validate: AutoBeRealizeValidateEvent;
205
+ }
@@ -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,22 +1,30 @@
1
- import { CamelPattern, PascalPattern } from "@autobe/interface";
1
+ import { CamelCasePattern, PascalCasePattern } from "@autobe/interface";
2
2
 
3
3
  export interface IAutoBeRealizeAuthorizationApplication {
4
4
  /**
5
- * Generates authentication provider, decorator, and payload type for role-based authorization.
5
+ * Generates authentication provider, decorator, and payload type for
6
+ * role-based authorization.
6
7
  *
7
8
  * This method creates a complete authentication infrastructure for a specific
8
- * role in the NestJS application. It generates three interconnected components
9
- * that work together to provide JWT-based authentication and authorization.
9
+ * role in the NestJS application. It generates three interconnected
10
+ * components that work together to provide JWT-based authentication and
11
+ * authorization.
10
12
  *
11
13
  * The generated components include:
12
- * - **Provider Function**: Handles JWT verification and user validation from database
13
- * - **Decorator**: NestJS parameter decorator for injecting authenticated user data
14
- * - **Payload Type**: TypeScript interface defining the authenticated user structure
15
14
  *
16
- * All components follow strict naming conventions and integrate with the existing
17
- * authentication architecture using the shared jwtAuthorize function.
15
+ * - **Provider Function**: Handles JWT verification and user validation from
16
+ * database
17
+ * - **Decorator**: NestJS parameter decorator for injecting authenticated user
18
+ * data
19
+ * - **Payload Type**: TypeScript interface defining the authenticated user
20
+ * structure
18
21
  *
19
- * @param next Properties containing provider, decorator, and payload type configurations
22
+ * All components follow strict naming conventions and integrate with the
23
+ * existing authentication architecture using the shared jwtAuthorize
24
+ * function.
25
+ *
26
+ * @param next Properties containing provider, decorator, and payload type
27
+ * configurations
20
28
  */
21
29
  createDecorator: (
22
30
  next: IAutoBeRealizeAuthorizationApplication.IProps,
@@ -60,7 +68,7 @@ export namespace IAutoBeRealizeAuthorizationApplication {
60
68
  *
61
69
  * DO: Use camelCase naming convention.
62
70
  */
63
- name: string & CamelPattern;
71
+ name: string & CamelCasePattern;
64
72
 
65
73
  /**
66
74
  * Complete TypeScript code for the authentication Provider function. Must
@@ -83,7 +91,7 @@ export namespace IAutoBeRealizeAuthorizationApplication {
83
91
  *
84
92
  * DO: Use PascalCase naming convention.
85
93
  */
86
- name: string & PascalPattern;
94
+ name: string & PascalCasePattern;
87
95
 
88
96
  /**
89
97
  * Complete TypeScript code for the authentication Decorator implementation.
@@ -105,7 +113,7 @@ export namespace IAutoBeRealizeAuthorizationApplication {
105
113
  *
106
114
  * DO: Use PascalCase naming convention.
107
115
  */
108
- name: string & PascalPattern;
116
+ name: string & PascalCasePattern;
109
117
 
110
118
  /**
111
119
  * Complete TypeScript code for the Payload type interface in {Role}Payload
@@ -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
  }