Class AgentCostByDateQueryResultMapper
java.lang.Object
com.flowable.platform.service.dashboard.resultmapper.extractor.AgentCostByDateQueryResultMapper
- All Implemented Interfaces:
DashboardComponentQueryResultMapper
public class AgentCostByDateQueryResultMapper
extends Object
implements DashboardComponentQueryResultMapper
Computes the total LLM cost per time bucket (a time series for a line chart) by combining per-bucket, per-model
token sums with the configured model prices for the tenant.
The dashboard query framework cannot express a single aggregation that groups by both date and model, so this
mapper does not use the (single) query result it is given. Instead it resolves the dashboard's date range from the
input parameters and delegates to AgentCostTokenService, which already buckets the range by day/week/month
and runs the per-model token query once per bucket (the same logic that powers the Control agent timeline). The
per-bucket per-model token sums are then priced here.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AgentCostTokenServiceprotected final AgentModelPricingServiceprotected final StandardDataQueryInputValuesTransformerprotected static final BigDecimalstatic final Stringprotected static final Stringprotected static final String -
Constructor Summary
ConstructorsConstructorDescriptionAgentCostByDateQueryResultMapper(AgentModelPricingService agentModelPricingService, AgentCostTokenService agentCostTokenService, StandardDataQueryInputValuesTransformer inputValuesTransformer) -
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.resolveAgentDefinitionKeys(Map<String, tools.jackson.databind.JsonNode> queryPayload) Resolves the optional agent definition filter from the query payload (an array of{ "key": ... }refs).resolveDateRange(Map<String, tools.jackson.databind.JsonNode> queryPayload) Resolves the date range from the query payload.
-
Field Details
-
TYPE
- See Also:
-
TOKENS_PER_PRICE_UNIT
-
TYPE_ABSOLUTE
- See Also:
-
TYPE_RELATIVE
- See Also:
-
agentModelPricingService
-
agentCostTokenService
-
inputValuesTransformer
-
-
Constructor Details
-
AgentCostByDateQueryResultMapper
public AgentCostByDateQueryResultMapper(AgentModelPricingService agentModelPricingService, AgentCostTokenService agentCostTokenService, StandardDataQueryInputValuesTransformer inputValuesTransformer)
-
-
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
-
resolveDateRange
protected StandardDataQueryPayloadValues.DateRangeValue resolveDateRange(Map<String, tools.jackson.databind.JsonNode> queryPayload) Resolves the date range from the query payload. The payload is keyed by query parameter name, so this finds the first value shaped like a date-range filter (anabsoluteorrelativetype) and resolves it with the shared transformer (start and end are carried by the same range object). -
resolveAgentDefinitionKeys
-
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.
-