nanoodle 0.11.0 → 0.13.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 CHANGED
@@ -35,7 +35,7 @@ agents.
35
35
  | | |
36
36
  |---|---|
37
37
  | **Package** | `nanoodle` on npm |
38
- | **Runtime** | Node ≥ 20 · built-in `fetch` · no deps |
38
+ | **Runtime** | Node 22.23.4+, 24.22.1+, or 26.12.1+ · built-in `fetch` · no deps |
39
39
  | **Sibling** | [Python package](https://github.com/nanoodlecom/nanoodle-py) (same graphs, same semantics) |
40
40
  | **Editor** | [nanoodle.com](https://nanoodle.com) — wire nodes, hit 💾, download the graph |
41
41
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanoodle",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "Run nanoodle visual AI workflows from JavaScript — zero-dependency executor for saved noodle-graph.json files",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
@@ -17,7 +17,7 @@
17
17
  "nanoodle": "./bin/nanoodle.mjs"
18
18
  },
19
19
  "engines": {
20
- "node": ">=20"
20
+ "node": "^22.23.4 || ^24.22.1 || >=26.12.1"
21
21
  },
22
22
  "scripts": {
23
23
  "test": "node --test"
package/src/client.mjs CHANGED
@@ -1,5 +1,6 @@
1
+ import { imageModelOpts } from "./image-options.mjs";
1
2
  import { NanoodleError } from "./errors.mjs";
2
- import { b64ImageMime, bytesToDataUrl, dataUrlBytes, MEDIA_INLINE_MAX } from "./media.mjs";
3
+ import { b64ImageMime, bytesToDataUrl, dataUrlBytes, redactUrl, sniffMime, MEDIA_INLINE_MAX } from "./media.mjs";
3
4
  import { assertPaymentOption, parseNanoInvoice, looksLikeResult } from "./x402.mjs";
4
5
 
5
6
  const AUDIO_MIME = { mp3: "audio/mpeg", opus: "audio/ogg", aac: "audio/aac", flac: "audio/flac", wav: "audio/wav", pcm: "audio/wav" };
@@ -260,7 +261,7 @@ export class NanoClient {
260
261
  if (prompt) body.prompt = prompt; // omit when blank — upscalers run with no instruction
261
262
  if (imageDataUrl) body.imageDataUrl = imageDataUrl; // string OR array (edit multi-reference)
262
263
  if (maskDataUrl) body.maskDataUrl = maskDataUrl; // white = repaint
263
- if (extra) Object.assign(body, extra);
264
+ Object.assign(body, imageModelOpts(extra));
264
265
  const r = await this._postJson("/v1/images/generations", body, signal);
265
266
  if (!r.ok) throw httpError(r.status, await r.text());
266
267
  const j = await r.json();
@@ -432,8 +433,14 @@ export class NanoClient {
432
433
  if (/^data:/i.test(audioUrl)) {
433
434
  ({ bytes, mime } = dataUrlBytes(audioUrl));
434
435
  } else {
435
- const r = await this.fetch(audioUrl, { signal }); // media CDN — no auth headers
436
- if (!r.ok) throw new NanoodleError("couldn't download the audio to transcribe (" + r.status + ")");
436
+ let r;
437
+ try { r = await this.fetch(audioUrl, { signal }); } // media CDN — no auth headers
438
+ catch (e) {
439
+ if (e && (e.name === "AbortError" || e.code === "aborted")) throw e;
440
+ if (signal && signal.aborted) throw e;
441
+ throw new NanoodleError("couldn't download the audio to transcribe: " + redactUrl(audioUrl));
442
+ }
443
+ if (!r.ok) throw new NanoodleError("couldn't download the audio to transcribe (" + r.status + "): " + redactUrl(audioUrl));
437
444
  bytes = new Uint8Array(await r.arrayBuffer());
438
445
  mime = ((r.headers && r.headers.get && r.headers.get("content-type")) || "audio/mpeg").split(";")[0];
439
446
  }
@@ -462,14 +469,41 @@ export class NanoClient {
462
469
  * Used when a chat audio part needs base64 bytes but the upstream node produced an https URL.
463
470
  */
464
471
  async fetchMediaDataUrl(url, { signal } = {}) {
465
- const r = await this.fetch(url, { signal });
466
- if (!r.ok) throw new NanoodleError("couldn't download media to inline (" + r.status + "): " + url);
472
+ let r;
473
+ try { r = await this.fetch(url, { signal }); }
474
+ catch (e) {
475
+ if (e && (e.name === "AbortError" || e.code === "aborted")) throw e;
476
+ if (signal && signal.aborted) throw e;
477
+ throw new NanoodleError("couldn't download media to inline: " + redactUrl(url));
478
+ }
479
+ if (!r.ok) throw new NanoodleError("couldn't download media to inline (" + r.status + "): " + redactUrl(url));
467
480
  const bytes = new Uint8Array(await r.arrayBuffer());
468
481
  const ct = (((r.headers && r.headers.get && r.headers.get("content-type")) || "").split(";")[0] || "").trim().toLowerCase();
469
482
  const mime = ct && ct !== "application/octet-stream" && ct !== "binary/octet-stream" ? ct : undefined;
470
483
  return bytesToDataUrl(bytes, mime); // sniffs magic bytes when the CDN's content-type is generic
471
484
  }
472
485
 
486
+ /**
487
+ * Resolve a provider media URL before it is handed to another node or returned
488
+ * as a node output. Relative content paths (Grok Imagine's
489
+ * `/api/generate-video/content?...`) and same-origin `/api` or `/v1` URLs are
490
+ * joined onto `baseUrl` and fetched with the API key, redirects manual so the
491
+ * key is never forwarded to the file host. A redirect Location becomes the
492
+ * absolute file URL (presigned queries stay on that URL — the next provider
493
+ * needs them — and are never put in errors). A direct 200 is inlined as a
494
+ * data URL only when it fits MEDIA_INLINE_MAX; an over-cap clip must come
495
+ * back as a redirect URL rather than failing the inline budget.
496
+ */
497
+ async resolveContentUrl(url, { signal } = {}) {
498
+ return resolveProviderMediaUrl(url, {
499
+ baseUrl: this.baseUrl,
500
+ fetch: this.fetch,
501
+ authHeaders: this._auth(),
502
+ apiKey: this.apiKey,
503
+ signal,
504
+ });
505
+ }
506
+
473
507
  /** Optional helper: POST /api/check-balance → { usd_balance }. */
474
508
  async checkBalance(signal) {
475
509
  const r = await this._postJson("/api/check-balance", {}, signal);
@@ -477,3 +511,142 @@ export class NanoClient {
477
511
  return r.json();
478
512
  }
479
513
  }
514
+
515
+ /** Paths that still need the API key (a content endpoint), not a public file. */
516
+ function isContentApiPath(pathname) {
517
+ return pathname === "/api" || pathname.startsWith("/api/")
518
+ || pathname === "/v1" || pathname.startsWith("/v1/");
519
+ }
520
+
521
+ function apiBase(baseUrl) {
522
+ const base = String(baseUrl || "https://nano-gpt.com").replace(/\/+$/, "");
523
+ const origin = new URL(base + "/").origin;
524
+ return { base, origin };
525
+ }
526
+
527
+ /** Estimated data-URL length for `byteLength` raw bytes. Matches the inline cap's string check. */
528
+ function dataUrlWouldExceed(byteLength, mime) {
529
+ const header = ("data:" + (mime || "application/octet-stream") + ";base64,").length;
530
+ return header + Math.ceil(Math.max(0, byteLength) / 3) * 4 > MEDIA_INLINE_MAX;
531
+ }
532
+
533
+ /** Drop the API key, bearer tokens, and query strings from text that may be shown. */
534
+ function scrubSecrets(text, apiKey) {
535
+ let s = String(text || "");
536
+ if (apiKey && String(apiKey).length >= 4) s = s.split(String(apiKey)).join("[redacted]");
537
+ s = s.replace(/bearer\s+\S+/gi, "Bearer [redacted]");
538
+ s = s.replace(/[?#][^\s)"']*/g, "");
539
+ s = s.replace(/(?:X-Amz-[A-Za-z-]*|Signature|sig|token|api_key|apikey)\s*[:=]\s*\S+/gi, (m) => m.split(/[:=]/)[0] + "=[redacted]");
540
+ return s.replace(/\s+/g, " ").trim().slice(0, 160);
541
+ }
542
+
543
+ function authHeadersFor(url, origin, authHeaders) {
544
+ try {
545
+ if (new URL(url).origin !== origin) return {};
546
+ } catch {
547
+ return {};
548
+ }
549
+ return authHeaders ? { ...authHeaders } : {};
550
+ }
551
+
552
+ async function drainBody(r) {
553
+ try {
554
+ if (r && r.body && typeof r.body.cancel === "function") await r.body.cancel();
555
+ else if (r && typeof r.arrayBuffer === "function") await r.arrayBuffer();
556
+ } catch { /* already consumed, or the peer hung up */ }
557
+ }
558
+
559
+ function responseMime(r) {
560
+ const ct = ((r && r.headers && r.headers.get && r.headers.get("content-type")) || "").split(";")[0].trim().toLowerCase();
561
+ if (!ct || ct === "application/octet-stream" || ct === "binary/octet-stream") return "";
562
+ return ct;
563
+ }
564
+
565
+ /**
566
+ * Resolve one provider media URL.
567
+ * - data:, blob:, and ordinary http(s) URLs pass through (no fetch, no key).
568
+ * - A path-absolute URL is joined onto the NanoGPT base. Non-API paths become
569
+ * that absolute URL and are not fetched (the next node can GET them).
570
+ * - `/api` and `/v1` URLs (relative, or already on the API origin) are fetched
571
+ * with the key and `redirect: "manual"`. An off-origin or non-API Location is
572
+ * the fetchable file URL and is returned without downloading it — so a clip
573
+ * over the ~4.4 MB inline cap still chains. A 200 body is inlined only when
574
+ * the data URL fits MEDIA_INLINE_MAX.
575
+ * Errors never include the API key or a presigned query string.
576
+ */
577
+ export async function resolveProviderMediaUrl(url, { baseUrl, fetch: fetchImpl, authHeaders, apiKey, signal } = {}) {
578
+ if (typeof url !== "string") return url;
579
+ const s = url.trim();
580
+ if (!s || /^(data:|blob:)/i.test(s)) return s;
581
+ const { base, origin } = apiBase(baseUrl);
582
+ let start;
583
+ try {
584
+ if (/^https?:/i.test(s)) {
585
+ const abs = new URL(s);
586
+ if (abs.origin !== origin || !isContentApiPath(abs.pathname)) return s;
587
+ start = abs;
588
+ } else if (s.startsWith("/") && !s.startsWith("//")) {
589
+ start = new URL(s, base + "/");
590
+ if (!isContentApiPath(start.pathname)) return start.href;
591
+ } else {
592
+ return s;
593
+ }
594
+ } catch {
595
+ return s;
596
+ }
597
+
598
+ const doFetch = fetchImpl || globalThis.fetch;
599
+ if (!doFetch) throw new NanoodleError("couldn't fetch provider media: no fetch available");
600
+ let current = start.href;
601
+ for (let hop = 0; hop < 5; hop++) {
602
+ let r;
603
+ try {
604
+ r = await doFetch(current, {
605
+ method: "GET",
606
+ headers: authHeadersFor(current, origin, authHeaders),
607
+ redirect: "manual",
608
+ signal,
609
+ });
610
+ } catch (e) {
611
+ if (e && (e.name === "AbortError" || e.code === "aborted")) throw e;
612
+ if (signal && signal.aborted) throw e;
613
+ const detail = scrubSecrets(e && e.message, apiKey);
614
+ throw new NanoodleError("couldn't fetch provider media" + (detail ? " (" + detail + ")" : ""));
615
+ }
616
+ const status = r.status;
617
+ const loc = r.headers && r.headers.get && r.headers.get("location");
618
+ if (loc && (status === 0 || (status >= 300 && status < 400))) {
619
+ await drainBody(r);
620
+ let next;
621
+ try { next = new URL(loc, current); }
622
+ catch { throw new NanoodleError("provider media redirect had no usable location"); }
623
+ // File host or a non-API path: hand back the absolute URL. Do not fetch it
624
+ // (that would pull a multi-megabyte clip and might attach the key).
625
+ if (next.origin !== origin || !isContentApiPath(next.pathname)) return next.href;
626
+ current = next.href;
627
+ continue;
628
+ }
629
+ if (status >= 300 && status < 400) {
630
+ await drainBody(r);
631
+ throw new NanoodleError("provider media redirect had no location");
632
+ }
633
+ if (!r.ok) {
634
+ const raw = String(await r.text().catch(() => "")).slice(0, 500);
635
+ const snippet = scrubSecrets(raw, apiKey);
636
+ throw new NanoodleError("couldn't fetch provider media (HTTP " + status + ")" + (snippet ? ": " + snippet : ""));
637
+ }
638
+ const mimeHeader = responseMime(r);
639
+ const declared = Number(r.headers && r.headers.get && r.headers.get("content-length"));
640
+ if (Number.isFinite(declared) && declared >= 0 && dataUrlWouldExceed(declared, mimeHeader)) {
641
+ await drainBody(r);
642
+ throw new NanoodleError("provider media is too large to send inline (~4 MB max) and did not redirect to a fetchable file");
643
+ }
644
+ const bytes = new Uint8Array(await r.arrayBuffer());
645
+ const mime = mimeHeader || sniffMime(bytes);
646
+ if (dataUrlWouldExceed(bytes.length, mime)) {
647
+ throw new NanoodleError("provider media is too large to send inline (~4 MB max) and did not redirect to a fetchable file");
648
+ }
649
+ return bytesToDataUrl(bytes, mime);
650
+ }
651
+ throw new NanoodleError("provider media redirect did not resolve to a fetchable file");
652
+ }
package/src/estimate.mjs CHANGED
@@ -163,11 +163,11 @@ function videoBaseUsd(pricing, fields, audioOn, refOn) {
163
163
  if (v != null) return v * dur;
164
164
  }
165
165
  if (audioOn) {
166
- for (const k of ["text_image_with_audio_per_second", "image_to_video_with_audio_per_second", "text_to_video_with_audio_per_second"]) {
166
+ for (const k of ["text_image_with_audio_per_second", "image_to_video_with_audio_per_second", "text_to_video_with_audio_per_second", "per_second_with_audio"]) {
167
167
  if (p[k] != null) { v = (typeof p[k] === "object") ? rp(p[k]) : _num(p[k]); if (v != null) return v * dur; }
168
168
  }
169
169
  }
170
- for (const k of ["text_to_video_per_second", "text_image_without_audio_per_second", "image_to_video_without_audio_per_second"]) {
170
+ for (const k of ["text_to_video_per_second", "text_image_without_audio_per_second", "image_to_video_without_audio_per_second", "per_second_without_audio"]) {
171
171
  if (p[k] != null) { v = (typeof p[k] === "object") ? rp(p[k]) : _num(p[k]); if (v != null) return v * dur; }
172
172
  }
173
173
  if (p.base_price_per_second != null) { const m = p.resolution_multipliers ? (rp(p.resolution_multipliers) ?? 1) : 1; v = _num(p.base_price_per_second); if (v != null) return v * dur * m; }
@@ -0,0 +1,11 @@
1
+ // Model knobs may tune generation, but cannot replace node-owned request fields
2
+ // or smuggle routing/authentication settings into an image request.
3
+ export function imageModelOpts(opts) {
4
+ const out = {};
5
+ if (!opts || typeof opts !== "object" || Array.isArray(opts)) return out;
6
+ for (const [key, value] of Object.entries(opts)) {
7
+ if (/^(?:model|prompt|size|n|responseformat|image|images|imageurl|imagedataurl|mask|maskurl|maskdataurl|key|apikey|xapikey|token|accesstoken|authorization|auth|headers|url|endpoint|baseurl|method|body|credentials|proxy|runid|requestid|isapirequest|paymentsource|paymentid|tojson|proto|prototype|constructor)$/i.test(key.replace(/[_-]/g, ""))) continue;
8
+ out[key] = value;
9
+ }
10
+ return out;
11
+ }
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { inflate, deflate } from "./zlib.mjs";
17
17
  import { NanoodleError } from "./errors.mjs";
18
- import { bytesToDataUrl, dataUrlBytes, sniffMime, MEDIA_INLINE_MAX } from "./media.mjs";
18
+ import { bytesToDataUrl, dataUrlBytes, redactUrl, sniffMime, MEDIA_INLINE_MAX } from "./media.mjs";
19
19
  import { MP4CAT } from "./mp4cat.mjs";
20
20
 
21
21
  const MAX_FRAMES = 12;
@@ -121,8 +121,13 @@ async function urlBytes(url, fetchFn) {
121
121
  if (/^https?:/i.test(u)) {
122
122
  const fetchImpl = fetchFn || globalThis.fetch;
123
123
  if (!fetchImpl) throw new NanoodleError("can't download media: no fetch available");
124
- const r = await fetchImpl(u);
125
- if (!r.ok) throw new NanoodleError(`couldn't download media (${r.status}): ${u.slice(0, 120)}`);
124
+ let r;
125
+ try { r = await fetchImpl(u); }
126
+ catch (e) {
127
+ if (e && (e.name === "AbortError" || e.code === "aborted")) throw e;
128
+ throw new NanoodleError(`couldn't download media: ${redactUrl(u)}`);
129
+ }
130
+ if (!r.ok) throw new NanoodleError(`couldn't download media (${r.status}): ${redactUrl(u)}`);
126
131
  return new Uint8Array(await r.arrayBuffer());
127
132
  }
128
133
  throw new NanoodleError("media must be a data: or http(s) URL");
package/src/media.mjs CHANGED
@@ -33,12 +33,18 @@ export function b64ImageMime(b64) {
33
33
  if (b64.startsWith("iVBOR")) return "image/png";
34
34
  if (b64.startsWith("R0lG")) return "image/gif";
35
35
  if (b64.startsWith("UklG")) return "image/webp";
36
+ // SVG may start with a BOM, XML declaration, or comments. Inspect a bounded
37
+ // prefix as text only; no XML parsing or execution.
38
+ try {
39
+ const head = atob(b64.slice(0, 8192));
40
+ if (/^(?:\xef\xbb\xbf)?\s*(?:<\?xml[^>]*>\s*)?(?:<!--[\s\S]*?-->\s*)*<svg(?:\s|\/?>)/i.test(head)) return "image/svg+xml";
41
+ } catch { /* malformed/unknown base64 keeps the raster fallback */ }
36
42
  return "image/png";
37
43
  }
38
44
 
39
45
  const EXT_MIME = {
40
46
  ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif",
41
- ".webp": "image/webp", ".bmp": "image/bmp",
47
+ ".webp": "image/webp", ".bmp": "image/bmp", ".svg": "image/svg+xml",
42
48
  ".mp3": "audio/mpeg", ".wav": "audio/wav", ".ogg": "audio/ogg", ".opus": "audio/ogg",
43
49
  ".aac": "audio/aac", ".flac": "audio/flac", ".m4a": "audio/mp4",
44
50
  ".mp4": "video/mp4", ".webm": "video/webm", ".mov": "video/quicktime", ".mkv": "video/x-matroska",
@@ -47,7 +53,7 @@ const EXT_MIME = {
47
53
  };
48
54
 
49
55
  const MIME_EXT = {
50
- "image/png": "png", "image/jpeg": "jpg", "image/gif": "gif", "image/webp": "webp",
56
+ "image/svg+xml": "svg", "image/png": "png", "image/jpeg": "jpg", "image/gif": "gif", "image/webp": "webp",
51
57
  "audio/mpeg": "mp3", "audio/wav": "wav", "audio/ogg": "ogg", "audio/aac": "aac",
52
58
  "audio/flac": "flac", "audio/mp4": "m4a",
53
59
  "video/mp4": "mp4", "video/webm": "webm", "video/quicktime": "mov",
@@ -55,6 +61,22 @@ const MIME_EXT = {
55
61
  "text/plain": "txt", "application/json": "json",
56
62
  };
57
63
 
64
+ /**
65
+ * A URL safe to put in an error or log line: origin + path only.
66
+ * Presigned query strings (and any other search/fragment) are dropped, so a
67
+ * signature or a key that rode along in the query cannot leak via an error.
68
+ */
69
+ export function redactUrl(url) {
70
+ const s = String(url || "");
71
+ try {
72
+ const u = new URL(s);
73
+ return u.origin + u.pathname;
74
+ } catch {
75
+ const cut = s.search(/[?#]/);
76
+ return (cut >= 0 ? s.slice(0, cut) : s).slice(0, 120);
77
+ }
78
+ }
79
+
58
80
  /** Best-effort file extension for a MIME type (used by the CLI --out saver). */
59
81
  export function extForMime(mime) {
60
82
  return MIME_EXT[String(mime || "").split(";")[0].trim().toLowerCase()] || "bin";
@@ -134,8 +156,14 @@ export class MediaRef {
134
156
  /** @returns {Promise<Uint8Array>} the raw media bytes (decodes data:, fetches http(s)). */
135
157
  async bytes() {
136
158
  if (this.url.startsWith("data:")) return dataUrlBytes(this.url).bytes;
137
- const r = await this._fetch(this.url);
138
- if (!r.ok) throw new NanoodleError("couldn't download media (" + r.status + "): " + this.url);
159
+ let r;
160
+ try {
161
+ r = await this._fetch(this.url);
162
+ } catch (e) {
163
+ if (e && (e.name === "AbortError" || e.code === "aborted")) throw e;
164
+ throw new NanoodleError("couldn't download media: " + redactUrl(this.url));
165
+ }
166
+ if (!r.ok) throw new NanoodleError("couldn't download media (" + r.status + "): " + redactUrl(this.url));
139
167
  if (!this._mime) {
140
168
  const ct = r.headers && r.headers.get && r.headers.get("content-type");
141
169
  if (ct) this._mime = ct.split(";")[0].trim();
package/src/nodes.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { imageModelOpts } from "./image-options.mjs";
1
2
  import { NanoodleError } from "./errors.mjs";
2
3
  import { catItem, chatModelCan, pricingAdvertisesRefs } from "./catalog.mjs";
3
4
  import { IMG_PORT_RE, EDIT_IMG_RE, REF_PORT_RE, CLIP_PORT_RE, VID_PORT_RE, optionalNode } from "./graph.mjs";
@@ -181,9 +182,11 @@ function loraKind(type) { return (type === "image" || type === "edit" || type ==
181
182
  function imageTakesLora(id) {
182
183
  id = String(id || "");
183
184
  if (/inpaint/i.test(id)) return false;
184
- // flux-2-klein-* only (lora-capable per catalog); FLUX.3 Klein (blackforestlabs/flux-3/klein/…)
185
- // takes no lora_url — twin of the app's imageTakesLora (nanoodle #732)
185
+ // twin of the app's imageTakesLora (nanoodle #732, #764): flux-2-klein-* is lora-capable;
186
+ // FLUX.3 Klein text-to-image (base + distilled) gained lora_url_1..3 in the catalog on
187
+ // 2026-10-27, but FLUX.3 Klein edit-image still takes no lora_url
186
188
  if (/flux-2-klein/i.test(id)) return true;
189
+ if (/flux-3\/klein\/(base\/)?text-to-image/i.test(id)) return true;
187
190
  if (/minimax-h3\/(text-to-image|image-edit)/i.test(id)) return true;
188
191
  return /(^|[-\/])lora($|[-\/])/i.test(id);
189
192
  }
@@ -268,7 +271,7 @@ function airModelTakesNegative(model) {
268
271
 
269
272
  /** Per-call image extras: LoRA params + fixed seed (when numeric) + custom-civitai AIR. */
270
273
  function imgExtra(n) {
271
- const e = loraParams(n);
274
+ const e = { ...imageModelOpts(n.fields.modelOpts), ...loraParams(n) };
272
275
  const s = n.fields.seed;
273
276
  if (s != null && String(s).trim() !== "" && !isNaN(Number(s))) e.seed = Number(s);
274
277
  if (n.fields.model === "custom-civitai") {
@@ -675,7 +678,8 @@ export const RUNNERS = {
675
678
  }
676
679
  }
677
680
  const prompt = promptOf(n, inp);
678
- if (!prompt && !/upscal/i.test(n.fields.model || "")) throw new NanoodleError("no edit instruction");
681
+ if (!prompt && !/upscal/i.test(n.fields.model || "")
682
+ && !(n.fields.model === "ideogram/vector" && n.fields.modelOpts?.vector_operation === "convert")) throw new NanoodleError("no edit instruction");
679
683
  imgs = await Promise.all(imgs.map((u) => fitImage(u, ctx, "source image")));
680
684
  guardRefsSize(imgs);
681
685
  const src = imgs.length > 1 ? imgs : imgs[0]; // array → multi-image composite; string → single edit
@@ -717,7 +721,12 @@ export const RUNNERS = {
717
721
  const prompt = promptOf(n, inp);
718
722
  const opts = { ...videoSourceOpts(inp.video), ...videoDims(n, ctx), lora: loraParams(n), extra: n.fields.modelOpts || {} };
719
723
  applyRefs(opts, collectPorts(inp, REF_PORT_RE), n, ctx); // ref wires (seedance video-edit family) — same key/cap resolution as tvideo
720
- return { video: await ctx.video(mdl(n), prompt, opts, null) };
724
+ // Character image (image+video->video motion-control / replace models, e.g. Wan 2.2 Animate):
725
+ // the wired still rides as imageDataUrl next to the driver video. Gated on the catalog so a
726
+ // stale wire left after a swap to a plain v2v model is never sent; catalog miss → send (the
727
+ // wire was authored deliberately, same permissive-ON stance as ivideo's endframe).
728
+ const image = inp.image && vEditTakesImage(ctx && ctx.catalog, n.fields.model) ? await fitImage(inp.image, ctx, "character image") : null;
729
+ return { video: await ctx.video(mdl(n), prompt, opts, image) };
721
730
  },
722
731
 
723
732
  async lipsync(n, inp, ctx) {
@@ -849,6 +858,18 @@ export const RUNNERS = {
849
858
  * HeyGen Avatar V). Catalog miss → true (the long-standing portrait requirement).
850
859
  * Mirrors play's built-in lipsync runner: raw `capabilities.image_to_video` or a normalized `i2v`.
851
860
  */
861
+ // Video-edit models that take a character/reference still AND a driver video but no text prompt
862
+ // (architecture image+video->video: Wan 2.2 Animate replace/animate, Kling / PixVerse motion
863
+ // control, P-Video Animate). Text+image+video "unified" models are excluded: for them an image
864
+ // usually switches the job to image→video and drops the source clip. Catalog miss → true.
865
+ export function vEditTakesImage(catalog, model) {
866
+ const m = catItem(catalog, "video", model);
867
+ if (!m) return true;
868
+ const a = m.architecture || {};
869
+ const mods = Array.isArray(a.input_modalities) ? a.input_modalities : String(a.modality || "").split("->")[0].split("+");
870
+ return mods.includes("image") && mods.includes("video") && !mods.includes("text");
871
+ }
872
+
852
873
  function avatarNeedsPortrait(catalog, model) {
853
874
  const m = catItem(catalog, "video", model);
854
875
  return !m || !!((m.capabilities || {}).image_to_video) || !!m.i2v;
package/src/workflow.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { NanoodleError, RunError, UnsupportedNodeError } from "./errors.mjs";
2
2
  import { NODE_TYPES, displayName, isInputPort, lockedNode, materialize, topoSort, wiredFramesFloor, MAX_FRAMES } from "./graph.mjs";
3
+ import { endpointOutPort } from "./endpoint.mjs";
3
4
  import { deriveInputs, deriveOutputs, deriveSettings, resolveInputKey, resolveSettingKey } from "./io.mjs";
4
5
  import { NanoClient } from "./client.mjs";
5
6
  import { MediaRef, coerceMediaInput } from "./media.mjs";
@@ -27,6 +28,68 @@ function warnGraph(msg) {
27
28
  }
28
29
 
29
30
  const MEDIA_KINDS = new Set(["image", "audio", "video", "inpaint"]);
31
+ /** Ports whose value is media a later node will fetch or inline. */
32
+ const HANDED_MEDIA_PORT = /^(?:video|audio|image|mask|endframe|model)$|^(?:img|image|vid|clip|ref|frame)\d+$/;
33
+ const MEDIA_OUT_TYPES = new Set(["image", "audio", "video", "model3d"]);
34
+
35
+ function mediaOutputKeys(node, out) {
36
+ const keys = [];
37
+ const add = (k) => { if (k && !keys.includes(k)) keys.push(k); };
38
+ if (!out || typeof out !== "object") return keys;
39
+ if (node.type === "endpoint") {
40
+ const p = endpointOutPort(node);
41
+ if (p && MEDIA_OUT_TYPES.has(p.type)) add(p.name);
42
+ } else if (node.type === "vframes") {
43
+ for (const k of Object.keys(out)) if (/^frame\d+$/.test(k)) add(k);
44
+ } else {
45
+ const spec = NODE_TYPES[node.type];
46
+ for (const p of (spec && spec.outputs) || []) {
47
+ if (MEDIA_OUT_TYPES.has(p.type)) add(p.name);
48
+ }
49
+ }
50
+ if (Array.isArray(out.images)) add("images");
51
+ return keys;
52
+ }
53
+
54
+ /**
55
+ * Resolve provider-relative content URLs on a node's media outputs before they
56
+ * are stored or wired onward. One fetch per distinct URL (image + images[]).
57
+ */
58
+ async function publishNodeMedia(client, node, out, signal) {
59
+ if (!out || typeof out !== "object" || Array.isArray(out)) return out;
60
+ const keys = mediaOutputKeys(node, out);
61
+ if (!keys.length) return out;
62
+ const cache = new Map();
63
+ const resolve = async (value) => {
64
+ if (typeof value === "string") {
65
+ if (!value) return value;
66
+ if (cache.has(value)) return cache.get(value);
67
+ const resolved = await client.resolveContentUrl(value, { signal });
68
+ cache.set(value, resolved);
69
+ return resolved;
70
+ }
71
+ if (Array.isArray(value)) {
72
+ let changed = false;
73
+ const next = [];
74
+ for (const item of value) {
75
+ const r = await resolve(item);
76
+ if (r !== item) changed = true;
77
+ next.push(r);
78
+ }
79
+ return changed ? next : value;
80
+ }
81
+ return value;
82
+ };
83
+ let copy = null;
84
+ for (const k of keys) {
85
+ const resolved = await resolve(out[k]);
86
+ if (resolved !== out[k]) {
87
+ if (!copy) copy = { ...out };
88
+ copy[k] = resolved;
89
+ }
90
+ }
91
+ return copy || out;
92
+ }
30
93
 
31
94
  function abortReason(signal) {
32
95
  const r = signal && signal.reason;
@@ -339,7 +402,14 @@ export class Workflow {
339
402
  continue;
340
403
  }
341
404
  const v = srcOut[l.from.port];
342
- if (isInputPort(n, l.to.port)) inp[l.to.port] = v;
405
+ if (isInputPort(n, l.to.port)) {
406
+ // Node boundary: a relative content URL from the upstream provider is
407
+ // resolved (authed redirect → absolute file URL, or inlined bytes)
408
+ // before this node builds videoUrl / videoDataUrl / audio / image.
409
+ inp[l.to.port] = (typeof v === "string" && v && HANDED_MEDIA_PORT.test(l.to.port))
410
+ ? await this.client.resolveContentUrl(v, { signal: ac.signal })
411
+ : v;
412
+ }
343
413
  // Custom endpoint url/mode: a Choice path like "/post" must ride inp so
344
414
  // endpointResolveTarget can join it onto the typed host. Overwriting
345
415
  // fields.url with "/post" rejects the joined URL.
@@ -401,10 +471,15 @@ export class Workflow {
401
471
  });
402
472
  deadline.catch(() => {});
403
473
  }
404
- const work = RUNNERS[n.type]({ ...n, fields }, inp, ctxFor(n, rec, nodeSignal));
405
- const out = deadline ? await Promise.race([work, deadline]) : await work;
474
+ const nodeForRun = { ...n, fields };
475
+ const work = RUNNERS[n.type](nodeForRun, inp, ctxFor(n, rec, nodeSignal));
476
+ const rawOut = deadline ? await Promise.race([work, deadline]) : await work;
406
477
  if (deadline) throwIfAborted(nodeSignal);
407
478
  throwIfAborted(ac.signal);
479
+ // Final outputs of this node are absolute usable URLs, not the relative
480
+ // content path the provider returned. Downstream reads this same object.
481
+ const out = await publishNodeMedia(this.client, nodeForRun, rawOut, nodeSignal);
482
+ throwIfAborted(ac.signal);
408
483
  rec.final = true;
409
484
  rec.status = "done";
410
485
  rec.out = out;