@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,189 +1,183 @@
1
- import {
2
- AutoBeExampleProject,
3
- AutoBeHistory,
4
- AutoBePhase,
5
- IAutoBePlaygroundBenchmarkScore,
6
- IAutoBePlaygroundReplay,
7
- } from "@autobe/interface";
8
- import { AutoBeProcessAggregateFactory } from "@autobe/utils";
9
-
10
- export namespace AutoBeReplayComputer {
11
- export const SIGNIFICANT_PROJECTS: AutoBeExampleProject[] = [
12
- "todo",
13
- "bbs",
14
- "reddit",
15
- "shopping",
16
- ];
17
-
18
- export const emoji = (
19
- summaries: IAutoBePlaygroundReplay.ISummary[],
20
- ): string => {
21
- const success: number = summaries.filter(
22
- (s) => s.realize !== null && s.realize.success === true,
23
- ).length;
24
- if (success >= 3) return "🟢";
25
-
26
- const tested: boolean = !!summaries.find((s) => s.test !== null);
27
- return tested ? "🟡" : "❌";
28
- };
29
-
30
- export const score = (
31
- summaries: IAutoBePlaygroundReplay.ISummary[],
32
- ): IAutoBePlaygroundBenchmarkScore => {
33
- // list up significant projects
34
- summaries = summaries.filter((s) =>
35
- ["todo", "bbs", "reddit", "shopping"].includes(s.project),
36
- );
37
-
38
- // the formula to compute the benchmark score
39
- const compute = (summary: IAutoBePlaygroundReplay.ISummary): number => {
40
- const add = (
41
- phase: IAutoBePlaygroundReplay.IPhaseState | null,
42
- success: number,
43
- failure?: number,
44
- ): number =>
45
- phase !== null
46
- ? phase.success === true
47
- ? success
48
- : (failure ?? success / 2)
49
- : 0;
50
- return (
51
- add(summary.analyze, 10) +
52
- add(summary.prisma, 20) +
53
- add(summary.interface, 30) +
54
- add(summary.test, 20) +
55
- add(summary.realize, 20)
56
- );
57
- };
58
- const individual = (project: AutoBeExampleProject): number => {
59
- const found = summaries.find((s) => s.project === project);
60
- if (found === undefined) return 0;
61
- return compute(found);
62
- };
63
- return {
64
- aggregate: summaries.map(compute).reduce((a, b) => a + b, 0) / 4,
65
- todo: individual("todo"),
66
- bbs: individual("bbs"),
67
- reddit: individual("reddit"),
68
- shopping: individual("shopping"),
69
- };
70
- };
71
-
72
- export const summarize = (
73
- replay: IAutoBePlaygroundReplay,
74
- ): IAutoBePlaygroundReplay.ISummary => {
75
- const predicate = <Type extends AutoBePhase>(
76
- type: Type,
77
- success: (history: AutoBeHistory.Mapper[Type]) => boolean,
78
- commodity: (
79
- history: AutoBeHistory.Mapper[Type],
80
- ) => Record<string, number>,
81
- ): IAutoBePlaygroundReplay.IPhaseState | null => {
82
- const reversed: AutoBeHistory[] = replay.histories.slice().reverse();
83
- const step: number | undefined = reversed.find(
84
- (h) => h.type === "analyze",
85
- )?.step;
86
- if (step === undefined) return null;
87
-
88
- const history: AutoBeHistory.Mapper[Type] | undefined = reversed.find(
89
- (h) => h.type === type && h.step === step,
90
- ) as AutoBeHistory.Mapper[Type] | undefined;
91
- if (history === undefined) return null;
92
- return {
93
- success: success(history),
94
- commodity: commodity(history),
95
- elapsed:
96
- new Date(history.completed_at).getTime() -
97
- new Date(history.created_at).getTime(),
98
- aggregates: history.aggregates,
99
- };
100
- };
101
- const phaseStates: Record<
102
- AutoBePhase,
103
- IAutoBePlaygroundReplay.IPhaseState | null
104
- > = {
105
- analyze: predicate(
106
- "analyze",
107
- () => true,
108
- (h) => ({
109
- actors: h.actors.length,
110
- documents: h.files.length,
111
- }),
112
- ),
113
- prisma: predicate(
114
- "prisma",
115
- (h) => h.compiled.type === "success",
116
- (h) => ({
117
- namespaces: h.result.data.files.length,
118
- models: h.result.data.files.map((f) => f.models).flat().length,
119
- }),
120
- ),
121
- interface: predicate(
122
- "interface",
123
- (h) => h.missed.length === 0,
124
- (h) => ({
125
- operations: h.document.operations.length,
126
- schemas: Object.keys(h.document.components.schemas).length,
127
- }),
128
- ),
129
- test: predicate(
130
- "test",
131
- (h) => h.compiled.type === "success",
132
- (h) => ({
133
- functions: h.files.length,
134
- ...(h.compiled.type === "failure"
135
- ? {
136
- errors: new Set(h.compiled.diagnostics.map((d) => d.file ?? ""))
137
- .size,
138
- }
139
- : {}),
140
- }),
141
- ),
142
- realize: predicate(
143
- "realize",
144
- (h) => h.compiled.type === "success",
145
- (h) => ({
146
- functions: h.functions.length,
147
- ...(h.compiled.type === "failure"
148
- ? {
149
- errors: new Set(h.compiled.diagnostics.map((d) => d.file ?? ""))
150
- .size,
151
- }
152
- : {}),
153
- }),
154
- ),
155
- };
156
- const phase: AutoBePhase | null =
157
- (["realize", "test", "interface", "prisma", "analyze"] as const).find(
158
- (key) => phaseStates[key] !== null,
159
- ) ?? null;
160
- return {
161
- vendor: replay.vendor,
162
- project: replay.project,
163
- aggregates: AutoBeProcessAggregateFactory.reduce(
164
- replay.histories
165
- .filter(
166
- (h) =>
167
- h.type === "analyze" ||
168
- h.type === "prisma" ||
169
- h.type === "interface" ||
170
- h.type === "test" ||
171
- h.type === "realize",
172
- )
173
- .map((h) => h.aggregates),
174
- ),
175
- elapsed: replay.histories
176
- .filter(
177
- (h) => h.type !== "userMessage" && h.type !== "assistantMessage",
178
- )
179
- .map(
180
- (h) =>
181
- new Date(h.completed_at).getTime() -
182
- new Date(h.created_at).getTime(),
183
- )
184
- .reduce((a, b) => a + b, 0),
185
- ...phaseStates,
186
- phase,
187
- };
188
- };
189
- }
1
+ import {
2
+ AutoBeExampleProject,
3
+ AutoBeHistory,
4
+ AutoBePhase,
5
+ IAutoBePlaygroundBenchmarkScore,
6
+ IAutoBePlaygroundReplay,
7
+ } from "@autobe/interface";
8
+ import { AutoBeProcessAggregateFactory } from "@autobe/utils";
9
+ import typia from "typia";
10
+
11
+ export namespace AutoBeReplayComputer {
12
+ export const SIGNIFICANT_PROJECTS: AutoBeExampleProject[] = [
13
+ "todo",
14
+ "bbs",
15
+ "reddit",
16
+ "shopping",
17
+ ];
18
+
19
+ export const emoji = (
20
+ summaries: IAutoBePlaygroundReplay.ISummary[],
21
+ ): string => {
22
+ const success: number = summaries.filter(
23
+ (s) => s.realize !== null && s.realize.success === true,
24
+ ).length;
25
+ if (success >= 3) return "🟢";
26
+
27
+ const tested: boolean = !!summaries.find((s) => s.test !== null);
28
+ return tested ? "🟡" : "❌";
29
+ };
30
+
31
+ export const score = (
32
+ summaries: IAutoBePlaygroundReplay.ISummary[],
33
+ ): IAutoBePlaygroundBenchmarkScore => {
34
+ // list up significant projects
35
+ summaries = summaries.filter((s) =>
36
+ ["todo", "bbs", "reddit", "shopping"].includes(s.project),
37
+ );
38
+
39
+ const individual = (project: AutoBeExampleProject): number => {
40
+ const found = summaries.find((s) => s.project === project);
41
+ if (found === undefined) return 0;
42
+ return compute(found);
43
+ };
44
+ return {
45
+ aggregate: round(summaries.map(compute).reduce((a, b) => a + b, 0) / 4),
46
+ todo: individual("todo"),
47
+ bbs: individual("bbs"),
48
+ reddit: individual("reddit"),
49
+ shopping: individual("shopping"),
50
+ };
51
+ };
52
+
53
+ export const summarize = (
54
+ replay: IAutoBePlaygroundReplay,
55
+ ): IAutoBePlaygroundReplay.ISummary => {
56
+ const predicate = <Type extends AutoBePhase>(
57
+ type: Type,
58
+ success: (history: AutoBeHistory.Mapper[Type]) => boolean,
59
+ commodity: (
60
+ history: AutoBeHistory.Mapper[Type],
61
+ ) => Record<string, number>,
62
+ ): IAutoBePlaygroundReplay.IPhaseState | null => {
63
+ const reversed: AutoBeHistory[] = replay.histories.slice().reverse();
64
+ const step: number | undefined = reversed.find(
65
+ (h) => h.type === "analyze",
66
+ )?.step;
67
+ if (step === undefined) return null;
68
+
69
+ const history: AutoBeHistory.Mapper[Type] | undefined = reversed.find(
70
+ (h) => h.type === type && h.step === step,
71
+ ) as AutoBeHistory.Mapper[Type] | undefined;
72
+ if (history === undefined) return null;
73
+ return {
74
+ success: success(history),
75
+ commodity: commodity(history),
76
+ elapsed:
77
+ new Date(history.completed_at).getTime() -
78
+ new Date(history.created_at).getTime(),
79
+ aggregates: history.aggregates,
80
+ };
81
+ };
82
+ const phaseStates: Record<
83
+ AutoBePhase,
84
+ IAutoBePlaygroundReplay.IPhaseState | null
85
+ > = {
86
+ analyze: predicate(
87
+ "analyze",
88
+ () => true,
89
+ (h) => ({
90
+ actors: h.actors.length,
91
+ documents: h.files.length,
92
+ }),
93
+ ),
94
+ database: predicate(
95
+ "database",
96
+ (h) => h.compiled.type === "success",
97
+ (h) => ({
98
+ namespaces: h.result.data.files.length,
99
+ models: h.result.data.files.map((f) => f.models).flat().length,
100
+ }),
101
+ ),
102
+ interface: predicate(
103
+ "interface",
104
+ (h) => h.missed.length === 0,
105
+ (h) => ({
106
+ operations: h.document.operations.length,
107
+ schemas: Object.keys(h.document.components.schemas).length,
108
+ }),
109
+ ),
110
+ test: predicate(
111
+ "test",
112
+ (h) => h.compiled.type === "success",
113
+ (h) => ({
114
+ functions: h.functions.length,
115
+ ...(h.compiled.type === "failure"
116
+ ? {
117
+ errors: new Set(h.compiled.diagnostics.map((d) => d.file ?? ""))
118
+ .size,
119
+ }
120
+ : {}),
121
+ }),
122
+ ),
123
+ realize: predicate(
124
+ "realize",
125
+ (h) => h.compiled.type === "success",
126
+ (h) => ({
127
+ functions: h.functions.length,
128
+ ...(h.compiled.type === "failure"
129
+ ? {
130
+ errors: new Set(h.compiled.diagnostics.map((d) => d.file ?? ""))
131
+ .size,
132
+ }
133
+ : {}),
134
+ }),
135
+ ),
136
+ };
137
+ const phase: AutoBePhase | null =
138
+ (["realize", "test", "interface", "database", "analyze"] as const).find(
139
+ (key) => phaseStates[key] !== null,
140
+ ) ?? null;
141
+ return {
142
+ vendor: replay.vendor,
143
+ project: replay.project,
144
+ ...phaseStates,
145
+ aggregates: AutoBeProcessAggregateFactory.reduce(
146
+ Object.values(phaseStates)
147
+ .filter((p) => p !== null)
148
+ .map((p) => p.aggregates),
149
+ ),
150
+ phase,
151
+ elapsed: Object.values(phaseStates)
152
+ .map((p) => p?.elapsed ?? 0)
153
+ .reduce((a, b) => a + (b ?? 0), 0),
154
+ };
155
+ };
156
+ }
157
+
158
+ const compute = (summary: IAutoBePlaygroundReplay.ISummary): number => {
159
+ const getScore = (phase: AutoBePhase): number => {
160
+ const state = summary[phase];
161
+ if (state === null) return 0;
162
+
163
+ const [success, failure] = FORMULA[phase];
164
+ return state.success === true
165
+ ? success
166
+ : success * failure(state.commodity);
167
+ };
168
+ return round(sum(typia.misc.literals<AutoBePhase>().map(getScore)));
169
+ };
170
+ const round = (value: number) => Math.round(value * 100) / 100;
171
+ const sum = (targets: number[]): number => targets.reduce((a, b) => a + b, 0);
172
+
173
+ // for type safety
174
+ const FORMULA: Record<
175
+ AutoBePhase,
176
+ [number, (commodity: Record<string, number>) => number]
177
+ > = {
178
+ analyze: [10, () => 0],
179
+ database: [20, () => 0.5],
180
+ interface: [30, () => 0.5],
181
+ test: [20, (c) => Math.max(0.5, 1 - (c.errors * 3) / c.functions)],
182
+ realize: [20, (c) => Math.max(0.5, 1 - (c.errors * 3) / c.functions)],
183
+ };