@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
@@ -1,31 +1,47 @@
1
+ import { IAgenticaController, MicroAgentica } from "@agentica/core";
1
2
  import {
2
- AgenticaAssistantMessageHistory,
3
- IAgenticaController,
4
- MicroAgentica,
5
- MicroAgenticaHistory,
6
- } from "@agentica/core";
7
- import {
8
- AutoBeAssistantMessageHistory,
9
3
  AutoBeInterfaceEndpointsEvent,
10
4
  AutoBeOpenApi,
11
5
  } from "@autobe/interface";
6
+ import { AutoBeInterfaceGroup } from "@autobe/interface/src/histories/contents/AutoBeInterfaceGroup";
12
7
  import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
13
8
  import { HashSet, IPointer } from "tstl";
14
9
  import typia from "typia";
15
- import { v4 } from "uuid";
16
10
 
17
- import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
18
11
  import { AutoBeContext } from "../../context/AutoBeContext";
19
12
  import { assertSchemaModel } from "../../context/assertSchemaModel";
20
- import { OpenApiEndpointComparator } from "./OpenApiEndpointComparator";
21
- import { transformInterfaceHistories } from "./transformInterfaceHistories";
13
+ import { enforceToolCall } from "../../utils/enforceToolCall";
14
+ import { transformInterfaceEndpointHistories } from "./histories/transformInterfaceEndpointHistories";
15
+ import { IAutoBeInterfaceEndpointApplication } from "./structures/IAutoBeInterfaceEndpointApplication";
16
+ import { OpenApiEndpointComparator } from "./utils/OpenApiEndpointComparator";
22
17
 
23
18
  export async function orchestrateInterfaceEndpoints<
24
19
  Model extends ILlmSchema.Model,
25
20
  >(
26
21
  ctx: AutoBeContext<Model>,
27
- content: string = "Make API endpoints for the given assets.",
28
- ): Promise<AutoBeInterfaceEndpointsEvent | AutoBeAssistantMessageHistory> {
22
+ groups: AutoBeInterfaceGroup[],
23
+ content: string = `Make endpoints for the given assets`,
24
+ ): Promise<AutoBeOpenApi.IEndpoint[]> {
25
+ const progress: IProgress = {
26
+ total: groups.length,
27
+ completed: 0,
28
+ };
29
+ const endpoints: AutoBeOpenApi.IEndpoint[] = (
30
+ await Promise.all(groups.map((g) => process(ctx, g, content, progress)))
31
+ ).flat();
32
+ return new HashSet(
33
+ endpoints,
34
+ OpenApiEndpointComparator.hashCode,
35
+ OpenApiEndpointComparator.equals,
36
+ ).toJSON();
37
+ }
38
+
39
+ async function process<Model extends ILlmSchema.Model>(
40
+ ctx: AutoBeContext<Model>,
41
+ group: AutoBeInterfaceGroup,
42
+ content: string,
43
+ progress: IProgress,
44
+ ): Promise<AutoBeOpenApi.IEndpoint[]> {
29
45
  const start: Date = new Date();
30
46
  const pointer: IPointer<AutoBeOpenApi.IEndpoint[] | null> = {
31
47
  value: null,
@@ -39,10 +55,7 @@ export async function orchestrateInterfaceEndpoints<
39
55
  describe: null,
40
56
  },
41
57
  },
42
- histories: transformInterfaceHistories(
43
- ctx.state(),
44
- AutoBeSystemPromptConstant.INTERFACE_ENDPOINT,
45
- ),
58
+ histories: transformInterfaceEndpointHistories(ctx.state(), group),
46
59
  controllers: [
47
60
  createApplication({
48
61
  model: ctx.model,
@@ -53,23 +66,14 @@ export async function orchestrateInterfaceEndpoints<
53
66
  }),
54
67
  ],
55
68
  });
69
+ enforceToolCall(agentica);
56
70
 
