@autobe/agent 0.0.0 → 0.3.9

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
@@ -0,0 +1,194 @@
1
+ import { IAgenticaController, MicroAgentica } from "@agentica/core";
2
+ import { IAutoBePrismaCompilerResult } from "@autobe/interface";
3
+ import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
4
+ import { IPointer } from "tstl";
5
+ import typia from "typia";
6
+
7
+ import { AutoBeContext } from "../../context/AutoBeContext";
8
+ import { assertSchemaModel } from "../../context/assertSchemaModel";
9
+ import { transformPrismaCompilerHistories } from "./transformPrismaCompilerHistories";
10
+
11
+ export async function orchestratePrismaCompiler<Model extends ILlmSchema.Model>(
12
+ ctx: AutoBeContext<Model>,
13
+ files: Record<string, string>,
14
+ retry: number = 10,
15
+ ): Promise<IAutoBePrismaCompilerResult & { description: string }> {
16
+ const pointer: IPointer<IModifyPrismaSchemaFilesProps> = {
17
+ value: { files, description: "" },
18
+ };
19
+ const agentica: MicroAgentica<Model> = new MicroAgentica({
20
+ model: ctx.model,
21
+ vendor: ctx.vendor,
22
+ config: {
23
+ ...(ctx.config ?? {}),
24
+ },
25
+ histories: transformPrismaCompilerHistories(ctx.state(), files),
26
+ tokenUsage: ctx.usage(),
27
+ controllers: [
28
+ createApplication({
29
+ model: ctx.model,
30
+ build: (next) => {
31
+ pointer.value = next;
32
+ },
33
+ }),
34
+ ],
35
+ });
36
+
37
+ agentica.on("request", (event) => {
38
+ if (event.body.tools) {
39
+ event.body.tool_choice = "required";
40
+ }
41
+ });
42
+
43
+ let result: IAutoBePrismaCompilerResult;
44
+
45
+ for (let i: number = 0; i < retry; ++i) {
46
+ result = await ctx.compiler.prisma({
47
+ files: pointer.value?.files ?? files,
48
+ });
49
+
50
+ if (result.type !== "failure") break;
51
+ ctx.dispatch({
52
+ type: "prismaValidate",
53
+ schemas: files,
54
+ result,
55
+ step: ctx.state().analyze?.step ?? 0,
56
+ created_at: new Date().toISOString(),
57
+ });
58
+
59
+ await agentica.conversate(
60
+ [
61
+ "The Prisma schema files have compilation errors that must be fixed. You MUST provide complete, corrected files.",
62
+ "",
63
+ "============================================== CURRENT FILES ==============================================",
64
+ "",
65
+ ...Object.entries(pointer.value?.files ?? files).flatMap(
66
+ ([filename, content]) => [`### ${filename} ###`, content, ""],
67
+ ),
68
+ "",
69
+ "============================================== COMPILATION ERRORS ==============================================",
70
+ "",
71
+ result.reason,
72
+ "",
73
+ "============================================== REQUIREMENTS ==============================================",
74
+ "",
75
+ "CRITICAL: You must call the modifyPrismaSchemaFiles function with:",
76
+ "",
77
+ "1. **COMPLETE file contents** - Do NOT truncate or abbreviate any content",
78
+ "2. **ALL files** - Every file from the input must be included in the output",
79
+ "3. **Fixed errors** - Resolve all compilation errors shown above",
80
+ "4. **Preserved structure** - Keep all models, fields, relationships, and comments",
81
+ "5. **Proper syntax** - Ensure valid Prisma schema syntax",
82
+ "",
83
+ "IMPORTANT NOTES:",
84
+ "- Include the ENTIRE content of each file, not summaries or truncated versions",
85
+ "- Maintain all existing relationships between models",
86
+ "- Keep all field definitions, attributes, and indexes",
87
+ "- Preserve all comments and documentation",
88
+ "- Fix ONLY the compilation errors, don't make unnecessary changes",
89
+ "",
90
+ "Example of what NOT to do:",
91
+ "```",
92
+ "// ... (truncated for brevity)",
93
+ "// ... other fields and relationships",
94
+ "// ... unchanged ...",
95
+ "```",
96
+ "",
97
+ "You must provide the COMPLETE file content for each file.",
98
+ ].join("\n"),
99
+ );
100
+
101
+ if (i === retry - 1) {
102
+ throw new Error("Prisma schema compiler failed");
103
+ }
104
+ }
105
+
106
+ return { ...result!, description: pointer.value.description };
107
+ }
108
+
109
+ function createApplication<Model extends ILlmSchema.Model>(props: {
110
+ model: Model;
111
+ build: (next: IModifyPrismaSchemaFilesProps) => void;
112
+ }): IAgenticaController.IClass<Model> {
113
+ assertSchemaModel(props.model);
114
+ const application: ILlmApplication<Model> = collection[
115
+ props.model
116
+ ] as unknown as ILlmApplication<Model>;
117
+ return {
118
+ protocol: "class",
119
+ name: "Prisma Compiler",
120
+ application,
121
+ execute: {
122
+ modifyPrismaSchemaFiles: (next) => {
123
+ props.build(next);
124
+ },
125
+ } satisfies IApplication,
126
+ };
127
+ }
128
+
129
+ const claude = typia.llm.application<
130
+ IApplication,
131
+ "claude",
132
+ { reference: true }
133
+ >();
134
+ const collection = {
135
+ chatgpt: typia.llm.application<
136
+ IApplication,
137
+ "chatgpt",
138
+ { reference: true }
139
+ >(),
140
+ claude,
141
+ llama: claude,
142
+ deepseek: claude,
143
+ "3.1": claude,
144
+ "3.0": typia.llm.application<IApplication, "3.0">(),
145
+ };
146
+
147
+ interface IApplication {
148
+ /**
149
+ * Fixes compilation errors in Prisma schema files.
150
+ *
151
+ * CRITICAL: This function must return COMPLETE file contents, not truncated
152
+ * versions.
153
+ *
154
+ * Responsibilities:
155
+ *
156
+ * 1. Analyze compilation errors in the provided schema files
157
+ * 2. Fix all syntax and structural issues
158
+ * 3. Return COMPLETE corrected files (no truncation or abbreviation)
159
+ * 4. Preserve all existing models, relationships, and business logic
160
+ * 5. Maintain proper cross-file references and dependencies
161
+ *
162
+ * @param props Contains files to fix and requires complete file contents in
163
+ * response
164
+ */
165
+ modifyPrismaSchemaFiles(props: IModifyPrismaSchemaFilesProps): void;
166
+ }
167
+
168
+ interface IModifyPrismaSchemaFilesProps {
169
+ /**
170
+ * COMPLETE Prisma schema files with ALL content included.
171
+ *
172
+ * CRITICAL REQUIREMENTS:
173
+ *
174
+ * - Each file must contain the ENTIRE schema content
175
+ * - Do NOT truncate, abbreviate, or use placeholders like "... unchanged ..."
176
+ * - Include ALL models, fields, relationships, indexes, and comments
177
+ * - Maintain exact same file organization and naming
178
+ *
179
+ * File organization patterns:
180
+ *
181
+ * - Main.prisma: Configuration, datasource, generators
182
+ * - Schema-XX-domain.prisma: Complete domain-specific models with ALL fields
183
+ *
184
+ * Key = filename (e.g., "main.prisma", "schema-01-core.prisma") Value =
185
+ * COMPLETE file content (no truncation allowed)
186
+ */
187
+ files: Record<string, string>;
188
+
189
+ /**
190
+ * Brief description of what was fixed or modified in the schema files. Should
191
+ * summarize the changes made to resolve compilation errors.
192
+ */
193
+ description: string;
194
+ }
@@ -0,0 +1,176 @@
1
+ import {
2
+ AgenticaAssistantMessageHistory,
3
+ IAgenticaController,
4
+ MicroAgentica,
5
+ MicroAgenticaHistory,
6
+ } from "@agentica/core";
7
+ import { AutoBeAssistantMessageHistory } from "@autobe/interface";
8
+ import { AutoBePrismaComponentsEvent } from "@autobe/interface/src/events/AutoBePrismaComponentsEvent";
9
+ import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
10
+ import { IPointer } from "tstl";
11
+ import typia from "typia";
12
+ import { v4 } from "uuid";
13
+
14
+ import { AutoBeContext } from "../../context/AutoBeContext";
15
+ import { assertSchemaModel } from "../../context/assertSchemaModel";
16
+ import { transformPrismaComponentsHistories } from "./transformPrismaComponentsHistories";
17
+
18
+ export async function orchestratePrismaComponents<
19
+ Model extends ILlmSchema.Model,
20
+ >(
21
+ ctx: AutoBeContext<Model>,
22
+ content: string = "Please extract files and tables from the given documents.",
23
+ ): Promise<AutoBeAssistantMessageHistory | AutoBePrismaComponentsEvent> {
24
+ const start: Date = new Date();
25
+ const pointer: IPointer<IExtractComponentsProps | null> = {
26
+ value: null,
27
+ };
28
+ const agentica: MicroAgentica<Model> = new MicroAgentica({
29
+ model: ctx.model,
30
+ vendor: ctx.vendor,
31
+ config: {
32
+ ...(ctx.config ?? {}),
33
+ },
34
+ histories: transformPrismaComponentsHistories(ctx.state()),
35
+ tokenUsage: ctx.usage(),
36
+ controllers: [
37
+ createApplication({
38
+ model: ctx.model,
39
+ build: (next) => {
40
+ pointer.value = next;
41
+ },
42
+ }),
43
+ ],
44
+ });
45
+
46
+ const histories: MicroAgenticaHistory<Model>[] =
47
+ await agentica.conversate(content);
48
+ if (histories.at(-1)?.type === "assistantMessage")
49
+ return {
50
+ ...(histories.at(-1)! as AgenticaAssistantMessageHistory),
51
+ created_at: start.toISOString(),
52
+ completed_at: new Date().toISOString(),
53
+ id: v4(),
54
+ } satisfies AutoBeAssistantMessageHistory;
55
+ else if (pointer.value === null) {
56
+ throw new Error("Failed to extract files and tables."); // unreachable
57
+ }
58
+ return {
59
+ type: "prismaComponents",
60
+ created_at: start.toISOString(),
61
+ components: pointer.value.components,
62
+ step: ctx.state().analyze?.step ?? 0,
63
+ };
64
+ }
65
+
66
+ function createApplication<Model extends ILlmSchema.Model>(props: {
67
+ model: Model;
68
+ build: (next: IExtractComponentsProps) => void;
69
+ }): IAgenticaController.IClass<Model> {
70
+ assertSchemaModel(props.model);
71
+
72
+ const application: ILlmApplication<Model> = collection[
73
+ props.model
74
+ ] as unknown as ILlmApplication<Model>;
75
+ return {
76
+ protocol: "class",
77
+ name: "Prisma Extract Files and Tables",
78
+ application,
79
+ execute: {
80
+ extractComponents: (next) => {
81
+ props.build(next);
82
+ },
83
+ } satisfies IApplication,
84
+ };
85
+ }
86
+
87
+ const claude = typia.llm.application<
88
+ IApplication,
89
+ "claude",
90
+ { reference: true }
91
+ >();
92
+ const collection = {
93
+ chatgpt: typia.llm.application<
94
+ IApplication,
95
+ "chatgpt",
96
+ { reference: true }
97
+ >(),
98
+ claude,
99
+ llama: claude,
100
+ deepseek: claude,
101
+ "3.1": claude,
102
+ "3.0": typia.llm.application<IApplication, "3.0">(),
103
+ };
104
+
105
+ interface IApplication {
106
+ /**
107
+ * Extracts and organizes database schema files with their corresponding table
108
+ * definitions.
109
+ *
110
+ * Processes Prisma schema files and maps each file to its contained database
111
+ * tables, enabling structured organization of schemas across multiple files
112
+ * for large projects.
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * application.extractFilesAndTables({
117
+ * components: [
118
+ * {
119
+ * filename: "schema-01-users.prisma",
120
+ * tables: ["user", "user_profile"]
121
+ * },
122
+ * {
123
+ * filename: "schema-02-articles.prisma",
124
+ * tables: ["article", "attachment_file"]
125
+ * }
126
+ * ]
127
+ * });
128
+ * ```;
129
+ *
130
+ * @param props - Configuration object containing the file-to-table mapping
131
+ * structure
132
+ */
133
+ extractComponents(props: IExtractComponentsProps): void;
134
+ }
135
+
136
+ interface IExtractComponentsProps {
137
+ /**
138
+ * Maps Prisma schema filenames to their contained database tables.
139
+ *
140
+ * **Structure:**
141
+ *
142
+ * - Key: Prisma schema filename with .prisma extension
143
+ * - Value: Array of table names defined in that file
144
+ *
145
+ * **Example:**
146
+ *
147
+ * ```typescript
148
+ * {
149
+ * {
150
+ * filename: "schema-01-users.prisma",
151
+ * tables: ["user", "user_profile", "user_settings"]
152
+ * },
153
+ * {
154
+ * filename: "schema-02-articles.prisma",
155
+ * tables: ["article", "article_snapshot"]
156
+ * },
157
+ * {
158
+ * filename: "schema-03-comments.prisma",
159
+ * tables: ["comment", "comment_like"]
160
+ * }
161
+ * }
162
+ * ```
163
+ *
164
+ * **Notes:**
165
+ *
166
+ * - Table names must match exact Prisma model names (case-sensitive)
167
+ * - Keep mapping synchronized with actual schema files
168
+ * - Use consistent naming convention for files
169
+ */
170
+ components: IComponent[];
171
+ }
172
+
173
+ interface IComponent {
174
+ filename: string;
175
+ tables: string[];
176
+ }
@@ -0,0 +1,181 @@
1
+ import { IAgenticaController, MicroAgentica } from "@agentica/core";
2
+ import { AutoBePrismaSchemasEvent } from "@autobe/interface/src/events/AutoBePrismaSchemasEvent";
3
+ import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
4
+ import { IPointer } from "tstl";
5
+ import typia from "typia";
6
+
7
+ import { AutoBeContext } from "../../context/AutoBeContext";
8
+ import { assertSchemaModel } from "../../context/assertSchemaModel";
9
+ import { transformPrismaSchemaHistories } from "./transformPrismaSchemaHistories";
10
+
11
+ export async function orchestratePrismaSchemas<Model extends ILlmSchema.Model>(
12
+ ctx: AutoBeContext<Model>,
13
+ components: { filename: string; tables: string[] }[],
14
+ ): Promise<AutoBePrismaSchemasEvent[]> {
15
+ const start: Date = new Date();
16
+ const entireTables: string[] = Array.from(
17
+ new Set(components.flatMap((c) => c.tables)),
18
+ );
19
+
20
+ const total: number = components.reduce((acc, c) => acc + c.tables.length, 0);
21
+ let i: number = 0;
22
+
23
+ return await Promise.all(
24
+ components.map(async (c) => {
25
+ const result: IMakePrismaSchemaFilesProps = await process(ctx, {
26
+ filename: c.filename,
27
+ tables: c.tables,
28
+ entireTables,
29
+ });
30
+ const event: AutoBePrismaSchemasEvent = {
31
+ type: "prismaSchemas",
32
+ created_at: start.toISOString(),
33
+ filename: c.filename,
34
+ content: result.content,
35
+ completed: (i += c.tables.length),
36
+ total,
37
+ step: ctx.state().analyze?.step ?? 0,
38
+ };
39
+ ctx.dispatch(event);
40
+ return event;
41
+ }),
42
+ );
43
+ }
44
+
45
+ async function process<Model extends ILlmSchema.Model>(
46
+ ctx: AutoBeContext<Model>,
47
+ component: { filename: string; tables: string[] } & {
48
+ entireTables: string[];
49
+ },
50
+ ): Promise<IMakePrismaSchemaFilesProps> {
51
+ const pointer: IPointer<IMakePrismaSchemaFilesProps | null> = {
52
+ value: null,
53
+ };
54
+ const agentica: MicroAgentica<Model> = new MicroAgentica({
55
+ model: ctx.model,
56
+ vendor: ctx.vendor,
57
+ config: {
58
+ ...(ctx.config ?? {}),
59
+ },
60
+ histories: transformPrismaSchemaHistories(ctx.state()),
61
+ tokenUsage: ctx.usage(),
62
+ controllers: [
63
+ createApplication({
64
+ model: ctx.model,
65
+ build: (next) => {
66
+ pointer.value = next;
67
+ },
68
+ }),
69
+ ],
70
+ });
71
+ agentica.on("request", async (event) => {
72
+ if (event.body.tools) {
73
+ event.body.tool_choice = "required";
74
+ }
75
+ });
76
+
77
+ await agentica.conversate(
78
+ [
79
+ "Please generate Prisma schema files based on the previous requirement analysis report.",
80
+ "",
81
+ "**Context:**",
82
+ `- Target filename: \`${component.filename}\``,
83
+ `- Tables to implement in this file: \`${component.tables.join("`, `")}\``,
84
+ `- All available tables in the system: \`${component.entireTables.join("`, `")}\``,
85
+ "",
86
+ "**Instructions:**",
87
+ "1. Create comprehensive Prisma schema content for the specified tables",
88
+ "2. Reference the previous requirement analysis to understand business logic and data structures",
89
+ "3. Establish appropriate relationships between tables using the entireTables list as reference",
90
+ "4. Include proper field types, constraints, indexes, and documentation",
91
+ "5. Follow enterprise-level schema design patterns and best practices",
92
+ "6. Ensure cross-table relationships are accurately modeled based on business requirements",
93
+ "",
94
+ "**Key Requirements:**",
95
+ "- Implement only the tables specified for this file",
96
+ "- Create foreign key relationships to tables from entireTables when business logic requires it",
97
+ "- Add comprehensive field documentation and model descriptions",
98
+ "- Include appropriate indexes for performance optimization",
99
+ "- Follow consistent naming conventions and data types",
100
+ ].join("\n"),
101
+ );
102
+
103
+ if (pointer.value === null)
104
+ throw new Error("Unreachable code: Prisma Schema not generated");
105
+
106
+ return pointer.value;
107
+ }
108
+
109
+ function createApplication<Model extends ILlmSchema.Model>(props: {
110
+ model: Model;
111
+ build: (next: IMakePrismaSchemaFilesProps) => void;
112
+ }): IAgenticaController.IClass<Model> {
113
+ assertSchemaModel(props.model);
114
+ const application: ILlmApplication<Model> = collection[
115
+ props.model
116
+ ] as unknown as ILlmApplication<Model>;
117
+ return {
118
+ protocol: "class",
119
+ name: "Prisma Generator",
120
+ application,
121
+ execute: {
122
+ makePrismaSchemaFiles: (next) => {
123
+ props.build(next);
124
+ },
125
+ } satisfies IApplication,
126
+ };
127
+ }
128
+
129
+ const claude = typia.llm.application<
130
+ IApplication,
131
+ "claude",
132
+ { reference: true }
133
+ >();
134
+ const collection = {
135
+ chatgpt: typia.llm.application<
136
+ IApplication,
137
+ "chatgpt",
138
+ { reference: true }
139
+ >(),
140
+ claude,
141
+ llama: claude,
142
+ deepseek: claude,
143
+ "3.1": claude,
144
+ "3.0": typia.llm.application<IApplication, "3.0">(),
145
+ };
146
+
147
+ interface IApplication {
148
+ /**
149
+ * Generates comprehensive Prisma schema files based on detailed requirements
150
+ * analysis.
151
+ *
152
+ * Creates multiple organized schema files following enterprise patterns
153
+ * including proper domain separation, relationship modeling, snapshot
154
+ * patterns, inheritance, materialized views, and comprehensive documentation.
155
+ * The generated schemas implement best practices for scalability,
156
+ * maintainability, and data integrity.
157
+ *
158
+ * @param props Properties containing the complete set of Prisma schema files
159
+ */
160
+ makePrismaSchemaFiles(props: IMakePrismaSchemaFilesProps): void;
161
+ }
162
+
163
+ interface IMakePrismaSchemaFilesProps {
164
+ /**
165
+ * Complete Prisma schema content as a single concatenated string.
166
+ *
167
+ * Contains all schema files organized by domain/functionality with clear file
168
+ * separators. Each file section includes models, relationships, indexes, and
169
+ * comprehensive documentation following enterprise patterns.
170
+ *
171
+ * Content should be organized following enterprise patterns:
172
+ *
173
+ * - Main.prisma: Configuration, datasource, and generators
174
+ * - Schema-XX-domain.prisma: Domain-specific entity definitions
175
+ * - Proper cross-file relationships and dependencies
176
+ */
177
+ content: string;
178
+
179
+ /** Summary description of the application requirements and business context. */
180
+ description: string;
181
+ }
@@ -0,0 +1,49 @@
1
+ import { IAgenticaHistoryJson } from "@agentica/core";
2
+
3
+ import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
4
+ import { AutoBeState } from "../../context/AutoBeState";
5
+
6
+ export const transformPrismaCompilerHistories = (
7
+ state: AutoBeState,
8
+ files: Record<string, string>,
9
+ ): Array<
10
+ IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
11
+ > => {
12
+ if (state.analyze === null)
13
+ return [
14
+ {
15
+ type: "systemMessage",
16
+ text: [
17
+ "Requirement analysis is not yet completed.",
18
+ "Don't call any tool function,",
19
+ "but say to process the requirement analysis.",
20
+ ].join(" "),
21
+ },
22
+ ];
23
+ return [
24
+ {
25
+ type: "systemMessage",
26
+ text: AutoBeSystemPromptConstant.PRISMA_COMPILER,
27
+ },
28
+ {
29
+ type: "assistantMessage",
30
+ text: [
31
+ "Below are the current schema files that failed compilation:",
32
+ "",
33
+ "============================================== CURRENT SCHEMA FILES ==============================================",
34
+ "",
35
+ Object.entries(files)
36
+ .map(([filename, content]) => {
37
+ return [
38
+ `// =============================================================================`,
39
+ `// FILE: ${filename}`,
40
+ `// =============================================================================`,
41
+ content,
42
+ ].join("\n");
43
+ })
44
+ .join("\n\n"),
45
+ "",
46
+ ].join("\n"),
47
+ },
48
+ ];
49
+ };
@@ -0,0 +1,46 @@
1
+ import { IAgenticaHistoryJson } from "@agentica/core";
2
+
3
+ import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
4
+ import { AutoBeState } from "../../context/AutoBeState";
5
+
6
+ export const transformPrismaComponentsHistories = (
7
+ state: AutoBeState,
8
+ ): Array<
9
+ IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
10
+ > => {
11
+ if (state.analyze === null)
12
+ return [
13
+ {
14
+ type: "systemMessage",
15
+ text: [
16
+ "Requirement analysis is not yet completed.",
17
+ "Don't call any tool function,",
18
+ "but say to process the requirement analysis.",
19
+ ].join(" "),
20
+ },
21
+ ];
22
+ return [
23
+ {
24
+ type: "systemMessage",
25
+ text: AutoBeSystemPromptConstant.PRISMA_COMPONENT,
26
+ },
27
+ {
28
+ type: "assistantMessage",
29
+ text: [
30
+ "Here is the requirement analysis report.",
31
+ "",
32
+ "Call the provided tool function to generate Prisma DB schema",
33
+ "referencing below requirement analysis report.",
34
+ "",
35
+ "## User Request",
36
+ state.analyze.reason,
37
+ "",
38
+ `## Requirement Analysis Report`,
39
+ "",
40
+ "```json",
41
+ JSON.stringify(state.analyze.files),
42
+ "```",
43
+ ].join("\n"),
44
+ },
45
+ ];
46
+ };
@@ -0,0 +1,50 @@
1
+ import { IAgenticaHistoryJson } from "@agentica/core";
2
+
3
+ import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
4
+ import { AutoBeState } from "../../context/AutoBeState";
5
+
6
+ export const transformPrismaHistories = (
7
+ state: AutoBeState,
8
+ ): Array<
9
+ IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
10
+ > => {
11
+ if (state.analyze === null)
12
+ return [
13
+ {
14
+ type: "systemMessage",
15
+ text: [
16
+ "Requirement analysis is not yet completed.",
17
+ "Don't call any tool function,",
18
+ "but say to process the requirement analysis.",
19
+ ].join(" "),
20
+ },
21
+ ];
22
+ return [
23
+ {
24
+ type: "systemMessage",
25
+ text: AutoBeSystemPromptConstant.PRISMA,
26
+ },
27
+ {
28
+ type: "assistantMessage",
29
+ text: AutoBeSystemPromptConstant.PRISMA_EXAMPLE,
30
+ },
31
+ {
32
+ type: "assistantMessage",
33
+ text: [
34
+ "Here is the requirement analysis report.",
35
+ "",
36
+ "Call the provided tool function to generate Prisma DB schema",
37
+ "referencing below requirement analysis report.",
38
+ "",
39
+ "## User Request",
40
+ state.analyze.reason,
41
+ "",
42
+ `## Requirement Analysis Report`,
43
+ "",
44
+ "```json",
45
+ JSON.stringify(state.analyze.files),
46
+ "```",
47
+ ].join("\n"),
48
+ },
49
+ ];
50
+ };