@autobe/agent 0.3.23 → 0.4.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 (48) hide show
  1. package/lib/AutoBeAgent.d.ts +0 -7
  2. package/lib/AutoBeAgent.js +5 -5
  3. package/lib/AutoBeAgent.js.map +1 -1
  4. package/lib/constants/AutoBeSystemPromptConstant.d.ts +4 -4
  5. package/lib/factory/createAgenticaHistory.js +1 -1
  6. package/lib/factory/createAgenticaHistory.js.map +1 -1
  7. package/lib/factory/createAutoBeApplication.js +9 -9
  8. package/lib/factory/createAutoBeApplication.js.map +1 -1
  9. package/lib/index.d.ts +0 -4
  10. package/lib/index.mjs +3508 -504
  11. package/lib/index.mjs.map +1 -1
  12. package/lib/orchestrate/interface/transformInterfaceHistories.js +3 -3
  13. package/lib/orchestrate/interface/transformInterfaceHistories.js.map +1 -1
  14. package/lib/orchestrate/prisma/orchestratePrisma.js +13 -8
  15. package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -1
  16. package/lib/orchestrate/prisma/orchestratePrismaComponent.js +67 -26
  17. package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -1
  18. package/lib/orchestrate/prisma/orchestratePrismaCorrect.d.ts +4 -0
  19. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +2010 -0
  20. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -0
  21. package/lib/orchestrate/prisma/orchestratePrismaSchema.js +1649 -80
  22. package/lib/orchestrate/prisma/orchestratePrismaSchema.js.map +1 -1
  23. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js +1 -1
  24. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js.map +1 -1
  25. package/lib/orchestrate/prisma/transformPrismaCorrectHistories.d.ts +3 -0
  26. package/lib/orchestrate/prisma/{transformPrismaCompilerHistories.js → transformPrismaCorrectHistories.js} +11 -10
  27. package/lib/orchestrate/prisma/transformPrismaCorrectHistories.js.map +1 -0
  28. package/lib/orchestrate/prisma/transformPrismaHistories.js +1 -1
  29. package/lib/orchestrate/prisma/transformPrismaHistories.js.map +1 -1
  30. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js +1 -1
  31. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js.map +1 -1
  32. package/package.json +4 -4
  33. package/src/AutoBeAgent.ts +5 -5
  34. package/src/constants/AutoBeSystemPromptConstant.ts +4 -4
  35. package/src/factory/createAgenticaHistory.ts +1 -1
  36. package/src/factory/createAutoBeApplication.ts +9 -9
  37. package/src/orchestrate/interface/transformInterfaceHistories.ts +3 -3
  38. package/src/orchestrate/prisma/orchestratePrisma.ts +20 -12
  39. package/src/orchestrate/prisma/orchestratePrismaComponent.ts +6 -3
  40. package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +258 -0
  41. package/src/orchestrate/prisma/orchestratePrismaSchema.ts +16 -53
  42. package/src/orchestrate/prisma/{transformPrismaCompilerHistories.ts → transformPrismaCorrectHistories.ts} +10 -10
  43. package/lib/orchestrate/prisma/orchestratePrismaCompiler.d.ts +0 -4
  44. package/lib/orchestrate/prisma/orchestratePrismaCompiler.js +0 -443
  45. package/lib/orchestrate/prisma/orchestratePrismaCompiler.js.map +0 -1
  46. package/lib/orchestrate/prisma/transformPrismaCompilerHistories.d.ts +0 -3
  47. package/lib/orchestrate/prisma/transformPrismaCompilerHistories.js.map +0 -1
  48. package/src/orchestrate/prisma/orchestratePrismaCompiler.ts +0 -276
