@vibedev-si/dsh-vibedev 0.8.0 → 0.9.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 CHANGED
@@ -10,19 +10,39 @@
10
10
 
11
11
  本插件由 `dsh-media` 改名而来,见下面的「从 dsh-media 升级」。
12
12
 
13
+ ## 0.9.0 用户可见更新
14
+
15
+ 模型限时特惠接进来了:
16
+
17
+ - **模型选择器**:网关正在做的活动,其覆盖的模型旁边会显示「限时特惠」徽标。只有当前报价分组在活动范围内时才显示;读不到活动信息时静默不显示,模型列表照常可用。
18
+ - **模型价格页**:带徽标的模型卡片里有完整说明:活动描述、档位(前一天全模型实付满多少、次日几折)、每天可享优惠的额度、活动起止时间和每天 00:10 的更新时间。起止时间取自网关返回,活动结束后徽标自动消失。
19
+ - **使用记录**:享受过优惠的记录显示「限时特惠 −¥x(原价 ¥y)」。优惠金额直接用网关返回的 `promotion_discount`,实付金额用 `actual_cost`。插件不自己折算折扣,也不用「原价 − 实付」倒推——那个差额里可能还有分组倍率或其他优惠。
20
+ - **仪表盘**:今日和累计 Token 卡片增加缓存命中率,算法与用量图表一致:缓存读取 ÷(输入 + 缓存读取 + 缓存创建)。
21
+
22
+ 折扣由网关发放,只对 VibeDev 托管密钥生效;公开 API Key 即使在同一分组也不享受。插件只负责显示,不参与计算。
23
+
24
+ ## 0.8.1 用户可见更新
25
+
26
+ 回复输出到一半时,网关到上游模型服务的连接断开、超时或上游临时出错(5xx、限流),现在和输出开始之前一样按退避自动重试,不再停下来显示「回复暂时中断,已收到的内容已保留。请确认后继续。」(0.6.0 到 0.8.0 会这样)。重试会把这一步从头重新生成:已经显示的半截会清掉,对话里出现一行重试提示和失败原因;这一轮里之前已经完成的步骤和工具结果都保留。所有重试都失败时,对话里显示真实的失败原因。
27
+
28
+ 网关注明无法确认上游是否已经执行、不要自动重发的失败(`SESSION_EXECUTION_UNCONFIRMED`)不会自动重试,以免重复执行、重复扣费。旧版网关用 503 返回这种失败,以前会被当作服务端错误自动重发。
29
+
13
30
  ## 0.8.0 用户可见更新
14
31
 
15
32
  侧边栏的「VibeDev」现在只有账户页面,不再有「插件」分区。浏览、安装和更新插件请到侧边栏的「插件」页,已安装的插件在那里更新。在 VibeDev 应用里,VibeDev 出品的插件列在「发现」里;在 DeepSeek Harness 里按包名安装。
16
33
 
17
- 本插件不再附带 VibeDev 生态。0.6.0 到 0.7.3 的安装包里带有一份生态 0.2.0,并在没有单独安装生态时自动启用它;从 0.8.0 起,安装本插件只安装本插件。你单独安装过的生态仍然可用:它不再出现在 VibeDev 页面里,而是回到自己的侧栏入口「VibeDev 生态」,也可以在「插件」页卸载。
34
+ 本插件不再附带 VibeDev 生态。0.5.0 到 0.7.3 的安装包里带有一份生态 0.2.0,并在没有单独安装生态时自动启用它;从 0.8.0 起,安装本插件只安装本插件。你单独安装过的生态仍然可用:它不再出现在 VibeDev 页面里,而是回到自己的侧栏入口「VibeDev 生态」,也可以在「插件」页卸载。
35
+
36
+ 从 0.5.0 到 0.7.3 升级时,请在「插件」页更新本插件。如果是通过旧版本附带的那份生态来更新的,更新完成后这份生态会一起消失,因为 0.8.0 不再附带它;这是预期结果,之后在「插件」页管理插件。
18
37
 
19
38
  登录、充值、用量和影视工作台里的账户入口不变。
20
39
 
21
- 在列出搜索和抓取提供方的设置页里,本插件的提供方显示为「VibeDev」,不再显示内部标识 `vibedev-gateway`。
40
+ 在列出搜索和抓取提供方的设置页里,本插件的提供方显示为「VibeDev」,不再显示内部标识 `vibedev-gateway`。这需要 DeepSeek Harness 0.2.2-rc.2 或更新的宿主;更早的宿主仍显示内部标识。
22
41
 
23
42
  **给其他插件的作者**:浏览器端的 `vibedevCenter` 服务和 `vibedev.center.section` 插槽已移除,不能再往 VibeDev 页面里挂分区。Host 端打开账户页面的 `vibedevMedia.openAccountCenter({ page })` 不变。
24
43
 
25
44
  ## 0.7.3 用户可见更新
45
+
26
46
  「消息」页和账户中心其他页面一样居中显示,宽窗口里不再贴着左边。
27
47
 
