@pollinations/cli 0.1.30 → 0.1.32

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.32",
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;
@@ -1123,6 +1125,7 @@ Examples:
1123
1125
 
1124
1126
  // src/commands/gen/chat.ts
1125
1127
  init_api();
1128
+ init_client();
1126
1129
  init_config();
1127
1130
  import { writeFileSync as writeFileSync3 } from "fs";
1128
1131
  import { createInterface as createInterface2 } from "readline";
@@ -1226,7 +1229,8 @@ Chat session started (model: ${opts.model ?? "API default"})
1226
1229
  method: "POST",
1227
1230
  headers: {
1228
1231
  "Content-Type": "application/json",
1229
- Authorization: `Bearer ${key}`
1232
+ Authorization: `Bearer ${key}`,
1233
+ "X-Polli-Client": POLLI_CLIENT
1230
1234
  },
1231
1235
  body: JSON.stringify(body)
1232
1236
  });
@@ -1235,6 +1239,7 @@ Chat session started (model: ${opts.model ?? "API default"})
1235
1239
  const hint = await budgetHint(res.status, errText);
1236
1240
  if (hint) {
1237
1241
  printError(hint);
1242
+ stopped = true;
1238
1243
  rl.close();
1239
1244
  process.exitCode = 1;
1240
1245
  return;
@@ -1291,11 +1296,14 @@ Chat session started (model: ${opts.model ?? "API default"})
1291
1296
  }
1292
1297
  };
1293
1298
  let closed = false;
1299
+ let stopped = false;
1300
+ let pending;
1294
1301
  rl.prompt();
1295
- rl.on("line", async (line) => {
1302
+ const handleLine = async (line) => {
1303
+ if (stopped) return;
1296
1304
  const input = line.trim();
1297
1305
  if (!input) {
1298
- rl.prompt();
1306
+ if (!closed) rl.prompt();
1299
1307
  return;
1300
1308
  }
1301
1309
  if (input === "/exit" || input === "/quit") {
@@ -1308,6 +1316,7 @@ Session ended. ${totalTokens} tokens used.
1308
1316
  )
1309
1317
  );
1310
1318
  }
1319
+ stopped = true;
1311
1320
  rl.close();
1312
1321
  return;
1313
1322
  }
@@ -1322,22 +1331,33 @@ Session ended. ${totalTokens} tokens used.
1322
1331
  chalk4.dim("Conversation cleared.\n\n")
1323
1332
  );
1324
1333
  }
1325
- rl.prompt();
1334
+ if (!closed) rl.prompt();
1326
1335
  return;
1327
1336
  }
1328
1337
  if (input.startsWith("/save")) {
1329
1338
  const path = input.slice(5).trim() || "chat.txt";
1330
1339
  saveTranscript(path);
1331
- rl.prompt();
1340
+ if (!closed) rl.prompt();
1332
1341
  return;
1333
1342
  }
1334
1343
  await sendMessage(input);
1335
1344
  if (!closed) rl.prompt();
1345
+ };
1346
+ rl.on("line", (line) => {
1347
+ const turn = (pending ? pending.then(() => handleLine(line)) : handleLine(line)).finally(() => {
1348
+ if (pending === turn) pending = void 0;
1349
+ });
1350
+ pending = turn;
1351
+ return turn;
1336
1352
  });
1337
1353
  rl.on("close", () => {
1338
1354
  closed = true;
1339
- if (opts.save) saveTranscript(opts.save);
1340
- process.exitCode ??= 0;
1355
+ const finish = () => {
1356
+ if (opts.save) saveTranscript(opts.save);
1357
+ process.exitCode ??= 0;
1358
+ };
1359
+ if (pending && !stopped) void pending.then(finish);
1360
+ else finish();
1341
1361
  });
1342
1362
  });
1343
1363
  }
@@ -1392,7 +1412,8 @@ function createEmbeddingsCommand() {
1392
1412
  }
