@mcp-use/cli 3.1.5-canary.4 → 3.2.0-canary.5
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/dist/commands/client-auth.d.ts +4 -0
- package/dist/commands/client-auth.d.ts.map +1 -0
- package/dist/commands/client.d.ts +4 -2
- package/dist/commands/client.d.ts.map +1 -1
- package/dist/index.cjs +1935 -1202
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1806 -1066
- package/dist/index.js.map +1 -1
- package/dist/utils/format.d.ts +36 -5
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/oauth.d.ts +25 -0
- package/dist/utils/oauth.d.ts.map +1 -0
- package/dist/utils/parse-args.d.ts +27 -0
- package/dist/utils/parse-args.d.ts.map +1 -0
- package/dist/utils/session-storage.d.ts +8 -0
- package/dist/utils/session-storage.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,13 +1,770 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __esm = (fn, res) => function __init() {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
};
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.14_tsx@4.21.0_typescript@5.9.3_yaml@2.8.3/node_modules/tsup/assets/esm_shims.js
|
|
13
|
+
import path from "path";
|
|
14
|
+
import { fileURLToPath } from "url";
|
|
15
|
+
var getFilename, getDirname, __dirname;
|
|
16
|
+
var init_esm_shims = __esm({
|
|
17
|
+
"../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.14_tsx@4.21.0_typescript@5.9.3_yaml@2.8.3/node_modules/tsup/assets/esm_shims.js"() {
|
|
18
|
+
"use strict";
|
|
19
|
+
getFilename = () => fileURLToPath(import.meta.url);
|
|
20
|
+
getDirname = () => path.dirname(getFilename());
|
|
21
|
+
__dirname = /* @__PURE__ */ getDirname();
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// ../../node_modules/.pnpm/is-docker@3.0.0/node_modules/is-docker/index.js
|
|
26
|
+
import fs from "fs";
|
|
27
|
+
function hasDockerEnv() {
|
|
28
|
+
try {
|
|
29
|
+
fs.statSync("/.dockerenv");
|
|
30
|
+
return true;
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function hasDockerCGroup() {
|
|
36
|
+
try {
|
|
37
|
+
return fs.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function isDocker() {
|
|
43
|
+
if (isDockerCached === void 0) {
|
|
44
|
+
isDockerCached = hasDockerEnv() || hasDockerCGroup();
|
|
45
|
+
}
|
|
46
|
+
return isDockerCached;
|
|
47
|
+
}
|
|
48
|
+
var isDockerCached;
|
|
49
|
+
var init_is_docker = __esm({
|
|
50
|
+
"../../node_modules/.pnpm/is-docker@3.0.0/node_modules/is-docker/index.js"() {
|
|
51
|
+
"use strict";
|
|
52
|
+
init_esm_shims();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// ../../node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.js
|
|
57
|
+
import fs2 from "fs";
|
|
58
|
+
function isInsideContainer() {
|
|
59
|
+
if (cachedResult === void 0) {
|
|
60
|
+
cachedResult = hasContainerEnv() || isDocker();
|
|
61
|
+
}
|
|
62
|
+
return cachedResult;
|
|
63
|
+
}
|
|
64
|
+
var cachedResult, hasContainerEnv;
|
|
65
|
+
var init_is_inside_container = __esm({
|
|
66
|
+
"../../node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.js"() {
|
|
67
|
+
"use strict";
|
|
68
|
+
init_esm_shims();
|
|
69
|
+
init_is_docker();
|
|
70
|
+
hasContainerEnv = () => {
|
|
71
|
+
try {
|
|
72
|
+
fs2.statSync("/run/.containerenv");
|
|
73
|
+
return true;
|
|
74
|
+
} catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// ../../node_modules/.pnpm/is-wsl@3.1.0/node_modules/is-wsl/index.js
|
|
82
|
+
import process3 from "process";
|
|
83
|
+
import os2 from "os";
|
|
84
|
+
import fs3 from "fs";
|
|
85
|
+
var isWsl, is_wsl_default;
|
|
86
|
+
var init_is_wsl = __esm({
|
|
87
|
+
"../../node_modules/.pnpm/is-wsl@3.1.0/node_modules/is-wsl/index.js"() {
|
|
88
|
+
"use strict";
|
|
89
|
+
init_esm_shims();
|
|
90
|
+
init_is_inside_container();
|
|
91
|
+
isWsl = () => {
|
|
92
|
+
if (process3.platform !== "linux") {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (os2.release().toLowerCase().includes("microsoft")) {
|
|
96
|
+
if (isInsideContainer()) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
return fs3.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft") ? !isInsideContainer() : false;
|
|
103
|
+
} catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
is_wsl_default = process3.env.__IS_WSL_TEST__ ? isWsl : isWsl();
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// ../../node_modules/.pnpm/powershell-utils@0.1.0/node_modules/powershell-utils/index.js
|
|
112
|
+
import process4 from "process";
|
|
113
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
114
|
+
import { promisify } from "util";
|
|
115
|
+
import childProcess from "child_process";
|
|
116
|
+
import fs4, { constants as fsConstants } from "fs/promises";
|
|
117
|
+
var execFile, powerShellPath, executePowerShell;
|
|
118
|
+
var init_powershell_utils = __esm({
|
|
119
|
+
"../../node_modules/.pnpm/powershell-utils@0.1.0/node_modules/powershell-utils/index.js"() {
|
|
120
|
+
"use strict";
|
|
121
|
+
init_esm_shims();
|
|
122
|
+
execFile = promisify(childProcess.execFile);
|
|
123
|
+
powerShellPath = () => `${process4.env.SYSTEMROOT || process4.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
124
|
+
executePowerShell = async (command, options = {}) => {
|
|
125
|
+
const {
|
|
126
|
+
powerShellPath: psPath,
|
|
127
|
+
...execFileOptions
|
|
128
|
+
} = options;
|
|
129
|
+
const encodedCommand = executePowerShell.encodeCommand(command);
|
|
130
|
+
return execFile(
|
|
131
|
+
psPath ?? powerShellPath(),
|
|
132
|
+
[
|
|
133
|
+
...executePowerShell.argumentsPrefix,
|
|
134
|
+
encodedCommand
|
|
135
|
+
],
|
|
136
|
+
{
|
|
137
|
+
encoding: "utf8",
|
|
138
|
+
...execFileOptions
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
};
|
|
142
|
+
executePowerShell.argumentsPrefix = [
|
|
143
|
+
"-NoProfile",
|
|
144
|
+
"-NonInteractive",
|
|
145
|
+
"-ExecutionPolicy",
|
|
146
|
+
"Bypass",
|
|
147
|
+
"-EncodedCommand"
|
|
148
|
+
];
|
|
149
|
+
executePowerShell.encodeCommand = (command) => Buffer2.from(command, "utf16le").toString("base64");
|
|
150
|
+
executePowerShell.escapeArgument = (value) => `'${String(value).replaceAll("'", "''")}'`;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// ../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/utilities.js
|
|
155
|
+
function parseMountPointFromConfig(content) {
|
|
156
|
+
for (const line of content.split("\n")) {
|
|
157
|
+
if (/^\s*#/.test(line)) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const match = /^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(line);
|
|
161
|
+
if (!match) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
return match.groups.mountPoint.trim().replaceAll(/^["']|["']$/g, "");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
var init_utilities = __esm({
|
|
168
|
+
"../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/utilities.js"() {
|
|
169
|
+
"use strict";
|
|
170
|
+
init_esm_shims();
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// ../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/index.js
|
|
175
|
+
import { promisify as promisify2 } from "util";
|
|
176
|
+
import childProcess2 from "child_process";
|
|
177
|
+
import fs5, { constants as fsConstants2 } from "fs/promises";
|
|
178
|
+
var execFile2, wslDrivesMountPoint, powerShellPathFromWsl, powerShellPath2, canAccessPowerShellPromise, canAccessPowerShell, wslDefaultBrowser, convertWslPathToWindows;
|
|
179
|
+
var init_wsl_utils = __esm({
|
|
180
|
+
"../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/index.js"() {
|
|
181
|
+
"use strict";
|
|
182
|
+
init_esm_shims();
|
|
183
|
+
init_is_wsl();
|
|
184
|
+
init_powershell_utils();
|
|
185
|
+
init_utilities();
|
|
186
|
+
init_is_wsl();
|
|
187
|
+
execFile2 = promisify2(childProcess2.execFile);
|
|
188
|
+
wslDrivesMountPoint = /* @__PURE__ */ (() => {
|
|
189
|
+
const defaultMountPoint = "/mnt/";
|
|
190
|
+
let mountPoint;
|
|
191
|
+
return async function() {
|
|
192
|
+
if (mountPoint) {
|
|
193
|
+
return mountPoint;
|
|
194
|
+
}
|
|
195
|
+
const configFilePath = "/etc/wsl.conf";
|
|
196
|
+
let isConfigFileExists = false;
|
|
197
|
+
try {
|
|
198
|
+
await fs5.access(configFilePath, fsConstants2.F_OK);
|
|
199
|
+
isConfigFileExists = true;
|
|
200
|
+
} catch {
|
|
201
|
+
}
|
|
202
|
+
if (!isConfigFileExists) {
|
|
203
|
+
return defaultMountPoint;
|
|
204
|
+
}
|
|
205
|
+
const configContent = await fs5.readFile(configFilePath, { encoding: "utf8" });
|
|
206
|
+
const parsedMountPoint = parseMountPointFromConfig(configContent);
|
|
207
|
+
if (parsedMountPoint === void 0) {
|
|
208
|
+
return defaultMountPoint;
|
|
209
|
+
}
|
|
210
|
+
mountPoint = parsedMountPoint;
|
|
211
|
+
mountPoint = mountPoint.endsWith("/") ? mountPoint : `${mountPoint}/`;
|
|
212
|
+
return mountPoint;
|
|
213
|
+
};
|
|
214
|
+
})();
|
|
215
|
+
powerShellPathFromWsl = async () => {
|
|
216
|
+
const mountPoint = await wslDrivesMountPoint();
|
|
217
|
+
return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
|
|
218
|
+
};
|
|
219
|
+
powerShellPath2 = is_wsl_default ? powerShellPathFromWsl : powerShellPath;
|
|
220
|
+
canAccessPowerShell = async () => {
|
|
221
|
+
canAccessPowerShellPromise ??= (async () => {
|
|
222
|
+
try {
|
|
223
|
+
const psPath = await powerShellPath2();
|
|
224
|
+
await fs5.access(psPath, fsConstants2.X_OK);
|
|
225
|
+
return true;
|
|
226
|
+
} catch {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
})();
|
|
230
|
+
return canAccessPowerShellPromise;
|
|
231
|
+
};
|
|
232
|
+
wslDefaultBrowser = async () => {
|
|
233
|
+
const psPath = await powerShellPath2();
|
|
234
|
+
const command = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
|
|
235
|
+
const { stdout } = await executePowerShell(command, { powerShellPath: psPath });
|
|
236
|
+
return stdout.trim();
|
|
237
|
+
};
|
|
238
|
+
convertWslPathToWindows = async (path9) => {
|
|
239
|
+
if (/^[a-z]+:\/\//i.test(path9)) {
|
|
240
|
+
return path9;
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
const { stdout } = await execFile2("wslpath", ["-aw", path9], { encoding: "utf8" });
|
|
244
|
+
return stdout.trim();
|
|
245
|
+
} catch {
|
|
246
|
+
return path9;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// ../../node_modules/.pnpm/define-lazy-prop@3.0.0/node_modules/define-lazy-prop/index.js
|
|
253
|
+
function defineLazyProperty(object, propertyName, valueGetter) {
|
|
254
|
+
const define = (value) => Object.defineProperty(object, propertyName, { value, enumerable: true, writable: true });
|
|
255
|
+
Object.defineProperty(object, propertyName, {
|
|
256
|
+
configurable: true,
|
|
257
|
+
enumerable: true,
|
|
258
|
+
get() {
|
|
259
|
+
const result = valueGetter();
|
|
260
|
+
define(result);
|
|
261
|
+
return result;
|
|
262
|
+
},
|
|
263
|
+
set(value) {
|
|
264
|
+
define(value);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
return object;
|
|
268
|
+
}
|
|
269
|
+
var init_define_lazy_prop = __esm({
|
|
270
|
+
"../../node_modules/.pnpm/define-lazy-prop@3.0.0/node_modules/define-lazy-prop/index.js"() {
|
|
271
|
+
"use strict";
|
|
272
|
+
init_esm_shims();
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// ../../node_modules/.pnpm/default-browser-id@5.0.1/node_modules/default-browser-id/index.js
|
|
277
|
+
import { promisify as promisify3 } from "util";
|
|
278
|
+
import process5 from "process";
|
|
279
|
+
import { execFile as execFile3 } from "child_process";
|
|
280
|
+
async function defaultBrowserId() {
|
|
281
|
+
if (process5.platform !== "darwin") {
|
|
282
|
+
throw new Error("macOS only");
|
|
283
|
+
}
|
|
284
|
+
const { stdout } = await execFileAsync("defaults", ["read", "com.apple.LaunchServices/com.apple.launchservices.secure", "LSHandlers"]);
|
|
285
|
+
const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
|
|
286
|
+
const browserId = match?.groups.id ?? "com.apple.Safari";
|
|
287
|
+
if (browserId === "com.apple.safari") {
|
|
288
|
+
return "com.apple.Safari";
|
|
289
|
+
}
|
|
290
|
+
return browserId;
|
|
291
|
+
}
|
|
292
|
+
var execFileAsync;
|
|
293
|
+
var init_default_browser_id = __esm({
|
|
294
|
+
"../../node_modules/.pnpm/default-browser-id@5.0.1/node_modules/default-browser-id/index.js"() {
|
|
295
|
+
"use strict";
|
|
296
|
+
init_esm_shims();
|
|
297
|
+
execFileAsync = promisify3(execFile3);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
// ../../node_modules/.pnpm/run-applescript@7.1.0/node_modules/run-applescript/index.js
|
|
302
|
+
import process6 from "process";
|
|
303
|
+
import { promisify as promisify4 } from "util";
|
|
304
|
+
import { execFile as execFile4, execFileSync } from "child_process";
|
|
305
|
+
async function runAppleScript(script, { humanReadableOutput = true, signal } = {}) {
|
|
306
|
+
if (process6.platform !== "darwin") {
|
|
307
|
+
throw new Error("macOS only");
|
|
308
|
+
}
|
|
309
|
+
const outputArguments = humanReadableOutput ? [] : ["-ss"];
|
|
310
|
+
const execOptions = {};
|
|
311
|
+
if (signal) {
|
|
312
|
+
execOptions.signal = signal;
|
|
313
|
+
}
|
|
314
|
+
const { stdout } = await execFileAsync2("osascript", ["-e", script, outputArguments], execOptions);
|
|
315
|
+
return stdout.trim();
|
|
316
|
+
}
|
|
317
|
+
var execFileAsync2;
|
|
318
|
+
var init_run_applescript = __esm({
|
|
319
|
+
"../../node_modules/.pnpm/run-applescript@7.1.0/node_modules/run-applescript/index.js"() {
|
|
320
|
+
"use strict";
|
|
321
|
+
init_esm_shims();
|
|
322
|
+
execFileAsync2 = promisify4(execFile4);
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// ../../node_modules/.pnpm/bundle-name@4.1.0/node_modules/bundle-name/index.js
|
|
327
|
+
async function bundleName(bundleId) {
|
|
328
|
+
return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string
|
|
329
|
+
tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
|
|
330
|
+
}
|
|
331
|
+
var init_bundle_name = __esm({
|
|
332
|
+
"../../node_modules/.pnpm/bundle-name@4.1.0/node_modules/bundle-name/index.js"() {
|
|
333
|
+
"use strict";
|
|
334
|
+
init_esm_shims();
|
|
335
|
+
init_run_applescript();
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
// ../../node_modules/.pnpm/default-browser@5.5.0/node_modules/default-browser/windows.js
|
|
340
|
+
import { promisify as promisify5 } from "util";
|
|
341
|
+
import { execFile as execFile5 } from "child_process";
|
|
342
|
+
async function defaultBrowser(_execFileAsync = execFileAsync3) {
|
|
343
|
+
const { stdout } = await _execFileAsync("reg", [
|
|
344
|
+
"QUERY",
|
|
345
|
+
" HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice",
|
|
346
|
+
"/v",
|
|
347
|
+
"ProgId"
|
|
348
|
+
]);
|
|
349
|
+
const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
|
|
350
|
+
if (!match) {
|
|
351
|
+
throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
|
|
352
|
+
}
|
|
353
|
+
const { id } = match.groups;
|
|
354
|
+
const dotIndex = id.lastIndexOf(".");
|
|
355
|
+
const hyphenIndex = id.lastIndexOf("-");
|
|
356
|
+
const baseIdByDot = dotIndex === -1 ? void 0 : id.slice(0, dotIndex);
|
|
357
|
+
const baseIdByHyphen = hyphenIndex === -1 ? void 0 : id.slice(0, hyphenIndex);
|
|
358
|
+
return windowsBrowserProgIds[id] ?? windowsBrowserProgIds[baseIdByDot] ?? windowsBrowserProgIds[baseIdByHyphen] ?? { name: id, id };
|
|
359
|
+
}
|
|
360
|
+
var execFileAsync3, windowsBrowserProgIds, _windowsBrowserProgIdMap, UnknownBrowserError;
|
|
361
|
+
var init_windows = __esm({
|
|
362
|
+
"../../node_modules/.pnpm/default-browser@5.5.0/node_modules/default-browser/windows.js"() {
|
|
363
|
+
"use strict";
|
|
364
|
+
init_esm_shims();
|
|
365
|
+
execFileAsync3 = promisify5(execFile5);
|
|
366
|
+
windowsBrowserProgIds = {
|
|
367
|
+
MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" },
|
|
368
|
+
// The missing `L` is correct.
|
|
369
|
+
MSEdgeBHTML: { name: "Edge Beta", id: "com.microsoft.edge.beta" },
|
|
370
|
+
MSEdgeDHTML: { name: "Edge Dev", id: "com.microsoft.edge.dev" },
|
|
371
|
+
AppXq0fevzme2pys62n3e0fbqa7peapykr8v: { name: "Edge", id: "com.microsoft.edge.old" },
|
|
372
|
+
ChromeHTML: { name: "Chrome", id: "com.google.chrome" },
|
|
373
|
+
ChromeBHTML: { name: "Chrome Beta", id: "com.google.chrome.beta" },
|
|
374
|
+
ChromeDHTML: { name: "Chrome Dev", id: "com.google.chrome.dev" },
|
|
375
|
+
ChromiumHTM: { name: "Chromium", id: "org.chromium.Chromium" },
|
|
376
|
+
BraveHTML: { name: "Brave", id: "com.brave.Browser" },
|
|
377
|
+
BraveBHTML: { name: "Brave Beta", id: "com.brave.Browser.beta" },
|
|
378
|
+
BraveDHTML: { name: "Brave Dev", id: "com.brave.Browser.dev" },
|
|
379
|
+
BraveSSHTM: { name: "Brave Nightly", id: "com.brave.Browser.nightly" },
|
|
380
|
+
FirefoxURL: { name: "Firefox", id: "org.mozilla.firefox" },
|
|
381
|
+
OperaStable: { name: "Opera", id: "com.operasoftware.Opera" },
|
|
382
|
+
VivaldiHTM: { name: "Vivaldi", id: "com.vivaldi.Vivaldi" },
|
|
383
|
+
"IE.HTTP": { name: "Internet Explorer", id: "com.microsoft.ie" }
|
|
384
|
+
};
|
|
385
|
+
_windowsBrowserProgIdMap = new Map(Object.entries(windowsBrowserProgIds));
|
|
386
|
+
UnknownBrowserError = class extends Error {
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// ../../node_modules/.pnpm/default-browser@5.5.0/node_modules/default-browser/index.js
|
|
392
|
+
import { promisify as promisify6 } from "util";
|
|
393
|
+
import process7 from "process";
|
|
394
|
+
import { execFile as execFile6 } from "child_process";
|
|
395
|
+
async function defaultBrowser2() {
|
|
396
|
+
if (process7.platform === "darwin") {
|
|
397
|
+
const id = await defaultBrowserId();
|
|
398
|
+
const name = await bundleName(id);
|
|
399
|
+
return { name, id };
|
|
400
|
+
}
|
|
401
|
+
if (process7.platform === "linux") {
|
|
402
|
+
const { stdout } = await execFileAsync4("xdg-mime", ["query", "default", "x-scheme-handler/http"]);
|
|
403
|
+
const id = stdout.trim();
|
|
404
|
+
const name = titleize(id.replace(/.desktop$/, "").replace("-", " "));
|
|
405
|
+
return { name, id };
|
|
406
|
+
}
|
|
407
|
+
if (process7.platform === "win32") {
|
|
408
|
+
return defaultBrowser();
|
|
409
|
+
}
|
|
410
|
+
throw new Error("Only macOS, Linux, and Windows are supported");
|
|
411
|
+
}
|
|
412
|
+
var execFileAsync4, titleize;
|
|
413
|
+
var init_default_browser = __esm({
|
|
414
|
+
"../../node_modules/.pnpm/default-browser@5.5.0/node_modules/default-browser/index.js"() {
|
|
415
|
+
"use strict";
|
|
416
|
+
init_esm_shims();
|
|
417
|
+
init_default_browser_id();
|
|
418
|
+
init_bundle_name();
|
|
419
|
+
init_windows();
|
|
420
|
+
init_windows();
|
|
421
|
+
execFileAsync4 = promisify6(execFile6);
|
|
422
|
+
titleize = (string) => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (x) => x.toUpperCase());
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
// ../../node_modules/.pnpm/is-in-ssh@1.0.0/node_modules/is-in-ssh/index.js
|
|
427
|
+
import process8 from "process";
|
|
428
|
+
var isInSsh, is_in_ssh_default;
|
|
429
|
+
var init_is_in_ssh = __esm({
|
|
430
|
+
"../../node_modules/.pnpm/is-in-ssh@1.0.0/node_modules/is-in-ssh/index.js"() {
|
|
431
|
+
"use strict";
|
|
432
|
+
init_esm_shims();
|
|
433
|
+
isInSsh = Boolean(process8.env.SSH_CONNECTION || process8.env.SSH_CLIENT || process8.env.SSH_TTY);
|
|
434
|
+
is_in_ssh_default = isInSsh;
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// ../../node_modules/.pnpm/open@11.0.0/node_modules/open/index.js
|
|
439
|
+
var open_exports = {};
|
|
440
|
+
__export(open_exports, {
|
|
441
|
+
apps: () => apps,
|
|
442
|
+
default: () => open_default,
|
|
443
|
+
openApp: () => openApp
|
|
444
|
+
});
|
|
445
|
+
import process9 from "process";
|
|
446
|
+
import path2 from "path";
|
|
447
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
448
|
+
import childProcess3 from "child_process";
|
|
449
|
+
import fs6, { constants as fsConstants3 } from "fs/promises";
|
|
450
|
+
function detectArchBinary(binary) {
|
|
451
|
+
if (typeof binary === "string" || Array.isArray(binary)) {
|
|
452
|
+
return binary;
|
|
453
|
+
}
|
|
454
|
+
const { [arch]: archBinary } = binary;
|
|
455
|
+
if (!archBinary) {
|
|
456
|
+
throw new Error(`${arch} is not supported`);
|
|
457
|
+
}
|
|
458
|
+
return archBinary;
|
|
459
|
+
}
|
|
460
|
+
function detectPlatformBinary({ [platform]: platformBinary }, { wsl } = {}) {
|
|
461
|
+
if (wsl && is_wsl_default) {
|
|
462
|
+
return detectArchBinary(wsl);
|
|
463
|
+
}
|
|
464
|
+
if (!platformBinary) {
|
|
465
|
+
throw new Error(`${platform} is not supported`);
|
|
466
|
+
}
|
|
467
|
+
return detectArchBinary(platformBinary);
|
|
468
|
+
}
|
|
469
|
+
var fallbackAttemptSymbol, __dirname2, localXdgOpenPath, platform, arch, tryEachApp, baseOpen, open, openApp, apps, open_default;
|
|
470
|
+
var init_open = __esm({
|
|
471
|
+
"../../node_modules/.pnpm/open@11.0.0/node_modules/open/index.js"() {
|
|
472
|
+
"use strict";
|
|
473
|
+
init_esm_shims();
|
|
474
|
+
init_wsl_utils();
|
|
475
|
+
init_powershell_utils();
|
|
476
|
+
init_define_lazy_prop();
|
|
477
|
+
init_default_browser();
|
|
478
|
+
init_is_inside_container();
|
|
479
|
+
init_is_in_ssh();
|
|
480
|
+
fallbackAttemptSymbol = /* @__PURE__ */ Symbol("fallbackAttempt");
|
|
481
|
+
__dirname2 = import.meta.url ? path2.dirname(fileURLToPath2(import.meta.url)) : "";
|
|
482
|
+
localXdgOpenPath = path2.join(__dirname2, "xdg-open");
|
|
483
|
+
({ platform, arch } = process9);
|
|
484
|
+
tryEachApp = async (apps2, opener) => {
|
|
485
|
+
if (apps2.length === 0) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
const errors = [];
|
|
489
|
+
for (const app of apps2) {
|
|
490
|
+
try {
|
|
491
|
+
return await opener(app);
|
|
492
|
+
} catch (error) {
|
|
493
|
+
errors.push(error);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
throw new AggregateError(errors, "Failed to open in all supported apps");
|
|
497
|
+
};
|
|
498
|
+
baseOpen = async (options) => {
|
|
499
|
+
options = {
|
|
500
|
+
wait: false,
|
|
501
|
+
background: false,
|
|
502
|
+
newInstance: false,
|
|
503
|
+
allowNonzeroExitCode: false,
|
|
504
|
+
...options
|
|
505
|
+
};
|
|
506
|
+
const isFallbackAttempt = options[fallbackAttemptSymbol] === true;
|
|
507
|
+
delete options[fallbackAttemptSymbol];
|
|
508
|
+
if (Array.isArray(options.app)) {
|
|
509
|
+
return tryEachApp(options.app, (singleApp) => baseOpen({
|
|
510
|
+
...options,
|
|
511
|
+
app: singleApp,
|
|
512
|
+
[fallbackAttemptSymbol]: true
|
|
513
|
+
}));
|
|
514
|
+
}
|
|
515
|
+
let { name: app, arguments: appArguments = [] } = options.app ?? {};
|
|
516
|
+
appArguments = [...appArguments];
|
|
517
|
+
if (Array.isArray(app)) {
|
|
518
|
+
return tryEachApp(app, (appName) => baseOpen({
|
|
519
|
+
...options,
|
|
520
|
+
app: {
|
|
521
|
+
name: appName,
|
|
522
|
+
arguments: appArguments
|
|
523
|
+
},
|
|
524
|
+
[fallbackAttemptSymbol]: true
|
|
525
|
+
}));
|
|
526
|
+
}
|
|
527
|
+
if (app === "browser" || app === "browserPrivate") {
|
|
528
|
+
const ids = {
|
|
529
|
+
"com.google.chrome": "chrome",
|
|
530
|
+
"google-chrome.desktop": "chrome",
|
|
531
|
+
"com.brave.browser": "brave",
|
|
532
|
+
"org.mozilla.firefox": "firefox",
|
|
533
|
+
"firefox.desktop": "firefox",
|
|
534
|
+
"com.microsoft.msedge": "edge",
|
|
535
|
+
"com.microsoft.edge": "edge",
|
|
536
|
+
"com.microsoft.edgemac": "edge",
|
|
537
|
+
"microsoft-edge.desktop": "edge",
|
|
538
|
+
"com.apple.safari": "safari"
|
|
539
|
+
};
|
|
540
|
+
const flags = {
|
|
541
|
+
chrome: "--incognito",
|
|
542
|
+
brave: "--incognito",
|
|
543
|
+
firefox: "--private-window",
|
|
544
|
+
edge: "--inPrivate"
|
|
545
|
+
// Safari doesn't support private mode via command line
|
|
546
|
+
};
|
|
547
|
+
let browser;
|
|
548
|
+
if (is_wsl_default) {
|
|
549
|
+
const progId = await wslDefaultBrowser();
|
|
550
|
+
const browserInfo = _windowsBrowserProgIdMap.get(progId);
|
|
551
|
+
browser = browserInfo ?? {};
|
|
552
|
+
} else {
|
|
553
|
+
browser = await defaultBrowser2();
|
|
554
|
+
}
|
|
555
|
+
if (browser.id in ids) {
|
|
556
|
+
const browserName = ids[browser.id.toLowerCase()];
|
|
557
|
+
if (app === "browserPrivate") {
|
|
558
|
+
if (browserName === "safari") {
|
|
559
|
+
throw new Error("Safari doesn't support opening in private mode via command line");
|
|
560
|
+
}
|
|
561
|
+
appArguments.push(flags[browserName]);
|
|
562
|
+
}
|
|
563
|
+
return baseOpen({
|
|
564
|
+
...options,
|
|
565
|
+
app: {
|
|
566
|
+
name: apps[browserName],
|
|
567
|
+
arguments: appArguments
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
throw new Error(`${browser.name} is not supported as a default browser`);
|
|
572
|
+
}
|
|
573
|
+
let command;
|
|
574
|
+
const cliArguments = [];
|
|
575
|
+
const childProcessOptions = {};
|
|
576
|
+
let shouldUseWindowsInWsl = false;
|
|
577
|
+
if (is_wsl_default && !isInsideContainer() && !is_in_ssh_default && !app) {
|
|
578
|
+
shouldUseWindowsInWsl = await canAccessPowerShell();
|
|
579
|
+
}
|
|
580
|
+
if (platform === "darwin") {
|
|
581
|
+
command = "open";
|
|
582
|
+
if (options.wait) {
|
|
583
|
+
cliArguments.push("--wait-apps");
|
|
584
|
+
}
|
|
585
|
+
if (options.background) {
|
|
586
|
+
cliArguments.push("--background");
|
|
587
|
+
}
|
|
588
|
+
if (options.newInstance) {
|
|
589
|
+
cliArguments.push("--new");
|
|
590
|
+
}
|
|
591
|
+
if (app) {
|
|
592
|
+
cliArguments.push("-a", app);
|
|
593
|
+
}
|
|
594
|
+
} else if (platform === "win32" || shouldUseWindowsInWsl) {
|
|
595
|
+
command = await powerShellPath2();
|
|
596
|
+
cliArguments.push(...executePowerShell.argumentsPrefix);
|
|
597
|
+
if (!is_wsl_default) {
|
|
598
|
+
childProcessOptions.windowsVerbatimArguments = true;
|
|
599
|
+
}
|
|
600
|
+
if (is_wsl_default && options.target) {
|
|
601
|
+
options.target = await convertWslPathToWindows(options.target);
|
|
602
|
+
}
|
|
603
|
+
const encodedArguments = ["$ProgressPreference = 'SilentlyContinue';", "Start"];
|
|
604
|
+
if (options.wait) {
|
|
605
|
+
encodedArguments.push("-Wait");
|
|
606
|
+
}
|
|
607
|
+
if (app) {
|
|
608
|
+
encodedArguments.push(executePowerShell.escapeArgument(app));
|
|
609
|
+
if (options.target) {
|
|
610
|
+
appArguments.push(options.target);
|
|
611
|
+
}
|
|
612
|
+
} else if (options.target) {
|
|
613
|
+
encodedArguments.push(executePowerShell.escapeArgument(options.target));
|
|
614
|
+
}
|
|
615
|
+
if (appArguments.length > 0) {
|
|
616
|
+
appArguments = appArguments.map((argument) => executePowerShell.escapeArgument(argument));
|
|
617
|
+
encodedArguments.push("-ArgumentList", appArguments.join(","));
|
|
618
|
+
}
|
|
619
|
+
options.target = executePowerShell.encodeCommand(encodedArguments.join(" "));
|
|
620
|
+
if (!options.wait) {
|
|
621
|
+
childProcessOptions.stdio = "ignore";
|
|
622
|
+
}
|
|
623
|
+
} else {
|
|
624
|
+
if (app) {
|
|
625
|
+
command = app;
|
|
626
|
+
} else {
|
|
627
|
+
const isBundled = !__dirname2 || __dirname2 === "/";
|
|
628
|
+
let exeLocalXdgOpen = false;
|
|
629
|
+
try {
|
|
630
|
+
await fs6.access(localXdgOpenPath, fsConstants3.X_OK);
|
|
631
|
+
exeLocalXdgOpen = true;
|
|
632
|
+
} catch {
|
|
633
|
+
}
|
|
634
|
+
const useSystemXdgOpen = process9.versions.electron ?? (platform === "android" || isBundled || !exeLocalXdgOpen);
|
|
635
|
+
command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath;
|
|
636
|
+
}
|
|
637
|
+
if (appArguments.length > 0) {
|
|
638
|
+
cliArguments.push(...appArguments);
|
|
639
|
+
}
|
|
640
|
+
if (!options.wait) {
|
|
641
|
+
childProcessOptions.stdio = "ignore";
|
|
642
|
+
childProcessOptions.detached = true;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (platform === "darwin" && appArguments.length > 0) {
|
|
646
|
+
cliArguments.push("--args", ...appArguments);
|
|
647
|
+
}
|
|
648
|
+
if (options.target) {
|
|
649
|
+
cliArguments.push(options.target);
|
|
650
|
+
}
|
|
651
|
+
const subprocess = childProcess3.spawn(command, cliArguments, childProcessOptions);
|
|
652
|
+
if (options.wait) {
|
|
653
|
+
return new Promise((resolve2, reject) => {
|
|
654
|
+
subprocess.once("error", reject);
|
|
655
|
+
subprocess.once("close", (exitCode) => {
|
|
656
|
+
if (!options.allowNonzeroExitCode && exitCode !== 0) {
|
|
657
|
+
reject(new Error(`Exited with code ${exitCode}`));
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
resolve2(subprocess);
|
|
661
|
+
});
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
if (isFallbackAttempt) {
|
|
665
|
+
return new Promise((resolve2, reject) => {
|
|
666
|
+
subprocess.once("error", reject);
|
|
667
|
+
subprocess.once("spawn", () => {
|
|
668
|
+
subprocess.once("close", (exitCode) => {
|
|
669
|
+
subprocess.off("error", reject);
|
|
670
|
+
if (exitCode !== 0) {
|
|
671
|
+
reject(new Error(`Exited with code ${exitCode}`));
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
subprocess.unref();
|
|
675
|
+
resolve2(subprocess);
|
|
676
|
+
});
|
|
677
|
+
});
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
subprocess.unref();
|
|
681
|
+
return new Promise((resolve2, reject) => {
|
|
682
|
+
subprocess.once("error", reject);
|
|
683
|
+
subprocess.once("spawn", () => {
|
|
684
|
+
subprocess.off("error", reject);
|
|
685
|
+
resolve2(subprocess);
|
|
686
|
+
});
|
|
687
|
+
});
|
|
688
|
+
};
|
|
689
|
+
open = (target, options) => {
|
|
690
|
+
if (typeof target !== "string") {
|
|
691
|
+
throw new TypeError("Expected a `target`");
|
|
692
|
+
}
|
|
693
|
+
return baseOpen({
|
|
694
|
+
...options,
|
|
695
|
+
target
|
|
696
|
+
});
|
|
697
|
+
};
|
|
698
|
+
openApp = (name, options) => {
|
|
699
|
+
if (typeof name !== "string" && !Array.isArray(name)) {
|
|
700
|
+
throw new TypeError("Expected a valid `name`");
|
|
701
|
+
}
|
|
702
|
+
const { arguments: appArguments = [] } = options ?? {};
|
|
703
|
+
if (appArguments !== void 0 && appArguments !== null && !Array.isArray(appArguments)) {
|
|
704
|
+
throw new TypeError("Expected `appArguments` as Array type");
|
|
705
|
+
}
|
|
706
|
+
return baseOpen({
|
|
707
|
+
...options,
|
|
708
|
+
app: {
|
|
709
|
+
name,
|
|
710
|
+
arguments: appArguments
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
};
|
|
714
|
+
apps = {
|
|
715
|
+
browser: "browser",
|
|
716
|
+
browserPrivate: "browserPrivate"
|
|
717
|
+
};
|
|
718
|
+
defineLazyProperty(apps, "chrome", () => detectPlatformBinary({
|
|
719
|
+
darwin: "google chrome",
|
|
720
|
+
win32: "chrome",
|
|
721
|
+
// `chromium-browser` is the older deb package name used by Ubuntu/Debian before snap.
|
|
722
|
+
linux: ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"]
|
|
723
|
+
}, {
|
|
724
|
+
wsl: {
|
|
725
|
+
ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
|
|
726
|
+
x64: ["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]
|
|
727
|
+
}
|
|
728
|
+
}));
|
|
729
|
+
defineLazyProperty(apps, "brave", () => detectPlatformBinary({
|
|
730
|
+
darwin: "brave browser",
|
|
731
|
+
win32: "brave",
|
|
732
|
+
linux: ["brave-browser", "brave"]
|
|
733
|
+
}, {
|
|
734
|
+
wsl: {
|
|
735
|
+
ia32: "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
|
|
736
|
+
x64: ["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe", "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"]
|
|
737
|
+
}
|
|
738
|
+
}));
|
|
739
|
+
defineLazyProperty(apps, "firefox", () => detectPlatformBinary({
|
|
740
|
+
darwin: "firefox",
|
|
741
|
+
win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
|
|
742
|
+
linux: "firefox"
|
|
743
|
+
}, {
|
|
744
|
+
wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
|
|
745
|
+
}));
|
|
746
|
+
defineLazyProperty(apps, "edge", () => detectPlatformBinary({
|
|
747
|
+
darwin: "microsoft edge",
|
|
748
|
+
win32: "msedge",
|
|
749
|
+
linux: ["microsoft-edge", "microsoft-edge-dev"]
|
|
750
|
+
}, {
|
|
751
|
+
wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
|
|
752
|
+
}));
|
|
753
|
+
defineLazyProperty(apps, "safari", () => detectPlatformBinary({
|
|
754
|
+
darwin: "Safari"
|
|
755
|
+
}));
|
|
756
|
+
open_default = open;
|
|
757
|
+
}
|
|
758
|
+
});
|
|
2
759
|
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var __dirname = /* @__PURE__ */ getDirname();
|
|
760
|
+
// src/index.ts
|
|
761
|
+
init_esm_shims();
|
|
762
|
+
|
|
763
|
+
// ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
|
|
764
|
+
init_esm_shims();
|
|
9
765
|
|
|
10
766
|
// ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
767
|
+
init_esm_shims();
|
|
11
768
|
var ANSI_BACKGROUND_OFFSET = 10;
|
|
12
769
|
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
13
770
|
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
@@ -183,954 +940,349 @@ function assembleStyles() {
|
|
|
183
940
|
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
184
941
|
enumerable: false
|
|
185
942
|
},
|
|
186
|
-
hexToAnsi: {
|
|
187
|
-
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
188
|
-
enumerable: false
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
return styles;
|
|
192
|
-
}
|
|
193
|
-
var ansiStyles = assembleStyles();
|
|
194
|
-
var ansi_styles_default = ansiStyles;
|
|
195
|
-
|
|
196
|
-
// ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js
|
|
197
|
-
import process2 from "process";
|
|
198
|
-
import os from "os";
|
|
199
|
-
import tty from "tty";
|
|
200
|
-
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.argv) {
|
|
201
|
-
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
202
|
-
const position = argv.indexOf(prefix + flag);
|
|
203
|
-
const terminatorPosition = argv.indexOf("--");
|
|
204
|
-
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
205
|
-
}
|
|
206
|
-
var { env } = process2;
|
|
207
|
-
var flagForceColor;
|
|
208
|
-
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
209
|
-
flagForceColor = 0;
|
|
210
|
-
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
211
|
-
flagForceColor = 1;
|
|
212
|
-
}
|
|
213
|
-
function envForceColor() {
|
|
214
|
-
if ("FORCE_COLOR" in env) {
|
|
215
|
-
if (env.FORCE_COLOR === "true") {
|
|
216
|
-
return 1;
|
|
217
|
-
}
|
|
218
|
-
if (env.FORCE_COLOR === "false") {
|
|
219
|
-
return 0;
|
|
220
|
-
}
|
|
221
|
-
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
function translateLevel(level) {
|
|
225
|
-
if (level === 0) {
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
return {
|
|
229
|
-
level,
|
|
230
|
-
hasBasic: true,
|
|
231
|
-
has256: level >= 2,
|
|
232
|
-
has16m: level >= 3
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
236
|
-
const noFlagForceColor = envForceColor();
|
|
237
|
-
if (noFlagForceColor !== void 0) {
|
|
238
|
-
flagForceColor = noFlagForceColor;
|
|
239
|
-
}
|
|
240
|
-
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
241
|
-
if (forceColor === 0) {
|
|
242
|
-
return 0;
|
|
243
|
-
}
|
|
244
|
-
if (sniffFlags) {
|
|
245
|
-
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
246
|
-
return 3;
|
|
247
|
-
}
|
|
248
|
-
if (hasFlag("color=256")) {
|
|
249
|
-
return 2;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
253
|
-
return 1;
|
|
254
|
-
}
|
|
255
|
-
if (haveStream && !streamIsTTY && forceColor === void 0) {
|
|
256
|
-
return 0;
|
|
257
|
-
}
|
|
258
|
-
const min = forceColor || 0;
|
|
259
|
-
if (env.TERM === "dumb") {
|
|
260
|
-
return min;
|
|
261
|
-
}
|
|
262
|
-
if (process2.platform === "win32") {
|
|
263
|
-
const osRelease = os.release().split(".");
|
|
264
|
-
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
265
|
-
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
266
|
-
}
|
|
267
|
-
return 1;
|
|
268
|
-
}
|
|
269
|
-
if ("CI" in env) {
|
|
270
|
-
if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
|
|
271
|
-
return 3;
|
|
272
|
-
}
|
|
273
|
-
if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
274
|
-
return 1;
|
|
275
|
-
}
|
|
276
|
-
return min;
|
|
277
|
-
}
|
|
278
|
-
if ("TEAMCITY_VERSION" in env) {
|
|
279
|
-
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
280
|
-
}
|
|
281
|
-
if (env.COLORTERM === "truecolor") {
|
|
282
|
-
return 3;
|
|
283
|
-
}
|
|
284
|
-
if (env.TERM === "xterm-kitty") {
|
|
285
|
-
return 3;
|
|
286
|
-
}
|
|
287
|
-
if (env.TERM === "xterm-ghostty") {
|
|
288
|
-
return 3;
|
|
289
|
-
}
|
|
290
|
-
if (env.TERM === "wezterm") {
|
|
291
|
-
return 3;
|
|
292
|
-
}
|
|
293
|
-
if ("TERM_PROGRAM" in env) {
|
|
294
|
-
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
295
|
-
switch (env.TERM_PROGRAM) {
|
|
296
|
-
case "iTerm.app": {
|
|
297
|
-
return version >= 3 ? 3 : 2;
|
|
298
|
-
}
|
|
299
|
-
case "Apple_Terminal": {
|
|
300
|
-
return 2;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
if (/-256(color)?$/i.test(env.TERM)) {
|
|
305
|
-
return 2;
|
|
306
|
-
}
|
|
307
|
-
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
308
|
-
return 1;
|
|
309
|
-
}
|
|
310
|
-
if ("COLORTERM" in env) {
|
|
311
|
-
return 1;
|
|
312
|
-
}
|
|
313
|
-
return min;
|
|
314
|
-
}
|
|
315
|
-
function createSupportsColor(stream, options = {}) {
|
|
316
|
-
const level = _supportsColor(stream, {
|
|
317
|
-
streamIsTTY: stream && stream.isTTY,
|
|
318
|
-
...options
|
|
319
|
-
});
|
|
320
|
-
return translateLevel(level);
|
|
321
|
-
}
|
|
322
|
-
var supportsColor = {
|
|
323
|
-
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
324
|
-
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
|
325
|
-
};
|
|
326
|
-
var supports_color_default = supportsColor;
|
|
327
|
-
|
|
328
|
-
// ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js
|
|
329
|
-
function stringReplaceAll(string, substring, replacer) {
|
|
330
|
-
let index = string.indexOf(substring);
|
|
331
|
-
if (index === -1) {
|
|
332
|
-
return string;
|
|
333
|
-
}
|
|
334
|
-
const substringLength = substring.length;
|
|
335
|
-
let endIndex = 0;
|
|
336
|
-
let returnValue = "";
|
|
337
|
-
do {
|
|
338
|
-
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
339
|
-
endIndex = index + substringLength;
|
|
340
|
-
index = string.indexOf(substring, endIndex);
|
|
341
|
-
} while (index !== -1);
|
|
342
|
-
returnValue += string.slice(endIndex);
|
|
343
|
-
return returnValue;
|
|
344
|
-
}
|
|
345
|
-
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
346
|
-
let endIndex = 0;
|
|
347
|
-
let returnValue = "";
|
|
348
|
-
do {
|
|
349
|
-
const gotCR = string[index - 1] === "\r";
|
|
350
|
-
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
|
|
351
|
-
endIndex = index + 1;
|
|
352
|
-
index = string.indexOf("\n", endIndex);
|
|
353
|
-
} while (index !== -1);
|
|
354
|
-
returnValue += string.slice(endIndex);
|
|
355
|
-
return returnValue;
|
|
943
|
+
hexToAnsi: {
|
|
944
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
945
|
+
enumerable: false
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
return styles;
|
|
356
949
|
}
|
|
950
|
+
var ansiStyles = assembleStyles();
|
|
951
|
+
var ansi_styles_default = ansiStyles;
|
|
357
952
|
|
|
358
|
-
// ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
"
|
|
365
|
-
|
|
366
|
-
"
|
|
367
|
-
|
|
368
|
-
];
|
|
369
|
-
var styles2 = /* @__PURE__ */ Object.create(null);
|
|
370
|
-
var applyOptions = (object, options = {}) => {
|
|
371
|
-
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
372
|
-
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
373
|
-
}
|
|
374
|
-
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
375
|
-
object.level = options.level === void 0 ? colorLevel : options.level;
|
|
376
|
-
};
|
|
377
|
-
var chalkFactory = (options) => {
|
|
378
|
-
const chalk2 = (...strings) => strings.join(" ");
|
|
379
|
-
applyOptions(chalk2, options);
|
|
380
|
-
Object.setPrototypeOf(chalk2, createChalk.prototype);
|
|
381
|
-
return chalk2;
|
|
382
|
-
};
|
|
383
|
-
function createChalk(options) {
|
|
384
|
-
return chalkFactory(options);
|
|
953
|
+
// ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js
|
|
954
|
+
init_esm_shims();
|
|
955
|
+
import process2 from "process";
|
|
956
|
+
import os from "os";
|
|
957
|
+
import tty from "tty";
|
|
958
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.argv) {
|
|
959
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
960
|
+
const position = argv.indexOf(prefix + flag);
|
|
961
|
+
const terminatorPosition = argv.indexOf("--");
|
|
962
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
385
963
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
return builder;
|
|
393
|
-
}
|
|
394
|
-
};
|
|
964
|
+
var { env } = process2;
|
|
965
|
+
var flagForceColor;
|
|
966
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
967
|
+
flagForceColor = 0;
|
|
968
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
969
|
+
flagForceColor = 1;
|
|
395
970
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
return builder;
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
var getModelAnsi = (model, level, type, ...arguments_) => {
|
|
404
|
-
if (model === "rgb") {
|
|
405
|
-
if (level === "ansi16m") {
|
|
406
|
-
return ansi_styles_default[type].ansi16m(...arguments_);
|
|
971
|
+
function envForceColor() {
|
|
972
|
+
if ("FORCE_COLOR" in env) {
|
|
973
|
+
if (env.FORCE_COLOR === "true") {
|
|
974
|
+
return 1;
|
|
407
975
|
}
|
|
408
|
-
if (
|
|
409
|
-
return
|
|
976
|
+
if (env.FORCE_COLOR === "false") {
|
|
977
|
+
return 0;
|
|
410
978
|
}
|
|
411
|
-
return
|
|
412
|
-
}
|
|
413
|
-
if (model === "hex") {
|
|
414
|
-
return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
|
|
979
|
+
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
415
980
|
}
|
|
416
|
-
return ansi_styles_default[type][model](...arguments_);
|
|
417
|
-
};
|
|
418
|
-
var usedModels = ["rgb", "hex", "ansi256"];
|
|
419
|
-
for (const model of usedModels) {
|
|
420
|
-
styles2[model] = {
|
|
421
|
-
get() {
|
|
422
|
-
const { level } = this;
|
|
423
|
-
return function(...arguments_) {
|
|
424
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
425
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
430
|
-
styles2[bgModel] = {
|
|
431
|
-
get() {
|
|
432
|
-
const { level } = this;
|
|
433
|
-
return function(...arguments_) {
|
|
434
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
|
435
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
981
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
level: {
|
|
444
|
-
enumerable: true,
|
|
445
|
-
get() {
|
|
446
|
-
return this[GENERATOR].level;
|
|
447
|
-
},
|
|
448
|
-
set(level) {
|
|
449
|
-
this[GENERATOR].level = level;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
var createStyler = (open2, close, parent) => {
|
|
454
|
-
let openAll;
|
|
455
|
-
let closeAll;
|
|
456
|
-
if (parent === void 0) {
|
|
457
|
-
openAll = open2;
|
|
458
|
-
closeAll = close;
|
|
459
|
-
} else {
|
|
460
|
-
openAll = parent.openAll + open2;
|
|
461
|
-
closeAll = close + parent.closeAll;
|
|
982
|
+
function translateLevel(level) {
|
|
983
|
+
if (level === 0) {
|
|
984
|
+
return false;
|
|
462
985
|
}
|
|
463
986
|
return {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
parent
|
|
987
|
+
level,
|
|
988
|
+
hasBasic: true,
|
|
989
|
+
has256: level >= 2,
|
|
990
|
+
has16m: level >= 3
|
|
469
991
|
};
|
|
470
|
-
};
|
|
471
|
-
var createBuilder = (self, _styler, _isEmpty) => {
|
|
472
|
-
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
473
|
-
Object.setPrototypeOf(builder, proto);
|
|
474
|
-
builder[GENERATOR] = self;
|
|
475
|
-
builder[STYLER] = _styler;
|
|
476
|
-
builder[IS_EMPTY] = _isEmpty;
|
|
477
|
-
return builder;
|
|
478
|
-
};
|
|
479
|
-
var applyStyle = (self, string) => {
|
|
480
|
-
if (self.level <= 0 || !string) {
|
|
481
|
-
return self[IS_EMPTY] ? "" : string;
|
|
482
|
-
}
|
|
483
|
-
let styler = self[STYLER];
|
|
484
|
-
if (styler === void 0) {
|
|
485
|
-
return string;
|
|
486
|
-
}
|
|
487
|
-
const { openAll, closeAll } = styler;
|
|
488
|
-
if (string.includes("\x1B")) {
|
|
489
|
-
while (styler !== void 0) {
|
|
490
|
-
string = stringReplaceAll(string, styler.close, styler.open);
|
|
491
|
-
styler = styler.parent;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
const lfIndex = string.indexOf("\n");
|
|
495
|
-
if (lfIndex !== -1) {
|
|
496
|
-
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
497
|
-
}
|
|
498
|
-
return openAll + string + closeAll;
|
|
499
|
-
};
|
|
500
|
-
Object.defineProperties(createChalk.prototype, styles2);
|
|
501
|
-
var chalk = createChalk();
|
|
502
|
-
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
503
|
-
var source_default = chalk;
|
|
504
|
-
|
|
505
|
-
// src/index.ts
|
|
506
|
-
import { Command as Command6 } from "commander";
|
|
507
|
-
import "dotenv/config";
|
|
508
|
-
import { spawn } from "child_process";
|
|
509
|
-
import { readFileSync as readFileSync2 } from "fs";
|
|
510
|
-
import { access, mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
|
|
511
|
-
import { createRequire as createRequire2 } from "module";
|
|
512
|
-
import path8 from "path";
|
|
513
|
-
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
514
|
-
|
|
515
|
-
// ../../node_modules/.pnpm/open@11.0.0/node_modules/open/index.js
|
|
516
|
-
import process9 from "process";
|
|
517
|
-
import path2 from "path";
|
|
518
|
-
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
519
|
-
import childProcess3 from "child_process";
|
|
520
|
-
import fs6, { constants as fsConstants3 } from "fs/promises";
|
|
521
|
-
|
|
522
|
-
// ../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/index.js
|
|
523
|
-
import { promisify as promisify2 } from "util";
|
|
524
|
-
import childProcess2 from "child_process";
|
|
525
|
-
import fs5, { constants as fsConstants2 } from "fs/promises";
|
|
526
|
-
|
|
527
|
-
// ../../node_modules/.pnpm/is-wsl@3.1.0/node_modules/is-wsl/index.js
|
|
528
|
-
import process3 from "process";
|
|
529
|
-
import os2 from "os";
|
|
530
|
-
import fs3 from "fs";
|
|
531
|
-
|
|
532
|
-
// ../../node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.js
|
|
533
|
-
import fs2 from "fs";
|
|
534
|
-
|
|
535
|
-
// ../../node_modules/.pnpm/is-docker@3.0.0/node_modules/is-docker/index.js
|
|
536
|
-
import fs from "fs";
|
|
537
|
-
var isDockerCached;
|
|
538
|
-
function hasDockerEnv() {
|
|
539
|
-
try {
|
|
540
|
-
fs.statSync("/.dockerenv");
|
|
541
|
-
return true;
|
|
542
|
-
} catch {
|
|
543
|
-
return false;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
function hasDockerCGroup() {
|
|
547
|
-
try {
|
|
548
|
-
return fs.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
549
|
-
} catch {
|
|
550
|
-
return false;
|
|
551
|
-
}
|
|
552
992
|
}
|
|
553
|
-
function
|
|
554
|
-
|
|
555
|
-
|
|
993
|
+
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
994
|
+
const noFlagForceColor = envForceColor();
|
|
995
|
+
if (noFlagForceColor !== void 0) {
|
|
996
|
+
flagForceColor = noFlagForceColor;
|
|
556
997
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
// ../../node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.js
|
|
561
|
-
var cachedResult;
|
|
562
|
-
var hasContainerEnv = () => {
|
|
563
|
-
try {
|
|
564
|
-
fs2.statSync("/run/.containerenv");
|
|
565
|
-
return true;
|
|
566
|
-
} catch {
|
|
567
|
-
return false;
|
|
998
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
999
|
+
if (forceColor === 0) {
|
|
1000
|
+
return 0;
|
|
568
1001
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
1002
|
+
if (sniffFlags) {
|
|
1003
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
1004
|
+
return 3;
|
|
1005
|
+
}
|
|
1006
|
+
if (hasFlag("color=256")) {
|
|
1007
|
+
return 2;
|
|
1008
|
+
}
|
|
573
1009
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
// ../../node_modules/.pnpm/is-wsl@3.1.0/node_modules/is-wsl/index.js
|
|
578
|
-
var isWsl = () => {
|
|
579
|
-
if (process3.platform !== "linux") {
|
|
580
|
-
return false;
|
|
1010
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
1011
|
+
return 1;
|
|
581
1012
|
}
|
|
582
|
-
if (
|
|
583
|
-
|
|
584
|
-
return false;
|
|
585
|
-
}
|
|
586
|
-
return true;
|
|
1013
|
+
if (haveStream && !streamIsTTY && forceColor === void 0) {
|
|
1014
|
+
return 0;
|
|
587
1015
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
return false;
|
|
1016
|
+
const min = forceColor || 0;
|
|
1017
|
+
if (env.TERM === "dumb") {
|
|
1018
|
+
return min;
|
|
592
1019
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
import process4 from "process";
|
|
598
|
-
import { Buffer } from "buffer";
|
|
599
|
-
import { promisify } from "util";
|
|
600
|
-
import childProcess from "child_process";
|
|
601
|
-
import fs4, { constants as fsConstants } from "fs/promises";
|
|
602
|
-
var execFile = promisify(childProcess.execFile);
|
|
603
|
-
var powerShellPath = () => `${process4.env.SYSTEMROOT || process4.env.windir || String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`;
|
|
604
|
-
var executePowerShell = async (command, options = {}) => {
|
|
605
|
-
const {
|
|
606
|
-
powerShellPath: psPath,
|
|
607
|
-
...execFileOptions
|
|
608
|
-
} = options;
|
|
609
|
-
const encodedCommand = executePowerShell.encodeCommand(command);
|
|
610
|
-
return execFile(
|
|
611
|
-
psPath ?? powerShellPath(),
|
|
612
|
-
[
|
|
613
|
-
...executePowerShell.argumentsPrefix,
|
|
614
|
-
encodedCommand
|
|
615
|
-
],
|
|
616
|
-
{
|
|
617
|
-
encoding: "utf8",
|
|
618
|
-
...execFileOptions
|
|
619
|
-
}
|
|
620
|
-
);
|
|
621
|
-
};
|
|
622
|
-
executePowerShell.argumentsPrefix = [
|
|
623
|
-
"-NoProfile",
|
|
624
|
-
"-NonInteractive",
|
|
625
|
-
"-ExecutionPolicy",
|
|
626
|
-
"Bypass",
|
|
627
|
-
"-EncodedCommand"
|
|
628
|
-
];
|
|
629
|
-
executePowerShell.encodeCommand = (command) => Buffer.from(command, "utf16le").toString("base64");
|
|
630
|
-
executePowerShell.escapeArgument = (value) => `'${String(value).replaceAll("'", "''")}'`;
|
|
631
|
-
|
|
632
|
-
// ../../node_modules/.pnpm/wsl-utils@0.3.1/node_modules/wsl-utils/utilities.js
|
|
633
|
-
function parseMountPointFromConfig(content) {
|
|
634
|
-
for (const line of content.split("\n")) {
|
|
635
|
-
if (/^\s*#/.test(line)) {
|
|
636
|
-
continue;
|
|
637
|
-
}
|
|
638
|
-
const match = /^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(line);
|
|
639
|
-
if (!match) {
|
|
640
|
-
continue;
|
|
1020
|
+
if (process2.platform === "win32") {
|
|
1021
|
+
const osRelease = os.release().split(".");
|
|
1022
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
1023
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
641
1024
|
}
|
|
642
|
-
return
|
|
1025
|
+
return 1;
|
|
643
1026
|
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
var execFile2 = promisify2(childProcess2.execFile);
|
|
648
|
-
var wslDrivesMountPoint = /* @__PURE__ */ (() => {
|
|
649
|
-
const defaultMountPoint = "/mnt/";
|
|
650
|
-
let mountPoint;
|
|
651
|
-
return async function() {
|
|
652
|
-
if (mountPoint) {
|
|
653
|
-
return mountPoint;
|
|
654
|
-
}
|
|
655
|
-
const configFilePath = "/etc/wsl.conf";
|
|
656
|
-
let isConfigFileExists = false;
|
|
657
|
-
try {
|
|
658
|
-
await fs5.access(configFilePath, fsConstants2.F_OK);
|
|
659
|
-
isConfigFileExists = true;
|
|
660
|
-
} catch {
|
|
661
|
-
}
|
|
662
|
-
if (!isConfigFileExists) {
|
|
663
|
-
return defaultMountPoint;
|
|
664
|
-
}
|
|
665
|
-
const configContent = await fs5.readFile(configFilePath, { encoding: "utf8" });
|
|
666
|
-
const parsedMountPoint = parseMountPointFromConfig(configContent);
|
|
667
|
-
if (parsedMountPoint === void 0) {
|
|
668
|
-
return defaultMountPoint;
|
|
1027
|
+
if ("CI" in env) {
|
|
1028
|
+
if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) {
|
|
1029
|
+
return 3;
|
|
669
1030
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
return mountPoint;
|
|
673
|
-
};
|
|
674
|
-
})();
|
|
675
|
-
var powerShellPathFromWsl = async () => {
|
|
676
|
-
const mountPoint = await wslDrivesMountPoint();
|
|
677
|
-
return `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`;
|
|
678
|
-
};
|
|
679
|
-
var powerShellPath2 = is_wsl_default ? powerShellPathFromWsl : powerShellPath;
|
|
680
|
-
var canAccessPowerShellPromise;
|
|
681
|
-
var canAccessPowerShell = async () => {
|
|
682
|
-
canAccessPowerShellPromise ??= (async () => {
|
|
683
|
-
try {
|
|
684
|
-
const psPath = await powerShellPath2();
|
|
685
|
-
await fs5.access(psPath, fsConstants2.X_OK);
|
|
686
|
-
return true;
|
|
687
|
-
} catch {
|
|
688
|
-
return false;
|
|
1031
|
+
if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
1032
|
+
return 1;
|
|
689
1033
|
}
|
|
690
|
-
|
|
691
|
-
return canAccessPowerShellPromise;
|
|
692
|
-
};
|
|
693
|
-
var wslDefaultBrowser = async () => {
|
|
694
|
-
const psPath = await powerShellPath2();
|
|
695
|
-
const command = String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`;
|
|
696
|
-
const { stdout } = await executePowerShell(command, { powerShellPath: psPath });
|
|
697
|
-
return stdout.trim();
|
|
698
|
-
};
|
|
699
|
-
var convertWslPathToWindows = async (path9) => {
|
|
700
|
-
if (/^[a-z]+:\/\//i.test(path9)) {
|
|
701
|
-
return path9;
|
|
1034
|
+
return min;
|
|
702
1035
|
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
return stdout.trim();
|
|
706
|
-
} catch {
|
|
707
|
-
return path9;
|
|
1036
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
1037
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
708
1038
|
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
1039
|
+
if (env.COLORTERM === "truecolor") {
|
|
1040
|
+
return 3;
|
|
1041
|
+
}
|
|
1042
|
+
if (env.TERM === "xterm-kitty") {
|
|
1043
|
+
return 3;
|
|
1044
|
+
}
|
|
1045
|
+
if (env.TERM === "xterm-ghostty") {
|
|
1046
|
+
return 3;
|
|
1047
|
+
}
|
|
1048
|
+
if (env.TERM === "wezterm") {
|
|
1049
|
+
return 3;
|
|
1050
|
+
}
|
|
1051
|
+
if ("TERM_PROGRAM" in env) {
|
|
1052
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
1053
|
+
switch (env.TERM_PROGRAM) {
|
|
1054
|
+
case "iTerm.app": {
|
|
1055
|
+
return version >= 3 ? 3 : 2;
|
|
1056
|
+
}
|
|
1057
|
+
case "Apple_Terminal": {
|
|
1058
|
+
return 2;
|
|
1059
|
+
}
|
|
724
1060
|
}
|
|
725
|
-
});
|
|
726
|
-
return object;
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
// ../../node_modules/.pnpm/default-browser@5.5.0/node_modules/default-browser/index.js
|
|
730
|
-
import { promisify as promisify6 } from "util";
|
|
731
|
-
import process7 from "process";
|
|
732
|
-
import { execFile as execFile6 } from "child_process";
|
|
733
|
-
|
|
734
|
-
// ../../node_modules/.pnpm/default-browser-id@5.0.1/node_modules/default-browser-id/index.js
|
|
735
|
-
import { promisify as promisify3 } from "util";
|
|
736
|
-
import process5 from "process";
|
|
737
|
-
import { execFile as execFile3 } from "child_process";
|
|
738
|
-
var execFileAsync = promisify3(execFile3);
|
|
739
|
-
async function defaultBrowserId() {
|
|
740
|
-
if (process5.platform !== "darwin") {
|
|
741
|
-
throw new Error("macOS only");
|
|
742
1061
|
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
const browserId = match?.groups.id ?? "com.apple.Safari";
|
|
746
|
-
if (browserId === "com.apple.safari") {
|
|
747
|
-
return "com.apple.Safari";
|
|
1062
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
1063
|
+
return 2;
|
|
748
1064
|
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
// ../../node_modules/.pnpm/run-applescript@7.1.0/node_modules/run-applescript/index.js
|
|
753
|
-
import process6 from "process";
|
|
754
|
-
import { promisify as promisify4 } from "util";
|
|
755
|
-
import { execFile as execFile4, execFileSync } from "child_process";
|
|
756
|
-
var execFileAsync2 = promisify4(execFile4);
|
|
757
|
-
async function runAppleScript(script, { humanReadableOutput = true, signal } = {}) {
|
|
758
|
-
if (process6.platform !== "darwin") {
|
|
759
|
-
throw new Error("macOS only");
|
|
1065
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
1066
|
+
return 1;
|
|
760
1067
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
if (signal) {
|
|
764
|
-
execOptions.signal = signal;
|
|
1068
|
+
if ("COLORTERM" in env) {
|
|
1069
|
+
return 1;
|
|
765
1070
|
}
|
|
766
|
-
|
|
767
|
-
return stdout.trim();
|
|
1071
|
+
return min;
|
|
768
1072
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
1073
|
+
function createSupportsColor(stream, options = {}) {
|
|
1074
|
+
const level = _supportsColor(stream, {
|
|
1075
|
+
streamIsTTY: stream && stream.isTTY,
|
|
1076
|
+
...options
|
|
1077
|
+
});
|
|
1078
|
+
return translateLevel(level);
|
|
774
1079
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
import { execFile as execFile5 } from "child_process";
|
|
779
|
-
var execFileAsync3 = promisify5(execFile5);
|
|
780
|
-
var windowsBrowserProgIds = {
|
|
781
|
-
MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" },
|
|
782
|
-
// The missing `L` is correct.
|
|
783
|
-
MSEdgeBHTML: { name: "Edge Beta", id: "com.microsoft.edge.beta" },
|
|
784
|
-
MSEdgeDHTML: { name: "Edge Dev", id: "com.microsoft.edge.dev" },
|
|
785
|
-
AppXq0fevzme2pys62n3e0fbqa7peapykr8v: { name: "Edge", id: "com.microsoft.edge.old" },
|
|
786
|
-
ChromeHTML: { name: "Chrome", id: "com.google.chrome" },
|
|
787
|
-
ChromeBHTML: { name: "Chrome Beta", id: "com.google.chrome.beta" },
|
|
788
|
-
ChromeDHTML: { name: "Chrome Dev", id: "com.google.chrome.dev" },
|
|
789
|
-
ChromiumHTM: { name: "Chromium", id: "org.chromium.Chromium" },
|
|
790
|
-
BraveHTML: { name: "Brave", id: "com.brave.Browser" },
|
|
791
|
-
BraveBHTML: { name: "Brave Beta", id: "com.brave.Browser.beta" },
|
|
792
|
-
BraveDHTML: { name: "Brave Dev", id: "com.brave.Browser.dev" },
|
|
793
|
-
BraveSSHTM: { name: "Brave Nightly", id: "com.brave.Browser.nightly" },
|
|
794
|
-
FirefoxURL: { name: "Firefox", id: "org.mozilla.firefox" },
|
|
795
|
-
OperaStable: { name: "Opera", id: "com.operasoftware.Opera" },
|
|
796
|
-
VivaldiHTM: { name: "Vivaldi", id: "com.vivaldi.Vivaldi" },
|
|
797
|
-
"IE.HTTP": { name: "Internet Explorer", id: "com.microsoft.ie" }
|
|
798
|
-
};
|
|
799
|
-
var _windowsBrowserProgIdMap = new Map(Object.entries(windowsBrowserProgIds));
|
|
800
|
-
var UnknownBrowserError = class extends Error {
|
|
1080
|
+
var supportsColor = {
|
|
1081
|
+
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
1082
|
+
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
|
801
1083
|
};
|
|
802
|
-
|
|
803
|
-
const { stdout } = await _execFileAsync("reg", [
|
|
804
|
-
"QUERY",
|
|
805
|
-
" HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice",
|
|
806
|
-
"/v",
|
|
807
|
-
"ProgId"
|
|
808
|
-
]);
|
|
809
|
-
const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
|
|
810
|
-
if (!match) {
|
|
811
|
-
throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
|
|
812
|
-
}
|
|
813
|
-
const { id } = match.groups;
|
|
814
|
-
const dotIndex = id.lastIndexOf(".");
|
|
815
|
-
const hyphenIndex = id.lastIndexOf("-");
|
|
816
|
-
const baseIdByDot = dotIndex === -1 ? void 0 : id.slice(0, dotIndex);
|
|
817
|
-
const baseIdByHyphen = hyphenIndex === -1 ? void 0 : id.slice(0, hyphenIndex);
|
|
818
|
-
return windowsBrowserProgIds[id] ?? windowsBrowserProgIds[baseIdByDot] ?? windowsBrowserProgIds[baseIdByHyphen] ?? { name: id, id };
|
|
819
|
-
}
|
|
1084
|
+
var supports_color_default = supportsColor;
|
|
820
1085
|
|
|
821
|
-
// ../../node_modules/.pnpm/
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
if (
|
|
826
|
-
|
|
827
|
-
const name = await bundleName(id);
|
|
828
|
-
return { name, id };
|
|
829
|
-
}
|
|
830
|
-
if (process7.platform === "linux") {
|
|
831
|
-
const { stdout } = await execFileAsync4("xdg-mime", ["query", "default", "x-scheme-handler/http"]);
|
|
832
|
-
const id = stdout.trim();
|
|
833
|
-
const name = titleize(id.replace(/.desktop$/, "").replace("-", " "));
|
|
834
|
-
return { name, id };
|
|
835
|
-
}
|
|
836
|
-
if (process7.platform === "win32") {
|
|
837
|
-
return defaultBrowser();
|
|
1086
|
+
// ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js
|
|
1087
|
+
init_esm_shims();
|
|
1088
|
+
function stringReplaceAll(string, substring, replacer) {
|
|
1089
|
+
let index = string.indexOf(substring);
|
|
1090
|
+
if (index === -1) {
|
|
1091
|
+
return string;
|
|
838
1092
|
}
|
|
839
|
-
|
|
1093
|
+
const substringLength = substring.length;
|
|
1094
|
+
let endIndex = 0;
|
|
1095
|
+
let returnValue = "";
|
|
1096
|
+
do {
|
|
1097
|
+
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
1098
|
+
endIndex = index + substringLength;
|
|
1099
|
+
index = string.indexOf(substring, endIndex);
|
|
1100
|
+
} while (index !== -1);
|
|
1101
|
+
returnValue += string.slice(endIndex);
|
|
1102
|
+
return returnValue;
|
|
1103
|
+
}
|
|
1104
|
+
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
1105
|
+
let endIndex = 0;
|
|
1106
|
+
let returnValue = "";
|
|
1107
|
+
do {
|
|
1108
|
+
const gotCR = string[index - 1] === "\r";
|
|
1109
|
+
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
|
|
1110
|
+
endIndex = index + 1;
|
|
1111
|
+
index = string.indexOf("\n", endIndex);
|
|
1112
|
+
} while (index !== -1);
|
|
1113
|
+
returnValue += string.slice(endIndex);
|
|
1114
|
+
return returnValue;
|
|
840
1115
|
}
|
|
841
1116
|
|
|
842
|
-
// ../../node_modules/.pnpm/
|
|
843
|
-
|
|
844
|
-
var
|
|
845
|
-
var
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
for (const app of apps2) {
|
|
858
|
-
try {
|
|
859
|
-
return await opener(app);
|
|
860
|
-
} catch (error) {
|
|
861
|
-
errors.push(error);
|
|
862
|
-
}
|
|
1117
|
+
// ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
|
|
1118
|
+
var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
|
|
1119
|
+
var GENERATOR = /* @__PURE__ */ Symbol("GENERATOR");
|
|
1120
|
+
var STYLER = /* @__PURE__ */ Symbol("STYLER");
|
|
1121
|
+
var IS_EMPTY = /* @__PURE__ */ Symbol("IS_EMPTY");
|
|
1122
|
+
var levelMapping = [
|
|
1123
|
+
"ansi",
|
|
1124
|
+
"ansi",
|
|
1125
|
+
"ansi256",
|
|
1126
|
+
"ansi16m"
|
|
1127
|
+
];
|
|
1128
|
+
var styles2 = /* @__PURE__ */ Object.create(null);
|
|
1129
|
+
var applyOptions = (object, options = {}) => {
|
|
1130
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
1131
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
863
1132
|
}
|
|
864
|
-
|
|
1133
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
1134
|
+
object.level = options.level === void 0 ? colorLevel : options.level;
|
|
1135
|
+
};
|
|
1136
|
+
var chalkFactory = (options) => {
|
|
1137
|
+
const chalk2 = (...strings) => strings.join(" ");
|
|
1138
|
+
applyOptions(chalk2, options);
|
|
1139
|
+
Object.setPrototypeOf(chalk2, createChalk.prototype);
|
|
1140
|
+
return chalk2;
|
|
865
1141
|
};
|
|
866
|
-
|
|
867
|
-
options
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
1142
|
+
function createChalk(options) {
|
|
1143
|
+
return chalkFactory(options);
|
|
1144
|
+
}
|
|
1145
|
+
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
1146
|
+
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
|
|
1147
|
+
styles2[styleName] = {
|
|
1148
|
+
get() {
|
|
1149
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
1150
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
1151
|
+
return builder;
|
|
1152
|
+
}
|
|
873
1153
|
};
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
[fallbackAttemptSymbol]: true
|
|
881
|
-
}));
|
|
882
|
-
}
|
|
883
|
-
let { name: app, arguments: appArguments = [] } = options.app ?? {};
|
|
884
|
-
appArguments = [...appArguments];
|
|
885
|
-
if (Array.isArray(app)) {
|
|
886
|
-
return tryEachApp(app, (appName) => baseOpen({
|
|
887
|
-
...options,
|
|
888
|
-
app: {
|
|
889
|
-
name: appName,
|
|
890
|
-
arguments: appArguments
|
|
891
|
-
},
|
|
892
|
-
[fallbackAttemptSymbol]: true
|
|
893
|
-
}));
|
|
1154
|
+
}
|
|
1155
|
+
styles2.visible = {
|
|
1156
|
+
get() {
|
|
1157
|
+
const builder = createBuilder(this, this[STYLER], true);
|
|
1158
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
1159
|
+
return builder;
|
|
894
1160
|
}
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
"org.mozilla.firefox": "firefox",
|
|
901
|
-
"firefox.desktop": "firefox",
|
|
902
|
-
"com.microsoft.msedge": "edge",
|
|
903
|
-
"com.microsoft.edge": "edge",
|
|
904
|
-
"com.microsoft.edgemac": "edge",
|
|
905
|
-
"microsoft-edge.desktop": "edge",
|
|
906
|
-
"com.apple.safari": "safari"
|
|
907
|
-
};
|
|
908
|
-
const flags = {
|
|
909
|
-
chrome: "--incognito",
|
|
910
|
-
brave: "--incognito",
|
|
911
|
-
firefox: "--private-window",
|
|
912
|
-
edge: "--inPrivate"
|
|
913
|
-
// Safari doesn't support private mode via command line
|
|
914
|
-
};
|
|
915
|
-
let browser;
|
|
916
|
-
if (is_wsl_default) {
|
|
917
|
-
const progId = await wslDefaultBrowser();
|
|
918
|
-
const browserInfo = _windowsBrowserProgIdMap.get(progId);
|
|
919
|
-
browser = browserInfo ?? {};
|
|
920
|
-
} else {
|
|
921
|
-
browser = await defaultBrowser2();
|
|
1161
|
+
};
|
|
1162
|
+
var getModelAnsi = (model, level, type, ...arguments_) => {
|
|
1163
|
+
if (model === "rgb") {
|
|
1164
|
+
if (level === "ansi16m") {
|
|
1165
|
+
return ansi_styles_default[type].ansi16m(...arguments_);
|
|
922
1166
|
}
|
|
923
|
-
if (
|
|
924
|
-
|
|
925
|
-
if (app === "browserPrivate") {
|
|
926
|
-
if (browserName === "safari") {
|
|
927
|
-
throw new Error("Safari doesn't support opening in private mode via command line");
|
|
928
|
-
}
|
|
929
|
-
appArguments.push(flags[browserName]);
|
|
930
|
-
}
|
|
931
|
-
return baseOpen({
|
|
932
|
-
...options,
|
|
933
|
-
app: {
|
|
934
|
-
name: apps[browserName],
|
|
935
|
-
arguments: appArguments
|
|
936
|
-
}
|
|
937
|
-
});
|
|
1167
|
+
if (level === "ansi256") {
|
|
1168
|
+
return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
|
|
938
1169
|
}
|
|
939
|
-
|
|
1170
|
+
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
|
|
940
1171
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
const childProcessOptions = {};
|
|
944
|
-
let shouldUseWindowsInWsl = false;
|
|
945
|
-
if (is_wsl_default && !isInsideContainer() && !is_in_ssh_default && !app) {
|
|
946
|
-
shouldUseWindowsInWsl = await canAccessPowerShell();
|
|
1172
|
+
if (model === "hex") {
|
|
1173
|
+
return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
|
|
947
1174
|
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
if (app) {
|
|
960
|
-
cliArguments.push("-a", app);
|
|
961
|
-
}
|
|
962
|
-
} else if (platform === "win32" || shouldUseWindowsInWsl) {
|
|
963
|
-
command = await powerShellPath2();
|
|
964
|
-
cliArguments.push(...executePowerShell.argumentsPrefix);
|
|
965
|
-
if (!is_wsl_default) {
|
|
966
|
-
childProcessOptions.windowsVerbatimArguments = true;
|
|
967
|
-
}
|
|
968
|
-
if (is_wsl_default && options.target) {
|
|
969
|
-
options.target = await convertWslPathToWindows(options.target);
|
|
970
|
-
}
|
|
971
|
-
const encodedArguments = ["$ProgressPreference = 'SilentlyContinue';", "Start"];
|
|
972
|
-
if (options.wait) {
|
|
973
|
-
encodedArguments.push("-Wait");
|
|
974
|
-
}
|
|
975
|
-
if (app) {
|
|
976
|
-
encodedArguments.push(executePowerShell.escapeArgument(app));
|
|
977
|
-
if (options.target) {
|
|
978
|
-
appArguments.push(options.target);
|
|
979
|
-
}
|
|
980
|
-
} else if (options.target) {
|
|
981
|
-
encodedArguments.push(executePowerShell.escapeArgument(options.target));
|
|
982
|
-
}
|
|
983
|
-
if (appArguments.length > 0) {
|
|
984
|
-
appArguments = appArguments.map((argument) => executePowerShell.escapeArgument(argument));
|
|
985
|
-
encodedArguments.push("-ArgumentList", appArguments.join(","));
|
|
986
|
-
}
|
|
987
|
-
options.target = executePowerShell.encodeCommand(encodedArguments.join(" "));
|
|
988
|
-
if (!options.wait) {
|
|
989
|
-
childProcessOptions.stdio = "ignore";
|
|
990
|
-
}
|
|
991
|
-
} else {
|
|
992
|
-
if (app) {
|
|
993
|
-
command = app;
|
|
994
|
-
} else {
|
|
995
|
-
const isBundled = !__dirname2 || __dirname2 === "/";
|
|
996
|
-
let exeLocalXdgOpen = false;
|
|
997
|
-
try {
|
|
998
|
-
await fs6.access(localXdgOpenPath, fsConstants3.X_OK);
|
|
999
|
-
exeLocalXdgOpen = true;
|
|
1000
|
-
} catch {
|
|
1001
|
-
}
|
|
1002
|
-
const useSystemXdgOpen = process9.versions.electron ?? (platform === "android" || isBundled || !exeLocalXdgOpen);
|
|
1003
|
-
command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath;
|
|
1175
|
+
return ansi_styles_default[type][model](...arguments_);
|
|
1176
|
+
};
|
|
1177
|
+
var usedModels = ["rgb", "hex", "ansi256"];
|
|
1178
|
+
for (const model of usedModels) {
|
|
1179
|
+
styles2[model] = {
|
|
1180
|
+
get() {
|
|
1181
|
+
const { level } = this;
|
|
1182
|
+
return function(...arguments_) {
|
|
1183
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
1184
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
1185
|
+
};
|
|
1004
1186
|
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1187
|
+
};
|
|
1188
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
1189
|
+
styles2[bgModel] = {
|
|
1190
|
+
get() {
|
|
1191
|
+
const { level } = this;
|
|
1192
|
+
return function(...arguments_) {
|
|
1193
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
|
1194
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
1195
|
+
};
|
|
1007
1196
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
var proto = Object.defineProperties(() => {
|
|
1200
|
+
}, {
|
|
1201
|
+
...styles2,
|
|
1202
|
+
level: {
|
|
1203
|
+
enumerable: true,
|
|
1204
|
+
get() {
|
|
1205
|
+
return this[GENERATOR].level;
|
|
1206
|
+
},
|
|
1207
|
+
set(level) {
|
|
1208
|
+
this[GENERATOR].level = level;
|
|
1011
1209
|
}
|
|
1012
1210
|
}
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
subprocess.once("close", (exitCode) => {
|
|
1024
|
-
if (!options.allowNonzeroExitCode && exitCode !== 0) {
|
|
1025
|
-
reject(new Error(`Exited with code ${exitCode}`));
|
|
1026
|
-
return;
|
|
1027
|
-
}
|
|
1028
|
-
resolve2(subprocess);
|
|
1029
|
-
});
|
|
1030
|
-
});
|
|
1031
|
-
}
|
|
1032
|
-
if (isFallbackAttempt) {
|
|
1033
|
-
return new Promise((resolve2, reject) => {
|
|
1034
|
-
subprocess.once("error", reject);
|
|
1035
|
-
subprocess.once("spawn", () => {
|
|
1036
|
-
subprocess.once("close", (exitCode) => {
|
|
1037
|
-
subprocess.off("error", reject);
|
|
1038
|
-
if (exitCode !== 0) {
|
|
1039
|
-
reject(new Error(`Exited with code ${exitCode}`));
|
|
1040
|
-
return;
|
|
1041
|
-
}
|
|
1042
|
-
subprocess.unref();
|
|
1043
|
-
resolve2(subprocess);
|
|
1044
|
-
});
|
|
1045
|
-
});
|
|
1046
|
-
});
|
|
1211
|
+
});
|
|
1212
|
+
var createStyler = (open2, close, parent) => {
|
|
1213
|
+
let openAll;
|
|
1214
|
+
let closeAll;
|
|
1215
|
+
if (parent === void 0) {
|
|
1216
|
+
openAll = open2;
|
|
1217
|
+
closeAll = close;
|
|
1218
|
+
} else {
|
|
1219
|
+
openAll = parent.openAll + open2;
|
|
1220
|
+
closeAll = close + parent.closeAll;
|
|
1047
1221
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
});
|
|
1222
|
+
return {
|
|
1223
|
+
open: open2,
|
|
1224
|
+
close,
|
|
1225
|
+
openAll,
|
|
1226
|
+
closeAll,
|
|
1227
|
+
parent
|
|
1228
|
+
};
|
|
1056
1229
|
};
|
|
1057
|
-
var
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
});
|
|
1230
|
+
var createBuilder = (self, _styler, _isEmpty) => {
|
|
1231
|
+
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
1232
|
+
Object.setPrototypeOf(builder, proto);
|
|
1233
|
+
builder[GENERATOR] = self;
|
|
1234
|
+
builder[STYLER] = _styler;
|
|
1235
|
+
builder[IS_EMPTY] = _isEmpty;
|
|
1236
|
+
return builder;
|
|
1065
1237
|
};
|
|
1066
|
-
|
|
1067
|
-
if (
|
|
1068
|
-
return
|
|
1238
|
+
var applyStyle = (self, string) => {
|
|
1239
|
+
if (self.level <= 0 || !string) {
|
|
1240
|
+
return self[IS_EMPTY] ? "" : string;
|
|
1069
1241
|
}
|
|
1070
|
-
|
|
1071
|
-
if (
|
|
1072
|
-
|
|
1242
|
+
let styler = self[STYLER];
|
|
1243
|
+
if (styler === void 0) {
|
|
1244
|
+
return string;
|
|
1073
1245
|
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1246
|
+
const { openAll, closeAll } = styler;
|
|
1247
|
+
if (string.includes("\x1B")) {
|
|
1248
|
+
while (styler !== void 0) {
|
|
1249
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
1250
|
+
styler = styler.parent;
|
|
1251
|
+
}
|
|
1079
1252
|
}
|
|
1080
|
-
|
|
1081
|
-
|
|
1253
|
+
const lfIndex = string.indexOf("\n");
|
|
1254
|
+
if (lfIndex !== -1) {
|
|
1255
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
1082
1256
|
}
|
|
1083
|
-
return
|
|
1084
|
-
}
|
|
1085
|
-
var apps = {
|
|
1086
|
-
browser: "browser",
|
|
1087
|
-
browserPrivate: "browserPrivate"
|
|
1257
|
+
return openAll + string + closeAll;
|
|
1088
1258
|
};
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
linux: ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"]
|
|
1094
|
-
}, {
|
|
1095
|
-
wsl: {
|
|
1096
|
-
ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
|
|
1097
|
-
x64: ["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]
|
|
1098
|
-
}
|
|
1099
|
-
}));
|
|
1100
|
-
defineLazyProperty(apps, "brave", () => detectPlatformBinary({
|
|
1101
|
-
darwin: "brave browser",
|
|
1102
|
-
win32: "brave",
|
|
1103
|
-
linux: ["brave-browser", "brave"]
|
|
1104
|
-
}, {
|
|
1105
|
-
wsl: {
|
|
1106
|
-
ia32: "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe",
|
|
1107
|
-
x64: ["/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe", "/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"]
|
|
1108
|
-
}
|
|
1109
|
-
}));
|
|
1110
|
-
defineLazyProperty(apps, "firefox", () => detectPlatformBinary({
|
|
1111
|
-
darwin: "firefox",
|
|
1112
|
-
win32: String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,
|
|
1113
|
-
linux: "firefox"
|
|
1114
|
-
}, {
|
|
1115
|
-
wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
|
|
1116
|
-
}));
|
|
1117
|
-
defineLazyProperty(apps, "edge", () => detectPlatformBinary({
|
|
1118
|
-
darwin: "microsoft edge",
|
|
1119
|
-
win32: "msedge",
|
|
1120
|
-
linux: ["microsoft-edge", "microsoft-edge-dev"]
|
|
1121
|
-
}, {
|
|
1122
|
-
wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
|
|
1123
|
-
}));
|
|
1124
|
-
defineLazyProperty(apps, "safari", () => detectPlatformBinary({
|
|
1125
|
-
darwin: "Safari"
|
|
1126
|
-
}));
|
|
1127
|
-
var open_default = open;
|
|
1259
|
+
Object.defineProperties(createChalk.prototype, styles2);
|
|
1260
|
+
var chalk = createChalk();
|
|
1261
|
+
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
1262
|
+
var source_default = chalk;
|
|
1128
1263
|
|
|
1129
1264
|
// src/index.ts
|
|
1265
|
+
init_open();
|
|
1266
|
+
import { Command as Command6 } from "commander";
|
|
1267
|
+
import "dotenv/config";
|
|
1268
|
+
import { spawn } from "child_process";
|
|
1269
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
1270
|
+
import { access, mkdir as mkdir3, readFile as readFile3, writeFile as writeFile3 } from "fs/promises";
|
|
1271
|
+
import { createRequire as createRequire2 } from "module";
|
|
1272
|
+
import path8 from "path";
|
|
1273
|
+
import { pathToFileURL as pathToFileURL2 } from "url";
|
|
1130
1274
|
import { viteSingleFile } from "vite-plugin-singlefile";
|
|
1131
1275
|
import { toJSONSchema } from "zod";
|
|
1132
1276
|
|
|
1277
|
+
// src/commands/auth.ts
|
|
1278
|
+
init_esm_shims();
|
|
1279
|
+
init_open();
|
|
1280
|
+
|
|
1281
|
+
// src/utils/api.ts
|
|
1282
|
+
init_esm_shims();
|
|
1283
|
+
|
|
1133
1284
|
// src/utils/config.ts
|
|
1285
|
+
init_esm_shims();
|
|
1134
1286
|
import { promises as fs7 } from "fs";
|
|
1135
1287
|
import os3 from "os";
|
|
1136
1288
|
import path3 from "path";
|
|
@@ -1320,8 +1472,8 @@ var McpUseAPI = class _McpUseAPI {
|
|
|
1320
1472
|
// ── Organization ID resolution ──────────────────────────────────
|
|
1321
1473
|
async resolveOrganizationId() {
|
|
1322
1474
|
if (this.orgId) return this.orgId;
|
|
1323
|
-
const
|
|
1324
|
-
const id =
|
|
1475
|
+
const auth2 = await this.testAuth();
|
|
1476
|
+
const id = auth2.default_org_id;
|
|
1325
1477
|
if (!id) {
|
|
1326
1478
|
throw new Error(
|
|
1327
1479
|
"No organization set. Run `mcp-use org switch` or use --org to specify one."
|
|
@@ -1509,6 +1661,7 @@ var McpUseAPI = class _McpUseAPI {
|
|
|
1509
1661
|
};
|
|
1510
1662
|
|
|
1511
1663
|
// src/utils/errors.ts
|
|
1664
|
+
init_esm_shims();
|
|
1512
1665
|
function handleCommandError(error, context) {
|
|
1513
1666
|
if (error instanceof ApiUnauthorizedError) {
|
|
1514
1667
|
console.error(
|
|
@@ -1855,52 +2008,113 @@ async function whoamiCommand() {
|
|
|
1855
2008
|
}
|
|
1856
2009
|
|
|
1857
2010
|
// src/commands/client.ts
|
|
2011
|
+
init_esm_shims();
|
|
1858
2012
|
import { Command } from "commander";
|
|
1859
2013
|
import { MCPClient } from "mcp-use/client";
|
|
1860
2014
|
import { getPackageVersion } from "mcp-use/server";
|
|
1861
|
-
import { createInterface } from "readline";
|
|
2015
|
+
import { createInterface as createInterface2 } from "readline";
|
|
1862
2016
|
|
|
1863
2017
|
// src/utils/format.ts
|
|
1864
|
-
|
|
2018
|
+
init_esm_shims();
|
|
2019
|
+
var ANSI_RE = /\x1b\[[0-9;]*m/g;
|
|
2020
|
+
var GUTTER = " ";
|
|
2021
|
+
var MIN_TRUNCATABLE_WIDTH = 8;
|
|
2022
|
+
var DEFAULT_MAX_WIDTH = 100;
|
|
2023
|
+
function stripAnsi(s) {
|
|
2024
|
+
return s.replace(ANSI_RE, "");
|
|
2025
|
+
}
|
|
2026
|
+
function visibleWidth(s) {
|
|
2027
|
+
return stripAnsi(s).length;
|
|
2028
|
+
}
|
|
2029
|
+
function padCell(s, width) {
|
|
2030
|
+
const w = visibleWidth(s);
|
|
2031
|
+
if (w >= width) return s;
|
|
2032
|
+
return s + " ".repeat(width - w);
|
|
2033
|
+
}
|
|
2034
|
+
function truncateCell(s, width) {
|
|
2035
|
+
if (width <= 0) return "";
|
|
2036
|
+
const plain = stripAnsi(s);
|
|
2037
|
+
if (plain.length <= width) return s;
|
|
2038
|
+
if (width === 1) return "\u2026";
|
|
2039
|
+
return plain.slice(0, width - 1) + "\u2026";
|
|
2040
|
+
}
|
|
2041
|
+
function formatTable(data, columns, options = {}) {
|
|
2042
|
+
const tsv = options.tsv ?? !process.stdout.isTTY;
|
|
2043
|
+
if (tsv) {
|
|
2044
|
+
return data.map(
|
|
2045
|
+
(row) => columns.map(
|
|
2046
|
+
(c) => stripAnsi(String(row[c.key] ?? "")).replace(/[\t\r\n]+/g, " ")
|
|
2047
|
+
).join(" ")
|
|
2048
|
+
).join("\n");
|
|
2049
|
+
}
|
|
1865
2050
|
if (data.length === 0) {
|
|
1866
2051
|
return source_default.gray("No items found");
|
|
1867
2052
|
}
|
|
1868
|
-
const
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
)
|
|
1872
|
-
|
|
1873
|
-
|
|
2053
|
+
const maxWidth = options.maxWidth ?? process.stdout.columns ?? DEFAULT_MAX_WIDTH;
|
|
2054
|
+
const natural = columns.map((col) => {
|
|
2055
|
+
const headerW = col.header.length;
|
|
2056
|
+
const dataW = data.reduce((m, row) => {
|
|
2057
|
+
return Math.max(m, visibleWidth(String(row[col.key] ?? "")));
|
|
2058
|
+
}, 0);
|
|
2059
|
+
return Math.max(headerW, dataW);
|
|
1874
2060
|
});
|
|
1875
|
-
const
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
2061
|
+
const widths = columns.map((c, i) => c.width ?? natural[i]);
|
|
2062
|
+
const overhead = GUTTER.length * (columns.length - 1);
|
|
2063
|
+
const totalWidth = () => widths.reduce((s, w) => s + w, 0) + overhead;
|
|
2064
|
+
if (totalWidth() > maxWidth) {
|
|
2065
|
+
const truncIdxs = columns.map((c, i) => c.truncate ? i : -1).filter((i) => i >= 0);
|
|
2066
|
+
if (truncIdxs.length > 0) {
|
|
2067
|
+
const fixedSum = columns.reduce(
|
|
2068
|
+
(s, c, i) => s + (c.truncate ? 0 : widths[i]),
|
|
2069
|
+
0
|
|
2070
|
+
);
|
|
2071
|
+
const remaining = Math.max(
|
|
2072
|
+
truncIdxs.length * MIN_TRUNCATABLE_WIDTH,
|
|
2073
|
+
maxWidth - fixedSum - overhead
|
|
2074
|
+
);
|
|
2075
|
+
const truncSum = truncIdxs.reduce((s, i) => s + widths[i], 0) || 1;
|
|
2076
|
+
let used = 0;
|
|
2077
|
+
truncIdxs.forEach((i, idx) => {
|
|
2078
|
+
if (idx === truncIdxs.length - 1) {
|
|
2079
|
+
widths[i] = Math.max(MIN_TRUNCATABLE_WIDTH, remaining - used);
|
|
2080
|
+
} else {
|
|
2081
|
+
const share = Math.max(
|
|
2082
|
+
MIN_TRUNCATABLE_WIDTH,
|
|
2083
|
+
Math.floor(widths[i] / truncSum * remaining)
|
|
2084
|
+
);
|
|
2085
|
+
widths[i] = share;
|
|
2086
|
+
used += share;
|
|
2087
|
+
}
|
|
2088
|
+
});
|
|
1886
2089
|
}
|
|
1887
|
-
|
|
1888
|
-
};
|
|
2090
|
+
}
|
|
1889
2091
|
const lines = [];
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
true
|
|
1895
|
-
)
|
|
1896
|
-
);
|
|
1897
|
-
lines.push(separator("\u2500"));
|
|
1898
|
-
data.forEach((row) => {
|
|
1899
|
-
lines.push(createRow(columns.map((c) => String(row[c.key] || ""))));
|
|
2092
|
+
const headerCells = columns.map((c, i) => {
|
|
2093
|
+
const text = c.header.toUpperCase();
|
|
2094
|
+
const cell = i === columns.length - 1 ? text : padCell(text, widths[i]);
|
|
2095
|
+
return source_default.bold(cell);
|
|
1900
2096
|
});
|
|
1901
|
-
lines.push(
|
|
2097
|
+
lines.push(headerCells.join(GUTTER).trimEnd());
|
|
2098
|
+
for (const row of data) {
|
|
2099
|
+
const cells = columns.map((c, i) => {
|
|
2100
|
+
let v = String(row[c.key] ?? "");
|
|
2101
|
+
if (visibleWidth(v) > widths[i]) {
|
|
2102
|
+
v = truncateCell(v, widths[i]);
|
|
2103
|
+
}
|
|
2104
|
+
return i === columns.length - 1 ? v : padCell(v, widths[i]);
|
|
2105
|
+
});
|
|
2106
|
+
lines.push(cells.join(GUTTER).trimEnd());
|
|
2107
|
+
}
|
|
1902
2108
|
return lines.join("\n");
|
|
1903
2109
|
}
|
|
2110
|
+
function isStdoutTty() {
|
|
2111
|
+
return Boolean(process.stdout.isTTY);
|
|
2112
|
+
}
|
|
2113
|
+
function formatToolMode(annotations) {
|
|
2114
|
+
if (annotations?.readOnlyHint === true) return source_default.green("read-only");
|
|
2115
|
+
if (annotations?.destructiveHint === true) return source_default.red("destructive");
|
|
2116
|
+
return source_default.yellow("write");
|
|
2117
|
+
}
|
|
1904
2118
|
function formatJson(data, pretty = true) {
|
|
1905
2119
|
if (pretty) {
|
|
1906
2120
|
return JSON.stringify(data, null, 2);
|
|
@@ -1909,20 +2123,26 @@ function formatJson(data, pretty = true) {
|
|
|
1909
2123
|
}
|
|
1910
2124
|
function formatToolCall(result) {
|
|
1911
2125
|
const lines = [];
|
|
1912
|
-
|
|
2126
|
+
const { isError, structuredContent } = result;
|
|
2127
|
+
const hasContent = !!result.content?.length;
|
|
2128
|
+
const hasStructured = structuredContent !== void 0 && structuredContent !== null;
|
|
2129
|
+
if (isError) {
|
|
1913
2130
|
lines.push(source_default.red("\u2717 Tool execution failed"));
|
|
1914
2131
|
lines.push("");
|
|
1915
2132
|
} else {
|
|
1916
2133
|
lines.push(source_default.green("\u2713 Tool executed successfully"));
|
|
1917
2134
|
lines.push("");
|
|
1918
2135
|
}
|
|
1919
|
-
if (
|
|
2136
|
+
if (hasContent) {
|
|
2137
|
+
if (isError) {
|
|
2138
|
+
lines.push(source_default.red.bold("Error details:"));
|
|
2139
|
+
}
|
|
1920
2140
|
result.content.forEach((item, index) => {
|
|
1921
2141
|
if (result.content.length > 1) {
|
|
1922
2142
|
lines.push(source_default.bold(`Content ${index + 1}:`));
|
|
1923
2143
|
}
|
|
1924
2144
|
if (item.type === "text") {
|
|
1925
|
-
lines.push(item.text);
|
|
2145
|
+
lines.push(isError ? source_default.red(item.text) : item.text);
|
|
1926
2146
|
} else if (item.type === "image") {
|
|
1927
2147
|
lines.push(source_default.cyan(`[Image: ${item.mimeType || "unknown type"}]`));
|
|
1928
2148
|
if (item.data) {
|
|
@@ -1944,6 +2164,16 @@ function formatToolCall(result) {
|
|
|
1944
2164
|
}
|
|
1945
2165
|
});
|
|
1946
2166
|
}
|
|
2167
|
+
if (hasStructured) {
|
|
2168
|
+
if (hasContent) lines.push("");
|
|
2169
|
+
lines.push(
|
|
2170
|
+
source_default.bold(isError ? "Structured error data:" : "Structured content:")
|
|
2171
|
+
);
|
|
2172
|
+
lines.push(formatJson(structuredContent));
|
|
2173
|
+
}
|
|
2174
|
+
if (isError && !hasContent && !hasStructured) {
|
|
2175
|
+
lines.push(source_default.gray("(no error details provided by server)"));
|
|
2176
|
+
}
|
|
1947
2177
|
return lines.join("\n");
|
|
1948
2178
|
}
|
|
1949
2179
|
function formatResourceContent(content) {
|
|
@@ -2089,14 +2319,218 @@ function formatPromptMessages(messages) {
|
|
|
2089
2319
|
}
|
|
2090
2320
|
}
|
|
2091
2321
|
}
|
|
2092
|
-
if (index < messages.length - 1) {
|
|
2093
|
-
lines.push("");
|
|
2322
|
+
if (index < messages.length - 1) {
|
|
2323
|
+
lines.push("");
|
|
2324
|
+
}
|
|
2325
|
+
});
|
|
2326
|
+
return lines.join("\n");
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
// src/utils/parse-args.ts
|
|
2330
|
+
init_esm_shims();
|
|
2331
|
+
function parseToolArgs(rawArgs, inputSchema) {
|
|
2332
|
+
if (!rawArgs || rawArgs.length === 0) return {};
|
|
2333
|
+
if (rawArgs.length === 1) {
|
|
2334
|
+
const trimmed = rawArgs[0].trim();
|
|
2335
|
+
if (trimmed.startsWith("{")) {
|
|
2336
|
+
try {
|
|
2337
|
+
const parsed = JSON.parse(trimmed);
|
|
2338
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
2339
|
+
throw new Error("expected a JSON object");
|
|
2340
|
+
}
|
|
2341
|
+
return parsed;
|
|
2342
|
+
} catch (err) {
|
|
2343
|
+
throw new Error(`Invalid JSON arguments: ${err.message}`);
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
const props = inputSchema?.properties ?? {};
|
|
2348
|
+
const result = {};
|
|
2349
|
+
for (const raw of rawArgs) {
|
|
2350
|
+
const token = raw.startsWith("--") ? raw.slice(2) : raw;
|
|
2351
|
+
const jsonIdx = token.indexOf(":=");
|
|
2352
|
+
const eqIdx = token.indexOf("=");
|
|
2353
|
+
let key;
|
|
2354
|
+
let rawValue;
|
|
2355
|
+
let forceJson = false;
|
|
2356
|
+
if (jsonIdx !== -1 && (eqIdx === -1 || jsonIdx < eqIdx)) {
|
|
2357
|
+
key = token.slice(0, jsonIdx);
|
|
2358
|
+
rawValue = token.slice(jsonIdx + 2);
|
|
2359
|
+
forceJson = true;
|
|
2360
|
+
} else if (eqIdx !== -1) {
|
|
2361
|
+
key = token.slice(0, eqIdx);
|
|
2362
|
+
rawValue = token.slice(eqIdx + 1);
|
|
2363
|
+
} else {
|
|
2364
|
+
throw new Error(
|
|
2365
|
+
`Invalid argument '${raw}'. Use key=value or key:=jsonvalue.`
|
|
2366
|
+
);
|
|
2367
|
+
}
|
|
2368
|
+
if (!key) {
|
|
2369
|
+
throw new Error(`Empty key in argument '${raw}'`);
|
|
2370
|
+
}
|
|
2371
|
+
result[key] = coerceArgValue(rawValue, props[key], forceJson, key);
|
|
2372
|
+
}
|
|
2373
|
+
return result;
|
|
2374
|
+
}
|
|
2375
|
+
function coerceArgValue(value, propSchema, forceJson, key) {
|
|
2376
|
+
if (forceJson) {
|
|
2377
|
+
try {
|
|
2378
|
+
return JSON.parse(value);
|
|
2379
|
+
} catch (err) {
|
|
2380
|
+
throw new Error(
|
|
2381
|
+
`Invalid JSON value for '${key}': ${err.message}`
|
|
2382
|
+
);
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
const types = Array.isArray(propSchema?.type) ? propSchema.type : propSchema?.type ? [propSchema.type] : [];
|
|
2386
|
+
if (types.includes("null") && (value === "null" || value === "")) {
|
|
2387
|
+
return null;
|
|
2388
|
+
}
|
|
2389
|
+
if (types.includes("integer")) {
|
|
2390
|
+
const n = Number(value);
|
|
2391
|
+
if (!Number.isFinite(n) || !Number.isInteger(n)) {
|
|
2392
|
+
throw new Error(`Expected integer for '${key}', got '${value}'`);
|
|
2393
|
+
}
|
|
2394
|
+
return n;
|
|
2395
|
+
}
|
|
2396
|
+
if (types.includes("number")) {
|
|
2397
|
+
const n = Number(value);
|
|
2398
|
+
if (!Number.isFinite(n)) {
|
|
2399
|
+
throw new Error(`Expected number for '${key}', got '${value}'`);
|
|
2400
|
+
}
|
|
2401
|
+
return n;
|
|
2402
|
+
}
|
|
2403
|
+
if (types.includes("boolean")) {
|
|
2404
|
+
if (value === "true" || value === "1") return true;
|
|
2405
|
+
if (value === "false" || value === "0") return false;
|
|
2406
|
+
throw new Error(
|
|
2407
|
+
`Expected boolean (true/false) for '${key}', got '${value}'`
|
|
2408
|
+
);
|
|
2409
|
+
}
|
|
2410
|
+
if (types.includes("array") || types.includes("object")) {
|
|
2411
|
+
try {
|
|
2412
|
+
return JSON.parse(value);
|
|
2413
|
+
} catch (err) {
|
|
2414
|
+
const wanted = types.includes("array") ? "array" : "object";
|
|
2415
|
+
throw new Error(
|
|
2416
|
+
`Expected JSON ${wanted} for '${key}'. Tip: use ${key}:=<json>. ${err.message}`
|
|
2417
|
+
);
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
return value;
|
|
2421
|
+
}
|
|
2422
|
+
function parsePromptArgs(rawArgs) {
|
|
2423
|
+
if (!rawArgs || rawArgs.length === 0) return {};
|
|
2424
|
+
if (rawArgs.length === 1) {
|
|
2425
|
+
const trimmed = rawArgs[0].trim();
|
|
2426
|
+
if (trimmed.startsWith("{")) {
|
|
2427
|
+
try {
|
|
2428
|
+
const parsed = JSON.parse(trimmed);
|
|
2429
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
2430
|
+
throw new Error("expected a JSON object");
|
|
2431
|
+
}
|
|
2432
|
+
const out = {};
|
|
2433
|
+
for (const [k, v] of Object.entries(parsed)) {
|
|
2434
|
+
out[k] = typeof v === "string" ? v : JSON.stringify(v);
|
|
2435
|
+
}
|
|
2436
|
+
return out;
|
|
2437
|
+
} catch (err) {
|
|
2438
|
+
throw new Error(`Invalid JSON arguments: ${err.message}`);
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
const result = {};
|
|
2443
|
+
for (const raw of rawArgs) {
|
|
2444
|
+
const token = raw.startsWith("--") ? raw.slice(2) : raw;
|
|
2445
|
+
const eqIdx = token.indexOf("=");
|
|
2446
|
+
if (eqIdx === -1) {
|
|
2447
|
+
throw new Error(`Invalid argument '${raw}'. Use key=value.`);
|
|
2448
|
+
}
|
|
2449
|
+
const key = token.slice(0, eqIdx);
|
|
2450
|
+
const value = token.slice(eqIdx + 1);
|
|
2451
|
+
if (!key) {
|
|
2452
|
+
throw new Error(`Empty key in argument '${raw}'`);
|
|
2453
|
+
}
|
|
2454
|
+
result[key] = value;
|
|
2455
|
+
}
|
|
2456
|
+
return result;
|
|
2457
|
+
}
|
|
2458
|
+
|
|
2459
|
+
// src/utils/oauth.ts
|
|
2460
|
+
init_esm_shims();
|
|
2461
|
+
import {
|
|
2462
|
+
auth,
|
|
2463
|
+
NodeOAuthClientProvider,
|
|
2464
|
+
OAuthFlowError,
|
|
2465
|
+
UnauthorizedError
|
|
2466
|
+
} from "mcp-use/auth/node";
|
|
2467
|
+
import { createInterface } from "readline";
|
|
2468
|
+
async function buildOAuthProvider(serverUrl, options = {}) {
|
|
2469
|
+
return NodeOAuthClientProvider.create(serverUrl, {
|
|
2470
|
+
clientName: "mcp-use CLI",
|
|
2471
|
+
clientUri: "https://mcp-use.com",
|
|
2472
|
+
storageKeyPrefix: "mcp:auth",
|
|
2473
|
+
...options,
|
|
2474
|
+
openBrowser: async (url) => {
|
|
2475
|
+
if (!process.stdout.isTTY) {
|
|
2476
|
+
console.error(`
|
|
2477
|
+
Open this URL in a browser to authenticate:`);
|
|
2478
|
+
console.error(` ${url}
|
|
2479
|
+
`);
|
|
2480
|
+
return;
|
|
2481
|
+
}
|
|
2482
|
+
const { default: open2 } = await Promise.resolve().then(() => (init_open(), open_exports));
|
|
2483
|
+
await open2(url);
|
|
2094
2484
|
}
|
|
2095
2485
|
});
|
|
2096
|
-
|
|
2486
|
+
}
|
|
2487
|
+
async function runOAuthFlow(provider, serverUrl, print = console.error.bind(console)) {
|
|
2488
|
+
print(
|
|
2489
|
+
process.stdout.isTTY ? `\u2192 Opening browser to authenticate...` : `\u2192 OAuth authentication required.`
|
|
2490
|
+
);
|
|
2491
|
+
print(
|
|
2492
|
+
` Listening on http://127.0.0.1:${provider.callbackPort}/callback (waiting up to 5m)`
|
|
2493
|
+
);
|
|
2494
|
+
if (!provider.hasPendingFlow) {
|
|
2495
|
+
const result = await auth(provider, { serverUrl });
|
|
2496
|
+
if (result === "AUTHORIZED") {
|
|
2497
|
+
return;
|
|
2498
|
+
}
|
|
2499
|
+
if (result !== "REDIRECT") {
|
|
2500
|
+
throw new OAuthFlowError(
|
|
2501
|
+
"unexpected_auth_result",
|
|
2502
|
+
`auth() returned ${result}`
|
|
2503
|
+
);
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
const code = await provider.getAuthorizationCode();
|
|
2507
|
+
await auth(provider, { serverUrl, authorizationCode: code });
|
|
2508
|
+
}
|
|
2509
|
+
function isUnauthorized(err) {
|
|
2510
|
+
if (err instanceof UnauthorizedError) return true;
|
|
2511
|
+
if (err instanceof Error && err.name === "UnauthorizedError") return true;
|
|
2512
|
+
if (err instanceof Error && err.code === 401) {
|
|
2513
|
+
return true;
|
|
2514
|
+
}
|
|
2515
|
+
return false;
|
|
2516
|
+
}
|
|
2517
|
+
async function promptYesNo(question, defaultYes = true) {
|
|
2518
|
+
if (!process.stdin.isTTY) return false;
|
|
2519
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
2520
|
+
try {
|
|
2521
|
+
const answer = await new Promise((resolve2) => {
|
|
2522
|
+
rl.question(`${question} ${defaultYes ? "[Y/n] " : "[y/N] "}`, resolve2);
|
|
2523
|
+
});
|
|
2524
|
+
const trimmed = answer.trim().toLowerCase();
|
|
2525
|
+
if (!trimmed) return defaultYes;
|
|
2526
|
+
return trimmed === "y" || trimmed === "yes";
|
|
2527
|
+
} finally {
|
|
2528
|
+
rl.close();
|
|
2529
|
+
}
|
|
2097
2530
|
}
|
|
2098
2531
|
|
|
2099
2532
|
// src/utils/session-storage.ts
|
|
2533
|
+
init_esm_shims();
|
|
2100
2534
|
import { homedir } from "os";
|
|
2101
2535
|
import { join } from "path";
|
|
2102
2536
|
import { readFile, writeFile, mkdir } from "fs/promises";
|
|
@@ -2176,8 +2610,133 @@ async function updateSessionInfo(name, serverInfo, capabilities) {
|
|
|
2176
2610
|
}
|
|
2177
2611
|
}
|
|
2178
2612
|
|
|
2613
|
+
// src/commands/client-auth.ts
|
|
2614
|
+
init_esm_shims();
|
|
2615
|
+
async function resolveSession(sessionArg) {
|
|
2616
|
+
let name = sessionArg;
|
|
2617
|
+
if (!name) {
|
|
2618
|
+
const active = await getActiveSession();
|
|
2619
|
+
if (!active) {
|
|
2620
|
+
console.error(formatError("No active session"));
|
|
2621
|
+
return null;
|
|
2622
|
+
}
|
|
2623
|
+
name = active.name;
|
|
2624
|
+
}
|
|
2625
|
+
const config = await getSession(name);
|
|
2626
|
+
if (!config) {
|
|
2627
|
+
console.error(formatError(`Session '${name}' not found`));
|
|
2628
|
+
return null;
|
|
2629
|
+
}
|
|
2630
|
+
if (config.type !== "http") {
|
|
2631
|
+
console.error(formatError("Auth commands only apply to HTTP sessions"));
|
|
2632
|
+
return null;
|
|
2633
|
+
}
|
|
2634
|
+
if (config.authMode !== "oauth") {
|
|
2635
|
+
console.error(
|
|
2636
|
+
formatError(
|
|
2637
|
+
`Session '${name}' was not authenticated via OAuth (authMode=${config.authMode ?? "bearer"})`
|
|
2638
|
+
)
|
|
2639
|
+
);
|
|
2640
|
+
return null;
|
|
2641
|
+
}
|
|
2642
|
+
return { name, url: config.url };
|
|
2643
|
+
}
|
|
2644
|
+
function formatExpiresIn(expSec) {
|
|
2645
|
+
const ms = expSec * 1e3 - Date.now();
|
|
2646
|
+
if (ms <= 0) return "expired";
|
|
2647
|
+
const mins = Math.round(ms / 6e4);
|
|
2648
|
+
if (mins < 60) return `${mins}m`;
|
|
2649
|
+
const hours = Math.floor(mins / 60);
|
|
2650
|
+
const rem = mins % 60;
|
|
2651
|
+
return rem ? `${hours}h${rem}m` : `${hours}h`;
|
|
2652
|
+
}
|
|
2653
|
+
function decodeJwtExp(token) {
|
|
2654
|
+
try {
|
|
2655
|
+
const parts = token.split(".");
|
|
2656
|
+
if (parts.length < 2) return null;
|
|
2657
|
+
const payload = JSON.parse(
|
|
2658
|
+
Buffer.from(parts[1], "base64url").toString("utf-8")
|
|
2659
|
+
);
|
|
2660
|
+
return typeof payload.exp === "number" ? payload.exp : null;
|
|
2661
|
+
} catch {
|
|
2662
|
+
return null;
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
async function authStatusCommand(sessionArg) {
|
|
2666
|
+
const target = await resolveSession(sessionArg);
|
|
2667
|
+
if (!target) {
|
|
2668
|
+
process.exit(1);
|
|
2669
|
+
}
|
|
2670
|
+
const provider = await buildOAuthProvider(target.url);
|
|
2671
|
+
const tokens = await provider.tokens();
|
|
2672
|
+
const fields = {
|
|
2673
|
+
session: target.name,
|
|
2674
|
+
url: target.url,
|
|
2675
|
+
tokens: tokens?.access_token ? "present" : "missing"
|
|
2676
|
+
};
|
|
2677
|
+
if (tokens?.scope) fields.scope = tokens.scope;
|
|
2678
|
+
if (tokens?.access_token) {
|
|
2679
|
+
const exp = decodeJwtExp(tokens.access_token);
|
|
2680
|
+
fields.expires_in = exp ? formatExpiresIn(exp) : "unknown (opaque token)";
|
|
2681
|
+
}
|
|
2682
|
+
fields.refresh = tokens?.refresh_token ? "available" : "missing";
|
|
2683
|
+
console.log(formatKeyValue(fields));
|
|
2684
|
+
if (!tokens?.access_token) process.exit(1);
|
|
2685
|
+
}
|
|
2686
|
+
async function authRefreshCommand(sessionArg) {
|
|
2687
|
+
const target = await resolveSession(sessionArg);
|
|
2688
|
+
if (!target) {
|
|
2689
|
+
process.exit(1);
|
|
2690
|
+
}
|
|
2691
|
+
const provider = await buildOAuthProvider(target.url);
|
|
2692
|
+
const refreshed = await provider.forceRefresh();
|
|
2693
|
+
if (!refreshed) {
|
|
2694
|
+
console.error(
|
|
2695
|
+
formatError(
|
|
2696
|
+
"Refresh failed (no refresh_token, or server rejected). Re-connect to re-authenticate."
|
|
2697
|
+
)
|
|
2698
|
+
);
|
|
2699
|
+
console.error(
|
|
2700
|
+
formatInfo(
|
|
2701
|
+
`Run: mcp-use client connect ${target.url} --name ${target.name}`
|
|
2702
|
+
)
|
|
2703
|
+
);
|
|
2704
|
+
process.exit(1);
|
|
2705
|
+
}
|
|
2706
|
+
const exp = refreshed.access_token ? decodeJwtExp(refreshed.access_token) : null;
|
|
2707
|
+
console.log(
|
|
2708
|
+
formatSuccess(
|
|
2709
|
+
`Refreshed access token${exp ? ` (expires in ${formatExpiresIn(exp)})` : ""}`
|
|
2710
|
+
)
|
|
2711
|
+
);
|
|
2712
|
+
}
|
|
2713
|
+
async function authLogoutCommand(sessionArg) {
|
|
2714
|
+
const target = await resolveSession(sessionArg);
|
|
2715
|
+
if (!target) {
|
|
2716
|
+
process.exit(1);
|
|
2717
|
+
}
|
|
2718
|
+
const provider = await buildOAuthProvider(target.url);
|
|
2719
|
+
await provider.invalidateCredentials("all");
|
|
2720
|
+
console.log(formatSuccess(`Removed tokens for ${target.url}`));
|
|
2721
|
+
console.log(
|
|
2722
|
+
formatInfo(
|
|
2723
|
+
`Session '${target.name}' kept; reconnect with \`mcp-use client connect\`.`
|
|
2724
|
+
)
|
|
2725
|
+
);
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2179
2728
|
// src/commands/client.ts
|
|
2180
2729
|
var activeSessions = /* @__PURE__ */ new Map();
|
|
2730
|
+
async function cleanupAndExit(code) {
|
|
2731
|
+
for (const [name, { client }] of activeSessions) {
|
|
2732
|
+
try {
|
|
2733
|
+
await client.closeAllSessions();
|
|
2734
|
+
} catch {
|
|
2735
|
+
}
|
|
2736
|
+
activeSessions.delete(name);
|
|
2737
|
+
}
|
|
2738
|
+
process.exit(code);
|
|
2739
|
+
}
|
|
2181
2740
|
async function getOrRestoreSession(sessionName) {
|
|
2182
2741
|
if (!sessionName) {
|
|
2183
2742
|
const active = await getActiveSession();
|
|
@@ -2204,12 +2763,22 @@ async function getOrRestoreSession(sessionName) {
|
|
|
2204
2763
|
try {
|
|
2205
2764
|
const client = new MCPClient();
|
|
2206
2765
|
const cliClientInfo = getCliClientInfo();
|
|
2766
|
+
let authProvider;
|
|
2207
2767
|
if (config.type === "http") {
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2768
|
+
if (config.authMode === "oauth") {
|
|
2769
|
+
authProvider = await buildOAuthProvider(config.url);
|
|
2770
|
+
client.addServer(sessionName, {
|
|
2771
|
+
url: config.url,
|
|
2772
|
+
authProvider,
|
|
2773
|
+
clientInfo: cliClientInfo
|
|
2774
|
+
});
|
|
2775
|
+
} else {
|
|
2776
|
+
client.addServer(sessionName, {
|
|
2777
|
+
url: config.url,
|
|
2778
|
+
headers: config.authToken ? { Authorization: `Bearer ${config.authToken}` } : void 0,
|
|
2779
|
+
clientInfo: cliClientInfo
|
|
2780
|
+
});
|
|
2781
|
+
}
|
|
2213
2782
|
} else if (config.type === "stdio") {
|
|
2214
2783
|
client.addServer(sessionName, {
|
|
2215
2784
|
command: config.command,
|
|
@@ -2221,7 +2790,30 @@ async function getOrRestoreSession(sessionName) {
|
|
|
2221
2790
|
console.error(formatError(`Unknown session type: ${config.type}`));
|
|
2222
2791
|
return null;
|
|
2223
2792
|
}
|
|
2224
|
-
|
|
2793
|
+
let session;
|
|
2794
|
+
try {
|
|
2795
|
+
session = await client.createSession(sessionName);
|
|
2796
|
+
} catch (err) {
|
|
2797
|
+
if (config.type === "http" && config.authMode === "oauth" && authProvider && isUnauthorized(err)) {
|
|
2798
|
+
const reAuth = await promptYesNo(
|
|
2799
|
+
`! Tokens for session '${sessionName}' expired and could not refresh. Re-authenticate now?`,
|
|
2800
|
+
true
|
|
2801
|
+
);
|
|
2802
|
+
if (!reAuth) {
|
|
2803
|
+
console.error(formatError(`Tokens expired and could not refresh.`));
|
|
2804
|
+
console.error(
|
|
2805
|
+
formatInfo(
|
|
2806
|
+
`Run: mcp-use client connect ${config.url} --name ${sessionName}`
|
|
2807
|
+
)
|
|
2808
|
+
);
|
|
2809
|
+
return null;
|
|
2810
|
+
}
|
|
2811
|
+
await runOAuthFlow(authProvider, config.url);
|
|
2812
|
+
session = await client.createSession(sessionName);
|
|
2813
|
+
} else {
|
|
2814
|
+
throw err;
|
|
2815
|
+
}
|
|
2816
|
+
}
|
|
2225
2817
|
activeSessions.set(sessionName, { client, session });
|
|
2226
2818
|
console.error(formatInfo(`Reconnected to session '${sessionName}'`));
|
|
2227
2819
|
return { name: sessionName, session };
|
|
@@ -2271,16 +2863,40 @@ async function connectCommand(urlOrCommand, options) {
|
|
|
2271
2863
|
});
|
|
2272
2864
|
} else {
|
|
2273
2865
|
console.error(formatInfo(`Connecting to ${urlOrCommand}...`));
|
|
2866
|
+
const wantOAuth = !options.auth && options.oauth !== false;
|
|
2867
|
+
let authProvider;
|
|
2868
|
+
if (wantOAuth) {
|
|
2869
|
+
const authTimeoutMs = options.authTimeout ? Number.parseInt(options.authTimeout, 10) : void 0;
|
|
2870
|
+
authProvider = await buildOAuthProvider(urlOrCommand, {
|
|
2871
|
+
...authTimeoutMs ? { authTimeoutMs } : {}
|
|
2872
|
+
});
|
|
2873
|
+
}
|
|
2274
2874
|
client.addServer(sessionName, {
|
|
2275
2875
|
url: urlOrCommand,
|
|
2276
|
-
|
|
2876
|
+
...authProvider ? { authProvider } : options.auth ? { headers: { Authorization: `Bearer ${options.auth}` } } : {},
|
|
2277
2877
|
clientInfo: cliClientInfo
|
|
2278
2878
|
});
|
|
2279
|
-
|
|
2879
|
+
try {
|
|
2880
|
+
session = await client.createSession(sessionName);
|
|
2881
|
+
} catch (err) {
|
|
2882
|
+
if (authProvider && isUnauthorized(err)) {
|
|
2883
|
+
console.error(
|
|
2884
|
+
formatWarning(
|
|
2885
|
+
"Server requires authentication. Starting OAuth flow."
|
|
2886
|
+
)
|
|
2887
|
+
);
|
|
2888
|
+
await runOAuthFlow(authProvider, urlOrCommand);
|
|
2889
|
+
console.error(formatSuccess("Authentication successful"));
|
|
2890
|
+
session = await client.createSession(sessionName);
|
|
2891
|
+
} else {
|
|
2892
|
+
throw err;
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2280
2895
|
await saveSession(sessionName, {
|
|
2281
2896
|
type: "http",
|
|
2282
2897
|
url: urlOrCommand,
|
|
2283
|
-
|
|
2898
|
+
authMode: authProvider ? "oauth" : options.auth ? "bearer" : void 0,
|
|
2899
|
+
authToken: authProvider ? void 0 : options.auth,
|
|
2284
2900
|
lastUsed: (/* @__PURE__ */ new Date()).toISOString()
|
|
2285
2901
|
});
|
|
2286
2902
|
}
|
|
@@ -2316,8 +2932,9 @@ async function connectCommand(urlOrCommand, options) {
|
|
|
2316
2932
|
);
|
|
2317
2933
|
} catch (error) {
|
|
2318
2934
|
console.error(formatError(`Connection failed: ${error.message}`));
|
|
2319
|
-
|
|
2935
|
+
await cleanupAndExit(1);
|
|
2320
2936
|
}
|
|
2937
|
+
await cleanupAndExit(0);
|
|
2321
2938
|
}
|
|
2322
2939
|
async function disconnectCommand(sessionName, options) {
|
|
2323
2940
|
try {
|
|
@@ -2327,13 +2944,13 @@ async function disconnectCommand(sessionName, options) {
|
|
|
2327
2944
|
activeSessions.delete(name);
|
|
2328
2945
|
console.log(formatSuccess(`Disconnected from ${name}`));
|
|
2329
2946
|
}
|
|
2330
|
-
|
|
2947
|
+
await cleanupAndExit(0);
|
|
2331
2948
|
}
|
|
2332
2949
|
if (!sessionName) {
|
|
2333
2950
|
const active = await getActiveSession();
|
|
2334
2951
|
if (!active) {
|
|
2335
2952
|
console.error(formatError("No active session to disconnect"));
|
|
2336
|
-
|
|
2953
|
+
await cleanupAndExit(0);
|
|
2337
2954
|
}
|
|
2338
2955
|
sessionName = active.name;
|
|
2339
2956
|
}
|
|
@@ -2347,43 +2964,52 @@ async function disconnectCommand(sessionName, options) {
|
|
|
2347
2964
|
}
|
|
2348
2965
|
} catch (error) {
|
|
2349
2966
|
console.error(formatError(`Failed to disconnect: ${error.message}`));
|
|
2350
|
-
|
|
2967
|
+
await cleanupAndExit(1);
|
|
2351
2968
|
}
|
|
2969
|
+
await cleanupAndExit(0);
|
|
2352
2970
|
}
|
|
2353
2971
|
async function listSessionsCommand() {
|
|
2354
2972
|
try {
|
|
2355
2973
|
const sessions = await listAllSessions();
|
|
2356
2974
|
if (sessions.length === 0) {
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2975
|
+
if (isStdoutTty()) {
|
|
2976
|
+
console.log(formatInfo("No saved sessions"));
|
|
2977
|
+
console.log(
|
|
2978
|
+
formatInfo(
|
|
2979
|
+
"Connect to a server with: npx mcp-use client connect <url>"
|
|
2980
|
+
)
|
|
2981
|
+
);
|
|
2982
|
+
}
|
|
2361
2983
|
return;
|
|
2362
2984
|
}
|
|
2363
|
-
|
|
2364
|
-
|
|
2985
|
+
const tty2 = isStdoutTty();
|
|
2986
|
+
if (tty2) {
|
|
2987
|
+
console.log(formatHeader("Saved Sessions:"));
|
|
2988
|
+
console.log("");
|
|
2989
|
+
}
|
|
2365
2990
|
const tableData = sessions.map((s) => ({
|
|
2366
2991
|
name: s.isActive ? source_default.green.bold(`${s.name} *`) : s.name,
|
|
2367
2992
|
type: s.config.type,
|
|
2368
2993
|
target: s.config.type === "http" ? s.config.url || "" : `${s.config.command} ${(s.config.args || []).join(" ")}`,
|
|
2369
|
-
server: s.config.serverInfo?.name || "unknown"
|
|
2370
|
-
status: activeSessions.has(s.name) ? source_default.green("connected") : source_default.gray("disconnected")
|
|
2994
|
+
server: s.config.serverInfo?.name || "unknown"
|
|
2371
2995
|
}));
|
|
2372
2996
|
console.log(
|
|
2373
2997
|
formatTable(tableData, [
|
|
2374
2998
|
{ key: "name", header: "Name" },
|
|
2375
2999
|
{ key: "type", header: "Type" },
|
|
2376
|
-
{ key: "target", header: "Target",
|
|
2377
|
-
{ key: "server", header: "Server" }
|
|
2378
|
-
{ key: "status", header: "Status" }
|
|
3000
|
+
{ key: "target", header: "Target", truncate: true },
|
|
3001
|
+
{ key: "server", header: "Server" }
|
|
2379
3002
|
])
|
|
2380
3003
|
);
|
|
2381
|
-
|
|
2382
|
-
|
|
3004
|
+
if (tty2) {
|
|
3005
|
+
console.log("");
|
|
3006
|
+
console.log(source_default.gray("* = active session"));
|
|
3007
|
+
}
|
|
2383
3008
|
} catch (error) {
|
|
2384
3009
|
console.error(formatError(`Failed to list sessions: ${error.message}`));
|
|
2385
|
-
|
|
3010
|
+
await cleanupAndExit(1);
|
|
2386
3011
|
}
|
|
3012
|
+
await cleanupAndExit(0);
|
|
2387
3013
|
}
|
|
2388
3014
|
async function switchSessionCommand(name) {
|
|
2389
3015
|
try {
|
|
@@ -2391,44 +3017,70 @@ async function switchSessionCommand(name) {
|
|
|
2391
3017
|
console.log(formatSuccess(`Switched to session '${name}'`));
|
|
2392
3018
|
} catch (error) {
|
|
2393
3019
|
console.error(formatError(`Failed to switch session: ${error.message}`));
|
|
2394
|
-
|
|
3020
|
+
await cleanupAndExit(1);
|
|
2395
3021
|
}
|
|
3022
|
+
await cleanupAndExit(0);
|
|
2396
3023
|
}
|
|
2397
3024
|
async function listToolsCommand(options) {
|
|
2398
3025
|
try {
|
|
2399
3026
|
const result = await getOrRestoreSession(options.session || null);
|
|
2400
|
-
if (!result)
|
|
3027
|
+
if (!result) {
|
|
3028
|
+
await cleanupAndExit(1);
|
|
3029
|
+
}
|
|
2401
3030
|
const { session } = result;
|
|
2402
3031
|
const tools = await session.listTools();
|
|
2403
3032
|
if (options.json) {
|
|
2404
3033
|
console.log(formatJson(tools));
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
3034
|
+
} else if (tools.length === 0) {
|
|
3035
|
+
if (isStdoutTty()) console.log(formatInfo("No tools available"));
|
|
3036
|
+
} else {
|
|
3037
|
+
const tty2 = isStdoutTty();
|
|
3038
|
+
if (tty2) {
|
|
3039
|
+
console.log(formatHeader(`Available Tools (${tools.length}):`));
|
|
3040
|
+
console.log("");
|
|
3041
|
+
}
|
|
3042
|
+
const tableData = tools.map((tool) => {
|
|
3043
|
+
const props = tool.inputSchema?.properties ?? {};
|
|
3044
|
+
const required = tool.inputSchema?.required ?? [];
|
|
3045
|
+
const total = Object.keys(props).length;
|
|
3046
|
+
const reqCount = Array.isArray(required) ? required.length : 0;
|
|
3047
|
+
const argsCell = total === 0 ? source_default.gray("\u2014") : `${reqCount}/${total}`;
|
|
3048
|
+
return {
|
|
3049
|
+
name: source_default.bold(tool.name),
|
|
3050
|
+
mode: formatToolMode(tool.annotations),
|
|
3051
|
+
args: argsCell,
|
|
3052
|
+
description: tool.description || source_default.gray("(no description)")
|
|
3053
|
+
};
|
|
3054
|
+
});
|
|
3055
|
+
console.log(
|
|
3056
|
+
formatTable(tableData, [
|
|
3057
|
+
{ key: "name", header: "Tool" },
|
|
3058
|
+
{ key: "mode", header: "Mode" },
|
|
3059
|
+
{ key: "args", header: "Args" },
|
|
3060
|
+
{ key: "description", header: "Description", truncate: true }
|
|
3061
|
+
])
|
|
3062
|
+
);
|
|
3063
|
+
if (tty2) {
|
|
3064
|
+
console.log("");
|
|
3065
|
+
console.log(
|
|
3066
|
+
source_default.gray(
|
|
3067
|
+
"ARGS shows required/total. Modes: read-only \xB7 write \xB7 destructive."
|
|
3068
|
+
)
|
|
3069
|
+
);
|
|
3070
|
+
}
|
|
2410
3071
|
}
|
|
2411
|
-
console.log(formatHeader(`Available Tools (${tools.length}):`));
|
|
2412
|
-
console.log("");
|
|
2413
|
-
const tableData = tools.map((tool) => ({
|
|
2414
|
-
name: source_default.bold(tool.name),
|
|
2415
|
-
description: tool.description || source_default.gray("No description")
|
|
2416
|
-
}));
|
|
2417
|
-
console.log(
|
|
2418
|
-
formatTable(tableData, [
|
|
2419
|
-
{ key: "name", header: "Tool", width: 25 },
|
|
2420
|
-
{ key: "description", header: "Description", width: 50 }
|
|
2421
|
-
])
|
|
2422
|
-
);
|
|
2423
3072
|
} catch (error) {
|
|
2424
3073
|
console.error(formatError(`Failed to list tools: ${error.message}`));
|
|
2425
|
-
|
|
3074
|
+
await cleanupAndExit(1);
|
|
2426
3075
|
}
|
|
3076
|
+
await cleanupAndExit(0);
|
|
2427
3077
|
}
|
|
2428
3078
|
async function describeToolCommand(toolName, options) {
|
|
2429
3079
|
try {
|
|
2430
3080
|
const result = await getOrRestoreSession(options.session || null);
|
|
2431
|
-
if (!result)
|
|
3081
|
+
if (!result) {
|
|
3082
|
+
await cleanupAndExit(1);
|
|
3083
|
+
}
|
|
2432
3084
|
const { session } = result;
|
|
2433
3085
|
const tools = session.tools;
|
|
2434
3086
|
const tool = tools.find((t) => t.name === toolName);
|
|
@@ -2437,7 +3089,7 @@ async function describeToolCommand(toolName, options) {
|
|
|
2437
3089
|
console.log("");
|
|
2438
3090
|
console.log(formatInfo("Available tools:"));
|
|
2439
3091
|
tools.forEach((t) => console.log(` \u2022 ${t.name}`));
|
|
2440
|
-
|
|
3092
|
+
await cleanupAndExit(1);
|
|
2441
3093
|
}
|
|
2442
3094
|
console.log(formatHeader(`Tool: ${tool.name}`));
|
|
2443
3095
|
console.log("");
|
|
@@ -2451,41 +3103,54 @@ async function describeToolCommand(toolName, options) {
|
|
|
2451
3103
|
}
|
|
2452
3104
|
} catch (error) {
|
|
2453
3105
|
console.error(formatError(`Failed to describe tool: ${error.message}`));
|
|
2454
|
-
|
|
3106
|
+
await cleanupAndExit(1);
|
|
2455
3107
|
}
|
|
3108
|
+
await cleanupAndExit(0);
|
|
2456
3109
|
}
|
|
2457
|
-
async function callToolCommand(toolName,
|
|
3110
|
+
async function callToolCommand(toolName, argsList, options) {
|
|
2458
3111
|
try {
|
|
2459
3112
|
const result = await getOrRestoreSession(options?.session || null);
|
|
2460
|
-
if (!result)
|
|
3113
|
+
if (!result) {
|
|
3114
|
+
await cleanupAndExit(1);
|
|
3115
|
+
}
|
|
2461
3116
|
const { session } = result;
|
|
3117
|
+
const tools = session.tools;
|
|
3118
|
+
const tool = tools.find((t) => t.name === toolName);
|
|
2462
3119
|
let args = {};
|
|
2463
|
-
if (
|
|
3120
|
+
if (argsList && argsList.length > 0) {
|
|
2464
3121
|
try {
|
|
2465
|
-
args =
|
|
3122
|
+
args = parseToolArgs(argsList, tool?.inputSchema);
|
|
2466
3123
|
} catch (error) {
|
|
2467
|
-
console.error(formatError(
|
|
2468
|
-
return;
|
|
2469
|
-
}
|
|
2470
|
-
} else {
|
|
2471
|
-
const tools = session.tools;
|
|
2472
|
-
const tool = tools.find((t) => t.name === toolName);
|
|
2473
|
-
if (tool?.inputSchema?.required && tool.inputSchema.required.length > 0) {
|
|
2474
|
-
console.error(
|
|
2475
|
-
formatError(
|
|
2476
|
-
"This tool requires arguments. Provide them as a JSON string."
|
|
2477
|
-
)
|
|
2478
|
-
);
|
|
3124
|
+
console.error(formatError(error.message));
|
|
2479
3125
|
console.log("");
|
|
2480
|
-
console.log(formatInfo("
|
|
3126
|
+
console.log(formatInfo("Usage:"));
|
|
2481
3127
|
console.log(
|
|
2482
|
-
` npx mcp-use client tools call ${toolName}
|
|
3128
|
+
` npx mcp-use client tools call ${toolName} key=value [key2=value2 ...]`
|
|
2483
3129
|
);
|
|
2484
|
-
console.log(
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
3130
|
+
console.log(
|
|
3131
|
+
` npx mcp-use client tools call ${toolName} nested:='{"a":1}' # JSON value`
|
|
3132
|
+
);
|
|
3133
|
+
console.log(
|
|
3134
|
+
` npx mcp-use client tools call ${toolName} '{"key":"value"}' # full JSON object`
|
|
3135
|
+
);
|
|
3136
|
+
if (tool?.inputSchema) {
|
|
3137
|
+
console.log("");
|
|
3138
|
+
console.log(formatInfo("Tool schema:"));
|
|
3139
|
+
console.log(formatSchema(tool.inputSchema));
|
|
3140
|
+
}
|
|
3141
|
+
await cleanupAndExit(1);
|
|
2488
3142
|
}
|
|
3143
|
+
} else if (tool?.inputSchema?.required && tool.inputSchema.required.length > 0) {
|
|
3144
|
+
console.error(formatError("This tool requires arguments."));
|
|
3145
|
+
console.log("");
|
|
3146
|
+
console.log(formatInfo("Provide arguments as key=value pairs:"));
|
|
3147
|
+
console.log(
|
|
3148
|
+
` npx mcp-use client tools call ${toolName} key=value [key2=value2 ...]`
|
|
3149
|
+
);
|
|
3150
|
+
console.log("");
|
|
3151
|
+
console.log(formatInfo("Tool schema:"));
|
|
3152
|
+
console.log(formatSchema(tool.inputSchema));
|
|
3153
|
+
await cleanupAndExit(1);
|
|
2489
3154
|
}
|
|
2490
3155
|
console.error(formatInfo(`Calling tool '${toolName}'...`));
|
|
2491
3156
|
const callResult = await session.callTool(toolName, args, {
|
|
@@ -2496,49 +3161,66 @@ async function callToolCommand(toolName, argsJson, options) {
|
|
|
2496
3161
|
} else {
|
|
2497
3162
|
console.log(formatToolCall(callResult));
|
|
2498
3163
|
}
|
|
3164
|
+
if (callResult.isError) {
|
|
3165
|
+
await cleanupAndExit(1);
|
|
3166
|
+
}
|
|
2499
3167
|
} catch (error) {
|
|
2500
3168
|
console.error(formatError(`Failed to call tool: ${error.message}`));
|
|
2501
|
-
|
|
3169
|
+
if (error?.data !== void 0) {
|
|
3170
|
+
console.error(
|
|
3171
|
+
source_default.gray(
|
|
3172
|
+
typeof error.data === "string" ? error.data : formatJson(error.data)
|
|
3173
|
+
)
|
|
3174
|
+
);
|
|
3175
|
+
}
|
|
3176
|
+
await cleanupAndExit(1);
|
|
2502
3177
|
}
|
|
3178
|
+
await cleanupAndExit(0);
|
|
2503
3179
|
}
|
|
2504
3180
|
async function listResourcesCommand(options) {
|
|
2505
3181
|
try {
|
|
2506
3182
|
const result = await getOrRestoreSession(options.session || null);
|
|
2507
|
-
if (!result)
|
|
3183
|
+
if (!result) {
|
|
3184
|
+
await cleanupAndExit(1);
|
|
3185
|
+
}
|
|
2508
3186
|
const { session } = result;
|
|
2509
3187
|
const resourcesResult = await session.listAllResources();
|
|
2510
3188
|
const resources = resourcesResult.resources;
|
|
2511
3189
|
if (options.json) {
|
|
2512
3190
|
console.log(formatJson(resources));
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
3191
|
+
} else if (resources.length === 0) {
|
|
3192
|
+
if (isStdoutTty()) console.log(formatInfo("No resources available"));
|
|
3193
|
+
} else {
|
|
3194
|
+
const tty2 = isStdoutTty();
|
|
3195
|
+
if (tty2) {
|
|
3196
|
+
console.log(formatHeader(`Available Resources (${resources.length}):`));
|
|
3197
|
+
console.log("");
|
|
3198
|
+
}
|
|
3199
|
+
const tableData = resources.map((resource) => ({
|
|
3200
|
+
name: source_default.bold(resource.name || "(no name)"),
|
|
3201
|
+
type: resource.mimeType || source_default.gray("unknown"),
|
|
3202
|
+
uri: resource.uri
|
|
3203
|
+
}));
|
|
3204
|
+
console.log(
|
|
3205
|
+
formatTable(tableData, [
|
|
3206
|
+
{ key: "name", header: "Name" },
|
|
3207
|
+
{ key: "type", header: "Type" },
|
|
3208
|
+
{ key: "uri", header: "URI", truncate: true }
|
|
3209
|
+
])
|
|
3210
|
+
);
|
|
2518
3211
|
}
|
|
2519
|
-
console.log(formatHeader(`Available Resources (${resources.length}):`));
|
|
2520
|
-
console.log("");
|
|
2521
|
-
const tableData = resources.map((resource) => ({
|
|
2522
|
-
uri: resource.uri,
|
|
2523
|
-
name: resource.name || source_default.gray("(no name)"),
|
|
2524
|
-
type: resource.mimeType || source_default.gray("unknown")
|
|
2525
|
-
}));
|
|
2526
|
-
console.log(
|
|
2527
|
-
formatTable(tableData, [
|
|
2528
|
-
{ key: "uri", header: "URI", width: 40 },
|
|
2529
|
-
{ key: "name", header: "Name", width: 20 },
|
|
2530
|
-
{ key: "type", header: "Type", width: 15 }
|
|
2531
|
-
])
|
|
2532
|
-
);
|
|
2533
3212
|
} catch (error) {
|
|
2534
3213
|
console.error(formatError(`Failed to list resources: ${error.message}`));
|
|
2535
|
-
|
|
3214
|
+
await cleanupAndExit(1);
|
|
2536
3215
|
}
|
|
3216
|
+
await cleanupAndExit(0);
|
|
2537
3217
|
}
|
|
2538
3218
|
async function readResourceCommand(uri, options) {
|
|
2539
3219
|
try {
|
|
2540
3220
|
const result = await getOrRestoreSession(options.session || null);
|
|
2541
|
-
if (!result)
|
|
3221
|
+
if (!result) {
|
|
3222
|
+
await cleanupAndExit(1);
|
|
3223
|
+
}
|
|
2542
3224
|
const { session } = result;
|
|
2543
3225
|
console.error(formatInfo(`Reading resource: ${uri}`));
|
|
2544
3226
|
const resource = await session.readResource(uri);
|
|
@@ -2549,13 +3231,16 @@ async function readResourceCommand(uri, options) {
|
|
|
2549
3231
|
}
|
|
2550
3232
|
} catch (error) {
|
|
2551
3233
|
console.error(formatError(`Failed to read resource: ${error.message}`));
|
|
2552
|
-
|
|
3234
|
+
await cleanupAndExit(1);
|
|
2553
3235
|
}
|
|
3236
|
+
await cleanupAndExit(0);
|
|
2554
3237
|
}
|
|
2555
3238
|
async function subscribeResourceCommand(uri, options) {
|
|
2556
3239
|
try {
|
|
2557
3240
|
const result = await getOrRestoreSession(options.session || null);
|
|
2558
|
-
if (!result)
|
|
3241
|
+
if (!result) {
|
|
3242
|
+
await cleanupAndExit(1);
|
|
3243
|
+
}
|
|
2559
3244
|
const { session } = result;
|
|
2560
3245
|
await session.subscribeToResource(uri);
|
|
2561
3246
|
console.log(formatSuccess(`Subscribed to resource: ${uri}`));
|
|
@@ -2573,13 +3258,15 @@ async function subscribeResourceCommand(uri, options) {
|
|
|
2573
3258
|
console.error(
|
|
2574
3259
|
formatError(`Failed to subscribe to resource: ${error.message}`)
|
|
2575
3260
|
);
|
|
2576
|
-
|
|
3261
|
+
await cleanupAndExit(1);
|
|
2577
3262
|
}
|
|
2578
3263
|
}
|
|
2579
3264
|
async function unsubscribeResourceCommand(uri, options) {
|
|
2580
3265
|
try {
|
|
2581
3266
|
const result = await getOrRestoreSession(options.session || null);
|
|
2582
|
-
if (!result)
|
|
3267
|
+
if (!result) {
|
|
3268
|
+
await cleanupAndExit(1);
|
|
3269
|
+
}
|
|
2583
3270
|
const { session } = result;
|
|
2584
3271
|
await session.unsubscribeFromResource(uri);
|
|
2585
3272
|
console.log(formatSuccess(`Unsubscribed from resource: ${uri}`));
|
|
@@ -2587,53 +3274,76 @@ async function unsubscribeResourceCommand(uri, options) {
|
|
|
2587
3274
|
console.error(
|
|
2588
3275
|
formatError(`Failed to unsubscribe from resource: ${error.message}`)
|
|
2589
3276
|
);
|
|
2590
|
-
|
|
3277
|
+
await cleanupAndExit(1);
|
|
2591
3278
|
}
|
|
3279
|
+
await cleanupAndExit(0);
|
|
2592
3280
|
}
|
|
2593
3281
|
async function listPromptsCommand(options) {
|
|
2594
3282
|
try {
|
|
2595
3283
|
const result = await getOrRestoreSession(options.session || null);
|
|
2596
|
-
if (!result)
|
|
3284
|
+
if (!result) {
|
|
3285
|
+
await cleanupAndExit(1);
|
|
3286
|
+
}
|
|
2597
3287
|
const { session } = result;
|
|
2598
3288
|
const promptsResult = await session.listPrompts();
|
|
2599
3289
|
const prompts = promptsResult.prompts;
|
|
2600
3290
|
if (options.json) {
|
|
2601
3291
|
console.log(formatJson(prompts));
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
3292
|
+
} else if (prompts.length === 0) {
|
|
3293
|
+
if (isStdoutTty()) console.log(formatInfo("No prompts available"));
|
|
3294
|
+
} else {
|
|
3295
|
+
const tty2 = isStdoutTty();
|
|
3296
|
+
if (tty2) {
|
|
3297
|
+
console.log(formatHeader(`Available Prompts (${prompts.length}):`));
|
|
3298
|
+
console.log("");
|
|
3299
|
+
}
|
|
3300
|
+
const tableData = prompts.map((prompt4) => {
|
|
3301
|
+
const args = prompt4.arguments ?? [];
|
|
3302
|
+
const reqCount = Array.isArray(args) ? args.filter((a) => a?.required).length : 0;
|
|
3303
|
+
const total = Array.isArray(args) ? args.length : 0;
|
|
3304
|
+
const argsCell = total === 0 ? source_default.gray("\u2014") : `${reqCount}/${total}`;
|
|
3305
|
+
return {
|
|
3306
|
+
name: source_default.bold(prompt4.name),
|
|
3307
|
+
args: argsCell,
|
|
3308
|
+
description: prompt4.description || source_default.gray("(no description)")
|
|
3309
|
+
};
|
|
3310
|
+
});
|
|
3311
|
+
console.log(
|
|
3312
|
+
formatTable(tableData, [
|
|
3313
|
+
{ key: "name", header: "Prompt" },
|
|
3314
|
+
{ key: "args", header: "Args" },
|
|
3315
|
+
{ key: "description", header: "Description", truncate: true }
|
|
3316
|
+
])
|
|
3317
|
+
);
|
|
2607
3318
|
}
|
|
2608
|
-
console.log(formatHeader(`Available Prompts (${prompts.length}):`));
|
|
2609
|
-
console.log("");
|
|
2610
|
-
const tableData = prompts.map((prompt4) => ({
|
|
2611
|
-
name: source_default.bold(prompt4.name),
|
|
2612
|
-
description: prompt4.description || source_default.gray("No description")
|
|
2613
|
-
}));
|
|
2614
|
-
console.log(
|
|
2615
|
-
formatTable(tableData, [
|
|
2616
|
-
{ key: "name", header: "Prompt", width: 25 },
|
|
2617
|
-
{ key: "description", header: "Description", width: 50 }
|
|
2618
|
-
])
|
|
2619
|
-
);
|
|
2620
3319
|
} catch (error) {
|
|
2621
3320
|
console.error(formatError(`Failed to list prompts: ${error.message}`));
|
|
2622
|
-
|
|
3321
|
+
await cleanupAndExit(1);
|
|
2623
3322
|
}
|
|
3323
|
+
await cleanupAndExit(0);
|
|
2624
3324
|
}
|
|
2625
|
-
async function getPromptCommand(promptName,
|
|
3325
|
+
async function getPromptCommand(promptName, argsList, options) {
|
|
2626
3326
|
try {
|
|
2627
3327
|
const result = await getOrRestoreSession(options?.session || null);
|
|
2628
|
-
if (!result)
|
|
3328
|
+
if (!result) {
|
|
3329
|
+
await cleanupAndExit(1);
|
|
3330
|
+
}
|
|
2629
3331
|
const { session } = result;
|
|
2630
3332
|
let args = {};
|
|
2631
|
-
if (
|
|
3333
|
+
if (argsList && argsList.length > 0) {
|
|
2632
3334
|
try {
|
|
2633
|
-
args =
|
|
3335
|
+
args = parsePromptArgs(argsList);
|
|
2634
3336
|
} catch (error) {
|
|
2635
|
-
console.error(formatError(
|
|
2636
|
-
|
|
3337
|
+
console.error(formatError(error.message));
|
|
3338
|
+
console.log("");
|
|
3339
|
+
console.log(formatInfo("Usage:"));
|
|
3340
|
+
console.log(
|
|
3341
|
+
` npx mcp-use client prompts get ${promptName} key=value [key2=value2 ...]`
|
|
3342
|
+
);
|
|
3343
|
+
console.log(
|
|
3344
|
+
` npx mcp-use client prompts get ${promptName} '{"key":"value"}' # full JSON object`
|
|
3345
|
+
);
|
|
3346
|
+
await cleanupAndExit(1);
|
|
2637
3347
|
}
|
|
2638
3348
|
}
|
|
2639
3349
|
console.error(formatInfo(`Getting prompt '${promptName}'...`));
|
|
@@ -2655,8 +3365,9 @@ async function getPromptCommand(promptName, argsJson, options) {
|
|
|
2655
3365
|
}
|
|
2656
3366
|
} catch (error) {
|
|
2657
3367
|
console.error(formatError(`Failed to get prompt: ${error.message}`));
|
|
2658
|
-
|
|
3368
|
+
await cleanupAndExit(1);
|
|
2659
3369
|
}
|
|
3370
|
+
await cleanupAndExit(0);
|
|
2660
3371
|
}
|
|
2661
3372
|
async function interactiveCommand(options) {
|
|
2662
3373
|
try {
|
|
@@ -2691,7 +3402,7 @@ async function interactiveCommand(options) {
|
|
|
2691
3402
|
source_default.gray(" exit, quit - Exit interactive mode")
|
|
2692
3403
|
);
|
|
2693
3404
|
console.log("");
|
|
2694
|
-
const rl =
|
|
3405
|
+
const rl = createInterface2({
|
|
2695
3406
|
input: process.stdin,
|
|
2696
3407
|
output: process.stdout,
|
|
2697
3408
|
prompt: source_default.cyan("mcp> ")
|
|
@@ -2706,7 +3417,7 @@ async function interactiveCommand(options) {
|
|
|
2706
3417
|
if (trimmed === "exit" || trimmed === "quit") {
|
|
2707
3418
|
console.log(formatInfo("Goodbye!"));
|
|
2708
3419
|
rl.close();
|
|
2709
|
-
|
|
3420
|
+
await cleanupAndExit(0);
|
|
2710
3421
|
}
|
|
2711
3422
|
const parts = trimmed.split(" ");
|
|
2712
3423
|
const scope = parts[0];
|
|
@@ -2830,23 +3541,29 @@ async function interactiveCommand(options) {
|
|
|
2830
3541
|
}
|
|
2831
3542
|
rl.prompt();
|
|
2832
3543
|
});
|
|
2833
|
-
rl.on("close", () => {
|
|
3544
|
+
rl.on("close", async () => {
|
|
2834
3545
|
console.log("");
|
|
2835
3546
|
console.log(formatInfo("Goodbye!"));
|
|
2836
|
-
|
|
3547
|
+
await cleanupAndExit(0);
|
|
2837
3548
|
});
|
|
2838
3549
|
} catch (error) {
|
|
2839
3550
|
console.error(
|
|
2840
3551
|
formatError(`Failed to start interactive mode: ${error.message}`)
|
|
2841
3552
|
);
|
|
2842
|
-
|
|
3553
|
+
await cleanupAndExit(1);
|
|
2843
3554
|
}
|
|
2844
3555
|
}
|
|
2845
3556
|
function createClientCommand() {
|
|
2846
3557
|
const clientCommand = new Command("client").description(
|
|
2847
3558
|
"Interactive MCP client for terminal usage"
|
|
2848
3559
|
);
|
|
2849
|
-
clientCommand.command("connect <url>").description("Connect to an MCP server").option("--name <name>", "Session name").option("--stdio", "Use stdio connector instead of HTTP").option("--auth <token>", "
|
|
3560
|
+
clientCommand.command("connect <url>").description("Connect to an MCP server").option("--name <name>", "Session name").option("--stdio", "Use stdio connector instead of HTTP").option("--auth <token>", "Static Bearer token (skips OAuth)").option(
|
|
3561
|
+
"--no-oauth",
|
|
3562
|
+
"Don't auto-trigger OAuth on 401; fail with the 401 instead"
|
|
3563
|
+
).option(
|
|
3564
|
+
"--auth-timeout <ms>",
|
|
3565
|
+
"OAuth loopback wait timeout in ms (default 300000)"
|
|
3566
|
+
).action(connectCommand);
|
|
2850
3567
|
clientCommand.command("disconnect [session]").description("Disconnect from a session").option("--all", "Disconnect all sessions").action(disconnectCommand);
|
|
2851
3568
|
const sessionsCommand = new Command("sessions").description(
|
|
2852
3569
|
"Manage CLI sessions"
|
|
@@ -2858,7 +3575,9 @@ function createClientCommand() {
|
|
|
2858
3575
|
"Interact with MCP tools"
|
|
2859
3576
|
);
|
|
2860
3577
|
toolsCommand.command("list").description("List available tools").option("--session <name>", "Use specific session").option("--json", "Output as JSON").action(listToolsCommand);
|
|
2861
|
-
toolsCommand.command("call <name> [args]").description(
|
|
3578
|
+
toolsCommand.command("call <name> [args...]").description(
|
|
3579
|
+
"Call a tool. Args as key=value pairs (use key:=<json> for nested values, or pass a JSON object)"
|
|
3580
|
+
).option("--session <name>", "Use specific session").option("--timeout <ms>", "Request timeout in milliseconds", parseInt).option("--json", "Output as JSON").action(callToolCommand);
|
|
2862
3581
|
toolsCommand.command("describe <name>").description("Show tool details and schema").option("--session <name>", "Use specific session").action(describeToolCommand);
|
|
2863
3582
|
clientCommand.addCommand(toolsCommand);
|
|
2864
3583
|
const resourcesCommand = new Command("resources").description(
|
|
@@ -2873,17 +3592,29 @@ function createClientCommand() {
|
|
|
2873
3592
|
"Interact with MCP prompts"
|
|
2874
3593
|
);
|
|
2875
3594
|
promptsCommand.command("list").description("List available prompts").option("--session <name>", "Use specific session").option("--json", "Output as JSON").action(listPromptsCommand);
|
|
2876
|
-
promptsCommand.command("get <name> [args]").description(
|
|
3595
|
+
promptsCommand.command("get <name> [args...]").description(
|
|
3596
|
+
"Get a prompt. Args as key=value pairs (or pass a JSON object)"
|
|
3597
|
+
).option("--session <name>", "Use specific session").option("--json", "Output as JSON").action(getPromptCommand);
|
|
2877
3598
|
clientCommand.addCommand(promptsCommand);
|
|
2878
3599
|
clientCommand.command("interactive").description("Start interactive REPL mode").option("--session <name>", "Use specific session").action(interactiveCommand);
|
|
3600
|
+
const authCommand = new Command("auth").description(
|
|
3601
|
+
"Manage OAuth tokens for HTTP sessions"
|
|
3602
|
+
);
|
|
3603
|
+
authCommand.command("status [session]").description("Show OAuth token status for a session").action(authStatusCommand);
|
|
3604
|
+
authCommand.command("refresh [session]").description("Force-refresh the OAuth access token").action(authRefreshCommand);
|
|
3605
|
+
authCommand.command("logout [session]").description("Remove stored OAuth tokens for the session's URL").action(authLogoutCommand);
|
|
3606
|
+
clientCommand.addCommand(authCommand);
|
|
2879
3607
|
return clientCommand;
|
|
2880
3608
|
}
|
|
2881
3609
|
|
|
2882
3610
|
// src/commands/deploy.ts
|
|
3611
|
+
init_esm_shims();
|
|
3612
|
+
init_open();
|
|
2883
3613
|
import { promises as fs9 } from "fs";
|
|
2884
3614
|
import path5 from "path";
|
|
2885
3615
|
|
|
2886
3616
|
// src/utils/git.ts
|
|
3617
|
+
init_esm_shims();
|
|
2887
3618
|
import { execFile as execFile7 } from "child_process";
|
|
2888
3619
|
import { promisify as promisify7 } from "util";
|
|
2889
3620
|
var execFileAsync5 = promisify7(execFile7);
|
|
@@ -3019,6 +3750,7 @@ function isGitHubUrl(url) {
|
|
|
3019
3750
|
}
|
|
3020
3751
|
|
|
3021
3752
|
// src/utils/cloud-urls.ts
|
|
3753
|
+
init_esm_shims();
|
|
3022
3754
|
var GATEWAY_DOMAIN = "run.mcp-use.com";
|
|
3023
3755
|
function buildGatewayUrl(slugOrId) {
|
|
3024
3756
|
return `https://${slugOrId}.${GATEWAY_DOMAIN}/mcp`;
|
|
@@ -3035,6 +3767,7 @@ function getMcpServerUrlForCloudServer(server) {
|
|
|
3035
3767
|
}
|
|
3036
3768
|
|
|
3037
3769
|
// src/utils/project-link.ts
|
|
3770
|
+
init_esm_shims();
|
|
3038
3771
|
import { promises as fs8 } from "fs";
|
|
3039
3772
|
import path4 from "path";
|
|
3040
3773
|
var MCP_USE_DIR = ".mcp-use";
|
|
@@ -4257,6 +4990,7 @@ async function deployCommand(options) {
|
|
|
4257
4990
|
}
|
|
4258
4991
|
|
|
4259
4992
|
// src/commands/deployments.ts
|
|
4993
|
+
init_esm_shims();
|
|
4260
4994
|
import { Command as Command2 } from "commander";
|
|
4261
4995
|
async function prompt2(question) {
|
|
4262
4996
|
const readline = await import("readline");
|
|
@@ -4685,9 +5419,11 @@ function createDeploymentsCommand() {
|
|
|
4685
5419
|
}
|
|
4686
5420
|
|
|
4687
5421
|
// src/commands/servers.ts
|
|
5422
|
+
init_esm_shims();
|
|
4688
5423
|
import { Command as Command4 } from "commander";
|
|
4689
5424
|
|
|
4690
5425
|
// src/commands/env.ts
|
|
5426
|
+
init_esm_shims();
|
|
4691
5427
|
import { Command as Command3 } from "commander";
|
|
4692
5428
|
var ALL_ENVS = ["production", "preview", "development"];
|
|
4693
5429
|
function parseEnvironments(raw) {
|
|
@@ -5128,6 +5864,7 @@ function createServersCommand() {
|
|
|
5128
5864
|
}
|
|
5129
5865
|
|
|
5130
5866
|
// src/commands/org.ts
|
|
5867
|
+
init_esm_shims();
|
|
5131
5868
|
async function ensureLoggedIn() {
|
|
5132
5869
|
if (!await isLoggedIn()) {
|
|
5133
5870
|
console.log(source_default.yellow("\u26A0\uFE0F You are not logged in."));
|
|
@@ -5235,6 +5972,7 @@ async function orgCurrentCommand() {
|
|
|
5235
5972
|
}
|
|
5236
5973
|
|
|
5237
5974
|
// src/commands/skills.ts
|
|
5975
|
+
init_esm_shims();
|
|
5238
5976
|
import { Command as Command5 } from "commander";
|
|
5239
5977
|
import { cpSync, existsSync as existsSync2, mkdtempSync, readdirSync, rmSync } from "fs";
|
|
5240
5978
|
import { tmpdir } from "os";
|
|
@@ -5351,6 +6089,7 @@ function createSkillsCommand() {
|
|
|
5351
6089
|
}
|
|
5352
6090
|
|
|
5353
6091
|
// src/utils/next-shims.ts
|
|
6092
|
+
init_esm_shims();
|
|
5354
6093
|
import { existsSync as existsSync3, promises as fs10 } from "fs";
|
|
5355
6094
|
import path6 from "path";
|
|
5356
6095
|
import { fileURLToPath as fileURLToPath3, pathToFileURL } from "url";
|
|
@@ -5451,6 +6190,7 @@ function quoteNodeOption(value) {
|
|
|
5451
6190
|
}
|
|
5452
6191
|
|
|
5453
6192
|
// src/utils/update-check.ts
|
|
6193
|
+
init_esm_shims();
|
|
5454
6194
|
import { readFileSync } from "fs";
|
|
5455
6195
|
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
|
|
5456
6196
|
import { createRequire } from "module";
|