@autobe/agent 0.10.6 → 0.11.1

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 (147) hide show
  1. package/lib/AutoBeAgent.js +13 -46
  2. package/lib/AutoBeAgent.js.map +1 -1
  3. package/lib/constants/AutoBeSystemPromptConstant.d.ts +11 -6
  4. package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
  5. package/lib/context/AutoBeContext.d.ts +3 -2
  6. package/lib/factory/getAutoBeGenerated.d.ts +5 -0
  7. package/lib/factory/getAutoBeGenerated.js +307 -0
  8. package/lib/factory/getAutoBeGenerated.js.map +1 -0
  9. package/lib/index.mjs +1652 -1402
  10. package/lib/index.mjs.map +1 -1
  11. package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.d.ts +2 -7
  12. package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.js +1 -9
  13. package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.js.map +1 -1
  14. package/lib/orchestrate/analyze/AutoBeAnalyzeRole.d.ts +13 -0
  15. package/lib/orchestrate/analyze/AutoBeAnalyzeRole.js +3 -0
  16. package/lib/orchestrate/analyze/AutoBeAnalyzeRole.js.map +1 -0
  17. package/lib/orchestrate/analyze/orchestrateAnalyze.d.ts +0 -25
  18. package/lib/orchestrate/analyze/orchestrateAnalyze.js +22 -420
  19. package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
  20. package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.d.ts +6 -0
  21. package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.js +561 -0
  22. package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.js.map +1 -0
  23. package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.d.ts +6 -0
  24. package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js +41 -0
  25. package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js.map +1 -0
  26. package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.d.ts +14 -0
  27. package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js +468 -0
  28. package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js.map +1 -0
  29. package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeComposerApplication.d.ts +68 -0
  30. package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeComposerApplication.js +3 -0
  31. package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeComposerApplication.js.map +1 -0
  32. package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.d.ts +5 -0
  33. package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js +27 -0
  34. package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js.map +1 -0
  35. package/lib/orchestrate/analyze/transformAnalyzeWriteHistories.d.ts +12 -0
  36. package/lib/orchestrate/analyze/transformAnalyzeWriteHistories.js +78 -0
  37. package/lib/orchestrate/analyze/transformAnalyzeWriteHistories.js.map +1 -0
  38. package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.d.ts +6 -0
  39. package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js +58 -0
  40. package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js.map +1 -0
  41. package/lib/orchestrate/interface/orchestrateInterface.js +0 -2
  42. package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
  43. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +17 -137
  44. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +1 -1
  45. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +92 -141
  46. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
  47. package/lib/orchestrate/prisma/orchestratePrisma.js +9 -5
  48. package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -1
  49. package/lib/orchestrate/prisma/orchestratePrismaComponent.js +54 -25
  50. package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -1
  51. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +4 -3
  52. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
  53. package/lib/orchestrate/prisma/{orchestratePrismaSchema.d.ts → orchestratePrismaSchemas.d.ts} +2 -4
  54. package/lib/orchestrate/prisma/{orchestratePrismaSchema.js → orchestratePrismaSchemas.js} +269 -203
  55. package/lib/orchestrate/prisma/orchestratePrismaSchemas.js.map +1 -0
  56. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js +1 -1
  57. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js.map +1 -1
  58. package/lib/orchestrate/prisma/transformPrismaCorrectHistories.js +1 -1
  59. package/lib/orchestrate/prisma/transformPrismaHistories.js +1 -1
  60. package/lib/orchestrate/prisma/transformPrismaHistories.js.map +1 -1
  61. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.d.ts +2 -6
  62. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js +24 -32
  63. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js.map +1 -1
  64. package/lib/orchestrate/realize/RealizePipe.d.ts +5 -0
  65. package/lib/orchestrate/realize/RealizePipe.js +14 -0
  66. package/lib/orchestrate/realize/RealizePipe.js.map +1 -0
  67. package/lib/orchestrate/realize/orchestrateRealize.d.ts +0 -6
  68. package/lib/orchestrate/realize/orchestrateRealize.js +6 -43
  69. package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
  70. package/lib/orchestrate/realize/orchestrateRealizeCoder.d.ts +3 -3
  71. package/lib/orchestrate/realize/orchestrateRealizeCoder.js +124 -59
  72. package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -1
  73. package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.d.ts +188 -18
  74. package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.d.ts +23 -0
  75. package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.js +3 -0
  76. package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.js.map +1 -0
  77. package/lib/orchestrate/realize/structures/IAutoBeRealizeFailedSymbol.d.ts +2 -0
  78. package/lib/orchestrate/realize/structures/IAutoBeRealizeFailedSymbol.js +5 -0
  79. package/lib/orchestrate/realize/structures/IAutoBeRealizeFailedSymbol.js.map +1 -0
  80. package/lib/orchestrate/realize/transformRealizeCoderHistories.d.ts +2 -1
  81. package/lib/orchestrate/realize/transformRealizeCoderHistories.js +50 -36
  82. package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -1
  83. package/lib/orchestrate/realize/writeCodeUntilCompilePassed.d.ts +5 -0
  84. package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js +123 -0
  85. package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js.map +1 -0
  86. package/lib/orchestrate/test/compile/getTestExternalDeclarations.js +4 -1
  87. package/lib/orchestrate/test/compile/getTestExternalDeclarations.js.map +1 -1
  88. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js +2 -1
  89. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js.map +1 -1
  90. package/lib/orchestrate/test/orchestrateTest.js +11 -5
  91. package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
  92. package/lib/orchestrate/test/orchestrateTestCorrect.js +3 -2
  93. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  94. package/lib/orchestrate/test/orchestrateTestWrite.js +22 -13
  95. package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -1
  96. package/lib/structures/IAutoBeProps.d.ts +8 -8
  97. package/lib/utils/pipe.d.ts +5 -0
  98. package/lib/utils/pipe.js +14 -0
  99. package/lib/utils/pipe.js.map +1 -0
  100. package/package.json +6 -6
  101. package/src/AutoBeAgent.ts +22 -76
  102. package/src/constants/AutoBeSystemPromptConstant.ts +11 -6
  103. package/src/context/AutoBeContext.ts +3 -1
  104. package/src/factory/getAutoBeGenerated.ts +113 -0
  105. package/src/orchestrate/analyze/AutoBeAnalyzeFileSystem.ts +5 -13
  106. package/src/orchestrate/analyze/AutoBeAnalyzeRole.ts +14 -0
  107. package/src/orchestrate/analyze/orchestrateAnalyze.ts +30 -165
  108. package/src/orchestrate/analyze/orchestrateAnalyzeComposer.ts +115 -0
  109. package/src/orchestrate/analyze/orchestrateAnalyzeReviewer.ts +39 -0
  110. package/src/orchestrate/analyze/orchestrateAnalyzeWrite.ts +106 -0
  111. package/src/orchestrate/analyze/structures/IAutoBeAnalyzeComposerApplication.ts +74 -0
  112. package/src/orchestrate/analyze/transformAnalyzeReviewerHistories.ts +31 -0
  113. package/src/orchestrate/analyze/transformAnalyzeWriteHistories.ts +94 -0
  114. package/src/orchestrate/analyze/writeDocumentUntilReviewPassed.ts +66 -0
  115. package/src/orchestrate/interface/orchestrateInterface.ts +0 -2
  116. package/src/orchestrate/interface/orchestrateInterfaceComponents.ts +2 -3
  117. package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +21 -0
  118. package/src/orchestrate/prisma/orchestratePrisma.ts +12 -5
  119. package/src/orchestrate/prisma/orchestratePrismaComponent.ts +4 -13
  120. package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +9 -4
  121. package/src/orchestrate/prisma/orchestratePrismaSchemas.ts +265 -0
  122. package/src/orchestrate/prisma/transformPrismaSchemaHistories.ts +26 -37
  123. package/src/orchestrate/realize/RealizePipe.ts +39 -0
  124. package/src/orchestrate/realize/orchestrateRealize.ts +3 -91
  125. package/src/orchestrate/realize/orchestrateRealizeCoder.ts +60 -25
  126. package/src/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.ts +192 -18
  127. package/src/orchestrate/realize/structures/IAutoBeRealizeCompile.ts +34 -0
  128. package/src/orchestrate/realize/structures/IAutoBeRealizeFailedSymbol.ts +2 -0
  129. package/src/orchestrate/realize/transformRealizeCoderHistories.ts +58 -34
  130. package/src/orchestrate/realize/writeCodeUntilCompilePassed.ts +178 -0
  131. package/src/orchestrate/test/compile/getTestExternalDeclarations.ts +5 -4
  132. package/src/orchestrate/test/compile/getTestScenarioArtifacts.ts +7 -2
  133. package/src/orchestrate/test/orchestrateTest.ts +14 -12
  134. package/src/orchestrate/test/orchestrateTestCorrect.ts +10 -9
  135. package/src/orchestrate/test/orchestrateTestWrite.ts +33 -27
  136. package/src/structures/IAutoBeProps.ts +10 -7
  137. package/src/utils/pipe.ts +39 -0
  138. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.d.ts +0 -20
  139. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js +0 -735
  140. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js.map +0 -1
  141. package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.d.ts +0 -15
  142. package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js +0 -44
  143. package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js.map +0 -1
  144. package/lib/orchestrate/prisma/orchestratePrismaSchema.js.map +0 -1
  145. package/src/orchestrate/analyze/AutoBeAnalyzeAgent.ts +0 -219
  146. package/src/orchestrate/analyze/AutoBeAnalyzeReviewer.ts +0 -62
  147. package/src/orchestrate/prisma/orchestratePrismaSchema.ts +0 -157
