@autobe/agent 0.0.0 → 0.3.6

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 (166) hide show
  1. package/LICENSE +21 -21
  2. package/lib/AutoBeAgent.d.ts +9 -7
  3. package/lib/AutoBeAgent.js +106 -14
  4. package/lib/AutoBeAgent.js.map +1 -1
  5. package/lib/analyze/AnalyzeAgent.d.ts +24 -0
  6. package/lib/analyze/AnalyzeAgent.js +817 -0
  7. package/lib/analyze/AnalyzeAgent.js.map +1 -0
  8. package/lib/analyze/CreateReviewerAgent.d.ts +16 -0
  9. package/lib/analyze/CreateReviewerAgent.js +97 -0
  10. package/lib/analyze/CreateReviewerAgent.js.map +1 -0
  11. package/lib/analyze/Planning.d.ts +63 -0
  12. package/lib/{orchestrate/orchestratePrisma.js → analyze/Planning.js} +28 -11
  13. package/lib/analyze/Planning.js.map +1 -0
  14. package/lib/constants/AutoBeSystemPromptConstant.d.ts +14 -0
  15. package/lib/constants/AutoBeSystemPromptConstant.js +4 -0
  16. package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -0
  17. package/lib/context/AutoBeContext.d.ts +7 -3
  18. package/lib/context/IAutoBeApplication.d.ts +72 -32
  19. package/lib/context/IAutoBeApplicationProps.d.ts +22 -2
  20. package/lib/context/IAutoBeApplicationResult.d.ts +0 -1
  21. package/lib/context/assertSchemaModel.d.ts +2 -0
  22. package/lib/context/assertSchemaModel.js +15 -0
  23. package/lib/context/assertSchemaModel.js.map +1 -0
  24. package/lib/{internal/transformAgenticaHistory.d.ts → factory/createAgenticaHistory.d.ts} +1 -1
  25. package/lib/{internal/transformAgenticaHistory.js → factory/createAgenticaHistory.js} +3 -4
  26. package/lib/factory/createAgenticaHistory.js.map +1 -0
  27. package/lib/factory/createAutoBeApplication.js +1195 -0
  28. package/lib/factory/createAutoBeApplication.js.map +1 -0
  29. package/lib/factory/createAutoBeState.js.map +1 -0
  30. package/lib/factory/index.d.ts +2 -0
  31. package/lib/factory/index.js +19 -0
  32. package/lib/factory/index.js.map +1 -0
  33. package/lib/factory/invertOpenApiDocument.d.ts +3 -0
  34. package/lib/factory/invertOpenApiDocument.js +51 -0
  35. package/lib/factory/invertOpenApiDocument.js.map +1 -0
  36. package/lib/index.d.ts +3 -3
  37. package/lib/index.js +4 -4
  38. package/lib/index.js.map +1 -1
  39. package/lib/index.mjs +5455 -547
  40. package/lib/index.mjs.map +1 -1
  41. package/lib/orchestrate/facade/transformFacadeStateMessage.d.ts +2 -0
  42. package/lib/orchestrate/facade/transformFacadeStateMessage.js +46 -0
  43. package/lib/orchestrate/facade/transformFacadeStateMessage.js.map +1 -0
  44. package/lib/orchestrate/index.d.ts +2 -2
  45. package/lib/orchestrate/index.js +2 -2
  46. package/lib/orchestrate/index.js.map +1 -1
  47. package/lib/orchestrate/interface/OpenApiEndpointComparator.d.ts +5 -0
  48. package/lib/orchestrate/interface/OpenApiEndpointComparator.js +16 -0
  49. package/lib/orchestrate/interface/OpenApiEndpointComparator.js.map +1 -0
  50. package/lib/orchestrate/interface/orchestrateInterface.d.ts +5 -0
  51. package/lib/orchestrate/interface/orchestrateInterface.js +61 -0
  52. package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -0
  53. package/lib/orchestrate/interface/orchestrateInterfaceComponents.d.ts +4 -0
  54. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +702 -0
  55. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +1 -0
  56. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.d.ts +4 -0
  57. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +452 -0
  58. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -0
  59. package/lib/orchestrate/interface/orchestrateInterfaceOperations.d.ts +4 -0
  60. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +2065 -0
  61. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -0
  62. package/lib/orchestrate/interface/transformInterfaceHistories.d.ts +3 -0
  63. package/lib/orchestrate/interface/transformInterfaceHistories.js +94 -0
  64. package/lib/orchestrate/interface/transformInterfaceHistories.js.map +1 -0
  65. package/lib/orchestrate/orchestrateAnalyze.d.ts +1 -3
  66. package/lib/orchestrate/orchestrateAnalyze.js +60 -6
  67. package/lib/orchestrate/orchestrateAnalyze.js.map +1 -1
  68. package/lib/orchestrate/{orchestratePrisma.d.ts → prisma/orchestratePrisma.d.ts} +3 -6
  69. package/lib/orchestrate/prisma/orchestratePrisma.js +103 -0
  70. package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -0
  71. package/lib/orchestrate/prisma/orchestratePrismaCompiler.d.ts +6 -0
  72. package/lib/orchestrate/prisma/orchestratePrismaCompiler.js +436 -0
  73. package/lib/orchestrate/prisma/orchestratePrismaCompiler.js.map +1 -0
  74. package/lib/orchestrate/prisma/orchestratePrismaComponent.d.ts +5 -0
  75. package/lib/orchestrate/prisma/orchestratePrismaComponent.js +437 -0
  76. package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -0
  77. package/lib/orchestrate/prisma/orchestratePrismaSchema.d.ts +7 -0
  78. package/lib/orchestrate/prisma/orchestratePrismaSchema.js +369 -0
  79. package/lib/orchestrate/prisma/orchestratePrismaSchema.js.map +1 -0
  80. package/lib/orchestrate/prisma/transformPrismaCompilerHistories.d.ts +3 -0
  81. package/lib/orchestrate/prisma/transformPrismaCompilerHistories.js +44 -0
  82. package/lib/orchestrate/prisma/transformPrismaCompilerHistories.js.map +1 -0
  83. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.d.ts +3 -0
  84. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js +42 -0
  85. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js.map +1 -0
  86. package/lib/orchestrate/prisma/transformPrismaHistories.d.ts +3 -0
  87. package/lib/orchestrate/prisma/transformPrismaHistories.js +46 -0
  88. package/lib/orchestrate/prisma/transformPrismaHistories.js.map +1 -0
  89. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.d.ts +3 -0
  90. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js +46 -0
  91. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js.map +1 -0
  92. package/lib/structures/IAutoBeConfig.d.ts +4 -4
  93. package/lib/utils/StringUtil.d.ts +4 -0
  94. package/lib/utils/StringUtil.js +43 -0
  95. package/lib/utils/StringUtil.js.map +1 -0
  96. package/lib/utils/divideArray.d.ts +4 -0
  97. package/lib/utils/divideArray.js +19 -0
  98. package/lib/utils/divideArray.js.map +1 -0
  99. package/lib/utils/emplaceMap.d.ts +1 -0
  100. package/lib/utils/emplaceMap.js +13 -0
  101. package/lib/utils/emplaceMap.js.map +1 -0
  102. package/package.json +29 -8
  103. package/src/AutoBeAgent.ts +227 -101
  104. package/src/analyze/AnalyzeAgent.ts +167 -0
  105. package/src/analyze/CreateReviewerAgent.ts +126 -0
  106. package/src/analyze/Planning.ts +75 -0
  107. package/src/constants/AutoBeSystemPromptConstant.ts +15 -0
  108. package/src/context/AutoBeContext.ts +19 -15
  109. package/src/context/AutoBeState.ts +15 -15
  110. package/src/context/AutoBeTokenUsage.ts +3 -3
  111. package/src/context/IAutoBeApplication.ts +112 -72
  112. package/src/context/IAutoBeApplicationProps.ts +27 -6
  113. package/src/context/IAutoBeApplicationResult.ts +3 -4
  114. package/src/context/assertSchemaModel.ts +17 -0
  115. package/src/{internal/transformAgenticaHistory.ts → factory/createAgenticaHistory.ts} +51 -54
  116. package/src/{internal → factory}/createAutoBeApplication.ts +52 -47
  117. package/src/{internal → factory}/createAutoBeState.ts +14 -14
  118. package/src/factory/index.ts +2 -0
  119. package/src/factory/invertOpenApiDocument.ts +63 -0
  120. package/src/index.ts +13 -12
  121. package/src/orchestrate/facade/transformFacadeStateMessage.ts +58 -0
  122. package/src/orchestrate/index.ts +5 -5
  123. package/src/orchestrate/interface/OpenApiEndpointComparator.ts +15 -0
  124. package/src/orchestrate/interface/orchestrateInterface.ts +66 -0
  125. package/src/orchestrate/interface/orchestrateInterfaceComponents.ts +324 -0
  126. package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +140 -0
  127. package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +247 -0
  128. package/src/orchestrate/interface/transformInterfaceHistories.ts +98 -0
  129. package/src/orchestrate/orchestrateAnalyze.ts +86 -21
  130. package/src/orchestrate/orchestrateRealize.ts +18 -18
  131. package/src/orchestrate/orchestrateTest.ts +18 -18
  132. package/src/orchestrate/prisma/orchestratePrisma.ts +117 -0
  133. package/src/orchestrate/prisma/orchestratePrismaCompiler.ts +194 -0
  134. package/src/orchestrate/prisma/orchestratePrismaComponent.ts +176 -0
  135. package/src/orchestrate/prisma/orchestratePrismaSchema.ts +181 -0
  136. package/src/orchestrate/prisma/transformPrismaCompilerHistories.ts +49 -0
  137. package/src/orchestrate/prisma/transformPrismaComponentsHistories.ts +46 -0
  138. package/src/orchestrate/prisma/transformPrismaHistories.ts +50 -0
  139. package/src/orchestrate/prisma/transformPrismaSchemaHistories.ts +50 -0
  140. package/src/structures/IAutoBeConfig.ts +25 -25
  141. package/src/structures/IAutoBeProps.ts +13 -13
  142. package/src/structures/IAutoBeVendor.ts +3 -3
  143. package/src/utils/StringUtil.ts +45 -0
  144. package/src/utils/divideArray.ts +16 -0
  145. package/src/utils/emplaceMap.ts +14 -0
  146. package/lib/factory/transformRouteDocument.d.ts +0 -3
  147. package/lib/factory/transformRouteDocument.js +0 -50
  148. package/lib/factory/transformRouteDocument.js.map +0 -1
  149. package/lib/internal/createAutoBeApplication.js +0 -1452
  150. package/lib/internal/createAutoBeApplication.js.map +0 -1
  151. package/lib/internal/createAutoBeState.js.map +0 -1
  152. package/lib/internal/transformAgenticaHistory.js.map +0 -1
  153. package/lib/orchestrate/interface/AutoBeInterfaceAgent.d.ts +0 -0
  154. package/lib/orchestrate/interface/AutoBeInterfaceAgent.js +0 -2
  155. package/lib/orchestrate/interface/AutoBeInterfaceAgent.js.map +0 -1
  156. package/lib/orchestrate/orchestrateInterface.d.ts +0 -8
  157. package/lib/orchestrate/orchestrateInterface.js +0 -22
  158. package/lib/orchestrate/orchestrateInterface.js.map +0 -1
  159. package/lib/orchestrate/orchestratePrisma.js.map +0 -1
  160. package/src/factory/transformRouteDocument.ts +0 -49
  161. package/src/orchestrate/interface/AutoBeInterfaceAgent.ts +0 -0
  162. package/src/orchestrate/orchestrateInterface.ts +0 -21
  163. package/src/orchestrate/orchestratePrisma.ts +0 -21
  164. /package/lib/{internal → factory}/createAutoBeApplication.d.ts +0 -0
  165. /package/lib/{internal → factory}/createAutoBeState.d.ts +0 -0
  166. /package/lib/{internal → factory}/createAutoBeState.js +0 -0
