nanoodle 0.9.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
 
@@ -188,6 +188,38 @@ result.get("Image") // throws NanoodleError code "gated": the gate "Decide" an
188
188
  the CLI exits 0 with `gated` in its JSON summary. A node fed by both a closed
189
189
  gate and a real failure is still an error.
190
190
 
191
+ ### Per-node timeout, skip on failure, locked nodes
192
+
193
+ Three optional keys inside a node's `fields` (saved with the graph, no format change):
194
+
195
+ - **`timeoutMs`**: a deadline for this node alone. The node gets its own abort
196
+ signal, linked to the run's, and fails with a `NanoodleError` of code
197
+ `"timeout"` (`result.errors[i].code === "timeout"`). The run-level
198
+ `run(inputs, { timeoutMs })` still applies on top.
199
+ - **`onError: "skip"`**: if the node fails or times out, it gets
200
+ `status: "skipped"` (with `error`), the failure is still recorded in
201
+ `result.errors`, and progress emits `node-skipped` with `reason: "error"`.
202
+ Its ports come out `undefined`, so dependents just ignore it: a `join` keeps
203
+ the surviving inputs, and a decider reads only the writers that finished. A
204
+ node whose **every** input was skipped fails with "all inputs were skipped
205
+ after failing", and the run still fails if a non-skipped output fails or if
206
+ every output was skipped. A run-level abort is never skipped.
207
+ A network node that started but was skipped, timed out or aborted without
208
+ reporting a price makes `result.costExact` false. Once a node is finalized
209
+ (and once the run settles), late cost, progress or output callbacks from a
210
+ runner that ignored its abort signal are ignored, so `result.nodes` and the
211
+ cost totals don't change afterwards.
212
+ - **`locked: true`**: none of the node's fields become inputs (`wf.inputs`,
213
+ CLI `--input`, MCP tool args). An input key aimed at a locked field is
214
+ rejected, and so is any `run(…, { settings })` override that targets the
215
+ locked node (`NanoodleError` code `"locked"`). Inputs and settings can't
216
+ change a locked node's stored fields. Wires into its ports still deliver
217
+ data as usual, and editing the graph file itself still changes it.
218
+
219
+ ```js
220
+ { id: "w1", type: "llm", fields: { model: "…", system: "…", timeoutMs: 60000, onError: "skip", locked: true } }
221
+ ```
222
+
191
223
  ### Prompt length caps
192
224
 
193
225
  Many image and video models reject an over-long prompt at NanoGPT's route
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanoodle",
3
- "version": "0.9.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" };
@@ -159,6 +160,27 @@ export class NanoClient {
159
160
  });
