@huaqiu/dsh-auth 0.5.9 → 0.5.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 +124 -27
- package/lib/client.js.map +1 -1
- package/lib/index.mjs +60 -0
- package/package.json +2 -2
- package/src/client/client.ts +16 -0
- package/src/client/i18n.ts +16 -0
- package/src/client/lib.ts +31 -0
- package/src/client/transport.ts +23 -1
- package/src/client/ui/sidebar-action.tsx +118 -26
- package/src/routes.ts +95 -0
package/lib/client.js
CHANGED
|
@@ -101,6 +101,18 @@ window.__ModuleLoader__.load({
|
|
|
101
101
|
} catch {
|
|
102
102
|
return null;
|
|
103
103
|
}
|
|
104
|
+
},
|
|
105
|
+
async fetchAiUsage() {
|
|
106
|
+
try {
|
|
107
|
+
const res = await doFetch(`${base}/ai-usage`, {
|
|
108
|
+
method: "GET",
|
|
109
|
+
headers: { accept: "application/json" }
|
|
110
|
+
});
|
|
111
|
+
if (!res.ok) return null;
|
|
112
|
+
return (await res.json()).usage ?? null;
|
|
113
|
+
} catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
104
116
|
}
|
|
105
117
|
};
|
|
106
118
|
}
|
|
@@ -583,6 +595,10 @@ window.__ModuleLoader__.load({
|
|
|
583
595
|
"subscription.quotaHeader": "套餐与使用额度",
|
|
584
596
|
"subscription.upgrade": "订阅 / 升级套餐",
|
|
585
597
|
"subscription.online": "在线",
|
|
598
|
+
"subscription.ai": "AI 用量",
|
|
599
|
+
"subscription.aiUsageCount": "{used} / {total} 点",
|
|
600
|
+
"subscription.aiUsagePercent": "已使用 {percent}%",
|
|
601
|
+
"subscription.aiUsageUnknown": "暂无数据",
|
|
586
602
|
"card.title": "华秋 EDA AI(eda.cn)登录",
|
|
587
603
|
"card.desc": "工具「{tool}」需要登录华秋 EDA AI 账号才能继续。请在下方的登录框完成登录(或点击左侧「华秋EDA AI登录」按钮);登录完成后,回复助手「已登录,请重试」,助手会自动重新调用该工具。",
|
|
588
604
|
"card.loggedIn": "✓ 已登录{nickname} —— 现在可以回复助手「已登录,请重试」,助手会重新调用工具。",
|
|
@@ -617,6 +633,10 @@ window.__ModuleLoader__.load({
|
|
|
617
633
|
"subscription.quotaHeader": "Plan & usage quota",
|
|
618
634
|
"subscription.upgrade": "Subscribe / Upgrade plan",
|
|
619
635
|
"subscription.online": "Online",
|
|
636
|
+
"subscription.ai": "AI usage",
|
|
637
|
+
"subscription.aiUsageCount": "{used} / {total} pts",
|
|
638
|
+
"subscription.aiUsagePercent": "{percent}% used",
|
|
639
|
+
"subscription.aiUsageUnknown": "No data",
|
|
620
640
|
"card.title": "Huaqiu EDA AI (eda.cn) login",
|
|
621
641
|
"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.",
|
|
622
642
|
"card.loggedIn": "✓ Logged in{nickname} — reply \"I have logged in, please retry\" and the assistant will retry the tool.",
|
|
@@ -1094,6 +1114,11 @@ window.__ModuleLoader__.load({
|
|
|
1094
1114
|
productCode
|
|
1095
1115
|
});
|
|
1096
1116
|
},
|
|
1117
|
+
getAiTokenUsage: async () => {
|
|
1118
|
+
if (hostMode && !hostSessionLoaded) await resolveHost();
|
|
1119
|
+
if (!await auth.getAccessToken()) return null;
|
|
1120
|
+
return transport.fetchAiUsage();
|
|
1121
|
+
},
|
|
1097
1122
|
openSubscriptionDialog: async () => {
|
|
1098
1123
|
if (hostMode && !hostSessionLoaded) await resolveHost();
|
|
1099
1124
|
const token = await auth.getAccessToken();
|
|
@@ -1500,6 +1525,7 @@ window.__ModuleLoader__.load({
|
|
|
1500
1525
|
track: "#e4e7ec",
|
|
1501
1526
|
genGradient: "linear-gradient(90deg, #3b82f6, #6366f1)",
|
|
1502
1527
|
ercGradient: "linear-gradient(90deg, #a855f7, #ec4899)",
|
|
1528
|
+
aiGradient: "linear-gradient(90deg, #10b981, #06b6d4)",
|
|
1503
1529
|
online: "#10b981"
|
|
1504
1530
|
};
|
|
1505
1531
|
const DARK_PALETTE = {
|
|
@@ -1522,6 +1548,7 @@ window.__ModuleLoader__.load({
|
|
|
1522
1548
|
track: "rgba(255, 255, 255, 0.10)",
|
|
1523
1549
|
genGradient: "linear-gradient(90deg, #3b82f6, #6366f1)",
|
|
1524
1550
|
ercGradient: "linear-gradient(90deg, #a855f7, #ec4899)",
|
|
1551
|
+
aiGradient: "linear-gradient(90deg, #10b981, #06b6d4)",
|
|
1525
1552
|
online: "#10b981"
|
|
1526
1553
|
};
|
|
1527
1554
|
const TRIGGER_BASE = {
|
|
@@ -1741,17 +1768,28 @@ window.__ModuleLoader__.load({
|
|
|
1741
1768
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("polyline", { points: "9 18 15 12 9 6" })
|
|
1742
1769
|
});
|
|
1743
1770
|
}
|
|
1771
|
+
/** AI usage metric glyph (lucide `sparkles`) — the token balance. */
|
|
1772
|
+
function SparklesIcon() {
|
|
1773
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
1774
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1775
|
+
width: 14,
|
|
1776
|
+
height: 14,
|
|
1777
|
+
viewBox: "0 0 24 24",
|
|
1778
|
+
fill: "none",
|
|
1779
|
+
stroke: "#10b981",
|
|
1780
|
+
strokeWidth: 2,
|
|
1781
|
+
strokeLinecap: "round",
|
|
1782
|
+
strokeLinejoin: "round",
|
|
1783
|
+
"aria-hidden": true,
|
|
1784
|
+
style: { flex: "0 0 auto" },
|
|
1785
|
+
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" })]
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1744
1788
|
/** Quota metric card: icon + label, mono count and a gradient progress bar. */
|
|
1745
|
-
function QuotaMetric({ label, icon,
|
|
1746
|
-
|
|
1789
|
+
function QuotaMetric({ label, icon, reading, gradient, palette }) {
|
|
1790
|
+
useT();
|
|
1747
1791
|
const [hovered, setHovered] = (0, react.useState)(false);
|
|
1748
|
-
const
|
|
1749
|
-
const total = quota?.totalQuota;
|
|
1750
|
-
const percent = quota?.hasSubscription && typeof total === "number" && total > 0 ? Math.max(0, Math.min(100, Math.round((used ?? 0) / total * 100))) : 0;
|
|
1751
|
-
const value = quota ? quota.hasSubscription ? typeof total === "number" ? t("subscription.quotaCount", {
|
|
1752
|
-
used: used ?? 0,
|
|
1753
|
-
total
|
|
1754
|
-
}) : String(used ?? 0) : t("subscription.unsubscribed") : "—";
|
|
1792
|
+
const value = reading?.value ?? "—";
|
|
1755
1793
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1756
1794
|
role: "presentation",
|
|
1757
1795
|
style: {
|
|
@@ -1793,13 +1831,13 @@ window.__ModuleLoader__.load({
|
|
|
1793
1831
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1794
1832
|
style: {
|
|
1795
1833
|
fontWeight: 700,
|
|
1796
|
-
color:
|
|
1834
|
+
color: reading?.ok ? palette.text : palette.danger,
|
|
1797
1835
|
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
|
|
1798
1836
|
fontSize: 12,
|
|
1799
1837
|
whiteSpace: "nowrap",
|
|
1800
1838
|
flexShrink: 0
|
|
1801
1839
|
},
|
|
1802
|
-
title: value,
|
|
1840
|
+
title: reading?.title ?? value,
|
|
1803
1841
|
children: value
|
|
1804
1842
|
})]
|
|
1805
1843
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -1811,7 +1849,7 @@ window.__ModuleLoader__.load({
|
|
|
1811
1849
|
overflow: "hidden"
|
|
1812
1850
|
},
|
|
1813
1851
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: {
|
|
1814
|
-
width: `${percent}%`,
|
|
1852
|
+
width: `${reading?.percent ?? 0}%`,
|
|
1815
1853
|
height: "100%",
|
|
1816
1854
|
borderRadius: 999,
|
|
1817
1855
|
background: gradient
|
|
@@ -1820,6 +1858,50 @@ window.__ModuleLoader__.load({
|
|
|
1820
1858
|
});
|
|
1821
1859
|
}
|
|
1822
1860
|
/**
|
|
1861
|
+
* GEN / ERC reading from an eda.cn active-subscription payload.
|
|
1862
|
+
*
|
|
1863
|
+
* `hasSubscription` false (or an unknown total) is NOT an error: it is an
|
|
1864
|
+
* account with no plan, which reads as 0% plus the "not subscribed" copy in
|
|
1865
|
+
* the danger color.
|
|
1866
|
+
*/
|
|
1867
|
+
function quotaReading(quota, t) {
|
|
1868
|
+
if (!quota) return null;
|
|
1869
|
+
const used = quota.currentQuota;
|
|
1870
|
+
const total = quota.totalQuota;
|
|
1871
|
+
const percent = quota.hasSubscription && typeof total === "number" && total > 0 ? Math.max(0, Math.min(100, Math.round(used / total * 100))) : 0;
|
|
1872
|
+
return {
|
|
1873
|
+
value: quota.hasSubscription ? typeof total === "number" ? t("subscription.quotaCount", {
|
|
1874
|
+
used,
|
|
1875
|
+
total
|
|
1876
|
+
}) : String(used) : t("subscription.unsubscribed"),
|
|
1877
|
+
percent,
|
|
1878
|
+
ok: quota.hasSubscription
|
|
1879
|
+
};
|
|
1880
|
+
}
|
|
1881
|
+
/**
|
|
1882
|
+
* AI token reading from `/user-rest/api/ai/usage`.
|
|
1883
|
+
*
|
|
1884
|
+
* The balance is reported as `usedPoints` + `availablePoints`, so the total is
|
|
1885
|
+
* their sum — there is no separate `totalPoints` field to read. Percent keeps
|
|
1886
|
+
* one decimal: a fresh account burns well under 1% of its balance, and rounding
|
|
1887
|
+
* 0.6% up to "1%" would overstate consumption fourfold.
|
|
1888
|
+
*/
|
|
1889
|
+
function aiUsageReading(usage, t) {
|
|
1890
|
+
if (!usage) return null;
|
|
1891
|
+
const used = Math.max(0, usage.usedPoints);
|
|
1892
|
+
const total = used + Math.max(0, usage.availablePoints);
|
|
1893
|
+
const percent = total > 0 ? Math.min(100, Math.round(used / total * 1e3) / 10) : 0;
|
|
1894
|
+
return {
|
|
1895
|
+
value: t("subscription.aiUsageCount", {
|
|
1896
|
+
used,
|
|
1897
|
+
total
|
|
1898
|
+
}),
|
|
1899
|
+
title: t("subscription.aiUsagePercent", { percent }),
|
|
1900
|
+
percent,
|
|
1901
|
+
ok: true
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1823
1905
|
* Profile header card (prototype): name + plan badge + phone line on the
|
|
1824
1906
|
* left, an "online" pill on the right. No redundant avatar — the trigger
|
|
1825
1907
|
* already shows it.
|
|
@@ -1997,10 +2079,15 @@ window.__ModuleLoader__.load({
|
|
|
1997
2079
|
return;
|
|
1998
2080
|
}
|
|
1999
2081
|
let cancelled = false;
|
|
2000
|
-
Promise.all([
|
|
2082
|
+
Promise.all([
|
|
2083
|
+
auth?.getSubscriptionQuota?.("auto-design").catch(() => null) ?? Promise.resolve(null),
|
|
2084
|
+
auth?.getSubscriptionQuota?.("erc").catch(() => null) ?? Promise.resolve(null),
|
|
2085
|
+
auth?.getAiTokenUsage?.().catch(() => null) ?? Promise.resolve(null)
|
|
2086
|
+
]).then(([gen, erc, ai]) => {
|
|
2001
2087
|
if (!cancelled) setQuota({
|
|
2002
2088
|
gen,
|
|
2003
|
-
erc
|
|
2089
|
+
erc,
|
|
2090
|
+
ai
|
|
2004
2091
|
});
|
|
2005
2092
|
});
|
|
2006
2093
|
return () => {
|
|
@@ -2172,19 +2259,29 @@ window.__ModuleLoader__.load({
|
|
|
2172
2259
|
flexDirection: "column",
|
|
2173
2260
|
gap: 8
|
|
2174
2261
|
},
|
|
2175
|
-
children: [
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2262
|
+
children: [
|
|
2263
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuotaMetric, {
|
|
2264
|
+
label: t("subscription.gen"),
|
|
2265
|
+
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CpuIcon, {}),
|
|
2266
|
+
reading: quotaReading(quota?.gen ?? null, t),
|
|
2267
|
+
gradient: palette.genGradient,
|
|
2268
|
+
palette
|
|
2269
|
+
}),
|
|
2270
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuotaMetric, {
|
|
2271
|
+
label: t("subscription.erc"),
|
|
2272
|
+
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WaveIcon, {}),
|
|
2273
|
+
reading: quotaReading(quota?.erc ?? null, t),
|
|
2274
|
+
gradient: palette.ercGradient,
|
|
2275
|
+
palette
|
|
2276
|
+
}),
|
|
2277
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuotaMetric, {
|
|
2278
|
+
label: t("subscription.ai"),
|
|
2279
|
+
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SparklesIcon, {}),
|
|
2280
|
+
reading: aiUsageReading(quota?.ai ?? null, t),
|
|
2281
|
+
gradient: palette.aiGradient,
|
|
2282
|
+
palette
|
|
2283
|
+
})
|
|
2284
|
+
]
|
|
2188
2285
|
}),
|
|
2189
2286
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(UpgradeButton, {
|
|
2190
2287
|
subscribing,
|