@@ -1,276 +0,0 @@
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 { StringUtil } from "../../utils/StringUtil";
10
- import { transformPrismaCompilerHistories } from "./transformPrismaCompilerHistories";
11
-
12
- export function orchestratePrismaCompiler<Model extends ILlmSchema.Model>(
13
- ctx: AutoBeContext<Model>,
14
- files: Record<string, string>,
15
- retry: number = 8,
16
- ): Promise<IAutoBePrismaCompilerResult> {
17
- return step(ctx, files, retry);
18
- }
19
-
20
- async function step<Model extends ILlmSchema.Model>(
21
- ctx: AutoBeContext<Model>,
22
- files: Record<string, string>,
23
- life: number,
24
- ): Promise<IAutoBePrismaCompilerResult> {
25
- // FIX MAIN PRISMA FILE
26
- files["main.prisma"] = MAIN_PRISMA_FILE;
27
-
28
- // TRY COMPILATION
29
- const result: IAutoBePrismaCompilerResult = await ctx.compiler.prisma({
30
- files,
31
- });
32
- if (result.type !== "failure" || life <= 0) return result;
33
-
34
- // VALIDATION FAILED
35
- ctx.dispatch({
36
- type: "prismaValidate",
37
- schemas: files,
38
- result,
39
- step: ctx.state().analyze?.step ?? 0,
40
- created_at: new Date().toISOString(),
41
- });
42
-
43
- const pointer: IPointer<IModifyPrismaSchemaFilesProps | null> = {
44
- value: null,
45
- };
46
- const agentica: MicroAgentica<Model> = new MicroAgentica({
47
- model: ctx.model,
48
- vendor: ctx.vendor,
49
- config: {
50
- ...(ctx.config ?? {}),
51
- },
52
- histories: transformPrismaCompilerHistories(files, result),
53
- tokenUsage: ctx.usage(),
54
- controllers: [
55
- createApplication({
56
- model: ctx.model,
57
- build: (next) => {
58
- pointer.value = next;
59
- },
60
- }),
61
- ],
62
- });
63
- agentica.on("request", (event) => {
64
- if (event.body.tools) {
65
- event.body.tool_choice = "required";
66
- }
67
- });
68
-
69
- // REQUEST CORRECTION
70
- await agentica.conversate(
71
- StringUtil.trim`
72
- Resolve the compilation errors in the provided Prisma schema files.
73
-
74
- Don't remake every schema files. Fix only some of the files that have
75
- compilation errors. You MUST provide complete, corrected files.
76
- `,
77
- );
78
- if (pointer.value === null) {
79
- console.error(
80
- "Unreachable error: PrismaCompilerAgent.pointer.value is null",
81
- );
82
- return result; // unreachable
83
- }
84
-
85
- ctx.dispatch({
86
- type: "prismaCorrect",
87
- input: files,
88
- failure: result,
89
- correction: pointer.value.files,
90
- planning: pointer.value.planning,
91
- step: ctx.state().analyze?.step ?? 0,
92
- created_at: new Date().toISOString(),
93
- });
94
-
95
- const newFiles: Record<string, string> = {
96
- ...files,
97
- ...pointer.value.files,
98
- };
99
- return step(ctx, newFiles, life - 1);
100
- }
101
-
102
- function createApplication<Model extends ILlmSchema.Model>(props: {
103
- model: Model;
104
- build: (next: IModifyPrismaSchemaFilesProps) => void;
105
- }): IAgenticaController.IClass<Model> {
106
- assertSchemaModel(props.model);
107
- const application: ILlmApplication<Model> = collection[
108
- props.model
109
- ] as unknown as ILlmApplication<Model>;
110
- return {
111
- protocol: "class",
112
- name: "Prisma Compiler",
113
- application,
114
- execute: {
115
- modifyPrismaSchemaFiles: (next) => {
116
- props.build(next);
117
- },
118
- } satisfies IApplication,
119
- };
120
- }
121
-
122
- const claude = typia.llm.application<
123
- IApplication,
124
- "claude",
125
- { reference: true }
126
- >();
127
- const collection = {
128
- chatgpt: typia.llm.application<
129
- IApplication,
130
- "chatgpt",
131
- { reference: true }
132
- >(),
133
- claude,
134
- llama: claude,
135
- deepseek: claude,
136
- "3.1": claude,
137
- "3.0": typia.llm.application<IApplication, "3.0">(),
138
- };
139
-
140
- interface IApplication {
141
- /**
142
- * Fixes Prisma compilation errors while preserving ALL existing comments,
143
- * documentation, and schema structure.
144
- *
145
- * ## Core Rules
146
- *
147
- * 1. Fix ONLY compilation errors - never remove comments/documentation
148
- * 2. Apply minimal changes - preserve original design and relationships
149
- * 3. Return COMPLETE files - no truncation allowed
150
- * 4. NEVER use mapping names in @relation directives
151
- *
152
- * ## Preservation Requirements
153
- *
154
- * - Keep ALL comments (`//` and `///`)
155
- * - Keep ALL field/model documentation
156
- * - Keep business logic and architectural patterns
157
- * - Remove description comments only when erasing properties/relationships
158
- *
159
- * ## Fix Strategy
160
- *
161
- * - Resolve syntax/relationship errors without changing structure
162
- * - Remove mapping names from @relation directives if present
163
- * - Add missing foreign keys/constraints while preserving documentation
164
- */
165
- modifyPrismaSchemaFiles(props: IModifyPrismaSchemaFilesProps): void;
166
- }
167
-
168
- interface IModifyPrismaSchemaFilesProps {
169
- /**
170
- * Detailed execution plan for fixing Prisma compilation errors.
171
- *
172
- * 🎯 Purpose: Enable systematic reasoning and step-by-step error resolution
173
- * approach
174
- *
175
- * 📋 Required Planning Content:
176
- *
177
- * 1. **Error Analysis Summary**
178
- *
179
- * - List all identified compilation errors with their locations
180
- * - Categorize errors by type (syntax, relationships, types, constraints)
181
- * - Identify root causes and error interdependencies
182
- * 2. **Fix Strategy Overview**
183
- *
184
- * - Prioritize fixes based on dependencies (fix foundational errors first)
185
- * - Outline minimal changes needed for each error
186
- * - Identify potential impact on other schema parts
187
- * 3. **Step-by-Step Fix Plan**
188
- *
189
- * - File-by-file modification plan with specific changes
190
- * - Exact line numbers or sections to be modified
191
- * - New code additions or corrections to be applied
192
- * - Verification steps to ensure fixes don't break other parts
193
- * 4. **Preservation Checklist**
194
- *
195
- * - Confirm which comments/documentation must be preserved
196
- * - List relationships and business logic to maintain unchanged
197
- * - Identify cross-file dependencies that must remain intact
198
- * 5. **Risk Assessment**
199
- *
200
- * - Potential side effects of each planned fix
201
- * - Validation points to check after applying fixes
202
- * - Rollback considerations if fixes introduce new issues
203
- *
204
- * 💡 Example Planning Structure:
205
- *
206
- * ## Error Analysis
207
- * - Error 1: Missing foreign key field 'userId' in Post model (schema-02-posts.prisma:15)
208
- * - Error 2: Invalid @relation reference to non-existent 'User.posts' (schema-01-users.prisma:8)
209
- *
210
- * ## Fix Strategy
211
- * 1. Add missing 'userId String' field to Post model
212
- * 2. Update @relation mapping in User model to reference correct field
213
- *
214
- * ## Detailed Steps
215
- * 1. schema-02-posts.prisma: Add 'userId String' after line 14
216
- * 2. schema-01-users.prisma: Fix @relation(fields: [userId], references: [id])
217
- *
218
- * ## Preservation Notes
219
- * - Keep all existing comments in Post model
220
- * - Maintain User model documentation
221
- * - Preserve existing indexes and constraints
222
- */
223
- planning: string;
224
-
225
- /**
226
- * Original Prisma schema files that contain compilation errors and need
227
- * correction.
228
- *
229
- * 📥 Input Structure:
230
- *
231
- * - Key: filename (e.g., "schema-01-users.prisma")
232
- * - Value: COMPLETE original file content with compilation errors
233
- *
234
- * 🔍 Expected Input File Types:
235
- *
236
- * - Domain-specific schema files: "schema-XX-domain.prisma" → Contains complete
237
- * model definitions for specific business domains
238
- *
239
- * 📝 Input File Content Analysis:
240
- *
241
- * - All models with their complete field definitions
242
- * - All relationships (@relation directives with field mappings)
243
- * - All indexes, constraints, and unique identifiers
244
- * - All enums and their complete value sets
245
- * - All comments and documentation
246
- * - Cross-file model references and dependencies
247
- *
248
- * ⚠️ Input Processing Notes:
249
- *
250
- * - Files may contain syntax errors, type mismatches, or missing references
251
- * - Some models might reference non-existent fields or models
252
- * - Relationship mappings might be incorrect or incomplete
253
- * - Foreign key fields might be missing or incorrectly defined
254
- * - Cross-file dependencies might be broken or circular
255
- */
256
- files: Record<string, string>;
257
- }
258
-
259
- const MAIN_PRISMA_FILE = StringUtil.trim`
260
- generator client {
261
- provider = "prisma-client-js"
262
- previewFeatures = ["postgresqlExtensions", "views"]
263
- binaryTargets = ["native"]
264
- }
265
-
266
- datasource db {
267
- provider = "postgresql"
268
- url = env("DATABASE_URL")
269
- extensions = []
270
- }
271
-
272
- generator markdown {
273
- provider = "prisma-markdown"
274
- output = "../docs/ERD.md"
275
- }
276
- `;