28
48
  VibeDev 开着时发布的 `popup` 公告,现在会在下一次读取消息时弹出:每 5 分钟读一次,窗口回到前台时也会读,不用等下次重启。仍然是一次启动最多弹一次:关掉一条后,之后的 `popup` 公告留到下次启动。
@@ -178,7 +198,7 @@ VibeDev 开着时发布的 `popup` 公告,现在会在下一次读取消息时
178
198
  - 分组和倍率只影响显示:请求、历史记录和模型选择使用网关下发的完整模型 ID,不会去掉 `relay-` 或倍率后缀。不同倍率和无倍率的同名模型保持独立;价格和扣费仍以网关为准,插件不会按名称再乘一次倍率。中转模型保留目录声明的上下文、图片输入和推理档位,并按原模型族选择协议。原来已保存的普通路由与中转模型选择仍可解析。
179
199
  - 没登录就用了 VibeDev 的模型,或登录已失效时,对话里会提示到侧边栏或设置里登录;余额不足时会提示并给出充值链接。这些提示和 DeepSeek 账号的登录、充值提示是分开的。
180
200
  - 访问令牌过期时插件会自动续期并重发请求,不会重复输出。
181
- - 网关到上游模型服务的连接中途断开(例如 `upstream_http2_stream_error`、上游响应流被中断)属于可恢复的传输故障,会和超时、5xx、限流一样按退避自动重试,不再直接判定成一次不可重试的失败;重试会重新发起该次请求,已经输出的内容不会续写。
201
+ - 网关到上游模型服务的连接中途断开(例如 `upstream_http2_stream_error`、上游响应流被中断)属于可恢复的传输故障,会和超时、5xx、限流一样按退避自动重试,不再直接判定成一次不可重试的失败;回复已经输出一部分时也一样(0.8.1 起)。重试会重新发起该次请求,已经输出的内容不会续写。网关注明不要自动重发的失败(`SESSION_EXECUTION_UNCONFIRMED`)不重试。
182
202
  - 0.3.7 起,网关新上架或下架的模型不用退出重新登录就能看到:指针停在侧边栏的 VibeDev 账号行上打开余额卡片、打开账号菜单(显示的余额超过 10 秒时),以及点「刷新」或打开「设置 → VibeDev 账号」时,插件在重新读取余额的同时也重新读取模型列表,最多每分钟一次;余额照常立刻显示,不等模型列表。模型有变化时,选择器里的「VibeDev」组和设置页的「N 个模型」随即更新。没人操作时,仍按原来的方式在启动、登录或切换账号时以及每 30 分钟(`catalogRefreshMinutes`)读取一次,不会定时轮询。
183
203
 
184
204
  ## Claude 提示词缓存(0.3.10)
@@ -310,7 +330,7 @@ VibeDev 开着时发布的 `popup` 公告,现在会在下一次读取消息时
310
330
  ## 从 dsh-media 升级
311
331
 
312
332
  - 先在插件页停用 `dsh-media`,再安装 `@vibedev-si/dsh-vibedev`,然后卸载 `dsh-media`,完全退出再打开应用。两个不能同时启用:它们注册同名的工具,后加载的那个会启动失败。
313
- - 以前由 VibeDev 插件中心代做的「一键切换」随插件中心一起退役了,现在需要按上面的顺序手动做。
333
+ - 以前由 VibeDev 插件中心代做「一键切换」。本插件不再附带插件中心,所以现在按上面的顺序手动做。
314
334
  - 登录状态、进行中的视频和音频任务都会保留,不用重新登录。插件页里的媒体设置(花费确认、保存目录、默认模型)会回到默认值,需要的话重新设一下。
315
335
 
316
336
  ## 隐私
@@ -359,19 +379,39 @@ npm run build
359
379
 
360
380
  ## English
361
381
 
382
+ ### What changes in 0.9.0
383
+
384
+ Model promotions are now visible:
385
+
386
+ - **Model selector**: a 「限时特惠」 badge appears beside each model the gateway currently promotes. It shows only when the account's price group is in the promotion's scope, and hides silently when the promotion cannot be read, so the model list keeps working.
387
+ - **Model prices page**: a promoted card carries the activity description, its spending tiers, the daily discounted amount, the activity window and the daily 00:10 refresh note. The window is whatever the gateway returned, so the badge disappears by itself when the activity ends.
388
+ - **Usage records**: a discounted row shows 「限时特惠 −¥x(原价 ¥y)」. The amount is the gateway's own `promotion_discount`, shown beside `actual_cost`. The plugin never computes a discount and never subtracts the two costs, because that difference can also carry a group multiplier or another discount.
389
+ - **Dashboard**: the today and lifetime token cards carry a cache-hit rate, computed the way the usage charts compute it: cache reads over reads, writes and fresh input.
390
+
391
+ The gateway grants the discount to its managed keys only; a public API key gets none even in the same group. The plugin only displays it.
392
+
393
+ ### What changes in 0.8.1
394
+
395
+ When the connection from the gateway to the upstream model service breaks, times out, or the upstream fails temporarily (5xx, rate limit) after a reply has started, the request is now retried with backoff, as it is before any output, instead of stopping with 「回复暂时中断,已收到的内容已保留。请确认后继续。」 as releases 0.6.0 to 0.8.0 did. A retry generates that step again from its beginning: the partial reply on screen is cleared and the conversation shows a retry row with the failure reason; earlier steps of the turn and their tool results stay. When every retry fails, the conversation shows the real failure reason.
396
+
397
+ A failure the gateway marks as an execution it cannot confirm and must not resubmit automatically (`SESSION_EXECUTION_UNCONFIRMED`) is never retried automatically, so the execution and its charge are not repeated. An older gateway answered it with 503, which used to be resent as a server failure.
398
+
362
399
  ### What changes in 0.8.0
