@autobe/agent 0.15.1 → 0.16.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.
- package/lib/AutoBeAgent.js +2 -2
- package/lib/AutoBeAgent.js.map +1 -1
- package/lib/AutoBeMockAgent.d.ts +1 -0
- package/lib/AutoBeMockAgent.js +18 -4
- package/lib/AutoBeMockAgent.js.map +1 -1
- package/lib/constants/AutoBeSystemPromptConstant.d.ts +3 -3
- package/lib/factory/getAutoBeGenerated.js +2 -1
- package/lib/factory/getAutoBeGenerated.js.map +1 -1
- package/lib/index.mjs +739 -577
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.d.ts +0 -15
- package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.js +0 -3
- package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyze.js +19 -12
- package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.d.ts +1 -2
- package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.js +3 -5
- package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.d.ts +7 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js +363 -4
- package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.d.ts +3 -3
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js +3 -118
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js.map +1 -1
- package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js +1 -1
- package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js.map +1 -1
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.d.ts +11 -4
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js +61 -45
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js.map +1 -1
- package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js +17 -10
- package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js.map +1 -1
- package/lib/orchestrate/realize/ProviderCodeComparator.d.ts +5 -0
- package/lib/orchestrate/realize/ProviderCodeComparator.js +16 -0
- package/lib/orchestrate/realize/ProviderCodeComparator.js.map +1 -0
- package/lib/orchestrate/realize/orchestrateRealize.js +41 -53
- package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js +13 -87
- package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.js +32 -43
- package/lib/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeCoder.d.ts +3 -2
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js +25 -39
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -1
- package/lib/orchestrate/realize/structures/IAutoBeRealizeAuthorizationApplication.d.ts +15 -15
- package/lib/orchestrate/realize/structures/IAutoBeRealizeAuthorizationCorrectApplication.d.ts +11 -17
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.d.ts +4 -2
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.d.ts +21 -17
- package/lib/orchestrate/realize/transformRealizeAuthorization.js +5 -9
- package/lib/orchestrate/realize/transformRealizeAuthorization.js.map +1 -1
- package/lib/orchestrate/realize/transformRealizeAuthorizationCorrectHistories.js +9 -0
- package/lib/orchestrate/realize/transformRealizeAuthorizationCorrectHistories.js.map +1 -1
- package/lib/orchestrate/realize/transformRealizeCoderHistories.d.ts +3 -2
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js +58 -27
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -1
- package/lib/orchestrate/realize/utils/AutoBeRealizeAuthorizationFileSystem.d.ts +5 -0
- package/lib/orchestrate/realize/utils/AutoBeRealizeAuthorizationFileSystem.js +10 -0
- package/lib/orchestrate/realize/utils/AutoBeRealizeAuthorizationFileSystem.js.map +1 -0
- package/lib/orchestrate/realize/utils/AutoBeRealizeAuthorizationReplaceImport.d.ts +4 -0
- package/lib/orchestrate/realize/utils/AutoBeRealizeAuthorizationReplaceImport.js +38 -0
- package/lib/orchestrate/realize/utils/AutoBeRealizeAuthorizationReplaceImport.js.map +1 -0
- package/lib/orchestrate/realize/utils/replaceImportStatements.d.ts +2 -1
- package/lib/orchestrate/realize/utils/replaceImportStatements.js +15 -2
- package/lib/orchestrate/realize/utils/replaceImportStatements.js.map +1 -1
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.d.ts +9 -2
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js +158 -100
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTest.js +1 -1
- package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
- package/package.json +6 -6
- package/src/AutoBeAgent.ts +1 -1
- package/src/AutoBeMockAgent.ts +20 -6
- package/src/constants/AutoBeSystemPromptConstant.ts +3 -3
- package/src/factory/getAutoBeGenerated.ts +2 -1
- package/src/orchestrate/analyze/AutoBeAnalyzeFileSystem.ts +0 -15
- package/src/orchestrate/analyze/orchestrateAnalyze.ts +17 -17
- package/src/orchestrate/analyze/orchestrateAnalyzeComposer.ts +4 -7
- package/src/orchestrate/analyze/orchestrateAnalyzeReviewer.ts +100 -6
- package/src/orchestrate/analyze/orchestrateAnalyzeWrite.ts +5 -21
- package/src/orchestrate/analyze/writeDocumentUntilReviewPassed.ts +76 -59
- package/src/orchestrate/prisma/transformPrismaComponentsHistories.ts +17 -10
- package/src/orchestrate/realize/ProviderCodeComparator.ts +15 -0
- package/src/orchestrate/realize/orchestrateRealize.ts +54 -59
- package/src/orchestrate/realize/orchestrateRealizeAuthorization.ts +12 -120
- package/src/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.ts +21 -5
- package/src/orchestrate/realize/orchestrateRealizeCoder.ts +10 -9
- package/src/orchestrate/realize/structures/IAutoBeRealizeAuthorizationApplication.ts +15 -15
- package/src/orchestrate/realize/structures/IAutoBeRealizeAuthorizationCorrectApplication.ts +11 -18
- package/src/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.ts +4 -2
- package/src/orchestrate/realize/structures/IAutoBeRealizeCompile.ts +24 -17
- package/src/orchestrate/realize/transformRealizeAuthorization.ts +5 -9
- package/src/orchestrate/realize/transformRealizeAuthorizationCorrectHistories.ts +9 -0
- package/src/orchestrate/realize/transformRealizeCoderHistories.ts +73 -25
- package/src/orchestrate/realize/utils/AutoBeRealizeAuthorizationFileSystem.ts +9 -0
- package/src/orchestrate/realize/utils/AutoBeRealizeAuthorizationReplaceImport.ts +64 -0
- package/src/orchestrate/realize/utils/replaceImportStatements.ts +41 -2
- package/src/orchestrate/realize/writeCodeUntilCompilePassed.ts +219 -145
- package/src/orchestrate/test/orchestrateTest.ts +1 -1
|
@@ -80,6 +80,15 @@ export const transformRealizeAuthorizationCorrectHistories = (
|
|
|
80
80
|
"```json",
|
|
81
81
|
JSON.stringify(diagnostics, null, 2),
|
|
82
82
|
"```",
|
|
83
|
+
"## Component Naming Convention",
|
|
84
|
+
"",
|
|
85
|
+
"If the name of the component is not correct, please correct it.",
|
|
86
|
+
"",
|
|
87
|
+
"Please follow this naming convention for the authorization components:",
|
|
88
|
+
"",
|
|
89
|
+
`- Provider Name: ${auth.role.toLowerCase()}Authorize (e.g. ${auth.role.toLowerCase()}Authorize)`,
|
|
90
|
+
`- Decorator Name: ${auth.role.charAt(0).toUpperCase() + auth.role.slice(1).toLowerCase()}Auth (e.g. ${auth.role.charAt(0).toUpperCase() + auth.role.slice(1).toLowerCase()}Auth)`,
|
|
91
|
+
`- Payload Name: ${auth.role.charAt(0).toUpperCase() + auth.role.slice(1).toLowerCase()}Payload (e.g. ${auth.role.charAt(0).toUpperCase() + auth.role.slice(1).toLowerCase()}Payload)`,
|
|
83
92
|
].join("\n"),
|
|
84
93
|
},
|
|
85
94
|
];
|
|
@@ -1,21 +1,57 @@
|
|
|
1
1
|
import { IAgenticaHistoryJson } from "@agentica/core";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AutoBeRealizeAuthorization,
|
|
4
|
+
IAutoBeTypeScriptCompileResult,
|
|
5
|
+
} from "@autobe/interface";
|
|
3
6
|
import { v4 } from "uuid";
|
|
4
7
|
|
|
5
8
|
import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
|
|
6
9
|
import { AutoBeState } from "../../context/AutoBeState";
|
|
7
10
|
import { IAutoBeTestScenarioArtifacts } from "../test/structures/IAutoBeTestScenarioArtifacts";
|
|
8
11
|
import { RealizePlannerOutput } from "./orchestrateRealizePlanner";
|
|
12
|
+
import { IAutoBeRealizeCompile } from "./structures/IAutoBeRealizeCompile";
|
|
9
13
|
|
|
10
14
|
export const transformRealizeCoderHistories = (
|
|
11
15
|
state: AutoBeState,
|
|
16
|
+
previousCodes: IAutoBeRealizeCompile.Success[],
|
|
12
17
|
props: RealizePlannerOutput,
|
|
13
18
|
artifacts: IAutoBeTestScenarioArtifacts,
|
|
14
19
|
previous: string | null,
|
|
15
20
|
diagnostics: IAutoBeTypeScriptCompileResult.IDiagnostic[],
|
|
21
|
+
authorization?: AutoBeRealizeAuthorization,
|
|
16
22
|
): Array<
|
|
17
23
|
IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
|
|
18
24
|
> => {
|
|
25
|
+
const [operation] = artifacts.document.operations;
|
|
26
|
+
|
|
27
|
+
const propsFields: string[] = [];
|
|
28
|
+
|
|
29
|
+
// payload 추가
|
|
30
|
+
if (authorization && operation.authorizationRole) {
|
|
31
|
+
propsFields.push(
|
|
32
|
+
`${operation.authorizationRole}: ${authorization.payload.name};`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// parameters 추가
|
|
37
|
+
operation.parameters.forEach((parameter) => {
|
|
38
|
+
const format =
|
|
39
|
+
"format" in parameter.schema
|
|
40
|
+
? ` & tags.Format<'${parameter.schema.format}'>`
|
|
41
|
+
: "";
|
|
42
|
+
propsFields.push(`${parameter.name}: ${parameter.schema.type}${format};`);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// body 추가
|
|
46
|
+
if (operation.requestBody?.typeName) {
|
|
47
|
+
propsFields.push(`body: ${operation.requestBody.typeName};`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const input =
|
|
51
|
+
propsFields.length > 0
|
|
52
|
+
? `props: {\n${propsFields.map((field) => ` ${field}`).join("\n")}\n}`
|
|
53
|
+
: `// No props parameter needed - function should have no parameters`;
|
|
54
|
+
|
|
19
55
|
if (state.analyze === null)
|
|
20
56
|
return [
|
|
21
57
|
{
|
|
@@ -91,25 +127,6 @@ export const transformRealizeCoderHistories = (
|
|
|
91
127
|
type: "systemMessage",
|
|
92
128
|
text: AutoBeSystemPromptConstant.REALIZE_CODER_TOTAL,
|
|
93
129
|
},
|
|
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: decorators/${props.decoratorEvent.provider.name}.ts`,
|
|
105
|
-
` - Contains JWT validation, role checking, and authorization logic`,
|
|
106
|
-
` - When importing from providers folder, use: '../decorators/${props.decoratorEvent.provider.name}'`,
|
|
107
|
-
`- Type definition: decorators/payload/${props.decoratorEvent.payload.name}.ts`,
|
|
108
|
-
` - TypeScript interface for authenticated user payload`,
|
|
109
|
-
` - When importing from providers folder, use: '../decorators/payload/${props.decoratorEvent.payload.name}'`,
|
|
110
|
-
].join("\n")
|
|
111
|
-
: "",
|
|
112
|
-
},
|
|
113
130
|
{
|
|
114
131
|
id: v4(),
|
|
115
132
|
created_at: new Date().toISOString(),
|
|
@@ -119,11 +136,44 @@ export const transformRealizeCoderHistories = (
|
|
|
119
136
|
JSON.stringify(state.prisma.schemas),
|
|
120
137
|
)
|
|
121
138
|
.replaceAll(`{artifacts_sdk}`, JSON.stringify(artifacts.sdk))
|
|
122
|
-
.replaceAll(`{artifacts_dto}`, JSON.stringify(artifacts.dto))
|
|
123
|
-
|
|
139
|
+
.replaceAll(`{artifacts_dto}`, JSON.stringify(artifacts.dto))
|
|
140
|
+
.replaceAll(`{input}`, input),
|
|
124
141
|
},
|
|
125
142
|
...(previous !== null
|
|
126
143
|
? [
|
|
144
|
+
{
|
|
145
|
+
id: v4(),
|
|
146
|
+
created_at: new Date().toISOString(),
|
|
147
|
+
type: "assistantMessage",
|
|
148
|
+
text: [
|
|
149
|
+
"These values contain previously generated code and thought flow.",
|
|
150
|
+
"All of these codes are failed compilation values.",
|
|
151
|
+
previousCodes.length >= 2
|
|
152
|
+
? "🚨 CRITICAL: You have already failed " +
|
|
153
|
+
previousCodes.length +
|
|
154
|
+
" times. The current approach is FUNDAMENTALLY WRONG!"
|
|
155
|
+
: "Please refer to the code for writing a new code.",
|
|
156
|
+
previousCodes.length >= 2
|
|
157
|
+
? [
|
|
158
|
+
"",
|
|
159
|
+
"After multiple failures, you MUST make AGGRESSIVE changes:",
|
|
160
|
+
"1. COMPLETELY REWRITE the problematic parts - don't just tweak",
|
|
161
|
+
"2. Try a DIFFERENT algorithm or approach entirely",
|
|
162
|
+
"3. Question ALL your assumptions about the requirements",
|
|
163
|
+
"4. Consider alternative Prisma patterns or query structures",
|
|
164
|
+
"5. The error might be in your fundamental understanding - rethink everything",
|
|
165
|
+
].join("\n")
|
|
166
|
+
: "",
|
|
167
|
+
"",
|
|
168
|
+
"```json",
|
|
169
|
+
JSON.stringify(
|
|
170
|
+
previousCodes.map((c) => c.result.implementationCode),
|
|
171
|
+
),
|
|
172
|
+
"```",
|
|
173
|
+
]
|
|
174
|
+
.filter(Boolean)
|
|
175
|
+
.join("\n"),
|
|
176
|
+
} as const,
|
|
127
177
|
{
|
|
128
178
|
id: v4(),
|
|
129
179
|
created_at: new Date().toISOString(),
|
|
@@ -131,9 +181,7 @@ export const transformRealizeCoderHistories = (
|
|
|
131
181
|
text: AutoBeSystemPromptConstant.REALIZE_CODER_DIAGNOSTICS.replaceAll(
|
|
132
182
|
`{code}`,
|
|
133
183
|
previous,
|
|
134
|
-
)
|
|
135
|
-
// .replaceAll("{total_diagnostics}", JSON.stringify(total))
|
|
136
|
-
.replaceAll("{current_diagnostics}", JSON.stringify(diagnostics)),
|
|
184
|
+
).replaceAll("{current_diagnostics}", JSON.stringify(diagnostics)),
|
|
137
185
|
} as const,
|
|
138
186
|
{
|
|
139
187
|
id: v4(),
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export namespace AutoBeRealizeAuthorizationFileSystem {
|
|
2
|
+
export const getDecoratorPath = (name: string) => `src/decorators/${name}.ts`;
|
|
3
|
+
|
|
4
|
+
export const getPayloadPath = (name: string) =>
|
|
5
|
+
`src/decorators/payload/${name}.ts`;
|
|
6
|
+
|
|
7
|
+
export const getProviderPath = (name: string) =>
|
|
8
|
+
`src/providers/authorize/${name}.ts`;
|
|
9
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export namespace AutoBeRealizeAuthorizationReplaceImport {
|
|
2
|
+
export function replaceProviderImport(role: string, content: string): string {
|
|
3
|
+
let updatedContent = content;
|
|
4
|
+
|
|
5
|
+
const roleCapitalized =
|
|
6
|
+
role.charAt(0).toUpperCase() + role.slice(1).toLowerCase();
|
|
7
|
+
|
|
8
|
+
const nestjsCommonPattern =
|
|
9
|
+
/import\s+{\s*[^}]*\s*}\s+from\s+"@nestjs\/common";/g;
|
|
10
|
+
const nestjsCommonReplacement =
|
|
11
|
+
'import { ForbiddenException, UnauthorizedException } from "@nestjs/common";';
|
|
12
|
+
|
|
13
|
+
const myGlobalPattern = /import\s+{\s*MyGlobal\s*}\s+from\s+[^;]+;/g;
|
|
14
|
+
const myGlobalReplacement = 'import { MyGlobal } from "../../MyGlobal";';
|
|
15
|
+
|
|
16
|
+
const jwtAuthorizePattern =
|
|
17
|
+
/import\s+{\s*jwtAuthorize\s*}\s+from\s+[^;]+;/g;
|
|
18
|
+
const jwtAuthorizeReplacement =
|
|
19
|
+
'import { jwtAuthorize } from "./jwtAuthorize";';
|
|
20
|
+
|
|
21
|
+
const payloadPattern = /import\s+{\s*\w*Payload\s*}\s+from\s+[^;]+;/g;
|
|
22
|
+
const payloadReplacement = `import { ${roleCapitalized}Payload } from "../../decorators/payload/${roleCapitalized}Payload";`;
|
|
23
|
+
|
|
24
|
+
// 각 패턴을 순차적으로 적용
|
|
25
|
+
updatedContent = updatedContent.replace(
|
|
26
|
+
nestjsCommonPattern,
|
|
27
|
+
nestjsCommonReplacement,
|
|
28
|
+
);
|
|
29
|
+
updatedContent = updatedContent.replace(
|
|
30
|
+
myGlobalPattern,
|
|
31
|
+
myGlobalReplacement,
|
|
32
|
+
);
|
|
33
|
+
updatedContent = updatedContent.replace(
|
|
34
|
+
jwtAuthorizePattern,
|
|
35
|
+
jwtAuthorizeReplacement,
|
|
36
|
+
);
|
|
37
|
+
updatedContent = updatedContent.replace(payloadPattern, payloadReplacement);
|
|
38
|
+
|
|
39
|
+
return updatedContent;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function replaceDecoratorImport(
|
|
43
|
+
role: string,
|
|
44
|
+
content: string,
|
|
45
|
+
): string {
|
|
46
|
+
let updatedContent = content;
|
|
47
|
+
|
|
48
|
+
const roleLowercase = role.toLowerCase();
|
|
49
|
+
|
|
50
|
+
// ~Authorize로 끝나는 import 구문을 특정 경로로 변경하는 정규표현식
|
|
51
|
+
const authorizePattern = /import\s+{\s*\w*Authorize\s*}\s+from\s+[^;]+;/g;
|
|
52
|
+
|
|
53
|
+
// role을 기반으로 동적으로 replacement 생성
|
|
54
|
+
const authorizeReplacement = `import { ${roleLowercase}Authorize } from "../providers/authorize/${roleLowercase}Authorize";`;
|
|
55
|
+
|
|
56
|
+
// 패턴 적용
|
|
57
|
+
updatedContent = updatedContent.replace(
|
|
58
|
+
authorizePattern,
|
|
59
|
+
authorizeReplacement,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return updatedContent;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -2,11 +2,24 @@ import { IAutoBeCompiler } from "@autobe/interface";
|
|
|
2
2
|
import { ILlmSchema } from "@samchon/openapi";
|
|
3
3
|
|
|
4
4
|
import { AutoBeContext } from "../../../context/AutoBeContext";
|
|
5
|
+
import { IAutoBeTestScenarioArtifacts } from "../../test/structures/IAutoBeTestScenarioArtifacts";
|
|
5
6
|
|
|
6
7
|
export function replaceImportStatements<Model extends ILlmSchema.Model>(
|
|
7
8
|
ctx: AutoBeContext<Model>,
|
|
8
9
|
) {
|
|
9
|
-
return async function (
|
|
10
|
+
return async function (
|
|
11
|
+
artifacts: IAutoBeTestScenarioArtifacts,
|
|
12
|
+
code: string,
|
|
13
|
+
decoratorType?: string,
|
|
14
|
+
) {
|
|
15
|
+
const typeReferences: string[] = Array.from(
|
|
16
|
+
new Set(
|
|
17
|
+
Object.keys(artifacts.document.components.schemas).map(
|
|
18
|
+
(key) => key.split(".")[0]!,
|
|
19
|
+
),
|
|
20
|
+
),
|
|
21
|
+
);
|
|
22
|
+
|
|
10
23
|
const compiler: IAutoBeCompiler = await ctx.compiler();
|
|
11
24
|
code = await compiler.typescript.beautify(code);
|
|
12
25
|
// Remove existing import statements using flexible regex patterns
|
|
@@ -35,10 +48,32 @@ export function replaceImportStatements<Model extends ILlmSchema.Model>(
|
|
|
35
48
|
"",
|
|
36
49
|
);
|
|
37
50
|
|
|
51
|
+
// Remove any existing API structure imports
|
|
52
|
+
// Pattern 1: ../api/structures path
|
|
53
|
+
code = code.replace(
|
|
54
|
+
/import\s*(?:type\s*)?{\s*[^}]+\s*}\s*from\s*["']\.\.\/api\/structures\/[^"']+["']\s*;?\s*/gm,
|
|
55
|
+
"",
|
|
56
|
+
);
|
|
57
|
+
// Pattern 2: @ORGANIZATION/PROJECT-api/lib/structures path
|
|
58
|
+
code = code.replace(
|
|
59
|
+
/import\s*(?:type\s*)?{\s*[^}]+\s*}\s*from\s*["']@ORGANIZATION\/PROJECT-api\/lib\/structures\/[^"']+["']\s*;?\s*/gm,
|
|
60
|
+
"",
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// Remove specific type imports that match our typeReferences
|
|
64
|
+
for (const ref of typeReferences) {
|
|
65
|
+
// Remove any import of this specific type from any path
|
|
66
|
+
const typeImportRegex = new RegExp(
|
|
67
|
+
`import\\s*(?:type\\s*)?{\\s*${ref}\\s*}\\s*from\\s*["'][^"']+["']\\s*;?\\s*`,
|
|
68
|
+
"gm",
|
|
69
|
+
);
|
|
70
|
+
code = code.replace(typeImportRegex, "");
|
|
71
|
+
}
|
|
72
|
+
|
|
38
73
|
// Remove any existing decoratorType imports if LLM mistakenly added them
|
|
39
74
|
if (decoratorType) {
|
|
40
75
|
const decoratorTypeRegex = new RegExp(
|
|
41
|
-
`import\\s*{\\s*${decoratorType}\\s*}\\s*from\\s*["']\\.\\.\/decorators\/payload\/${decoratorType}["']\\s*;?\\s*`,
|
|
76
|
+
`import\\s*(?:type\\s*)?{\\s*${decoratorType}\\s*}\\s*from\\s*["']\\.\\.\/decorators\/payload\/${decoratorType}["']\\s*;?\\s*`,
|
|
42
77
|
"gm",
|
|
43
78
|
);
|
|
44
79
|
code = code.replace(decoratorTypeRegex, "");
|
|
@@ -51,6 +86,10 @@ export function replaceImportStatements<Model extends ILlmSchema.Model>(
|
|
|
51
86
|
'import { Prisma } from "@prisma/client";',
|
|
52
87
|
'import { v4 } from "uuid";',
|
|
53
88
|
'import { toISOStringSafe } from "../util/toISOStringSafe"',
|
|
89
|
+
...typeReferences.map(
|
|
90
|
+
(ref) =>
|
|
91
|
+
`import { ${ref} } from "@ORGANIZATION/PROJECT-api/lib/structures/${ref}";`,
|
|
92
|
+
),
|
|
54
93
|
];
|
|
55
94
|
|
|
56
95
|
// Only add decoratorType import if it exists
|