nanoodle 0.13.0 → 0.13.3

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 22.23.4+, 24.22.1+, or 26.12.1+ · built-in `fetch` · no deps |
38
+ | **Runtime** | Node 22.23.5+, 24.22.3+, or 26.13.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
 
@@ -115,7 +115,7 @@ unrecoverable.
115
115
  ```js
116
116
  wf.inputs // [{ key: "Text", nodeId: "n1", field: "text", kind: "textarea", optional: false, def: "..." }]
117
117
  wf.outputs // [{ key: "Image", nodeId: "n3", type: "image", ports: [{ name: "image", type: "image" }] }]
118
- wf.settings // [{ key: "n3.model", kind: "model", def: "nano-banana-2-lite" }, ...]
118
+ wf.settings // [{ key: "n3.model", kind: "model", def: "nano-banana-2-fast" }, ...]
119
119
  ```
120
120
 
121
121
  Input keys are flexible (case-insensitive): the node’s custom name (`"Text"`),
@@ -250,6 +250,24 @@ The pieces are exported if you orchestrate graphs yourself:
250
250
  `promptCap`, `fitPromptText`, `isPromptTooLong`, `promptCapFromError`,
251
251
  `PROMPT_CAPS`.
252
252
 
253
+ ### Conditional Decide branches
254
+
255
+ A saved node with `type: "decide-branch"` uses the Decide model and question with a typed
256
+ yes/no answer. Wire its `yes` and `no` ports to the corresponding branch entries. The
257
+ selected port forwards the input text, or the answer if no text was supplied. Ordinary
258
+ `text` and `image` outputs remain data outputs.
259
+
260
+ Branch nodes and their downstream work start only after their controls resolve. A shared
261
+ prerequisite can run once and feed both branches. A join runs when any of its routed
262
+ inputs is active and receives only active inputs. An invalid or missing answer fails the
263
+ decision and opens neither port. Skipped branch nodes have `status: "skipped"` and
264
+ `skipReason: "branch"`. They contribute no provider cost. A legacy `decide` node and its
265
+ optional yes/no gate retain their existing behavior.
266
+
267
+ Use an executor that supports `decide-branch` for new branch graphs. The
268
+ [shared offline fixture](tests/fixtures/decider-branches.json) covers both picks, nested
269
+ decisions, joins, retries, and an existing gate.
270
+
253
271
  ## Supported nodes
254
272
 
255
273
  | runs | node types |
@@ -298,6 +316,43 @@ generation.
298
316
  - `result.costUsd` — total of prices NanoGPT returned
299
317
  - `result.costExact` — `false` if any call omitted a price (total is then a floor)
300
318
  - `result.remainingBalance` — freshest balance the API reported
319
+ - `result.nodes[nodeId].runId` — provider job ID for async video, 3D, and audio
320
+ jobs, or `null`. Available on failures too through `RunError.result`; an
321
+ `onProgress` event `{ type: "node-run-id", nodeId, name, runId }` reports it
322
+ immediately after submit, before polling.
323
+
324
+ `estimateGraphCost()` follows recognized per-model billing contracts in the
325
+ NanoGPT catalog. Explicit whole-second contracts round up and apply their
326
+ billable-duration bounds; P-Video Upscale also applies its documented frame cap
327
+ and output-FPS rate. Fractional and unspecified per-second contracts preserve
328
+ fractions. Flat, frame, and explicit billing-interval prices retain their own
329
+ units. Audio/video estimates remain forecasts: the provider verifies source
330
+ media duration, and actual generated duration and pricing can differ.
331
+ Input-video-second pricing (such as LTX 2.5 Reframe) uses the wired source
332
+ node's `fields.duration` as a seconds hint. With no positive source-duration hint,
333
+ it counts that node as `unpriced`; the returned USD is only a subtotal. The
334
+ estimator never downloads media to measure it.
335
+
336
+ Hosted media downloads (`MediaRef.bytes()` / `.save()` and media inputs) retry
337
+ connection or response-body interruptions up to three total GET attempts. Final
338
+ failures are `NanoodleError`s with signed URL queries omitted. HTTP rejections
339
+ and cancellation stop immediately. Generation requests are never retried by
340
+ this download policy.
341
+
342
+ `MediaRef.save("splat")` adds the detected media extension and returns the actual
343
+ saved path (for example, `splat.ply`). An explicit filename extension is preserved.
344
+ Generic binary downloads are sniffed before naming; unknown formats use `.bin`.
345
+
346
+ **0.x migration note:** previously, an extensionless string path passed to
347
+ `save()` was the literal output path. It now gets a detected extension; use the returned path
348
+ instead of assuming the argument names the saved file. Explicit extensions stay
349
+ unchanged. If you require an exact extensionless path in Node.js, write the bytes
350
+ yourself: `await writeFile(exactPath, await media.bytes())`, with `writeFile` from
351
+ `node:fs/promises`.
352
+
353
+ The Idol 3D node returns its Gaussian splat PLY, while mesh models retain their
354
+ GLB output. TRELLIS.2 estimates use the selected geometry resolution and texture
355
+ size, including the catalog's 4K-texture variant prices.
301
356
 