57
- const histories: MicroAgenticaHistory<Model>[] = await agentica
58
- .conversate(content)
59
- .finally(() => {
60
- const tokenUsage = agentica.getTokenUsage();
61
- ctx.usage().record(tokenUsage, ["interface"]);
62
- });
63
- if (histories.at(-1)?.type === "assistantMessage")
64
- return {
65
- ...(histories.at(-1)! as AgenticaAssistantMessageHistory),
66
- created_at: start.toISOString(),
67
- completed_at: new Date().toISOString(),
68
- id: v4(),
69
- } satisfies AutoBeAssistantMessageHistory;
70
- else if (pointer.value === null)
71
- throw new Error("Failed to generate endpoints."); // unreachable
72
- return {
71
+ await agentica.conversate(content).finally(() => {
72
+ const tokenUsage = agentica.getTokenUsage();
73
+ ctx.usage().record(tokenUsage, ["interface"]);
74
+ });
75
+ if (pointer.value === null) throw new Error("Failed to generate endpoints."); // unreachable
76
+ const event: AutoBeInterfaceEndpointsEvent = {
73
77
  type: "interfaceEndpoints",
74
78
  endpoints: new HashSet(
75
79
  pointer.value,
@@ -78,7 +82,11 @@ export async function orchestrateInterfaceEndpoints<
78
82
  ).toJSON(),
79
83
  created_at: start.toISOString(),
80
84
  step: ctx.state().analyze?.step ?? 0,
81
- } satisfies AutoBeInterfaceEndpointsEvent;
85
+ completed: ++progress.completed,
86
+ total: progress.total,
87
+ };
88
+ ctx.dispatch(event);
89
+ return pointer.value;
82
90
  }
83
91
 
84
92
  function createApplication<Model extends ILlmSchema.Model>(props: {
@@ -98,18 +106,18 @@ function createApplication<Model extends ILlmSchema.Model>(props: {
98
106
  makeEndpoints: (next) => {
99
107
  props.build(next.endpoints);
100
108
  },
101
- } satisfies IApplication,
109
+ } satisfies IAutoBeInterfaceEndpointApplication,
102
110
  };
103
111
  }
104
112
 
105
113
  const claude = typia.llm.application<
106
- IApplication,
114
+ IAutoBeInterfaceEndpointApplication,
107
115
  "claude",
108
116
  { reference: true }
109
117
  >();