1393
1413
 
1394
1414
  // src/commands/gen/image.ts
1395
- import { writeFileSync as writeFileSync4 } from "fs";
1415
+ import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync4 } from "fs";
1416
+ import { dirname as dirname2 } from "path";
1396
1417
  import { Command as Command8 } from "commander";
1397
1418
  init_output();
1398
1419
  function createImageCommand() {
@@ -1423,6 +1444,7 @@ function createImageCommand() {
1423
1444
  }
1424
1445
  const encodedPrompt = encodeURIComponent(prompt);
1425
1446
  const path = `/image/${encodedPrompt}?${params}`;
1447
+ mkdirSync3(dirname2(opts.output), { recursive: true });
1426
1448
  if (isHuman) printInfo("Generating image...");
1427
1449
  try {
1428
1450
  const res = await fetchGen(path);
@@ -1440,8 +1462,8 @@ function createImageCommand() {
1440
1462
  }
1441
1463
 
1442
1464
  // src/commands/gen/isolate.ts
1443
- import { readFileSync as readFileSync3, writeFileSync as writeFileSync5 } from "fs";
1444
- import { basename } from "path";
1465
+ import { mkdirSync as mkdirSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync5 } from "fs";
1466
+ import { basename, dirname as dirname3 } from "path";
1445
1467
  import { Command as Command9 } from "commander";
1446
1468
 
1447
1469
  // src/lib/mime.ts
@@ -1484,6 +1506,7 @@ function createIsolateCommand() {
1484
1506
  basename(file)
1485
1507
  );
1486
1508
  if (opts.model) formData.append("model", opts.model);
1509
+ mkdirSync4(dirname3(opts.output), { recursive: true });
1487
1510
  if (isHuman) printInfo("Isolating speech...");
1488
1511
  try {
1489
1512
  const res = await fetchGen("/v1/audio/voice-isolator", {
@@ -1504,7 +1527,8 @@ function createIsolateCommand() {
1504
1527
  }
1505
1528
 
1506
1529
  // src/commands/gen/model3d.ts
1507
- import { writeFileSync as writeFileSync6 } from "fs";
1530
+ import { mkdirSync as mkdirSync5, writeFileSync as writeFileSync6 } from "fs";
1531
+ import { dirname as dirname4 } from "path";
1508
1532
  import { Command as Command10 } from "commander";
1509
1533
  init_output();
1510
1534
  var EXTENSION_BY_CONTENT_TYPE = {
@@ -1539,6 +1563,8 @@ function createModel3dCommand() {
1539
1563
  if (images.length) params.set("image", images.join("|"));
1540
1564
  const encodedPrompt = encodeURIComponent(promptArg || "model");
1541
1565
  const path = `/3d/${encodedPrompt}?${params}`;
1566
+ if (opts.output)
1567
+ mkdirSync5(dirname4(opts.output), { recursive: true });
1542
1568
  if (isHuman)
1543
1569
  printInfo("Generating 3D model (this can take a while)...");
1544
1570
  try {
@@ -1560,7 +1586,8 @@ function createModel3dCommand() {
1560
1586
  }
1561
1587
 
1562
1588
  // src/commands/gen/text.ts
1563
- import { writeFileSync as writeFileSync7 } from "fs";
1589
+ import { mkdirSync as mkdirSync6, writeFileSync as writeFileSync7 } from "fs";
1590
+ import { dirname as dirname5 } from "path";
1564
1591
  import chalk5 from "chalk";
1565
1592
  import { Command as Command11 } from "commander";
1566
1593
  init_output();
@@ -1659,6 +1686,8 @@ ${stdinText}` : stdinText;
1659
1686
  body.response_format = { type: "json_object" };
1660
1687
  if (opts.reasoning) body.reasoning_effort = opts.reasoning;
1661
1688
  if (useStream) body.stream = true;
1689
+ if (opts.output)
1690
+ mkdirSync6(dirname5(opts.output), { recursive: true });
1662
1691
  if (isHuman && !useStream) printInfo("Generating...");
1663
1692
  const warnIfTruncated = (reason) => {
1664
1693
  if (reason === "length")
@@ -1768,7 +1797,8 @@ function createTranscribeCommand() {
1768
1797
  }
1769
1798
 
1770
1799
  // src/commands/gen/video.ts
1771
- import { writeFileSync as writeFileSync8 } from "fs";
1800
+ import { mkdirSync as mkdirSync7, writeFileSync as writeFileSync8 } from "fs";
1801
+ import { dirname as dirname6 } from "path";
1772
1802
  import { Command as Command13 } from "commander";
1773
1803
  init_output();
1774
1804
  function createVideoCommand() {
@@ -1794,6 +1824,7 @@ function createVideoCommand() {
1794
1824
  }
1795
1825
  const encodedPrompt = encodeURIComponent(prompt);
1796
1826
  const path = `/video/${encodedPrompt}?${params}`;
1827
+ mkdirSync7(dirname6(opts.output), { recursive: true });
1797
1828
  if (isHuman)
1798
1829
  printInfo("Generating video (this can take up to 60s)...");
1799
1830
  try {
@@ -1812,8 +1843,8 @@ function createVideoCommand() {
1812
1843
  }
1813
1844
 
1814
1845
  // src/commands/gen/voice-change.ts
1815
- import { readFileSync as readFileSync5, writeFileSync as writeFileSync9 } from "fs";
1816
- import { basename as basename3 } from "path";
1846
+ import { mkdirSync as mkdirSync8, readFileSync as readFileSync5, writeFileSync as writeFileSync9 } from "fs";
1847
+ import { basename as basename3, dirname as dirname7 } from "path";
1817
1848
  import { Command as Command14 } from "commander";
1818
1849
  init_output();
1819
1850
  function createVoiceChangeCommand() {
@@ -1834,6 +1865,7 @@ function createVoiceChangeCommand() {
1834
1865
  if (opts.model) formData.append("model", opts.model);
1835
1866
  if (opts.format !== "mp3")
1836
1867
  formData.append("response_format", opts.format);
1868
+ mkdirSync8(dirname7(output), { recursive: true });
1837
1869
  if (isHuman) printInfo("Transforming voice...");
1838
1870
  try {
1839
1871
  const res = await fetchGen("/v1/audio/voice-changer", {
@@ -1872,14 +1904,14 @@ import {
1872
1904
  accessSync,
1873
1905
  constants,
1874
1906
  existsSync as existsSync2,
1875
- mkdirSync as mkdirSync2,
1907
+ mkdirSync as mkdirSync9,
1876
1908
  readFileSync as readFileSync6,
1877
1909
  renameSync,
1878
1910
  statSync,
1879
1911
  unlinkSync as unlinkSync2,
1880
1912
  writeFileSync as writeFileSync10
1881
1913
  } from "fs";
1882
- import { basename as basename4, delimiter, dirname, join as join2, resolve } from "path";
1914
+ import { basename as basename4, delimiter, dirname as dirname8, join as join2, resolve } from "path";
1883
1915
  var resolveHomePath = (home, path) => resolve(
1884
1916
  path === "~" ? home : path.startsWith("~/") || path.startsWith("~\\") ? join2(home, path.slice(2)) : path
1885
1917
  );
@@ -1900,9 +1932,9 @@ var commandExists = (command, env, fallbacks = []) => {
1900
1932
  };
1901
1933
  var readTextIfExists = (path) => existsSync2(path) ? readFileSync6(path, "utf-8") : null;
1902
1934
  var writeTextAtomic = (path, text, mode) => {
1903
- mkdirSync2(dirname(path), { recursive: true, mode: 448 });
1935
+ mkdirSync9(dirname8(path), { recursive: true, mode: 448 });
1904
1936
  const fileMode = mode ?? (existsSync2(path) ? statSync(path).mode & 511 : 384);
1905
- const tmp = join2(dirname(path), `.${basename4(path)}.${process.pid}.tmp`);
1937
+ const tmp = join2(dirname8(path), `.${basename4(path)}.${process.pid}.tmp`);
1906
1938
  writeFileSync10(tmp, text, { encoding: "utf-8", mode: fileMode });
1907
1939
  renameSync(tmp, path);
1908
1940
  };
@@ -5582,7 +5614,7 @@ import { execFileSync } from "child_process";
5582
5614
  import {
5583
5615
  chmodSync,
5584
5616
  existsSync as existsSync3,
5585
- mkdirSync as mkdirSync3,
5617
+ mkdirSync as mkdirSync10,
5586
5618
  readFileSync as readFileSync7,
5587
5619
  realpathSync,
5588
5620
  writeFileSync as writeFileSync11
@@ -5737,7 +5769,7 @@ async function proxy(host) {
5737
5769
  });
5738
5770
  }
5739
5771
  function setupSsh() {
5740
- mkdirSync3(SSH_DIR, { recursive: true, mode: 448 });
5772
+ mkdirSync10(SSH_DIR, { recursive: true, mode: 448 });
5741
5773
  if (!existsSync3(SSH_KEY)) {
5742
5774
  execFileSync("ssh-keygen", [
5743
5775
  "-q",
@@ -5768,7 +5800,7 @@ function setupSsh() {
5768
5800
  );
5769
5801
  const current = existsSync3(USER_SSH_CONFIG) ? readFileSync7(USER_SSH_CONFIG, "utf8") : "";
5770
5802
  if (!current.split("\n").includes(INCLUDE)) {
5771
- mkdirSync3(join15(homedir4(), ".ssh"), { recursive: true, mode: 448 });
5803
+ mkdirSync10(join15(homedir4(), ".ssh"), { recursive: true, mode: 448 });
5772
5804
  writeFileSync11(USER_SSH_CONFIG, `${INCLUDE}
5773
5805
 
5774
5806
  ${current}`);
@@ -5920,7 +5952,7 @@ var sandboxCommand = new Command22("sandbox").description("E2B sandboxes billed
5920
5952
  init_output();
5921
5953
  import { execSync, spawnSync as spawnSync6 } from "child_process";
5922
5954
  import { existsSync as existsSync4, readFileSync as readFileSync8 } from "fs";
5923
- import { dirname as dirname2, join as join16, resolve as resolve2, sep } from "path";
5955
+ import { dirname as dirname9, join as join16, resolve as resolve2, sep } from "path";
5924
5956
  import { fileURLToPath } from "url";
5925
5957
  import { Command as Command23 } from "commander";
5926
5958
  var PACKAGE_NAME = "@pollinations/cli";
@@ -5928,13 +5960,13 @@ var REGISTRY_URL = "https://registry.npmjs.org/@pollinations%2Fcli/latest";
5928
5960
  function findPackageRoot(fromDir) {
5929
5961
  let dir = resolve2(fromDir);
5930
5962
  while (!existsSync4(join16(dir, "package.json"))) {
5931
- const parent = dirname2(dir);
5963
+ const parent = dirname9(dir);
5932
5964
  if (parent === dir) throw new Error("could not locate package.json");
5933
5965
  dir = parent;
5934
5966
  }
5935
5967
  return dir;
5936
5968
  }
5937
- var packageDir = findPackageRoot(dirname2(fileURLToPath(import.meta.url)));
5969
+ var packageDir = findPackageRoot(dirname9(fileURLToPath(import.meta.url)));
5938
5970
  var currentVersion = JSON.parse(readFileSync8(join16(packageDir, "package.json"), "utf-8")).version;
5939
5971
  function detectInstallKind(dir, globalRoot) {
5940
5972
  const resolvedDir = resolve2(dir);