@springbrand/contracts 0.0.0-stage → 0.1.0-alpha.0
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/README.md +23 -2
- package/dist/contracts/src/account.d.ts +300 -0
- package/dist/contracts/src/account.js +211 -0
- package/dist/contracts/src/action.d.ts +445 -0
- package/dist/contracts/src/action.js +267 -0
- package/dist/contracts/src/admin.d.ts +35 -0
- package/dist/contracts/src/admin.js +34 -0
- package/dist/contracts/src/agent-config-deletion.d.ts +11 -0
- package/dist/contracts/src/agent-config-deletion.js +18 -0
- package/dist/contracts/src/attachment.d.ts +197 -0
- package/dist/contracts/src/attachment.js +39 -0
- package/dist/contracts/src/campaign-time-schema.d.ts +15 -0
- package/dist/contracts/src/campaign-time-schema.js +9 -0
- package/dist/contracts/src/campaign-time.d.ts +8 -0
- package/dist/contracts/src/campaign-time.js +33 -0
- package/dist/contracts/src/campaign.d.ts +438 -0
- package/dist/contracts/src/campaign.js +148 -0
- package/dist/contracts/src/connectors.d.ts +98 -0
- package/dist/contracts/src/connectors.js +30 -0
- package/dist/contracts/src/errors.d.ts +6707 -0
- package/dist/contracts/src/errors.js +118 -0
- package/dist/contracts/src/extension-verification.d.ts +45 -0
- package/dist/contracts/src/extension-verification.js +12 -0
- package/dist/contracts/src/http.d.ts +3055 -0
- package/dist/contracts/src/http.js +4 -0
- package/dist/contracts/src/mcp-api-key.d.ts +132 -0
- package/dist/contracts/src/mcp-api-key.js +86 -0
- package/dist/contracts/src/mcp-gateway/errors.d.ts +52 -0
- package/dist/contracts/src/mcp-gateway/errors.js +44 -0
- package/dist/contracts/src/mcp-gateway/service-auth.d.ts +5 -0
- package/dist/contracts/src/mcp-gateway/service-auth.js +15 -0
- package/dist/contracts/src/mcp-observation.d.ts +302 -0
- package/dist/contracts/src/mcp-observation.js +95 -0
- package/dist/contracts/src/onboarding.d.ts +207 -0
- package/dist/contracts/src/onboarding.js +37 -0
- package/dist/contracts/src/referral.d.ts +169 -0
- package/dist/contracts/src/referral.js +73 -0
- package/dist/contracts/src/runtime-plan-maintenance.d.ts +77 -0
- package/dist/contracts/src/runtime-plan-maintenance.js +63 -0
- package/dist/contracts/src/user-reference.d.ts +157 -0
- package/dist/contracts/src/user-reference.js +26 -0
- package/dist/resource/src/api-supplier.d.ts +35 -0
- package/dist/resource/src/api-supplier.js +12 -0
- package/dist/resource/src/index.d.ts +1748 -0
- package/dist/resource/src/index.js +715 -0
- package/dist/resource/src/skill-render.d.ts +19 -0
- package/dist/resource/src/skill-render.js +84 -0
- package/dist/utils/src/attachment.d.ts +12 -0
- package/dist/utils/src/attachment.js +50 -0
- package/dist/utils/src/base64.d.ts +3 -0
- package/dist/utils/src/base64.js +27 -0
- package/dist/utils/src/content-hash.d.ts +5 -0
- package/dist/utils/src/content-hash.js +27 -0
- package/dist/utils/src/database.d.ts +1 -0
- package/dist/utils/src/database.js +9 -0
- package/dist/utils/src/html.d.ts +2 -0
- package/dist/utils/src/html.js +9 -0
- package/dist/utils/src/image.d.ts +33 -0
- package/dist/utils/src/image.js +35 -0
- package/dist/utils/src/index.d.ts +12 -0
- package/dist/utils/src/index.js +12 -0
- package/dist/utils/src/ip-address.d.ts +6 -0
- package/dist/utils/src/ip-address.js +11 -0
- package/dist/utils/src/json.d.ts +6 -0
- package/dist/utils/src/json.js +18 -0
- package/dist/utils/src/ooxml.d.ts +14 -0
- package/dist/utils/src/ooxml.js +170 -0
- package/dist/utils/src/serialized-size.d.ts +9 -0
- package/dist/utils/src/serialized-size.js +11 -0
- package/dist/utils/src/strict-zip.d.ts +68 -0
- package/dist/utils/src/strict-zip.js +177 -0
- package/dist/utils/src/uuid.d.ts +9 -0
- package/dist/utils/src/uuid.js +27 -0
- package/package.json +102 -4
package/README.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @springbrand/contracts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
API、Web、Agent 和 Auth 共用的业务接口合约:每个业务领域的 Zod schema 和推导出的 TypeScript 类型。
|
|
4
|
+
|
|
5
|
+
## 只用子路径导入
|
|
6
|
+
|
|
7
|
+
本包没有根入口。每个领域单独导出,例如:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { accountSnapshotSchema, type AccountSnapshot } from '@springbrand/contracts/account'
|
|
11
|
+
import { actionExecutionReplySchema } from '@springbrand/contracts/action'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Zod schema 在模块加载时就会被创建。单一根入口会让每个调用方都创建全部业务 schema,Agent Worker 冷启动会因此变慢,
|
|
15
|
+
所以新增领域时要新建模块,并在 `package.json` 的 `exports` 里加对应子路径。
|
|
16
|
+
|
|
17
|
+
## 边界
|
|
18
|
+
|
|
19
|
+
- HTTP 响应信封、客户端、服务鉴权属于上游 `@springbrand/http`。平台错误码目录(`./errors`)和它的 Hono 响应(`./http`)放在这里,因为错误码是平台业务定义。
|
|
20
|
+
- Agent 运行时专用的合约属于 `@springbrand/agent-contracts`;Resource 与能力合约属于 `@springbrand/resource`。
|
|
21
|
+
- `mcp-api-key` 是对外冻结的 MCP Key 合约。mcp-gateway vendor 的外部 tarball 仍叫 `@springbrand/http`(入口 `./mcp-api-key`、`./service-auth`、`./errors`,v2 形状),由
|
|
22
|
+
`scripts/pack-mcp-contracts.mjs` 生成:`./mcp-api-key` 来自本包,另外两个入口来自 `src/mcp-gateway/` 的兼容层(数据和逻辑取自 `./errors` 与公共 SDK)。改动兼容层或合约后,用新的 `--version` 重新打包,并在 mcp-gateway 里跑一遍 typecheck 和测试。
|
|
23
|
+
|
|
24
|
+
- `agent-config-deletion` 持有 Agent 删除检查和阻碍事实,供错误目录与 Agent 合约共同使用,避免两者形成循环依赖。
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const subscriptionStatusSchema: z.ZodEnum<{
|
|
3
|
+
active: "active";
|
|
4
|
+
canceling: "canceling";
|
|
5
|
+
past_due: "past_due";
|
|
6
|
+
}>;
|
|
7
|
+
export declare const accountActionSchema: z.ZodEnum<{
|
|
8
|
+
subscribe: "subscribe";
|
|
9
|
+
change_plan: "change_plan";
|
|
10
|
+
cancel_subscription: "cancel_subscription";
|
|
11
|
+
resume_subscription: "resume_subscription";
|
|
12
|
+
update_payment_method: "update_payment_method";
|
|
13
|
+
}>;
|
|
14
|
+
export declare const accountSnapshotSchema: z.ZodObject<{
|
|
15
|
+
asOf: z.ZodString;
|
|
16
|
+
reconciliationCompleted: z.ZodBoolean;
|
|
17
|
+
profile: z.ZodObject<{
|
|
18
|
+
userId: z.ZodString;
|
|
19
|
+
email: z.ZodEmail;
|
|
20
|
+
displayName: z.ZodString;
|
|
21
|
+
avatarUrl: z.ZodNullable<z.ZodString>;
|
|
22
|
+
timezone: z.ZodString;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
plan: z.ZodObject<{
|
|
25
|
+
id: z.ZodString;
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
subscription: z.ZodNullable<z.ZodObject<{
|
|
29
|
+
status: z.ZodEnum<{
|
|
30
|
+
active: "active";
|
|
31
|
+
canceling: "canceling";
|
|
32
|
+
past_due: "past_due";
|
|
33
|
+
}>;
|
|
34
|
+
billingInterval: z.ZodEnum<{
|
|
35
|
+
month: "month";
|
|
36
|
+
year: "year";
|
|
37
|
+
}>;
|
|
38
|
+
autoRenews: z.ZodBoolean;
|
|
39
|
+
planChangeBlockedReason: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
40
|
+
subscription_refunded: "subscription_refunded";
|
|
41
|
+
}>>>;
|
|
42
|
+
}, z.core.$strip>>;
|
|
43
|
+
pendingPlanCheckout: z.ZodNullable<z.ZodObject<{
|
|
44
|
+
orderId: z.ZodString;
|
|
45
|
+
planId: z.ZodString;
|
|
46
|
+
billingInterval: z.ZodEnum<{
|
|
47
|
+
month: "month";
|
|
48
|
+
year: "year";
|
|
49
|
+
}>;
|
|
50
|
+
status: z.ZodLiteral<"confirmation_pending">;
|
|
51
|
+
}, z.core.$strip>>;
|
|
52
|
+
pendingTopupCheckout: z.ZodNullable<z.ZodObject<{
|
|
53
|
+
orderId: z.ZodString;
|
|
54
|
+
topupId: z.ZodString;
|
|
55
|
+
creditQuantity: z.ZodNumber;
|
|
56
|
+
status: z.ZodLiteral<"confirmation_pending">;
|
|
57
|
+
}, z.core.$strip>>;
|
|
58
|
+
creditAccount: z.ZodObject<{
|
|
59
|
+
availableUnits: z.ZodNumber;
|
|
60
|
+
topupRemainingUnits: z.ZodNumber;
|
|
61
|
+
otherRemainingUnits: z.ZodNumber;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
currentCreditPeriod: z.ZodNullable<z.ZodObject<{
|
|
64
|
+
startsAt: z.ZodString;
|
|
65
|
+
endsAt: z.ZodString;
|
|
66
|
+
allowanceUnits: z.ZodNumber;
|
|
67
|
+
remainingUnits: z.ZodNumber;
|
|
68
|
+
}, z.core.$strip>>;
|
|
69
|
+
renewAt: z.ZodNullable<z.ZodString>;
|
|
70
|
+
planEndsAt: z.ZodNullable<z.ZodString>;
|
|
71
|
+
nextGrantAt: z.ZodNullable<z.ZodString>;
|
|
72
|
+
nextExpiryAt: z.ZodNullable<z.ZodString>;
|
|
73
|
+
allowedActions: z.ZodArray<z.ZodEnum<{
|
|
74
|
+
subscribe: "subscribe";
|
|
75
|
+
change_plan: "change_plan";
|
|
76
|
+
cancel_subscription: "cancel_subscription";
|
|
77
|
+
resume_subscription: "resume_subscription";
|
|
78
|
+
update_payment_method: "update_payment_method";
|
|
79
|
+
}>>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
export declare const planChangeRequestSchema: z.ZodObject<{
|
|
82
|
+
planId: z.ZodString;
|
|
83
|
+
billingInterval: z.ZodEnum<{
|
|
84
|
+
month: "month";
|
|
85
|
+
year: "year";
|
|
86
|
+
}>;
|
|
87
|
+
returnPath: z.ZodOptional<z.ZodString>;
|
|
88
|
+
}, z.core.$strict>;
|
|
89
|
+
export declare const planCheckoutRequestSchema: z.ZodObject<{
|
|
90
|
+
planId: z.ZodString;
|
|
91
|
+
billingInterval: z.ZodEnum<{
|
|
92
|
+
month: "month";
|
|
93
|
+
year: "year";
|
|
94
|
+
}>;
|
|
95
|
+
idempotencyKey: z.ZodUUID;
|
|
96
|
+
returnPath: z.ZodOptional<z.ZodString>;
|
|
97
|
+
}, z.core.$strict>;
|
|
98
|
+
export declare const topupCheckoutRequestSchema: z.ZodObject<{
|
|
99
|
+
topupId: z.ZodString;
|
|
100
|
+
idempotencyKey: z.ZodUUID;
|
|
101
|
+
returnPath: z.ZodOptional<z.ZodString>;
|
|
102
|
+
}, z.core.$strict>;
|
|
103
|
+
export declare const planChangeSchema: z.ZodObject<{
|
|
104
|
+
confirmationUrl: z.ZodURL;
|
|
105
|
+
}, z.core.$strip>;
|
|
106
|
+
export declare const planCatalogSchema: z.ZodObject<{
|
|
107
|
+
freePlan: z.ZodObject<{
|
|
108
|
+
id: z.ZodString;
|
|
109
|
+
name: z.ZodString;
|
|
110
|
+
allowanceUnits: z.ZodNumber;
|
|
111
|
+
}, z.core.$strip>;
|
|
112
|
+
plans: z.ZodArray<z.ZodObject<{
|
|
113
|
+
id: z.ZodString;
|
|
114
|
+
name: z.ZodString;
|
|
115
|
+
allowanceUnits: z.ZodOptional<z.ZodNumber>;
|
|
116
|
+
topupBonusPercent: z.ZodOptional<z.ZodNumber>;
|
|
117
|
+
billingOptions: z.ZodArray<z.ZodObject<{
|
|
118
|
+
billingInterval: z.ZodEnum<{
|
|
119
|
+
month: "month";
|
|
120
|
+
year: "year";
|
|
121
|
+
}>;
|
|
122
|
+
amount: z.ZodNumber;
|
|
123
|
+
currency: z.ZodString;
|
|
124
|
+
}, z.core.$strip>>;
|
|
125
|
+
}, z.core.$strip>>;
|
|
126
|
+
}, z.core.$strip>;
|
|
127
|
+
export declare const topupCatalogSchema: z.ZodObject<{
|
|
128
|
+
topups: z.ZodArray<z.ZodObject<{
|
|
129
|
+
id: z.ZodString;
|
|
130
|
+
name: z.ZodString;
|
|
131
|
+
baseCreditQuantity: z.ZodNumber;
|
|
132
|
+
bonusCreditQuantity: z.ZodNumber;
|
|
133
|
+
effectiveCreditQuantity: z.ZodNumber;
|
|
134
|
+
amount: z.ZodNumber;
|
|
135
|
+
currency: z.ZodString;
|
|
136
|
+
}, z.core.$strip>>;
|
|
137
|
+
}, z.core.$strip>;
|
|
138
|
+
export declare const topupCatalogQuerySchema: z.ZodObject<{
|
|
139
|
+
planId: z.ZodOptional<z.ZodString>;
|
|
140
|
+
}, z.core.$strip>;
|
|
141
|
+
export declare const accountActivitySchema: z.ZodObject<{
|
|
142
|
+
items: z.ZodArray<z.ZodObject<{
|
|
143
|
+
id: z.ZodString;
|
|
144
|
+
category: z.ZodEnum<{
|
|
145
|
+
credit: "credit";
|
|
146
|
+
spend: "spend";
|
|
147
|
+
removal: "removal";
|
|
148
|
+
}>;
|
|
149
|
+
title: z.ZodString;
|
|
150
|
+
context: z.ZodString;
|
|
151
|
+
amount: z.ZodNumber;
|
|
152
|
+
availableAfter: z.ZodNumber;
|
|
153
|
+
createdAt: z.ZodString;
|
|
154
|
+
chatId: z.ZodNullable<z.ZodString>;
|
|
155
|
+
}, z.core.$strip>>;
|
|
156
|
+
nextBefore: z.ZodNullable<z.ZodString>;
|
|
157
|
+
}, z.core.$strip>;
|
|
158
|
+
export declare const accountRateCardSchema: z.ZodObject<{
|
|
159
|
+
rateVersion: z.ZodNumber;
|
|
160
|
+
effectiveAtMs: z.ZodNumber;
|
|
161
|
+
creditValue: z.ZodNullable<z.ZodObject<{
|
|
162
|
+
basis: z.ZodLiteral<"plus_topup">;
|
|
163
|
+
packageId: z.ZodString;
|
|
164
|
+
currency: z.ZodString;
|
|
165
|
+
amountUsd: z.ZodNumber;
|
|
166
|
+
effectiveCredits: z.ZodNumber;
|
|
167
|
+
creditsPerUsd: z.ZodNumber;
|
|
168
|
+
usdPerCredit: z.ZodNumber;
|
|
169
|
+
}, z.core.$strip>>;
|
|
170
|
+
meters: z.ZodArray<z.ZodObject<{
|
|
171
|
+
meterId: z.ZodString;
|
|
172
|
+
provider: z.ZodString;
|
|
173
|
+
model: z.ZodString;
|
|
174
|
+
prices: z.ZodObject<{
|
|
175
|
+
inputTokens: z.ZodOptional<z.ZodObject<{
|
|
176
|
+
credits: z.ZodNumber;
|
|
177
|
+
per: z.ZodNumber;
|
|
178
|
+
}, z.core.$strip>>;
|
|
179
|
+
outputTokens: z.ZodOptional<z.ZodObject<{
|
|
180
|
+
credits: z.ZodNumber;
|
|
181
|
+
per: z.ZodNumber;
|
|
182
|
+
}, z.core.$strip>>;
|
|
183
|
+
cacheReadTokens: z.ZodOptional<z.ZodObject<{
|
|
184
|
+
credits: z.ZodNumber;
|
|
185
|
+
per: z.ZodNumber;
|
|
186
|
+
}, z.core.$strip>>;
|
|
187
|
+
cacheWriteTokens: z.ZodOptional<z.ZodObject<{
|
|
188
|
+
credits: z.ZodNumber;
|
|
189
|
+
per: z.ZodNumber;
|
|
190
|
+
}, z.core.$strip>>;
|
|
191
|
+
reasoningTokens: z.ZodOptional<z.ZodObject<{
|
|
192
|
+
credits: z.ZodNumber;
|
|
193
|
+
per: z.ZodNumber;
|
|
194
|
+
}, z.core.$strip>>;
|
|
195
|
+
}, z.core.$strip>;
|
|
196
|
+
providerCost: z.ZodNullable<z.ZodObject<{
|
|
197
|
+
provider: z.ZodLiteral<"openrouter">;
|
|
198
|
+
inputUsdPer1M: z.ZodNumber;
|
|
199
|
+
outputUsdPer1M: z.ZodNumber;
|
|
200
|
+
fetchedAt: z.ZodString;
|
|
201
|
+
}, z.core.$strip>>;
|
|
202
|
+
economics: z.ZodObject<{
|
|
203
|
+
input: z.ZodNullable<z.ZodObject<{
|
|
204
|
+
revenueUsdPer1M: z.ZodNumber;
|
|
205
|
+
providerCostUsdPer1M: z.ZodNumber;
|
|
206
|
+
grossProfitUsdPer1M: z.ZodNumber;
|
|
207
|
+
grossMarginPct: z.ZodNumber;
|
|
208
|
+
}, z.core.$strip>>;
|
|
209
|
+
output: z.ZodNullable<z.ZodObject<{
|
|
210
|
+
revenueUsdPer1M: z.ZodNumber;
|
|
211
|
+
providerCostUsdPer1M: z.ZodNumber;
|
|
212
|
+
grossProfitUsdPer1M: z.ZodNumber;
|
|
213
|
+
grossMarginPct: z.ZodNumber;
|
|
214
|
+
}, z.core.$strip>>;
|
|
215
|
+
}, z.core.$strip>;
|
|
216
|
+
}, z.core.$strip>>;
|
|
217
|
+
}, z.core.$strip>;
|
|
218
|
+
export declare const accountUsageDetailsSchema: z.ZodObject<{
|
|
219
|
+
items: z.ZodArray<z.ZodObject<{
|
|
220
|
+
id: z.ZodString;
|
|
221
|
+
eventId: z.ZodString;
|
|
222
|
+
runId: z.ZodString;
|
|
223
|
+
chatId: z.ZodNullable<z.ZodString>;
|
|
224
|
+
chatTitle: z.ZodNullable<z.ZodString>;
|
|
225
|
+
subagentRunId: z.ZodNullable<z.ZodString>;
|
|
226
|
+
parentRunId: z.ZodNullable<z.ZodString>;
|
|
227
|
+
kind: z.ZodEnum<{
|
|
228
|
+
assistant_model: "assistant_model";
|
|
229
|
+
compaction: "compaction";
|
|
230
|
+
subagent: "subagent";
|
|
231
|
+
chat_title: "chat_title";
|
|
232
|
+
}>;
|
|
233
|
+
outcome: z.ZodEnum<{
|
|
234
|
+
billable: "billable";
|
|
235
|
+
user_cancelled: "user_cancelled";
|
|
236
|
+
system_failure: "system_failure";
|
|
237
|
+
provider_failure: "provider_failure";
|
|
238
|
+
missing_trusted_usage: "missing_trusted_usage";
|
|
239
|
+
}>;
|
|
240
|
+
status: z.ZodEnum<{
|
|
241
|
+
settled: "settled";
|
|
242
|
+
platform_owned: "platform_owned";
|
|
243
|
+
anomaly: "anomaly";
|
|
244
|
+
}>;
|
|
245
|
+
rateVersion: z.ZodNumber;
|
|
246
|
+
meterId: z.ZodString;
|
|
247
|
+
provider: z.ZodString;
|
|
248
|
+
model: z.ZodString;
|
|
249
|
+
metrics: z.ZodObject<{
|
|
250
|
+
inputTokens: z.ZodNullable<z.ZodNumber>;
|
|
251
|
+
outputTokens: z.ZodNullable<z.ZodNumber>;
|
|
252
|
+
cacheReadTokens: z.ZodNullable<z.ZodNumber>;
|
|
253
|
+
cacheWriteTokens: z.ZodNullable<z.ZodNumber>;
|
|
254
|
+
reasoningTokens: z.ZodNullable<z.ZodNumber>;
|
|
255
|
+
}, z.core.$strip>;
|
|
256
|
+
ratedUnits: z.ZodNullable<z.ZodNumber>;
|
|
257
|
+
debitedUnits: z.ZodNumber;
|
|
258
|
+
shortfallUnits: z.ZodNumber;
|
|
259
|
+
platformOwnedUnits: z.ZodNullable<z.ZodNumber>;
|
|
260
|
+
platformOwnedReason: z.ZodNullable<z.ZodEnum<{
|
|
261
|
+
chat_title: "chat_title";
|
|
262
|
+
system_failure: "system_failure";
|
|
263
|
+
provider_failure: "provider_failure";
|
|
264
|
+
missing_trusted_usage: "missing_trusted_usage";
|
|
265
|
+
insufficient_balance: "insufficient_balance";
|
|
266
|
+
}>>;
|
|
267
|
+
availableAfter: z.ZodNullable<z.ZodNumber>;
|
|
268
|
+
createdAt: z.ZodString;
|
|
269
|
+
}, z.core.$strip>>;
|
|
270
|
+
nextBefore: z.ZodNullable<z.ZodString>;
|
|
271
|
+
}, z.core.$strip>;
|
|
272
|
+
export type AccountActivity = z.infer<typeof accountActivitySchema>;
|
|
273
|
+
export type AccountAction = z.infer<typeof accountActionSchema>;
|
|
274
|
+
export type AccountSnapshot = z.infer<typeof accountSnapshotSchema>;
|
|
275
|
+
export type AccountRateCard = z.infer<typeof accountRateCardSchema>;
|
|
276
|
+
export type AccountUsageDetails = z.infer<typeof accountUsageDetailsSchema>;
|
|
277
|
+
export type PlanCatalog = z.infer<typeof planCatalogSchema>;
|
|
278
|
+
export type PlanChange = z.infer<typeof planChangeSchema>;
|
|
279
|
+
export type PlanChangeRequest = z.infer<typeof planChangeRequestSchema>;
|
|
280
|
+
export type PlanCheckoutRequest = z.infer<typeof planCheckoutRequestSchema>;
|
|
281
|
+
export type TopupCheckoutRequest = z.infer<typeof topupCheckoutRequestSchema>;
|
|
282
|
+
export type SubscriptionStatus = z.infer<typeof subscriptionStatusSchema>;
|
|
283
|
+
export type TopupCatalog = z.infer<typeof topupCatalogSchema>;
|
|
284
|
+
export type TopupCatalogQuery = z.infer<typeof topupCatalogQuerySchema>;
|
|
285
|
+
export declare const mockCreditCheckoutRequestSchema: z.ZodObject<{
|
|
286
|
+
orderId: z.ZodUUID;
|
|
287
|
+
priceId: z.ZodOptional<z.ZodString>;
|
|
288
|
+
outcome: z.ZodEnum<{
|
|
289
|
+
paid: "paid";
|
|
290
|
+
cancelled: "cancelled";
|
|
291
|
+
}>;
|
|
292
|
+
}, z.core.$strict>;
|
|
293
|
+
export declare const mockCreditCheckoutResultSchema: z.ZodObject<{
|
|
294
|
+
status: z.ZodEnum<{
|
|
295
|
+
paid: "paid";
|
|
296
|
+
cancelled: "cancelled";
|
|
297
|
+
}>;
|
|
298
|
+
}, z.core.$strip>;
|
|
299
|
+
export type MockCreditCheckoutRequest = z.infer<typeof mockCreditCheckoutRequestSchema>;
|
|
300
|
+
export type MockCreditCheckoutResult = z.infer<typeof mockCreditCheckoutResultSchema>;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const subscriptionStatusSchema = z.enum(["active", "canceling", "past_due"]);
|
|
3
|
+
export const accountActionSchema = z.enum([
|
|
4
|
+
"subscribe",
|
|
5
|
+
"change_plan",
|
|
6
|
+
"cancel_subscription",
|
|
7
|
+
"resume_subscription",
|
|
8
|
+
"update_payment_method",
|
|
9
|
+
]);
|
|
10
|
+
export const accountSnapshotSchema = z.object({
|
|
11
|
+
asOf: z.string(),
|
|
12
|
+
reconciliationCompleted: z.boolean(),
|
|
13
|
+
profile: z.object({
|
|
14
|
+
userId: z.string(),
|
|
15
|
+
email: z.email(),
|
|
16
|
+
displayName: z.string(),
|
|
17
|
+
avatarUrl: z.string().nullable(),
|
|
18
|
+
timezone: z.string(),
|
|
19
|
+
}),
|
|
20
|
+
plan: z.object({ id: z.string(), name: z.string() }),
|
|
21
|
+
subscription: z.object({
|
|
22
|
+
status: subscriptionStatusSchema,
|
|
23
|
+
billingInterval: z.enum(["month", "year"]),
|
|
24
|
+
autoRenews: z.boolean(),
|
|
25
|
+
planChangeBlockedReason: z.enum(["subscription_refunded"]).nullable().optional(),
|
|
26
|
+
}).nullable(),
|
|
27
|
+
pendingPlanCheckout: z.object({
|
|
28
|
+
orderId: z.string(),
|
|
29
|
+
planId: z.string(),
|
|
30
|
+
billingInterval: z.enum(["month", "year"]),
|
|
31
|
+
status: z.literal("confirmation_pending"),
|
|
32
|
+
}).nullable(),
|
|
33
|
+
pendingTopupCheckout: z.object({
|
|
34
|
+
orderId: z.string(),
|
|
35
|
+
topupId: z.string(),
|
|
36
|
+
creditQuantity: z.number().int().positive(),
|
|
37
|
+
status: z.literal("confirmation_pending"),
|
|
38
|
+
}).nullable(),
|
|
39
|
+
creditAccount: z.object({
|
|
40
|
+
availableUnits: z.number().int(),
|
|
41
|
+
topupRemainingUnits: z.number().int().nonnegative(),
|
|
42
|
+
otherRemainingUnits: z.number().int().nonnegative(),
|
|
43
|
+
}),
|
|
44
|
+
currentCreditPeriod: z.object({
|
|
45
|
+
startsAt: z.string(),
|
|
46
|
+
endsAt: z.string(),
|
|
47
|
+
allowanceUnits: z.number().int().positive(),
|
|
48
|
+
remainingUnits: z.number().int().nonnegative(),
|
|
49
|
+
}).nullable(),
|
|
50
|
+
renewAt: z.string().nullable(),
|
|
51
|
+
planEndsAt: z.string().nullable(),
|
|
52
|
+
nextGrantAt: z.string().nullable(),
|
|
53
|
+
nextExpiryAt: z.string().nullable(),
|
|
54
|
+
allowedActions: z.array(accountActionSchema),
|
|
55
|
+
});
|
|
56
|
+
const checkoutReturnPathSchema = z.string().trim().max(2048).optional();
|
|
57
|
+
export const planChangeRequestSchema = z.object({
|
|
58
|
+
planId: z.string().trim().min(1).max(100),
|
|
59
|
+
billingInterval: z.enum(["month", "year"]),
|
|
60
|
+
returnPath: checkoutReturnPathSchema,
|
|
61
|
+
}).strict();
|
|
62
|
+
export const planCheckoutRequestSchema = z.object({
|
|
63
|
+
planId: z.string().trim().min(1).max(100),
|
|
64
|
+
billingInterval: z.enum(["month", "year"]),
|
|
65
|
+
idempotencyKey: z.uuid(),
|
|
66
|
+
returnPath: checkoutReturnPathSchema,
|
|
67
|
+
}).strict();
|
|
68
|
+
export const topupCheckoutRequestSchema = z.object({
|
|
69
|
+
topupId: z.string().trim().min(1).max(100),
|
|
70
|
+
idempotencyKey: z.uuid(),
|
|
71
|
+
returnPath: checkoutReturnPathSchema,
|
|
72
|
+
}).strict();
|
|
73
|
+
export const planChangeSchema = z.object({
|
|
74
|
+
confirmationUrl: z.url(),
|
|
75
|
+
});
|
|
76
|
+
export const planCatalogSchema = z.object({
|
|
77
|
+
freePlan: z.object({
|
|
78
|
+
id: z.string(),
|
|
79
|
+
name: z.string(),
|
|
80
|
+
allowanceUnits: z.number().int().nonnegative(),
|
|
81
|
+
}),
|
|
82
|
+
plans: z.array(z.object({
|
|
83
|
+
id: z.string(),
|
|
84
|
+
name: z.string(),
|
|
85
|
+
allowanceUnits: z.number().int().positive().optional(),
|
|
86
|
+
topupBonusPercent: z.number().int().nonnegative().optional(),
|
|
87
|
+
billingOptions: z.array(z.object({
|
|
88
|
+
billingInterval: z.enum(["month", "year"]),
|
|
89
|
+
amount: z.number().int().positive(),
|
|
90
|
+
currency: z.string(),
|
|
91
|
+
})),
|
|
92
|
+
})),
|
|
93
|
+
});
|
|
94
|
+
export const topupCatalogSchema = z.object({
|
|
95
|
+
topups: z.array(z.object({
|
|
96
|
+
id: z.string(),
|
|
97
|
+
name: z.string(),
|
|
98
|
+
baseCreditQuantity: z.number().int().positive(),
|
|
99
|
+
bonusCreditQuantity: z.number().int().nonnegative(),
|
|
100
|
+
effectiveCreditQuantity: z.number().int().positive(),
|
|
101
|
+
amount: z.number().int().positive(),
|
|
102
|
+
currency: z.string(),
|
|
103
|
+
})),
|
|
104
|
+
});
|
|
105
|
+
export const topupCatalogQuerySchema = z.object({
|
|
106
|
+
planId: z.string().trim().min(1).max(100).optional(),
|
|
107
|
+
});
|
|
108
|
+
export const accountActivitySchema = z.object({
|
|
109
|
+
items: z.array(z.object({
|
|
110
|
+
id: z.string(),
|
|
111
|
+
category: z.enum(["credit", "spend", "removal"]),
|
|
112
|
+
title: z.string(),
|
|
113
|
+
context: z.string(),
|
|
114
|
+
amount: z.number().int(),
|
|
115
|
+
availableAfter: z.number().int(),
|
|
116
|
+
createdAt: z.string(),
|
|
117
|
+
chatId: z.string().uuid().nullable(),
|
|
118
|
+
})),
|
|
119
|
+
nextBefore: z.string().nullable(),
|
|
120
|
+
});
|
|
121
|
+
const accountRatePriceSchema = z.object({
|
|
122
|
+
credits: z.number().int().positive(),
|
|
123
|
+
per: z.number().int().positive(),
|
|
124
|
+
});
|
|
125
|
+
const accountRateCardUnitEconomicsSchema = z.object({
|
|
126
|
+
revenueUsdPer1M: z.number().finite().nonnegative(),
|
|
127
|
+
providerCostUsdPer1M: z.number().finite().nonnegative(),
|
|
128
|
+
grossProfitUsdPer1M: z.number().finite(),
|
|
129
|
+
grossMarginPct: z.number().finite(),
|
|
130
|
+
});
|
|
131
|
+
const accountRateCardProviderCostSchema = z.object({
|
|
132
|
+
provider: z.literal("openrouter"),
|
|
133
|
+
inputUsdPer1M: z.number().finite().nonnegative(),
|
|
134
|
+
outputUsdPer1M: z.number().finite().nonnegative(),
|
|
135
|
+
fetchedAt: z.string().datetime(),
|
|
136
|
+
});
|
|
137
|
+
export const accountRateCardSchema = z.object({
|
|
138
|
+
rateVersion: z.number().int().positive(),
|
|
139
|
+
effectiveAtMs: z.number().int().nonnegative(),
|
|
140
|
+
creditValue: z.object({
|
|
141
|
+
basis: z.literal("plus_topup"),
|
|
142
|
+
packageId: z.string(),
|
|
143
|
+
currency: z.string(),
|
|
144
|
+
amountUsd: z.number().positive(),
|
|
145
|
+
effectiveCredits: z.number().int().positive(),
|
|
146
|
+
creditsPerUsd: z.number().positive(),
|
|
147
|
+
usdPerCredit: z.number().positive(),
|
|
148
|
+
}).nullable(),
|
|
149
|
+
meters: z.array(z.object({
|
|
150
|
+
meterId: z.string(),
|
|
151
|
+
provider: z.string(),
|
|
152
|
+
model: z.string(),
|
|
153
|
+
prices: z.object({
|
|
154
|
+
inputTokens: accountRatePriceSchema.optional(),
|
|
155
|
+
outputTokens: accountRatePriceSchema.optional(),
|
|
156
|
+
cacheReadTokens: accountRatePriceSchema.optional(),
|
|
157
|
+
cacheWriteTokens: accountRatePriceSchema.optional(),
|
|
158
|
+
reasoningTokens: accountRatePriceSchema.optional(),
|
|
159
|
+
}),
|
|
160
|
+
providerCost: accountRateCardProviderCostSchema.nullable(),
|
|
161
|
+
economics: z.object({
|
|
162
|
+
input: accountRateCardUnitEconomicsSchema.nullable(),
|
|
163
|
+
output: accountRateCardUnitEconomicsSchema.nullable(),
|
|
164
|
+
}),
|
|
165
|
+
})),
|
|
166
|
+
});
|
|
167
|
+
export const accountUsageDetailsSchema = z.object({
|
|
168
|
+
items: z.array(z.object({
|
|
169
|
+
id: z.string().uuid(),
|
|
170
|
+
eventId: z.string(),
|
|
171
|
+
runId: z.string(),
|
|
172
|
+
chatId: z.string().uuid().nullable(),
|
|
173
|
+
chatTitle: z.string().nullable(),
|
|
174
|
+
subagentRunId: z.string().nullable(),
|
|
175
|
+
parentRunId: z.string().nullable(),
|
|
176
|
+
kind: z.enum(["assistant_model", "compaction", "subagent", "chat_title"]),
|
|
177
|
+
outcome: z.enum(["billable", "user_cancelled", "system_failure", "provider_failure", "missing_trusted_usage"]),
|
|
178
|
+
status: z.enum(["settled", "platform_owned", "anomaly"]),
|
|
179
|
+
rateVersion: z.number().int().positive(),
|
|
180
|
+
meterId: z.string(),
|
|
181
|
+
provider: z.string(),
|
|
182
|
+
model: z.string(),
|
|
183
|
+
metrics: z.object({
|
|
184
|
+
inputTokens: z.number().int().nonnegative().nullable(),
|
|
185
|
+
outputTokens: z.number().int().nonnegative().nullable(),
|
|
186
|
+
cacheReadTokens: z.number().int().nonnegative().nullable(),
|
|
187
|
+
cacheWriteTokens: z.number().int().nonnegative().nullable(),
|
|
188
|
+
reasoningTokens: z.number().int().nonnegative().nullable(),
|
|
189
|
+
}),
|
|
190
|
+
ratedUnits: z.number().int().nonnegative().nullable(),
|
|
191
|
+
debitedUnits: z.number().int().nonnegative(),
|
|
192
|
+
shortfallUnits: z.number().int().nonnegative(),
|
|
193
|
+
platformOwnedUnits: z.number().int().nonnegative().nullable(),
|
|
194
|
+
platformOwnedReason: z.enum([
|
|
195
|
+
"insufficient_balance",
|
|
196
|
+
"chat_title",
|
|
197
|
+
"system_failure",
|
|
198
|
+
"provider_failure",
|
|
199
|
+
"missing_trusted_usage",
|
|
200
|
+
]).nullable(),
|
|
201
|
+
availableAfter: z.number().int().nullable(),
|
|
202
|
+
createdAt: z.string(),
|
|
203
|
+
})),
|
|
204
|
+
nextBefore: z.string().nullable(),
|
|
205
|
+
});
|
|
206
|
+
export const mockCreditCheckoutRequestSchema = z.object({
|
|
207
|
+
orderId: z.uuid(),
|
|
208
|
+
priceId: z.string().min(1).max(255).optional(),
|
|
209
|
+
outcome: z.enum(["paid", "cancelled"]),
|
|
210
|
+
}).strict();
|
|
211
|
+
export const mockCreditCheckoutResultSchema = z.object({ status: z.enum(["paid", "cancelled"]) });
|