160
161
  if (cr.ok) {
161
162
  const ct = ((cr.headers && cr.headers.get && cr.headers.get("content-type")) || "");
163
+ const mime = ct.split(";")[0].trim().toLowerCase();
164
+ // A binary 2xx IS the replayed result: TTS (/api/v1/audio/speech) replays raw audio bytes,
165
+ // typed audio/* or a generic application/octet-stream. It's the only paid call that answers
166
+ // binary — images, video, chat and decisions all answer JSON — so image/* and video/* are
167
+ // not accepted here. The payment is now completed and can't be reused, so dropping this
168
+ // body and re-POSTing only gets a 402.
169
+ if (mime.startsWith("audio/") || mime === "application/octet-stream") {
170
+ return { paymentId: invoice.paymentId, statusUrl: invoice.statusUrl, response: cr };
171
+ }
172
+ // Any other non-JSON 2xx (a text/plain settlement ack, a text/html error page) is neither
173
+ // the result nor a settle receipt we can act on. The complete call may already have
174
+ // consumed the payment, so re-POSTing could get a second 402 and paying again would
175
+ // double-charge: fail with the payment id instead. No second payment, no re-POST.
176
+ if (mime && !mime.includes("json")) {
177
+ const snippet = String(await cr.text().catch(() => "")).replace(/\s+/g, " ").trim().slice(0, 160);
178
+ throw new NanoodleError(
179
+ "payment " + invoice.paymentId + " was sent, but the complete call answered HTTP " + cr.status +
180
+ " with " + mime + " instead of a result" + (snippet ? " (" + snippet + ")" : "") +
181
+ " — check " + (invoice.statusUrl || "the payment status") + " before paying again",
182
+ { code: "x402", status: cr.status, paymentId: invoice.paymentId });
183
+ }
162
184
  let cj = null;
163
185
  if (ct.includes("json")) { try { cj = await cr.json(); } catch { /* treat as settle-only */ } }
164
186
  if (looksLikeResult(cj)) {
@@ -239,7 +261,7 @@ export class NanoClient {
239
261
  if (prompt) body.prompt = prompt; // omit when blank — upscalers run with no instruction
240
262
  if (imageDataUrl) body.imageDataUrl = imageDataUrl; // string OR array (edit multi-reference)
241
263
  if (maskDataUrl) body.maskDataUrl = maskDataUrl; // white = repaint
242
- if (extra) Object.assign(body, extra);
264
+ Object.assign(body, imageModelOpts(extra));
243
265
  const r = await this._postJson("/v1/images/generations", body, signal);
244
266
  if (!r.ok) throw httpError(r.status, await r.text());
245
267
  const j = await r.json();
@@ -411,8 +433,14 @@ export class NanoClient {
411
433
  if (/^data:/i.test(audioUrl)) {
412
434
  ({ bytes, mime } = dataUrlBytes(audioUrl));
413
435
  } else {
414
- const r = await this.fetch(audioUrl, { signal }); // media CDN — no auth headers
415
- 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));
416
444
  bytes = new Uint8Array(await r.arrayBuffer());
417
445
  mime = ((r.headers && r.headers.get && r.headers.get("content-type")) || "audio/mpeg").split(";")[0];
418
446
  }
@@ -441,14 +469,41 @@ export class NanoClient {
441
469
  * Used when a chat audio part needs base64 bytes but the upstream node produced an https URL.
442
470
  */
443
471
  async fetchMediaDataUrl(url, { signal } = {}) {
444
- const r = await this.fetch(url, { signal });
445
- 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));
446
480
  const bytes = new Uint8Array(await r.arrayBuffer());
447
481
  const ct = (((r.headers && r.headers.get && r.headers.get("content-type")) || "").split(";")[0] || "").trim().toLowerCase();
448
482
  const mime = ct && ct !== "application/octet-stream" && ct !== "binary/octet-stream" ? ct : undefined;
449
483
  return bytesToDataUrl(bytes, mime); // sniffs magic bytes when the CDN's content-type is generic
450
484
  }
451
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
+
452
507
  /** Optional helper: POST /api/check-balance → { usd_balance }. */
453
508
  async checkBalance(signal) {
454
509
  const r = await this._postJson("/api/check-balance", {}, signal);
@@ -456,3 +511,142 @@ export class NanoClient {
456
511
  return r.json();
457
512
  }
458
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; }
package/src/graph.mjs CHANGED
@@ -90,6 +90,12 @@ export function optionalNode(node) {
90
90
  return v === true || v === "true";
91
91
  }
92
92
 
93
+ /** Author-locked node: fields.locked keeps every field at its stored value (no inputs derived). */
94
+ export function lockedNode(node) {
95
+ const v = node && node.fields && node.fields.locked;
96
+ return v === true || v === "true";
97
+ }
98
+
93
99
  /** Is a wire landing on `port` of `node` a data input (vs a field override)? */
94
100
  export function isInputPort(node, port) {
95
101
  const t = NODE_TYPES[node.type];
@@ -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
+ }
package/src/io.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NanoodleError } from "./errors.mjs";
2
- import { NODE_TYPES, displayName, optionalNode, topoSort, wiredFramesFloor, MAX_FRAMES } from "./graph.mjs";
2
+ import { NODE_TYPES, displayName, lockedNode, optionalNode, topoSort, wiredFramesFloor, MAX_FRAMES } from "./graph.mjs";
3
3
  import { endpointOutPort } from "./endpoint.mjs";
4
4
 
5
5
  /* ============================== INPUTS ============================== */
@@ -41,6 +41,9 @@ export function deriveInputs(graph) {
41
41
  };
