@pionex/pionex-ai-kit 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.
package/dist/index.js ADDED
@@ -0,0 +1,1152 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { createInterface } from "readline";
5
+
6
+ // ../core/dist/index.js
7
+ import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
8
+ import { join, dirname } from "path";
9
+ import { homedir } from "os";
10
+
11
+ // ../../node_modules/smol-toml/dist/error.js
12
+ function getLineColFromPtr(string, ptr) {
13
+ let lines = string.slice(0, ptr).split(/\r\n|\n|\r/g);
14
+ return [lines.length, lines.pop().length + 1];
15
+ }
16
+ function makeCodeBlock(string, line, column) {
17
+ let lines = string.split(/\r\n|\n|\r/g);
18
+ let codeblock = "";
19
+ let numberLen = (Math.log10(line + 1) | 0) + 1;
20
+ for (let i = line - 1; i <= line + 1; i++) {
21
+ let l = lines[i - 1];
22
+ if (!l)
23
+ continue;
24
+ codeblock += i.toString().padEnd(numberLen, " ");
25
+ codeblock += ": ";
26
+ codeblock += l;
27
+ codeblock += "\n";
28
+ if (i === line) {
29
+ codeblock += " ".repeat(numberLen + column + 2);
30
+ codeblock += "^\n";
31
+ }
32
+ }
33
+ return codeblock;
34
+ }
35
+ var TomlError = class extends Error {
36
+ line;
37
+ column;
38
+ codeblock;
39
+ constructor(message, options) {
40
+ const [line, column] = getLineColFromPtr(options.toml, options.ptr);
41
+ const codeblock = makeCodeBlock(options.toml, line, column);
42
+ super(`Invalid TOML document: ${message}
43
+
44
+ ${codeblock}`, options);
45
+ this.line = line;
46
+ this.column = column;
47
+ this.codeblock = codeblock;
48
+ }
49
+ };
50
+
51
+ // ../../node_modules/smol-toml/dist/util.js
52
+ function isEscaped(str, ptr) {
53
+ let i = 0;
54
+ while (str[ptr - ++i] === "\\")
55
+ ;
56
+ return --i && i % 2;
57
+ }
58
+ function indexOfNewline(str, start = 0, end = str.length) {
59
+ let idx = str.indexOf("\n", start);
60
+ if (str[idx - 1] === "\r")
61
+ idx--;
62
+ return idx <= end ? idx : -1;
63
+ }
64
+ function skipComment(str, ptr) {
65
+ for (let i = ptr; i < str.length; i++) {
66
+ let c = str[i];
67
+ if (c === "\n")
68
+ return i;
69
+ if (c === "\r" && str[i + 1] === "\n")
70
+ return i + 1;
71
+ if (c < " " && c !== " " || c === "\x7F") {
72
+ throw new TomlError("control characters are not allowed in comments", {
73
+ toml: str,
74
+ ptr
75
+ });
76
+ }
77
+ }
78
+ return str.length;
79
+ }
80
+ function skipVoid(str, ptr, banNewLines, banComments) {
81
+ let c;
82
+ while ((c = str[ptr]) === " " || c === " " || !banNewLines && (c === "\n" || c === "\r" && str[ptr + 1] === "\n"))
83
+ ptr++;
84
+ return banComments || c !== "#" ? ptr : skipVoid(str, skipComment(str, ptr), banNewLines);
85
+ }
86
+ function skipUntil(str, ptr, sep, end, banNewLines = false) {
87
+ if (!end) {
88
+ ptr = indexOfNewline(str, ptr);
89
+ return ptr < 0 ? str.length : ptr;
90
+ }
91
+ for (let i = ptr; i < str.length; i++) {
92
+ let c = str[i];
93
+ if (c === "#") {
94
+ i = indexOfNewline(str, i);
95
+ } else if (c === sep) {
96
+ return i + 1;
97
+ } else if (c === end || banNewLines && (c === "\n" || c === "\r" && str[i + 1] === "\n")) {
98
+ return i;
99
+ }
100
+ }
101
+ throw new TomlError("cannot find end of structure", {
102
+ toml: str,
103
+ ptr
104
+ });
105
+ }
106
+ function getStringEnd(str, seek) {
107
+ let first = str[seek];
108
+ let target = first === str[seek + 1] && str[seek + 1] === str[seek + 2] ? str.slice(seek, seek + 3) : first;
109
+ seek += target.length - 1;
110
+ do
111
+ seek = str.indexOf(target, ++seek);
112
+ while (seek > -1 && first !== "'" && isEscaped(str, seek));
113
+ if (seek > -1) {
114
+ seek += target.length;
115
+ if (target.length > 1) {
116
+ if (str[seek] === first)
117
+ seek++;
118
+ if (str[seek] === first)
119
+ seek++;
120
+ }
121
+ }
122
+ return seek;
123
+ }
124
+
125
+ // ../../node_modules/smol-toml/dist/date.js
126
+ var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;
127
+ var TomlDate = class _TomlDate extends Date {
128
+ #hasDate = false;
129
+ #hasTime = false;
130
+ #offset = null;
131
+ constructor(date) {
132
+ let hasDate = true;
133
+ let hasTime = true;
134
+ let offset = "Z";
135
+ if (typeof date === "string") {
136
+ let match = date.match(DATE_TIME_RE);
137
+ if (match) {
138
+ if (!match[1]) {
139
+ hasDate = false;
140
+ date = `0000-01-01T${date}`;
141
+ }
142
+ hasTime = !!match[2];
143
+ hasTime && date[10] === " " && (date = date.replace(" ", "T"));
144
+ if (match[2] && +match[2] > 23) {
145
+ date = "";
146
+ } else {
147
+ offset = match[3] || null;
148
+ date = date.toUpperCase();
149
+ if (!offset && hasTime)
150
+ date += "Z";
151
+ }
152
+ } else {
153
+ date = "";
154
+ }
155
+ }
156
+ super(date);
157
+ if (!isNaN(this.getTime())) {
158
+ this.#hasDate = hasDate;
159
+ this.#hasTime = hasTime;
160
+ this.#offset = offset;
161
+ }
162
+ }
163
+ isDateTime() {
164
+ return this.#hasDate && this.#hasTime;
165
+ }
166
+ isLocal() {
167
+ return !this.#hasDate || !this.#hasTime || !this.#offset;
168
+ }
169
+ isDate() {
170
+ return this.#hasDate && !this.#hasTime;
171
+ }
172
+ isTime() {
173
+ return this.#hasTime && !this.#hasDate;
174
+ }
175
+ isValid() {
176
+ return this.#hasDate || this.#hasTime;
177
+ }
178
+ toISOString() {
179
+ let iso = super.toISOString();
180
+ if (this.isDate())
181
+ return iso.slice(0, 10);
182
+ if (this.isTime())
183
+ return iso.slice(11, 23);
184
+ if (this.#offset === null)
185
+ return iso.slice(0, -1);
186
+ if (this.#offset === "Z")
187
+ return iso;
188
+ let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
189
+ offset = this.#offset[0] === "-" ? offset : -offset;
190
+ let offsetDate = new Date(this.getTime() - offset * 6e4);
191
+ return offsetDate.toISOString().slice(0, -1) + this.#offset;
192
+ }
193
+ static wrapAsOffsetDateTime(jsDate, offset = "Z") {
194
+ let date = new _TomlDate(jsDate);
195
+ date.#offset = offset;
196
+ return date;
197
+ }
198
+ static wrapAsLocalDateTime(jsDate) {
199
+ let date = new _TomlDate(jsDate);
200
+ date.#offset = null;
201
+ return date;
202
+ }
203
+ static wrapAsLocalDate(jsDate) {
204
+ let date = new _TomlDate(jsDate);
205
+ date.#hasTime = false;
206
+ date.#offset = null;
207
+ return date;
208
+ }
209
+ static wrapAsLocalTime(jsDate) {
210
+ let date = new _TomlDate(jsDate);
211
+ date.#hasDate = false;
212
+ date.#offset = null;
213
+ return date;
214
+ }
215
+ };
216
+
217
+ // ../../node_modules/smol-toml/dist/primitive.js
218
+ var INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/;
219
+ var FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/;
220
+ var LEADING_ZERO = /^[+-]?0[0-9_]/;
221
+ var ESCAPE_REGEX = /^[0-9a-f]{2,8}$/i;
222
+ var ESC_MAP = {
223
+ b: "\b",
224
+ t: " ",
225
+ n: "\n",
226
+ f: "\f",
227
+ r: "\r",
228
+ e: "\x1B",
229
+ '"': '"',
230
+ "\\": "\\"
231
+ };
232
+ function parseString(str, ptr = 0, endPtr = str.length) {
233
+ let isLiteral = str[ptr] === "'";
234
+ let isMultiline = str[ptr++] === str[ptr] && str[ptr] === str[ptr + 1];
235
+ if (isMultiline) {
236
+ endPtr -= 2;
237
+ if (str[ptr += 2] === "\r")
238
+ ptr++;
239
+ if (str[ptr] === "\n")
240
+ ptr++;
241
+ }
242
+ let tmp = 0;
243
+ let isEscape;
244
+ let parsed = "";
245
+ let sliceStart = ptr;
246
+ while (ptr < endPtr - 1) {
247
+ let c = str[ptr++];
248
+ if (c === "\n" || c === "\r" && str[ptr] === "\n") {
249
+ if (!isMultiline) {
250
+ throw new TomlError("newlines are not allowed in strings", {
251
+ toml: str,
252
+ ptr: ptr - 1
253
+ });
254
+ }
255
+ } else if (c < " " && c !== " " || c === "\x7F") {
256
+ throw new TomlError("control characters are not allowed in strings", {
257
+ toml: str,
258
+ ptr: ptr - 1
259
+ });
260
+ }
261
+ if (isEscape) {
262
+ isEscape = false;
263
+ if (c === "x" || c === "u" || c === "U") {
264
+ let code = str.slice(ptr, ptr += c === "x" ? 2 : c === "u" ? 4 : 8);
265
+ if (!ESCAPE_REGEX.test(code)) {
266
+ throw new TomlError("invalid unicode escape", {
267
+ toml: str,
268
+ ptr: tmp
269
+ });
270
+ }
271
+ try {
272
+ parsed += String.fromCodePoint(parseInt(code, 16));
273
+ } catch {
274
+ throw new TomlError("invalid unicode escape", {
275
+ toml: str,
276
+ ptr: tmp
277
+ });
278
+ }
279
+ } else if (isMultiline && (c === "\n" || c === " " || c === " " || c === "\r")) {
280
+ ptr = skipVoid(str, ptr - 1, true);
281
+ if (str[ptr] !== "\n" && str[ptr] !== "\r") {
282
+ throw new TomlError("invalid escape: only line-ending whitespace may be escaped", {
283
+ toml: str,
284
+ ptr: tmp
285
+ });
286
+ }
287
+ ptr = skipVoid(str, ptr);
288
+ } else if (c in ESC_MAP) {
289
+ parsed += ESC_MAP[c];
290
+ } else {
291
+ throw new TomlError("unrecognized escape sequence", {
292
+ toml: str,
293
+ ptr: tmp
294
+ });
295
+ }
296
+ sliceStart = ptr;
297
+ } else if (!isLiteral && c === "\\") {
298
+ tmp = ptr - 1;
299
+ isEscape = true;
300
+ parsed += str.slice(sliceStart, tmp);
301
+ }
302
+ }
303
+ return parsed + str.slice(sliceStart, endPtr - 1);
304
+ }
305
+ function parseValue(value, toml, ptr, integersAsBigInt) {
306
+ if (value === "true")
307
+ return true;
308
+ if (value === "false")
309
+ return false;
310
+ if (value === "-inf")
311
+ return -Infinity;
312
+ if (value === "inf" || value === "+inf")
313
+ return Infinity;
314
+ if (value === "nan" || value === "+nan" || value === "-nan")
315
+ return NaN;
316
+ if (value === "-0")
317
+ return integersAsBigInt ? 0n : 0;
318
+ let isInt = INT_REGEX.test(value);
319
+ if (isInt || FLOAT_REGEX.test(value)) {
320
+ if (LEADING_ZERO.test(value)) {
321
+ throw new TomlError("leading zeroes are not allowed", {
322
+ toml,
323
+ ptr
324
+ });
325
+ }
326
+ value = value.replace(/_/g, "");
327
+ let numeric = +value;
328
+ if (isNaN(numeric)) {
329
+ throw new TomlError("invalid number", {
330
+ toml,
331
+ ptr
332
+ });
333
+ }
334
+ if (isInt) {
335
+ if ((isInt = !Number.isSafeInteger(numeric)) && !integersAsBigInt) {
336
+ throw new TomlError("integer value cannot be represented losslessly", {
337
+ toml,
338
+ ptr
339
+ });
340
+ }
341
+ if (isInt || integersAsBigInt === true)
342
+ numeric = BigInt(value);
343
+ }
344
+ return numeric;
345
+ }
346
+ const date = new TomlDate(value);
347
+ if (!date.isValid()) {
348
+ throw new TomlError("invalid value", {
349
+ toml,
350
+ ptr
351
+ });
352
+ }
353
+ return date;
354
+ }
355
+
356
+ // ../../node_modules/smol-toml/dist/extract.js
357
+ function sliceAndTrimEndOf(str, startPtr, endPtr) {
358
+ let value = str.slice(startPtr, endPtr);
359
+ let commentIdx = value.indexOf("#");
360
+ if (commentIdx > -1) {
361
+ skipComment(str, commentIdx);
362
+ value = value.slice(0, commentIdx);
363
+ }
364
+ return [value.trimEnd(), commentIdx];
365
+ }
366
+ function extractValue(str, ptr, end, depth, integersAsBigInt) {
367
+ if (depth === 0) {
368
+ throw new TomlError("document contains excessively nested structures. aborting.", {
369
+ toml: str,
370
+ ptr
371
+ });
372
+ }
373
+ let c = str[ptr];
374
+ if (c === "[" || c === "{") {
375
+ let [value, endPtr2] = c === "[" ? parseArray(str, ptr, depth, integersAsBigInt) : parseInlineTable(str, ptr, depth, integersAsBigInt);
376
+ if (end) {
377
+ endPtr2 = skipVoid(str, endPtr2);
378
+ if (str[endPtr2] === ",")
379
+ endPtr2++;
380
+ else if (str[endPtr2] !== end) {
381
+ throw new TomlError("expected comma or end of structure", {
382
+ toml: str,
383
+ ptr: endPtr2
384
+ });
385
+ }
386
+ }
387
+ return [value, endPtr2];
388
+ }
389
+ let endPtr;
390
+ if (c === '"' || c === "'") {
391
+ endPtr = getStringEnd(str, ptr);
392
+ let parsed = parseString(str, ptr, endPtr);
393
+ if (end) {
394
+ endPtr = skipVoid(str, endPtr);
395
+ if (str[endPtr] && str[endPtr] !== "," && str[endPtr] !== end && str[endPtr] !== "\n" && str[endPtr] !== "\r") {
396
+ throw new TomlError("unexpected character encountered", {
397
+ toml: str,
398
+ ptr: endPtr
399
+ });
400
+ }
401
+ endPtr += +(str[endPtr] === ",");
402
+ }
403
+ return [parsed, endPtr];
404
+ }
405
+ endPtr = skipUntil(str, ptr, ",", end);
406
+ let slice = sliceAndTrimEndOf(str, ptr, endPtr - +(str[endPtr - 1] === ","));
407
+ if (!slice[0]) {
408
+ throw new TomlError("incomplete key-value declaration: no value specified", {
409
+ toml: str,
410
+ ptr
411
+ });
412
+ }
413
+ if (end && slice[1] > -1) {
414
+ endPtr = skipVoid(str, ptr + slice[1]);
415
+ endPtr += +(str[endPtr] === ",");
416
+ }
417
+ return [
418
+ parseValue(slice[0], str, ptr, integersAsBigInt),
419
+ endPtr
420
+ ];
421
+ }
422
+
423
+ // ../../node_modules/smol-toml/dist/struct.js
424
+ var KEY_PART_RE = /^[a-zA-Z0-9-_]+[ \t]*$/;
425
+ function parseKey(str, ptr, end = "=") {
426
+ let dot = ptr - 1;
427
+ let parsed = [];
428
+ let endPtr = str.indexOf(end, ptr);
429
+ if (endPtr < 0) {
430
+ throw new TomlError("incomplete key-value: cannot find end of key", {
431
+ toml: str,
432
+ ptr
433
+ });
434
+ }
435
+ do {
436
+ let c = str[ptr = ++dot];
437
+ if (c !== " " && c !== " ") {
438
+ if (c === '"' || c === "'") {
439
+ if (c === str[ptr + 1] && c === str[ptr + 2]) {
440
+ throw new TomlError("multiline strings are not allowed in keys", {
441
+ toml: str,
442
+ ptr
443
+ });
444
+ }
445
+ let eos = getStringEnd(str, ptr);
446
+ if (eos < 0) {
447
+ throw new TomlError("unfinished string encountered", {
448
+ toml: str,
449
+ ptr
450
+ });
451
+ }
452
+ dot = str.indexOf(".", eos);
453
+ let strEnd = str.slice(eos, dot < 0 || dot > endPtr ? endPtr : dot);
454
+ let newLine = indexOfNewline(strEnd);
455
+ if (newLine > -1) {
456
+ throw new TomlError("newlines are not allowed in keys", {
457
+ toml: str,
458
+ ptr: ptr + dot + newLine
459
+ });
460
+ }
461
+ if (strEnd.trimStart()) {
462
+ throw new TomlError("found extra tokens after the string part", {
463
+ toml: str,
464
+ ptr: eos
465
+ });
466
+ }
467
+ if (endPtr < eos) {
468
+ endPtr = str.indexOf(end, eos);
469
+ if (endPtr < 0) {
470
+ throw new TomlError("incomplete key-value: cannot find end of key", {
471
+ toml: str,
472
+ ptr
473
+ });
474
+ }
475
+ }
476
+ parsed.push(parseString(str, ptr, eos));
477
+ } else {
478
+ dot = str.indexOf(".", ptr);
479
+ let part = str.slice(ptr, dot < 0 || dot > endPtr ? endPtr : dot);
480
+ if (!KEY_PART_RE.test(part)) {
481
+ throw new TomlError("only letter, numbers, dashes and underscores are allowed in keys", {
482
+ toml: str,
483
+ ptr
484
+ });
485
+ }
486
+ parsed.push(part.trimEnd());
487
+ }
488
+ }
489
+ } while (dot + 1 && dot < endPtr);
490
+ return [parsed, skipVoid(str, endPtr + 1, true, true)];
491
+ }
492
+ function parseInlineTable(str, ptr, depth, integersAsBigInt) {
493
+ let res = {};
494
+ let seen = /* @__PURE__ */ new Set();
495
+ let c;
496
+ ptr++;
497
+ while ((c = str[ptr++]) !== "}" && c) {
498
+ if (c === ",") {
499
+ throw new TomlError("expected value, found comma", {
500
+ toml: str,
501
+ ptr: ptr - 1
502
+ });
503
+ } else if (c === "#")
504
+ ptr = skipComment(str, ptr);
505
+ else if (c !== " " && c !== " " && c !== "\n" && c !== "\r") {
506
+ let k;
507
+ let t = res;
508
+ let hasOwn = false;
509
+ let [key, keyEndPtr] = parseKey(str, ptr - 1);
510
+ for (let i = 0; i < key.length; i++) {
511
+ if (i)
512
+ t = hasOwn ? t[k] : t[k] = {};
513
+ k = key[i];
514
+ if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) {
515
+ throw new TomlError("trying to redefine an already defined value", {
516
+ toml: str,
517
+ ptr
518
+ });
519
+ }
520
+ if (!hasOwn && k === "__proto__") {
521
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
522
+ }
523
+ }
524
+ if (hasOwn) {
525
+ throw new TomlError("trying to redefine an already defined value", {
526
+ toml: str,
527
+ ptr
528
+ });
529
+ }
530
+ let [value, valueEndPtr] = extractValue(str, keyEndPtr, "}", depth - 1, integersAsBigInt);
531
+ seen.add(value);
532
+ t[k] = value;
533
+ ptr = valueEndPtr;
534
+ }
535
+ }
536
+ if (!c) {
537
+ throw new TomlError("unfinished table encountered", {
538
+ toml: str,
539
+ ptr
540
+ });
541
+ }
542
+ return [res, ptr];
543
+ }
544
+ function parseArray(str, ptr, depth, integersAsBigInt) {
545
+ let res = [];
546
+ let c;
547
+ ptr++;
548
+ while ((c = str[ptr++]) !== "]" && c) {
549
+ if (c === ",") {
550
+ throw new TomlError("expected value, found comma", {
551
+ toml: str,
552
+ ptr: ptr - 1
553
+ });
554
+ } else if (c === "#")
555
+ ptr = skipComment(str, ptr);
556
+ else if (c !== " " && c !== " " && c !== "\n" && c !== "\r") {
557
+ let e = extractValue(str, ptr - 1, "]", depth - 1, integersAsBigInt);
558
+ res.push(e[0]);
559
+ ptr = e[1];
560
+ }
561
+ }
562
+ if (!c) {
563
+ throw new TomlError("unfinished array encountered", {
564
+ toml: str,
565
+ ptr
566
+ });
567
+ }
568
+ return [res, ptr];
569
+ }
570
+
571
+ // ../../node_modules/smol-toml/dist/parse.js
572
+ function peekTable(key, table, meta, type) {
573
+ let t = table;
574
+ let m = meta;
575
+ let k;
576
+ let hasOwn = false;
577
+ let state;
578
+ for (let i = 0; i < key.length; i++) {
579
+ if (i) {
580
+ t = hasOwn ? t[k] : t[k] = {};
581
+ m = (state = m[k]).c;
582
+ if (type === 0 && (state.t === 1 || state.t === 2)) {
583
+ return null;
584
+ }
585
+ if (state.t === 2) {
586
+ let l = t.length - 1;
587
+ t = t[l];
588
+ m = m[l].c;
589
+ }
590
+ }
591
+ k = key[i];
592
+ if ((hasOwn = Object.hasOwn(t, k)) && m[k]?.t === 0 && m[k]?.d) {
593
+ return null;
594
+ }
595
+ if (!hasOwn) {
596
+ if (k === "__proto__") {
597
+ Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
598
+ Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
599
+ }
600
+ m[k] = {
601
+ t: i < key.length - 1 && type === 2 ? 3 : type,
602
+ d: false,
603
+ i: 0,
604
+ c: {}
605
+ };
606
+ }
607
+ }
608
+ state = m[k];
609
+ if (state.t !== type && !(type === 1 && state.t === 3)) {
610
+ return null;
611
+ }
612
+ if (type === 2) {
613
+ if (!state.d) {
614
+ state.d = true;
615
+ t[k] = [];
616
+ }
617
+ t[k].push(t = {});
618
+ state.c[state.i++] = state = { t: 1, d: false, i: 0, c: {} };
619
+ }
620
+ if (state.d) {
621
+ return null;
622
+ }
623
+ state.d = true;
624
+ if (type === 1) {
625
+ t = hasOwn ? t[k] : t[k] = {};
626
+ } else if (type === 0 && hasOwn) {
627
+ return null;
628
+ }
629
+ return [k, t, state.c];
630
+ }
631
+ function parse(toml, { maxDepth = 1e3, integersAsBigInt } = {}) {
632
+ let res = {};
633
+ let meta = {};
634
+ let tbl = res;
635
+ let m = meta;
636
+ for (let ptr = skipVoid(toml, 0); ptr < toml.length; ) {
637
+ if (toml[ptr] === "[") {
638
+ let isTableArray = toml[++ptr] === "[";
639
+ let k = parseKey(toml, ptr += +isTableArray, "]");
640
+ if (isTableArray) {
641
+ if (toml[k[1] - 1] !== "]") {
642
+ throw new TomlError("expected end of table declaration", {
643
+ toml,
644
+ ptr: k[1] - 1
645
+ });
646
+ }
647
+ k[1]++;
648
+ }
649
+ let p = peekTable(
650
+ k[0],
651
+ res,
652
+ meta,
653
+ isTableArray ? 2 : 1
654
+ /* Type.EXPLICIT */
655
+ );
656
+ if (!p) {
657
+ throw new TomlError("trying to redefine an already defined table or value", {
658
+ toml,
659
+ ptr
660
+ });
661
+ }
662
+ m = p[2];
663
+ tbl = p[1];
664
+ ptr = k[1];
665
+ } else {
666
+ let k = parseKey(toml, ptr);
667
+ let p = peekTable(
668
+ k[0],
669
+ tbl,
670
+ m,
671
+ 0
672
+ /* Type.DOTTED */
673
+ );
674
+ if (!p) {
675
+ throw new TomlError("trying to redefine an already defined table or value", {
676
+ toml,
677
+ ptr
678
+ });
679
+ }
680
+ let v = extractValue(toml, k[1], void 0, maxDepth, integersAsBigInt);
681
+ p[1][p[0]] = v[0];
682
+ ptr = v[1];
683
+ }
684
+ ptr = skipVoid(toml, ptr, true);
685
+ if (toml[ptr] && toml[ptr] !== "\n" && toml[ptr] !== "\r") {
686
+ throw new TomlError("each key-value declaration must be followed by an end-of-line", {
687
+ toml,
688
+ ptr
689
+ });
690
+ }
691
+ ptr = skipVoid(toml, ptr);
692
+ }
693
+ return res;
694
+ }
695
+
696
+ // ../../node_modules/smol-toml/dist/stringify.js
697
+ var BARE_KEY = /^[a-z0-9-_]+$/i;
698
+ function extendedTypeOf(obj) {
699
+ let type = typeof obj;
700
+ if (type === "object") {
701
+ if (Array.isArray(obj))
702
+ return "array";
703
+ if (obj instanceof Date)
704
+ return "date";
705
+ }
706
+ return type;
707
+ }
708
+ function isArrayOfTables(obj) {
709
+ for (let i = 0; i < obj.length; i++) {
710
+ if (extendedTypeOf(obj[i]) !== "object")
711
+ return false;
712
+ }
713
+ return obj.length != 0;
714
+ }
715
+ function formatString(s) {
716
+ return JSON.stringify(s).replace(/\x7f/g, "\\u007f");
717
+ }
718
+ function stringifyValue(val, type, depth, numberAsFloat) {
719
+ if (depth === 0) {
720
+ throw new Error("Could not stringify the object: maximum object depth exceeded");
721
+ }
722
+ if (type === "number") {
723
+ if (isNaN(val))
724
+ return "nan";
725
+ if (val === Infinity)
726
+ return "inf";
727
+ if (val === -Infinity)
728
+ return "-inf";
729
+ if (numberAsFloat && Number.isInteger(val))
730
+ return val.toFixed(1);
731
+ return val.toString();
732
+ }
733
+ if (type === "bigint" || type === "boolean") {
734
+ return val.toString();
735
+ }
736
+ if (type === "string") {
737
+ return formatString(val);
738
+ }
739
+ if (type === "date") {
740
+ if (isNaN(val.getTime())) {
741
+ throw new TypeError("cannot serialize invalid date");
742
+ }
743
+ return val.toISOString();
744
+ }
745
+ if (type === "object") {
746
+ return stringifyInlineTable(val, depth, numberAsFloat);
747
+ }
748
+ if (type === "array") {
749
+ return stringifyArray(val, depth, numberAsFloat);
750
+ }
751
+ }
752
+ function stringifyInlineTable(obj, depth, numberAsFloat) {
753
+ let keys = Object.keys(obj);
754
+ if (keys.length === 0)
755
+ return "{}";
756
+ let res = "{ ";
757
+ for (let i = 0; i < keys.length; i++) {
758
+ let k = keys[i];
759
+ if (i)
760
+ res += ", ";
761
+ res += BARE_KEY.test(k) ? k : formatString(k);
762
+ res += " = ";
763
+ res += stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat);
764
+ }
765
+ return res + " }";
766
+ }
767
+ function stringifyArray(array, depth, numberAsFloat) {
768
+ if (array.length === 0)
769
+ return "[]";
770
+ let res = "[ ";
771
+ for (let i = 0; i < array.length; i++) {
772
+ if (i)
773
+ res += ", ";
774
+ if (array[i] === null || array[i] === void 0) {
775
+ throw new TypeError("arrays cannot contain null or undefined values");
776
+ }
777
+ res += stringifyValue(array[i], extendedTypeOf(array[i]), depth - 1, numberAsFloat);
778
+ }
779
+ return res + " ]";
780
+ }
781
+ function stringifyArrayTable(array, key, depth, numberAsFloat) {
782
+ if (depth === 0) {
783
+ throw new Error("Could not stringify the object: maximum object depth exceeded");
784
+ }
785
+ let res = "";
786
+ for (let i = 0; i < array.length; i++) {
787
+ res += `${res && "\n"}[[${key}]]
788
+ `;
789
+ res += stringifyTable(0, array[i], key, depth, numberAsFloat);
790
+ }
791
+ return res;
792
+ }
793
+ function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat) {
794
+ if (depth === 0) {
795
+ throw new Error("Could not stringify the object: maximum object depth exceeded");
796
+ }
797
+ let preamble = "";
798
+ let tables = "";
799
+ let keys = Object.keys(obj);
800
+ for (let i = 0; i < keys.length; i++) {
801
+ let k = keys[i];
802
+ if (obj[k] !== null && obj[k] !== void 0) {
803
+ let type = extendedTypeOf(obj[k]);
804
+ if (type === "symbol" || type === "function") {
805
+ throw new TypeError(`cannot serialize values of type '${type}'`);
806
+ }
807
+ let key = BARE_KEY.test(k) ? k : formatString(k);
808
+ if (type === "array" && isArrayOfTables(obj[k])) {
809
+ tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat);
810
+ } else if (type === "object") {
811
+ let tblKey = prefix ? `${prefix}.${key}` : key;
812
+ tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat);
813
+ } else {
814
+ preamble += key;
815
+ preamble += " = ";
816
+ preamble += stringifyValue(obj[k], type, depth, numberAsFloat);
817
+ preamble += "\n";
818
+ }
819
+ }
820
+ }
821
+ if (tableKey && (preamble || !tables))
822
+ preamble = preamble ? `[${tableKey}]
823
+ ${preamble}` : `[${tableKey}]`;
824
+ return preamble && tables ? `${preamble}
825
+ ${tables}` : preamble || tables;
826
+ }
827
+ function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false } = {}) {
828
+ if (extendedTypeOf(obj) !== "object") {
829
+ throw new TypeError("stringify can only be called with an object");
830
+ }
831
+ let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat);
832
+ if (str[str.length - 1] !== "\n")
833
+ return str + "\n";
834
+ return str;
835
+ }
836
+
837
+ // ../core/dist/index.js
838
+ import * as fs from "fs";
839
+ import * as path from "path";
840
+ import * as os from "os";
841
+ import { execFileSync } from "child_process";
842
+ function configFilePath() {
843
+ return join(homedir(), ".pionex", "config.toml");
844
+ }
845
+ function readFullConfig() {
846
+ const path2 = configFilePath();
847
+ if (!existsSync(path2)) return { profiles: {} };
848
+ const raw = readFileSync(path2, "utf-8");
849
+ return parse(raw);
850
+ }
851
+ function writeFullConfig(config) {
852
+ const path2 = configFilePath();
853
+ const dir = dirname(path2);
854
+ if (!existsSync(dir)) {
855
+ mkdirSync(dir, { recursive: true });
856
+ }
857
+ writeFileSync(path2, stringify(config), "utf-8");
858
+ }
859
+ var CLIENT_NAMES = {
860
+ "claude-desktop": "Claude Desktop",
861
+ cursor: "Cursor",
862
+ windsurf: "Windsurf",
863
+ vscode: "VS Code",
864
+ "claude-code": "Claude Code CLI",
865
+ open_claw: "OpenClaw (mcporter)"
866
+ };
867
+ var SUPPORTED_CLIENTS = Object.keys(CLIENT_NAMES);
868
+ function appData() {
869
+ return process.env.APPDATA ?? path.join(os.homedir(), "AppData", "Roaming");
870
+ }
871
+ var CLAUDE_CONFIG_FILE = "claude_desktop_config.json";
872
+ function findMsStoreClaudePath() {
873
+ const localAppData = process.env.LOCALAPPDATA ?? path.join(os.homedir(), "AppData", "Local");
874
+ const packagesDir = path.join(localAppData, "Packages");
875
+ try {
876
+ const entries = fs.readdirSync(packagesDir);
877
+ const claudePkg = entries.find((e) => e.startsWith("Claude_"));
878
+ if (claudePkg) {
879
+ const configPath = path.join(
880
+ packagesDir,
881
+ claudePkg,
882
+ "LocalCache",
883
+ "Roaming",
884
+ "Claude",
885
+ CLAUDE_CONFIG_FILE
886
+ );
887
+ if (fs.existsSync(configPath) || fs.existsSync(path.dirname(configPath))) {
888
+ return configPath;
889
+ }
890
+ }
891
+ } catch {
892
+ }
893
+ return null;
894
+ }
895
+ function getConfigPath(client) {
896
+ const home = os.homedir();
897
+ const platform = process.platform;
898
+ switch (client) {
899
+ case "claude-desktop":
900
+ if (platform === "win32") {
901
+ return findMsStoreClaudePath() ?? path.join(appData(), "Claude", CLAUDE_CONFIG_FILE);
902
+ }
903
+ if (platform === "darwin") {
904
+ return path.join(home, "Library", "Application Support", "Claude", CLAUDE_CONFIG_FILE);
905
+ }
906
+ return path.join(process.env.XDG_CONFIG_HOME ?? path.join(home, ".config"), "Claude", CLAUDE_CONFIG_FILE);
907
+ case "cursor":
908
+ return path.join(home, ".cursor", "mcp.json");
909
+ case "windsurf":
910
+ return path.join(home, ".codeium", "windsurf", "mcp_config.json");
911
+ case "vscode":
912
+ return path.join(process.cwd(), ".mcp.json");
913
+ case "claude-code":
914
+ return null;
915
+ case "open_claw":
916
+ return path.join(home, ".openclaw", "workspace", "config", "mcporter.json");
917
+ }
918
+ }
919
+ var NPX_PACKAGE = "pionex-trade-mcp";
920
+ function buildEntry(client) {
921
+ if (client === "vscode") {
922
+ return { type: "stdio", command: "pionex-trade-mcp" };
923
+ }
924
+ return { command: "npx", args: ["-y", NPX_PACKAGE] };
925
+ }
926
+ function mergeJsonConfig(configPath, serverName, entry) {
927
+ const dir = path.dirname(configPath);
928
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
929
+ let data = {};
930
+ if (fs.existsSync(configPath)) {
931
+ const raw = fs.readFileSync(configPath, "utf-8");
932
+ try {
933
+ data = JSON.parse(raw);
934
+ } catch {
935
+ throw new Error(`Failed to parse existing config at ${configPath}`);
936
+ }
937
+ }
938
+ if (typeof data.mcpServers !== "object" || data.mcpServers === null) {
939
+ data.mcpServers = {};
940
+ }
941
+ data.mcpServers[serverName] = entry;
942
+ fs.writeFileSync(configPath, JSON.stringify(data, null, 2) + "\n", "utf-8");
943
+ }
944
+ function runSetup(options) {
945
+ const { client } = options;
946
+ const name = CLIENT_NAMES[client];
947
+ const serverName = "pionex-trade-mcp";
948
+ if (client === "claude-code") {
949
+ const claudeArgs = [
950
+ "mcp",
951
+ "add",
952
+ "--transport",
953
+ "stdio",
954
+ serverName,
955
+ "--",
956
+ "pionex-trade-mcp"
957
+ ];
958
+ process.stdout.write(`Running: claude ${claudeArgs.join(" ")}
959
+ `);
960
+ execFileSync("claude", claudeArgs, { stdio: "inherit" });
961
+ process.stdout.write(`\u2713 Configured ${name}
962
+ `);
963
+ return;
964
+ }
965
+ const configPath = getConfigPath(client);
966
+ if (!configPath) {
967
+ throw new Error(`${name} is not supported on this platform`);
968
+ }
969
+ const entry = buildEntry(client);
970
+ mergeJsonConfig(configPath, serverName, entry);
971
+ process.stdout.write(
972
+ `\u2713 Configured ${name}
973
+ ${configPath}
974
+ Restart ${name} to apply changes.
975
+ `
976
+ );
977
+ }
978
+
979
+ // src/index.ts
980
+ var DEFAULT_PROFILE_NAME = "pionx-prod";
981
+ var DEFAULT_BASE_URL = "https://api.pionex.com";
982
+ function ask(rl, question, defaultValue = "") {
983
+ const prompt = defaultValue ? `${question} [${defaultValue}]: ` : `${question}: `;
984
+ return new Promise((resolve) => rl.question(prompt, (answer) => resolve((answer ?? "").trim() || defaultValue)));
985
+ }
986
+ async function cmdConfigInit() {
987
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
988
+ process.stdout.write("\n pionex-ai-kit v0.2.x\n");
989
+ process.stdout.write(" \u26A0\uFE0F Security Tips: NEVER send API keys in agent chat. Create a dedicated API Key for your agent. Please test thoroughly before connecting to large real-money accounts.\n");
990
+ process.stdout.write(" \u26A0\uFE0F \u5B89\u5168\u63D0\u793A\uFF1A\u5207\u52FF\u5728 Agent \u5BF9\u8BDD\u4E2D\u53D1\u9001 API Key\u3002\u8BF7\u4E3A Agent \u521B\u5EFA\u4E13\u7528API Key\u63A5\u5165\uFF0C\u5148\u7528\u5C0F\u91D1\u989D\u5145\u5206\u9A8C\u8BC1\u540E\u518D\u63A5\u5165\u5B9E\u76D8\u3002\n\n");
991
+ process.stdout.write("Pionex CLI \u2014 Configuration Wizard\n\n");
992
+ process.stdout.write("Go to https://www.pionex.com/zh-CN/my-account/api to create an API Key (trade permission required)\n\n");
993
+ process.stdout.write("Credentials will be saved to " + configFilePath() + "\n\n");
994
+ const apiKey = await ask(rl, "Pionex API Key");
995
+ if (!apiKey) {
996
+ process.stderr.write(" Error: API Key cannot be empty.\n");
997
+ rl.close();
998
+ process.exit(1);
999
+ }
1000
+ const secretKey = await ask(rl, "Pionex API Secret");
1001
+ if (!secretKey) {
1002
+ process.stderr.write(" Error: API Secret cannot be empty.\n");
1003
+ rl.close();
1004
+ process.exit(1);
1005
+ }
1006
+ const profileName = await ask(rl, "Profile name", DEFAULT_PROFILE_NAME);
1007
+ rl.close();
1008
+ let config = { profiles: {} };
1009
+ try {
1010
+ config = readFullConfig();
1011
+ } catch {
1012
+ config = { profiles: {} };
1013
+ }
1014
+ if (!config.profiles) config.profiles = {};
1015
+ const profile = {
1016
+ api_key: apiKey,
1017
+ secret_key: secretKey,
1018
+ base_url: DEFAULT_BASE_URL
1019
+ };
1020
+ config.profiles[profileName] = profile;
1021
+ config.default_profile = profileName;
1022
+ try {
1023
+ writeFullConfig(config);
1024
+ } catch (e) {
1025
+ process.stderr.write(" Failed to write config: " + (e instanceof Error ? e.message : String(e)) + "\n");
1026
+ process.exit(1);
1027
+ }
1028
+ process.stdout.write("\n Config saved to " + configFilePath() + "\n");
1029
+ process.stdout.write(" Default profile: " + profileName + "\n");
1030
+ process.stdout.write(" Usage: pionex-ai-kit config init\n");
1031
+ process.stdout.write(
1032
+ " Next: run 'pionex-ai-kit setup --mcp=pionex-trade-mcp --client cursor' or 'pionex-trade-mcp setup --client cursor' to register the MCP server.\n You can replace 'cursor' with 'claude-desktop', 'windsurf', 'vscode', 'claude-code', or 'open_claw' depending on which agent you want to configure.\n\n"
1033
+ );
1034
+ }
1035
+ function printHelp() {
1036
+ process.stdout.write(`
1037
+ Usage: pionex-ai-kit <command>
1038
+
1039
+ Commands:
1040
+ config init Interactive wizard to create ~/.pionex/config.toml (API key, secret)
1041
+ help Show this help
1042
+
1043
+ The MCP server (pionex-trade-mcp) reads credentials from ~/.pionex/config.toml.
1044
+ Install it with: npm install -g pionex-trade-mcp
1045
+ Then run: pionex-trade-mcp setup --client cursor
1046
+
1047
+ Shortcuts:
1048
+ setup Equivalent to 'pionex-trade-mcp setup --client <client>' (for pionex-trade-mcp)
1049
+
1050
+ `);
1051
+ }
1052
+ function parseSetupArgs(argv) {
1053
+ let mcp;
1054
+ let client;
1055
+ for (let i = 0; i < argv.length; i++) {
1056
+ const arg = argv[i];
1057
+ if (arg === "--mcp" && argv[i + 1]) {
1058
+ mcp = argv[++i];
1059
+ } else if (arg.startsWith("--mcp=")) {
1060
+ mcp = arg.slice("--mcp=".length);
1061
+ } else if (arg === "--client" && argv[i + 1]) {
1062
+ client = argv[++i];
1063
+ } else if (arg.startsWith("--client=")) {
1064
+ client = arg.slice("--client=".length);
1065
+ }
1066
+ }
1067
+ return { mcp, client };
1068
+ }
1069
+ function cmdSetup(argv) {
1070
+ const { mcp, client } = parseSetupArgs(argv);
1071
+ const targetMcp = mcp ?? "pionex-trade-mcp";
1072
+ if (targetMcp !== "pionex-trade-mcp") {
1073
+ process.stderr.write(`Unsupported MCP server: ${targetMcp}. Currently only 'pionex-trade-mcp' is supported.
1074
+ `);
1075
+ process.exit(1);
1076
+ }
1077
+ if (!client) {
1078
+ process.stderr.write(
1079
+ "Usage: pionex-ai-kit setup --mcp=pionex-trade-mcp --client <" + SUPPORTED_CLIENTS.join("|") + ">\n"
1080
+ );
1081
+ process.exit(1);
1082
+ }
1083
+ if (!SUPPORTED_CLIENTS.includes(client)) {
1084
+ process.stderr.write(
1085
+ `Unsupported client: ${client}. Supported: ${SUPPORTED_CLIENTS.join(", ")}
1086
+ `
1087
+ );
1088
+ process.exit(1);
1089
+ }
1090
+ runSetup({ client });
1091
+ }
1092
+ function main() {
1093
+ const cmd = process.argv[2];
1094
+ if (cmd === "config" && process.argv[3] === "init") {
1095
+ cmdConfigInit().catch((e) => {
1096
+ process.stderr.write(String(e) + "\n");
1097
+ process.exit(1);
1098
+ });
1099
+ return;
1100
+ }
1101
+ if (cmd === "setup") {
1102
+ cmdSetup(process.argv.slice(3));
1103
+ return;
1104
+ }
1105
+ if (cmd === "help" || cmd === "--help" || cmd === "-h" || !cmd) {
1106
+ printHelp();
1107
+ return;
1108
+ }
1109
+ process.stderr.write("Unknown command: " + cmd + ". Run 'pionex-ai-kit help'.\n");
1110
+ process.exit(1);
1111
+ }
1112
+ main();
1113
+ /*! Bundled license information:
1114
+
1115
+ smol-toml/dist/error.js:
1116
+ smol-toml/dist/util.js:
1117
+ smol-toml/dist/date.js:
1118
+ smol-toml/dist/primitive.js:
1119
+ smol-toml/dist/extract.js:
1120
+ smol-toml/dist/struct.js:
1121
+ smol-toml/dist/parse.js:
1122
+ smol-toml/dist/stringify.js:
1123
+ smol-toml/dist/index.js:
1124
+ (*!
1125
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
1126
+ * SPDX-License-Identifier: BSD-3-Clause
1127
+ *
1128
+ * Redistribution and use in source and binary forms, with or without
1129
+ * modification, are permitted provided that the following conditions are met:
1130
+ *
1131
+ * 1. Redistributions of source code must retain the above copyright notice, this
1132
+ * list of conditions and the following disclaimer.
1133
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
1134
+ * this list of conditions and the following disclaimer in the
1135
+ * documentation and/or other materials provided with the distribution.
1136
+ * 3. Neither the name of the copyright holder nor the names of its contributors
1137
+ * may be used to endorse or promote products derived from this software without
1138
+ * specific prior written permission.
1139
+ *
1140
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1141
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1142
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1143
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
1144
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1145
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1146
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1147
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1148
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1149
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1150
+ *)
1151
+ */
1152
+ //# sourceMappingURL=index.js.map