@autobe/agent 0.14.6 → 0.15.0

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 (152) hide show
  1. package/lib/AutoBeMockAgent.js +1 -1
  2. package/lib/AutoBeMockAgent.js.map +1 -1
  3. package/lib/constants/AutoBeSystemPromptConstant.d.ts +10 -8
  4. package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
  5. package/lib/index.mjs +1276 -834
  6. package/lib/index.mjs.map +1 -1
  7. package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js +4 -9
  8. package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js.map +1 -1
  9. package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js +2 -8
  10. package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js.map +1 -1
  11. package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js +1 -1
  12. package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js.map +1 -1
  13. package/lib/orchestrate/analyze/transformAnalyzeWriteHistories.js +1 -1
  14. package/lib/orchestrate/analyze/transformAnalyzeWriteHistories.js.map +1 -1
  15. package/lib/orchestrate/interface/histories/transformInterfaceAssetHistories.d.ts +3 -0
  16. package/lib/orchestrate/interface/histories/transformInterfaceAssetHistories.js +65 -0
  17. package/lib/orchestrate/interface/histories/transformInterfaceAssetHistories.js.map +1 -0
  18. package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.d.ts +4 -0
  19. package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js +62 -0
  20. package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js.map +1 -0
  21. package/lib/orchestrate/interface/histories/transformInterfaceEndpointHistories.d.ts +4 -0
  22. package/lib/orchestrate/interface/histories/transformInterfaceEndpointHistories.js +28 -0
  23. package/lib/orchestrate/interface/histories/transformInterfaceEndpointHistories.js.map +1 -0
  24. package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.d.ts +3 -0
  25. package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js +28 -0
  26. package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js.map +1 -0
  27. package/lib/orchestrate/interface/histories/transformInterfaceOperationHistories.d.ts +4 -0
  28. package/lib/orchestrate/interface/histories/transformInterfaceOperationHistories.js +28 -0
  29. package/lib/orchestrate/interface/histories/transformInterfaceOperationHistories.js.map +1 -0
  30. package/lib/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.d.ts +3 -0
  31. package/lib/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.js +63 -0
  32. package/lib/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.js.map +1 -0
  33. package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.d.ts +4 -0
  34. package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js +28 -0
  35. package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js.map +1 -0
  36. package/lib/orchestrate/interface/orchestrateInterface.js +14 -9
  37. package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
  38. package/lib/orchestrate/interface/orchestrateInterfaceComplement.d.ts +1 -1
  39. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +13 -40
  40. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
  41. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.d.ts +3 -2
  42. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +52 -32
  43. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
  44. package/lib/orchestrate/interface/orchestrateInterfaceGroups.d.ts +4 -0
  45. package/lib/orchestrate/interface/orchestrateInterfaceGroups.js +350 -0
  46. package/lib/orchestrate/interface/orchestrateInterfaceGroups.js.map +1 -0
  47. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +249 -225
  48. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
  49. package/lib/orchestrate/interface/orchestrateInterfaceSchemas.d.ts +4 -0
  50. package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js +411 -0
  51. package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js.map +1 -0
  52. package/lib/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.d.ts +55 -0
  53. package/lib/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.js +3 -0
  54. package/lib/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.js.map +1 -0
  55. package/lib/orchestrate/interface/structures/IAutoBeInterfaceEndpointApplication.d.ts +23 -0
  56. package/lib/orchestrate/interface/structures/IAutoBeInterfaceEndpointApplication.js +3 -0
  57. package/lib/orchestrate/interface/structures/IAutoBeInterfaceEndpointApplication.js.map +1 -0
  58. package/lib/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.d.ts +108 -0
  59. package/lib/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.js +3 -0
  60. package/lib/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.js.map +1 -0
  61. package/lib/orchestrate/interface/structures/IAutoBeInterfaceOperationApplication.d.ts +122 -0
  62. package/lib/orchestrate/interface/structures/IAutoBeInterfaceOperationApplication.js +3 -0
  63. package/lib/orchestrate/interface/structures/IAutoBeInterfaceOperationApplication.js.map +1 -0
  64. package/lib/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.d.ts +75 -0
  65. package/lib/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.js +3 -0
  66. package/lib/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.js.map +1 -0
  67. package/lib/orchestrate/interface/{OpenApiEndpointComparator.d.ts → utils/OpenApiEndpointComparator.d.ts} +1 -0
  68. package/lib/orchestrate/interface/{OpenApiEndpointComparator.js → utils/OpenApiEndpointComparator.js} +6 -0
  69. package/lib/orchestrate/interface/utils/OpenApiEndpointComparator.js.map +1 -0
  70. package/lib/orchestrate/realize/orchestrateRealize.js +16 -2
  71. package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
  72. package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js +5 -7
  73. package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js.map +1 -1
  74. package/lib/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.js +2 -2
  75. package/lib/orchestrate/realize/orchestrateRealizeCoder.js +3 -2
  76. package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -1
  77. package/lib/orchestrate/realize/structures/IAutoBeRealizeAuthorizationCorrectApplication.d.ts +1 -1
  78. package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.d.ts +34 -13
  79. package/lib/orchestrate/realize/transformRealizeAuthorization.js +1 -1
  80. package/lib/orchestrate/realize/transformRealizeAuthorization.js.map +1 -1
  81. package/lib/orchestrate/realize/transformRealizeAuthorizationCorrectHistories.js +1 -1
  82. package/lib/orchestrate/realize/transformRealizeAuthorizationCorrectHistories.js.map +1 -1
  83. package/lib/orchestrate/realize/transformRealizeCoderHistories.js +5 -5
  84. package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -1
  85. package/lib/orchestrate/realize/utils/InternalFileSystem.d.ts +8 -0
  86. package/lib/orchestrate/realize/utils/InternalFileSystem.js +17 -0
  87. package/lib/orchestrate/realize/utils/InternalFileSystem.js.map +1 -0
  88. package/lib/orchestrate/realize/utils/ProviderFileSystem.d.ts +3 -0
  89. package/lib/orchestrate/realize/utils/ProviderFileSystem.js +8 -0
  90. package/lib/orchestrate/realize/utils/ProviderFileSystem.js.map +1 -0
  91. package/lib/orchestrate/realize/utils/replaceImportStatements.js +2 -2
  92. package/lib/orchestrate/realize/utils/replaceImportStatements.js.map +1 -1
  93. package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js +36 -36
  94. package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js.map +1 -1
  95. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js +1 -0
  96. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js.map +1 -1
  97. package/lib/orchestrate/test/orchestrateTestScenario.js +29 -13
  98. package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
  99. package/lib/orchestrate/test/transformTestWriteHistories.js +3 -2
  100. package/lib/orchestrate/test/transformTestWriteHistories.js.map +1 -1
  101. package/lib/utils/arrayToRecord.d.ts +17 -0
  102. package/lib/utils/arrayToRecord.js +19 -0
  103. package/lib/utils/arrayToRecord.js.map +1 -0
  104. package/lib/utils/backoffRetry.js +0 -1
  105. package/lib/utils/backoffRetry.js.map +1 -1
  106. package/package.json +5 -5
  107. package/src/AutoBeMockAgent.ts +1 -1
  108. package/src/constants/AutoBeSystemPromptConstant.ts +10 -8
  109. package/src/orchestrate/analyze/orchestrateAnalyzeReviewer.ts +1 -3
  110. package/src/orchestrate/analyze/orchestrateAnalyzeWrite.ts +1 -3
  111. package/src/orchestrate/interface/histories/transformInterfaceAssetHistories.ts +75 -0
  112. package/src/orchestrate/interface/histories/transformInterfaceComplementHistories.ts +69 -0
  113. package/src/orchestrate/interface/histories/transformInterfaceEndpointHistories.ts +34 -0
  114. package/src/orchestrate/interface/histories/transformInterfaceGroupHistories.ts +32 -0
  115. package/src/orchestrate/interface/histories/transformInterfaceOperationHistories.ts +34 -0
  116. package/src/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.ts +66 -0
  117. package/src/orchestrate/interface/histories/transformInterfaceSchemaHistories.ts +34 -0
  118. package/src/orchestrate/interface/orchestrateInterface.ts +17 -8
  119. package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +22 -97
  120. package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +48 -55
  121. package/src/orchestrate/interface/orchestrateInterfaceGroups.ts +109 -0
  122. package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +81 -120
  123. package/src/orchestrate/interface/orchestrateInterfaceSchemas.ts +197 -0
  124. package/src/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.ts +58 -0
  125. package/src/orchestrate/interface/structures/IAutoBeInterfaceEndpointApplication.ts +24 -0
  126. package/src/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.ts +112 -0
  127. package/src/orchestrate/interface/structures/IAutoBeInterfaceOperationApplication.ts +125 -0
  128. package/src/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.ts +76 -0
  129. package/src/orchestrate/interface/{OpenApiEndpointComparator.ts → utils/OpenApiEndpointComparator.ts} +8 -0
  130. package/src/orchestrate/realize/orchestrateRealize.ts +19 -2
  131. package/src/orchestrate/realize/orchestrateRealizeAuthorization.ts +6 -19
  132. package/src/orchestrate/realize/orchestrateRealizeCoder.ts +3 -6
  133. package/src/orchestrate/realize/structures/IAutoBeRealizeAuthorizationCorrectApplication.ts +1 -1
  134. package/src/orchestrate/realize/structures/IAutoBeRealizeCompile.ts +42 -24
  135. package/src/orchestrate/realize/transformRealizeCoderHistories.ts +4 -4
  136. package/src/orchestrate/realize/utils/InternalFileSystem.ts +12 -0
  137. package/src/orchestrate/realize/utils/ProviderFileSystem.ts +4 -0
  138. package/src/orchestrate/realize/utils/replaceImportStatements.ts +2 -2
  139. package/src/orchestrate/realize/writeCodeUntilCompilePassed.ts +59 -53
  140. package/src/orchestrate/test/compile/getTestScenarioArtifacts.ts +1 -0
  141. package/src/orchestrate/test/orchestrateTestScenario.ts +4 -2
  142. package/src/utils/arrayToRecord.ts +49 -0
  143. package/src/utils/backoffRetry.ts +0 -1
  144. package/lib/orchestrate/interface/OpenApiEndpointComparator.js.map +0 -1
  145. package/lib/orchestrate/interface/orchestrateInterfaceComponents.d.ts +0 -4
  146. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +0 -473
  147. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +0 -1
  148. package/lib/orchestrate/interface/transformInterfaceHistories.d.ts +0 -3
  149. package/lib/orchestrate/interface/transformInterfaceHistories.js +0 -149
  150. package/lib/orchestrate/interface/transformInterfaceHistories.js.map +0 -1
  151. package/src/orchestrate/interface/orchestrateInterfaceComponents.ts +0 -292
  152. package/src/orchestrate/interface/transformInterfaceHistories.ts +0 -152
