feat: add billing expression system documentation and enhance tiered billing logic

- Introduced a new rule for the Billing Expression System, emphasizing the importance of reading `pkg/billingexpr/expr.md` for dynamic billing.
- Updated the billing expression logic to support new variables and improved handling of image and audio tokens.
- Enhanced the tiered billing functionality with versioning support for expressions and refined quota calculations.
- Added tests to validate the new billing expression features and ensure correctness in pricing calculations.
This commit is contained in:
CaIon
2026-03-17 15:29:43 +08:00
parent 5b03b39db2
commit c5405b2a12
27 changed files with 894 additions and 578 deletions
@@ -646,8 +646,8 @@ export function useModelPricingEditorState({
ImageRatio: parseOptionJSON(options.ImageRatio),
AudioRatio: parseOptionJSON(options.AudioRatio),
AudioCompletionRatio: parseOptionJSON(options.AudioCompletionRatio),
ModelBillingMode: parseOptionJSON(options.ModelBillingMode),
ModelBillingExpr: parseOptionJSON(options.ModelBillingExpr),
ModelBillingMode: parseOptionJSON(options['billing_setting.billing_mode']),
ModelBillingExpr: parseOptionJSON(options['billing_setting.billing_expr']),
};
const names = new Set([
@@ -1035,19 +1035,19 @@ export function useModelPricingEditorState({
};
const tieredOutput = {
ModelBillingMode: {},
ModelBillingExpr: {},
'billing_setting.billing_mode': {},
'billing_setting.billing_expr': {},
};
for (const model of models) {
if (model.billingMode === 'tiered_expr') {
tieredOutput.ModelBillingMode[model.name] = 'tiered_expr';
tieredOutput['billing_setting.billing_mode'][model.name] = 'tiered_expr';
const finalBillingExpr = combineBillingExpr(
model.billingExpr,
model.requestRuleExpr,
);
if (finalBillingExpr) {
tieredOutput.ModelBillingExpr[model.name] = finalBillingExpr;
tieredOutput['billing_setting.billing_expr'][model.name] = finalBillingExpr;
}
}
if (model.billingMode === 'tiered_expr') {