@pollinations/cli 0.1.12 → 0.1.14
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 +16 -8
- package/SKILL.md +10 -5
- package/dist/index.js +710 -255
- 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 && {
|
|
@@ -243,11 +243,19 @@ function printAgents(agents) {
|
|
|
243
243
|
agents.map((agent) => ({
|
|
244
244
|
id: chalk2.dim(agent.id),
|
|
245
245
|
name: agent.name,
|
|
246
|
-
|
|
246
|
+
type: agent.type,
|
|
247
|
+
base_model: agent.type === "prompt_agent" ? agent.baseModel : "-",
|
|
247
248
|
visibility: agent.visibility,
|
|
248
|
-
pollinations_tools: agent.mcpServers.includes("pollinations") ? "yes" : "no"
|
|
249
|
+
pollinations_tools: agent.type === "prompt_agent" ? agent.mcpServers.includes("pollinations") ? "yes" : "no" : "built in"
|
|
249
250
|
})),
|
|
250
|
-
[
|
|
251
|
+
[
|
|
252
|
+
"id",
|
|
253
|
+
"name",
|
|
254
|
+
"type",
|
|
255
|
+
"base_model",
|
|
256
|
+
"visibility",
|
|
257
|
+
"pollinations_tools"
|
|
258
|
+
]
|
|
251
259
|
);
|
|
252
260
|
}
|
|
253
261
|
var list = new Command("list").description("List agents owned by your account").action(async () => {
|
|
@@ -280,13 +288,12 @@ var get = new Command("get").description("Get an agent owned by your account").a
|
|
|
280
288
|
process.exit(1);
|
|
281
289
|
}
|
|
282
290
|
});
|
|
283
|
-
var create = new Command("create").description("Create a
|
|
291
|
+
var create = new Command("create").description("Create a managed agent").requiredOption(
|
|
284
292
|
"--config <file>",
|
|
285
293
|
"JSON agent config file sent directly to the API"
|
|
286
|
-
).
|
|
294
|
+
).option("--name <name>", "Prompt-agent callable model name").option("--title <title>", "Prompt-agent catalog title").option("--description <text>", "Prompt-agent description").option(
|
|
287
295
|
"--visibility <visibility>",
|
|
288
|
-
"Agent visibility: private (default) or public"
|
|
289
|
-
"private"
|
|
296
|
+
"Agent visibility: private (default) or public"
|
|
290
297
|
).action(async (opts) => {
|
|
291
298
|
const key = requireKey();
|
|
292
299
|
try {
|
|
@@ -349,7 +356,25 @@ var remove = new Command("delete").description("Delete an agent and its model re
|
|
|
349
356
|
process.exit(1);
|
|
350
357
|
}
|
|
351
358
|
});
|
|
352
|
-
var
|
|
359
|
+
var sync = new Command("sync").description("Deploy the latest revision of a code agent").argument("<id>", "Agent id").action(async (id) => {
|
|
360
|
+
try {
|
|
361
|
+
const result7 = await gen(`/account/agents/${encodeURIComponent(id)}/sync`, {
|
|
362
|
+
method: "POST"
|
|
363
|
+
});
|
|
364
|
+
if (getOutputMode() === "json") printResult(result7);
|
|
365
|
+
else {
|
|
366
|
+
printSuccess(
|
|
367
|
+
result7.updated ? `Agent deployed at ${result7.deployedCommitSha}` : `Agent already uses ${result7.deployedCommitSha}`
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
} catch (error) {
|
|
371
|
+
printError(
|
|
372
|
+
`Failed to sync agent: ${error instanceof Error ? error.message : "unknown"}`
|
|
373
|
+
);
|
|
374
|
+
process.exit(1);
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
var agentsCommand = new Command("agents").description("Manage agents").addCommand(list).addCommand(get).addCommand(create).addCommand(update).addCommand(sync).addCommand(remove);
|
|
353
378
|
|
|
354
379
|
// src/commands/auth.ts
|
|
355
380
|
import { Command as Command2, Option } from "commander";
|
|
@@ -685,12 +710,25 @@ import { Command as Command5 } from "commander";
|
|
|
685
710
|
// src/lib/errors.ts
|
|
686
711
|
async function budgetHint(status2, bodyText) {
|
|
687
712
|
if (status2 !== 402) return null;
|
|
713
|
+
let code;
|
|
714
|
+
try {
|
|
715
|
+
code = JSON.parse(bodyText)?.error?.code;
|
|
716
|
+
} catch {
|
|
717
|
+
}
|
|
718
|
+
if (code === "KEY_BUDGET_EXHAUSTED") {
|
|
719
|
+
return [
|
|
720
|
+
"API key budget exhausted. Topping up the wallet does not increase the key budget.",
|
|
721
|
+
"Manage key budget: https://enter.pollinations.ai/keys",
|
|
722
|
+
`Server said: ${bodyText}`
|
|
723
|
+
].join("\n");
|
|
724
|
+
}
|
|
688
725
|
const balance = await gen("/account/balance", {
|
|
689
726
|
apiKey: requireKey()
|
|
690
727
|
}).then((r) => r.balance).catch(() => null);
|
|
691
728
|
const lines = [
|
|
692
|
-
"Insufficient pollen balance.",
|
|
729
|
+
code === "INSUFFICIENT_BALANCE" ? "Insufficient pollen balance." : "Check your pollen balance and API key budget.",
|
|
693
730
|
"Top up: https://enter.pollinations.ai/pollen",
|
|
731
|
+
...code === "INSUFFICIENT_BALANCE" ? [] : ["Manage key budget: https://enter.pollinations.ai/keys"],
|
|
694
732
|
""
|
|
695
733
|
];
|
|
696
734
|
if (balance != null) lines.push(`Account balance: ${balance} pollen`);
|
|
@@ -751,12 +789,12 @@ var findPlayer = () => {
|
|
|
751
789
|
var playAudio = async (filePath) => {
|
|
752
790
|
const player = findPlayer();
|
|
753
791
|
if (!player) return false;
|
|
754
|
-
return new Promise((
|
|
792
|
+
return new Promise((resolve2) => {
|
|
755
793
|
const child = spawn(player.cmd, player.args(filePath), {
|
|
756
794
|
stdio: "ignore"
|
|
757
795
|
});
|
|
758
|
-
child.on("error", () =>
|
|
759
|
-
child.on("exit", (code) =>
|
|
796
|
+
child.on("error", () => resolve2(false));
|
|
797
|
+
child.on("exit", (code) => resolve2(code === 0));
|
|
760
798
|
});
|
|
761
799
|
};
|
|
762
800
|
var playerMissingHint = () => {
|
|
@@ -1263,13 +1301,9 @@ function createGenCommand() {
|
|
|
1263
1301
|
import { homedir as homedir2 } from "os";
|
|
1264
1302
|
import { Command as Command12 } from "commander";
|
|
1265
1303
|
|
|
1266
|
-
// src/harnesses/
|
|
1267
|
-
import { join as join4
|
|
1304
|
+
// src/harnesses/bloom.ts
|
|
1305
|
+
import { join as join4 } from "path";
|
|
1268
1306
|
import { parseEnv } from "util";
|
|
1269
|
-
import { isMap, isSeq, parseDocument, Scalar } from "yaml";
|
|
1270
|
-
|
|
1271
|
-
// SKILL.md?raw
|
|
1272
|
-
var SKILL_default = '---\nname: polli\ndescription: Generate images, text, audio, video, and transcribe speech via the Pollinations API using the polli CLI. Use when asked to generate media, call pollinations.ai, check pollen balance, list models, manage API keys, inspect quests, manage agents or my-models, or run polli commands.\nallowed-tools: Bash(polli *)\n---\n\n# polli \u2014 Pollinations CLI\n\nThin wrapper around `gen.pollinations.ai`. Generates images, text, audio, video; transcribes speech; manages API keys, usage, quests, agents, and invite-only my-models.\n\nIf `polli` is not installed, run `npm i -g @pollinations/cli@latest` (provides the `polli` binary).\n\n## When to use this skill\n\n- User asks to **generate an image / text / audio / video** via pollinations\n- User mentions **polli, pollinations, pollen, pollinations.ai**\n- User wants to **transcribe speech** or run TTS\n- User asks about their **pollen balance, usage, or API keys**\n- User wants to **browse or filter available models**\n- User wants to inspect **quests** or manage invite-only **my-models**\n- User wants to create or update a hosted prompt **agent**\n\n## Quick reference\n\n| Intent | Command |\n|---|---|\n| Log in once | `polli auth login` |\n| Store an existing key | `printf \'%s\' "$POLLINATIONS_API_KEY" \\| polli auth login --with-token` |\n| Generate image | `polli gen image "<prompt>" --output out.png` |\n| Generate text | `polli gen text "<prompt>"` |\n| Text with stdin as context | `echo "<ctx>" \\| polli gen text "<question>"` |\n| Describe an image (vision) | `polli gen text "what is this?" --image <url>` |\n| One-shot TTS | `polli gen audio "<text>" --output speech.mp3` |\n| Speak out loud | `polli gen audio "<text>" --play` (uses `afplay` on macOS; `ffplay`/`mpv`/`mpg123` on Linux) |\n| Generate video | `polli gen video "<prompt>" --output out.mp4` |\n| Transcribe audio | `polli gen transcribe path/to.mp3` |\n| Upload a local file | `polli upload path/to.png` (prints public URL) |\n| List all models | `polli models` |\n| Filter models by type | `polli models --type image` |\n| Model health + latency | `polli models --stats` (default 60m, `--window <min>`) |\n| Check balance | `polli usage` |\n| Developer earnings | `polli earnings` (`--days <n>`, max 90) |\n| List your quests + claim state | `polli quests` (filters: `--open --claimable --claimed --coming-soon`) |\n| Manage prompt agents | `polli agents list` |\n| Manage invite-only community models | `polli my-models list` |\n| Connect a coding harness to Pollinations | `polli harness <dsh\\|opencode\\|pi> on` (available adapters: `polli harness --help`) |\n| Machine-readable output | append `--json` to any command |\n\n## Setup\n\nOne-time: `polli auth login` (device-flow; creates a key with `profile`, `usage`, and `keys`). To store an existing key, run\n`printf \'%s\' "$POLLINATIONS_API_KEY" | polli auth login --with-token`. Verify\nwith `polli auth status`.\nOverride the stored key for a single command with `--key <key>`.\n\n## Recipes\n\n### Generate an image to a file\n```bash\npolli gen image "a fox reading a book, studio ghibli style" --output fox.png\n```\nDefaults: `zimage`, 1024x1024. Pick a different model with `--model flux` (see `polli models --type image`). For edits / img2img, pass one or more `--image <url>` flags \u2014 **must be public http(s) URLs**, local paths are rejected client-side. **Only models that list `"image"` in `input_modalities` actually consume the flag** \u2014 `flux` and `zimage` are text-only and will silently ignore `--image`. Find i2i-capable models with `polli models --type image --json | jq -r \'.[] | select(.input_modalities | contains(["image"])) | .name\'` (common choices: `nanobanana`, `kontext`, `p-image-edit`). To use a local file, upload it first with `polli upload` (see next recipe).\n\n### Upload a local file to get a public URL\n```bash\nURL=$(polli upload cat.png)\npolli gen image "make the cat purple" --image "$URL" --output purple.png\n```\n`polli upload <file>` posts a multipart upload to `media.pollinations.ai` (100MB max; 30-day lifecycle, refreshed by GETs once the object is at least 15 days old). Each upload receives a unique id. Human mode: URL on stdout and id/size/contentType on stderr. `--json`: full upload response on stdout. The returned URL is public (no auth to fetch) and works anywhere `--image` is accepted \u2014 `gen image`, `gen video`, etc.\n\n### Generate text\n```bash\npolli gen text "summarize the three laws of robotics"\n```\nSave to file: `--output summary.txt`. Use `--system "<msg>"` to set system prompt. For reasoning models, pass `--reasoning low|medium|high` to control reasoning effort. **Only send `--reasoning` to models where `reasoning: true`** in `polli models --type text --json` \u2014 the flag is not validated client-side, and non-reasoning models may silently accept it (openai), ignore it, or return a 400 (mistral).\n\n### Describe an image with a vision model\n```bash\nURL=$(polli upload selfie.jpg)\npolli gen text "turn this person into a cartoon pet in one playful sentence" --image "$URL"\n```\n`gen text --image <url...>` attaches one or more **public https URLs** as an OpenAI-style multimodal message \u2014 repeatable for multi-image prompts. Local paths aren\'t supported; run them through `polli upload` first (see the upload recipe above). **Only text models with `"image"` in `input_modalities` actually read the image** \u2014 filter with `polli models --type text --json | jq -r \'.[] | select(.input_modalities | index("image")) | .name\'`. Non-vision models silently ignore the attachment. Good defaults: `openai`, `gemini`, `claude`.\n\n### Pipe stdin as context into text generation\n```bash\ncat README.md | polli gen text "what does this project do?"\n```\nstdin becomes context; the positional argument is the question.\n\n### Interactive chat session\n```bash\npolli gen chat --model openai --system "you are a terse assistant"\n```\nSlash commands inside the session: `/exit`, `/clear`, `/save <path>`.\n\n### Text-to-speech\n```bash\npolli gen audio "hello world" --voice nova --output hello.mp3\necho "long script" | polli gen audio --voice nova --output out.mp3\n```\nDefault voice is `sage`. To discover the full live voice list, use the model registry: `polli models --type audio --json | jq -r \'.[].voices[]?\'` \u2014 each audio model entry includes its `voices[]` array. Format defaults to mp3; `--format opus|aac|flac|wav` to change. Accepts stdin (same as `gen text`). Add `--play` to save and then play the audio back (handy for narration/demos). Playback starts after the file is fully written, and the command blocks until playback finishes \u2014 if you want fire-and-forget, wrap in a subshell: `( polli gen audio "..." --play & )`. Player on macOS: `afplay`; on Linux it tries `ffplay`, then `mpv`, then `mpg123` in that order.\n\n### Generate music (elevenmusic)\n```bash\npolli gen audio "lofi hip-hop beat" --model elevenmusic --duration 30 --instrumental --output track.mp3\n```\n\n### Generate sound effects (eleven-sfx)\n```bash\npolli gen audio "thunderclap with heavy rain" --model eleven-sfx --duration 5 --output thunder.mp3\n```\nText-to-sound-effect via ElevenLabs (aliases: `sfx`, `sound-effects`). `--duration` 0.5\u201330s (omit to let the model pick). Billed per second of output (~$0.004/s, capped at $0.12 for a full 30s).\n\n### Multilingual TTS (eleven-multilingual-v2)\n```bash\npolli gen audio "Bonjour, ceci est un test" --model multilingual-v2 --voice rachel --output fr.mp3\n```\nStable, lifelike TTS across 29 languages (aliases: `multilingual-v2`, `eleven-v2`) \u2014 a non-alpha alternative to the default v3.\n\n### Generate video\n```bash\npolli gen video "a spacecraft landing on mars" --model wan-fast --duration 5 --output mars.mp4\n```\nCheapest path: `--model wan-fast` at ~$0.01/sec, **fixed 5-second output** (any `--duration` value is ignored \u2014 you always pay for and receive 5 sec). For image-to-video, pass `--image <url>` with a **public HTTPS URL** (local file paths and 404/rate-limited hosts will fail with a server error).\n\n**Flag support varies per model and is not enforced client-side.** `--duration`, `--aspect-ratio`, and `--audio` are forwarded to the server but may be silently ignored \u2014 verified on `wan-fast` where duration is locked to 5s, `--aspect-ratio 9:16` still returns 16:9, and `--audio` produces no audio track. Always inspect the output (`file`, `ffprobe`) before trusting a flag worked. Check `polli models --type video --json` for per-model capabilities.\n\n**Video is not tracked by `--stats`.** `polli models --type video --stats` returns empty \u2014 the stats pipe only records text/image/audio events. To compare video models, fall back to `polli models --type video --json` and look at price/description fields.\n\n### Transcribe audio to text\n```bash\npolli gen transcribe recording.mp3 --language en\n```\nModels: `whisper` (default), `scribe`, `universal-2`, `universal-3.5-pro`. Accepts common audio formats (mp3, wav, m4a, flac, ogg); non-audio input (e.g. a `.txt` file) returns a clear `400 invalid_request_error: extension "txt" not supported` \u2014 no need to pre-validate with `file`. Default output is the plain transcript on stdout as a single line (pipe-friendly). Use `--json` for structured output: **whisper** and **AssemblyAI** return timing data when requested through the API; **scribe** returns only `{text: "..."}` \u2014 use whisper or AssemblyAI if you need timing data. `--language <ISO-639-1>` (e.g. `en`, `fr`) is an optional hint that can improve accuracy for non-English or accented speech.\n\n### Discover models\n```bash\npolli models --type text # text models only\npolli models --type image --verbose # with context length / pricing\npolli models --stats # health + avg latency + err% (60m default)\npolli models --stats --window 5 # last 5 minutes only\n```\nUse `--stats` before choosing a model. **Caveat**: the `err%` column counts **5xx only** \u2014 a model can show `0.0%` while having massive 4xx rates (auth, validation, etc.). For the full picture use `--stats --json` and read `errors_4xx`, `errors_5xx`, `latency_p95_ms`.\n\n**Pricing fields are per-token, not per-request.** `completionImageTokens: 0.000008` means each output image-token costs that much \u2014 a single 1024x1024 image from `gptimage` lands at ~$0.008, not $0.000008. Flat-priced image models (`flux`, `zimage`) expose `completionImageTokens` as the whole-image price because they emit exactly one "token" per image. When in doubt, make one call and read the true cost from `polli usage --history --limit 5 --json`.\n\n### Check usage and balance\n```bash\npolli usage # current pollen balance\npolli usage --history # recent individual requests\npolli usage --daily # daily cost summary\npolli earnings # developer earnings total + per-entity breakdown (default 30d)\npolli earnings --days 7 # rolling window, max 90\npolli quests # your quests + claim state (open/claimable/claimed/coming)\npolli quests --claimable # only rewards ready to claim\n```\n**History is eventually consistent** \u2014 a request you just made may not appear for 30\u201360s. When matching costs to freshly-generated media, use `--limit 50` and filter by timestamp, and retry if the expected entry is missing. `polli usage --json` returns `{"pollen": <number>}` \u2014 the current balance only; use `--history --json` or `--daily --json` for cost breakdowns.\n\n### Manage my-models\n```bash\npolli my-models list\npolli my-models models --base-url https://api.example.com/v1 --bearer-token "$UPSTREAM_KEY"\npolli my-models create --name my-model --title "My Model" --base-url https://api.example.com/v1 --bearer-token "$UPSTREAM_KEY" --upstream-model gpt-4.1-mini\npolli my-models create --name my-image --title "My Image" --modality image --image-pricing request --completion-image-price 0.01 --base-url https://api.example.com/v1 --bearer-token "$UPSTREAM_KEY" --upstream-model flux\npolli my-models update <id> --description "Updated description"\npolli my-models update <id> --paid-only # only accept Paid Pollen; --no-paid-only reverts\npolli my-models delete <id>\n```\n`my-models` manages owned community text, image, and transcription models. Any account can create private models; `communityEndpointsAllowed: true` is required only to publish them. API keys require `account:keys`. Use `account:usage` for narrow read-only usage and `polli quests`; use both permissions when a client needs both read-only account state and admin operations. Quest claiming is dashboard-only; `polli quests` is read-only and account-aware.\n\n### Register an image my-model\n```bash\npolli my-models test --modality image --base-url https://api.example.com/v1 --bearer-token "$UPSTREAM_KEY" --model image-v1\npolli my-models create --name my-image --title "My Image" --modality image --image-pricing request --completion-image-price 0.01 --input-modalities text,image --base-url https://api.example.com/v1 --bearer-token "$UPSTREAM_KEY" --upstream-model image-v1\n```\nTest before creating. The probe reports the pricing mode it detected and the input modalities it found, including whether the endpoint accepts image edits; pass those back as `--input-modalities text,image` to advertise edit support. `polli my-models list` shows them in the `inputs` column.\n\nTwo billing modes: `--image-pricing request` charges `--completion-image-price` per generated image, while `--image-pricing tokens` bills returned token usage per 1M through `--prompt-text-price`, `--prompt-image-price`, and `--completion-image-price`.\n\nPrices only apply to `--visibility public` models. A private model is owner-only and always free, so every price flag above is stored as `0` until you publish \u2014 and making a published model private clears its prices again.\n\n`--modality` is fixed at creation \u2014 `update` cannot change it.\n\n### Manage agents\n\n```bash\npolli agents list\npolli agents get <id>\npolli agents create --config agent.json --name my-agent --title "My Agent"\npolli agents update <id> --config agent.json\npolli agents delete <id>\n```\nThe config file contains `systemPrompt`, `baseModel`, and optional `mcpServers`; create also requires `--name` and `--title` for the callable model listing. The only supported server ID is currently `"pollinations"`. Updates replace the complete agent configuration.\n\nCreating an agent also creates its callable model listing. Managed agents are text-only and free, with no fallbacks or per-user RPM. Deleting the agent also deletes its model listing. See [Publish an Agent](https://github.com/pollinations/pollinations/blob/main/BUILD_YOUR_OWN_AGENT.md).\n\n### Manage API keys\n```bash\npolli keys list # list all keys on the account\npolli keys info # details about the CURRENTLY AUTHENTICATED key only (takes no id)\npolli keys create --name "my-bot" --type secret --budget 1000 --permissions profile usage # scoped key\npolli keys create --name "my-app" --type publishable --redirect-uri https://app.example/callback --earnings\npolli keys revoke <id> # id comes from `keys list --json`\n```\n`--permissions <perms...>` scopes what the new key can do on the account (e.g. `profile usage` lets it call `polli --key <new> usage`). **Without `--permissions`, new scoped keys can generate media but cannot read account state** \u2014 `polli --key <new> usage` will 403. `"keys"` is auto-stripped from the list so a scoped key can never mint further keys. Existing keys with `account:keys` can manage my-models where that invite-only feature is enabled, but still need `account:usage` for read-only account state. Publishable app keys default developer earnings off; pass `--earnings` to enable them. To inspect a specific key other than the current one, use `polli keys list --json | jq \'.[] | select(.id == "<id>")\'`. `keys info` is intentionally scoped to the caller\'s own key.\n\n### Connect a coding harness\n```bash\npolli harness --help # supported harnesses\npolli harness dsh on # login if needed, mint key "polli-harness-dsh", write provider + default model\npolli harness dsh on --model kimi # any tool-calling text model from `polli models`\npolli harness dsh on --no-mcp # configure the provider and skill without MCP tools\npolli harness dsh off # restore the config backed up before "on"\npolli harness opencode on # enable the Pollinations OpenCode plugin\npolli harness opencode off # remove the plugin setup and stored key\npolli harness pi on # login if needed, mint key "polli-harness-pi", configure Pi with Pollinations\npolli harness pi on --model kimi # any tool-calling text model from `polli models`\npolli harness pi off # restore the Pi config backed up before "on"\n```\nEach adapter checks that its harness can be launched before login, key creation, or configuration. DSH\'s official launch uses `npx`, so its adapter checks for `npx`; OpenCode and Pi require their installed commands.\n\nThe DSH adapter globally configures the Pollinations provider, hosted Pollinations MCP, and this skill under `$DSH_HOME` (default `~/.dsh`). OpenCode enables the existing Pollinations plugin and stores its dedicated key in the plugin config. Pi writes `~/.pi/agent/models.json`, `auth.json`, and `settings.json`, and installs this skill under `~/.pi/agent/skills/polli/`. Guide: `polli docs` section "Coding Harnesses".\n\n### Read API docs\n```bash\npolli docs # full llm.txt reference\npolli docs /v1/chat/completions # filter to one endpoint\npolli docs --open # open in browser\n```\n\n## Output contract\n\n- **Default (human mode):** varies by command \u2014 most emit `key: value` pairs or tab-separated tables with a header row. Exceptions: `gen text` prints the full response to stdout; `gen transcribe` prints the transcript as plain text; `gen chat` runs an interactive REPL. Status/progress messages go to stderr, so pipes stay clean.\n- **`--json`:** every command emits machine-parseable JSON to stdout; all human messages go to stderr. **Always prefer `--json` when piping into `jq` or parsing** \u2014 it\'s the only shape with a stable contract.\n- **Exit codes:** 0 on success, non-zero on auth failure, rate limit, network error, or invalid args. Error messages go to stderr.\n\n## Agent operating rules\n\n1. **Run `polli auth status` first** if you don\'t know whether the user is logged in. Fail fast with a clear "run `polli auth login`" message if not.\n2. **Prefer `--json`** whenever you\'ll parse the output. Never grep human-formatted tables.\n3. **Don\'t hardcode model IDs.** Fetch the live list with `polli models --type <type>`. Model availability changes.\n4. **Before picking a model for production use, check `polli models --stats`.** Rule of thumb for "healthy": `err%` \u2264 5, `avg` latency in a reasonable range for the modality (standard text <5s, image <10s, video <60s), and `requests` high enough to be statistically meaningful (ignore rows with <10 requests \u2014 noise). **Filter by capability first, then optimize by health** \u2014 e.g. for a reasoning task, narrow to models where `reasoning: true` (via `polli models --type text --json`), *then* cross-reference against `--stats` output. The healthiest model overall may not support the capability you need. **Reasoning models are inherently slower \u2014 expect 5\u201350s, not <5s**; when picking among them, prioritize low `err%` and request count over raw latency, and compare latency only within the reasoning-capable subset.\n5. **Always pass `--output <path>`** for `gen image`, `gen audio`, `gen video` \u2014 otherwise the file lands in the current directory with a default name.\n6. **For stdin-as-context** on `gen text`, pipe the context and pass the question as the positional argument: `cat file | polli gen text "question about the file"`.\n7. **For exact flag lists, run `polli <cmd> --help` or `polli gen <cmd> --help`.** This skill\'s recipes cover the common path; the CLI\'s own help is always the source of truth.\n8. **Use `polli docs [endpoint]` over guessing API shapes.** It prints the canonical `llm.txt` reference from the live API.\n\n## Common pitfalls\n\n- Forgetting `--output` on binary generators (image/audio/video) \u2014 the file goes to a default path, which may not be what the user wants.\n- Using `polli gen text --json` expecting OpenAI chat-completions shape \u2014 the CLI\'s `--json` wraps its own structure. Use `polli docs /v1/chat/completions` to see the raw API shape if you need it.\n- Running commands without auth \u2014 `polli auth status` tells you who you\'re logged in as and your balance in one call.\n- **`gen text` streams to a TTY, buffers when piped.** The default now auto-detects \u2014 a human at the terminal sees tokens tick in, a pipe/redirect gets the full response once. Force either mode with `--stream` or `--no-stream`. For scripts and chains like `polli gen text \u2026 | polli gen audio \u2026`, you don\'t need to do anything; buffering happens automatically.\n- **Translating a `polli` workflow into a browser app.** `gen.pollinations.ai` requires a bearer token for generation requests, so a plain client-side `fetch` with no auth returns 401 unless it is served from cache. Mint a scoped key with `polli keys create` and proxy via your own backend.\n';
|
|
1273
1307
|
|
|
1274
1308
|
// src/harnesses/fs.ts
|
|
1275
1309
|
import {
|
|
@@ -1283,7 +1317,10 @@ import {
|
|
|
1283
1317
|
unlinkSync as unlinkSync2,
|
|
1284
1318
|
writeFileSync as writeFileSync7
|
|
1285
1319
|
} from "fs";
|
|
1286
|
-
import { basename as basename2, delimiter, dirname, join as join2 } from "path";
|
|
1320
|
+
import { basename as basename2, delimiter, dirname, join as join2, resolve } from "path";
|
|
1321
|
+
var resolveHomePath = (home, path) => resolve(
|
|
1322
|
+
path === "~" ? home : path.startsWith("~/") || path.startsWith("~\\") ? join2(home, path.slice(2)) : path
|
|
1323
|
+
);
|
|
1287
1324
|
var isExecutable = (path) => {
|
|
1288
1325
|
try {
|
|
1289
1326
|
accessSync(path, constants.X_OK);
|
|
@@ -1346,20 +1383,6 @@ var resolveHarnessKey = async (harness, options) => {
|
|
|
1346
1383
|
return created.key;
|
|
1347
1384
|
};
|
|
1348
1385
|
|
|
1349
|
-
// src/harnesses/models.ts
|
|
1350
|
-
var fetchHarnessModels = async () => {
|
|
1351
|
-
const { data } = await gen("/v1/models");
|
|
1352
|
-
return data.filter(
|
|
1353
|
-
(m) => m.tools === true && m.output_modalities?.includes("text") && m.supported_endpoints?.includes("/v1/chat/completions") && m.context_length && !m.agent && !m.id.includes("/")
|
|
1354
|
-
).map((m) => ({
|
|
1355
|
-
id: m.id,
|
|
1356
|
-
contextWindow: m.context_length,
|
|
1357
|
-
input: (m.input_modalities ?? ["text"]).filter(
|
|
1358
|
-
(modality) => modality === "text" || modality === "image"
|
|
1359
|
-
)
|
|
1360
|
-
}));
|
|
1361
|
-
};
|
|
1362
|
-
|
|
1363
1386
|
// src/harnesses/snapshot.ts
|
|
1364
1387
|
import { createHash } from "crypto";
|
|
1365
1388
|
import { join as join3 } from "path";
|
|
@@ -1380,8 +1403,8 @@ var captureFiles = (paths) => Object.fromEntries(
|
|
|
1380
1403
|
{ before: readTextIfExists(path), afterHash: null }
|
|
1381
1404
|
])
|
|
1382
1405
|
);
|
|
1383
|
-
var restoreFiles = (
|
|
1384
|
-
for (const [path, file] of Object.entries(
|
|
1406
|
+
var restoreFiles = (files7) => {
|
|
1407
|
+
for (const [path, file] of Object.entries(files7)) {
|
|
1385
1408
|
if (file.before === null) removeIfExists(path);
|
|
1386
1409
|
else writeTextAtomic(path, file.before);
|
|
1387
1410
|
}
|
|
@@ -1419,32 +1442,129 @@ var applyWithSnapshot = (ctx, id, paths, apply) => {
|
|
|
1419
1442
|
snapshot.complete = true;
|
|
1420
1443
|
writeSnapshot(ctx, id, paths, snapshot);
|
|
1421
1444
|
};
|
|
1422
|
-
var
|
|
1445
|
+
var restoreOrStrip = (ctx, id, paths, strip) => {
|
|
1423
1446
|
const snapshot = loadSnapshot(ctx, id, paths);
|
|
1424
|
-
if (!snapshot
|
|
1425
|
-
|
|
1447
|
+
if (snapshot && (!snapshot.complete || Object.entries(snapshot.files).every(
|
|
1448
|
+
([path, file]) => contentHash(readTextIfExists(path)) === file.afterHash
|
|
1449
|
+
))) {
|
|
1426
1450
|
restoreFiles(snapshot.files);
|
|
1427
|
-
|
|
1451
|
+
clearSnapshot(ctx, id, paths);
|
|
1428
1452
|
return "restored";
|
|
1429
1453
|
}
|
|
1430
|
-
const
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
)) {
|
|
1434
|
-
return "modified";
|
|
1435
|
-
}
|
|
1436
|
-
restoreFiles(snapshot.files);
|
|
1437
|
-
removeIfExists(snapshotPath(ctx, id, paths));
|
|
1438
|
-
return "restored";
|
|
1454
|
+
const outcome = strip() ? "stripped" : "unchanged";
|
|
1455
|
+
clearSnapshot(ctx, id, paths);
|
|
1456
|
+
return outcome;
|
|
1439
1457
|
};
|
|
1440
1458
|
var clearSnapshot = (ctx, id, paths) => removeIfExists(snapshotPath(ctx, id, paths));
|
|
1441
1459
|
|
|
1460
|
+
// src/harnesses/bloom.ts
|
|
1461
|
+
var ID = "bloom";
|
|
1462
|
+
var LABEL = "Bloom CLI";
|
|
1463
|
+
var KEY_ENV = "POLLINATIONS_API_KEY";
|
|
1464
|
+
var bloomHome = (ctx) => {
|
|
1465
|
+
const configured = ctx.env.BLOOM_HOME;
|
|
1466
|
+
if (!configured?.trim()) return join4(ctx.home, ".bloom");
|
|
1467
|
+
return resolveHomePath(ctx.home, configured);
|
|
1468
|
+
};
|
|
1469
|
+
var envPath = (ctx) => join4(bloomHome(ctx), ".env");
|
|
1470
|
+
var files = (ctx) => [envPath(ctx)];
|
|
1471
|
+
var keyLine = new RegExp(`^\\s*(?:export\\s+)?${KEY_ENV}\\s*=`, "u");
|
|
1472
|
+
var readKey = (ctx) => {
|
|
1473
|
+
const text = readTextIfExists(envPath(ctx));
|
|
1474
|
+
if (text === null) return null;
|
|
1475
|
+
return parseEnv(text)[KEY_ENV] || null;
|
|
1476
|
+
};
|
|
1477
|
+
var setKey = (ctx, key) => {
|
|
1478
|
+
const lines = (readTextIfExists(envPath(ctx)) ?? "").split("\n");
|
|
1479
|
+
const index = lines.findIndex((line) => keyLine.test(line));
|
|
1480
|
+
const filtered = lines.filter(
|
|
1481
|
+
(line, current) => current === index || !keyLine.test(line)
|
|
1482
|
+
);
|
|
1483
|
+
const value = `${KEY_ENV}=${JSON.stringify(key)}`;
|
|
1484
|
+
if (index === -1) {
|
|
1485
|
+
const insertAt = filtered.at(-1) === "" ? filtered.length - 1 : filtered.length;
|
|
1486
|
+
filtered.splice(insertAt, 0, value);
|
|
1487
|
+
} else filtered[index] = value;
|
|
1488
|
+
writeTextAtomic(envPath(ctx), filtered.join("\n"), 384);
|
|
1489
|
+
};
|
|
1490
|
+
var stripKey = (ctx) => {
|
|
1491
|
+
const text = readTextIfExists(envPath(ctx));
|
|
1492
|
+
if (text === null) return false;
|
|
1493
|
+
const lines = text.split("\n");
|
|
1494
|
+
const filtered = lines.filter((line) => !keyLine.test(line));
|
|
1495
|
+
if (filtered.length === lines.length) return false;
|
|
1496
|
+
writeTextAtomic(envPath(ctx), filtered.join("\n"), 384);
|
|
1497
|
+
return true;
|
|
1498
|
+
};
|
|
1499
|
+
var result = (ctx) => ({
|
|
1500
|
+
harness: ID,
|
|
1501
|
+
label: LABEL,
|
|
1502
|
+
configured: readKey(ctx) !== null,
|
|
1503
|
+
files: files(ctx)
|
|
1504
|
+
});
|
|
1505
|
+
var configureBloom = (ctx, apiKey) => {
|
|
1506
|
+
applyWithSnapshot(ctx, ID, files(ctx), () => setKey(ctx, apiKey));
|
|
1507
|
+
return result(ctx);
|
|
1508
|
+
};
|
|
1509
|
+
var disableBloom = (ctx) => {
|
|
1510
|
+
const outcome = restoreOrStrip(ctx, ID, files(ctx), () => stripKey(ctx));
|
|
1511
|
+
return { ...result(ctx), configured: false, outcome };
|
|
1512
|
+
};
|
|
1513
|
+
var bloom = {
|
|
1514
|
+
id: ID,
|
|
1515
|
+
label: LABEL,
|
|
1516
|
+
description: "Create and configure a dedicated Pollinations key for Bloom",
|
|
1517
|
+
restartHint: "Changes apply on the next Bloom session. Start Bloom with: bloom",
|
|
1518
|
+
async on(ctx, options) {
|
|
1519
|
+
if (!commandExists("bloom", ctx.env)) {
|
|
1520
|
+
throw new Error(
|
|
1521
|
+
"Bloom was not found. Install it first: uv tool install bloom-cli"
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
const apiKey = await resolveHarnessKey(
|
|
1525
|
+
{ id: ID, label: LABEL, existingKey: readKey(ctx) },
|
|
1526
|
+
{ browser: options.browser }
|
|
1527
|
+
);
|
|
1528
|
+
return configureBloom(ctx, apiKey);
|
|
1529
|
+
},
|
|
1530
|
+
off: disableBloom,
|
|
1531
|
+
status: result
|
|
1532
|
+
};
|
|
1533
|
+
|
|
1442
1534
|
// src/harnesses/dsh.ts
|
|
1443
|
-
|
|
1444
|
-
|
|
1535
|
+
import { join as join5 } from "path";
|
|
1536
|
+
import { parseEnv as parseEnv2 } from "util";
|
|
1537
|
+
import { isMap, isSeq, parseDocument, Scalar } from "yaml";
|
|
1538
|
+
|
|
1539
|
+
// SKILL.md?raw
|
|
1540
|
+
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 <bloom\\|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 create --config code-agent.json\npolli agents update <id> --config agent.json\npolli agents delete <id>\n```\nPrompt-agent config contains `systemPrompt`, `baseModel`, and optional `mcpServers`; create also requires `--name` and `--title`. Code-agent config contains `type: "code_agent"` and a public GitHub `repository` with `agent.ts` at its root; its model ID, title, and description come from GitHub. Use server IDs from the MCP catalog. Prompt-agent updates replace the complete runtime 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 bloom on # create a dedicated key for Bloom CLI\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`; Bloom, OpenCode, OpenClaw, and Pi require their installed commands.\n\nBloom already uses Pollinations and only needs a dedicated key in `$BLOOM_HOME/.env` (default `~/.bloom/.env`). The 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';
|
|
1541
|
+
|
|
1542
|
+
// src/harnesses/models.ts
|
|
1543
|
+
var fetchHarnessModels = async (selectedModel) => {
|
|
1544
|
+
const { data } = await gen("/v1/models");
|
|
1545
|
+
const models2 = data.filter(
|
|
1546
|
+
(m) => m.tools === true && m.output_modalities?.includes("text") && m.supported_endpoints?.includes("/v1/chat/completions") && m.context_length && !m.agent && m.community !== true
|
|
1547
|
+
).map((m) => ({
|
|
1548
|
+
id: m.id,
|
|
1549
|
+
contextWindow: m.context_length,
|
|
1550
|
+
input: (m.input_modalities ?? ["text"]).filter(
|
|
1551
|
+
(modality) => modality === "text" || modality === "image"
|
|
1552
|
+
)
|
|
1553
|
+
}));
|
|
1554
|
+
if (!models2.some((model) => model.id === selectedModel)) {
|
|
1555
|
+
throw new Error(
|
|
1556
|
+
`Model "${selectedModel}" is not a tool-calling text model. Run: polli models`
|
|
1557
|
+
);
|
|
1558
|
+
}
|
|
1559
|
+
return models2;
|
|
1560
|
+
};
|
|
1561
|
+
|
|
1562
|
+
// src/harnesses/dsh.ts
|
|
1563
|
+
var ID2 = "dsh";
|
|
1564
|
+
var LABEL2 = "DeepSeek Harness";
|
|
1445
1565
|
var PROVIDER = "pollinations";
|
|
1446
|
-
var DEFAULT_MODEL = "deepseek";
|
|
1447
|
-
var
|
|
1566
|
+
var DEFAULT_MODEL = "deepseek/deepseek-v4-flash";
|
|
1567
|
+
var KEY_ENV2 = "POLLI_DSH_API_KEY";
|
|
1448
1568
|
var MCP_ID = "mcp-pollinations";
|
|
1449
1569
|
var MCP_URL = `${BASE_URL}/mcp/pollinations`;
|
|
1450
1570
|
var PROVIDER_PATH = ["llm-pi-ai", "providers", PROVIDER];
|
|
@@ -1456,48 +1576,47 @@ var JS_TAG = {
|
|
|
1456
1576
|
};
|
|
1457
1577
|
var dshHome = (ctx) => {
|
|
1458
1578
|
const configured = ctx.env.DSH_HOME;
|
|
1459
|
-
if (!configured?.trim()) return
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
var
|
|
1464
|
-
var
|
|
1465
|
-
var
|
|
1466
|
-
var skillPath = (ctx) => join4(dshHome(ctx), "skills", "polli", "SKILL.md");
|
|
1579
|
+
if (!configured?.trim()) return join5(ctx.home, ".dsh");
|
|
1580
|
+
return resolveHomePath(ctx.home, configured);
|
|
1581
|
+
};
|
|
1582
|
+
var settingsPath = (ctx) => join5(dshHome(ctx), "settings.yaml");
|
|
1583
|
+
var envPath2 = (ctx) => join5(dshHome(ctx), ".env");
|
|
1584
|
+
var patchPath = (ctx) => join5(dshHome(ctx), "cordis.patch.yml");
|
|
1585
|
+
var skillPath = (ctx) => join5(dshHome(ctx), "skills", "polli", "SKILL.md");
|
|
1467
1586
|
var loadYaml = (path) => parseDocument(readTextIfExists(path) ?? "", { customTags: [JS_TAG] });
|
|
1468
|
-
var
|
|
1587
|
+
var files2 = (ctx) => [
|
|
1469
1588
|
settingsPath(ctx),
|
|
1470
|
-
|
|
1589
|
+
envPath2(ctx),
|
|
1471
1590
|
patchPath(ctx),
|
|
1472
1591
|
skillPath(ctx)
|
|
1473
1592
|
];
|
|
1474
|
-
var
|
|
1475
|
-
const text = readTextIfExists(
|
|
1593
|
+
var readKey2 = (ctx) => {
|
|
1594
|
+
const text = readTextIfExists(envPath2(ctx));
|
|
1476
1595
|
if (text === null) return null;
|
|
1477
|
-
const key =
|
|
1596
|
+
const key = parseEnv2(text)[KEY_ENV2];
|
|
1478
1597
|
return key || null;
|
|
1479
1598
|
};
|
|
1480
|
-
var envLine = (key) => `${
|
|
1481
|
-
var
|
|
1599
|
+
var envLine = (key) => `${KEY_ENV2}=${JSON.stringify(key)}`;
|
|
1600
|
+
var keyLine2 = new RegExp(`^\\s*(?:export\\s+)?${KEY_ENV2}\\s*=`, "u");
|
|
1482
1601
|
var setEnvKey = (ctx, key) => {
|
|
1483
|
-
const lines = (readTextIfExists(
|
|
1484
|
-
const index = lines.findIndex((line) =>
|
|
1602
|
+
const lines = (readTextIfExists(envPath2(ctx)) ?? "").split("\n");
|
|
1603
|
+
const index = lines.findIndex((line) => keyLine2.test(line));
|
|
1485
1604
|
const filtered = lines.filter(
|
|
1486
|
-
(line, i) => i === index || !
|
|
1605
|
+
(line, i) => i === index || !keyLine2.test(line)
|
|
1487
1606
|
);
|
|
1488
1607
|
if (index === -1) {
|
|
1489
1608
|
const insertAt = filtered.at(-1) === "" ? filtered.length - 1 : filtered.length;
|
|
1490
1609
|
filtered.splice(insertAt, 0, envLine(key));
|
|
1491
1610
|
} else filtered[index] = envLine(key);
|
|
1492
|
-
writeTextAtomic(
|
|
1611
|
+
writeTextAtomic(envPath2(ctx), filtered.join("\n"), 384);
|
|
1493
1612
|
};
|
|
1494
1613
|
var deleteEnvKey = (ctx) => {
|
|
1495
|
-
const text = readTextIfExists(
|
|
1614
|
+
const text = readTextIfExists(envPath2(ctx));
|
|
1496
1615
|
if (text === null) return false;
|
|
1497
1616
|
const lines = text.split("\n");
|
|
1498
|
-
const filtered = lines.filter((line) => !
|
|
1617
|
+
const filtered = lines.filter((line) => !keyLine2.test(line));
|
|
1499
1618
|
if (filtered.length === lines.length) return false;
|
|
1500
|
-
writeTextAtomic(
|
|
1619
|
+
writeTextAtomic(envPath2(ctx), filtered.join("\n"), 384);
|
|
1501
1620
|
return true;
|
|
1502
1621
|
};
|
|
1503
1622
|
var stripMcpEntry = (doc) => {
|
|
@@ -1533,7 +1652,7 @@ var writeMcpEntry = (ctx) => {
|
|
|
1533
1652
|
}
|
|
1534
1653
|
stripMcpEntry(doc);
|
|
1535
1654
|
const authorization = doc.createNode(
|
|
1536
|
-
`\`Bearer \${process.env.${
|
|
1655
|
+
`\`Bearer \${process.env.${KEY_ENV2}}\``
|
|
1537
1656
|
);
|
|
1538
1657
|
authorization.tag = "tag:yaml.org,2002:js";
|
|
1539
1658
|
authorization.type = Scalar.QUOTE_SINGLE;
|
|
@@ -1566,7 +1685,7 @@ var hasMcpEntry = (ctx) => {
|
|
|
1566
1685
|
};
|
|
1567
1686
|
var providerConfig = (models2) => ({
|
|
1568
1687
|
displayName: "Pollinations.ai",
|
|
1569
|
-
apiKeyEnv:
|
|
1688
|
+
apiKeyEnv: KEY_ENV2,
|
|
1570
1689
|
api: "openai-completions",
|
|
1571
1690
|
baseURL: `${BASE_URL}/v1`,
|
|
1572
1691
|
compat: {
|
|
@@ -1621,34 +1740,29 @@ var stripConfig = (ctx) => {
|
|
|
1621
1740
|
}
|
|
1622
1741
|
return changed;
|
|
1623
1742
|
};
|
|
1624
|
-
var
|
|
1743
|
+
var result2 = (ctx) => {
|
|
1625
1744
|
const doc = loadYaml(settingsPath(ctx));
|
|
1626
1745
|
const model = doc.getIn([...DEFAULT_MODEL_PATH, "model"]);
|
|
1627
1746
|
return {
|
|
1628
|
-
harness:
|
|
1629
|
-
label:
|
|
1630
|
-
configured: doc.getIn([...PROVIDER_PATH, "apiKeyEnv"]) ===
|
|
1747
|
+
harness: ID2,
|
|
1748
|
+
label: LABEL2,
|
|
1749
|
+
configured: doc.getIn([...PROVIDER_PATH, "apiKeyEnv"]) === KEY_ENV2 && doc.getIn([...PROVIDER_PATH, "api"]) === "openai-completions" && doc.getIn([...PROVIDER_PATH, "baseURL"]) === `${BASE_URL}/v1` && doc.getIn([...DEFAULT_MODEL_PATH, "provider"]) === PROVIDER && typeof model === "string" && readKey2(ctx) !== null && readTextIfExists(skillPath(ctx)) !== null,
|
|
1631
1750
|
model: typeof model === "string" ? model : void 0,
|
|
1632
1751
|
mcp: hasMcpEntry(ctx),
|
|
1633
|
-
files:
|
|
1752
|
+
files: files2(ctx)
|
|
1634
1753
|
};
|
|
1635
1754
|
};
|
|
1636
1755
|
var configureDsh = (ctx, settings) => {
|
|
1637
|
-
applyWithSnapshot(ctx,
|
|
1638
|
-
return
|
|
1756
|
+
applyWithSnapshot(ctx, ID2, files2(ctx), () => writeConfig(ctx, settings));
|
|
1757
|
+
return result2(ctx);
|
|
1639
1758
|
};
|
|
1640
1759
|
var disableDsh = (ctx) => {
|
|
1641
|
-
const
|
|
1642
|
-
|
|
1643
|
-
if (restoreSnapshot(ctx, ID, managedFiles) !== "restored") {
|
|
1644
|
-
outcome = stripConfig(ctx) ? "stripped" : "unchanged";
|
|
1645
|
-
clearSnapshot(ctx, ID, managedFiles);
|
|
1646
|
-
}
|
|
1647
|
-
return { ...result(ctx), configured: false, outcome };
|
|
1760
|
+
const outcome = restoreOrStrip(ctx, ID2, files2(ctx), () => stripConfig(ctx));
|
|
1761
|
+
return { ...result2(ctx), configured: false, outcome };
|
|
1648
1762
|
};
|
|
1649
1763
|
var dsh = {
|
|
1650
|
-
id:
|
|
1651
|
-
label:
|
|
1764
|
+
id: ID2,
|
|
1765
|
+
label: LABEL2,
|
|
1652
1766
|
description: "Configure DeepSeek Harness as a Pollinations provider",
|
|
1653
1767
|
restartHint: "Changes apply on the next request. Start DeepSeek Harness with: npx @deepseek-ai/dsh web",
|
|
1654
1768
|
async on(ctx, options) {
|
|
@@ -1658,14 +1772,9 @@ var dsh = {
|
|
|
1658
1772
|
);
|
|
1659
1773
|
}
|
|
1660
1774
|
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
|
-
}
|
|
1775
|
+
const models2 = await fetchHarnessModels(model);
|
|
1667
1776
|
const apiKey = await resolveHarnessKey(
|
|
1668
|
-
{ id:
|
|
1777
|
+
{ id: ID2, label: LABEL2, existingKey: readKey2(ctx) },
|
|
1669
1778
|
{ browser: options.browser }
|
|
1670
1779
|
);
|
|
1671
1780
|
return configureDsh(ctx, {
|
|
@@ -1676,38 +1785,200 @@ var dsh = {
|
|
|
1676
1785
|
});
|
|
1677
1786
|
},
|
|
1678
1787
|
off: disableDsh,
|
|
1679
|
-
status:
|
|
1788
|
+
status: result2
|
|
1789
|
+
};
|
|
1790
|
+
|
|
1791
|
+
// src/harnesses/openclaw.ts
|
|
1792
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
1793
|
+
import { join as join6 } from "path";
|
|
1794
|
+
import JSON5 from "json5";
|
|
1795
|
+
var ID3 = "openclaw";
|
|
1796
|
+
var LABEL3 = "OpenClaw";
|
|
1797
|
+
var PROVIDER2 = "pollinations";
|
|
1798
|
+
var DEFAULT_MODEL2 = "moonshotai/kimi-k2.6";
|
|
1799
|
+
var KEY_ENV3 = "POLLI_OPENCLAW_API_KEY";
|
|
1800
|
+
var openclawStateDir = (ctx) => {
|
|
1801
|
+
const stateDir = ctx.env.OPENCLAW_STATE_DIR?.trim();
|
|
1802
|
+
if (stateDir) return resolveHomePath(ctx.home, stateDir);
|
|
1803
|
+
const home = ctx.env.OPENCLAW_HOME?.trim();
|
|
1804
|
+
return join6(home ? resolveHomePath(ctx.home, home) : ctx.home, ".openclaw");
|
|
1805
|
+
};
|
|
1806
|
+
var configPath = (ctx) => {
|
|
1807
|
+
const override = ctx.env.OPENCLAW_CONFIG_PATH?.trim();
|
|
1808
|
+
return override ? resolveHomePath(ctx.home, override) : join6(openclawStateDir(ctx), "openclaw.json");
|
|
1809
|
+
};
|
|
1810
|
+
var skillFile = (ctx) => join6(openclawStateDir(ctx), "skills", "polli", "SKILL.md");
|
|
1811
|
+
var files3 = (ctx) => [configPath(ctx), skillFile(ctx)];
|
|
1812
|
+
var loadJson = (path) => {
|
|
1813
|
+
const text = readTextIfExists(path);
|
|
1814
|
+
if (!text?.trim()) return {};
|
|
1815
|
+
return JSON5.parse(text);
|
|
1816
|
+
};
|
|
1817
|
+
var saveJson = (path, data) => {
|
|
1818
|
+
writeTextAtomic(path, `${JSON.stringify(data, null, 2)}
|
|
1819
|
+
`, 384);
|
|
1820
|
+
};
|
|
1821
|
+
var readKey3 = (ctx) => {
|
|
1822
|
+
const env = loadJson(configPath(ctx)).env;
|
|
1823
|
+
const key = env?.vars?.[KEY_ENV3];
|
|
1824
|
+
return typeof key === "string" && key ? key : null;
|
|
1825
|
+
};
|
|
1826
|
+
var providerEntry = (models2) => ({
|
|
1827
|
+
baseUrl: `${BASE_URL}/v1`,
|
|
1828
|
+
apiKey: `\${${KEY_ENV3}}`,
|
|
1829
|
+
api: "openai-completions",
|
|
1830
|
+
models: models2.map((model) => ({
|
|
1831
|
+
id: model.id,
|
|
1832
|
+
name: model.id,
|
|
1833
|
+
contextWindow: model.contextWindow,
|
|
1834
|
+
input: model.input
|
|
1835
|
+
}))
|
|
1836
|
+
});
|
|
1837
|
+
var asRecord = (value) => value && typeof value === "object" ? value : {};
|
|
1838
|
+
var writeConfig2 = (ctx, models2, apiKey, model) => {
|
|
1839
|
+
const doc = loadJson(configPath(ctx));
|
|
1840
|
+
const env = asRecord(doc.env);
|
|
1841
|
+
const vars = asRecord(env.vars);
|
|
1842
|
+
vars[KEY_ENV3] = apiKey;
|
|
1843
|
+
env.vars = vars;
|
|
1844
|
+
doc.env = env;
|
|
1845
|
+
const modelsConfig = asRecord(doc.models);
|
|
1846
|
+
const providers = asRecord(modelsConfig.providers);
|
|
1847
|
+
providers[PROVIDER2] = providerEntry(models2);
|
|
1848
|
+
modelsConfig.providers = providers;
|
|
1849
|
+
doc.models = modelsConfig;
|
|
1850
|
+
const agents = asRecord(doc.agents);
|
|
1851
|
+
const defaults = asRecord(agents.defaults);
|
|
1852
|
+
const agentModel = asRecord(defaults.model);
|
|
1853
|
+
agentModel.primary = `${PROVIDER2}/${model}`;
|
|
1854
|
+
defaults.model = agentModel;
|
|
1855
|
+
agents.defaults = defaults;
|
|
1856
|
+
doc.agents = agents;
|
|
1857
|
+
saveJson(configPath(ctx), doc);
|
|
1858
|
+
if (readTextIfExists(skillFile(ctx)) === null) {
|
|
1859
|
+
writeTextAtomic(skillFile(ctx), SKILL_default, 384);
|
|
1860
|
+
}
|
|
1861
|
+
};
|
|
1862
|
+
var stripConfig2 = (ctx) => {
|
|
1863
|
+
let changed = false;
|
|
1864
|
+
const doc = loadJson(configPath(ctx));
|
|
1865
|
+
if (doc.env?.vars && KEY_ENV3 in asRecord(doc.env.vars)) {
|
|
1866
|
+
const vars = asRecord(doc.env.vars);
|
|
1867
|
+
delete vars[KEY_ENV3];
|
|
1868
|
+
if (Object.keys(vars).length === 0) delete doc.env.vars;
|
|
1869
|
+
saveJson(configPath(ctx), doc);
|
|
1870
|
+
changed = true;
|
|
1871
|
+
}
|
|
1872
|
+
const providers = asRecord(doc.models?.providers);
|
|
1873
|
+
if (PROVIDER2 in providers) {
|
|
1874
|
+
delete providers[PROVIDER2];
|
|
1875
|
+
if (Object.keys(providers).length === 0)
|
|
1876
|
+
delete asRecord(doc.models).providers;
|
|
1877
|
+
saveJson(configPath(ctx), doc);
|
|
1878
|
+
changed = true;
|
|
1879
|
+
}
|
|
1880
|
+
const primary = asRecord(doc.agents?.defaults?.model).primary;
|
|
1881
|
+
if (typeof primary === "string" && primary.startsWith(`${PROVIDER2}/`)) {
|
|
1882
|
+
delete asRecord(asRecord(doc.agents).defaults).model.primary;
|
|
1883
|
+
saveJson(configPath(ctx), doc);
|
|
1884
|
+
changed = true;
|
|
1885
|
+
}
|
|
1886
|
+
if (readTextIfExists(skillFile(ctx)) === SKILL_default) {
|
|
1887
|
+
removeIfExists(skillFile(ctx));
|
|
1888
|
+
changed = true;
|
|
1889
|
+
}
|
|
1890
|
+
return changed;
|
|
1891
|
+
};
|
|
1892
|
+
var result3 = (ctx) => {
|
|
1893
|
+
const doc = loadJson(configPath(ctx));
|
|
1894
|
+
const provider = asRecord(doc.models?.providers?.[PROVIDER2]);
|
|
1895
|
+
const primary = asRecord(doc.agents?.defaults?.model).primary;
|
|
1896
|
+
return {
|
|
1897
|
+
harness: ID3,
|
|
1898
|
+
label: LABEL3,
|
|
1899
|
+
configured: provider?.baseUrl === `${BASE_URL}/v1` && provider?.api === "openai-completions" && provider?.apiKey === `\${${KEY_ENV3}}` && typeof primary === "string" && primary.startsWith(`${PROVIDER2}/`) && readKey3(ctx) !== null && readTextIfExists(skillFile(ctx)) !== null,
|
|
1900
|
+
model: typeof primary === "string" && primary.startsWith(`${PROVIDER2}/`) ? primary.slice(`${PROVIDER2}/`.length) : void 0,
|
|
1901
|
+
files: files3(ctx)
|
|
1902
|
+
};
|
|
1903
|
+
};
|
|
1904
|
+
var configureOpenClaw = (ctx, models2, apiKey, model) => {
|
|
1905
|
+
applyWithSnapshot(
|
|
1906
|
+
ctx,
|
|
1907
|
+
ID3,
|
|
1908
|
+
files3(ctx),
|
|
1909
|
+
() => writeConfig2(ctx, models2, apiKey, model)
|
|
1910
|
+
);
|
|
1911
|
+
return result3(ctx);
|
|
1912
|
+
};
|
|
1913
|
+
var disableOpenClaw = (ctx) => {
|
|
1914
|
+
const outcome = restoreOrStrip(ctx, ID3, files3(ctx), () => stripConfig2(ctx));
|
|
1915
|
+
return { ...result3(ctx), configured: false, outcome };
|
|
1916
|
+
};
|
|
1917
|
+
var openclawInstalled = (ctx) => commandExists("openclaw", ctx.env);
|
|
1918
|
+
var initializeOpenClaw = (ctx) => {
|
|
1919
|
+
if (readTextIfExists(configPath(ctx)) !== null) return;
|
|
1920
|
+
const setup = spawnSync2("openclaw", ["setup", "--baseline"], {
|
|
1921
|
+
env: ctx.env,
|
|
1922
|
+
stdio: "ignore"
|
|
1923
|
+
});
|
|
1924
|
+
if (setup.error) throw setup.error;
|
|
1925
|
+
if (setup.status !== 0 || readTextIfExists(configPath(ctx)) === null) {
|
|
1926
|
+
throw new Error("OpenClaw baseline setup failed");
|
|
1927
|
+
}
|
|
1928
|
+
};
|
|
1929
|
+
var openclaw = {
|
|
1930
|
+
id: ID3,
|
|
1931
|
+
label: LABEL3,
|
|
1932
|
+
description: "Add Pollinations as a provider in OpenClaw",
|
|
1933
|
+
restartHint: "Restart the gateway: openclaw gateway restart (or /model inside chat to switch).",
|
|
1934
|
+
async on(ctx, options) {
|
|
1935
|
+
if (!openclawInstalled(ctx)) {
|
|
1936
|
+
throw new Error(
|
|
1937
|
+
"OpenClaw was not found. Install it from: https://openclaw.ai/install"
|
|
1938
|
+
);
|
|
1939
|
+
}
|
|
1940
|
+
const model = options.model ?? DEFAULT_MODEL2;
|
|
1941
|
+
const models2 = await fetchHarnessModels(model);
|
|
1942
|
+
initializeOpenClaw(ctx);
|
|
1943
|
+
const apiKey = await resolveHarnessKey(
|
|
1944
|
+
{ id: ID3, label: LABEL3, existingKey: readKey3(ctx) },
|
|
1945
|
+
{ browser: options.browser }
|
|
1946
|
+
);
|
|
1947
|
+
return configureOpenClaw(ctx, models2, apiKey, model);
|
|
1948
|
+
},
|
|
1949
|
+
off: disableOpenClaw,
|
|
1950
|
+
status: result3
|
|
1680
1951
|
};
|
|
1681
1952
|
|
|
1682
1953
|
// src/harnesses/opencode.ts
|
|
1683
|
-
import { join as
|
|
1684
|
-
|
|
1685
|
-
var
|
|
1686
|
-
var
|
|
1954
|
+
import { join as join7 } from "path";
|
|
1955
|
+
import JSON52 from "json5";
|
|
1956
|
+
var ID4 = "opencode";
|
|
1957
|
+
var LABEL4 = "OpenCode";
|
|
1958
|
+
var DEFAULT_MODEL3 = "openai/gpt-5.4-nano";
|
|
1687
1959
|
var PLUGIN_SPEC = "opencode-pollinations-plugin";
|
|
1688
1960
|
var pollinationsConfigDir = (ctx) => {
|
|
1689
1961
|
if (process.platform === "win32") {
|
|
1690
|
-
return
|
|
1962
|
+
return join7(ctx.env.APPDATA ?? ctx.home, "pollinations");
|
|
1691
1963
|
}
|
|
1692
1964
|
if (process.platform === "darwin") {
|
|
1693
|
-
return
|
|
1965
|
+
return join7(ctx.home, "Library", "Application Support", "pollinations");
|
|
1694
1966
|
}
|
|
1695
1967
|
const xdg = ctx.env.XDG_CONFIG_HOME?.trim();
|
|
1696
|
-
return
|
|
1697
|
-
xdg ?
|
|
1968
|
+
return join7(
|
|
1969
|
+
xdg ? resolveHomePath(ctx.home, xdg) : join7(ctx.home, ".config"),
|
|
1698
1970
|
"pollinations"
|
|
1699
1971
|
);
|
|
1700
1972
|
};
|
|
1701
|
-
var expandTilde = (ctx, path) => path === "~" ? ctx.home : path.startsWith("~/") || path.startsWith("~\\") ? join5(ctx.home, path.slice(2)) : path;
|
|
1702
1973
|
var opencodeConfigFile = (ctx) => {
|
|
1703
1974
|
if (ctx.env.OPENCODE_CONFIG?.trim()) {
|
|
1704
|
-
return
|
|
1975
|
+
return resolveHomePath(ctx.home, ctx.env.OPENCODE_CONFIG);
|
|
1705
1976
|
}
|
|
1706
|
-
const dir = ctx.env.OPENCODE_CONFIG_DIR?.trim() ?
|
|
1707
|
-
return
|
|
1977
|
+
const dir = ctx.env.OPENCODE_CONFIG_DIR?.trim() ? resolveHomePath(ctx.home, ctx.env.OPENCODE_CONFIG_DIR) : join7(ctx.home, ".config", "opencode");
|
|
1978
|
+
return ["opencode.jsonc", "opencode.json", "config.json"].map((name) => join7(dir, name)).find((path) => readTextIfExists(path) !== null) ?? join7(dir, "opencode.json");
|
|
1708
1979
|
};
|
|
1709
|
-
var pluginConfigFile = (ctx) =>
|
|
1710
|
-
var
|
|
1980
|
+
var pluginConfigFile = (ctx) => join7(pollinationsConfigDir(ctx), "config.json");
|
|
1981
|
+
var files4 = (ctx) => [
|
|
1711
1982
|
opencodeConfigFile(ctx),
|
|
1712
1983
|
pluginConfigFile(ctx)
|
|
1713
1984
|
];
|
|
@@ -1715,13 +1986,18 @@ var readJson = (path) => {
|
|
|
1715
1986
|
const text = readTextIfExists(path);
|
|
1716
1987
|
if (text === null) return null;
|
|
1717
1988
|
try {
|
|
1718
|
-
const parsed =
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1989
|
+
const parsed = JSON52.parse(text);
|
|
1990
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
1991
|
+
return parsed;
|
|
1992
|
+
}
|
|
1993
|
+
} catch (error) {
|
|
1994
|
+
throw new Error(`Could not parse OpenCode config at ${path}`, {
|
|
1995
|
+
cause: error
|
|
1996
|
+
});
|
|
1722
1997
|
}
|
|
1998
|
+
throw new Error(`OpenCode config at ${path} must contain an object`);
|
|
1723
1999
|
};
|
|
1724
|
-
var writeJson = (
|
|
2000
|
+
var writeJson = (path, data) => writeTextAtomic(path, `${JSON.stringify(data, null, 2)}
|
|
1725
2001
|
`, 384);
|
|
1726
2002
|
var isPluginEntry = (entry) => typeof entry === "string" ? entry === PLUGIN_SPEC || entry.includes(PLUGIN_SPEC) : entry !== null && typeof entry === "object" && Object.values(entry).some(
|
|
1727
2003
|
(value) => typeof value === "string" && value.includes(PLUGIN_SPEC)
|
|
@@ -1732,13 +2008,13 @@ var hasPluginEntry = (config) => {
|
|
|
1732
2008
|
return Array.isArray(entries) && entries.some(isPluginEntry);
|
|
1733
2009
|
};
|
|
1734
2010
|
var readApiKey = (ctx) => {
|
|
1735
|
-
const key =
|
|
2011
|
+
const key = readJson(pluginConfigFile(ctx))?.apiKey;
|
|
1736
2012
|
return typeof key === "string" && key.length > 5 ? key : null;
|
|
1737
2013
|
};
|
|
1738
2014
|
var writeApiKey = (ctx, apiKey) => {
|
|
1739
2015
|
const config = readJson(pluginConfigFile(ctx)) ?? {};
|
|
1740
2016
|
config.apiKey = apiKey;
|
|
1741
|
-
writeJson(
|
|
2017
|
+
writeJson(pluginConfigFile(ctx), config);
|
|
1742
2018
|
};
|
|
1743
2019
|
var deleteApiKey = (ctx) => {
|
|
1744
2020
|
const path = pluginConfigFile(ctx);
|
|
@@ -1746,7 +2022,7 @@ var deleteApiKey = (ctx) => {
|
|
|
1746
2022
|
if (config === null || config.apiKey === void 0) return false;
|
|
1747
2023
|
delete config.apiKey;
|
|
1748
2024
|
if (Object.keys(config).length === 0) removeIfExists(path);
|
|
1749
|
-
else writeJson(
|
|
2025
|
+
else writeJson(path, config);
|
|
1750
2026
|
return true;
|
|
1751
2027
|
};
|
|
1752
2028
|
var openCodeConfig = (ctx) => readJson(opencodeConfigFile(ctx)) ?? {};
|
|
@@ -1763,7 +2039,7 @@ var writeOpenCodeConfig = (ctx, model) => {
|
|
|
1763
2039
|
config[key] = [...entries, PLUGIN_SPEC];
|
|
1764
2040
|
}
|
|
1765
2041
|
config.model = defaultModelRef(model);
|
|
1766
|
-
writeJson(
|
|
2042
|
+
writeJson(opencodeConfigFile(ctx), config);
|
|
1767
2043
|
};
|
|
1768
2044
|
var stripOpenCodeConfig = (ctx) => {
|
|
1769
2045
|
const path = opencodeConfigFile(ctx);
|
|
@@ -1782,48 +2058,43 @@ var stripOpenCodeConfig = (ctx) => {
|
|
|
1782
2058
|
delete config.model;
|
|
1783
2059
|
changed = true;
|
|
1784
2060
|
}
|
|
1785
|
-
if (changed) writeJson(
|
|
2061
|
+
if (changed) writeJson(path, config);
|
|
1786
2062
|
return changed;
|
|
1787
2063
|
};
|
|
1788
|
-
var
|
|
2064
|
+
var result4 = (ctx) => {
|
|
1789
2065
|
const config = openCodeConfig(ctx);
|
|
1790
2066
|
const model = isOurDefaultModel(config.model) ? config.model.slice("pollinations/enter/".length) : void 0;
|
|
1791
2067
|
return {
|
|
1792
|
-
harness:
|
|
1793
|
-
label:
|
|
2068
|
+
harness: ID4,
|
|
2069
|
+
label: LABEL4,
|
|
1794
2070
|
configured: hasPluginEntry(config) && isOurDefaultModel(config.model) && readApiKey(ctx) !== null,
|
|
1795
2071
|
model,
|
|
1796
|
-
files:
|
|
2072
|
+
files: files4(ctx)
|
|
1797
2073
|
};
|
|
1798
2074
|
};
|
|
1799
|
-
var
|
|
2075
|
+
var writeConfig3 = (ctx, settings) => {
|
|
1800
2076
|
writeOpenCodeConfig(ctx, settings.model);
|
|
1801
2077
|
writeApiKey(ctx, settings.apiKey);
|
|
1802
2078
|
};
|
|
1803
|
-
var
|
|
2079
|
+
var stripConfig3 = (ctx) => {
|
|
1804
2080
|
let changed = stripOpenCodeConfig(ctx);
|
|
1805
2081
|
changed = deleteApiKey(ctx) || changed;
|
|
1806
2082
|
return changed;
|
|
1807
2083
|
};
|
|
1808
2084
|
var configureOpenCode = (ctx, settings) => {
|
|
1809
|
-
applyWithSnapshot(ctx,
|
|
1810
|
-
return
|
|
2085
|
+
applyWithSnapshot(ctx, ID4, files4(ctx), () => writeConfig3(ctx, settings));
|
|
2086
|
+
return result4(ctx);
|
|
1811
2087
|
};
|
|
1812
2088
|
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 };
|
|
2089
|
+
const outcome = restoreOrStrip(ctx, ID4, files4(ctx), () => stripConfig3(ctx));
|
|
2090
|
+
return { ...result4(ctx), configured: false, outcome };
|
|
1820
2091
|
};
|
|
1821
2092
|
var openCodeInstalled = (ctx) => commandExists("opencode", ctx.env, [
|
|
1822
|
-
|
|
2093
|
+
join7(ctx.home, ".opencode", "bin", "opencode")
|
|
1823
2094
|
]);
|
|
1824
2095
|
var opencode = {
|
|
1825
|
-
id:
|
|
1826
|
-
label:
|
|
2096
|
+
id: ID4,
|
|
2097
|
+
label: LABEL4,
|
|
1827
2098
|
description: "Configure OpenCode to use Pollinations",
|
|
1828
2099
|
restartHint: "Restart OpenCode, then pick a Pollinations model with /models. Inside OpenCode: /poll quests shows claimable Pollen, /poll help lists the media tools.",
|
|
1829
2100
|
async on(ctx, options) {
|
|
@@ -1832,17 +2103,12 @@ var opencode = {
|
|
|
1832
2103
|
"OpenCode was not found. Install it first: curl -fsSL https://opencode.ai/install | bash"
|
|
1833
2104
|
);
|
|
1834
2105
|
}
|
|
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
|
-
}
|
|
2106
|
+
const model = options.model ?? DEFAULT_MODEL3;
|
|
2107
|
+
await fetchHarnessModels(model);
|
|
1842
2108
|
const apiKey = await resolveHarnessKey(
|
|
1843
2109
|
{
|
|
1844
|
-
id:
|
|
1845
|
-
label:
|
|
2110
|
+
id: ID4,
|
|
2111
|
+
label: LABEL4,
|
|
1846
2112
|
existingKey: readApiKey(ctx),
|
|
1847
2113
|
accountPermissions: ["profile", "usage"]
|
|
1848
2114
|
},
|
|
@@ -1851,43 +2117,42 @@ var opencode = {
|
|
|
1851
2117
|
return configureOpenCode(ctx, { apiKey, model });
|
|
1852
2118
|
},
|
|
1853
2119
|
off: disableOpenCode,
|
|
1854
|
-
status:
|
|
2120
|
+
status: result4
|
|
1855
2121
|
};
|
|
1856
2122
|
|
|
1857
2123
|
// src/harnesses/pi.ts
|
|
1858
|
-
import { join as
|
|
1859
|
-
var
|
|
1860
|
-
var
|
|
1861
|
-
var
|
|
1862
|
-
var
|
|
2124
|
+
import { join as join8 } from "path";
|
|
2125
|
+
var ID5 = "pi";
|
|
2126
|
+
var LABEL5 = "Pi";
|
|
2127
|
+
var PROVIDER3 = "pollinations";
|
|
2128
|
+
var DEFAULT_MODEL4 = "deepseek/deepseek-v4-flash";
|
|
1863
2129
|
var piAgentDir = (ctx) => {
|
|
1864
2130
|
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) => [
|
|
2131
|
+
if (!configured?.trim()) return join8(ctx.home, ".pi", "agent");
|
|
2132
|
+
return resolveHomePath(ctx.home, configured);
|
|
2133
|
+
};
|
|
2134
|
+
var modelsPath = (ctx) => join8(piAgentDir(ctx), "models.json");
|
|
2135
|
+
var authPath = (ctx) => join8(piAgentDir(ctx), "auth.json");
|
|
2136
|
+
var settingsPath2 = (ctx) => join8(piAgentDir(ctx), "settings.json");
|
|
2137
|
+
var skillFile2 = (ctx) => join8(piAgentDir(ctx), "skills", "polli", "SKILL.md");
|
|
2138
|
+
var files5 = (ctx) => [
|
|
1874
2139
|
modelsPath(ctx),
|
|
1875
2140
|
authPath(ctx),
|
|
1876
2141
|
settingsPath2(ctx),
|
|
1877
|
-
|
|
2142
|
+
skillFile2(ctx)
|
|
1878
2143
|
];
|
|
1879
|
-
var
|
|
2144
|
+
var loadJson2 = (path) => {
|
|
1880
2145
|
const text = readTextIfExists(path);
|
|
1881
2146
|
if (!text?.trim()) return {};
|
|
1882
2147
|
return JSON.parse(text);
|
|
1883
2148
|
};
|
|
1884
|
-
var
|
|
2149
|
+
var saveJson2 = (path, data) => {
|
|
1885
2150
|
writeTextAtomic(path, `${JSON.stringify(data, null, 2)}
|
|
1886
2151
|
`, 384);
|
|
1887
2152
|
};
|
|
1888
|
-
var
|
|
1889
|
-
const auth =
|
|
1890
|
-
const entry = auth[
|
|
2153
|
+
var readKey4 = (ctx) => {
|
|
2154
|
+
const auth = loadJson2(authPath(ctx));
|
|
2155
|
+
const entry = auth[PROVIDER3];
|
|
1891
2156
|
if (!entry || typeof entry !== "object") return null;
|
|
1892
2157
|
const key = entry.key;
|
|
1893
2158
|
return typeof key === "string" && key ? key : null;
|
|
@@ -1895,8 +2160,6 @@ var readKey2 = (ctx) => {
|
|
|
1895
2160
|
var providerConfig2 = (models2) => ({
|
|
1896
2161
|
baseUrl: `${BASE_URL}/v1`,
|
|
1897
2162
|
api: "openai-completions",
|
|
1898
|
-
// Pi validates custom providers before resolving their auth.json entry.
|
|
1899
|
-
apiKey: PROVIDER2,
|
|
1900
2163
|
compat: {
|
|
1901
2164
|
supportsStore: false,
|
|
1902
2165
|
supportsDeveloperRole: false,
|
|
@@ -1912,96 +2175,91 @@ var providerConfig2 = (models2) => ({
|
|
|
1912
2175
|
input: model.input
|
|
1913
2176
|
}))
|
|
1914
2177
|
});
|
|
1915
|
-
var
|
|
1916
|
-
const modelsData =
|
|
2178
|
+
var writeConfig4 = (ctx, settings) => {
|
|
2179
|
+
const modelsData = loadJson2(modelsPath(ctx));
|
|
1917
2180
|
const providers = modelsData.providers ?? {};
|
|
1918
2181
|
modelsData.providers = {
|
|
1919
2182
|
...providers,
|
|
1920
|
-
[
|
|
2183
|
+
[PROVIDER3]: providerConfig2(settings.models)
|
|
1921
2184
|
};
|
|
1922
|
-
|
|
1923
|
-
const auth =
|
|
1924
|
-
auth[
|
|
1925
|
-
|
|
1926
|
-
const piSettings =
|
|
1927
|
-
piSettings.defaultProvider =
|
|
2185
|
+
saveJson2(modelsPath(ctx), modelsData);
|
|
2186
|
+
const auth = loadJson2(authPath(ctx));
|
|
2187
|
+
auth[PROVIDER3] = { type: "api_key", key: settings.apiKey };
|
|
2188
|
+
saveJson2(authPath(ctx), auth);
|
|
2189
|
+
const piSettings = loadJson2(settingsPath2(ctx));
|
|
2190
|
+
piSettings.defaultProvider = PROVIDER3;
|
|
1928
2191
|
piSettings.defaultModel = settings.model;
|
|
1929
|
-
|
|
1930
|
-
if (readTextIfExists(
|
|
1931
|
-
writeTextAtomic(
|
|
2192
|
+
saveJson2(settingsPath2(ctx), piSettings);
|
|
2193
|
+
if (readTextIfExists(skillFile2(ctx)) === null) {
|
|
2194
|
+
writeTextAtomic(skillFile2(ctx), SKILL_default, 384);
|
|
1932
2195
|
}
|
|
1933
2196
|
};
|
|
1934
|
-
var
|
|
2197
|
+
var stripConfig4 = (ctx) => {
|
|
1935
2198
|
let changed = false;
|
|
1936
2199
|
const modelsText = readTextIfExists(modelsPath(ctx));
|
|
1937
2200
|
if (modelsText?.trim()) {
|
|
1938
2201
|
const data = JSON.parse(modelsText);
|
|
1939
|
-
if (data.providers && typeof data.providers === "object" &&
|
|
1940
|
-
delete data.providers[
|
|
1941
|
-
|
|
2202
|
+
if (data.providers && typeof data.providers === "object" && PROVIDER3 in data.providers) {
|
|
2203
|
+
delete data.providers[PROVIDER3];
|
|
2204
|
+
saveJson2(modelsPath(ctx), data);
|
|
1942
2205
|
changed = true;
|
|
1943
2206
|
}
|
|
1944
2207
|
}
|
|
1945
2208
|
const authText = readTextIfExists(authPath(ctx));
|
|
1946
2209
|
if (authText?.trim()) {
|
|
1947
2210
|
const data = JSON.parse(authText);
|
|
1948
|
-
if (
|
|
1949
|
-
delete data[
|
|
1950
|
-
|
|
2211
|
+
if (PROVIDER3 in data) {
|
|
2212
|
+
delete data[PROVIDER3];
|
|
2213
|
+
saveJson2(authPath(ctx), data);
|
|
1951
2214
|
changed = true;
|
|
1952
2215
|
}
|
|
1953
2216
|
}
|
|
1954
2217
|
const settingsText = readTextIfExists(settingsPath2(ctx));
|
|
1955
2218
|
if (settingsText?.trim()) {
|
|
1956
2219
|
const data = JSON.parse(settingsText);
|
|
1957
|
-
if (data.defaultProvider ===
|
|
2220
|
+
if (data.defaultProvider === PROVIDER3) {
|
|
1958
2221
|
delete data.defaultProvider;
|
|
1959
2222
|
delete data.defaultModel;
|
|
1960
|
-
|
|
2223
|
+
saveJson2(settingsPath2(ctx), data);
|
|
1961
2224
|
changed = true;
|
|
1962
2225
|
}
|
|
1963
2226
|
}
|
|
1964
|
-
if (readTextIfExists(
|
|
1965
|
-
removeIfExists(
|
|
2227
|
+
if (readTextIfExists(skillFile2(ctx)) === SKILL_default) {
|
|
2228
|
+
removeIfExists(skillFile2(ctx));
|
|
1966
2229
|
changed = true;
|
|
1967
2230
|
}
|
|
1968
2231
|
return changed;
|
|
1969
2232
|
};
|
|
1970
|
-
var
|
|
1971
|
-
const modelsData =
|
|
1972
|
-
const authData =
|
|
1973
|
-
const settingsData =
|
|
2233
|
+
var result5 = (ctx) => {
|
|
2234
|
+
const modelsData = loadJson2(modelsPath(ctx));
|
|
2235
|
+
const authData = loadJson2(authPath(ctx));
|
|
2236
|
+
const settingsData = loadJson2(settingsPath2(ctx));
|
|
1974
2237
|
const providers = modelsData.providers;
|
|
1975
|
-
const provider = providers?.[
|
|
1976
|
-
const hasProvider = provider?.
|
|
1977
|
-
const authEntry = authData[
|
|
2238
|
+
const provider = providers?.[PROVIDER3];
|
|
2239
|
+
const hasProvider = provider?.baseUrl === `${BASE_URL}/v1` && provider?.api === "openai-completions";
|
|
2240
|
+
const authEntry = authData[PROVIDER3];
|
|
1978
2241
|
const hasKey = authEntry?.type === "api_key" && typeof authEntry.key === "string" && !!authEntry.key;
|
|
1979
|
-
const hasDefaultProvider = settingsData.defaultProvider ===
|
|
2242
|
+
const hasDefaultProvider = settingsData.defaultProvider === PROVIDER3;
|
|
1980
2243
|
const model = typeof settingsData.defaultModel === "string" ? settingsData.defaultModel : void 0;
|
|
1981
2244
|
return {
|
|
1982
|
-
harness:
|
|
1983
|
-
label:
|
|
1984
|
-
configured: hasProvider && hasKey && hasDefaultProvider && readTextIfExists(
|
|
2245
|
+
harness: ID5,
|
|
2246
|
+
label: LABEL5,
|
|
2247
|
+
configured: hasProvider && hasKey && hasDefaultProvider && readTextIfExists(skillFile2(ctx)) !== null,
|
|
1985
2248
|
model,
|
|
1986
|
-
files:
|
|
2249
|
+
files: files5(ctx)
|
|
1987
2250
|
};
|
|
1988
2251
|
};
|
|
1989
2252
|
var configurePi = (ctx, settings) => {
|
|
1990
|
-
applyWithSnapshot(ctx,
|
|
1991
|
-
return
|
|
2253
|
+
applyWithSnapshot(ctx, ID5, files5(ctx), () => writeConfig4(ctx, settings));
|
|
2254
|
+
return result5(ctx);
|
|
1992
2255
|
};
|
|
1993
2256
|
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 };
|
|
2257
|
+
const outcome = restoreOrStrip(ctx, ID5, files5(ctx), () => stripConfig4(ctx));
|
|
2258
|
+
return { ...result5(ctx), configured: false, outcome };
|
|
2001
2259
|
};
|
|
2002
2260
|
var pi = {
|
|
2003
|
-
id:
|
|
2004
|
-
label:
|
|
2261
|
+
id: ID5,
|
|
2262
|
+
label: LABEL5,
|
|
2005
2263
|
description: "Configure Pi as a Pollinations provider",
|
|
2006
2264
|
restartHint: "Changes apply on the next Pi session. Start Pi with: pi",
|
|
2007
2265
|
async on(ctx, options) {
|
|
@@ -2010,25 +2268,183 @@ var pi = {
|
|
|
2010
2268
|
"Pi was not found. Install it first: npm install -g --ignore-scripts @earendil-works/pi-coding-agent"
|
|
2011
2269
|
);
|
|
2012
2270
|
}
|
|
2013
|
-
const model = options.model ??
|
|
2014
|
-
const models2 = await fetchHarnessModels();
|
|
2015
|
-
|
|
2271
|
+
const model = options.model ?? DEFAULT_MODEL4;
|
|
2272
|
+
const models2 = await fetchHarnessModels(model);
|
|
2273
|
+
const apiKey = await resolveHarnessKey(
|
|
2274
|
+
{ id: ID5, label: LABEL5, existingKey: readKey4(ctx) },
|
|
2275
|
+
{ browser: options.browser }
|
|
2276
|
+
);
|
|
2277
|
+
return configurePi(ctx, { apiKey, model, models: models2 });
|
|
2278
|
+
},
|
|
2279
|
+
off: disablePi,
|
|
2280
|
+
status: result5
|
|
2281
|
+
};
|
|
2282
|
+
|
|
2283
|
+
// src/harnesses/prime.ts
|
|
2284
|
+
import { join as join9 } from "path";
|
|
2285
|
+
var ID6 = "prime";
|
|
2286
|
+
var LABEL6 = "Prime Agent";
|
|
2287
|
+
var PROVIDER4 = "pollinations";
|
|
2288
|
+
var DEFAULT_MODEL5 = "deepseek/deepseek-v4-flash";
|
|
2289
|
+
var primeAgentDir = (ctx) => {
|
|
2290
|
+
const configured = ctx.env.PRIME_AGENT_CODING_AGENT_DIR;
|
|
2291
|
+
if (!configured?.trim()) return join9(ctx.home, ".prime", "agent");
|
|
2292
|
+
return resolveHomePath(ctx.home, configured);
|
|
2293
|
+
};
|
|
2294
|
+
var modelsPath2 = (ctx) => join9(primeAgentDir(ctx), "models.json");
|
|
2295
|
+
var authPath2 = (ctx) => join9(primeAgentDir(ctx), "auth.json");
|
|
2296
|
+
var settingsPath3 = (ctx) => join9(primeAgentDir(ctx), "settings.json");
|
|
2297
|
+
var skillPath2 = (ctx) => join9(primeAgentDir(ctx), "skills", "polli", "SKILL.md");
|
|
2298
|
+
var files6 = (ctx) => [
|
|
2299
|
+
modelsPath2(ctx),
|
|
2300
|
+
authPath2(ctx),
|
|
2301
|
+
settingsPath3(ctx),
|
|
2302
|
+
skillPath2(ctx)
|
|
2303
|
+
];
|
|
2304
|
+
var loadJson3 = (path) => {
|
|
2305
|
+
const text = readTextIfExists(path);
|
|
2306
|
+
if (!text?.trim()) return {};
|
|
2307
|
+
return JSON.parse(text);
|
|
2308
|
+
};
|
|
2309
|
+
var saveJson3 = (path, data) => {
|
|
2310
|
+
writeTextAtomic(path, `${JSON.stringify(data, null, 2)}
|
|
2311
|
+
`, 384);
|
|
2312
|
+
};
|
|
2313
|
+
var compat = {
|
|
2314
|
+
supportsStore: false,
|
|
2315
|
+
supportsDeveloperRole: false,
|
|
2316
|
+
supportsReasoningEffort: true,
|
|
2317
|
+
supportsUsageInStreaming: true,
|
|
2318
|
+
supportsStrictMode: false,
|
|
2319
|
+
maxTokensField: "max_tokens"
|
|
2320
|
+
};
|
|
2321
|
+
var providerEntry2 = (models2) => ({
|
|
2322
|
+
baseUrl: `${BASE_URL}/v1`,
|
|
2323
|
+
api: "openai-completions",
|
|
2324
|
+
// Prime validates custom providers before resolving their auth.json entry.
|
|
2325
|
+
apiKey: PROVIDER4,
|
|
2326
|
+
compat,
|
|
2327
|
+
models: models2.map((model) => ({
|
|
2328
|
+
id: model.id,
|
|
2329
|
+
name: model.id,
|
|
2330
|
+
input: model.input,
|
|
2331
|
+
contextWindow: model.contextWindow
|
|
2332
|
+
}))
|
|
2333
|
+
});
|
|
2334
|
+
var readKey5 = (ctx) => {
|
|
2335
|
+
const auth = loadJson3(authPath2(ctx));
|
|
2336
|
+
const credential = auth[PROVIDER4];
|
|
2337
|
+
return credential?.type === "api_key" && credential.key ? credential.key : null;
|
|
2338
|
+
};
|
|
2339
|
+
var writeAuth = (ctx, apiKey) => {
|
|
2340
|
+
const auth = loadJson3(authPath2(ctx));
|
|
2341
|
+
auth[PROVIDER4] = { type: "api_key", key: apiKey };
|
|
2342
|
+
saveJson3(authPath2(ctx), auth);
|
|
2343
|
+
};
|
|
2344
|
+
var deleteAuth = (ctx) => {
|
|
2345
|
+
const auth = loadJson3(authPath2(ctx));
|
|
2346
|
+
if (!(PROVIDER4 in auth)) return false;
|
|
2347
|
+
delete auth[PROVIDER4];
|
|
2348
|
+
if (Object.keys(auth).length === 0) removeIfExists(authPath2(ctx));
|
|
2349
|
+
else saveJson3(authPath2(ctx), auth);
|
|
2350
|
+
return true;
|
|
2351
|
+
};
|
|
2352
|
+
var writeConfig5 = (ctx, models2, apiKey, model) => {
|
|
2353
|
+
const doc = loadJson3(modelsPath2(ctx));
|
|
2354
|
+
const providers = doc.providers ?? {};
|
|
2355
|
+
providers[PROVIDER4] = providerEntry2(models2);
|
|
2356
|
+
doc.providers = providers;
|
|
2357
|
+
saveJson3(modelsPath2(ctx), doc);
|
|
2358
|
+
writeAuth(ctx, apiKey);
|
|
2359
|
+
const settings = loadJson3(settingsPath3(ctx));
|
|
2360
|
+
settings.defaultProvider = PROVIDER4;
|
|
2361
|
+
settings.defaultModel = model;
|
|
2362
|
+
saveJson3(settingsPath3(ctx), settings);
|
|
2363
|
+
if (readTextIfExists(skillPath2(ctx)) === null) {
|
|
2364
|
+
writeTextAtomic(skillPath2(ctx), SKILL_default, 384);
|
|
2365
|
+
}
|
|
2366
|
+
};
|
|
2367
|
+
var stripConfig5 = (ctx) => {
|
|
2368
|
+
let changed = false;
|
|
2369
|
+
const doc = loadJson3(modelsPath2(ctx));
|
|
2370
|
+
if (doc?.providers && PROVIDER4 in doc.providers) {
|
|
2371
|
+
delete doc.providers[PROVIDER4];
|
|
2372
|
+
if (Object.keys(doc.providers).length === 0) delete doc.providers;
|
|
2373
|
+
saveJson3(modelsPath2(ctx), doc);
|
|
2374
|
+
changed = true;
|
|
2375
|
+
}
|
|
2376
|
+
changed = deleteAuth(ctx) || changed;
|
|
2377
|
+
const settings = loadJson3(settingsPath3(ctx));
|
|
2378
|
+
if (settings && settings.defaultProvider === PROVIDER4) {
|
|
2379
|
+
delete settings.defaultProvider;
|
|
2380
|
+
delete settings.defaultModel;
|
|
2381
|
+
saveJson3(settingsPath3(ctx), settings);
|
|
2382
|
+
changed = true;
|
|
2383
|
+
}
|
|
2384
|
+
if (readTextIfExists(skillPath2(ctx)) === SKILL_default) {
|
|
2385
|
+
removeIfExists(skillPath2(ctx));
|
|
2386
|
+
changed = true;
|
|
2387
|
+
}
|
|
2388
|
+
return changed;
|
|
2389
|
+
};
|
|
2390
|
+
var result6 = (ctx) => {
|
|
2391
|
+
const doc = loadJson3(modelsPath2(ctx));
|
|
2392
|
+
const provider = doc?.providers?.[PROVIDER4];
|
|
2393
|
+
const settings = loadJson3(settingsPath3(ctx));
|
|
2394
|
+
const model = settings?.defaultProvider === PROVIDER4 ? settings.defaultModel : void 0;
|
|
2395
|
+
return {
|
|
2396
|
+
harness: ID6,
|
|
2397
|
+
label: LABEL6,
|
|
2398
|
+
configured: provider?.baseUrl === `${BASE_URL}/v1` && provider?.api === "openai-completions" && provider?.apiKey === PROVIDER4 && readKey5(ctx) !== null && readTextIfExists(skillPath2(ctx)) !== null,
|
|
2399
|
+
model: typeof model === "string" ? model : void 0,
|
|
2400
|
+
files: files6(ctx)
|
|
2401
|
+
};
|
|
2402
|
+
};
|
|
2403
|
+
var configurePrime = (ctx, models2, apiKey, model) => {
|
|
2404
|
+
applyWithSnapshot(
|
|
2405
|
+
ctx,
|
|
2406
|
+
ID6,
|
|
2407
|
+
files6(ctx),
|
|
2408
|
+
() => writeConfig5(ctx, models2, apiKey, model)
|
|
2409
|
+
);
|
|
2410
|
+
return result6(ctx);
|
|
2411
|
+
};
|
|
2412
|
+
var disablePrime = (ctx) => {
|
|
2413
|
+
const outcome = restoreOrStrip(ctx, ID6, files6(ctx), () => stripConfig5(ctx));
|
|
2414
|
+
return { ...result6(ctx), configured: false, outcome };
|
|
2415
|
+
};
|
|
2416
|
+
var prime = {
|
|
2417
|
+
id: ID6,
|
|
2418
|
+
label: LABEL6,
|
|
2419
|
+
description: "Add Pollinations as a custom provider in Prime Agent",
|
|
2420
|
+
restartHint: "Models reload when you open /model. Start Prime Agent with: prime-agent",
|
|
2421
|
+
async on(ctx, options) {
|
|
2422
|
+
if (!commandExists("prime-agent", ctx.env)) {
|
|
2016
2423
|
throw new Error(
|
|
2017
|
-
|
|
2424
|
+
"Prime Agent was not found. Install it first: curl -fsSL https://app.primeintellect.ai/prime-agent/install.sh | sh"
|
|
2018
2425
|
);
|
|
2019
2426
|
}
|
|
2427
|
+
const model = options.model ?? DEFAULT_MODEL5;
|
|
2428
|
+
const models2 = await fetchHarnessModels(model);
|
|
2020
2429
|
const apiKey = await resolveHarnessKey(
|
|
2021
|
-
{ id:
|
|
2430
|
+
{ id: ID6, label: LABEL6, existingKey: readKey5(ctx) },
|
|
2022
2431
|
{ browser: options.browser }
|
|
2023
2432
|
);
|
|
2024
|
-
return
|
|
2433
|
+
return configurePrime(ctx, models2, apiKey, model);
|
|
2025
2434
|
},
|
|
2026
|
-
off:
|
|
2027
|
-
status:
|
|
2435
|
+
off: disablePrime,
|
|
2436
|
+
status: result6
|
|
2028
2437
|
};
|
|
2029
2438
|
|
|
2030
2439
|
// src/harnesses/index.ts
|
|
2031
|
-
var HARNESSES = [
|
|
2440
|
+
var HARNESSES = [
|
|
2441
|
+
bloom,
|
|
2442
|
+
dsh,
|
|
2443
|
+
opencode,
|
|
2444
|
+
openclaw,
|
|
2445
|
+
pi,
|
|
2446
|
+
prime
|
|
2447
|
+
];
|
|
2032
2448
|
|
|
2033
2449
|
// src/commands/harness.ts
|
|
2034
2450
|
var context = () => ({ home: homedir2(), env: process.env });
|
|
@@ -2039,22 +2455,22 @@ var OFF_MESSAGES = {
|
|
|
2039
2455
|
};
|
|
2040
2456
|
var runOn = async (harness, options) => {
|
|
2041
2457
|
try {
|
|
2042
|
-
const
|
|
2043
|
-
const model =
|
|
2458
|
+
const result7 = await harness.on(context(), options);
|
|
2459
|
+
const model = result7.model ? ` (model: ${result7.model})` : "";
|
|
2044
2460
|
printSuccess(`${harness.label} now uses Pollinations${model}.`);
|
|
2045
2461
|
printInfo(harness.restartHint);
|
|
2046
|
-
printResult(
|
|
2462
|
+
printResult(result7);
|
|
2047
2463
|
} catch (error) {
|
|
2048
2464
|
fail(`Failed to connect ${harness.label}`, error);
|
|
2049
2465
|
}
|
|
2050
2466
|
};
|
|
2051
2467
|
var runOff = async (harness) => {
|
|
2052
2468
|
try {
|
|
2053
|
-
const
|
|
2054
|
-
const outcome =
|
|
2469
|
+
const result7 = await harness.off(context());
|
|
2470
|
+
const outcome = result7.outcome ?? "unchanged";
|
|
2055
2471
|
printSuccess(`${harness.label}: ${OFF_MESSAGES[outcome]}`);
|
|
2056
2472
|
if (outcome !== "unchanged") printInfo(harness.restartHint);
|
|
2057
|
-
printResult(
|
|
2473
|
+
printResult(result7);
|
|
2058
2474
|
} catch (error) {
|
|
2059
2475
|
fail(`Failed to disconnect ${harness.label}`, error);
|
|
2060
2476
|
}
|
|
@@ -2472,13 +2888,35 @@ function readPriceOptions(opts) {
|
|
|
2472
2888
|
}
|
|
2473
2889
|
return prices;
|
|
2474
2890
|
}
|
|
2891
|
+
function commaSeparatedList(value) {
|
|
2892
|
+
return String(value).split(",").map((item) => item.trim()).filter(Boolean);
|
|
2893
|
+
}
|
|
2894
|
+
function endpointTarget(opts, required) {
|
|
2895
|
+
if (opts.api !== void 0 || opts.url !== void 0 || required && (opts.modality ?? "text") === "text") {
|
|
2896
|
+
if (opts.baseUrl !== void 0) {
|
|
2897
|
+
fail("Text endpoints use --api and --url; omit --base-url");
|
|
2898
|
+
}
|
|
2899
|
+
if (opts.modality !== void 0 && opts.modality !== "text") {
|
|
2900
|
+
fail("--api and --url are only supported for text endpoints");
|
|
2901
|
+
}
|
|
2902
|
+
if (opts.api !== "chat_completions" && opts.api !== "responses") {
|
|
2903
|
+
fail("--api must be 'chat_completions' or 'responses'");
|
|
2904
|
+
}
|
|
2905
|
+
if (!opts.url) fail("--api and --url must be provided together");
|
|
2906
|
+
return { api: opts.api, url: opts.url };
|
|
2907
|
+
}
|
|
2908
|
+
if (required && !opts.baseUrl) fail("--base-url is required for media");
|
|
2909
|
+
return opts.baseUrl !== void 0 ? { baseUrl: opts.baseUrl } : {};
|
|
2910
|
+
}
|
|
2475
2911
|
function modelBody(opts, includeRequired) {
|
|
2476
|
-
const body =
|
|
2912
|
+
const body = {
|
|
2913
|
+
...readPriceOptions(opts),
|
|
2914
|
+
...endpointTarget(opts, includeRequired)
|
|
2915
|
+
};
|
|
2477
2916
|
const fields = [
|
|
2478
2917
|
["name", "name"],
|
|
2479
2918
|
["title", "title"],
|
|
2480
2919
|
["description", "description"],
|
|
2481
|
-
["baseUrl", "baseUrl"],
|
|
2482
2920
|
["upstreamModel", "upstreamModel"],
|
|
2483
2921
|
["bearerToken", "bearerToken"],
|
|
2484
2922
|
["paidOnly", "paidOnly"]
|
|
@@ -2493,9 +2931,9 @@ function modelBody(opts, includeRequired) {
|
|
|
2493
2931
|
body.visibility = opts.visibility;
|
|
2494
2932
|
}
|
|
2495
2933
|
if (includeRequired && opts.modality !== void 0) {
|
|
2496
|
-
if (opts.modality !== "text" && opts.modality !== "image" && opts.modality !== "video" && opts.modality !== "transcription" && opts.modality !== "embedding") {
|
|
2934
|
+
if (opts.modality !== "text" && opts.modality !== "image" && opts.modality !== "video" && opts.modality !== "transcription" && opts.modality !== "speech" && opts.modality !== "embedding") {
|
|
2497
2935
|
fail(
|
|
2498
|
-
"--modality must be 'text', 'image', 'video', 'transcription', or 'embedding'"
|
|
2936
|
+
"--modality must be 'text', 'image', 'video', 'transcription', 'speech', or 'embedding'"
|
|
2499
2937
|
);
|
|
2500
2938
|
}
|
|
2501
2939
|
body.modality = opts.modality;
|
|
@@ -2507,10 +2945,13 @@ function modelBody(opts, includeRequired) {
|
|
|
2507
2945
|
body.imagePricing = opts.imagePricing;
|
|
2508
2946
|
}
|
|
2509
2947
|
if (opts.fallbacks !== void 0) {
|
|
2510
|
-
body.fallbacks =
|
|
2948
|
+
body.fallbacks = commaSeparatedList(opts.fallbacks);
|
|
2511
2949
|
}
|
|
2512
2950
|
if (opts.inputModalities !== void 0) {
|
|
2513
|
-
body.inputModalities =
|
|
2951
|
+
body.inputModalities = commaSeparatedList(opts.inputModalities);
|
|
2952
|
+
}
|
|
2953
|
+
if (opts.requiredSafety !== void 0) {
|
|
2954
|
+
body.requiredSafetyFeatures = String(opts.requiredSafety).trim() === "none" ? [] : commaSeparatedList(opts.requiredSafety);
|
|
2514
2955
|
}
|
|
2515
2956
|
if (includeRequired) {
|
|
2516
2957
|
for (const required of ["name", "title"]) {
|
|
@@ -2520,7 +2961,6 @@ function modelBody(opts, includeRequired) {
|
|
|
2520
2961
|
);
|
|
2521
2962
|
}
|
|
2522
2963
|
}
|
|
2523
|
-
if (!body.baseUrl) fail("--base-url is required");
|
|
2524
2964
|
if (!body.bearerToken) fail("--bearer-token is required");
|
|
2525
2965
|
}
|
|
2526
2966
|
return body;
|
|
@@ -2543,8 +2983,9 @@ function printModels(models2) {
|
|
|
2543
2983
|
video_price: model.type === "proxy" && model.modality === "video" ? `${model.completionVideoPrice}/sec` : "-",
|
|
2544
2984
|
inputs: model.type === "proxy" ? model.inputModalities?.join(", ") || "-" : "-",
|
|
2545
2985
|
visibility: model.type === "proxy" && model.paidOnly ? `${model.visibility} (paid only)` : model.visibility,
|
|
2546
|
-
upstream: model.type === "proxy" && model.modality === "video" ? "-" : model.upstreamModel,
|
|
2547
|
-
|
|
2986
|
+
upstream: model.type === "proxy" && model.modality === "video" ? "-" : model.upstreamModel ?? "-",
|
|
2987
|
+
api: model.type === "prompt_agent" || model.type === "code_agent" ? "responses" : model.api ?? "-",
|
|
2988
|
+
endpoint: model.url ?? model.baseUrl ?? "-",
|
|
2548
2989
|
fallbacks: model.type === "proxy" ? model.fallbacks?.join(", ") || "-" : "-",
|
|
2549
2990
|
description: model.description ?? "-"
|
|
2550
2991
|
})),
|
|
@@ -2559,7 +3000,8 @@ function printModels(models2) {
|
|
|
2559
3000
|
"inputs",
|
|
2560
3001
|
"visibility",
|
|
2561
3002
|
"upstream",
|
|
2562
|
-
"
|
|
3003
|
+
"api",
|
|
3004
|
+
"endpoint",
|
|
2563
3005
|
"fallbacks",
|
|
2564
3006
|
"description"
|
|
2565
3007
|
]
|
|
@@ -2579,8 +3021,11 @@ var list3 = new Command15("list").description("List models owned by your account
|
|
|
2579
3021
|
var create3 = addPriceOptions(
|
|
2580
3022
|
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
3023
|
"--base-url <url>",
|
|
2582
|
-
"
|
|
3024
|
+
"Media API base URL, or exact video endpoint URL"
|
|
2583
3025
|
).option(
|
|
3026
|
+
"--api <api>",
|
|
3027
|
+
"Text upstream API: chat_completions or responses"
|
|
3028
|
+
).option("--url <url>", "Exact text endpoint URL for the selected API").option(
|
|
2584
3029
|
"--upstream-model <model>",
|
|
2585
3030
|
"Upstream model id (not used for video)"
|
|
2586
3031
|
).option("--bearer-token <token>", "Upstream bearer token").option(
|
|
@@ -2595,6 +3040,9 @@ var create3 = addPriceOptions(
|
|
|
2595
3040
|
).option(
|
|
2596
3041
|
"--input-modalities <types>",
|
|
2597
3042
|
"Comma-separated accepted inputs: text,image,audio,video"
|
|
3043
|
+
).option(
|
|
3044
|
+
"--required-safety <features>",
|
|
3045
|
+
"Comma-separated required checks: privacy,secrets,sexual,violence,shield; none clears them"
|
|
2598
3046
|
).option(
|
|
2599
3047
|
"--modality <modality>",
|
|
2600
3048
|
"Model family: text (default), image, video, transcription, or embedding"
|
|
@@ -2622,8 +3070,11 @@ var create3 = addPriceOptions(
|
|
|
2622
3070
|
var update2 = addPriceOptions(
|
|
2623
3071
|
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
3072
|
"--base-url <url>",
|
|
2625
|
-
"
|
|
3073
|
+
"Media API base URL, or exact video endpoint URL"
|
|
2626
3074
|
).option(
|
|
3075
|
+
"--api <api>",
|
|
3076
|
+
"Text upstream API: chat_completions or responses (requires --url)"
|
|
3077
|
+
).option("--url <url>", "Exact text endpoint URL (requires --api)").option(
|
|
2627
3078
|
"--upstream-model <model>",
|
|
2628
3079
|
"Upstream model id (not used for video)"
|
|
2629
3080
|
).option("--bearer-token <token>", "Upstream bearer token").option(
|
|
@@ -2638,6 +3089,9 @@ var update2 = addPriceOptions(
|
|
|
2638
3089
|
).option(
|
|
2639
3090
|
"--input-modalities <types>",
|
|
2640
3091
|
"Comma-separated accepted inputs: text,image,audio,video"
|
|
3092
|
+
).option(
|
|
3093
|
+
"--required-safety <features>",
|
|
3094
|
+
"Comma-separated required checks: privacy,secrets,sexual,violence,shield; none clears them"
|
|
2641
3095
|
).option(
|
|
2642
3096
|
"--image-pricing <mode>",
|
|
2643
3097
|
"Image billing: request (per image) or tokens"
|
|
@@ -2703,20 +3157,21 @@ var models = new Command15("models").description("List upstream models from an e
|
|
|
2703
3157
|
fail("Failed to fetch upstream models", err);
|
|
2704
3158
|
}
|
|
2705
3159
|
});
|
|
2706
|
-
var test = new Command15("test").description("Test an endpoint/model before registering it").
|
|
3160
|
+
var test = new Command15("test").description("Test an endpoint/model before registering it").option(
|
|
2707
3161
|
"--base-url <url>",
|
|
2708
|
-
"
|
|
2709
|
-
).requiredOption("--bearer-token <token>", "Upstream bearer token").option("--model <model>", "Upstream model id (not used for video)").option(
|
|
3162
|
+
"Media API base URL, or exact video endpoint URL"
|
|
3163
|
+
).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
3164
|
"--modality <modality>",
|
|
2711
3165
|
"Model family: text (default), image, video, transcription, or embedding"
|
|
2712
3166
|
).action(async (opts) => {
|
|
2713
3167
|
const key = requireKey();
|
|
2714
|
-
if (opts.modality !== void 0 && opts.modality !== "text" && opts.modality !== "image" && opts.modality !== "video" && opts.modality !== "transcription" && opts.modality !== "embedding") {
|
|
3168
|
+
if (opts.modality !== void 0 && opts.modality !== "text" && opts.modality !== "image" && opts.modality !== "video" && opts.modality !== "transcription" && opts.modality !== "speech" && opts.modality !== "embedding") {
|
|
2715
3169
|
fail(
|
|
2716
|
-
"--modality must be 'text', 'image', 'video', 'transcription', or 'embedding'"
|
|
3170
|
+
"--modality must be 'text', 'image', 'video', 'transcription', 'speech', or 'embedding'"
|
|
2717
3171
|
);
|
|
2718
3172
|
}
|
|
2719
3173
|
const modality = opts.modality ?? "text";
|
|
3174
|
+
const target = endpointTarget(opts, true);
|
|
2720
3175
|
if (modality !== "video" && !opts.model) {
|
|
2721
3176
|
fail("--model is required unless --modality is video");
|
|
2722
3177
|
}
|
|
@@ -2727,7 +3182,7 @@ var test = new Command15("test").description("Test an endpoint/model before regi
|
|
|
2727
3182
|
apiKey: key,
|
|
2728
3183
|
method: "POST",
|
|
2729
3184
|
body: {
|
|
2730
|
-
|
|
3185
|
+
...target,
|
|
2731
3186
|
bearerToken: opts.bearerToken,
|
|
2732
3187
|
...opts.model && { model: opts.model },
|
|
2733
3188
|
modality
|