@autobe/agent 0.11.2 → 0.12.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.d.ts +3 -146
- package/lib/AutoBeAgent.js +6 -180
- package/lib/AutoBeAgent.js.map +1 -1
- package/lib/AutoBeAgentBase.d.ts +18 -0
- package/lib/AutoBeAgentBase.js +54 -0
- package/lib/AutoBeAgentBase.js.map +1 -0
- package/lib/AutoBeMockAgent.d.ts +14 -0
- package/lib/AutoBeMockAgent.js +135 -0
- package/lib/AutoBeMockAgent.js.map +1 -0
- package/lib/constants/AutoBeSystemPromptConstant.d.ts +8 -4
- package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
- package/lib/factory/getAutoBeGenerated.d.ts +3 -4
- package/lib/factory/getAutoBeGenerated.js +6 -250
- package/lib/factory/getAutoBeGenerated.js.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +883 -399
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyze.js +6 -1
- package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.d.ts +4 -1
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js +6 -2
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealize.js +11 -2
- package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js +46 -15
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeDecorator.d.ts +10 -0
- package/lib/orchestrate/realize/orchestrateRealizeDecorator.js +545 -0
- package/lib/orchestrate/realize/orchestrateRealizeDecorator.js.map +1 -0
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.d.ts +12 -9
- package/lib/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.d.ts +85 -0
- package/lib/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.js +3 -0
- package/lib/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.js.map +1 -0
- package/lib/orchestrate/realize/transformRealizeCoderHistories.d.ts +1 -1
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js +24 -30
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -1
- package/lib/orchestrate/realize/transformRealizeDecorator.d.ts +4 -0
- package/lib/orchestrate/realize/transformRealizeDecorator.js +32 -0
- package/lib/orchestrate/realize/transformRealizeDecorator.js.map +1 -0
- package/lib/orchestrate/realize/transformRealizeDecoratorCorrectHistories.d.ts +6 -0
- package/lib/orchestrate/realize/transformRealizeDecoratorCorrectHistories.js +49 -0
- package/lib/orchestrate/realize/transformRealizeDecoratorCorrectHistories.js.map +1 -0
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js +30 -11
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestCorrect.js +2 -1
- package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
- package/lib/utils/backoffRetry.d.ts +18 -0
- package/lib/utils/backoffRetry.js +38 -0
- package/lib/utils/backoffRetry.js.map +1 -1
- package/package.json +8 -8
- package/src/AutoBeAgent.ts +10 -203
- package/src/AutoBeAgentBase.ts +78 -0
- package/src/AutoBeMockAgent.ts +163 -0
- package/src/constants/AutoBeSystemPromptConstant.ts +8 -4
- package/src/factory/getAutoBeGenerated.ts +8 -13
- package/src/index.ts +3 -1
- package/src/orchestrate/analyze/orchestrateAnalyze.ts +7 -1
- package/src/orchestrate/analyze/writeDocumentUntilReviewPassed.ts +8 -0
- package/src/orchestrate/realize/orchestrateRealize.ts +11 -0
- package/src/orchestrate/realize/orchestrateRealizeCoder.ts +26 -4
- package/src/orchestrate/realize/orchestrateRealizeDecorator.ts +286 -0
- package/src/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.ts +12 -9
- package/src/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.ts +94 -0
- package/src/orchestrate/realize/transformRealizeCoderHistories.ts +22 -29
- package/src/orchestrate/realize/transformRealizeDecorator.ts +37 -0
- package/src/orchestrate/realize/transformRealizeDecoratorCorrectHistories.ts +58 -0
- package/src/orchestrate/realize/writeCodeUntilCompilePassed.ts +34 -9
- package/src/orchestrate/test/orchestrateTest.ts +1 -0
- package/src/orchestrate/test/orchestrateTestCorrect.ts +1 -1
- package/src/utils/backoffRetry.ts +56 -0
|
@@ -3,23 +3,19 @@ import {
|
|
|
3
3
|
IAutoBeCompiler,
|
|
4
4
|
IAutoBeGetFilesOptions,
|
|
5
5
|
} from "@autobe/interface";
|
|
6
|
-
import { ILlmSchema } from "@samchon/openapi";
|
|
7
|
-
import typia from "typia";
|
|
8
6
|
|
|
9
|
-
import { AutoBeContext } from "../context/AutoBeContext";
|
|
10
7
|
import { AutoBeState } from "../context/AutoBeState";
|
|
11
8
|
import { AutoBeTokenUsage } from "../context/AutoBeTokenUsage";
|
|
12
9
|
|
|
13
|
-
export async function getAutoBeGenerated
|
|
14
|
-
|
|
10
|
+
export async function getAutoBeGenerated(
|
|
11
|
+
compiler: IAutoBeCompiler,
|
|
12
|
+
state: AutoBeState,
|
|
15
13
|
histories: AutoBeHistory[],
|
|
16
14
|
tokenUsage: AutoBeTokenUsage,
|
|
17
15
|
options?: Partial<IAutoBeGetFilesOptions>,
|
|
18
16
|
): Promise<Record<string, string>> {
|
|
19
|
-
const state: AutoBeState = ctx.state();
|
|
20
|
-
const ret: Record<string, string> = {};
|
|
21
|
-
|
|
22
17
|
// ANALYZE
|
|
18
|
+
const ret: Record<string, string> = {};
|
|
23
19
|
if (state.analyze === null) return {};
|
|
24
20
|
Object.assign<Record<string, string>, Record<string, string>>(
|
|
25
21
|
ret,
|
|
@@ -32,7 +28,6 @@ export async function getAutoBeGenerated<Model extends ILlmSchema.Model>(
|
|
|
32
28
|
);
|
|
33
29
|
|
|
34
30
|
// PRISMA
|
|
35
|
-
const compiler: IAutoBeCompiler = await ctx.compiler();
|
|
36
31
|
if (state.prisma?.step === state.analyze.step) {
|
|
37
32
|
const schemaFiles: Record<string, string> =
|
|
38
33
|
(options?.dbms ?? "postgres") === "postgres"
|
|
@@ -51,7 +46,7 @@ export async function getAutoBeGenerated<Model extends ILlmSchema.Model>(
|
|
|
51
46
|
]),
|
|
52
47
|
),
|
|
53
48
|
{
|
|
54
|
-
"autobe/prisma.json":
|
|
49
|
+
"autobe/prisma.json": JSON.stringify(state.prisma.result.data),
|
|
55
50
|
},
|
|
56
51
|
);
|
|
57
52
|
if (state.prisma.compiled.type === "success")
|
|
@@ -79,7 +74,7 @@ export async function getAutoBeGenerated<Model extends ILlmSchema.Model>(
|
|
|
79
74
|
)
|
|
80
75
|
: files,
|
|
81
76
|
{
|
|
82
|
-
"autobe/document.json":
|
|
77
|
+
"autobe/document.json": JSON.stringify(state.interface.document),
|
|
83
78
|
},
|
|
84
79
|
);
|
|
85
80
|
}
|
|
@@ -106,8 +101,8 @@ export async function getAutoBeGenerated<Model extends ILlmSchema.Model>(
|
|
|
106
101
|
|
|
107
102
|
// LOGGING
|
|
108
103
|
Object.assign<Record<string, string>, Record<string, string>>(ret, {
|
|
109
|
-
"autobe/histories.json":
|
|
110
|
-
"autobe/tokenUsage.json":
|
|
104
|
+
"autobe/histories.json": JSON.stringify(histories),
|
|
105
|
+
"autobe/tokenUsage.json": JSON.stringify(tokenUsage),
|
|
111
106
|
});
|
|
112
107
|
return ret;
|
|
113
108
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from "./AutoBeAgent";
|
|
2
|
-
|
|
3
2
|
export * from "./context/AutoBeTokenUsage";
|
|
4
3
|
|
|
5
4
|
export * from "./structures/IAutoBeProps";
|
|
@@ -11,3 +10,6 @@ export * as factory from "./factory";
|
|
|
11
10
|
|
|
12
11
|
/** @internal */
|
|
13
12
|
export * as orchestrate from "./orchestrate";
|
|
13
|
+
|
|
14
|
+
/** @internal */
|
|
15
|
+
export * from "./AutoBeMockAgent";
|
|
@@ -70,6 +70,11 @@ export const orchestrateAnalyze =
|
|
|
70
70
|
return history;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
const retryCount = 3 as const;
|
|
74
|
+
const progress = {
|
|
75
|
+
total: tableOfContents.length * retryCount,
|
|
76
|
+
completed: 0,
|
|
77
|
+
};
|
|
73
78
|
const pointers = await Promise.all(
|
|
74
79
|
tableOfContents.map(async ({ filename }) => {
|
|
75
80
|
const pointer: AutoBeAnalyzePointer = { value: { files: {} } };
|
|
@@ -79,7 +84,8 @@ export const orchestrateAnalyze =
|
|
|
79
84
|
tableOfContents,
|
|
80
85
|
filename,
|
|
81
86
|
roles,
|
|
82
|
-
|
|
87
|
+
progress,
|
|
88
|
+
retryCount,
|
|
83
89
|
);
|
|
84
90
|
return pointer;
|
|
85
91
|
}),
|
|
@@ -16,6 +16,7 @@ export async function writeDocumentUntilReviewPassed<
|
|
|
16
16
|
totalFiles: Pick<IFile, "filename" | "reason">[],
|
|
17
17
|
filename: string,
|
|
18
18
|
roles: AutoBeAnalyzeRole[],
|
|
19
|
+
progress: { total: number; completed: number },
|
|
19
20
|
retry = 3,
|
|
20
21
|
): Promise<AutoBeAnalyzePointer> {
|
|
21
22
|
const isAborted: IPointer<boolean> = { value: false };
|
|
@@ -38,16 +39,21 @@ export async function writeDocumentUntilReviewPassed<
|
|
|
38
39
|
pointer,
|
|
39
40
|
isAborted,
|
|
40
41
|
);
|
|
42
|
+
|
|
41
43
|
await writer.conversate(review ?? write).finally(() => {
|
|
42
44
|
const tokenUsage = writer.getTokenUsage();
|
|
43
45
|
ctx.usage().record(tokenUsage, ["analyze"]);
|
|
44
46
|
});
|
|
47
|
+
|
|
45
48
|
if (pointer.value === null) {
|
|
46
49
|
throw new Error("Failed to write document by unknown reason.");
|
|
47
50
|
}
|
|
51
|
+
|
|
48
52
|
ctx.dispatch({
|
|
49
53
|
type: "analyzeWrite",
|
|
50
54
|
files: pointer.value.files,
|
|
55
|
+
total: progress.total,
|
|
56
|
+
completed: ++progress.completed,
|
|
51
57
|
step: ctx.state().analyze?.step ?? 0,
|
|
52
58
|
created_at: new Date().toISOString(),
|
|
53
59
|
});
|
|
@@ -58,6 +64,8 @@ export async function writeDocumentUntilReviewPassed<
|
|
|
58
64
|
ctx.dispatch({
|
|
59
65
|
type: "analyzeReview",
|
|
60
66
|
review,
|
|
67
|
+
total: progress.total,
|
|
68
|
+
completed: progress.completed,
|
|
61
69
|
step: ctx.state().analyze?.step ?? 0,
|
|
62
70
|
created_at: new Date().toISOString(),
|
|
63
71
|
});
|
|
@@ -7,6 +7,7 @@ import { v4 } from "uuid";
|
|
|
7
7
|
|
|
8
8
|
import { AutoBeContext } from "../../context/AutoBeContext";
|
|
9
9
|
import { IAutoBeApplicationProps } from "../../context/IAutoBeApplicationProps";
|
|
10
|
+
import { orchestrateRealizeDecorator } from "./orchestrateRealizeDecorator";
|
|
10
11
|
import { writeCodeUntilCompilePassed } from "./writeCodeUntilCompilePassed";
|
|
11
12
|
|
|
12
13
|
export const orchestrateRealize =
|
|
@@ -20,6 +21,16 @@ export const orchestrateRealize =
|
|
|
20
21
|
throw new Error("Can't do realize agent because operations are nothing.");
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
ctx.dispatch({
|
|
25
|
+
type: "realizeStart",
|
|
26
|
+
created_at: new Date().toISOString(),
|
|
27
|
+
reason: props.reason,
|
|
28
|
+
step: ctx.state().test?.step ?? 0,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const decorators = await orchestrateRealizeDecorator(ctx);
|
|
32
|
+
decorators;
|
|
33
|
+
|
|
23
34
|
await writeCodeUntilCompilePassed(ctx, ops, 3);
|
|
24
35
|
const now = new Date().toISOString();
|
|
25
36
|
ctx.dispatch({
|
|
@@ -10,6 +10,10 @@ import typia from "typia";
|
|
|
10
10
|
|
|
11
11
|
import { AutoBeContext } from "../../context/AutoBeContext";
|
|
12
12
|
import { assertSchemaModel } from "../../context/assertSchemaModel";
|
|
13
|
+
import {
|
|
14
|
+
randomBackoffRetry,
|
|
15
|
+
randomBackoffStrategy,
|
|
16
|
+
} from "../../utils/backoffRetry";
|
|
13
17
|
import { enforceToolCall } from "../../utils/enforceToolCall";
|
|
14
18
|
import { getTestScenarioArtifacts } from "../test/compile/getTestScenarioArtifacts";
|
|
15
19
|
import { IAutoBeTestScenarioArtifacts } from "../test/structures/IAutoBeTestScenarioArtifacts";
|
|
@@ -50,6 +54,7 @@ export const orchestrateRealizeCoder = async <Model extends ILlmSchema.Model>(
|
|
|
50
54
|
>
|
|
51
55
|
| FAILED
|
|
52
56
|
> => {
|
|
57
|
+
total;
|
|
53
58
|
const artifacts: IAutoBeTestScenarioArtifacts =
|
|
54
59
|
await getTestScenarioArtifacts(ctx, {
|
|
55
60
|
endpoint: {
|
|
@@ -79,6 +84,7 @@ export const orchestrateRealizeCoder = async <Model extends ILlmSchema.Model>(
|
|
|
79
84
|
vendor: ctx.vendor,
|
|
80
85
|
config: {
|
|
81
86
|
...ctx.config,
|
|
87
|
+
backoffStrategy: randomBackoffStrategy,
|
|
82
88
|
executor: {
|
|
83
89
|
describe: null,
|
|
84
90
|
},
|
|
@@ -88,15 +94,31 @@ export const orchestrateRealizeCoder = async <Model extends ILlmSchema.Model>(
|
|
|
88
94
|
props,
|
|
89
95
|
artifacts,
|
|
90
96
|
previous,
|
|
91
|
-
total,
|
|
92
97
|
diagnostics,
|
|
93
98
|
),
|
|
94
99
|
});
|
|
95
100
|
enforceToolCall(agent);
|
|
96
101
|
|
|
97
|
-
await
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
await randomBackoffRetry(() =>
|
|
103
|
+
agent.conversate(
|
|
104
|
+
[
|
|
105
|
+
`Write complete, production-ready TypeScript code that strictly follows these rules:`,
|
|
106
|
+
"",
|
|
107
|
+
`1. Do **not** use the native \`Date\` type anywhere.`,
|
|
108
|
+
`2. All date or datetime values must be written as \`string & tags.Format<'date-time'>\`.`,
|
|
109
|
+
`3. UUIDs must be generated using \`v4()\` and typed as \`string & tags.Format<'uuid'>\`.`,
|
|
110
|
+
`4. Do not use \`as\` for type assertions — resolve types properly.`,
|
|
111
|
+
`5. All functions must be fully typed with clear parameter and return types.`,
|
|
112
|
+
`6. Do not skip validations or default values where necessary.`,
|
|
113
|
+
`7. Follow functional, immutable, and consistent code structure.`,
|
|
114
|
+
"",
|
|
115
|
+
`Use \`@nestia/e2e\` test structure if relevant.`,
|
|
116
|
+
].join("\n"),
|
|
117
|
+
),
|
|
118
|
+
).finally(() => {
|
|
119
|
+
const tokenUsage = agent.getTokenUsage();
|
|
120
|
+
ctx.usage().record(tokenUsage, ["realize"]);
|
|
121
|
+
});
|
|
100
122
|
|
|
101
123
|
if (pointer.value === null) {
|
|
102
124
|
return FAILED;
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { IAgenticaController, MicroAgentica } from "@agentica/core";
|
|
2
|
+
import {
|
|
3
|
+
AutoBeRealizeDecoratorEvent,
|
|
4
|
+
IAutoBeCompiler,
|
|
5
|
+
} from "@autobe/interface";
|
|
6
|
+
import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
|
|
7
|
+
import fs from "fs/promises";
|
|
8
|
+
import path from "path";
|
|
9
|
+
import { IPointer } from "tstl";
|
|
10
|
+
import typia from "typia";
|
|
11
|
+
|
|
12
|
+
import { AutoBeContext } from "../../context/AutoBeContext";
|
|
13
|
+
import { assertSchemaModel } from "../../context/assertSchemaModel";
|
|
14
|
+
import { enforceToolCall } from "../../utils/enforceToolCall";
|
|
15
|
+
import { IAutoBeRealizeDecoratorApplication } from "./structures/IAutoBeRealizeDecoratorApplication";
|
|
16
|
+
import { transformRealizeDecoratorHistories } from "./transformRealizeDecorator";
|
|
17
|
+
import { transformRealizeDecoratorCorrectHistories } from "./transformRealizeDecoratorCorrectHistories";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 1. Create decorator and its parameters. and design the Authorization Provider.
|
|
21
|
+
* 2. According to Authorization Provider design, create the Provider.
|
|
22
|
+
*
|
|
23
|
+
* @param ctx
|
|
24
|
+
*/
|
|
25
|
+
export async function orchestrateRealizeDecorator<
|
|
26
|
+
Model extends ILlmSchema.Model,
|
|
27
|
+
>(
|
|
28
|
+
ctx: AutoBeContext<Model>,
|
|
29
|
+
): Promise<IAutoBeRealizeDecoratorApplication.IProps[]> {
|
|
30
|
+
const roles =
|
|
31
|
+
ctx
|
|
32
|
+
.state()
|
|
33
|
+
.interface?.document.components.authorization?.map((auth) => auth.name) ??
|
|
34
|
+
[];
|
|
35
|
+
|
|
36
|
+
const decorators: IAutoBeRealizeDecoratorApplication.IProps[] = [];
|
|
37
|
+
|
|
38
|
+
let completed = 0;
|
|
39
|
+
|
|
40
|
+
const templateFiles = {
|
|
41
|
+
"src/MyGlobal.ts": await fs.readFile(
|
|
42
|
+
path.join(
|
|
43
|
+
__dirname,
|
|
44
|
+
"../../../../../internals/template/realize/src/MyGlobal.ts",
|
|
45
|
+
),
|
|
46
|
+
"utf-8",
|
|
47
|
+
),
|
|
48
|
+
"src/authentications/jwtAuthorize.ts": await fs.readFile(
|
|
49
|
+
path.join(
|
|
50
|
+
__dirname,
|
|
51
|
+
"../../../../../internals/template/realize/src/providers/jwtAuthorize.ts",
|
|
52
|
+
),
|
|
53
|
+
"utf-8",
|
|
54
|
+
),
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const files: Record<string, string> = {
|
|
58
|
+
...templateFiles,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
await Promise.all(
|
|
62
|
+
roles.map(async (role) => {
|
|
63
|
+
const decorator: IAutoBeRealizeDecoratorApplication.IProps =
|
|
64
|
+
await process(ctx, role, templateFiles);
|
|
65
|
+
|
|
66
|
+
files[`src/decorators/${decorator.decorator.name}.ts`] =
|
|
67
|
+
decorator.decorator.code;
|
|
68
|
+
files[`src/authentications/${decorator.provider.name}.ts`] =
|
|
69
|
+
decorator.provider.code;
|
|
70
|
+
files[`src/authentications/types/${decorator.decoratorType.name}.ts`] =
|
|
71
|
+
decorator.decoratorType.code;
|
|
72
|
+
|
|
73
|
+
decorators.push(decorator);
|
|
74
|
+
|
|
75
|
+
const events: AutoBeRealizeDecoratorEvent = {
|
|
76
|
+
type: "realizeDecorator",
|
|
77
|
+
created_at: new Date().toISOString(),
|
|
78
|
+
files,
|
|
79
|
+
completed: ++completed,
|
|
80
|
+
total: roles.length,
|
|
81
|
+
step: ctx.state().test?.step ?? 0,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
ctx.dispatch(events);
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
return decorators;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async function process<Model extends ILlmSchema.Model>(
|
|
92
|
+
ctx: AutoBeContext<Model>,
|
|
93
|
+
role: string,
|
|
94
|
+
templateFiles: Record<string, string>,
|
|
95
|
+
): Promise<IAutoBeRealizeDecoratorApplication.IProps> {
|
|
96
|
+
const pointer: IPointer<IAutoBeRealizeDecoratorApplication.IProps | null> = {
|
|
97
|
+
value: null,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const agentica: MicroAgentica<Model> = new MicroAgentica({
|
|
101
|
+
model: ctx.model,
|
|
102
|
+
vendor: ctx.vendor,
|
|
103
|
+
config: {
|
|
104
|
+
...(ctx.config ?? {}),
|
|
105
|
+
executor: {
|
|
106
|
+
describe: null,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
histories: transformRealizeDecoratorHistories(ctx, role),
|
|
110
|
+
controllers: [
|
|
111
|
+
createApplication({
|
|
112
|
+
model: ctx.model,
|
|
113
|
+
build: (next) => {
|
|
114
|
+
pointer.value = next;
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
117
|
+
],
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
enforceToolCall(agentica);
|
|
121
|
+
|
|
122
|
+
await agentica
|
|
123
|
+
.conversate("Create Authorization Provider and Decorator.")
|
|
124
|
+
.finally(() => {
|
|
125
|
+
const tokenUsage = agentica.getTokenUsage();
|
|
126
|
+
ctx.usage().record(tokenUsage, ["realize"]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
if (pointer.value === null) throw new Error("Failed to create decorator.");
|
|
130
|
+
|
|
131
|
+
const compiled = ctx.state().prisma?.compiled;
|
|
132
|
+
|
|
133
|
+
const prismaClients: Record<string, string> =
|
|
134
|
+
compiled?.type === "success" ? compiled.nodeModules : {};
|
|
135
|
+
|
|
136
|
+
return await correctDecorator(
|
|
137
|
+
ctx,
|
|
138
|
+
pointer.value,
|
|
139
|
+
prismaClients,
|
|
140
|
+
templateFiles,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function correctDecorator<Model extends ILlmSchema.Model>(
|
|
145
|
+
ctx: AutoBeContext<Model>,
|
|
146
|
+
result: IAutoBeRealizeDecoratorApplication.IProps,
|
|
147
|
+
prismaClients: Record<string, string>,
|
|
148
|
+
templateFiles: Record<string, string>,
|
|
149
|
+
life: number = 4,
|
|
150
|
+
): Promise<IAutoBeRealizeDecoratorApplication.IProps> {
|
|
151
|
+
// Check Compile
|
|
152
|
+
const files = {
|
|
153
|
+
...templateFiles,
|
|
154
|
+
...prismaClients,
|
|
155
|
+
[`src/decorators/${result.decorator.name}.ts`]: result.decorator.code,
|
|
156
|
+
[`src/authentications/${result.provider.name}.ts`]: result.provider.code,
|
|
157
|
+
[`src/authentications/types/${result.decoratorType.name}.ts`]:
|
|
158
|
+
result.decoratorType.code,
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const compiler: IAutoBeCompiler = await ctx.compiler();
|
|
162
|
+
|
|
163
|
+
const compiled = await compiler.typescript.compile({
|
|
164
|
+
files,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
ctx.dispatch({
|
|
168
|
+
type: "realizeDecoratorValidate",
|
|
169
|
+
created_at: new Date().toISOString(),
|
|
170
|
+
result: compiled,
|
|
171
|
+
files,
|
|
172
|
+
step: ctx.state().test?.step ?? 0,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
if (compiled.type === "success") {
|
|
176
|
+
return result;
|
|
177
|
+
} else if (compiled.type === "exception" || life === 0) {
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const pointer: IPointer<IAutoBeRealizeDecoratorApplication.IProps | null> = {
|
|
182
|
+
value: null,
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const agentica: MicroAgentica<Model> = new MicroAgentica({
|
|
186
|
+
model: ctx.model,
|
|
187
|
+
vendor: ctx.vendor,
|
|
188
|
+
config: {
|
|
189
|
+
...(ctx.config ?? {}),
|
|
190
|
+
executor: {
|
|
191
|
+
describe: null,
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
histories: transformRealizeDecoratorCorrectHistories(
|
|
195
|
+
ctx,
|
|
196
|
+
result,
|
|
197
|
+
templateFiles,
|
|
198
|
+
compiled.diagnostics,
|
|
199
|
+
),
|
|
200
|
+
controllers: [
|
|
201
|
+
createApplication({
|
|
202
|
+
model: ctx.model,
|
|
203
|
+
build: (next) => {
|
|
204
|
+
pointer.value = next;
|
|
205
|
+
},
|
|
206
|
+
}),
|
|
207
|
+
],
|
|
208
|
+
});
|
|
209
|
+
enforceToolCall(agentica);
|
|
210
|
+
|
|
211
|
+
await agentica
|
|
212
|
+
.conversate("Please correct the decorator and the provider.")
|
|
213
|
+
.finally(() => {
|
|
214
|
+
const tokenUsage = agentica.getTokenUsage();
|
|
215
|
+
ctx.usage().record(tokenUsage, ["realize"]);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
if (pointer.value === null) throw new Error("Failed to correct decorator.");
|
|
219
|
+
|
|
220
|
+
const correctedFiles: Record<string, string> = {
|
|
221
|
+
...files,
|
|
222
|
+
[`src/decorators/${pointer.value.decorator.name}.ts`]:
|
|
223
|
+
pointer.value.decorator.code,
|
|
224
|
+
[`src/authentications/${pointer.value.provider.name}.ts`]:
|
|
225
|
+
pointer.value.provider.code,
|
|
226
|
+
[`src/authentications/types/${pointer.value.decoratorType.name}.ts`]:
|
|
227
|
+
pointer.value.decoratorType.code,
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
ctx.dispatch({
|
|
231
|
+
type: "realizeDecoratorCorrect",
|
|
232
|
+
created_at: new Date().toISOString(),
|
|
233
|
+
files: correctedFiles,
|
|
234
|
+
result: compiled,
|
|
235
|
+
step: ctx.state().test?.step ?? 0,
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
return await correctDecorator(
|
|
239
|
+
ctx,
|
|
240
|
+
pointer.value,
|
|
241
|
+
prismaClients,
|
|
242
|
+
templateFiles,
|
|
243
|
+
life - 1,
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function createApplication<Model extends ILlmSchema.Model>(props: {
|
|
248
|
+
model: Model;
|
|
249
|
+
build: (next: IAutoBeRealizeDecoratorApplication.IProps) => void;
|
|
250
|
+
}): IAgenticaController.IClass<Model> {
|
|
251
|
+
assertSchemaModel(props.model);
|
|
252
|
+
|
|
253
|
+
const application: ILlmApplication<Model> = collection[
|
|
254
|
+
props.model
|
|
255
|
+
] as unknown as ILlmApplication<Model>;
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
protocol: "class",
|
|
259
|
+
name: "Create Decorator",
|
|
260
|
+
application,
|
|
261
|
+
execute: {
|
|
262
|
+
createDecorator: (next) => {
|
|
263
|
+
props.build(next);
|
|
264
|
+
},
|
|
265
|
+
} satisfies IAutoBeRealizeDecoratorApplication,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const claude = typia.llm.application<
|
|
270
|
+
IAutoBeRealizeDecoratorApplication,
|
|
271
|
+
"claude",
|
|
272
|
+
{
|
|
273
|
+
reference: true;
|
|
274
|
+
}
|
|
275
|
+
>();
|
|
276
|
+
const collection = {
|
|
277
|
+
chatgpt: typia.llm.application<
|
|
278
|
+
IAutoBeRealizeDecoratorApplication,
|
|
279
|
+
"chatgpt",
|
|
280
|
+
{ reference: true }
|
|
281
|
+
>(),
|
|
282
|
+
claude,
|
|
283
|
+
llama: claude,
|
|
284
|
+
deepseek: claude,
|
|
285
|
+
"3.1": claude,
|
|
286
|
+
};
|
|
@@ -32,7 +32,7 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
32
32
|
* logic.
|
|
33
33
|
*/
|
|
34
34
|
export interface RealizeCoderOutput {
|
|
35
|
-
/**
|
|
35
|
+
/** @ignore */
|
|
36
36
|
filename: string;
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -68,9 +68,9 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
68
68
|
*
|
|
69
69
|
* ⚠️ TypeScript-specific considerations:
|
|
70
70
|
*
|
|
71
|
-
* - Do **not** use native `Date` objects directly; convert all dates
|
|
72
|
-
* `.toISOString()`
|
|
73
|
-
*
|
|
71
|
+
* - Do **not** use native `Date` objects directly; always convert all dates
|
|
72
|
+
* to ISO strings with `.toISOString()` and brand as `string &
|
|
73
|
+
* tags.Format<'date-time'>`. This rule applies throughout all phases.
|
|
74
74
|
* - Prefer `satisfies` for DTO conformance instead of unsafe `as` casts
|
|
75
75
|
* - Avoid weak typing such as `any`, `as any`, or `satisfies any`
|
|
76
76
|
* - Use branded types (e.g., `tags.Format<'uuid'>`) and literal unions where
|
|
@@ -106,7 +106,7 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
106
106
|
* - Using `?? undefined` to normalize nullable fields.
|
|
107
107
|
* - Applying correct relation handling (e.g., `connect` instead of direct
|
|
108
108
|
* foreign key assignment).
|
|
109
|
-
* - Ensuring
|
|
109
|
+
* - Ensuring all date fields use `.toISOString()` and proper branding.
|
|
110
110
|
* - Include fallback or workaround plans if a direct fix is complex.
|
|
111
111
|
* - If no error is present, simply omit this section.
|
|
112
112
|
*
|
|
@@ -142,9 +142,10 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
142
142
|
*
|
|
143
143
|
* - Avoid using the `any` type at all costs to ensure type safety.
|
|
144
144
|
* - Do NOT assign native `Date` objects directly; always convert dates using
|
|
145
|
-
* `.toISOString()` before assignment.
|
|
145
|
+
* `.toISOString()` before assignment and apply proper branding.
|
|
146
146
|
* - Maintain a single-function structure; avoid using classes.
|
|
147
147
|
*/
|
|
148
|
+
draft_without_date_type: string;
|
|
148
149
|
|
|
149
150
|
/**
|
|
150
151
|
* 🔍 Phase 2: Review code
|
|
@@ -172,9 +173,11 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
172
173
|
*
|
|
173
174
|
* ✅ Must:
|
|
174
175
|
*
|
|
175
|
-
* -
|
|
176
|
+
* - Only include this field if TypeScript errors are detected in the Review
|
|
177
|
+
* phase.
|
|
178
|
+
* - Resolve all TypeScript errors without using `as any`.
|
|
176
179
|
* - Provide safe brand casting only if required (e.g., `as string &
|
|
177
|
-
* tags.Format<'uuid'>`)
|
|
180
|
+
* tags.Format<'uuid'>`).
|
|
178
181
|
*/
|
|
179
182
|
withCompilerFeedback?: string;
|
|
180
183
|
|
|
@@ -185,7 +188,7 @@ export namespace IAutoBeRealizeCoderApplication {
|
|
|
185
188
|
*
|
|
186
189
|
* - Passes strict type checking without errors.
|
|
187
190
|
* - Uses only safe branding or literal type assertions.
|
|
188
|
-
* - Converts all
|
|
191
|
+
* - Converts all date values properly to ISO string format.
|
|
189
192
|
* - Follows DTO structures using `satisfies`.
|
|
190
193
|
* - Avoids any weak typing such as `any`, `as any`, or `satisfies any`.
|
|
191
194
|
* - Uses only allowed imports (e.g., from `src/api/structures` and
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export interface IAutoBeRealizeDecoratorApplication {
|
|
2
|
+
createDecorator: (next: IAutoBeRealizeDecoratorApplication.IProps) => void;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export namespace IAutoBeRealizeDecoratorApplication {
|
|
6
|
+
export interface IProps {
|
|
7
|
+
/**
|
|
8
|
+
* Authentication Provider function configuration containing the function
|
|
9
|
+
* name and implementation code. The Provider handles JWT token
|
|
10
|
+
* verification, role validation, and database queries to authenticate
|
|
11
|
+
* users.
|
|
12
|
+
*/
|
|
13
|
+
provider: IAutoBeRealizeDecoratorApplication.IProvider;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Authentication Decorator configuration containing the decorator name and
|
|
17
|
+
* implementation code. The Decorator integrates with NestJS parameter
|
|
18
|
+
* decorators to automatically inject authenticated user data into
|
|
19
|
+
* Controller methods.
|
|
20
|
+
*/
|
|
21
|
+
decorator: IAutoBeRealizeDecoratorApplication.IDecorator;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Authentication Decorator Type configuration containing the decorator type
|
|
25
|
+
* name and implementation code. The Decorator Type is used to define the
|
|
26
|
+
* structure of the authenticated user data that will be injected into
|
|
27
|
+
* Controller methods when using the decorator. It serves as the TypeScript
|
|
28
|
+
* type for the parameter in Controller method signatures.
|
|
29
|
+
*/
|
|
30
|
+
decoratorType: IAutoBeRealizeDecoratorApplication.IDecoratorType;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface IProvider {
|
|
34
|
+
/**
|
|
35
|
+
* The name of the authentication Provider function in {role}Authorize
|
|
36
|
+
* format (e.g., adminAuthorize, userAuthorize). This function will be
|
|
37
|
+
* called by the decorator to verify JWT tokens and return authenticated
|
|
38
|
+
* user information for the specified role.
|
|
39
|
+
*/
|
|
40
|
+
name: string;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Complete TypeScript code for the authentication Provider function and its
|
|
44
|
+
* corresponding Payload interface. Must include: JWT token verification
|
|
45
|
+
* using jwtAuthorize function, role type checking against payload.type,
|
|
46
|
+
* database query using MyGlobal.prisma.{tableName} pattern to verify user
|
|
47
|
+
* existence, proper error handling with ForbiddenException and
|
|
48
|
+
* UnauthorizedException, and the Payload interface definition with id (UUID
|
|
49
|
+
* format) and type (role discriminator) fields using typia tags.
|
|
50
|
+
*/
|
|
51
|
+
code: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface IDecorator {
|
|
55
|
+
/**
|
|
56
|
+
* The name of the Decorator to be generated in {Role}Auth format (e.g.,
|
|
57
|
+
* AdminAuth, UserAuth). This decorator will be used as a parameter
|
|
58
|
+
* decorator in Controller methods to automatically authenticate and
|
|
59
|
+
* authorize users for the specific role, injecting the authenticated user
|
|
60
|
+
* payload as a method parameter.
|
|
61
|
+
*/
|
|
62
|
+
name: string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Complete TypeScript code for the authentication Decorator implementation.
|
|
66
|
+
* Must include: SwaggerCustomizer integration to add bearer token security
|
|
67
|
+
* schema to API documentation, createParamDecorator implementation that
|
|
68
|
+
* calls the corresponding Provider function for authentication, Singleton
|
|
69
|
+
* pattern using tstl library for efficient decorator instance management,
|
|
70
|
+
* and proper TypeScript typing for the ParameterDecorator interface.
|
|
71
|
+
*/
|
|
72
|
+
code: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface IDecoratorType {
|
|
76
|
+
/**
|
|
77
|
+
* The name of the Decorator to be generated in {Role}Auth format (e.g.,
|
|
78
|
+
* AdminAuth, UserAuth). This decorator will be used as a parameter
|
|
79
|
+
* decorator in Controller methods to automatically authenticate and
|
|
80
|
+
* authorize users for the specific role, injecting the authenticated user
|
|
81
|
+
* payload as a method parameter.
|
|
82
|
+
*/
|
|
83
|
+
name: string;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The TypeScript code for the Payload type in {Role}Payload format (e.g.,
|
|
87
|
+
* AdminPayload, UserPayload). This interface defines the structure of the
|
|
88
|
+
* authenticated user data that will be injected into Controller methods
|
|
89
|
+
* when using the decorator. It serves as the TypeScript type for the
|
|
90
|
+
* parameter in Controller method signatures.
|
|
91
|
+
*/
|
|
92
|
+
code: string;
|
|
93
|
+
}
|
|
94
|
+
}
|