@@ -0,0 +1,265 @@
1
+ import { IAgenticaController, MicroAgentica } from "@agentica/core";
2
+ import { AutoBePrisma } from "@autobe/interface";
3
+ import { AutoBePrismaSchemasEvent } from "@autobe/interface/src/events/AutoBePrismaSchemasEvent";
4
+ import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
5
+ import { IPointer } from "tstl";
6
+ import typia from "typia";
7
+
8
+ // import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
9
+ import { AutoBeContext } from "../../context/AutoBeContext";
10
+ import { assertSchemaModel } from "../../context/assertSchemaModel";
11
+ import { enforceToolCall } from "../../utils/enforceToolCall";
12
+ import { forceRetry } from "../../utils/forceRetry";
13
+ import { transformPrismaSchemaHistories } from "./transformPrismaSchemaHistories";
14
+
15
+ export async function orchestratePrismaSchemas<Model extends ILlmSchema.Model>(
16
+ ctx: AutoBeContext<Model>,
17
+ components: AutoBePrisma.IComponent[],
18
+ ): Promise<AutoBePrismaSchemasEvent[]> {
19
+ const start: Date = new Date();
20
+ const total: number = components
21
+ .map((c) => c.tables.length)
22
+ .reduce((x, y) => x + y, 0);
23
+ let completed: number = 0;
24
+ return await Promise.all(
25
+ components.map(async (comp) => {
26
+ const targetComponent: AutoBePrisma.IComponent = comp;
27
+ const otherComponents: AutoBePrisma.IComponent[] = components.filter(
28
+ (y) => comp !== y,
29
+ );
30
+ const result: IMakePrismaSchemaFileProps = await forceRetry(() =>
31
+ process(ctx, targetComponent, otherComponents),
32
+ );
33
+ const event: AutoBePrismaSchemasEvent = {
34
+ type: "prismaSchemas",
35
+ created_at: start.toISOString(),
36
+ file: {
37
+ filename: comp.filename,
38
+ namespace: comp.namespace,
39
+ models: result.models,
40
+ },
41
+ completed: (completed += comp.tables.length),
42
+ total,
43
+ step: ctx.state().analyze?.step ?? 0,
44
+ };
45
+ ctx.dispatch(event);
46
+ return event;
47
+ }),
48
+ );
49
+ }
50
+
51
+ async function process<Model extends ILlmSchema.Model>(
52
+ ctx: AutoBeContext<Model>,
53
+ targetComponent: AutoBePrisma.IComponent,
54
+ otherComponents: AutoBePrisma.IComponent[],
55
+ ): Promise<IMakePrismaSchemaFileProps> {
56
+ const pointer: IPointer<IMakePrismaSchemaFileProps | null> = {
57
+ value: null,
58
+ };
59
+ const agentica: MicroAgentica<Model> = new MicroAgentica({
60
+ model: ctx.model,
61
+ vendor: ctx.vendor,
62
+ config: {
63
+ ...(ctx.config ?? {}),
64
+ executor: {
65
+ describe: null,
66
+ },
67
+ },
68
+ histories: transformPrismaSchemaHistories(
69
+ ctx.state().analyze!.files,
70
+ targetComponent,
71
+ otherComponents,
72
+ ),
73
+ controllers: [
74
+ createApplication(ctx, {
75
+ targetComponent,
76
+ otherComponents,
77
+ build: (next) => {
78
+ pointer.value = next;
79
+ },
80
+ }),
81
+ ],
82
+ });
83
+ enforceToolCall(agentica);
84
+
85
+ await agentica.conversate("Make prisma schema file please").finally(() => {
86
+ const tokenUsage = agentica.getTokenUsage();
87
+ ctx.usage().record(tokenUsage, ["prisma"]);
88
+ });
89
+ if (pointer.value === null)
90
+ throw new Error("Unreachable code: Prisma Schema not generated");
91
+ return pointer.value;
92
+ }
93
+
94
+ function createApplication<Model extends ILlmSchema.Model>(
95
+ ctx: AutoBeContext<Model>,
96
+ props: {
97
+ targetComponent: AutoBePrisma.IComponent;
98
+ otherComponents: AutoBePrisma.IComponent[];
99
+ build: (next: IMakePrismaSchemaFileProps) => void;
100
+ },
101
+ ): IAgenticaController.IClass<Model> {
102
+ assertSchemaModel(ctx.model);
103
+ const application: ILlmApplication<Model> = collection[
104
+ ctx.model
105
+ ] as unknown as ILlmApplication<Model>;
106
+ // application.functions[0].validate = (
107
+ // input: unknown,
108
+ // ): IValidation<IMakePrismaSchemaFileProps> => {
109
+ // const result: IValidation<IMakePrismaSchemaFileProps> =
110
+ // typia.validate<IMakePrismaSchemaFileProps>(input);
111
+ // if (result.success === false) return result;
112
+
113
+ // const everyModels: AutoBePrisma.IModel[] = result.data.models;
114
+ // result.data.models = result.data.models.filter((m) =>
115
+ // props.otherComponents.every((oc) => oc.tables.includes(m.name) === false),
116
+ // );
117
+ // const expected: string[] = props.targetComponent.tables;
118
+ // const actual: string[] = result.data.models.map((m) => m.name);
119
+ // const missed: string[] = expected.filter(
120
+ // (x) => actual.includes(x) === false,
121
+ // );
122
+ // if (missed.length === 0) return result;
123
+
124
+ // ctx.dispatch({
125
+ // type: "prismaInsufficient",
126
+ // created_at: new Date().toISOString(),
127
+ // component: props.targetComponent,
128
+ // actual: everyModels,
129
+ // missed,
130
+ // tablesToCreate: result.data.tablesToCreate,
131
+ // validationReview: result.data.validationReview,
132
+ // confirmedTables: result.data.confirmedTables,
133
+ // });
134
+ // return {
135
+ // success: false,
136
+ // data: result.data,
137
+ // errors: [
138
+ // {
139
+ // path: "$input.file.models",
140
+ // value: result.data.models,
141
+ // expected: `Array<AutoBePrisma.IModel>`,
142
+ // description: [
143
+ // "You missed some tables from the current domain's component.",
144
+ // "",
145
+ // "Look at the following details to fix the schemas. Never forget to",
146
+ // "compose the `missed` tables at the next function calling.",
147
+ // "",
148
+ // "- filename: current domain's filename",
149
+ // "- namespace: current domain's namespace",
150
+ // "- expected: expected tables in the current domain",
151
+ // "- actual: actual tables you made",
152
+ // "- missed: tables you have missed, and you have to compose again",
153
+ // "",
154
+ // JSON.stringify({
155
+ // filename: props.targetComponent.filename,
156
+ // namespace: props.targetComponent.namespace,
157
+ // expected,
158
+ // actual,
159
+ // missed,
160
+ // }),
161
+ // ].join("\n"),
162
+ // },
163
+ // ],
164
+ // };
165
+ // };
166
+ return {
167
+ protocol: "class",
168
+ name: "Prisma Generator",
169
+ application,
170
+ execute: {
171
+ makePrismaSchemaFile: (next) => {
172
+ props.build(next);
173
+ },
174
+ } satisfies IApplication,
175
+ };
176
+ }
177
+
178
+ const claude = typia.llm.application<
179
+ IApplication,
180
+ "claude",
181
+ { reference: true }
182
+ >();
183
+ const collection = {
184
+ chatgpt: typia.llm.application<
185
+ IApplication,
186
+ "chatgpt",
187
+ { reference: true }
188
+ >(),
189
+ claude,
190
+ llama: claude,
191
+ deepseek: claude,
192
+ "3.1": claude,
193
+ };
194
+
195
+ interface IApplication {
196
+ /**
197
+ * Generates comprehensive Prisma schema files based on detailed requirements
198
+ * analysis.
199
+ *
200
+ * Creates multiple organized schema files following enterprise patterns
201
+ * including proper domain separation, relationship modeling, snapshot
202
+ * patterns, inheritance, materialized views, and comprehensive documentation.
203
+ * The generated schemas implement best practices for scalability,
204
+ * maintainability, and data integrity.
205
+ *
206
+ * @param props Properties containing the file
207
+ */
208
+ makePrismaSchemaFile(props: IMakePrismaSchemaFileProps): void;
209
+ }
210
+
211
+ interface IMakePrismaSchemaFileProps {
212
+ /**
213
+ * STEP 1: First enumeration of tables that must be created
214
+ *
215
+ * List all table names that need to be created based on the
216
+ * `targetComponent.tables`. This should be an exact copy of the
217
+ * `targetComponent.tables` array.
218
+ *
219
+ * Example: ["shopping_goods", "shopping_goods_options"]
220
+ */
221
+ tablesToCreate: string[];
222
+
223
+ /**
224
+ * STEP 2: Validation review of the first enumeration
225
+ *
226
+ * Compare `tablesToCreate` against `targetComponent.tables` and
227
+ * `otherComponents[].tables`. Write a review statement that validates:
228
+ *
229
+ * - All tables from `targetComponent.tables` are included
230
+ * - No tables from `otherComponents[].tables` are included
231
+ * - Additional tables (if any) are for M:N junction relationships or
232
+ * domain-specific needs
233
+ * - No forbidden tables from other domains are included
234
+ *
235
+ * Example: "VALIDATION PASSED: All required tables from
236
+ * `targetComponent.tables` included: shopping_goods, shopping_goods_options.
237
+ * FORBIDDEN CHECK: No tables from `otherComponents` included
238
+ * (shopping_customers, shopping_sellers are correctly excluded). Additional
239
+ * tables: none needed for this domain."
240
+ */
241
+ validationReview: string;
242
+
243
+ /**
244
+ * STEP 3: Second enumeration of tables to create
245
+ *
246
+ * After validation, re-list the tables that will be created. This should be
247
+ * identical to `tablesToCreate` if validation passed. This serves as the
248
+ * final confirmed list before model creation.
249
+ *
250
+ * Example: ["shopping_goods", "shopping_goods_options"]
251
+ */
252
+ confirmedTables: string[];
253
+
254
+ /**
255
+ * STEP 4: Array of Prisma models (database tables) within the domain
256
+ *
257
+ * Create exactly one model for each table in `confirmedTables`. Each model
258
+ * represents a business entity or concept within the namespace. Models can
259
+ * reference each other through foreign key relationships.
260
+ *
261
+ * The `models` array length must equal `confirmedTables.length`. Each
262
+ * `model.name` must match an entry in `confirmedTables`.
263
+ */
264
+ models: AutoBePrisma.IModel[];
265
+ }
@@ -1,16 +1,13 @@
1
1
  import { IAgenticaHistoryJson } from "@agentica/core";
