@pollinations/cli 0.1.83 → 0.1.86
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 +14 -6
- 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.86",
|
|
18
18
|
description: "The Pollinations CLI \u2014 for humans, AI agents, and everything in between",
|
|
19
19
|
type: "module",
|
|
20
20
|
bin: {
|
|
@@ -644,14 +644,20 @@ import { Readable, Writable } from "stream";
|
|
|
644
644
|
import { Command as Command2 } from "commander";
|
|
645
645
|
|
|
646
646
|
// src/lib/stream.ts
|
|
647
|
+
function throwIfFailed(completion) {
|
|
648
|
+
const failed = completion.choices?.find(
|
|
649
|
+
(choice) => choice.finish_reason === "error"
|
|
650
|
+
);
|
|
651
|
+
const error = completion.error ?? failed?.error;
|
|
652
|
+
if (!error && !failed) return;
|
|
653
|
+
throw new Error(
|
|
654
|
+
error?.message ?? (error ? JSON.stringify(error) : "Completion failed")
|
|
655
|
+
);
|
|
656
|
+
}
|
|
647
657
|
async function* streamSSE(response, onEvent) {
|
|
648
658
|
for await (const event of sseEvents(response)) {
|
|
649
659
|
const parsed = event;
|
|
650
|
-
|
|
651
|
-
throw new Error(
|
|
652
|
-
parsed.error.message ?? JSON.stringify(parsed.error)
|
|
653
|
-
);
|
|
654
|
-
}
|
|
660
|
+
throwIfFailed(parsed);
|
|
655
661
|
onEvent?.(parsed);
|
|
656
662
|
const delta = parsed.choices?.[0]?.delta;
|
|
657
663
|
if (delta?.content) yield delta.content;
|
|
@@ -1858,6 +1864,7 @@ Chat session started (model: ${opts.model ?? "API default"})
|
|
|
1858
1864
|
}
|
|
1859
1865
|
if (isJson) {
|
|
1860
1866
|
const data = await res.json();
|
|
1867
|
+
throwIfFailed(data);
|
|
1861
1868
|
const message = data.choices[0]?.message;
|
|
1862
1869
|
const content2 = message?.content || message?.refusal || "";
|
|
1863
1870
|
messages.push({ role: "assistant", content: content2 });
|
|
@@ -2488,6 +2495,7 @@ ${stdinText}` : stdinText;
|
|
|
2488
2495
|
return;
|
|
2489
2496
|
}
|
|
2490
2497
|
const data = await res.json();
|
|
2498
|
+
throwIfFailed(data);
|
|
2491
2499
|
const message = data.choices[0]?.message;
|
|
2492
2500
|
const content = message?.content || message?.refusal || "";
|
|
2493
2501
|
warnIfTruncated(data.choices[0]?.finish_reason);
|