363
400
 
364
401
  The VibeDev sidebar entry now holds the account pages only; its Plugins section is gone. Browse, install and update plugins on the sidebar's Plugins page, where installed plugins update. In the VibeDev app, VibeDev's own plugins are listed under Discover; in DeepSeek Harness they are installed by package name.
365
402
 
366
- This plugin no longer brings the VibeDev Ecosystem with it. Releases 0.6.0 to 0.7.3 carried a copy of Ecosystem 0.2.0 and switched it on when no separately installed ecosystem was present; from 0.8.0, installing this plugin installs this plugin alone. An ecosystem you installed yourself keeps working: it no longer appears inside the VibeDev page and returns to its own sidebar entry, VibeDev Ecosystem. It can be removed on the Plugins page.
403
+ This plugin no longer brings the VibeDev Ecosystem with it. Releases 0.5.0 to 0.7.3 carried a copy of Ecosystem 0.2.0 and switched it on when no separately installed ecosystem was present; from 0.8.0, installing this plugin installs this plugin alone. An ecosystem you installed yourself keeps working: it no longer appears inside the VibeDev page and returns to its own sidebar entry, VibeDev Ecosystem. It can be removed on the Plugins page.
404
+
405
+ When updating from 0.5.0 to 0.7.3, update this plugin on the Plugins page. If you update through the ecosystem copy that the older release brought with it, that copy is gone once the update finishes, because 0.8.0 no longer brings it; this is the expected result, and plugins are managed on the Plugins page from then on.
367
406
 
368
407
  Sign-in, top-up, usage and the account entries in the film workbench are unchanged.
369
408
 
370
- On a settings page that lists search and fetch providers, this plugin's providers appear as "VibeDev" instead of the internal id `vibedev-gateway`.
409
+ On a settings page that lists search and fetch providers, this plugin's providers appear as "VibeDev" instead of the internal id `vibedev-gateway`. This needs a host of DeepSeek Harness 0.2.2-rc.2 or later; an earlier host still shows the id.
371
410
 
372
411
  **For authors of other plugins**: the browser-side `vibedevCenter` service and the `vibedev.center.section` slot are removed, so a section can no longer be mounted into the VibeDev page. The Host-side `vibedevMedia.openAccountCenter({ page })` that opens an account page is unchanged.
373
412
 
374
413
  ### What changes in 0.7.3
414
+
375
415
  The Messages page is centred like the other account-center pages instead of hugging the left edge of a wide window.
376
416
 
377
417
  A `popup` announcement published while VibeDev is open now pops on the next read of the mailbox — every five minutes, and whenever the window comes back — instead of waiting for the next launch. It still interrupts at most once per launch: after one is closed, any further `popup` message waits for the next launch.
@@ -532,7 +572,7 @@ For explicit joint acceptance, run node scripts/verify-fetch-joint.mjs with one
532
572
 
533
573
  **Settings**: open "VibeDev Account & Models" on the Plugins page for the spending confirmation, the output folder and the default media models. `displayName`, `relayDisplayName` (the relay group label, default 中转), `preferredModels`, `openBrowserOnSignIn`, `catalogRefreshMinutes`, `client` (the client name sent with the sign-in, default `vibedev-plugin`), `primary` (show the account as the app's main account; off by default, on in the VibeDev app) and `gatewayFetch` (register the gateway fetch provider `vibedev-gateway`; off by default, and the `web` row's `fetchProvider` still selects it) are set in the profile's `cordis.patch.yml` row `dsh-vibedev`.
534
574
 
535
- **Upgrading from dsh-media**: disable `dsh-media` first, install `@vibedev-si/dsh-vibedev`, uninstall `dsh-media` and restart the app fully. The VibeDev Plugin Center used to do this switch for you; it is retired, so the steps are now done by hand. The two cannot both be enabled: they register the same tool names, and whichever loads second fails to start. The sign-in and running video and audio tasks carry over; the media settings go back to their defaults.
575
+ **Upgrading from dsh-media**: disable `dsh-media` first, install `@vibedev-si/dsh-vibedev`, uninstall `dsh-media` and restart the app fully. The VibeDev Plugin Center used to do this switch for you; this plugin no longer brings it, so the steps are now done by hand. The two cannot both be enabled: they register the same tool names, and whichever loads second fails to start. The sign-in and running video and audio tasks carry over; the media settings go back to their defaults.
536
576
 
