dsh-pick 0.5.2 → 0.6.0
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/README.md +22 -1
- package/data/catalog.json +1 -1
- package/lib/boards.js +56 -8
- package/lib/engine.js +97 -10
- package/lib/market-index.js +134 -0
- package/lib/market-source.js +68 -0
- package/lib/overall.js +192 -0
- package/lib/remote.js +14 -0
- package/package.json +6 -2
- package/plugin/client.js +26 -0
- package/plugin/index.js +34 -1
- package/plugin/tools.js +26 -1
- package/web/panel.html +12 -5
- package/web/panel.js +62 -1
package/lib/boards.js
CHANGED
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
const OFFICIAL_JS = 'https://cdn.jsdelivr.net/npm/@deepseek-ai/dsh-official-bundles@latest/lib/index.js'
|
|
12
12
|
const COMMUNITY_URL = 'https://awesome-dsh-plugin.com/plugins.json'
|
|
13
13
|
const SHOP_BASE = 'https://LivXue.github.io/dsh-plugin-shop/v1/'
|
|
14
|
+
// dsh-m 的精选清单(人工挑的,分「装机必备」等几个区);jsDelivr 比 raw.githubusercontent.com 稳
|
|
15
|
+
const PICKS_URL = 'https://cdn.jsdelivr.net/gh/iasiv5/dsh-m@main/registry.json'
|
|
16
|
+
// 精选清单里这个区是 dsh-m 作者自己的插件,不算「推荐」
|
|
17
|
+
const SELF_PROMO = new Set(['self-dev'])
|
|
14
18
|
const REGISTRY = 'https://registry.npmjs.org/'
|
|
15
19
|
const DOWNLOADS = 'https://api.npmjs.org/downloads/point/last-week/'
|
|
16
20
|
const TOP = 100
|
|
@@ -77,7 +81,7 @@ export function communityBoard(doc) {
|
|
|
77
81
|
added: date(p && p.added),
|
|
78
82
|
d: zh(p && p.description),
|
|
79
83
|
})).filter(r => r.name && (r.n || r.repo))
|
|
80
|
-
return { total: rows.length, updated: date(doc && doc.updated), rows: topRows(rows, ['s', 'dl', 'added']) }
|
|
84
|
+
return { total: rows.length, updated: date(doc && doc.updated), rows: topRows(rows, ['s', 'dl', 'added']), all: rows }
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
/**
|
|
@@ -113,7 +117,7 @@ export function shopBoard(plugins, stars) {
|
|
|
113
117
|
d: zh(p && p.catalog && p.catalog.summary),
|
|
114
118
|
}
|
|
115
119
|
}).filter(r => r.name && (r.n || r.repo))
|
|
116
|
-
return { total: rows.length, rows: topRows(rows, ['s', 'added']) }
|
|
120
|
+
return { total: rows.length, rows: topRows(rows, ['s', 'added']), all: rows }
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
async function getJson(fetchImpl, url, ms) {
|
|
@@ -134,19 +138,42 @@ async function loadOfficial(fetchImpl) {
|
|
|
134
138
|
getJson(fetchImpl, `${DOWNLOADS}${enc}`, 15000).catch(() => null),
|
|
135
139
|
])
|
|
136
140
|
row.v = meta ? text(meta.version, 40) : ''
|
|
141
|
+
// 最近一次发布的时间:精简版 packument 的 modified(综合榜的维护分要用)
|
|
142
|
+
const brief = await fetchImpl(`${REGISTRY}${enc}`, { headers: { accept: 'application/vnd.npm.install-v1+json' }, signal: AbortSignal.timeout(15000) })
|
|
143
|
+
.then(r => (r.ok ? r.json() : null)).catch(() => null)
|
|
144
|
+
row.t = brief && date(brief.modified) ? brief.modified : null
|
|
137
145
|
if (!row.d && meta) row.d = text(meta.description)
|
|
138
146
|
row.w = dl ? count(dl.downloads) : null
|
|
139
147
|
}))
|
|
140
148
|
return { total: rows.length, rows }
|
|
141
149
|
}
|
|
142
150
|
|
|
143
|
-
async function loadShop(fetchImpl) {
|
|
151
|
+
async function loadShop(fetchImpl, members) {
|
|
144
152
|
const index = await getJson(fetchImpl, `${SHOP_BASE}index.json`, 30000)
|
|
145
153
|
const [plugins, stars] = await Promise.all([
|
|
146
154
|
getJson(fetchImpl, SHOP_BASE + index.plugins.url, 180000),
|
|
147
155
|
getJson(fetchImpl, SHOP_BASE + index.stars.url, 60000),
|
|
148
156
|
])
|
|
149
|
-
|
|
157
|
+
const board = shopBoard(plugins, stars)
|
|
158
|
+
members.shop = board.all
|
|
159
|
+
delete board.all
|
|
160
|
+
return board
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* dsh-m 精选清单 → 收录名单(不算作者自己那个区)
|
|
165
|
+
* @returns {{n: string|null, repo: string|null, name: string}[]}
|
|
166
|
+
*/
|
|
167
|
+
export function picksMembers(doc) {
|
|
168
|
+
const list = doc && Array.isArray(doc.plugins) ? doc.plugins : []
|
|
169
|
+
return list
|
|
170
|
+
.filter(p => p && !(SELF_PROMO.has(p.category) && !(p.alsoCategories || []).some(c => !SELF_PROMO.has(c))))
|
|
171
|
+
.map(p => ({
|
|
172
|
+
n: npmName(p.npm),
|
|
173
|
+
repo: typeof p.github === 'string' && /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(p.github) ? `https://github.com/${p.github}` : null,
|
|
174
|
+
name: text(p.name || p.id, 80),
|
|
175
|
+
}))
|
|
176
|
+
.filter(r => r.n || r.repo)
|
|
150
177
|
}
|
|
151
178
|
|
|
152
179
|
/**
|
|
@@ -155,11 +182,32 @@ async function loadShop(fetchImpl) {
|
|
|
155
182
|
* @param {object} [opt.previous] 上一次的 boards
|
|
156
183
|
* @param {object} [opt.communityDoc] 已经下载好的社区目录,有就不再下一次
|
|
157
184
|
*/
|
|
158
|
-
export async function buildBoards({ fetchImpl = globalThis.fetch, previous = {}, communityDoc = null, onProgress = () => {} } = {}) {
|
|
185
|
+
export async function buildBoards({ fetchImpl = globalThis.fetch, previous = {}, communityDoc = null, members = {}, onProgress = () => {} } = {}) {
|
|
186
|
+
// members:各市场的完整收录名单(综合榜算「收录于」要用),不落盘;抓不到的那个市场留 null
|
|
187
|
+
members.community = null
|
|
188
|
+
members.shop = null
|
|
189
|
+
members.official = null
|
|
190
|
+
members.picks = null
|
|
159
191
|
const sources = {
|
|
160
|
-
official: () =>
|
|
161
|
-
|
|
162
|
-
|
|
192
|
+
official: async () => {
|
|
193
|
+
const board = await loadOfficial(fetchImpl)
|
|
194
|
+
// 官方包大多不带 dsh-plugin 关键字,不在 npm 目录里:把周下载、版本、说明带上,综合榜直接用
|
|
195
|
+
members.official = board.rows.map(r => ({ n: r.n, repo: null, name: r.n, w: r.w, v: r.v, d: r.d, t: r.t }))
|
|
196
|
+
return board
|
|
197
|
+
},
|
|
198
|
+
community: async () => {
|
|
199
|
+
const board = communityBoard(communityDoc || await loadCommunity(fetchImpl))
|
|
200
|
+
members.community = board.all
|
|
201
|
+
delete board.all
|
|
202
|
+
return board
|
|
203
|
+
},
|
|
204
|
+
shop: () => loadShop(fetchImpl, members),
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
members.picks = picksMembers(await getJson(fetchImpl, PICKS_URL, 30000))
|
|
208
|
+
onProgress(` dsh-m 精选:${members.picks.length} 个(不含作者自己的)`)
|
|
209
|
+
} catch (e) {
|
|
210
|
+
onProgress(` dsh-m 精选抓不到(${e.message})`)
|
|
163
211
|
}
|
|
164
212
|
const boards = {}
|
|
165
213
|
for (const [key, load] of Object.entries(sources)) {
|
package/lib/engine.js
CHANGED
|
@@ -14,6 +14,7 @@ import { expandWords } from './words.js'
|
|
|
14
14
|
import { baselineWithStart, growth, cadence, ageDays, score, sum } from './metrics.js'
|
|
15
15
|
import { parseRepo, fetchRepos, fetchRepoLive, countsForPlugin } from './github.js'
|
|
16
16
|
import { buildBoards, communityPackages, loadCommunity, repoUrl } from './boards.js'
|
|
17
|
+
import { buildOverall } from './overall.js'
|
|
17
18
|
|
|
18
19
|
const PKG_ROOT = fileURLToPath(new URL('..', import.meta.url))
|
|
19
20
|
/** 随包自带的目录(发版时的快照;dsh-pick build 也写这里) */
|
|
@@ -36,6 +37,43 @@ const REG_API = 'https://registry.npmjs.org'
|
|
|
36
37
|
|
|
37
38
|
/* ---------------------------------------------------------------- 网络 */
|
|
38
39
|
|
|
40
|
+
/**
|
|
41
|
+
* 和 jget 一样,但分得清「没有这个包」(404/410)和「这次没拿到」(限流、5xx、网络)。
|
|
42
|
+
* 在 GitHub Actions 上读几千个 manifest 会被 npm 限流,把两者混为一谈就会把一大批好好的包当成不存在丢掉
|
|
43
|
+
* @returns {Promise<{status: 'ok', data: any} | {status: 'gone'} | {status: 'failed'}>}
|
|
44
|
+
*/
|
|
45
|
+
async function jgetStatus(url, { tries = 4, wait = 800 } = {}) {
|
|
46
|
+
for (let i = 0; i < tries; i++) {
|
|
47
|
+
try {
|
|
48
|
+
const r = await fetch(url, { headers: { accept: 'application/json' } })
|
|
49
|
+
if (r.status === 404 || r.status === 410) return { status: 'gone' }
|
|
50
|
+
if (r.ok) return { status: 'ok', data: await r.json() }
|
|
51
|
+
} catch { /* 网络错误:等一下再试 */ }
|
|
52
|
+
await sleep(wait * (i + 1))
|
|
53
|
+
}
|
|
54
|
+
return { status: 'failed' }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 读一批 npm manifest(/latest),分轮降速:第一轮并发 8,没拿到的第二轮并发 2,再没拿到的第三轮逐个慢慢来
|
|
59
|
+
* @returns {Promise<Map<string, {status: string, data?: any}>>}
|
|
60
|
+
*/
|
|
61
|
+
export async function fetchManifests(names, { wait = 800, onProgress = () => {} } = {}) {
|
|
62
|
+
const out = new Map()
|
|
63
|
+
let pending = names.slice()
|
|
64
|
+
const rounds = [{ conc: 8, pause: 0 }, { conc: 2, pause: 200 }, { conc: 1, pause: 600 }]
|
|
65
|
+
for (let round = 0; round < rounds.length && pending.length; round++) {
|
|
66
|
+
const { conc, pause } = rounds[round]
|
|
67
|
+
if (round > 0) onProgress(` manifest 第 ${round + 1} 轮(并发 ${conc}),${pending.length} 个上一轮没拿到…`)
|
|
68
|
+
await pool(pending, conc, async n => {
|
|
69
|
+
out.set(n, await jgetStatus(`${REG_API}/${enc(n)}/latest`, { wait }))
|
|
70
|
+
if (pause) await sleep(pause * wait / 800)
|
|
71
|
+
})
|
|
72
|
+
pending = pending.filter(n => out.get(n).status === 'failed')
|
|
73
|
+
}
|
|
74
|
+
return out
|
|
75
|
+
}
|
|
76
|
+
|
|
39
77
|
async function jget(url, tries = 4) {
|
|
40
78
|
for (let i = 0; i < tries; i++) {
|
|
41
79
|
try {
|
|
@@ -150,6 +188,8 @@ export async function buildCatalog({ deep = 200, max = 2250, pages = 9, deepOnly
|
|
|
150
188
|
w: (o.downloads && o.downloads.weekly) || 0,
|
|
151
189
|
m: (o.downloads && o.downloads.monthly) || 0,
|
|
152
190
|
pub: (pkg.date || '').slice(0, 10),
|
|
191
|
+
// 最新版的发布时间(完整的 ISO 时间):插件索引的 publishTimestamp 要它
|
|
192
|
+
t: /^\d{4}-\d{2}-\d{2}T/.test(pkg.date || '') ? pkg.date : undefined,
|
|
153
193
|
// search API 直接给 links,不额外花请求
|
|
154
194
|
home: (pkg.links && pkg.links.homepage) || '',
|
|
155
195
|
repo: (pkg.links && pkg.links.repository) || '',
|
|
@@ -249,8 +289,17 @@ export async function buildCatalog({ deep = 200, max = 2250, pages = 9, deepOnly
|
|
|
249
289
|
// 已经有的不再抓:deepOnly 沿用的,和社区目录补进来时读过 manifest 的
|
|
250
290
|
const needFacts = [...records.values()].filter(r => !r.inst)
|
|
251
291
|
onProgress(`安装信息 ${needFacts.length} 个…`)
|
|
252
|
-
const
|
|
253
|
-
|
|
292
|
+
const facts = await fetchManifests(needFacts.map(r => r.n), { onProgress })
|
|
293
|
+
let factsReused = 0
|
|
294
|
+
for (const rec of needFacts) {
|
|
295
|
+
const res = facts.get(rec.n)
|
|
296
|
+
if (res.status === 'ok') rec.inst = installFacts(res.data)
|
|
297
|
+
else if (res.status === 'failed' && previous && previous.packages && previous.packages[rec.n] && previous.packages[rec.n].inst) {
|
|
298
|
+
rec.inst = previous.packages[rec.n].inst // 被限流没读到:沿用上次的
|
|
299
|
+
factsReused++
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (factsReused) onProgress(` ${factsReused} 个安装信息这次没读到,沿用上次的`)
|
|
254
303
|
|
|
255
304
|
// GitHub:星标、Fork、未关闭 issue / PR、最近提交、归档。要令牌(Actions 自带的就够),没有就跳过
|
|
256
305
|
if (githubToken) {
|
|
@@ -275,7 +324,14 @@ export async function buildCatalog({ deep = 200, max = 2250, pages = 9, deepOnly
|
|
|
275
324
|
|
|
276
325
|
// npm、GitHub 之外的榜单:官方、社区、插件商店(抓不到的沿用上次)
|
|
277
326
|
onProgress('其他榜单…')
|
|
278
|
-
const
|
|
327
|
+
const members = {}
|
|
328
|
+
const boards = await buildBoards({ previous: previous && previous.boards, communityDoc, members, onProgress })
|
|
329
|
+
|
|
330
|
+
// 综合榜:几个市场合成一个榜,一个插件一行;顺带给每个 npm 包写上综合分 sc 和「收录于」src
|
|
331
|
+
const previousSrc = {}
|
|
332
|
+
for (const r of Object.values((previous && previous.packages) || {})) if (r && r.src) previousSrc[r.n] = r.src
|
|
333
|
+
boards.overall = buildOverall({ packages: Object.fromEntries(records), members, previousSrc })
|
|
334
|
+
onProgress(` 综合榜:${boards.overall.total} 个插件参与排名(${Object.entries(boards.overall.excluded).map(([k, v]) => `${k} ${v}`).join('、') || '无'}不进榜)`)
|
|
279
335
|
|
|
280
336
|
for (const rec of records.values()) slimRecord(rec)
|
|
281
337
|
|
|
@@ -308,14 +364,31 @@ export async function buildCatalog({ deep = 200, max = 2250, pages = 9, deepOnly
|
|
|
308
364
|
* @param {string} [opt.today] YYYY-MM-DD,决定今天轮到哪些带 scope 的包(见 weeklyDue)
|
|
309
365
|
* @returns {Promise<number>} 补进去几个
|
|
310
366
|
*/
|
|
311
|
-
export async function addCommunity(records, rows, { previous = {}, today = new Date().toISOString().slice(0, 10), onProgress = () => {} } = {}) {
|
|
367
|
+
export async function addCommunity(records, rows, { previous = {}, today = new Date().toISOString().slice(0, 10), wait = 800, onProgress = () => {} } = {}) {
|
|
312
368
|
const missing = rows.filter(r => !records.has(r.n))
|
|
313
369
|
onProgress(`社区目录 ${rows.length} 个 npm 包,其中 ${missing.length} 个搜索接口没翻到,逐个读 manifest…`)
|
|
314
|
-
const
|
|
315
|
-
const added =
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
370
|
+
const got = await fetchManifests(missing.map(r => r.n), { wait, onProgress })
|
|
371
|
+
const added = []
|
|
372
|
+
let gone = 0, reused = 0, lost = 0
|
|
373
|
+
for (const row of missing) {
|
|
374
|
+
const res = got.get(row.n)
|
|
375
|
+
if (res.status === 'ok') {
|
|
376
|
+
const rec = communityRecord(row, res.data)
|
|
377
|
+
if (rec) added.push(rec)
|
|
378
|
+
else gone++ // 名字对不上,当不存在
|
|
379
|
+
} else if (res.status === 'gone') {
|
|
380
|
+
gone++
|
|
381
|
+
} else if (previous && previous[row.n]) {
|
|
382
|
+
// 三轮都没拿到(多半被限流):沿用上次目录里的,别因为一次网络问题就把包丢了
|
|
383
|
+
added.push({ ...previous[row.n] })
|
|
384
|
+
reused++
|
|
385
|
+
} else {
|
|
386
|
+
lost++
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (gone) onProgress(` ${gone} 个在 npm 上不存在,不收`)
|
|
390
|
+
if (reused) onProgress(` ${reused} 个这次没读到 manifest,沿用上次目录里的`)
|
|
391
|
+
if (lost) onProgress(` ${lost} 个这次没读到、上次目录里也没有,先不收`)
|
|
319
392
|
|
|
320
393
|
// 不带 scope 的批量查,每天全查;带 scope 的只能逐个查,下载量接口经不起(几百个包在 Actions 上要排队二十多分钟),
|
|
321
394
|
// 所以每天只查轮到的那组和上次没有数的,其余沿用上次的
|
|
@@ -423,6 +496,8 @@ export function slimRecord(rec) {
|
|
|
423
496
|
if (rec.inst) {
|
|
424
497
|
if (rec.inst.p == null) delete rec.inst.p
|
|
425
498
|
if (rec.inst.r == null) delete rec.inst.r
|
|
499
|
+
if (rec.inst.e == null) delete rec.inst.e
|
|
500
|
+
if (rec.inst.a == null) delete rec.inst.a
|
|
426
501
|
}
|
|
427
502
|
if (rec.gh) {
|
|
428
503
|
if (!rec.gh.a) delete rec.gh.a
|
|
@@ -446,7 +521,15 @@ export function installFacts(manifest = {}) {
|
|
|
446
521
|
if (/^@deepseek-ai\/dsh(-|$)/.test(name) && typeof range === 'string' && range.trim()) reqs.push(range.trim())
|
|
447
522
|
}
|
|
448
523
|
const platform = dsh.client && typeof dsh.client.platform === 'string' ? dsh.client.platform : null
|
|
449
|
-
|
|
524
|
+
// e:只认顶层 engines.dsh,原样保留——DSH 插件索引(index.json)只收声明了它的版本,而且要求一字不改
|
|
525
|
+
const e = manifest.engines && typeof manifest.engines.dsh === 'string' && manifest.engines.dsh.trim() ? manifest.engines.dsh : null
|
|
526
|
+
// a:作者名(npm 的 author 可以是对象,也可以是 "名字 <邮箱> (网址)" 这种简写),只留名字
|
|
527
|
+
const author = manifest.author
|
|
528
|
+
const name = typeof author === 'string' ? author.replace(/\s*[<(].*$/, '') : author && typeof author.name === 'string' ? author.name : ''
|
|
529
|
+
return {
|
|
530
|
+
b: Boolean(dsh.bundle), p: platform, r: reqs.length ? [...new Set(reqs)].join(' ∩ ') : null,
|
|
531
|
+
e, a: name.trim() || null,
|
|
532
|
+
}
|
|
450
533
|
}
|
|
451
534
|
|
|
452
535
|
/* ---------------------------------------------------------------- 查询 */
|
|
@@ -478,6 +561,10 @@ export async function loadCatalog({ env = process.env } = {}) {
|
|
|
478
561
|
if (cache) return cache
|
|
479
562
|
const [bundled, cached] = await Promise.all([readJson(CATALOG_PATH), readJson(cachePath(env))])
|
|
480
563
|
const pick = newerCatalog(cached, bundled) ? { ...cached, source: 'remote' } : bundled ? { ...bundled, source: 'bundled' } : null
|
|
564
|
+
// 每日目录是旧代码构建的、还没有某个榜(比如刚加的综合榜):先用随包自带的那份顶上,下次每日构建后就齐了
|
|
565
|
+
if (pick && pick.source === 'remote' && bundled && bundled.boards) {
|
|
566
|
+
pick.boards = { ...bundled.boards, ...(pick.boards || {}) }
|
|
567
|
+
}
|
|
481
568
|
cache = pick ? normalize(pick) : { asOf: null, anchor: null, packages: {}, total: 0, source: 'none' }
|
|
482
569
|
return cache
|
|
483
570
|
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// lib/market-index.js — 把目录变成 DSH「插件 → 发现」能读的插件索引(index.json,format 1)
|
|
2
|
+
//
|
|
3
|
+
// DSH 的「发现」页读用户添加的插件索引源,格式由官方定义(deepseek-harness 仓库
|
|
4
|
+
// .agents/notes/implemented/feature/2026-10-02-plugin-market-index-format.md),
|
|
5
|
+
// 官方校验器是 @deepseek-ai/dsh-plugin-market-index。要点:
|
|
6
|
+
// - 只收声明了 dsh.bundle 和顶层 engines.dsh 的插件,engines.dsh 原样照抄(官方的硬性要求)
|
|
7
|
+
// - 每个版本要有发布时间(秒)、来源(这里都是 npm);dist-tags 只能指向列出来的版本
|
|
8
|
+
// - 读取方遇到任何一处不合规就拒收整份索引——所以每条先单独过校验,不合格的剔除并记下原因
|
|
9
|
+
//
|
|
10
|
+
// 每日构建时生成,和目录一起推到 catalog 分支;插件启动时把 INDEX_URL 加进「发现」(plugin/index.js)。
|
|
11
|
+
|
|
12
|
+
import { parseRepo } from './github.js'
|
|
13
|
+
|
|
14
|
+
export const INDEX_URL = 'https://cdn.jsdelivr.net/gh/AIcivilization/dsh-pick@catalog/index.json'
|
|
15
|
+
|
|
16
|
+
/** 目录的分类 → 索引里的分类 id(索引要求 id 稳定,不能用会变的中文名) */
|
|
17
|
+
const CATEGORY_IDS = {
|
|
18
|
+
'界面与主题': ['ui', 'UI & themes'],
|
|
19
|
+
'记忆与上下文': ['memory', 'Memory & context'],
|
|
20
|
+
'模型与网关': ['models', 'Models & gateways'],
|
|
21
|
+
'搜索与检索': ['search', 'Search & retrieval'],
|
|
22
|
+
'用量与计费': ['usage', 'Usage & billing'],
|
|
23
|
+
'自动化与多智能体': ['automation', 'Automation & agents'],
|
|
24
|
+
'远程与部署': ['remote', 'Remote & deploy'],
|
|
25
|
+
'文档与办公': ['docs', 'Docs & office'],
|
|
26
|
+
'媒体与生成': ['media', 'Media & generation'],
|
|
27
|
+
'集成与连接': ['integrations', 'Integrations'],
|
|
28
|
+
'插件市场与工具链': ['tooling', 'Markets & tooling'],
|
|
29
|
+
'安全与权限': ['security', 'Security & permissions'],
|
|
30
|
+
'代码与开发': ['code', 'Code & development'],
|
|
31
|
+
'其他': ['other', 'Other'],
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const SORT_KEYS = {
|
|
35
|
+
overall: { title: { en: 'dsh-pick overall score', zh: '综合分' }, order: 'desc' },
|
|
36
|
+
downloads: { title: { en: 'Weekly downloads', zh: '周下载' }, order: 'desc' },
|
|
37
|
+
baseline: { title: { en: 'Daily baseline (denoised)', zh: '日常基线(去噪)' }, order: 'desc' },
|
|
38
|
+
stars: { title: { en: 'GitHub stars', zh: 'GitHub 星标' }, order: 'desc' },
|
|
39
|
+
health: { title: { en: 'Health score', zh: '健康度' }, order: 'desc' },
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const nonBlank = v => typeof v === 'string' && /\S/.test(v)
|
|
43
|
+
const finite = v => (Number.isFinite(v) ? v : undefined)
|
|
44
|
+
|
|
45
|
+
/** 索引的根:标题、说明、分类与排序项的声明 */
|
|
46
|
+
export function indexRoot() {
|
|
47
|
+
const categories = {}
|
|
48
|
+
for (const [zh, [id, en]] of Object.entries(CATEGORY_IDS)) categories[id] = { title: { en, zh } }
|
|
49
|
+
return {
|
|
50
|
+
format: 1,
|
|
51
|
+
title: { en: 'dsh-pick · DSH plugin picks', zh: 'dsh-pick 选插件' },
|
|
52
|
+
description: {
|
|
53
|
+
en: 'Every npm DSH plugin that declares engines.dsh and a bundle, ordered by the dsh-pick overall score (merging dshmarket, dsh-m picks, dsh-plugin-shop and the DeepSeek official list), with denoised download metrics and GitHub stars. Rebuilt daily; a community index, not an official DeepSeek one.',
|
|
54
|
+
zh: '所有声明了 engines.dsh 和 bundle 的 npm DSH 插件,默认按 dsh-pick 综合分排(合并 dshmarket、dsh-m 精选、dsh-plugin-shop、DeepSeek 官方几个市场),带去噪后的下载指标和 GitHub 星标。每天重建;社区索引,不是 DeepSeek 官方的。',
|
|
55
|
+
},
|
|
56
|
+
metadata: { categories, sortKeys: SORT_KEYS },
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 目录里的一个包 → 索引里的一个插件;不够格返回 { skip: 原因 }
|
|
62
|
+
* @param {object} rec 目录记录(归一化前后都行)
|
|
63
|
+
* @param {string} [publishedAt] 最新版的发布时间(ISO);不给就用 rec.t
|
|
64
|
+
*/
|
|
65
|
+
export function indexEntry(rec, publishedAt) {
|
|
66
|
+
const inst = rec.inst || {}
|
|
67
|
+
if (!inst.b) return { skip: '没声明 dsh.bundle' }
|
|
68
|
+
if (!nonBlank(inst.e)) return { skip: '没声明 engines.dsh' }
|
|
69
|
+
if (!nonBlank(rec.v)) return { skip: '没有版本号' }
|
|
70
|
+
const ms = Date.parse(publishedAt || rec.t || '')
|
|
71
|
+
if (!Number.isFinite(ms)) return { skip: '没有发布时间' }
|
|
72
|
+
|
|
73
|
+
const entry = { name: rec.n }
|
|
74
|
+
if (nonBlank(rec.d)) entry.description = rec.d.trim()
|
|
75
|
+
if (nonBlank(inst.a)) entry.author = inst.a.trim()
|
|
76
|
+
if (/^https?:\/\/[^\s?#]+$/.test(rec.home || '')) entry.homepage = rec.home
|
|
77
|
+
const repo = parseRepo(rec.repo) || parseRepo(rec.home)
|
|
78
|
+
if (repo) entry.repository = { url: `https://github.com/${repo}` }
|
|
79
|
+
|
|
80
|
+
const sortKeys = {}
|
|
81
|
+
if (finite(rec.sc) !== undefined) sortKeys.overall = rec.sc
|
|
82
|
+
const d = rec.deep
|
|
83
|
+
if (finite(rec.w) !== undefined) sortKeys.downloads = rec.w
|
|
84
|
+
if (d && finite(d.base ?? d.baseline) !== undefined) sortKeys.baseline = d.base ?? d.baseline
|
|
85
|
+
if (rec.gh && finite(rec.gh.s) !== undefined) sortKeys.stars = rec.gh.s
|
|
86
|
+
if (d && finite(d.s ?? d.score) !== undefined) sortKeys.health = d.s ?? d.score
|
|
87
|
+
entry.metadata = {
|
|
88
|
+
category: (CATEGORY_IDS[rec.cat] || CATEGORY_IDS['其他'])[0],
|
|
89
|
+
keywords: (rec.kw || []).filter(nonBlank),
|
|
90
|
+
sortKeys,
|
|
91
|
+
}
|
|
92
|
+
entry['dist-tags'] = { latest: rec.v }
|
|
93
|
+
entry.versions = [{
|
|
94
|
+
version: rec.v,
|
|
95
|
+
publishTimestamp: Math.floor(ms / 1000),
|
|
96
|
+
source: { type: 'npm' },
|
|
97
|
+
engines: { dsh: inst.e },
|
|
98
|
+
}]
|
|
99
|
+
return { entry }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 生成整份索引
|
|
104
|
+
* @param {object} catalog 目录
|
|
105
|
+
* @param {object} opt
|
|
106
|
+
* @param {(value: object, url: string) => unknown} opt.parse 官方校验器的 parseMarketIndex:不合规就抛错
|
|
107
|
+
* @param {Record<string, string>} [opt.times] 包名 → 最新版发布时间(目录里没有 t 的,构建脚本另外查)
|
|
108
|
+
* @returns {{ index: object, skipped: Record<string, number>, rejected: {name: string, reason: string}[] }}
|
|
109
|
+
*/
|
|
110
|
+
export function buildMarketIndex(catalog, { parse, times = {} }) {
|
|
111
|
+
// 默认顺序按综合分(没有的按周下载):「发现」页不选排序时,最值得装的在前面
|
|
112
|
+
const root = indexRoot()
|
|
113
|
+
const skipped = {}
|
|
114
|
+
const rejected = []
|
|
115
|
+
const plugins = []
|
|
116
|
+
const recs = Object.values(catalog.packages || {}).sort((a, b) => (b.sc ?? -1) - (a.sc ?? -1) || (b.w || 0) - (a.w || 0))
|
|
117
|
+
for (const rec of recs) {
|
|
118
|
+
const { entry, skip } = indexEntry(rec, times[rec.n])
|
|
119
|
+
if (skip) {
|
|
120
|
+
skipped[skip] = (skipped[skip] || 0) + 1
|
|
121
|
+
continue
|
|
122
|
+
}
|
|
123
|
+
// 读取方见到一处不合规就拒收整份:每条先单独校验,不合格的剔掉、记下原因
|
|
124
|
+
try {
|
|
125
|
+
parse({ ...root, plugins: [entry] }, INDEX_URL)
|
|
126
|
+
plugins.push(entry)
|
|
127
|
+
} catch (e) {
|
|
128
|
+
rejected.push({ name: rec.n, reason: `${e.path || ''} ${e.reason || e.message}`.trim() })
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const index = { ...root, plugins }
|
|
132
|
+
parse(index, INDEX_URL) // 整份再校验一次(比如重名),不过就让构建失败
|
|
133
|
+
return { index, skipped, rejected }
|
|
134
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// lib/market-source.js — 把 dsh-pick 的插件索引加进 DSH「插件 → 发现」的索引源
|
|
2
|
+
//
|
|
3
|
+
// 「发现」页由 DSH 的 pluginMarket 服务读用户配置的索引源(官方的实验功能「自定义插件索引」)。
|
|
4
|
+
// 它提供 listIndexes() 和 setIndexes(urls):setIndexes 用整份列表替换,所以要带上已有的再加我们的。
|
|
5
|
+
//
|
|
6
|
+
// 规矩:装上后自动加一次;用户之后在「发现」里删掉了,就尊重他,不再自动加回来
|
|
7
|
+
// (本机 ~/.dsh/dsh-pick/market.json 记着加过没有)。设置页的按钮是用户明确要加,不受这条限制。
|
|
8
|
+
|
|
9
|
+
import { readFile, writeFile, mkdir } from 'node:fs/promises'
|
|
10
|
+
import { join, dirname } from 'node:path'
|
|
11
|
+
import { dshHome } from './engine.js'
|
|
12
|
+
import { INDEX_URL } from './market-index.js'
|
|
13
|
+
|
|
14
|
+
const stateFile = env => join(dshHome(env), 'dsh-pick', 'market.json')
|
|
15
|
+
|
|
16
|
+
async function readState(env) {
|
|
17
|
+
try { return JSON.parse(await readFile(stateFile(env), 'utf8')) } catch { return {} }
|
|
18
|
+
}
|
|
19
|
+
async function writeState(env, state) {
|
|
20
|
+
await mkdir(dirname(stateFile(env)), { recursive: true })
|
|
21
|
+
await writeFile(stateFile(env), JSON.stringify(state))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** listIndexes 的答复里的地址(每项可能是字符串,也可能是 { url, ... }) */
|
|
25
|
+
async function configured(market) {
|
|
26
|
+
const list = await market.listIndexes()
|
|
27
|
+
return (Array.isArray(list) ? list : []).map(x => (typeof x === 'string' ? x : x && x.url)).filter(Boolean)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const usable = market => Boolean(market && typeof market.listIndexes === 'function' && typeof market.setIndexes === 'function')
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 现在的状态(设置页显示用)
|
|
34
|
+
* @returns {Promise<{available: boolean, added: boolean, url: string}>}
|
|
35
|
+
*/
|
|
36
|
+
export async function marketStatus(market) {
|
|
37
|
+
if (!usable(market)) return { available: false, added: false, url: INDEX_URL }
|
|
38
|
+
try {
|
|
39
|
+
return { available: true, added: (await configured(market)).includes(INDEX_URL), url: INDEX_URL }
|
|
40
|
+
} catch {
|
|
41
|
+
return { available: false, added: false, url: INDEX_URL }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 把索引源加进去
|
|
47
|
+
* @param {object} market DSH 的 pluginMarket 服务
|
|
48
|
+
* @param {object} [opt]
|
|
49
|
+
* @param {boolean} [opt.force] 用户在设置页点的:不管以前加过没有都加
|
|
50
|
+
* @returns {Promise<{status: 'added'|'present'|'skipped'|'unavailable'|'failed', message?: string}>}
|
|
51
|
+
*/
|
|
52
|
+
export async function ensureMarketSource(market, { force = false, env = process.env } = {}) {
|
|
53
|
+
if (!usable(market)) return { status: 'unavailable' }
|
|
54
|
+
try {
|
|
55
|
+
const urls = await configured(market)
|
|
56
|
+
if (urls.includes(INDEX_URL)) {
|
|
57
|
+
await writeState(env, { added: true, at: new Date().toISOString() })
|
|
58
|
+
return { status: 'present' }
|
|
59
|
+
}
|
|
60
|
+
// 自动加过、现在又不在了:是用户自己删的
|
|
61
|
+
if (!force && (await readState(env)).added) return { status: 'skipped' }
|
|
62
|
+
await market.setIndexes([...urls, INDEX_URL])
|
|
63
|
+
await writeState(env, { added: true, at: new Date().toISOString() })
|
|
64
|
+
return { status: 'added' }
|
|
65
|
+
} catch (e) {
|
|
66
|
+
return { status: 'failed', message: e && e.message ? e.message : String(e) }
|
|
67
|
+
}
|
|
68
|
+
}
|