@wang121ye/skillmanager 0.0.2 → 0.0.3
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/package.json +2 -2
- package/src/cli.js +1 -1
- package/src/lib/http.js +27 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wang121ye/skillmanager",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Cross-platform agent skill manager (bootstrap + optional Web UI selection) built on top of openskills.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"skillmanager",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
"gray-matter": "^4.0.3",
|
|
46
46
|
"openskills": "^1.5.0",
|
|
47
47
|
"simple-git": "^3.27.0",
|
|
48
|
-
"undici": "^
|
|
48
|
+
"undici": "^6.23.0"
|
|
49
49
|
}
|
|
50
50
|
}
|
package/src/cli.js
CHANGED
|
@@ -94,7 +94,7 @@ async function main() {
|
|
|
94
94
|
config
|
|
95
95
|
.command('set-remote-profile-url')
|
|
96
96
|
.description('设置远端 profile URL(用于 config push/pull)。')
|
|
97
|
-
.argument('<url>', '例如 https://<bucket>.<region>.aliyuncs.com/
|
|
97
|
+
.argument('<url>', '例如 https://<bucket>.<region>.aliyuncs.com/skillmanager/')
|
|
98
98
|
.action(async (url) => {
|
|
99
99
|
await setRemoteProfileUrlCmd(url);
|
|
100
100
|
});
|
package/src/lib/http.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
let proxyInitialized = false;
|
|
2
|
+
let fetchImpl = globalThis.fetch;
|
|
3
|
+
let undiciModule = null;
|
|
2
4
|
|
|
3
5
|
function getProxyUrlFromEnv() {
|
|
4
6
|
return (
|
|
@@ -11,18 +13,35 @@ function getProxyUrlFromEnv() {
|
|
|
11
13
|
);
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
function getUndici() {
|
|
17
|
+
if (undiciModule) return undiciModule;
|
|
18
|
+
try {
|
|
19
|
+
// eslint-disable-next-line global-require
|
|
20
|
+
undiciModule = require('undici');
|
|
21
|
+
return undiciModule;
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
14
27
|
function ensureProxyInitialized() {
|
|
15
28
|
if (proxyInitialized) return;
|
|
16
29
|
proxyInitialized = true;
|
|
17
30
|
|
|
18
31
|
const proxyUrl = getProxyUrlFromEnv();
|
|
32
|
+
const undici = getUndici();
|
|
33
|
+
|
|
34
|
+
// 如果有 undici,就优先用它的 fetch(这样 setGlobalDispatcher 才能生效)
|
|
35
|
+
if (undici?.fetch) fetchImpl = undici.fetch.bind(undici);
|
|
36
|
+
|
|
19
37
|
if (!proxyUrl) return;
|
|
20
38
|
|
|
21
39
|
try {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
40
|
+
if (!undici?.ProxyAgent || !undici?.setGlobalDispatcher) {
|
|
41
|
+
throw new Error('未找到 undici ProxyAgent/setGlobalDispatcher');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
undici.setGlobalDispatcher(new undici.ProxyAgent(proxyUrl));
|
|
26
45
|
// eslint-disable-next-line no-console
|
|
27
46
|
console.log(`使用代理:${proxyUrl}`);
|
|
28
47
|
} catch (e) {
|
|
@@ -35,7 +54,10 @@ function ensureProxyInitialized() {
|
|
|
35
54
|
|
|
36
55
|
async function httpFetch(url, options) {
|
|
37
56
|
ensureProxyInitialized();
|
|
38
|
-
|
|
57
|
+
if (typeof fetchImpl !== 'function') {
|
|
58
|
+
throw new Error('当前 Node 环境不支持 fetch(需要 Node 18+ 或提供 undici.fetch)');
|
|
59
|
+
}
|
|
60
|
+
return await fetchImpl(url, options);
|
|
39
61
|
}
|
|
40
62
|
|
|
41
63
|
module.exports = { httpFetch };
|