Class AgentCostTotalQueryResultMapper
java.lang.Object
com.flowable.platform.service.dashboard.resultmapper.extractor.AgentCostTotalQueryResultMapper
- All Implemented Interfaces:
DashboardComponentQueryResultMapper
public class AgentCostTotalQueryResultMapper
extends Object
implements DashboardComponentQueryResultMapper
Computes the single total cost across all LLM models by combining the input/output/cached token sums from the
_flowable_AgentInvocationTokensByModelByTypeQuery query result with the model prices stored in the
configuration store for the tenant. The per-model costs are summed into one value.
Reads the same three groupByNestedFieldFilteredWithSumField aggregations as
AgentCostByModelQueryResultMapper (inputTokens, outputTokens, cachedTokens) and
applies the same per-1,000,000-tokens cost arithmetic with longest-prefix model matching. Models with no matching
price are skipped. Returns a SingleValueDashboardComponentData with the total cost.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classprotected static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AgentModelPricingServiceprotected static final Stringprotected static final Stringprotected static final Stringprotected static final BigDecimalstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionAgentCostTotalQueryResultMapper(AgentModelPricingService agentModelPricingService) -
Method Summary
Modifier and TypeMethodDescriptionprotected static BigDecimalcomputeCost(double inputTokens, double outputTokens, double cachedTokens, AgentModelPrice price) Computes the cost for a single model.protected static BigDecimalcostFor(double tokens, BigDecimal pricePerUnit) getType()map(DashboardComponentDefinitionModel dashboardComponentDefinitionModel, Map<String, tools.jackson.databind.JsonNode> queryPayload, tools.jackson.databind.JsonNode queryResult) map(DashboardComponentDefinitionModel dashboardComponentDefinitionModel, Map<String, tools.jackson.databind.JsonNode> queryPayload, tools.jackson.databind.JsonNode queryResult, String tenantId) protected static AgentModelPricematchPrice(String model, List<AgentModelPrice> prices) Returns the price whosemodelPrefixis the longest prefix of the given model name, ornullwhen no configured prefix matches.protected voidreadSummedTokens(tools.jackson.databind.JsonNode queryResult, String aggregationName, Map<String, AgentCostTotalQueryResultMapper.ModelTokens> tokensByModel, AgentCostTotalQueryResultMapper.TokenAssigner assigner) Reads the summed token count per model for the given nested-filtered aggregation and applies it to the accumulatedAgentCostTotalQueryResultMapper.ModelTokensfor that model.
-
Field Details
-
TYPE
- See Also:
-
TOKENS_PER_PRICE_UNIT
-
INPUT_TOKENS_AGGREGATION
- See Also:
-
OUTPUT_TOKENS_AGGREGATION
- See Also:
-
CACHED_TOKENS_AGGREGATION
- See Also:
-
agentModelPricingService
-
-
Constructor Details
-
AgentCostTotalQueryResultMapper
-
-
Method Details
-
getType
- Specified by:
getTypein interfaceDashboardComponentQueryResultMapper
-
map
public DashboardComponentData map(DashboardComponentDefinitionModel dashboardComponentDefinitionModel, Map<String, tools.jackson.databind.JsonNode> queryPayload, tools.jackson.databind.JsonNode queryResult) - Specified by:
mapin interfaceDashboardComponentQueryResultMapper
-
map
public DashboardComponentData map(DashboardComponentDefinitionModel dashboardComponentDefinitionModel, Map<String, tools.jackson.databind.JsonNode> queryPayload, tools.jackson.databind.JsonNode queryResult, String tenantId) - Specified by:
mapin interfaceDashboardComponentQueryResultMapper
-
readSummedTokens
protected void readSummedTokens(tools.jackson.databind.JsonNode queryResult, String aggregationName, Map<String, AgentCostTotalQueryResultMapper.ModelTokens> tokensByModel, AgentCostTotalQueryResultMapper.TokenAssigner assigner) Reads the summed token count per model for the given nested-filtered aggregation and applies it to the accumulatedAgentCostTotalQueryResultMapper.ModelTokensfor that model. MirrorsgroupByNestedFieldFilteredWithSumField's result structure. -
computeCost
protected static BigDecimal computeCost(double inputTokens, double outputTokens, double cachedTokens, AgentModelPrice price) Computes the cost for a single model. Each token type is priced per 1,000,000 tokens; a null price for a token type contributes zero. -
costFor
-
matchPrice
Returns the price whosemodelPrefixis the longest prefix of the given model name, ornullwhen no configured prefix matches.
-