universal-plugin-hub 1.0.6 → 1.0.25

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.
Files changed (65) hide show
  1. package/README.md +41 -5
  2. package/README.zh.md +41 -5
  3. package/assets/Add-plugin-source.png +0 -0
  4. package/assets/MCP.png +0 -0
  5. package/assets/Plugin-management.png +0 -0
  6. package/assets/Plugins-official.png +0 -0
  7. package/assets/Skills.png +0 -0
  8. package/assets/fluent-3d/balance_scale_3d.png +0 -0
  9. package/assets/fluent-3d/bar_chart_3d.png +0 -0
  10. package/assets/fluent-3d/books_3d.png +0 -0
  11. package/assets/fluent-3d/brain_3d.png +0 -0
  12. package/assets/fluent-3d/briefcase_3d.png +0 -0
  13. package/assets/fluent-3d/card_file_box_3d.png +0 -0
  14. package/assets/fluent-3d/chart_increasing_3d.png +0 -0
  15. package/assets/fluent-3d/clapper_board_3d.png +0 -0
  16. package/assets/fluent-3d/clipboard_3d.png +0 -0
  17. package/assets/fluent-3d/cloud_3d.png +0 -0
  18. package/assets/fluent-3d/compass_3d.png +0 -0
  19. package/assets/fluent-3d/control_knobs_3d.png +0 -0
  20. package/assets/fluent-3d/desktop_computer_3d.png +0 -0
  21. package/assets/fluent-3d/framed_picture_3d.png +0 -0
  22. package/assets/fluent-3d/gear_3d.png +0 -0
  23. package/assets/fluent-3d/globe_with_meridians_3d.png +0 -0
  24. package/assets/fluent-3d/graduation_cap_3d.png +0 -0
  25. package/assets/fluent-3d/handshake_3d.png +0 -0
  26. package/assets/fluent-3d/identification_card_3d.png +0 -0
  27. package/assets/fluent-3d/input_latin_letters_3d.png +0 -0
  28. package/assets/fluent-3d/lady_beetle_3d.png +0 -0
  29. package/assets/fluent-3d/laptop_3d.png +0 -0
  30. package/assets/fluent-3d/link_3d.png +0 -0
  31. package/assets/fluent-3d/locked_3d.png +0 -0
  32. package/assets/fluent-3d/magnifying_glass_tilted_left_3d.png +0 -0
  33. package/assets/fluent-3d/manifest.json +221 -0
  34. package/assets/fluent-3d/memo_3d.png +0 -0
  35. package/assets/fluent-3d/microscope_3d.png +0 -0
  36. package/assets/fluent-3d/money_bag_3d.png +0 -0
  37. package/assets/fluent-3d/musical_notes_3d.png +0 -0
  38. package/assets/fluent-3d/notebook_3d.png +0 -0
  39. package/assets/fluent-3d/open_book_3d.png +0 -0
  40. package/assets/fluent-3d/puzzle_piece_3d.png +0 -0
  41. package/assets/fluent-3d/red_question_mark_3d.png +0 -0
  42. package/assets/fluent-3d/robot_3d.png +0 -0
  43. package/assets/fluent-3d/shield_3d.png +0 -0
  44. package/assets/fluent-3d/shopping_bags_3d.png +0 -0
  45. package/assets/fluent-3d/sparkles_3d.png +0 -0
  46. package/assets/fluent-3d/speech_balloon_3d.png +0 -0
  47. package/assets/fluent-3d/spiral_calendar_3d.png +0 -0
  48. package/assets/fluent-3d/ticket_3d.png +0 -0
  49. package/assets/fluent-3d/triangular_ruler_3d.png +0 -0
  50. package/assets/fluent-3d/world_map_3d.png +0 -0
  51. package/assets/licenses/fluent-emoji.txt +21 -0
  52. package/client/client.js +910 -1240
  53. package/package.json +20 -4
  54. package/screenshots.json +7 -0
  55. package/src/icons.js +5 -1
  56. package/src/index.js +30 -2
  57. package/src/install.js +191 -37
  58. package/src/oauth-bridge.js +270 -0
  59. package/src/oauth-config.js +48 -0
  60. package/src/oauth-store.js +86 -0
  61. package/src/oauth.js +165 -0
  62. package/src/parser.js +25 -3
  63. package/src/routes.js +112 -10
  64. package/src/skills.js +365 -0
  65. package/assets/hero.png +0 -0
package/package.json CHANGED
@@ -2,8 +2,11 @@
2
2
  "name": "universal-plugin-hub",
3
3
  "title": "Universal Plugin Hub",
4
4
  "displayName": "Universal Plugin Hub",
5
- "description": "DSH 插件市场:安装 Claude Code 与 Codex 插件、Skills 和命令,接入子代理、MCP、Hooks 与 LSP。",
6
- "version": "1.0.6",
5
+ "description": "在 DSH 中使用 Claude Code、Codex 等软件生态的插件,一站式管理插件、Skills 与 MCP。支持添加自己的 Git 插件源、上传插件和 Skills、添加 MCP 服务器,自动扫描并开关本地 Skills,接入插件提供的子代理、MCP、Hooks 与 LSP。",
6
+ "version": "1.0.25",
7
+ "engines": {
8
+ "dsh": ">=0.1.5-rc.1"
9
+ },
7
10
  "type": "module",
8
11
  "main": "src/index.js",
9
12
  "license": "MIT",
