@autobe/agent 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/lib/AutoBeAgent.js +11 -4
  2. package/lib/AutoBeAgent.js.map +1 -1
  3. package/lib/constants/AutoBeSystemPromptConstant.d.ts +6 -6
  4. package/lib/context/AutoBeTokenUsage.d.ts +15 -1
  5. package/lib/context/AutoBeTokenUsage.js +56 -1
  6. package/lib/context/AutoBeTokenUsage.js.map +1 -1
  7. package/lib/factory/createAutoBeApplication.js +288 -643
  8. package/lib/factory/createAutoBeApplication.js.map +1 -1
  9. package/lib/index.mjs +5057 -7211
  10. package/lib/index.mjs.map +1 -1
  11. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js +82 -319
  12. package/lib/orchestrate/analyze/AutoBeAnalyzeAgent.js.map +1 -1
  13. package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js +0 -1
  14. package/lib/orchestrate/analyze/AutoBeAnalyzeReviewer.js.map +1 -1
  15. package/lib/orchestrate/analyze/orchestrateAnalyze.js +95 -266
  16. package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
  17. package/lib/orchestrate/facade/transformFacadeStateMessage.js +2 -2
  18. package/lib/orchestrate/facade/transformFacadeStateMessage.js.map +1 -1
  19. package/lib/orchestrate/index.d.ts +2 -2
  20. package/lib/orchestrate/index.js +4 -4
  21. package/lib/orchestrate/index.js.map +1 -1
  22. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +56 -142
  23. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
  24. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +195 -199
  25. package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +1 -1
  26. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +75 -172
  27. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
  28. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +772 -1097
  29. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
  30. package/lib/orchestrate/interface/transformInterfaceHistories.js +2 -0
  31. package/lib/orchestrate/interface/transformInterfaceHistories.js.map +1 -1
  32. package/lib/orchestrate/prisma/orchestratePrismaComponent.js +64 -175
  33. package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -1
  34. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +552 -1073
  35. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
  36. package/lib/orchestrate/prisma/orchestratePrismaSchema.js +571 -1119
  37. package/lib/orchestrate/prisma/orchestratePrismaSchema.js.map +1 -1
  38. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js +9 -0
  39. package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js.map +1 -1
  40. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js +8 -0
  41. package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js.map +1 -1
  42. package/lib/orchestrate/realize/orchestrateRealize.d.ts +11 -0
  43. package/lib/orchestrate/realize/orchestrateRealize.js +109 -0
  44. package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -0
  45. package/lib/orchestrate/realize/orchestrateRealizeCoder.d.ts +25 -0
  46. package/lib/orchestrate/realize/orchestrateRealizeCoder.js +337 -0
  47. package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -0
  48. package/lib/orchestrate/realize/orchestrateRealizeIntegrator.d.ts +52 -0
  49. package/lib/orchestrate/realize/orchestrateRealizeIntegrator.js +57 -0
  50. package/lib/orchestrate/realize/orchestrateRealizeIntegrator.js.map +1 -0
  51. package/lib/orchestrate/realize/orchestrateRealizePlanner.d.ts +80 -0
  52. package/lib/orchestrate/realize/orchestrateRealizePlanner.js +53 -0
  53. package/lib/orchestrate/realize/orchestrateRealizePlanner.js.map +1 -0
  54. package/lib/orchestrate/realize/orchestrateRealizeValidator.d.ts +46 -0
  55. package/lib/orchestrate/realize/orchestrateRealizeValidator.js +37 -0
  56. package/lib/orchestrate/realize/orchestrateRealizeValidator.js.map +1 -0
  57. package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.d.ts +33 -0
  58. package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.js +3 -0
  59. package/lib/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.js.map +1 -0
  60. package/lib/orchestrate/realize/transformRealizeCoderHistories.d.ts +5 -0
  61. package/lib/orchestrate/realize/transformRealizeCoderHistories.js +127 -0
  62. package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -0
  63. package/lib/orchestrate/test/compile/completeTestCode.d.ts +2 -0
  64. package/lib/orchestrate/test/compile/completeTestCode.js +21 -0
  65. package/lib/orchestrate/test/compile/completeTestCode.js.map +1 -0
  66. package/lib/orchestrate/test/{filterTestFileName.js → compile/filterTestFileName.js} +1 -1
  67. package/lib/orchestrate/test/compile/filterTestFileName.js.map +1 -0
  68. package/lib/orchestrate/test/compile/getTestExternalDeclarations.d.ts +3 -0
  69. package/lib/orchestrate/test/compile/getTestExternalDeclarations.js +27 -0
  70. package/lib/orchestrate/test/compile/getTestExternalDeclarations.js.map +1 -0
  71. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.d.ts +5 -0
  72. package/lib/orchestrate/test/{compileTestScenario.js → compile/getTestScenarioArtifacts.js} +10 -5
  73. package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js.map +1 -0
  74. package/lib/orchestrate/test/orchestrateTest.js +14 -9
  75. package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
  76. package/lib/orchestrate/test/orchestrateTestCorrect.d.ts +3 -2
  77. package/lib/orchestrate/test/orchestrateTestCorrect.js +150 -448
  78. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  79. package/lib/orchestrate/test/orchestrateTestScenario.js +272 -530
  80. package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
  81. package/lib/orchestrate/test/orchestrateTestWrite.d.ts +3 -2
  82. package/lib/orchestrate/test/orchestrateTestWrite.js +139 -90
  83. package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -1
  84. package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.d.ts +121 -0
  85. package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.js +3 -0
  86. package/lib/orchestrate/test/structures/IAutoBeTestCorrectApplication.js.map +1 -0
  87. package/lib/orchestrate/test/structures/IAutoBeTestFunction.d.ts +8 -0
  88. package/lib/{utils/types/BackoffOptions.js → orchestrate/test/structures/IAutoBeTestFunction.js} +1 -1
  89. package/lib/orchestrate/test/structures/IAutoBeTestFunction.js.map +1 -0
  90. package/lib/orchestrate/test/structures/IAutoBeTestScenarioApplication.d.ts +14 -2
  91. package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.d.ts +112 -0
  92. package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.js +3 -0
  93. package/lib/orchestrate/test/structures/IAutoBeTestWriteApplication.js.map +1 -0
  94. package/lib/orchestrate/test/structures/IAutoBeTestWriteResult.d.ts +7 -0
  95. package/lib/orchestrate/test/structures/IAutoBeTestWriteResult.js +3 -0
  96. package/lib/orchestrate/test/structures/IAutoBeTestWriteResult.js.map +1 -0
  97. package/lib/orchestrate/test/transformTestCorrectHistories.d.ts +3 -2
  98. package/lib/orchestrate/test/transformTestCorrectHistories.js +28 -67
  99. package/lib/orchestrate/test/transformTestCorrectHistories.js.map +1 -1
  100. package/lib/orchestrate/test/transformTestWriteHistories.d.ts +5 -4
  101. package/lib/orchestrate/test/transformTestWriteHistories.js +168 -43
  102. package/lib/orchestrate/test/transformTestWriteHistories.js.map +1 -1
  103. package/lib/structures/IAutoBeConfig.d.ts +11 -0
  104. package/lib/utils/backoffRetry.d.ts +4 -7
  105. package/lib/utils/backoffRetry.js +19 -37
  106. package/lib/utils/backoffRetry.js.map +1 -1
  107. package/lib/utils/forceRetry.d.ts +1 -0
  108. package/lib/{orchestrate/orchestrateRealize.js → utils/forceRetry.js} +15 -8
  109. package/lib/utils/forceRetry.js.map +1 -0
  110. package/package.json +8 -7
  111. package/src/AutoBeAgent.ts +17 -3
  112. package/src/constants/AutoBeSystemPromptConstant.ts +6 -6
  113. package/src/context/AutoBeTokenUsage.ts +85 -1
  114. package/src/factory/createAutoBeApplication.ts +2 -3
  115. package/src/orchestrate/analyze/AutoBeAnalyzeAgent.ts +8 -3
  116. package/src/orchestrate/analyze/AutoBeAnalyzeReviewer.ts +0 -1
  117. package/src/orchestrate/analyze/orchestrateAnalyze.ts +6 -5
  118. package/src/orchestrate/facade/transformFacadeStateMessage.ts +2 -1
  119. package/src/orchestrate/index.ts +2 -2
  120. package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +4 -3
  121. package/src/orchestrate/interface/orchestrateInterfaceComponents.ts +26 -23
  122. package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +6 -4
  123. package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +14 -11
  124. package/src/orchestrate/interface/transformInterfaceHistories.ts +2 -0
  125. package/src/orchestrate/prisma/orchestratePrismaComponent.ts +10 -5
  126. package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +11 -5
  127. package/src/orchestrate/prisma/orchestratePrismaSchema.ts +16 -8
  128. package/src/orchestrate/prisma/transformPrismaComponentsHistories.ts +9 -0
  129. package/src/orchestrate/prisma/transformPrismaSchemaHistories.ts +8 -0
  130. package/src/orchestrate/realize/orchestrateRealize.ts +169 -0
  131. package/src/orchestrate/realize/orchestrateRealizeCoder.ts +156 -0
  132. package/src/orchestrate/realize/orchestrateRealizeIntegrator.ts +75 -0
  133. package/src/orchestrate/realize/orchestrateRealizePlanner.ts +115 -0
  134. package/src/orchestrate/realize/orchestrateRealizeValidator.ts +64 -0
  135. package/src/orchestrate/realize/structures/IAutoBeRealizeCoderApplication.ts +36 -0
  136. package/src/orchestrate/realize/transformRealizeCoderHistories.ts +136 -0
  137. package/src/orchestrate/test/compile/completeTestCode.ts +35 -0
  138. package/src/orchestrate/test/{filterTestFileName.ts → compile/filterTestFileName.ts} +1 -1
  139. package/src/orchestrate/test/compile/getTestExternalDeclarations.ts +24 -0
  140. package/src/orchestrate/test/{compileTestScenario.ts → compile/getTestScenarioArtifacts.ts} +16 -8
  141. package/src/orchestrate/test/experimental/orchestrateTestCorrect.ast +240 -0
  142. package/src/orchestrate/test/experimental/orchestrateTestWrite.ast +316 -0
  143. package/src/orchestrate/test/experimental/transformTestCorrectHistories.ast +52 -0
  144. package/src/orchestrate/test/orchestrateTest.ts +33 -16
  145. package/src/orchestrate/test/orchestrateTestCorrect.ts +109 -497
  146. package/src/orchestrate/test/orchestrateTestScenario.ts +102 -71
  147. package/src/orchestrate/test/orchestrateTestWrite.ts +55 -181
  148. package/src/orchestrate/test/structures/IAutoBeTestCorrectApplication.ts +126 -0
  149. package/src/orchestrate/test/structures/IAutoBeTestFunction.ts +10 -0
  150. package/src/orchestrate/test/structures/IAutoBeTestScenarioApplication.ts +14 -2
  151. package/src/orchestrate/test/structures/IAutoBeTestWriteApplication.ts +117 -0
  152. package/src/orchestrate/test/structures/IAutoBeTestWriteResult.ts +9 -0
  153. package/src/orchestrate/test/transformTestCorrectHistories.ts +38 -71
  154. package/src/orchestrate/test/transformTestWriteHistories.ts +88 -46
  155. package/src/structures/IAutoBeConfig.ts +9 -0
  156. package/src/utils/backoffRetry.ts +25 -36
  157. package/src/utils/forceRetry.ts +13 -0
  158. package/lib/factory/invertOpenApiDocument.d.ts +0 -3
  159. package/lib/factory/invertOpenApiDocument.js +0 -51
  160. package/lib/factory/invertOpenApiDocument.js.map +0 -1
  161. package/lib/orchestrate/orchestrateRealize.d.ts +0 -5
  162. package/lib/orchestrate/orchestrateRealize.js.map +0 -1
  163. package/lib/orchestrate/test/compileTestScenario.d.ts +0 -5
  164. package/lib/orchestrate/test/compileTestScenario.js.map +0 -1
  165. package/lib/orchestrate/test/filterTestFileName.js.map +0 -1
  166. package/lib/utils/StringUtil.d.ts +0 -4
  167. package/lib/utils/StringUtil.js +0 -43
  168. package/lib/utils/StringUtil.js.map +0 -1
  169. package/lib/utils/types/BackoffOptions.d.ts +0 -12
  170. package/lib/utils/types/BackoffOptions.js.map +0 -1
  171. package/src/factory/invertOpenApiDocument.ts +0 -63
  172. package/src/orchestrate/orchestrateRealize.ts +0 -18
  173. package/src/utils/StringUtil.ts +0 -45
  174. package/src/utils/types/BackoffOptions.ts +0 -15
  175. /package/lib/orchestrate/test/{filterTestFileName.d.ts → compile/filterTestFileName.d.ts} +0 -0