2
- import { AutoBeAnalyzeHistory } from "@autobe/interface";
2
+ import { AutoBePrisma } from "@autobe/interface";
3
3
  import { v4 } from "uuid";
4
4
 
5
5
  import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
6
6
 
7
7
  export const transformPrismaSchemaHistories = (
8
- analyze: AutoBeAnalyzeHistory,
9
- component: {
10
- filename: string;
11
- tables: string[];
12
- entireTables: string[];
13
- },
8
+ requirementAnalysisReport: Record<string, string>,
9
+ targetComponent: AutoBePrisma.IComponent,
10
+ otherComponents: AutoBePrisma.IComponent[],
14
11
  ): Array<
15
12
  IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
16
13
  > => {
@@ -21,44 +18,36 @@ export const transformPrismaSchemaHistories = (
21
18
  type: "systemMessage",
22
19
  text: AutoBeSystemPromptConstant.PRISMA_SCHEMA,
23
20
  },
24
- // {
25
- // id: v4(),
26
- // created_at: new Date().toISOString(),
27
- // type: "systemMessage",
28
- // text: [
29
- // "Before making prisma schema files,",
30
- // "learn about the prisma schema language",
31
- // "from the best practices and examples",
32
- // "",
33
- // AutoBeSystemPromptConstant.PRISMA_EXAMPLE,
34
- // ].join("\n"),
35
- // },
36
21
  {
37
22
  id: v4(),
38
23
  created_at: new Date().toISOString(),
39
- type: "systemMessage",
24
+ type: "assistantMessage",
40
25
  text: [
41
- "Here is the requirement analysis report.",
42
- "",
43
- "Call the provided tool function to generate Prisma DB schema",
44
- "referencing below requirement analysis report.",
26
+ "Here is the input data for generating Prisma DB schema.",
45
27
  "",
46
- "## User Request",
47
- analyze.reason,
48
- "",
49
- `## Requirement Analysis Report`,
28
+ "```",
29
+ JSON.stringify({
30
+ requirementAnalysisReport,
31
+ otherComponents,
32
+ targetComponent,
33
+ }),
34
+ "```",
35
+ ].join("\n"),
36
+ },
37
+ {
38
+ id: v4(),
39
+ created_at: new Date().toISOString(),
40
+ type: "systemMessage",
41
+ text: [
42
+ "You've already taken a mistake that creating models from the other components.",
43
+ "Note that, you have to make models from the target component only. Never make",
44
+ "models from the other components. The other components' models are already made.",
50
45
  "",
51
46
  "```json",
52
- JSON.stringify(analyze.files),
47
+ JSON.stringify({
48
+ targetComponent,
49
+ }),
53
50
  "```",
54
- "",
55
- "## Context",
56
- "",
57
- ` - Target filename: ${component.filename}`,
58
- ` - Tables what you have to make:`,
59
- ...component.tables.map((table) => ` - ${table}`),
60
- ` - Entire tables you can reference:`,
61
- ...component.entireTables.map((table) => ` - ${table}`),
62
51
  ].join("\n"),
63
52
  },
64
53
  ];
