terse-types 0.0.23 → 0.0.25

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.
@@ -130,6 +130,8 @@ export declare const ApiRoutes: {
130
130
  DEPLOYS: string;
131
131
  SOURCE_FILES: string;
132
132
  SOURCE_FILE_CONTENT: string;
133
+ ROTATE_SIGNING_SECRET: string;
134
+ ROTATE_API_KEY: string;
133
135
  };
134
136
  SDK: {
135
137
  ME: string;
@@ -142,6 +144,7 @@ export declare const ApiRoutes: {
142
144
  AGENT_RUN: string;
143
145
  APPROVAL_DECISION: string;
144
146
  SESSION_EVENTS: string;
147
+ LISTEN: string;
145
148
  CREATE_PROJECT: string;
146
149
  DEPLOY: string;
147
150
  DEVICE_TOKEN_EXCHANGE: string;
@@ -129,7 +129,9 @@
129
129
  "BY_ID": "/projects/:id",
130
130
  "DEPLOYS": "/projects/:id/deploys",
131
131
  "SOURCE_FILES": "/projects/:id/source/files",
132
- "SOURCE_FILE_CONTENT": "/projects/:id/source/files/:fileId"
132
+ "SOURCE_FILE_CONTENT": "/projects/:id/source/files/:fileId",
133
+ "ROTATE_SIGNING_SECRET": "/projects/:id/rotate-signing-secret",
134
+ "ROTATE_API_KEY": "/projects/:id/rotate-api-key"
133
135
  },
134
136
  "SDK": {
135
137
  "ME": "/sdk/me",
@@ -142,6 +144,7 @@
142
144
  "AGENT_RUN": "/sdk/agent-run",
143
145
  "APPROVAL_DECISION": "/sdk/approval-decision",
144
146
  "SESSION_EVENTS": "/sdk/session-events",
147
+ "LISTEN": "/sdk/listen",
145
148
  "CREATE_PROJECT": "/sdk/projects",
146
149
  "DEPLOY": "/sdk/deploy",
147
150
  "DEVICE_TOKEN_EXCHANGE": "/sdk/auth/device-token-exchange",
@@ -0,0 +1,403 @@
1
+ import { z } from "zod";
2
+ export declare enum PlanKey {
3
+ FREE = "free",
4
+ PRO = "pro"
5
+ }
6
+ export declare const planKeySchema: z.ZodEnum<typeof PlanKey>;
7
+ export declare enum TimePeriods {
8
+ MONTHLY = "monthly",
9
+ YEARLY = "yearly"
10
+ }
11
+ export declare const billingPeriodSchema: z.ZodEnum<typeof TimePeriods>;
12
+ export type BillingPeriod = z.infer<typeof billingPeriodSchema>;
13
+ export declare enum SupportedTopUps {
14
+ TOPUP_10K = 10000
15
+ }
16
+ export declare const supportedTopUpsSchema: z.ZodEnum<typeof SupportedTopUps>;
17
+ export declare const envIdSchema: z.ZodObject<{
18
+ live: z.ZodString;
19
+ test: z.ZodString;
20
+ }, z.core.$strip>;
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
+ export declare const billingScheduledChangeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
30
+ kind: z.ZodLiteral<"cancel_to_free">;
31
+ effectiveAt: z.ZodCoercedDate<unknown>;
32
+ }, z.core.$strip>, z.ZodObject<{
33
+ kind: z.ZodLiteral<"change_period">;
34
+ effectiveAt: z.ZodCoercedDate<unknown>;
35
+ period: z.ZodEnum<typeof TimePeriods>;
36
+ }, z.core.$strip>], "kind">;
37
+ export type BillingScheduledChange = z.infer<typeof billingScheduledChangeSchema>;
38
+ export declare const balanceSummarySchema: z.ZodObject<{
39
+ planKey: z.ZodEnum<typeof PlanKey>;
40
+ billingPeriod: z.ZodNullable<z.ZodEnum<typeof TimePeriods>>;
41
+ planCredits: z.ZodNumber;
42
+ consumedCredits: z.ZodNumber;
43
+ remainingCredits: z.ZodNumber;
44
+ totalCreditCapacity: z.ZodNumber;
45
+ periodStart: z.ZodCoercedDate<unknown>;
46
+ periodEnd: z.ZodCoercedDate<unknown>;
47
+ overageMode: z.ZodEnum<{
48
+ soft: "soft";
49
+ strict: "strict";
50
+ }>;
51
+ hardCap: z.ZodNumber;
52
+ canBuyTopups: z.ZodBoolean;
53
+ scheduledChange: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
54
+ kind: z.ZodLiteral<"cancel_to_free">;
55
+ effectiveAt: z.ZodCoercedDate<unknown>;
56
+ }, z.core.$strip>, z.ZodObject<{
57
+ kind: z.ZodLiteral<"change_period">;
58
+ effectiveAt: z.ZodCoercedDate<unknown>;
59
+ period: z.ZodEnum<typeof TimePeriods>;
60
+ }, z.core.$strip>], "kind">>;
61
+ }, z.core.$strip>;
62
+ export type BalanceSummary = z.infer<typeof balanceSummarySchema>;
63
+ export declare const usageBucketSchema: z.ZodObject<{
64
+ startTimestamp: z.ZodNumber;
65
+ endTimestamp: z.ZodNumber;
66
+ credits: z.ZodNumber;
67
+ }, z.core.$strip>;
68
+ export type UsageBucket = z.infer<typeof usageBucketSchema>;
69
+ export declare const usageResponseSchema: z.ZodObject<{
70
+ buckets: z.ZodArray<z.ZodObject<{
71
+ startTimestamp: z.ZodNumber;
72
+ endTimestamp: z.ZodNumber;
73
+ credits: z.ZodNumber;
74
+ }, z.core.$strip>>;
75
+ }, z.core.$strip>;
76
+ export type UsageResponse = z.infer<typeof usageResponseSchema>;
77
+ export declare const billingContextResponseSchema: z.ZodObject<{
78
+ billingEnabled: z.ZodBoolean;
79
+ balance: z.ZodObject<{
80
+ planKey: z.ZodEnum<typeof PlanKey>;
81
+ billingPeriod: z.ZodNullable<z.ZodEnum<typeof TimePeriods>>;
82
+ planCredits: z.ZodNumber;
83
+ consumedCredits: z.ZodNumber;
84
+ remainingCredits: z.ZodNumber;
85
+ totalCreditCapacity: z.ZodNumber;
86
+ periodStart: z.ZodCoercedDate<unknown>;
87
+ periodEnd: z.ZodCoercedDate<unknown>;
88
+ overageMode: z.ZodEnum<{
89
+ soft: "soft";
90
+ strict: "strict";
91
+ }>;
92
+ hardCap: z.ZodNumber;
93
+ canBuyTopups: z.ZodBoolean;
94
+ scheduledChange: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
95
+ kind: z.ZodLiteral<"cancel_to_free">;
96
+ effectiveAt: z.ZodCoercedDate<unknown>;
97
+ }, z.core.$strip>, z.ZodObject<{
98
+ kind: z.ZodLiteral<"change_period">;
99
+ effectiveAt: z.ZodCoercedDate<unknown>;
100
+ period: z.ZodEnum<typeof TimePeriods>;
101
+ }, z.core.$strip>], "kind">>;
102
+ }, z.core.$strip>;
103
+ usage: z.ZodObject<{
104
+ buckets: z.ZodArray<z.ZodObject<{
105
+ startTimestamp: z.ZodNumber;
106
+ endTimestamp: z.ZodNumber;
107
+ credits: z.ZodNumber;
108
+ }, z.core.$strip>>;
109
+ }, z.core.$strip>;
110
+ }, z.core.$strip>;
111
+ export type BillingContextResponse = z.infer<typeof billingContextResponseSchema>;
112
+ export declare const completedEventUsageSchema: z.ZodObject<{
113
+ inputTokens: z.ZodNumber;
114
+ outputTokens: z.ZodNumber;
115
+ totalTokens: z.ZodNumber;
116
+ inputTokensDetails: z.ZodObject<{
117
+ cached_tokens: z.ZodNumber;
118
+ }, z.core.$strip>;
119
+ }, z.core.$strip>;
120
+ export type CompletedEventUsage = z.infer<typeof completedEventUsageSchema>;
121
+ export declare const billingRunGateRequestBodySchema: z.ZodObject<{
122
+ organizationId: z.ZodString;
123
+ }, z.core.$strip>;
124
+ export type BillingRunGateRequestBody = z.infer<typeof billingRunGateRequestBodySchema>;
125
+ export declare const billingChargeRunBaseBodySchema: z.ZodObject<{
126
+ organizationId: z.ZodString;
127
+ runId: z.ZodString;
128
+ }, z.core.$strip>;
129
+ export type BillingChargeRunBaseBody = z.infer<typeof billingChargeRunBaseBodySchema>;
130
+ /** Acknowledgement from POST /billing/charge-run-base (credits debited for starting a run). */
131
+ export declare const billingChargeRunBaseResponseSchema: z.ZodObject<{
132
+ runId: z.ZodString;
133
+ creditsCharged: z.ZodNumber;
134
+ }, z.core.$strip>;
135
+ export type BillingChargeRunBaseResponse = z.infer<typeof billingChargeRunBaseResponseSchema>;
136
+ export declare const billingRecordLlmBodySchema: z.ZodObject<{
137
+ organizationId: z.ZodString;
138
+ runId: z.ZodString;
139
+ responseId: z.ZodString;
140
+ model: z.ZodObject<{
141
+ providerId: z.ZodEnum<{
142
+ anthropic: "anthropic";
143
+ openai: "openai";
144
+ }>;
145
+ modelId: z.ZodString;
146
+ value: z.ZodString;
147
+ }, z.core.$strip>;
148
+ usage: z.ZodObject<{
149
+ inputTokens: z.ZodNumber;
150
+ outputTokens: z.ZodNumber;
151
+ totalTokens: z.ZodNumber;
152
+ inputTokensDetails: z.ZodObject<{
153
+ cached_tokens: z.ZodNumber;
154
+ }, z.core.$strip>;
155
+ }, z.core.$strip>;
156
+ }, z.core.$strip>;
157
+ export type BillingRecordLlmBody = z.infer<typeof billingRecordLlmBodySchema>;
158
+ /** Acknowledgement from POST /billing/record-llm (credits debited for model usage). */
159
+ export declare const billingRecordLlmResponseSchema: z.ZodObject<{
160
+ responseId: z.ZodString;
161
+ creditsCharged: z.ZodNumber;
162
+ }, z.core.$strip>;
163
+ export type BillingRecordLlmResponse = z.infer<typeof billingRecordLlmResponseSchema>;
164
+ export declare const billingRecordLlmPayloadSchema: z.ZodObject<{
165
+ usage: z.ZodObject<{
166
+ inputTokens: z.ZodNumber;
167
+ outputTokens: z.ZodNumber;
168
+ totalTokens: z.ZodNumber;
169
+ inputTokensDetails: z.ZodObject<{
170
+ cached_tokens: z.ZodNumber;
171
+ }, z.core.$strip>;
172
+ }, z.core.$strip>;
173
+ model: z.ZodObject<{
174
+ providerId: z.ZodEnum<{
175
+ anthropic: "anthropic";
176
+ openai: "openai";
177
+ }>;
178
+ modelId: z.ZodString;
179
+ value: z.ZodString;
180
+ }, z.core.$strip>;
181
+ responseId: z.ZodString;
182
+ }, z.core.$strip>;
183
+ export type BillingRecordLlmPayload = z.infer<typeof billingRecordLlmPayloadSchema>;
184
+ export declare const billingCacheInvalidationBodySchema: z.ZodObject<{
185
+ organizationId: z.ZodString;
186
+ }, z.core.$strip>;
187
+ export type BillingCacheInvalidationBody = z.infer<typeof billingCacheInvalidationBodySchema>;
188
+ export declare const billingCheckoutPlanBodySchema: z.ZodObject<{
189
+ kind: z.ZodLiteral<"plan">;
190
+ planKey: z.ZodEnum<typeof PlanKey>;
191
+ period: z.ZodEnum<typeof TimePeriods>;
192
+ }, z.core.$strip>;
193
+ export type BillingCheckoutPlanBody = z.infer<typeof billingCheckoutPlanBodySchema>;
194
+ export declare const billingCheckoutTopupBodySchema: z.ZodObject<{
195
+ kind: z.ZodLiteral<"topup">;
196
+ packCredits: z.ZodEnum<typeof SupportedTopUps>;
197
+ }, z.core.$strip>;
198
+ export type BillingCheckoutTopupBody = z.infer<typeof billingCheckoutTopupBodySchema>;
199
+ export declare const billingCheckoutRequestBodySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
200
+ kind: z.ZodLiteral<"plan">;
201
+ planKey: z.ZodEnum<typeof PlanKey>;
202
+ period: z.ZodEnum<typeof TimePeriods>;
203
+ }, z.core.$strip>, z.ZodObject<{
204
+ kind: z.ZodLiteral<"topup">;
205
+ packCredits: z.ZodEnum<typeof SupportedTopUps>;
206
+ }, z.core.$strip>], "kind">;
207
+ export type BillingCheckoutRequestBody = z.infer<typeof billingCheckoutRequestBodySchema>;
208
+ export declare const billingChangeCancelBodySchema: z.ZodObject<{
209
+ kind: z.ZodLiteral<"cancel_to_free">;
210
+ }, z.core.$strip>;
211
+ export declare const billingChangePeriodBodySchema: z.ZodObject<{
212
+ kind: z.ZodLiteral<"change_period">;
213
+ planKey: z.ZodEnum<typeof PlanKey>;
214
+ period: z.ZodEnum<typeof TimePeriods>;
215
+ }, z.core.$strip>;
216
+ export declare const billingChangeRequestBodySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
217
+ kind: z.ZodLiteral<"cancel_to_free">;
218
+ }, z.core.$strip>, z.ZodObject<{
219
+ kind: z.ZodLiteral<"change_period">;
220
+ planKey: z.ZodEnum<typeof PlanKey>;
221
+ period: z.ZodEnum<typeof TimePeriods>;
222
+ }, z.core.$strip>], "kind">;
223
+ 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
+ export declare const billingPortalSessionRequestBodySchema: z.ZodObject<{}, z.core.$strict>;
232
+ export type BillingPortalSessionRequestBody = z.infer<typeof billingPortalSessionRequestBodySchema>;
233
+ export declare const billingContextQuerySchema: z.ZodObject<{
234
+ start: z.ZodOptional<z.ZodCoercedDate<unknown>>;
235
+ end: z.ZodOptional<z.ZodCoercedDate<unknown>>;
236
+ }, z.core.$strip>;
237
+ export type BillingContextQuery = z.infer<typeof billingContextQuerySchema>;
238
+ export declare const getOrCreateCustomerRequestBodySchema: z.ZodObject<{}, z.core.$strict>;
239
+ export type GetOrCreateCustomerRequestBody = z.infer<typeof getOrCreateCustomerRequestBodySchema>;
240
+ export declare const billingStripeRedirectResponseSchema: z.ZodObject<{
241
+ url: z.ZodString;
242
+ }, z.core.$strip>;
243
+ export type BillingStripeRedirectResponse = z.infer<typeof billingStripeRedirectResponseSchema>;
244
+ export declare const setOverageModeResponseSchema: z.ZodObject<{
245
+ ok: z.ZodLiteral<true>;
246
+ }, z.core.$strip>;
247
+ export type SetOverageModeResponse = z.infer<typeof setOverageModeResponseSchema>;
248
+ export declare const billingChangeResponseSchema: z.ZodObject<{
249
+ ok: z.ZodLiteral<true>;
250
+ scheduledChange: z.ZodNullable<z.ZodDiscriminatedUnion<[z.ZodObject<{
251
+ kind: z.ZodLiteral<"cancel_to_free">;
252
+ effectiveAt: z.ZodCoercedDate<unknown>;
253
+ }, z.core.$strip>, z.ZodObject<{
254
+ kind: z.ZodLiteral<"change_period">;
255
+ effectiveAt: z.ZodCoercedDate<unknown>;
256
+ period: z.ZodEnum<typeof TimePeriods>;
257
+ }, z.core.$strip>], "kind">>;
258
+ }, z.core.$strip>;
259
+ export type BillingChangeResponse = z.infer<typeof billingChangeResponseSchema>;
260
+ export declare const runGateDenyReasonSchema: z.ZodEnum<{
261
+ credits_exhausted: "credits_exhausted";
262
+ subscription_past_due: "subscription_past_due";
263
+ no_subscription: "no_subscription";
264
+ }>;
265
+ export type RunGateDenyReason = z.infer<typeof runGateDenyReasonSchema>;
266
+ export declare const runGateAllowSchema: z.ZodObject<{
267
+ allow: z.ZodLiteral<true>;
268
+ }, z.core.$strip>;
269
+ export declare const runGateDenySchema: z.ZodObject<{
270
+ allow: z.ZodLiteral<false>;
271
+ reason: z.ZodEnum<{
272
+ credits_exhausted: "credits_exhausted";
273
+ subscription_past_due: "subscription_past_due";
274
+ no_subscription: "no_subscription";
275
+ }>;
276
+ }, z.core.$strip>;
277
+ export declare const runGateDecisionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
278
+ allow: z.ZodLiteral<true>;
279
+ }, z.core.$strip>, z.ZodObject<{
280
+ allow: z.ZodLiteral<false>;
281
+ reason: z.ZodEnum<{
282
+ credits_exhausted: "credits_exhausted";
283
+ subscription_past_due: "subscription_past_due";
284
+ no_subscription: "no_subscription";
285
+ }>;
286
+ }, z.core.$strip>], "allow">;
287
+ export type RunGateDecision = z.infer<typeof runGateDecisionSchema>;
288
+ export declare function parseRunGateDenyReason(raw: unknown): RunGateDenyReason;
289
+ export declare const getOrCreateCustomerResponseSchema: z.ZodObject<{
290
+ customerId: z.ZodString;
291
+ }, z.core.$strip>;
292
+ export type GetOrCreateCustomerResponse = z.infer<typeof getOrCreateCustomerResponseSchema>;
293
+ export declare const planSchema: z.ZodObject<{
294
+ key: z.ZodEnum<typeof PlanKey>;
295
+ name: z.ZodString;
296
+ monthlyBasePriceId: z.ZodNullable<z.ZodObject<{
297
+ live: z.ZodString;
298
+ test: z.ZodString;
299
+ }, z.core.$strip>>;
300
+ annualBasePriceId: z.ZodNullable<z.ZodObject<{
301
+ live: z.ZodString;
302
+ test: z.ZodString;
303
+ }, z.core.$strip>>;
304
+ overagePriceId: z.ZodNullable<z.ZodObject<{
305
+ live: z.ZodString;
306
+ test: z.ZodString;
307
+ }, z.core.$strip>>;
308
+ priceInUsdMonthly: z.ZodNullable<z.ZodNumber>;
309
+ priceInUsdMonthlyAnnual: z.ZodNullable<z.ZodNumber>;
310
+ 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
+ }, z.core.$strip>;
319
+ export type Plan = z.infer<typeof planSchema>;
320
+ export declare function isPurchasablePlan(plan: Plan): boolean;
321
+ export declare const topUpSchema: z.ZodObject<{
322
+ credits: z.ZodEnum<typeof SupportedTopUps>;
323
+ priceInUsd: z.ZodNumber;
324
+ priceId: z.ZodObject<{
325
+ live: z.ZodString;
326
+ test: z.ZodString;
327
+ }, z.core.$strip>;
328
+ }, z.core.$strip>;
329
+ export type TopUp = z.infer<typeof topUpSchema>;
330
+ export declare const billingCatalogResponseSchema: z.ZodObject<{
331
+ plans: z.ZodArray<z.ZodObject<{
332
+ key: z.ZodEnum<typeof PlanKey>;
333
+ name: z.ZodString;
334
+ monthlyBasePriceId: z.ZodNullable<z.ZodObject<{
335
+ live: z.ZodString;
336
+ test: z.ZodString;
337
+ }, z.core.$strip>>;
338
+ annualBasePriceId: z.ZodNullable<z.ZodObject<{
339
+ live: z.ZodString;
340
+ test: z.ZodString;
341
+ }, z.core.$strip>>;
342
+ overagePriceId: z.ZodNullable<z.ZodObject<{
343
+ live: z.ZodString;
344
+ test: z.ZodString;
345
+ }, z.core.$strip>>;
346
+ priceInUsdMonthly: z.ZodNullable<z.ZodNumber>;
347
+ priceInUsdMonthlyAnnual: z.ZodNullable<z.ZodNumber>;
348
+ 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
+ }, z.core.$strip>>;
357
+ topUps: z.ZodArray<z.ZodObject<{
358
+ credits: z.ZodEnum<typeof SupportedTopUps>;
359
+ priceInUsd: z.ZodNumber;
360
+ priceId: z.ZodObject<{
361
+ live: z.ZodString;
362
+ test: z.ZodString;
363
+ }, z.core.$strip>;
364
+ }, z.core.$strip>>;
365
+ }, z.core.$strip>;
366
+ export type BillingCatalogResponse = z.infer<typeof billingCatalogResponseSchema>;
367
+ export declare const BILLING_SERVICE_JWT_ISSUER: "terse-api";
368
+ export declare const BILLING_SERVICE_JWT_AUDIENCE: "terse-billing";
369
+ export declare const BILLING_SERVICE_CALLBACK_JWT_ISSUER: "terse-billing";
370
+ export declare const BILLING_SERVICE_CALLBACK_JWT_AUDIENCE: "terse-api";
371
+ export declare const terseBillingJwtClaimsSchema: z.ZodObject<{
372
+ organizationId: z.ZodString;
373
+ }, z.core.$strip>;
374
+ export type TerseBillingJwtClaims = z.infer<typeof terseBillingJwtClaimsSchema>;
375
+ export declare const BillingRoutes: {
376
+ CATALOG: string;
377
+ CONTEXT: string;
378
+ CHECKOUT_SESSION: string;
379
+ CHANGE: string;
380
+ PORTAL_SESSION: string;
381
+ OVERAGE_MODE: string;
382
+ CUSTOMER: string;
383
+ RUN_GATE: string;
384
+ CHARGE_RUN_BASE: string;
385
+ RECORD_LLM: string;
386
+ CACHE_INVALIDATION: string;
387
+ };
388
+ export type BillingForbiddenErrorType = "CreditGateDeniedError" | "StripeError";
389
+ export type BillingForbiddenErrorBody = {
390
+ type: BillingForbiddenErrorType;
391
+ reason?: string;
392
+ };
393
+ export declare class CreditGateDeniedError extends Error {
394
+ readonly reason: RunGateDenyReason;
395
+ constructor(reason: RunGateDenyReason);
396
+ }
397
+ export declare class StripeError extends Error {
398
+ readonly reason?: string;
399
+ constructor(message?: string, reason?: string);
400
+ }
401
+ export declare function billingErrorFromForbiddenBody(body: unknown): CreditGateDeniedError | StripeError | null;
402
+ /** Parse JSON body from a billing HTTP 403 response */
403
+ export declare function parseBillingForbiddenJson(raw: string): CreditGateDeniedError | StripeError | null;
@@ -0,0 +1,227 @@
1
+ import { z } from "zod";
2
+ import billingRoutes from "./BillingRoutes.json" with { type: "json" };
3
+ import { modelReferenceSchema } from "./ModelRegistry.js";
4
+ export var PlanKey;
5
+ (function (PlanKey) {
6
+ PlanKey["FREE"] = "free";
7
+ PlanKey["PRO"] = "pro";
8
+ })(PlanKey || (PlanKey = {}));
9
+ export const planKeySchema = z.enum(PlanKey);
10
+ export var TimePeriods;
11
+ (function (TimePeriods) {
12
+ TimePeriods["MONTHLY"] = "monthly";
13
+ TimePeriods["YEARLY"] = "yearly";
14
+ })(TimePeriods || (TimePeriods = {}));
15
+ export const billingPeriodSchema = z.enum(TimePeriods);
16
+ export var SupportedTopUps;
17
+ (function (SupportedTopUps) {
18
+ SupportedTopUps[SupportedTopUps["TOPUP_10K"] = 10000] = "TOPUP_10K";
19
+ })(SupportedTopUps || (SupportedTopUps = {}));
20
+ export const supportedTopUpsSchema = z.enum(SupportedTopUps);
21
+ export const envIdSchema = z.object({
22
+ live: z.string(),
23
+ test: z.string()
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
+ export const billingScheduledChangeSchema = z.discriminatedUnion("kind", [
29
+ z.object({
30
+ kind: z.literal("cancel_to_free"),
31
+ effectiveAt: z.coerce.date()
32
+ }),
33
+ z.object({
34
+ kind: z.literal("change_period"),
35
+ effectiveAt: z.coerce.date(),
36
+ period: billingPeriodSchema
37
+ })
38
+ ]);
39
+ export const balanceSummarySchema = z.object({
40
+ planKey: planKeySchema,
41
+ billingPeriod: billingPeriodSchema.nullable(),
42
+ planCredits: z.number(),
43
+ consumedCredits: z.number(),
44
+ remainingCredits: z.number(),
45
+ totalCreditCapacity: z.number(),
46
+ periodStart: z.coerce.date(),
47
+ periodEnd: z.coerce.date(),
48
+ overageMode: overageModeSchema,
49
+ hardCap: z.number(),
50
+ canBuyTopups: z.boolean(),
51
+ scheduledChange: billingScheduledChangeSchema.nullable()
52
+ });
53
+ export const usageBucketSchema = z.object({
54
+ startTimestamp: z.number(),
55
+ endTimestamp: z.number(),
56
+ credits: z.number()
57
+ });
58
+ export const usageResponseSchema = z.object({
59
+ buckets: z.array(usageBucketSchema)
60
+ });
61
+ export const billingContextResponseSchema = z.object({
62
+ billingEnabled: z.boolean(),
63
+ balance: balanceSummarySchema,
64
+ usage: usageResponseSchema
65
+ });
66
+ export const completedEventUsageSchema = z.object({
67
+ inputTokens: z.number().nonnegative(),
68
+ outputTokens: z.number().nonnegative(),
69
+ totalTokens: z.number().nonnegative(),
70
+ inputTokensDetails: z.object({
71
+ cached_tokens: z.number().nonnegative()
72
+ })
73
+ });
74
+ export const billingRunGateRequestBodySchema = z.object({
75
+ organizationId: z.string().min(1)
76
+ });
77
+ export const billingChargeRunBaseBodySchema = billingRunGateRequestBodySchema.extend({
78
+ runId: z.string().min(1)
79
+ });
80
+ /** Acknowledgement from POST /billing/charge-run-base (credits debited for starting a run). */
81
+ export const billingChargeRunBaseResponseSchema = z.object({
82
+ runId: z.string().min(1),
83
+ creditsCharged: z.number().nonnegative()
84
+ });
85
+ export const billingRecordLlmBodySchema = z.object({
86
+ organizationId: z.string().min(1),
87
+ runId: z.string().min(1),
88
+ responseId: z.string().min(1),
89
+ model: modelReferenceSchema,
90
+ usage: completedEventUsageSchema
91
+ });
92
+ /** Acknowledgement from POST /billing/record-llm (credits debited for model usage). */
93
+ export const billingRecordLlmResponseSchema = z.object({
94
+ responseId: z.string().min(1),
95
+ creditsCharged: z.number().nonnegative()
96
+ });
97
+ export const billingRecordLlmPayloadSchema = billingRecordLlmBodySchema.pick({
98
+ responseId: true,
99
+ model: true,
100
+ usage: true
101
+ });
102
+ export const billingCacheInvalidationBodySchema = z.object({
103
+ organizationId: z.string().min(1)
104
+ });
105
+ export const billingCheckoutPlanBodySchema = z.object({
106
+ kind: z.literal("plan"),
107
+ planKey: planKeySchema,
108
+ period: billingPeriodSchema
109
+ });
110
+ export const billingCheckoutTopupBodySchema = z.object({
111
+ kind: z.literal("topup"),
112
+ packCredits: supportedTopUpsSchema
113
+ });
114
+ export const billingCheckoutRequestBodySchema = z.discriminatedUnion("kind", [billingCheckoutPlanBodySchema, billingCheckoutTopupBodySchema]);
115
+ export const billingChangeCancelBodySchema = z.object({ kind: z.literal("cancel_to_free") });
116
+ export const billingChangePeriodBodySchema = z.object({
117
+ kind: z.literal("change_period"),
118
+ planKey: planKeySchema,
119
+ period: billingPeriodSchema
120
+ });
121
+ export const billingChangeRequestBodySchema = z.discriminatedUnion("kind", [billingChangeCancelBodySchema, billingChangePeriodBodySchema]);
122
+ export const billingOverageModePatchBodySchema = z.object({
123
+ mode: overageModeSchema
124
+ });
125
+ export const billingPortalSessionRequestBodySchema = z.object({}).strict();
126
+ export const billingContextQuerySchema = z.object({
127
+ start: z.coerce.date().optional(),
128
+ end: z.coerce.date().optional()
129
+ });
130
+ export const getOrCreateCustomerRequestBodySchema = z.object({}).strict();
131
+ export const billingStripeRedirectResponseSchema = z.object({
132
+ url: z.string()
133
+ });
134
+ export const setOverageModeResponseSchema = z.object({
135
+ ok: z.literal(true)
136
+ });
137
+ export const billingChangeResponseSchema = z.object({
138
+ ok: z.literal(true),
139
+ scheduledChange: billingScheduledChangeSchema.nullable()
140
+ });
141
+ export const runGateDenyReasonSchema = z.enum(["credits_exhausted", "subscription_past_due", "no_subscription"]);
142
+ export const runGateAllowSchema = z.object({ allow: z.literal(true) });
143
+ export const runGateDenySchema = z.object({
144
+ allow: z.literal(false),
145
+ reason: runGateDenyReasonSchema
146
+ });
147
+ export const runGateDecisionSchema = z.discriminatedUnion("allow", [runGateAllowSchema, runGateDenySchema]);
148
+ export function parseRunGateDenyReason(raw) {
149
+ const parsed = runGateDenyReasonSchema.safeParse(raw);
150
+ return parsed.success ? parsed.data : "credits_exhausted";
151
+ }
152
+ export const getOrCreateCustomerResponseSchema = z.object({
153
+ customerId: z.string()
154
+ });
155
+ export const planSchema = z.object({
156
+ key: planKeySchema,
157
+ name: z.string(),
158
+ monthlyBasePriceId: envIdSchema.nullable(),
159
+ annualBasePriceId: envIdSchema.nullable(),
160
+ overagePriceId: envIdSchema.nullable(),
161
+ priceInUsdMonthly: z.number().nullable(),
162
+ priceInUsdMonthlyAnnual: z.number().nullable(),
163
+ includedCreditsPerMonth: z.number(),
164
+ markupPct: z.number(),
165
+ overageCentsPerCredit: z.number(),
166
+ hardCapMultiplier: z.number(),
167
+ defaultOverageMode: overageModeSchema
168
+ });
169
+ export function isPurchasablePlan(plan) {
170
+ return !!(plan.monthlyBasePriceId || plan.annualBasePriceId);
171
+ }
172
+ export const topUpSchema = z.object({
173
+ credits: supportedTopUpsSchema,
174
+ priceInUsd: z.number(),
175
+ priceId: envIdSchema
176
+ });
177
+ export const billingCatalogResponseSchema = z.object({
178
+ plans: z.array(planSchema),
179
+ topUps: z.array(topUpSchema)
180
+ });
181
+ export const BILLING_SERVICE_JWT_ISSUER = "terse-api";
182
+ export const BILLING_SERVICE_JWT_AUDIENCE = "terse-billing";
183
+ export const BILLING_SERVICE_CALLBACK_JWT_ISSUER = "terse-billing";
184
+ export const BILLING_SERVICE_CALLBACK_JWT_AUDIENCE = "terse-api";
185
+ export const terseBillingJwtClaimsSchema = z.object({
186
+ organizationId: z.string().min(1)
187
+ });
188
+ export const BillingRoutes = billingRoutes;
189
+ export class CreditGateDeniedError extends Error {
190
+ reason;
191
+ constructor(reason) {
192
+ super(`Credit gate denied: ${reason}`);
193
+ this.name = "CreditGateDeniedError";
194
+ this.reason = reason;
195
+ }
196
+ }
197
+ export class StripeError extends Error {
198
+ reason;
199
+ constructor(message, reason) {
200
+ super(message ?? reason ?? "Billing provider error");
201
+ this.name = "StripeError";
202
+ this.reason = reason;
203
+ }
204
+ }
205
+ export function billingErrorFromForbiddenBody(body) {
206
+ if (!body || typeof body !== "object")
207
+ return null;
208
+ const o = body;
209
+ const t = o.type ?? o.errorType;
210
+ if (t === "CreditGateDeniedError") {
211
+ return new CreditGateDeniedError(parseRunGateDenyReason(o.reason));
212
+ }
213
+ if (t === "StripeError") {
214
+ const reason = typeof o.reason === "string" ? o.reason : undefined;
215
+ return new StripeError(reason, reason);
216
+ }
217
+ return null;
218
+ }
219
+ /** Parse JSON body from a billing HTTP 403 response */
220
+ export function parseBillingForbiddenJson(raw) {
221
+ try {
222
+ return billingErrorFromForbiddenBody(JSON.parse(raw));
223
+ }
224
+ catch {
225
+ return null;
226
+ }
227
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "CATALOG": "/billing/catalog",
3
+ "CONTEXT": "/billing/context",
4
+ "CHECKOUT_SESSION": "/billing/checkout-session",
5
+ "CHANGE": "/billing/change",
6
+ "PORTAL_SESSION": "/billing/portal-session",
7
+ "OVERAGE_MODE": "/billing/overage-mode",
8
+ "CUSTOMER": "/billing/customer",
9
+ "RUN_GATE": "/billing/run-gate",
10
+ "CHARGE_RUN_BASE": "/billing/charge-run-base",
11
+ "RECORD_LLM": "/billing/record-llm",
12
+ "CACHE_INVALIDATION": "/billing/cache-invalidation"
13
+ }
@@ -17,7 +17,8 @@
17
17
  "RUN_HISTORY": "/app/agents/:id?tab=history&runId=:runId"
18
18
  },
19
19
  "PROJECTS": {
20
- "BY_ID": "/app/projects/:id"
20
+ "BY_ID": "/app/projects/:id",
21
+ "DEPLOYS": "/app/projects/:id/deploys"
21
22
  },
22
23
  "HOME": "/app/home",
23
24
  "INTEGRATIONS": "/app/integrations",