@mx-space/cli 0.1.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.
Files changed (190) hide show
  1. package/LICENSE +33 -0
  2. package/README.md +375 -0
  3. package/ROADMAP.md +42 -0
  4. package/bin/mxs.cjs +40 -0
  5. package/dist/Lexical.dev-DpU35QTu.mjs +10992 -0
  6. package/dist/Lexical.dev-DpU35QTu.mjs.map +1 -0
  7. package/dist/Lexical.node-gYNDt_p9.mjs +247 -0
  8. package/dist/Lexical.node-gYNDt_p9.mjs.map +1 -0
  9. package/dist/Lexical.prod-t4c3bHV3.mjs +5579 -0
  10. package/dist/Lexical.prod-t4c3bHV3.mjs.map +1 -0
  11. package/dist/LexicalClipboard.dev-CdeeWCIq.mjs +496 -0
  12. package/dist/LexicalClipboard.dev-CdeeWCIq.mjs.map +1 -0
  13. package/dist/LexicalClipboard.node-0e9GBL1g.mjs +26 -0
  14. package/dist/LexicalClipboard.node-0e9GBL1g.mjs.map +1 -0
  15. package/dist/LexicalClipboard.prod-CsCWYmV7.mjs +293 -0
  16. package/dist/LexicalClipboard.prod-CsCWYmV7.mjs.map +1 -0
  17. package/dist/LexicalCodeCore.dev-haI2cqH8.mjs +539 -0
  18. package/dist/LexicalCodeCore.dev-haI2cqH8.mjs.map +1 -0
  19. package/dist/LexicalCodeCore.prod-D_k7zuE5.mjs +383 -0
  20. package/dist/LexicalCodeCore.prod-D_k7zuE5.mjs.map +1 -0
  21. package/dist/LexicalDragon.dev-CAggdFh_.mjs +90 -0
  22. package/dist/LexicalDragon.dev-CAggdFh_.mjs.map +1 -0
  23. package/dist/LexicalDragon.node-QMR_wqJg.mjs +15 -0
  24. package/dist/LexicalDragon.node-QMR_wqJg.mjs.map +1 -0
  25. package/dist/LexicalDragon.prod-OssQhwS-.mjs +61 -0
  26. package/dist/LexicalDragon.prod-OssQhwS-.mjs.map +1 -0
  27. package/dist/LexicalExtension.dev-CtDZiMCU.mjs +1665 -0
  28. package/dist/LexicalExtension.dev-CtDZiMCU.mjs.map +1 -0
  29. package/dist/LexicalExtension.node-BM0gh8zu.mjs +51 -0
  30. package/dist/LexicalExtension.node-BM0gh8zu.mjs.map +1 -0
  31. package/dist/LexicalExtension.prod-Ug6emhEO.mjs +971 -0
  32. package/dist/LexicalExtension.prod-Ug6emhEO.mjs.map +1 -0
  33. package/dist/LexicalHeadless.dev-D4yQpl_s.mjs +45 -0
  34. package/dist/LexicalHeadless.dev-D4yQpl_s.mjs.map +1 -0
  35. package/dist/LexicalHeadless.prod-jeN65B3k.mjs +31 -0
  36. package/dist/LexicalHeadless.prod-jeN65B3k.mjs.map +1 -0
  37. package/dist/LexicalHtml.dev-BdU1_ITQ.mjs +686 -0
  38. package/dist/LexicalHtml.dev-BdU1_ITQ.mjs.map +1 -0
  39. package/dist/LexicalHtml.node-DLtAh00E.mjs +26 -0
  40. package/dist/LexicalHtml.node-DLtAh00E.mjs.map +1 -0
  41. package/dist/LexicalHtml.prod-DdLE1HHT.mjs +432 -0
  42. package/dist/LexicalHtml.prod-DdLE1HHT.mjs.map +1 -0
  43. package/dist/LexicalLink.dev-DK87Biuy.mjs +1084 -0
  44. package/dist/LexicalLink.dev-DK87Biuy.mjs.map +1 -0
  45. package/dist/LexicalLink.prod-fssuv6Sf.mjs +717 -0
  46. package/dist/LexicalLink.prod-fssuv6Sf.mjs.map +1 -0
  47. package/dist/LexicalList.dev-BJ4dr_rk.mjs +1352 -0
  48. package/dist/LexicalList.dev-BJ4dr_rk.mjs.map +1 -0
  49. package/dist/LexicalList.prod-jWBbaWfi.mjs +841 -0
  50. package/dist/LexicalList.prod-jWBbaWfi.mjs.map +1 -0
  51. package/dist/LexicalMarkdown.dev-C8e-eh6y.mjs +1207 -0
  52. package/dist/LexicalMarkdown.dev-C8e-eh6y.mjs.map +1 -0
  53. package/dist/LexicalMarkdown.prod-k73tZVb2.mjs +756 -0
  54. package/dist/LexicalMarkdown.prod-k73tZVb2.mjs.map +1 -0
  55. package/dist/LexicalRichText.dev-CrSqq3K-.mjs +645 -0
  56. package/dist/LexicalRichText.dev-CrSqq3K-.mjs.map +1 -0
  57. package/dist/LexicalRichText.node-B7k7wlQz.mjs +106 -0
  58. package/dist/LexicalRichText.node-B7k7wlQz.mjs.map +1 -0
  59. package/dist/LexicalRichText.prod-CqvyxQ9m.mjs +429 -0
  60. package/dist/LexicalRichText.prod-CqvyxQ9m.mjs.map +1 -0
  61. package/dist/LexicalSelection.dev-sNOHKHe_.mjs +725 -0
  62. package/dist/LexicalSelection.dev-sNOHKHe_.mjs.map +1 -0
  63. package/dist/LexicalSelection.node-Di7GwBCZ.mjs +38 -0
  64. package/dist/LexicalSelection.node-Di7GwBCZ.mjs.map +1 -0
  65. package/dist/LexicalSelection.prod-SWllPJop.mjs +388 -0
  66. package/dist/LexicalSelection.prod-SWllPJop.mjs.map +1 -0
  67. package/dist/LexicalTable.dev-CQkLHXJx.mjs +3262 -0
  68. package/dist/LexicalTable.dev-CQkLHXJx.mjs.map +1 -0
  69. package/dist/LexicalTable.prod-BtqCwKSi.mjs +2218 -0
  70. package/dist/LexicalTable.prod-BtqCwKSi.mjs.map +1 -0
  71. package/dist/LexicalUtils.dev-DiUpsXE8.mjs +850 -0
  72. package/dist/LexicalUtils.dev-DiUpsXE8.mjs.map +1 -0
  73. package/dist/LexicalUtils.node-CmK462d1.mjs +66 -0
  74. package/dist/LexicalUtils.node-CmK462d1.mjs.map +1 -0
  75. package/dist/LexicalUtils.prod-bWwV4GAF.mjs +377 -0
  76. package/dist/LexicalUtils.prod-bWwV4GAF.mjs.map +1 -0
  77. package/dist/auth-DIFZzoMm.mjs +211 -0
  78. package/dist/auth-DIFZzoMm.mjs.map +1 -0
  79. package/dist/bin/mxs.d.mts +927 -0
  80. package/dist/bin/mxs.mjs +3249 -0
  81. package/dist/bin/mxs.mjs.map +1 -0
  82. package/dist/chunk-hT5z_Zn9.mjs +35 -0
  83. package/dist/config-store-DIu7x0ao.mjs +121 -0
  84. package/dist/config-store-DIu7x0ao.mjs.map +1 -0
  85. package/dist/create-B2AOQL1e.mjs +24 -0
  86. package/dist/create-B2AOQL1e.mjs.map +1 -0
  87. package/dist/create-CwjGcv2n.mjs +23 -0
  88. package/dist/create-CwjGcv2n.mjs.map +1 -0
  89. package/dist/create-DT1l2hue.mjs +23 -0
  90. package/dist/create-DT1l2hue.mjs.map +1 -0
  91. package/dist/create-DjlRHPXy.mjs +23 -0
  92. package/dist/create-DjlRHPXy.mjs.map +1 -0
  93. package/dist/create-Dz6rJJSS.mjs +19 -0
  94. package/dist/create-Dz6rJJSS.mjs.map +1 -0
  95. package/dist/delete-B4dGrrus.mjs +22 -0
  96. package/dist/delete-B4dGrrus.mjs.map +1 -0
  97. package/dist/delete-BH6ZngTz.mjs +22 -0
  98. package/dist/delete-BH6ZngTz.mjs.map +1 -0
  99. package/dist/delete-BrY5zJ6S.mjs +22 -0
  100. package/dist/delete-BrY5zJ6S.mjs.map +1 -0
  101. package/dist/delete-CaG2d_xt.mjs +31 -0
  102. package/dist/delete-CaG2d_xt.mjs.map +1 -0
  103. package/dist/delete-YzRliRn8.mjs +31 -0
  104. package/dist/delete-YzRliRn8.mjs.map +1 -0
  105. package/dist/document-output-BVB8emLt.mjs +145 -0
  106. package/dist/document-output-BVB8emLt.mjs.map +1 -0
  107. package/dist/edit-Bb0Ze4w6.mjs +79 -0
  108. package/dist/edit-Bb0Ze4w6.mjs.map +1 -0
  109. package/dist/edit-BeFmC3XD.mjs +80 -0
  110. package/dist/edit-BeFmC3XD.mjs.map +1 -0
  111. package/dist/edit-DLDw_ZWX.mjs +86 -0
  112. package/dist/edit-DLDw_ZWX.mjs.map +1 -0
  113. package/dist/edit-z55ofr1S.mjs +40 -0
  114. package/dist/edit-z55ofr1S.mjs.map +1 -0
  115. package/dist/editor-xrF-j3UE.mjs +42 -0
  116. package/dist/editor-xrF-j3UE.mjs.map +1 -0
  117. package/dist/envelope-overlays-DPAlMNW1.mjs +26 -0
  118. package/dist/envelope-overlays-DPAlMNW1.mjs.map +1 -0
  119. package/dist/get-2qjq0wgG.mjs +28 -0
  120. package/dist/get-2qjq0wgG.mjs.map +1 -0
  121. package/dist/get-BGAk1Zmv.mjs +14 -0
  122. package/dist/get-BGAk1Zmv.mjs.map +1 -0
  123. package/dist/get-CRR13lgj.mjs +10 -0
  124. package/dist/get-CRR13lgj.mjs.map +1 -0
  125. package/dist/get-ClkpDBTL.mjs +13 -0
  126. package/dist/get-ClkpDBTL.mjs.map +1 -0
  127. package/dist/get-DJfUJ3sP.mjs +10 -0
  128. package/dist/get-DJfUJ3sP.mjs.map +1 -0
  129. package/dist/get-DiqaQvoS.mjs +14 -0
  130. package/dist/get-DiqaQvoS.mjs.map +1 -0
  131. package/dist/index.d.mts +338 -0
  132. package/dist/index.mjs +10 -0
  133. package/dist/list-BYzhflDg.mjs +14 -0
  134. package/dist/list-BYzhflDg.mjs.map +1 -0
  135. package/dist/list-DY-tPNG-.mjs +10 -0
  136. package/dist/list-DY-tPNG-.mjs.map +1 -0
  137. package/dist/list-DlQSkbqx.mjs +10 -0
  138. package/dist/list-DlQSkbqx.mjs.map +1 -0
  139. package/dist/list-DsrA5wIz.mjs +15 -0
  140. package/dist/list-DsrA5wIz.mjs.map +1 -0
  141. package/dist/list-Fp4nKfQb.mjs +10 -0
  142. package/dist/list-Fp4nKfQb.mjs.map +1 -0
  143. package/dist/list-s_tloiEX.mjs +10 -0
  144. package/dist/list-s_tloiEX.mjs.map +1 -0
  145. package/dist/litexml-codec-CDoRloiR.mjs +13451 -0
  146. package/dist/litexml-codec-CDoRloiR.mjs.map +1 -0
  147. package/dist/login-CLOJ-fTJ.mjs +579 -0
  148. package/dist/login-CLOJ-fTJ.mjs.map +1 -0
  149. package/dist/logout-v8ihxsim.mjs +11 -0
  150. package/dist/logout-v8ihxsim.mjs.map +1 -0
  151. package/dist/onboarding-640IldLz.mjs +888 -0
  152. package/dist/onboarding-640IldLz.mjs.map +1 -0
  153. package/dist/output-BM7aBFwt.mjs +120 -0
  154. package/dist/output-BM7aBFwt.mjs.map +1 -0
  155. package/dist/output-CTnO1lYt.d.mts +16 -0
  156. package/dist/payload-CN11pUto.mjs +547 -0
  157. package/dist/payload-CN11pUto.mjs.map +1 -0
  158. package/dist/publish-DkTYB-eK.mjs +23 -0
  159. package/dist/publish-DkTYB-eK.mjs.map +1 -0
  160. package/dist/publish-pRBfTJfe.mjs +23 -0
  161. package/dist/publish-pRBfTJfe.mjs.map +1 -0
  162. package/dist/resolve-BogJOR7R.mjs +119 -0
  163. package/dist/resolve-BogJOR7R.mjs.map +1 -0
  164. package/dist/resolve-Bp1AfBmM.mjs +26 -0
  165. package/dist/resolve-Bp1AfBmM.mjs.map +1 -0
  166. package/dist/resolve-Bw5Po9yK.mjs +16 -0
  167. package/dist/resolve-Bw5Po9yK.mjs.map +1 -0
  168. package/dist/resolve-CyjMlaoJ.mjs +23 -0
  169. package/dist/resolve-CyjMlaoJ.mjs.map +1 -0
  170. package/dist/resolve-helpers-CahPoJ0Y.mjs +30 -0
  171. package/dist/resolve-helpers-CahPoJ0Y.mjs.map +1 -0
  172. package/dist/set-BEGQz2si.mjs +43 -0
  173. package/dist/set-BEGQz2si.mjs.map +1 -0
  174. package/dist/shared-D0HVBDHI.mjs +39 -0
  175. package/dist/shared-D0HVBDHI.mjs.map +1 -0
  176. package/dist/status-LXrN9fI-.mjs +22 -0
  177. package/dist/status-LXrN9fI-.mjs.map +1 -0
  178. package/dist/update-B9ynFCdZ.mjs +30 -0
  179. package/dist/update-B9ynFCdZ.mjs.map +1 -0
  180. package/dist/update-BMZQPOvR.mjs +28 -0
  181. package/dist/update-BMZQPOvR.mjs.map +1 -0
  182. package/dist/update-BXz0l7Lz.mjs +36 -0
  183. package/dist/update-BXz0l7Lz.mjs.map +1 -0
  184. package/dist/update-Dx6AF8tf.mjs +30 -0
  185. package/dist/update-Dx6AF8tf.mjs.map +1 -0
  186. package/dist/update-q66TLS38.mjs +37 -0
  187. package/dist/update-q66TLS38.mjs.map +1 -0
  188. package/dist/whoami-CTkctOEd.mjs +22 -0
  189. package/dist/whoami-CTkctOEd.mjs.map +1 -0
  190. package/package.json +77 -0