@@ -0,0 +1,39 @@
1
+ import { FAILED } from "./structures/IAutoBeRealizeFailedSymbol";
2
+
3
+ export function pipe<A, B>(
4
+ a: A,
5
+ ab: (a: A) => Promise<B | FAILED>,
6
+ ): Promise<B | FAILED>;
7
+
8
+ export function pipe<A, B, C>(
9
+ a: A,
10
+ ab: (a: A) => Promise<B | FAILED>,
11
+ bc: (b: B) => Promise<C | FAILED>,
12
+ ): Promise<C | FAILED>;
13
+
14
+ export function pipe<A, B, C, D>(
15
+ a: A,
16
+ ab: (a: A) => Promise<B | FAILED>,
17
+ bc: (b: B) => Promise<C | FAILED>,
18
+ cd: (c: C) => Promise<D | FAILED>,
19
+ ): Promise<D | FAILED>;
20
+
21
+ export function pipe<A, B, C, D, E>(
22
+ a: A,
23
+ ab: (a: A) => Promise<B | FAILED>,
24
+ bc: (b: B) => Promise<C | FAILED>,
25
+ cd: (c: C) => Promise<D | FAILED>,
26
+ de: (d: D) => Promise<E | FAILED>,
27
+ ): Promise<E | FAILED>;
28
+
29
+ export function pipe(
30
+ a: any,
31
+ ...fns: Array<(arg: any) => Promise<any>>
32
+ ): Promise<any> {
33
+ return fns.reduce((prev, fn) => {
34
+ return prev.then((result) => {
35
+ if (result === FAILED) return FAILED;
36
+ return fn(result);
37
+ });
38
+ }, Promise.resolve(a));
39
+ }
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  AutoBeAssistantMessageHistory,
3
- AutoBeOpenApi,
4
3
  AutoBeRealizeHistory,
