@acosmi/sdk-ts 2.12.0 → 2.13.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/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to `@acosmi/sdk-ts` will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.13.0] - 2026-08-01 — 邀请奖励窗口重置券 (window-reset credits)
9
+
10
+ 邀请奖励从"送 token"改为**送窗口重置次数**:被邀请人激活并达到用量门槛后给邀请人发一张重置券,每张可清空一次滚动窗口已用量(只动窗口用量原语,**月度额度池零触碰**)。SDK 加性新增总览查询与核销两个客户端方法,核销支持 `clientRequestId` 幂等键。全部加性,既有调用零改动。
11
+
12
+ ### Added
13
+
14
+ - **`Client.getWindowResetSummary(signal?)`** — 查询当前用户窗口重置券总览(`GET /entitlements/window-reset/summary`);返回 `WindowResetSummary`。`userId` 由网关从鉴权态解析,客户端永不传。用于个人中心邀请栏与 429 窗口限额弹窗展示「还剩几张券 + 最近到期时间 + 邀请进度」。
15
+ - **`Client.redeemWindowReset({ clientRequestId?, signal? })`** — 消费一张重置券清空当前滚动窗口已用量(`POST /entitlements/window-reset/redeem`),返回 `{ remaining }`(扣减后剩余张数)。**幂等键语义**:同一 `clientRequestId` 重放不二次扣券(网关按该键返回首次结果),网络重试 / 用户连点必须复用同一 ID,换 ID = 换一次真实扣券;不传则不幂等。业务错按 SDK 惯例抛 `BusinessError`(message 含机器码):`NO_AVAILABLE_CREDIT`(无可用券)/ `NO_WINDOW_USAGE`(当前窗口无已用量,不扣券)。
16
+ - **`WindowResetSummary`(类型)** — `{ availableCount, nextExpireAt: string | null, totalGranted, totalUsed, qualifiedInvites, pendingInvites }`:可用券张数、可用券中最早到期时间(无券为 `null`)、累计发放 / 已用张数,以及邀请已达标 / 待达标数。
17
+
8
18
  ## [2.12.0] - 2026-07-11 — 5 小时窗口软限额 (windowOverridable + 继续开关)
9
19
 
10
20
  后端把 5 小时窗口改为**软限额**:默认开启(到达 5h 仅提醒、自动继续消耗周配额),用户可关成严格模式(到达即等待恢复);周窗维持硬限。429 响应体加性新增 `windowOverridable`(5h 严格模式=true,可续跑;周窗/显式禁止/灰度关=false,硬等待),额度总览加 `windowFiveHourContinueEnabled` 与 `WindowLimitStatus.overridable`,并新增设置「继续」开关的客户端方法。全部加性,向后兼容——旧字段/旧调用零改动,老网关不返回新字段时按硬等待处理。
package/README.md CHANGED
@@ -582,6 +582,7 @@ const client = new Client({ serverURL: process.env.ACOSMI_SERVER_URL!, store: ne
582
582
  | **Tools** | `listTools`, `getTool` |
583
583
  | **Wallet** | `getWalletStats`, `getWalletTransactions` |
584
584
  | **Entitlements** | `getBalance`, `getBalanceDetail`, `listEntitlements`, `listConsumeRecords`, `claimMonthlyFree`, `getByModel`, `listBuckets`, `listCoefficients`, `invalidateCoefficientCache` |
585
+ | **Entitlements — 窗口重置券**(v2.13.0+) | `getWindowResetSummary`(邀请奖励券总览), `redeemWindowReset`(核销一张券清空当前窗口已用量;`clientRequestId` 为幂等键) |
585
586
  | **Packages** | `listTokenPackages`, `getTokenPackageDetail`, `buyTokenPackage`, `getOrderStatus`, `listMyOrders`, `waitForPayment` |
586
587
  | **Notifications** | `listNotifications`, `getUnreadCount`, `markNotificationRead`, `markAllNotificationsRead`, `deleteNotification`, `registerDevice`, `unregisterDevice`, `listNotificationPreferences`, `updateNotificationPreference` |
587
588
  | **Notifications — WebSocket** | `connect`, `disconnect`, `isConnected` (实时推送订阅;浏览器走原生 WebSocket,Node 18-21 需自装 `ws`,Node 22+ 用原生) |
@@ -2814,6 +2814,46 @@ var Client = class _Client {
2814
2814
  );
2815
2815
  return { enabled: resp.data.enabled };
2816
2816
  }
2817
+ /**
2818
+ * [W-MEMBERSHIP 2026-08-01 邀请奖励] 查询当前用户窗口重置券总览 (v2.13+)。
2819
+ *
2820
+ * 重置券由邀请奖励发放 (被邀请人激活并达到用量门槛后计一次), 每张可清空一次滚动窗口已用量
2821
+ * (见 redeemWindowReset)。userId 由网关从鉴权态解析, 客户端永不传。
2822
+ * 用于个人中心邀请栏与 429 窗口限额弹窗展示"还剩几张券 + 最近到期时间 + 邀请进度"。
2823
+ *
2824
+ * @returns 券余量 / 最近到期 / 累计发放与使用 / 邀请已达标与待达标数。
2825
+ */
2826
+ async getWindowResetSummary(signal) {
2827
+ const resp = await this.doJSON(
2828
+ "GET",
2829
+ "/entitlements/window-reset/summary",
2830
+ null,
2831
+ signal
2832
+ );
2833
+ return resp.data;
2834
+ }
2835
+ /**
2836
+ * [W-MEMBERSHIP 2026-08-01 邀请奖励] 消费一张窗口重置券, 清空当前滚动窗口已用量 (v2.13+)。
2837
+ *
2838
+ * **幂等键语义**: 传 `clientRequestId` 时同一 ID 重放**不会二次扣券** — 网关按该键返回首次
2839
+ * 结果 (`remaining` 与首次一致)。网络重试 / 用户连点必须**复用同一 ID**; 换 ID = 换一次真实
2840
+ * 扣券。不传则不幂等, 每次调用都是一次真实扣券。
2841
+ *
2842
+ * 业务错 (信封 `code != 0`) 按 SDK 惯例抛 `BusinessError` (message 含机器码), 常见两种:
2843
+ * - `NO_AVAILABLE_CREDIT` — 无可用券 (未发放 / 已用尽 / 已过期)
2844
+ * - `NO_WINDOW_USAGE` — 当前窗口无已用量, 无可重置 (不扣券)
2845
+ *
2846
+ * @returns 扣减后剩余可用券张数 { remaining }。
2847
+ */
2848
+ async redeemWindowReset(opts) {
2849
+ const resp = await this.doJSON(
2850
+ "POST",
2851
+ "/entitlements/window-reset/redeem",
2852
+ { clientRequestId: opts?.clientRequestId },
2853
+ opts?.signal
2854
+ );
2855
+ return { remaining: resp.data.remaining };
2856
+ }
2817
2857
  /**
2818
2858
  * 查询单个模型的能力矩阵
2819
2859
  * 优先从 listModels 缓存读取, miss 时调用 listModels 刷新