@autobe/agent 0.10.5 → 0.11.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 +13 -46
- package/lib/AutoBeAgent.js.map +1 -1
- package/lib/constants/AutoBeSystemPromptConstant.d.ts +11 -6
- package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
- package/lib/context/AutoBeContext.d.ts +3 -2
- package/lib/factory/getAutoBeGenerated.d.ts +5 -0
- package/lib/factory/getAutoBeGenerated.js +307 -0
- package/lib/factory/getAutoBeGenerated.js.map +1 -0
- package/lib/index.mjs +1631 -1389
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.d.ts +2 -7
- package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.js +1 -9
- package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.js.map +1 -1
- package/lib/orchestrate/analyze/AutoBeAnalyzeRole.d.ts +13 -0
- package/lib/orchestrate/analyze/AutoBeAnalyzeRole.js +3 -0
- package/lib/orchestrate/analyze/AutoBeAnalyzeRole.js.map +1 -0
- package/lib/orchestrate/analyze/orchestrateAnalyze.d.ts +0 -25
- package/lib/orchestrate/analyze/orchestrateAnalyze.js +22 -420
- package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.d.ts +6 -0
- package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.js +561 -0
- package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.js.map +1 -0
- package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.d.ts +6 -0
- package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js +41 -0
- package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js.map +1 -0
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.d.ts +14 -0
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js +468 -0
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js.map +1 -0
- package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeComposerApplication.d.ts +68 -0
- package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeComposerApplication.js +3 -0
- package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeComposerApplication.js.map +1 -0
- package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.d.ts +5 -0
- package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js +27 -0
- package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js.map +1 -0
- package/lib/orchestrate/analyze/transformAnalyzeWriteHistories.d.ts +12 -0
- package/lib/orchestrate/analyze/transformAnalyzeWriteHistories.js +78 -0
- package/lib/orchestrate/analyze/transformAnalyzeWriteHistories.js.map +1 -0
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.d.ts +6 -0
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js +58 -0
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js.map +1 -0
- package/lib/orchestrate/interface/orchestrateInterface.js +0 -2
- package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +17 -137
- package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +92 -141
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrisma.js +9 -5
- package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaComponent.js +54 -25
- package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +4 -3
- package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
- package/lib/orchestrate/prisma/{orchestratePrismaSchema.d.ts → orchestratePrismaSchemas.d.ts} +2 -4
- package/lib/orchestrate/prisma/{orchestratePrismaSchema.js → orchestratePrismaSchemas.js} +269 -203
- package/lib/orchestrate/prisma/orchestratePrismaSchemas.js.map +1 -0
- package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js +1 -1
- package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js.map +1 -1
- package/lib/orchestrate/prisma/transformPrismaCorrectHistories.js +1 -1
- package/lib/orchestrate/prisma/transformPrismaHistories.js +1 -1
- package/lib/orchestrate/prisma/transformPrismaHistories.js.map +1 -1
- package/lib/orchestrate/prisma/transformPrismaSchemaHistories.d.ts +2 -6
- package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js +24 -32
- package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js.map +1 -1
- package/lib/orchestrate/realize/RealizePipe.d.ts +5 -0
- package/lib/orchestrate/realize/RealizePipe.js +14 -0
- package/lib/orchestrate/realize/RealizePipe.js.map +1 -0
- package/lib/orchestrate/realize/orchestrateRealize.d.ts +0 -6
- package/lib/orchestrate/realize/orchestrateRealize.js +6 -43
- package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeCoder.d.ts +3 -3
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js +124 -59
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -1
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.d.ts +188 -18
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.d.ts +23 -0
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.js +3 -0
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.js.map +1 -0
- package/lib/orchestrate/realize/structures/IAutoBeRealizeFailedSymbol.d.ts +2 -0
- package/lib/orchestrate/realize/structures/IAutoBeRealizeFailedSymbol.js +5 -0
- package/lib/orchestrate/realize/structures/IAutoBeRealizeFailedSymbol.js.map +1 -0
- package/lib/orchestrate/realize/transformRealizeCoderHistories.d.ts +2 -1
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js +50 -36
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -1
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.d.ts +5 -0
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js +123 -0
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js.map +1 -0
- package/lib/orchestrate/test/compile/getTestExternalDeclarations.js +4 -1
- package/lib/orchestrate/test/compile/getTestExternalDeclarations.js.map +1 -1
- package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js +2 -1
- package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTest.js +11 -5
- package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestCorrect.js +3 -2
- package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
- package/lib/structures/IAutoBeProps.d.ts +8 -8
- package/lib/utils/pipe.d.ts +5 -0
- package/lib/utils/pipe.js +14 -0
- package/lib/utils/pipe.js.map +1 -0
- package/package.json +6 -6
- package/src/AutoBeAgent.ts +22 -76
- package/src/constants/AutoBeSystemPromptConstant.ts +11 -6
- package/src/context/AutoBeContext.ts +3 -1
- package/src/factory/getAutoBeGenerated.ts +113 -0
- package/src/orchestrate/analyze/AutoBeAnalyzeFileSystem.ts +5 -13
- package/src/orchestrate/analyze/AutoBeAnalyzeRole.ts +14 -0
- package/src/orchestrate/analyze/orchestrateAnalyze.ts +30 -165
- package/src/orchestrate/analyze/orchestrateAnalyzeComposer.ts +115 -0
- package/src/orchestrate/analyze/orchestrateAnalyzeReviewer.ts +39 -0
- package/src/orchestrate/analyze/orchestrateAnalyzeWrite.ts +106 -0
- package/src/orchestrate/analyze/structures/IAutoBeAnalyzeComposerApplication.ts +74 -0
- package/src/orchestrate/analyze/transformAnalyzeReviewerHistories.ts +31 -0
- package/src/orchestrate/analyze/transformAnalyzeWriteHistories.ts +94 -0
- package/src/orchestrate/analyze/writeDocumentUntilReviewPassed.ts +66 -0
- package/src/orchestrate/interface/orchestrateInterface.ts +0 -2
- package/src/orchestrate/interface/orchestrateInterfaceComponents.ts +2 -3
- package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +21 -0
- package/src/orchestrate/prisma/orchestratePrisma.ts +12 -5
- package/src/orchestrate/prisma/orchestratePrismaComponent.ts +4 -13
- package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +9 -4
- package/src/orchestrate/prisma/orchestratePrismaSchemas.ts +265 -0
- package/src/orchestrate/prisma/transformPrismaSchemaHistories.ts +26 -37
- package/src/orchestrate/realize/RealizePipe.ts +39 -0
- package/src/orchestrate/realize/orchestrateRealize.ts +3 -91
- package/src/orchestrate/realize/orchestrateRealizeCoder.ts +60 -25
- package/src/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.ts +192 -18
- package/src/orchestrate/realize/structures/IAutoBeRealizeCompile.ts +34 -0
- package/src/orchestrate/realize/structures/IAutoBeRealizeFailedSymbol.ts +2 -0
- package/src/orchestrate/realize/transformRealizeCoderHistories.ts +58 -34
- package/src/orchestrate/realize/writeCodeUntilCompilePassed.ts +178 -0
- package/src/orchestrate/test/compile/getTestExternalDeclarations.ts +5 -4
- package/src/orchestrate/test/compile/getTestScenarioArtifacts.ts +7 -2
- package/src/orchestrate/test/orchestrateTest.ts +14 -12
- package/src/orchestrate/test/orchestrateTestCorrect.ts +10 -9
- package/src/structures/IAutoBeProps.ts +10 -7
- package/src/utils/pipe.ts +39 -0
- package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.d.ts +0 -20
- package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js +0 -735
- package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js.map +0 -1
- package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.d.ts +0 -15
- package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js +0 -44
- package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js.map +0 -1
- package/lib/orchestrate/prisma/orchestratePrismaSchema.js.map +0 -1
- package/src/orchestrate/analyze/AutoBeAnalyzeAgent.ts +0 -219
- package/src/orchestrate/analyze/AutoBeAnalyzeReviewer.ts +0 -62
- package/src/orchestrate/prisma/orchestratePrismaSchema.ts +0 -157
|
@@ -1,39 +1,213 @@
|
|
|
1
1
|
import { AutoBeOpenApi } from "@autobe/interface";
|
|
2
2
|
|
|
3
|
-
import { FAILED } from "
|
|
3
|
+
import { FAILED } from "./IAutoBeRealizeFailedSymbol";
|
|
4
4
|
|
|
5
5
|
export interface IAutoBeRealizeCoderApplication {
|
|
6
|
-
|
|
6
|
+
programming: (input: IAutoBeRealizeCoderApplication.IProps) => void;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export namespace IAutoBeRealizeCoderApplication {
|
|
10
|
+
/**
|
|
11
|
+
* Properties for the component or function that consumes the output of the
|
|
12
|
+
* code generation pipeline.
|
|
13
|
+
*/
|
|
10
14
|
export interface IProps {
|
|
11
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The detailed output of the code generation process, containing all phases
|
|
17
|
+
* from planning to final implementation of a TypeScript provider function.
|
|
18
|
+
*/
|
|
19
|
+
output: RealizeCoderOutput;
|
|
12
20
|
}
|
|
13
21
|
|
|
14
22
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
23
|
+
* Represents the complete output of a code generation pipeline. Each field
|
|
24
|
+
* corresponds to a stage in the Chain of Thought (CoT) process for generating
|
|
25
|
+
* a production-quality TypeScript function.
|
|
26
|
+
*
|
|
27
|
+
* All fields contain TypeScript code strings and follow these rules:
|
|
28
|
+
*
|
|
29
|
+
* - All code must be valid TypeScript or structurally valid even if incomplete.
|
|
30
|
+
* - Each phase builds upon the previous one and must resolve specific concerns.
|
|
31
|
+
* - All phases must follow system conventions around structure, typing, and
|
|
32
|
+
* logic.
|
|
17
33
|
*/
|
|
18
34
|
export interface RealizeCoderOutput {
|
|
35
|
+
/** The name of the file to be generated (e.g., "user.create.ts") */
|
|
36
|
+
filename: string;
|
|
37
|
+
|
|
19
38
|
/**
|
|
20
|
-
*
|
|
39
|
+
* 🧠 Provider Function Implementation Plan
|
|
40
|
+
*
|
|
41
|
+
* This field outlines the strategic plan for implementing the provider
|
|
42
|
+
* function according to the Realize Coder Agent specification. Before
|
|
43
|
+
* writing the actual code, think through the logic and structure.
|
|
44
|
+
*
|
|
45
|
+
* The plan must consider:
|
|
46
|
+
*
|
|
47
|
+
* - 🧩 Required business entities (e.g., users, posts, logs) and their
|
|
48
|
+
* relationships
|
|
49
|
+
* - 🛠 Operations needed to fulfill the business scenario (e.g., fetch,
|
|
50
|
+
* create, update)
|
|
51
|
+
* - 🔄 Data dependencies between steps (e.g., use userId to fetch related
|
|
52
|
+
* data)
|
|
53
|
+
* - ✅ Validation points (based on business rules, not field presence)
|
|
54
|
+
* - 🚧 Error and edge cases that must be handled explicitly (e.g., missing
|
|
55
|
+
* records)
|
|
56
|
+
* - 🏗 Structure: always a single `async function`, using only `parameters`
|
|
57
|
+
* and `body`
|
|
58
|
+
*
|
|
59
|
+
* ⚠️ Important Constraints:
|
|
60
|
+
*
|
|
61
|
+
* - Do NOT perform input validation — assume `parameters` and `body` are
|
|
62
|
+
* already valid
|
|
63
|
+
* - Use `typia.random<T>()` with an explanatory comment if logic can't be
|
|
64
|
+
* implemented
|
|
65
|
+
* - Never use `any` or make assumptions without sufficient context
|
|
66
|
+
* - Use only allowed imports — DTOs and Prisma types
|
|
67
|
+
* - Use `MyGlobal.prisma` for DB access and respect Prisma typing rules
|
|
68
|
+
*
|
|
69
|
+
* ⚠️ TypeScript-specific considerations:
|
|
70
|
+
*
|
|
71
|
+
* - Do **not** use native `Date` objects directly; convert all dates with
|
|
72
|
+
* `.toISOString()`
|
|
73
|
+
* - Use `string & tags.Format<'date-time'>` for all date/time typed fields
|
|
74
|
+
* - Prefer `satisfies` for DTO conformance instead of unsafe `as` casts
|
|
75
|
+
* - Avoid weak typing such as `any`, `as any`, or `satisfies any`
|
|
76
|
+
* - Use branded types (e.g., `tags.Format<'uuid'>`) and literal unions where
|
|
77
|
+
* applicable
|
|
21
78
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
79
|
+
* ✅ Example Structure:
|
|
80
|
+
*
|
|
81
|
+
* ```ts
|
|
82
|
+
* export async function doSomething(
|
|
83
|
+
* user: { id: string & tags.Format<"uuid">; type: string },
|
|
84
|
+
* parameters: IParams,
|
|
85
|
+
* body: IBody
|
|
86
|
+
* ): Promise<IReturn> {
|
|
87
|
+
* const { id } = parameters;
|
|
88
|
+
* const { name } = body;
|
|
89
|
+
* const user = await MyGlobal.prisma.users.findFirst({ where: { id } });
|
|
90
|
+
* if (!user) throw new Error("User not found");
|
|
91
|
+
* ...
|
|
92
|
+
* return result;
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* 🔥 Error Handling Plan:
|
|
97
|
+
*
|
|
98
|
+
* If an error is expected or encountered during implementation:
|
|
99
|
+
*
|
|
100
|
+
* - Clearly document the error message(s) and TypeScript error codes.
|
|
101
|
+
* - Analyze the root cause (e.g., type mismatch, missing field, nullability
|
|
102
|
+
* issue).
|
|
103
|
+
* - Define concrete steps to resolve the issue, such as:
|
|
104
|
+
*
|
|
105
|
+
* - Adjusting type declarations or using Prisma-generated input types.
|
|
106
|
+
* - Using `?? undefined` to normalize nullable fields.
|
|
107
|
+
* - Applying correct relation handling (e.g., `connect` instead of direct
|
|
108
|
+
* foreign key assignment).
|
|
109
|
+
* - Ensuring `Date` fields use `.toISOString()` and branded types.
|
|
110
|
+
* - Include fallback or workaround plans if a direct fix is complex.
|
|
111
|
+
* - If no error is present, simply omit this section.
|
|
112
|
+
*
|
|
113
|
+
* This plan ensures the function will:
|
|
114
|
+
*
|
|
115
|
+
* - Respect the global architecture and coding conventions
|
|
116
|
+
* - Be safe, predictable, and aligned with upstream logic
|
|
24
117
|
*/
|
|
25
|
-
|
|
118
|
+
plan: string;
|
|
26
119
|
|
|
27
120
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* -
|
|
36
|
-
*
|
|
121
|
+
* ✏️ Phase 1: Draft code
|
|
122
|
+
*
|
|
123
|
+
* This is the initial drafting phase where you outline the basic skeleton
|
|
124
|
+
* of the function.
|
|
125
|
+
*
|
|
126
|
+
* - The function signature must correctly include `user`, `parameters`, and
|
|
127
|
+
* `body` arguments.
|
|
128
|
+
* - Design the main flow of business logic, such as DB fetches and early
|
|
129
|
+
* returns based on conditions.
|
|
130
|
+
* - Mark any incomplete or missing parts clearly with placeholders (e.g.,
|
|
131
|
+
* comments or temporary values).
|
|
132
|
+
*
|
|
133
|
+
* ⚠️ Import rules:
|
|
134
|
+
*
|
|
135
|
+
* - Do NOT add any new import statements manually.
|
|
136
|
+
* - All necessary imports are provided globally or by the system
|
|
137
|
+
* automatically.
|
|
138
|
+
* - Writing import statements directly is prohibited and may cause compile
|
|
139
|
+
* errors. If import errors occur, check your environment configuration.
|
|
140
|
+
*
|
|
141
|
+
* ✅ Requirements:
|
|
142
|
+
*
|
|
143
|
+
* - Avoid using the `any` type at all costs to ensure type safety.
|
|
144
|
+
* - Do NOT assign native `Date` objects directly; always convert dates using
|
|
145
|
+
* `.toISOString()` before assignment.
|
|
146
|
+
* - Maintain a single-function structure; avoid using classes.
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 🔍 Phase 2: Review code
|
|
151
|
+
*
|
|
152
|
+
* A refined version of the draft with improved completeness.
|
|
153
|
+
*
|
|
154
|
+
* - Replace placeholder logic with real DTO-conformant operations.
|
|
155
|
+
* - Add error handling (`throw new Error(...)`) where necessary.
|
|
156
|
+
* - Begin resolving structural or type mismatches.
|
|
157
|
+
*
|
|
158
|
+
* ✅ Requirements:
|
|
159
|
+
*
|
|
160
|
+
* - Use `satisfies` to ensure DTO conformity.
|
|
161
|
+
* - Avoid unsafe `as` casts unless only for branding or literal narrowing.
|
|
162
|
+
* - Include `.toISOString()` for all date fields.
|
|
163
|
+
* - Ensure all object keys strictly conform to the expected type definitions.
|
|
164
|
+
*/
|
|
165
|
+
review: string;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 🛠 Phase 3: With compiler feedback (optional)
|
|
169
|
+
*
|
|
170
|
+
* A correction pass that applies fixes for compile-time errors that arose
|
|
171
|
+
* during the review stage (if any).
|
|
172
|
+
*
|
|
173
|
+
* ✅ Must:
|
|
174
|
+
*
|
|
175
|
+
* - Resolve all TypeScript errors without using `as any`
|
|
176
|
+
* - Provide safe brand casting only if required (e.g., `as string &
|
|
177
|
+
* tags.Format<'uuid'>`)
|
|
178
|
+
*/
|
|
179
|
+
withCompilerFeedback?: string;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* ✅ Phase 4: Final implementation
|
|
183
|
+
*
|
|
184
|
+
* The complete and fully correct TypeScript function implementation.
|
|
185
|
+
*
|
|
186
|
+
* - Passes strict type checking without errors.
|
|
187
|
+
* - Uses only safe branding or literal type assertions.
|
|
188
|
+
* - Converts all Date values properly to ISO string format.
|
|
189
|
+
* - Follows DTO structures using `satisfies`.
|
|
190
|
+
* - Avoids any weak typing such as `any`, `as any`, or `satisfies any`.
|
|
191
|
+
* - Uses only allowed imports (e.g., from `src/api/structures` and
|
|
192
|
+
* `MyGlobal.prisma`).
|
|
193
|
+
*
|
|
194
|
+
* ⚠️ Prohibited Practices:
|
|
195
|
+
*
|
|
196
|
+
* - Do NOT add or modify import statements manually. Imports are handled
|
|
197
|
+
* automatically by the system.
|
|
198
|
+
* - Do NOT use `any`, `as any`, or `satisfies any` to bypass type checking.
|
|
199
|
+
* - Do NOT assign native `Date` objects directly; always convert them to ISO
|
|
200
|
+
* strings with `.toISOString()`.
|
|
201
|
+
* - Do NOT use unsafe type assertions except for safe branding or literal
|
|
202
|
+
* narrowing.
|
|
203
|
+
* - Do NOT write code outside the single async function structure (e.g., no
|
|
204
|
+
* classes or multiple functions).
|
|
205
|
+
* - Do NOT perform any input validation — assume all inputs are already
|
|
206
|
+
* validated.
|
|
207
|
+
* - Do NOT use dynamic import expressions (`import()`); all imports must be
|
|
208
|
+
* static.
|
|
209
|
+
* - Do NOT rely on DTO types for database update input; always use
|
|
210
|
+
* Prisma-generated input types.
|
|
37
211
|
*/
|
|
38
212
|
implementationCode: string;
|
|
39
213
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AutoBeOpenApi,
|
|
3
|
+
IAutoBeTypeScriptCompileResult,
|
|
4
|
+
} from "@autobe/interface";
|
|
5
|
+
|
|
6
|
+
import { IAutoBeRealizeCoderApplication } from "./IAutoBeRealizeCoderApplication";
|
|
7
|
+
import { FAILED } from "./IAutoBeRealizeFailedSymbol";
|
|
8
|
+
|
|
9
|
+
export namespace IAutoBeRealizeCompile {
|
|
10
|
+
export interface Success {
|
|
11
|
+
type: "success";
|
|
12
|
+
op: AutoBeOpenApi.IOperation;
|
|
13
|
+
result: Pick<
|
|
14
|
+
IAutoBeRealizeCoderApplication.RealizeCoderOutput,
|
|
15
|
+
"filename" | "implementationCode"
|
|
16
|
+
>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface Fail {
|
|
20
|
+
type: "failed";
|
|
21
|
+
op: AutoBeOpenApi.IOperation;
|
|
22
|
+
result: FAILED;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type FileContentMap = Record<
|
|
26
|
+
string,
|
|
27
|
+
{ content: string; result: "failed" | "success" }
|
|
28
|
+
>;
|
|
29
|
+
|
|
30
|
+
export interface CompileDiagnostics {
|
|
31
|
+
total: IAutoBeTypeScriptCompileResult.IDiagnostic[];
|
|
32
|
+
current: IAutoBeTypeScriptCompileResult.IDiagnostic[];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IAgenticaHistoryJson } from "@agentica/core";
|
|
2
|
+
import { IAutoBeTypeScriptCompileResult } from "@autobe/interface";
|
|
2
3
|
import { v4 } from "uuid";
|
|
3
4
|
|
|
4
5
|
import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
|
|
@@ -10,6 +11,9 @@ export const transformRealizeCoderHistories = (
|
|
|
10
11
|
state: AutoBeState,
|
|
11
12
|
props: RealizePlannerOutput,
|
|
12
13
|
artifacts: IAutoBeTestScenarioArtifacts,
|
|
14
|
+
previous: string | null,
|
|
15
|
+
total: IAutoBeTypeScriptCompileResult.IDiagnostic[],
|
|
16
|
+
diagnostics: IAutoBeTypeScriptCompileResult.IDiagnostic[],
|
|
13
17
|
): Array<
|
|
14
18
|
IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
|
|
15
19
|
> => {
|
|
@@ -86,47 +90,67 @@ export const transformRealizeCoderHistories = (
|
|
|
86
90
|
id: v4(),
|
|
87
91
|
created_at: new Date().toISOString(),
|
|
88
92
|
type: "systemMessage",
|
|
89
|
-
text:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
text: AutoBeSystemPromptConstant.REALIZE_CODER,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: v4(),
|
|
97
|
+
created_at: new Date().toISOString(),
|
|
98
|
+
type: "systemMessage",
|
|
99
|
+
text: AutoBeSystemPromptConstant.REALIZE_CODER_TYPESCRIPT,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: v4(),
|
|
103
|
+
created_at: new Date().toISOString(),
|
|
104
|
+
type: "systemMessage",
|
|
105
|
+
text: AutoBeSystemPromptConstant.REALIZE_CODER_PRISMA,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
id: v4(),
|
|
109
|
+
created_at: new Date().toISOString(),
|
|
110
|
+
type: "systemMessage",
|
|
111
|
+
text: AutoBeSystemPromptConstant.REALIZE_CODER_BROWSER,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: v4(),
|
|
115
|
+
created_at: new Date().toISOString(),
|
|
116
|
+
type: "systemMessage",
|
|
117
|
+
text: AutoBeSystemPromptConstant.REALIZE_CODER_TYPIA,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: v4(),
|
|
121
|
+
created_at: new Date().toISOString(),
|
|
122
|
+
type: "systemMessage",
|
|
123
|
+
text: AutoBeSystemPromptConstant.REALIZE_CODER_ARTIFACT.replaceAll(
|
|
124
|
+
`{prisma_schemas}`,
|
|
94
125
|
JSON.stringify(state.prisma.schemas),
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// JSON.stringify(state.prisma.compiled.nodeModules),
|
|
100
|
-
// "```",
|
|
101
|
-
"# SDK",
|
|
102
|
-
"",
|
|
103
|
-
"The following is the SDK for the API. Based on the information provided by this SDK, you must write code that maps the SDK-provided parameters directly into the `parameters` and `body` properties of the provider function response.",
|
|
104
|
-
"If there are no parameters, define `parameters` as `Record<string, never>`. Similarly, if there is no body, define `body` as `Record<string, never>`.",
|
|
105
|
-
"**Every function must be implemented to accept both `parameters` and `body`, without exception.**",
|
|
106
|
-
"If any required type information is referenced in the SDK, refer to the definitions in the DTO section.",
|
|
107
|
-
"",
|
|
108
|
-
"```json",
|
|
109
|
-
JSON.stringify(artifacts.sdk),
|
|
110
|
-
"```",
|
|
111
|
-
"",
|
|
112
|
-
"# DTO",
|
|
113
|
-
"if you want to import this files, write this: 'import { something } from '../api/structures/something';'",
|
|
114
|
-
"",
|
|
115
|
-
"```json",
|
|
116
|
-
JSON.stringify(artifacts.dto),
|
|
117
|
-
"```",
|
|
118
|
-
"# Document",
|
|
119
|
-
"```json",
|
|
120
|
-
JSON.stringify(artifacts.document),
|
|
121
|
-
"```",
|
|
122
|
-
].join("\n"),
|
|
126
|
+
)
|
|
127
|
+
.replaceAll(`{artifacts_sdk}`, JSON.stringify(artifacts.sdk))
|
|
128
|
+
.replaceAll(`{artifacts_dto}`, JSON.stringify(artifacts.dto))
|
|
129
|
+
.replaceAll(`{artifacts_document}`, JSON.stringify(artifacts.document)),
|
|
123
130
|
},
|
|
131
|
+
...(previous !== null
|
|
132
|
+
? [
|
|
133
|
+
{
|
|
134
|
+
id: v4(),
|
|
135
|
+
created_at: new Date().toISOString(),
|
|
136
|
+
type: "assistantMessage",
|
|
137
|
+
text: AutoBeSystemPromptConstant.REALIZE_CODER_DIAGNOSTICS.replaceAll(
|
|
138
|
+
`{code}`,
|
|
139
|
+
previous,
|
|
140
|
+
)
|
|
141
|
+
.replaceAll("{total_diagnostics}", JSON.stringify(total))
|
|
142
|
+
.replaceAll("{current_diagnostics}", JSON.stringify(diagnostics)),
|
|
143
|
+
} as const,
|
|
144
|
+
]
|
|
145
|
+
: []),
|
|
124
146
|
{
|
|
125
147
|
id: v4(),
|
|
126
148
|
created_at: new Date().toISOString(),
|
|
127
149
|
type: "systemMessage",
|
|
128
150
|
text: [
|
|
129
|
-
|
|
151
|
+
previous
|
|
152
|
+
? "Modify the previous code to reflect the following operation."
|
|
153
|
+
: "Write new code based on the following operation.",
|
|
130
154
|
"```json",
|
|
131
155
|
JSON.stringify(props),
|
|
132
156
|
"```",
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AutoBeOpenApi,
|
|
3
|
+
IAutoBeTypeScriptCompileResult,
|
|
4
|
+
} from "@autobe/interface";
|
|
5
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
6
|
+
import { readFile } from "fs/promises";
|
|
7
|
+
import path from "path";
|
|
8
|
+
|
|
9
|
+
import { AutoBeContext } from "../../context/AutoBeContext";
|
|
10
|
+
import { pipe } from "./RealizePipe";
|
|
11
|
+
import { orchestrateRealizeCoder } from "./orchestrateRealizeCoder";
|
|
12
|
+
import { orchestrateRealizePlanner } from "./orchestrateRealizePlanner";
|
|
13
|
+
import { IAutoBeRealizeCoderApplication } from "./structures/IAutoBeRealizeCoderApplication";
|
|
14
|
+
import { IAutoBeRealizeCompile } from "./structures/IAutoBeRealizeCompile";
|
|
15
|
+
import { FAILED } from "./structures/IAutoBeRealizeFailedSymbol";
|
|
16
|
+
|
|
17
|
+
export async function writeCodeUntilCompilePassed<
|
|
18
|
+
Model extends ILlmSchema.Model,
|
|
19
|
+
>(
|
|
20
|
+
ctx: AutoBeContext<Model>,
|
|
21
|
+
ops: AutoBeOpenApi.IOperation[],
|
|
22
|
+
retry: number = 5,
|
|
23
|
+
): Promise<
|
|
24
|
+
Pick<
|
|
25
|
+
IAutoBeRealizeCoderApplication.RealizeCoderOutput,
|
|
26
|
+
"filename" | "implementationCode"
|
|
27
|
+
>[]
|
|
28
|
+
> {
|
|
29
|
+
const files = Object.entries(await ctx.files({ dbms: "postgres" }))
|
|
30
|
+
.filter(([key]) => {
|
|
31
|
+
return key.startsWith("src");
|
|
32
|
+
})
|
|
33
|
+
.reduce(
|
|
34
|
+
(acc, [filename, content]) => Object.assign(acc, { [filename]: content }),
|
|
35
|
+
{},
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const templateFiles = ["src/providers/jwtDecode.ts", "src/MyGlobal.ts"];
|
|
39
|
+
const entireCodes: IAutoBeRealizeCompile.FileContentMap = {
|
|
40
|
+
...(await loadTemplateFiles(templateFiles)),
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
let diagnostics: IAutoBeRealizeCompile.CompileDiagnostics = {
|
|
44
|
+
current: [],
|
|
45
|
+
total: [],
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
for (let i = 0; i < retry; i++) {
|
|
49
|
+
const generatedCodes: (
|
|
50
|
+
| IAutoBeRealizeCompile.Success
|
|
51
|
+
| IAutoBeRealizeCompile.Fail
|
|
52
|
+
)[] = await Promise.all(
|
|
53
|
+
ops
|
|
54
|
+
.filter((op) => shouldProcessOperation(op, diagnostics.current))
|
|
55
|
+
.map((op) => process(ctx, op, diagnostics, entireCodes)),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
for (const c of generatedCodes) {
|
|
59
|
+
if (c.type === "success") {
|
|
60
|
+
entireCodes[c.result.filename] = {
|
|
61
|
+
content: c.result.implementationCode,
|
|
62
|
+
result: "success",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const prisma = ctx.state().prisma?.compiled;
|
|
68
|
+
const nodeModules = prisma?.type === "success" ? prisma.nodeModules : {};
|
|
69
|
+
const compiler = await ctx.compiler();
|
|
70
|
+
const compiled = await compiler.typescript.compile({
|
|
71
|
+
files: {
|
|
72
|
+
...files,
|
|
73
|
+
...nodeModules,
|
|
74
|
+
...Object.entries(entireCodes)
|
|
75
|
+
.map(([filename, { content }]) => {
|
|
76
|
+
return {
|
|
77
|
+
[filename]: content,
|
|
78
|
+
};
|
|
79
|
+
})
|
|
80
|
+
.reduce<Record<string, string>>(
|
|
81
|
+
(acc, cur) => Object.assign(acc, cur),
|
|
82
|
+
{},
|
|
83
|
+
),
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
if (
|
|
88
|
+
compiled.type === "success" &&
|
|
89
|
+
generatedCodes.every((c) => c.type === "success")
|
|
90
|
+
) {
|
|
91
|
+
break;
|
|
92
|
+
} else if (compiled.type === "failure") {
|
|
93
|
+
diagnostics.current = compiled.diagnostics;
|
|
94
|
+
diagnostics.total = [...diagnostics.total, ...compiled.diagnostics];
|
|
95
|
+
|
|
96
|
+
console.log(JSON.stringify(diagnostics, null, 2), i);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return Object.entries(entireCodes).map(([filename, { content }]) => {
|
|
101
|
+
return {
|
|
102
|
+
filename,
|
|
103
|
+
implementationCode: content,
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function loadTemplateFiles(
|
|
109
|
+
templateFiles: string[],
|
|
110
|
+
): Promise<Record<string, { content: string; result: "success" }>> {
|
|
111
|
+
const templateBasePath = path.join(
|
|
112
|
+
__dirname,
|
|
113
|
+
"../../../../../internals/template/realize",
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const result: Record<string, { content: string; result: "success" }> = {};
|
|
117
|
+
|
|
118
|
+
for (const filePath of templateFiles) {
|
|
119
|
+
result[filePath] = {
|
|
120
|
+
content: await readFile(path.join(templateBasePath, filePath), {
|
|
121
|
+
encoding: "utf-8",
|
|
122
|
+
}),
|
|
123
|
+
result: "success",
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function process<Model extends ILlmSchema.Model>(
|
|
131
|
+
ctx: AutoBeContext<Model>,
|
|
132
|
+
op: AutoBeOpenApi.IOperation,
|
|
133
|
+
diagnostics: IAutoBeRealizeCompile.CompileDiagnostics,
|
|
134
|
+
entireCodes: IAutoBeRealizeCompile.FileContentMap,
|
|
135
|
+
) {
|
|
136
|
+
const result = await pipe(
|
|
137
|
+
op,
|
|
138
|
+
(op) => orchestrateRealizePlanner(ctx, op),
|
|
139
|
+
(p) => {
|
|
140
|
+
const filename = `src/providers/${p.functionName}.ts` as const;
|
|
141
|
+
const t = diagnostics.total.filter((el) => el.file === filename);
|
|
142
|
+
|
|
143
|
+
const d = diagnostics.current.filter((el) => el.file === filename);
|
|
144
|
+
const c = entireCodes[filename]?.content ?? null;
|
|
145
|
+
|
|
146
|
+
return orchestrateRealizeCoder(ctx, op, p, c, t, d);
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
if (result === FAILED) {
|
|
151
|
+
return { type: "failed", op, result } as const;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return { type: "success", op, result: result } as const;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function shouldProcessOperation(
|
|
158
|
+
op: AutoBeOpenApi.IOperation,
|
|
159
|
+
currentDiagnostics: IAutoBeTypeScriptCompileResult.IDiagnostic[],
|
|
160
|
+
): boolean {
|
|
161
|
+
if (currentDiagnostics.length === 0) {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const operationFilename = generateProviderFilename(op);
|
|
166
|
+
|
|
167
|
+
return currentDiagnostics.some(
|
|
168
|
+
(diagnostic) => diagnostic.file === operationFilename,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function generateProviderFilename(op: AutoBeOpenApi.IOperation): string {
|
|
173
|
+
return `src/providers/${op.method}_${op.path
|
|
174
|
+
.replaceAll("/", "_")
|
|
175
|
+
.replaceAll("-", "_")
|
|
176
|
+
.replaceAll("{", "$")
|
|
177
|
+
.replaceAll("}", "")}.ts`;
|
|
178
|
+
}
|
|
@@ -4,10 +4,11 @@ import { Singleton } from "tstl";
|
|
|
4
4
|
|
|
5
5
|
import { AutoBeContext } from "../../../context/AutoBeContext";
|
|
6
6
|
|
|
7
|
-
export function getTestExternalDeclarations<
|
|
8
|
-
|
|
9
|
-
): Promise<Record<string, string>> {
|
|
10
|
-
|
|
7
|
+
export async function getTestExternalDeclarations<
|
|
8
|
+
Model extends ILlmSchema.Model,
|
|
9
|
+
>(ctx: AutoBeContext<Model>): Promise<Record<string, string>> {
|
|
10
|
+
const compiler = await ctx.compiler();
|
|
11
|
+
return singleton.get(compiler.test);
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
const singleton = new Singleton(async (compiler: IAutoBeTestCompiler) => {
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AutoBeOpenApi,
|
|
3
|
+
AutoBeTestScenario,
|
|
4
|
+
IAutoBeCompiler,
|
|
5
|
+
} from "@autobe/interface";
|
|
2
6
|
import { ILlmSchema, OpenApiTypeChecker } from "@samchon/openapi";
|
|
3
7
|
|
|
4
8
|
import { AutoBeContext } from "../../../context/AutoBeContext";
|
|
@@ -8,12 +12,13 @@ export async function getTestScenarioArtifacts<Model extends ILlmSchema.Model>(
|
|
|
8
12
|
ctx: AutoBeContext<Model>,
|
|
9
13
|
scenario: Pick<AutoBeTestScenario, "endpoint" | "dependencies">,
|
|
10
14
|
): Promise<IAutoBeTestScenarioArtifacts> {
|
|
15
|
+
const compiler: IAutoBeCompiler = await ctx.compiler();
|
|
11
16
|
const document: AutoBeOpenApi.IDocument = filterDocument(
|
|
12
17
|
scenario,
|
|
13
18
|
ctx.state().interface!.document,
|
|
14
19
|
);
|
|
15
20
|
const entries: [string, string][] = Object.entries(
|
|
16
|
-
await
|
|
21
|
+
await compiler.interface.write(document),
|
|
17
22
|
);
|
|
18
23
|
const filter = (prefix: string, exclude?: string) => {
|
|
19
24
|
const result: [string, string][] = entries.filter(
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
AutoBeTestHistory,
|
|
6
6
|
AutoBeTestScenarioEvent,
|
|
7
7
|
AutoBeTestValidateEvent,
|
|
8
|
+
IAutoBeCompiler,
|
|
8
9
|
IAutoBeTypeScriptCompileResult,
|
|
9
10
|
} from "@autobe/interface";
|
|
10
11
|
import { ILlmSchema } from "@samchon/openapi";
|
|
@@ -66,17 +67,18 @@ export const orchestrateTest =
|
|
|
66
67
|
);
|
|
67
68
|
|
|
68
69
|
// DO COMPILE
|
|
69
|
-
const
|
|
70
|
+
const compiler: IAutoBeCompiler = await ctx.compiler();
|
|
71
|
+
const result: AutoBeTestFile[] = success.map((c) => c.file);
|
|
70
72
|
const compiled: IAutoBeTypeScriptCompileResult =
|
|
71
|
-
await
|
|
72
|
-
files:
|
|
73
|
-
...Object.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
),
|
|
77
|
-
),
|
|
78
|
-
...
|
|
79
|
-
|
|
73
|
+
await compiler.typescript.compile({
|
|
74
|
+
files: Object.fromEntries([
|
|
75
|
+
...Object.entries(
|
|
76
|
+
await ctx.files({
|
|
77
|
+
dbms: "sqlite",
|
|
78
|
+
}),
|
|
79
|
+
).filter(([key]) => key.endsWith(".ts")),
|
|
80
|
+
...result.map((f) => [f.location, f.content]),
|
|
81
|
+
]),
|
|
80
82
|
});
|
|
81
83
|
|
|
82
84
|
const history: AutoBeTestHistory = {
|
|
@@ -84,7 +86,7 @@ export const orchestrateTest =
|
|
|
84
86
|
id: v4(),
|
|
85
87
|
completed_at: new Date().toISOString(),
|
|
86
88
|
created_at: start.toISOString(),
|
|
87
|
-
files,
|
|
89
|
+
files: result,
|
|
88
90
|
compiled,
|
|
89
91
|
reason: "Step to the test generation referencing the interface",
|
|
90
92
|
step: ctx.state().interface?.step ?? 0,
|
|
@@ -92,7 +94,7 @@ export const orchestrateTest =
|
|
|
92
94
|
ctx.dispatch({
|
|
93
95
|
type: "testComplete",
|
|
94
96
|
created_at: start.toISOString(),
|
|
95
|
-
files: Object.fromEntries(
|
|
97
|
+
files: Object.fromEntries(result.map((f) => [f.location, f.content])),
|
|
96
98
|
compiled,
|
|
97
99
|
step: ctx.state().interface?.step ?? 0,
|
|
98
100
|
});
|