@autobe/benchmark 0.29.2 → 0.30.0-dev.20260315

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 (38) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +261 -0
  3. package/lib/example/AutoBeExampleArchiver.d.ts +2 -1
  4. package/lib/example/AutoBeExampleArchiver.js +41 -19
  5. package/lib/example/AutoBeExampleArchiver.js.map +1 -1
  6. package/lib/example/AutoBeExampleBenchmark.d.ts +5 -1
  7. package/lib/example/AutoBeExampleBenchmark.js +53 -42
  8. package/lib/example/AutoBeExampleBenchmark.js.map +1 -1
  9. package/lib/example/{AutoBeExampleDocumentation.d.ts → AutoBeExampleLogger.d.ts} +1 -1
  10. package/lib/example/{AutoBeExampleDocumentation.js → AutoBeExampleLogger.js} +39 -37
  11. package/lib/example/AutoBeExampleLogger.js.map +1 -0
  12. package/lib/example/AutoBeExampleStorage.d.ts +9 -2
  13. package/lib/example/AutoBeExampleStorage.js +74 -24
  14. package/lib/example/AutoBeExampleStorage.js.map +1 -1
  15. package/lib/example/index.d.ts +1 -1
  16. package/lib/example/index.js +1 -1
  17. package/lib/example/index.js.map +1 -1
  18. package/lib/replay/AutoBeReplayComputer.js +35 -28
  19. package/lib/replay/AutoBeReplayComputer.js.map +1 -1
  20. package/lib/replay/AutoBeReplayDocumentation.js +44 -42
  21. package/lib/replay/AutoBeReplayDocumentation.js.map +1 -1
  22. package/lib/replay/AutoBeReplayStorage.js +10 -3
  23. package/lib/replay/AutoBeReplayStorage.js.map +1 -1
  24. package/lib/structures/IAutoBeExampleBenchmarkState.d.ts +1 -1
  25. package/package.json +5 -6
  26. package/src/example/AutoBeExampleArchiver.ts +381 -337
  27. package/src/example/AutoBeExampleBenchmark.ts +190 -159
  28. package/src/example/{AutoBeExampleDocumentation.ts → AutoBeExampleLogger.ts} +85 -84
  29. package/src/example/AutoBeExampleStorage.ts +289 -218
  30. package/src/example/index.ts +4 -4
  31. package/src/index.ts +2 -2
  32. package/src/replay/AutoBeReplayComputer.ts +183 -189
  33. package/src/replay/AutoBeReplayDocumentation.ts +176 -174
  34. package/src/replay/AutoBeReplayStorage.ts +116 -109
  35. package/src/replay/index.ts +3 -3
  36. package/src/structures/IAutoBeExampleBenchmarkState.ts +30 -30
  37. package/src/structures/index.ts +1 -1
  38. package/lib/example/AutoBeExampleDocumentation.js.map +0 -1
