@devness/useai-cli 0.8.6 → 0.8.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +521 -507
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ var SYSTEMD_SERVICE_PATH = join(homedir(), ".config", "systemd", "user", "useai-
|
|
|
30
30
|
var WINDOWS_STARTUP_SCRIPT_PATH = join(process.env["APPDATA"] ?? join(homedir(), "AppData", "Roaming"), "Microsoft", "Windows", "Start Menu", "Programs", "Startup", "useai-daemon.vbs");
|
|
31
31
|
|
|
32
32
|
// ../shared/dist/constants/version.js
|
|
33
|
-
var VERSION = "0.8.
|
|
33
|
+
var VERSION = "0.8.7";
|
|
34
34
|
|
|
35
35
|
// ../shared/dist/constants/defaults.js
|
|
36
36
|
var DEFAULT_CAPTURE_CONFIG = {
|
|
@@ -158,7 +158,7 @@ var KNOWN_CLIENTS = Object.keys(TOOL_COLORS);
|
|
|
158
158
|
|
|
159
159
|
// src/commands/stats.ts
|
|
160
160
|
import { Command } from "commander";
|
|
161
|
-
import
|
|
161
|
+
import pc2 from "picocolors";
|
|
162
162
|
|
|
163
163
|
// ../shared/dist/utils/fs.js
|
|
164
164
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync } from "fs";
|
|
@@ -291,24 +291,29 @@ function calculateStreak(sessions) {
|
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
// src/utils/display.ts
|
|
294
|
-
import
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
${
|
|
294
|
+
import pc from "picocolors";
|
|
295
|
+
import { homedir as homedir2 } from "os";
|
|
296
|
+
function header(text2) {
|
|
297
|
+
return pc.bold(pc.cyan(`
|
|
298
|
+
${text2}
|
|
299
|
+
${"\u2500".repeat(text2.length)}`));
|
|
299
300
|
}
|
|
300
301
|
function table(rows) {
|
|
301
302
|
const maxLabel = Math.max(...rows.map(([label]) => label.length));
|
|
302
|
-
return rows.map(([label, value]) => ` ${
|
|
303
|
+
return rows.map(([label, value]) => ` ${pc.dim(label.padEnd(maxLabel))} ${value}`).join("\n");
|
|
304
|
+
}
|
|
305
|
+
function success(text2) {
|
|
306
|
+
return pc.green(` ${text2}`);
|
|
303
307
|
}
|
|
304
|
-
function
|
|
305
|
-
return
|
|
308
|
+
function error(text2) {
|
|
309
|
+
return pc.red(` ${text2}`);
|
|
306
310
|
}
|
|
307
|
-
function
|
|
308
|
-
return
|
|
311
|
+
function info(text2) {
|
|
312
|
+
return pc.dim(` ${text2}`);
|
|
309
313
|
}
|
|
310
|
-
function
|
|
311
|
-
|
|
314
|
+
function shortenPath(p3) {
|
|
315
|
+
const home2 = homedir2();
|
|
316
|
+
return home2 && p3.startsWith(home2) ? "~" + p3.slice(home2.length) : p3;
|
|
312
317
|
}
|
|
313
318
|
|
|
314
319
|
// src/commands/stats.ts
|
|
@@ -321,9 +326,9 @@ var statsCommand = new Command("stats").description("Show aggregated AI developm
|
|
|
321
326
|
console.log(header("AI Development Stats"));
|
|
322
327
|
console.log(
|
|
323
328
|
table([
|
|
324
|
-
["Total time",
|
|
325
|
-
["Sessions",
|
|
326
|
-
["Current streak",
|
|
329
|
+
["Total time", pc2.bold(formatDuration(Math.round(stats.totalHours * 3600)))],
|
|
330
|
+
["Sessions", pc2.bold(String(stats.totalSessions))],
|
|
331
|
+
["Current streak", pc2.bold(`${stats.currentStreak} day${stats.currentStreak !== 1 ? "s" : ""}`)]
|
|
327
332
|
])
|
|
328
333
|
);
|
|
329
334
|
const clientEntries = Object.entries(stats.byClient).sort((a, b) => b[1] - a[1]);
|
|
@@ -353,7 +358,7 @@ var statsCommand = new Command("stats").description("Show aggregated AI developm
|
|
|
353
358
|
// src/commands/status.ts
|
|
354
359
|
import { Command as Command2 } from "commander";
|
|
355
360
|
import { existsSync as existsSync2, statSync, readdirSync } from "fs";
|
|
356
|
-
import
|
|
361
|
+
import pc3 from "picocolors";
|
|
357
362
|
|
|
358
363
|
// src/services/config.service.ts
|
|
359
364
|
function getConfig() {
|
|
@@ -405,23 +410,23 @@ var statusCommand = new Command2("status").description("Full transparency dashbo
|
|
|
405
410
|
console.log(header("useai Status"));
|
|
406
411
|
console.log(
|
|
407
412
|
table([
|
|
408
|
-
["Sessions recorded",
|
|
409
|
-
["Total tracked time",
|
|
410
|
-
["Milestones",
|
|
411
|
-
["Local storage",
|
|
412
|
-
["Data directory",
|
|
413
|
+
["Sessions recorded", pc3.bold(String(sessions.length))],
|
|
414
|
+
["Total tracked time", pc3.bold(formatDuration(totalSeconds))],
|
|
415
|
+
["Milestones", pc3.bold(`${unpublished} unpublished, ${published} published`)],
|
|
416
|
+
["Local storage", pc3.bold(formatBytes(storageSize))],
|
|
417
|
+
["Data directory", pc3.dim(DATA_DIR)]
|
|
413
418
|
])
|
|
414
419
|
);
|
|
415
420
|
console.log(header("Settings"));
|
|
416
421
|
console.log(
|
|
417
422
|
table([
|
|
418
|
-
["Milestone tracking", config.capture.milestones ?
|
|
419
|
-
["Prompt capture", config.capture.prompt ?
|
|
423
|
+
["Milestone tracking", config.capture.milestones ? pc3.green("on") : pc3.red("off")],
|
|
424
|
+
["Prompt capture", config.capture.prompt ? pc3.green("on") : pc3.red("off")],
|
|
420
425
|
["Eval reasons", config.capture.evaluation_reasons],
|
|
421
|
-
["Cloud sync", config.sync.enabled ?
|
|
426
|
+
["Cloud sync", config.sync.enabled ? pc3.green("on") : pc3.red("off")],
|
|
422
427
|
["Sync interval", `${config.sync.interval_hours}h`],
|
|
423
|
-
["Last sync", config.last_sync_at ??
|
|
424
|
-
["Logged in", config.auth ?
|
|
428
|
+
["Last sync", config.last_sync_at ?? pc3.dim("never")],
|
|
429
|
+
["Logged in", config.auth ? pc3.green(config.auth.user.email) : pc3.dim("no")]
|
|
425
430
|
])
|
|
426
431
|
);
|
|
427
432
|
console.log(header("Privacy"));
|
|
@@ -436,7 +441,7 @@ var statusCommand = new Command2("status").description("Full transparency dashbo
|
|
|
436
441
|
|
|
437
442
|
// src/commands/milestones.ts
|
|
438
443
|
import { Command as Command3 } from "commander";
|
|
439
|
-
import
|
|
444
|
+
import pc4 from "picocolors";
|
|
440
445
|
var milestonesCommand = new Command3("milestones").description("List local milestones").option("-v, --verbose", "Show full milestone details").action((opts) => {
|
|
441
446
|
const milestones = readJson(MILESTONES_FILE, []);
|
|
442
447
|
if (milestones.length === 0) {
|
|
@@ -445,11 +450,11 @@ var milestonesCommand = new Command3("milestones").description("List local miles
|
|
|
445
450
|
}
|
|
446
451
|
console.log(header(`Milestones (${milestones.length})`));
|
|
447
452
|
for (const m of milestones) {
|
|
448
|
-
const status = m.published ?
|
|
453
|
+
const status = m.published ? pc4.green("published") : pc4.yellow("local");
|
|
449
454
|
const displayTitle = m.private_title ?? m.title;
|
|
450
455
|
console.log(
|
|
451
456
|
`
|
|
452
|
-
${
|
|
457
|
+
${pc4.bold(displayTitle)} ${status}`
|
|
453
458
|
);
|
|
454
459
|
console.log(
|
|
455
460
|
table([
|
|
@@ -461,11 +466,11 @@ var milestonesCommand = new Command3("milestones").description("List local miles
|
|
|
461
466
|
);
|
|
462
467
|
if (opts.verbose) {
|
|
463
468
|
const verboseRows = [
|
|
464
|
-
["ID",
|
|
465
|
-
["Session",
|
|
469
|
+
["ID", pc4.dim(m.id)],
|
|
470
|
+
["Session", pc4.dim(m.session_id)],
|
|
466
471
|
["Client", m.client],
|
|
467
472
|
["Languages", m.languages.join(", ") || "none"],
|
|
468
|
-
["Chain hash",
|
|
473
|
+
["Chain hash", pc4.dim(m.chain_hash.slice(0, 16) + "...")],
|
|
469
474
|
["Published at", m.published_at ?? "n/a"]
|
|
470
475
|
];
|
|
471
476
|
if (m.private_title) {
|
|
@@ -479,7 +484,7 @@ var milestonesCommand = new Command3("milestones").description("List local miles
|
|
|
479
484
|
|
|
480
485
|
// src/commands/config.ts
|
|
481
486
|
import { Command as Command4 } from "commander";
|
|
482
|
-
import
|
|
487
|
+
import pc5 from "picocolors";
|
|
483
488
|
|
|
484
489
|
// ../shared/dist/crypto/keystore.js
|
|
485
490
|
import { generateKeyPairSync, randomBytes, createCipheriv, createDecipheriv, createPrivateKey } from "crypto";
|
|
@@ -1153,41 +1158,41 @@ var ZodType = class {
|
|
|
1153
1158
|
get description() {
|
|
1154
1159
|
return this._def.description;
|
|
1155
1160
|
}
|
|
1156
|
-
_getType(
|
|
1157
|
-
return getParsedType(
|
|
1161
|
+
_getType(input) {
|
|
1162
|
+
return getParsedType(input.data);
|
|
1158
1163
|
}
|
|
1159
|
-
_getOrReturnCtx(
|
|
1164
|
+
_getOrReturnCtx(input, ctx) {
|
|
1160
1165
|
return ctx || {
|
|
1161
|
-
common:
|
|
1162
|
-
data:
|
|
1163
|
-
parsedType: getParsedType(
|
|
1166
|
+
common: input.parent.common,
|
|
1167
|
+
data: input.data,
|
|
1168
|
+
parsedType: getParsedType(input.data),
|
|
1164
1169
|
schemaErrorMap: this._def.errorMap,
|
|
1165
|
-
path:
|
|
1166
|
-
parent:
|
|
1170
|
+
path: input.path,
|
|
1171
|
+
parent: input.parent
|
|
1167
1172
|
};
|
|
1168
1173
|
}
|
|
1169
|
-
_processInputParams(
|
|
1174
|
+
_processInputParams(input) {
|
|
1170
1175
|
return {
|
|
1171
1176
|
status: new ParseStatus(),
|
|
1172
1177
|
ctx: {
|
|
1173
|
-
common:
|
|
1174
|
-
data:
|
|
1175
|
-
parsedType: getParsedType(
|
|
1178
|
+
common: input.parent.common,
|
|
1179
|
+
data: input.data,
|
|
1180
|
+
parsedType: getParsedType(input.data),
|
|
1176
1181
|
schemaErrorMap: this._def.errorMap,
|
|
1177
|
-
path:
|
|
1178
|
-
parent:
|
|
1182
|
+
path: input.path,
|
|
1183
|
+
parent: input.parent
|
|
1179
1184
|
}
|
|
1180
1185
|
};
|
|
1181
1186
|
}
|
|
1182
|
-
_parseSync(
|
|
1183
|
-
const result = this._parse(
|
|
1187
|
+
_parseSync(input) {
|
|
1188
|
+
const result = this._parse(input);
|
|
1184
1189
|
if (isAsync(result)) {
|
|
1185
1190
|
throw new Error("Synchronous parse encountered promise.");
|
|
1186
1191
|
}
|
|
1187
1192
|
return result;
|
|
1188
1193
|
}
|
|
1189
|
-
_parseAsync(
|
|
1190
|
-
const result = this._parse(
|
|
1194
|
+
_parseAsync(input) {
|
|
1195
|
+
const result = this._parse(input);
|
|
1191
1196
|
return Promise.resolve(result);
|
|
1192
1197
|
}
|
|
1193
1198
|
parse(data, params) {
|
|
@@ -1513,13 +1518,13 @@ function isValidCidr(ip, version) {
|
|
|
1513
1518
|
return false;
|
|
1514
1519
|
}
|
|
1515
1520
|
var ZodString = class _ZodString extends ZodType {
|
|
1516
|
-
_parse(
|
|
1521
|
+
_parse(input) {
|
|
1517
1522
|
if (this._def.coerce) {
|
|
1518
|
-
|
|
1523
|
+
input.data = String(input.data);
|
|
1519
1524
|
}
|
|
1520
|
-
const parsedType = this._getType(
|
|
1525
|
+
const parsedType = this._getType(input);
|
|
1521
1526
|
if (parsedType !== ZodParsedType.string) {
|
|
1522
|
-
const ctx2 = this._getOrReturnCtx(
|
|
1527
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1523
1528
|
addIssueToContext(ctx2, {
|
|
1524
1529
|
code: ZodIssueCode.invalid_type,
|
|
1525
1530
|
expected: ZodParsedType.string,
|
|
@@ -1531,8 +1536,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1531
1536
|
let ctx = void 0;
|
|
1532
1537
|
for (const check of this._def.checks) {
|
|
1533
1538
|
if (check.kind === "min") {
|
|
1534
|
-
if (
|
|
1535
|
-
ctx = this._getOrReturnCtx(
|
|
1539
|
+
if (input.data.length < check.value) {
|
|
1540
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1536
1541
|
addIssueToContext(ctx, {
|
|
1537
1542
|
code: ZodIssueCode.too_small,
|
|
1538
1543
|
minimum: check.value,
|
|
@@ -1544,8 +1549,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1544
1549
|
status.dirty();
|
|
1545
1550
|
}
|
|
1546
1551
|
} else if (check.kind === "max") {
|
|
1547
|
-
if (
|
|
1548
|
-
ctx = this._getOrReturnCtx(
|
|
1552
|
+
if (input.data.length > check.value) {
|
|
1553
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1549
1554
|
addIssueToContext(ctx, {
|
|
1550
1555
|
code: ZodIssueCode.too_big,
|
|
1551
1556
|
maximum: check.value,
|
|
@@ -1557,10 +1562,10 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1557
1562
|
status.dirty();
|
|
1558
1563
|
}
|
|
1559
1564
|
} else if (check.kind === "length") {
|
|
1560
|
-
const tooBig =
|
|
1561
|
-
const tooSmall =
|
|
1565
|
+
const tooBig = input.data.length > check.value;
|
|
1566
|
+
const tooSmall = input.data.length < check.value;
|
|
1562
1567
|
if (tooBig || tooSmall) {
|
|
1563
|
-
ctx = this._getOrReturnCtx(
|
|
1568
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1564
1569
|
if (tooBig) {
|
|
1565
1570
|
addIssueToContext(ctx, {
|
|
1566
1571
|
code: ZodIssueCode.too_big,
|
|
@@ -1583,8 +1588,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1583
1588
|
status.dirty();
|
|
1584
1589
|
}
|
|
1585
1590
|
} else if (check.kind === "email") {
|
|
1586
|
-
if (!emailRegex.test(
|
|
1587
|
-
ctx = this._getOrReturnCtx(
|
|
1591
|
+
if (!emailRegex.test(input.data)) {
|
|
1592
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1588
1593
|
addIssueToContext(ctx, {
|
|
1589
1594
|
validation: "email",
|
|
1590
1595
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1596,8 +1601,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1596
1601
|
if (!emojiRegex) {
|
|
1597
1602
|
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
1598
1603
|
}
|
|
1599
|
-
if (!emojiRegex.test(
|
|
1600
|
-
ctx = this._getOrReturnCtx(
|
|
1604
|
+
if (!emojiRegex.test(input.data)) {
|
|
1605
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1601
1606
|
addIssueToContext(ctx, {
|
|
1602
1607
|
validation: "emoji",
|
|
1603
1608
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1606,8 +1611,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1606
1611
|
status.dirty();
|
|
1607
1612
|
}
|
|
1608
1613
|
} else if (check.kind === "uuid") {
|
|
1609
|
-
if (!uuidRegex.test(
|
|
1610
|
-
ctx = this._getOrReturnCtx(
|
|
1614
|
+
if (!uuidRegex.test(input.data)) {
|
|
1615
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1611
1616
|
addIssueToContext(ctx, {
|
|
1612
1617
|
validation: "uuid",
|
|
1613
1618
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1616,8 +1621,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1616
1621
|
status.dirty();
|
|
1617
1622
|
}
|
|
1618
1623
|
} else if (check.kind === "nanoid") {
|
|
1619
|
-
if (!nanoidRegex.test(
|
|
1620
|
-
ctx = this._getOrReturnCtx(
|
|
1624
|
+
if (!nanoidRegex.test(input.data)) {
|
|
1625
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1621
1626
|
addIssueToContext(ctx, {
|
|
1622
1627
|
validation: "nanoid",
|
|
1623
1628
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1626,8 +1631,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1626
1631
|
status.dirty();
|
|
1627
1632
|
}
|
|
1628
1633
|
} else if (check.kind === "cuid") {
|
|
1629
|
-
if (!cuidRegex.test(
|
|
1630
|
-
ctx = this._getOrReturnCtx(
|
|
1634
|
+
if (!cuidRegex.test(input.data)) {
|
|
1635
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1631
1636
|
addIssueToContext(ctx, {
|
|
1632
1637
|
validation: "cuid",
|
|
1633
1638
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1636,8 +1641,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1636
1641
|
status.dirty();
|
|
1637
1642
|
}
|
|
1638
1643
|
} else if (check.kind === "cuid2") {
|
|
1639
|
-
if (!cuid2Regex.test(
|
|
1640
|
-
ctx = this._getOrReturnCtx(
|
|
1644
|
+
if (!cuid2Regex.test(input.data)) {
|
|
1645
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1641
1646
|
addIssueToContext(ctx, {
|
|
1642
1647
|
validation: "cuid2",
|
|
1643
1648
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1646,8 +1651,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1646
1651
|
status.dirty();
|
|
1647
1652
|
}
|
|
1648
1653
|
} else if (check.kind === "ulid") {
|
|
1649
|
-
if (!ulidRegex.test(
|
|
1650
|
-
ctx = this._getOrReturnCtx(
|
|
1654
|
+
if (!ulidRegex.test(input.data)) {
|
|
1655
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1651
1656
|
addIssueToContext(ctx, {
|
|
1652
1657
|
validation: "ulid",
|
|
1653
1658
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1657,9 +1662,9 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1657
1662
|
}
|
|
1658
1663
|
} else if (check.kind === "url") {
|
|
1659
1664
|
try {
|
|
1660
|
-
new URL(
|
|
1665
|
+
new URL(input.data);
|
|
1661
1666
|
} catch {
|
|
1662
|
-
ctx = this._getOrReturnCtx(
|
|
1667
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1663
1668
|
addIssueToContext(ctx, {
|
|
1664
1669
|
validation: "url",
|
|
1665
1670
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1669,9 +1674,9 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1669
1674
|
}
|
|
1670
1675
|
} else if (check.kind === "regex") {
|
|
1671
1676
|
check.regex.lastIndex = 0;
|
|
1672
|
-
const testResult = check.regex.test(
|
|
1677
|
+
const testResult = check.regex.test(input.data);
|
|
1673
1678
|
if (!testResult) {
|
|
1674
|
-
ctx = this._getOrReturnCtx(
|
|
1679
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1675
1680
|
addIssueToContext(ctx, {
|
|
1676
1681
|
validation: "regex",
|
|
1677
1682
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1680,10 +1685,10 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1680
1685
|
status.dirty();
|
|
1681
1686
|
}
|
|
1682
1687
|
} else if (check.kind === "trim") {
|
|
1683
|
-
|
|
1688
|
+
input.data = input.data.trim();
|
|
1684
1689
|
} else if (check.kind === "includes") {
|
|
1685
|
-
if (!
|
|
1686
|
-
ctx = this._getOrReturnCtx(
|
|
1690
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
1691
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1687
1692
|
addIssueToContext(ctx, {
|
|
1688
1693
|
code: ZodIssueCode.invalid_string,
|
|
1689
1694
|
validation: { includes: check.value, position: check.position },
|
|
@@ -1692,12 +1697,12 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1692
1697
|
status.dirty();
|
|
1693
1698
|
}
|
|
1694
1699
|
} else if (check.kind === "toLowerCase") {
|
|
1695
|
-
|
|
1700
|
+
input.data = input.data.toLowerCase();
|
|
1696
1701
|
} else if (check.kind === "toUpperCase") {
|
|
1697
|
-
|
|
1702
|
+
input.data = input.data.toUpperCase();
|
|
1698
1703
|
} else if (check.kind === "startsWith") {
|
|
1699
|
-
if (!
|
|
1700
|
-
ctx = this._getOrReturnCtx(
|
|
1704
|
+
if (!input.data.startsWith(check.value)) {
|
|
1705
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1701
1706
|
addIssueToContext(ctx, {
|
|
1702
1707
|
code: ZodIssueCode.invalid_string,
|
|
1703
1708
|
validation: { startsWith: check.value },
|
|
@@ -1706,8 +1711,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1706
1711
|
status.dirty();
|
|
1707
1712
|
}
|
|
1708
1713
|
} else if (check.kind === "endsWith") {
|
|
1709
|
-
if (!
|
|
1710
|
-
ctx = this._getOrReturnCtx(
|
|
1714
|
+
if (!input.data.endsWith(check.value)) {
|
|
1715
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1711
1716
|
addIssueToContext(ctx, {
|
|
1712
1717
|
code: ZodIssueCode.invalid_string,
|
|
1713
1718
|
validation: { endsWith: check.value },
|
|
@@ -1717,8 +1722,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1717
1722
|
}
|
|
1718
1723
|
} else if (check.kind === "datetime") {
|
|
1719
1724
|
const regex = datetimeRegex(check);
|
|
1720
|
-
if (!regex.test(
|
|
1721
|
-
ctx = this._getOrReturnCtx(
|
|
1725
|
+
if (!regex.test(input.data)) {
|
|
1726
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1722
1727
|
addIssueToContext(ctx, {
|
|
1723
1728
|
code: ZodIssueCode.invalid_string,
|
|
1724
1729
|
validation: "datetime",
|
|
@@ -1728,8 +1733,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1728
1733
|
}
|
|
1729
1734
|
} else if (check.kind === "date") {
|
|
1730
1735
|
const regex = dateRegex;
|
|
1731
|
-
if (!regex.test(
|
|
1732
|
-
ctx = this._getOrReturnCtx(
|
|
1736
|
+
if (!regex.test(input.data)) {
|
|
1737
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1733
1738
|
addIssueToContext(ctx, {
|
|
1734
1739
|
code: ZodIssueCode.invalid_string,
|
|
1735
1740
|
validation: "date",
|
|
@@ -1739,8 +1744,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1739
1744
|
}
|
|
1740
1745
|
} else if (check.kind === "time") {
|
|
1741
1746
|
const regex = timeRegex(check);
|
|
1742
|
-
if (!regex.test(
|
|
1743
|
-
ctx = this._getOrReturnCtx(
|
|
1747
|
+
if (!regex.test(input.data)) {
|
|
1748
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1744
1749
|
addIssueToContext(ctx, {
|
|
1745
1750
|
code: ZodIssueCode.invalid_string,
|
|
1746
1751
|
validation: "time",
|
|
@@ -1749,8 +1754,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1749
1754
|
status.dirty();
|
|
1750
1755
|
}
|
|
1751
1756
|
} else if (check.kind === "duration") {
|
|
1752
|
-
if (!durationRegex.test(
|
|
1753
|
-
ctx = this._getOrReturnCtx(
|
|
1757
|
+
if (!durationRegex.test(input.data)) {
|
|
1758
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1754
1759
|
addIssueToContext(ctx, {
|
|
1755
1760
|
validation: "duration",
|
|
1756
1761
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1759,8 +1764,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1759
1764
|
status.dirty();
|
|
1760
1765
|
}
|
|
1761
1766
|
} else if (check.kind === "ip") {
|
|
1762
|
-
if (!isValidIP(
|
|
1763
|
-
ctx = this._getOrReturnCtx(
|
|
1767
|
+
if (!isValidIP(input.data, check.version)) {
|
|
1768
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1764
1769
|
addIssueToContext(ctx, {
|
|
1765
1770
|
validation: "ip",
|
|
1766
1771
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1769,8 +1774,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1769
1774
|
status.dirty();
|
|
1770
1775
|
}
|
|
1771
1776
|
} else if (check.kind === "jwt") {
|
|
1772
|
-
if (!isValidJWT(
|
|
1773
|
-
ctx = this._getOrReturnCtx(
|
|
1777
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1778
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1774
1779
|
addIssueToContext(ctx, {
|
|
1775
1780
|
validation: "jwt",
|
|
1776
1781
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1779,8 +1784,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1779
1784
|
status.dirty();
|
|
1780
1785
|
}
|
|
1781
1786
|
} else if (check.kind === "cidr") {
|
|
1782
|
-
if (!isValidCidr(
|
|
1783
|
-
ctx = this._getOrReturnCtx(
|
|
1787
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1788
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1784
1789
|
addIssueToContext(ctx, {
|
|
1785
1790
|
validation: "cidr",
|
|
1786
1791
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1789,8 +1794,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1789
1794
|
status.dirty();
|
|
1790
1795
|
}
|
|
1791
1796
|
} else if (check.kind === "base64") {
|
|
1792
|
-
if (!base64Regex.test(
|
|
1793
|
-
ctx = this._getOrReturnCtx(
|
|
1797
|
+
if (!base64Regex.test(input.data)) {
|
|
1798
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1794
1799
|
addIssueToContext(ctx, {
|
|
1795
1800
|
validation: "base64",
|
|
1796
1801
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1799,8 +1804,8 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1799
1804
|
status.dirty();
|
|
1800
1805
|
}
|
|
1801
1806
|
} else if (check.kind === "base64url") {
|
|
1802
|
-
if (!base64urlRegex.test(
|
|
1803
|
-
ctx = this._getOrReturnCtx(
|
|
1807
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1808
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1804
1809
|
addIssueToContext(ctx, {
|
|
1805
1810
|
validation: "base64url",
|
|
1806
1811
|
code: ZodIssueCode.invalid_string,
|
|
@@ -1812,7 +1817,7 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1812
1817
|
util.assertNever(check);
|
|
1813
1818
|
}
|
|
1814
1819
|
}
|
|
1815
|
-
return { status: status.value, value:
|
|
1820
|
+
return { status: status.value, value: input.data };
|
|
1816
1821
|
}
|
|
1817
1822
|
_regex(regex, validation, message) {
|
|
1818
1823
|
return this.refinement((data) => regex.test(data), {
|
|
@@ -2073,13 +2078,13 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
|
2073
2078
|
this.max = this.lte;
|
|
2074
2079
|
this.step = this.multipleOf;
|
|
2075
2080
|
}
|
|
2076
|
-
_parse(
|
|
2081
|
+
_parse(input) {
|
|
2077
2082
|
if (this._def.coerce) {
|
|
2078
|
-
|
|
2083
|
+
input.data = Number(input.data);
|
|
2079
2084
|
}
|
|
2080
|
-
const parsedType = this._getType(
|
|
2085
|
+
const parsedType = this._getType(input);
|
|
2081
2086
|
if (parsedType !== ZodParsedType.number) {
|
|
2082
|
-
const ctx2 = this._getOrReturnCtx(
|
|
2087
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2083
2088
|
addIssueToContext(ctx2, {
|
|
2084
2089
|
code: ZodIssueCode.invalid_type,
|
|
2085
2090
|
expected: ZodParsedType.number,
|
|
@@ -2091,8 +2096,8 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
|
2091
2096
|
const status = new ParseStatus();
|
|
2092
2097
|
for (const check of this._def.checks) {
|
|
2093
2098
|
if (check.kind === "int") {
|
|
2094
|
-
if (!util.isInteger(
|
|
2095
|
-
ctx = this._getOrReturnCtx(
|
|
2099
|
+
if (!util.isInteger(input.data)) {
|
|
2100
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2096
2101
|
addIssueToContext(ctx, {
|
|
2097
2102
|
code: ZodIssueCode.invalid_type,
|
|
2098
2103
|
expected: "integer",
|
|
@@ -2102,9 +2107,9 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
|
2102
2107
|
status.dirty();
|
|
2103
2108
|
}
|
|
2104
2109
|
} else if (check.kind === "min") {
|
|
2105
|
-
const tooSmall = check.inclusive ?
|
|
2110
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
2106
2111
|
if (tooSmall) {
|
|
2107
|
-
ctx = this._getOrReturnCtx(
|
|
2112
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2108
2113
|
addIssueToContext(ctx, {
|
|
2109
2114
|
code: ZodIssueCode.too_small,
|
|
2110
2115
|
minimum: check.value,
|
|
@@ -2116,9 +2121,9 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
|
2116
2121
|
status.dirty();
|
|
2117
2122
|
}
|
|
2118
2123
|
} else if (check.kind === "max") {
|
|
2119
|
-
const tooBig = check.inclusive ?
|
|
2124
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
2120
2125
|
if (tooBig) {
|
|
2121
|
-
ctx = this._getOrReturnCtx(
|
|
2126
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2122
2127
|
addIssueToContext(ctx, {
|
|
2123
2128
|
code: ZodIssueCode.too_big,
|
|
2124
2129
|
maximum: check.value,
|
|
@@ -2130,8 +2135,8 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
|
2130
2135
|
status.dirty();
|
|
2131
2136
|
}
|
|
2132
2137
|
} else if (check.kind === "multipleOf") {
|
|
2133
|
-
if (floatSafeRemainder(
|
|
2134
|
-
ctx = this._getOrReturnCtx(
|
|
2138
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
2139
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2135
2140
|
addIssueToContext(ctx, {
|
|
2136
2141
|
code: ZodIssueCode.not_multiple_of,
|
|
2137
2142
|
multipleOf: check.value,
|
|
@@ -2140,8 +2145,8 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
|
2140
2145
|
status.dirty();
|
|
2141
2146
|
}
|
|
2142
2147
|
} else if (check.kind === "finite") {
|
|
2143
|
-
if (!Number.isFinite(
|
|
2144
|
-
ctx = this._getOrReturnCtx(
|
|
2148
|
+
if (!Number.isFinite(input.data)) {
|
|
2149
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2145
2150
|
addIssueToContext(ctx, {
|
|
2146
2151
|
code: ZodIssueCode.not_finite,
|
|
2147
2152
|
message: check.message
|
|
@@ -2152,7 +2157,7 @@ var ZodNumber = class _ZodNumber extends ZodType {
|
|
|
2152
2157
|
util.assertNever(check);
|
|
2153
2158
|
}
|
|
2154
2159
|
}
|
|
2155
|
-
return { status: status.value, value:
|
|
2160
|
+
return { status: status.value, value: input.data };
|
|
2156
2161
|
}
|
|
2157
2162
|
gte(value, message) {
|
|
2158
2163
|
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
@@ -2304,25 +2309,25 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
2304
2309
|
this.min = this.gte;
|
|
2305
2310
|
this.max = this.lte;
|
|
2306
2311
|
}
|
|
2307
|
-
_parse(
|
|
2312
|
+
_parse(input) {
|
|
2308
2313
|
if (this._def.coerce) {
|
|
2309
2314
|
try {
|
|
2310
|
-
|
|
2315
|
+
input.data = BigInt(input.data);
|
|
2311
2316
|
} catch {
|
|
2312
|
-
return this._getInvalidInput(
|
|
2317
|
+
return this._getInvalidInput(input);
|
|
2313
2318
|
}
|
|
2314
2319
|
}
|
|
2315
|
-
const parsedType = this._getType(
|
|
2320
|
+
const parsedType = this._getType(input);
|
|
2316
2321
|
if (parsedType !== ZodParsedType.bigint) {
|
|
2317
|
-
return this._getInvalidInput(
|
|
2322
|
+
return this._getInvalidInput(input);
|
|
2318
2323
|
}
|
|
2319
2324
|
let ctx = void 0;
|
|
2320
2325
|
const status = new ParseStatus();
|
|
2321
2326
|
for (const check of this._def.checks) {
|
|
2322
2327
|
if (check.kind === "min") {
|
|
2323
|
-
const tooSmall = check.inclusive ?
|
|
2328
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
2324
2329
|
if (tooSmall) {
|
|
2325
|
-
ctx = this._getOrReturnCtx(
|
|
2330
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2326
2331
|
addIssueToContext(ctx, {
|
|
2327
2332
|
code: ZodIssueCode.too_small,
|
|
2328
2333
|
type: "bigint",
|
|
@@ -2333,9 +2338,9 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
2333
2338
|
status.dirty();
|
|
2334
2339
|
}
|
|
2335
2340
|
} else if (check.kind === "max") {
|
|
2336
|
-
const tooBig = check.inclusive ?
|
|
2341
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
2337
2342
|
if (tooBig) {
|
|
2338
|
-
ctx = this._getOrReturnCtx(
|
|
2343
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2339
2344
|
addIssueToContext(ctx, {
|
|
2340
2345
|
code: ZodIssueCode.too_big,
|
|
2341
2346
|
type: "bigint",
|
|
@@ -2346,8 +2351,8 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
2346
2351
|
status.dirty();
|
|
2347
2352
|
}
|
|
2348
2353
|
} else if (check.kind === "multipleOf") {
|
|
2349
|
-
if (
|
|
2350
|
-
ctx = this._getOrReturnCtx(
|
|
2354
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
2355
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2351
2356
|
addIssueToContext(ctx, {
|
|
2352
2357
|
code: ZodIssueCode.not_multiple_of,
|
|
2353
2358
|
multipleOf: check.value,
|
|
@@ -2359,10 +2364,10 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
2359
2364
|
util.assertNever(check);
|
|
2360
2365
|
}
|
|
2361
2366
|
}
|
|
2362
|
-
return { status: status.value, value:
|
|
2367
|
+
return { status: status.value, value: input.data };
|
|
2363
2368
|
}
|
|
2364
|
-
_getInvalidInput(
|
|
2365
|
-
const ctx = this._getOrReturnCtx(
|
|
2369
|
+
_getInvalidInput(input) {
|
|
2370
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2366
2371
|
addIssueToContext(ctx, {
|
|
2367
2372
|
code: ZodIssueCode.invalid_type,
|
|
2368
2373
|
expected: ZodParsedType.bigint,
|
|
@@ -2471,13 +2476,13 @@ ZodBigInt.create = (params) => {
|
|
|
2471
2476
|
});
|
|
2472
2477
|
};
|
|
2473
2478
|
var ZodBoolean = class extends ZodType {
|
|
2474
|
-
_parse(
|
|
2479
|
+
_parse(input) {
|
|
2475
2480
|
if (this._def.coerce) {
|
|
2476
|
-
|
|
2481
|
+
input.data = Boolean(input.data);
|
|
2477
2482
|
}
|
|
2478
|
-
const parsedType = this._getType(
|
|
2483
|
+
const parsedType = this._getType(input);
|
|
2479
2484
|
if (parsedType !== ZodParsedType.boolean) {
|
|
2480
|
-
const ctx = this._getOrReturnCtx(
|
|
2485
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2481
2486
|
addIssueToContext(ctx, {
|
|
2482
2487
|
code: ZodIssueCode.invalid_type,
|
|
2483
2488
|
expected: ZodParsedType.boolean,
|
|
@@ -2485,7 +2490,7 @@ var ZodBoolean = class extends ZodType {
|
|
|
2485
2490
|
});
|
|
2486
2491
|
return INVALID;
|
|
2487
2492
|
}
|
|
2488
|
-
return OK(
|
|
2493
|
+
return OK(input.data);
|
|
2489
2494
|
}
|
|
2490
2495
|
};
|
|
2491
2496
|
ZodBoolean.create = (params) => {
|
|
@@ -2496,13 +2501,13 @@ ZodBoolean.create = (params) => {
|
|
|
2496
2501
|
});
|
|
2497
2502
|
};
|
|
2498
2503
|
var ZodDate = class _ZodDate extends ZodType {
|
|
2499
|
-
_parse(
|
|
2504
|
+
_parse(input) {
|
|
2500
2505
|
if (this._def.coerce) {
|
|
2501
|
-
|
|
2506
|
+
input.data = new Date(input.data);
|
|
2502
2507
|
}
|
|
2503
|
-
const parsedType = this._getType(
|
|
2508
|
+
const parsedType = this._getType(input);
|
|
2504
2509
|
if (parsedType !== ZodParsedType.date) {
|
|
2505
|
-
const ctx2 = this._getOrReturnCtx(
|
|
2510
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2506
2511
|
addIssueToContext(ctx2, {
|
|
2507
2512
|
code: ZodIssueCode.invalid_type,
|
|
2508
2513
|
expected: ZodParsedType.date,
|
|
@@ -2510,8 +2515,8 @@ var ZodDate = class _ZodDate extends ZodType {
|
|
|
2510
2515
|
});
|
|
2511
2516
|
return INVALID;
|
|
2512
2517
|
}
|
|
2513
|
-
if (Number.isNaN(
|
|
2514
|
-
const ctx2 = this._getOrReturnCtx(
|
|
2518
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
2519
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2515
2520
|
addIssueToContext(ctx2, {
|
|
2516
2521
|
code: ZodIssueCode.invalid_date
|
|
2517
2522
|
});
|
|
@@ -2521,8 +2526,8 @@ var ZodDate = class _ZodDate extends ZodType {
|
|
|
2521
2526
|
let ctx = void 0;
|
|
2522
2527
|
for (const check of this._def.checks) {
|
|
2523
2528
|
if (check.kind === "min") {
|
|
2524
|
-
if (
|
|
2525
|
-
ctx = this._getOrReturnCtx(
|
|
2529
|
+
if (input.data.getTime() < check.value) {
|
|
2530
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2526
2531
|
addIssueToContext(ctx, {
|
|
2527
2532
|
code: ZodIssueCode.too_small,
|
|
2528
2533
|
message: check.message,
|
|
@@ -2534,8 +2539,8 @@ var ZodDate = class _ZodDate extends ZodType {
|
|
|
2534
2539
|
status.dirty();
|
|
2535
2540
|
}
|
|
2536
2541
|
} else if (check.kind === "max") {
|
|
2537
|
-
if (
|
|
2538
|
-
ctx = this._getOrReturnCtx(
|
|
2542
|
+
if (input.data.getTime() > check.value) {
|
|
2543
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2539
2544
|
addIssueToContext(ctx, {
|
|
2540
2545
|
code: ZodIssueCode.too_big,
|
|
2541
2546
|
message: check.message,
|
|
@@ -2552,7 +2557,7 @@ var ZodDate = class _ZodDate extends ZodType {
|
|
|
2552
2557
|
}
|
|
2553
2558
|
return {
|
|
2554
2559
|
status: status.value,
|
|
2555
|
-
value: new Date(
|
|
2560
|
+
value: new Date(input.data.getTime())
|
|
2556
2561
|
};
|
|
2557
2562
|
}
|
|
2558
2563
|
_addCheck(check) {
|
|
@@ -2605,10 +2610,10 @@ ZodDate.create = (params) => {
|
|
|
2605
2610
|
});
|
|
2606
2611
|
};
|
|
2607
2612
|
var ZodSymbol = class extends ZodType {
|
|
2608
|
-
_parse(
|
|
2609
|
-
const parsedType = this._getType(
|
|
2613
|
+
_parse(input) {
|
|
2614
|
+
const parsedType = this._getType(input);
|
|
2610
2615
|
if (parsedType !== ZodParsedType.symbol) {
|
|
2611
|
-
const ctx = this._getOrReturnCtx(
|
|
2616
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2612
2617
|
addIssueToContext(ctx, {
|
|
2613
2618
|
code: ZodIssueCode.invalid_type,
|
|
2614
2619
|
expected: ZodParsedType.symbol,
|
|
@@ -2616,7 +2621,7 @@ var ZodSymbol = class extends ZodType {
|
|
|
2616
2621
|
});
|
|
2617
2622
|
return INVALID;
|
|
2618
2623
|
}
|
|
2619
|
-
return OK(
|
|
2624
|
+
return OK(input.data);
|
|
2620
2625
|
}
|
|
2621
2626
|
};
|
|
2622
2627
|
ZodSymbol.create = (params) => {
|
|
@@ -2626,10 +2631,10 @@ ZodSymbol.create = (params) => {
|
|
|
2626
2631
|
});
|
|
2627
2632
|
};
|
|
2628
2633
|
var ZodUndefined = class extends ZodType {
|
|
2629
|
-
_parse(
|
|
2630
|
-
const parsedType = this._getType(
|
|
2634
|
+
_parse(input) {
|
|
2635
|
+
const parsedType = this._getType(input);
|
|
2631
2636
|
if (parsedType !== ZodParsedType.undefined) {
|
|
2632
|
-
const ctx = this._getOrReturnCtx(
|
|
2637
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2633
2638
|
addIssueToContext(ctx, {
|
|
2634
2639
|
code: ZodIssueCode.invalid_type,
|
|
2635
2640
|
expected: ZodParsedType.undefined,
|
|
@@ -2637,7 +2642,7 @@ var ZodUndefined = class extends ZodType {
|
|
|
2637
2642
|
});
|
|
2638
2643
|
return INVALID;
|
|
2639
2644
|
}
|
|
2640
|
-
return OK(
|
|
2645
|
+
return OK(input.data);
|
|
2641
2646
|
}
|
|
2642
2647
|
};
|
|
2643
2648
|
ZodUndefined.create = (params) => {
|
|
@@ -2647,10 +2652,10 @@ ZodUndefined.create = (params) => {
|
|
|
2647
2652
|
});
|
|
2648
2653
|
};
|
|
2649
2654
|
var ZodNull = class extends ZodType {
|
|
2650
|
-
_parse(
|
|
2651
|
-
const parsedType = this._getType(
|
|
2655
|
+
_parse(input) {
|
|
2656
|
+
const parsedType = this._getType(input);
|
|
2652
2657
|
if (parsedType !== ZodParsedType.null) {
|
|
2653
|
-
const ctx = this._getOrReturnCtx(
|
|
2658
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2654
2659
|
addIssueToContext(ctx, {
|
|
2655
2660
|
code: ZodIssueCode.invalid_type,
|
|
2656
2661
|
expected: ZodParsedType.null,
|
|
@@ -2658,7 +2663,7 @@ var ZodNull = class extends ZodType {
|
|
|
2658
2663
|
});
|
|
2659
2664
|
return INVALID;
|
|
2660
2665
|
}
|
|
2661
|
-
return OK(
|
|
2666
|
+
return OK(input.data);
|
|
2662
2667
|
}
|
|
2663
2668
|
};
|
|
2664
2669
|
ZodNull.create = (params) => {
|
|
@@ -2672,8 +2677,8 @@ var ZodAny = class extends ZodType {
|
|
|
2672
2677
|
super(...arguments);
|
|
2673
2678
|
this._any = true;
|
|
2674
2679
|
}
|
|
2675
|
-
_parse(
|
|
2676
|
-
return OK(
|
|
2680
|
+
_parse(input) {
|
|
2681
|
+
return OK(input.data);
|
|
2677
2682
|
}
|
|
2678
2683
|
};
|
|
2679
2684
|
ZodAny.create = (params) => {
|
|
@@ -2687,8 +2692,8 @@ var ZodUnknown = class extends ZodType {
|
|
|
2687
2692
|
super(...arguments);
|
|
2688
2693
|
this._unknown = true;
|
|
2689
2694
|
}
|
|
2690
|
-
_parse(
|
|
2691
|
-
return OK(
|
|
2695
|
+
_parse(input) {
|
|
2696
|
+
return OK(input.data);
|
|
2692
2697
|
}
|
|
2693
2698
|
};
|
|
2694
2699
|
ZodUnknown.create = (params) => {
|
|
@@ -2698,8 +2703,8 @@ ZodUnknown.create = (params) => {
|
|
|
2698
2703
|
});
|
|
2699
2704
|
};
|
|
2700
2705
|
var ZodNever = class extends ZodType {
|
|
2701
|
-
_parse(
|
|
2702
|
-
const ctx = this._getOrReturnCtx(
|
|
2706
|
+
_parse(input) {
|
|
2707
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2703
2708
|
addIssueToContext(ctx, {
|
|
2704
2709
|
code: ZodIssueCode.invalid_type,
|
|
2705
2710
|
expected: ZodParsedType.never,
|
|
@@ -2715,10 +2720,10 @@ ZodNever.create = (params) => {
|
|
|
2715
2720
|
});
|
|
2716
2721
|
};
|
|
2717
2722
|
var ZodVoid = class extends ZodType {
|
|
2718
|
-
_parse(
|
|
2719
|
-
const parsedType = this._getType(
|
|
2723
|
+
_parse(input) {
|
|
2724
|
+
const parsedType = this._getType(input);
|
|
2720
2725
|
if (parsedType !== ZodParsedType.undefined) {
|
|
2721
|
-
const ctx = this._getOrReturnCtx(
|
|
2726
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2722
2727
|
addIssueToContext(ctx, {
|
|
2723
2728
|
code: ZodIssueCode.invalid_type,
|
|
2724
2729
|
expected: ZodParsedType.void,
|
|
@@ -2726,7 +2731,7 @@ var ZodVoid = class extends ZodType {
|
|
|
2726
2731
|
});
|
|
2727
2732
|
return INVALID;
|
|
2728
2733
|
}
|
|
2729
|
-
return OK(
|
|
2734
|
+
return OK(input.data);
|
|
2730
2735
|
}
|
|
2731
2736
|
};
|
|
2732
2737
|
ZodVoid.create = (params) => {
|
|
@@ -2736,8 +2741,8 @@ ZodVoid.create = (params) => {
|
|
|
2736
2741
|
});
|
|
2737
2742
|
};
|
|
2738
2743
|
var ZodArray = class _ZodArray extends ZodType {
|
|
2739
|
-
_parse(
|
|
2740
|
-
const { ctx, status } = this._processInputParams(
|
|
2744
|
+
_parse(input) {
|
|
2745
|
+
const { ctx, status } = this._processInputParams(input);
|
|
2741
2746
|
const def = this._def;
|
|
2742
2747
|
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2743
2748
|
addIssueToContext(ctx, {
|
|
@@ -2877,10 +2882,10 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
2877
2882
|
this._cached = { shape, keys };
|
|
2878
2883
|
return this._cached;
|
|
2879
2884
|
}
|
|
2880
|
-
_parse(
|
|
2881
|
-
const parsedType = this._getType(
|
|
2885
|
+
_parse(input) {
|
|
2886
|
+
const parsedType = this._getType(input);
|
|
2882
2887
|
if (parsedType !== ZodParsedType.object) {
|
|
2883
|
-
const ctx2 = this._getOrReturnCtx(
|
|
2888
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2884
2889
|
addIssueToContext(ctx2, {
|
|
2885
2890
|
code: ZodIssueCode.invalid_type,
|
|
2886
2891
|
expected: ZodParsedType.object,
|
|
@@ -2888,7 +2893,7 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
2888
2893
|
});
|
|
2889
2894
|
return INVALID;
|
|
2890
2895
|
}
|
|
2891
|
-
const { status, ctx } = this._processInputParams(
|
|
2896
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2892
2897
|
const { shape, keys: shapeKeys } = this._getCached();
|
|
2893
2898
|
const extraKeys = [];
|
|
2894
2899
|
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
@@ -3201,8 +3206,8 @@ ZodObject.lazycreate = (shape, params) => {
|
|
|
3201
3206
|
});
|
|
3202
3207
|
};
|
|
3203
3208
|
var ZodUnion = class extends ZodType {
|
|
3204
|
-
_parse(
|
|
3205
|
-
const { ctx } = this._processInputParams(
|
|
3209
|
+
_parse(input) {
|
|
3210
|
+
const { ctx } = this._processInputParams(input);
|
|
3206
3211
|
const options = this._def.options;
|
|
3207
3212
|
function handleResults(results) {
|
|
3208
3213
|
for (const result of results) {
|
|
@@ -3323,8 +3328,8 @@ var getDiscriminator = (type) => {
|
|
|
3323
3328
|
}
|
|
3324
3329
|
};
|
|
3325
3330
|
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
3326
|
-
_parse(
|
|
3327
|
-
const { ctx } = this._processInputParams(
|
|
3331
|
+
_parse(input) {
|
|
3332
|
+
const { ctx } = this._processInputParams(input);
|
|
3328
3333
|
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3329
3334
|
addIssueToContext(ctx, {
|
|
3330
3335
|
code: ZodIssueCode.invalid_type,
|
|
@@ -3437,8 +3442,8 @@ function mergeValues(a, b) {
|
|
|
3437
3442
|
}
|
|
3438
3443
|
}
|
|
3439
3444
|
var ZodIntersection = class extends ZodType {
|
|
3440
|
-
_parse(
|
|
3441
|
-
const { status, ctx } = this._processInputParams(
|
|
3445
|
+
_parse(input) {
|
|
3446
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3442
3447
|
const handleParsed = (parsedLeft, parsedRight) => {
|
|
3443
3448
|
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
3444
3449
|
return INVALID;
|
|
@@ -3490,8 +3495,8 @@ ZodIntersection.create = (left, right, params) => {
|
|
|
3490
3495
|
});
|
|
3491
3496
|
};
|
|
3492
3497
|
var ZodTuple = class _ZodTuple extends ZodType {
|
|
3493
|
-
_parse(
|
|
3494
|
-
const { status, ctx } = this._processInputParams(
|
|
3498
|
+
_parse(input) {
|
|
3499
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3495
3500
|
if (ctx.parsedType !== ZodParsedType.array) {
|
|
3496
3501
|
addIssueToContext(ctx, {
|
|
3497
3502
|
code: ZodIssueCode.invalid_type,
|
|
@@ -3563,8 +3568,8 @@ var ZodRecord = class _ZodRecord extends ZodType {
|
|
|
3563
3568
|
get valueSchema() {
|
|
3564
3569
|
return this._def.valueType;
|
|
3565
3570
|
}
|
|
3566
|
-
_parse(
|
|
3567
|
-
const { status, ctx } = this._processInputParams(
|
|
3571
|
+
_parse(input) {
|
|
3572
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3568
3573
|
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3569
3574
|
addIssueToContext(ctx, {
|
|
3570
3575
|
code: ZodIssueCode.invalid_type,
|
|
@@ -3616,8 +3621,8 @@ var ZodMap = class extends ZodType {
|
|
|
3616
3621
|
get valueSchema() {
|
|
3617
3622
|
return this._def.valueType;
|
|
3618
3623
|
}
|
|
3619
|
-
_parse(
|
|
3620
|
-
const { status, ctx } = this._processInputParams(
|
|
3624
|
+
_parse(input) {
|
|
3625
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3621
3626
|
if (ctx.parsedType !== ZodParsedType.map) {
|
|
3622
3627
|
addIssueToContext(ctx, {
|
|
3623
3628
|
code: ZodIssueCode.invalid_type,
|
|
@@ -3676,8 +3681,8 @@ ZodMap.create = (keyType, valueType, params) => {
|
|
|
3676
3681
|
});
|
|
3677
3682
|
};
|
|
3678
3683
|
var ZodSet = class _ZodSet extends ZodType {
|
|
3679
|
-
_parse(
|
|
3680
|
-
const { status, ctx } = this._processInputParams(
|
|
3684
|
+
_parse(input) {
|
|
3685
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3681
3686
|
if (ctx.parsedType !== ZodParsedType.set) {
|
|
3682
3687
|
addIssueToContext(ctx, {
|
|
3683
3688
|
code: ZodIssueCode.invalid_type,
|
|
@@ -3765,8 +3770,8 @@ var ZodFunction = class _ZodFunction extends ZodType {
|
|
|
3765
3770
|
super(...arguments);
|
|
3766
3771
|
this.validate = this.implement;
|
|
3767
3772
|
}
|
|
3768
|
-
_parse(
|
|
3769
|
-
const { ctx } = this._processInputParams(
|
|
3773
|
+
_parse(input) {
|
|
3774
|
+
const { ctx } = this._processInputParams(input);
|
|
3770
3775
|
if (ctx.parsedType !== ZodParsedType.function) {
|
|
3771
3776
|
addIssueToContext(ctx, {
|
|
3772
3777
|
code: ZodIssueCode.invalid_type,
|
|
@@ -3869,8 +3874,8 @@ var ZodLazy = class extends ZodType {
|
|
|
3869
3874
|
get schema() {
|
|
3870
3875
|
return this._def.getter();
|
|
3871
3876
|
}
|
|
3872
|
-
_parse(
|
|
3873
|
-
const { ctx } = this._processInputParams(
|
|
3877
|
+
_parse(input) {
|
|
3878
|
+
const { ctx } = this._processInputParams(input);
|
|
3874
3879
|
const lazySchema = this._def.getter();
|
|
3875
3880
|
return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
|
|
3876
3881
|
}
|
|
@@ -3883,9 +3888,9 @@ ZodLazy.create = (getter, params) => {
|
|
|
3883
3888
|
});
|
|
3884
3889
|
};
|
|
3885
3890
|
var ZodLiteral = class extends ZodType {
|
|
3886
|
-
_parse(
|
|
3887
|
-
if (
|
|
3888
|
-
const ctx = this._getOrReturnCtx(
|
|
3891
|
+
_parse(input) {
|
|
3892
|
+
if (input.data !== this._def.value) {
|
|
3893
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3889
3894
|
addIssueToContext(ctx, {
|
|
3890
3895
|
received: ctx.data,
|
|
3891
3896
|
code: ZodIssueCode.invalid_literal,
|
|
@@ -3893,7 +3898,7 @@ var ZodLiteral = class extends ZodType {
|
|
|
3893
3898
|
});
|
|
3894
3899
|
return INVALID;
|
|
3895
3900
|
}
|
|
3896
|
-
return { status: "valid", value:
|
|
3901
|
+
return { status: "valid", value: input.data };
|
|
3897
3902
|
}
|
|
3898
3903
|
get value() {
|
|
3899
3904
|
return this._def.value;
|
|
@@ -3914,9 +3919,9 @@ function createZodEnum(values, params) {
|
|
|
3914
3919
|
});
|
|
3915
3920
|
}
|
|
3916
3921
|
var ZodEnum = class _ZodEnum extends ZodType {
|
|
3917
|
-
_parse(
|
|
3918
|
-
if (typeof
|
|
3919
|
-
const ctx = this._getOrReturnCtx(
|
|
3922
|
+
_parse(input) {
|
|
3923
|
+
if (typeof input.data !== "string") {
|
|
3924
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3920
3925
|
const expectedValues = this._def.values;
|
|
3921
3926
|
addIssueToContext(ctx, {
|
|
3922
3927
|
expected: util.joinValues(expectedValues),
|
|
@@ -3928,8 +3933,8 @@ var ZodEnum = class _ZodEnum extends ZodType {
|
|
|
3928
3933
|
if (!this._cache) {
|
|
3929
3934
|
this._cache = new Set(this._def.values);
|
|
3930
3935
|
}
|
|
3931
|
-
if (!this._cache.has(
|
|
3932
|
-
const ctx = this._getOrReturnCtx(
|
|
3936
|
+
if (!this._cache.has(input.data)) {
|
|
3937
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3933
3938
|
const expectedValues = this._def.values;
|
|
3934
3939
|
addIssueToContext(ctx, {
|
|
3935
3940
|
received: ctx.data,
|
|
@@ -3938,7 +3943,7 @@ var ZodEnum = class _ZodEnum extends ZodType {
|
|
|
3938
3943
|
});
|
|
3939
3944
|
return INVALID;
|
|
3940
3945
|
}
|
|
3941
|
-
return OK(
|
|
3946
|
+
return OK(input.data);
|
|
3942
3947
|
}
|
|
3943
3948
|
get options() {
|
|
3944
3949
|
return this._def.values;
|
|
@@ -3979,9 +3984,9 @@ var ZodEnum = class _ZodEnum extends ZodType {
|
|
|
3979
3984
|
};
|
|
3980
3985
|
ZodEnum.create = createZodEnum;
|
|
3981
3986
|
var ZodNativeEnum = class extends ZodType {
|
|
3982
|
-
_parse(
|
|
3987
|
+
_parse(input) {
|
|
3983
3988
|
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
3984
|
-
const ctx = this._getOrReturnCtx(
|
|
3989
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3985
3990
|
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
3986
3991
|
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3987
3992
|
addIssueToContext(ctx, {
|
|
@@ -3994,7 +3999,7 @@ var ZodNativeEnum = class extends ZodType {
|
|
|
3994
3999
|
if (!this._cache) {
|
|
3995
4000
|
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
3996
4001
|
}
|
|
3997
|
-
if (!this._cache.has(
|
|
4002
|
+
if (!this._cache.has(input.data)) {
|
|
3998
4003
|
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3999
4004
|
addIssueToContext(ctx, {
|
|
4000
4005
|
received: ctx.data,
|
|
@@ -4003,7 +4008,7 @@ var ZodNativeEnum = class extends ZodType {
|
|
|
4003
4008
|
});
|
|
4004
4009
|
return INVALID;
|
|
4005
4010
|
}
|
|
4006
|
-
return OK(
|
|
4011
|
+
return OK(input.data);
|
|
4007
4012
|
}
|
|
4008
4013
|
get enum() {
|
|
4009
4014
|
return this._def.values;
|
|
@@ -4020,8 +4025,8 @@ var ZodPromise = class extends ZodType {
|
|
|
4020
4025
|
unwrap() {
|
|
4021
4026
|
return this._def.type;
|
|
4022
4027
|
}
|
|
4023
|
-
_parse(
|
|
4024
|
-
const { ctx } = this._processInputParams(
|
|
4028
|
+
_parse(input) {
|
|
4029
|
+
const { ctx } = this._processInputParams(input);
|
|
4025
4030
|
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
4026
4031
|
addIssueToContext(ctx, {
|
|
4027
4032
|
code: ZodIssueCode.invalid_type,
|
|
@@ -4053,8 +4058,8 @@ var ZodEffects = class extends ZodType {
|
|
|
4053
4058
|
sourceType() {
|
|
4054
4059
|
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
4055
4060
|
}
|
|
4056
|
-
_parse(
|
|
4057
|
-
const { status, ctx } = this._processInputParams(
|
|
4061
|
+
_parse(input) {
|
|
4062
|
+
const { status, ctx } = this._processInputParams(input);
|
|
4058
4063
|
const effect = this._def.effect || null;
|
|
4059
4064
|
const checkCtx = {
|
|
4060
4065
|
addIssue: (arg) => {
|
|
@@ -4186,12 +4191,12 @@ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
|
4186
4191
|
});
|
|
4187
4192
|
};
|
|
4188
4193
|
var ZodOptional = class extends ZodType {
|
|
4189
|
-
_parse(
|
|
4190
|
-
const parsedType = this._getType(
|
|
4194
|
+
_parse(input) {
|
|
4195
|
+
const parsedType = this._getType(input);
|
|
4191
4196
|
if (parsedType === ZodParsedType.undefined) {
|
|
4192
4197
|
return OK(void 0);
|
|
4193
4198
|
}
|
|
4194
|
-
return this._def.innerType._parse(
|
|
4199
|
+
return this._def.innerType._parse(input);
|
|
4195
4200
|
}
|
|
4196
4201
|
unwrap() {
|
|
4197
4202
|
return this._def.innerType;
|
|
@@ -4205,12 +4210,12 @@ ZodOptional.create = (type, params) => {
|
|
|
4205
4210
|
});
|
|
4206
4211
|
};
|
|
4207
4212
|
var ZodNullable = class extends ZodType {
|
|
4208
|
-
_parse(
|
|
4209
|
-
const parsedType = this._getType(
|
|
4213
|
+
_parse(input) {
|
|
4214
|
+
const parsedType = this._getType(input);
|
|
4210
4215
|
if (parsedType === ZodParsedType.null) {
|
|
4211
4216
|
return OK(null);
|
|
4212
4217
|
}
|
|
4213
|
-
return this._def.innerType._parse(
|
|
4218
|
+
return this._def.innerType._parse(input);
|
|
4214
4219
|
}
|
|
4215
4220
|
unwrap() {
|
|
4216
4221
|
return this._def.innerType;
|
|
@@ -4224,8 +4229,8 @@ ZodNullable.create = (type, params) => {
|
|
|
4224
4229
|
});
|
|
4225
4230
|
};
|
|
4226
4231
|
var ZodDefault = class extends ZodType {
|
|
4227
|
-
_parse(
|
|
4228
|
-
const { ctx } = this._processInputParams(
|
|
4232
|
+
_parse(input) {
|
|
4233
|
+
const { ctx } = this._processInputParams(input);
|
|
4229
4234
|
let data = ctx.data;
|
|
4230
4235
|
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
4231
4236
|
data = this._def.defaultValue();
|
|
@@ -4249,8 +4254,8 @@ ZodDefault.create = (type, params) => {
|
|
|
4249
4254
|
});
|
|
4250
4255
|
};
|
|
4251
4256
|
var ZodCatch = class extends ZodType {
|
|
4252
|
-
_parse(
|
|
4253
|
-
const { ctx } = this._processInputParams(
|
|
4257
|
+
_parse(input) {
|
|
4258
|
+
const { ctx } = this._processInputParams(input);
|
|
4254
4259
|
const newCtx = {
|
|
4255
4260
|
...ctx,
|
|
4256
4261
|
common: {
|
|
@@ -4302,10 +4307,10 @@ ZodCatch.create = (type, params) => {
|
|
|
4302
4307
|
});
|
|
4303
4308
|
};
|
|
4304
4309
|
var ZodNaN = class extends ZodType {
|
|
4305
|
-
_parse(
|
|
4306
|
-
const parsedType = this._getType(
|
|
4310
|
+
_parse(input) {
|
|
4311
|
+
const parsedType = this._getType(input);
|
|
4307
4312
|
if (parsedType !== ZodParsedType.nan) {
|
|
4308
|
-
const ctx = this._getOrReturnCtx(
|
|
4313
|
+
const ctx = this._getOrReturnCtx(input);
|
|
4309
4314
|
addIssueToContext(ctx, {
|
|
4310
4315
|
code: ZodIssueCode.invalid_type,
|
|
4311
4316
|
expected: ZodParsedType.nan,
|
|
@@ -4313,7 +4318,7 @@ var ZodNaN = class extends ZodType {
|
|
|
4313
4318
|
});
|
|
4314
4319
|
return INVALID;
|
|
4315
4320
|
}
|
|
4316
|
-
return { status: "valid", value:
|
|
4321
|
+
return { status: "valid", value: input.data };
|
|
4317
4322
|
}
|
|
4318
4323
|
};
|
|
4319
4324
|
ZodNaN.create = (params) => {
|
|
@@ -4324,8 +4329,8 @@ ZodNaN.create = (params) => {
|
|
|
4324
4329
|
};
|
|
4325
4330
|
var BRAND = /* @__PURE__ */ Symbol("zod_brand");
|
|
4326
4331
|
var ZodBranded = class extends ZodType {
|
|
4327
|
-
_parse(
|
|
4328
|
-
const { ctx } = this._processInputParams(
|
|
4332
|
+
_parse(input) {
|
|
4333
|
+
const { ctx } = this._processInputParams(input);
|
|
4329
4334
|
const data = ctx.data;
|
|
4330
4335
|
return this._def.type._parse({
|
|
4331
4336
|
data,
|
|
@@ -4338,8 +4343,8 @@ var ZodBranded = class extends ZodType {
|
|
|
4338
4343
|
}
|
|
4339
4344
|
};
|
|
4340
4345
|
var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
4341
|
-
_parse(
|
|
4342
|
-
const { status, ctx } = this._processInputParams(
|
|
4346
|
+
_parse(input) {
|
|
4347
|
+
const { status, ctx } = this._processInputParams(input);
|
|
4343
4348
|
if (ctx.common.async) {
|
|
4344
4349
|
const handleAsync = async () => {
|
|
4345
4350
|
const inResult = await this._def.in._parseAsync({
|
|
@@ -4393,8 +4398,8 @@ var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
|
4393
4398
|
}
|
|
4394
4399
|
};
|
|
4395
4400
|
var ZodReadonly = class extends ZodType {
|
|
4396
|
-
_parse(
|
|
4397
|
-
const result = this._def.innerType._parse(
|
|
4401
|
+
_parse(input) {
|
|
4402
|
+
const result = this._def.innerType._parse(input);
|
|
4398
4403
|
const freeze = (data) => {
|
|
4399
4404
|
if (isValid(data)) {
|
|
4400
4405
|
data.value = Object.freeze(data.value);
|
|
@@ -4415,9 +4420,9 @@ ZodReadonly.create = (type, params) => {
|
|
|
4415
4420
|
});
|
|
4416
4421
|
};
|
|
4417
4422
|
function cleanParams(params, data) {
|
|
4418
|
-
const
|
|
4419
|
-
const
|
|
4420
|
-
return
|
|
4423
|
+
const p3 = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
4424
|
+
const p22 = typeof p3 === "string" ? { message: p3 } : p3;
|
|
4425
|
+
return p22;
|
|
4421
4426
|
}
|
|
4422
4427
|
function custom(check, _params = {}, fatal) {
|
|
4423
4428
|
if (check)
|
|
@@ -4680,14 +4685,14 @@ var publishPayloadSchema = external_exports.object({
|
|
|
4680
4685
|
import { execSync } from "child_process";
|
|
4681
4686
|
import { existsSync as existsSync3 } from "fs";
|
|
4682
4687
|
import { join as join2 } from "path";
|
|
4683
|
-
import { homedir as
|
|
4688
|
+
import { homedir as homedir3 } from "os";
|
|
4684
4689
|
var isWindows = process.platform === "win32";
|
|
4685
4690
|
var KNOWN_PATHS = isWindows ? [] : [
|
|
4686
4691
|
"/usr/local/bin/npx",
|
|
4687
4692
|
"/opt/homebrew/bin/npx",
|
|
4688
|
-
join2(
|
|
4689
|
-
join2(
|
|
4690
|
-
join2(
|
|
4693
|
+
join2(homedir3(), ".nvm", "current", "bin", "npx"),
|
|
4694
|
+
join2(homedir3(), ".volta", "bin", "npx"),
|
|
4695
|
+
join2(homedir3(), ".bun", "bin", "npx")
|
|
4691
4696
|
];
|
|
4692
4697
|
function resolveNpxPath() {
|
|
4693
4698
|
const whichCmd = isWindows ? "where npx.cmd" : "which npx";
|
|
@@ -4723,14 +4728,14 @@ function resolveNpxPath() {
|
|
|
4723
4728
|
} catch {
|
|
4724
4729
|
}
|
|
4725
4730
|
}
|
|
4726
|
-
for (const
|
|
4727
|
-
if (existsSync3(
|
|
4728
|
-
return
|
|
4731
|
+
for (const p3 of KNOWN_PATHS) {
|
|
4732
|
+
if (existsSync3(p3))
|
|
4733
|
+
return p3;
|
|
4729
4734
|
}
|
|
4730
4735
|
throw new Error("Could not find npx. Ensure Node.js is installed and npx is in your PATH.");
|
|
4731
4736
|
}
|
|
4732
4737
|
function buildNodePath() {
|
|
4733
|
-
const home2 =
|
|
4738
|
+
const home2 = homedir3();
|
|
4734
4739
|
const dirs = [
|
|
4735
4740
|
"/usr/local/bin",
|
|
4736
4741
|
"/opt/homebrew/bin",
|
|
@@ -4853,7 +4858,7 @@ async function killDaemon() {
|
|
|
4853
4858
|
}
|
|
4854
4859
|
const pids = findPidsByPort(port);
|
|
4855
4860
|
if (pids.length > 0) {
|
|
4856
|
-
await Promise.all(pids.map((
|
|
4861
|
+
await Promise.all(pids.map((p3) => killPid(p3)));
|
|
4857
4862
|
}
|
|
4858
4863
|
try {
|
|
4859
4864
|
if (existsSync4(DAEMON_PID_FILE))
|
|
@@ -5186,10 +5191,10 @@ async function fetchLatestVersion(packageName = PACKAGE_NAME) {
|
|
|
5186
5191
|
// ../shared/dist/hooks/claude-code.js
|
|
5187
5192
|
import { existsSync as existsSync6, readFileSync as readFileSync3, writeFileSync as writeFileSync3, mkdirSync as mkdirSync3, unlinkSync as unlinkSync3, chmodSync } from "fs";
|
|
5188
5193
|
import { join as join3 } from "path";
|
|
5189
|
-
import { homedir as
|
|
5194
|
+
import { homedir as homedir4 } from "os";
|
|
5190
5195
|
var STOP_GUARD_PATH = join3(USEAI_HOOKS_DIR, "stop-guard.js");
|
|
5191
5196
|
var PROMPT_GUARD_PATH = join3(USEAI_HOOKS_DIR, "prompt-guard.js");
|
|
5192
|
-
var CLAUDE_SETTINGS_PATH = join3(
|
|
5197
|
+
var CLAUDE_SETTINGS_PATH = join3(homedir4(), ".claude", "settings.json");
|
|
5193
5198
|
var STOP_GUARD_SCRIPT = `#!/usr/bin/env node
|
|
5194
5199
|
'use strict';
|
|
5195
5200
|
const { readFileSync } = require('node:fs');
|
|
@@ -5248,7 +5253,7 @@ function readSettings() {
|
|
|
5248
5253
|
}
|
|
5249
5254
|
}
|
|
5250
5255
|
function writeSettings(settings) {
|
|
5251
|
-
mkdirSync3(join3(
|
|
5256
|
+
mkdirSync3(join3(homedir4(), ".claude"), { recursive: true });
|
|
5252
5257
|
writeFileSync3(CLAUDE_SETTINGS_PATH, JSON.stringify(settings, null, 2) + "\n");
|
|
5253
5258
|
}
|
|
5254
5259
|
function installClaudeCodeHooks() {
|
|
@@ -5556,7 +5561,7 @@ function buildInstructionsText(frameworkId, opts) {
|
|
|
5556
5561
|
import { execSync as execSync4 } from "child_process";
|
|
5557
5562
|
import { existsSync as existsSync7, readFileSync as readFileSync4, writeFileSync as writeFileSync4, mkdirSync as mkdirSync4, unlinkSync as unlinkSync4 } from "fs";
|
|
5558
5563
|
import { dirname as dirname2, join as join4 } from "path";
|
|
5559
|
-
import { homedir as
|
|
5564
|
+
import { homedir as homedir5 } from "os";
|
|
5560
5565
|
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
|
|
5561
5566
|
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
5562
5567
|
var USEAI_INSTRUCTIONS_TEXT = [
|
|
@@ -5571,7 +5576,7 @@ var MCP_ENTRY = {
|
|
|
5571
5576
|
};
|
|
5572
5577
|
var MCP_HTTP_URL = DAEMON_MCP_URL;
|
|
5573
5578
|
var MCP_HTTP_ENTRY = { type: "http", url: MCP_HTTP_URL };
|
|
5574
|
-
var home =
|
|
5579
|
+
var home = homedir5();
|
|
5575
5580
|
function installStandardHttp(configPath) {
|
|
5576
5581
|
const config = readJsonFile(configPath);
|
|
5577
5582
|
const servers = config["mcpServers"] ?? {};
|
|
@@ -5967,7 +5972,7 @@ var AI_TOOLS = [
|
|
|
5967
5972
|
name: "Claude Code",
|
|
5968
5973
|
configFormat: "standard",
|
|
5969
5974
|
configPath: join4(home, ".claude.json"),
|
|
5970
|
-
detect: () =>
|
|
5975
|
+
detect: () => existsSync7(join4(home, ".claude.json")) || hasBinary("claude"),
|
|
5971
5976
|
instructions: { method: "append", path: join4(home, ".claude", "CLAUDE.md") },
|
|
5972
5977
|
supportsUrl: true
|
|
5973
5978
|
}),
|
|
@@ -6038,7 +6043,7 @@ var AI_TOOLS = [
|
|
|
6038
6043
|
name: "Copilot CLI",
|
|
6039
6044
|
configFormat: "standard",
|
|
6040
6045
|
configPath: join4(home, ".copilot", "mcp-config.json"),
|
|
6041
|
-
detect: () =>
|
|
6046
|
+
detect: () => existsSync7(join4(home, ".copilot")) || hasBinary("copilot"),
|
|
6042
6047
|
manualHint: "No global instructions file \u2014 add UseAI instructions to your project-level agent rules.",
|
|
6043
6048
|
supportsUrl: true
|
|
6044
6049
|
}),
|
|
@@ -6121,7 +6126,7 @@ var AI_TOOLS = [
|
|
|
6121
6126
|
name: "Amazon Q CLI",
|
|
6122
6127
|
configFormat: "standard",
|
|
6123
6128
|
configPath: join4(home, ".aws", "amazonq", "mcp.json"),
|
|
6124
|
-
detect: () =>
|
|
6129
|
+
detect: () => existsSync7(join4(home, ".aws", "amazonq")) || hasBinary("q"),
|
|
6125
6130
|
manualHint: "Create .amazonq/rules/useai.md in your project root with the instructions below."
|
|
6126
6131
|
}),
|
|
6127
6132
|
createTool({
|
|
@@ -6137,7 +6142,7 @@ var AI_TOOLS = [
|
|
|
6137
6142
|
name: "Codex",
|
|
6138
6143
|
configFormat: "toml",
|
|
6139
6144
|
configPath: join4(home, ".codex", "config.toml"),
|
|
6140
|
-
detect: () =>
|
|
6145
|
+
detect: () => existsSync7(join4(home, ".codex")) || existsSync7("/Applications/Codex.app") || hasBinary("codex"),
|
|
6141
6146
|
instructions: { method: "append", path: join4(home, ".codex", "AGENTS.md") },
|
|
6142
6147
|
supportsUrl: true
|
|
6143
6148
|
}),
|
|
@@ -6155,7 +6160,7 @@ var AI_TOOLS = [
|
|
|
6155
6160
|
name: "OpenCode",
|
|
6156
6161
|
configFormat: "standard",
|
|
6157
6162
|
configPath: join4(home, ".config", "opencode", "opencode.json"),
|
|
6158
|
-
detect: () =>
|
|
6163
|
+
detect: () => existsSync7(join4(home, ".config", "opencode")) || hasBinary("opencode"),
|
|
6159
6164
|
instructions: { method: "append", path: join4(home, ".config", "opencode", "AGENTS.md") },
|
|
6160
6165
|
supportsUrl: true
|
|
6161
6166
|
}),
|
|
@@ -6164,7 +6169,7 @@ var AI_TOOLS = [
|
|
|
6164
6169
|
name: "Crush",
|
|
6165
6170
|
configFormat: "crush",
|
|
6166
6171
|
configPath: join4(home, ".config", "crush", "crush.json"),
|
|
6167
|
-
detect: () =>
|
|
6172
|
+
detect: () => existsSync7(join4(home, ".config", "crush")) || hasBinary("crush"),
|
|
6168
6173
|
manualHint: "No global instructions file \u2014 add UseAI instructions to your project-level .crush.json.",
|
|
6169
6174
|
supportsUrl: true
|
|
6170
6175
|
}),
|
|
@@ -6228,7 +6233,7 @@ var configCommand = new Command4("config").description("View or update settings"
|
|
|
6228
6233
|
console.log(error(`Unknown framework: ${opts.framework}. Valid: ${validIds.join(", ")}`));
|
|
6229
6234
|
} else {
|
|
6230
6235
|
updateConfig({ evaluation_framework: opts.framework });
|
|
6231
|
-
console.log(success(`Evaluation framework set to ${
|
|
6236
|
+
console.log(success(`Evaluation framework set to ${pc5.bold(opts.framework)}.`));
|
|
6232
6237
|
const results = reinjectInstructions(opts.framework);
|
|
6233
6238
|
if (results.length > 0) {
|
|
6234
6239
|
for (const r of results) {
|
|
@@ -6243,14 +6248,14 @@ var configCommand = new Command4("config").description("View or update settings"
|
|
|
6243
6248
|
console.log(header("Current Settings"));
|
|
6244
6249
|
console.log(
|
|
6245
6250
|
table([
|
|
6246
|
-
["Milestone tracking", config.capture.milestones ?
|
|
6247
|
-
["Prompt capture", config.capture.prompt ?
|
|
6251
|
+
["Milestone tracking", config.capture.milestones ? pc5.green("on") : pc5.red("off")],
|
|
6252
|
+
["Prompt capture", config.capture.prompt ? pc5.green("on") : pc5.red("off")],
|
|
6248
6253
|
["Eval reasons", config.capture.evaluation_reasons],
|
|
6249
|
-
["Cloud sync", config.sync.enabled ?
|
|
6250
|
-
["Eval framework",
|
|
6254
|
+
["Cloud sync", config.sync.enabled ? pc5.green("on") : pc5.red("off")],
|
|
6255
|
+
["Eval framework", pc5.cyan(config.evaluation_framework ?? "space")],
|
|
6251
6256
|
["Sync interval", `${config.sync.interval_hours}h`],
|
|
6252
|
-
["Last sync", config.last_sync_at ??
|
|
6253
|
-
["Logged in", config.auth ?
|
|
6257
|
+
["Last sync", config.last_sync_at ?? pc5.dim("never")],
|
|
6258
|
+
["Logged in", config.auth ? pc5.green(config.auth.user.email) : pc5.dim("no")]
|
|
6254
6259
|
])
|
|
6255
6260
|
);
|
|
6256
6261
|
console.log("");
|
|
@@ -6304,188 +6309,195 @@ var purgeCommand = new Command6("purge").description("Delete ALL local useai dat
|
|
|
6304
6309
|
|
|
6305
6310
|
// src/commands/setup.ts
|
|
6306
6311
|
import { Command as Command7 } from "commander";
|
|
6307
|
-
import
|
|
6308
|
-
import
|
|
6309
|
-
function shortenPath(p) {
|
|
6310
|
-
const home2 = process.env["HOME"] ?? "";
|
|
6311
|
-
return home2 && p.startsWith(home2) ? p.replace(home2, "~") : p;
|
|
6312
|
-
}
|
|
6312
|
+
import * as p from "@clack/prompts";
|
|
6313
|
+
import pc6 from "picocolors";
|
|
6313
6314
|
function showManualHints(installedTools) {
|
|
6314
6315
|
const hints = installedTools.map((t) => ({ name: t.name, hint: t.getManualHint() })).filter((h) => h.hint !== null);
|
|
6315
6316
|
if (hints.length === 0) return;
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
`)
|
|
6319
|
-
for (const { name, hint } of hints) {
|
|
6320
|
-
console.log(` ${chalk6.bold(name)}: ${hint}`);
|
|
6321
|
-
}
|
|
6322
|
-
console.log();
|
|
6323
|
-
for (const line of USEAI_INSTRUCTIONS_TEXT.split("\n")) {
|
|
6324
|
-
console.log(` ${line}`);
|
|
6325
|
-
}
|
|
6326
|
-
console.log();
|
|
6317
|
+
const lines = hints.map(({ name, hint }) => `${pc6.bold(name)}: ${hint}`);
|
|
6318
|
+
lines.push("", ...USEAI_INSTRUCTIONS_TEXT.split("\n"));
|
|
6319
|
+
p.note(lines.join("\n"), `Manual setup needed for ${hints.length} tool${hints.length === 1 ? "" : "s"}`);
|
|
6327
6320
|
}
|
|
6328
6321
|
function showStatus(tools) {
|
|
6329
|
-
console.log(header("AI Tool MCP Status"));
|
|
6330
6322
|
const detected = tools.filter((t) => t.detect());
|
|
6331
6323
|
if (detected.length === 0) {
|
|
6332
|
-
|
|
6333
|
-
console.log();
|
|
6324
|
+
p.log.warn("No supported AI tools detected on this system.");
|
|
6334
6325
|
return;
|
|
6335
6326
|
}
|
|
6336
|
-
const rows = [];
|
|
6337
6327
|
const nameWidth = Math.max(...detected.map((t) => t.name.length));
|
|
6338
|
-
const
|
|
6339
|
-
for (const tool of detected) {
|
|
6328
|
+
const lines = detected.map((tool) => {
|
|
6340
6329
|
const name = tool.name.padEnd(nameWidth);
|
|
6330
|
+
const path = pc6.dim(shortenPath(tool.getConfigPath()));
|
|
6341
6331
|
if (tool.isConfigured()) {
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6332
|
+
return `${name} ${pc6.green("\u2713 Configured")} ${path}`;
|
|
6333
|
+
}
|
|
6334
|
+
return `${name} ${pc6.yellow("\u2717 Not set up")} ${path}`;
|
|
6335
|
+
});
|
|
6336
|
+
p.note(lines.join("\n"), "AI Tool MCP Status");
|
|
6337
|
+
}
|
|
6338
|
+
function configureToolAndCollect(tool, useDaemon) {
|
|
6339
|
+
try {
|
|
6340
|
+
if (useDaemon && tool.supportsUrl) {
|
|
6341
|
+
tool.installHttp();
|
|
6342
|
+
return { tool, ok: true, mode: "http" };
|
|
6343
|
+
}
|
|
6344
|
+
tool.install();
|
|
6345
|
+
return { tool, ok: true, mode: "stdio" };
|
|
6346
|
+
} catch (e) {
|
|
6347
|
+
return { tool, ok: false, mode: "stdio", error: e.message };
|
|
6348
|
+
}
|
|
6349
|
+
}
|
|
6350
|
+
function showGroupedResults(results) {
|
|
6351
|
+
const httpOk = results.filter((r) => r.ok && r.mode === "http");
|
|
6352
|
+
const stdioOk = results.filter((r) => r.ok && r.mode === "stdio");
|
|
6353
|
+
const failed = results.filter((r) => !r.ok);
|
|
6354
|
+
if (httpOk.length > 0) {
|
|
6355
|
+
p.log.success(`HTTP (daemon): ${httpOk.map((r) => r.tool.name).join(", ")}`);
|
|
6356
|
+
}
|
|
6357
|
+
if (stdioOk.length > 0) {
|
|
6358
|
+
p.log.success(`stdio: ${stdioOk.map((r) => r.tool.name).join(", ")}`);
|
|
6359
|
+
}
|
|
6360
|
+
if (failed.length > 0) {
|
|
6361
|
+
for (const r of failed) {
|
|
6362
|
+
p.log.error(`${r.tool.name} \u2014 ${r.error}`);
|
|
6349
6363
|
}
|
|
6350
6364
|
}
|
|
6351
|
-
console.log(rows.join("\n"));
|
|
6352
|
-
console.log();
|
|
6353
6365
|
}
|
|
6354
6366
|
async function daemonInstallFlow(tools, explicit) {
|
|
6355
|
-
|
|
6367
|
+
p.intro(pc6.bgCyan(pc6.black(" useai ")));
|
|
6368
|
+
const s = p.spinner();
|
|
6369
|
+
s.start("Starting UseAI daemon...");
|
|
6356
6370
|
const daemonOk = await ensureDaemon();
|
|
6357
6371
|
let useDaemon = true;
|
|
6358
6372
|
if (daemonOk) {
|
|
6359
|
-
|
|
6373
|
+
s.stop(`Daemon running on port ${DAEMON_PORT}`);
|
|
6360
6374
|
} else {
|
|
6361
6375
|
useDaemon = false;
|
|
6362
|
-
|
|
6363
|
-
|
|
6376
|
+
s.stop("Could not start daemon \u2014 falling back to stdio config");
|
|
6377
|
+
p.note(
|
|
6378
|
+
[
|
|
6379
|
+
"Check if the port is in use:",
|
|
6380
|
+
` lsof -i :${DAEMON_PORT}`,
|
|
6381
|
+
"",
|
|
6382
|
+
"Run in foreground to debug:",
|
|
6383
|
+
` npx @devness/useai daemon --port ${DAEMON_PORT}`,
|
|
6384
|
+
"",
|
|
6385
|
+
"For containers/CI, use stdio mode:",
|
|
6386
|
+
" npx @devness/useai mcp --stdio"
|
|
6387
|
+
].join("\n"),
|
|
6388
|
+
"Troubleshooting"
|
|
6389
|
+
);
|
|
6364
6390
|
}
|
|
6365
6391
|
if (useDaemon) {
|
|
6366
6392
|
const platform = detectPlatform();
|
|
6367
6393
|
if (platform !== "unsupported") {
|
|
6368
6394
|
try {
|
|
6369
6395
|
installAutostart();
|
|
6370
|
-
|
|
6396
|
+
p.log.success(`Auto-start service installed (${platform})`);
|
|
6371
6397
|
} catch {
|
|
6372
|
-
|
|
6398
|
+
p.log.warn("Could not install auto-start service");
|
|
6373
6399
|
}
|
|
6374
6400
|
}
|
|
6375
6401
|
}
|
|
6376
6402
|
const targetTools = explicit ? tools : tools.filter((t) => t.detect());
|
|
6377
6403
|
if (targetTools.length === 0) {
|
|
6378
|
-
|
|
6404
|
+
p.log.error("No AI tools detected on this machine.");
|
|
6405
|
+
p.outro("Setup complete.");
|
|
6379
6406
|
return;
|
|
6380
6407
|
}
|
|
6381
|
-
|
|
6382
|
-
console.log();
|
|
6408
|
+
const results = [];
|
|
6383
6409
|
for (const tool of targetTools) {
|
|
6384
|
-
|
|
6385
|
-
if (useDaemon && tool.supportsUrl) {
|
|
6386
|
-
tool.installHttp();
|
|
6387
|
-
console.log(success(`\u2713 ${tool.name.padEnd(18)} \u2192 ${chalk6.dim("HTTP (daemon)")}`));
|
|
6388
|
-
} else if (useDaemon && !tool.supportsUrl) {
|
|
6389
|
-
tool.install();
|
|
6390
|
-
console.log(success(`\u2713 ${tool.name.padEnd(18)} \u2192 ${chalk6.dim("stdio (no URL support)")}`));
|
|
6391
|
-
} else {
|
|
6392
|
-
tool.install();
|
|
6393
|
-
console.log(success(`\u2713 ${tool.name.padEnd(18)} \u2192 ${chalk6.dim("stdio")}`));
|
|
6394
|
-
}
|
|
6395
|
-
configuredCount++;
|
|
6396
|
-
} catch (e) {
|
|
6397
|
-
console.log(error(`\u2717 ${tool.name.padEnd(18)} \u2014 ${e.message}`));
|
|
6398
|
-
}
|
|
6410
|
+
results.push(configureToolAndCollect(tool, useDaemon));
|
|
6399
6411
|
}
|
|
6412
|
+
showGroupedResults(results);
|
|
6400
6413
|
try {
|
|
6401
6414
|
const hooksInstalled = installClaudeCodeHooks();
|
|
6402
6415
|
if (hooksInstalled) {
|
|
6403
|
-
|
|
6416
|
+
p.log.success("Claude Code hooks installed (UserPromptSubmit + Stop + SessionEnd)");
|
|
6404
6417
|
}
|
|
6405
6418
|
} catch {
|
|
6406
|
-
|
|
6419
|
+
p.log.warn("Could not install Claude Code hooks");
|
|
6407
6420
|
}
|
|
6408
6421
|
showManualHints(targetTools);
|
|
6422
|
+
const configuredCount = results.filter((r) => r.ok).length;
|
|
6409
6423
|
const mode = useDaemon ? "daemon mode" : "stdio mode";
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
`);
|
|
6424
|
+
const dashboard = useDaemon ? `
|
|
6425
|
+
Dashboard \u2192 ${pc6.cyan(`http://127.0.0.1:${DAEMON_PORT}/dashboard`)}` : "";
|
|
6426
|
+
p.outro(`UseAI configured in ${pc6.bold(String(configuredCount))} tool${configuredCount === 1 ? "" : "s"} (${mode}).${dashboard}`);
|
|
6413
6427
|
}
|
|
6414
6428
|
async function stdioInstallFlow(tools, autoYes, explicit) {
|
|
6429
|
+
p.intro(pc6.bgCyan(pc6.black(" useai ")));
|
|
6415
6430
|
if (explicit) {
|
|
6416
|
-
|
|
6431
|
+
const results2 = [];
|
|
6417
6432
|
for (const tool of tools) {
|
|
6418
|
-
|
|
6419
|
-
const wasConfigured = tool.isConfigured();
|
|
6420
|
-
tool.install();
|
|
6421
|
-
if (wasConfigured) {
|
|
6422
|
-
console.log(success(`\u2713 ${tool.name.padEnd(18)} ${chalk6.dim("(updated)")}`));
|
|
6423
|
-
} else {
|
|
6424
|
-
console.log(success(`\u2713 ${tool.name.padEnd(18)} \u2192 ${chalk6.dim(shortenPath(tool.getConfigPath()))}`));
|
|
6425
|
-
}
|
|
6426
|
-
} catch (err) {
|
|
6427
|
-
console.log(error(`\u2717 ${tool.name.padEnd(18)} \u2014 ${err.message}`));
|
|
6428
|
-
}
|
|
6433
|
+
results2.push(configureToolAndCollect(tool, false));
|
|
6429
6434
|
}
|
|
6435
|
+
showGroupedResults(results2);
|
|
6430
6436
|
showManualHints(tools);
|
|
6431
|
-
|
|
6437
|
+
p.outro("Setup complete.");
|
|
6432
6438
|
return;
|
|
6433
6439
|
}
|
|
6434
|
-
|
|
6440
|
+
const s = p.spinner();
|
|
6441
|
+
s.start("Scanning for AI tools...");
|
|
6435
6442
|
const detected = tools.filter((t) => t.detect());
|
|
6443
|
+
s.stop(`Found ${detected.length} AI tool${detected.length === 1 ? "" : "s"}`);
|
|
6436
6444
|
if (detected.length === 0) {
|
|
6437
|
-
|
|
6445
|
+
p.log.error("No AI tools detected on this machine.");
|
|
6446
|
+
p.outro("Setup complete.");
|
|
6438
6447
|
return;
|
|
6439
6448
|
}
|
|
6440
6449
|
const alreadyConfigured = detected.filter((t) => t.isConfigured());
|
|
6441
6450
|
const unconfigured = detected.filter((t) => !t.isConfigured());
|
|
6442
|
-
|
|
6443
|
-
`)
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
}
|
|
6447
|
-
for (const tool of unconfigured) {
|
|
6448
|
-
console.log(chalk6.dim(` \u2610 ${tool.name}`));
|
|
6449
|
-
}
|
|
6450
|
-
console.log();
|
|
6451
|
+
const toolLines = [
|
|
6452
|
+
...alreadyConfigured.map((t) => `${pc6.green("\u2713")} ${t.name} ${pc6.dim("(already configured)")}`),
|
|
6453
|
+
...unconfigured.map((t) => `${pc6.dim("\u25CB")} ${t.name}`)
|
|
6454
|
+
];
|
|
6455
|
+
p.note(toolLines.join("\n"), `${detected.length} AI tool${detected.length === 1 ? "" : "s"} detected`);
|
|
6451
6456
|
if (unconfigured.length === 0) {
|
|
6452
|
-
|
|
6457
|
+
p.log.success("All detected tools are already configured.");
|
|
6458
|
+
p.outro("Nothing to do.");
|
|
6453
6459
|
return;
|
|
6454
6460
|
}
|
|
6455
6461
|
let toInstall;
|
|
6456
6462
|
if (autoYes) {
|
|
6457
6463
|
toInstall = unconfigured;
|
|
6458
6464
|
} else {
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6466
|
-
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6465
|
+
const selected = await p.multiselect({
|
|
6466
|
+
message: `Select tools to configure ${pc6.dim("(space to toggle)")}`,
|
|
6467
|
+
options: unconfigured.map((t) => ({
|
|
6468
|
+
value: t.id,
|
|
6469
|
+
label: t.name,
|
|
6470
|
+
hint: shortenPath(t.getConfigPath())
|
|
6471
|
+
})),
|
|
6472
|
+
initialValues: unconfigured.map((t) => t.id),
|
|
6473
|
+
required: true
|
|
6474
|
+
});
|
|
6475
|
+
if (p.isCancel(selected)) {
|
|
6476
|
+
p.cancel("Setup cancelled.");
|
|
6471
6477
|
return;
|
|
6472
6478
|
}
|
|
6473
6479
|
toInstall = unconfigured.filter((t) => selected.includes(t.id));
|
|
6474
6480
|
}
|
|
6475
6481
|
if (toInstall.length === 0) {
|
|
6476
|
-
|
|
6482
|
+
p.log.info("No tools selected.");
|
|
6483
|
+
p.outro("Setup complete.");
|
|
6477
6484
|
return;
|
|
6478
6485
|
}
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
`)
|
|
6486
|
+
p.note(
|
|
6487
|
+
[
|
|
6488
|
+
`Tools: ${toInstall.map((t) => t.name).join(", ")}`,
|
|
6489
|
+
`Mode: stdio`
|
|
6490
|
+
].join("\n"),
|
|
6491
|
+
"Installation Summary"
|
|
6492
|
+
);
|
|
6493
|
+
const shouldProceed = await p.confirm({ message: "Proceed with installation?" });
|
|
6494
|
+
if (p.isCancel(shouldProceed) || !shouldProceed) {
|
|
6495
|
+
p.cancel("Setup cancelled.");
|
|
6496
|
+
return;
|
|
6497
|
+
}
|
|
6498
|
+
const results = [];
|
|
6482
6499
|
for (const tool of toInstall) {
|
|
6483
|
-
|
|
6484
|
-
tool.install();
|
|
6485
|
-
console.log(success(`\u2713 ${tool.name.padEnd(18)} \u2192 ${chalk6.dim(shortenPath(tool.getConfigPath()))}`));
|
|
6486
|
-
} catch (err) {
|
|
6487
|
-
console.log(error(`\u2717 ${tool.name.padEnd(18)} \u2014 ${err.message}`));
|
|
6488
|
-
}
|
|
6500
|
+
results.push(configureToolAndCollect(tool, false));
|
|
6489
6501
|
}
|
|
6490
6502
|
for (const tool of alreadyConfigured) {
|
|
6491
6503
|
try {
|
|
@@ -6493,12 +6505,13 @@ async function stdioInstallFlow(tools, autoYes, explicit) {
|
|
|
6493
6505
|
} catch {
|
|
6494
6506
|
}
|
|
6495
6507
|
}
|
|
6508
|
+
showGroupedResults(results);
|
|
6496
6509
|
showManualHints([...toInstall, ...alreadyConfigured]);
|
|
6497
|
-
|
|
6498
|
-
|
|
6499
|
-
`);
|
|
6510
|
+
const configuredCount = results.filter((r) => r.ok).length;
|
|
6511
|
+
p.outro(`UseAI configured in ${pc6.bold(String(configuredCount))} tool${configuredCount === 1 ? "" : "s"} (stdio mode).`);
|
|
6500
6512
|
}
|
|
6501
6513
|
async function fullRemoveFlow(tools, autoYes, explicit) {
|
|
6514
|
+
p.intro(pc6.bgCyan(pc6.black(" useai ")));
|
|
6502
6515
|
if (explicit) {
|
|
6503
6516
|
const toRemove = tools.filter((t) => {
|
|
6504
6517
|
try {
|
|
@@ -6515,17 +6528,14 @@ async function fullRemoveFlow(tools, autoYes, explicit) {
|
|
|
6515
6528
|
}
|
|
6516
6529
|
});
|
|
6517
6530
|
for (const tool of notConfigured) {
|
|
6518
|
-
|
|
6531
|
+
p.log.info(`${tool.name} is not configured \u2014 skipping.`);
|
|
6519
6532
|
}
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
} catch (err) {
|
|
6527
|
-
console.log(error(`\u2717 ${tool.name} \u2014 ${err.message}`));
|
|
6528
|
-
}
|
|
6533
|
+
for (const tool of toRemove) {
|
|
6534
|
+
try {
|
|
6535
|
+
tool.remove();
|
|
6536
|
+
p.log.success(`Removed from ${tool.name}`);
|
|
6537
|
+
} catch (err) {
|
|
6538
|
+
p.log.error(`${tool.name} \u2014 ${err.message}`);
|
|
6529
6539
|
}
|
|
6530
6540
|
}
|
|
6531
6541
|
} else {
|
|
@@ -6537,43 +6547,37 @@ async function fullRemoveFlow(tools, autoYes, explicit) {
|
|
|
6537
6547
|
}
|
|
6538
6548
|
});
|
|
6539
6549
|
if (configured.length === 0) {
|
|
6540
|
-
|
|
6550
|
+
p.log.info("UseAI is not configured in any AI tools.");
|
|
6541
6551
|
} else {
|
|
6542
|
-
console.log(`
|
|
6543
|
-
Found UseAI configured in ${chalk6.bold(String(configured.length))} tool${configured.length === 1 ? "" : "s"}:
|
|
6544
|
-
`);
|
|
6545
6552
|
let toRemove;
|
|
6546
6553
|
if (autoYes) {
|
|
6547
6554
|
toRemove = configured;
|
|
6548
6555
|
} else {
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6556
|
+
const selected = await p.multiselect({
|
|
6557
|
+
message: `Select tools to remove UseAI from ${pc6.dim("(space to toggle)")}`,
|
|
6558
|
+
options: configured.map((t) => ({
|
|
6559
|
+
value: t.id,
|
|
6560
|
+
label: t.name,
|
|
6561
|
+
hint: shortenPath(t.getConfigPath())
|
|
6562
|
+
})),
|
|
6563
|
+
initialValues: configured.map((t) => t.id),
|
|
6564
|
+
required: true
|
|
6565
|
+
});
|
|
6566
|
+
if (p.isCancel(selected)) {
|
|
6567
|
+
p.cancel("Removal cancelled.");
|
|
6561
6568
|
return;
|
|
6562
6569
|
}
|
|
6563
6570
|
toRemove = configured.filter((t) => selected.includes(t.id));
|
|
6564
6571
|
}
|
|
6565
6572
|
if (toRemove.length === 0) {
|
|
6566
|
-
|
|
6573
|
+
p.log.info("No tools selected.");
|
|
6567
6574
|
} else {
|
|
6568
|
-
console.log(`
|
|
6569
|
-
Removing from ${toRemove.length} tool${toRemove.length === 1 ? "" : "s"}...
|
|
6570
|
-
`);
|
|
6571
6575
|
for (const tool of toRemove) {
|
|
6572
6576
|
try {
|
|
6573
6577
|
tool.remove();
|
|
6574
|
-
|
|
6578
|
+
p.log.success(`Removed from ${tool.name}`);
|
|
6575
6579
|
} catch (err) {
|
|
6576
|
-
|
|
6580
|
+
p.log.error(`${tool.name} \u2014 ${err.message}`);
|
|
6577
6581
|
}
|
|
6578
6582
|
}
|
|
6579
6583
|
}
|
|
@@ -6589,27 +6593,26 @@ async function fullRemoveFlow(tools, autoYes, explicit) {
|
|
|
6589
6593
|
if (!anyRemaining) {
|
|
6590
6594
|
try {
|
|
6591
6595
|
removeClaudeCodeHooks();
|
|
6592
|
-
|
|
6596
|
+
p.log.success("Claude Code hooks removed");
|
|
6593
6597
|
} catch {
|
|
6594
6598
|
}
|
|
6595
|
-
console.log();
|
|
6596
6599
|
try {
|
|
6597
6600
|
await killDaemon();
|
|
6598
|
-
|
|
6601
|
+
p.log.success("Daemon stopped");
|
|
6599
6602
|
} catch {
|
|
6600
|
-
|
|
6603
|
+
p.log.info("Daemon was not running");
|
|
6601
6604
|
}
|
|
6602
6605
|
if (isAutostartInstalled()) {
|
|
6603
6606
|
try {
|
|
6604
6607
|
removeAutostart();
|
|
6605
|
-
|
|
6608
|
+
p.log.success("Auto-start service removed");
|
|
6606
6609
|
} catch {
|
|
6607
|
-
|
|
6610
|
+
p.log.error("Failed to remove auto-start service");
|
|
6608
6611
|
}
|
|
6609
6612
|
}
|
|
6610
|
-
|
|
6613
|
+
p.outro("UseAI fully removed.");
|
|
6611
6614
|
} else {
|
|
6612
|
-
|
|
6615
|
+
p.outro("Other tools still configured \u2014 daemon and hooks kept running.");
|
|
6613
6616
|
}
|
|
6614
6617
|
}
|
|
6615
6618
|
var mcpCommand = new Command7("mcp").description("Configure UseAI MCP server in your AI tools").argument("[tools...]", "Specific tool names (e.g. codex cursor vscode)").option("--stdio", "Use stdio config (legacy mode for containers/CI)").option("--remove", "Remove UseAI from configured tools, stop daemon, remove auto-start").option("--status", "Show configuration status without modifying").option("-y, --yes", "Skip confirmation, auto-select all detected tools").action(async (toolNames, opts) => {
|
|
@@ -6618,8 +6621,8 @@ var mcpCommand = new Command7("mcp").description("Configure UseAI MCP server in
|
|
|
6618
6621
|
if (explicit) {
|
|
6619
6622
|
const { matched, unmatched } = resolveTools(toolNames);
|
|
6620
6623
|
if (unmatched.length > 0) {
|
|
6621
|
-
|
|
6622
|
-
|
|
6624
|
+
p.log.error(`Unknown tool${unmatched.length === 1 ? "" : "s"}: ${unmatched.join(", ")}`);
|
|
6625
|
+
p.log.info(`Available: ${AI_TOOLS.map((t) => t.id).join(", ")}`);
|
|
6623
6626
|
return;
|
|
6624
6627
|
}
|
|
6625
6628
|
tools = matched;
|
|
@@ -6638,14 +6641,14 @@ var mcpCommand = new Command7("mcp").description("Configure UseAI MCP server in
|
|
|
6638
6641
|
// src/commands/daemon.ts
|
|
6639
6642
|
import { Command as Command8 } from "commander";
|
|
6640
6643
|
import { spawn as spawn2 } from "child_process";
|
|
6641
|
-
import
|
|
6644
|
+
import pc7 from "picocolors";
|
|
6642
6645
|
var startCommand = new Command8("start").description("Start the UseAI daemon").option("-p, --port <port>", "Port to listen on", String(DAEMON_PORT)).option("--foreground", "Run in foreground (don't daemonize)").action(async (opts) => {
|
|
6643
6646
|
const port = parseInt(opts.port, 10);
|
|
6644
6647
|
const pid = readPidFile();
|
|
6645
6648
|
if (pid && isProcessRunning(pid.pid)) {
|
|
6646
6649
|
const health = await fetchDaemonHealth(pid.port);
|
|
6647
6650
|
if (health) {
|
|
6648
|
-
console.log(
|
|
6651
|
+
console.log(pc7.yellow(` Daemon already running (PID ${pid.pid}, port ${pid.port})`));
|
|
6649
6652
|
return;
|
|
6650
6653
|
}
|
|
6651
6654
|
}
|
|
@@ -6660,55 +6663,55 @@ var startCommand = new Command8("start").description("Start the UseAI daemon").o
|
|
|
6660
6663
|
});
|
|
6661
6664
|
return;
|
|
6662
6665
|
}
|
|
6663
|
-
console.log(
|
|
6666
|
+
console.log(pc7.dim(" Starting daemon..."));
|
|
6664
6667
|
const started = await ensureDaemon();
|
|
6665
6668
|
if (started) {
|
|
6666
6669
|
const newPid = readPidFile();
|
|
6667
|
-
console.log(
|
|
6670
|
+
console.log(pc7.green(` \u2713 Daemon started (PID ${newPid?.pid ?? "unknown"}, port ${port})`));
|
|
6668
6671
|
} else {
|
|
6669
|
-
console.log(
|
|
6670
|
-
console.log(
|
|
6672
|
+
console.log(pc7.red(` \u2717 Daemon failed to start within 8 seconds`));
|
|
6673
|
+
console.log(pc7.dim(` Try: useai daemon start --foreground`));
|
|
6671
6674
|
}
|
|
6672
6675
|
});
|
|
6673
6676
|
var stopCommand = new Command8("stop").description("Stop the UseAI daemon").option("-p, --port <port>", "Port to stop daemon on", String(DAEMON_PORT)).action(async (opts) => {
|
|
6674
6677
|
const port = parseInt(opts.port, 10);
|
|
6675
6678
|
const pid = readPidFile();
|
|
6676
6679
|
if (pid && isProcessRunning(pid.pid)) {
|
|
6677
|
-
console.log(
|
|
6680
|
+
console.log(pc7.dim(` Stopping daemon (PID ${pid.pid})...`));
|
|
6678
6681
|
await killDaemon();
|
|
6679
|
-
console.log(
|
|
6682
|
+
console.log(pc7.green(` \u2713 Daemon stopped`));
|
|
6680
6683
|
return;
|
|
6681
6684
|
}
|
|
6682
6685
|
const pids = findPidsByPort(port);
|
|
6683
6686
|
if (pids.length > 0) {
|
|
6684
|
-
console.log(
|
|
6687
|
+
console.log(pc7.dim(` Stopping daemon on port ${port} (PIDs: ${pids.join(", ")})...`));
|
|
6685
6688
|
await killDaemon();
|
|
6686
|
-
console.log(
|
|
6689
|
+
console.log(pc7.green(` \u2713 Daemon stopped`));
|
|
6687
6690
|
return;
|
|
6688
6691
|
}
|
|
6689
|
-
console.log(
|
|
6692
|
+
console.log(pc7.dim(" Daemon is not running"));
|
|
6690
6693
|
});
|
|
6691
6694
|
var statusCommand2 = new Command8("status").description("Show daemon status").action(async () => {
|
|
6692
6695
|
const pid = readPidFile();
|
|
6693
6696
|
if (!pid) {
|
|
6694
|
-
console.log(
|
|
6697
|
+
console.log(pc7.dim(" Daemon is not running"));
|
|
6695
6698
|
return;
|
|
6696
6699
|
}
|
|
6697
6700
|
if (!isProcessRunning(pid.pid)) {
|
|
6698
|
-
console.log(
|
|
6701
|
+
console.log(pc7.dim(" Daemon is not running (stale PID file)"));
|
|
6699
6702
|
return;
|
|
6700
6703
|
}
|
|
6701
6704
|
const health = await fetchDaemonHealth(pid.port);
|
|
6702
6705
|
if (!health) {
|
|
6703
|
-
console.log(
|
|
6706
|
+
console.log(pc7.yellow(` Daemon process exists (PID ${pid.pid}) but health check failed`));
|
|
6704
6707
|
return;
|
|
6705
6708
|
}
|
|
6706
6709
|
const uptime = health["uptime_seconds"];
|
|
6707
6710
|
const platform = detectPlatform();
|
|
6708
|
-
const autostartStatus = isAutostartInstalled() ?
|
|
6709
|
-
console.log(
|
|
6710
|
-
console.log(
|
|
6711
|
-
console.log(` Status: ${
|
|
6711
|
+
const autostartStatus = isAutostartInstalled() ? pc7.green("installed") + pc7.dim(` (${platform})`) : pc7.dim("not installed");
|
|
6712
|
+
console.log(pc7.bold(pc7.cyan("\n UseAI Daemon")));
|
|
6713
|
+
console.log(pc7.bold(pc7.cyan(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")));
|
|
6714
|
+
console.log(` Status: ${pc7.green("running")}`);
|
|
6712
6715
|
console.log(` PID: ${pid.pid}`);
|
|
6713
6716
|
console.log(` Port: ${pid.port}`);
|
|
6714
6717
|
console.log(` Version: ${health["version"]}`);
|
|
@@ -6720,48 +6723,48 @@ var statusCommand2 = new Command8("status").description("Show daemon status").ac
|
|
|
6720
6723
|
var autostartInstallCommand = new Command8("install").description("Install auto-start service (survives reboots)").action(() => {
|
|
6721
6724
|
const platform = detectPlatform();
|
|
6722
6725
|
if (platform === "unsupported") {
|
|
6723
|
-
console.log(
|
|
6726
|
+
console.log(pc7.red(` \u2717 Auto-start is not supported on ${process.platform}`));
|
|
6724
6727
|
return;
|
|
6725
6728
|
}
|
|
6726
6729
|
try {
|
|
6727
6730
|
installAutostart();
|
|
6728
|
-
console.log(
|
|
6731
|
+
console.log(pc7.green(` \u2713 Auto-start installed (${platform})`));
|
|
6729
6732
|
} catch (e) {
|
|
6730
|
-
console.log(
|
|
6733
|
+
console.log(pc7.red(` \u2717 Failed to install auto-start: ${e.message}`));
|
|
6731
6734
|
}
|
|
6732
6735
|
});
|
|
6733
6736
|
var autostartRemoveCommand = new Command8("remove").description("Remove auto-start service").action(() => {
|
|
6734
6737
|
try {
|
|
6735
6738
|
removeAutostart();
|
|
6736
|
-
console.log(
|
|
6739
|
+
console.log(pc7.green(` \u2713 Auto-start removed`));
|
|
6737
6740
|
} catch (e) {
|
|
6738
|
-
console.log(
|
|
6741
|
+
console.log(pc7.red(` \u2717 Failed to remove auto-start: ${e.message}`));
|
|
6739
6742
|
}
|
|
6740
6743
|
});
|
|
6741
6744
|
var autostartStatusCommand = new Command8("status").description("Check auto-start status").action(() => {
|
|
6742
6745
|
const platform = detectPlatform();
|
|
6743
6746
|
const installed = isAutostartInstalled();
|
|
6744
6747
|
if (installed) {
|
|
6745
|
-
console.log(
|
|
6748
|
+
console.log(pc7.green(` \u2713 Auto-start is installed (${platform})`));
|
|
6746
6749
|
} else {
|
|
6747
|
-
console.log(
|
|
6750
|
+
console.log(pc7.dim(` Auto-start is not installed`));
|
|
6748
6751
|
}
|
|
6749
6752
|
});
|
|
6750
6753
|
var autostartRecoverCommand = new Command8("recover").description("Recover auto-start from disabled/failed state (after crash loops)").action(() => {
|
|
6751
6754
|
const platform = detectPlatform();
|
|
6752
6755
|
if (platform === "unsupported") {
|
|
6753
|
-
console.log(
|
|
6756
|
+
console.log(pc7.red(` \u2717 Auto-start is not supported on ${process.platform}`));
|
|
6754
6757
|
return;
|
|
6755
6758
|
}
|
|
6756
6759
|
if (!isAutostartInstalled()) {
|
|
6757
|
-
console.log(
|
|
6760
|
+
console.log(pc7.yellow(" Auto-start is not installed. Run: useai daemon autostart install"));
|
|
6758
6761
|
return;
|
|
6759
6762
|
}
|
|
6760
6763
|
const result = recoverAutostart();
|
|
6761
6764
|
if (result.recovered) {
|
|
6762
|
-
console.log(
|
|
6765
|
+
console.log(pc7.green(` \u2713 ${result.message}`));
|
|
6763
6766
|
} else {
|
|
6764
|
-
console.log(
|
|
6767
|
+
console.log(pc7.yellow(` ${result.message}`));
|
|
6765
6768
|
}
|
|
6766
6769
|
});
|
|
6767
6770
|
var autostartCommand = new Command8("autostart").description("Manage auto-start service").addCommand(autostartInstallCommand).addCommand(autostartRemoveCommand).addCommand(autostartStatusCommand).addCommand(autostartRecoverCommand);
|
|
@@ -6770,26 +6773,26 @@ var daemonCommand = new Command8("daemon").description("Manage the UseAI HTTP da
|
|
|
6770
6773
|
// src/commands/serve.ts
|
|
6771
6774
|
import { Command as Command9 } from "commander";
|
|
6772
6775
|
import { exec } from "child_process";
|
|
6773
|
-
import
|
|
6776
|
+
import pc8 from "picocolors";
|
|
6774
6777
|
var serveCommand = new Command9("serve").description("Open the local UseAI dashboard").option("--open", "Open the dashboard in your default browser").action(async (opts) => {
|
|
6775
6778
|
const url = `http://127.0.0.1:${DAEMON_PORT}/dashboard`;
|
|
6776
|
-
console.log(
|
|
6779
|
+
console.log(pc8.dim(" Ensuring daemon is running..."));
|
|
6777
6780
|
const started = await ensureDaemon();
|
|
6778
6781
|
if (!started) {
|
|
6779
|
-
console.log(
|
|
6782
|
+
console.log(pc8.red(" Failed to start daemon. Try: useai daemon start --foreground"));
|
|
6780
6783
|
process.exit(1);
|
|
6781
6784
|
}
|
|
6782
|
-
console.log(
|
|
6785
|
+
console.log(pc8.green(` Dashboard running at ${pc8.bold(url)}`));
|
|
6783
6786
|
if (opts.open) {
|
|
6784
6787
|
const cmd = process.platform === "darwin" ? "open" : "xdg-open";
|
|
6785
6788
|
exec(`${cmd} ${url}`, (err) => {
|
|
6786
6789
|
if (err) {
|
|
6787
|
-
console.log(
|
|
6788
|
-
console.log(
|
|
6790
|
+
console.log(pc8.yellow(` Could not open browser: ${err.message}`));
|
|
6791
|
+
console.log(pc8.dim(` Open manually: ${url}`));
|
|
6789
6792
|
}
|
|
6790
6793
|
});
|
|
6791
6794
|
}
|
|
6792
|
-
console.log(
|
|
6795
|
+
console.log(pc8.dim(" Press Ctrl+C to exit"));
|
|
6793
6796
|
const keepAlive = setInterval(() => {
|
|
6794
6797
|
}, 6e4);
|
|
6795
6798
|
const shutdown = () => {
|
|
@@ -6802,8 +6805,8 @@ var serveCommand = new Command9("serve").description("Open the local UseAI dashb
|
|
|
6802
6805
|
|
|
6803
6806
|
// src/commands/login.ts
|
|
6804
6807
|
import { Command as Command10 } from "commander";
|
|
6805
|
-
import
|
|
6806
|
-
import
|
|
6808
|
+
import * as p2 from "@clack/prompts";
|
|
6809
|
+
import pc9 from "picocolors";
|
|
6807
6810
|
var API_URL = process.env.USEAI_API_URL || "https://api.useai.dev";
|
|
6808
6811
|
async function apiCall(endpoint, body) {
|
|
6809
6812
|
const res = await fetch(`${API_URL}${endpoint}`, {
|
|
@@ -6821,47 +6824,58 @@ var loginCommand = new Command10("login").description("Login to useai.dev").acti
|
|
|
6821
6824
|
try {
|
|
6822
6825
|
const config = getConfig();
|
|
6823
6826
|
if (config.auth?.token) {
|
|
6824
|
-
console.log(
|
|
6825
|
-
console.log(
|
|
6827
|
+
console.log(pc9.dim(` Already logged in as ${pc9.bold(config.auth.user.email)}`));
|
|
6828
|
+
console.log(pc9.dim(" Run `useai logout` to switch accounts."));
|
|
6826
6829
|
return;
|
|
6827
6830
|
}
|
|
6828
|
-
const
|
|
6831
|
+
const emailResult = await p2.text({
|
|
6829
6832
|
message: "Email:",
|
|
6830
|
-
validate: (v) => v.includes("@")
|
|
6833
|
+
validate: (v) => !v || !v.includes("@") ? "Please enter a valid email" : void 0
|
|
6831
6834
|
});
|
|
6832
|
-
|
|
6835
|
+
if (p2.isCancel(emailResult)) {
|
|
6836
|
+
console.log(pc9.dim("\n Cancelled."));
|
|
6837
|
+
return;
|
|
6838
|
+
}
|
|
6839
|
+
const email = emailResult;
|
|
6840
|
+
console.log(pc9.dim(" Sending verification code..."));
|
|
6833
6841
|
try {
|
|
6834
6842
|
await apiCall("/api/auth/send-otp", { email });
|
|
6835
6843
|
} catch (err) {
|
|
6836
6844
|
if (err.message.includes("rate") || err.message.includes("Too many")) {
|
|
6837
|
-
console.log(
|
|
6845
|
+
console.log(pc9.red(" Too many requests. Please wait a minute and try again."));
|
|
6838
6846
|
return;
|
|
6839
6847
|
}
|
|
6840
6848
|
throw err;
|
|
6841
6849
|
}
|
|
6842
|
-
console.log(
|
|
6850
|
+
console.log(pc9.green(" \u2713 Code sent to your email"));
|
|
6843
6851
|
console.log("");
|
|
6844
6852
|
let attempts = 0;
|
|
6845
6853
|
const maxAttempts = 3;
|
|
6846
6854
|
let success2 = false;
|
|
6847
6855
|
while (attempts < maxAttempts && !success2) {
|
|
6848
|
-
const
|
|
6856
|
+
const codeResult = await p2.text({
|
|
6849
6857
|
message: 'Enter 6-digit code (or "resend"):',
|
|
6850
6858
|
validate: (v) => {
|
|
6851
|
-
if (v
|
|
6852
|
-
|
|
6859
|
+
if (!v) return "Code is required";
|
|
6860
|
+
if (v.toLowerCase() === "resend") return void 0;
|
|
6861
|
+
return /^\d{6}$/.test(v) ? void 0 : 'Code must be 6 digits (or type "resend")';
|
|
6853
6862
|
}
|
|
6854
6863
|
});
|
|
6864
|
+
if (p2.isCancel(codeResult)) {
|
|
6865
|
+
console.log(pc9.dim("\n Cancelled."));
|
|
6866
|
+
return;
|
|
6867
|
+
}
|
|
6868
|
+
const code = codeResult;
|
|
6855
6869
|
if (code.toLowerCase() === "resend") {
|
|
6856
|
-
console.log(
|
|
6870
|
+
console.log(pc9.dim(" Resending code..."));
|
|
6857
6871
|
try {
|
|
6858
6872
|
await apiCall("/api/auth/send-otp", { email });
|
|
6859
|
-
console.log(
|
|
6873
|
+
console.log(pc9.green(" \u2713 New code sent"));
|
|
6860
6874
|
console.log("");
|
|
6861
6875
|
continue;
|
|
6862
6876
|
} catch (err) {
|
|
6863
6877
|
if (err.message.includes("rate") || err.message.includes("Too many")) {
|
|
6864
|
-
console.log(
|
|
6878
|
+
console.log(pc9.yellow(" Please wait before requesting a new code."));
|
|
6865
6879
|
continue;
|
|
6866
6880
|
}
|
|
6867
6881
|
throw err;
|
|
@@ -6881,80 +6895,80 @@ var loginCommand = new Command10("login").description("Login to useai.dev").acti
|
|
|
6881
6895
|
}
|
|
6882
6896
|
});
|
|
6883
6897
|
console.log("");
|
|
6884
|
-
console.log(
|
|
6898
|
+
console.log(pc9.green(` \u2713 Logged in as ${pc9.bold(result.user.email)}`));
|
|
6885
6899
|
if (result.user.username) {
|
|
6886
|
-
console.log(
|
|
6900
|
+
console.log(pc9.dim(` username: ${result.user.username}`));
|
|
6887
6901
|
}
|
|
6888
6902
|
console.log("");
|
|
6889
|
-
console.log(
|
|
6903
|
+
console.log(pc9.dim(" Your sessions and milestones will sync to useai.dev"));
|
|
6890
6904
|
success2 = true;
|
|
6891
6905
|
}
|
|
6892
6906
|
} catch (err) {
|
|
6893
6907
|
attempts++;
|
|
6894
6908
|
if (err.message.includes("expired") || err.message.includes("No valid OTP")) {
|
|
6895
|
-
console.log(
|
|
6909
|
+
console.log(pc9.red(" Code expired. Sending a new one..."));
|
|
6896
6910
|
await apiCall("/api/auth/send-otp", { email });
|
|
6897
|
-
console.log(
|
|
6911
|
+
console.log(pc9.green(" \u2713 New code sent"));
|
|
6898
6912
|
attempts = 0;
|
|
6899
6913
|
continue;
|
|
6900
6914
|
}
|
|
6901
6915
|
if (err.message.includes("Too many attempts")) {
|
|
6902
|
-
console.log(
|
|
6916
|
+
console.log(pc9.red(" Too many attempts. Sending a new code..."));
|
|
6903
6917
|
await apiCall("/api/auth/send-otp", { email });
|
|
6904
|
-
console.log(
|
|
6918
|
+
console.log(pc9.green(" \u2713 New code sent"));
|
|
6905
6919
|
attempts = 0;
|
|
6906
6920
|
continue;
|
|
6907
6921
|
}
|
|
6908
6922
|
const remaining = maxAttempts - attempts;
|
|
6909
6923
|
if (remaining > 0) {
|
|
6910
|
-
console.log(
|
|
6924
|
+
console.log(pc9.red(` Invalid code. ${remaining} attempt(s) remaining.`));
|
|
6911
6925
|
} else {
|
|
6912
|
-
console.log(
|
|
6926
|
+
console.log(pc9.red(" Too many invalid attempts. Please try again later."));
|
|
6913
6927
|
return;
|
|
6914
6928
|
}
|
|
6915
6929
|
}
|
|
6916
6930
|
}
|
|
6917
6931
|
if (!success2) {
|
|
6918
|
-
console.log(
|
|
6932
|
+
console.log(pc9.red(" Login failed. Please try again."));
|
|
6919
6933
|
}
|
|
6920
6934
|
} catch (err) {
|
|
6921
6935
|
if (err.name === "ExitPromptError" || err.message?.includes("force closed")) {
|
|
6922
6936
|
console.log("");
|
|
6923
|
-
console.log(
|
|
6937
|
+
console.log(pc9.dim(" Cancelled."));
|
|
6924
6938
|
return;
|
|
6925
6939
|
}
|
|
6926
|
-
console.log(
|
|
6940
|
+
console.log(pc9.red(` Login failed: ${err.message}`));
|
|
6927
6941
|
}
|
|
6928
6942
|
});
|
|
6929
6943
|
var logoutCommand = new Command10("logout").description("Logout from useai.dev").action(() => {
|
|
6930
6944
|
const config = getConfig();
|
|
6931
6945
|
if (!config.auth) {
|
|
6932
|
-
console.log(
|
|
6946
|
+
console.log(pc9.dim(" Not logged in."));
|
|
6933
6947
|
return;
|
|
6934
6948
|
}
|
|
6935
6949
|
const email = config.auth.user.email;
|
|
6936
6950
|
updateConfig({ auth: void 0 });
|
|
6937
|
-
console.log(
|
|
6951
|
+
console.log(pc9.green(` \u2713 Logged out from ${email}`));
|
|
6938
6952
|
});
|
|
6939
6953
|
|
|
6940
6954
|
// src/commands/update.ts
|
|
6941
6955
|
import { Command as Command11 } from "commander";
|
|
6942
|
-
import
|
|
6956
|
+
import pc10 from "picocolors";
|
|
6943
6957
|
var updateCommand = new Command11("update").description("Update UseAI to the latest version (daemon + MCP configs)").action(async () => {
|
|
6944
|
-
console.log(
|
|
6958
|
+
console.log(pc10.dim(" Checking for updates..."));
|
|
6945
6959
|
const latest = await fetchLatestVersion();
|
|
6946
6960
|
if (!latest) {
|
|
6947
|
-
console.log(
|
|
6961
|
+
console.log(pc10.red(" \u2717 Could not reach npm registry"));
|
|
6948
6962
|
return;
|
|
6949
6963
|
}
|
|
6950
6964
|
const health = await fetchDaemonHealth();
|
|
6951
6965
|
const currentVersion = health?.["version"] ?? VERSION;
|
|
6952
6966
|
if (currentVersion === latest) {
|
|
6953
|
-
console.log(
|
|
6967
|
+
console.log(pc10.green(` \u2713 Already up to date (v${latest})`));
|
|
6954
6968
|
return;
|
|
6955
6969
|
}
|
|
6956
|
-
console.log(` ${
|
|
6957
|
-
console.log(` ${
|
|
6970
|
+
console.log(` ${pc10.dim("Current:")} v${currentVersion}`);
|
|
6971
|
+
console.log(` ${pc10.dim("Latest:")} v${latest}`);
|
|
6958
6972
|
console.log();
|
|
6959
6973
|
const configuredTools = AI_TOOLS.filter((t) => {
|
|
6960
6974
|
try {
|
|
@@ -6964,7 +6978,7 @@ var updateCommand = new Command11("update").description("Update UseAI to the lat
|
|
|
6964
6978
|
}
|
|
6965
6979
|
});
|
|
6966
6980
|
if (configuredTools.length > 0) {
|
|
6967
|
-
console.log(
|
|
6981
|
+
console.log(pc10.dim(" Removing MCP configs from configured tools..."));
|
|
6968
6982
|
for (const tool of configuredTools) {
|
|
6969
6983
|
try {
|
|
6970
6984
|
tool.remove();
|
|
@@ -6975,20 +6989,20 @@ var updateCommand = new Command11("update").description("Update UseAI to the lat
|
|
|
6975
6989
|
}
|
|
6976
6990
|
console.log();
|
|
6977
6991
|
}
|
|
6978
|
-
console.log(
|
|
6992
|
+
console.log(pc10.dim(" Stopping current daemon..."));
|
|
6979
6993
|
await killDaemon();
|
|
6980
|
-
console.log(
|
|
6994
|
+
console.log(pc10.dim(" Starting updated daemon..."));
|
|
6981
6995
|
const daemonOk = await ensureDaemon();
|
|
6982
6996
|
if (!daemonOk) {
|
|
6983
|
-
console.log(
|
|
6984
|
-
console.log(
|
|
6985
|
-
console.log(
|
|
6997
|
+
console.log(pc10.red(" \u2717 Failed to start updated daemon"));
|
|
6998
|
+
console.log(pc10.dim(" Try running in foreground to debug:"));
|
|
6999
|
+
console.log(pc10.dim(` npx -y --prefer-online @devness/useai@latest daemon --port ${DAEMON_PORT}`));
|
|
6986
7000
|
if (configuredTools.length > 0) {
|
|
6987
|
-
console.log(
|
|
7001
|
+
console.log(pc10.dim("\n Reinstalling MCP configs (stdio fallback)..."));
|
|
6988
7002
|
for (const tool of configuredTools) {
|
|
6989
7003
|
try {
|
|
6990
7004
|
tool.install();
|
|
6991
|
-
console.log(success(` \u2713 ${tool.name} \u2192 ${
|
|
7005
|
+
console.log(success(` \u2713 ${tool.name} \u2192 ${pc10.dim("stdio")}`));
|
|
6992
7006
|
} catch {
|
|
6993
7007
|
console.log(error(` \u2717 ${tool.name}`));
|
|
6994
7008
|
}
|
|
@@ -6998,18 +7012,18 @@ var updateCommand = new Command11("update").description("Update UseAI to the lat
|
|
|
6998
7012
|
}
|
|
6999
7013
|
const newHealth = await fetchDaemonHealth();
|
|
7000
7014
|
const newVersion = newHealth?.["version"] ?? "unknown";
|
|
7001
|
-
console.log(
|
|
7015
|
+
console.log(pc10.green(`
|
|
7002
7016
|
\u2713 Daemon updated: v${currentVersion} \u2192 v${newVersion}`));
|
|
7003
7017
|
if (configuredTools.length > 0) {
|
|
7004
|
-
console.log(
|
|
7018
|
+
console.log(pc10.dim("\n Reinstalling MCP configs..."));
|
|
7005
7019
|
for (const tool of configuredTools) {
|
|
7006
7020
|
try {
|
|
7007
7021
|
if (tool.supportsUrl) {
|
|
7008
7022
|
tool.installHttp();
|
|
7009
|
-
console.log(success(` \u2713 ${tool.name} \u2192 ${
|
|
7023
|
+
console.log(success(` \u2713 ${tool.name} \u2192 ${pc10.dim("HTTP (daemon)")}`));
|
|
7010
7024
|
} else {
|
|
7011
7025
|
tool.install();
|
|
7012
|
-
console.log(success(` \u2713 ${tool.name} \u2192 ${
|
|
7026
|
+
console.log(success(` \u2713 ${tool.name} \u2192 ${pc10.dim("stdio")}`));
|
|
7013
7027
|
}
|
|
7014
7028
|
} catch {
|
|
7015
7029
|
console.log(error(` \u2717 ${tool.name}`));
|
|
@@ -7024,9 +7038,9 @@ var updateCommand = new Command11("update").description("Update UseAI to the lat
|
|
|
7024
7038
|
} catch {
|
|
7025
7039
|
}
|
|
7026
7040
|
console.log(`
|
|
7027
|
-
Done! UseAI updated to v${newVersion} in ${
|
|
7041
|
+
Done! UseAI updated to v${newVersion} in ${pc10.bold(String(configuredTools.length))} tool${configuredTools.length === 1 ? "" : "s"}.
|
|
7028
7042
|
`);
|
|
7029
|
-
console.log(
|
|
7043
|
+
console.log(pc10.dim(` Dashboard: http://127.0.0.1:${DAEMON_PORT}/dashboard`));
|
|
7030
7044
|
});
|
|
7031
7045
|
|
|
7032
7046
|
// src/index.ts
|