pull/715/head
Travis Fischer 2025-05-25 23:22:11 +07:00
rodzic 27ef5754b3
commit a620de2002
8 zmienionych plików z 145 dodań i 11 usunięć

Wyświetl plik

@ -1,4 +1,4 @@
{
"name": "My Project",
"name": "test-basic-raw-free-json",
"originUrl": "https://jsonplaceholder.typicode.com"
}

Wyświetl plik

@ -1,6 +1,6 @@
import { defineConfig } from '@agentic/platform-schemas'
export default defineConfig({
name: 'My Project',
name: 'test-basic-raw-free-ts',
originUrl: 'https://jsonplaceholder.typicode.com'
})

Wyświetl plik

@ -2,7 +2,7 @@ import { defaultFreePricingPlan, defineConfig } from '@agentic/platform-schemas'
export default defineConfig({
// TODO: resolve name / slug conflicts
name: 'My Project',
name: 'test-pricing-freemium',
originUrl: 'https://httpbin.org',
pricingPlans: [
defaultFreePricingPlan,

Wyświetl plik

@ -0,0 +1,54 @@
import { defineConfig } from '@agentic/platform-schemas'
export default defineConfig({
name: 'test-pricing-pay-as-you-go',
originUrl: 'https://httpbin.org',
pricingPlans: [
{
name: 'Free',
slug: 'free',
lineItems: [
{
slug: 'base',
usageType: 'licensed',
amount: 0
},
{
slug: 'requests',
usageType: 'metered',
billingScheme: 'per_unit',
unitAmount: 0,
// Free but limited to 20 requests per day
rateLimit: {
maxPerInterval: 20,
interval: 60 * 60 * 24 // 1 day in seconds
}
}
]
},
{
name: 'Pay-As-You-Go',
slug: 'pay-as-you-go',
lineItems: [
{
slug: 'requests',
usageType: 'metered',
billingScheme: 'tiered',
tiersMode: 'volume',
// $0.00467 USD per request up to 999 requests per month
// then $0.00053 USD for unlimited further requests that month
tiers: [
{
upTo: 999,
unitAmount: 0.467
},
{
upTo: 'inf',
unitAmount: 0.053
}
]
}
]
}
]
})

Wyświetl plik

@ -2,7 +2,7 @@
exports[`loadAgenticConfig > basic-raw-free-json 1`] = `
{
"name": "My Project",
"name": "test-basic-raw-free-json",
"originAdapter": {
"location": "external",
"type": "raw",
@ -29,7 +29,7 @@ exports[`loadAgenticConfig > basic-raw-free-json 1`] = `
exports[`loadAgenticConfig > basic-raw-free-ts 1`] = `
{
"name": "My Project",
"name": "test-basic-raw-free-ts",
"originAdapter": {
"location": "external",
"type": "raw",
@ -56,7 +56,7 @@ exports[`loadAgenticConfig > basic-raw-free-ts 1`] = `
exports[`loadAgenticConfig > pricing-freemium 1`] = `
{
"name": "My Project",
"name": "test-pricing-freemium",
"originAdapter": {
"location": "external",
"type": "raw",
@ -94,3 +94,64 @@ exports[`loadAgenticConfig > pricing-freemium 1`] = `
],
}
`;
exports[`loadAgenticConfig > pricing-pay-as-you-go 1`] = `
{
"name": "test-pricing-pay-as-you-go",
"originAdapter": {
"location": "external",
"type": "raw",
},
"originUrl": "https://httpbin.org",
"pricingIntervals": [
"month",
],
"pricingPlans": [
{
"lineItems": [
{
"amount": 0,
"slug": "base",
"usageType": "licensed",
},
{
"billingScheme": "per_unit",
"rateLimit": {
"interval": 86400,
"maxPerInterval": 20,
},
"slug": "requests",
"unitAmount": 0,
"usageType": "metered",
},
],
"name": "Free",
"slug": "free",
},
{
"interval": "month",
"lineItems": [
{
"billingScheme": "tiered",
"interval": "month",
"slug": "requests",
"tiers": [
{
"unitAmount": 0.467,
"upTo": 999,
},
{
"unitAmount": 0.053,
"upTo": "inf",
},
],
"tiersMode": "volume",
"usageType": "metered",
},
],
"name": "Pay-As-You-Go",
"slug": "pay-as-you-go",
},
],
}
`;

Wyświetl plik

@ -8,7 +8,8 @@ import { loadAgenticConfig } from './load-agentic-config'
const fixtures = [
'basic-raw-free-ts',
'basic-raw-free-json',
'pricing-freemium'
'pricing-freemium',
'pricing-pay-as-you-go'
]
const fixturesDir = path.join(

Wyświetl plik

@ -198,7 +198,6 @@ export async function validateAgenticConfig(
400,
`Invalid pricingPlan "${pricingPlan.slug}": metered LineItem "${lineItem.slug}" must not specify "tiers" when using "per_unit" billing scheme.`
)
break
case 'tiered':
@ -214,12 +213,17 @@ export async function validateAgenticConfig(
`Invalid pricingPlan "${pricingPlan.slug}": metered LineItem "${lineItem.slug}" must specify a non-empty "tiers" array when using "tiered" billing scheme.`
)
assert(
lineItem.tiersMode !== undefined,
400,
`Invalid pricingPlan "${pricingPlan.slug}": metered LineItem "${lineItem.slug}" must specify a valid "tiersMode" when using "tiered" billing scheme.`
)
assert(
lineItem.transformQuantity === undefined,
400,
`Invalid pricingPlan "${pricingPlan.slug}": metered LineItem "${lineItem.slug}" must not specify "transformQuantity" when using "tiered" billing scheme.`
)
break
default:

Wyświetl plik

@ -189,8 +189,7 @@ export const pricingPlanLineItemSchema = z
* `unitAmount`) will be charged per unit of total usage.
*
* `tiered` indicates that the unit pricing will be computed using a
* tiering strategy as defined using the `tiers` and `tiersMode`
* attributes.
* tiering strategy as defined using `tiers` and `tiersMode`.
*/
billingScheme: z.union([z.literal('per_unit'), z.literal('tiered')]),
@ -206,9 +205,24 @@ export const pricingPlanLineItemSchema = z
unitAmount: z.number().nonnegative().optional(),
// Only applicable for `tiered` billing schemes
/**
* Defines if the tiering price should be `graduated` or `volume` based.
* In `volume`-based tiering, the maximum quantity within a period
* determines the per unit price, in `graduated` tiering pricing can
* successively change as the quantity grows.
*
* This field requires `billingScheme` to be set to `tiered`.
*/
tiersMode: z
.union([z.literal('graduated'), z.literal('volume')])
.optional(),
/**
* Pricing tiers for `tiered` billing schemes.
*
* This field requires `billingScheme` to be set to `tiered`.
*/
tiers: z.array(pricingPlanTierSchema).optional(),
// TODO: add support for tiered rate limits?