@autobe/agent 0.10.6 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/lib/AutoBeAgent.js +13 -46
  2. package/lib/AutoBeAgent.js.map +1 -1
  3. package/lib/constants/AutoBeSystemPromptConstant.d.ts +11 -6
  4. package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
  5. package/lib/context/AutoBeContext.d.ts +3 -2
  6. package/lib/factory/getAutoBeGenerated.d.ts +5 -0
  7. package/lib/factory/getAutoBeGenerated.js +307 -0
  8. package/lib/factory/getAutoBeGenerated.js.map +1 -0
  9. package/lib/index.mjs +1652 -1402
  10. package/lib/index.mjs.map +1 -1
  11. package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.d.ts +2 -7
  12. package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.js +1 -9
  13. package/lib/orchestrate/analyze/AutoBeAnalyzeFileSystem.js.map +1 -1
  14. package/lib/orchestrate/analyze/AutoBeAnalyzeRole.d.ts +13 -0
  15. package/lib/orchestrate/analyze/AutoBeAnalyzeRole.js +3 -0
  16. package/lib/orchestrate/analyze/AutoBeAnalyzeRole.js.map +1 -0
  17. package/lib/orchestrate/analyze/orchestrateAnalyze.d.ts +0 -25
  18. package/lib/orchestrate/analyze/orchestrateAnalyze.js +22 -420
  19. package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
  20. package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.d.ts +6 -0
  21. package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.js +561 -0
  22. package/lib/orchestrate/analyze/orchestrateAnalyzeComposer.js.map +1 -0
  23. package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.d.ts +6 -0
  24. package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js +41 -0
  25. package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js.map +1 -0
  26. package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.d.ts +14 -0
  27. package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js +468 -0
  28. package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js.map +1 -0
  29. package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeComposerApplication.d.ts +68 -0
  30. package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeComposerApplication.js +3 -0
  31. package/lib/orchestrate/analyze/structures/IAutoBeAnalyzeComposerApplication.js.map +1 -0
  32. package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.d.ts +5 -0
  33. package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js +27 -0
  34. package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js.map +1 -0
  35. package/lib/orchestrate/analyze/transformAnalyzeWriteHistories.d.ts +12 -0
  36. package/lib/orchestrate/analyze/transformAnalyzeWriteHistories.js +78 -0
  37. package/lib/orchestrate/analyze/transformAnalyzeWriteHistories.js.map +1 -0
  38. package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.d.ts +6 -0
  39. package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js +58 -0
  40. package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js.map +1 -0
  41. package/lib/orchestrate/interface/orchestrateInterface.js +0 -2
  42. package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
  43. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +17 -137
  44. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +1 -1
  45. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +92 -141
  46. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
  47. package/lib/orchestrate/prisma/orchestratePrisma.js +9 -5
  48. package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -1
  49. package/lib/orchestrate/prisma/orchestratePrismaComponent.js +54 -25
  50. package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -1
  51. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +4 -3
  52. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
  53. package/lib/orchestrate/prisma/{orchestratePrismaSchema.d.ts → orchestratePrismaSchemas.d.ts} +2 -4
  54. package/lib/orchestrate/prisma/{orchestratePrismaSchema.js → orchestratePrismaSchemas.js} +269 -203
  55. package/lib/orchestrate/prisma/orchestratePrismaSchemas.js.map +1 -0
  56. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js +1 -1
  57. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js.map +1 -1
  58. package/lib/orchestrate/prisma/transformPrismaCorrectHistories.js +1 -1
  59. package/lib/orchestrate/prisma/transformPrismaHistories.js +1 -1
  60. package/lib/orchestrate/prisma/transformPrismaHistories.js.map +1 -1
  61. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.d.ts +2 -6
  62. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js +24 -32
  63. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js.map +1 -1
  64. package/lib/orchestrate/realize/RealizePipe.d.ts +5 -0
  65. package/lib/orchestrate/realize/RealizePipe.js +14 -0
  66. package/lib/orchestrate/realize/RealizePipe.js.map +1 -0
  67. package/lib/orchestrate/realize/orchestrateRealize.d.ts +0 -6
  68. package/lib/orchestrate/realize/orchestrateRealize.js +6 -43
  69. package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
  70. package/lib/orchestrate/realize/orchestrateRealizeCoder.d.ts +3 -3
  71. package/lib/orchestrate/realize/orchestrateRealizeCoder.js +124 -59
  72. package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -1
  73. package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.d.ts +188 -18
  74. package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.d.ts +23 -0
  75. package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.js +3 -0
  76. package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.js.map +1 -0
  77. package/lib/orchestrate/realize/structures/IAutoBeRealizeFailedSymbol.d.ts +2 -0
  78. package/lib/orchestrate/realize/structures/IAutoBeRealizeFailedSymbol.js +5 -0
  79. package/lib/orchestrate/realize/structures/IAutoBeRealizeFailedSymbol.js.map +1 -0
  80. package/lib/orchestrate/realize/transformRealizeCoderHistories.d.ts +2 -1
  81. package/lib/orchestrate/realize/transformRealizeCoderHistories.js +50 -36
  82. package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -1
  83. package/lib/orchestrate/realize/writeCodeUntilCompilePassed.d.ts +5 -0
  84. package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js +123 -0
  85. package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js.map +1 -0
  86. package/lib/orchestrate/test/compile/getTestExternalDeclarations.js +4 -1
  87. package/lib/orchestrate/test/compile/getTestExternalDeclarations.js.map +1 -1
  88. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js +2 -1
  89. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js.map +1 -1
  90. package/lib/orchestrate/test/orchestrateTest.js +11 -5
  91. package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
  92. package/lib/orchestrate/test/orchestrateTestCorrect.js +3 -2
  93. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  94. package/lib/orchestrate/test/orchestrateTestWrite.js +22 -13
  95. package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -1
  96. package/lib/structures/IAutoBeProps.d.ts +8 -8
  97. package/lib/utils/pipe.d.ts +5 -0
  98. package/lib/utils/pipe.js +14 -0
  99. package/lib/utils/pipe.js.map +1 -0
  100. package/package.json +6 -6
  101. package/src/AutoBeAgent.ts +22 -76
  102. package/src/constants/AutoBeSystemPromptConstant.ts +11 -6
  103. package/src/context/AutoBeContext.ts +3 -1
  104. package/src/factory/getAutoBeGenerated.ts +113 -0
  105. package/src/orchestrate/analyze/AutoBeAnalyzeFileSystem.ts +5 -13
  106. package/src/orchestrate/analyze/AutoBeAnalyzeRole.ts +14 -0
  107. package/src/orchestrate/analyze/orchestrateAnalyze.ts +30 -165
  108. package/src/orchestrate/analyze/orchestrateAnalyzeComposer.ts +115 -0
  109. package/src/orchestrate/analyze/orchestrateAnalyzeReviewer.ts +39 -0
  110. package/src/orchestrate/analyze/orchestrateAnalyzeWrite.ts +106 -0
  111. package/src/orchestrate/analyze/structures/IAutoBeAnalyzeComposerApplication.ts +74 -0
  112. package/src/orchestrate/analyze/transformAnalyzeReviewerHistories.ts +31 -0
  113. package/src/orchestrate/analyze/transformAnalyzeWriteHistories.ts +94 -0
  114. package/src/orchestrate/analyze/writeDocumentUntilReviewPassed.ts +66 -0
  115. package/src/orchestrate/interface/orchestrateInterface.ts +0 -2
  116. package/src/orchestrate/interface/orchestrateInterfaceComponents.ts +2 -3
  117. package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +21 -0
  118. package/src/orchestrate/prisma/orchestratePrisma.ts +12 -5
  119. package/src/orchestrate/prisma/orchestratePrismaComponent.ts +4 -13
  120. package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +9 -4
  121. package/src/orchestrate/prisma/orchestratePrismaSchemas.ts +265 -0
  122. package/src/orchestrate/prisma/transformPrismaSchemaHistories.ts +26 -37
  123. package/src/orchestrate/realize/RealizePipe.ts +39 -0
  124. package/src/orchestrate/realize/orchestrateRealize.ts +3 -91
  125. package/src/orchestrate/realize/orchestrateRealizeCoder.ts +60 -25
  126. package/src/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.ts +192 -18
  127. package/src/orchestrate/realize/structures/IAutoBeRealizeCompile.ts +34 -0
  128. package/src/orchestrate/realize/structures/IAutoBeRealizeFailedSymbol.ts +2 -0
  129. package/src/orchestrate/realize/transformRealizeCoderHistories.ts +58 -34
  130. package/src/orchestrate/realize/writeCodeUntilCompilePassed.ts +178 -0
  131. package/src/orchestrate/test/compile/getTestExternalDeclarations.ts +5 -4
  132. package/src/orchestrate/test/compile/getTestScenarioArtifacts.ts +7 -2
  133. package/src/orchestrate/test/orchestrateTest.ts +14 -12
  134. package/src/orchestrate/test/orchestrateTestCorrect.ts +10 -9
  135. package/src/orchestrate/test/orchestrateTestWrite.ts +33 -27
  136. package/src/structures/IAutoBeProps.ts +10 -7
  137. package/src/utils/pipe.ts +39 -0
  138. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.d.ts +0 -20
  139. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js +0 -735
  140. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js.map +0 -1
  141. package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.d.ts +0 -15
  142. package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js +0 -44
  143. package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js.map +0 -1
  144. package/lib/orchestrate/prisma/orchestratePrismaSchema.js.map +0 -1
  145. package/src/orchestrate/analyze/AutoBeAnalyzeAgent.ts +0 -219
  146. package/src/orchestrate/analyze/AutoBeAnalyzeReviewer.ts +0 -62
  147. package/src/orchestrate/prisma/orchestratePrismaSchema.ts +0 -157