302
357
  A price of `0` means known-included (subscription), not unknown. `inspect`
303
358
  and loading/validating workflows never call the API. No telemetry, no
@@ -366,6 +421,14 @@ Opt-in live probe (spends a fraction of a cent):
366
421
  `node scripts/live-spot-check.mjs` (add `--image` to also run the starter
367
422
  graph’s image step).
368
423
 
424
+ ## GitHub source releases
425
+
426
+ Update the version in `package.json` in the release PR. When that version
427
+ change reaches `main`, the Node tests and npm packaging check qualify the
428
+ exact commit for a GitHub release tagged `v<version>`. npm publishes the
429
+ tested tarball through its own job. If that job fails, rerun it from the
430
+ version-changing workflow run to publish the same artifact.
431
+
369
432
  ## License
370
433
 
371
434
  MIT — see [LICENSE](LICENSE). Not affiliated with NanoGPT. Build workflows at
package/bin/nanoodle.mjs CHANGED
@@ -223,12 +223,12 @@ then: NANOGPT_API_KEY=... nanoodle run ${dest} --input Text="your idea"`);
223
223
  }
224
224
 
225
225
  // ---- run ----
226
- const inputs = {};
226
+ const inputs = Object.create(null);
227
227
  for (const arg of inputArgs) {
228
228
  const [k, v] = parseKv(arg, "--input");
229
229
  inputs[k] = await resolveValue(v);
230
230
  }
231
- const settings = {};
231
+ const settings = Object.create(null);
232
232
  for (const arg of setArgs) {
233
233
  const [k, v] = parseKv(arg, "--set");
234
234
  settings[k] = v;
@@ -260,7 +260,8 @@ then: NANOGPT_API_KEY=... nanoodle run ${dest} --input Text="your idea"`);
260
260
  // media outputs land under --out (default ./noodle-out; created only if there is media to save)
261
261
  const dir = outDir ?? "noodle-out";
262
262
  let dirMade = false;
263
- const printable = {};
263
+ const printable = Object.create(null);
264
+ const savedNames = new Set();
264
265
  for (const o of wf.outputs) {
265
266
  const value = result.outputs[o.key];
266
267
  if (value === undefined) { printable[o.key] = null; continue; }
@@ -269,7 +270,15 @@ then: NANOGPT_API_KEY=... nanoodle run ${dest} --input Text="your idea"`);
269
270
  const safe = o.key.replace(/[^\w.-]+/g, "_");
270
271
  // fetch before naming: hosted media only reveals its mime via the response Content-Type
271
272
  const data = await value.bytes();
272
- const path = join(dir, safe + "." + extForMime(value.mime || sniffMime(data)));
273
+ const ext = extForMime(value.mime || sniffMime(data));
274
+ let filename = safe + "." + ext;
275
+ // Friendly keys can collapse during sanitization ("A B" / "A_B").
276
+ // Also avoid case-only collisions on case-insensitive filesystems.
277
+ for (let suffix = 2; savedNames.has(filename.toLowerCase()); suffix++) {
278
+ filename = safe + "_" + suffix + "." + ext;
279
+ }
280
+ savedNames.add(filename.toLowerCase());
281
+ const path = join(dir, filename);
273
282
  await writeFile(path, data);
274
283
  printable[o.key] = path;
275
284
  if (!quiet) console.error(`${o.key}: saved ${path}`);
@@ -289,6 +298,7 @@ then: NANOGPT_API_KEY=... nanoodle run ${dest} --input Text="your idea"`);
289
298
  gated: result.gated || [],
290
299
  nodes: Object.fromEntries(Object.entries(result.nodes).map(([id, r]) => [id, {
291
300
  status: r.status, ms: r.ms, costUsd: r.costUsd, error: r.error,
301
+ ...(r.runId != null ? { runId: r.runId } : {}),
292
302
  ...(r.gate ? { gate: r.gate } : {}), ...(r.gatedBy ? { gatedBy: r.gatedBy } : {}),
293
303
  }])),
