@stamn/stamn-plugin 0.1.0-alpha.0 → 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,12 +1,1273 @@
1
- // src/register.ts
2
- import { handleLogin, handleConfig, handleStatus, handleUninstall } from "@stamn/cli";
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
3
26
 
4
- // src/config.ts
27
+ // ../stamn-cli/node_modules/picocolors/picocolors.js
28
+ var require_picocolors = __commonJS({
29
+ "../stamn-cli/node_modules/picocolors/picocolors.js"(exports, module) {
30
+ "use strict";
31
+ var p = process || {};
32
+ var argv = p.argv || [];
33
+ var env = p.env || {};
34
+ var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
35
+ var formatter = (open, close, replace = open) => (input) => {
36
+ let string = "" + input, index = string.indexOf(close, open.length);
37
+ return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
38
+ };
39
+ var replaceClose = (string, close, replace, index) => {
40
+ let result = "", cursor = 0;
41
+ do {
42
+ result += string.substring(cursor, index) + replace;
43
+ cursor = index + close.length;
44
+ index = string.indexOf(close, cursor);
45
+ } while (~index);
46
+ return result + string.substring(cursor);
47
+ };
48
+ var createColors = (enabled = isColorSupported) => {
49
+ let f = enabled ? formatter : () => String;
50
+ return {
51
+ isColorSupported: enabled,
52
+ reset: f("\x1B[0m", "\x1B[0m"),
53
+ bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
54
+ dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
55
+ italic: f("\x1B[3m", "\x1B[23m"),
56
+ underline: f("\x1B[4m", "\x1B[24m"),
57
+ inverse: f("\x1B[7m", "\x1B[27m"),
58
+ hidden: f("\x1B[8m", "\x1B[28m"),
59
+ strikethrough: f("\x1B[9m", "\x1B[29m"),
60
+ black: f("\x1B[30m", "\x1B[39m"),
61
+ red: f("\x1B[31m", "\x1B[39m"),
62
+ green: f("\x1B[32m", "\x1B[39m"),
63
+ yellow: f("\x1B[33m", "\x1B[39m"),
64
+ blue: f("\x1B[34m", "\x1B[39m"),
65
+ magenta: f("\x1B[35m", "\x1B[39m"),
66
+ cyan: f("\x1B[36m", "\x1B[39m"),
67
+ white: f("\x1B[37m", "\x1B[39m"),
68
+ gray: f("\x1B[90m", "\x1B[39m"),
69
+ bgBlack: f("\x1B[40m", "\x1B[49m"),
70
+ bgRed: f("\x1B[41m", "\x1B[49m"),
71
+ bgGreen: f("\x1B[42m", "\x1B[49m"),
72
+ bgYellow: f("\x1B[43m", "\x1B[49m"),
73
+ bgBlue: f("\x1B[44m", "\x1B[49m"),
74
+ bgMagenta: f("\x1B[45m", "\x1B[49m"),
75
+ bgCyan: f("\x1B[46m", "\x1B[49m"),
76
+ bgWhite: f("\x1B[47m", "\x1B[49m"),
77
+ blackBright: f("\x1B[90m", "\x1B[39m"),
78
+ redBright: f("\x1B[91m", "\x1B[39m"),
79
+ greenBright: f("\x1B[92m", "\x1B[39m"),
80
+ yellowBright: f("\x1B[93m", "\x1B[39m"),
81
+ blueBright: f("\x1B[94m", "\x1B[39m"),
82
+ magentaBright: f("\x1B[95m", "\x1B[39m"),
83
+ cyanBright: f("\x1B[96m", "\x1B[39m"),
84
+ whiteBright: f("\x1B[97m", "\x1B[39m"),
85
+ bgBlackBright: f("\x1B[100m", "\x1B[49m"),
86
+ bgRedBright: f("\x1B[101m", "\x1B[49m"),
87
+ bgGreenBright: f("\x1B[102m", "\x1B[49m"),
88
+ bgYellowBright: f("\x1B[103m", "\x1B[49m"),
89
+ bgBlueBright: f("\x1B[104m", "\x1B[49m"),
90
+ bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
91
+ bgCyanBright: f("\x1B[106m", "\x1B[49m"),
92
+ bgWhiteBright: f("\x1B[107m", "\x1B[49m")
93
+ };
94
+ };
95
+ module.exports = createColors();
96
+ module.exports.createColors = createColors;
97
+ }
98
+ });
99
+
100
+ // ../stamn-cli/node_modules/sisteransi/src/index.js
101
+ var require_src = __commonJS({
102
+ "../stamn-cli/node_modules/sisteransi/src/index.js"(exports, module) {
103
+ "use strict";
104
+ var ESC = "\x1B";
105
+ var CSI = `${ESC}[`;
106
+ var beep = "\x07";
107
+ var cursor = {
108
+ to(x3, y2) {
109
+ if (!y2) return `${CSI}${x3 + 1}G`;
110
+ return `${CSI}${y2 + 1};${x3 + 1}H`;
111
+ },
112
+ move(x3, y2) {
113
+ let ret = "";
114
+ if (x3 < 0) ret += `${CSI}${-x3}D`;
115
+ else if (x3 > 0) ret += `${CSI}${x3}C`;
116
+ if (y2 < 0) ret += `${CSI}${-y2}A`;
117
+ else if (y2 > 0) ret += `${CSI}${y2}B`;
118
+ return ret;
119
+ },
120
+ up: (count = 1) => `${CSI}${count}A`,
121
+ down: (count = 1) => `${CSI}${count}B`,
122
+ forward: (count = 1) => `${CSI}${count}C`,
123
+ backward: (count = 1) => `${CSI}${count}D`,
124
+ nextLine: (count = 1) => `${CSI}E`.repeat(count),
125
+ prevLine: (count = 1) => `${CSI}F`.repeat(count),
126
+ left: `${CSI}G`,
127
+ hide: `${CSI}?25l`,
128
+ show: `${CSI}?25h`,
129
+ save: `${ESC}7`,
130
+ restore: `${ESC}8`
131
+ };
132
+ var scroll = {
133
+ up: (count = 1) => `${CSI}S`.repeat(count),
134
+ down: (count = 1) => `${CSI}T`.repeat(count)
135
+ };
136
+ var erase = {
137
+ screen: `${CSI}2J`,
138
+ up: (count = 1) => `${CSI}1J`.repeat(count),
139
+ down: (count = 1) => `${CSI}J`.repeat(count),
140
+ line: `${CSI}2K`,
141
+ lineEnd: `${CSI}K`,
142
+ lineStart: `${CSI}1K`,
143
+ lines(count) {
144
+ let clear = "";
145
+ for (let i = 0; i < count; i++)
146
+ clear += this.line + (i < count - 1 ? cursor.up() : "");
147
+ if (count)
148
+ clear += cursor.left;
149
+ return clear;
150
+ }
151
+ };
152
+ module.exports = { cursor, scroll, erase, beep };
153
+ }
154
+ });
155
+
156
+ // ../stamn-cli/node_modules/@clack/core/dist/index.mjs
157
+ var import_picocolors = __toESM(require_picocolors(), 1);
158
+ var import_sisteransi = __toESM(require_src(), 1);
159
+ import { stdout as R, stdin as q } from "process";
160
+ import * as k from "readline";
161
+ import ot from "readline";
162
+ import { ReadStream as J } from "tty";
163
+ var at = (t) => t === 161 || t === 164 || t === 167 || t === 168 || t === 170 || t === 173 || t === 174 || t >= 176 && t <= 180 || t >= 182 && t <= 186 || t >= 188 && t <= 191 || t === 198 || t === 208 || t === 215 || t === 216 || t >= 222 && t <= 225 || t === 230 || t >= 232 && t <= 234 || t === 236 || t === 237 || t === 240 || t === 242 || t === 243 || t >= 247 && t <= 250 || t === 252 || t === 254 || t === 257 || t === 273 || t === 275 || t === 283 || t === 294 || t === 295 || t === 299 || t >= 305 && t <= 307 || t === 312 || t >= 319 && t <= 322 || t === 324 || t >= 328 && t <= 331 || t === 333 || t === 338 || t === 339 || t === 358 || t === 359 || t === 363 || t === 462 || t === 464 || t === 466 || t === 468 || t === 470 || t === 472 || t === 474 || t === 476 || t === 593 || t === 609 || t === 708 || t === 711 || t >= 713 && t <= 715 || t === 717 || t === 720 || t >= 728 && t <= 731 || t === 733 || t === 735 || t >= 768 && t <= 879 || t >= 913 && t <= 929 || t >= 931 && t <= 937 || t >= 945 && t <= 961 || t >= 963 && t <= 969 || t === 1025 || t >= 1040 && t <= 1103 || t === 1105 || t === 8208 || t >= 8211 && t <= 8214 || t === 8216 || t === 8217 || t === 8220 || t === 8221 || t >= 8224 && t <= 8226 || t >= 8228 && t <= 8231 || t === 8240 || t === 8242 || t === 8243 || t === 8245 || t === 8251 || t === 8254 || t === 8308 || t === 8319 || t >= 8321 && t <= 8324 || t === 8364 || t === 8451 || t === 8453 || t === 8457 || t === 8467 || t === 8470 || t === 8481 || t === 8482 || t === 8486 || t === 8491 || t === 8531 || t === 8532 || t >= 8539 && t <= 8542 || t >= 8544 && t <= 8555 || t >= 8560 && t <= 8569 || t === 8585 || t >= 8592 && t <= 8601 || t === 8632 || t === 8633 || t === 8658 || t === 8660 || t === 8679 || t === 8704 || t === 8706 || t === 8707 || t === 8711 || t === 8712 || t === 8715 || t === 8719 || t === 8721 || t === 8725 || t === 8730 || t >= 8733 && t <= 8736 || t === 8739 || t === 8741 || t >= 8743 && t <= 8748 || t === 8750 || t >= 8756 && t <= 8759 || t === 8764 || t === 8765 || t === 8776 || t === 8780 || t === 8786 || t === 8800 || t === 8801 || t >= 8804 && t <= 8807 || t === 8810 || t === 8811 || t === 8814 || t === 8815 || t === 8834 || t === 8835 || t === 8838 || t === 8839 || t === 8853 || t === 8857 || t === 8869 || t === 8895 || t === 8978 || t >= 9312 && t <= 9449 || t >= 9451 && t <= 9547 || t >= 9552 && t <= 9587 || t >= 9600 && t <= 9615 || t >= 9618 && t <= 9621 || t === 9632 || t === 9633 || t >= 9635 && t <= 9641 || t === 9650 || t === 9651 || t === 9654 || t === 9655 || t === 9660 || t === 9661 || t === 9664 || t === 9665 || t >= 9670 && t <= 9672 || t === 9675 || t >= 9678 && t <= 9681 || t >= 9698 && t <= 9701 || t === 9711 || t === 9733 || t === 9734 || t === 9737 || t === 9742 || t === 9743 || t === 9756 || t === 9758 || t === 9792 || t === 9794 || t === 9824 || t === 9825 || t >= 9827 && t <= 9829 || t >= 9831 && t <= 9834 || t === 9836 || t === 9837 || t === 9839 || t === 9886 || t === 9887 || t === 9919 || t >= 9926 && t <= 9933 || t >= 9935 && t <= 9939 || t >= 9941 && t <= 9953 || t === 9955 || t === 9960 || t === 9961 || t >= 9963 && t <= 9969 || t === 9972 || t >= 9974 && t <= 9977 || t === 9979 || t === 9980 || t === 9982 || t === 9983 || t === 10045 || t >= 10102 && t <= 10111 || t >= 11094 && t <= 11097 || t >= 12872 && t <= 12879 || t >= 57344 && t <= 63743 || t >= 65024 && t <= 65039 || t === 65533 || t >= 127232 && t <= 127242 || t >= 127248 && t <= 127277 || t >= 127280 && t <= 127337 || t >= 127344 && t <= 127373 || t === 127375 || t === 127376 || t >= 127387 && t <= 127404 || t >= 917760 && t <= 917999 || t >= 983040 && t <= 1048573 || t >= 1048576 && t <= 1114109;
164
+ var lt = (t) => t === 12288 || t >= 65281 && t <= 65376 || t >= 65504 && t <= 65510;
165
+ var ht = (t) => t >= 4352 && t <= 4447 || t === 8986 || t === 8987 || t === 9001 || t === 9002 || t >= 9193 && t <= 9196 || t === 9200 || t === 9203 || t === 9725 || t === 9726 || t === 9748 || t === 9749 || t >= 9800 && t <= 9811 || t === 9855 || t === 9875 || t === 9889 || t === 9898 || t === 9899 || t === 9917 || t === 9918 || t === 9924 || t === 9925 || t === 9934 || t === 9940 || t === 9962 || t === 9970 || t === 9971 || t === 9973 || t === 9978 || t === 9981 || t === 9989 || t === 9994 || t === 9995 || t === 10024 || t === 10060 || t === 10062 || t >= 10067 && t <= 10069 || t === 10071 || t >= 10133 && t <= 10135 || t === 10160 || t === 10175 || t === 11035 || t === 11036 || t === 11088 || t === 11093 || t >= 11904 && t <= 11929 || t >= 11931 && t <= 12019 || t >= 12032 && t <= 12245 || t >= 12272 && t <= 12287 || t >= 12289 && t <= 12350 || t >= 12353 && t <= 12438 || t >= 12441 && t <= 12543 || t >= 12549 && t <= 12591 || t >= 12593 && t <= 12686 || t >= 12688 && t <= 12771 || t >= 12783 && t <= 12830 || t >= 12832 && t <= 12871 || t >= 12880 && t <= 19903 || t >= 19968 && t <= 42124 || t >= 42128 && t <= 42182 || t >= 43360 && t <= 43388 || t >= 44032 && t <= 55203 || t >= 63744 && t <= 64255 || t >= 65040 && t <= 65049 || t >= 65072 && t <= 65106 || t >= 65108 && t <= 65126 || t >= 65128 && t <= 65131 || t >= 94176 && t <= 94180 || t === 94192 || t === 94193 || t >= 94208 && t <= 100343 || t >= 100352 && t <= 101589 || t >= 101632 && t <= 101640 || t >= 110576 && t <= 110579 || t >= 110581 && t <= 110587 || t === 110589 || t === 110590 || t >= 110592 && t <= 110882 || t === 110898 || t >= 110928 && t <= 110930 || t === 110933 || t >= 110948 && t <= 110951 || t >= 110960 && t <= 111355 || t === 126980 || t === 127183 || t === 127374 || t >= 127377 && t <= 127386 || t >= 127488 && t <= 127490 || t >= 127504 && t <= 127547 || t >= 127552 && t <= 127560 || t === 127568 || t === 127569 || t >= 127584 && t <= 127589 || t >= 127744 && t <= 127776 || t >= 127789 && t <= 127797 || t >= 127799 && t <= 127868 || t >= 127870 && t <= 127891 || t >= 127904 && t <= 127946 || t >= 127951 && t <= 127955 || t >= 127968 && t <= 127984 || t === 127988 || t >= 127992 && t <= 128062 || t === 128064 || t >= 128066 && t <= 128252 || t >= 128255 && t <= 128317 || t >= 128331 && t <= 128334 || t >= 128336 && t <= 128359 || t === 128378 || t === 128405 || t === 128406 || t === 128420 || t >= 128507 && t <= 128591 || t >= 128640 && t <= 128709 || t === 128716 || t >= 128720 && t <= 128722 || t >= 128725 && t <= 128727 || t >= 128732 && t <= 128735 || t === 128747 || t === 128748 || t >= 128756 && t <= 128764 || t >= 128992 && t <= 129003 || t === 129008 || t >= 129292 && t <= 129338 || t >= 129340 && t <= 129349 || t >= 129351 && t <= 129535 || t >= 129648 && t <= 129660 || t >= 129664 && t <= 129672 || t >= 129680 && t <= 129725 || t >= 129727 && t <= 129733 || t >= 129742 && t <= 129755 || t >= 129760 && t <= 129768 || t >= 129776 && t <= 129784 || t >= 131072 && t <= 196605 || t >= 196608 && t <= 262141;
166
+ var O = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
167
+ var y = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
168
+ var L = /\t{1,1000}/y;
169
+ var P = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
170
+ var M = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
171
+ var ct = /\p{M}+/gu;
172
+ var ft = { limit: 1 / 0, ellipsis: "" };
173
+ var X = (t, e2 = {}, s = {}) => {
174
+ const i = e2.limit ?? 1 / 0, r = e2.ellipsis ?? "", n = e2?.ellipsisWidth ?? (r ? X(r, ft, s).width : 0), u = s.ansiWidth ?? 0, a = s.controlWidth ?? 0, l = s.tabWidth ?? 8, E = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, m = s.fullWidthWidth ?? 2, A = s.regularWidth ?? 1, V2 = s.wideWidth ?? 2;
175
+ let h = 0, o = 0, p = t.length, v = 0, F = false, d2 = p, b = Math.max(0, i - n), C2 = 0, w = 0, c = 0, f = 0;
176
+ t: for (; ; ) {
177
+ if (w > C2 || o >= p && o > h) {
178
+ const ut2 = t.slice(C2, w) || t.slice(h, o);
179
+ v = 0;
180
+ for (const Y of ut2.replaceAll(ct, "")) {
181
+ const $ = Y.codePointAt(0) || 0;
182
+ if (lt($) ? f = m : ht($) ? f = V2 : E !== A && at($) ? f = E : f = A, c + f > b && (d2 = Math.min(d2, Math.max(C2, h) + v)), c + f > i) {
183
+ F = true;
184
+ break t;
185
+ }
186
+ v += Y.length, c += f;
187
+ }
188
+ C2 = w = 0;
189
+ }
190
+ if (o >= p) break;
191
+ if (M.lastIndex = o, M.test(t)) {
192
+ if (v = M.lastIndex - o, f = v * A, c + f > b && (d2 = Math.min(d2, o + Math.floor((b - c) / A))), c + f > i) {
193
+ F = true;
194
+ break;
195
+ }
196
+ c += f, C2 = h, w = o, o = h = M.lastIndex;
197
+ continue;
198
+ }
199
+ if (O.lastIndex = o, O.test(t)) {
200
+ if (c + u > b && (d2 = Math.min(d2, o)), c + u > i) {
201
+ F = true;
202
+ break;
203
+ }
204
+ c += u, C2 = h, w = o, o = h = O.lastIndex;
205
+ continue;
206
+ }
207
+ if (y.lastIndex = o, y.test(t)) {
208
+ if (v = y.lastIndex - o, f = v * a, c + f > b && (d2 = Math.min(d2, o + Math.floor((b - c) / a))), c + f > i) {
209
+ F = true;
210
+ break;
211
+ }
212
+ c += f, C2 = h, w = o, o = h = y.lastIndex;
213
+ continue;
214
+ }
215
+ if (L.lastIndex = o, L.test(t)) {
216
+ if (v = L.lastIndex - o, f = v * l, c + f > b && (d2 = Math.min(d2, o + Math.floor((b - c) / l))), c + f > i) {
217
+ F = true;
218
+ break;
219
+ }
220
+ c += f, C2 = h, w = o, o = h = L.lastIndex;
221
+ continue;
222
+ }
223
+ if (P.lastIndex = o, P.test(t)) {
224
+ if (c + g > b && (d2 = Math.min(d2, o)), c + g > i) {
225
+ F = true;
226
+ break;
227
+ }
228
+ c += g, C2 = h, w = o, o = h = P.lastIndex;
229
+ continue;
230
+ }
231
+ o += 1;
232
+ }
233
+ return { width: F ? b : c, index: F ? d2 : p, truncated: F, ellipsed: F && i >= n };
234
+ };
235
+ var pt = { limit: 1 / 0, ellipsis: "", ellipsisWidth: 0 };
236
+ var S = (t, e2 = {}) => X(t, pt, e2).width;
237
+ var W = "\x1B";
238
+ var Z = "\x9B";
239
+ var Ft = 39;
240
+ var j = "\x07";
241
+ var Q = "[";
242
+ var dt = "]";
243
+ var tt = "m";
244
+ var U = `${dt}8;;`;
245
+ var et = new RegExp(`(?:\\${Q}(?<code>\\d+)m|\\${U}(?<uri>.*)${j})`, "y");
246
+ var mt = (t) => {
247
+ if (t >= 30 && t <= 37 || t >= 90 && t <= 97) return 39;
248
+ if (t >= 40 && t <= 47 || t >= 100 && t <= 107) return 49;
249
+ if (t === 1 || t === 2) return 22;
250
+ if (t === 3) return 23;
251
+ if (t === 4) return 24;
252
+ if (t === 7) return 27;
253
+ if (t === 8) return 28;
254
+ if (t === 9) return 29;
255
+ if (t === 0) return 0;
256
+ };
257
+ var st = (t) => `${W}${Q}${t}${tt}`;
258
+ var it = (t) => `${W}${U}${t}${j}`;
259
+ var gt = (t) => t.map((e2) => S(e2));
260
+ var G = (t, e2, s) => {
261
+ const i = e2[Symbol.iterator]();
262
+ let r = false, n = false, u = t.at(-1), a = u === void 0 ? 0 : S(u), l = i.next(), E = i.next(), g = 0;
263
+ for (; !l.done; ) {
264
+ const m = l.value, A = S(m);
265
+ a + A <= s ? t[t.length - 1] += m : (t.push(m), a = 0), (m === W || m === Z) && (r = true, n = e2.startsWith(U, g + 1)), r ? n ? m === j && (r = false, n = false) : m === tt && (r = false) : (a += A, a === s && !E.done && (t.push(""), a = 0)), l = E, E = i.next(), g += m.length;
266
+ }
267
+ u = t.at(-1), !a && u !== void 0 && u.length > 0 && t.length > 1 && (t[t.length - 2] += t.pop());
268
+ };
269
+ var vt = (t) => {
270
+ const e2 = t.split(" ");
271
+ let s = e2.length;
272
+ for (; s > 0 && !(S(e2[s - 1]) > 0); ) s--;
273
+ return s === e2.length ? t : e2.slice(0, s).join(" ") + e2.slice(s).join("");
274
+ };
275
+ var Et = (t, e2, s = {}) => {
276
+ if (s.trim !== false && t.trim() === "") return "";
277
+ let i = "", r, n;
278
+ const u = t.split(" "), a = gt(u);
279
+ let l = [""];
280
+ for (const [h, o] of u.entries()) {
281
+ s.trim !== false && (l[l.length - 1] = (l.at(-1) ?? "").trimStart());
282
+ let p = S(l.at(-1) ?? "");
283
+ if (h !== 0 && (p >= e2 && (s.wordWrap === false || s.trim === false) && (l.push(""), p = 0), (p > 0 || s.trim === false) && (l[l.length - 1] += " ", p++)), s.hard && a[h] > e2) {
284
+ const v = e2 - p, F = 1 + Math.floor((a[h] - v - 1) / e2);
285
+ Math.floor((a[h] - 1) / e2) < F && l.push(""), G(l, o, e2);
286
+ continue;
287
+ }
288
+ if (p + a[h] > e2 && p > 0 && a[h] > 0) {
289
+ if (s.wordWrap === false && p < e2) {
290
+ G(l, o, e2);
291
+ continue;
292
+ }
293
+ l.push("");
294
+ }
295
+ if (p + a[h] > e2 && s.wordWrap === false) {
296
+ G(l, o, e2);
297
+ continue;
298
+ }
299
+ l[l.length - 1] += o;
300
+ }
301
+ s.trim !== false && (l = l.map((h) => vt(h)));
302
+ const E = l.join(`
303
+ `), g = E[Symbol.iterator]();
304
+ let m = g.next(), A = g.next(), V2 = 0;
305
+ for (; !m.done; ) {
306
+ const h = m.value, o = A.value;
307
+ if (i += h, h === W || h === Z) {
308
+ et.lastIndex = V2 + 1;
309
+ const F = et.exec(E)?.groups;
310
+ if (F?.code !== void 0) {
311
+ const d2 = Number.parseFloat(F.code);
312
+ r = d2 === Ft ? void 0 : d2;
313
+ } else F?.uri !== void 0 && (n = F.uri.length === 0 ? void 0 : F.uri);
314
+ }
315
+ const p = r ? mt(r) : void 0;
316
+ o === `
317
+ ` ? (n && (i += it("")), r && p && (i += st(p))) : h === `
318
+ ` && (r && p && (i += st(r)), n && (i += it(n))), V2 += h.length, m = A, A = g.next();
319
+ }
320
+ return i;
321
+ };
322
+ function K(t, e2, s) {
323
+ return String(t).normalize().replaceAll(`\r
324
+ `, `
325
+ `).split(`
326
+ `).map((i) => Et(i, e2, s)).join(`
327
+ `);
328
+ }
329
+ var At = ["up", "down", "left", "right", "space", "enter", "cancel"];
330
+ var _ = { actions: new Set(At), aliases: /* @__PURE__ */ new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["", "cancel"], ["escape", "cancel"]]), messages: { cancel: "Canceled", error: "Something went wrong" }, withGuide: true };
331
+ function H(t, e2) {
332
+ if (typeof t == "string") return _.aliases.get(t) === e2;
333
+ for (const s of t) if (s !== void 0 && H(s, e2)) return true;
334
+ return false;
335
+ }
336
+ function _t(t, e2) {
337
+ if (t === e2) return;
338
+ const s = t.split(`
339
+ `), i = e2.split(`
340
+ `), r = Math.max(s.length, i.length), n = [];
341
+ for (let u = 0; u < r; u++) s[u] !== i[u] && n.push(u);
342
+ return { lines: n, numLinesBefore: s.length, numLinesAfter: i.length, numLines: r };
343
+ }
344
+ var bt = globalThis.process.platform.startsWith("win");
345
+ var z = /* @__PURE__ */ Symbol("clack:cancel");
346
+ function T(t, e2) {
347
+ const s = t;
348
+ s.isTTY && s.setRawMode(e2);
349
+ }
350
+ function Bt({ input: t = q, output: e2 = R, overwrite: s = true, hideCursor: i = true } = {}) {
351
+ const r = k.createInterface({ input: t, output: e2, prompt: "", tabSize: 1 });
352
+ k.emitKeypressEvents(t, r), t instanceof J && t.isTTY && t.setRawMode(true);
353
+ const n = (u, { name: a, sequence: l }) => {
354
+ const E = String(u);
355
+ if (H([E, a, l], "cancel")) {
356
+ i && e2.write(import_sisteransi.cursor.show), process.exit(0);
357
+ return;
358
+ }
359
+ if (!s) return;
360
+ const g = a === "return" ? 0 : -1, m = a === "return" ? -1 : 0;
361
+ k.moveCursor(e2, g, m, () => {
362
+ k.clearLine(e2, 1, () => {
363
+ t.once("keypress", n);
364
+ });
365
+ });
366
+ };
367
+ return i && e2.write(import_sisteransi.cursor.hide), t.once("keypress", n), () => {
368
+ t.off("keypress", n), i && e2.write(import_sisteransi.cursor.show), t instanceof J && t.isTTY && !bt && t.setRawMode(false), r.terminal = false, r.close();
369
+ };
370
+ }
371
+ var rt = (t) => "columns" in t && typeof t.columns == "number" ? t.columns : 80;
372
+ var nt = (t) => "rows" in t && typeof t.rows == "number" ? t.rows : 20;
373
+ var x = class {
374
+ input;
375
+ output;
376
+ _abortSignal;
377
+ rl;
378
+ opts;
379
+ _render;
380
+ _track = false;
381
+ _prevFrame = "";
382
+ _subscribers = /* @__PURE__ */ new Map();
383
+ _cursor = 0;
384
+ state = "initial";
385
+ error = "";
386
+ value;
387
+ userInput = "";
388
+ constructor(e2, s = true) {
389
+ const { input: i = q, output: r = R, render: n, signal: u, ...a } = e2;
390
+ this.opts = a, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = n.bind(this), this._track = s, this._abortSignal = u, this.input = i, this.output = r;
391
+ }
392
+ unsubscribe() {
393
+ this._subscribers.clear();
394
+ }
395
+ setSubscriber(e2, s) {
396
+ const i = this._subscribers.get(e2) ?? [];
397
+ i.push(s), this._subscribers.set(e2, i);
398
+ }
399
+ on(e2, s) {
400
+ this.setSubscriber(e2, { cb: s });
401
+ }
402
+ once(e2, s) {
403
+ this.setSubscriber(e2, { cb: s, once: true });
404
+ }
405
+ emit(e2, ...s) {
406
+ const i = this._subscribers.get(e2) ?? [], r = [];
407
+ for (const n of i) n.cb(...s), n.once && r.push(() => i.splice(i.indexOf(n), 1));
408
+ for (const n of r) n();
409
+ }
410
+ prompt() {
411
+ return new Promise((e2) => {
412
+ if (this._abortSignal) {
413
+ if (this._abortSignal.aborted) return this.state = "cancel", this.close(), e2(z);
414
+ this._abortSignal.addEventListener("abort", () => {
415
+ this.state = "cancel", this.close();
416
+ }, { once: true });
417
+ }
418
+ this.rl = ot.createInterface({ input: this.input, tabSize: 2, prompt: "", escapeCodeTimeout: 50, terminal: true }), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, true), this.input.on("keypress", this.onKeypress), T(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
419
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), T(this.input, false), e2(this.value);
420
+ }), this.once("cancel", () => {
421
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), T(this.input, false), e2(z);
422
+ });
423
+ });
424
+ }
425
+ _isActionKey(e2, s) {
426
+ return e2 === " ";
427
+ }
428
+ _setValue(e2) {
429
+ this.value = e2, this.emit("value", this.value);
430
+ }
431
+ _setUserInput(e2, s) {
432
+ this.userInput = e2 ?? "", this.emit("userInput", this.userInput), s && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
433
+ }
434
+ _clearUserInput() {
435
+ this.rl?.write(null, { ctrl: true, name: "u" }), this._setUserInput("");
436
+ }
437
+ onKeypress(e2, s) {
438
+ if (this._track && s.name !== "return" && (s.name && this._isActionKey(e2, s) && this.rl?.write(null, { ctrl: true, name: "h" }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), s?.name && (!this._track && _.aliases.has(s.name) && this.emit("cursor", _.aliases.get(s.name)), _.actions.has(s.name) && this.emit("cursor", s.name)), e2 && (e2.toLowerCase() === "y" || e2.toLowerCase() === "n") && this.emit("confirm", e2.toLowerCase() === "y"), this.emit("key", e2?.toLowerCase(), s), s?.name === "return") {
439
+ if (this.opts.validate) {
440
+ const i = this.opts.validate(this.value);
441
+ i && (this.error = i instanceof Error ? i.message : i, this.state = "error", this.rl?.write(this.userInput));
442
+ }
443
+ this.state !== "error" && (this.state = "submit");
444
+ }
445
+ H([e2, s?.name, s?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
446
+ }
447
+ close() {
448
+ this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
449
+ `), T(this.input, false), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
450
+ }
451
+ restoreCursor() {
452
+ const e2 = K(this._prevFrame, process.stdout.columns, { hard: true, trim: false }).split(`
453
+ `).length - 1;
454
+ this.output.write(import_sisteransi.cursor.move(-999, e2 * -1));
455
+ }
456
+ render() {
457
+ const e2 = K(this._render(this) ?? "", process.stdout.columns, { hard: true, trim: false });
458
+ if (e2 !== this._prevFrame) {
459
+ if (this.state === "initial") this.output.write(import_sisteransi.cursor.hide);
460
+ else {
461
+ const s = _t(this._prevFrame, e2), i = nt(this.output);
462
+ if (this.restoreCursor(), s) {
463
+ const r = Math.max(0, s.numLinesAfter - i), n = Math.max(0, s.numLinesBefore - i);
464
+ let u = s.lines.find((a) => a >= r);
465
+ if (u === void 0) {
466
+ this._prevFrame = e2;
467
+ return;
468
+ }
469
+ if (s.lines.length === 1) {
470
+ this.output.write(import_sisteransi.cursor.move(0, u - n)), this.output.write(import_sisteransi.erase.lines(1));
471
+ const a = e2.split(`
472
+ `);
473
+ this.output.write(a[u]), this._prevFrame = e2, this.output.write(import_sisteransi.cursor.move(0, a.length - u - 1));
474
+ return;
475
+ } else if (s.lines.length > 1) {
476
+ if (r < n) u = r;
477
+ else {
478
+ const l = u - n;
479
+ l > 0 && this.output.write(import_sisteransi.cursor.move(0, l));
480
+ }
481
+ this.output.write(import_sisteransi.erase.down());
482
+ const a = e2.split(`
483
+ `).slice(u);
484
+ this.output.write(a.join(`
485
+ `)), this._prevFrame = e2;
486
+ return;
487
+ }
488
+ }
489
+ this.output.write(import_sisteransi.erase.down());
490
+ }
491
+ this.output.write(e2), this.state === "initial" && (this.state = "active"), this._prevFrame = e2;
492
+ }
493
+ }
494
+ };
495
+ var kt = class extends x {
496
+ get cursor() {
497
+ return this.value ? 0 : 1;
498
+ }
499
+ get _value() {
500
+ return this.cursor === 0;
501
+ }
502
+ constructor(e2) {
503
+ super(e2, false), this.value = !!e2.initialValue, this.on("userInput", () => {
504
+ this.value = this._value;
505
+ }), this.on("confirm", (s) => {
506
+ this.output.write(import_sisteransi.cursor.move(0, -1)), this.value = s, this.state = "submit", this.close();
507
+ }), this.on("cursor", () => {
508
+ this.value = !this.value;
509
+ });
510
+ }
511
+ };
512
+ var $t = class extends x {
513
+ get userInputWithCursor() {
514
+ if (this.state === "submit") return this.userInput;
515
+ const e2 = this.userInput;
516
+ if (this.cursor >= e2.length) return `${this.userInput}\u2588`;
517
+ const s = e2.slice(0, this.cursor), [i, ...r] = e2.slice(this.cursor);
518
+ return `${s}${import_picocolors.default.inverse(i)}${r.join("")}`;
519
+ }
520
+ get cursor() {
521
+ return this._cursor;
522
+ }
523
+ constructor(e2) {
524
+ super({ ...e2, initialUserInput: e2.initialUserInput ?? e2.initialValue }), this.on("userInput", (s) => {
525
+ this._setValue(s);
526
+ }), this.on("finalize", () => {
527
+ this.value || (this.value = e2.defaultValue), this.value === void 0 && (this.value = "");
528
+ });
529
+ }
530
+ };
531
+
532
+ // ../stamn-cli/node_modules/@clack/prompts/dist/index.mjs
533
+ var import_picocolors2 = __toESM(require_picocolors(), 1);
534
+ var import_sisteransi2 = __toESM(require_src(), 1);
535
+ import N2 from "process";
536
+ import { readdirSync as de, existsSync as $e, lstatSync as xt2 } from "fs";
537
+ import { dirname as _t2, join as he } from "path";
538
+ import { stripVTControlCharacters as ut } from "util";
539
+ function me() {
540
+ return N2.platform !== "win32" ? N2.env.TERM !== "linux" : !!N2.env.CI || !!N2.env.WT_SESSION || !!N2.env.TERMINUS_SUBLIME || N2.env.ConEmuTask === "{cmd::Cmder}" || N2.env.TERM_PROGRAM === "Terminus-Sublime" || N2.env.TERM_PROGRAM === "vscode" || N2.env.TERM === "xterm-256color" || N2.env.TERM === "alacritty" || N2.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
541
+ }
542
+ var et2 = me();
543
+ var ct2 = () => process.env.CI === "true";
544
+ var C = (t, r) => et2 ? t : r;
545
+ var Rt = C("\u25C6", "*");
546
+ var dt2 = C("\u25A0", "x");
547
+ var $t2 = C("\u25B2", "x");
548
+ var V = C("\u25C7", "o");
549
+ var ht2 = C("\u250C", "T");
550
+ var d = C("\u2502", "|");
551
+ var x2 = C("\u2514", "\u2014");
552
+ var Ot = C("\u2510", "T");
553
+ var Pt = C("\u2518", "\u2014");
554
+ var Q2 = C("\u25CF", ">");
555
+ var H2 = C("\u25CB", " ");
556
+ var st2 = C("\u25FB", "[\u2022]");
557
+ var U2 = C("\u25FC", "[+]");
558
+ var q2 = C("\u25FB", "[ ]");
559
+ var Nt = C("\u25AA", "\u2022");
560
+ var rt2 = C("\u2500", "-");
561
+ var mt2 = C("\u256E", "+");
562
+ var Wt2 = C("\u251C", "+");
563
+ var pt2 = C("\u256F", "+");
564
+ var gt2 = C("\u2570", "+");
565
+ var Lt2 = C("\u256D", "+");
566
+ var ft2 = C("\u25CF", "\u2022");
567
+ var Ft2 = C("\u25C6", "*");
568
+ var yt2 = C("\u25B2", "!");
569
+ var Et2 = C("\u25A0", "x");
570
+ var W2 = (t) => {
571
+ switch (t) {
572
+ case "initial":
573
+ case "active":
574
+ return import_picocolors2.default.cyan(Rt);
575
+ case "cancel":
576
+ return import_picocolors2.default.red(dt2);
577
+ case "error":
578
+ return import_picocolors2.default.yellow($t2);
579
+ case "submit":
580
+ return import_picocolors2.default.green(V);
581
+ }
582
+ };
583
+ var pe = (t) => t === 161 || t === 164 || t === 167 || t === 168 || t === 170 || t === 173 || t === 174 || t >= 176 && t <= 180 || t >= 182 && t <= 186 || t >= 188 && t <= 191 || t === 198 || t === 208 || t === 215 || t === 216 || t >= 222 && t <= 225 || t === 230 || t >= 232 && t <= 234 || t === 236 || t === 237 || t === 240 || t === 242 || t === 243 || t >= 247 && t <= 250 || t === 252 || t === 254 || t === 257 || t === 273 || t === 275 || t === 283 || t === 294 || t === 295 || t === 299 || t >= 305 && t <= 307 || t === 312 || t >= 319 && t <= 322 || t === 324 || t >= 328 && t <= 331 || t === 333 || t === 338 || t === 339 || t === 358 || t === 359 || t === 363 || t === 462 || t === 464 || t === 466 || t === 468 || t === 470 || t === 472 || t === 474 || t === 476 || t === 593 || t === 609 || t === 708 || t === 711 || t >= 713 && t <= 715 || t === 717 || t === 720 || t >= 728 && t <= 731 || t === 733 || t === 735 || t >= 768 && t <= 879 || t >= 913 && t <= 929 || t >= 931 && t <= 937 || t >= 945 && t <= 961 || t >= 963 && t <= 969 || t === 1025 || t >= 1040 && t <= 1103 || t === 1105 || t === 8208 || t >= 8211 && t <= 8214 || t === 8216 || t === 8217 || t === 8220 || t === 8221 || t >= 8224 && t <= 8226 || t >= 8228 && t <= 8231 || t === 8240 || t === 8242 || t === 8243 || t === 8245 || t === 8251 || t === 8254 || t === 8308 || t === 8319 || t >= 8321 && t <= 8324 || t === 8364 || t === 8451 || t === 8453 || t === 8457 || t === 8467 || t === 8470 || t === 8481 || t === 8482 || t === 8486 || t === 8491 || t === 8531 || t === 8532 || t >= 8539 && t <= 8542 || t >= 8544 && t <= 8555 || t >= 8560 && t <= 8569 || t === 8585 || t >= 8592 && t <= 8601 || t === 8632 || t === 8633 || t === 8658 || t === 8660 || t === 8679 || t === 8704 || t === 8706 || t === 8707 || t === 8711 || t === 8712 || t === 8715 || t === 8719 || t === 8721 || t === 8725 || t === 8730 || t >= 8733 && t <= 8736 || t === 8739 || t === 8741 || t >= 8743 && t <= 8748 || t === 8750 || t >= 8756 && t <= 8759 || t === 8764 || t === 8765 || t === 8776 || t === 8780 || t === 8786 || t === 8800 || t === 8801 || t >= 8804 && t <= 8807 || t === 8810 || t === 8811 || t === 8814 || t === 8815 || t === 8834 || t === 8835 || t === 8838 || t === 8839 || t === 8853 || t === 8857 || t === 8869 || t === 8895 || t === 8978 || t >= 9312 && t <= 9449 || t >= 9451 && t <= 9547 || t >= 9552 && t <= 9587 || t >= 9600 && t <= 9615 || t >= 9618 && t <= 9621 || t === 9632 || t === 9633 || t >= 9635 && t <= 9641 || t === 9650 || t === 9651 || t === 9654 || t === 9655 || t === 9660 || t === 9661 || t === 9664 || t === 9665 || t >= 9670 && t <= 9672 || t === 9675 || t >= 9678 && t <= 9681 || t >= 9698 && t <= 9701 || t === 9711 || t === 9733 || t === 9734 || t === 9737 || t === 9742 || t === 9743 || t === 9756 || t === 9758 || t === 9792 || t === 9794 || t === 9824 || t === 9825 || t >= 9827 && t <= 9829 || t >= 9831 && t <= 9834 || t === 9836 || t === 9837 || t === 9839 || t === 9886 || t === 9887 || t === 9919 || t >= 9926 && t <= 9933 || t >= 9935 && t <= 9939 || t >= 9941 && t <= 9953 || t === 9955 || t === 9960 || t === 9961 || t >= 9963 && t <= 9969 || t === 9972 || t >= 9974 && t <= 9977 || t === 9979 || t === 9980 || t === 9982 || t === 9983 || t === 10045 || t >= 10102 && t <= 10111 || t >= 11094 && t <= 11097 || t >= 12872 && t <= 12879 || t >= 57344 && t <= 63743 || t >= 65024 && t <= 65039 || t === 65533 || t >= 127232 && t <= 127242 || t >= 127248 && t <= 127277 || t >= 127280 && t <= 127337 || t >= 127344 && t <= 127373 || t === 127375 || t === 127376 || t >= 127387 && t <= 127404 || t >= 917760 && t <= 917999 || t >= 983040 && t <= 1048573 || t >= 1048576 && t <= 1114109;
584
+ var ge = (t) => t === 12288 || t >= 65281 && t <= 65376 || t >= 65504 && t <= 65510;
585
+ var fe = (t) => t >= 4352 && t <= 4447 || t === 8986 || t === 8987 || t === 9001 || t === 9002 || t >= 9193 && t <= 9196 || t === 9200 || t === 9203 || t === 9725 || t === 9726 || t === 9748 || t === 9749 || t >= 9800 && t <= 9811 || t === 9855 || t === 9875 || t === 9889 || t === 9898 || t === 9899 || t === 9917 || t === 9918 || t === 9924 || t === 9925 || t === 9934 || t === 9940 || t === 9962 || t === 9970 || t === 9971 || t === 9973 || t === 9978 || t === 9981 || t === 9989 || t === 9994 || t === 9995 || t === 10024 || t === 10060 || t === 10062 || t >= 10067 && t <= 10069 || t === 10071 || t >= 10133 && t <= 10135 || t === 10160 || t === 10175 || t === 11035 || t === 11036 || t === 11088 || t === 11093 || t >= 11904 && t <= 11929 || t >= 11931 && t <= 12019 || t >= 12032 && t <= 12245 || t >= 12272 && t <= 12287 || t >= 12289 && t <= 12350 || t >= 12353 && t <= 12438 || t >= 12441 && t <= 12543 || t >= 12549 && t <= 12591 || t >= 12593 && t <= 12686 || t >= 12688 && t <= 12771 || t >= 12783 && t <= 12830 || t >= 12832 && t <= 12871 || t >= 12880 && t <= 19903 || t >= 19968 && t <= 42124 || t >= 42128 && t <= 42182 || t >= 43360 && t <= 43388 || t >= 44032 && t <= 55203 || t >= 63744 && t <= 64255 || t >= 65040 && t <= 65049 || t >= 65072 && t <= 65106 || t >= 65108 && t <= 65126 || t >= 65128 && t <= 65131 || t >= 94176 && t <= 94180 || t === 94192 || t === 94193 || t >= 94208 && t <= 100343 || t >= 100352 && t <= 101589 || t >= 101632 && t <= 101640 || t >= 110576 && t <= 110579 || t >= 110581 && t <= 110587 || t === 110589 || t === 110590 || t >= 110592 && t <= 110882 || t === 110898 || t >= 110928 && t <= 110930 || t === 110933 || t >= 110948 && t <= 110951 || t >= 110960 && t <= 111355 || t === 126980 || t === 127183 || t === 127374 || t >= 127377 && t <= 127386 || t >= 127488 && t <= 127490 || t >= 127504 && t <= 127547 || t >= 127552 && t <= 127560 || t === 127568 || t === 127569 || t >= 127584 && t <= 127589 || t >= 127744 && t <= 127776 || t >= 127789 && t <= 127797 || t >= 127799 && t <= 127868 || t >= 127870 && t <= 127891 || t >= 127904 && t <= 127946 || t >= 127951 && t <= 127955 || t >= 127968 && t <= 127984 || t === 127988 || t >= 127992 && t <= 128062 || t === 128064 || t >= 128066 && t <= 128252 || t >= 128255 && t <= 128317 || t >= 128331 && t <= 128334 || t >= 128336 && t <= 128359 || t === 128378 || t === 128405 || t === 128406 || t === 128420 || t >= 128507 && t <= 128591 || t >= 128640 && t <= 128709 || t === 128716 || t >= 128720 && t <= 128722 || t >= 128725 && t <= 128727 || t >= 128732 && t <= 128735 || t === 128747 || t === 128748 || t >= 128756 && t <= 128764 || t >= 128992 && t <= 129003 || t === 129008 || t >= 129292 && t <= 129338 || t >= 129340 && t <= 129349 || t >= 129351 && t <= 129535 || t >= 129648 && t <= 129660 || t >= 129664 && t <= 129672 || t >= 129680 && t <= 129725 || t >= 129727 && t <= 129733 || t >= 129742 && t <= 129755 || t >= 129760 && t <= 129768 || t >= 129776 && t <= 129784 || t >= 131072 && t <= 196605 || t >= 196608 && t <= 262141;
586
+ var At2 = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/y;
587
+ var it2 = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
588
+ var nt2 = /\t{1,1000}/y;
589
+ var wt = /[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/yu;
590
+ var at2 = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
591
+ var Fe = /\p{M}+/gu;
592
+ var ye = { limit: 1 / 0, ellipsis: "" };
593
+ var jt = (t, r = {}, s = {}) => {
594
+ const i = r.limit ?? 1 / 0, a = r.ellipsis ?? "", o = r?.ellipsisWidth ?? (a ? jt(a, ye, s).width : 0), u = s.ansiWidth ?? 0, l = s.controlWidth ?? 0, n = s.tabWidth ?? 8, c = s.ambiguousWidth ?? 1, g = s.emojiWidth ?? 2, F = s.fullWidthWidth ?? 2, p = s.regularWidth ?? 1, E = s.wideWidth ?? 2;
595
+ let $ = 0, m = 0, h = t.length, y2 = 0, f = false, v = h, S2 = Math.max(0, i - o), I2 = 0, B = 0, A = 0, w = 0;
596
+ t: for (; ; ) {
597
+ if (B > I2 || m >= h && m > $) {
598
+ const _2 = t.slice(I2, B) || t.slice($, m);
599
+ y2 = 0;
600
+ for (const D2 of _2.replaceAll(Fe, "")) {
601
+ const T2 = D2.codePointAt(0) || 0;
602
+ if (ge(T2) ? w = F : fe(T2) ? w = E : c !== p && pe(T2) ? w = c : w = p, A + w > S2 && (v = Math.min(v, Math.max(I2, $) + y2)), A + w > i) {
603
+ f = true;
604
+ break t;
605
+ }
606
+ y2 += D2.length, A += w;
607
+ }
608
+ I2 = B = 0;
609
+ }
610
+ if (m >= h) break;
611
+ if (at2.lastIndex = m, at2.test(t)) {
612
+ if (y2 = at2.lastIndex - m, w = y2 * p, A + w > S2 && (v = Math.min(v, m + Math.floor((S2 - A) / p))), A + w > i) {
613
+ f = true;
614
+ break;
615
+ }
616
+ A += w, I2 = $, B = m, m = $ = at2.lastIndex;
617
+ continue;
618
+ }
619
+ if (At2.lastIndex = m, At2.test(t)) {
620
+ if (A + u > S2 && (v = Math.min(v, m)), A + u > i) {
621
+ f = true;
622
+ break;
623
+ }
624
+ A += u, I2 = $, B = m, m = $ = At2.lastIndex;
625
+ continue;
626
+ }
627
+ if (it2.lastIndex = m, it2.test(t)) {
628
+ if (y2 = it2.lastIndex - m, w = y2 * l, A + w > S2 && (v = Math.min(v, m + Math.floor((S2 - A) / l))), A + w > i) {
629
+ f = true;
630
+ break;
631
+ }
632
+ A += w, I2 = $, B = m, m = $ = it2.lastIndex;
633
+ continue;
634
+ }
635
+ if (nt2.lastIndex = m, nt2.test(t)) {
636
+ if (y2 = nt2.lastIndex - m, w = y2 * n, A + w > S2 && (v = Math.min(v, m + Math.floor((S2 - A) / n))), A + w > i) {
637
+ f = true;
638
+ break;
639
+ }
640
+ A += w, I2 = $, B = m, m = $ = nt2.lastIndex;
641
+ continue;
642
+ }
643
+ if (wt.lastIndex = m, wt.test(t)) {
644
+ if (A + g > S2 && (v = Math.min(v, m)), A + g > i) {
645
+ f = true;
646
+ break;
647
+ }
648
+ A += g, I2 = $, B = m, m = $ = wt.lastIndex;
649
+ continue;
650
+ }
651
+ m += 1;
652
+ }
653
+ return { width: f ? S2 : A, index: f ? v : h, truncated: f, ellipsed: f && i >= o };
654
+ };
655
+ var Ee = { limit: 1 / 0, ellipsis: "", ellipsisWidth: 0 };
656
+ var M2 = (t, r = {}) => jt(t, Ee, r).width;
657
+ var ot2 = "\x1B";
658
+ var Gt = "\x9B";
659
+ var ve = 39;
660
+ var Ct2 = "\x07";
661
+ var kt2 = "[";
662
+ var Ae = "]";
663
+ var Vt2 = "m";
664
+ var St = `${Ae}8;;`;
665
+ var Ht = new RegExp(`(?:\\${kt2}(?<code>\\d+)m|\\${St}(?<uri>.*)${Ct2})`, "y");
666
+ var we = (t) => {
667
+ if (t >= 30 && t <= 37 || t >= 90 && t <= 97) return 39;
668
+ if (t >= 40 && t <= 47 || t >= 100 && t <= 107) return 49;
669
+ if (t === 1 || t === 2) return 22;
670
+ if (t === 3) return 23;
671
+ if (t === 4) return 24;
672
+ if (t === 7) return 27;
673
+ if (t === 8) return 28;
674
+ if (t === 9) return 29;
675
+ if (t === 0) return 0;
676
+ };
677
+ var Ut = (t) => `${ot2}${kt2}${t}${Vt2}`;
678
+ var Kt = (t) => `${ot2}${St}${t}${Ct2}`;
679
+ var Ce = (t) => t.map((r) => M2(r));
680
+ var It2 = (t, r, s) => {
681
+ const i = r[Symbol.iterator]();
682
+ let a = false, o = false, u = t.at(-1), l = u === void 0 ? 0 : M2(u), n = i.next(), c = i.next(), g = 0;
683
+ for (; !n.done; ) {
684
+ const F = n.value, p = M2(F);
685
+ l + p <= s ? t[t.length - 1] += F : (t.push(F), l = 0), (F === ot2 || F === Gt) && (a = true, o = r.startsWith(St, g + 1)), a ? o ? F === Ct2 && (a = false, o = false) : F === Vt2 && (a = false) : (l += p, l === s && !c.done && (t.push(""), l = 0)), n = c, c = i.next(), g += F.length;
686
+ }
687
+ u = t.at(-1), !l && u !== void 0 && u.length > 0 && t.length > 1 && (t[t.length - 2] += t.pop());
688
+ };
689
+ var Se = (t) => {
690
+ const r = t.split(" ");
691
+ let s = r.length;
692
+ for (; s > 0 && !(M2(r[s - 1]) > 0); ) s--;
693
+ return s === r.length ? t : r.slice(0, s).join(" ") + r.slice(s).join("");
694
+ };
695
+ var Ie = (t, r, s = {}) => {
696
+ if (s.trim !== false && t.trim() === "") return "";
697
+ let i = "", a, o;
698
+ const u = t.split(" "), l = Ce(u);
699
+ let n = [""];
700
+ for (const [$, m] of u.entries()) {
701
+ s.trim !== false && (n[n.length - 1] = (n.at(-1) ?? "").trimStart());
702
+ let h = M2(n.at(-1) ?? "");
703
+ if ($ !== 0 && (h >= r && (s.wordWrap === false || s.trim === false) && (n.push(""), h = 0), (h > 0 || s.trim === false) && (n[n.length - 1] += " ", h++)), s.hard && l[$] > r) {
704
+ const y2 = r - h, f = 1 + Math.floor((l[$] - y2 - 1) / r);
705
+ Math.floor((l[$] - 1) / r) < f && n.push(""), It2(n, m, r);
706
+ continue;
707
+ }
708
+ if (h + l[$] > r && h > 0 && l[$] > 0) {
709
+ if (s.wordWrap === false && h < r) {
710
+ It2(n, m, r);
711
+ continue;
712
+ }
713
+ n.push("");
714
+ }
715
+ if (h + l[$] > r && s.wordWrap === false) {
716
+ It2(n, m, r);
717
+ continue;
718
+ }
719
+ n[n.length - 1] += m;
720
+ }
721
+ s.trim !== false && (n = n.map(($) => Se($)));
722
+ const c = n.join(`
723
+ `), g = c[Symbol.iterator]();
724
+ let F = g.next(), p = g.next(), E = 0;
725
+ for (; !F.done; ) {
726
+ const $ = F.value, m = p.value;
727
+ if (i += $, $ === ot2 || $ === Gt) {
728
+ Ht.lastIndex = E + 1;
729
+ const f = Ht.exec(c)?.groups;
730
+ if (f?.code !== void 0) {
731
+ const v = Number.parseFloat(f.code);
732
+ a = v === ve ? void 0 : v;
733
+ } else f?.uri !== void 0 && (o = f.uri.length === 0 ? void 0 : f.uri);
734
+ }
735
+ const h = a ? we(a) : void 0;
736
+ m === `
737
+ ` ? (o && (i += Kt("")), a && h && (i += Ut(h))) : $ === `
738
+ ` && (a && h && (i += Ut(a)), o && (i += Kt(o))), E += $.length, F = p, p = g.next();
739
+ }
740
+ return i;
741
+ };
742
+ function J2(t, r, s) {
743
+ return String(t).normalize().replaceAll(`\r
744
+ `, `
745
+ `).split(`
746
+ `).map((i) => Ie(i, r, s)).join(`
747
+ `);
748
+ }
749
+ var Re = (t) => {
750
+ const r = t.active ?? "Yes", s = t.inactive ?? "No";
751
+ return new kt({ active: r, inactive: s, signal: t.signal, input: t.input, output: t.output, initialValue: t.initialValue ?? true, render() {
752
+ const i = t.withGuide ?? _.withGuide, a = `${i ? `${import_picocolors2.default.gray(d)}
753
+ ` : ""}${W2(this.state)} ${t.message}
754
+ `, o = this.value ? r : s;
755
+ switch (this.state) {
756
+ case "submit": {
757
+ const u = i ? `${import_picocolors2.default.gray(d)} ` : "";
758
+ return `${a}${u}${import_picocolors2.default.dim(o)}`;
759
+ }
760
+ case "cancel": {
761
+ const u = i ? `${import_picocolors2.default.gray(d)} ` : "";
762
+ return `${a}${u}${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(o))}${i ? `
763
+ ${import_picocolors2.default.gray(d)}` : ""}`;
764
+ }
765
+ default: {
766
+ const u = i ? `${import_picocolors2.default.cyan(d)} ` : "", l = i ? import_picocolors2.default.cyan(x2) : "";
767
+ return `${a}${u}${this.value ? `${import_picocolors2.default.green(Q2)} ${r}` : `${import_picocolors2.default.dim(H2)} ${import_picocolors2.default.dim(r)}`}${t.vertical ? i ? `
768
+ ${import_picocolors2.default.cyan(d)} ` : `
769
+ ` : ` ${import_picocolors2.default.dim("/")} `}${this.value ? `${import_picocolors2.default.dim(H2)} ${import_picocolors2.default.dim(s)}` : `${import_picocolors2.default.green(Q2)} ${s}`}
770
+ ${l}
771
+ `;
772
+ }
773
+ }
774
+ } }).prompt();
775
+ };
776
+ var R2 = { message: (t = [], { symbol: r = import_picocolors2.default.gray(d), secondarySymbol: s = import_picocolors2.default.gray(d), output: i = process.stdout, spacing: a = 1, withGuide: o } = {}) => {
777
+ const u = [], l = o ?? _.withGuide, n = l ? s : "", c = l ? `${r} ` : "", g = l ? `${s} ` : "";
778
+ for (let p = 0; p < a; p++) u.push(n);
779
+ const F = Array.isArray(t) ? t : t.split(`
780
+ `);
781
+ if (F.length > 0) {
782
+ const [p, ...E] = F;
783
+ p.length > 0 ? u.push(`${c}${p}`) : u.push(l ? r : "");
784
+ for (const $ of E) $.length > 0 ? u.push(`${g}${$}`) : u.push(l ? s : "");
785
+ }
786
+ i.write(`${u.join(`
787
+ `)}
788
+ `);
789
+ }, info: (t, r) => {
790
+ R2.message(t, { ...r, symbol: import_picocolors2.default.blue(ft2) });
791
+ }, success: (t, r) => {
792
+ R2.message(t, { ...r, symbol: import_picocolors2.default.green(Ft2) });
793
+ }, step: (t, r) => {
794
+ R2.message(t, { ...r, symbol: import_picocolors2.default.green(V) });
795
+ }, warn: (t, r) => {
796
+ R2.message(t, { ...r, symbol: import_picocolors2.default.yellow(yt2) });
797
+ }, warning: (t, r) => {
798
+ R2.warn(t, r);
799
+ }, error: (t, r) => {
800
+ R2.message(t, { ...r, symbol: import_picocolors2.default.red(Et2) });
801
+ } };
802
+ var Ne = (t = "", r) => {
803
+ (r?.output ?? process.stdout).write(`${import_picocolors2.default.gray(x2)} ${import_picocolors2.default.red(t)}
804
+
805
+ `);
806
+ };
807
+ var We = (t = "", r) => {
808
+ (r?.output ?? process.stdout).write(`${import_picocolors2.default.gray(ht2)} ${t}
809
+ `);
810
+ };
811
+ var Le = (t = "", r) => {
812
+ (r?.output ?? process.stdout).write(`${import_picocolors2.default.gray(d)}
813
+ ${import_picocolors2.default.gray(x2)} ${t}
814
+
815
+ `);
816
+ };
817
+ var Ge = (t) => import_picocolors2.default.dim(t);
818
+ var ke = (t, r, s) => {
819
+ const i = { hard: true, trim: false }, a = J2(t, r, i).split(`
820
+ `), o = a.reduce((n, c) => Math.max(M2(c), n), 0), u = a.map(s).reduce((n, c) => Math.max(M2(c), n), 0), l = r - (u - o);
821
+ return J2(t, l, i);
822
+ };
823
+ var Ve = (t = "", r = "", s) => {
824
+ const i = s?.output ?? N2.stdout, a = s?.withGuide ?? _.withGuide, o = s?.format ?? Ge, u = ["", ...ke(t, rt(i) - 6, o).split(`
825
+ `).map(o), ""], l = M2(r), n = Math.max(u.reduce((p, E) => {
826
+ const $ = M2(E);
827
+ return $ > p ? $ : p;
828
+ }, 0), l) + 2, c = u.map((p) => `${import_picocolors2.default.gray(d)} ${p}${" ".repeat(n - M2(p))}${import_picocolors2.default.gray(d)}`).join(`
829
+ `), g = a ? `${import_picocolors2.default.gray(d)}
830
+ ` : "", F = a ? Wt2 : gt2;
831
+ i.write(`${g}${import_picocolors2.default.green(V)} ${import_picocolors2.default.reset(r)} ${import_picocolors2.default.gray(rt2.repeat(Math.max(n - l - 1, 1)) + mt2)}
832
+ ${c}
833
+ ${import_picocolors2.default.gray(F + rt2.repeat(n + 2) + pt2)}
834
+ `);
835
+ };
836
+ var Ke = import_picocolors2.default.magenta;
837
+ var bt2 = ({ indicator: t = "dots", onCancel: r, output: s = process.stdout, cancelMessage: i, errorMessage: a, frames: o = et2 ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"], delay: u = et2 ? 80 : 120, signal: l, ...n } = {}) => {
838
+ const c = ct2();
839
+ let g, F, p = false, E = false, $ = "", m, h = performance.now();
840
+ const y2 = rt(s), f = n?.styleFrame ?? Ke, v = (b) => {
841
+ const O2 = b > 1 ? a ?? _.messages.error : i ?? _.messages.cancel;
842
+ E = b === 1, p && (L2(O2, b), E && typeof r == "function" && r());
843
+ }, S2 = () => v(2), I2 = () => v(1), B = () => {
844
+ process.on("uncaughtExceptionMonitor", S2), process.on("unhandledRejection", S2), process.on("SIGINT", I2), process.on("SIGTERM", I2), process.on("exit", v), l && l.addEventListener("abort", I2);
845
+ }, A = () => {
846
+ process.removeListener("uncaughtExceptionMonitor", S2), process.removeListener("unhandledRejection", S2), process.removeListener("SIGINT", I2), process.removeListener("SIGTERM", I2), process.removeListener("exit", v), l && l.removeEventListener("abort", I2);
847
+ }, w = () => {
848
+ if (m === void 0) return;
849
+ c && s.write(`
850
+ `);
851
+ const b = J2(m, y2, { hard: true, trim: false }).split(`
852
+ `);
853
+ b.length > 1 && s.write(import_sisteransi2.cursor.up(b.length - 1)), s.write(import_sisteransi2.cursor.to(0)), s.write(import_sisteransi2.erase.down());
854
+ }, _2 = (b) => b.replace(/\.+$/, ""), D2 = (b) => {
855
+ const O2 = (performance.now() - b) / 1e3, j2 = Math.floor(O2 / 60), G2 = Math.floor(O2 % 60);
856
+ return j2 > 0 ? `[${j2}m ${G2}s]` : `[${G2}s]`;
857
+ }, T2 = n.withGuide ?? _.withGuide, Y = (b = "") => {
858
+ p = true, g = Bt({ output: s }), $ = _2(b), h = performance.now(), T2 && s.write(`${import_picocolors2.default.gray(d)}
859
+ `);
860
+ let O2 = 0, j2 = 0;
861
+ B(), F = setInterval(() => {
862
+ if (c && $ === m) return;
863
+ w(), m = $;
864
+ const G2 = f(o[O2]);
865
+ let tt2;
866
+ if (c) tt2 = `${G2} ${$}...`;
867
+ else if (t === "timer") tt2 = `${G2} ${$} ${D2(h)}`;
868
+ else {
869
+ const te = ".".repeat(Math.floor(j2)).slice(0, 3);
870
+ tt2 = `${G2} ${$}${te}`;
871
+ }
872
+ const Zt = J2(tt2, y2, { hard: true, trim: false });
873
+ s.write(Zt), O2 = O2 + 1 < o.length ? O2 + 1 : 0, j2 = j2 < 4 ? j2 + 0.125 : 0;
874
+ }, u);
875
+ }, L2 = (b = "", O2 = 0, j2 = false) => {
876
+ if (!p) return;
877
+ p = false, clearInterval(F), w();
878
+ const G2 = O2 === 0 ? import_picocolors2.default.green(V) : O2 === 1 ? import_picocolors2.default.red(dt2) : import_picocolors2.default.red($t2);
879
+ $ = b ?? $, j2 || (t === "timer" ? s.write(`${G2} ${$} ${D2(h)}
880
+ `) : s.write(`${G2} ${$}
881
+ `)), A(), g();
882
+ };
883
+ return { start: Y, stop: (b = "") => L2(b, 0), message: (b = "") => {
884
+ $ = _2(b ?? $);
885
+ }, cancel: (b = "") => L2(b, 1), error: (b = "") => L2(b, 2), clear: () => L2("", 0, true), get isCancelled() {
886
+ return E;
887
+ } };
888
+ };
889
+ var zt = { light: C("\u2500", "-"), heavy: C("\u2501", "="), block: C("\u2588", "#") };
890
+ var Qt = `${import_picocolors2.default.gray(d)} `;
891
+ var Ze = (t) => new $t({ validate: t.validate, placeholder: t.placeholder, defaultValue: t.defaultValue, initialValue: t.initialValue, output: t.output, signal: t.signal, input: t.input, render() {
892
+ const r = t?.withGuide ?? _.withGuide, s = `${`${r ? `${import_picocolors2.default.gray(d)}
893
+ ` : ""}${W2(this.state)} `}${t.message}
894
+ `, i = t.placeholder ? import_picocolors2.default.inverse(t.placeholder[0]) + import_picocolors2.default.dim(t.placeholder.slice(1)) : import_picocolors2.default.inverse(import_picocolors2.default.hidden("_")), a = this.userInput ? this.userInputWithCursor : i, o = this.value ?? "";
895
+ switch (this.state) {
896
+ case "error": {
897
+ const u = this.error ? ` ${import_picocolors2.default.yellow(this.error)}` : "", l = r ? `${import_picocolors2.default.yellow(d)} ` : "", n = r ? import_picocolors2.default.yellow(x2) : "";
898
+ return `${s.trim()}
899
+ ${l}${a}
900
+ ${n}${u}
901
+ `;
902
+ }
903
+ case "submit": {
904
+ const u = o ? ` ${import_picocolors2.default.dim(o)}` : "", l = r ? import_picocolors2.default.gray(d) : "";
905
+ return `${s}${l}${u}`;
906
+ }
907
+ case "cancel": {
908
+ const u = o ? ` ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(o))}` : "", l = r ? import_picocolors2.default.gray(d) : "";
909
+ return `${s}${l}${u}${o.trim() ? `
910
+ ${l}` : ""}`;
911
+ }
912
+ default: {
913
+ const u = r ? `${import_picocolors2.default.cyan(d)} ` : "", l = r ? import_picocolors2.default.cyan(x2) : "";
914
+ return `${s}${u}${a}
915
+ ${l}
916
+ `;
917
+ }
918
+ }
919
+ } }).prompt();
920
+
921
+ // ../stamn-sdk/dist/index.js
922
+ var Resource = class {
923
+ constructor(client) {
924
+ this.client = client;
925
+ }
926
+ };
927
+ var DEFAULT_POLL_INTERVAL_MS = 5e3;
928
+ var DEFAULT_TIMEOUT_MS = 3e5;
929
+ var AuthResource = class extends Resource {
930
+ async initiateDeviceFlow() {
931
+ const res = await this.client.request(
932
+ "POST",
933
+ "/v1/auth/device-codes"
934
+ );
935
+ return res.data;
936
+ }
937
+ async getDeviceFlowStatus(deviceCode) {
938
+ const res = await this.client.request(
939
+ "GET",
940
+ `/v1/auth/device-codes/${deviceCode}`
941
+ );
942
+ return res.data;
943
+ }
944
+ async pollForApproval(deviceCode, options) {
945
+ const pollInterval = options?.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
946
+ const timeout = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
947
+ const deadline = Date.now() + timeout;
948
+ while (Date.now() < deadline) {
949
+ await new Promise((r) => setTimeout(r, pollInterval));
950
+ try {
951
+ const status = await this.getDeviceFlowStatus(deviceCode);
952
+ if (status.status === "approved" && status.apiKey) {
953
+ return status.apiKey;
954
+ }
955
+ if (status.status === "expired") {
956
+ throw new Error("Login code expired. Try again.");
957
+ }
958
+ } catch (err) {
959
+ if (err.message.includes("expired")) throw err;
960
+ }
961
+ }
962
+ throw new Error("Login timed out. Try again.");
963
+ }
964
+ };
965
+ var AgentsResource = class extends Resource {
966
+ async create(options) {
967
+ const res = await this.client.request(
968
+ "POST",
969
+ "/v1/participants",
970
+ {
971
+ name: options?.name,
972
+ description: options?.description
973
+ }
974
+ );
975
+ return res.data;
976
+ }
977
+ };
978
+ var HealthResource = class extends Resource {
979
+ async check() {
980
+ try {
981
+ await this.client.request("GET", "/v1/health");
982
+ return { ok: true };
983
+ } catch {
984
+ return { ok: false };
985
+ }
986
+ }
987
+ };
988
+ var DirectoryResource = class extends Resource {
989
+ async list(options) {
990
+ const params = new URLSearchParams();
991
+ if (options?.serviceTag) params.set("serviceTag", options.serviceTag);
992
+ if (options?.name) params.set("name", options.name);
993
+ const query = params.toString();
994
+ const path = `/v1/directory${query ? `?${query}` : ""}`;
995
+ const res = await this.client.request(
996
+ "GET",
997
+ path
998
+ );
999
+ return res.data;
1000
+ }
1001
+ };
1002
+ var StamnApiError = class extends Error {
1003
+ constructor(message, status) {
1004
+ super(message);
1005
+ this.status = status;
1006
+ this.name = "StamnApiError";
1007
+ }
1008
+ };
1009
+ var DEFAULT_RETRY = {
1010
+ maxRetries: 0,
1011
+ initialDelayMs: 500,
1012
+ backoffMultiplier: 2,
1013
+ maxDelayMs: 1e4
1014
+ };
1015
+ var SERVER_URL = "https://api.stamn.com";
1016
+ var StamnClient = class {
1017
+ serverUrl = SERVER_URL;
1018
+ apiKey;
1019
+ retryOptions;
1020
+ auth;
1021
+ agents;
1022
+ health;
1023
+ directory;
1024
+ constructor(options = {}) {
1025
+ this.apiKey = options.apiKey;
1026
+ this.retryOptions = { ...DEFAULT_RETRY, ...options.retry };
1027
+ this.auth = new AuthResource(this);
1028
+ this.agents = new AgentsResource(this);
1029
+ this.health = new HealthResource(this);
1030
+ this.directory = new DirectoryResource(this);
1031
+ }
1032
+ setApiKey(apiKey) {
1033
+ this.apiKey = apiKey;
1034
+ }
1035
+ async request(method, path, body) {
1036
+ let lastError;
1037
+ for (let attempt = 0; attempt <= this.retryOptions.maxRetries; attempt++) {
1038
+ if (attempt > 0) {
1039
+ await this.sleep(this.calculateDelay(attempt - 1));
1040
+ }
1041
+ try {
1042
+ return await this.executeRequest(method, path, body);
1043
+ } catch (error) {
1044
+ lastError = error;
1045
+ if (!this.isRetryable(error) || attempt === this.retryOptions.maxRetries) {
1046
+ throw error;
1047
+ }
1048
+ }
1049
+ }
1050
+ throw lastError;
1051
+ }
1052
+ async executeRequest(method, path, body) {
1053
+ const headers = {};
1054
+ if (body !== void 0) {
1055
+ headers["Content-Type"] = "application/json";
1056
+ }
1057
+ if (this.apiKey) {
1058
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
1059
+ }
1060
+ const res = await fetch(`${this.serverUrl}${path}`, {
1061
+ method,
1062
+ headers,
1063
+ body: body !== void 0 ? JSON.stringify(body) : void 0
1064
+ });
1065
+ if (!res.ok) {
1066
+ const message = await this.parseErrorResponse(res);
1067
+ throw new StamnApiError(message, res.status);
1068
+ }
1069
+ const text2 = await res.text();
1070
+ if (!text2) return void 0;
1071
+ return JSON.parse(text2);
1072
+ }
1073
+ isRetryable(error) {
1074
+ if (error instanceof TypeError) return true;
1075
+ if (error instanceof StamnApiError && error.status >= 500) return true;
1076
+ if (error instanceof StamnApiError && error.status === 429) return true;
1077
+ return false;
1078
+ }
1079
+ calculateDelay(attempt) {
1080
+ const baseDelay = this.retryOptions.initialDelayMs * Math.pow(this.retryOptions.backoffMultiplier, attempt);
1081
+ const capped = Math.min(baseDelay, this.retryOptions.maxDelayMs);
1082
+ return Math.random() * capped;
1083
+ }
1084
+ sleep(ms) {
1085
+ return new Promise((resolve) => setTimeout(resolve, ms));
1086
+ }
1087
+ async parseErrorResponse(res) {
1088
+ const body = await res.text();
1089
+ try {
1090
+ const parsed = JSON.parse(body);
1091
+ const msg = parsed.error?.message ?? (Array.isArray(parsed.message) ? parsed.message.join(". ") : parsed.message);
1092
+ if (msg) return msg;
1093
+ } catch {
1094
+ }
1095
+ return body || `HTTP ${res.status}`;
1096
+ }
1097
+ };
1098
+
1099
+ // ../stamn-cli/dist/chunk-CAVP3V47.js
1100
+ import { execSync } from "child_process";
1101
+ import { mkdirSync, readFileSync, writeFileSync, unlinkSync } from "fs";
5
1102
  import { join } from "path";
1103
+ import { tmpdir } from "os";
1104
+ import { rmSync } from "fs";
1105
+ import { dirname } from "path";
1106
+ import { mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
1107
+ import { dirname as dirname2, join as join2 } from "path";
1108
+ async function handleLogin(opts, adapter) {
1109
+ const client = new StamnClient();
1110
+ We("Stamn Agent Login");
1111
+ let name = opts.name;
1112
+ if (!name) {
1113
+ const input = await Ze({
1114
+ message: "What should we call this agent?",
1115
+ placeholder: "my-agent",
1116
+ validate: (value) => {
1117
+ if (!value?.trim()) return "Name is required.";
1118
+ }
1119
+ });
1120
+ if (typeof input === "symbol") {
1121
+ Ne("Login cancelled.");
1122
+ return;
1123
+ }
1124
+ name = input;
1125
+ }
1126
+ const s = bt2();
1127
+ try {
1128
+ s.start("Initiating device flow...");
1129
+ const flow = await client.auth.initiateDeviceFlow();
1130
+ s.stop("Device flow initiated.");
1131
+ const label = (str) => str.padEnd(7);
1132
+ Ve(
1133
+ `${label("Open:")} ${flow.verificationUri}
1134
+ ${label("Code:")} ${flow.userCode}`,
1135
+ "Authorize in your browser"
1136
+ );
1137
+ s.start("Waiting for approval...");
1138
+ const apiKey = await client.auth.pollForApproval(flow.deviceCode);
1139
+ s.stop("Approved!");
1140
+ client.setApiKey(apiKey);
1141
+ s.start("Registering agent...");
1142
+ const agent = await client.agents.create({ name });
1143
+ s.stop("Agent registered.");
1144
+ adapter.writeConfig({
1145
+ apiKey,
1146
+ agentId: agent.id,
1147
+ agentName: agent.name
1148
+ });
1149
+ R2.success(`Agent "${agent.name}" (${agent.id})`);
1150
+ R2.info(`Config written to ${adapter.getConfigPath()}`);
1151
+ Le("Done! You can now use stamn commands.");
1152
+ } catch (err) {
1153
+ s.stop("Failed.");
1154
+ Ne(`Login failed: ${err.message}`);
1155
+ process.exitCode = 1;
1156
+ }
1157
+ }
1158
+ function openEditor(initial) {
1159
+ const editor = process.env.EDITOR || process.env.VISUAL || "vi";
1160
+ const tmpFile = join(tmpdir(), `stamn-personality-${Date.now()}.md`);
1161
+ mkdirSync(tmpdir(), { recursive: true });
1162
+ writeFileSync(tmpFile, initial, "utf-8");
1163
+ try {
1164
+ execSync(`${editor} "${tmpFile}"`, { stdio: "inherit" });
1165
+ const result = readFileSync(tmpFile, "utf-8").trim();
1166
+ return result || null;
1167
+ } catch {
1168
+ return null;
1169
+ } finally {
1170
+ try {
1171
+ unlinkSync(tmpFile);
1172
+ } catch {
1173
+ }
1174
+ }
1175
+ }
1176
+ function handleConfig(opts, adapter) {
1177
+ if (!opts.name && !opts.personality) {
1178
+ const config = adapter.readConfig();
1179
+ if (!config) {
1180
+ R2.warn("No config found. Run `stamn agent login` first.");
1181
+ return;
1182
+ }
1183
+ R2.info(`Name: ${config.agentName ?? "(not set)"}`);
1184
+ R2.info(`Personality: ${config.personality ? "configured" : "(not set)"}`);
1185
+ return;
1186
+ }
1187
+ if (opts.name) {
1188
+ adapter.writeConfig({ agentName: opts.name });
1189
+ R2.success(`Name set: "${opts.name}"`);
1190
+ }
1191
+ if (opts.personality) {
1192
+ const existing = adapter.readConfig()?.personality ?? "";
1193
+ const text2 = openEditor(existing);
1194
+ if (!text2) {
1195
+ R2.warn("Editor closed without saving. Personality unchanged.");
1196
+ return;
1197
+ }
1198
+ adapter.writeConfig({ personality: text2 });
1199
+ R2.success("Personality updated.");
1200
+ }
1201
+ }
1202
+ async function handleStatus(adapter) {
1203
+ const config = adapter.readConfig();
1204
+ const status = adapter.readStatusFile();
1205
+ const label = (str) => str.padEnd(14);
1206
+ We("Stamn Status");
1207
+ R2.info(`${label("Agent ID:")} ${config?.agentId || "(not configured)"}`);
1208
+ R2.info(
1209
+ `${label("Agent Name:")} ${config?.agentName || "(not configured)"}`
1210
+ );
1211
+ R2.info(`${label("Connected:")} ${status?.connected ? "yes" : "no"}`);
1212
+ if (status?.connected && status.connectedAt) {
1213
+ R2.info(
1214
+ `${label("Since:")} ${new Date(status.connectedAt).toLocaleString()}`
1215
+ );
1216
+ }
1217
+ if (config?.apiKey) {
1218
+ const client = new StamnClient({ apiKey: config.apiKey });
1219
+ const health = await client.health.check();
1220
+ R2.info(`${label("Server:")} ${health.ok ? "healthy" : "unhealthy"}`);
1221
+ }
1222
+ Le("");
1223
+ }
1224
+ async function handleUninstall(adapter) {
1225
+ We("Stamn Uninstall");
1226
+ const configDir = dirname(adapter.getConfigPath());
1227
+ const shouldContinue = await Re({
1228
+ message: `This will delete all config at ${configDir}. Continue?`
1229
+ });
1230
+ if (!shouldContinue || typeof shouldContinue === "symbol") {
1231
+ Ne("Uninstall cancelled.");
1232
+ return;
1233
+ }
1234
+ try {
1235
+ rmSync(configDir, { recursive: true, force: true });
1236
+ R2.success(`Removed ${configDir}`);
1237
+ Le("Stamn config removed.");
1238
+ } catch (err) {
1239
+ Ne(`Failed to remove config: ${err.message}`);
1240
+ process.exitCode = 1;
1241
+ }
1242
+ }
1243
+ function readJsonFile(filePath) {
1244
+ try {
1245
+ const raw = readFileSync2(filePath, "utf-8");
1246
+ return JSON.parse(raw);
1247
+ } catch {
1248
+ return null;
1249
+ }
1250
+ }
1251
+ function writeJsonFile(filePath, data) {
1252
+ mkdirSync2(dirname2(filePath), { recursive: true });
1253
+ writeFileSync2(filePath, JSON.stringify(data, null, 2) + "\n", "utf-8");
1254
+ }
1255
+
1256
+ // src/config.ts
1257
+ import { existsSync, rmSync as rmSync2 } from "fs";
1258
+ import { join as join3 } from "path";
6
1259
  import { homedir } from "os";
7
- import { readJsonFile, writeJsonFile } from "@stamn/cli";
1260
+ var DEFAULT_SERVER_URL = "https://api.stamn.com";
1261
+ function getWsUrl() {
1262
+ const base = process.env.STAMN_SERVER_URL || DEFAULT_SERVER_URL;
1263
+ const wsBase = base.replace(/^https:\/\//, "wss://").replace(/^http:\/\//, "ws://");
1264
+ return `${wsBase}/ws/agent`;
1265
+ }
1266
+ function writeStatusFile(status) {
1267
+ writeJsonFile(join3(homedir(), ".openclaw", "stamn-status.json"), status);
1268
+ }
8
1269
  function getConfigPath() {
9
- return join(homedir(), ".openclaw", "openclaw.json");
1270
+ return join3(homedir(), ".openclaw", "openclaw.json");
10
1271
  }
11
1272
  function ensurePluginConfig(config) {
12
1273
  if (!config.plugins) config.plugins = {};
@@ -31,48 +1292,635 @@ function createOpenclawAdapter() {
31
1292
  writeConfig(updates) {
32
1293
  const config = readOpenclawConfig();
33
1294
  ensurePluginConfig(config);
34
- const gatewayToken = config?.gateway?.auth?.token ?? process.env.OPENCLAW_GATEWAY_TOKEN ?? "";
35
1295
  config.plugins.entries.stamn.enabled = true;
36
1296
  config.plugins.entries.stamn.config = {
37
1297
  ...config.plugins.entries.stamn.config,
38
- ...updates,
39
- ...gatewayToken ? { gatewayToken } : {}
1298
+ ...updates
40
1299
  };
41
- if (!config.gateway) config.gateway = {};
42
- if (!config.gateway.http) config.gateway.http = {};
43
- if (!config.gateway.http.endpoints) config.gateway.http.endpoints = {};
44
- if (!config.gateway.http.endpoints.chatCompletions) {
45
- config.gateway.http.endpoints.chatCompletions = { enabled: true };
46
- }
47
1300
  writeJsonFile(getConfigPath(), config);
48
1301
  },
49
1302
  readStatusFile() {
50
- return readJsonFile(join(homedir(), ".openclaw", "stamn-status.json"));
1303
+ return readJsonFile(join3(homedir(), ".openclaw", "stamn-status.json"));
1304
+ },
1305
+ uninstall() {
1306
+ const config = readOpenclawConfig();
1307
+ if (config?.plugins?.entries?.stamn) {
1308
+ delete config.plugins.entries.stamn;
1309
+ writeJsonFile(getConfigPath(), config);
1310
+ }
1311
+ const statusPath = join3(homedir(), ".openclaw", "stamn-status.json");
1312
+ if (existsSync(statusPath)) {
1313
+ rmSync2(statusPath);
1314
+ }
51
1315
  }
52
1316
  };
53
1317
  }
54
1318
 
55
1319
  // src/register.ts
56
- function registerCli(api, config) {
1320
+ function registerCli(api) {
57
1321
  const adapter = createOpenclawAdapter();
58
1322
  api.registerCli(
59
1323
  ({ program }) => {
60
1324
  const stamn = program.command("stamn").description("Stamn commands");
61
1325
  const agent = stamn.command("agent").description("Agent management");
62
- agent.command("login").description("Authenticate and register an agent").option("--name <name>", "Agent name").action(
63
- (opts) => handleLogin({ ...opts, server: config.serverUrl }, adapter)
64
- );
65
- agent.command("config").description("View or update agent configuration").option("--name <name>", "Agent display name").option("--personality", "Open editor to set agent personality").action(
66
- (opts) => handleConfig(opts, adapter)
67
- );
68
- stamn.command("status").description("Show connection status and server health").action(() => handleStatus(config, adapter));
1326
+ agent.command("login").description("Authenticate and register an agent").option("--name <name>", "Agent name").action((opts) => handleLogin(opts, adapter));
1327
+ agent.command("config").description("View or update agent configuration").option("--name <name>", "Agent display name").option("--personality", "Open editor to set agent personality").action((opts) => handleConfig(opts, adapter));
1328
+ stamn.command("status").description("Show connection status and server health").action(() => handleStatus(adapter));
69
1329
  stamn.command("uninstall").description("Remove all Stamn config and data").action(() => handleUninstall(adapter));
70
1330
  },
71
1331
  { commands: ["stamn"] }
72
1332
  );
73
1333
  }
1334
+
1335
+ // src/tools.ts
1336
+ import { randomUUID } from "crypto";
1337
+ function text(msg) {
1338
+ return { content: [{ type: "text", text: msg }] };
1339
+ }
1340
+ function json(data) {
1341
+ return text(JSON.stringify(data, null, 2));
1342
+ }
1343
+ function createReadTools(wsService) {
1344
+ return [
1345
+ {
1346
+ name: "stamn_world_status",
1347
+ description: "Get the current world state including your position, balance, nearby agents, owned land, and available services.",
1348
+ parameters: { type: "object", properties: {} },
1349
+ execute: () => {
1350
+ const state = wsService.getWorldState();
1351
+ return state ? json(state) : text("No world state received yet.");
1352
+ }
1353
+ },
1354
+ {
1355
+ name: "stamn_get_events",
1356
+ description: "Drain the pending event buffer. Returns all events received since the last call (service requests, chat messages, owner commands, transfers, etc.).",
1357
+ parameters: { type: "object", properties: {} },
1358
+ execute: () => {
1359
+ const events = wsService.drainEvents();
1360
+ return events.length > 0 ? json(events) : text("No new events.");
1361
+ }
1362
+ },
1363
+ {
1364
+ name: "stamn_get_balance",
1365
+ description: "Request the agent's current balance from the server.",
1366
+ parameters: { type: "object", properties: {} },
1367
+ execute: () => {
1368
+ wsService.send("participant:get_balance", {});
1369
+ const cached = wsService.getBalance();
1370
+ return cached ? text(`Balance request sent. Last known balance: ${cached.balanceCents} cents.`) : text("Balance request sent. Check events for the response.");
1371
+ }
1372
+ }
1373
+ ];
1374
+ }
1375
+ function createActionTools(wsService, agentId) {
1376
+ return [
1377
+ {
1378
+ name: "stamn_move",
1379
+ description: "Move the agent one cell in a direction on the world grid.",
1380
+ parameters: {
1381
+ type: "object",
1382
+ properties: {
1383
+ direction: {
1384
+ type: "string",
1385
+ enum: ["up", "down", "left", "right"],
1386
+ description: "Direction to move."
1387
+ }
1388
+ },
1389
+ required: ["direction"]
1390
+ },
1391
+ execute: (args) => {
1392
+ wsService.send("participant:move", { participantId: agentId, direction: args.direction });
1393
+ return text(`Moving ${args.direction}.`);
1394
+ }
1395
+ },
1396
+ {
1397
+ name: "stamn_claim_land",
1398
+ description: "Claim the land tile at the agent's current position.",
1399
+ parameters: { type: "object", properties: {} },
1400
+ execute: () => {
1401
+ wsService.send("participant:land_claim", { participantId: agentId });
1402
+ return text("Land claim request sent. Check events for the result.");
1403
+ }
1404
+ },
1405
+ {
1406
+ name: "stamn_register_service",
1407
+ description: "Register a service offering that other agents can purchase.",
1408
+ parameters: {
1409
+ type: "object",
1410
+ properties: {
1411
+ serviceTag: { type: "string", description: "Unique identifier (e.g. 'summarize')." },
1412
+ description: { type: "string", description: "What the service does." },
1413
+ priceCents: { type: "string", description: "Price in cents (USDC)." }
1414
+ },
1415
+ required: ["serviceTag", "description", "priceCents"]
1416
+ },
1417
+ execute: (args) => {
1418
+ wsService.send("participant:service_register", {
1419
+ participantId: agentId,
1420
+ serviceTag: args.serviceTag,
1421
+ description: args.description,
1422
+ priceCents: Number(args.priceCents)
1423
+ });
1424
+ return text(`Service "${args.serviceTag}" registration sent.`);
1425
+ }
1426
+ },
1427
+ {
1428
+ name: "stamn_service_respond",
1429
+ description: "Respond to an incoming service request with a result.",
1430
+ parameters: {
1431
+ type: "object",
1432
+ properties: {
1433
+ requestId: { type: "string", description: "The requestId from the incoming event." },
1434
+ output: { type: "string", description: "The result/output of the service." },
1435
+ success: {
1436
+ type: "string",
1437
+ enum: ["true", "false"],
1438
+ description: "Whether it succeeded."
1439
+ }
1440
+ },
1441
+ required: ["requestId", "output", "success"]
1442
+ },
1443
+ execute: (args) => {
1444
+ wsService.send("participant:service_result", {
1445
+ requestId: args.requestId,
1446
+ output: args.output,
1447
+ success: args.success === "true"
1448
+ });
1449
+ return text(`Service response sent for request ${args.requestId}.`);
1450
+ }
1451
+ },
1452
+ {
1453
+ name: "stamn_chat_reply",
1454
+ description: "Reply to a message from the agent's owner.",
1455
+ parameters: {
1456
+ type: "object",
1457
+ properties: {
1458
+ text: { type: "string", description: "The reply message text." },
1459
+ replyToMessageId: {
1460
+ type: "string",
1461
+ description: "Optional message ID being replied to."
1462
+ }
1463
+ },
1464
+ required: ["text"]
1465
+ },
1466
+ execute: (args) => {
1467
+ wsService.send("participant:owner_chat_reply", {
1468
+ participantId: agentId,
1469
+ text: args.text,
1470
+ ...args.replyToMessageId ? { replyToMessageId: args.replyToMessageId } : {}
1471
+ });
1472
+ return text("Reply sent to owner.");
1473
+ }
1474
+ },
1475
+ {
1476
+ name: "stamn_spend",
1477
+ description: "Request a spend from the agent's balance (USDC).",
1478
+ parameters: {
1479
+ type: "object",
1480
+ properties: {
1481
+ amountCents: { type: "string", description: "Amount in cents." },
1482
+ description: { type: "string", description: "What the spend is for." },
1483
+ category: {
1484
+ type: "string",
1485
+ enum: ["api", "compute", "contractor", "transfer", "inference"],
1486
+ description: "Spend category."
1487
+ },
1488
+ rail: {
1489
+ type: "string",
1490
+ enum: ["crypto_onchain", "x402", "internal"],
1491
+ description: "Payment rail."
1492
+ },
1493
+ vendor: { type: "string", description: "Optional vendor name." },
1494
+ recipientParticipantId: { type: "string", description: "Optional recipient agent ID." }
1495
+ },
1496
+ required: ["amountCents", "description", "category", "rail"]
1497
+ },
1498
+ execute: (args) => {
1499
+ const requestId = randomUUID();
1500
+ wsService.send("participant:spend_request", {
1501
+ requestId,
1502
+ amountCents: Number(args.amountCents),
1503
+ currency: "USDC",
1504
+ category: args.category,
1505
+ rail: args.rail,
1506
+ description: args.description,
1507
+ ...args.vendor ? { vendor: args.vendor } : {},
1508
+ ...args.recipientParticipantId ? { recipientParticipantId: args.recipientParticipantId } : {}
1509
+ });
1510
+ return text(
1511
+ `Spend request sent (requestId: ${requestId}). Check events for approval/denial.`
1512
+ );
1513
+ }
1514
+ }
1515
+ ];
1516
+ }
1517
+ function registerTools(api, wsService, config) {
1518
+ const tools = [...createReadTools(wsService), ...createActionTools(wsService, config.agentId)];
1519
+ for (const tool of tools) {
1520
+ const originalExecute = tool.execute;
1521
+ api.registerTool({
1522
+ ...tool,
1523
+ execute: async (args) => {
1524
+ if (!wsService.getConnectionStatus().authenticated) {
1525
+ return text('Not connected to Stamn server. Run "stamn status" to check.');
1526
+ }
1527
+ return originalExecute(args);
1528
+ }
1529
+ });
1530
+ }
1531
+ }
1532
+
1533
+ // src/ws-service.ts
1534
+ import WebSocket from "ws";
1535
+ var MAX_EVENT_BUFFER_SIZE = 200;
1536
+ var BASE_RECONNECT_DELAY_MS = 1e3;
1537
+ var MAX_RECONNECT_DELAY_MS = 6e4;
1538
+ var DEFAULT_HEARTBEAT_MS = 3e4;
1539
+ var PLUGIN_VERSION = "0.1.0";
1540
+ var ServerEvent = {
1541
+ AUTHENTICATED: "server:authenticated",
1542
+ AUTH_ERROR: "server:auth_error",
1543
+ HEARTBEAT_ACK: "server:heartbeat_ack",
1544
+ WORLD_UPDATE: "server:world_update",
1545
+ BALANCE: "server:balance",
1546
+ OWNER_CHAT_MESSAGE: "server:owner_chat_message"
1547
+ };
1548
+ var ClientEvent = {
1549
+ AUTHENTICATE: "participant:authenticate",
1550
+ HEARTBEAT: "participant:heartbeat",
1551
+ STATUS_REPORT: "participant:status_report"
1552
+ };
1553
+ var StamnWsService = class {
1554
+ ws = null;
1555
+ connected = false;
1556
+ authenticated = false;
1557
+ authFailed = false;
1558
+ startedAt = /* @__PURE__ */ new Date();
1559
+ heartbeatTimer = null;
1560
+ reconnectTimer = null;
1561
+ reconnectAttempt = 0;
1562
+ latestWorldUpdate = null;
1563
+ latestBalance = null;
1564
+ eventBuffer = [];
1565
+ config;
1566
+ logger;
1567
+ wsUrl;
1568
+ onStatusChange;
1569
+ createSocket;
1570
+ ownerChatHandler;
1571
+ messageHandlers;
1572
+ constructor(opts) {
1573
+ this.config = opts.config;
1574
+ this.logger = opts.logger;
1575
+ this.wsUrl = opts.wsUrl;
1576
+ this.onStatusChange = opts.onStatusChange;
1577
+ this.createSocket = opts.createSocket ?? ((url) => new WebSocket(url));
1578
+ this.messageHandlers = {
1579
+ [ServerEvent.AUTHENTICATED]: (d2) => this.onAuthenticated(d2),
1580
+ [ServerEvent.AUTH_ERROR]: (d2) => this.onAuthError(d2),
1581
+ [ServerEvent.HEARTBEAT_ACK]: () => this.logger.debug("Heartbeat acknowledged"),
1582
+ [ServerEvent.WORLD_UPDATE]: (d2) => this.onWorldUpdate(d2),
1583
+ [ServerEvent.BALANCE]: (d2) => this.onBalanceUpdate(d2),
1584
+ [ServerEvent.OWNER_CHAT_MESSAGE]: (d2) => this.handleOwnerChat(d2)
1585
+ };
1586
+ }
1587
+ async start() {
1588
+ if (!this.config.apiKey || !this.config.agentId) {
1589
+ this.logger.error("Cannot start WS: missing apiKey or agentId");
1590
+ return;
1591
+ }
1592
+ this.startedAt = /* @__PURE__ */ new Date();
1593
+ this.connect();
1594
+ }
1595
+ async stop() {
1596
+ this.clearTimers();
1597
+ if (this.isSocketOpen()) {
1598
+ this.sendMessage(ClientEvent.STATUS_REPORT, {
1599
+ participantId: this.config.agentId,
1600
+ status: "shutting_down",
1601
+ version: PLUGIN_VERSION
1602
+ });
1603
+ this.ws.close(1e3, "Plugin shutting down");
1604
+ }
1605
+ this.writeStatus(false);
1606
+ }
1607
+ getWorldState() {
1608
+ return this.latestWorldUpdate;
1609
+ }
1610
+ getBalance() {
1611
+ return this.latestBalance;
1612
+ }
1613
+ drainEvents() {
1614
+ const events = this.eventBuffer;
1615
+ this.eventBuffer = [];
1616
+ return events;
1617
+ }
1618
+ getConnectionStatus() {
1619
+ return {
1620
+ connected: this.connected,
1621
+ authenticated: this.authenticated,
1622
+ reconnectAttempt: this.reconnectAttempt
1623
+ };
1624
+ }
1625
+ send(event, data) {
1626
+ this.sendMessage(event, data);
1627
+ }
1628
+ setOwnerChatHandler(handler) {
1629
+ this.ownerChatHandler = handler;
1630
+ }
1631
+ connect() {
1632
+ this.logger.info(`Connecting to ${this.wsUrl}...`);
1633
+ try {
1634
+ this.ws = this.createSocket(this.wsUrl);
1635
+ } catch (err) {
1636
+ this.logger.error(`Failed to create WebSocket: ${err}`);
1637
+ this.scheduleReconnect();
1638
+ return;
1639
+ }
1640
+ this.ws.on("open", () => this.onOpen());
1641
+ this.ws.on("message", (raw) => this.onRawMessage(raw));
1642
+ this.ws.on("close", (code, reason) => this.onClose(code, reason));
1643
+ this.ws.on("error", (err) => this.logger.error(`WebSocket error: ${err.message}`));
1644
+ }
1645
+ onOpen() {
1646
+ this.connected = true;
1647
+ this.logger.info("WebSocket connected, authenticating...");
1648
+ this.sendMessage(ClientEvent.AUTHENTICATE, {
1649
+ participantId: this.config.agentId,
1650
+ apiKey: this.config.apiKey
1651
+ });
1652
+ }
1653
+ onRawMessage(raw) {
1654
+ try {
1655
+ const msg = JSON.parse(raw.toString());
1656
+ this.routeMessage(msg);
1657
+ } catch (err) {
1658
+ this.logger.error(`Failed to parse WS message: ${err}`);
1659
+ }
1660
+ }
1661
+ onClose(code, reason) {
1662
+ this.connected = false;
1663
+ this.authenticated = false;
1664
+ this.stopHeartbeat();
1665
+ this.logger.info(`WebSocket closed (code=${code}, reason=${reason.toString()})`);
1666
+ this.writeStatus(false);
1667
+ if (!this.authFailed) {
1668
+ this.scheduleReconnect();
1669
+ }
1670
+ }
1671
+ routeMessage(msg) {
1672
+ const handler = this.messageHandlers[msg.event];
1673
+ if (handler) {
1674
+ handler(msg.data);
1675
+ return;
1676
+ }
1677
+ this.logger.info(`Event received: ${msg.event}`);
1678
+ this.bufferEvent(msg.event, msg.data);
1679
+ }
1680
+ onAuthenticated(payload) {
1681
+ this.authenticated = true;
1682
+ this.authFailed = false;
1683
+ this.reconnectAttempt = 0;
1684
+ this.logger.info(
1685
+ `Authenticated as ${payload.participantId} (server v${payload.serverVersion})`
1686
+ );
1687
+ this.startHeartbeat();
1688
+ this.writeStatus(true);
1689
+ }
1690
+ onAuthError(payload) {
1691
+ this.authFailed = true;
1692
+ this.logger.error(`Authentication failed: ${payload.reason}`);
1693
+ }
1694
+ onWorldUpdate(payload) {
1695
+ this.latestWorldUpdate = payload;
1696
+ this.logger.debug("World state updated");
1697
+ }
1698
+ onBalanceUpdate(payload) {
1699
+ this.latestBalance = { balanceCents: payload.balanceCents };
1700
+ this.logger.debug(`Balance updated: ${payload.balanceCents} cents`);
1701
+ }
1702
+ handleOwnerChat(payload) {
1703
+ this.logger.info(`Owner message: ${payload.text.slice(0, 80)}`);
1704
+ this.bufferEvent(ServerEvent.OWNER_CHAT_MESSAGE, payload);
1705
+ this.ownerChatHandler?.(payload);
1706
+ }
1707
+ bufferEvent(event, data) {
1708
+ if (this.eventBuffer.length >= MAX_EVENT_BUFFER_SIZE) {
1709
+ this.eventBuffer.shift();
1710
+ }
1711
+ this.eventBuffer.push({
1712
+ event,
1713
+ data,
1714
+ receivedAt: (/* @__PURE__ */ new Date()).toISOString()
1715
+ });
1716
+ }
1717
+ startHeartbeat() {
1718
+ this.stopHeartbeat();
1719
+ const interval = this.config.heartbeatIntervalMs ?? DEFAULT_HEARTBEAT_MS;
1720
+ this.heartbeatTimer = setInterval(() => this.sendHeartbeat(), interval);
1721
+ }
1722
+ stopHeartbeat() {
1723
+ if (this.heartbeatTimer) {
1724
+ clearInterval(this.heartbeatTimer);
1725
+ this.heartbeatTimer = null;
1726
+ }
1727
+ }
1728
+ sendHeartbeat() {
1729
+ const uptimeSeconds = Math.floor((Date.now() - this.startedAt.getTime()) / 1e3);
1730
+ const memoryUsageMb = Math.round(process.memoryUsage().rss / 1024 / 1024);
1731
+ this.sendMessage(ClientEvent.HEARTBEAT, {
1732
+ participantId: this.config.agentId,
1733
+ uptimeSeconds,
1734
+ memoryUsageMb
1735
+ });
1736
+ }
1737
+ scheduleReconnect() {
1738
+ const jitter = 0.5 + Math.random() * 0.5;
1739
+ const delay = Math.min(
1740
+ BASE_RECONNECT_DELAY_MS * Math.pow(2, this.reconnectAttempt) * jitter,
1741
+ MAX_RECONNECT_DELAY_MS
1742
+ );
1743
+ this.reconnectAttempt++;
1744
+ this.logger.info(
1745
+ `Reconnecting in ${Math.round(delay)}ms (attempt ${this.reconnectAttempt})...`
1746
+ );
1747
+ this.reconnectTimer = setTimeout(() => {
1748
+ this.reconnectTimer = null;
1749
+ this.connect();
1750
+ }, delay);
1751
+ }
1752
+ isSocketOpen() {
1753
+ return this.ws !== null && this.ws.readyState === WebSocket.OPEN;
1754
+ }
1755
+ sendMessage(event, data) {
1756
+ if (!this.isSocketOpen()) {
1757
+ this.logger.warn(`Cannot send ${event}: WebSocket not open`);
1758
+ return;
1759
+ }
1760
+ this.ws.send(JSON.stringify({ event, data }));
1761
+ }
1762
+ clearTimers() {
1763
+ if (this.reconnectTimer) {
1764
+ clearTimeout(this.reconnectTimer);
1765
+ this.reconnectTimer = null;
1766
+ }
1767
+ this.stopHeartbeat();
1768
+ }
1769
+ writeStatus(connected) {
1770
+ try {
1771
+ this.onStatusChange({
1772
+ connected,
1773
+ agentId: this.config.agentId,
1774
+ agentName: this.config.agentName,
1775
+ ...connected ? { connectedAt: (/* @__PURE__ */ new Date()).toISOString() } : { disconnectedAt: (/* @__PURE__ */ new Date()).toISOString() }
1776
+ });
1777
+ } catch (err) {
1778
+ this.logger.error(`Failed to write status file: ${err}`);
1779
+ }
1780
+ }
1781
+ };
1782
+
1783
+ // src/channel.ts
1784
+ var CHANNEL_ID = "stamn";
1785
+ function createStamnChannel(opts) {
1786
+ const { logger, getWsService, getConfig } = opts;
1787
+ return {
1788
+ id: CHANNEL_ID,
1789
+ meta: {
1790
+ id: CHANNEL_ID,
1791
+ label: "Stamn",
1792
+ blurb: "Receive messages from your agent owner via the Stamn platform."
1793
+ },
1794
+ capabilities: {
1795
+ chatTypes: ["direct"]
1796
+ },
1797
+ config: {
1798
+ listAccountIds() {
1799
+ const cfg = getConfig();
1800
+ return cfg?.agentId ? [cfg.agentId] : [];
1801
+ },
1802
+ resolveAccount(_cfg, accountId) {
1803
+ const stamnCfg = getConfig();
1804
+ if (!stamnCfg || stamnCfg.agentId !== accountId) return null;
1805
+ return {
1806
+ accountId: stamnCfg.agentId,
1807
+ agentName: stamnCfg.agentName ?? stamnCfg.agentId,
1808
+ enabled: true
1809
+ };
1810
+ }
1811
+ },
1812
+ outbound: {
1813
+ deliveryMode: "direct",
1814
+ async sendText({ text: text2 }) {
1815
+ const ws = getWsService();
1816
+ const cfg = getConfig();
1817
+ if (!ws || !cfg) {
1818
+ logger.warn("Cannot send reply: WS service or config unavailable");
1819
+ return { ok: false };
1820
+ }
1821
+ ws.send("participant:owner_chat_reply", {
1822
+ participantId: cfg.agentId,
1823
+ text: text2
1824
+ });
1825
+ logger.info("Chat reply sent to owner via channel outbound");
1826
+ return { ok: true };
1827
+ }
1828
+ }
1829
+ };
1830
+ }
1831
+
1832
+ // src/index.ts
1833
+ var index_default = {
1834
+ id: "stamn",
1835
+ name: "Stamn",
1836
+ register(api) {
1837
+ const adapter = createOpenclawAdapter();
1838
+ const config = adapter.readConfig();
1839
+ registerCli(api);
1840
+ if (!config?.apiKey || !config?.agentId) {
1841
+ api.logger.warn('Stamn not configured. Run "stamn agent login" first.');
1842
+ return;
1843
+ }
1844
+ const agentId = config.agentId;
1845
+ let wsService;
1846
+ const stamnChannel = createStamnChannel({
1847
+ logger: api.logger,
1848
+ getWsService: () => wsService,
1849
+ getConfig: () => adapter.readConfig()
1850
+ });
1851
+ api.registerChannel({ plugin: stamnChannel });
1852
+ wsService = new StamnWsService({
1853
+ config,
1854
+ logger: api.logger,
1855
+ wsUrl: getWsUrl(),
1856
+ onStatusChange: (status) => writeStatusFile(status)
1857
+ });
1858
+ wsService.setOwnerChatHandler((payload) => {
1859
+ dispatchOwnerChat(api, wsService, payload, agentId);
1860
+ });
1861
+ api.registerService({
1862
+ id: "stamn-ws",
1863
+ start: () => wsService.start(),
1864
+ stop: () => wsService.stop()
1865
+ });
1866
+ registerTools(api, wsService, config);
1867
+ }
1868
+ };
1869
+ function dispatchOwnerChat(api, wsService, payload, agentId) {
1870
+ api.logger.info(`[stamn-channel] dispatchOwnerChat called: "${payload.text.slice(0, 80)}"`);
1871
+ api.logger.info(`[stamn-channel] api.runtime exists: ${!!api.runtime}`);
1872
+ api.logger.info(`[stamn-channel] api.runtime keys: ${api.runtime ? Object.keys(api.runtime).join(", ") : "N/A"}`);
1873
+ if (!api.runtime?.channel?.reply) {
1874
+ api.logger.warn("[stamn-channel] api.runtime.channel.reply not available \u2014 channel dispatch not supported by this OpenClaw version");
1875
+ api.logger.info(`[stamn-channel] api.runtime.channel: ${api.runtime?.channel ? Object.keys(api.runtime.channel).join(", ") : "N/A"}`);
1876
+ return;
1877
+ }
1878
+ const reply = api.runtime.channel.reply;
1879
+ api.logger.info(`[stamn-channel] channel.reply keys: ${Object.keys(reply).join(", ")}`);
1880
+ try {
1881
+ const { dispatcher, replyOptions } = reply.createReplyDispatcherWithTyping({
1882
+ deliver: async (outbound) => {
1883
+ api.logger.info(`[stamn-channel] deliver called, outbound type: ${typeof outbound}`);
1884
+ api.logger.info(`[stamn-channel] deliver payload: ${JSON.stringify(outbound).slice(0, 200)}`);
1885
+ const text2 = typeof outbound === "string" ? outbound : outbound?.text;
1886
+ if (!text2) {
1887
+ api.logger.warn("[stamn-channel] deliver: no text extracted from outbound");
1888
+ return;
1889
+ }
1890
+ wsService.send("participant:owner_chat_reply", {
1891
+ participantId: agentId,
1892
+ text: text2
1893
+ });
1894
+ api.logger.info("[stamn-channel] Chat reply sent to owner via deliver callback");
1895
+ },
1896
+ channel: "stamn",
1897
+ accountId: agentId
1898
+ });
1899
+ api.logger.info("[stamn-channel] dispatcher created, calling dispatchReplyFromConfig...");
1900
+ reply.dispatchReplyFromConfig({
1901
+ ctx: {
1902
+ BodyForAgent: payload.text,
1903
+ ChatType: "direct",
1904
+ MessageSid: payload.messageId
1905
+ },
1906
+ cfg: api.config,
1907
+ dispatcher,
1908
+ replyOptions
1909
+ }).then((result) => {
1910
+ api.logger.info(`[stamn-channel] dispatchReplyFromConfig resolved: ${JSON.stringify(result)}`);
1911
+ }).catch((err) => {
1912
+ api.logger.error(`[stamn-channel] dispatchReplyFromConfig failed: ${err}`);
1913
+ });
1914
+ } catch (err) {
1915
+ api.logger.error(`[stamn-channel] dispatchOwnerChat threw: ${err}`);
1916
+ }
1917
+ }
74
1918
  export {
1919
+ StamnWsService,
75
1920
  createOpenclawAdapter,
76
- registerCli
1921
+ index_default as default,
1922
+ getWsUrl,
1923
+ registerCli,
1924
+ writeStatusFile
77
1925
  };
78
1926
  //# sourceMappingURL=index.js.map