@@ -30,6 +33,7 @@
30
33
  "mcp"
31
34
  ],
32
35
  "dependencies": {
36
+ "@modelcontextprotocol/sdk": "1.32.1",
33
37
  "js-yaml": "^5.3.0"
34
38
  },
35
39
  "peerDependencies": {
@@ -66,6 +70,18 @@
66
70
  "client",
67
71
  "scripts/postinstall.js",
68
72
  "cordis.patch.yml",
69
- "assets/hero.png"
70
- ]
73
+ "screenshots.json",
74
+ "assets/Plugins-official.png",
75
+ "assets/Skills.png",
76
+ "assets/MCP.png",
77
+ "assets/Plugin-management.png",
78
+ "assets/Add-plugin-source.png",
79
+ "assets/licenses/fluent-emoji.txt",
80
+ "assets/fluent-3d"
81
+ ],
82
+ "devDependencies": {
83
+ "react": "^19.2.0",
84
+ "react-test-renderer": "^19.2.0",
85
+ "acorn": "^8.18.0"
86
+ }
71
87
  }
@@ -0,0 +1,7 @@
1
+ [
2
+ "assets/Plugins-official.png",
3
+ "assets/Plugin-management.png",
4
+ "assets/Skills.png",
5
+ "assets/MCP.png",
6
+ "assets/Add-plugin-source.png"
7
+ ]
package/src/icons.js CHANGED
@@ -10,6 +10,8 @@ const CACHE_TTL = 7 * 24 * 60 * 60 * 1000
10
10
  const memory = new Map()
11
11
  const pending = new Map()
12
12
  const failures = new Map()
13
+ const bundledIconRoot = new URL('../assets/fluent-3d/', import.meta.url)
14
+ const bundledIconFiles = new Map(Object.values(JSON.parse(readFileSync(new URL('manifest.json', bundledIconRoot), 'utf8')).icons).map(icon => [icon.url, icon.file]))
13
15
 
