@kenz1117/dsh-ui-usage-billing 1.8.3-alpha.21 → 1.8.3-alpha.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/index.js +79 -6
- package/lib/types/config.d.ts +12 -0
- package/lib/types/relay-exclusion.d.ts +50 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -9896,7 +9896,7 @@ function parseNewApiStatus(data) {
|
|
|
9896
9896
|
return window === null ? null : { windows: [window] };
|
|
9897
9897
|
}
|
|
9898
9898
|
/** 归一化站点 origin(与聚合层 `siteOriginOf` 同口径)。 */
|
|
9899
|
-
function originOf(baseURL) {
|
|
9899
|
+
function originOf$1(baseURL) {
|
|
9900
9900
|
try {
|
|
9901
9901
|
return new URL(baseURL).origin;
|
|
9902
9902
|
} catch {
|
|
@@ -9926,7 +9926,7 @@ const OFFICIAL_HOSTS = /* @__PURE__ */ new Set([
|
|
|
9926
9926
|
* @returns 官方端点返回 true(中转站面板应排除)。
|
|
9927
9927
|
*/
|
|
9928
9928
|
function isOfficialBaseUrl(baseURL) {
|
|
9929
|
-
const host = originOf(baseURL).replace(/^https?:\/\//, "");
|
|
9929
|
+
const host = originOf$1(baseURL).replace(/^https?:\/\//, "");
|
|
9930
9930
|
return host !== baseURL && OFFICIAL_HOSTS.has(host);
|
|
9931
9931
|
}
|
|
9932
9932
|
/** 构造端点 URL:`/v1/usage` 与 `/api/status` 都以 baseURL 为宿主解析。 */
|
|
@@ -9955,7 +9955,7 @@ async function readRelayByKind(baseURL, apiKey, kind) {
|
|
|
9955
9955
|
async function queryRelayQuota(ctx, route) {
|
|
9956
9956
|
const base = {
|
|
9957
9957
|
route: route.route,
|
|
9958
|
-
origin: originOf(route.baseURL),
|
|
9958
|
+
origin: originOf$1(route.baseURL),
|
|
9959
9959
|
displayName: route.displayName ?? route.route
|
|
9960
9960
|
};
|
|
9961
9961
|
const gateKey = `${route.baseURL}::${route.route}`;
|
|
@@ -10074,6 +10074,78 @@ async function queryRelayQuotas(ctx, routes) {
|
|
|
10074
10074
|
return await Promise.all(routes.map(async (route) => queryRelayQuota(ctx, route)));
|
|
10075
10075
|
}
|
|
10076
10076
|
//#endregion
|
|
10077
|
+
//#region lib/types/relay-exclusion.js
|
|
10078
|
+
/**
|
|
10079
|
+
* 中转站额度探测的**排除项**(issue #152)。
|
|
10080
|
+
*
|
|
10081
|
+
* 背景:报告者的自建网关只实现 OpenAI 兼容的 `/v1/chat/completions`、`/v1/models`,
|
|
10082
|
+
* 没有余额/额度端点。插件的 `refreshRelay` 把「配了非官方 baseURL + 能解析到 key」
|
|
10083
|
+
* 的路由一律当疑似中转站探测,两个端点必然 404;而**识别失败不写指纹缓存**
|
|
10084
|
+
* (`fingerprintCache` 只在解析成功时写),于是每轮都重新探测——网关日志被稳定
|
|
10085
|
+
* 污染(每 10 分钟两条 404),按 4xx 统计错误率的告警持续误报,面板上却完全
|
|
10086
|
+
* 无感知。
|
|
10087
|
+
*
|
|
10088
|
+
* 熔断挡不住这个场景:`relayGate` 是 3 次失败冷却 60 秒,而轮询周期是 10 分钟,
|
|
10089
|
+
* 冷却早已过期。
|
|
10090
|
+
*
|
|
10091
|
+
* 排除项是**纯增量**:未配置时行为与此前逐字一致(存量中转站用户不受影响)。
|
|
10092
|
+
* 匹配语义刻意保守——**精确匹配**路由名或 origin,不支持通配/后缀:
|
|
10093
|
+
* 排除错了会让用户以为额度还在,代价(漏看余额)比多探测一次更大。
|
|
10094
|
+
*/
|
|
10095
|
+
/** 路由的 origin(协议 + 主机 + 端口);baseURL 非法时原样返回。 */
|
|
10096
|
+
function originOf(baseURL) {
|
|
10097
|
+
try {
|
|
10098
|
+
return new URL(baseURL).origin;
|
|
10099
|
+
} catch {
|
|
10100
|
+
return baseURL;
|
|
10101
|
+
}
|
|
10102
|
+
}
|
|
10103
|
+
/**
|
|
10104
|
+
* 该路由是否被排除在额度探测之外。
|
|
10105
|
+
*
|
|
10106
|
+
* @param route - llm-pi-ai 路由名(如 `nas`)。
|
|
10107
|
+
* @param baseURL - 该路由的端点地址。
|
|
10108
|
+
* @param exclusions - 用户配置的排除项;每项可写路由名或 origin。
|
|
10109
|
+
* @returns 命中排除项返回 true。
|
|
10110
|
+
*/
|
|
10111
|
+
function isRelayQuotaExcluded(route, baseURL, exclusions) {
|
|
10112
|
+
if (exclusions === void 0 || exclusions.length === 0) return false;
|
|
10113
|
+
const origin = originOf(baseURL);
|
|
10114
|
+
for (const raw of exclusions) {
|
|
10115
|
+
const item = raw.trim();
|
|
10116
|
+
if (item === "") continue;
|
|
10117
|
+
if (item === route) return true;
|
|
10118
|
+
if (item.toLowerCase() === origin.toLowerCase()) return true;
|
|
10119
|
+
}
|
|
10120
|
+
return false;
|
|
10121
|
+
}
|
|
10122
|
+
/**
|
|
10123
|
+
* 从 provider 路由表里挑出**可探测**的路由(issue #152)。
|
|
10124
|
+
*
|
|
10125
|
+
* 三道门,顺序固定:
|
|
10126
|
+
* 1. 没有 `baseURL` → 不是中转站形态,跳过;
|
|
10127
|
+
* 2. 官方厂商端点 → 卖的是官方按量余额而非中转站额度,跳过;
|
|
10128
|
+
* 3. 用户显式排除 → 命中即跳过,**不发任何请求**。
|
|
10129
|
+
*
|
|
10130
|
+
* @param providers - llm-pi-ai 的 provider 路由表。
|
|
10131
|
+
* @param isOfficial - 该 baseURL 是否指向官方厂商端点。
|
|
10132
|
+
* @param exclusions - 用户配置的排除项。
|
|
10133
|
+
* @returns 可探测的路由(保持配置里的顺序)。
|
|
10134
|
+
*/
|
|
10135
|
+
function selectRelayQuotaCandidates(providers, isOfficial, exclusions) {
|
|
10136
|
+
const out = [];
|
|
10137
|
+
for (const [route, entry] of Object.entries(providers)) {
|
|
10138
|
+
if (entry.baseURL === void 0) continue;
|
|
10139
|
+
if (isOfficial(entry.baseURL)) continue;
|
|
10140
|
+
if (isRelayQuotaExcluded(route, entry.baseURL, exclusions)) continue;
|
|
10141
|
+
out.push({
|
|
10142
|
+
route,
|
|
10143
|
+
baseURL: entry.baseURL
|
|
10144
|
+
});
|
|
10145
|
+
}
|
|
10146
|
+
return out;
|
|
10147
|
+
}
|
|
10148
|
+
//#endregion
|
|
10077
10149
|
//#region lib/types/guard.js
|
|
10078
10150
|
/**
|
|
10079
10151
|
* 共享 loopback 守卫(v1.5.2 抽自 src/index.ts)。
|
|
@@ -13187,9 +13259,10 @@ function apply(ctx, config = {}) {
|
|
|
13187
13259
|
const providers = await readPiAiProviders(ctx.settings);
|
|
13188
13260
|
const resolve = refResolver(ctx.credentials);
|
|
13189
13261
|
const routes = [];
|
|
13190
|
-
|
|
13191
|
-
|
|
13192
|
-
|
|
13262
|
+
const candidates = selectRelayQuotaCandidates(providers, isOfficialBaseUrl, config.relayQuotaExclusions);
|
|
13263
|
+
for (const candidate of candidates) {
|
|
13264
|
+
const route = candidate.route;
|
|
13265
|
+
const entry = providers[route];
|
|
13193
13266
|
const apiKeyRefs = [.../* @__PURE__ */ new Set([...entry.apiKeyEnv !== void 0 ? [entry.apiKeyEnv] : [], ...routeKeyRefCandidates(route)])];
|
|
13194
13267
|
const hit = await firstResolvedRef(apiKeyRefs, resolve);
|
|
13195
13268
|
if (entry.apiKeyEnv === void 0 && hit === void 0) continue;
|
package/lib/types/config.d.ts
CHANGED
|
@@ -101,6 +101,18 @@ export interface UsageBillingConfig {
|
|
|
101
101
|
* 如 `{ "hy4-preview": "hunyuan" }`)。聚合折叠与客户端渲染共用同一映射。
|
|
102
102
|
*/
|
|
103
103
|
modelKeyAliases?: Record<string, string>;
|
|
104
|
+
/**
|
|
105
|
+
* 中转站额度探测的排除项(issue #152):命中的路由**完全不发探测请求**,
|
|
106
|
+
* 也不在「中转站额度」面板里占位。
|
|
107
|
+
*
|
|
108
|
+
* 用于自建网关——只实现 OpenAI 兼容接口、没有余额/额度端点,探测必然 404;
|
|
109
|
+
* 且识别失败不写指纹缓存(每轮都重新探测),污染网关日志与错误率告警。
|
|
110
|
+
*
|
|
111
|
+
* 每项可写**路由名**(如 `nas`)或 **origin**(如 `http://192.168.1.10:8080`),
|
|
112
|
+
* **精确匹配**、不支持通配或后缀(与 `trustedHosts` 同姿态)。缺省空 = 行为与
|
|
113
|
+
* 此前逐字一致。
|
|
114
|
+
*/
|
|
115
|
+
relayQuotaExclusions?: string[];
|
|
104
116
|
/**
|
|
105
117
|
* 启动后延迟全量折叠的时长(毫秒,issue #105):聚合器创建起 `replayDelayMs`
|
|
106
118
|
* 之内,`/api/billing/*` 只出账本轻文档(不读任何会话日志,面板以「数据滞后」
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 中转站额度探测的**排除项**(issue #152)。
|
|
3
|
+
*
|
|
4
|
+
* 背景:报告者的自建网关只实现 OpenAI 兼容的 `/v1/chat/completions`、`/v1/models`,
|
|
5
|
+
* 没有余额/额度端点。插件的 `refreshRelay` 把「配了非官方 baseURL + 能解析到 key」
|
|
6
|
+
* 的路由一律当疑似中转站探测,两个端点必然 404;而**识别失败不写指纹缓存**
|
|
7
|
+
* (`fingerprintCache` 只在解析成功时写),于是每轮都重新探测——网关日志被稳定
|
|
8
|
+
* 污染(每 10 分钟两条 404),按 4xx 统计错误率的告警持续误报,面板上却完全
|
|
9
|
+
* 无感知。
|
|
10
|
+
*
|
|
11
|
+
* 熔断挡不住这个场景:`relayGate` 是 3 次失败冷却 60 秒,而轮询周期是 10 分钟,
|
|
12
|
+
* 冷却早已过期。
|
|
13
|
+
*
|
|
14
|
+
* 排除项是**纯增量**:未配置时行为与此前逐字一致(存量中转站用户不受影响)。
|
|
15
|
+
* 匹配语义刻意保守——**精确匹配**路由名或 origin,不支持通配/后缀:
|
|
16
|
+
* 排除错了会让用户以为额度还在,代价(漏看余额)比多探测一次更大。
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* 该路由是否被排除在额度探测之外。
|
|
20
|
+
*
|
|
21
|
+
* @param route - llm-pi-ai 路由名(如 `nas`)。
|
|
22
|
+
* @param baseURL - 该路由的端点地址。
|
|
23
|
+
* @param exclusions - 用户配置的排除项;每项可写路由名或 origin。
|
|
24
|
+
* @returns 命中排除项返回 true。
|
|
25
|
+
*/
|
|
26
|
+
export declare function isRelayQuotaExcluded(route: string, baseURL: string, exclusions: readonly string[] | undefined): boolean;
|
|
27
|
+
/** 一条待探测路由的最小事实面。 */
|
|
28
|
+
export interface RelayQuotaCandidate {
|
|
29
|
+
/** llm-pi-ai 路由名。 */
|
|
30
|
+
readonly route: string;
|
|
31
|
+
/** 该路由的端点地址。 */
|
|
32
|
+
readonly baseURL: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 从 provider 路由表里挑出**可探测**的路由(issue #152)。
|
|
36
|
+
*
|
|
37
|
+
* 三道门,顺序固定:
|
|
38
|
+
* 1. 没有 `baseURL` → 不是中转站形态,跳过;
|
|
39
|
+
* 2. 官方厂商端点 → 卖的是官方按量余额而非中转站额度,跳过;
|
|
40
|
+
* 3. 用户显式排除 → 命中即跳过,**不发任何请求**。
|
|
41
|
+
*
|
|
42
|
+
* @param providers - llm-pi-ai 的 provider 路由表。
|
|
43
|
+
* @param isOfficial - 该 baseURL 是否指向官方厂商端点。
|
|
44
|
+
* @param exclusions - 用户配置的排除项。
|
|
45
|
+
* @returns 可探测的路由(保持配置里的顺序)。
|
|
46
|
+
*/
|
|
47
|
+
export declare function selectRelayQuotaCandidates(providers: Readonly<Record<string, {
|
|
48
|
+
readonly baseURL?: string;
|
|
49
|
+
}>>, isOfficial: (baseURL: string) => boolean, exclusions: readonly string[] | undefined): readonly RelayQuotaCandidate[];
|
|
50
|
+
//# sourceMappingURL=relay-exclusion.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kenz1117/dsh-ui-usage-billing",
|
|
3
3
|
"description": "Usage billing dashboard for DeepSeek Harness: sidebar cost metrics plus a full dashboard modal, priced from a current multi-provider catalog with real usage aggregated from session logs.",
|
|
4
|
-
"version": "1.8.3-alpha.
|
|
4
|
+
"version": "1.8.3-alpha.22",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
7
7
|
"deepseek",
|