nanoodle 0.5.1 → 0.6.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 +6 -0
- package/package.json +1 -1
- package/src/graph.mjs +11 -0
- package/src/io.mjs +8 -4
- package/src/nodes.mjs +13 -4
package/README.md
CHANGED
|
@@ -119,6 +119,12 @@ keys are the sink node’s custom name (or its type name). A workflow with
|
|
|
119
119
|
exactly one required input also accepts a bare value: `wf.run("hello")`.
|
|
120
120
|
Settings use `nodeId.field` keys (`"n3.model"`).
|
|
121
121
|
|
|
122
|
+
An input is `optional` when its node-type spec says so (LLM system prompts),
|
|
123
|
+
or when the author checked **optional** on the node in the editor (saved as
|
|
124
|
+
`fields.optional`). Optional inputs can be omitted: the run proceeds and the
|
|
125
|
+
node yields an empty value (an omitted optional image/audio/video input is
|
|
126
|
+
simply dropped by downstream reference-style consumers).
|
|
127
|
+
|
|
122
128
|
### Media inputs
|
|
123
129
|
|
|
124
130
|
```js
|
package/package.json
CHANGED
package/src/graph.mjs
CHANGED
|
@@ -73,6 +73,17 @@ export function displayName(node) {
|
|
|
73
73
|
return (t && t.title) || node.type || "?";
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Author-marked optional node: fields.optional (the editor's "optional" checkbox on
|
|
78
|
+
* input nodes) makes every input this node surfaces skippable — the run proceeds and
|
|
79
|
+
* the node yields an empty value instead of failing. Serialized inside fields so it
|
|
80
|
+
* survives save/share/materialize with zero format changes.
|
|
81
|
+
*/
|
|
82
|
+
export function optionalNode(node) {
|
|
83
|
+
const v = node && node.fields && node.fields.optional;
|
|
84
|
+
return v === true || v === "true";
|
|
85
|
+
}
|
|
86
|
+
|
|
76
87
|
/** Is a wire landing on `port` of `node` a data input (vs a field override)? */
|
|
77
88
|
export function isInputPort(node, port) {
|
|
78
89
|
const t = NODE_TYPES[node.type];
|
package/src/io.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NanoodleError } from "./errors.mjs";
|
|
2
|
-
import { NODE_TYPES, displayName, topoSort, wiredFramesFloor, MAX_FRAMES } from "./graph.mjs";
|
|
2
|
+
import { NODE_TYPES, displayName, optionalNode, topoSort, wiredFramesFloor, MAX_FRAMES } from "./graph.mjs";
|
|
3
3
|
|
|
4
4
|
/* ============================== INPUTS ============================== */
|
|
5
5
|
|
|
@@ -31,7 +31,7 @@ export function deriveInputs(graph) {
|
|
|
31
31
|
const mk = (n, field, label, kind, optional, specDef) => {
|
|
32
32
|
const cur = n.fields[field];
|
|
33
33
|
return {
|
|
34
|
-
nodeId: n.id, field, label, kind, optional: !!optional,
|
|
34
|
+
nodeId: n.id, field, label, kind, optional: !!optional || optionalNode(n),
|
|
35
35
|
def: cur != null && String(cur) !== "" ? cur : specDef,
|
|
36
36
|
title: displayName(n), _node: n,
|
|
37
37
|
};
|
|
@@ -67,13 +67,17 @@ export function deriveInputs(graph) {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
// Friendly keys: a node's custom name labels its input when it contributes exactly one
|
|
70
|
-
// REQUIRED input (app PR #138)
|
|
70
|
+
// REQUIRED input (app PR #138) — or exactly one input at all, so an author-optional
|
|
71
|
+
// renamed node (e.g. an optional "Style reference" upload) keeps its name as the key.
|
|
72
|
+
// Otherwise the generic spec label. Dedupe with " 2", " 3".
|
|
71
73
|
const used = new Map();
|
|
72
74
|
for (const e of entries) {
|
|
73
75
|
const nodeEntries = entries.filter((x) => x.nodeId === e.nodeId);
|
|
74
76
|
const required = nodeEntries.filter((x) => !x.optional);
|
|
75
77
|
const custom = (e._node.name || "").trim();
|
|
76
|
-
|
|
78
|
+
const names = (required.length === 1 && required[0] === e) ||
|
|
79
|
+
(required.length === 0 && nodeEntries.length === 1);
|
|
80
|
+
let key = custom && names ? custom : e.label;
|
|
77
81
|
const lower = key.toLowerCase();
|
|
78
82
|
const count = (used.get(lower) || 0) + 1;
|
|
79
83
|
used.set(lower, count);
|
package/src/nodes.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NanoodleError } from "./errors.mjs";
|
|
2
2
|
import { catItem, chatModelCan } from "./catalog.mjs";
|
|
3
|
-
import { IMG_PORT_RE, EDIT_IMG_RE, REF_PORT_RE, CLIP_PORT_RE, VID_PORT_RE } from "./graph.mjs";
|
|
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,
|
|
@@ -385,15 +385,24 @@ export const RUNNERS = {
|
|
|
385
385
|
async text(n) { return { text: n.fields.text || "" }; },
|
|
386
386
|
|
|
387
387
|
async upload(n) {
|
|
388
|
-
if (!n.fields.image)
|
|
388
|
+
if (!n.fields.image) {
|
|
389
|
+
if (optionalNode(n)) return { image: "" }; // skipped optional input — consumers drop empty media (collectPorts)
|
|
390
|
+
throw new NanoodleError("no image — this Image input has no image");
|
|
391
|
+
}
|
|
389
392
|
return { image: n.fields.image };
|
|
390
393
|
},
|
|
391
394
|
async aupload(n) {
|
|
392
|
-
if (!n.fields.audio)
|
|
395
|
+
if (!n.fields.audio) {
|
|
396
|
+
if (optionalNode(n)) return { audio: "" };
|
|
397
|
+
throw new NanoodleError("no audio — this Audio input has no clip");
|
|
398
|
+
}
|
|
393
399
|
return { audio: n.fields.audio };
|
|
394
400
|
},
|
|
395
401
|
async vupload(n) {
|
|
396
|
-
if (!n.fields.video)
|
|
402
|
+
if (!n.fields.video) {
|
|
403
|
+
if (optionalNode(n)) return { video: "" };
|
|
404
|
+
throw new NanoodleError("no video — this Video input has no clip");
|
|
405
|
+
}
|
|
397
406
|
return { video: n.fields.video };
|
|
398
407
|
},
|
|
399
408
|
|