From 906a304771945accb1353b75f4b8c3511f3f192d Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Mon, 14 Jul 2025 18:29:03 +0900 Subject: [PATCH 01/17] chore: add jwtAuthorize template code --- .../template/src/providers/jwtAuthorize.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 internals/template/src/providers/jwtAuthorize.ts diff --git a/internals/template/src/providers/jwtAuthorize.ts b/internals/template/src/providers/jwtAuthorize.ts new file mode 100644 index 0000000000..becc03d719 --- /dev/null +++ b/internals/template/src/providers/jwtAuthorize.ts @@ -0,0 +1,32 @@ +import { ForbiddenException, UnauthorizedException } from "@nestjs/common"; +import jwt from "jsonwebtoken"; + +import { MyGlobal } from "../MyGlobal"; + +export function jwtAuthorize(props: { + request: { + headers: { authorization?: string }; + }; +}) { + if (!props.request.headers.authorization) + throw new ForbiddenException("No token value exists"); + else if ( + props.request.headers.authorization.startsWith(BEARER_PREFIX) === false + ) + throw new UnauthorizedException("Invalid token"); + + // PARSE TOKEN + try { + const token: string = props.request.headers.authorization.substring( + BEARER_PREFIX.length, + ); + + const verified = jwt.verify(token, MyGlobal.env.JWT_SECRET_KEY); + + return verified; + } catch { + throw new UnauthorizedException("Invalid token"); + } +} + +const BEARER_PREFIX = "Bearer "; From dc74a143614d2c4a1ff3ecb71675a910c64bd1ec Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Mon, 14 Jul 2025 18:50:10 +0900 Subject: [PATCH 02/17] chore: define AutoBeRealizeDecoratorEvent --- packages/interface/src/events/AutoBeEvent.ts | 3 +++ .../interface/src/events/AutoBeRealizeDecoratorEvent.ts | 6 ++++++ packages/interface/src/events/index.ts | 1 + packages/interface/src/rpc/IAutoBeRpcListener.ts | 9 +++++++++ .../src/movies/events/AutoBePlaygroundEventMovie.tsx | 1 + .../movies/events/AutoBePlaygroundProgressEventMovie.tsx | 4 ++++ .../movies/events/AutoBePlaygroundStartEventMovie.tsx | 6 +++++- .../src/structures/AutoBePlaygroundListener.ts | 3 +++ 8 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts diff --git a/packages/interface/src/events/AutoBeEvent.ts b/packages/interface/src/events/AutoBeEvent.ts index 89875649f8..6319dab87d 100644 --- a/packages/interface/src/events/AutoBeEvent.ts +++ b/packages/interface/src/events/AutoBeEvent.ts @@ -16,6 +16,7 @@ import { AutoBePrismaSchemasEvent } from "./AutoBePrismaSchemasEvent"; import { AutoBePrismaStartEvent } from "./AutoBePrismaStartEvent"; import { AutoBePrismaValidateEvent } from "./AutoBePrismaValidateEvent"; import { AutoBeRealizeCompleteEvent } from "./AutoBeRealizeCompleteEvent"; +import { AutoBeRealizeDecoratorEvent } from "./AutoBeRealizeDecoratorEvent"; import { AutoBeRealizeProgressEvent } from "./AutoBeRealizeProgressEvent"; import { AutoBeRealizeStartEvent } from "./AutoBeRealizeStartEvent"; import { AutoBeRealizeValidateEvent } from "./AutoBeRealizeValidateEvent"; @@ -75,6 +76,7 @@ export type AutoBeEvent = | AutoBeTestCorrectEvent | AutoBeTestCompleteEvent | AutoBeRealizeStartEvent + | AutoBeRealizeDecoratorEvent | AutoBeRealizeProgressEvent | AutoBeRealizeValidateEvent | AutoBeRealizeCompleteEvent; @@ -139,6 +141,7 @@ export namespace AutoBeEvent { testCorrect: AutoBeTestCorrectEvent; testComplete: AutoBeTestCompleteEvent; realizeStart: AutoBeRealizeStartEvent; + realizeDecorator: AutoBeRealizeDecoratorEvent; realizeProgress: AutoBeRealizeProgressEvent; realizeValidate: AutoBeRealizeValidateEvent; realizeComplete: AutoBeRealizeCompleteEvent; diff --git a/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts b/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts new file mode 100644 index 0000000000..48e6068fd1 --- /dev/null +++ b/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts @@ -0,0 +1,6 @@ +import { AutoBeEventBase } from "./AutoBeEventBase"; + +export interface AutoBeRealizeDecoratorEvent + extends AutoBeEventBase<"realizeDecorator"> { + files: Record; +} diff --git a/packages/interface/src/events/index.ts b/packages/interface/src/events/index.ts index 68f1e13114..585f90f74e 100644 --- a/packages/interface/src/events/index.ts +++ b/packages/interface/src/events/index.ts @@ -30,6 +30,7 @@ export * from "./AutoBeTestCorrectEvent"; export * from "./AutoBeTestCompleteEvent"; export * from "./AutoBeRealizeStartEvent"; +export * from "./AutoBeRealizeDecoratorEvent"; export * from "./AutoBeRealizeProgressEvent"; export * from "./AutoBeRealizeValidateEvent"; export * from "./AutoBeRealizeCompleteEvent"; diff --git a/packages/interface/src/rpc/IAutoBeRpcListener.ts b/packages/interface/src/rpc/IAutoBeRpcListener.ts index f2cfebef27..28b16ebe57 100644 --- a/packages/interface/src/rpc/IAutoBeRpcListener.ts +++ b/packages/interface/src/rpc/IAutoBeRpcListener.ts @@ -17,6 +17,7 @@ import { AutoBePrismaStartEvent, AutoBePrismaValidateEvent, AutoBeRealizeCompleteEvent, + AutoBeRealizeDecoratorEvent, AutoBeRealizeProgressEvent, AutoBeRealizeStartEvent, AutoBeRealizeValidateEvent, @@ -294,6 +295,14 @@ export interface IAutoBeRpcListener { */ realizeStart?(event: AutoBeRealizeStartEvent): Promise; + /** + * Optional handler for decorator generation events. + * + * Called when the Realize agent begins generating decorators, enabling client + * applications to indicate the start of the decorator generation phase. + */ + realizeDecorator?(event: AutoBeRealizeDecoratorEvent): Promise; + /** * Optional handler for implementation progress events. * diff --git a/packages/playground-ui/src/movies/events/AutoBePlaygroundEventMovie.tsx b/packages/playground-ui/src/movies/events/AutoBePlaygroundEventMovie.tsx index 91dc2d88ec..2d961b77e2 100644 --- a/packages/playground-ui/src/movies/events/AutoBePlaygroundEventMovie.tsx +++ b/packages/playground-ui/src/movies/events/AutoBePlaygroundEventMovie.tsx @@ -40,6 +40,7 @@ export function AutoBePlaygroundEventMovie( case "testScenario": case "testCorrect": case "testValidate": + case "realizeDecorator": case "realizeValidate": return ; // COMPLETE EVENTS diff --git a/packages/playground-ui/src/movies/events/AutoBePlaygroundProgressEventMovie.tsx b/packages/playground-ui/src/movies/events/AutoBePlaygroundProgressEventMovie.tsx index 1218c33f24..663e15955e 100644 --- a/packages/playground-ui/src/movies/events/AutoBePlaygroundProgressEventMovie.tsx +++ b/packages/playground-ui/src/movies/events/AutoBePlaygroundProgressEventMovie.tsx @@ -7,6 +7,7 @@ import { AutoBeInterfaceOperationsEvent, AutoBePrismaComponentsEvent, AutoBePrismaSchemasEvent, + AutoBeRealizeDecoratorEvent, AutoBeRealizeProgressEvent, AutoBeRealizeValidateEvent, AutoBeTestCorrectEvent, @@ -37,6 +38,7 @@ export namespace AutoBePlaygroundProgressEventMovie { | AutoBeInterfaceComplementEvent | AutoBeTestScenarioEvent | AutoBeTestWriteEvent + | AutoBeRealizeDecoratorEvent | AutoBeTestValidateEvent | AutoBeTestCorrectEvent | AutoBeRealizeProgressEvent @@ -72,6 +74,8 @@ function getDescription( return `Validating Test Function: ${event.result.type}`; case "testCorrect": return `Correcting Test Function`; + case "realizeDecorator": + return `Generating Decorators`; case "realizeValidate": return `Validating Realize Function: ${event.result.type}`; case "realizeProgress": diff --git a/packages/playground-ui/src/movies/events/AutoBePlaygroundStartEventMovie.tsx b/packages/playground-ui/src/movies/events/AutoBePlaygroundStartEventMovie.tsx index 9fe0c97860..06d731b4f7 100644 --- a/packages/playground-ui/src/movies/events/AutoBePlaygroundStartEventMovie.tsx +++ b/packages/playground-ui/src/movies/events/AutoBePlaygroundStartEventMovie.tsx @@ -2,6 +2,7 @@ import { AutoBeAnalyzeStartEvent, AutoBeInterfaceStartEvent, AutoBePrismaStartEvent, + AutoBeRealizeDecoratorEvent, AutoBeRealizeStartEvent, AutoBeTestStartEvent, } from "@autobe/interface"; @@ -42,7 +43,8 @@ export namespace AutoBePlaygroundStartEventMovie { | AutoBePrismaStartEvent | AutoBeInterfaceStartEvent | AutoBeTestStartEvent - | AutoBeRealizeStartEvent; + | AutoBeRealizeStartEvent + | AutoBeRealizeDecoratorEvent; } } @@ -60,6 +62,8 @@ function getTitle( return "Test"; case "realizeStart": return "Realize"; + case "realizeDecorator": + return "Realize Decorator"; default: event satisfies never; throw new Error("Unknown event type"); // unreachable diff --git a/packages/playground-ui/src/structures/AutoBePlaygroundListener.ts b/packages/playground-ui/src/structures/AutoBePlaygroundListener.ts index ef96e19326..b5989ea7c9 100644 --- a/packages/playground-ui/src/structures/AutoBePlaygroundListener.ts +++ b/packages/playground-ui/src/structures/AutoBePlaygroundListener.ts @@ -87,6 +87,9 @@ export class AutoBePlaygroundListener { realizeStart: async (event) => { this.callback?.(event); }, + realizeDecorator: async (event) => { + this.callback?.(event); + }, realizeProgress: async (event) => { this.callback?.(event); }, From aeabe836baa5ddbb34ddb92a62cf5c5eac666e7c Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Mon, 14 Jul 2025 18:51:21 +0900 Subject: [PATCH 03/17] docs: define REALIZE DECORATOR system prompt --- packages/agent/prompts/REALIZE_DECORATOR.md | 197 ++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 packages/agent/prompts/REALIZE_DECORATOR.md diff --git a/packages/agent/prompts/REALIZE_DECORATOR.md b/packages/agent/prompts/REALIZE_DECORATOR.md new file mode 100644 index 0000000000..aa05eec00c --- /dev/null +++ b/packages/agent/prompts/REALIZE_DECORATOR.md @@ -0,0 +1,197 @@ +# NestJS Authentication Provider & Decorator Generation AI Agent + +You are a world-class NestJS expert and TypeScript developer. Your role is to automatically generate Provider functions and Decorators for JWT authentication based on given Role information and Prisma Client Types. + +## Core Mission + +Generate authentication Provider and Decorator code specialized for specific Roles based on Role information provided by users. + +## Input Information + +- **Role Name**: The authentication role to generate (e.g., admin, user, manager, etc.) +- **Prisma Client Type**: Database table information associated with the Role + +## Code Generation Rules + +### 1. Provider Function Generation Rules + +- Function name: `{role}Authorize` format (e.g., adminAuthorize, userAuthorize) +- Must use the `jwtAuthorize` function for JWT token verification +- Verify payload type and check if `payload.type` matches the correct role +- Query database using `MyGlobal.prisma.{tableName}` format +- Verify that the user actually exists in the database +- Function return type should be `{Role}Payload` interface + +### 2. Payload Interface Generation Rules + +- Interface name: `{Role}Payload` format (e.g., AdminPayload, UserPayload) +- Required fields: + - `id: string & tags.Format<"uuid">`: User ID (UUID format) + - `type: "{role}"`: Discriminator for role identification +- Additional fields should be generated according to Role characteristics + +### 3. Decorator Generation Rules + +- Decorator name: `{Role}Auth` format (e.g., AdminAuth, UserAuth) +- Use SwaggerCustomizer to add bearer token security schema to API documentation +- Use createParamDecorator to implement actual authentication logic +- Use Singleton pattern to manage decorator instances + +### 4. Code Style and Structure + +- Comply with TypeScript strict mode +- Utilize NestJS Exception classes (ForbiddenException, UnauthorizedException) +- Ensure type safety using typia tags +- Add appropriate JSDoc comments + +## Reference Functions and Examples + +### JWT Authentication Function + +```typescript +// jwtAuthorize.ts +import { ForbiddenException, UnauthorizedException } from "@nestjs/common"; +import jwt from "jsonwebtoken"; + +import { MyGlobal } from "../MyGlobal"; + +export function jwtAuthorize(props: { + request: { + headers: { authorization?: string }; + }; +}) { + if (!props.request.headers.authorization) + throw new ForbiddenException("No token value exists"); + else if ( + props.request.headers.authorization.startsWith(BEARER_PREFIX) === false + ) + throw new UnauthorizedException("Invalid token"); + + // PARSE TOKEN + try { + const token: string = props.request.headers.authorization.substring( + BEARER_PREFIX.length, + ); + + const verified = jwt.verify(token, MyGlobal.env.JWT_SECRET_KEY); + + return verified; + } catch { + throw new UnauthorizedException("Invalid token"); + } +} + +const BEARER_PREFIX = "Bearer "; +``` + +### Provider Function Example + +```typescript +import { ForbiddenException } from "@nestjs/common"; +import { tags } from "typia"; + +import { MyGlobal } from "../MyGlobal"; +import { jwtAuthorize } from "./JwtTokenProvider"; + +export async function adminAuthorize(request: { + headers: { + authorization?: string; + }; +}): Promise { + const payload: AdminPayload = jwtAuthorize({ request }) as AdminPayload; + + if (payload.type !== "admin") { + throw new ForbiddenException(`You're not ${payload.type}`); + } + + const admin = await MyGlobal.prisma.admin.findFirst({ + where: { + id: payload.id, + }, + }); + + if (admin === null) { + throw new ForbiddenException("You're not enrolled"); + } + + return payload; +} + +export interface AdminPayload { + /** + * User ID. + */ + id: string & tags.Format<"uuid">; + /** + * Discriminator for the discriminated union type. + */ + type: "admin"; +} +``` + +### Decorator Example + +```typescript +import { SwaggerCustomizer } from "@nestia/core"; +import { ExecutionContext, createParamDecorator } from "@nestjs/common"; +import { Singleton } from "tstl"; + +import { adminAuthorize } from "./AdminProvider"; + +export const AdminAuth = + (): ParameterDecorator => + ( + target: object, + propertyKey: string | symbol | undefined, + parameterIndex: number, + ): void => { + SwaggerCustomizer((props) => { + props.route.security ??= []; + props.route.security.push({ + bearer: [], + }); + })(target, propertyKey as string, undefined!); + singleton.get()(target, propertyKey, parameterIndex); + }; + +const singleton = new Singleton(() => + createParamDecorator(async (_0: unknown, ctx: ExecutionContext) => { + const request = ctx.switchToHttp().getRequest(); + return adminAuthorize(request); + })(), +); +``` + +## Output Format + +You must provide your response in a structured JSON format containing the following nested structure: + +**provider**: An object containing the authentication Provider function configuration + +- **name**: The name of the authentication Provider function in `{role}Authorize` format (e.g., adminAuthorize, userAuthorize). This function verifies JWT tokens and returns user information for the specified role. +- **code**: Complete TypeScript code for the authentication Provider function and its corresponding Payload interface. Must include JWT verification, role checking, database query logic, and the Payload interface definition. + +**decorator**: An object containing the authentication Decorator configuration + +- **name**: The name of the Decorator to be generated in `{Role}Auth` format (e.g., AdminAuth, UserAuth). The decorator name used in Controller method parameters. +- **typeName**: The name of the Payload type in `{Role}Payload` format (e.g., AdminPayload, UserPayload). Used as the parameter type when using decorators in Controllers. +- **code**: Complete TypeScript code for the Decorator. Must include complete authentication decorator implementation using SwaggerCustomizer, createParamDecorator, and Singleton pattern. + +## Work Process + +1. Analyze the input Role name +2. Generate Provider function for the Role +3. Define Payload interface +4. Implement Decorator +5. Verify that all code follows example patterns +6. Generate response in specified format + +## Quality Standards + +- Ensure type safety +- Follow NestJS conventions +- Complete error handling +- Code reusability +- Complete documentation + +When users provide Role information, generate complete and practical authentication code according to the above rules. \ No newline at end of file From a8fb75ea01a2c5abd8b33cc65ac6df818969891a Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Mon, 14 Jul 2025 18:52:06 +0900 Subject: [PATCH 04/17] feat: Realize Decorator Draft --- .../orchestrate/realize/orchestrateRealize.ts | 27 +++ .../realize/orchestrateRealizeDecorator.ts | 200 ++++++++++++++++++ .../IAutoBeRealizeDecoratorApplication.ts | 74 +++++++ .../realize/transformRealizeDecorator.ts | 30 +++ 4 files changed, 331 insertions(+) create mode 100644 packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts create mode 100644 packages/agent/src/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.ts create mode 100644 packages/agent/src/orchestrate/realize/transformRealizeDecorator.ts diff --git a/packages/agent/src/orchestrate/realize/orchestrateRealize.ts b/packages/agent/src/orchestrate/realize/orchestrateRealize.ts index 52ad1921d0..00d59375ce 100644 --- a/packages/agent/src/orchestrate/realize/orchestrateRealize.ts +++ b/packages/agent/src/orchestrate/realize/orchestrateRealize.ts @@ -9,8 +9,10 @@ import { v4 } from "uuid"; import { AutoBeContext } from "../../context/AutoBeContext"; import { IAutoBeApplicationProps } from "../../context/IAutoBeApplicationProps"; import { orchestrateRealizeCoder } from "./orchestrateRealizeCoder"; +import { orchestrateRealizeDecorator } from "./orchestrateRealizeDecorator"; import { orchestrateRealizePlanner } from "./orchestrateRealizePlanner"; import { IAutoBeRealizeCoderApplication } from "./structures/IAutoBeRealizeCoderApplication"; +import { IAutoBeRealizeDecoratorApplication } from "./structures/IAutoBeRealizeDecoratorApplication"; export const orchestrateRealize = (ctx: AutoBeContext) => @@ -23,6 +25,31 @@ export const orchestrateRealize = throw new Error(); } + ops.forEach((op, i) => { + if (!op.authorization?.role) { + op.authorization = { + role: [], + type: "Bearer", + }; + } + + if (i === 1) op.authorization.role.push("user"); + if (i === 2) op.authorization.role.push("admin"); + if (i === 3) op.authorization.role.push("moderator"); + }); + + ctx.dispatch({ + type: "realizeStart", + created_at: new Date().toISOString(), + reason: props.reason, + step: ctx.state().test?.step ?? 0, + }); + + const decorators: IAutoBeRealizeDecoratorApplication.IProps[] = + await orchestrateRealizeDecorator(ctx); + + decorators; + const files: Record = { ...ctx.state().interface?.files, ...ctx.state().test?.files.reduce( diff --git a/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts b/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts new file mode 100644 index 0000000000..c5308f9ccf --- /dev/null +++ b/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts @@ -0,0 +1,200 @@ +import { IAgenticaController, MicroAgentica } from "@agentica/core"; +import { AutoBeRealizeDecoratorEvent } from "@autobe/interface"; +import { ILlmApplication, ILlmSchema } from "@samchon/openapi"; +import { IPointer } from "tstl"; +import typia from "typia"; + +import { AutoBeContext } from "../../context/AutoBeContext"; +import { assertSchemaModel } from "../../context/assertSchemaModel"; +import { enforceToolCall } from "../../utils/enforceToolCall"; +import { IAutoBeRealizeDecoratorApplication } from "./structures/IAutoBeRealizeDecoratorApplication"; +import { transformRealizeDecoratorHistories } from "./transformRealizeDecorator"; + +/** + * 1. Create decorator and its parameters. and design the Authorization Provider. + * 2. According to Authorization Provider design, create the Provider. + * + * @param ctx + */ +export async function orchestrateRealizeDecorator< + Model extends ILlmSchema.Model, +>( + ctx: AutoBeContext, +): Promise { + const compiled = ctx.state().prisma?.compiled; + + const prismaClients: Record = + compiled?.type === "success" ? compiled.nodeModules : {}; + + const roles = Array.from( + new Set( + ctx + .state() + .interface?.document.operations.map( + (operation) => operation.authorization?.role, + ) + .flat() + .filter((role) => role !== undefined), + ), + ); + + const result: Record = {}; + const decorators: IAutoBeRealizeDecoratorApplication.IProps[] = []; + + for (const role of roles) { + const decorator: IAutoBeRealizeDecoratorApplication.IProps = await process( + ctx, + role, + prismaClients, + ); + + result[`src/decorators/${decorator.decorator.name}.ts`] = + decorator.decorator.code; + result[`src/authentications/${decorator.provider.name}.ts`] = + decorator.provider.code; + + decorators.push(decorator); + } + + const events: AutoBeRealizeDecoratorEvent = { + type: "realizeDecorator", + created_at: new Date().toISOString(), + files: result, + }; + + ctx.dispatch(events); + + return decorators; +} + +async function process( + ctx: AutoBeContext, + role: string, + prismaClients: Record, +): Promise { + const pointer: IPointer = { + value: null, + }; + + const agentica: MicroAgentica = new MicroAgentica({ + model: ctx.model, + vendor: ctx.vendor, + config: { + ...(ctx.config ?? {}), + executor: { + describe: null, + }, + }, + histories: transformRealizeDecoratorHistories(role, prismaClients), + controllers: [ + createApplication({ + model: ctx.model, + build: (next) => { + pointer.value = next; + }, + }), + ], + }); + + enforceToolCall(agentica); + + await agentica + .conversate("Create Authorization Provider and Decorator.") + .finally(() => { + const tokenUsage = agentica.getTokenUsage(); + ctx.usage().record(tokenUsage, ["realize"]); + }); + + if (pointer.value === null) throw new Error("Failed to create decorator."); + + return pointer.value; +} + +function createApplication(props: { + model: Model; + build: (next: IAutoBeRealizeDecoratorApplication.IProps) => void; +}): IAgenticaController.IClass { + assertSchemaModel(props.model); + + const application: ILlmApplication = collection[ + props.model + ] as unknown as ILlmApplication; + + return { + protocol: "class", + name: "Create Decorator", + application, + execute: { + createDecorator: (next) => { + props.build(next); + }, + } satisfies IAutoBeRealizeDecoratorApplication, + }; +} + +const claude = typia.llm.application< + IAutoBeRealizeDecoratorApplication, + "claude", + { + reference: true; + } +>(); +const collection = { + chatgpt: typia.llm.application< + IAutoBeRealizeDecoratorApplication, + "chatgpt", + { reference: true } + >(), + claude, + llama: claude, + deepseek: claude, + "3.1": claude, +}; + +// interface IAutoBeRealizeDecoratorApplication.IProps { +// /** +// * The name of the authentication Provider function in {role}Authorize format +// * (e.g., adminAuthorize, userAuthorize). This function verifies JWT tokens +// * and returns user information for the specified role. It should handle JWT +// * validation, role verification, and database queries to ensure the user +// * exists and has proper permissions. +// */ +// providerFunctionName: string; + +// /** +// * The name of the Payload type in {Role}Payload format (e.g., AdminPayload, +// * UserPayload). This interface defines the structure of the authenticated +// * user data that will be used as the parameter type when using decorators in +// * Controllers. Must include 'id' (UUID format) and 'type' (role +// * discriminator) fields. +// */ +// decoratorTypeName: string; + +// /** +// * Complete TypeScript code for the authentication Provider function and its +// * corresponding Payload interface. Must include: JWT token verification using +// * jwtAuthorize function, role type checking, database query using +// * MyGlobal.prisma.{tableName} pattern, proper error handling with NestJS +// * exceptions, and the Payload interface definition with appropriate typia +// * tags for type safety. +// */ +// provider: string; + +// /** +// * The name of the Decorator to be generated in {Role}Auth format (e.g., +// * AdminAuth, UserAuth). This decorator will be used as a parameter decorator +// * in Controller methods to automatically authenticate and authorize users for +// * the specific role, injecting the authenticated user payload. +// */ +// decoratorName: string; + +// /** +// * Complete TypeScript code for the authentication Decorator implementation. +// * Must include: SwaggerCustomizer integration for API documentation with +// * bearer token security, createParamDecorator implementation for the actual +// * authentication logic, Singleton pattern for efficient decorator instance +// * management, and proper integration with the corresponding Provider +// * function. +// */ +// decorator: string; +// } diff --git a/packages/agent/src/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.ts b/packages/agent/src/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.ts new file mode 100644 index 0000000000..33826a6480 --- /dev/null +++ b/packages/agent/src/orchestrate/realize/structures/IAutoBeRealizeDecoratorApplication.ts @@ -0,0 +1,74 @@ +export interface IAutoBeRealizeDecoratorApplication { + createDecorator: (next: IAutoBeRealizeDecoratorApplication.IProps) => void; +} + +export namespace IAutoBeRealizeDecoratorApplication { + export interface IProps { + /** + * Authentication Provider function configuration containing the function + * name and implementation code. The Provider handles JWT token + * verification, role validation, and database queries to authenticate + * users. + */ + provider: IAutoBeRealizeDecoratorApplication.IProvider; + + /** + * Authentication Decorator configuration containing the decorator name, + * payload type, and implementation code. The Decorator integrates with + * NestJS parameter decorators to automatically inject authenticated user + * data into Controller methods. + */ + decorator: IAutoBeRealizeDecoratorApplication.IDecorator; + } + + export interface IProvider { + /** + * The name of the authentication Provider function in {role}Authorize + * format (e.g., adminAuthorize, userAuthorize). This function will be + * called by the decorator to verify JWT tokens and return authenticated + * user information for the specified role. + */ + name: string; + + /** + * Complete TypeScript code for the authentication Provider function and its + * corresponding Payload interface. Must include: JWT token verification + * using jwtAuthorize function, role type checking against payload.type, + * database query using MyGlobal.prisma.{tableName} pattern to verify user + * existence, proper error handling with ForbiddenException and + * UnauthorizedException, and the Payload interface definition with id (UUID + * format) and type (role discriminator) fields using typia tags. + */ + code: string; + } + + export interface IDecorator { + /** + * The name of the Decorator to be generated in {Role}Auth format (e.g., + * AdminAuth, UserAuth). This decorator will be used as a parameter + * decorator in Controller methods to automatically authenticate and + * authorize users for the specific role, injecting the authenticated user + * payload as a method parameter. + */ + name: string; + + /** + * The name of the Payload type in {Role}Payload format (e.g., AdminPayload, + * UserPayload). This interface defines the structure of the authenticated + * user data that will be injected into Controller methods when using the + * decorator. It serves as the TypeScript type for the parameter in + * Controller method signatures. + */ + typeName: string; + + /** + * Complete TypeScript code for the authentication Decorator implementation. + * Must include: SwaggerCustomizer integration to add bearer token security + * schema to API documentation, createParamDecorator implementation that + * calls the corresponding Provider function for authentication, Singleton + * pattern using tstl library for efficient decorator instance management, + * and proper TypeScript typing for the ParameterDecorator interface. + */ + code: string; + } +} diff --git a/packages/agent/src/orchestrate/realize/transformRealizeDecorator.ts b/packages/agent/src/orchestrate/realize/transformRealizeDecorator.ts new file mode 100644 index 0000000000..8250fe1aed --- /dev/null +++ b/packages/agent/src/orchestrate/realize/transformRealizeDecorator.ts @@ -0,0 +1,30 @@ +import { IAgenticaHistoryJson } from "@agentica/core"; +import { v4 } from "uuid"; + +import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant"; + +export const transformRealizeDecoratorHistories = ( + role: string, + prismaClients: Record, +): Array< + IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage +> => { + return [ + { + id: v4(), + created_at: new Date().toISOString(), + type: "systemMessage", + text: AutoBeSystemPromptConstant.REALIZE_DECORATOR, + }, + { + id: v4(), + created_at: new Date().toISOString(), + type: "systemMessage", + text: [ + "Create Authorization Provider.", + "The role is " + role, + "The Prisma Clients are " + Object.keys(prismaClients).join(", "), + ].join("\n"), + }, + ]; +}; From fc7be11195826c47897598e8ccf117967fea5345 Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Tue, 15 Jul 2025 12:35:33 +0900 Subject: [PATCH 05/17] chore: fix the AutoBeRealizeDecoratorEvent --- .../src/orchestrate/realize/orchestrateRealizeDecorator.ts | 5 +++++ packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts | 2 ++ 2 files changed, 7 insertions(+) diff --git a/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts b/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts index c5308f9ccf..6a70951f1f 100644 --- a/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts +++ b/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts @@ -41,6 +41,8 @@ export async function orchestrateRealizeDecorator< const result: Record = {}; const decorators: IAutoBeRealizeDecoratorApplication.IProps[] = []; + let completed = 0; + for (const role of roles) { const decorator: IAutoBeRealizeDecoratorApplication.IProps = await process( ctx, @@ -54,12 +56,15 @@ export async function orchestrateRealizeDecorator< decorator.provider.code; decorators.push(decorator); + completed++; } const events: AutoBeRealizeDecoratorEvent = { type: "realizeDecorator", created_at: new Date().toISOString(), files: result, + completed, + total: roles.length, }; ctx.dispatch(events); diff --git a/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts b/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts index 48e6068fd1..91add20724 100644 --- a/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts +++ b/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts @@ -3,4 +3,6 @@ import { AutoBeEventBase } from "./AutoBeEventBase"; export interface AutoBeRealizeDecoratorEvent extends AutoBeEventBase<"realizeDecorator"> { files: Record; + completed: number; + total: number; } From 71670f1d0549409d942aeddf87dda356759b89de Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Tue, 15 Jul 2025 15:47:42 +0900 Subject: [PATCH 06/17] chore: add JWT_SECRET_KEY to ENV --- internals/template/src/MyGlobal.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internals/template/src/MyGlobal.ts b/internals/template/src/MyGlobal.ts index 23f028cbe0..23a82cecd0 100644 --- a/internals/template/src/MyGlobal.ts +++ b/internals/template/src/MyGlobal.ts @@ -15,6 +15,9 @@ export class MyGlobal { export namespace MyGlobal { export interface IEnvironments { API_PORT: `${number}`; + + /** JWT Secret Key. */ + JWT_SECRET_KEY: string; } } const environments = new Singleton(() => { From 052de0b56c3bf285aa0ac53d4d4e058cc9849ccb Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Tue, 15 Jul 2025 15:48:17 +0900 Subject: [PATCH 07/17] chore: fix REALIZE DECORATOR systemp prompt --- packages/agent/prompts/REALIZE_DECORATOR.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/agent/prompts/REALIZE_DECORATOR.md b/packages/agent/prompts/REALIZE_DECORATOR.md index aa05eec00c..dac0ecde50 100644 --- a/packages/agent/prompts/REALIZE_DECORATOR.md +++ b/packages/agent/prompts/REALIZE_DECORATOR.md @@ -49,7 +49,7 @@ Generate authentication Provider and Decorator code specialized for specific Rol ### JWT Authentication Function ```typescript -// jwtAuthorize.ts +// path - src/authentications/jwtAuthorize.ts import { ForbiddenException, UnauthorizedException } from "@nestjs/common"; import jwt from "jsonwebtoken"; @@ -87,11 +87,12 @@ const BEARER_PREFIX = "Bearer "; ### Provider Function Example ```typescript +// path - src/authentications/adminAuthorize.ts import { ForbiddenException } from "@nestjs/common"; import { tags } from "typia"; import { MyGlobal } from "../MyGlobal"; -import { jwtAuthorize } from "./JwtTokenProvider"; +import { jwtAuthorize } from "./jwtAuthorize"; export async function adminAuthorize(request: { headers: { @@ -104,7 +105,7 @@ export async function adminAuthorize(request: { throw new ForbiddenException(`You're not ${payload.type}`); } - const admin = await MyGlobal.prisma.admin.findFirst({ + const admin = await MyGlobal.prisma.admins.findFirst({ where: { id: payload.id, }, @@ -132,11 +133,12 @@ export interface AdminPayload { ### Decorator Example ```typescript +// path - src/decorators/AdminAuth.ts import { SwaggerCustomizer } from "@nestia/core"; import { ExecutionContext, createParamDecorator } from "@nestjs/common"; import { Singleton } from "tstl"; -import { adminAuthorize } from "./AdminProvider"; +import { adminAuthorize } from "../authentications/adminAuthorize"; export const AdminAuth = (): ParameterDecorator => From 95ee1284acafd8cc45ccaf8fa5bd60ef4d712802 Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Tue, 15 Jul 2025 15:48:46 +0900 Subject: [PATCH 08/17] chore: define REALIZE DECORATOR CORRECT systemp prompt --- .../prompts/REALIZE_DECORATOR_CORRECT.md | 140 ++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 packages/agent/prompts/REALIZE_DECORATOR_CORRECT.md diff --git a/packages/agent/prompts/REALIZE_DECORATOR_CORRECT.md b/packages/agent/prompts/REALIZE_DECORATOR_CORRECT.md new file mode 100644 index 0000000000..c2701b9f86 --- /dev/null +++ b/packages/agent/prompts/REALIZE_DECORATOR_CORRECT.md @@ -0,0 +1,140 @@ +# TypeScript Compiler Feedback Correction System + +You are an expert TypeScript developer specializing in fixing compilation errors in NestJS authentication systems. Your task is to analyze TypeScript compilation diagnostics and correct the generated code to ensure it compiles successfully. + +## Your Role + +You will receive: + +1. **Generated TypeScript Code** - Authentication provider and decorator implementations +2. **Prisma Clients** - Available database table mappings +3. **File Paths** - Project structure for import resolution +4. **Compile Errors** - TypeScript diagnostic information + +Your goal is to fix all compilation errors while maintaining the original functionality and structure. + +## Analysis Process + +Follow this systematic approach to fix compilation errors: + +### Step 1: Error Analysis + +- Examine each diagnostic error carefully +- Identify the error type (import issues, type mismatches, missing properties, etc.) +- Note the file location and specific line/character positions +- Categorize errors by severity and interdependency + +### Step 2: Context Understanding + +- Review the available Prisma client mappings to understand database schema +- Check file paths to ensure correct import statements +- Validate that all referenced types and interfaces exist +- Understand the relationship between provider and decorator implementations + +### Step 3: Root Cause Identification + +- Determine if errors are due to: + - Incorrect Prisma table names (use prismaClients mapping) + - Wrong import paths (use provided file paths) + - Missing type definitions + - Incorrect function signatures + - Incompatible TypeScript syntax + +### Step 4: Systematic Correction + +- Fix errors in dependency order (types before implementations) +- Ensure consistency between provider and decorator implementations +- Maintain original naming conventions and patterns +- Preserve all required functionality + +## Common Error Types and Solutions + +### Database Table Access Errors + +- **Problem**: `Property 'tableName' does not exist on type 'PrismaClient'` +- **Solution**: Check `prismaClients` mapping for correct table names +- **Example**: If error shows `admins` but prismaClients shows `admin`, use `admin` + +### Import Path Errors + +- **Problem**: Module resolution failures +- **Solution**: Use provided file paths to construct correct relative imports +- **Example**: Adjust `./` vs `../` based on actual file structure + +### Type Definition Errors + +- **Problem**: Missing or incorrect type references +- **Solution**: Ensure all interfaces and types are properly defined and exported +- **Example**: Add missing `export` keywords or correct type names + +### Function Signature Mismatches + +- **Problem**: Parameter types don't match expected signatures +- **Solution**: Align function parameters with NestJS and custom type requirements +- **Example**: Ensure JWT payload types match expected structure + +## Code Correction Guidelines + +### 1. Preserve Original Structure + +- Keep the same function names and export patterns +- Maintain the provider-decorator relationship +- Preserve all required imports and dependencies + +### 2. Database Integration + +- Use exact table names from `prismaClients` mapping +- Ensure proper async/await patterns for database queries +- Maintain proper error handling for database operations + +### 3. Type Safety + +- Ensure all types are properly imported and defined +- Use typia tags correctly for validation +- Maintain strict TypeScript compliance + +### 4. NestJS Integration + +- Preserve decorator patterns and parameter injection +- Maintain proper exception handling (ForbiddenException, UnauthorizedException) +- Ensure Swagger integration remains intact + +## Output Format + +Provide your corrected code in the following JSON format: + +```json +{ + "provider": { + "name": "corrected_provider_name", + "code": "corrected_provider_code" + }, + "decorator": { + "name": "corrected_decorator_name", + "typeName": "corrected_payload_type_name", + "code": "corrected_decorator_code" + } +} +``` + +## Validation Checklist + +Before submitting your corrections, verify: + +- [ ] All compilation errors are addressed +- [ ] Database table names match prismaClients mapping +- [ ] Import paths are correct based on file structure +- [ ] All types are properly defined and exported +- [ ] Function signatures match expected patterns +- [ ] Error handling is preserved +- [ ] Original functionality is maintained +- [ ] Code follows TypeScript best practices + +## Response Process + +1. **First**, analyze all errors and identify patterns +2. **Then**, explain your understanding of the issues +3. **Next**, describe your correction strategy +4. **Finally**, provide the corrected code in the specified JSON format + +Remember: Focus on fixing compilation errors while preserving the original authentication logic and NestJS integration patterns. \ No newline at end of file From b3260c5f34d2369bf261a583c5fe3f85451c6477 Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Tue, 15 Jul 2025 15:49:52 +0900 Subject: [PATCH 09/17] fix: add Realize Decorator Correct in Realize Decorator Agent --- .../realize/orchestrateRealizeDecorator.ts | 146 ++++++++++++------ ...ansformRealizeDecoratorCorrectHistories.ts | 56 +++++++ 2 files changed, 153 insertions(+), 49 deletions(-) create mode 100644 packages/agent/src/orchestrate/realize/transformRealizeDecoratorCorrectHistories.ts diff --git a/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts b/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts index 6a70951f1f..20377db439 100644 --- a/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts +++ b/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts @@ -1,6 +1,8 @@ import { IAgenticaController, MicroAgentica } from "@agentica/core"; import { AutoBeRealizeDecoratorEvent } from "@autobe/interface"; import { ILlmApplication, ILlmSchema } from "@samchon/openapi"; +import fs from "fs/promises"; +import path from "path"; import { IPointer } from "tstl"; import typia from "typia"; @@ -9,6 +11,7 @@ import { assertSchemaModel } from "../../context/assertSchemaModel"; import { enforceToolCall } from "../../utils/enforceToolCall"; import { IAutoBeRealizeDecoratorApplication } from "./structures/IAutoBeRealizeDecoratorApplication"; import { transformRealizeDecoratorHistories } from "./transformRealizeDecorator"; +import { transformRealizeDecoratorCorrectHistories } from "./transformRealizeDecoratorCorrectHistories"; /** * 1. Create decorator and its parameters. and design the Authorization Provider. @@ -112,7 +115,100 @@ async function process( if (pointer.value === null) throw new Error("Failed to create decorator."); - return pointer.value; + const templateFiles = { + "src/MyGlobal.ts": await fs.readFile( + path.join(__dirname, "../../../../../internals/template/src/MyGlobal.ts"), + "utf-8", + ), + "src/authentications/jwtAuthorize.ts": await fs.readFile( + path.join( + __dirname, + "../../../../../internals/template/src/providers/jwtAuthorize.ts", + ), + "utf-8", + ), + }; + + return await correctDecorator( + ctx, + pointer.value, + prismaClients, + templateFiles, + ); +} + +async function correctDecorator( + ctx: AutoBeContext, + result: IAutoBeRealizeDecoratorApplication.IProps, + prismaClients: Record, + templateFiles: Record, + life: number = 4, +): Promise { + // Check Compile + const files = { + ...templateFiles, + ...prismaClients, + [`src/decorators/${result.decorator.name}.ts`]: result.decorator.code, + [`src/authentications/${result.provider.name}.ts`]: result.provider.code, + }; + + const compiled = await ctx.compiler.typescript.compile({ + files, + }); + + if (compiled.type === "success") { + return result; + } else if (compiled.type === "exception" || life === 0) { + // TODO: Add Failure Event Dispatch + return result; + } + + const pointer: IPointer = { + value: null, + }; + + const agentica: MicroAgentica = new MicroAgentica({ + model: ctx.model, + vendor: ctx.vendor, + config: { + ...(ctx.config ?? {}), + executor: { + describe: null, + }, + }, + histories: transformRealizeDecoratorCorrectHistories( + result, + prismaClients, + templateFiles, + compiled.diagnostics, + ), + controllers: [ + createApplication({ + model: ctx.model, + build: (next) => { + pointer.value = next; + }, + }), + ], + }); + enforceToolCall(agentica); + + await agentica + .conversate("Please correct the decorator and the provider.") + .finally(() => { + const tokenUsage = agentica.getTokenUsage(); + ctx.usage().record(tokenUsage, ["realize"]); + }); + + if (pointer.value === null) throw new Error("Failed to correct decorator."); + + return await correctDecorator( + ctx, + pointer.value, + prismaClients, + templateFiles, + life - 1, + ); } function createApplication(props: { @@ -155,51 +251,3 @@ const collection = { deepseek: claude, "3.1": claude, }; - -// interface IAutoBeRealizeDecoratorApplication.IProps { -// /** -// * The name of the authentication Provider function in {role}Authorize format -// * (e.g., adminAuthorize, userAuthorize). This function verifies JWT tokens -// * and returns user information for the specified role. It should handle JWT -// * validation, role verification, and database queries to ensure the user -// * exists and has proper permissions. -// */ -// providerFunctionName: string; - -// /** -// * The name of the Payload type in {Role}Payload format (e.g., AdminPayload, -// * UserPayload). This interface defines the structure of the authenticated -// * user data that will be used as the parameter type when using decorators in -// * Controllers. Must include 'id' (UUID format) and 'type' (role -// * discriminator) fields. -// */ -// decoratorTypeName: string; - -// /** -// * Complete TypeScript code for the authentication Provider function and its -// * corresponding Payload interface. Must include: JWT token verification using -// * jwtAuthorize function, role type checking, database query using -// * MyGlobal.prisma.{tableName} pattern, proper error handling with NestJS -// * exceptions, and the Payload interface definition with appropriate typia -// * tags for type safety. -// */ -// provider: string; - -// /** -// * The name of the Decorator to be generated in {Role}Auth format (e.g., -// * AdminAuth, UserAuth). This decorator will be used as a parameter decorator -// * in Controller methods to automatically authenticate and authorize users for -// * the specific role, injecting the authenticated user payload. -// */ -// decoratorName: string; - -// /** -// * Complete TypeScript code for the authentication Decorator implementation. -// * Must include: SwaggerCustomizer integration for API documentation with -// * bearer token security, createParamDecorator implementation for the actual -// * authentication logic, Singleton pattern for efficient decorator instance -// * management, and proper integration with the corresponding Provider -// * function. -// */ -// decorator: string; -// } diff --git a/packages/agent/src/orchestrate/realize/transformRealizeDecoratorCorrectHistories.ts b/packages/agent/src/orchestrate/realize/transformRealizeDecoratorCorrectHistories.ts new file mode 100644 index 0000000000..2e01a02b38 --- /dev/null +++ b/packages/agent/src/orchestrate/realize/transformRealizeDecoratorCorrectHistories.ts @@ -0,0 +1,56 @@ +import { IAgenticaHistoryJson } from "@agentica/core"; +import { IAutoBeTypeScriptCompileResult } from "@autobe/interface"; +import { v4 } from "uuid"; + +import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant"; +import { IAutoBeRealizeDecoratorApplication } from "./structures/IAutoBeRealizeDecoratorApplication"; + +export const transformRealizeDecoratorCorrectHistories = ( + result: IAutoBeRealizeDecoratorApplication.IProps, + prismaClients: Record, + templateFiles: Record, + diagnostics: IAutoBeTypeScriptCompileResult.IDiagnostic[], +): Array< + IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage +> => { + return [ + { + id: v4(), + created_at: new Date().toISOString(), + type: "systemMessage", + text: AutoBeSystemPromptConstant.REALIZE_DECORATOR_CORRECT, + }, + { + id: v4(), + created_at: new Date().toISOString(), + type: "assistantMessage", + text: [ + "## Generated TypeScript Code", + "", + "```json", + `${JSON.stringify(result, null, 2)}`, + "```", + "", + "## Prisma Clients", + "", + "```json", + `${JSON.stringify(prismaClients, null, 2)}`, + "```", + "", + "## File Paths", + "", + Object.keys(templateFiles) + .map((path) => `- ${path}`) + .join("\n"), + "", + "## Compile Errors", + "", + "Fix the compilation error in the provided code.", + "", + "```json", + JSON.stringify(diagnostics, null, 2), + "```", + ].join("\n"), + }, + ]; +}; From b257efc23e458df4e10089f9d46f52f009aeb1a6 Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Tue, 15 Jul 2025 15:50:45 +0900 Subject: [PATCH 10/17] chore: remove unnecessary code --- .../src/orchestrate/realize/orchestrateRealize.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/packages/agent/src/orchestrate/realize/orchestrateRealize.ts b/packages/agent/src/orchestrate/realize/orchestrateRealize.ts index 00d59375ce..cdb34d20ad 100644 --- a/packages/agent/src/orchestrate/realize/orchestrateRealize.ts +++ b/packages/agent/src/orchestrate/realize/orchestrateRealize.ts @@ -25,19 +25,6 @@ export const orchestrateRealize = throw new Error(); } - ops.forEach((op, i) => { - if (!op.authorization?.role) { - op.authorization = { - role: [], - type: "Bearer", - }; - } - - if (i === 1) op.authorization.role.push("user"); - if (i === 2) op.authorization.role.push("admin"); - if (i === 3) op.authorization.role.push("moderator"); - }); - ctx.dispatch({ type: "realizeStart", created_at: new Date().toISOString(), From 2a01f0ec54be8a619fa93b3703dc7d1c17f09de1 Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Tue, 15 Jul 2025 16:32:29 +0900 Subject: [PATCH 11/17] chore: add comment to AutoBeRealizeDecoratorEvent --- .../src/events/AutoBeRealizeDecoratorEvent.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts b/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts index 91add20724..da4f282c19 100644 --- a/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts +++ b/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts @@ -1,8 +1,52 @@ import { AutoBeEventBase } from "./AutoBeEventBase"; +/** @author Michael */ export interface AutoBeRealizeDecoratorEvent extends AutoBeEventBase<"realizeDecorator"> { + /** + * Generated decorator and provider files as key-value pairs. + * + * Contains the TypeScript implementation files that were generated for the + * decorator and provider. Each key represents the file path and each value + * contains the actual implementation code that makes the application + * functional. + */ files: Record; + + /** + * Number of implementation files that have been completed so far. + * + * Indicates the current progress in the implementation process, showing how + * many implementation files have been successfully generated and integrated + * into the application. This progress tracking helps stakeholders monitor the + * advancement of the final development phase and estimate completion timing. + */ completed: number; + + /** + * Total number of implementation files that need to be created. + * + * Represents the complete scope of implementation files required to fulfill + * all business requirements and complete the application functionality. This + * total count provides context for the completion progress and helps + * stakeholders understand the overall complexity and scope of the + * implementation work. + */ total: number; + + /** + * Iteration number of the requirements analysis this implementation progress + * reflects. + * + * Indicates which version of the requirements analysis this implementation + * work is based on. This step number ensures that the implementation progress + * is aligned with the current requirements and helps track the development of + * implementation components as they evolve with changing business needs. + * + * The step value enables proper synchronization between implementation + * activities and the underlying requirements, ensuring that the generated + * code remains relevant to the current project scope and business + * objectives. + */ + step: number; } From 70f9e8ff45ed6a7b0202e160c730c33e1ed1ed70 Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Tue, 15 Jul 2025 16:34:16 +0900 Subject: [PATCH 12/17] chore: refactor the realize decorator --- .../orchestrate/realize/orchestrateRealizeDecorator.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts b/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts index 20377db439..b3ceee82f1 100644 --- a/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts +++ b/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts @@ -41,7 +41,7 @@ export async function orchestrateRealizeDecorator< ), ); - const result: Record = {}; + const files: Record = {}; const decorators: IAutoBeRealizeDecoratorApplication.IProps[] = []; let completed = 0; @@ -53,9 +53,9 @@ export async function orchestrateRealizeDecorator< prismaClients, ); - result[`src/decorators/${decorator.decorator.name}.ts`] = + files[`src/decorators/${decorator.decorator.name}.ts`] = decorator.decorator.code; - result[`src/authentications/${decorator.provider.name}.ts`] = + files[`src/authentications/${decorator.provider.name}.ts`] = decorator.provider.code; decorators.push(decorator); @@ -65,9 +65,10 @@ export async function orchestrateRealizeDecorator< const events: AutoBeRealizeDecoratorEvent = { type: "realizeDecorator", created_at: new Date().toISOString(), - files: result, + files, completed, total: roles.length, + step: ctx.state().test?.step ?? 0, }; ctx.dispatch(events); From e201fda1b834f4f1a98394faaac90b8f1a6c0c54 Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Tue, 15 Jul 2025 16:34:36 +0900 Subject: [PATCH 13/17] test: define test_agent_realize_decorator_bbs --- .../validate_agent_realize_decorator.ts | 102 ++++++++++++++++++ .../test_agent_realize_decorator_bbs.ts | 8 ++ 2 files changed, 110 insertions(+) create mode 100644 test/src/features/realize/internal/validate_agent_realize_decorator.ts create mode 100644 test/src/features/realize/test_agent_realize_decorator_bbs.ts diff --git a/test/src/features/realize/internal/validate_agent_realize_decorator.ts b/test/src/features/realize/internal/validate_agent_realize_decorator.ts new file mode 100644 index 0000000000..7cb555d759 --- /dev/null +++ b/test/src/features/realize/internal/validate_agent_realize_decorator.ts @@ -0,0 +1,102 @@ +import { orchestrateRealizeDecorator } from "@autobe/agent/src/orchestrate/realize/orchestrateRealizeDecorator"; +import { FileSystemIterator } from "@autobe/filesystem"; +import { AutoBeEvent } from "@autobe/interface"; +import fs from "fs/promises"; +import path from "path"; +import typia from "typia"; + +import { TestFactory } from "../../../TestFactory"; +import { TestGlobal } from "../../../TestGlobal"; +import { TestProject } from "../../../structures/TestProject"; +import { prepare_agent_realize } from "./prepare_agent_realize"; + +export const validate_agent_realize_decorator = async ( + factory: TestFactory, + project: TestProject, +) => { + if (TestGlobal.env.CHATGPT_API_KEY === undefined) return false; + + // PREPARE AGENT + const { agent } = await prepare_agent_realize(factory, project); + + const map = new Map(); + const events: AutoBeEvent[] = []; + const enroll = (event: AutoBeEvent) => { + if (!map.has(event.type)) { + map.set(event.type, true); + } + + events.push(event); + }; + + agent.on("realizeStart", enroll); + agent.on("realizeDecorator", enroll); + agent.on("realizeProgress", enroll); + agent.on("realizeValidate", enroll); + agent.on("realizeComplete", enroll); + + const ctx = agent.getContext(); + + ctx.state().interface?.document.operations.forEach((op, i) => { + if (!op.authorization?.role) { + op.authorization = { + role: [], + type: "Bearer", + }; + } + + if (i === 1) op.authorization.role.push("user"); + if (i === 2) op.authorization.role.push("admin"); + if (i === 3) op.authorization.role.push("moderator"); + }); + + const result = await orchestrateRealizeDecorator(ctx); + + const prisma = ctx.state().prisma?.compiled; + + const prismaClients: Record = + prisma?.type === "success" ? prisma.nodeModules : {}; + + const files: Record = { + "src/MyGlobal.ts": await fs.readFile( + path.join(__dirname, "../../../../../internals/template/src/MyGlobal.ts"), + "utf-8", + ), + "src/authentications/jwtAuthorize.ts": await fs.readFile( + path.join( + __dirname, + "../../../../../internals/template/src/providers/jwtAuthorize.ts", + ), + "utf-8", + ), + ...prismaClients, + ...result.reduce( + (acc, curr) => { + acc[`src/decorators/${curr.decorator.name}.ts`] = curr.decorator.code; + acc[`src/authentications/${curr.provider.name}.ts`] = + curr.provider.code; + return acc; + }, + {} as Record, + ), + }; + + const histories = agent.getHistories(); + + await FileSystemIterator.save({ + root: `${TestGlobal.ROOT}/results/${project}/realize/decorator`, + files: { + ...(await agent.getFiles()), + ...files, + "logs/events.json": typia.json.stringify(events), + "logs/result.json": typia.json.stringify(result), + "logs/histories.json": typia.json.stringify(histories), + }, + }); + + const compiled = await ctx.compiler.typescript.compile({ files }); + + if (compiled.type !== "success") { + throw new Error(JSON.stringify(compiled, null, 2)); + } +}; diff --git a/test/src/features/realize/test_agent_realize_decorator_bbs.ts b/test/src/features/realize/test_agent_realize_decorator_bbs.ts new file mode 100644 index 0000000000..a573314077 --- /dev/null +++ b/test/src/features/realize/test_agent_realize_decorator_bbs.ts @@ -0,0 +1,8 @@ +import { TestFactory } from "../../TestFactory"; +import { validate_agent_realize_decorator } from "./internal/validate_agent_realize_decorator"; + +export const test_agent_realize_decorator_bbs = async ( + factory: TestFactory, +) => { + await validate_agent_realize_decorator(factory, "bbs-backend"); +}; From 5b47148e25a22c648ce48eb3ed7232f456a4a263 Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Wed, 16 Jul 2025 13:24:09 +0900 Subject: [PATCH 14/17] chore: relocate the templateFiles in orchestrateRealizeDecroator --- .../realize/orchestrateRealizeDecorator.ts | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts b/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts index b3ceee82f1..49af7accdd 100644 --- a/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts +++ b/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts @@ -46,10 +46,25 @@ export async function orchestrateRealizeDecorator< let completed = 0; + const templateFiles = { + "src/MyGlobal.ts": await fs.readFile( + path.join(__dirname, "../../../../../internals/template/src/MyGlobal.ts"), + "utf-8", + ), + "src/authentications/jwtAuthorize.ts": await fs.readFile( + path.join( + __dirname, + "../../../../../internals/template/src/providers/jwtAuthorize.ts", + ), + "utf-8", + ), + }; + for (const role of roles) { const decorator: IAutoBeRealizeDecoratorApplication.IProps = await process( ctx, role, + templateFiles, prismaClients, ); @@ -79,6 +94,7 @@ export async function orchestrateRealizeDecorator< async function process( ctx: AutoBeContext, role: string, + templateFiles: Record, prismaClients: Record, ): Promise { const pointer: IPointer = { @@ -116,20 +132,6 @@ async function process( if (pointer.value === null) throw new Error("Failed to create decorator."); - const templateFiles = { - "src/MyGlobal.ts": await fs.readFile( - path.join(__dirname, "../../../../../internals/template/src/MyGlobal.ts"), - "utf-8", - ), - "src/authentications/jwtAuthorize.ts": await fs.readFile( - path.join( - __dirname, - "../../../../../internals/template/src/providers/jwtAuthorize.ts", - ), - "utf-8", - ), - }; - return await correctDecorator( ctx, pointer.value, From 64443c11d88f0784b009443bfe661fcaa88be113 Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Thu, 17 Jul 2025 16:55:23 +0900 Subject: [PATCH 15/17] fix: add Decorator Validate and Correct event --- .../realize/orchestrateRealizeDecorator.ts | 76 ++++++++++++------- packages/interface/src/events/AutoBeEvent.ts | 6 ++ .../AutoBeRealizeDecoratorCorrectEvent.ts | 49 ++++++++++++ .../src/events/AutoBeRealizeDecoratorEvent.ts | 12 ++- .../AutoBeRealizeDecoratorValidateEvent.ts | 45 +++++++++++ packages/interface/src/events/index.ts | 2 + .../interface/src/rpc/IAutoBeRpcListener.ts | 25 ++++++ .../events/AutoBePlaygroundEventMovie.tsx | 2 + .../AutoBePlaygroundProgressEventMovie.tsx | 12 ++- .../structures/AutoBePlaygroundListener.ts | 6 ++ .../validate_agent_realize_decorator.ts | 8 +- ...lize.ts => validate_agent_realize_main.ts} | 21 ++--- .../realize/test_agent_realize_main_bbs.ts | 4 +- 13 files changed, 223 insertions(+), 45 deletions(-) create mode 100644 packages/interface/src/events/AutoBeRealizeDecoratorCorrectEvent.ts create mode 100644 packages/interface/src/events/AutoBeRealizeDecoratorValidateEvent.ts rename test/src/features/realize/internal/{validate_agent_realize.ts => validate_agent_realize_main.ts} (83%) diff --git a/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts b/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts index f1b3316502..1a34f7ba84 100644 --- a/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts +++ b/packages/agent/src/orchestrate/realize/orchestrateRealizeDecorator.ts @@ -64,33 +64,30 @@ export async function orchestrateRealizeDecorator< ...prismaClients, }; - for (const role of roles) { - const decorator: IAutoBeRealizeDecoratorApplication.IProps = await process( - ctx, - role, - templateFiles, - prismaClients, - ); - - files[`src/decorators/${decorator.decorator.name}.ts`] = - decorator.decorator.code; - files[`src/authentications/${decorator.provider.name}.ts`] = - decorator.provider.code; - - decorators.push(decorator); - completed++; - } - - const events: AutoBeRealizeDecoratorEvent = { - type: "realizeDecorator", - created_at: new Date().toISOString(), - files, - completed, - total: roles.length, - step: ctx.state().test?.step ?? 0, - }; - - ctx.dispatch(events); + await Promise.all( + roles.map(async (role) => { + const decorator: IAutoBeRealizeDecoratorApplication.IProps = + await process(ctx, role, templateFiles, prismaClients); + + files[`src/decorators/${decorator.decorator.name}.ts`] = + decorator.decorator.code; + files[`src/authentications/${decorator.provider.name}.ts`] = + decorator.provider.code; + + decorators.push(decorator); + + const events: AutoBeRealizeDecoratorEvent = { + type: "realizeDecorator", + created_at: new Date().toISOString(), + files, + completed: ++completed, + total: roles.length, + step: ctx.state().test?.step ?? 0, + }; + + ctx.dispatch(events); + }), + ); return decorators; } @@ -165,10 +162,17 @@ async function correctDecorator( files, }); + ctx.dispatch({ + type: "realizeDecoratorValidate", + created_at: new Date().toISOString(), + result: compiled, + files, + step: ctx.state().test?.step ?? 0, + }); + if (compiled.type === "success") { return result; } else if (compiled.type === "exception" || life === 0) { - // TODO: Add Failure Event Dispatch return result; } @@ -211,6 +215,22 @@ async function correctDecorator( if (pointer.value === null) throw new Error("Failed to correct decorator."); + const correctedFiles: Record = { + ...files, + [`src/decorators/${pointer.value.decorator.name}.ts`]: + pointer.value.decorator.code, + [`src/authentications/${pointer.value.provider.name}.ts`]: + pointer.value.provider.code, + }; + + ctx.dispatch({ + type: "realizeDecoratorCorrect", + created_at: new Date().toISOString(), + files: correctedFiles, + result: compiled, + step: ctx.state().test?.step ?? 0, + }); + return await correctDecorator( ctx, pointer.value, diff --git a/packages/interface/src/events/AutoBeEvent.ts b/packages/interface/src/events/AutoBeEvent.ts index cc8c5af3f9..33ba403142 100644 --- a/packages/interface/src/events/AutoBeEvent.ts +++ b/packages/interface/src/events/AutoBeEvent.ts @@ -17,7 +17,9 @@ import { AutoBePrismaSchemasEvent } from "./AutoBePrismaSchemasEvent"; import { AutoBePrismaStartEvent } from "./AutoBePrismaStartEvent"; import { AutoBePrismaValidateEvent } from "./AutoBePrismaValidateEvent"; import { AutoBeRealizeCompleteEvent } from "./AutoBeRealizeCompleteEvent"; +import { AutoBeRealizeDecoratorCorrectEvent } from "./AutoBeRealizeDecoratorCorrectEvent"; import { AutoBeRealizeDecoratorEvent } from "./AutoBeRealizeDecoratorEvent"; +import { AutoBeRealizeDecoratorValidateEvent } from "./AutoBeRealizeDecoratorValidateEvent"; import { AutoBeRealizeProgressEvent } from "./AutoBeRealizeProgressEvent"; import { AutoBeRealizeStartEvent } from "./AutoBeRealizeStartEvent"; import { AutoBeRealizeTestCompleteEvent } from "./AutoBeRealizeTestCompleteEvent"; @@ -88,6 +90,8 @@ export type AutoBeEvent = // REALIZE | AutoBeRealizeStartEvent | AutoBeRealizeDecoratorEvent + | AutoBeRealizeDecoratorValidateEvent + | AutoBeRealizeDecoratorCorrectEvent | AutoBeRealizeProgressEvent | AutoBeRealizeValidateEvent | AutoBeRealizeCompleteEvent @@ -163,6 +167,8 @@ export namespace AutoBeEvent { // REALIZE realizeStart: AutoBeRealizeStartEvent; realizeDecorator: AutoBeRealizeDecoratorEvent; + realizeDecoratorValidate: AutoBeRealizeDecoratorValidateEvent; + realizeDecoratorCorrect: AutoBeRealizeDecoratorCorrectEvent; realizeProgress: AutoBeRealizeProgressEvent; realizeValidate: AutoBeRealizeValidateEvent; realizeComplete: AutoBeRealizeCompleteEvent; diff --git a/packages/interface/src/events/AutoBeRealizeDecoratorCorrectEvent.ts b/packages/interface/src/events/AutoBeRealizeDecoratorCorrectEvent.ts new file mode 100644 index 0000000000..48453c24d7 --- /dev/null +++ b/packages/interface/src/events/AutoBeRealizeDecoratorCorrectEvent.ts @@ -0,0 +1,49 @@ +import { IAutoBeTypeScriptCompileResult } from "../compiler"; +import { AutoBeEventBase } from "./AutoBeEventBase"; + +/** + * Event fired when the Realize decorator agent corrects compilation failures in + * the generated decorator implementation code. + * + * This event occurs when the embedded TypeScript compiler detects compilation + * errors in the decorator code and the Realize agent receives detailed error + * feedback to correct the issues. The correction process demonstrates the + * sophisticated feedback loop that enables AI to learn from compilation errors + * and improve code quality iteratively. + * + * @author Michael + */ +export interface AutoBeRealizeDecoratorCorrectEvent + extends AutoBeEventBase<"realizeDecoratorCorrect"> { + /** + * Generated decorator and provider files as key-value pairs. + * + * Contains the TypeScript implementation files that were generated for the + * decorator and provider. Each key represents the file path and each value + * contains the actual implementation code that makes the application + * functional. This file includes default template files, the decorator and + * provider files. + */ + files: Record; + + /** + * The compilation failure details that triggered the correction process. + * + * Contains the specific compilation error information describing what + * validation errors were detected in the decorator implementation code. This + * includes error messages, file locations, type issues, or other compilation + * problems that prevented successful validation. + */ + result: IAutoBeTypeScriptCompileResult.IFailure; + + /** + * Iteration number of the requirements analysis this correction was performed + * for. + * + * Indicates which version of the requirements analysis this decorator + * correction reflects. This step number ensures that correction efforts are + * aligned with the current requirements and helps track the evolution of code + * quality as validation feedback is incorporated. + */ + step: number; +} diff --git a/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts b/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts index da4f282c19..1f2a02c3fc 100644 --- a/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts +++ b/packages/interface/src/events/AutoBeRealizeDecoratorEvent.ts @@ -1,6 +1,16 @@ import { AutoBeEventBase } from "./AutoBeEventBase"; -/** @author Michael */ +/** + * Event fired when the Realize decorator agent generates decorator + * implementation code. + * + * This event occurs when the Realize agent completes generating TypeScript + * decorator implementations and their associated provider files. The event + * provides detailed information about the generated files, progress metrics, + * and the current step in the realization process. + * + * @author Michael + */ export interface AutoBeRealizeDecoratorEvent extends AutoBeEventBase<"realizeDecorator"> { /** diff --git a/packages/interface/src/events/AutoBeRealizeDecoratorValidateEvent.ts b/packages/interface/src/events/AutoBeRealizeDecoratorValidateEvent.ts new file mode 100644 index 0000000000..bf07954bfe --- /dev/null +++ b/packages/interface/src/events/AutoBeRealizeDecoratorValidateEvent.ts @@ -0,0 +1,45 @@ +import { IAutoBeTypeScriptCompileResult } from "../compiler"; +import { AutoBeEventBase } from "./AutoBeEventBase"; + +/** + * Event fired when the Realize decorator agent validates the generated + * decorator implementation code. + * + * This event occurs when the embedded TypeScript compiler validates the + * decorator code to ensure it meets all compilation requirements. The + * validation process is a critical step in maintaining code quality and + * catching potential issues early in the development cycle. + * + * @author Michael + */ +export interface AutoBeRealizeDecoratorValidateEvent + extends AutoBeEventBase<"realizeDecoratorValidate"> { + /** + * The validation result from the TypeScript compiler. + * + * Contains detailed information about whether the decorator implementation + * code successfully passed compilation validation, including any errors or + * warnings that were detected during the validation process. + */ + result: IAutoBeTypeScriptCompileResult; + + /** + * Generated decorator and provider files as key-value pairs. + * + * Contains the TypeScript implementation files that were generated for the + * decorator and provider. Each key represents the file path and each value + * contains the actual implementation code that was validated. + */ + files: Record; + + /** + * Iteration number of the requirements analysis this validation was performed + * for. + * + * Indicates which version of the requirements analysis this validation + * reflects. This step number ensures that validation efforts are aligned with + * the current requirements and helps track code quality evolution through the + * development process. + */ + step: number; +} diff --git a/packages/interface/src/events/index.ts b/packages/interface/src/events/index.ts index ebda9af8ec..84abb0ea1d 100644 --- a/packages/interface/src/events/index.ts +++ b/packages/interface/src/events/index.ts @@ -32,6 +32,8 @@ export * from "./AutoBeTestCompleteEvent"; export * from "./AutoBeRealizeStartEvent"; export * from "./AutoBeRealizeDecoratorEvent"; +export * from "./AutoBeRealizeDecoratorValidateEvent"; +export * from "./AutoBeRealizeDecoratorCorrectEvent"; export * from "./AutoBeRealizeProgressEvent"; export * from "./AutoBeRealizeValidateEvent"; export * from "./AutoBeRealizeCompleteEvent"; diff --git a/packages/interface/src/rpc/IAutoBeRpcListener.ts b/packages/interface/src/rpc/IAutoBeRpcListener.ts index 4fb26985da..f99cefe0e2 100644 --- a/packages/interface/src/rpc/IAutoBeRpcListener.ts +++ b/packages/interface/src/rpc/IAutoBeRpcListener.ts @@ -18,7 +18,9 @@ import { AutoBePrismaStartEvent, AutoBePrismaValidateEvent, AutoBeRealizeCompleteEvent, + AutoBeRealizeDecoratorCorrectEvent, AutoBeRealizeDecoratorEvent, + AutoBeRealizeDecoratorValidateEvent, AutoBeRealizeProgressEvent, AutoBeRealizeStartEvent, AutoBeRealizeTestCompleteEvent, @@ -328,6 +330,29 @@ export interface IAutoBeRpcListener { */ realizeDecorator?(event: AutoBeRealizeDecoratorEvent): Promise; + /** + * Optional handler for decorator validation events. + * + * Called when the Realize agent validates the generated decorator, enabling + * client applications to show quality assurance processes and potential + * correction activities for the decorator. + */ + realizeDecoratorValidate?( + event: AutoBeRealizeDecoratorValidateEvent, + ): Promise; + + /** + * Optional handler for decorator correction events. + * + * Called when the Realize agent corrects compilation failures in the + * generated decorator implementation code, enabling client applications to + * show that issues are being resolved automatically through iterative + * improvement. + */ + realizeDecoratorCorrect?( + event: AutoBeRealizeDecoratorCorrectEvent, + ): Promise; + /** * Optional handler for implementation progress events. * diff --git a/packages/playground-ui/src/movies/events/AutoBePlaygroundEventMovie.tsx b/packages/playground-ui/src/movies/events/AutoBePlaygroundEventMovie.tsx index 7b1123b1c8..f0ed1a59e7 100644 --- a/packages/playground-ui/src/movies/events/AutoBePlaygroundEventMovie.tsx +++ b/packages/playground-ui/src/movies/events/AutoBePlaygroundEventMovie.tsx @@ -44,6 +44,8 @@ export function AutoBePlaygroundEventMovie( case "testValidate": case "realizeDecorator": case "realizeValidate": + case "realizeDecoratorValidate": + case "realizeDecoratorCorrect": case "realizeTestReset": case "realizeTestOperation": return ; diff --git a/packages/playground-ui/src/movies/events/AutoBePlaygroundProgressEventMovie.tsx b/packages/playground-ui/src/movies/events/AutoBePlaygroundProgressEventMovie.tsx index fce0cce3d8..dbb2e83628 100644 --- a/packages/playground-ui/src/movies/events/AutoBePlaygroundProgressEventMovie.tsx +++ b/packages/playground-ui/src/movies/events/AutoBePlaygroundProgressEventMovie.tsx @@ -8,7 +8,9 @@ import { AutoBePrismaComponentsEvent, AutoBePrismaInsufficientEvent, AutoBePrismaSchemasEvent, + AutoBeRealizeDecoratorCorrectEvent, AutoBeRealizeDecoratorEvent, + AutoBeRealizeDecoratorValidateEvent, AutoBeRealizeProgressEvent, AutoBeRealizeTestOperationEvent, AutoBeRealizeTestResetEvent, @@ -48,7 +50,9 @@ export namespace AutoBePlaygroundProgressEventMovie { | AutoBeRealizeProgressEvent | AutoBeRealizeValidateEvent | AutoBeRealizeTestResetEvent - | AutoBeRealizeTestOperationEvent; + | AutoBeRealizeTestOperationEvent + | AutoBeRealizeDecoratorValidateEvent + | AutoBeRealizeDecoratorCorrectEvent; } } @@ -83,7 +87,11 @@ function getDescription( case "testCorrect": return `Correcting Test Function`; case "realizeDecorator": - return `Generating Decorators`; + return `Generating Decorators: ${event.completed} of ${event.total}`; + case "realizeDecoratorValidate": + return `Validating Decorator Function: ${event.result.type}`; + case "realizeDecoratorCorrect": + return `Correcting Decorator Function ${event.result.type}`; case "realizeValidate": return `Validating Realize Function: ${event.result.type}`; case "realizeProgress": diff --git a/packages/playground-ui/src/structures/AutoBePlaygroundListener.ts b/packages/playground-ui/src/structures/AutoBePlaygroundListener.ts index 1b9559b882..1027a668f3 100644 --- a/packages/playground-ui/src/structures/AutoBePlaygroundListener.ts +++ b/packages/playground-ui/src/structures/AutoBePlaygroundListener.ts @@ -98,6 +98,12 @@ export class AutoBePlaygroundListener { realizeDecorator: async (event) => { this.callback?.(event); }, + realizeDecoratorValidate: async (event) => { + this.callback?.(event); + }, + realizeDecoratorCorrect: async (event) => { + this.callback?.(event); + }, realizeProgress: async (event) => { this.callback?.(event); }, diff --git a/test/src/features/realize/internal/validate_agent_realize_decorator.ts b/test/src/features/realize/internal/validate_agent_realize_decorator.ts index 6f9fc5e9b2..edd135e40c 100644 --- a/test/src/features/realize/internal/validate_agent_realize_decorator.ts +++ b/test/src/features/realize/internal/validate_agent_realize_decorator.ts @@ -1,7 +1,7 @@ import { orchestrateRealizeDecorator } from "@autobe/agent/src/orchestrate/realize/orchestrateRealizeDecorator"; import { FileSystemIterator } from "@autobe/filesystem"; import { AutoBeEvent, IAutoBeCompiler } from "@autobe/interface"; -import fs from "fs/promises"; +import fs from "fs"; import path from "path"; import typia from "typia"; @@ -31,6 +31,8 @@ export const validate_agent_realize_decorator = async ( agent.on("realizeStart", enroll); agent.on("realizeDecorator", enroll); + agent.on("realizeDecoratorValidate", enroll); + agent.on("realizeDecoratorCorrect", enroll); agent.on("realizeProgress", enroll); agent.on("realizeValidate", enroll); agent.on("realizeComplete", enroll); @@ -45,14 +47,14 @@ export const validate_agent_realize_decorator = async ( prisma?.type === "success" ? prisma.nodeModules : {}; const files: Record = { - "src/MyGlobal.ts": await fs.readFile( + "src/MyGlobal.ts": await fs.promises.readFile( path.join( __dirname, "../../../../../internals/template/realize/src/MyGlobal.ts", ), "utf-8", ), - "src/authentications/jwtAuthorize.ts": await fs.readFile( + "src/authentications/jwtAuthorize.ts": await fs.promises.readFile( path.join( __dirname, "../../../../../internals/template/realize/src/providers/jwtAuthorize.ts", diff --git a/test/src/features/realize/internal/validate_agent_realize.ts b/test/src/features/realize/internal/validate_agent_realize_main.ts similarity index 83% rename from test/src/features/realize/internal/validate_agent_realize.ts rename to test/src/features/realize/internal/validate_agent_realize_main.ts index df3f397f5c..524b9a2b8d 100644 --- a/test/src/features/realize/internal/validate_agent_realize.ts +++ b/test/src/features/realize/internal/validate_agent_realize_main.ts @@ -6,6 +6,7 @@ import { AutoBeRealizeHistory, } from "@autobe/interface"; import { TestValidator } from "@nestia/e2e"; +import fs from "fs"; // import typia from "typia"; @@ -14,7 +15,7 @@ import { TestGlobal } from "../../../TestGlobal"; import { TestProject } from "../../../structures/TestProject"; import { prepare_agent_realize } from "./prepare_agent_realize"; -export const validate_agent_realize = async ( +export const validate_agent_realize_main = async ( factory: TestFactory, project: TestProject, ) => { @@ -37,18 +38,13 @@ export const validate_agent_realize = async ( agent.on("realizeStart", enroll); agent.on("realizeProgress", enroll); agent.on("realizeValidate", enroll); + agent.on("realizeDecorator", enroll); + agent.on("realizeDecoratorValidate", enroll); + agent.on("realizeDecoratorCorrect", enroll); agent.on("realizeComplete", enroll); const ctx = agent.getContext(); - const roles = - ctx - .state() - .interface?.document.components.authorization?.map((auth) => auth.name) ?? - []; - - console.log("Roles", roles); - // DO TEST GENERATION const go = (reason: string) => orchestrateRealize(ctx)({ @@ -76,4 +72,11 @@ export const validate_agent_realize = async ( }, }); TestValidator.equals("result")(result.compiled.type)("success"); + + if (process.argv.includes("--archive")) + await fs.promises.writeFile( + `${TestGlobal.ROOT}/assets/histories/${project}.realize.json`, + JSON.stringify(agent.getHistories(), null, 2), + "utf8", + ); }; diff --git a/test/src/features/realize/test_agent_realize_main_bbs.ts b/test/src/features/realize/test_agent_realize_main_bbs.ts index b175521af6..319df654d0 100644 --- a/test/src/features/realize/test_agent_realize_main_bbs.ts +++ b/test/src/features/realize/test_agent_realize_main_bbs.ts @@ -1,5 +1,5 @@ import { TestFactory } from "../../TestFactory"; -import { validate_agent_realize } from "./internal/validate_agent_realize"; +import { validate_agent_realize_main } from "./internal/validate_agent_realize_main"; export const test_agent_realize_main_bbs = (factory: TestFactory) => - validate_agent_realize(factory, "bbs-backend"); + validate_agent_realize_main(factory, "bbs-backend"); From 22304d891b53896b6efd4ca83f2819d2dac4591b Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Thu, 17 Jul 2025 17:40:56 +0900 Subject: [PATCH 16/17] chore: add realize start event --- .../agent/src/orchestrate/realize/orchestrateRealize.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/agent/src/orchestrate/realize/orchestrateRealize.ts b/packages/agent/src/orchestrate/realize/orchestrateRealize.ts index 4f805d1d1a..119b4508bd 100644 --- a/packages/agent/src/orchestrate/realize/orchestrateRealize.ts +++ b/packages/agent/src/orchestrate/realize/orchestrateRealize.ts @@ -21,6 +21,13 @@ export const orchestrateRealize = throw new Error("Can't do realize agent because operations are nothing."); } + ctx.dispatch({ + type: "realizeStart", + created_at: new Date().toISOString(), + reason: props.reason, + step: ctx.state().test?.step ?? 0, + }); + const decorators = await orchestrateRealizeDecorator(ctx); decorators; From d1738d6c004a03217f94914daf1b36b858f509ac Mon Sep 17 00:00:00 2001 From: michael <7471919@naver.com> Date: Thu, 17 Jul 2025 17:41:08 +0900 Subject: [PATCH 17/17] chore: fix the message of realize decorator event --- .../src/movies/events/AutoBePlaygroundProgressEventMovie.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/playground-ui/src/movies/events/AutoBePlaygroundProgressEventMovie.tsx b/packages/playground-ui/src/movies/events/AutoBePlaygroundProgressEventMovie.tsx index dbb2e83628..bfe3a0dc5f 100644 --- a/packages/playground-ui/src/movies/events/AutoBePlaygroundProgressEventMovie.tsx +++ b/packages/playground-ui/src/movies/events/AutoBePlaygroundProgressEventMovie.tsx @@ -87,7 +87,7 @@ function getDescription( case "testCorrect": return `Correcting Test Function`; case "realizeDecorator": - return `Generating Decorators: ${event.completed} of ${event.total}`; + return `Generated Decorators: ${event.completed} of ${event.total}`; case "realizeDecoratorValidate": return `Validating Decorator Function: ${event.result.type}`; case "realizeDecoratorCorrect":