5
4
  } from "@autobe/interface";
6
5
  import { ILlmSchema } from "@samchon/openapi";
@@ -8,9 +7,7 @@ import { v4 } from "uuid";
8
7
 
9
8
  import { AutoBeContext } from "../../context/AutoBeContext";
10
9
  import { IAutoBeApplicationProps } from "../../context/IAutoBeApplicationProps";
11
- import { orchestrateRealizeCoder } from "./orchestrateRealizeCoder";
12
- import { orchestrateRealizePlanner } from "./orchestrateRealizePlanner";
13
- import { IAutoBeRealizeCoderApplication } from "./structures/IAutoBeRealizeCoderApplication";
10
+ import { writeCodeUntilCompilePassed } from "./writeCodeUntilCompilePassed";
14
11
 
15
12
  export const orchestrateRealize =
16
13
  <Model extends ILlmSchema.Model>(ctx: AutoBeContext<Model>) =>
@@ -20,55 +17,10 @@ export const orchestrateRealize =
20
17
  props;
21
18
  const ops = ctx.state().interface?.document.operations;
22
19
  if (!ops) {
23
- throw new Error();
24
- }
25
-
26
- const files: Record<string, string> = {
27
- ...ctx.state().interface?.files,
28
- ...ctx.state().test?.files.reduce(
29
- (acc, file) => {
30
- acc[file.location] = file.content;
31
- return acc;
32
- },
33
- {} as Record<string, string>,
34
- ),
35
- };
36
-
37
- const codes: IAutoBeRealizeCoderApplication.IPipeOutput[] =
38
- await Promise.all(
39
- ops.map(async (op) => ({
40
- operation: op,
41
- result: await pipe(
42
- op,
43
- (op) => orchestrateRealizePlanner(ctx, op),
44
- (p) => orchestrateRealizeCoder(ctx, op, p, files),
45
- ),
46
- })),
47
- );
48
-
49
- const successes: Array<{
50
- operation: AutoBeOpenApi.IOperation;
51
- result: IAutoBeRealizeCoderApplication.RealizeCoderOutput;
52
- }> = [];
53
- const failures: Array<{
54
- operation: AutoBeOpenApi.IOperation;
55
- result: FAILED;
56
- }> = [];
57
-
58
- for (const code of codes) {
59
- if (code.result === FAILED) {
60
- failures.push({
61
- operation: code.operation,
62
- result: code.result,
63
- });
64
- } else {
65
- successes.push({
66
- operation: code.operation,
67
- result: code.result,
68
- });
69
- }
20
+ throw new Error("Can't do realize agent because operations are nothing.");
70
21
  }