@@ -0,0 +1,197 @@
1
+ import { IAgenticaController, MicroAgentica } from "@agentica/core";
2
+ import { AutoBeOpenApi } from "@autobe/interface";
3
+ import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
4
+ import { OpenApiV3_1Emender } from "@samchon/openapi/lib/converters/OpenApiV3_1Emender";
5
+ import { IPointer } from "tstl";
6
+ import typia from "typia";
7
+
8
+ import { AutoBeContext } from "../../context/AutoBeContext";
9
+ import { assertSchemaModel } from "../../context/assertSchemaModel";
10
+ import { divideArray } from "../../utils/divideArray";
11
+ import { enforceToolCall } from "../../utils/enforceToolCall";
12
+ import { forceRetry } from "../../utils/forceRetry";
13
+ import { transformInterfaceSchemaHistories } from "./histories/transformInterfaceSchemaHistories";
14
+ import { IAutoBeInterfaceSchemaApplication } from "./structures/IAutoBeInterfaceSchemaApplication";
15
+
16
+ export async function orchestrateInterfaceSchemas<
17
+ Model extends ILlmSchema.Model,
18
+ >(
19
+ ctx: AutoBeContext<Model>,
20
+ operations: AutoBeOpenApi.IOperation[],
21
+ capacity: number = 12,
22
+ ): Promise<Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>> {
23
+ const typeNames: Set<string> = new Set();
24
+ for (const op of operations) {
25
+ if (op.requestBody !== null) typeNames.add(op.requestBody.typeName);
26
+ if (op.responseBody !== null) typeNames.add(op.responseBody.typeName);
27
+ }
28
+ const matrix: string[][] = divideArray({
29
+ array: Array.from(typeNames),
30
+ capacity,
31
+ });
32
+ let progress: number = 0;
33
+
34
+ const x: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive> = {};
35
+ for (const y of await Promise.all(
36
+ matrix.map(async (it) => {
37
+ const row: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive> =
38
+ await divideAndConquer(ctx, operations, it, 3, (count) => {
39
+ progress += count;
40
+ });
41
+ ctx.dispatch({
42
+ type: "interfaceSchemas",
43
+ schemas: row,
44
+ completed: progress,
45
+ total: typeNames.size,
46
+ step: ctx.state().analyze?.step ?? 0,
47
+ created_at: new Date().toISOString(),
48
+ });
49
+ return row;
50
+ }),
51
+ )) {
52
+ Object.assign(x, y);
53
+ }
54
+ return x;
55
+ }
56
+
57
+ async function divideAndConquer<Model extends ILlmSchema.Model>(
58
+ ctx: AutoBeContext<Model>,
59
+ operations: AutoBeOpenApi.IOperation[],
60
+ typeNames: string[],
61
+ retry: number,
62
+ progress: (completed: number) => void,
63
+ ): Promise<Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>> {
64
+ const remained: Set<string> = new Set(typeNames);
65
+ const schemas: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive> = {};
66
+ for (let i: number = 0; i < retry; ++i) {
67
+ if (remained.size === 0) break;
68
+ const before: number = remained.size;
69
+ const newbie: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive> =
70
+ await forceRetry(() => process(ctx, operations, schemas, remained));
71
+ for (const key of Object.keys(newbie)) {
72
+ schemas[key] = newbie[key];
73
+ remained.delete(key);
74
+ }
75
+ if (before - remained.size !== 0) progress(before - remained.size);
76
+ }
77
+ return schemas;
78
+ }
79
+
80
+ async function process<Model extends ILlmSchema.Model>(
81
+ ctx: AutoBeContext<Model>,
82
+ operations: AutoBeOpenApi.IOperation[],
83
+ oldbie: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>,
84
+ remained: Set<string>,
85
+ ): Promise<Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>> {
86
+ const pointer: IPointer<Record<
87
+ string,
88
+ AutoBeOpenApi.IJsonSchemaDescriptive
89
+ > | null> = {
90
+ value: null,
91
+ };
92
+ const agentica: MicroAgentica<Model> = new MicroAgentica({
93
+ model: ctx.model,
94
+ vendor: ctx.vendor,
95
+ config: {
96
+ ...(ctx.config ?? {}),
97
+ executor: {
98
+ describe: null,
99
+ },
100
+ },
101
+ histories: transformInterfaceSchemaHistories(ctx.state(), operations),
102
+ controllers: [
103
+ createApplication({
104
+ model: ctx.model,
105
+ build: async (next) => {
106
+ pointer.value ??= {};
107
+ Object.assign(pointer.value, next);
108
+ },
109
+ pointer,
110
+ }),
111
+ ],
112
+ });
113
+ enforceToolCall(agentica);
114
+
115
+ const already: string[] = Object.keys(oldbie);
116
+ await agentica
117
+ .conversate(
118
+ [
119
+ "Make type components please.",
120
+ "",
121
+ "Here is the list of request/response bodies' type names from",
122
+ "OpenAPI operations. Make type components of them. If more object",
123
+ "types are required during making the components, please make them",
124
+ "too.",
125
+ "",
126
+ ...Array.from(remained).map((k) => `- \`${k}\``),
127
+ ...(already.length !== 0
128
+ ? [
129
+ "",
130
+ "> By the way, here is the list of components schemas what you've",
131
+ "> already made. So, you don't need to make them again.",
132
+ ">",
133
+ ...already.map((k) => `> - \`${k}\``),
134
+ ]
135
+ : []),
136
+ ].join("\n"),
137
+ )
138
+ .finally(() => {
139
+ const tokenUsage = agentica.getTokenUsage();
140
+ ctx.usage().record(tokenUsage, ["interface"]);
141
+ });
142
+ if (pointer.value === null) {
143
+ // never be happened
144
+ throw new Error("Failed to create components.");
145
+ }
146
+ return (
147
+ (
148
+ OpenApiV3_1Emender.convertComponents({
149
+ schemas: pointer.value,
150
+ }) as AutoBeOpenApi.IComponents
151
+ ).schemas ?? {}
152
+ );
153
+ }
154
+
155
+ function createApplication<Model extends ILlmSchema.Model>(props: {
156
+ model: Model;
157
+ build: (
158
+ next: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>,
159
+ ) => Promise<void>;
160
+ pointer: IPointer<Record<
161
+ string,
162
+ AutoBeOpenApi.IJsonSchemaDescriptive
163
+ > | null>;
164
+ }): IAgenticaController.IClass<Model> {
165
+ assertSchemaModel(props.model);
166
+
167
+ const application: ILlmApplication<Model> = collection[
168
+ props.model
169
+ ] as unknown as ILlmApplication<Model>;
170
+ return {
171
+ protocol: "class",
172
+ name: "interface",
173
+ application,
174
+ execute: {
175
+ makeComponents: async (next) => {
176
+ await props.build(next.schemas);
177
+ },
178
+ } satisfies IAutoBeInterfaceSchemaApplication,
179
+ };
180
+ }
181
+
182
+ const claude = typia.llm.application<
183
+ IAutoBeInterfaceSchemaApplication,
184
+ "claude",
185
+ { reference: true }
186
+ >();
187
+ const collection = {
188
+ chatgpt: typia.llm.application<
189
+ IAutoBeInterfaceSchemaApplication,
190
+ "chatgpt",
191
+ { reference: true }
192
+ >(),
193
+ claude,
194
+ llama: claude,
195
+ deepseek: claude,
196
+ "3.1": claude,
197
+ };
@@ -0,0 +1,58 @@
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+
3
+ export interface IAutoBeInterfaceComplementApplication {
4
+ /**
5
+ * Complements missing schema types
6
+ *
7
+ * This method fills in schema definitions that are referenced via $ref but
8
+ * not yet defined in the `components.schemas` section. For example, if an API
9
+ * operation references `{ "$ref": "#/components/schemas/UserProfile" }` but
10
+ * `UserProfile` type is not defined in `components.schemas`, this method will
11
+ * add the missing schema definition.
12
+ *
13
+ * This function is designed to be called via AI function calling mechanism to
14
+ * ensure the OpenAPI document is complete and all referenced schemas are
15
+ * properly defined.
16
+ */
17
+ complementComponents(
18
+ props: IAutoBeInterfaceComplementApplication.IProps,
19
+ ): void;
20
+ }
21
+ export namespace IAutoBeInterfaceComplementApplication {
22
+ export interface IProps {
23
+ /**
24
+ * A collection of missing schema definitions that need to be added to the
25
+ * OpenAPI document's `components.schemas` section.
26
+ *
27
+ * This object contains schema definitions for types that are referenced but
28
+ * not yet defined:
29
+ *
30
+ * - Key: Schema name (`string`): The name of the schema type that will be
31
+ * referenced in $ref statements
32
+ * - Value: `AutoBeOpenApi.IJsonSchema` - The complete JSON Schema definition
33
+ * for that type
34
+ *
35
+ * Example structure:
36
+ *
37
+ * ```typescript
38
+ * {
39
+ * "UserProfile": {
40
+ * "type": "object",
41
+ * "properties": {
42
+ * "id": { "type": "string" },
43
+ * "name": { "type": "string" },
44
+ * "email": { "type": "string", "format": "email" }
45
+ * },
46
+ * "required": ["id", "name", "email"]
47
+ * }
48
+ * }
49
+ * ```
50
+ *
51
+ * Each schema definition follows the JSON Schema specification and will be
52
+ * directly inserted into the OpenAPI document's components.schemas section,
53
+ * making them available for $ref references throughout the API
54
+ * specification.
55
+ */
56
+ schemas: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>;
57
+ }
58
+ }
@@ -0,0 +1,24 @@
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+
3
+ export interface IAutoBeInterfaceEndpointApplication {
4
+ /**
5
+ * Create Restful API endpoints.
6
+ *
7
+ * Create Restful API endpoints referencing the given documents; requirement
8
+ * analysis documents, and Prisma schema files with ERD descriptions. The API
9
+ * endpoints must cover every requirements and every entities in the ERD.
10
+ *
11
+ * Also, each combination of {@link AutoBeOpenApi.IEndpoint.path} and
12
+ * {@link AutoBeOpenApi.IEndpoint.method} must be unique to avoid duplicates.
13
+ * Please don't make any duplicates.
14
+ *
15
+ * @param props Properties containing the endpoints
16
+ */
17
+ makeEndpoints(props: IAutoBeInterfaceEndpointApplication.IProps): void;
18
+ }
19
+ export namespace IAutoBeInterfaceEndpointApplication {
20
+ export interface IProps {
21
+ /** The endpoints to generate. */
22
+ endpoints: AutoBeOpenApi.IEndpoint[];
23
+ }
24
+ }
@@ -0,0 +1,112 @@
1
+ import { tags } from "typia";
2
+
3
+ export interface IAutoBeInterfaceGroupApplication {
4
+ /**
5
+ * Generate logical groups for organizing API endpoint creation based on
6
+ * Prisma schema structure.
7
+ *
8
+ * Groups MUST be derived from Prisma schema organization (namespaces, file
9
+ * structure, table prefixes) rather than arbitrary business domains. Only
10
+ * create new groups when existing schema structure cannot adequately cover
11
+ * all requirements.
12
+ *
13
+ * @param props Properties containing the groups to be created for API
14
+ * organization
15
+ */
16
+ makeGroups(props: IAutoBeInterfaceGroupApplication.IProps): void;
17
+ }
18
+
19
+ export namespace IAutoBeInterfaceGroupApplication {
20
+ export interface IProps {
21
+ /**
22
+ * Array of API endpoint groups for organizing development.
23
+ *
24
+ * Groups MUST be organized around existing Prisma schema structure and
25
+ * provide complete coverage of all entities and requirements without
26
+ * overlap.
27
+ */
28
+ groups: IGroup[] & tags.MinItems<1>;
29
+ }
30
+
31
+ /**
32
+ * Definition of a logical API endpoint group based on Prisma schema
33
+ * organization.
34
+ *
35
+ * **SCHEMA-BASED GROUP REQUIREMENTS:**
36
+ *
37
+ * Groups MUST be derived from the Prisma schema structure rather than
38
+ * arbitrary business domain names. This ensures consistency with the
39
+ * underlying data model and prevents misalignment between API organization
40
+ * and database structure.
41
+ *
42
+ * **Primary Group Sources (in order of priority):**
43
+ *
44
+ * 1. **Prisma Schema Namespaces**: Use namespace names (e.g., `namespace
45
+ * Shopping` → "Shopping")
46
+ * 2. **Schema File Names**: Derive from file names (e.g., `shopping.prisma` →
47
+ * "Shopping")
48
+ * 3. **Table Prefix Patterns**: Use consistent prefixes (e.g., `shopping_orders`
49
+ * → "Shopping")
50
+ * 4. **Schema Comments/Annotations**: Follow organizational comments in schema
51
+ *
52
+ * **Group Creation Guidelines:**
53
+ *
54
+ * - Each group must cover specific Prisma schema entities without overlap
55
+ * - Size groups appropriately for manageable endpoint generation cycles
56
+ * - Maintain clear boundaries based on schema organization
57
+ * - Ensure complete coverage of all database entities and requirements
58
+ * - Related database tables within the same schema area should be grouped
59
+ * together
60
+ *
61
+ * **When to Create Schema-Independent Groups:**
62
+ *
63
+ * Only create groups that don't correspond to Prisma schema organization
64
+ * when:
65
+ *
66
+ * - Requirements include functionality not represented in any schema entity
67
+ * - Cross-cutting concerns span multiple schema areas
68
+ * - Integration operations don't map to specific database entities
69
+ * - System-level functionality requires dedicated API operations
70
+ *
71
+ * **Naming Standards:**
72
+ *
73
+ * - Use PascalCase format (e.g., "Shopping", "BBS", "UserManagement")
74
+ * - Names MUST directly reflect Prisma schema structure
75
+ * - Keep names concise and schema-derived
76
+ * - Avoid arbitrary business domain names
77
+ * - Maintain consistency with schema organization
78
+ *
79
+ * **Quality Requirements:**
80
+ *
81
+ * - Groups collectively must cover ALL entities and requirements
82
+ * - Each database entity belongs to exactly one group
83
+ * - Clear mapping to specific Prisma schema elements
84
+ * - Balance group sizes within schema constraints
85
+ * - Follow existing schema namespace or file structure patterns
86
+ */
87
+ export interface IGroup {
88
+ /**
89
+ * Unique identifier name derived from Prisma schema structure.
90
+ *
91
+ * Must correspond to schema namespaces, file names, table prefixes, or
92
+ * organizational annotations rather than arbitrary business domain names.
93
+ */
94
+ name: string & tags.MinLength<1>;
95
+
96
+ /**
97
+ * Comprehensive description of the group's scope, schema foundation, and
98
+ * purpose.
99
+ *
100
+ * **Required Content:**
101
+ *
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
109
+ */
110
+ description: string & tags.MinLength<1>;
111
+ }
112
+ }
@@ -0,0 +1,125 @@
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import { tags } from "typia";
3
+
4
+ export interface IAutoBeInterfaceOperationApplication {
5
+ /**
6
+ * Generate detailed API operations from path/method combinations.
7
+ *
8
+ * This function creates complete API operations following REST principles and
9
+ * quality standards. Each generated operation includes specification, path,
10
+ * method, detailed multi-paragraph description, concise summary, parameters,
11
+ * and appropriate request/response bodies.
12
+ *
13
+ * The function processes as many operations as possible in a single call,
14
+ * with progress tracking to ensure iterative completion of all required
15
+ * endpoints.
16
+ *
17
+ * @param props Properties containing the operations to generate.
18
+ */
19
+ makeOperations(props: IAutoBeInterfaceOperationApplication.IProps): void;
20
+ }
21
+ export namespace IAutoBeInterfaceOperationApplication {
22
+ export interface IProps {
23
+ /**
24
+ * Array of API operations to generate.
25
+ *
26
+ * Each operation in this array must include:
27
+ *
28
+ * - Specification: Detailed API specification with clear purpose and
29
+ * functionality
30
+ * - Path: Resource-centric URL path (e.g., "/resources/{resourceId}")
31
+ * - Method: HTTP method (get, post, put, delete, patch)
32
+ * - Description: Extremely detailed multi-paragraph description referencing
33
+ * Prisma schema comments
34
+ * - Summary: Concise one-sentence summary of the endpoint
35
+ * - Parameters: Array of all necessary parameters with descriptions and
36
+ * schema definitions
37
+ * - RequestBody: For POST/PUT/PATCH methods, with typeName referencing
38
+ * components.schemas
39
+ * - ResponseBody: With typeName referencing appropriate response type
40
+ *
41
+ * All operations must follow strict quality standards:
42
+ *
43
+ * 1. Detailed descriptions referencing Prisma schema comments
44
+ * 2. Accurate parameter definitions matching path parameters
45
+ * 3. Appropriate request/response body type references
46
+ * 4. Consistent patterns for CRUD operations
47
+ *
48
+ * For list retrievals (typically PATCH), include pagination, search, and
49
+ * sorting. For detail retrieval (GET), return a single resource. For
50
+ * creation (POST), use .ICreate request body. For modification (PUT), use
51
+ * .IUpdate request body.
52
+ */
53
+ operations: IOperation[];
54
+ }
55
+
56
+ /**
57
+ * Operation of the Restful API.
58
+ *
59
+ * This interface defines a single API endpoint with its HTTP {@link method},
60
+ * {@link path}, {@link parameters path parameters},
61
+ * {@link requestBody request body}, and {@link responseBody} structure. It
62
+ * corresponds to an individual operation in the paths section of an OpenAPI
63
+ * document.
64
+ *
65
+ * Each operation requires a detailed explanation of its purpose through the
66
+ * reason and description fields, making it clear why the API was designed and
67
+ * how it should be used.
68
+ *
69
+ * All request bodies and responses for this operation must be object types
70
+ * and must reference named types defined in the components section. The
71
+ * content-type is always `application/json`. For file upload/download
72
+ * operations, use `string & tags.Format<"uri">` in the appropriate schema
73
+ * instead of binary data formats.
74
+ *
75
+ * In OpenAPI, this might represent:
76
+ *
77
+ * ```json
78
+ * {
79
+ * "/shoppings/customers/orders": {
80
+ * "post": {
81
+ * "description": "Create a new order application from shopping cart...",
82
+ * "parameters": [...],
83
+ * "requestBody": {...},
84
+ * "responses": {...}
85
+ * }
86
+ * }
87
+ * }
88
+ * ```
89
+ */
90
+ export interface IOperation
91
+ extends Omit<AutoBeOpenApi.IOperation, "authorizationRole"> {
92
+ /**
93
+ * Authorization roles required to access this API operation.
94
+ *
95
+ * This field specifies which user roles are allowed to access this
96
+ * endpoint. Multiple roles can be specified to allow different types of
97
+ * users to access the same endpoint.
98
+ *
99
+ * ## Important Guidelines
100
+ *
101
+ * - Set to empty array `[]` for public endpoints that require no
102
+ * authentication
103
+ * - Set to array with role strings for role-restricted endpoints
104
+ * - The role names MUST match exactly with the user type/role defined in the
105
+ * database
106
+ * - This will be used by the Realize Agent to generate appropriate decorator
107
+ * and authorization logic in the provider functions
108
+ * - The controller will apply the corresponding authentication decorator
109
+ * based on these roles
110
+ *
111
+ * ## Examples
112
+ *
113
+ * - `[]` - Public endpoint, no authentication required
114
+ * - `["user"]` - Any authenticated user can access
115
+ * - `["admin"]` - Only admin users can access
116
+ * - `["admin", "moderator"]` - Both admin and moderator users can access
117
+ * - `["seller"]` - Only seller users can access
118
+ *
119
+ * Note: The actual authentication/authorization implementation will be
120
+ * handled by decorators at the controller level, and the provider function
121
+ * will receive the authenticated user object with the appropriate type.
122
+ */
123
+ authorizationRoles: Array<string & tags.MinLength<1>>;
124
+ }
125
+ }
@@ -0,0 +1,76 @@
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+
3
+ export interface IAutoBeInterfaceSchemaApplication {
4
+ /**
5
+ * Generate OpenAPI components containing named schema types.
6
+ *
7
+ * This method receives a complete set of schema components and integrates
8
+ * them into the final OpenAPI specification. It processes all entity schemas,
9
+ * their variants, and related type definitions to ensure a comprehensive and
10
+ * consistent API design.
11
+ *
12
+ * The provided components should include schemas for all entities identified
13
+ * in the previous phases of API path/method definition and operation
14
+ * creation. This ensures that the final OpenAPI document has complete type
15
+ * coverage for all operations.
16
+ *
17
+ * CRITICAL: All schema definitions must follow the established naming
18
+ * conventions (IEntityName, IEntityName.ICreate, etc.) and must be thoroughly
19
+ * documented with descriptions that reference the original Prisma schema
20
+ * comments.
21
+ *
22
+ * @param props Properties containing components to generate.
23
+ */
24
+ makeComponents(props: IAutoBeInterfaceSchemaApplication.IProps): void;
25
+ }
26
+ export namespace IAutoBeInterfaceSchemaApplication {
27
+ export interface IProps {
28
+ /**
29
+ * Complete set of schema components for the OpenAPI specification.
30
+ *
31
+ * This property contains comprehensive type definitions for all entities in
32
+ * the system. It is the central repository of all named schema types that
33
+ * will be used throughout the API specification.
34
+ *
35
+ * CRITICAL REQUIREMENT: All object types MUST be defined as named types in
36
+ * the components.schemas section. Inline anonymous object definitions are
37
+ * strictly prohibited.
38
+ *
39
+ * This components object should include:
40
+ *
41
+ * - Main entity types (IEntityName)
42
+ * - Operation-specific variants (.ICreate, .IUpdate, .ISummary, etc.)
43
+ * - Container types (IPage<T> for pagination)
44
+ * - Enumeration types
45
+ *
46
+ * All schema definitions must include detailed descriptions that reference
47
+ * the original Prisma schema comments and thoroughly document each
48
+ * property. Every property that references an object must use a $ref to a
49
+ * named type in the components.schemas section. This applies to all objects
50
+ * in request bodies, response bodies, and properties that are objects or
51
+ * arrays of objects.
52
+ *
53
+ * Example structure:
54
+ *
55
+ * ```typescript
56
+ * {
57
+ * schemas: {
58
+ * IUser: {
59
+ * type: "object",
60
+ * properties: {
61
+ * id: { type: "string", format: "uuid" },
62
+ * email: { type: "string", format: "email" },
63
+ * profile: { "$ref": "#/components/schemas/IUserProfile" }
64
+ * },
65
+ * required: ["id", "email"],
66
+ * description: "User entity representing system account holders..."
67
+ * },
68
+ * "IUser.ICreate": { ... },
69
+ * // Additional schemas
70
+ * }
71
+ * }
72
+ * ```
73
+ */
74
+ schemas: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>;
75
+ }
76
+ }
@@ -12,4 +12,12 @@ export namespace OpenApiEndpointComparator {
12
12
  ): boolean {
13
13
  return x.path === y.path && x.method === y.method;
14
14
  }
