@pollinations/cli 0.1.29 → 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 +87 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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.
|
|
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: {
|
|
@@ -160,7 +160,7 @@ var init_config = __esm({
|
|
|
160
160
|
|
|
161
161
|
// src/lib/output.ts
|
|
162
162
|
import chalk from "chalk";
|
|
163
|
-
var configureHelp, currentMode, setOutputMode, getOutputMode, printResult, printTable, printInfo, printMeta, printSuccess, printError, ExitSignal, fail;
|
|
163
|
+
var configureHelp, currentMode, setOutputMode, getOutputMode, printResult, printTable, printInfo, printMeta, printSuccess, printError, ExitSignal, fail, printWarn;
|
|
164
164
|
var init_output = __esm({
|
|
165
165
|
"src/lib/output.ts"() {
|
|
166
166
|
"use strict";
|
|
@@ -280,6 +280,12 @@ var init_output = __esm({
|
|
|
280
280
|
printError(`${message}${detail}`);
|
|
281
281
|
throw new ExitSignal(1);
|
|
282
282
|
};
|
|
283
|
+
printWarn = (msg) => {
|
|
284
|
+
process.stderr.write(
|
|
285
|
+
`${chalk.yellow.bold("warn:")} ${chalk.yellow(msg)}
|
|
286
|
+
`
|
|
287
|
+
);
|
|
288
|
+
};
|
|
283
289
|
}
|
|
284
290
|
});
|
|
285
291
|
|
|
@@ -788,11 +794,22 @@ var docsCommand = new Command3("docs").description("Show Pollinations API docume
|
|
|
788
794
|
const isJson = getOutputMode() === "json";
|
|
789
795
|
let content = doc;
|
|
790
796
|
if (endpoint) {
|
|
791
|
-
const sections =
|
|
797
|
+
const sections = [""];
|
|
798
|
+
let inFence = false;
|
|
799
|
+
for (const line of doc.split(/(?<=\n)/)) {
|
|
800
|
+
if (line.startsWith("```")) inFence = !inFence;
|
|
801
|
+
if (!inFence && /^#{1,6} /.test(line)) {
|
|
802
|
+
sections.push("");
|
|
803
|
+
}
|
|
804
|
+
sections[sections.length - 1] += line;
|
|
805
|
+
}
|
|
792
806
|
const needle = endpoint.replace(/^\//, "").toLowerCase();
|
|
793
|
-
const
|
|
807
|
+
const headingMatches = sections.filter(
|
|
794
808
|
(s) => s.split("\n")[0].toLowerCase().includes(needle)
|
|
795
809
|
);
|
|
810
|
+
const matches = headingMatches.length ? headingMatches : sections.filter(
|
|
811
|
+
(s) => s.toLowerCase().includes(needle)
|
|
812
|
+
);
|
|
796
813
|
if (matches.length === 0) {
|
|
797
814
|
printError(`No docs found matching "${endpoint}"`);
|
|
798
815
|
printInfo(
|
|
@@ -864,7 +881,8 @@ var earningsCommand = new Command4("earnings").description("Show developer earni
|
|
|
864
881
|
import { Command as Command15 } from "commander";
|
|
865
882
|
|
|
866
883
|
// src/commands/gen/audio.ts
|
|
867
|
-
import { writeFileSync as writeFileSync2 } from "fs";
|
|
884
|
+
import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
885
|
+
import { dirname } from "path";
|
|
868
886
|
import { Command as Command5 } from "commander";
|
|
869
887
|
|
|
870
888
|
// src/lib/errors.ts
|
|
@@ -1075,6 +1093,7 @@ Examples:
|
|
|
1075
1093
|
);
|
|
1076
1094
|
throw new ExitSignal(1);
|
|
1077
1095
|
}
|
|
1096
|
+
mkdirSync2(dirname(output), { recursive: true });
|
|
1078
1097
|
if (isHuman) printInfo("Generating audio...");
|
|
1079
1098
|
try {
|
|
1080
1099
|
const alignmentPath = opts.timestamps ? `${output}.json` : void 0;
|
|
@@ -1218,6 +1237,7 @@ Chat session started (model: ${opts.model ?? "API default"})
|
|
|
1218
1237
|
const hint = await budgetHint(res.status, errText);
|
|
1219
1238
|
if (hint) {
|
|
1220
1239
|
printError(hint);
|
|
1240
|
+
stopped = true;
|
|
1221
1241
|
rl.close();
|
|
1222
1242
|
process.exitCode = 1;
|
|
1223
1243
|
return;
|
|
@@ -1274,11 +1294,14 @@ Chat session started (model: ${opts.model ?? "API default"})
|
|
|
1274
1294
|
}
|
|
1275
1295
|
};
|
|
1276
1296
|
let closed = false;
|
|
1297
|
+
let stopped = false;
|
|
1298
|
+
let pending;
|
|
1277
1299
|
rl.prompt();
|
|
1278
|
-
|
|
1300
|
+
const handleLine = async (line) => {
|
|
1301
|
+
if (stopped) return;
|
|
1279
1302
|
const input = line.trim();
|
|
1280
1303
|
if (!input) {
|
|
1281
|
-
rl.prompt();
|
|
1304
|
+
if (!closed) rl.prompt();
|
|
1282
1305
|
return;
|
|
1283
1306
|
}
|
|
1284
1307
|
if (input === "/exit" || input === "/quit") {
|
|
@@ -1291,6 +1314,7 @@ Session ended. ${totalTokens} tokens used.
|
|
|
1291
1314
|
)
|
|
1292
1315
|
);
|
|
1293
1316
|
}
|
|
1317
|
+
stopped = true;
|
|
1294
1318
|
rl.close();
|
|
1295
1319
|
return;
|
|
1296
1320
|
}
|
|
@@ -1305,22 +1329,33 @@ Session ended. ${totalTokens} tokens used.
|
|
|
1305
1329
|
chalk4.dim("Conversation cleared.\n\n")
|
|
1306
1330
|
);
|
|
1307
1331
|
}
|
|
1308
|
-
rl.prompt();
|
|
1332
|
+
if (!closed) rl.prompt();
|
|
1309
1333
|
return;
|
|
1310
1334
|
}
|
|
1311
1335
|
if (input.startsWith("/save")) {
|
|
1312
1336
|
const path = input.slice(5).trim() || "chat.txt";
|
|
1313
1337
|
saveTranscript(path);
|
|
1314
|
-
rl.prompt();
|
|
1338
|
+
if (!closed) rl.prompt();
|
|
1315
1339
|
return;
|
|
1316
1340
|
}
|
|
1317
1341
|
await sendMessage(input);
|
|
1318
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;
|
|
1319
1350
|
});
|
|
1320
1351
|
rl.on("close", () => {
|
|
1321
1352
|
closed = true;
|
|
1322
|
-
|
|
1323
|
-
|
|
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();
|
|
1324
1359
|
});
|
|
1325
1360
|
});
|
|
1326
1361
|
}
|
|
@@ -1375,7 +1410,8 @@ function createEmbeddingsCommand() {
|
|
|
1375
1410
|
}
|
|
1376
1411
|
|
|
1377
1412
|
// src/commands/gen/image.ts
|
|
1378
|
-
import { writeFileSync as writeFileSync4 } from "fs";
|
|
1413
|
+
import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync4 } from "fs";
|
|
1414
|
+
import { dirname as dirname2 } from "path";
|
|
1379
1415
|
import { Command as Command8 } from "commander";
|
|
1380
1416
|
init_output();
|
|
1381
1417
|
function createImageCommand() {
|
|
@@ -1406,6 +1442,7 @@ function createImageCommand() {
|
|
|
1406
1442
|
}
|
|
1407
1443
|
const encodedPrompt = encodeURIComponent(prompt);
|
|
1408
1444
|
const path = `/image/${encodedPrompt}?${params}`;
|
|
1445
|
+
mkdirSync3(dirname2(opts.output), { recursive: true });
|
|
1409
1446
|
if (isHuman) printInfo("Generating image...");
|
|
1410
1447
|
try {
|
|
1411
1448
|
const res = await fetchGen(path);
|
|
@@ -1423,8 +1460,8 @@ function createImageCommand() {
|
|
|
1423
1460
|
}
|
|
1424
1461
|
|
|
1425
1462
|
// src/commands/gen/isolate.ts
|
|
1426
|
-
import { readFileSync as readFileSync3, writeFileSync as writeFileSync5 } from "fs";
|
|
1427
|
-
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";
|
|
1428
1465
|
import { Command as Command9 } from "commander";
|
|
1429
1466
|
|
|
1430
1467
|
// src/lib/mime.ts
|
|
@@ -1467,6 +1504,7 @@ function createIsolateCommand() {
|
|
|
1467
1504
|
basename(file)
|
|
1468
1505
|
);
|
|
1469
1506
|
if (opts.model) formData.append("model", opts.model);
|
|
1507
|
+
mkdirSync4(dirname3(opts.output), { recursive: true });
|
|
1470
1508
|
if (isHuman) printInfo("Isolating speech...");
|
|
1471
1509
|
try {
|
|
1472
1510
|
const res = await fetchGen("/v1/audio/voice-isolator", {
|
|
@@ -1487,7 +1525,8 @@ function createIsolateCommand() {
|
|
|
1487
1525
|
}
|
|
1488
1526
|
|
|
1489
1527
|
// src/commands/gen/model3d.ts
|
|
1490
|
-
import { writeFileSync as writeFileSync6 } from "fs";
|
|
1528
|
+
import { mkdirSync as mkdirSync5, writeFileSync as writeFileSync6 } from "fs";
|
|
1529
|
+
import { dirname as dirname4 } from "path";
|
|
1491
1530
|
import { Command as Command10 } from "commander";
|
|
1492
1531
|
init_output();
|
|
1493
1532
|
var EXTENSION_BY_CONTENT_TYPE = {
|
|
@@ -1522,6 +1561,8 @@ function createModel3dCommand() {
|
|
|
1522
1561
|
if (images.length) params.set("image", images.join("|"));
|
|
1523
1562
|
const encodedPrompt = encodeURIComponent(promptArg || "model");
|
|
1524
1563
|
const path = `/3d/${encodedPrompt}?${params}`;
|
|
1564
|
+
if (opts.output)
|
|
1565
|
+
mkdirSync5(dirname4(opts.output), { recursive: true });
|
|
1525
1566
|
if (isHuman)
|
|
1526
1567
|
printInfo("Generating 3D model (this can take a while)...");
|
|
1527
1568
|
try {
|
|
@@ -1543,7 +1584,8 @@ function createModel3dCommand() {
|
|
|
1543
1584
|
}
|
|
1544
1585
|
|
|
1545
1586
|
// src/commands/gen/text.ts
|
|
1546
|
-
import { writeFileSync as writeFileSync7 } from "fs";
|
|
1587
|
+
import { mkdirSync as mkdirSync6, writeFileSync as writeFileSync7 } from "fs";
|
|
1588
|
+
import { dirname as dirname5 } from "path";
|
|
1547
1589
|
import chalk5 from "chalk";
|
|
1548
1590
|
import { Command as Command11 } from "commander";
|
|
1549
1591
|
init_output();
|
|
@@ -1642,7 +1684,15 @@ ${stdinText}` : stdinText;
|
|
|
1642
1684
|
body.response_format = { type: "json_object" };
|
|
1643
1685
|
if (opts.reasoning) body.reasoning_effort = opts.reasoning;
|
|
1644
1686
|
if (useStream) body.stream = true;
|
|
1687
|
+
if (opts.output)
|
|
1688
|
+
mkdirSync6(dirname5(opts.output), { recursive: true });
|
|
1645
1689
|
if (isHuman && !useStream) printInfo("Generating...");
|
|
1690
|
+
const warnIfTruncated = (reason) => {
|
|
1691
|
+
if (reason === "length")
|
|
1692
|
+
printWarn(
|
|
1693
|
+
"The model reached its output token limit; the response may be truncated."
|
|
1694
|
+
);
|
|
1695
|
+
};
|
|
1646
1696
|
try {
|
|
1647
1697
|
const res = await fetchGen("/v1/chat/completions", {
|
|
1648
1698
|
method: "POST",
|
|
@@ -1656,15 +1706,19 @@ ${stdinText}` : stdinText;
|
|
|
1656
1706
|
let content2 = "";
|
|
1657
1707
|
let model = null;
|
|
1658
1708
|
let tokens = null;
|
|
1709
|
+
let lengthTerminated = false;
|
|
1659
1710
|
for await (const chunk of streamSSE(res, (event) => {
|
|
1660
1711
|
if (typeof event.model === "string")
|
|
1661
1712
|
model = event.model;
|
|
1662
1713
|
if (typeof event.usage?.total_tokens === "number")
|
|
1663
1714
|
tokens = event.usage.total_tokens;
|
|
1715
|
+
if (event.choices?.[0]?.finish_reason === "length")
|
|
1716
|
+
lengthTerminated = true;
|
|
1664
1717
|
})) {
|
|
1665
1718
|
content2 += chunk;
|
|
1666
1719
|
if (isHuman) process.stdout.write(colorize(chunk));
|
|
1667
1720
|
}
|
|
1721
|
+
if (lengthTerminated) warnIfTruncated("length");
|
|
1668
1722
|
if (isHuman) process.stdout.write("\n");
|
|
1669
1723
|
if (getOutputMode() === "json") {
|
|
1670
1724
|
printResult({ content: content2, model, tokens });
|
|
@@ -1673,6 +1727,7 @@ ${stdinText}` : stdinText;
|
|
|
1673
1727
|
}
|
|
1674
1728
|
const data = await res.json();
|
|
1675
1729
|
const content = data.choices[0]?.message?.content ?? "";
|
|
1730
|
+
warnIfTruncated(data.choices[0]?.finish_reason);
|
|
1676
1731
|
if (opts.output) {
|
|
1677
1732
|
writeFileSync7(opts.output, content, "utf-8");
|
|
1678
1733
|
if (getOutputMode() === "json") {
|
|
@@ -1740,7 +1795,8 @@ function createTranscribeCommand() {
|
|
|
1740
1795
|
}
|
|
1741
1796
|
|
|
1742
1797
|
// src/commands/gen/video.ts
|
|
1743
|
-
import { writeFileSync as writeFileSync8 } from "fs";
|
|
1798
|
+
import { mkdirSync as mkdirSync7, writeFileSync as writeFileSync8 } from "fs";
|
|
1799
|
+
import { dirname as dirname6 } from "path";
|
|
1744
1800
|
import { Command as Command13 } from "commander";
|
|
1745
1801
|
init_output();
|
|
1746
1802
|
function createVideoCommand() {
|
|
@@ -1766,6 +1822,7 @@ function createVideoCommand() {
|
|
|
1766
1822
|
}
|
|
1767
1823
|
const encodedPrompt = encodeURIComponent(prompt);
|
|
1768
1824
|
const path = `/video/${encodedPrompt}?${params}`;
|
|
1825
|
+
mkdirSync7(dirname6(opts.output), { recursive: true });
|
|
1769
1826
|
if (isHuman)
|
|
1770
1827
|
printInfo("Generating video (this can take up to 60s)...");
|
|
1771
1828
|
try {
|
|
@@ -1784,8 +1841,8 @@ function createVideoCommand() {
|
|
|
1784
1841
|
}
|
|
1785
1842
|
|
|
1786
1843
|
// src/commands/gen/voice-change.ts
|
|
1787
|
-
import { readFileSync as readFileSync5, writeFileSync as writeFileSync9 } from "fs";
|
|
1788
|
-
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";
|
|
1789
1846
|
import { Command as Command14 } from "commander";
|
|
1790
1847
|
init_output();
|
|
1791
1848
|
function createVoiceChangeCommand() {
|
|
@@ -1806,6 +1863,7 @@ function createVoiceChangeCommand() {
|
|
|
1806
1863
|
if (opts.model) formData.append("model", opts.model);
|
|
1807
1864
|
if (opts.format !== "mp3")
|
|
1808
1865
|
formData.append("response_format", opts.format);
|
|
1866
|
+
mkdirSync8(dirname7(output), { recursive: true });
|
|
1809
1867
|
if (isHuman) printInfo("Transforming voice...");
|
|
1810
1868
|
try {
|
|
1811
1869
|
const res = await fetchGen("/v1/audio/voice-changer", {
|
|
@@ -1844,14 +1902,14 @@ import {
|
|
|
1844
1902
|
accessSync,
|
|
1845
1903
|
constants,
|
|
1846
1904
|
existsSync as existsSync2,
|
|
1847
|
-
mkdirSync as
|
|
1905
|
+
mkdirSync as mkdirSync9,
|
|
1848
1906
|
readFileSync as readFileSync6,
|
|
1849
1907
|
renameSync,
|
|
1850
1908
|
statSync,
|
|
1851
1909
|
unlinkSync as unlinkSync2,
|
|
1852
1910
|
writeFileSync as writeFileSync10
|
|
1853
1911
|
} from "fs";
|
|
1854
|
-
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";
|
|
1855
1913
|
var resolveHomePath = (home, path) => resolve(
|
|
1856
1914
|
path === "~" ? home : path.startsWith("~/") || path.startsWith("~\\") ? join2(home, path.slice(2)) : path
|
|
1857
1915
|
);
|
|
@@ -1872,9 +1930,9 @@ var commandExists = (command, env, fallbacks = []) => {
|
|
|
1872
1930
|
};
|
|
1873
1931
|
var readTextIfExists = (path) => existsSync2(path) ? readFileSync6(path, "utf-8") : null;
|
|
1874
1932
|
var writeTextAtomic = (path, text, mode) => {
|
|
1875
|
-
|
|
1933
|
+
mkdirSync9(dirname8(path), { recursive: true, mode: 448 });
|
|
1876
1934
|
const fileMode = mode ?? (existsSync2(path) ? statSync(path).mode & 511 : 384);
|
|
1877
|
-
const tmp = join2(
|
|
1935
|
+
const tmp = join2(dirname8(path), `.${basename4(path)}.${process.pid}.tmp`);
|
|
1878
1936
|
writeFileSync10(tmp, text, { encoding: "utf-8", mode: fileMode });
|
|
1879
1937
|
renameSync(tmp, path);
|
|
1880
1938
|
};
|
|
@@ -5554,7 +5612,7 @@ import { execFileSync } from "child_process";
|
|
|
5554
5612
|
import {
|
|
5555
5613
|
chmodSync,
|
|
5556
5614
|
existsSync as existsSync3,
|
|
5557
|
-
mkdirSync as
|
|
5615
|
+
mkdirSync as mkdirSync10,
|
|
5558
5616
|
readFileSync as readFileSync7,
|
|
5559
5617
|
realpathSync,
|
|
5560
5618
|
writeFileSync as writeFileSync11
|
|
@@ -5709,7 +5767,7 @@ async function proxy(host) {
|
|
|
5709
5767
|
});
|
|
5710
5768
|
}
|
|
5711
5769
|
function setupSsh() {
|
|
5712
|
-
|
|
5770
|
+
mkdirSync10(SSH_DIR, { recursive: true, mode: 448 });
|
|
5713
5771
|
if (!existsSync3(SSH_KEY)) {
|
|
5714
5772
|
execFileSync("ssh-keygen", [
|
|
5715
5773
|
"-q",
|
|
@@ -5740,7 +5798,7 @@ function setupSsh() {
|
|
|
5740
5798
|
);
|
|
5741
5799
|
const current = existsSync3(USER_SSH_CONFIG) ? readFileSync7(USER_SSH_CONFIG, "utf8") : "";
|
|
5742
5800
|
if (!current.split("\n").includes(INCLUDE)) {
|
|
5743
|
-
|
|
5801
|
+
mkdirSync10(join15(homedir4(), ".ssh"), { recursive: true, mode: 448 });
|
|
5744
5802
|
writeFileSync11(USER_SSH_CONFIG, `${INCLUDE}
|
|
5745
5803
|
|
|
5746
5804
|
${current}`);
|
|
@@ -5892,7 +5950,7 @@ var sandboxCommand = new Command22("sandbox").description("E2B sandboxes billed
|
|
|
5892
5950
|
init_output();
|
|
5893
5951
|
import { execSync, spawnSync as spawnSync6 } from "child_process";
|
|
5894
5952
|
import { existsSync as existsSync4, readFileSync as readFileSync8 } from "fs";
|
|
5895
|
-
import { dirname as
|
|
5953
|
+
import { dirname as dirname9, join as join16, resolve as resolve2, sep } from "path";
|
|
5896
5954
|
import { fileURLToPath } from "url";
|
|
5897
5955
|
import { Command as Command23 } from "commander";
|
|
5898
5956
|
var PACKAGE_NAME = "@pollinations/cli";
|
|
@@ -5900,13 +5958,13 @@ var REGISTRY_URL = "https://registry.npmjs.org/@pollinations%2Fcli/latest";
|
|
|
5900
5958
|
function findPackageRoot(fromDir) {
|
|
5901
5959
|
let dir = resolve2(fromDir);
|
|
5902
5960
|
while (!existsSync4(join16(dir, "package.json"))) {
|
|
5903
|
-
const parent =
|
|
5961
|
+
const parent = dirname9(dir);
|
|
5904
5962
|
if (parent === dir) throw new Error("could not locate package.json");
|
|
5905
5963
|
dir = parent;
|
|
5906
5964
|
}
|
|
5907
5965
|
return dir;
|
|
5908
5966
|
}
|
|
5909
|
-
var packageDir = findPackageRoot(
|
|
5967
|
+
var packageDir = findPackageRoot(dirname9(fileURLToPath(import.meta.url)));
|
|
5910
5968
|
var currentVersion = JSON.parse(readFileSync8(join16(packageDir, "package.json"), "utf-8")).version;
|
|
5911
5969
|
function detectInstallKind(dir, globalRoot) {
|
|
5912
5970
|
const resolvedDir = resolve2(dir);
|