71
22
 
23
+ await writeCodeUntilCompilePassed(ctx, ops, 3);
72
24
  const now = new Date().toISOString();
73
25
  ctx.dispatch({
74
26
  type: "assistantMessage",
@@ -87,43 +39,3 @@ export const orchestrateRealize =
87
39
  step: ctx.state().test?.step ?? 0,
88
40
  };
89
41
  };
90
-
91
- export const FAILED = Symbol("FAILED");
92
- export type FAILED = typeof FAILED;
93
-
94
- export function pipe<A, B>(
95
- a: A,
96
- ab: (a: A) => Promise<B | FAILED>,
97
- ): Promise<B | FAILED>;
98
-
99
- export function pipe<A, B, C>(
100
- a: A,
101
- ab: (a: A) => Promise<B | FAILED>,
102
- bc: (b: B) => Promise<C | FAILED>,
103
- ): Promise<C | FAILED>;
104
-
105
- export function pipe<A, B, C, D>(
106
- a: A,
107
- ab: (a: A) => Promise<B | FAILED>,
108
- bc: (b: B) => Promise<C | FAILED>,
109
- cd: (c: C) => Promise<D | FAILED>,
110
- ): Promise<D | FAILED>;
111
-
112
- export function pipe<A, B, C, D>(
113
- a: A,
114
- ab: (a: A) => Promise<B | FAILED>,
115
- bc: (b: B) => Promise<C | FAILED>,
116
- cd: (c: C) => Promise<D | FAILED>,
117
- ): Promise<D | FAILED>;
118
-
119
- export function pipe(
120
- a: any,
121
- ...fns: Array<(arg: any) => Promise<any>>
122
- ): Promise<any> {
123
- return fns.reduce((prev, fn) => {
124
- return prev.then((result) => {
125
- if (result === FAILED) return FAILED;
126
- return fn(result);
127
- });
128
- }, Promise.resolve(a));
129
- }
@@ -1,5 +1,9 @@
1
1
  import { IAgenticaController, MicroAgentica } from "@agentica/core";