@@ -0,0 +1,888 @@
1
+ import { t as __commonJSMin } from "./chunk-hT5z_Zn9.mjs";
2
+ import { s as MxsError } from "./output-BM7aBFwt.mjs";
3
+ import { c as readCredentials, d as writeCredentials, o as normalizeApiUrl, s as readConfig, u as writeConfig } from "./config-store-DIu7x0ao.mjs";
4
+ import { c as refreshAccessToken, n as defaultHttp, r as ensureFreshToken, s as probeAuthEndpoint } from "./auth-DIFZzoMm.mjs";
5
+ import "node:path";
6
+ import "node:fs";
7
+ import V, { stdin, stdout } from "node:process";
8
+ import { stripVTControlCharacters, styleText } from "node:util";
9
+ import "node:readline";
10
+ import E from "node:readline";
11
+ import "node:tty";
12
+ //#region src/core/api-client.ts
13
+ var ApiClient = class {
14
+ ctx;
15
+ http;
16
+ token;
17
+ refreshed = false;
18
+ constructor(ctx) {
19
+ this.ctx = ctx;
20
+ this.http = ctx.http ?? defaultHttp();
21
+ this.token = ctx.token;
22
+ }
23
+ get apiBase() {
24
+ return this.ctx.apiBase;
25
+ }
26
+ async request(path, options = {}) {
27
+ if (this.ctx.autoRefresh && this.token) await this.tryRefresh();
28
+ const url = buildUrl(this.ctx.apiBase, path, options.query);
29
+ const method = options.method ?? "GET";
30
+ const headers = {
31
+ accept: "application/json",
32
+ ...options.headers
33
+ };
34
+ if (this.token) headers.authorization = `Bearer ${this.token}`;
35
+ if (this.ctx.apiKey) headers["x-api-key"] = this.ctx.apiKey;
36
+ if (options.body !== void 0 && !(options.body instanceof FormData)) headers["content-type"] ??= "application/json";
37
+ const startedAt = Date.now();
38
+ let res = await this.http.fetch(url, {
39
+ method,
40
+ headers,
41
+ body: options.body === void 0 ? void 0 : options.body instanceof FormData ? options.body : JSON.stringify(options.body),
42
+ signal: options.signal
43
+ });
44
+ if (this.ctx.verbose) process.stderr.write(`${method} ${url} → ${res.status} (${Date.now() - startedAt}ms)\n`);
45
+ if (res.status === 401 && !this.refreshed && this.token) {
46
+ const refreshed = await this.tryRefresh();
47
+ if (refreshed) {
48
+ this.refreshed = true;
49
+ headers.authorization = `Bearer ${refreshed.access_token}`;
50
+ this.token = refreshed.access_token;
51
+ res = await this.http.fetch(url, {
52
+ method,
53
+ headers,
54
+ body: options.body === void 0 ? void 0 : options.body instanceof FormData ? options.body : JSON.stringify(options.body),
55
+ signal: options.signal
56
+ });
57
+ }
58
+ }
59
+ const data = await parseBody(res);
60
+ if (res.ok) return {
61
+ ok: true,
62
+ status: res.status,
63
+ data
64
+ };
65
+ throw toMxsError(res.status, data);
66
+ }
67
+ async tryRefresh() {
68
+ const current = await readCredentials();
69
+ if (!current) return null;
70
+ if (this.token && current.access_token !== this.token) return null;
71
+ const refreshed = await refreshAccessToken(this.ctx.authBase, this.ctx.clientId, current, this.http);
72
+ if (!refreshed) return null;
73
+ await writeCredentials(refreshed);
74
+ this.token = refreshed.access_token;
75
+ return refreshed;
76
+ }
77
+ };
78
+ async function createApiClient(ctx) {
79
+ if (!ctx.token) return new ApiClient(ctx);
80
+ const fresh = await ensureFreshToken(ctx.authBase, ctx.clientId, ctx.http ?? defaultHttp()).catch(() => null);
81
+ if (fresh) return new ApiClient({
82
+ ...ctx,
83
+ token: fresh.access_token
84
+ });
85
+ return new ApiClient(ctx);
86
+ }
87
+ function buildUrl(base, path, query) {
88
+ const url = new URL(path.startsWith("/") ? path.slice(1) : path, base.endsWith("/") ? base : `${base}/`);
89
+ if (query) for (const [k, v] of Object.entries(query)) {
90
+ if (v === void 0 || v === null) continue;
91
+ url.searchParams.set(k, String(v));
92
+ }
93
+ return url.toString();
94
+ }
95
+ async function parseBody(res) {
96
+ if ((res.headers.get("content-type") ?? "").includes("application/json")) try {
97
+ return await res.json();
98
+ } catch {
99
+ return;
100
+ }
101
+ return await res.text();
102
+ }
103
+ function toMxsError(status, body) {
104
+ if (status === 401) return new MxsError({
105
+ code: "auth.expired",
106
+ message: "authentication required",
107
+ hint: "run `mxs auth login`",
108
+ details: body
109
+ });
110
+ if (status === 403) return new MxsError({
111
+ code: "auth.denied",
112
+ message: "permission denied",
113
+ details: body
114
+ });
115
+ if (status === 404) return new MxsError({
116
+ code: "resource.not_found",
117
+ message: "resource not found",
118
+ details: body
119
+ });
120
+ if (status === 422 || status === 400) return new MxsError({
121
+ code: "validation.failed",
122
+ message: extractMessage(body) ?? "validation failed",
123
+ details: body
124
+ });
125
+ if (status >= 500) return new MxsError({
126
+ code: "server.error",
127
+ message: extractMessage(body) ?? `server error (${status})`,
128
+ details: body
129
+ });
130
+ return new MxsError({
131
+ code: "generic",
132
+ message: extractMessage(body) ?? `request failed (${status})`,
133
+ details: body
134
+ });
135
+ }
136
+ function extractMessage(body) {
137
+ if (!body || typeof body !== "object") return null;
138
+ const msg = body.message;
139
+ if (typeof msg === "string") return msg;
140
+ if (Array.isArray(msg) && typeof msg[0] === "string") return msg.join("; ");
141
+ return null;
142
+ }
143
+ //#endregion
144
+ //#region ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/utils.js
145
+ const getCodePointsLength = (() => {
146
+ const SURROGATE_PAIR_RE = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
147
+ return (input) => {
148
+ let surrogatePairsNr = 0;
149
+ SURROGATE_PAIR_RE.lastIndex = 0;
150
+ while (SURROGATE_PAIR_RE.test(input)) surrogatePairsNr += 1;
151
+ return input.length - surrogatePairsNr;
152
+ };
153
+ })();
154
+ const isFullWidth = (x) => {
155
+ return x === 12288 || x >= 65281 && x <= 65376 || x >= 65504 && x <= 65510;
156
+ };
157
+ const isWideNotCJKTNotEmoji = (x) => {
158
+ return x === 8987 || x === 9001 || x >= 12272 && x <= 12287 || x >= 12289 && x <= 12350 || x >= 12441 && x <= 12543 || x >= 12549 && x <= 12591 || x >= 12593 && x <= 12686 || x >= 12688 && x <= 12771 || x >= 12783 && x <= 12830 || x >= 12832 && x <= 12871 || x >= 12880 && x <= 19903 || x >= 65040 && x <= 65049 || x >= 65072 && x <= 65106 || x >= 65108 && x <= 65126 || x >= 65128 && x <= 65131 || x >= 127488 && x <= 127490 || x >= 127504 && x <= 127547 || x >= 127552 && x <= 127560 || x >= 131072 && x <= 196605 || x >= 196608 && x <= 262141;
159
+ };
160
+ //#endregion
161
+ //#region ../../node_modules/.pnpm/fast-string-truncated-width@3.0.3/node_modules/fast-string-truncated-width/dist/index.js
162
+ const ANSI_RE = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y;
163
+ const CONTROL_RE = /[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y;
164
+ const CJKT_WIDE_RE = /(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy;
165
+ const TAB_RE = /\t{1,1000}/y;
166
+ const EMOJI_RE = /[\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?))*/uy;
167
+ const LATIN_RE = /(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y;
168
+ const MODIFIER_RE = /\p{M}+/gu;
169
+ const NO_TRUNCATION$1 = {
170
+ limit: Infinity,
171
+ ellipsis: ""
172
+ };
173
+ const getStringTruncatedWidth = (input, truncationOptions = {}, widthOptions = {}) => {
174
+ const LIMIT = truncationOptions.limit ?? Infinity;
175
+ const ELLIPSIS = truncationOptions.ellipsis ?? "";
176
+ const ELLIPSIS_WIDTH = truncationOptions?.ellipsisWidth ?? (ELLIPSIS ? getStringTruncatedWidth(ELLIPSIS, NO_TRUNCATION$1, widthOptions).width : 0);
177
+ const ANSI_WIDTH = 0;
178
+ const CONTROL_WIDTH = widthOptions.controlWidth ?? 0;
179
+ const TAB_WIDTH = widthOptions.tabWidth ?? 8;
180
+ const EMOJI_WIDTH = widthOptions.emojiWidth ?? 2;
181
+ const FULL_WIDTH_WIDTH = 2;
182
+ const REGULAR_WIDTH = widthOptions.regularWidth ?? 1;
183
+ const WIDE_WIDTH = widthOptions.wideWidth ?? FULL_WIDTH_WIDTH;
184
+ const PARSE_BLOCKS = [
185
+ [LATIN_RE, REGULAR_WIDTH],
186
+ [ANSI_RE, ANSI_WIDTH],
187
+ [CONTROL_RE, CONTROL_WIDTH],
188
+ [TAB_RE, TAB_WIDTH],
189
+ [EMOJI_RE, EMOJI_WIDTH],
190
+ [CJKT_WIDE_RE, WIDE_WIDTH]
191
+ ];
192
+ let indexPrev = 0;
193
+ let index = 0;
194
+ let length = input.length;
195
+ let lengthExtra = 0;
196
+ let truncationEnabled = false;
197
+ let truncationIndex = length;
198
+ let truncationLimit = Math.max(0, LIMIT - ELLIPSIS_WIDTH);
199
+ let unmatchedStart = 0;
200
+ let unmatchedEnd = 0;
201
+ let width = 0;
202
+ let widthExtra = 0;
203
+ outer: while (true) {
204
+ if (unmatchedEnd > unmatchedStart || index >= length && index > indexPrev) {
205
+ const unmatched = input.slice(unmatchedStart, unmatchedEnd) || input.slice(indexPrev, index);
206
+ lengthExtra = 0;
207
+ for (const char of unmatched.replaceAll(MODIFIER_RE, "")) {
208
+ const codePoint = char.codePointAt(0) || 0;
209
+ if (isFullWidth(codePoint)) widthExtra = FULL_WIDTH_WIDTH;
210
+ else if (isWideNotCJKTNotEmoji(codePoint)) widthExtra = WIDE_WIDTH;
211
+ else widthExtra = REGULAR_WIDTH;
212
+ if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, Math.max(unmatchedStart, indexPrev) + lengthExtra);
213
+ if (width + widthExtra > LIMIT) {
214
+ truncationEnabled = true;
215
+ break outer;
216
+ }
217
+ lengthExtra += char.length;
218
+ width += widthExtra;
219
+ }
220
+ unmatchedStart = unmatchedEnd = 0;
221
+ }
222
+ if (index >= length) break outer;
223
+ for (let i = 0, l = PARSE_BLOCKS.length; i < l; i++) {
224
+ const [BLOCK_RE, BLOCK_WIDTH] = PARSE_BLOCKS[i];
225
+ BLOCK_RE.lastIndex = index;
226
+ if (BLOCK_RE.test(input)) {
227
+ lengthExtra = BLOCK_RE === CJKT_WIDE_RE ? getCodePointsLength(input.slice(index, BLOCK_RE.lastIndex)) : BLOCK_RE === EMOJI_RE ? 1 : BLOCK_RE.lastIndex - index;
228
+ widthExtra = lengthExtra * BLOCK_WIDTH;
229
+ if (width + widthExtra > truncationLimit) truncationIndex = Math.min(truncationIndex, index + Math.floor((truncationLimit - width) / BLOCK_WIDTH));
230
+ if (width + widthExtra > LIMIT) {
231
+ truncationEnabled = true;
232
+ break outer;
233
+ }
234
+ width += widthExtra;
235
+ unmatchedStart = indexPrev;
236
+ unmatchedEnd = index;
237
+ index = indexPrev = BLOCK_RE.lastIndex;
238
+ continue outer;
239
+ }
240
+ }
241
+ index += 1;
242
+ }
243
+ return {
244
+ width: truncationEnabled ? truncationLimit : width,
245
+ index: truncationEnabled ? truncationIndex : length,
246
+ truncated: truncationEnabled,
247
+ ellipsed: truncationEnabled && LIMIT >= ELLIPSIS_WIDTH
248
+ };
249
+ };
250
+ //#endregion
251
+ //#region ../../node_modules/.pnpm/fast-string-width@3.0.2/node_modules/fast-string-width/dist/index.js
252
+ const NO_TRUNCATION = {
253
+ limit: Infinity,
254
+ ellipsis: "",
255
+ ellipsisWidth: 0
256
+ };
257
+ const fastStringWidth = (input, options = {}) => {
258
+ return getStringTruncatedWidth(input, NO_TRUNCATION, options).width;
259
+ };
260
+ //#endregion
261
+ //#region ../../node_modules/.pnpm/fast-wrap-ansi@0.2.0/node_modules/fast-wrap-ansi/lib/main.js
262
+ const ESC = "\x1B";
263
+ const CSI = "›";
264
+ const END_CODE = 39;
265
+ const ANSI_ESCAPE_BELL = "\x07";
266
+ const ANSI_CSI = "[";
267
+ const ANSI_OSC = "]";
268
+ const ANSI_SGR_TERMINATOR = "m";
269
+ const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;
270
+ const GROUP_REGEX = new RegExp(`(?:\\${ANSI_CSI}(?<code>\\d+)m|\\${ANSI_ESCAPE_LINK}(?<uri>.*)${ANSI_ESCAPE_BELL})`, "y");
271
+ const getClosingCode = (openingCode) => {
272
+ if (openingCode >= 30 && openingCode <= 37) return 39;
273
+ if (openingCode >= 90 && openingCode <= 97) return 39;
274
+ if (openingCode >= 40 && openingCode <= 47) return 49;
275
+ if (openingCode >= 100 && openingCode <= 107) return 49;
276
+ if (openingCode === 1 || openingCode === 2) return 22;
277
+ if (openingCode === 3) return 23;
278
+ if (openingCode === 4) return 24;
279
+ if (openingCode === 7) return 27;
280
+ if (openingCode === 8) return 28;
281
+ if (openingCode === 9) return 29;
282
+ if (openingCode === 0) return 0;
283
+ };
284
+ const wrapAnsiCode = (code) => `${ESC}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
285
+ const wrapAnsiHyperlink = (url) => `${ESC}${ANSI_ESCAPE_LINK}${url}${ANSI_ESCAPE_BELL}`;
286
+ const wrapWord = (rows, word, columns) => {
287
+ const characters = word[Symbol.iterator]();
288
+ let isInsideEscape = false;
289
+ let isInsideLinkEscape = false;
290
+ let lastRow = rows.at(-1);
291
+ let visible = lastRow === void 0 ? 0 : fastStringWidth(lastRow);
292
+ let currentCharacter = characters.next();
293
+ let nextCharacter = characters.next();
294
+ let rawCharacterIndex = 0;
295
+ while (!currentCharacter.done) {
296
+ const character = currentCharacter.value;
297
+ const characterLength = fastStringWidth(character);
298
+ if (visible + characterLength <= columns) rows[rows.length - 1] += character;
299
+ else {
300
+ rows.push(character);
301
+ visible = 0;
302
+ }
303
+ if (character === ESC || character === CSI) {
304
+ isInsideEscape = true;
305
+ isInsideLinkEscape = word.startsWith(ANSI_ESCAPE_LINK, rawCharacterIndex + 1);
306
+ }
307
+ if (isInsideEscape) {
308
+ if (isInsideLinkEscape) {
309
+ if (character === ANSI_ESCAPE_BELL) {
310
+ isInsideEscape = false;
311
+ isInsideLinkEscape = false;
312
+ }
313
+ } else if (character === ANSI_SGR_TERMINATOR) isInsideEscape = false;
314
+ } else {
315
+ visible += characterLength;
316
+ if (visible === columns && !nextCharacter.done) {
317
+ rows.push("");
318
+ visible = 0;
319
+ }
320
+ }
321
+ currentCharacter = nextCharacter;
322
+ nextCharacter = characters.next();
323
+ rawCharacterIndex += character.length;
324
+ }
325
+ lastRow = rows.at(-1);
326
+ if (!visible && lastRow !== void 0 && lastRow.length && rows.length > 1) rows[rows.length - 2] += rows.pop();
327
+ };
328
+ const stringVisibleTrimSpacesRight = (string) => {
329
+ const words = string.split(" ");
330
+ let last = words.length;
331
+ while (last) {
332
+ if (fastStringWidth(words[last - 1])) break;
333
+ last--;
334
+ }
335
+ if (last === words.length) return string;
336
+ return words.slice(0, last).join(" ") + words.slice(last).join("");
337
+ };
338
+ const exec = (string, columns, options = {}) => {
339
+ if (options.trim !== false && string.trim() === "") return "";
340
+ let returnValue = "";
341
+ let escapeCode;
342
+ let escapeUrl;
343
+ const words = string.split(" ");
344
+ let rows = [""];
345
+ let rowLength = 0;
346
+ for (let index = 0; index < words.length; index++) {
347
+ const word = words[index];
348
+ if (options.trim !== false) {
349
+ const row = rows.at(-1) ?? "";
350
+ const trimmed = row.trimStart();
351
+ if (row.length !== trimmed.length) {
352
+ rows[rows.length - 1] = trimmed;
353
+ rowLength = fastStringWidth(trimmed);
354
+ }
355
+ }
356
+ if (index !== 0) {
357
+ if (rowLength >= columns && (options.wordWrap === false || options.trim === false)) {
358
+ rows.push("");
359
+ rowLength = 0;
360
+ }
361
+ if (rowLength || options.trim === false) {
362
+ rows[rows.length - 1] += " ";
363
+ rowLength++;
364
+ }
365
+ }
366
+ const wordLength = fastStringWidth(word);
367
+ if (options.hard && wordLength > columns) {
368
+ const remainingColumns = columns - rowLength;
369
+ const breaksStartingThisLine = 1 + Math.floor((wordLength - remainingColumns - 1) / columns);
370
+ if (Math.floor((wordLength - 1) / columns) < breaksStartingThisLine) rows.push("");
371
+ wrapWord(rows, word, columns);
372
+ rowLength = fastStringWidth(rows.at(-1) ?? "");
373
+ continue;
374
+ }
375
+ if (rowLength + wordLength > columns && rowLength && wordLength) {
376
+ if (options.wordWrap === false && rowLength < columns) {
377
+ wrapWord(rows, word, columns);
378
+ rowLength = fastStringWidth(rows.at(-1) ?? "");
379
+ continue;
380
+ }
381
+ rows.push("");
382
+ rowLength = 0;
383
+ }
384
+ if (rowLength + wordLength > columns && options.wordWrap === false) {
385
+ wrapWord(rows, word, columns);
386
+ rowLength = fastStringWidth(rows.at(-1) ?? "");
387
+ continue;
388
+ }
389
+ rows[rows.length - 1] += word;
390
+ rowLength += wordLength;
391
+ }
392
+ if (options.trim !== false) rows = rows.map((row) => stringVisibleTrimSpacesRight(row));
393
+ const preString = rows.join("\n");
394
+ let inSurrogate = false;
395
+ for (let i = 0; i < preString.length; i++) {
396
+ const character = preString[i];
397
+ returnValue += character;
398
+ if (!inSurrogate) {
399
+ inSurrogate = character >= "\ud800" && character <= "\udbff";
400
+ if (inSurrogate) continue;
401
+ } else inSurrogate = false;
402
+ if (character === ESC || character === CSI) {
403
+ GROUP_REGEX.lastIndex = i + 1;
404
+ const groups = GROUP_REGEX.exec(preString)?.groups;
405
+ if (groups?.code !== void 0) {
406
+ const code = Number.parseFloat(groups.code);
407
+ escapeCode = code === END_CODE ? void 0 : code;
408
+ } else if (groups?.uri !== void 0) escapeUrl = groups.uri.length === 0 ? void 0 : groups.uri;
409
+ }
410
+ if (preString[i + 1] === "\n") {
411
+ if (escapeUrl) returnValue += wrapAnsiHyperlink("");
412
+ const closingCode = escapeCode ? getClosingCode(escapeCode) : void 0;
413
+ if (escapeCode && closingCode) returnValue += wrapAnsiCode(closingCode);
414
+ } else if (character === "\n") {
415
+ if (escapeCode && getClosingCode(escapeCode)) returnValue += wrapAnsiCode(escapeCode);
416
+ if (escapeUrl) returnValue += wrapAnsiHyperlink(escapeUrl);
417
+ }
418
+ }
419
+ return returnValue;
420
+ };
421
+ const CRLF_OR_LF = /\r?\n/;
422
+ function wrapAnsi(string, columns, options) {
423
+ return String(string).normalize().split(CRLF_OR_LF).map((line) => exec(line, columns, options)).join("\n");
424
+ }
425
+ //#endregion
426
+ //#region ../../node_modules/.pnpm/@clack+core@1.3.1/node_modules/@clack/core/dist/index.mjs
427
+ var import_src = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
428
+ const ESC = "\x1B";
429
+ const CSI = `${ESC}[`;
430
+ const beep = "\x07";
431
+ const cursor = {
432
+ to(x, y) {
433
+ if (!y) return `${CSI}${x + 1}G`;
434
+ return `${CSI}${y + 1};${x + 1}H`;
435
+ },
436
+ move(x, y) {
437
+ let ret = "";
438
+ if (x < 0) ret += `${CSI}${-x}D`;
439
+ else if (x > 0) ret += `${CSI}${x}C`;
440
+ if (y < 0) ret += `${CSI}${-y}A`;
441
+ else if (y > 0) ret += `${CSI}${y}B`;
442
+ return ret;
443
+ },
444
+ up: (count = 1) => `${CSI}${count}A`,
445
+ down: (count = 1) => `${CSI}${count}B`,
446
+ forward: (count = 1) => `${CSI}${count}C`,
447
+ backward: (count = 1) => `${CSI}${count}D`,
448
+ nextLine: (count = 1) => `${CSI}E`.repeat(count),
449
+ prevLine: (count = 1) => `${CSI}F`.repeat(count),
450
+ left: `${CSI}G`,
451
+ hide: `${CSI}?25l`,
452
+ show: `${CSI}?25h`,
453
+ save: `${ESC}7`,
454
+ restore: `${ESC}8`
455
+ };
456
+ module.exports = {
457
+ cursor,
458
+ scroll: {
459
+ up: (count = 1) => `${CSI}S`.repeat(count),
460
+ down: (count = 1) => `${CSI}T`.repeat(count)
461
+ },
462
+ erase: {
463
+ screen: `${CSI}2J`,
464
+ up: (count = 1) => `${CSI}1J`.repeat(count),
465
+ down: (count = 1) => `${CSI}J`.repeat(count),
466
+ line: `${CSI}2K`,
467
+ lineEnd: `${CSI}K`,
468
+ lineStart: `${CSI}1K`,
469
+ lines(count) {
470
+ let clear = "";
471
+ for (let i = 0; i < count; i++) clear += this.line + (i < count - 1 ? cursor.up() : "");
472
+ if (count) clear += cursor.left;
473
+ return clear;
474
+ }
475
+ },
476
+ beep
477
+ };
478
+ })))();
479
+ function f(r, t, s) {
480
+ if (!s.some((o) => !o.disabled)) return r;
481
+ const e = r + t, i = Math.max(s.length - 1, 0), n = e < 0 ? i : e > i ? 0 : e;
482
+ return s[n].disabled ? f(n, t < 0 ? -1 : 1, s) : n;
483
+ }
484
+ const h = {
485
+ actions: new Set([
486
+ "up",
487
+ "down",
488
+ "left",
489
+ "right",
490
+ "space",
491
+ "enter",
492
+ "cancel"
493
+ ]),
494
+ aliases: new Map([
495
+ ["k", "up"],
496
+ ["j", "down"],
497
+ ["h", "left"],
498
+ ["l", "right"],
499
+ ["", "cancel"],
500
+ ["escape", "cancel"]
501
+ ]),
502
+ messages: {
503
+ cancel: "Canceled",
504
+ error: "Something went wrong"
505
+ },
506
+ withGuide: !0,
507
+ date: {
508
+ monthNames: [...[
509
+ "January",
510
+ "February",
511
+ "March",
512
+ "April",
513
+ "May",
514
+ "June",
515
+ "July",
516
+ "August",
517
+ "September",
518
+ "October",
519
+ "November",
520
+ "December"
521
+ ]],
522
+ messages: {
523
+ required: "Please enter a valid date",
524
+ invalidMonth: "There are only 12 months in a year",
525
+ invalidDay: (r, t) => `There are only ${r} days in ${t}`,
526
+ afterMin: (r) => `Date must be on or after ${r.toISOString().slice(0, 10)}`,
527
+ beforeMax: (r) => `Date must be on or before ${r.toISOString().slice(0, 10)}`
528
+ }
529
+ }
530
+ };
531
+ function C(r, t) {
532
+ if (typeof r == "string") return h.aliases.get(r) === t;
533
+ for (const s of r) if (s !== void 0 && C(s, t)) return !0;
534
+ return !1;
535
+ }
536
+ function z$1(r, t) {
537
+ if (r === t) return;
538
+ const s = r.split(`
539
+ `), e = t.split(`
540
+ `), i = Math.max(s.length, e.length), n = [];
541
+ for (let o = 0; o < i; o++) s[o] !== e[o] && n.push(o);
542
+ return {
543
+ lines: n,
544
+ numLinesBefore: s.length,
545
+ numLinesAfter: e.length,
546
+ numLines: i
547
+ };
548
+ }
549
+ globalThis.process.platform.startsWith("win");
550
+ const k = Symbol("clack:cancel");
551
+ function w$1(r, t) {
552
+ const s = r;
553
+ s.isTTY && s.setRawMode(t);
554
+ }
555
+ const L = (r) => "rows" in r && typeof r.rows == "number" ? r.rows : 20;
556
+ let m = class {
557
+ input;
558
+ output;
559
+ _abortSignal;
560
+ rl;
561
+ opts;
562
+ _render;
563
+ _track = !1;
564
+ _prevFrame = "";
565
+ _subscribers = /* @__PURE__ */ new Map();
566
+ _cursor = 0;
567
+ state = "initial";
568
+ error = "";
569
+ value;
570
+ userInput = "";
571
+ constructor(t, s = !0) {
572
+ const { input: e = stdin, output: i = stdout, render: n, signal: o, ...u } = t;
573
+ this.opts = u, 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 = o, this.input = e, this.output = i;
574
+ }
575
+ unsubscribe() {
576
+ this._subscribers.clear();
577
+ }
578
+ setSubscriber(t, s) {
579
+ const e = this._subscribers.get(t) ?? [];
580
+ e.push(s), this._subscribers.set(t, e);
581
+ }
582
+ on(t, s) {
583
+ this.setSubscriber(t, { cb: s });
584
+ }
585
+ once(t, s) {
586
+ this.setSubscriber(t, {
587
+ cb: s,
588
+ once: !0
589
+ });
590
+ }
591
+ emit(t, ...s) {
592
+ const e = this._subscribers.get(t) ?? [], i = [];
593
+ for (const n of e) n.cb(...s), n.once && i.push(() => e.splice(e.indexOf(n), 1));
594
+ for (const n of i) n();
595
+ }
596
+ prompt() {
597
+ return new Promise((t) => {
598
+ if (this._abortSignal) {
599
+ if (this._abortSignal.aborted) return this.state = "cancel", this.close(), t(k);
600
+ this._abortSignal.addEventListener("abort", () => {
601
+ this.state = "cancel", this.close();
602
+ }, { once: !0 });
603
+ }
604
+ this.rl = E.createInterface({
605
+ input: this.input,
606
+ tabSize: 2,
607
+ prompt: "",
608
+ escapeCodeTimeout: 50,
609
+ terminal: !0
610
+ }), this.rl.prompt(), this.opts.initialUserInput !== void 0 && this._setUserInput(this.opts.initialUserInput, !0), this.input.on("keypress", this.onKeypress), w$1(this.input, !0), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
611
+ this.output.write(import_src.cursor.show), this.output.off("resize", this.render), w$1(this.input, !1), t(this.value);
612
+ }), this.once("cancel", () => {
613
+ this.output.write(import_src.cursor.show), this.output.off("resize", this.render), w$1(this.input, !1), t(k);
614
+ });
615
+ });
616
+ }
617
+ _isActionKey(t, s) {
618
+ return t === " ";
619
+ }
620
+ _shouldSubmit(t, s) {
621
+ return !0;
622
+ }
623
+ _setValue(t) {
624
+ this.value = t, this.emit("value", this.value);
625
+ }
626
+ _setUserInput(t, s) {
627
+ this.userInput = t ?? "", this.emit("userInput", this.userInput), s && this._track && this.rl && (this.rl.write(this.userInput), this._cursor = this.rl.cursor);
628
+ }
629
+ _clearUserInput() {
630
+ this.rl?.write(null, {
631
+ ctrl: !0,
632
+ name: "u"
633
+ }), this._setUserInput("");
634
+ }
635
+ onKeypress(t, s) {
636
+ if (this._track && s.name !== "return" && (s.name && this._isActionKey(t, s) && this.rl?.write(null, {
637
+ ctrl: !0,
638
+ name: "h"
639
+ }), this._cursor = this.rl?.cursor ?? 0, this._setUserInput(this.rl?.line)), this.state === "error" && (this.state = "active"), s?.name && (!this._track && h.aliases.has(s.name) && this.emit("cursor", h.aliases.get(s.name)), h.actions.has(s.name) && this.emit("cursor", s.name)), t && (t.toLowerCase() === "y" || t.toLowerCase() === "n") && this.emit("confirm", t.toLowerCase() === "y"), this.emit("key", t?.toLowerCase(), s), s?.name === "return" && this._shouldSubmit(t, s)) {
640
+ if (this.opts.validate) {
641
+ const e = this.opts.validate(this.value);
642
+ e && (this.error = e instanceof Error ? e.message : e, this.state = "error", this.rl?.write(this.userInput));
643
+ }
644
+ this.state !== "error" && (this.state = "submit");
645
+ }
646
+ C([
647
+ t,
648
+ s?.name,
649
+ s?.sequence
650
+ ], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
651
+ }
652
+ close() {
653
+ this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
654
+ `), w$1(this.input, !1), this.rl?.close(), this.rl = void 0, this.emit(`${this.state}`, this.value), this.unsubscribe();
655
+ }
656
+ restoreCursor() {
657
+ const t = wrapAnsi(this._prevFrame, process.stdout.columns, {
658
+ hard: !0,
659
+ trim: !1
660
+ }).split(`
661
+ `).length - 1;
662
+ this.output.write(import_src.cursor.move(-999, t * -1));
663
+ }
664
+ render() {
665
+ const t = wrapAnsi(this._render(this) ?? "", process.stdout.columns, {
666
+ hard: !0,
667
+ trim: !1
668
+ });
669
+ if (t !== this._prevFrame) {
670
+ if (this.state === "initial") this.output.write(import_src.cursor.hide);
671
+ else {
672
+ const s = z$1(this._prevFrame, t), e = L(this.output);
673
+ if (this.restoreCursor(), s) {
674
+ const i = Math.max(0, s.numLinesAfter - e), n = Math.max(0, s.numLinesBefore - e);
675
+ let o = s.lines.find((u) => u >= i);
676
+ if (o === void 0) {
677
+ this._prevFrame = t;
678
+ return;
679
+ }
680
+ if (s.lines.length === 1) {
681
+ this.output.write(import_src.cursor.move(0, o - n)), this.output.write(import_src.erase.lines(1));
682
+ const u = t.split(`
683
+ `);
684
+ this.output.write(u[o]), this._prevFrame = t, this.output.write(import_src.cursor.move(0, u.length - o - 1));
685
+ return;
686
+ } else if (s.lines.length > 1) {
687
+ if (i < n) o = i;
688
+ else {
689
+ const a = o - n;
690
+ a > 0 && this.output.write(import_src.cursor.move(0, a));
691
+ }
692
+ this.output.write(import_src.erase.down());
693
+ const u = t.split(`
694
+ `).slice(o);
695
+ this.output.write(u.join(`
696
+ `)), this._prevFrame = t;
697
+ return;
698
+ }
699
+ }
700
+ this.output.write(import_src.erase.down());
701
+ }
702
+ this.output.write(t), this.state === "initial" && (this.state = "active"), this._prevFrame = t;
703
+ }
704
+ }
705
+ };
706
+ var ht$1 = class extends m {
707
+ get userInputWithCursor() {
708
+ if (this.state === "submit") return this.userInput;
709
+ const t = this.userInput;
710
+ if (this.cursor >= t.length) return `${this.userInput}\u2588`;
711
+ const s = t.slice(0, this.cursor), [e, ...i] = t.slice(this.cursor);
712
+ return `${s}${styleText("inverse", e)}${i.join("")}`;
713
+ }
714
+ get cursor() {
715
+ return this._cursor;
716
+ }
717
+ constructor(t) {
718
+ super({
719
+ ...t,
720
+ initialUserInput: t.initialUserInput ?? t.initialValue
721
+ }), this.on("userInput", (s) => {
722
+ this._setValue(s);
723
+ }), this.on("finalize", () => {
724
+ this.value || (this.value = t.defaultValue), this.value === void 0 && (this.value = "");
725
+ });
726
+ }
727
+ };
728
+ //#endregion
729
+ //#region ../../node_modules/.pnpm/@clack+prompts@1.4.0/node_modules/@clack/prompts/dist/index.mjs
730
+ function ee() {
731
+ return V.platform !== "win32" ? V.env.TERM !== "linux" : !!V.env.CI || !!V.env.WT_SESSION || !!V.env.TERMINUS_SUBLIME || V.env.ConEmuTask === "{cmd::Cmder}" || V.env.TERM_PROGRAM === "Terminus-Sublime" || V.env.TERM_PROGRAM === "vscode" || V.env.TERM === "xterm-256color" || V.env.TERM === "alacritty" || V.env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
732
+ }
733
+ const tt = ee(), w = (t, i) => tt ? t : i, Tt = w("◆", "*"), at = w("■", "x"), ut = w("▲", "x"), H = w("◇", "o");
734
+ const $ = w("│", "|"), x = w("└", "—"), ht = w("●", "•"), pt = w("◆", "*"), mt = w("▲", "!"), gt = w("■", "x"), P = (t) => {
735
+ switch (t) {
736
+ case "initial":
737
+ case "active": return styleText("cyan", Tt);
738
+ case "cancel": return styleText("red", at);
739
+ case "error": return styleText("yellow", ut);
740
+ case "submit": return styleText("green", H);
741
+ }
742
+ }, R = {
743
+ message: (t = [], { symbol: i = styleText("gray", $), secondarySymbol: s = styleText("gray", $), output: r = process.stdout, spacing: u = 1, withGuide: n } = {}) => {
744
+ const a = [], c = n ?? h.withGuide, o = c ? s : "", l = c ? `${i} ` : "", d = c ? `${s} ` : "";
745
+ for (let p = 0; p < u; p++) a.push(o);
746
+ const g = Array.isArray(t) ? t : t.split(`
747
+ `);
748
+ if (g.length > 0) {
749
+ const [p, ...f] = g;
750
+ p.length > 0 ? a.push(`${l}${p}`) : a.push(c ? i : "");
751
+ for (const h of f) h.length > 0 ? a.push(`${d}${h}`) : a.push(c ? s : "");
752
+ }
753
+ r.write(`${a.join(`
754
+ `)}
755
+ `);
756
+ },
757
+ info: (t, i) => {
758
+ R.message(t, {
759
+ ...i,
760
+ symbol: styleText("blue", ht)
761
+ });
762
+ },
763
+ success: (t, i) => {
764
+ R.message(t, {
765
+ ...i,
766
+ symbol: styleText("green", pt)
767
+ });
768
+ },
769
+ step: (t, i) => {
770
+ R.message(t, {
771
+ ...i,
772
+ symbol: styleText("green", H)
773
+ });
774
+ },
775
+ warn: (t, i) => {
776
+ R.message(t, {
777
+ ...i,
778
+ symbol: styleText("yellow", mt)
779
+ });
780
+ },
781
+ warning: (t, i) => {
782
+ R.warn(t, i);
783
+ },
784
+ error: (t, i) => {
785
+ R.message(t, {
786
+ ...i,
787
+ symbol: styleText("red", gt)
788
+ });
789
+ }
790
+ }, Nt = `${styleText("gray", $)} `, q = {
791
+ message: async (t, { symbol: i = styleText("gray", $) } = {}) => {
792
+ process.stdout.write(`${styleText("gray", $)}
793
+ ${i} `);
794
+ let s = 3;
795
+ for await (let r of t) {
796
+ r = r.replace(/\n/g, `
797
+ ${Nt}`), r.includes(`
798
+ `) && (s = 3 + stripVTControlCharacters(r.slice(r.lastIndexOf(`
799
+ `))).length);
800
+ const u = stripVTControlCharacters(r).length;
801
+ s + u < process.stdout.columns ? (s += u, process.stdout.write(r)) : (process.stdout.write(`
802
+ ${Nt}${r.trimStart()}`), s = 3 + stripVTControlCharacters(r.trimStart()).length);
803
+ }
804
+ process.stdout.write(`
805
+ `);
806
+ },
807
+ info: (t) => q.message(t, { symbol: styleText("blue", ht) }),
808
+ success: (t) => q.message(t, { symbol: styleText("green", pt) }),
809
+ step: (t) => q.message(t, { symbol: styleText("green", H) }),
810
+ warn: (t) => q.message(t, { symbol: styleText("yellow", mt) }),
811
+ warning: (t) => q.warn(t),
812
+ error: (t) => q.message(t, { symbol: styleText("red", gt) })
813
+ }, Pe = (t) => new ht$1({
814
+ validate: t.validate,
815
+ placeholder: t.placeholder,
816
+ defaultValue: t.defaultValue,
817
+ initialValue: t.initialValue,
818
+ output: t.output,
819
+ signal: t.signal,
820
+ input: t.input,
821
+ render() {
822
+ const i = t?.withGuide ?? h.withGuide, s = `${`${i ? `${styleText("gray", $)}
823
+ ` : ""}${P(this.state)} `}${t.message}
824
+ `, r = t.placeholder ? styleText("inverse", t.placeholder[0]) + styleText("dim", t.placeholder.slice(1)) : styleText(["inverse", "hidden"], "_"), u = this.userInput ? this.userInputWithCursor : r, n = this.value ?? "";
825
+ switch (this.state) {
826
+ case "error": {
827
+ const a = this.error ? ` ${styleText("yellow", this.error)}` : "", c = i ? `${styleText("yellow", $)} ` : "", o = i ? styleText("yellow", x) : "";
828
+ return `${s.trim()}
829
+ ${c}${u}
830
+ ${o}${a}
831
+ `;
832
+ }
833
+ case "submit": {
834
+ const a = n ? ` ${styleText("dim", n)}` : "";
835
+ return `${s}${i ? styleText("gray", $) : ""}${a}`;
836
+ }
837
+ case "cancel": {
838
+ const a = n ? ` ${styleText(["strikethrough", "dim"], n)}` : "", c = i ? styleText("gray", $) : "";
839
+ return `${s}${c}${a}${n.trim() ? `
840
+ ${c}` : ""}`;
841
+ }
842
+ default: return `${s}${i ? `${styleText("cyan", $)} ` : ""}${u}
843
+ ${i ? styleText("cyan", x) : ""}
844
+ `;
845
+ }
846
+ }
847
+ }).prompt();
848
+ //#endregion
849
+ //#region src/core/onboarding.ts
850
+ async function runOnboarding(opts = {}) {
851
+ const tty = opts.isTTY ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
852
+ let input = opts.initialApiUrl;
853
+ if (!input) {
854
+ if (!tty) throw new MxsError({
855
+ code: "config.missing.api_url",
856
+ message: "API URL is not configured",
857
+ hint: "set MXS_API_URL or pass --api-url <url>, or run `mxs auth login` in an interactive shell"
858
+ });
859
+ if (opts.prompt) input = await opts.prompt("API URL of your mx-core server");
860
+ else {
861
+ const answer = await Pe({
862
+ message: "API URL of your mx-core server",
863
+ placeholder: "https://blog.example.com",
864
+ validate: (v) => !v || v.trim().length === 0 ? "required" : void 0
865
+ });
866
+ if (typeof answer !== "string") throw new MxsError({
867
+ code: "config.missing.api_url",
868
+ message: "onboarding aborted"
869
+ });
870
+ input = answer;
871
+ }
872
+ }
873
+ const probed = await probeAuthEndpoint(normalizeApiUrl(input), opts.http ?? defaultHttp());
874
+ const existing = await readConfig();
875
+ await writeConfig({
876
+ ...existing,
877
+ api_url: probed.apiUrl,
878
+ api_base: probed.apiBase,
879
+ auth_base: probed.authBase,
880
+ api_version: probed.apiVersion,
881
+ client_id: existing.client_id ?? "mxs-cli"
882
+ });
883
+ return probed;
884
+ }
885
+ //#endregion
886
+ export { ApiClient as n, createApiClient as r, runOnboarding as t };
887
+
888
+ //# sourceMappingURL=onboarding-640IldLz.mjs.map