15
+
16
+ export function compare(
17
+ x: AutoBeOpenApi.IEndpoint,
18
+ y: AutoBeOpenApi.IEndpoint,
19
+ ): number {
20
+ if (x.path !== y.path) return x.path.localeCompare(y.path);
21
+ return x.method.localeCompare(y.method);
22
+ }
15
23
  }
@@ -35,7 +35,7 @@ export const orchestrateRealize =
35
35
  ctx,
36
36
  ops,
37
37
  authorizations,
38
- 2,
38
+ 3,
39
39
  );
40
40
 
41
41
  const now = new Date().toISOString();
@@ -48,7 +48,24 @@ export const orchestrateRealize =
48
48
  compiled: {
49
49
  type: "success",
50
50
  },
51
- functions: files,
51
+ functions: {
52
+ ...files,
53
+ ...authorizations
54
+ .flatMap((el) => {
55
+ return [
56
+ {
57
+ [el.decorator.location]: el.decorator.content,
58
+ },
59
+ {
60
+ [el.payload.location]: el.payload.content,
61
+ },
62
+ {
63
+ [el.payload.location]: el.payload.content,
64
+ },
65
+ ];
66
+ })
67
+ .reduce((acc, cur) => Object.assign(acc, cur)),
68
+ },
52
69
  completed_at: now,
53
70
  created_at: now,
54
71
  id: v4(),