@@ -0,0 +1,169 @@
1
+ import {
2
+ AutoBeAssistantMessageHistory,
3
+ AutoBeRealizeHistory,
4
+ } from "@autobe/interface";
5
+ import { ILlmSchema } from "@samchon/openapi";
6
+ import { v4 } from "uuid";
7
+
8
+ import { AutoBeContext } from "../../context/AutoBeContext";
9
+ import { IAutoBeApplicationProps } from "../../context/IAutoBeApplicationProps";
10
+ import { orchestrateRealizeCoder } from "./orchestrateRealizeCoder";
11
+ import { orchestrateRealizeIntegrator } from "./orchestrateRealizeIntegrator";
12
+ import { orchestrateRealizePlanner } from "./orchestrateRealizePlanner";
13
+ import {
14
+ RealizeValidatorOutput,
15
+ orchestrateRealizeValidator,
16
+ } from "./orchestrateRealizeValidator";
17
+ import { IAutoBeRealizeCoderApplication } from "./structures/IAutoBeRealizeCoderApplication";
18
+
19
+ export const orchestrateRealize =
20
+ <Model extends ILlmSchema.Model>(ctx: AutoBeContext<Model>) =>
21
+ async (
22
+ props: IAutoBeApplicationProps,
23
+ ): Promise<AutoBeAssistantMessageHistory | AutoBeRealizeHistory> => {
24
+ props;
25
+
26
+ const ops = ctx.state().interface?.document.operations;
27
+ if (!ops) {
28
+ throw new Error();
29
+ }
30
+
31
+ const codes: (
32
+ | IAutoBeRealizeCoderApplication.RealizeCoderOutput
33
+ | FAILED
34
+ )[] = await Promise.all(
35
+ ops.map(async (op) =>
36
+ pipe(
37
+ op,
38
+ (op) => orchestrateRealizePlanner(ctx, op),
39
+ (p) => orchestrateRealizeCoder(ctx, op, p),
40
+ ),
41
+ ),
42
+ );
43
+
44
+ const vaildates: (RealizeValidatorOutput | FAILED)[] = await Promise.all(
45
+ codes
46
+ .filter((el) => el !== FAILED)
47
+ .map(async (c) =>
48
+ pipe(
49
+ c,
50
+ (c) => orchestrateRealizeIntegrator(ctx, c),
51
+ (i) => orchestrateRealizeValidator(ctx, i),
52
+ ),
53
+ ),
54
+ );
55
+
56
+ if (vaildates.length) {
57
+ if (vaildates.every((v) => v !== FAILED)) {
58
+ const files = {
59
+ ...ctx.state().interface?.files,
60
+ ...vaildates
61
+ .map((v) => ({ [v.location]: v.content }))
62
+ .reduce((acc, cur) => Object.assign(acc, cur), {}),
63
+ };
64
+
65
+ const compiled = await ctx.compiler.typescript.compile({ files });
66
+
67
+ const now = new Date().toISOString();
68
+ ctx.dispatch({
69
+ type: "realizeComplete",
70
+ compiled: compiled,
71
+ created_at: now,
72
+ files: files,
73
+ step: ctx.state().analyze?.step ?? 0,
74
+ });
75
+
76
+ return {
77
+ id: v4(),
78
+ type: "realize",
79
+ completed_at: now,
80
+ created_at: now,
81
+ compiled,
82
+ files,
83
+ reason: props.reason,
84
+ step: ctx.state().analyze?.step ?? 0,
85
+ } satisfies AutoBeRealizeHistory;
86
+ } else {
87
+ const total = codes.length;
88
+ const failedCount = codes.filter((code) => code === FAILED).length;
89
+ const successCount = total - failedCount;
90
+
91
+ const now = new Date().toISOString();
92
+ ctx.dispatch({
93
+ type: "assistantMessage",
94
+ text: [
95
+ `Out of ${total} code blocks, ${successCount} succeeded, but ${failedCount} failed.`,
96
+ `The process has been stopped due to the failure. Please review the failed steps and try again.`,
97
+ ].join("\n"),
98
+ created_at: now,
99
+ });
100
+
101
+ return {
102
+ id: v4(),
103
+ type: "assistantMessage",
104
+ completed_at: now,
105
+ created_at: now,
106
+ text: [
107
+ `Out of ${total} code blocks, ${successCount} succeeded, but ${failedCount} failed.`,
108
+ `The process has been stopped due to the failure. Please review the failed steps and try again.`,
109
+ ].join("\n"),
110
+ } satisfies AutoBeAssistantMessageHistory;
111
+ }
112
+ }
113
+
114
+ const now = new Date().toISOString();
115
+ ctx.dispatch({
116
+ type: "assistantMessage",
117
+ text: "Any codes can not be generated.",
118
+ created_at: now,
119
+ });
120
+
121
+ return {
122
+ id: v4(),
123
+ type: "assistantMessage",
124
+ completed_at: now,
125
+ created_at: now,
126
+ text: "Any codes can not be generated.",
127
+ } satisfies AutoBeAssistantMessageHistory;
128
+ };
129
+
130
+ export const FAILED = Symbol("FAILED");
131
+ export type FAILED = typeof FAILED;
132
+
133
+ export function pipe<A, B>(
134
+ a: A,
135
+ ab: (a: A) => Promise<B | FAILED>,
136
+ ): Promise<B | FAILED>;
137
+
138
+ export function pipe<A, B, C>(
139
+ a: A,
140
+ ab: (a: A) => Promise<B | FAILED>,
141
+ bc: (b: B) => Promise<C | FAILED>,
142
+ ): Promise<C | FAILED>;
143
+
144
+ export function pipe<A, B, C, D>(
145
+ a: A,
146
+ ab: (a: A) => Promise<B | FAILED>,
147
+ bc: (b: B) => Promise<C | FAILED>,
148
+ cd: (c: C) => Promise<D | FAILED>,
149
+ ): Promise<D | FAILED>;
150
+
151
+ export function pipe<A, B, C, D, E>(
152
+ a: A,
153
+ ab: (a: A) => Promise<B | FAILED>,
154
+ bc: (b: B) => Promise<C | FAILED>,
155
+ cd: (c: C) => Promise<D | FAILED>,
156
+ de: (d: D) => Promise<E | FAILED>,
157
+ ): Promise<E | FAILED>;
158
+
159
+ export function pipe(
160
+ a: any,
161
+ ...fns: Array<(arg: any) => Promise<any>>
162
+ ): Promise<any> {
163
+ return fns.reduce((prev, fn) => {
164
+ return prev.then((result) => {
165
+ if (result === FAILED) return FAILED;
166
+ return fn(result);
167
+ });
168
+ }, Promise.resolve(a));
169
+ }
@@ -0,0 +1,156 @@
1
+ import { IAgenticaController, MicroAgentica } from "@agentica/core";
2
+ import { AutoBeOpenApi } from "@autobe/interface";
3
+ import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
4
+ import sortImport from "@trivago/prettier-plugin-sort-imports";
5
+ import { format } from "prettier";
6
+ import { IPointer } from "tstl";
7
+ import typia from "typia";
8
+
9
+ import { AutoBeContext } from "../../context/AutoBeContext";
10
+ import { assertSchemaModel } from "../../context/assertSchemaModel";
11
+ import { enforceToolCall } from "../../utils/enforceToolCall";
12
+ import { getTestScenarioArtifacts } from "../test/compile/getTestScenarioArtifacts";
13
+ import { IAutoBeTestScenarioArtifacts } from "../test/structures/IAutoBeTestScenarioArtifacts";
14
+ import { FAILED } from "./orchestrateRealize";
15
+ import { RealizePlannerOutput } from "./orchestrateRealizePlanner";
16
+ import { IAutoBeRealizeCoderApplication } from "./structures/IAutoBeRealizeCoderApplication";
17
+ import { transformRealizeCoderHistories } from "./transformRealizeCoderHistories";
18
+
19
+ /**
20
+ * Generates a TypeScript function implementation based on the given plan.
21
+ *
22
+ * This function transforms the plan (function name, input/output schema,
23
+ * constraints, and scenarios) into a complete TypeScript function as a string.
24
+ * It is responsible only for producing the code logic, and does not handle
25
+ * imports, exports, or formatting.
26
+ *
27
+ * Import statements are handled separately and will be injected automatically.
28
+ * Any unused imports will be removed by tooling (e.g. eslint).
29
+ *
30
+ * Type annotations should be omitted whenever possible to favor TypeScript's
31
+ * type inference, unless explicit types are critical to correctness.
32
+ *
33
+ * @param ctx - AutoBE execution context
34
+ * @param props - Planning result describing what function to generate
35
+ * @returns The generated function name and TypeScript code
36
+ */
37
+ export const orchestrateRealizeCoder = async <Model extends ILlmSchema.Model>(
38
+ ctx: AutoBeContext<Model>,
39
+ operation: AutoBeOpenApi.IOperation,
40
+ props: RealizePlannerOutput,
41
+ ): Promise<IAutoBeRealizeCoderApplication.RealizeCoderOutput | FAILED> => {
42
+ const artifacts: IAutoBeTestScenarioArtifacts =
43
+ await getTestScenarioArtifacts(ctx, {
44
+ endpoint: {
45
+ method: operation.method,
46
+ path: operation.path,
47
+ },
48
+ dependencies: [],
49
+ });
50
+
51
+ const pointer: IPointer<Pick<
52
+ IAutoBeRealizeCoderApplication.RealizeCoderOutput,
53
+ "implementationCode"
54
+ > | null> = {
55
+ value: null,
56
+ };
57
+
58
+ const controller = createApplication({
59
+ model: ctx.model,
60
+ build: (props) => {
61
+ pointer.value = props.result;
62
+ },
63
+ });
64
+
65
+ const agent = new MicroAgentica({
66
+ controllers: [controller],
67
+ model: ctx.model,
68
+ vendor: ctx.vendor,
69
+ config: {
70
+ ...ctx.config,
71
+ executor: {
72
+ describe: null,
73
+ },
74
+ },
75
+ histories: transformRealizeCoderHistories(ctx.state(), props, artifacts),
76
+ });
77
+ enforceToolCall(agent);
78
+
79
+ await agent.conversate("Write code.");
80
+ const tokenUsage = agent.getTokenUsage();
81
+ ctx.usage().record(tokenUsage, ["realize"]);
82
+
83
+ if (pointer.value === null) {
84
+ return FAILED;
85
+ }
86
+
87
+ pointer.value.implementationCode = await format(
88
+ pointer.value.implementationCode,
89
+ {
90
+ parser: "typescript",
91
+ plugins: [sortImport, await import("prettier-plugin-jsdoc")],
92
+ importOrder: ["<THIRD_PARTY_MODULES>", "^[./]"],
93
+ importOrderSeparation: true,
94
+ importOrderSortSpecifiers: true,
95
+ importOrderParserPlugins: ["decorators-legacy", "typescript", "jsx"],
96
+ },
97
+ );
98
+
99
+ pointer.value.implementationCode = pointer.value.implementationCode
100
+ .replaceAll('import { MyGlobal } from "../MyGlobal";', "")
101
+ .replaceAll('import typia, { tags } from "typia";', "")
102
+ .replaceAll('import { Prisma } from "@prisma/client";', "")
103
+ .replaceAll('import { jwtDecode } from "./jwtDecode"', "");
104
+
105
+ pointer.value.implementationCode = [
106
+ 'import { MyGlobal } from "../MyGlobal";',
107
+ 'import typia, { tags } from "typia";',
108
+ 'import { Prisma } from "@prisma/client";',
109
+ 'import { jwtDecode } from "./jwtDecode"',
110
+ "",
111
+ pointer.value.implementationCode,
112
+ ].join("\n");
113
+
114
+ return { ...pointer.value, functionName: props.functionName };
115
+ };
116
+
117
+ function createApplication<Model extends ILlmSchema.Model>(props: {
118
+ model: Model;
119
+ build: (next: IAutoBeRealizeCoderApplication.IProps) => void;
120
+ }): IAgenticaController.IClass<Model> {
121
+ assertSchemaModel(props.model);
122
+
123
+ const application: ILlmApplication<Model> = collection[
124
+ props.model
125
+ ] as unknown as ILlmApplication<Model>;
126
+
127
+ return {
128
+ protocol: "class",
129
+ name: "Write code",
130
+ application,
131
+ execute: {
132
+ programing: (next) => {
133
+ props.build(next);
134
+ },
135
+ } satisfies IAutoBeRealizeCoderApplication,
136
+ };
137
+ }
138
+
139
+ const claude = typia.llm.application<
140
+ IAutoBeRealizeCoderApplication,
141
+ "claude",
142
+ {
143
+ reference: true;
144
+ }
145
+ >();
146
+ const collection = {
147
+ chatgpt: typia.llm.application<
148
+ IAutoBeRealizeCoderApplication,
149
+ "chatgpt",
150
+ { reference: true }
151
+ >(),
152
+ claude,
153
+ llama: claude,
154
+ deepseek: claude,
155
+ "3.1": claude,
156
+ };
@@ -0,0 +1,75 @@
1
+ import { ILlmSchema } from "@samchon/openapi";
2
+
3
+ import { AutoBeContext } from "../../context/AutoBeContext";
4
+ import { IAutoBeRealizeCoderApplication } from "./structures/IAutoBeRealizeCoderApplication";
5
+
6
+ /**
7
+ * The result of integrating the generated code into the actual application
8
+ * files (e.g., controller).
9
+ */
10
+ export interface RealizeIntegratorOutput {
11
+ /**
12
+ * Indicates the result of the integration process.
13
+ *
14
+ * - "success": The function was correctly inserted, imported, and passed
15
+ * compilation.
16
+ * - "fail": The integration did not complete (e.g., target controller not
17
+ * found, syntax error).
18
+ * - "exception": An unexpected error occurred (e.g., I/O failure, invalid
19
+ * context state).
20
+ */
21
+ result: "success" | "fail" | "exception";
22
+ }
23
+
24
+ /**
25
+ * Integrates the generated function into an appropriate controller file,
26
+ * handling insertion, import, and static validation.
27
+ *
28
+ * This function performs the following steps:
29
+ *
30
+ * 1. **Locate appropriate controller file**
31
+ *
32
+ * - Usually matches `*.controller.ts`
33
+ * - May be based on inferred target (e.g., from functionName or folder structure)
34
+ * 2. **Insert the generated function into the file content**
35
+ *
36
+ * - Ensures proper placement, such as inside a class or export block
37
+ * - May replace or append to existing function stubs
38
+ * 3. **Inject required imports automatically**
39
+ *
40
+ * - Identifies any missing imports (e.g., DTOs, utility functions)
41
+ * - Ensures imports are added without duplication
42
+ * 4. **Check for compile-time safety**
43
+ *
44
+ * - Ensures TypeScript type-checking passes
45
+ * - Verifies that Nestia-generated routers still function without error
46
+ * - If compilation fails or static types are invalid, marks result as `"fail"`
47
+ *
48
+ * ⚠️ Note: This step **must not rely on runtime execution**. It only guarantees
49
+ * static, structural validity (i.e., valid TypeScript).
50
+ *
51
+ * @param ctx - AutoBE context including current source files and settings
52
+ * @param props - Output from the code generation step to be integrated
53
+ * @returns Integration status, indicating success or failure of insertion
54
+ */
55
+ export const orchestrateRealizeIntegrator = async <
56
+ Model extends ILlmSchema.Model,
57
+ >(
58
+ ctx: AutoBeContext<Model>,
59
+ props: IAutoBeRealizeCoderApplication.RealizeCoderOutput,
60
+ ): Promise<RealizeIntegratorOutput> => {
61
+ props;
62
+
63
+ const controllers: [string, string][] = Object.entries(
64
+ ctx.state().interface?.files ?? {},
65
+ ).filter(([filename]) => {
66
+ return filename.endsWith("controller.ts");
67
+ });
68
+
69
+ // Placeholder: insert props.implementationCode into selected controller
70
+ // Inject necessary import statements for used types/functions
71
+ // Optionally run TypeScript compiler in dry-run mode to validate correctness
72
+ controllers;
73
+
74
+ return null!;
75
+ };
@@ -0,0 +1,115 @@
1
+ import { AutoBeOpenApi } from "@autobe/interface";
2
+ import { ILlmSchema } from "@samchon/openapi";
3
+
4
+ import { AutoBeContext } from "../../context/AutoBeContext";
5
+
6
+ export interface RealizePlannerOutput {
7
+ /**
8
+ * The name of the function to be generated.
9
+ *
10
+ * Derived from the Swagger path and method. The function name must be written
11
+ * in snake_case. It serves as the entry point in both code generation and
12
+ * test code.
13
+ *
14
+ * Once the function is generated, the function name and file name will be the
15
+ * same. The generated file will be located at
16
+ * `src/providers/${function_name}.ts`.
17
+ */
18
+ functionName: string;
19
+
20
+ /**
21
+ * Definition of path and query parameters extracted from the OpenAPI spec.
22
+ *
23
+ * Includes input values passed via URL path or query string. Used for type
24
+ * definitions, validation, and function signature construction.
25
+ */
26
+ parameters: AutoBeOpenApi.IParameter[];
27
+
28
+ /**
29
+ * Schema definition for the request body input.
30
+ *
31
+ * Extracted from the requestBody section of Swagger. Represents the input
32
+ * data passed in the body (e.g., JSON). Used for generating function
33
+ * arguments or DTOs.
34
+ */
35
+ inputSchema: AutoBeOpenApi.IRequestBody | null;
36
+
37
+ /**
38
+ * Schema definition for the response body.
39
+ *
40
+ * Extracted from the responses section of Swagger. Used to define the return
41
+ * type and expected output in test code.
42
+ */
43
+ outputSchema: AutoBeOpenApi.IResponseBody | null;
44
+
45
+ /**
46
+ * Natural language description of the function’s purpose.
47
+ *
48
+ * Extracted from the summary or description field of Swagger. Used for code
49
+ * documentation, test scenario generation, and conveying function intent.
50
+ */
51
+ description: string;
52
+
53
+ /**
54
+ * HTTP method information.
55
+ *
56
+ * Extracted from the Swagger operation method. Used to define the request
57
+ * type during code and test generation.
58
+ */
59
+ operationType: "get" | "post" | "put" | "delete" | "patch";
60
+
61
+ /**
62
+ * List of scenario descriptions for test code generation.
63
+ *
64
+ * Each scenario describes the expected behavior of the function under certain
65
+ * conditions. Used as a basis for TDD-style automated test generation.
66
+ */
67
+ testScenarios: string[];
68
+ }
69
+
70
+ /**
71
+ * Generates a planning result that defines what kind of function should be
72
+ * created, based solely on the provided Swagger (OpenAPI) operation — without
73
+ * using an LLM.
74
+ *
75
+ * This function analyzes the structure of the OpenAPI operation (such as the
76
+ * path, method, parameters, request/response schema, and descriptions) to
77
+ * determine the appropriate function name, input/output types, and purpose of
78
+ * the function.
79
+ *
80
+ * The result of this function (`RealizePlannerOutput`) will be passed to the
81
+ * next step in the AutoBE pipeline, which is responsible for generating the
82
+ * actual implementation code.
83
+ *
84
+ * @param ctx - AutoBE context including model and configuration
85
+ * @param operation - A single OpenAPI operation object to analyze and plan
86
+ * @returns A planning object containing all structural information needed to
87
+ * generate the function
88
+ */
89
+ export const orchestrateRealizePlanner = async <Model extends ILlmSchema.Model>(
90
+ ctx: AutoBeContext<Model>,
91
+ operation: AutoBeOpenApi.IOperation,
92
+ ): Promise<RealizePlannerOutput> => {
93
+ const testScenarios =
94
+ ctx
95
+ .state()
96
+ .test?.files.filter(
97
+ (el) =>
98
+ el.scenario.endpoint.method === operation.method &&
99
+ el.scenario.endpoint.path === operation.path,
100
+ ) ?? [];
101
+
102
+ return {
103
+ description: operation.description,
104
+ parameters: operation.parameters,
105
+ inputSchema: operation.requestBody,
106
+ outputSchema: operation.responseBody,
107
+ operationType: operation.method,
108
+ testScenarios: testScenarios.map((el) => el.scenario.draft),
109
+ functionName: `${operation.method}_${operation.path
110
+ .replaceAll("/", "_")
111
+ .replaceAll("-", "_")
112
+ .replaceAll("{", "$")
113
+ .replaceAll("}", "")}`,
114
+ } satisfies RealizePlannerOutput;
115
+ };
@@ -0,0 +1,64 @@
1
+ import { ILlmSchema } from "@samchon/openapi";
2
+
3
+ import { AutoBeContext } from "../../context/AutoBeContext";
4
+ import { RealizeIntegratorOutput } from "./orchestrateRealizeIntegrator";
5
+
6
+ /**
7
+ * The result of validating the integrated code by running tests or static
8
+ * checks.
9
+ */
10
+ export interface RealizeValidatorOutput {
11
+ /** File path or location of the generated provider logic file. */
12
+ location: string;
13
+
14
+ /** The full TypeScript source code content of the generated provider file. */
15
+ content: string;
16
+
17
+ /**
18
+ * Overall result of the test execution.
19
+ *
20
+ * - "success": All tests passed successfully.
21
+ * - "fail": Some tests failed.
22
+ * - "exception": An unexpected error occurred during test execution.
23
+ */
24
+ result: "success" | "fail" | "exception";
25
+
26
+ /** Total number of test cases executed. */
27
+ total: number;
28
+
29
+ /** Number of tests that passed. */
30
+ success: number;
31
+
32
+ /** Number of tests that failed. */
33
+ fail: number;
34
+ }
35
+
36
+ /**
37
+ * Validates the integrated provider logic by returning the generated source
38
+ * code along with the summary of test execution results.
39
+ *
40
+ * This function serves as the final step to:
41
+ *
42
+ * - Provide the full TypeScript implementation files created/updated during
43
+ * integration.
44
+ * - Return a detailed summary of the automated test outcomes executed against
45
+ * that code.
46
+ *
47
+ * It does not throw errors; all failures or exceptions are reported via the
48
+ * `result` property.
49
+ *
50
+ * @param ctx - AutoBE execution context
51
+ * @param props - Result from the integration step
52
+ * @returns An object containing provider file content and test results
53
+ */
54
+ export const orchestrateRealizeValidator = async <
55
+ Model extends ILlmSchema.Model,
56
+ >(
57
+ ctx: AutoBeContext<Model>,
58
+ props: RealizeIntegratorOutput,
59
+ ): Promise<RealizeValidatorOutput> => {
60
+ ctx;
61
+ props;
62
+
63
+ return null!;
64
+ };
@@ -0,0 +1,36 @@
1
+ export interface IAutoBeRealizeCoderApplication {
2
+ programing: (next: IAutoBeRealizeCoderApplication.IProps) => void;
3
+ }
4
+
5
+ export namespace IAutoBeRealizeCoderApplication {
6
+ export interface IProps {
7
+ result: RealizeCoderOutput;
8
+ }
9
+
10
+ /**
11
+ * The result of the code generation step, representing a fully generated
12
+ * TypeScript function.
13
+ */
14
+ export interface RealizeCoderOutput {
15
+ /**
16
+ * The name of the function to be generated.
17
+ *
18
+ * This name will be used as the function's identifier and as the export
19
+ * name in the provider file.
20
+ */
21
+ functionName: string;
22
+
23
+ /**
24
+ * The raw TypeScript code string implementing the function.
25
+ *
26
+ * - The implementation must be valid TypeScript code.
27
+ * - It should focus solely on the logic of the function.
28
+ * - Import statements do **not** need to be included. They will be
29
+ * automatically inserted by the system.
30
+ * - Any unused imports will be automatically removed by eslint.
31
+ * - Type annotations (e.g. for parameters and return types) should be omitted
32
+ * if they can be inferred.
33
+ */
34
+ implementationCode: string;
35
+ }
36
+ }