@khal-os/cli 1.0.5 → 1.0.7
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/index.js +1344 -2003
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1886,1307 +1886,818 @@ var require_commander = __commonJS((exports) => {
|
|
|
1886
1886
|
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
1887
1887
|
});
|
|
1888
1888
|
|
|
1889
|
-
//
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
close: `\x1B[${style[1]}m`
|
|
1897
|
-
};
|
|
1898
|
-
group[styleName] = styles[styleName];
|
|
1899
|
-
codes.set(style[0], style[1]);
|
|
1900
|
-
}
|
|
1901
|
-
Object.defineProperty(styles, groupName, {
|
|
1902
|
-
value: group,
|
|
1903
|
-
enumerable: false
|
|
1904
|
-
});
|
|
1889
|
+
// src/lib/instances.ts
|
|
1890
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
1891
|
+
import { join } from "node:path";
|
|
1892
|
+
function getInstancesDir() {
|
|
1893
|
+
const dir = join(getConfigDir(), "instances");
|
|
1894
|
+
if (!existsSync(dir)) {
|
|
1895
|
+
mkdirSync(dir, { recursive: true });
|
|
1905
1896
|
}
|
|
1906
|
-
|
|
1907
|
-
value: codes,
|
|
1908
|
-
enumerable: false
|
|
1909
|
-
});
|
|
1910
|
-
styles.color.close = "\x1B[39m";
|
|
1911
|
-
styles.bgColor.close = "\x1B[49m";
|
|
1912
|
-
styles.color.ansi = wrapAnsi16();
|
|
1913
|
-
styles.color.ansi256 = wrapAnsi256();
|
|
1914
|
-
styles.color.ansi16m = wrapAnsi16m();
|
|
1915
|
-
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
1916
|
-
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
1917
|
-
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
1918
|
-
Object.defineProperties(styles, {
|
|
1919
|
-
rgbToAnsi256: {
|
|
1920
|
-
value(red, green, blue) {
|
|
1921
|
-
if (red === green && green === blue) {
|
|
1922
|
-
if (red < 8) {
|
|
1923
|
-
return 16;
|
|
1924
|
-
}
|
|
1925
|
-
if (red > 248) {
|
|
1926
|
-
return 231;
|
|
1927
|
-
}
|
|
1928
|
-
return Math.round((red - 8) / 247 * 24) + 232;
|
|
1929
|
-
}
|
|
1930
|
-
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
1931
|
-
},
|
|
1932
|
-
enumerable: false
|
|
1933
|
-
},
|
|
1934
|
-
hexToRgb: {
|
|
1935
|
-
value(hex) {
|
|
1936
|
-
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
1937
|
-
if (!matches) {
|
|
1938
|
-
return [0, 0, 0];
|
|
1939
|
-
}
|
|
1940
|
-
let [colorString] = matches;
|
|
1941
|
-
if (colorString.length === 3) {
|
|
1942
|
-
colorString = [...colorString].map((character) => character + character).join("");
|
|
1943
|
-
}
|
|
1944
|
-
const integer = Number.parseInt(colorString, 16);
|
|
1945
|
-
return [
|
|
1946
|
-
integer >> 16 & 255,
|
|
1947
|
-
integer >> 8 & 255,
|
|
1948
|
-
integer & 255
|
|
1949
|
-
];
|
|
1950
|
-
},
|
|
1951
|
-
enumerable: false
|
|
1952
|
-
},
|
|
1953
|
-
hexToAnsi256: {
|
|
1954
|
-
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
1955
|
-
enumerable: false
|
|
1956
|
-
},
|
|
1957
|
-
ansi256ToAnsi: {
|
|
1958
|
-
value(code) {
|
|
1959
|
-
if (code < 8) {
|
|
1960
|
-
return 30 + code;
|
|
1961
|
-
}
|
|
1962
|
-
if (code < 16) {
|
|
1963
|
-
return 90 + (code - 8);
|
|
1964
|
-
}
|
|
1965
|
-
let red;
|
|
1966
|
-
let green;
|
|
1967
|
-
let blue;
|
|
1968
|
-
if (code >= 232) {
|
|
1969
|
-
red = ((code - 232) * 10 + 8) / 255;
|
|
1970
|
-
green = red;
|
|
1971
|
-
blue = red;
|
|
1972
|
-
} else {
|
|
1973
|
-
code -= 16;
|
|
1974
|
-
const remainder = code % 36;
|
|
1975
|
-
red = Math.floor(code / 36) / 5;
|
|
1976
|
-
green = Math.floor(remainder / 6) / 5;
|
|
1977
|
-
blue = remainder % 6 / 5;
|
|
1978
|
-
}
|
|
1979
|
-
const value = Math.max(red, green, blue) * 2;
|
|
1980
|
-
if (value === 0) {
|
|
1981
|
-
return 30;
|
|
1982
|
-
}
|
|
1983
|
-
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
1984
|
-
if (value === 2) {
|
|
1985
|
-
result += 60;
|
|
1986
|
-
}
|
|
1987
|
-
return result;
|
|
1988
|
-
},
|
|
1989
|
-
enumerable: false
|
|
1990
|
-
},
|
|
1991
|
-
rgbToAnsi: {
|
|
1992
|
-
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
1993
|
-
enumerable: false
|
|
1994
|
-
},
|
|
1995
|
-
hexToAnsi: {
|
|
1996
|
-
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
1997
|
-
enumerable: false
|
|
1998
|
-
}
|
|
1999
|
-
});
|
|
2000
|
-
return styles;
|
|
1897
|
+
return dir;
|
|
2001
1898
|
}
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
hidden: [8, 28],
|
|
2014
|
-
strikethrough: [9, 29]
|
|
2015
|
-
},
|
|
2016
|
-
color: {
|
|
2017
|
-
black: [30, 39],
|
|
2018
|
-
red: [31, 39],
|
|
2019
|
-
green: [32, 39],
|
|
2020
|
-
yellow: [33, 39],
|
|
2021
|
-
blue: [34, 39],
|
|
2022
|
-
magenta: [35, 39],
|
|
2023
|
-
cyan: [36, 39],
|
|
2024
|
-
white: [37, 39],
|
|
2025
|
-
blackBright: [90, 39],
|
|
2026
|
-
gray: [90, 39],
|
|
2027
|
-
grey: [90, 39],
|
|
2028
|
-
redBright: [91, 39],
|
|
2029
|
-
greenBright: [92, 39],
|
|
2030
|
-
yellowBright: [93, 39],
|
|
2031
|
-
blueBright: [94, 39],
|
|
2032
|
-
magentaBright: [95, 39],
|
|
2033
|
-
cyanBright: [96, 39],
|
|
2034
|
-
whiteBright: [97, 39]
|
|
2035
|
-
},
|
|
2036
|
-
bgColor: {
|
|
2037
|
-
bgBlack: [40, 49],
|
|
2038
|
-
bgRed: [41, 49],
|
|
2039
|
-
bgGreen: [42, 49],
|
|
2040
|
-
bgYellow: [43, 49],
|
|
2041
|
-
bgBlue: [44, 49],
|
|
2042
|
-
bgMagenta: [45, 49],
|
|
2043
|
-
bgCyan: [46, 49],
|
|
2044
|
-
bgWhite: [47, 49],
|
|
2045
|
-
bgBlackBright: [100, 49],
|
|
2046
|
-
bgGray: [100, 49],
|
|
2047
|
-
bgGrey: [100, 49],
|
|
2048
|
-
bgRedBright: [101, 49],
|
|
2049
|
-
bgGreenBright: [102, 49],
|
|
2050
|
-
bgYellowBright: [103, 49],
|
|
2051
|
-
bgBlueBright: [104, 49],
|
|
2052
|
-
bgMagentaBright: [105, 49],
|
|
2053
|
-
bgCyanBright: [106, 49],
|
|
2054
|
-
bgWhiteBright: [107, 49]
|
|
2055
|
-
}
|
|
2056
|
-
};
|
|
2057
|
-
modifierNames = Object.keys(styles.modifier);
|
|
2058
|
-
foregroundColorNames = Object.keys(styles.color);
|
|
2059
|
-
backgroundColorNames = Object.keys(styles.bgColor);
|
|
2060
|
-
colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
2061
|
-
ansiStyles = assembleStyles();
|
|
2062
|
-
ansi_styles_default = ansiStyles;
|
|
2063
|
-
});
|
|
2064
|
-
|
|
2065
|
-
// ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js
|
|
2066
|
-
import process2 from "node:process";
|
|
2067
|
-
import os from "node:os";
|
|
2068
|
-
import tty from "node:tty";
|
|
2069
|
-
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.argv) {
|
|
2070
|
-
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
2071
|
-
const position = argv.indexOf(prefix + flag);
|
|
2072
|
-
const terminatorPosition = argv.indexOf("--");
|
|
2073
|
-
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
1899
|
+
function listInstances() {
|
|
1900
|
+
const dir = getInstancesDir();
|
|
1901
|
+
const files = readdirSync(dir).filter((f) => f.endsWith(".json"));
|
|
1902
|
+
const instances = [];
|
|
1903
|
+
for (const file of files) {
|
|
1904
|
+
try {
|
|
1905
|
+
const raw = readFileSync(join(dir, file), "utf-8");
|
|
1906
|
+
instances.push(JSON.parse(raw));
|
|
1907
|
+
} catch {}
|
|
1908
|
+
}
|
|
1909
|
+
return instances;
|
|
2074
1910
|
}
|
|
2075
|
-
function
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
1911
|
+
function getInstance(name) {
|
|
1912
|
+
const filePath = join(getInstancesDir(), `${name}.json`);
|
|
1913
|
+
if (!existsSync(filePath))
|
|
1914
|
+
return null;
|
|
1915
|
+
try {
|
|
1916
|
+
return JSON.parse(readFileSync(filePath, "utf-8"));
|
|
1917
|
+
} catch {
|
|
1918
|
+
return null;
|
|
2084
1919
|
}
|
|
2085
1920
|
}
|
|
2086
|
-
function
|
|
2087
|
-
|
|
1921
|
+
function saveInstance(config) {
|
|
1922
|
+
const filePath = join(getInstancesDir(), `${config.name}.json`);
|
|
1923
|
+
writeFileSync(filePath, `${JSON.stringify(config, null, 2)}
|
|
1924
|
+
`, "utf-8");
|
|
1925
|
+
}
|
|
1926
|
+
function removeInstance(name) {
|
|
1927
|
+
const filePath = join(getInstancesDir(), `${name}.json`);
|
|
1928
|
+
if (!existsSync(filePath))
|
|
2088
1929
|
return false;
|
|
2089
|
-
|
|
2090
|
-
return
|
|
2091
|
-
level,
|
|
2092
|
-
hasBasic: true,
|
|
2093
|
-
has256: level >= 2,
|
|
2094
|
-
has16m: level >= 3
|
|
2095
|
-
};
|
|
1930
|
+
rmSync(filePath);
|
|
1931
|
+
return true;
|
|
2096
1932
|
}
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
return min;
|
|
1933
|
+
var PROVIDERS;
|
|
1934
|
+
var init_instances = __esm(() => {
|
|
1935
|
+
init_config();
|
|
1936
|
+
PROVIDERS = ["local", "k3s", "oci", "docker"];
|
|
1937
|
+
});
|
|
1938
|
+
|
|
1939
|
+
// src/lib/config.ts
|
|
1940
|
+
var exports_config = {};
|
|
1941
|
+
__export(exports_config, {
|
|
1942
|
+
setActiveInstance: () => setActiveInstance,
|
|
1943
|
+
saveCredential: () => saveCredential,
|
|
1944
|
+
resolveInstance: () => resolveInstance,
|
|
1945
|
+
removeCredential: () => removeCredential,
|
|
1946
|
+
readCredentials: () => readCredentials,
|
|
1947
|
+
getCredentialForInstance: () => getCredentialForInstance,
|
|
1948
|
+
getConfigDir: () => getConfigDir,
|
|
1949
|
+
getActiveInstance: () => getActiveInstance
|
|
1950
|
+
});
|
|
1951
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
1952
|
+
import { homedir } from "node:os";
|
|
1953
|
+
import { join as join2 } from "node:path";
|
|
1954
|
+
function getConfigDir() {
|
|
1955
|
+
const dir = join2(homedir(), CONFIG_DIR_NAME);
|
|
1956
|
+
if (!existsSync2(dir)) {
|
|
1957
|
+
mkdirSync2(dir, { recursive: true });
|
|
2123
1958
|
}
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
1959
|
+
return dir;
|
|
1960
|
+
}
|
|
1961
|
+
function configPath() {
|
|
1962
|
+
return join2(getConfigDir(), CONFIG_FILE);
|
|
1963
|
+
}
|
|
1964
|
+
function credentialsPath() {
|
|
1965
|
+
return join2(getConfigDir(), CREDENTIALS_FILE);
|
|
1966
|
+
}
|
|
1967
|
+
function readJson(path, fallback) {
|
|
1968
|
+
if (!existsSync2(path))
|
|
1969
|
+
return fallback;
|
|
1970
|
+
try {
|
|
1971
|
+
return JSON.parse(readFileSync2(path, "utf-8"));
|
|
1972
|
+
} catch {
|
|
1973
|
+
return fallback;
|
|
2130
1974
|
}
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
1975
|
+
}
|
|
1976
|
+
function writeJson(path, data) {
|
|
1977
|
+
writeFileSync2(path, `${JSON.stringify(data, null, 2)}
|
|
1978
|
+
`, "utf-8");
|
|
1979
|
+
}
|
|
1980
|
+
function readCredentials() {
|
|
1981
|
+
return readJson(credentialsPath(), {});
|
|
1982
|
+
}
|
|
1983
|
+
function saveCredential(instanceUrl, token, type) {
|
|
1984
|
+
const creds = readCredentials();
|
|
1985
|
+
creds[instanceUrl] = { token, type };
|
|
1986
|
+
writeJson(credentialsPath(), creds);
|
|
1987
|
+
}
|
|
1988
|
+
function removeCredential(instanceUrl) {
|
|
1989
|
+
const creds = readCredentials();
|
|
1990
|
+
delete creds[instanceUrl];
|
|
1991
|
+
writeJson(credentialsPath(), creds);
|
|
1992
|
+
}
|
|
1993
|
+
function getCredentialForInstance(instanceUrl) {
|
|
1994
|
+
const creds = readCredentials();
|
|
1995
|
+
return creds[instanceUrl] ?? null;
|
|
1996
|
+
}
|
|
1997
|
+
function getActiveInstance() {
|
|
1998
|
+
const cfg = readJson(configPath(), { activeInstance: DEFAULT_INSTANCE });
|
|
1999
|
+
return cfg.activeInstance;
|
|
2000
|
+
}
|
|
2001
|
+
function setActiveInstance(url) {
|
|
2002
|
+
const cfg = readJson(configPath(), { activeInstance: DEFAULT_INSTANCE });
|
|
2003
|
+
cfg.activeInstance = url;
|
|
2004
|
+
writeJson(configPath(), cfg);
|
|
2005
|
+
}
|
|
2006
|
+
function resolveInstance(flagValue) {
|
|
2007
|
+
if (flagValue) {
|
|
2008
|
+
if (flagValue.startsWith("http://") || flagValue.startsWith("https://"))
|
|
2009
|
+
return flagValue;
|
|
2010
|
+
const inst = getInstance(flagValue);
|
|
2011
|
+
if (inst)
|
|
2012
|
+
return inst.url;
|
|
2013
|
+
return flagValue;
|
|
2014
|
+
}
|
|
2015
|
+
if (process.env.KHAL_INSTANCE)
|
|
2016
|
+
return process.env.KHAL_INSTANCE;
|
|
2017
|
+
return getActiveInstance();
|
|
2018
|
+
}
|
|
2019
|
+
var CONFIG_DIR_NAME = ".khal-os", CONFIG_FILE = "config.json", CREDENTIALS_FILE = "credentials.json", DEFAULT_INSTANCE = "http://localhost:8888";
|
|
2020
|
+
var init_config = __esm(() => {
|
|
2021
|
+
init_instances();
|
|
2022
|
+
});
|
|
2023
|
+
|
|
2024
|
+
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/encoders.js
|
|
2025
|
+
var require_encoders = __commonJS((exports) => {
|
|
2026
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2027
|
+
exports.TD = exports.TE = exports.Empty = undefined;
|
|
2028
|
+
exports.encode = encode;
|
|
2029
|
+
exports.decode = decode;
|
|
2030
|
+
exports.Empty = new Uint8Array(0);
|
|
2031
|
+
exports.TE = new TextEncoder;
|
|
2032
|
+
exports.TD = new TextDecoder;
|
|
2033
|
+
function concat(...bufs) {
|
|
2034
|
+
let max = 0;
|
|
2035
|
+
for (let i = 0;i < bufs.length; i++) {
|
|
2036
|
+
max += bufs[i].length;
|
|
2134
2037
|
}
|
|
2135
|
-
|
|
2136
|
-
|
|
2038
|
+
const out = new Uint8Array(max);
|
|
2039
|
+
let index = 0;
|
|
2040
|
+
for (let i = 0;i < bufs.length; i++) {
|
|
2041
|
+
out.set(bufs[i], index);
|
|
2042
|
+
index += bufs[i].length;
|
|
2137
2043
|
}
|
|
2138
|
-
return
|
|
2139
|
-
}
|
|
2140
|
-
if ("TEAMCITY_VERSION" in env) {
|
|
2141
|
-
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
2142
|
-
}
|
|
2143
|
-
if (env.COLORTERM === "truecolor") {
|
|
2144
|
-
return 3;
|
|
2044
|
+
return out;
|
|
2145
2045
|
}
|
|
2146
|
-
|
|
2147
|
-
|
|
2046
|
+
function encode(...a) {
|
|
2047
|
+
const bufs = [];
|
|
2048
|
+
for (let i = 0;i < a.length; i++) {
|
|
2049
|
+
bufs.push(exports.TE.encode(a[i]));
|
|
2050
|
+
}
|
|
2051
|
+
if (bufs.length === 0) {
|
|
2052
|
+
return exports.Empty;
|
|
2053
|
+
}
|
|
2054
|
+
if (bufs.length === 1) {
|
|
2055
|
+
return bufs[0];
|
|
2056
|
+
}
|
|
2057
|
+
return concat(...bufs);
|
|
2148
2058
|
}
|
|
2149
|
-
|
|
2150
|
-
|
|
2059
|
+
function decode(a) {
|
|
2060
|
+
if (!a || a.length === 0) {
|
|
2061
|
+
return "";
|
|
2062
|
+
}
|
|
2063
|
+
return exports.TD.decode(a);
|
|
2151
2064
|
}
|
|
2152
|
-
|
|
2153
|
-
|
|
2065
|
+
});
|
|
2066
|
+
|
|
2067
|
+
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/errors.js
|
|
2068
|
+
var require_errors = __commonJS((exports) => {
|
|
2069
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2070
|
+
exports.errors = exports.PermissionViolationError = exports.NoRespondersError = exports.TimeoutError = exports.RequestError = exports.ProtocolError = exports.ConnectionError = exports.DrainingConnectionError = exports.ClosedConnectionError = exports.AuthorizationError = exports.UserAuthenticationExpiredError = exports.InvalidOperationError = exports.InvalidArgumentError = exports.InvalidSubjectError = undefined;
|
|
2071
|
+
|
|
2072
|
+
class InvalidSubjectError extends Error {
|
|
2073
|
+
constructor(subject, options) {
|
|
2074
|
+
super(`illegal subject: '${subject}'`, options);
|
|
2075
|
+
this.name = "InvalidSubjectError";
|
|
2076
|
+
}
|
|
2154
2077
|
}
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2078
|
+
exports.InvalidSubjectError = InvalidSubjectError;
|
|
2079
|
+
|
|
2080
|
+
class InvalidArgumentError2 extends Error {
|
|
2081
|
+
constructor(message, options) {
|
|
2082
|
+
super(message, options);
|
|
2083
|
+
this.name = "InvalidArgumentError";
|
|
2084
|
+
}
|
|
2085
|
+
static format(property, message, options) {
|
|
2086
|
+
if (Array.isArray(message) && message.length > 1) {
|
|
2087
|
+
message = message[0];
|
|
2160
2088
|
}
|
|
2161
|
-
|
|
2162
|
-
|
|
2089
|
+
if (Array.isArray(property)) {
|
|
2090
|
+
property = property.map((n) => `'${n}'`);
|
|
2091
|
+
property = property.join(",");
|
|
2092
|
+
} else {
|
|
2093
|
+
property = `'${property}'`;
|
|
2163
2094
|
}
|
|
2095
|
+
return new InvalidArgumentError2(`${property} ${message}`, options);
|
|
2164
2096
|
}
|
|
2165
2097
|
}
|
|
2166
|
-
|
|
2167
|
-
return 2;
|
|
2168
|
-
}
|
|
2169
|
-
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
2170
|
-
return 1;
|
|
2171
|
-
}
|
|
2172
|
-
if ("COLORTERM" in env) {
|
|
2173
|
-
return 1;
|
|
2174
|
-
}
|
|
2175
|
-
return min;
|
|
2176
|
-
}
|
|
2177
|
-
function createSupportsColor(stream, options = {}) {
|
|
2178
|
-
const level = _supportsColor(stream, {
|
|
2179
|
-
streamIsTTY: stream && stream.isTTY,
|
|
2180
|
-
...options
|
|
2181
|
-
});
|
|
2182
|
-
return translateLevel(level);
|
|
2183
|
-
}
|
|
2184
|
-
var env, flagForceColor, supportsColor, supports_color_default;
|
|
2185
|
-
var init_supports_color = __esm(() => {
|
|
2186
|
-
({ env } = process2);
|
|
2187
|
-
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
2188
|
-
flagForceColor = 0;
|
|
2189
|
-
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
2190
|
-
flagForceColor = 1;
|
|
2191
|
-
}
|
|
2192
|
-
supportsColor = {
|
|
2193
|
-
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
2194
|
-
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
|
2195
|
-
};
|
|
2196
|
-
supports_color_default = supportsColor;
|
|
2197
|
-
});
|
|
2098
|
+
exports.InvalidArgumentError = InvalidArgumentError2;
|
|
2198
2099
|
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2100
|
+
class InvalidOperationError extends Error {
|
|
2101
|
+
constructor(message, options) {
|
|
2102
|
+
super(message, options);
|
|
2103
|
+
this.name = "InvalidOperationError";
|
|
2104
|
+
}
|
|
2204
2105
|
}
|
|
2205
|
-
|
|
2206
|
-
let endIndex = 0;
|
|
2207
|
-
let returnValue = "";
|
|
2208
|
-
do {
|
|
2209
|
-
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
2210
|
-
endIndex = index + substringLength;
|
|
2211
|
-
index = string.indexOf(substring, endIndex);
|
|
2212
|
-
} while (index !== -1);
|
|
2213
|
-
returnValue += string.slice(endIndex);
|
|
2214
|
-
return returnValue;
|
|
2215
|
-
}
|
|
2216
|
-
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
2217
|
-
let endIndex = 0;
|
|
2218
|
-
let returnValue = "";
|
|
2219
|
-
do {
|
|
2220
|
-
const gotCR = string[index - 1] === "\r";
|
|
2221
|
-
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? `\r
|
|
2222
|
-
` : `
|
|
2223
|
-
`) + postfix;
|
|
2224
|
-
endIndex = index + 1;
|
|
2225
|
-
index = string.indexOf(`
|
|
2226
|
-
`, endIndex);
|
|
2227
|
-
} while (index !== -1);
|
|
2228
|
-
returnValue += string.slice(endIndex);
|
|
2229
|
-
return returnValue;
|
|
2230
|
-
}
|
|
2106
|
+
exports.InvalidOperationError = InvalidOperationError;
|
|
2231
2107
|
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2108
|
+
class UserAuthenticationExpiredError extends Error {
|
|
2109
|
+
constructor(message, options) {
|
|
2110
|
+
super(message, options);
|
|
2111
|
+
this.name = "UserAuthenticationExpiredError";
|
|
2112
|
+
}
|
|
2113
|
+
static parse(s) {
|
|
2114
|
+
const ss = s.toLowerCase();
|
|
2115
|
+
if (ss.indexOf("user authentication expired") !== -1) {
|
|
2116
|
+
return new UserAuthenticationExpiredError(s);
|
|
2117
|
+
}
|
|
2118
|
+
return null;
|
|
2119
|
+
}
|
|
2239
2120
|
}
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
return chalk;
|
|
2247
|
-
}, getModelAnsi = (model, level, type, ...arguments_) => {
|
|
2248
|
-
if (model === "rgb") {
|
|
2249
|
-
if (level === "ansi16m") {
|
|
2250
|
-
return ansi_styles_default[type].ansi16m(...arguments_);
|
|
2121
|
+
exports.UserAuthenticationExpiredError = UserAuthenticationExpiredError;
|
|
2122
|
+
|
|
2123
|
+
class AuthorizationError extends Error {
|
|
2124
|
+
constructor(message, options) {
|
|
2125
|
+
super(message, options);
|
|
2126
|
+
this.name = "AuthorizationError";
|
|
2251
2127
|
}
|
|
2252
|
-
|
|
2253
|
-
|
|
2128
|
+
static parse(s) {
|
|
2129
|
+
const messages = [
|
|
2130
|
+
"authorization violation",
|
|
2131
|
+
"account authentication expired",
|
|
2132
|
+
"authentication timeout"
|
|
2133
|
+
];
|
|
2134
|
+
const ss = s.toLowerCase();
|
|
2135
|
+
for (let i = 0;i < messages.length; i++) {
|
|
2136
|
+
if (ss.indexOf(messages[i]) !== -1) {
|
|
2137
|
+
return new AuthorizationError(s);
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
return null;
|
|
2254
2141
|
}
|
|
2255
|
-
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
|
|
2256
2142
|
}
|
|
2257
|
-
|
|
2258
|
-
|
|
2143
|
+
exports.AuthorizationError = AuthorizationError;
|
|
2144
|
+
|
|
2145
|
+
class ClosedConnectionError extends Error {
|
|
2146
|
+
constructor() {
|
|
2147
|
+
super("closed connection");
|
|
2148
|
+
this.name = "ClosedConnectionError";
|
|
2149
|
+
}
|
|
2259
2150
|
}
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
} else {
|
|
2268
|
-
openAll = parent.openAll + open;
|
|
2269
|
-
closeAll = close + parent.closeAll;
|
|
2151
|
+
exports.ClosedConnectionError = ClosedConnectionError;
|
|
2152
|
+
|
|
2153
|
+
class DrainingConnectionError extends Error {
|
|
2154
|
+
constructor() {
|
|
2155
|
+
super("connection draining");
|
|
2156
|
+
this.name = "DrainingConnectionError";
|
|
2157
|
+
}
|
|
2270
2158
|
}
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
}, createBuilder = (self2, _styler, _isEmpty) => {
|
|
2279
|
-
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
2280
|
-
Object.setPrototypeOf(builder, proto);
|
|
2281
|
-
builder[GENERATOR] = self2;
|
|
2282
|
-
builder[STYLER] = _styler;
|
|
2283
|
-
builder[IS_EMPTY] = _isEmpty;
|
|
2284
|
-
return builder;
|
|
2285
|
-
}, applyStyle = (self2, string) => {
|
|
2286
|
-
if (self2.level <= 0 || !string) {
|
|
2287
|
-
return self2[IS_EMPTY] ? "" : string;
|
|
2159
|
+
exports.DrainingConnectionError = DrainingConnectionError;
|
|
2160
|
+
|
|
2161
|
+
class ConnectionError extends Error {
|
|
2162
|
+
constructor(message, options) {
|
|
2163
|
+
super(message, options);
|
|
2164
|
+
this.name = "ConnectionError";
|
|
2165
|
+
}
|
|
2288
2166
|
}
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2167
|
+
exports.ConnectionError = ConnectionError;
|
|
2168
|
+
|
|
2169
|
+
class ProtocolError extends Error {
|
|
2170
|
+
constructor(message, options) {
|
|
2171
|
+
super(message, options);
|
|
2172
|
+
this.name = "ProtocolError";
|
|
2173
|
+
}
|
|
2292
2174
|
}
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2175
|
+
exports.ProtocolError = ProtocolError;
|
|
2176
|
+
|
|
2177
|
+
class RequestError extends Error {
|
|
2178
|
+
constructor(message = "", options) {
|
|
2179
|
+
super(message, options);
|
|
2180
|
+
this.name = "RequestError";
|
|
2181
|
+
}
|
|
2182
|
+
isNoResponders() {
|
|
2183
|
+
return this.cause instanceof NoRespondersError;
|
|
2298
2184
|
}
|
|
2299
2185
|
}
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2186
|
+
exports.RequestError = RequestError;
|
|
2187
|
+
|
|
2188
|
+
class TimeoutError extends Error {
|
|
2189
|
+
constructor(options) {
|
|
2190
|
+
super("timeout", options);
|
|
2191
|
+
this.name = "TimeoutError";
|
|
2192
|
+
}
|
|
2304
2193
|
}
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
levelMapping = [
|
|
2315
|
-
"ansi",
|
|
2316
|
-
"ansi",
|
|
2317
|
-
"ansi256",
|
|
2318
|
-
"ansi16m"
|
|
2319
|
-
];
|
|
2320
|
-
styles2 = Object.create(null);
|
|
2321
|
-
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
2322
|
-
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
|
|
2323
|
-
styles2[styleName] = {
|
|
2324
|
-
get() {
|
|
2325
|
-
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
2326
|
-
Object.defineProperty(this, styleName, { value: builder });
|
|
2327
|
-
return builder;
|
|
2328
|
-
}
|
|
2329
|
-
};
|
|
2194
|
+
exports.TimeoutError = TimeoutError;
|
|
2195
|
+
|
|
2196
|
+
class NoRespondersError extends Error {
|
|
2197
|
+
subject;
|
|
2198
|
+
constructor(subject, options) {
|
|
2199
|
+
super(`no responders: '${subject}'`, options);
|
|
2200
|
+
this.subject = subject;
|
|
2201
|
+
this.name = "NoResponders";
|
|
2202
|
+
}
|
|
2330
2203
|
}
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2204
|
+
exports.NoRespondersError = NoRespondersError;
|
|
2205
|
+
|
|
2206
|
+
class PermissionViolationError extends Error {
|
|
2207
|
+
operation;
|
|
2208
|
+
subject;
|
|
2209
|
+
queue;
|
|
2210
|
+
constructor(message, operation, subject, queue, options) {
|
|
2211
|
+
super(message, options);
|
|
2212
|
+
this.name = "PermissionViolationError";
|
|
2213
|
+
this.operation = operation;
|
|
2214
|
+
this.subject = subject;
|
|
2215
|
+
this.queue = queue;
|
|
2336
2216
|
}
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
get() {
|
|
2342
|
-
const { level } = this;
|
|
2343
|
-
return function(...arguments_) {
|
|
2344
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
2345
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
2346
|
-
};
|
|
2347
|
-
}
|
|
2348
|
-
};
|
|
2349
|
-
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
2350
|
-
styles2[bgModel] = {
|
|
2351
|
-
get() {
|
|
2352
|
-
const { level } = this;
|
|
2353
|
-
return function(...arguments_) {
|
|
2354
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
|
2355
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
2356
|
-
};
|
|
2217
|
+
static parse(s) {
|
|
2218
|
+
const t = s ? s.toLowerCase() : "";
|
|
2219
|
+
if (t.indexOf("permissions violation") === -1) {
|
|
2220
|
+
return null;
|
|
2357
2221
|
}
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2222
|
+
let operation = "publish";
|
|
2223
|
+
let subject = "";
|
|
2224
|
+
let queue = undefined;
|
|
2225
|
+
const m = s.match(/(Publish|Subscription) to "(\S+)"/);
|
|
2226
|
+
if (m) {
|
|
2227
|
+
operation = m[1].toLowerCase();
|
|
2228
|
+
subject = m[2];
|
|
2229
|
+
if (operation === "subscription") {
|
|
2230
|
+
const qm = s.match(/using queue "(\S+)"/);
|
|
2231
|
+
if (qm) {
|
|
2232
|
+
queue = qm[1];
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2369
2235
|
}
|
|
2236
|
+
return new PermissionViolationError(s, operation, subject, queue);
|
|
2370
2237
|
}
|
|
2371
|
-
}
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2238
|
+
}
|
|
2239
|
+
exports.PermissionViolationError = PermissionViolationError;
|
|
2240
|
+
exports.errors = {
|
|
2241
|
+
AuthorizationError,
|
|
2242
|
+
ClosedConnectionError,
|
|
2243
|
+
ConnectionError,
|
|
2244
|
+
DrainingConnectionError,
|
|
2245
|
+
InvalidArgumentError: InvalidArgumentError2,
|
|
2246
|
+
InvalidOperationError,
|
|
2247
|
+
InvalidSubjectError,
|
|
2248
|
+
NoRespondersError,
|
|
2249
|
+
PermissionViolationError,
|
|
2250
|
+
ProtocolError,
|
|
2251
|
+
RequestError,
|
|
2252
|
+
TimeoutError,
|
|
2253
|
+
UserAuthenticationExpiredError
|
|
2254
|
+
};
|
|
2376
2255
|
});
|
|
2377
2256
|
|
|
2378
|
-
//
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2257
|
+
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/util.js
|
|
2258
|
+
var require_util = __commonJS((exports) => {
|
|
2259
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2260
|
+
exports.SimpleMutex = exports.Perf = undefined;
|
|
2261
|
+
exports.extend = extend;
|
|
2262
|
+
exports.render = render;
|
|
2263
|
+
exports.timeout = timeout;
|
|
2264
|
+
exports.delay = delay;
|
|
2265
|
+
exports.deadline = deadline;
|
|
2266
|
+
exports.deferred = deferred;
|
|
2267
|
+
exports.debugDeferred = debugDeferred;
|
|
2268
|
+
exports.shuffle = shuffle;
|
|
2269
|
+
exports.collect = collect;
|
|
2270
|
+
exports.jitter = jitter;
|
|
2271
|
+
exports.backoff = backoff;
|
|
2272
|
+
exports.nanos = nanos;
|
|
2273
|
+
exports.millis = millis;
|
|
2274
|
+
var encoders_1 = require_encoders();
|
|
2275
|
+
var errors_1 = require_errors();
|
|
2276
|
+
function extend(a, ...b) {
|
|
2277
|
+
for (let i = 0;i < b.length; i++) {
|
|
2278
|
+
const o = b[i];
|
|
2279
|
+
Object.keys(o).forEach(function(k) {
|
|
2280
|
+
a[k] = o[k];
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
return a;
|
|
2385
2284
|
}
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2285
|
+
function render(frame) {
|
|
2286
|
+
const cr = "␍";
|
|
2287
|
+
const lf = "␊";
|
|
2288
|
+
return encoders_1.TD.decode(frame).replace(/\n/g, lf).replace(/\r/g, cr);
|
|
2289
|
+
}
|
|
2290
|
+
function timeout(ms, asyncTraces = true) {
|
|
2291
|
+
const err = asyncTraces ? new errors_1.TimeoutError : null;
|
|
2292
|
+
let methods;
|
|
2293
|
+
let timer;
|
|
2294
|
+
const p = new Promise((_resolve, reject) => {
|
|
2295
|
+
const cancel = () => {
|
|
2296
|
+
if (timer) {
|
|
2297
|
+
clearTimeout(timer);
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
methods = { cancel };
|
|
2301
|
+
timer = setTimeout(() => {
|
|
2302
|
+
if (err === null) {
|
|
2303
|
+
reject(new errors_1.TimeoutError);
|
|
2304
|
+
} else {
|
|
2305
|
+
reject(err);
|
|
2306
|
+
}
|
|
2307
|
+
}, ms);
|
|
2308
|
+
});
|
|
2309
|
+
return Object.assign(p, methods);
|
|
2310
|
+
}
|
|
2311
|
+
function delay(ms = 0) {
|
|
2312
|
+
let methods;
|
|
2313
|
+
const p = new Promise((resolve) => {
|
|
2314
|
+
const timer = setTimeout(() => {
|
|
2315
|
+
resolve();
|
|
2316
|
+
}, ms);
|
|
2317
|
+
const cancel = () => {
|
|
2318
|
+
if (timer) {
|
|
2319
|
+
clearTimeout(timer);
|
|
2320
|
+
resolve();
|
|
2321
|
+
}
|
|
2322
|
+
};
|
|
2323
|
+
methods = { cancel };
|
|
2324
|
+
});
|
|
2325
|
+
return Object.assign(p, methods);
|
|
2326
|
+
}
|
|
2327
|
+
async function deadline(p, millis2 = 1000) {
|
|
2328
|
+
const d = deferred();
|
|
2329
|
+
const timer = setTimeout(() => {
|
|
2330
|
+
d.reject(new errors_1.TimeoutError);
|
|
2331
|
+
}, millis2);
|
|
2393
2332
|
try {
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2333
|
+
return await Promise.race([p, d]);
|
|
2334
|
+
} finally {
|
|
2335
|
+
clearTimeout(timer);
|
|
2336
|
+
}
|
|
2397
2337
|
}
|
|
2398
|
-
|
|
2399
|
-
}
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
return
|
|
2404
|
-
try {
|
|
2405
|
-
return JSON.parse(readFileSync(filePath, "utf-8"));
|
|
2406
|
-
} catch {
|
|
2407
|
-
return null;
|
|
2338
|
+
function deferred() {
|
|
2339
|
+
let methods = {};
|
|
2340
|
+
const p = new Promise((resolve, reject) => {
|
|
2341
|
+
methods = { resolve, reject };
|
|
2342
|
+
});
|
|
2343
|
+
return Object.assign(p, methods);
|
|
2408
2344
|
}
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
}
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
init_config();
|
|
2425
|
-
PROVIDERS = ["local", "k3s", "oci", "docker"];
|
|
2426
|
-
});
|
|
2427
|
-
|
|
2428
|
-
// src/lib/config.ts
|
|
2429
|
-
var exports_config = {};
|
|
2430
|
-
__export(exports_config, {
|
|
2431
|
-
setActiveInstance: () => setActiveInstance,
|
|
2432
|
-
saveCredential: () => saveCredential,
|
|
2433
|
-
resolveInstance: () => resolveInstance,
|
|
2434
|
-
removeCredential: () => removeCredential,
|
|
2435
|
-
readCredentials: () => readCredentials,
|
|
2436
|
-
getCredentialForInstance: () => getCredentialForInstance,
|
|
2437
|
-
getConfigDir: () => getConfigDir,
|
|
2438
|
-
getActiveInstance: () => getActiveInstance
|
|
2439
|
-
});
|
|
2440
|
-
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
2441
|
-
import { homedir } from "node:os";
|
|
2442
|
-
import { join as join2 } from "node:path";
|
|
2443
|
-
function getConfigDir() {
|
|
2444
|
-
const dir = join2(homedir(), CONFIG_DIR_NAME);
|
|
2445
|
-
if (!existsSync2(dir)) {
|
|
2446
|
-
mkdirSync2(dir, { recursive: true });
|
|
2447
|
-
}
|
|
2448
|
-
return dir;
|
|
2449
|
-
}
|
|
2450
|
-
function configPath() {
|
|
2451
|
-
return join2(getConfigDir(), CONFIG_FILE);
|
|
2452
|
-
}
|
|
2453
|
-
function credentialsPath() {
|
|
2454
|
-
return join2(getConfigDir(), CREDENTIALS_FILE);
|
|
2455
|
-
}
|
|
2456
|
-
function readJson(path, fallback) {
|
|
2457
|
-
if (!existsSync2(path))
|
|
2458
|
-
return fallback;
|
|
2459
|
-
try {
|
|
2460
|
-
return JSON.parse(readFileSync2(path, "utf-8"));
|
|
2461
|
-
} catch {
|
|
2462
|
-
return fallback;
|
|
2463
|
-
}
|
|
2464
|
-
}
|
|
2465
|
-
function writeJson(path, data) {
|
|
2466
|
-
writeFileSync2(path, `${JSON.stringify(data, null, 2)}
|
|
2467
|
-
`, "utf-8");
|
|
2468
|
-
}
|
|
2469
|
-
function readCredentials() {
|
|
2470
|
-
return readJson(credentialsPath(), {});
|
|
2471
|
-
}
|
|
2472
|
-
function saveCredential(instanceUrl, token, type) {
|
|
2473
|
-
const creds = readCredentials();
|
|
2474
|
-
creds[instanceUrl] = { token, type };
|
|
2475
|
-
writeJson(credentialsPath(), creds);
|
|
2476
|
-
}
|
|
2477
|
-
function removeCredential(instanceUrl) {
|
|
2478
|
-
const creds = readCredentials();
|
|
2479
|
-
delete creds[instanceUrl];
|
|
2480
|
-
writeJson(credentialsPath(), creds);
|
|
2481
|
-
}
|
|
2482
|
-
function getCredentialForInstance(instanceUrl) {
|
|
2483
|
-
const creds = readCredentials();
|
|
2484
|
-
return creds[instanceUrl] ?? null;
|
|
2485
|
-
}
|
|
2486
|
-
function getActiveInstance() {
|
|
2487
|
-
const cfg = readJson(configPath(), { activeInstance: DEFAULT_INSTANCE });
|
|
2488
|
-
return cfg.activeInstance;
|
|
2489
|
-
}
|
|
2490
|
-
function setActiveInstance(url) {
|
|
2491
|
-
const cfg = readJson(configPath(), { activeInstance: DEFAULT_INSTANCE });
|
|
2492
|
-
cfg.activeInstance = url;
|
|
2493
|
-
writeJson(configPath(), cfg);
|
|
2494
|
-
}
|
|
2495
|
-
function resolveInstance(flagValue) {
|
|
2496
|
-
if (flagValue) {
|
|
2497
|
-
if (flagValue.startsWith("http://") || flagValue.startsWith("https://"))
|
|
2498
|
-
return flagValue;
|
|
2499
|
-
const inst = getInstance(flagValue);
|
|
2500
|
-
if (inst)
|
|
2501
|
-
return inst.url;
|
|
2502
|
-
return flagValue;
|
|
2503
|
-
}
|
|
2504
|
-
if (process.env.KHAL_INSTANCE)
|
|
2505
|
-
return process.env.KHAL_INSTANCE;
|
|
2506
|
-
return getActiveInstance();
|
|
2507
|
-
}
|
|
2508
|
-
var CONFIG_DIR_NAME = ".khal-os", CONFIG_FILE = "config.json", CREDENTIALS_FILE = "credentials.json", DEFAULT_INSTANCE = "http://localhost:8888";
|
|
2509
|
-
var init_config = __esm(() => {
|
|
2510
|
-
init_instances();
|
|
2511
|
-
});
|
|
2512
|
-
|
|
2513
|
-
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/encoders.js
|
|
2514
|
-
var require_encoders = __commonJS((exports) => {
|
|
2515
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2516
|
-
exports.TD = exports.TE = exports.Empty = undefined;
|
|
2517
|
-
exports.encode = encode;
|
|
2518
|
-
exports.decode = decode;
|
|
2519
|
-
exports.Empty = new Uint8Array(0);
|
|
2520
|
-
exports.TE = new TextEncoder;
|
|
2521
|
-
exports.TD = new TextDecoder;
|
|
2522
|
-
function concat(...bufs) {
|
|
2523
|
-
let max = 0;
|
|
2524
|
-
for (let i = 0;i < bufs.length; i++) {
|
|
2525
|
-
max += bufs[i].length;
|
|
2526
|
-
}
|
|
2527
|
-
const out = new Uint8Array(max);
|
|
2528
|
-
let index = 0;
|
|
2529
|
-
for (let i = 0;i < bufs.length; i++) {
|
|
2530
|
-
out.set(bufs[i], index);
|
|
2531
|
-
index += bufs[i].length;
|
|
2532
|
-
}
|
|
2533
|
-
return out;
|
|
2345
|
+
function debugDeferred() {
|
|
2346
|
+
let methods = {};
|
|
2347
|
+
const p = new Promise((resolve, reject) => {
|
|
2348
|
+
methods = {
|
|
2349
|
+
resolve: (v) => {
|
|
2350
|
+
console.trace("resolve", v);
|
|
2351
|
+
resolve(v);
|
|
2352
|
+
},
|
|
2353
|
+
reject: (err) => {
|
|
2354
|
+
console.trace("reject");
|
|
2355
|
+
reject(err);
|
|
2356
|
+
}
|
|
2357
|
+
};
|
|
2358
|
+
});
|
|
2359
|
+
return Object.assign(p, methods);
|
|
2534
2360
|
}
|
|
2535
|
-
function
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
}
|
|
2540
|
-
if (bufs.length === 0) {
|
|
2541
|
-
return exports.Empty;
|
|
2542
|
-
}
|
|
2543
|
-
if (bufs.length === 1) {
|
|
2544
|
-
return bufs[0];
|
|
2361
|
+
function shuffle(a) {
|
|
2362
|
+
for (let i = a.length - 1;i > 0; i--) {
|
|
2363
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
2364
|
+
[a[i], a[j]] = [a[j], a[i]];
|
|
2545
2365
|
}
|
|
2546
|
-
return
|
|
2366
|
+
return a;
|
|
2547
2367
|
}
|
|
2548
|
-
function
|
|
2549
|
-
|
|
2550
|
-
|
|
2368
|
+
async function collect(iter) {
|
|
2369
|
+
const buf = [];
|
|
2370
|
+
for await (const v of iter) {
|
|
2371
|
+
buf.push(v);
|
|
2551
2372
|
}
|
|
2552
|
-
return
|
|
2373
|
+
return buf;
|
|
2553
2374
|
}
|
|
2554
|
-
});
|
|
2555
|
-
|
|
2556
|
-
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/errors.js
|
|
2557
|
-
var require_errors = __commonJS((exports) => {
|
|
2558
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2559
|
-
exports.errors = exports.PermissionViolationError = exports.NoRespondersError = exports.TimeoutError = exports.RequestError = exports.ProtocolError = exports.ConnectionError = exports.DrainingConnectionError = exports.ClosedConnectionError = exports.AuthorizationError = exports.UserAuthenticationExpiredError = exports.InvalidOperationError = exports.InvalidArgumentError = exports.InvalidSubjectError = undefined;
|
|
2560
2375
|
|
|
2561
|
-
class
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2376
|
+
class Perf {
|
|
2377
|
+
timers;
|
|
2378
|
+
measures;
|
|
2379
|
+
constructor() {
|
|
2380
|
+
this.timers = new Map;
|
|
2381
|
+
this.measures = new Map;
|
|
2565
2382
|
}
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
class InvalidArgumentError2 extends Error {
|
|
2570
|
-
constructor(message, options) {
|
|
2571
|
-
super(message, options);
|
|
2572
|
-
this.name = "InvalidArgumentError";
|
|
2383
|
+
mark(key) {
|
|
2384
|
+
this.timers.set(key, performance.now());
|
|
2573
2385
|
}
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2386
|
+
measure(key, startKey, endKey) {
|
|
2387
|
+
const s = this.timers.get(startKey);
|
|
2388
|
+
if (s === undefined) {
|
|
2389
|
+
throw new Error(`${startKey} is not defined`);
|
|
2577
2390
|
}
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
} else {
|
|
2582
|
-
property = `'${property}'`;
|
|
2391
|
+
const e = this.timers.get(endKey);
|
|
2392
|
+
if (e === undefined) {
|
|
2393
|
+
throw new Error(`${endKey} is not defined`);
|
|
2583
2394
|
}
|
|
2584
|
-
|
|
2395
|
+
this.measures.set(key, e - s);
|
|
2585
2396
|
}
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
this.name = "InvalidOperationError";
|
|
2397
|
+
getEntries() {
|
|
2398
|
+
const values = [];
|
|
2399
|
+
this.measures.forEach((v, k) => {
|
|
2400
|
+
values.push({ name: k, duration: v });
|
|
2401
|
+
});
|
|
2402
|
+
return values;
|
|
2593
2403
|
}
|
|
2594
2404
|
}
|
|
2595
|
-
exports.
|
|
2405
|
+
exports.Perf = Perf;
|
|
2596
2406
|
|
|
2597
|
-
class
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2407
|
+
class SimpleMutex {
|
|
2408
|
+
max;
|
|
2409
|
+
current;
|
|
2410
|
+
waiting;
|
|
2411
|
+
constructor(max = 1) {
|
|
2412
|
+
this.max = max;
|
|
2413
|
+
this.current = 0;
|
|
2414
|
+
this.waiting = [];
|
|
2601
2415
|
}
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
if (
|
|
2605
|
-
return
|
|
2416
|
+
lock() {
|
|
2417
|
+
this.current++;
|
|
2418
|
+
if (this.current <= this.max) {
|
|
2419
|
+
return Promise.resolve();
|
|
2606
2420
|
}
|
|
2607
|
-
|
|
2421
|
+
const d = deferred();
|
|
2422
|
+
this.waiting.push(d);
|
|
2423
|
+
return d;
|
|
2608
2424
|
}
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
constructor(message, options) {
|
|
2614
|
-
super(message, options);
|
|
2615
|
-
this.name = "AuthorizationError";
|
|
2616
|
-
}
|
|
2617
|
-
static parse(s) {
|
|
2618
|
-
const messages = [
|
|
2619
|
-
"authorization violation",
|
|
2620
|
-
"account authentication expired",
|
|
2621
|
-
"authentication timeout"
|
|
2622
|
-
];
|
|
2623
|
-
const ss = s.toLowerCase();
|
|
2624
|
-
for (let i = 0;i < messages.length; i++) {
|
|
2625
|
-
if (ss.indexOf(messages[i]) !== -1) {
|
|
2626
|
-
return new AuthorizationError(s);
|
|
2627
|
-
}
|
|
2628
|
-
}
|
|
2629
|
-
return null;
|
|
2425
|
+
unlock() {
|
|
2426
|
+
this.current--;
|
|
2427
|
+
const d = this.waiting.pop();
|
|
2428
|
+
d?.resolve();
|
|
2630
2429
|
}
|
|
2631
2430
|
}
|
|
2632
|
-
exports.
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
super("closed connection");
|
|
2637
|
-
this.name = "ClosedConnectionError";
|
|
2431
|
+
exports.SimpleMutex = SimpleMutex;
|
|
2432
|
+
function jitter(n) {
|
|
2433
|
+
if (n === 0) {
|
|
2434
|
+
return 0;
|
|
2638
2435
|
}
|
|
2436
|
+
return Math.floor(n / 2 + Math.random() * n);
|
|
2639
2437
|
}
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
constructor() {
|
|
2644
|
-
super("connection draining");
|
|
2645
|
-
this.name = "DrainingConnectionError";
|
|
2438
|
+
function backoff(policy = [0, 250, 250, 500, 500, 3000, 5000]) {
|
|
2439
|
+
if (!Array.isArray(policy)) {
|
|
2440
|
+
policy = [0, 250, 250, 500, 500, 3000, 5000];
|
|
2646
2441
|
}
|
|
2442
|
+
const max = policy.length - 1;
|
|
2443
|
+
return {
|
|
2444
|
+
backoff(attempt) {
|
|
2445
|
+
return jitter(attempt > max ? policy[max] : policy[attempt]);
|
|
2446
|
+
}
|
|
2447
|
+
};
|
|
2647
2448
|
}
|
|
2648
|
-
|
|
2449
|
+
function nanos(millis2) {
|
|
2450
|
+
return millis2 * 1e6;
|
|
2451
|
+
}
|
|
2452
|
+
function millis(ns) {
|
|
2453
|
+
return Math.floor(ns / 1e6);
|
|
2454
|
+
}
|
|
2455
|
+
});
|
|
2649
2456
|
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2457
|
+
// ../../node_modules/.pnpm/@nats-io+nuid@2.0.3/node_modules/@nats-io/nuid/lib/nuid.js
|
|
2458
|
+
var require_nuid = __commonJS((exports) => {
|
|
2459
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2460
|
+
exports.nuid = exports.Nuid = undefined;
|
|
2461
|
+
var digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
2462
|
+
var base = 36;
|
|
2463
|
+
var preLen = 12;
|
|
2464
|
+
var seqLen = 10;
|
|
2465
|
+
var maxSeq = 3656158440062976;
|
|
2466
|
+
var minInc = 33;
|
|
2467
|
+
var maxInc = 333;
|
|
2468
|
+
var totalLen = preLen + seqLen;
|
|
2469
|
+
function _getRandomValues(a) {
|
|
2470
|
+
for (let i = 0;i < a.length; i++) {
|
|
2471
|
+
a[i] = Math.floor(Math.random() * 255);
|
|
2654
2472
|
}
|
|
2655
2473
|
}
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
this.name = "ProtocolError";
|
|
2474
|
+
function fillRandom(a) {
|
|
2475
|
+
if (globalThis?.crypto?.getRandomValues) {
|
|
2476
|
+
globalThis.crypto.getRandomValues(a);
|
|
2477
|
+
} else {
|
|
2478
|
+
_getRandomValues(a);
|
|
2662
2479
|
}
|
|
2663
2480
|
}
|
|
2664
|
-
exports.ProtocolError = ProtocolError;
|
|
2665
2481
|
|
|
2666
|
-
class
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2482
|
+
class Nuid {
|
|
2483
|
+
buf;
|
|
2484
|
+
seq;
|
|
2485
|
+
inc;
|
|
2486
|
+
inited;
|
|
2487
|
+
constructor() {
|
|
2488
|
+
this.buf = new Uint8Array(totalLen);
|
|
2489
|
+
this.inited = false;
|
|
2670
2490
|
}
|
|
2671
|
-
|
|
2672
|
-
|
|
2491
|
+
init() {
|
|
2492
|
+
this.inited = true;
|
|
2493
|
+
this.setPre();
|
|
2494
|
+
this.initSeqAndInc();
|
|
2495
|
+
this.fillSeq();
|
|
2673
2496
|
}
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
class TimeoutError extends Error {
|
|
2678
|
-
constructor(options) {
|
|
2679
|
-
super("timeout", options);
|
|
2680
|
-
this.name = "TimeoutError";
|
|
2497
|
+
initSeqAndInc() {
|
|
2498
|
+
this.seq = Math.floor(Math.random() * maxSeq);
|
|
2499
|
+
this.inc = Math.floor(Math.random() * (maxInc - minInc) + minInc);
|
|
2681
2500
|
}
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
this.subject = subject;
|
|
2690
|
-
this.name = "NoResponders";
|
|
2501
|
+
setPre() {
|
|
2502
|
+
const cbuf = new Uint8Array(preLen);
|
|
2503
|
+
fillRandom(cbuf);
|
|
2504
|
+
for (let i = 0;i < preLen; i++) {
|
|
2505
|
+
const di = cbuf[i] % base;
|
|
2506
|
+
this.buf[i] = digits.charCodeAt(di);
|
|
2507
|
+
}
|
|
2691
2508
|
}
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
queue;
|
|
2699
|
-
constructor(message, operation, subject, queue, options) {
|
|
2700
|
-
super(message, options);
|
|
2701
|
-
this.name = "PermissionViolationError";
|
|
2702
|
-
this.operation = operation;
|
|
2703
|
-
this.subject = subject;
|
|
2704
|
-
this.queue = queue;
|
|
2509
|
+
fillSeq() {
|
|
2510
|
+
let n = this.seq;
|
|
2511
|
+
for (let i = totalLen - 1;i >= preLen; i--) {
|
|
2512
|
+
this.buf[i] = digits.charCodeAt(n % base);
|
|
2513
|
+
n = Math.floor(n / base);
|
|
2514
|
+
}
|
|
2705
2515
|
}
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
return null;
|
|
2516
|
+
next() {
|
|
2517
|
+
if (!this.inited) {
|
|
2518
|
+
this.init();
|
|
2710
2519
|
}
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
if (m) {
|
|
2716
|
-
operation = m[1].toLowerCase();
|
|
2717
|
-
subject = m[2];
|
|
2718
|
-
if (operation === "subscription") {
|
|
2719
|
-
const qm = s.match(/using queue "(\S+)"/);
|
|
2720
|
-
if (qm) {
|
|
2721
|
-
queue = qm[1];
|
|
2722
|
-
}
|
|
2723
|
-
}
|
|
2520
|
+
this.seq += this.inc;
|
|
2521
|
+
if (this.seq > maxSeq) {
|
|
2522
|
+
this.setPre();
|
|
2523
|
+
this.initSeqAndInc();
|
|
2724
2524
|
}
|
|
2725
|
-
|
|
2525
|
+
this.fillSeq();
|
|
2526
|
+
return String.fromCharCode.apply(String, this.buf);
|
|
2527
|
+
}
|
|
2528
|
+
reset() {
|
|
2529
|
+
this.init();
|
|
2726
2530
|
}
|
|
2727
2531
|
}
|
|
2728
|
-
exports.
|
|
2729
|
-
exports.
|
|
2730
|
-
AuthorizationError,
|
|
2731
|
-
ClosedConnectionError,
|
|
2732
|
-
ConnectionError,
|
|
2733
|
-
DrainingConnectionError,
|
|
2734
|
-
InvalidArgumentError: InvalidArgumentError2,
|
|
2735
|
-
InvalidOperationError,
|
|
2736
|
-
InvalidSubjectError,
|
|
2737
|
-
NoRespondersError,
|
|
2738
|
-
PermissionViolationError,
|
|
2739
|
-
ProtocolError,
|
|
2740
|
-
RequestError,
|
|
2741
|
-
TimeoutError,
|
|
2742
|
-
UserAuthenticationExpiredError
|
|
2743
|
-
};
|
|
2532
|
+
exports.Nuid = Nuid;
|
|
2533
|
+
exports.nuid = new Nuid;
|
|
2744
2534
|
});
|
|
2745
2535
|
|
|
2746
|
-
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/
|
|
2747
|
-
var
|
|
2536
|
+
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/nuid.js
|
|
2537
|
+
var require_nuid2 = __commonJS((exports) => {
|
|
2748
2538
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2749
|
-
exports.
|
|
2750
|
-
|
|
2751
|
-
exports
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
exports
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
exports
|
|
2762
|
-
exports.
|
|
2763
|
-
|
|
2539
|
+
exports.nuid = exports.Nuid = undefined;
|
|
2540
|
+
var nuid_1 = require_nuid();
|
|
2541
|
+
Object.defineProperty(exports, "Nuid", { enumerable: true, get: function() {
|
|
2542
|
+
return nuid_1.Nuid;
|
|
2543
|
+
} });
|
|
2544
|
+
Object.defineProperty(exports, "nuid", { enumerable: true, get: function() {
|
|
2545
|
+
return nuid_1.nuid;
|
|
2546
|
+
} });
|
|
2547
|
+
});
|
|
2548
|
+
|
|
2549
|
+
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/core.js
|
|
2550
|
+
var require_core = __commonJS((exports) => {
|
|
2551
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2552
|
+
exports.DEFAULT_HOST = exports.DEFAULT_PORT = exports.Match = undefined;
|
|
2553
|
+
exports.syncIterator = syncIterator;
|
|
2554
|
+
exports.createInbox = createInbox;
|
|
2555
|
+
var nuid_1 = require_nuid2();
|
|
2764
2556
|
var errors_1 = require_errors();
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
return
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2557
|
+
exports.Match = {
|
|
2558
|
+
Exact: "exact",
|
|
2559
|
+
CanonicalMIME: "canonical",
|
|
2560
|
+
IgnoreCase: "insensitive"
|
|
2561
|
+
};
|
|
2562
|
+
function syncIterator(src) {
|
|
2563
|
+
const iter = src[Symbol.asyncIterator]();
|
|
2564
|
+
return {
|
|
2565
|
+
async next() {
|
|
2566
|
+
const m = await iter.next();
|
|
2567
|
+
if (m.done) {
|
|
2568
|
+
return Promise.resolve(null);
|
|
2569
|
+
}
|
|
2570
|
+
return Promise.resolve(m.value);
|
|
2571
|
+
}
|
|
2572
|
+
};
|
|
2778
2573
|
}
|
|
2779
|
-
function
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
const p = new Promise((_resolve, reject) => {
|
|
2784
|
-
const cancel = () => {
|
|
2785
|
-
if (timer) {
|
|
2786
|
-
clearTimeout(timer);
|
|
2787
|
-
}
|
|
2788
|
-
};
|
|
2789
|
-
methods = { cancel };
|
|
2790
|
-
timer = setTimeout(() => {
|
|
2791
|
-
if (err === null) {
|
|
2792
|
-
reject(new errors_1.TimeoutError);
|
|
2793
|
-
} else {
|
|
2794
|
-
reject(err);
|
|
2795
|
-
}
|
|
2796
|
-
}, ms);
|
|
2797
|
-
});
|
|
2798
|
-
return Object.assign(p, methods);
|
|
2799
|
-
}
|
|
2800
|
-
function delay(ms = 0) {
|
|
2801
|
-
let methods;
|
|
2802
|
-
const p = new Promise((resolve) => {
|
|
2803
|
-
const timer = setTimeout(() => {
|
|
2804
|
-
resolve();
|
|
2805
|
-
}, ms);
|
|
2806
|
-
const cancel = () => {
|
|
2807
|
-
if (timer) {
|
|
2808
|
-
clearTimeout(timer);
|
|
2809
|
-
resolve();
|
|
2810
|
-
}
|
|
2811
|
-
};
|
|
2812
|
-
methods = { cancel };
|
|
2813
|
-
});
|
|
2814
|
-
return Object.assign(p, methods);
|
|
2815
|
-
}
|
|
2816
|
-
async function deadline(p, millis2 = 1000) {
|
|
2817
|
-
const d = deferred();
|
|
2818
|
-
const timer = setTimeout(() => {
|
|
2819
|
-
d.reject(new errors_1.TimeoutError);
|
|
2820
|
-
}, millis2);
|
|
2821
|
-
try {
|
|
2822
|
-
return await Promise.race([p, d]);
|
|
2823
|
-
} finally {
|
|
2824
|
-
clearTimeout(timer);
|
|
2574
|
+
function createInbox(prefix = "") {
|
|
2575
|
+
prefix = prefix || "_INBOX";
|
|
2576
|
+
if (typeof prefix !== "string") {
|
|
2577
|
+
throw new TypeError("prefix must be a string");
|
|
2825
2578
|
}
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
methods = { resolve, reject };
|
|
2831
|
-
});
|
|
2832
|
-
return Object.assign(p, methods);
|
|
2833
|
-
}
|
|
2834
|
-
function debugDeferred() {
|
|
2835
|
-
let methods = {};
|
|
2836
|
-
const p = new Promise((resolve, reject) => {
|
|
2837
|
-
methods = {
|
|
2838
|
-
resolve: (v) => {
|
|
2839
|
-
console.trace("resolve", v);
|
|
2840
|
-
resolve(v);
|
|
2841
|
-
},
|
|
2842
|
-
reject: (err) => {
|
|
2843
|
-
console.trace("reject");
|
|
2844
|
-
reject(err);
|
|
2845
|
-
}
|
|
2846
|
-
};
|
|
2579
|
+
prefix.split(".").forEach((v) => {
|
|
2580
|
+
if (v === "*" || v === ">") {
|
|
2581
|
+
throw errors_1.InvalidArgumentError.format("prefix", `cannot have wildcards ('${prefix}')`);
|
|
2582
|
+
}
|
|
2847
2583
|
});
|
|
2848
|
-
return
|
|
2849
|
-
}
|
|
2850
|
-
function shuffle(a) {
|
|
2851
|
-
for (let i = a.length - 1;i > 0; i--) {
|
|
2852
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
2853
|
-
[a[i], a[j]] = [a[j], a[i]];
|
|
2854
|
-
}
|
|
2855
|
-
return a;
|
|
2856
|
-
}
|
|
2857
|
-
async function collect(iter) {
|
|
2858
|
-
const buf = [];
|
|
2859
|
-
for await (const v of iter) {
|
|
2860
|
-
buf.push(v);
|
|
2861
|
-
}
|
|
2862
|
-
return buf;
|
|
2584
|
+
return `${prefix}.${nuid_1.nuid.next()}`;
|
|
2863
2585
|
}
|
|
2586
|
+
exports.DEFAULT_PORT = 4222;
|
|
2587
|
+
exports.DEFAULT_HOST = "127.0.0.1";
|
|
2588
|
+
});
|
|
2864
2589
|
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2590
|
+
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/databuffer.js
|
|
2591
|
+
var require_databuffer = __commonJS((exports) => {
|
|
2592
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2593
|
+
exports.DataBuffer = undefined;
|
|
2594
|
+
var encoders_1 = require_encoders();
|
|
2595
|
+
|
|
2596
|
+
class DataBuffer {
|
|
2597
|
+
buffers;
|
|
2598
|
+
byteLength;
|
|
2868
2599
|
constructor() {
|
|
2869
|
-
this.
|
|
2870
|
-
this.
|
|
2871
|
-
}
|
|
2872
|
-
mark(key) {
|
|
2873
|
-
this.timers.set(key, performance.now());
|
|
2600
|
+
this.buffers = [];
|
|
2601
|
+
this.byteLength = 0;
|
|
2874
2602
|
}
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2603
|
+
static concat(...bufs) {
|
|
2604
|
+
let max = 0;
|
|
2605
|
+
for (let i = 0;i < bufs.length; i++) {
|
|
2606
|
+
max += bufs[i].length;
|
|
2879
2607
|
}
|
|
2880
|
-
const
|
|
2881
|
-
|
|
2882
|
-
|
|
2608
|
+
const out = new Uint8Array(max);
|
|
2609
|
+
let index = 0;
|
|
2610
|
+
for (let i = 0;i < bufs.length; i++) {
|
|
2611
|
+
out.set(bufs[i], index);
|
|
2612
|
+
index += bufs[i].length;
|
|
2883
2613
|
}
|
|
2884
|
-
|
|
2614
|
+
return out;
|
|
2885
2615
|
}
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
return values;
|
|
2616
|
+
static fromAscii(m) {
|
|
2617
|
+
if (!m) {
|
|
2618
|
+
m = "";
|
|
2619
|
+
}
|
|
2620
|
+
return encoders_1.TE.encode(m);
|
|
2892
2621
|
}
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
class SimpleMutex {
|
|
2897
|
-
max;
|
|
2898
|
-
current;
|
|
2899
|
-
waiting;
|
|
2900
|
-
constructor(max = 1) {
|
|
2901
|
-
this.max = max;
|
|
2902
|
-
this.current = 0;
|
|
2903
|
-
this.waiting = [];
|
|
2622
|
+
static toAscii(a) {
|
|
2623
|
+
return encoders_1.TD.decode(a);
|
|
2904
2624
|
}
|
|
2905
|
-
|
|
2906
|
-
this.
|
|
2907
|
-
|
|
2908
|
-
|
|
2625
|
+
reset() {
|
|
2626
|
+
this.buffers.length = 0;
|
|
2627
|
+
this.byteLength = 0;
|
|
2628
|
+
}
|
|
2629
|
+
pack() {
|
|
2630
|
+
if (this.buffers.length > 1) {
|
|
2631
|
+
const v = new Uint8Array(this.byteLength);
|
|
2632
|
+
let index = 0;
|
|
2633
|
+
for (let i = 0;i < this.buffers.length; i++) {
|
|
2634
|
+
v.set(this.buffers[i], index);
|
|
2635
|
+
index += this.buffers[i].length;
|
|
2636
|
+
}
|
|
2637
|
+
this.buffers.length = 0;
|
|
2638
|
+
this.buffers.push(v);
|
|
2909
2639
|
}
|
|
2910
|
-
const d = deferred();
|
|
2911
|
-
this.waiting.push(d);
|
|
2912
|
-
return d;
|
|
2913
2640
|
}
|
|
2914
|
-
|
|
2915
|
-
this.
|
|
2916
|
-
|
|
2917
|
-
|
|
2641
|
+
shift() {
|
|
2642
|
+
if (this.buffers.length) {
|
|
2643
|
+
const a = this.buffers.shift();
|
|
2644
|
+
if (a) {
|
|
2645
|
+
this.byteLength -= a.length;
|
|
2646
|
+
return a;
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
return new Uint8Array(0);
|
|
2918
2650
|
}
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2651
|
+
drain(n) {
|
|
2652
|
+
if (this.buffers.length) {
|
|
2653
|
+
this.pack();
|
|
2654
|
+
const v = this.buffers.pop();
|
|
2655
|
+
if (v) {
|
|
2656
|
+
const max = this.byteLength;
|
|
2657
|
+
if (n === undefined || n > max) {
|
|
2658
|
+
n = max;
|
|
2659
|
+
}
|
|
2660
|
+
const d = v.subarray(0, n);
|
|
2661
|
+
if (max > n) {
|
|
2662
|
+
this.buffers.push(v.subarray(n));
|
|
2663
|
+
}
|
|
2664
|
+
this.byteLength = max - n;
|
|
2665
|
+
return d;
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
return new Uint8Array(0);
|
|
2924
2669
|
}
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2670
|
+
fill(a, ...bufs) {
|
|
2671
|
+
if (a) {
|
|
2672
|
+
this.buffers.push(a);
|
|
2673
|
+
this.byteLength += a.length;
|
|
2674
|
+
}
|
|
2675
|
+
for (let i = 0;i < bufs.length; i++) {
|
|
2676
|
+
if (bufs[i] && bufs[i].length) {
|
|
2677
|
+
this.buffers.push(bufs[i]);
|
|
2678
|
+
this.byteLength += bufs[i].length;
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2930
2681
|
}
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
return
|
|
2682
|
+
peek() {
|
|
2683
|
+
if (this.buffers.length) {
|
|
2684
|
+
this.pack();
|
|
2685
|
+
return this.buffers[0];
|
|
2935
2686
|
}
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2687
|
+
return new Uint8Array(0);
|
|
2688
|
+
}
|
|
2689
|
+
size() {
|
|
2690
|
+
return this.byteLength;
|
|
2691
|
+
}
|
|
2692
|
+
length() {
|
|
2693
|
+
return this.buffers.length;
|
|
2694
|
+
}
|
|
2943
2695
|
}
|
|
2696
|
+
exports.DataBuffer = DataBuffer;
|
|
2944
2697
|
});
|
|
2945
2698
|
|
|
2946
|
-
// ../../node_modules/.pnpm/@nats-io+
|
|
2947
|
-
var
|
|
2948
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2949
|
-
exports.nuid = exports.Nuid = undefined;
|
|
2950
|
-
var digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
2951
|
-
var base = 36;
|
|
2952
|
-
var preLen = 12;
|
|
2953
|
-
var seqLen = 10;
|
|
2954
|
-
var maxSeq = 3656158440062976;
|
|
2955
|
-
var minInc = 33;
|
|
2956
|
-
var maxInc = 333;
|
|
2957
|
-
var totalLen = preLen + seqLen;
|
|
2958
|
-
function _getRandomValues(a) {
|
|
2959
|
-
for (let i = 0;i < a.length; i++) {
|
|
2960
|
-
a[i] = Math.floor(Math.random() * 255);
|
|
2961
|
-
}
|
|
2962
|
-
}
|
|
2963
|
-
function fillRandom(a) {
|
|
2964
|
-
if (globalThis?.crypto?.getRandomValues) {
|
|
2965
|
-
globalThis.crypto.getRandomValues(a);
|
|
2966
|
-
} else {
|
|
2967
|
-
_getRandomValues(a);
|
|
2968
|
-
}
|
|
2969
|
-
}
|
|
2970
|
-
|
|
2971
|
-
class Nuid {
|
|
2972
|
-
buf;
|
|
2973
|
-
seq;
|
|
2974
|
-
inc;
|
|
2975
|
-
inited;
|
|
2976
|
-
constructor() {
|
|
2977
|
-
this.buf = new Uint8Array(totalLen);
|
|
2978
|
-
this.inited = false;
|
|
2979
|
-
}
|
|
2980
|
-
init() {
|
|
2981
|
-
this.inited = true;
|
|
2982
|
-
this.setPre();
|
|
2983
|
-
this.initSeqAndInc();
|
|
2984
|
-
this.fillSeq();
|
|
2985
|
-
}
|
|
2986
|
-
initSeqAndInc() {
|
|
2987
|
-
this.seq = Math.floor(Math.random() * maxSeq);
|
|
2988
|
-
this.inc = Math.floor(Math.random() * (maxInc - minInc) + minInc);
|
|
2989
|
-
}
|
|
2990
|
-
setPre() {
|
|
2991
|
-
const cbuf = new Uint8Array(preLen);
|
|
2992
|
-
fillRandom(cbuf);
|
|
2993
|
-
for (let i = 0;i < preLen; i++) {
|
|
2994
|
-
const di = cbuf[i] % base;
|
|
2995
|
-
this.buf[i] = digits.charCodeAt(di);
|
|
2996
|
-
}
|
|
2997
|
-
}
|
|
2998
|
-
fillSeq() {
|
|
2999
|
-
let n = this.seq;
|
|
3000
|
-
for (let i = totalLen - 1;i >= preLen; i--) {
|
|
3001
|
-
this.buf[i] = digits.charCodeAt(n % base);
|
|
3002
|
-
n = Math.floor(n / base);
|
|
3003
|
-
}
|
|
3004
|
-
}
|
|
3005
|
-
next() {
|
|
3006
|
-
if (!this.inited) {
|
|
3007
|
-
this.init();
|
|
3008
|
-
}
|
|
3009
|
-
this.seq += this.inc;
|
|
3010
|
-
if (this.seq > maxSeq) {
|
|
3011
|
-
this.setPre();
|
|
3012
|
-
this.initSeqAndInc();
|
|
3013
|
-
}
|
|
3014
|
-
this.fillSeq();
|
|
3015
|
-
return String.fromCharCode.apply(String, this.buf);
|
|
3016
|
-
}
|
|
3017
|
-
reset() {
|
|
3018
|
-
this.init();
|
|
3019
|
-
}
|
|
3020
|
-
}
|
|
3021
|
-
exports.Nuid = Nuid;
|
|
3022
|
-
exports.nuid = new Nuid;
|
|
3023
|
-
});
|
|
3024
|
-
|
|
3025
|
-
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/nuid.js
|
|
3026
|
-
var require_nuid2 = __commonJS((exports) => {
|
|
3027
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3028
|
-
exports.nuid = exports.Nuid = undefined;
|
|
3029
|
-
var nuid_1 = require_nuid();
|
|
3030
|
-
Object.defineProperty(exports, "Nuid", { enumerable: true, get: function() {
|
|
3031
|
-
return nuid_1.Nuid;
|
|
3032
|
-
} });
|
|
3033
|
-
Object.defineProperty(exports, "nuid", { enumerable: true, get: function() {
|
|
3034
|
-
return nuid_1.nuid;
|
|
3035
|
-
} });
|
|
3036
|
-
});
|
|
3037
|
-
|
|
3038
|
-
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/core.js
|
|
3039
|
-
var require_core = __commonJS((exports) => {
|
|
3040
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3041
|
-
exports.DEFAULT_HOST = exports.DEFAULT_PORT = exports.Match = undefined;
|
|
3042
|
-
exports.syncIterator = syncIterator;
|
|
3043
|
-
exports.createInbox = createInbox;
|
|
3044
|
-
var nuid_1 = require_nuid2();
|
|
3045
|
-
var errors_1 = require_errors();
|
|
3046
|
-
exports.Match = {
|
|
3047
|
-
Exact: "exact",
|
|
3048
|
-
CanonicalMIME: "canonical",
|
|
3049
|
-
IgnoreCase: "insensitive"
|
|
3050
|
-
};
|
|
3051
|
-
function syncIterator(src) {
|
|
3052
|
-
const iter = src[Symbol.asyncIterator]();
|
|
3053
|
-
return {
|
|
3054
|
-
async next() {
|
|
3055
|
-
const m = await iter.next();
|
|
3056
|
-
if (m.done) {
|
|
3057
|
-
return Promise.resolve(null);
|
|
3058
|
-
}
|
|
3059
|
-
return Promise.resolve(m.value);
|
|
3060
|
-
}
|
|
3061
|
-
};
|
|
3062
|
-
}
|
|
3063
|
-
function createInbox(prefix = "") {
|
|
3064
|
-
prefix = prefix || "_INBOX";
|
|
3065
|
-
if (typeof prefix !== "string") {
|
|
3066
|
-
throw new TypeError("prefix must be a string");
|
|
3067
|
-
}
|
|
3068
|
-
prefix.split(".").forEach((v) => {
|
|
3069
|
-
if (v === "*" || v === ">") {
|
|
3070
|
-
throw errors_1.InvalidArgumentError.format("prefix", `cannot have wildcards ('${prefix}')`);
|
|
3071
|
-
}
|
|
3072
|
-
});
|
|
3073
|
-
return `${prefix}.${nuid_1.nuid.next()}`;
|
|
3074
|
-
}
|
|
3075
|
-
exports.DEFAULT_PORT = 4222;
|
|
3076
|
-
exports.DEFAULT_HOST = "127.0.0.1";
|
|
3077
|
-
});
|
|
3078
|
-
|
|
3079
|
-
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/databuffer.js
|
|
3080
|
-
var require_databuffer = __commonJS((exports) => {
|
|
3081
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3082
|
-
exports.DataBuffer = undefined;
|
|
3083
|
-
var encoders_1 = require_encoders();
|
|
3084
|
-
|
|
3085
|
-
class DataBuffer {
|
|
3086
|
-
buffers;
|
|
3087
|
-
byteLength;
|
|
3088
|
-
constructor() {
|
|
3089
|
-
this.buffers = [];
|
|
3090
|
-
this.byteLength = 0;
|
|
3091
|
-
}
|
|
3092
|
-
static concat(...bufs) {
|
|
3093
|
-
let max = 0;
|
|
3094
|
-
for (let i = 0;i < bufs.length; i++) {
|
|
3095
|
-
max += bufs[i].length;
|
|
3096
|
-
}
|
|
3097
|
-
const out = new Uint8Array(max);
|
|
3098
|
-
let index = 0;
|
|
3099
|
-
for (let i = 0;i < bufs.length; i++) {
|
|
3100
|
-
out.set(bufs[i], index);
|
|
3101
|
-
index += bufs[i].length;
|
|
3102
|
-
}
|
|
3103
|
-
return out;
|
|
3104
|
-
}
|
|
3105
|
-
static fromAscii(m) {
|
|
3106
|
-
if (!m) {
|
|
3107
|
-
m = "";
|
|
3108
|
-
}
|
|
3109
|
-
return encoders_1.TE.encode(m);
|
|
3110
|
-
}
|
|
3111
|
-
static toAscii(a) {
|
|
3112
|
-
return encoders_1.TD.decode(a);
|
|
3113
|
-
}
|
|
3114
|
-
reset() {
|
|
3115
|
-
this.buffers.length = 0;
|
|
3116
|
-
this.byteLength = 0;
|
|
3117
|
-
}
|
|
3118
|
-
pack() {
|
|
3119
|
-
if (this.buffers.length > 1) {
|
|
3120
|
-
const v = new Uint8Array(this.byteLength);
|
|
3121
|
-
let index = 0;
|
|
3122
|
-
for (let i = 0;i < this.buffers.length; i++) {
|
|
3123
|
-
v.set(this.buffers[i], index);
|
|
3124
|
-
index += this.buffers[i].length;
|
|
3125
|
-
}
|
|
3126
|
-
this.buffers.length = 0;
|
|
3127
|
-
this.buffers.push(v);
|
|
3128
|
-
}
|
|
3129
|
-
}
|
|
3130
|
-
shift() {
|
|
3131
|
-
if (this.buffers.length) {
|
|
3132
|
-
const a = this.buffers.shift();
|
|
3133
|
-
if (a) {
|
|
3134
|
-
this.byteLength -= a.length;
|
|
3135
|
-
return a;
|
|
3136
|
-
}
|
|
3137
|
-
}
|
|
3138
|
-
return new Uint8Array(0);
|
|
3139
|
-
}
|
|
3140
|
-
drain(n) {
|
|
3141
|
-
if (this.buffers.length) {
|
|
3142
|
-
this.pack();
|
|
3143
|
-
const v = this.buffers.pop();
|
|
3144
|
-
if (v) {
|
|
3145
|
-
const max = this.byteLength;
|
|
3146
|
-
if (n === undefined || n > max) {
|
|
3147
|
-
n = max;
|
|
3148
|
-
}
|
|
3149
|
-
const d = v.subarray(0, n);
|
|
3150
|
-
if (max > n) {
|
|
3151
|
-
this.buffers.push(v.subarray(n));
|
|
3152
|
-
}
|
|
3153
|
-
this.byteLength = max - n;
|
|
3154
|
-
return d;
|
|
3155
|
-
}
|
|
3156
|
-
}
|
|
3157
|
-
return new Uint8Array(0);
|
|
3158
|
-
}
|
|
3159
|
-
fill(a, ...bufs) {
|
|
3160
|
-
if (a) {
|
|
3161
|
-
this.buffers.push(a);
|
|
3162
|
-
this.byteLength += a.length;
|
|
3163
|
-
}
|
|
3164
|
-
for (let i = 0;i < bufs.length; i++) {
|
|
3165
|
-
if (bufs[i] && bufs[i].length) {
|
|
3166
|
-
this.buffers.push(bufs[i]);
|
|
3167
|
-
this.byteLength += bufs[i].length;
|
|
3168
|
-
}
|
|
3169
|
-
}
|
|
3170
|
-
}
|
|
3171
|
-
peek() {
|
|
3172
|
-
if (this.buffers.length) {
|
|
3173
|
-
this.pack();
|
|
3174
|
-
return this.buffers[0];
|
|
3175
|
-
}
|
|
3176
|
-
return new Uint8Array(0);
|
|
3177
|
-
}
|
|
3178
|
-
size() {
|
|
3179
|
-
return this.byteLength;
|
|
3180
|
-
}
|
|
3181
|
-
length() {
|
|
3182
|
-
return this.buffers.length;
|
|
3183
|
-
}
|
|
3184
|
-
}
|
|
3185
|
-
exports.DataBuffer = DataBuffer;
|
|
3186
|
-
});
|
|
3187
|
-
|
|
3188
|
-
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/transport.js
|
|
3189
|
-
var require_transport = __commonJS((exports) => {
|
|
2699
|
+
// ../../node_modules/.pnpm/@nats-io+nats-core@3.3.1/node_modules/@nats-io/nats-core/lib/transport.js
|
|
2700
|
+
var require_transport = __commonJS((exports) => {
|
|
3190
2701
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3191
2702
|
exports.LF = exports.CR = exports.CRLF = exports.CR_LF_LEN = exports.CR_LF = undefined;
|
|
3192
2703
|
exports.setTransportFactory = setTransportFactory;
|
|
@@ -14641,186 +14152,13 @@ var require_websocket_server = __commonJS((exports, module) => {
|
|
|
14641
14152
|
}
|
|
14642
14153
|
});
|
|
14643
14154
|
|
|
14644
|
-
// src/
|
|
14645
|
-
|
|
14646
|
-
|
|
14647
|
-
|
|
14648
|
-
|
|
14649
|
-
|
|
14650
|
-
|
|
14651
|
-
import * as readline from "node:readline";
|
|
14652
|
-
function toPascalCase(name) {
|
|
14653
|
-
return name.split("-").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join("") + "App";
|
|
14654
|
-
}
|
|
14655
|
-
function toLabel(name) {
|
|
14656
|
-
return name.split("-").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(" ");
|
|
14657
|
-
}
|
|
14658
|
-
function interpolate(content, vars) {
|
|
14659
|
-
let result = content;
|
|
14660
|
-
for (const [key, value] of Object.entries(vars)) {
|
|
14661
|
-
result = result.replaceAll(`{{${key}}}`, value);
|
|
14662
|
-
}
|
|
14663
|
-
return result;
|
|
14664
|
-
}
|
|
14665
|
-
function prompt(rl, question, defaultValue) {
|
|
14666
|
-
return new Promise((resolve2) => {
|
|
14667
|
-
const display = defaultValue ? `${question} ${source_default.dim(`(${defaultValue})`)} ` : `${question} `;
|
|
14668
|
-
rl.question(display, (answer) => {
|
|
14669
|
-
resolve2(answer.trim() || defaultValue);
|
|
14670
|
-
});
|
|
14671
|
-
});
|
|
14672
|
-
}
|
|
14673
|
-
function confirm(rl, question, defaultYes = true) {
|
|
14674
|
-
return new Promise((resolve2) => {
|
|
14675
|
-
const hint = defaultYes ? "Y/n" : "y/N";
|
|
14676
|
-
rl.question(`${question} ${source_default.dim(`(${hint})`)} `, (answer) => {
|
|
14677
|
-
const a = answer.trim().toLowerCase();
|
|
14678
|
-
if (a === "")
|
|
14679
|
-
resolve2(defaultYes);
|
|
14680
|
-
else
|
|
14681
|
-
resolve2(a === "y" || a === "yes");
|
|
14682
|
-
});
|
|
14683
|
-
});
|
|
14684
|
-
}
|
|
14685
|
-
function findTemplateDir() {
|
|
14686
|
-
const candidates = [
|
|
14687
|
-
path.resolve(import.meta.dirname ?? __dirname, "../../templates/app"),
|
|
14688
|
-
path.resolve(import.meta.dirname ?? __dirname, "../templates/app")
|
|
14689
|
-
];
|
|
14690
|
-
for (const candidate of candidates) {
|
|
14691
|
-
if (fs.existsSync(candidate))
|
|
14692
|
-
return candidate;
|
|
14693
|
-
}
|
|
14694
|
-
throw new Error("Template directory not found. Expected at packages/os-cli/templates/app/");
|
|
14695
|
-
}
|
|
14696
|
-
function scaffoldApp(opts) {
|
|
14697
|
-
const { name, description, includeService, projectRoot } = opts;
|
|
14698
|
-
const packageName = `${name}-app`;
|
|
14699
|
-
const targetDir = path.join(projectRoot, "packages", packageName);
|
|
14700
|
-
if (fs.existsSync(targetDir)) {
|
|
14701
|
-
throw new Error(`Directory already exists: packages/${packageName}`);
|
|
14702
|
-
}
|
|
14703
|
-
const templateDir = findTemplateDir();
|
|
14704
|
-
const componentName = toPascalCase(name);
|
|
14705
|
-
const label = toLabel(name);
|
|
14706
|
-
const vars = {
|
|
14707
|
-
name,
|
|
14708
|
-
packageName,
|
|
14709
|
-
label,
|
|
14710
|
-
description,
|
|
14711
|
-
componentName
|
|
14712
|
-
};
|
|
14713
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
14714
|
-
const viewsDir = path.join(targetDir, "views", name);
|
|
14715
|
-
fs.mkdirSync(path.join(viewsDir, "ui"), { recursive: true });
|
|
14716
|
-
if (includeService) {
|
|
14717
|
-
fs.mkdirSync(path.join(viewsDir, "service"), { recursive: true });
|
|
14718
|
-
}
|
|
14719
|
-
const manifestSrc = fs.readFileSync(path.join(templateDir, "manifest.ts"), "utf8");
|
|
14720
|
-
let manifestContent = interpolate(manifestSrc, vars);
|
|
14721
|
-
if (!includeService) {
|
|
14722
|
-
manifestContent = manifestContent.replace(/\t\t\tnatsPrefix:.*\n/, "");
|
|
14723
|
-
}
|
|
14724
|
-
fs.writeFileSync(path.join(targetDir, "manifest.ts"), manifestContent);
|
|
14725
|
-
const pkgTemplate = includeService ? "package.json.tmpl" : "package-no-service.json.tmpl";
|
|
14726
|
-
const pkgSrc = fs.readFileSync(path.join(templateDir, pkgTemplate), "utf8");
|
|
14727
|
-
fs.writeFileSync(path.join(targetDir, "package.json"), interpolate(pkgSrc, vars));
|
|
14728
|
-
const componentsSrc = fs.readFileSync(path.join(templateDir, "components.ts"), "utf8");
|
|
14729
|
-
fs.writeFileSync(path.join(targetDir, "components.ts"), interpolate(componentsSrc, vars));
|
|
14730
|
-
const uiTemplate = includeService ? "App.tsx" : "App-no-service.tsx";
|
|
14731
|
-
const uiSrc = fs.readFileSync(path.join(templateDir, "views", "__name__", "ui", uiTemplate), "utf8");
|
|
14732
|
-
fs.writeFileSync(path.join(viewsDir, "ui", "App.tsx"), interpolate(uiSrc, vars));
|
|
14733
|
-
if (includeService) {
|
|
14734
|
-
const schemaSrc = fs.readFileSync(path.join(templateDir, "views", "__name__", "schema.ts"), "utf8");
|
|
14735
|
-
fs.writeFileSync(path.join(viewsDir, "schema.ts"), interpolate(schemaSrc, vars));
|
|
14736
|
-
const subjectsSrc = fs.readFileSync(path.join(templateDir, "views", "__name__", "subjects.ts"), "utf8");
|
|
14737
|
-
fs.writeFileSync(path.join(viewsDir, "subjects.ts"), interpolate(subjectsSrc, vars));
|
|
14738
|
-
const serviceSrc = fs.readFileSync(path.join(templateDir, "views", "__name__", "service", "index.ts"), "utf8");
|
|
14739
|
-
fs.writeFileSync(path.join(viewsDir, "service", "index.ts"), interpolate(serviceSrc, vars));
|
|
14740
|
-
}
|
|
14741
|
-
}
|
|
14742
|
-
async function runAppCreate(nameArg) {
|
|
14743
|
-
const projectRoot = process.cwd();
|
|
14744
|
-
const rootPkg = path.join(projectRoot, "package.json");
|
|
14745
|
-
if (!fs.existsSync(rootPkg)) {
|
|
14746
|
-
console.error(source_default.red("Error: Not in a project directory (no package.json found)."));
|
|
14747
|
-
process.exit(1);
|
|
14748
|
-
}
|
|
14749
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
14750
|
-
try {
|
|
14751
|
-
console.log(`
|
|
14752
|
-
${source_default.bold("Create a new KhalOS app")}
|
|
14753
|
-
`);
|
|
14754
|
-
const name = nameArg || await prompt(rl, "App name (kebab-case):", "");
|
|
14755
|
-
if (!name) {
|
|
14756
|
-
console.error(source_default.red("Error: App name is required."));
|
|
14757
|
-
process.exit(1);
|
|
14758
|
-
}
|
|
14759
|
-
if (!/^[a-z][a-z0-9-]*$/.test(name)) {
|
|
14760
|
-
console.error(source_default.red("Error: App name must be kebab-case (lowercase, hyphens, starting with a letter)."));
|
|
14761
|
-
process.exit(1);
|
|
14762
|
-
}
|
|
14763
|
-
const description = await prompt(rl, "Description:", "A KhalOS app");
|
|
14764
|
-
const includeService = await confirm(rl, "Include backend service (NATS)?");
|
|
14765
|
-
const includeIcon = await confirm(rl, "Include desktop icon?");
|
|
14766
|
-
console.log("");
|
|
14767
|
-
scaffoldApp({
|
|
14768
|
-
name,
|
|
14769
|
-
description,
|
|
14770
|
-
includeService,
|
|
14771
|
-
includeIcon,
|
|
14772
|
-
projectRoot
|
|
14773
|
-
});
|
|
14774
|
-
const packageName = `${name}-app`;
|
|
14775
|
-
console.log(source_default.green(`✓ Created packages/${packageName}/`));
|
|
14776
|
-
console.log("");
|
|
14777
|
-
console.log(` ${source_default.dim("manifest.ts")} App metadata`);
|
|
14778
|
-
console.log(` ${source_default.dim("package.json")} Workspace package`);
|
|
14779
|
-
console.log(` ${source_default.dim("components.ts")} Lazy-load wiring`);
|
|
14780
|
-
console.log(` ${source_default.dim(`views/${name}/ui/`)} React component`);
|
|
14781
|
-
if (includeService) {
|
|
14782
|
-
console.log(` ${source_default.dim(`views/${name}/service/`)} NATS service`);
|
|
14783
|
-
console.log(` ${source_default.dim(`views/${name}/schema.ts`)} TypeBox schemas`);
|
|
14784
|
-
console.log(` ${source_default.dim(`views/${name}/subjects.ts`)} Subject constants`);
|
|
14785
|
-
}
|
|
14786
|
-
console.log("");
|
|
14787
|
-
console.log(source_default.dim("Running pnpm install..."));
|
|
14788
|
-
const { execSync } = await import("node:child_process");
|
|
14789
|
-
try {
|
|
14790
|
-
execSync("pnpm install", {
|
|
14791
|
-
cwd: projectRoot,
|
|
14792
|
-
stdio: "pipe"
|
|
14793
|
-
});
|
|
14794
|
-
console.log(source_default.green("✓ Dependencies installed"));
|
|
14795
|
-
} catch {
|
|
14796
|
-
console.log(source_default.yellow("⚠ pnpm install failed — run it manually"));
|
|
14797
|
-
}
|
|
14798
|
-
console.log("");
|
|
14799
|
-
console.log(`${source_default.bold("Next steps:")}`);
|
|
14800
|
-
console.log(` 1. ${source_default.cyan("make dev")} — Start the dev server`);
|
|
14801
|
-
console.log(" 2. Open the desktop — your app should appear");
|
|
14802
|
-
if (includeService) {
|
|
14803
|
-
console.log(` 3. Click "Ping Service" to verify the backend`);
|
|
14804
|
-
}
|
|
14805
|
-
console.log("");
|
|
14806
|
-
console.log(` ${source_default.dim("Tutorial:")} docs/BUILDING_APPS.md`);
|
|
14807
|
-
console.log("");
|
|
14808
|
-
} finally {
|
|
14809
|
-
rl.close();
|
|
14810
|
-
}
|
|
14811
|
-
}
|
|
14812
|
-
var __dirname = "/home/runner/_work/core/core/packages/os-cli/src/commands";
|
|
14813
|
-
var init_app_create = __esm(() => {
|
|
14814
|
-
init_source();
|
|
14815
|
-
});
|
|
14816
|
-
|
|
14817
|
-
// ../server-sdk/src/runtime/base.ts
|
|
14818
|
-
class BaseRuntime {
|
|
14819
|
-
config;
|
|
14820
|
-
handlers = new Set;
|
|
14821
|
-
running = false;
|
|
14822
|
-
constructor(config) {
|
|
14823
|
-
this.config = config;
|
|
14155
|
+
// ../server-sdk/src/runtime/base.ts
|
|
14156
|
+
class BaseRuntime {
|
|
14157
|
+
config;
|
|
14158
|
+
handlers = new Set;
|
|
14159
|
+
running = false;
|
|
14160
|
+
constructor(config) {
|
|
14161
|
+
this.config = config;
|
|
14824
14162
|
}
|
|
14825
14163
|
on(handler) {
|
|
14826
14164
|
this.handlers.add(handler);
|
|
@@ -14905,11 +14243,11 @@ var init_azure = __esm(() => {
|
|
|
14905
14243
|
});
|
|
14906
14244
|
|
|
14907
14245
|
// ../server-sdk/src/runtime/deps.ts
|
|
14908
|
-
import { chmodSync, createWriteStream, existsSync as
|
|
14246
|
+
import { chmodSync, createWriteStream, existsSync as existsSync3, mkdirSync as mkdirSync3, renameSync, rmSync as rmSync2 } from "node:fs";
|
|
14909
14247
|
import { get as httpGet } from "node:http";
|
|
14910
14248
|
import { get as httpsGet } from "node:https";
|
|
14911
14249
|
import { homedir as homedir2, arch as osArch, platform as osPlatform } from "node:os";
|
|
14912
|
-
import { join as
|
|
14250
|
+
import { join as join3 } from "node:path";
|
|
14913
14251
|
function detectPlatform() {
|
|
14914
14252
|
const p = osPlatform();
|
|
14915
14253
|
if (p === "win32")
|
|
@@ -14938,7 +14276,7 @@ function getBunUrl(version, platform, arch) {
|
|
|
14938
14276
|
return `https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-${os2}-${a}-${profile}.${ext}`;
|
|
14939
14277
|
}
|
|
14940
14278
|
function followRedirects(url, maxRedirects = 5) {
|
|
14941
|
-
return new Promise((
|
|
14279
|
+
return new Promise((resolve2, reject) => {
|
|
14942
14280
|
if (maxRedirects <= 0) {
|
|
14943
14281
|
reject(new Error("Too many redirects"));
|
|
14944
14282
|
return;
|
|
@@ -14946,25 +14284,25 @@ function followRedirects(url, maxRedirects = 5) {
|
|
|
14946
14284
|
const get = url.startsWith("https") ? httpsGet : httpGet;
|
|
14947
14285
|
get(url, (res) => {
|
|
14948
14286
|
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
14949
|
-
followRedirects(res.headers.location, maxRedirects - 1).then(
|
|
14287
|
+
followRedirects(res.headers.location, maxRedirects - 1).then(resolve2, reject);
|
|
14950
14288
|
return;
|
|
14951
14289
|
}
|
|
14952
14290
|
if (res.statusCode && res.statusCode >= 400) {
|
|
14953
14291
|
reject(new Error(`HTTP ${res.statusCode} for ${url}`));
|
|
14954
14292
|
return;
|
|
14955
14293
|
}
|
|
14956
|
-
|
|
14294
|
+
resolve2(res);
|
|
14957
14295
|
}).on("error", reject);
|
|
14958
14296
|
});
|
|
14959
14297
|
}
|
|
14960
14298
|
function downloadFile(url, dest) {
|
|
14961
|
-
return new Promise((
|
|
14299
|
+
return new Promise((resolve2, reject) => {
|
|
14962
14300
|
followRedirects(url).then((res) => {
|
|
14963
14301
|
const file = createWriteStream(dest);
|
|
14964
14302
|
res.pipe(file);
|
|
14965
14303
|
file.on("finish", () => {
|
|
14966
14304
|
file.close();
|
|
14967
|
-
|
|
14305
|
+
resolve2();
|
|
14968
14306
|
});
|
|
14969
14307
|
file.on("error", (err) => {
|
|
14970
14308
|
rmSync2(dest, { force: true });
|
|
@@ -14996,21 +14334,21 @@ async function extractZip(archivePath, destDir, binaryName) {
|
|
|
14996
14334
|
return lines[0];
|
|
14997
14335
|
}
|
|
14998
14336
|
function defaultBinDir() {
|
|
14999
|
-
return
|
|
14337
|
+
return join3(homedir2(), ".khal-os", "bin");
|
|
15000
14338
|
}
|
|
15001
14339
|
async function ensureBinary(name, version, binDir, downloadUrl, emit) {
|
|
15002
|
-
|
|
15003
|
-
const binaryPath =
|
|
15004
|
-
if (
|
|
14340
|
+
mkdirSync3(binDir, { recursive: true });
|
|
14341
|
+
const binaryPath = join3(binDir, `${name}-${version}`);
|
|
14342
|
+
if (existsSync3(binaryPath)) {
|
|
15005
14343
|
emit?.({ type: "dep:ready", name, path: binaryPath });
|
|
15006
14344
|
return binaryPath;
|
|
15007
14345
|
}
|
|
15008
14346
|
emit?.({ type: "dep:downloading", name, url: downloadUrl });
|
|
15009
14347
|
const ext = downloadUrl.endsWith(".tar.gz") ? ".tar.gz" : ".zip";
|
|
15010
|
-
const tmpArchive =
|
|
15011
|
-
const tmpExtract =
|
|
14348
|
+
const tmpArchive = join3(binDir, `${name}-${version}-download${ext}`);
|
|
14349
|
+
const tmpExtract = join3(binDir, `${name}-${version}-extract`);
|
|
15012
14350
|
try {
|
|
15013
|
-
|
|
14351
|
+
mkdirSync3(tmpExtract, { recursive: true });
|
|
15014
14352
|
await downloadFile(downloadUrl, tmpArchive);
|
|
15015
14353
|
let extractedPath;
|
|
15016
14354
|
if (ext === ".tar.gz") {
|
|
@@ -15028,7 +14366,7 @@ async function ensureBinary(name, version, binDir, downloadUrl, emit) {
|
|
|
15028
14366
|
}
|
|
15029
14367
|
}
|
|
15030
14368
|
function isBinaryCached(name, version, binDir) {
|
|
15031
|
-
return
|
|
14369
|
+
return existsSync3(join3(binDir, `${name}-${version}`));
|
|
15032
14370
|
}
|
|
15033
14371
|
var init_deps = () => {};
|
|
15034
14372
|
|
|
@@ -15068,12 +14406,12 @@ __export(exports_local, {
|
|
|
15068
14406
|
LocalRuntime: () => LocalRuntime
|
|
15069
14407
|
});
|
|
15070
14408
|
import { execSync as execSync3, spawn } from "node:child_process";
|
|
15071
|
-
import { existsSync as
|
|
14409
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync4, readFileSync as readFileSync4, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
15072
14410
|
import { createConnection } from "node:net";
|
|
15073
14411
|
import { homedir as homedir3 } from "node:os";
|
|
15074
|
-
import { join as
|
|
14412
|
+
import { join as join4 } from "node:path";
|
|
15075
14413
|
function waitForPort(port, host = "127.0.0.1", timeoutMs = 30000) {
|
|
15076
|
-
return new Promise((
|
|
14414
|
+
return new Promise((resolve2, reject) => {
|
|
15077
14415
|
const deadline = Date.now() + timeoutMs;
|
|
15078
14416
|
function attempt() {
|
|
15079
14417
|
if (Date.now() > deadline) {
|
|
@@ -15083,7 +14421,7 @@ function waitForPort(port, host = "127.0.0.1", timeoutMs = 30000) {
|
|
|
15083
14421
|
const socket = createConnection({ port, host });
|
|
15084
14422
|
socket.once("connect", () => {
|
|
15085
14423
|
socket.destroy();
|
|
15086
|
-
|
|
14424
|
+
resolve2();
|
|
15087
14425
|
});
|
|
15088
14426
|
socket.once("error", () => {
|
|
15089
14427
|
socket.destroy();
|
|
@@ -15094,7 +14432,7 @@ function waitForPort(port, host = "127.0.0.1", timeoutMs = 30000) {
|
|
|
15094
14432
|
});
|
|
15095
14433
|
}
|
|
15096
14434
|
function ensurePortFree(port, host = "127.0.0.1") {
|
|
15097
|
-
return new Promise((
|
|
14435
|
+
return new Promise((resolve2, reject) => {
|
|
15098
14436
|
const socket = createConnection({ port, host });
|
|
15099
14437
|
socket.once("connect", () => {
|
|
15100
14438
|
socket.destroy();
|
|
@@ -15122,31 +14460,31 @@ function ensurePortFree(port, host = "127.0.0.1") {
|
|
|
15122
14460
|
});
|
|
15123
14461
|
s.once("error", () => {
|
|
15124
14462
|
s.destroy();
|
|
15125
|
-
|
|
14463
|
+
resolve2();
|
|
15126
14464
|
});
|
|
15127
14465
|
};
|
|
15128
14466
|
setTimeout(check, 500);
|
|
15129
14467
|
});
|
|
15130
14468
|
socket.once("error", () => {
|
|
15131
14469
|
socket.destroy();
|
|
15132
|
-
|
|
14470
|
+
resolve2();
|
|
15133
14471
|
});
|
|
15134
14472
|
});
|
|
15135
14473
|
}
|
|
15136
14474
|
function probePort(port, host = "127.0.0.1") {
|
|
15137
|
-
return new Promise((
|
|
14475
|
+
return new Promise((resolve2) => {
|
|
15138
14476
|
const socket = createConnection({ port, host });
|
|
15139
14477
|
socket.once("connect", () => {
|
|
15140
14478
|
socket.destroy();
|
|
15141
|
-
|
|
14479
|
+
resolve2(true);
|
|
15142
14480
|
});
|
|
15143
14481
|
socket.once("error", () => {
|
|
15144
14482
|
socket.destroy();
|
|
15145
|
-
|
|
14483
|
+
resolve2(false);
|
|
15146
14484
|
});
|
|
15147
14485
|
socket.setTimeout(2000, () => {
|
|
15148
14486
|
socket.destroy();
|
|
15149
|
-
|
|
14487
|
+
resolve2(false);
|
|
15150
14488
|
});
|
|
15151
14489
|
});
|
|
15152
14490
|
}
|
|
@@ -15166,17 +14504,17 @@ var init_local = __esm(() => {
|
|
|
15166
14504
|
startedAt;
|
|
15167
14505
|
constructor(config) {
|
|
15168
14506
|
super(config);
|
|
15169
|
-
this.dataDir = config.dataDir ??
|
|
14507
|
+
this.dataDir = config.dataDir ?? join4(homedir3(), ".khal-os");
|
|
15170
14508
|
}
|
|
15171
14509
|
async ensureDeps() {
|
|
15172
|
-
const binDir =
|
|
14510
|
+
const binDir = join4(this.dataDir, "bin");
|
|
15173
14511
|
const platform = detectPlatform();
|
|
15174
14512
|
const arch = detectArch();
|
|
15175
14513
|
const emitter = (event) => this.emit(event);
|
|
15176
14514
|
this.natsBin = await ensureBinary("nats-server", NATS_VERSION, binDir, getNatsUrl(NATS_VERSION, platform, arch), emitter);
|
|
15177
14515
|
}
|
|
15178
14516
|
async depsReady() {
|
|
15179
|
-
const binDir =
|
|
14517
|
+
const binDir = join4(this.dataDir, "bin");
|
|
15180
14518
|
return isBinaryCached("nats-server", NATS_VERSION, binDir);
|
|
15181
14519
|
}
|
|
15182
14520
|
async start() {
|
|
@@ -15211,8 +14549,8 @@ var init_local = __esm(() => {
|
|
|
15211
14549
|
NEXT_PUBLIC_WS_URL: "ws://localhost:4280/ws/nats"
|
|
15212
14550
|
};
|
|
15213
14551
|
const projectRoot = this.config.projectRoot;
|
|
15214
|
-
const nextDirect =
|
|
15215
|
-
const nextBin =
|
|
14552
|
+
const nextDirect = join4(projectRoot, "node_modules/.bin/next");
|
|
14553
|
+
const nextBin = existsSync4(nextDirect) ? nextDirect : "npx";
|
|
15216
14554
|
const nextArgs = (args) => nextBin === "npx" ? ["next", ...args] : args;
|
|
15217
14555
|
if (!frontendOnly) {
|
|
15218
14556
|
this.spawnChild("nats", this.natsBin, ["--port", String(NATS_PORT), "--jetstream"], {
|
|
@@ -15221,8 +14559,8 @@ var init_local = __esm(() => {
|
|
|
15221
14559
|
port: NATS_PORT
|
|
15222
14560
|
});
|
|
15223
14561
|
await waitForPort(NATS_PORT);
|
|
15224
|
-
const tsxDirect =
|
|
15225
|
-
const tsxBin =
|
|
14562
|
+
const tsxDirect = join4(projectRoot, "node_modules/.bin/tsx");
|
|
14563
|
+
const tsxBin = existsSync4(tsxDirect) ? tsxDirect : "npx";
|
|
15226
14564
|
const tsxArgs = (args) => tsxBin === "npx" ? ["tsx", ...args] : args;
|
|
15227
14565
|
this.spawnChild("services", tsxBin, tsxArgs(["src/lib/service-loader.ts"]), {
|
|
15228
14566
|
cwd: projectRoot,
|
|
@@ -15273,18 +14611,18 @@ var init_local = __esm(() => {
|
|
|
15273
14611
|
} catch {}
|
|
15274
14612
|
}
|
|
15275
14613
|
}
|
|
15276
|
-
await Promise.all(this.children.map((child) => new Promise((
|
|
14614
|
+
await Promise.all(this.children.map((child) => new Promise((resolve2) => {
|
|
15277
14615
|
const timer = setTimeout(() => {
|
|
15278
14616
|
if (child.process.pid && !child.process.killed) {
|
|
15279
14617
|
try {
|
|
15280
14618
|
child.process.kill("SIGKILL");
|
|
15281
14619
|
} catch {}
|
|
15282
14620
|
}
|
|
15283
|
-
|
|
14621
|
+
resolve2();
|
|
15284
14622
|
}, STOP_TIMEOUT_MS);
|
|
15285
14623
|
child.process.once("exit", () => {
|
|
15286
14624
|
clearTimeout(timer);
|
|
15287
|
-
|
|
14625
|
+
resolve2();
|
|
15288
14626
|
});
|
|
15289
14627
|
})));
|
|
15290
14628
|
this.children = [];
|
|
@@ -15355,10 +14693,10 @@ var init_local = __esm(() => {
|
|
|
15355
14693
|
}
|
|
15356
14694
|
killStalePid() {
|
|
15357
14695
|
const pidFile = this.pidFilePath();
|
|
15358
|
-
if (!
|
|
14696
|
+
if (!existsSync4(pidFile))
|
|
15359
14697
|
return;
|
|
15360
14698
|
try {
|
|
15361
|
-
const oldPid = Number.parseInt(
|
|
14699
|
+
const oldPid = Number.parseInt(readFileSync4(pidFile, "utf8").trim(), 10);
|
|
15362
14700
|
if (!Number.isNaN(oldPid) && oldPid > 0 && oldPid !== process.pid) {
|
|
15363
14701
|
process.kill(oldPid, "SIGTERM");
|
|
15364
14702
|
const deadline = Date.now() + 2000;
|
|
@@ -15376,11 +14714,11 @@ var init_local = __esm(() => {
|
|
|
15376
14714
|
rmSync3(pidFile, { force: true });
|
|
15377
14715
|
}
|
|
15378
14716
|
pidFilePath() {
|
|
15379
|
-
return
|
|
14717
|
+
return join4(this.dataDir, "khal-os.pid");
|
|
15380
14718
|
}
|
|
15381
14719
|
writePidFile() {
|
|
15382
|
-
|
|
15383
|
-
|
|
14720
|
+
mkdirSync4(this.dataDir, { recursive: true });
|
|
14721
|
+
writeFileSync3(this.pidFilePath(), String(process.pid), "utf8");
|
|
15384
14722
|
}
|
|
15385
14723
|
removePidFile() {
|
|
15386
14724
|
rmSync3(this.pidFilePath(), { force: true });
|
|
@@ -15546,12 +14884,12 @@ __export(exports_kubernetes, {
|
|
|
15546
14884
|
KubernetesRuntime: () => KubernetesRuntime
|
|
15547
14885
|
});
|
|
15548
14886
|
import { execFile } from "node:child_process";
|
|
15549
|
-
import { existsSync as
|
|
14887
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
15550
14888
|
import { promisify } from "node:util";
|
|
15551
14889
|
function isInCluster() {
|
|
15552
14890
|
if (_inClusterCached !== undefined)
|
|
15553
14891
|
return _inClusterCached;
|
|
15554
|
-
_inClusterCached =
|
|
14892
|
+
_inClusterCached = existsSync5(IN_CLUSTER_TOKEN_PATH) && !!process.env.KUBERNETES_SERVICE_HOST;
|
|
15555
14893
|
return _inClusterCached;
|
|
15556
14894
|
}
|
|
15557
14895
|
var exec, IN_CLUSTER_TOKEN_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/token", _inClusterCached, DEFAULT_KUBECONFIG = "/etc/rancher/k3s/k3s.yaml", DEFAULT_NATS_URL = "nats://nats:4222", DEFAULT_RESOURCES, SANDBOX_RUNTIME_CLASS = "sysbox-runc", SANDBOX_PVC_SIZE = "20Gi", SANDBOX_STORAGE_CLASS = "local-path", SANDBOX_SSH_PORT = 22, SANDBOX_NAMESPACE = "khal-sandbox", SANDBOX_HELM_CHART, SANDBOX_RESOURCES, KubernetesRuntime;
|
|
@@ -15969,8 +15307,8 @@ var init_kubernetes = __esm(() => {
|
|
|
15969
15307
|
}
|
|
15970
15308
|
applyManifest(json) {
|
|
15971
15309
|
const kubeArgs = this.kubeconfigArgs();
|
|
15972
|
-
return new Promise((
|
|
15973
|
-
const child = execFile("kubectl", [...kubeArgs, "apply", "-f", "-"], { timeout: 30000 }, (err) => err ? reject(err) :
|
|
15310
|
+
return new Promise((resolve2, reject) => {
|
|
15311
|
+
const child = execFile("kubectl", [...kubeArgs, "apply", "-f", "-"], { timeout: 30000 }, (err) => err ? reject(err) : resolve2());
|
|
15974
15312
|
child.stdin?.write(json);
|
|
15975
15313
|
child.stdin?.end();
|
|
15976
15314
|
});
|
|
@@ -17062,11 +16400,11 @@ var require_jsmconsumer_api = __commonJS((exports) => {
|
|
|
17062
16400
|
consumerName = cfg.name ?? cfg.durable_name ?? "";
|
|
17063
16401
|
}
|
|
17064
16402
|
if (consumerName !== "") {
|
|
17065
|
-
let
|
|
17066
|
-
if (
|
|
17067
|
-
|
|
16403
|
+
let fs = cfg.filter_subject ?? undefined;
|
|
16404
|
+
if (fs === ">") {
|
|
16405
|
+
fs = undefined;
|
|
17068
16406
|
}
|
|
17069
|
-
subj =
|
|
16407
|
+
subj = fs !== undefined ? `${this.prefix}.CONSUMER.CREATE.${stream}.${consumerName}.${fs}` : `${this.prefix}.CONSUMER.CREATE.${stream}.${consumerName}`;
|
|
17070
16408
|
} else {
|
|
17071
16409
|
subj = cfg.durable_name ? `${this.prefix}.CONSUMER.DURABLE.CREATE.${stream}.${cfg.durable_name}` : `${this.prefix}.CONSUMER.CREATE.${stream}`;
|
|
17072
16410
|
}
|
|
@@ -19701,31 +19039,519 @@ var require_mod4 = __commonJS((exports) => {
|
|
|
19701
19039
|
return internal_mod_2.StoreCompression;
|
|
19702
19040
|
} });
|
|
19703
19041
|
});
|
|
19704
|
-
|
|
19705
|
-
// src/index.ts
|
|
19706
|
-
import { readFileSync as
|
|
19707
|
-
|
|
19708
|
-
// ../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/esm.mjs
|
|
19709
|
-
var import__ = __toESM(require_commander(), 1);
|
|
19710
|
-
var {
|
|
19711
|
-
program,
|
|
19712
|
-
createCommand,
|
|
19713
|
-
createArgument,
|
|
19714
|
-
createOption,
|
|
19715
|
-
CommanderError,
|
|
19716
|
-
InvalidArgumentError,
|
|
19717
|
-
InvalidOptionArgumentError,
|
|
19718
|
-
Command,
|
|
19719
|
-
Argument,
|
|
19720
|
-
Option,
|
|
19721
|
-
Help
|
|
19722
|
-
} = import__.default;
|
|
19723
|
-
|
|
19724
|
-
// src/_version.ts
|
|
19725
|
-
var KHALOS_VERSION = "0.0.0-dev";
|
|
19042
|
+
|
|
19043
|
+
// src/index.ts
|
|
19044
|
+
import { readFileSync as readFileSync6 } from "node:fs";
|
|
19045
|
+
|
|
19046
|
+
// ../../node_modules/.pnpm/commander@12.1.0/node_modules/commander/esm.mjs
|
|
19047
|
+
var import__ = __toESM(require_commander(), 1);
|
|
19048
|
+
var {
|
|
19049
|
+
program,
|
|
19050
|
+
createCommand,
|
|
19051
|
+
createArgument,
|
|
19052
|
+
createOption,
|
|
19053
|
+
CommanderError,
|
|
19054
|
+
InvalidArgumentError,
|
|
19055
|
+
InvalidOptionArgumentError,
|
|
19056
|
+
Command,
|
|
19057
|
+
Argument,
|
|
19058
|
+
Option,
|
|
19059
|
+
Help
|
|
19060
|
+
} = import__.default;
|
|
19061
|
+
|
|
19062
|
+
// src/_version.ts
|
|
19063
|
+
var KHALOS_VERSION = "0.0.0-dev";
|
|
19064
|
+
|
|
19065
|
+
// ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
19066
|
+
var ANSI_BACKGROUND_OFFSET = 10;
|
|
19067
|
+
var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
|
|
19068
|
+
var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
|
|
19069
|
+
var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
|
|
19070
|
+
var styles = {
|
|
19071
|
+
modifier: {
|
|
19072
|
+
reset: [0, 0],
|
|
19073
|
+
bold: [1, 22],
|
|
19074
|
+
dim: [2, 22],
|
|
19075
|
+
italic: [3, 23],
|
|
19076
|
+
underline: [4, 24],
|
|
19077
|
+
overline: [53, 55],
|
|
19078
|
+
inverse: [7, 27],
|
|
19079
|
+
hidden: [8, 28],
|
|
19080
|
+
strikethrough: [9, 29]
|
|
19081
|
+
},
|
|
19082
|
+
color: {
|
|
19083
|
+
black: [30, 39],
|
|
19084
|
+
red: [31, 39],
|
|
19085
|
+
green: [32, 39],
|
|
19086
|
+
yellow: [33, 39],
|
|
19087
|
+
blue: [34, 39],
|
|
19088
|
+
magenta: [35, 39],
|
|
19089
|
+
cyan: [36, 39],
|
|
19090
|
+
white: [37, 39],
|
|
19091
|
+
blackBright: [90, 39],
|
|
19092
|
+
gray: [90, 39],
|
|
19093
|
+
grey: [90, 39],
|
|
19094
|
+
redBright: [91, 39],
|
|
19095
|
+
greenBright: [92, 39],
|
|
19096
|
+
yellowBright: [93, 39],
|
|
19097
|
+
blueBright: [94, 39],
|
|
19098
|
+
magentaBright: [95, 39],
|
|
19099
|
+
cyanBright: [96, 39],
|
|
19100
|
+
whiteBright: [97, 39]
|
|
19101
|
+
},
|
|
19102
|
+
bgColor: {
|
|
19103
|
+
bgBlack: [40, 49],
|
|
19104
|
+
bgRed: [41, 49],
|
|
19105
|
+
bgGreen: [42, 49],
|
|
19106
|
+
bgYellow: [43, 49],
|
|
19107
|
+
bgBlue: [44, 49],
|
|
19108
|
+
bgMagenta: [45, 49],
|
|
19109
|
+
bgCyan: [46, 49],
|
|
19110
|
+
bgWhite: [47, 49],
|
|
19111
|
+
bgBlackBright: [100, 49],
|
|
19112
|
+
bgGray: [100, 49],
|
|
19113
|
+
bgGrey: [100, 49],
|
|
19114
|
+
bgRedBright: [101, 49],
|
|
19115
|
+
bgGreenBright: [102, 49],
|
|
19116
|
+
bgYellowBright: [103, 49],
|
|
19117
|
+
bgBlueBright: [104, 49],
|
|
19118
|
+
bgMagentaBright: [105, 49],
|
|
19119
|
+
bgCyanBright: [106, 49],
|
|
19120
|
+
bgWhiteBright: [107, 49]
|
|
19121
|
+
}
|
|
19122
|
+
};
|
|
19123
|
+
var modifierNames = Object.keys(styles.modifier);
|
|
19124
|
+
var foregroundColorNames = Object.keys(styles.color);
|
|
19125
|
+
var backgroundColorNames = Object.keys(styles.bgColor);
|
|
19126
|
+
var colorNames = [...foregroundColorNames, ...backgroundColorNames];
|
|
19127
|
+
function assembleStyles() {
|
|
19128
|
+
const codes = new Map;
|
|
19129
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
19130
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
19131
|
+
styles[styleName] = {
|
|
19132
|
+
open: `\x1B[${style[0]}m`,
|
|
19133
|
+
close: `\x1B[${style[1]}m`
|
|
19134
|
+
};
|
|
19135
|
+
group[styleName] = styles[styleName];
|
|
19136
|
+
codes.set(style[0], style[1]);
|
|
19137
|
+
}
|
|
19138
|
+
Object.defineProperty(styles, groupName, {
|
|
19139
|
+
value: group,
|
|
19140
|
+
enumerable: false
|
|
19141
|
+
});
|
|
19142
|
+
}
|
|
19143
|
+
Object.defineProperty(styles, "codes", {
|
|
19144
|
+
value: codes,
|
|
19145
|
+
enumerable: false
|
|
19146
|
+
});
|
|
19147
|
+
styles.color.close = "\x1B[39m";
|
|
19148
|
+
styles.bgColor.close = "\x1B[49m";
|
|
19149
|
+
styles.color.ansi = wrapAnsi16();
|
|
19150
|
+
styles.color.ansi256 = wrapAnsi256();
|
|
19151
|
+
styles.color.ansi16m = wrapAnsi16m();
|
|
19152
|
+
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
19153
|
+
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
19154
|
+
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
19155
|
+
Object.defineProperties(styles, {
|
|
19156
|
+
rgbToAnsi256: {
|
|
19157
|
+
value(red, green, blue) {
|
|
19158
|
+
if (red === green && green === blue) {
|
|
19159
|
+
if (red < 8) {
|
|
19160
|
+
return 16;
|
|
19161
|
+
}
|
|
19162
|
+
if (red > 248) {
|
|
19163
|
+
return 231;
|
|
19164
|
+
}
|
|
19165
|
+
return Math.round((red - 8) / 247 * 24) + 232;
|
|
19166
|
+
}
|
|
19167
|
+
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
19168
|
+
},
|
|
19169
|
+
enumerable: false
|
|
19170
|
+
},
|
|
19171
|
+
hexToRgb: {
|
|
19172
|
+
value(hex) {
|
|
19173
|
+
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
19174
|
+
if (!matches) {
|
|
19175
|
+
return [0, 0, 0];
|
|
19176
|
+
}
|
|
19177
|
+
let [colorString] = matches;
|
|
19178
|
+
if (colorString.length === 3) {
|
|
19179
|
+
colorString = [...colorString].map((character) => character + character).join("");
|
|
19180
|
+
}
|
|
19181
|
+
const integer = Number.parseInt(colorString, 16);
|
|
19182
|
+
return [
|
|
19183
|
+
integer >> 16 & 255,
|
|
19184
|
+
integer >> 8 & 255,
|
|
19185
|
+
integer & 255
|
|
19186
|
+
];
|
|
19187
|
+
},
|
|
19188
|
+
enumerable: false
|
|
19189
|
+
},
|
|
19190
|
+
hexToAnsi256: {
|
|
19191
|
+
value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
19192
|
+
enumerable: false
|
|
19193
|
+
},
|
|
19194
|
+
ansi256ToAnsi: {
|
|
19195
|
+
value(code) {
|
|
19196
|
+
if (code < 8) {
|
|
19197
|
+
return 30 + code;
|
|
19198
|
+
}
|
|
19199
|
+
if (code < 16) {
|
|
19200
|
+
return 90 + (code - 8);
|
|
19201
|
+
}
|
|
19202
|
+
let red;
|
|
19203
|
+
let green;
|
|
19204
|
+
let blue;
|
|
19205
|
+
if (code >= 232) {
|
|
19206
|
+
red = ((code - 232) * 10 + 8) / 255;
|
|
19207
|
+
green = red;
|
|
19208
|
+
blue = red;
|
|
19209
|
+
} else {
|
|
19210
|
+
code -= 16;
|
|
19211
|
+
const remainder = code % 36;
|
|
19212
|
+
red = Math.floor(code / 36) / 5;
|
|
19213
|
+
green = Math.floor(remainder / 6) / 5;
|
|
19214
|
+
blue = remainder % 6 / 5;
|
|
19215
|
+
}
|
|
19216
|
+
const value = Math.max(red, green, blue) * 2;
|
|
19217
|
+
if (value === 0) {
|
|
19218
|
+
return 30;
|
|
19219
|
+
}
|
|
19220
|
+
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
19221
|
+
if (value === 2) {
|
|
19222
|
+
result += 60;
|
|
19223
|
+
}
|
|
19224
|
+
return result;
|
|
19225
|
+
},
|
|
19226
|
+
enumerable: false
|
|
19227
|
+
},
|
|
19228
|
+
rgbToAnsi: {
|
|
19229
|
+
value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
19230
|
+
enumerable: false
|
|
19231
|
+
},
|
|
19232
|
+
hexToAnsi: {
|
|
19233
|
+
value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
19234
|
+
enumerable: false
|
|
19235
|
+
}
|
|
19236
|
+
});
|
|
19237
|
+
return styles;
|
|
19238
|
+
}
|
|
19239
|
+
var ansiStyles = assembleStyles();
|
|
19240
|
+
var ansi_styles_default = ansiStyles;
|
|
19241
|
+
|
|
19242
|
+
// ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js
|
|
19243
|
+
import process2 from "node:process";
|
|
19244
|
+
import os from "node:os";
|
|
19245
|
+
import tty from "node:tty";
|
|
19246
|
+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process2.argv) {
|
|
19247
|
+
const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
|
|
19248
|
+
const position = argv.indexOf(prefix + flag);
|
|
19249
|
+
const terminatorPosition = argv.indexOf("--");
|
|
19250
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
19251
|
+
}
|
|
19252
|
+
var { env } = process2;
|
|
19253
|
+
var flagForceColor;
|
|
19254
|
+
if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
|
|
19255
|
+
flagForceColor = 0;
|
|
19256
|
+
} else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
|
|
19257
|
+
flagForceColor = 1;
|
|
19258
|
+
}
|
|
19259
|
+
function envForceColor() {
|
|
19260
|
+
if ("FORCE_COLOR" in env) {
|
|
19261
|
+
if (env.FORCE_COLOR === "true") {
|
|
19262
|
+
return 1;
|
|
19263
|
+
}
|
|
19264
|
+
if (env.FORCE_COLOR === "false") {
|
|
19265
|
+
return 0;
|
|
19266
|
+
}
|
|
19267
|
+
return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
19268
|
+
}
|
|
19269
|
+
}
|
|
19270
|
+
function translateLevel(level) {
|
|
19271
|
+
if (level === 0) {
|
|
19272
|
+
return false;
|
|
19273
|
+
}
|
|
19274
|
+
return {
|
|
19275
|
+
level,
|
|
19276
|
+
hasBasic: true,
|
|
19277
|
+
has256: level >= 2,
|
|
19278
|
+
has16m: level >= 3
|
|
19279
|
+
};
|
|
19280
|
+
}
|
|
19281
|
+
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
19282
|
+
const noFlagForceColor = envForceColor();
|
|
19283
|
+
if (noFlagForceColor !== undefined) {
|
|
19284
|
+
flagForceColor = noFlagForceColor;
|
|
19285
|
+
}
|
|
19286
|
+
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
19287
|
+
if (forceColor === 0) {
|
|
19288
|
+
return 0;
|
|
19289
|
+
}
|
|
19290
|
+
if (sniffFlags) {
|
|
19291
|
+
if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
|
|
19292
|
+
return 3;
|
|
19293
|
+
}
|
|
19294
|
+
if (hasFlag("color=256")) {
|
|
19295
|
+
return 2;
|
|
19296
|
+
}
|
|
19297
|
+
}
|
|
19298
|
+
if ("TF_BUILD" in env && "AGENT_NAME" in env) {
|
|
19299
|
+
return 1;
|
|
19300
|
+
}
|
|
19301
|
+
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
19302
|
+
return 0;
|
|
19303
|
+
}
|
|
19304
|
+
const min = forceColor || 0;
|
|
19305
|
+
if (env.TERM === "dumb") {
|
|
19306
|
+
return min;
|
|
19307
|
+
}
|
|
19308
|
+
if (process2.platform === "win32") {
|
|
19309
|
+
const osRelease = os.release().split(".");
|
|
19310
|
+
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
|
19311
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
19312
|
+
}
|
|
19313
|
+
return 1;
|
|
19314
|
+
}
|
|
19315
|
+
if ("CI" in env) {
|
|
19316
|
+
if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => (key in env))) {
|
|
19317
|
+
return 3;
|
|
19318
|
+
}
|
|
19319
|
+
if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => (sign in env)) || env.CI_NAME === "codeship") {
|
|
19320
|
+
return 1;
|
|
19321
|
+
}
|
|
19322
|
+
return min;
|
|
19323
|
+
}
|
|
19324
|
+
if ("TEAMCITY_VERSION" in env) {
|
|
19325
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
19326
|
+
}
|
|
19327
|
+
if (env.COLORTERM === "truecolor") {
|
|
19328
|
+
return 3;
|
|
19329
|
+
}
|
|
19330
|
+
if (env.TERM === "xterm-kitty") {
|
|
19331
|
+
return 3;
|
|
19332
|
+
}
|
|
19333
|
+
if (env.TERM === "xterm-ghostty") {
|
|
19334
|
+
return 3;
|
|
19335
|
+
}
|
|
19336
|
+
if (env.TERM === "wezterm") {
|
|
19337
|
+
return 3;
|
|
19338
|
+
}
|
|
19339
|
+
if ("TERM_PROGRAM" in env) {
|
|
19340
|
+
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
|
|
19341
|
+
switch (env.TERM_PROGRAM) {
|
|
19342
|
+
case "iTerm.app": {
|
|
19343
|
+
return version >= 3 ? 3 : 2;
|
|
19344
|
+
}
|
|
19345
|
+
case "Apple_Terminal": {
|
|
19346
|
+
return 2;
|
|
19347
|
+
}
|
|
19348
|
+
}
|
|
19349
|
+
}
|
|
19350
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
19351
|
+
return 2;
|
|
19352
|
+
}
|
|
19353
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
19354
|
+
return 1;
|
|
19355
|
+
}
|
|
19356
|
+
if ("COLORTERM" in env) {
|
|
19357
|
+
return 1;
|
|
19358
|
+
}
|
|
19359
|
+
return min;
|
|
19360
|
+
}
|
|
19361
|
+
function createSupportsColor(stream, options = {}) {
|
|
19362
|
+
const level = _supportsColor(stream, {
|
|
19363
|
+
streamIsTTY: stream && stream.isTTY,
|
|
19364
|
+
...options
|
|
19365
|
+
});
|
|
19366
|
+
return translateLevel(level);
|
|
19367
|
+
}
|
|
19368
|
+
var supportsColor = {
|
|
19369
|
+
stdout: createSupportsColor({ isTTY: tty.isatty(1) }),
|
|
19370
|
+
stderr: createSupportsColor({ isTTY: tty.isatty(2) })
|
|
19371
|
+
};
|
|
19372
|
+
var supports_color_default = supportsColor;
|
|
19373
|
+
|
|
19374
|
+
// ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js
|
|
19375
|
+
function stringReplaceAll(string, substring, replacer) {
|
|
19376
|
+
let index = string.indexOf(substring);
|
|
19377
|
+
if (index === -1) {
|
|
19378
|
+
return string;
|
|
19379
|
+
}
|
|
19380
|
+
const substringLength = substring.length;
|
|
19381
|
+
let endIndex = 0;
|
|
19382
|
+
let returnValue = "";
|
|
19383
|
+
do {
|
|
19384
|
+
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
19385
|
+
endIndex = index + substringLength;
|
|
19386
|
+
index = string.indexOf(substring, endIndex);
|
|
19387
|
+
} while (index !== -1);
|
|
19388
|
+
returnValue += string.slice(endIndex);
|
|
19389
|
+
return returnValue;
|
|
19390
|
+
}
|
|
19391
|
+
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
19392
|
+
let endIndex = 0;
|
|
19393
|
+
let returnValue = "";
|
|
19394
|
+
do {
|
|
19395
|
+
const gotCR = string[index - 1] === "\r";
|
|
19396
|
+
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? `\r
|
|
19397
|
+
` : `
|
|
19398
|
+
`) + postfix;
|
|
19399
|
+
endIndex = index + 1;
|
|
19400
|
+
index = string.indexOf(`
|
|
19401
|
+
`, endIndex);
|
|
19402
|
+
} while (index !== -1);
|
|
19403
|
+
returnValue += string.slice(endIndex);
|
|
19404
|
+
return returnValue;
|
|
19405
|
+
}
|
|
19406
|
+
|
|
19407
|
+
// ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
|
|
19408
|
+
var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
|
|
19409
|
+
var GENERATOR = Symbol("GENERATOR");
|
|
19410
|
+
var STYLER = Symbol("STYLER");
|
|
19411
|
+
var IS_EMPTY = Symbol("IS_EMPTY");
|
|
19412
|
+
var levelMapping = [
|
|
19413
|
+
"ansi",
|
|
19414
|
+
"ansi",
|
|
19415
|
+
"ansi256",
|
|
19416
|
+
"ansi16m"
|
|
19417
|
+
];
|
|
19418
|
+
var styles2 = Object.create(null);
|
|
19419
|
+
var applyOptions = (object, options = {}) => {
|
|
19420
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
19421
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
19422
|
+
}
|
|
19423
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
19424
|
+
object.level = options.level === undefined ? colorLevel : options.level;
|
|
19425
|
+
};
|
|
19426
|
+
var chalkFactory = (options) => {
|
|
19427
|
+
const chalk = (...strings) => strings.join(" ");
|
|
19428
|
+
applyOptions(chalk, options);
|
|
19429
|
+
Object.setPrototypeOf(chalk, createChalk.prototype);
|
|
19430
|
+
return chalk;
|
|
19431
|
+
};
|
|
19432
|
+
function createChalk(options) {
|
|
19433
|
+
return chalkFactory(options);
|
|
19434
|
+
}
|
|
19435
|
+
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
19436
|
+
for (const [styleName, style] of Object.entries(ansi_styles_default)) {
|
|
19437
|
+
styles2[styleName] = {
|
|
19438
|
+
get() {
|
|
19439
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
19440
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
19441
|
+
return builder;
|
|
19442
|
+
}
|
|
19443
|
+
};
|
|
19444
|
+
}
|
|
19445
|
+
styles2.visible = {
|
|
19446
|
+
get() {
|
|
19447
|
+
const builder = createBuilder(this, this[STYLER], true);
|
|
19448
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
19449
|
+
return builder;
|
|
19450
|
+
}
|
|
19451
|
+
};
|
|
19452
|
+
var getModelAnsi = (model, level, type, ...arguments_) => {
|
|
19453
|
+
if (model === "rgb") {
|
|
19454
|
+
if (level === "ansi16m") {
|
|
19455
|
+
return ansi_styles_default[type].ansi16m(...arguments_);
|
|
19456
|
+
}
|
|
19457
|
+
if (level === "ansi256") {
|
|
19458
|
+
return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
|
|
19459
|
+
}
|
|
19460
|
+
return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
|
|
19461
|
+
}
|
|
19462
|
+
if (model === "hex") {
|
|
19463
|
+
return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
|
|
19464
|
+
}
|
|
19465
|
+
return ansi_styles_default[type][model](...arguments_);
|
|
19466
|
+
};
|
|
19467
|
+
var usedModels = ["rgb", "hex", "ansi256"];
|
|
19468
|
+
for (const model of usedModels) {
|
|
19469
|
+
styles2[model] = {
|
|
19470
|
+
get() {
|
|
19471
|
+
const { level } = this;
|
|
19472
|
+
return function(...arguments_) {
|
|
19473
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
|
|
19474
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
19475
|
+
};
|
|
19476
|
+
}
|
|
19477
|
+
};
|
|
19478
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
19479
|
+
styles2[bgModel] = {
|
|
19480
|
+
get() {
|
|
19481
|
+
const { level } = this;
|
|
19482
|
+
return function(...arguments_) {
|
|
19483
|
+
const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
|
|
19484
|
+
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
19485
|
+
};
|
|
19486
|
+
}
|
|
19487
|
+
};
|
|
19488
|
+
}
|
|
19489
|
+
var proto = Object.defineProperties(() => {}, {
|
|
19490
|
+
...styles2,
|
|
19491
|
+
level: {
|
|
19492
|
+
enumerable: true,
|
|
19493
|
+
get() {
|
|
19494
|
+
return this[GENERATOR].level;
|
|
19495
|
+
},
|
|
19496
|
+
set(level) {
|
|
19497
|
+
this[GENERATOR].level = level;
|
|
19498
|
+
}
|
|
19499
|
+
}
|
|
19500
|
+
});
|
|
19501
|
+
var createStyler = (open, close, parent) => {
|
|
19502
|
+
let openAll;
|
|
19503
|
+
let closeAll;
|
|
19504
|
+
if (parent === undefined) {
|
|
19505
|
+
openAll = open;
|
|
19506
|
+
closeAll = close;
|
|
19507
|
+
} else {
|
|
19508
|
+
openAll = parent.openAll + open;
|
|
19509
|
+
closeAll = close + parent.closeAll;
|
|
19510
|
+
}
|
|
19511
|
+
return {
|
|
19512
|
+
open,
|
|
19513
|
+
close,
|
|
19514
|
+
openAll,
|
|
19515
|
+
closeAll,
|
|
19516
|
+
parent
|
|
19517
|
+
};
|
|
19518
|
+
};
|
|
19519
|
+
var createBuilder = (self2, _styler, _isEmpty) => {
|
|
19520
|
+
const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
19521
|
+
Object.setPrototypeOf(builder, proto);
|
|
19522
|
+
builder[GENERATOR] = self2;
|
|
19523
|
+
builder[STYLER] = _styler;
|
|
19524
|
+
builder[IS_EMPTY] = _isEmpty;
|
|
19525
|
+
return builder;
|
|
19526
|
+
};
|
|
19527
|
+
var applyStyle = (self2, string) => {
|
|
19528
|
+
if (self2.level <= 0 || !string) {
|
|
19529
|
+
return self2[IS_EMPTY] ? "" : string;
|
|
19530
|
+
}
|
|
19531
|
+
let styler = self2[STYLER];
|
|
19532
|
+
if (styler === undefined) {
|
|
19533
|
+
return string;
|
|
19534
|
+
}
|
|
19535
|
+
const { openAll, closeAll } = styler;
|
|
19536
|
+
if (string.includes("\x1B")) {
|
|
19537
|
+
while (styler !== undefined) {
|
|
19538
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
19539
|
+
styler = styler.parent;
|
|
19540
|
+
}
|
|
19541
|
+
}
|
|
19542
|
+
const lfIndex = string.indexOf(`
|
|
19543
|
+
`);
|
|
19544
|
+
if (lfIndex !== -1) {
|
|
19545
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
19546
|
+
}
|
|
19547
|
+
return openAll + string + closeAll;
|
|
19548
|
+
};
|
|
19549
|
+
Object.defineProperties(createChalk.prototype, styles2);
|
|
19550
|
+
var chalk = createChalk();
|
|
19551
|
+
var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
19552
|
+
var source_default = chalk;
|
|
19726
19553
|
|
|
19727
19554
|
// src/commands/app.ts
|
|
19728
|
-
init_source();
|
|
19729
19555
|
init_config();
|
|
19730
19556
|
|
|
19731
19557
|
// src/lib/nats.ts
|
|
@@ -19980,9 +19806,21 @@ async function connectNats(instanceUrl) {
|
|
|
19980
19806
|
const cred = getCredentialForInstance(instance);
|
|
19981
19807
|
return connectToInstance(instance, cred?.token);
|
|
19982
19808
|
}
|
|
19809
|
+
function encode(data) {
|
|
19810
|
+
return new TextEncoder().encode(JSON.stringify(data));
|
|
19811
|
+
}
|
|
19983
19812
|
function decode(data) {
|
|
19984
19813
|
return new TextDecoder().decode(data);
|
|
19985
19814
|
}
|
|
19815
|
+
async function natsRequest(subject, payload = {}, instanceUrl, timeout = 5000) {
|
|
19816
|
+
const nc = await connectNats(instanceUrl);
|
|
19817
|
+
try {
|
|
19818
|
+
const resp = await nc.request(subject, encode(payload), { timeout });
|
|
19819
|
+
return JSON.parse(decode(resp.data));
|
|
19820
|
+
} finally {
|
|
19821
|
+
await nc.close();
|
|
19822
|
+
}
|
|
19823
|
+
}
|
|
19986
19824
|
|
|
19987
19825
|
// src/commands/app.ts
|
|
19988
19826
|
var S = {
|
|
@@ -20009,18 +19847,6 @@ var S = {
|
|
|
20009
19847
|
};
|
|
20010
19848
|
var TIMEOUT = 5000;
|
|
20011
19849
|
var WORKFLOW_PROGRESS_TIMEOUT_MS = 300000;
|
|
20012
|
-
function encode(data) {
|
|
20013
|
-
return new TextEncoder().encode(JSON.stringify(data));
|
|
20014
|
-
}
|
|
20015
|
-
async function natsRequest(subject, payload = {}, instanceUrl) {
|
|
20016
|
-
const nc = await connectNats(instanceUrl);
|
|
20017
|
-
try {
|
|
20018
|
-
const resp = await nc.request(subject, encode(payload), { timeout: TIMEOUT });
|
|
20019
|
-
return JSON.parse(decode(resp.data));
|
|
20020
|
-
} finally {
|
|
20021
|
-
await nc.close();
|
|
20022
|
-
}
|
|
20023
|
-
}
|
|
20024
19850
|
async function checkTemporalAvailability(instanceUrl) {
|
|
20025
19851
|
const nc = await connectNats(instanceUrl);
|
|
20026
19852
|
try {
|
|
@@ -20082,8 +19908,8 @@ async function resolveRemote(name) {
|
|
|
20082
19908
|
await nc.close();
|
|
20083
19909
|
}
|
|
20084
19910
|
}
|
|
20085
|
-
async function remoteRequest(baseUrl,
|
|
20086
|
-
const url = `${baseUrl.replace(/\/$/, "")}${
|
|
19911
|
+
async function remoteRequest(baseUrl, path, opts) {
|
|
19912
|
+
const url = `${baseUrl.replace(/\/$/, "")}${path}`;
|
|
20087
19913
|
const resp = await fetch(url, {
|
|
20088
19914
|
method: opts?.method ?? "GET",
|
|
20089
19915
|
headers: opts?.body ? { "Content-Type": "application/json" } : {},
|
|
@@ -20095,11 +19921,7 @@ async function remoteRequest(baseUrl, path2, opts) {
|
|
|
20095
19921
|
}
|
|
20096
19922
|
return resp.json();
|
|
20097
19923
|
}
|
|
20098
|
-
var appCommand = new Command("app").description("Manage KhalOS apps — install, list, store, submit, approve
|
|
20099
|
-
appCommand.command("create").argument("[name]", "App name (kebab-case)").description("Scaffold a new KhalOS app in the monorepo").action(async (name) => {
|
|
20100
|
-
const { runAppCreate: runAppCreate2 } = await Promise.resolve().then(() => (init_app_create(), exports_app_create));
|
|
20101
|
-
await runAppCreate2(name);
|
|
20102
|
-
});
|
|
19924
|
+
var appCommand = new Command("app").description("Manage KhalOS apps — install, list, store, submit, approve");
|
|
20103
19925
|
appCommand.command("list").description("List installed apps").option("-i, --instance <url>", "Instance URL").action(async function(opts) {
|
|
20104
19926
|
const instance = resolveInstanceFromOpts(opts, this);
|
|
20105
19927
|
const data = await natsRequest(S.list, {}, instance);
|
|
@@ -20184,12 +20006,12 @@ appCommand.command("install").argument("<slug>", "App slug to install").descript
|
|
|
20184
20006
|
console.error(source_default.red(`App "${slug}" not found in remote "${opts.from}".`));
|
|
20185
20007
|
process.exit(1);
|
|
20186
20008
|
}
|
|
20187
|
-
const
|
|
20009
|
+
const path = `packages/${slug}-app`;
|
|
20188
20010
|
const result = await natsRequest(S.register, {
|
|
20189
20011
|
slug: remoteApp.slug,
|
|
20190
20012
|
name: remoteApp.name,
|
|
20191
20013
|
repoUrl: remoteApp.repoUrl,
|
|
20192
|
-
path
|
|
20014
|
+
path,
|
|
20193
20015
|
shortDescription: remoteApp.shortDescription,
|
|
20194
20016
|
category: remoteApp.category,
|
|
20195
20017
|
authorName: remoteApp.authorName,
|
|
@@ -20486,15 +20308,12 @@ ${source_default.bold("Leaderboard")}
|
|
|
20486
20308
|
});
|
|
20487
20309
|
|
|
20488
20310
|
// src/commands/deploy.ts
|
|
20489
|
-
|
|
20490
|
-
import {
|
|
20491
|
-
import { resolve as resolve2 } from "node:path";
|
|
20311
|
+
import { readFileSync as readFileSync3 } from "node:fs";
|
|
20312
|
+
import { resolve } from "node:path";
|
|
20492
20313
|
init_instances();
|
|
20493
20314
|
|
|
20494
20315
|
// src/providers/k3s.ts
|
|
20495
|
-
init_source();
|
|
20496
20316
|
import { execSync } from "node:child_process";
|
|
20497
|
-
|
|
20498
20317
|
class K3sProvider {
|
|
20499
20318
|
config;
|
|
20500
20319
|
name = "k3s";
|
|
@@ -20595,9 +20414,7 @@ class K3sProvider {
|
|
|
20595
20414
|
}
|
|
20596
20415
|
|
|
20597
20416
|
// src/providers/oci.ts
|
|
20598
|
-
init_source();
|
|
20599
20417
|
import { execSync as execSync2 } from "node:child_process";
|
|
20600
|
-
|
|
20601
20418
|
class OciProvider {
|
|
20602
20419
|
config;
|
|
20603
20420
|
name = "oci";
|
|
@@ -20715,7 +20532,7 @@ function getProvider(config) {
|
|
|
20715
20532
|
|
|
20716
20533
|
// src/commands/deploy.ts
|
|
20717
20534
|
function readProjectVersion(projectRoot) {
|
|
20718
|
-
const pkg = JSON.parse(
|
|
20535
|
+
const pkg = JSON.parse(readFileSync3(resolve(projectRoot, "package.json"), "utf-8"));
|
|
20719
20536
|
return pkg.version;
|
|
20720
20537
|
}
|
|
20721
20538
|
function resolveDeployInstance(nameOrUrl) {
|
|
@@ -20804,7 +20621,6 @@ var deployCommand = new Command("deploy").description("Deploy KhalOS to the acti
|
|
|
20804
20621
|
});
|
|
20805
20622
|
|
|
20806
20623
|
// src/commands/dev.ts
|
|
20807
|
-
init_source();
|
|
20808
20624
|
var devCommand = new Command("dev").description("Start KhalOS local development environment").option("-p, --port <port>", "Next.js port", "8888").action(async (opts) => {
|
|
20809
20625
|
const { createRuntime: createRuntime2 } = await Promise.resolve().then(() => (init_runtime(), exports_runtime));
|
|
20810
20626
|
console.log(`
|
|
@@ -20859,9 +20675,10 @@ ${source_default.bold("◆ Khal OS")} v${KHALOS_VERSION}
|
|
|
20859
20675
|
});
|
|
20860
20676
|
|
|
20861
20677
|
// src/commands/events.ts
|
|
20862
|
-
init_source();
|
|
20863
20678
|
var import_jetstream = __toESM(require_mod4(), 1);
|
|
20864
20679
|
init_config();
|
|
20680
|
+
|
|
20681
|
+
// src/lib/utils.ts
|
|
20865
20682
|
function parseDuration(input) {
|
|
20866
20683
|
const match = input.match(/^(\d+)(s|m|h|d)$/);
|
|
20867
20684
|
if (!match)
|
|
@@ -20871,6 +20688,8 @@ function parseDuration(input) {
|
|
|
20871
20688
|
const multipliers = { s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
20872
20689
|
return value * multipliers[unit];
|
|
20873
20690
|
}
|
|
20691
|
+
|
|
20692
|
+
// src/commands/events.ts
|
|
20874
20693
|
var SERVICE_COLORS = [
|
|
20875
20694
|
source_default.cyan,
|
|
20876
20695
|
source_default.magenta,
|
|
@@ -21000,11 +20819,10 @@ async function replayThenTail(nc, subject, opts) {
|
|
|
21000
20819
|
}
|
|
21001
20820
|
|
|
21002
20821
|
// src/commands/instances.ts
|
|
21003
|
-
|
|
21004
|
-
import { createInterface as createInterface2 } from "node:readline";
|
|
20822
|
+
import { createInterface } from "node:readline";
|
|
21005
20823
|
init_instances();
|
|
21006
20824
|
function makeAsker() {
|
|
21007
|
-
const rl =
|
|
20825
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
21008
20826
|
const ask = (q) => new Promise((r) => rl.question(q, r));
|
|
21009
20827
|
return { rl, ask };
|
|
21010
20828
|
}
|
|
@@ -21113,8 +20931,8 @@ var removeCommand = new Command("remove").alias("rm").description("Remove an ins
|
|
|
21113
20931
|
}
|
|
21114
20932
|
const { rl, ask } = makeAsker();
|
|
21115
20933
|
try {
|
|
21116
|
-
const
|
|
21117
|
-
if (
|
|
20934
|
+
const confirm = await ask(`Remove instance "${name}"? (y/N) `);
|
|
20935
|
+
if (confirm.toLowerCase() !== "y") {
|
|
21118
20936
|
console.log("Aborted.");
|
|
21119
20937
|
return;
|
|
21120
20938
|
}
|
|
@@ -21145,7 +20963,6 @@ ${source_default.bold(`Instance: ${name}`)}
|
|
|
21145
20963
|
var instancesCommand = new Command("instances").description("Manage instance profiles").addCommand(addCommand).addCommand(listCommand).addCommand(removeCommand).addCommand(showCommand);
|
|
21146
20964
|
|
|
21147
20965
|
// src/commands/login.ts
|
|
21148
|
-
init_source();
|
|
21149
20966
|
init_config();
|
|
21150
20967
|
var loginCommand = new Command("login").description("Authenticate with a KhalOS instance").option("-t, --token <token>", "API key (sk-*) for non-interactive auth").action(async (opts, cmd) => {
|
|
21151
20968
|
const instance = resolveInstance(cmd.parent?.opts().instance);
|
|
@@ -21166,7 +20983,6 @@ Generate a token: ${source_default.dim('khal-os token create --name "my-key"')}`
|
|
|
21166
20983
|
});
|
|
21167
20984
|
|
|
21168
20985
|
// src/commands/logout.ts
|
|
21169
|
-
init_source();
|
|
21170
20986
|
init_config();
|
|
21171
20987
|
var logoutCommand = new Command("logout").description("Remove stored credentials for a KhalOS instance").action(async (_opts, cmd) => {
|
|
21172
20988
|
const instance = resolveInstance(cmd.parent?.opts().instance);
|
|
@@ -21175,12 +20991,10 @@ var logoutCommand = new Command("logout").description("Remove stored credentials
|
|
|
21175
20991
|
});
|
|
21176
20992
|
|
|
21177
20993
|
// src/commands/logs.ts
|
|
21178
|
-
init_source();
|
|
21179
20994
|
var import_jetstream2 = __toESM(require_mod4(), 1);
|
|
21180
20995
|
init_config();
|
|
21181
20996
|
|
|
21182
20997
|
// src/lib/formatter.ts
|
|
21183
|
-
init_source();
|
|
21184
20998
|
var LEVEL_ICONS = {
|
|
21185
20999
|
debug: source_default.gray("DBG"),
|
|
21186
21000
|
info: source_default.blue("INF"),
|
|
@@ -21267,15 +21081,6 @@ function formatHealthTable(services) {
|
|
|
21267
21081
|
}
|
|
21268
21082
|
|
|
21269
21083
|
// src/commands/logs.ts
|
|
21270
|
-
function parseDuration2(input) {
|
|
21271
|
-
const match = input.match(/^(\d+)(s|m|h|d)$/);
|
|
21272
|
-
if (!match)
|
|
21273
|
-
throw new Error(`Invalid duration: "${input}". Use format like 5m, 1h, 30s`);
|
|
21274
|
-
const value = Number.parseInt(match[1], 10);
|
|
21275
|
-
const unit = match[2];
|
|
21276
|
-
const multipliers = { s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
21277
|
-
return value * multipliers[unit];
|
|
21278
|
-
}
|
|
21279
21084
|
var logsCommand = new Command("logs").description("Tail structured logs from services").argument("[service]", "Service name to tail logs for").option("--all", "Tail logs from all services").option("--since <duration>", "Replay logs from JetStream (e.g. 5m, 1h, 30s)").option("--level <level>", "Minimum log level (debug, info, warn, error)", "debug").option("--json", "Output raw JSON lines").option("-i, --instance <url>", "KhalOS instance URL").action(async (service, opts, cmd) => {
|
|
21280
21085
|
if (!service && !opts.all) {
|
|
21281
21086
|
console.error("Error: specify a service name or use --all");
|
|
@@ -21315,7 +21120,7 @@ async function liveTail2(nc, subject, opts) {
|
|
|
21315
21120
|
}
|
|
21316
21121
|
}
|
|
21317
21122
|
async function replayThenTail2(nc, subject, opts) {
|
|
21318
|
-
const sinceMs =
|
|
21123
|
+
const sinceMs = parseDuration(opts.since);
|
|
21319
21124
|
const startTime = new Date(Date.now() - sinceMs);
|
|
21320
21125
|
const js = import_jetstream2.jetstream(nc);
|
|
21321
21126
|
const consumer = await js.consumers.get("OS_O11Y_LOGS", {
|
|
@@ -21341,7 +21146,6 @@ async function replayThenTail2(nc, subject, opts) {
|
|
|
21341
21146
|
}
|
|
21342
21147
|
|
|
21343
21148
|
// src/commands/perf.ts
|
|
21344
|
-
init_source();
|
|
21345
21149
|
init_config();
|
|
21346
21150
|
|
|
21347
21151
|
// ../server-sdk/src/config.ts
|
|
@@ -21369,7 +21173,7 @@ var AGENT_WORKTREE_ROOT_ENV = process.env.OS_AGENT_WORKTREE_ROOT;
|
|
|
21369
21173
|
|
|
21370
21174
|
// ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/index.js
|
|
21371
21175
|
import os2 from "os";
|
|
21372
|
-
import
|
|
21176
|
+
import fs from "fs";
|
|
21373
21177
|
|
|
21374
21178
|
// ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/query.js
|
|
21375
21179
|
var originCache = new Map;
|
|
@@ -21379,9 +21183,9 @@ var CLOSE = {};
|
|
|
21379
21183
|
|
|
21380
21184
|
class Query extends Promise {
|
|
21381
21185
|
constructor(strings, args, handler, canceller, options = {}) {
|
|
21382
|
-
let
|
|
21186
|
+
let resolve2, reject;
|
|
21383
21187
|
super((a, b) => {
|
|
21384
|
-
|
|
21188
|
+
resolve2 = a;
|
|
21385
21189
|
reject = b;
|
|
21386
21190
|
});
|
|
21387
21191
|
this.tagged = Array.isArray(strings.raw);
|
|
@@ -21392,7 +21196,7 @@ class Query extends Promise {
|
|
|
21392
21196
|
this.options = options;
|
|
21393
21197
|
this.state = null;
|
|
21394
21198
|
this.statement = null;
|
|
21395
|
-
this.resolve = (x) => (this.active = false,
|
|
21199
|
+
this.resolve = (x) => (this.active = false, resolve2(x));
|
|
21396
21200
|
this.reject = (x) => (this.active = false, reject(x));
|
|
21397
21201
|
this.active = false;
|
|
21398
21202
|
this.cancelled = null;
|
|
@@ -21440,12 +21244,12 @@ class Query extends Promise {
|
|
|
21440
21244
|
if (this.executed && !this.active)
|
|
21441
21245
|
return { done: true };
|
|
21442
21246
|
prev && prev();
|
|
21443
|
-
const promise = new Promise((
|
|
21247
|
+
const promise = new Promise((resolve2, reject) => {
|
|
21444
21248
|
this.cursorFn = (value) => {
|
|
21445
|
-
|
|
21249
|
+
resolve2({ value, done: false });
|
|
21446
21250
|
return new Promise((r) => prev = r);
|
|
21447
21251
|
};
|
|
21448
|
-
this.resolve = () => (this.active = false,
|
|
21252
|
+
this.resolve = () => (this.active = false, resolve2({ done: true }));
|
|
21449
21253
|
this.reject = (x) => (this.active = false, reject(x));
|
|
21450
21254
|
});
|
|
21451
21255
|
this.execute();
|
|
@@ -22041,12 +21845,12 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
|
|
|
22041
21845
|
x.on("drain", drain);
|
|
22042
21846
|
return x;
|
|
22043
21847
|
}
|
|
22044
|
-
async function cancel({ pid, secret },
|
|
21848
|
+
async function cancel({ pid, secret }, resolve2, reject) {
|
|
22045
21849
|
try {
|
|
22046
21850
|
cancelMessage = bytes_default().i32(16).i32(80877102).i32(pid).i32(secret).end(16);
|
|
22047
21851
|
await connect2();
|
|
22048
21852
|
socket.once("error", reject);
|
|
22049
|
-
socket.once("close",
|
|
21853
|
+
socket.once("close", resolve2);
|
|
22050
21854
|
} catch (error2) {
|
|
22051
21855
|
reject(error2);
|
|
22052
21856
|
}
|
|
@@ -22764,13 +22568,13 @@ function Subscribe(postgres2, options) {
|
|
|
22764
22568
|
}
|
|
22765
22569
|
}
|
|
22766
22570
|
function handle(a, b2) {
|
|
22767
|
-
const
|
|
22571
|
+
const path = b2.relation.schema + "." + b2.relation.table;
|
|
22768
22572
|
call("*", a, b2);
|
|
22769
|
-
call("*:" +
|
|
22770
|
-
b2.relation.keys.length && call("*:" +
|
|
22573
|
+
call("*:" + path, a, b2);
|
|
22574
|
+
b2.relation.keys.length && call("*:" + path + "=" + b2.relation.keys.map((x2) => a[x2.name]), a, b2);
|
|
22771
22575
|
call(b2.command, a, b2);
|
|
22772
|
-
call(b2.command + ":" +
|
|
22773
|
-
b2.relation.keys.length && call(b2.command + ":" +
|
|
22576
|
+
call(b2.command + ":" + path, a, b2);
|
|
22577
|
+
b2.relation.keys.length && call(b2.command + ":" + path + "=" + b2.relation.keys.map((x2) => a[x2.name]), a, b2);
|
|
22774
22578
|
}
|
|
22775
22579
|
function pong() {
|
|
22776
22580
|
const x2 = Buffer.alloc(34);
|
|
@@ -22872,14 +22676,14 @@ function parseEvent(x) {
|
|
|
22872
22676
|
const xs = x.match(/^(\*|insert|update|delete)?:?([^.]+?\.?[^=]+)?=?(.+)?/i) || [];
|
|
22873
22677
|
if (!xs)
|
|
22874
22678
|
throw new Error("Malformed subscribe pattern: " + x);
|
|
22875
|
-
const [, command,
|
|
22876
|
-
return (command || "*") + (
|
|
22679
|
+
const [, command, path, key] = xs;
|
|
22680
|
+
return (command || "*") + (path ? ":" + (path.indexOf(".") === -1 ? "public." + path : path) : "") + (key ? "=" + key : "");
|
|
22877
22681
|
}
|
|
22878
22682
|
|
|
22879
22683
|
// ../../node_modules/.pnpm/postgres@3.4.8/node_modules/postgres/src/large.js
|
|
22880
22684
|
import Stream2 from "stream";
|
|
22881
22685
|
function largeObject(sql, oid, mode = 131072 | 262144) {
|
|
22882
|
-
return new Promise(async (
|
|
22686
|
+
return new Promise(async (resolve2, reject) => {
|
|
22883
22687
|
await sql.begin(async (sql2) => {
|
|
22884
22688
|
let finish;
|
|
22885
22689
|
!oid && ([{ oid }] = await sql2`select lo_creat(-1) as oid`);
|
|
@@ -22905,7 +22709,7 @@ function largeObject(sql, oid, mode = 131072 | 262144) {
|
|
|
22905
22709
|
) seek
|
|
22906
22710
|
`
|
|
22907
22711
|
};
|
|
22908
|
-
|
|
22712
|
+
resolve2(lo);
|
|
22909
22713
|
return new Promise(async (r) => finish = r);
|
|
22910
22714
|
async function readable({
|
|
22911
22715
|
highWaterMark = 2048 * 8,
|
|
@@ -23017,10 +22821,10 @@ function Postgres(a, b2) {
|
|
|
23017
22821
|
});
|
|
23018
22822
|
return query;
|
|
23019
22823
|
}
|
|
23020
|
-
function file(
|
|
22824
|
+
function file(path, args = [], options2 = {}) {
|
|
23021
22825
|
arguments.length === 2 && !Array.isArray(args) && (options2 = args, args = []);
|
|
23022
22826
|
const query = new Query([], args, (query2) => {
|
|
23023
|
-
|
|
22827
|
+
fs.readFile(path, "utf8", (err, string) => {
|
|
23024
22828
|
if (err)
|
|
23025
22829
|
return query2.reject(err);
|
|
23026
22830
|
query2.strings = [string];
|
|
@@ -23077,8 +22881,8 @@ function Postgres(a, b2) {
|
|
|
23077
22881
|
}
|
|
23078
22882
|
async function reserve() {
|
|
23079
22883
|
const queue = queue_default();
|
|
23080
|
-
const c = open.length ? open.shift() : await new Promise((
|
|
23081
|
-
const query = { reserve:
|
|
22884
|
+
const c = open.length ? open.shift() : await new Promise((resolve2, reject) => {
|
|
22885
|
+
const query = { reserve: resolve2, reject };
|
|
23082
22886
|
queries.push(query);
|
|
23083
22887
|
closed.length && connect2(closed.shift(), query);
|
|
23084
22888
|
});
|
|
@@ -23115,9 +22919,9 @@ function Postgres(a, b2) {
|
|
|
23115
22919
|
let uncaughtError, result;
|
|
23116
22920
|
name && await sql2`savepoint ${sql2(name)}`;
|
|
23117
22921
|
try {
|
|
23118
|
-
result = await new Promise((
|
|
22922
|
+
result = await new Promise((resolve2, reject) => {
|
|
23119
22923
|
const x = fn2(sql2);
|
|
23120
|
-
Promise.resolve(Array.isArray(x) ? Promise.all(x) : x).then(
|
|
22924
|
+
Promise.resolve(Array.isArray(x) ? Promise.all(x) : x).then(resolve2, reject);
|
|
23121
22925
|
});
|
|
23122
22926
|
if (uncaughtError)
|
|
23123
22927
|
throw uncaughtError;
|
|
@@ -23174,8 +22978,8 @@ function Postgres(a, b2) {
|
|
|
23174
22978
|
return c.execute(query) ? move(c, busy) : move(c, full);
|
|
23175
22979
|
}
|
|
23176
22980
|
function cancel(query) {
|
|
23177
|
-
return new Promise((
|
|
23178
|
-
query.state ? query.active ? connection_default(options).cancel(query.state,
|
|
22981
|
+
return new Promise((resolve2, reject) => {
|
|
22982
|
+
query.state ? query.active ? connection_default(options).cancel(query.state, resolve2, reject) : query.cancelled = { resolve: resolve2, reject } : (queries.remove(query), query.cancelled = true, query.reject(Errors.generic("57014", "canceling statement due to user request")), resolve2());
|
|
23179
22983
|
});
|
|
23180
22984
|
}
|
|
23181
22985
|
async function end({ timeout = null } = {}) {
|
|
@@ -23191,11 +22995,11 @@ function Postgres(a, b2) {
|
|
|
23191
22995
|
async function close() {
|
|
23192
22996
|
await Promise.all(connections.map((c) => c.end()));
|
|
23193
22997
|
}
|
|
23194
|
-
async function destroy(
|
|
22998
|
+
async function destroy(resolve2) {
|
|
23195
22999
|
await Promise.all(connections.map((c) => c.terminate()));
|
|
23196
23000
|
while (queries.length)
|
|
23197
23001
|
queries.shift().reject(Errors.connection("CONNECTION_DESTROYED", options));
|
|
23198
|
-
|
|
23002
|
+
resolve2();
|
|
23199
23003
|
}
|
|
23200
23004
|
function connect2(c, query) {
|
|
23201
23005
|
move(c, connecting);
|
|
@@ -23353,15 +23157,6 @@ async function closeDb() {
|
|
|
23353
23157
|
}
|
|
23354
23158
|
|
|
23355
23159
|
// src/commands/perf.ts
|
|
23356
|
-
function parseDuration3(input) {
|
|
23357
|
-
const match = input.match(/^(\d+)(s|m|h|d)$/);
|
|
23358
|
-
if (!match)
|
|
23359
|
-
throw new Error(`Invalid duration: "${input}". Use format like 5m, 1h, 30s`);
|
|
23360
|
-
const value = Number.parseInt(match[1], 10);
|
|
23361
|
-
const unit = match[2];
|
|
23362
|
-
const multipliers = { s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
23363
|
-
return value * multipliers[unit];
|
|
23364
|
-
}
|
|
23365
23160
|
var EVENT_LOOP_LAG_THRESHOLD_MS = 50;
|
|
23366
23161
|
var COMPUTE_RATIO_THRESHOLD = 0.5;
|
|
23367
23162
|
var IO_RATIO_THRESHOLD = 0.8;
|
|
@@ -23628,7 +23423,7 @@ var perfCommand = new Command("perf").description("Performance analysis for Rust
|
|
|
23628
23423
|
perfCommand.command("hotspots").description("Rank handlers by cumulative latency and classify CPU/IO bound").requiredOption("--since <duration>", "Time window to analyze (e.g. 1h, 24h, 7d)").option("--json", "Output as JSON").option("--limit <n>", "Max rows to show", "50").option("-i, --instance <url>", "KhalOS instance URL").action(async (opts, cmd) => {
|
|
23629
23424
|
const _instance = resolveInstance(opts.instance || cmd.parent?.parent?.opts().instance);
|
|
23630
23425
|
try {
|
|
23631
|
-
const sinceMs =
|
|
23426
|
+
const sinceMs = parseDuration(opts.since);
|
|
23632
23427
|
const rows = await queryHotspots(sinceMs);
|
|
23633
23428
|
const limited = rows.slice(0, Number.parseInt(opts.limit, 10));
|
|
23634
23429
|
if (opts.json) {
|
|
@@ -23668,442 +23463,7 @@ perfCommand.command("snapshot").description("Show latest process metrics for all
|
|
|
23668
23463
|
}
|
|
23669
23464
|
});
|
|
23670
23465
|
|
|
23671
|
-
// src/commands/qa/assert-apps.ts
|
|
23672
|
-
init_source();
|
|
23673
|
-
|
|
23674
|
-
// src/commands/qa/lib.ts
|
|
23675
|
-
import { execSync as execSync4 } from "node:child_process";
|
|
23676
|
-
var DEFAULT_URL = "http://localhost:8888";
|
|
23677
|
-
var DEFAULT_SESSION = "khal-qa";
|
|
23678
|
-
function resolveUrl(urlArg) {
|
|
23679
|
-
if (urlArg)
|
|
23680
|
-
return urlArg;
|
|
23681
|
-
if (process.env.DEV_SLOT_URL)
|
|
23682
|
-
return process.env.DEV_SLOT_URL;
|
|
23683
|
-
return DEFAULT_URL;
|
|
23684
|
-
}
|
|
23685
|
-
function resolveSession(sessionArg) {
|
|
23686
|
-
if (sessionArg)
|
|
23687
|
-
return sessionArg;
|
|
23688
|
-
if (process.env.GENIE_TEAM)
|
|
23689
|
-
return `khal-qa-${process.env.GENIE_TEAM}`;
|
|
23690
|
-
return DEFAULT_SESSION;
|
|
23691
|
-
}
|
|
23692
|
-
function execBrowser(cmd, session) {
|
|
23693
|
-
const s = resolveSession(session);
|
|
23694
|
-
const full = `agent-browser --session ${s} ${cmd}`;
|
|
23695
|
-
return execSync4(full, { encoding: "utf-8", timeout: 30000 }).trim();
|
|
23696
|
-
}
|
|
23697
|
-
function openAndWait(url, session) {
|
|
23698
|
-
execBrowser(`open "${url}" --user-agent "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/131.0.0.0 Safari/537.36"`, session);
|
|
23699
|
-
execBrowser("wait --load networkidle", session);
|
|
23700
|
-
}
|
|
23701
|
-
function ensureLoggedIn(url, session) {
|
|
23702
|
-
openAndWait(url, session);
|
|
23703
|
-
}
|
|
23704
|
-
|
|
23705
|
-
// src/commands/qa/assert-apps.ts
|
|
23706
|
-
var assertAppsCommand = new Command("apps").description("Compare NATS app count vs visible desktop icons").argument("[url]", "Target URL").option("--session <name>", "Browser session name").option("--json", "JSON output").action(async (urlArg, opts) => {
|
|
23707
|
-
const url = resolveUrl(urlArg);
|
|
23708
|
-
const session = resolveSession(opts.session);
|
|
23709
|
-
let expectedApps = [];
|
|
23710
|
-
try {
|
|
23711
|
-
const nc = await connectNats();
|
|
23712
|
-
const resp = await nc.request("os.apps.list", new TextEncoder().encode(JSON.stringify({})), {
|
|
23713
|
-
timeout: 5000
|
|
23714
|
-
});
|
|
23715
|
-
const data = JSON.parse(decode(resp.data));
|
|
23716
|
-
expectedApps = data.apps.map((a) => a.store?.name ?? a.slug).filter(Boolean);
|
|
23717
|
-
await nc.close();
|
|
23718
|
-
} catch (_err) {
|
|
23719
|
-
console.error(source_default.red("Failed to query NATS for app list"));
|
|
23720
|
-
process.exitCode = 1;
|
|
23721
|
-
return;
|
|
23722
|
-
}
|
|
23723
|
-
ensureLoggedIn(url, session);
|
|
23724
|
-
const snapshot = execBrowser("snapshot -i -c", session);
|
|
23725
|
-
const visibleNames = [];
|
|
23726
|
-
for (const line of snapshot.split(`
|
|
23727
|
-
`)) {
|
|
23728
|
-
const nameMatch = line.match(/"([^"]+)"/);
|
|
23729
|
-
if (nameMatch) {
|
|
23730
|
-
visibleNames.push(nameMatch[1]);
|
|
23731
|
-
}
|
|
23732
|
-
}
|
|
23733
|
-
const missing = expectedApps.filter((name) => !visibleNames.some((v) => v.toLowerCase().includes(name.toLowerCase())));
|
|
23734
|
-
const pass = missing.length === 0;
|
|
23735
|
-
const result = {
|
|
23736
|
-
pass,
|
|
23737
|
-
expected: expectedApps.length,
|
|
23738
|
-
visible: expectedApps.length - missing.length,
|
|
23739
|
-
missing,
|
|
23740
|
-
expectedApps
|
|
23741
|
-
};
|
|
23742
|
-
if (opts.json) {
|
|
23743
|
-
console.log(JSON.stringify(result, null, 2));
|
|
23744
|
-
} else {
|
|
23745
|
-
const icon = pass ? source_default.green("PASS") : source_default.red("FAIL");
|
|
23746
|
-
console.log(`${icon}: ${result.expected} apps expected, ${result.visible} visible`);
|
|
23747
|
-
if (missing.length > 0) {
|
|
23748
|
-
console.log(source_default.red(` Missing: ${missing.join(", ")}`));
|
|
23749
|
-
}
|
|
23750
|
-
}
|
|
23751
|
-
if (!pass)
|
|
23752
|
-
process.exitCode = 1;
|
|
23753
|
-
});
|
|
23754
|
-
|
|
23755
|
-
// src/commands/qa/assert-auth.ts
|
|
23756
|
-
init_source();
|
|
23757
|
-
var assertAuthCommand = new Command("auth").description("Test auth redirect + HeadlessChrome bypass").argument("[url]", "Target URL").option("--json", "JSON output").action(async (urlArg, opts) => {
|
|
23758
|
-
const base = resolveUrl(urlArg);
|
|
23759
|
-
const checks = [];
|
|
23760
|
-
try {
|
|
23761
|
-
const res = await fetch(base, {
|
|
23762
|
-
redirect: "manual",
|
|
23763
|
-
signal: AbortSignal.timeout(5000)
|
|
23764
|
-
});
|
|
23765
|
-
const isRedirect = res.status === 307 || res.status === 302 || res.status === 301;
|
|
23766
|
-
checks.push({
|
|
23767
|
-
name: "auth-redirect",
|
|
23768
|
-
pass: isRedirect,
|
|
23769
|
-
detail: `HTTP ${res.status}${isRedirect ? " (redirect)" : " (expected 307)"}`
|
|
23770
|
-
});
|
|
23771
|
-
} catch (err) {
|
|
23772
|
-
checks.push({
|
|
23773
|
-
name: "auth-redirect",
|
|
23774
|
-
pass: false,
|
|
23775
|
-
detail: `unreachable: ${err instanceof Error ? err.message : "unknown"}`
|
|
23776
|
-
});
|
|
23777
|
-
}
|
|
23778
|
-
try {
|
|
23779
|
-
const res = await fetch(`${base}/desktop`, {
|
|
23780
|
-
redirect: "follow",
|
|
23781
|
-
headers: {
|
|
23782
|
-
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/131.0.0.0 Safari/537.36"
|
|
23783
|
-
},
|
|
23784
|
-
signal: AbortSignal.timeout(1e4)
|
|
23785
|
-
});
|
|
23786
|
-
const isOk = res.status === 200;
|
|
23787
|
-
checks.push({
|
|
23788
|
-
name: "headless-bypass",
|
|
23789
|
-
pass: isOk,
|
|
23790
|
-
detail: `HTTP ${res.status}${isOk ? " (desktop rendered)" : " (expected 200)"}`
|
|
23791
|
-
});
|
|
23792
|
-
} catch (err) {
|
|
23793
|
-
checks.push({
|
|
23794
|
-
name: "headless-bypass",
|
|
23795
|
-
pass: false,
|
|
23796
|
-
detail: `unreachable: ${err instanceof Error ? err.message : "unknown"}`
|
|
23797
|
-
});
|
|
23798
|
-
}
|
|
23799
|
-
const allPass = checks.every((c) => c.pass);
|
|
23800
|
-
if (opts.json) {
|
|
23801
|
-
console.log(JSON.stringify({ pass: allPass, checks }, null, 2));
|
|
23802
|
-
} else {
|
|
23803
|
-
const icon = allPass ? source_default.green("PASS") : source_default.red("FAIL");
|
|
23804
|
-
console.log(`${icon}: auth redirect works, headless bypass works`);
|
|
23805
|
-
for (const c of checks) {
|
|
23806
|
-
const ci = c.pass ? source_default.green("✔") : source_default.red("✘");
|
|
23807
|
-
console.log(` ${ci} ${c.name}: ${c.detail}`);
|
|
23808
|
-
}
|
|
23809
|
-
}
|
|
23810
|
-
if (!allPass)
|
|
23811
|
-
process.exitCode = 1;
|
|
23812
|
-
});
|
|
23813
|
-
|
|
23814
|
-
// src/commands/qa/assert-health.ts
|
|
23815
|
-
init_source();
|
|
23816
|
-
import { readFileSync as readFileSync6 } from "node:fs";
|
|
23817
|
-
var assertHealthCommand = new Command("health").description("Validate API health + NATS + version").argument("[url]", "Target URL").option("--json", "JSON output").action(async (urlArg, opts) => {
|
|
23818
|
-
const base = resolveUrl(urlArg);
|
|
23819
|
-
const checks = [];
|
|
23820
|
-
let health = null;
|
|
23821
|
-
try {
|
|
23822
|
-
const res = await fetch(`${base}/api/health`, { signal: AbortSignal.timeout(5000) });
|
|
23823
|
-
if (res.ok) {
|
|
23824
|
-
health = await res.json();
|
|
23825
|
-
checks.push({
|
|
23826
|
-
name: "health-endpoint",
|
|
23827
|
-
pass: health.status === "ok",
|
|
23828
|
-
detail: `status=${health.status}`
|
|
23829
|
-
});
|
|
23830
|
-
} else {
|
|
23831
|
-
checks.push({ name: "health-endpoint", pass: false, detail: `HTTP ${res.status}` });
|
|
23832
|
-
}
|
|
23833
|
-
} catch {
|
|
23834
|
-
checks.push({ name: "health-endpoint", pass: false, detail: "unreachable" });
|
|
23835
|
-
}
|
|
23836
|
-
checks.push({
|
|
23837
|
-
name: "nats-connected",
|
|
23838
|
-
pass: health?.nats?.connected === true,
|
|
23839
|
-
detail: health?.nats?.connected ? "connected" : "disconnected"
|
|
23840
|
-
});
|
|
23841
|
-
let pkgVersion = "unknown";
|
|
23842
|
-
try {
|
|
23843
|
-
const pkg = JSON.parse(readFileSync6("package.json", "utf-8"));
|
|
23844
|
-
pkgVersion = pkg.version;
|
|
23845
|
-
} catch {}
|
|
23846
|
-
const versionMatch = health?.version === pkgVersion;
|
|
23847
|
-
checks.push({
|
|
23848
|
-
name: "version-match",
|
|
23849
|
-
pass: versionMatch || pkgVersion === "unknown",
|
|
23850
|
-
detail: `api=${health?.version ?? "unknown"} pkg=${pkgVersion}`
|
|
23851
|
-
});
|
|
23852
|
-
try {
|
|
23853
|
-
const res = await fetch(`${base}/api/server-info`, { signal: AbortSignal.timeout(5000) });
|
|
23854
|
-
checks.push({
|
|
23855
|
-
name: "server-info",
|
|
23856
|
-
pass: res.ok,
|
|
23857
|
-
detail: res.ok ? "reachable" : `HTTP ${res.status}`
|
|
23858
|
-
});
|
|
23859
|
-
} catch {
|
|
23860
|
-
checks.push({ name: "server-info", pass: false, detail: "unreachable" });
|
|
23861
|
-
}
|
|
23862
|
-
const allPass = checks.every((c) => c.pass);
|
|
23863
|
-
if (opts.json) {
|
|
23864
|
-
console.log(JSON.stringify({ pass: allPass, checks }, null, 2));
|
|
23865
|
-
} else {
|
|
23866
|
-
const icon = allPass ? source_default.green("PASS") : source_default.red("FAIL");
|
|
23867
|
-
const summary = [
|
|
23868
|
-
`health ${health?.status ?? "down"}`,
|
|
23869
|
-
`NATS ${health?.nats?.connected ? "connected" : "disconnected"}`,
|
|
23870
|
-
`v${health?.version ?? "?"}`
|
|
23871
|
-
].join(", ");
|
|
23872
|
-
console.log(`${icon}: ${summary}`);
|
|
23873
|
-
for (const c of checks) {
|
|
23874
|
-
const ci = c.pass ? source_default.green("✔") : source_default.red("✘");
|
|
23875
|
-
console.log(` ${ci} ${c.name}: ${c.detail}`);
|
|
23876
|
-
}
|
|
23877
|
-
}
|
|
23878
|
-
if (!allPass)
|
|
23879
|
-
process.exitCode = 1;
|
|
23880
|
-
});
|
|
23881
|
-
|
|
23882
|
-
// src/commands/qa/assert.ts
|
|
23883
|
-
var assertCommand = new Command("assert").description("Run QA assertions (ground truth vs reality)");
|
|
23884
|
-
assertCommand.addCommand(assertAppsCommand);
|
|
23885
|
-
assertCommand.addCommand(assertHealthCommand);
|
|
23886
|
-
assertCommand.addCommand(assertAuthCommand);
|
|
23887
|
-
|
|
23888
|
-
// src/commands/qa/bug.ts
|
|
23889
|
-
init_source();
|
|
23890
|
-
import { execSync as execSync5 } from "node:child_process";
|
|
23891
|
-
import { mkdirSync as mkdirSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
23892
|
-
var bugCommand = new Command("bug").description("Create a GitHub issue with screenshot + console + DOM evidence").argument("<title>", "Bug title").argument("[url]", "Target URL").option("--session <name>", "Browser session name").option("--label <labels>", "Additional labels (comma-separated)", "").action(async (title, urlArg, opts) => {
|
|
23893
|
-
const url = resolveUrl(urlArg);
|
|
23894
|
-
const session = resolveSession(opts.session);
|
|
23895
|
-
console.log(source_default.dim("Capturing evidence..."));
|
|
23896
|
-
ensureLoggedIn(url, session);
|
|
23897
|
-
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
23898
|
-
const dir = ".qa/screenshots";
|
|
23899
|
-
mkdirSync6(dir, { recursive: true });
|
|
23900
|
-
const screenshotPath = `${dir}/bug-${ts}.png`;
|
|
23901
|
-
execBrowser(`screenshot ${screenshotPath} --full`, session);
|
|
23902
|
-
const consoleOut = execBrowser("console", session);
|
|
23903
|
-
const errors = consoleOut.split(`
|
|
23904
|
-
`).filter((l) => /\[error\]/i.test(l)).join(`
|
|
23905
|
-
`);
|
|
23906
|
-
const snapshot = execBrowser("snapshot -c -i", session);
|
|
23907
|
-
const currentUrl = execBrowser("get url", session);
|
|
23908
|
-
const snapshotPath = `${dir}/bug-${ts}-snapshot.txt`;
|
|
23909
|
-
writeFileSync5(snapshotPath, snapshot);
|
|
23910
|
-
const body = [
|
|
23911
|
-
"## Environment",
|
|
23912
|
-
`- **URL:** ${currentUrl}`,
|
|
23913
|
-
`- **Timestamp:** ${new Date().toISOString()}`,
|
|
23914
|
-
"",
|
|
23915
|
-
"## Console Errors",
|
|
23916
|
-
errors ? `\`\`\`
|
|
23917
|
-
${errors}
|
|
23918
|
-
\`\`\`` : "_No console errors_",
|
|
23919
|
-
"",
|
|
23920
|
-
"## DOM Snapshot (interactive elements)",
|
|
23921
|
-
`\`\`\`
|
|
23922
|
-
${snapshot.slice(0, 3000)}
|
|
23923
|
-
\`\`\``,
|
|
23924
|
-
"",
|
|
23925
|
-
"## Screenshot",
|
|
23926
|
-
`Saved to: \`${screenshotPath}\``
|
|
23927
|
-
].join(`
|
|
23928
|
-
`);
|
|
23929
|
-
const labels = ["bug", ...opts.label ? opts.label.split(",") : []].join(",");
|
|
23930
|
-
const ghCmd = `gh issue create --title ${JSON.stringify(title)} --body ${JSON.stringify(body)} --label "${labels}"`;
|
|
23931
|
-
try {
|
|
23932
|
-
const issueUrl = execSync5(ghCmd, { encoding: "utf-8", timeout: 15000 }).trim();
|
|
23933
|
-
console.log(`
|
|
23934
|
-
${source_default.green("✔")} Issue created: ${issueUrl}`);
|
|
23935
|
-
console.log(` ${source_default.dim("Screenshot:")} ${screenshotPath}`);
|
|
23936
|
-
console.log(` ${source_default.dim("Snapshot:")} ${snapshotPath}`);
|
|
23937
|
-
} catch (_err) {
|
|
23938
|
-
console.error(source_default.red("Failed to create GitHub issue."));
|
|
23939
|
-
console.error(source_default.dim("Body saved to:"), snapshotPath);
|
|
23940
|
-
writeFileSync5(`${dir}/bug-${ts}-body.md`, body);
|
|
23941
|
-
process.exitCode = 1;
|
|
23942
|
-
}
|
|
23943
|
-
});
|
|
23944
|
-
|
|
23945
|
-
// src/commands/qa/console.ts
|
|
23946
|
-
init_source();
|
|
23947
|
-
var consoleCommand = new Command("console").description("Capture and categorize browser console messages").argument("[url]", "Target URL").option("--session <name>", "Browser session name").option("--json", "JSON output").action(async (urlArg, opts) => {
|
|
23948
|
-
const url = resolveUrl(urlArg);
|
|
23949
|
-
const session = resolveSession(opts.session);
|
|
23950
|
-
ensureLoggedIn(url, session);
|
|
23951
|
-
const raw = execBrowser("console", session);
|
|
23952
|
-
const lines = raw.split(`
|
|
23953
|
-
`).filter(Boolean);
|
|
23954
|
-
const errors = lines.filter((l) => /\[error\]/i.test(l));
|
|
23955
|
-
const warnings = lines.filter((l) => /\[warn(ing)?\]/i.test(l));
|
|
23956
|
-
const info = lines.filter((l) => /\[info\]/i.test(l) || /\[log\]/i.test(l));
|
|
23957
|
-
const other = lines.filter((l) => !/\[error\]/i.test(l) && !/\[warn(ing)?\]/i.test(l) && !/\[info\]/i.test(l) && !/\[log\]/i.test(l));
|
|
23958
|
-
if (opts.json) {
|
|
23959
|
-
console.log(JSON.stringify({ errors, warnings, info, other, total: lines.length }, null, 2));
|
|
23960
|
-
return;
|
|
23961
|
-
}
|
|
23962
|
-
console.log(`
|
|
23963
|
-
${source_default.bold("QA Console")}
|
|
23964
|
-
`);
|
|
23965
|
-
console.log(` Total: ${lines.length} messages`);
|
|
23966
|
-
console.log(` ${source_default.red(`Errors: ${errors.length}`)}`);
|
|
23967
|
-
console.log(` ${source_default.yellow(`Warnings: ${warnings.length}`)}`);
|
|
23968
|
-
console.log(` ${source_default.dim(`Info: ${info.length}`)}`);
|
|
23969
|
-
console.log("");
|
|
23970
|
-
if (errors.length > 0) {
|
|
23971
|
-
console.log(source_default.red.bold("Errors:"));
|
|
23972
|
-
for (const e of errors)
|
|
23973
|
-
console.log(` ${e}`);
|
|
23974
|
-
console.log("");
|
|
23975
|
-
}
|
|
23976
|
-
if (warnings.length > 0) {
|
|
23977
|
-
console.log(source_default.yellow.bold("Warnings:"));
|
|
23978
|
-
for (const w of warnings)
|
|
23979
|
-
console.log(` ${w}`);
|
|
23980
|
-
console.log("");
|
|
23981
|
-
}
|
|
23982
|
-
});
|
|
23983
|
-
|
|
23984
|
-
// src/commands/qa/health.ts
|
|
23985
|
-
init_source();
|
|
23986
|
-
var healthCommand = new Command("health").description("Check /api/health and /api/server-info").argument("[url]", "Target URL").option("--json", "JSON output").action(async (urlArg, opts) => {
|
|
23987
|
-
const base = resolveUrl(urlArg);
|
|
23988
|
-
const [healthRes, infoRes] = await Promise.allSettled([
|
|
23989
|
-
fetch(`${base}/api/health`, { signal: AbortSignal.timeout(5000) }),
|
|
23990
|
-
fetch(`${base}/api/server-info`, { signal: AbortSignal.timeout(5000) })
|
|
23991
|
-
]);
|
|
23992
|
-
const health = healthRes.status === "fulfilled" && healthRes.value.ok ? await healthRes.value.json() : null;
|
|
23993
|
-
const info = infoRes.status === "fulfilled" && infoRes.value.ok ? await infoRes.value.json() : null;
|
|
23994
|
-
const result = {
|
|
23995
|
-
healthy: health?.status === "ok",
|
|
23996
|
-
status: health?.status ?? "unreachable",
|
|
23997
|
-
version: health?.version ?? "unknown",
|
|
23998
|
-
nats: health?.nats?.connected ?? false,
|
|
23999
|
-
uptime: health?.uptime ?? 0,
|
|
24000
|
-
capabilities: info?.capabilities ?? []
|
|
24001
|
-
};
|
|
24002
|
-
if (opts.json) {
|
|
24003
|
-
console.log(JSON.stringify(result, null, 2));
|
|
24004
|
-
return;
|
|
24005
|
-
}
|
|
24006
|
-
const statusIcon = result.healthy ? source_default.green("✔") : source_default.red("✘");
|
|
24007
|
-
const natsIcon = result.nats ? source_default.green("✔") : source_default.red("✘");
|
|
24008
|
-
console.log(`
|
|
24009
|
-
${source_default.bold("QA Health")}
|
|
24010
|
-
`);
|
|
24011
|
-
console.log(` ${statusIcon} Status: ${result.status}`);
|
|
24012
|
-
console.log(` ${natsIcon} NATS: ${result.nats ? "connected" : "disconnected"}`);
|
|
24013
|
-
console.log(` ${source_default.dim("Version:")} ${result.version}`);
|
|
24014
|
-
console.log(` ${source_default.dim("Uptime:")} ${result.uptime}s`);
|
|
24015
|
-
if (result.capabilities.length > 0) {
|
|
24016
|
-
console.log(` ${source_default.dim("Capabilities:")} ${result.capabilities.join(", ")}`);
|
|
24017
|
-
}
|
|
24018
|
-
console.log("");
|
|
24019
|
-
if (!result.healthy) {
|
|
24020
|
-
process.exitCode = 1;
|
|
24021
|
-
}
|
|
24022
|
-
});
|
|
24023
|
-
|
|
24024
|
-
// src/commands/qa/login.ts
|
|
24025
|
-
init_source();
|
|
24026
|
-
var loginCommand2 = new Command("login").description("Authenticate via HeadlessChrome bypass and persist session").argument("[url]", "Target URL").option("--session <name>", "Browser session name").action(async (urlArg, opts) => {
|
|
24027
|
-
const url = resolveUrl(urlArg);
|
|
24028
|
-
const session = resolveSession(opts.session);
|
|
24029
|
-
console.log(source_default.dim(`Logging in to ${url} (session: ${session})...`));
|
|
24030
|
-
ensureLoggedIn(url, session);
|
|
24031
|
-
console.log(source_default.green("✔ Logged in. Session persisted."));
|
|
24032
|
-
console.log(source_default.dim("Subsequent QA commands will reuse this session."));
|
|
24033
|
-
});
|
|
24034
|
-
|
|
24035
|
-
// src/commands/qa/look.ts
|
|
24036
|
-
init_source();
|
|
24037
|
-
import { mkdirSync as mkdirSync7 } from "node:fs";
|
|
24038
|
-
var lookCommand = new Command("look").description("Screenshot + DOM snapshot + console errors").argument("[url]", "Target URL").option("--session <name>", "Browser session name").option("--full", "Full page screenshot").action(async (urlArg, opts) => {
|
|
24039
|
-
const url = resolveUrl(urlArg);
|
|
24040
|
-
const session = resolveSession(opts.session);
|
|
24041
|
-
ensureLoggedIn(url, session);
|
|
24042
|
-
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
24043
|
-
const dir = ".qa/screenshots";
|
|
24044
|
-
mkdirSync7(dir, { recursive: true });
|
|
24045
|
-
const screenshotPath = `${dir}/${ts}.png`;
|
|
24046
|
-
const screenshotFlags = opts.full ? "--full" : "";
|
|
24047
|
-
execBrowser(`screenshot ${screenshotPath} ${screenshotFlags}`.trim(), session);
|
|
24048
|
-
const snapshot = execBrowser("snapshot -c", session);
|
|
24049
|
-
const elementCount = (snapshot.match(/^\s*-/gm) || []).length;
|
|
24050
|
-
const interactiveCount = (snapshot.match(/\[ref=/g) || []).length;
|
|
24051
|
-
const consoleOut = execBrowser("console", session);
|
|
24052
|
-
const errorCount = (consoleOut.match(/\[error\]/gi) || []).length;
|
|
24053
|
-
const warnCount = (consoleOut.match(/\[warn(ing)?\]/gi) || []).length;
|
|
24054
|
-
const currentUrl = execBrowser("get url", session);
|
|
24055
|
-
console.log(`
|
|
24056
|
-
${source_default.bold("QA Look")}
|
|
24057
|
-
`);
|
|
24058
|
-
console.log(` ${source_default.dim("URL:")} ${currentUrl}`);
|
|
24059
|
-
console.log(` ${source_default.dim("Screenshot:")} ${screenshotPath}`);
|
|
24060
|
-
console.log(` ${source_default.dim("Console:")} ${errorCount} errors, ${warnCount} warnings`);
|
|
24061
|
-
console.log(` ${source_default.dim("DOM:")} ${elementCount} elements, ${interactiveCount} interactive`);
|
|
24062
|
-
console.log("");
|
|
24063
|
-
if (errorCount > 0) {
|
|
24064
|
-
console.log(source_default.red("Console Errors:"));
|
|
24065
|
-
console.log(consoleOut.split(`
|
|
24066
|
-
`).filter((l) => /\[error\]/i.test(l)).join(`
|
|
24067
|
-
`));
|
|
24068
|
-
console.log("");
|
|
24069
|
-
}
|
|
24070
|
-
});
|
|
24071
|
-
|
|
24072
|
-
// src/commands/qa/session.ts
|
|
24073
|
-
init_source();
|
|
24074
|
-
var listCommand2 = new Command("list").description("List active browser sessions").action(async () => {
|
|
24075
|
-
const out = execBrowser("session list", undefined);
|
|
24076
|
-
console.log(`
|
|
24077
|
-
${source_default.bold("Active Sessions")}
|
|
24078
|
-
`);
|
|
24079
|
-
console.log(out || source_default.dim("No active sessions"));
|
|
24080
|
-
console.log("");
|
|
24081
|
-
});
|
|
24082
|
-
var closeCommand = new Command("close").description("Close the QA browser session").option("--session <name>", "Browser session name").action(async (opts) => {
|
|
24083
|
-
const session = resolveSession(opts.session);
|
|
24084
|
-
try {
|
|
24085
|
-
execBrowser("close", session);
|
|
24086
|
-
console.log(source_default.green(`✔ Session "${session}" closed.`));
|
|
24087
|
-
} catch {
|
|
24088
|
-
console.log(source_default.dim(`Session "${session}" was not active.`));
|
|
24089
|
-
}
|
|
24090
|
-
});
|
|
24091
|
-
var sessionCommand = new Command("session").description("Manage QA browser sessions");
|
|
24092
|
-
sessionCommand.addCommand(listCommand2);
|
|
24093
|
-
sessionCommand.addCommand(closeCommand);
|
|
24094
|
-
|
|
24095
|
-
// src/commands/qa.ts
|
|
24096
|
-
var qaCommand = new Command("qa").description("QA tools — screenshot, assert, health check, bug report");
|
|
24097
|
-
qaCommand.addCommand(lookCommand);
|
|
24098
|
-
qaCommand.addCommand(healthCommand);
|
|
24099
|
-
qaCommand.addCommand(consoleCommand);
|
|
24100
|
-
qaCommand.addCommand(bugCommand);
|
|
24101
|
-
qaCommand.addCommand(loginCommand2);
|
|
24102
|
-
qaCommand.addCommand(sessionCommand);
|
|
24103
|
-
qaCommand.addCommand(assertCommand);
|
|
24104
|
-
|
|
24105
23466
|
// src/commands/start.ts
|
|
24106
|
-
init_source();
|
|
24107
23467
|
var startCommand = new Command("start").description('Alias for "dev" — start KhalOS local development environment').option("-p, --port <port>", "Next.js port", "8888").action(async (opts) => {
|
|
24108
23468
|
console.log(source_default.yellow(`Note: "khal-os start" is deprecated. Use "khal-os dev" instead.
|
|
24109
23469
|
`));
|
|
@@ -24113,7 +23473,6 @@ var startCommand = new Command("start").description('Alias for "dev" — start K
|
|
|
24113
23473
|
});
|
|
24114
23474
|
|
|
24115
23475
|
// src/commands/status.ts
|
|
24116
|
-
init_source();
|
|
24117
23476
|
init_config();
|
|
24118
23477
|
function formatUptime2(seconds) {
|
|
24119
23478
|
const days = Math.floor(seconds / 86400);
|
|
@@ -24229,19 +23588,18 @@ async function watchHealth(nc, subject) {
|
|
|
24229
23588
|
}
|
|
24230
23589
|
|
|
24231
23590
|
// src/commands/stop.ts
|
|
24232
|
-
|
|
24233
|
-
import { existsSync as existsSync7, readFileSync as readFileSync7, unlinkSync } from "node:fs";
|
|
23591
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5, unlinkSync } from "node:fs";
|
|
24234
23592
|
import { homedir as homedir4 } from "node:os";
|
|
24235
|
-
import { join as
|
|
24236
|
-
var PID_FILE =
|
|
23593
|
+
import { join as join5 } from "node:path";
|
|
23594
|
+
var PID_FILE = join5(homedir4(), ".khal-os", "khal-os.pid");
|
|
24237
23595
|
var stopCommand = new Command("stop").description("Stop running KhalOS instance").action(() => {
|
|
24238
|
-
if (!
|
|
23596
|
+
if (!existsSync6(PID_FILE)) {
|
|
24239
23597
|
console.log(`
|
|
24240
23598
|
${source_default.dim("Khal OS is not running.")}
|
|
24241
23599
|
`);
|
|
24242
23600
|
process.exit(0);
|
|
24243
23601
|
}
|
|
24244
|
-
const pid = Number.parseInt(
|
|
23602
|
+
const pid = Number.parseInt(readFileSync5(PID_FILE, "utf-8").trim(), 10);
|
|
24245
23603
|
try {
|
|
24246
23604
|
process.kill(pid, "SIGTERM");
|
|
24247
23605
|
unlinkSync(PID_FILE);
|
|
@@ -24257,16 +23615,13 @@ var stopCommand = new Command("stop").description("Stop running KhalOS instance"
|
|
|
24257
23615
|
});
|
|
24258
23616
|
|
|
24259
23617
|
// src/commands/token.ts
|
|
24260
|
-
init_source();
|
|
24261
|
-
var encode2 = (data) => new TextEncoder().encode(data);
|
|
24262
|
-
var decode2 = (data) => new TextDecoder().decode(data);
|
|
24263
23618
|
var tokenCreate = new Command("create").description("Create a new API token").requiredOption("-n, --name <name>", 'Token name (e.g. "my-ci-key")').action(async (opts) => {
|
|
24264
23619
|
try {
|
|
24265
23620
|
const nc = await connectNats();
|
|
24266
|
-
const resp = await nc.request("khal.*.auth.keys.create",
|
|
23621
|
+
const resp = await nc.request("khal.*.auth.keys.create", encode({ name: opts.name }), {
|
|
24267
23622
|
timeout: 5000
|
|
24268
23623
|
});
|
|
24269
|
-
const data = JSON.parse(
|
|
23624
|
+
const data = JSON.parse(decode(resp.data));
|
|
24270
23625
|
console.log(`
|
|
24271
23626
|
${source_default.green("✓")} Token created
|
|
24272
23627
|
`);
|
|
@@ -24285,8 +23640,8 @@ ${source_default.green("✓")} Token created
|
|
|
24285
23640
|
var tokenList = new Command("list").description("List all API tokens").action(async () => {
|
|
24286
23641
|
try {
|
|
24287
23642
|
const nc = await connectNats();
|
|
24288
|
-
const resp = await nc.request("khal.*.auth.keys.list",
|
|
24289
|
-
const data = JSON.parse(
|
|
23643
|
+
const resp = await nc.request("khal.*.auth.keys.list", encode({}), { timeout: 5000 });
|
|
23644
|
+
const data = JSON.parse(decode(resp.data));
|
|
24290
23645
|
if (data.keys.length === 0) {
|
|
24291
23646
|
console.log(source_default.dim(`
|
|
24292
23647
|
No API tokens found.
|
|
@@ -24311,7 +23666,7 @@ ${source_default.bold("API Tokens")}
|
|
|
24311
23666
|
var tokenRevoke = new Command("revoke").description("Revoke an API token").argument("<id>", "Token ID to revoke").action(async (id) => {
|
|
24312
23667
|
try {
|
|
24313
23668
|
const nc = await connectNats();
|
|
24314
|
-
await nc.request("khal.*.auth.keys.revoke",
|
|
23669
|
+
await nc.request("khal.*.auth.keys.revoke", encode({ id }), {
|
|
24315
23670
|
timeout: 5000
|
|
24316
23671
|
});
|
|
24317
23672
|
console.log(`${source_default.green("✓")} Token ${id} revoked`);
|
|
@@ -24324,12 +23679,10 @@ var tokenRevoke = new Command("revoke").description("Revoke an API token").argum
|
|
|
24324
23679
|
var tokenCommand = new Command("token").description("Manage API tokens").addCommand(tokenCreate).addCommand(tokenList).addCommand(tokenRevoke);
|
|
24325
23680
|
|
|
24326
23681
|
// src/commands/traces.ts
|
|
24327
|
-
init_source();
|
|
24328
23682
|
var import_jetstream3 = __toESM(require_mod4(), 1);
|
|
24329
23683
|
init_config();
|
|
24330
23684
|
|
|
24331
23685
|
// src/lib/trace-tree.ts
|
|
24332
|
-
init_source();
|
|
24333
23686
|
function buildSpanTree(entries) {
|
|
24334
23687
|
entries.sort((a, b2) => new Date(a.ts).getTime() - new Date(b2.ts).getTime());
|
|
24335
23688
|
const nodeMap = new Map;
|
|
@@ -24461,17 +23814,8 @@ var tracesCommand = new Command("traces").description("Show distributed trace sp
|
|
|
24461
23814
|
}
|
|
24462
23815
|
await nc.close();
|
|
24463
23816
|
});
|
|
24464
|
-
function parseDuration4(input) {
|
|
24465
|
-
const match = input.match(/^(\d+)(s|m|h|d)$/);
|
|
24466
|
-
if (!match)
|
|
24467
|
-
throw new Error(`Invalid duration: "${input}". Use format like 5m, 1h, 30s`);
|
|
24468
|
-
const value = Number.parseInt(match[1], 10);
|
|
24469
|
-
const unit = match[2];
|
|
24470
|
-
const multipliers = { s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
24471
|
-
return value * multipliers[unit];
|
|
24472
|
-
}
|
|
24473
23817
|
async function collectTraceEntries(nc, traceId, sinceDuration) {
|
|
24474
|
-
const sinceMs =
|
|
23818
|
+
const sinceMs = parseDuration(sinceDuration);
|
|
24475
23819
|
const startTime = new Date(Date.now() - sinceMs);
|
|
24476
23820
|
const js = import_jetstream3.jetstream(nc);
|
|
24477
23821
|
const entries = [];
|
|
@@ -24513,7 +23857,6 @@ async function drainStream(js, stream, subject, startTime, traceId, entries, typ
|
|
|
24513
23857
|
}
|
|
24514
23858
|
|
|
24515
23859
|
// src/commands/use.ts
|
|
24516
|
-
init_source();
|
|
24517
23860
|
init_config();
|
|
24518
23861
|
init_instances();
|
|
24519
23862
|
var useCommand = new Command("use").description("Switch active instance").argument("[name]", "Instance name to activate").action((name) => {
|
|
@@ -24537,7 +23880,6 @@ var useCommand = new Command("use").description("Switch active instance").argume
|
|
|
24537
23880
|
});
|
|
24538
23881
|
|
|
24539
23882
|
// src/commands/whoami.ts
|
|
24540
|
-
init_source();
|
|
24541
23883
|
init_config();
|
|
24542
23884
|
var whoamiCommand = new Command("whoami").description("Show current user and instance").action(async (_opts, cmd) => {
|
|
24543
23885
|
const instance = resolveInstance(cmd.parent?.opts().instance);
|
|
@@ -24556,10 +23898,10 @@ ${source_default.bold("◆ Khal OS")}
|
|
|
24556
23898
|
console.log(` ${source_default.dim("Auth:")} ${cred.type} (${cred.token.slice(0, 10)}...)`);
|
|
24557
23899
|
try {
|
|
24558
23900
|
const nc = await connectNats(instance);
|
|
24559
|
-
const resp = await nc.request("khal.*.auth.whoami",
|
|
23901
|
+
const resp = await nc.request("khal.*.auth.whoami", encode({}), {
|
|
24560
23902
|
timeout: 5000
|
|
24561
23903
|
});
|
|
24562
|
-
const data = JSON.parse(
|
|
23904
|
+
const data = JSON.parse(decode(resp.data));
|
|
24563
23905
|
console.log(` ${source_default.dim("User:")} ${data.userId}`);
|
|
24564
23906
|
console.log(` ${source_default.dim("Org:")} ${data.orgId}`);
|
|
24565
23907
|
console.log(` ${source_default.dim("Role:")} ${data.role}`);
|
|
@@ -24585,13 +23927,12 @@ program2.addCommand(eventsCommand);
|
|
|
24585
23927
|
program2.addCommand(logsCommand);
|
|
24586
23928
|
program2.addCommand(tracesCommand);
|
|
24587
23929
|
program2.addCommand(perfCommand);
|
|
24588
|
-
program2.addCommand(qaCommand);
|
|
24589
23930
|
program2.addCommand(deployCommand);
|
|
24590
23931
|
program2.addCommand(instancesCommand);
|
|
24591
23932
|
program2.addCommand(useCommand);
|
|
24592
23933
|
if (process.argv.length <= 2) {
|
|
24593
23934
|
try {
|
|
24594
|
-
const pkg = JSON.parse(
|
|
23935
|
+
const pkg = JSON.parse(readFileSync6("package.json", "utf-8"));
|
|
24595
23936
|
if (pkg.name === "khal-os") {
|
|
24596
23937
|
process.argv.push("dev");
|
|
24597
23938
|
} else {
|