dsh-plugin-explorer 0.0.0-stage → 0.1.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/LICENSE +26 -0
- package/README.md +57 -2
- package/client.js +414 -0
- package/cordis.patch.yml +4 -0
- package/data/plugins.json +1 -0
- package/icon.svg +7 -0
- package/index.js +80 -0
- package/lib/catalog.js +71 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +50 -4
- package/scripts/build-data.mjs +17 -0
- package/scripts/verify.mjs +102 -0
package/icon.svg
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36" fill="none">
|
|
2
|
+
<circle cx="15.5" cy="15" r="8.25" stroke="#3b82f6" stroke-width="2.6"/>
|
|
3
|
+
<circle cx="12" cy="12" r="1.7" fill="#3b82f6"/>
|
|
4
|
+
<circle cx="19" cy="12.25" r="1.7" fill="#3b82f6"/>
|
|
5
|
+
<circle cx="15.5" cy="18.5" r="1.7" fill="#3b82f6"/>
|
|
6
|
+
<path d="M21.6 21.1 28.9 28.4" stroke="#3b82f6" stroke-width="3" stroke-linecap="round"/>
|
|
7
|
+
</svg>
|
package/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host half of the plugin finder: serves the community plugin directory to the Web page.
|
|
3
|
+
*
|
|
4
|
+
* The directory is bundled with the package and needs no network. `?refresh=1` re-reads the
|
|
5
|
+
* upstream CC0 catalog (`dsh-plugin-catalog` on jsDelivr) and replaces the served copy for the
|
|
6
|
+
* rest of this session; a failed refresh leaves the loaded copy in place.
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync } from 'node:fs'
|
|
9
|
+
import { normalizeCatalog } from './lib/catalog.js'
|
|
10
|
+
|
|
11
|
+
/** Exact Fetch route below `/api` the browser reads. */
|
|
12
|
+
const ROUTE = '/api/plugin-finder/catalog.json'
|
|
13
|
+
|
|
14
|
+
/** Upstream catalog document; jsDelivr resolves the tag to the newest published version. */
|
|
15
|
+
const SOURCE_URL = 'https://cdn.jsdelivr.net/npm/dsh-plugin-catalog@latest/plugins.json'
|
|
16
|
+
|
|
17
|
+
/** Deadline for one upstream read, including the body. */
|
|
18
|
+
const REFRESH_TIMEOUT_MS = 90_000
|
|
19
|
+
|
|
20
|
+
function respond(body, status = 200) {
|
|
21
|
+
return new Response(body, {
|
|
22
|
+
status,
|
|
23
|
+
headers: {
|
|
24
|
+
'content-type': 'application/json; charset=utf-8',
|
|
25
|
+
'cache-control': 'no-store',
|
|
26
|
+
'x-content-type-options': 'nosniff',
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The catalog bundled with this package. */
|
|
32
|
+
function readBundled() {
|
|
33
|
+
return readFileSync(new URL('./data/plugins.json', import.meta.url), 'utf8')
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Contribute the catalog route.
|
|
38
|
+
* @param ctx - the Host plugin context.
|
|
39
|
+
*/
|
|
40
|
+
export function apply(ctx) {
|
|
41
|
+
let bundled
|
|
42
|
+
let refreshed
|
|
43
|
+
let pending
|
|
44
|
+
|
|
45
|
+
function current() {
|
|
46
|
+
return refreshed?.json ?? (bundled ??= readBundled())
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function refresh() {
|
|
50
|
+
pending ??= (async () => {
|
|
51
|
+
const response = await fetch(SOURCE_URL, { signal: AbortSignal.timeout(REFRESH_TIMEOUT_MS), redirect: 'follow' })
|
|
52
|
+
if (!response.ok) throw new Error(`upstream answered HTTP ${String(response.status)}`)
|
|
53
|
+
const payload = normalizeCatalog(await response.json())
|
|
54
|
+
payload.source = SOURCE_URL
|
|
55
|
+
refreshed = { json: JSON.stringify(payload) }
|
|
56
|
+
})().finally(() => {
|
|
57
|
+
pending = undefined
|
|
58
|
+
})
|
|
59
|
+
return pending
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
ctx.inject(['connection'], (scope) => {
|
|
63
|
+
scope.effect(() => scope.connection.fetch.register({
|
|
64
|
+
path: ROUTE,
|
|
65
|
+
methods: ['GET'],
|
|
66
|
+
requestBody: 'buffered',
|
|
67
|
+
fetch: async (request) => {
|
|
68
|
+
if (new URL(request.url).searchParams.get('refresh') === '1') {
|
|
69
|
+
try {
|
|
70
|
+
await refresh()
|
|
71
|
+
} catch (error) {
|
|
72
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
73
|
+
return respond(JSON.stringify({ error: message }), 502)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return respond(current())
|
|
77
|
+
},
|
|
78
|
+
}), `plugin-finder: ${ROUTE}`)
|
|
79
|
+
})
|
|
80
|
+
}
|
package/lib/catalog.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize a plugin catalog document into the compact directory this plugin serves.
|
|
3
|
+
*
|
|
4
|
+
* The catalog is the CC0 `dsh-plugin-catalog` dataset: one object per community plugin with its
|
|
5
|
+
* GitHub source, npm package, version, localized description, stars and downloads. Only entries
|
|
6
|
+
* published to npm with an exact version are kept, because the Plugins page install dialog takes
|
|
7
|
+
* an exact `name@version` spec.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Longest description kept, per language. */
|
|
11
|
+
const DESCRIPTION_LIMIT = 420
|
|
12
|
+
|
|
13
|
+
/** Source identifier stored in the served document. */
|
|
14
|
+
export const CATALOG_SOURCE = 'dsh-plugin-catalog'
|
|
15
|
+
|
|
16
|
+
function finite(value) {
|
|
17
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function text(value) {
|
|
21
|
+
if (typeof value === 'string') return value.length === 0 ? undefined : value.slice(0, DESCRIPTION_LIMIT)
|
|
22
|
+
if (value === null || typeof value !== 'object') return undefined
|
|
23
|
+
const picked = {}
|
|
24
|
+
for (const language of ['en', 'zh']) {
|
|
25
|
+
if (typeof value[language] === 'string' && value[language].length > 0) {
|
|
26
|
+
picked[language] = value[language].slice(0, DESCRIPTION_LIMIT)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return Object.keys(picked).length === 0 ? undefined : picked
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Turn a catalog document into the served payload.
|
|
34
|
+
* @param raw - a `dsh-plugin-catalog` document: an array, or an object with a `plugins` array.
|
|
35
|
+
* @returns the compact payload with one entry per installable npm package, most downloaded first.
|
|
36
|
+
*/
|
|
37
|
+
export function normalizeCatalog(raw) {
|
|
38
|
+
const list = Array.isArray(raw) ? raw : raw?.plugins
|
|
39
|
+
if (!Array.isArray(list)) throw new Error('plugin catalog: the document has no plugin list')
|
|
40
|
+
|
|
41
|
+
const byNpm = new Map()
|
|
42
|
+
for (const entry of list) {
|
|
43
|
+
if (entry === null || typeof entry !== 'object') continue
|
|
44
|
+
if (typeof entry.npm !== 'string' || entry.npm.length === 0) continue
|
|
45
|
+
if (typeof entry.version !== 'string' || entry.version.length === 0) continue
|
|
46
|
+
const downloads = finite(entry.downloads) ?? 0
|
|
47
|
+
const current = byNpm.get(entry.npm)
|
|
48
|
+
if (current !== undefined && current.downloads >= downloads) continue
|
|
49
|
+
byNpm.set(entry.npm, {
|
|
50
|
+
name: entry.npm,
|
|
51
|
+
version: entry.version,
|
|
52
|
+
owner: typeof entry.owner === 'string' && entry.owner.length > 0 ? entry.owner : undefined,
|
|
53
|
+
category: typeof entry.category === 'string' && entry.category.length > 0 ? entry.category : undefined,
|
|
54
|
+
description: text(entry.description),
|
|
55
|
+
url: typeof entry.url === 'string' && entry.url.startsWith('https://') ? entry.url : undefined,
|
|
56
|
+
page: typeof entry.page === 'string' && entry.page.startsWith('https://') ? entry.page : undefined,
|
|
57
|
+
stars: finite(entry.stars),
|
|
58
|
+
downloads: finite(entry.downloads),
|
|
59
|
+
added: typeof entry.added === 'string' ? entry.added : undefined,
|
|
60
|
+
icon: typeof entry.icon === 'string' && entry.icon.startsWith('https://') ? entry.icon : undefined,
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const plugins = [...byNpm.values()].sort((a, b) => (b.downloads ?? 0) - (a.downloads ?? 0))
|
|
65
|
+
return {
|
|
66
|
+
format: 1,
|
|
67
|
+
source: CATALOG_SOURCE,
|
|
68
|
+
generatedAt: new Date().toISOString(),
|
|
69
|
+
plugins,
|
|
70
|
+
}
|
|
71
|
+
}
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "Plugin search",
|
|
4
|
+
"description": "Adds a Search tab to the Plugins page: type a plugin name, author, or keyword to search 7,000+ installable community plugins from a bundled catalog, then install one through the normal confirmation dialog. The catalog ships with the plugin, so searching needs no network; use Refresh catalog to read the newest community index."
|
|
5
|
+
}
|
|
6
|
+
}
|
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-explorer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Search the community plugin catalog from the Plugins page and install a matching bundle in one click.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./client": "./client.js",
|
|
10
|
+
"./locale/*.json": "./locale/*.json",
|
|
11
|
+
"./icon": "./icon.svg",
|
|
12
|
+
"./data/plugins.json": "./data/plugins.json"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"client.js",
|
|
17
|
+
"lib",
|
|
18
|
+
"data",
|
|
19
|
+
"locale",
|
|
20
|
+
"cordis.patch.yml",
|
|
21
|
+
"icon.svg",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"scripts"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build:data": "node scripts/build-data.mjs",
|
|
28
|
+
"verify": "node scripts/verify.mjs"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"dsh",
|
|
32
|
+
"dsh-plugin",
|
|
33
|
+
"deepseek-harness",
|
|
34
|
+
"plugin-marketplace",
|
|
35
|
+
"plugin-search"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"dsh": ">=0.2.2-rc.5"
|
|
39
|
+
},
|
|
40
|
+
"dsh": {
|
|
41
|
+
"bundle": {
|
|
42
|
+
"patch": "./cordis.patch.yml"
|
|
43
|
+
},
|
|
44
|
+
"client": {
|
|
45
|
+
"platform": "web",
|
|
46
|
+
"inject": [
|
|
47
|
+
"@deepseek-ai/dsh-client-locale",
|
|
48
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager"
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Build the bundled plugin directory from a dsh-plugin-catalog plugins.json.
|
|
2
|
+
// Usage: node scripts/build-data.mjs <catalog-plugins.json> [out-file]
|
|
3
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs'
|
|
4
|
+
import { dirname, resolve } from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
import { normalizeCatalog } from '../lib/catalog.js'
|
|
7
|
+
|
|
8
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
9
|
+
const input = resolve(process.argv[2] ?? '')
|
|
10
|
+
const out = resolve(process.argv[3] ?? resolve(here, '..', 'data', 'plugins.json'))
|
|
11
|
+
|
|
12
|
+
const raw = JSON.parse(readFileSync(input, 'utf8'))
|
|
13
|
+
const payload = normalizeCatalog(raw)
|
|
14
|
+
const json = JSON.stringify(payload)
|
|
15
|
+
mkdirSync(dirname(out), { recursive: true })
|
|
16
|
+
writeFileSync(out, json)
|
|
17
|
+
console.log(`wrote ${payload.plugins.length} plugins to ${out} (${(json.length / 1048576).toFixed(1)} MB)`)
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Verification: Host catalog route + client search pipeline against the bundled directory.
|
|
2
|
+
// Usage: node scripts/verify.mjs [--refresh]
|
|
3
|
+
import { apply } from '../index.js'
|
|
4
|
+
|
|
5
|
+
let failures = 0
|
|
6
|
+
function check(label, condition) {
|
|
7
|
+
console.log(`${condition ? 'PASS' : 'FAIL'} ${label}`)
|
|
8
|
+
if (!condition) failures += 1
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// --- Host half: register the route with a minimal Cordis-shaped context. ---
|
|
12
|
+
const routes = []
|
|
13
|
+
const scope = {
|
|
14
|
+
effect(fn) { return fn() },
|
|
15
|
+
connection: { fetch: { register(route) { routes.push(route); return async () => {} } } },
|
|
16
|
+
}
|
|
17
|
+
apply({ inject(_deps, callback) { callback(scope) } })
|
|
18
|
+
check('host registers one GET route', routes.length === 1 && routes[0].methods.join() === 'GET')
|
|
19
|
+
check('route path is absolute below /api', routes[0]?.path === '/api/plugin-finder/catalog.json')
|
|
20
|
+
|
|
21
|
+
const bundledResponse = await routes[0].fetch(new Request('http://127.0.0.1:1/api/plugin-finder/catalog.json'))
|
|
22
|
+
const bundled = JSON.parse(await bundledResponse.text())
|
|
23
|
+
check('bundled route answers 200 json', bundledResponse.status === 200 && bundledResponse.headers.get('content-type').startsWith('application/json'))
|
|
24
|
+
check('bundled payload has 7000+ plugins', Array.isArray(bundled.plugins) && bundled.plugins.length > 7000)
|
|
25
|
+
check('every bundled entry has name and version', bundled.plugins.every(p => typeof p.name === 'string' && p.name !== '' && typeof p.version === 'string' && p.version !== ''))
|
|
26
|
+
check('entries are sorted by downloads', bundled.plugins.every((p, i) => i === 0 || (bundled.plugins[i - 1].downloads ?? 0) >= (p.downloads ?? 0)))
|
|
27
|
+
|
|
28
|
+
if (process.argv.includes('--refresh')) {
|
|
29
|
+
const refreshed = await routes[0].fetch(new Request('http://127.0.0.1:1/api/plugin-finder/catalog.json?refresh=1'))
|
|
30
|
+
const text = await refreshed.text()
|
|
31
|
+
let payload
|
|
32
|
+
try { payload = JSON.parse(text) } catch { payload = undefined }
|
|
33
|
+
check('refresh answers 200 with a catalog', refreshed.status === 200 && Array.isArray(payload?.plugins))
|
|
34
|
+
if (refreshed.status !== 200) console.log(' refresh error:', text.slice(0, 300))
|
|
35
|
+
else console.log(' refreshed plugins:', payload.plugins.length, 'source:', payload.source, 'at', payload.generatedAt)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// --- Client half: load the module with a stub window and React. ---
|
|
39
|
+
let captured
|
|
40
|
+
globalThis.window = { __ModuleLoader__: { load(definition) { captured = definition } } }
|
|
41
|
+
globalThis.document = { baseURI: 'http://127.0.0.1:63873/', documentElement: { lang: 'zh-CN' } }
|
|
42
|
+
const reactStub = {
|
|
43
|
+
createElement: (type, props, ...children) => ({ type, props, children }),
|
|
44
|
+
useState: value => [value, () => {}],
|
|
45
|
+
useMemo: factory => factory(),
|
|
46
|
+
useEffect: () => {},
|
|
47
|
+
}
|
|
48
|
+
await import('../client.js')
|
|
49
|
+
check('client module registers itself', captured?.id === 'dsh-plugin-explorer')
|
|
50
|
+
const plugin = captured.factory(id => {
|
|
51
|
+
if (id === 'react') return reactStub
|
|
52
|
+
throw new Error(`unexpected require: ${id}`)
|
|
53
|
+
})
|
|
54
|
+
check('client exposes a tab registration', typeof plugin.apply === 'function' && plugin.inject.includes('slots'))
|
|
55
|
+
check('search helpers are exposed for verification', typeof plugin.__test?.searchEntries === 'function')
|
|
56
|
+
|
|
57
|
+
const entries = plugin.__test.prepare(bundled.plugins)
|
|
58
|
+
check('prepared entries keep the catalog size', entries.length === bundled.plugins.length)
|
|
59
|
+
|
|
60
|
+
const queries = [
|
|
61
|
+
['pet', ['dsh-pet', 'pet']],
|
|
62
|
+
['记忆', ['memory']],
|
|
63
|
+
['theme', ['theme']],
|
|
64
|
+
['memory', ['memory']],
|
|
65
|
+
['cyrene', ['cyrene']],
|
|
66
|
+
['wsl', ['wsl']],
|
|
67
|
+
]
|
|
68
|
+
for (const [query, expected] of queries) {
|
|
69
|
+
const results = plugin.__test.searchEntries(entries, plugin.__test.tokenize(query))
|
|
70
|
+
const names = results.slice(0, 8).map(entry => entry.name)
|
|
71
|
+
const hit = expected.some(fragment => names.some(name => name.includes(fragment)))
|
|
72
|
+
check(`"${query}" finds ${expected.join(' or ')} (top: ${names.slice(0, 3).join(', ') || 'none'})`, hit)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// A name hit outranks a description-only hit for the same token.
|
|
76
|
+
const exact = plugin.__test.searchEntries(entries, plugin.__test.tokenize('dsh-pet'))
|
|
77
|
+
check('exact name match ranks first for "dsh-pet"', exact.findIndex(entry => entry.name === 'dsh-pet') === 0)
|
|
78
|
+
|
|
79
|
+
// Every token must occur in the matched entry.
|
|
80
|
+
const chinese = plugin.__test.searchEntries(entries, plugin.__test.tokenize('主题'))
|
|
81
|
+
check('every "主题" result contains the token', chinese.length > 0 && chinese.every(entry => entry.haystack.includes('主题')))
|
|
82
|
+
|
|
83
|
+
// The category id also ranks results when the query names it.
|
|
84
|
+
const themed = plugin.__test.searchEntries(entries, plugin.__test.tokenize('theme'))
|
|
85
|
+
check('theme category results are ranked', themed.length > 0 && themed[0].categoryLower === 'theme')
|
|
86
|
+
|
|
87
|
+
// Empty query enumerates the catalog.
|
|
88
|
+
check('empty query enumerates every entry', plugin.__test.searchEntries(entries, []).length === entries.length)
|
|
89
|
+
|
|
90
|
+
// Descriptions are kept for both languages where the source has them.
|
|
91
|
+
const bilingual = bundled.plugins.filter(p => p.description && p.description.zh && p.description.en).length
|
|
92
|
+
check(`bilingual descriptions present (${bilingual})`, bilingual > 6000)
|
|
93
|
+
|
|
94
|
+
// Both components render through the stub React without throwing.
|
|
95
|
+
const translate = key => key
|
|
96
|
+
const tab = plugin.__test.FinderTab({ t: translate, install: () => {} })
|
|
97
|
+
check('tab renders its root', tab?.props?.className === 'pf-root')
|
|
98
|
+
const row = plugin.__test.FinderRow({ entry: entries[0], install: () => {}, language: 'zh', t: translate })
|
|
99
|
+
check('row renders its root', row?.props?.className === 'pf-row')
|
|
100
|
+
|
|
101
|
+
console.log(failures === 0 ? '\nALL CHECKS PASSED' : `\n${failures} CHECK(S) FAILED`)
|
|
102
|
+
process.exit(failures === 0 ? 0 : 1)
|