@huaqiu/dsh-auth 0.6.20 → 0.6.22

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,25 @@ 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
+ }
52
+ /** Accept only a finite `quotaRemainPercent`; anything else → unavailable. */
53
+ function normalizeUsage(value) {
54
+ if (value === null || typeof value !== "object") return null;
55
+ const percent = value.quotaRemainPercent;
56
+ return typeof percent === "number" && Number.isFinite(percent) ? { quotaRemainPercent: percent } : null;
57
+ }
39
58
  function createWebServerAuthTransport(base = "/api/v1/huaqiu/auth", doFetch = globalThis.fetch.bind(globalThis)) {
40
59
  return {
41
60
  async pushSession(info) {
@@ -55,16 +74,29 @@ window.__ModuleLoader__.load({
55
74
  const res = await doFetch(`${base}/logout`, { method: "POST" });
56
75
  if (!res.ok) throw new Error(`auth logout push failed: HTTP ${res.status}`);
57
76
  },
58
- async fetchHostMode() {
77
+ async fetchRuntimeConfig() {
59
78
  try {
60
79
  const res = await doFetch(`${base}/config`, {
61
80
  method: "GET",
62
81
  headers: { accept: "application/json" }
63
82
  });
64
- if (!res.ok) return false;
65
- return (await res.json()).hostMode === true;
83
+ if (!res.ok) return {
84
+ hostMode: false,
85
+ subscriptionOrigin: null,
86
+ subscriptionApiBaseUrl: null
87
+ };
88
+ const body = await res.json();
89
+ return {
90
+ hostMode: body.hostMode === true,
91
+ subscriptionOrigin: normalizeOrigin(body.subscriptionOrigin),
92
+ subscriptionApiBaseUrl: normalizeOrigin(body.subscriptionApiBaseUrl)
93
+ };
66
94
  } catch {
67
- return false;
95
+ return {
96
+ hostMode: false,
97
+ subscriptionOrigin: null,
98
+ subscriptionApiBaseUrl: null
99
+ };
68
100
  }
69
101
  },
70
102
  async fetchSession() {
@@ -109,7 +141,7 @@ window.__ModuleLoader__.load({
109
141
  headers: { accept: "application/json" }
110
142
  });
111
143
  if (!res.ok) return null;
112
- return (await res.json()).usage ?? null;
144
+ return normalizeUsage((await res.json()).usage);
113
145
  } catch {
114
146
  return null;
115
147
  }
@@ -118,14 +150,6 @@ window.__ModuleLoader__.load({
118
150
  }
119
151
  /**「Go to profile」destination: the eda.cn account page. */
120
152
  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
153
  const SUBSCRIPTION_PATH = "/subscription";
130
154
  const SUBSCRIPTION_PREFERRED_SIZE = {
131
155
  width: 1400,
@@ -133,12 +157,15 @@ window.__ModuleLoader__.load({
133
157
  };
134
158
  /**
135
159
  * Build the subscription landing URL. Mirrors `buildProfileUrl`: the token is
136
- * always attached — `gen.eda.cn/subscription` consumes it to establish the
160
+ * always attached — the subscription page consumes it to establish the
137
161
  * session and hides it itself. `encodeURIComponent` is required (tokens are
138
162
  * base64-ish and may contain `+`, `/` or `=`).
163
+ *
164
+ * `origin` comes from the node half (HQ Edge → `HQ_AI_ENV`); omitted in
165
+ * standalone DSH, which keeps the PROD fallback.
139
166
  */
140
167
  function buildSubscriptionUrl(options) {
141
- return `${SUBSCRIPTION_ORIGIN}${SUBSCRIPTION_PATH}?token=${encodeURIComponent(options.token)}`;
168
+ return `${(options.origin ?? "https://gen.eda.cn").replace(/\/+$/, "")}${SUBSCRIPTION_PATH}?token=${encodeURIComponent(options.token)}`;
142
169
  }
143
170
  const SUB_API_PREFIX = "/sub-api";
144
171
  const SUB_API_SUCCESS_CODES = [200, 2e5];
@@ -168,18 +195,23 @@ window.__ModuleLoader__.load({
168
195
  };
169
196
  }
170
197
  /**
171
- * Fetch the active subscription quota DIRECTLY from eda.cn
172
- * (`GET {baseUrl}/sub-api/subscriptions/active?userId&productCode` with
173
- * `x-token` + `X-User-Id` headers) — the same API `hq-eda-ai`'s
174
- * `getActiveSubscription` and `hq-edge`'s ERC quota proxy call, so displaying
175
- * the available quota never depends on an hq-edge hop.
198
+ * Fetch the active subscription quota (`GET {baseUrl}/sub-api/subscriptions/
199
+ * active?userId&productCode` with `x-token` + `X-User-Id` headers) — the same
200
+ * API `hq-eda-ai`'s `getActiveSubscription` and `hq-edge`'s ERC quota proxy
201
+ * call.
202
+ *
203
+ * `baseUrl` is the origin the node half derives from the resolved
204
+ * subscription-balances endpoint (`HQ_AI_ENV`), so this call follows the
205
+ * selected environment and DSH Auth never hardcodes a production host. No
206
+ * configured origin → null (the UI shows「—」).
176
207
  *
177
208
  * Returns null when the fetch/unwrap fails (callers decide fail-open vs
178
209
  * fail-closed); a well-formed response always yields a `SubscriptionQuota`
179
210
  * (possibly with `hasSubscription: false`).
180
211
  */
181
212
  async function fetchSubscriptionQuota(options) {
182
- const { userId, token, productCode, baseUrl = "https://www.eda.cn" } = options;
213
+ const { userId, token, productCode, baseUrl } = options;
214
+ if (!baseUrl) return null;
183
215
  const fetchImpl = options.fetchImpl ?? fetch;
184
216
  const url = `${baseUrl}${SUB_API_PREFIX}/subscriptions/active?${new URLSearchParams({
185
217
  userId: String(userId),
@@ -586,6 +618,7 @@ window.__ModuleLoader__.load({
586
618
  "subscription.package": "套餐:{name}",
587
619
  "subscription.quota": "可用次数:{count}",
588
620
  "subscription.quotaCount": "{used} / {total}次",
621
+ "subscription.quotaPercent": "{percent}%",
589
622
  "subscription.noQuota": "无可用次数",
590
623
  "subscription.unsubscribed": "未订阅",
591
624
  "subscription.subscribe": "订阅 / 升级",
@@ -596,8 +629,7 @@ window.__ModuleLoader__.load({
596
629
  "subscription.upgrade": "订阅 / 升级套餐",
597
630
  "subscription.online": "在线",
598
631
  "subscription.ai": "AI 用量",
599
- "subscription.aiUsageCount": "{available} / {total} 点",
600
- "subscription.aiUsagePercent": "剩余 {percent}%",
632
+ "subscription.aiUsagePercent": "{percent}%",
601
633
  "subscription.aiUsageUnknown": "暂无数据",
602
634
  "card.title": "华秋 EDA AI(eda.cn)登录",
603
635
  "card.desc": "工具「{tool}」需要登录华秋 EDA AI 账号才能继续。请在下方的登录框完成登录(或点击左侧「华秋EDA AI登录」按钮);登录完成后,回复助手「已登录,请重试」,助手会自动重新调用该工具。",
@@ -624,6 +656,7 @@ window.__ModuleLoader__.load({
624
656
  "subscription.package": "Plan: {name}",
625
657
  "subscription.quota": "Available: {count}",
626
658
  "subscription.quotaCount": "{used} / {total}",
659
+ "subscription.quotaPercent": "{percent}%",
627
660
  "subscription.noQuota": "No quota left",
628
661
  "subscription.unsubscribed": "Not subscribed",
629
662
  "subscription.subscribe": "Subscribe / Upgrade",
@@ -634,8 +667,7 @@ window.__ModuleLoader__.load({
634
667
  "subscription.upgrade": "Subscribe / Upgrade plan",
635
668
  "subscription.online": "Online",
636
669
  "subscription.ai": "AI usage",
637
- "subscription.aiUsageCount": "{available} / {total} pts",
638
- "subscription.aiUsagePercent": "{percent}% remaining",
670
+ "subscription.aiUsagePercent": "{percent}%",
639
671
  "subscription.aiUsageUnknown": "No data",
640
672
  "card.title": "Huaqiu EDA AI (eda.cn) login",
641
673
  "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 +1052,16 @@ window.__ModuleLoader__.load({
1020
1052
  let hostMode = false;
1021
1053
  let hostSession = null;
1022
1054
  let hostSessionLoaded = false;
1055
+ /**
1056
+ * Subscription origin resolved by HQ Edge from `HQ_AI_ENV` and served on the
1057
+ * node `/config` route. Null in standalone → lib's PROD fallback.
1058
+ */
1059
+ let subscriptionOrigin = null;
1060
+ /**
1061
+ * Origin of the resolved subscription-balances API (node `/config`). Null
1062
+ * when no environment is configured → GEN/ERC quota calls are skipped.
1063
+ */
1064
+ let subscriptionApiBaseUrl = null;
1023
1065
  const emit = (info) => {
1024
1066
  for (const listener of listeners) listener(info);
1025
1067
  };
@@ -1111,7 +1153,8 @@ window.__ModuleLoader__.load({
1111
1153
  return fetchSubscriptionQuota({
1112
1154
  userId: id,
1113
1155
  token,
1114
- productCode
1156
+ productCode,
1157
+ ...subscriptionApiBaseUrl ? { baseUrl: subscriptionApiBaseUrl } : {}
1115
1158
  });
1116
1159
  },
1117
1160
  getAiTokenUsage: async () => {
@@ -1123,7 +1166,10 @@ window.__ModuleLoader__.load({
1123
1166
  if (hostMode && !hostSessionLoaded) await resolveHost();
1124
1167
  const token = await auth.getAccessToken();
1125
1168
  if (!token) return;
1126
- const url = buildSubscriptionUrl({ token });
1169
+ const url = buildSubscriptionUrl({
1170
+ token,
1171
+ ...subscriptionOrigin ? { origin: subscriptionOrigin } : {}
1172
+ });
1127
1173
  if (hostMode) {
1128
1174
  if (!deps.openHostDialog) return;
1129
1175
  await deps.openHostDialog(url, {
@@ -1187,9 +1233,14 @@ window.__ModuleLoader__.load({
1187
1233
  const prevToken = hostSession?.token ?? storage.get()?.token ?? null;
1188
1234
  let mode = false;
1189
1235
  try {
1190
- mode = await transport.fetchHostMode();
1236
+ const runtime = await transport.fetchRuntimeConfig();
1237
+ mode = runtime.hostMode;
1238
+ subscriptionOrigin = runtime.subscriptionOrigin;
1239
+ subscriptionApiBaseUrl = runtime.subscriptionApiBaseUrl;
1191
1240
  } catch {
1192
1241
  mode = false;
1242
+ subscriptionOrigin = null;
1243
+ subscriptionApiBaseUrl = null;
1193
1244
  }
1194
1245
  hostMode = mode;
1195
1246
  hostSessionLoaded = false;
@@ -1225,6 +1276,8 @@ window.__ModuleLoader__.load({
1225
1276
  hostMode = false;
1226
1277
  hostSession = null;
1227
1278
  hostSessionLoaded = false;
1279
+ subscriptionOrigin = null;
1280
+ subscriptionApiBaseUrl = null;
1228
1281
  }
1229
1282
  };
1230
1283
  }
@@ -1497,18 +1550,28 @@ window.__ModuleLoader__.load({
1497
1550
  * `UserMenu`, portalled to `document.body` with fixed positioning so the
1498
1551
  * sidebar's `overflow: hidden` can never clip it.
1499
1552
  *
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.
1553
+ * THEMING: the LIGHT palette stays token-first (DSH `--dsw-alias-*` with an
1554
+ * explicit fallback), so a custom host theme is honored. The DARK palette is
1555
+ * deliberately EXPLICIT: it follows `docs/prototype/avatar_popup_redesign_prototype.html`,
1556
+ * whose "before" is exactly what the host token produces — `--dsw-alias-bg-overlay`
1557
+ * resolves to `rgb(97, 102, 107)` in dark mode, the muddy medium-gray surface
1558
+ * the prototype calls out as the contrast defect. Keeping the token would
1559
+ * silently re-introduce it, so the popup pins its own deep-slate color schema
1560
+ * instead. `useIsDark()` still selects the pair, driven by the same
1561
+ * `body[data-ds-dark-theme]` snapshot ui-layout's presenter writes.
1505
1562
  */
1506
1563
  const AVATAR_SIZE = 26;
1507
1564
  const ICON_SIZE = 22;
1565
+ /**
1566
+ * Light scheme keeps the DSH token-first convention (custom host themes win).
1567
+ * The extra tokens introduced for the dark redesign are filled with the values
1568
+ * that were previously hardcoded inline, so light rendering is unchanged.
1569
+ */
1508
1570
  const LIGHT_PALETTE = {
1509
1571
  surface: "var(--dsw-alias-bg-overlay, #ffffff)",
1510
1572
  border: "var(--dsw-alias-border-l1, #e4e7ec)",
1511
1573
  text: "var(--dsw-alias-label-primary, #3a4356)",
1574
+ heading: "var(--dsw-alias-label-primary, #3a4356)",
1512
1575
  muted: "var(--dsw-alias-label-secondary, #8a94a6)",
1513
1576
  hover: "var(--dsw-alias-interactive-bg-hover, #f5f7fa)",
1514
1577
  danger: "var(--dsw-alias-state-error-primary, #d4380d)",
@@ -1516,40 +1579,67 @@ window.__ModuleLoader__.load({
1516
1579
  avatarBg: "var(--dsw-alias-bg-layer-2, #eef2f7)",
1517
1580
  shadow: "0 20px 40px -15px rgba(0, 0, 0, 0.12), 0 0 1px 1px rgba(0, 0, 0, 0.05)",
1518
1581
  card: "#f7f8fa",
1582
+ headerBorder: "#e8ebf0",
1519
1583
  cardBorder: "#e8ebf0",
1520
1584
  metric: "#f7f8fa",
1521
1585
  metricHover: "#eef1f5",
1586
+ badgeBg: "rgba(230, 46, 45, 0.08)",
1587
+ badgeText: "#e62e2d",
1588
+ badgeBorder: "rgba(230, 46, 45, 0.08)",
1589
+ online: "#10b981",
1590
+ onlineBg: "rgba(16, 185, 129, 0.10)",
1591
+ onlineBorder: "rgba(16, 185, 129, 0.20)",
1522
1592
  primary: "#e62e2d",
1523
1593
  primaryHover: "#cc2423",
1524
- primarySoft: "rgba(230, 46, 45, 0.08)",
1594
+ ctaEnd: "#e11d48",
1595
+ ctaHoverEnd: "#be123c",
1596
+ ctaShadow: "0 8px 20px rgba(230, 46, 45, 0.22)",
1525
1597
  track: "#e4e7ec",
1598
+ aiIcon: "#10b981",
1526
1599
  genGradient: "linear-gradient(90deg, #3b82f6, #6366f1)",
1527
1600
  ercGradient: "linear-gradient(90deg, #a855f7, #ec4899)",
1528
- aiGradient: "linear-gradient(90deg, #10b981, #06b6d4)",
1529
- online: "#10b981"
1601
+ aiGradient: "linear-gradient(90deg, #10b981, #06b6d4)"
1530
1602
  };
1603
+ /**
1604
+ * Dark color schema from `avatar_popup_redesign_prototype.html` (the "AFTER"
1605
+ * card and the interactive popover's `dark:` classes). Explicit values, not
1606
+ * `var(--dsw-alias-*, …)`: the host's dark `--dsw-alias-bg-overlay` is
1607
+ * `rgb(97, 102, 107)`, the muddy surface the prototype replaces with a crisp
1608
+ * deep slate. Alpha-tinted badges, the cyan→blue meter and the brighter brand
1609
+ * red are the other three contrast fixes the prototype prescribes.
1610
+ */
1531
1611
  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)",
1612
+ surface: "#1C1E24",
1613
+ border: "rgba(255, 255, 255, 0.10)",
1614
+ text: "#e2e8f0",
1615
+ heading: "#ffffff",
1616
+ muted: "#94a3b8",
1617
+ hover: "rgba(255, 255, 255, 0.05)",
1618
+ danger: "#f87171",
1619
+ dangerHover: "rgba(239, 68, 68, 0.10)",
1620
+ avatarBg: "rgba(255, 255, 255, 0.10)",
1621
+ shadow: "0 16px 36px -4px rgba(0, 0, 0, 0.6), 0 0 1px 1px rgba(255, 255, 255, 0.08)",
1622
+ card: "transparent",
1623
+ headerBorder: "transparent",
1624
+ cardBorder: "rgba(255, 255, 255, 0.05)",
1625
+ metric: "#252831",
1626
+ metricHover: "#2C303A",
1627
+ badgeBg: "rgba(239, 68, 68, 0.20)",
1628
+ badgeText: "#f87171",
1629
+ badgeBorder: "rgba(239, 68, 68, 0.20)",
1630
+ online: "#34d399",
1631
+ onlineBg: "rgba(16, 185, 129, 0.10)",
1632
+ onlineBorder: "rgba(16, 185, 129, 0.20)",
1633
+ primary: "#FF4D4F",
1634
+ primaryHover: "#FF6B6D",
1635
+ ctaEnd: "#ef4444",
1636
+ ctaHoverEnd: "#f87171",
1637
+ ctaShadow: "0 8px 20px rgba(255, 77, 79, 0.24)",
1638
+ track: "#334155",
1639
+ aiIcon: "#22d3ee",
1549
1640
  genGradient: "linear-gradient(90deg, #3b82f6, #6366f1)",
1550
1641
  ercGradient: "linear-gradient(90deg, #a855f7, #ec4899)",
1551
- aiGradient: "linear-gradient(90deg, #10b981, #06b6d4)",
1552
- online: "#10b981"
1642
+ aiGradient: "linear-gradient(90deg, #06b6d4, #3b82f6)"
1553
1643
  };
1554
1644
  const TRIGGER_BASE = {
1555
1645
  width: "100%",
@@ -1626,7 +1716,15 @@ window.__ModuleLoader__.load({
1626
1716
  gap: 10,
1627
1717
  minWidth: 0
1628
1718
  },
1629
- children: [icon, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1719
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1720
+ style: {
1721
+ display: "flex",
1722
+ flex: "0 0 auto",
1723
+ color: danger ? palette.danger : hovered ? palette.text : palette.muted,
1724
+ transition: "color 0.15s ease"
1725
+ },
1726
+ children: icon
1727
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1630
1728
  style: {
1631
1729
  overflow: "hidden",
1632
1730
  textOverflow: "ellipsis",
@@ -1689,55 +1787,6 @@ window.__ModuleLoader__.load({
1689
1787
  ]
1690
1788
  });
1691
1789
  }
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
1790
  /** Upgrade-button crown (solid amber like the prototype). */
1742
1791
  function CrownIcon() {
1743
1792
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
@@ -1768,6 +1817,23 @@ window.__ModuleLoader__.load({
1768
1817
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("polyline", { points: "9 18 15 12 9 6" })
1769
1818
  });
1770
1819
  }
1820
+ /** AI usage metric glyph (lucide `sparkles`) — the token balance. */
1821
+ function SparklesIcon({ color }) {
1822
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1823
+ xmlns: "http://www.w3.org/2000/svg",
1824
+ width: 14,
1825
+ height: 14,
1826
+ viewBox: "0 0 24 24",
1827
+ fill: "none",
1828
+ stroke: color,
1829
+ strokeWidth: 2,
1830
+ strokeLinecap: "round",
1831
+ strokeLinejoin: "round",
1832
+ "aria-hidden": true,
1833
+ style: { flex: "0 0 auto" },
1834
+ 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" })]
1835
+ });
1836
+ }
1771
1837
  /** Quota metric card: icon + label, mono count and a gradient progress bar. */
1772
1838
  function QuotaMetric({ label, icon, reading, gradient, palette }) {
1773
1839
  useT();
@@ -1814,7 +1880,7 @@ window.__ModuleLoader__.load({
1814
1880
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1815
1881
  style: {
1816
1882
  fontWeight: 700,
1817
- color: reading?.ok ? palette.text : palette.danger,
1883
+ color: reading?.ok ? palette.heading : palette.danger,
1818
1884
  fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
1819
1885
  fontSize: 12,
1820
1886
  whiteSpace: "nowrap",
@@ -1841,24 +1907,20 @@ window.__ModuleLoader__.load({
1841
1907
  });
1842
1908
  }
1843
1909
  /**
1844
- * GEN / ERC reading from an eda.cn active-subscription payload.
1910
+ * AI reading from the subscription-balances AI Points group.
1845
1911
  *
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.
1912
+ * The percentage is the upstream `quotaRemainPercent` — the REMAINING share —
1913
+ * passed through unchanged: no local ratio and no re-rounding, so `99.68`
1914
+ * renders as `99.68%`. A missing / `null` / non-finite value is unavailable
1915
+ * (the card shows「—」); the bar clamps to 0–100 while the label does not.
1849
1916
  */
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;
1917
+ function aiUsageReading(usage, t) {
1918
+ const percent = usage?.quotaRemainPercent;
1919
+ if (typeof percent !== "number" || !Number.isFinite(percent)) return null;
1855
1920
  return {
1856
- value: quota.hasSubscription ? typeof total === "number" ? t("subscription.quotaCount", {
1857
- used,
1858
- total
1859
- }) : String(used) : t("subscription.unsubscribed"),
1860
- percent,
1861
- ok: quota.hasSubscription
1921
+ value: t("subscription.aiUsagePercent", { percent }),
1922
+ percent: Math.max(0, Math.min(100, percent)),
1923
+ ok: true
1862
1924
  };
1863
1925
  }
1864
1926
  /**
@@ -1874,7 +1936,7 @@ window.__ModuleLoader__.load({
1874
1936
  padding: 10,
1875
1937
  borderRadius: 12,
1876
1938
  background: palette.card,
1877
- border: `1px solid ${palette.cardBorder}`,
1939
+ border: `1px solid ${palette.headerBorder}`,
1878
1940
  display: "flex",
1879
1941
  alignItems: "center",
1880
1942
  justifyContent: "space-between",
@@ -1898,7 +1960,7 @@ window.__ModuleLoader__.load({
1898
1960
  style: {
1899
1961
  fontSize: 14,
1900
1962
  fontWeight: 700,
1901
- color: palette.text,
1963
+ color: palette.heading,
1902
1964
  overflow: "hidden",
1903
1965
  textOverflow: "ellipsis",
1904
1966
  whiteSpace: "nowrap"
@@ -1907,12 +1969,12 @@ window.__ModuleLoader__.load({
1907
1969
  }), packageName ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1908
1970
  style: {
1909
1971
  fontSize: 10,
1910
- background: palette.primarySoft,
1911
- color: palette.primary,
1972
+ background: palette.badgeBg,
1973
+ color: palette.badgeText,
1912
1974
  padding: "2px 6px",
1913
1975
  borderRadius: 4,
1914
1976
  fontWeight: 500,
1915
- border: `1px solid ${palette.primarySoft}`,
1977
+ border: `1px solid ${palette.badgeBorder}`,
1916
1978
  whiteSpace: "nowrap",
1917
1979
  flexShrink: 0
1918
1980
  },
@@ -1933,12 +1995,12 @@ window.__ModuleLoader__.load({
1933
1995
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1934
1996
  style: {
1935
1997
  fontSize: 10,
1936
- background: "rgba(16, 185, 129, 0.10)",
1998
+ background: palette.onlineBg,
1937
1999
  color: palette.online,
1938
2000
  padding: "2px 8px",
1939
2001
  borderRadius: 999,
1940
2002
  fontWeight: 500,
1941
- border: "1px solid rgba(16, 185, 129, 0.20)",
2003
+ border: `1px solid ${palette.onlineBorder}`,
1942
2004
  display: "flex",
1943
2005
  alignItems: "center",
1944
2006
  gap: 5,
@@ -1965,7 +2027,7 @@ window.__ModuleLoader__.load({
1965
2027
  padding: "9px 12px",
1966
2028
  borderRadius: 12,
1967
2029
  border: "none",
1968
- background: subscribing ? `linear-gradient(90deg, ${palette.primary}, #e11d48)` : hovered ? `linear-gradient(90deg, ${palette.primaryHover}, #be123c)` : `linear-gradient(90deg, ${palette.primary}, #e11d48)`,
2030
+ background: hovered && !subscribing ? `linear-gradient(90deg, ${palette.primaryHover}, ${palette.ctaHoverEnd})` : `linear-gradient(90deg, ${palette.primary}, ${palette.ctaEnd})`,
1969
2031
  color: "#ffffff",
1970
2032
  fontSize: 12,
1971
2033
  fontWeight: 600,
@@ -1975,7 +2037,7 @@ window.__ModuleLoader__.load({
1975
2037
  gap: 8,
1976
2038
  cursor: subscribing ? "default" : "pointer",
1977
2039
  opacity: subscribing ? .72 : 1,
1978
- boxShadow: "0 8px 20px rgba(230, 46, 45, 0.22)",
2040
+ boxShadow: palette.ctaShadow,
1979
2041
  transition: "background 0.15s ease, opacity 0.15s ease"
1980
2042
  },
1981
2043
  onMouseEnter: () => setHovered(true),
@@ -2212,26 +2274,20 @@ window.__ModuleLoader__.load({
2212
2274
  },
2213
2275
  children: t("subscription.quotaHeader")
2214
2276
  }),
2215
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2277
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2216
2278
  role: "presentation",
2217
2279
  style: {
2218
2280
  display: "flex",
2219
2281
  flexDirection: "column",
2220
2282
  gap: 8
2221
2283
  },
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,
2284
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuotaMetric, {
2285
+ label: t("subscription.ai"),
2286
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SparklesIcon, { color: palette.aiIcon }),
2287
+ reading: aiUsageReading(quota?.ai ?? null, t),
2288
+ gradient: palette.aiGradient,
2227
2289
  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
- })]
2290
+ })
2235
2291
  }),
2236
2292
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UpgradeButton, {
2237
2293
  subscribing,