@pollinations/cli 0.1.10 → 0.1.12
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/README.md +35 -2
- package/SKILL.md +26 -2
- package/dist/index.js +1011 -82
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { readFileSync as
|
|
2
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
3
3
|
import chalk11 from "chalk";
|
|
4
|
-
import { Command as
|
|
4
|
+
import { Command as Command19 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/commands/agents.ts
|
|
7
7
|
import { readFileSync as readFileSync2 } from "fs";
|
|
@@ -426,21 +426,7 @@ async function fetchProfileLabel(key) {
|
|
|
426
426
|
if (!profile) return null;
|
|
427
427
|
return `Logged in as ${profile.githubUsername ?? "unknown"}`;
|
|
428
428
|
}
|
|
429
|
-
|
|
430
|
-
new Option(
|
|
431
|
-
"--token <key>",
|
|
432
|
-
"API key (pk_ or sk_) for direct auth"
|
|
433
|
-
).hideHelp()
|
|
434
|
-
).option("--with-token", "Read an existing API key from stdin").option("--no-browser", "Print URL instead of opening browser").action(async (opts) => {
|
|
435
|
-
if (opts.token) {
|
|
436
|
-
await authenticateWithKey(assertApiKey(opts.token));
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
if (opts.withToken) {
|
|
440
|
-
const key2 = assertApiKey(await readStdinToken());
|
|
441
|
-
await authenticateWithKey(key2);
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
429
|
+
async function loginWithDeviceFlow(opts = {}) {
|
|
444
430
|
printInfo("Requesting device code...");
|
|
445
431
|
const res = await fetch(`${ENTER_URL}/api/device/code`, {
|
|
446
432
|
method: "POST",
|
|
@@ -506,11 +492,27 @@ Your code: ${deviceResp.user_code}
|
|
|
506
492
|
if (label) {
|
|
507
493
|
printSuccess(label);
|
|
508
494
|
} else {
|
|
509
|
-
printInfo(
|
|
510
|
-
"Key stored. Could not fetch profile, but auth is complete."
|
|
511
|
-
);
|
|
495
|
+
printInfo("Key stored. Could not fetch profile, but auth is complete.");
|
|
512
496
|
}
|
|
513
497
|
printInfo(flavor.login);
|
|
498
|
+
return key;
|
|
499
|
+
}
|
|
500
|
+
var login = new Command2("login").description("Authenticate with Pollinations").addOption(
|
|
501
|
+
new Option(
|
|
502
|
+
"--token <key>",
|
|
503
|
+
"API key (pk_ or sk_) for direct auth"
|
|
504
|
+
).hideHelp()
|
|
505
|
+
).option("--with-token", "Read an existing API key from stdin").option("--no-browser", "Print URL instead of opening browser").action(async (opts) => {
|
|
506
|
+
if (opts.token) {
|
|
507
|
+
await authenticateWithKey(assertApiKey(opts.token));
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
if (opts.withToken) {
|
|
511
|
+
const key = assertApiKey(await readStdinToken());
|
|
512
|
+
await authenticateWithKey(key);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
await loginWithDeviceFlow({ browser: opts.browser });
|
|
514
516
|
});
|
|
515
517
|
var logout = new Command2("logout").description("Clear stored credentials").action(() => {
|
|
516
518
|
clearCredentials();
|
|
@@ -614,12 +616,71 @@ var docsCommand = new Command3("docs").description("Show Pollinations API docume
|
|
|
614
616
|
await open(url);
|
|
615
617
|
});
|
|
616
618
|
|
|
619
|
+
// src/commands/earnings.ts
|
|
620
|
+
import { Command as Command4 } from "commander";
|
|
621
|
+
var MAX_EARNINGS_DAYS = 90;
|
|
622
|
+
function parseDaysWindow(value) {
|
|
623
|
+
const days = Number(value);
|
|
624
|
+
if (!Number.isInteger(days) || days < 1) {
|
|
625
|
+
throw new Error("--days must be a positive integer");
|
|
626
|
+
}
|
|
627
|
+
if (days > MAX_EARNINGS_DAYS) {
|
|
628
|
+
throw new Error(`--days must be ${MAX_EARNINGS_DAYS} or less`);
|
|
629
|
+
}
|
|
630
|
+
return days;
|
|
631
|
+
}
|
|
632
|
+
function totalPollenEarned(perEntity) {
|
|
633
|
+
return perEntity.reduce((sum, row) => sum + row.pollen_earned, 0);
|
|
634
|
+
}
|
|
635
|
+
var earningsCommand = new Command4("earnings").description("Show developer earnings from BYOP apps and community models").option("--days <n>", "Rolling window in days, max 90", "30").action(async (opts) => {
|
|
636
|
+
const key = requireKey();
|
|
637
|
+
let days;
|
|
638
|
+
try {
|
|
639
|
+
days = parseDaysWindow(opts.days);
|
|
640
|
+
} catch (err) {
|
|
641
|
+
printError(
|
|
642
|
+
err instanceof Error ? err.message : "Invalid --days value"
|
|
643
|
+
);
|
|
644
|
+
process.exit(1);
|
|
645
|
+
}
|
|
646
|
+
try {
|
|
647
|
+
const data = await gen(
|
|
648
|
+
`/account/earnings?days=${days}`,
|
|
649
|
+
{ apiKey: key }
|
|
650
|
+
);
|
|
651
|
+
if (getOutputMode() !== "human") {
|
|
652
|
+
printResult({ daily: data.daily, perEntity: data.perEntity });
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
if (data.perEntity.length === 0) {
|
|
656
|
+
printInfo(`No earnings in the last ${days} days.`);
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
const total = totalPollenEarned(data.perEntity);
|
|
660
|
+
printResult({
|
|
661
|
+
total_pollen: total.toFixed(4),
|
|
662
|
+
window_days: days
|
|
663
|
+
});
|
|
664
|
+
printTable(
|
|
665
|
+
data.perEntity.map((row) => ({
|
|
666
|
+
entity: row.entity_name,
|
|
667
|
+
source: row.source,
|
|
668
|
+
requests: row.requests,
|
|
669
|
+
pollen: row.pollen_earned.toFixed(4),
|
|
670
|
+
volume: `$${row.cost_usd.toFixed(2)}`
|
|
671
|
+
}))
|
|
672
|
+
);
|
|
673
|
+
} catch (err) {
|
|
674
|
+
fail("Failed to fetch earnings", err);
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
|
|
617
678
|
// src/commands/gen/index.ts
|
|
618
|
-
import { Command as
|
|
679
|
+
import { Command as Command11 } from "commander";
|
|
619
680
|
|
|
620
681
|
// src/commands/gen/audio.ts
|
|
621
682
|
import { writeFileSync as writeFileSync2 } from "fs";
|
|
622
|
-
import { Command as
|
|
683
|
+
import { Command as Command5 } from "commander";
|
|
623
684
|
|
|
624
685
|
// src/lib/errors.ts
|
|
625
686
|
async function budgetHint(status2, bodyText) {
|
|
@@ -690,12 +751,12 @@ var findPlayer = () => {
|
|
|
690
751
|
var playAudio = async (filePath) => {
|
|
691
752
|
const player = findPlayer();
|
|
692
753
|
if (!player) return false;
|
|
693
|
-
return new Promise((
|
|
754
|
+
return new Promise((resolve4) => {
|
|
694
755
|
const child = spawn(player.cmd, player.args(filePath), {
|
|
695
756
|
stdio: "ignore"
|
|
696
757
|
});
|
|
697
|
-
child.on("error", () =>
|
|
698
|
-
child.on("exit", (code) =>
|
|
758
|
+
child.on("error", () => resolve4(false));
|
|
759
|
+
child.on("exit", (code) => resolve4(code === 0));
|
|
699
760
|
});
|
|
700
761
|
};
|
|
701
762
|
var playerMissingHint = () => {
|
|
@@ -719,7 +780,7 @@ async function readStdin() {
|
|
|
719
780
|
|
|
720
781
|
// src/commands/gen/audio.ts
|
|
721
782
|
function createAudioCommand() {
|
|
722
|
-
return new
|
|
783
|
+
return new Command5("audio").description(
|
|
723
784
|
"Generate speech or music from text (stdin ok). Discover voices: polli models --type audio --json | jq '.[].voices'"
|
|
724
785
|
).addHelpText(
|
|
725
786
|
"after",
|
|
@@ -773,7 +834,7 @@ Examples:
|
|
|
773
834
|
import { writeFileSync as writeFileSync3 } from "fs";
|
|
774
835
|
import { createInterface } from "readline";
|
|
775
836
|
import chalk4 from "chalk";
|
|
776
|
-
import { Command as
|
|
837
|
+
import { Command as Command6 } from "commander";
|
|
777
838
|
|
|
778
839
|
// src/lib/stream.ts
|
|
779
840
|
async function* streamSSE(response) {
|
|
@@ -810,7 +871,7 @@ async function* streamSSE(response) {
|
|
|
810
871
|
|
|
811
872
|
// src/commands/gen/chat.ts
|
|
812
873
|
function createChatCommand() {
|
|
813
|
-
return new
|
|
874
|
+
return new Command6("chat").description("Interactive multi-turn chat session").option(
|
|
814
875
|
"--model <model>",
|
|
815
876
|
"Text model (default: from config or 'openai')"
|
|
816
877
|
).option("--system <msg>", "System message").option("--temperature <n>", "Randomness (0-2)").option("--max-tokens <n>", "Maximum output tokens").option("--save <path>", "Save conversation transcript on exit").action(async (opts) => {
|
|
@@ -958,9 +1019,9 @@ Session ended. ${totalTokens} tokens used.
|
|
|
958
1019
|
|
|
959
1020
|
// src/commands/gen/image.ts
|
|
960
1021
|
import { writeFileSync as writeFileSync4 } from "fs";
|
|
961
|
-
import { Command as
|
|
1022
|
+
import { Command as Command7 } from "commander";
|
|
962
1023
|
function createImageCommand() {
|
|
963
|
-
return new
|
|
1024
|
+
return new Command7("image").description("Generate an image from a prompt").argument("<prompt>", "Image description").option("--model <model>", "Image model", "zimage").option("--width <n>", "Image width", "1024").option("--height <n>", "Image height", "1024").option("--seed <n>", "Random seed").option("--safe", "Enable safety filters").option("--transparent", "Transparent background (PNG)").option(
|
|
964
1025
|
"--image <url...>",
|
|
965
1026
|
"Reference image URL(s) for editing/i2i (repeatable)"
|
|
966
1027
|
).option("--output <path>", "Save to file", "image.png").action(async (prompt, opts) => {
|
|
@@ -1006,9 +1067,9 @@ function createImageCommand() {
|
|
|
1006
1067
|
// src/commands/gen/text.ts
|
|
1007
1068
|
import { writeFileSync as writeFileSync5 } from "fs";
|
|
1008
1069
|
import chalk5 from "chalk";
|
|
1009
|
-
import { Command as
|
|
1070
|
+
import { Command as Command8 } from "commander";
|
|
1010
1071
|
function createTextCommand() {
|
|
1011
|
-
return new
|
|
1072
|
+
return new Command8("text").description(
|
|
1012
1073
|
"Generate text from a prompt (also reads stdin: echo 'hello' | polli text)"
|
|
1013
1074
|
).argument("[prompt]", "Text prompt (or pipe via stdin)").option("--model <model>", "Text model").option("--system <msg>", "System message").option("--temperature <n>", "Randomness (0-2)").option("--max-tokens <n>", "Maximum output tokens").option("--top-p <n>", "Nucleus sampling (0-1)").option("--frequency-penalty <n>", "Repetition penalty (-2 to 2)").option("--presence-penalty <n>", "Topic penalty (-2 to 2)").option("--seed <n>", "Reproducibility seed").option("--json-response", "Force model to return JSON object").option(
|
|
1014
1075
|
"--reasoning <effort>",
|
|
@@ -1114,9 +1175,9 @@ ${stdinText}` : stdinText;
|
|
|
1114
1175
|
// src/commands/gen/transcribe.ts
|
|
1115
1176
|
import { readFileSync as readFileSync3 } from "fs";
|
|
1116
1177
|
import { basename } from "path";
|
|
1117
|
-
import { Command as
|
|
1178
|
+
import { Command as Command9 } from "commander";
|
|
1118
1179
|
function createTranscribeCommand() {
|
|
1119
|
-
return new
|
|
1180
|
+
return new Command9("transcribe").description("Transcribe audio to text (speech-to-text)").argument("<file>", "Audio file path (mp3, wav, etc.)").option(
|
|
1120
1181
|
"--model <model>",
|
|
1121
1182
|
"STT model (whisper, scribe, universal-2, universal-3.5-pro)",
|
|
1122
1183
|
"whisper"
|
|
@@ -1149,9 +1210,9 @@ function createTranscribeCommand() {
|
|
|
1149
1210
|
|
|
1150
1211
|
// src/commands/gen/video.ts
|
|
1151
1212
|
import { writeFileSync as writeFileSync6 } from "fs";
|
|
1152
|
-
import { Command as
|
|
1213
|
+
import { Command as Command10 } from "commander";
|
|
1153
1214
|
function createVideoCommand() {
|
|
1154
|
-
return new
|
|
1215
|
+
return new Command10("video").description("Generate a video from a prompt").argument("<prompt>", "Video description").option(
|
|
1155
1216
|
"--model <model>",
|
|
1156
1217
|
"Video model (default: from config or 'wan')"
|
|
1157
1218
|
).option("--width <n>", "Video width", "1024").option("--height <n>", "Video height", "1024").option("--duration <n>", "Duration in seconds (1-30)").option("--aspect-ratio <ratio>", "16:9 or 9:16").option("--audio", "Include AI soundtrack").option("--seed <n>", "Random seed").option("--image <url>", "Reference frame URL").option("--output <path>", "Save to file", "video.mp4").action(async (prompt, opts) => {
|
|
@@ -1195,13 +1256,847 @@ function createVideoCommand() {
|
|
|
1195
1256
|
|
|
1196
1257
|
// src/commands/gen/index.ts
|
|
1197
1258
|
function createGenCommand() {
|
|
1198
|
-
return new
|
|
1259
|
+
return new Command11("gen").description("Generate text, images, audio, video, and more").addCommand(createTextCommand()).addCommand(createImageCommand()).addCommand(createAudioCommand()).addCommand(createVideoCommand()).addCommand(createChatCommand()).addCommand(createTranscribeCommand());
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
// src/commands/harness.ts
|
|
1263
|
+
import { homedir as homedir2 } from "os";
|
|
1264
|
+
import { Command as Command12 } from "commander";
|
|
1265
|
+
|
|
1266
|
+
// src/harnesses/dsh.ts
|
|
1267
|
+
import { join as join4, resolve } from "path";
|
|
1268
|
+
import { parseEnv } from "util";
|
|
1269
|
+
import { isMap, isSeq, parseDocument, Scalar } from "yaml";
|
|
1270
|
+
|
|
1271
|
+
// SKILL.md?raw
|
|
1272
|
+
var SKILL_default = '---\nname: polli\ndescription: Generate images, text, audio, video, and transcribe speech via the Pollinations API using the polli CLI. Use when asked to generate media, call pollinations.ai, check pollen balance, list models, manage API keys, inspect quests, manage agents or my-models, or run polli commands.\nallowed-tools: Bash(polli *)\n---\n\n# polli \u2014 Pollinations CLI\n\nThin wrapper around `gen.pollinations.ai`. Generates images, text, audio, video; transcribes speech; manages API keys, usage, quests, agents, and invite-only my-models.\n\nIf `polli` is not installed, run `npm i -g @pollinations/cli@latest` (provides the `polli` binary).\n\n## When to use this skill\n\n- User asks to **generate an image / text / audio / video** via pollinations\n- User mentions **polli, pollinations, pollen, pollinations.ai**\n- User wants to **transcribe speech** or run TTS\n- User asks about their **pollen balance, usage, or API keys**\n- User wants to **browse or filter available models**\n- User wants to inspect **quests** or manage invite-only **my-models**\n- User wants to create or update a hosted prompt **agent**\n\n## Quick reference\n\n| Intent | Command |\n|---|---|\n| Log in once | `polli auth login` |\n| Store an existing key | `printf \'%s\' "$POLLINATIONS_API_KEY" \\| polli auth login --with-token` |\n| Generate image | `polli gen image "<prompt>" --output out.png` |\n| Generate text | `polli gen text "<prompt>"` |\n| Text with stdin as context | `echo "<ctx>" \\| polli gen text "<question>"` |\n| Describe an image (vision) | `polli gen text "what is this?" --image <url>` |\n| One-shot TTS | `polli gen audio "<text>" --output speech.mp3` |\n| Speak out loud | `polli gen audio "<text>" --play` (uses `afplay` on macOS; `ffplay`/`mpv`/`mpg123` on Linux) |\n| Generate video | `polli gen video "<prompt>" --output out.mp4` |\n| Transcribe audio | `polli gen transcribe path/to.mp3` |\n| Upload a local file | `polli upload path/to.png` (prints public URL) |\n| List all models | `polli models` |\n| Filter models by type | `polli models --type image` |\n| Model health + latency | `polli models --stats` (default 60m, `--window <min>`) |\n| Check balance | `polli usage` |\n| Developer earnings | `polli earnings` (`--days <n>`, max 90) |\n| List your quests + claim state | `polli quests` (filters: `--open --claimable --claimed --coming-soon`) |\n| Manage prompt agents | `polli agents list` |\n| Manage invite-only community models | `polli my-models list` |\n| Connect a coding harness to Pollinations | `polli harness <dsh\\|opencode\\|pi> on` (available adapters: `polli harness --help`) |\n| Machine-readable output | append `--json` to any command |\n\n## Setup\n\nOne-time: `polli auth login` (device-flow; creates a key with `profile`, `usage`, and `keys`). To store an existing key, run\n`printf \'%s\' "$POLLINATIONS_API_KEY" | polli auth login --with-token`. Verify\nwith `polli auth status`.\nOverride the stored key for a single command with `--key <key>`.\n\n## Recipes\n\n### Generate an image to a file\n```bash\npolli gen image "a fox reading a book, studio ghibli style" --output fox.png\n```\nDefaults: `zimage`, 1024x1024. Pick a different model with `--model flux` (see `polli models --type image`). For edits / img2img, pass one or more `--image <url>` flags \u2014 **must be public http(s) URLs**, local paths are rejected client-side. **Only models that list `"image"` in `input_modalities` actually consume the flag** \u2014 `flux` and `zimage` are text-only and will silently ignore `--image`. Find i2i-capable models with `polli models --type image --json | jq -r \'.[] | select(.input_modalities | contains(["image"])) | .name\'` (common choices: `nanobanana`, `kontext`, `p-image-edit`). To use a local file, upload it first with `polli upload` (see next recipe).\n\n### Upload a local file to get a public URL\n```bash\nURL=$(polli upload cat.png)\npolli gen image "make the cat purple" --image "$URL" --output purple.png\n```\n`polli upload <file>` posts a multipart upload to `media.pollinations.ai` (100MB max; 30-day lifecycle, refreshed by GETs once the object is at least 15 days old). Each upload receives a unique id. Human mode: URL on stdout and id/size/contentType on stderr. `--json`: full upload response on stdout. The returned URL is public (no auth to fetch) and works anywhere `--image` is accepted \u2014 `gen image`, `gen video`, etc.\n\n### Generate text\n```bash\npolli gen text "summarize the three laws of robotics"\n```\nSave to file: `--output summary.txt`. Use `--system "<msg>"` to set system prompt. For reasoning models, pass `--reasoning low|medium|high` to control reasoning effort. **Only send `--reasoning` to models where `reasoning: true`** in `polli models --type text --json` \u2014 the flag is not validated client-side, and non-reasoning models may silently accept it (openai), ignore it, or return a 400 (mistral).\n\n### Describe an image with a vision model\n```bash\nURL=$(polli upload selfie.jpg)\npolli gen text "turn this person into a cartoon pet in one playful sentence" --image "$URL"\n```\n`gen text --image <url...>` attaches one or more **public https URLs** as an OpenAI-style multimodal message \u2014 repeatable for multi-image prompts. Local paths aren\'t supported; run them through `polli upload` first (see the upload recipe above). **Only text models with `"image"` in `input_modalities` actually read the image** \u2014 filter with `polli models --type text --json | jq -r \'.[] | select(.input_modalities | index("image")) | .name\'`. Non-vision models silently ignore the attachment. Good defaults: `openai`, `gemini`, `claude`.\n\n### Pipe stdin as context into text generation\n```bash\ncat README.md | polli gen text "what does this project do?"\n```\nstdin becomes context; the positional argument is the question.\n\n### Interactive chat session\n```bash\npolli gen chat --model openai --system "you are a terse assistant"\n```\nSlash commands inside the session: `/exit`, `/clear`, `/save <path>`.\n\n### Text-to-speech\n```bash\npolli gen audio "hello world" --voice nova --output hello.mp3\necho "long script" | polli gen audio --voice nova --output out.mp3\n```\nDefault voice is `sage`. To discover the full live voice list, use the model registry: `polli models --type audio --json | jq -r \'.[].voices[]?\'` \u2014 each audio model entry includes its `voices[]` array. Format defaults to mp3; `--format opus|aac|flac|wav` to change. Accepts stdin (same as `gen text`). Add `--play` to save and then play the audio back (handy for narration/demos). Playback starts after the file is fully written, and the command blocks until playback finishes \u2014 if you want fire-and-forget, wrap in a subshell: `( polli gen audio "..." --play & )`. Player on macOS: `afplay`; on Linux it tries `ffplay`, then `mpv`, then `mpg123` in that order.\n\n### Generate music (elevenmusic)\n```bash\npolli gen audio "lofi hip-hop beat" --model elevenmusic --duration 30 --instrumental --output track.mp3\n```\n\n### Generate sound effects (eleven-sfx)\n```bash\npolli gen audio "thunderclap with heavy rain" --model eleven-sfx --duration 5 --output thunder.mp3\n```\nText-to-sound-effect via ElevenLabs (aliases: `sfx`, `sound-effects`). `--duration` 0.5\u201330s (omit to let the model pick). Billed per second of output (~$0.004/s, capped at $0.12 for a full 30s).\n\n### Multilingual TTS (eleven-multilingual-v2)\n```bash\npolli gen audio "Bonjour, ceci est un test" --model multilingual-v2 --voice rachel --output fr.mp3\n```\nStable, lifelike TTS across 29 languages (aliases: `multilingual-v2`, `eleven-v2`) \u2014 a non-alpha alternative to the default v3.\n\n### Generate video\n```bash\npolli gen video "a spacecraft landing on mars" --model wan-fast --duration 5 --output mars.mp4\n```\nCheapest path: `--model wan-fast` at ~$0.01/sec, **fixed 5-second output** (any `--duration` value is ignored \u2014 you always pay for and receive 5 sec). For image-to-video, pass `--image <url>` with a **public HTTPS URL** (local file paths and 404/rate-limited hosts will fail with a server error).\n\n**Flag support varies per model and is not enforced client-side.** `--duration`, `--aspect-ratio`, and `--audio` are forwarded to the server but may be silently ignored \u2014 verified on `wan-fast` where duration is locked to 5s, `--aspect-ratio 9:16` still returns 16:9, and `--audio` produces no audio track. Always inspect the output (`file`, `ffprobe`) before trusting a flag worked. Check `polli models --type video --json` for per-model capabilities.\n\n**Video is not tracked by `--stats`.** `polli models --type video --stats` returns empty \u2014 the stats pipe only records text/image/audio events. To compare video models, fall back to `polli models --type video --json` and look at price/description fields.\n\n### Transcribe audio to text\n```bash\npolli gen transcribe recording.mp3 --language en\n```\nModels: `whisper` (default), `scribe`, `universal-2`, `universal-3.5-pro`. Accepts common audio formats (mp3, wav, m4a, flac, ogg); non-audio input (e.g. a `.txt` file) returns a clear `400 invalid_request_error: extension "txt" not supported` \u2014 no need to pre-validate with `file`. Default output is the plain transcript on stdout as a single line (pipe-friendly). Use `--json` for structured output: **whisper** and **AssemblyAI** return timing data when requested through the API; **scribe** returns only `{text: "..."}` \u2014 use whisper or AssemblyAI if you need timing data. `--language <ISO-639-1>` (e.g. `en`, `fr`) is an optional hint that can improve accuracy for non-English or accented speech.\n\n### Discover models\n```bash\npolli models --type text # text models only\npolli models --type image --verbose # with context length / pricing\npolli models --stats # health + avg latency + err% (60m default)\npolli models --stats --window 5 # last 5 minutes only\n```\nUse `--stats` before choosing a model. **Caveat**: the `err%` column counts **5xx only** \u2014 a model can show `0.0%` while having massive 4xx rates (auth, validation, etc.). For the full picture use `--stats --json` and read `errors_4xx`, `errors_5xx`, `latency_p95_ms`.\n\n**Pricing fields are per-token, not per-request.** `completionImageTokens: 0.000008` means each output image-token costs that much \u2014 a single 1024x1024 image from `gptimage` lands at ~$0.008, not $0.000008. Flat-priced image models (`flux`, `zimage`) expose `completionImageTokens` as the whole-image price because they emit exactly one "token" per image. When in doubt, make one call and read the true cost from `polli usage --history --limit 5 --json`.\n\n### Check usage and balance\n```bash\npolli usage # current pollen balance\npolli usage --history # recent individual requests\npolli usage --daily # daily cost summary\npolli earnings # developer earnings total + per-entity breakdown (default 30d)\npolli earnings --days 7 # rolling window, max 90\npolli quests # your quests + claim state (open/claimable/claimed/coming)\npolli quests --claimable # only rewards ready to claim\n```\n**History is eventually consistent** \u2014 a request you just made may not appear for 30\u201360s. When matching costs to freshly-generated media, use `--limit 50` and filter by timestamp, and retry if the expected entry is missing. `polli usage --json` returns `{"pollen": <number>}` \u2014 the current balance only; use `--history --json` or `--daily --json` for cost breakdowns.\n\n### Manage my-models\n```bash\npolli my-models list\npolli my-models models --base-url https://api.example.com/v1 --bearer-token "$UPSTREAM_KEY"\npolli my-models create --name my-model --title "My Model" --base-url https://api.example.com/v1 --bearer-token "$UPSTREAM_KEY" --upstream-model gpt-4.1-mini\npolli my-models create --name my-image --title "My Image" --modality image --image-pricing request --completion-image-price 0.01 --base-url https://api.example.com/v1 --bearer-token "$UPSTREAM_KEY" --upstream-model flux\npolli my-models update <id> --description "Updated description"\npolli my-models update <id> --paid-only # only accept Paid Pollen; --no-paid-only reverts\npolli my-models delete <id>\n```\n`my-models` manages owned community text, image, and transcription models. Any account can create private models; `communityEndpointsAllowed: true` is required only to publish them. API keys require `account:keys`. Use `account:usage` for narrow read-only usage and `polli quests`; use both permissions when a client needs both read-only account state and admin operations. Quest claiming is dashboard-only; `polli quests` is read-only and account-aware.\n\n### Register an image my-model\n```bash\npolli my-models test --modality image --base-url https://api.example.com/v1 --bearer-token "$UPSTREAM_KEY" --model image-v1\npolli my-models create --name my-image --title "My Image" --modality image --image-pricing request --completion-image-price 0.01 --input-modalities text,image --base-url https://api.example.com/v1 --bearer-token "$UPSTREAM_KEY" --upstream-model image-v1\n```\nTest before creating. The probe reports the pricing mode it detected and the input modalities it found, including whether the endpoint accepts image edits; pass those back as `--input-modalities text,image` to advertise edit support. `polli my-models list` shows them in the `inputs` column.\n\nTwo billing modes: `--image-pricing request` charges `--completion-image-price` per generated image, while `--image-pricing tokens` bills returned token usage per 1M through `--prompt-text-price`, `--prompt-image-price`, and `--completion-image-price`.\n\nPrices only apply to `--visibility public` models. A private model is owner-only and always free, so every price flag above is stored as `0` until you publish \u2014 and making a published model private clears its prices again.\n\n`--modality` is fixed at creation \u2014 `update` cannot change it.\n\n### Manage agents\n\n```bash\npolli agents list\npolli agents get <id>\npolli agents create --config agent.json --name my-agent --title "My Agent"\npolli agents update <id> --config agent.json\npolli agents delete <id>\n```\nThe config file contains `systemPrompt`, `baseModel`, and optional `mcpServers`; create also requires `--name` and `--title` for the callable model listing. The only supported server ID is currently `"pollinations"`. Updates replace the complete agent configuration.\n\nCreating an agent also creates its callable model listing. Managed agents are text-only and free, with no fallbacks or per-user RPM. Deleting the agent also deletes its model listing. See [Publish an Agent](https://github.com/pollinations/pollinations/blob/main/BUILD_YOUR_OWN_AGENT.md).\n\n### Manage API keys\n```bash\npolli keys list # list all keys on the account\npolli keys info # details about the CURRENTLY AUTHENTICATED key only (takes no id)\npolli keys create --name "my-bot" --type secret --budget 1000 --permissions profile usage # scoped key\npolli keys create --name "my-app" --type publishable --redirect-uri https://app.example/callback --earnings\npolli keys revoke <id> # id comes from `keys list --json`\n```\n`--permissions <perms...>` scopes what the new key can do on the account (e.g. `profile usage` lets it call `polli --key <new> usage`). **Without `--permissions`, new scoped keys can generate media but cannot read account state** \u2014 `polli --key <new> usage` will 403. `"keys"` is auto-stripped from the list so a scoped key can never mint further keys. Existing keys with `account:keys` can manage my-models where that invite-only feature is enabled, but still need `account:usage` for read-only account state. Publishable app keys default developer earnings off; pass `--earnings` to enable them. To inspect a specific key other than the current one, use `polli keys list --json | jq \'.[] | select(.id == "<id>")\'`. `keys info` is intentionally scoped to the caller\'s own key.\n\n### Connect a coding harness\n```bash\npolli harness --help # supported harnesses\npolli harness dsh on # login if needed, mint key "polli-harness-dsh", write provider + default model\npolli harness dsh on --model kimi # any tool-calling text model from `polli models`\npolli harness dsh on --no-mcp # configure the provider and skill without MCP tools\npolli harness dsh off # restore the config backed up before "on"\npolli harness opencode on # enable the Pollinations OpenCode plugin\npolli harness opencode off # remove the plugin setup and stored key\npolli harness pi on # login if needed, mint key "polli-harness-pi", configure Pi with Pollinations\npolli harness pi on --model kimi # any tool-calling text model from `polli models`\npolli harness pi off # restore the Pi config backed up before "on"\n```\nEach adapter checks that its harness can be launched before login, key creation, or configuration. DSH\'s official launch uses `npx`, so its adapter checks for `npx`; OpenCode and Pi require their installed commands.\n\nThe DSH adapter globally configures the Pollinations provider, hosted Pollinations MCP, and this skill under `$DSH_HOME` (default `~/.dsh`). OpenCode enables the existing Pollinations plugin and stores its dedicated key in the plugin config. Pi writes `~/.pi/agent/models.json`, `auth.json`, and `settings.json`, and installs this skill under `~/.pi/agent/skills/polli/`. Guide: `polli docs` section "Coding Harnesses".\n\n### Read API docs\n```bash\npolli docs # full llm.txt reference\npolli docs /v1/chat/completions # filter to one endpoint\npolli docs --open # open in browser\n```\n\n## Output contract\n\n- **Default (human mode):** varies by command \u2014 most emit `key: value` pairs or tab-separated tables with a header row. Exceptions: `gen text` prints the full response to stdout; `gen transcribe` prints the transcript as plain text; `gen chat` runs an interactive REPL. Status/progress messages go to stderr, so pipes stay clean.\n- **`--json`:** every command emits machine-parseable JSON to stdout; all human messages go to stderr. **Always prefer `--json` when piping into `jq` or parsing** \u2014 it\'s the only shape with a stable contract.\n- **Exit codes:** 0 on success, non-zero on auth failure, rate limit, network error, or invalid args. Error messages go to stderr.\n\n## Agent operating rules\n\n1. **Run `polli auth status` first** if you don\'t know whether the user is logged in. Fail fast with a clear "run `polli auth login`" message if not.\n2. **Prefer `--json`** whenever you\'ll parse the output. Never grep human-formatted tables.\n3. **Don\'t hardcode model IDs.** Fetch the live list with `polli models --type <type>`. Model availability changes.\n4. **Before picking a model for production use, check `polli models --stats`.** Rule of thumb for "healthy": `err%` \u2264 5, `avg` latency in a reasonable range for the modality (standard text <5s, image <10s, video <60s), and `requests` high enough to be statistically meaningful (ignore rows with <10 requests \u2014 noise). **Filter by capability first, then optimize by health** \u2014 e.g. for a reasoning task, narrow to models where `reasoning: true` (via `polli models --type text --json`), *then* cross-reference against `--stats` output. The healthiest model overall may not support the capability you need. **Reasoning models are inherently slower \u2014 expect 5\u201350s, not <5s**; when picking among them, prioritize low `err%` and request count over raw latency, and compare latency only within the reasoning-capable subset.\n5. **Always pass `--output <path>`** for `gen image`, `gen audio`, `gen video` \u2014 otherwise the file lands in the current directory with a default name.\n6. **For stdin-as-context** on `gen text`, pipe the context and pass the question as the positional argument: `cat file | polli gen text "question about the file"`.\n7. **For exact flag lists, run `polli <cmd> --help` or `polli gen <cmd> --help`.** This skill\'s recipes cover the common path; the CLI\'s own help is always the source of truth.\n8. **Use `polli docs [endpoint]` over guessing API shapes.** It prints the canonical `llm.txt` reference from the live API.\n\n## Common pitfalls\n\n- Forgetting `--output` on binary generators (image/audio/video) \u2014 the file goes to a default path, which may not be what the user wants.\n- Using `polli gen text --json` expecting OpenAI chat-completions shape \u2014 the CLI\'s `--json` wraps its own structure. Use `polli docs /v1/chat/completions` to see the raw API shape if you need it.\n- Running commands without auth \u2014 `polli auth status` tells you who you\'re logged in as and your balance in one call.\n- **`gen text` streams to a TTY, buffers when piped.** The default now auto-detects \u2014 a human at the terminal sees tokens tick in, a pipe/redirect gets the full response once. Force either mode with `--stream` or `--no-stream`. For scripts and chains like `polli gen text \u2026 | polli gen audio \u2026`, you don\'t need to do anything; buffering happens automatically.\n- **Translating a `polli` workflow into a browser app.** `gen.pollinations.ai` requires a bearer token for generation requests, so a plain client-side `fetch` with no auth returns 401 unless it is served from cache. Mint a scoped key with `polli keys create` and proxy via your own backend.\n';
|
|
1273
|
+
|
|
1274
|
+
// src/harnesses/fs.ts
|
|
1275
|
+
import {
|
|
1276
|
+
accessSync,
|
|
1277
|
+
constants,
|
|
1278
|
+
existsSync as existsSync2,
|
|
1279
|
+
mkdirSync as mkdirSync2,
|
|
1280
|
+
readFileSync as readFileSync4,
|
|
1281
|
+
renameSync,
|
|
1282
|
+
statSync,
|
|
1283
|
+
unlinkSync as unlinkSync2,
|
|
1284
|
+
writeFileSync as writeFileSync7
|
|
1285
|
+
} from "fs";
|
|
1286
|
+
import { basename as basename2, delimiter, dirname, join as join2 } from "path";
|
|
1287
|
+
var isExecutable = (path) => {
|
|
1288
|
+
try {
|
|
1289
|
+
accessSync(path, constants.X_OK);
|
|
1290
|
+
return true;
|
|
1291
|
+
} catch {
|
|
1292
|
+
return false;
|
|
1293
|
+
}
|
|
1294
|
+
};
|
|
1295
|
+
var commandExists = (command, env, fallbacks = []) => {
|
|
1296
|
+
const extensions = process.platform === "win32" ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";") : [""];
|
|
1297
|
+
const candidates = (env.PATH ?? env.Path ?? "").split(delimiter).filter(Boolean).flatMap(
|
|
1298
|
+
(dir) => extensions.map((extension) => join2(dir, `${command}${extension}`))
|
|
1299
|
+
);
|
|
1300
|
+
return [...candidates, ...fallbacks].some(isExecutable);
|
|
1301
|
+
};
|
|
1302
|
+
var readTextIfExists = (path) => existsSync2(path) ? readFileSync4(path, "utf-8") : null;
|
|
1303
|
+
var writeTextAtomic = (path, text, mode) => {
|
|
1304
|
+
mkdirSync2(dirname(path), { recursive: true, mode: 448 });
|
|
1305
|
+
const fileMode = mode ?? (existsSync2(path) ? statSync(path).mode & 511 : 384);
|
|
1306
|
+
const tmp = join2(dirname(path), `.${basename2(path)}.${process.pid}.tmp`);
|
|
1307
|
+
writeFileSync7(tmp, text, { encoding: "utf-8", mode: fileMode });
|
|
1308
|
+
renameSync(tmp, path);
|
|
1309
|
+
};
|
|
1310
|
+
var removeIfExists = (path) => {
|
|
1311
|
+
if (existsSync2(path)) unlinkSync2(path);
|
|
1312
|
+
};
|
|
1313
|
+
|
|
1314
|
+
// src/harnesses/keys.ts
|
|
1315
|
+
var keyIsValid = async (key) => {
|
|
1316
|
+
try {
|
|
1317
|
+
const info2 = await gen("/account/key", {
|
|
1318
|
+
apiKey: key
|
|
1319
|
+
});
|
|
1320
|
+
return info2.valid === true;
|
|
1321
|
+
} catch (error) {
|
|
1322
|
+
if (error instanceof ApiError && error.status === 401) return false;
|
|
1323
|
+
throw error;
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
var resolveHarnessKey = async (harness, options) => {
|
|
1327
|
+
const existing = harness.existingKey;
|
|
1328
|
+
if (existing && await keyIsValid(existing)) {
|
|
1329
|
+
printInfo(
|
|
1330
|
+
`Reusing the Pollinations key already stored for ${harness.label}.`
|
|
1331
|
+
);
|
|
1332
|
+
return existing;
|
|
1333
|
+
}
|
|
1334
|
+
const accountKey = resolveApiKey() ?? await loginWithDeviceFlow({ browser: options.browser });
|
|
1335
|
+
const name = `polli-harness-${harness.id}`;
|
|
1336
|
+
const created = await gen("/account/keys", {
|
|
1337
|
+
method: "POST",
|
|
1338
|
+
apiKey: accountKey,
|
|
1339
|
+
body: {
|
|
1340
|
+
name,
|
|
1341
|
+
type: "secret",
|
|
1342
|
+
...harness.accountPermissions ? { accountPermissions: harness.accountPermissions } : {}
|
|
1343
|
+
}
|
|
1344
|
+
});
|
|
1345
|
+
printSuccess(`Created API key "${name}" for ${harness.label}.`);
|
|
1346
|
+
return created.key;
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1349
|
+
// src/harnesses/models.ts
|
|
1350
|
+
var fetchHarnessModels = async () => {
|
|
1351
|
+
const { data } = await gen("/v1/models");
|
|
1352
|
+
return data.filter(
|
|
1353
|
+
(m) => m.tools === true && m.output_modalities?.includes("text") && m.supported_endpoints?.includes("/v1/chat/completions") && m.context_length && !m.agent && !m.id.includes("/")
|
|
1354
|
+
).map((m) => ({
|
|
1355
|
+
id: m.id,
|
|
1356
|
+
contextWindow: m.context_length,
|
|
1357
|
+
input: (m.input_modalities ?? ["text"]).filter(
|
|
1358
|
+
(modality) => modality === "text" || modality === "image"
|
|
1359
|
+
)
|
|
1360
|
+
}));
|
|
1361
|
+
};
|
|
1362
|
+
|
|
1363
|
+
// src/harnesses/snapshot.ts
|
|
1364
|
+
import { createHash } from "crypto";
|
|
1365
|
+
import { join as join3 } from "path";
|
|
1366
|
+
var sha256 = (content) => createHash("sha256").update(content).digest("hex");
|
|
1367
|
+
var snapshotPath = (ctx, id, paths) => {
|
|
1368
|
+
const key = sha256(paths.join("\n")).slice(0, 12);
|
|
1369
|
+
return join3(ctx.home, ".pollinations", "harnesses", `${id}.${key}.json`);
|
|
1370
|
+
};
|
|
1371
|
+
var contentHash = (content) => content === null ? null : sha256(content);
|
|
1372
|
+
var writeSnapshot = (ctx, id, paths, snapshot) => writeTextAtomic(
|
|
1373
|
+
snapshotPath(ctx, id, paths),
|
|
1374
|
+
JSON.stringify(snapshot, null, 2),
|
|
1375
|
+
384
|
|
1376
|
+
);
|
|
1377
|
+
var captureFiles = (paths) => Object.fromEntries(
|
|
1378
|
+
paths.map((path) => [
|
|
1379
|
+
path,
|
|
1380
|
+
{ before: readTextIfExists(path), afterHash: null }
|
|
1381
|
+
])
|
|
1382
|
+
);
|
|
1383
|
+
var restoreFiles = (files4) => {
|
|
1384
|
+
for (const [path, file] of Object.entries(files4)) {
|
|
1385
|
+
if (file.before === null) removeIfExists(path);
|
|
1386
|
+
else writeTextAtomic(path, file.before);
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
var loadSnapshot = (ctx, id, paths) => {
|
|
1390
|
+
const text = readTextIfExists(snapshotPath(ctx, id, paths));
|
|
1391
|
+
if (!text) return null;
|
|
1392
|
+
return JSON.parse(text);
|
|
1393
|
+
};
|
|
1394
|
+
var applyWithSnapshot = (ctx, id, paths, apply) => {
|
|
1395
|
+
const existing = loadSnapshot(ctx, id, paths);
|
|
1396
|
+
const rollback = captureFiles(paths);
|
|
1397
|
+
const snapshot = existing ?? {
|
|
1398
|
+
complete: false,
|
|
1399
|
+
files: rollback
|
|
1400
|
+
};
|
|
1401
|
+
if (!existing) writeSnapshot(ctx, id, paths, snapshot);
|
|
1402
|
+
try {
|
|
1403
|
+
apply();
|
|
1404
|
+
} catch (error) {
|
|
1405
|
+
try {
|
|
1406
|
+
restoreFiles(rollback);
|
|
1407
|
+
if (!existing) clearSnapshot(ctx, id, paths);
|
|
1408
|
+
} catch (rollbackError) {
|
|
1409
|
+
throw new AggregateError(
|
|
1410
|
+
[error, rollbackError],
|
|
1411
|
+
"Harness setup failed and its config could not be restored"
|
|
1412
|
+
);
|
|
1413
|
+
}
|
|
1414
|
+
throw error;
|
|
1415
|
+
}
|
|
1416
|
+
for (const path of paths) {
|
|
1417
|
+
snapshot.files[path].afterHash = contentHash(readTextIfExists(path));
|
|
1418
|
+
}
|
|
1419
|
+
snapshot.complete = true;
|
|
1420
|
+
writeSnapshot(ctx, id, paths, snapshot);
|
|
1421
|
+
};
|
|
1422
|
+
var restoreSnapshot = (ctx, id, paths) => {
|
|
1423
|
+
const snapshot = loadSnapshot(ctx, id, paths);
|
|
1424
|
+
if (!snapshot) return "missing";
|
|
1425
|
+
if (!snapshot.complete) {
|
|
1426
|
+
restoreFiles(snapshot.files);
|
|
1427
|
+
removeIfExists(snapshotPath(ctx, id, paths));
|
|
1428
|
+
return "restored";
|
|
1429
|
+
}
|
|
1430
|
+
const entries = Object.entries(snapshot.files);
|
|
1431
|
+
if (entries.some(
|
|
1432
|
+
([path, file]) => contentHash(readTextIfExists(path)) !== file.afterHash
|
|
1433
|
+
)) {
|
|
1434
|
+
return "modified";
|
|
1435
|
+
}
|
|
1436
|
+
restoreFiles(snapshot.files);
|
|
1437
|
+
removeIfExists(snapshotPath(ctx, id, paths));
|
|
1438
|
+
return "restored";
|
|
1439
|
+
};
|
|
1440
|
+
var clearSnapshot = (ctx, id, paths) => removeIfExists(snapshotPath(ctx, id, paths));
|
|
1441
|
+
|
|
1442
|
+
// src/harnesses/dsh.ts
|
|
1443
|
+
var ID = "dsh";
|
|
1444
|
+
var LABEL = "DeepSeek Harness";
|
|
1445
|
+
var PROVIDER = "pollinations";
|
|
1446
|
+
var DEFAULT_MODEL = "deepseek";
|
|
1447
|
+
var KEY_ENV = "POLLI_DSH_API_KEY";
|
|
1448
|
+
var MCP_ID = "mcp-pollinations";
|
|
1449
|
+
var MCP_URL = `${BASE_URL}/mcp/pollinations`;
|
|
1450
|
+
var PROVIDER_PATH = ["llm-pi-ai", "providers", PROVIDER];
|
|
1451
|
+
var DEFAULT_MODEL_PATH = ["agent-default-model"];
|
|
1452
|
+
var YAML_OUT = { lineWidth: 0 };
|
|
1453
|
+
var JS_TAG = {
|
|
1454
|
+
tag: "tag:yaml.org,2002:js",
|
|
1455
|
+
resolve: (value) => value
|
|
1456
|
+
};
|
|
1457
|
+
var dshHome = (ctx) => {
|
|
1458
|
+
const configured = ctx.env.DSH_HOME;
|
|
1459
|
+
if (!configured?.trim()) return join4(ctx.home, ".dsh");
|
|
1460
|
+
const expanded = configured === "~" ? ctx.home : configured.startsWith("~/") || configured.startsWith("~\\") ? join4(ctx.home, configured.slice(2)) : configured;
|
|
1461
|
+
return resolve(expanded);
|
|
1462
|
+
};
|
|
1463
|
+
var settingsPath = (ctx) => join4(dshHome(ctx), "settings.yaml");
|
|
1464
|
+
var envPath = (ctx) => join4(dshHome(ctx), ".env");
|
|
1465
|
+
var patchPath = (ctx) => join4(dshHome(ctx), "cordis.patch.yml");
|
|
1466
|
+
var skillPath = (ctx) => join4(dshHome(ctx), "skills", "polli", "SKILL.md");
|
|
1467
|
+
var loadYaml = (path) => parseDocument(readTextIfExists(path) ?? "", { customTags: [JS_TAG] });
|
|
1468
|
+
var files = (ctx) => [
|
|
1469
|
+
settingsPath(ctx),
|
|
1470
|
+
envPath(ctx),
|
|
1471
|
+
patchPath(ctx),
|
|
1472
|
+
skillPath(ctx)
|
|
1473
|
+
];
|
|
1474
|
+
var readKey = (ctx) => {
|
|
1475
|
+
const text = readTextIfExists(envPath(ctx));
|
|
1476
|
+
if (text === null) return null;
|
|
1477
|
+
const key = parseEnv(text)[KEY_ENV];
|
|
1478
|
+
return key || null;
|
|
1479
|
+
};
|
|
1480
|
+
var envLine = (key) => `${KEY_ENV}=${JSON.stringify(key)}`;
|
|
1481
|
+
var keyLine = new RegExp(`^\\s*(?:export\\s+)?${KEY_ENV}\\s*=`, "u");
|
|
1482
|
+
var setEnvKey = (ctx, key) => {
|
|
1483
|
+
const lines = (readTextIfExists(envPath(ctx)) ?? "").split("\n");
|
|
1484
|
+
const index = lines.findIndex((line) => keyLine.test(line));
|
|
1485
|
+
const filtered = lines.filter(
|
|
1486
|
+
(line, i) => i === index || !keyLine.test(line)
|
|
1487
|
+
);
|
|
1488
|
+
if (index === -1) {
|
|
1489
|
+
const insertAt = filtered.at(-1) === "" ? filtered.length - 1 : filtered.length;
|
|
1490
|
+
filtered.splice(insertAt, 0, envLine(key));
|
|
1491
|
+
} else filtered[index] = envLine(key);
|
|
1492
|
+
writeTextAtomic(envPath(ctx), filtered.join("\n"), 384);
|
|
1493
|
+
};
|
|
1494
|
+
var deleteEnvKey = (ctx) => {
|
|
1495
|
+
const text = readTextIfExists(envPath(ctx));
|
|
1496
|
+
if (text === null) return false;
|
|
1497
|
+
const lines = text.split("\n");
|
|
1498
|
+
const filtered = lines.filter((line) => !keyLine.test(line));
|
|
1499
|
+
if (filtered.length === lines.length) return false;
|
|
1500
|
+
writeTextAtomic(envPath(ctx), filtered.join("\n"), 384);
|
|
1501
|
+
return true;
|
|
1502
|
+
};
|
|
1503
|
+
var stripMcpEntry = (doc) => {
|
|
1504
|
+
if (!isSeq(doc.contents)) return false;
|
|
1505
|
+
let changed = false;
|
|
1506
|
+
for (let i = doc.contents.items.length - 1; i >= 0; i--) {
|
|
1507
|
+
const patch = doc.contents.items[i];
|
|
1508
|
+
if (!isMap(patch)) continue;
|
|
1509
|
+
const inserted = patch.get("insert", true);
|
|
1510
|
+
if (!isSeq(inserted)) continue;
|
|
1511
|
+
const before = inserted.items.length;
|
|
1512
|
+
inserted.items = inserted.items.filter(
|
|
1513
|
+
(entry) => !isMap(entry) || entry.get("id") !== MCP_ID
|
|
1514
|
+
);
|
|
1515
|
+
changed ||= inserted.items.length !== before;
|
|
1516
|
+
if (inserted.items.length === 0 && patch.items.length === 1) {
|
|
1517
|
+
doc.contents.items.splice(i, 1);
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
return changed;
|
|
1521
|
+
};
|
|
1522
|
+
var removeMcpEntry = (ctx) => {
|
|
1523
|
+
const doc = loadYaml(patchPath(ctx));
|
|
1524
|
+
if (!stripMcpEntry(doc)) return false;
|
|
1525
|
+
writeTextAtomic(patchPath(ctx), doc.toString(YAML_OUT), 384);
|
|
1526
|
+
return true;
|
|
1527
|
+
};
|
|
1528
|
+
var writeMcpEntry = (ctx) => {
|
|
1529
|
+
const doc = loadYaml(patchPath(ctx));
|
|
1530
|
+
if (doc.contents === null) doc.contents = doc.createNode([]);
|
|
1531
|
+
if (!isSeq(doc.contents)) {
|
|
1532
|
+
throw new Error(`${patchPath(ctx)} must contain a YAML list`);
|
|
1533
|
+
}
|
|
1534
|
+
stripMcpEntry(doc);
|
|
1535
|
+
const authorization = doc.createNode(
|
|
1536
|
+
`\`Bearer \${process.env.${KEY_ENV}}\``
|
|
1537
|
+
);
|
|
1538
|
+
authorization.tag = "tag:yaml.org,2002:js";
|
|
1539
|
+
authorization.type = Scalar.QUOTE_SINGLE;
|
|
1540
|
+
doc.add({
|
|
1541
|
+
insert: [
|
|
1542
|
+
{
|
|
1543
|
+
id: MCP_ID,
|
|
1544
|
+
name: "@deepseek-ai/dsh-mcp-client",
|
|
1545
|
+
config: {
|
|
1546
|
+
serverName: "pollinations",
|
|
1547
|
+
transport: "streamable-http",
|
|
1548
|
+
url: MCP_URL,
|
|
1549
|
+
headers: { Authorization: authorization }
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
]
|
|
1553
|
+
});
|
|
1554
|
+
writeTextAtomic(patchPath(ctx), doc.toString(YAML_OUT), 384);
|
|
1555
|
+
};
|
|
1556
|
+
var hasMcpEntry = (ctx) => {
|
|
1557
|
+
const doc = loadYaml(patchPath(ctx));
|
|
1558
|
+
if (!isSeq(doc.contents)) return false;
|
|
1559
|
+
return doc.contents.items.some((patch) => {
|
|
1560
|
+
if (!isMap(patch)) return false;
|
|
1561
|
+
const inserted = patch.get("insert", true);
|
|
1562
|
+
return isSeq(inserted) && inserted.items.some(
|
|
1563
|
+
(entry) => isMap(entry) && entry.get("id") === MCP_ID && entry.getIn(["config", "url"]) === MCP_URL
|
|
1564
|
+
);
|
|
1565
|
+
});
|
|
1566
|
+
};
|
|
1567
|
+
var providerConfig = (models2) => ({
|
|
1568
|
+
displayName: "Pollinations.ai",
|
|
1569
|
+
apiKeyEnv: KEY_ENV,
|
|
1570
|
+
api: "openai-completions",
|
|
1571
|
+
baseURL: `${BASE_URL}/v1`,
|
|
1572
|
+
compat: {
|
|
1573
|
+
supportsStore: false,
|
|
1574
|
+
supportsDeveloperRole: false,
|
|
1575
|
+
supportsReasoningEffort: true,
|
|
1576
|
+
supportsUsageInStreaming: true,
|
|
1577
|
+
supportsStrictMode: false,
|
|
1578
|
+
maxTokensField: "max_tokens"
|
|
1579
|
+
},
|
|
1580
|
+
models: models2.map((model) => ({
|
|
1581
|
+
id: model.id,
|
|
1582
|
+
name: model.id,
|
|
1583
|
+
contextWindow: model.contextWindow,
|
|
1584
|
+
input: model.input,
|
|
1585
|
+
reasoningEfforts: false
|
|
1586
|
+
}))
|
|
1587
|
+
});
|
|
1588
|
+
var writeConfig = (ctx, settings) => {
|
|
1589
|
+
const doc = loadYaml(settingsPath(ctx));
|
|
1590
|
+
doc.setIn(PROVIDER_PATH, doc.createNode(providerConfig(settings.models)));
|
|
1591
|
+
doc.setIn(
|
|
1592
|
+
DEFAULT_MODEL_PATH,
|
|
1593
|
+
doc.createNode({ provider: PROVIDER, model: settings.model })
|
|
1594
|
+
);
|
|
1595
|
+
writeTextAtomic(settingsPath(ctx), doc.toString(YAML_OUT), 384);
|
|
1596
|
+
setEnvKey(ctx, settings.apiKey);
|
|
1597
|
+
if (settings.mcp === false) removeMcpEntry(ctx);
|
|
1598
|
+
else writeMcpEntry(ctx);
|
|
1599
|
+
if (readTextIfExists(skillPath(ctx)) === null) {
|
|
1600
|
+
writeTextAtomic(skillPath(ctx), SKILL_default, 384);
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
var stripConfig = (ctx) => {
|
|
1604
|
+
const doc = loadYaml(settingsPath(ctx));
|
|
1605
|
+
let changed = false;
|
|
1606
|
+
if (doc.hasIn(PROVIDER_PATH)) {
|
|
1607
|
+
doc.deleteIn(PROVIDER_PATH);
|
|
1608
|
+
changed = true;
|
|
1609
|
+
}
|
|
1610
|
+
if (doc.getIn([...DEFAULT_MODEL_PATH, "provider"]) === PROVIDER) {
|
|
1611
|
+
doc.deleteIn(DEFAULT_MODEL_PATH);
|
|
1612
|
+
changed = true;
|
|
1613
|
+
}
|
|
1614
|
+
if (changed)
|
|
1615
|
+
writeTextAtomic(settingsPath(ctx), doc.toString(YAML_OUT), 384);
|
|
1616
|
+
changed = deleteEnvKey(ctx) || changed;
|
|
1617
|
+
changed = removeMcpEntry(ctx) || changed;
|
|
1618
|
+
if (readTextIfExists(skillPath(ctx)) === SKILL_default) {
|
|
1619
|
+
removeIfExists(skillPath(ctx));
|
|
1620
|
+
changed = true;
|
|
1621
|
+
}
|
|
1622
|
+
return changed;
|
|
1623
|
+
};
|
|
1624
|
+
var result = (ctx) => {
|
|
1625
|
+
const doc = loadYaml(settingsPath(ctx));
|
|
1626
|
+
const model = doc.getIn([...DEFAULT_MODEL_PATH, "model"]);
|
|
1627
|
+
return {
|
|
1628
|
+
harness: ID,
|
|
1629
|
+
label: LABEL,
|
|
1630
|
+
configured: doc.getIn([...PROVIDER_PATH, "apiKeyEnv"]) === KEY_ENV && doc.getIn([...PROVIDER_PATH, "api"]) === "openai-completions" && doc.getIn([...PROVIDER_PATH, "baseURL"]) === `${BASE_URL}/v1` && doc.getIn([...DEFAULT_MODEL_PATH, "provider"]) === PROVIDER && typeof model === "string" && readKey(ctx) !== null && readTextIfExists(skillPath(ctx)) !== null,
|
|
1631
|
+
model: typeof model === "string" ? model : void 0,
|
|
1632
|
+
mcp: hasMcpEntry(ctx),
|
|
1633
|
+
files: files(ctx)
|
|
1634
|
+
};
|
|
1635
|
+
};
|
|
1636
|
+
var configureDsh = (ctx, settings) => {
|
|
1637
|
+
applyWithSnapshot(ctx, ID, files(ctx), () => writeConfig(ctx, settings));
|
|
1638
|
+
return result(ctx);
|
|
1639
|
+
};
|
|
1640
|
+
var disableDsh = (ctx) => {
|
|
1641
|
+
const managedFiles = files(ctx);
|
|
1642
|
+
let outcome = "restored";
|
|
1643
|
+
if (restoreSnapshot(ctx, ID, managedFiles) !== "restored") {
|
|
1644
|
+
outcome = stripConfig(ctx) ? "stripped" : "unchanged";
|
|
1645
|
+
clearSnapshot(ctx, ID, managedFiles);
|
|
1646
|
+
}
|
|
1647
|
+
return { ...result(ctx), configured: false, outcome };
|
|
1648
|
+
};
|
|
1649
|
+
var dsh = {
|
|
1650
|
+
id: ID,
|
|
1651
|
+
label: LABEL,
|
|
1652
|
+
description: "Configure DeepSeek Harness as a Pollinations provider",
|
|
1653
|
+
restartHint: "Changes apply on the next request. Start DeepSeek Harness with: npx @deepseek-ai/dsh web",
|
|
1654
|
+
async on(ctx, options) {
|
|
1655
|
+
if (!commandExists("npx", ctx.env)) {
|
|
1656
|
+
throw new Error(
|
|
1657
|
+
"DeepSeek Harness requires npx. Install Node.js, then run: npx @deepseek-ai/dsh web"
|
|
1658
|
+
);
|
|
1659
|
+
}
|
|
1660
|
+
const model = options.model ?? DEFAULT_MODEL;
|
|
1661
|
+
const models2 = await fetchHarnessModels();
|
|
1662
|
+
if (!models2.some((candidate) => candidate.id === model)) {
|
|
1663
|
+
throw new Error(
|
|
1664
|
+
`Model "${model}" is not a tool-calling text model. Run: polli models`
|
|
1665
|
+
);
|
|
1666
|
+
}
|
|
1667
|
+
const apiKey = await resolveHarnessKey(
|
|
1668
|
+
{ id: ID, label: LABEL, existingKey: readKey(ctx) },
|
|
1669
|
+
{ browser: options.browser }
|
|
1670
|
+
);
|
|
1671
|
+
return configureDsh(ctx, {
|
|
1672
|
+
apiKey,
|
|
1673
|
+
model,
|
|
1674
|
+
models: models2,
|
|
1675
|
+
mcp: options.mcp
|
|
1676
|
+
});
|
|
1677
|
+
},
|
|
1678
|
+
off: disableDsh,
|
|
1679
|
+
status: result
|
|
1680
|
+
};
|
|
1681
|
+
|
|
1682
|
+
// src/harnesses/opencode.ts
|
|
1683
|
+
import { join as join5, resolve as resolve2 } from "path";
|
|
1684
|
+
var ID2 = "opencode";
|
|
1685
|
+
var LABEL2 = "OpenCode";
|
|
1686
|
+
var DEFAULT_MODEL2 = "openai";
|
|
1687
|
+
var PLUGIN_SPEC = "opencode-pollinations-plugin";
|
|
1688
|
+
var pollinationsConfigDir = (ctx) => {
|
|
1689
|
+
if (process.platform === "win32") {
|
|
1690
|
+
return join5(ctx.env.APPDATA ?? ctx.home, "pollinations");
|
|
1691
|
+
}
|
|
1692
|
+
if (process.platform === "darwin") {
|
|
1693
|
+
return join5(ctx.home, "Library", "Application Support", "pollinations");
|
|
1694
|
+
}
|
|
1695
|
+
const xdg = ctx.env.XDG_CONFIG_HOME?.trim();
|
|
1696
|
+
return join5(
|
|
1697
|
+
xdg ? resolve2(expandTilde(ctx, xdg)) : join5(ctx.home, ".config"),
|
|
1698
|
+
"pollinations"
|
|
1699
|
+
);
|
|
1700
|
+
};
|
|
1701
|
+
var expandTilde = (ctx, path) => path === "~" ? ctx.home : path.startsWith("~/") || path.startsWith("~\\") ? join5(ctx.home, path.slice(2)) : path;
|
|
1702
|
+
var opencodeConfigFile = (ctx) => {
|
|
1703
|
+
if (ctx.env.OPENCODE_CONFIG?.trim()) {
|
|
1704
|
+
return resolve2(expandTilde(ctx, ctx.env.OPENCODE_CONFIG));
|
|
1705
|
+
}
|
|
1706
|
+
const dir = ctx.env.OPENCODE_CONFIG_DIR?.trim() ? resolve2(expandTilde(ctx, ctx.env.OPENCODE_CONFIG_DIR)) : join5(ctx.home, ".config", "opencode");
|
|
1707
|
+
return join5(dir, "opencode.json");
|
|
1708
|
+
};
|
|
1709
|
+
var pluginConfigFile = (ctx) => join5(pollinationsConfigDir(ctx), "config.json");
|
|
1710
|
+
var files2 = (ctx) => [
|
|
1711
|
+
opencodeConfigFile(ctx),
|
|
1712
|
+
pluginConfigFile(ctx)
|
|
1713
|
+
];
|
|
1714
|
+
var readJson = (path) => {
|
|
1715
|
+
const text = readTextIfExists(path);
|
|
1716
|
+
if (text === null) return null;
|
|
1717
|
+
try {
|
|
1718
|
+
const parsed = JSON.parse(text);
|
|
1719
|
+
return parsed && typeof parsed === "object" ? parsed : null;
|
|
1720
|
+
} catch {
|
|
1721
|
+
return null;
|
|
1722
|
+
}
|
|
1723
|
+
};
|
|
1724
|
+
var writeJson = (ctx, path, data) => writeTextAtomic(path, `${JSON.stringify(data, null, 2)}
|
|
1725
|
+
`, 384);
|
|
1726
|
+
var isPluginEntry = (entry) => typeof entry === "string" ? entry === PLUGIN_SPEC || entry.includes(PLUGIN_SPEC) : entry !== null && typeof entry === "object" && Object.values(entry).some(
|
|
1727
|
+
(value) => typeof value === "string" && value.includes(PLUGIN_SPEC)
|
|
1728
|
+
);
|
|
1729
|
+
var pluginListKey = (config) => Array.isArray(config.plugins) && !Array.isArray(config.plugin) ? "plugins" : "plugin";
|
|
1730
|
+
var hasPluginEntry = (config) => {
|
|
1731
|
+
const entries = config[pluginListKey(config)];
|
|
1732
|
+
return Array.isArray(entries) && entries.some(isPluginEntry);
|
|
1733
|
+
};
|
|
1734
|
+
var readApiKey = (ctx) => {
|
|
1735
|
+
const key = (readJson(pluginConfigFile(ctx)) ?? {}).apiKey;
|
|
1736
|
+
return typeof key === "string" && key.length > 5 ? key : null;
|
|
1737
|
+
};
|
|
1738
|
+
var writeApiKey = (ctx, apiKey) => {
|
|
1739
|
+
const config = readJson(pluginConfigFile(ctx)) ?? {};
|
|
1740
|
+
config.apiKey = apiKey;
|
|
1741
|
+
writeJson(ctx, pluginConfigFile(ctx), config);
|
|
1742
|
+
};
|
|
1743
|
+
var deleteApiKey = (ctx) => {
|
|
1744
|
+
const path = pluginConfigFile(ctx);
|
|
1745
|
+
const config = readJson(path);
|
|
1746
|
+
if (config === null || config.apiKey === void 0) return false;
|
|
1747
|
+
delete config.apiKey;
|
|
1748
|
+
if (Object.keys(config).length === 0) removeIfExists(path);
|
|
1749
|
+
else writeJson(ctx, path, config);
|
|
1750
|
+
return true;
|
|
1751
|
+
};
|
|
1752
|
+
var openCodeConfig = (ctx) => readJson(opencodeConfigFile(ctx)) ?? {};
|
|
1753
|
+
var defaultModelRef = (model) => `pollinations/enter/${model}`;
|
|
1754
|
+
var isOurDefaultModel = (model) => typeof model === "string" && model.startsWith("pollinations/enter/");
|
|
1755
|
+
var writeOpenCodeConfig = (ctx, model) => {
|
|
1756
|
+
const config = openCodeConfig(ctx);
|
|
1757
|
+
if (typeof config.$schema !== "string") {
|
|
1758
|
+
config.$schema = "https://opencode.ai/config.json";
|
|
1759
|
+
}
|
|
1760
|
+
if (!hasPluginEntry(config)) {
|
|
1761
|
+
const key = pluginListKey(config);
|
|
1762
|
+
const entries = Array.isArray(config[key]) ? config[key] : [];
|
|
1763
|
+
config[key] = [...entries, PLUGIN_SPEC];
|
|
1764
|
+
}
|
|
1765
|
+
config.model = defaultModelRef(model);
|
|
1766
|
+
writeJson(ctx, opencodeConfigFile(ctx), config);
|
|
1767
|
+
};
|
|
1768
|
+
var stripOpenCodeConfig = (ctx) => {
|
|
1769
|
+
const path = opencodeConfigFile(ctx);
|
|
1770
|
+
const config = readJson(path);
|
|
1771
|
+
if (config === null) return false;
|
|
1772
|
+
let changed = false;
|
|
1773
|
+
const key = pluginListKey(config);
|
|
1774
|
+
const entries = config[key];
|
|
1775
|
+
if (Array.isArray(entries) && entries.some(isPluginEntry)) {
|
|
1776
|
+
const filtered = entries.filter((entry) => !isPluginEntry(entry));
|
|
1777
|
+
if (filtered.length === 0) delete config[key];
|
|
1778
|
+
else config[key] = filtered;
|
|
1779
|
+
changed = true;
|
|
1780
|
+
}
|
|
1781
|
+
if (isOurDefaultModel(config.model)) {
|
|
1782
|
+
delete config.model;
|
|
1783
|
+
changed = true;
|
|
1784
|
+
}
|
|
1785
|
+
if (changed) writeJson(ctx, path, config);
|
|
1786
|
+
return changed;
|
|
1787
|
+
};
|
|
1788
|
+
var result2 = (ctx) => {
|
|
1789
|
+
const config = openCodeConfig(ctx);
|
|
1790
|
+
const model = isOurDefaultModel(config.model) ? config.model.slice("pollinations/enter/".length) : void 0;
|
|
1791
|
+
return {
|
|
1792
|
+
harness: ID2,
|
|
1793
|
+
label: LABEL2,
|
|
1794
|
+
configured: hasPluginEntry(config) && isOurDefaultModel(config.model) && readApiKey(ctx) !== null,
|
|
1795
|
+
model,
|
|
1796
|
+
files: files2(ctx)
|
|
1797
|
+
};
|
|
1798
|
+
};
|
|
1799
|
+
var writeConfig2 = (ctx, settings) => {
|
|
1800
|
+
writeOpenCodeConfig(ctx, settings.model);
|
|
1801
|
+
writeApiKey(ctx, settings.apiKey);
|
|
1802
|
+
};
|
|
1803
|
+
var stripConfig2 = (ctx) => {
|
|
1804
|
+
let changed = stripOpenCodeConfig(ctx);
|
|
1805
|
+
changed = deleteApiKey(ctx) || changed;
|
|
1806
|
+
return changed;
|
|
1807
|
+
};
|
|
1808
|
+
var configureOpenCode = (ctx, settings) => {
|
|
1809
|
+
applyWithSnapshot(ctx, ID2, files2(ctx), () => writeConfig2(ctx, settings));
|
|
1810
|
+
return result2(ctx);
|
|
1811
|
+
};
|
|
1812
|
+
var disableOpenCode = (ctx) => {
|
|
1813
|
+
const managedFiles = files2(ctx);
|
|
1814
|
+
let outcome = "restored";
|
|
1815
|
+
if (restoreSnapshot(ctx, ID2, managedFiles) !== "restored") {
|
|
1816
|
+
outcome = stripConfig2(ctx) ? "stripped" : "unchanged";
|
|
1817
|
+
clearSnapshot(ctx, ID2, managedFiles);
|
|
1818
|
+
}
|
|
1819
|
+
return { ...result2(ctx), configured: false, outcome };
|
|
1820
|
+
};
|
|
1821
|
+
var openCodeInstalled = (ctx) => commandExists("opencode", ctx.env, [
|
|
1822
|
+
join5(ctx.home, ".opencode", "bin", "opencode")
|
|
1823
|
+
]);
|
|
1824
|
+
var opencode = {
|
|
1825
|
+
id: ID2,
|
|
1826
|
+
label: LABEL2,
|
|
1827
|
+
description: "Configure OpenCode to use Pollinations",
|
|
1828
|
+
restartHint: "Restart OpenCode, then pick a Pollinations model with /models. Inside OpenCode: /poll quests shows claimable Pollen, /poll help lists the media tools.",
|
|
1829
|
+
async on(ctx, options) {
|
|
1830
|
+
if (!openCodeInstalled(ctx)) {
|
|
1831
|
+
throw new Error(
|
|
1832
|
+
"OpenCode was not found. Install it first: curl -fsSL https://opencode.ai/install | bash"
|
|
1833
|
+
);
|
|
1834
|
+
}
|
|
1835
|
+
const model = options.model ?? DEFAULT_MODEL2;
|
|
1836
|
+
const models2 = await fetchHarnessModels();
|
|
1837
|
+
if (!models2.some((candidate) => candidate.id === model)) {
|
|
1838
|
+
throw new Error(
|
|
1839
|
+
`Model "${model}" is not a tool-calling text model. Run: polli models`
|
|
1840
|
+
);
|
|
1841
|
+
}
|
|
1842
|
+
const apiKey = await resolveHarnessKey(
|
|
1843
|
+
{
|
|
1844
|
+
id: ID2,
|
|
1845
|
+
label: LABEL2,
|
|
1846
|
+
existingKey: readApiKey(ctx),
|
|
1847
|
+
accountPermissions: ["profile", "usage"]
|
|
1848
|
+
},
|
|
1849
|
+
{ browser: options.browser }
|
|
1850
|
+
);
|
|
1851
|
+
return configureOpenCode(ctx, { apiKey, model });
|
|
1852
|
+
},
|
|
1853
|
+
off: disableOpenCode,
|
|
1854
|
+
status: result2
|
|
1855
|
+
};
|
|
1856
|
+
|
|
1857
|
+
// src/harnesses/pi.ts
|
|
1858
|
+
import { join as join6, resolve as resolve3 } from "path";
|
|
1859
|
+
var ID3 = "pi";
|
|
1860
|
+
var LABEL3 = "Pi";
|
|
1861
|
+
var PROVIDER2 = "pollinations";
|
|
1862
|
+
var DEFAULT_MODEL3 = "deepseek";
|
|
1863
|
+
var piAgentDir = (ctx) => {
|
|
1864
|
+
const configured = ctx.env.PI_CODING_AGENT_DIR;
|
|
1865
|
+
if (!configured?.trim()) return join6(ctx.home, ".pi", "agent");
|
|
1866
|
+
const expanded = configured === "~" ? ctx.home : configured.startsWith("~/") || configured.startsWith("~\\") ? join6(ctx.home, configured.slice(2)) : configured;
|
|
1867
|
+
return resolve3(expanded);
|
|
1868
|
+
};
|
|
1869
|
+
var modelsPath = (ctx) => join6(piAgentDir(ctx), "models.json");
|
|
1870
|
+
var authPath = (ctx) => join6(piAgentDir(ctx), "auth.json");
|
|
1871
|
+
var settingsPath2 = (ctx) => join6(piAgentDir(ctx), "settings.json");
|
|
1872
|
+
var skillFile = (ctx) => join6(piAgentDir(ctx), "skills", "polli", "SKILL.md");
|
|
1873
|
+
var files3 = (ctx) => [
|
|
1874
|
+
modelsPath(ctx),
|
|
1875
|
+
authPath(ctx),
|
|
1876
|
+
settingsPath2(ctx),
|
|
1877
|
+
skillFile(ctx)
|
|
1878
|
+
];
|
|
1879
|
+
var loadJson = (path) => {
|
|
1880
|
+
const text = readTextIfExists(path);
|
|
1881
|
+
if (!text?.trim()) return {};
|
|
1882
|
+
return JSON.parse(text);
|
|
1883
|
+
};
|
|
1884
|
+
var saveJson = (path, data) => {
|
|
1885
|
+
writeTextAtomic(path, `${JSON.stringify(data, null, 2)}
|
|
1886
|
+
`, 384);
|
|
1887
|
+
};
|
|
1888
|
+
var readKey2 = (ctx) => {
|
|
1889
|
+
const auth = loadJson(authPath(ctx));
|
|
1890
|
+
const entry = auth[PROVIDER2];
|
|
1891
|
+
if (!entry || typeof entry !== "object") return null;
|
|
1892
|
+
const key = entry.key;
|
|
1893
|
+
return typeof key === "string" && key ? key : null;
|
|
1894
|
+
};
|
|
1895
|
+
var providerConfig2 = (models2) => ({
|
|
1896
|
+
baseUrl: `${BASE_URL}/v1`,
|
|
1897
|
+
api: "openai-completions",
|
|
1898
|
+
// Pi validates custom providers before resolving their auth.json entry.
|
|
1899
|
+
apiKey: PROVIDER2,
|
|
1900
|
+
compat: {
|
|
1901
|
+
supportsStore: false,
|
|
1902
|
+
supportsDeveloperRole: false,
|
|
1903
|
+
supportsReasoningEffort: true,
|
|
1904
|
+
supportsUsageInStreaming: true,
|
|
1905
|
+
supportsStrictMode: false,
|
|
1906
|
+
maxTokensField: "max_tokens"
|
|
1907
|
+
},
|
|
1908
|
+
models: models2.map((model) => ({
|
|
1909
|
+
id: model.id,
|
|
1910
|
+
name: model.id,
|
|
1911
|
+
contextWindow: model.contextWindow,
|
|
1912
|
+
input: model.input
|
|
1913
|
+
}))
|
|
1914
|
+
});
|
|
1915
|
+
var writeConfig3 = (ctx, settings) => {
|
|
1916
|
+
const modelsData = loadJson(modelsPath(ctx));
|
|
1917
|
+
const providers = modelsData.providers ?? {};
|
|
1918
|
+
modelsData.providers = {
|
|
1919
|
+
...providers,
|
|
1920
|
+
[PROVIDER2]: providerConfig2(settings.models)
|
|
1921
|
+
};
|
|
1922
|
+
saveJson(modelsPath(ctx), modelsData);
|
|
1923
|
+
const auth = loadJson(authPath(ctx));
|
|
1924
|
+
auth[PROVIDER2] = { type: "api_key", key: settings.apiKey };
|
|
1925
|
+
saveJson(authPath(ctx), auth);
|
|
1926
|
+
const piSettings = loadJson(settingsPath2(ctx));
|
|
1927
|
+
piSettings.defaultProvider = PROVIDER2;
|
|
1928
|
+
piSettings.defaultModel = settings.model;
|
|
1929
|
+
saveJson(settingsPath2(ctx), piSettings);
|
|
1930
|
+
if (readTextIfExists(skillFile(ctx)) === null) {
|
|
1931
|
+
writeTextAtomic(skillFile(ctx), SKILL_default, 384);
|
|
1932
|
+
}
|
|
1933
|
+
};
|
|
1934
|
+
var stripConfig3 = (ctx) => {
|
|
1935
|
+
let changed = false;
|
|
1936
|
+
const modelsText = readTextIfExists(modelsPath(ctx));
|
|
1937
|
+
if (modelsText?.trim()) {
|
|
1938
|
+
const data = JSON.parse(modelsText);
|
|
1939
|
+
if (data.providers && typeof data.providers === "object" && PROVIDER2 in data.providers) {
|
|
1940
|
+
delete data.providers[PROVIDER2];
|
|
1941
|
+
saveJson(modelsPath(ctx), data);
|
|
1942
|
+
changed = true;
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
const authText = readTextIfExists(authPath(ctx));
|
|
1946
|
+
if (authText?.trim()) {
|
|
1947
|
+
const data = JSON.parse(authText);
|
|
1948
|
+
if (PROVIDER2 in data) {
|
|
1949
|
+
delete data[PROVIDER2];
|
|
1950
|
+
saveJson(authPath(ctx), data);
|
|
1951
|
+
changed = true;
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
const settingsText = readTextIfExists(settingsPath2(ctx));
|
|
1955
|
+
if (settingsText?.trim()) {
|
|
1956
|
+
const data = JSON.parse(settingsText);
|
|
1957
|
+
if (data.defaultProvider === PROVIDER2) {
|
|
1958
|
+
delete data.defaultProvider;
|
|
1959
|
+
delete data.defaultModel;
|
|
1960
|
+
saveJson(settingsPath2(ctx), data);
|
|
1961
|
+
changed = true;
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
if (readTextIfExists(skillFile(ctx)) === SKILL_default) {
|
|
1965
|
+
removeIfExists(skillFile(ctx));
|
|
1966
|
+
changed = true;
|
|
1967
|
+
}
|
|
1968
|
+
return changed;
|
|
1969
|
+
};
|
|
1970
|
+
var result3 = (ctx) => {
|
|
1971
|
+
const modelsData = loadJson(modelsPath(ctx));
|
|
1972
|
+
const authData = loadJson(authPath(ctx));
|
|
1973
|
+
const settingsData = loadJson(settingsPath2(ctx));
|
|
1974
|
+
const providers = modelsData.providers;
|
|
1975
|
+
const provider = providers?.[PROVIDER2];
|
|
1976
|
+
const hasProvider = provider?.apiKey === PROVIDER2;
|
|
1977
|
+
const authEntry = authData[PROVIDER2];
|
|
1978
|
+
const hasKey = authEntry?.type === "api_key" && typeof authEntry.key === "string" && !!authEntry.key;
|
|
1979
|
+
const hasDefaultProvider = settingsData.defaultProvider === PROVIDER2;
|
|
1980
|
+
const model = typeof settingsData.defaultModel === "string" ? settingsData.defaultModel : void 0;
|
|
1981
|
+
return {
|
|
1982
|
+
harness: ID3,
|
|
1983
|
+
label: LABEL3,
|
|
1984
|
+
configured: hasProvider && hasKey && hasDefaultProvider && readTextIfExists(skillFile(ctx)) !== null,
|
|
1985
|
+
model,
|
|
1986
|
+
files: files3(ctx)
|
|
1987
|
+
};
|
|
1988
|
+
};
|
|
1989
|
+
var configurePi = (ctx, settings) => {
|
|
1990
|
+
applyWithSnapshot(ctx, ID3, files3(ctx), () => writeConfig3(ctx, settings));
|
|
1991
|
+
return result3(ctx);
|
|
1992
|
+
};
|
|
1993
|
+
var disablePi = (ctx) => {
|
|
1994
|
+
const managedFiles = files3(ctx);
|
|
1995
|
+
let outcome = "restored";
|
|
1996
|
+
if (restoreSnapshot(ctx, ID3, managedFiles) !== "restored") {
|
|
1997
|
+
outcome = stripConfig3(ctx) ? "stripped" : "unchanged";
|
|
1998
|
+
clearSnapshot(ctx, ID3, managedFiles);
|
|
1999
|
+
}
|
|
2000
|
+
return { ...result3(ctx), configured: false, outcome };
|
|
2001
|
+
};
|
|
2002
|
+
var pi = {
|
|
2003
|
+
id: ID3,
|
|
2004
|
+
label: LABEL3,
|
|
2005
|
+
description: "Configure Pi as a Pollinations provider",
|
|
2006
|
+
restartHint: "Changes apply on the next Pi session. Start Pi with: pi",
|
|
2007
|
+
async on(ctx, options) {
|
|
2008
|
+
if (!commandExists("pi", ctx.env)) {
|
|
2009
|
+
throw new Error(
|
|
2010
|
+
"Pi was not found. Install it first: npm install -g --ignore-scripts @earendil-works/pi-coding-agent"
|
|
2011
|
+
);
|
|
2012
|
+
}
|
|
2013
|
+
const model = options.model ?? DEFAULT_MODEL3;
|
|
2014
|
+
const models2 = await fetchHarnessModels();
|
|
2015
|
+
if (!models2.some((candidate) => candidate.id === model)) {
|
|
2016
|
+
throw new Error(
|
|
2017
|
+
`Model "${model}" is not a tool-calling text model. Run: polli models`
|
|
2018
|
+
);
|
|
2019
|
+
}
|
|
2020
|
+
const apiKey = await resolveHarnessKey(
|
|
2021
|
+
{ id: ID3, label: LABEL3, existingKey: readKey2(ctx) },
|
|
2022
|
+
{ browser: options.browser }
|
|
2023
|
+
);
|
|
2024
|
+
return configurePi(ctx, { apiKey, model, models: models2 });
|
|
2025
|
+
},
|
|
2026
|
+
off: disablePi,
|
|
2027
|
+
status: result3
|
|
2028
|
+
};
|
|
2029
|
+
|
|
2030
|
+
// src/harnesses/index.ts
|
|
2031
|
+
var HARNESSES = [dsh, opencode, pi];
|
|
2032
|
+
|
|
2033
|
+
// src/commands/harness.ts
|
|
2034
|
+
var context = () => ({ home: homedir2(), env: process.env });
|
|
2035
|
+
var OFF_MESSAGES = {
|
|
2036
|
+
restored: "original config restored.",
|
|
2037
|
+
stripped: "Pollinations entries removed.",
|
|
2038
|
+
unchanged: "was not connected; nothing changed."
|
|
2039
|
+
};
|
|
2040
|
+
var runOn = async (harness, options) => {
|
|
2041
|
+
try {
|
|
2042
|
+
const result4 = await harness.on(context(), options);
|
|
2043
|
+
const model = result4.model ? ` (model: ${result4.model})` : "";
|
|
2044
|
+
printSuccess(`${harness.label} now uses Pollinations${model}.`);
|
|
2045
|
+
printInfo(harness.restartHint);
|
|
2046
|
+
printResult(result4);
|
|
2047
|
+
} catch (error) {
|
|
2048
|
+
fail(`Failed to connect ${harness.label}`, error);
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
var runOff = async (harness) => {
|
|
2052
|
+
try {
|
|
2053
|
+
const result4 = await harness.off(context());
|
|
2054
|
+
const outcome = result4.outcome ?? "unchanged";
|
|
2055
|
+
printSuccess(`${harness.label}: ${OFF_MESSAGES[outcome]}`);
|
|
2056
|
+
if (outcome !== "unchanged") printInfo(harness.restartHint);
|
|
2057
|
+
printResult(result4);
|
|
2058
|
+
} catch (error) {
|
|
2059
|
+
fail(`Failed to disconnect ${harness.label}`, error);
|
|
2060
|
+
}
|
|
2061
|
+
};
|
|
2062
|
+
var runStatus = async (harness) => {
|
|
2063
|
+
try {
|
|
2064
|
+
printResult(await harness.status(context()));
|
|
2065
|
+
} catch (error) {
|
|
2066
|
+
fail(`Failed to inspect ${harness.label}`, error);
|
|
2067
|
+
}
|
|
2068
|
+
};
|
|
2069
|
+
var withOnOptions = (command) => command.option("--model <id>", "Default model for the harness").option("--no-mcp", "Skip MCP tool configuration").option(
|
|
2070
|
+
"--no-browser",
|
|
2071
|
+
"Print the login URL instead of opening a browser"
|
|
2072
|
+
);
|
|
2073
|
+
var harnessSubcommand = (harness) => {
|
|
2074
|
+
const command = withOnOptions(
|
|
2075
|
+
new Command12(harness.id).description(harness.description)
|
|
2076
|
+
).action((options) => runOn(harness, options));
|
|
2077
|
+
command.addCommand(
|
|
2078
|
+
new Command12("on").description(`Connect ${harness.label} to Pollinations`).action(() => runOn(harness, command.opts()))
|
|
2079
|
+
);
|
|
2080
|
+
command.addCommand(
|
|
2081
|
+
new Command12("off").description(`Restore ${harness.label}'s previous configuration`).action(() => runOff(harness))
|
|
2082
|
+
);
|
|
2083
|
+
command.addCommand(
|
|
2084
|
+
new Command12("status").description(`Show ${harness.label}'s Pollinations status`).action(() => runStatus(harness))
|
|
2085
|
+
);
|
|
2086
|
+
return command;
|
|
2087
|
+
};
|
|
2088
|
+
var harnessCommand = new Command12("harness").description("Configure coding harnesses to use Pollinations").addHelpText(
|
|
2089
|
+
"after",
|
|
2090
|
+
"\nGuide: https://gen.pollinations.ai/docs#tag/coding-harnesses\n"
|
|
2091
|
+
);
|
|
2092
|
+
for (const harness of HARNESSES) {
|
|
2093
|
+
harnessCommand.addCommand(harnessSubcommand(harness));
|
|
1199
2094
|
}
|
|
1200
2095
|
|
|
1201
2096
|
// src/commands/keys.ts
|
|
1202
2097
|
import chalk6 from "chalk";
|
|
1203
|
-
import { Command as
|
|
1204
|
-
var list2 = new
|
|
2098
|
+
import { Command as Command13 } from "commander";
|
|
2099
|
+
var list2 = new Command13("list").description("List all API keys for your account").option(
|
|
1205
2100
|
"--verbose",
|
|
1206
2101
|
"Show id, created, last_used, enabled columns (use --json for full raw data)"
|
|
1207
2102
|
).action(async (opts) => {
|
|
@@ -1258,7 +2153,7 @@ var list2 = new Command11("list").description("List all API keys for your accoun
|
|
|
1258
2153
|
fail("Failed to list keys", err);
|
|
1259
2154
|
}
|
|
1260
2155
|
});
|
|
1261
|
-
var info = new
|
|
2156
|
+
var info = new Command13("info").description(
|
|
1262
2157
|
"Show details about the currently authenticated key (no args). To inspect another key by id, use `polli keys list --json`."
|
|
1263
2158
|
).action(async () => {
|
|
1264
2159
|
const key = requireKey();
|
|
@@ -1280,7 +2175,7 @@ var info = new Command11("info").description(
|
|
|
1280
2175
|
fail("Failed to fetch key info", err);
|
|
1281
2176
|
}
|
|
1282
2177
|
});
|
|
1283
|
-
var create2 = new
|
|
2178
|
+
var create2 = new Command13("create").description(
|
|
1284
2179
|
"Create a new API key. Use --type publishable to create an app key."
|
|
1285
2180
|
).requiredOption("--name <name>", "Key name").option(
|
|
1286
2181
|
"--type <type>",
|
|
@@ -1354,7 +2249,7 @@ Examples:
|
|
|
1354
2249
|
fail("Failed to create key", err);
|
|
1355
2250
|
}
|
|
1356
2251
|
});
|
|
1357
|
-
var revoke = new
|
|
2252
|
+
var revoke = new Command13("revoke").description("Revoke an API key by ID").argument("<id>", "Key ID to revoke").action(async (id) => {
|
|
1358
2253
|
const key = requireKey();
|
|
1359
2254
|
try {
|
|
1360
2255
|
await gen(`/account/keys/${id}`, {
|
|
@@ -1366,11 +2261,11 @@ var revoke = new Command11("revoke").description("Revoke an API key by ID").argu
|
|
|
1366
2261
|
fail("Failed to revoke key", err);
|
|
1367
2262
|
}
|
|
1368
2263
|
});
|
|
1369
|
-
var keysCommand = new
|
|
2264
|
+
var keysCommand = new Command13("keys").description("Manage API keys (create, list, revoke)").addCommand(list2).addCommand(info).addCommand(create2).addCommand(revoke);
|
|
1370
2265
|
|
|
1371
2266
|
// src/commands/models.ts
|
|
1372
2267
|
import chalk7 from "chalk";
|
|
1373
|
-
import { Command as
|
|
2268
|
+
import { Command as Command14 } from "commander";
|
|
1374
2269
|
|
|
1375
2270
|
// src/commands/stats.ts
|
|
1376
2271
|
var MODEL_HEALTH_URL = "https://gen.pollinations.ai/v1/models/status";
|
|
@@ -1416,7 +2311,7 @@ function buildRow(m, mType, verbose) {
|
|
|
1416
2311
|
}
|
|
1417
2312
|
return row;
|
|
1418
2313
|
}
|
|
1419
|
-
var modelsCommand = new
|
|
2314
|
+
var modelsCommand = new Command14("models").description("List available models or show model health stats").option(
|
|
1420
2315
|
"--type <type>",
|
|
1421
2316
|
"Filter: text, image, audio, video, embedding, all",
|
|
1422
2317
|
"all"
|
|
@@ -1526,7 +2421,7 @@ var modelsCommand = new Command12("models").description("List available models o
|
|
|
1526
2421
|
|
|
1527
2422
|
// src/commands/my-models.ts
|
|
1528
2423
|
import chalk8 from "chalk";
|
|
1529
|
-
import { Command as
|
|
2424
|
+
import { Command as Command15 } from "commander";
|
|
1530
2425
|
var PRICE_FLAGS = [
|
|
1531
2426
|
["--prompt-text-price <number>", "Prompt text token price"],
|
|
1532
2427
|
["--prompt-cached-price <number>", "Prompt cached token price"],
|
|
@@ -1542,7 +2437,8 @@ var PRICE_FLAGS = [
|
|
|
1542
2437
|
[
|
|
1543
2438
|
"--completion-image-price <number>",
|
|
1544
2439
|
"Generated-image price (per image when --image-pricing request; per token when --image-pricing tokens)"
|
|
1545
|
-
]
|
|
2440
|
+
],
|
|
2441
|
+
["--completion-video-price <number>", "Generated-video price per second"]
|
|
1546
2442
|
];
|
|
1547
2443
|
var PRICE_OPTION_KEYS = [
|
|
1548
2444
|
"promptTextPrice",
|
|
@@ -1553,7 +2449,8 @@ var PRICE_OPTION_KEYS = [
|
|
|
1553
2449
|
"completionTextPrice",
|
|
1554
2450
|
"completionReasoningPrice",
|
|
1555
2451
|
"completionAudioPrice",
|
|
1556
|
-
"completionImagePrice"
|
|
2452
|
+
"completionImagePrice",
|
|
2453
|
+
"completionVideoPrice"
|
|
1557
2454
|
];
|
|
1558
2455
|
function addPriceOptions(command) {
|
|
1559
2456
|
for (const [flag, description] of PRICE_FLAGS) {
|
|
@@ -1583,7 +2480,8 @@ function modelBody(opts, includeRequired) {
|
|
|
1583
2480
|
["description", "description"],
|
|
1584
2481
|
["baseUrl", "baseUrl"],
|
|
1585
2482
|
["upstreamModel", "upstreamModel"],
|
|
1586
|
-
["bearerToken", "bearerToken"]
|
|
2483
|
+
["bearerToken", "bearerToken"],
|
|
2484
|
+
["paidOnly", "paidOnly"]
|
|
1587
2485
|
];
|
|
1588
2486
|
for (const [optionKey, bodyKey] of fields) {
|
|
1589
2487
|
if (opts[optionKey] !== void 0) body[bodyKey] = opts[optionKey];
|
|
@@ -1595,8 +2493,10 @@ function modelBody(opts, includeRequired) {
|
|
|
1595
2493
|
body.visibility = opts.visibility;
|
|
1596
2494
|
}
|
|
1597
2495
|
if (includeRequired && opts.modality !== void 0) {
|
|
1598
|
-
if (opts.modality !== "text" && opts.modality !== "image" && opts.modality !== "transcription") {
|
|
1599
|
-
fail(
|
|
2496
|
+
if (opts.modality !== "text" && opts.modality !== "image" && opts.modality !== "video" && opts.modality !== "transcription" && opts.modality !== "embedding") {
|
|
2497
|
+
fail(
|
|
2498
|
+
"--modality must be 'text', 'image', 'video', 'transcription', or 'embedding'"
|
|
2499
|
+
);
|
|
1600
2500
|
}
|
|
1601
2501
|
body.modality = opts.modality;
|
|
1602
2502
|
}
|
|
@@ -1640,9 +2540,10 @@ function printModels(models2) {
|
|
|
1640
2540
|
// Price and billing mode read as one unit, so they share a cell
|
|
1641
2541
|
// rather than widening an already wide table by two columns.
|
|
1642
2542
|
image_price: model.type === "proxy" && model.modality === "image" ? `${model.completionImagePrice}/${model.imagePricing === "tokens" ? "token" : "req"}` : "-",
|
|
2543
|
+
video_price: model.type === "proxy" && model.modality === "video" ? `${model.completionVideoPrice}/sec` : "-",
|
|
1643
2544
|
inputs: model.type === "proxy" ? model.inputModalities?.join(", ") || "-" : "-",
|
|
1644
|
-
visibility: model.visibility,
|
|
1645
|
-
upstream: model.upstreamModel,
|
|
2545
|
+
visibility: model.type === "proxy" && model.paidOnly ? `${model.visibility} (paid only)` : model.visibility,
|
|
2546
|
+
upstream: model.type === "proxy" && model.modality === "video" ? "-" : model.upstreamModel,
|
|
1646
2547
|
base_url: model.baseUrl,
|
|
1647
2548
|
fallbacks: model.type === "proxy" ? model.fallbacks?.join(", ") || "-" : "-",
|
|
1648
2549
|
description: model.description ?? "-"
|
|
@@ -1654,6 +2555,7 @@ function printModels(models2) {
|
|
|
1654
2555
|
"type",
|
|
1655
2556
|
"modality",
|
|
1656
2557
|
"image_price",
|
|
2558
|
+
"video_price",
|
|
1657
2559
|
"inputs",
|
|
1658
2560
|
"visibility",
|
|
1659
2561
|
"upstream",
|
|
@@ -1663,7 +2565,7 @@ function printModels(models2) {
|
|
|
1663
2565
|
]
|
|
1664
2566
|
);
|
|
1665
2567
|
}
|
|
1666
|
-
var list3 = new
|
|
2568
|
+
var list3 = new Command15("list").description("List models owned by your account").action(async () => {
|
|
1667
2569
|
const key = requireKey();
|
|
1668
2570
|
try {
|
|
1669
2571
|
const res = await gen("/account/my-models", {
|
|
@@ -1675,10 +2577,19 @@ var list3 = new Command13("list").description("List models owned by your account
|
|
|
1675
2577
|
}
|
|
1676
2578
|
});
|
|
1677
2579
|
var create3 = addPriceOptions(
|
|
1678
|
-
new
|
|
2580
|
+
new Command15("create").description("Register a community model endpoint").requiredOption("--name <name>", "Model name").requiredOption("--title <title>", "Display title shown in the catalog").option("--description <text>", "Model description").option(
|
|
2581
|
+
"--base-url <url>",
|
|
2582
|
+
"OpenAI-compatible base URL, or exact video endpoint URL"
|
|
2583
|
+
).option(
|
|
2584
|
+
"--upstream-model <model>",
|
|
2585
|
+
"Upstream model id (not used for video)"
|
|
2586
|
+
).option("--bearer-token <token>", "Upstream bearer token").option(
|
|
1679
2587
|
"--visibility <visibility>",
|
|
1680
2588
|
"Model visibility: private (default) or public"
|
|
1681
2589
|
).option(
|
|
2590
|
+
"--paid-only",
|
|
2591
|
+
"Only accept Paid Pollen, for a pay-as-you-go upstream whose cost free Quest Pollen would not cover"
|
|
2592
|
+
).option("--no-paid-only", "Accept Quest or Paid Pollen (default)").option(
|
|
1682
2593
|
"--fallbacks <ids>",
|
|
1683
2594
|
"Comma-separated community model ids tried in order when this model's upstream fails; empty string clears them"
|
|
1684
2595
|
).option(
|
|
@@ -1686,7 +2597,7 @@ var create3 = addPriceOptions(
|
|
|
1686
2597
|
"Comma-separated accepted inputs: text,image,audio,video"
|
|
1687
2598
|
).option(
|
|
1688
2599
|
"--modality <modality>",
|
|
1689
|
-
"Model family: text (default), image, or
|
|
2600
|
+
"Model family: text (default), image, video, transcription, or embedding"
|
|
1690
2601
|
).option(
|
|
1691
2602
|
"--image-pricing <mode>",
|
|
1692
2603
|
"Image billing: request (per image, default) or tokens"
|
|
@@ -1709,10 +2620,19 @@ var create3 = addPriceOptions(
|
|
|
1709
2620
|
}
|
|
1710
2621
|
});
|
|
1711
2622
|
var update2 = addPriceOptions(
|
|
1712
|
-
new
|
|
2623
|
+
new Command15("update").description("Update one of your models").argument("<id>", "Model id").option("--name <name>", "Model name").option("--title <title>", "Display title shown in the catalog").option("--description <text>", "Model description").option(
|
|
2624
|
+
"--base-url <url>",
|
|
2625
|
+
"OpenAI-compatible base URL, or exact video endpoint URL"
|
|
2626
|
+
).option(
|
|
2627
|
+
"--upstream-model <model>",
|
|
2628
|
+
"Upstream model id (not used for video)"
|
|
2629
|
+
).option("--bearer-token <token>", "Upstream bearer token").option(
|
|
1713
2630
|
"--visibility <visibility>",
|
|
1714
2631
|
"Model visibility: private or public"
|
|
1715
2632
|
).option(
|
|
2633
|
+
"--paid-only",
|
|
2634
|
+
"Only accept Paid Pollen, for a pay-as-you-go upstream whose cost free Quest Pollen would not cover"
|
|
2635
|
+
).option("--no-paid-only", "Accept Quest or Paid Pollen").option(
|
|
1716
2636
|
"--fallbacks <ids>",
|
|
1717
2637
|
"Comma-separated community model ids tried in order when this model's upstream fails; empty string clears them"
|
|
1718
2638
|
).option(
|
|
@@ -1742,7 +2662,7 @@ var update2 = addPriceOptions(
|
|
|
1742
2662
|
fail("Failed to update model", err);
|
|
1743
2663
|
}
|
|
1744
2664
|
});
|
|
1745
|
-
var remove2 = new
|
|
2665
|
+
var remove2 = new Command15("delete").description("Delete one of your models").argument("<id>", "Model id").action(async (id) => {
|
|
1746
2666
|
const key = requireKey();
|
|
1747
2667
|
try {
|
|
1748
2668
|
await gen(
|
|
@@ -1758,7 +2678,7 @@ var remove2 = new Command13("delete").description("Delete one of your models").a
|
|
|
1758
2678
|
fail("Failed to delete model", err);
|
|
1759
2679
|
}
|
|
1760
2680
|
});
|
|
1761
|
-
var models = new
|
|
2681
|
+
var models = new Command15("models").description("List upstream models from an endpoint before registering it").requiredOption("--base-url <url>", "OpenAI-compatible base URL").requiredOption("--bearer-token <token>", "Upstream bearer token").action(async (opts) => {
|
|
1762
2682
|
const key = requireKey();
|
|
1763
2683
|
try {
|
|
1764
2684
|
const res = await gen(
|
|
@@ -1783,13 +2703,22 @@ var models = new Command13("models").description("List upstream models from an e
|
|
|
1783
2703
|
fail("Failed to fetch upstream models", err);
|
|
1784
2704
|
}
|
|
1785
2705
|
});
|
|
1786
|
-
var test = new
|
|
2706
|
+
var test = new Command15("test").description("Test an endpoint/model before registering it").requiredOption(
|
|
2707
|
+
"--base-url <url>",
|
|
2708
|
+
"OpenAI-compatible base URL, or exact video endpoint URL"
|
|
2709
|
+
).requiredOption("--bearer-token <token>", "Upstream bearer token").option("--model <model>", "Upstream model id (not used for video)").option(
|
|
1787
2710
|
"--modality <modality>",
|
|
1788
|
-
"Model family: text (default), image, or
|
|
2711
|
+
"Model family: text (default), image, video, transcription, or embedding"
|
|
1789
2712
|
).action(async (opts) => {
|
|
1790
2713
|
const key = requireKey();
|
|
1791
|
-
if (opts.modality !== void 0 && opts.modality !== "text" && opts.modality !== "image" && opts.modality !== "transcription") {
|
|
1792
|
-
fail(
|
|
2714
|
+
if (opts.modality !== void 0 && opts.modality !== "text" && opts.modality !== "image" && opts.modality !== "video" && opts.modality !== "transcription" && opts.modality !== "embedding") {
|
|
2715
|
+
fail(
|
|
2716
|
+
"--modality must be 'text', 'image', 'video', 'transcription', or 'embedding'"
|
|
2717
|
+
);
|
|
2718
|
+
}
|
|
2719
|
+
const modality = opts.modality ?? "text";
|
|
2720
|
+
if (modality !== "video" && !opts.model) {
|
|
2721
|
+
fail("--model is required unless --modality is video");
|
|
1793
2722
|
}
|
|
1794
2723
|
try {
|
|
1795
2724
|
const res = await gen(
|
|
@@ -1800,10 +2729,8 @@ var test = new Command13("test").description("Test an endpoint/model before regi
|
|
|
1800
2729
|
body: {
|
|
1801
2730
|
baseUrl: opts.baseUrl,
|
|
1802
2731
|
bearerToken: opts.bearerToken,
|
|
1803
|
-
model: opts.model,
|
|
1804
|
-
|
|
1805
|
-
modality: opts.modality
|
|
1806
|
-
}
|
|
2732
|
+
...opts.model && { model: opts.model },
|
|
2733
|
+
modality
|
|
1807
2734
|
}
|
|
1808
2735
|
}
|
|
1809
2736
|
);
|
|
@@ -1812,13 +2739,13 @@ var test = new Command13("test").description("Test an endpoint/model before regi
|
|
|
1812
2739
|
fail("Failed to test model", err);
|
|
1813
2740
|
}
|
|
1814
2741
|
});
|
|
1815
|
-
var myModelsCommand = new
|
|
1816
|
-
"Manage private and published community text, image,
|
|
2742
|
+
var myModelsCommand = new Command15("my-models").description(
|
|
2743
|
+
"Manage private and published community text, image, video, transcription, and embedding models"
|
|
1817
2744
|
).addCommand(list3).addCommand(create3).addCommand(update2).addCommand(remove2).addCommand(models).addCommand(test);
|
|
1818
2745
|
|
|
1819
2746
|
// src/commands/quests.ts
|
|
1820
2747
|
import chalk9 from "chalk";
|
|
1821
|
-
import { Command as
|
|
2748
|
+
import { Command as Command16 } from "commander";
|
|
1822
2749
|
function questStatus(quest) {
|
|
1823
2750
|
if (quest.state === "coming_soon" || quest.status === "coming_soon") {
|
|
1824
2751
|
return "coming";
|
|
@@ -1878,7 +2805,7 @@ function renderQuests(quests) {
|
|
|
1878
2805
|
["status", "category", "reward", "title", "url"]
|
|
1879
2806
|
);
|
|
1880
2807
|
}
|
|
1881
|
-
var questsCommand = new
|
|
2808
|
+
var questsCommand = new Command16("quests").description(
|
|
1882
2809
|
"List your quests with claim state (open / claimable / claimed / coming)"
|
|
1883
2810
|
).option("--open", "Show only open quests").option("--claimable", "Show only quests with a reward ready to claim").option("--claimed", "Show only already-claimed quests").option("--coming-soon", "Show only coming-soon quests").action(async (opts) => {
|
|
1884
2811
|
try {
|
|
@@ -1907,9 +2834,9 @@ var questsCommand = new Command14("quests").description(
|
|
|
1907
2834
|
});
|
|
1908
2835
|
|
|
1909
2836
|
// src/commands/upload.ts
|
|
1910
|
-
import { existsSync as
|
|
1911
|
-
import { basename as
|
|
1912
|
-
import { Command as
|
|
2837
|
+
import { existsSync as existsSync3, readFileSync as readFileSync5 } from "fs";
|
|
2838
|
+
import { basename as basename3, extname } from "path";
|
|
2839
|
+
import { Command as Command17 } from "commander";
|
|
1913
2840
|
var MIME_BY_EXT = {
|
|
1914
2841
|
".jpg": "image/jpeg",
|
|
1915
2842
|
".jpeg": "image/jpeg",
|
|
@@ -1928,20 +2855,20 @@ var MIME_BY_EXT = {
|
|
|
1928
2855
|
".webm": "video/webm",
|
|
1929
2856
|
".mov": "video/quicktime"
|
|
1930
2857
|
};
|
|
1931
|
-
var uploadCommand = new
|
|
2858
|
+
var uploadCommand = new Command17("upload").description(
|
|
1932
2859
|
"Upload a local file to media.pollinations.ai and print its public URL"
|
|
1933
2860
|
).argument("<file>", "Path to the local file to upload").action(async (file) => {
|
|
1934
2861
|
const key = requireKey();
|
|
1935
2862
|
const isHuman = getOutputMode() === "human";
|
|
1936
|
-
if (!
|
|
2863
|
+
if (!existsSync3(file)) {
|
|
1937
2864
|
fail(`File not found: ${file}`);
|
|
1938
2865
|
}
|
|
1939
2866
|
const mime = MIME_BY_EXT[extname(file).toLowerCase()] || "application/octet-stream";
|
|
1940
2867
|
const form = new FormData();
|
|
1941
2868
|
form.append(
|
|
1942
2869
|
"file",
|
|
1943
|
-
new Blob([
|
|
1944
|
-
|
|
2870
|
+
new Blob([readFileSync5(file)], { type: mime }),
|
|
2871
|
+
basename3(file)
|
|
1945
2872
|
);
|
|
1946
2873
|
const res = await fetch(`${MEDIA_URL}/upload`, {
|
|
1947
2874
|
method: "POST",
|
|
@@ -1969,8 +2896,8 @@ var uploadCommand = new Command15("upload").description(
|
|
|
1969
2896
|
|
|
1970
2897
|
// src/commands/usage.ts
|
|
1971
2898
|
import chalk10 from "chalk";
|
|
1972
|
-
import { Command as
|
|
1973
|
-
var usageCommand = new
|
|
2899
|
+
import { Command as Command18 } from "commander";
|
|
2900
|
+
var usageCommand = new Command18("usage").description(
|
|
1974
2901
|
"Show pollen balance (default), usage history, or daily summary"
|
|
1975
2902
|
).option("--limit <n>", "Number of records", "20").option("--history", "Show individual request history").option("--daily", "Show daily summary instead of individual requests").action(async (opts) => {
|
|
1976
2903
|
const key = requireKey();
|
|
@@ -2034,9 +2961,9 @@ var usageCommand = new Command16("usage").description(
|
|
|
2034
2961
|
|
|
2035
2962
|
// src/index.ts
|
|
2036
2963
|
var pkg = JSON.parse(
|
|
2037
|
-
|
|
2964
|
+
readFileSync6(new URL("../package.json", import.meta.url), "utf-8")
|
|
2038
2965
|
);
|
|
2039
|
-
var program = new
|
|
2966
|
+
var program = new Command19();
|
|
2040
2967
|
program.configureHelp({
|
|
2041
2968
|
styleTitle: (s) => chalk11.hex("#a78bfa").bold(s),
|
|
2042
2969
|
styleCommandText: (s) => chalk11.bold(s),
|
|
@@ -2068,9 +2995,11 @@ AI agent? Read the skill file for the full usage map:
|
|
|
2068
2995
|
program.addCommand(authCommand);
|
|
2069
2996
|
program.addCommand(keysCommand);
|
|
2070
2997
|
program.addCommand(usageCommand);
|
|
2998
|
+
program.addCommand(earningsCommand);
|
|
2071
2999
|
program.addCommand(questsCommand);
|
|
2072
3000
|
program.addCommand(agentsCommand);
|
|
2073
3001
|
program.addCommand(myModelsCommand);
|
|
3002
|
+
program.addCommand(harnessCommand);
|
|
2074
3003
|
program.addCommand(createGenCommand());
|
|
2075
3004
|
program.addCommand(uploadCommand);
|
|
2076
3005
|
program.addCommand(modelsCommand);
|