@autobe/agent 0.0.0 → 0.3.6
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/LICENSE +21 -21
- package/lib/AutoBeAgent.d.ts +9 -7
- package/lib/AutoBeAgent.js +106 -14
- package/lib/AutoBeAgent.js.map +1 -1
- package/lib/analyze/AnalyzeAgent.d.ts +24 -0
- package/lib/analyze/AnalyzeAgent.js +817 -0
- package/lib/analyze/AnalyzeAgent.js.map +1 -0
- package/lib/analyze/CreateReviewerAgent.d.ts +16 -0
- package/lib/analyze/CreateReviewerAgent.js +97 -0
- package/lib/analyze/CreateReviewerAgent.js.map +1 -0
- package/lib/analyze/Planning.d.ts +63 -0
- package/lib/{orchestrate/orchestratePrisma.js → analyze/Planning.js} +28 -11
- package/lib/analyze/Planning.js.map +1 -0
- package/lib/constants/AutoBeSystemPromptConstant.d.ts +14 -0
- package/lib/constants/AutoBeSystemPromptConstant.js +4 -0
- package/lib/constants/AutoBeSystemPromptConstant.js.map +1 -0
- package/lib/context/AutoBeContext.d.ts +7 -3
- package/lib/context/IAutoBeApplication.d.ts +72 -32
- package/lib/context/IAutoBeApplicationProps.d.ts +22 -2
- package/lib/context/IAutoBeApplicationResult.d.ts +0 -1
- package/lib/context/assertSchemaModel.d.ts +2 -0
- package/lib/context/assertSchemaModel.js +15 -0
- package/lib/context/assertSchemaModel.js.map +1 -0
- package/lib/{internal/transformAgenticaHistory.d.ts → factory/createAgenticaHistory.d.ts} +1 -1
- package/lib/{internal/transformAgenticaHistory.js → factory/createAgenticaHistory.js} +3 -4
- package/lib/factory/createAgenticaHistory.js.map +1 -0
- package/lib/factory/createAutoBeApplication.js +1195 -0
- package/lib/factory/createAutoBeApplication.js.map +1 -0
- package/lib/factory/createAutoBeState.js.map +1 -0
- package/lib/factory/index.d.ts +2 -0
- package/lib/factory/index.js +19 -0
- package/lib/factory/index.js.map +1 -0
- package/lib/factory/invertOpenApiDocument.d.ts +3 -0
- package/lib/factory/invertOpenApiDocument.js +51 -0
- package/lib/factory/invertOpenApiDocument.js.map +1 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +5455 -547
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/facade/transformFacadeStateMessage.d.ts +2 -0
- package/lib/orchestrate/facade/transformFacadeStateMessage.js +46 -0
- package/lib/orchestrate/facade/transformFacadeStateMessage.js.map +1 -0
- package/lib/orchestrate/index.d.ts +2 -2
- package/lib/orchestrate/index.js +2 -2
- package/lib/orchestrate/index.js.map +1 -1
- package/lib/orchestrate/interface/OpenApiEndpointComparator.d.ts +5 -0
- package/lib/orchestrate/interface/OpenApiEndpointComparator.js +16 -0
- package/lib/orchestrate/interface/OpenApiEndpointComparator.js.map +1 -0
- package/lib/orchestrate/interface/orchestrateInterface.d.ts +5 -0
- package/lib/orchestrate/interface/orchestrateInterface.js +61 -0
- package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -0
- package/lib/orchestrate/interface/orchestrateInterfaceComponents.d.ts +4 -0
- package/lib/orchestrate/interface/orchestrateInterfaceComponents.js +702 -0
- package/lib/orchestrate/interface/orchestrateInterfaceComponents.js.map +1 -0
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.d.ts +4 -0
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +452 -0
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -0
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.d.ts +4 -0
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +2065 -0
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -0
- package/lib/orchestrate/interface/transformInterfaceHistories.d.ts +3 -0
- package/lib/orchestrate/interface/transformInterfaceHistories.js +94 -0
- package/lib/orchestrate/interface/transformInterfaceHistories.js.map +1 -0
- package/lib/orchestrate/orchestrateAnalyze.d.ts +1 -3
- package/lib/orchestrate/orchestrateAnalyze.js +60 -6
- package/lib/orchestrate/orchestrateAnalyze.js.map +1 -1
- package/lib/orchestrate/{orchestratePrisma.d.ts → prisma/orchestratePrisma.d.ts} +3 -6
- package/lib/orchestrate/prisma/orchestratePrisma.js +103 -0
- package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -0
- package/lib/orchestrate/prisma/orchestratePrismaCompiler.d.ts +6 -0
- package/lib/orchestrate/prisma/orchestratePrismaCompiler.js +436 -0
- package/lib/orchestrate/prisma/orchestratePrismaCompiler.js.map +1 -0
- package/lib/orchestrate/prisma/orchestratePrismaComponent.d.ts +5 -0
- package/lib/orchestrate/prisma/orchestratePrismaComponent.js +437 -0
- package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -0
- package/lib/orchestrate/prisma/orchestratePrismaSchema.d.ts +7 -0
- package/lib/orchestrate/prisma/orchestratePrismaSchema.js +369 -0
- package/lib/orchestrate/prisma/orchestratePrismaSchema.js.map +1 -0
- package/lib/orchestrate/prisma/transformPrismaCompilerHistories.d.ts +3 -0
- package/lib/orchestrate/prisma/transformPrismaCompilerHistories.js +44 -0
- package/lib/orchestrate/prisma/transformPrismaCompilerHistories.js.map +1 -0
- package/lib/orchestrate/prisma/transformPrismaComponentsHistories.d.ts +3 -0
- package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js +42 -0
- package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js.map +1 -0
- package/lib/orchestrate/prisma/transformPrismaHistories.d.ts +3 -0
- package/lib/orchestrate/prisma/transformPrismaHistories.js +46 -0
- package/lib/orchestrate/prisma/transformPrismaHistories.js.map +1 -0
- package/lib/orchestrate/prisma/transformPrismaSchemaHistories.d.ts +3 -0
- package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js +46 -0
- package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js.map +1 -0
- package/lib/structures/IAutoBeConfig.d.ts +4 -4
- package/lib/utils/StringUtil.d.ts +4 -0
- package/lib/utils/StringUtil.js +43 -0
- package/lib/utils/StringUtil.js.map +1 -0
- package/lib/utils/divideArray.d.ts +4 -0
- package/lib/utils/divideArray.js +19 -0
- package/lib/utils/divideArray.js.map +1 -0
- package/lib/utils/emplaceMap.d.ts +1 -0
- package/lib/utils/emplaceMap.js +13 -0
- package/lib/utils/emplaceMap.js.map +1 -0
- package/package.json +29 -8
- package/src/AutoBeAgent.ts +227 -101
- package/src/analyze/AnalyzeAgent.ts +167 -0
- package/src/analyze/CreateReviewerAgent.ts +126 -0
- package/src/analyze/Planning.ts +75 -0
- package/src/constants/AutoBeSystemPromptConstant.ts +15 -0
- package/src/context/AutoBeContext.ts +19 -15
- package/src/context/AutoBeState.ts +15 -15
- package/src/context/AutoBeTokenUsage.ts +3 -3
- package/src/context/IAutoBeApplication.ts +112 -72
- package/src/context/IAutoBeApplicationProps.ts +27 -6
- package/src/context/IAutoBeApplicationResult.ts +3 -4
- package/src/context/assertSchemaModel.ts +17 -0
- package/src/{internal/transformAgenticaHistory.ts → factory/createAgenticaHistory.ts} +51 -54
- package/src/{internal → factory}/createAutoBeApplication.ts +52 -47
- package/src/{internal → factory}/createAutoBeState.ts +14 -14
- package/src/factory/index.ts +2 -0
- package/src/factory/invertOpenApiDocument.ts +63 -0
- package/src/index.ts +13 -12
- package/src/orchestrate/facade/transformFacadeStateMessage.ts +58 -0
- package/src/orchestrate/index.ts +5 -5
- package/src/orchestrate/interface/OpenApiEndpointComparator.ts +15 -0
- package/src/orchestrate/interface/orchestrateInterface.ts +66 -0
- package/src/orchestrate/interface/orchestrateInterfaceComponents.ts +324 -0
- package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +140 -0
- package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +247 -0
- package/src/orchestrate/interface/transformInterfaceHistories.ts +98 -0
- package/src/orchestrate/orchestrateAnalyze.ts +86 -21
- package/src/orchestrate/orchestrateRealize.ts +18 -18
- package/src/orchestrate/orchestrateTest.ts +18 -18
- package/src/orchestrate/prisma/orchestratePrisma.ts +117 -0
- package/src/orchestrate/prisma/orchestratePrismaCompiler.ts +194 -0
- package/src/orchestrate/prisma/orchestratePrismaComponent.ts +176 -0
- package/src/orchestrate/prisma/orchestratePrismaSchema.ts +181 -0
- package/src/orchestrate/prisma/transformPrismaCompilerHistories.ts +49 -0
- package/src/orchestrate/prisma/transformPrismaComponentsHistories.ts +46 -0
- package/src/orchestrate/prisma/transformPrismaHistories.ts +50 -0
- package/src/orchestrate/prisma/transformPrismaSchemaHistories.ts +50 -0
- package/src/structures/IAutoBeConfig.ts +25 -25
- package/src/structures/IAutoBeProps.ts +13 -13
- package/src/structures/IAutoBeVendor.ts +3 -3
- package/src/utils/StringUtil.ts +45 -0
- package/src/utils/divideArray.ts +16 -0
- package/src/utils/emplaceMap.ts +14 -0
- package/lib/factory/transformRouteDocument.d.ts +0 -3
- package/lib/factory/transformRouteDocument.js +0 -50
- package/lib/factory/transformRouteDocument.js.map +0 -1
- package/lib/internal/createAutoBeApplication.js +0 -1452
- package/lib/internal/createAutoBeApplication.js.map +0 -1
- package/lib/internal/createAutoBeState.js.map +0 -1
- package/lib/internal/transformAgenticaHistory.js.map +0 -1
- package/lib/orchestrate/interface/AutoBeInterfaceAgent.d.ts +0 -0
- package/lib/orchestrate/interface/AutoBeInterfaceAgent.js +0 -2
- package/lib/orchestrate/interface/AutoBeInterfaceAgent.js.map +0 -1
- package/lib/orchestrate/orchestrateInterface.d.ts +0 -8
- package/lib/orchestrate/orchestrateInterface.js +0 -22
- package/lib/orchestrate/orchestrateInterface.js.map +0 -1
- package/lib/orchestrate/orchestratePrisma.js.map +0 -1
- package/src/factory/transformRouteDocument.ts +0 -49
- package/src/orchestrate/interface/AutoBeInterfaceAgent.ts +0 -0
- package/src/orchestrate/orchestrateInterface.ts +0 -21
- package/src/orchestrate/orchestratePrisma.ts +0 -21
- /package/lib/{internal → factory}/createAutoBeApplication.d.ts +0 -0
- /package/lib/{internal → factory}/createAutoBeState.d.ts +0 -0
- /package/lib/{internal → factory}/createAutoBeState.js +0 -0
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autobe/agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "AI backend server code generator",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Wrtn Technologies",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/wrtnlabs/autobe"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/wrtnlabs/autobe/issues"
|
|
14
|
+
},
|
|
8
15
|
"files": [
|
|
9
16
|
"lib",
|
|
10
17
|
"src",
|
|
@@ -13,19 +20,31 @@
|
|
|
13
20
|
"README.md"
|
|
14
21
|
],
|
|
15
22
|
"dependencies": {
|
|
16
|
-
"@agentica/core": "^0.
|
|
17
|
-
"@
|
|
23
|
+
"@agentica/core": "^0.27.2",
|
|
24
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
25
|
+
"@prisma/internals": "^6.7.0",
|
|
26
|
+
"@samchon/openapi": "^4.3.3",
|
|
27
|
+
"@types/node": "^22.15.18",
|
|
28
|
+
"chalk": "4.1.2",
|
|
18
29
|
"openai": "^4.80.0",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
30
|
+
"tstl": "^3.0.0",
|
|
31
|
+
"typia": "^9.3.1",
|
|
32
|
+
"uuid": "^11.1.0",
|
|
33
|
+
"@autobe/interface": "^0.3.6"
|
|
21
34
|
},
|
|
22
35
|
"devDependencies": {
|
|
23
36
|
"@rollup/plugin-terser": "^0.4.4",
|
|
24
37
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
38
|
+
"@types/node": "^22.15.19",
|
|
39
|
+
"@types/uuid": "^10.0.0",
|
|
40
|
+
"chalk": "4.1.2",
|
|
25
41
|
"rimraf": "^6.0.1",
|
|
26
42
|
"rollup": "^4.40.1",
|
|
43
|
+
"ts-node": "^10.9.2",
|
|
27
44
|
"ts-patch": "^3.3.0",
|
|
28
|
-
"typescript": "~5.8.3"
|
|
45
|
+
"typescript": "~5.8.3",
|
|
46
|
+
"@autobe/compiler": "^0.3.6",
|
|
47
|
+
"@autobe/filesystem": "^0.3.6"
|
|
29
48
|
},
|
|
30
49
|
"keywords": [
|
|
31
50
|
"ai",
|
|
@@ -60,8 +79,10 @@
|
|
|
60
79
|
"access": "public"
|
|
61
80
|
},
|
|
62
81
|
"scripts": {
|
|
63
|
-
"build": "rimraf lib && rollup -c && tsc",
|
|
64
|
-
"
|
|
82
|
+
"build": "rimraf lib && pnpm run build:prompt && rollup -c && tsc",
|
|
83
|
+
"build:examples": "ts-node build/examples.ts",
|
|
84
|
+
"build:prompt": "ts-node build/prompt.ts",
|
|
85
|
+
"dev": "rimraf lib && pnpm run build:prompt && tsc --watch"
|
|
65
86
|
},
|
|
66
87
|
"typings": "lib/index.d.ts"
|
|
67
88
|
}
|
package/src/AutoBeAgent.ts
CHANGED
|
@@ -1,101 +1,227 @@
|
|
|
1
|
-
import { MicroAgentica } from "@agentica/core";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
1
|
+
import { MicroAgentica } from "@agentica/core";
|
|
2
|
+
import {
|
|
3
|
+
AutoBeAssistantMessageHistory,
|
|
4
|
+
AutoBeEvent,
|
|
5
|
+
AutoBeHistory,
|
|
6
|
+
AutoBeUserMessageContent,
|
|
7
|
+
AutoBeUserMessageHistory,
|
|
8
|
+
} from "@autobe/interface";
|
|
9
|
+
import { ILlmSchema } from "@samchon/openapi";
|
|
10
|
+
import { v4 } from "uuid";
|
|
11
|
+
|
|
12
|
+
import { AutoBeContext } from "./context/AutoBeContext";
|
|
13
|
+
import { AutoBeState } from "./context/AutoBeState";
|
|
14
|
+
import { AutoBeTokenUsage } from "./context/AutoBeTokenUsage";
|
|
15
|
+
import { createAgenticaHistory } from "./factory/createAgenticaHistory";
|
|
16
|
+
import { createAutoBeController } from "./factory/createAutoBeApplication";
|
|
17
|
+
import { createAutoBeState } from "./factory/createAutoBeState";
|
|
18
|
+
import { transformFacadeStateMessage } from "./orchestrate/facade/transformFacadeStateMessage";
|
|
19
|
+
import { IAutoBeProps } from "./structures/IAutoBeProps";
|
|
20
|
+
import { emplaceMap } from "./utils/emplaceMap";
|
|
21
|
+
|
|
22
|
+
export class AutoBeAgent<Model extends ILlmSchema.Model> {
|
|
23
|
+
private readonly agentica_: MicroAgentica<Model>;
|
|
24
|
+
private readonly histories_: AutoBeHistory[];
|
|
25
|
+
private readonly context_: AutoBeContext<Model>;
|
|
26
|
+
|
|
27
|
+
private readonly state_: AutoBeState;
|
|
28
|
+
private readonly listeners_: Map<
|
|
29
|
+
string,
|
|
30
|
+
Set<(event: AutoBeEvent) => Promise<void> | void>
|
|
31
|
+
>;
|
|
32
|
+
|
|
33
|
+
/* -----------------------------------------------------------
|
|
34
|
+
CONSTRUCTOR
|
|
35
|
+
----------------------------------------------------------- */
|
|
36
|
+
/**
|
|
37
|
+
* Initializer constructor.
|
|
38
|
+
*
|
|
39
|
+
* @param props Properties to construct the agent
|
|
40
|
+
*/
|
|
41
|
+
public constructor(private readonly props: IAutoBeProps<Model>) {
|
|
42
|
+
this.histories_ = props.histories?.slice() ?? [];
|
|
43
|
+
this.state_ = createAutoBeState(this.histories_);
|
|
44
|
+
this.context_ = {
|
|
45
|
+
model: props.model,
|
|
46
|
+
vendor: props.vendor,
|
|
47
|
+
config: props.config,
|
|
48
|
+
compiler: props.compiler,
|
|
49
|
+
histories: () => this.histories_,
|
|
50
|
+
state: () => this.state_,
|
|
51
|
+
usage: () => this.agentica_.getTokenUsage(),
|
|
52
|
+
files: () => this.getFiles(),
|
|
53
|
+
dispatch: (event) => {
|
|
54
|
+
this.dispatch(event).catch(() => {});
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
this.listeners_ = new Map();
|
|
58
|
+
|
|
59
|
+
this.agentica_ = new MicroAgentica({
|
|
60
|
+
model: props.model,
|
|
61
|
+
vendor: props.vendor,
|
|
62
|
+
config: {
|
|
63
|
+
...(props.config ?? {}),
|
|
64
|
+
executor: {
|
|
65
|
+
describe: null,
|
|
66
|
+
},
|
|
67
|
+
systemPrompt: {
|
|
68
|
+
execute: () => transformFacadeStateMessage(this.state_),
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
controllers: [
|
|
72
|
+
createAutoBeController({
|
|
73
|
+
model: props.model,
|
|
74
|
+
context: this.context_,
|
|
75
|
+
}),
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
this.agentica_.getHistories().push(
|
|
79
|
+
...this.histories_
|
|
80
|
+
.map((history) =>
|
|
81
|
+
createAgenticaHistory({
|
|
82
|
+
operations: this.agentica_.getOperations(),
|
|
83
|
+
history,
|
|
84
|
+
}),
|
|
85
|
+
)
|
|
86
|
+
.filter((h) => h !== null),
|
|
87
|
+
);
|
|
88
|
+
this.agentica_.on("assistantMessage", async (message) => {
|
|
89
|
+
const start = new Date();
|
|
90
|
+
const history: AutoBeAssistantMessageHistory = {
|
|
91
|
+
id: v4(),
|
|
92
|
+
type: "assistantMessage",
|
|
93
|
+
text: await message.join(),
|
|
94
|
+
created_at: start.toISOString(),
|
|
95
|
+
completed_at: new Date().toISOString(),
|
|
96
|
+
};
|
|
97
|
+
this.histories_.push(history);
|
|
98
|
+
this.dispatch({
|
|
99
|
+
type: "assistantMessage",
|
|
100
|
+
text: history.text,
|
|
101
|
+
created_at: history.created_at,
|
|
102
|
+
}).catch(() => {});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** @internal */
|
|
107
|
+
public clone(): AutoBeAgent<Model> {
|
|
108
|
+
return new AutoBeAgent<Model>({
|
|
109
|
+
...this.props,
|
|
110
|
+
histories: this.histories_.slice(),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public on<Type extends AutoBeEvent.Type>(
|
|
115
|
+
type: Type,
|
|
116
|
+
listener: (event: AutoBeEvent.Mapper[Type]) => Promise<void> | void,
|
|
117
|
+
): this {
|
|
118
|
+
emplaceMap(this.listeners_, type, () => new Set()).add(
|
|
119
|
+
listener as (event: AutoBeEvent) => any,
|
|
120
|
+
);
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public off<Type extends AutoBeEvent.Type>(
|
|
125
|
+
type: Type,
|
|
126
|
+
listener: (event: AutoBeEvent.Mapper[Type]) => Promise<void> | void,
|
|
127
|
+
): this {
|
|
128
|
+
const set = this.listeners_.get(type);
|
|
129
|
+
if (set === undefined) return this;
|
|
130
|
+
|
|
131
|
+
set.delete(listener as (event: AutoBeEvent) => any);
|
|
132
|
+
if (set.size === 0) this.listeners_.delete(type);
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/* -----------------------------------------------------------
|
|
137
|
+
ACCESSORS
|
|
138
|
+
----------------------------------------------------------- */
|
|
139
|
+
public async conversate(
|
|
140
|
+
content: string | AutoBeUserMessageContent | AutoBeUserMessageContent[],
|
|
141
|
+
): Promise<AutoBeHistory[]> {
|
|
142
|
+
const index: number = this.histories_.length;
|
|
143
|
+
const userMessageHistory: AutoBeUserMessageHistory = {
|
|
144
|
+
id: v4(),
|
|
145
|
+
type: "userMessage",
|
|
146
|
+
contents:
|
|
147
|
+
typeof content === "string"
|
|
148
|
+
? [
|
|
149
|
+
{
|
|
150
|
+
type: "text",
|
|
151
|
+
text: content,
|
|
152
|
+
},
|
|
153
|
+
]
|
|
154
|
+
: Array.isArray(content)
|
|
155
|
+
? content
|
|
156
|
+
: [content],
|
|
157
|
+
created_at: new Date().toISOString(),
|
|
158
|
+
};
|
|
159
|
+
this.histories_.push(userMessageHistory);
|
|
160
|
+
this.dispatch(userMessageHistory).catch(() => {});
|
|
161
|
+
|
|
162
|
+
await this.agentica_.conversate(content);
|
|
163
|
+
return this.histories_.slice(index);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public getFiles(): Record<string, string> {
|
|
167
|
+
return {
|
|
168
|
+
...Object.fromEntries(
|
|
169
|
+
this.state_.analyze
|
|
170
|
+
? Object.entries(this.state_.analyze.files).map(([key, value]) => [
|
|
171
|
+
`docs/analysis/${key.split("/").at(-1)}`,
|
|
172
|
+
value,
|
|
173
|
+
])
|
|
174
|
+
: [],
|
|
175
|
+
),
|
|
176
|
+
...Object.fromEntries(
|
|
177
|
+
this.state_.prisma?.result.type === "success"
|
|
178
|
+
? [
|
|
179
|
+
...Object.entries(this.state_.prisma.result.schemas).map(
|
|
180
|
+
([key, value]) => [
|
|
181
|
+
`prisma/schema/${key.split("/").at(-1)}`,
|
|
182
|
+
value,
|
|
183
|
+
],
|
|
184
|
+
),
|
|
185
|
+
["docs/ERD.md", this.state_.prisma.result.document],
|
|
186
|
+
]
|
|
187
|
+
: [],
|
|
188
|
+
),
|
|
189
|
+
...(this.state_.interface ? this.state_.interface.files : {}),
|
|
190
|
+
...(this.state_.test?.result.type === "success"
|
|
191
|
+
? this.state_.test.files
|
|
192
|
+
: {}),
|
|
193
|
+
...(this.state_.realize?.result.type === "success"
|
|
194
|
+
? this.state_.realize.files
|
|
195
|
+
: {}),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
public getHistories(): AutoBeHistory[] {
|
|
200
|
+
return this.histories_;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
public getTokenUsage(): AutoBeTokenUsage {
|
|
204
|
+
return this.agentica_.getTokenUsage();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/* -----------------------------------------------------------
|
|
208
|
+
CONTEXTS
|
|
209
|
+
----------------------------------------------------------- */
|
|
210
|
+
/** @internal */
|
|
211
|
+
public getContext(): AutoBeContext<Model> {
|
|
212
|
+
return this.context_;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** @internal */
|
|
216
|
+
private async dispatch(event: AutoBeEvent): Promise<void> {
|
|
217
|
+
const set = this.listeners_.get(event.type);
|
|
218
|
+
if (set === undefined) return;
|
|
219
|
+
await Promise.all(
|
|
220
|
+
Array.from(set).map(async (listener) => {
|
|
221
|
+
try {
|
|
222
|
+
await listener(event);
|
|
223
|
+
} catch {}
|
|
224
|
+
}),
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
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 { AutoBeSystemPromptConstant } from "../constants/AutoBeSystemPromptConstant";
|
|
7
|
+
import { AutoBeContext } from "../context/AutoBeContext";
|
|
8
|
+
import { assertSchemaModel } from "../context/assertSchemaModel";
|
|
9
|
+
import { createReviewerAgent } from "./CreateReviewerAgent";
|
|
10
|
+
import { IPlanning, Planning } from "./Planning";
|
|
11
|
+
|
|
12
|
+
type Filename = string;
|
|
13
|
+
type FileContent = string;
|
|
14
|
+
|
|
15
|
+
export class AnalyzeAgent<Model extends ILlmSchema.Model> {
|
|
16
|
+
private readonly agent: MicroAgentica<Model>;
|
|
17
|
+
private readonly fileMap: Record<Filename, FileContent> = {};
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
private readonly createReviewerAgentFn: typeof createReviewerAgent,
|
|
21
|
+
private readonly ctx: AutoBeContext<Model>,
|
|
22
|
+
private readonly pointer: IPointer<{
|
|
23
|
+
files: Record<Filename, FileContent>;
|
|
24
|
+
} | null>,
|
|
25
|
+
) {
|
|
26
|
+
assertSchemaModel(ctx.model);
|
|
27
|
+
|
|
28
|
+
const controller = createController<Model>({
|
|
29
|
+
model: ctx.model,
|
|
30
|
+
execute: new Planning(this.fileMap),
|
|
31
|
+
build: async (files: Record<Filename, FileContent>) => {
|
|
32
|
+
this.pointer.value = { files };
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
this.agent = new MicroAgentica({
|
|
36
|
+
controllers: [controller],
|
|
37
|
+
model: ctx.model,
|
|
38
|
+
vendor: ctx.vendor,
|
|
39
|
+
config: {
|
|
40
|
+
systemPrompt: {
|
|
41
|
+
common: () => {
|
|
42
|
+
return AutoBeSystemPromptConstant.ANALYZE.replace(
|
|
43
|
+
"{% Guidelines %}",
|
|
44
|
+
AutoBeSystemPromptConstant.ANALYZE_GUIDELINE,
|
|
45
|
+
)
|
|
46
|
+
.replace(
|
|
47
|
+
"{% Example Documentation %}",
|
|
48
|
+
AutoBeSystemPromptConstant.ANALYZE_EXAMPLE,
|
|
49
|
+
)
|
|
50
|
+
.replace("{% User Locale %}", ctx.config?.locale ?? "en-US");
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
tokenUsage: ctx.usage(),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Conversate with planner agent
|
|
60
|
+
*
|
|
61
|
+
* @param content Conversation from user in this time.
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
async conversate(content: string): Promise<string> {
|
|
65
|
+
const response = await this.agent.conversate(content);
|
|
66
|
+
const lastMessage = response[response.length - 1]!;
|
|
67
|
+
|
|
68
|
+
if ("text" in lastMessage) {
|
|
69
|
+
this.ctx.dispatch({
|
|
70
|
+
type: "analyzeWriteDocument",
|
|
71
|
+
files: this.fileMap,
|
|
72
|
+
created_at: new Date().toISOString(),
|
|
73
|
+
step: this.ctx.state().analyze?.step ?? 0,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const aborted =
|
|
77
|
+
lastMessage.type === "describe" &&
|
|
78
|
+
lastMessage.executes.some((el) => {
|
|
79
|
+
if (
|
|
80
|
+
el.protocol === "class" &&
|
|
81
|
+
el.operation.function.name === "abort"
|
|
82
|
+
) {
|
|
83
|
+
el.arguments;
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (aborted === true) {
|
|
89
|
+
return lastMessage.text;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const currentFiles = this.fileMap;
|
|
93
|
+
|
|
94
|
+
const reviewer = this.createReviewerAgentFn(this.ctx, {
|
|
95
|
+
query: content,
|
|
96
|
+
currentFiles,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const [review] = await reviewer.conversate(lastMessage.text);
|
|
100
|
+
|
|
101
|
+
if (review) {
|
|
102
|
+
if (review.type === "assistantMessage") {
|
|
103
|
+
this.ctx.dispatch({
|
|
104
|
+
type: "analyzeReview",
|
|
105
|
+
review: review.text,
|
|
106
|
+
created_at: new Date().toISOString(),
|
|
107
|
+
step: this.ctx.state().analyze?.step ?? 0,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return this.conversate(
|
|
111
|
+
JSON.stringify({
|
|
112
|
+
user_query: content,
|
|
113
|
+
message: `THIS IS ANSWER OF REVIEW AGENT. FOLLOW THIS INSTRUCTIONS. AND DON\'T REQUEST ANYTHING.`,
|
|
114
|
+
review: review.text,
|
|
115
|
+
}),
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return "COMPLETE";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function createController<Model extends ILlmSchema.Model>(props: {
|
|
126
|
+
model: Model;
|
|
127
|
+
execute: Planning;
|
|
128
|
+
build: (input: Record<Filename, FileContent>) => void;
|
|
129
|
+
}): IAgenticaController.IClass<Model> {
|
|
130
|
+
assertSchemaModel(props.model);
|
|
131
|
+
const application: ILlmApplication<Model> = collection[
|
|
132
|
+
props.model
|
|
133
|
+
] as unknown as ILlmApplication<Model>;
|
|
134
|
+
return {
|
|
135
|
+
protocol: "class",
|
|
136
|
+
name: "Planning",
|
|
137
|
+
application,
|
|
138
|
+
// execute: props.execute,
|
|
139
|
+
execute: {
|
|
140
|
+
removeFile: (input) => {
|
|
141
|
+
const response = props.execute.removeFile(input);
|
|
142
|
+
props.build(props.execute.allFiles());
|
|
143
|
+
return response;
|
|
144
|
+
},
|
|
145
|
+
abort: (input) => {
|
|
146
|
+
const response = props.execute.abort(input);
|
|
147
|
+
props.build(props.execute.allFiles());
|
|
148
|
+
return response;
|
|
149
|
+
},
|
|
150
|
+
createOrUpdateFile: (input) => {
|
|
151
|
+
const response = props.execute.createOrUpdateFile(input);
|
|
152
|
+
props.build(props.execute.allFiles());
|
|
153
|
+
return response;
|
|
154
|
+
},
|
|
155
|
+
} satisfies IPlanning,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const claude = typia.llm.application<Planning, "claude", { reference: true }>();
|
|
160
|
+
const collection = {
|
|
161
|
+
chatgpt: typia.llm.application<Planning, "chatgpt", { reference: true }>(),
|
|
162
|
+
claude,
|
|
163
|
+
llama: claude,
|
|
164
|
+
deepseek: claude,
|
|
165
|
+
"3.1": claude,
|
|
166
|
+
"3.0": typia.llm.application<Planning, "3.0">(),
|
|
167
|
+
};
|