@autobe/agent 0.25.0 → 0.25.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.
- package/lib/AutoBeAgent.js +11 -1
- package/lib/AutoBeAgent.js.map +1 -1
- package/lib/AutoBeMockAgent.js +1 -0
- package/lib/AutoBeMockAgent.js.map +1 -1
- package/lib/constants/AutoBeSystemPromptConstant.d.ts +13 -13
- package/lib/factory/createAutoBeContext.js +1 -0
- package/lib/factory/createAutoBeContext.js.map +1 -1
- package/lib/index.mjs +2250 -806
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/common/histories/transformCommonCorrectCastingHistories.js +1 -1
- package/lib/orchestrate/common/histories/transformCommonCorrectCastingHistories.js.map +1 -1
- package/lib/orchestrate/common/orchestrateCommonCorrectCasting.js +36 -23
- package/lib/orchestrate/common/orchestrateCommonCorrectCasting.js.map +1 -1
- package/lib/orchestrate/common/structures/IAutoBeCommonCorrectCastingApplication.d.ts +22 -42
- package/lib/orchestrate/interface/histories/transformInterfaceCommonPrerequisiteHistories.d.ts +3 -0
- package/lib/orchestrate/interface/histories/{transformInterfacePrerequisiteHistories.js → transformInterfaceCommonPrerequisiteHistories.js} +4 -4
- package/lib/orchestrate/interface/histories/transformInterfaceCommonPrerequisiteHistories.js.map +1 -0
- package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js +2 -2
- package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js +3 -3
- package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfacePrerequisitesHistories.d.ts +3 -0
- package/lib/orchestrate/interface/histories/transformInterfacePrerequisitesHistories.js +102 -0
- package/lib/orchestrate/interface/histories/transformInterfacePrerequisitesHistories.js.map +1 -0
- package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceSchemasReviewHistories.js +2 -2
- package/lib/orchestrate/interface/histories/transformInterfaceSchemasReviewHistories.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterface.js +25 -9
- package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceAuthorizations.js +260 -29
- package/lib/orchestrate/interface/orchestrateInterfaceAuthorizations.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +56 -64
- package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +3 -3
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceGroups.js +2 -2
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +4 -5
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceOperationsReview.js +260 -29
- package/lib/orchestrate/interface/orchestrateInterfaceOperationsReview.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfacePrerequisites.d.ts +5 -0
- package/lib/orchestrate/interface/orchestrateInterfacePrerequisites.js +713 -0
- package/lib/orchestrate/interface/orchestrateInterfacePrerequisites.js.map +1 -0
- package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js +47 -35
- package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceSchemasReview.js +41 -7
- package/lib/orchestrate/interface/orchestrateInterfaceSchemasReview.js.map +1 -1
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.d.ts +0 -38
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.d.ts +6 -10
- package/lib/orchestrate/interface/structures/IAutoBeInterfacePrerequisitesApplication.d.ts +52 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfacePrerequisitesApplication.js +3 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfacePrerequisitesApplication.js.map +1 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.d.ts +0 -33
- package/lib/orchestrate/interface/utils/JsonSchemaFactory.d.ts +6 -2
- package/lib/orchestrate/interface/utils/JsonSchemaFactory.js +105 -5
- package/lib/orchestrate/interface/utils/JsonSchemaFactory.js.map +1 -1
- package/lib/orchestrate/interface/utils/JsonSchemaValidator.js +20 -1
- package/lib/orchestrate/interface/utils/JsonSchemaValidator.js.map +1 -1
- package/lib/orchestrate/interface/utils/OperationValidator.d.ts +3 -4
- package/lib/orchestrate/interface/utils/OperationValidator.js +1 -1
- package/lib/orchestrate/interface/utils/OperationValidator.js.map +1 -1
- package/lib/orchestrate/realize/histories/transformRealizeCorrectCastingHistories.js +9 -10
- package/lib/orchestrate/realize/histories/transformRealizeCorrectCastingHistories.js.map +1 -1
- package/lib/orchestrate/realize/histories/transformRealizeCorrectHistories.js +14 -22
- package/lib/orchestrate/realize/histories/transformRealizeCorrectHistories.js.map +1 -1
- package/lib/orchestrate/realize/histories/transformRealizeWriteAuthorizationsHistories.js +6 -6
- package/lib/orchestrate/realize/histories/transformRealizeWriteHistories.js +8 -2
- package/lib/orchestrate/realize/histories/transformRealizeWriteHistories.js.map +1 -1
- package/lib/orchestrate/realize/internal/compileRealizeFiles.js +1 -2
- package/lib/orchestrate/realize/internal/compileRealizeFiles.js.map +1 -1
- package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.d.ts +2 -1
- package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.js +103 -40
- package/lib/orchestrate/realize/orchestRateRealizeCorrectCasting.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealize.js +81 -45
- package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeCorrect.js +117 -87
- package/lib/orchestrate/realize/orchestrateRealizeCorrect.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeWrite.d.ts +2 -1
- package/lib/orchestrate/realize/orchestrateRealizeWrite.js +117 -54
- package/lib/orchestrate/realize/orchestrateRealizeWrite.js.map +1 -1
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCorrectApplication.d.ts +52 -26
- package/lib/orchestrate/realize/structures/IAutoBeRealizeWriteApplication.d.ts +44 -34
- package/lib/orchestrate/realize/utils/InternalFileSystem.js +1 -1
- package/lib/orchestrate/realize/utils/InternalFileSystem.js.map +1 -1
- package/lib/orchestrate/realize/utils/getRealizeWriteCodeTemplate.d.ts +8 -3
- package/lib/orchestrate/realize/utils/getRealizeWriteCodeTemplate.js +44 -17
- package/lib/orchestrate/realize/utils/getRealizeWriteCodeTemplate.js.map +1 -1
- package/lib/orchestrate/realize/utils/getRealizeWriteImportStatements.d.ts +4 -1
- package/lib/orchestrate/realize/utils/getRealizeWriteImportStatements.js +24 -9
- package/lib/orchestrate/realize/utils/getRealizeWriteImportStatements.js.map +1 -1
- package/lib/orchestrate/realize/utils/printErrorHints.d.ts +8 -0
- package/lib/orchestrate/realize/utils/printErrorHints.js +48 -0
- package/lib/orchestrate/realize/utils/printErrorHints.js.map +1 -0
- package/lib/orchestrate/realize/utils/replaceImportStatements.d.ts +1 -0
- package/lib/orchestrate/realize/utils/replaceImportStatements.js +93 -55
- package/lib/orchestrate/realize/utils/replaceImportStatements.js.map +1 -1
- package/lib/orchestrate/test/histories/transformTestCorrectHistories.js +1 -1
- package/lib/orchestrate/test/histories/transformTestCorrectHistories.js.map +1 -1
- package/lib/orchestrate/test/histories/transformTestCorrectInvalidRequestHistories.js +1 -1
- package/lib/orchestrate/test/histories/transformTestCorrectInvalidRequestHistories.js.map +1 -1
- package/lib/orchestrate/test/histories/transformTestScenarioHistories.js +10 -79
- package/lib/orchestrate/test/histories/transformTestScenarioHistories.js.map +1 -1
- package/lib/orchestrate/test/histories/transformTestScenarioReviewHistories.js +15 -65
- package/lib/orchestrate/test/histories/transformTestScenarioReviewHistories.js.map +1 -1
- package/lib/orchestrate/test/histories/transformTestWriteHistories.js +1 -1
- package/lib/orchestrate/test/histories/transformTestWriteHistories.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestCorrect.js +32 -17
- package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestCorrectInvalidRequest.js +31 -13
- package/lib/orchestrate/test/orchestrateTestCorrectInvalidRequest.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestScenario.d.ts +1 -1
- package/lib/orchestrate/test/orchestrateTestScenario.js +5 -5
- package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestScenarioReview.js +1 -1
- package/lib/orchestrate/test/orchestrateTestScenarioReview.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestWrite.js +37 -21
- package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -1
- package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.d.ts +9 -5
- package/lib/orchestrate/test/structures/IAutoBeTestCorrectInvalidRequestApplication.d.ts +8 -2
- package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.d.ts +11 -7
- package/lib/orchestrate/test/utils/getPrerequisites.d.ts +5 -0
- package/lib/orchestrate/test/utils/getPrerequisites.js +36 -0
- package/lib/orchestrate/test/utils/getPrerequisites.js.map +1 -0
- package/lib/orchestrate/test/utils/getReferenceIds.js +1 -1
- package/lib/orchestrate/test/utils/getReferenceIds.js.map +1 -1
- package/package.json +5 -5
- package/src/AutoBeAgent.ts +17 -1
- package/src/AutoBeMockAgent.ts +1 -0
- package/src/constants/AutoBeSystemPromptConstant.ts +13 -13
- package/src/factory/createAutoBeContext.ts +1 -0
- package/src/orchestrate/common/orchestrateCommonCorrectCasting.ts +2 -2
- package/src/orchestrate/common/structures/IAutoBeCommonCorrectCastingApplication.ts +25 -45
- package/src/orchestrate/interface/histories/{transformInterfacePrerequisiteHistories.ts → transformInterfaceCommonPrerequisiteHistories.ts} +1 -1
- package/src/orchestrate/interface/histories/transformInterfaceGroupHistories.ts +4 -2
- package/src/orchestrate/interface/histories/transformInterfacePrerequisitesHistories.ts +118 -0
- package/src/orchestrate/interface/orchestrateInterface.ts +43 -17
- package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +12 -33
- package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +5 -5
- package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +7 -6
- package/src/orchestrate/interface/orchestrateInterfacePrerequisites.ts +274 -0
- package/src/orchestrate/interface/orchestrateInterfaceSchemas.ts +1 -1
- package/src/orchestrate/interface/orchestrateInterfaceSchemasReview.ts +1 -1
- package/src/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.ts +0 -39
- package/src/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.ts +6 -10
- package/src/orchestrate/interface/structures/IAutoBeInterfacePrerequisitesApplication.ts +58 -0
- package/src/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.ts +0 -34
- package/src/orchestrate/interface/utils/JsonSchemaFactory.ts +92 -4
- package/src/orchestrate/interface/utils/JsonSchemaValidator.ts +19 -1
- package/src/orchestrate/interface/utils/OperationValidator.ts +9 -7
- package/src/orchestrate/realize/histories/transformRealizeCorrectCastingHistories.ts +9 -10
- package/src/orchestrate/realize/histories/transformRealizeCorrectHistories.ts +13 -24
- package/src/orchestrate/realize/histories/transformRealizeWriteAuthorizationsHistories.ts +6 -6
- package/src/orchestrate/realize/histories/transformRealizeWriteHistories.ts +6 -4
- package/src/orchestrate/realize/internal/compileRealizeFiles.ts +1 -5
- package/src/orchestrate/realize/orchestRateRealizeCorrectCasting.ts +84 -17
- package/src/orchestrate/realize/orchestrateRealize.ts +125 -74
- package/src/orchestrate/realize/orchestrateRealizeCorrect.ts +33 -6
- package/src/orchestrate/realize/orchestrateRealizeWrite.ts +14 -4
- package/src/orchestrate/realize/structures/IAutoBeRealizeCorrectApplication.ts +54 -29
- package/src/orchestrate/realize/structures/IAutoBeRealizeWriteApplication.ts +46 -35
- package/src/orchestrate/realize/utils/InternalFileSystem.ts +1 -1
- package/src/orchestrate/realize/utils/getRealizeWriteCodeTemplate.ts +54 -22
- package/src/orchestrate/realize/utils/getRealizeWriteImportStatements.ts +28 -16
- package/src/orchestrate/realize/utils/printErrorHints.ts +55 -0
- package/src/orchestrate/realize/utils/replaceImportStatements.ts +99 -102
- package/src/orchestrate/test/histories/transformTestScenarioHistories.ts +18 -91
- package/src/orchestrate/test/histories/transformTestScenarioReviewHistories.ts +17 -90
- package/src/orchestrate/test/orchestrateTestCorrect.ts +7 -6
- package/src/orchestrate/test/orchestrateTestCorrectInvalidRequest.ts +13 -1
- package/src/orchestrate/test/orchestrateTestScenario.ts +12 -6
- package/src/orchestrate/test/orchestrateTestScenarioReview.ts +3 -3
- package/src/orchestrate/test/orchestrateTestWrite.ts +7 -6
- package/src/orchestrate/test/structures/IAutoBeTestCorrectApplication.ts +9 -228
- package/src/orchestrate/test/structures/IAutoBeTestCorrectInvalidRequestApplication.ts +8 -2
- package/src/orchestrate/test/structures/IAutoBeTestWriteApplication.ts +11 -78
- package/src/orchestrate/test/utils/getPrerequisites.ts +51 -0
- package/src/orchestrate/test/utils/getReferenceIds.ts +2 -1
- package/lib/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.d.ts +0 -3
- package/lib/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.js.map +0 -1
- package/lib/orchestrate/interface/utils/OpenApiEndpointComparator.d.ts +0 -6
- package/lib/orchestrate/interface/utils/OpenApiEndpointComparator.js +0 -22
- package/lib/orchestrate/interface/utils/OpenApiEndpointComparator.js.map +0 -1
- package/src/orchestrate/interface/utils/OpenApiEndpointComparator.ts +0 -23
|
@@ -19,6 +19,7 @@ import { IAutoBeRealizeCorrectApplication } from "./structures/IAutoBeRealizeCor
|
|
|
19
19
|
import { IAutoBeRealizeFunctionFailure } from "./structures/IAutoBeRealizeFunctionFailure";
|
|
20
20
|
import { IAutoBeRealizeScenarioResult } from "./structures/IAutoBeRealizeScenarioResult";
|
|
21
21
|
import { filterDiagnostics } from "./utils/filterDiagnostics";
|
|
22
|
+
import { getRealizeWriteCodeTemplate } from "./utils/getRealizeWriteCodeTemplate";
|
|
22
23
|
import { getRealizeWriteDto } from "./utils/getRealizeWriteDto";
|
|
23
24
|
import { replaceImportStatements } from "./utils/replaceImportStatements";
|
|
24
25
|
|
|
@@ -42,7 +43,9 @@ export async function orchestrateRealizeCorrect<Model extends ILlmSchema.Model>(
|
|
|
42
43
|
const diagnostics = event.result.diagnostics;
|
|
43
44
|
|
|
44
45
|
if (
|
|
45
|
-
event.result.diagnostics.every(
|
|
46
|
+
event.result.diagnostics.every(
|
|
47
|
+
(d) => !d.file?.startsWith("src/providers"),
|
|
48
|
+
) === true
|
|
46
49
|
) {
|
|
47
50
|
// No diagnostics related to provider functions, stop correcting
|
|
48
51
|
return functions;
|
|
@@ -99,7 +102,6 @@ export async function orchestrateRealizeCorrect<Model extends ILlmSchema.Model>(
|
|
|
99
102
|
),
|
|
100
103
|
progress,
|
|
101
104
|
);
|
|
102
|
-
|
|
103
105
|
return orchestrateRealizeCorrect(
|
|
104
106
|
ctx,
|
|
105
107
|
scenarios,
|
|
@@ -211,6 +213,23 @@ async function step<Model extends ILlmSchema.Model>(
|
|
|
211
213
|
enforceFunctionCall: true,
|
|
212
214
|
message: StringUtil.trim`
|
|
213
215
|
Correct the TypeScript code implementation.
|
|
216
|
+
|
|
217
|
+
The instruction to write at first was as follows, and the code you received is the code you wrote according to this instruction.
|
|
218
|
+
When modifying, modify the entire code, but not the import statement.
|
|
219
|
+
|
|
220
|
+
Below is template code you wrote:
|
|
221
|
+
|
|
222
|
+
${getRealizeWriteCodeTemplate({
|
|
223
|
+
scenario: props.scenario,
|
|
224
|
+
schemas: ctx.state().interface!.document.components.schemas,
|
|
225
|
+
operation: props.scenario.operation,
|
|
226
|
+
authorization: props.authorization ?? null,
|
|
227
|
+
})}
|
|
228
|
+
|
|
229
|
+
Current code is as follows:
|
|
230
|
+
\`\`\`typescript
|
|
231
|
+
${props.function.content}
|
|
232
|
+
\`\`\`
|
|
214
233
|
`,
|
|
215
234
|
});
|
|
216
235
|
|
|
@@ -218,17 +237,25 @@ async function step<Model extends ILlmSchema.Model>(
|
|
|
218
237
|
return null;
|
|
219
238
|
}
|
|
220
239
|
|
|
221
|
-
pointer.value.
|
|
240
|
+
pointer.value.draft = await replaceImportStatements(ctx, {
|
|
222
241
|
operation: props.scenario.operation,
|
|
223
|
-
|
|
242
|
+
schemas: ctx.state().interface!.document.components.schemas,
|
|
243
|
+
code: pointer.value.draft,
|
|
224
244
|
decoratorType: props.authorization?.payload.name,
|
|
225
245
|
});
|
|
246
|
+
if (pointer.value.revise.final)
|
|
247
|
+
pointer.value.revise.final = await replaceImportStatements(ctx, {
|
|
248
|
+
operation: props.scenario.operation,
|
|
249
|
+
schemas: ctx.state().interface!.document.components.schemas,
|
|
250
|
+
code: pointer.value.revise.final,
|
|
251
|
+
decoratorType: props.authorization?.payload.name,
|
|
252
|
+
});
|
|
226
253
|
|
|
227
254
|
const event: AutoBeRealizeCorrectEvent = {
|
|
228
255
|
type: "realizeCorrect",
|
|
229
256
|
id: v7(),
|
|
230
257
|
location: props.scenario.location,
|
|
231
|
-
content: pointer.value.revise.final,
|
|
258
|
+
content: pointer.value.revise.final ?? pointer.value.draft,
|
|
232
259
|
tokenUsage,
|
|
233
260
|
completed: ++props.progress.completed,
|
|
234
261
|
total: props.progress.total,
|
|
@@ -253,7 +280,7 @@ function createController<Model extends ILlmSchema.Model>(props: {
|
|
|
253
280
|
name: "Write code",
|
|
254
281
|
application,
|
|
255
282
|
execute: {
|
|
256
|
-
|
|
283
|
+
correct: (next) => {
|
|
257
284
|
props.build(next);
|
|
258
285
|
},
|
|
259
286
|
} satisfies IAutoBeRealizeCorrectApplication,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AutoBeOpenApi,
|
|
2
3
|
AutoBeProgressEventBase,
|
|
3
4
|
AutoBeRealizeAuthorization,
|
|
4
5
|
AutoBeRealizeWriteEvent,
|
|
@@ -20,6 +21,7 @@ import { replaceImportStatements } from "./utils/replaceImportStatements";
|
|
|
20
21
|
export async function orchestrateRealizeWrite<Model extends ILlmSchema.Model>(
|
|
21
22
|
ctx: AutoBeContext<Model>,
|
|
22
23
|
props: {
|
|
24
|
+
document: AutoBeOpenApi.IDocument;
|
|
23
25
|
totalAuthorizations: AutoBeRealizeAuthorization[];
|
|
24
26
|
authorization: AutoBeRealizeAuthorization | null;
|
|
25
27
|
scenario: IAutoBeRealizeScenarioResult;
|
|
@@ -69,17 +71,25 @@ export async function orchestrateRealizeWrite<Model extends ILlmSchema.Model>(
|
|
|
69
71
|
});
|
|
70
72
|
if (pointer.value === null) throw new Error("Failed to write code.");
|
|
71
73
|
|
|
72
|
-
pointer.value.
|
|
74
|
+
pointer.value.draft = await replaceImportStatements(ctx, {
|
|
73
75
|
operation: props.scenario.operation,
|
|
74
|
-
|
|
76
|
+
schemas: props.document.components.schemas,
|
|
77
|
+
code: pointer.value.draft,
|
|
75
78
|
decoratorType: props.authorization?.payload.name,
|
|
76
79
|
});
|
|
80
|
+
if (pointer.value.revise.final)
|
|
81
|
+
pointer.value.revise.final = await replaceImportStatements(ctx, {
|
|
82
|
+
operation: props.scenario.operation,
|
|
83
|
+
schemas: props.document.components.schemas,
|
|
84
|
+
code: pointer.value.revise.final,
|
|
85
|
+
decoratorType: props.authorization?.payload.name,
|
|
86
|
+
});
|
|
77
87
|
|
|
78
88
|
const event: AutoBeRealizeWriteEvent = {
|
|
79
89
|
type: "realizeWrite",
|
|
80
90
|
id: v7(),
|
|
81
91
|
location: props.scenario.location,
|
|
82
|
-
content: pointer.value.final,
|
|
92
|
+
content: pointer.value.revise.final ?? pointer.value.draft,
|
|
83
93
|
tokenUsage,
|
|
84
94
|
completed: ++props.progress.completed,
|
|
85
95
|
total: props.progress.total,
|
|
@@ -105,7 +115,7 @@ function createController<Model extends ILlmSchema.Model>(props: {
|
|
|
105
115
|
name: "Write code",
|
|
106
116
|
application,
|
|
107
117
|
execute: {
|
|
108
|
-
|
|
118
|
+
write: (next) => {
|
|
109
119
|
props.build(next);
|
|
110
120
|
},
|
|
111
121
|
} satisfies IAutoBeRealizeWriteApplication,
|
|
@@ -1,45 +1,70 @@
|
|
|
1
1
|
export interface IAutoBeRealizeCorrectApplication {
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Systematically analyze and correct TypeScript compilation errors.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Implements a three-phase workflow (think → draft → revise) that balances
|
|
6
|
+
* efficiency for simple errors with thoroughness for complex problems.
|
|
7
7
|
*
|
|
8
|
-
* @param props
|
|
8
|
+
* @param props Three-phase correction properties
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
correct(props: IAutoBeRealizeCorrectApplication.IProps): void;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export namespace IAutoBeRealizeCorrectApplication {
|
|
14
|
-
/**
|
|
15
|
-
* Properties for error correction following Chain of Thinking (CoT).
|
|
16
|
-
*
|
|
17
|
-
* All phases are wrapped in a `revise` object for systematic error
|
|
18
|
-
* resolution.
|
|
19
|
-
*/
|
|
20
14
|
export interface IProps {
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
15
|
+
/**
|
|
16
|
+
* Initial error analysis and correction strategy.
|
|
17
|
+
*
|
|
18
|
+
* Analyzes TypeScript compilation errors to understand:
|
|
19
|
+
*
|
|
20
|
+
* - Error patterns and root causes
|
|
21
|
+
* - Required fixes and their impact
|
|
22
|
+
* - Whether quick fixes or deep refactoring is needed
|
|
23
|
+
* - Prisma schema and API contract constraints
|
|
30
24
|
*/
|
|
31
|
-
|
|
25
|
+
think: string;
|
|
32
26
|
|
|
33
|
-
/**
|
|
34
|
-
|
|
27
|
+
/**
|
|
28
|
+
* First correction attempt.
|
|
29
|
+
*
|
|
30
|
+
* Implements the initial fixes identified in the think phase. For simple
|
|
31
|
+
* errors (typos, missing imports), this may be the final solution. Complex
|
|
32
|
+
* errors may require further refinement.
|
|
33
|
+
*/
|
|
34
|
+
draft: string;
|
|
35
35
|
|
|
36
|
-
/**
|
|
37
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Revision and finalization phase.
|
|
38
|
+
*
|
|
39
|
+
* Reviews the draft corrections and produces the final, error-free code
|
|
40
|
+
* that maintains all business requirements.
|
|
41
|
+
*/
|
|
42
|
+
revise: IReviseProps;
|
|
43
|
+
}
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
export interface IReviseProps {
|
|
46
|
+
/**
|
|
47
|
+
* Correction review and validation.
|
|
48
|
+
*
|
|
49
|
+
* Analyzes the draft corrections to ensure:
|
|
50
|
+
*
|
|
51
|
+
* - All TypeScript errors are resolved
|
|
52
|
+
* - Business logic remains intact
|
|
53
|
+
* - AutoBE coding standards are maintained
|
|
54
|
+
* - No new errors are introduced
|
|
55
|
+
* - Performance and security are preserved
|
|
56
|
+
*/
|
|
57
|
+
review: string;
|
|
41
58
|
|
|
42
|
-
/**
|
|
43
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Final error-free implementation.
|
|
61
|
+
*
|
|
62
|
+
* The complete, corrected code that passes all TypeScript compilation
|
|
63
|
+
* checks.
|
|
64
|
+
*
|
|
65
|
+
* Returns `null` if the draft corrections are sufficient and need no
|
|
66
|
+
* further changes.
|
|
67
|
+
*/
|
|
68
|
+
final: string | null;
|
|
44
69
|
}
|
|
45
70
|
}
|
|
@@ -1,55 +1,66 @@
|
|
|
1
1
|
export interface IAutoBeRealizeWriteApplication {
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Generate complete provider function implementation using Chain of Thinking.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* functions that handle business logic for API operations. It follows a
|
|
7
|
-
* schema-first approach with multiple refinement phases to ensure type-safe,
|
|
8
|
-
* error-free code generation.
|
|
5
|
+
* Follows a 3-phase process: plan → draft → revise.
|
|
9
6
|
*
|
|
10
|
-
*
|
|
7
|
+
* Ensures type safety, proper Prisma usage, and API contract compliance.
|
|
11
8
|
*
|
|
12
|
-
*
|
|
13
|
-
* 2. Schema definition for relevant models
|
|
14
|
-
* 3. Review and refinement for completeness
|
|
15
|
-
* 4. Final implementation with all validations and type safety
|
|
16
|
-
*
|
|
17
|
-
* @param next Properties containing the multi-phase implementation plan and
|
|
18
|
-
* code
|
|
9
|
+
* @param props Chain of Thinking properties for implementation
|
|
19
10
|
*/
|
|
20
|
-
|
|
11
|
+
write(props: IAutoBeRealizeWriteApplication.IProps): void;
|
|
21
12
|
}
|
|
22
13
|
|
|
23
14
|
export namespace IAutoBeRealizeWriteApplication {
|
|
24
|
-
/**
|
|
25
|
-
* Properties for the Realize Write Application following Chain of Thinking
|
|
26
|
-
* (CoT).
|
|
27
|
-
*
|
|
28
|
-
* Each field represents a distinct phase in the implementation process.
|
|
29
|
-
* Detailed guidelines are in REALIZE_WRITE.md.
|
|
30
|
-
*/
|
|
31
15
|
export interface IProps {
|
|
32
16
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* Strategic plan following SCHEMA-FIRST APPROACH:
|
|
36
|
-
*
|
|
37
|
-
* 1. Verify Prisma schema fields (list existing and non-existing)
|
|
38
|
-
* 2. Plan field usage in operations
|
|
39
|
-
* 3. Plan type conversions and nullable handling
|
|
40
|
-
* 4. Define implementation approach with error handling
|
|
17
|
+
* Implementation plan and strategy.
|
|
41
18
|
*
|
|
42
|
-
*
|
|
19
|
+
* Analyzes the provider function requirements, identifies related Prisma
|
|
20
|
+
* schemas, and outlines the implementation approach. Includes schema
|
|
21
|
+
* validation and API contract verification.
|
|
43
22
|
*/
|
|
44
23
|
plan: string;
|
|
45
24
|
|
|
46
|
-
/**
|
|
47
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Initial implementation draft.
|
|
27
|
+
*
|
|
28
|
+
* The first complete implementation attempt based on the plan. May contain
|
|
29
|
+
* areas that need refinement in the review phase.
|
|
30
|
+
*/
|
|
31
|
+
draft: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Revision and finalization phase.
|
|
35
|
+
*
|
|
36
|
+
* Reviews the draft implementation and produces the final code with all
|
|
37
|
+
* improvements and corrections applied.
|
|
38
|
+
*/
|
|
39
|
+
revise: IReviseProps;
|
|
40
|
+
}
|
|
48
41
|
|
|
49
|
-
|
|
42
|
+
export interface IReviseProps {
|
|
43
|
+
/**
|
|
44
|
+
* Review and improvement suggestions.
|
|
45
|
+
*
|
|
46
|
+
* Identifies areas for improvement in the draft code, including:
|
|
47
|
+
*
|
|
48
|
+
* - Type safety enhancements
|
|
49
|
+
* - Prisma query optimizations
|
|
50
|
+
* - Null/undefined handling corrections
|
|
51
|
+
* - Authentication/authorization improvements
|
|
52
|
+
* - Error handling refinements
|
|
53
|
+
*/
|
|
50
54
|
review: string;
|
|
51
55
|
|
|
52
|
-
/**
|
|
53
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Final implementation code.
|
|
58
|
+
*
|
|
59
|
+
* The complete, production-ready implementation with all review suggestions
|
|
60
|
+
* applied.
|
|
61
|
+
*
|
|
62
|
+
* Returns `null` if the draft is already perfect and needs no changes.
|
|
63
|
+
*/
|
|
64
|
+
final: string | null;
|
|
54
65
|
}
|
|
55
66
|
}
|
|
@@ -20,9 +20,9 @@ import { getRealizeWriteImportStatements } from "./getRealizeWriteImportStatemen
|
|
|
20
20
|
* import { MyGlobal } from "../MyGlobal";
|
|
21
21
|
* // ... other imports
|
|
22
22
|
*
|
|
23
|
-
* async function post__users_create(
|
|
23
|
+
* async function post__users_create(props: {
|
|
24
24
|
* body: IUserCreateRequest
|
|
25
|
-
* ): Promise<IUserResponse> {
|
|
25
|
+
* }): Promise<IUserResponse> {
|
|
26
26
|
* ...
|
|
27
27
|
* }
|
|
28
28
|
* ```;
|
|
@@ -32,35 +32,31 @@ import { getRealizeWriteImportStatements } from "./getRealizeWriteImportStatemen
|
|
|
32
32
|
* @param authorization - Authorization context if endpoint is authenticated
|
|
33
33
|
* @returns Complete TypeScript code template as a formatted string
|
|
34
34
|
*/
|
|
35
|
-
export function getRealizeWriteCodeTemplate(
|
|
36
|
-
scenario: IAutoBeRealizeScenarioResult
|
|
37
|
-
operation: AutoBeOpenApi.IOperation
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
export function getRealizeWriteCodeTemplate(props: {
|
|
36
|
+
scenario: IAutoBeRealizeScenarioResult;
|
|
37
|
+
operation: AutoBeOpenApi.IOperation;
|
|
38
|
+
schemas: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>;
|
|
39
|
+
authorization: AutoBeRealizeAuthorization | null;
|
|
40
|
+
}): string {
|
|
40
41
|
// Collect all function parameters in order
|
|
41
42
|
const functionParameters: string[] = [];
|
|
42
43
|
|
|
43
44
|
// Add authentication parameter if needed (e.g., user: IUser, admin: IAdmin)
|
|
44
|
-
if (authorization && authorization.role.name) {
|
|
45
|
+
if (props.authorization && props.authorization.role.name) {
|
|
45
46
|
// Debug: Log the values to check what's being used
|
|
46
|
-
const authParameter = `${authorization.role.name}: ${authorization.payload.name}`;
|
|
47
|
+
const authParameter = `${props.authorization.role.name}: ${props.authorization.payload.name}`;
|
|
47
48
|
functionParameters.push(authParameter);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
// Add path parameters (e.g., id, postId, etc.)
|
|
51
|
-
const pathParameters = operation.parameters.map((param) => {
|
|
52
|
-
|
|
53
|
-
const paramFormat =
|
|
54
|
-
"format" in param.schema
|
|
55
|
-
? ` & tags.Format<'${param.schema.format}'>`
|
|
56
|
-
: "";
|
|
57
|
-
return `${param.name}: ${paramType}${paramFormat}`;
|
|
52
|
+
const pathParameters = props.operation.parameters.map((param) => {
|
|
53
|
+
return `${param.name}: ${writeParameterType(param.schema)}`;
|
|
58
54
|
});
|
|
59
55
|
functionParameters.push(...pathParameters);
|
|
60
56
|
|
|
61
57
|
// Add request body parameter if present
|
|
62
|
-
if (operation.requestBody?.typeName) {
|
|
63
|
-
const bodyParameter = `body: ${operation.requestBody.typeName}`;
|
|
58
|
+
if (props.operation.requestBody?.typeName) {
|
|
59
|
+
const bodyParameter = `body: ${props.operation.requestBody.typeName}`;
|
|
64
60
|
functionParameters.push(bodyParameter);
|
|
65
61
|
}
|
|
66
62
|
|
|
@@ -79,19 +75,55 @@ export function getRealizeWriteCodeTemplate(
|
|
|
79
75
|
}
|
|
80
76
|
|
|
81
77
|
// Determine return type
|
|
82
|
-
const returnType = operation.responseBody?.typeName ?? "void";
|
|
78
|
+
const returnType = props.operation.responseBody?.typeName ?? "void";
|
|
83
79
|
|
|
84
80
|
// Generate the complete template
|
|
85
81
|
return StringUtil.trim`
|
|
86
82
|
Complete the code below, disregard the import part and return only the function part.
|
|
87
83
|
|
|
88
84
|
\`\`\`typescript
|
|
89
|
-
${getRealizeWriteImportStatements(
|
|
85
|
+
${getRealizeWriteImportStatements(props).join("\n")}
|
|
90
86
|
|
|
91
|
-
//
|
|
92
|
-
|
|
87
|
+
// DON'T CHANGE FUNCTION NAME AND PARAMETERS,
|
|
88
|
+
// ONLY YOU HAVE TO WRITE THIS FUNCTION BODY, AND USE IMPORTED.
|
|
89
|
+
export async function ${props.scenario.functionName}(${formattedSignature}): Promise<${returnType}> {
|
|
93
90
|
...
|
|
94
91
|
}
|
|
95
92
|
\`\`\`
|
|
96
93
|
`;
|
|
97
94
|
}
|
|
95
|
+
|
|
96
|
+
const writeParameterType = (
|
|
97
|
+
schema: AutoBeOpenApi.IParameter["schema"],
|
|
98
|
+
): string => {
|
|
99
|
+
const elements: string[] =
|
|
100
|
+
schema.type === "integer"
|
|
101
|
+
? ["number", `tags.Type<"int32">`]
|
|
102
|
+
: [schema.type];
|
|
103
|
+
if (schema.type === "number") {
|
|
104
|
+
if (schema.minimum !== undefined)
|
|
105
|
+
elements.push(`tags.Minimum<${schema.minimum}>`);
|
|
106
|
+
if (schema.maximum !== undefined)
|
|
107
|
+
elements.push(`tags.Maximum<${schema.maximum}>`);
|
|
108
|
+
if (schema.exclusiveMinimum !== undefined)
|
|
109
|
+
elements.push(`tags.ExclusiveMinimum<${schema.exclusiveMinimum}>`);
|
|
110
|
+
if (schema.exclusiveMaximum !== undefined)
|
|
111
|
+
elements.push(`tags.ExclusiveMaximum<${schema.exclusiveMaximum}>`);
|
|
112
|
+
if (schema.multipleOf !== undefined)
|
|
113
|
+
elements.push(`tags.MultipleOf<${schema.multipleOf}>`);
|
|
114
|
+
} else if (schema.type === "string") {
|
|
115
|
+
if (schema.format !== undefined)
|
|
116
|
+
elements.push(`tags.Format<${JSON.stringify(schema.format)}>`);
|
|
117
|
+
if (schema.contentMediaType !== undefined)
|
|
118
|
+
elements.push(
|
|
119
|
+
`tags.ContentMediaType<${JSON.stringify(schema.contentMediaType)}>`,
|
|
120
|
+
);
|
|
121
|
+
if (schema.pattern !== undefined)
|
|
122
|
+
elements.push(`tags.Pattern<${JSON.stringify(schema.pattern)}>`);
|
|
123
|
+
if (schema.minLength !== undefined)
|
|
124
|
+
elements.push(`tags.MinLength<${schema.minLength}>`);
|
|
125
|
+
if (schema.maxLength !== undefined)
|
|
126
|
+
elements.push(`tags.MaxLength<${schema.maxLength}>`);
|
|
127
|
+
}
|
|
128
|
+
return elements.join(" & ");
|
|
129
|
+
};
|
|
@@ -1,30 +1,42 @@
|
|
|
1
1
|
import { AutoBeOpenApi } from "@autobe/interface";
|
|
2
|
+
import { OpenApiTypeChecker } from "@samchon/openapi";
|
|
2
3
|
|
|
3
|
-
export function getRealizeWriteImportStatements(
|
|
4
|
-
operation: AutoBeOpenApi.IOperation
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
export function getRealizeWriteImportStatements(props: {
|
|
5
|
+
operation: AutoBeOpenApi.IOperation;
|
|
6
|
+
schemas: Record<string, AutoBeOpenApi.IJsonSchemaDescriptive>;
|
|
7
|
+
}): string[] {
|
|
8
|
+
const typeReferences: Set<string> = new Set();
|
|
9
|
+
const visit = (key: string) =>
|
|
10
|
+
OpenApiTypeChecker.visit({
|
|
11
|
+
schema: {
|
|
12
|
+
$ref: `#/components/schemas/${key}`,
|
|
13
|
+
},
|
|
14
|
+
components: { schemas: props.schemas },
|
|
15
|
+
closure: (next) => {
|
|
16
|
+
if (OpenApiTypeChecker.isReference(next))
|
|
17
|
+
typeReferences.add(next.$ref.split("/").pop()!.split(".")[0]!);
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
if (props.operation.requestBody) visit(props.operation.requestBody.typeName);
|
|
21
|
+
if (props.operation.responseBody)
|
|
22
|
+
visit(props.operation.responseBody.typeName);
|
|
13
23
|
|
|
14
24
|
// Build the standard imports
|
|
15
25
|
const imports = [
|
|
26
|
+
'import { HttpException } from "@nestjs/common";',
|
|
27
|
+
'import { Prisma } from "@prisma/client";',
|
|
16
28
|
'import jwt from "jsonwebtoken";',
|
|
17
|
-
'import { MyGlobal } from "../MyGlobal";',
|
|
18
29
|
'import typia, { tags } from "typia";',
|
|
19
|
-
'import { Prisma } from "@prisma/client";',
|
|
20
30
|
'import { v4 } from "uuid";',
|
|
21
|
-
|
|
22
|
-
'import {
|
|
23
|
-
|
|
31
|
+
|
|
32
|
+
'import { MyGlobal } from "../MyGlobal";',
|
|
33
|
+
'import { PasswordUtil } from "../utils/PasswordUtil";',
|
|
34
|
+
'import { toISOStringSafe } from "../utils/toISOStringSafe"',
|
|
35
|
+
"",
|
|
36
|
+
...Array.from(typeReferences).map(
|
|
24
37
|
(ref) =>
|
|
25
38
|
`import { ${ref} } from "@ORGANIZATION/PROJECT-api/lib/structures/${ref}";`,
|
|
26
39
|
),
|
|
27
40
|
];
|
|
28
|
-
|
|
29
41
|
return imports;
|
|
30
42
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { IAutoBeTypeScriptCompileResult } from "@autobe/interface";
|
|
2
|
+
import { StringUtil } from "@autobe/utils";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Prints error hints for a given code and its diagnostics.
|
|
6
|
+
*
|
|
7
|
+
* @param code The code to analyze.
|
|
8
|
+
* @param diagnostics The diagnostics to use for error hinting.
|
|
9
|
+
*/
|
|
10
|
+
export function printErrorHints(
|
|
11
|
+
code: string,
|
|
12
|
+
diagnostics: IAutoBeTypeScriptCompileResult.IDiagnostic[],
|
|
13
|
+
): string {
|
|
14
|
+
const lines: string[] = code.split("\n");
|
|
15
|
+
|
|
16
|
+
let cursor: number = 0;
|
|
17
|
+
const hints: string[] = [];
|
|
18
|
+
lines.forEach((line, index, arr) => {
|
|
19
|
+
const lineStart = cursor;
|
|
20
|
+
cursor += line.length + 1; // +1 for the newline character
|
|
21
|
+
|
|
22
|
+
diagnostics.forEach((diag) => {
|
|
23
|
+
if (diag.start === null || diag.start === undefined) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Check if the diagnostic start position falls within the current line
|
|
28
|
+
if (diag.start >= lineStart && diag.start < cursor) {
|
|
29
|
+
// Handle multi-line error messages by escaping newlines
|
|
30
|
+
const errorMessage = String(diag.messageText).replace(/\n/g, "\\n");
|
|
31
|
+
const targetLine = line + " // error: " + errorMessage;
|
|
32
|
+
|
|
33
|
+
// targetLine만 덮어써서 새로운 배열을 만들어야 한다.
|
|
34
|
+
const hint: string = arr
|
|
35
|
+
.slice(0, index)
|
|
36
|
+
.concat(targetLine)
|
|
37
|
+
.concat(arr.slice(index + 1))
|
|
38
|
+
.join("\n");
|
|
39
|
+
|
|
40
|
+
hints.push(hint);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return hints
|
|
46
|
+
.map((h, i) => {
|
|
47
|
+
return StringUtil.trim`
|
|
48
|
+
hint #${i + 1}:
|
|
49
|
+
\`\`\`typescript
|
|
50
|
+
${h}
|
|
51
|
+
\`\`\`
|
|
52
|
+
`;
|
|
53
|
+
})
|
|
54
|
+
.join("\n");
|
|
55
|
+
}
|