14
16
  export function imageContentType(buffer) {
15
17
  if (!buffer?.length) return null
@@ -63,7 +65,7 @@ export function buildPluginIcons(meta, { sourceId, name, dir, source } = {}) {
63
65
  }
64
66
  const common = [ui.composerIcon, ui.icon, ui.iconSmall, ui.iconLarge, ui.logo, meta?.icon, meta?.iconUrl, meta?.logo]
65
67
  const values = (theme) => common.flatMap((v) => typeof v === 'object' && v ? [v[theme], v.default, v.url, v.src, v[theme === 'dark' ? 'light' : 'dark']] : [v])
66
- const defaults = dir ? ['assets/icon.svg', 'assets/logo.svg', 'assets/icon.png', 'assets/logo.png', 'icon.svg', 'logo.svg', 'icon.png', 'logo.png'] : []
68
+ const defaults = dir ? ['assets/icon.svg', 'assets/logo.svg', 'assets/icon.png', 'assets/codex-icon.png', 'assets/logo.png', 'icon.svg', 'logo.svg', 'icon.png', 'logo.png'] : []
67
69
  const light = [...new Set([ui.iconLight, ui.logoLight, meta?.iconLight, ...values('light'), ...defaults].map(toUrl).filter(Boolean))]
68
70
  const dark = [...new Set([ui.iconDark, ui.logoDark, meta?.iconDark, ...values('dark'), ...defaults].map(toUrl).filter(Boolean))]
69
71
  return { light, dark }
@@ -86,6 +88,8 @@ export async function getOrFetchIcon(url) {
86
88
  }
87
89
  const cached = memory.get(url)
88
90
  if (cached && Date.now() - cached.time < CACHE_TTL) return cached
91
+ const bundledFile = bundledIconFiles.get(url)
92
+ if (bundledFile) return remember(url, { buffer: readFileSync(new URL(bundledFile, bundledIconRoot)), contentType: 'image/png' })
89
93
  if (failures.get(url) > Date.now()) throw new Error('Icon temporarily unavailable')
90
94
  if (pending.has(url)) return pending.get(url)
91
95
  const task = (async () => {
package/src/index.js CHANGED
@@ -7,11 +7,36 @@
7
7
  * scripts behind an approval prompt, so startup is the reliable path.
8
8
  */
9
9
  import { mountRoutes } from './routes.js'
10
- import { syncAllInstalledSkillsToDsh, installProfilePackages, LSP_HOST_PACKAGES, HOOK_HOST_PACKAGES } from './install.js'
10
+ import { cancelAllOAuthVerifications } from './oauth.js'
11
+ import { syncAllInstalledSkillsToDsh, installProfilePackages, findDshMainNodeModules, LSP_HOST_PACKAGES, HOOK_HOST_PACKAGES } from './install.js'
12
+ import { createSkillsManager } from './skills.js'
13
+ import { createRequire } from 'node:module'
14
+ import { join } from 'node:path'
11
15
 
12
16
  export const name = 'universal-plugin-hub'
13
17
 
14
18
  export function apply(ctx) {
19
+ const skills = createSkillsManager()
20
+ ctx.inject(['skills'], (hostCtx) => {
21
+ hostCtx.effect(() => skills.attach(hostCtx.skills, () => {
22
+ hostCtx.emit('plugin-manager/changed')
23
+ }), 'universal-plugin-hub: skills provider')
24
+ })
25
+ ctx.inject(['skills', 'agents'], (hostCtx) => {
26
+ // Borrow DSH's own scope module so its opaque scope identity is shared.
27
+ // A profile that cannot resolve it only loses the *scoped* half of the
28
+ // skill switches; throwing here would take the whole plugin down with it,
29
+ // so degrade to the global provider and say so once.
30
+ let createScope = null
31
+ try {
32
+ const main = findDshMainNodeModules()
33
+ if (!main) throw new Error('无法定位 DSH 原生 node_modules')
34
+ createScope = createRequire(join(main, '.universal-plugin-hub-resolve.cjs'))('@deepseek-ai/dsh-scope').createScope
35
+ } catch (err) {
36
+ ctx.logger?.warn?.(`[universal-plugin-hub] scoped skill switches unavailable: ${err.message}`)
37
+ }
38
+ hostCtx.effect(() => skills.attachAgents(hostCtx, createScope), 'universal-plugin-hub: scoped skill switches')
39
+ })
15
40
  // Ensure all installed plugin skills are immediately synced to $DSH_HOME/skills
16
41
  try {
17
42
  syncAllInstalledSkillsToDsh()
@@ -27,6 +52,9 @@ export function apply(ctx) {
27
52
  })
28
53
 
29
54
  ctx.inject(['webServer'], (hostCtx) => {
30
- hostCtx.effect(() => mountRoutes(hostCtx.webServer), 'universal-plugin-hub: http routes')
55
+ hostCtx.effect(() => {
56
+ const unmount = mountRoutes(hostCtx.webServer, skills)
57
+ return () => { unmount(); cancelAllOAuthVerifications() }
58
+ }, 'universal-plugin-hub: http routes')
31
59
  })
32
60
  }
package/src/install.js CHANGED
@@ -8,16 +8,23 @@
8
8
  * agents.
9
9
  */
10
10
  import { existsSync, mkdirSync, rmSync, readFileSync, writeFileSync, renameSync, readdirSync, copyFileSync, statSync, accessSync, constants as fsConstants } from 'node:fs'
11
+ import { fileURLToPath } from 'node:url'
11
12
  import { dirname, join, basename, isAbsolute, resolve, extname, delimiter } from 'node:path'
12
13
  import { spawn, execFile, execFileSync } from 'node:child_process'
13
14
  import { gunzipSync } from 'node:zlib'
15
+ import { createHash } from 'node:crypto'
14
16
  import { homedir } from 'node:os'
15
17
  import * as yaml from 'js-yaml'
16
- import { installedDir, readState, writeState, slugify, dshHome, dshSkillsDir, safeRmDir } from './store.js'
18
+ import { installedDir, readState, writeState, slugify, dshHome, dshSkillsDir, safeRmDir, sourceCacheDir } from './store.js'
17
19
  import { materializePlugin, pullSource, pluginPath } from './market.js'
18
- import { copyDir, listSkills, listAgents, listPrompts, listConnectors, listHooks, listLspServers, readPluginManifest, resolveHookConfigPath, invalidateParserCaches, invalidateMarketplaceCache } from './parser.js'
20
+ import { copyDir, listSkills, listAgents, listPrompts, listConnectors, listHooks, listLspServers, readPluginManifest, resolveHookConfigPath, invalidateParserCaches, invalidateMarketplaceCache, readMarketplace, connectorTransport, isRemoteTransportName } from './parser.js'
19
21
  import { parseAgentDefinition, compileSubagentsHubSkill, cleanupLegacyPresets } from './agents-map.js'
20
22
  import { buildPluginIcons } from './icons.js'
23
+ import { beginOAuthVerification, completeOAuthVerification, saveCustomOAuthClient, readSavedOAuthClient } from './oauth.js'
24
+ import { encodeOAuthConfig, isOAuthMode, oauthCredentialKey, oauthRuntimeConfig, remoteConfigFromEntry } from './oauth-config.js'
25
+ import { oauthStoreDir } from './oauth-store.js'
26
+
27
+ const OAUTH_BRIDGE_PATH = fileURLToPath(new URL('./oauth-bridge.js', import.meta.url))
21
28
 
22
29
  /** Active profile name: env DSH_PROFILE -> desktop (if present) -> web. */
23
30
  export function resolveActiveProfileName() {
@@ -75,7 +82,7 @@ export function getConnectorEntry(pluginName, connectorName) {
75
82
 
76
83
  export function connectorRequiresAuth(cfg) {
77
84
  if (!cfg) return true
78
- const isHttp = (cfg.type === 'http' || cfg.type === 'sse' || (!cfg.command && (!!cfg.url || !cfg.args?.length)))
85
+ const isHttp = (connectorTransport(cfg.type, cfg.url, cfg.command) === 'http')
79
86
 
80
87
  // 1. If HTTP / SSE connector has NO valid URL or empty placeholder URL, it ALWAYS requires configuration/auth!
81
88
  if (isHttp) {
@@ -134,7 +141,7 @@ export function isConnectorAuthenticated(pluginName, connectorName) {
134
141
  const entry = getConnectorEntry(pluginName, connectorName)
135
142
  const cfg = entry?.config || found || {}
136
143
 
137
- const isHttp = (entry?.config?.transport === 'streamable-http' || found?.type === 'http' || found?.type === 'sse' || (!found?.command && (found?.url || cfg.url)) || (!found?.command && !found?.args?.length))
144
+ const isHttp = (isRemoteTransportName(entry?.config?.transport) || isRemoteTransportName(found?.type) || (!found?.command && (found?.url || cfg.url)) || (!found?.command && !found?.args?.length))
138
145
  if (isHttp) {
139
146
  const url = cfg.url || found?.url || ''
140
147
  if (!url || typeof url !== 'string' || !/^https?:\/\//i.test(url.trim())) {
@@ -173,10 +180,47 @@ export function isConnectorAuthenticated(pluginName, connectorName) {
173
180
  return false
174
181
  }
175
182
 
183
+ function isRemoteConnector(config = {}) {
184
+ return isRemoteTransportName(config.transport) || isRemoteTransportName(config.type) || (!config.command && (!!config.url || !config.args?.length))
185
+ }
186
+
187
+ function remoteConfigFingerprint(config = {}) {
188
+ const normalized = {
189
+ transport: 'http',
190
+ url: String(config.url || '').trim(),
191
+ headers: Object.fromEntries(Object.entries(config.headers || {}).filter(([key]) => {
192
+ const name = key.toLowerCase()
193
+ return name !== 'content-type' && (!isOAuthMode(config.oauth) || name !== 'authorization')
194
+ }).sort(([a], [b]) => a.localeCompare(b))),
195
+ oauth: config.oauth || 'none',
196
+ oauthClientId: config.oauthClientId || '',
197
+ oauthScope: config.oauthScope || '',
198
+ oauthCallbackPort: Number(config.oauthCallbackPort) || null,
199
+ }
200
+ return createHash('sha256').update(JSON.stringify(normalized)).digest('hex')
201
+ }
202
+
203
+ function setRemoteVerification(pluginName, connectorName, payload, verified) {
204
+ const key = `${pluginName}::${connectorName}`
205
+ const state = readMcpToolsState()
206
+ state[key] = {
207
+ ...(state[key] || {}),
208
+ verifiedRemoteConfig: verified ? remoteConfigFingerprint(payload) : null,
209
+ }
210
+ writeMcpToolsState(state)
211
+ }
212
+
176
213
  export function isConnectorActive(pluginName, connectorName) {
177
214
  const entry = getConnectorEntry(pluginName, connectorName)
178
215
  if (!entry) return false
179
- return isConnectorAuthenticated(pluginName, connectorName)
216
+ const remote = remoteConfigFromEntry(entry.config)
217
+ if (remote) {
218
+ const key = `${pluginName}::${connectorName}`
219
+ return readMcpToolsState()[key]?.verifiedRemoteConfig === remoteConfigFingerprint(remote)
220
+ }
221
+ if (!isRemoteConnector(entry.config)) return isConnectorAuthenticated(pluginName, connectorName)
222
+ const key = `${pluginName}::${connectorName}`
223
+ return readMcpToolsState()[key]?.verifiedRemoteConfig === remoteConfigFingerprint(entry.config)
180
224
  }
181
225
 
182
226
  export const getPluginConnectors = listConnectors
@@ -204,6 +248,7 @@ export function substitutePluginRoot(val, pluginRoot) {
204
248
  export function registerConnector(pluginName, connectorName, connectorConfig) {
205
249
  const patch = readCordisPatch()
206
250
  const id = getConnectorId(pluginName, connectorName)
251
+ const existingEntry = patch.flatMap((item) => item?.insert || []).find((item) => item?.id === id)
207
252
  const pluginRoot = installedDir(pluginName)
208
253
  const resolvedConfig = substitutePluginRoot(connectorConfig, pluginRoot)
209
254
 
@@ -215,7 +260,7 @@ export function registerConnector(pluginName, connectorName, connectorConfig) {
215
260
 
216
261
  insertBlock.insert = insertBlock.insert.filter((item) => item && item.id !== id)
217
262
 
218
- const isHttp = resolvedConfig.type === 'http' || resolvedConfig.type === 'sse' || (!resolvedConfig.command && (!!resolvedConfig.url || !resolvedConfig.args?.length))
263
+ const isHttp = connectorTransport(resolvedConfig.type || resolvedConfig.transport, resolvedConfig.url, resolvedConfig.command) === 'http'
219
264
  if (isHttp && (!resolvedConfig.url || !resolvedConfig.url.trim() || !/^https?:\/\//i.test(resolvedConfig.url.trim()))) {
220
265
  return { ok: false, connected: false, error: '缺少有效的服务 URL' }
221
266
  }
@@ -246,6 +291,13 @@ export function registerConnector(pluginName, connectorName, connectorConfig) {
246
291
  export function unregisterConnector(pluginName, connectorName) {
247
292
  const patch = readCordisPatch()
248
293
  const id = getConnectorId(pluginName, connectorName)
294
+ const remote = remoteConfigFromEntry(getConnectorEntry(pluginName, connectorName)?.config)
295
+ if (remote) {
296
+ const key = `${pluginName}::${connectorName}`
297
+ const state = readMcpToolsState()
298
+ state[key] = { ...(state[key] || {}), savedOAuthRemoteConfig: remote }
299
+ writeMcpToolsState(state)
300
+ }
249
301
 
250
302
  for (const item of patch) {
251
303
  if (item && Array.isArray(item.insert)) {
@@ -907,6 +959,18 @@ export function toggleConnector(pluginName, connectorName, enabled) {
907
959
  const found = connectors.find((c) => c.name === connectorName) || { name: connectorName }
908
960
 
909
961
  if (enabled) {
962
+ const entry = getConnectorEntry(pluginName, connectorName)
963
+ const remote = remoteConfigFromEntry(entry?.config) || readMcpToolsState()[`${pluginName}::${connectorName}`]?.savedOAuthRemoteConfig
964
+ if (remote && isOAuthMode(remote.oauth)) {
965
+ const saved = remoteConfigFromEntry(entry?.config) ? entry.config : {
966
+ command: process.execPath, args: [OAUTH_BRIDGE_PATH],
967
+ env: { UPH_OAUTH_STORE_DIR: oauthStoreDir(), UPH_MCP_REMOTE_CONFIG: encodeOAuthConfig(oauthRuntimeConfig({
968
+ ...remote, credentialKey: oauthCredentialKey(pluginName, connectorName, remote.url, remote.oauth),
969
+ oauth: { mode: remote.oauth, clientId: remote.oauthClientId, callbackPort: remote.oauthCallbackPort, scope: remote.oauthScope },
970
+ })) },
971
+ }
972
+ return registerConnector(pluginName, connectorName, { ...remote, type: 'stdio', command: saved.command, args: saved.args, env: saved.env })
973
+ }
910
974
  if (connectorRequiresAuth(found) && !isConnectorAuthenticated(pluginName, connectorName)) {
911
975
  throw new Error(`请先验证并配置 ${connectorName} 的授权访问 Token`)
912
976
  }
@@ -927,7 +991,26 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
927
991
  const url = (typeof payload === 'object' && payload?.url) || found?.url || (connectorName === 'notion' ? 'https://mcp.notion.com/mcp' : null)
928
992
  const command = (typeof payload === 'object' && payload?.command) || found?.command || null
929
993
 
994
+ if (transport !== 'stdio' && url && isOAuthMode(payload?.oauth)) {
995
+ setRemoteVerification(pluginName, connectorName, payload, false)
996
+ try {
997
+ saveCustomOAuthClient(pluginName, connectorName, payload)
998
+ const session = beginOAuthVerification(pluginName, connectorName, { ...payload, url }, {
999
+ onFinished: (result) => setRemoteVerification(pluginName, connectorName, payload, result.ok === true),
1000
+ })
1001
+ const result = await Promise.race([
1002
+ completeOAuthVerification(session),
1003
+ new Promise((resolve) => setTimeout(() => resolve({ pending: true, sessionId: session.id, status: session.status, message: session.message || '正在准备 OAuth 授权…' }), 250)),
1004
+ ])
1005
+ setRemoteVerification(pluginName, connectorName, payload, result.ok === true)
1006
+ return { ...result, server: connectorName, transport: 'http', endpoint: url, statusCode: result.statusCode ?? result.status }
1007
+ } catch (error) {
1008
+ return { ok: false, message: error.message, server: connectorName, transport: 'http', endpoint: url }
1009
+ }
1010
+ }
1011
+
930
1012
  if (transport === 'stdio') {
1013
+ setRemoteVerification(pluginName, connectorName, payload, false)
931
1014
  if (found && found.url && !command) {
932
1015
  return {
933
1016
  ok: false,
@@ -963,6 +1046,7 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
963
1046
  }
964
1047
  }
965
1048
  if (!url) {
1049
+ setRemoteVerification(pluginName, connectorName, payload, false)
966
1050
  return {
967
1051
  ok: false,
968
1052
  message: '请输入有效的服务 URL',
@@ -983,6 +1067,7 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
983
1067
  }
984
1068
 
985
1069
  const startTime = Date.now()
1070
+ let result
986
1071
  try {
987
1072
  const controller = new AbortController()
988
1073
  const timer = setTimeout(() => controller.abort(), 8000)
@@ -995,7 +1080,7 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
995
1080
 
996
1081
  const duration = Date.now() - startTime
997
1082
  if (res.status === 200) {
998
- return {
1083
+ result = {
999
1084
  ok: true,
1000
1085
  message: '验证成功!已连接到 MCP 远程服务并激活权限。',
1001
1086
  server: connectorName,
@@ -1014,7 +1099,7 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
1014
1099
  userFriendly = `认证未通过:缺少访问令牌 (Access Token) 或需要 OAuth 授权`
1015
1100
  }
1016
1101
  }
1017
- return {
1102
+ result = {
1018
1103
  ok: false,
1019
1104
  message: userFriendly,
1020
1105
  server: connectorName,
@@ -1028,7 +1113,7 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
1028
1113
  } catch (e) {
1029
1114
  const duration = Date.now() - startTime
1030
1115
  if (e.name === 'AbortError') {
1031
- return {
1116
+ result = {
1032
1117
  ok: false,
1033
1118
  message: '连接超时(8 秒未响应),请检查服务 URL 与网络',
1034
1119
  server: connectorName,
@@ -1038,7 +1123,7 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
1038
1123
  duration,
1039
1124
  }
1040
1125
  }
1041
- return {
1126
+ result = {
1042
1127
  ok: false,
1043
1128
  message: `连接异常:${e.message}`,
1044
1129
  server: connectorName,
@@ -1048,6 +1133,8 @@ export async function verifyConnectorAuth(pluginName, connectorName, payload) {
1048
1133
  duration,
1049
1134
  }
1050
1135
  }
1136
+ setRemoteVerification(pluginName, connectorName, { transport, url, headers: reqHeaders, oauth: payload?.oauth }, result.ok === true)
1137
+ return result
1051
1138
  }
1052
1139
 
1053
1140
  export function saveConnectorAuth(pluginName, connectorName, payload) {
@@ -1062,6 +1149,7 @@ export function saveConnectorAuth(pluginName, connectorName, payload) {
1062
1149
  let customEnv = typeof payload === 'object' && payload?.env ? { ...payload.env } : { ...(found.env || {}) }
1063
1150
  let customArgs = typeof payload === 'object' && Array.isArray(payload?.args) ? payload.args : (found.args || [])
1064
1151
  let oauth = typeof payload === 'object' && payload?.oauth ? payload.oauth : 'none'
1152
+ if (isOAuthMode(oauth)) token = ''
1065
1153
 
1066
1154
  if (token && token.trim()) {
1067
1155
  const authVal = token.trim().startsWith('Bearer ') ? token.trim() : `Bearer ${token.trim()}`
@@ -1079,7 +1167,7 @@ export function saveConnectorAuth(pluginName, connectorName, payload) {
1079
1167
  }
1080
1168
 
1081
1169
  const isStdio = (transport === 'stdio')
1082
- const result = registerConnector(pluginName, connectorName, {
1170
+ let registration = {
1083
1171
  ...found,
1084
1172
  type: isStdio ? 'stdio' : (transport === 'sse' ? 'sse' : 'http'),
1085
1173
  url: isStdio ? null : (url || found.url || null),
@@ -1088,11 +1176,41 @@ export function saveConnectorAuth(pluginName, connectorName, payload) {
1088
1176
  env: { ...baseEnv, ...customEnv },
1089
1177
  headers: { ...baseHeaders, ...customHeaders },
1090
1178
  oauth: isStdio ? 'none' : oauth,
1091
- })
1092
- // Re-auth (or transport switch) changes which remote the connector talks to.
1093
- // The cached tool list was captured against the old connection, so drop it
1094
- // here — fetchConnectorTools will repopulate on the next list call.
1179
+ }
1180
+ if (!isStdio && isOAuthMode(oauth)) {
1181
+ saveCustomOAuthClient(pluginName, connectorName, payload)
1182
+ const credentialKey = oauthCredentialKey(pluginName, connectorName, url, oauth)
1183
+ const remote = oauthRuntimeConfig({
1184
+ url, headers: customHeaders, credentialKey,
1185
+ oauth: {
1186
+ mode: oauth, clientId: payload.oauthClientId || '', callbackPort: Number(payload.oauthCallbackPort) || null,
1187
+ scope: payload.oauthScope || '',
1188
+ },
1189
+ })
1190
+ registration = {
1191
+ type: 'stdio', command: process.execPath, args: [OAUTH_BRIDGE_PATH],
1192
+ env: { UPH_MCP_REMOTE_CONFIG: encodeOAuthConfig(remote), UPH_OAUTH_STORE_DIR: oauthStoreDir() },
1193
+ }
1194
+ }
1195
+ const result = registerConnector(pluginName, connectorName, registration)
1095
1196
  const toolsKey = `${pluginName}::${connectorName}`
1197
+ if (result.ok && !isStdio) {
1198
+ const verifiedConfig = { transport, url, headers: customHeaders, oauth, oauthClientId: payload.oauthClientId || '', oauthScope: payload.oauthScope || '', oauthCallbackPort: payload.oauthCallbackPort }
1199
+ const savedState = readMcpToolsState()
1200
+ savedState[toolsKey] = { ...(savedState[toolsKey] || {}), savedOAuthRemoteConfig: isOAuthMode(oauth) ? remoteConfigFromEntry(registration.env ? { env: registration.env } : {}) : undefined }
1201
+ if (!isOAuthMode(oauth)) delete savedState[toolsKey].savedOAuthRemoteConfig
1202
+ writeMcpToolsState(savedState)
1203
+ if (savedState[toolsKey]?.verifiedRemoteConfig !== remoteConfigFingerprint(verifiedConfig)) {
1204
+ setRemoteVerification(pluginName, connectorName, verifiedConfig, false)
1205
+ }
1206
+ }
1207
+ if (result.ok) {
1208
+ const savedState = readMcpToolsState()
1209
+ if (savedState[toolsKey]) {
1210
+ delete savedState[toolsKey].cachedTools
1211
+ writeMcpToolsState(savedState)
1212
+ }
1213
+ }
1096
1214
  if (MEMORY_TOOLS_CACHE.has(toolsKey)) {
1097
1215
  const mem = MEMORY_TOOLS_CACHE.get(toolsKey)
1098
1216
  MEMORY_TOOLS_CACHE.set(toolsKey, { ...mem, tools: [], disabledTools: mem.disabledTools || [] })
@@ -1170,7 +1288,7 @@ function quoteArgForShell(value) {
1170
1288
  * an (possibly empty) tool list, so callers can tell "no tools" from "the
1171
1289
  * probe never reached the server".
1172
1290
  */
1173
- function queryStdioToolsList(cmd, args, extraEnv = {}) {
1291
+ export function queryStdioToolsList(cmd, args, extraEnv = {}) {
1174
1292
  return new Promise((resolve) => {
1175
1293
  const argv = Array.isArray(args) ? args : []
1176
1294
  const useShell = SHELL_COMMANDS.test(String(cmd).trim())
@@ -1195,10 +1313,12 @@ function queryStdioToolsList(cmd, args, extraEnv = {}) {
1195
1313
  let stderr = ''
1196
1314
  let answered = false
1197
1315
  let settled = false
1316
+ let timer
1198
1317
 
1199
1318
  const finish = (tools, error) => {
1200
1319
  if (settled) return
1201
1320
  settled = true
1321
+ clearTimeout(timer)
1202
1322
  try { cp.kill() } catch {}
1203
1323
  resolve({ tools: tools || [], error: tools ? null : error })
1204
1324
  }
@@ -1207,7 +1327,9 @@ function queryStdioToolsList(cmd, args, extraEnv = {}) {
1207
1327
 
1208
1328
  cp.stdout.on('data', (d) => {
1209
1329
  output += d.toString()
1210
- for (const line of output.split('\n')) {
1330
+ const lines = output.split('\n')
1331
+ output = lines.pop() || ''
1332
+ for (const line of lines) {
1211
1333
  if (!line.trim()) continue
1212
1334
  try {
1213
1335
  const json = JSON.parse(line.trim())
@@ -1216,6 +1338,11 @@ function queryStdioToolsList(cmd, args, extraEnv = {}) {
1216
1338
  finish(json.result.tools, null)
1217
1339
  return
1218
1340
  }
1341
+ if (json.id === 0 && json.result) {
1342
+ cp.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n')
1343
+ cp.stdin.write(toolsReq)
1344
+ }
1345
+ if (json.id === 0 && json.error) finish([], json.error.message || 'MCP initialize failed')
1219
1346
  } catch {}
1220
1347
  }
1221
1348
  })
@@ -1245,16 +1372,9 @@ function queryStdioToolsList(cmd, args, extraEnv = {}) {
1245
1372
 
1246
1373
  try {
1247
1374
  cp.stdin.write(initReq)
1248
- setTimeout(() => {
1249
- if (!settled) {
1250
- try {
1251
- cp.stdin.write(toolsReq)
1252
- } catch {}
1253
- }
1254
- }, 300)
1255
1375
  } catch {}
1256
1376
 
1257
- setTimeout(() => {
1377
+ timer = setTimeout(() => {
1258
1378
  if (!settled) {
1259
1379
  const detail = stderr.trim().split('\n').filter(Boolean).slice(-2).join(' ')
1260
1380
  finish([], detail || 'MCP 服务在 25 秒内没有返回工具列表')
@@ -1289,8 +1409,9 @@ export async function fetchConnectorTools(pluginName, connectorName, forceFresh
1289
1409
  return { ok: true, tools: cached, disabledTools }
1290
1410
  }
1291
1411
 
1292
- const transport = entryCfg.transport === 'stdio' ? 'stdio' : (found?.type === 'stdio' ? 'stdio' : 'http')
1293
- const url = entryCfg.url || found?.url
1412
+ const transport = entryCfg.transport || (found?.type === 'stdio' ? 'stdio' : 'http')
1413
+ const remote = remoteConfigFromEntry(entryCfg)
1414
+ const url = remote?.url || entryCfg.url || found?.url
1294
1415
  const headers = entryCfg.headers || found?.headers || {}
1295
1416
 
1296
1417
  // Nothing to connect to (unknown server, or a config with neither URL nor
@@ -1357,7 +1478,7 @@ export async function fetchConnectorTools(pluginName, connectorName, forceFresh
1357
1478
  if (cmd) {
1358
1479
  try {
1359
1480
  const probe = await queryStdioToolsList(cmd, args, entryCfg.env || found?.env || {})
1360
- if (probe.tools.length > 0) {
1481
+ if (probe.tools.length > 0 || !probe.error) {
1361
1482
  if (!state[key]) state[key] = { disabledTools, cachedTools: [] }
1362
1483
  state[key].cachedTools = probe.tools
1363
1484
  writeMcpToolsState(state)
@@ -1685,7 +1806,7 @@ export async function installPlugin({ sourceId, pluginName, refresh = false }) {
1685
1806
  }
1686
1807
  for (const c of pluginConnectors) {
1687
1808
  if (!connectorRequiresAuth(c)) {
1688
- const isHttp = (c.type === 'http' || c.type === 'sse' || (!c.command && (!!c.url || !c.args?.length)))
1809
+ const isHttp = (connectorTransport(c.type, c.url, c.command) === 'http')
1689
1810
  if (isHttp && (!c.url || !c.url.trim() || !/^https?:\/\//i.test(c.url.trim()))) {
1690
1811
  continue
1691
1812
  }
@@ -1864,9 +1985,12 @@ export async function updatePlugin(pluginName) {
1864
1985
  const state = readState()
1865
1986
  const rec = state.plugins.find((p) => p.name === pluginName)
1866
1987
  if (!rec) throw new Error(`plugin not installed: ${pluginName}`)
1988
+ if (rec.sourceId === 'local' && !readMarketplace('local').some(row => row.name === pluginName)) {
1989
+ throw new Error('本地插件的原始来源不可用,请重新导入后再更新')
1990
+ }
1867
1991
  const source = state.sources.find((s) => s.id === rec.sourceId)
1868
1992
  if (source && typeof source.url === 'string') {
1869
- const cacheDir = join(marketRoot(), 'market', rec.sourceId)
1993
+ const cacheDir = sourceCacheDir(rec.sourceId)
1870
1994
  if (existsSync(join(cacheDir, '.git'))) {
1871
1995
  await pullSource(rec.sourceId)
1872
1996
  }
@@ -1894,6 +2018,19 @@ export async function findMarketRow(sourceId, pluginName) {
1894
2018
  return rows.find((r) => r.name === pluginName) ?? null
1895
2019
  }
1896
2020
 
2021
+ /**
2022
+ * Author from the source's live marketplace row. Used as the last fallback for
2023
+ * installed records written before the reader merged each plugin's own
2024
+ * manifest (`author: null`). Returns null when the row or its author is absent.
2025
+ */
2026
+ function findMarketRowAuthor(sourceId, pluginName) {
2027
+ try {
2028
+ return readMarketplace(sourceId).find((r) => r.name === pluginName)?.author ?? null
2029
+ } catch {
2030
+ return null
2031
+ }
2032
+ }
2033
+
1897
2034
  /** Re-exported for routes: list installed plugins with details. */
1898
2035
  export function installedDetails() {
1899
2036
  const state = readState()
@@ -1931,11 +2068,13 @@ export function installedDetails() {
1931
2068
  const connected = isConnectorActive(rec.name, c.name)
1932
2069
  const savedEntry = getConnectorEntry(rec.name, c.name)
1933
2070
  const savedConfig = savedEntry?.config || {}
1934
- const savedHeaders = (savedConfig.headers && Object.keys(savedConfig.headers).length > 0) ? savedConfig.headers : c.headers
1935
- const savedEnv = (savedConfig.env && Object.keys(savedConfig.env).length > 0) ? savedConfig.env : c.env
1936
- const savedUrl = savedConfig.url || c.url
1937
- const savedArgs = (savedConfig.args && savedConfig.args.length > 0) ? savedConfig.args : c.args
1938
- const savedTransport = savedConfig.transport ? (savedConfig.transport === 'streamable-http' ? 'http' : (savedConfig.transport === 'stdio' ? 'stdio' : c.type)) : c.type
2071
+ const remote = remoteConfigFromEntry(savedConfig) || (!savedEntry ? readMcpToolsState()[`${rec.name}::${c.name}`]?.savedOAuthRemoteConfig : null)
2072
+ const savedHeaders = remote ? remote.headers : ((savedConfig.headers && Object.keys(savedConfig.headers).length > 0) ? savedConfig.headers : c.headers)
2073
+ const savedEnv = remote ? {} : ((savedConfig.env && Object.keys(savedConfig.env).length > 0) ? savedConfig.env : c.env)
2074
+ const savedUrl = remote ? remote.url : (savedConfig.url || c.url)
2075
+ const savedArgs = remote ? [] : ((savedConfig.args && savedConfig.args.length > 0) ? savedConfig.args : c.args)
2076
+ const savedTransport = remote ? 'http' : connectorTransport(savedConfig.transport || savedConfig.type, savedUrl, savedConfig.command || c.command)
2077
+ const savedClient = remote?.oauth === 'custom' ? readSavedOAuthClient(rec.name, c.name, savedUrl, remote.oauth) : null
1939
2078
 
1940
2079
  return {
1941
2080
  ...c,
@@ -1944,9 +2083,14 @@ export function installedDetails() {
1944
2083
  headers: savedHeaders,
1945
2084
  env: savedEnv,
1946
2085
  args: savedArgs,
1947
- oauth: savedConfig.oauth || c.oauth || 'none',
2086
+ oauth: remote?.oauth || savedConfig.oauth || c.oauth || 'none',
2087
+ oauthClientId: savedClient?.clientId || '',
2088
+ oauthHasClientSecret: savedClient?.hasClientSecret || false,
2089
+ oauthCallbackPort: remote?.oauthCallbackPort || '',
2090
+ oauthScope: remote?.oauthScope || '',
1948
2091
  needsAuth,
1949
2092
  authenticated,
2093
+ enabled: !!savedEntry,
1950
2094
  connected,
1951
2095
  }
1952
2096
  }) : []
@@ -1992,8 +2136,17 @@ export function installedDetails() {
1992
2136
  const missingCommand = !active && !!s.command && !resolveCommandPath(s.command)
1993
2137
  return { ...s, active, missingCommand }
1994
2138
  })
2139
+ const targetManifest = existsSync(target) ? readPluginManifest(target) : null
2140
+ // Author: the state record is written at install time, so installs made
2141
+ // before the marketplace reader learned to merge a plugin's own manifest
2142
+ // carry `author: null` forever. Fall back to the installed copy's manifest,
2143
+ // then to the live marketplace row, so those records self-heal on read.
2144
+ const manifestAuthor = targetManifest?.author
2145
+ ? (typeof targetManifest.author === 'string' ? targetManifest.author : targetManifest.author.name)
2146
+ : null
2147
+ const author = rec.author || manifestAuthor || findMarketRowAuthor(rec.sourceId, rec.name)
1995
2148
  const detail = existsSync(target) ? {
1996
- icons: buildPluginIcons(readPluginManifest(target), { sourceId: rec.sourceId, name: rec.name, dir: target }),
2149
+ icons: buildPluginIcons(targetManifest, { sourceId: rec.sourceId, name: rec.name, dir: target }),
1997
2150
  skills: listSkills(target),
1998
2151
  agents: listAgents(target),
1999
2152
  prompts: listPrompts(target),
@@ -2005,6 +2158,7 @@ export function installedDetails() {
2005
2158
  return {
2006
2159
  ...rec,
2007
2160
  ...detail,
2161
+ author: author || rec.author,
2008
2162
  skillCount: detail.skills.length,
2009
2163
  agentCount: detail.agents.length,
2010
2164
  promptCount: detail.prompts.length,