@pollinations/cli 0.1.12 → 0.1.13
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 +12 -6
- package/SKILL.md +8 -5
- package/dist/index.js +540 -195
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -217,13 +217,13 @@ function readConfig(path) {
|
|
|
217
217
|
process.exit(1);
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
-
function agentBody(
|
|
220
|
+
function agentBody(configPath2, opts) {
|
|
221
221
|
if (opts.visibility !== void 0 && opts.visibility !== "private" && opts.visibility !== "public") {
|
|
222
222
|
printError("--visibility must be 'private' or 'public'");
|
|
223
223
|
process.exit(1);
|
|
224
224
|
}
|
|
225
225
|
return {
|
|
226
|
-
...readConfig(
|
|
226
|
+
...readConfig(configPath2),
|
|
227
227
|
...opts.name !== void 0 && { name: opts.name },
|
|
228
228
|
...opts.title !== void 0 && { title: opts.title },
|
|
229
229
|
...opts.description !== void 0 && {
|
|
@@ -685,12 +685,25 @@ import { Command as Command5 } from "commander";
|
|
|
685
685
|
// src/lib/errors.ts
|
|
686
686
|
async function budgetHint(status2, bodyText) {
|
|
687
687
|
if (status2 !== 402) return null;
|
|
688
|
+
let code;
|
|
689
|
+
try {
|
|
690
|
+
code = JSON.parse(bodyText)?.error?.code;
|
|
691
|
+
} catch {
|
|
692
|
+
}
|
|
693
|
+
if (code === "KEY_BUDGET_EXHAUSTED") {
|
|
694
|
+
return [
|
|
695
|
+
"API key budget exhausted. Topping up the wallet does not increase the key budget.",
|
|
696
|
+
"Manage key budget: https://enter.pollinations.ai/keys",
|
|
697
|
+
`Server said: ${bodyText}`
|
|
698
|
+
].join("\n");
|
|
699
|
+
}
|
|
688
700
|
const balance = await gen("/account/balance", {
|
|
689
701
|
apiKey: requireKey()
|
|
690
702
|
}).then((r) => r.balance).catch(() => null);
|
|
691
703
|
const lines = [
|
|
692
|
-
"Insufficient pollen balance.",
|
|
704
|
+
code === "INSUFFICIENT_BALANCE" ? "Insufficient pollen balance." : "Check your pollen balance and API key budget.",
|
|
693
705
|
"Top up: https://enter.pollinations.ai/pollen",
|
|
706
|
+
...code === "INSUFFICIENT_BALANCE" ? [] : ["Manage key budget: https://enter.pollinations.ai/keys"],
|
|
694
707
|
""
|
|
695
708
|
];
|
|
696
709
|
if (balance != null) lines.push(`Account balance: ${balance} pollen`);
|
|
@@ -751,12 +764,12 @@ var findPlayer = () => {
|
|
|
751
764
|
var playAudio = async (filePath) => {
|
|
752
765
|
const player = findPlayer();
|
|
753
766
|
if (!player) return false;
|
|
754
|
-
return new Promise((
|
|
767
|
+
return new Promise((resolve2) => {
|
|
755
768
|
const child = spawn(player.cmd, player.args(filePath), {
|
|
756
769
|
stdio: "ignore"
|
|
757
770
|
});
|
|
758
|
-
child.on("error", () =>
|
|
759
|
-
child.on("exit", (code) =>
|
|
771
|
+
child.on("error", () => resolve2(false));
|
|
772
|
+
child.on("exit", (code) => resolve2(code === 0));
|
|
760
773
|
});
|
|
761
774
|
};
|
|
762
775
|
var playerMissingHint = () => {
|
|
@@ -1264,12 +1277,12 @@ import { homedir as homedir2 } from "os";
|
|
|
1264
1277
|
import { Command as Command12 } from "commander";
|
|
1265
1278
|
|
|
1266
1279
|
// src/harnesses/dsh.ts
|
|
1267
|
-
import { join as join4
|
|
1280
|
+
import { join as join4 } from "path";
|
|
1268
1281
|
import { parseEnv } from "util";
|
|
1269
1282
|
import { isMap, isSeq, parseDocument, Scalar } from "yaml";
|
|
1270
1283
|
|
|
1271
1284
|
// 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';
|
|
1285
|
+
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\\|openclaw\\|pi\\|prime> 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" --api chat_completions --url https://api.example.com/v1/chat/completions --bearer-token "$UPSTREAM_KEY" --upstream-model gpt-4.1-mini --required-safety privacy,secrets,sexual,violence,shield\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 update <id> --required-safety privacy,secrets,sexual,violence,shield\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. Use server IDs from the MCP catalog. 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"\npolli harness openclaw on # login if needed, mint key "polli-harness-openclaw", add provider + Polli skill\npolli harness openclaw off # remove the Pollinations provider, key, and skill\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, OpenClaw, 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. OpenClaw adds a `pollinations` provider to `~/.openclaw/openclaw.json`, stores a dedicated key in `env.vars`, and installs this skill under `~/.openclaw/skills/polli/`. 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
1286
|
|
|
1274
1287
|
// src/harnesses/fs.ts
|
|
1275
1288
|
import {
|
|
@@ -1283,7 +1296,10 @@ import {
|
|
|
1283
1296
|
unlinkSync as unlinkSync2,
|
|
1284
1297
|
writeFileSync as writeFileSync7
|
|
1285
1298
|
} from "fs";
|
|
1286
|
-
import { basename as basename2, delimiter, dirname, join as join2 } from "path";
|
|
1299
|
+
import { basename as basename2, delimiter, dirname, join as join2, resolve } from "path";
|
|
1300
|
+
var resolveHomePath = (home, path) => resolve(
|
|
1301
|
+
path === "~" ? home : path.startsWith("~/") || path.startsWith("~\\") ? join2(home, path.slice(2)) : path
|
|
1302
|
+
);
|
|
1287
1303
|
var isExecutable = (path) => {
|
|
1288
1304
|
try {
|
|
1289
1305
|
accessSync(path, constants.X_OK);
|
|
@@ -1347,10 +1363,10 @@ var resolveHarnessKey = async (harness, options) => {
|
|
|
1347
1363
|
};
|
|
1348
1364
|
|
|
1349
1365
|
// src/harnesses/models.ts
|
|
1350
|
-
var fetchHarnessModels = async () => {
|
|
1366
|
+
var fetchHarnessModels = async (selectedModel) => {
|
|
1351
1367
|
const { data } = await gen("/v1/models");
|
|
1352
|
-
|
|
1353
|
-
(m) => m.tools === true && m.output_modalities?.includes("text") && m.supported_endpoints?.includes("/v1/chat/completions") && m.context_length && !m.agent &&
|
|
1368
|
+
const models2 = data.filter(
|
|
1369
|
+
(m) => m.tools === true && m.output_modalities?.includes("text") && m.supported_endpoints?.includes("/v1/chat/completions") && m.context_length && !m.agent && m.community !== true
|
|
1354
1370
|
).map((m) => ({
|
|
1355
1371
|
id: m.id,
|
|
1356
1372
|
contextWindow: m.context_length,
|
|
@@ -1358,6 +1374,12 @@ var fetchHarnessModels = async () => {
|
|
|
1358
1374
|
(modality) => modality === "text" || modality === "image"
|
|
1359
1375
|
)
|
|
1360
1376
|
}));
|
|
1377
|
+
if (!models2.some((model) => model.id === selectedModel)) {
|
|
1378
|
+
throw new Error(
|
|
1379
|
+
`Model "${selectedModel}" is not a tool-calling text model. Run: polli models`
|
|
1380
|
+
);
|
|
1381
|
+
}
|
|
1382
|
+
return models2;
|
|
1361
1383
|
};
|
|
1362
1384
|
|
|
1363
1385
|
// src/harnesses/snapshot.ts
|
|
@@ -1380,8 +1402,8 @@ var captureFiles = (paths) => Object.fromEntries(
|
|
|
1380
1402
|
{ before: readTextIfExists(path), afterHash: null }
|
|
1381
1403
|
])
|
|
1382
1404
|
);
|
|
1383
|
-
var restoreFiles = (
|
|
1384
|
-
for (const [path, file] of Object.entries(
|
|
1405
|
+
var restoreFiles = (files6) => {
|
|
1406
|
+
for (const [path, file] of Object.entries(files6)) {
|
|
1385
1407
|
if (file.before === null) removeIfExists(path);
|
|
1386
1408
|
else writeTextAtomic(path, file.before);
|
|
1387
1409
|
}
|
|
@@ -1419,23 +1441,18 @@ var applyWithSnapshot = (ctx, id, paths, apply) => {
|
|
|
1419
1441
|
snapshot.complete = true;
|
|
1420
1442
|
writeSnapshot(ctx, id, paths, snapshot);
|
|
1421
1443
|
};
|
|
1422
|
-
var
|
|
1444
|
+
var restoreOrStrip = (ctx, id, paths, strip) => {
|
|
1423
1445
|
const snapshot = loadSnapshot(ctx, id, paths);
|
|
1424
|
-
if (!snapshot
|
|
1425
|
-
|
|
1446
|
+
if (snapshot && (!snapshot.complete || Object.entries(snapshot.files).every(
|
|
1447
|
+
([path, file]) => contentHash(readTextIfExists(path)) === file.afterHash
|
|
1448
|
+
))) {
|
|
1426
1449
|
restoreFiles(snapshot.files);
|
|
1427
|
-
|
|
1450
|
+
clearSnapshot(ctx, id, paths);
|
|
1428
1451
|
return "restored";
|
|
1429
1452
|
}
|
|
1430
|
-
const
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
)) {
|
|
1434
|
-
return "modified";
|
|
1435
|
-
}
|
|
1436
|
-
restoreFiles(snapshot.files);
|
|
1437
|
-
removeIfExists(snapshotPath(ctx, id, paths));
|
|
1438
|
-
return "restored";
|
|
1453
|
+
const outcome = strip() ? "stripped" : "unchanged";
|
|
1454
|
+
clearSnapshot(ctx, id, paths);
|
|
1455
|
+
return outcome;
|
|
1439
1456
|
};
|
|
1440
1457
|
var clearSnapshot = (ctx, id, paths) => removeIfExists(snapshotPath(ctx, id, paths));
|
|
1441
1458
|
|
|
@@ -1443,7 +1460,7 @@ var clearSnapshot = (ctx, id, paths) => removeIfExists(snapshotPath(ctx, id, pat
|
|
|
1443
1460
|
var ID = "dsh";
|
|
1444
1461
|
var LABEL = "DeepSeek Harness";
|
|
1445
1462
|
var PROVIDER = "pollinations";
|
|
1446
|
-
var DEFAULT_MODEL = "deepseek";
|
|
1463
|
+
var DEFAULT_MODEL = "deepseek/deepseek-v4-flash";
|
|
1447
1464
|
var KEY_ENV = "POLLI_DSH_API_KEY";
|
|
1448
1465
|
var MCP_ID = "mcp-pollinations";
|
|
1449
1466
|
var MCP_URL = `${BASE_URL}/mcp/pollinations`;
|
|
@@ -1457,8 +1474,7 @@ var JS_TAG = {
|
|
|
1457
1474
|
var dshHome = (ctx) => {
|
|
1458
1475
|
const configured = ctx.env.DSH_HOME;
|
|
1459
1476
|
if (!configured?.trim()) return join4(ctx.home, ".dsh");
|
|
1460
|
-
|
|
1461
|
-
return resolve(expanded);
|
|
1477
|
+
return resolveHomePath(ctx.home, configured);
|
|
1462
1478
|
};
|
|
1463
1479
|
var settingsPath = (ctx) => join4(dshHome(ctx), "settings.yaml");
|
|
1464
1480
|
var envPath = (ctx) => join4(dshHome(ctx), ".env");
|
|
@@ -1638,12 +1654,7 @@ var configureDsh = (ctx, settings) => {
|
|
|
1638
1654
|
return result(ctx);
|
|
1639
1655
|
};
|
|
1640
1656
|
var disableDsh = (ctx) => {
|
|
1641
|
-
const
|
|
1642
|
-
let outcome = "restored";
|
|
1643
|
-
if (restoreSnapshot(ctx, ID, managedFiles) !== "restored") {
|
|
1644
|
-
outcome = stripConfig(ctx) ? "stripped" : "unchanged";
|
|
1645
|
-
clearSnapshot(ctx, ID, managedFiles);
|
|
1646
|
-
}
|
|
1657
|
+
const outcome = restoreOrStrip(ctx, ID, files(ctx), () => stripConfig(ctx));
|
|
1647
1658
|
return { ...result(ctx), configured: false, outcome };
|
|
1648
1659
|
};
|
|
1649
1660
|
var dsh = {
|
|
@@ -1658,12 +1669,7 @@ var dsh = {
|
|
|
1658
1669
|
);
|
|
1659
1670
|
}
|
|
1660
1671
|
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
|
-
}
|
|
1672
|
+
const models2 = await fetchHarnessModels(model);
|
|
1667
1673
|
const apiKey = await resolveHarnessKey(
|
|
1668
1674
|
{ id: ID, label: LABEL, existingKey: readKey(ctx) },
|
|
1669
1675
|
{ browser: options.browser }
|
|
@@ -1679,35 +1685,197 @@ var dsh = {
|
|
|
1679
1685
|
status: result
|
|
1680
1686
|
};
|
|
1681
1687
|
|
|
1688
|
+
// src/harnesses/openclaw.ts
|
|
1689
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
1690
|
+
import { join as join5 } from "path";
|
|
1691
|
+
import JSON5 from "json5";
|
|
1692
|
+
var ID2 = "openclaw";
|
|
1693
|
+
var LABEL2 = "OpenClaw";
|
|
1694
|
+
var PROVIDER2 = "pollinations";
|
|
1695
|
+
var DEFAULT_MODEL2 = "moonshotai/kimi-k2.6";
|
|
1696
|
+
var KEY_ENV2 = "POLLI_OPENCLAW_API_KEY";
|
|
1697
|
+
var openclawStateDir = (ctx) => {
|
|
1698
|
+
const stateDir = ctx.env.OPENCLAW_STATE_DIR?.trim();
|
|
1699
|
+
if (stateDir) return resolveHomePath(ctx.home, stateDir);
|
|
1700
|
+
const home = ctx.env.OPENCLAW_HOME?.trim();
|
|
1701
|
+
return join5(home ? resolveHomePath(ctx.home, home) : ctx.home, ".openclaw");
|
|
1702
|
+
};
|
|
1703
|
+
var configPath = (ctx) => {
|
|
1704
|
+
const override = ctx.env.OPENCLAW_CONFIG_PATH?.trim();
|
|
1705
|
+
return override ? resolveHomePath(ctx.home, override) : join5(openclawStateDir(ctx), "openclaw.json");
|
|
1706
|
+
};
|
|
1707
|
+
var skillFile = (ctx) => join5(openclawStateDir(ctx), "skills", "polli", "SKILL.md");
|
|
1708
|
+
var files2 = (ctx) => [configPath(ctx), skillFile(ctx)];
|
|
1709
|
+
var loadJson = (path) => {
|
|
1710
|
+
const text = readTextIfExists(path);
|
|
1711
|
+
if (!text?.trim()) return {};
|
|
1712
|
+
return JSON5.parse(text);
|
|
1713
|
+
};
|
|
1714
|
+
var saveJson = (path, data) => {
|
|
1715
|
+
writeTextAtomic(path, `${JSON.stringify(data, null, 2)}
|
|
1716
|
+
`, 384);
|
|
1717
|
+
};
|
|
1718
|
+
var readKey2 = (ctx) => {
|
|
1719
|
+
const env = loadJson(configPath(ctx)).env;
|
|
1720
|
+
const key = env?.vars?.[KEY_ENV2];
|
|
1721
|
+
return typeof key === "string" && key ? key : null;
|
|
1722
|
+
};
|
|
1723
|
+
var providerEntry = (models2) => ({
|
|
1724
|
+
baseUrl: `${BASE_URL}/v1`,
|
|
1725
|
+
apiKey: `\${${KEY_ENV2}}`,
|
|
1726
|
+
api: "openai-completions",
|
|
1727
|
+
models: models2.map((model) => ({
|
|
1728
|
+
id: model.id,
|
|
1729
|
+
name: model.id,
|
|
1730
|
+
contextWindow: model.contextWindow,
|
|
1731
|
+
input: model.input
|
|
1732
|
+
}))
|
|
1733
|
+
});
|
|
1734
|
+
var asRecord = (value) => value && typeof value === "object" ? value : {};
|
|
1735
|
+
var writeConfig2 = (ctx, models2, apiKey, model) => {
|
|
1736
|
+
const doc = loadJson(configPath(ctx));
|
|
1737
|
+
const env = asRecord(doc.env);
|
|
1738
|
+
const vars = asRecord(env.vars);
|
|
1739
|
+
vars[KEY_ENV2] = apiKey;
|
|
1740
|
+
env.vars = vars;
|
|
1741
|
+
doc.env = env;
|
|
1742
|
+
const modelsConfig = asRecord(doc.models);
|
|
1743
|
+
const providers = asRecord(modelsConfig.providers);
|
|
1744
|
+
providers[PROVIDER2] = providerEntry(models2);
|
|
1745
|
+
modelsConfig.providers = providers;
|
|
1746
|
+
doc.models = modelsConfig;
|
|
1747
|
+
const agents = asRecord(doc.agents);
|
|
1748
|
+
const defaults = asRecord(agents.defaults);
|
|
1749
|
+
const agentModel = asRecord(defaults.model);
|
|
1750
|
+
agentModel.primary = `${PROVIDER2}/${model}`;
|
|
1751
|
+
defaults.model = agentModel;
|
|
1752
|
+
agents.defaults = defaults;
|
|
1753
|
+
doc.agents = agents;
|
|
1754
|
+
saveJson(configPath(ctx), doc);
|
|
1755
|
+
if (readTextIfExists(skillFile(ctx)) === null) {
|
|
1756
|
+
writeTextAtomic(skillFile(ctx), SKILL_default, 384);
|
|
1757
|
+
}
|
|
1758
|
+
};
|
|
1759
|
+
var stripConfig2 = (ctx) => {
|
|
1760
|
+
let changed = false;
|
|
1761
|
+
const doc = loadJson(configPath(ctx));
|
|
1762
|
+
if (doc.env?.vars && KEY_ENV2 in asRecord(doc.env.vars)) {
|
|
1763
|
+
const vars = asRecord(doc.env.vars);
|
|
1764
|
+
delete vars[KEY_ENV2];
|
|
1765
|
+
if (Object.keys(vars).length === 0) delete doc.env.vars;
|
|
1766
|
+
saveJson(configPath(ctx), doc);
|
|
1767
|
+
changed = true;
|
|
1768
|
+
}
|
|
1769
|
+
const providers = asRecord(doc.models?.providers);
|
|
1770
|
+
if (PROVIDER2 in providers) {
|
|
1771
|
+
delete providers[PROVIDER2];
|
|
1772
|
+
if (Object.keys(providers).length === 0)
|
|
1773
|
+
delete asRecord(doc.models).providers;
|
|
1774
|
+
saveJson(configPath(ctx), doc);
|
|
1775
|
+
changed = true;
|
|
1776
|
+
}
|
|
1777
|
+
const primary = asRecord(doc.agents?.defaults?.model).primary;
|
|
1778
|
+
if (typeof primary === "string" && primary.startsWith(`${PROVIDER2}/`)) {
|
|
1779
|
+
delete asRecord(asRecord(doc.agents).defaults).model.primary;
|
|
1780
|
+
saveJson(configPath(ctx), doc);
|
|
1781
|
+
changed = true;
|
|
1782
|
+
}
|
|
1783
|
+
if (readTextIfExists(skillFile(ctx)) === SKILL_default) {
|
|
1784
|
+
removeIfExists(skillFile(ctx));
|
|
1785
|
+
changed = true;
|
|
1786
|
+
}
|
|
1787
|
+
return changed;
|
|
1788
|
+
};
|
|
1789
|
+
var result2 = (ctx) => {
|
|
1790
|
+
const doc = loadJson(configPath(ctx));
|
|
1791
|
+
const provider = asRecord(doc.models?.providers?.[PROVIDER2]);
|
|
1792
|
+
const primary = asRecord(doc.agents?.defaults?.model).primary;
|
|
1793
|
+
return {
|
|
1794
|
+
harness: ID2,
|
|
1795
|
+
label: LABEL2,
|
|
1796
|
+
configured: provider?.baseUrl === `${BASE_URL}/v1` && provider?.api === "openai-completions" && provider?.apiKey === `\${${KEY_ENV2}}` && typeof primary === "string" && primary.startsWith(`${PROVIDER2}/`) && readKey2(ctx) !== null && readTextIfExists(skillFile(ctx)) !== null,
|
|
1797
|
+
model: typeof primary === "string" && primary.startsWith(`${PROVIDER2}/`) ? primary.slice(`${PROVIDER2}/`.length) : void 0,
|
|
1798
|
+
files: files2(ctx)
|
|
1799
|
+
};
|
|
1800
|
+
};
|
|
1801
|
+
var configureOpenClaw = (ctx, models2, apiKey, model) => {
|
|
1802
|
+
applyWithSnapshot(
|
|
1803
|
+
ctx,
|
|
1804
|
+
ID2,
|
|
1805
|
+
files2(ctx),
|
|
1806
|
+
() => writeConfig2(ctx, models2, apiKey, model)
|
|
1807
|
+
);
|
|
1808
|
+
return result2(ctx);
|
|
1809
|
+
};
|
|
1810
|
+
var disableOpenClaw = (ctx) => {
|
|
1811
|
+
const outcome = restoreOrStrip(ctx, ID2, files2(ctx), () => stripConfig2(ctx));
|
|
1812
|
+
return { ...result2(ctx), configured: false, outcome };
|
|
1813
|
+
};
|
|
1814
|
+
var openclawInstalled = (ctx) => commandExists("openclaw", ctx.env);
|
|
1815
|
+
var initializeOpenClaw = (ctx) => {
|
|
1816
|
+
if (readTextIfExists(configPath(ctx)) !== null) return;
|
|
1817
|
+
const setup = spawnSync2("openclaw", ["setup", "--baseline"], {
|
|
1818
|
+
env: ctx.env,
|
|
1819
|
+
stdio: "ignore"
|
|
1820
|
+
});
|
|
1821
|
+
if (setup.error) throw setup.error;
|
|
1822
|
+
if (setup.status !== 0 || readTextIfExists(configPath(ctx)) === null) {
|
|
1823
|
+
throw new Error("OpenClaw baseline setup failed");
|
|
1824
|
+
}
|
|
1825
|
+
};
|
|
1826
|
+
var openclaw = {
|
|
1827
|
+
id: ID2,
|
|
1828
|
+
label: LABEL2,
|
|
1829
|
+
description: "Add Pollinations as a provider in OpenClaw",
|
|
1830
|
+
restartHint: "Restart the gateway: openclaw gateway restart (or /model inside chat to switch).",
|
|
1831
|
+
async on(ctx, options) {
|
|
1832
|
+
if (!openclawInstalled(ctx)) {
|
|
1833
|
+
throw new Error(
|
|
1834
|
+
"OpenClaw was not found. Install it from: https://openclaw.ai/install"
|
|
1835
|
+
);
|
|
1836
|
+
}
|
|
1837
|
+
const model = options.model ?? DEFAULT_MODEL2;
|
|
1838
|
+
const models2 = await fetchHarnessModels(model);
|
|
1839
|
+
initializeOpenClaw(ctx);
|
|
1840
|
+
const apiKey = await resolveHarnessKey(
|
|
1841
|
+
{ id: ID2, label: LABEL2, existingKey: readKey2(ctx) },
|
|
1842
|
+
{ browser: options.browser }
|
|
1843
|
+
);
|
|
1844
|
+
return configureOpenClaw(ctx, models2, apiKey, model);
|
|
1845
|
+
},
|
|
1846
|
+
off: disableOpenClaw,
|
|
1847
|
+
status: result2
|
|
1848
|
+
};
|
|
1849
|
+
|
|
1682
1850
|
// src/harnesses/opencode.ts
|
|
1683
|
-
import { join as
|
|
1684
|
-
|
|
1685
|
-
var
|
|
1686
|
-
var
|
|
1851
|
+
import { join as join6 } from "path";
|
|
1852
|
+
import JSON52 from "json5";
|
|
1853
|
+
var ID3 = "opencode";
|
|
1854
|
+
var LABEL3 = "OpenCode";
|
|
1855
|
+
var DEFAULT_MODEL3 = "openai/gpt-5.4-nano";
|
|
1687
1856
|
var PLUGIN_SPEC = "opencode-pollinations-plugin";
|
|
1688
1857
|
var pollinationsConfigDir = (ctx) => {
|
|
1689
1858
|
if (process.platform === "win32") {
|
|
1690
|
-
return
|
|
1859
|
+
return join6(ctx.env.APPDATA ?? ctx.home, "pollinations");
|
|
1691
1860
|
}
|
|
1692
1861
|
if (process.platform === "darwin") {
|
|
1693
|
-
return
|
|
1862
|
+
return join6(ctx.home, "Library", "Application Support", "pollinations");
|
|
1694
1863
|
}
|
|
1695
1864
|
const xdg = ctx.env.XDG_CONFIG_HOME?.trim();
|
|
1696
|
-
return
|
|
1697
|
-
xdg ?
|
|
1865
|
+
return join6(
|
|
1866
|
+
xdg ? resolveHomePath(ctx.home, xdg) : join6(ctx.home, ".config"),
|
|
1698
1867
|
"pollinations"
|
|
1699
1868
|
);
|
|
1700
1869
|
};
|
|
1701
|
-
var expandTilde = (ctx, path) => path === "~" ? ctx.home : path.startsWith("~/") || path.startsWith("~\\") ? join5(ctx.home, path.slice(2)) : path;
|
|
1702
1870
|
var opencodeConfigFile = (ctx) => {
|
|
1703
1871
|
if (ctx.env.OPENCODE_CONFIG?.trim()) {
|
|
1704
|
-
return
|
|
1872
|
+
return resolveHomePath(ctx.home, ctx.env.OPENCODE_CONFIG);
|
|
1705
1873
|
}
|
|
1706
|
-
const dir = ctx.env.OPENCODE_CONFIG_DIR?.trim() ?
|
|
1707
|
-
return
|
|
1874
|
+
const dir = ctx.env.OPENCODE_CONFIG_DIR?.trim() ? resolveHomePath(ctx.home, ctx.env.OPENCODE_CONFIG_DIR) : join6(ctx.home, ".config", "opencode");
|
|
1875
|
+
return ["opencode.jsonc", "opencode.json", "config.json"].map((name) => join6(dir, name)).find((path) => readTextIfExists(path) !== null) ?? join6(dir, "opencode.json");
|
|
1708
1876
|
};
|
|
1709
|
-
var pluginConfigFile = (ctx) =>
|
|
1710
|
-
var
|
|
1877
|
+
var pluginConfigFile = (ctx) => join6(pollinationsConfigDir(ctx), "config.json");
|
|
1878
|
+
var files3 = (ctx) => [
|
|
1711
1879
|
opencodeConfigFile(ctx),
|
|
1712
1880
|
pluginConfigFile(ctx)
|
|
1713
1881
|
];
|
|
@@ -1715,13 +1883,18 @@ var readJson = (path) => {
|
|
|
1715
1883
|
const text = readTextIfExists(path);
|
|
1716
1884
|
if (text === null) return null;
|
|
1717
1885
|
try {
|
|
1718
|
-
const parsed =
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1886
|
+
const parsed = JSON52.parse(text);
|
|
1887
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1888
|
+
return parsed;
|
|
1889
|
+
}
|
|
1890
|
+
} catch (error) {
|
|
1891
|
+
throw new Error(`Could not parse OpenCode config at ${path}`, {
|
|
1892
|
+
cause: error
|
|
1893
|
+
});
|
|
1722
1894
|
}
|
|
1895
|
+
throw new Error(`OpenCode config at ${path} must contain an object`);
|
|
1723
1896
|
};
|
|
1724
|
-
var writeJson = (
|
|
1897
|
+
var writeJson = (path, data) => writeTextAtomic(path, `${JSON.stringify(data, null, 2)}
|
|
1725
1898
|
`, 384);
|
|
1726
1899
|
var isPluginEntry = (entry) => typeof entry === "string" ? entry === PLUGIN_SPEC || entry.includes(PLUGIN_SPEC) : entry !== null && typeof entry === "object" && Object.values(entry).some(
|
|
1727
1900
|
(value) => typeof value === "string" && value.includes(PLUGIN_SPEC)
|
|
@@ -1732,13 +1905,13 @@ var hasPluginEntry = (config) => {
|
|
|
1732
1905
|
return Array.isArray(entries) && entries.some(isPluginEntry);
|
|
1733
1906
|
};
|
|
1734
1907
|
var readApiKey = (ctx) => {
|
|
1735
|
-
const key =
|
|
1908
|
+
const key = readJson(pluginConfigFile(ctx))?.apiKey;
|
|
1736
1909
|
return typeof key === "string" && key.length > 5 ? key : null;
|
|
1737
1910
|
};
|
|
1738
1911
|
var writeApiKey = (ctx, apiKey) => {
|
|
1739
1912
|
const config = readJson(pluginConfigFile(ctx)) ?? {};
|
|
1740
1913
|
config.apiKey = apiKey;
|
|
1741
|
-
writeJson(
|
|
1914
|
+
writeJson(pluginConfigFile(ctx), config);
|
|
1742
1915
|
};
|
|
1743
1916
|
var deleteApiKey = (ctx) => {
|
|
1744
1917
|
const path = pluginConfigFile(ctx);
|
|
@@ -1746,7 +1919,7 @@ var deleteApiKey = (ctx) => {
|
|
|
1746
1919
|
if (config === null || config.apiKey === void 0) return false;
|
|
1747
1920
|
delete config.apiKey;
|
|
1748
1921
|
if (Object.keys(config).length === 0) removeIfExists(path);
|
|
1749
|
-
else writeJson(
|
|
1922
|
+
else writeJson(path, config);
|
|
1750
1923
|
return true;
|
|
1751
1924
|
};
|
|
1752
1925
|
var openCodeConfig = (ctx) => readJson(opencodeConfigFile(ctx)) ?? {};
|
|
@@ -1763,7 +1936,7 @@ var writeOpenCodeConfig = (ctx, model) => {
|
|
|
1763
1936
|
config[key] = [...entries, PLUGIN_SPEC];
|
|
1764
1937
|
}
|
|
1765
1938
|
config.model = defaultModelRef(model);
|
|
1766
|
-
writeJson(
|
|
1939
|
+
writeJson(opencodeConfigFile(ctx), config);
|
|
1767
1940
|
};
|
|
1768
1941
|
var stripOpenCodeConfig = (ctx) => {
|
|
1769
1942
|
const path = opencodeConfigFile(ctx);
|
|
@@ -1782,48 +1955,43 @@ var stripOpenCodeConfig = (ctx) => {
|
|
|
1782
1955
|
delete config.model;
|
|
1783
1956
|
changed = true;
|
|
1784
1957
|
}
|
|
1785
|
-
if (changed) writeJson(
|
|
1958
|
+
if (changed) writeJson(path, config);
|
|
1786
1959
|
return changed;
|
|
1787
1960
|
};
|
|
1788
|
-
var
|
|
1961
|
+
var result3 = (ctx) => {
|
|
1789
1962
|
const config = openCodeConfig(ctx);
|
|
1790
1963
|
const model = isOurDefaultModel(config.model) ? config.model.slice("pollinations/enter/".length) : void 0;
|
|
1791
1964
|
return {
|
|
1792
|
-
harness:
|
|
1793
|
-
label:
|
|
1965
|
+
harness: ID3,
|
|
1966
|
+
label: LABEL3,
|
|
1794
1967
|
configured: hasPluginEntry(config) && isOurDefaultModel(config.model) && readApiKey(ctx) !== null,
|
|
1795
1968
|
model,
|
|
1796
|
-
files:
|
|
1969
|
+
files: files3(ctx)
|
|
1797
1970
|
};
|
|
1798
1971
|
};
|
|
1799
|
-
var
|
|
1972
|
+
var writeConfig3 = (ctx, settings) => {
|
|
1800
1973
|
writeOpenCodeConfig(ctx, settings.model);
|
|
1801
1974
|
writeApiKey(ctx, settings.apiKey);
|
|
1802
1975
|
};
|
|
1803
|
-
var
|
|
1976
|
+
var stripConfig3 = (ctx) => {
|
|
1804
1977
|
let changed = stripOpenCodeConfig(ctx);
|
|
1805
1978
|
changed = deleteApiKey(ctx) || changed;
|
|
1806
1979
|
return changed;
|
|
1807
1980
|
};
|
|
1808
1981
|
var configureOpenCode = (ctx, settings) => {
|
|
1809
|
-
applyWithSnapshot(ctx,
|
|
1810
|
-
return
|
|
1982
|
+
applyWithSnapshot(ctx, ID3, files3(ctx), () => writeConfig3(ctx, settings));
|
|
1983
|
+
return result3(ctx);
|
|
1811
1984
|
};
|
|
1812
1985
|
var disableOpenCode = (ctx) => {
|
|
1813
|
-
const
|
|
1814
|
-
|
|
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 };
|
|
1986
|
+
const outcome = restoreOrStrip(ctx, ID3, files3(ctx), () => stripConfig3(ctx));
|
|
1987
|
+
return { ...result3(ctx), configured: false, outcome };
|
|
1820
1988
|
};
|
|
1821
1989
|
var openCodeInstalled = (ctx) => commandExists("opencode", ctx.env, [
|
|
1822
|
-
|
|
1990
|
+
join6(ctx.home, ".opencode", "bin", "opencode")
|
|
1823
1991
|
]);
|
|
1824
1992
|
var opencode = {
|
|
1825
|
-
id:
|
|
1826
|
-
label:
|
|
1993
|
+
id: ID3,
|
|
1994
|
+
label: LABEL3,
|
|
1827
1995
|
description: "Configure OpenCode to use Pollinations",
|
|
1828
1996
|
restartHint: "Restart OpenCode, then pick a Pollinations model with /models. Inside OpenCode: /poll quests shows claimable Pollen, /poll help lists the media tools.",
|
|
1829
1997
|
async on(ctx, options) {
|
|
@@ -1832,17 +2000,12 @@ var opencode = {
|
|
|
1832
2000
|
"OpenCode was not found. Install it first: curl -fsSL https://opencode.ai/install | bash"
|
|
1833
2001
|
);
|
|
1834
2002
|
}
|
|
1835
|
-
const model = options.model ??
|
|
1836
|
-
|
|
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
|
-
}
|
|
2003
|
+
const model = options.model ?? DEFAULT_MODEL3;
|
|
2004
|
+
await fetchHarnessModels(model);
|
|
1842
2005
|
const apiKey = await resolveHarnessKey(
|
|
1843
2006
|
{
|
|
1844
|
-
id:
|
|
1845
|
-
label:
|
|
2007
|
+
id: ID3,
|
|
2008
|
+
label: LABEL3,
|
|
1846
2009
|
existingKey: readApiKey(ctx),
|
|
1847
2010
|
accountPermissions: ["profile", "usage"]
|
|
1848
2011
|
},
|
|
@@ -1851,43 +2014,42 @@ var opencode = {
|
|
|
1851
2014
|
return configureOpenCode(ctx, { apiKey, model });
|
|
1852
2015
|
},
|
|
1853
2016
|
off: disableOpenCode,
|
|
1854
|
-
status:
|
|
2017
|
+
status: result3
|
|
1855
2018
|
};
|
|
1856
2019
|
|
|
1857
2020
|
// src/harnesses/pi.ts
|
|
1858
|
-
import { join as
|
|
1859
|
-
var
|
|
1860
|
-
var
|
|
1861
|
-
var
|
|
1862
|
-
var
|
|
2021
|
+
import { join as join7 } from "path";
|
|
2022
|
+
var ID4 = "pi";
|
|
2023
|
+
var LABEL4 = "Pi";
|
|
2024
|
+
var PROVIDER3 = "pollinations";
|
|
2025
|
+
var DEFAULT_MODEL4 = "deepseek/deepseek-v4-flash";
|
|
1863
2026
|
var piAgentDir = (ctx) => {
|
|
1864
2027
|
const configured = ctx.env.PI_CODING_AGENT_DIR;
|
|
1865
|
-
if (!configured?.trim()) return
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
var
|
|
1870
|
-
var
|
|
1871
|
-
var
|
|
1872
|
-
var
|
|
1873
|
-
var files3 = (ctx) => [
|
|
2028
|
+
if (!configured?.trim()) return join7(ctx.home, ".pi", "agent");
|
|
2029
|
+
return resolveHomePath(ctx.home, configured);
|
|
2030
|
+
};
|
|
2031
|
+
var modelsPath = (ctx) => join7(piAgentDir(ctx), "models.json");
|
|
2032
|
+
var authPath = (ctx) => join7(piAgentDir(ctx), "auth.json");
|
|
2033
|
+
var settingsPath2 = (ctx) => join7(piAgentDir(ctx), "settings.json");
|
|
2034
|
+
var skillFile2 = (ctx) => join7(piAgentDir(ctx), "skills", "polli", "SKILL.md");
|
|
2035
|
+
var files4 = (ctx) => [
|
|
1874
2036
|
modelsPath(ctx),
|
|
1875
2037
|
authPath(ctx),
|
|
1876
2038
|
settingsPath2(ctx),
|
|
1877
|
-
|
|
2039
|
+
skillFile2(ctx)
|
|
1878
2040
|
];
|
|
1879
|
-
var
|
|
2041
|
+
var loadJson2 = (path) => {
|
|
1880
2042
|
const text = readTextIfExists(path);
|
|
1881
2043
|
if (!text?.trim()) return {};
|
|
1882
2044
|
return JSON.parse(text);
|
|
1883
2045
|
};
|
|
1884
|
-
var
|
|
2046
|
+
var saveJson2 = (path, data) => {
|
|
1885
2047
|
writeTextAtomic(path, `${JSON.stringify(data, null, 2)}
|
|
1886
2048
|
`, 384);
|
|
1887
2049
|
};
|
|
1888
|
-
var
|
|
1889
|
-
const auth =
|
|
1890
|
-
const entry = auth[
|
|
2050
|
+
var readKey3 = (ctx) => {
|
|
2051
|
+
const auth = loadJson2(authPath(ctx));
|
|
2052
|
+
const entry = auth[PROVIDER3];
|
|
1891
2053
|
if (!entry || typeof entry !== "object") return null;
|
|
1892
2054
|
const key = entry.key;
|
|
1893
2055
|
return typeof key === "string" && key ? key : null;
|
|
@@ -1895,8 +2057,6 @@ var readKey2 = (ctx) => {
|
|
|
1895
2057
|
var providerConfig2 = (models2) => ({
|
|
1896
2058
|
baseUrl: `${BASE_URL}/v1`,
|
|
1897
2059
|
api: "openai-completions",
|
|
1898
|
-
// Pi validates custom providers before resolving their auth.json entry.
|
|
1899
|
-
apiKey: PROVIDER2,
|
|
1900
2060
|
compat: {
|
|
1901
2061
|
supportsStore: false,
|
|
1902
2062
|
supportsDeveloperRole: false,
|
|
@@ -1912,96 +2072,91 @@ var providerConfig2 = (models2) => ({
|
|
|
1912
2072
|
input: model.input
|
|
1913
2073
|
}))
|
|
1914
2074
|
});
|
|
1915
|
-
var
|
|
1916
|
-
const modelsData =
|
|
2075
|
+
var writeConfig4 = (ctx, settings) => {
|
|
2076
|
+
const modelsData = loadJson2(modelsPath(ctx));
|
|
1917
2077
|
const providers = modelsData.providers ?? {};
|
|
1918
2078
|
modelsData.providers = {
|
|
1919
2079
|
...providers,
|
|
1920
|
-
[
|
|
2080
|
+
[PROVIDER3]: providerConfig2(settings.models)
|
|
1921
2081
|
};
|
|
1922
|
-
|
|
1923
|
-
const auth =
|
|
1924
|
-
auth[
|
|
1925
|
-
|
|
1926
|
-
const piSettings =
|
|
1927
|
-
piSettings.defaultProvider =
|
|
2082
|
+
saveJson2(modelsPath(ctx), modelsData);
|
|
2083
|
+
const auth = loadJson2(authPath(ctx));
|
|
2084
|
+
auth[PROVIDER3] = { type: "api_key", key: settings.apiKey };
|
|
2085
|
+
saveJson2(authPath(ctx), auth);
|
|
2086
|
+
const piSettings = loadJson2(settingsPath2(ctx));
|
|
2087
|
+
piSettings.defaultProvider = PROVIDER3;
|
|
1928
2088
|
piSettings.defaultModel = settings.model;
|
|
1929
|
-
|
|
1930
|
-
if (readTextIfExists(
|
|
1931
|
-
writeTextAtomic(
|
|
2089
|
+
saveJson2(settingsPath2(ctx), piSettings);
|
|
2090
|
+
if (readTextIfExists(skillFile2(ctx)) === null) {
|
|
2091
|
+
writeTextAtomic(skillFile2(ctx), SKILL_default, 384);
|
|
1932
2092
|
}
|
|
1933
2093
|
};
|
|
1934
|
-
var
|
|
2094
|
+
var stripConfig4 = (ctx) => {
|
|
1935
2095
|
let changed = false;
|
|
1936
2096
|
const modelsText = readTextIfExists(modelsPath(ctx));
|
|
1937
2097
|
if (modelsText?.trim()) {
|
|
1938
2098
|
const data = JSON.parse(modelsText);
|
|
1939
|
-
if (data.providers && typeof data.providers === "object" &&
|
|
1940
|
-
delete data.providers[
|
|
1941
|
-
|
|
2099
|
+
if (data.providers && typeof data.providers === "object" && PROVIDER3 in data.providers) {
|
|
2100
|
+
delete data.providers[PROVIDER3];
|
|
2101
|
+
saveJson2(modelsPath(ctx), data);
|
|
1942
2102
|
changed = true;
|
|
1943
2103
|
}
|
|
1944
2104
|
}
|
|
1945
2105
|
const authText = readTextIfExists(authPath(ctx));
|
|
1946
2106
|
if (authText?.trim()) {
|
|
1947
2107
|
const data = JSON.parse(authText);
|
|
1948
|
-
if (
|
|
1949
|
-
delete data[
|
|
1950
|
-
|
|
2108
|
+
if (PROVIDER3 in data) {
|
|
2109
|
+
delete data[PROVIDER3];
|
|
2110
|
+
saveJson2(authPath(ctx), data);
|
|
1951
2111
|
changed = true;
|
|
1952
2112
|
}
|
|
1953
2113
|
}
|
|
1954
2114
|
const settingsText = readTextIfExists(settingsPath2(ctx));
|
|
1955
2115
|
if (settingsText?.trim()) {
|
|
1956
2116
|
const data = JSON.parse(settingsText);
|
|
1957
|
-
if (data.defaultProvider ===
|
|
2117
|
+
if (data.defaultProvider === PROVIDER3) {
|
|
1958
2118
|
delete data.defaultProvider;
|
|
1959
2119
|
delete data.defaultModel;
|
|
1960
|
-
|
|
2120
|
+
saveJson2(settingsPath2(ctx), data);
|
|
1961
2121
|
changed = true;
|
|
1962
2122
|
}
|
|
1963
2123
|
}
|
|
1964
|
-
if (readTextIfExists(
|
|
1965
|
-
removeIfExists(
|
|
2124
|
+
if (readTextIfExists(skillFile2(ctx)) === SKILL_default) {
|
|
2125
|
+
removeIfExists(skillFile2(ctx));
|
|
1966
2126
|
changed = true;
|
|
1967
2127
|
}
|
|
1968
2128
|
return changed;
|
|
1969
2129
|
};
|
|
1970
|
-
var
|
|
1971
|
-
const modelsData =
|
|
1972
|
-
const authData =
|
|
1973
|
-
const settingsData =
|
|
2130
|
+
var result4 = (ctx) => {
|
|
2131
|
+
const modelsData = loadJson2(modelsPath(ctx));
|
|
2132
|
+
const authData = loadJson2(authPath(ctx));
|
|
2133
|
+
const settingsData = loadJson2(settingsPath2(ctx));
|
|
1974
2134
|
const providers = modelsData.providers;
|
|
1975
|
-
const provider = providers?.[
|
|
1976
|
-
const hasProvider = provider?.
|
|
1977
|
-
const authEntry = authData[
|
|
2135
|
+
const provider = providers?.[PROVIDER3];
|
|
2136
|
+
const hasProvider = provider?.baseUrl === `${BASE_URL}/v1` && provider?.api === "openai-completions";
|
|
2137
|
+
const authEntry = authData[PROVIDER3];
|
|
1978
2138
|
const hasKey = authEntry?.type === "api_key" && typeof authEntry.key === "string" && !!authEntry.key;
|
|
1979
|
-
const hasDefaultProvider = settingsData.defaultProvider ===
|
|
2139
|
+
const hasDefaultProvider = settingsData.defaultProvider === PROVIDER3;
|
|
1980
2140
|
const model = typeof settingsData.defaultModel === "string" ? settingsData.defaultModel : void 0;
|
|
1981
2141
|
return {
|
|
1982
|
-
harness:
|
|
1983
|
-
label:
|
|
1984
|
-
configured: hasProvider && hasKey && hasDefaultProvider && readTextIfExists(
|
|
2142
|
+
harness: ID4,
|
|
2143
|
+
label: LABEL4,
|
|
2144
|
+
configured: hasProvider && hasKey && hasDefaultProvider && readTextIfExists(skillFile2(ctx)) !== null,
|
|
1985
2145
|
model,
|
|
1986
|
-
files:
|
|
2146
|
+
files: files4(ctx)
|
|
1987
2147
|
};
|
|
1988
2148
|
};
|
|
1989
2149
|
var configurePi = (ctx, settings) => {
|
|
1990
|
-
applyWithSnapshot(ctx,
|
|
1991
|
-
return
|
|
2150
|
+
applyWithSnapshot(ctx, ID4, files4(ctx), () => writeConfig4(ctx, settings));
|
|
2151
|
+
return result4(ctx);
|
|
1992
2152
|
};
|
|
1993
2153
|
var disablePi = (ctx) => {
|
|
1994
|
-
const
|
|
1995
|
-
|
|
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 };
|
|
2154
|
+
const outcome = restoreOrStrip(ctx, ID4, files4(ctx), () => stripConfig4(ctx));
|
|
2155
|
+
return { ...result4(ctx), configured: false, outcome };
|
|
2001
2156
|
};
|
|
2002
2157
|
var pi = {
|
|
2003
|
-
id:
|
|
2004
|
-
label:
|
|
2158
|
+
id: ID4,
|
|
2159
|
+
label: LABEL4,
|
|
2005
2160
|
description: "Configure Pi as a Pollinations provider",
|
|
2006
2161
|
restartHint: "Changes apply on the next Pi session. Start Pi with: pi",
|
|
2007
2162
|
async on(ctx, options) {
|
|
@@ -2010,25 +2165,176 @@ var pi = {
|
|
|
2010
2165
|
"Pi was not found. Install it first: npm install -g --ignore-scripts @earendil-works/pi-coding-agent"
|
|
2011
2166
|
);
|
|
2012
2167
|
}
|
|
2013
|
-
const model = options.model ??
|
|
2014
|
-
const models2 = await fetchHarnessModels();
|
|
2015
|
-
|
|
2168
|
+
const model = options.model ?? DEFAULT_MODEL4;
|
|
2169
|
+
const models2 = await fetchHarnessModels(model);
|
|
2170
|
+
const apiKey = await resolveHarnessKey(
|
|
2171
|
+
{ id: ID4, label: LABEL4, existingKey: readKey3(ctx) },
|
|
2172
|
+
{ browser: options.browser }
|
|
2173
|
+
);
|
|
2174
|
+
return configurePi(ctx, { apiKey, model, models: models2 });
|
|
2175
|
+
},
|
|
2176
|
+
off: disablePi,
|
|
2177
|
+
status: result4
|
|
2178
|
+
};
|
|
2179
|
+
|
|
2180
|
+
// src/harnesses/prime.ts
|
|
2181
|
+
import { join as join8 } from "path";
|
|
2182
|
+
var ID5 = "prime";
|
|
2183
|
+
var LABEL5 = "Prime Agent";
|
|
2184
|
+
var PROVIDER4 = "pollinations";
|
|
2185
|
+
var DEFAULT_MODEL5 = "deepseek/deepseek-v4-flash";
|
|
2186
|
+
var primeAgentDir = (ctx) => {
|
|
2187
|
+
const configured = ctx.env.PRIME_AGENT_CODING_AGENT_DIR;
|
|
2188
|
+
if (!configured?.trim()) return join8(ctx.home, ".prime", "agent");
|
|
2189
|
+
return resolveHomePath(ctx.home, configured);
|
|
2190
|
+
};
|
|
2191
|
+
var modelsPath2 = (ctx) => join8(primeAgentDir(ctx), "models.json");
|
|
2192
|
+
var authPath2 = (ctx) => join8(primeAgentDir(ctx), "auth.json");
|
|
2193
|
+
var settingsPath3 = (ctx) => join8(primeAgentDir(ctx), "settings.json");
|
|
2194
|
+
var skillPath2 = (ctx) => join8(primeAgentDir(ctx), "skills", "polli", "SKILL.md");
|
|
2195
|
+
var files5 = (ctx) => [
|
|
2196
|
+
modelsPath2(ctx),
|
|
2197
|
+
authPath2(ctx),
|
|
2198
|
+
settingsPath3(ctx),
|
|
2199
|
+
skillPath2(ctx)
|
|
2200
|
+
];
|
|
2201
|
+
var loadJson3 = (path) => {
|
|
2202
|
+
const text = readTextIfExists(path);
|
|
2203
|
+
if (!text?.trim()) return {};
|
|
2204
|
+
return JSON.parse(text);
|
|
2205
|
+
};
|
|
2206
|
+
var saveJson3 = (path, data) => {
|
|
2207
|
+
writeTextAtomic(path, `${JSON.stringify(data, null, 2)}
|
|
2208
|
+
`, 384);
|
|
2209
|
+
};
|
|
2210
|
+
var compat = {
|
|
2211
|
+
supportsStore: false,
|
|
2212
|
+
supportsDeveloperRole: false,
|
|
2213
|
+
supportsReasoningEffort: true,
|
|
2214
|
+
supportsUsageInStreaming: true,
|
|
2215
|
+
supportsStrictMode: false,
|
|
2216
|
+
maxTokensField: "max_tokens"
|
|
2217
|
+
};
|
|
2218
|
+
var providerEntry2 = (models2) => ({
|
|
2219
|
+
baseUrl: `${BASE_URL}/v1`,
|
|
2220
|
+
api: "openai-completions",
|
|
2221
|
+
// Prime validates custom providers before resolving their auth.json entry.
|
|
2222
|
+
apiKey: PROVIDER4,
|
|
2223
|
+
compat,
|
|
2224
|
+
models: models2.map((model) => ({
|
|
2225
|
+
id: model.id,
|
|
2226
|
+
name: model.id,
|
|
2227
|
+
input: model.input,
|
|
2228
|
+
contextWindow: model.contextWindow
|
|
2229
|
+
}))
|
|
2230
|
+
});
|
|
2231
|
+
var readKey4 = (ctx) => {
|
|
2232
|
+
const auth = loadJson3(authPath2(ctx));
|
|
2233
|
+
const credential = auth[PROVIDER4];
|
|
2234
|
+
return credential?.type === "api_key" && credential.key ? credential.key : null;
|
|
2235
|
+
};
|
|
2236
|
+
var writeAuth = (ctx, apiKey) => {
|
|
2237
|
+
const auth = loadJson3(authPath2(ctx));
|
|
2238
|
+
auth[PROVIDER4] = { type: "api_key", key: apiKey };
|
|
2239
|
+
saveJson3(authPath2(ctx), auth);
|
|
2240
|
+
};
|
|
2241
|
+
var deleteAuth = (ctx) => {
|
|
2242
|
+
const auth = loadJson3(authPath2(ctx));
|
|
2243
|
+
if (!(PROVIDER4 in auth)) return false;
|
|
2244
|
+
delete auth[PROVIDER4];
|
|
2245
|
+
if (Object.keys(auth).length === 0) removeIfExists(authPath2(ctx));
|
|
2246
|
+
else saveJson3(authPath2(ctx), auth);
|
|
2247
|
+
return true;
|
|
2248
|
+
};
|
|
2249
|
+
var writeConfig5 = (ctx, models2, apiKey, model) => {
|
|
2250
|
+
const doc = loadJson3(modelsPath2(ctx));
|
|
2251
|
+
const providers = doc.providers ?? {};
|
|
2252
|
+
providers[PROVIDER4] = providerEntry2(models2);
|
|
2253
|
+
doc.providers = providers;
|
|
2254
|
+
saveJson3(modelsPath2(ctx), doc);
|
|
2255
|
+
writeAuth(ctx, apiKey);
|
|
2256
|
+
const settings = loadJson3(settingsPath3(ctx));
|
|
2257
|
+
settings.defaultProvider = PROVIDER4;
|
|
2258
|
+
settings.defaultModel = model;
|
|
2259
|
+
saveJson3(settingsPath3(ctx), settings);
|
|
2260
|
+
if (readTextIfExists(skillPath2(ctx)) === null) {
|
|
2261
|
+
writeTextAtomic(skillPath2(ctx), SKILL_default, 384);
|
|
2262
|
+
}
|
|
2263
|
+
};
|
|
2264
|
+
var stripConfig5 = (ctx) => {
|
|
2265
|
+
let changed = false;
|
|
2266
|
+
const doc = loadJson3(modelsPath2(ctx));
|
|
2267
|
+
if (doc?.providers && PROVIDER4 in doc.providers) {
|
|
2268
|
+
delete doc.providers[PROVIDER4];
|
|
2269
|
+
if (Object.keys(doc.providers).length === 0) delete doc.providers;
|
|
2270
|
+
saveJson3(modelsPath2(ctx), doc);
|
|
2271
|
+
changed = true;
|
|
2272
|
+
}
|
|
2273
|
+
changed = deleteAuth(ctx) || changed;
|
|
2274
|
+
const settings = loadJson3(settingsPath3(ctx));
|
|
2275
|
+
if (settings && settings.defaultProvider === PROVIDER4) {
|
|
2276
|
+
delete settings.defaultProvider;
|
|
2277
|
+
delete settings.defaultModel;
|
|
2278
|
+
saveJson3(settingsPath3(ctx), settings);
|
|
2279
|
+
changed = true;
|
|
2280
|
+
}
|
|
2281
|
+
if (readTextIfExists(skillPath2(ctx)) === SKILL_default) {
|
|
2282
|
+
removeIfExists(skillPath2(ctx));
|
|
2283
|
+
changed = true;
|
|
2284
|
+
}
|
|
2285
|
+
return changed;
|
|
2286
|
+
};
|
|
2287
|
+
var result5 = (ctx) => {
|
|
2288
|
+
const doc = loadJson3(modelsPath2(ctx));
|
|
2289
|
+
const provider = doc?.providers?.[PROVIDER4];
|
|
2290
|
+
const settings = loadJson3(settingsPath3(ctx));
|
|
2291
|
+
const model = settings?.defaultProvider === PROVIDER4 ? settings.defaultModel : void 0;
|
|
2292
|
+
return {
|
|
2293
|
+
harness: ID5,
|
|
2294
|
+
label: LABEL5,
|
|
2295
|
+
configured: provider?.baseUrl === `${BASE_URL}/v1` && provider?.api === "openai-completions" && provider?.apiKey === PROVIDER4 && readKey4(ctx) !== null && readTextIfExists(skillPath2(ctx)) !== null,
|
|
2296
|
+
model: typeof model === "string" ? model : void 0,
|
|
2297
|
+
files: files5(ctx)
|
|
2298
|
+
};
|
|
2299
|
+
};
|
|
2300
|
+
var configurePrime = (ctx, models2, apiKey, model) => {
|
|
2301
|
+
applyWithSnapshot(
|
|
2302
|
+
ctx,
|
|
2303
|
+
ID5,
|
|
2304
|
+
files5(ctx),
|
|
2305
|
+
() => writeConfig5(ctx, models2, apiKey, model)
|
|
2306
|
+
);
|
|
2307
|
+
return result5(ctx);
|
|
2308
|
+
};
|
|
2309
|
+
var disablePrime = (ctx) => {
|
|
2310
|
+
const outcome = restoreOrStrip(ctx, ID5, files5(ctx), () => stripConfig5(ctx));
|
|
2311
|
+
return { ...result5(ctx), configured: false, outcome };
|
|
2312
|
+
};
|
|
2313
|
+
var prime = {
|
|
2314
|
+
id: ID5,
|
|
2315
|
+
label: LABEL5,
|
|
2316
|
+
description: "Add Pollinations as a custom provider in Prime Agent",
|
|
2317
|
+
restartHint: "Models reload when you open /model. Start Prime Agent with: prime-agent",
|
|
2318
|
+
async on(ctx, options) {
|
|
2319
|
+
if (!commandExists("prime-agent", ctx.env)) {
|
|
2016
2320
|
throw new Error(
|
|
2017
|
-
|
|
2321
|
+
"Prime Agent was not found. Install it first: curl -fsSL https://app.primeintellect.ai/prime-agent/install.sh | sh"
|
|
2018
2322
|
);
|
|
2019
2323
|
}
|
|
2324
|
+
const model = options.model ?? DEFAULT_MODEL5;
|
|
2325
|
+
const models2 = await fetchHarnessModels(model);
|
|
2020
2326
|
const apiKey = await resolveHarnessKey(
|
|
2021
|
-
{ id:
|
|
2327
|
+
{ id: ID5, label: LABEL5, existingKey: readKey4(ctx) },
|
|
2022
2328
|
{ browser: options.browser }
|
|
2023
2329
|
);
|
|
2024
|
-
return
|
|
2330
|
+
return configurePrime(ctx, models2, apiKey, model);
|
|
2025
2331
|
},
|
|
2026
|
-
off:
|
|
2027
|
-
status:
|
|
2332
|
+
off: disablePrime,
|
|
2333
|
+
status: result5
|
|
2028
2334
|
};
|
|
2029
2335
|
|
|
2030
2336
|
// src/harnesses/index.ts
|
|
2031
|
-
var HARNESSES = [dsh, opencode, pi];
|
|
2337
|
+
var HARNESSES = [dsh, opencode, openclaw, pi, prime];
|
|
2032
2338
|
|
|
2033
2339
|
// src/commands/harness.ts
|
|
2034
2340
|
var context = () => ({ home: homedir2(), env: process.env });
|
|
@@ -2039,22 +2345,22 @@ var OFF_MESSAGES = {
|
|
|
2039
2345
|
};
|
|
2040
2346
|
var runOn = async (harness, options) => {
|
|
2041
2347
|
try {
|
|
2042
|
-
const
|
|
2043
|
-
const model =
|
|
2348
|
+
const result6 = await harness.on(context(), options);
|
|
2349
|
+
const model = result6.model ? ` (model: ${result6.model})` : "";
|
|
2044
2350
|
printSuccess(`${harness.label} now uses Pollinations${model}.`);
|
|
2045
2351
|
printInfo(harness.restartHint);
|
|
2046
|
-
printResult(
|
|
2352
|
+
printResult(result6);
|
|
2047
2353
|
} catch (error) {
|
|
2048
2354
|
fail(`Failed to connect ${harness.label}`, error);
|
|
2049
2355
|
}
|
|
2050
2356
|
};
|
|
2051
2357
|
var runOff = async (harness) => {
|
|
2052
2358
|
try {
|
|
2053
|
-
const
|
|
2054
|
-
const outcome =
|
|
2359
|
+
const result6 = await harness.off(context());
|
|
2360
|
+
const outcome = result6.outcome ?? "unchanged";
|
|
2055
2361
|
printSuccess(`${harness.label}: ${OFF_MESSAGES[outcome]}`);
|
|
2056
2362
|
if (outcome !== "unchanged") printInfo(harness.restartHint);
|
|
2057
|
-
printResult(
|
|
2363
|
+
printResult(result6);
|
|
2058
2364
|
} catch (error) {
|
|
2059
2365
|
fail(`Failed to disconnect ${harness.label}`, error);
|
|
2060
2366
|
}
|
|
@@ -2472,13 +2778,35 @@ function readPriceOptions(opts) {
|
|
|
2472
2778
|
}
|
|
2473
2779
|
return prices;
|
|
2474
2780
|
}
|
|
2781
|
+
function commaSeparatedList(value) {
|
|
2782
|
+
return String(value).split(",").map((item) => item.trim()).filter(Boolean);
|
|
2783
|
+
}
|
|
2784
|
+
function endpointTarget(opts, required) {
|
|
2785
|
+
if (opts.api !== void 0 || opts.url !== void 0 || required && (opts.modality ?? "text") === "text") {
|
|
2786
|
+
if (opts.baseUrl !== void 0) {
|
|
2787
|
+
fail("Text endpoints use --api and --url; omit --base-url");
|
|
2788
|
+
}
|
|
2789
|
+
if (opts.modality !== void 0 && opts.modality !== "text") {
|
|
2790
|
+
fail("--api and --url are only supported for text endpoints");
|
|
2791
|
+
}
|
|
2792
|
+
if (opts.api !== "chat_completions" && opts.api !== "responses") {
|
|
2793
|
+
fail("--api must be 'chat_completions' or 'responses'");
|
|
2794
|
+
}
|
|
2795
|
+
if (!opts.url) fail("--api and --url must be provided together");
|
|
2796
|
+
return { api: opts.api, url: opts.url };
|
|
2797
|
+
}
|
|
2798
|
+
if (required && !opts.baseUrl) fail("--base-url is required for media");
|
|
2799
|
+
return opts.baseUrl !== void 0 ? { baseUrl: opts.baseUrl } : {};
|
|
2800
|
+
}
|
|
2475
2801
|
function modelBody(opts, includeRequired) {
|
|
2476
|
-
const body =
|
|
2802
|
+
const body = {
|
|
2803
|
+
...readPriceOptions(opts),
|
|
2804
|
+
...endpointTarget(opts, includeRequired)
|
|
2805
|
+
};
|
|
2477
2806
|
const fields = [
|
|
2478
2807
|
["name", "name"],
|
|
2479
2808
|
["title", "title"],
|
|
2480
2809
|
["description", "description"],
|
|
2481
|
-
["baseUrl", "baseUrl"],
|
|
2482
2810
|
["upstreamModel", "upstreamModel"],
|
|
2483
2811
|
["bearerToken", "bearerToken"],
|
|
2484
2812
|
["paidOnly", "paidOnly"]
|
|
@@ -2493,9 +2821,9 @@ function modelBody(opts, includeRequired) {
|
|
|
2493
2821
|
body.visibility = opts.visibility;
|
|
2494
2822
|
}
|
|
2495
2823
|
if (includeRequired && opts.modality !== void 0) {
|
|
2496
|
-
if (opts.modality !== "text" && opts.modality !== "image" && opts.modality !== "video" && opts.modality !== "transcription" && opts.modality !== "embedding") {
|
|
2824
|
+
if (opts.modality !== "text" && opts.modality !== "image" && opts.modality !== "video" && opts.modality !== "transcription" && opts.modality !== "speech" && opts.modality !== "embedding") {
|
|
2497
2825
|
fail(
|
|
2498
|
-
"--modality must be 'text', 'image', 'video', 'transcription', or 'embedding'"
|
|
2826
|
+
"--modality must be 'text', 'image', 'video', 'transcription', 'speech', or 'embedding'"
|
|
2499
2827
|
);
|
|
2500
2828
|
}
|
|
2501
2829
|
body.modality = opts.modality;
|
|
@@ -2507,10 +2835,13 @@ function modelBody(opts, includeRequired) {
|
|
|
2507
2835
|
body.imagePricing = opts.imagePricing;
|
|
2508
2836
|
}
|
|
2509
2837
|
if (opts.fallbacks !== void 0) {
|
|
2510
|
-
body.fallbacks =
|
|
2838
|
+
body.fallbacks = commaSeparatedList(opts.fallbacks);
|
|
2511
2839
|
}
|
|
2512
2840
|
if (opts.inputModalities !== void 0) {
|
|
2513
|
-
body.inputModalities =
|
|
2841
|
+
body.inputModalities = commaSeparatedList(opts.inputModalities);
|
|
2842
|
+
}
|
|
2843
|
+
if (opts.requiredSafety !== void 0) {
|
|
2844
|
+
body.requiredSafetyFeatures = String(opts.requiredSafety).trim() === "none" ? [] : commaSeparatedList(opts.requiredSafety);
|
|
2514
2845
|
}
|
|
2515
2846
|
if (includeRequired) {
|
|
2516
2847
|
for (const required of ["name", "title"]) {
|
|
@@ -2520,7 +2851,6 @@ function modelBody(opts, includeRequired) {
|
|
|
2520
2851
|
);
|
|
2521
2852
|
}
|
|
2522
2853
|
}
|
|
2523
|
-
if (!body.baseUrl) fail("--base-url is required");
|
|
2524
2854
|
if (!body.bearerToken) fail("--bearer-token is required");
|
|
2525
2855
|
}
|
|
2526
2856
|
return body;
|
|
@@ -2543,8 +2873,9 @@ function printModels(models2) {
|
|
|
2543
2873
|
video_price: model.type === "proxy" && model.modality === "video" ? `${model.completionVideoPrice}/sec` : "-",
|
|
2544
2874
|
inputs: model.type === "proxy" ? model.inputModalities?.join(", ") || "-" : "-",
|
|
2545
2875
|
visibility: model.type === "proxy" && model.paidOnly ? `${model.visibility} (paid only)` : model.visibility,
|
|
2546
|
-
upstream: model.type === "proxy" && model.modality === "video" ? "-" : model.upstreamModel,
|
|
2547
|
-
|
|
2876
|
+
upstream: model.type === "proxy" && model.modality === "video" ? "-" : model.upstreamModel ?? "-",
|
|
2877
|
+
api: model.type === "prompt_agent" ? "responses" : model.api ?? "-",
|
|
2878
|
+
endpoint: model.url ?? model.baseUrl ?? "-",
|
|
2548
2879
|
fallbacks: model.type === "proxy" ? model.fallbacks?.join(", ") || "-" : "-",
|
|
2549
2880
|
description: model.description ?? "-"
|
|
2550
2881
|
})),
|
|
@@ -2559,7 +2890,8 @@ function printModels(models2) {
|
|
|
2559
2890
|
"inputs",
|
|
2560
2891
|
"visibility",
|
|
2561
2892
|
"upstream",
|
|
2562
|
-
"
|
|
2893
|
+
"api",
|
|
2894
|
+
"endpoint",
|
|
2563
2895
|
"fallbacks",
|
|
2564
2896
|
"description"
|
|
2565
2897
|
]
|
|
@@ -2579,8 +2911,11 @@ var list3 = new Command15("list").description("List models owned by your account
|
|
|
2579
2911
|
var create3 = addPriceOptions(
|
|
2580
2912
|
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
2913
|
"--base-url <url>",
|
|
2582
|
-
"
|
|
2914
|
+
"Media API base URL, or exact video endpoint URL"
|
|
2583
2915
|
).option(
|
|
2916
|
+
"--api <api>",
|
|
2917
|
+
"Text upstream API: chat_completions or responses"
|
|
2918
|
+
).option("--url <url>", "Exact text endpoint URL for the selected API").option(
|
|
2584
2919
|
"--upstream-model <model>",
|
|
2585
2920
|
"Upstream model id (not used for video)"
|
|
2586
2921
|
).option("--bearer-token <token>", "Upstream bearer token").option(
|
|
@@ -2595,6 +2930,9 @@ var create3 = addPriceOptions(
|
|
|
2595
2930
|
).option(
|
|
2596
2931
|
"--input-modalities <types>",
|
|
2597
2932
|
"Comma-separated accepted inputs: text,image,audio,video"
|
|
2933
|
+
).option(
|
|
2934
|
+
"--required-safety <features>",
|
|
2935
|
+
"Comma-separated required checks: privacy,secrets,sexual,violence,shield; none clears them"
|
|
2598
2936
|
).option(
|
|
2599
2937
|
"--modality <modality>",
|
|
2600
2938
|
"Model family: text (default), image, video, transcription, or embedding"
|
|
@@ -2622,8 +2960,11 @@ var create3 = addPriceOptions(
|
|
|
2622
2960
|
var update2 = addPriceOptions(
|
|
2623
2961
|
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
2962
|
"--base-url <url>",
|
|
2625
|
-
"
|
|
2963
|
+
"Media API base URL, or exact video endpoint URL"
|
|
2626
2964
|
).option(
|
|
2965
|
+
"--api <api>",
|
|
2966
|
+
"Text upstream API: chat_completions or responses (requires --url)"
|
|
2967
|
+
).option("--url <url>", "Exact text endpoint URL (requires --api)").option(
|
|
2627
2968
|
"--upstream-model <model>",
|
|
2628
2969
|
"Upstream model id (not used for video)"
|
|
2629
2970
|
).option("--bearer-token <token>", "Upstream bearer token").option(
|
|
@@ -2638,6 +2979,9 @@ var update2 = addPriceOptions(
|
|
|
2638
2979
|
).option(
|
|
2639
2980
|
"--input-modalities <types>",
|
|
2640
2981
|
"Comma-separated accepted inputs: text,image,audio,video"
|
|
2982
|
+
).option(
|
|
2983
|
+
"--required-safety <features>",
|
|
2984
|
+
"Comma-separated required checks: privacy,secrets,sexual,violence,shield; none clears them"
|
|
2641
2985
|
).option(
|
|
2642
2986
|
"--image-pricing <mode>",
|
|
2643
2987
|
"Image billing: request (per image) or tokens"
|
|
@@ -2703,20 +3047,21 @@ var models = new Command15("models").description("List upstream models from an e
|
|
|
2703
3047
|
fail("Failed to fetch upstream models", err);
|
|
2704
3048
|
}
|
|
2705
3049
|
});
|
|
2706
|
-
var test = new Command15("test").description("Test an endpoint/model before registering it").
|
|
3050
|
+
var test = new Command15("test").description("Test an endpoint/model before registering it").option(
|
|
2707
3051
|
"--base-url <url>",
|
|
2708
|
-
"
|
|
2709
|
-
).requiredOption("--bearer-token <token>", "Upstream bearer token").option("--model <model>", "Upstream model id (not used for video)").option(
|
|
3052
|
+
"Media API base URL, or exact video endpoint URL"
|
|
3053
|
+
).option("--api <api>", "Text upstream API: chat_completions or responses").option("--url <url>", "Exact text endpoint URL for the selected API").requiredOption("--bearer-token <token>", "Upstream bearer token").option("--model <model>", "Upstream model id (not used for video)").option(
|
|
2710
3054
|
"--modality <modality>",
|
|
2711
3055
|
"Model family: text (default), image, video, transcription, or embedding"
|
|
2712
3056
|
).action(async (opts) => {
|
|
2713
3057
|
const key = requireKey();
|
|
2714
|
-
if (opts.modality !== void 0 && opts.modality !== "text" && opts.modality !== "image" && opts.modality !== "video" && opts.modality !== "transcription" && opts.modality !== "embedding") {
|
|
3058
|
+
if (opts.modality !== void 0 && opts.modality !== "text" && opts.modality !== "image" && opts.modality !== "video" && opts.modality !== "transcription" && opts.modality !== "speech" && opts.modality !== "embedding") {
|
|
2715
3059
|
fail(
|
|
2716
|
-
"--modality must be 'text', 'image', 'video', 'transcription', or 'embedding'"
|
|
3060
|
+
"--modality must be 'text', 'image', 'video', 'transcription', 'speech', or 'embedding'"
|
|
2717
3061
|
);
|
|
2718
3062
|
}
|
|
2719
3063
|
const modality = opts.modality ?? "text";
|
|
3064
|
+
const target = endpointTarget(opts, true);
|
|
2720
3065
|
if (modality !== "video" && !opts.model) {
|
|
2721
3066
|
fail("--model is required unless --modality is video");
|
|
2722
3067
|
}
|
|
@@ -2727,7 +3072,7 @@ var test = new Command15("test").description("Test an endpoint/model before regi
|
|
|
2727
3072
|
apiKey: key,
|
|
2728
3073
|
method: "POST",
|
|
2729
3074
|
body: {
|
|
2730
|
-
|
|
3075
|
+
...target,
|
|
2731
3076
|
bearerToken: opts.bearerToken,
|
|
2732
3077
|
...opts.model && { model: opts.model },
|
|
2733
3078
|
modality
|