kfc-code-cli 0.0.1-alpha.1 → 0.0.1-alpha.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/README.md +13 -0
- package/dist/main.mjs +4235 -3836
- package/dist/{multipart-parser-CetGDzPt.mjs → multipart-parser-OI2tZKyS.mjs} +1 -1
- package/dist/session-event-bus-Baiz630d.mjs +106 -0
- package/dist/{src-CzEfkVXq.mjs → src-CL9dVeBV.mjs} +2 -2
- package/package.json +3 -1
- package/dist/client-CdbQcqne.mjs +0 -2007
- package/dist/open-KsP3qi4-.mjs +0 -466
- package/dist/stdio-S3GL8wYq.mjs +0 -584
- package/dist/streamableHttp-D_Fc3kFI.mjs +0 -1530
- package/dist/types-CdOcSyeC.mjs +0 -1244
- /package/dist/{dist-CKY8wJId.mjs → dist-CsQLzhCC.mjs} +0 -0
- /package/dist/{from-BNWSEQzV.mjs → from-BG79vaL9.mjs} +0 -0
package/dist/stdio-S3GL8wYq.mjs
DELETED
|
@@ -1,584 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { a as __toESM, i as __require, t as __commonJSMin } from "./chunk-pPjepVcp.mjs";
|
|
3
|
-
import { y as JSONRPCMessageSchema } from "./types-CdOcSyeC.mjs";
|
|
4
|
-
import { PassThrough } from "node:stream";
|
|
5
|
-
import process$1 from "node:process";
|
|
6
|
-
//#region ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js
|
|
7
|
-
var require_windows = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
8
|
-
module.exports = isexe;
|
|
9
|
-
isexe.sync = sync;
|
|
10
|
-
var fs$2 = __require("fs");
|
|
11
|
-
function checkPathExt(path, options) {
|
|
12
|
-
var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
|
|
13
|
-
if (!pathext) return true;
|
|
14
|
-
pathext = pathext.split(";");
|
|
15
|
-
if (pathext.indexOf("") !== -1) return true;
|
|
16
|
-
for (var i = 0; i < pathext.length; i++) {
|
|
17
|
-
var p = pathext[i].toLowerCase();
|
|
18
|
-
if (p && path.substr(-p.length).toLowerCase() === p) return true;
|
|
19
|
-
}
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
function checkStat(stat, path, options) {
|
|
23
|
-
if (!stat.isSymbolicLink() && !stat.isFile()) return false;
|
|
24
|
-
return checkPathExt(path, options);
|
|
25
|
-
}
|
|
26
|
-
function isexe(path, options, cb) {
|
|
27
|
-
fs$2.stat(path, function(er, stat) {
|
|
28
|
-
cb(er, er ? false : checkStat(stat, path, options));
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
function sync(path, options) {
|
|
32
|
-
return checkStat(fs$2.statSync(path), path, options);
|
|
33
|
-
}
|
|
34
|
-
}));
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js
|
|
37
|
-
var require_mode = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
38
|
-
module.exports = isexe;
|
|
39
|
-
isexe.sync = sync;
|
|
40
|
-
var fs$1 = __require("fs");
|
|
41
|
-
function isexe(path, options, cb) {
|
|
42
|
-
fs$1.stat(path, function(er, stat) {
|
|
43
|
-
cb(er, er ? false : checkStat(stat, options));
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
function sync(path, options) {
|
|
47
|
-
return checkStat(fs$1.statSync(path), options);
|
|
48
|
-
}
|
|
49
|
-
function checkStat(stat, options) {
|
|
50
|
-
return stat.isFile() && checkMode(stat, options);
|
|
51
|
-
}
|
|
52
|
-
function checkMode(stat, options) {
|
|
53
|
-
var mod = stat.mode;
|
|
54
|
-
var uid = stat.uid;
|
|
55
|
-
var gid = stat.gid;
|
|
56
|
-
var myUid = options.uid !== void 0 ? options.uid : process.getuid && process.getuid();
|
|
57
|
-
var myGid = options.gid !== void 0 ? options.gid : process.getgid && process.getgid();
|
|
58
|
-
var u = parseInt("100", 8);
|
|
59
|
-
var g = parseInt("010", 8);
|
|
60
|
-
var o = parseInt("001", 8);
|
|
61
|
-
var ug = u | g;
|
|
62
|
-
return mod & o || mod & g && gid === myGid || mod & u && uid === myUid || mod & ug && myUid === 0;
|
|
63
|
-
}
|
|
64
|
-
}));
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js
|
|
67
|
-
var require_isexe = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
68
|
-
__require("fs");
|
|
69
|
-
var core;
|
|
70
|
-
if (process.platform === "win32" || global.TESTING_WINDOWS) core = require_windows();
|
|
71
|
-
else core = require_mode();
|
|
72
|
-
module.exports = isexe;
|
|
73
|
-
isexe.sync = sync;
|
|
74
|
-
function isexe(path, options, cb) {
|
|
75
|
-
if (typeof options === "function") {
|
|
76
|
-
cb = options;
|
|
77
|
-
options = {};
|
|
78
|
-
}
|
|
79
|
-
if (!cb) {
|
|
80
|
-
if (typeof Promise !== "function") throw new TypeError("callback not provided");
|
|
81
|
-
return new Promise(function(resolve, reject) {
|
|
82
|
-
isexe(path, options || {}, function(er, is) {
|
|
83
|
-
if (er) reject(er);
|
|
84
|
-
else resolve(is);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
core(path, options || {}, function(er, is) {
|
|
89
|
-
if (er) {
|
|
90
|
-
if (er.code === "EACCES" || options && options.ignoreErrors) {
|
|
91
|
-
er = null;
|
|
92
|
-
is = false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
cb(er, is);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
function sync(path, options) {
|
|
99
|
-
try {
|
|
100
|
-
return core.sync(path, options || {});
|
|
101
|
-
} catch (er) {
|
|
102
|
-
if (options && options.ignoreErrors || er.code === "EACCES") return false;
|
|
103
|
-
else throw er;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}));
|
|
107
|
-
//#endregion
|
|
108
|
-
//#region ../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js
|
|
109
|
-
var require_which = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
110
|
-
const isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
|
|
111
|
-
const path$2 = __require("path");
|
|
112
|
-
const COLON = isWindows ? ";" : ":";
|
|
113
|
-
const isexe = require_isexe();
|
|
114
|
-
const getNotFoundError = (cmd) => Object.assign(/* @__PURE__ */ new Error(`not found: ${cmd}`), { code: "ENOENT" });
|
|
115
|
-
const getPathInfo = (cmd, opt) => {
|
|
116
|
-
const colon = opt.colon || COLON;
|
|
117
|
-
const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [""] : [...isWindows ? [process.cwd()] : [], ...(opt.path || process.env.PATH || "").split(colon)];
|
|
118
|
-
const pathExtExe = isWindows ? opt.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
|
|
119
|
-
const pathExt = isWindows ? pathExtExe.split(colon) : [""];
|
|
120
|
-
if (isWindows) {
|
|
121
|
-
if (cmd.indexOf(".") !== -1 && pathExt[0] !== "") pathExt.unshift("");
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
pathEnv,
|
|
125
|
-
pathExt,
|
|
126
|
-
pathExtExe
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
const which = (cmd, opt, cb) => {
|
|
130
|
-
if (typeof opt === "function") {
|
|
131
|
-
cb = opt;
|
|
132
|
-
opt = {};
|
|
133
|
-
}
|
|
134
|
-
if (!opt) opt = {};
|
|
135
|
-
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
136
|
-
const found = [];
|
|
137
|
-
const step = (i) => new Promise((resolve, reject) => {
|
|
138
|
-
if (i === pathEnv.length) return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd));
|
|
139
|
-
const ppRaw = pathEnv[i];
|
|
140
|
-
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
141
|
-
const pCmd = path$2.join(pathPart, cmd);
|
|
142
|
-
resolve(subStep(!pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd, i, 0));
|
|
143
|
-
});
|
|
144
|
-
const subStep = (p, i, ii) => new Promise((resolve, reject) => {
|
|
145
|
-
if (ii === pathExt.length) return resolve(step(i + 1));
|
|
146
|
-
const ext = pathExt[ii];
|
|
147
|
-
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
148
|
-
if (!er && is) if (opt.all) found.push(p + ext);
|
|
149
|
-
else return resolve(p + ext);
|
|
150
|
-
return resolve(subStep(p, i, ii + 1));
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
|
|
154
|
-
};
|
|
155
|
-
const whichSync = (cmd, opt) => {
|
|
156
|
-
opt = opt || {};
|
|
157
|
-
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
158
|
-
const found = [];
|
|
159
|
-
for (let i = 0; i < pathEnv.length; i++) {
|
|
160
|
-
const ppRaw = pathEnv[i];
|
|
161
|
-
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
162
|
-
const pCmd = path$2.join(pathPart, cmd);
|
|
163
|
-
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
164
|
-
for (let j = 0; j < pathExt.length; j++) {
|
|
165
|
-
const cur = p + pathExt[j];
|
|
166
|
-
try {
|
|
167
|
-
if (isexe.sync(cur, { pathExt: pathExtExe })) if (opt.all) found.push(cur);
|
|
168
|
-
else return cur;
|
|
169
|
-
} catch (ex) {}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (opt.all && found.length) return found;
|
|
173
|
-
if (opt.nothrow) return null;
|
|
174
|
-
throw getNotFoundError(cmd);
|
|
175
|
-
};
|
|
176
|
-
module.exports = which;
|
|
177
|
-
which.sync = whichSync;
|
|
178
|
-
}));
|
|
179
|
-
//#endregion
|
|
180
|
-
//#region ../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js
|
|
181
|
-
var require_path_key = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
182
|
-
const pathKey = (options = {}) => {
|
|
183
|
-
const environment = options.env || process.env;
|
|
184
|
-
if ((options.platform || process.platform) !== "win32") return "PATH";
|
|
185
|
-
return Object.keys(environment).reverse().find((key) => key.toUpperCase() === "PATH") || "Path";
|
|
186
|
-
};
|
|
187
|
-
module.exports = pathKey;
|
|
188
|
-
module.exports.default = pathKey;
|
|
189
|
-
}));
|
|
190
|
-
//#endregion
|
|
191
|
-
//#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js
|
|
192
|
-
var require_resolveCommand = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
193
|
-
const path$1 = __require("path");
|
|
194
|
-
const which = require_which();
|
|
195
|
-
const getPathKey = require_path_key();
|
|
196
|
-
function resolveCommandAttempt(parsed, withoutPathExt) {
|
|
197
|
-
const env = parsed.options.env || process.env;
|
|
198
|
-
const cwd = process.cwd();
|
|
199
|
-
const hasCustomCwd = parsed.options.cwd != null;
|
|
200
|
-
const shouldSwitchCwd = hasCustomCwd && process.chdir !== void 0 && !process.chdir.disabled;
|
|
201
|
-
if (shouldSwitchCwd) try {
|
|
202
|
-
process.chdir(parsed.options.cwd);
|
|
203
|
-
} catch (err) {}
|
|
204
|
-
let resolved;
|
|
205
|
-
try {
|
|
206
|
-
resolved = which.sync(parsed.command, {
|
|
207
|
-
path: env[getPathKey({ env })],
|
|
208
|
-
pathExt: withoutPathExt ? path$1.delimiter : void 0
|
|
209
|
-
});
|
|
210
|
-
} catch (e) {} finally {
|
|
211
|
-
if (shouldSwitchCwd) process.chdir(cwd);
|
|
212
|
-
}
|
|
213
|
-
if (resolved) resolved = path$1.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
|
|
214
|
-
return resolved;
|
|
215
|
-
}
|
|
216
|
-
function resolveCommand(parsed) {
|
|
217
|
-
return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);
|
|
218
|
-
}
|
|
219
|
-
module.exports = resolveCommand;
|
|
220
|
-
}));
|
|
221
|
-
//#endregion
|
|
222
|
-
//#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js
|
|
223
|
-
var require_escape = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
224
|
-
const metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
|
|
225
|
-
function escapeCommand(arg) {
|
|
226
|
-
arg = arg.replace(metaCharsRegExp, "^$1");
|
|
227
|
-
return arg;
|
|
228
|
-
}
|
|
229
|
-
function escapeArgument(arg, doubleEscapeMetaChars) {
|
|
230
|
-
arg = `${arg}`;
|
|
231
|
-
arg = arg.replace(/(?=(\\+?)?)\1"/g, "$1$1\\\"");
|
|
232
|
-
arg = arg.replace(/(?=(\\+?)?)\1$/, "$1$1");
|
|
233
|
-
arg = `"${arg}"`;
|
|
234
|
-
arg = arg.replace(metaCharsRegExp, "^$1");
|
|
235
|
-
if (doubleEscapeMetaChars) arg = arg.replace(metaCharsRegExp, "^$1");
|
|
236
|
-
return arg;
|
|
237
|
-
}
|
|
238
|
-
module.exports.command = escapeCommand;
|
|
239
|
-
module.exports.argument = escapeArgument;
|
|
240
|
-
}));
|
|
241
|
-
//#endregion
|
|
242
|
-
//#region ../../node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js
|
|
243
|
-
var require_shebang_regex = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
244
|
-
module.exports = /^#!(.*)/;
|
|
245
|
-
}));
|
|
246
|
-
//#endregion
|
|
247
|
-
//#region ../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js
|
|
248
|
-
var require_shebang_command = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
249
|
-
const shebangRegex = require_shebang_regex();
|
|
250
|
-
module.exports = (string = "") => {
|
|
251
|
-
const match = string.match(shebangRegex);
|
|
252
|
-
if (!match) return null;
|
|
253
|
-
const [path, argument] = match[0].replace(/#! ?/, "").split(" ");
|
|
254
|
-
const binary = path.split("/").pop();
|
|
255
|
-
if (binary === "env") return argument;
|
|
256
|
-
return argument ? `${binary} ${argument}` : binary;
|
|
257
|
-
};
|
|
258
|
-
}));
|
|
259
|
-
//#endregion
|
|
260
|
-
//#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js
|
|
261
|
-
var require_readShebang = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
262
|
-
const fs = __require("fs");
|
|
263
|
-
const shebangCommand = require_shebang_command();
|
|
264
|
-
function readShebang(command) {
|
|
265
|
-
const size = 150;
|
|
266
|
-
const buffer = Buffer.alloc(size);
|
|
267
|
-
let fd;
|
|
268
|
-
try {
|
|
269
|
-
fd = fs.openSync(command, "r");
|
|
270
|
-
fs.readSync(fd, buffer, 0, size, 0);
|
|
271
|
-
fs.closeSync(fd);
|
|
272
|
-
} catch (e) {}
|
|
273
|
-
return shebangCommand(buffer.toString());
|
|
274
|
-
}
|
|
275
|
-
module.exports = readShebang;
|
|
276
|
-
}));
|
|
277
|
-
//#endregion
|
|
278
|
-
//#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js
|
|
279
|
-
var require_parse = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
280
|
-
const path = __require("path");
|
|
281
|
-
const resolveCommand = require_resolveCommand();
|
|
282
|
-
const escape = require_escape();
|
|
283
|
-
const readShebang = require_readShebang();
|
|
284
|
-
const isWin = process.platform === "win32";
|
|
285
|
-
const isExecutableRegExp = /\.(?:com|exe)$/i;
|
|
286
|
-
const isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
|
|
287
|
-
function detectShebang(parsed) {
|
|
288
|
-
parsed.file = resolveCommand(parsed);
|
|
289
|
-
const shebang = parsed.file && readShebang(parsed.file);
|
|
290
|
-
if (shebang) {
|
|
291
|
-
parsed.args.unshift(parsed.file);
|
|
292
|
-
parsed.command = shebang;
|
|
293
|
-
return resolveCommand(parsed);
|
|
294
|
-
}
|
|
295
|
-
return parsed.file;
|
|
296
|
-
}
|
|
297
|
-
function parseNonShell(parsed) {
|
|
298
|
-
if (!isWin) return parsed;
|
|
299
|
-
const commandFile = detectShebang(parsed);
|
|
300
|
-
const needsShell = !isExecutableRegExp.test(commandFile);
|
|
301
|
-
if (parsed.options.forceShell || needsShell) {
|
|
302
|
-
const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
|
|
303
|
-
parsed.command = path.normalize(parsed.command);
|
|
304
|
-
parsed.command = escape.command(parsed.command);
|
|
305
|
-
parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
|
|
306
|
-
parsed.args = [
|
|
307
|
-
"/d",
|
|
308
|
-
"/s",
|
|
309
|
-
"/c",
|
|
310
|
-
`"${[parsed.command].concat(parsed.args).join(" ")}"`
|
|
311
|
-
];
|
|
312
|
-
parsed.command = process.env.comspec || "cmd.exe";
|
|
313
|
-
parsed.options.windowsVerbatimArguments = true;
|
|
314
|
-
}
|
|
315
|
-
return parsed;
|
|
316
|
-
}
|
|
317
|
-
function parse(command, args, options) {
|
|
318
|
-
if (args && !Array.isArray(args)) {
|
|
319
|
-
options = args;
|
|
320
|
-
args = null;
|
|
321
|
-
}
|
|
322
|
-
args = args ? args.slice(0) : [];
|
|
323
|
-
options = Object.assign({}, options);
|
|
324
|
-
const parsed = {
|
|
325
|
-
command,
|
|
326
|
-
args,
|
|
327
|
-
options,
|
|
328
|
-
file: void 0,
|
|
329
|
-
original: {
|
|
330
|
-
command,
|
|
331
|
-
args
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
return options.shell ? parsed : parseNonShell(parsed);
|
|
335
|
-
}
|
|
336
|
-
module.exports = parse;
|
|
337
|
-
}));
|
|
338
|
-
//#endregion
|
|
339
|
-
//#region ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js
|
|
340
|
-
var require_enoent = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
341
|
-
const isWin = process.platform === "win32";
|
|
342
|
-
function notFoundError(original, syscall) {
|
|
343
|
-
return Object.assign(/* @__PURE__ */ new Error(`${syscall} ${original.command} ENOENT`), {
|
|
344
|
-
code: "ENOENT",
|
|
345
|
-
errno: "ENOENT",
|
|
346
|
-
syscall: `${syscall} ${original.command}`,
|
|
347
|
-
path: original.command,
|
|
348
|
-
spawnargs: original.args
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
function hookChildProcess(cp, parsed) {
|
|
352
|
-
if (!isWin) return;
|
|
353
|
-
const originalEmit = cp.emit;
|
|
354
|
-
cp.emit = function(name, arg1) {
|
|
355
|
-
if (name === "exit") {
|
|
356
|
-
const err = verifyENOENT(arg1, parsed);
|
|
357
|
-
if (err) return originalEmit.call(cp, "error", err);
|
|
358
|
-
}
|
|
359
|
-
return originalEmit.apply(cp, arguments);
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
function verifyENOENT(status, parsed) {
|
|
363
|
-
if (isWin && status === 1 && !parsed.file) return notFoundError(parsed.original, "spawn");
|
|
364
|
-
return null;
|
|
365
|
-
}
|
|
366
|
-
function verifyENOENTSync(status, parsed) {
|
|
367
|
-
if (isWin && status === 1 && !parsed.file) return notFoundError(parsed.original, "spawnSync");
|
|
368
|
-
return null;
|
|
369
|
-
}
|
|
370
|
-
module.exports = {
|
|
371
|
-
hookChildProcess,
|
|
372
|
-
verifyENOENT,
|
|
373
|
-
verifyENOENTSync,
|
|
374
|
-
notFoundError
|
|
375
|
-
};
|
|
376
|
-
}));
|
|
377
|
-
//#endregion
|
|
378
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.3.6/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
|
|
379
|
-
var import_cross_spawn = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
380
|
-
const cp = __require("child_process");
|
|
381
|
-
const parse = require_parse();
|
|
382
|
-
const enoent = require_enoent();
|
|
383
|
-
function spawn(command, args, options) {
|
|
384
|
-
const parsed = parse(command, args, options);
|
|
385
|
-
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
386
|
-
enoent.hookChildProcess(spawned, parsed);
|
|
387
|
-
return spawned;
|
|
388
|
-
}
|
|
389
|
-
function spawnSync(command, args, options) {
|
|
390
|
-
const parsed = parse(command, args, options);
|
|
391
|
-
const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
|
|
392
|
-
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
393
|
-
return result;
|
|
394
|
-
}
|
|
395
|
-
module.exports = spawn;
|
|
396
|
-
module.exports.spawn = spawn;
|
|
397
|
-
module.exports.sync = spawnSync;
|
|
398
|
-
module.exports._parse = parse;
|
|
399
|
-
module.exports._enoent = enoent;
|
|
400
|
-
})))(), 1);
|
|
401
|
-
/**
|
|
402
|
-
* Buffers a continuous stdio stream into discrete JSON-RPC messages.
|
|
403
|
-
*/
|
|
404
|
-
var ReadBuffer = class {
|
|
405
|
-
append(chunk) {
|
|
406
|
-
this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
|
|
407
|
-
}
|
|
408
|
-
readMessage() {
|
|
409
|
-
if (!this._buffer) return null;
|
|
410
|
-
const index = this._buffer.indexOf("\n");
|
|
411
|
-
if (index === -1) return null;
|
|
412
|
-
const line = this._buffer.toString("utf8", 0, index).replace(/\r$/, "");
|
|
413
|
-
this._buffer = this._buffer.subarray(index + 1);
|
|
414
|
-
return deserializeMessage(line);
|
|
415
|
-
}
|
|
416
|
-
clear() {
|
|
417
|
-
this._buffer = void 0;
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
function deserializeMessage(line) {
|
|
421
|
-
return JSONRPCMessageSchema.parse(JSON.parse(line));
|
|
422
|
-
}
|
|
423
|
-
function serializeMessage(message) {
|
|
424
|
-
return JSON.stringify(message) + "\n";
|
|
425
|
-
}
|
|
426
|
-
//#endregion
|
|
427
|
-
//#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.3.6/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js
|
|
428
|
-
/**
|
|
429
|
-
* Environment variables to inherit by default, if an environment is not explicitly given.
|
|
430
|
-
*/
|
|
431
|
-
const DEFAULT_INHERITED_ENV_VARS = process$1.platform === "win32" ? [
|
|
432
|
-
"APPDATA",
|
|
433
|
-
"HOMEDRIVE",
|
|
434
|
-
"HOMEPATH",
|
|
435
|
-
"LOCALAPPDATA",
|
|
436
|
-
"PATH",
|
|
437
|
-
"PROCESSOR_ARCHITECTURE",
|
|
438
|
-
"SYSTEMDRIVE",
|
|
439
|
-
"SYSTEMROOT",
|
|
440
|
-
"TEMP",
|
|
441
|
-
"USERNAME",
|
|
442
|
-
"USERPROFILE",
|
|
443
|
-
"PROGRAMFILES"
|
|
444
|
-
] : [
|
|
445
|
-
"HOME",
|
|
446
|
-
"LOGNAME",
|
|
447
|
-
"PATH",
|
|
448
|
-
"SHELL",
|
|
449
|
-
"TERM",
|
|
450
|
-
"USER"
|
|
451
|
-
];
|
|
452
|
-
/**
|
|
453
|
-
* Returns a default environment object including only environment variables deemed safe to inherit.
|
|
454
|
-
*/
|
|
455
|
-
function getDefaultEnvironment() {
|
|
456
|
-
const env = {};
|
|
457
|
-
for (const key of DEFAULT_INHERITED_ENV_VARS) {
|
|
458
|
-
const value = process$1.env[key];
|
|
459
|
-
if (value === void 0) continue;
|
|
460
|
-
if (value.startsWith("()")) continue;
|
|
461
|
-
env[key] = value;
|
|
462
|
-
}
|
|
463
|
-
return env;
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Client transport for stdio: this will connect to a server by spawning a process and communicating with it over stdin/stdout.
|
|
467
|
-
*
|
|
468
|
-
* This transport is only available in Node.js environments.
|
|
469
|
-
*/
|
|
470
|
-
var StdioClientTransport = class {
|
|
471
|
-
constructor(server) {
|
|
472
|
-
this._readBuffer = new ReadBuffer();
|
|
473
|
-
this._stderrStream = null;
|
|
474
|
-
this._serverParams = server;
|
|
475
|
-
if (server.stderr === "pipe" || server.stderr === "overlapped") this._stderrStream = new PassThrough();
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* Starts the server process and prepares to communicate with it.
|
|
479
|
-
*/
|
|
480
|
-
async start() {
|
|
481
|
-
if (this._process) throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");
|
|
482
|
-
return new Promise((resolve, reject) => {
|
|
483
|
-
this._process = (0, import_cross_spawn.default)(this._serverParams.command, this._serverParams.args ?? [], {
|
|
484
|
-
env: {
|
|
485
|
-
...getDefaultEnvironment(),
|
|
486
|
-
...this._serverParams.env
|
|
487
|
-
},
|
|
488
|
-
stdio: [
|
|
489
|
-
"pipe",
|
|
490
|
-
"pipe",
|
|
491
|
-
this._serverParams.stderr ?? "inherit"
|
|
492
|
-
],
|
|
493
|
-
shell: false,
|
|
494
|
-
windowsHide: process$1.platform === "win32",
|
|
495
|
-
cwd: this._serverParams.cwd
|
|
496
|
-
});
|
|
497
|
-
this._process.on("error", (error) => {
|
|
498
|
-
reject(error);
|
|
499
|
-
this.onerror?.(error);
|
|
500
|
-
});
|
|
501
|
-
this._process.on("spawn", () => {
|
|
502
|
-
resolve();
|
|
503
|
-
});
|
|
504
|
-
this._process.on("close", (_code) => {
|
|
505
|
-
this._process = void 0;
|
|
506
|
-
this.onclose?.();
|
|
507
|
-
});
|
|
508
|
-
this._process.stdin?.on("error", (error) => {
|
|
509
|
-
this.onerror?.(error);
|
|
510
|
-
});
|
|
511
|
-
this._process.stdout?.on("data", (chunk) => {
|
|
512
|
-
this._readBuffer.append(chunk);
|
|
513
|
-
this.processReadBuffer();
|
|
514
|
-
});
|
|
515
|
-
this._process.stdout?.on("error", (error) => {
|
|
516
|
-
this.onerror?.(error);
|
|
517
|
-
});
|
|
518
|
-
if (this._stderrStream && this._process.stderr) this._process.stderr.pipe(this._stderrStream);
|
|
519
|
-
});
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* The stderr stream of the child process, if `StdioServerParameters.stderr` was set to "pipe" or "overlapped".
|
|
523
|
-
*
|
|
524
|
-
* If stderr piping was requested, a PassThrough stream is returned _immediately_, allowing callers to
|
|
525
|
-
* attach listeners before the start method is invoked. This prevents loss of any early
|
|
526
|
-
* error output emitted by the child process.
|
|
527
|
-
*/
|
|
528
|
-
get stderr() {
|
|
529
|
-
if (this._stderrStream) return this._stderrStream;
|
|
530
|
-
return this._process?.stderr ?? null;
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* The child process pid spawned by this transport.
|
|
534
|
-
*
|
|
535
|
-
* This is only available after the transport has been started.
|
|
536
|
-
*/
|
|
537
|
-
get pid() {
|
|
538
|
-
return this._process?.pid ?? null;
|
|
539
|
-
}
|
|
540
|
-
processReadBuffer() {
|
|
541
|
-
while (true) try {
|
|
542
|
-
const message = this._readBuffer.readMessage();
|
|
543
|
-
if (message === null) break;
|
|
544
|
-
this.onmessage?.(message);
|
|
545
|
-
} catch (error) {
|
|
546
|
-
this.onerror?.(error);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
async close() {
|
|
550
|
-
if (this._process) {
|
|
551
|
-
const processToClose = this._process;
|
|
552
|
-
this._process = void 0;
|
|
553
|
-
const closePromise = new Promise((resolve) => {
|
|
554
|
-
processToClose.once("close", () => {
|
|
555
|
-
resolve();
|
|
556
|
-
});
|
|
557
|
-
});
|
|
558
|
-
try {
|
|
559
|
-
processToClose.stdin?.end();
|
|
560
|
-
} catch {}
|
|
561
|
-
await Promise.race([closePromise, new Promise((resolve) => setTimeout(resolve, 2e3).unref())]);
|
|
562
|
-
if (processToClose.exitCode === null) {
|
|
563
|
-
try {
|
|
564
|
-
processToClose.kill("SIGTERM");
|
|
565
|
-
} catch {}
|
|
566
|
-
await Promise.race([closePromise, new Promise((resolve) => setTimeout(resolve, 2e3).unref())]);
|
|
567
|
-
}
|
|
568
|
-
if (processToClose.exitCode === null) try {
|
|
569
|
-
processToClose.kill("SIGKILL");
|
|
570
|
-
} catch {}
|
|
571
|
-
}
|
|
572
|
-
this._readBuffer.clear();
|
|
573
|
-
}
|
|
574
|
-
send(message) {
|
|
575
|
-
return new Promise((resolve) => {
|
|
576
|
-
if (!this._process?.stdin) throw new Error("Not connected");
|
|
577
|
-
const json = serializeMessage(message);
|
|
578
|
-
if (this._process.stdin.write(json)) resolve();
|
|
579
|
-
else this._process.stdin.once("drain", resolve);
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
};
|
|
583
|
-
//#endregion
|
|
584
|
-
export { StdioClientTransport };
|