537
577
  **Privacy**: prompts and reference media are sent to the VibeDev gateway, which forwards them to the model provider. The plugin's own sign-in is kept in the DeepSeek Harness credential store, and task records under `dsh-media/` in the DeepSeek Harness data folder (the former name, kept so an upgrade loses nothing).
538
578
 
@@ -1,4 +1,4 @@
1
- THIRD-PARTY NOTICES · @vibedev-si/dsh-vibedev 0.8.0
1
+ THIRD-PARTY NOTICES · @vibedev-si/dsh-vibedev 0.9.0
2
2
 
3
3
  This package bundles code from the projects below. Each is used under the licence that
4
4
  follows its name; the licence texts are reproduced as the projects ship them.
@@ -322,6 +322,13 @@ window.__ModuleLoader__.load({
322
322
  const priceFactFields = Object.keys(factText);
323
323
  const facts = (index) => Object.fromEntries(Object.entries(factText).map(([key, values]) => [`priceFact_${key}`, values[index]]));
324
324
  const priceZh = {
325
+ pricePromoBadge: "限时特惠",
326
+ pricePromoTitle: "限时特惠",
327
+ pricePromoTier: "{min} 及以上 → {rate}",
328
+ pricePromoRate: "{percent} 折",
329
+ pricePromoCap: "每天前 ¥{amount} 的 {model} 消费享受折扣",
330
+ pricePromoUpdated: "北京时间每天 00:10 更新",
331
+ pricePromoWindow: "活动时间 {from} – {to}",
325
332
  ...facts(0),
326
333
  priceTitle: "模型价格",
327
334
  priceIntro: "当前已发布目录与分组售价。仅供阅读,不是报价单或账单;最终扣费以实际用量与计费结果为准。",
@@ -458,6 +465,13 @@ window.__ModuleLoader__.load({
458
465
  priceNoteImageEstimate: "约:按官方输出 Token 示例推导,仅含图片输出,不含提示词、参考图、文字/思考和工具费用。"
459
466
  };
460
467
  const priceEn = {
468
+ pricePromoBadge: "Limited-time offer",
469
+ pricePromoTitle: "Limited-time offer",
470
+ pricePromoTier: "{min} and above → {rate}",
471
+ pricePromoRate: "{percent}% off",
472
+ pricePromoCap: "The first ¥{amount} of {model} spend each day is discounted",
473
+ pricePromoUpdated: "Refreshed daily at 00:10 Beijing time",
474
+ pricePromoWindow: "Activity window {from} – {to}",
461
475
  ...facts(1),
462
476
  priceTitle: "Model prices",
463
477
  priceIntro: "Current published catalog and group retail prices. Not a quote or ledger; final charges follow actual usage and billing results.",
@@ -1516,6 +1530,8 @@ window.__ModuleLoader__.load({
1516
1530
  //#endregion
1517
1531
  //#region src/client/AccountCenter/center-locales.ts
1518
1532
  const centerZh = {
1533
+ centerUsagePromo: "限时特惠 −{discount}(原价 {total})",
1534
+ centerCacheHitRate: "缓存命中率",
1519
1535
  ...commerceZh,
1520
1536
  ...memberZh,
1521
1537
  ...businessZh,
@@ -1662,6 +1678,8 @@ window.__ModuleLoader__.load({
1662
1678
  centerBooleanNo: "否"
1663
1679
  };
1664
1680
  const centerEn = {
1681
+ centerUsagePromo: "Limited-time offer −{discount} (standard {total})",
1682
+ centerCacheHitRate: "Cache hit rate",
1665
1683
  ...commerceEn,
1666
1684
  ...memberEn,
1667
1685
  ...businessEn,
@@ -2441,6 +2459,22 @@ window.__ModuleLoader__.load({
2441
2459
  return "—";
2442
2460
  }
2443
2461
  }
2462
+ /**
2463
+ * One usage row's promotion line, from the gateway's own discount.
2464
+ *
2465
+ * `actual_cost` is what was charged and `total_cost` the list price, but their
2466
+ * difference also carries group multipliers and other discounts, so it is never
2467
+ * used to infer this amount: `promotion_discount` is the only source.
2468
+ * @param row - one usage row.
2469
+ * @param t - the page's translate function.
2470
+ * @returns the sentence, or undefined when the row received no promotion.
2471
+ */
2472
+ function promotionText(row, t) {
2473
+ const discount = numeric(row.promotion_discount);
2474
+ if (discount === void 0 || discount <= 0) return void 0;
2475
+ const currency = typeof row.currency === "string" && /^[A-Z]{3}$/.test(row.currency) ? row.currency : "CNY";
2476
+ return t("centerUsagePromo").replace("{discount}", money(discount, currency)).replace("{total}", money(row.total_cost, currency));
2477
+ }
2444
2478
  function dateTime(value, t) {
2445
2479
  if (typeof value !== "string" || !Number.isFinite(Date.parse(value))) return "—";
2446
2480
  return new Date(value).toLocaleString(t?.("localeTag") === "en" ? "en-US" : t === void 0 ? void 0 : "zh-CN", {
@@ -3290,6 +3324,15 @@ window.__ModuleLoader__.load({
3290
3324
  }
3291
3325
  function DashboardMetrics({ stats, view, t }) {
3292
3326
  const currency = stats.currency ?? "CNY";
3327
+ /**
3328
+ * The share of prompt tokens the provider served from its cache, using the same
3329
+ * arithmetic the usage charts use: reads over reads, writes and fresh input.
3330
+ */
3331
+ const cacheRate = (prefix) => {
3332
+ const input = numeric(stats[`${prefix}input_tokens`]), read = numeric(stats[`${prefix}cache_read_tokens`]), created = numeric(stats[`${prefix}cache_creation_tokens`]);
3333
+ if (input === void 0 || read === void 0 || created === void 0 || input + read + created <= 0) return "—";
3334
+ return `${new Intl.NumberFormat(void 0, { maximumFractionDigits: 1 }).format(read / (input + read + created) * 100)}%`;
3335
+ };
3293
3336
  const tokenRows = (prefix) => [
3294
3337
  [t("centerInputTokens"), count(stats[`${prefix}input_tokens`])],
3295
3338
  [t("centerOutputTokens"), count(stats[`${prefix}output_tokens`])],
@@ -3324,12 +3367,12 @@ window.__ModuleLoader__.load({
3324
3367
  {
3325
3368
  title: t("centerTodayTokens"),
3326
3369
  value: count(stats.today_tokens),
3327
- rows: tokenRows("today_").slice(0, 2)
3370
+ rows: [...tokenRows("today_").slice(0, 2), [t("centerCacheHitRate"), cacheRate("today_")]]
3328
3371
  },
3329
3372
  {
3330
3373
  title: t("centerTotalTokens"),
3331
3374
  value: count(stats.total_tokens),
3332
- rows: tokenRows("total_").slice(0, 2)
3375
+ rows: [...tokenRows("total_").slice(0, 2), [t("centerCacheHitRate"), cacheRate("total_")]]
3333
3376
  },
3334
3377
  {
3335
3378
  title: t("centerPerformance"),
@@ -4278,7 +4321,10 @@ window.__ModuleLoader__.load({
4278
4321
  })
4279
4322
  ] })]
4280
4323
  })] });
4281
- case "cost": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FactList, { facts: [[t("centerActual"), amount(row.actual_cost)], [t("centerStandard"), amount(row.total_cost)]] });
4324
+ case "cost": return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(FactList, { facts: [[t("centerActual"), amount(row.actual_cost)], [t("centerStandard"), amount(row.total_cost)]] }), promotionText(row, t) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
4325
+ className: "center-usage-promo",
4326
+ children: promotionText(row, t)
4327
+ })] });
4282
4328
  case "latency": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FactList, { facts: [
4283
4329
  [t("centerDuration"), duration(row.duration_ms)],
4284
4330
  [t("centerFirstToken"), duration(row.first_token_ms)],
@@ -4895,6 +4941,10 @@ window.__ModuleLoader__.load({
4895
4941
  [t("centerCacheWriteCost"), amount(row.cache_creation_cost)]
4896
4942
  ]
4897
4943
  }),
4944
+ promotionText(row, t) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
4945
+ className: "center-usage-promo",
4946
+ children: promotionText(row, t)
4947
+ }),
4898
4948
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
4899
4949
  className: "center-detail-unit-prices",
4900
4950
  children: [
@@ -5990,6 +6040,126 @@ window.__ModuleLoader__.load({
5990
6040
  return `model-plaza?${params}`;
5991
6041
  }
5992
6042
  //#endregion
6043
+ //#region src/client/AccountCenter/promotion-api.ts
6044
+ /**
6045
+ * The 「限时特惠」 list the model page labels prices with, read from this plugin's
6046
+ * own Host route so the renderer never calls the gateway.
6047
+ *
6048
+ * The Host has already narrowed the list to the account's price group and to the
6049
+ * activity window the gateway stated; this module only re-validates the wire
6050
+ * shape, because the answer is network data the page did not construct.
6051
+ *
6052
+ * A promotion is decoration: every failure answers "no promotion", which is what
6053
+ * keeps prices reachable when the gateway cannot describe one.
6054
+ *
6055
+ * @module dsh-vibedev/account-center/promotion-api
6056
+ */
6057
+ /** Where the Host serves the list. */
6058
+ const PROMOTIONS_ROUTE = "/api/dsh-vibedev/promotions";
6059
+ /** No promotions apply; shared so an unlabelled page allocates nothing. */
6060
+ const NO_PROMOTIONS = { items: [] };
6061
+ /** How long one answer stays usable in the page, matching the Host's own cache. */
6062
+ const CACHE_MS = 3e5;
6063
+ /**
6064
+ * The last answer, with the account it was read for: switching accounts must not
6065
+ * show the previous account's group labels for five minutes.
6066
+ */
6067
+ let cached;
6068
+ let inflight;
6069
+ const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
6070
+ const string = (value) => typeof value === "string" && value.trim() !== "" ? value : void 0;
6071
+ const amount = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
6072
+ const identifier = (value) => {
6073
+ const parsed = amount(value);
6074
+ return parsed !== void 0 && Number.isInteger(parsed) && parsed > 0 ? parsed : void 0;
6075
+ };
6076
+ /**
6077
+ * One promotion, or undefined when it cannot be rendered safely.
6078
+ * @param value - one `items[]` entry.
6079
+ * @returns the promotion, or undefined.
6080
+ */
6081
+ function parsePromotion(value) {
6082
+ const source = record(value);
6083
+ if (source === void 0) return void 0;
6084
+ const model = string(source.model);
6085
+ const startsAt = string(source.starts_at);
6086
+ const endsAt = string(source.ends_at);
6087
+ if (model === void 0 || startsAt === void 0 || endsAt === void 0) return void 0;
6088
+ if (!Number.isFinite(Date.parse(startsAt)) || !Number.isFinite(Date.parse(endsAt))) return void 0;
6089
+ const dailyCap = amount(source.daily_cap);
6090
+ const tiers = Array.isArray(source.tiers) ? source.tiers.flatMap((item) => {
6091
+ const tier = record(item);
6092
+ const prevSpendMin = tier === void 0 ? void 0 : amount(tier.prev_spend_min);
6093
+ const discountRate = tier === void 0 ? void 0 : amount(tier.discount_rate);
6094
+ return prevSpendMin === void 0 || discountRate === void 0 || discountRate <= 0 ? [] : [{
6095
+ prevSpendMin,
6096
+ discountRate
6097
+ }];
6098
+ }) : [];
6099
+ return {
6100
+ model,
6101
+ badge: string(source.badge) ?? "限时特惠",
6102
+ description: string(source.description) ?? "",
6103
+ ...dailyCap === void 0 || dailyCap === 0 ? {} : { dailyCap },
6104
+ startsAt,
6105
+ endsAt,
6106
+ tiers: tiers.sort((left, right) => left.prevSpendMin - right.prevSpendMin)
6107
+ };
6108
+ }
6109
+ /**
6110
+ * The whole answer, or none when it is not shaped like one.
6111
+ * @param value - the response body of the Host route.
6112
+ * @returns the listing, or undefined.
6113
+ */
6114
+ function parsePromotionListing(value) {
6115
+ const body = record(value);
6116
+ const data = record(body?.data);
6117
+ const items = data?.items;
6118
+ if (!Array.isArray(items)) return void 0;
6119
+ const groupId = identifier(data?.group_id);
6120
+ return {
6121
+ ...groupId === void 0 ? {} : { groupId },
6122
+ items: items.flatMap((item) => {
6123
+ const parsed = parsePromotion(item);
6124
+ return parsed === void 0 ? [] : [parsed];
6125
+ })
6126
+ };
6127
+ }
6128
+ /**
6129
+ * Read the promotions, from a five-minute cache when one is fresh for this account.
6130
+ * @param options - fetch implementation, clock and the account the page shows, for tests.
6131
+ * @returns the listing, or none when the read fails.
6132
+ */
6133
+ async function readPromotions(options = {}) {
6134
+ const now = options.now ?? Date.now;
6135
+ const identity = options.identity ?? "";
6136
+ if (cached !== void 0 && cached.identity === identity && now() - cached.at < CACHE_MS) return cached.value;
6137
+ if (inflight !== void 0 && inflight.identity === identity) return inflight.read;
6138
+ const read = (async () => {
6139
+ try {
6140
+ const response = await (options.fetch ?? fetch)(PROMOTIONS_ROUTE, { headers: { accept: "application/json" } });
6141
+ if (!response.ok) return NO_PROMOTIONS;
6142
+ return parsePromotionListing(await response.json()) ?? NO_PROMOTIONS;
6143
+ } catch {
6144
+ return NO_PROMOTIONS;
6145
+ }
6146
+ })().then((value) => {
6147
+ cached = {
6148
+ at: now(),
6149
+ identity,
6150
+ value
6151
+ };
6152
+ return value;
6153
+ }).finally(() => {
6154
+ if (inflight?.identity === identity) inflight = void 0;
6155
+ });
6156
+ inflight = {
6157
+ identity,
6158
+ read
6159
+ };
6160
+ return read;
6161
+ }
6162
+ //#endregion
5993
6163
  //#region src/client/AccountCenter/ModelPrices.tsx
5994
6164
  const p = (t, key) => t(key);
5995
6165
  const message = (value, t) => {
@@ -6469,7 +6639,48 @@ window.__ModuleLoader__.load({
6469
6639
  })]
6470
6640
  });
6471
6641
  }
6472
- function ModelPriceCard({ model, context, t }) {
6642
+ /**
6643
+ * The label a card may carry: only the promotion whose model id matches exactly,
6644
+ * and only while the page shows the group the account's promotions were read for.
6645
+ * Browsing another group's prices never carries this group's label along.
6646
+ */
6647
+ function promotionOf(model, response, promotions) {
6648
+ if (promotions === void 0 || promotions.groupId === void 0) return void 0;
6649
+ if (Number(response.price_context.group_id) !== promotions.groupId) return void 0;
6650
+ return promotions.items.find((item) => item.model === model.id);
6651
+ }
6652
+ /** What the activity gives, stated as the gateway stated it: description, tiers, daily cap, window. */
6653
+ function PromotionDetails({ promotion, model, t }) {
6654
+ const english = t("localeTag") === "en";
6655
+ const rate = (value) => p(t, "pricePromoRate").replace("{percent}", String(english ? Math.round((1 - value) * 1e3) / 10 : Math.round(value * 100) / 10));
6656
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
6657
+ className: "center-price-detail-block center-price-promotion",
6658
+ children: [
6659
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", { children: p(t, "pricePromoTitle") }),
6660
+ promotion.description !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6661
+ className: "center-price-description",
6662
+ children: promotion.description
6663
+ }),
6664
+ promotion.tiers.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
6665
+ className: "center-price-promo-tiers",
6666
+ children: promotion.tiers.map((tier) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", { children: p(t, "pricePromoTier").replace("{min}", `¥${priceAmount(tier.prevSpendMin)}`).replace("{rate}", rate(tier.discountRate)) }, tier.prevSpendMin))
6667
+ }),
6668
+ promotion.dailyCap !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6669
+ className: "center-muted",
6670
+ children: p(t, "pricePromoCap").replace("{amount}", priceAmount(promotion.dailyCap)).replace("{model}", model.name || model.id)
6671
+ }),
6672
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6673
+ className: "center-muted",
6674
+ children: p(t, "pricePromoWindow").replace("{from}", dateTime(promotion.startsAt, t)).replace("{to}", dateTime(promotion.endsAt, t))
6675
+ }),
6676
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6677
+ className: "center-muted",
6678
+ children: p(t, "pricePromoUpdated")
6679
+ })
6680
+ ]
6681
+ });
6682
+ }
6683
+ function ModelPriceCard({ model, context, promotion, t }) {
6473
6684
  const [scenario, setScenario] = (0, react.useState)(() => ({
6474
6685
  ...defaultScenario(),
6475
6686
  resolution: (model.kind === "image" ? model.capabilities.image_sizes?.[0] : model.capabilities.video?.resolutions?.[0]) ?? defaultScenario().resolution,
@@ -6492,7 +6703,10 @@ window.__ModuleLoader__.load({
6492
6703
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6493
6704
  className: "center-price-model",
6494
6705
  children: [
6495
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: model.name || model.id }),
6706
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("h3", { children: [model.name || model.id, promotion && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6707
+ className: "center-price-tag center-price-promo-badge",
6708
+ children: promotion.badge || p(t, "pricePromoBadge")
6709
+ })] }),
6496
6710
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: model.id }),
6497
6711
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6498
6712
  className: "center-price-tags",
@@ -6584,6 +6798,11 @@ window.__ModuleLoader__.load({
6584
6798
  })
6585
6799
  ]