package/src/index.ts CHANGED
@@ -1,12 +1,13 @@
1
- export * from "./AutoBeAgent";
2
-
3
- export * from "./context/AutoBeTokenUsage";
4
-
5
- export * from "./structures/IAutoBeProps";
6
- export * from "./structures/IAutoBeConfig";
7
- export * from "./structures/IAutoBeVendor";
8
-
9
- /**
10
- * @internal
11
- */
12
- export * as orchestrate from "./orchestrate";
1
+ export * from "./AutoBeAgent";
2
+
3
+ export * from "./context/AutoBeTokenUsage";
4
+
5
+ export * from "./structures/IAutoBeProps";
6
+ export * from "./structures/IAutoBeConfig";
7
+ export * from "./structures/IAutoBeVendor";
8
+
9
+ /** @internal */
10
+ export * as factory from "./factory";
11
+
12
+ /** @internal */
13
+ export * as orchestrate from "./orchestrate";
@@ -0,0 +1,58 @@
1
+ import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
2
+ import { AutoBeState } from "../../context/AutoBeState";
3
+ import { StringUtil } from "../../utils/StringUtil";
4
+
5
+ export function transformFacadeStateMessage(state: AutoBeState): string {
6
+ const currentState: ICurrentState = getCurrentState(state);
7
+ return AutoBeSystemPromptConstant.FACADE.replace(
8
+ "{% STATE %}",
9
+ StringUtil.trim`
10
+ ## Current State
11
+
12
+ The current execution status of each functional agent is shown below.
13
+ Each agent can be in one of three states: "none" (never executed),
14
+ "up-to-date" (successfully executed with current output),
15
+ or "out-of-date" (previously executed but needs updating due to
16
+ changes in earlier stages).
17
+
18
+ An agent cannot be executed if any of its prerequisite agents have
19
+ a status of "none" or "out-of-date". In such cases, you must complete or
20
+ update the earlier stages first. Additionally, re-executing an "up-to-date"
21
+ agent will cause all subsequent agents to become "out-of-date", as they
22
+ depend on the updated output.
23
+
24
+ - analyze: ${currentState.analyze}
25
+ - prisma: ${currentState.prisma}
26
+ - interface: ${currentState.interface}
27
+ - test: ${currentState.test}
28
+ - realize: ${currentState.realize}
29
+ `,
30
+ );
31
+ }
32
+
33
+ function getCurrentState(state: AutoBeState): ICurrentState {
34
+ const value = (
35
+ obj: {
36
+ step: number;
37
+ } | null,
38
+ ) => {
39
+ if (state.analyze === null || obj === null) return "none";
40
+ else if (state.analyze.step === obj.step) return "up-to-date";
41
+ else return "out-of-date";
42
+ };
43
+ return {
44
+ analyze: state.analyze === null ? "none" : "up-to-date",
45
+ prisma: value(state.prisma),
46
+ interface: value(state.interface),
47
+ test: value(state.test),
48
+ realize: value(state.realize),
49
+ };
50
+ }
51
+
52
+ interface ICurrentState {
53
+ analyze: "up-to-date" | "none";
54
+ prisma: "up-to-date" | "out-of-date" | "none";
55
+ interface: "up-to-date" | "out-of-date" | "none";
56
+ test: "up-to-date" | "out-of-date" | "none";
57
+ realize: "up-to-date" | "out-of-date" | "none";
58
+ }
@@ -1,5 +1,5 @@
1
- export { orchestrateAnalyze as analyze } from "./orchestrateAnalyze";
2
- export { orchestrateInterface as interface } from "./orchestrateInterface";
3
- export { orchestratePrisma as prisma } from "./orchestratePrisma";
4
- export { orchestrateTest as test } from "./orchestrateTest";
5
- export { orchestrateRealize as realize } from "./orchestrateRealize";
1
+ export { orchestrateAnalyze as analyze } from "./orchestrateAnalyze";
2
+ export { orchestrateInterface as interface } from "./interface/orchestrateInterface";
3
+ export { orchestratePrisma as prisma } from "./prisma/orchestratePrisma";
4
+ export { orchestrateTest as test } from "./orchestrateTest";
5
+ export { orchestrateRealize as realize } from "./orchestrateRealize";
@@ -0,0 +1,15 @@
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import { hash } from "tstl";
3
+
4
+ export namespace OpenApiEndpointComparator {
5
+ export function hashCode(e: AutoBeOpenApi.IEndpoint): number {
6
+ return hash(e.path, e.method);
7
+ }
8
+
9
+ export function equals(
10
+ x: AutoBeOpenApi.IEndpoint,
11
+ y: AutoBeOpenApi.IEndpoint,
12
+ ): boolean {
13
+ return x.path === y.path && x.method === y.method;
14
+ }
15
+ }
@@ -0,0 +1,66 @@
1
+ import {
2
+ AutoBeAssistantMessageHistory,
3
+ AutoBeInterfaceCompleteEvent,
4
+ AutoBeInterfaceEndpointsEvent,
5
+ AutoBeInterfaceHistory,
6
+ AutoBeOpenApi,
7
+ } from "@autobe/interface";
8
+ import { ILlmSchema } from "@samchon/openapi";
9
+ import { v4 } from "uuid";
10
+
11
+ import { AutoBeContext } from "../../context/AutoBeContext";
12
+ import { IAutoBeApplicationProps } from "../../context/IAutoBeApplicationProps";
13
+ import { orchestrateInterfaceComponents } from "./orchestrateInterfaceComponents";
14
+ import { orchestrateInterfaceEndpoints } from "./orchestrateInterfaceEndpoints";
15
+ import { orchestrateInterfaceOperations } from "./orchestrateInterfaceOperations";
16
+
17
+ export const orchestrateInterface =
18
+ <Model extends ILlmSchema.Model>(ctx: AutoBeContext<Model>) =>
19
+ async (
20
+ props: IAutoBeApplicationProps,
21
+ ): Promise<AutoBeAssistantMessageHistory | AutoBeInterfaceHistory> => {
22
+ // ENDPOINTS
23
+ const start: Date = new Date();
24
+ const init: AutoBeAssistantMessageHistory | AutoBeInterfaceEndpointsEvent =
25
+ await orchestrateInterfaceEndpoints(ctx);
26
+ if (init.type === "assistantMessage") {
27
+ ctx.dispatch(init);
28
+ ctx.histories().push(init);
29
+ return init;
30
+ } else ctx.dispatch(init);
31
+
32
+ // OPERATIONS
33
+ const operations: AutoBeOpenApi.IOperation[] =
34
+ await orchestrateInterfaceOperations(ctx, init.endpoints);
35
+
36
+ // COMPONENTS
37
+ const components: AutoBeOpenApi.IComponents =
38
+ await orchestrateInterfaceComponents(ctx, operations);
39
+
40
+ // TYPESCRIPT CODE GENERATION
41
+ const document: AutoBeOpenApi.IDocument = {
42
+ operations,
43
+ components,
44
+ };
45
+ const result: AutoBeInterfaceHistory = {
46
+ type: "interface",
47
+ id: v4(),
48
+ document,
49
+ files: await ctx.compiler.interface(document),
50
+ reason: props.reason,
51
+ step: ctx.state().analyze?.step ?? 0,
52
+ created_at: start.toISOString(),
53
+ completed_at: new Date().toISOString(),
54
+ };
55
+ ctx.state().interface = result;
56
+ ctx.histories().push(result);
57
+ ctx.dispatch({
58
+ type: "interfaceComplete",
59
+ files: result.files,
60
+ document: result.document,
61
+ created_at: start.toISOString(),
62
+ reason: props.reason,
63
+ step: ctx.state().analyze?.step ?? 0,
64
+ } satisfies AutoBeInterfaceCompleteEvent);
65
+ return result;
66
+ };
@@ -0,0 +1,324 @@
1
+ import { IAgenticaController, MicroAgentica } from "@agentica/core";
2
+ import { AutoBeOpenApi } from "@autobe/interface";
3
+ import {
4
+ ILlmApplication,
5
+ ILlmSchema,
6
+ IValidation,
7
+ OpenApiTypeChecker,
8
+ } from "@samchon/openapi";
9
+ import { OpenApiV3_1Emender } from "@samchon/openapi/lib/converters/OpenApiV3_1Emender";
10
+ import { IPointer } from "tstl";
11
+ import typia from "typia";
12
+
13
+ import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
14
+ import { AutoBeContext } from "../../context/AutoBeContext";
15
+ import { assertSchemaModel } from "../../context/assertSchemaModel";
16
+ import { divideArray } from "../../utils/divideArray";
17
+ import { transformInterfaceHistories } from "./transformInterfaceHistories";
18
+
19
+ export async function orchestrateInterfaceComponents<
20
+ Model extends ILlmSchema.Model,
21
+ >(
22
+ ctx: AutoBeContext<Model>,
23
+ operations: AutoBeOpenApi.IOperation[],
24
+ capacity: number = 12,
25
+ ): Promise<AutoBeOpenApi.IComponents> {
26
+ const typeNames: Set<string> = new Set();
27
+ for (const op of operations) {
28
+ if (op.requestBody !== null) typeNames.add(op.requestBody.typeName);
29
+ if (op.responseBody !== null) typeNames.add(op.responseBody.typeName);
30
+ }
31
+ const matrix: string[][] = divideArray({
32
+ array: Array.from(typeNames),
33
+ capacity,
34
+ });
35
+ let progress: number = 0;
36
+
37
+ const x: AutoBeOpenApi.IComponents = {
38
+ schemas: {},
39
+ };
40
+ for (const y of await Promise.all(
41
+ matrix.map(async (it) => {
42
+ const row: AutoBeOpenApi.IComponents = await divideAndConquer(
43
+ ctx,
44
+ operations,
45
+ it,
46
+ 3,
47
+ (count) => {
48
+ progress += count;
49
+ },
50
+ );
51
+ ctx.dispatch({
52
+ type: "interfaceComponents",
53
+ components: row,
54
+ completed: progress,
55
+ total: typeNames.size,
56
+ step: ctx.state().analyze?.step ?? 0,
57
+ created_at: new Date().toISOString(),
58
+ });
59
+ return row;
60
+ }),
61
+ )) {
62
+ Object.assign(x.schemas, y.schemas);
63
+ if (y.authorization) x.authorization = y.authorization;
64
+ }
65
+ return x;
66
+ }
67
+
68
+ async function divideAndConquer<Model extends ILlmSchema.Model>(
69
+ ctx: AutoBeContext<Model>,
70
+ operations: AutoBeOpenApi.IOperation[],
71
+ typeNames: string[],
72
+ retry: number,
73
+ progress: (completed: number) => void,
74
+ ): Promise<AutoBeOpenApi.IComponents> {
75
+ const remained: Set<string> = new Set(typeNames);
76
+ const components: AutoBeOpenApi.IComponents = {
77
+ schemas: {},
78
+ };
79
+ for (let i: number = 0; i < retry; ++i) {
80
+ if (remained.size === 0) break;
81
+ const before: number = remained.size;
82
+ const newbie: AutoBeOpenApi.IComponents = await process(
83
+ ctx,
84
+ operations,
85
+ components,
86
+ remained,
87
+ );
88
+ for (const key of Object.keys(newbie.schemas)) {
89
+ components.schemas[key] = newbie.schemas[key];
90
+ remained.delete(key);
91
+ }
92
+ if (before - remained.size !== 0) progress(before - remained.size);
93
+ }
94
+ return components;
95
+ }
96
+
97
+ async function process<Model extends ILlmSchema.Model>(
98
+ ctx: AutoBeContext<Model>,
99
+ operations: AutoBeOpenApi.IOperation[],
100
+ oldbie: AutoBeOpenApi.IComponents,
101
+ remained: Set<string>,
102
+ ): Promise<AutoBeOpenApi.IComponents> {
103
+ const pointer: IPointer<AutoBeOpenApi.IComponents | null> = {
104
+ value: null,
105
+ };
106
+ const agentica: MicroAgentica<Model> = new MicroAgentica({
107
+ model: ctx.model,
108
+ vendor: ctx.vendor,
109
+ config: {
110
+ ...(ctx.config ?? {}),
111
+ executor: {
112
+ describe: null,
113
+ },
114
+ },
115
+ histories: [
116
+ ...transformInterfaceHistories(
117
+ ctx.state(),
118
+ AutoBeSystemPromptConstant.INTERFACE_SCHEMA,
119
+ ),
120
+ {
121
+ type: "assistantMessage",
122
+ text: [
123
+ "Here is the OpenAPI operations generated by phase 2.",
124
+ "",
125
+ "```json",
126
+ JSON.stringify(operations),
127
+ "```",
128
+ ].join("\n"),
129
+ },
130
+ ],
131
+ tokenUsage: ctx.usage(),
132
+ controllers: [
133
+ createApplication({
134
+ model: ctx.model,
135
+ build: async (components) => {
136
+ pointer.value = components;
137
+ },
138
+ pointer,
139
+ }),
140
+ ],
141
+ });
142
+ agentica.on("request", async (event) => {
143
+ event.body.tool_choice = "required";
144
+ });
145
+
146
+ const already: string[] = Object.keys(oldbie.schemas);
147
+ await agentica.conversate(
148
+ [
149
+ "Make type components please.",
150
+ "",
151
+ "Here is the list of request/response bodies' type names from",
152
+ "OpenAPI operations. Make type components of them. If more object",
153
+ "types are required during making the components, please make them",
154
+ "too.",
155
+ "",
156
+ ...Array.from(remained).map((k) => `- \`${k}\``),
157
+ ...(already.length !== 0
158
+ ? [
159
+ "",
160
+ "> By the way, here is the list of components schemas what you've",
161
+ "> already made. So, you don't need to make them again.",
162
+ ">",
163
+ ...already.map((k) => `> - \`${k}\``),
164
+ ]
165
+ : []),
166
+ ].join("\n"),
167
+ );
168
+ if (pointer.value === null) {
169
+ // never be happened
170
+ throw new Error("Failed to create components.");
171
+ }
172
+ return OpenApiV3_1Emender.convertComponents(
173
+ pointer.value,
174
+ ) as AutoBeOpenApi.IComponents;
175
+ }
176
+
177
+ function createApplication<Model extends ILlmSchema.Model>(props: {
178
+ model: Model;
179
+ build: (components: AutoBeOpenApi.IComponents) => Promise<void>;
180
+ pointer: IPointer<AutoBeOpenApi.IComponents | null>;
181
+ }): IAgenticaController.IClass<Model> {
182
+ assertSchemaModel(props.model);
183
+
184
+ const application: ILlmApplication<Model> = collection[
185
+ props.model
186
+ ] as unknown as ILlmApplication<Model>;
187
+ const validate = (next: unknown): IValidation => {
188
+ const result: IValidation<IMakeComponentsProps> =
189
+ typia.validate<IMakeComponentsProps>(next);
190
+ if (result.success === false) return result;
191
+ props.pointer.value = result.data.components;
192
+
193
+ const errors: IValidation.IError[] = [];
194
+ for (const value of Object.values(result.data.components.schemas)) {
195
+ OpenApiTypeChecker.visit({
196
+ components: result.data.components,
197
+ schema: value,
198
+ closure: (v) => {
199
+ if (OpenApiTypeChecker.isReference(v)) {
200
+ const key: string = v.$ref.split("/").at(-1)!;
201
+ if (result.data.components.schemas?.[key] === undefined)
202
+ errors.push({
203
+ path: `components.schemas.${key}`,
204
+ expected: "AutoBeOpenApi.IJsonSchemaDescriptive",
205
+ value: "undefined",
206
+ });
207
+ }
208
+ },
209
+ });
210
+ }
211
+ if (errors.length !== 0)
212
+ return {
213
+ success: false,
214
+ data: result.data,
215
+ errors,
216
+ };
217
+ return result;
218
+ };
219
+
220
+ application.functions[0].validate = validate;
221
+ return {
222
+ protocol: "class",
223
+ name: "interface",
224
+ application,
225
+ execute: {
226
+ makeComponents: async (next) => {
227
+ await props.build(next.components);
228
+ return {
229
+ success: true,
230
+ };
231
+ },
232
+ } satisfies IApplication,
233
+ };
234
+ }
235
+
236
+ const claude = typia.llm.application<
237
+ IApplication,
238
+ "claude",
239
+ { reference: true }
240
+ >();
241
+ const collection = {
242
+ chatgpt: typia.llm.application<
243
+ IApplication,
244
+ "chatgpt",
245
+ { reference: true }
246
+ >(),
247
+ claude,
248
+ llama: claude,
249
+ deepseek: claude,
250
+ "3.1": claude,
251
+ "3.0": typia.llm.application<IApplication, "3.0">(),
252
+ };
253
+
254
+ interface IApplication {
255
+ /**
256
+ * Generate OpenAPI components containing named schema types.
257
+ *
258
+ * This method receives a complete set of schema components and integrates
259
+ * them into the final OpenAPI specification. It processes all entity schemas,
260
+ * their variants, and related type definitions to ensure a comprehensive and
261
+ * consistent API design.
262
+ *
263
+ * The provided components should include schemas for all entities identified
264
+ * in the previous phases of API path/method definition and operation
265
+ * creation. This ensures that the final OpenAPI document has complete type
266
+ * coverage for all operations.
267
+ *
268
+ * CRITICAL: All schema definitions must follow the established naming
269
+ * conventions (IEntityName, IEntityName.ICreate, etc.) and must be thoroughly
270
+ * documented with descriptions that reference the original Prisma schema
271
+ * comments.
272
+ *
273
+ * @param props Properties containing components to generate.
274
+ */
275
+ makeComponents(props: IMakeComponentsProps): void;
276
+ }
277
+
278
+ interface IMakeComponentsProps {
279
+ /**
280
+ * Complete set of schema components for the OpenAPI specification.
281
+ *
282
+ * This property contains comprehensive type definitions for all entities in
283
+ * the system. It is the central repository of all named schema types that
284
+ * will be used throughout the API specification.
285
+ *
286
+ * CRITICAL REQUIREMENT: All object types MUST be defined as named types in
287
+ * the components.schemas section. Inline anonymous object definitions are
288
+ * strictly prohibited.
289
+ *
290
+ * This components object should include:
291
+ *
292
+ * - Main entity types (IEntityName)
293
+ * - Operation-specific variants (.ICreate, .IUpdate, .ISummary, etc.)
294
+ * - Container types (IPage<T> for pagination)
295
+ * - Enumeration types
296
+ *
297
+ * All schema definitions must include detailed descriptions that reference
298
+ * the original Prisma schema comments and thoroughly document each property.
299
+ * Every property that references an object must use a $ref to a named type in
300
+ * the components.schemas section. This applies to all objects in request
301
+ * bodies, response bodies, and properties that are objects or arrays of
302
+ * objects.
303
+ *
304
+ * Example structure:
305
+ *
306
+ * components: {
307
+ * schemas: {
308
+ * IUser: {
309
+ * type: "object",
310
+ * properties: {
311
+ * id: { type: "string", format: "uuid" },
312
+ * email: { type: "string", format: "email" },
313
+ * profile: { "$ref": "#/components/schemas/IUserProfile" }
314
+ * },
315
+ * required: ["id", "email"],
316
+ * description: "User entity representing system account holders..."
317
+ * },
318
+ * "IUser.ICreate": { ... },
319
+ * // Additional schemas
320
+ * }
321
+ * }
322
+ */
323
+ components: AutoBeOpenApi.IComponents;
324
+ }
@@ -0,0 +1,140 @@
1
+ import {
2
+ AgenticaAssistantMessageHistory,
3
+ IAgenticaController,
4
+ MicroAgentica,
5
+ MicroAgenticaHistory,
6
+ } from "@agentica/core";
7
+ import {
8
+ AutoBeAssistantMessageHistory,
9
+ AutoBeInterfaceEndpointsEvent,
10
+ AutoBeOpenApi,
11
+ } from "@autobe/interface";
12
+ import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
13
+ import { HashSet, IPointer } from "tstl";
14
+ import typia from "typia";
15
+ import { v4 } from "uuid";
16
+
17
+ import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
18
+ import { AutoBeContext } from "../../context/AutoBeContext";
19
+ import { assertSchemaModel } from "../../context/assertSchemaModel";
20
+ import { OpenApiEndpointComparator } from "./OpenApiEndpointComparator";
21
+ import { transformInterfaceHistories } from "./transformInterfaceHistories";
22
+
23
+ export async function orchestrateInterfaceEndpoints<
24
+ Model extends ILlmSchema.Model,
25
+ >(
26
+ ctx: AutoBeContext<Model>,
27
+ content: string = "Make API endpoints for the given assets.",
28
+ ): Promise<AutoBeInterfaceEndpointsEvent | AutoBeAssistantMessageHistory> {
29
+ const start: Date = new Date();
30
+ const pointer: IPointer<AutoBeOpenApi.IEndpoint[] | null> = {
31
+ value: null,
32
+ };
33
+ const agentica: MicroAgentica<Model> = new MicroAgentica({
34
+ model: ctx.model,
35
+ vendor: ctx.vendor,
36
+ config: {
37
+ ...(ctx.config ?? {}),
38
+ executor: {
39
+ describe: null,
40
+ },
41
+ },
42
+ histories: transformInterfaceHistories(
43
+ ctx.state(),
44
+ AutoBeSystemPromptConstant.INTERFACE_ENDPOINT,
45
+ ),
46
+ tokenUsage: ctx.usage(),
47
+ controllers: [
48
+ createApplication({
49
+ model: ctx.model,
50
+ build: async (endpoints) => {
51
+ pointer.value = endpoints;
52
+ },
53
+ }),
54
+ ],
55
+ });
56
+
57
+ const histories: MicroAgenticaHistory<Model>[] =
58
+ await agentica.conversate(content);
59
+ if (histories.at(-1)?.type === "assistantMessage")
60
+ return {
61
+ ...(histories.at(-1)! as AgenticaAssistantMessageHistory),
62
+ created_at: start.toISOString(),
63
+ completed_at: new Date().toISOString(),
64
+ id: v4(),
65
+ } satisfies AutoBeAssistantMessageHistory;
66
+ else if (pointer.value === null)
67
+ throw new Error("Failed to generate endpoints."); // unreachable
68
+ return {
69
+ type: "interfaceEndpoints",
70
+ endpoints: new HashSet(
71
+ pointer.value,
72
+ OpenApiEndpointComparator.hashCode,
73
+ OpenApiEndpointComparator.equals,
74
+ ).toJSON(),
75
+ created_at: start.toISOString(),
76
+ step: ctx.state().analyze?.step ?? 0,
77
+ } satisfies AutoBeInterfaceEndpointsEvent;
78
+ }
79
+
80
+ function createApplication<Model extends ILlmSchema.Model>(props: {
81
+ model: Model;
82
+ build: (endpoints: AutoBeOpenApi.IEndpoint[]) => Promise<void>;
83
+ }): IAgenticaController.IClass<Model> {
84
+ assertSchemaModel(props.model);
85
+
86
+ const application: ILlmApplication<Model> = collection[
87
+ props.model
88
+ ] as unknown as ILlmApplication<Model>;
89
+ return {
90
+ protocol: "class",
91
+ name: "interface",
92
+ application,
93
+ execute: {
94
+ makeEndpoints: async (next) => {
95
+ await props.build(next.endpoints);
96
+ return {
97
+ success: true,
98
+ };
99
+ },
100
+ } satisfies IApplication,
101
+ };
102
+ }
103
+
104
+ const claude = typia.llm.application<
105
+ IApplication,
106
+ "claude",
107
+ { reference: true }
108
+ >();
109
+ const collection = {
110
+ chatgpt: typia.llm.application<
111
+ IApplication,
112
+ "chatgpt",
113
+ { reference: true }
114
+ >(),
115
+ claude,
116
+ llama: claude,
117
+ deepseek: claude,
118
+ "3.1": claude,
119
+ "3.0": typia.llm.application<IApplication, "3.0">(),
120
+ };
121
+
122
+ interface IApplication {
123
+ /**
124
+ * Create Restful API endpoints.
125
+ *
126
+ * Create Restful API endpoints referencing the given documents; requirement
127
+ * analysis documents, and Prisma schema files with ERD descriptions. The API
128
+ * endpoints must cover every requirements and every entities in the ERD.
129
+ *
130
+ * Also, each combination of {@link AutoBeOpenApi.IEndpoint.path} and
131
+ * {@link AutoBeOpenApi.IEndpoint.method} must be unique to avoid duplicates.
132
+ * Please don't make any duplicates.
133
+ *
134
+ * @param props Properties containing the endpoints
135
+ */
136
+ makeEndpoints(props: {
137
+ /** List of endpoints to generate. */
138
+ endpoints: AutoBeOpenApi.IEndpoint[];
139
+ }): void;
140
+ }