@autobe/benchmark 0.29.0 → 0.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/lib/example/AutoBeExampleArchiver.d.ts +18 -0
  2. package/lib/example/AutoBeExampleArchiver.js +237 -0
  3. package/lib/example/AutoBeExampleArchiver.js.map +1 -0
  4. package/lib/example/AutoBeExampleBenchmark.d.ts +15 -0
  5. package/lib/example/AutoBeExampleBenchmark.js +110 -0
  6. package/lib/example/AutoBeExampleBenchmark.js.map +1 -0
  7. package/lib/example/AutoBeExampleStorage.d.ts +2 -1
  8. package/lib/example/AutoBeExampleStorage.js +42 -41
  9. package/lib/example/AutoBeExampleStorage.js.map +1 -1
  10. package/lib/example/index.d.ts +2 -0
  11. package/lib/example/index.js +2 -0
  12. package/lib/example/index.js.map +1 -1
  13. package/lib/replay/AutoBeReplayComputer.js +2 -2
  14. package/lib/replay/AutoBeReplayComputer.js.map +1 -1
  15. package/lib/replay/AutoBeReplayStorage.d.ts +5 -0
  16. package/lib/replay/AutoBeReplayStorage.js +15 -0
  17. package/lib/replay/AutoBeReplayStorage.js.map +1 -1
  18. package/lib/structures/IAutoBeExampleBenchmarkState.d.ts +24 -0
  19. package/lib/structures/IAutoBeExampleBenchmarkState.js +3 -0
  20. package/lib/structures/IAutoBeExampleBenchmarkState.js.map +1 -0
  21. package/lib/structures/index.d.ts +1 -0
  22. package/lib/structures/index.js +18 -0
  23. package/lib/structures/index.js.map +1 -0
  24. package/package.json +4 -5
  25. package/src/example/AutoBeExampleArchiver.ts +334 -0
  26. package/src/example/AutoBeExampleBenchmark.ts +143 -0
  27. package/src/example/AutoBeExampleStorage.ts +45 -44
  28. package/src/example/index.ts +2 -0
  29. package/src/replay/AutoBeReplayComputer.ts +1 -1
  30. package/src/replay/AutoBeReplayStorage.ts +29 -0
  31. package/src/structures/IAutoBeExampleBenchmarkState.ts +29 -0
  32. package/src/structures/index.ts +1 -0
@@ -1,8 +1,13 @@
1
1
  import { AutoBeExampleProject, IAutoBePlaygroundReplay } from "@autobe/interface";
2
2
  export declare namespace AutoBeReplayStorage {
3
3
  const getAll: (vendor: string, projectFilter?: (project: AutoBeExampleProject) => boolean) => Promise<IAutoBePlaygroundReplay[]>;
4
+ const getAllSummaries: (vendor: string, projectFilter?: (project: AutoBeExampleProject) => boolean) => Promise<IAutoBePlaygroundReplay.ISummary[]>;
4
5
  const get: (props: {
5
6
  vendor: string;
6
7
  project: AutoBeExampleProject;
7
8
  }) => Promise<IAutoBePlaygroundReplay | null>;
9
+ const getSummary: (props: {
10
+ vendor: string;
11
+ project: AutoBeExampleProject;
12
+ }) => Promise<IAutoBePlaygroundReplay.ISummary | null>;
8
13
  }
@@ -13,6 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.AutoBeReplayStorage = void 0;
16
+ const filesystem_1 = require("@autobe/filesystem");
17
+ const fs_1 = __importDefault(require("fs"));
16
18
  const typia_1 = __importDefault(require("typia"));
17
19
  const AutoBeExampleStorage_1 = require("../example/AutoBeExampleStorage");
18
20
  var AutoBeReplayStorage;
@@ -27,6 +29,13 @@ var AutoBeReplayStorage;
27
29
  })));
28
30
  return replays.filter((r) => r !== null);
29
31
  });
