@dsh-plugins/dsh-llm-hub 1.3.0 → 1.3.1
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 +13 -0
- package/README.md +11 -4
- package/lib/client.js +685 -400
- package/lib/index.js +18 -27
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -356,6 +356,20 @@ function sendJson(response, status, payload) {
|
|
|
356
356
|
response.end(JSON.stringify(payload))
|
|
357
357
|
}
|
|
358
358
|
|
|
359
|
+
/**
|
|
360
|
+
* API Key 脱敏 —— 保留首尾(前4~6位 + 后4位),中间用 •••• 掩码。
|
|
361
|
+
* @param {string|undefined|null} key - 原始 Key
|
|
362
|
+
* @returns {string|null} 脱敏后的 Key,无有效值时返回 null
|
|
363
|
+
*/
|
|
364
|
+
export function maskKey(key) {
|
|
365
|
+
if (typeof key !== 'string' || key.trim() === '') return null
|
|
366
|
+
const trimmed = key.trim()
|
|
367
|
+
if (trimmed.length <= 8) return '••••••••'
|
|
368
|
+
const head = trimmed.length >= 24 ? 6 : 4
|
|
369
|
+
const tail = 4
|
|
370
|
+
return `${trimmed.slice(0, head)}••••${trimmed.slice(-tail)}`
|
|
371
|
+
}
|
|
372
|
+
|
|
359
373
|
export const name = 'dsh-llm-hub'
|
|
360
374
|
/**
|
|
361
375
|
* 硬依赖:llm(注册发现 + 监听 llm/stream + 过滤 listProviders)、webServer(HTTP 路由)。
|
|
@@ -691,13 +705,14 @@ export function apply(ctx) {
|
|
|
691
705
|
return
|
|
692
706
|
}
|
|
693
707
|
try {
|
|
708
|
+
const { apiKey } = await connectionFacts()
|
|
694
709
|
const payload = shapeBalance(await getJson('/user/balance'))
|
|
695
710
|
if (request.method === 'HEAD') {
|
|
696
711
|
response.writeHead(200, { 'content-type': 'application/json; charset=utf-8' })
|
|
697
712
|
response.end()
|
|
698
713
|
return
|
|
699
714
|
}
|
|
700
|
-
send(200, { ok: true, ...payload })
|
|
715
|
+
send(200, { ok: true, apiKey: apiKey ?? null, keyMasked: maskKey(apiKey), ...payload })
|
|
701
716
|
} catch (error) {
|
|
702
717
|
send(502, { ok: false, error: error instanceof Error ? error.message : String(error) })
|
|
703
718
|
}
|
|
@@ -870,6 +885,8 @@ export function apply(ctx) {
|
|
|
870
885
|
baseURLSource: baseURL !== undefined ? 'settings' : (KNOWN_GATEWAY_BASE[String(provider ?? '')] !== undefined ? 'known' : 'none'),
|
|
871
886
|
apiKeyEnv: ref,
|
|
872
887
|
keyConfigured: apiKey !== undefined,
|
|
888
|
+
keyMasked: maskKey(apiKey),
|
|
889
|
+
apiKey: apiKey ?? null,
|
|
873
890
|
modelCount: models.length,
|
|
874
891
|
// 已配置的 id 列表:前端拉到网关目录后要据此把「已经在用的」默认勾上,
|
|
875
892
|
// 光有数量做不到这件事。
|
|
@@ -2258,32 +2275,6 @@ export function apply(ctx) {
|
|
|
2258
2275
|
}
|
|
2259
2276
|
}), 'dsh-llm-hub: routing resolve route')
|
|
2260
2277
|
|
|
2261
|
-
ctx.effect(() => ctx.webServer.register({
|
|
2262
|
-
kind: 'exact',
|
|
2263
|
-
path: ROUTING_RESOLVE_PATH,
|
|
2264
|
-
handler: async (request, response) => {
|
|
2265
|
-
if (request.method !== 'POST') {
|
|
2266
|
-
response.writeHead(405, { allow: 'POST' })
|
|
2267
|
-
response.end()
|
|
2268
|
-
return
|
|
2269
|
-
}
|
|
2270
|
-
if (!sameOrigin(request)) {
|
|
2271
|
-
sendJson(response, 403, { ok: false, error: 'cross-origin writes are refused' })
|
|
2272
|
-
return
|
|
2273
|
-
}
|
|
2274
|
-
let payload
|
|
2275
|
-
try {
|
|
2276
|
-
const collected = []
|
|
2277
|
-
for await (const chunk of request) collected.push(chunk)
|
|
2278
|
-
payload = JSON.parse(Buffer.concat(collected).toString('utf8'))
|
|
2279
|
-
} catch {
|
|
2280
|
-
sendJson(response, 400, { ok: false, error: '请求内容不是合法 JSON' })
|
|
2281
|
-
return
|
|
2282
|
-
}
|
|
2283
|
-
sendJson(response, 200, resolveRoute(payload?.active))
|
|
2284
|
-
}
|
|
2285
|
-
}), 'dsh-llm-hub: routing resolve route')
|
|
2286
|
-
|
|
2287
2278
|
// ── 模型别名 ──────────────────────────────────────────────────────────────
|
|
2288
2279
|
//
|
|
2289
2280
|
// settings.dsh-llm-hub.aliases:把长 model id 映射成短显示名,典型场景:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-plugins/dsh-llm-hub",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "DSH 模型管理层:网关可达性探测、模型目录拉取、DeepSeek + MiniMax/智谱/Moonshot/StepFun 余额与配额、本月用量统计、余额预警、Provider 健康看板,再把本机装好的 codex / claude / agy 注册成子代理(装了才出现)。零运行时依赖,不改动 DSH 安装。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|