110
118
  const collection = {
111
119
  chatgpt: typia.llm.application<
112
- IApplication,
120
+ IAutoBeInterfaceEndpointApplication,
113
121
  "chatgpt",
114
122
  { reference: true }
115
123
  >(),
@@ -119,22 +127,7 @@ const collection = {
119
127
  "3.1": claude,
120
128
  };
121
129
 
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;
130
+ interface IProgress {
131
+ total: number;
132
+ completed: number;
140
133
  }
@@ -0,0 +1,109 @@
1
+ import {
2
+ IAgenticaController,
3
+ MicroAgentica,
4
+ MicroAgenticaHistory,
5
+ } from "@agentica/core";
6
+ import {
7
+ AutoBeAssistantMessageHistory,
8
+ AutoBeInterfaceGroupsEvent,
9
+ } from "@autobe/interface";
10
+ import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
11
+ import { IPointer } from "tstl";
12
+ import typia from "typia";
13
+ import { v4 } from "uuid";
14
+
15
+ import { AutoBeContext } from "../../context/AutoBeContext";
16
+ import { assertSchemaModel } from "../../context/assertSchemaModel";
17
+ import { transformInterfaceGroupHistories } from "./histories/transformInterfaceGroupHistories";
18
+ import { IAutoBeInterfaceGroupApplication } from "./structures/IAutoBeInterfaceGroupApplication";
19
+
20
+ export async function orchestrateInterfaceGroups<
21
+ Model extends ILlmSchema.Model,
22
+ >(
23
+ ctx: AutoBeContext<Model>,
24
+ content: string = "Design API operations for the given assets.",
25
+ ): Promise<AutoBeAssistantMessageHistory | AutoBeInterfaceGroupsEvent> {
26
+ const start: Date = new Date();
27
+ const pointer: IPointer<IAutoBeInterfaceGroupApplication.IProps | null> = {
28
+ value: null,
29
+ };
30
+ const agentica: MicroAgentica<Model> = new MicroAgentica({
31
+ model: ctx.model,
32
+ vendor: ctx.vendor,
33
+ config: {
34
+ ...(ctx.config ?? {}),
35
+ executor: {
36
+ describe: null,
37
+ },
38
+ },
39
+ histories: transformInterfaceGroupHistories(ctx.state()),
40
+ controllers: [
41
+ createApplication({
42
+ model: ctx.model,
43
+ build: (next) => {
44
+ pointer.value = next;
45
+ },
46
+ }),
47
+ ],
48
+ });
49
+
50
+ const histories: MicroAgenticaHistory<Model>[] = await agentica
51
+ .conversate(content)
52
+ .finally(() => {
53
+ const tokenUsage = agentica.getTokenUsage();
54
+ ctx.usage().record(tokenUsage, ["interface"]);
55
+ });
56
+ const last: MicroAgenticaHistory<Model> = histories.at(-1)!;
57
+ if (last.type === "assistantMessage")
58
+ return {
59
+ ...last,
60
+ created_at: start.toISOString(),
61
+ completed_at: new Date().toISOString(),
62
+ id: v4(),
63
+ } satisfies AutoBeAssistantMessageHistory;
64
+ else if (pointer.value === null)
65
+ throw new Error("Failed to generate groups."); // unreachable
66
+ return {
67
+ type: "interfaceGroups",
68
+ created_at: start.toISOString(),
69
+ groups: pointer.value.groups,
70
+ step: ctx.state().analyze?.step ?? 0,
71
+ } satisfies AutoBeInterfaceGroupsEvent;
72
+ }
73
+
74
+ function createApplication<Model extends ILlmSchema.Model>(props: {
75
+ model: Model;
76
+ build: (next: IAutoBeInterfaceGroupApplication.IProps) => void;
77
+ }): IAgenticaController.IClass<Model> {
78
+ assertSchemaModel(props.model);
79
+
80
+ const application: ILlmApplication<Model> = collection[
81
+ props.model
82
+ ] as unknown as ILlmApplication<Model>;
83
+ return {
84
+ protocol: "class",
85
+ name: "interface",
86
+ application,
87
+ execute: {
88
+ makeGroups: (next) => {
89
+ props.build(next);
90
+ },
91
+ } satisfies IAutoBeInterfaceGroupApplication,
92
+ };
93
+ }
94
+
95
+ const claude = typia.llm.application<
96
+ IAutoBeInterfaceGroupApplication,
97
+ "claude"
98
+ >();
99
+ const chatgpt = typia.llm.application<
100
+ IAutoBeInterfaceGroupApplication,
101
+ "chatgpt"
102
+ >();
103
+ const collection = {
104
+ chatgpt,
105
+ claude,
106
+ llama: claude,
107
+ deepseek: claude,
108
+ "3.1": claude,
109
+ };
@@ -3,15 +3,16 @@ import { AutoBeOpenApi } from "@autobe/interface";
3
3
  import { ILlmApplication, ILlmSchema, IValidation } from "@samchon/openapi";
4
4
  import { HashMap, HashSet, IPointer } from "tstl";
5
5
  import typia from "typia";
6
+ import { NamingConvention } from "typia/lib/utils/NamingConvention";
6
7
 
7
- import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
8
8
  import { AutoBeContext } from "../../context/AutoBeContext";
9
9
  import { assertSchemaModel } from "../../context/assertSchemaModel";
10
10
  import { divideArray } from "../../utils/divideArray";
11
11
  import { enforceToolCall } from "../../utils/enforceToolCall";
12
12
  import { forceRetry } from "../../utils/forceRetry";
13
- import { OpenApiEndpointComparator } from "./OpenApiEndpointComparator";
14
- import { transformInterfaceHistories } from "./transformInterfaceHistories";
13
+ import { transformInterfaceOperationHistories } from "./histories/transformInterfaceOperationHistories";
14
+ import { IAutoBeInterfaceOperationApplication } from "./structures/IAutoBeInterfaceOperationApplication";
15
+ import { OpenApiEndpointComparator } from "./utils/OpenApiEndpointComparator";
15
16
 
16
17
  export async function orchestrateInterfaceOperations<
17
18
  Model extends ILlmSchema.Model,
@@ -24,22 +25,22 @@ export async function orchestrateInterfaceOperations<
24
25
  array: endpoints,
25
26
  capacity,
26
27
  });