@@ -0,0 +1,106 @@
1
+ import { IAgenticaController, MicroAgentica } from "@agentica/core";
2
+ import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
3
+ import { IPointer } from "tstl";
4
+ import typia from "typia";
5
+
6
+ import { AutoBeContext } from "../../context/AutoBeContext";
7
+ import { assertSchemaModel } from "../../context/assertSchemaModel";
8
+ import { randomBackoffStrategy } from "../../utils/backoffRetry";
9
+ import { enforceToolCall } from "../../utils/enforceToolCall";
10
+ import {
11
+ AutoBeAnalyzeFileSystem,
12
+ IAutoBeAnalyzeFileSystem,
13
+ IFile,
14
+ } from "./AutoBeAnalyzeFileSystem";
15
+ import {
16
+ AutoBEAnalyzeFileMap,
17
+ AutoBeAnalyzePointer,
18
+ } from "./AutoBeAnalyzePointer";
19
+ import { AutoBeAnalyzeRole } from "./AutoBeAnalyzeRole";
20
+ import { transformAnalyzeWriteHistories } from "./transformAnalyzeWriteHistories";
21
+
22
+ export const orchestrateAnalyzeWrite = <Model extends ILlmSchema.Model>(
23
+ ctx: AutoBeContext<Model>,
24
+ input: {
25
+ /** Total file names */
26
+ totalFiles: Pick<IFile, "filename" | "reason">[];
27
+ targetFile: string;
28
+ roles: AutoBeAnalyzeRole[];
29
+ review: string | null;
30
+ },
31
+ pointer: AutoBeAnalyzePointer,
32
+ isAborted: IPointer<boolean>,
33
+ ): MicroAgentica<Model> => {
34
+ const controller = createController<Model>({
35
+ model: ctx.model,
36
+ execute: new AutoBeAnalyzeFileSystem({ [input.targetFile]: "" as const }),
37
+ build: async (files: AutoBEAnalyzeFileMap) => {
38
+ pointer.value ??= { files: {} };
39
+ Object.assign(pointer.value.files, files);
40
+ },
41
+ abort: () => (isAborted.value = true),
42
+ });
43
+
44
+ const agent = new MicroAgentica({
45
+ controllers: [controller],
46
+ model: ctx.model,
47
+ vendor: ctx.vendor,
48
+ config: {
49
+ locale: ctx.config?.locale,
50
+ backoffStrategy: randomBackoffStrategy,
51
+ executor: {
52
+ describe: null,
53
+ },
54
+ },
55
+ histories: [...transformAnalyzeWriteHistories(ctx, input)],
56
+ });
57
+ enforceToolCall(agent);
58
+ return agent;
59
+ };
60
+
61
+ function createController<Model extends ILlmSchema.Model>(props: {
62
+ model: Model;
63
+ execute: AutoBeAnalyzeFileSystem;
64
+ build: (input: AutoBEAnalyzeFileMap) => void;
65
+ abort: () => void;
66
+ }): IAgenticaController.IClass<Model> {
67
+ assertSchemaModel(props.model);
68
+ const application: ILlmApplication<Model> = collection[
69
+ props.model
70
+ ] as unknown as ILlmApplication<Model>;
71
+ return {
72
+ protocol: "class",
73
+ name: "Planning",
74
+ application,
75
+ execute: {
76
+ abort: (input) => {
77
+ const response = props.execute.abort(input);
78
+ props.abort();
79
+
80
+ return response;
81
+ },
82
+ createOrUpdateFiles: async (input) => {
83
+ const fileMap = await props.execute.createOrUpdateFiles(input);
84
+ props.build(fileMap);
85
+ return fileMap;
86
+ },
87
+ } satisfies IAutoBeAnalyzeFileSystem,
88
+ };
89
+ }
90
+
91
+ const claude = typia.llm.application<
92
+ AutoBeAnalyzeFileSystem,
93
+ "claude",
94
+ { reference: true }
95
+ >();
96
+ const collection = {
97
+ chatgpt: typia.llm.application<
98
+ AutoBeAnalyzeFileSystem,
99
+ "chatgpt",
100
+ { reference: true }
101
+ >(),
102
+ claude,
103
+ llama: claude,
104
+ deepseek: claude,
105
+ "3.1": claude,
106
+ };
@@ -0,0 +1,74 @@
1
+ import { IFile } from "../AutoBeAnalyzeFileSystem";
2
+ import { AutoBeAnalyzeRole } from "../AutoBeAnalyzeRole";
3
+
4
+ export interface IComposeInput {
5
+ /** Reason for the analysis and composition of the project structure. */
6
+ reason: string;
7
+
8
+ /**
9
+ * Prefix for file names and all prisma schema files, table, interface, and
10
+ * variable names.
11
+ */
12
+ prefix: string;
13
+
14
+ /** Roles to be assigned for the project */
15
+ roles: AutoBeAnalyzeRole[];
16
+
17
+ /**
18
+ * If the user has requested a specific number of pages, enter that number.
19
+ * Otherwise, provide an appropriate number of documents needed to meet the
20
+ * user's requirements. This number must always match the length of the files
21
+ * property, must be greater than 1, and must include the table of contents.
22
+ * For example, if the user requests 3 pages, the total should be 4, including
23
+ * the table of contents.
24
+ */
25
+ page: number;
26
+
27
+ /**
28
+ * # Document files to be generated
29
+ *
30
+ * File name must be English and it must contain the numbering and prefix.
31
+ *
32
+ * These files represent business documentation that may include:
33
+ *
34
+ * - Business requirements and functional specifications
35
+ * - User journey mapping and use case scenarios
36
+ * - Business rules and workflow definitions
37
+ * - Service architecture and system design overview
38
+ * - Data flow and integration requirements
39
+ * - User roles and permission matrix
40
+ * - API endpoint specifications and contracts
41
+ * - Business logic and validation rules
42
+ *
43
+ * Generate files based on actual requirements gathered from conversation. Do
44
+ * not create unnecessary documentation - only generate what is needed to
45
+ * properly define the business requirements and system specifications.
46
+ *
47
+ * # Page Length Rules
48
+ *
49
+ * The number of documents must match the user's request, excluding the table
50
+ * of contents. For example, if the user requests 3 pages, a total of 4
51
+ * documents should be generated, including the table of contents. If the user
52
+ * does not specify a number, generate a sufficient number of documents to
53
+ * adequately support the service.
54
+ */
55
+ files: Array<Pick<IFile, "filename" | "reason">>;
56
+ }
57
+
58
+ export interface IAutoBeAnalyzeComposerApplication {
59
+ /**
60
+ * Compose project structure with roles and files.
61
+ *
62
+ * Design a list of roles and initial documents that you need to create for
63
+ * that requirement. Roles define team member responsibilities, while files
64
+ * define the documentation structure. These are managed separately. If you
65
+ * determine from the conversation that the user's requirements have not been
66
+ * fully gathered, you must stop the analysis and continue collecting the
67
+ * remaining requirements. In this case, you do not need to generate any files
68
+ * or roles. Simply pass an empty array to `input.files` and `input.roles`.
69
+ *
70
+ * @param input Prefix, roles, and files
71
+ * @returns
72
+ */
73
+ compose(input: IComposeInput): IComposeInput;
74
+ }
@@ -0,0 +1,31 @@
1
+ import { IAgenticaHistoryJson } from "@agentica/core";
2
+ import { v4 } from "uuid";
3
+
4
+ import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
5
+
6
+ export const transformAnalyzeReviewerHistories = (input: {
7
+ /** Total file names */
8
+ files: Record<string, string>;
9
+ }): Array<
10
+ IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
11
+ > => {
12
+ return [
13
+ {
14
+ id: v4(),
15
+ created_at: new Date().toISOString(),
16
+ type: "assistantMessage",
17
+ text: [
18
+ "Below are all of the files.",
19
+ "```json",
20
+ JSON.stringify(input.files),
21
+ "```",
22
+ ].join("\n"),
23
+ },
24
+ {
25
+ id: v4(),
26
+ created_at: new Date().toISOString(),
27
+ type: "systemMessage",
28
+ text: AutoBeSystemPromptConstant.ANALYZE_REVIEWER,
29
+ },
30
+ ];
31
+ };
@@ -0,0 +1,94 @@
1
+ import { IAgenticaHistoryJson } from "@agentica/core";
2
+ import { ILlmSchema } from "@samchon/openapi";
3
+ import { v4 } from "uuid";
4
+
5
+ import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
6
+ import { AutoBeContext } from "../../context/AutoBeContext";
7
+ import { IFile } from "./AutoBeAnalyzeFileSystem";
8
+ import { AutoBeAnalyzeRole } from "./AutoBeAnalyzeRole";
9
+
10
+ export const transformAnalyzeWriteHistories = <Model extends ILlmSchema.Model>(
11
+ ctx: AutoBeContext<Model>,
12
+ input: {
13
+ /** Total file names */
14
+ totalFiles: Pick<IFile, "filename" | "reason">[];
15
+ targetFile: string;
16
+ roles: AutoBeAnalyzeRole[];
17
+ review: string | null;
18
+ },
19
+ ): Array<
20
+ IAgenticaHistoryJson.IAssistantMessage | IAgenticaHistoryJson.ISystemMessage
21
+ > => {
22
+ return [
23
+ ...(input.review !== null
24
+ ? ([
25
+ {
26
+ id: v4(),
27
+ created_at: new Date().toISOString(),
28
+ type: "assistantMessage",
29
+ text: [
30
+ input.totalFiles.find((el) => el.filename === input.targetFile),
31
+ ].join("\n"),
32
+ },
33
+ {
34
+ id: v4(),
35
+ created_at: new Date().toISOString(),
36
+ type: "assistantMessage",
37
+ text: [
38
+ `You previously wrote a piece of content.`,
39
+ `The following review has been received regarding your writing:`,
40
+ input.review,
41
+ `You must revise your content to reflect the feedback in this review.`,
42
+ ].join(),
43
+ },
44
+ ] as const)
45
+ : []),
46
+ {
47
+ id: v4(),
48
+ created_at: new Date().toISOString(),
49
+ type: "systemMessage",
50
+ text: AutoBeSystemPromptConstant.ANALYZE.replace(
51
+ "{% User Locale %}",
52
+ ctx.config?.locale ?? "en-US",
53
+ ),
54
+ },
55
+ {
56
+ id: v4(),
57
+ created_at: new Date().toISOString(),
58
+ type: "systemMessage",
59
+ text: [
60
+ "# Guidelines",
61
+ "If the user specifies the exact number of pages, please follow it precisely.",
62
+ AutoBeSystemPromptConstant.ANALYZE_GUIDELINE,
63
+ ].join("\n"),
64
+ },
65
+ {
66
+ id: v4(),
67
+ created_at: new Date().toISOString(),
68
+ type: "systemMessage",
69
+ text: [
70
+ `# Instruction`,
71
+ `The names of all the files are as follows: ${input.totalFiles
72
+ .map((f) => f.filename)
73
+ .join(",")}`,
74
+ "Assume that all files are in the same folder. Also, when pointing to the location of a file, go to the relative path.",
75
+ "",
76
+ `The following user roles have been defined for this system:`,
77
+ ...input.roles.map((role) => `- ${role.name}: ${role.description}`),
78
+ "These roles will be used for API authentication and should be considered when creating documentation.",
79
+ "",
80
+ `Document Length Specification:`,
81
+ `- You are responsible for writing ONLY ONE document: ${input.targetFile}`,
82
+ `- Each page should contain approximately 2,000 characters`,
83
+ `- DO NOT write content for other documents - focus only on ${input.targetFile}`,
84
+ "",
85
+ `Among the various documents, the part you decided to take care of is as follows.: ${input.targetFile}`,
86
+ `Only write this document named '${input.targetFile}'.`,
87
+ "Never write other documents.",
88
+ "",
89
+ "# Reason to write this document",
90
+ `- ${input.totalFiles.find((el) => el.filename === input.targetFile)?.reason}`,
91
+ ].join("\n"),
92
+ },
93
+ ];
94
+ };
@@ -0,0 +1,66 @@
1
+ import { ILlmSchema } from "@samchon/openapi";
2
+ import { IPointer } from "tstl";
3
+
4
+ import { AutoBeContext } from "../../context/AutoBeContext";
5
+ import { IFile } from "./AutoBeAnalyzeFileSystem";
6
+ import { AutoBeAnalyzePointer } from "./AutoBeAnalyzePointer";
7
+ import { AutoBeAnalyzeRole } from "./AutoBeAnalyzeRole";
8
+ import { orchestrateAnalyzeReviewer } from "./orchestrateAnalyzeReviewer";
9
+ import { orchestrateAnalyzeWrite } from "./orchestrateAnalyzeWrite";
10
+
11
+ export async function writeDocumentUntilReviewPassed<
12
+ Model extends ILlmSchema.Model,
13
+ >(
14
+ ctx: AutoBeContext<Model>,
15
+ pointer: AutoBeAnalyzePointer,
16
+ totalFiles: Pick<IFile, "filename" | "reason">[],
17
+ filename: string,
18
+ roles: AutoBeAnalyzeRole[],
19
+ retry = 3,
20
+ ): Promise<AutoBeAnalyzePointer> {
21
+ const isAborted: IPointer<boolean> = { value: false };
22
+ let review: string | null = null;
23
+ for (let i = 0; i < retry; i++) {
24
+ if (isAborted.value === true) {
25
+ return pointer;
26
+ }
27
+
28
+ // Write the document until the review is passed.
29
+ const write = "Write Document OR Abort." as const;
30
+ const writer = orchestrateAnalyzeWrite(
31
+ ctx,
32
+ {
33
+ totalFiles: totalFiles,
34
+ roles: roles,
35
+ targetFile: filename,
36
+ review,
37
+ },
38
+ pointer,
39
+ isAborted,
40
+ );
41
+ await writer.conversate(review ?? write).finally(() => {
42
+ const tokenUsage = writer.getTokenUsage();
43
+ ctx.usage().record(tokenUsage, ["analyze"]);
44
+ });
45
+ if (pointer.value === null) {
46
+ throw new Error("Failed to write document by unknown reason.");
47
+ }
48
+ ctx.dispatch({
49
+ type: "analyzeWrite",
50
+ files: pointer.value.files,
51
+ step: ctx.state().analyze?.step ?? 0,
52
+ created_at: new Date().toISOString(),
53
+ });
54
+
55
+ // Do review
56
+ review = await orchestrateAnalyzeReviewer(ctx, pointer.value);
57
+ if (review !== null)
58
+ ctx.dispatch({
59
+ type: "analyzeReview",
60
+ review,
61
+ step: ctx.state().analyze?.step ?? 0,
62
+ created_at: new Date().toISOString(),
63
+ });
64
+ }
65
+ return pointer;
66
+ }
@@ -53,7 +53,6 @@ export const orchestrateInterface =
53
53
  type: "interface",
