@bigbrain-work/mcp-connect 1.3.4 → 1.3.6
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/package.json +1 -1
- package/src/keyring-worker.js +40 -0
- package/src/skill-refresh.js +4 -3
- package/src/token-store.js +72 -1
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { stdin, stdout } from "node:process";
|
|
2
|
+
|
|
3
|
+
async function readRequest() {
|
|
4
|
+
let input = "";
|
|
5
|
+
stdin.setEncoding("utf8");
|
|
6
|
+
for await (const chunk of stdin) input += chunk;
|
|
7
|
+
return JSON.parse(input);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function validateRequest(request) {
|
|
11
|
+
if (
|
|
12
|
+
!request ||
|
|
13
|
+
!["get", "set", "delete"].includes(request.operation) ||
|
|
14
|
+
typeof request.service !== "string" ||
|
|
15
|
+
typeof request.account !== "string" ||
|
|
16
|
+
(request.operation === "set" && typeof request.password !== "string")
|
|
17
|
+
) {
|
|
18
|
+
throw new Error("凭据库请求无效");
|
|
19
|
+
}
|
|
20
|
+
return request;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const request = validateRequest(await readRequest());
|
|
25
|
+
const { Entry } = await import("@napi-rs/keyring");
|
|
26
|
+
const entry = new Entry(request.service, request.account);
|
|
27
|
+
|
|
28
|
+
if (request.operation === "get") {
|
|
29
|
+
stdout.write(JSON.stringify({ value: await entry.getPassword() }));
|
|
30
|
+
} else if (request.operation === "set") {
|
|
31
|
+
await entry.setPassword(request.password);
|
|
32
|
+
stdout.write(JSON.stringify({ ok: true }));
|
|
33
|
+
} else {
|
|
34
|
+
await entry.deletePassword();
|
|
35
|
+
stdout.write(JSON.stringify({ ok: true }));
|
|
36
|
+
}
|
|
37
|
+
} catch (error) {
|
|
38
|
+
process.stderr.write(error?.message || String(error));
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
}
|
package/src/skill-refresh.js
CHANGED
|
@@ -11,6 +11,7 @@ import path from "node:path";
|
|
|
11
11
|
|
|
12
12
|
export const SKILL_REFRESH_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
13
13
|
export const SHILIU_SKILL_NAME = "shiliu-ai-mcp";
|
|
14
|
+
export const SHILIU_SKILL_SOURCE = "https://bigbrain.work/shiliuAI";
|
|
14
15
|
const STALE_LOCK_MS = 15 * 60 * 1000;
|
|
15
16
|
|
|
16
17
|
function stateFile(home) {
|
|
@@ -90,9 +91,9 @@ export function runSkillUpdate({
|
|
|
90
91
|
"/d",
|
|
91
92
|
"/s",
|
|
92
93
|
"/c",
|
|
93
|
-
`npx.cmd -y skills
|
|
94
|
+
`npx.cmd -y skills add ${SHILIU_SKILL_SOURCE} -y`,
|
|
94
95
|
]
|
|
95
|
-
: ["-y", "skills", "
|
|
96
|
+
: ["-y", "skills", "add", SHILIU_SKILL_SOURCE, "-y"];
|
|
96
97
|
const result = spawnImpl(
|
|
97
98
|
command,
|
|
98
99
|
args,
|
|
@@ -109,7 +110,7 @@ export function runSkillUpdate({
|
|
|
109
110
|
throw new Error(
|
|
110
111
|
result.stderr?.trim() ||
|
|
111
112
|
result.stdout?.trim() ||
|
|
112
|
-
`skills
|
|
113
|
+
`skills add 返回退出码 ${result.status}`,
|
|
113
114
|
);
|
|
114
115
|
}
|
|
115
116
|
}
|
package/src/token-store.js
CHANGED
|
@@ -3,6 +3,12 @@ import {
|
|
|
3
3
|
KEYRING_SERVICE,
|
|
4
4
|
PENDING_KEYRING_ACCOUNT,
|
|
5
5
|
} from "./constants.js";
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const KEYRING_WORKER_PATH = fileURLToPath(
|
|
10
|
+
new URL("./keyring-worker.js", import.meta.url),
|
|
11
|
+
);
|
|
6
12
|
|
|
7
13
|
function validateTokenSet(value) {
|
|
8
14
|
if (
|
|
@@ -17,7 +23,72 @@ function validateTokenSet(value) {
|
|
|
17
23
|
return value;
|
|
18
24
|
}
|
|
19
25
|
|
|
20
|
-
|
|
26
|
+
export function runKeyringWorker(request, { spawnImpl = spawn } = {}) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
const child = spawnImpl(process.execPath, [KEYRING_WORKER_PATH], {
|
|
29
|
+
windowsHide: true,
|
|
30
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
31
|
+
});
|
|
32
|
+
let stdout = "";
|
|
33
|
+
let stderr = "";
|
|
34
|
+
child.stdout.setEncoding("utf8");
|
|
35
|
+
child.stderr.setEncoding("utf8");
|
|
36
|
+
child.stdout.on("data", (chunk) => {
|
|
37
|
+
stdout += chunk;
|
|
38
|
+
});
|
|
39
|
+
child.stderr.on("data", (chunk) => {
|
|
40
|
+
stderr += chunk;
|
|
41
|
+
});
|
|
42
|
+
child.on("error", reject);
|
|
43
|
+
child.on("close", (code) => {
|
|
44
|
+
if (code !== 0) {
|
|
45
|
+
reject(new Error(stderr.trim() || `凭据库子进程返回退出码 ${code}`));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
resolve(JSON.parse(stdout));
|
|
50
|
+
} catch {
|
|
51
|
+
reject(new Error("凭据库子进程返回了无效响应"));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
child.stdin.end(JSON.stringify(request));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function createSystemEntry(
|
|
59
|
+
account,
|
|
60
|
+
{
|
|
61
|
+
platform = process.platform,
|
|
62
|
+
runWorker = runKeyringWorker,
|
|
63
|
+
} = {},
|
|
64
|
+
) {
|
|
65
|
+
if (platform === "win32") {
|
|
66
|
+
return {
|
|
67
|
+
async setPassword(password) {
|
|
68
|
+
await runWorker({
|
|
69
|
+
operation: "set",
|
|
70
|
+
service: KEYRING_SERVICE,
|
|
71
|
+
account,
|
|
72
|
+
password,
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
async getPassword() {
|
|
76
|
+
const result = await runWorker({
|
|
77
|
+
operation: "get",
|
|
78
|
+
service: KEYRING_SERVICE,
|
|
79
|
+
account,
|
|
80
|
+
});
|
|
81
|
+
return result.value;
|
|
82
|
+
},
|
|
83
|
+
async deletePassword() {
|
|
84
|
+
await runWorker({
|
|
85
|
+
operation: "delete",
|
|
86
|
+
service: KEYRING_SERVICE,
|
|
87
|
+
account,
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
21
92
|
let module;
|
|
22
93
|
try {
|
|
23
94
|
module = await import("@napi-rs/keyring");
|