@autobe/agent 0.26.0 → 0.27.0

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 (189) hide show
  1. package/lib/AutoBeAgent.d.ts +2 -1
  2. package/lib/AutoBeAgent.js +27 -7
  3. package/lib/AutoBeAgent.js.map +1 -1
  4. package/lib/AutoBeMockAgent.js +2 -4
  5. package/lib/AutoBeMockAgent.js.map +1 -1
  6. package/lib/constants/AutoBeSystemPromptConstant.d.ts +10 -10
  7. package/lib/context/AutoBeContext.d.ts +4 -1
  8. package/lib/context/AutoBeTokenUsage.d.ts +1 -1
  9. package/lib/context/AutoBeTokenUsage.js.map +1 -1
  10. package/lib/factory/AutoBeFunctionCallingMetricFactory.d.ts +7 -0
  11. package/lib/factory/AutoBeFunctionCallingMetricFactory.js +35 -0
  12. package/lib/factory/AutoBeFunctionCallingMetricFactory.js.map +1 -0
  13. package/lib/factory/AutoBeProcessAggregateFactory.d.ts +13 -0
  14. package/lib/factory/AutoBeProcessAggregateFactory.js +100 -0
  15. package/lib/factory/AutoBeProcessAggregateFactory.js.map +1 -0
  16. package/lib/factory/createAutoBeContext.d.ts +2 -1
  17. package/lib/factory/createAutoBeContext.js +78 -27
  18. package/lib/factory/createAutoBeContext.js.map +1 -1
  19. package/lib/index.mjs +1891 -1214
  20. package/lib/index.mjs.map +1 -1
  21. package/lib/orchestrate/analyze/orchestrateAnalyze.js +1 -0
  22. package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
  23. package/lib/orchestrate/analyze/orchestrateAnalyzeReview.js +2 -1
  24. package/lib/orchestrate/analyze/orchestrateAnalyzeReview.js.map +1 -1
  25. package/lib/orchestrate/analyze/orchestrateAnalyzeScenario.js +2 -1
  26. package/lib/orchestrate/analyze/orchestrateAnalyzeScenario.js.map +1 -1
  27. package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js +3 -2
  28. package/lib/orchestrate/analyze/orchestrateAnalyzeWrite.js.map +1 -1
  29. package/lib/orchestrate/common/orchestrateCommonCorrectCasting.d.ts +2 -1
  30. package/lib/orchestrate/common/orchestrateCommonCorrectCasting.js +3 -2
  31. package/lib/orchestrate/common/orchestrateCommonCorrectCasting.js.map +1 -1
  32. package/lib/{factory/createAutoBeApplication.d.ts → orchestrate/facade/createAutoBeFacadeController.d.ts} +2 -2
  33. package/lib/{factory/createAutoBeApplication.js → orchestrate/facade/createAutoBeFacadeController.js} +53 -57
  34. package/lib/orchestrate/facade/createAutoBeFacadeController.js.map +1 -0
  35. package/lib/orchestrate/facade/histories/IAutoBeFacadeApplication.js.map +1 -0
  36. package/lib/orchestrate/facade/histories/IAutoBeFacadeApplicationProps.js.map +1 -0
  37. package/lib/orchestrate/facade/histories/IAutoBeFacadeApplicationResult.js.map +1 -0
  38. package/lib/orchestrate/facade/{transformFacadeStateMessage.d.ts → structures/transformFacadeStateMessage.d.ts} +1 -1
  39. package/lib/orchestrate/facade/structures/transformFacadeStateMessage.js.map +1 -0
  40. package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js +2 -2
  41. package/lib/orchestrate/interface/histories/transformInterfaceComplementHistories.js.map +1 -1
  42. package/lib/orchestrate/interface/histories/transformInterfaceEndpointHistories.js +1 -1
  43. package/lib/orchestrate/interface/histories/transformInterfaceEndpointHistories.js.map +1 -1
  44. package/lib/orchestrate/interface/histories/transformInterfaceEndpointsReviewHistories.js +3 -2
  45. package/lib/orchestrate/interface/histories/transformInterfaceEndpointsReviewHistories.js.map +1 -1
  46. package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js +1 -1
  47. package/lib/orchestrate/interface/histories/transformInterfaceGroupHistories.js.map +1 -1
  48. package/lib/orchestrate/interface/histories/transformInterfaceOperationHistories.js +1 -1
  49. package/lib/orchestrate/interface/histories/transformInterfaceOperationHistories.js.map +1 -1
  50. package/lib/orchestrate/interface/histories/transformInterfaceOperationsReviewHistories.js +2 -2
  51. package/lib/orchestrate/interface/histories/transformInterfaceOperationsReviewHistories.js.map +1 -1
  52. package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js +1 -1
  53. package/lib/orchestrate/interface/histories/transformInterfaceSchemaHistories.js.map +1 -1
  54. package/lib/orchestrate/interface/orchestrateInterface.d.ts +1 -1
  55. package/lib/orchestrate/interface/orchestrateInterface.js +15 -8
  56. package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
  57. package/lib/orchestrate/interface/orchestrateInterfaceAuthorizations.js +136 -48
  58. package/lib/orchestrate/interface/orchestrateInterfaceAuthorizations.js.map +1 -1
  59. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +234 -59
  60. package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
  61. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +3 -2
  62. package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
  63. package/lib/orchestrate/interface/orchestrateInterfaceEndpointsReview.d.ts +0 -6
  64. package/lib/orchestrate/interface/orchestrateInterfaceEndpointsReview.js +2 -2
  65. package/lib/orchestrate/interface/orchestrateInterfaceEndpointsReview.js.map +1 -1
  66. package/lib/orchestrate/interface/orchestrateInterfaceGroups.js +2 -1
  67. package/lib/orchestrate/interface/orchestrateInterfaceGroups.js.map +1 -1
  68. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +137 -49
  69. package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
  70. package/lib/orchestrate/interface/orchestrateInterfaceOperationsReview.js +136 -48
  71. package/lib/orchestrate/interface/orchestrateInterfaceOperationsReview.js.map +1 -1
  72. package/lib/orchestrate/interface/orchestrateInterfacePrerequisites.js +2 -1
  73. package/lib/orchestrate/interface/orchestrateInterfacePrerequisites.js.map +1 -1
  74. package/lib/orchestrate/interface/orchestrateInterfaceSchemaRename.js +2 -1
  75. package/lib/orchestrate/interface/orchestrateInterfaceSchemaRename.js.map +1 -1
  76. package/lib/orchestrate/interface/orchestrateInterfaceSchemaReview.d.ts +5 -3
  77. package/lib/orchestrate/interface/orchestrateInterfaceSchemaReview.js +241 -69
  78. package/lib/orchestrate/interface/orchestrateInterfaceSchemaReview.js.map +1 -1
  79. package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js +234 -59
  80. package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js.map +1 -1
  81. package/lib/orchestrate/interface/utils/JsonSchemaFactory.js +23 -23
  82. package/lib/orchestrate/prisma/orchestratePrisma.d.ts +1 -1
  83. package/lib/orchestrate/prisma/orchestratePrisma.js +1 -0
  84. package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -1
  85. package/lib/orchestrate/prisma/orchestratePrismaComponent.js +2 -1
  86. package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -1
  87. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +2 -1
  88. package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
  89. package/lib/orchestrate/prisma/orchestratePrismaReview.js +2 -1
  90. package/lib/orchestrate/prisma/orchestratePrismaReview.js.map +1 -1
  91. package/lib/orchestrate/prisma/orchestratePrismaSchemas.js +2 -1
  92. package/lib/orchestrate/prisma/orchestratePrismaSchemas.js.map +1 -1
  93. package/lib/orchestrate/realize/histories/transformRealizeWriteAuthorizationsHistories.js +2 -2
  94. package/lib/orchestrate/realize/histories/transformRealizeWriteAuthorizationsHistories.js.map +1 -1
  95. package/lib/orchestrate/realize/orchestrateRealize.d.ts +1 -1
  96. package/lib/orchestrate/realize/orchestrateRealize.js +2 -1
  97. package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
  98. package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js +2 -1
  99. package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js.map +1 -1
  100. package/lib/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.js +3 -2
  101. package/lib/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.js.map +1 -1
  102. package/lib/orchestrate/realize/orchestrateRealizeCorrect.js +3 -2
  103. package/lib/orchestrate/realize/orchestrateRealizeCorrect.js.map +1 -1
  104. package/lib/orchestrate/realize/orchestrateRealizeCorrectCasting.js +6 -5
  105. package/lib/orchestrate/realize/orchestrateRealizeCorrectCasting.js.map +1 -1
  106. package/lib/orchestrate/realize/orchestrateRealizeWrite.js +2 -1
  107. package/lib/orchestrate/realize/orchestrateRealizeWrite.js.map +1 -1
  108. package/lib/orchestrate/realize/utils/replaceImportStatements.js +0 -85
  109. package/lib/orchestrate/realize/utils/replaceImportStatements.js.map +1 -1
  110. package/lib/orchestrate/test/orchestrateTest.d.ts +1 -1
  111. package/lib/orchestrate/test/orchestrateTest.js +2 -1
  112. package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
  113. package/lib/orchestrate/test/orchestrateTestCorrect.js +3 -1
  114. package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
  115. package/lib/orchestrate/test/orchestrateTestCorrectInvalidRequest.js +3 -2
  116. package/lib/orchestrate/test/orchestrateTestCorrectInvalidRequest.js.map +1 -1
  117. package/lib/orchestrate/test/orchestrateTestScenario.js +2 -1
  118. package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
  119. package/lib/orchestrate/test/orchestrateTestScenarioReview.js +2 -1
  120. package/lib/orchestrate/test/orchestrateTestScenarioReview.js.map +1 -1
  121. package/lib/orchestrate/test/orchestrateTestWrite.js +2 -1
  122. package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -1
  123. package/lib/utils/TokenUsageComputer.d.ts +5 -0
  124. package/lib/utils/TokenUsageComputer.js +29 -0
  125. package/lib/utils/TokenUsageComputer.js.map +1 -0
  126. package/package.json +7 -7
  127. package/src/AutoBeAgent.ts +40 -6
  128. package/src/AutoBeMockAgent.ts +2 -4
  129. package/src/constants/AutoBeSystemPromptConstant.ts +10 -10
  130. package/src/context/AutoBeContext.ts +8 -0
  131. package/src/context/AutoBeTokenUsage.ts +1 -1
  132. package/src/factory/AutoBeFunctionCallingMetricFactory.ts +44 -0
  133. package/src/factory/AutoBeProcessAggregateFactory.ts +141 -0
  134. package/src/factory/createAutoBeContext.ts +96 -36
  135. package/src/orchestrate/analyze/orchestrateAnalyze.ts +1 -0
  136. package/src/orchestrate/analyze/orchestrateAnalyzeReview.ts +2 -1
  137. package/src/orchestrate/analyze/orchestrateAnalyzeScenario.ts +2 -1
  138. package/src/orchestrate/analyze/orchestrateAnalyzeWrite.ts +3 -2
  139. package/src/orchestrate/common/orchestrateCommonCorrectCasting.ts +5 -2
  140. package/src/orchestrate/facade/createAutoBeFacadeController.ts +135 -0
  141. package/src/orchestrate/facade/{transformFacadeStateMessage.ts → structures/transformFacadeStateMessage.ts} +2 -2
  142. package/src/orchestrate/interface/histories/transformInterfaceEndpointsReviewHistories.ts +1 -0
  143. package/src/orchestrate/interface/orchestrateInterface.ts +17 -6
  144. package/src/orchestrate/interface/orchestrateInterfaceAuthorizations.ts +2 -1
  145. package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +2 -1
  146. package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +3 -2
  147. package/src/orchestrate/interface/orchestrateInterfaceEndpointsReview.ts +3 -4
  148. package/src/orchestrate/interface/orchestrateInterfaceGroups.ts +2 -1
  149. package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +2 -1
  150. package/src/orchestrate/interface/orchestrateInterfaceOperationsReview.ts +2 -1
  151. package/src/orchestrate/interface/orchestrateInterfacePrerequisites.ts +2 -1
  152. package/src/orchestrate/interface/orchestrateInterfaceSchemaRename.ts +2 -1
  153. package/src/orchestrate/interface/orchestrateInterfaceSchemaReview.ts +10 -15
  154. package/src/orchestrate/interface/orchestrateInterfaceSchemas.ts +2 -1
  155. package/src/orchestrate/prisma/orchestratePrisma.ts +2 -1
  156. package/src/orchestrate/prisma/orchestratePrismaComponent.ts +2 -1
  157. package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +2 -1
  158. package/src/orchestrate/prisma/orchestratePrismaReview.ts +2 -1
  159. package/src/orchestrate/prisma/orchestratePrismaSchemas.ts +2 -1
  160. package/src/orchestrate/realize/orchestrateRealize.ts +3 -2
  161. package/src/orchestrate/realize/orchestrateRealizeAuthorization.ts +2 -1
  162. package/src/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.ts +2 -1
  163. package/src/orchestrate/realize/orchestrateRealizeCorrect.ts +3 -2
  164. package/src/orchestrate/realize/orchestrateRealizeCorrectCasting.ts +6 -5
  165. package/src/orchestrate/realize/orchestrateRealizeWrite.ts +2 -1
  166. package/src/orchestrate/realize/utils/replaceImportStatements.ts +0 -90
  167. package/src/orchestrate/test/orchestrateTest.ts +3 -2
  168. package/src/orchestrate/test/orchestrateTestCorrect.ts +3 -1
  169. package/src/orchestrate/test/orchestrateTestCorrectInvalidRequest.ts +3 -2
  170. package/src/orchestrate/test/orchestrateTestScenario.ts +2 -1
  171. package/src/orchestrate/test/orchestrateTestScenarioReview.ts +2 -1
  172. package/src/orchestrate/test/orchestrateTestWrite.ts +2 -1
  173. package/src/utils/TokenUsageComputer.ts +35 -0
  174. package/lib/context/IAutoBeFacadeApplication.js.map +0 -1
  175. package/lib/context/IAutoBeFacadeApplicationProps.js.map +0 -1
  176. package/lib/context/IAutoBeFacadeApplicationResult.js.map +0 -1
  177. package/lib/factory/createAutoBeApplication.js.map +0 -1
  178. package/lib/orchestrate/facade/transformFacadeStateMessage.js.map +0 -1
  179. package/src/factory/createAutoBeApplication.ts +0 -123
  180. /package/lib/{context → orchestrate/facade/histories}/IAutoBeFacadeApplication.d.ts +0 -0
  181. /package/lib/{context → orchestrate/facade/histories}/IAutoBeFacadeApplication.js +0 -0
  182. /package/lib/{context → orchestrate/facade/histories}/IAutoBeFacadeApplicationProps.d.ts +0 -0
  183. /package/lib/{context → orchestrate/facade/histories}/IAutoBeFacadeApplicationProps.js +0 -0
  184. /package/lib/{context → orchestrate/facade/histories}/IAutoBeFacadeApplicationResult.d.ts +0 -0
  185. /package/lib/{context → orchestrate/facade/histories}/IAutoBeFacadeApplicationResult.js +0 -0
  186. /package/lib/orchestrate/facade/{transformFacadeStateMessage.js → structures/transformFacadeStateMessage.js} +0 -0
  187. /package/src/{context → orchestrate/facade/histories}/IAutoBeFacadeApplication.ts +0 -0
  188. /package/src/{context → orchestrate/facade/histories}/IAutoBeFacadeApplicationProps.ts +0 -0
  189. /package/src/{context → orchestrate/facade/histories}/IAutoBeFacadeApplicationResult.ts +0 -0
