@pollinations/cli 0.1.28 → 0.1.30

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.28",
17
+ version: "0.1.30",
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 = doc.split(/^(?=#{1,6} )/m);
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 matches = sections.filter(
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(
@@ -1643,6 +1660,12 @@ ${stdinText}` : stdinText;
1643
1660
  if (opts.reasoning) body.reasoning_effort = opts.reasoning;
1644
1661
  if (useStream) body.stream = true;
1645
1662
  if (isHuman && !useStream) printInfo("Generating...");
1663
+ const warnIfTruncated = (reason) => {
1664
+ if (reason === "length")
1665
+ printWarn(
1666
+ "The model reached its output token limit; the response may be truncated."
1667
+ );
1668
+ };
1646
1669
  try {
1647
1670
  const res = await fetchGen("/v1/chat/completions", {
1648
1671
  method: "POST",
@@ -1656,15 +1679,19 @@ ${stdinText}` : stdinText;
1656
1679
  let content2 = "";
1657
1680
  let model = null;
1658
1681
  let tokens = null;
1682
+ let lengthTerminated = false;
1659
1683
  for await (const chunk of streamSSE(res, (event) => {
1660
1684
  if (typeof event.model === "string")
1661
1685
  model = event.model;
1662
1686
  if (typeof event.usage?.total_tokens === "number")
1663
1687
  tokens = event.usage.total_tokens;
1688
+ if (event.choices?.[0]?.finish_reason === "length")
1689
+ lengthTerminated = true;
1664
1690
  })) {
1665
1691
  content2 += chunk;
1666
1692
  if (isHuman) process.stdout.write(colorize(chunk));
1667
1693
  }
1694
+ if (lengthTerminated) warnIfTruncated("length");
1668
1695
  if (isHuman) process.stdout.write("\n");
1669
1696
  if (getOutputMode() === "json") {
1670
1697
  printResult({ content: content2, model, tokens });
@@ -1673,6 +1700,7 @@ ${stdinText}` : stdinText;
1673
1700
  }
1674
1701
  const data = await res.json();
1675
1702
  const content = data.choices[0]?.message?.content ?? "";
1703
+ warnIfTruncated(data.choices[0]?.finish_reason);
1676
1704
  if (opts.output) {
1677
1705
  writeFileSync7(opts.output, content, "utf-8");
1678
1706
  if (getOutputMode() === "json") {
@@ -6127,7 +6155,7 @@ var usageCommand = new Command25("usage").description(
6127
6155
  "Filter by model id (repeatable)",
6128
6156
  collect,
6129
6157
  []
6130
- ).option("--days <n>", "Rolling window in days").option("--csv", "Print the raw CSV export").addHelpText(
6158
+ ).option("--days <n>", "Rolling window in days (--daily defaults to 7)").option("--csv", "Print the raw CSV export").addHelpText(
6131
6159
  "after",
6132
6160
  chalk10.dim(
6133
6161
  '\nKey filter:\n --key <name-or-id> Filter by API key name or id (repeatable, resolves\n names via /account/keys). Placed after "usage" it filters;\n before "usage" it stays the global auth override.'
@@ -6192,7 +6220,8 @@ var usageCommand = new Command25("usage").description(
6192
6220
  }
6193
6221
  }
6194
6222
  const params = new URLSearchParams();
6195
- if (opts.days !== void 0) params.set("days", opts.days);
6223
+ const days = opts.days ?? (opts.daily ? "7" : void 0);
6224
+ if (days !== void 0) params.set("days", days);
6196
6225
  try {
6197
6226
  if (opts.daily) {
6198
6227
  if (opts.csv) {