27
- let completed: number = 0;
28
+ const progress: IProgress = {
29
+ total: endpoints.length,
30
+ completed: 0,
31
+ };
28
32
  const operations: AutoBeOpenApi.IOperation[][] = await Promise.all(
29
33
  matrix.map(async (it) => {
30
34
  const row: AutoBeOpenApi.IOperation[] = await divideAndConquer(
31
35
  ctx,
32
36
  it,
33
37
  3,
34
- (count) => {
35
- completed += count;
36
- },
38
+ progress,
37
39
  );
38
40
  ctx.dispatch({
39
41
  type: "interfaceOperations",
40
42
  operations: row,
41
- completed,
42
- total: endpoints.length,
43
+ ...progress,
43
44
  step: ctx.state().analyze?.step ?? 0,
44
45
  created_at: new Date().toISOString(),
45
46
  });
@@ -53,7 +54,7 @@ async function divideAndConquer<Model extends ILlmSchema.Model>(
53
54
  ctx: AutoBeContext<Model>,
54
55
  endpoints: AutoBeOpenApi.IEndpoint[],
55
56
  retry: number,
56
- progress: (completed: number) => void,
57
+ progress: IProgress,
57
58
  ): Promise<AutoBeOpenApi.IOperation[]> {
58
59
  const remained: HashSet<AutoBeOpenApi.IEndpoint> = new HashSet(
59
60
  endpoints,
@@ -68,15 +69,13 @@ async function divideAndConquer<Model extends ILlmSchema.Model>(
68
69
  for (let i: number = 0; i < retry; ++i) {
69
70
  if (remained.empty() === true || operations.size() >= endpoints.length)
70
71
  break;
71
- const before: number = operations.size();
72
72
  const newbie: AutoBeOpenApi.IOperation[] = await forceRetry(() =>
73
- process(ctx, Array.from(remained)),
73
+ process(ctx, Array.from(remained), progress),
74
74
  );
75
75
  for (const item of newbie) {
76
76
  operations.set(item, item);
77
77
  remained.erase(item);
78
78
  }
79
- if (operations.size() - before !== 0) progress(operations.size() - before);
80
79
  }
81
80
  return operations.toJSON().map((it) => it.second);
82
81
  }
@@ -84,11 +83,12 @@ async function divideAndConquer<Model extends ILlmSchema.Model>(
84
83
  async function process<Model extends ILlmSchema.Model>(
85
84
  ctx: AutoBeContext<Model>,
86
85
  endpoints: AutoBeOpenApi.IEndpoint[],
86
+ progress: IProgress,
87
87
  ): Promise<AutoBeOpenApi.IOperation[]> {
88
+ const prefix: string = NamingConvention.camel(ctx.state().analyze!.prefix);
88
89
  const pointer: IPointer<AutoBeOpenApi.IOperation[] | null> = {
89
90
  value: null,
90
91
  };
91
-
92
92
  const agentica: MicroAgentica<Model> = new MicroAgentica({
93
93
  model: ctx.model,
94
94
  vendor: ctx.vendor,
@@ -98,65 +98,74 @@ async function process<Model extends ILlmSchema.Model>(
98
98
  describe: null,
99
99
  },
100
100
  },
101
- histories: transformInterfaceHistories(
102
- ctx.state(),
103
- AutoBeSystemPromptConstant.INTERFACE_ENDPOINT,
104
- ),
101
+ histories: transformInterfaceOperationHistories(ctx.state(), endpoints),
105
102
  controllers: [
106
103
  createApplication({
107
104
  model: ctx.model,
108
- roles: ctx.state().analyze?.roles.map((it) => it.name) ?? null,
109
- build: (endpoints) => {
105
+ roles: ctx.state().analyze?.roles.map((it) => it.name) ?? [],
106
+ build: (operations) => {
110
107
  pointer.value ??= [];
111
- pointer.value.push(...endpoints);
108
+ const matrix: AutoBeOpenApi.IOperation[][] = operations.map((op) => {
109
+ if (op.authorizationRoles.length === 0)
110
+ return [
111
+ {
112
+ ...op,
113
+ path:
114
+ "/" +
115
+ [prefix, ...op.path.split("/")]
116
+ .filter((it) => it !== "")
117
+ .join("/"),
118
+ authorizationRole: null,
119
+ },
120
+ ];
121
+ return op.authorizationRoles.map((role) => ({
122
+ ...op,
123
+ path:
124
+ "/" +
125
+ [prefix, role, ...op.path.split("/")]
126
+ .filter((it) => it !== "")
127
+ .join("/"),
128
+ authorizationRole: role,
129
+ }));
130
+ });
131
+ progress.completed += matrix.flat().length;
132
+ progress.total += matrix
133
+ .filter((it) => it.length > 1)
134
+ .map((it) => it.length - 1)
135
+ .reduce((a, b) => a + b, 0);
136
+ pointer.value.push(...matrix.flat());
112
137
  },
113
138
  }),
114
139
  ],
115
140
  });
116
141
  enforceToolCall(agentica);
117
- await agentica
118
- .conversate(
119
- [
120
- "Make API operations for below endpoints:",
121
- "",
122
- "**CRITICAL INSTRUCTIONS**:",
123
- "1. Base ALL operation descriptions on ACTUAL fields in the Prisma schema",
124
- "2. NEVER reference fields that don't exist (e.g., deleted_at, created_by, updated_by)",
125
- "3. For DELETE operations:",
126
- " - Check if the entity has soft delete fields in the schema",
127
- " - If YES: Describe soft delete behavior using those fields",
128
- " - If NO: Describe hard delete behavior (permanent removal)",
129
- "4. Every field mentioned in descriptions MUST exist in the Prisma schema",
130
- "",
131
- "```json",
132
- JSON.stringify(Array.from(endpoints), null, 2),
133
- "```",
134
- ].join("\n"),
135
- )
136
- .finally(() => {
137
- const tokenUsage = agentica.getTokenUsage();
138
- ctx.usage().record(tokenUsage, ["interface"]);
139
- });
142
+ await agentica.conversate("Make API operations").finally(() => {
143
+ const tokenUsage = agentica.getTokenUsage();
144
+ ctx.usage().record(tokenUsage, ["interface"]);
145
+ });
140
146
  if (pointer.value === null) throw new Error("Failed to create operations."); // never be happened
141
147
  return pointer.value;
142
148
  }
143
149
 
144
150
  function createApplication<Model extends ILlmSchema.Model>(props: {
145
151
  model: Model;
146
- roles: string[] | null;
147
- build: (operations: AutoBeOpenApi.IOperation[]) => void;
152
+ roles: string[];
153
+ build: (
154
+ operations: IAutoBeInterfaceOperationApplication.IOperation[],
155
+ ) => void;
148
156
  }): IAgenticaController.IClass<Model> {
149
157
  assertSchemaModel(props.model);
150
158
 
151
159
  const application: ILlmApplication<Model> = collection[
152
160
  props.model
153
161
  ] as unknown as ILlmApplication<Model>;
154
- application.functions[0].validate = (next: unknown): IValidation => {
155
- const result: IValidation<IMakeOperationProps> =
156
- typia.validate<IMakeOperationProps>(next);
162
+ application.functions[0].validate = (next: unknown) => {
163
+ const result: IValidation<IAutoBeInterfaceOperationApplication.IProps> =
164
+ typia.validate<IAutoBeInterfaceOperationApplication.IProps>(next);
157
165
  if (result.success === false) return result;
158
166
 
159
- const operations: AutoBeOpenApi.IOperation[] = result.data.operations;
167
+ const operations: IAutoBeInterfaceOperationApplication.IOperation[] =
168
+ result.data.operations;
160
169
  const errors: IValidation.IError[] = [];
161
170
  operations.forEach((op, i) => {
162
171
  if (op.method === "get" && op.requestBody !== null)
@@ -166,23 +175,22 @@ function createApplication<Model extends ILlmSchema.Model>(props: {
166
175
  "GET method should not have request body. Change method, or re-design the operation.",
167
176
  value: op.requestBody,
168
177
  });
169
- if (props.roles === null) op.authorizationRole = null;
170
- else if (
171
- op.authorizationRole !== null &&
172
- !!props.roles?.length &&
173
- props.roles.find((it) => it === op.authorizationRole) === undefined
174
- )
175
- errors.push({
176
- path: `$input.operations[${i}].authorizationRole`,
177
- expected: `null | ${props.roles.map((str) => JSON.stringify(str)).join(" | ")}`,
178
- description: [
179
- `Role "${op.authorizationRole}" is not defined in the roles list.`,
180
- "",
181
- "Please select one of them below, or do not define (`null`): ",
182
- "",
183
- ...(props.roles ?? []).map((role) => `- ${role}`),
184
- ].join("\n"),
185
- value: op.authorizationRole,
178
+ if (props.roles.length === 0) op.authorizationRoles = [];
179
+ else if (op.authorizationRoles.length !== 0 && props.roles.length !== 0)
180
+ op.authorizationRoles.forEach((role, j) => {
181
+ if (props.roles.includes(role) === true) return;
182
+ errors.push({
183
+ path: `$input.operations[${i}].authorizationRoles[${j}]`,
184
+ expected: `null | ${props.roles.map((str) => JSON.stringify(str)).join(" | ")}`,
185
+ description: [
186
+ `Role "${role}" is not defined in the roles list.`,
187
+ "",
188
+ "Please select one of them below, or do not define (`null`): ",
189
+ "",
190
+ ...props.roles.map((role) => `- ${role}`),
191
+ ].join("\n"),
192
+ value: role,
193
+ });
186
194
  });
187
195
  });
188
196
  if (errors.length !== 0)
@@ -201,18 +209,18 @@ function createApplication<Model extends ILlmSchema.Model>(props: {
201
209
  makeOperations: (next) => {
202
210
  props.build(next.operations);
203
211
  },
204
- } satisfies IApplication,
212
+ } satisfies IAutoBeInterfaceOperationApplication,
205
213
  };
206
214
  }
207
215
 
208
216
  const claude = typia.llm.application<
209
- IApplication,
217
+ IAutoBeInterfaceOperationApplication,
210
218
  "claude",
211
219
  { reference: true }
212
220
  >();
213
221
  const collection = {
214
222
  chatgpt: typia.llm.application<
215
- IApplication,
223
+ IAutoBeInterfaceOperationApplication,
216
224
  "chatgpt",
217
225
  { reference: true }
218
226
  >(),
@@ -222,54 +230,7 @@ const collection = {
222
230
  "3.1": claude,
223
231
  };
224
232
 
225
- interface IApplication {
226
- /**
227
- * Generate detailed API operations from path/method combinations.
228
- *
229
- * This function creates complete API operations following REST principles and
230
- * quality standards. Each generated operation includes specification, path,
231
- * method, detailed multi-paragraph description, concise summary, parameters,
232
- * and appropriate request/response bodies.
233
- *
234
- * The function processes as many operations as possible in a single call,
235
- * with progress tracking to ensure iterative completion of all required
236
- * endpoints.
237
- *
238
- * @param props Properties containing the operations to generate.
239
- */
240
- makeOperations(props: IMakeOperationProps): void;
241
- }
242
-
243
- interface IMakeOperationProps {
244
- /**
245
- * Array of API operations to generate.
246
- *
247
- * Each operation in this array must include:
248
- *
249
- * - Specification: Detailed API specification with clear purpose and
250
- * functionality
251
- * - Path: Resource-centric URL path (e.g., "/resources/{resourceId}")
252
- * - Method: HTTP method (get, post, put, delete, patch)
253
- * - Description: Extremely detailed multi-paragraph description referencing
254
- * Prisma schema comments
255
- * - Summary: Concise one-sentence summary of the endpoint
256
- * - Parameters: Array of all necessary parameters with descriptions and schema
257
- * definitions
258
- * - RequestBody: For POST/PUT/PATCH methods, with typeName referencing
259
- * components.schemas
260
- * - ResponseBody: With typeName referencing appropriate response type
261
- *
262
- * All operations must follow strict quality standards:
263
- *
264
- * 1. Detailed descriptions referencing Prisma schema comments
265
- * 2. Accurate parameter definitions matching path parameters
266
- * 3. Appropriate request/response body type references
267
- * 4. Consistent patterns for CRUD operations
268
- *
269
- * For list retrievals (typically PATCH), include pagination, search, and
270
- * sorting. For detail retrieval (GET), return a single resource. For creation
271
- * (POST), use .ICreate request body. For modification (PUT), use .IUpdate
272
- * request body.
273
- */
274
- operations: AutoBeOpenApi.IOperation[];
233
+ interface IProgress {
234
+ completed: number;
235
+ total: number;
275
236
  }