@pollinations/cli 0.1.30 → 0.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var init_package = __esm({
14
14
  "package.json"() {
15
15
  package_default = {
16
16
  name: "@pollinations/cli",
17
- version: "0.1.30",
17
+ version: "0.1.31",
18
18
  description: "The Pollinations CLI \u2014 for humans, AI agents, and everything in between",
19
19
  type: "module",
20
20
  bin: {
@@ -881,7 +881,8 @@ var earningsCommand = new Command4("earnings").description("Show developer earni
881
881
  import { Command as Command15 } from "commander";
882
882
 
883
883
  // src/commands/gen/audio.ts
884
- import { writeFileSync as writeFileSync2 } from "fs";
884
+ import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
885
+ import { dirname } from "path";
885
886
  import { Command as Command5 } from "commander";
886
887
 
887
888
  // src/lib/errors.ts
@@ -1092,6 +1093,7 @@ Examples:
1092
1093
  );
1093
1094
  throw new ExitSignal(1);
1094
1095
  }
1096
+ mkdirSync2(dirname(output), { recursive: true });
1095
1097
  if (isHuman) printInfo("Generating audio...");
1096
1098
  try {
1097
1099
  const alignmentPath = opts.timestamps ? `${output}.json` : void 0;
@@ -1235,6 +1237,7 @@ Chat session started (model: ${opts.model ?? "API default"})
1235
1237
  const hint = await budgetHint(res.status, errText);
1236
1238
  if (hint) {
1237
1239
  printError(hint);
1240
+ stopped = true;
1238
1241
  rl.close();
1239
1242
  process.exitCode = 1;
1240
1243
  return;
@@ -1291,11 +1294,14 @@ Chat session started (model: ${opts.model ?? "API default"})
1291
1294
  }
1292
1295
  };
1293
1296
  let closed = false;
1297
+ let stopped = false;
1298
+ let pending;
1294
1299
  rl.prompt();
1295
- rl.on("line", async (line) => {
1300
+ const handleLine = async (line) => {
1301
+ if (stopped) return;
1296
1302
  const input = line.trim();
1297
1303
  if (!input) {
1298
- rl.prompt();
1304
+ if (!closed) rl.prompt();
1299
1305
  return;
1300
1306
  }
1301
1307
  if (input === "/exit" || input === "/quit") {
@@ -1308,6 +1314,7 @@ Session ended. ${totalTokens} tokens used.
1308
1314
  )
1309
1315
  );
1310
1316
  }
1317
+ stopped = true;
1311
1318
  rl.close();
1312
1319
  return;
1313
1320
  }
@@ -1322,22 +1329,33 @@ Session ended. ${totalTokens} tokens used.
1322
1329
  chalk4.dim("Conversation cleared.\n\n")
1323
1330
  );
1324
1331
  }
1325
- rl.prompt();
1332
+ if (!closed) rl.prompt();
1326
1333
  return;
1327
1334
  }
1328
1335
  if (input.startsWith("/save")) {
1329
1336
  const path = input.slice(5).trim() || "chat.txt";
1330
1337
  saveTranscript(path);
1331
- rl.prompt();
1338
+ if (!closed) rl.prompt();
1332
1339
  return;
1333
1340
  }
1334
1341
  await sendMessage(input);
1335
1342
  if (!closed) rl.prompt();
1343
+ };
1344
+ rl.on("line", (line) => {
1345
+ const turn = (pending ? pending.then(() => handleLine(line)) : handleLine(line)).finally(() => {
1346
+ if (pending === turn) pending = void 0;
1347
+ });
1348
+ pending = turn;
1349
+ return turn;
1336
1350
  });
1337
1351
  rl.on("close", () => {
1338
1352
  closed = true;
1339
- if (opts.save) saveTranscript(opts.save);
1340
- process.exitCode ??= 0;
1353
+ const finish = () => {
1354
+ if (opts.save) saveTranscript(opts.save);
1355
+ process.exitCode ??= 0;
1356
+ };
1357
+ if (pending && !stopped) void pending.then(finish);
1358
+ else finish();
1341
1359
  });
