@huaqiu/dsh-auth 0.6.20 → 0.6.21

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/lib/client.js CHANGED
@@ -36,6 +36,19 @@ window.__ModuleLoader__.load({
36
36
  }
37
37
  //#endregion
38
38
  //#region src/client/transport.ts
39
+ /** Accept only an absolute http(s) origin; anything else → null. */
40
+ function normalizeOrigin(value) {
41
+ if (typeof value !== "string") return null;
42
+ const trimmed = value.trim().replace(/\/+$/, "");
43
+ if (!trimmed) return null;
44
+ try {
45
+ const url = new URL(trimmed);
46
+ if (url.protocol !== "http:" && url.protocol !== "https:") return null;
47
+ return trimmed;
48
+ } catch {
49
+ return null;
50
+ }
51
+ }
39
52
  function createWebServerAuthTransport(base = "/api/v1/huaqiu/auth", doFetch = globalThis.fetch.bind(globalThis)) {
40
53
  return {
41
54
  async pushSession(info) {
@@ -55,16 +68,26 @@ window.__ModuleLoader__.load({
55
68
  const res = await doFetch(`${base}/logout`, { method: "POST" });
56
69
  if (!res.ok) throw new Error(`auth logout push failed: HTTP ${res.status}`);
57
70
  },
58
- async fetchHostMode() {
71
+ async fetchRuntimeConfig() {
59
72
  try {
60
73
  const res = await doFetch(`${base}/config`, {
61
74
  method: "GET",
62
75
  headers: { accept: "application/json" }
63
76
  });
64
- if (!res.ok) return false;
65
- return (await res.json()).hostMode === true;
77
+ if (!res.ok) return {
78
+ hostMode: false,
79
+ subscriptionOrigin: null
80
+ };
81
+ const body = await res.json();
82
+ return {
83
+ hostMode: body.hostMode === true,
84
+ subscriptionOrigin: normalizeOrigin(body.subscriptionOrigin)
85
+ };
66
86
  } catch {
67
- return false;
87
+ return {
88
+ hostMode: false,
89
+ subscriptionOrigin: null
90
+ };
68
91
  }
69
92
  },
70
93
  async fetchSession() {
@@ -118,14 +141,6 @@ window.__ModuleLoader__.load({
118
141
  }
119
142
  /**「Go to profile」destination: the eda.cn account page. */
120
143
  const PROFILE_URL = "https://www.eda.cn/account/profile";
121
- /**
122
- * Subscription landing page — the same page `hq-eda-ai` serves at
123
- * `gen.eda.cn/subscription` (token taken from the URL query; see its
124
- * `UserInfoContext`). The preferred window size for BOTH surfaces (KiCad
125
- * native dialog via DialogService.OpenUrl and the standalone iframe dialog)
126
- * is 1400×740.
127
- */
128
- const SUBSCRIPTION_ORIGIN = "https://gen.eda.cn";
129
144
  const SUBSCRIPTION_PATH = "/subscription";
130
145
  const SUBSCRIPTION_PREFERRED_SIZE = {
131
146
  width: 1400,
@@ -133,12 +148,15 @@ window.__ModuleLoader__.load({
133
148
  };
134
149
  /**
135
150
  * Build the subscription landing URL. Mirrors `buildProfileUrl`: the token is
136
- * always attached — `gen.eda.cn/subscription` consumes it to establish the
151
+ * always attached — the subscription page consumes it to establish the
137
152
  * session and hides it itself. `encodeURIComponent` is required (tokens are
138
153
  * base64-ish and may contain `+`, `/` or `=`).
154
+ *
155
+ * `origin` comes from the node half (HQ Edge → `HQ_AI_ENV`); omitted in
156
+ * standalone DSH, which keeps the PROD fallback.
139
157
  */
140
158
  function buildSubscriptionUrl(options) {
141
- return `${SUBSCRIPTION_ORIGIN}${SUBSCRIPTION_PATH}?token=${encodeURIComponent(options.token)}`;
159
+ return `${(options.origin ?? "https://gen.eda.cn").replace(/\/+$/, "")}${SUBSCRIPTION_PATH}?token=${encodeURIComponent(options.token)}`;
142
160
  }
143
161
  const SUB_API_PREFIX = "/sub-api";
144
162
  const SUB_API_SUCCESS_CODES = [200, 2e5];
@@ -586,6 +604,7 @@ window.__ModuleLoader__.load({
586
604
  "subscription.package": "套餐:{name}",
587
605
  "subscription.quota": "可用次数:{count}",
588
606
  "subscription.quotaCount": "{used} / {total}次",
607
+ "subscription.quotaPercent": "{percent}%",
589
608
  "subscription.noQuota": "无可用次数",
590
609
  "subscription.unsubscribed": "未订阅",
591
610
  "subscription.subscribe": "订阅 / 升级",
@@ -597,7 +616,7 @@ window.__ModuleLoader__.load({
597
616
  "subscription.online": "在线",
598
617
  "subscription.ai": "AI 用量",
599
618
  "subscription.aiUsageCount": "{available} / {total} 点",
600
- "subscription.aiUsagePercent": "剩余 {percent}%",
619
+ "subscription.aiUsagePercent": "{percent}%",
601
620
  "subscription.aiUsageUnknown": "暂无数据",
602
621
  "card.title": "华秋 EDA AI(eda.cn)登录",
603
622
  "card.desc": "工具「{tool}」需要登录华秋 EDA AI 账号才能继续。请在下方的登录框完成登录(或点击左侧「华秋EDA AI登录」按钮);登录完成后,回复助手「已登录,请重试」,助手会自动重新调用该工具。",
@@ -624,6 +643,7 @@ window.__ModuleLoader__.load({
624
643
  "subscription.package": "Plan: {name}",
625
644
  "subscription.quota": "Available: {count}",
626
645
  "subscription.quotaCount": "{used} / {total}",
646
+ "subscription.quotaPercent": "{percent}%",
627
647
  "subscription.noQuota": "No quota left",
628
648
  "subscription.unsubscribed": "Not subscribed",
629
649
  "subscription.subscribe": "Subscribe / Upgrade",
@@ -635,7 +655,7 @@ window.__ModuleLoader__.load({
635
655
  "subscription.online": "Online",
636
656
  "subscription.ai": "AI usage",
637
657
  "subscription.aiUsageCount": "{available} / {total} pts",
638
- "subscription.aiUsagePercent": "{percent}% remaining",
658
+ "subscription.aiUsagePercent": "{percent}%",
639
659
  "subscription.aiUsageUnknown": "No data",
640
660
  "card.title": "Huaqiu EDA AI (eda.cn) login",
641
661
  "card.desc": "Tool \"{tool}\" needs a Huaqiu EDA AI account. Complete the login below (or use the Huaqiu EDA AI button in the sidebar), then reply \"I have logged in, please retry\" so the assistant can retry the tool.",
@@ -1020,6 +1040,11 @@ window.__ModuleLoader__.load({
1020
1040
  let hostMode = false;
1021
1041
  let hostSession = null;
1022
1042
  let hostSessionLoaded = false;
1043
+ /**
1044
+ * Subscription origin resolved by HQ Edge from `HQ_AI_ENV` and served on the
1045
+ * node `/config` route. Null in standalone → lib's PROD fallback.
1046
+ */
1047
+ let subscriptionOrigin = null;
1023
1048
  const emit = (info) => {
1024
1049
  for (const listener of listeners) listener(info);
1025
1050
  };
@@ -1123,7 +1148,10 @@ window.__ModuleLoader__.load({
1123
1148
  if (hostMode && !hostSessionLoaded) await resolveHost();
1124
1149
  const token = await auth.getAccessToken();
1125
1150
  if (!token) return;
1126
- const url = buildSubscriptionUrl({ token });
1151
+ const url = buildSubscriptionUrl({
1152
+ token,
1153
+ ...subscriptionOrigin ? { origin: subscriptionOrigin } : {}
1154
+ });
1127
1155
  if (hostMode) {
1128
1156
  if (!deps.openHostDialog) return;
1129
1157
  await deps.openHostDialog(url, {
@@ -1187,9 +1215,12 @@ window.__ModuleLoader__.load({
1187
1215
  const prevToken = hostSession?.token ?? storage.get()?.token ?? null;
1188
1216
  let mode = false;
1189
1217
  try {
1190
- mode = await transport.fetchHostMode();
1218
+ const runtime = await transport.fetchRuntimeConfig();
1219
+ mode = runtime.hostMode;
1220
+ subscriptionOrigin = runtime.subscriptionOrigin;
1191
1221
  } catch {
1192
1222
  mode = false;
1223
+ subscriptionOrigin = null;
1193
1224
  }
1194
1225
  hostMode = mode;
1195
1226
  hostSessionLoaded = false;
@@ -1225,6 +1256,7 @@ window.__ModuleLoader__.load({
1225
1256
  hostMode = false;
1226
1257
  hostSession = null;
1227
1258
  hostSessionLoaded = false;
1259
+ subscriptionOrigin = null;
1228
1260
  }
1229
1261
  };
1230
1262
  }
@@ -1497,18 +1529,28 @@ window.__ModuleLoader__.load({
1497
1529
  * `UserMenu`, portalled to `document.body` with fixed positioning so the
1498
1530
  * sidebar's `overflow: hidden` can never clip it.
1499
1531
  *
1500
- * THEMING: colors prefer DSH's `--dsw-alias-*` tokens (so a custom host theme
1501
- * is honored) and fall back to an explicit light/dark pair chosen from
1502
- * `useIsDark()`; the two paths cannot disagree, because ui-layout's presenter
1503
- * writes `body[data-ds-dark-theme]` from the very snapshot that installs those
1504
- * tokens.
1532
+ * THEMING: the LIGHT palette stays token-first (DSH `--dsw-alias-*` with an
1533
+ * explicit fallback), so a custom host theme is honored. The DARK palette is
1534
+ * deliberately EXPLICIT: it follows `docs/prototype/avatar_popup_redesign_prototype.html`,
1535
+ * whose "before" is exactly what the host token produces — `--dsw-alias-bg-overlay`
1536
+ * resolves to `rgb(97, 102, 107)` in dark mode, the muddy medium-gray surface
1537
+ * the prototype calls out as the contrast defect. Keeping the token would
1538
+ * silently re-introduce it, so the popup pins its own deep-slate color schema
1539
+ * instead. `useIsDark()` still selects the pair, driven by the same
1540
+ * `body[data-ds-dark-theme]` snapshot ui-layout's presenter writes.
1505
1541
  */
1506
1542
  const AVATAR_SIZE = 26;
1507
1543
  const ICON_SIZE = 22;
1544
+ /**
1545
+ * Light scheme keeps the DSH token-first convention (custom host themes win).
1546
+ * The extra tokens introduced for the dark redesign are filled with the values
1547
+ * that were previously hardcoded inline, so light rendering is unchanged.
1548
+ */
1508
1549
  const LIGHT_PALETTE = {
1509
1550
  surface: "var(--dsw-alias-bg-overlay, #ffffff)",
1510
1551
  border: "var(--dsw-alias-border-l1, #e4e7ec)",
1511
1552
  text: "var(--dsw-alias-label-primary, #3a4356)",
1553
+ heading: "var(--dsw-alias-label-primary, #3a4356)",
1512
1554
  muted: "var(--dsw-alias-label-secondary, #8a94a6)",
1513
1555
  hover: "var(--dsw-alias-interactive-bg-hover, #f5f7fa)",
1514
1556
  danger: "var(--dsw-alias-state-error-primary, #d4380d)",
@@ -1516,40 +1558,67 @@ window.__ModuleLoader__.load({
1516
1558
  avatarBg: "var(--dsw-alias-bg-layer-2, #eef2f7)",
1517
1559
  shadow: "0 20px 40px -15px rgba(0, 0, 0, 0.12), 0 0 1px 1px rgba(0, 0, 0, 0.05)",
1518
1560
  card: "#f7f8fa",
1561
+ headerBorder: "#e8ebf0",
1519
1562
  cardBorder: "#e8ebf0",
1520
1563
  metric: "#f7f8fa",
1521
1564
  metricHover: "#eef1f5",
1565
+ badgeBg: "rgba(230, 46, 45, 0.08)",
1566
+ badgeText: "#e62e2d",
1567
+ badgeBorder: "rgba(230, 46, 45, 0.08)",
1568
+ online: "#10b981",
1569
+ onlineBg: "rgba(16, 185, 129, 0.10)",
1570
+ onlineBorder: "rgba(16, 185, 129, 0.20)",
1522
1571
  primary: "#e62e2d",
1523
1572
  primaryHover: "#cc2423",
1524
- primarySoft: "rgba(230, 46, 45, 0.08)",
1573
+ ctaEnd: "#e11d48",
1574
+ ctaHoverEnd: "#be123c",
1575
+ ctaShadow: "0 8px 20px rgba(230, 46, 45, 0.22)",
1525
1576
  track: "#e4e7ec",
1577
+ aiIcon: "#10b981",
1526
1578
  genGradient: "linear-gradient(90deg, #3b82f6, #6366f1)",
1527
1579
  ercGradient: "linear-gradient(90deg, #a855f7, #ec4899)",
1528
- aiGradient: "linear-gradient(90deg, #10b981, #06b6d4)",
1529
- online: "#10b981"
1580
+ aiGradient: "linear-gradient(90deg, #10b981, #06b6d4)"
1530
1581
  };
1582
+ /**
1583
+ * Dark color schema from `avatar_popup_redesign_prototype.html` (the "AFTER"
1584
+ * card and the interactive popover's `dark:` classes). Explicit values, not
1585
+ * `var(--dsw-alias-*, …)`: the host's dark `--dsw-alias-bg-overlay` is
1586
+ * `rgb(97, 102, 107)`, the muddy surface the prototype replaces with a crisp
1587
+ * deep slate. Alpha-tinted badges, the cyan→blue meter and the brighter brand
1588
+ * red are the other three contrast fixes the prototype prescribes.
1589
+ */
1531
1590
  const DARK_PALETTE = {
1532
- surface: "var(--dsw-alias-bg-overlay, #1e1b24)",
1533
- border: "var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.10))",
1534
- text: "var(--dsw-alias-label-primary, #e6eaf0)",
1535
- muted: "var(--dsw-alias-label-secondary, #8b95a5)",
1536
- hover: "var(--dsw-alias-interactive-bg-hover, rgba(255, 255, 255, 0.08))",
1537
- danger: "var(--dsw-alias-state-error-primary, #ff7875)",
1538
- dangerHover: "rgba(255, 120, 117, 0.14)",
1539
- avatarBg: "var(--dsw-alias-bg-layer-2, rgba(255, 255, 255, 0.10))",
1540
- shadow: "0 20px 40px -15px rgba(0, 0, 0, 0.7), 0 0 1px 1px rgba(255, 255, 255, 0.1)",
1541
- card: "rgba(255, 255, 255, 0.03)",
1542
- cardBorder: "rgba(255, 255, 255, 0.08)",
1543
- metric: "rgba(0, 0, 0, 0.20)",
1544
- metricHover: "rgba(0, 0, 0, 0.30)",
1545
- primary: "#e62e2d",
1546
- primaryHover: "#cc2423",
1547
- primarySoft: "rgba(230, 46, 45, 0.10)",
1548
- track: "rgba(255, 255, 255, 0.10)",
1591
+ surface: "#1C1E24",
1592
+ border: "rgba(255, 255, 255, 0.10)",
1593
+ text: "#e2e8f0",
1594
+ heading: "#ffffff",
1595
+ muted: "#94a3b8",
1596
+ hover: "rgba(255, 255, 255, 0.05)",
1597
+ danger: "#f87171",
1598
+ dangerHover: "rgba(239, 68, 68, 0.10)",
1599
+ avatarBg: "rgba(255, 255, 255, 0.10)",
1600
+ shadow: "0 16px 36px -4px rgba(0, 0, 0, 0.6), 0 0 1px 1px rgba(255, 255, 255, 0.08)",
1601
+ card: "transparent",
1602
+ headerBorder: "transparent",
1603
+ cardBorder: "rgba(255, 255, 255, 0.05)",
1604
+ metric: "#252831",
1605
+ metricHover: "#2C303A",
1606
+ badgeBg: "rgba(239, 68, 68, 0.20)",
1607
+ badgeText: "#f87171",
1608
+ badgeBorder: "rgba(239, 68, 68, 0.20)",
1609
+ online: "#34d399",
1610
+ onlineBg: "rgba(16, 185, 129, 0.10)",
1611
+ onlineBorder: "rgba(16, 185, 129, 0.20)",
1612
+ primary: "#FF4D4F",
1613
+ primaryHover: "#FF6B6D",
1614
+ ctaEnd: "#ef4444",
1615
+ ctaHoverEnd: "#f87171",
1616
+ ctaShadow: "0 8px 20px rgba(255, 77, 79, 0.24)",
1617
+ track: "#334155",
1618
+ aiIcon: "#22d3ee",
1549
1619
  genGradient: "linear-gradient(90deg, #3b82f6, #6366f1)",
1550
1620
  ercGradient: "linear-gradient(90deg, #a855f7, #ec4899)",
1551
- aiGradient: "linear-gradient(90deg, #10b981, #06b6d4)",
1552
- online: "#10b981"
1621
+ aiGradient: "linear-gradient(90deg, #06b6d4, #3b82f6)"
1553
1622
  };
1554
1623
  const TRIGGER_BASE = {
1555
1624
  width: "100%",
@@ -1626,7 +1695,15 @@ window.__ModuleLoader__.load({
1626
1695
  gap: 10,
1627
1696
  minWidth: 0
1628
1697
  },
1629
- children: [icon, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1698
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1699
+ style: {
1700
+ display: "flex",
1701
+ flex: "0 0 auto",
1702
+ color: danger ? palette.danger : hovered ? palette.text : palette.muted,
1703
+ transition: "color 0.15s ease"
1704
+ },
1705
+ children: icon
1706
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1630
1707
  style: {
1631
1708
  overflow: "hidden",
1632
1709
  textOverflow: "ellipsis",
@@ -1689,55 +1766,6 @@ window.__ModuleLoader__.load({
1689
1766
  ]
1690
1767
  });
1691
1768
  }
1692
- /** GEN metric icon (lucide `cpu`, blue like the prototype). */
1693
- function CpuIcon() {
1694
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1695
- xmlns: "http://www.w3.org/2000/svg",
1696
- width: 13,
1697
- height: 13,
1698
- viewBox: "0 0 24 24",
1699
- fill: "none",
1700
- stroke: "#3b82f6",
1701
- strokeWidth: 2,
1702
- strokeLinecap: "round",
1703
- strokeLinejoin: "round",
1704
- "aria-hidden": true,
1705
- style: { flex: "0 0 auto" },
1706
- children: [
1707
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
1708
- x: "4",
1709
- y: "4",
1710
- width: "16",
1711
- height: "16",
1712
- rx: "2"
1713
- }),
1714
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
1715
- x: "9",
1716
- y: "9",
1717
- width: "6",
1718
- height: "6"
1719
- }),
1720
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M9 2v2M15 2v2M9 20v2M15 20v2M2 9h2M2 15h2M20 9h2M20 15h2" })
1721
- ]
1722
- });
1723
- }
1724
- /** ERC metric icon (lucide `waves`, purple like the prototype). */
1725
- function WaveIcon() {
1726
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1727
- xmlns: "http://www.w3.org/2000/svg",
1728
- width: 13,
1729
- height: 13,
1730
- viewBox: "0 0 24 24",
1731
- fill: "none",
1732
- stroke: "#a855f7",
1733
- strokeWidth: 2,
1734
- strokeLinecap: "round",
1735
- strokeLinejoin: "round",
1736
- "aria-hidden": true,
1737
- style: { flex: "0 0 auto" },
1738
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M2 12c1.5-3 3-3 4.5 0s3 3 4.5 0 3-3 4.5 0 3 3 4.5 0" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M2 17c1.5-3 3-3 4.5 0s3 3 4.5 0 3-3 4.5 0 3 3 4.5 0" })]
1739
- });
1740
- }
1741
1769
  /** Upgrade-button crown (solid amber like the prototype). */
1742
1770
  function CrownIcon() {
1743
1771
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
@@ -1768,6 +1796,23 @@ window.__ModuleLoader__.load({
1768
1796
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("polyline", { points: "9 18 15 12 9 6" })
1769
1797
  });
1770
1798
  }
1799
+ /** AI usage metric glyph (lucide `sparkles`) — the token balance. */
1800
+ function SparklesIcon({ color }) {
1801
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1802
+ xmlns: "http://www.w3.org/2000/svg",
1803
+ width: 14,
1804
+ height: 14,
1805
+ viewBox: "0 0 24 24",
1806
+ fill: "none",
1807
+ stroke: color,
1808
+ strokeWidth: 2,
1809
+ strokeLinecap: "round",
1810
+ strokeLinejoin: "round",
1811
+ "aria-hidden": true,
1812
+ style: { flex: "0 0 auto" },
1813
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9L12 3z" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M19 15l.9 2.1L22 18l-2.1.9L19 21l-.9-2.1L16 18l2.1-.9L19 15z" })]
1814
+ });
1815
+ }
1771
1816
  /** Quota metric card: icon + label, mono count and a gradient progress bar. */
1772
1817
  function QuotaMetric({ label, icon, reading, gradient, palette }) {
1773
1818
  useT();
@@ -1814,7 +1859,7 @@ window.__ModuleLoader__.load({
1814
1859
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1815
1860
  style: {
1816
1861
  fontWeight: 700,
1817
- color: reading?.ok ? palette.text : palette.danger,
1862
+ color: reading?.ok ? palette.heading : palette.danger,
1818
1863
  fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
1819
1864
  fontSize: 12,
1820
1865
  whiteSpace: "nowrap",
@@ -1841,24 +1886,35 @@ window.__ModuleLoader__.load({
1841
1886
  });
1842
1887
  }
1843
1888
  /**
1844
- * GEN / ERC reading from an eda.cn active-subscription payload.
1889
+ * AI token reading from `/user-rest/api/ai/usage`.
1890
+ *
1891
+ * The headline number is the AVAILABLE (remaining) balance, not the consumed
1892
+ * one — the same convention as the GEN/ERC cards beside it, which display
1893
+ * `currentQuota` (the REMAINING quota: hq-edge exposes it as
1894
+ * `availableQuota`/"Available Quota", hq-eda-ai as `remainingQuota`). Showing
1895
+ * `usedPoints` here made the AI card the only surface in the product that
1896
+ * reported consumption as the balance: an account that burned 77 of its 100
1897
+ * points read "77 / 100 pts" where the user expects "23 / 100 pts".
1845
1898
  *
1846
- * `hasSubscription` false (or an unknown total) is NOT an error: it is an
1847
- * account with no plan, which reads as 0% plus the "not subscribed" copy in
1848
- * the danger color.
1899
+ * The balance is reported as `usedPoints` + `availablePoints`, so the total is
1900
+ * their sum — there is no separate `totalPoints` field to read. Percent keeps
1901
+ * one decimal: a fresh account has well over 99% of its balance left, and
1902
+ * rounding 99.6% up to "100%" would read as an exhausted account.
1849
1903
  */
1850
- function quotaReading(quota, t) {
1851
- if (!quota) return null;
1852
- const used = quota.currentQuota;
1853
- const total = quota.totalQuota;
1854
- const percent = quota.hasSubscription && typeof total === "number" && total > 0 ? Math.max(0, Math.min(100, Math.round(used / total * 100))) : 0;
1904
+ function aiUsageReading(usage, t) {
1905
+ if (!usage) return null;
1906
+ const used = Math.max(0, usage.usedPoints);
1907
+ const available = Math.max(0, usage.availablePoints);
1908
+ const total = used + available;
1909
+ const percent = total > 0 ? Math.min(100, Math.round(available / total * 1e3) / 10) : 0;
1855
1910
  return {
1856
- value: quota.hasSubscription ? typeof total === "number" ? t("subscription.quotaCount", {
1857
- used,
1911
+ value: t("subscription.aiUsagePercent", { percent: Math.round(percent) }),
1912
+ title: t("subscription.aiUsageCount", {
1913
+ available,
1858
1914
  total
1859
- }) : String(used) : t("subscription.unsubscribed"),
1915
+ }),
1860
1916
  percent,
1861
- ok: quota.hasSubscription
1917
+ ok: true
1862
1918
  };
1863
1919
  }
1864
1920
  /**
@@ -1874,7 +1930,7 @@ window.__ModuleLoader__.load({
1874
1930
  padding: 10,
1875
1931
  borderRadius: 12,
1876
1932
  background: palette.card,
1877
- border: `1px solid ${palette.cardBorder}`,
1933
+ border: `1px solid ${palette.headerBorder}`,
1878
1934
  display: "flex",
1879
1935
  alignItems: "center",
1880
1936
  justifyContent: "space-between",
@@ -1898,7 +1954,7 @@ window.__ModuleLoader__.load({
1898
1954
  style: {
1899
1955
  fontSize: 14,
1900
1956
  fontWeight: 700,
1901
- color: palette.text,
1957
+ color: palette.heading,
1902
1958
  overflow: "hidden",
1903
1959
  textOverflow: "ellipsis",
1904
1960
  whiteSpace: "nowrap"
@@ -1907,12 +1963,12 @@ window.__ModuleLoader__.load({
1907
1963
  }), packageName ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1908
1964
  style: {
1909
1965
  fontSize: 10,
1910
- background: palette.primarySoft,
1911
- color: palette.primary,
1966
+ background: palette.badgeBg,
1967
+ color: palette.badgeText,
1912
1968
  padding: "2px 6px",
1913
1969
  borderRadius: 4,
1914
1970
  fontWeight: 500,
1915
- border: `1px solid ${palette.primarySoft}`,
1971
+ border: `1px solid ${palette.badgeBorder}`,
1916
1972
  whiteSpace: "nowrap",
1917
1973
  flexShrink: 0
1918
1974
  },
@@ -1933,12 +1989,12 @@ window.__ModuleLoader__.load({
1933
1989
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1934
1990
  style: {
1935
1991
  fontSize: 10,
1936
- background: "rgba(16, 185, 129, 0.10)",
1992
+ background: palette.onlineBg,
1937
1993
  color: palette.online,
1938
1994
  padding: "2px 8px",
1939
1995
  borderRadius: 999,
1940
1996
  fontWeight: 500,
1941
- border: "1px solid rgba(16, 185, 129, 0.20)",
1997
+ border: `1px solid ${palette.onlineBorder}`,
1942
1998
  display: "flex",
1943
1999
  alignItems: "center",
1944
2000
  gap: 5,
@@ -1965,7 +2021,7 @@ window.__ModuleLoader__.load({
1965
2021
  padding: "9px 12px",
1966
2022
  borderRadius: 12,
1967
2023
  border: "none",
1968
- background: subscribing ? `linear-gradient(90deg, ${palette.primary}, #e11d48)` : hovered ? `linear-gradient(90deg, ${palette.primaryHover}, #be123c)` : `linear-gradient(90deg, ${palette.primary}, #e11d48)`,
2024
+ background: hovered && !subscribing ? `linear-gradient(90deg, ${palette.primaryHover}, ${palette.ctaHoverEnd})` : `linear-gradient(90deg, ${palette.primary}, ${palette.ctaEnd})`,
1969
2025
  color: "#ffffff",
1970
2026
  fontSize: 12,
1971
2027
  fontWeight: 600,
@@ -1975,7 +2031,7 @@ window.__ModuleLoader__.load({
1975
2031
  gap: 8,
1976
2032
  cursor: subscribing ? "default" : "pointer",
1977
2033
  opacity: subscribing ? .72 : 1,
1978
- boxShadow: "0 8px 20px rgba(230, 46, 45, 0.22)",
2034
+ boxShadow: palette.ctaShadow,
1979
2035
  transition: "background 0.15s ease, opacity 0.15s ease"
1980
2036
  },
1981
2037
  onMouseEnter: () => setHovered(true),
@@ -2212,26 +2268,20 @@ window.__ModuleLoader__.load({
2212
2268
  },
2213
2269
  children: t("subscription.quotaHeader")
2214
2270
  }),
2215
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2271
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2216
2272
  role: "presentation",
2217
2273
  style: {
2218
2274
  display: "flex",
2219
2275
  flexDirection: "column",
2220
2276
  gap: 8
2221
2277
  },
2222
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuotaMetric, {
2223
- label: t("subscription.gen"),
2224
- icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CpuIcon, {}),
2225
- reading: quotaReading(quota?.gen ?? null, t),
2226
- gradient: palette.genGradient,
2278
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuotaMetric, {
2279
+ label: t("subscription.ai"),
2280
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SparklesIcon, { color: palette.aiIcon }),
2281
+ reading: aiUsageReading(quota?.ai ?? null, t),
2282
+ gradient: palette.aiGradient,
2227
2283
  palette
2228
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuotaMetric, {
2229
- label: t("subscription.erc"),
2230
- icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WaveIcon, {}),
2231
- reading: quotaReading(quota?.erc ?? null, t),
2232
- gradient: palette.ercGradient,
2233
- palette
2234
- })]
2284
+ })
2235
2285
  }),
2236
2286
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UpgradeButton, {
2237
2287
  subscribing,