kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
27ef5754b3
commit
a620de2002
|
@ -1,4 +1,4 @@
|
||||||
{
|
{
|
||||||
"name": "My Project",
|
"name": "test-basic-raw-free-json",
|
||||||
"originUrl": "https://jsonplaceholder.typicode.com"
|
"originUrl": "https://jsonplaceholder.typicode.com"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { defineConfig } from '@agentic/platform-schemas'
|
import { defineConfig } from '@agentic/platform-schemas'
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
name: 'My Project',
|
name: 'test-basic-raw-free-ts',
|
||||||
originUrl: 'https://jsonplaceholder.typicode.com'
|
originUrl: 'https://jsonplaceholder.typicode.com'
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { defaultFreePricingPlan, defineConfig } from '@agentic/platform-schemas'
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
// TODO: resolve name / slug conflicts
|
// TODO: resolve name / slug conflicts
|
||||||
name: 'My Project',
|
name: 'test-pricing-freemium',
|
||||||
originUrl: 'https://httpbin.org',
|
originUrl: 'https://httpbin.org',
|
||||||
pricingPlans: [
|
pricingPlans: [
|
||||||
defaultFreePricingPlan,
|
defaultFreePricingPlan,
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
exports[`loadAgenticConfig > basic-raw-free-json 1`] = `
|
exports[`loadAgenticConfig > basic-raw-free-json 1`] = `
|
||||||
{
|
{
|
||||||
"name": "My Project",
|
"name": "test-basic-raw-free-json",
|
||||||
"originAdapter": {
|
"originAdapter": {
|
||||||
"location": "external",
|
"location": "external",
|
||||||
"type": "raw",
|
"type": "raw",
|
||||||
|
@ -29,7 +29,7 @@ exports[`loadAgenticConfig > basic-raw-free-json 1`] = `
|
||||||
|
|
||||||
exports[`loadAgenticConfig > basic-raw-free-ts 1`] = `
|
exports[`loadAgenticConfig > basic-raw-free-ts 1`] = `
|
||||||
{
|
{
|
||||||
"name": "My Project",
|
"name": "test-basic-raw-free-ts",
|
||||||
"originAdapter": {
|
"originAdapter": {
|
||||||
"location": "external",
|
"location": "external",
|
||||||
"type": "raw",
|
"type": "raw",
|
||||||
|
@ -56,7 +56,7 @@ exports[`loadAgenticConfig > basic-raw-free-ts 1`] = `
|
||||||
|
|
||||||
exports[`loadAgenticConfig > pricing-freemium 1`] = `
|
exports[`loadAgenticConfig > pricing-freemium 1`] = `
|
||||||
{
|
{
|
||||||
"name": "My Project",
|
"name": "test-pricing-freemium",
|
||||||
"originAdapter": {
|
"originAdapter": {
|
||||||
"location": "external",
|
"location": "external",
|
||||||
"type": "raw",
|
"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",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
|
@ -8,7 +8,8 @@ import { loadAgenticConfig } from './load-agentic-config'
|
||||||
const fixtures = [
|
const fixtures = [
|
||||||
'basic-raw-free-ts',
|
'basic-raw-free-ts',
|
||||||
'basic-raw-free-json',
|
'basic-raw-free-json',
|
||||||
'pricing-freemium'
|
'pricing-freemium',
|
||||||
|
'pricing-pay-as-you-go'
|
||||||
]
|
]
|
||||||
|
|
||||||
const fixturesDir = path.join(
|
const fixturesDir = path.join(
|
||||||
|
|
|
@ -198,7 +198,6 @@ export async function validateAgenticConfig(
|
||||||
400,
|
400,
|
||||||
`Invalid pricingPlan "${pricingPlan.slug}": metered LineItem "${lineItem.slug}" must not specify "tiers" when using "per_unit" billing scheme.`
|
`Invalid pricingPlan "${pricingPlan.slug}": metered LineItem "${lineItem.slug}" must not specify "tiers" when using "per_unit" billing scheme.`
|
||||||
)
|
)
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
case 'tiered':
|
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.`
|
`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(
|
assert(
|
||||||
lineItem.transformQuantity === undefined,
|
lineItem.transformQuantity === undefined,
|
||||||
400,
|
400,
|
||||||
`Invalid pricingPlan "${pricingPlan.slug}": metered LineItem "${lineItem.slug}" must not specify "transformQuantity" when using "tiered" billing scheme.`
|
`Invalid pricingPlan "${pricingPlan.slug}": metered LineItem "${lineItem.slug}" must not specify "transformQuantity" when using "tiered" billing scheme.`
|
||||||
)
|
)
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -189,8 +189,7 @@ export const pricingPlanLineItemSchema = z
|
||||||
* `unitAmount`) will be charged per unit of total usage.
|
* `unitAmount`) will be charged per unit of total usage.
|
||||||
*
|
*
|
||||||
* `tiered` indicates that the unit pricing will be computed using a
|
* `tiered` indicates that the unit pricing will be computed using a
|
||||||
* tiering strategy as defined using the `tiers` and `tiersMode`
|
* tiering strategy as defined using `tiers` and `tiersMode`.
|
||||||
* attributes.
|
|
||||||
*/
|
*/
|
||||||
billingScheme: z.union([z.literal('per_unit'), z.literal('tiered')]),
|
billingScheme: z.union([z.literal('per_unit'), z.literal('tiered')]),
|
||||||
|
|
||||||
|
@ -206,9 +205,24 @@ export const pricingPlanLineItemSchema = z
|
||||||
unitAmount: z.number().nonnegative().optional(),
|
unitAmount: z.number().nonnegative().optional(),
|
||||||
|
|
||||||
// Only applicable for `tiered` billing schemes
|
// 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
|
tiersMode: z
|
||||||
.union([z.literal('graduated'), z.literal('volume')])
|
.union([z.literal('graduated'), z.literal('volume')])
|
||||||
.optional(),
|
.optional(),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pricing tiers for `tiered` billing schemes.
|
||||||
|
*
|
||||||
|
* This field requires `billingScheme` to be set to `tiered`.
|
||||||
|
*/
|
||||||
tiers: z.array(pricingPlanTierSchema).optional(),
|
tiers: z.array(pricingPlanTierSchema).optional(),
|
||||||
|
|
||||||
// TODO: add support for tiered rate limits?
|
// TODO: add support for tiered rate limits?
|
||||||
|
|
Ładowanie…
Reference in New Issue