1342
1360
  });
1343
1361
  }
@@ -1392,7 +1410,8 @@ function createEmbeddingsCommand() {
1392
1410
  }
1393
1411
 
1394
1412
  // src/commands/gen/image.ts
1395
- import { writeFileSync as writeFileSync4 } from "fs";
1413
+ import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync4 } from "fs";
1414
+ import { dirname as dirname2 } from "path";
1396
1415
  import { Command as Command8 } from "commander";
1397
1416
  init_output();
1398
1417
  function createImageCommand() {
@@ -1423,6 +1442,7 @@ function createImageCommand() {
1423
1442
  }
1424
1443
  const encodedPrompt = encodeURIComponent(prompt);
1425
1444
  const path = `/image/${encodedPrompt}?${params}`;
1445
+ mkdirSync3(dirname2(opts.output), { recursive: true });
1426
1446
  if (isHuman) printInfo("Generating image...");
1427
1447
  try {
1428
1448
  const res = await fetchGen(path);
@@ -1440,8 +1460,8 @@ function createImageCommand() {
1440
1460
  }
1441
1461
 
1442
1462
  // src/commands/gen/isolate.ts
1443
- import { readFileSync as readFileSync3, writeFileSync as writeFileSync5 } from "fs";
1444
- import { basename } from "path";
1463
+ import { mkdirSync as mkdirSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync5 } from "fs";
1464
+ import { basename, dirname as dirname3 } from "path";
1445
1465
  import { Command as Command9 } from "commander";
1446
1466
 
1447
1467
  // src/lib/mime.ts
@@ -1484,6 +1504,7 @@ function createIsolateCommand() {
1484
1504
  basename(file)
1485
1505
  );
1486
1506
  if (opts.model) formData.append("model", opts.model);
1507
+ mkdirSync4(dirname3(opts.output), { recursive: true });
1487
1508
  if (isHuman) printInfo("Isolating speech...");
1488
1509
  try {
1489
1510
  const res = await fetchGen("/v1/audio/voice-isolator", {
@@ -1504,7 +1525,8 @@ function createIsolateCommand() {
1504
1525
  }
1505
1526
 
1506
1527
  // src/commands/gen/model3d.ts
1507
- import { writeFileSync as writeFileSync6 } from "fs";
1528
+ import { mkdirSync as mkdirSync5, writeFileSync as writeFileSync6 } from "fs";
1529
+ import { dirname as dirname4 } from "path";
1508
1530
  import { Command as Command10 } from "commander";
1509
1531
  init_output();
1510
1532
  var EXTENSION_BY_CONTENT_TYPE = {
@@ -1539,6 +1561,8 @@ function createModel3dCommand() {
1539
1561
  if (images.length) params.set("image", images.join("|"));
1540
1562
  const encodedPrompt = encodeURIComponent(promptArg || "model");
1541
1563
  const path = `/3d/${encodedPrompt}?${params}`;
1564
+ if (opts.output)
1565
+ mkdirSync5(dirname4(opts.output), { recursive: true });
1542
1566
  if (isHuman)
1543
1567
  printInfo("Generating 3D model (this can take a while)...");
1544
1568
  try {
@@ -1560,7 +1584,8 @@ function createModel3dCommand() {
1560
1584
  }
1561
1585
 
1562
1586
  // src/commands/gen/text.ts
1563
- import { writeFileSync as writeFileSync7 } from "fs";
1587
+ import { mkdirSync as mkdirSync6, writeFileSync as writeFileSync7 } from "fs";
1588
+ import { dirname as dirname5 } from "path";
1564
1589
  import chalk5 from "chalk";
1565
1590
  import { Command as Command11 } from "commander";
1566
1591
  init_output();
@@ -1659,6 +1684,8 @@ ${stdinText}` : stdinText;
1659
1684
  body.response_format = { type: "json_object" };
1660
1685
  if (opts.reasoning) body.reasoning_effort = opts.reasoning;
1661
1686
  if (useStream) body.stream = true;
1687
+ if (opts.output)
1688
+ mkdirSync6(dirname5(opts.output), { recursive: true });
1662
1689
  if (isHuman && !useStream) printInfo("Generating...");
1663
1690
  const warnIfTruncated = (reason) => {
1664
1691
  if (reason === "length")
@@ -1768,7 +1795,8 @@ function createTranscribeCommand() {
1768
1795
  }
1769
1796
 
1770
1797
  // src/commands/gen/video.ts
1771
- import { writeFileSync as writeFileSync8 } from "fs";
1798
+ import { mkdirSync as mkdirSync7, writeFileSync as writeFileSync8 } from "fs";
1799
+ import { dirname as dirname6 } from "path";
1772
1800
  import { Command as Command13 } from "commander";
1773
1801
  init_output();
1774
1802
  function createVideoCommand() {
@@ -1794,6 +1822,7 @@ function createVideoCommand() {
1794
1822
  }
1795
1823
  const encodedPrompt = encodeURIComponent(prompt);
1796
1824
  const path = `/video/${encodedPrompt}?${params}`;
1825
+ mkdirSync7(dirname6(opts.output), { recursive: true });
1797
1826
  if (isHuman)
1798
1827
  printInfo("Generating video (this can take up to 60s)...");
1799
1828
  try {
@@ -1812,8 +1841,8 @@ function createVideoCommand() {
1812
1841
  }
1813
1842
 
1814
1843
  // src/commands/gen/voice-change.ts
1815
- import { readFileSync as readFileSync5, writeFileSync as writeFileSync9 } from "fs";
1816
- import { basename as basename3 } from "path";
1844
+ import { mkdirSync as mkdirSync8, readFileSync as readFileSync5, writeFileSync as writeFileSync9 } from "fs";
1845
+ import { basename as basename3, dirname as dirname7 } from "path";
1817
1846
  import { Command as Command14 } from "commander";
1818
1847
  init_output();
1819
1848
  function createVoiceChangeCommand() {
@@ -1834,6 +1863,7 @@ function createVoiceChangeCommand() {
1834
1863
  if (opts.model) formData.append("model", opts.model);
1835
1864
  if (opts.format !== "mp3")
1836
1865
  formData.append("response_format", opts.format);
1866
+ mkdirSync8(dirname7(output), { recursive: true });
1837
1867
  if (isHuman) printInfo("Transforming voice...");
1838
1868
  try {
1839
1869
  const res = await fetchGen("/v1/audio/voice-changer", {
@@ -1872,14 +1902,14 @@ import {
1872
1902
  accessSync,
1873
1903
  constants,
1874
1904
  existsSync as existsSync2,
1875
- mkdirSync as mkdirSync2,
1905
+ mkdirSync as mkdirSync9,
1876
1906
  readFileSync as readFileSync6,
1877
1907
  renameSync,
1878
1908
  statSync,
1879
1909
  unlinkSync as unlinkSync2,
1880
1910
  writeFileSync as writeFileSync10
1881
1911
  } from "fs";
1882
- import { basename as basename4, delimiter, dirname, join as join2, resolve } from "path";
1912
+ import { basename as basename4, delimiter, dirname as dirname8, join as join2, resolve } from "path";
1883
1913
  var resolveHomePath = (home, path) => resolve(
1884
1914
  path === "~" ? home : path.startsWith("~/") || path.startsWith("~\\") ? join2(home, path.slice(2)) : path
1885
1915
  );
@@ -1900,9 +1930,9 @@ var commandExists = (command, env, fallbacks = []) => {
1900
1930
  };
1901
1931
  var readTextIfExists = (path) => existsSync2(path) ? readFileSync6(path, "utf-8") : null;
1902
1932
  var writeTextAtomic = (path, text, mode) => {
1903
- mkdirSync2(dirname(path), { recursive: true, mode: 448 });
1933
+ mkdirSync9(dirname8(path), { recursive: true, mode: 448 });
1904
1934
  const fileMode = mode ?? (existsSync2(path) ? statSync(path).mode & 511 : 384);
1905
- const tmp = join2(dirname(path), `.${basename4(path)}.${process.pid}.tmp`);
1935
+ const tmp = join2(dirname8(path), `.${basename4(path)}.${process.pid}.tmp`);
1906
1936
  writeFileSync10(tmp, text, { encoding: "utf-8", mode: fileMode });
1907
1937
  renameSync(tmp, path);
1908
1938
  };
@@ -5582,7 +5612,7 @@ import { execFileSync } from "child_process";
5582
5612
  import {
5583
5613
  chmodSync,
5584
5614
  existsSync as existsSync3,
5585
- mkdirSync as mkdirSync3,
5615
+ mkdirSync as mkdirSync10,
5586
5616
  readFileSync as readFileSync7,
5587
5617
  realpathSync,
5588
5618
  writeFileSync as writeFileSync11
@@ -5737,7 +5767,7 @@ async function proxy(host) {
5737
5767
  });
5738
5768
  }
5739
5769
  function setupSsh() {
5740
- mkdirSync3(SSH_DIR, { recursive: true, mode: 448 });
5770
+ mkdirSync10(SSH_DIR, { recursive: true, mode: 448 });
5741
5771
  if (!existsSync3(SSH_KEY)) {
5742
5772
  execFileSync("ssh-keygen", [
5743
5773
  "-q",
@@ -5768,7 +5798,7 @@ function setupSsh() {
5768
5798
  );
5769
5799
  const current = existsSync3(USER_SSH_CONFIG) ? readFileSync7(USER_SSH_CONFIG, "utf8") : "";
5770
5800
  if (!current.split("\n").includes(INCLUDE)) {
5771
- mkdirSync3(join15(homedir4(), ".ssh"), { recursive: true, mode: 448 });
5801
+ mkdirSync10(join15(homedir4(), ".ssh"), { recursive: true, mode: 448 });
5772
5802
  writeFileSync11(USER_SSH_CONFIG, `${INCLUDE}
5773
5803
 
5774
5804
  ${current}`);
@@ -5920,7 +5950,7 @@ var sandboxCommand = new Command22("sandbox").description("E2B sandboxes billed
5920
5950
  init_output();
5921
5951
  import { execSync, spawnSync as spawnSync6 } from "child_process";
5922
5952
  import { existsSync as existsSync4, readFileSync as readFileSync8 } from "fs";
5923
- import { dirname as dirname2, join as join16, resolve as resolve2, sep } from "path";
5953
+ import { dirname as dirname9, join as join16, resolve as resolve2, sep } from "path";
5924
5954
  import { fileURLToPath } from "url";
5925
5955
  import { Command as Command23 } from "commander";
5926
5956
  var PACKAGE_NAME = "@pollinations/cli";
@@ -5928,13 +5958,13 @@ var REGISTRY_URL = "https://registry.npmjs.org/@pollinations%2Fcli/latest";
5928
5958
  function findPackageRoot(fromDir) {
5929
5959
  let dir = resolve2(fromDir);
5930
5960
  while (!existsSync4(join16(dir, "package.json"))) {
5931
- const parent = dirname2(dir);
5961
+ const parent = dirname9(dir);
5932
5962
  if (parent === dir) throw new Error("could not locate package.json");
5933
5963
  dir = parent;
5934
5964
  }
5935
5965
  return dir;
5936
5966
  }
5937
- var packageDir = findPackageRoot(dirname2(fileURLToPath(import.meta.url)));
5967
+ var packageDir = findPackageRoot(dirname9(fileURLToPath(import.meta.url)));
5938
5968
  var currentVersion = JSON.parse(readFileSync8(join16(packageDir, "package.json"), "utf-8")).version;
5939
5969
  function detectInstallKind(dir, globalRoot) {
5940
5970
  const resolvedDir = resolve2(dir);