@autobe/agent 0.14.6 → 0.15.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.
- package/lib/AutoBeMockAgent.js +1 -1
- package/lib/AutoBeMockAgent.js.map +1 -1
- package/lib/constants/AutoBeSystemPromptConstant.d.ts +10 -8
- package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -1
- package/lib/index.mjs +1276 -834
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js +4 -9
- package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js +2 -8
- package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js.map +1 -1
- package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js +1 -1
- package/lib/orchestrate/analyze/transformAnalyzeReviewerHistories.js.map +1 -1
- package/lib/orchestrate/analyze/transformAnalyzeWriteHistories.js +1 -1
- package/lib/orchestrate/analyze/transformAnalyzeWriteHistories.js.map +1 -1
- package/lib/orchestrate/interface/histories/transformInterfaceAssetHistories.d.ts +3 -0
- package/lib/orchestrate/interface/histories/transformInterfaceAssetHistories.js +65 -0
- package/lib/orchestrate/interface/histories/transformInterfaceAssetHistories.js.map +1 -0
- package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.d.ts +4 -0
- package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js +62 -0
- package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js.map +1 -0
- package/lib/orchestrate/interface/histories/transformInterfaceEndpointHistories.d.ts +4 -0
- package/lib/orchestrate/interface/histories/transformInterfaceEndpointHistories.js +28 -0
- package/lib/orchestrate/interface/histories/transformInterfaceEndpointHistories.js.map +1 -0
- package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.d.ts +3 -0
- package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js +28 -0
- package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js.map +1 -0
- package/lib/orchestrate/interface/histories/transformInterfaceOperationHistories.d.ts +4 -0
- package/lib/orchestrate/interface/histories/transformInterfaceOperationHistories.js +28 -0
- package/lib/orchestrate/interface/histories/transformInterfaceOperationHistories.js.map +1 -0
- package/lib/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.d.ts +3 -0
- package/lib/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.js +63 -0
- package/lib/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.js.map +1 -0
- package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.d.ts +4 -0
- package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js +28 -0
- package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js.map +1 -0
- package/lib/orchestrate/interface/orchestrateInterface.js +14 -9
- package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceComplement.d.ts +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +13 -40
- package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.d.ts +3 -2
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +52 -32
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceGroups.d.ts +4 -0
- package/lib/orchestrate/interface/orchestrateInterfaceGroups.js +350 -0
- package/lib/orchestrate/interface/orchestrateInterfaceGroups.js.map +1 -0
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +249 -225
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceSchemas.d.ts +4 -0
- package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js +411 -0
- package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js.map +1 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.d.ts +55 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.js +3 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.js.map +1 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceEndpointApplication.d.ts +23 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceEndpointApplication.js +3 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceEndpointApplication.js.map +1 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.d.ts +108 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.js +3 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.js.map +1 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceOperationApplication.d.ts +122 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceOperationApplication.js +3 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceOperationApplication.js.map +1 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.d.ts +75 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.js +3 -0
- package/lib/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.js.map +1 -0
- package/lib/orchestrate/interface/{OpenApiEndpointComparator.d.ts → utils/OpenApiEndpointComparator.d.ts} +1 -0
- package/lib/orchestrate/interface/{OpenApiEndpointComparator.js → utils/OpenApiEndpointComparator.js} +6 -0
- package/lib/orchestrate/interface/utils/OpenApiEndpointComparator.js.map +1 -0
- package/lib/orchestrate/realize/orchestrateRealize.js +16 -2
- package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js +5 -7
- package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.js +2 -2
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js +3 -2
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -1
- package/lib/orchestrate/realize/structures/IAutoBeRealizeAuthorizationCorrectApplication.d.ts +1 -1
- package/lib/orchestrate/realize/structures/IAutoBeRealizeCompile.d.ts +34 -13
- package/lib/orchestrate/realize/transformRealizeAuthorization.js +1 -1
- package/lib/orchestrate/realize/transformRealizeAuthorization.js.map +1 -1
- package/lib/orchestrate/realize/transformRealizeAuthorizationCorrectHistories.js +1 -1
- package/lib/orchestrate/realize/transformRealizeAuthorizationCorrectHistories.js.map +1 -1
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js +5 -5
- package/lib/orchestrate/realize/transformRealizeCoderHistories.js.map +1 -1
- package/lib/orchestrate/realize/utils/InternalFileSystem.d.ts +8 -0
- package/lib/orchestrate/realize/utils/InternalFileSystem.js +17 -0
- package/lib/orchestrate/realize/utils/InternalFileSystem.js.map +1 -0
- package/lib/orchestrate/realize/utils/ProviderFileSystem.d.ts +3 -0
- package/lib/orchestrate/realize/utils/ProviderFileSystem.js +8 -0
- package/lib/orchestrate/realize/utils/ProviderFileSystem.js.map +1 -0
- package/lib/orchestrate/realize/utils/replaceImportStatements.js +2 -2
- package/lib/orchestrate/realize/utils/replaceImportStatements.js.map +1 -1
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js +36 -36
- package/lib/orchestrate/realize/writeCodeUntilCompilePassed.js.map +1 -1
- package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js +1 -0
- package/lib/orchestrate/test/compile/getTestScenarioArtifacts.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestScenario.js +29 -13
- package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
- package/lib/orchestrate/test/transformTestWriteHistories.js +3 -2
- package/lib/orchestrate/test/transformTestWriteHistories.js.map +1 -1
- package/lib/utils/arrayToRecord.d.ts +17 -0
- package/lib/utils/arrayToRecord.js +19 -0
- package/lib/utils/arrayToRecord.js.map +1 -0
- package/lib/utils/backoffRetry.js +0 -1
- package/lib/utils/backoffRetry.js.map +1 -1
- package/package.json +5 -5
- package/src/AutoBeMockAgent.ts +1 -1
- package/src/constants/AutoBeSystemPromptConstant.ts +10 -8
- package/src/orchestrate/analyze/orchestrateAnalyzeReviewer.ts +1 -3
- package/src/orchestrate/analyze/orchestrateAnalyzeWrite.ts +1 -3
- package/src/orchestrate/interface/histories/transformInterfaceAssetHistories.ts +75 -0
- package/src/orchestrate/interface/histories/transformInterfaceComplementHistories.ts +69 -0
- package/src/orchestrate/interface/histories/transformInterfaceEndpointHistories.ts +34 -0
- package/src/orchestrate/interface/histories/transformInterfaceGroupHistories.ts +32 -0
- package/src/orchestrate/interface/histories/transformInterfaceOperationHistories.ts +34 -0
- package/src/orchestrate/interface/histories/transformInterfacePrerequisiteHistories.ts +66 -0
- package/src/orchestrate/interface/histories/transformInterfaceSchemaHistories.ts +34 -0
- package/src/orchestrate/interface/orchestrateInterface.ts +17 -8
- package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +22 -97
- package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +48 -55
- package/src/orchestrate/interface/orchestrateInterfaceGroups.ts +109 -0
- package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +81 -120
- package/src/orchestrate/interface/orchestrateInterfaceSchemas.ts +197 -0
- package/src/orchestrate/interface/structures/IAutoBeInterfaceComplementApplication.ts +58 -0
- package/src/orchestrate/interface/structures/IAutoBeInterfaceEndpointApplication.ts +24 -0
- package/src/orchestrate/interface/structures/IAutoBeInterfaceGroupApplication.ts +112 -0
- package/src/orchestrate/interface/structures/IAutoBeInterfaceOperationApplication.ts +125 -0
- package/src/orchestrate/interface/structures/IAutoBeInterfaceSchemaApplication.ts +76 -0
- package/src/orchestrate/interface/{OpenApiEndpointComparator.ts → utils/OpenApiEndpointComparator.ts} +8 -0
- package/src/orchestrate/realize/orchestrateRealize.ts +19 -2
- package/src/orchestrate/realize/orchestrateRealizeAuthorization.ts +6 -19
- package/src/orchestrate/realize/orchestrateRealizeCoder.ts +3 -6
- package/src/orchestrate/realize/structures/IAutoBeRealizeAuthorizationCorrectApplication.ts +1 -1
- package/src/orchestrate/realize/structures/IAutoBeRealizeCompile.ts +42 -24
- package/src/orchestrate/realize/transformRealizeCoderHistories.ts +4 -4
- package/src/orchestrate/realize/utils/InternalFileSystem.ts +12 -0
- package/src/orchestrate/realize/utils/ProviderFileSystem.ts +4 -0
- package/src/orchestrate/realize/utils/replaceImportStatements.ts +2 -2
- package/src/orchestrate/realize/writeCodeUntilCompilePassed.ts +59 -53
- package/src/orchestrate/test/compile/getTestScenarioArtifacts.ts +1 -0
- package/src/orchestrate/test/orchestrateTestScenario.ts +4 -2
- package/src/utils/arrayToRecord.ts +49 -0
- package/src/utils/backoffRetry.ts +0 -1
- package/lib/orchestrate/interface/OpenApiEndpointComparator.js.map +0 -1
- package/lib/orchestrate/interface/orchestrateInterfaceComponents.d.ts +0 -4
- package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +0 -473
- package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +0 -1
- package/lib/orchestrate/interface/transformInterfaceHistories.d.ts +0 -3
- package/lib/orchestrate/interface/transformInterfaceHistories.js +0 -149
- package/lib/orchestrate/interface/transformInterfaceHistories.js.map +0 -1
- package/src/orchestrate/interface/orchestrateInterfaceComponents.ts +0 -292
- package/src/orchestrate/interface/transformInterfaceHistories.ts +0 -152
|
@@ -1,31 +1,47 @@
|
|
|
1
|
+
import { IAgenticaController, MicroAgentica } from "@agentica/core";
|
|
1
2
|
import {
|
|
2
|
-
AgenticaAssistantMessageHistory,
|
|
3
|
-
IAgenticaController,
|
|
4
|
-
MicroAgentica,
|
|
5
|
-
MicroAgenticaHistory,
|
|
6
|
-
} from "@agentica/core";
|
|
7
|
-
import {
|
|
8
|
-
AutoBeAssistantMessageHistory,
|
|
9
3
|
AutoBeInterfaceEndpointsEvent,
|
|
10
4
|
AutoBeOpenApi,
|
|
11
5
|
} from "@autobe/interface";
|
|
6
|
+
import { AutoBeInterfaceGroup } from "@autobe/interface/src/histories/contents/AutoBeInterfaceGroup";
|
|
12
7
|
import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
|
|
13
8
|
import { HashSet, IPointer } from "tstl";
|
|
14
9
|
import typia from "typia";
|
|
15
|
-
import { v4 } from "uuid";
|
|
16
10
|
|
|
17
|
-
import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
|
|
18
11
|
import { AutoBeContext } from "../../context/AutoBeContext";
|
|
19
12
|
import { assertSchemaModel } from "../../context/assertSchemaModel";
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
13
|
+
import { enforceToolCall } from "../../utils/enforceToolCall";
|
|
14
|
+
import { transformInterfaceEndpointHistories } from "./histories/transformInterfaceEndpointHistories";
|
|
15
|
+
import { IAutoBeInterfaceEndpointApplication } from "./structures/IAutoBeInterfaceEndpointApplication";
|
|
16
|
+
import { OpenApiEndpointComparator } from "./utils/OpenApiEndpointComparator";
|
|
22
17
|
|
|
23
18
|
export async function orchestrateInterfaceEndpoints<
|
|
24
19
|
Model extends ILlmSchema.Model,
|
|
25
20
|
>(
|
|
26
21
|
ctx: AutoBeContext<Model>,
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
groups: AutoBeInterfaceGroup[],
|
|
23
|
+
content: string = `Make endpoints for the given assets`,
|
|
24
|
+
): Promise<AutoBeOpenApi.IEndpoint[]> {
|
|
25
|
+
const progress: IProgress = {
|
|
26
|
+
total: groups.length,
|
|
27
|
+
completed: 0,
|
|
28
|
+
};
|
|
29
|
+
const endpoints: AutoBeOpenApi.IEndpoint[] = (
|
|
30
|
+
await Promise.all(groups.map((g) => process(ctx, g, content, progress)))
|
|
31
|
+
).flat();
|
|
32
|
+
return new HashSet(
|
|
33
|
+
endpoints,
|
|
34
|
+
OpenApiEndpointComparator.hashCode,
|
|
35
|
+
OpenApiEndpointComparator.equals,
|
|
36
|
+
).toJSON();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function process<Model extends ILlmSchema.Model>(
|
|
40
|
+
ctx: AutoBeContext<Model>,
|
|
41
|
+
group: AutoBeInterfaceGroup,
|
|
42
|
+
content: string,
|
|
43
|
+
progress: IProgress,
|
|
44
|
+
): Promise<AutoBeOpenApi.IEndpoint[]> {
|
|
29
45
|
const start: Date = new Date();
|
|
30
46
|
const pointer: IPointer<AutoBeOpenApi.IEndpoint[] | null> = {
|
|
31
47
|
value: null,
|
|
@@ -39,10 +55,7 @@ export async function orchestrateInterfaceEndpoints<
|
|
|
39
55
|
describe: null,
|
|
40
56
|
},
|
|
41
57
|
},
|
|
42
|
-
histories:
|
|
43
|
-
ctx.state(),
|
|
44
|
-
AutoBeSystemPromptConstant.INTERFACE_ENDPOINT,
|
|
45
|
-
),
|
|
58
|
+
histories: transformInterfaceEndpointHistories(ctx.state(), group),
|
|
46
59
|
controllers: [
|
|
47
60
|
createApplication({
|
|
48
61
|
model: ctx.model,
|
|
@@ -53,23 +66,14 @@ export async function orchestrateInterfaceEndpoints<
|
|
|
53
66
|
}),
|
|
54
67
|
],
|
|
55
68
|
});
|
|
69
|
+
enforceToolCall(agentica);
|
|
56
70
|
|
|
57
|
-
|
|
58
|
-
.
|
|
59
|
-
.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (histories.at(-1)?.type === "assistantMessage")
|
|
64
|
-
return {
|
|
65
|
-
...(histories.at(-1)! as AgenticaAssistantMessageHistory),
|
|
66
|
-
created_at: start.toISOString(),
|
|
67
|
-
completed_at: new Date().toISOString(),
|
|
68
|
-
id: v4(),
|
|
69
|
-
} satisfies AutoBeAssistantMessageHistory;
|
|
70
|
-
else if (pointer.value === null)
|
|
71
|
-
throw new Error("Failed to generate endpoints."); // unreachable
|
|
72
|
-
return {
|
|
71
|
+
await agentica.conversate(content).finally(() => {
|
|
72
|
+
const tokenUsage = agentica.getTokenUsage();
|
|
73
|
+
ctx.usage().record(tokenUsage, ["interface"]);
|
|
74
|
+
});
|
|
75
|
+
if (pointer.value === null) throw new Error("Failed to generate endpoints."); // unreachable
|
|
76
|
+
const event: AutoBeInterfaceEndpointsEvent = {
|
|
73
77
|
type: "interfaceEndpoints",
|
|
74
78
|
endpoints: new HashSet(
|
|
75
79
|
pointer.value,
|
|
@@ -78,7 +82,11 @@ export async function orchestrateInterfaceEndpoints<
|
|
|
78
82
|
).toJSON(),
|
|
79
83
|
created_at: start.toISOString(),
|
|
80
84
|
step: ctx.state().analyze?.step ?? 0,
|
|
81
|
-
|
|
85
|
+
completed: ++progress.completed,
|
|
86
|
+
total: progress.total,
|
|
87
|
+
};
|
|
88
|
+
ctx.dispatch(event);
|
|
89
|
+
return pointer.value;
|
|
82
90
|
}
|
|
83
91
|
|
|
84
92
|
function createApplication<Model extends ILlmSchema.Model>(props: {
|
|
@@ -98,18 +106,18 @@ function createApplication<Model extends ILlmSchema.Model>(props: {
|
|
|
98
106
|
makeEndpoints: (next) => {
|
|
99
107
|
props.build(next.endpoints);
|
|
100
108
|
},
|
|
101
|
-
} satisfies
|
|
109
|
+
} satisfies IAutoBeInterfaceEndpointApplication,
|
|
102
110
|
};
|
|
103
111
|
}
|
|
104
112
|
|
|
105
113
|
const claude = typia.llm.application<
|
|
106
|
-
|
|
114
|
+
IAutoBeInterfaceEndpointApplication,
|
|
107
115
|
"claude",
|
|
108
116
|
{ reference: true }
|
|
109
117
|
>();
|
|
110
118
|
const collection = {
|
|
111
119
|
chatgpt: typia.llm.application<
|
|
112
|
-
|
|
120
|
+
IAutoBeInterfaceEndpointApplication,
|
|
113
121
|
"chatgpt",
|
|
114
122
|
{ reference: true }
|
|
115
123
|
>(),
|
|
@@ -119,22 +127,7 @@ const collection = {
|
|
|
119
127
|
"3.1": claude,
|
|
120
128
|
};
|
|
121
129
|
|
|
122
|
-
interface
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
*
|
|
126
|
-
* Create Restful API endpoints referencing the given documents; requirement
|
|
127
|
-
* analysis documents, and Prisma schema files with ERD descriptions. The API
|
|
128
|
-
* endpoints must cover every requirements and every entities in the ERD.
|
|
129
|
-
*
|
|
130
|
-
* Also, each combination of {@link AutoBeOpenApi.IEndpoint.path} and
|
|
131
|
-
* {@link AutoBeOpenApi.IEndpoint.method} must be unique to avoid duplicates.
|
|
132
|
-
* Please don't make any duplicates.
|
|
133
|
-
*
|
|
134
|
-
* @param props Properties containing the endpoints
|
|
135
|
-
*/
|
|
136
|
-
makeEndpoints(props: {
|
|
137
|
-
/** List of endpoints to generate. */
|
|
138
|
-
endpoints: AutoBeOpenApi.IEndpoint[];
|
|
139
|
-
}): void;
|
|
130
|
+
interface IProgress {
|
|
131
|
+
total: number;
|
|
132
|
+
completed: number;
|
|
140
133
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IAgenticaController,
|
|
3
|
+
MicroAgentica,
|
|
4
|
+
MicroAgenticaHistory,
|
|
5
|
+
} from "@agentica/core";
|
|
6
|
+
import {
|
|
7
|
+
AutoBeAssistantMessageHistory,
|
|
8
|
+
AutoBeInterfaceGroupsEvent,
|
|
9
|
+
} from "@autobe/interface";
|
|
10
|
+
import { ILlmApplication, ILlmSchema } from "@samchon/openapi";
|
|
11
|
+
import { IPointer } from "tstl";
|
|
12
|
+
import typia from "typia";
|
|
13
|
+
import { v4 } from "uuid";
|
|
14
|
+
|
|
15
|
+
import { AutoBeContext } from "../../context/AutoBeContext";
|
|
16
|
+
import { assertSchemaModel } from "../../context/assertSchemaModel";
|
|
17
|
+
import { transformInterfaceGroupHistories } from "./histories/transformInterfaceGroupHistories";
|
|
18
|
+
import { IAutoBeInterfaceGroupApplication } from "./structures/IAutoBeInterfaceGroupApplication";
|
|
19
|
+
|
|
20
|
+
export async function orchestrateInterfaceGroups<
|
|
21
|
+
Model extends ILlmSchema.Model,
|
|
22
|
+
>(
|
|
23
|
+
ctx: AutoBeContext<Model>,
|
|
24
|
+
content: string = "Design API operations for the given assets.",
|
|
25
|
+
): Promise<AutoBeAssistantMessageHistory | AutoBeInterfaceGroupsEvent> {
|
|
26
|
+
const start: Date = new Date();
|
|
27
|
+
const pointer: IPointer<IAutoBeInterfaceGroupApplication.IProps | null> = {
|
|
28
|
+
value: null,
|
|
29
|
+
};
|
|
30
|
+
const agentica: MicroAgentica<Model> = new MicroAgentica({
|
|
31
|
+
model: ctx.model,
|
|
32
|
+
vendor: ctx.vendor,
|
|
33
|
+
config: {
|
|
34
|
+
...(ctx.config ?? {}),
|
|
35
|
+
executor: {
|
|
36
|
+
describe: null,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
histories: transformInterfaceGroupHistories(ctx.state()),
|
|
40
|
+
controllers: [
|
|
41
|
+
createApplication({
|
|
42
|
+
model: ctx.model,
|
|
43
|
+
build: (next) => {
|
|
44
|
+
pointer.value = next;
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const histories: MicroAgenticaHistory<Model>[] = await agentica
|
|
51
|
+
.conversate(content)
|
|
52
|
+
.finally(() => {
|
|
53
|
+
const tokenUsage = agentica.getTokenUsage();
|
|
54
|
+
ctx.usage().record(tokenUsage, ["interface"]);
|
|
55
|
+
});
|
|
56
|
+
const last: MicroAgenticaHistory<Model> = histories.at(-1)!;
|
|
57
|
+
if (last.type === "assistantMessage")
|
|
58
|
+
return {
|
|
59
|
+
...last,
|
|
60
|
+
created_at: start.toISOString(),
|
|
61
|
+
completed_at: new Date().toISOString(),
|
|
62
|
+
id: v4(),
|
|
63
|
+
} satisfies AutoBeAssistantMessageHistory;
|
|
64
|
+
else if (pointer.value === null)
|
|
65
|
+
throw new Error("Failed to generate groups."); // unreachable
|
|
66
|
+
return {
|
|
67
|
+
type: "interfaceGroups",
|
|
68
|
+
created_at: start.toISOString(),
|
|
69
|
+
groups: pointer.value.groups,
|
|
70
|
+
step: ctx.state().analyze?.step ?? 0,
|
|
71
|
+
} satisfies AutoBeInterfaceGroupsEvent;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function createApplication<Model extends ILlmSchema.Model>(props: {
|
|
75
|
+
model: Model;
|
|
76
|
+
build: (next: IAutoBeInterfaceGroupApplication.IProps) => void;
|
|
77
|
+
}): IAgenticaController.IClass<Model> {
|
|
78
|
+
assertSchemaModel(props.model);
|
|
79
|
+
|
|
80
|
+
const application: ILlmApplication<Model> = collection[
|
|
81
|
+
props.model
|
|
82
|
+
] as unknown as ILlmApplication<Model>;
|
|
83
|
+
return {
|
|
84
|
+
protocol: "class",
|
|
85
|
+
name: "interface",
|
|
86
|
+
application,
|
|
87
|
+
execute: {
|
|
88
|
+
makeGroups: (next) => {
|
|
89
|
+
props.build(next);
|
|
90
|
+
},
|
|
91
|
+
} satisfies IAutoBeInterfaceGroupApplication,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const claude = typia.llm.application<
|
|
96
|
+
IAutoBeInterfaceGroupApplication,
|
|
97
|
+
"claude"
|
|
98
|
+
>();
|
|
99
|
+
const chatgpt = typia.llm.application<
|
|
100
|
+
IAutoBeInterfaceGroupApplication,
|
|
101
|
+
"chatgpt"
|
|
102
|
+
>();
|
|
103
|
+
const collection = {
|
|
104
|
+
chatgpt,
|
|
105
|
+
claude,
|
|
106
|
+
llama: claude,
|
|
107
|
+
deepseek: claude,
|
|
108
|
+
"3.1": claude,
|
|
109
|
+
};
|
|
@@ -3,15 +3,16 @@ import { AutoBeOpenApi } from "@autobe/interface";
|
|
|
3
3
|
import { ILlmApplication, ILlmSchema, IValidation } from "@samchon/openapi";
|
|
4
4
|
import { HashMap, HashSet, IPointer } from "tstl";
|
|
5
5
|
import typia from "typia";
|
|
6
|
+
import { NamingConvention } from "typia/lib/utils/NamingConvention";
|
|
6
7
|
|
|
7
|
-
import { AutoBeSystemPromptConstant } from "../../constants/AutoBeSystemPromptConstant";
|
|
8
8
|
import { AutoBeContext } from "../../context/AutoBeContext";
|
|
9
9
|
import { assertSchemaModel } from "../../context/assertSchemaModel";
|
|
10
10
|
import { divideArray } from "../../utils/divideArray";
|
|
11
11
|
import { enforceToolCall } from "../../utils/enforceToolCall";
|
|
12
12
|
import { forceRetry } from "../../utils/forceRetry";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { transformInterfaceOperationHistories } from "./histories/transformInterfaceOperationHistories";
|
|
14
|
+
import { IAutoBeInterfaceOperationApplication } from "./structures/IAutoBeInterfaceOperationApplication";
|
|
15
|
+
import { OpenApiEndpointComparator } from "./utils/OpenApiEndpointComparator";
|
|
15
16
|
|
|
16
17
|
export async function orchestrateInterfaceOperations<
|
|
17
18
|
Model extends ILlmSchema.Model,
|
|
@@ -24,22 +25,22 @@ export async function orchestrateInterfaceOperations<
|
|
|
24
25
|
array: endpoints,
|
|
25
26
|
capacity,
|
|
26
27
|
});
|
|
27
|
-
|
|
28
|
+
const progress: IProgress = {
|
|
29
|
+
total: endpoints.length,
|
|
30
|
+
completed: 0,
|
|
31
|
+
};
|
|
28
32
|
const operations: AutoBeOpenApi.IOperation[][] = await Promise.all(
|
|
29
33
|
matrix.map(async (it) => {
|
|
30
34
|
const row: AutoBeOpenApi.IOperation[] = await divideAndConquer(
|
|
31
35
|
ctx,
|
|
32
36
|
it,
|
|
33
37
|
3,
|
|
34
|
-
|
|
35
|
-
completed += count;
|
|
36
|
-
},
|
|
38
|
+
progress,
|
|
37
39
|
);
|
|
38
40
|
ctx.dispatch({
|
|
39
41
|
type: "interfaceOperations",
|
|
40
42
|
operations: row,
|
|
41
|
-
|
|
42
|
-
total: endpoints.length,
|
|
43
|
+
...progress,
|
|
43
44
|
step: ctx.state().analyze?.step ?? 0,
|
|
44
45
|
created_at: new Date().toISOString(),
|
|
45
46
|
});
|
|
@@ -53,7 +54,7 @@ async function divideAndConquer<Model extends ILlmSchema.Model>(
|
|
|
53
54
|
ctx: AutoBeContext<Model>,
|
|
54
55
|
endpoints: AutoBeOpenApi.IEndpoint[],
|
|
55
56
|
retry: number,
|
|
56
|
-
progress:
|
|
57
|
+
progress: IProgress,
|
|
57
58
|
): Promise<AutoBeOpenApi.IOperation[]> {
|
|
58
59
|
const remained: HashSet<AutoBeOpenApi.IEndpoint> = new HashSet(
|
|
59
60
|
endpoints,
|
|
@@ -68,15 +69,13 @@ async function divideAndConquer<Model extends ILlmSchema.Model>(
|
|
|
68
69
|
for (let i: number = 0; i < retry; ++i) {
|
|
69
70
|
if (remained.empty() === true || operations.size() >= endpoints.length)
|
|
70
71
|
break;
|
|
71
|
-
const before: number = operations.size();
|
|
72
72
|
const newbie: AutoBeOpenApi.IOperation[] = await forceRetry(() =>
|
|
73
|
-
process(ctx, Array.from(remained)),
|
|
73
|
+
process(ctx, Array.from(remained), progress),
|
|
74
74
|
);
|
|
75
75
|
for (const item of newbie) {
|
|
76
76
|
operations.set(item, item);
|
|
77
77
|
remained.erase(item);
|
|
78
78
|
}
|
|
79
|
-
if (operations.size() - before !== 0) progress(operations.size() - before);
|
|
80
79
|
}
|
|
81
80
|
return operations.toJSON().map((it) => it.second);
|
|
82
81
|
}
|
|
@@ -84,11 +83,12 @@ async function divideAndConquer<Model extends ILlmSchema.Model>(
|
|
|
84
83
|
async function process<Model extends ILlmSchema.Model>(
|
|
85
84
|
ctx: AutoBeContext<Model>,
|
|
86
85
|
endpoints: AutoBeOpenApi.IEndpoint[],
|
|
86
|
+
progress: IProgress,
|
|
87
87
|
): Promise<AutoBeOpenApi.IOperation[]> {
|
|
88
|
+
const prefix: string = NamingConvention.camel(ctx.state().analyze!.prefix);
|
|
88
89
|
const pointer: IPointer<AutoBeOpenApi.IOperation[] | null> = {
|
|
89
90
|
value: null,
|
|
90
91
|
};
|
|
91
|
-
|
|
92
92
|
const agentica: MicroAgentica<Model> = new MicroAgentica({
|
|
93
93
|
model: ctx.model,
|
|
94
94
|
vendor: ctx.vendor,
|
|
@@ -98,65 +98,74 @@ async function process<Model extends ILlmSchema.Model>(
|
|
|
98
98
|
describe: null,
|
|
99
99
|
},
|
|
100
100
|
},
|
|
101
|
-
histories:
|
|
102
|
-
ctx.state(),
|
|
103
|
-
AutoBeSystemPromptConstant.INTERFACE_ENDPOINT,
|
|
104
|
-
),
|
|
101
|
+
histories: transformInterfaceOperationHistories(ctx.state(), endpoints),
|
|
105
102
|
controllers: [
|
|
106
103
|
createApplication({
|
|
107
104
|
model: ctx.model,
|
|
108
|
-
roles: ctx.state().analyze?.roles.map((it) => it.name) ??
|
|
109
|
-
build: (
|
|
105
|
+
roles: ctx.state().analyze?.roles.map((it) => it.name) ?? [],
|
|
106
|
+
build: (operations) => {
|
|
110
107
|
pointer.value ??= [];
|
|
111
|
-
|
|
108
|
+
const matrix: AutoBeOpenApi.IOperation[][] = operations.map((op) => {
|
|
109
|
+
if (op.authorizationRoles.length === 0)
|
|
110
|
+
return [
|
|
111
|
+
{
|
|
112
|
+
...op,
|
|
113
|
+
path:
|
|
114
|
+
"/" +
|
|
115
|
+
[prefix, ...op.path.split("/")]
|
|
116
|
+
.filter((it) => it !== "")
|
|
117
|
+
.join("/"),
|
|
118
|
+
authorizationRole: null,
|
|
119
|
+
},
|
|
120
|
+
];
|
|
121
|
+
return op.authorizationRoles.map((role) => ({
|
|
122
|
+
...op,
|
|
123
|
+
path:
|
|
124
|
+
"/" +
|
|
125
|
+
[prefix, role, ...op.path.split("/")]
|
|
126
|
+
.filter((it) => it !== "")
|
|
127
|
+
.join("/"),
|
|
128
|
+
authorizationRole: role,
|
|
129
|
+
}));
|
|
130
|
+
});
|
|
131
|
+
progress.completed += matrix.flat().length;
|
|
132
|
+
progress.total += matrix
|
|
133
|
+
.filter((it) => it.length > 1)
|
|
134
|
+
.map((it) => it.length - 1)
|
|
135
|
+
.reduce((a, b) => a + b, 0);
|
|
136
|
+
pointer.value.push(...matrix.flat());
|
|
112
137
|
},
|
|
113
138
|
}),
|
|
114
139
|
],
|
|
115
140
|
});
|
|
116
141
|
enforceToolCall(agentica);
|
|
117
|
-
await agentica
|
|
118
|
-
.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
"",
|
|
122
|
-
"**CRITICAL INSTRUCTIONS**:",
|
|
123
|
-
"1. Base ALL operation descriptions on ACTUAL fields in the Prisma schema",
|
|
124
|
-
"2. NEVER reference fields that don't exist (e.g., deleted_at, created_by, updated_by)",
|
|
125
|
-
"3. For DELETE operations:",
|
|
126
|
-
" - Check if the entity has soft delete fields in the schema",
|
|
127
|
-
" - If YES: Describe soft delete behavior using those fields",
|
|
128
|
-
" - If NO: Describe hard delete behavior (permanent removal)",
|
|
129
|
-
"4. Every field mentioned in descriptions MUST exist in the Prisma schema",
|
|
130
|
-
"",
|
|
131
|
-
"```json",
|
|
132
|
-
JSON.stringify(Array.from(endpoints), null, 2),
|
|
133
|
-
"```",
|
|
134
|
-
].join("\n"),
|
|
135
|
-
)
|
|
136
|
-
.finally(() => {
|
|
137
|
-
const tokenUsage = agentica.getTokenUsage();
|
|
138
|
-
ctx.usage().record(tokenUsage, ["interface"]);
|
|
139
|
-
});
|
|
142
|
+
await agentica.conversate("Make API operations").finally(() => {
|
|
143
|
+
const tokenUsage = agentica.getTokenUsage();
|
|
144
|
+
ctx.usage().record(tokenUsage, ["interface"]);
|
|
145
|
+
});
|
|
140
146
|
if (pointer.value === null) throw new Error("Failed to create operations."); // never be happened
|
|
141
147
|
return pointer.value;
|
|
142
148
|
}
|
|
143
149
|
|
|
144
150
|
function createApplication<Model extends ILlmSchema.Model>(props: {
|
|
145
151
|
model: Model;
|
|
146
|
-
roles: string[]
|
|
147
|
-
build: (
|
|
152
|
+
roles: string[];
|
|
153
|
+
build: (
|
|
154
|
+
operations: IAutoBeInterfaceOperationApplication.IOperation[],
|
|
155
|
+
) => void;
|
|
148
156
|
}): IAgenticaController.IClass<Model> {
|
|
149
157
|
assertSchemaModel(props.model);
|
|
150
158
|
|
|
151
159
|
const application: ILlmApplication<Model> = collection[
|
|
152
160
|
props.model
|
|
153
161
|
] as unknown as ILlmApplication<Model>;
|
|
154
|
-
application.functions[0].validate = (next: unknown)
|
|
155
|
-
const result: IValidation<
|
|
156
|
-
typia.validate<
|
|
162
|
+
application.functions[0].validate = (next: unknown) => {
|
|
163
|
+
const result: IValidation<IAutoBeInterfaceOperationApplication.IProps> =
|
|
164
|
+
typia.validate<IAutoBeInterfaceOperationApplication.IProps>(next);
|
|
157
165
|
if (result.success === false) return result;
|
|
158
166
|
|
|
159
|
-
const operations:
|
|
167
|
+
const operations: IAutoBeInterfaceOperationApplication.IOperation[] =
|
|
168
|
+
result.data.operations;
|
|
160
169
|
const errors: IValidation.IError[] = [];
|
|
161
170
|
operations.forEach((op, i) => {
|
|
162
171
|
if (op.method === "get" && op.requestBody !== null)
|
|
@@ -166,23 +175,22 @@ function createApplication<Model extends ILlmSchema.Model>(props: {
|
|
|
166
175
|
"GET method should not have request body. Change method, or re-design the operation.",
|
|
167
176
|
value: op.requestBody,
|
|
168
177
|
});
|
|
169
|
-
if (props.roles ===
|
|
170
|
-
else if (
|
|
171
|
-
op.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
"",
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
value: op.authorizationRole,
|
|
178
|
+
if (props.roles.length === 0) op.authorizationRoles = [];
|
|
179
|
+
else if (op.authorizationRoles.length !== 0 && props.roles.length !== 0)
|
|
180
|
+
op.authorizationRoles.forEach((role, j) => {
|
|
181
|
+
if (props.roles.includes(role) === true) return;
|
|
182
|
+
errors.push({
|
|
183
|
+
path: `$input.operations[${i}].authorizationRoles[${j}]`,
|
|
184
|
+
expected: `null | ${props.roles.map((str) => JSON.stringify(str)).join(" | ")}`,
|
|
185
|
+
description: [
|
|
186
|
+
`Role "${role}" is not defined in the roles list.`,
|
|
187
|
+
"",
|
|
188
|
+
"Please select one of them below, or do not define (`null`): ",
|
|
189
|
+
"",
|
|
190
|
+
...props.roles.map((role) => `- ${role}`),
|
|
191
|
+
].join("\n"),
|
|
192
|
+
value: role,
|
|
193
|
+
});
|
|
186
194
|
});
|
|
187
195
|
});
|
|
188
196
|
if (errors.length !== 0)
|
|
@@ -201,18 +209,18 @@ function createApplication<Model extends ILlmSchema.Model>(props: {
|
|
|
201
209
|
makeOperations: (next) => {
|
|
202
210
|
props.build(next.operations);
|
|
203
211
|
},
|
|
204
|
-
} satisfies
|
|
212
|
+
} satisfies IAutoBeInterfaceOperationApplication,
|
|
205
213
|
};
|
|
206
214
|
}
|
|
207
215
|
|
|
208
216
|
const claude = typia.llm.application<
|
|
209
|
-
|
|
217
|
+
IAutoBeInterfaceOperationApplication,
|
|
210
218
|
"claude",
|
|
211
219
|
{ reference: true }
|
|
212
220
|
>();
|
|
213
221
|
const collection = {
|
|
214
222
|
chatgpt: typia.llm.application<
|
|
215
|
-
|
|
223
|
+
IAutoBeInterfaceOperationApplication,
|
|
216
224
|
"chatgpt",
|
|
217
225
|
{ reference: true }
|
|
218
226
|
>(),
|
|
@@ -222,54 +230,7 @@ const collection = {
|
|
|
222
230
|
"3.1": claude,
|
|
223
231
|
};
|
|
224
232
|
|
|
225
|
-
interface
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
*
|
|
229
|
-
* This function creates complete API operations following REST principles and
|
|
230
|
-
* quality standards. Each generated operation includes specification, path,
|
|
231
|
-
* method, detailed multi-paragraph description, concise summary, parameters,
|
|
232
|
-
* and appropriate request/response bodies.
|
|
233
|
-
*
|
|
234
|
-
* The function processes as many operations as possible in a single call,
|
|
235
|
-
* with progress tracking to ensure iterative completion of all required
|
|
236
|
-
* endpoints.
|
|
237
|
-
*
|
|
238
|
-
* @param props Properties containing the operations to generate.
|
|
239
|
-
*/
|
|
240
|
-
makeOperations(props: IMakeOperationProps): void;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
interface IMakeOperationProps {
|
|
244
|
-
/**
|
|
245
|
-
* Array of API operations to generate.
|
|
246
|
-
*
|
|
247
|
-
* Each operation in this array must include:
|
|
248
|
-
*
|
|
249
|
-
* - Specification: Detailed API specification with clear purpose and
|
|
250
|
-
* functionality
|
|
251
|
-
* - Path: Resource-centric URL path (e.g., "/resources/{resourceId}")
|
|
252
|
-
* - Method: HTTP method (get, post, put, delete, patch)
|
|
253
|
-
* - Description: Extremely detailed multi-paragraph description referencing
|
|
254
|
-
* Prisma schema comments
|
|
255
|
-
* - Summary: Concise one-sentence summary of the endpoint
|
|
256
|
-
* - Parameters: Array of all necessary parameters with descriptions and schema
|
|
257
|
-
* definitions
|
|
258
|
-
* - RequestBody: For POST/PUT/PATCH methods, with typeName referencing
|
|
259
|
-
* components.schemas
|
|
260
|
-
* - ResponseBody: With typeName referencing appropriate response type
|
|
261
|
-
*
|
|
262
|
-
* All operations must follow strict quality standards:
|
|
263
|
-
*
|
|
264
|
-
* 1. Detailed descriptions referencing Prisma schema comments
|
|
265
|
-
* 2. Accurate parameter definitions matching path parameters
|
|
266
|
-
* 3. Appropriate request/response body type references
|
|
267
|
-
* 4. Consistent patterns for CRUD operations
|
|
268
|
-
*
|
|
269
|
-
* For list retrievals (typically PATCH), include pagination, search, and
|
|
270
|
-
* sorting. For detail retrieval (GET), return a single resource. For creation
|
|
271
|
-
* (POST), use .ICreate request body. For modification (PUT), use .IUpdate
|
|
272
|
-
* request body.
|
|
273
|
-
*/
|
|
274
|
-
operations: AutoBeOpenApi.IOperation[];
|
|
233
|
+
interface IProgress {
|
|
234
|
+
completed: number;
|
|
235
|
+
total: number;
|
|
275
236
|
}
|