@@ -1,159 +1,190 @@
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: null,
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
- props.projectState.started_at = new Date();
89
- for (const phase of PHASE_SEQUENCE) {
90
- if (props.phases && props.phases.includes(phase) === false) continue;
91
- const phaseState: IAutoBeExampleBenchmarkState.IOfPhase = {
92
- name: phase,
93
- snapshot: null,
94
- success: null,
95
- started_at: new Date(),
96
- completed_at: null,
97
- trial: 0,
98
- };
99
- props.projectState.phases.push(phaseState);
100
- for (let i: number = 0; i < 3; ++i) {
101
- try {
102
- ++phaseState.trial;
103
- phaseState.started_at = new Date();
104
- phaseState.completed_at = null;
105
- const success: boolean = await getArchiver(phase)({
106
- vendor: props.vendor,
107
- project: props.projectState.name,
108
- agent: (next) => ctx.createAgent(next),
109
- on: (s) => {
110
- const event = s.event;
111
- if (
112
- event.type !== "jsonValidateError" &&
113
- event.type !== "jsonParseError" &&
114
- event.type !== "preliminary" &&
115
- event.type !== "consentFunctionCall"
116
- )
117
- phaseState.snapshot = s;
118
- props.report();
119
- if (props.on) props.on(s.event);
120
- },
121
- });
122
- phaseState.success = success;
123
- phaseState.completed_at = new Date();
124
- props.report();
125
- if (success === true) break;
126
- } catch (error) {
127
- continue;
128
- }
129
- }
130
- if (phaseState.success === null) break;
131
- else if (phaseState.success === false && phaseState.name !== "test")
132
- break;
133
- }
134
- props.projectState.completed_at = new Date();
135
- props.projectState.success = props.projectState.phases.every(
136
- (phase) => phase.success === true,
137
- );
138
- props.report();
139
- };
140
- }
141
-
142
- const getArchiver = (phase: AutoBePhase) => {
143
- if (phase === "analyze") return AutoBeExampleArchiver.archiveAnalyze;
144
- else if (phase === "prisma") return AutoBeExampleArchiver.archivePrisma;
145
- else if (phase === "interface") return AutoBeExampleArchiver.archiveInterface;
146
- else if (phase === "test") return AutoBeExampleArchiver.archiveTest;
147
- else if (phase === "realize") return AutoBeExampleArchiver.archiveRealize;
148
- phase satisfies never;
149
- throw new Error(`Unknown phase: ${phase}`);
150
- };
151
-
152
- const PROJECT_SEQUENCE = ["todo", "bbs", "reddit", "shopping"] as const;
153
- const PHASE_SEQUENCE = [
154
- "analyze",
155
- "prisma",
156
- "interface",
157
- "test",
158
- "realize",
159
- ] as const;
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
+ imagePath?: string;
25
+ progress: (state: IAutoBeExampleBenchmarkState) => void;
26
+ on?: (
27
+ event: AutoBeEvent,
28
+ agent: IAutoBeAgent,
29
+ context: { vendor: string; project: AutoBeExampleProject },
30
+ ) => void;
31
+ },
32
+ ): Promise<void> => {
33
+ const state: IAutoBeExampleBenchmarkState = {
34
+ vendors: props.vendors.map(
35
+ (vendor): IAutoBeExampleBenchmarkState.IOfVendor => ({
36
+ name: vendor,
37
+ projects: PROJECT_SEQUENCE.filter(
38
+ (p) => !props.projects || props.projects.includes(p),
39
+ ).map(
40
+ (project): IAutoBeExampleBenchmarkState.IOfProject => ({
41
+ name: project,
42
+ phases: [],
43
+ success: null,
44
+ started_at: null,
45
+ completed_at: null,
46
+ }),
47
+ ),
48
+ }),
49
+ ),
50
+ };
51
+ const report = () => props.progress(state);
52
+ await Promise.all(
53
+ state.vendors.map(async (vendor) => {
54
+ await executeVendor(ctx, {
55
+ imagePath: props.imagePath,
56
+ phases: props.phases,
57
+ vendorState: vendor,
58
+ on: props.on,
59
+ report,
60
+ });
61
+ }),
62
+ );
63
+ };
64
+
65
+ const executeVendor = async (
66
+ ctx: IContext,
67
+ props: {
68
+ imagePath?: string;
69
+ vendorState: IAutoBeExampleBenchmarkState.IOfVendor;
70
+ phases?: AutoBePhase[];
71
+ report: () => void;
72
+ on?: (
73
+ event: AutoBeEvent,
74
+ agent: IAutoBeAgent,
75
+ context: { vendor: string; project: AutoBeExampleProject },
76
+ ) => void;
77
+ },
78
+ ): Promise<void> => {
79
+ for (const project of props.vendorState.projects)
80
+ await executeProject(ctx, {
81
+ imagePath: props.imagePath,
82
+ vendor: props.vendorState.name,
83
+ projectState: project,
84
+ phases: props.phases,
85
+ report: props.report,
86
+ on: props.on,
87
+ });
88
+ };
89
+
90
+ const executeProject = async (
91
+ ctx: IContext,
92
+ props: {
93
+ vendor: string;
94
+ projectState: IAutoBeExampleBenchmarkState.IOfProject;
95
+ imagePath?: string;
96
+ phases?: AutoBePhase[];
97
+ report: () => void;
98
+ on?: (
99
+ event: AutoBeEvent,
100
+ agent: IAutoBeAgent,
101
+ context: { vendor: string; project: AutoBeExampleProject },
102
+ ) => void;
103
+ },
104
+ ): Promise<void> => {
105
+ props.projectState.started_at = new Date();
106
+ for (const phase of PHASE_SEQUENCE) {
107
+ if (props.phases && props.phases.includes(phase) === false) continue;
108
+ const phaseState: IAutoBeExampleBenchmarkState.IOfPhase = {
109
+ name: phase,
110
+ snapshot: null,
111
+ success: null,
112
+ started_at: new Date(),
113
+ completed_at: null,
114
+ count: 0,
115
+ };
116
+ props.projectState.phases.push(phaseState);
117
+ try {
118
+ phaseState.started_at = new Date();
119
+ phaseState.completed_at = null;
120
+ phaseState.count = 0;
121
+ const success: boolean = await getArchiver(phase)({
122
+ vendor: props.vendor,
123
+ project: props.projectState.name,
124
+ imagePath: props.imagePath,
125
+ agent: (next) => ctx.createAgent(next),
126
+ on: (s, agent) => {
127
+ ++phaseState.count;
128
+ const event = s.event;
129
+ if (
130
+ event.type !== "jsonValidateError" &&
131
+ event.type !== "jsonParseError" &&
132
+ event.type !== "preliminary" &&
133
+ event.type !== "consentFunctionCall"
134
+ )
135
+ phaseState.snapshot = s;
136
+ props.report();
137
+ if (props.on)
138
+ props.on(s.event, agent, {
139
+ vendor: props.vendor,
140
+ project: props.projectState.name,
141
+ });
142
+ },
143
+ });
144
+ phaseState.success = success;
145
+ phaseState.completed_at = new Date();
146
+ props.report();
147
+ } catch (error) {
148
+ console.log(
149
+ props.vendor,
150
+ props.projectState.name,
151
+ phaseState.name,
152
+ error,
153
+ );
154
+ throw error;
155
+ }
156
+ if (phaseState.success === null || phaseState.success === false) break;
157
+ }
158
+ props.projectState.completed_at = new Date();
159
+ props.projectState.success = props.projectState.phases.every(
160
+ (phase) => phase.success === true,
161
+ );
162
+ props.report();
163
+ };
164
+ }
165
+
166
+ const getArchiver = (phase: AutoBePhase) => {
167
+ if (phase === "analyze") return AutoBeExampleArchiver.archiveAnalyze;
168
+ else if (phase === "database") return AutoBeExampleArchiver.archivePrisma;
169
+ else if (phase === "interface") return AutoBeExampleArchiver.archiveInterface;
170
+ else if (phase === "test") return AutoBeExampleArchiver.archiveTest;
171
+ else if (phase === "realize") return AutoBeExampleArchiver.archiveRealize;
172
+ phase satisfies never;
173
+ throw new Error(`Unknown phase: ${phase}`);
174
+ };
175
+
176
+ const PROJECT_SEQUENCE = [
177
+ "todo",
178
+ "bbs",
179
+ "reddit",
180
+ "shopping",
181
+ "account",
182
+ "erp",
183
+ ] as const;
184
+ const PHASE_SEQUENCE = [
185
+ "analyze",
186
+ "database",
187
+ "interface",
188
+ "test",
189
+ "realize",
190
+ ] as const;
@@ -1,84 +1,85 @@
1
- import { AutoBeProgressEventBase } from "@autobe/interface";
2
- import { StringUtil } from "@autobe/utils";
3
- import typia from "typia";
4
-
5
- import { IAutoBeExampleBenchmarkState } from "../structures";
6
-
7
- export namespace AutoBeExampleDocumentation {
8
- export const markdown = (state: IAutoBeExampleBenchmarkState): string =>
9
- StringUtil.trim`
10
- # AutoBe Example Benchmark Report
11
-
12
- ${markdownIndex(state)}
13
-
14
- ${state.vendors.map(markdownVendor).join("\n\n")}
15
- `;
16
-
17
- const markdownIndex = (
18
- state: IAutoBeExampleBenchmarkState,
19
- ): string => StringUtil.trim`
20
- ## Table of Contents
21
-
22
- ${state.vendors
23
- .map(
24
- (vendor) =>
25
- `- [\`${vendor.name}\`](#${vendor.name
26
- .replaceAll("/", "")
27
- .replaceAll(":", "")})`,
28
- )
29
- .join("\n")}
30
- `;
31
-
32
- const markdownVendor = (
33
- state: IAutoBeExampleBenchmarkState.IOfVendor,
34
- ): string => StringUtil.trim`
35
- ## \`${state.name}\`
36
-
37
- Project | Phase | State | Elapsed Time
38
- :-------|:------|:------|-------------:
39
- ${state.projects.map(markdownProject).join("\n")}
40
- `;
41
-
42
- const markdownProject = (
43
- state: IAutoBeExampleBenchmarkState.IOfProject,
44
- ): string => {
45
- // yellow circle emoji:
46
- const phase: IAutoBeExampleBenchmarkState.IOfPhase | undefined =
47
- state.phases.at(-1);
48
- return [
49
- state.name,
50
- !!phase?.name ? `${phase.name} (${phase.trial})` : "-",
51
- state.completed_at !== null
52
- ? state.success
53
- ? "🟢 success"
54
- : "🔴 failure"
55
- : phase !== undefined && phase.snapshot !== null
56
- ? [
57
- phase.trial !== 1 ? "🟠" : "🟡",
58
- `\`${phase.snapshot.event.type}\``,
59
- ...(typia.is<AutoBeProgressEventBase>(phase.snapshot.event)
60
- ? [
61
- `(${phase.snapshot.event.completed} of ${phase.snapshot.event.total})`,
62
- ]
63
- : []),
64
- ].join(" ")
65
- : "-",
66
- state.started_at !== null
67
- ? elapsedTime({
68
- started_at: state.started_at,
69
- completed_at: state.completed_at,
70
- })
71
- : "-",
72
- ].join(" | ");
73
- };
74
- }
75
-
76
- const elapsedTime = (props: {
77
- started_at: Date;
78
- completed_at: Date | null;
79
- }): string =>
80
- Math.round(
81
- ((props.completed_at ?? new Date()).getTime() -
82
- props.started_at.getTime()) /
83
- 1_000,
84
- ).toLocaleString() + " sec";
1
+ import { AutoBeProgressEventBase } from "@autobe/interface";
2
+ import { StringUtil } from "@autobe/utils";
3
+ import typia from "typia";
4
+
5
+ import { IAutoBeExampleBenchmarkState } from "../structures";
6
+
7
+ export namespace AutoBeExampleLogger {
8
+ export const markdown = (state: IAutoBeExampleBenchmarkState): string =>
9
+ StringUtil.trim`
10
+ # AutoBe Example Benchmark Report
11
+
12
+ ${markdownIndex(state)}
13
+
14
+ ${state.vendors.map(markdownVendor).join("\n\n")}
15
+ `;
16
+
17
+ const markdownIndex = (
18
+ state: IAutoBeExampleBenchmarkState,
19
+ ): string => StringUtil.trim`
20
+ ## Table of Contents
21
+
22
+ ${state.vendors
23
+ .map(
24
+ (vendor) =>
25
+ `- [\`${vendor.name}\`](#${vendor.name
26
+ .replaceAll("/", "")
27
+ .replaceAll(":", "")})`,
28
+ )
29
+ .join("\n")}
30
+ `;
31
+
32
+ const markdownVendor = (
33
+ state: IAutoBeExampleBenchmarkState.IOfVendor,
34
+ ): string => StringUtil.trim`
35
+ ## \`${state.name}\`
36
+
37
+ Project | Phase | State | Count | Elapsed Time
38
+ :-------|:------|:------|------:|-------------:
39
+ ${state.projects.map(markdownProject).join("\n")}
40
+ `;
41
+
42
+ const markdownProject = (
43
+ state: IAutoBeExampleBenchmarkState.IOfProject,
44
+ ): string => {
45
+ // yellow circle emoji:
46
+ const phase: IAutoBeExampleBenchmarkState.IOfPhase | undefined =
47
+ state.phases.at(-1);
48
+ return [
49
+ state.name,
50
+ phase?.name ?? "-",
51
+ phase !== undefined && phase.snapshot !== null
52
+ ? [
53
+ state.completed_at !== null
54
+ ? state.success
55
+ ? "🟢 success"
56
+ : "🔴 failure"
57
+ : "🟡",
58
+ `\`${phase.snapshot.event.type}\``,
59
+ ...(typia.is<AutoBeProgressEventBase>(phase.snapshot.event)
60
+ ? [
61
+ `(${phase.snapshot.event.completed} of ${phase.snapshot.event.total})`,
62
+ ]
63
+ : []),
64
+ ].join(" ")
65
+ : "-",
66
+ phase?.count.toLocaleString() ?? "0",
67
+ state.started_at !== null
68
+ ? elapsedTime({
69
+ started_at: state.started_at,
70
+ completed_at: state.completed_at,
71
+ })
72
+ : "-",
73
+ ].join(" | ");
74
+ };
75
+ }
76
+
77
+ const elapsedTime = (props: {
78
+ started_at: Date;
79
+ completed_at: Date | null;
80
+ }): string =>
81
+ Math.round(
82
+ ((props.completed_at ?? new Date()).getTime() -
83
+ props.started_at.getTime()) /
84
+ 1_000,
85
+ ).toLocaleString() + " sec";