@openape/ape-agent 2.0.0
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/LICENSE +21 -0
- package/README.md +84 -0
- package/dist/bridge.mjs +4149 -0
- package/package.json +53 -0
package/dist/bridge.mjs
ADDED
|
@@ -0,0 +1,4149 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
12
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
+
};
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
32
|
+
mod
|
|
33
|
+
));
|
|
34
|
+
|
|
35
|
+
// ../../packages/apes/dist/chunk-OBF7IMQ2.js
|
|
36
|
+
import { homedir as homedir4 } from "os";
|
|
37
|
+
import { join as join3 } from "path";
|
|
38
|
+
var CONFIG_DIR, AUTH_FILE, CONFIG_FILE;
|
|
39
|
+
var init_chunk_OBF7IMQ2 = __esm({
|
|
40
|
+
"../../packages/apes/dist/chunk-OBF7IMQ2.js"() {
|
|
41
|
+
"use strict";
|
|
42
|
+
CONFIG_DIR = join3(homedir4(), ".config", "apes");
|
|
43
|
+
AUTH_FILE = join3(CONFIG_DIR, "auth.json");
|
|
44
|
+
CONFIG_FILE = join3(CONFIG_DIR, "config.toml");
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/chunks/prompt.mjs
|
|
49
|
+
var prompt_exports = {};
|
|
50
|
+
__export(prompt_exports, {
|
|
51
|
+
kCancel: () => kCancel,
|
|
52
|
+
prompt: () => prompt
|
|
53
|
+
});
|
|
54
|
+
import "util";
|
|
55
|
+
import g, { stdin, stdout } from "process";
|
|
56
|
+
import f from "readline";
|
|
57
|
+
import { WriteStream } from "tty";
|
|
58
|
+
function getDefaultExportFromCjs(x2) {
|
|
59
|
+
return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
|
|
60
|
+
}
|
|
61
|
+
function requireSrc() {
|
|
62
|
+
if (hasRequiredSrc) return src;
|
|
63
|
+
hasRequiredSrc = 1;
|
|
64
|
+
const ESC = "\x1B";
|
|
65
|
+
const CSI = `${ESC}[`;
|
|
66
|
+
const beep = "\x07";
|
|
67
|
+
const cursor = {
|
|
68
|
+
to(x2, y3) {
|
|
69
|
+
if (!y3) return `${CSI}${x2 + 1}G`;
|
|
70
|
+
return `${CSI}${y3 + 1};${x2 + 1}H`;
|
|
71
|
+
},
|
|
72
|
+
move(x2, y3) {
|
|
73
|
+
let ret = "";
|
|
74
|
+
if (x2 < 0) ret += `${CSI}${-x2}D`;
|
|
75
|
+
else if (x2 > 0) ret += `${CSI}${x2}C`;
|
|
76
|
+
if (y3 < 0) ret += `${CSI}${-y3}A`;
|
|
77
|
+
else if (y3 > 0) ret += `${CSI}${y3}B`;
|
|
78
|
+
return ret;
|
|
79
|
+
},
|
|
80
|
+
up: (count = 1) => `${CSI}${count}A`,
|
|
81
|
+
down: (count = 1) => `${CSI}${count}B`,
|
|
82
|
+
forward: (count = 1) => `${CSI}${count}C`,
|
|
83
|
+
backward: (count = 1) => `${CSI}${count}D`,
|
|
84
|
+
nextLine: (count = 1) => `${CSI}E`.repeat(count),
|
|
85
|
+
prevLine: (count = 1) => `${CSI}F`.repeat(count),
|
|
86
|
+
left: `${CSI}G`,
|
|
87
|
+
hide: `${CSI}?25l`,
|
|
88
|
+
show: `${CSI}?25h`,
|
|
89
|
+
save: `${ESC}7`,
|
|
90
|
+
restore: `${ESC}8`
|
|
91
|
+
};
|
|
92
|
+
const scroll = {
|
|
93
|
+
up: (count = 1) => `${CSI}S`.repeat(count),
|
|
94
|
+
down: (count = 1) => `${CSI}T`.repeat(count)
|
|
95
|
+
};
|
|
96
|
+
const erase = {
|
|
97
|
+
screen: `${CSI}2J`,
|
|
98
|
+
up: (count = 1) => `${CSI}1J`.repeat(count),
|
|
99
|
+
down: (count = 1) => `${CSI}J`.repeat(count),
|
|
100
|
+
line: `${CSI}2K`,
|
|
101
|
+
lineEnd: `${CSI}K`,
|
|
102
|
+
lineStart: `${CSI}1K`,
|
|
103
|
+
lines(count) {
|
|
104
|
+
let clear = "";
|
|
105
|
+
for (let i2 = 0; i2 < count; i2++)
|
|
106
|
+
clear += this.line + (i2 < count - 1 ? cursor.up() : "");
|
|
107
|
+
if (count)
|
|
108
|
+
clear += cursor.left;
|
|
109
|
+
return clear;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
src = { cursor, scroll, erase, beep };
|
|
113
|
+
return src;
|
|
114
|
+
}
|
|
115
|
+
function requirePicocolors() {
|
|
116
|
+
if (hasRequiredPicocolors) return picocolors.exports;
|
|
117
|
+
hasRequiredPicocolors = 1;
|
|
118
|
+
let p = process || {}, argv2 = p.argv || [], env2 = p.env || {};
|
|
119
|
+
let isColorSupported2 = !(!!env2.NO_COLOR || argv2.includes("--no-color")) && (!!env2.FORCE_COLOR || argv2.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env2.TERM !== "dumb" || !!env2.CI);
|
|
120
|
+
let formatter = (open, close, replace = open) => (input) => {
|
|
121
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
122
|
+
return ~index ? open + replaceClose2(string, close, replace, index) + close : open + string + close;
|
|
123
|
+
};
|
|
124
|
+
let replaceClose2 = (string, close, replace, index) => {
|
|
125
|
+
let result = "", cursor = 0;
|
|
126
|
+
do {
|
|
127
|
+
result += string.substring(cursor, index) + replace;
|
|
128
|
+
cursor = index + close.length;
|
|
129
|
+
index = string.indexOf(close, cursor);
|
|
130
|
+
} while (~index);
|
|
131
|
+
return result + string.substring(cursor);
|
|
132
|
+
};
|
|
133
|
+
let createColors2 = (enabled = isColorSupported2) => {
|
|
134
|
+
let f3 = enabled ? formatter : () => String;
|
|
135
|
+
return {
|
|
136
|
+
isColorSupported: enabled,
|
|
137
|
+
reset: f3("\x1B[0m", "\x1B[0m"),
|
|
138
|
+
bold: f3("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
139
|
+
dim: f3("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
140
|
+
italic: f3("\x1B[3m", "\x1B[23m"),
|
|
141
|
+
underline: f3("\x1B[4m", "\x1B[24m"),
|
|
142
|
+
inverse: f3("\x1B[7m", "\x1B[27m"),
|
|
143
|
+
hidden: f3("\x1B[8m", "\x1B[28m"),
|
|
144
|
+
strikethrough: f3("\x1B[9m", "\x1B[29m"),
|
|
145
|
+
black: f3("\x1B[30m", "\x1B[39m"),
|
|
146
|
+
red: f3("\x1B[31m", "\x1B[39m"),
|
|
147
|
+
green: f3("\x1B[32m", "\x1B[39m"),
|
|
148
|
+
yellow: f3("\x1B[33m", "\x1B[39m"),
|
|
149
|
+
blue: f3("\x1B[34m", "\x1B[39m"),
|
|
150
|
+
magenta: f3("\x1B[35m", "\x1B[39m"),
|
|
151
|
+
cyan: f3("\x1B[36m", "\x1B[39m"),
|
|
152
|
+
white: f3("\x1B[37m", "\x1B[39m"),
|
|
153
|
+
gray: f3("\x1B[90m", "\x1B[39m"),
|
|
154
|
+
bgBlack: f3("\x1B[40m", "\x1B[49m"),
|
|
155
|
+
bgRed: f3("\x1B[41m", "\x1B[49m"),
|
|
156
|
+
bgGreen: f3("\x1B[42m", "\x1B[49m"),
|
|
157
|
+
bgYellow: f3("\x1B[43m", "\x1B[49m"),
|
|
158
|
+
bgBlue: f3("\x1B[44m", "\x1B[49m"),
|
|
159
|
+
bgMagenta: f3("\x1B[45m", "\x1B[49m"),
|
|
160
|
+
bgCyan: f3("\x1B[46m", "\x1B[49m"),
|
|
161
|
+
bgWhite: f3("\x1B[47m", "\x1B[49m"),
|
|
162
|
+
blackBright: f3("\x1B[90m", "\x1B[39m"),
|
|
163
|
+
redBright: f3("\x1B[91m", "\x1B[39m"),
|
|
164
|
+
greenBright: f3("\x1B[92m", "\x1B[39m"),
|
|
165
|
+
yellowBright: f3("\x1B[93m", "\x1B[39m"),
|
|
166
|
+
blueBright: f3("\x1B[94m", "\x1B[39m"),
|
|
167
|
+
magentaBright: f3("\x1B[95m", "\x1B[39m"),
|
|
168
|
+
cyanBright: f3("\x1B[96m", "\x1B[39m"),
|
|
169
|
+
whiteBright: f3("\x1B[97m", "\x1B[39m"),
|
|
170
|
+
bgBlackBright: f3("\x1B[100m", "\x1B[49m"),
|
|
171
|
+
bgRedBright: f3("\x1B[101m", "\x1B[49m"),
|
|
172
|
+
bgGreenBright: f3("\x1B[102m", "\x1B[49m"),
|
|
173
|
+
bgYellowBright: f3("\x1B[103m", "\x1B[49m"),
|
|
174
|
+
bgBlueBright: f3("\x1B[104m", "\x1B[49m"),
|
|
175
|
+
bgMagentaBright: f3("\x1B[105m", "\x1B[49m"),
|
|
176
|
+
bgCyanBright: f3("\x1B[106m", "\x1B[49m"),
|
|
177
|
+
bgWhiteBright: f3("\x1B[107m", "\x1B[49m")
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
picocolors.exports = createColors2();
|
|
181
|
+
picocolors.exports.createColors = createColors2;
|
|
182
|
+
return picocolors.exports;
|
|
183
|
+
}
|
|
184
|
+
function J({ onlyFirst: t2 = false } = {}) {
|
|
185
|
+
const F3 = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
|
|
186
|
+
return new RegExp(F3, t2 ? void 0 : "g");
|
|
187
|
+
}
|
|
188
|
+
function T$1(t2) {
|
|
189
|
+
if (typeof t2 != "string") throw new TypeError(`Expected a \`string\`, got \`${typeof t2}\``);
|
|
190
|
+
return t2.replace(Q, "");
|
|
191
|
+
}
|
|
192
|
+
function O(t2) {
|
|
193
|
+
return t2 && t2.__esModule && Object.prototype.hasOwnProperty.call(t2, "default") ? t2.default : t2;
|
|
194
|
+
}
|
|
195
|
+
function A$1(t2, u3 = {}) {
|
|
196
|
+
if (typeof t2 != "string" || t2.length === 0 || (u3 = { ambiguousIsNarrow: true, ...u3 }, t2 = T$1(t2), t2.length === 0)) return 0;
|
|
197
|
+
t2 = t2.replace(FD(), " ");
|
|
198
|
+
const F3 = u3.ambiguousIsNarrow ? 1 : 2;
|
|
199
|
+
let e2 = 0;
|
|
200
|
+
for (const s2 of t2) {
|
|
201
|
+
const i2 = s2.codePointAt(0);
|
|
202
|
+
if (i2 <= 31 || i2 >= 127 && i2 <= 159 || i2 >= 768 && i2 <= 879) continue;
|
|
203
|
+
switch (DD.eastAsianWidth(s2)) {
|
|
204
|
+
case "F":
|
|
205
|
+
case "W":
|
|
206
|
+
e2 += 2;
|
|
207
|
+
break;
|
|
208
|
+
case "A":
|
|
209
|
+
e2 += F3;
|
|
210
|
+
break;
|
|
211
|
+
default:
|
|
212
|
+
e2 += 1;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return e2;
|
|
216
|
+
}
|
|
217
|
+
function sD() {
|
|
218
|
+
const t2 = /* @__PURE__ */ new Map();
|
|
219
|
+
for (const [u3, F3] of Object.entries(r)) {
|
|
220
|
+
for (const [e2, s2] of Object.entries(F3)) r[e2] = { open: `\x1B[${s2[0]}m`, close: `\x1B[${s2[1]}m` }, F3[e2] = r[e2], t2.set(s2[0], s2[1]);
|
|
221
|
+
Object.defineProperty(r, u3, { value: F3, enumerable: false });
|
|
222
|
+
}
|
|
223
|
+
return Object.defineProperty(r, "codes", { value: t2, enumerable: false }), r.color.close = "\x1B[39m", r.bgColor.close = "\x1B[49m", r.color.ansi = L$1(), r.color.ansi256 = N(), r.color.ansi16m = I(), r.bgColor.ansi = L$1(m), r.bgColor.ansi256 = N(m), r.bgColor.ansi16m = I(m), Object.defineProperties(r, { rgbToAnsi256: { value: (u3, F3, e2) => u3 === F3 && F3 === e2 ? u3 < 8 ? 16 : u3 > 248 ? 231 : Math.round((u3 - 8) / 247 * 24) + 232 : 16 + 36 * Math.round(u3 / 255 * 5) + 6 * Math.round(F3 / 255 * 5) + Math.round(e2 / 255 * 5), enumerable: false }, hexToRgb: { value: (u3) => {
|
|
224
|
+
const F3 = /[a-f\d]{6}|[a-f\d]{3}/i.exec(u3.toString(16));
|
|
225
|
+
if (!F3) return [0, 0, 0];
|
|
226
|
+
let [e2] = F3;
|
|
227
|
+
e2.length === 3 && (e2 = [...e2].map((i2) => i2 + i2).join(""));
|
|
228
|
+
const s2 = Number.parseInt(e2, 16);
|
|
229
|
+
return [s2 >> 16 & 255, s2 >> 8 & 255, s2 & 255];
|
|
230
|
+
}, enumerable: false }, hexToAnsi256: { value: (u3) => r.rgbToAnsi256(...r.hexToRgb(u3)), enumerable: false }, ansi256ToAnsi: { value: (u3) => {
|
|
231
|
+
if (u3 < 8) return 30 + u3;
|
|
232
|
+
if (u3 < 16) return 90 + (u3 - 8);
|
|
233
|
+
let F3, e2, s2;
|
|
234
|
+
if (u3 >= 232) F3 = ((u3 - 232) * 10 + 8) / 255, e2 = F3, s2 = F3;
|
|
235
|
+
else {
|
|
236
|
+
u3 -= 16;
|
|
237
|
+
const C3 = u3 % 36;
|
|
238
|
+
F3 = Math.floor(u3 / 36) / 5, e2 = Math.floor(C3 / 6) / 5, s2 = C3 % 6 / 5;
|
|
239
|
+
}
|
|
240
|
+
const i2 = Math.max(F3, e2, s2) * 2;
|
|
241
|
+
if (i2 === 0) return 30;
|
|
242
|
+
let D2 = 30 + (Math.round(s2) << 2 | Math.round(e2) << 1 | Math.round(F3));
|
|
243
|
+
return i2 === 2 && (D2 += 60), D2;
|
|
244
|
+
}, enumerable: false }, rgbToAnsi: { value: (u3, F3, e2) => r.ansi256ToAnsi(r.rgbToAnsi256(u3, F3, e2)), enumerable: false }, hexToAnsi: { value: (u3) => r.ansi256ToAnsi(r.hexToAnsi256(u3)), enumerable: false } }), r;
|
|
245
|
+
}
|
|
246
|
+
function G(t2, u3, F3) {
|
|
247
|
+
return String(t2).normalize().replace(/\r\n/g, `
|
|
248
|
+
`).split(`
|
|
249
|
+
`).map((e2) => oD(e2, u3, F3)).join(`
|
|
250
|
+
`);
|
|
251
|
+
}
|
|
252
|
+
function k$1(t2, u3) {
|
|
253
|
+
if (typeof t2 == "string") return c.aliases.get(t2) === u3;
|
|
254
|
+
for (const F3 of t2) if (F3 !== void 0 && k$1(F3, u3)) return true;
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
function lD(t2, u3) {
|
|
258
|
+
if (t2 === u3) return;
|
|
259
|
+
const F3 = t2.split(`
|
|
260
|
+
`), e2 = u3.split(`
|
|
261
|
+
`), s2 = [];
|
|
262
|
+
for (let i2 = 0; i2 < Math.max(F3.length, e2.length); i2++) F3[i2] !== e2[i2] && s2.push(i2);
|
|
263
|
+
return s2;
|
|
264
|
+
}
|
|
265
|
+
function d$1(t2, u3) {
|
|
266
|
+
const F3 = t2;
|
|
267
|
+
F3.isTTY && F3.setRawMode(u3);
|
|
268
|
+
}
|
|
269
|
+
function ce() {
|
|
270
|
+
return g.platform !== "win32" ? g.env.TERM !== "linux" : !!g.env.CI || !!g.env.WT_SESSION || !!g.env.TERMINUS_SUBLIME || g.env.ConEmuTask === "{cmd::Cmder}" || g.env.TERM_PROGRAM === "Terminus-Sublime" || g.env.TERM_PROGRAM === "vscode" || g.env.TERM === "xterm-256color" || g.env.TERM === "alacritty" || g.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
271
|
+
}
|
|
272
|
+
async function prompt(message, opts = {}) {
|
|
273
|
+
const handleCancel = (value) => {
|
|
274
|
+
if (typeof value !== "symbol" || value.toString() !== "Symbol(clack:cancel)") {
|
|
275
|
+
return value;
|
|
276
|
+
}
|
|
277
|
+
switch (opts.cancel) {
|
|
278
|
+
case "reject": {
|
|
279
|
+
const error = new Error("Prompt cancelled.");
|
|
280
|
+
error.name = "ConsolaPromptCancelledError";
|
|
281
|
+
if (Error.captureStackTrace) {
|
|
282
|
+
Error.captureStackTrace(error, prompt);
|
|
283
|
+
}
|
|
284
|
+
throw error;
|
|
285
|
+
}
|
|
286
|
+
case "undefined": {
|
|
287
|
+
return void 0;
|
|
288
|
+
}
|
|
289
|
+
case "null": {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
case "symbol": {
|
|
293
|
+
return kCancel;
|
|
294
|
+
}
|
|
295
|
+
default:
|
|
296
|
+
case "default": {
|
|
297
|
+
return opts.default ?? opts.initial;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
if (!opts.type || opts.type === "text") {
|
|
302
|
+
return await he({
|
|
303
|
+
message,
|
|
304
|
+
defaultValue: opts.default,
|
|
305
|
+
placeholder: opts.placeholder,
|
|
306
|
+
initialValue: opts.initial
|
|
307
|
+
}).then(handleCancel);
|
|
308
|
+
}
|
|
309
|
+
if (opts.type === "confirm") {
|
|
310
|
+
return await ye({
|
|
311
|
+
message,
|
|
312
|
+
initialValue: opts.initial
|
|
313
|
+
}).then(handleCancel);
|
|
314
|
+
}
|
|
315
|
+
if (opts.type === "select") {
|
|
316
|
+
return await ve({
|
|
317
|
+
message,
|
|
318
|
+
options: opts.options.map(
|
|
319
|
+
(o3) => typeof o3 === "string" ? { value: o3, label: o3 } : o3
|
|
320
|
+
),
|
|
321
|
+
initialValue: opts.initial
|
|
322
|
+
}).then(handleCancel);
|
|
323
|
+
}
|
|
324
|
+
if (opts.type === "multiselect") {
|
|
325
|
+
return await fe({
|
|
326
|
+
message,
|
|
327
|
+
options: opts.options.map(
|
|
328
|
+
(o3) => typeof o3 === "string" ? { value: o3, label: o3 } : o3
|
|
329
|
+
),
|
|
330
|
+
required: opts.required,
|
|
331
|
+
initialValues: opts.initial
|
|
332
|
+
}).then(handleCancel);
|
|
333
|
+
}
|
|
334
|
+
throw new Error(`Unknown prompt type: ${opts.type}`);
|
|
335
|
+
}
|
|
336
|
+
var src, hasRequiredSrc, srcExports, picocolors, hasRequiredPicocolors, picocolorsExports, e, Q, P$1, X, DD, uD, FD, m, L$1, N, I, r, tD, eD, iD, v, CD, w$1, W$1, rD, R, y, V$1, z, ED, _, nD, oD, aD, c, S, AD, pD, h, x, fD, bD, mD, Y, wD, SD, $D, q, jD, PD, V, u, le, L, W, C, o, d, k, P, A, T, F, w, B, he, ye, ve, fe, kCancel;
|
|
337
|
+
var init_prompt = __esm({
|
|
338
|
+
"../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/chunks/prompt.mjs"() {
|
|
339
|
+
"use strict";
|
|
340
|
+
srcExports = requireSrc();
|
|
341
|
+
picocolors = { exports: {} };
|
|
342
|
+
picocolorsExports = /* @__PURE__ */ requirePicocolors();
|
|
343
|
+
e = /* @__PURE__ */ getDefaultExportFromCjs(picocolorsExports);
|
|
344
|
+
Q = J();
|
|
345
|
+
P$1 = { exports: {} };
|
|
346
|
+
(function(t2) {
|
|
347
|
+
var u3 = {};
|
|
348
|
+
t2.exports = u3, u3.eastAsianWidth = function(e2) {
|
|
349
|
+
var s2 = e2.charCodeAt(0), i2 = e2.length == 2 ? e2.charCodeAt(1) : 0, D2 = s2;
|
|
350
|
+
return 55296 <= s2 && s2 <= 56319 && 56320 <= i2 && i2 <= 57343 && (s2 &= 1023, i2 &= 1023, D2 = s2 << 10 | i2, D2 += 65536), D2 == 12288 || 65281 <= D2 && D2 <= 65376 || 65504 <= D2 && D2 <= 65510 ? "F" : D2 == 8361 || 65377 <= D2 && D2 <= 65470 || 65474 <= D2 && D2 <= 65479 || 65482 <= D2 && D2 <= 65487 || 65490 <= D2 && D2 <= 65495 || 65498 <= D2 && D2 <= 65500 || 65512 <= D2 && D2 <= 65518 ? "H" : 4352 <= D2 && D2 <= 4447 || 4515 <= D2 && D2 <= 4519 || 4602 <= D2 && D2 <= 4607 || 9001 <= D2 && D2 <= 9002 || 11904 <= D2 && D2 <= 11929 || 11931 <= D2 && D2 <= 12019 || 12032 <= D2 && D2 <= 12245 || 12272 <= D2 && D2 <= 12283 || 12289 <= D2 && D2 <= 12350 || 12353 <= D2 && D2 <= 12438 || 12441 <= D2 && D2 <= 12543 || 12549 <= D2 && D2 <= 12589 || 12593 <= D2 && D2 <= 12686 || 12688 <= D2 && D2 <= 12730 || 12736 <= D2 && D2 <= 12771 || 12784 <= D2 && D2 <= 12830 || 12832 <= D2 && D2 <= 12871 || 12880 <= D2 && D2 <= 13054 || 13056 <= D2 && D2 <= 19903 || 19968 <= D2 && D2 <= 42124 || 42128 <= D2 && D2 <= 42182 || 43360 <= D2 && D2 <= 43388 || 44032 <= D2 && D2 <= 55203 || 55216 <= D2 && D2 <= 55238 || 55243 <= D2 && D2 <= 55291 || 63744 <= D2 && D2 <= 64255 || 65040 <= D2 && D2 <= 65049 || 65072 <= D2 && D2 <= 65106 || 65108 <= D2 && D2 <= 65126 || 65128 <= D2 && D2 <= 65131 || 110592 <= D2 && D2 <= 110593 || 127488 <= D2 && D2 <= 127490 || 127504 <= D2 && D2 <= 127546 || 127552 <= D2 && D2 <= 127560 || 127568 <= D2 && D2 <= 127569 || 131072 <= D2 && D2 <= 194367 || 177984 <= D2 && D2 <= 196605 || 196608 <= D2 && D2 <= 262141 ? "W" : 32 <= D2 && D2 <= 126 || 162 <= D2 && D2 <= 163 || 165 <= D2 && D2 <= 166 || D2 == 172 || D2 == 175 || 10214 <= D2 && D2 <= 10221 || 10629 <= D2 && D2 <= 10630 ? "Na" : D2 == 161 || D2 == 164 || 167 <= D2 && D2 <= 168 || D2 == 170 || 173 <= D2 && D2 <= 174 || 176 <= D2 && D2 <= 180 || 182 <= D2 && D2 <= 186 || 188 <= D2 && D2 <= 191 || D2 == 198 || D2 == 208 || 215 <= D2 && D2 <= 216 || 222 <= D2 && D2 <= 225 || D2 == 230 || 232 <= D2 && D2 <= 234 || 236 <= D2 && D2 <= 237 || D2 == 240 || 242 <= D2 && D2 <= 243 || 247 <= D2 && D2 <= 250 || D2 == 252 || D2 == 254 || D2 == 257 || D2 == 273 || D2 == 275 || D2 == 283 || 294 <= D2 && D2 <= 295 || D2 == 299 || 305 <= D2 && D2 <= 307 || D2 == 312 || 319 <= D2 && D2 <= 322 || D2 == 324 || 328 <= D2 && D2 <= 331 || D2 == 333 || 338 <= D2 && D2 <= 339 || 358 <= D2 && D2 <= 359 || D2 == 363 || D2 == 462 || D2 == 464 || D2 == 466 || D2 == 468 || D2 == 470 || D2 == 472 || D2 == 474 || D2 == 476 || D2 == 593 || D2 == 609 || D2 == 708 || D2 == 711 || 713 <= D2 && D2 <= 715 || D2 == 717 || D2 == 720 || 728 <= D2 && D2 <= 731 || D2 == 733 || D2 == 735 || 768 <= D2 && D2 <= 879 || 913 <= D2 && D2 <= 929 || 931 <= D2 && D2 <= 937 || 945 <= D2 && D2 <= 961 || 963 <= D2 && D2 <= 969 || D2 == 1025 || 1040 <= D2 && D2 <= 1103 || D2 == 1105 || D2 == 8208 || 8211 <= D2 && D2 <= 8214 || 8216 <= D2 && D2 <= 8217 || 8220 <= D2 && D2 <= 8221 || 8224 <= D2 && D2 <= 8226 || 8228 <= D2 && D2 <= 8231 || D2 == 8240 || 8242 <= D2 && D2 <= 8243 || D2 == 8245 || D2 == 8251 || D2 == 8254 || D2 == 8308 || D2 == 8319 || 8321 <= D2 && D2 <= 8324 || D2 == 8364 || D2 == 8451 || D2 == 8453 || D2 == 8457 || D2 == 8467 || D2 == 8470 || 8481 <= D2 && D2 <= 8482 || D2 == 8486 || D2 == 8491 || 8531 <= D2 && D2 <= 8532 || 8539 <= D2 && D2 <= 8542 || 8544 <= D2 && D2 <= 8555 || 8560 <= D2 && D2 <= 8569 || D2 == 8585 || 8592 <= D2 && D2 <= 8601 || 8632 <= D2 && D2 <= 8633 || D2 == 8658 || D2 == 8660 || D2 == 8679 || D2 == 8704 || 8706 <= D2 && D2 <= 8707 || 8711 <= D2 && D2 <= 8712 || D2 == 8715 || D2 == 8719 || D2 == 8721 || D2 == 8725 || D2 == 8730 || 8733 <= D2 && D2 <= 8736 || D2 == 8739 || D2 == 8741 || 8743 <= D2 && D2 <= 8748 || D2 == 8750 || 8756 <= D2 && D2 <= 8759 || 8764 <= D2 && D2 <= 8765 || D2 == 8776 || D2 == 8780 || D2 == 8786 || 8800 <= D2 && D2 <= 8801 || 8804 <= D2 && D2 <= 8807 || 8810 <= D2 && D2 <= 8811 || 8814 <= D2 && D2 <= 8815 || 8834 <= D2 && D2 <= 8835 || 8838 <= D2 && D2 <= 8839 || D2 == 8853 || D2 == 8857 || D2 == 8869 || D2 == 8895 || D2 == 8978 || 9312 <= D2 && D2 <= 9449 || 9451 <= D2 && D2 <= 9547 || 9552 <= D2 && D2 <= 9587 || 9600 <= D2 && D2 <= 9615 || 9618 <= D2 && D2 <= 9621 || 9632 <= D2 && D2 <= 9633 || 9635 <= D2 && D2 <= 9641 || 9650 <= D2 && D2 <= 9651 || 9654 <= D2 && D2 <= 9655 || 9660 <= D2 && D2 <= 9661 || 9664 <= D2 && D2 <= 9665 || 9670 <= D2 && D2 <= 9672 || D2 == 9675 || 9678 <= D2 && D2 <= 9681 || 9698 <= D2 && D2 <= 9701 || D2 == 9711 || 9733 <= D2 && D2 <= 9734 || D2 == 9737 || 9742 <= D2 && D2 <= 9743 || 9748 <= D2 && D2 <= 9749 || D2 == 9756 || D2 == 9758 || D2 == 9792 || D2 == 9794 || 9824 <= D2 && D2 <= 9825 || 9827 <= D2 && D2 <= 9829 || 9831 <= D2 && D2 <= 9834 || 9836 <= D2 && D2 <= 9837 || D2 == 9839 || 9886 <= D2 && D2 <= 9887 || 9918 <= D2 && D2 <= 9919 || 9924 <= D2 && D2 <= 9933 || 9935 <= D2 && D2 <= 9953 || D2 == 9955 || 9960 <= D2 && D2 <= 9983 || D2 == 10045 || D2 == 10071 || 10102 <= D2 && D2 <= 10111 || 11093 <= D2 && D2 <= 11097 || 12872 <= D2 && D2 <= 12879 || 57344 <= D2 && D2 <= 63743 || 65024 <= D2 && D2 <= 65039 || D2 == 65533 || 127232 <= D2 && D2 <= 127242 || 127248 <= D2 && D2 <= 127277 || 127280 <= D2 && D2 <= 127337 || 127344 <= D2 && D2 <= 127386 || 917760 <= D2 && D2 <= 917999 || 983040 <= D2 && D2 <= 1048573 || 1048576 <= D2 && D2 <= 1114109 ? "A" : "N";
|
|
351
|
+
}, u3.characterLength = function(e2) {
|
|
352
|
+
var s2 = this.eastAsianWidth(e2);
|
|
353
|
+
return s2 == "F" || s2 == "W" || s2 == "A" ? 2 : 1;
|
|
354
|
+
};
|
|
355
|
+
function F3(e2) {
|
|
356
|
+
return e2.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g) || [];
|
|
357
|
+
}
|
|
358
|
+
u3.length = function(e2) {
|
|
359
|
+
for (var s2 = F3(e2), i2 = 0, D2 = 0; D2 < s2.length; D2++) i2 = i2 + this.characterLength(s2[D2]);
|
|
360
|
+
return i2;
|
|
361
|
+
}, u3.slice = function(e2, s2, i2) {
|
|
362
|
+
textLen = u3.length(e2), s2 = s2 || 0, i2 = i2 || 1, s2 < 0 && (s2 = textLen + s2), i2 < 0 && (i2 = textLen + i2);
|
|
363
|
+
for (var D2 = "", C3 = 0, o3 = F3(e2), E = 0; E < o3.length; E++) {
|
|
364
|
+
var a2 = o3[E], n2 = u3.length(a2);
|
|
365
|
+
if (C3 >= s2 - (n2 == 2 ? 1 : 0)) if (C3 + n2 <= i2) D2 += a2;
|
|
366
|
+
else break;
|
|
367
|
+
C3 += n2;
|
|
368
|
+
}
|
|
369
|
+
return D2;
|
|
370
|
+
};
|
|
371
|
+
})(P$1);
|
|
372
|
+
X = P$1.exports;
|
|
373
|
+
DD = O(X);
|
|
374
|
+
uD = function() {
|
|
375
|
+
return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
|
|
376
|
+
};
|
|
377
|
+
FD = O(uD);
|
|
378
|
+
m = 10;
|
|
379
|
+
L$1 = (t2 = 0) => (u3) => `\x1B[${u3 + t2}m`;
|
|
380
|
+
N = (t2 = 0) => (u3) => `\x1B[${38 + t2};5;${u3}m`;
|
|
381
|
+
I = (t2 = 0) => (u3, F3, e2) => `\x1B[${38 + t2};2;${u3};${F3};${e2}m`;
|
|
382
|
+
r = { modifier: { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], overline: [53, 55], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29] }, color: { black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], blackBright: [90, 39], gray: [90, 39], grey: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39] }, bgColor: { bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgGray: [100, 49], bgGrey: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49] } };
|
|
383
|
+
Object.keys(r.modifier);
|
|
384
|
+
tD = Object.keys(r.color);
|
|
385
|
+
eD = Object.keys(r.bgColor);
|
|
386
|
+
[...tD, ...eD];
|
|
387
|
+
iD = sD();
|
|
388
|
+
v = /* @__PURE__ */ new Set(["\x1B", "\x9B"]);
|
|
389
|
+
CD = 39;
|
|
390
|
+
w$1 = "\x07";
|
|
391
|
+
W$1 = "[";
|
|
392
|
+
rD = "]";
|
|
393
|
+
R = "m";
|
|
394
|
+
y = `${rD}8;;`;
|
|
395
|
+
V$1 = (t2) => `${v.values().next().value}${W$1}${t2}${R}`;
|
|
396
|
+
z = (t2) => `${v.values().next().value}${y}${t2}${w$1}`;
|
|
397
|
+
ED = (t2) => t2.split(" ").map((u3) => A$1(u3));
|
|
398
|
+
_ = (t2, u3, F3) => {
|
|
399
|
+
const e2 = [...u3];
|
|
400
|
+
let s2 = false, i2 = false, D2 = A$1(T$1(t2[t2.length - 1]));
|
|
401
|
+
for (const [C3, o3] of e2.entries()) {
|
|
402
|
+
const E = A$1(o3);
|
|
403
|
+
if (D2 + E <= F3 ? t2[t2.length - 1] += o3 : (t2.push(o3), D2 = 0), v.has(o3) && (s2 = true, i2 = e2.slice(C3 + 1).join("").startsWith(y)), s2) {
|
|
404
|
+
i2 ? o3 === w$1 && (s2 = false, i2 = false) : o3 === R && (s2 = false);
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
D2 += E, D2 === F3 && C3 < e2.length - 1 && (t2.push(""), D2 = 0);
|
|
408
|
+
}
|
|
409
|
+
!D2 && t2[t2.length - 1].length > 0 && t2.length > 1 && (t2[t2.length - 2] += t2.pop());
|
|
410
|
+
};
|
|
411
|
+
nD = (t2) => {
|
|
412
|
+
const u3 = t2.split(" ");
|
|
413
|
+
let F3 = u3.length;
|
|
414
|
+
for (; F3 > 0 && !(A$1(u3[F3 - 1]) > 0); ) F3--;
|
|
415
|
+
return F3 === u3.length ? t2 : u3.slice(0, F3).join(" ") + u3.slice(F3).join("");
|
|
416
|
+
};
|
|
417
|
+
oD = (t2, u3, F3 = {}) => {
|
|
418
|
+
if (F3.trim !== false && t2.trim() === "") return "";
|
|
419
|
+
let e2 = "", s2, i2;
|
|
420
|
+
const D2 = ED(t2);
|
|
421
|
+
let C3 = [""];
|
|
422
|
+
for (const [E, a2] of t2.split(" ").entries()) {
|
|
423
|
+
F3.trim !== false && (C3[C3.length - 1] = C3[C3.length - 1].trimStart());
|
|
424
|
+
let n2 = A$1(C3[C3.length - 1]);
|
|
425
|
+
if (E !== 0 && (n2 >= u3 && (F3.wordWrap === false || F3.trim === false) && (C3.push(""), n2 = 0), (n2 > 0 || F3.trim === false) && (C3[C3.length - 1] += " ", n2++)), F3.hard && D2[E] > u3) {
|
|
426
|
+
const B2 = u3 - n2, p = 1 + Math.floor((D2[E] - B2 - 1) / u3);
|
|
427
|
+
Math.floor((D2[E] - 1) / u3) < p && C3.push(""), _(C3, a2, u3);
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
if (n2 + D2[E] > u3 && n2 > 0 && D2[E] > 0) {
|
|
431
|
+
if (F3.wordWrap === false && n2 < u3) {
|
|
432
|
+
_(C3, a2, u3);
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
C3.push("");
|
|
436
|
+
}
|
|
437
|
+
if (n2 + D2[E] > u3 && F3.wordWrap === false) {
|
|
438
|
+
_(C3, a2, u3);
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
C3[C3.length - 1] += a2;
|
|
442
|
+
}
|
|
443
|
+
F3.trim !== false && (C3 = C3.map((E) => nD(E)));
|
|
444
|
+
const o3 = [...C3.join(`
|
|
445
|
+
`)];
|
|
446
|
+
for (const [E, a2] of o3.entries()) {
|
|
447
|
+
if (e2 += a2, v.has(a2)) {
|
|
448
|
+
const { groups: B2 } = new RegExp(`(?:\\${W$1}(?<code>\\d+)m|\\${y}(?<uri>.*)${w$1})`).exec(o3.slice(E).join("")) || { groups: {} };
|
|
449
|
+
if (B2.code !== void 0) {
|
|
450
|
+
const p = Number.parseFloat(B2.code);
|
|
451
|
+
s2 = p === CD ? void 0 : p;
|
|
452
|
+
} else B2.uri !== void 0 && (i2 = B2.uri.length === 0 ? void 0 : B2.uri);
|
|
453
|
+
}
|
|
454
|
+
const n2 = iD.codes.get(Number(s2));
|
|
455
|
+
o3[E + 1] === `
|
|
456
|
+
` ? (i2 && (e2 += z("")), s2 && n2 && (e2 += V$1(n2))) : a2 === `
|
|
457
|
+
` && (s2 && n2 && (e2 += V$1(s2)), i2 && (e2 += z(i2)));
|
|
458
|
+
}
|
|
459
|
+
return e2;
|
|
460
|
+
};
|
|
461
|
+
aD = ["up", "down", "left", "right", "space", "enter", "cancel"];
|
|
462
|
+
c = { actions: new Set(aD), aliases: /* @__PURE__ */ new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["", "cancel"], ["escape", "cancel"]]) };
|
|
463
|
+
globalThis.process.platform.startsWith("win");
|
|
464
|
+
S = /* @__PURE__ */ Symbol("clack:cancel");
|
|
465
|
+
AD = Object.defineProperty;
|
|
466
|
+
pD = (t2, u3, F3) => u3 in t2 ? AD(t2, u3, { enumerable: true, configurable: true, writable: true, value: F3 }) : t2[u3] = F3;
|
|
467
|
+
h = (t2, u3, F3) => (pD(t2, typeof u3 != "symbol" ? u3 + "" : u3, F3), F3);
|
|
468
|
+
x = class {
|
|
469
|
+
constructor(u3, F3 = true) {
|
|
470
|
+
h(this, "input"), h(this, "output"), h(this, "_abortSignal"), h(this, "rl"), h(this, "opts"), h(this, "_render"), h(this, "_track", false), h(this, "_prevFrame", ""), h(this, "_subscribers", /* @__PURE__ */ new Map()), h(this, "_cursor", 0), h(this, "state", "initial"), h(this, "error", ""), h(this, "value");
|
|
471
|
+
const { input: e2 = stdin, output: s2 = stdout, render: i2, signal: D2, ...C3 } = u3;
|
|
472
|
+
this.opts = C3, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = i2.bind(this), this._track = F3, this._abortSignal = D2, this.input = e2, this.output = s2;
|
|
473
|
+
}
|
|
474
|
+
unsubscribe() {
|
|
475
|
+
this._subscribers.clear();
|
|
476
|
+
}
|
|
477
|
+
setSubscriber(u3, F3) {
|
|
478
|
+
const e2 = this._subscribers.get(u3) ?? [];
|
|
479
|
+
e2.push(F3), this._subscribers.set(u3, e2);
|
|
480
|
+
}
|
|
481
|
+
on(u3, F3) {
|
|
482
|
+
this.setSubscriber(u3, { cb: F3 });
|
|
483
|
+
}
|
|
484
|
+
once(u3, F3) {
|
|
485
|
+
this.setSubscriber(u3, { cb: F3, once: true });
|
|
486
|
+
}
|
|
487
|
+
emit(u3, ...F3) {
|
|
488
|
+
const e2 = this._subscribers.get(u3) ?? [], s2 = [];
|
|
489
|
+
for (const i2 of e2) i2.cb(...F3), i2.once && s2.push(() => e2.splice(e2.indexOf(i2), 1));
|
|
490
|
+
for (const i2 of s2) i2();
|
|
491
|
+
}
|
|
492
|
+
prompt() {
|
|
493
|
+
return new Promise((u3, F3) => {
|
|
494
|
+
if (this._abortSignal) {
|
|
495
|
+
if (this._abortSignal.aborted) return this.state = "cancel", this.close(), u3(S);
|
|
496
|
+
this._abortSignal.addEventListener("abort", () => {
|
|
497
|
+
this.state = "cancel", this.close();
|
|
498
|
+
}, { once: true });
|
|
499
|
+
}
|
|
500
|
+
const e2 = new WriteStream(0);
|
|
501
|
+
e2._write = (s2, i2, D2) => {
|
|
502
|
+
this._track && (this.value = this.rl?.line.replace(/\t/g, ""), this._cursor = this.rl?.cursor ?? 0, this.emit("value", this.value)), D2();
|
|
503
|
+
}, this.input.pipe(e2), this.rl = f.createInterface({ input: this.input, output: e2, tabSize: 2, prompt: "", escapeCodeTimeout: 50 }), f.emitKeypressEvents(this.input, this.rl), this.rl.prompt(), this.opts.initialValue !== void 0 && this._track && this.rl.write(this.opts.initialValue), this.input.on("keypress", this.onKeypress), d$1(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
|
|
504
|
+
this.output.write(srcExports.cursor.show), this.output.off("resize", this.render), d$1(this.input, false), u3(this.value);
|
|
505
|
+
}), this.once("cancel", () => {
|
|
506
|
+
this.output.write(srcExports.cursor.show), this.output.off("resize", this.render), d$1(this.input, false), u3(S);
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
onKeypress(u3, F3) {
|
|
511
|
+
if (this.state === "error" && (this.state = "active"), F3?.name && (!this._track && c.aliases.has(F3.name) && this.emit("cursor", c.aliases.get(F3.name)), c.actions.has(F3.name) && this.emit("cursor", F3.name)), u3 && (u3.toLowerCase() === "y" || u3.toLowerCase() === "n") && this.emit("confirm", u3.toLowerCase() === "y"), u3 === " " && this.opts.placeholder && (this.value || (this.rl?.write(this.opts.placeholder), this.emit("value", this.opts.placeholder))), u3 && this.emit("key", u3.toLowerCase()), F3?.name === "return") {
|
|
512
|
+
if (this.opts.validate) {
|
|
513
|
+
const e2 = this.opts.validate(this.value);
|
|
514
|
+
e2 && (this.error = e2 instanceof Error ? e2.message : e2, this.state = "error", this.rl?.write(this.value));
|
|
515
|
+
}
|
|
516
|
+
this.state !== "error" && (this.state = "submit");
|
|
517
|
+
}
|
|
518
|
+
k$1([u3, F3?.name, F3?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
|
|
519
|
+
}
|
|
520
|
+
close() {
|
|
521
|
+
this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
|
|
522
|
+
`), d$1(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
|
|
523
|
+
}
|
|
524
|
+
restoreCursor() {
|
|
525
|
+
const u3 = G(this._prevFrame, process.stdout.columns, { hard: true }).split(`
|
|
526
|
+
`).length - 1;
|
|
527
|
+
this.output.write(srcExports.cursor.move(-999, u3 * -1));
|
|
528
|
+
}
|
|
529
|
+
render() {
|
|
530
|
+
const u3 = G(this._render(this) ?? "", process.stdout.columns, { hard: true });
|
|
531
|
+
if (u3 !== this._prevFrame) {
|
|
532
|
+
if (this.state === "initial") this.output.write(srcExports.cursor.hide);
|
|
533
|
+
else {
|
|
534
|
+
const F3 = lD(this._prevFrame, u3);
|
|
535
|
+
if (this.restoreCursor(), F3 && F3?.length === 1) {
|
|
536
|
+
const e2 = F3[0];
|
|
537
|
+
this.output.write(srcExports.cursor.move(0, e2)), this.output.write(srcExports.erase.lines(1));
|
|
538
|
+
const s2 = u3.split(`
|
|
539
|
+
`);
|
|
540
|
+
this.output.write(s2[e2]), this._prevFrame = u3, this.output.write(srcExports.cursor.move(0, s2.length - e2 - 1));
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
if (F3 && F3?.length > 1) {
|
|
544
|
+
const e2 = F3[0];
|
|
545
|
+
this.output.write(srcExports.cursor.move(0, e2)), this.output.write(srcExports.erase.down());
|
|
546
|
+
const s2 = u3.split(`
|
|
547
|
+
`).slice(e2);
|
|
548
|
+
this.output.write(s2.join(`
|
|
549
|
+
`)), this._prevFrame = u3;
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
this.output.write(srcExports.erase.down());
|
|
553
|
+
}
|
|
554
|
+
this.output.write(u3), this.state === "initial" && (this.state = "active"), this._prevFrame = u3;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
fD = class extends x {
|
|
559
|
+
get cursor() {
|
|
560
|
+
return this.value ? 0 : 1;
|
|
561
|
+
}
|
|
562
|
+
get _value() {
|
|
563
|
+
return this.cursor === 0;
|
|
564
|
+
}
|
|
565
|
+
constructor(u3) {
|
|
566
|
+
super(u3, false), this.value = !!u3.initialValue, this.on("value", () => {
|
|
567
|
+
this.value = this._value;
|
|
568
|
+
}), this.on("confirm", (F3) => {
|
|
569
|
+
this.output.write(srcExports.cursor.move(0, -1)), this.value = F3, this.state = "submit", this.close();
|
|
570
|
+
}), this.on("cursor", () => {
|
|
571
|
+
this.value = !this.value;
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
bD = Object.defineProperty;
|
|
576
|
+
mD = (t2, u3, F3) => u3 in t2 ? bD(t2, u3, { enumerable: true, configurable: true, writable: true, value: F3 }) : t2[u3] = F3;
|
|
577
|
+
Y = (t2, u3, F3) => (mD(t2, typeof u3 != "symbol" ? u3 + "" : u3, F3), F3);
|
|
578
|
+
wD = class extends x {
|
|
579
|
+
constructor(u3) {
|
|
580
|
+
super(u3, false), Y(this, "options"), Y(this, "cursor", 0), this.options = u3.options, this.value = [...u3.initialValues ?? []], this.cursor = Math.max(this.options.findIndex(({ value: F3 }) => F3 === u3.cursorAt), 0), this.on("key", (F3) => {
|
|
581
|
+
F3 === "a" && this.toggleAll();
|
|
582
|
+
}), this.on("cursor", (F3) => {
|
|
583
|
+
switch (F3) {
|
|
584
|
+
case "left":
|
|
585
|
+
case "up":
|
|
586
|
+
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
587
|
+
break;
|
|
588
|
+
case "down":
|
|
589
|
+
case "right":
|
|
590
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
591
|
+
break;
|
|
592
|
+
case "space":
|
|
593
|
+
this.toggleValue();
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
get _value() {
|
|
599
|
+
return this.options[this.cursor].value;
|
|
600
|
+
}
|
|
601
|
+
toggleAll() {
|
|
602
|
+
const u3 = this.value.length === this.options.length;
|
|
603
|
+
this.value = u3 ? [] : this.options.map((F3) => F3.value);
|
|
604
|
+
}
|
|
605
|
+
toggleValue() {
|
|
606
|
+
const u3 = this.value.includes(this._value);
|
|
607
|
+
this.value = u3 ? this.value.filter((F3) => F3 !== this._value) : [...this.value, this._value];
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
SD = Object.defineProperty;
|
|
611
|
+
$D = (t2, u3, F3) => u3 in t2 ? SD(t2, u3, { enumerable: true, configurable: true, writable: true, value: F3 }) : t2[u3] = F3;
|
|
612
|
+
q = (t2, u3, F3) => ($D(t2, typeof u3 != "symbol" ? u3 + "" : u3, F3), F3);
|
|
613
|
+
jD = class extends x {
|
|
614
|
+
constructor(u3) {
|
|
615
|
+
super(u3, false), q(this, "options"), q(this, "cursor", 0), this.options = u3.options, this.cursor = this.options.findIndex(({ value: F3 }) => F3 === u3.initialValue), this.cursor === -1 && (this.cursor = 0), this.changeValue(), this.on("cursor", (F3) => {
|
|
616
|
+
switch (F3) {
|
|
617
|
+
case "left":
|
|
618
|
+
case "up":
|
|
619
|
+
this.cursor = this.cursor === 0 ? this.options.length - 1 : this.cursor - 1;
|
|
620
|
+
break;
|
|
621
|
+
case "down":
|
|
622
|
+
case "right":
|
|
623
|
+
this.cursor = this.cursor === this.options.length - 1 ? 0 : this.cursor + 1;
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
this.changeValue();
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
get _value() {
|
|
630
|
+
return this.options[this.cursor];
|
|
631
|
+
}
|
|
632
|
+
changeValue() {
|
|
633
|
+
this.value = this._value.value;
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
PD = class extends x {
|
|
637
|
+
get valueWithCursor() {
|
|
638
|
+
if (this.state === "submit") return this.value;
|
|
639
|
+
if (this.cursor >= this.value.length) return `${this.value}\u2588`;
|
|
640
|
+
const u3 = this.value.slice(0, this.cursor), [F3, ...e$1] = this.value.slice(this.cursor);
|
|
641
|
+
return `${u3}${e.inverse(F3)}${e$1.join("")}`;
|
|
642
|
+
}
|
|
643
|
+
get cursor() {
|
|
644
|
+
return this._cursor;
|
|
645
|
+
}
|
|
646
|
+
constructor(u3) {
|
|
647
|
+
super(u3), this.on("finalize", () => {
|
|
648
|
+
this.value || (this.value = u3.defaultValue);
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
V = ce();
|
|
653
|
+
u = (t2, n2) => V ? t2 : n2;
|
|
654
|
+
le = u("\u276F", ">");
|
|
655
|
+
L = u("\u25A0", "x");
|
|
656
|
+
W = u("\u25B2", "x");
|
|
657
|
+
C = u("\u2714", "\u221A");
|
|
658
|
+
o = u("");
|
|
659
|
+
d = u("");
|
|
660
|
+
k = u("\u25CF", ">");
|
|
661
|
+
P = u("\u25CB", " ");
|
|
662
|
+
A = u("\u25FB", "[\u2022]");
|
|
663
|
+
T = u("\u25FC", "[+]");
|
|
664
|
+
F = u("\u25FB", "[ ]");
|
|
665
|
+
w = (t2) => {
|
|
666
|
+
switch (t2) {
|
|
667
|
+
case "initial":
|
|
668
|
+
case "active":
|
|
669
|
+
return e.cyan(le);
|
|
670
|
+
case "cancel":
|
|
671
|
+
return e.red(L);
|
|
672
|
+
case "error":
|
|
673
|
+
return e.yellow(W);
|
|
674
|
+
case "submit":
|
|
675
|
+
return e.green(C);
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
B = (t2) => {
|
|
679
|
+
const { cursor: n2, options: s2, style: r3 } = t2, i2 = t2.maxItems ?? Number.POSITIVE_INFINITY, a2 = Math.max(process.stdout.rows - 4, 0), c3 = Math.min(a2, Math.max(i2, 5));
|
|
680
|
+
let l2 = 0;
|
|
681
|
+
n2 >= l2 + c3 - 3 ? l2 = Math.max(Math.min(n2 - c3 + 3, s2.length - c3), 0) : n2 < l2 + 2 && (l2 = Math.max(n2 - 2, 0));
|
|
682
|
+
const $ = c3 < s2.length && l2 > 0, p = c3 < s2.length && l2 + c3 < s2.length;
|
|
683
|
+
return s2.slice(l2, l2 + c3).map((M, v2, x2) => {
|
|
684
|
+
const j = v2 === 0 && $, E = v2 === x2.length - 1 && p;
|
|
685
|
+
return j || E ? e.dim("...") : r3(M, v2 + l2 === n2);
|
|
686
|
+
});
|
|
687
|
+
};
|
|
688
|
+
he = (t2) => new PD({ validate: t2.validate, placeholder: t2.placeholder, defaultValue: t2.defaultValue, initialValue: t2.initialValue, render() {
|
|
689
|
+
const n2 = `${e.gray(o)}
|
|
690
|
+
${w(this.state)} ${t2.message}
|
|
691
|
+
`, s2 = t2.placeholder ? e.inverse(t2.placeholder[0]) + e.dim(t2.placeholder.slice(1)) : e.inverse(e.hidden("_")), r3 = this.value ? this.valueWithCursor : s2;
|
|
692
|
+
switch (this.state) {
|
|
693
|
+
case "error":
|
|
694
|
+
return `${n2.trim()}
|
|
695
|
+
${e.yellow(o)} ${r3}
|
|
696
|
+
${e.yellow(d)} ${e.yellow(this.error)}
|
|
697
|
+
`;
|
|
698
|
+
case "submit":
|
|
699
|
+
return `${n2}${e.gray(o)} ${e.dim(this.value || t2.placeholder)}`;
|
|
700
|
+
case "cancel":
|
|
701
|
+
return `${n2}${e.gray(o)} ${e.strikethrough(e.dim(this.value ?? ""))}${this.value?.trim() ? `
|
|
702
|
+
${e.gray(o)}` : ""}`;
|
|
703
|
+
default:
|
|
704
|
+
return `${n2}${e.cyan(o)} ${r3}
|
|
705
|
+
${e.cyan(d)}
|
|
706
|
+
`;
|
|
707
|
+
}
|
|
708
|
+
} }).prompt();
|
|
709
|
+
ye = (t2) => {
|
|
710
|
+
const n2 = t2.active ?? "Yes", s2 = t2.inactive ?? "No";
|
|
711
|
+
return new fD({ active: n2, inactive: s2, initialValue: t2.initialValue ?? true, render() {
|
|
712
|
+
const r3 = `${e.gray(o)}
|
|
713
|
+
${w(this.state)} ${t2.message}
|
|
714
|
+
`, i2 = this.value ? n2 : s2;
|
|
715
|
+
switch (this.state) {
|
|
716
|
+
case "submit":
|
|
717
|
+
return `${r3}${e.gray(o)} ${e.dim(i2)}`;
|
|
718
|
+
case "cancel":
|
|
719
|
+
return `${r3}${e.gray(o)} ${e.strikethrough(e.dim(i2))}
|
|
720
|
+
${e.gray(o)}`;
|
|
721
|
+
default:
|
|
722
|
+
return `${r3}${e.cyan(o)} ${this.value ? `${e.green(k)} ${n2}` : `${e.dim(P)} ${e.dim(n2)}`} ${e.dim("/")} ${this.value ? `${e.dim(P)} ${e.dim(s2)}` : `${e.green(k)} ${s2}`}
|
|
723
|
+
${e.cyan(d)}
|
|
724
|
+
`;
|
|
725
|
+
}
|
|
726
|
+
} }).prompt();
|
|
727
|
+
};
|
|
728
|
+
ve = (t2) => {
|
|
729
|
+
const n2 = (s2, r3) => {
|
|
730
|
+
const i2 = s2.label ?? String(s2.value);
|
|
731
|
+
switch (r3) {
|
|
732
|
+
case "selected":
|
|
733
|
+
return `${e.dim(i2)}`;
|
|
734
|
+
case "active":
|
|
735
|
+
return `${e.green(k)} ${i2} ${s2.hint ? e.dim(`(${s2.hint})`) : ""}`;
|
|
736
|
+
case "cancelled":
|
|
737
|
+
return `${e.strikethrough(e.dim(i2))}`;
|
|
738
|
+
default:
|
|
739
|
+
return `${e.dim(P)} ${e.dim(i2)}`;
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
return new jD({ options: t2.options, initialValue: t2.initialValue, render() {
|
|
743
|
+
const s2 = `${e.gray(o)}
|
|
744
|
+
${w(this.state)} ${t2.message}
|
|
745
|
+
`;
|
|
746
|
+
switch (this.state) {
|
|
747
|
+
case "submit":
|
|
748
|
+
return `${s2}${e.gray(o)} ${n2(this.options[this.cursor], "selected")}`;
|
|
749
|
+
case "cancel":
|
|
750
|
+
return `${s2}${e.gray(o)} ${n2(this.options[this.cursor], "cancelled")}
|
|
751
|
+
${e.gray(o)}`;
|
|
752
|
+
default:
|
|
753
|
+
return `${s2}${e.cyan(o)} ${B({ cursor: this.cursor, options: this.options, maxItems: t2.maxItems, style: (r3, i2) => n2(r3, i2 ? "active" : "inactive") }).join(`
|
|
754
|
+
${e.cyan(o)} `)}
|
|
755
|
+
${e.cyan(d)}
|
|
756
|
+
`;
|
|
757
|
+
}
|
|
758
|
+
} }).prompt();
|
|
759
|
+
};
|
|
760
|
+
fe = (t2) => {
|
|
761
|
+
const n2 = (s2, r3) => {
|
|
762
|
+
const i2 = s2.label ?? String(s2.value);
|
|
763
|
+
return r3 === "active" ? `${e.cyan(A)} ${i2} ${s2.hint ? e.dim(`(${s2.hint})`) : ""}` : r3 === "selected" ? `${e.green(T)} ${e.dim(i2)}` : r3 === "cancelled" ? `${e.strikethrough(e.dim(i2))}` : r3 === "active-selected" ? `${e.green(T)} ${i2} ${s2.hint ? e.dim(`(${s2.hint})`) : ""}` : r3 === "submitted" ? `${e.dim(i2)}` : `${e.dim(F)} ${e.dim(i2)}`;
|
|
764
|
+
};
|
|
765
|
+
return new wD({ options: t2.options, initialValues: t2.initialValues, required: t2.required ?? true, cursorAt: t2.cursorAt, validate(s2) {
|
|
766
|
+
if (this.required && s2.length === 0) return `Please select at least one option.
|
|
767
|
+
${e.reset(e.dim(`Press ${e.gray(e.bgWhite(e.inverse(" space ")))} to select, ${e.gray(e.bgWhite(e.inverse(" enter ")))} to submit`))}`;
|
|
768
|
+
}, render() {
|
|
769
|
+
const s2 = `${e.gray(o)}
|
|
770
|
+
${w(this.state)} ${t2.message}
|
|
771
|
+
`, r3 = (i2, a2) => {
|
|
772
|
+
const c3 = this.value.includes(i2.value);
|
|
773
|
+
return a2 && c3 ? n2(i2, "active-selected") : c3 ? n2(i2, "selected") : n2(i2, a2 ? "active" : "inactive");
|
|
774
|
+
};
|
|
775
|
+
switch (this.state) {
|
|
776
|
+
case "submit":
|
|
777
|
+
return `${s2}${e.gray(o)} ${this.options.filter(({ value: i2 }) => this.value.includes(i2)).map((i2) => n2(i2, "submitted")).join(e.dim(", ")) || e.dim("none")}`;
|
|
778
|
+
case "cancel": {
|
|
779
|
+
const i2 = this.options.filter(({ value: a2 }) => this.value.includes(a2)).map((a2) => n2(a2, "cancelled")).join(e.dim(", "));
|
|
780
|
+
return `${s2}${e.gray(o)} ${i2.trim() ? `${i2}
|
|
781
|
+
${e.gray(o)}` : ""}`;
|
|
782
|
+
}
|
|
783
|
+
case "error": {
|
|
784
|
+
const i2 = this.error.split(`
|
|
785
|
+
`).map((a2, c3) => c3 === 0 ? `${e.yellow(d)} ${e.yellow(a2)}` : ` ${a2}`).join(`
|
|
786
|
+
`);
|
|
787
|
+
return `${s2 + e.yellow(o)} ${B({ options: this.options, cursor: this.cursor, maxItems: t2.maxItems, style: r3 }).join(`
|
|
788
|
+
${e.yellow(o)} `)}
|
|
789
|
+
${i2}
|
|
790
|
+
`;
|
|
791
|
+
}
|
|
792
|
+
default:
|
|
793
|
+
return `${s2}${e.cyan(o)} ${B({ options: this.options, cursor: this.cursor, maxItems: t2.maxItems, style: r3 }).join(`
|
|
794
|
+
${e.cyan(o)} `)}
|
|
795
|
+
${e.cyan(d)}
|
|
796
|
+
`;
|
|
797
|
+
}
|
|
798
|
+
} }).prompt();
|
|
799
|
+
};
|
|
800
|
+
`${e.gray(o)} `;
|
|
801
|
+
kCancel = /* @__PURE__ */ Symbol.for("cancel");
|
|
802
|
+
}
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
// ../../node_modules/.pnpm/shell-quote@1.8.3/node_modules/shell-quote/quote.js
|
|
806
|
+
var require_quote = __commonJS({
|
|
807
|
+
"../../node_modules/.pnpm/shell-quote@1.8.3/node_modules/shell-quote/quote.js"(exports, module) {
|
|
808
|
+
"use strict";
|
|
809
|
+
module.exports = function quote(xs) {
|
|
810
|
+
return xs.map(function(s2) {
|
|
811
|
+
if (s2 === "") {
|
|
812
|
+
return "''";
|
|
813
|
+
}
|
|
814
|
+
if (s2 && typeof s2 === "object") {
|
|
815
|
+
return s2.op.replace(/(.)/g, "\\$1");
|
|
816
|
+
}
|
|
817
|
+
if (/["\s\\]/.test(s2) && !/'/.test(s2)) {
|
|
818
|
+
return "'" + s2.replace(/(['])/g, "\\$1") + "'";
|
|
819
|
+
}
|
|
820
|
+
if (/["'\s]/.test(s2)) {
|
|
821
|
+
return '"' + s2.replace(/(["\\$`!])/g, "\\$1") + '"';
|
|
822
|
+
}
|
|
823
|
+
return String(s2).replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@[\\\]^`{|}])/g, "$1\\$2");
|
|
824
|
+
}).join(" ");
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
// ../../node_modules/.pnpm/shell-quote@1.8.3/node_modules/shell-quote/parse.js
|
|
830
|
+
var require_parse = __commonJS({
|
|
831
|
+
"../../node_modules/.pnpm/shell-quote@1.8.3/node_modules/shell-quote/parse.js"(exports, module) {
|
|
832
|
+
"use strict";
|
|
833
|
+
var CONTROL = "(?:" + [
|
|
834
|
+
"\\|\\|",
|
|
835
|
+
"\\&\\&",
|
|
836
|
+
";;",
|
|
837
|
+
"\\|\\&",
|
|
838
|
+
"\\<\\(",
|
|
839
|
+
"\\<\\<\\<",
|
|
840
|
+
">>",
|
|
841
|
+
">\\&",
|
|
842
|
+
"<\\&",
|
|
843
|
+
"[&;()|<>]"
|
|
844
|
+
].join("|") + ")";
|
|
845
|
+
var controlRE = new RegExp("^" + CONTROL + "$");
|
|
846
|
+
var META = "|&;()<> \\t";
|
|
847
|
+
var SINGLE_QUOTE = '"((\\\\"|[^"])*?)"';
|
|
848
|
+
var DOUBLE_QUOTE = "'((\\\\'|[^'])*?)'";
|
|
849
|
+
var hash = /^#$/;
|
|
850
|
+
var SQ = "'";
|
|
851
|
+
var DQ = '"';
|
|
852
|
+
var DS = "$";
|
|
853
|
+
var TOKEN = "";
|
|
854
|
+
var mult = 4294967296;
|
|
855
|
+
for (i2 = 0; i2 < 4; i2++) {
|
|
856
|
+
TOKEN += (mult * Math.random()).toString(16);
|
|
857
|
+
}
|
|
858
|
+
var i2;
|
|
859
|
+
var startsWithToken = new RegExp("^" + TOKEN);
|
|
860
|
+
function matchAll(s2, r3) {
|
|
861
|
+
var origIndex = r3.lastIndex;
|
|
862
|
+
var matches = [];
|
|
863
|
+
var matchObj;
|
|
864
|
+
while (matchObj = r3.exec(s2)) {
|
|
865
|
+
matches.push(matchObj);
|
|
866
|
+
if (r3.lastIndex === matchObj.index) {
|
|
867
|
+
r3.lastIndex += 1;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
r3.lastIndex = origIndex;
|
|
871
|
+
return matches;
|
|
872
|
+
}
|
|
873
|
+
function getVar(env2, pre, key) {
|
|
874
|
+
var r3 = typeof env2 === "function" ? env2(key) : env2[key];
|
|
875
|
+
if (typeof r3 === "undefined" && key != "") {
|
|
876
|
+
r3 = "";
|
|
877
|
+
} else if (typeof r3 === "undefined") {
|
|
878
|
+
r3 = "$";
|
|
879
|
+
}
|
|
880
|
+
if (typeof r3 === "object") {
|
|
881
|
+
return pre + TOKEN + JSON.stringify(r3) + TOKEN;
|
|
882
|
+
}
|
|
883
|
+
return pre + r3;
|
|
884
|
+
}
|
|
885
|
+
function parseInternal(string, env2, opts) {
|
|
886
|
+
if (!opts) {
|
|
887
|
+
opts = {};
|
|
888
|
+
}
|
|
889
|
+
var BS = opts.escape || "\\";
|
|
890
|
+
var BAREWORD = "(\\" + BS + `['"` + META + `]|[^\\s'"` + META + "])+";
|
|
891
|
+
var chunker = new RegExp([
|
|
892
|
+
"(" + CONTROL + ")",
|
|
893
|
+
// control chars
|
|
894
|
+
"(" + BAREWORD + "|" + SINGLE_QUOTE + "|" + DOUBLE_QUOTE + ")+"
|
|
895
|
+
].join("|"), "g");
|
|
896
|
+
var matches = matchAll(string, chunker);
|
|
897
|
+
if (matches.length === 0) {
|
|
898
|
+
return [];
|
|
899
|
+
}
|
|
900
|
+
if (!env2) {
|
|
901
|
+
env2 = {};
|
|
902
|
+
}
|
|
903
|
+
var commented = false;
|
|
904
|
+
return matches.map(function(match) {
|
|
905
|
+
var s2 = match[0];
|
|
906
|
+
if (!s2 || commented) {
|
|
907
|
+
return void 0;
|
|
908
|
+
}
|
|
909
|
+
if (controlRE.test(s2)) {
|
|
910
|
+
return { op: s2 };
|
|
911
|
+
}
|
|
912
|
+
var quote = false;
|
|
913
|
+
var esc = false;
|
|
914
|
+
var out = "";
|
|
915
|
+
var isGlob = false;
|
|
916
|
+
var i3;
|
|
917
|
+
function parseEnvVar() {
|
|
918
|
+
i3 += 1;
|
|
919
|
+
var varend;
|
|
920
|
+
var varname;
|
|
921
|
+
var char = s2.charAt(i3);
|
|
922
|
+
if (char === "{") {
|
|
923
|
+
i3 += 1;
|
|
924
|
+
if (s2.charAt(i3) === "}") {
|
|
925
|
+
throw new Error("Bad substitution: " + s2.slice(i3 - 2, i3 + 1));
|
|
926
|
+
}
|
|
927
|
+
varend = s2.indexOf("}", i3);
|
|
928
|
+
if (varend < 0) {
|
|
929
|
+
throw new Error("Bad substitution: " + s2.slice(i3));
|
|
930
|
+
}
|
|
931
|
+
varname = s2.slice(i3, varend);
|
|
932
|
+
i3 = varend;
|
|
933
|
+
} else if (/[*@#?$!_-]/.test(char)) {
|
|
934
|
+
varname = char;
|
|
935
|
+
i3 += 1;
|
|
936
|
+
} else {
|
|
937
|
+
var slicedFromI = s2.slice(i3);
|
|
938
|
+
varend = slicedFromI.match(/[^\w\d_]/);
|
|
939
|
+
if (!varend) {
|
|
940
|
+
varname = slicedFromI;
|
|
941
|
+
i3 = s2.length;
|
|
942
|
+
} else {
|
|
943
|
+
varname = slicedFromI.slice(0, varend.index);
|
|
944
|
+
i3 += varend.index - 1;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
return getVar(env2, "", varname);
|
|
948
|
+
}
|
|
949
|
+
for (i3 = 0; i3 < s2.length; i3++) {
|
|
950
|
+
var c3 = s2.charAt(i3);
|
|
951
|
+
isGlob = isGlob || !quote && (c3 === "*" || c3 === "?");
|
|
952
|
+
if (esc) {
|
|
953
|
+
out += c3;
|
|
954
|
+
esc = false;
|
|
955
|
+
} else if (quote) {
|
|
956
|
+
if (c3 === quote) {
|
|
957
|
+
quote = false;
|
|
958
|
+
} else if (quote == SQ) {
|
|
959
|
+
out += c3;
|
|
960
|
+
} else {
|
|
961
|
+
if (c3 === BS) {
|
|
962
|
+
i3 += 1;
|
|
963
|
+
c3 = s2.charAt(i3);
|
|
964
|
+
if (c3 === DQ || c3 === BS || c3 === DS) {
|
|
965
|
+
out += c3;
|
|
966
|
+
} else {
|
|
967
|
+
out += BS + c3;
|
|
968
|
+
}
|
|
969
|
+
} else if (c3 === DS) {
|
|
970
|
+
out += parseEnvVar();
|
|
971
|
+
} else {
|
|
972
|
+
out += c3;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
} else if (c3 === DQ || c3 === SQ) {
|
|
976
|
+
quote = c3;
|
|
977
|
+
} else if (controlRE.test(c3)) {
|
|
978
|
+
return { op: s2 };
|
|
979
|
+
} else if (hash.test(c3)) {
|
|
980
|
+
commented = true;
|
|
981
|
+
var commentObj = { comment: string.slice(match.index + i3 + 1) };
|
|
982
|
+
if (out.length) {
|
|
983
|
+
return [out, commentObj];
|
|
984
|
+
}
|
|
985
|
+
return [commentObj];
|
|
986
|
+
} else if (c3 === BS) {
|
|
987
|
+
esc = true;
|
|
988
|
+
} else if (c3 === DS) {
|
|
989
|
+
out += parseEnvVar();
|
|
990
|
+
} else {
|
|
991
|
+
out += c3;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
if (isGlob) {
|
|
995
|
+
return { op: "glob", pattern: out };
|
|
996
|
+
}
|
|
997
|
+
return out;
|
|
998
|
+
}).reduce(function(prev, arg) {
|
|
999
|
+
return typeof arg === "undefined" ? prev : prev.concat(arg);
|
|
1000
|
+
}, []);
|
|
1001
|
+
}
|
|
1002
|
+
module.exports = function parse(s2, env2, opts) {
|
|
1003
|
+
var mapped = parseInternal(s2, env2, opts);
|
|
1004
|
+
if (typeof env2 !== "function") {
|
|
1005
|
+
return mapped;
|
|
1006
|
+
}
|
|
1007
|
+
return mapped.reduce(function(acc, s3) {
|
|
1008
|
+
if (typeof s3 === "object") {
|
|
1009
|
+
return acc.concat(s3);
|
|
1010
|
+
}
|
|
1011
|
+
var xs = s3.split(RegExp("(" + TOKEN + ".*?" + TOKEN + ")", "g"));
|
|
1012
|
+
if (xs.length === 1) {
|
|
1013
|
+
return acc.concat(xs[0]);
|
|
1014
|
+
}
|
|
1015
|
+
return acc.concat(xs.filter(Boolean).map(function(x2) {
|
|
1016
|
+
if (startsWithToken.test(x2)) {
|
|
1017
|
+
return JSON.parse(x2.split(TOKEN)[1]);
|
|
1018
|
+
}
|
|
1019
|
+
return x2;
|
|
1020
|
+
}));
|
|
1021
|
+
}, []);
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
// ../../node_modules/.pnpm/shell-quote@1.8.3/node_modules/shell-quote/index.js
|
|
1027
|
+
var require_shell_quote = __commonJS({
|
|
1028
|
+
"../../node_modules/.pnpm/shell-quote@1.8.3/node_modules/shell-quote/index.js"(exports) {
|
|
1029
|
+
"use strict";
|
|
1030
|
+
exports.quote = require_quote();
|
|
1031
|
+
exports.parse = require_parse();
|
|
1032
|
+
}
|
|
1033
|
+
});
|
|
1034
|
+
|
|
1035
|
+
// ../../packages/apes/dist/chunk-7OCVIDC7.js
|
|
1036
|
+
var init_chunk_7OCVIDC7 = __esm({
|
|
1037
|
+
"../../packages/apes/dist/chunk-7OCVIDC7.js"() {
|
|
1038
|
+
"use strict";
|
|
1039
|
+
}
|
|
1040
|
+
});
|
|
1041
|
+
|
|
1042
|
+
// src/bridge.ts
|
|
1043
|
+
import { existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
|
|
1044
|
+
import { homedir as homedir8 } from "os";
|
|
1045
|
+
import { join as join8 } from "path";
|
|
1046
|
+
import process2 from "process";
|
|
1047
|
+
|
|
1048
|
+
// ../../packages/cli-auth/dist/index.js
|
|
1049
|
+
import { ofetch } from "ofetch";
|
|
1050
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from "fs";
|
|
1051
|
+
import { homedir } from "os";
|
|
1052
|
+
import { join } from "path";
|
|
1053
|
+
import { ofetch as ofetch3 } from "ofetch";
|
|
1054
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
1055
|
+
import { sign } from "crypto";
|
|
1056
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
1057
|
+
import { homedir as homedir2 } from "os";
|
|
1058
|
+
import { join as join2 } from "path";
|
|
1059
|
+
import { ofetch as ofetch2 } from "ofetch";
|
|
1060
|
+
import { Buffer as Buffer3 } from "buffer";
|
|
1061
|
+
import { createPrivateKey } from "crypto";
|
|
1062
|
+
import { ofetch as ofetch4 } from "ofetch";
|
|
1063
|
+
function getConfigDir() {
|
|
1064
|
+
const override = process.env.OPENAPE_CLI_AUTH_HOME;
|
|
1065
|
+
if (override) return override;
|
|
1066
|
+
return join(homedir(), ".config", "apes");
|
|
1067
|
+
}
|
|
1068
|
+
function getAuthFile() {
|
|
1069
|
+
return join(getConfigDir(), "auth.json");
|
|
1070
|
+
}
|
|
1071
|
+
function ensureConfigDir() {
|
|
1072
|
+
const dir = getConfigDir();
|
|
1073
|
+
if (!existsSync(dir)) {
|
|
1074
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
function loadIdpAuth() {
|
|
1078
|
+
const file = getAuthFile();
|
|
1079
|
+
if (!existsSync(file)) return null;
|
|
1080
|
+
try {
|
|
1081
|
+
const raw = readFileSync(file, "utf-8");
|
|
1082
|
+
if (!raw.trim()) return null;
|
|
1083
|
+
return JSON.parse(raw);
|
|
1084
|
+
} catch {
|
|
1085
|
+
return null;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
function saveIdpAuth(auth) {
|
|
1089
|
+
ensureConfigDir();
|
|
1090
|
+
const file = getAuthFile();
|
|
1091
|
+
let extra = {};
|
|
1092
|
+
if (existsSync(file)) {
|
|
1093
|
+
try {
|
|
1094
|
+
const raw = readFileSync(file, "utf-8");
|
|
1095
|
+
if (raw.trim()) {
|
|
1096
|
+
const prev = JSON.parse(raw);
|
|
1097
|
+
for (const key of Object.keys(prev)) {
|
|
1098
|
+
if (!(key in auth)) {
|
|
1099
|
+
extra[key] = prev[key];
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
} catch {
|
|
1104
|
+
extra = {};
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
const merged = { ...extra, ...auth };
|
|
1108
|
+
writeFileSync(file, JSON.stringify(merged, null, 2), { mode: 384 });
|
|
1109
|
+
}
|
|
1110
|
+
var AuthError = class extends Error {
|
|
1111
|
+
status;
|
|
1112
|
+
hint;
|
|
1113
|
+
constructor(status, message, hint) {
|
|
1114
|
+
super(hint ? `${message}
|
|
1115
|
+
${hint}` : message);
|
|
1116
|
+
this.name = "AuthError";
|
|
1117
|
+
this.status = status;
|
|
1118
|
+
this.hint = hint;
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1121
|
+
var NotLoggedInError = class extends AuthError {
|
|
1122
|
+
constructor(hint) {
|
|
1123
|
+
super(
|
|
1124
|
+
401,
|
|
1125
|
+
"Not logged in",
|
|
1126
|
+
hint ?? "Run `apes login <email>` once on this device to authenticate against the OpenApe IdP."
|
|
1127
|
+
);
|
|
1128
|
+
this.name = "NotLoggedInError";
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
var OPENSSH_MAGIC = "openssh-key-v1\0";
|
|
1132
|
+
function loadEd25519PrivateKey(pem) {
|
|
1133
|
+
if (pem.includes("BEGIN OPENSSH PRIVATE KEY")) {
|
|
1134
|
+
return parseOpenSSHEd25519(pem);
|
|
1135
|
+
}
|
|
1136
|
+
return createPrivateKey(pem);
|
|
1137
|
+
}
|
|
1138
|
+
function parseOpenSSHEd25519(pem) {
|
|
1139
|
+
const b64 = pem.replace(/-----BEGIN OPENSSH PRIVATE KEY-----/, "").replace(/-----END OPENSSH PRIVATE KEY-----/, "").replace(/\s/g, "");
|
|
1140
|
+
const buf = Buffer3.from(b64, "base64");
|
|
1141
|
+
let offset = 0;
|
|
1142
|
+
const magic = buf.subarray(0, OPENSSH_MAGIC.length).toString("ascii");
|
|
1143
|
+
if (magic !== OPENSSH_MAGIC) {
|
|
1144
|
+
throw new Error("Not an OpenSSH private key");
|
|
1145
|
+
}
|
|
1146
|
+
offset += OPENSSH_MAGIC.length;
|
|
1147
|
+
const cipherLen = buf.readUInt32BE(offset);
|
|
1148
|
+
offset += 4;
|
|
1149
|
+
const cipher = buf.subarray(offset, offset + cipherLen).toString();
|
|
1150
|
+
offset += cipherLen;
|
|
1151
|
+
if (cipher !== "none") {
|
|
1152
|
+
throw new Error(`Encrypted keys not supported (cipher: ${cipher}). Decrypt first with: ssh-keygen -p -f <key>`);
|
|
1153
|
+
}
|
|
1154
|
+
const kdfLen = buf.readUInt32BE(offset);
|
|
1155
|
+
offset += 4;
|
|
1156
|
+
offset += kdfLen;
|
|
1157
|
+
const kdfOptsLen = buf.readUInt32BE(offset);
|
|
1158
|
+
offset += 4;
|
|
1159
|
+
offset += kdfOptsLen;
|
|
1160
|
+
const numKeys = buf.readUInt32BE(offset);
|
|
1161
|
+
offset += 4;
|
|
1162
|
+
if (numKeys !== 1) {
|
|
1163
|
+
throw new Error(`Expected 1 key, got ${numKeys}`);
|
|
1164
|
+
}
|
|
1165
|
+
const pubSectionLen = buf.readUInt32BE(offset);
|
|
1166
|
+
offset += 4;
|
|
1167
|
+
offset += pubSectionLen;
|
|
1168
|
+
const privSectionLen = buf.readUInt32BE(offset);
|
|
1169
|
+
offset += 4;
|
|
1170
|
+
const privSection = buf.subarray(offset, offset + privSectionLen);
|
|
1171
|
+
let pOffset = 0;
|
|
1172
|
+
const check1 = privSection.readUInt32BE(pOffset);
|
|
1173
|
+
pOffset += 4;
|
|
1174
|
+
const check2 = privSection.readUInt32BE(pOffset);
|
|
1175
|
+
pOffset += 4;
|
|
1176
|
+
if (check1 !== check2) {
|
|
1177
|
+
throw new Error("Check integers mismatch \u2014 key may be corrupted or encrypted");
|
|
1178
|
+
}
|
|
1179
|
+
const keyTypeLen = privSection.readUInt32BE(pOffset);
|
|
1180
|
+
pOffset += 4;
|
|
1181
|
+
const keyType = privSection.subarray(pOffset, pOffset + keyTypeLen).toString();
|
|
1182
|
+
pOffset += keyTypeLen;
|
|
1183
|
+
if (keyType !== "ssh-ed25519") {
|
|
1184
|
+
throw new Error(`Expected ssh-ed25519, got ${keyType}`);
|
|
1185
|
+
}
|
|
1186
|
+
const pubKeyLen = privSection.readUInt32BE(pOffset);
|
|
1187
|
+
pOffset += 4;
|
|
1188
|
+
const pubKey = privSection.subarray(pOffset, pOffset + pubKeyLen);
|
|
1189
|
+
pOffset += pubKeyLen;
|
|
1190
|
+
const privKeyLen = privSection.readUInt32BE(pOffset);
|
|
1191
|
+
pOffset += 4;
|
|
1192
|
+
const privKeyData = privSection.subarray(pOffset, pOffset + privKeyLen);
|
|
1193
|
+
const seed = privKeyData.subarray(0, 32);
|
|
1194
|
+
return createPrivateKey({
|
|
1195
|
+
key: { kty: "OKP", crv: "Ed25519", d: seed.toString("base64url"), x: pubKey.toString("base64url") },
|
|
1196
|
+
format: "jwk"
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
async function getEndpoints(idp) {
|
|
1200
|
+
let disco = {};
|
|
1201
|
+
try {
|
|
1202
|
+
disco = await ofetch2(`${idp}/.well-known/openid-configuration`);
|
|
1203
|
+
} catch {
|
|
1204
|
+
}
|
|
1205
|
+
return {
|
|
1206
|
+
challenge: disco.ddisa_agent_challenge_endpoint ?? `${idp}/api/agent/challenge`,
|
|
1207
|
+
authenticate: disco.ddisa_agent_authenticate_endpoint ?? `${idp}/api/agent/authenticate`
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
function resolveKeyPath(p) {
|
|
1211
|
+
if (p.startsWith("~")) return join2(homedir2(), p.slice(1));
|
|
1212
|
+
return p;
|
|
1213
|
+
}
|
|
1214
|
+
function findSigningKey(auth) {
|
|
1215
|
+
const candidates = [];
|
|
1216
|
+
if (auth.key_path) candidates.push(resolveKeyPath(auth.key_path));
|
|
1217
|
+
candidates.push(join2(homedir2(), ".ssh", "id_ed25519"));
|
|
1218
|
+
for (const p of candidates) {
|
|
1219
|
+
if (existsSync2(p)) {
|
|
1220
|
+
try {
|
|
1221
|
+
return { keyPath: p, keyContent: readFileSync2(p, "utf-8") };
|
|
1222
|
+
} catch {
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
return null;
|
|
1227
|
+
}
|
|
1228
|
+
async function refreshAgentToken(auth, now = Math.floor(Date.now() / 1e3)) {
|
|
1229
|
+
const key = findSigningKey(auth);
|
|
1230
|
+
if (!key) return null;
|
|
1231
|
+
let privateKey;
|
|
1232
|
+
try {
|
|
1233
|
+
privateKey = loadEd25519PrivateKey(key.keyContent);
|
|
1234
|
+
} catch {
|
|
1235
|
+
return null;
|
|
1236
|
+
}
|
|
1237
|
+
let endpoints;
|
|
1238
|
+
try {
|
|
1239
|
+
endpoints = await getEndpoints(auth.idp);
|
|
1240
|
+
} catch {
|
|
1241
|
+
return null;
|
|
1242
|
+
}
|
|
1243
|
+
let challenge;
|
|
1244
|
+
try {
|
|
1245
|
+
const resp = await ofetch2(endpoints.challenge, {
|
|
1246
|
+
method: "POST",
|
|
1247
|
+
headers: { "Content-Type": "application/json" },
|
|
1248
|
+
body: { agent_id: auth.email }
|
|
1249
|
+
});
|
|
1250
|
+
challenge = resp.challenge;
|
|
1251
|
+
} catch {
|
|
1252
|
+
return null;
|
|
1253
|
+
}
|
|
1254
|
+
let signature;
|
|
1255
|
+
try {
|
|
1256
|
+
signature = sign(null, Buffer2.from(challenge), privateKey).toString("base64");
|
|
1257
|
+
} catch {
|
|
1258
|
+
return null;
|
|
1259
|
+
}
|
|
1260
|
+
let authResp;
|
|
1261
|
+
try {
|
|
1262
|
+
authResp = await ofetch2(endpoints.authenticate, {
|
|
1263
|
+
method: "POST",
|
|
1264
|
+
headers: { "Content-Type": "application/json" },
|
|
1265
|
+
body: { agent_id: auth.email, challenge, signature }
|
|
1266
|
+
});
|
|
1267
|
+
} catch {
|
|
1268
|
+
return null;
|
|
1269
|
+
}
|
|
1270
|
+
return {
|
|
1271
|
+
...auth,
|
|
1272
|
+
access_token: authResp.token,
|
|
1273
|
+
expires_at: now + (authResp.expires_in || 3600),
|
|
1274
|
+
key_path: auth.key_path ?? key.keyPath
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
var EXPIRY_SKEW_SECONDS = 30;
|
|
1278
|
+
async function getTokenEndpoint(idp) {
|
|
1279
|
+
try {
|
|
1280
|
+
const disco = await ofetch3(`${idp}/.well-known/openid-configuration`);
|
|
1281
|
+
if (disco.token_endpoint) return disco.token_endpoint;
|
|
1282
|
+
} catch {
|
|
1283
|
+
}
|
|
1284
|
+
return `${idp}/token`;
|
|
1285
|
+
}
|
|
1286
|
+
async function ensureFreshIdpAuth(now = Math.floor(Date.now() / 1e3)) {
|
|
1287
|
+
const auth = loadIdpAuth();
|
|
1288
|
+
if (!auth) {
|
|
1289
|
+
throw new NotLoggedInError();
|
|
1290
|
+
}
|
|
1291
|
+
if (auth.expires_at > now + EXPIRY_SKEW_SECONDS) {
|
|
1292
|
+
return auth;
|
|
1293
|
+
}
|
|
1294
|
+
if (!auth.refresh_token) {
|
|
1295
|
+
const refreshed = await refreshAgentToken(auth, now);
|
|
1296
|
+
if (refreshed) {
|
|
1297
|
+
saveIdpAuth(refreshed);
|
|
1298
|
+
return refreshed;
|
|
1299
|
+
}
|
|
1300
|
+
throw new NotLoggedInError(
|
|
1301
|
+
`IdP token expired at ${new Date(auth.expires_at * 1e3).toISOString()} and no refresh_token is stored. Run \`apes login\` again.`
|
|
1302
|
+
);
|
|
1303
|
+
}
|
|
1304
|
+
const tokenEndpoint = await getTokenEndpoint(auth.idp);
|
|
1305
|
+
const body = new URLSearchParams({
|
|
1306
|
+
grant_type: "refresh_token",
|
|
1307
|
+
refresh_token: auth.refresh_token
|
|
1308
|
+
});
|
|
1309
|
+
let response;
|
|
1310
|
+
try {
|
|
1311
|
+
response = await ofetch3(tokenEndpoint, {
|
|
1312
|
+
method: "POST",
|
|
1313
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1314
|
+
body: body.toString()
|
|
1315
|
+
});
|
|
1316
|
+
} catch (err) {
|
|
1317
|
+
const status = err.status ?? err.statusCode ?? 0;
|
|
1318
|
+
if (status === 400 || status === 401) {
|
|
1319
|
+
saveIdpAuth({ ...auth, refresh_token: void 0 });
|
|
1320
|
+
throw new NotLoggedInError(
|
|
1321
|
+
`Refresh token rejected by ${auth.idp}. Run \`apes login\` again.`
|
|
1322
|
+
);
|
|
1323
|
+
}
|
|
1324
|
+
throw new AuthError(
|
|
1325
|
+
0,
|
|
1326
|
+
`Network error refreshing IdP token at ${tokenEndpoint}`,
|
|
1327
|
+
`Underlying: ${err.message ?? err}`
|
|
1328
|
+
);
|
|
1329
|
+
}
|
|
1330
|
+
if (!response.access_token) {
|
|
1331
|
+
throw new AuthError(0, `IdP refresh response missing access_token (endpoint: ${tokenEndpoint})`);
|
|
1332
|
+
}
|
|
1333
|
+
const next = {
|
|
1334
|
+
...auth,
|
|
1335
|
+
access_token: response.access_token,
|
|
1336
|
+
refresh_token: response.refresh_token ?? auth.refresh_token,
|
|
1337
|
+
expires_at: now + (response.expires_in ?? 3600)
|
|
1338
|
+
};
|
|
1339
|
+
saveIdpAuth(next);
|
|
1340
|
+
return next;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// src/bridge.ts
|
|
1344
|
+
import { decodeJwt } from "jose";
|
|
1345
|
+
import WebSocket from "ws";
|
|
1346
|
+
|
|
1347
|
+
// src/chat-api.ts
|
|
1348
|
+
import { ofetch as ofetch5 } from "ofetch";
|
|
1349
|
+
var MAX_BODY = 1e4;
|
|
1350
|
+
var ChatApi = class {
|
|
1351
|
+
constructor(endpoint, bearer) {
|
|
1352
|
+
this.endpoint = endpoint;
|
|
1353
|
+
this.bearer = bearer;
|
|
1354
|
+
}
|
|
1355
|
+
async postMessage(roomId, body, opts = {}) {
|
|
1356
|
+
const trimmed = clamp(body, MAX_BODY);
|
|
1357
|
+
const url = `${this.endpoint}/api/rooms/${encodeURIComponent(roomId)}/messages`;
|
|
1358
|
+
const payload = { body: trimmed };
|
|
1359
|
+
if (opts.replyTo) payload.reply_to = opts.replyTo;
|
|
1360
|
+
if (opts.threadId) payload.thread_id = opts.threadId;
|
|
1361
|
+
const result = await ofetch5(url, {
|
|
1362
|
+
method: "POST",
|
|
1363
|
+
headers: { Authorization: await this.bearer() },
|
|
1364
|
+
body: payload
|
|
1365
|
+
});
|
|
1366
|
+
return result;
|
|
1367
|
+
}
|
|
1368
|
+
async requestContact(peerEmail) {
|
|
1369
|
+
const url = `${this.endpoint}/api/contacts`;
|
|
1370
|
+
return await ofetch5(url, {
|
|
1371
|
+
method: "POST",
|
|
1372
|
+
headers: { Authorization: await this.bearer() },
|
|
1373
|
+
body: { email: peerEmail }
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
async listContacts() {
|
|
1377
|
+
const url = `${this.endpoint}/api/contacts`;
|
|
1378
|
+
return await ofetch5(url, {
|
|
1379
|
+
method: "GET",
|
|
1380
|
+
headers: { Authorization: await this.bearer() }
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
async acceptContact(peerEmail) {
|
|
1384
|
+
const url = `${this.endpoint}/api/contacts/${encodeURIComponent(peerEmail)}/accept`;
|
|
1385
|
+
return await ofetch5(url, {
|
|
1386
|
+
method: "POST",
|
|
1387
|
+
headers: { Authorization: await this.bearer() }
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Create a named thread in a room. Used by the cron-runner to drop
|
|
1392
|
+
* each task's runs into its own thread so the chat sidebar shows
|
|
1393
|
+
* one thread per task instead of all task DMs piling into the
|
|
1394
|
+
* main thread.
|
|
1395
|
+
*/
|
|
1396
|
+
async createThread(roomId, name) {
|
|
1397
|
+
const url = `${this.endpoint}/api/rooms/${encodeURIComponent(roomId)}/threads`;
|
|
1398
|
+
return await ofetch5(url, {
|
|
1399
|
+
method: "POST",
|
|
1400
|
+
headers: { Authorization: await this.bearer() },
|
|
1401
|
+
body: { name: name.slice(0, 100) }
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
async patchMessage(messageId, body) {
|
|
1405
|
+
const trimmed = clamp(body, MAX_BODY);
|
|
1406
|
+
const url = `${this.endpoint}/api/messages/${encodeURIComponent(messageId)}`;
|
|
1407
|
+
await ofetch5(url, {
|
|
1408
|
+
method: "PATCH",
|
|
1409
|
+
headers: { Authorization: await this.bearer() },
|
|
1410
|
+
body: { body: trimmed }
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
};
|
|
1414
|
+
function clamp(s2, max) {
|
|
1415
|
+
if (s2.trim().length === 0) return "\u2026";
|
|
1416
|
+
if (s2.length <= max) return s2;
|
|
1417
|
+
return `${s2.slice(0, max - 1)}\u2026`;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
// src/cron-runner.ts
|
|
1421
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync3, readdirSync as readdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
1422
|
+
import { homedir as homedir6 } from "os";
|
|
1423
|
+
import { join as join6 } from "path";
|
|
1424
|
+
|
|
1425
|
+
// ../../packages/apes/dist/chunk-TDSCDH5P.js
|
|
1426
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
1427
|
+
import { homedir as homedir3 } from "os";
|
|
1428
|
+
import { dirname, normalize, resolve } from "path";
|
|
1429
|
+
import { execFileSync } from "child_process";
|
|
1430
|
+
import { execFileSync as execFileSync2 } from "child_process";
|
|
1431
|
+
var MAX_BYTES = 1024 * 1024;
|
|
1432
|
+
function jailPath(input) {
|
|
1433
|
+
if (typeof input !== "string" || input === "") {
|
|
1434
|
+
throw new Error("path must be a non-empty string");
|
|
1435
|
+
}
|
|
1436
|
+
const home = homedir3();
|
|
1437
|
+
const candidate = input.startsWith("~/") ? resolve(home, input.slice(2)) : input.startsWith("/") ? normalize(input) : resolve(home, input);
|
|
1438
|
+
if (candidate !== home && !candidate.startsWith(`${home}/`)) {
|
|
1439
|
+
throw new Error(`path "${input}" resolves outside the agent's home`);
|
|
1440
|
+
}
|
|
1441
|
+
return candidate;
|
|
1442
|
+
}
|
|
1443
|
+
var fileTools = [
|
|
1444
|
+
{
|
|
1445
|
+
name: "file.read",
|
|
1446
|
+
description: "Read a UTF-8 file from the agent's home directory ($HOME). Capped at 1MB. Path traversal blocked.",
|
|
1447
|
+
parameters: {
|
|
1448
|
+
type: "object",
|
|
1449
|
+
properties: {
|
|
1450
|
+
path: { type: "string", description: "Path relative to $HOME (or absolute under $HOME). `..` segments are rejected." }
|
|
1451
|
+
},
|
|
1452
|
+
required: ["path"]
|
|
1453
|
+
},
|
|
1454
|
+
execute: async (args) => {
|
|
1455
|
+
const a2 = args;
|
|
1456
|
+
const p = jailPath(a2.path);
|
|
1457
|
+
const content = readFileSync3(p, "utf8");
|
|
1458
|
+
if (Buffer.byteLength(content, "utf8") > MAX_BYTES) {
|
|
1459
|
+
return { path: p, truncated: true, content: content.slice(0, MAX_BYTES) };
|
|
1460
|
+
}
|
|
1461
|
+
return { path: p, truncated: false, content };
|
|
1462
|
+
}
|
|
1463
|
+
},
|
|
1464
|
+
{
|
|
1465
|
+
name: "file.write",
|
|
1466
|
+
description: "Write a UTF-8 file under the agent's home directory. Creates parent dirs as needed. 1MB max.",
|
|
1467
|
+
parameters: {
|
|
1468
|
+
type: "object",
|
|
1469
|
+
properties: {
|
|
1470
|
+
path: { type: "string", description: "Path relative to $HOME (or absolute under $HOME)." },
|
|
1471
|
+
content: { type: "string", description: "File body. Existing files are overwritten." }
|
|
1472
|
+
},
|
|
1473
|
+
required: ["path", "content"]
|
|
1474
|
+
},
|
|
1475
|
+
execute: async (args) => {
|
|
1476
|
+
const a2 = args;
|
|
1477
|
+
if (typeof a2.content !== "string") throw new Error("content must be a string");
|
|
1478
|
+
if (Buffer.byteLength(a2.content, "utf8") > MAX_BYTES) {
|
|
1479
|
+
throw new Error(`content exceeds ${MAX_BYTES} byte cap`);
|
|
1480
|
+
}
|
|
1481
|
+
const p = jailPath(a2.path);
|
|
1482
|
+
mkdirSync2(dirname(p), { recursive: true });
|
|
1483
|
+
writeFileSync2(p, a2.content, { encoding: "utf8" });
|
|
1484
|
+
return { path: p, bytes: Buffer.byteLength(a2.content, "utf8") };
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
];
|
|
1488
|
+
var MAX_BYTES2 = 1024 * 1024;
|
|
1489
|
+
var FORBIDDEN_HEADERS = /* @__PURE__ */ new Set([
|
|
1490
|
+
"host",
|
|
1491
|
+
"authorization",
|
|
1492
|
+
"cookie",
|
|
1493
|
+
"connection",
|
|
1494
|
+
"transfer-encoding",
|
|
1495
|
+
"upgrade",
|
|
1496
|
+
"proxy-authorization"
|
|
1497
|
+
]);
|
|
1498
|
+
function sanitizeHeaders(input) {
|
|
1499
|
+
if (!input || typeof input !== "object") return {};
|
|
1500
|
+
const out = {};
|
|
1501
|
+
for (const [k2, v2] of Object.entries(input)) {
|
|
1502
|
+
if (typeof v2 !== "string") continue;
|
|
1503
|
+
if (FORBIDDEN_HEADERS.has(k2.toLowerCase())) continue;
|
|
1504
|
+
out[k2] = v2;
|
|
1505
|
+
}
|
|
1506
|
+
return out;
|
|
1507
|
+
}
|
|
1508
|
+
async function readCappedBody(res) {
|
|
1509
|
+
const buf = new Uint8Array(MAX_BYTES2 + 1);
|
|
1510
|
+
let written = 0;
|
|
1511
|
+
const reader = res.body?.getReader();
|
|
1512
|
+
if (!reader) return await res.text();
|
|
1513
|
+
while (true) {
|
|
1514
|
+
const { value, done } = await reader.read();
|
|
1515
|
+
if (done) break;
|
|
1516
|
+
if (written + value.byteLength > MAX_BYTES2) {
|
|
1517
|
+
buf.set(value.subarray(0, MAX_BYTES2 - written), written);
|
|
1518
|
+
written = MAX_BYTES2;
|
|
1519
|
+
try {
|
|
1520
|
+
await reader.cancel();
|
|
1521
|
+
} catch {
|
|
1522
|
+
}
|
|
1523
|
+
break;
|
|
1524
|
+
}
|
|
1525
|
+
buf.set(value, written);
|
|
1526
|
+
written += value.byteLength;
|
|
1527
|
+
}
|
|
1528
|
+
return new TextDecoder().decode(buf.subarray(0, written));
|
|
1529
|
+
}
|
|
1530
|
+
var httpTools = [
|
|
1531
|
+
{
|
|
1532
|
+
name: "http.get",
|
|
1533
|
+
description: "GET an HTTPS URL and return the response body (capped at 1MB). Useful for reading public APIs, RSS feeds, web pages.",
|
|
1534
|
+
parameters: {
|
|
1535
|
+
type: "object",
|
|
1536
|
+
properties: {
|
|
1537
|
+
url: { type: "string", description: "Absolute HTTPS URL." },
|
|
1538
|
+
headers: { type: "object", description: "Optional headers (Host, Authorization, Cookie are stripped)." }
|
|
1539
|
+
},
|
|
1540
|
+
required: ["url"]
|
|
1541
|
+
},
|
|
1542
|
+
execute: async (args) => {
|
|
1543
|
+
const a2 = args;
|
|
1544
|
+
if (typeof a2.url !== "string" || !a2.url.startsWith("http")) {
|
|
1545
|
+
throw new Error("url must be an http(s) URL");
|
|
1546
|
+
}
|
|
1547
|
+
const res = await fetch(a2.url, { method: "GET", headers: sanitizeHeaders(a2.headers) });
|
|
1548
|
+
const body = await readCappedBody(res);
|
|
1549
|
+
return { status: res.status, headers: Object.fromEntries(res.headers), body };
|
|
1550
|
+
}
|
|
1551
|
+
},
|
|
1552
|
+
{
|
|
1553
|
+
name: "http.post",
|
|
1554
|
+
description: "POST JSON to an HTTPS URL and return the response body (capped at 1MB).",
|
|
1555
|
+
parameters: {
|
|
1556
|
+
type: "object",
|
|
1557
|
+
properties: {
|
|
1558
|
+
url: { type: "string", description: "Absolute HTTPS URL." },
|
|
1559
|
+
body: { description: "JSON-serialisable payload." },
|
|
1560
|
+
headers: { type: "object", description: "Optional headers (Host, Authorization, Cookie are stripped)." }
|
|
1561
|
+
},
|
|
1562
|
+
required: ["url", "body"]
|
|
1563
|
+
},
|
|
1564
|
+
execute: async (args) => {
|
|
1565
|
+
const a2 = args;
|
|
1566
|
+
if (typeof a2.url !== "string" || !a2.url.startsWith("http")) {
|
|
1567
|
+
throw new Error("url must be an http(s) URL");
|
|
1568
|
+
}
|
|
1569
|
+
const res = await fetch(a2.url, {
|
|
1570
|
+
method: "POST",
|
|
1571
|
+
headers: { "content-type": "application/json", ...sanitizeHeaders(a2.headers) },
|
|
1572
|
+
body: JSON.stringify(a2.body)
|
|
1573
|
+
});
|
|
1574
|
+
const body = await readCappedBody(res);
|
|
1575
|
+
return { status: res.status, headers: Object.fromEntries(res.headers), body };
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
];
|
|
1579
|
+
function o365(args) {
|
|
1580
|
+
try {
|
|
1581
|
+
return execFileSync("o365-cli", args, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
1582
|
+
} catch (err) {
|
|
1583
|
+
const e2 = err;
|
|
1584
|
+
if (e2.code === "ENOENT") {
|
|
1585
|
+
throw new Error("o365-cli is not installed on this agent host");
|
|
1586
|
+
}
|
|
1587
|
+
const stderr = typeof e2.stderr === "string" ? e2.stderr : e2.stderr?.toString("utf8");
|
|
1588
|
+
throw new Error(`o365-cli failed: ${stderr ?? e2.message ?? err}`);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
var mailTools = [
|
|
1592
|
+
{
|
|
1593
|
+
name: "mail.list",
|
|
1594
|
+
description: "List recent inbox messages via o365-cli. Optional `unread_only` and `limit`.",
|
|
1595
|
+
parameters: {
|
|
1596
|
+
type: "object",
|
|
1597
|
+
properties: {
|
|
1598
|
+
limit: { type: "integer", minimum: 1, maximum: 100, default: 20 },
|
|
1599
|
+
unread_only: { type: "boolean", default: false }
|
|
1600
|
+
},
|
|
1601
|
+
required: []
|
|
1602
|
+
},
|
|
1603
|
+
execute: async (args) => {
|
|
1604
|
+
const a2 = args ?? {};
|
|
1605
|
+
const argv2 = ["mail", "list", "--json", "--limit", String(a2.limit ?? 20)];
|
|
1606
|
+
if (a2.unread_only) argv2.push("--unread");
|
|
1607
|
+
const out = o365(argv2);
|
|
1608
|
+
try {
|
|
1609
|
+
return JSON.parse(out);
|
|
1610
|
+
} catch {
|
|
1611
|
+
return { raw: out };
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
},
|
|
1615
|
+
{
|
|
1616
|
+
name: "mail.search",
|
|
1617
|
+
description: "Search the inbox via o365-cli using a free-form query string.",
|
|
1618
|
+
parameters: {
|
|
1619
|
+
type: "object",
|
|
1620
|
+
properties: {
|
|
1621
|
+
q: { type: "string" },
|
|
1622
|
+
limit: { type: "integer", minimum: 1, maximum: 100, default: 20 }
|
|
1623
|
+
},
|
|
1624
|
+
required: ["q"]
|
|
1625
|
+
},
|
|
1626
|
+
execute: async (args) => {
|
|
1627
|
+
const a2 = args;
|
|
1628
|
+
if (typeof a2.q !== "string" || a2.q.length === 0) throw new Error("q is required");
|
|
1629
|
+
const argv2 = ["mail", "search", a2.q, "--json", "--limit", String(a2.limit ?? 20)];
|
|
1630
|
+
const out = o365(argv2);
|
|
1631
|
+
try {
|
|
1632
|
+
return JSON.parse(out);
|
|
1633
|
+
} catch {
|
|
1634
|
+
return { raw: out };
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
];
|
|
1639
|
+
function ape(args) {
|
|
1640
|
+
try {
|
|
1641
|
+
return execFileSync2("ape-tasks", args, { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
1642
|
+
} catch (err) {
|
|
1643
|
+
const e2 = err;
|
|
1644
|
+
const stderr = typeof e2.stderr === "string" ? e2.stderr : e2.stderr?.toString("utf8");
|
|
1645
|
+
throw new Error(`ape-tasks failed: ${stderr ?? e2.message ?? err}`);
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
var tasksTools = [
|
|
1649
|
+
{
|
|
1650
|
+
name: "tasks.list",
|
|
1651
|
+
description: "List the owner's open ape-tasks (the user's personal task list at tasks.openape.ai).",
|
|
1652
|
+
parameters: {
|
|
1653
|
+
type: "object",
|
|
1654
|
+
properties: {
|
|
1655
|
+
status: { type: "string", enum: ["open", "doing", "done", "archived"] },
|
|
1656
|
+
team_id: { type: "string" }
|
|
1657
|
+
},
|
|
1658
|
+
required: []
|
|
1659
|
+
},
|
|
1660
|
+
execute: async (args) => {
|
|
1661
|
+
const a2 = args ?? {};
|
|
1662
|
+
const argv2 = ["list", "--json"];
|
|
1663
|
+
if (a2.status) argv2.push("--status", a2.status);
|
|
1664
|
+
if (a2.team_id) argv2.push("--team", a2.team_id);
|
|
1665
|
+
const out = ape(argv2);
|
|
1666
|
+
try {
|
|
1667
|
+
return JSON.parse(out);
|
|
1668
|
+
} catch {
|
|
1669
|
+
return { raw: out };
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
},
|
|
1673
|
+
{
|
|
1674
|
+
name: "tasks.create",
|
|
1675
|
+
description: "Create a new ape-task on the owner's task list at tasks.openape.ai.",
|
|
1676
|
+
parameters: {
|
|
1677
|
+
type: "object",
|
|
1678
|
+
properties: {
|
|
1679
|
+
title: { type: "string" },
|
|
1680
|
+
notes: { type: "string" },
|
|
1681
|
+
priority: { type: "string", enum: ["low", "med", "high"] },
|
|
1682
|
+
due_at: { type: "string", description: "ISO date or +Nh/+Nd shorthand." }
|
|
1683
|
+
},
|
|
1684
|
+
required: ["title"]
|
|
1685
|
+
},
|
|
1686
|
+
execute: async (args) => {
|
|
1687
|
+
const a2 = args;
|
|
1688
|
+
const argv2 = ["new", "--title", a2.title, "--json"];
|
|
1689
|
+
if (a2.notes) argv2.push("--notes", a2.notes);
|
|
1690
|
+
if (a2.priority) argv2.push("--priority", a2.priority);
|
|
1691
|
+
if (a2.due_at) argv2.push("--due", a2.due_at);
|
|
1692
|
+
const out = ape(argv2);
|
|
1693
|
+
try {
|
|
1694
|
+
return JSON.parse(out);
|
|
1695
|
+
} catch {
|
|
1696
|
+
return { raw: out };
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
];
|
|
1701
|
+
var timeTools = [
|
|
1702
|
+
{
|
|
1703
|
+
name: "time.now",
|
|
1704
|
+
description: "Returns the current UTC date and time as ISO 8601 plus epoch seconds. No inputs.",
|
|
1705
|
+
parameters: { type: "object", properties: {}, required: [] },
|
|
1706
|
+
execute: async () => {
|
|
1707
|
+
const now = /* @__PURE__ */ new Date();
|
|
1708
|
+
return {
|
|
1709
|
+
iso: now.toISOString(),
|
|
1710
|
+
epoch_seconds: Math.floor(now.getTime() / 1e3),
|
|
1711
|
+
timezone_offset_minutes: -now.getTimezoneOffset()
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
];
|
|
1716
|
+
var ALL_TOOLS = [
|
|
1717
|
+
...timeTools,
|
|
1718
|
+
...httpTools,
|
|
1719
|
+
...fileTools,
|
|
1720
|
+
...tasksTools,
|
|
1721
|
+
...mailTools
|
|
1722
|
+
];
|
|
1723
|
+
var TOOLS = Object.fromEntries(
|
|
1724
|
+
ALL_TOOLS.map((t2) => [t2.name, t2])
|
|
1725
|
+
);
|
|
1726
|
+
function taskTools(names) {
|
|
1727
|
+
const out = [];
|
|
1728
|
+
const missing = [];
|
|
1729
|
+
for (const name of names) {
|
|
1730
|
+
const tool = TOOLS[name];
|
|
1731
|
+
if (!tool) missing.push(name);
|
|
1732
|
+
else out.push(tool);
|
|
1733
|
+
}
|
|
1734
|
+
if (missing.length > 0) {
|
|
1735
|
+
throw new Error(`unknown tool(s): ${missing.join(", ")}`);
|
|
1736
|
+
}
|
|
1737
|
+
return out;
|
|
1738
|
+
}
|
|
1739
|
+
function asOpenAiTools(tools) {
|
|
1740
|
+
return tools.map((t2) => ({
|
|
1741
|
+
type: "function",
|
|
1742
|
+
function: { name: wireToolName(t2.name), description: t2.description, parameters: t2.parameters }
|
|
1743
|
+
}));
|
|
1744
|
+
}
|
|
1745
|
+
function wireToolName(local) {
|
|
1746
|
+
return local.replace(/\./g, "_");
|
|
1747
|
+
}
|
|
1748
|
+
function localToolName(wire) {
|
|
1749
|
+
for (const t2 of Object.values(TOOLS)) {
|
|
1750
|
+
if (wireToolName(t2.name) === wire) return t2.name;
|
|
1751
|
+
}
|
|
1752
|
+
return wire;
|
|
1753
|
+
}
|
|
1754
|
+
function previewJson(value, max = 500) {
|
|
1755
|
+
let s2;
|
|
1756
|
+
try {
|
|
1757
|
+
s2 = JSON.stringify(value);
|
|
1758
|
+
} catch {
|
|
1759
|
+
s2 = String(value);
|
|
1760
|
+
}
|
|
1761
|
+
return s2.length > max ? `${s2.slice(0, max)}\u2026` : s2;
|
|
1762
|
+
}
|
|
1763
|
+
async function runLoop(opts) {
|
|
1764
|
+
const fetchFn = opts.fetchImpl ?? fetch;
|
|
1765
|
+
const trace = [];
|
|
1766
|
+
const messages = [
|
|
1767
|
+
{ role: "system", content: opts.systemPrompt },
|
|
1768
|
+
...opts.history ?? [],
|
|
1769
|
+
{ role: "user", content: opts.userMessage }
|
|
1770
|
+
];
|
|
1771
|
+
const tools = asOpenAiTools(opts.tools);
|
|
1772
|
+
for (let step = 1; step <= opts.maxSteps; step++) {
|
|
1773
|
+
const res = await fetchFn(`${opts.config.apiBase}/chat/completions`, {
|
|
1774
|
+
method: "POST",
|
|
1775
|
+
headers: {
|
|
1776
|
+
"authorization": `Bearer ${opts.config.apiKey}`,
|
|
1777
|
+
"content-type": "application/json"
|
|
1778
|
+
},
|
|
1779
|
+
body: JSON.stringify({
|
|
1780
|
+
model: opts.config.model,
|
|
1781
|
+
messages,
|
|
1782
|
+
...tools.length > 0 ? { tools, tool_choice: "auto" } : {}
|
|
1783
|
+
})
|
|
1784
|
+
});
|
|
1785
|
+
if (!res.ok) {
|
|
1786
|
+
const text = await res.text().catch(() => "");
|
|
1787
|
+
throw new Error(`LiteLLM ${res.status}: ${text.slice(0, 500)}`);
|
|
1788
|
+
}
|
|
1789
|
+
const data = await res.json();
|
|
1790
|
+
const choice = data.choices?.[0];
|
|
1791
|
+
if (!choice) throw new Error("LiteLLM response had no choices");
|
|
1792
|
+
const assistant = choice.message;
|
|
1793
|
+
messages.push(assistant);
|
|
1794
|
+
if (assistant.content) opts.handlers?.onTextDelta?.(assistant.content);
|
|
1795
|
+
trace.push({
|
|
1796
|
+
step,
|
|
1797
|
+
type: "assistant",
|
|
1798
|
+
preview: previewJson({ content: assistant.content, tool_calls: assistant.tool_calls?.length ?? 0 })
|
|
1799
|
+
});
|
|
1800
|
+
if (!assistant.tool_calls || assistant.tool_calls.length === 0) {
|
|
1801
|
+
const result2 = {
|
|
1802
|
+
status: "ok",
|
|
1803
|
+
finalMessage: assistant.content,
|
|
1804
|
+
stepCount: step,
|
|
1805
|
+
trace
|
|
1806
|
+
};
|
|
1807
|
+
opts.handlers?.onDone?.(result2);
|
|
1808
|
+
return result2;
|
|
1809
|
+
}
|
|
1810
|
+
for (const call of assistant.tool_calls) {
|
|
1811
|
+
const wireName = call.function.name;
|
|
1812
|
+
const localName = localToolName(wireName);
|
|
1813
|
+
const tool = opts.tools.find((t2) => t2.name === localName);
|
|
1814
|
+
let parsedArgs;
|
|
1815
|
+
try {
|
|
1816
|
+
parsedArgs = JSON.parse(call.function.arguments);
|
|
1817
|
+
} catch {
|
|
1818
|
+
parsedArgs = {};
|
|
1819
|
+
}
|
|
1820
|
+
opts.handlers?.onToolCall?.({ name: localName, args: parsedArgs });
|
|
1821
|
+
trace.push({ step, type: "tool_call", tool: localName, preview: previewJson(parsedArgs) });
|
|
1822
|
+
let result2;
|
|
1823
|
+
let isError = false;
|
|
1824
|
+
if (!tool) {
|
|
1825
|
+
result2 = `unknown tool: ${localName}`;
|
|
1826
|
+
isError = true;
|
|
1827
|
+
} else {
|
|
1828
|
+
try {
|
|
1829
|
+
result2 = await tool.execute(parsedArgs);
|
|
1830
|
+
} catch (err) {
|
|
1831
|
+
result2 = err?.message ?? String(err);
|
|
1832
|
+
isError = true;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
if (isError) {
|
|
1836
|
+
opts.handlers?.onToolError?.({ name: localName, error: String(result2) });
|
|
1837
|
+
trace.push({ step, type: "tool_error", tool: localName, preview: previewJson(result2) });
|
|
1838
|
+
} else {
|
|
1839
|
+
opts.handlers?.onToolResult?.({ name: localName, result: result2 });
|
|
1840
|
+
trace.push({ step, type: "tool_result", tool: localName, preview: previewJson(result2) });
|
|
1841
|
+
}
|
|
1842
|
+
messages.push({
|
|
1843
|
+
role: "tool",
|
|
1844
|
+
tool_call_id: call.id,
|
|
1845
|
+
name: wireToolName(localName),
|
|
1846
|
+
content: typeof result2 === "string" ? result2 : JSON.stringify(result2)
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
const result = {
|
|
1851
|
+
status: "error",
|
|
1852
|
+
finalMessage: `max_steps (${opts.maxSteps}) reached without completion`,
|
|
1853
|
+
stepCount: opts.maxSteps,
|
|
1854
|
+
trace
|
|
1855
|
+
};
|
|
1856
|
+
opts.handlers?.onDone?.(result);
|
|
1857
|
+
return result;
|
|
1858
|
+
}
|
|
1859
|
+
var RPC_SESSION_TTL_MS = 60 * 60 * 1e3;
|
|
1860
|
+
|
|
1861
|
+
// ../../packages/apes/dist/chunk-DYSFQ26B.js
|
|
1862
|
+
init_chunk_OBF7IMQ2();
|
|
1863
|
+
import { createHash } from "crypto";
|
|
1864
|
+
import { existsSync as existsSync3, readdirSync as readdirSync2, readFileSync as readFileSync4 } from "fs";
|
|
1865
|
+
import { homedir as homedir5 } from "os";
|
|
1866
|
+
import { basename, join as join4 } from "path";
|
|
1867
|
+
|
|
1868
|
+
// ../../packages/core/dist/index.js
|
|
1869
|
+
import * as jose from "jose";
|
|
1870
|
+
|
|
1871
|
+
// ../../packages/grants/dist/index.js
|
|
1872
|
+
function normalizeSelector(selector) {
|
|
1873
|
+
if (!selector)
|
|
1874
|
+
return void 0;
|
|
1875
|
+
const entries = Object.entries(selector).filter(([, value]) => value !== void 0 && value !== "").sort(([a2], [b2]) => a2.localeCompare(b2));
|
|
1876
|
+
if (entries.length === 0)
|
|
1877
|
+
return void 0;
|
|
1878
|
+
return Object.fromEntries(entries);
|
|
1879
|
+
}
|
|
1880
|
+
function selectorString(selector) {
|
|
1881
|
+
const normalized = normalizeSelector(selector);
|
|
1882
|
+
if (!normalized)
|
|
1883
|
+
return "*";
|
|
1884
|
+
return Object.entries(normalized).map(([key, value]) => `${key}=${value}`).join(",");
|
|
1885
|
+
}
|
|
1886
|
+
function canonicalizeCliPermission(detail) {
|
|
1887
|
+
const chain = detail.resource_chain.map((resource) => `${resource.resource}[${selectorString(resource.selector)}]`).join(".");
|
|
1888
|
+
return `${detail.cli_id}.${chain}#${detail.action}`;
|
|
1889
|
+
}
|
|
1890
|
+
async function computeArgvHash(argv2) {
|
|
1891
|
+
const encoder = new TextEncoder();
|
|
1892
|
+
const data = encoder.encode(JSON.stringify(argv2));
|
|
1893
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
1894
|
+
const hashArray = new Uint8Array(hashBuffer);
|
|
1895
|
+
const digest2 = Array.from(hashArray).map((b2) => b2.toString(16).padStart(2, "0")).join("");
|
|
1896
|
+
return `SHA-256:${digest2}`;
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
// ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/core.mjs
|
|
1900
|
+
var LogLevels = {
|
|
1901
|
+
silent: Number.NEGATIVE_INFINITY,
|
|
1902
|
+
fatal: 0,
|
|
1903
|
+
error: 0,
|
|
1904
|
+
warn: 1,
|
|
1905
|
+
log: 2,
|
|
1906
|
+
info: 3,
|
|
1907
|
+
success: 3,
|
|
1908
|
+
fail: 3,
|
|
1909
|
+
ready: 3,
|
|
1910
|
+
start: 3,
|
|
1911
|
+
box: 3,
|
|
1912
|
+
debug: 4,
|
|
1913
|
+
trace: 5,
|
|
1914
|
+
verbose: Number.POSITIVE_INFINITY
|
|
1915
|
+
};
|
|
1916
|
+
var LogTypes = {
|
|
1917
|
+
// Silent
|
|
1918
|
+
silent: {
|
|
1919
|
+
level: -1
|
|
1920
|
+
},
|
|
1921
|
+
// Level 0
|
|
1922
|
+
fatal: {
|
|
1923
|
+
level: LogLevels.fatal
|
|
1924
|
+
},
|
|
1925
|
+
error: {
|
|
1926
|
+
level: LogLevels.error
|
|
1927
|
+
},
|
|
1928
|
+
// Level 1
|
|
1929
|
+
warn: {
|
|
1930
|
+
level: LogLevels.warn
|
|
1931
|
+
},
|
|
1932
|
+
// Level 2
|
|
1933
|
+
log: {
|
|
1934
|
+
level: LogLevels.log
|
|
1935
|
+
},
|
|
1936
|
+
// Level 3
|
|
1937
|
+
info: {
|
|
1938
|
+
level: LogLevels.info
|
|
1939
|
+
},
|
|
1940
|
+
success: {
|
|
1941
|
+
level: LogLevels.success
|
|
1942
|
+
},
|
|
1943
|
+
fail: {
|
|
1944
|
+
level: LogLevels.fail
|
|
1945
|
+
},
|
|
1946
|
+
ready: {
|
|
1947
|
+
level: LogLevels.info
|
|
1948
|
+
},
|
|
1949
|
+
start: {
|
|
1950
|
+
level: LogLevels.info
|
|
1951
|
+
},
|
|
1952
|
+
box: {
|
|
1953
|
+
level: LogLevels.info
|
|
1954
|
+
},
|
|
1955
|
+
// Level 4
|
|
1956
|
+
debug: {
|
|
1957
|
+
level: LogLevels.debug
|
|
1958
|
+
},
|
|
1959
|
+
// Level 5
|
|
1960
|
+
trace: {
|
|
1961
|
+
level: LogLevels.trace
|
|
1962
|
+
},
|
|
1963
|
+
// Verbose
|
|
1964
|
+
verbose: {
|
|
1965
|
+
level: LogLevels.verbose
|
|
1966
|
+
}
|
|
1967
|
+
};
|
|
1968
|
+
function isPlainObject$1(value) {
|
|
1969
|
+
if (value === null || typeof value !== "object") {
|
|
1970
|
+
return false;
|
|
1971
|
+
}
|
|
1972
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1973
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
1974
|
+
return false;
|
|
1975
|
+
}
|
|
1976
|
+
if (Symbol.iterator in value) {
|
|
1977
|
+
return false;
|
|
1978
|
+
}
|
|
1979
|
+
if (Symbol.toStringTag in value) {
|
|
1980
|
+
return Object.prototype.toString.call(value) === "[object Module]";
|
|
1981
|
+
}
|
|
1982
|
+
return true;
|
|
1983
|
+
}
|
|
1984
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
1985
|
+
if (!isPlainObject$1(defaults)) {
|
|
1986
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
1987
|
+
}
|
|
1988
|
+
const object = Object.assign({}, defaults);
|
|
1989
|
+
for (const key in baseObject) {
|
|
1990
|
+
if (key === "__proto__" || key === "constructor") {
|
|
1991
|
+
continue;
|
|
1992
|
+
}
|
|
1993
|
+
const value = baseObject[key];
|
|
1994
|
+
if (value === null || value === void 0) {
|
|
1995
|
+
continue;
|
|
1996
|
+
}
|
|
1997
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
1998
|
+
continue;
|
|
1999
|
+
}
|
|
2000
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
2001
|
+
object[key] = [...value, ...object[key]];
|
|
2002
|
+
} else if (isPlainObject$1(value) && isPlainObject$1(object[key])) {
|
|
2003
|
+
object[key] = _defu(
|
|
2004
|
+
value,
|
|
2005
|
+
object[key],
|
|
2006
|
+
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
2007
|
+
merger
|
|
2008
|
+
);
|
|
2009
|
+
} else {
|
|
2010
|
+
object[key] = value;
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
return object;
|
|
2014
|
+
}
|
|
2015
|
+
function createDefu(merger) {
|
|
2016
|
+
return (...arguments_) => (
|
|
2017
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
2018
|
+
arguments_.reduce((p, c3) => _defu(p, c3, "", merger), {})
|
|
2019
|
+
);
|
|
2020
|
+
}
|
|
2021
|
+
var defu = createDefu();
|
|
2022
|
+
function isPlainObject(obj) {
|
|
2023
|
+
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
2024
|
+
}
|
|
2025
|
+
function isLogObj(arg) {
|
|
2026
|
+
if (!isPlainObject(arg)) {
|
|
2027
|
+
return false;
|
|
2028
|
+
}
|
|
2029
|
+
if (!arg.message && !arg.args) {
|
|
2030
|
+
return false;
|
|
2031
|
+
}
|
|
2032
|
+
if (arg.stack) {
|
|
2033
|
+
return false;
|
|
2034
|
+
}
|
|
2035
|
+
return true;
|
|
2036
|
+
}
|
|
2037
|
+
var paused = false;
|
|
2038
|
+
var queue = [];
|
|
2039
|
+
var Consola = class _Consola {
|
|
2040
|
+
options;
|
|
2041
|
+
_lastLog;
|
|
2042
|
+
_mockFn;
|
|
2043
|
+
/**
|
|
2044
|
+
* Creates an instance of Consola with specified options or defaults.
|
|
2045
|
+
*
|
|
2046
|
+
* @param {Partial<ConsolaOptions>} [options={}] - Configuration options for the Consola instance.
|
|
2047
|
+
*/
|
|
2048
|
+
constructor(options = {}) {
|
|
2049
|
+
const types = options.types || LogTypes;
|
|
2050
|
+
this.options = defu(
|
|
2051
|
+
{
|
|
2052
|
+
...options,
|
|
2053
|
+
defaults: { ...options.defaults },
|
|
2054
|
+
level: _normalizeLogLevel(options.level, types),
|
|
2055
|
+
reporters: [...options.reporters || []]
|
|
2056
|
+
},
|
|
2057
|
+
{
|
|
2058
|
+
types: LogTypes,
|
|
2059
|
+
throttle: 1e3,
|
|
2060
|
+
throttleMin: 5,
|
|
2061
|
+
formatOptions: {
|
|
2062
|
+
date: true,
|
|
2063
|
+
colors: false,
|
|
2064
|
+
compact: true
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
);
|
|
2068
|
+
for (const type in types) {
|
|
2069
|
+
const defaults = {
|
|
2070
|
+
type,
|
|
2071
|
+
...this.options.defaults,
|
|
2072
|
+
...types[type]
|
|
2073
|
+
};
|
|
2074
|
+
this[type] = this._wrapLogFn(defaults);
|
|
2075
|
+
this[type].raw = this._wrapLogFn(
|
|
2076
|
+
defaults,
|
|
2077
|
+
true
|
|
2078
|
+
);
|
|
2079
|
+
}
|
|
2080
|
+
if (this.options.mockFn) {
|
|
2081
|
+
this.mockTypes();
|
|
2082
|
+
}
|
|
2083
|
+
this._lastLog = {};
|
|
2084
|
+
}
|
|
2085
|
+
/**
|
|
2086
|
+
* Gets the current log level of the Consola instance.
|
|
2087
|
+
*
|
|
2088
|
+
* @returns {number} The current log level.
|
|
2089
|
+
*/
|
|
2090
|
+
get level() {
|
|
2091
|
+
return this.options.level;
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* Sets the minimum log level that will be output by the instance.
|
|
2095
|
+
*
|
|
2096
|
+
* @param {number} level - The new log level to set.
|
|
2097
|
+
*/
|
|
2098
|
+
set level(level) {
|
|
2099
|
+
this.options.level = _normalizeLogLevel(
|
|
2100
|
+
level,
|
|
2101
|
+
this.options.types,
|
|
2102
|
+
this.options.level
|
|
2103
|
+
);
|
|
2104
|
+
}
|
|
2105
|
+
/**
|
|
2106
|
+
* Displays a prompt to the user and returns the response.
|
|
2107
|
+
* Throw an error if `prompt` is not supported by the current configuration.
|
|
2108
|
+
*
|
|
2109
|
+
* @template T
|
|
2110
|
+
* @param {string} message - The message to display in the prompt.
|
|
2111
|
+
* @param {T} [opts] - Optional options for the prompt. See {@link PromptOptions}.
|
|
2112
|
+
* @returns {promise<T>} A promise that infer with the prompt options. See {@link PromptOptions}.
|
|
2113
|
+
*/
|
|
2114
|
+
prompt(message, opts) {
|
|
2115
|
+
if (!this.options.prompt) {
|
|
2116
|
+
throw new Error("prompt is not supported!");
|
|
2117
|
+
}
|
|
2118
|
+
return this.options.prompt(message, opts);
|
|
2119
|
+
}
|
|
2120
|
+
/**
|
|
2121
|
+
* Creates a new instance of Consola, inheriting options from the current instance, with possible overrides.
|
|
2122
|
+
*
|
|
2123
|
+
* @param {Partial<ConsolaOptions>} options - Optional overrides for the new instance. See {@link ConsolaOptions}.
|
|
2124
|
+
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
|
2125
|
+
*/
|
|
2126
|
+
create(options) {
|
|
2127
|
+
const instance = new _Consola({
|
|
2128
|
+
...this.options,
|
|
2129
|
+
...options
|
|
2130
|
+
});
|
|
2131
|
+
if (this._mockFn) {
|
|
2132
|
+
instance.mockTypes(this._mockFn);
|
|
2133
|
+
}
|
|
2134
|
+
return instance;
|
|
2135
|
+
}
|
|
2136
|
+
/**
|
|
2137
|
+
* Creates a new Consola instance with the specified default log object properties.
|
|
2138
|
+
*
|
|
2139
|
+
* @param {InputLogObject} defaults - Default properties to include in any log from the new instance. See {@link InputLogObject}.
|
|
2140
|
+
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
|
2141
|
+
*/
|
|
2142
|
+
withDefaults(defaults) {
|
|
2143
|
+
return this.create({
|
|
2144
|
+
...this.options,
|
|
2145
|
+
defaults: {
|
|
2146
|
+
...this.options.defaults,
|
|
2147
|
+
...defaults
|
|
2148
|
+
}
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
2151
|
+
/**
|
|
2152
|
+
* Creates a new Consola instance with a specified tag, which will be included in every log.
|
|
2153
|
+
*
|
|
2154
|
+
* @param {string} tag - The tag to include in each log of the new instance.
|
|
2155
|
+
* @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
|
|
2156
|
+
*/
|
|
2157
|
+
withTag(tag) {
|
|
2158
|
+
return this.withDefaults({
|
|
2159
|
+
tag: this.options.defaults.tag ? this.options.defaults.tag + ":" + tag : tag
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
/**
|
|
2163
|
+
* Adds a custom reporter to the Consola instance.
|
|
2164
|
+
* Reporters will be called for each log message, depending on their implementation and log level.
|
|
2165
|
+
*
|
|
2166
|
+
* @param {ConsolaReporter} reporter - The reporter to add. See {@link ConsolaReporter}.
|
|
2167
|
+
* @returns {Consola} The current Consola instance.
|
|
2168
|
+
*/
|
|
2169
|
+
addReporter(reporter) {
|
|
2170
|
+
this.options.reporters.push(reporter);
|
|
2171
|
+
return this;
|
|
2172
|
+
}
|
|
2173
|
+
/**
|
|
2174
|
+
* Removes a custom reporter from the Consola instance.
|
|
2175
|
+
* If no reporter is specified, all reporters will be removed.
|
|
2176
|
+
*
|
|
2177
|
+
* @param {ConsolaReporter} reporter - The reporter to remove. See {@link ConsolaReporter}.
|
|
2178
|
+
* @returns {Consola} The current Consola instance.
|
|
2179
|
+
*/
|
|
2180
|
+
removeReporter(reporter) {
|
|
2181
|
+
if (reporter) {
|
|
2182
|
+
const i2 = this.options.reporters.indexOf(reporter);
|
|
2183
|
+
if (i2 !== -1) {
|
|
2184
|
+
return this.options.reporters.splice(i2, 1);
|
|
2185
|
+
}
|
|
2186
|
+
} else {
|
|
2187
|
+
this.options.reporters.splice(0);
|
|
2188
|
+
}
|
|
2189
|
+
return this;
|
|
2190
|
+
}
|
|
2191
|
+
/**
|
|
2192
|
+
* Replaces all reporters of the Consola instance with the specified array of reporters.
|
|
2193
|
+
*
|
|
2194
|
+
* @param {ConsolaReporter[]} reporters - The new reporters to set. See {@link ConsolaReporter}.
|
|
2195
|
+
* @returns {Consola} The current Consola instance.
|
|
2196
|
+
*/
|
|
2197
|
+
setReporters(reporters) {
|
|
2198
|
+
this.options.reporters = Array.isArray(reporters) ? reporters : [reporters];
|
|
2199
|
+
return this;
|
|
2200
|
+
}
|
|
2201
|
+
wrapAll() {
|
|
2202
|
+
this.wrapConsole();
|
|
2203
|
+
this.wrapStd();
|
|
2204
|
+
}
|
|
2205
|
+
restoreAll() {
|
|
2206
|
+
this.restoreConsole();
|
|
2207
|
+
this.restoreStd();
|
|
2208
|
+
}
|
|
2209
|
+
/**
|
|
2210
|
+
* Overrides console methods with Consola logging methods for consistent logging.
|
|
2211
|
+
*/
|
|
2212
|
+
wrapConsole() {
|
|
2213
|
+
for (const type in this.options.types) {
|
|
2214
|
+
if (!console["__" + type]) {
|
|
2215
|
+
console["__" + type] = console[type];
|
|
2216
|
+
}
|
|
2217
|
+
console[type] = this[type].raw;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
/**
|
|
2221
|
+
* Restores the original console methods, removing Consola overrides.
|
|
2222
|
+
*/
|
|
2223
|
+
restoreConsole() {
|
|
2224
|
+
for (const type in this.options.types) {
|
|
2225
|
+
if (console["__" + type]) {
|
|
2226
|
+
console[type] = console["__" + type];
|
|
2227
|
+
delete console["__" + type];
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
/**
|
|
2232
|
+
* Overrides standard output and error streams to redirect them through Consola.
|
|
2233
|
+
*/
|
|
2234
|
+
wrapStd() {
|
|
2235
|
+
this._wrapStream(this.options.stdout, "log");
|
|
2236
|
+
this._wrapStream(this.options.stderr, "log");
|
|
2237
|
+
}
|
|
2238
|
+
_wrapStream(stream, type) {
|
|
2239
|
+
if (!stream) {
|
|
2240
|
+
return;
|
|
2241
|
+
}
|
|
2242
|
+
if (!stream.__write) {
|
|
2243
|
+
stream.__write = stream.write;
|
|
2244
|
+
}
|
|
2245
|
+
stream.write = (data) => {
|
|
2246
|
+
this[type].raw(String(data).trim());
|
|
2247
|
+
};
|
|
2248
|
+
}
|
|
2249
|
+
/**
|
|
2250
|
+
* Restores the original standard output and error streams, removing the Consola redirection.
|
|
2251
|
+
*/
|
|
2252
|
+
restoreStd() {
|
|
2253
|
+
this._restoreStream(this.options.stdout);
|
|
2254
|
+
this._restoreStream(this.options.stderr);
|
|
2255
|
+
}
|
|
2256
|
+
_restoreStream(stream) {
|
|
2257
|
+
if (!stream) {
|
|
2258
|
+
return;
|
|
2259
|
+
}
|
|
2260
|
+
if (stream.__write) {
|
|
2261
|
+
stream.write = stream.__write;
|
|
2262
|
+
delete stream.__write;
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
/**
|
|
2266
|
+
* Pauses logging, queues incoming logs until resumed.
|
|
2267
|
+
*/
|
|
2268
|
+
pauseLogs() {
|
|
2269
|
+
paused = true;
|
|
2270
|
+
}
|
|
2271
|
+
/**
|
|
2272
|
+
* Resumes logging, processing any queued logs.
|
|
2273
|
+
*/
|
|
2274
|
+
resumeLogs() {
|
|
2275
|
+
paused = false;
|
|
2276
|
+
const _queue = queue.splice(0);
|
|
2277
|
+
for (const item of _queue) {
|
|
2278
|
+
item[0]._logFn(item[1], item[2]);
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
/**
|
|
2282
|
+
* Replaces logging methods with mocks if a mock function is provided.
|
|
2283
|
+
*
|
|
2284
|
+
* @param {ConsolaOptions["mockFn"]} mockFn - The function to use for mocking logging methods. See {@link ConsolaOptions["mockFn"]}.
|
|
2285
|
+
*/
|
|
2286
|
+
mockTypes(mockFn) {
|
|
2287
|
+
const _mockFn = mockFn || this.options.mockFn;
|
|
2288
|
+
this._mockFn = _mockFn;
|
|
2289
|
+
if (typeof _mockFn !== "function") {
|
|
2290
|
+
return;
|
|
2291
|
+
}
|
|
2292
|
+
for (const type in this.options.types) {
|
|
2293
|
+
this[type] = _mockFn(type, this.options.types[type]) || this[type];
|
|
2294
|
+
this[type].raw = this[type];
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
_wrapLogFn(defaults, isRaw) {
|
|
2298
|
+
return (...args) => {
|
|
2299
|
+
if (paused) {
|
|
2300
|
+
queue.push([this, defaults, args, isRaw]);
|
|
2301
|
+
return;
|
|
2302
|
+
}
|
|
2303
|
+
return this._logFn(defaults, args, isRaw);
|
|
2304
|
+
};
|
|
2305
|
+
}
|
|
2306
|
+
_logFn(defaults, args, isRaw) {
|
|
2307
|
+
if ((defaults.level || 0) > this.level) {
|
|
2308
|
+
return false;
|
|
2309
|
+
}
|
|
2310
|
+
const logObj = {
|
|
2311
|
+
date: /* @__PURE__ */ new Date(),
|
|
2312
|
+
args: [],
|
|
2313
|
+
...defaults,
|
|
2314
|
+
level: _normalizeLogLevel(defaults.level, this.options.types)
|
|
2315
|
+
};
|
|
2316
|
+
if (!isRaw && args.length === 1 && isLogObj(args[0])) {
|
|
2317
|
+
Object.assign(logObj, args[0]);
|
|
2318
|
+
} else {
|
|
2319
|
+
logObj.args = [...args];
|
|
2320
|
+
}
|
|
2321
|
+
if (logObj.message) {
|
|
2322
|
+
logObj.args.unshift(logObj.message);
|
|
2323
|
+
delete logObj.message;
|
|
2324
|
+
}
|
|
2325
|
+
if (logObj.additional) {
|
|
2326
|
+
if (!Array.isArray(logObj.additional)) {
|
|
2327
|
+
logObj.additional = logObj.additional.split("\n");
|
|
2328
|
+
}
|
|
2329
|
+
logObj.args.push("\n" + logObj.additional.join("\n"));
|
|
2330
|
+
delete logObj.additional;
|
|
2331
|
+
}
|
|
2332
|
+
logObj.type = typeof logObj.type === "string" ? logObj.type.toLowerCase() : "log";
|
|
2333
|
+
logObj.tag = typeof logObj.tag === "string" ? logObj.tag : "";
|
|
2334
|
+
const resolveLog = (newLog = false) => {
|
|
2335
|
+
const repeated = (this._lastLog.count || 0) - this.options.throttleMin;
|
|
2336
|
+
if (this._lastLog.object && repeated > 0) {
|
|
2337
|
+
const args2 = [...this._lastLog.object.args];
|
|
2338
|
+
if (repeated > 1) {
|
|
2339
|
+
args2.push(`(repeated ${repeated} times)`);
|
|
2340
|
+
}
|
|
2341
|
+
this._log({ ...this._lastLog.object, args: args2 });
|
|
2342
|
+
this._lastLog.count = 1;
|
|
2343
|
+
}
|
|
2344
|
+
if (newLog) {
|
|
2345
|
+
this._lastLog.object = logObj;
|
|
2346
|
+
this._log(logObj);
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
clearTimeout(this._lastLog.timeout);
|
|
2350
|
+
const diffTime = this._lastLog.time && logObj.date ? logObj.date.getTime() - this._lastLog.time.getTime() : 0;
|
|
2351
|
+
this._lastLog.time = logObj.date;
|
|
2352
|
+
if (diffTime < this.options.throttle) {
|
|
2353
|
+
try {
|
|
2354
|
+
const serializedLog = JSON.stringify([
|
|
2355
|
+
logObj.type,
|
|
2356
|
+
logObj.tag,
|
|
2357
|
+
logObj.args
|
|
2358
|
+
]);
|
|
2359
|
+
const isSameLog = this._lastLog.serialized === serializedLog;
|
|
2360
|
+
this._lastLog.serialized = serializedLog;
|
|
2361
|
+
if (isSameLog) {
|
|
2362
|
+
this._lastLog.count = (this._lastLog.count || 0) + 1;
|
|
2363
|
+
if (this._lastLog.count > this.options.throttleMin) {
|
|
2364
|
+
this._lastLog.timeout = setTimeout(
|
|
2365
|
+
resolveLog,
|
|
2366
|
+
this.options.throttle
|
|
2367
|
+
);
|
|
2368
|
+
return;
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
} catch {
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
resolveLog(true);
|
|
2375
|
+
}
|
|
2376
|
+
_log(logObj) {
|
|
2377
|
+
for (const reporter of this.options.reporters) {
|
|
2378
|
+
reporter.log(logObj, {
|
|
2379
|
+
options: this.options
|
|
2380
|
+
});
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
};
|
|
2384
|
+
function _normalizeLogLevel(input, types = {}, defaultLevel = 3) {
|
|
2385
|
+
if (input === void 0) {
|
|
2386
|
+
return defaultLevel;
|
|
2387
|
+
}
|
|
2388
|
+
if (typeof input === "number") {
|
|
2389
|
+
return input;
|
|
2390
|
+
}
|
|
2391
|
+
if (types[input] && types[input].level !== void 0) {
|
|
2392
|
+
return types[input].level;
|
|
2393
|
+
}
|
|
2394
|
+
return defaultLevel;
|
|
2395
|
+
}
|
|
2396
|
+
Consola.prototype.add = Consola.prototype.addReporter;
|
|
2397
|
+
Consola.prototype.remove = Consola.prototype.removeReporter;
|
|
2398
|
+
Consola.prototype.clear = Consola.prototype.removeReporter;
|
|
2399
|
+
Consola.prototype.withScope = Consola.prototype.withTag;
|
|
2400
|
+
Consola.prototype.mock = Consola.prototype.mockTypes;
|
|
2401
|
+
Consola.prototype.pause = Consola.prototype.pauseLogs;
|
|
2402
|
+
Consola.prototype.resume = Consola.prototype.resumeLogs;
|
|
2403
|
+
function createConsola(options = {}) {
|
|
2404
|
+
return new Consola(options);
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
// ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs
|
|
2408
|
+
import { formatWithOptions } from "util";
|
|
2409
|
+
import { sep } from "path";
|
|
2410
|
+
function parseStack(stack, message) {
|
|
2411
|
+
const cwd = process.cwd() + sep;
|
|
2412
|
+
const lines = stack.split("\n").splice(message.split("\n").length).map((l2) => l2.trim().replace("file://", "").replace(cwd, ""));
|
|
2413
|
+
return lines;
|
|
2414
|
+
}
|
|
2415
|
+
function writeStream(data, stream) {
|
|
2416
|
+
const write = stream.__write || stream.write;
|
|
2417
|
+
return write.call(stream, data);
|
|
2418
|
+
}
|
|
2419
|
+
var bracket = (x2) => x2 ? `[${x2}]` : "";
|
|
2420
|
+
var BasicReporter = class {
|
|
2421
|
+
formatStack(stack, message, opts) {
|
|
2422
|
+
const indent = " ".repeat((opts?.errorLevel || 0) + 1);
|
|
2423
|
+
return indent + parseStack(stack, message).join(`
|
|
2424
|
+
${indent}`);
|
|
2425
|
+
}
|
|
2426
|
+
formatError(err, opts) {
|
|
2427
|
+
const message = err.message ?? formatWithOptions(opts, err);
|
|
2428
|
+
const stack = err.stack ? this.formatStack(err.stack, message, opts) : "";
|
|
2429
|
+
const level = opts?.errorLevel || 0;
|
|
2430
|
+
const causedPrefix = level > 0 ? `${" ".repeat(level)}[cause]: ` : "";
|
|
2431
|
+
const causedError = err.cause ? "\n\n" + this.formatError(err.cause, { ...opts, errorLevel: level + 1 }) : "";
|
|
2432
|
+
return causedPrefix + message + "\n" + stack + causedError;
|
|
2433
|
+
}
|
|
2434
|
+
formatArgs(args, opts) {
|
|
2435
|
+
const _args = args.map((arg) => {
|
|
2436
|
+
if (arg && typeof arg.stack === "string") {
|
|
2437
|
+
return this.formatError(arg, opts);
|
|
2438
|
+
}
|
|
2439
|
+
return arg;
|
|
2440
|
+
});
|
|
2441
|
+
return formatWithOptions(opts, ..._args);
|
|
2442
|
+
}
|
|
2443
|
+
formatDate(date, opts) {
|
|
2444
|
+
return opts.date ? date.toLocaleTimeString() : "";
|
|
2445
|
+
}
|
|
2446
|
+
filterAndJoin(arr) {
|
|
2447
|
+
return arr.filter(Boolean).join(" ");
|
|
2448
|
+
}
|
|
2449
|
+
formatLogObj(logObj, opts) {
|
|
2450
|
+
const message = this.formatArgs(logObj.args, opts);
|
|
2451
|
+
if (logObj.type === "box") {
|
|
2452
|
+
return "\n" + [
|
|
2453
|
+
bracket(logObj.tag),
|
|
2454
|
+
logObj.title && logObj.title,
|
|
2455
|
+
...message.split("\n")
|
|
2456
|
+
].filter(Boolean).map((l2) => " > " + l2).join("\n") + "\n";
|
|
2457
|
+
}
|
|
2458
|
+
return this.filterAndJoin([
|
|
2459
|
+
bracket(logObj.type),
|
|
2460
|
+
bracket(logObj.tag),
|
|
2461
|
+
message
|
|
2462
|
+
]);
|
|
2463
|
+
}
|
|
2464
|
+
log(logObj, ctx) {
|
|
2465
|
+
const line = this.formatLogObj(logObj, {
|
|
2466
|
+
columns: ctx.options.stdout.columns || 0,
|
|
2467
|
+
...ctx.options.formatOptions
|
|
2468
|
+
});
|
|
2469
|
+
return writeStream(
|
|
2470
|
+
line + "\n",
|
|
2471
|
+
logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout
|
|
2472
|
+
);
|
|
2473
|
+
}
|
|
2474
|
+
};
|
|
2475
|
+
|
|
2476
|
+
// ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/index.mjs
|
|
2477
|
+
import g$1 from "process";
|
|
2478
|
+
|
|
2479
|
+
// ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs
|
|
2480
|
+
import * as tty from "tty";
|
|
2481
|
+
var {
|
|
2482
|
+
env = {},
|
|
2483
|
+
argv = [],
|
|
2484
|
+
platform = ""
|
|
2485
|
+
} = typeof process === "undefined" ? {} : process;
|
|
2486
|
+
var isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
|
|
2487
|
+
var isForced = "FORCE_COLOR" in env || argv.includes("--color");
|
|
2488
|
+
var isWindows = platform === "win32";
|
|
2489
|
+
var isDumbTerminal = env.TERM === "dumb";
|
|
2490
|
+
var isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
|
|
2491
|
+
var isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
|
|
2492
|
+
var isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
2493
|
+
function replaceClose(index, string, close, replace, head = string.slice(0, Math.max(0, index)) + replace, tail = string.slice(Math.max(0, index + close.length)), next = tail.indexOf(close)) {
|
|
2494
|
+
return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
|
2495
|
+
}
|
|
2496
|
+
function clearBleed(index, string, open, close, replace) {
|
|
2497
|
+
return index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
|
|
2498
|
+
}
|
|
2499
|
+
function filterEmpty(open, close, replace = open, at = open.length + 1) {
|
|
2500
|
+
return (string) => string || !(string === "" || string === void 0) ? clearBleed(
|
|
2501
|
+
("" + string).indexOf(close, at),
|
|
2502
|
+
string,
|
|
2503
|
+
open,
|
|
2504
|
+
close,
|
|
2505
|
+
replace
|
|
2506
|
+
) : "";
|
|
2507
|
+
}
|
|
2508
|
+
function init(open, close, replace) {
|
|
2509
|
+
return filterEmpty(`\x1B[${open}m`, `\x1B[${close}m`, replace);
|
|
2510
|
+
}
|
|
2511
|
+
var colorDefs = {
|
|
2512
|
+
reset: init(0, 0),
|
|
2513
|
+
bold: init(1, 22, "\x1B[22m\x1B[1m"),
|
|
2514
|
+
dim: init(2, 22, "\x1B[22m\x1B[2m"),
|
|
2515
|
+
italic: init(3, 23),
|
|
2516
|
+
underline: init(4, 24),
|
|
2517
|
+
inverse: init(7, 27),
|
|
2518
|
+
hidden: init(8, 28),
|
|
2519
|
+
strikethrough: init(9, 29),
|
|
2520
|
+
black: init(30, 39),
|
|
2521
|
+
red: init(31, 39),
|
|
2522
|
+
green: init(32, 39),
|
|
2523
|
+
yellow: init(33, 39),
|
|
2524
|
+
blue: init(34, 39),
|
|
2525
|
+
magenta: init(35, 39),
|
|
2526
|
+
cyan: init(36, 39),
|
|
2527
|
+
white: init(37, 39),
|
|
2528
|
+
gray: init(90, 39),
|
|
2529
|
+
bgBlack: init(40, 49),
|
|
2530
|
+
bgRed: init(41, 49),
|
|
2531
|
+
bgGreen: init(42, 49),
|
|
2532
|
+
bgYellow: init(43, 49),
|
|
2533
|
+
bgBlue: init(44, 49),
|
|
2534
|
+
bgMagenta: init(45, 49),
|
|
2535
|
+
bgCyan: init(46, 49),
|
|
2536
|
+
bgWhite: init(47, 49),
|
|
2537
|
+
blackBright: init(90, 39),
|
|
2538
|
+
redBright: init(91, 39),
|
|
2539
|
+
greenBright: init(92, 39),
|
|
2540
|
+
yellowBright: init(93, 39),
|
|
2541
|
+
blueBright: init(94, 39),
|
|
2542
|
+
magentaBright: init(95, 39),
|
|
2543
|
+
cyanBright: init(96, 39),
|
|
2544
|
+
whiteBright: init(97, 39),
|
|
2545
|
+
bgBlackBright: init(100, 49),
|
|
2546
|
+
bgRedBright: init(101, 49),
|
|
2547
|
+
bgGreenBright: init(102, 49),
|
|
2548
|
+
bgYellowBright: init(103, 49),
|
|
2549
|
+
bgBlueBright: init(104, 49),
|
|
2550
|
+
bgMagentaBright: init(105, 49),
|
|
2551
|
+
bgCyanBright: init(106, 49),
|
|
2552
|
+
bgWhiteBright: init(107, 49)
|
|
2553
|
+
};
|
|
2554
|
+
function createColors(useColor = isColorSupported) {
|
|
2555
|
+
return useColor ? colorDefs : Object.fromEntries(Object.keys(colorDefs).map((key) => [key, String]));
|
|
2556
|
+
}
|
|
2557
|
+
var colors = createColors();
|
|
2558
|
+
function getColor(color, fallback = "reset") {
|
|
2559
|
+
return colors[color] || colors[fallback];
|
|
2560
|
+
}
|
|
2561
|
+
var ansiRegex = [
|
|
2562
|
+
String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`,
|
|
2563
|
+
String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`
|
|
2564
|
+
].join("|");
|
|
2565
|
+
function stripAnsi(text) {
|
|
2566
|
+
return text.replace(new RegExp(ansiRegex, "g"), "");
|
|
2567
|
+
}
|
|
2568
|
+
var boxStylePresets = {
|
|
2569
|
+
solid: {
|
|
2570
|
+
tl: "\u250C",
|
|
2571
|
+
tr: "\u2510",
|
|
2572
|
+
bl: "\u2514",
|
|
2573
|
+
br: "\u2518",
|
|
2574
|
+
h: "\u2500",
|
|
2575
|
+
v: "\u2502"
|
|
2576
|
+
},
|
|
2577
|
+
double: {
|
|
2578
|
+
tl: "\u2554",
|
|
2579
|
+
tr: "\u2557",
|
|
2580
|
+
bl: "\u255A",
|
|
2581
|
+
br: "\u255D",
|
|
2582
|
+
h: "\u2550",
|
|
2583
|
+
v: "\u2551"
|
|
2584
|
+
},
|
|
2585
|
+
doubleSingle: {
|
|
2586
|
+
tl: "\u2553",
|
|
2587
|
+
tr: "\u2556",
|
|
2588
|
+
bl: "\u2559",
|
|
2589
|
+
br: "\u255C",
|
|
2590
|
+
h: "\u2500",
|
|
2591
|
+
v: "\u2551"
|
|
2592
|
+
},
|
|
2593
|
+
doubleSingleRounded: {
|
|
2594
|
+
tl: "\u256D",
|
|
2595
|
+
tr: "\u256E",
|
|
2596
|
+
bl: "\u2570",
|
|
2597
|
+
br: "\u256F",
|
|
2598
|
+
h: "\u2500",
|
|
2599
|
+
v: "\u2551"
|
|
2600
|
+
},
|
|
2601
|
+
singleThick: {
|
|
2602
|
+
tl: "\u250F",
|
|
2603
|
+
tr: "\u2513",
|
|
2604
|
+
bl: "\u2517",
|
|
2605
|
+
br: "\u251B",
|
|
2606
|
+
h: "\u2501",
|
|
2607
|
+
v: "\u2503"
|
|
2608
|
+
},
|
|
2609
|
+
singleDouble: {
|
|
2610
|
+
tl: "\u2552",
|
|
2611
|
+
tr: "\u2555",
|
|
2612
|
+
bl: "\u2558",
|
|
2613
|
+
br: "\u255B",
|
|
2614
|
+
h: "\u2550",
|
|
2615
|
+
v: "\u2502"
|
|
2616
|
+
},
|
|
2617
|
+
singleDoubleRounded: {
|
|
2618
|
+
tl: "\u256D",
|
|
2619
|
+
tr: "\u256E",
|
|
2620
|
+
bl: "\u2570",
|
|
2621
|
+
br: "\u256F",
|
|
2622
|
+
h: "\u2550",
|
|
2623
|
+
v: "\u2502"
|
|
2624
|
+
},
|
|
2625
|
+
rounded: {
|
|
2626
|
+
tl: "\u256D",
|
|
2627
|
+
tr: "\u256E",
|
|
2628
|
+
bl: "\u2570",
|
|
2629
|
+
br: "\u256F",
|
|
2630
|
+
h: "\u2500",
|
|
2631
|
+
v: "\u2502"
|
|
2632
|
+
}
|
|
2633
|
+
};
|
|
2634
|
+
var defaultStyle = {
|
|
2635
|
+
borderColor: "white",
|
|
2636
|
+
borderStyle: "rounded",
|
|
2637
|
+
valign: "center",
|
|
2638
|
+
padding: 2,
|
|
2639
|
+
marginLeft: 1,
|
|
2640
|
+
marginTop: 1,
|
|
2641
|
+
marginBottom: 1
|
|
2642
|
+
};
|
|
2643
|
+
function box(text, _opts = {}) {
|
|
2644
|
+
const opts = {
|
|
2645
|
+
..._opts,
|
|
2646
|
+
style: {
|
|
2647
|
+
...defaultStyle,
|
|
2648
|
+
..._opts.style
|
|
2649
|
+
}
|
|
2650
|
+
};
|
|
2651
|
+
const textLines = text.split("\n");
|
|
2652
|
+
const boxLines = [];
|
|
2653
|
+
const _color = getColor(opts.style.borderColor);
|
|
2654
|
+
const borderStyle = {
|
|
2655
|
+
...typeof opts.style.borderStyle === "string" ? boxStylePresets[opts.style.borderStyle] || boxStylePresets.solid : opts.style.borderStyle
|
|
2656
|
+
};
|
|
2657
|
+
if (_color) {
|
|
2658
|
+
for (const key in borderStyle) {
|
|
2659
|
+
borderStyle[key] = _color(
|
|
2660
|
+
borderStyle[key]
|
|
2661
|
+
);
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
const paddingOffset = opts.style.padding % 2 === 0 ? opts.style.padding : opts.style.padding + 1;
|
|
2665
|
+
const height = textLines.length + paddingOffset;
|
|
2666
|
+
const width = Math.max(
|
|
2667
|
+
...textLines.map((line) => stripAnsi(line).length),
|
|
2668
|
+
opts.title ? stripAnsi(opts.title).length : 0
|
|
2669
|
+
) + paddingOffset;
|
|
2670
|
+
const widthOffset = width + paddingOffset;
|
|
2671
|
+
const leftSpace = opts.style.marginLeft > 0 ? " ".repeat(opts.style.marginLeft) : "";
|
|
2672
|
+
if (opts.style.marginTop > 0) {
|
|
2673
|
+
boxLines.push("".repeat(opts.style.marginTop));
|
|
2674
|
+
}
|
|
2675
|
+
if (opts.title) {
|
|
2676
|
+
const title = _color ? _color(opts.title) : opts.title;
|
|
2677
|
+
const left = borderStyle.h.repeat(
|
|
2678
|
+
Math.floor((width - stripAnsi(opts.title).length) / 2)
|
|
2679
|
+
);
|
|
2680
|
+
const right = borderStyle.h.repeat(
|
|
2681
|
+
width - stripAnsi(opts.title).length - stripAnsi(left).length + paddingOffset
|
|
2682
|
+
);
|
|
2683
|
+
boxLines.push(
|
|
2684
|
+
`${leftSpace}${borderStyle.tl}${left}${title}${right}${borderStyle.tr}`
|
|
2685
|
+
);
|
|
2686
|
+
} else {
|
|
2687
|
+
boxLines.push(
|
|
2688
|
+
`${leftSpace}${borderStyle.tl}${borderStyle.h.repeat(widthOffset)}${borderStyle.tr}`
|
|
2689
|
+
);
|
|
2690
|
+
}
|
|
2691
|
+
const valignOffset = opts.style.valign === "center" ? Math.floor((height - textLines.length) / 2) : opts.style.valign === "top" ? height - textLines.length - paddingOffset : height - textLines.length;
|
|
2692
|
+
for (let i2 = 0; i2 < height; i2++) {
|
|
2693
|
+
if (i2 < valignOffset || i2 >= valignOffset + textLines.length) {
|
|
2694
|
+
boxLines.push(
|
|
2695
|
+
`${leftSpace}${borderStyle.v}${" ".repeat(widthOffset)}${borderStyle.v}`
|
|
2696
|
+
);
|
|
2697
|
+
} else {
|
|
2698
|
+
const line = textLines[i2 - valignOffset];
|
|
2699
|
+
const left = " ".repeat(paddingOffset);
|
|
2700
|
+
const right = " ".repeat(width - stripAnsi(line).length);
|
|
2701
|
+
boxLines.push(
|
|
2702
|
+
`${leftSpace}${borderStyle.v}${left}${line}${right}${borderStyle.v}`
|
|
2703
|
+
);
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
boxLines.push(
|
|
2707
|
+
`${leftSpace}${borderStyle.bl}${borderStyle.h.repeat(widthOffset)}${borderStyle.br}`
|
|
2708
|
+
);
|
|
2709
|
+
if (opts.style.marginBottom > 0) {
|
|
2710
|
+
boxLines.push("".repeat(opts.style.marginBottom));
|
|
2711
|
+
}
|
|
2712
|
+
return boxLines.join("\n");
|
|
2713
|
+
}
|
|
2714
|
+
|
|
2715
|
+
// ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/index.mjs
|
|
2716
|
+
import "util";
|
|
2717
|
+
import "path";
|
|
2718
|
+
import "tty";
|
|
2719
|
+
var r2 = /* @__PURE__ */ Object.create(null);
|
|
2720
|
+
var i = (e2) => globalThis.process?.env || import.meta.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (e2 ? r2 : globalThis);
|
|
2721
|
+
var o2 = new Proxy(r2, { get(e2, s2) {
|
|
2722
|
+
return i()[s2] ?? r2[s2];
|
|
2723
|
+
}, has(e2, s2) {
|
|
2724
|
+
const E = i();
|
|
2725
|
+
return s2 in E || s2 in r2;
|
|
2726
|
+
}, set(e2, s2, E) {
|
|
2727
|
+
const B2 = i(true);
|
|
2728
|
+
return B2[s2] = E, true;
|
|
2729
|
+
}, deleteProperty(e2, s2) {
|
|
2730
|
+
if (!s2) return false;
|
|
2731
|
+
const E = i(true);
|
|
2732
|
+
return delete E[s2], true;
|
|
2733
|
+
}, ownKeys() {
|
|
2734
|
+
const e2 = i(true);
|
|
2735
|
+
return Object.keys(e2);
|
|
2736
|
+
} });
|
|
2737
|
+
var t = typeof process < "u" && process.env && process.env.NODE_ENV || "";
|
|
2738
|
+
var f2 = [["APPVEYOR"], ["AWS_AMPLIFY", "AWS_APP_ID", { ci: true }], ["AZURE_PIPELINES", "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"], ["AZURE_STATIC", "INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"], ["APPCIRCLE", "AC_APPCIRCLE"], ["BAMBOO", "bamboo_planKey"], ["BITBUCKET", "BITBUCKET_COMMIT"], ["BITRISE", "BITRISE_IO"], ["BUDDY", "BUDDY_WORKSPACE_ID"], ["BUILDKITE"], ["CIRCLE", "CIRCLECI"], ["CIRRUS", "CIRRUS_CI"], ["CLOUDFLARE_PAGES", "CF_PAGES", { ci: true }], ["CODEBUILD", "CODEBUILD_BUILD_ARN"], ["CODEFRESH", "CF_BUILD_ID"], ["DRONE"], ["DRONE", "DRONE_BUILD_EVENT"], ["DSARI"], ["GITHUB_ACTIONS"], ["GITLAB", "GITLAB_CI"], ["GITLAB", "CI_MERGE_REQUEST_ID"], ["GOCD", "GO_PIPELINE_LABEL"], ["LAYERCI"], ["HUDSON", "HUDSON_URL"], ["JENKINS", "JENKINS_URL"], ["MAGNUM"], ["NETLIFY"], ["NETLIFY", "NETLIFY_LOCAL", { ci: false }], ["NEVERCODE"], ["RENDER"], ["SAIL", "SAILCI"], ["SEMAPHORE"], ["SCREWDRIVER"], ["SHIPPABLE"], ["SOLANO", "TDDIUM"], ["STRIDER"], ["TEAMCITY", "TEAMCITY_VERSION"], ["TRAVIS"], ["VERCEL", "NOW_BUILDER"], ["VERCEL", "VERCEL", { ci: false }], ["VERCEL", "VERCEL_ENV", { ci: false }], ["APPCENTER", "APPCENTER_BUILD_ID"], ["CODESANDBOX", "CODESANDBOX_SSE", { ci: false }], ["CODESANDBOX", "CODESANDBOX_HOST", { ci: false }], ["STACKBLITZ"], ["STORMKIT"], ["CLEAVR"], ["ZEABUR"], ["CODESPHERE", "CODESPHERE_APP_ID", { ci: true }], ["RAILWAY", "RAILWAY_PROJECT_ID"], ["RAILWAY", "RAILWAY_SERVICE_ID"], ["DENO-DEPLOY", "DENO_DEPLOYMENT_ID"], ["FIREBASE_APP_HOSTING", "FIREBASE_APP_HOSTING", { ci: true }]];
|
|
2739
|
+
function b() {
|
|
2740
|
+
if (globalThis.process?.env) for (const e2 of f2) {
|
|
2741
|
+
const s2 = e2[1] || e2[0];
|
|
2742
|
+
if (globalThis.process?.env[s2]) return { name: e2[0].toLowerCase(), ...e2[2] };
|
|
2743
|
+
}
|
|
2744
|
+
return globalThis.process?.env?.SHELL === "/bin/jsh" && globalThis.process?.versions?.webcontainer ? { name: "stackblitz", ci: false } : { name: "", ci: false };
|
|
2745
|
+
}
|
|
2746
|
+
var l = b();
|
|
2747
|
+
l.name;
|
|
2748
|
+
function n(e2) {
|
|
2749
|
+
return e2 ? e2 !== "false" : false;
|
|
2750
|
+
}
|
|
2751
|
+
var I2 = globalThis.process?.platform || "";
|
|
2752
|
+
var T2 = n(o2.CI) || l.ci !== false;
|
|
2753
|
+
var a = n(globalThis.process?.stdout && globalThis.process?.stdout.isTTY);
|
|
2754
|
+
var g2 = n(o2.DEBUG);
|
|
2755
|
+
var R2 = t === "test" || n(o2.TEST);
|
|
2756
|
+
n(o2.MINIMAL) || T2 || R2 || !a;
|
|
2757
|
+
var A2 = /^win/i.test(I2);
|
|
2758
|
+
!n(o2.NO_COLOR) && (n(o2.FORCE_COLOR) || (a || A2) && o2.TERM !== "dumb" || T2);
|
|
2759
|
+
var C2 = (globalThis.process?.versions?.node || "").replace(/^v/, "") || null;
|
|
2760
|
+
Number(C2?.split(".")[0]) || null;
|
|
2761
|
+
var y2 = globalThis.process || /* @__PURE__ */ Object.create(null);
|
|
2762
|
+
var _2 = { versions: {} };
|
|
2763
|
+
new Proxy(y2, { get(e2, s2) {
|
|
2764
|
+
if (s2 === "env") return o2;
|
|
2765
|
+
if (s2 in e2) return e2[s2];
|
|
2766
|
+
if (s2 in _2) return _2[s2];
|
|
2767
|
+
} });
|
|
2768
|
+
var c2 = globalThis.process?.release?.name === "node";
|
|
2769
|
+
var O2 = !!globalThis.Bun || !!globalThis.process?.versions?.bun;
|
|
2770
|
+
var D = !!globalThis.Deno;
|
|
2771
|
+
var L2 = !!globalThis.fastly;
|
|
2772
|
+
var S2 = !!globalThis.Netlify;
|
|
2773
|
+
var u2 = !!globalThis.EdgeRuntime;
|
|
2774
|
+
var N2 = globalThis.navigator?.userAgent === "Cloudflare-Workers";
|
|
2775
|
+
var F2 = [[S2, "netlify"], [u2, "edge-light"], [N2, "workerd"], [L2, "fastly"], [D, "deno"], [O2, "bun"], [c2, "node"]];
|
|
2776
|
+
function G2() {
|
|
2777
|
+
const e2 = F2.find((s2) => s2[0]);
|
|
2778
|
+
if (e2) return { name: e2[1] };
|
|
2779
|
+
}
|
|
2780
|
+
var P2 = G2();
|
|
2781
|
+
P2?.name || "";
|
|
2782
|
+
function ansiRegex2({ onlyFirst = false } = {}) {
|
|
2783
|
+
const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
|
|
2784
|
+
const pattern = [
|
|
2785
|
+
`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`,
|
|
2786
|
+
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"
|
|
2787
|
+
].join("|");
|
|
2788
|
+
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
2789
|
+
}
|
|
2790
|
+
var regex = ansiRegex2();
|
|
2791
|
+
function stripAnsi2(string) {
|
|
2792
|
+
if (typeof string !== "string") {
|
|
2793
|
+
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
2794
|
+
}
|
|
2795
|
+
return string.replace(regex, "");
|
|
2796
|
+
}
|
|
2797
|
+
function isAmbiguous(x2) {
|
|
2798
|
+
return x2 === 161 || x2 === 164 || x2 === 167 || x2 === 168 || x2 === 170 || x2 === 173 || x2 === 174 || x2 >= 176 && x2 <= 180 || x2 >= 182 && x2 <= 186 || x2 >= 188 && x2 <= 191 || x2 === 198 || x2 === 208 || x2 === 215 || x2 === 216 || x2 >= 222 && x2 <= 225 || x2 === 230 || x2 >= 232 && x2 <= 234 || x2 === 236 || x2 === 237 || x2 === 240 || x2 === 242 || x2 === 243 || x2 >= 247 && x2 <= 250 || x2 === 252 || x2 === 254 || x2 === 257 || x2 === 273 || x2 === 275 || x2 === 283 || x2 === 294 || x2 === 295 || x2 === 299 || x2 >= 305 && x2 <= 307 || x2 === 312 || x2 >= 319 && x2 <= 322 || x2 === 324 || x2 >= 328 && x2 <= 331 || x2 === 333 || x2 === 338 || x2 === 339 || x2 === 358 || x2 === 359 || x2 === 363 || x2 === 462 || x2 === 464 || x2 === 466 || x2 === 468 || x2 === 470 || x2 === 472 || x2 === 474 || x2 === 476 || x2 === 593 || x2 === 609 || x2 === 708 || x2 === 711 || x2 >= 713 && x2 <= 715 || x2 === 717 || x2 === 720 || x2 >= 728 && x2 <= 731 || x2 === 733 || x2 === 735 || x2 >= 768 && x2 <= 879 || x2 >= 913 && x2 <= 929 || x2 >= 931 && x2 <= 937 || x2 >= 945 && x2 <= 961 || x2 >= 963 && x2 <= 969 || x2 === 1025 || x2 >= 1040 && x2 <= 1103 || x2 === 1105 || x2 === 8208 || x2 >= 8211 && x2 <= 8214 || x2 === 8216 || x2 === 8217 || x2 === 8220 || x2 === 8221 || x2 >= 8224 && x2 <= 8226 || x2 >= 8228 && x2 <= 8231 || x2 === 8240 || x2 === 8242 || x2 === 8243 || x2 === 8245 || x2 === 8251 || x2 === 8254 || x2 === 8308 || x2 === 8319 || x2 >= 8321 && x2 <= 8324 || x2 === 8364 || x2 === 8451 || x2 === 8453 || x2 === 8457 || x2 === 8467 || x2 === 8470 || x2 === 8481 || x2 === 8482 || x2 === 8486 || x2 === 8491 || x2 === 8531 || x2 === 8532 || x2 >= 8539 && x2 <= 8542 || x2 >= 8544 && x2 <= 8555 || x2 >= 8560 && x2 <= 8569 || x2 === 8585 || x2 >= 8592 && x2 <= 8601 || x2 === 8632 || x2 === 8633 || x2 === 8658 || x2 === 8660 || x2 === 8679 || x2 === 8704 || x2 === 8706 || x2 === 8707 || x2 === 8711 || x2 === 8712 || x2 === 8715 || x2 === 8719 || x2 === 8721 || x2 === 8725 || x2 === 8730 || x2 >= 8733 && x2 <= 8736 || x2 === 8739 || x2 === 8741 || x2 >= 8743 && x2 <= 8748 || x2 === 8750 || x2 >= 8756 && x2 <= 8759 || x2 === 8764 || x2 === 8765 || x2 === 8776 || x2 === 8780 || x2 === 8786 || x2 === 8800 || x2 === 8801 || x2 >= 8804 && x2 <= 8807 || x2 === 8810 || x2 === 8811 || x2 === 8814 || x2 === 8815 || x2 === 8834 || x2 === 8835 || x2 === 8838 || x2 === 8839 || x2 === 8853 || x2 === 8857 || x2 === 8869 || x2 === 8895 || x2 === 8978 || x2 >= 9312 && x2 <= 9449 || x2 >= 9451 && x2 <= 9547 || x2 >= 9552 && x2 <= 9587 || x2 >= 9600 && x2 <= 9615 || x2 >= 9618 && x2 <= 9621 || x2 === 9632 || x2 === 9633 || x2 >= 9635 && x2 <= 9641 || x2 === 9650 || x2 === 9651 || x2 === 9654 || x2 === 9655 || x2 === 9660 || x2 === 9661 || x2 === 9664 || x2 === 9665 || x2 >= 9670 && x2 <= 9672 || x2 === 9675 || x2 >= 9678 && x2 <= 9681 || x2 >= 9698 && x2 <= 9701 || x2 === 9711 || x2 === 9733 || x2 === 9734 || x2 === 9737 || x2 === 9742 || x2 === 9743 || x2 === 9756 || x2 === 9758 || x2 === 9792 || x2 === 9794 || x2 === 9824 || x2 === 9825 || x2 >= 9827 && x2 <= 9829 || x2 >= 9831 && x2 <= 9834 || x2 === 9836 || x2 === 9837 || x2 === 9839 || x2 === 9886 || x2 === 9887 || x2 === 9919 || x2 >= 9926 && x2 <= 9933 || x2 >= 9935 && x2 <= 9939 || x2 >= 9941 && x2 <= 9953 || x2 === 9955 || x2 === 9960 || x2 === 9961 || x2 >= 9963 && x2 <= 9969 || x2 === 9972 || x2 >= 9974 && x2 <= 9977 || x2 === 9979 || x2 === 9980 || x2 === 9982 || x2 === 9983 || x2 === 10045 || x2 >= 10102 && x2 <= 10111 || x2 >= 11094 && x2 <= 11097 || x2 >= 12872 && x2 <= 12879 || x2 >= 57344 && x2 <= 63743 || x2 >= 65024 && x2 <= 65039 || x2 === 65533 || x2 >= 127232 && x2 <= 127242 || x2 >= 127248 && x2 <= 127277 || x2 >= 127280 && x2 <= 127337 || x2 >= 127344 && x2 <= 127373 || x2 === 127375 || x2 === 127376 || x2 >= 127387 && x2 <= 127404 || x2 >= 917760 && x2 <= 917999 || x2 >= 983040 && x2 <= 1048573 || x2 >= 1048576 && x2 <= 1114109;
|
|
2799
|
+
}
|
|
2800
|
+
function isFullWidth(x2) {
|
|
2801
|
+
return x2 === 12288 || x2 >= 65281 && x2 <= 65376 || x2 >= 65504 && x2 <= 65510;
|
|
2802
|
+
}
|
|
2803
|
+
function isWide(x2) {
|
|
2804
|
+
return x2 >= 4352 && x2 <= 4447 || x2 === 8986 || x2 === 8987 || x2 === 9001 || x2 === 9002 || x2 >= 9193 && x2 <= 9196 || x2 === 9200 || x2 === 9203 || x2 === 9725 || x2 === 9726 || x2 === 9748 || x2 === 9749 || x2 >= 9776 && x2 <= 9783 || x2 >= 9800 && x2 <= 9811 || x2 === 9855 || x2 >= 9866 && x2 <= 9871 || x2 === 9875 || x2 === 9889 || x2 === 9898 || x2 === 9899 || x2 === 9917 || x2 === 9918 || x2 === 9924 || x2 === 9925 || x2 === 9934 || x2 === 9940 || x2 === 9962 || x2 === 9970 || x2 === 9971 || x2 === 9973 || x2 === 9978 || x2 === 9981 || x2 === 9989 || x2 === 9994 || x2 === 9995 || x2 === 10024 || x2 === 10060 || x2 === 10062 || x2 >= 10067 && x2 <= 10069 || x2 === 10071 || x2 >= 10133 && x2 <= 10135 || x2 === 10160 || x2 === 10175 || x2 === 11035 || x2 === 11036 || x2 === 11088 || x2 === 11093 || x2 >= 11904 && x2 <= 11929 || x2 >= 11931 && x2 <= 12019 || x2 >= 12032 && x2 <= 12245 || x2 >= 12272 && x2 <= 12287 || x2 >= 12289 && x2 <= 12350 || x2 >= 12353 && x2 <= 12438 || x2 >= 12441 && x2 <= 12543 || x2 >= 12549 && x2 <= 12591 || x2 >= 12593 && x2 <= 12686 || x2 >= 12688 && x2 <= 12773 || x2 >= 12783 && x2 <= 12830 || x2 >= 12832 && x2 <= 12871 || x2 >= 12880 && x2 <= 42124 || x2 >= 42128 && x2 <= 42182 || x2 >= 43360 && x2 <= 43388 || x2 >= 44032 && x2 <= 55203 || x2 >= 63744 && x2 <= 64255 || x2 >= 65040 && x2 <= 65049 || x2 >= 65072 && x2 <= 65106 || x2 >= 65108 && x2 <= 65126 || x2 >= 65128 && x2 <= 65131 || x2 >= 94176 && x2 <= 94180 || x2 === 94192 || x2 === 94193 || x2 >= 94208 && x2 <= 100343 || x2 >= 100352 && x2 <= 101589 || x2 >= 101631 && x2 <= 101640 || x2 >= 110576 && x2 <= 110579 || x2 >= 110581 && x2 <= 110587 || x2 === 110589 || x2 === 110590 || x2 >= 110592 && x2 <= 110882 || x2 === 110898 || x2 >= 110928 && x2 <= 110930 || x2 === 110933 || x2 >= 110948 && x2 <= 110951 || x2 >= 110960 && x2 <= 111355 || x2 >= 119552 && x2 <= 119638 || x2 >= 119648 && x2 <= 119670 || x2 === 126980 || x2 === 127183 || x2 === 127374 || x2 >= 127377 && x2 <= 127386 || x2 >= 127488 && x2 <= 127490 || x2 >= 127504 && x2 <= 127547 || x2 >= 127552 && x2 <= 127560 || x2 === 127568 || x2 === 127569 || x2 >= 127584 && x2 <= 127589 || x2 >= 127744 && x2 <= 127776 || x2 >= 127789 && x2 <= 127797 || x2 >= 127799 && x2 <= 127868 || x2 >= 127870 && x2 <= 127891 || x2 >= 127904 && x2 <= 127946 || x2 >= 127951 && x2 <= 127955 || x2 >= 127968 && x2 <= 127984 || x2 === 127988 || x2 >= 127992 && x2 <= 128062 || x2 === 128064 || x2 >= 128066 && x2 <= 128252 || x2 >= 128255 && x2 <= 128317 || x2 >= 128331 && x2 <= 128334 || x2 >= 128336 && x2 <= 128359 || x2 === 128378 || x2 === 128405 || x2 === 128406 || x2 === 128420 || x2 >= 128507 && x2 <= 128591 || x2 >= 128640 && x2 <= 128709 || x2 === 128716 || x2 >= 128720 && x2 <= 128722 || x2 >= 128725 && x2 <= 128727 || x2 >= 128732 && x2 <= 128735 || x2 === 128747 || x2 === 128748 || x2 >= 128756 && x2 <= 128764 || x2 >= 128992 && x2 <= 129003 || x2 === 129008 || x2 >= 129292 && x2 <= 129338 || x2 >= 129340 && x2 <= 129349 || x2 >= 129351 && x2 <= 129535 || x2 >= 129648 && x2 <= 129660 || x2 >= 129664 && x2 <= 129673 || x2 >= 129679 && x2 <= 129734 || x2 >= 129742 && x2 <= 129756 || x2 >= 129759 && x2 <= 129769 || x2 >= 129776 && x2 <= 129784 || x2 >= 131072 && x2 <= 196605 || x2 >= 196608 && x2 <= 262141;
|
|
2805
|
+
}
|
|
2806
|
+
function validate(codePoint) {
|
|
2807
|
+
if (!Number.isSafeInteger(codePoint)) {
|
|
2808
|
+
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
function eastAsianWidth(codePoint, { ambiguousAsWide = false } = {}) {
|
|
2812
|
+
validate(codePoint);
|
|
2813
|
+
if (isFullWidth(codePoint) || isWide(codePoint) || ambiguousAsWide && isAmbiguous(codePoint)) {
|
|
2814
|
+
return 2;
|
|
2815
|
+
}
|
|
2816
|
+
return 1;
|
|
2817
|
+
}
|
|
2818
|
+
var emojiRegex = () => {
|
|
2819
|
+
return /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE89\uDE8F-\uDEC2\uDEC6\uDECE-\uDEDC\uDEDF-\uDEE9]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g;
|
|
2820
|
+
};
|
|
2821
|
+
var segmenter = globalThis.Intl?.Segmenter ? new Intl.Segmenter() : { segment: (str) => str.split("") };
|
|
2822
|
+
var defaultIgnorableCodePointRegex = new RegExp("^\\p{Default_Ignorable_Code_Point}$", "u");
|
|
2823
|
+
function stringWidth$1(string, options = {}) {
|
|
2824
|
+
if (typeof string !== "string" || string.length === 0) {
|
|
2825
|
+
return 0;
|
|
2826
|
+
}
|
|
2827
|
+
const {
|
|
2828
|
+
ambiguousIsNarrow = true,
|
|
2829
|
+
countAnsiEscapeCodes = false
|
|
2830
|
+
} = options;
|
|
2831
|
+
if (!countAnsiEscapeCodes) {
|
|
2832
|
+
string = stripAnsi2(string);
|
|
2833
|
+
}
|
|
2834
|
+
if (string.length === 0) {
|
|
2835
|
+
return 0;
|
|
2836
|
+
}
|
|
2837
|
+
let width = 0;
|
|
2838
|
+
const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
|
|
2839
|
+
for (const { segment: character } of segmenter.segment(string)) {
|
|
2840
|
+
const codePoint = character.codePointAt(0);
|
|
2841
|
+
if (codePoint <= 31 || codePoint >= 127 && codePoint <= 159) {
|
|
2842
|
+
continue;
|
|
2843
|
+
}
|
|
2844
|
+
if (codePoint >= 8203 && codePoint <= 8207 || codePoint === 65279) {
|
|
2845
|
+
continue;
|
|
2846
|
+
}
|
|
2847
|
+
if (codePoint >= 768 && codePoint <= 879 || codePoint >= 6832 && codePoint <= 6911 || codePoint >= 7616 && codePoint <= 7679 || codePoint >= 8400 && codePoint <= 8447 || codePoint >= 65056 && codePoint <= 65071) {
|
|
2848
|
+
continue;
|
|
2849
|
+
}
|
|
2850
|
+
if (codePoint >= 55296 && codePoint <= 57343) {
|
|
2851
|
+
continue;
|
|
2852
|
+
}
|
|
2853
|
+
if (codePoint >= 65024 && codePoint <= 65039) {
|
|
2854
|
+
continue;
|
|
2855
|
+
}
|
|
2856
|
+
if (defaultIgnorableCodePointRegex.test(character)) {
|
|
2857
|
+
continue;
|
|
2858
|
+
}
|
|
2859
|
+
if (emojiRegex().test(character)) {
|
|
2860
|
+
width += 2;
|
|
2861
|
+
continue;
|
|
2862
|
+
}
|
|
2863
|
+
width += eastAsianWidth(codePoint, eastAsianWidthOptions);
|
|
2864
|
+
}
|
|
2865
|
+
return width;
|
|
2866
|
+
}
|
|
2867
|
+
function isUnicodeSupported() {
|
|
2868
|
+
const { env: env2 } = g$1;
|
|
2869
|
+
const { TERM, TERM_PROGRAM } = env2;
|
|
2870
|
+
if (g$1.platform !== "win32") {
|
|
2871
|
+
return TERM !== "linux";
|
|
2872
|
+
}
|
|
2873
|
+
return Boolean(env2.WT_SESSION) || Boolean(env2.TERMINUS_SUBLIME) || env2.ConEmuTask === "{cmd::Cmder}" || TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env2.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
2874
|
+
}
|
|
2875
|
+
var TYPE_COLOR_MAP = {
|
|
2876
|
+
info: "cyan",
|
|
2877
|
+
fail: "red",
|
|
2878
|
+
success: "green",
|
|
2879
|
+
ready: "green",
|
|
2880
|
+
start: "magenta"
|
|
2881
|
+
};
|
|
2882
|
+
var LEVEL_COLOR_MAP = {
|
|
2883
|
+
0: "red",
|
|
2884
|
+
1: "yellow"
|
|
2885
|
+
};
|
|
2886
|
+
var unicode = isUnicodeSupported();
|
|
2887
|
+
var s = (c3, fallback) => unicode ? c3 : fallback;
|
|
2888
|
+
var TYPE_ICONS = {
|
|
2889
|
+
error: s("\u2716", "\xD7"),
|
|
2890
|
+
fatal: s("\u2716", "\xD7"),
|
|
2891
|
+
ready: s("\u2714", "\u221A"),
|
|
2892
|
+
warn: s("\u26A0", "\u203C"),
|
|
2893
|
+
info: s("\u2139", "i"),
|
|
2894
|
+
success: s("\u2714", "\u221A"),
|
|
2895
|
+
debug: s("\u2699", "D"),
|
|
2896
|
+
trace: s("\u2192", "\u2192"),
|
|
2897
|
+
fail: s("\u2716", "\xD7"),
|
|
2898
|
+
start: s("\u25D0", "o"),
|
|
2899
|
+
log: ""
|
|
2900
|
+
};
|
|
2901
|
+
function stringWidth(str) {
|
|
2902
|
+
const hasICU = typeof Intl === "object";
|
|
2903
|
+
if (!hasICU || !Intl.Segmenter) {
|
|
2904
|
+
return stripAnsi(str).length;
|
|
2905
|
+
}
|
|
2906
|
+
return stringWidth$1(str);
|
|
2907
|
+
}
|
|
2908
|
+
var FancyReporter = class extends BasicReporter {
|
|
2909
|
+
formatStack(stack, message, opts) {
|
|
2910
|
+
const indent = " ".repeat((opts?.errorLevel || 0) + 1);
|
|
2911
|
+
return `
|
|
2912
|
+
${indent}` + parseStack(stack, message).map(
|
|
2913
|
+
(line) => " " + line.replace(/^at +/, (m2) => colors.gray(m2)).replace(/\((.+)\)/, (_3, m2) => `(${colors.cyan(m2)})`)
|
|
2914
|
+
).join(`
|
|
2915
|
+
${indent}`);
|
|
2916
|
+
}
|
|
2917
|
+
formatType(logObj, isBadge, opts) {
|
|
2918
|
+
const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || "gray";
|
|
2919
|
+
if (isBadge) {
|
|
2920
|
+
return getBgColor(typeColor)(
|
|
2921
|
+
colors.black(` ${logObj.type.toUpperCase()} `)
|
|
2922
|
+
);
|
|
2923
|
+
}
|
|
2924
|
+
const _type = typeof TYPE_ICONS[logObj.type] === "string" ? TYPE_ICONS[logObj.type] : logObj.icon || logObj.type;
|
|
2925
|
+
return _type ? getColor2(typeColor)(_type) : "";
|
|
2926
|
+
}
|
|
2927
|
+
formatLogObj(logObj, opts) {
|
|
2928
|
+
const [message, ...additional] = this.formatArgs(logObj.args, opts).split(
|
|
2929
|
+
"\n"
|
|
2930
|
+
);
|
|
2931
|
+
if (logObj.type === "box") {
|
|
2932
|
+
return box(
|
|
2933
|
+
characterFormat(
|
|
2934
|
+
message + (additional.length > 0 ? "\n" + additional.join("\n") : "")
|
|
2935
|
+
),
|
|
2936
|
+
{
|
|
2937
|
+
title: logObj.title ? characterFormat(logObj.title) : void 0,
|
|
2938
|
+
style: logObj.style
|
|
2939
|
+
}
|
|
2940
|
+
);
|
|
2941
|
+
}
|
|
2942
|
+
const date = this.formatDate(logObj.date, opts);
|
|
2943
|
+
const coloredDate = date && colors.gray(date);
|
|
2944
|
+
const isBadge = logObj.badge ?? logObj.level < 2;
|
|
2945
|
+
const type = this.formatType(logObj, isBadge, opts);
|
|
2946
|
+
const tag = logObj.tag ? colors.gray(logObj.tag) : "";
|
|
2947
|
+
let line;
|
|
2948
|
+
const left = this.filterAndJoin([type, characterFormat(message)]);
|
|
2949
|
+
const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]);
|
|
2950
|
+
const space = (opts.columns || 0) - stringWidth(left) - stringWidth(right) - 2;
|
|
2951
|
+
line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left;
|
|
2952
|
+
line += characterFormat(
|
|
2953
|
+
additional.length > 0 ? "\n" + additional.join("\n") : ""
|
|
2954
|
+
);
|
|
2955
|
+
if (logObj.type === "trace") {
|
|
2956
|
+
const _err = new Error("Trace: " + logObj.message);
|
|
2957
|
+
line += this.formatStack(_err.stack || "", _err.message);
|
|
2958
|
+
}
|
|
2959
|
+
return isBadge ? "\n" + line + "\n" : line;
|
|
2960
|
+
}
|
|
2961
|
+
};
|
|
2962
|
+
function characterFormat(str) {
|
|
2963
|
+
return str.replace(/`([^`]+)`/gm, (_3, m2) => colors.cyan(m2)).replace(/\s+_([^_]+)_\s+/gm, (_3, m2) => ` ${colors.underline(m2)} `);
|
|
2964
|
+
}
|
|
2965
|
+
function getColor2(color = "white") {
|
|
2966
|
+
return colors[color] || colors.white;
|
|
2967
|
+
}
|
|
2968
|
+
function getBgColor(color = "bgWhite") {
|
|
2969
|
+
return colors[`bg${color[0].toUpperCase()}${color.slice(1)}`] || colors.bgWhite;
|
|
2970
|
+
}
|
|
2971
|
+
function createConsola2(options = {}) {
|
|
2972
|
+
let level = _getDefaultLogLevel();
|
|
2973
|
+
if (process.env.CONSOLA_LEVEL) {
|
|
2974
|
+
level = Number.parseInt(process.env.CONSOLA_LEVEL) ?? level;
|
|
2975
|
+
}
|
|
2976
|
+
const consola2 = createConsola({
|
|
2977
|
+
level,
|
|
2978
|
+
defaults: { level },
|
|
2979
|
+
stdout: process.stdout,
|
|
2980
|
+
stderr: process.stderr,
|
|
2981
|
+
prompt: (...args) => Promise.resolve().then(() => (init_prompt(), prompt_exports)).then((m2) => m2.prompt(...args)),
|
|
2982
|
+
reporters: options.reporters || [
|
|
2983
|
+
options.fancy ?? !(T2 || R2) ? new FancyReporter() : new BasicReporter()
|
|
2984
|
+
],
|
|
2985
|
+
...options
|
|
2986
|
+
});
|
|
2987
|
+
return consola2;
|
|
2988
|
+
}
|
|
2989
|
+
function _getDefaultLogLevel() {
|
|
2990
|
+
if (g2) {
|
|
2991
|
+
return LogLevels.debug;
|
|
2992
|
+
}
|
|
2993
|
+
if (R2) {
|
|
2994
|
+
return LogLevels.warn;
|
|
2995
|
+
}
|
|
2996
|
+
return LogLevels.info;
|
|
2997
|
+
}
|
|
2998
|
+
var consola = createConsola2();
|
|
2999
|
+
|
|
3000
|
+
// ../../packages/apes/dist/chunk-DYSFQ26B.js
|
|
3001
|
+
var import_shell_quote = __toESM(require_shell_quote(), 1);
|
|
3002
|
+
|
|
3003
|
+
// ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/utils.mjs
|
|
3004
|
+
import "tty";
|
|
3005
|
+
|
|
3006
|
+
// ../../node_modules/.pnpm/citty@0.1.6/node_modules/citty/dist/index.mjs
|
|
3007
|
+
function defineCommand(def) {
|
|
3008
|
+
return def;
|
|
3009
|
+
}
|
|
3010
|
+
|
|
3011
|
+
// ../../packages/apes/dist/chunk-DYSFQ26B.js
|
|
3012
|
+
import { homedir as homedir52 } from "os";
|
|
3013
|
+
import { join as join5 } from "path";
|
|
3014
|
+
function parseKeyValue(line) {
|
|
3015
|
+
const eqIndex = line.indexOf("=");
|
|
3016
|
+
if (eqIndex === -1)
|
|
3017
|
+
return null;
|
|
3018
|
+
const key = line.slice(0, eqIndex).trim();
|
|
3019
|
+
const value = line.slice(eqIndex + 1).trim();
|
|
3020
|
+
if (!key || !value)
|
|
3021
|
+
return null;
|
|
3022
|
+
return { key, value };
|
|
3023
|
+
}
|
|
3024
|
+
function parseTomlValue(raw) {
|
|
3025
|
+
const trimmed = raw.trim();
|
|
3026
|
+
if (trimmed.startsWith('"') && trimmed.endsWith('"'))
|
|
3027
|
+
return trimmed.slice(1, -1);
|
|
3028
|
+
if (trimmed === "true")
|
|
3029
|
+
return true;
|
|
3030
|
+
if (trimmed === "false")
|
|
3031
|
+
return false;
|
|
3032
|
+
if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
|
|
3033
|
+
const inner = trimmed.slice(1, -1).trim();
|
|
3034
|
+
if (!inner)
|
|
3035
|
+
return [];
|
|
3036
|
+
return inner.split(",").map((value) => value.trim().replace(/^"|"$/g, ""));
|
|
3037
|
+
}
|
|
3038
|
+
return trimmed;
|
|
3039
|
+
}
|
|
3040
|
+
function parseAdapterToml(content) {
|
|
3041
|
+
const result = {};
|
|
3042
|
+
const operations = [];
|
|
3043
|
+
let currentSection = "root";
|
|
3044
|
+
let currentEntry = {};
|
|
3045
|
+
const flushOperation = () => {
|
|
3046
|
+
if (currentSection === "operation" && Object.keys(currentEntry).length > 0) {
|
|
3047
|
+
operations.push(currentEntry);
|
|
3048
|
+
currentEntry = {};
|
|
3049
|
+
}
|
|
3050
|
+
};
|
|
3051
|
+
for (const rawLine of content.split("\n")) {
|
|
3052
|
+
const line = rawLine.trim();
|
|
3053
|
+
if (!line || line.startsWith("#"))
|
|
3054
|
+
continue;
|
|
3055
|
+
if (line === "[cli]") {
|
|
3056
|
+
flushOperation();
|
|
3057
|
+
currentSection = "cli";
|
|
3058
|
+
result.cli = {};
|
|
3059
|
+
continue;
|
|
3060
|
+
}
|
|
3061
|
+
if (line === "[[operation]]") {
|
|
3062
|
+
flushOperation();
|
|
3063
|
+
currentSection = "operation";
|
|
3064
|
+
currentEntry = {};
|
|
3065
|
+
continue;
|
|
3066
|
+
}
|
|
3067
|
+
const kv = parseKeyValue(line);
|
|
3068
|
+
if (!kv)
|
|
3069
|
+
continue;
|
|
3070
|
+
const value = parseTomlValue(kv.value);
|
|
3071
|
+
if (currentSection === "root") {
|
|
3072
|
+
;
|
|
3073
|
+
result[kv.key] = value;
|
|
3074
|
+
} else if (currentSection === "cli") {
|
|
3075
|
+
;
|
|
3076
|
+
result.cli[kv.key] = value;
|
|
3077
|
+
} else {
|
|
3078
|
+
currentEntry[kv.key] = value;
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
flushOperation();
|
|
3082
|
+
result.operation = operations;
|
|
3083
|
+
if (result.schema !== "openape-shapes/v1") {
|
|
3084
|
+
throw new Error(`Unsupported adapter schema: ${result.schema ?? "missing"}`);
|
|
3085
|
+
}
|
|
3086
|
+
if (!result.cli?.id || !result.cli.executable) {
|
|
3087
|
+
throw new Error("Adapter is missing cli.id or cli.executable");
|
|
3088
|
+
}
|
|
3089
|
+
if (!result.operation?.length) {
|
|
3090
|
+
throw new Error("Adapter must define at least one [[operation]] entry");
|
|
3091
|
+
}
|
|
3092
|
+
return {
|
|
3093
|
+
schema: result.schema,
|
|
3094
|
+
cli: {
|
|
3095
|
+
id: String(result.cli.id),
|
|
3096
|
+
executable: String(result.cli.executable),
|
|
3097
|
+
...result.cli.audience ? { audience: String(result.cli.audience) } : {},
|
|
3098
|
+
...result.cli.version ? { version: String(result.cli.version) } : {}
|
|
3099
|
+
},
|
|
3100
|
+
operations: result.operation.map((operation) => {
|
|
3101
|
+
if (!Array.isArray(operation.command) || operation.command.some((token) => typeof token !== "string")) {
|
|
3102
|
+
throw new Error(`Operation ${String(operation.id ?? "<unknown>")} is missing command[]`);
|
|
3103
|
+
}
|
|
3104
|
+
if (!Array.isArray(operation.resource_chain) || operation.resource_chain.some((token) => typeof token !== "string")) {
|
|
3105
|
+
throw new Error(`Operation ${String(operation.id ?? "<unknown>")} is missing resource_chain[]`);
|
|
3106
|
+
}
|
|
3107
|
+
if (typeof operation.id !== "string" || typeof operation.display !== "string" || typeof operation.action !== "string") {
|
|
3108
|
+
throw new TypeError("Operation must define id, display, and action");
|
|
3109
|
+
}
|
|
3110
|
+
return {
|
|
3111
|
+
id: operation.id,
|
|
3112
|
+
command: operation.command,
|
|
3113
|
+
...Array.isArray(operation.positionals) ? { positionals: operation.positionals } : {},
|
|
3114
|
+
...Array.isArray(operation.required_options) ? { required_options: operation.required_options } : {},
|
|
3115
|
+
display: operation.display,
|
|
3116
|
+
action: operation.action,
|
|
3117
|
+
risk: operation.risk || "low",
|
|
3118
|
+
resource_chain: operation.resource_chain,
|
|
3119
|
+
...operation.exact_command !== void 0 ? { exact_command: Boolean(operation.exact_command) } : {}
|
|
3120
|
+
};
|
|
3121
|
+
})
|
|
3122
|
+
};
|
|
3123
|
+
}
|
|
3124
|
+
function digest(content) {
|
|
3125
|
+
return `SHA-256:${createHash("sha256").update(content).digest("hex")}`;
|
|
3126
|
+
}
|
|
3127
|
+
function adapterDirs() {
|
|
3128
|
+
return [
|
|
3129
|
+
join4(process.cwd(), ".openape", "shapes", "adapters"),
|
|
3130
|
+
join4(homedir5(), ".openape", "shapes", "adapters"),
|
|
3131
|
+
join4("/etc", "openape", "shapes", "adapters")
|
|
3132
|
+
];
|
|
3133
|
+
}
|
|
3134
|
+
function findByExecutable(executable) {
|
|
3135
|
+
for (const dir of adapterDirs()) {
|
|
3136
|
+
if (!existsSync3(dir))
|
|
3137
|
+
continue;
|
|
3138
|
+
try {
|
|
3139
|
+
const files = readdirSync2(dir).filter((f3) => f3.endsWith(".toml"));
|
|
3140
|
+
for (const file of files) {
|
|
3141
|
+
const path = join4(dir, file);
|
|
3142
|
+
const content = readFileSync4(path, "utf-8");
|
|
3143
|
+
const match = content.match(/^\s*executable\s*=\s*"([^"]+)"/m);
|
|
3144
|
+
if (match && match[1] === executable)
|
|
3145
|
+
return path;
|
|
3146
|
+
}
|
|
3147
|
+
} catch {
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
return void 0;
|
|
3151
|
+
}
|
|
3152
|
+
function resolveAdapterPath(cliId, explicitPath) {
|
|
3153
|
+
if (explicitPath) {
|
|
3154
|
+
if (existsSync3(explicitPath))
|
|
3155
|
+
return explicitPath;
|
|
3156
|
+
throw new Error(`Adapter file not found: ${explicitPath}`);
|
|
3157
|
+
}
|
|
3158
|
+
const candidates = adapterDirs().map((dir) => join4(dir, `${cliId}.toml`));
|
|
3159
|
+
const match = candidates.find((path) => existsSync3(path));
|
|
3160
|
+
if (match)
|
|
3161
|
+
return match;
|
|
3162
|
+
const byExec = findByExecutable(cliId);
|
|
3163
|
+
if (byExec)
|
|
3164
|
+
return byExec;
|
|
3165
|
+
throw new Error(`No adapter found for ${cliId}`);
|
|
3166
|
+
}
|
|
3167
|
+
function loadAdapter(cliId, explicitPath) {
|
|
3168
|
+
const source = resolveAdapterPath(cliId, explicitPath);
|
|
3169
|
+
const content = readFileSync4(source, "utf-8");
|
|
3170
|
+
const adapter = parseAdapterToml(content);
|
|
3171
|
+
const idMatch = adapter.cli.id === cliId;
|
|
3172
|
+
const fileMatch = basename(source) === `${cliId}.toml`;
|
|
3173
|
+
const execMatch = adapter.cli.executable === cliId;
|
|
3174
|
+
if (!idMatch && !fileMatch && !execMatch)
|
|
3175
|
+
throw new Error(`Adapter ${source} does not match requested CLI ${cliId}`);
|
|
3176
|
+
return {
|
|
3177
|
+
adapter,
|
|
3178
|
+
source,
|
|
3179
|
+
digest: digest(content)
|
|
3180
|
+
};
|
|
3181
|
+
}
|
|
3182
|
+
var REGISTRY_URL = process.env.SHAPES_REGISTRY_URL ?? "https://raw.githubusercontent.com/openape-ai/shapes-registry/main/registry.json";
|
|
3183
|
+
var CACHE_TTL_MS = 60 * 60 * 1e3;
|
|
3184
|
+
function parseOptionArgs(tokens, valueOptions) {
|
|
3185
|
+
const options = {};
|
|
3186
|
+
const positionals = [];
|
|
3187
|
+
const takesValue = new Set(valueOptions ?? []);
|
|
3188
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
3189
|
+
const token = tokens[index];
|
|
3190
|
+
if (token.startsWith("--")) {
|
|
3191
|
+
const stripped = token.slice(2);
|
|
3192
|
+
const eqIndex = stripped.indexOf("=");
|
|
3193
|
+
if (eqIndex >= 0) {
|
|
3194
|
+
options[stripped.slice(0, eqIndex)] = stripped.slice(eqIndex + 1);
|
|
3195
|
+
continue;
|
|
3196
|
+
}
|
|
3197
|
+
const next = tokens[index + 1];
|
|
3198
|
+
if (next && !next.startsWith("-")) {
|
|
3199
|
+
options[stripped] = next;
|
|
3200
|
+
index += 1;
|
|
3201
|
+
continue;
|
|
3202
|
+
}
|
|
3203
|
+
options[stripped] = "true";
|
|
3204
|
+
} else if (token.startsWith("-") && token.length > 1 && !/^-\d/.test(token)) {
|
|
3205
|
+
const key = token.slice(1);
|
|
3206
|
+
if (key.length === 1 && !takesValue.has(key)) {
|
|
3207
|
+
options[key] = "true";
|
|
3208
|
+
} else {
|
|
3209
|
+
const next = tokens[index + 1];
|
|
3210
|
+
if (next && !next.startsWith("-")) {
|
|
3211
|
+
options[key] = next;
|
|
3212
|
+
index += 1;
|
|
3213
|
+
} else {
|
|
3214
|
+
options[key] = "true";
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
} else {
|
|
3218
|
+
positionals.push(token);
|
|
3219
|
+
}
|
|
3220
|
+
}
|
|
3221
|
+
return { options, positionals };
|
|
3222
|
+
}
|
|
3223
|
+
function resolveBindingToken(binding, bindings) {
|
|
3224
|
+
const match = binding.match(/^\{([^}|]+)(?:\|([^}]+))?\}$/);
|
|
3225
|
+
if (!match)
|
|
3226
|
+
return binding;
|
|
3227
|
+
const [, name, transform] = match;
|
|
3228
|
+
const value = bindings[name];
|
|
3229
|
+
if (!value)
|
|
3230
|
+
throw new Error(`Missing binding: ${name}`);
|
|
3231
|
+
if (!transform)
|
|
3232
|
+
return value;
|
|
3233
|
+
if (transform === "owner" || transform === "name") {
|
|
3234
|
+
const [owner, repo] = value.split("/");
|
|
3235
|
+
if (!owner || !repo)
|
|
3236
|
+
throw new Error(`Binding ${name} must be in owner/name form`);
|
|
3237
|
+
return transform === "owner" ? owner : repo;
|
|
3238
|
+
}
|
|
3239
|
+
throw new Error(`Unsupported binding transform: ${transform}`);
|
|
3240
|
+
}
|
|
3241
|
+
function renderTemplate(template, bindings) {
|
|
3242
|
+
return template.replace(/\{([^}]+)\}/g, (_3, expression) => resolveBindingToken(`{${expression}}`, bindings));
|
|
3243
|
+
}
|
|
3244
|
+
function parseResourceChain(chain, bindings) {
|
|
3245
|
+
return chain.map((entry) => {
|
|
3246
|
+
const [resource, selectorSpec = "*"] = entry.split(":", 2);
|
|
3247
|
+
if (!resource)
|
|
3248
|
+
throw new Error(`Invalid resource chain entry: ${entry}`);
|
|
3249
|
+
if (selectorSpec === "*") {
|
|
3250
|
+
return { resource };
|
|
3251
|
+
}
|
|
3252
|
+
const selector = Object.fromEntries(
|
|
3253
|
+
selectorSpec.split(",").map((segment) => {
|
|
3254
|
+
const [key, rawValue] = segment.split("=", 2);
|
|
3255
|
+
if (!key || !rawValue)
|
|
3256
|
+
throw new Error(`Invalid selector segment: ${segment}`);
|
|
3257
|
+
return [key, renderTemplate(rawValue, bindings)];
|
|
3258
|
+
})
|
|
3259
|
+
);
|
|
3260
|
+
return { resource, selector };
|
|
3261
|
+
});
|
|
3262
|
+
}
|
|
3263
|
+
function matchOperation(operation, argv2) {
|
|
3264
|
+
if (argv2.length < operation.command.length)
|
|
3265
|
+
return null;
|
|
3266
|
+
const prefix = argv2.slice(0, operation.command.length);
|
|
3267
|
+
if (prefix.join("\0") !== operation.command.join("\0"))
|
|
3268
|
+
return null;
|
|
3269
|
+
const remainder = argv2.slice(operation.command.length);
|
|
3270
|
+
const { options, positionals } = parseOptionArgs(remainder, operation.required_options);
|
|
3271
|
+
const expectedPositionals = operation.positionals ?? [];
|
|
3272
|
+
if (positionals.length !== expectedPositionals.length)
|
|
3273
|
+
return null;
|
|
3274
|
+
for (const option of operation.required_options ?? []) {
|
|
3275
|
+
if (!options[option])
|
|
3276
|
+
return null;
|
|
3277
|
+
}
|
|
3278
|
+
const bindings = { ...options };
|
|
3279
|
+
for (let index = 0; index < expectedPositionals.length; index += 1) {
|
|
3280
|
+
const name = expectedPositionals[index];
|
|
3281
|
+
const value = positionals[index];
|
|
3282
|
+
if (name.startsWith("=")) {
|
|
3283
|
+
if (value !== name.slice(1))
|
|
3284
|
+
return null;
|
|
3285
|
+
continue;
|
|
3286
|
+
}
|
|
3287
|
+
bindings[name] = value;
|
|
3288
|
+
}
|
|
3289
|
+
return bindings;
|
|
3290
|
+
}
|
|
3291
|
+
function expandCombinedFlags(argv2) {
|
|
3292
|
+
return argv2.flatMap((token) => {
|
|
3293
|
+
if (token.startsWith("-") && !token.startsWith("--") && token.length > 2 && /^-[a-z]+$/i.test(token)) {
|
|
3294
|
+
return Array.from(token.slice(1), (c3) => `-${c3}`);
|
|
3295
|
+
}
|
|
3296
|
+
return [token];
|
|
3297
|
+
});
|
|
3298
|
+
}
|
|
3299
|
+
function tryMatch(operations, argv2) {
|
|
3300
|
+
return operations.flatMap((operation) => {
|
|
3301
|
+
try {
|
|
3302
|
+
const bindings = matchOperation(operation, argv2);
|
|
3303
|
+
return bindings ? [{ operation, bindings }] : [];
|
|
3304
|
+
} catch {
|
|
3305
|
+
return [];
|
|
3306
|
+
}
|
|
3307
|
+
});
|
|
3308
|
+
}
|
|
3309
|
+
async function resolveCommand(loaded, fullArgv) {
|
|
3310
|
+
const [executable, ...commandArgv] = fullArgv;
|
|
3311
|
+
if (!executable) {
|
|
3312
|
+
throw new Error("Missing wrapped command");
|
|
3313
|
+
}
|
|
3314
|
+
if (executable !== loaded.adapter.cli.executable) {
|
|
3315
|
+
throw new Error(`Adapter ${loaded.adapter.cli.id} expects executable ${loaded.adapter.cli.executable}, got ${executable}`);
|
|
3316
|
+
}
|
|
3317
|
+
let matches = tryMatch(loaded.adapter.operations, commandArgv);
|
|
3318
|
+
if (matches.length === 0) {
|
|
3319
|
+
const expanded = expandCombinedFlags(commandArgv);
|
|
3320
|
+
if (expanded.length !== commandArgv.length) {
|
|
3321
|
+
matches = tryMatch(loaded.adapter.operations, expanded);
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
if (matches.length === 0) {
|
|
3325
|
+
throw new Error(`No adapter operation matched: ${fullArgv.join(" ")}`);
|
|
3326
|
+
}
|
|
3327
|
+
if (matches.length > 1) {
|
|
3328
|
+
matches.sort((a2, b2) => b2.operation.command.length - a2.operation.command.length);
|
|
3329
|
+
matches = [matches[0]];
|
|
3330
|
+
}
|
|
3331
|
+
const { operation, bindings } = matches[0];
|
|
3332
|
+
const resource_chain = parseResourceChain(operation.resource_chain, bindings);
|
|
3333
|
+
const detail = {
|
|
3334
|
+
type: "openape_cli",
|
|
3335
|
+
cli_id: loaded.adapter.cli.id,
|
|
3336
|
+
operation_id: operation.id,
|
|
3337
|
+
resource_chain,
|
|
3338
|
+
action: operation.action,
|
|
3339
|
+
permission: "",
|
|
3340
|
+
display: renderTemplate(operation.display, bindings),
|
|
3341
|
+
risk: operation.risk,
|
|
3342
|
+
...operation.exact_command ? { constraints: { exact_command: true } } : {}
|
|
3343
|
+
};
|
|
3344
|
+
detail.permission = canonicalizeCliPermission(detail);
|
|
3345
|
+
return {
|
|
3346
|
+
adapter: loaded.adapter,
|
|
3347
|
+
source: loaded.source,
|
|
3348
|
+
digest: loaded.digest,
|
|
3349
|
+
executable,
|
|
3350
|
+
commandArgv,
|
|
3351
|
+
bindings,
|
|
3352
|
+
detail,
|
|
3353
|
+
executionContext: {
|
|
3354
|
+
argv: fullArgv,
|
|
3355
|
+
argv_hash: await computeArgvHash(fullArgv),
|
|
3356
|
+
adapter_id: loaded.adapter.cli.id,
|
|
3357
|
+
adapter_version: loaded.adapter.cli.version ?? loaded.adapter.schema,
|
|
3358
|
+
adapter_digest: loaded.digest,
|
|
3359
|
+
resolved_executable: executable,
|
|
3360
|
+
context_bindings: bindings
|
|
3361
|
+
},
|
|
3362
|
+
permission: detail.permission
|
|
3363
|
+
};
|
|
3364
|
+
}
|
|
3365
|
+
var explainCommand = defineCommand({
|
|
3366
|
+
meta: {
|
|
3367
|
+
name: "explain",
|
|
3368
|
+
description: "Show what permission a wrapped command would need"
|
|
3369
|
+
},
|
|
3370
|
+
args: {
|
|
3371
|
+
adapter: {
|
|
3372
|
+
type: "string",
|
|
3373
|
+
description: "Explicit path to adapter TOML file"
|
|
3374
|
+
},
|
|
3375
|
+
_: {
|
|
3376
|
+
type: "positional",
|
|
3377
|
+
description: "Wrapped command (after --)",
|
|
3378
|
+
required: false
|
|
3379
|
+
}
|
|
3380
|
+
},
|
|
3381
|
+
async run({ rawArgs }) {
|
|
3382
|
+
const command = extractWrappedCommand(rawArgs ?? []);
|
|
3383
|
+
if (command.length === 0)
|
|
3384
|
+
throw new Error("Missing wrapped command. Usage: shapes explain [--adapter <file>] -- <cli> ...");
|
|
3385
|
+
const adapterOpt = extractOption(rawArgs ?? [], "adapter");
|
|
3386
|
+
const loaded = loadAdapter(command[0], adapterOpt);
|
|
3387
|
+
const resolved = await resolveCommand(loaded, command);
|
|
3388
|
+
process.stdout.write(`${JSON.stringify({
|
|
3389
|
+
adapter: resolved.adapter.cli.id,
|
|
3390
|
+
source: resolved.source,
|
|
3391
|
+
operation: resolved.detail.operation_id,
|
|
3392
|
+
display: resolved.detail.display,
|
|
3393
|
+
permission: resolved.permission,
|
|
3394
|
+
resource_chain: resolved.detail.resource_chain,
|
|
3395
|
+
exact_command: resolved.detail.constraints?.exact_command ?? false,
|
|
3396
|
+
adapter_digest: resolved.digest
|
|
3397
|
+
}, null, 2)}
|
|
3398
|
+
`);
|
|
3399
|
+
}
|
|
3400
|
+
});
|
|
3401
|
+
function extractWrappedCommand(args) {
|
|
3402
|
+
const delimiter = args.indexOf("--");
|
|
3403
|
+
return delimiter >= 0 ? args.slice(delimiter + 1) : [];
|
|
3404
|
+
}
|
|
3405
|
+
function extractOption(args, name) {
|
|
3406
|
+
const delimiter = args.indexOf("--");
|
|
3407
|
+
const optionArgs = delimiter >= 0 ? args.slice(0, delimiter) : args;
|
|
3408
|
+
const index = optionArgs.indexOf(`--${name}`);
|
|
3409
|
+
if (index >= 0 && index + 1 < optionArgs.length)
|
|
3410
|
+
return optionArgs[index + 1];
|
|
3411
|
+
return void 0;
|
|
3412
|
+
}
|
|
3413
|
+
var AUTH_FILE2 = join5(homedir52(), ".config", "apes", "auth.json");
|
|
3414
|
+
|
|
3415
|
+
// ../../packages/apes/dist/chunk-QJJ7DG5C.js
|
|
3416
|
+
init_chunk_OBF7IMQ2();
|
|
3417
|
+
var debug = process.argv.includes("--debug");
|
|
3418
|
+
|
|
3419
|
+
// ../../packages/apes/dist/index.js
|
|
3420
|
+
init_chunk_OBF7IMQ2();
|
|
3421
|
+
init_chunk_7OCVIDC7();
|
|
3422
|
+
|
|
3423
|
+
// src/cron-runner.ts
|
|
3424
|
+
var TASK_CACHE_DIR = join6(homedir6(), ".openape", "agent", "tasks");
|
|
3425
|
+
var AGENT_CONFIG_PATH = join6(homedir6(), ".openape", "agent", "agent.json");
|
|
3426
|
+
var TASK_THREADS_PATH = join6(homedir6(), ".openape", "agent", "task-threads.json");
|
|
3427
|
+
var TICK_INTERVAL_MS = 6e4;
|
|
3428
|
+
function parseField(token, range, allowStep) {
|
|
3429
|
+
if (token === "*") return { type: "any" };
|
|
3430
|
+
if (allowStep && token.startsWith("*/")) {
|
|
3431
|
+
const step = Number(token.slice(2));
|
|
3432
|
+
if (!Number.isInteger(step) || step < 1 || step > range[1]) return null;
|
|
3433
|
+
return { type: "step", step };
|
|
3434
|
+
}
|
|
3435
|
+
const n2 = Number(token);
|
|
3436
|
+
if (!Number.isInteger(n2) || n2 < range[0] || n2 > range[1]) return null;
|
|
3437
|
+
return { type: "fixed", value: n2 };
|
|
3438
|
+
}
|
|
3439
|
+
function parseCron(expr) {
|
|
3440
|
+
const parts = expr.trim().split(/\s+/);
|
|
3441
|
+
if (parts.length !== 5) return null;
|
|
3442
|
+
const [m2, h2, dom, mo, dow] = parts;
|
|
3443
|
+
const minute = parseField(m2, [0, 59], true);
|
|
3444
|
+
const hour = parseField(h2, [0, 23], true);
|
|
3445
|
+
const dayOfMonth = parseField(dom, [1, 31], false);
|
|
3446
|
+
const month = parseField(mo, [1, 12], false);
|
|
3447
|
+
const dayOfWeek = parseField(dow, [0, 7], false);
|
|
3448
|
+
if (!minute || !hour || !dayOfMonth || !month || !dayOfWeek) return null;
|
|
3449
|
+
return {
|
|
3450
|
+
minute,
|
|
3451
|
+
hour,
|
|
3452
|
+
dom: dayOfMonth,
|
|
3453
|
+
month,
|
|
3454
|
+
dow: dayOfWeek
|
|
3455
|
+
};
|
|
3456
|
+
}
|
|
3457
|
+
function fieldMatches(field, value) {
|
|
3458
|
+
if (field.type === "any") return true;
|
|
3459
|
+
if (field.type === "fixed") return field.value === value;
|
|
3460
|
+
if (field.type === "step") return value % field.step === 0;
|
|
3461
|
+
return false;
|
|
3462
|
+
}
|
|
3463
|
+
function cronMatches(expr, now) {
|
|
3464
|
+
const dow = now.getDay();
|
|
3465
|
+
return fieldMatches(expr.minute, now.getMinutes()) && fieldMatches(expr.hour, now.getHours()) && fieldMatches(expr.dom, now.getDate()) && fieldMatches(expr.month, now.getMonth() + 1) && (fieldMatches(expr.dow, dow) || expr.dow.type === "fixed" && expr.dow.value === 7 && dow === 0);
|
|
3466
|
+
}
|
|
3467
|
+
function readTaskSpecs() {
|
|
3468
|
+
if (!existsSync4(TASK_CACHE_DIR)) return [];
|
|
3469
|
+
const out = [];
|
|
3470
|
+
for (const entry of readdirSync3(TASK_CACHE_DIR)) {
|
|
3471
|
+
if (!entry.endsWith(".json")) continue;
|
|
3472
|
+
const path = join6(TASK_CACHE_DIR, entry);
|
|
3473
|
+
try {
|
|
3474
|
+
const t2 = JSON.parse(readFileSync5(path, "utf8"));
|
|
3475
|
+
if (t2.taskId && t2.cron && t2.enabled !== false) out.push(t2);
|
|
3476
|
+
} catch {
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
3479
|
+
return out;
|
|
3480
|
+
}
|
|
3481
|
+
function readSystemPrompt() {
|
|
3482
|
+
if (!existsSync4(AGENT_CONFIG_PATH)) return "";
|
|
3483
|
+
try {
|
|
3484
|
+
const parsed = JSON.parse(readFileSync5(AGENT_CONFIG_PATH, "utf8"));
|
|
3485
|
+
return typeof parsed.systemPrompt === "string" ? parsed.systemPrompt : "";
|
|
3486
|
+
} catch {
|
|
3487
|
+
return "";
|
|
3488
|
+
}
|
|
3489
|
+
}
|
|
3490
|
+
var CronRunner = class {
|
|
3491
|
+
constructor(deps) {
|
|
3492
|
+
this.deps = deps;
|
|
3493
|
+
this.loadTaskThreads();
|
|
3494
|
+
}
|
|
3495
|
+
timer;
|
|
3496
|
+
lastTickedMinute;
|
|
3497
|
+
/**
|
|
3498
|
+
* Sessions still streaming — keeps accumulated text, destination
|
|
3499
|
+
* room, plus the troop run-id we created at fire time so we can
|
|
3500
|
+
* PATCH it with status + step_count when the run ends.
|
|
3501
|
+
*/
|
|
3502
|
+
pending = /* @__PURE__ */ new Map();
|
|
3503
|
+
/**
|
|
3504
|
+
* taskId → chatThreadId. Loaded from disk on construct, persisted
|
|
3505
|
+
* after each new thread allocation. All runs of the same task post
|
|
3506
|
+
* into the same thread so the chat history stays coherent.
|
|
3507
|
+
*/
|
|
3508
|
+
taskThreads = /* @__PURE__ */ new Map();
|
|
3509
|
+
loadTaskThreads() {
|
|
3510
|
+
if (!existsSync4(TASK_THREADS_PATH)) return;
|
|
3511
|
+
try {
|
|
3512
|
+
const parsed = JSON.parse(readFileSync5(TASK_THREADS_PATH, "utf8"));
|
|
3513
|
+
for (const [k2, v2] of Object.entries(parsed)) {
|
|
3514
|
+
if (typeof v2 === "string") this.taskThreads.set(k2, v2);
|
|
3515
|
+
}
|
|
3516
|
+
} catch {
|
|
3517
|
+
}
|
|
3518
|
+
}
|
|
3519
|
+
persistTaskThreads() {
|
|
3520
|
+
try {
|
|
3521
|
+
const dir = join6(homedir6(), ".openape", "agent");
|
|
3522
|
+
mkdirSync3(dir, { recursive: true });
|
|
3523
|
+
writeFileSync3(
|
|
3524
|
+
TASK_THREADS_PATH,
|
|
3525
|
+
`${JSON.stringify(Object.fromEntries(this.taskThreads), null, 2)}
|
|
3526
|
+
`,
|
|
3527
|
+
{ mode: 384 }
|
|
3528
|
+
);
|
|
3529
|
+
} catch (err) {
|
|
3530
|
+
this.deps.log(`task-threads persist failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
start() {
|
|
3534
|
+
if (this.timer) return;
|
|
3535
|
+
this.timer = setInterval(() => this.tick(), TICK_INTERVAL_MS);
|
|
3536
|
+
setTimeout(() => this.tick(), 5e3).unref();
|
|
3537
|
+
}
|
|
3538
|
+
stop() {
|
|
3539
|
+
if (this.timer) clearInterval(this.timer);
|
|
3540
|
+
this.timer = void 0;
|
|
3541
|
+
}
|
|
3542
|
+
/**
|
|
3543
|
+
* Fire any tasks whose cron matches the current minute. Idempotent
|
|
3544
|
+
* within a single minute — we de-dup by floored-minute-string.
|
|
3545
|
+
*/
|
|
3546
|
+
async tick() {
|
|
3547
|
+
const now = /* @__PURE__ */ new Date();
|
|
3548
|
+
const minuteKey = `${now.getFullYear()}-${now.getMonth()}-${now.getDate()}-${now.getHours()}-${now.getMinutes()}`;
|
|
3549
|
+
if (this.lastTickedMinute === minuteKey) return;
|
|
3550
|
+
this.lastTickedMinute = minuteKey;
|
|
3551
|
+
const specs = readTaskSpecs();
|
|
3552
|
+
const systemPrompt = readSystemPrompt();
|
|
3553
|
+
for (const spec of specs) {
|
|
3554
|
+
const expr = parseCron(spec.cron);
|
|
3555
|
+
if (!expr) {
|
|
3556
|
+
this.deps.log(`task ${spec.taskId}: invalid cron "${spec.cron}" \u2014 skipping`);
|
|
3557
|
+
continue;
|
|
3558
|
+
}
|
|
3559
|
+
if (!cronMatches(expr, now)) continue;
|
|
3560
|
+
void this.fire(spec, systemPrompt).catch((err) => {
|
|
3561
|
+
this.deps.log(`task ${spec.taskId} fire failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
3562
|
+
});
|
|
3563
|
+
}
|
|
3564
|
+
}
|
|
3565
|
+
async fire(spec, systemPrompt) {
|
|
3566
|
+
const contacts = await this.deps.chat.listContacts().catch(() => []);
|
|
3567
|
+
const ownerLower = this.deps.ownerEmail.toLowerCase();
|
|
3568
|
+
const room = contacts.find((c3) => c3.peerEmail.toLowerCase() === ownerLower && c3.connected && c3.roomId);
|
|
3569
|
+
if (!room?.roomId) {
|
|
3570
|
+
this.deps.log(`task ${spec.taskId} fired but no active owner room \u2014 skipping DM (accept the contact in chat)`);
|
|
3571
|
+
return;
|
|
3572
|
+
}
|
|
3573
|
+
const sessionId = `task:${spec.taskId}`;
|
|
3574
|
+
let runId;
|
|
3575
|
+
try {
|
|
3576
|
+
const res = await fetch(`${this.deps.troopUrl}/api/agents/me/runs`, {
|
|
3577
|
+
method: "POST",
|
|
3578
|
+
headers: {
|
|
3579
|
+
"Authorization": await this.deps.bearer(),
|
|
3580
|
+
"Content-Type": "application/json"
|
|
3581
|
+
},
|
|
3582
|
+
body: JSON.stringify({ task_id: spec.taskId })
|
|
3583
|
+
});
|
|
3584
|
+
if (res.ok) {
|
|
3585
|
+
const data = await res.json();
|
|
3586
|
+
runId = data.id;
|
|
3587
|
+
} else {
|
|
3588
|
+
this.deps.log(`troop startRun ${spec.taskId} failed: ${res.status}`);
|
|
3589
|
+
}
|
|
3590
|
+
} catch (err) {
|
|
3591
|
+
this.deps.log(`troop startRun ${spec.taskId} error: ${err instanceof Error ? err.message : String(err)}`);
|
|
3592
|
+
}
|
|
3593
|
+
this.pending.set(sessionId, { taskId: spec.taskId, taskName: spec.name, accumulated: "", roomId: room.roomId, status: "pending", runId });
|
|
3594
|
+
this.deps.log(`task ${spec.taskId} fired (session=${sessionId}, run=${runId ?? "no-troop"})`);
|
|
3595
|
+
void this.runTask(sessionId, systemPrompt, spec);
|
|
3596
|
+
}
|
|
3597
|
+
async runTask(sessionId, systemPrompt, spec) {
|
|
3598
|
+
try {
|
|
3599
|
+
const result = await runLoop({
|
|
3600
|
+
config: this.deps.runtimeConfig,
|
|
3601
|
+
systemPrompt,
|
|
3602
|
+
userMessage: spec.userPrompt,
|
|
3603
|
+
tools: taskTools(spec.tools),
|
|
3604
|
+
maxSteps: spec.maxSteps,
|
|
3605
|
+
handlers: {
|
|
3606
|
+
onTextDelta: (delta) => {
|
|
3607
|
+
const turn2 = this.pending.get(sessionId);
|
|
3608
|
+
if (turn2) turn2.accumulated += delta;
|
|
3609
|
+
}
|
|
3610
|
+
}
|
|
3611
|
+
});
|
|
3612
|
+
const turn = this.pending.get(sessionId);
|
|
3613
|
+
if (!turn) return;
|
|
3614
|
+
turn.status = result.status === "error" ? "error" : "ok";
|
|
3615
|
+
await this.finaliseRun(turn, result.stepCount);
|
|
3616
|
+
await this.postResult(sessionId, turn);
|
|
3617
|
+
this.pending.delete(sessionId);
|
|
3618
|
+
} catch (err) {
|
|
3619
|
+
const turn = this.pending.get(sessionId);
|
|
3620
|
+
if (!turn) return;
|
|
3621
|
+
turn.status = "error";
|
|
3622
|
+
turn.accumulated = `(runtime error: ${err instanceof Error ? err.message : String(err)})`;
|
|
3623
|
+
await this.finaliseRun(turn, 0);
|
|
3624
|
+
await this.postResult(sessionId, turn);
|
|
3625
|
+
this.pending.delete(sessionId);
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
async finaliseRun(turn, stepCount) {
|
|
3629
|
+
if (!turn.runId) return;
|
|
3630
|
+
try {
|
|
3631
|
+
await fetch(`${this.deps.troopUrl}/api/agents/me/runs/${encodeURIComponent(turn.runId)}`, {
|
|
3632
|
+
method: "PATCH",
|
|
3633
|
+
headers: {
|
|
3634
|
+
"Authorization": await this.deps.bearer(),
|
|
3635
|
+
"Content-Type": "application/json"
|
|
3636
|
+
},
|
|
3637
|
+
body: JSON.stringify({
|
|
3638
|
+
status: turn.status === "pending" ? "error" : turn.status,
|
|
3639
|
+
final_message: turn.accumulated.slice(0, 4e3),
|
|
3640
|
+
step_count: stepCount,
|
|
3641
|
+
trace: []
|
|
3642
|
+
})
|
|
3643
|
+
});
|
|
3644
|
+
} catch (err) {
|
|
3645
|
+
this.deps.log(`troop finaliseRun failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
async postResult(sid, turn) {
|
|
3649
|
+
const prefix = turn.status === "error" ? "\u274C" : "\u2705";
|
|
3650
|
+
const text = turn.accumulated.trim() || (turn.status === "error" ? "(crashed)" : "(no output)");
|
|
3651
|
+
const body = `${prefix} *${turn.taskName}*
|
|
3652
|
+
|
|
3653
|
+
${text}`.slice(0, 9e3);
|
|
3654
|
+
let threadId = this.taskThreads.get(turn.taskId);
|
|
3655
|
+
if (!threadId) {
|
|
3656
|
+
try {
|
|
3657
|
+
const created = await this.deps.chat.createThread(turn.roomId, turn.taskName || turn.taskId);
|
|
3658
|
+
threadId = created.id;
|
|
3659
|
+
this.taskThreads.set(turn.taskId, threadId);
|
|
3660
|
+
this.persistTaskThreads();
|
|
3661
|
+
this.deps.log(`task ${turn.taskId} thread created: ${threadId}`);
|
|
3662
|
+
} catch (err) {
|
|
3663
|
+
this.deps.log(`createThread failed for ${turn.taskId}, falling back to main thread: ${err instanceof Error ? err.message : String(err)}`);
|
|
3664
|
+
}
|
|
3665
|
+
}
|
|
3666
|
+
try {
|
|
3667
|
+
const posted = await this.deps.chat.postMessage(turn.roomId, body, threadId ? { threadId } : {});
|
|
3668
|
+
this.deps.log(`task DM posted (session=${sid}, ${turn.accumulated.length} chars, thread=${posted.threadId})`);
|
|
3669
|
+
} catch (err) {
|
|
3670
|
+
this.deps.log(`task DM post failed (session=${sid}): ${err instanceof Error ? err.message : String(err)}`);
|
|
3671
|
+
}
|
|
3672
|
+
}
|
|
3673
|
+
};
|
|
3674
|
+
|
|
3675
|
+
// src/identity.ts
|
|
3676
|
+
import { existsSync as existsSync5, readFileSync as readFileSync6 } from "fs";
|
|
3677
|
+
import { homedir as homedir7 } from "os";
|
|
3678
|
+
import { join as join7 } from "path";
|
|
3679
|
+
function authPath() {
|
|
3680
|
+
return join7(homedir7(), ".config", "apes", "auth.json");
|
|
3681
|
+
}
|
|
3682
|
+
function allowlistPath() {
|
|
3683
|
+
return join7(homedir7(), ".config", "openape", "bridge-allowlist.json");
|
|
3684
|
+
}
|
|
3685
|
+
function readAgentIdentity() {
|
|
3686
|
+
const path = authPath();
|
|
3687
|
+
if (!existsSync5(path)) {
|
|
3688
|
+
throw new Error(`agent identity not found at ${path}`);
|
|
3689
|
+
}
|
|
3690
|
+
const raw = readFileSync6(path, "utf8");
|
|
3691
|
+
const parsed = JSON.parse(raw);
|
|
3692
|
+
if (!parsed.email) throw new Error(`auth.json at ${path} missing 'email'`);
|
|
3693
|
+
if (!parsed.idp) throw new Error(`auth.json at ${path} missing 'idp'`);
|
|
3694
|
+
const ownerEmail = parsed.owner_email ?? process.env.OPENAPE_OWNER_EMAIL;
|
|
3695
|
+
if (!ownerEmail) {
|
|
3696
|
+
throw new Error(
|
|
3697
|
+
`auth.json at ${path} missing 'owner_email' and no OPENAPE_OWNER_EMAIL env var set \u2014 re-spawn the agent with @openape/apes >= 0.28 or add OPENAPE_OWNER_EMAIL to the launchd plist`
|
|
3698
|
+
);
|
|
3699
|
+
}
|
|
3700
|
+
return { email: parsed.email, ownerEmail, idp: parsed.idp };
|
|
3701
|
+
}
|
|
3702
|
+
function readAllowlist() {
|
|
3703
|
+
const path = allowlistPath();
|
|
3704
|
+
if (!existsSync5(path)) return /* @__PURE__ */ new Set();
|
|
3705
|
+
try {
|
|
3706
|
+
const parsed = JSON.parse(readFileSync6(path, "utf8"));
|
|
3707
|
+
if (!Array.isArray(parsed.emails)) return /* @__PURE__ */ new Set();
|
|
3708
|
+
return new Set(parsed.emails.map((e2) => e2.toLowerCase()));
|
|
3709
|
+
} catch {
|
|
3710
|
+
return /* @__PURE__ */ new Set();
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
function shouldAutoAccept(peerEmail, identity, allowlist) {
|
|
3714
|
+
const peer = peerEmail.toLowerCase();
|
|
3715
|
+
if (peer === identity.ownerEmail.toLowerCase()) return true;
|
|
3716
|
+
return allowlist.has(peer);
|
|
3717
|
+
}
|
|
3718
|
+
|
|
3719
|
+
// src/throttle.ts
|
|
3720
|
+
function createThrottle(fn, intervalMs) {
|
|
3721
|
+
let timer;
|
|
3722
|
+
let pendingFlush = false;
|
|
3723
|
+
let inFlight = false;
|
|
3724
|
+
const fire = async () => {
|
|
3725
|
+
if (inFlight) {
|
|
3726
|
+
pendingFlush = true;
|
|
3727
|
+
return;
|
|
3728
|
+
}
|
|
3729
|
+
inFlight = true;
|
|
3730
|
+
pendingFlush = false;
|
|
3731
|
+
try {
|
|
3732
|
+
await fn();
|
|
3733
|
+
} finally {
|
|
3734
|
+
inFlight = false;
|
|
3735
|
+
if (pendingFlush) {
|
|
3736
|
+
pendingFlush = false;
|
|
3737
|
+
await fn();
|
|
3738
|
+
}
|
|
3739
|
+
}
|
|
3740
|
+
};
|
|
3741
|
+
return {
|
|
3742
|
+
schedule() {
|
|
3743
|
+
if (timer) return;
|
|
3744
|
+
timer = setTimeout(() => {
|
|
3745
|
+
timer = void 0;
|
|
3746
|
+
void fire();
|
|
3747
|
+
}, intervalMs);
|
|
3748
|
+
},
|
|
3749
|
+
flush() {
|
|
3750
|
+
if (timer) {
|
|
3751
|
+
clearTimeout(timer);
|
|
3752
|
+
timer = void 0;
|
|
3753
|
+
}
|
|
3754
|
+
void fire();
|
|
3755
|
+
},
|
|
3756
|
+
cancel() {
|
|
3757
|
+
if (timer) {
|
|
3758
|
+
clearTimeout(timer);
|
|
3759
|
+
timer = void 0;
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3762
|
+
};
|
|
3763
|
+
}
|
|
3764
|
+
|
|
3765
|
+
// src/thread-session.ts
|
|
3766
|
+
var PATCH_INTERVAL_MS = 300;
|
|
3767
|
+
var ThreadSession = class {
|
|
3768
|
+
constructor(deps) {
|
|
3769
|
+
this.deps = deps;
|
|
3770
|
+
this.resolvedTools = taskTools(deps.tools);
|
|
3771
|
+
}
|
|
3772
|
+
active;
|
|
3773
|
+
queue = [];
|
|
3774
|
+
history = [];
|
|
3775
|
+
resolvedTools;
|
|
3776
|
+
/** No-op placeholder kept for API compatibility with the previous
|
|
3777
|
+
* RPC-listener model where dispose() detached the listener. */
|
|
3778
|
+
dispose() {
|
|
3779
|
+
}
|
|
3780
|
+
/** Forward an inbound chat message to the runtime. Queues if a turn is in flight. */
|
|
3781
|
+
enqueue(body, replyToMessageId) {
|
|
3782
|
+
if (this.active) {
|
|
3783
|
+
this.queue.push({ body, replyToMessageId });
|
|
3784
|
+
return;
|
|
3785
|
+
}
|
|
3786
|
+
void this.startTurn(body, replyToMessageId);
|
|
3787
|
+
}
|
|
3788
|
+
async startTurn(body, replyToMessageId) {
|
|
3789
|
+
const placeholder = await this.deps.chat.postMessage(this.deps.roomId, "\u2026", {
|
|
3790
|
+
replyTo: replyToMessageId,
|
|
3791
|
+
threadId: this.deps.threadId
|
|
3792
|
+
});
|
|
3793
|
+
const turn = {
|
|
3794
|
+
placeholderId: placeholder.id,
|
|
3795
|
+
accumulated: "",
|
|
3796
|
+
replyToMessageId,
|
|
3797
|
+
throttle: createThrottle(async () => {
|
|
3798
|
+
if (!this.active || this.active.placeholderId !== placeholder.id) return;
|
|
3799
|
+
const text = this.active.accumulated || "\u2026";
|
|
3800
|
+
try {
|
|
3801
|
+
await this.deps.chat.patchMessage(placeholder.id, text);
|
|
3802
|
+
} catch (err) {
|
|
3803
|
+
this.deps.log(`patch failed (room=${this.deps.roomId} thread=${this.deps.threadId}): ${err instanceof Error ? err.message : String(err)}`);
|
|
3804
|
+
}
|
|
3805
|
+
}, PATCH_INTERVAL_MS)
|
|
3806
|
+
};
|
|
3807
|
+
this.active = turn;
|
|
3808
|
+
try {
|
|
3809
|
+
const result = await runLoop({
|
|
3810
|
+
config: this.deps.runtimeConfig,
|
|
3811
|
+
systemPrompt: this.deps.systemPrompt,
|
|
3812
|
+
userMessage: body,
|
|
3813
|
+
tools: this.resolvedTools,
|
|
3814
|
+
maxSteps: this.deps.maxSteps,
|
|
3815
|
+
history: this.history,
|
|
3816
|
+
handlers: {
|
|
3817
|
+
onTextDelta: (delta) => {
|
|
3818
|
+
if (!this.active) return;
|
|
3819
|
+
this.active.accumulated += delta;
|
|
3820
|
+
this.active.throttle.schedule();
|
|
3821
|
+
},
|
|
3822
|
+
onToolCall: ({ name }) => {
|
|
3823
|
+
this.deps.log(`[${this.deps.roomId}/${this.deps.threadId.slice(0, 8)}] tool_call: ${name}`);
|
|
3824
|
+
},
|
|
3825
|
+
onToolResult: ({ name }) => {
|
|
3826
|
+
this.deps.log(`[${this.deps.roomId}/${this.deps.threadId.slice(0, 8)}] tool_result: ${name}`);
|
|
3827
|
+
},
|
|
3828
|
+
onToolError: ({ name, error }) => {
|
|
3829
|
+
this.deps.log(`[${this.deps.roomId}/${this.deps.threadId.slice(0, 8)}] tool_error: ${name} \u2192 ${error}`);
|
|
3830
|
+
}
|
|
3831
|
+
}
|
|
3832
|
+
});
|
|
3833
|
+
this.history.push({ role: "user", content: body });
|
|
3834
|
+
if (result.finalMessage) {
|
|
3835
|
+
this.history.push({ role: "assistant", content: result.finalMessage });
|
|
3836
|
+
}
|
|
3837
|
+
if (result.status === "error") {
|
|
3838
|
+
this.deps.log(`runtime done with status=error (room=${this.deps.roomId} thread=${this.deps.threadId})`);
|
|
3839
|
+
}
|
|
3840
|
+
this.endTurn();
|
|
3841
|
+
} catch (err) {
|
|
3842
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
3843
|
+
this.deps.log(`runtime error (room=${this.deps.roomId} thread=${this.deps.threadId}): ${message}`);
|
|
3844
|
+
this.failTurn(`(runtime error: ${message})`);
|
|
3845
|
+
}
|
|
3846
|
+
}
|
|
3847
|
+
endTurn() {
|
|
3848
|
+
const turn = this.active;
|
|
3849
|
+
if (!turn) return;
|
|
3850
|
+
turn.throttle.flush();
|
|
3851
|
+
this.active = void 0;
|
|
3852
|
+
const next = this.queue.shift();
|
|
3853
|
+
if (next) {
|
|
3854
|
+
void this.startTurn(next.body, next.replyToMessageId);
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
failTurn(message) {
|
|
3858
|
+
const turn = this.active;
|
|
3859
|
+
if (!turn) return;
|
|
3860
|
+
turn.accumulated = message;
|
|
3861
|
+
turn.throttle.flush();
|
|
3862
|
+
this.active = void 0;
|
|
3863
|
+
const next = this.queue.shift();
|
|
3864
|
+
if (next) {
|
|
3865
|
+
void this.startTurn(next.body, next.replyToMessageId);
|
|
3866
|
+
}
|
|
3867
|
+
}
|
|
3868
|
+
};
|
|
3869
|
+
|
|
3870
|
+
// src/bridge.ts
|
|
3871
|
+
var AGENT_CONFIG_PATH2 = join8(homedir8(), ".openape", "agent", "agent.json");
|
|
3872
|
+
function resolveSystemPrompt(envFallback) {
|
|
3873
|
+
if (!existsSync6(AGENT_CONFIG_PATH2)) return envFallback;
|
|
3874
|
+
try {
|
|
3875
|
+
const parsed = JSON.parse(readFileSync7(AGENT_CONFIG_PATH2, "utf8"));
|
|
3876
|
+
return typeof parsed.systemPrompt === "string" ? parsed.systemPrompt : envFallback;
|
|
3877
|
+
} catch {
|
|
3878
|
+
return envFallback;
|
|
3879
|
+
}
|
|
3880
|
+
}
|
|
3881
|
+
function resolveTools(envFallback) {
|
|
3882
|
+
if (existsSync6(AGENT_CONFIG_PATH2)) {
|
|
3883
|
+
try {
|
|
3884
|
+
const parsed = JSON.parse(readFileSync7(AGENT_CONFIG_PATH2, "utf8"));
|
|
3885
|
+
if (Array.isArray(parsed.tools)) {
|
|
3886
|
+
return parsed.tools.filter((t2) => typeof t2 === "string");
|
|
3887
|
+
}
|
|
3888
|
+
} catch {
|
|
3889
|
+
}
|
|
3890
|
+
}
|
|
3891
|
+
return envFallback;
|
|
3892
|
+
}
|
|
3893
|
+
var DEFAULT_ENDPOINT = "https://chat.openape.ai";
|
|
3894
|
+
var DEFAULT_APES_BIN = "apes";
|
|
3895
|
+
var DEFAULT_MAX_STEPS = 10;
|
|
3896
|
+
var DEFAULT_SYSTEM_PROMPT = `You are a helpful assistant in a 1:1 chat. Be concise and friendly. When asked for facts, say "I don't know" rather than guess.`;
|
|
3897
|
+
var PING_INTERVAL_MS = 3e4;
|
|
3898
|
+
var RECONNECT_BASE_MS = 1e3;
|
|
3899
|
+
var RECONNECT_MAX_MS = 3e4;
|
|
3900
|
+
var ALLOWLIST_POLL_INTERVAL_MS = 3e4;
|
|
3901
|
+
function loadBridgeEnvFile() {
|
|
3902
|
+
const path = join8(homedir8(), "Library", "Application Support", "openape", "bridge", ".env");
|
|
3903
|
+
if (!existsSync6(path)) return;
|
|
3904
|
+
try {
|
|
3905
|
+
const raw = readFileSync7(path, "utf8");
|
|
3906
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
3907
|
+
const trimmed = line.trim();
|
|
3908
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
3909
|
+
const eq = trimmed.indexOf("=");
|
|
3910
|
+
if (eq < 0) continue;
|
|
3911
|
+
const key = trimmed.slice(0, eq).trim();
|
|
3912
|
+
const value = trimmed.slice(eq + 1).trim().replace(/^["']|["']$/g, "");
|
|
3913
|
+
if (!key) continue;
|
|
3914
|
+
if (process2.env[key] === void 0) {
|
|
3915
|
+
process2.env[key] = value;
|
|
3916
|
+
}
|
|
3917
|
+
}
|
|
3918
|
+
} catch {
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
function readConfig() {
|
|
3922
|
+
loadBridgeEnvFile();
|
|
3923
|
+
const toolsRaw = process2.env.APE_CHAT_BRIDGE_TOOLS ?? "";
|
|
3924
|
+
const tools = toolsRaw.split(",").map((s2) => s2.trim()).filter(Boolean);
|
|
3925
|
+
const maxStepsRaw = process2.env.APE_CHAT_BRIDGE_MAX_STEPS;
|
|
3926
|
+
const maxSteps = maxStepsRaw ? Number.parseInt(maxStepsRaw, 10) : DEFAULT_MAX_STEPS;
|
|
3927
|
+
const model = process2.env.APE_CHAT_BRIDGE_MODEL;
|
|
3928
|
+
if (!model) {
|
|
3929
|
+
throw new Error(
|
|
3930
|
+
"APE_CHAT_BRIDGE_MODEL is not set. Set it in the bridge .env (usually `~/Library/Application Support/openape/bridge/.env` on macOS) or globally in `~/litellm/.env` so resolveBridgeConfig picks it up at spawn time. Common values: `gpt-5.4` (ChatGPT-only LiteLLM proxy), `claude-haiku-4-5` (Anthropic-only)."
|
|
3931
|
+
);
|
|
3932
|
+
}
|
|
3933
|
+
return {
|
|
3934
|
+
endpoint: (process2.env.APE_CHAT_ENDPOINT ?? DEFAULT_ENDPOINT).replace(/\/$/, ""),
|
|
3935
|
+
apesBin: process2.env.APE_CHAT_BRIDGE_APES_BIN ?? DEFAULT_APES_BIN,
|
|
3936
|
+
model,
|
|
3937
|
+
systemPrompt: process2.env.APE_CHAT_BRIDGE_SYSTEM_PROMPT ?? DEFAULT_SYSTEM_PROMPT,
|
|
3938
|
+
tools,
|
|
3939
|
+
maxSteps: Number.isFinite(maxSteps) && maxSteps > 0 ? maxSteps : DEFAULT_MAX_STEPS,
|
|
3940
|
+
roomFilter: process2.env.APE_CHAT_BRIDGE_ROOM
|
|
3941
|
+
};
|
|
3942
|
+
}
|
|
3943
|
+
async function getIdentity() {
|
|
3944
|
+
const idp = await ensureFreshIdpAuth();
|
|
3945
|
+
const claims = decodeJwt(idp.access_token);
|
|
3946
|
+
if (!claims.sub) {
|
|
3947
|
+
throw new NotLoggedInError("IdP token has no sub claim \u2014 re-run `apes login` for this user.");
|
|
3948
|
+
}
|
|
3949
|
+
return { email: claims.sub };
|
|
3950
|
+
}
|
|
3951
|
+
function log(line) {
|
|
3952
|
+
process2.stderr.write(`${(/* @__PURE__ */ new Date()).toISOString()} ${line}
|
|
3953
|
+
`);
|
|
3954
|
+
}
|
|
3955
|
+
function sleep(ms) {
|
|
3956
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
3957
|
+
}
|
|
3958
|
+
function truncate(s2, n2) {
|
|
3959
|
+
return s2.length <= n2 ? s2 : `${s2.slice(0, n2 - 1)}\u2026`;
|
|
3960
|
+
}
|
|
3961
|
+
var Bridge = class {
|
|
3962
|
+
constructor(cfg, selfEmail, ownerEmail) {
|
|
3963
|
+
this.cfg = cfg;
|
|
3964
|
+
this.selfEmail = selfEmail;
|
|
3965
|
+
this.ownerEmail = ownerEmail;
|
|
3966
|
+
this.bearer = async () => {
|
|
3967
|
+
const idp = await ensureFreshIdpAuth();
|
|
3968
|
+
return `Bearer ${idp.access_token}`;
|
|
3969
|
+
};
|
|
3970
|
+
this.chat = new ChatApi(this.cfg.endpoint, this.bearer);
|
|
3971
|
+
this.cron = new CronRunner({
|
|
3972
|
+
runtimeConfig: this.runtimeConfig(),
|
|
3973
|
+
chat: this.chat,
|
|
3974
|
+
ownerEmail: this.ownerEmail,
|
|
3975
|
+
log,
|
|
3976
|
+
troopUrl: (process2.env.OPENAPE_TROOP_URL ?? "https://troop.openape.ai").replace(/\/$/, ""),
|
|
3977
|
+
bearer: this.bearer
|
|
3978
|
+
});
|
|
3979
|
+
this.cron.start();
|
|
3980
|
+
}
|
|
3981
|
+
// Sessions keyed by `${roomId}:${threadId}`. Each ThreadSession holds
|
|
3982
|
+
// its own message history and calls @openape/apes' runLoop directly
|
|
3983
|
+
// (no stdio JSON-RPC subprocess — see thread-session.ts).
|
|
3984
|
+
threads = /* @__PURE__ */ new Map();
|
|
3985
|
+
chat;
|
|
3986
|
+
bearer;
|
|
3987
|
+
cron;
|
|
3988
|
+
/**
|
|
3989
|
+
* RuntimeConfig is shared across thread sessions and the cron runner.
|
|
3990
|
+
* The bridge resolves it from its own env at boot and reuses for the
|
|
3991
|
+
* whole process lifetime.
|
|
3992
|
+
*/
|
|
3993
|
+
runtimeConfig() {
|
|
3994
|
+
const apiBase = (process2.env.LITELLM_BASE_URL ?? "http://127.0.0.1:4000/v1").replace(/\/$/, "");
|
|
3995
|
+
const apiKey = process2.env.LITELLM_API_KEY ?? process2.env.LITELLM_MASTER_KEY ?? "";
|
|
3996
|
+
if (!apiKey) {
|
|
3997
|
+
throw new Error("LITELLM_API_KEY (or LITELLM_MASTER_KEY) must be set in the bridge env.");
|
|
3998
|
+
}
|
|
3999
|
+
return { apiBase, apiKey, model: this.cfg.model };
|
|
4000
|
+
}
|
|
4001
|
+
async sendInitialOwnerRequestIfNeeded() {
|
|
4002
|
+
const contacts = await this.chat.listContacts();
|
|
4003
|
+
const ownerLower = this.ownerEmail.toLowerCase();
|
|
4004
|
+
const existing = contacts.find((c3) => c3.peerEmail.toLowerCase() === ownerLower);
|
|
4005
|
+
if (existing) return;
|
|
4006
|
+
log(`sending initial contact request to owner ${this.ownerEmail}`);
|
|
4007
|
+
try {
|
|
4008
|
+
await this.chat.requestContact(this.ownerEmail);
|
|
4009
|
+
} catch (err) {
|
|
4010
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
4011
|
+
log(`could not send initial request to ${this.ownerEmail}: ${msg}`);
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
async acceptAllowedPendingContacts() {
|
|
4015
|
+
const contacts = await this.chat.listContacts();
|
|
4016
|
+
const pending = contacts.filter((c3) => c3.myStatus === "pending");
|
|
4017
|
+
if (pending.length === 0) return;
|
|
4018
|
+
const allowlist = readAllowlist();
|
|
4019
|
+
const identity = { email: this.selfEmail, ownerEmail: this.ownerEmail, idp: "" };
|
|
4020
|
+
const accepted = [];
|
|
4021
|
+
const skipped = [];
|
|
4022
|
+
for (const c3 of pending) {
|
|
4023
|
+
if (!shouldAutoAccept(c3.peerEmail, identity, allowlist)) {
|
|
4024
|
+
skipped.push(c3.peerEmail);
|
|
4025
|
+
continue;
|
|
4026
|
+
}
|
|
4027
|
+
try {
|
|
4028
|
+
await this.chat.acceptContact(c3.peerEmail);
|
|
4029
|
+
accepted.push(c3.peerEmail);
|
|
4030
|
+
} catch (err) {
|
|
4031
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
4032
|
+
log(`failed to accept ${c3.peerEmail}: ${msg}`);
|
|
4033
|
+
}
|
|
4034
|
+
}
|
|
4035
|
+
if (accepted.length > 0) log(`accepted: ${accepted.join(", ")}`);
|
|
4036
|
+
if (skipped.length > 0) log(`skipped (not on allowlist): ${skipped.join(", ")}`);
|
|
4037
|
+
}
|
|
4038
|
+
handleInbound(msg) {
|
|
4039
|
+
if (msg.senderEmail === this.selfEmail) return;
|
|
4040
|
+
if (!msg.body.trim()) return;
|
|
4041
|
+
if (this.cfg.roomFilter && msg.roomId !== this.cfg.roomFilter) return;
|
|
4042
|
+
if (!msg.threadId) {
|
|
4043
|
+
log(`[${msg.roomId}] dropping message ${msg.id} without threadId \u2014 server too old?`);
|
|
4044
|
+
return;
|
|
4045
|
+
}
|
|
4046
|
+
log(`[${msg.roomId}/${msg.threadId.slice(0, 8)}] in: ${truncate(msg.body, 80)}`);
|
|
4047
|
+
const session = this.getOrCreateThread(msg.roomId, msg.threadId);
|
|
4048
|
+
session.enqueue(msg.body, msg.id);
|
|
4049
|
+
}
|
|
4050
|
+
getOrCreateThread(roomId, threadId) {
|
|
4051
|
+
const key = `${roomId}:${threadId}`;
|
|
4052
|
+
let s2 = this.threads.get(key);
|
|
4053
|
+
if (s2) return s2;
|
|
4054
|
+
s2 = new ThreadSession({
|
|
4055
|
+
roomId,
|
|
4056
|
+
threadId,
|
|
4057
|
+
chat: this.chat,
|
|
4058
|
+
runtimeConfig: this.runtimeConfig(),
|
|
4059
|
+
systemPrompt: resolveSystemPrompt(this.cfg.systemPrompt),
|
|
4060
|
+
// Tools resolve from agent.json (latest sync from troop) on
|
|
4061
|
+
// every new thread, so owner edits in the troop UI take
|
|
4062
|
+
// effect after the next sync without a bridge restart.
|
|
4063
|
+
tools: resolveTools(this.cfg.tools),
|
|
4064
|
+
maxSteps: this.cfg.maxSteps,
|
|
4065
|
+
log
|
|
4066
|
+
});
|
|
4067
|
+
this.threads.set(key, s2);
|
|
4068
|
+
return s2;
|
|
4069
|
+
}
|
|
4070
|
+
async pumpOnce() {
|
|
4071
|
+
const bearer = await this.bearer();
|
|
4072
|
+
const wsUrl = `${this.cfg.endpoint.replace(/^http/, "ws")}/api/ws?token=${encodeURIComponent(bearer.replace(/^Bearer\s+/i, ""))}`;
|
|
4073
|
+
const ws = new WebSocket(wsUrl);
|
|
4074
|
+
return new Promise((resolve2, reject) => {
|
|
4075
|
+
let pingTimer;
|
|
4076
|
+
let allowlistTimer;
|
|
4077
|
+
ws.on("open", () => {
|
|
4078
|
+
log(`connected as ${this.selfEmail} \u2192 ${this.cfg.endpoint}`);
|
|
4079
|
+
pingTimer = setInterval(() => ws.ping(), PING_INTERVAL_MS);
|
|
4080
|
+
void this.sendInitialOwnerRequestIfNeeded().catch((err) => {
|
|
4081
|
+
log(`initial owner request failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
4082
|
+
});
|
|
4083
|
+
void this.acceptAllowedPendingContacts().catch((err) => {
|
|
4084
|
+
log(`accept-pending-contacts failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
4085
|
+
});
|
|
4086
|
+
allowlistTimer = setInterval(() => {
|
|
4087
|
+
void this.acceptAllowedPendingContacts().catch((err) => {
|
|
4088
|
+
log(`allowlist re-poll failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
4089
|
+
});
|
|
4090
|
+
}, ALLOWLIST_POLL_INTERVAL_MS);
|
|
4091
|
+
});
|
|
4092
|
+
ws.on("message", (data) => {
|
|
4093
|
+
const text = typeof data === "string" ? data : Buffer.isBuffer(data) ? data.toString("utf8") : "";
|
|
4094
|
+
if (!text) return;
|
|
4095
|
+
let frame;
|
|
4096
|
+
try {
|
|
4097
|
+
frame = JSON.parse(text);
|
|
4098
|
+
} catch {
|
|
4099
|
+
return;
|
|
4100
|
+
}
|
|
4101
|
+
if (frame.type !== "message") return;
|
|
4102
|
+
this.handleInbound(frame.payload);
|
|
4103
|
+
});
|
|
4104
|
+
ws.on("close", () => {
|
|
4105
|
+
if (pingTimer) clearInterval(pingTimer);
|
|
4106
|
+
if (allowlistTimer) clearInterval(allowlistTimer);
|
|
4107
|
+
resolve2();
|
|
4108
|
+
});
|
|
4109
|
+
ws.on("error", (err) => {
|
|
4110
|
+
if (pingTimer) clearInterval(pingTimer);
|
|
4111
|
+
if (allowlistTimer) clearInterval(allowlistTimer);
|
|
4112
|
+
reject(err);
|
|
4113
|
+
});
|
|
4114
|
+
});
|
|
4115
|
+
}
|
|
4116
|
+
};
|
|
4117
|
+
async function main() {
|
|
4118
|
+
const cfg = readConfig();
|
|
4119
|
+
const idpId = await getIdentity();
|
|
4120
|
+
const onDisk = readAgentIdentity();
|
|
4121
|
+
if (onDisk.email.toLowerCase() !== idpId.email.toLowerCase()) {
|
|
4122
|
+
throw new Error(
|
|
4123
|
+
`auth.json email (${onDisk.email}) doesn't match IdP token sub (${idpId.email}) \u2014 refusing to start`
|
|
4124
|
+
);
|
|
4125
|
+
}
|
|
4126
|
+
log(
|
|
4127
|
+
`bridge starting \u2014 agent=${onDisk.email} owner=${onDisk.ownerEmail} apes=${cfg.apesBin} model=${cfg.model} tools=[${cfg.tools.join(",") || "none"}] max_steps=${cfg.maxSteps} room=${cfg.roomFilter ?? "*"}`
|
|
4128
|
+
);
|
|
4129
|
+
const bridge = new Bridge(cfg, onDisk.email, onDisk.ownerEmail);
|
|
4130
|
+
let attempt = 0;
|
|
4131
|
+
while (true) {
|
|
4132
|
+
try {
|
|
4133
|
+
await bridge.pumpOnce();
|
|
4134
|
+
attempt = 0;
|
|
4135
|
+
} catch (err) {
|
|
4136
|
+
const delay = Math.min(RECONNECT_BASE_MS * 2 ** attempt, RECONNECT_MAX_MS);
|
|
4137
|
+
attempt++;
|
|
4138
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
4139
|
+
log(`disconnected (${msg}) \u2014 reconnecting in ${Math.round(delay / 1e3)}s`);
|
|
4140
|
+
await sleep(delay);
|
|
4141
|
+
}
|
|
4142
|
+
}
|
|
4143
|
+
}
|
|
4144
|
+
main().catch((err) => {
|
|
4145
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
4146
|
+
process2.stderr.write(`fatal: ${msg}
|
|
4147
|
+
`);
|
|
4148
|
+
process2.exit(1);
|
|
4149
|
+
});
|