cheapgen 0.1.2 → 0.2.0
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 +126 -194
- package/data/models.json +393 -26
- package/data/prices.json +410 -42
- package/package.json +3 -3
- package/skills/cheapgen/SKILL.md +37 -5
- package/src/catalog.js +28 -0
- package/src/cli/commands/config.js +9 -6
- package/src/cli/commands/index.js +17 -3
- package/src/cli/commands/info.js +11 -3
- package/src/cli/commands/quote.js +18 -5
- package/src/cli/commands/run.js +44 -8
- package/src/cli/commands/shared.js +2 -1
- package/src/cli/main.js +8 -4
- package/src/config.js +32 -9
- package/src/http.js +1 -1
- package/src/mcp/tools.js +42 -4
- package/src/media.js +231 -0
- package/src/pricing/check.js +14 -8
- package/src/pricing/formulas.js +26 -0
- package/src/pricing/index.js +5 -2
- package/src/providers/common.js +47 -6
- package/src/providers/errors.js +6 -2
- package/src/providers/fal.js +28 -12
- package/src/providers/higgsfield.js +250 -0
- package/src/providers/index.js +55 -5
- package/src/providers/kie.js +48 -14
- package/src/providers/replicate.js +15 -10
- package/src/providers/wavespeed.js +21 -14
- package/src/request.js +276 -23
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cheapgen",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Send each AI video or image generation request to the cheapest connected provider (Kie, Replicate, WaveSpeed, fal).",
|
|
5
|
-
"keywords": ["ai", "video", "image", "generation", "cli", "seedance", "seedream", "kie", "replicate", "wavespeed", "fal", "claude-code", "mcp", "mcp-server",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Send each AI video or image generation request to the cheapest connected provider (Kie, Replicate, WaveSpeed, fal, Higgsfield).",
|
|
5
|
+
"keywords": ["ai", "video", "image", "generation", "cli", "seedance", "seedream", "kie", "replicate", "wavespeed", "fal", "higgsfield", "claude-code", "mcp", "mcp-server",
|
|
6
6
|
"agent-skills", "codex", "github-copilot", "cursor"],
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "jzr-supove (https://github.com/jzr-supove)",
|
package/skills/cheapgen/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: cheapgen
|
|
3
|
-
description: Generate AI videos (Seedance 2.0 / 2.5) and images (Seedream 5, Nano Banana, FLUX 2 Pro) through the cheapest provider the user has a key for (Kie, Replicate, WaveSpeed, fal), using the cheapgen CLI. Use when the user asks to make, generate or price a video or image with one of these models, or asks what a generation would cost.
|
|
3
|
+
description: Generate AI videos (Seedance 2.0 / 2.5) and images (Seedream 5, Nano Banana, FLUX 2 Pro) through the cheapest provider the user has a key for (Kie, Replicate, WaveSpeed, fal, Higgsfield), using the cheapgen CLI. Use when the user asks to make, generate or price a video or image with one of these models, or asks what a generation would cost.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# cheapgen
|
|
@@ -27,9 +27,10 @@ If the `cheapgen` command isn't found (for example when it came with a plugin),
|
|
|
27
27
|
another provider. Tell the user to check that provider's dashboard and let them decide.
|
|
28
28
|
5. **Keys are the user's.** Never ask for a key in the chat, and never put one in a command.
|
|
29
29
|
If no provider is connected (exit 3, `no_keys`), tell the user to set `KIE_API_KEY`,
|
|
30
|
-
`REPLICATE_API_TOKEN`, `WAVESPEED_API_KEY` or `
|
|
30
|
+
`REPLICATE_API_TOKEN`, `WAVESPEED_API_KEY`, `FAL_KEY` or `HIGGSFIELD_API_KEY`, or to run
|
|
31
31
|
`cheapgen config set-key <provider>` themselves in a terminal (it asks for
|
|
32
|
-
the key and hides it).
|
|
32
|
+
the key and hides it). A Higgsfield key has the form `KEY_ID:KEY_SECRET` and is for the
|
|
33
|
+
Higgsfield API, which has its own balance; a higgsfield.ai subscription doesn't pay for it.
|
|
33
34
|
6. **Don't change the user's config** (`cheapgen config set ...`) unless they ask.
|
|
34
35
|
|
|
35
36
|
## Models
|
|
@@ -42,12 +43,43 @@ Video: `seedance-2.0-mini` (cheapest), `seedance-2.0-fast`, `seedance-2.0`,
|
|
|
42
43
|
## Parameters
|
|
43
44
|
|
|
44
45
|
- `--prompt TEXT`: what to generate. Quote it for the shell; prefer single quotes.
|
|
45
|
-
- `--image FILE|URL`: first frame, which makes it image-to-video
|
|
46
|
+
- `--image FILE|URL`: on a video model, the first frame, which makes it image-to-video (one
|
|
47
|
+
only). On an image model, an image to edit; repeat it to combine several, in the order given.
|
|
48
|
+
PNG, JPEG or WebP, up to 30 MB each. Local files are uploaded to the provider that runs the job,
|
|
49
|
+
so tell the user before sending a file they haven't asked you to send.
|
|
50
|
+
- `--last-image FILE|URL`: video only, with `--image`: the last frame. The video runs from the
|
|
51
|
+
first frame to the last.
|
|
52
|
+
- `--ref-image FILE|URL` and `--ref-audio FILE|URL`: video only, each repeatable: reference
|
|
53
|
+
images (a character, product or style) and reference audio (a voice or music), which makes it
|
|
54
|
+
reference-to-video. They can't be combined with `--image` or `--last-image`.
|
|
55
|
+
- Name them in the prompt by position: `@image1` is the first `--ref-image`, `@audio1` the
|
|
56
|
+
first `--ref-audio`. cheapgen rewrites the names for the provider that gets the job.
|
|
57
|
+
- Limits: 9 images and 3 audio files on the `seedance-2.0` models, 30 and 10 on
|
|
58
|
+
`seedance-2.5`, 10 and 5 on `seedance-2.5-flash` (`cheapgen models --json` has them under
|
|
59
|
+
`references`). Audio is WAV or MP3, at least 2 seconds, and at most 15 seconds in total on
|
|
60
|
+
the 2.0 models or 30 on the 2.5 models. The 2.0 models need at least one image with audio.
|
|
61
|
+
- Frames and reference images are PNG, JPEG or WebP, up to 30 MB, 300 to 6000 pixels a side.
|
|
62
|
+
- The model rejects reference images that show a real person's face. Tell the user before
|
|
63
|
+
they pay for a run that is likely to be rejected.
|
|
64
|
+
- A last frame or references don't change the price. If a provider's price for references is
|
|
65
|
+
unknown (`usd: null`), rule 2 applies.
|
|
66
|
+
- The quote lists providers that can't take the inputs under `unavailable`, with the reason
|
|
67
|
+
(for example, reference audio with no image).
|
|
46
68
|
- Video: `--res 480p|720p|1080p|4k` (default 720p; 4k only on `seedance-2.0` and `seedance-2.5`,
|
|
47
69
|
as a 10-bit H.265/HEVC file that some players can't open), `--duration SECONDS` (default 5),
|
|
48
70
|
`--aspect 16:9|9:16|1:1|4:3|3:4|21:9` (default 16:9), `--audio` / `--no-audio` (default on).
|
|
71
|
+
- 1080p and 4k on `seedance-2.0-mini`, `seedance-2.0-fast` and `seedance-2.5-flash` exist only as
|
|
72
|
+
WaveSpeed's upscaled 720p, and only when the user has turned on the `allowVariants` setting.
|
|
73
|
+
Without it they are a usage error that says so. Don't turn the setting on yourself (rule 6):
|
|
74
|
+
tell the user what it means and let them decide. When it is on, the quote has
|
|
75
|
+
`"variant": "wavespeed-upscaled"` and a warning; pass that on to the user.
|
|
49
76
|
- Image: `--size` (default 1K, or the model's smallest; `cheapgen models` lists each model's
|
|
50
|
-
sizes, such as 1.5K or 3K), `--aspect`.
|
|
77
|
+
sizes, such as 1.5K or 3K), `--aspect`. With `--image` the result follows the first input's
|
|
78
|
+
shape (`--aspect auto`, the default when editing); set a ratio to change it.
|
|
79
|
+
- Editing: input images can add to the price and providers differ in how many they take. The
|
|
80
|
+
quote already includes this. In `--json` it lists providers that can't take the request under
|
|
81
|
+
`unavailable` (`provider`, `reason`); if a reason says the provider needs `--aspect`, adding
|
|
82
|
+
one brings it back.
|
|
51
83
|
- Don't use `--duration auto`: the cost is only known afterwards. If the user insists, it needs
|
|
52
84
|
`--allow-auto-duration`, and the quote shows the maximum cost.
|
|
53
85
|
|
package/src/catalog.js
CHANGED
|
@@ -15,6 +15,34 @@ function readJson(file) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* A provider's entry for a model, as the request needs it: for an image edit the provider's edit
|
|
20
|
+
* block (endpoint, image field, limits) is attached as `edit`. Null when the provider doesn't
|
|
21
|
+
* list the model.
|
|
22
|
+
*/
|
|
23
|
+
export function entryFor(catalog, providerId, request) {
|
|
24
|
+
const model = catalog.models[request.model];
|
|
25
|
+
const entry = model?.providers?.[providerId];
|
|
26
|
+
if (!entry) return null;
|
|
27
|
+
if (request.mode !== 'image-edit') return entry;
|
|
28
|
+
const edit = model.edit?.providers?.[providerId];
|
|
29
|
+
return edit ? { ...entry, edit } : entry;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The variant that sells `resolution` for a model which doesn't list it itself: something one
|
|
34
|
+
* provider offers under the model's name that may differ in quality (an upscaled resolution,
|
|
35
|
+
* for example). Null when the model lists the resolution, or no variant has it.
|
|
36
|
+
* @returns {{ id: string, provider: string, resolutions: string[], label: string, note: string } | null}
|
|
37
|
+
*/
|
|
38
|
+
export function variantFor(model, resolution) {
|
|
39
|
+
if (!resolution || model?.resolutions?.includes(resolution)) return null;
|
|
40
|
+
for (const [id, v] of Object.entries(model?.variants ?? {})) {
|
|
41
|
+
if (v.resolutions?.includes(resolution)) return { id, ...v };
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
18
46
|
/**
|
|
19
47
|
* @param {string} [dataDir]
|
|
20
48
|
* @returns {{ models: object, prices: { schemaVersion: number, entries: object[] }, frameSizes: object }}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// `cheapgen config list | show | path | set <key> <value> | set-key <provider> | get-key <provider>`.
|
|
2
2
|
import { EXIT, usageError } from '../../errors.js';
|
|
3
|
-
import { PROVIDER_IDS,
|
|
3
|
+
import { PROVIDER_IDS, storeKey, storeSetting, envNameOf, keyParts } from '../../config.js';
|
|
4
4
|
import { ADAPTERS } from '../../providers/index.js';
|
|
5
5
|
import { notConnectedError } from '../../router.js';
|
|
6
6
|
import { table } from '../output.js';
|
|
@@ -13,7 +13,7 @@ const mask = (key) => (key.length < MIN_LENGTH_TO_SHOW_END ? '****' : `****${key
|
|
|
13
13
|
|
|
14
14
|
function keyInfo(app, id) {
|
|
15
15
|
const key = app.keys[id];
|
|
16
|
-
return { provider: id, envVar:
|
|
16
|
+
return { provider: id, envVar: envNameOf(app, id), set: Boolean(key), source: app.keySources[id], masked: key ? mask(key) : null };
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
const sourceText = (info) => (info.source === 'env' ? info.envVar : 'config file');
|
|
@@ -59,7 +59,7 @@ function getKey(app, rest) {
|
|
|
59
59
|
function show(app, rest) {
|
|
60
60
|
if (rest.length) throw usageError(`too many arguments. Usage: ${USAGE}`);
|
|
61
61
|
const keys = Object.fromEntries(PROVIDER_IDS.map((id) => [id,
|
|
62
|
-
app.keySources[id] === 'env' ? `set (${
|
|
62
|
+
app.keySources[id] === 'env' ? `set (${envNameOf(app, id)})` : app.keySources[id] === 'file' ? 'set (config file)' : 'not set']));
|
|
63
63
|
const obj = { files: app.configFiles, settings: app.config, keys };
|
|
64
64
|
app.out.result(obj, JSON.stringify(obj, null, 2));
|
|
65
65
|
return EXIT.OK;
|
|
@@ -90,8 +90,9 @@ async function setKey(app, rest) {
|
|
|
90
90
|
}
|
|
91
91
|
const id = rest[0];
|
|
92
92
|
checkProvider(id);
|
|
93
|
+
const format = ADAPTERS[id].keyFormat;
|
|
93
94
|
const answer = app.io.promptSecret
|
|
94
|
-
? await app.io.promptSecret(`${ADAPTERS[id].displayName} API key (hidden): `)
|
|
95
|
+
? await app.io.promptSecret(format?.prompt ?? `${ADAPTERS[id].displayName} API key (hidden): `)
|
|
95
96
|
: await app.io.readStdin();
|
|
96
97
|
if (answer === null) throw usageError('cancelled, nothing was stored');
|
|
97
98
|
const input = String(answer ?? '');
|
|
@@ -100,10 +101,12 @@ async function setKey(app, rest) {
|
|
|
100
101
|
throw usageError(app.io.promptSecret ? 'no key entered, nothing was stored'
|
|
101
102
|
: `no key on standard input. Run \`cheapgen config set-key ${id}\` in a terminal, or pipe the key in.`);
|
|
102
103
|
}
|
|
103
|
-
app.secrets.push(key);
|
|
104
|
+
app.secrets.push(key, ...keyParts(id, key));
|
|
105
|
+
// The message never repeats the input: a mistyped key is still mostly a key.
|
|
106
|
+
if (format && !format.pattern.test(key)) throw usageError(format.hint);
|
|
104
107
|
const { file, warnings } = storeKey(app.io, id, key);
|
|
105
108
|
for (const w of warnings) app.out.warn(w);
|
|
106
|
-
if (app.keySources[id] === 'env') app.out.warn(`${
|
|
109
|
+
if (app.keySources[id] === 'env') app.out.warn(`${envNameOf(app, id)} is set in your environment and takes precedence over the stored key`);
|
|
107
110
|
app.out.result({ stored: true, provider: id, file }, `Stored the ${id} key in ${file}.`);
|
|
108
111
|
return EXIT.OK;
|
|
109
112
|
}
|
|
@@ -29,10 +29,23 @@ Usage:
|
|
|
29
29
|
|
|
30
30
|
Parameters:
|
|
31
31
|
--prompt TEXT what to generate
|
|
32
|
-
--image FILE|URL first frame (image-to-video)
|
|
32
|
+
--image FILE|URL video models: the first frame (image-to-video)
|
|
33
|
+
image models: an image to edit; repeat it to combine several
|
|
34
|
+
(PNG, JPEG or WebP, up to 30 MB each; local files are uploaded)
|
|
35
|
+
--last-image FILE|URL video: the last frame, together with --image
|
|
36
|
+
--ref-image FILE|URL video: a reference image (a character, product or style); repeat it
|
|
37
|
+
--ref-audio FILE|URL video: reference audio (WAV or MP3, 2 to 15 seconds; 30 on the 2.5 models)
|
|
38
|
+
References can't be combined with --image. Name them in the prompt as
|
|
39
|
+
@image1, @audio1. \`cheapgen models --json\` shows how many a model takes.
|
|
40
|
+
Local files are uploaded to the provider that runs the job. The model
|
|
41
|
+
rejects reference images that show a real person's face.
|
|
33
42
|
--res 480p|720p|1080p|4k (default 720p) --size 1K|2K|4K|... (images; default 1K, or the model's smallest)
|
|
34
43
|
--duration SECONDS (default 5) --aspect 16:9|9:16|1:1|... (default 16:9)
|
|
44
|
+
--aspect auto: follow the first input image (the
|
|
45
|
+
default when editing an image)
|
|
35
46
|
--audio | --no-audio (default on) --allow-auto-duration (accept the maximum cost)
|
|
47
|
+
1080p and 4k on seedance-2.0-mini, -fast and seedance-2.5-flash are WaveSpeed's upscaled 720p,
|
|
48
|
+
off by default. Allow them with: cheapgen config set allowVariants true
|
|
36
49
|
|
|
37
50
|
Run options:
|
|
38
51
|
--provider ID use this provider only --exclude ID skip a provider for this run
|
|
@@ -42,6 +55,7 @@ Run options:
|
|
|
42
55
|
--download DIR where to save results (default ./cheapgen-out) --no-download
|
|
43
56
|
--json machine-readable output
|
|
44
57
|
|
|
45
|
-
Keys: set KIE_API_KEY, REPLICATE_API_TOKEN, WAVESPEED_API_KEY or
|
|
46
|
-
\`cheapgen config set-key <provider>\`, which asks for the key and hides it.
|
|
58
|
+
Keys: set KIE_API_KEY, REPLICATE_API_TOKEN, WAVESPEED_API_KEY, FAL_KEY or HIGGSFIELD_API_KEY, or
|
|
59
|
+
store one with \`cheapgen config set-key <provider>\`, which asks for the key and hides it.
|
|
60
|
+
A Higgsfield key is KEY_ID:KEY_SECRET.
|
|
47
61
|
`;
|
package/src/cli/commands/info.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Read-only commands: `providers`, `models`, `spend`, `prices`.
|
|
2
2
|
import { EXIT, usageError } from '../../errors.js';
|
|
3
|
-
import { PROVIDER_IDS,
|
|
3
|
+
import { PROVIDER_IDS, envNameOf } from '../../config.js';
|
|
4
4
|
import { ADAPTERS } from '../../providers/index.js';
|
|
5
5
|
import { connectedIds, noKeysError, isEnabled, balanceOf } from '../../router.js';
|
|
6
6
|
import { readSpend, joinJobs } from '../../spend-log.js';
|
|
@@ -16,7 +16,7 @@ export async function providers(app) {
|
|
|
16
16
|
for (const id of PROVIDER_IDS) {
|
|
17
17
|
const connected = Boolean(app.keys[id]);
|
|
18
18
|
const enabled = isEnabled(app, id);
|
|
19
|
-
list.push({ id, name: ADAPTERS[id].displayName, envVar:
|
|
19
|
+
list.push({ id, name: ADAPTERS[id].displayName, envVar: envNameOf(app, id), connected, keySource: app.keySources[id],
|
|
20
20
|
enabled, balance: connected && enabled ? await balanceOf(app, id) : null });
|
|
21
21
|
}
|
|
22
22
|
const rows = list.map((p) => [p.id,
|
|
@@ -36,10 +36,18 @@ export async function models(app) {
|
|
|
36
36
|
id, kind: m.kind, modes: m.modes,
|
|
37
37
|
...(m.kind === 'video' ? { resolutions: m.resolutions, durations: m.durations } : { sizes: m.sizes ?? [] }),
|
|
38
38
|
aspectRatios: m.aspectRatios,
|
|
39
|
+
...(m.references ? { references: { maxImages: m.references.maxImages, maxAudio: m.references.maxAudio,
|
|
40
|
+
audioAlone: m.references.audioAlone } } : {}),
|
|
41
|
+
...(m.variants ? { variants: Object.entries(m.variants)
|
|
42
|
+
.map(([vid, v]) => ({ id: vid, provider: v.provider, resolutions: v.resolutions, note: v.note })) } : {}),
|
|
39
43
|
providers: Object.keys(m.providers ?? {}).filter((p) => PROVIDER_IDS.includes(p))
|
|
40
44
|
.map((p) => ({ id: p, connected: Boolean(app.keys[p]) })),
|
|
41
45
|
}));
|
|
42
|
-
|
|
46
|
+
// With variants allowed, their resolutions are shown next to the model's own, with the first
|
|
47
|
+
// word of the variant's label ("upscaled") saying what kind they are.
|
|
48
|
+
const extra = (m) => (app.config.allowVariants ? Object.values(app.catalog.models[m.id].variants ?? {}) : [])
|
|
49
|
+
.map((v) => ` (+${v.resolutions.join('/')} ${v.label.split(' ')[0]})`).join('');
|
|
50
|
+
const rows = list.map((m) => [m.id, m.kind, (m.resolutions ?? m.sizes).join('/') + extra(m),
|
|
43
51
|
m.providers.map((p) => (p.connected ? `${p.id}*` : p.id)).join(', ')]);
|
|
44
52
|
const text = list.length ? `${table(rows)}\n(* = connected)` : `no model matches "${app.flags.search}"`;
|
|
45
53
|
app.out.result({ models: list }, text);
|
|
@@ -5,7 +5,7 @@ import { PROVIDER_IDS } from '../../config.js';
|
|
|
5
5
|
import { supports } from '../../providers/index.js';
|
|
6
6
|
import { rankCandidates, priceOf, compareQuotes, isEnabled } from '../../router.js';
|
|
7
7
|
import { staleWarnings } from '../../pricing/index.js';
|
|
8
|
-
import { describeRequest, logParams } from '../../request.js';
|
|
8
|
+
import { describeRequest, logParams, variantWarning } from '../../request.js';
|
|
9
9
|
import { usd, table } from '../output.js';
|
|
10
10
|
import { requestFrom, excludeList, providerFlag } from './shared.js';
|
|
11
11
|
|
|
@@ -25,16 +25,27 @@ export async function quote(app) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const quotes = [];
|
|
28
|
+
// Providers that carry the model but can't take this request, with the reason.
|
|
29
|
+
const unavailable = [];
|
|
28
30
|
for (const id of PROVIDER_IDS) {
|
|
29
|
-
if (!supports(app.catalog, id, request).ok) continue;
|
|
30
31
|
const connected = Boolean(app.keys[id]);
|
|
32
|
+
const s = supports(app.catalog, id, request);
|
|
33
|
+
if (!s.ok) {
|
|
34
|
+
const listed = Boolean(app.catalog.models[request.model].providers?.[id]);
|
|
35
|
+
if (listed && (connected || app.config.showUnconnected)) {
|
|
36
|
+
unavailable.push({ provider: id, reason: s.reason.replace(`${id} `, '') });
|
|
37
|
+
}
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
31
40
|
if (!connected && !app.config.showUnconnected) continue;
|
|
32
41
|
const p = await priceOf(app, id, request);
|
|
33
42
|
quotes.push({ provider: id, usd: p.usd, source: p.source, verifiedOn: p.verifiedOn ?? null, ageDays: p.ageDays ?? null,
|
|
34
|
-
connected, enabled: isEnabled(app, id), chosen: id === chosen, ...(p.reason ? { reason: p.reason } : {})
|
|
43
|
+
connected, enabled: isEnabled(app, id), chosen: id === chosen, ...(p.reason ? { reason: p.reason } : {}),
|
|
44
|
+
...(request.variant ? { variant: request.variant.id } : {}) });
|
|
35
45
|
}
|
|
36
46
|
quotes.sort((a, b) => compareQuotes(a, b, { prefer: app.config.prefer }));
|
|
37
47
|
const warnings = staleWarnings(quotes);
|
|
48
|
+
if (request.variant) warnings.push(variantWarning(request));
|
|
38
49
|
if (request.autoDuration) warnings.push(`auto duration: prices assume the maximum of ${request.maxDuration} seconds`);
|
|
39
50
|
for (const w of warnings) app.out.warn(w);
|
|
40
51
|
|
|
@@ -42,13 +53,15 @@ export async function quote(app) {
|
|
|
42
53
|
` ${q.provider}`,
|
|
43
54
|
usd(q.usd),
|
|
44
55
|
q.source ? `${q.source} ${q.verifiedOn}` : '',
|
|
45
|
-
[q.chosen ? '← run would use this' : '', !q.connected ? '(not connected)' : '', q.connected && !q.enabled ? '(disabled)' : ''
|
|
56
|
+
[q.chosen ? '← run would use this' : '', !q.connected ? '(not connected)' : '', q.connected && !q.enabled ? '(disabled)' : '',
|
|
57
|
+
q.variant ? `(${request.variant.label})` : '']
|
|
46
58
|
.filter(Boolean).join(' '),
|
|
47
59
|
]);
|
|
48
60
|
const text = [describeRequest(request), quotes.length ? table(rows) : ' no provider offers this request',
|
|
61
|
+
...unavailable.map((u) => ` ${u.provider} can't take this request: it ${u.reason}`),
|
|
49
62
|
...(note && !chosen ? [` ${note}`] : [])].join('\n');
|
|
50
63
|
|
|
51
64
|
app.out.result({ model: request.model, mode: request.mode, params: logParams(request), quotes, chosen, warnings,
|
|
52
|
-
...(note ? { note } : {}) }, text);
|
|
65
|
+
...(unavailable.length ? { unavailable } : {}), ...(note ? { note } : {}) }, text);
|
|
53
66
|
return EXIT.OK;
|
|
54
67
|
}
|
package/src/cli/commands/run.js
CHANGED
|
@@ -7,7 +7,8 @@ import { pendingUpload } from '../../providers/common.js';
|
|
|
7
7
|
import { rankCandidates, ctxFor } from '../../router.js';
|
|
8
8
|
import { TIMEOUT_MS } from '../../jobs.js';
|
|
9
9
|
import { appendSpend } from '../../spend-log.js';
|
|
10
|
-
import { describeRequest, logParams } from '../../request.js';
|
|
10
|
+
import { describeRequest, logParams, variantWarning } from '../../request.js';
|
|
11
|
+
import { IMAGE_MIME, AUDIO_MIME } from '../../media.js';
|
|
11
12
|
import { usd } from '../output.js';
|
|
12
13
|
import { requestFrom, excludeList, providerFlag, maxCostFlag, timeoutFlag } from './shared.js';
|
|
13
14
|
import { finishJob, describeFinished, downloadDirFrom } from './jobs.js';
|
|
@@ -26,7 +27,9 @@ export async function run(app) {
|
|
|
26
27
|
const timeoutMs = timeoutFlag(app) ?? TIMEOUT_MS[request.kind];
|
|
27
28
|
|
|
28
29
|
const { ranked, pinned } = await rankCandidates(app, request, { provider, exclude });
|
|
29
|
-
|
|
30
|
+
// The codec note describes ByteDance's own 4k; a provider's upscaled variant may differ.
|
|
31
|
+
if (request.kind === 'video' && request.resolution === '4k' && !request.variant) out.notice(`Note: ${HEVC_NOTE}`);
|
|
32
|
+
if (request.variant) out.warn(variantWarning(request));
|
|
30
33
|
const first = ranked[0];
|
|
31
34
|
const overLimit = first.usd !== null && first.usd > limit + EPS;
|
|
32
35
|
|
|
@@ -57,9 +60,7 @@ export async function run(app) {
|
|
|
57
60
|
|
|
58
61
|
let accepted;
|
|
59
62
|
try {
|
|
60
|
-
|
|
61
|
-
: request.imageIsLocal ? await adapter.upload(request.image, ctx) : request.image;
|
|
62
|
-
accepted = await adapter.submit(request, ctx, { entry: c.entry, imageUrl });
|
|
63
|
+
accepted = await adapter.submit(request, ctx, { entry: c.entry, ...(await sendInputs(request, adapter, ctx)) });
|
|
63
64
|
} catch (err) {
|
|
64
65
|
if (err instanceof SubmitRejected) {
|
|
65
66
|
lastRejection = { provider: c.provider, message: err.message };
|
|
@@ -72,6 +73,9 @@ export async function run(app) {
|
|
|
72
73
|
continue;
|
|
73
74
|
}
|
|
74
75
|
if (err instanceof SubmitUnknown) {
|
|
76
|
+
// No job id, but a record of the attempt (and anything that identifies it) helps find the job later.
|
|
77
|
+
appendSpend(app, { event: 'submit_unknown', provider: c.provider, model: request.model, mode: request.mode,
|
|
78
|
+
params: logParams(request), estimateUsd: c.usd, ...(err.details ?? {}) });
|
|
75
79
|
throw new CliError(EXIT.UNKNOWN_OUTCOME, 'unknown_outcome', `the outcome of the submit to ${c.provider} is unknown `
|
|
76
80
|
+ `(${err.message}). A job may have been created and billed, so no other provider was tried. Check your `
|
|
77
81
|
+ `${adapter.displayName} dashboard before running again.`, { provider: c.provider });
|
|
@@ -83,7 +87,7 @@ export async function run(app) {
|
|
|
83
87
|
appendSpend(app, { event: 'submitted', job, provider: c.provider, model: request.model, mode: request.mode,
|
|
84
88
|
params: logParams(request), estimateUsd: c.usd, priceSource: c.source, ...(accepted.meta ? { meta: accepted.meta } : {}) });
|
|
85
89
|
const base = { job, provider: c.provider, model: request.model, estimateUsd: c.usd, priceSource: c.source,
|
|
86
|
-
verifiedOn: c.verifiedOn };
|
|
90
|
+
verifiedOn: c.verifiedOn, ...(request.variant ? { variant: request.variant.id } : {}) };
|
|
87
91
|
|
|
88
92
|
if (!flags.wait) {
|
|
89
93
|
out.result({ ...base, state: 'submitted' }, `Submitted to ${c.provider}: ${job}\n`
|
|
@@ -121,10 +125,42 @@ export async function run(app) {
|
|
|
121
125
|
+ `${lastRejection.provider}, said: ${lastRejection.message}`, { provider: lastRejection.provider });
|
|
122
126
|
}
|
|
123
127
|
|
|
128
|
+
/**
|
|
129
|
+
* The addresses of the request's input files on this provider: local files are uploaded to it,
|
|
130
|
+
* in the order given, and URLs are passed through.
|
|
131
|
+
*/
|
|
132
|
+
async function sendInputs(request, adapter, ctx) {
|
|
133
|
+
// One at a time, so the provider receives the files in the order given. A file whose type was
|
|
134
|
+
// read from its bytes is uploaded as that type, whatever its name says.
|
|
135
|
+
const send = async (files) => {
|
|
136
|
+
const urls = [];
|
|
137
|
+
for (const f of files) urls.push(f.isLocal ? await adapter.upload(f.source, ctx, mimeOf(f)) : f.source);
|
|
138
|
+
return urls;
|
|
139
|
+
};
|
|
140
|
+
if (request.images) return { imageUrls: await send(request.images) };
|
|
141
|
+
if (request.mode === 'reference-to-video') {
|
|
142
|
+
const refImageUrls = await send(request.refImages);
|
|
143
|
+
return { refImageUrls, refAudioUrls: await send(request.refAudio) };
|
|
144
|
+
}
|
|
145
|
+
if (!request.image) return {};
|
|
146
|
+
const imageUrl = request.imageIsLocal ? await adapter.upload(request.image, ctx) : request.image;
|
|
147
|
+
return { imageUrl, ...(request.lastImage ? { lastImageUrl: (await send([request.lastImage]))[0] } : {}) };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** The content type of an input whose type was read from its bytes. */
|
|
151
|
+
const mimeOf = (file) => AUDIO_MIME[file.type] ?? IMAGE_MIME[file.type];
|
|
152
|
+
|
|
153
|
+
/** What a dry run shows for each input: its address, or a placeholder for a local file. */
|
|
154
|
+
const shown = (files) => files.map((f) => (f.isLocal ? pendingUpload(f.source) : f.source));
|
|
155
|
+
|
|
124
156
|
function dryRun(app, request, ranked, { limit, overLimit }) {
|
|
125
157
|
const first = ranked[0];
|
|
126
158
|
const imageUrl = !request.image ? undefined : request.imageIsLocal ? pendingUpload(request.image) : request.image;
|
|
127
|
-
const built = ADAPTERS[first.provider].buildRequest(request, { entry: first.entry, imageUrl
|
|
159
|
+
const built = ADAPTERS[first.provider].buildRequest(request, { entry: first.entry, imageUrl,
|
|
160
|
+
imageUrls: request.images && shown(request.images),
|
|
161
|
+
lastImageUrl: request.lastImage && shown([request.lastImage])[0],
|
|
162
|
+
refImageUrls: request.refImages && shown(request.refImages),
|
|
163
|
+
refAudioUrls: request.refAudio && shown(request.refAudio) });
|
|
128
164
|
const fallbacks = ranked.slice(1).map((c) => ({ provider: c.provider, estimateUsd: c.usd }));
|
|
129
165
|
const text = [
|
|
130
166
|
`Dry run: nothing was sent.`,
|
|
@@ -137,6 +173,6 @@ function dryRun(app, request, ranked, { limit, overLimit }) {
|
|
|
137
173
|
].join('\n');
|
|
138
174
|
app.out.result({ dryRun: true, provider: first.provider, estimateUsd: first.usd, priceSource: first.source,
|
|
139
175
|
verifiedOn: first.verifiedOn, limitUsd: limit, overLimit, needsConfirmation: overLimit || first.usd === null,
|
|
140
|
-
request: built, fallbacks }, text);
|
|
176
|
+
...(request.variant ? { variant: request.variant.id } : {}), request: built, fallbacks }, text);
|
|
141
177
|
return EXIT.OK;
|
|
142
178
|
}
|
|
@@ -10,7 +10,8 @@ export function noExtraArgs(app, max, usage) {
|
|
|
10
10
|
/** The canonical request from `<model>` and the shared flags. */
|
|
11
11
|
export function requestFrom(app, { requirePrompt }) {
|
|
12
12
|
noExtraArgs(app, 1, `cheapgen ${requirePrompt ? 'run' : 'quote'} <model> [options]`);
|
|
13
|
-
return buildCanonicalRequest(app.args[0], app.flags, app.catalog,
|
|
13
|
+
return buildCanonicalRequest(app.args[0], app.flags, app.catalog,
|
|
14
|
+
{ cwd: app.io.cwd, requirePrompt, allowVariants: app.config.allowVariants });
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
/** --exclude, repeatable and comma-separated. */
|
package/src/cli/main.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { parseArgs } from 'node:util';
|
|
4
4
|
import { CliError, EXIT, usageError } from '../errors.js';
|
|
5
5
|
import { loadCatalog, DEFAULT_DATA_DIR } from '../catalog.js';
|
|
6
|
-
import { loadConfig } from '../config.js';
|
|
6
|
+
import { loadConfig, keyParts } from '../config.js';
|
|
7
7
|
import { createPriceCache } from '../pricing/cache.js';
|
|
8
8
|
import { redact } from '../http.js';
|
|
9
9
|
import { createOutput } from './output.js';
|
|
@@ -12,7 +12,10 @@ import { COMMANDS, HELP } from './commands/index.js';
|
|
|
12
12
|
|
|
13
13
|
const OPTIONS = {
|
|
14
14
|
prompt: { type: 'string' },
|
|
15
|
-
image: { type: 'string' },
|
|
15
|
+
image: { type: 'string', multiple: true },
|
|
16
|
+
'last-image': { type: 'string', multiple: true },
|
|
17
|
+
'ref-image': { type: 'string', multiple: true },
|
|
18
|
+
'ref-audio': { type: 'string', multiple: true },
|
|
16
19
|
res: { type: 'string' },
|
|
17
20
|
size: { type: 'string' },
|
|
18
21
|
duration: { type: 'string' },
|
|
@@ -73,12 +76,13 @@ export async function main(argv, io = {}) {
|
|
|
73
76
|
if (!command) throw usageError(`unknown command "${name}". Run \`cheapgen --help\` for the list.`);
|
|
74
77
|
|
|
75
78
|
const loaded = loadConfig(io);
|
|
76
|
-
|
|
79
|
+
for (const [id, key] of Object.entries(loaded.keys)) secrets.push(key, ...keyParts(id, key));
|
|
77
80
|
for (const w of loaded.warnings) out.warn(w);
|
|
78
81
|
|
|
79
82
|
const app = {
|
|
80
83
|
io, out, flags, args, secrets,
|
|
81
|
-
config: loaded.config, keys: loaded.keys, keySources: loaded.keySources,
|
|
84
|
+
config: loaded.config, keys: loaded.keys, keySources: loaded.keySources, keyEnvVars: loaded.keyEnvVars,
|
|
85
|
+
configFiles: loaded.files,
|
|
82
86
|
get catalog() { return (this._catalog ??= loadCatalog(io.dataDir)); },
|
|
83
87
|
priceCache: createPriceCache(io.homedir),
|
|
84
88
|
priceMemo: new Map(),
|
package/src/config.js
CHANGED
|
@@ -5,8 +5,24 @@ import fs from 'node:fs';
|
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { CliError, EXIT, usageError } from './errors.js';
|
|
7
7
|
|
|
8
|
-
export const PROVIDER_IDS = ['kie', 'replicate', 'wavespeed', 'fal'];
|
|
9
|
-
export const ENV_VARS = { kie: 'KIE_API_KEY', replicate: 'REPLICATE_API_TOKEN', wavespeed: 'WAVESPEED_API_KEY', fal: 'FAL_KEY'
|
|
8
|
+
export const PROVIDER_IDS = ['kie', 'replicate', 'wavespeed', 'fal', 'higgsfield'];
|
|
9
|
+
export const ENV_VARS = { kie: 'KIE_API_KEY', replicate: 'REPLICATE_API_TOKEN', wavespeed: 'WAVESPEED_API_KEY', fal: 'FAL_KEY',
|
|
10
|
+
higgsfield: 'HIGGSFIELD_API_KEY' };
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A key split over two variables, used when the provider's own variable is unset. Higgsfield's
|
|
14
|
+
* docs name the key id and secret HF_API_KEY_ID and HF_API_KEY_SECRET; the stored key joins them.
|
|
15
|
+
*/
|
|
16
|
+
export const ENV_PAIRS = { higgsfield: ['HF_API_KEY_ID', 'HF_API_KEY_SECRET'] };
|
|
17
|
+
|
|
18
|
+
/** The variable(s) a key from the environment came from, for messages. */
|
|
19
|
+
export const envNameOf = (app, id) => app.keyEnvVars?.[id] ?? ENV_VARS[id];
|
|
20
|
+
|
|
21
|
+
/** Parts of a key worth redacting on their own (a provider may echo one half), besides the whole key. */
|
|
22
|
+
export function keyParts(id, key) {
|
|
23
|
+
if (!ENV_PAIRS[id] || typeof key !== 'string') return [];
|
|
24
|
+
return key.split(':').filter((part) => part.length >= 8);
|
|
25
|
+
}
|
|
10
26
|
|
|
11
27
|
export const DEFAULTS = Object.freeze({
|
|
12
28
|
providers: Object.fromEntries(PROVIDER_IDS.map((id) => [id, { enabled: true }])),
|
|
@@ -106,7 +122,7 @@ function splitKeys(layer) {
|
|
|
106
122
|
|
|
107
123
|
/**
|
|
108
124
|
* @returns {{ config: object, keys: Record<string, string>, keySources: Record<string, 'env'|'file'|null>,
|
|
109
|
-
* warnings: string[], files: { user: string, project: string } }}
|
|
125
|
+
* keyEnvVars: Record<string, string>, warnings: string[], files: { user: string, project: string } }}
|
|
110
126
|
*/
|
|
111
127
|
export function loadConfig(io) {
|
|
112
128
|
const warnings = [];
|
|
@@ -124,20 +140,27 @@ export function loadConfig(io) {
|
|
|
124
140
|
Object.assign(fileKeys, keys);
|
|
125
141
|
}
|
|
126
142
|
|
|
143
|
+
// An app that starts cheapgen can pass an unset setting as its unfilled placeholder
|
|
144
|
+
// (`${user_config.x}`, `$VAR`). That is not a key, so it must not hide a stored one.
|
|
145
|
+
const envValue = (name) => {
|
|
146
|
+
const v = io.env[name];
|
|
147
|
+
if (typeof v !== 'string' || !v.trim() || /^\$(\{[^}]*\}|[A-Za-z_]\w*)$/.test(v.trim())) return null;
|
|
148
|
+
return v.trim();
|
|
149
|
+
};
|
|
127
150
|
const keys = {};
|
|
128
151
|
const keySources = {};
|
|
152
|
+
const keyEnvVars = {};
|
|
129
153
|
for (const id of PROVIDER_IDS) {
|
|
130
|
-
const fromEnv =
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (typeof fromEnv === 'string' && fromEnv.trim() && !unfilled) { keys[id] = fromEnv.trim(); keySources[id] = 'env'; }
|
|
154
|
+
const fromEnv = envValue(ENV_VARS[id]);
|
|
155
|
+
const pair = ENV_PAIRS[id]?.map(envValue);
|
|
156
|
+
if (fromEnv) { keys[id] = fromEnv; keySources[id] = 'env'; keyEnvVars[id] = ENV_VARS[id]; }
|
|
157
|
+
else if (pair?.every(Boolean)) { keys[id] = pair.join(':'); keySources[id] = 'env'; keyEnvVars[id] = ENV_PAIRS[id].join(' + '); }
|
|
135
158
|
else if (fileKeys[id]) { keys[id] = fileKeys[id]; keySources[id] = 'file'; }
|
|
136
159
|
else keySources[id] = null;
|
|
137
160
|
}
|
|
138
161
|
|
|
139
162
|
// Keys live outside the config object, so printing the config can't include them.
|
|
140
|
-
return { config: deepFreeze(structuredClone(config)), keys: Object.freeze(keys), keySources, warnings, files };
|
|
163
|
+
return { config: deepFreeze(structuredClone(config)), keys: Object.freeze(keys), keySources, keyEnvVars, warnings, files };
|
|
141
164
|
}
|
|
142
165
|
|
|
143
166
|
/**
|
package/src/http.js
CHANGED
|
@@ -8,7 +8,7 @@ const escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
|
8
8
|
|
|
9
9
|
const PATTERNS = [
|
|
10
10
|
[/\bBearer\s+[^\s"',;)]+/gi, 'Bearer [redacted]'],
|
|
11
|
-
[/\bKey\s+[
|
|
11
|
+
[/\bKey\s+[^\s:"',;)]+:[^\s"',;)]+/g, 'Key [redacted]'],
|
|
12
12
|
[/\br8_[A-Za-z0-9]{8,}/g, '[redacted]'],
|
|
13
13
|
];
|
|
14
14
|
|
package/src/mcp/tools.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import crypto from 'node:crypto';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { main } from '../cli/main.js';
|
|
7
|
+
import { loadCatalog } from '../catalog.js';
|
|
7
8
|
import { RpcError } from './errors.js';
|
|
8
9
|
|
|
9
10
|
export const QUOTE_TTL_MS = 10 * 60_000;
|
|
@@ -16,13 +17,24 @@ const READ_ONLY = { readOnlyHint: true, destructiveHint: false, idempotentHint:
|
|
|
16
17
|
const REQUEST_PROPERTIES = {
|
|
17
18
|
model: str('Model id from the `models` tool, e.g. seedance-2.0-mini or seedream-5.5.'),
|
|
18
19
|
prompt: str('What to generate. Needed before the quote can be used with `run`.'),
|
|
19
|
-
image: str('First frame for image-to-video: an https URL or an absolute local file path.'),
|
|
20
|
-
|
|
20
|
+
image: str('Video models only. First frame for image-to-video: an https URL or an absolute local file path.'),
|
|
21
|
+
images: { type: 'array', items: { type: 'string' }, description: 'Image models only. Input images to edit or combine: '
|
|
22
|
+
+ 'https URLs or absolute local file paths (PNG, JPEG or WebP), in order. Local files are uploaded to the chosen provider. '
|
|
23
|
+
+ 'Without an aspect the result follows the first image.' },
|
|
24
|
+
lastImage: str('Video models only. Last frame of the video, used together with `image` (the first frame): an https URL or an '
|
|
25
|
+
+ 'absolute local file path (PNG, JPEG or WebP).'),
|
|
26
|
+
refImages: { type: 'array', items: { type: 'string' }, description: 'Video models only. Reference images the video should '
|
|
27
|
+
+ 'follow (characters, products, style): https URLs or absolute local file paths (PNG, JPEG or WebP), in order. Name them in '
|
|
28
|
+
+ 'the prompt as @image1, @image2. Not together with `image` or `lastImage`. The models tool shows how many a model takes.' },
|
|
29
|
+
refAudio: { type: 'array', items: { type: 'string' }, description: 'Video models only. Reference audio for the video (voice, '
|
|
30
|
+
+ 'music, sound): https URLs or absolute local file paths (WAV or MP3, 2 to 15 seconds, 30 on the 2.5 models), in order. '
|
|
31
|
+
+ 'Name them in the prompt as @audio1. The Seedance 2.0 models also need at least one reference image.' },
|
|
32
|
+
resolution: str('Video resolution: 480p, 720p, 1080p or 4k (only some models; the models tool shows which, and which are a provider\'s upscaled variant that the user must allow first). Default 720p.'),
|
|
21
33
|
size: str('Image size, e.g. 1K, 2K or 4K. Default 1K, or the model\'s smallest.'),
|
|
22
34
|
duration: { type: 'number', description: 'Video length in seconds. Default 5.' },
|
|
23
35
|
aspect: str('Aspect ratio, e.g. 16:9, 9:16 or 1:1. Default 16:9.'),
|
|
24
36
|
audio: { type: 'boolean', description: 'Generate audio with the video (models that support it). Default true.' },
|
|
25
|
-
provider: str('Use only this provider: kie, replicate, wavespeed or
|
|
37
|
+
provider: str('Use only this provider: kie, replicate, wavespeed, fal or higgsfield.'),
|
|
26
38
|
exclude: { type: 'array', items: { type: 'string' }, description: 'Providers to skip.' },
|
|
27
39
|
};
|
|
28
40
|
|
|
@@ -39,7 +51,7 @@ export const TOOL_DEFINITIONS = [
|
|
|
39
51
|
{
|
|
40
52
|
name: 'providers',
|
|
41
53
|
title: 'List providers',
|
|
42
|
-
description: 'Lists the providers (Kie, Replicate, WaveSpeed, fal), whether each has a key, and their balances where the provider reports one.',
|
|
54
|
+
description: 'Lists the providers (Kie, Replicate, WaveSpeed, fal, Higgsfield), whether each has a key, and their balances where the provider reports one.',
|
|
43
55
|
inputSchema: closed({}),
|
|
44
56
|
annotations: { title: 'List providers', ...READ_ONLY },
|
|
45
57
|
},
|
|
@@ -133,6 +145,10 @@ function requestArgs(a) {
|
|
|
133
145
|
const opt = (flag, v) => { if (v !== undefined) args.push(flag, String(v)); };
|
|
134
146
|
opt('--prompt', a.prompt);
|
|
135
147
|
opt('--image', a.image);
|
|
148
|
+
for (const img of a.images ?? []) args.push('--image', img);
|
|
149
|
+
opt('--last-image', a.lastImage);
|
|
150
|
+
for (const img of a.refImages ?? []) args.push('--ref-image', img);
|
|
151
|
+
for (const clip of a.refAudio ?? []) args.push('--ref-audio', clip);
|
|
136
152
|
opt('--res', a.resolution);
|
|
137
153
|
opt('--size', a.size);
|
|
138
154
|
opt('--duration', a.duration);
|
|
@@ -143,6 +159,26 @@ function requestArgs(a) {
|
|
|
143
159
|
return args;
|
|
144
160
|
}
|
|
145
161
|
|
|
162
|
+
/**
|
|
163
|
+
* "image" is a video's first frame and "images" are an image model's inputs. Says which one to
|
|
164
|
+
* use when the other was given, and that a last frame and references are for video models; null
|
|
165
|
+
* when the fields fit the model (or the model is unknown, which the command reports itself).
|
|
166
|
+
*/
|
|
167
|
+
function wrongImageField(ctx, a) {
|
|
168
|
+
const videoOnly = ['lastImage', 'refImages', 'refAudio'].find((field) => a[field] !== undefined);
|
|
169
|
+
if (a.image === undefined && a.images === undefined && !videoOnly) return null;
|
|
170
|
+
let kind;
|
|
171
|
+
try { kind = loadCatalog(ctx.io.dataDir).models[a.model]?.kind; } catch { return null; }
|
|
172
|
+
if (kind === 'image' && videoOnly) return `"${videoOnly}" is for video models, and ${a.model} is an image model`;
|
|
173
|
+
if (kind === 'image' && a.image !== undefined) {
|
|
174
|
+
return `${a.model} is an image model: pass its input images in "images" (a list), not "image"`;
|
|
175
|
+
}
|
|
176
|
+
if (kind === 'video' && a.images !== undefined) {
|
|
177
|
+
return `${a.model} is a video model: pass its first frame in "image" (one value), not "images"`;
|
|
178
|
+
}
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
|
|
146
182
|
/** True when `dir` is `parent` or inside it. */
|
|
147
183
|
function isInside(dir, parent) {
|
|
148
184
|
const rel = path.relative(path.resolve(parent), path.resolve(dir));
|
|
@@ -208,6 +244,8 @@ const HANDLERS = {
|
|
|
208
244
|
},
|
|
209
245
|
|
|
210
246
|
async quote(ctx, a) {
|
|
247
|
+
const wrong = wrongImageField(ctx, a);
|
|
248
|
+
if (wrong) return failure('usage', `quote: ${wrong}`);
|
|
211
249
|
const args = requestArgs(a);
|
|
212
250
|
const r = await cli(ctx.io, ['quote', ...args]);
|
|
213
251
|
if (r.code !== 0) return fromCli(r);
|