294
304
  }, null, 2));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nanoodle",
3
- "version": "0.13.0",
4
- "description": "Run nanoodle visual AI workflows from JavaScript — zero-dependency executor for saved noodle-graph.json files",
3
+ "version": "0.13.3",
4
+ "description": "Run nanoodle visual AI workflows from JavaScript \u2014 zero-dependency executor for saved noodle-graph.json files",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
7
7
  "exports": {
@@ -17,7 +17,7 @@
17
17
  "nanoodle": "./bin/nanoodle.mjs"
18
18
  },
19
19
  "engines": {
20
- "node": "^22.23.4 || ^24.22.1 || >=26.12.1"
20
+ "node": "^22.23.5 || ^24.22.3 || >=26.13.1"
21
21
  },
22
22
  "scripts": {
23
23
  "test": "node --test"
@@ -59,4 +59,4 @@
59
59
  "bugs": {
60
60
  "url": "https://github.com/nanoodlecom/nanoodle-js/issues"
61
61
  }
62
- }
62
+ }
@@ -0,0 +1,55 @@
1
+ import { NanoodleError } from "./errors.mjs";
2
+
3
+ export function isBranchDecider(node) {
4
+ return node.type === "decide" && node.fields?.branch === true;
5
+ }
6
+
7
+ const branchPort = (port) => port === "yes" || port === "no";
8
+
9
+ /**
10
+ * Build per-run routing over a topologically ordered set of node IDs.
11
+ * Explicit Yes/No wires control entry to a branch. Further downstream, any
12
+ * active routed input opens a join. Ordinary dependencies never open a branch.
13
+ */
14
+ export function planBranches(graph, order) {
15
+ const deciders = new Map(graph.nodes.filter(n => n.type === "decide").map(n => [n.id, n]));
16
+ const direct = new Set();
17
+ for (const link of graph.links) {
18
+ const source = deciders.get(link.from.node);
19
+ if (!source || !branchPort(link.from.port)) continue;
20
+ if (!isBranchDecider(source)) {
21
+ throw new NanoodleError(`node ${source.id}: enable branching on Decide to wire ${link.from.port}`, { code: "decide-branch" });
22
+ }
23
+ direct.add(link);
24
+ }
25
+ if (!direct.size) return null;
26
+
27
+ const inbound = new Map(order.map(id => [id, []]));
28
+ for (const link of graph.links) inbound.get(link.to.node)?.push(link);
29
+ const selectors = new Map();
30
+ for (const id of order) {
31
+ const links = inbound.get(id);
32
+ const fromDeciders = links.filter(link => direct.has(link));
33
+ const controls = fromDeciders.length ? fromDeciders : links.filter(link => selectors.has(link.from.node));
34
+ if (controls.length) selectors.set(id, controls);
35
+ }
36
+ const skipped = new Set();
37
+ return {
38
+ // Call after this node's upstreams have settled. A failed router is left
39
+ // to the usual upstream-error handling, which must also prevent execution.
40
+ activeLinks(id, outFor) {
41
+ const closed = (link) => {
42
+ if (skipped.has(link.from.node)) return true;
43
+ if (!direct.has(link)) return false;
44
+ const branch = outFor(link.from.node)?.decision?.branch;
45
+ return branchPort(branch) && branch !== link.from.port;
46
+ };
47
+ const controls = selectors.get(id);
48
+ if (controls?.every(closed)) {
49
+ skipped.add(id);
50
+ return null;
51
+ }
52
+ return inbound.get(id).filter(link => !closed(link));
53
+ },
54
+ };
55
+ }
package/src/browser.mjs CHANGED
@@ -32,6 +32,7 @@ export { NODE_TYPES, displayName, materialize, topoSort, wiredFramesFloor, MAX_F
32
32
  export { RUNNERS, IMG_INPUT_ROLES } from "./nodes.mjs"; // per-node executors — the play delegation shim drives these directly
33
33
  export { catItem, chatModelCan } from "./catalog.mjs";
34
34
  export { deriveInputs, deriveOutputs, deriveSettings, INPUT_SPECS, SETTING_SPECS } from "./io.mjs";
35
+ export { planBranches } from "./branches.mjs";
35
36
  export { decodeShareUrl, decodeShareFragment, isShareRef } from "./share.mjs";
36
37
  export { resizePlan, maskToSource, resizeCropImage, encodeWavMono } from "./local-media.mjs";
37
38
  export { parseNanoInvoice } from "./x402.mjs";