@autobe/agent 0.13.0 → 0.14.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/AutoBeMockAgent.js +2 -1
- package/lib/AutoBeMockAgent.js.map +1 -1
- package/lib/constants/AutoBeSystemPromptConstant.d.ts +7 -9
- package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
- package/lib/factory/getAutoBeGenerated.js +11 -1
- package/lib/factory/getAutoBeGenerated.js.map +1 -1
- package/lib/index.mjs +391 -236
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +107 -110
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
- package/lib/orchestrate/interface/transformInterfaceHistories.js +10 -0
- package/lib/orchestrate/interface/transformInterfaceHistories.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealize.js +30 -8
- package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
- package/lib/orchestrate/realize/{orchestrateRealizeDecorator.d.ts → orchestrateRealizeAuthorization.d.ts} +2 -2
- package/lib/orchestrate/realize/{orchestrateRealizeDecorator.js → orchestrateRealizeAuthorization.js} +104 -67
- package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js.map +1 -0
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js +51 -40
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizePlanner.d.ts +11 -2
- package/lib/orchestrate/realize/orchestrateRealizePlanner.js +2 -1
- package/lib/orchestrate/realize/orchestrateRealizePlanner.js.map +1 -1
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.d.ts +148 -17
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.d.ts +10 -2
- package/lib/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.d.ts +4 -4
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js +58 -11
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -1
- package/lib/orchestrate/realize/transformRealizeDecoratorCorrectHistories.d.ts +2 -3
- package/lib/orchestrate/realize/transformRealizeDecoratorCorrectHistories.js +15 -2
- package/lib/orchestrate/realize/transformRealizeDecoratorCorrectHistories.js.map +1 -1
- package/lib/orchestrate/realize/utils/AuthorizationFileSystem.d.ts +5 -0
- package/lib/orchestrate/realize/utils/AuthorizationFileSystem.js +10 -0
- package/lib/orchestrate/realize/utils/AuthorizationFileSystem.js.map +1 -0
- package/lib/orchestrate/realize/utils/replaceImportStatements.d.ts +3 -0
- package/lib/orchestrate/realize/utils/replaceImportStatements.js +65 -0
- package/lib/orchestrate/realize/utils/replaceImportStatements.js.map +1 -0
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.d.ts +2 -3
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js +45 -24
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js.map +1 -1
- package/package.json +5 -5
- package/src/AutoBeMockAgent.ts +3 -2
- package/src/constants/AutoBeSystemPromptConstant.ts +7 -9
- package/src/factory/getAutoBeGenerated.ts +20 -5
- package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +26 -18
- package/src/orchestrate/interface/transformInterfaceHistories.ts +10 -0
- package/src/orchestrate/realize/orchestrateRealize.ts +32 -7
- package/src/orchestrate/realize/{orchestrateRealizeDecorator.ts → orchestrateRealizeAuthorization.ts} +90 -80
- package/src/orchestrate/realize/orchestrateRealizeCoder.ts +9 -30
- package/src/orchestrate/realize/orchestrateRealizePlanner.ts +13 -1
- package/src/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.ts +150 -17
- package/src/orchestrate/realize/structures/IAutoBeRealizeCompile.ts +13 -2
- package/src/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.ts +4 -4
- package/src/orchestrate/realize/transformRealizeCoderHistories.ts +55 -8
- package/src/orchestrate/realize/transformRealizeDecoratorCorrectHistories.ts +23 -3
- package/src/orchestrate/realize/utils/AuthorizationFileSystem.ts +10 -0
- package/src/orchestrate/realize/utils/replaceImportStatements.ts +85 -0
- package/src/orchestrate/realize/writeCodeUntilCompilePassed.ts +58 -33
- package/lib/orchestrate/realize/orchestrateRealizeDecorator.js.map +0 -1
|
@@ -36,18 +36,89 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
36
36
|
filename: string;
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
+
* Error Analysis Phase (Optional)
|
|
40
|
+
*
|
|
41
|
+
* 🔍 Analyzes TypeScript compilation errors from previous attempts.
|
|
42
|
+
*
|
|
43
|
+
* This field should contain a detailed analysis of any TypeScript errors
|
|
44
|
+
* encountered, with root cause identification and resolution strategies:
|
|
45
|
+
*
|
|
46
|
+
* Common Error Patterns to Analyze:
|
|
47
|
+
*
|
|
48
|
+
* 1. **"Property does not exist" (TS2353)**:
|
|
49
|
+
*
|
|
50
|
+
* - Root Cause: Using fields that don't exist in Prisma schema
|
|
51
|
+
* - Example: Using `deleted_at` when the field doesn't exist in the model
|
|
52
|
+
* - Resolution: Remove the non-existent field or use hard delete instead
|
|
53
|
+
* 2. **"Type 'void' is not assignable" (TS2322)**:
|
|
54
|
+
*
|
|
55
|
+
* - Root Cause: Using `typia.assertGuard` instead of `typia.assert`
|
|
56
|
+
* - `assertGuard` returns void, `assert` returns the validated value
|
|
57
|
+
* - Resolution: Change `typia.assertGuard<T>()` to `typia.assert<T>()`
|
|
58
|
+
* 3. **"Type 'Date' is not assignable to type 'string &
|
|
59
|
+
* Format<'date-time'>'"**:
|
|
60
|
+
*
|
|
61
|
+
* - Root Cause: Assigning native Date objects to string fields
|
|
62
|
+
* - Resolution: Use `toISOStringSafe(dateValue)` for all date conversions
|
|
63
|
+
* 4. **Complex Prisma Type Errors**:
|
|
64
|
+
*
|
|
65
|
+
* - Root Cause: Nested operations with incompatible types
|
|
66
|
+
* - Resolution: Use separate queries and application-level joins
|
|
67
|
+
*
|
|
68
|
+
* Analysis Format:
|
|
69
|
+
*
|
|
70
|
+
* - List each error with its TypeScript error code
|
|
71
|
+
* - Identify the root cause (schema mismatch, wrong function usage, etc.)
|
|
72
|
+
* - Provide specific resolution steps
|
|
73
|
+
* - Note any schema limitations discovered
|
|
74
|
+
*/
|
|
75
|
+
errorAnalysis?: string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Step 1.
|
|
79
|
+
*
|
|
39
80
|
* 🧠 Provider Function Implementation Plan
|
|
40
81
|
*
|
|
41
82
|
* This field outlines the strategic plan for implementing the provider
|
|
42
83
|
* function according to the Realize Coder Agent specification. Before
|
|
43
84
|
* writing the actual code, think through the logic and structure.
|
|
44
85
|
*
|
|
45
|
-
* The plan
|
|
86
|
+
* The plan MUST follow MANDATORY SCHEMA-FIRST APPROACH:
|
|
87
|
+
*
|
|
88
|
+
* 📋 STEP 1 - PRISMA SCHEMA VERIFICATION (MOST CRITICAL):
|
|
89
|
+
*
|
|
90
|
+
* - EXAMINE the actual Prisma schema model definition
|
|
91
|
+
* - LIST EVERY field that exists in the model with exact types
|
|
92
|
+
* - EXPLICITLY NOTE fields that DO NOT exist (e.g., "Note: deleted_at field
|
|
93
|
+
* DOES NOT EXIST")
|
|
94
|
+
* - Common assumption errors to avoid: `deleted_at`, `created_by`,
|
|
95
|
+
* `updated_by`, `is_deleted`, `is_active`
|
|
96
|
+
*
|
|
97
|
+
* 📋 STEP 2 - FIELD INVENTORY:
|
|
98
|
+
*
|
|
99
|
+
* - List ONLY fields confirmed to exist in schema
|
|
100
|
+
* - Example: "Verified fields in user model: id (String), email (String),
|
|
101
|
+
* created_at (DateTime), updated_at (DateTime)"
|
|
102
|
+
* - Example: "Fields that DO NOT exist: deleted_at, is_active, created_by"
|
|
103
|
+
*
|
|
104
|
+
* 📋 STEP 3 - FIELD ACCESS STRATEGY:
|
|
105
|
+
*
|
|
106
|
+
* - Plan which verified fields will be used in select, update, create
|
|
107
|
+
* operations
|
|
108
|
+
* - For complex operations with type errors, plan to use separate queries
|
|
109
|
+
* instead of nested operations
|
|
110
|
+
*
|
|
111
|
+
* 📋 STEP 4 - TYPE COMPATIBILITY:
|
|
112
|
+
*
|
|
113
|
+
* - Plan DateTime to ISO string conversions using toISOStringSafe()
|
|
114
|
+
* - Plan handling of nullable vs required fields
|
|
115
|
+
*
|
|
116
|
+
* 📋 STEP 5 - IMPLEMENTATION APPROACH:
|
|
46
117
|
*
|
|
47
118
|
* - 🧩 Required business entities (e.g., users, posts, logs) and their
|
|
48
119
|
* relationships
|
|
49
120
|
* - 🛠 Operations needed to fulfill the business scenario (e.g., fetch,
|
|
50
|
-
* create, update)
|
|
121
|
+
* create, update) using ONLY verified fields
|
|
51
122
|
* - 🔄 Data dependencies between steps (e.g., use userId to fetch related
|
|
52
123
|
* data)
|
|
53
124
|
* - ✅ Validation points (based on business rules, not field presence)
|
|
@@ -69,7 +140,7 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
69
140
|
* ⚠️ TypeScript-specific considerations:
|
|
70
141
|
*
|
|
71
142
|
* - Do **not** use native `Date` objects directly; always convert all dates
|
|
72
|
-
*
|
|
143
|
+
* using `toISOStringSafe()` and brand as `string &
|
|
73
144
|
* tags.Format<'date-time'>`. This rule applies throughout all phases.
|
|
74
145
|
* - Prefer `satisfies` for DTO conformance instead of unsafe `as` casts
|
|
75
146
|
* - Avoid weak typing such as `any`, `as any`, or `satisfies any`
|
|
@@ -93,6 +164,18 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
93
164
|
* }
|
|
94
165
|
* ```
|
|
95
166
|
*
|
|
167
|
+
* 🔍 Feasibility Analysis Requirement:
|
|
168
|
+
*
|
|
169
|
+
* - Before generating any code, the agent **must analyze** whether the
|
|
170
|
+
* requested implementation is **feasible based on the given Prisma schema
|
|
171
|
+
* and DTO types**.
|
|
172
|
+
* - If required fields or relationships are **missing or incompatible**, the
|
|
173
|
+
* plan should explicitly state that the implementation is **not
|
|
174
|
+
* possible** with the current schema/DTO, and no code should be generated
|
|
175
|
+
* in later stages.
|
|
176
|
+
* - In such cases, only a detailed **comment in the `implementationCode`**
|
|
177
|
+
* should be returned explaining why the logic cannot be implemented.
|
|
178
|
+
*
|
|
96
179
|
* 🔥 Error Handling Plan:
|
|
97
180
|
*
|
|
98
181
|
* If an error is expected or encountered during implementation:
|
|
@@ -118,10 +201,35 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
118
201
|
plan: string;
|
|
119
202
|
|
|
120
203
|
/**
|
|
121
|
-
*
|
|
204
|
+
* Step 2.
|
|
205
|
+
*
|
|
206
|
+
* The Prisma schema string that will be used to validate the implementation
|
|
207
|
+
* logic in this file.
|
|
208
|
+
*
|
|
209
|
+
* You must **explicitly specify only the relevant models and fields** from
|
|
210
|
+
* your full schema that are used in this implementation. This ensures that
|
|
211
|
+
* your logic is aligned with the expected database structure without
|
|
212
|
+
* accidentally introducing unrelated fields or models.
|
|
213
|
+
*
|
|
214
|
+
* ⚠️ Important: The value of this field must be a valid Prisma schema
|
|
215
|
+
* string containing only the models used in this code — not the entire
|
|
216
|
+
* schema.
|
|
217
|
+
*
|
|
218
|
+
* This acts as a safeguard against:
|
|
219
|
+
*
|
|
220
|
+
* - Forgetting required fields used in this implementation
|
|
221
|
+
* - Including fields or models that are not actually used
|
|
222
|
+
*/
|
|
223
|
+
prisma_schemas: string;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Step 3.
|
|
227
|
+
*
|
|
228
|
+
* Draft WITHOUT using native Date type.
|
|
122
229
|
*
|
|
123
230
|
* This is the initial drafting phase where you outline the basic skeleton
|
|
124
|
-
* of the function.
|
|
231
|
+
* of the function. CRITICAL: This draft must NEVER use the native Date
|
|
232
|
+
* type.
|
|
125
233
|
*
|
|
126
234
|
* - The function signature must correctly include `user`, `parameters`, and
|
|
127
235
|
* `body` arguments.
|
|
@@ -141,14 +249,15 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
141
249
|
* ✅ Requirements:
|
|
142
250
|
*
|
|
143
251
|
* - Avoid using the `any` type at all costs to ensure type safety.
|
|
144
|
-
* -
|
|
145
|
-
*
|
|
252
|
+
* - NEVER declare variables with `: Date` type
|
|
253
|
+
* - ALWAYS use `string & tags.Format<'date-time'>` for date values
|
|
254
|
+
* - Use `toISOStringSafe(new Date())` for current timestamps
|
|
146
255
|
* - Maintain a single-function structure; avoid using classes.
|
|
147
256
|
*/
|
|
148
257
|
draft_without_date_type: string;
|
|
149
258
|
|
|
150
259
|
/**
|
|
151
|
-
*
|
|
260
|
+
* Step 4.
|
|
152
261
|
*
|
|
153
262
|
* A refined version of the draft with improved completeness.
|
|
154
263
|
*
|
|
@@ -160,13 +269,13 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
160
269
|
*
|
|
161
270
|
* - Use `satisfies` to ensure DTO conformity.
|
|
162
271
|
* - Avoid unsafe `as` casts unless only for branding or literal narrowing.
|
|
163
|
-
* -
|
|
272
|
+
* - Use `toISOStringSafe()` for all date conversions (NOT `.toISOString()`).
|
|
164
273
|
* - Ensure all object keys strictly conform to the expected type definitions.
|
|
165
274
|
*/
|
|
166
275
|
review: string;
|
|
167
276
|
|
|
168
277
|
/**
|
|
169
|
-
* 🛠 Phase
|
|
278
|
+
* 🛠 Phase 4-2: With compiler feedback (optional)
|
|
170
279
|
*
|
|
171
280
|
* A correction pass that applies fixes for compile-time errors that arose
|
|
172
281
|
* during the review stage (if any).
|
|
@@ -182,25 +291,45 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
182
291
|
withCompilerFeedback?: string;
|
|
183
292
|
|
|
184
293
|
/**
|
|
185
|
-
*
|
|
294
|
+
* Step 5.
|
|
186
295
|
*
|
|
187
296
|
* The complete and fully correct TypeScript function implementation.
|
|
188
297
|
*
|
|
189
298
|
* - Passes strict type checking without errors.
|
|
190
299
|
* - Uses only safe branding or literal type assertions.
|
|
191
|
-
* - Converts all date values properly
|
|
300
|
+
* - Converts all date values properly using `toISOStringSafe()`.
|
|
192
301
|
* - Follows DTO structures using `satisfies`.
|
|
193
302
|
* - Avoids any weak typing such as `any`, `as any`, or `satisfies any`.
|
|
194
|
-
* - Uses only allowed imports (e.g., from
|
|
303
|
+
* - Uses only allowed imports (e.g., from `../api/structures` and
|
|
195
304
|
* `MyGlobal.prisma`).
|
|
305
|
+
* - NEVER creates intermediate variables for Prisma operations.
|
|
306
|
+
*
|
|
307
|
+
* ⚠️ Fallback Behavior:
|
|
308
|
+
*
|
|
309
|
+
* - If the `plan` phase explicitly determines that the requested logic is
|
|
310
|
+
* **not feasible** due to mismatches or limitations in the provided
|
|
311
|
+
* Prisma schema and DTO types:
|
|
312
|
+
*
|
|
313
|
+
* - The implementation must still return a syntactically valid function.
|
|
314
|
+
* - In such cases, return mock data using `typia.random<T>()` wrapped in the
|
|
315
|
+
* correct structure, along with a comment explaining the limitation.
|
|
316
|
+
*
|
|
317
|
+
* Example fallback:
|
|
318
|
+
*
|
|
319
|
+
* ```ts
|
|
320
|
+
* // ⚠️ Cannot implement logic due to missing relation between A and B
|
|
321
|
+
* export async function someFunction(...) {
|
|
322
|
+
* return typia.random<IReturn>(); // mocked output
|
|
323
|
+
* }
|
|
324
|
+
* ```
|
|
196
325
|
*
|
|
197
326
|
* ⚠️ Prohibited Practices:
|
|
198
327
|
*
|
|
199
328
|
* - Do NOT add or modify import statements manually. Imports are handled
|
|
200
329
|
* automatically by the system.
|
|
201
330
|
* - Do NOT use `any`, `as any`, or `satisfies any` to bypass type checking.
|
|
202
|
-
* - Do NOT assign native `Date` objects directly; always convert them
|
|
203
|
-
*
|
|
331
|
+
* - Do NOT assign native `Date` objects directly; always convert them using
|
|
332
|
+
* `toISOStringSafe()`.
|
|
204
333
|
* - Do NOT use unsafe type assertions except for safe branding or literal
|
|
205
334
|
* narrowing.
|
|
206
335
|
* - Do NOT write code outside the single async function structure (e.g., no
|
|
@@ -209,8 +338,12 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
209
338
|
* validated.
|
|
210
339
|
* - Do NOT use dynamic import expressions (`import()`); all imports must be
|
|
211
340
|
* static.
|
|
212
|
-
* - Do NOT
|
|
213
|
-
*
|
|
341
|
+
* - Do NOT use Prisma-generated input types; always use types from
|
|
342
|
+
* `../api/structures`.
|
|
343
|
+
* - Do NOT use `Object.prototype.hasOwnProperty.call()` for field checks.
|
|
344
|
+
* - Do NOT escape newlines or quotes in the implementation string (e.g., no
|
|
345
|
+
* `\\n` or `\"`); use a properly formatted template literal with actual
|
|
346
|
+
* line breaks instead.
|
|
214
347
|
*/
|
|
215
348
|
implementationCode: string;
|
|
216
349
|
}
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
AutoBeOpenApi,
|
|
3
3
|
IAutoBeTypeScriptCompileResult,
|
|
4
4
|
} from "@autobe/interface";
|
|
5
|
+
import { tags } from "typia";
|
|
5
6
|
|
|
6
7
|
import { IAutoBeRealizeCoderApplication } from "./IAutoBeRealizeCoderApplication";
|
|
7
8
|
import { FAILED } from "./IAutoBeRealizeFailedSymbol";
|
|
@@ -13,7 +14,10 @@ export namespace IAutoBeRealizeCompile {
|
|
|
13
14
|
result: Pick<
|
|
14
15
|
IAutoBeRealizeCoderApplication.RealizeCoderOutput,
|
|
15
16
|
"filename" | "implementationCode"
|
|
16
|
-
|
|
17
|
+
> & {
|
|
18
|
+
/** Function name */
|
|
19
|
+
name: string;
|
|
20
|
+
};
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
export interface Fail {
|
|
@@ -24,7 +28,14 @@ export namespace IAutoBeRealizeCompile {
|
|
|
24
28
|
|
|
25
29
|
export type FileContentMap = Record<
|
|
26
30
|
string,
|
|
27
|
-
{
|
|
31
|
+
{
|
|
32
|
+
result: "failed" | "success";
|
|
33
|
+
content: string;
|
|
34
|
+
role?: (string & tags.MinLength<1>) | null;
|
|
35
|
+
endpoint?: AutoBeOpenApi.IEndpoint;
|
|
36
|
+
location?: string;
|
|
37
|
+
name?: string;
|
|
38
|
+
}
|
|
28
39
|
>;
|
|
29
40
|
|
|
30
41
|
export interface CompileDiagnostics {
|
|
@@ -21,13 +21,13 @@ export namespace IAutoBeRealizeDecoratorApplication {
|
|
|
21
21
|
decorator: IAutoBeRealizeDecoratorApplication.IDecorator;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* Authentication
|
|
25
|
-
* name and implementation code. The
|
|
24
|
+
* Authentication Payload Type configuration containing the payload type
|
|
25
|
+
* name and implementation code. The Payload Type is used to define the
|
|
26
26
|
* structure of the authenticated user data that will be injected into
|
|
27
27
|
* Controller methods when using the decorator. It serves as the TypeScript
|
|
28
28
|
* type for the parameter in Controller method signatures.
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
payload: IAutoBeRealizeDecoratorApplication.IPayloadType;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export interface IProvider {
|
|
@@ -72,7 +72,7 @@ export namespace IAutoBeRealizeDecoratorApplication {
|
|
|
72
72
|
code: string;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
export interface
|
|
75
|
+
export interface IPayloadType {
|
|
76
76
|
/**
|
|
77
77
|
* The name of the Decorator to be generated in {Role}Auth format (e.g.,
|
|
78
78
|
* AdminAuth, UserAuth). This decorator will be used as a parameter
|
|
@@ -91,6 +91,25 @@ export const transformRealizeCoderHistories = (
|
|
|
91
91
|
type: "systemMessage",
|
|
92
92
|
text: AutoBeSystemPromptConstant.REALIZE_CODER_TOTAL,
|
|
93
93
|
},
|
|
94
|
+
{
|
|
95
|
+
id: v4(),
|
|
96
|
+
created_at: new Date().toISOString(),
|
|
97
|
+
type: "systemMessage",
|
|
98
|
+
text: props.decoratorEvent
|
|
99
|
+
? [
|
|
100
|
+
"Decorator-related files are already generated at the following locations:",
|
|
101
|
+
`- Decorator implementation: decorators/${props.decoratorEvent.decorator.name}.ts`,
|
|
102
|
+
` - NestJS parameter decorator`,
|
|
103
|
+
` - When importing from providers folder, use: '../decorators/${props.decoratorEvent.decorator.name}'`,
|
|
104
|
+
`- Authentication provider: authentications/${props.decoratorEvent.provider.name}.ts`,
|
|
105
|
+
` - Contains JWT validation, role checking, and authorization logic`,
|
|
106
|
+
` - When importing from providers folder, use: '../authentications/${props.decoratorEvent.provider.name}'`,
|
|
107
|
+
`- Type definition: authentications/types/${props.decoratorEvent.payload.name}.ts`,
|
|
108
|
+
` - TypeScript interface for authenticated user payload`,
|
|
109
|
+
` - When importing from providers folder, use: '../authentications/types/${props.decoratorEvent.payload.name}'`,
|
|
110
|
+
].join("\n")
|
|
111
|
+
: "",
|
|
112
|
+
},
|
|
94
113
|
{
|
|
95
114
|
id: v4(),
|
|
96
115
|
created_at: new Date().toISOString(),
|
|
@@ -116,19 +135,47 @@ export const transformRealizeCoderHistories = (
|
|
|
116
135
|
// .replaceAll("{total_diagnostics}", JSON.stringify(total))
|
|
117
136
|
.replaceAll("{current_diagnostics}", JSON.stringify(diagnostics)),
|
|
118
137
|
} as const,
|
|
138
|
+
{
|
|
139
|
+
id: v4(),
|
|
140
|
+
created_at: new Date().toISOString(),
|
|
141
|
+
type: "systemMessage",
|
|
142
|
+
text: [
|
|
143
|
+
"Modify the previous code to reflect the following operation.",
|
|
144
|
+
"```json",
|
|
145
|
+
JSON.stringify(props),
|
|
146
|
+
"```",
|
|
147
|
+
].join("\n"),
|
|
148
|
+
} as const,
|
|
119
149
|
]
|
|
120
|
-
: [
|
|
150
|
+
: [
|
|
151
|
+
{
|
|
152
|
+
id: v4(),
|
|
153
|
+
created_at: new Date().toISOString(),
|
|
154
|
+
type: "systemMessage",
|
|
155
|
+
text: [
|
|
156
|
+
"Write new code based on the following operation.",
|
|
157
|
+
"```json",
|
|
158
|
+
JSON.stringify(props),
|
|
159
|
+
"```",
|
|
160
|
+
].join("\n"),
|
|
161
|
+
} as const,
|
|
162
|
+
]),
|
|
121
163
|
{
|
|
122
164
|
id: v4(),
|
|
123
165
|
created_at: new Date().toISOString(),
|
|
124
|
-
type: "
|
|
166
|
+
type: "assistantMessage",
|
|
125
167
|
text: [
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
168
|
+
`I understand your request.`,
|
|
169
|
+
``,
|
|
170
|
+
`To summarize:`,
|
|
171
|
+
`- I must **never use the native \`Date\` type** in any code or type definitions.`,
|
|
172
|
+
`- Instead, all date and datetime values must be handled as \`string & tags.Format<'date-time'>\`.`,
|
|
173
|
+
`- This rule is **strict** and applies everywhere, including domain types, API inputs/outputs, and Prisma models.`,
|
|
174
|
+
`- Even if a library or tool returns a \`Date\`, I must convert it to the correct string format before use.`,
|
|
175
|
+
``,
|
|
176
|
+
`Especially regarding the \`Date\` type: I understand that using it can lead to type inconsistency and runtime issues, so I will completely avoid it in all circumstances.`,
|
|
177
|
+
``,
|
|
178
|
+
`I'll make sure to follow all these rules strictly. Let’s proceed with this in mind.`,
|
|
132
179
|
].join("\n"),
|
|
133
180
|
},
|
|
134
181
|
{
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { IAgenticaHistoryJson } from "@agentica/core";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AutoBeRealizeAuthorization,
|
|
4
|
+
IAutoBeTypeScriptCompileResult,
|
|
5
|
+
} from "@autobe/interface";
|
|
3
6
|
import { ILlmSchema } from "@samchon/openapi";
|
|
4
7
|
import { v4 } from "uuid";
|
|
5
8
|
|
|
@@ -9,7 +12,7 @@ import { IAutoBeRealizeDecoratorApplication } from "./structures/IAutoBeRealizeD
|
|
|
9
12
|
|
|
10
13
|
export const transformRealizeDecoratorCorrectHistories = (
|
|
11
14
|
ctx: AutoBeContext<ILlmSchema.Model>,
|
|
12
|
-
|
|
15
|
+
auth: AutoBeRealizeAuthorization,
|
|
13
16
|
templateFiles: Record<string, string>,
|
|
14
17
|
diagnostics: IAutoBeTypeScriptCompileResult.IDiagnostic[],
|
|
15
18
|
): Array<
|
|
@@ -30,7 +33,24 @@ export const transformRealizeDecoratorCorrectHistories = (
|
|
|
30
33
|
"## Generated TypeScript Code",
|
|
31
34
|
"",
|
|
32
35
|
"```json",
|
|
33
|
-
`${JSON.stringify(
|
|
36
|
+
`${JSON.stringify(
|
|
37
|
+
{
|
|
38
|
+
provider: {
|
|
39
|
+
name: auth.provider.name,
|
|
40
|
+
code: auth.provider.content,
|
|
41
|
+
},
|
|
42
|
+
decorator: {
|
|
43
|
+
name: auth.decorator.name,
|
|
44
|
+
code: auth.decorator.content,
|
|
45
|
+
},
|
|
46
|
+
payload: {
|
|
47
|
+
name: auth.payload.name,
|
|
48
|
+
code: auth.payload.content,
|
|
49
|
+
},
|
|
50
|
+
} satisfies IAutoBeRealizeDecoratorApplication.IProps,
|
|
51
|
+
null,
|
|
52
|
+
2,
|
|
53
|
+
)}`,
|
|
34
54
|
"```",
|
|
35
55
|
"",
|
|
36
56
|
"## Prisma Schema",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export namespace AuthorizationFileSystem {
|
|
2
|
+
export const decoratorPath = (name: string): string =>
|
|
3
|
+
`src/decorators/${name}.ts`;
|
|
4
|
+
|
|
5
|
+
export const payloadPath = (name: string): string =>
|
|
6
|
+
`src/decorators/payload/${name}.ts`;
|
|
7
|
+
|
|
8
|
+
export const providerPath = (name: string): string =>
|
|
9
|
+
`src/providers/authorize/${name}.ts`;
|
|
10
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { IAutoBeCompiler } from "@autobe/interface";
|
|
2
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
3
|
+
|
|
4
|
+
import { AutoBeContext } from "../../../context/AutoBeContext";
|
|
5
|
+
|
|
6
|
+
export function replaceImportStatements<Model extends ILlmSchema.Model>(
|
|
7
|
+
ctx: AutoBeContext<Model>,
|
|
8
|
+
) {
|
|
9
|
+
return async function (code: string, decoratorType?: string) {
|
|
10
|
+
const compiler: IAutoBeCompiler = await ctx.compiler();
|
|
11
|
+
code = await compiler.typescript.beautify(code);
|
|
12
|
+
// Remove existing import statements using flexible regex patterns
|
|
13
|
+
code = code
|
|
14
|
+
.replace(
|
|
15
|
+
/import\s*{\s*MyGlobal\s*}\s*from\s*["']\.\.\/MyGlobal["']\s*;?\s*/gm,
|
|
16
|
+
"",
|
|
17
|
+
)
|
|
18
|
+
.replace(
|
|
19
|
+
/import\s+typia\s*,\s*{\s*tags\s*}\s*from\s*["']typia["']\s*;?\s*/gm,
|
|
20
|
+
"",
|
|
21
|
+
)
|
|
22
|
+
.replace(/import\s*{\s*tags\s*}\s*from\s*["']typia["']\s*;?\s*/gm, "")
|
|
23
|
+
.replace(
|
|
24
|
+
/import\s*{\s*tags\s*,\s*typia\s*}\s*from\s*["']typia["']\s*;?\s*/gm,
|
|
25
|
+
"",
|
|
26
|
+
)
|
|
27
|
+
.replace(/import\s+typia\s*from\s*["']typia["']\s*;?\s*/gm, "")
|
|
28
|
+
.replace(
|
|
29
|
+
/import\s*{\s*Prisma\s*}\s*from\s*["']@prisma\/client["']\s*;?\s*/gm,
|
|
30
|
+
"",
|
|
31
|
+
)
|
|
32
|
+
.replace(/import\s*{\s*v4\s*}\s*from\s*["']uuid["']\s*;?\s*/gm, "")
|
|
33
|
+
.replace(
|
|
34
|
+
/import\s*{\s*toISOStringSafe\s*}\s*from\s*["']\.\.\/util\/toISOStringSafe["']\s*;?\s*/gm,
|
|
35
|
+
"",
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// Remove any existing decoratorType imports if LLM mistakenly added them
|
|
39
|
+
if (decoratorType) {
|
|
40
|
+
const decoratorTypeRegex = new RegExp(
|
|
41
|
+
`import\\s*{\\s*${decoratorType}\\s*}\\s*from\\s*["']\\.\\.\/authentications\/types\/${decoratorType}["']\\s*;?\\s*`,
|
|
42
|
+
"gm",
|
|
43
|
+
);
|
|
44
|
+
code = code.replace(decoratorTypeRegex, "");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Build the standard imports
|
|
48
|
+
const imports = [
|
|
49
|
+
'import { MyGlobal } from "../MyGlobal";',
|
|
50
|
+
'import typia, { tags } from "typia";',
|
|
51
|
+
'import { Prisma } from "@prisma/client";',
|
|
52
|
+
'import { v4 } from "uuid";',
|
|
53
|
+
'import { toISOStringSafe } from "../util/toISOStringSafe"',
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
// Only add decoratorType import if it exists
|
|
57
|
+
if (decoratorType) {
|
|
58
|
+
imports.push(
|
|
59
|
+
`import { ${decoratorType} } from "../authentications/types/${decoratorType}"`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
code = [...imports, "", code].join("\n");
|
|
64
|
+
|
|
65
|
+
// Clean up formatting issues
|
|
66
|
+
code =
|
|
67
|
+
code
|
|
68
|
+
// Remove lines with only whitespace
|
|
69
|
+
.replace(/^\s+$/gm, "")
|
|
70
|
+
// Replace 3+ consecutive newlines with exactly 2 newlines
|
|
71
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
72
|
+
// Ensure proper spacing after import section
|
|
73
|
+
.replace(/(import.*?;)(\s*)(\n(?!import|\s*$))/g, "$1\n\n$3")
|
|
74
|
+
// Trim and ensure single trailing newline
|
|
75
|
+
.trim() + "\n";
|
|
76
|
+
|
|
77
|
+
// fix escaped codes
|
|
78
|
+
code = code.replace(/\\n/g, "\n").replace(/\\"/g, '"').replace(/\\'/g, "'");
|
|
79
|
+
|
|
80
|
+
// Apply final beautification
|
|
81
|
+
code = await compiler.typescript.beautify(code);
|
|
82
|
+
|
|
83
|
+
return code;
|
|
84
|
+
};
|
|
85
|
+
}
|