@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
@@ -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
  /**
@@ -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,152 @@ 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 props = {
80
+ totalAuthorizations: authorizations,
81
+ authorization: art.decoratorEvent ?? null,
82
+ scenario: art,
83
+ document,
84
+ progress: writeProgress,
85
+ promptCacheKey,
86
+ };
87
+ try {
88
+ return await orchestrateRealizeWrite(ctx, props);
89
+ } catch {
90
+ try {
91
+ return await orchestrateRealizeWrite(ctx, props);
92
+ } catch {
93
+ return null;
94
+ }
95
+ }
96
+ }),
97
+ )
98
+ ).filter((w) => w !== null);
99
+ const functions: AutoBeRealizeFunction[] = Object.entries(
100
+ Object.fromEntries(writes.map((w) => [w.location, w.content])),
101
+ ).map(([location, content]) => {
102
+ const scenario: IAutoBeRealizeScenarioResult = artifacts.find(
103
+ (el) => el.location === location,
104
+ )!;
105
+ return {
106
+ location,
107
+ content,
108
+ endpoint: {
109
+ method: scenario.operation.method,
110
+ path: scenario.operation.path,
111
+ },
112
+ name: scenario.functionName,
113
+ };
114
+ });
115
+ const corrected: AutoBeRealizeFunction[] =
116
+ await orchestrateRealizeCorrectCasting(
117
+ ctx,
118
+ artifacts,
119
+ authorizations,
120
+ functions,
121
+ correctProgress,
122
+ ).then(async (res) => {
123
+ return await orchestrateRealizeCorrect(
124
+ ctx,
125
+ artifacts,
126
+ authorizations,
127
+ res,
128
+ [],
129
+ correctProgress,
130
+ );
131
+ });
132
+ const validate: AutoBeRealizeValidateEvent = await compileRealizeFiles(
133
+ ctx,
134
+ {
135
+ authorizations,
136
+ functions: corrected,
137
+ },
89
138
  );
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
139
  return {
100
- location,
101
- content,
102
- endpoint: {
103
- method: scenario.operation.method,
104
- path: scenario.operation.path,
105
- },
106
- name: scenario.functionName,
140
+ corrected,
141
+ validate,
107
142
  };
108
- });
109
-
110
- const reviewProgress: AutoBeProgressEventBase = {
111
- total: writeEvents.length,
112
- completed: writeEvents.length,
113
143
  };
114
144
 
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
- });
145
+ // SCENARIOS
146
+ const entireScenarios: IAutoBeRealizeScenarioResult[] =
147
+ document.operations.map((operation) =>
148
+ generateRealizeScenario(ctx, operation, authorizations),
149
+ );
150
+ let bucket: IBucket = await process(entireScenarios);
151
+ for (let i: number = 0; i < 2; ++i) {
152
+ if (bucket.validate.result.type !== "failure") break;
153
+
154
+ const failedScenarios: IAutoBeRealizeScenarioResult[] = Array.from(
155
+ new Set(bucket.validate.result.diagnostics.map((f) => f.file)),
156
+ )
157
+ .map((location) =>
158
+ bucket.corrected.find((f) => f.location === location),
159
+ )
160
+ .filter((f) => f !== undefined)
161
+ .map((f) =>
162
+ entireScenarios.find(
163
+ (s) =>
164
+ s.operation.path === f.endpoint.path &&
165
+ s.operation.method === f.endpoint.method,
166
+ ),
167
+ )
168
+ .filter((o) => o !== undefined);
169
+ if (failedScenarios.length === 0) break;
170
+
171
+ writeProgress.total += failedScenarios.length;
172
+ correctProgress.total += failedScenarios.length;
173
+
174
+ const newBucket: IBucket = await process(failedScenarios);
175
+ const corrected: Map<string, AutoBeRealizeFunction> = new Map([
176
+ ...bucket.corrected.map((f) => [f.location, f] as const),
177
+ ...newBucket.corrected.map((f) => [f.location, f] as const),
178
+ ]);
179
+ bucket = {
180
+ corrected: Array.from(corrected.values()),
181
+ validate: newBucket.validate,
182
+ };
183
+ }
131
184
 
132
- const compiler: IAutoBeCompiler = await ctx.compiler();
133
185
  const controllers: Record<string, string> =
134
186
  await compiler.realize.controller({
135
187
  document: ctx.state().interface!.document,
136
- functions: totalCorrected,
188
+ functions: bucket.corrected,
137
189
  authorizations,
138
190
  });
139
-
140
- const { result } = await compileRealizeFiles(ctx, {
141
- authorizations,
142
- functions: totalCorrected,
143
- });
144
-
145
191
  return ctx.dispatch({
146
192
  type: "realizeComplete",
147
193
  id: v7(),
148
194
  created_at: new Date().toISOString(),
149
- functions: totalCorrected,
195
+ functions: bucket.corrected,
150
196
  authorizations,
151
197
  controllers,
152
- compiled: result,
198
+ compiled: bucket.validate.result,
153
199
  step: ctx.state().analyze?.step ?? 0,
154
200
  elapsed: new Date().getTime() - start.getTime(),
155
201
  });
156
202
  };
203
+
204
+ interface IBucket {
205
+ corrected: AutoBeRealizeFunction[];
206
+ validate: AutoBeRealizeValidateEvent;
207
+ }