openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
884 lines (883 loc) • 28.8 kB
JavaScript
import { l as normalizeOptionalString, t as hasNonEmptyString } from "./string-coerce-CCIiB4H7.mjs";
import { n as resolveRuntimeDependencyEntrypointUrl } from "./runtime-process-dependency-url-DZ5qlXt3.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import "./process-runtime-DcBPEA8Y.mjs";
import { c as BrowserProfileUnavailableError } from "./errors-C9QQGqVs.mjs";
import { createRequire } from "node:module";
import { fileURLToPath } from "node:url";
import { readFileSync } from "fs";
import { normalize, resolve } from "path";
import { format as format$1 } from "util";
//#region node_modules/.pnpm/yargs-parser@22.0.0/node_modules/yargs-parser/build/lib/string-utils.js
/**
* @license
* Copyright (c) 2016, Contributors
* SPDX-License-Identifier: ISC
*/
function camelCase(e) {
if (!(e !== e.toLowerCase() && e !== e.toUpperCase())) e = e.toLowerCase();
if (e.indexOf("-") === -1 && e.indexOf("_") === -1) return e;
else {
let t = "";
let n = false;
const r = e.match(/^-+/);
for (let i = r ? r[0].length : 0; i < e.length; i++) {
let r = e.charAt(i);
if (n) {
n = false;
r = r.toUpperCase();
}
if (i !== 0 && (r === "-" || r === "_")) n = true;
else if (r !== "-" && r !== "_") t += r;
}
return t;
}
}
function decamelize(e, t) {
const n = e.toLowerCase();
t = t || "-";
let r = "";
for (let i = 0; i < e.length; i++) {
const a = n.charAt(i);
const o = e.charAt(i);
if (a !== o && i > 0) r += `${t}${n.charAt(i)}`;
else r += o;
}
return r;
}
function looksLikeNumber(e) {
if (e === null || e === void 0) return false;
if (typeof e === "number") return true;
if (/^0x[0-9a-f]+$/i.test(e)) return true;
if (/^0[^.]/.test(e)) return false;
return /^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e);
}
//#endregion
//#region node_modules/.pnpm/yargs-parser@22.0.0/node_modules/yargs-parser/build/lib/tokenize-arg-string.js
/**
* @license
* Copyright (c) 2016, Contributors
* SPDX-License-Identifier: ISC
*/
function tokenizeArgString(e) {
if (Array.isArray(e)) return e.map((e) => typeof e !== "string" ? e + "" : e);
e = e.trim();
let t = 0;
let n = null;
let r = null;
let i = null;
const a = [];
for (let o = 0; o < e.length; o++) {
n = r;
r = e.charAt(o);
if (r === " " && !i) {
if (!(n === " ")) t++;
continue;
}
if (r === i) i = null;
else if ((r === "'" || r === "\"") && !i) i = r;
if (!a[t]) a[t] = "";
a[t] += r;
}
return a;
}
//#endregion
//#region node_modules/.pnpm/yargs-parser@22.0.0/node_modules/yargs-parser/build/lib/yargs-parser-types.js
/**
* @license
* Copyright (c) 2016, Contributors
* SPDX-License-Identifier: ISC
*/
var DefaultValuesForTypeKey;
(function(e) {
e["BOOLEAN"] = "boolean";
e["STRING"] = "string";
e["NUMBER"] = "number";
e["ARRAY"] = "array";
})(DefaultValuesForTypeKey || (DefaultValuesForTypeKey = {}));
//#endregion
//#region node_modules/.pnpm/yargs-parser@22.0.0/node_modules/yargs-parser/build/lib/yargs-parser.js
/**
* @license
* Copyright (c) 2016, Contributors
* SPDX-License-Identifier: ISC
*/
let mixin;
var YargsParser = class {
constructor(e) {
mixin = e;
}
parse(e, t) {
const n = Object.assign({
alias: void 0,
array: void 0,
boolean: void 0,
config: void 0,
configObjects: void 0,
configuration: void 0,
coerce: void 0,
count: void 0,
default: void 0,
envPrefix: void 0,
narg: void 0,
normalize: void 0,
string: void 0,
number: void 0,
__: void 0,
key: void 0
}, t);
const r = tokenizeArgString(e);
const i = typeof e === "string";
const a = combineAliases(Object.assign(Object.create(null), n.alias));
const o = Object.assign({
"boolean-negation": true,
"camel-case-expansion": true,
"combine-arrays": false,
"dot-notation": true,
"duplicate-arguments-array": true,
"flatten-duplicate-arrays": true,
"greedy-arrays": true,
"halt-at-non-option": false,
"nargs-eats-options": false,
"negation-prefix": "no-",
"parse-numbers": true,
"parse-positional-numbers": true,
"populate--": false,
"set-placeholder-key": false,
"short-option-groups": true,
"strip-aliased": false,
"strip-dashed": false,
"unknown-options-as-args": false
}, n.configuration);
const s = Object.assign(Object.create(null), n.default);
const c = n.configObjects || [];
const l = n.envPrefix;
const u = o["populate--"];
const d = u ? "--" : "_";
const f = Object.create(null);
const p = Object.create(null);
const m = n.__ || mixin.format;
const h = {
aliases: Object.create(null),
arrays: Object.create(null),
bools: Object.create(null),
strings: Object.create(null),
numbers: Object.create(null),
counts: Object.create(null),
normalize: Object.create(null),
configs: Object.create(null),
nargs: Object.create(null),
coercions: Object.create(null),
keys: []
};
const g = /^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/;
const _ = new RegExp("^--" + o["negation-prefix"] + "(.+)");
[].concat(n.array || []).filter(Boolean).forEach(function(e) {
const t = typeof e === "object" ? e.key : e;
const n = Object.keys(e).map(function(e) {
return {
boolean: "bools",
string: "strings",
number: "numbers"
}[e];
}).filter(Boolean).pop();
if (n) h[n][t] = true;
h.arrays[t] = true;
h.keys.push(t);
});
[].concat(n.boolean || []).filter(Boolean).forEach(function(e) {
h.bools[e] = true;
h.keys.push(e);
});
[].concat(n.string || []).filter(Boolean).forEach(function(e) {
h.strings[e] = true;
h.keys.push(e);
});
[].concat(n.number || []).filter(Boolean).forEach(function(e) {
h.numbers[e] = true;
h.keys.push(e);
});
[].concat(n.count || []).filter(Boolean).forEach(function(e) {
h.counts[e] = true;
h.keys.push(e);
});
[].concat(n.normalize || []).filter(Boolean).forEach(function(e) {
h.normalize[e] = true;
h.keys.push(e);
});
if (typeof n.narg === "object") Object.entries(n.narg).forEach(([e, t]) => {
if (typeof t === "number") {
h.nargs[e] = t;
h.keys.push(e);
}
});
if (typeof n.coerce === "object") Object.entries(n.coerce).forEach(([e, t]) => {
if (typeof t === "function") {
h.coercions[e] = t;
h.keys.push(e);
}
});
if (typeof n.config !== "undefined") {
if (Array.isArray(n.config) || typeof n.config === "string") [].concat(n.config).filter(Boolean).forEach(function(e) {
h.configs[e] = true;
});
else if (typeof n.config === "object") Object.entries(n.config).forEach(([e, t]) => {
if (typeof t === "boolean" || typeof t === "function") h.configs[e] = t;
});
}
extendAliases(n.key, a, n.default, h.arrays);
Object.keys(s).forEach(function(e) {
(h.aliases[e] || []).forEach(function(t) {
s[t] = s[e];
});
});
let v = null;
checkConfiguration();
let y = [];
const b = Object.assign(Object.create(null), { _: [] });
const x = {};
for (let e = 0; e < r.length; e++) {
const t = r[e];
const n = t.replace(/^-{3,}/, "---");
let i;
let a;
let s;
let c;
let l;
let u;
if (t !== "--" && /^-/.test(t) && isUnknownOptionAsArg(t)) pushPositional(t);
else if (n.match(/^---+(=|$)/)) {
pushPositional(t);
continue;
} else if (t.match(/^--.+=/) || !o["short-option-groups"] && t.match(/^-.+=/)) {
c = t.match(/^--?([^=]+)=([\s\S]*)$/);
if (c !== null && Array.isArray(c) && c.length >= 3) {
if (checkAllAliases(c[1], h.arrays)) e = eatArray(e, c[1], r, c[2]);
else if (checkAllAliases(c[1], h.nargs) !== false) e = eatNargs(e, c[1], r, c[2]);
else setArg(c[1], c[2], true);
}
} else if (t.match(_) && o["boolean-negation"]) {
c = t.match(_);
if (c !== null && Array.isArray(c) && c.length >= 2) {
a = c[1];
setArg(a, checkAllAliases(a, h.arrays) ? [false] : false);
}
} else if (t.match(/^--.+/) || !o["short-option-groups"] && t.match(/^-[^-]+/)) {
c = t.match(/^--?(.+)/);
if (c !== null && Array.isArray(c) && c.length >= 2) {
a = c[1];
if (checkAllAliases(a, h.arrays)) e = eatArray(e, a, r);
else if (checkAllAliases(a, h.nargs) !== false) e = eatNargs(e, a, r);
else {
l = r[e + 1];
if (l !== void 0 && (!l.match(/^-/) || l.match(g)) && !checkAllAliases(a, h.bools) && !checkAllAliases(a, h.counts)) {
setArg(a, l);
e++;
} else if (/^(true|false)$/.test(l)) {
setArg(a, l);
e++;
} else setArg(a, defaultValue(a));
}
}
} else if (t.match(/^-.\..+=/)) {
c = t.match(/^-([^=]+)=([\s\S]*)$/);
if (c !== null && Array.isArray(c) && c.length >= 3) setArg(c[1], c[2]);
} else if (t.match(/^-.\..+/) && !t.match(g)) {
l = r[e + 1];
c = t.match(/^-(.\..+)/);
if (c !== null && Array.isArray(c) && c.length >= 2) {
a = c[1];
if (l !== void 0 && !l.match(/^-/) && !checkAllAliases(a, h.bools) && !checkAllAliases(a, h.counts)) {
setArg(a, l);
e++;
} else setArg(a, defaultValue(a));
}
} else if (t.match(/^-[^-]+/) && !t.match(g)) {
s = t.slice(1, -1).split("");
i = false;
for (let n = 0; n < s.length; n++) {
l = t.slice(n + 2);
if (s[n + 1] && s[n + 1] === "=") {
u = t.slice(n + 3);
a = s[n];
if (checkAllAliases(a, h.arrays)) e = eatArray(e, a, r, u);
else if (checkAllAliases(a, h.nargs) !== false) e = eatNargs(e, a, r, u);
else setArg(a, u);
i = true;
break;
}
if (l === "-") {
setArg(s[n], l);
continue;
}
if (/[A-Za-z]/.test(s[n]) && /^-?\d+(\.\d*)?(e-?\d+)?$/.test(l) && checkAllAliases(l, h.bools) === false) {
setArg(s[n], l);
i = true;
break;
}
if (s[n + 1] && s[n + 1].match(/\W/)) {
setArg(s[n], l);
i = true;
break;
} else setArg(s[n], defaultValue(s[n]));
}
a = t.slice(-1)[0];
if (!i && a !== "-") {
if (checkAllAliases(a, h.arrays)) e = eatArray(e, a, r);
else if (checkAllAliases(a, h.nargs) !== false) e = eatNargs(e, a, r);
else {
l = r[e + 1];
if (l !== void 0 && (!/^(-|--)[^-]/.test(l) || l.match(g)) && !checkAllAliases(a, h.bools) && !checkAllAliases(a, h.counts)) {
setArg(a, l);
e++;
} else if (/^(true|false)$/.test(l)) {
setArg(a, l);
e++;
} else setArg(a, defaultValue(a));
}
}
} else if (t.match(/^-[0-9]$/) && t.match(g) && checkAllAliases(t.slice(1), h.bools)) {
a = t.slice(1);
setArg(a, defaultValue(a));
} else if (t === "--") {
y = r.slice(e + 1);
break;
} else if (o["halt-at-non-option"]) {
y = r.slice(e);
break;
} else pushPositional(t);
}
applyEnvVars(b, true);
applyEnvVars(b, false);
setConfig(b);
setConfigObjects();
applyDefaultsAndAliases(b, h.aliases, s, true);
applyCoercions(b);
if (o["set-placeholder-key"]) setPlaceholderKeys(b);
Object.keys(h.counts).forEach(function(e) {
if (!hasKey(b, e.split("."))) setArg(e, 0);
});
if (u && y.length) b[d] = [];
y.forEach(function(e) {
b[d].push(e);
});
if (o["camel-case-expansion"] && o["strip-dashed"]) Object.keys(b).filter((e) => e !== "--" && e.includes("-")).forEach((e) => {
delete b[e];
});
if (o["strip-aliased"]) [].concat(...Object.keys(a).map((e) => a[e])).forEach((e) => {
if (o["camel-case-expansion"] && e.includes("-")) delete b[e.split(".").map((e) => camelCase(e)).join(".")];
delete b[e];
});
function pushPositional(e) {
const t = maybeCoerceNumber("_", e);
if (typeof t === "string" || typeof t === "number") b._.push(t);
}
function eatNargs(e, t, n, r) {
let i;
let a = checkAllAliases(t, h.nargs);
a = typeof a !== "number" || isNaN(a) ? 1 : a;
if (a === 0) {
if (!isUndefined(r)) v = Error(m("Argument unexpected for: %s", t));
setArg(t, defaultValue(t));
return e;
}
let s = isUndefined(r) ? 0 : 1;
if (o["nargs-eats-options"]) {
if (n.length - (e + 1) + s < a) v = Error(m("Not enough arguments following: %s", t));
s = a;
} else {
for (i = e + 1; i < n.length; i++) if (!n[i].match(/^-[^0-9]/) || n[i].match(g) || isUnknownOptionAsArg(n[i])) s++;
else break;
if (s < a) v = Error(m("Not enough arguments following: %s", t));
}
let c = Math.min(s, a);
if (!isUndefined(r) && c > 0) {
setArg(t, r);
c--;
}
for (i = e + 1; i < c + e + 1; i++) setArg(t, n[i]);
return e + c;
}
function eatArray(e, t, n, r) {
let a = [];
let c = r || n[e + 1];
const l = checkAllAliases(t, h.nargs);
if (checkAllAliases(t, h.bools) && !/^(true|false)$/.test(c)) a.push(true);
else if (isUndefined(c) || isUndefined(r) && /^-/.test(c) && !g.test(c) && !isUnknownOptionAsArg(c)) {
if (s[t] !== void 0) {
const e = s[t];
a = Array.isArray(e) ? e : [e];
}
} else {
if (!isUndefined(r)) a.push(processValue(t, r, true));
for (let r = e + 1; r < n.length; r++) {
if (!o["greedy-arrays"] && a.length > 0 || l && typeof l === "number" && a.length >= l) break;
c = n[r];
if (/^-/.test(c) && !g.test(c) && !isUnknownOptionAsArg(c)) break;
e = r;
a.push(processValue(t, c, i));
}
}
if (typeof l === "number" && (l && a.length < l || isNaN(l) && a.length === 0)) v = Error(m("Not enough arguments following: %s", t));
setArg(t, a);
return e;
}
function setArg(e, t, n = i) {
if (/-/.test(e) && o["camel-case-expansion"]) addNewAlias(e, e.split(".").map(function(e) {
return camelCase(e);
}).join("."));
const r = processValue(e, t, n);
const a = e.split(".");
setKey(b, a, r);
if (h.aliases[e]) h.aliases[e].forEach(function(e) {
const t = e.split(".");
setKey(b, t, r);
});
if (a.length > 1 && o["dot-notation"]) (h.aliases[a[0]] || []).forEach(function(t) {
let n = t.split(".");
const i = [].concat(a);
i.shift();
n = n.concat(i);
if (!(h.aliases[e] || []).includes(n.join("."))) setKey(b, n, r);
});
if (checkAllAliases(e, h.normalize) && !checkAllAliases(e, h.arrays)) [e].concat(h.aliases[e] || []).forEach(function(e) {
Object.defineProperty(x, e, {
enumerable: true,
get() {
return t;
},
set(e) {
t = typeof e === "string" ? mixin.normalize(e) : e;
}
});
});
}
function addNewAlias(e, t) {
if (!(h.aliases[e] && h.aliases[e].length)) {
h.aliases[e] = [t];
f[t] = true;
}
if (!(h.aliases[t] && h.aliases[t].length)) addNewAlias(t, e);
}
function processValue(e, t, n) {
if (n) t = stripQuotes(t);
if (checkAllAliases(e, h.bools) || checkAllAliases(e, h.counts)) {
if (typeof t === "string") t = t === "true";
}
let r = Array.isArray(t) ? t.map(function(t) {
return maybeCoerceNumber(e, t);
}) : maybeCoerceNumber(e, t);
if (checkAllAliases(e, h.counts) && (isUndefined(r) || typeof r === "boolean")) r = increment();
if (checkAllAliases(e, h.normalize) && checkAllAliases(e, h.arrays)) {
if (Array.isArray(t)) r = t.map((e) => {
return mixin.normalize(e);
});
else r = mixin.normalize(t);
}
return r;
}
function maybeCoerceNumber(e, t) {
if (!o["parse-positional-numbers"] && e === "_") return t;
if (!checkAllAliases(e, h.strings) && !checkAllAliases(e, h.bools) && !Array.isArray(t)) {
if (looksLikeNumber(t) && o["parse-numbers"] && Number.isSafeInteger(Math.floor(parseFloat(`${t}`))) || !isUndefined(t) && checkAllAliases(e, h.numbers)) t = Number(t);
}
return t;
}
function setConfig(e) {
const t = Object.create(null);
applyDefaultsAndAliases(t, h.aliases, s);
Object.keys(h.configs).forEach(function(n) {
const r = e[n] || t[n];
if (r) try {
let e = null;
const t = mixin.resolve(mixin.cwd(), r);
const i = h.configs[n];
if (typeof i === "function") {
try {
e = i(t);
} catch (t) {
e = t;
}
if (e instanceof Error) {
v = e;
return;
}
} else e = mixin.require(t);
setConfigObject(e);
} catch (t) {
if (t.name === "PermissionDenied") v = t;
else if (e[n]) v = Error(m("Invalid JSON config file: %s", r));
}
});
}
function setConfigObject(e, t) {
Object.keys(e).forEach(function(n) {
const r = e[n];
const i = t ? t + "." + n : n;
if (typeof r === "object" && r !== null && !Array.isArray(r) && o["dot-notation"]) setConfigObject(r, i);
else if (!hasKey(b, i.split(".")) || checkAllAliases(i, h.arrays) && o["combine-arrays"]) setArg(i, r);
});
}
function setConfigObjects() {
if (typeof c !== "undefined") c.forEach(function(e) {
setConfigObject(e);
});
}
function applyEnvVars(e, t) {
if (typeof l === "undefined") return;
const n = typeof l === "string" ? l : "";
const r = mixin.env();
Object.keys(r).forEach(function(i) {
if (n === "" || i.lastIndexOf(n, 0) === 0) {
const a = i.split("__").map(function(e, t) {
if (t === 0) e = e.substring(n.length);
return camelCase(e);
});
if ((t && h.configs[a.join(".")] || !t) && !hasKey(e, a)) setArg(a.join("."), r[i]);
}
});
}
function applyCoercions(e) {
let t;
const n = /* @__PURE__ */ new Set();
Object.keys(e).forEach(function(r) {
if (!n.has(r)) {
t = checkAllAliases(r, h.coercions);
if (typeof t === "function") try {
const i = maybeCoerceNumber(r, t(e[r]));
[].concat(h.aliases[r] || [], r).forEach((t) => {
n.add(t);
e[t] = i;
});
} catch (e) {
v = e;
}
}
});
}
function setPlaceholderKeys(e) {
h.keys.forEach((t) => {
if (~t.indexOf(".")) return;
if (typeof e[t] === "undefined") e[t] = void 0;
});
return e;
}
function applyDefaultsAndAliases(e, t, n, r = false) {
Object.keys(n).forEach(function(i) {
if (!hasKey(e, i.split("."))) {
setKey(e, i.split("."), n[i]);
if (r) p[i] = true;
(t[i] || []).forEach(function(t) {
if (hasKey(e, t.split("."))) return;
setKey(e, t.split("."), n[i]);
});
}
});
}
function hasKey(e, t) {
let n = e;
if (!o["dot-notation"]) t = [t.join(".")];
t.slice(0, -1).forEach(function(e) {
n = n[e] || {};
});
const r = t[t.length - 1];
if (typeof n !== "object") return false;
else return r in n;
}
function setKey(e, t, n) {
let r = e;
if (!o["dot-notation"]) t = [t.join(".")];
t.slice(0, -1).forEach(function(e) {
e = sanitizeKey(e);
if (typeof r === "object" && r[e] === void 0) r[e] = {};
if (typeof r[e] !== "object" || Array.isArray(r[e])) {
if (Array.isArray(r[e])) r[e].push({});
else r[e] = [r[e], {}];
r = r[e][r[e].length - 1];
} else r = r[e];
});
const i = sanitizeKey(t[t.length - 1]);
const a = checkAllAliases(t.join("."), h.arrays);
const s = Array.isArray(n);
let c = o["duplicate-arguments-array"];
if (!c && checkAllAliases(i, h.nargs)) {
c = true;
if (!isUndefined(r[i]) && h.nargs[i] === 1 || Array.isArray(r[i]) && r[i].length === h.nargs[i]) r[i] = void 0;
}
if (n === increment()) r[i] = increment(r[i]);
else if (Array.isArray(r[i])) {
if (c && a && s) r[i] = o["flatten-duplicate-arrays"] ? r[i].concat(n) : (Array.isArray(r[i][0]) ? r[i] : [r[i]]).concat([n]);
else if (!c && Boolean(a) === Boolean(s)) r[i] = n;
else r[i] = r[i].concat([n]);
} else if (r[i] === void 0 && a) r[i] = s ? n : [n];
else if (c && !(r[i] === void 0 || checkAllAliases(i, h.counts) || checkAllAliases(i, h.bools))) r[i] = [r[i], n];
else r[i] = n;
}
function extendAliases(...e) {
e.forEach(function(e) {
Object.keys(e || {}).forEach(function(e) {
if (h.aliases[e]) return;
h.aliases[e] = [].concat(a[e] || []);
h.aliases[e].concat(e).forEach(function(t) {
if (/-/.test(t) && o["camel-case-expansion"]) {
const n = camelCase(t);
if (n !== e && h.aliases[e].indexOf(n) === -1) {
h.aliases[e].push(n);
f[n] = true;
}
}
});
h.aliases[e].concat(e).forEach(function(t) {
if (t.length > 1 && /[A-Z]/.test(t) && o["camel-case-expansion"]) {
const n = decamelize(t, "-");
if (n !== e && h.aliases[e].indexOf(n) === -1) {
h.aliases[e].push(n);
f[n] = true;
}
}
});
h.aliases[e].forEach(function(t) {
h.aliases[t] = [e].concat(h.aliases[e].filter(function(e) {
return t !== e;
}));
});
});
});
}
function checkAllAliases(e, t) {
const n = [].concat(h.aliases[e] || [], e);
const r = Object.keys(t);
const i = n.find((e) => r.includes(e));
return i ? t[i] : false;
}
function hasAnyFlag(e) {
const t = Object.keys(h);
return [].concat(t.map((e) => h[e])).some(function(t) {
return Array.isArray(t) ? t.includes(e) : t[e];
});
}
function hasFlagsMatching(e, ...t) {
return [].concat(...t).some(function(t) {
const n = e.match(t);
return n && hasAnyFlag(n[1]);
});
}
function hasAllShortFlags(e) {
if (e.match(g) || !e.match(/^-[^-]+/)) return false;
let t = true;
let n;
const r = e.slice(1).split("");
for (let i = 0; i < r.length; i++) {
n = e.slice(i + 2);
if (!hasAnyFlag(r[i])) {
t = false;
break;
}
if (r[i + 1] && r[i + 1] === "=" || n === "-" || /[A-Za-z]/.test(r[i]) && /^-?\d+(\.\d*)?(e-?\d+)?$/.test(n) || r[i + 1] && r[i + 1].match(/\W/)) break;
}
return t;
}
function isUnknownOptionAsArg(e) {
return o["unknown-options-as-args"] && isUnknownOption(e);
}
function isUnknownOption(e) {
e = e.replace(/^-{3,}/, "--");
if (e.match(g)) return false;
if (hasAllShortFlags(e)) return false;
return !hasFlagsMatching(e, /^-+([^=]+?)=[\s\S]*$/, _, /^-+([^=]+?)$/, /^-+([^=]+?)-$/, /^-+([^=]+?\d+)$/, /^-+([^=]+?)\W+.*$/);
}
function defaultValue(e) {
if (!checkAllAliases(e, h.bools) && !checkAllAliases(e, h.counts) && `${e}` in s) return s[e];
else return defaultForType(guessType(e));
}
function defaultForType(e) {
return {
[DefaultValuesForTypeKey.BOOLEAN]: true,
[DefaultValuesForTypeKey.STRING]: "",
[DefaultValuesForTypeKey.NUMBER]: void 0,
[DefaultValuesForTypeKey.ARRAY]: []
}[e];
}
function guessType(e) {
let t = DefaultValuesForTypeKey.BOOLEAN;
if (checkAllAliases(e, h.strings)) t = DefaultValuesForTypeKey.STRING;
else if (checkAllAliases(e, h.numbers)) t = DefaultValuesForTypeKey.NUMBER;
else if (checkAllAliases(e, h.bools)) t = DefaultValuesForTypeKey.BOOLEAN;
else if (checkAllAliases(e, h.arrays)) t = DefaultValuesForTypeKey.ARRAY;
return t;
}
function isUndefined(e) {
return e === void 0;
}
function checkConfiguration() {
Object.keys(h.counts).find((e) => {
if (checkAllAliases(e, h.arrays)) {
v = Error(m("Invalid configuration: %s, opts.count excludes opts.array.", e));
return true;
} else if (checkAllAliases(e, h.nargs)) {
v = Error(m("Invalid configuration: %s, opts.count excludes opts.narg.", e));
return true;
}
return false;
});
}
return {
aliases: Object.assign({}, h.aliases),
argv: Object.assign(x, b),
configuration: o,
defaulted: Object.assign({}, p),
error: v,
newAliases: Object.assign({}, f)
};
}
};
function combineAliases(e) {
const t = [];
const n = Object.create(null);
let r = true;
Object.keys(e).forEach(function(n) {
t.push([].concat(e[n], n));
});
while (r) {
r = false;
for (let e = 0; e < t.length; e++) for (let n = e + 1; n < t.length; n++) if (t[e].filter(function(e) {
return t[n].indexOf(e) !== -1;
}).length) {
t[e] = t[e].concat(t[n]);
t.splice(n, 1);
r = true;
break;
}
}
t.forEach(function(e) {
e = e.filter(function(e, t, n) {
return n.indexOf(e) === t;
});
const t = e.pop();
if (t !== void 0 && typeof t === "string") n[t] = e;
});
return n;
}
function increment(e) {
return e !== void 0 ? e + 1 : 1;
}
function sanitizeKey(e) {
if (e === "__proto__") return "___proto___";
return e;
}
function stripQuotes(e) {
return typeof e === "string" && (e[0] === "'" || e[0] === "\"") && e[e.length - 1] === e[0] ? e.substring(1, e.length - 1) : e;
}
//#endregion
//#region node_modules/.pnpm/yargs-parser@22.0.0/node_modules/yargs-parser/build/lib/index.js
/**
* @fileoverview Main entrypoint for libraries using yargs-parser in Node.js
*
* @license
* Copyright (c) 2016, Contributors
* SPDX-License-Identifier: ISC
*/
var _a;
var _b;
var _c;
const minNodeVersion = process && process.env && process.env.YARGS_MIN_NODE_VERSION ? Number(process.env.YARGS_MIN_NODE_VERSION) : 20;
const nodeVersion = (_b = (_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node) !== null && _b !== void 0 ? _b : (_c = process === null || process === void 0 ? void 0 : process.version) === null || _c === void 0 ? void 0 : _c.slice(1);
if (nodeVersion) {
if (Number(nodeVersion.match(/^([^.]+)/)[1]) < minNodeVersion) throw Error(`yargs parser supports a minimum Node.js version of ${minNodeVersion}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`);
}
const env = process ? process.env : {};
const require = createRequire ? createRequire(import.meta.url) : void 0;
const parser = new YargsParser({
cwd: process.cwd,
env: () => {
return env;
},
format: format$1,
normalize,
resolve,
require: (e) => {
if (typeof require !== "undefined") return require(e);
else if (e.match(/\.json$/)) return JSON.parse(readFileSync(e, "utf8"));
else throw Error("only .json config files are supported in ESM");
}
});
const yargsParser = function Parser(e, t) {
return parser.parse(e.slice(), t).argv;
};
yargsParser.detailed = function(e, t) {
return parser.parse(e.slice(), t);
};
yargsParser.camelCase = camelCase;
yargsParser.decamelize = decamelize;
yargsParser.looksLikeNumber = looksLikeNumber;
//#endregion
//#region extensions/browser/src/browser/chrome-mcp-options.ts
const DEFAULT_CHROME_MCP_FEATURE_ARGS = ["--no-usage-statistics", "--experimentalStructuredContent"];
const CHROME_MCP_USAGE_STATISTICS_FLAG_RE = /^--(?:no-)?usage-?statistics(?:=.*)?$/i;
function normalizeChromeMcpOptions(e) {
if (typeof e === "object" && e && "command" in e && "args" in e) return e;
const t = e ?? {};
const n = normalizeOptionalString(t.mcpCommand);
const r = n === "npx" ? void 0 : n;
const i = Array.isArray(t.mcpArgs) ? t.mcpArgs.filter(hasNonEmptyString) : [];
const { argv: a, error: o } = yargsParser.detailed(i, {
alias: {
browserUrl: "u",
wsEndpoint: "w"
},
string: [
"browserUrl",
"wsEndpoint",
"userDataDir"
],
boolean: ["autoConnect"],
configuration: {
"strip-aliased": true,
"strip-dashed": true
}
});
const s = a.wsEndpoint ?? a.browserUrl;
if (o || a.browserUrl !== void 0 && a.wsEndpoint !== void 0 || s !== void 0 && (typeof s !== "string" || !URL.canParse(s)) || a.autoConnect !== void 0 && typeof a.autoConnect !== "boolean") throw new BrowserProfileUnavailableError("Chrome MCP endpoint arguments must select one valid browserUrl or wsEndpoint URL. Remove duplicate, conflicting, or empty endpoint arguments from mcpArgs.");
if (typeof s === "string" && !(a.wsEndpoint !== void 0 ? /^wss?:$/ : /^https?:$/).test(new URL(s).protocol)) throw new BrowserProfileUnavailableError("Chrome MCP endpoint arguments require http(s) for browserUrl or ws(s) for wsEndpoint.");
const c = s !== void 0 || a.autoConnect !== void 0;
const l = c ? typeof s === "string" ? s : void 0 : normalizeOptionalString(t.cdpUrl);
const u = normalizeOptionalString(t.userDataDir);
const d = c ? [] : l ? [/^wss?:\/\//i.test(l) ? "--wsEndpoint" : "--browserUrl", l] : ["--autoConnect"];
const f = i.some((e) => CHROME_MCP_USAGE_STATISTICS_FLAG_RE.test(e)) ? DEFAULT_CHROME_MCP_FEATURE_ARGS.filter((e) => e !== "--no-usage-statistics") : DEFAULT_CHROME_MCP_FEATURE_ARGS;
const p = [...d, ...f];
const m = [...!c && !l && u && a.userDataDir === void 0 ? ["--userDataDir", u] : [], ...i];
if (r !== void 0) return {
command: r,
env: void 0,
userDataDir: u,
browserUrl: l,
args: [
...p,
"--experimental-page-id-routing",
...m
]
};
return {
command: process.execPath,
env: { CHROME_DEVTOOLS_MCP_NO_UPDATE_CHECKS: "1" },
userDataDir: u,
browserUrl: l,
args: [
fileURLToPath(resolveRuntimeDependencyEntrypointUrl("chromeDevtoolsMcp", import.meta.url)),
"--experimentalVision",
...p,
...m
]
};
}
function buildChromeMcpSessionCacheKey(e, t) {
return JSON.stringify([
e,
t.userDataDir ?? "",
t.browserUrl ?? "",
t.command,
t.args
]);
}
//#endregion
export { normalizeChromeMcpOptions as n, buildChromeMcpSessionCacheKey as t };