32
+ AutoBeReplayStorage.getAllSummaries = (vendor, projectFilter) => __awaiter(this, void 0, void 0, function* () {
33
+ const projects = typia_1.default.misc
34
+ .literals()
35
+ .filter(projectFilter !== null && projectFilter !== void 0 ? projectFilter : (() => true));
36
+ const summaries = yield Promise.all(projects.map((project) => AutoBeReplayStorage.getSummary({ vendor, project })));
37
+ return summaries.filter((s) => s !== null);
38
+ });
30
39
  AutoBeReplayStorage.get = (props) => __awaiter(this, void 0, void 0, function* () {
31
40
  const histories = yield getHistories(props);
32
41
  if (histories === null)
@@ -54,6 +63,12 @@ var AutoBeReplayStorage;
54
63
  realize: yield snapshots("realize"),
55
64
  };
56
65
  });
66
+ AutoBeReplayStorage.getSummary = (props) => __awaiter(this, void 0, void 0, function* () {
67
+ const location = `${AutoBeExampleStorage_1.AutoBeExampleStorage.getDirectory(props)}/summary.json.gz`;
68
+ if (fs_1.default.existsSync(location) === false)
69
+ return null;
70
+ return JSON.parse(yield filesystem_1.CompressUtil.gunzip(yield fs_1.default.promises.readFile(location)));
71
+ });
57
72
  const getHistories = (props) => __awaiter(this, void 0, void 0, function* () {
58
73
  for (const phase of SEQUENCE) {
59
74
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"AutoBeReplayStorage.js","sourceRoot":"","sources":["../../src/replay/AutoBeReplayStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAOA,kDAA0B;AAE1B,0EAAuE;AAEvE,IAAiB,mBAAmB,CAkEnC;AAlED,WAAiB,mBAAmB;IACrB,0BAAM,GAAG,CACpB,MAAc,EACd,aAA0D,EACtB,EAAE;QACtC,MAAM,QAAQ,GAA2B,eAAK,CAAC,IAAI;aAChD,QAAQ,EAAwB;aAChC,MAAM,CAAC,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QACzC,MAAM,OAAO,GAA0C,MAAM,OAAO,CAAC,GAAG,CACtE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACjB,mBAAmB,CAAC,GAAG,CAAC;YACtB,MAAM;YACN,OAAO,EAAE,CAAC;SACX,CAAC,CACH,CACF,CAAC;QACF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;IAC3C,CAAC,CAAA,CAAC;IAEW,uBAAG,GAAG,CAAO,KAGzB,EAA2C,EAAE;QAC5C,MAAM,SAAS,GAA2B,MAAM,YAAY,CAAC,KAAK,CAAC,CAAC;QACpE,IAAI,SAAS,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QAEpC,M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C,CAAA,CAAC;IAEF,MAAM,YAAY,GAAG,CAAO,KAG3B,EAAmC,EAAE;QACpC,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YAC7B,IAAI,CAAC;gBACH,OAAO,MAAM,2CAAoB,CAAC,YAAY,CAAC;oBAC7C,MAAM,EAAE,KAAK,CAAC,MAAM;oBACpB,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,KAAK;iBACN,CAAC,CAAC;YACL,CAAC;YAAC,WAAM,CAAC,CAAA,CAAC;QACZ,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAA,CAAC;AACJ,CAAC,EA7FgB,mBAAmB,mCAAnB,mBAAmB,QA6FnC;AAED,MAAM,QAAQ,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,CAAU,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { AutoBeEventSnapshot, AutoBeExampleProject, AutoBePhase } from "@autobe/interface";
2
+ export interface IAutoBeExampleBenchmarkState {
3
+ vendors: IAutoBeExampleBenchmarkState.IOfVendor[];
4
+ }
5
+ export declare namespace IAutoBeExampleBenchmarkState {
6
+ interface IOfVendor {
7
+ name: string;
8
+ projects: IOfProject[];
9
+ }
10
+ interface IOfProject {
11
+ name: AutoBeExampleProject;
12
+ phases: IOfPhase[];
13
+ success: boolean | null;
14
+ started_at: Date;
15
+ completed_at: Date | null;
16
+ }
17
+ interface IOfPhase {
18
+ name: AutoBePhase;
19
+ snapshot: AutoBeEventSnapshot | null;
20
+ success: boolean | null;
21
+ started_at: Date;
22
+ completed_at: Date | null;
23
+ }
24
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IAutoBeExampleBenchmarkState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IAutoBeExampleBenchmarkState.js","sourceRoot":"","sources":["../../src/structures/IAutoBeExampleBenchmarkState.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export * from "./IAutoBeExampleBenchmarkState";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./IAutoBeExampleBenchmarkState"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/structures/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA+C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobe/benchmark",
3
- "version": "0.29.0",
3
+ "version": "0.29.1",
4
4
  "description": "AI backend server code generator",
5
5
  "main": "lib/index.js",
6
6
  "keywords": [],
@@ -27,10 +27,9 @@
27
27
  "tstl": "^3.0.0",
28
28
  "typia": "^10.0.2",
29
29
  "uuid": "^11.1.0",
30
- "@autobe/agent": "^0.29.0",
31
- "@autobe/filesystem": "^0.29.0",
32
- "@autobe/interface": "^0.29.0",
33
- "@autobe/utils": "^0.29.0"
30
+ "@autobe/filesystem": "^0.29.1",
31
+ "@autobe/utils": "^0.29.1",
32
+ "@autobe/interface": "^0.29.1"
34
33
  },
35
34
  "devDependencies": {
36
35
  "@types/uuid": "^10.0.0",
@@ -0,0 +1,334 @@
1
+ import { FileSystemIterator } from "@autobe/filesystem";
2
+ import {
3
+ AutoBeAggregateEventBase,
4
+ AutoBeEventOfSerializable,
5
+ AutoBeEventSnapshot,
6
+ AutoBeExampleProject,
7
+ AutoBeHistory,
8
+ AutoBePhase,
9
+ AutoBePrismaHistory,
10
+ AutoBeProcessAggregateCollection,
11
+ AutoBeUserMessageContent,
12
+ IAutoBeAgent,
13
+ IAutoBePlaygroundReplay,
14
+ IAutoBeTokenUsageJson,
15
+ } from "@autobe/interface";
16
+ import {
17
+ AutoBeProcessAggregateFactory,
18
+ TokenUsageComputer,
19
+ } from "@autobe/utils";
20
+ import typia from "typia";
21
+
22
+ import { AutoBeReplayComputer } from "../replay";
23
+ import { AutoBeExampleStorage } from "./AutoBeExampleStorage";
24
+
25
+ export namespace AutoBeExampleArchiver {
26
+ export interface IContext {
27
+ vendor: string;
28
+ project: AutoBeExampleProject;
29
+ agent: (props: IAgentProps) => Promise<IAutoBeAgent>;
30
+ on: (snapshot: AutoBeEventSnapshot) => void;
31
+ }
32
+
33
+ export interface IAgentProps {
34
+ histories: AutoBeHistory[];
35
+ tokenUsage: IAutoBeTokenUsageJson;
36
+ }
37
+
38
+ export const archiveAnalyze = (ctx: IContext): Promise<boolean> =>
39
+ archive(ctx, {
40
+ phase: "analyze",
41
+ trial: async (conversate): Promise<boolean> =>
42
+ (await conversate(
43
+ await AutoBeExampleStorage.getUserMessage({
44
+ project: ctx.project,
45
+ phase: "analyze",
46
+ }).then((r) => r.contents),
47
+ )) ||
48
+ (await conversate(
49
+ "I'm not familiar with the analyze feature. Please determine everything by yourself, and just show me the analysis report.",
50
+ )) ||
51
+ (await conversate(
52
+ "I already told you to publish the analysis report. Never ask me anything, and just do it right now.",
53
+ )),
54
+ predicate: (histories): boolean =>
55
+ histories.some((h) => h.type === "analyze"),
56
+ });
57
+
58
+ export const archivePrisma = (ctx: IContext): Promise<boolean> =>
59
+ archive(ctx, {
60
+ phase: "prisma",
61
+ trial: getTrial({
62
+ project: ctx.project,
63
+ phase: "prisma",
64
+ }),
65
+ predicate: (histories): boolean => {
66
+ const prisma: AutoBePrismaHistory | undefined = histories.find(
67
+ (h) => h.type === "prisma",
68
+ );
69
+ return prisma !== undefined && prisma.compiled.type === "success";
70
+ },
71
+ });
72
+
73
+ export const archiveInterface = (ctx: IContext): Promise<boolean> =>
74
+ archive(ctx, {
75
+ phase: "interface",
76
+ trial: getTrial({
77
+ project: ctx.project,
78
+ phase: "interface",
79
+ }),
80
+ predicate: (histories): boolean => {
81
+ const interfaceHistory: AutoBeHistory | undefined = histories.find(
82
+ (h) => h.type === "interface",
83
+ );
84
+ return (
85
+ interfaceHistory !== undefined && interfaceHistory.missed.length === 0
86
+ );
87
+ },
88
+ });
89
+
90
+ export const archiveTest = (ctx: IContext): Promise<boolean> =>
91
+ archive(ctx, {
92
+ phase: "test",
93
+ trial: getTrial({
94
+ project: ctx.project,
95
+ phase: "test",
96
+ }),
97
+ predicate: (histories): boolean => {
98
+ const testHistory: AutoBeHistory | undefined = histories.find(
99
+ (h) => h.type === "test",
100
+ );
101
+ return (
102
+ testHistory !== undefined && testHistory.compiled.type === "success"
103
+ );
104
+ },
105
+ });
106
+
107
+ export const archiveRealize = (ctx: IContext): Promise<boolean> =>
108
+ archive(ctx, {
109
+ phase: "realize",
110
+ trial: getTrial({
111
+ project: ctx.project,
112
+ phase: "realize",
113
+ }),
114
+ predicate: (histories): boolean => {
115
+ const realizeHistory: AutoBeHistory | undefined = histories.find(
116
+ (h) => h.type === "realize",
117
+ );
118
+ return (
119
+ realizeHistory !== undefined &&
120
+ realizeHistory.compiled.type === "success"
121
+ );
122
+ },
123
+ });
124
+
125
+ const archive = async (
126
+ ctx: IContext,
127
+ props: {
128
+ phase: AutoBePhase;
129
+ trial: (
130
+ conversate: (
131
+ input: string | AutoBeUserMessageContent | AutoBeUserMessageContent[],
132
+ ) => Promise<boolean>,
133
+ ) => Promise<boolean>;
134
+ predicate: (histories: AutoBeHistory[]) => boolean;
135
+ },
136
+ ): Promise<boolean> => {
137
+ // INITIALIZE AGENT
138
+ const asset: IAgentProps = await getAsset({
139
+ vendor: ctx.vendor,
140
+ project: ctx.project,
141
+ phase: props.phase,
142
+ });
143
+ const agent: IAutoBeAgent = await ctx.agent(asset);
144
+ const snapshots: AutoBeEventSnapshot[] = [];
145
+ for (const type of typia.misc.literals<AutoBeEventOfSerializable.Type>()) {
146
+ agent.on(type, (e) => {
147
+ const s: AutoBeEventSnapshot = {
148
+ event: e,
149
+ tokenUsage: agent.getTokenUsage(),
150
+ };
151
+ ctx.on(s);
152
+ snapshots.push(s);
153
+ });
154
+ }
155
+
156
+ const summarize = async (
157
+ histories: AutoBeHistory[],
158
+ error: boolean,
159
+ ): Promise<void> => {
160
+ const replay: IAutoBePlaygroundReplay = {
161
+ vendor: ctx.vendor,
162
+ project: ctx.project,
163
+ histories,
164
+ analyze: null,
165
+ prisma: null,
166
+ interface: null,
167
+ test: null,
168
+ realize: null,
169
+ };
170
+ for (const phase of PHASES)
171
+ if (phase === props.phase) {
172
+ replay[phase] = snapshots;
173
+ break;
174
+ } else
175
+ replay[phase] = await AutoBeExampleStorage.getSnapshots({
176
+ vendor: ctx.vendor,
177
+ project: ctx.project,
178
+ phase,
179
+ });
180
+ const summary: IAutoBePlaygroundReplay.ISummary =
181
+ AutoBeReplayComputer.summarize(replay);
182
+ if (error === true) {
183
+ const aggregates: AutoBeProcessAggregateCollection =
184
+ AutoBeProcessAggregateFactory.createCollection();
185
+ for (const { event } of snapshots) {
186
+ if (typia.is<AutoBeAggregateEventBase>(event) === false) continue;
187
+ AutoBeProcessAggregateFactory.emplaceEvent(aggregates, event);
188
+ }
189
+ summary[props.phase] = {
190
+ aggregates,
191
+ success: false,
192
+ elapsed: 0,
193
+ commodity: {},
194
+ };
195
+ }
196
+ await AutoBeExampleStorage.save({
197
+ vendor: ctx.vendor,
198
+ project: ctx.project,
199
+ files: {
200
+ [`summary.json`]: JSON.stringify(summary),
201
+ },
202
+ });
203
+ };
204
+
205
+ try {
206
+ // CONVERSATE
207
+ const go = async (
208
+ c: string | AutoBeUserMessageContent | AutoBeUserMessageContent[],
209
+ ): Promise<boolean> => {
210
+ const result: AutoBeHistory[] = await agent.conversate(c);
211
+ return result.some((h) => h.type === props.phase);
212
+ };
213
+ const done: boolean = await props.trial(go);
214
+ if (done === false)
215
+ throw new Error(
216
+ `Failed to function calling in the "${props.phase}" phase of the "${ctx.project}" project.`,
217
+ );
218
+
219
+ // AGGREGATE
220
+ const histories: AutoBeHistory[] = agent.getHistories();
221
+ try {
222
+ await FileSystemIterator.save({
223
+ root: `${AutoBeExampleStorage.TEST_ROOT}/results/${AutoBeExampleStorage.slugModel(ctx.vendor, false)}/${ctx.project}/${props.phase}`,
224
+ files: {
225
+ ...(await agent.getFiles()),
226
+ ...Object.fromEntries(
227
+ histories
228
+ .filter(
229
+ (h) =>
230
+ h.type === "prisma" ||
231
+ h.type === "interface" ||
232
+ h.type === "test" ||
233
+ h.type === "realize",
234
+ )
235
+ .map((h) => [`autobe/${h.type}.instruction.md`, h.instruction]),
236
+ ),
237
+ },
238
+ });
239
+ } catch {}
240
+ await AutoBeExampleStorage.save({
241
+ vendor: ctx.vendor,
242
+ project: ctx.project,
243
+ files: {
244
+ [`${props.phase}.histories.json`]: JSON.stringify(histories),
245
+ [`${props.phase}.snapshots.json`]: JSON.stringify(snapshots),
246
+ [`${props.phase}.error.json`]: null,
247
+ },
248
+ });
249
+ await summarize([...asset.histories, ...histories], false);
250
+ return props.predicate(histories);
251
+ } catch (error) {
252
+ if (error instanceof Error)
253
+ await AutoBeExampleStorage.save({
254
+ vendor: ctx.vendor,
255
+ project: ctx.project,
256
+ files: {
257
+ [`${props.phase}.snapshots.json`]: JSON.stringify(snapshots),
258
+ [`${props.phase}.error.json`]: JSON.stringify({
259
+ ...error,
260
+ name: error.name,
261
+ message: error.message,
262
+ stack: error.stack,
263
+ }),
264
+ },
265
+ });
266
+ await summarize(asset.histories, true);
267
+ throw error;
268
+ }
269
+ };
270
+
271
+ const getTrial =
272
+ (props: { project: AutoBeExampleProject; phase: AutoBePhase }) =>
273
+ async (
274
+ conversate: (
275
+ input: string | AutoBeUserMessageContent | AutoBeUserMessageContent[],
276
+ ) => Promise<boolean>,
277
+ ): Promise<boolean> =>
278
+ (await conversate(
279
+ await AutoBeExampleStorage.getUserMessage(props).then(
280
+ (r) => r.contents,
281
+ ),
282
+ )) ||
283
+ (await conversate(
284
+ "Don't ask me to do that, and just do it right now.",
285
+ )) ||
286
+ (await conversate(
287
+ `I already told you to do ${props.phase} process. Never ask me anything, and just do it right now. Go go go!`,
288
+ ));
289
+
290
+ const getAsset = async (props: {
291
+ vendor: string;
292
+ project: AutoBeExampleProject;
293
+ phase: AutoBePhase;
294
+ }): Promise<IAgentProps> => {
295
+ const previous: AutoBePhase | null =
296
+ PHASES[PHASES.indexOf(props.phase) - 1] ?? null;
297
+ if (previous === null)
298
+ return {
299
+ histories: [],
300
+ tokenUsage: {
301
+ aggregate: TokenUsageComputer.zero(),
302
+ facade: TokenUsageComputer.zero(),
303
+ analyze: TokenUsageComputer.zero(),
304
+ prisma: TokenUsageComputer.zero(),
305
+ interface: TokenUsageComputer.zero(),
306
+ test: TokenUsageComputer.zero(),
307
+ realize: TokenUsageComputer.zero(),
308
+ },
309
+ };
310
+ const histories: AutoBeHistory[] = await AutoBeExampleStorage.getHistories({
311
+ vendor: props.vendor,
312
+ project: props.project,
313
+ phase: previous,
314
+ });
315
+ const tokenUsage: IAutoBeTokenUsageJson =
316
+ await AutoBeExampleStorage.getTokenUsage({
317
+ vendor: props.vendor,
318
+ project: props.project,
319
+ phase: previous,
320
+ });
321
+ return {
322
+ histories,
323
+ tokenUsage,
324
+ };
325
+ };
326
+ }
327
+
328
+ const PHASES: AutoBePhase[] = [
329
+ "analyze",
330
+ "prisma",
331
+ "interface",
332
+ "test",
333
+ "realize",
334
+ ];
@@ -0,0 +1,143 @@
1
+ import {
2
+ AutoBeEvent,
3
+ AutoBeExampleProject,
4
+ AutoBePhase,
5
+ IAutoBeAgent,
6
+ } from "@autobe/interface";
7
+
8
+ import { IAutoBeExampleBenchmarkState } from "../structures/IAutoBeExampleBenchmarkState";
9
+ import { AutoBeExampleArchiver } from "./AutoBeExampleArchiver";
10
+
11
+ export namespace AutoBeExampleBenchmark {
12
+ export interface IContext {
13
+ createAgent: (
14
+ props: AutoBeExampleArchiver.IAgentProps,
15
+ ) => Promise<IAutoBeAgent>;
16
+ }
17
+
18
+ export const execute = async (
19
+ ctx: IContext,
20
+ props: {
21
+ vendors: string[];
22
+ projects?: AutoBeExampleProject[];
23
+ phases?: AutoBePhase[];
24
+ progress: (state: IAutoBeExampleBenchmarkState) => void;
25
+ on?: (event: AutoBeEvent) => void;
26
+ },
27
+ ): Promise<void> => {
28
+ const state: IAutoBeExampleBenchmarkState = {
29
+ vendors: props.vendors.map(
30
+ (vendor): IAutoBeExampleBenchmarkState.IOfVendor => ({
31
+ name: vendor,
32
+ projects: PROJECT_SEQUENCE.filter(
33
+ (p) => !props.projects || props.projects.includes(p),
34
+ ).map(
35
+ (project): IAutoBeExampleBenchmarkState.IOfProject => ({
36
+ name: project,
37
+ phases: [],
38
+ success: null,
39
+ started_at: new Date(),
40
+ completed_at: null,
41
+ }),
42
+ ),
43
+ }),
44
+ ),
45
+ };
46
+ const report = () => props.progress(state);
47
+ await Promise.all(
48
+ state.vendors.map((vendor) =>
49
+ executeVendor(ctx, {
50
+ phases: props.phases,
51
+ vendorState: vendor,
52
+ on: props.on,
53
+ report,
54
+ }),
55
+ ),
56
+ );
57
+ };
58
+
59
+ const executeVendor = async (
60
+ ctx: IContext,
61
+ props: {
62
+ vendorState: IAutoBeExampleBenchmarkState.IOfVendor;
63
+ phases?: AutoBePhase[];
64
+ report: () => void;
65
+ on?: (event: AutoBeEvent) => void;
66
+ },
67
+ ): Promise<void> => {
68
+ for (const project of props.vendorState.projects)
69
+ await executeProject(ctx, {
70
+ vendor: props.vendorState.name,
71
+ projectState: project,
72
+ phases: props.phases,
73
+ report: props.report,
74
+ on: props.on,
75
+ });
76
+ };
77
+
78
+ const executeProject = async (
79
+ ctx: IContext,
80
+ props: {
81
+ vendor: string;
82
+ projectState: IAutoBeExampleBenchmarkState.IOfProject;
83
+ phases?: AutoBePhase[];
84
+ report: () => void;
85
+ on?: (event: AutoBeEvent) => void;
86
+ },
87
+ ): Promise<void> => {
88
+ for (const phase of PHASE_SEQUENCE) {
89
+ if (props.phases && props.phases.includes(phase) === false) continue;
90
+ const phaseState: IAutoBeExampleBenchmarkState.IOfPhase = {
91
+ name: phase,
92
+ snapshot: null,
93
+ success: null,
94
+ started_at: new Date(),
95
+ completed_at: null,
96
+ };
97
+ props.projectState.phases.push(phaseState);
98
+ for (let i: number = 0; i < 3; ++i) {
99
+ try {
100
+ phaseState.started_at = new Date();
101
+ phaseState.completed_at = null;
102
+ const success: boolean = await getArchiver(phase)({
103
+ vendor: props.vendor,
104
+ project: props.projectState.name,
105
+ agent: (next) => ctx.createAgent(next),
106
+ on: (s) => {
107
+ phaseState.snapshot = s;
108
+ props.report();
109
+ if (props.on) props.on(s.event);
110
+ },
111
+ });
112
+ phaseState.success = success;
113
+ phaseState.completed_at = new Date();
114
+ props.report();
115
+ if (success === true) break;
116
+ } catch (error) {
117
+ continue;
118
+ }
119
+ }
120
+ if (phaseState.success === null) break;
121
+ else if (phaseState.success === false && phaseState.name !== "test")
122
+ break;
123
+ }
124
+ props.projectState.completed_at = new Date();
125
+ props.projectState.success = props.projectState.phases.every(
126
+ (phase) => phase.success === true,
127
+ );
128
+ props.report();
129
+ };
130
+ }
131
+
132
+ const getArchiver = (phase: AutoBePhase) => {
133
+ if (phase === "analyze") return AutoBeExampleArchiver.archiveAnalyze;
134
+ else if (phase === "prisma") return AutoBeExampleArchiver.archivePrisma;
135
+ else if (phase === "interface") return AutoBeExampleArchiver.archiveInterface;
136
+ else if (phase === "test") return AutoBeExampleArchiver.archiveTest;
137
+ else if (phase === "realize") return AutoBeExampleArchiver.archiveRealize;
138
+ phase satisfies never;
139
+ throw new Error(`Unknown phase: ${phase}`);
140
+ };
141
+
142
+ const PROJECT_SEQUENCE = ["todo", "bbs", "reddit", "shopping"] as const;
143
+ const PHASE_SEQUENCE = ["analyze", "interface", "test", "realize"] as const;