terse-types 0.0.27 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ApiRouteBuilder.d.ts +9 -0
- package/dist/ApiRoutes.json +9 -0
- package/dist/Billing.d.ts +20 -54
- package/dist/Billing.js +30 -24
- package/dist/BillingErrors.d.ts +20 -0
- package/dist/BillingErrors.js +39 -0
- package/dist/BillingRoutes.json +0 -1
- package/dist/BillingSchemas.d.ts +72 -0
- package/dist/BillingSchemas.js +59 -0
- package/dist/FrontendRoutes.json +2 -0
- package/dist/FrontendRoutesBuilder.d.ts +2 -0
- package/dist/InvalidationKeys.d.ts +4 -0
- package/dist/InvalidationKeys.js +9 -1
- package/dist/OrganizationMetadata.d.ts +2 -6
- package/dist/OrganizationMetadata.js +7 -3
- package/dist/SandboxTypes.d.ts +15 -0
- package/dist/SandboxTypes.js +1 -0
- package/dist/ToolDisplayUtils.js +0 -9
- package/dist/Tools.d.ts +3 -78
- package/dist/Tools.js +0 -15
- package/dist/TriggerEventPresenters.d.ts +3 -0
- package/dist/TriggerEventPresenters.js +238 -0
- package/dist/TriggerEvents.d.ts +4054 -0
- package/dist/TriggerEvents.js +437 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/json-schema/terse-types.schema.json +1534 -363
- package/dist/types.d.ts +15 -3
- package/dist/types.js +11 -1
- package/package.json +1 -1
|
@@ -126,6 +126,7 @@ export declare const ApiRoutes: {
|
|
|
126
126
|
BY_ID: string;
|
|
127
127
|
};
|
|
128
128
|
PROJECTS: {
|
|
129
|
+
LIST: string;
|
|
129
130
|
BY_ID: string;
|
|
130
131
|
DEPLOYS: string;
|
|
131
132
|
SOURCE_FILES: string;
|
|
@@ -180,5 +181,13 @@ export declare const ApiRoutes: {
|
|
|
180
181
|
CREATE: string;
|
|
181
182
|
BY_ID: string;
|
|
182
183
|
};
|
|
184
|
+
BILLING: {
|
|
185
|
+
CATALOG: string;
|
|
186
|
+
CONTEXT: string;
|
|
187
|
+
CHECKOUT_SESSION: string;
|
|
188
|
+
CHANGE: string;
|
|
189
|
+
PORTAL_SESSION: string;
|
|
190
|
+
CACHE_INVALIDATION: string;
|
|
191
|
+
};
|
|
183
192
|
};
|
|
184
193
|
export declare function buildRoute(pattern: string, params: Record<string, string | number>): string;
|
package/dist/ApiRoutes.json
CHANGED
|
@@ -126,6 +126,7 @@
|
|
|
126
126
|
"BY_ID": "/api-tokens/:id"
|
|
127
127
|
},
|
|
128
128
|
"PROJECTS": {
|
|
129
|
+
"LIST": "/projects",
|
|
129
130
|
"BY_ID": "/projects/:id",
|
|
130
131
|
"DEPLOYS": "/projects/:id/deploys",
|
|
131
132
|
"SOURCE_FILES": "/projects/:id/source/files",
|
|
@@ -179,5 +180,13 @@
|
|
|
179
180
|
"USERS": {
|
|
180
181
|
"CREATE": "/users",
|
|
181
182
|
"BY_ID": "/users/:id"
|
|
183
|
+
},
|
|
184
|
+
"BILLING": {
|
|
185
|
+
"CATALOG": "/billing/catalog",
|
|
186
|
+
"CONTEXT": "/billing/context",
|
|
187
|
+
"CHECKOUT_SESSION": "/billing/checkout-session",
|
|
188
|
+
"CHANGE": "/billing/change",
|
|
189
|
+
"PORTAL_SESSION": "/billing/portal-session",
|
|
190
|
+
"CACHE_INVALIDATION": "/billing/cache-invalidation"
|
|
182
191
|
}
|
|
183
192
|
}
|
package/dist/Billing.d.ts
CHANGED
|
@@ -19,13 +19,6 @@ export declare const envIdSchema: z.ZodObject<{
|
|
|
19
19
|
test: z.ZodString;
|
|
20
20
|
}, z.core.$strip>;
|
|
21
21
|
export type EnvId = z.infer<typeof envIdSchema>;
|
|
22
|
-
export declare const overageModeSchema: z.ZodEnum<{
|
|
23
|
-
soft: "soft";
|
|
24
|
-
strict: "strict";
|
|
25
|
-
}>;
|
|
26
|
-
export type OverageMode = z.infer<typeof overageModeSchema>;
|
|
27
|
-
export declare const DEFAULT_OVERAGE_CAP_MULTIPLIER = 2;
|
|
28
|
-
export declare const DEFAULT_OVERAGE_MODE: OverageMode;
|
|
29
22
|
export declare const billingScheduledChangeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
30
23
|
kind: z.ZodLiteral<"cancel_to_free">;
|
|
31
24
|
effectiveAt: z.ZodCoercedDate<unknown>;
|
|
@@ -44,10 +37,6 @@ export declare const balanceSummarySchema: z.ZodObject<{
|
|
|
44
37
|
totalCreditCapacity: z.ZodNumber;
|
|
45
38
|
periodStart: z.ZodCoercedDate<unknown>;
|
|
46
39
|
periodEnd: z.ZodCoercedDate<unknown>;
|
|
47
|
-
overageMode: z.ZodEnum<{
|
|
48
|
-
soft: "soft";
|
|
49
|
-
strict: "strict";
|
|
50
|
-
}>;
|
|
51
40
|
hardCap: z.ZodNumber;
|
|
52
41
|
canBuyTopups: z.ZodBoolean;
|
|
53
42
|
scheduledChange: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -63,14 +52,20 @@ export type BalanceSummary = z.infer<typeof balanceSummarySchema>;
|
|
|
63
52
|
export declare const usageBucketSchema: z.ZodObject<{
|
|
64
53
|
startTimestamp: z.ZodNumber;
|
|
65
54
|
endTimestamp: z.ZodNumber;
|
|
66
|
-
|
|
55
|
+
inputTokenCredits: z.ZodNumber;
|
|
56
|
+
outputTokenCredits: z.ZodNumber;
|
|
57
|
+
cachedInputCredits: z.ZodNumber;
|
|
58
|
+
runCredits: z.ZodNumber;
|
|
67
59
|
}, z.core.$strip>;
|
|
68
60
|
export type UsageBucket = z.infer<typeof usageBucketSchema>;
|
|
69
61
|
export declare const usageResponseSchema: z.ZodObject<{
|
|
70
62
|
buckets: z.ZodArray<z.ZodObject<{
|
|
71
63
|
startTimestamp: z.ZodNumber;
|
|
72
64
|
endTimestamp: z.ZodNumber;
|
|
73
|
-
|
|
65
|
+
inputTokenCredits: z.ZodNumber;
|
|
66
|
+
outputTokenCredits: z.ZodNumber;
|
|
67
|
+
cachedInputCredits: z.ZodNumber;
|
|
68
|
+
runCredits: z.ZodNumber;
|
|
74
69
|
}, z.core.$strip>>;
|
|
75
70
|
}, z.core.$strip>;
|
|
76
71
|
export type UsageResponse = z.infer<typeof usageResponseSchema>;
|
|
@@ -85,10 +80,6 @@ export declare const billingContextResponseSchema: z.ZodObject<{
|
|
|
85
80
|
totalCreditCapacity: z.ZodNumber;
|
|
86
81
|
periodStart: z.ZodCoercedDate<unknown>;
|
|
87
82
|
periodEnd: z.ZodCoercedDate<unknown>;
|
|
88
|
-
overageMode: z.ZodEnum<{
|
|
89
|
-
soft: "soft";
|
|
90
|
-
strict: "strict";
|
|
91
|
-
}>;
|
|
92
83
|
hardCap: z.ZodNumber;
|
|
93
84
|
canBuyTopups: z.ZodBoolean;
|
|
94
85
|
scheduledChange: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -104,7 +95,10 @@ export declare const billingContextResponseSchema: z.ZodObject<{
|
|
|
104
95
|
buckets: z.ZodArray<z.ZodObject<{
|
|
105
96
|
startTimestamp: z.ZodNumber;
|
|
106
97
|
endTimestamp: z.ZodNumber;
|
|
107
|
-
|
|
98
|
+
inputTokenCredits: z.ZodNumber;
|
|
99
|
+
outputTokenCredits: z.ZodNumber;
|
|
100
|
+
cachedInputCredits: z.ZodNumber;
|
|
101
|
+
runCredits: z.ZodNumber;
|
|
108
102
|
}, z.core.$strip>>;
|
|
109
103
|
}, z.core.$strip>;
|
|
110
104
|
}, z.core.$strip>;
|
|
@@ -120,17 +114,18 @@ export declare const completedEventUsageSchema: z.ZodObject<{
|
|
|
120
114
|
export type CompletedEventUsage = z.infer<typeof completedEventUsageSchema>;
|
|
121
115
|
export declare const billingRunGateRequestBodySchema: z.ZodObject<{
|
|
122
116
|
organizationId: z.ZodString;
|
|
117
|
+
breakCache: z.ZodDefault<z.ZodBoolean>;
|
|
123
118
|
}, z.core.$strip>;
|
|
124
119
|
export type BillingRunGateRequestBody = z.infer<typeof billingRunGateRequestBodySchema>;
|
|
125
120
|
export declare const billingChargeRunBaseBodySchema: z.ZodObject<{
|
|
126
121
|
organizationId: z.ZodString;
|
|
122
|
+
breakCache: z.ZodDefault<z.ZodBoolean>;
|
|
127
123
|
runId: z.ZodString;
|
|
128
124
|
}, z.core.$strip>;
|
|
129
125
|
export type BillingChargeRunBaseBody = z.infer<typeof billingChargeRunBaseBodySchema>;
|
|
130
126
|
/** Acknowledgement from POST /billing/charge-run-base (credits debited for starting a run). */
|
|
131
127
|
export declare const billingChargeRunBaseResponseSchema: z.ZodObject<{
|
|
132
128
|
runId: z.ZodString;
|
|
133
|
-
creditsCharged: z.ZodNumber;
|
|
134
129
|
}, z.core.$strip>;
|
|
135
130
|
export type BillingChargeRunBaseResponse = z.infer<typeof billingChargeRunBaseResponseSchema>;
|
|
136
131
|
export declare const billingRecordLlmBodySchema: z.ZodObject<{
|
|
@@ -158,7 +153,6 @@ export type BillingRecordLlmBody = z.infer<typeof billingRecordLlmBodySchema>;
|
|
|
158
153
|
/** Acknowledgement from POST /billing/record-llm (credits debited for model usage). */
|
|
159
154
|
export declare const billingRecordLlmResponseSchema: z.ZodObject<{
|
|
160
155
|
responseId: z.ZodString;
|
|
161
|
-
creditsCharged: z.ZodNumber;
|
|
162
156
|
}, z.core.$strip>;
|
|
163
157
|
export type BillingRecordLlmResponse = z.infer<typeof billingRecordLlmResponseSchema>;
|
|
164
158
|
export declare const billingRecordLlmPayloadSchema: z.ZodObject<{
|
|
@@ -221,18 +215,13 @@ export declare const billingChangeRequestBodySchema: z.ZodDiscriminatedUnion<[z.
|
|
|
221
215
|
period: z.ZodEnum<typeof TimePeriods>;
|
|
222
216
|
}, z.core.$strip>], "kind">;
|
|
223
217
|
export type BillingChangeRequestBody = z.infer<typeof billingChangeRequestBodySchema>;
|
|
224
|
-
export declare const billingOverageModePatchBodySchema: z.ZodObject<{
|
|
225
|
-
mode: z.ZodEnum<{
|
|
226
|
-
soft: "soft";
|
|
227
|
-
strict: "strict";
|
|
228
|
-
}>;
|
|
229
|
-
}, z.core.$strip>;
|
|
230
|
-
export type BillingOverageModePatchBody = z.infer<typeof billingOverageModePatchBodySchema>;
|
|
231
218
|
export declare const billingPortalSessionRequestBodySchema: z.ZodObject<{}, z.core.$strict>;
|
|
232
219
|
export type BillingPortalSessionRequestBody = z.infer<typeof billingPortalSessionRequestBodySchema>;
|
|
220
|
+
export declare const DEFAULT_BILLING_CONTEXT_TIMEZONE = "UTC";
|
|
233
221
|
export declare const billingContextQuerySchema: z.ZodObject<{
|
|
234
222
|
start: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
235
223
|
end: z.ZodOptional<z.ZodCoercedDate<unknown>>;
|
|
224
|
+
timezone: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string, string | undefined>>;
|
|
236
225
|
}, z.core.$strip>;
|
|
237
226
|
export type BillingContextQuery = z.infer<typeof billingContextQuerySchema>;
|
|
238
227
|
export declare const getOrCreateCustomerRequestBodySchema: z.ZodObject<{}, z.core.$strict>;
|
|
@@ -301,20 +290,9 @@ export declare const planSchema: z.ZodObject<{
|
|
|
301
290
|
live: z.ZodString;
|
|
302
291
|
test: z.ZodString;
|
|
303
292
|
}, z.core.$strip>>;
|
|
304
|
-
overagePriceId: z.ZodNullable<z.ZodObject<{
|
|
305
|
-
live: z.ZodString;
|
|
306
|
-
test: z.ZodString;
|
|
307
|
-
}, z.core.$strip>>;
|
|
308
293
|
priceInUsdMonthly: z.ZodNullable<z.ZodNumber>;
|
|
309
294
|
priceInUsdMonthlyAnnual: z.ZodNullable<z.ZodNumber>;
|
|
310
295
|
includedCreditsPerMonth: z.ZodNumber;
|
|
311
|
-
markupPct: z.ZodNumber;
|
|
312
|
-
overageCentsPerCredit: z.ZodNumber;
|
|
313
|
-
hardCapMultiplier: z.ZodNumber;
|
|
314
|
-
defaultOverageMode: z.ZodEnum<{
|
|
315
|
-
soft: "soft";
|
|
316
|
-
strict: "strict";
|
|
317
|
-
}>;
|
|
318
296
|
}, z.core.$strip>;
|
|
319
297
|
export type Plan = z.infer<typeof planSchema>;
|
|
320
298
|
export declare function isPurchasablePlan(plan: Plan): boolean;
|
|
@@ -339,20 +317,9 @@ export declare const billingCatalogResponseSchema: z.ZodObject<{
|
|
|
339
317
|
live: z.ZodString;
|
|
340
318
|
test: z.ZodString;
|
|
341
319
|
}, z.core.$strip>>;
|
|
342
|
-
overagePriceId: z.ZodNullable<z.ZodObject<{
|
|
343
|
-
live: z.ZodString;
|
|
344
|
-
test: z.ZodString;
|
|
345
|
-
}, z.core.$strip>>;
|
|
346
320
|
priceInUsdMonthly: z.ZodNullable<z.ZodNumber>;
|
|
347
321
|
priceInUsdMonthlyAnnual: z.ZodNullable<z.ZodNumber>;
|
|
348
322
|
includedCreditsPerMonth: z.ZodNumber;
|
|
349
|
-
markupPct: z.ZodNumber;
|
|
350
|
-
overageCentsPerCredit: z.ZodNumber;
|
|
351
|
-
hardCapMultiplier: z.ZodNumber;
|
|
352
|
-
defaultOverageMode: z.ZodEnum<{
|
|
353
|
-
soft: "soft";
|
|
354
|
-
strict: "strict";
|
|
355
|
-
}>;
|
|
356
323
|
}, z.core.$strip>>;
|
|
357
324
|
topUps: z.ZodArray<z.ZodObject<{
|
|
358
325
|
credits: z.ZodEnum<typeof SupportedTopUps>;
|
|
@@ -378,14 +345,13 @@ export declare const BillingRoutes: {
|
|
|
378
345
|
CHECKOUT_SESSION: string;
|
|
379
346
|
CHANGE: string;
|
|
380
347
|
PORTAL_SESSION: string;
|
|
381
|
-
OVERAGE_MODE: string;
|
|
382
348
|
CUSTOMER: string;
|
|
383
349
|
RUN_GATE: string;
|
|
384
350
|
CHARGE_RUN_BASE: string;
|
|
385
351
|
RECORD_LLM: string;
|
|
386
352
|
CACHE_INVALIDATION: string;
|
|
387
353
|
};
|
|
388
|
-
export type BillingForbiddenErrorType = "CreditGateDeniedError" | "
|
|
354
|
+
export type BillingForbiddenErrorType = "CreditGateDeniedError" | "BillingError";
|
|
389
355
|
export type BillingForbiddenErrorBody = {
|
|
390
356
|
type: BillingForbiddenErrorType;
|
|
391
357
|
reason?: string;
|
|
@@ -394,10 +360,10 @@ export declare class CreditGateDeniedError extends Error {
|
|
|
394
360
|
readonly reason: RunGateDenyReason;
|
|
395
361
|
constructor(reason: RunGateDenyReason);
|
|
396
362
|
}
|
|
397
|
-
export declare class
|
|
363
|
+
export declare class BillingError extends Error {
|
|
398
364
|
readonly reason?: string;
|
|
399
365
|
constructor(message?: string, reason?: string);
|
|
400
366
|
}
|
|
401
|
-
export declare function billingErrorFromForbiddenBody(body: unknown): CreditGateDeniedError |
|
|
367
|
+
export declare function billingErrorFromForbiddenBody(body: unknown): CreditGateDeniedError | BillingError | null;
|
|
402
368
|
/** Parse JSON body from a billing HTTP 403 response */
|
|
403
|
-
export declare function parseBillingForbiddenJson(raw: string): CreditGateDeniedError |
|
|
369
|
+
export declare function parseBillingForbiddenJson(raw: string): CreditGateDeniedError | BillingError | null;
|
package/dist/Billing.js
CHANGED
|
@@ -22,9 +22,6 @@ export const envIdSchema = z.object({
|
|
|
22
22
|
live: z.string(),
|
|
23
23
|
test: z.string()
|
|
24
24
|
});
|
|
25
|
-
export const overageModeSchema = z.enum(["soft", "strict"]);
|
|
26
|
-
export const DEFAULT_OVERAGE_CAP_MULTIPLIER = 2;
|
|
27
|
-
export const DEFAULT_OVERAGE_MODE = "strict";
|
|
28
25
|
export const billingScheduledChangeSchema = z.discriminatedUnion("kind", [
|
|
29
26
|
z.object({
|
|
30
27
|
kind: z.literal("cancel_to_free"),
|
|
@@ -45,7 +42,6 @@ export const balanceSummarySchema = z.object({
|
|
|
45
42
|
totalCreditCapacity: z.number(),
|
|
46
43
|
periodStart: z.coerce.date(),
|
|
47
44
|
periodEnd: z.coerce.date(),
|
|
48
|
-
overageMode: overageModeSchema,
|
|
49
45
|
hardCap: z.number(),
|
|
50
46
|
canBuyTopups: z.boolean(),
|
|
51
47
|
scheduledChange: billingScheduledChangeSchema.nullable()
|
|
@@ -53,7 +49,10 @@ export const balanceSummarySchema = z.object({
|
|
|
53
49
|
export const usageBucketSchema = z.object({
|
|
54
50
|
startTimestamp: z.number(),
|
|
55
51
|
endTimestamp: z.number(),
|
|
56
|
-
|
|
52
|
+
inputTokenCredits: z.number(),
|
|
53
|
+
outputTokenCredits: z.number(),
|
|
54
|
+
cachedInputCredits: z.number(),
|
|
55
|
+
runCredits: z.number()
|
|
57
56
|
});
|
|
58
57
|
export const usageResponseSchema = z.object({
|
|
59
58
|
buckets: z.array(usageBucketSchema)
|
|
@@ -72,15 +71,15 @@ export const completedEventUsageSchema = z.object({
|
|
|
72
71
|
})
|
|
73
72
|
});
|
|
74
73
|
export const billingRunGateRequestBodySchema = z.object({
|
|
75
|
-
organizationId: z.string().min(1)
|
|
74
|
+
organizationId: z.string().min(1),
|
|
75
|
+
breakCache: z.boolean().default(false)
|
|
76
76
|
});
|
|
77
77
|
export const billingChargeRunBaseBodySchema = billingRunGateRequestBodySchema.extend({
|
|
78
78
|
runId: z.string().min(1)
|
|
79
79
|
});
|
|
80
80
|
/** Acknowledgement from POST /billing/charge-run-base (credits debited for starting a run). */
|
|
81
81
|
export const billingChargeRunBaseResponseSchema = z.object({
|
|
82
|
-
runId: z.string().min(1)
|
|
83
|
-
creditsCharged: z.number().nonnegative()
|
|
82
|
+
runId: z.string().min(1)
|
|
84
83
|
});
|
|
85
84
|
export const billingRecordLlmBodySchema = z.object({
|
|
86
85
|
organizationId: z.string().min(1),
|
|
@@ -91,8 +90,7 @@ export const billingRecordLlmBodySchema = z.object({
|
|
|
91
90
|
});
|
|
92
91
|
/** Acknowledgement from POST /billing/record-llm (credits debited for model usage). */
|
|
93
92
|
export const billingRecordLlmResponseSchema = z.object({
|
|
94
|
-
responseId: z.string().min(1)
|
|
95
|
-
creditsCharged: z.number().nonnegative()
|
|
93
|
+
responseId: z.string().min(1)
|
|
96
94
|
});
|
|
97
95
|
export const billingRecordLlmPayloadSchema = billingRecordLlmBodySchema.pick({
|
|
98
96
|
responseId: true,
|
|
@@ -119,13 +117,26 @@ export const billingChangePeriodBodySchema = z.object({
|
|
|
119
117
|
period: billingPeriodSchema
|
|
120
118
|
});
|
|
121
119
|
export const billingChangeRequestBodySchema = z.discriminatedUnion("kind", [billingChangeCancelBodySchema, billingChangePeriodBodySchema]);
|
|
122
|
-
export const billingOverageModePatchBodySchema = z.object({
|
|
123
|
-
mode: overageModeSchema
|
|
124
|
-
});
|
|
125
120
|
export const billingPortalSessionRequestBodySchema = z.object({}).strict();
|
|
121
|
+
export const DEFAULT_BILLING_CONTEXT_TIMEZONE = "UTC";
|
|
122
|
+
function isValidTimezone(timezone) {
|
|
123
|
+
try {
|
|
124
|
+
new Intl.DateTimeFormat("en-US", { timeZone: timezone }).format();
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
126
131
|
export const billingContextQuerySchema = z.object({
|
|
127
132
|
start: z.coerce.date().optional(),
|
|
128
|
-
end: z.coerce.date().optional()
|
|
133
|
+
end: z.coerce.date().optional(),
|
|
134
|
+
timezone: z
|
|
135
|
+
.string()
|
|
136
|
+
.trim()
|
|
137
|
+
.optional()
|
|
138
|
+
.transform(timezone => timezone || DEFAULT_BILLING_CONTEXT_TIMEZONE)
|
|
139
|
+
.refine(isValidTimezone, { message: "Invalid timezone" })
|
|
129
140
|
});
|
|
130
141
|
export const getOrCreateCustomerRequestBodySchema = z.object({}).strict();
|
|
131
142
|
export const billingStripeRedirectResponseSchema = z.object({
|
|
@@ -157,14 +168,9 @@ export const planSchema = z.object({
|
|
|
157
168
|
name: z.string(),
|
|
158
169
|
monthlyBasePriceId: envIdSchema.nullable(),
|
|
159
170
|
annualBasePriceId: envIdSchema.nullable(),
|
|
160
|
-
overagePriceId: envIdSchema.nullable(),
|
|
161
171
|
priceInUsdMonthly: z.number().nullable(),
|
|
162
172
|
priceInUsdMonthlyAnnual: z.number().nullable(),
|
|
163
|
-
includedCreditsPerMonth: z.number()
|
|
164
|
-
markupPct: z.number(),
|
|
165
|
-
overageCentsPerCredit: z.number(),
|
|
166
|
-
hardCapMultiplier: z.number(),
|
|
167
|
-
defaultOverageMode: overageModeSchema
|
|
173
|
+
includedCreditsPerMonth: z.number()
|
|
168
174
|
});
|
|
169
175
|
export function isPurchasablePlan(plan) {
|
|
170
176
|
return !!(plan.monthlyBasePriceId || plan.annualBasePriceId);
|
|
@@ -194,11 +200,11 @@ export class CreditGateDeniedError extends Error {
|
|
|
194
200
|
this.reason = reason;
|
|
195
201
|
}
|
|
196
202
|
}
|
|
197
|
-
export class
|
|
203
|
+
export class BillingError extends Error {
|
|
198
204
|
reason;
|
|
199
205
|
constructor(message, reason) {
|
|
200
206
|
super(message ?? reason ?? "Billing provider error");
|
|
201
|
-
this.name = "
|
|
207
|
+
this.name = "BillingError";
|
|
202
208
|
this.reason = reason;
|
|
203
209
|
}
|
|
204
210
|
}
|
|
@@ -210,9 +216,9 @@ export function billingErrorFromForbiddenBody(body) {
|
|
|
210
216
|
if (t === "CreditGateDeniedError") {
|
|
211
217
|
return new CreditGateDeniedError(parseRunGateDenyReason(o.reason));
|
|
212
218
|
}
|
|
213
|
-
if (t === "
|
|
219
|
+
if (t === "BillingError") {
|
|
214
220
|
const reason = typeof o.reason === "string" ? o.reason : undefined;
|
|
215
|
-
return new
|
|
221
|
+
return new BillingError(reason, reason);
|
|
216
222
|
}
|
|
217
223
|
return null;
|
|
218
224
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type BillingForbiddenErrorType = "CreditGateDeniedError" | "StripeError";
|
|
2
|
+
/**
|
|
3
|
+
* Wire shape other services should return with HTTP 403 for billing/credit denials.
|
|
4
|
+
* `type` may be sent as `errorType` for compatibility.
|
|
5
|
+
*/
|
|
6
|
+
export type BillingForbiddenErrorBody = {
|
|
7
|
+
type: BillingForbiddenErrorType;
|
|
8
|
+
reason?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class CreditGateDeniedError extends Error {
|
|
11
|
+
readonly reason: string;
|
|
12
|
+
constructor(reason: string);
|
|
13
|
+
}
|
|
14
|
+
export declare class StripeError extends Error {
|
|
15
|
+
readonly reason?: string;
|
|
16
|
+
constructor(message?: string, reason?: string);
|
|
17
|
+
}
|
|
18
|
+
export declare function billingErrorFromForbiddenBody(body: unknown): CreditGateDeniedError | StripeError | null;
|
|
19
|
+
/** Parse JSON body from a billing HTTP 403 response */
|
|
20
|
+
export declare function parseBillingForbiddenJson(raw: string): CreditGateDeniedError | StripeError | null;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export class CreditGateDeniedError extends Error {
|
|
2
|
+
reason;
|
|
3
|
+
constructor(reason) {
|
|
4
|
+
super(`Credit gate denied: ${reason}`);
|
|
5
|
+
this.name = "CreditGateDeniedError";
|
|
6
|
+
this.reason = reason;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class StripeError extends Error {
|
|
10
|
+
reason;
|
|
11
|
+
constructor(message, reason) {
|
|
12
|
+
super(message ?? reason ?? "Billing provider error");
|
|
13
|
+
this.name = "StripeError";
|
|
14
|
+
this.reason = reason;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function billingErrorFromForbiddenBody(body) {
|
|
18
|
+
if (!body || typeof body !== "object")
|
|
19
|
+
return null;
|
|
20
|
+
const o = body;
|
|
21
|
+
const t = o.type ?? o.errorType;
|
|
22
|
+
if (t === "CreditGateDeniedError") {
|
|
23
|
+
return new CreditGateDeniedError(typeof o.reason === "string" ? o.reason : "unknown");
|
|
24
|
+
}
|
|
25
|
+
if (t === "StripeError") {
|
|
26
|
+
const reason = typeof o.reason === "string" ? o.reason : undefined;
|
|
27
|
+
return new StripeError(reason, reason);
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
/** Parse JSON body from a billing HTTP 403 response */
|
|
32
|
+
export function parseBillingForbiddenJson(raw) {
|
|
33
|
+
try {
|
|
34
|
+
return billingErrorFromForbiddenBody(JSON.parse(raw));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/BillingRoutes.json
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
"CHECKOUT_SESSION": "/billing/checkout-session",
|
|
5
5
|
"CHANGE": "/billing/change",
|
|
6
6
|
"PORTAL_SESSION": "/billing/portal-session",
|
|
7
|
-
"OVERAGE_MODE": "/billing/overage-mode",
|
|
8
7
|
"CUSTOMER": "/billing/customer",
|
|
9
8
|
"RUN_GATE": "/billing/run-gate",
|
|
10
9
|
"CHARGE_RUN_BASE": "/billing/charge-run-base",
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { PlanKey, SupportedTopUps, TimePeriods } from "./Billing.js";
|
|
3
|
+
/** Matches `CompletedEventUsage` in `Billing.ts`. */
|
|
4
|
+
export declare const completedEventUsageSchema: z.ZodObject<{
|
|
5
|
+
inputTokens: z.ZodNumber;
|
|
6
|
+
outputTokens: z.ZodNumber;
|
|
7
|
+
totalTokens: z.ZodNumber;
|
|
8
|
+
inputTokensDetails: z.ZodObject<{
|
|
9
|
+
cached_tokens: z.ZodNumber;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
/** Matches `BillingRunGateRequestBody`. */
|
|
13
|
+
export declare const billingRunGateRequestBodySchema: z.ZodObject<{
|
|
14
|
+
organizationId: z.ZodString;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
/** Matches `BillingChargeRunBaseBody`. */
|
|
17
|
+
export declare const billingChargeRunBaseBodySchema: z.ZodObject<{
|
|
18
|
+
organizationId: z.ZodString;
|
|
19
|
+
runId: z.ZodString;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
/** Matches `BillingRecordLlmBody`. */
|
|
22
|
+
export declare const billingRecordLlmBodySchema: z.ZodObject<{
|
|
23
|
+
organizationId: z.ZodString;
|
|
24
|
+
runId: z.ZodString;
|
|
25
|
+
responseId: z.ZodString;
|
|
26
|
+
model: z.ZodObject<{
|
|
27
|
+
providerId: z.ZodEnum<{
|
|
28
|
+
anthropic: "anthropic";
|
|
29
|
+
openai: "openai";
|
|
30
|
+
}>;
|
|
31
|
+
modelId: z.ZodString;
|
|
32
|
+
value: z.ZodString;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
usage: z.ZodObject<{
|
|
35
|
+
inputTokens: z.ZodNumber;
|
|
36
|
+
outputTokens: z.ZodNumber;
|
|
37
|
+
totalTokens: z.ZodNumber;
|
|
38
|
+
inputTokensDetails: z.ZodObject<{
|
|
39
|
+
cached_tokens: z.ZodNumber;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
/** Matches `BillingCheckoutRequestBody`. */
|
|
44
|
+
export declare const billingCheckoutRequestBodySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
45
|
+
kind: z.ZodLiteral<"plan">;
|
|
46
|
+
planKey: z.ZodEnum<typeof PlanKey>;
|
|
47
|
+
period: z.ZodEnum<typeof TimePeriods>;
|
|
48
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
49
|
+
kind: z.ZodLiteral<"topup">;
|
|
50
|
+
packCredits: z.ZodEnum<typeof SupportedTopUps>;
|
|
51
|
+
}, z.core.$strip>], "kind">;
|
|
52
|
+
/** Matches `BillingChangeRequestBody`. */
|
|
53
|
+
export declare const billingChangeRequestBodySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
54
|
+
kind: z.ZodLiteral<"cancel_to_free">;
|
|
55
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
56
|
+
kind: z.ZodLiteral<"change_period">;
|
|
57
|
+
planKey: z.ZodEnum<typeof PlanKey>;
|
|
58
|
+
period: z.ZodEnum<typeof TimePeriods>;
|
|
59
|
+
}, z.core.$strip>], "kind">;
|
|
60
|
+
/** Matches `BillingOverageModePatchBody`. */
|
|
61
|
+
export declare const billingOverageModePatchBodySchema: z.ZodObject<{
|
|
62
|
+
mode: z.ZodEnum<{
|
|
63
|
+
soft: "soft";
|
|
64
|
+
strict: "strict";
|
|
65
|
+
}>;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
export declare const billingPortalSessionRequestBodySchema: z.ZodObject<{}, z.core.$strict>;
|
|
68
|
+
export declare const billingContextQuerySchema: z.ZodObject<{
|
|
69
|
+
start: z.ZodOptional<z.ZodString>;
|
|
70
|
+
end: z.ZodOptional<z.ZodString>;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
export declare const getOrCreateCustomerRequestBodySchema: z.ZodObject<{}, z.core.$strict>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { PlanKey, SupportedTopUps, TimePeriods } from "./Billing.js";
|
|
3
|
+
import { modelReferenceSchema } from "./ModelRegistry.js";
|
|
4
|
+
/** Matches `CompletedEventUsage` in `Billing.ts`. */
|
|
5
|
+
export const completedEventUsageSchema = z.object({
|
|
6
|
+
inputTokens: z.number().nonnegative(),
|
|
7
|
+
outputTokens: z.number().nonnegative(),
|
|
8
|
+
totalTokens: z.number().nonnegative(),
|
|
9
|
+
inputTokensDetails: z.object({
|
|
10
|
+
cached_tokens: z.number().nonnegative()
|
|
11
|
+
})
|
|
12
|
+
});
|
|
13
|
+
/** Matches `BillingRunGateRequestBody`. */
|
|
14
|
+
export const billingRunGateRequestBodySchema = z.object({
|
|
15
|
+
organizationId: z.string().min(1)
|
|
16
|
+
});
|
|
17
|
+
/** Matches `BillingChargeRunBaseBody`. */
|
|
18
|
+
export const billingChargeRunBaseBodySchema = billingRunGateRequestBodySchema.extend({
|
|
19
|
+
runId: z.string().min(1)
|
|
20
|
+
});
|
|
21
|
+
/** Matches `BillingRecordLlmBody`. */
|
|
22
|
+
export const billingRecordLlmBodySchema = z.object({
|
|
23
|
+
organizationId: z.string().min(1),
|
|
24
|
+
runId: z.string().min(1),
|
|
25
|
+
responseId: z.string().min(1),
|
|
26
|
+
model: modelReferenceSchema,
|
|
27
|
+
usage: completedEventUsageSchema
|
|
28
|
+
});
|
|
29
|
+
/** Matches `BillingCheckoutRequestBody`. */
|
|
30
|
+
export const billingCheckoutRequestBodySchema = z.discriminatedUnion("kind", [
|
|
31
|
+
z.object({
|
|
32
|
+
kind: z.literal("plan"),
|
|
33
|
+
planKey: z.enum(PlanKey),
|
|
34
|
+
period: z.enum(TimePeriods)
|
|
35
|
+
}),
|
|
36
|
+
z.object({
|
|
37
|
+
kind: z.literal("topup"),
|
|
38
|
+
packCredits: z.enum(SupportedTopUps)
|
|
39
|
+
})
|
|
40
|
+
]);
|
|
41
|
+
/** Matches `BillingChangeRequestBody`. */
|
|
42
|
+
export const billingChangeRequestBodySchema = z.discriminatedUnion("kind", [
|
|
43
|
+
z.object({ kind: z.literal("cancel_to_free") }),
|
|
44
|
+
z.object({
|
|
45
|
+
kind: z.literal("change_period"),
|
|
46
|
+
planKey: z.enum(PlanKey),
|
|
47
|
+
period: z.enum(TimePeriods)
|
|
48
|
+
})
|
|
49
|
+
]);
|
|
50
|
+
/** Matches `BillingOverageModePatchBody`. */
|
|
51
|
+
export const billingOverageModePatchBodySchema = z.object({
|
|
52
|
+
mode: z.enum(["soft", "strict"])
|
|
53
|
+
});
|
|
54
|
+
export const billingPortalSessionRequestBodySchema = z.object({}).strict();
|
|
55
|
+
export const billingContextQuerySchema = z.object({
|
|
56
|
+
start: z.string().min(1).optional(),
|
|
57
|
+
end: z.string().min(1).optional()
|
|
58
|
+
});
|
|
59
|
+
export const getOrCreateCustomerRequestBodySchema = z.object({}).strict();
|
package/dist/FrontendRoutes.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"APP": "/app",
|
|
3
|
+
"PRICING": "/app/pricing",
|
|
3
4
|
"OAUTH": {
|
|
4
5
|
"SUCCESS": "/oauth/success",
|
|
5
6
|
"ERROR": "/oauth/error"
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
"STATS": "/app/stats",
|
|
27
28
|
"NOTIFICATIONS": "/app/notifications",
|
|
28
29
|
"API_TOKENS": "/app/api-tokens",
|
|
30
|
+
"BILLING": "/app/billing",
|
|
29
31
|
"PROFILE": "/app/profile",
|
|
30
32
|
"USER_MANAGEMENT": "/app/profile?tab=users",
|
|
31
33
|
"ORGANIZATIONS": {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export declare const FROM_SETUP_CHAT_PARAM = "fromSetupChat";
|
|
3
3
|
export declare const FrontendRoutes: {
|
|
4
4
|
APP: string;
|
|
5
|
+
PRICING: string;
|
|
5
6
|
OAUTH: {
|
|
6
7
|
SUCCESS: string;
|
|
7
8
|
ERROR: string;
|
|
@@ -28,6 +29,7 @@ export declare const FrontendRoutes: {
|
|
|
28
29
|
STATS: string;
|
|
29
30
|
NOTIFICATIONS: string;
|
|
30
31
|
API_TOKENS: string;
|
|
32
|
+
BILLING: string;
|
|
31
33
|
PROFILE: string;
|
|
32
34
|
USER_MANAGEMENT: string;
|
|
33
35
|
ORGANIZATIONS: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BillingContextQuery } from "./Billing.js";
|
|
1
2
|
import { GetRunHistoryParams } from "./RunHistoryTypes.js";
|
|
2
3
|
import type { StatsInterval } from "./types.js";
|
|
3
4
|
export declare const currentUserKey: () => readonly [string];
|
|
@@ -50,3 +51,6 @@ export declare const agentFileContentKey: (agentId: string, fileId: string) => r
|
|
|
50
51
|
export declare const projectDeploysKey: (projectId: string) => readonly [string, string];
|
|
51
52
|
export declare const projectSourceFilesKey: (projectId: string) => readonly [string, string];
|
|
52
53
|
export declare const projectSourceFileContentKey: (projectId: string, fileId: string) => readonly [string, string, string];
|
|
54
|
+
export declare const billingContextKey: (params?: Partial<BillingContextQuery>) => readonly [string, string, string, string];
|
|
55
|
+
export declare const billingCatalogKey: () => readonly [string];
|
|
56
|
+
export declare const organizationProjectsKey: () => readonly [string];
|
package/dist/InvalidationKeys.js
CHANGED
|
@@ -6,7 +6,7 @@ export const notificationDestinationsKey = () => ["notificationDestinations"];
|
|
|
6
6
|
export const apiTokensKey = () => ["apiTokens"];
|
|
7
7
|
export const notificationSettingsKey = () => ["notificationSettings"];
|
|
8
8
|
export const sentNotificationsKey = () => ["sentNotifications"];
|
|
9
|
-
export const pendingApprovalsKey = () => ["
|
|
9
|
+
export const pendingApprovalsKey = () => ["pendingApprovals"];
|
|
10
10
|
export const slackChannelsKey = (integrationId) => {
|
|
11
11
|
if (!integrationId) {
|
|
12
12
|
return null;
|
|
@@ -145,3 +145,11 @@ export const agentFileContentKey = (agentId, fileId) => ["agentFileContent", age
|
|
|
145
145
|
export const projectDeploysKey = (projectId) => ["projectDeploys", projectId];
|
|
146
146
|
export const projectSourceFilesKey = (projectId) => ["projectSourceFiles", projectId];
|
|
147
147
|
export const projectSourceFileContentKey = (projectId, fileId) => ["projectSourceFileContent", projectId, fileId];
|
|
148
|
+
export const billingContextKey = (params) => [
|
|
149
|
+
"billingContext",
|
|
150
|
+
params?.timezone ?? "",
|
|
151
|
+
params?.start?.toISOString() ?? "",
|
|
152
|
+
params?.end?.toISOString() ?? ""
|
|
153
|
+
];
|
|
154
|
+
export const billingCatalogKey = () => ["billingCatalog"];
|
|
155
|
+
export const organizationProjectsKey = () => ["organization-projects"];
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
export declare const organizationMetadataSchema: z.ZodObject<{
|
|
3
3
|
stripeCustomerId: z.ZodString;
|
|
4
|
-
|
|
5
|
-
soft: "soft";
|
|
6
|
-
strict: "strict";
|
|
7
|
-
}>;
|
|
8
|
-
overageCapMultiplier: z.ZodPipe<z.ZodString, z.ZodTransform<number, string>>;
|
|
4
|
+
runExecutionBlocked: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>, z.ZodTransform<boolean, string | boolean | undefined>>;
|
|
9
5
|
}, z.core.$strip>;
|
|
10
6
|
export type OrganizationMetadata = z.infer<typeof organizationMetadataSchema>;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// Can be serialized a string, supports deserialization
|
|
3
|
+
const booleanMetadataSchema = z
|
|
4
|
+
.union([z.boolean(), z.string()])
|
|
5
|
+
.optional()
|
|
6
|
+
.transform(value => value === true || value === "true");
|
|
2
7
|
export const organizationMetadataSchema = z.object({
|
|
3
8
|
stripeCustomerId: z.string(),
|
|
4
|
-
|
|
5
|
-
overageCapMultiplier: z.string().transform(val => Number(val))
|
|
9
|
+
runExecutionBlocked: booleanMetadataSchema
|
|
6
10
|
});
|