universal-plugin-hub 1.1.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/README.md +1 -1
- package/client/client.js +2891 -909
- package/package.json +1 -1
- package/src/icons.js +219 -36
- package/src/index.js +26 -2
- package/src/install.js +3088 -2649
- package/src/local.js +439 -71
- package/src/market.js +48 -17
- package/src/oauth-bridge.js +1 -1
- package/src/oauth.js +2 -1
- package/src/parser.js +1246 -459
- package/src/routes.js +369 -119
- package/src/skill-uploads.js +116 -12
- package/src/skills.js +8 -1
- package/src/store.js +171 -31
package/src/market.js
CHANGED
|
@@ -42,9 +42,31 @@ export function pluginPath(root, path) {
|
|
|
42
42
|
return dir
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
const SHORTHAND_REPO_RE = /^[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._-]*(?:\.git)?$/i
|
|
46
|
+
|
|
47
|
+
/** Normalize remote plugin source objects (Claude `github` / `git-subdir` / `url`). */
|
|
48
|
+
export function normalizeRemotePluginSource(source) {
|
|
49
|
+
if (!source || typeof source !== 'object' || Array.isArray(source)) return source
|
|
50
|
+
if (source.source === 'github') {
|
|
51
|
+
const repo = typeof source.repo === 'string' ? source.repo.trim().replace(/^\/+|\.git$/gi, '') : ''
|
|
52
|
+
const url = typeof source.url === 'string' && source.url.trim()
|
|
53
|
+
? source.url.trim()
|
|
54
|
+
: (SHORTHAND_REPO_RE.test(repo) ? `https://github.com/${repo}.git` : '')
|
|
55
|
+
return { ...source, ...(url ? { url } : {}) }
|
|
56
|
+
}
|
|
57
|
+
if (source.source === 'git-subdir' && typeof source.url === 'string') {
|
|
58
|
+
const rawUrl = source.url.trim()
|
|
59
|
+
if (SHORTHAND_REPO_RE.test(rawUrl)) {
|
|
60
|
+
return { ...source, url: `https://github.com/${rawUrl.replace(/\.git$/i, '')}.git` }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return source
|
|
64
|
+
}
|
|
65
|
+
|
|
45
66
|
/** A marketplace can point back to its own checkout (including a subdirectory). */
|
|
46
67
|
export function sourceRepositoryDir(cache, source) {
|
|
47
|
-
|
|
68
|
+
const resolved = normalizeRemotePluginSource(source)
|
|
69
|
+
if (!resolved || !['url', 'git-subdir', 'github'].includes(resolved.source) || typeof resolved.url !== 'string') return null
|
|
48
70
|
const repoKey = (value) => {
|
|
49
71
|
try {
|
|
50
72
|
const url = new URL(value)
|
|
@@ -54,15 +76,15 @@ export function sourceRepositoryDir(cache, source) {
|
|
|
54
76
|
try {
|
|
55
77
|
const config = readFileSync(join(cache, '.git', 'config'), 'utf8')
|
|
56
78
|
const origin = config.match(/\[remote "origin"\]([^\[]*)/)?.[1].match(/^\s*url\s*=\s*(.+)$/m)?.[1].trim()
|
|
57
|
-
if (!origin || !repoKey(
|
|
79
|
+
if (!origin || !repoKey(resolved.url) || repoKey(origin) !== repoKey(resolved.url)) return null
|
|
58
80
|
const head = readFileSync(join(cache, '.git', 'HEAD'), 'utf8').trim()
|
|
59
81
|
// Reuse only the requested revision; another branch is a different plugin snapshot.
|
|
60
|
-
if (
|
|
61
|
-
if (
|
|
82
|
+
if (resolved.ref && head !== `ref: refs/heads/${resolved.ref}` && head !== resolved.ref) return null
|
|
83
|
+
if (resolved.sha) {
|
|
62
84
|
const commit = head.startsWith('ref: ') ? readFileSync(join(cache, '.git', head.slice(5)), 'utf8').trim() : head
|
|
63
|
-
if (commit !==
|
|
85
|
+
if (commit !== resolved.sha) return null
|
|
64
86
|
}
|
|
65
|
-
const dir =
|
|
87
|
+
const dir = resolved.path ? pluginPath(cache, resolved.path) : cache
|
|
66
88
|
return existsSync(dir) ? dir : null
|
|
67
89
|
} catch { return null }
|
|
68
90
|
}
|
|
@@ -177,33 +199,42 @@ export async function materializePlugin(sourceId, pluginName, source, { refresh
|
|
|
177
199
|
return { dir }
|
|
178
200
|
}
|
|
179
201
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
202
|
+
const normalized = normalizeRemotePluginSource(source)
|
|
203
|
+
if (normalized && typeof normalized === 'object') {
|
|
204
|
+
if (['url', 'git-subdir', 'github'].includes(normalized.source)) {
|
|
205
|
+
if (typeof normalized.url !== 'string' || !/^https?:\/\//.test(normalized.url)) {
|
|
183
206
|
throw new Error(`plugin ${pluginName}: unsupported remote url`)
|
|
184
207
|
}
|
|
185
|
-
const remoteKey = slugFromUrl(
|
|
208
|
+
const remoteKey = slugFromUrl(normalized.url)
|
|
186
209
|
const checkout = join(sourceCacheDir('remote'), remoteKey)
|
|
187
210
|
await withGitLock(`remote:${remoteKey}`, async () => {
|
|
188
211
|
if (!existsSync(join(checkout, '.git'))) {
|
|
189
212
|
// --depth 1 keeps clones small; `ref` (branch/tag) is honored when
|
|
190
|
-
// the marketplace pins one.
|
|
191
|
-
// first version installs the pinned ref's head.
|
|
213
|
+
// the marketplace pins one.
|
|
192
214
|
const args = ['clone', '--depth', '1']
|
|
193
|
-
if (
|
|
194
|
-
args.push(
|
|
215
|
+
if (normalized.ref) args.push('--branch', String(normalized.ref))
|
|
216
|
+
args.push(normalized.url, checkout)
|
|
195
217
|
await runGit(args)
|
|
196
218
|
} else if (refresh) {
|
|
197
219
|
// The cached checkout is otherwise reused forever, so updates would
|
|
198
220
|
// reinstall the first clone's commit. Re-fetch the tracked ref.
|
|
199
221
|
const args = ['fetch', '--depth', '1', 'origin']
|
|
200
|
-
if (
|
|
222
|
+
if (normalized.ref) args.push(String(normalized.ref))
|
|
201
223
|
await runGit(args, checkout)
|
|
202
224
|
await runGit(['reset', '--hard', 'FETCH_HEAD'], checkout)
|
|
203
225
|
}
|
|
226
|
+
if (normalized.sha && /^[0-9a-f]{7,64}$/i.test(String(normalized.sha))) {
|
|
227
|
+
try {
|
|
228
|
+
const headSha = (await runGit(['rev-parse', 'HEAD'], checkout)).trim()
|
|
229
|
+
if (headSha !== normalized.sha) {
|
|
230
|
+
await runGit(['fetch', '--depth', '1', 'origin', String(normalized.sha)], checkout)
|
|
231
|
+
await runGit(['checkout', '--detach', String(normalized.sha)], checkout)
|
|
232
|
+
}
|
|
233
|
+
} catch {}
|
|
234
|
+
}
|
|
204
235
|
})
|
|
205
|
-
const dir =
|
|
206
|
-
if (!existsSync(dir)) throw new Error(`plugin ${pluginName}: path ${
|
|
236
|
+
const dir = normalized.path ? pluginPath(checkout, normalized.path) : checkout
|
|
237
|
+
if (!existsSync(dir)) throw new Error(`plugin ${pluginName}: path ${normalized.path} not found in remote repo`)
|
|
207
238
|
return { dir }
|
|
208
239
|
}
|
|
209
240
|
}
|
package/src/oauth-bridge.js
CHANGED
|
@@ -171,7 +171,7 @@ function provider() {
|
|
|
171
171
|
persist()
|
|
172
172
|
},
|
|
173
173
|
async redirectToAuthorization(url) {
|
|
174
|
-
if (!interactive) throw new Error('OAuth
|
|
174
|
+
if (!interactive) throw new Error('OAuth 授权已失效,请重新登录。')
|
|
175
175
|
emit({ status: 'waiting', authorizationUrl: String(url) })
|
|
176
176
|
await openBrowser(url)
|
|
177
177
|
},
|
package/src/oauth.js
CHANGED
|
@@ -34,9 +34,10 @@ export function connectorOauthSettings(pluginName, connectorName, payload) {
|
|
|
34
34
|
function publicSession(session) {
|
|
35
35
|
return {
|
|
36
36
|
found: true, ok: session.status === 'success', pending: session.status === 'waiting' || session.status === 'starting',
|
|
37
|
-
sessionId: session.id, status: session.status, statusCode: session.statusCode,
|
|
37
|
+
sessionId: session.id, server: session.connectorName, status: session.status, statusCode: session.statusCode,
|
|
38
38
|
message: session.message, authorizationUrl: session.authorizationUrl,
|
|
39
39
|
duration: session.duration, tools: session.tools,
|
|
40
|
+
...(Array.isArray(session.tools) ? { toolsCount: session.tools.length } : {}),
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
|