42
42
  for (const n of graph.nodes) {
43
43
  if (n.unknown) continue;
44
+ // fields.locked: the node's fields are fixed by the graph — never surfaced as inputs,
45
+ // so runs use the stored values.
46
+ if (lockedNode(n)) continue;
44
47
  if (n.type === "inpaint") {
45
48
  if (!fed(n.id, "prompt")) entries.push(mk(n, "prompt", "What to paint in", "textarea", false));
46
49
  // image and/or mask surface whenever not wired (SPEC-io). The app's combined brush widget
@@ -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,7 +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
- if (/klein/i.test(id)) return true;
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
188
+ if (/flux-2-klein/i.test(id)) return true;
189
+ if (/flux-3\/klein\/(base\/)?text-to-image/i.test(id)) return true;
185
190
  if (/minimax-h3\/(text-to-image|image-edit)/i.test(id)) return true;
186
191
  return /(^|[-\/])lora($|[-\/])/i.test(id);
187
192
  }
@@ -266,7 +271,7 @@ function airModelTakesNegative(model) {
266
271
 
267
272
  /** Per-call image extras: LoRA params + fixed seed (when numeric) + custom-civitai AIR. */
268
273
  function imgExtra(n) {
269
- const e = loraParams(n);
274
+ const e = { ...imageModelOpts(n.fields.modelOpts), ...loraParams(n) };
270
275
  const s = n.fields.seed;
271
276
  if (s != null && String(s).trim() !== "" && !isNaN(Number(s))) e.seed = Number(s);
272
277
  if (n.fields.model === "custom-civitai") {
@@ -673,7 +678,8 @@ export const RUNNERS = {
673
678
  }
674
679
  }
675
680
  const prompt = promptOf(n, inp);
676
- 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");
677
683
  imgs = await Promise.all(imgs.map((u) => fitImage(u, ctx, "source image")));
678
684
  guardRefsSize(imgs);
679
685
  const src = imgs.length > 1 ? imgs : imgs[0]; // array → multi-image composite; string → single edit
@@ -715,11 +721,21 @@ export const RUNNERS = {
715
721
  const prompt = promptOf(n, inp);
716
722
  const opts = { ...videoSourceOpts(inp.video), ...videoDims(n, ctx), lora: loraParams(n), extra: n.fields.modelOpts || {} };
717
723
  applyRefs(opts, collectPorts(inp, REF_PORT_RE), n, ctx); // ref wires (seedance video-edit family) — same key/cap resolution as tvideo
718
- 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) };
719
730
  },
720
731
 
721
732
  async lipsync(n, inp, ctx) {
722
- if (!inp.image) throw new NanoodleError("no image input");
733
+ // Portrait required only for image_to_video avatars. Preset-only talking avatars (audio→video,
734
+ // catalog image_to_video false — e.g. HeyGen Avatar V) run from the preset + audio alone, and a
735
+ // wired image is NOT forwarded. Catalog miss / no catalog keeps the portrait requirement.
736
+ // Twin of play's built-in lipsync runner (nanoodle #733).
737
+ const needsPortrait = avatarNeedsPortrait(ctx && ctx.catalog, String((n.fields && n.fields.model) || "").trim());
738
+ if (needsPortrait && !inp.image) throw new NanoodleError("no image input");
723
739
  if (!inp.audio) throw new NanoodleError("no audio input");
724
740
  const prompt = promptOf(n, inp);
725
741
  // Avatar models cap audio length (LongCat = 30s) and the cap isn't reliably in the catalog,
@@ -731,7 +747,7 @@ export const RUNNERS = {
731
747
  // ctx.trimAudio lets a browser host inject its Web Audio trimmer so the retry bytes match
732
748
  // its built-in runner exactly; default is the local-media trimmer (pure-JS WAV, ffmpeg).
733
749
  const trim = ctx.trimAudio || ((url, start, len, rate) => trimAudioToWav(url, start, len, rate, mediaOpts(ctx)));
734
- const img = await fitImage(inp.image, ctx, "portrait image");
750
+ const img = needsPortrait ? await fitImage(inp.image, ctx, "portrait image") : null;
735
751
  let trimSec = null;
736
752
  for (let attempt = 0; attempt < 2; attempt++) {
737
753
  let opts;
@@ -836,6 +852,29 @@ export const RUNNERS = {
836
852
  },
837
853
  };
838
854
 
855
+ /**
856
+ * Does this avatar/lipsync model need a portrait image? True unless the model is in the
857
+ * opt-in catalog and is preset-only (no image_to_video — audio→video talking avatars such as
858
+ * HeyGen Avatar V). Catalog miss → true (the long-standing portrait requirement).
859
+ * Mirrors play's built-in lipsync runner: raw `capabilities.image_to_video` or a normalized `i2v`.
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
+
873
+ function avatarNeedsPortrait(catalog, model) {
874
+ const m = catItem(catalog, "video", model);
875
+ return !m || !!((m.capabilities || {}).image_to_video) || !!m.i2v;
876
+ }
877
+
839
878
  // Image→3D (Tripo) takes a photo only. Hunyuan Rapid takes text and an optional image.
840
879
  // Anything else, including a catalog miss, accepts either — the editor's same fallback.
841
880
  const MODEL3D_IMAGE_DEFAULT = "tripo3d/v2.5";
package/src/workflow.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { NanoodleError, RunError, UnsupportedNodeError } from "./errors.mjs";
2
- import { NODE_TYPES, displayName, isInputPort, materialize, topoSort, wiredFramesFloor, MAX_FRAMES } from "./graph.mjs";
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;
@@ -195,6 +258,13 @@ export class Workflow {
195
258
  const settingAssignments = [];
196
259
  for (const [key, value] of Object.entries(settings)) {
197
260
  const entry = resolveSettingKey(graph, this.settings, key);
261
+ const target = graph.nodes.find((x) => x.id === entry.nodeId);
262
+ if (lockedNode(target)) {
263
+ throw new NanoodleError(
264
+ `setting "${key}" targets locked node ${entry.nodeId} (${displayName(target)}) — ` +
265
+ `a locked node always runs with its stored fields, so settings can't override ${entry.nodeId}.${entry.field}`,
266
+ { code: "locked" });
267
+ }
198
268
  settingAssignments.push({ entry, value });
199
269
  }
200
270
 
@@ -273,15 +343,19 @@ export class Workflow {
273
343
  const promises = new Map();
274
344
  const mediaFetch = this.client.fetch;
275
345
 
276
- const ctxFor = (node, rec) => {
346
+ // Once a node is finalized (done / skipped / error) or the run has settled, late
347
+ // callbacks from a runner that ignored its abort signal must not mutate anything.
348
+ let runSettled = false;
349
+ const frozen = (rec) => runSettled || rec.final === true;
350
+ const ctxFor = (node, rec, nodeSignal = ac.signal) => {
277
351
  const onCost = (c) => {
278
- if (!c) return;
352
+ if (!c || frozen(rec)) return;
279
353
  if (c.usd != null) { rec.costUsd = (rec.costUsd || 0) + c.usd; cost.total += c.usd; }
280
354
  else cost.exact = false;
281
355
  if (c.balance != null) cost.balance = c.balance;
282
356
  };
283
- const onPoll = (info) => emit({ type: "poll", nodeId: node.id, name: displayName(node), ...info });
284
- const io = { onCost, onPoll, signal: ac.signal };
357
+ const onPoll = (info) => frozen(rec) ? undefined : emit({ type: "poll", nodeId: node.id, name: displayName(node), ...info });
358
+ const io = { onCost, onPoll, signal: nodeSignal };
285
359
  return {
286
360
  chat: (messages, model, opts) => this.client.chat(messages, model, opts, io),
287
361
  decide: (body) => this.client.decide(body, io),
@@ -292,9 +366,9 @@ export class Workflow {
292
366
  fetchMedia: (url) => this.client.fetchMediaDataUrl(url, io),
293
367
  // local media (resize/combine/…) — same fetch + signal as network I/O
294
368
  fetch: mediaFetch,
295
- signal: ac.signal,
369
+ signal: nodeSignal,
296
370
  catalog: this.catalog,
297
- progress: (msg) => emit({ type: "node-progress", nodeId: node.id, name: displayName(node), message: msg }),
371
+ progress: (msg) => frozen(rec) ? undefined : emit({ type: "node-progress", nodeId: node.id, name: displayName(node), message: msg }),
298
372
  };
299
373
  };
300
374
 
@@ -309,22 +383,33 @@ export class Workflow {
309
383
  };
310
384
  const execNode = async (n) => {
311
385
  const rec = nodesRec[n.id];
386
+ let nodeTimer = null, unlinkNode = null;
312
387
  try {
313
388
  throwIfAborted(ac.signal);
314
389
  const inbound = graph.links.filter((l) => l.to.node === n.id);
315
390
  const inp = {};
316
391
  let fields = effFields.get(n.id);
317
- let upstreamFail = null, gatedBy = null;
392
+ let upstreamFail = null, gatedBy = null, skippedIn = 0;
318
393
  for (const l of inbound) {
319
394
  let srcOut;
320
- try { srcOut = await promises.get(l.from.node); }
395
+ try {
396
+ srcOut = await promises.get(l.from.node);
397
+ if (nodesRec[l.from.node] && nodesRec[l.from.node].skippedOnError) { skippedIn++; continue; }
398
+ }
321
399
  catch {
322
400
  const g = gateOf(l.from.node);
323
401
  if (g) { if (!gatedBy) gatedBy = g; } else if (!upstreamFail) upstreamFail = displayName(byId.get(l.from.node));
324
402
  continue;
325
403
  }
326
404
  const v = srcOut[l.from.port];
327
- 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
+ }
328
413
  // Custom endpoint url/mode: a Choice path like "/post" must ride inp so
329
414
  // endpointResolveTarget can join it onto the typed host. Overwriting
330
415
  // fields.url with "/post" rejects the joined URL.
@@ -337,6 +422,12 @@ export class Workflow {
337
422
  }
338
423
  // a real failure upstream wins over a gate (the browser runners agree): that is an error
339
424
  if (upstreamFail) throw new NanoodleError("upstream failed: " + upstreamFail);
425
+ // onError:"skip" upstreams leave their ports undefined (ignored above). A node whose
426
+ // EVERY wire comes from a skipped node has nothing left to work with — fail clearly.
427
+ if (inbound.length && skippedIn === inbound.length) {
428
+ throw new NanoodleError("all inputs were skipped after failing: " +
429
+ [...new Set(inbound.map((l) => displayName(byId.get(l.from.node))))].join(", "));
430
+ }
340
431
  if (gatedBy) {
341
432
  rec.status = "skipped";
342
433
  rec.gatedBy = gatedBy;
@@ -352,6 +443,7 @@ export class Workflow {
352
443
  // and report it below. The graph's own prompts are never rewritten to avoid this.
353
444
  const fit = withFittedPrompt(n, fields, { catalog: this.catalog, learned: this._promptCaps });
354
445
  fields = fit.fields;
446
+ rec.started = true;
355
447
  emit({ type: "node-start", nodeId: n.id, name: displayName(n) });
356
448
  // A fitted prompt changed what this run pays for — never silent, even headless.
357
449
  if (fit.trimmed) {
@@ -360,14 +452,42 @@ export class Workflow {
360
452
  `${fields.model} rejects prompts over ${fit.trimmed.cap}`);
361
453
  }
362
454
  const t0 = Date.now();
363
- const out = await RUNNERS[n.type]({ ...n, fields }, inp, ctxFor(n, rec));
455
+ // Per-node timeout (fields.timeoutMs): a child controller linked to the run signal.
456
+ // The race guarantees the deadline even if a runner never observes its signal.
457
+ const timeoutMs = Number(fields.timeoutMs);
458
+ let nodeSignal = ac.signal, deadline = null;
459
+ if (Number.isFinite(timeoutMs) && timeoutMs > 0) {
460
+ const nac = new AbortController();
461
+ const onRunAbort = () => nac.abort(ac.signal.reason);
462
+ ac.signal.addEventListener("abort", onRunAbort, { once: true });
463
+ unlinkNode = () => ac.signal.removeEventListener("abort", onRunAbort);
464
+ nodeSignal = nac.signal;
465
+ deadline = new Promise((_, reject) => {
466
+ nodeTimer = setTimeout(() => {
467
+ const err = new NanoodleError(`node timed out after ${timeoutMs}ms`, { code: "timeout" });
468
+ nac.abort(err);
469
+ reject(err);
470
+ }, timeoutMs);
471
+ });
472
+ deadline.catch(() => {});
473
+ }
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;
477
+ if (deadline) throwIfAborted(nodeSignal);
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);
364
482
  throwIfAborted(ac.signal);
483
+ rec.final = true;
365
484
  rec.status = "done";
366
485
  rec.out = out;
367
486
  rec.ms = Date.now() - t0;
368
487
  emit({ type: "node-done", nodeId: n.id, name: displayName(n), ms: rec.ms, costUsd: rec.costUsd });
369
488
  return out;
370
489
  } catch (e) {
490
+ rec.final = true;
371
491
  if (e instanceof GateSkip) throw e;
372
492
  // ⚖️ Decide gate answered no: a settled, billed decision — not an error. Downstream skips.
373
493
  if (e && e.gate === true && !ac.signal.aborted) {
@@ -384,11 +504,24 @@ export class Workflow {
384
504
  if (learnPromptCap(this._promptCaps, n, e.message)) {
385
505
  e.message = e.message + " — noted: nanoodle keeps this model's prompt inside that limit from now on, so running again should succeed";
386
506
  }
387
- rec.status = "error";
388
507
  rec.error = e.message;
389
- errors.push({ nodeId: n.id, name: displayName(n), message: e.message });
508
+ errors.push({ nodeId: n.id, name: displayName(n), message: e.message, ...(e && e.code ? { code: e.code } : {}) });
509
+ // fields.onError:"skip" — a failed (or timed-out) node is recorded and skipped; its
510
+ // dependents see undefined ports. A run-level abort/timeout is never skipped.
511
+ const onError = (effFields.get(n.id) || {}).onError;
512
+ if (onError === "skip" && !ac.signal.aborted) {
513
+ rec.status = "skipped";
514
+ rec.skippedOnError = true;
515
+ rec.out = {};
516
+ emit({ type: "node-skipped", nodeId: n.id, name: displayName(n), reason: "error", error: e.message });
517
+ return {};
518
+ }
519
+ rec.status = "error";
390
520
  emit({ type: "node-error", nodeId: n.id, name: displayName(n), error: e.message });
391
521
  throw e;
522
+ } finally {
523
+ if (nodeTimer) clearTimeout(nodeTimer);
524
+ if (unlinkNode) unlinkNode();
392
525
  }
393
526
  };
394
527
 
@@ -400,10 +533,19 @@ export class Workflow {
400
533
  }
401
534
  await Promise.allSettled([...promises.values()]);
402
535
  } finally {
536
+ runSettled = true;
403
537
  if (timer) clearTimeout(timer);
404
538
  if (signal) signal.removeEventListener("abort", onOuterAbort);
405
539
  }
406
540
 
541
+ // A network node that started but was skipped, timed out or aborted without ever reporting
542
+ // a price may still have been billed: the total can't be exact.
543
+ for (const n of order) {
544
+ const rec = nodesRec[n.id];
545
+ const t = NODE_TYPES[n.type];
546
+ if (!rec || !rec.started || rec.status === "done" || rec.costUsd != null || (t && t.local)) continue;
547
+ cost.exact = false;
548
+ }
407
549
  // ---- result ----
408
550
  const outputsMap = {};
409
551
  for (const o of this.outputs) {
@@ -460,6 +602,12 @@ export class Workflow {
460
602
  }
461
603
  throw new RunError("run failed — " + detail, result);
462
604
  }
605
+ // onError:"skip" never makes a run succeed with nothing: if every output skipped, fail.
606
+ const skippedSinks = this.outputs.filter((o) => nodesRec[o.nodeId] && nodesRec[o.nodeId].skippedOnError);
607
+ if (this.outputs.length && skippedSinks.length === this.outputs.length) {
608
+ throw new RunError("run failed — every output was skipped after failing: " +
609
+ skippedSinks.map((o) => `"${o.key}": ${nodesRec[o.nodeId].error}`).join("; "), result);
610
+ }
463
611
  return result;
464
612
  }
465
613