@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
@@ -0,0 +1,274 @@
1
+ import { IAgenticaController } from "@agentica/core";
2
+ import { AutoBeOpenApi, AutoBeProgressEventBase } from "@autobe/interface";
3
+ import { AutoBeInterfacePrerequisite } from "@autobe/interface/src/histories/contents/AutoBeInterfacePrerequisite";
4
+ import { AutoBeOpenApiEndpointComparator } from "@autobe/utils";
5
+ import { ILlmApplication, ILlmSchema, IValidation } from "@samchon/openapi";
6
+ import { HashMap, IPointer, Pair } from "tstl";
7
+ import typia from "typia";
8
+ import { v7 } from "uuid";
9
+
10
+ import { AutoBeConfigConstant } from "../../constants/AutoBeConfigConstant";
11
+ import { AutoBeContext } from "../../context/AutoBeContext";
12
+ import { assertSchemaModel } from "../../context/assertSchemaModel";
13
+ import { divideArray } from "../../utils/divideArray";
14
+ import { executeCachedBatch } from "../../utils/executeCachedBatch";
15
+ import { transformInterfacePrerequisitesHistories } from "./histories/transformInterfacePrerequisitesHistories";
16
+ import { IAutoBeInterfacePrerequisitesApplication } from "./structures/IAutoBeInterfacePrerequisitesApplication";
17
+
18
+ export async function orchestrateInterfacePrerequisites<
19
+ Model extends ILlmSchema.Model,
20
+ >(
21
+ ctx: AutoBeContext<Model>,
22
+ document: AutoBeOpenApi.IDocument,
23
+ capacity: number = AutoBeConfigConstant.INTERFACE_CAPACITY,
24
+ ): Promise<AutoBeInterfacePrerequisite[]> {
25
+ const operations: AutoBeOpenApi.IOperation[] =
26
+ document.operations.filter((op) => op.authorizationType === null) ?? [];
27
+ const progress: AutoBeProgressEventBase = {
28
+ total: operations.length,
29
+ completed: 0,
30
+ };
31
+ const prerequisiteOperations: AutoBeOpenApi.IOperation[] =
32
+ document.operations.filter(
33
+ (op) => op.authorizationType === null && op.method === "post",
34
+ );
35
+
36
+ const dict: HashMap<AutoBeOpenApi.IEndpoint, AutoBeOpenApi.IOperation> =
37
+ new HashMap<AutoBeOpenApi.IEndpoint, AutoBeOpenApi.IOperation>(
38
+ prerequisiteOperations.map(
39
+ (op) => new Pair({ path: op.path, method: op.method }, op),
40
+ ),
41
+ AutoBeOpenApiEndpointComparator.hashCode,
42
+ AutoBeOpenApiEndpointComparator.equals,
43
+ );
44
+
45
+ const prerequisitesNotFound: string = [
46
+ `You have to select one of the endpoints below`,
47
+ "",
48
+ " method | path ",
49
+ "--------|------",
50
+ ...prerequisiteOperations
51
+ .map((op) => `\`${op.method}\` | \`${op.path}\``)
52
+ .join("\n"),
53
+ ].join("\n");
54
+
55
+ const exclude: AutoBeInterfacePrerequisite[] = [];
56
+ let include: AutoBeOpenApi.IOperation[] = [...operations];
57
+ let trial: number = 0;
58
+
59
+ do {
60
+ const matrix: AutoBeOpenApi.IOperation[][] = divideArray({
61
+ array: include,
62
+ capacity: capacity ?? AutoBeConfigConstant.INTERFACE_CAPACITY,
63
+ });
64
+
65
+ await executeCachedBatch(
66
+ matrix.map((ops) => async (promptCacheKey) => {
67
+ const row: AutoBeInterfacePrerequisite[] = await divideAndConquer(ctx, {
68
+ dict: dict,
69
+ document,
70
+ includes: ops,
71
+ progress,
72
+ promptCacheKey,
73
+ prerequisitesNotFound,
74
+ });
75
+ exclude.push(...row);
76
+ return row;
77
+ }),
78
+ );
79
+ include = include.filter((op) => {
80
+ if (
81
+ exclude.some(
82
+ (el) =>
83
+ el.endpoint.method === op.method && el.endpoint.path === op.path,
84
+ )
85
+ ) {
86
+ return false;
87
+ }
88
+ return true;
89
+ });
90
+ } while (include.length > 0 && ++trial < ctx.retry);
91
+ return exclude;
92
+ }
93
+
94
+ async function divideAndConquer<Model extends ILlmSchema.Model>(
95
+ ctx: AutoBeContext<Model>,
96
+ props: {
97
+ dict: HashMap<AutoBeOpenApi.IEndpoint, AutoBeOpenApi.IOperation>;
98
+ document: AutoBeOpenApi.IDocument;
99
+ includes: AutoBeOpenApi.IOperation[];
100
+ progress: AutoBeProgressEventBase;
101
+ promptCacheKey: string;
102
+ prerequisitesNotFound: string;
103
+ },
104
+ ): Promise<AutoBeInterfacePrerequisite[]> {
105
+ const pointer: IPointer<AutoBeInterfacePrerequisite[] | null> = {
106
+ value: null,
107
+ };
108
+
109
+ try {
110
+ const { tokenUsage } = await ctx.conversate({
111
+ source: "interfacePrerequisites",
112
+ controller: createController({
113
+ model: ctx.model,
114
+ document: props.document,
115
+ dict: props.dict,
116
+ includes: props.includes,
117
+ prerequisitesNotFound: props.prerequisitesNotFound,
118
+ build: (next) => {
119
+ pointer.value = next;
120
+ },
121
+ }),
122
+ histories: transformInterfacePrerequisitesHistories(
123
+ props.document,
124
+ props.includes,
125
+ ),
126
+ enforceFunctionCall: true,
127
+ promptCacheKey: props.promptCacheKey,
128
+ message: "Create prerequisite for the given operations",
129
+ });
130
+ if (pointer.value === null) return [];
131
+
132
+ props.progress.completed += pointer.value.length;
133
+ ctx.dispatch({
134
+ type: "interfacePrerequisites",
135
+ id: v7(),
136
+ created_at: new Date().toISOString(),
137
+ tokenUsage,
138
+ operations: pointer.value,
139
+ total: props.progress.total,
140
+ completed: props.progress.completed,
141
+ step: ctx.state().prisma?.step ?? 0,
142
+ });
143
+ return pointer.value;
144
+ } catch {
145
+ props.progress.completed += props.includes.length;
146
+ return [];
147
+ }
148
+ }
149
+
150
+ function createController<Model extends ILlmSchema.Model>(props: {
151
+ model: Model;
152
+ document: AutoBeOpenApi.IDocument;
153
+ dict: HashMap<AutoBeOpenApi.IEndpoint, AutoBeOpenApi.IOperation>;
154
+ includes: AutoBeOpenApi.IOperation[];
155
+ prerequisitesNotFound: string;
156
+ build: (next: AutoBeInterfacePrerequisite[]) => void;
157
+ }): IAgenticaController.IClass<Model> {
158
+ assertSchemaModel(props.model);
159
+
160
+ const validate = (
161
+ next: unknown,
162
+ ): IValidation<IAutoBeInterfacePrerequisitesApplication.IProps> => {
163
+ const result: IValidation<IAutoBeInterfacePrerequisitesApplication.IProps> =
164
+ typia.validate<IAutoBeInterfacePrerequisitesApplication.IProps>(next);
165
+ if (result.success === false) return result;
166
+
167
+ const operations: AutoBeInterfacePrerequisite[] = result.data.operations;
168
+ const filteredOperations: AutoBeInterfacePrerequisite[] = [];
169
+ const errors: IValidation.IError[] = [];
170
+
171
+ props.includes.forEach((el) => {
172
+ // Find the matched operation in the includes
173
+ const matched: AutoBeInterfacePrerequisite | undefined = operations.find(
174
+ (op) =>
175
+ op.endpoint.method === el.method && op.endpoint.path === el.path,
176
+ );
177
+
178
+ // Remove duplicate operations in Prerequisites
179
+ if (matched) {
180
+ const prerequisites: Map<string, AutoBeOpenApi.IPrerequisite> =
181
+ new Map();
182
+ matched.prerequisites.forEach((op) => {
183
+ if (
184
+ prerequisites.get(op.endpoint.method + op.endpoint.path) !==
185
+ undefined
186
+ ) {
187
+ return;
188
+ }
189
+ prerequisites.set(op.endpoint.method + op.endpoint.path, op);
190
+ });
191
+ matched.prerequisites = Array.from(prerequisites.values());
192
+ filteredOperations.push(matched);
193
+ }
194
+ });
195
+
196
+ filteredOperations.forEach((op, i) => {
197
+ op.prerequisites.forEach((p, j) => {
198
+ if (props.dict.has(p.endpoint) === false) {
199
+ errors.push({
200
+ value: p.endpoint,
201
+ path: `$input.operations[${i}].prerequisites[${j}].endpoint`,
202
+ expected: "AutoBeOpenApi.IEndpoint",
203
+ description: props.prerequisitesNotFound,
204
+ });
205
+ }
206
+
207
+ if (
208
+ p.endpoint.method === op.endpoint.method &&
209
+ p.endpoint.path === op.endpoint.path
210
+ ) {
211
+ errors.push({
212
+ value: p.endpoint,
213
+ path: `$input.operations[${i}].prerequisites[${j}].endpoint`,
214
+ expected: "AutoBeOpenApi.IEndpoint",
215
+ description: "Self-reference is not allowed.",
216
+ });
217
+ }
218
+ });
219
+ });
220
+
221
+ return errors.length === 0
222
+ ? {
223
+ ...result,
224
+ data: {
225
+ ...result.data,
226
+ operations: filteredOperations,
227
+ },
228
+ }
229
+ : {
230
+ success: false,
231
+ data: {
232
+ ...result.data,
233
+ operations: filteredOperations,
234
+ },
235
+ errors,
236
+ };
237
+ };
238
+
239
+ const application: ILlmApplication<Model> = collection[
240
+ props.model === "chatgpt" ? "chatgpt" : "claude"
241
+ ](
242
+ validate,
243
+ ) satisfies ILlmApplication<any> as unknown as ILlmApplication<Model>;
244
+
245
+ return {
246
+ protocol: "class",
247
+ name: "interface",
248
+ application,
249
+ execute: {
250
+ makePrerequisite: (next) => {
251
+ props.build(next.operations);
252
+ },
253
+ } satisfies IAutoBeInterfacePrerequisitesApplication,
254
+ };
255
+ }
256
+
257
+ const collection = {
258
+ chatgpt: (validate: Validator) =>
259
+ typia.llm.application<IAutoBeInterfacePrerequisitesApplication, "chatgpt">({
260
+ validate: {
261
+ makePrerequisite: validate,
262
+ },
263
+ }),
264
+ claude: (validate: Validator) =>
265
+ typia.llm.application<IAutoBeInterfacePrerequisitesApplication, "claude">({
266
+ validate: {
267
+ makePrerequisite: validate,
268
+ },
269
+ }),
270
+ };
271
+
272
+ type Validator = (
273
+ input: unknown,
274
+ ) => IValidation<IAutoBeInterfacePrerequisitesApplication.IProps>;
@@ -205,7 +205,7 @@ function createController<Model extends ILlmSchema.Model>(props: {
205
205
  const validate = (
206
206
  next: unknown,
207
207
  ): IValidation<IAutoBeInterfaceSchemaApplication.IProps> => {
208
- JsonSchemaFactory.fix("schemas", next);
208
+ JsonSchemaFactory.fixPage("schemas", next);
209
209
 
210
210
  const result: IValidation<IAutoBeInterfaceSchemaApplication.IProps> =
211
211
  typia.validate<IAutoBeInterfaceSchemaApplication.IProps>(next);
@@ -140,7 +140,7 @@ function createController<Model extends ILlmSchema.Model>(props: {
140
140
  const validate = (
141
141
  next: unknown,
142
142
  ): IValidation<IAutoBeInterfaceSchemasReviewApplication.IProps> => {
143
- JsonSchemaFactory.fix("content", next);
143
+ JsonSchemaFactory.fixPage("content", next);
144
144
 
145
145
  const result: IValidation<IAutoBeInterfaceSchemasReviewApplication.IProps> =
146
146
  typia.validate<IAutoBeInterfaceSchemasReviewApplication.IProps>(next);
@@ -20,45 +20,6 @@ export interface IAutoBeInterfaceComplementApplication {
20
20
  }
21
21
  export namespace IAutoBeInterfaceComplementApplication {
22
22
  export interface IProps {
23
- /**
24
- * TypeScript draft code for complement schema definitions.
25
- *
26
- * This property contains TypeScript interface definitions for missing schema
27
- * types that were referenced but not defined in the initial schema generation.
28
- * Similar to the main schema draft, this serves as a preliminary TypeScript
29
- * representation before converting to JSON Schema format.
30
- *
31
- * The draft helps ensure that complementary schemas maintain consistency with
32
- * the existing type system and follow the same conventions as the primary schemas.
33
- *
34
- * This draft typically includes:
35
- * - Missing entity interfaces referenced via $ref
36
- * - Nested object types used within other schemas
37
- * - Shared utility types or enumerations
38
- * - Any transitively referenced types
39
- *
40
- * The final schemas in the `schemas` property should be validated against and
41
- * derived from this TypeScript draft to ensure type safety and consistency
42
- * across the entire API specification.
43
- *
44
- * Example complement draft:
45
- * ```typescript
46
- * interface IUserProfile {
47
- * id: string;
48
- * userId: string;
49
- * displayName: string;
50
- * avatarUrl?: string;
51
- * }
52
- *
53
- * interface IAddress {
54
- * street: string;
55
- * city: string;
56
- * postalCode: string;
57
- * }
58
- * ```
59
- */
60
- draft: string;
61
-
62
23
  /**
63
24
  * A collection of missing schema definitions that need to be added to the
64
25
  * OpenAPI document's `components.schemas` section.
@@ -94,18 +94,14 @@ export namespace IAutoBeInterfaceGroupApplication {
94
94
  name: string & tags.MinLength<1>;
95
95
 
96
96
  /**
97
- * Comprehensive description of the group's scope, schema foundation, and
98
- * purpose.
97
+ * Concise description of the group's core purpose.
99
98
  *
100
- * **Required Content:**
99
+ * **Requirements:**
100
+ * - Keep it brief and focused (50-200 characters)
101
+ * - State the main purpose and key entities
102
+ * - Avoid detailed explanations or mappings
101
103
  *
102
- * 1. Schema Foundation: Identify the Prisma schema elements defining this
103
- * group
104
- * 2. Database Entities: List specific tables and entities from the schema
105
- * 3. Functional Scope: Detail operations and workflows for schema entities
106
- * 4. Schema Relationships: Describe table relationships and dependencies
107
- * 5. Key Operations: Outline main operation types (CRUD, business processes)
108
- * 6. Requirements Mapping: Explain how requirements map to schema entities
104
+ * Example: "Handles shopping-related entities and operations"
109
105
  */
110
106
  description: string & tags.MinLength<1>;
111
107
  }
@@ -1,4 +1,4 @@
1
- import { AutoBeOpenApi, CamelPattern } from "@autobe/interface";
1
+ import { AutoBeOpenApi, CamelCasePattern } from "@autobe/interface";
2
2
  import { tags } from "typia";
3
3
 
4
4
  export interface IAutoBeInterfaceOperationApplication {
@@ -86,8 +86,7 @@ export namespace IAutoBeInterfaceOperationApplication {
86
86
  * }
87
87
  * ```
88
88
  */
89
- export interface IOperation
90
- extends AutoBeOpenApi.IEndpoint {
89
+ export interface IOperation extends AutoBeOpenApi.IEndpoint {
91
90
  /**
92
91
  * Specification of the API operation.
93
92
  *
@@ -339,7 +338,7 @@ export namespace IAutoBeInterfaceOperationApplication {
339
338
  * operations can be uniquely identified in generated SDKs and prevents
340
339
  * naming conflicts.
341
340
  */
342
- name: string & CamelPattern;
341
+ name: string & CamelCasePattern;
343
342
 
344
343
  /**
345
344
  * Authorization roles required to access this API operation.
@@ -422,6 +421,6 @@ export namespace IAutoBeInterfaceOperationApplication {
422
421
  * handled by decorators at the controller level, and the provider function
423
422
  * will receive the authenticated user object with the appropriate type.
424
423
  */
425
- authorizationRoles: Array<string & CamelPattern & tags.MinLength<1>>;
424
+ authorizationRoles: Array<string & CamelCasePattern & tags.MinLength<1>>;
426
425
  }
427
426
  }
@@ -0,0 +1,58 @@
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+
3
+ /**
4
+ * Interface Prerequisite Agent application for analyzing and generating API
5
+ * operation dependencies.
6
+ *
7
+ * Analyzes Target Operations to determine which Available API Operations must
8
+ * be executed as prerequisites based on resource creation dependencies and
9
+ * existence validations.
10
+ */
11
+ export interface IAutoBeInterfacePrerequisitesApplication {
12
+ /**
13
+ * Generate prerequisites for the provided operations.
14
+ *
15
+ * Analyzes each operation's dependencies and returns the complete list with
16
+ * their required prerequisite chains based on resource relationships.
17
+ */
18
+ makePrerequisite(
19
+ props: IAutoBeInterfacePrerequisitesApplication.IProps,
20
+ ): void;
21
+ }
22
+
23
+ export namespace IAutoBeInterfacePrerequisitesApplication {
24
+ export interface IProps {
25
+ /**
26
+ * Target operations requiring prerequisite analysis.
27
+ *
28
+ * Each operation will be analyzed for dependency requirements and returned
29
+ * with appropriate prerequisites from Available API Operations.
30
+ */
31
+ operations: IOperation[];
32
+ }
33
+
34
+ /**
35
+ * Operation with its analyzed prerequisite dependencies.
36
+ *
37
+ * Represents a single API operation and its complete prerequisite chain
38
+ * needed for successful execution.
39
+ */
40
+ export interface IOperation {
41
+ /**
42
+ * The API endpoint being analyzed.
43
+ *
44
+ * Identifies the specific operation (method + path) that needs
45
+ * prerequisites.
46
+ */
47
+ endpoint: AutoBeOpenApi.IEndpoint;
48
+
49
+ /**
50
+ * Required prerequisite operations.
51
+ *
52
+ * List of API operations that must be successfully executed before this
53
+ * operation can be performed. Based on resource creation dependencies and
54
+ * existence validations from the analysis.
55
+ */
56
+ prerequisites: AutoBeOpenApi.IPrerequisite[];
57
+ }
58
+ }
@@ -24,40 +24,6 @@ export interface IAutoBeInterfaceSchemaApplication {
24
24
  }
25
25
  export namespace IAutoBeInterfaceSchemaApplication {
26
26
  export interface IProps {
27
- /**
28
- * TypeScript draft code for schema definitions.
29
- *
30
- * This property contains TypeScript interface definitions that serve as a
31
- * preliminary draft before generating the final JSON schema components.
32
- * The draft allows for initial design and validation of the schema structure
33
- * using TypeScript's type system before converting to OpenAPI/JSON Schema format.
34
- *
35
- * The draft typically includes:
36
- * - Entity interfaces matching the Prisma models
37
- * - Operation-specific variants (ICreate, IUpdate, etc.)
38
- * - Utility types and enumerations
39
- * - Type relationships and constraints
40
- *
41
- * This TypeScript draft serves as the foundation for the subsequent schema
42
- * generation, ensuring type safety and consistency. The final schemas in the
43
- * `schemas` property should be derived from and validated against this draft.
44
- *
45
- * Example draft structure:
46
- * ```typescript
47
- * interface IUser {
48
- * id: string;
49
- * email: string;
50
- * profile: IUserProfile;
51
- * }
52
- *
53
- * namespace IUser {
54
- * interface ICreate extends Omit<IUser, "id"> {}
55
- * interface IUpdate extends Partial<ICreate> {}
56
- * }
57
- * ```
58
- */
59
- draft: string;
60
-
61
27
  /**
62
28
  * Complete set of schema components for the OpenAPI specification.
63
29
  *
@@ -1,8 +1,12 @@
1
- import { AutoBeOpenApi } from "@autobe/interface";
1
+ import { AutoBeOpenApi, AutoBePrisma } from "@autobe/interface";
2
2
  import { AutoBeOpenApiTypeChecker, StringUtil } from "@autobe/utils";
3
+ import { OpenApiTypeChecker } from "@samchon/openapi";
3
4
  import typia, { tags } from "typia";
4
5
 
5
6
  export namespace JsonSchemaFactory {
7
+ /* -----------------------------------------------------------
8
+ ASSIGNMENTS
9
+ ----------------------------------------------------------- */
6
10
  export const presets = (
7
11
  typeNames: Set<string>,
8
12
  ): Record<string, AutoBeOpenApi.IJsonSchemaDescriptive> => {
@@ -44,6 +48,77 @@ export namespace JsonSchemaFactory {
44
48
  }
45
49
  };
46
50
 
51
+ export const finalize = (props: {
52
+ document: AutoBeOpenApi.IDocument;
53
+ application: AutoBePrisma.IApplication;
54
+ }): void => {
55
+ removeUnused(props.document);
56
+ fixTimestamps(props);
57
+ };
58
+
59
+ const removeUnused = (document: AutoBeOpenApi.IDocument): void => {
60
+ const used: Set<string> = new Set();
61
+ const visit = (schema: AutoBeOpenApi.IJsonSchema): void =>
62
+ OpenApiTypeChecker.visit({
63
+ components: { schemas: document.components.schemas },
64
+ schema,
65
+ closure: (next) => {
66
+ if (OpenApiTypeChecker.isReference(next)) {
67
+ const key: string = next.$ref.split("/").pop()!;
68
+ used.add(key);
69
+ }
70
+ },
71
+ });
72
+
73
+ for (const op of document.operations) {
74
+ if (op.requestBody !== null)
75
+ visit({
76
+ $ref: `#/components/schemas/${op.requestBody.typeName}`,
77
+ });
78
+ if (op.responseBody !== null)
79
+ visit({
80
+ $ref: `#/components/schemas/${op.responseBody.typeName}`,
81
+ });
82
+ }
83
+ for (const key of Object.keys(document.components.schemas))
84
+ if (used.has(key) === false) delete document.components.schemas[key];
85
+ };
86
+
87
+ const fixTimestamps = (props: {
88
+ document: AutoBeOpenApi.IDocument;
89
+ application: AutoBePrisma.IApplication;
90
+ }): void => {
91
+ const entireModels: AutoBePrisma.IModel[] = props.application.files
92
+ .map((f) => f.models)
93
+ .flat();
94
+ for (const value of Object.values(props.document.components.schemas)) {
95
+ if (AutoBeOpenApiTypeChecker.isObject(value) === false) continue;
96
+
97
+ const model: AutoBePrisma.IModel | undefined = value[
98
+ "x-autobe-prisma-schema"
99
+ ]
100
+ ? entireModels.find((m) => m.name === value["x-autobe-prisma-schema"])
101
+ : undefined;
102
+ if (model === undefined) continue;
103
+
104
+ const properties: string[] = Object.keys(value.properties);
105
+ for (const key of properties) {
106
+ if (
107
+ key !== "created_at" &&
108
+ key !== "updated_at" &&
109
+ key !== "deleted_at"
110
+ )
111
+ continue;
112
+ const column: AutoBePrisma.IPlainField | undefined =
113
+ model.plainFields.find((c) => c.name === key);
114
+ if (column === undefined) delete value.properties[key];
115
+ }
116
+ }
117
+ };
118
+
119
+ /* -----------------------------------------------------------
120
+ PAGINATION
121
+ ----------------------------------------------------------- */
47
122
  export const page = (
48
123
  key: string,
49
124
  ): AutoBeOpenApi.IJsonSchemaDescriptive.IObject => ({
@@ -69,7 +144,7 @@ export namespace JsonSchemaFactory {
69
144
  `,
70
145
  });
71
146
 
72
- export const fix = (path: string, input: unknown): void => {
147
+ export const fixPage = (path: string, input: unknown): void => {
73
148
  if (isRecord(input) === false || isRecord(input[path]) === false) return;
74
149
 
75
150
  if (input[path].description) delete input[path].description;
@@ -99,8 +174,8 @@ export namespace JsonSchemaFactory {
99
174
  const DEFAULT_SCHEMAS = typia.assertEquals<
100
175
  Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>
101
176
  >(
102
- typia.json.schemas<[IPage.IPagination, IAuthorizationToken]>().components
103
- ?.schemas,
177
+ typia.json.schemas<[IPage.IPagination, IPage.IRequest, IAuthorizationToken]>()
178
+ .components?.schemas,
104
179
  );
105
180
 
106
181
  namespace IPage {
@@ -122,6 +197,19 @@ namespace IPage {
122
197
  */
123
198
  pages: number & tags.Type<"uint32">;
124
199
  }
200
+
201
+ /** Page request data */
202
+ export interface IRequest {
203
+ /** Page number. */
204
+ page?: null | (number & tags.Type<"uint32">);
205
+
206
+ /**
207
+ * Limitation of records per a page.
208
+ *
209
+ * @default 100
210
+ */
211
+ limit?: null | (number & tags.Type<"uint32">);
212
+ }
125
213
  }
126
214
 
127
215
  /**