6586
6800
  }),
6801
+ promotion && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PromotionDetails, {
6802
+ promotion,
6803
+ model,
6804
+ t
6805
+ }),
6587
6806
  model.description && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
6588
6807
  className: "center-price-detail-block",
6589
6808
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", { children: p(t, "priceModelDescription") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
@@ -6601,7 +6820,7 @@ window.__ModuleLoader__.load({
6601
6820
  ]
6602
6821
  });
6603
6822
  }
6604
- function PriceCatalog({ response, filters, onChange, t }) {
6823
+ function PriceCatalog({ response, filters, promotions, onChange, t }) {
6605
6824
  const pagination = response?.pagination, pages = pagination ? Math.max(1, Math.ceil(pagination.total / Math.max(1, pagination.page_size))) : 1;
6606
6825
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6607
6826
  className: "center-price-catalog",
@@ -6699,6 +6918,7 @@ window.__ModuleLoader__.load({
6699
6918
  children: [response.models.map((model) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelPriceCard, {
6700
6919
  model,
6701
6920
  context: response.reference_context,
6921
+ promotion: promotionOf(model, response, promotions),
6702
6922
  t
6703
6923
  }, `${response.price_context.group_id}:${model.id}`)), response.models.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6704
6924
  className: "center-muted center-price-empty",
@@ -6747,7 +6967,16 @@ window.__ModuleLoader__.load({
6747
6967
  search: ""
6748
6968
  };
6749
6969
  function ModelPrices({ identity, refresh, t }) {
6750
- const [filters, setFilters] = (0, react.useState)(initialFilters), [search, setSearch] = (0, react.useState)("");
6970
+ const [filters, setFilters] = (0, react.useState)(initialFilters), [search, setSearch] = (0, react.useState)(""), [promotions, setPromotions] = (0, react.useState)(void 0);
6971
+ (0, react.useEffect)(() => {
6972
+ let live = true;
6973
+ readPromotions({ identity }).then((value) => {
6974
+ if (live) setPromotions(value);
6975
+ });
6976
+ return () => {
6977
+ live = false;
6978
+ };
6979
+ }, [identity]);
6751
6980
  (0, react.useEffect)(() => {
6752
6981
  const timer = setTimeout(() => setSearch(filters.search), 250);
6753
6982
  return () => clearTimeout(timer);
@@ -6777,6 +7006,7 @@ window.__ModuleLoader__.load({
6777
7006
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PriceCatalog, {
6778
7007
  response: data,
6779
7008
  filters,
7009
+ promotions,
6780
7010
  onChange: (patch) => setFilters((current) => ({
6781
7011
  ...current,
6782
7012
  ...patch
package/client/client.js CHANGED
@@ -1220,6 +1220,13 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1220
1220
  Object.keys(factText);
1221
1221
  const facts = (index) => Object.fromEntries(Object.entries(factText).map(([key, values]) => [`priceFact_${key}`, values[index]]));
1222
1222
  const priceZh = {
1223
+ pricePromoBadge: "限时特惠",
1224
+ pricePromoTitle: "限时特惠",
1225
+ pricePromoTier: "{min} 及以上 → {rate}",
1226
+ pricePromoRate: "{percent} 折",
1227
+ pricePromoCap: "每天前 ¥{amount} 的 {model} 消费享受折扣",
1228
+ pricePromoUpdated: "北京时间每天 00:10 更新",
1229
+ pricePromoWindow: "活动时间 {from} – {to}",
1223
1230
  ...facts(0),
1224
1231
  priceTitle: "模型价格",
1225
1232
  priceIntro: "当前已发布目录与分组售价。仅供阅读,不是报价单或账单;最终扣费以实际用量与计费结果为准。",
@@ -1356,6 +1363,13 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1356
1363
  priceNoteImageEstimate: "约:按官方输出 Token 示例推导,仅含图片输出,不含提示词、参考图、文字/思考和工具费用。"
1357
1364
  };
1358
1365
  const priceEn = {
1366
+ pricePromoBadge: "Limited-time offer",
1367
+ pricePromoTitle: "Limited-time offer",
1368
+ pricePromoTier: "{min} and above → {rate}",
1369
+ pricePromoRate: "{percent}% off",
1370
+ pricePromoCap: "The first ¥{amount} of {model} spend each day is discounted",
1371
+ pricePromoUpdated: "Refreshed daily at 00:10 Beijing time",
1372
+ pricePromoWindow: "Activity window {from} – {to}",
1359
1373
  ...facts(1),
1360
1374
  priceTitle: "Model prices",
1361
1375
  priceIntro: "Current published catalog and group retail prices. Not a quote or ledger; final charges follow actual usage and billing results.",
@@ -2400,6 +2414,8 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
2400
2414
  //#endregion
2401
2415
  //#region src/client/AccountCenter/center-locales.ts
2402
2416
  const centerZh = {
2417
+ centerUsagePromo: "限时特惠 −{discount}(原价 {total})",
2418
+ centerCacheHitRate: "缓存命中率",
2403
2419
  ...commerceZh,
2404
2420
  ...memberZh,
2405
2421
  ...businessZh,
@@ -2546,6 +2562,8 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
2546
2562
  centerBooleanNo: "否"
2547
2563
  };
2548
2564
  const centerEn = {
2565
+ centerUsagePromo: "Limited-time offer −{discount} (standard {total})",
2566
+ centerCacheHitRate: "Cache hit rate",
2549
2567
  ...commerceEn,
2550
2568
  ...memberEn,
2551
2569
  ...businessEn,
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The model page's 「限时特惠」 labels, read from the gateway by the Host so the
3
+ * renderer never talks to the gateway itself.
4
+ *
5
+ * - `GET /api/dsh-vibedev/promotions` — the promotions the account's own price
6
+ * group runs right now, already narrowed by the group and by the activity
7
+ * window the gateway stated. The page additionally keeps only the entries that
8
+ * name the group it is showing, so browsing another group's prices never
9
+ * carries this group's label along.
10
+ *
11
+ * The answer is always `200`: a promotion is decoration, and a gateway that
12
+ * cannot describe one must not stop a page from showing prices. It is never
13
+ * cached, because the page reads it once per open and the five-minute cache
14
+ * lives in {@link PromotionService}.
15
+ *
16
+ * @module dsh-vibedev/account/promotions
17
+ */
18
+ import type { ConnectionFetchRoute } from '@deepseek-ai/dsh-client-connection';
19
+ import type { ActivePromotion, PromotionService } from '../llm/promotions.js';
20
+ /** The Host route the model page reads. */
21
+ export declare const PROMOTIONS_ROUTE = "/api/dsh-vibedev/promotions";
22
+ /** One answer of the route. */
23
+ export interface PromotionListing {
24
+ /** The account's price group, so a page can keep the labels on that group's prices only. */
25
+ readonly group_id?: number;
26
+ readonly items: readonly ActivePromotion[];
27
+ }
28
+ /**
29
+ * The Host routes that serve promotion labels to the account pages.
30
+ * @param promotions - the shared service the model list labels from too.
31
+ * @returns the routes to register on the connection.
32
+ */
33
+ export declare function promotionRoutes(promotions: PromotionService): ConnectionFetchRoute[];