@pollinations/cli 0.1.82 → 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 +21 -9
- 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);
|
|
@@ -6910,14 +6918,17 @@ var sandboxCommand = new Command23("sandbox").description("E2B sandboxes billed
|
|
|
6910
6918
|
async (template, { timeout }) => {
|
|
6911
6919
|
requireKey();
|
|
6912
6920
|
try {
|
|
6913
|
-
const { sandboxID } = await createSandbox(
|
|
6921
|
+
const { sandboxID, notice } = await createSandbox(
|
|
6914
6922
|
template,
|
|
6915
6923
|
timeout
|
|
6916
6924
|
);
|
|
6917
6925
|
try {
|
|
6918
6926
|
setupSsh();
|
|
6919
6927
|
} catch (err) {
|
|
6920
|
-
printResult({
|
|
6928
|
+
printResult({
|
|
6929
|
+
id: sandboxID,
|
|
6930
|
+
...notice && { notice }
|
|
6931
|
+
});
|
|
6921
6932
|
fail(
|
|
6922
6933
|
`Sandbox ${sandboxID} created, but failed to set up ssh`,
|
|
6923
6934
|
err
|
|
@@ -6928,7 +6939,8 @@ var sandboxCommand = new Command23("sandbox").description("E2B sandboxes billed
|
|
|
6928
6939
|
);
|
|
6929
6940
|
printResult({
|
|
6930
6941
|
id: sandboxID,
|
|
6931
|
-
ssh: `ssh ${sandboxID}.polli
|
|
6942
|
+
ssh: `ssh ${sandboxID}.polli`,
|
|
6943
|
+
...notice && { notice }
|
|
6932
6944
|
});
|
|
6933
6945
|
} catch (err) {
|
|
6934
6946
|
fail("Failed to create sandbox", err);
|