2
- import { AutoBeOpenApi } from "@autobe/interface";
2
+ import {
3
+ AutoBeOpenApi,
4
+ IAutoBeCompiler,
5
+ IAutoBeTypeScriptCompileResult,
6
+ } from "@autobe/interface";
3
7
  import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
4
8
  import { IPointer } from "tstl";
5
9
  import typia from "typia";
@@ -9,9 +13,9 @@ import { assertSchemaModel } from "../../context/assertSchemaModel";
9
13
  import { enforceToolCall } from "../../utils/enforceToolCall";
10
14
  import { getTestScenarioArtifacts } from "../test/compile/getTestScenarioArtifacts";
11
15
  import { IAutoBeTestScenarioArtifacts } from "../test/structures/IAutoBeTestScenarioArtifacts";
12
- import { FAILED } from "./orchestrateRealize";
13
16
  import { RealizePlannerOutput } from "./orchestrateRealizePlanner";
14
17
  import { IAutoBeRealizeCoderApplication } from "./structures/IAutoBeRealizeCoderApplication";
18
+ import { FAILED } from "./structures/IAutoBeRealizeFailedSymbol";
15
19
  import { transformRealizeCoderHistories } from "./transformRealizeCoderHistories";
16
20
 
17
21
  /**
@@ -36,8 +40,16 @@ export const orchestrateRealizeCoder = async <Model extends ILlmSchema.Model>(
36
40
  ctx: AutoBeContext<Model>,
37
41
  operation: AutoBeOpenApi.IOperation,
38
42
  props: RealizePlannerOutput,
39
- files: Record<string, string>,
40
- ): Promise<IAutoBeRealizeCoderApplication.RealizeCoderOutput | FAILED> => {
43
+ previous: string | null,
44
+ total: IAutoBeTypeScriptCompileResult.IDiagnostic[],
45
+ diagnostics: IAutoBeTypeScriptCompileResult.IDiagnostic[],
46
+ ): Promise<
47
+ | Pick<
48
+ IAutoBeRealizeCoderApplication.RealizeCoderOutput,
49
+ "filename" | "implementationCode"
50
+ >
51
+ | FAILED
52
+ > => {
41
53
  const artifacts: IAutoBeTestScenarioArtifacts =
42
54
  await getTestScenarioArtifacts(ctx, {
43
55
  endpoint: {
@@ -57,7 +69,7 @@ export const orchestrateRealizeCoder = async <Model extends ILlmSchema.Model>(
57
69
  const controller = createApplication({
58
70
  model: ctx.model,
59
71
  build: (props) => {
60
- pointer.value = props.result;
72
+ pointer.value = props.output;
61
73
  },
62
74
  });
63
75
 
@@ -71,7 +83,14 @@ export const orchestrateRealizeCoder = async <Model extends ILlmSchema.Model>(
71
83
  describe: null,
72
84
  },
73
85
  },
74
- histories: transformRealizeCoderHistories(ctx.state(), props, artifacts),
86
+ histories: transformRealizeCoderHistories(
87
+ ctx.state(),
88
+ props,
89
+ artifacts,
90
+ previous,
91
+ total,
92
+ diagnostics,
93
+ ),
75
94
  });
76
95
  enforceToolCall(agent);
77
96
 
@@ -83,29 +102,45 @@ export const orchestrateRealizeCoder = async <Model extends ILlmSchema.Model>(
83
102
  return FAILED;
84
103
  }
85
104
 
86
- pointer.value.implementationCode = await ctx.compiler.typescript.beautify(
105
+ pointer.value.implementationCode = await replaceImportStatements(ctx)(
87
106
  pointer.value.implementationCode,
88
107
  );
89
- pointer.value.implementationCode = pointer.value.implementationCode
90
- .replaceAll('import { MyGlobal } from "../MyGlobal";', "")
91
- .replaceAll('import typia, { tags } from "typia";', "")
92
- .replaceAll('import { Prisma } from "@prisma/client";', "")
93
- .replaceAll('import { jwtDecode } from "./jwtDecode"', "");
94
- pointer.value.implementationCode = [
95
- 'import { MyGlobal } from "../MyGlobal";',
96
- 'import typia, { tags } from "typia";',
97
- 'import { Prisma } from "@prisma/client";',
98
- 'import { jwtDecode } from "./jwtDecode"',
99
- "",
100
- pointer.value.implementationCode,
101
- ].join("\n");
102
-
103
- files[`src/providers/${props.functionName}.ts`] =
104
- pointer.value.implementationCode;
105
108
 
106
- return { ...pointer.value, functionName: props.functionName };
109
+ return {
110
+ ...pointer.value,
111
+ filename: `src/providers/${props.functionName}.ts`,
112
+ };
107
113
  };
108
114
 
115
+ function replaceImportStatements<Model extends ILlmSchema.Model>(
116
+ ctx: AutoBeContext<Model>,
117
+ ) {
118
+ return async function (code: string) {
119
+ const compiler: IAutoBeCompiler = await ctx.compiler();
120
+ code = await compiler.typescript.beautify(code);
121
+ code = code
122
+ .replaceAll('import { MyGlobal } from "../MyGlobal";', "")
123
+ .replaceAll('import typia, { tags } from "typia";', "")
124
+ .replaceAll('import { tags } from "typia";', "")
125
+ .replaceAll('import { tags, typia } from "typia";', "")
126
+ .replaceAll('import typia from "typia";', "")
127
+ .replaceAll('import { Prisma } from "@prisma/client";', "")
128
+ .replaceAll('import { jwtDecode } from "./jwtDecode"', "")
129
+ .replaceAll('import { v4 } from "uuid"', "");
130
+ code = [
131
+ 'import { MyGlobal } from "../MyGlobal";',
132
+ 'import typia, { tags } from "typia";',
133
+ 'import { Prisma } from "@prisma/client";',
134
+ 'import { jwtDecode } from "./jwtDecode";',
135
+ 'import { v4 } from "uuid";',
136
+ "",
137
+ code,
138
+ ].join("\n");
139
+
140
+ return code;
141
+ };
142
+ }
143
+
109
144
  function createApplication<Model extends ILlmSchema.Model>(props: {
110
145
  model: Model;
111
146
  build: (next: IAutoBeRealizeCoderApplication.IProps) => void;
@@ -121,7 +156,7 @@ function createApplication<Model extends ILlmSchema.Model>(props: {
121
156
  name: "Write code",
122
157
  application,
123
158
  execute: {
124
- programing: (next) => {
159
+ programming: (next) => {
125
160
  props.build(next);
126
161
  },
127
162
  } satisfies IAutoBeRealizeCoderApplication,