@autobe/agent 0.16.1 → 0.17.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.
- package/lib/AutoBeAgent.js +9 -9
- package/lib/AutoBeAgent.js.map +1 -1
- package/lib/constants/AutoBeSystemPromptConstant.d.ts +2 -2
- package/lib/context/AutoBeContext.d.ts +16 -4
- package/lib/context/AutoBeTokenUsage.d.ts +168 -11
- package/lib/context/AutoBeTokenUsage.js +152 -32
- package/lib/context/AutoBeTokenUsage.js.map +1 -1
- package/lib/context/AutoBeTokenUsageComponent.d.ts +116 -0
- package/lib/context/AutoBeTokenUsageComponent.js +120 -0
- package/lib/context/AutoBeTokenUsageComponent.js.map +1 -0
- package/lib/factory/createAutoBeApplication.js +1 -1
- package/lib/factory/createAutoBeApplication.js.map +1 -1
- package/lib/factory/createAutoBeContext.d.ts +19 -0
- package/lib/factory/createAutoBeContext.js +141 -0
- package/lib/factory/createAutoBeContext.js.map +1 -0
- package/lib/factory/getAutoBeGenerated.d.ts +1 -1
- package/lib/factory/getAutoBeGenerated.js +14 -11
- package/lib/factory/getAutoBeGenerated.js.map +1 -1
- package/lib/factory/getAutoBeRealizeGenerated.d.ts +7 -0
- package/lib/factory/getAutoBeRealizeGenerated.js +27 -0
- package/lib/factory/getAutoBeRealizeGenerated.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +1090 -927
- package/lib/index.mjs.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyze.js +9 -36
- package/lib/orchestrate/analyze/orchestrateAnalyze.js.map +1 -1
- package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js +9 -9
- package/lib/orchestrate/analyze/orchestrateAnalyzeReviewer.js.map +1 -1
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js +1 -1
- package/lib/orchestrate/analyze/writeDocumentUntilReviewPassed.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterface.js +6 -23
- package/lib/orchestrate/interface/orchestrateInterface.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceComplement.js +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceComplement.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceEndpoints.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceGroups.js +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceGroups.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceOperations.js.map +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js +1 -1
- package/lib/orchestrate/interface/orchestrateInterfaceSchemas.js.map +1 -1
- package/lib/orchestrate/prisma/{transformPrismaComponentsHistories.d.ts → histories/transformPrismaComponentsHistories.d.ts} +1 -1
- package/lib/orchestrate/prisma/{transformPrismaComponentsHistories.js → histories/transformPrismaComponentsHistories.js} +1 -1
- package/lib/orchestrate/prisma/histories/transformPrismaComponentsHistories.js.map +1 -0
- package/lib/orchestrate/prisma/histories/transformPrismaCorrectHistories.js.map +1 -0
- package/lib/orchestrate/prisma/{transformPrismaHistories.d.ts → histories/transformPrismaHistories.d.ts} +1 -1
- package/lib/orchestrate/prisma/histories/transformPrismaHistories.js.map +1 -0
- package/lib/orchestrate/prisma/histories/transformPrismaSchemaHistories.js +48 -0
- package/lib/orchestrate/prisma/histories/transformPrismaSchemaHistories.js.map +1 -0
- package/lib/orchestrate/prisma/orchestratePrisma.d.ts +1 -1
- package/lib/orchestrate/prisma/orchestratePrisma.js +9 -29
- package/lib/orchestrate/prisma/orchestratePrisma.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaComponent.js +126 -19
- package/lib/orchestrate/prisma/orchestratePrismaComponent.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaCorrect.js +10 -10
- package/lib/orchestrate/prisma/orchestratePrismaCorrect.js.map +1 -1
- package/lib/orchestrate/prisma/orchestratePrismaSchemas.js +128 -150
- package/lib/orchestrate/prisma/orchestratePrismaSchemas.js.map +1 -1
- package/lib/orchestrate/prisma/structures/IAutoBePrismaComponentApplication.d.ts +120 -0
- package/lib/orchestrate/prisma/structures/IAutoBePrismaComponentApplication.js +3 -0
- package/lib/orchestrate/prisma/structures/IAutoBePrismaComponentApplication.js.map +1 -0
- package/lib/orchestrate/prisma/structures/IAutoBePrismaCorrectApplication.d.ts +142 -0
- package/lib/orchestrate/prisma/structures/IAutoBePrismaCorrectApplication.js +3 -0
- package/lib/orchestrate/prisma/structures/IAutoBePrismaCorrectApplication.js.map +1 -0
- package/lib/orchestrate/prisma/structures/IAutoBePrismaSchemaApplication.d.ts +209 -0
- package/lib/orchestrate/prisma/structures/IAutoBePrismaSchemaApplication.js +3 -0
- package/lib/orchestrate/prisma/structures/IAutoBePrismaSchemaApplication.js.map +1 -0
- package/lib/orchestrate/realize/orchestrateRealize.js +13 -24
- package/lib/orchestrate/realize/orchestrateRealize.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeAuthorization.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.js +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.js.map +1 -1
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js +23 -23
- package/lib/orchestrate/realize/orchestrateRealizeCoder.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTest.js +8 -26
- package/lib/orchestrate/test/orchestrateTest.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestCorrect.js +1 -1
- package/lib/orchestrate/test/orchestrateTestCorrect.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestScenario.js +1 -1
- package/lib/orchestrate/test/orchestrateTestScenario.js.map +1 -1
- package/lib/orchestrate/test/orchestrateTestWrite.js +1 -1
- package/lib/orchestrate/test/orchestrateTestWrite.js.map +1 -1
- package/package.json +7 -7
- package/src/AutoBeAgent.ts +10 -9
- package/src/constants/AutoBeSystemPromptConstant.ts +2 -2
- package/src/context/AutoBeContext.ts +30 -3
- package/src/context/AutoBeTokenUsage.ts +252 -54
- package/src/context/AutoBeTokenUsageComponent.ts +180 -0
- package/src/factory/createAutoBeApplication.ts +1 -1
- package/src/factory/createAutoBeContext.ts +193 -0
- package/src/factory/getAutoBeGenerated.ts +14 -21
- package/src/factory/getAutoBeRealizeGenerated.ts +30 -0
- package/src/index.ts +1 -0
- package/src/orchestrate/analyze/orchestrateAnalyze.ts +9 -38
- package/src/orchestrate/analyze/orchestrateAnalyzeReviewer.ts +1 -1
- package/src/orchestrate/analyze/writeDocumentUntilReviewPassed.ts +1 -1
- package/src/orchestrate/interface/orchestrateInterface.ts +4 -21
- package/src/orchestrate/interface/orchestrateInterfaceComplement.ts +1 -1
- package/src/orchestrate/interface/orchestrateInterfaceEndpoints.ts +1 -1
- package/src/orchestrate/interface/orchestrateInterfaceGroups.ts +1 -1
- package/src/orchestrate/interface/orchestrateInterfaceOperations.ts +1 -1
- package/src/orchestrate/interface/orchestrateInterfaceSchemas.ts +1 -1
- package/src/orchestrate/prisma/{transformPrismaComponentsHistories.ts → histories/transformPrismaComponentsHistories.ts} +2 -2
- package/src/orchestrate/prisma/{transformPrismaCorrectHistories.ts → histories/transformPrismaCorrectHistories.ts} +1 -1
- package/src/orchestrate/prisma/{transformPrismaHistories.ts → histories/transformPrismaHistories.ts} +2 -2
- package/src/orchestrate/prisma/{transformPrismaSchemaHistories.ts → histories/transformPrismaSchemaHistories.ts} +1 -1
- package/src/orchestrate/prisma/orchestratePrisma.ts +45 -68
- package/src/orchestrate/prisma/orchestratePrismaComponent.ts +13 -81
- package/src/orchestrate/prisma/orchestratePrismaCorrect.ts +8 -148
- package/src/orchestrate/prisma/orchestratePrismaSchemas.ts +15 -82
- package/src/orchestrate/prisma/structures/IAutoBePrismaComponentApplication.ts +124 -0
- package/src/orchestrate/prisma/structures/IAutoBePrismaCorrectApplication.ts +144 -0
- package/src/orchestrate/prisma/structures/IAutoBePrismaSchemaApplication.ts +214 -0
- package/src/orchestrate/realize/orchestrateRealize.ts +19 -32
- package/src/orchestrate/realize/orchestrateRealizeAuthorization.ts +1 -1
- package/src/orchestrate/realize/orchestrateRealizeAuthorizationCorrect.ts +1 -1
- package/src/orchestrate/realize/orchestrateRealizeCoder.ts +1 -1
- package/src/orchestrate/test/orchestrateTest.ts +6 -26
- package/src/orchestrate/test/orchestrateTestCorrect.ts +1 -1
- package/src/orchestrate/test/orchestrateTestScenario.ts +1 -1
- package/src/orchestrate/test/orchestrateTestWrite.ts +1 -1
- package/lib/orchestrate/prisma/transformPrismaComponentsHistories.js.map +0 -1
- package/lib/orchestrate/prisma/transformPrismaCorrectHistories.js.map +0 -1
- package/lib/orchestrate/prisma/transformPrismaHistories.js.map +0 -1
- package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js +0 -48
- package/lib/orchestrate/prisma/transformPrismaSchemaHistories.js.map +0 -1
- /package/lib/orchestrate/prisma/{transformPrismaCorrectHistories.d.ts → histories/transformPrismaCorrectHistories.d.ts} +0 -0
- /package/lib/orchestrate/prisma/{transformPrismaCorrectHistories.js → histories/transformPrismaCorrectHistories.js} +0 -0
- /package/lib/orchestrate/prisma/{transformPrismaHistories.js → histories/transformPrismaHistories.js} +0 -0
- /package/lib/orchestrate/prisma/{transformPrismaSchemaHistories.d.ts → histories/transformPrismaSchemaHistories.d.ts} +0 -0
|
@@ -1,16 +1,173 @@
|
|
|
1
|
-
import { AgenticaTokenUsage } from "@agentica/core";
|
|
2
1
|
import { IAutoBeTokenUsageJson } from "@autobe/interface";
|
|
2
|
+
import { AutoBeTokenUsageComponent } from "./AutoBeTokenUsageComponent";
|
|
3
3
|
import { IAutoBeApplication } from "./IAutoBeApplication";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Comprehensive token usage tracker for the AutoBe vibe coding system.
|
|
6
|
+
*
|
|
7
|
+
* This class provides centralized tracking and management of token consumption
|
|
8
|
+
* across all AI agents in the automated development pipeline. It captures
|
|
9
|
+
* detailed token usage statistics for each processing phase - from initial
|
|
10
|
+
* requirements analysis through final implementation - enabling cost
|
|
11
|
+
* monitoring, performance optimization, and resource utilization analysis.
|
|
12
|
+
*
|
|
13
|
+
* The token usage data includes both input tokens (with cache efficiency) and
|
|
14
|
+
* output tokens (with generation type breakdowns), providing insights into AI
|
|
15
|
+
* processing efficiency and helping optimize the balance between computational
|
|
16
|
+
* costs and output quality.
|
|
17
|
+
*
|
|
18
|
+
* @author SunRabbit123
|
|
19
|
+
*/
|
|
20
|
+
export declare class AutoBeTokenUsage implements IAutoBeTokenUsageJson {
|
|
21
|
+
/**
|
|
22
|
+
* Token usage for the facade agent orchestrating the entire pipeline.
|
|
23
|
+
*
|
|
24
|
+
* Tracks tokens consumed by the initial agent that coordinates and manages
|
|
25
|
+
* the overall vibe coding process, including request parsing and response
|
|
26
|
+
* orchestration.
|
|
27
|
+
*/
|
|
28
|
+
readonly facade: AutoBeTokenUsageComponent;
|
|
29
|
+
/**
|
|
30
|
+
* Token usage for the requirements analysis agent.
|
|
31
|
+
*
|
|
32
|
+
* Captures tokens used during the analysis phase where user requirements are
|
|
33
|
+
* processed, understood, and transformed into structured specifications for
|
|
34
|
+
* subsequent development phases.
|
|
35
|
+
*/
|
|
36
|
+
readonly analyze: AutoBeTokenUsageComponent;
|
|
37
|
+
/**
|
|
38
|
+
* Token usage for the Prisma database schema generation agent.
|
|
39
|
+
*
|
|
40
|
+
* Records tokens consumed while designing and generating database schemas,
|
|
41
|
+
* including entity relationships, field definitions, and database-specific
|
|
42
|
+
* optimizations.
|
|
43
|
+
*/
|
|
44
|
+
readonly prisma: AutoBeTokenUsageComponent;
|
|
45
|
+
/**
|
|
46
|
+
* Token usage for the API interface specification agent.
|
|
47
|
+
*
|
|
48
|
+
* Tracks tokens used in creating OpenAPI/Swagger specifications, defining
|
|
49
|
+
* endpoints, request/response structures, and API documentation.
|
|
50
|
+
*/
|
|
51
|
+
readonly interface: AutoBeTokenUsageComponent;
|
|
52
|
+
/**
|
|
53
|
+
* Token usage for the test code generation agent.
|
|
54
|
+
*
|
|
55
|
+
* Monitors tokens consumed during automated test creation, including scenario
|
|
56
|
+
* planning, test case generation, and end-to-end test implementation.
|
|
57
|
+
*/
|
|
58
|
+
readonly test: AutoBeTokenUsageComponent;
|
|
59
|
+
/**
|
|
60
|
+
* Token usage for the implementation realization agent.
|
|
61
|
+
*
|
|
62
|
+
* Captures tokens used in the final implementation phase where actual
|
|
63
|
+
* business logic, controllers, services, and integration code are generated.
|
|
64
|
+
*/
|
|
65
|
+
readonly realize: AutoBeTokenUsageComponent;
|
|
66
|
+
/**
|
|
67
|
+
* Aggregated token usage statistics across all agents.
|
|
68
|
+
*
|
|
69
|
+
* Provides a unified view of token consumption by combining data from all
|
|
70
|
+
* processing phases in the vibe coding pipeline. This computed property
|
|
71
|
+
* dynamically calculates the sum of all agent components (facade, analyze,
|
|
72
|
+
* prisma, interface, test, realize) whenever accessed, ensuring the aggregate
|
|
73
|
+
* always reflects the current state of token usage.
|
|
74
|
+
*
|
|
75
|
+
* The aggregation performs element-wise addition across all token metrics,
|
|
76
|
+
* including total counts, input breakdowns with cache statistics, and output
|
|
77
|
+
* categorizations by generation type. This comprehensive view enables overall
|
|
78
|
+
* cost assessment and resource utilization analysis for the entire automated
|
|
79
|
+
* development session.
|
|
80
|
+
*/
|
|
81
|
+
get aggregate(): IAutoBeTokenUsageJson.IComponent;
|
|
82
|
+
/**
|
|
83
|
+
* Default Constructor.
|
|
84
|
+
*
|
|
85
|
+
* Creates a new token usage tracker with all agent phases initialized to
|
|
86
|
+
* empty components. Each component starts with zero values for all token
|
|
87
|
+
* counters, providing a clean slate for tracking token consumption from the
|
|
88
|
+
* beginning of a vibe coding session.
|
|
89
|
+
*/
|
|
90
|
+
constructor();
|
|
91
|
+
/**
|
|
92
|
+
* Binding Constructor.
|
|
93
|
+
*
|
|
94
|
+
* Creates a new instance that shares component references with the provided
|
|
95
|
+
* AutoBeTokenUsage instance. This establishes a bound relationship where both
|
|
96
|
+
* instances point to the same component objects. Any modifications to token
|
|
97
|
+
* counts through either instance will be reflected in both, enabling shared
|
|
98
|
+
* tracking across different contexts.
|
|
99
|
+
*
|
|
100
|
+
* @param bind Existing AutoBeTokenUsage instance to bind to
|
|
101
|
+
*/
|
|
102
|
+
constructor(bind: AutoBeTokenUsage);
|
|
103
|
+
/**
|
|
104
|
+
* Initializer Constructor.
|
|
105
|
+
*
|
|
106
|
+
* Reconstructs a token usage tracker from serialized JSON data. Creates new
|
|
107
|
+
* AutoBeTokenUsageComponent instances for each agent phase, initializing them
|
|
108
|
+
* with the corresponding values from the JSON structure. This enables
|
|
109
|
+
* restoration of token usage state from persisted data or transmission
|
|
110
|
+
* between different parts of the system.
|
|
111
|
+
*
|
|
112
|
+
* @param props Token usage data in JSON format
|
|
113
|
+
*/
|
|
114
|
+
constructor(props?: Omit<IAutoBeTokenUsageJson, "aggregate">);
|
|
115
|
+
/**
|
|
116
|
+
* Serialize token usage data to JSON format.
|
|
117
|
+
*
|
|
118
|
+
* Converts the internal token usage representation to the standardized
|
|
119
|
+
* IAutoBeTokenUsageJson format, suitable for persistence, transmission, or
|
|
120
|
+
* external analysis. The serialized data maintains the complete structure
|
|
121
|
+
* including all agent phases and detailed token breakdowns.
|
|
122
|
+
*
|
|
123
|
+
* @returns JSON representation of token usage statistics
|
|
124
|
+
*/
|
|
125
|
+
toJSON(): IAutoBeTokenUsageJson;
|
|
126
|
+
/**
|
|
127
|
+
* Record token usage for specific processing stages.
|
|
128
|
+
*
|
|
129
|
+
* Updates token consumption statistics for one or more agent phases based on
|
|
130
|
+
* the provided usage data. This method allows selective recording of token
|
|
131
|
+
* usage for specific stages, enabling fine-grained tracking during
|
|
132
|
+
* multi-phase processing or when certain agents are invoked multiple times.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* tokenUsage.record(
|
|
137
|
+
* { total: 150, input: { total: 100, cached: 20 }, output: { total: 50, ... } },
|
|
138
|
+
* ['analyze', 'prisma']
|
|
139
|
+
* );
|
|
140
|
+
* ```;
|
|
141
|
+
*
|
|
142
|
+
* @param usage - Token usage component data to record
|
|
143
|
+
* @param additionalStages - Array of stage names to update with the usage
|
|
144
|
+
* data
|
|
145
|
+
*/
|
|
146
|
+
record(usage: IAutoBeTokenUsageJson.IComponent, additionalStages?: (keyof IAutoBeApplication)[]): void;
|
|
147
|
+
/**
|
|
148
|
+
* Increment current token usage with data from another instance.
|
|
149
|
+
*
|
|
150
|
+
* Adds token usage statistics from another AutoBeTokenUsage instance to this
|
|
151
|
+
* one, updating all agent phases simultaneously. This method is useful for
|
|
152
|
+
* combining token usage from parallel processing, multiple runs, or when
|
|
153
|
+
* aggregating statistics from distributed agent executions.
|
|
154
|
+
*
|
|
155
|
+
* @param usage - AutoBeTokenUsage instance to add to current statistics
|
|
156
|
+
* @returns This instance for method chaining
|
|
157
|
+
*/
|
|
13
158
|
increment(usage: AutoBeTokenUsage): this;
|
|
159
|
+
/**
|
|
160
|
+
* Create a new instance combining token usage from two sources.
|
|
161
|
+
*
|
|
162
|
+
* Performs element-wise addition of token usage statistics from two
|
|
163
|
+
* AutoBeTokenUsage instances, creating a new instance with the combined
|
|
164
|
+
* totals. This static method is useful for aggregating token usage across
|
|
165
|
+
* multiple vibe coding sessions or when merging statistics from different
|
|
166
|
+
* execution contexts.
|
|
167
|
+
*
|
|
168
|
+
* @param usageA - First token usage instance
|
|
169
|
+
* @param usageB - Second token usage instance
|
|
170
|
+
* @returns New instance with combined token usage statistics
|
|
171
|
+
*/
|
|
14
172
|
static plus(usageA: AutoBeTokenUsage, usageB: AutoBeTokenUsage): AutoBeTokenUsage;
|
|
15
|
-
toJSON(): IAutoBeTokenUsageJson;
|
|
16
173
|
}
|
|
@@ -1,60 +1,180 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AutoBeTokenUsage = void 0;
|
|
4
|
-
const
|
|
4
|
+
const AutoBeTokenUsageComponent_1 = require("./AutoBeTokenUsageComponent");
|
|
5
|
+
/**
|
|
6
|
+
* Comprehensive token usage tracker for the AutoBe vibe coding system.
|
|
7
|
+
*
|
|
8
|
+
* This class provides centralized tracking and management of token consumption
|
|
9
|
+
* across all AI agents in the automated development pipeline. It captures
|
|
10
|
+
* detailed token usage statistics for each processing phase - from initial
|
|
11
|
+
* requirements analysis through final implementation - enabling cost
|
|
12
|
+
* monitoring, performance optimization, and resource utilization analysis.
|
|
13
|
+
*
|
|
14
|
+
* The token usage data includes both input tokens (with cache efficiency) and
|
|
15
|
+
* output tokens (with generation type breakdowns), providing insights into AI
|
|
16
|
+
* processing efficiency and helping optimize the balance between computational
|
|
17
|
+
* costs and output quality.
|
|
18
|
+
*
|
|
19
|
+
* @author SunRabbit123
|
|
20
|
+
*/
|
|
5
21
|
class AutoBeTokenUsage {
|
|
22
|
+
/**
|
|
23
|
+
* Aggregated token usage statistics across all agents.
|
|
24
|
+
*
|
|
25
|
+
* Provides a unified view of token consumption by combining data from all
|
|
26
|
+
* processing phases in the vibe coding pipeline. This computed property
|
|
27
|
+
* dynamically calculates the sum of all agent components (facade, analyze,
|
|
28
|
+
* prisma, interface, test, realize) whenever accessed, ensuring the aggregate
|
|
29
|
+
* always reflects the current state of token usage.
|
|
30
|
+
*
|
|
31
|
+
* The aggregation performs element-wise addition across all token metrics,
|
|
32
|
+
* including total counts, input breakdowns with cache statistics, and output
|
|
33
|
+
* categorizations by generation type. This comprehensive view enables overall
|
|
34
|
+
* cost assessment and resource utilization analysis for the entire automated
|
|
35
|
+
* development session.
|
|
36
|
+
*/
|
|
37
|
+
get aggregate() {
|
|
38
|
+
return AutoBeTokenUsage.keys()
|
|
39
|
+
.reduce((acc, cur) => AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent.plus(acc, this[cur]), new AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent())
|
|
40
|
+
.toJSON();
|
|
41
|
+
}
|
|
6
42
|
constructor(props) {
|
|
7
43
|
if (props === undefined) {
|
|
8
|
-
this.facade = new
|
|
9
|
-
this.analyze = new
|
|
10
|
-
this.prisma = new
|
|
11
|
-
this.interface = new
|
|
12
|
-
this.test = new
|
|
13
|
-
this.realize = new
|
|
44
|
+
this.facade = new AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent();
|
|
45
|
+
this.analyze = new AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent();
|
|
46
|
+
this.prisma = new AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent();
|
|
47
|
+
this.interface = new AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent();
|
|
48
|
+
this.test = new AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent();
|
|
49
|
+
this.realize = new AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent();
|
|
14
50
|
return;
|
|
15
51
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
52
|
+
else if (props instanceof AutoBeTokenUsage) {
|
|
53
|
+
this.facade = props.facade;
|
|
54
|
+
this.analyze = props.analyze;
|
|
55
|
+
this.prisma = props.prisma;
|
|
56
|
+
this.interface = props.interface;
|
|
57
|
+
this.test = props.test;
|
|
58
|
+
this.realize = props.realize;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.facade = new AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent(props.facade);
|
|
62
|
+
this.analyze = new AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent(props.analyze);
|
|
63
|
+
this.prisma = new AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent(props.prisma);
|
|
64
|
+
this.interface = new AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent(props.interface);
|
|
65
|
+
this.test = new AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent(props.test);
|
|
66
|
+
this.realize = new AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent(props.realize);
|
|
67
|
+
}
|
|
22
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Serialize token usage data to JSON format.
|
|
71
|
+
*
|
|
72
|
+
* Converts the internal token usage representation to the standardized
|
|
73
|
+
* IAutoBeTokenUsageJson format, suitable for persistence, transmission, or
|
|
74
|
+
* external analysis. The serialized data maintains the complete structure
|
|
75
|
+
* including all agent phases and detailed token breakdowns.
|
|
76
|
+
*
|
|
77
|
+
* @returns JSON representation of token usage statistics
|
|
78
|
+
*/
|
|
79
|
+
toJSON() {
|
|
80
|
+
return {
|
|
81
|
+
aggregate: this.aggregate,
|
|
82
|
+
facade: this.facade.toJSON(),
|
|
83
|
+
analyze: this.analyze.toJSON(),
|
|
84
|
+
prisma: this.prisma.toJSON(),
|
|
85
|
+
interface: this.interface.toJSON(),
|
|
86
|
+
test: this.test.toJSON(),
|
|
87
|
+
realize: this.realize.toJSON(),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/* -----------------------------------------------------------
|
|
91
|
+
OPERATORS
|
|
92
|
+
----------------------------------------------------------- */
|
|
93
|
+
/**
|
|
94
|
+
* Record token usage for specific processing stages.
|
|
95
|
+
*
|
|
96
|
+
* Updates token consumption statistics for one or more agent phases based on
|
|
97
|
+
* the provided usage data. This method allows selective recording of token
|
|
98
|
+
* usage for specific stages, enabling fine-grained tracking during
|
|
99
|
+
* multi-phase processing or when certain agents are invoked multiple times.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* tokenUsage.record(
|
|
104
|
+
* { total: 150, input: { total: 100, cached: 20 }, output: { total: 50, ... } },
|
|
105
|
+
* ['analyze', 'prisma']
|
|
106
|
+
* );
|
|
107
|
+
* ```;
|
|
108
|
+
*
|
|
109
|
+
* @param usage - Token usage component data to record
|
|
110
|
+
* @param additionalStages - Array of stage names to update with the usage
|
|
111
|
+
* data
|
|
112
|
+
*/
|
|
23
113
|
record(usage, additionalStages = []) {
|
|
24
|
-
this.facade.increment(usage);
|
|
25
114
|
additionalStages.forEach((stage) => {
|
|
26
115
|
this[stage].increment(usage);
|
|
27
116
|
});
|
|
28
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Increment current token usage with data from another instance.
|
|
120
|
+
*
|
|
121
|
+
* Adds token usage statistics from another AutoBeTokenUsage instance to this
|
|
122
|
+
* one, updating all agent phases simultaneously. This method is useful for
|
|
123
|
+
* combining token usage from parallel processing, multiple runs, or when
|
|
124
|
+
* aggregating statistics from distributed agent executions.
|
|
125
|
+
*
|
|
126
|
+
* @param usage - AutoBeTokenUsage instance to add to current statistics
|
|
127
|
+
* @returns This instance for method chaining
|
|
128
|
+
*/
|
|
29
129
|
increment(usage) {
|
|
30
130
|
AutoBeTokenUsage.keys().forEach((key) => {
|
|
31
131
|
this[key].increment(usage[key]);
|
|
32
132
|
});
|
|
33
133
|
return this;
|
|
34
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Create a new instance combining token usage from two sources.
|
|
137
|
+
*
|
|
138
|
+
* Performs element-wise addition of token usage statistics from two
|
|
139
|
+
* AutoBeTokenUsage instances, creating a new instance with the combined
|
|
140
|
+
* totals. This static method is useful for aggregating token usage across
|
|
141
|
+
* multiple vibe coding sessions or when merging statistics from different
|
|
142
|
+
* execution contexts.
|
|
143
|
+
*
|
|
144
|
+
* @param usageA - First token usage instance
|
|
145
|
+
* @param usageB - Second token usage instance
|
|
146
|
+
* @returns New instance with combined token usage statistics
|
|
147
|
+
*/
|
|
35
148
|
static plus(usageA, usageB) {
|
|
36
149
|
return new AutoBeTokenUsage({
|
|
37
|
-
facade:
|
|
38
|
-
analyze:
|
|
39
|
-
prisma:
|
|
40
|
-
interface:
|
|
41
|
-
test:
|
|
42
|
-
realize:
|
|
150
|
+
facade: AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent.plus(usageA.facade, usageB.facade),
|
|
151
|
+
analyze: AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent.plus(usageA.analyze, usageB.analyze),
|
|
152
|
+
prisma: AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent.plus(usageA.prisma, usageB.prisma),
|
|
153
|
+
interface: AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent.plus(usageA.interface, usageB.interface),
|
|
154
|
+
test: AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent.plus(usageA.test, usageB.test),
|
|
155
|
+
realize: AutoBeTokenUsageComponent_1.AutoBeTokenUsageComponent.plus(usageA.realize, usageB.realize),
|
|
43
156
|
});
|
|
44
157
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Get all agent phase keys for iteration.
|
|
160
|
+
*
|
|
161
|
+
* Returns a readonly array of all agent phase names used in the vibe coding
|
|
162
|
+
* system. This internal utility method ensures consistent iteration over all
|
|
163
|
+
* token usage components when performing operations like aggregation or
|
|
164
|
+
* serialization.
|
|
165
|
+
*
|
|
166
|
+
* @returns Readonly array of agent phase keys
|
|
167
|
+
* @internal
|
|
168
|
+
*/
|
|
56
169
|
static keys() {
|
|
57
|
-
return [
|
|
170
|
+
return [
|
|
171
|
+
"facade",
|
|
172
|
+
"analyze",
|
|
173
|
+
"prisma",
|
|
174
|
+
"interface",
|
|
175
|
+
"test",
|
|
176
|
+
"realize",
|
|
177
|
+
];
|
|
58
178
|
}
|
|
59
179
|
}
|
|
60
180
|
exports.AutoBeTokenUsage = AutoBeTokenUsage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoBeTokenUsage.js","sourceRoot":"","sources":["../../src/context/AutoBeTokenUsage.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"AutoBeTokenUsage.js","sourceRoot":"","sources":["../../src/context/AutoBeTokenUsage.ts"],"names":[],"mappings":";;;AAEA,2EAAwE;AAGxE;;;;;;;;;;;;;;;GAeG;AACH,MAAa,gBAAgB;IAoD3B;;;;;;;;;;;;;;OAcG;IACH,IAAW,SAAS;QAClB,OAAO,gBAAgB,CAAC,IAAI,EAAE;aAC3B,MAAM,CACL,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,qDAAyB,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAC5D,IAAI,qDAAyB,EAAE,CAChC;aACA,MAAM,EAAE,CAAC;IACd,CAAC;IAyCD,YACE,KAA4D;QAE5D,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,IAAI,CAAC,MAAM,GAAG,IAAI,qDAAyB,EAAE,CAAC;YAC9C,IAAI,CAAC,OAAO,GAAG,IAAI,qDAAyB,EAAE,CAAC;YAC/C,IAAI,CAAC,MAAM,GAAG,IAAI,qDAAyB,EAAE,CAAC;YAC9C,IAAI,CAAC,SAAS,GAAG,IAAI,qDAAyB,EAAE,CAAC;YACjD,IAAI,CAAC,IAAI,GAAG,IAAI,qDAAyB,EAAE,CAAC;YAC5C,IAAI,CAAC,OAAO,GAAG,IAAI,qDAAyB,EAAE,CAAC;YAC/C,OAAO;QACT,CAAC;aAAM,IAAI,KAAK,YAAY,gBAAgB,EAAE,CAAC;YAC7C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YAC3B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;YAC7B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YAC3B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;YACjC,IAAI,C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
|
1
|
+
import { IAutoBeTokenUsageJson } from "@autobe/interface";
|
|
2
|
+
/**
|
|
3
|
+
* Token usage component for individual AI agents in the vibe coding pipeline.
|
|
4
|
+
*
|
|
5
|
+
* Represents detailed token consumption statistics for a specific processing
|
|
6
|
+
* phase (facade, analyze, prisma, interface, test, or realize). This class
|
|
7
|
+
* tracks both input and output token usage with granular breakdowns, enabling
|
|
8
|
+
* precise cost analysis and performance optimization for each agent.
|
|
9
|
+
*
|
|
10
|
+
* The component structure includes:
|
|
11
|
+
*
|
|
12
|
+
* - Total token count for quick cost calculations
|
|
13
|
+
* - Input token breakdown with cache efficiency metrics
|
|
14
|
+
* - Output token categorization by generation type
|
|
15
|
+
*
|
|
16
|
+
* This granular tracking helps identify optimization opportunities and
|
|
17
|
+
* understand the computational characteristics of each agent phase.
|
|
18
|
+
*
|
|
19
|
+
* @author SunRabbit123
|
|
20
|
+
*/
|
|
21
|
+
export declare class AutoBeTokenUsageComponent implements IAutoBeTokenUsageJson.IComponent {
|
|
22
|
+
/**
|
|
23
|
+
* Detailed breakdown of input token consumption.
|
|
24
|
+
*
|
|
25
|
+
* Tracks how many tokens were processed as input to the AI agent, including:
|
|
26
|
+
*
|
|
27
|
+
* - Total input tokens processed
|
|
28
|
+
* - Cached tokens that were reused from previous operations
|
|
29
|
+
*
|
|
30
|
+
* The cache efficiency (cached/total ratio) indicates how well the system is
|
|
31
|
+
* reusing context across multiple invocations.
|
|
32
|
+
*/
|
|
33
|
+
readonly input: IAutoBeTokenUsageJson.IInput;
|
|
34
|
+
/**
|
|
35
|
+
* Detailed breakdown of output token generation.
|
|
36
|
+
*
|
|
37
|
+
* Categorizes generated tokens by their purpose and acceptance status:
|
|
38
|
+
*
|
|
39
|
+
* - Total output tokens generated
|
|
40
|
+
* - Reasoning tokens (internal processing)
|
|
41
|
+
* - Accepted prediction tokens (efficient generation)
|
|
42
|
+
* - Rejected prediction tokens (quality control overhead)
|
|
43
|
+
*
|
|
44
|
+
* These metrics help understand the AI's generation efficiency and the
|
|
45
|
+
* effectiveness of its predictive mechanisms.
|
|
46
|
+
*/
|
|
47
|
+
readonly output: IAutoBeTokenUsageJson.IOutput;
|
|
48
|
+
/**
|
|
49
|
+
* Total token count combining all input and output tokens.
|
|
50
|
+
*
|
|
51
|
+
* Represents the complete token consumption for this component, providing a
|
|
52
|
+
* single metric for overall resource utilization. This value is critical for
|
|
53
|
+
* cost calculations and comparing efficiency across different agents or
|
|
54
|
+
* processing phases.
|
|
55
|
+
*/
|
|
56
|
+
get total(): number;
|
|
57
|
+
/**
|
|
58
|
+
* Default Constructor.
|
|
59
|
+
*
|
|
60
|
+
* Creates a new token usage component with all counters initialized to zero.
|
|
61
|
+
* Constructs fresh input and output objects with default values, providing a
|
|
62
|
+
* clean starting point for tracking token consumption in an agent phase.
|
|
63
|
+
*/
|
|
64
|
+
constructor();
|
|
65
|
+
/**
|
|
66
|
+
* Initializer Constructor.
|
|
67
|
+
*
|
|
68
|
+
* Creates a new component populated with existing token usage data. Directly
|
|
69
|
+
* assigns the provided values to instance properties, preserving the exact
|
|
70
|
+
* token counts and structure from the source data for accurate tracking
|
|
71
|
+
* continuation.
|
|
72
|
+
*
|
|
73
|
+
* @param props - Token usage data to initialize the component
|
|
74
|
+
*/
|
|
75
|
+
constructor(props: Omit<IAutoBeTokenUsageJson.IComponent, "total">);
|
|
76
|
+
/**
|
|
77
|
+
* Export token usage data as JSON.
|
|
78
|
+
*
|
|
79
|
+
* Converts the component's token usage statistics to the standardized
|
|
80
|
+
* IAutoBeTokenUsageJson.IComponent format. This serialization maintains the
|
|
81
|
+
* complete structure including total counts and detailed breakdowns for both
|
|
82
|
+
* input and output tokens.
|
|
83
|
+
*
|
|
84
|
+
* @returns JSON representation of the token usage component
|
|
85
|
+
*/
|
|
86
|
+
toJSON(): IAutoBeTokenUsageJson.IComponent;
|
|
87
|
+
/**
|
|
88
|
+
* Add token usage data to current statistics.
|
|
89
|
+
*
|
|
90
|
+
* Increments all token counters in this component by the corresponding values
|
|
91
|
+
* from the provided component data. This method performs in-place updates,
|
|
92
|
+
* modifying the current instance rather than creating a new one.
|
|
93
|
+
*
|
|
94
|
+
* Updates include:
|
|
95
|
+
*
|
|
96
|
+
* - Total token count
|
|
97
|
+
* - Input tokens (both total and cached)
|
|
98
|
+
* - Output tokens (reasoning, accepted/rejected predictions)
|
|
99
|
+
*
|
|
100
|
+
* @param props - Token usage component data to add to current values
|
|
101
|
+
*/
|
|
102
|
+
increment(props: IAutoBeTokenUsageJson.IComponent): void;
|
|
103
|
+
/**
|
|
104
|
+
* Create new component combining two token usage statistics.
|
|
105
|
+
*
|
|
106
|
+
* Performs element-wise addition of all token counters from two components,
|
|
107
|
+
* creating a new AutoBeTokenUsageComponent instance with the combined totals.
|
|
108
|
+
* This static method is useful for aggregating token usage across multiple
|
|
109
|
+
* agent invocations or combining statistics from parallel processing.
|
|
110
|
+
*
|
|
111
|
+
* @param a - First token usage component
|
|
112
|
+
* @param b - Second token usage component
|
|
113
|
+
* @returns New component with combined token statistics
|
|
114
|
+
*/
|
|
115
|
+
static plus(a: AutoBeTokenUsageComponent, b: AutoBeTokenUsageComponent): AutoBeTokenUsageComponent;
|
|
116
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AutoBeTokenUsageComponent = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Token usage component for individual AI agents in the vibe coding pipeline.
|
|
6
|
+
*
|
|
7
|
+
* Represents detailed token consumption statistics for a specific processing
|
|
8
|
+
* phase (facade, analyze, prisma, interface, test, or realize). This class
|
|
9
|
+
* tracks both input and output token usage with granular breakdowns, enabling
|
|
10
|
+
* precise cost analysis and performance optimization for each agent.
|
|
11
|
+
*
|
|
12
|
+
* The component structure includes:
|
|
13
|
+
*
|
|
14
|
+
* - Total token count for quick cost calculations
|
|
15
|
+
* - Input token breakdown with cache efficiency metrics
|
|
16
|
+
* - Output token categorization by generation type
|
|
17
|
+
*
|
|
18
|
+
* This granular tracking helps identify optimization opportunities and
|
|
19
|
+
* understand the computational characteristics of each agent phase.
|
|
20
|
+
*
|
|
21
|
+
* @author SunRabbit123
|
|
22
|
+
*/
|
|
23
|
+
class AutoBeTokenUsageComponent {
|
|
24
|
+
/**
|
|
25
|
+
* Total token count combining all input and output tokens.
|
|
26
|
+
*
|
|
27
|
+
* Represents the complete token consumption for this component, providing a
|
|
28
|
+
* single metric for overall resource utilization. This value is critical for
|
|
29
|
+
* cost calculations and comparing efficiency across different agents or
|
|
30
|
+
* processing phases.
|
|
31
|
+
*/
|
|
32
|
+
get total() {
|
|
33
|
+
return this.input.total + this.output.total;
|
|
34
|
+
}
|
|
35
|
+
constructor(props) {
|
|
36
|
+
if (props === undefined) {
|
|
37
|
+
this.input = { total: 0, cached: 0 };
|
|
38
|
+
this.output = {
|
|
39
|
+
total: 0,
|
|
40
|
+
reasoning: 0,
|
|
41
|
+
accepted_prediction: 0,
|
|
42
|
+
rejected_prediction: 0,
|
|
43
|
+
};
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this.input = props.input;
|
|
47
|
+
this.output = props.output;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Export token usage data as JSON.
|
|
51
|
+
*
|
|
52
|
+
* Converts the component's token usage statistics to the standardized
|
|
53
|
+
* IAutoBeTokenUsageJson.IComponent format. This serialization maintains the
|
|
54
|
+
* complete structure including total counts and detailed breakdowns for both
|
|
55
|
+
* input and output tokens.
|
|
56
|
+
*
|
|
57
|
+
* @returns JSON representation of the token usage component
|
|
58
|
+
*/
|
|
59
|
+
toJSON() {
|
|
60
|
+
return {
|
|
61
|
+
total: this.total,
|
|
62
|
+
input: this.input,
|
|
63
|
+
output: this.output,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/* -----------------------------------------------------------
|
|
67
|
+
OPERATORS
|
|
68
|
+
----------------------------------------------------------- */
|
|
69
|
+
/**
|
|
70
|
+
* Add token usage data to current statistics.
|
|
71
|
+
*
|
|
72
|
+
* Increments all token counters in this component by the corresponding values
|
|
73
|
+
* from the provided component data. This method performs in-place updates,
|
|
74
|
+
* modifying the current instance rather than creating a new one.
|
|
75
|
+
*
|
|
76
|
+
* Updates include:
|
|
77
|
+
*
|
|
78
|
+
* - Total token count
|
|
79
|
+
* - Input tokens (both total and cached)
|
|
80
|
+
* - Output tokens (reasoning, accepted/rejected predictions)
|
|
81
|
+
*
|
|
82
|
+
* @param props - Token usage component data to add to current values
|
|
83
|
+
*/
|
|
84
|
+
increment(props) {
|
|
85
|
+
this.input.total += props.input.total;
|
|
86
|
+
this.input.cached += props.input.cached;
|
|
87
|
+
this.output.total += props.output.total;
|
|
88
|
+
this.output.reasoning += props.output.reasoning;
|
|
89
|
+
this.output.accepted_prediction += props.output.accepted_prediction;
|
|
90
|
+
this.output.rejected_prediction += props.output.rejected_prediction;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Create new component combining two token usage statistics.
|
|
94
|
+
*
|
|
95
|
+
* Performs element-wise addition of all token counters from two components,
|
|
96
|
+
* creating a new AutoBeTokenUsageComponent instance with the combined totals.
|
|
97
|
+
* This static method is useful for aggregating token usage across multiple
|
|
98
|
+
* agent invocations or combining statistics from parallel processing.
|
|
99
|
+
*
|
|
100
|
+
* @param a - First token usage component
|
|
101
|
+
* @param b - Second token usage component
|
|
102
|
+
* @returns New component with combined token statistics
|
|
103
|
+
*/
|
|
104
|
+
static plus(a, b) {
|
|
105
|
+
return new AutoBeTokenUsageComponent({
|
|
106
|
+
input: {
|
|
107
|
+
total: a.input.total + b.input.total,
|
|
108
|
+
cached: a.input.cached + b.input.cached,
|
|
109
|
+
},
|
|
110
|
+
output: {
|
|
111
|
+
total: a.output.total + b.output.total,
|
|
112
|
+
reasoning: a.output.reasoning + b.output.reasoning,
|
|
113
|
+
accepted_prediction: a.output.accepted_prediction + b.output.accepted_prediction,
|
|
114
|
+
rejected_prediction: a.output.rejected_prediction + b.output.rejected_prediction,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.AutoBeTokenUsageComponent = AutoBeTokenUsageComponent;
|
|
120
|
+
//# sourceMappingURL=AutoBeTokenUsageComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoBeTokenUsageComponent.js","sourceRoot":"","sources":["../../src/context/AutoBeTokenUsageComponent.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,yBAAyB;IA+BpC;;;;;;;OAOG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;IAC9C,CAAC;IA0BD,YAAmB,KAAuD;QACxE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,IAAI,CAAC,KAAK,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC,MAAM,GAAG;gBACZ,KAAK,EAAE,CAAC;gBACR,SAAS,EAAE,CAAC;gBACZ,mBAAmB,EAAE,CAAC;gBACtB,mBAAmB,EAAE,CAAC;aACvB,CAAC;YACF,OAAO;QACT,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED;;;;;;;;;OASG;IACI,MAAM;QACX,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;IAED;;kEAE8D;IAC9D;;;;;;;;;;;;;;OAcG;IACI,SAAS,CAAC,KAAuC;QACtD,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,KA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|
};
|
|
81
81
|
}),
|
|
82
82
|
prisma: (next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
-
const r = yield (0, orchestratePrisma_1.orchestratePrisma)(props.context
|
|
83
|
+
const r = yield (0, orchestratePrisma_1.orchestratePrisma)(props.context, next);
|
|
84
84
|
if (r.type === "prisma")
|
|
85
85
|
return {
|
|
86
86
|
type: r.compiled.type,
|