@autobe/agent 0.5.1 → 0.5.2
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.
- package/lib/AutoBeAgent.js +22 -3
- package/lib/AutoBeAgent.js.map +1 -1
- package/lib/constants/AutoBeSystemPromptConstant.d.ts +2 -2
- package/lib/index.mjs +686 -827
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +764 -915
- package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
- package/lib/orchestrate/prisma/transformPrismaCorrectHistories.js +1 -1
- package/lib/orchestrate/prisma/transformPrismaCorrectHistories.js.map +1 -1
- package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js +1 -1
- package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js.map +1 -1
- package/package.json +4 -4
- package/src/AutoBeAgent.ts +29 -2
- package/src/constants/AutoBeSystemPromptConstant.ts +2 -2
- package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +112 -79
|
@@ -13,6 +13,14 @@ export function orchestratePrismaCorrect<Model extends ILlmSchema.Model>(
|
|
|
13
13
|
application: AutoBePrisma.IApplication,
|
|
14
14
|
retry: number = 8,
|
|
15
15
|
): Promise<IAutoBePrismaValidation> {
|
|
16
|
+
const unique: Set<string> = new Set();
|
|
17
|
+
for (const file of application.files)
|
|
18
|
+
file.models = file.models.filter((model) => {
|
|
19
|
+
if (unique.has(model.name)) return false;
|
|
20
|
+
unique.add(model.name);
|
|
21
|
+
return true;
|
|
22
|
+
});
|
|
23
|
+
application.files = application.files.filter((f) => f.models.length !== 0);
|
|
16
24
|
return step(ctx, application, retry);
|
|
17
25
|
}
|
|
18
26
|
|
|
@@ -76,12 +84,20 @@ async function step<Model extends ILlmSchema.Model>(
|
|
|
76
84
|
return result; // unreachable
|
|
77
85
|
}
|
|
78
86
|
|
|
87
|
+
const correction: AutoBePrisma.IApplication = {
|
|
88
|
+
files: application.files.map((file) => ({
|
|
89
|
+
filename: file.filename,
|
|
90
|
+
namespace: file.namespace,
|
|
91
|
+
models: file.models.map((model) => {
|
|
92
|
+
const newbie = pointer.value!.models.find((m) => m.name === model.name);
|
|
93
|
+
return newbie ?? model;
|
|
94
|
+
}),
|
|
95
|
+
})),
|
|
96
|
+
};
|
|
79
97
|
ctx.dispatch({
|
|
80
98
|
type: "prismaCorrect",
|
|
81
99
|
failure: result,
|
|
82
|
-
correction
|
|
83
|
-
files: pointer.value.files,
|
|
84
|
-
},
|
|
100
|
+
correction,
|
|
85
101
|
planning: pointer.value.planning,
|
|
86
102
|
step: ctx.state().analyze?.step ?? 0,
|
|
87
103
|
created_at: new Date().toISOString(),
|
|
@@ -89,7 +105,7 @@ async function step<Model extends ILlmSchema.Model>(
|
|
|
89
105
|
return step(
|
|
90
106
|
ctx,
|
|
91
107
|
{
|
|
92
|
-
files:
|
|
108
|
+
files: correction.files,
|
|
93
109
|
},
|
|
94
110
|
life - 1,
|
|
95
111
|
);
|
|
@@ -135,124 +151,141 @@ const collection = {
|
|
|
135
151
|
|
|
136
152
|
interface IApplication {
|
|
137
153
|
/**
|
|
138
|
-
* Fixes validation errors in AutoBePrisma
|
|
139
|
-
*
|
|
154
|
+
* Fixes validation errors in specific AutoBePrisma models while preserving
|
|
155
|
+
* ALL existing business logic and model descriptions.
|
|
140
156
|
*
|
|
141
157
|
* ## Core Rules
|
|
142
158
|
*
|
|
143
|
-
* 1. Fix ONLY validation errors - never remove business
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
159
|
+
* 1. Fix ONLY validation errors in provided models - never remove business
|
|
160
|
+
* descriptions
|
|
161
|
+
* 2. Apply minimal changes to error models only - preserve original design
|
|
162
|
+
* intent
|
|
163
|
+
* 3. Return ONLY corrected models - unchanged models remain in original schema
|
|
164
|
+
* 4. Maintain referential integrity with unchanged models
|
|
147
165
|
*
|
|
148
|
-
* ##
|
|
166
|
+
* ## Targeted Scope
|
|
149
167
|
*
|
|
150
|
-
* -
|
|
151
|
-
* -
|
|
152
|
-
* -
|
|
153
|
-
* -
|
|
168
|
+
* - Process ONLY models with validation errors from IError[] array
|
|
169
|
+
* - Exclude models without errors from processing and output
|
|
170
|
+
* - Minimize context usage by returning corrected models only
|
|
171
|
+
* - Preserve unchanged models in their original state
|
|
154
172
|
*
|
|
155
173
|
* ## Fix Strategy
|
|
156
174
|
*
|
|
157
|
-
* - Resolve
|
|
158
|
-
* -
|
|
159
|
-
* -
|
|
160
|
-
* - Ensure naming conventions and index rules compliance
|
|
175
|
+
* - Resolve validation errors within specific models only
|
|
176
|
+
* - Fix field duplications, invalid references, and type mismatches
|
|
177
|
+
* - Update cross-model references without modifying target models
|
|
178
|
+
* - Ensure naming conventions and index rules compliance in corrected models
|
|
161
179
|
*/
|
|
162
180
|
correctPrismaSchemaFiles(props: IModifyPrismaSchemaFilesProps): void;
|
|
163
181
|
}
|
|
164
182
|
|
|
165
183
|
interface IModifyPrismaSchemaFilesProps {
|
|
166
184
|
/**
|
|
167
|
-
* Detailed execution plan for fixing AutoBePrisma validation errors
|
|
185
|
+
* Detailed execution plan for fixing `AutoBePrisma` validation errors in
|
|
186
|
+
* specific models.
|
|
168
187
|
*
|
|
169
188
|
* 🎯 Purpose: Enable systematic reasoning and step-by-step error resolution
|
|
170
|
-
* approach for
|
|
189
|
+
* approach for targeted model validation issues
|
|
171
190
|
*
|
|
172
191
|
* 📋 Required Planning Content:
|
|
173
192
|
*
|
|
174
|
-
* 1. **Error Analysis
|
|
193
|
+
* 1. **Error Scope Analysis**
|
|
175
194
|
*
|
|
176
195
|
* - List all validation errors from IAutoBePrismaValidation.IError[] array
|
|
177
|
-
* -
|
|
178
|
-
* -
|
|
179
|
-
*
|
|
196
|
+
* - Extract unique table names from errors to identify affected models
|
|
197
|
+
* - Categorize errors by type (field duplications, references, types, indexes)
|
|
198
|
+
* - Identify which models need correction vs. which remain unchanged
|
|
199
|
+
* 2. **Targeted Fix Strategy**
|
|
180
200
|
*
|
|
181
|
-
* -
|
|
182
|
-
* - Outline minimal changes needed for each
|
|
183
|
-
* -
|
|
184
|
-
*
|
|
201
|
+
* - Focus ONLY on models mentioned in validation errors
|
|
202
|
+
* - Outline minimal changes needed for each affected model
|
|
203
|
+
* - Plan cross-model reference updates (if any) without modifying non-error
|
|
204
|
+
* models
|
|
205
|
+
* - Ensure unchanged models maintain valid references to corrected models
|
|
206
|
+
* 3. **Model-Specific Fix Plan**
|
|
185
207
|
*
|
|
186
|
-
* - Model-by-model modification plan
|
|
187
|
-
* - Exact field additions,
|
|
188
|
-
* - Reference updates
|
|
189
|
-
* - Index corrections to
|
|
190
|
-
* 4. **
|
|
208
|
+
* - Model-by-model modification plan for ONLY affected models
|
|
209
|
+
* - Exact field additions, renames, or type corrections required
|
|
210
|
+
* - Reference updates within corrected models only
|
|
211
|
+
* - Index corrections limited to affected models
|
|
212
|
+
* 4. **Minimal Scope Validation**
|
|
191
213
|
*
|
|
192
|
-
* - Confirm which
|
|
193
|
-
* - List
|
|
194
|
-
* - Identify cross-model dependencies
|
|
195
|
-
*
|
|
214
|
+
* - Confirm which models will be included in output (error models only)
|
|
215
|
+
* - List models that will remain unchanged in original schema
|
|
216
|
+
* - Identify cross-model dependencies without including unchanged models
|
|
217
|
+
* - Preserve all business logic within corrected models
|
|
218
|
+
* 5. **Targeted Impact Assessment**
|
|
196
219
|
*
|
|
197
|
-
* - Potential
|
|
198
|
-
* -
|
|
199
|
-
* - Ensure no new validation errors
|
|
220
|
+
* - Potential effects of fixes on unchanged models (reference validation)
|
|
221
|
+
* - Verification points for corrected models only
|
|
222
|
+
* - Ensure no new validation errors in targeted models
|
|
223
|
+
* - Confirm minimal output scope compliance
|
|
200
224
|
*
|
|
201
225
|
* 💡 Example Planning Structure:
|
|
202
226
|
*
|
|
203
|
-
* ## Error
|
|
204
|
-
* -
|
|
205
|
-
* -
|
|
227
|
+
* ## Error Scope
|
|
228
|
+
* - Target Models: shopping_customers, shopping_orders (2 models only)
|
|
229
|
+
* - Unchanged Models: All others remain in original schema
|
|
206
230
|
*
|
|
207
|
-
* ##
|
|
208
|
-
*
|
|
209
|
-
*
|
|
231
|
+
* ## Targeted Fixes
|
|
232
|
+
* - shopping_customers: Remove duplicate 'email' field
|
|
233
|
+
* - shopping_orders: Update targetModel reference to 'shopping_customers'
|
|
210
234
|
*
|
|
211
|
-
* ##
|
|
212
|
-
*
|
|
213
|
-
*
|
|
235
|
+
* ## Output Scope
|
|
236
|
+
* - Return: Only shopping_customers and shopping_orders models
|
|
237
|
+
* - Preserve: All other models unchanged in original schema
|
|
214
238
|
*
|
|
215
|
-
* ##
|
|
216
|
-
* -
|
|
217
|
-
* -
|
|
218
|
-
* - Preserve all indexes and constraints
|
|
239
|
+
* ## Cross-Model Impact
|
|
240
|
+
* - Verify: shopping_orders still references shopping_customers correctly
|
|
241
|
+
* - No changes needed in other models referencing these
|
|
219
242
|
*/
|
|
220
243
|
planning: string;
|
|
221
244
|
|
|
222
245
|
/**
|
|
223
|
-
*
|
|
224
|
-
*
|
|
246
|
+
* ONLY the specific models that contain validation errors and need
|
|
247
|
+
* correction.
|
|
225
248
|
*
|
|
226
249
|
* 📥 Input Structure:
|
|
227
250
|
*
|
|
228
|
-
* -
|
|
229
|
-
* - Each
|
|
230
|
-
* -
|
|
231
|
-
*
|
|
251
|
+
* - Contains ONLY models mentioned in IAutoBePrismaValidation.IError[] array
|
|
252
|
+
* - Each model has specific validation errors that need targeted correction
|
|
253
|
+
* - Models not mentioned in errors are excluded from this input
|
|
254
|
+
* - Represents minimal scope for error correction
|
|
255
|
+
*
|
|
256
|
+
* 🔍 Expected Validation Issues (Model-Specific):
|
|
257
|
+
*
|
|
258
|
+
* - Duplicate field/relation names within these specific models
|
|
259
|
+
* - Invalid foreign key references from these models to other models
|
|
260
|
+
* - Single foreign key fields in index arrays within these models
|
|
261
|
+
* - Invalid naming conventions within these specific models
|
|
262
|
+
* - Type validation errors in fields of these models
|
|
232
263
|
*
|
|
233
|
-
*
|
|
264
|
+
* 📝 Model Content Analysis (Targeted Scope):
|
|
234
265
|
*
|
|
235
|
-
* -
|
|
236
|
-
* -
|
|
237
|
-
* -
|
|
238
|
-
* -
|
|
239
|
-
* -
|
|
266
|
+
* - Complete field definitions for each error model only
|
|
267
|
+
* - Relationships from these models (may reference unchanged models)
|
|
268
|
+
* - Indexes within these models that need correction
|
|
269
|
+
* - Business descriptions specific to these models
|
|
270
|
+
* - Cross-model references that need validation (read-only for targets)
|
|
240
271
|
*
|
|
241
|
-
*
|
|
272
|
+
* ⚠️ Processing Notes (Focused Approach):
|
|
242
273
|
*
|
|
243
|
-
* -
|
|
244
|
-
* -
|
|
245
|
-
* -
|
|
246
|
-
*
|
|
247
|
-
* -
|
|
274
|
+
* - Input contains ONLY models with validation errors
|
|
275
|
+
* - May reference other models not included in this input
|
|
276
|
+
* - Cross-model references must be validated but target models won't be
|
|
277
|
+
* modified
|
|
278
|
+
* - Output should return corrected versions of ONLY these input models
|
|
279
|
+
* - All business logic and descriptions within these models must be preserved
|
|
280
|
+
* - Corrections must not break references from unchanged models
|
|
248
281
|
*
|
|
249
|
-
*
|
|
282
|
+
* 🎯 Correction Scope:
|
|
250
283
|
*
|
|
251
|
-
* -
|
|
252
|
-
* -
|
|
253
|
-
* -
|
|
254
|
-
* -
|
|
255
|
-
* -
|
|
284
|
+
* - Fix validation errors within these specific models
|
|
285
|
+
* - Update internal model structure (fields, relations, indexes)
|
|
286
|
+
* - Correct references to external models (without modifying targets)
|
|
287
|
+
* - Maintain compatibility with unchanged models in the full schema
|
|
288
|
+
* - Return corrected versions of ONLY these models
|
|
256
289
|
*/
|
|
257
|
-
|
|
290
|
+
models: AutoBePrisma.IModel[];
|
|
258
291
|
}
|