dsh-sub2api 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +4 -2
- package/lib/client.js +10 -0
- package/lib/routes.js +46 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.4
|
|
4
|
+
|
|
5
|
+
- Sync the catalog by itself once the account is funded. A top-up normally
|
|
6
|
+
happens on the payment site, so the balance is the only signal available:
|
|
7
|
+
`/status` now re-syncs when it sees a positive balance with an empty catalog,
|
|
8
|
+
or a stale snapshot, and announces the change to the picker. The panel polls
|
|
9
|
+
status every 45 seconds while visible, so models appear on their own.
|
|
10
|
+
- Failures back off for two minutes, so a group that legitimately has no models
|
|
11
|
+
is not retried on every poll.
|
|
12
|
+
|
|
3
13
|
## 0.2.3
|
|
4
14
|
|
|
5
15
|
- Show the running build's version in the panel's 诊断 card. A fix that shipped
|
package/README.md
CHANGED
|
@@ -174,7 +174,7 @@ Agent 工具(只读):`sub2api_status`、`sub2api_models`。模型可以回
|
|
|
174
174
|
4. 多个组时优先 `platform` 为 `openai` 的组(中间层走 `chat/completions`,别的平台服务不了)
|
|
175
175
|
5. 否则取第一个非独占组
|
|
176
176
|
|
|
177
|
-
### 2. 余额为 0
|
|
177
|
+
### 2. 余额为 0 拿不到模型,到账后自动同步
|
|
178
178
|
|
|
179
179
|
Sub2API 的网关对 `/v1/models` 有余额门槛,零余额直接 `403 INSUFFICIENT_BALANCE`:
|
|
180
180
|
|
|
@@ -185,7 +185,9 @@ Sub2API 的网关对 `/v1/models` 有余额门槛,零余额直接 `403 INSUFFI
|
|
|
185
185
|
[404] GET /api/v1/models → 控制面没有模型接口
|
|
186
186
|
```
|
|
187
187
|
|
|
188
|
-
|
|
188
|
+
插件把它当作**待充值状态**而不是错误:面板显示「余额不足,暂时拿不到模型列表」+「去充值」。
|
|
189
|
+
|
|
190
|
+
**充值到账后不需要手动刷新**:面板每 45 秒静默读一次状态,宿主机发现余额从 0 变成正数且目录仍为空时,会自己重新拉一次模型并通知选择器。失败后有两分钟退避,避免空分组被反复重试。
|
|
189
191
|
|
|
190
192
|
> 运营建议:给新用户送一点初始余额,否则注册完第一屏必然是空的。
|
|
191
193
|
|
package/lib/client.js
CHANGED
|
@@ -885,6 +885,16 @@ window.__ModuleLoader__.load({
|
|
|
885
885
|
|
|
886
886
|
useEffect(() => { refresh(); }, [refresh]);
|
|
887
887
|
|
|
888
|
+
// A top-up usually happens on the payment site, so the panel has to
|
|
889
|
+
// notice the new balance by itself: the host turns that into a model
|
|
890
|
+
// sync, and this poll is what makes it appear without a manual refresh.
|
|
891
|
+
useEffect(() => {
|
|
892
|
+
const timer = setInterval(() => {
|
|
893
|
+
if (document.visibilityState !== "hidden") refresh();
|
|
894
|
+
}, 45000);
|
|
895
|
+
return () => clearInterval(timer);
|
|
896
|
+
}, [refresh]);
|
|
897
|
+
|
|
888
898
|
useEffect(() => {
|
|
889
899
|
let cancelled = false;
|
|
890
900
|
call("/announcements")
|
package/lib/routes.js
CHANGED
|
@@ -42,12 +42,56 @@ export function makeRoutes(deps) {
|
|
|
42
42
|
/** Orders created by this process, keyed by the pay centre's order number. */
|
|
43
43
|
const orders = new Map();
|
|
44
44
|
|
|
45
|
+
/** When the last automatic catalog sync ran, so a poll cannot storm the gateway. */
|
|
46
|
+
let autoRefreshAt = 0;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Re-sync the catalog when the panel has a reason to believe it changed.
|
|
50
|
+
*
|
|
51
|
+
* A top-up is the usual trigger and it usually happens on another site, so
|
|
52
|
+
* nothing here can observe it directly: the balance is the only signal. Once
|
|
53
|
+
* it is positive and the catalog is still empty, the gate `/v1/models`
|
|
54
|
+
* enforces is open, and the picker should fill without the user pressing
|
|
55
|
+
* anything. A stale snapshot is refreshed on the same path.
|
|
56
|
+
* @param {number} balance reported account balance, NaN when unknown
|
|
57
|
+
*/
|
|
58
|
+
async function refreshCatalogIfNeeded(balance) {
|
|
59
|
+
const now = Date.now();
|
|
60
|
+
if (now - autoRefreshAt < 15000) return;
|
|
61
|
+
if (catalog.inflight !== undefined) return;
|
|
62
|
+
|
|
63
|
+
// Back off after a failure: a group with no models would otherwise be
|
|
64
|
+
// retried on every poll, and the answer will not change within seconds.
|
|
65
|
+
const failedAt = catalog.lastError?.at;
|
|
66
|
+
if (typeof failedAt === "number" && now - failedAt < 120000) return;
|
|
67
|
+
|
|
68
|
+
const empty = catalog.visible().length === 0;
|
|
69
|
+
const funded = Number.isFinite(balance) && balance > 0;
|
|
70
|
+
if (empty ? !funded : !catalog.stale) return;
|
|
71
|
+
|
|
72
|
+
autoRefreshAt = now;
|
|
73
|
+
try {
|
|
74
|
+
await catalog.refresh();
|
|
75
|
+
announceCatalog?.();
|
|
76
|
+
} catch {
|
|
77
|
+
// The failure is recorded on the catalog and shown by the panel.
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
45
81
|
/** Assemble the panel's view of the world. */
|
|
46
82
|
async function status() {
|
|
47
83
|
const stored = await session.read();
|
|
48
84
|
const apiKey = await session.apiKey();
|
|
49
85
|
await catalog.load();
|
|
50
86
|
|
|
87
|
+
// Balance first: it decides whether a model sync can succeed at all.
|
|
88
|
+
let profile;
|
|
89
|
+
if (stored !== undefined) {
|
|
90
|
+
const token = await session.accessToken().catch(() => undefined);
|
|
91
|
+
if (token !== undefined) profile = await safe(() => api.profile(token));
|
|
92
|
+
}
|
|
93
|
+
await refreshCatalogIfNeeded(Number(profile?.balance));
|
|
94
|
+
|
|
51
95
|
/** @type {Record<string, unknown>} */
|
|
52
96
|
const view = {
|
|
53
97
|
apiBase: cfg().apiBase,
|
|
@@ -69,15 +113,14 @@ export function makeRoutes(deps) {
|
|
|
69
113
|
if (stored !== undefined) {
|
|
70
114
|
const token = await session.accessToken().catch(() => undefined);
|
|
71
115
|
if (token !== undefined) {
|
|
72
|
-
const [
|
|
73
|
-
safe(() => api.profile(token)),
|
|
116
|
+
const [subscriptions, usage] = await Promise.all([
|
|
74
117
|
safe(() => api.subscriptionSummary(token)),
|
|
75
118
|
safe(() => api.usageDashboardStats(token)),
|
|
76
119
|
]);
|
|
77
|
-
view.profile = profile ?? null;
|
|
78
120
|
view.subscriptions = subscriptions ?? null;
|
|
79
121
|
view.usage = usage ?? null;
|
|
80
122
|
}
|
|
123
|
+
view.profile = profile ?? null;
|
|
81
124
|
}
|
|
82
125
|
return view;
|
|
83
126
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sub2api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Sub2API provider for DeepSeek Harness: zero-friction signup, auto-provisioned API key, upstream model sync, balance and recharge",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "GPL-3.0-only",
|