54
54
  id: v4(),
55
55
  document,
56
- files: await ctx.compiler.interface.compile(document),
57
56
  reason: props.reason,
58
57
  step: ctx.state().analyze?.step ?? 0,
59
58
  created_at: start.toISOString(),
@@ -63,7 +62,6 @@ export const orchestrateInterface =
63
62
  ctx.histories().push(result);
64
63
  ctx.dispatch({
65
64
  type: "interfaceComplete",
66
- files: result.files,
67
65
  document: result.document,
68
66
  created_at: start.toISOString(),
69
67
  reason: props.reason,
@@ -34,6 +34,7 @@ export async function orchestrateInterfaceComponents<
34
34
 
35
35
  const x: AutoBeOpenApi.IComponents = {
36
36
  schemas: {},
37
+ authorization: ctx.state().analyze?.roles,
37
38
  };
38
39
  for (const y of await Promise.all(
39
40
  matrix.map(async (it) => {
@@ -58,7 +59,6 @@ export async function orchestrateInterfaceComponents<
58
59
  }),
59
60
  )) {
60
61
  Object.assign(x.schemas, y.schemas);
61
- if (y.authorization) x.authorization = y.authorization;
62
62
  }
63
63
  return x;
64
64
  }
@@ -132,7 +132,6 @@ async function process<Model extends ILlmSchema.Model>(
132
132
  pointer.value ??= {
133
133
  schemas: {},
134
134
  };
135
- pointer.value.authorization ??= components.authorization;
136
135
  Object.assign(pointer.value.schemas, components.schemas);
137
136
  },
138
137
  pointer,
@@ -289,5 +288,5 @@ interface IMakeComponentsProps {
289
288
  * }
290
289
  * ```
291
290
  */
292
- components: AutoBeOpenApi.IComponents;
291
+ components: Omit<AutoBeOpenApi.IComponents, "authorization">;
293
292
  }
@@ -88,6 +88,7 @@ async function process<Model extends ILlmSchema.Model>(
88
88
  const pointer: IPointer<AutoBeOpenApi.IOperation[] | null> = {
89
89
  value: null,
90
90
  };
91
+
91
92
  const agentica: MicroAgentica<Model> = new MicroAgentica({
92
93
  model: ctx.model,
93
94
  vendor: ctx.vendor,
@@ -104,6 +105,7 @@ async function process<Model extends ILlmSchema.Model>(
104
105
  controllers: [
105
106
  createApplication({
106
107
  model: ctx.model,
108
+ roles: ctx.state().analyze?.roles.map((it) => it.name) ?? null,
107
109
  build: (endpoints) => {
108
110
  pointer.value ??= [];
109
111
  pointer.value.push(...endpoints);
@@ -132,6 +134,7 @@ async function process<Model extends ILlmSchema.Model>(
132
134
 
133
135
  function createApplication<Model extends ILlmSchema.Model>(props: {
134
136
  model: Model;
137
+ roles: string[] | null;
135
138
  build: (operations: AutoBeOpenApi.IOperation[]) => void;
136
139
  }): IAgenticaController.IClass<Model> {
137
140
  assertSchemaModel(props.model);
@@ -153,6 +156,24 @@ function createApplication<Model extends ILlmSchema.Model>(props: {
153
156
  "GET method should not have request body. Change method, or re-design the operation.",
154
157
  value: op.requestBody,
155
158
  });
159
+ op.authorizationRoles?.forEach((role, j) => {
160
+ if (props.roles === null) {
161
+ op.authorizationRoles = null;
162
+ }
163
+ if (props.roles?.find((it) => it === role) === undefined)
164
+ errors.push({
165
+ path: `operations[${i}].authorizationRoles[${j}]`,
166
+ expected: `undefined | ${props.roles?.join(" | ")}`,
167
+ description: [
168
+ `Role "${role}" is not defined in the roles list.`,
169
+ "",
170
+ "Please select one of them below, or do not define (undefined): ",
171
+ "",
172
+ ...(props.roles ?? []).map((role) => `- ${role}`),
173
+ ].join("\n"),
174
+ value: role,
175
+ });
176
+ });
156
177
  });
157
178
  if (errors.length !== 0)
158
179
  return {
@@ -3,6 +3,7 @@ import {
3
3
  AutoBePrismaCompleteEvent,
4
4
  AutoBePrismaComponentsEvent,
5
5
  AutoBePrismaHistory,
6
+ IAutoBeCompiler,
6
7
  IAutoBePrismaValidation,
7
8
  } from "@autobe/interface";
8
9
  import { AutoBePrismaSchemasEvent } from "@autobe/interface/src/events/AutoBePrismaSchemasEvent";
@@ -13,7 +14,7 @@ import { AutoBeContext } from "../../context/AutoBeContext";
13
14
  import { IAutoBeApplicationProps } from "../../context/IAutoBeApplicationProps";
14
15
  import { orchestratePrismaComponents } from "./orchestratePrismaComponent";
15
16
  import { orchestratePrismaCorrect } from "./orchestratePrismaCorrect";
16
- import { orchestratePrismaSchemas } from "./orchestratePrismaSchema";
17
+ import { orchestratePrismaSchemas } from "./orchestratePrismaSchemas";
17
18
 
18
19
  export const orchestratePrisma =
19
20
  <Model extends ILlmSchema.Model>(ctx: AutoBeContext<Model>) =>
@@ -38,21 +39,28 @@ export const orchestratePrisma =
38
39
  return components;
39
40
  } else ctx.dispatch(components);
40
41
 
41
- // SCHEMAS
42
+ // CONSTRUCT AST DATA
42
43
  const events: AutoBePrismaSchemasEvent[] = await orchestratePrismaSchemas(
43
44
  ctx,
44
45
  components.components,
45
46
  );
47
+
48
+ // VALIDATE
46
49
  const result: IAutoBePrismaValidation = await orchestratePrismaCorrect(
47
50
  ctx,
48
51
  {
49
52
  files: events.map((e) => e.file),
50
53
  },
51
54
  );
52
- const schemas: Record<string, string> = await ctx.compiler.prisma.write(
55
+
56
+ // COMPILE
57
+ const compiler: IAutoBeCompiler = await ctx.compiler();
58
+ const schemas: Record<string, string> = await compiler.prisma.write(
53
59
  result.data,
54
60
  "postgres",
55
61
  );
62
+
63
+ // PROPAGATE
56
64
  const history: AutoBePrismaHistory = {
57
65
  type: "prisma",
58
66
  id: v4(),
@@ -62,14 +70,13 @@ export const orchestratePrisma =
62
70
  description: "",
63
71
  result: result,
64
72
  schemas,
65
- compiled: await ctx.compiler.prisma.compile({
73
+ compiled: await compiler.prisma.compile({
66
74
  files: schemas,
67
75
  }),
68
76
  step: ctx.state().analyze?.step ?? 0,
69
77
  };
70
78
  ctx.state().prisma = history;
71
79
  ctx.histories().push(history);
72
-
73
80
  if (history.result.success === true)
74
81
  ctx.dispatch({
75
82
  type: "prismaComplete",
@@ -4,11 +4,11 @@ import {
4
4
  MicroAgentica,
5
5
  MicroAgenticaHistory,
6
6
  } from "@agentica/core";
7
- import { AutoBeAssistantMessageHistory } from "@autobe/interface";
7
+ import { AutoBeAssistantMessageHistory, AutoBePrisma } from "@autobe/interface";
8
8
  import { AutoBePrismaComponentsEvent } from "@autobe/interface/src/events/AutoBePrismaComponentsEvent";
9
9
  import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
10
10
  import { IPointer } from "tstl";
11
- import typia, { tags } from "typia";
11
+ import typia from "typia";
12
12
  import { v4 } from "uuid";
13
13
 
14
14
  import { AutoBeContext } from "../../context/AutoBeContext";
@@ -25,8 +25,7 @@ export async function orchestratePrismaComponents<
25
25
  const pointer: IPointer<IExtractComponentsProps | null> = {
26
26
  value: null,
27
27
  };
28
-
29
- const prefix = ctx.state().analyze?.prefix ?? null;
28
+ const prefix: string | null = ctx.state().analyze?.prefix ?? null;
30
29
 
31
30
  const agentica: MicroAgentica<Model> = new MicroAgentica({
32
31
  model: ctx.model,
@@ -178,13 +177,5 @@ interface IExtractComponentsProps {
178
177
  * - Keep mapping synchronized with actual schema files
179
178
  * - Use consistent naming convention for files
180
179
  */
181
- components: IComponent[];
182
- }
183
-
184
- interface IComponent {
185
- /** Filename of the Prisma schema file. */
186
- filename: string & tags.Pattern<"^[a-zA-Z0-9._-]+\\.prisma$">;
187
-
188
- /** List of table names that would be stored in the file. */
189
- tables: Array<string & tags.Pattern<"^[a-z][a-z0-9_]*$">>;
180
+ components: AutoBePrisma.IComponent[];
190
181
  }
@@ -1,5 +1,9 @@
1
1
  import { IAgenticaController, MicroAgentica } from "@agentica/core";
2
- import { AutoBePrisma, IAutoBePrismaValidation } from "@autobe/interface";
2
+ import {
3
+ AutoBePrisma,
4
+ IAutoBeCompiler,
5
+ IAutoBePrismaValidation,
6
+ } from "@autobe/interface";
3
7
  import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
4
8
  import { IPointer } from "tstl";
5
9
  import typia from "typia";
@@ -30,14 +34,15 @@ async function step<Model extends ILlmSchema.Model>(
30
34
  application: AutoBePrisma.IApplication,
31
35
  life: number,
32
36
  ): Promise<IAutoBePrismaValidation> {
37
+ const compiler: IAutoBeCompiler = await ctx.compiler();
33
38
  const result: IAutoBePrismaValidation =
34
- await ctx.compiler.prisma.validate(application);
39
+ await compiler.prisma.validate(application);
35
40
  if (result.success)
36
41
  return result; // SUCCESS
37
42
  else if (life <= 0) return result; // FAILURE
38
43
 
39
44
  // VALIDATION FAILED
40
- const schemas: Record<string, string> = await ctx.compiler.prisma.write(
45
+ const schemas: Record<string, string> = await compiler.prisma.write(
41
46
  application,
42
47
  "postgres",
43
48
  );
@@ -45,7 +50,7 @@ async function step<Model extends ILlmSchema.Model>(
45
50
  type: "prismaValidate",
46
51
  result,
47
52
  schemas,
48
- compiled: await ctx.compiler.prisma.compile({
53
+ compiled: await compiler.prisma.compile({
49
54
  files: schemas,
50
55
  }),
51
56
  step: ctx.state().analyze?.step ?? 0,