nanoodle 0.7.0 → 0.9.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 +57 -2
- package/bin/nanoodle.mjs +7 -1
- package/package.json +1 -1
- package/src/browser.mjs +1 -1
- package/src/catalog.mjs +19 -0
- package/src/cleanvoice.mjs +104 -0
- package/src/client.mjs +66 -8
- package/src/decide.mjs +160 -0
- package/src/endpoint.mjs +406 -0
- package/src/estimate.mjs +141 -20
- package/src/graph.mjs +12 -2
- package/src/index.mjs +4 -0
- package/src/io.mjs +28 -0
- package/src/local-media.mjs +38 -0
- package/src/media.mjs +3 -0
- package/src/nodes.mjs +184 -18
- package/src/prompt-caps.mjs +169 -0
- package/src/workflow.mjs +96 -7
package/src/graph.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { NanoodleError } from "./errors.mjs";
|
|
|
3
3
|
/* Dynamic input-port families (mirrors the nanoodle app's runGraph). A wire landing on one of
|
|
4
4
|
these ports — or on a port declared in NODE_TYPES[type].inputs — is a data input; a wire
|
|
5
5
|
landing on ANY other port is a field override (wired prompt/system/lyrics/q/...). */
|
|
6
|
-
export const IMG_PORT_RE = /^img\d+$/; // llm vision references
|
|
6
|
+
export const IMG_PORT_RE = /^img\d+$/; // llm vision references, decide candidates
|
|
7
7
|
export const EDIT_IMG_RE = /^image\d*$/; // edit multi-reference: image, image2, ...
|
|
8
8
|
export const VID_PORT_RE = /^vid\d+$/;
|
|
9
9
|
export const CLIP_PORT_RE = /^clip\d+$/; // combine clips
|
|
@@ -40,6 +40,7 @@ export const NODE_TYPES = {
|
|
|
40
40
|
upload: { title: "Image input", inputs: [], outputs: [{ name: "image", type: "image" }], local: true },
|
|
41
41
|
aupload: { title: "Audio input", inputs: [], outputs: [{ name: "audio", type: "audio" }], local: true },
|
|
42
42
|
vupload: { title: "Video input", inputs: [], outputs: [{ name: "video", type: "video" }], local: true },
|
|
43
|
+
mupload: { title: "3D input", inputs: [], outputs: [{ name: "model", type: "model3d" }], local: true },
|
|
43
44
|
choice: { title: "Choice", inputs: [], outputs: [{ name: "text", type: "text" }], local: true },
|
|
44
45
|
join: { title: "Join", inputs: ["a", "b"], outputs: [{ name: "text", type: "text" }], local: true },
|
|
45
46
|
llm: { title: "LLM", inputs: [], outputs: [{ name: "text", type: "text" }], network: true },
|
|
@@ -48,8 +49,10 @@ export const NODE_TYPES = {
|
|
|
48
49
|
inpaint: { title: "Inpaint", inputs: ["image", "mask"], outputs: [{ name: "image", type: "image" }], network: true },
|
|
49
50
|
resize: { title: "Resize / crop", inputs: ["image"], outputs: [{ name: "image", type: "image" }], local: true },
|
|
50
51
|
vision: { title: "Vision", inputs: ["image"], outputs: [{ name: "text", type: "text" }], network: true },
|
|
52
|
+
decide: { title: "Decide", inputs: ["text"], outputs: [{ name: "text", type: "text" }, { name: "image", type: "image" }], network: true }, // img1… candidates (IMG_PORT_RE)
|
|
51
53
|
tvideo: { title: "Text→Video", inputs: [], outputs: [{ name: "video", type: "video" }], network: true },
|
|
52
54
|
ivideo: { title: "Image→Video", inputs: ["image"], outputs: [{ name: "video", type: "video" }], network: true },
|
|
55
|
+
model3d: { title: "3D model", inputs: ["image"], outputs: [{ name: "model", type: "model3d" }], network: true },
|
|
53
56
|
vedit: { title: "Video edit", inputs: ["video"], outputs: [{ name: "video", type: "video" }], network: true },
|
|
54
57
|
vframes: { title: "Video → frames", inputs: ["video"], outputs: [{ name: "frame1", type: "image" }], local: true, framesOut: true }, // dynamic frame1..N
|
|
55
58
|
combine: { title: "Combine videos", inputs: [], outputs: [{ name: "video", type: "video" }], local: true },
|
|
@@ -61,6 +64,10 @@ export const NODE_TYPES = {
|
|
|
61
64
|
trim: { title: "Trim audio", inputs: ["audio"], outputs: [{ name: "audio", type: "audio" }], local: true },
|
|
62
65
|
extractaudio: { title: "Extract audio", inputs: ["video"], outputs: [{ name: "audio", type: "audio" }], local: true },
|
|
63
66
|
transcribe: { title: "Transcribe", inputs: ["audio"], outputs: [{ name: "text", type: "text" }], network: true },
|
|
67
|
+
cleanvoice: { title: "Clean voice", inputs: ["audio", "video"], outputs: [{ name: "audio", type: "audio" }], network: true },
|
|
68
|
+
// Custom URL — not a NanoGPT call, so `network` stays unset (no API key required).
|
|
69
|
+
// Output port follows fields.mode (see deriveOutputs / endpointOutPort).
|
|
70
|
+
endpoint: { title: "Custom endpoint", inputs: ["text", "image", "audio", "video"], outputs: [{ name: "text", type: "text" }] },
|
|
64
71
|
comment: { title: "Comment", inputs: [], outputs: [], note: true, local: true },
|
|
65
72
|
};
|
|
66
73
|
|
|
@@ -104,7 +111,10 @@ const MEDIA_FIELD_KEYS = ["image", "mask", "audio", "video"];
|
|
|
104
111
|
const MEDIA_URL_RE = /^(data:|https?:)/i;
|
|
105
112
|
|
|
106
113
|
function scrubMediaPlaceholders(n, warnings) {
|
|
107
|
-
|
|
114
|
+
// mupload stores the .glb on fields.model. That key is an AI model id on every
|
|
115
|
+
// other node, so it is only treated as media here.
|
|
116
|
+
const keys = n.type === "mupload" ? MEDIA_FIELD_KEYS.concat(["model"]) : MEDIA_FIELD_KEYS;
|
|
117
|
+
for (const k of keys) {
|
|
108
118
|
const v = n.fields[k];
|
|
109
119
|
if (v == null || v === "" || (typeof v === "string" && MEDIA_URL_RE.test(v.trim()))) continue;
|
|
110
120
|
const shown = typeof v === "string"
|
package/src/index.mjs
CHANGED
|
@@ -6,8 +6,12 @@ export {
|
|
|
6
6
|
} from "./media.mjs";
|
|
7
7
|
export { NanoClient } from "./client.mjs";
|
|
8
8
|
export { NODE_TYPES, displayName, materialize, topoSort, wiredFramesFloor, MAX_FRAMES } from "./graph.mjs";
|
|
9
|
+
// edit models whose image ports are ORDERED roles — a caller building graphs needs the slot order
|
|
10
|
+
export { IMG_INPUT_ROLES } from "./nodes.mjs";
|
|
9
11
|
export { deriveInputs, deriveOutputs, deriveSettings, INPUT_SPECS, SETTING_SPECS } from "./io.mjs";
|
|
10
12
|
export { estimateGraphCost, graphModelKinds } from "./estimate.mjs";
|
|
13
|
+
// prompt length caps — a caller doing its own orchestration needs the same trim-and-say-so
|
|
14
|
+
export { PROMPT_CAPS, promptCap, fitPromptText, isPromptTooLong, promptCapFromError } from "./prompt-caps.mjs";
|
|
11
15
|
export { decodeShareUrl, decodeShareFragment, isShareRef } from "./share.mjs";
|
|
12
16
|
export { parseNanoInvoice } from "./x402.mjs";
|
|
13
17
|
export { qrTerminal, qrModules } from "./qr.mjs";
|
package/src/io.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NanoodleError } from "./errors.mjs";
|
|
2
2
|
import { NODE_TYPES, displayName, optionalNode, topoSort, wiredFramesFloor, MAX_FRAMES } from "./graph.mjs";
|
|
3
|
+
import { endpointOutPort } from "./endpoint.mjs";
|
|
3
4
|
|
|
4
5
|
/* ============================== INPUTS ============================== */
|
|
5
6
|
|
|
@@ -9,6 +10,7 @@ export const INPUT_SPECS = {
|
|
|
9
10
|
upload: [{ f: "image", label: "Image", kind: "image" }],
|
|
10
11
|
aupload: [{ f: "audio", label: "Audio", kind: "audio" }],
|
|
11
12
|
vupload: [{ f: "video", label: "Video", kind: "video" }],
|
|
13
|
+
mupload: [{ f: "model", label: "3D file", kind: "model3d" }],
|
|
12
14
|
llm: [{ f: "prompt", label: "Prompt", kind: "textarea" },
|
|
13
15
|
{ f: "system", label: "System prompt", kind: "textarea", optional: true, def: "You are a helpful, concise assistant." }],
|
|
14
16
|
image: [{ f: "prompt", label: "Image prompt", kind: "textarea" }],
|
|
@@ -16,6 +18,9 @@ export const INPUT_SPECS = {
|
|
|
16
18
|
music: [{ f: "prompt", label: "Style / prompt", kind: "textarea" }],
|
|
17
19
|
remix: [{ f: "prompt", label: "Style / direction", kind: "textarea" }],
|
|
18
20
|
tts: [{ f: "prompt", label: "Text to speak", kind: "textarea" }],
|
|
21
|
+
// Optional: image-only 3D models run with a photo and no prompt.
|
|
22
|
+
model3d: [{ f: "prompt", label: "3D prompt", kind: "textarea", optional: true }],
|
|
23
|
+
endpoint:[{ f: "prompt", label: "Prompt", kind: "textarea" }],
|
|
19
24
|
};
|
|
20
25
|
|
|
21
26
|
/**
|
|
@@ -163,6 +168,8 @@ export function deriveOutputs(graph) {
|
|
|
163
168
|
ports = [];
|
|
164
169
|
for (let i = 1; i <= count; i++) ports.push({ name: "frame" + i, type: "image" });
|
|
165
170
|
}
|
|
171
|
+
// Custom endpoint's output port follows fields.mode (chat→text, image, video, audio, json→text).
|
|
172
|
+
if (n.type === "endpoint") ports = [endpointOutPort(n)];
|
|
166
173
|
return { key, nodeId: n.id, type: n.type, ports };
|
|
167
174
|
});
|
|
168
175
|
}
|
|
@@ -187,6 +194,14 @@ export const SETTING_SPECS = {
|
|
|
187
194
|
{ f: "model", label: "Model", kind: "model" },
|
|
188
195
|
{ f: "q", label: "Question", kind: "textarea", def: "Describe this image." },
|
|
189
196
|
],
|
|
197
|
+
decide: [
|
|
198
|
+
{ f: "model", label: "Model", kind: "model" },
|
|
199
|
+
{ f: "mode", label: "Decide", kind: "select", options: ["pick", "choose", "score", "yesno"], def: "pick" },
|
|
200
|
+
{ f: "question", label: "Question", kind: "textarea" },
|
|
201
|
+
{ f: "options", label: "Labels (one per line)", kind: "textarea" },
|
|
202
|
+
{ f: "levels", label: "Scale (worst → best, one per line)", kind: "textarea", def: "poor\nokay\ngood\ngreat" },
|
|
203
|
+
{ f: "gate", label: "Gate: stop downstream on no", kind: "boolean" },
|
|
204
|
+
],
|
|
190
205
|
image: [
|
|
191
206
|
{ f: "model", label: "Model", kind: "model" },
|
|
192
207
|
{ f: "size", label: "Image size", kind: "select", options: SIZES, def: "1024x1024" },
|
|
@@ -245,6 +260,19 @@ export const SETTING_SPECS = {
|
|
|
245
260
|
{ f: "model", label: "Model", kind: "model" },
|
|
246
261
|
{ f: "language", label: "Language", kind: "text", def: "auto" },
|
|
247
262
|
],
|
|
263
|
+
cleanvoice: [
|
|
264
|
+
{ f: "model", label: "Model", kind: "model" },
|
|
265
|
+
{ f: "url", label: "Public link (when nothing is wired)", kind: "text" },
|
|
266
|
+
],
|
|
267
|
+
model3d: [
|
|
268
|
+
{ f: "model", label: "Model", kind: "model" },
|
|
269
|
+
],
|
|
270
|
+
endpoint: [
|
|
271
|
+
{ f: "url", label: "URL", kind: "text", def: "http://127.0.0.1:8787/v1/chat/completions" },
|
|
272
|
+
{ f: "mode", label: "Mode", kind: "select", options: ["chat", "image", "video", "audio", "json"], def: "chat" },
|
|
273
|
+
{ f: "model", label: "Model", kind: "text", def: "local" },
|
|
274
|
+
{ f: "auth", label: "Authorization (optional)", kind: "text", def: "" },
|
|
275
|
+
],
|
|
248
276
|
join: [{ f: "sep", label: "Separator (use \\n for a line break)", kind: "text", def: " " }],
|
|
249
277
|
inpaint: [
|
|
250
278
|
{ f: "model", label: "Model", kind: "model" },
|
package/src/local-media.mjs
CHANGED
|
@@ -729,6 +729,44 @@ export async function fitImageInline(url, { budget = INLINE_IMAGE_BUDGET, fetch:
|
|
|
729
729
|
throw new NanoodleError("image is too large to send inline even after resizing (~4 MB max) — use a smaller image");
|
|
730
730
|
}
|
|
731
731
|
|
|
732
|
+
/**
|
|
733
|
+
* Shrink an image to fit a decision model's limits (⚖️ Decide): long edge ≤ maxDim and the
|
|
734
|
+
* data: URL ≤ budget characters. JPEG on white (a transparent PNG can't turn black), stepping
|
|
735
|
+
* quality down, then size, until it fits — the twin of the browser's canvas decideFitImage.
|
|
736
|
+
* Needs ffmpeg (decisions without images never touch this).
|
|
737
|
+
*/
|
|
738
|
+
export async function fitImageJpeg(url, maxDim, budget, { fetch: fetchFn, signal } = {}) {
|
|
739
|
+
return withTemp(async (dir) => {
|
|
740
|
+
throwIfAborted(signal);
|
|
741
|
+
const inPath = await writeInput(dir, "in", url, fetchFn);
|
|
742
|
+
const probe = await runProc("ffprobe", [
|
|
743
|
+
"-v", "error", "-select_streams", "v:0",
|
|
744
|
+
"-show_entries", "stream=width,height", "-of", "csv=p=0:s=x", inPath,
|
|
745
|
+
], { signal });
|
|
746
|
+
const dims = String(probe.stdout).trim().split("x").map(Number);
|
|
747
|
+
const sw = dims[0], sh = dims[1];
|
|
748
|
+
if (!(sw > 0) || !(sh > 0)) throw new NanoodleError("couldn’t read an image to judge");
|
|
749
|
+
let s = Math.min(1, maxDim / Math.max(sw, sh));
|
|
750
|
+
const qs = [3, 5, 8, 12]; // mjpeg -q:v (2 = best … 31 = worst) ≈ canvas quality 0.85 → 0.48
|
|
751
|
+
for (let round = 0; round < 6; round++) {
|
|
752
|
+
const w = Math.max(2, Math.round(sw * s / 2) * 2), h = Math.max(2, Math.round(sh * s / 2) * 2);
|
|
753
|
+
for (const q of qs) {
|
|
754
|
+
throwIfAborted(signal);
|
|
755
|
+
const outPath = join(dir, `fit-${round}-${q}.jpg`);
|
|
756
|
+
await runProc("ffmpeg", [
|
|
757
|
+
"-y", "-i", inPath, "-filter_complex",
|
|
758
|
+
`color=c=white:s=${w}x${h}[bg];[0:v]scale=${w}:${h},format=rgba[fg];[bg][fg]overlay=shortest=1,format=yuvj420p`,
|
|
759
|
+
"-frames:v", "1", "-q:v", String(q), outPath,
|
|
760
|
+
], { signal });
|
|
761
|
+
const out = await dataUrlFromFile(outPath, "image/jpeg");
|
|
762
|
+
if (out.length <= budget) return out;
|
|
763
|
+
}
|
|
764
|
+
s *= 0.75;
|
|
765
|
+
}
|
|
766
|
+
throw new NanoodleError("couldn’t shrink an image small enough for the decision model");
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
|
|
732
770
|
async function resizeCropImageFfmpeg(url, m, w, h, { fetch: fetchFn, signal } = {}) {
|
|
733
771
|
return withTemp(async (dir) => {
|
|
734
772
|
throwIfAborted(signal);
|
package/src/media.mjs
CHANGED
|
@@ -42,6 +42,7 @@ const EXT_MIME = {
|
|
|
42
42
|
".mp3": "audio/mpeg", ".wav": "audio/wav", ".ogg": "audio/ogg", ".opus": "audio/ogg",
|
|
43
43
|
".aac": "audio/aac", ".flac": "audio/flac", ".m4a": "audio/mp4",
|
|
44
44
|
".mp4": "video/mp4", ".webm": "video/webm", ".mov": "video/quicktime", ".mkv": "video/x-matroska",
|
|
45
|
+
".glb": "model/gltf-binary",
|
|
45
46
|
".txt": "text/plain", ".json": "application/json",
|
|
46
47
|
};
|
|
47
48
|
|
|
@@ -50,6 +51,7 @@ const MIME_EXT = {
|
|
|
50
51
|
"audio/mpeg": "mp3", "audio/wav": "wav", "audio/ogg": "ogg", "audio/aac": "aac",
|
|
51
52
|
"audio/flac": "flac", "audio/mp4": "m4a",
|
|
52
53
|
"video/mp4": "mp4", "video/webm": "webm", "video/quicktime": "mov",
|
|
54
|
+
"model/gltf-binary": "glb",
|
|
53
55
|
"text/plain": "txt", "application/json": "json",
|
|
54
56
|
};
|
|
55
57
|
|
|
@@ -80,6 +82,7 @@ export function sniffMime(bytes) {
|
|
|
80
82
|
if (ascii(0, "fLaC")) return "audio/flac";
|
|
81
83
|
if (b.length >= 12 && ascii(4, "ftyp")) return "video/mp4";
|
|
82
84
|
if (b.length >= 4 && b[0] === 0x1a && b[1] === 0x45 && b[2] === 0xdf && b[3] === 0xa3) return "video/webm";
|
|
85
|
+
if (b.length >= 4 && ascii(0, "glTF")) return "model/gltf-binary";
|
|
83
86
|
return "application/octet-stream";
|
|
84
87
|
}
|
|
85
88
|
|
package/src/nodes.mjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { NanoodleError } from "./errors.mjs";
|
|
2
|
-
import { catItem, chatModelCan } from "./catalog.mjs";
|
|
2
|
+
import { catItem, chatModelCan, pricingAdvertisesRefs } from "./catalog.mjs";
|
|
3
3
|
import { IMG_PORT_RE, EDIT_IMG_RE, REF_PORT_RE, CLIP_PORT_RE, VID_PORT_RE, optionalNode } from "./graph.mjs";
|
|
4
4
|
import { MEDIA_INLINE_MAX } from "./media.mjs";
|
|
5
5
|
import {
|
|
6
6
|
resizeCropImage, trimAudioToWav, extractAudioToWav,
|
|
7
|
-
extractVideoFrames, concatVideos, muxSoundtrack, maskToSource, fitImageInline,
|
|
7
|
+
extractVideoFrames, concatVideos, muxSoundtrack, maskToSource, fitImageInline, fitImageJpeg,
|
|
8
8
|
} from "./local-media.mjs";
|
|
9
|
+
import { decideRun, decideImageLimits } from "./decide.mjs";
|
|
10
|
+
import { cleanVoiceRun, CLEANVOICE_DEFAULT_MODEL } from "./cleanvoice.mjs";
|
|
11
|
+
import { runEndpoint } from "./endpoint.mjs";
|
|
9
12
|
|
|
10
13
|
function mdl(n) {
|
|
11
14
|
const m = String((n.fields && n.fields.model) || "").trim();
|
|
@@ -52,6 +55,46 @@ function collectPorts(inp, re) {
|
|
|
52
55
|
.filter(Boolean);
|
|
53
56
|
}
|
|
54
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Edit models that demand a FIXED, ORDERED set of input images. Nothing in the live catalog
|
|
60
|
+
* declares a minimum — a full 215-model scan (2026-07-31) found no min_items/min_input_images
|
|
61
|
+
* field, only free text — so the roles live here. The order IS the slot order: role 1 = the
|
|
62
|
+
* `image` port, role 2 = `image2`, … (flux vto auto-detects the wearer either way, but a
|
|
63
|
+
* garment-first send drifts the identity toward the garment photo's model).
|
|
64
|
+
*/
|
|
65
|
+
export const IMG_INPUT_ROLES = {
|
|
66
|
+
"flux-pro/v1/vto": ["person", "garment"],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const imgSlot = (i) => (i === 1 ? "image" : "image" + i); // slot index → EDIT_IMG_RE port name
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Refuse a role-model edit BEFORE the paid call unless every slot is wired. Read the RAW inp
|
|
73
|
+
* keys, never collectPorts: that compacts (.filter(Boolean)), so wiring only `image2` promotes
|
|
74
|
+
* the garment into the person slot and buys a silently wrong result.
|
|
75
|
+
*/
|
|
76
|
+
function guardInputRoles(model, inp) {
|
|
77
|
+
const roles = IMG_INPUT_ROLES[String(model || "").trim()];
|
|
78
|
+
if (!roles) return;
|
|
79
|
+
const missing = roles.filter((r, i) => !inp[imgSlot(i + 1)]);
|
|
80
|
+
if (!missing.length) return;
|
|
81
|
+
const slots = roles.map((r, i) => `${r} (${imgSlot(i + 1)})`).join(", ");
|
|
82
|
+
throw new NanoodleError(
|
|
83
|
+
`${model} needs ${roles.length} images: ${slots} — ${roles.length - missing.length} wired (missing: ${missing.join(", ")})`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* edit/inpaint have a single image output, but some models always bill (and return) a fixed
|
|
89
|
+
* batch — midjourney/text-to-image and higgsfield-soul declare fixed_image_count: 4. Ask with
|
|
90
|
+
* multi so we can SEE the extras and say we dropped them; the return shape stays one url.
|
|
91
|
+
*/
|
|
92
|
+
function keptFirst(urls, ctx) {
|
|
93
|
+
if (!Array.isArray(urls)) return urls; // host-injected ctx.image that ignores multi → already one url
|
|
94
|
+
if (urls.length > 1 && ctx && ctx.progress) ctx.progress(`model returned ${urls.length} images, kept the first`);
|
|
95
|
+
return urls[0];
|
|
96
|
+
}
|
|
97
|
+
|
|
55
98
|
function promptOf(n, inp, errMsg) {
|
|
56
99
|
const raw = inp.prompt != null ? inp.prompt : n.fields.prompt != null ? n.fields.prompt : "";
|
|
57
100
|
const p = String(raw).trim();
|
|
@@ -126,7 +169,10 @@ function loraFamily(model) {
|
|
|
126
169
|
if (/flux-2/i.test(m)) return "flux2dev";
|
|
127
170
|
if (/z-image/i.test(m)) return "zimage";
|
|
128
171
|
if (/ltx/i.test(m)) return "ltx";
|
|
129
|
-
if (/
|
|
172
|
+
if (/minimax-h3/i.test(m)) return "h3";
|
|
173
|
+
if (/anima/i.test(m) && /lora/i.test(m)) return "anima";
|
|
174
|
+
if (/qwen-image-2\.1/i.test(m) && /lora/i.test(m)) return "qwen21";
|
|
175
|
+
if (/lora/i.test(m)) return /krea/i.test(m) ? "krea" : "flux";
|
|
130
176
|
return null;
|
|
131
177
|
}
|
|
132
178
|
|
|
@@ -136,6 +182,7 @@ function imageTakesLora(id) {
|
|
|
136
182
|
id = String(id || "");
|
|
137
183
|
if (/inpaint/i.test(id)) return false;
|
|
138
184
|
if (/klein/i.test(id)) return true;
|
|
185
|
+
if (/minimax-h3\/(text-to-image|image-edit)/i.test(id)) return true;
|
|
139
186
|
return /(^|[-\/])lora($|[-\/])/i.test(id);
|
|
140
187
|
}
|
|
141
188
|
|
|
@@ -149,7 +196,7 @@ function modelTakesLora(kind, id) {
|
|
|
149
196
|
function loraCap(model) {
|
|
150
197
|
switch (loraFamily(model)) {
|
|
151
198
|
case "flux2dev": return 4;
|
|
152
|
-
case "flux2klein": case "zimage": case "ltx": return 3;
|
|
199
|
+
case "flux2klein": case "zimage": case "ltx": case "krea": case "h3": case "anima": case "qwen21": return 3;
|
|
153
200
|
default: return 1; // flux-lora, pimage — single slot
|
|
154
201
|
}
|
|
155
202
|
}
|
|
@@ -165,7 +212,7 @@ function nodeLoras(n) {
|
|
|
165
212
|
function loraBodyFor(model, items) {
|
|
166
213
|
const fam = loraFamily(model), sc = (v) => (isNaN(v) ? 1 : v);
|
|
167
214
|
if (fam === "pimage") return { lora_weights: items[0].url, lora_scale: sc(items[0].scale) };
|
|
168
|
-
if (fam === "flux2dev" || fam === "flux2klein" || fam === "zimage" || fam === "ltx") {
|
|
215
|
+
if (fam === "flux2dev" || fam === "flux2klein" || fam === "zimage" || fam === "ltx" || fam === "krea" || fam === "h3" || fam === "anima" || fam === "qwen21") {
|
|
169
216
|
const b = {};
|
|
170
217
|
items.forEach((it, i) => { b["lora_url_" + (i + 1)] = it.url; b["lora_scale_" + (i + 1)] = sc(it.scale); });
|
|
171
218
|
return b;
|
|
@@ -237,6 +284,13 @@ function imgExtra(n) {
|
|
|
237
284
|
const np = String(n.fields.negativePrompt || "").trim();
|
|
238
285
|
if (np) e.negative_prompt = np;
|
|
239
286
|
}
|
|
287
|
+
// FIBO 1.5: size is 1mp/4mp; shape rides as aspect_ratio. Only this advertised id —
|
|
288
|
+
// leftover fields.aspect after a model swap must not go out on Muse/Recraft/etc.
|
|
289
|
+
// Marketing /api/models additionalParams.aspect_ratio (v1 image-models still omits it).
|
|
290
|
+
if (n.fields.model === "bria/fibo-generate-1.5/text-to-image") {
|
|
291
|
+
const av = (n.fields.aspect != null && n.fields.aspect !== "") ? n.fields.aspect : "1:1";
|
|
292
|
+
if (av !== "") e.aspect_ratio = String(av);
|
|
293
|
+
}
|
|
240
294
|
return e;
|
|
241
295
|
}
|
|
242
296
|
|
|
@@ -255,12 +309,17 @@ function videoDims(n, ctx) {
|
|
|
255
309
|
const aWire = p.aspect_ratio ? "aspect_ratio" : p.orientation ? "orientation" : p.resolution_ratio ? "resolution_ratio" : "aspect_ratio";
|
|
256
310
|
const dP = p.duration || p.seconds;
|
|
257
311
|
const dWire = p.duration ? "duration" : p.seconds ? "seconds" : "duration";
|
|
312
|
+
// tvideo/ivideo soft-send aspect+duration (those nodes always show the knobs).
|
|
313
|
+
// vedit/lipsync and resolution never forward a leftover the model did not list.
|
|
314
|
+
// Gallery: Omni v1 has duration+aspect only; leftover 720p/4k from v1.1 must not POST.
|
|
315
|
+
// Matches play videoDimParams (pack.resolution / dimDefs) — including catalog-miss omit.
|
|
316
|
+
const soft = n.type !== "vedit" && n.type !== "lipsync";
|
|
258
317
|
let asp = f.aspect, dur = f.duration;
|
|
259
318
|
if ((asp == null || asp === "") && aP && aP.default != null) asp = aP.default;
|
|
260
319
|
if ((dur == null || dur === "") && dP && dP.default != null) dur = dP.default;
|
|
261
|
-
if (f.resolution != null && f.resolution !== "") out.resolution = f.resolution;
|
|
262
|
-
if (asp != null && asp !== "") out[aWire] = asp;
|
|
263
|
-
if (dur != null && dur !== "") out[dWire] = dur;
|
|
320
|
+
if (p.resolution && f.resolution != null && f.resolution !== "") out.resolution = f.resolution;
|
|
321
|
+
if ((aP || soft) && asp != null && asp !== "") out[aWire] = asp;
|
|
322
|
+
if ((dP || soft) && dur != null && dur !== "") out[dWire] = dur;
|
|
264
323
|
return out;
|
|
265
324
|
}
|
|
266
325
|
|
|
@@ -268,10 +327,13 @@ function videoDims(n, ctx) {
|
|
|
268
327
|
Video models disagree on the ref-array param name AND its size limit; sending the wrong
|
|
269
328
|
key silently degrades to a plain video, sending too many can over-bill. Resolve the
|
|
270
329
|
model's REAL key from the catalog and clamp to its declared max. */
|
|
271
|
-
function refMaxFor(model) {
|
|
330
|
+
function refMaxFor(model, pricing) {
|
|
272
331
|
const id = String(model || "");
|
|
273
332
|
if (/seedance/i.test(id)) return 9;
|
|
333
|
+
if (/minimax-h3/i.test(id)) return 9; // upstream cap; the first 5 are included, 6-9 bill extra_reference_image each
|
|
274
334
|
if (/luma|ray/i.test(id)) return 4;
|
|
335
|
+
const inc = pricing && +pricing.included_reference_images;
|
|
336
|
+
if (inc > 0) return inc; // no family entry: the included count is the only number the catalog gives us
|
|
275
337
|
return 4;
|
|
276
338
|
}
|
|
277
339
|
|
|
@@ -285,15 +347,15 @@ function modelRefSpec(model, ctx) {
|
|
|
285
347
|
const m = catItem(ctx && ctx.catalog, "video", model);
|
|
286
348
|
if (!m) return { key: "reference_images", cap: refMaxFor(model) };
|
|
287
349
|
const sp = m.supported_parameters || {}, pp = sp.parameters || sp;
|
|
288
|
-
const key = keys.find((k) => k in pp);
|
|
289
|
-
if (!key) return null; // known model with no ref-image param
|
|
350
|
+
const key = keys.find((k) => k in pp) || (pricingAdvertisesRefs(m.pricing) ? "reference_images" : null);
|
|
351
|
+
if (!key) return null; // known model with no ref-image param and no ref pricing
|
|
290
352
|
const d = pp[key];
|
|
291
353
|
let cap = null;
|
|
292
354
|
if (d && typeof d === "object") {
|
|
293
355
|
const mx = d.max != null ? d.max : d.maxItems != null ? d.maxItems : d.max_items;
|
|
294
356
|
if (mx != null && +mx > 0) cap = +mx;
|
|
295
357
|
}
|
|
296
|
-
return { key, cap: cap != null ? cap : refMaxFor(model) };
|
|
358
|
+
return { key, cap: cap != null ? cap : refMaxFor(model, m.pricing) };
|
|
297
359
|
}
|
|
298
360
|
|
|
299
361
|
/** Attach wired refs to video opts under the model's real key, clamped to its cap (twin of the app runtimes: say so, never silently discard). */
|
|
@@ -337,22 +399,42 @@ function audioParams(n, ctx) {
|
|
|
337
399
|
const durOk = !sp || (sp.min_duration != null && sp.max_duration != null); // cat:duration
|
|
338
400
|
const secDurOk = !sp || (sp.min_duration != null && sp.max_duration != null && +((m.pricing || {}).per_second) > 0); // cat:secduration
|
|
339
401
|
const voiceOk = !sp || (Array.isArray(sp.voices) && sp.voices.length > 0); // cat:voices
|
|
402
|
+
// Yue2 catalogs the file type as output_format (mp3/wav/flac). The OpenAI response_format
|
|
403
|
+
// key is ignored, so a wav/flac choice came back as mp3. No output_format in the catalog
|
|
404
|
+
// (or no catalog) keeps the old response_format send.
|
|
405
|
+
const putFormat = (fmt) => {
|
|
406
|
+
if (!nonEmpty(fmt)) return;
|
|
407
|
+
const of = sp && sp.output_format;
|
|
408
|
+
const values = of && Array.isArray(of.values) ? of.values : null;
|
|
409
|
+
if (values) {
|
|
410
|
+
if (values.indexOf(fmt) < 0) return;
|
|
411
|
+
const def = of.default != null ? of.default : "mp3";
|
|
412
|
+
if (fmt === def) return;
|
|
413
|
+
body.output_format = fmt;
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if (fmt !== "mp3") body.response_format = fmt;
|
|
417
|
+
};
|
|
340
418
|
if (n.type === "music") {
|
|
341
419
|
if (nonEmpty(f.lyrics)) body.lyrics = f.lyrics;
|
|
342
420
|
if (f.instrumental === true || f.instrumental === "true") body.instrumental = true;
|
|
343
421
|
if (nonEmpty(f.duration) && num(f.duration) != null && durOk) body.duration = num(f.duration);
|
|
344
422
|
if (nonEmpty(f.negative_prompt)) body.negative_prompt = f.negative_prompt;
|
|
345
423
|
if (nonEmpty(f.seed) && num(f.seed) != null) body.seed = num(f.seed);
|
|
346
|
-
|
|
424
|
+
putFormat(f.response_format);
|
|
347
425
|
} else if (n.type === "tts") {
|
|
348
426
|
if (nonEmpty(f.voice) && voiceOk) body.voice = f.voice;
|
|
349
427
|
if (nonEmpty(f.speed) && num(f.speed) != null && num(f.speed) !== 1) body.speed = num(f.speed); // omit when 1
|
|
350
428
|
if (nonEmpty(f.instructions)) body.instructions = f.instructions;
|
|
351
|
-
|
|
429
|
+
putFormat(f.response_format);
|
|
352
430
|
} else if (n.type === "remix") {
|
|
353
431
|
if (nonEmpty(f.lyrics)) body.lyrics = f.lyrics;
|
|
354
432
|
if (nonEmpty(f.duration) && num(f.duration) != null && secDurOk) body.duration = num(f.duration);
|
|
355
|
-
|
|
433
|
+
// Format is a remix knob only when the catalog lists output_format (Yue2 music-to-music).
|
|
434
|
+
// A cover model with no such key must not receive a stale response_format.
|
|
435
|
+
const of = sp && sp.output_format;
|
|
436
|
+
const fmtListed = !!(of && Array.isArray(of.values) && of.values.length);
|
|
437
|
+
if (!sp || fmtListed) putFormat(f.response_format);
|
|
356
438
|
}
|
|
357
439
|
if ((f.extraJson || "").trim()) {
|
|
358
440
|
try { Object.assign(body, JSON.parse(f.extraJson)); }
|
|
@@ -422,6 +504,13 @@ export const RUNNERS = {
|
|
|
422
504
|
}
|
|
423
505
|
return { video: n.fields.video };
|
|
424
506
|
},
|
|
507
|
+
async mupload(n) {
|
|
508
|
+
if (!n.fields.model) {
|
|
509
|
+
if (optionalNode(n)) return { model: "" };
|
|
510
|
+
throw new NanoodleError("no 3D file — drop a .glb first");
|
|
511
|
+
}
|
|
512
|
+
return { model: n.fields.model };
|
|
513
|
+
},
|
|
425
514
|
|
|
426
515
|
async choice(n) {
|
|
427
516
|
const opts = String(n.fields.options || "").split("\n").map((s) => s.trim()).filter(Boolean);
|
|
@@ -504,7 +593,16 @@ export const RUNNERS = {
|
|
|
504
593
|
|
|
505
594
|
async llm(n, inp, ctx) {
|
|
506
595
|
const prompt = promptOf(n, inp, "no prompt");
|
|
507
|
-
|
|
596
|
+
// Wired image ports: a text-only chat model can't see the pictures and NanoGPT still
|
|
597
|
+
// bills the image tokens, so drop them for a KNOWN text-only model and note it —
|
|
598
|
+
// mirrors play's chatModelCan("vision") / editor modelSupportsImages gate (permissive
|
|
599
|
+
// for catalog-absent models; twin of the audio gate below).
|
|
600
|
+
const allImgs = collectPorts(inp, IMG_PORT_RE);
|
|
601
|
+
const seesImages = chatModelCan(ctx.catalog, mdl(n), "vision");
|
|
602
|
+
const imgs = seesImages
|
|
603
|
+
? await Promise.all(allImgs.map((u) => fitImage(u, ctx, "wired image")))
|
|
604
|
+
: [];
|
|
605
|
+
if (allImgs.length && !seesImages) ctx.progress("image(s) ignored — this model is text-only");
|
|
508
606
|
// hosted audio (music/tts nodes return https CDN URLs verbatim) → download + inline as base64:
|
|
509
607
|
// the chat input_audio part carries bytes, never a URL
|
|
510
608
|
let audioPart = null;
|
|
@@ -536,6 +634,17 @@ export const RUNNERS = {
|
|
|
536
634
|
return { text: await ctx.chat(messages, mdl(n), {}) };
|
|
537
635
|
},
|
|
538
636
|
|
|
637
|
+
// ⚖️ Decide: one typed question to a NanoGPT decision model (twin of the editor/play node).
|
|
638
|
+
// A closed yes/no gate throws a NanoodleError with code "decide-gate" — downstream skips, unbilled.
|
|
639
|
+
async decide(n, inp, ctx) {
|
|
640
|
+
const model = mdl(n);
|
|
641
|
+
const it = catItem(ctx.catalog, "chat", model);
|
|
642
|
+
// a catalog row WITHOUT decision_input (e.g. the non-detailed /api/v1/models list) is "unknown", not text-only
|
|
643
|
+
const lim = decideImageLimits(it && it.decision_input, !!(it && it.decision_input));
|
|
644
|
+
const fit = (u, maxDim, budget) => fitImageJpeg(u, maxDim, budget, mediaOpts(ctx));
|
|
645
|
+
return decideRun(n.fields || {}, model, inp.text, collectPorts(inp, IMG_PORT_RE), lim, (body) => ctx.decide(body), fit);
|
|
646
|
+
},
|
|
647
|
+
|
|
539
648
|
async image(n, inp, ctx) {
|
|
540
649
|
const prompt = promptOf(n, inp, "no prompt");
|
|
541
650
|
let want = Math.max(1, parseInt(n.fields.variations, 10) || 1);
|
|
@@ -549,6 +658,7 @@ export const RUNNERS = {
|
|
|
549
658
|
},
|
|
550
659
|
|
|
551
660
|
async edit(n, inp, ctx) {
|
|
661
|
+
guardInputRoles(n.fields.model, inp); // role models: refuse holes before spending
|
|
552
662
|
let imgs = collectPorts(inp, EDIT_IMG_RE);
|
|
553
663
|
if (!imgs.length) throw new NanoodleError("no image input");
|
|
554
664
|
// cap to the model's max_input_images (item present but silent → 1; absent → no cap):
|
|
@@ -567,7 +677,8 @@ export const RUNNERS = {
|
|
|
567
677
|
imgs = await Promise.all(imgs.map((u) => fitImage(u, ctx, "source image")));
|
|
568
678
|
guardRefsSize(imgs);
|
|
569
679
|
const src = imgs.length > 1 ? imgs : imgs[0]; // array → multi-image composite; string → single edit
|
|
570
|
-
|
|
680
|
+
const urls = await ctx.image({ prompt, model: mdl(n), size: n.fields.size || "1024x1024", imageDataUrl: src, extra: imgExtra(n), multi: true });
|
|
681
|
+
return { image: keptFirst(urls, ctx) };
|
|
571
682
|
},
|
|
572
683
|
|
|
573
684
|
async inpaint(n, inp, ctx) {
|
|
@@ -580,7 +691,8 @@ export const RUNNERS = {
|
|
|
580
691
|
// ctx.maskToSource lets a browser host inject its canvas compositor (handles JPEG/WebP
|
|
581
692
|
// sources the pure-PNG path can't, where ffmpeg isn't an option).
|
|
582
693
|
const mask = await (ctx.maskToSource || maskToSource)(rawMask, source, mediaOpts(ctx));
|
|
583
|
-
|
|
694
|
+
const urls = await ctx.image({ prompt, model: mdl(n), size: n.fields.size || "1024x1024", imageDataUrl: source, maskDataUrl: mask, extra: imgExtra(n), multi: true });
|
|
695
|
+
return { image: keptFirst(urls, ctx) };
|
|
584
696
|
},
|
|
585
697
|
|
|
586
698
|
async tvideo(n, inp, ctx) {
|
|
@@ -688,4 +800,58 @@ export const RUNNERS = {
|
|
|
688
800
|
if (!inp.audio) throw new NanoodleError("no audio input");
|
|
689
801
|
return { text: await ctx.transcribe(mdl(n), inp.audio, (n.fields.language || "auto").trim()) };
|
|
690
802
|
},
|
|
803
|
+
|
|
804
|
+
// 🎧 Clean voice: hosted audio or video → voice-only audio. data:/blob: refused before any request.
|
|
805
|
+
async cleanvoice(n, inp, ctx) {
|
|
806
|
+
const model = String((n.fields && n.fields.model) || "").trim() || CLEANVOICE_DEFAULT_MODEL;
|
|
807
|
+
return cleanVoiceRun(model, inp, n.fields, (m, extra) => ctx.audio(m, "", extra));
|
|
808
|
+
},
|
|
809
|
+
|
|
810
|
+
// 🧊 3D model: image and/or text → GLB via the video submit/poll API (mediaKind model3d).
|
|
811
|
+
async model3d(n, inp, ctx) {
|
|
812
|
+
const model = String((n.fields && n.fields.model) || "").trim() || MODEL3D_IMAGE_DEFAULT;
|
|
813
|
+
const mods = model3dInputMods(ctx && ctx.catalog, model);
|
|
814
|
+
const prompt = promptOf(n, inp);
|
|
815
|
+
let image = mods.image ? (inp.image || "") : "";
|
|
816
|
+
if (inp.image && !mods.image && ctx && ctx.progress) {
|
|
817
|
+
ctx.progress("This model takes text only — the image wire stays, but this run ignores it.");
|
|
818
|
+
}
|
|
819
|
+
if (prompt && !mods.text && ctx && ctx.progress) {
|
|
820
|
+
ctx.progress("This model takes an image only — the prompt stays, but this run ignores it.");
|
|
821
|
+
}
|
|
822
|
+
if (mods.image && !mods.text && !image) throw new NanoodleError("Connect an image first.");
|
|
823
|
+
if (mods.text && !mods.image && !prompt) throw new NanoodleError("Add a prompt first.");
|
|
824
|
+
if (mods.image && mods.text && !image && !prompt) throw new NanoodleError("Add a prompt or connect an image first.");
|
|
825
|
+
if (image) image = await fitImage(image, ctx, "source image");
|
|
826
|
+
const url = await ctx.video(model, mods.text ? prompt : "", {
|
|
827
|
+
extra: n.fields.modelOpts || {},
|
|
828
|
+
mediaKind: "model3d",
|
|
829
|
+
}, image || null);
|
|
830
|
+
return { model: url };
|
|
831
|
+
},
|
|
832
|
+
|
|
833
|
+
// 🔌 Custom endpoint: POST to the graph's own URL. ctx.fetch so tests can point it at a mock.
|
|
834
|
+
async endpoint(n, inp, ctx) {
|
|
835
|
+
return runEndpoint(n, inp, { fetch: ctx && ctx.fetch, signal: ctx && ctx.signal });
|
|
836
|
+
},
|
|
691
837
|
};
|
|
838
|
+
|
|
839
|
+
// Image→3D (Tripo) takes a photo only. Hunyuan Rapid takes text and an optional image.
|
|
840
|
+
// Anything else, including a catalog miss, accepts either — the editor's same fallback.
|
|
841
|
+
const MODEL3D_IMAGE_DEFAULT = "tripo3d/v2.5";
|
|
842
|
+
const MODEL3D_TEXT_DEFAULT = "wavespeed-ai/hunyuan-3d-v3.1-rapid";
|
|
843
|
+
|
|
844
|
+
function model3dInputMods(catalog, id) {
|
|
845
|
+
const it = catItem(catalog, "model3d", id);
|
|
846
|
+
const raw = it && (
|
|
847
|
+
(Array.isArray(it.modalities) && it.modalities)
|
|
848
|
+
|| (it.architecture && Array.isArray(it.architecture.input_modalities) && it.architecture.input_modalities)
|
|
849
|
+
);
|
|
850
|
+
if (raw && raw.length) {
|
|
851
|
+
const mods = raw.filter((x) => x === "image" || x === "text");
|
|
852
|
+
if (mods.length) return { image: mods.includes("image"), text: mods.includes("text") };
|
|
853
|
+
}
|
|
854
|
+
if (id === MODEL3D_IMAGE_DEFAULT) return { image: true, text: false };
|
|
855
|
+
if (id === MODEL3D_TEXT_DEFAULT) return { image: true, text: true };
|
|
856
|
+
return { image: true, text: true };
|
|
857
|
+
}
|