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