@@ -10,9 +10,12 @@ import {
10
10
  AutoBeAssistantMessageHistory,
11
11
  AutoBeEvent,
12
12
  AutoBeEventSource,
13
+ AutoBeFunctionCallingMetric,
13
14
  AutoBeHistory,
14
15
  AutoBeInterfaceHistory,
16
+ AutoBePhase,
15
17
  AutoBePrismaHistory,
18
+ AutoBeProcessAggregateCollection,
16
19
  AutoBeRealizeHistory,
17
20
  AutoBeTestHistory,
18
21
  IAutoBeCompiler,
@@ -33,12 +36,16 @@ export interface AutoBeContext<Model extends ILlmSchema.Model> {
33
36
  retry: number;
34
37
 
35
38
  // accessors
39
+ aggregates: AutoBeProcessAggregateCollection;
36
40
  compilerListener: IAutoBeCompilerListener;
37
41
  compiler: () => Promise<IAutoBeCompiler>;
38
42
  files: (options: IAutoBeGetFilesOptions) => Promise<Record<string, string>>;
39
43
  histories: () => Readonly<AutoBeHistory[]>;
40
44
  state: () => Readonly<AutoBeState>;
41
45
  usage: () => AutoBeTokenUsage;
46
+ getCurrentAggregates: (
47
+ phase: AutoBePhase,
48
+ ) => AutoBeProcessAggregateCollection;
42
49
 
43
50
  // events
44
51
  dispatch: <Event extends Exclude<AutoBeEvent, AutoBeAssistantMessageEvent>>(
@@ -79,5 +86,6 @@ export namespace AutoBeContext {
79
86
  export interface IResult<Model extends ILlmSchema.Model> {
80
87
  histories: MicroAgenticaHistory<Model>[];
81
88
  tokenUsage: IAutoBeTokenUsageJson.IComponent;
89
+ metric: AutoBeFunctionCallingMetric;
82
90
  }
83
91
  }
@@ -1,7 +1,7 @@
1
1
  import { IAutoBeTokenUsageJson } from "@autobe/interface";
2
2
 
3
+ import { IAutoBeFacadeApplication } from "../orchestrate/facade/histories/IAutoBeFacadeApplication";
3
4
  import { AutoBeTokenUsageComponent } from "./AutoBeTokenUsageComponent";
4
- import { IAutoBeFacadeApplication } from "./IAutoBeFacadeApplication";
5
5
 
6
6
  /**
7
7
  * Comprehensive token usage tracker for the AutoBe vibe coding system.
@@ -0,0 +1,44 @@
1
+ import { AutoBeFunctionCallingMetric } from "@autobe/interface";
2
+
3
+ export namespace AutoBeFunctionCallingMetricFactory {
4
+ export const create = (): AutoBeFunctionCallingMetric => ({
5
+ attempt: 0,
6
+ success: 0,
7
+ consent: 0,
8
+ validationFailure: 0,
9
+ invalidJson: 0,
10
+ });
11
+
12
+ export const increment = (
13
+ x: AutoBeFunctionCallingMetric,
14
+ y: AutoBeFunctionCallingMetric,
15
+ ): void => {
16
+ x.attempt += y.attempt;
17
+ x.success += y.success;
18
+ x.consent += y.consent;
19
+ x.validationFailure += y.validationFailure;
20
+ x.invalidJson += y.invalidJson;
21
+ };
22
+
23
+ export const plus = (
24
+ x: AutoBeFunctionCallingMetric,
25
+ y: AutoBeFunctionCallingMetric,
26
+ ): AutoBeFunctionCallingMetric => ({
27
+ attempt: x.attempt + y.attempt,
28
+ success: x.success + y.success,
29
+ consent: x.consent + y.consent,
30
+ validationFailure: x.validationFailure + y.validationFailure,
31
+ invalidJson: x.invalidJson + y.invalidJson,
32
+ });
33
+
34
+ export const minus = (
35
+ x: AutoBeFunctionCallingMetric,
36
+ y: AutoBeFunctionCallingMetric,
37
+ ): AutoBeFunctionCallingMetric => ({
38
+ attempt: x.attempt - y.attempt,
39
+ success: x.success - y.success,
40
+ consent: x.consent - y.consent,
41
+ validationFailure: x.validationFailure - y.validationFailure,
42
+ invalidJson: x.invalidJson - y.invalidJson,
43
+ });
44
+ }
@@ -0,0 +1,141 @@
1
+ import {
2
+ AutoBeAggregateEventBase,
3
+ AutoBePhase,
4
+ AutoBeProcessAggregate,
5
+ AutoBeProcessAggregateCollection,
6
+ } from "@autobe/interface";
7
+
8
+ import { AutoBeTokenUsageComponent } from "../context/AutoBeTokenUsageComponent";
9
+ import { TokenUsageComputer } from "../utils/TokenUsageComputer";
10
+ import { AutoBeFunctionCallingMetricFactory } from "./AutoBeFunctionCallingMetricFactory";
11
+
12
+ export namespace AutoBeProcessAggregateFactory {
13
+ export const createAggregate = (): AutoBeProcessAggregate => ({
14
+ metric: AutoBeFunctionCallingMetricFactory.create(),
15
+ tokenUsage: new AutoBeTokenUsageComponent().toJSON(),
16
+ });
17
+
18
+ export const createCollection = <
19
+ Phase extends AutoBePhase | "all",
20
+ >(): AutoBeProcessAggregateCollection<Phase> =>
21
+ ({
22
+ total: createAggregate(),
23
+ }) satisfies AutoBeProcessAggregateCollection as AutoBeProcessAggregateCollection<Phase>;
24
+
25
+ export const computeTotal = <Phase extends AutoBePhase | "all">(
26
+ collection: AutoBeProcessAggregateCollection<Phase>,
27
+ ): AutoBeProcessAggregate => {
28
+ const total: AutoBeProcessAggregate = createAggregate();
29
+ for (const [key, value] of Object.entries(collection)) {
30
+ if (key === "total") continue;
31
+ AutoBeFunctionCallingMetricFactory.increment(total.metric, value.metric);
32
+ TokenUsageComputer.increment(total.tokenUsage, value.tokenUsage);
33
+ }
34
+ return total;
35
+ };
36
+
37
+ export const emplaceEvent = <
38
+ Event extends AutoBeAggregateEventBase & {
39
+ type: string;
40
+ },
41
+ >(
42
+ collection: AutoBeProcessAggregateCollection,
43
+ event: Event,
44
+ ): void => {
45
+ (collection as any)[event.type] ??= createAggregate();
46
+ collection.total ??= computeTotal(collection);
47
+
48
+ const local: AutoBeProcessAggregate = (collection as any)[
49
+ event.type
50
+ ] as AutoBeProcessAggregate;
51
+ const total: AutoBeProcessAggregate = collection.total;
52
+
53
+ AutoBeFunctionCallingMetricFactory.increment(local.metric, event.metric);
54
+ AutoBeFunctionCallingMetricFactory.increment(total.metric, event.metric);
55
+ TokenUsageComputer.increment(local.tokenUsage, event.tokenUsage);
56
+ TokenUsageComputer.increment(total.tokenUsage, event.tokenUsage);
57
+ };
58
+
59
+ export const filterPhase = <Phase extends AutoBePhase>(
60
+ collection: AutoBeProcessAggregateCollection,
61
+ phase: Phase,
62
+ ): AutoBeProcessAggregateCollection<Phase> => {
63
+ const result: AutoBeProcessAggregateCollection<Phase> = createCollection();
64
+ for (const [key, value] of Object.entries(collection)) {
65
+ if (key === "total") continue;
66
+ else if (key.startsWith(phase) === false) continue;
67
+
68
+ (result as any)[key] = value;
69
+ AutoBeFunctionCallingMetricFactory.increment(
70
+ result.total.metric,
71
+ value.metric,
72
+ );
73
+ TokenUsageComputer.increment(result.total.tokenUsage, value.tokenUsage);
74
+ }
75
+ return result;
76
+ };
77
+
78
+ export const reduce = (
79
+ collections: AutoBeProcessAggregateCollection[],
80
+ ): AutoBeProcessAggregateCollection => {
81
+ const result: AutoBeProcessAggregateCollection = createCollection();
82
+ for (const collection of collections) {
83
+ for (const [key, value] of Object.entries(collection)) {
84
+ if (key === "total") continue;
85
+ (result as any)[key] ??= createAggregate();
86
+ const local: AutoBeProcessAggregate = (result as any)[
87
+ key
88
+ ] as AutoBeProcessAggregate;
89
+ AutoBeFunctionCallingMetricFactory.increment(
90
+ local.metric,
91
+ value.metric,
92
+ );
93
+ TokenUsageComputer.increment(local.tokenUsage, value.tokenUsage);
94
+ AutoBeFunctionCallingMetricFactory.increment(
95
+ result.total.metric,
96
+ value.metric,
97
+ );
98
+ TokenUsageComputer.increment(result.total.tokenUsage, value.tokenUsage);
99
+ }
100
+ }
101
+ result.total ??= createAggregate();
102
+ Object.assign(result.total, computeTotal(result));
103
+ return result;
104
+ };
105
+
106
+ export const increment = (
107
+ x: AutoBeProcessAggregateCollection,
108
+ y: AutoBeProcessAggregateCollection,
109
+ ): void => {
110
+ for (const [key, value] of Object.entries(y)) {
111
+ if (key === "total") continue;
112
+ (x as any)[key] ??= createAggregate();
113
+ const local: AutoBeProcessAggregate = (x as any)[
114
+ key
115
+ ] as AutoBeProcessAggregate;
116
+ AutoBeFunctionCallingMetricFactory.increment(local.metric, value.metric);
117
+ }
118
+ x.total ??= createAggregate();
119
+ Object.assign(x.total, computeTotal(x));
120
+ };
121
+
122
+ export const minus = (
123
+ x: AutoBeProcessAggregateCollection,
124
+ y: AutoBeProcessAggregateCollection,
125
+ ): AutoBeProcessAggregateCollection => {
126
+ const result = JSON.parse(
127
+ JSON.stringify(x),
128
+ ) as AutoBeProcessAggregateCollection;
129
+ for (const [key, value] of Object.entries(y)) {
130
+ if (key === "total") continue;
131
+ (result as any)[key] ??= createAggregate();
132
+ const local: AutoBeProcessAggregate = (result as any)[
133
+ key
134
+ ] as AutoBeProcessAggregate;
135
+ AutoBeFunctionCallingMetricFactory.minus(local.metric, value.metric);
136
+ }
137
+ result.total ??= createAggregate();
138
+ Object.assign(result.total, computeTotal(result));
139
+ return result;
140
+ };
141
+ }
@@ -5,6 +5,7 @@ import {
5
5
  AutoBeAnalyzeStartEvent,
6
6
  AutoBeAssistantMessageEvent,
7
7
  AutoBeEvent,
8
+ AutoBeFunctionCallingMetric,
8
9
  AutoBeHistory,
9
10
  AutoBeInterfaceCompleteEvent,
10
11
  AutoBeInterfaceHistory,
@@ -12,6 +13,8 @@ import {
12
13
  AutoBePrismaCompleteEvent,
13
14
  AutoBePrismaHistory,
14
15
  AutoBePrismaStartEvent,
16
+ AutoBeProcessAggregate,
17
+ AutoBeProcessAggregateCollection,
15
18
  AutoBeRealizeCompleteEvent,
16
19
  AutoBeRealizeHistory,
17
20
  AutoBeRealizeStartEvent,
@@ -34,11 +37,13 @@ import { AutoBeContext } from "../context/AutoBeContext";
34
37
  import { AutoBeState } from "../context/AutoBeState";
35
38
  import { AutoBeTokenUsage } from "../context/AutoBeTokenUsage";
36
39
  import { AutoBeTokenUsageComponent } from "../context/AutoBeTokenUsageComponent";
37
- import { IAutoBeFacadeApplication } from "../context/IAutoBeFacadeApplication";
40
+ import { IAutoBeFacadeApplication } from "../orchestrate/facade/histories/IAutoBeFacadeApplication";
38
41
  import { IAutoBeConfig } from "../structures/IAutoBeConfig";
39
42
  import { IAutoBeVendor } from "../structures/IAutoBeVendor";
40
43
  import { AutoBeTimeoutError } from "../utils/AutoBeTimeoutError";
41
44
  import { TimedConversation } from "../utils/TimedConversation";
45
+ import { TokenUsageComputer } from "../utils/TokenUsageComputer";
46
+ import { AutoBeProcessAggregateFactory } from "./AutoBeProcessAggregateFactory";
42
47
  import { consentFunctionCall } from "./consentFunctionCall";
43
48
  import { getCommonPrompt } from "./getCommonPrompt";
44
49
  import { getCriticalCompiler } from "./getCriticalCompiler";
@@ -55,6 +60,7 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
55
60
  histories: () => AutoBeHistory[];
56
61
  usage: () => AutoBeTokenUsage;
57
62
  dispatch: (event: AutoBeEvent) => Promise<void>;
63
+ aggregates: AutoBeProcessAggregateCollection;
58
64
  }): AutoBeContext<Model> => {
59
65
  const config: Required<Omit<IAutoBeConfig, "backoffStrategy" | "timezone">> =
60
66
  {
@@ -68,6 +74,7 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
68
74
  vendor: props.vendor,
69
75
  retry: config.retry,
70
76
  locale: config.locale,
77
+ aggregates: props.aggregates,
71
78
  compilerListener: props.compilerListener,
72
79
  compiler: async () => {
73
80
  const compiler = await props.compiler();
@@ -86,7 +93,37 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
86
93
  return message;
87
94
  },
88
95
  conversate: async (next, closure) => {
89
- const trial = {
96
+ const aggregate: AutoBeProcessAggregate =
97
+ AutoBeProcessAggregateFactory.createAggregate();
98
+ const metric = (key: keyof AutoBeFunctionCallingMetric) => {
99
+ const accumulate = (collection: AutoBeProcessAggregateCollection) => {
100
+ ++collection.total.metric[key];
101
+ collection[next.source as "analyzeWrite"] ??=
102
+ AutoBeProcessAggregateFactory.createAggregate();
103
+ ++collection[next.source as "analyzeWrite"]!.metric[key];
104
+ };
105
+ ++aggregate.metric[key];
106
+ accumulate(props.aggregates);
107
+ };
108
+ const consume = (tokenUsage: IAutoBeTokenUsageJson.IComponent) => {
109
+ const accumulate = (collection: AutoBeProcessAggregateCollection) => {
110
+ TokenUsageComputer.increment(collection.total.tokenUsage, tokenUsage);
111
+ collection[next.source as "analyzeWrite"] ??=
112
+ AutoBeProcessAggregateFactory.createAggregate();
113
+ TokenUsageComputer.increment(
114
+ collection[next.source as "analyzeWrite"]!.tokenUsage,
115
+ tokenUsage,
116
+ );
117
+ };
118
+ TokenUsageComputer.increment(aggregate.tokenUsage, tokenUsage);
119
+ accumulate(props.aggregates);
120
+ props
121
+ .usage()
122
+ .record(tokenUsage, [
123
+ STAGES.find((stage) => next.source.startsWith(stage)) ?? "analyze",
124
+ ]);
125
+ };
126
+ const progress = {
90
127
  request: 0,
91
128
  response: 0,
92
129
  timeout: 0,
@@ -123,7 +160,7 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
123
160
  ...event,
124
161
  type: "vendorRequest",
125
162
  source: next.source,
126
- retry: trial.request++,
163
+ retry: progress.request++,
127
164
  });
128
165
  });
129
166
  agent.on("response", async (event) => {
@@ -132,11 +169,15 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
132
169
  ...event,
133
170
  type: "vendorResponse",
134
171
  source: next.source,
135
- retry: trial.response++,
172
+ retry: progress.response++,
136
173
  })
137
174
  .catch(() => {});
138
175
  });
176
+ agent.on("call", () => {
177
+ metric("attempt");
178
+ });
139
179
  agent.on("jsonParseError", (event) => {
180
+ metric("invalidJson");
140
181
  void props
141
182
  .dispatch({
142
183
  ...event,
@@ -145,6 +186,7 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
145
186
  .catch(() => {});
146
187
  });
147
188
  agent.on("validate", (event) => {
189
+ metric("validationFailure");
148
190
  void props
149
191
  .dispatch({
150
192
  type: "jsonValidateError",
@@ -193,7 +235,16 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
193
235
  .record(tokenUsage, [
194
236
  STAGES.find((stage) => next.source.startsWith(stage)) ?? "analyze",
195
237
  ]);
238
+ consume(tokenUsage);
196
239
 
240
+ const success = (histories: MicroAgenticaHistory<Model>[]) => {
241
+ metric("success");
242
+ return {
243
+ histories,
244
+ tokenUsage: aggregate.tokenUsage,
245
+ metric: aggregate.metric,
246
+ };
247
+ };
197
248
  if (result.type === "error") throw result.error;
198
249
  else if (result.type === "timeout") {
199
250
  void props
@@ -202,7 +253,7 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
202
253
  id: v7(),
203
254
  source: next.source,
204
255
  timeout: config.timeout!,
205
- retry: trial.timeout++,
256
+ retry: progress.timeout++,
206
257
  created_at: new Date().toISOString(),
207
258
  })
208
259
  .catch(() => {});
@@ -233,6 +284,7 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
233
284
  last?.type === "assistantMessage" &&
234
285
  last.text.trim().length !== 0
235
286
  ) {
287
+ metric("consent");
236
288
  const consent: string | null = await consentFunctionCall({
237
289
  source: next.source,
238
290
  dispatch: (e) => {
@@ -245,43 +297,46 @@ export const createAutoBeContext = <Model extends ILlmSchema.Model>(props: {
245
297
  if (consent !== null) {
246
298
  const newHistories: MicroAgenticaHistory<Model>[] =
247
299
  await agent.conversate(consent);
248
- const newTokenUsage: IAutoBeTokenUsageJson.IComponent = agent
249
- .getTokenUsage()
250
- .toJSON().aggregate;
251
- props
252
- .usage()
253
- .record(
254
- AutoBeTokenUsageComponent.minus(
255
- new AutoBeTokenUsageComponent(newTokenUsage),
256
- new AutoBeTokenUsageComponent(tokenUsage),
300
+ const newTokenUsage: IAutoBeTokenUsageJson.IComponent =
301
+ AutoBeTokenUsageComponent.minus(
302
+ new AutoBeTokenUsageComponent(
303
+ agent.getTokenUsage().toJSON().aggregate,
257
304
  ),
258
- [
259
- STAGES.find((stage) => next.source.startsWith(stage)) ??
260
- "analyze",
261
- ],
305
+ new AutoBeTokenUsageComponent(tokenUsage),
262
306
  );
263
- if (
264
- newHistories.some(
265
- (h) => h.type === "execute" && h.success === true,
266
- )
267
- )
268
- return {
269
- histories: newHistories,
270
- tokenUsage: newTokenUsage,
271
- };
307
+ consume(newTokenUsage);
308
+ if (newHistories.some((h) => h.type === "execute" && h.success))
309
+ return success(newHistories);
272
310
  }
273
311
  }
274
312
  failure();
275
313
  }
276
- return {
277
- histories: result.histories,
278
- tokenUsage,
279
- };
314
+ return success(result.histories);
280
315
  };
281
316
  if (next.enforceFunctionCall === true)
282
317
  return await forceRetry(execute, config.retry);
283
318
  else return await execute();
284
319
  },
320
+ getCurrentAggregates: (phase) => {
321
+ const previous: AutoBeProcessAggregateCollection =
322
+ AutoBeProcessAggregateFactory.reduce(
323
+ props
324
+ .histories()
325
+ .filter(
326
+ (h) =>
327
+ h.type === "analyze" ||
328
+ h.type === "prisma" ||
329
+ h.type === "interface" ||
330
+ h.type === "test" ||
331
+ h.type === "realize",
332
+ )
333
+ .map((h) => h.aggregates),
334
+ );
335
+ return AutoBeProcessAggregateFactory.filterPhase(
336
+ AutoBeProcessAggregateFactory.minus(props.aggregates, previous),
337
+ phase,
338
+ );
339
+ },
285
340
  };
286
341
  };
287
342
 
@@ -317,9 +372,10 @@ const createDispatch = (props: {
317
372
  prefix: event.prefix,
318
373
  actors: event.actors,
319
374
  files: event.files,
375
+ aggregates: event.aggregates,
376
+ step: event.step,
320
377
  created_at: analyzeStart?.created_at ?? new Date().toISOString(),
321
378
  completed_at: event.created_at,
322
- step: event.step,
323
379
  } satisfies AutoBeAnalyzeHistory,
324
380
  }) as AutoBeContext.DispatchHistory<Event>;
325
381
  else if (event.type === "prismaComplete")
@@ -335,9 +391,10 @@ const createDispatch = (props: {
335
391
  schemas: event.schemas,
336
392
  result: event.result,
337
393
  compiled: event.compiled,
394
+ aggregates: event.aggregates,
395
+ step: event.step,
338
396
  created_at: prismaStart?.created_at ?? new Date().toISOString(),
339
397
  completed_at: event.created_at,
340
- step: event.step,
341
398
  } satisfies AutoBePrismaHistory,
342
399
  }) as AutoBeContext.DispatchHistory<Event>;
343
400
  else if (event.type === "interfaceComplete")
@@ -353,9 +410,10 @@ const createDispatch = (props: {
353
410
  authorizations: event.authorizations,
354
411
  document: event.document,
355
412
  missed: event.missed,
413
+ aggregates: event.aggregates,
414
+ step: event.step,
356
415
  created_at: interfaceStart?.created_at ?? new Date().toISOString(),
357
416
  completed_at: new Date().toISOString(),
358
- step: event.step,
359
417
  } satisfies AutoBeInterfaceHistory,
360
418
  }) as AutoBeContext.DispatchHistory<Event>;
361
419
  else if (event.type === "testComplete")
@@ -370,9 +428,10 @@ const createDispatch = (props: {
370
428
  instruction: testStart?.reason ?? "",
371
429
  files: event.files,
372
430
  compiled: event.compiled,
431
+ aggregates: event.aggregates,
432
+ step: event.step,
373
433
  created_at: testStart?.created_at ?? new Date().toISOString(),
374
434
  completed_at: new Date().toISOString(),
375
- step: event.step,
376
435
  } satisfies AutoBeTestHistory,
377
436
  }) as AutoBeContext.DispatchHistory<Event>;
378
437
  else if (event.type === "realizeComplete")
@@ -389,9 +448,10 @@ const createDispatch = (props: {
389
448
  functions: event.functions,
390
449
  controllers: event.controllers,
391
450
  compiled: event.compiled,
451
+ aggregates: event.aggregates,
452
+ step: event.step,
392
453
  created_at: realizeStart?.created_at ?? new Date().toISOString(),
393
454
  completed_at: new Date().toISOString(),
394
- step: event.step,
395
455
  } satisfies AutoBeRealizeHistory,
396
456
  }) as AutoBeContext.DispatchHistory<Event>;
397
457
  void props.dispatch(event).catch(() => {});
@@ -92,6 +92,7 @@ export const orchestrateAnalyze = async <Model extends ILlmSchema.Model>(
92
92
  actors: scenario.actors,
93
93
  prefix: scenario.prefix,
94
94
  files: newFiles,
95
+ aggregates: ctx.getCurrentAggregates("analyze"),
95
96
  step,
96
97
  elapsed: new Date().getTime() - startTime.getTime(),
97
98
  created_at: new Date().toISOString(),
@@ -28,7 +28,7 @@ export const orchestrateAnalyzeReview = async <Model extends ILlmSchema.Model>(
28
28
  const pointer: IPointer<IAutoBeAnalyzeReviewApplication.IProps | null> = {
29
29
  value: null,
30
30
  };
31
- const { tokenUsage } = await ctx.conversate({
31
+ const { metric, tokenUsage } = await ctx.conversate({
32
32
  source: "analyzeReview",
33
33
  controller: createController({
34
34
  model: ctx.model,
@@ -57,6 +57,7 @@ export const orchestrateAnalyzeReview = async <Model extends ILlmSchema.Model>(
57
57
  review: pointer.value.review,
58
58
  content: pointer.value.content,
59
59
  tokenUsage,
60
+ metric,
60
61
  total: props.progress.total,
61
62
  completed: ++props.progress.completed,
62
63
  step: (ctx.state().analyze?.step ?? -1) + 1,
@@ -26,7 +26,7 @@ export const orchestrateAnalyzeScenario = async <
26
26
  const pointer: IPointer<IAutoBeAnalyzeScenarioApplication.IProps | null> = {
27
27
  value: null,
28
28
  };
29
- const { histories, tokenUsage } = await ctx.conversate({
29
+ const { histories, tokenUsage, metric } = await ctx.conversate({
30
30
  source: "analyzeScenario",
31
31
  controller: createController<Model>({
32
32
  model: ctx.model,
@@ -59,6 +59,7 @@ export const orchestrateAnalyzeScenario = async <
59
59
  language: pointer.value.language,
60
60
  actors: pointer.value.actors,
61
61
  files: pointer.value.files,
62
+ metric,
62
63
  tokenUsage,
63
64
  step: (ctx.state().analyze?.step ?? -1) + 1,
64
65
  created_at: start.toISOString(),
@@ -28,7 +28,7 @@ export const orchestrateAnalyzeWrite = async <Model extends ILlmSchema.Model>(
28
28
  const pointer: IPointer<IAutoBeAnalyzeWriteApplication.IProps | null> = {
29
29
  value: null,
30
30
  };
31
- const { tokenUsage } = await ctx.conversate({
31
+ const { metric, tokenUsage } = await ctx.conversate({
32
32
  source: "analyzeWrite",
33
33
  controller: createController<Model>({
34
34
  model: ctx.model,
@@ -49,7 +49,8 @@ export const orchestrateAnalyzeWrite = async <Model extends ILlmSchema.Model>(
49
49
  ...file,
50
50
  content: pointer.value.content,
51
51
  },
52
- tokenUsage: tokenUsage,
52
+ tokenUsage,
53
+ metric,
53
54
  step: (ctx.state().analyze?.step ?? -1) + 1,
54
55
  total: progress.total,
55
56
  completed: ++progress.completed,
@@ -1,4 +1,5 @@
1
1
  import {
2
+ AutoBeFunctionCallingMetric,
2
3
  AutoBeRealizeCorrectEvent,
3
4
  AutoBeRealizeValidateEvent,
4
5
  AutoBeTestCorrectEvent,
@@ -33,6 +34,7 @@ interface IFactoryProps<
33
34
  draft: string;
34
35
  review: string | undefined;
35
36
  final: string | undefined;
37
+ metric: AutoBeFunctionCallingMetric;
36
38
  tokenUsage: IAutoBeTokenUsageJson.IComponent;
37
39
  }): CorrectEvent;
38
40
  script(event: ValidateEvent): string;
@@ -92,7 +94,7 @@ const correct = async <
92
94
  > = {
93
95
  value: null,
94
96
  };
95
- const { tokenUsage } = await ctx.conversate({
97
+ const { metric, tokenUsage } = await ctx.conversate({
96
98
  source: factory.source,
97
99
  histories: transformCommonCorrectCastingHistories(
98
100
  [...failures, event].map((e) => ({
@@ -115,7 +117,7 @@ const correct = async <
115
117
  message: StringUtil.trim`
116
118
  Fix the TypeScript casting problems to resolve the compilation error.
117
119
 
118
- You don't need to explain me anything, but just fix or give it up
120
+ You don't need to explain me anything, but just fix or give it up
119
121
  immediately without any hesitation, explanation, and questions.
120
122
  `,
121
123
  });
@@ -129,6 +131,7 @@ const correct = async <
129
131
  draft: pointer.value.draft,
130
132
  review: pointer.value.revise.review,
131
133
  final: pointer.value.revise.final ?? undefined,
134
+ metric,
132
135
  tokenUsage,
133
136
  }),
134
137
  );