nanoodle 0.6.1 → 0.7.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
@@ -144,6 +144,13 @@ Media is sent inline as base64 (NanoGPT has no upload endpoint). Files over
144
144
  ~4.4 MB (~3.5 MB for transcription) are refused locally with a clear error
145
145
  before any paid call.
146
146
 
147
+ When authoring a graph by hand, leave media fields **empty** (`"image": ""` or
148
+ omit them) — the input then shows up as *required* in `inspect`/`wf.inputs` and
149
+ you supply the file at run time. Don’t write prose placeholders like
150
+ `"[image provided separately]"` into `fields.image`: anything that isn’t a
151
+ `data:` or `http(s)` URL is treated as empty at load (with a warning), never
152
+ sent to the API.
153
+
147
154
  ### Progress and errors
148
155
 
149
156
  ```js
@@ -169,7 +176,7 @@ all fail **before** anything is spent.
169
176
  |---|---|
170
177
  | local | text, upload (image/audio/video), choice, join, comment |
171
178
  | local media† | resize, vframes, combine, soundtrack, trim, extractaudio |
172
- | NanoGPT | llm (incl. vision + audio input), image, draw, edit, inpaint*, vision, tvideo, ivideo, vedit, lipsync, music, remix, tts, transcribe |
179
+ | NanoGPT | llm (incl. vision + audio input), image, edit, inpaint*, vision, tvideo, ivideo, vedit, lipsync, music, remix, tts, transcribe |
173
180
 
174
181
  † **local media** prefers a pure-JS path that matches the browser (lossless mp4 remux, PCM-WAV trim, PNG resize). **ffmpeg** on `PATH` is the fallback for everything else (soft dependency — not an npm package); clear error if it’s required and missing.
175
182
 
package/bin/nanoodle.mjs CHANGED
@@ -178,10 +178,27 @@ then: NANOGPT_API_KEY=... nanoodle run ${dest} --input Text="your idea"`);
178
178
 
179
179
  if (cmd === "inspect") {
180
180
  const pad = (s, n) => String(s).padEnd(n);
181
+ // Media defaults are data: URLs (megabytes of base64) — summarize instead of dumping,
182
+ // and tell the caller HOW to supply an unfilled media input, right in the listing.
183
+ const MEDIA_INPUT_KINDS = new Set(["image", "audio", "video"]);
184
+ const fmtSize = (chars) => chars >= 1024 * 1024
185
+ ? (chars / 1024 / 1024).toFixed(1) + " MB" : Math.max(1, Math.round(chars / 1024)) + " KB";
186
+ const describeDefault = (i) => {
187
+ if (i.def == null) return null;
188
+ const s = String(i.def);
189
+ if (!MEDIA_INPUT_KINDS.has(i.kind)) return `default: ${JSON.stringify(i.def)}`;
190
+ if (/^data:/i.test(s)) {
191
+ const mime = (s.match(/^data:([^;,]+)/) || [])[1] || i.kind;
192
+ return `prefilled: inline ${mime} (${fmtSize(s.length)})`;
193
+ }
194
+ return `prefilled: ${s.length > 60 ? s.slice(0, 57) + "…" : s}`;
195
+ };
181
196
  console.log("Inputs:");
182
197
  for (const i of wf.inputs) {
183
- const extras = [i.optional ? "optional" : "required", i.def != null ? `default: ${JSON.stringify(i.def)}` : null,
184
- i.options ? `options: ${i.options.join(" | ")}` : null].filter(Boolean).join(", ");
198
+ const extras = [i.optional ? "optional" : "required", describeDefault(i),
199
+ i.options ? `options: ${i.options.join(" | ")}` : null,
200
+ MEDIA_INPUT_KINDS.has(i.kind) && i.def == null ? `supply: --input "${i.key}=@file"` : null,
201
+ ].filter(Boolean).join(", ");
185
202
  console.log(` ${pad('"' + i.key + '"', 26)} ${pad(i.nodeId + "." + i.field, 16)} ${pad(i.kind, 9)} ${extras}`);
186
203
  }
187
204
  if (!wf.inputs.length) console.log(" (none)");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanoodle",
3
- "version": "0.6.1",
3
+ "version": "0.7.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",
package/src/client.mjs CHANGED
@@ -196,26 +196,6 @@ export class NanoClient {
196
196
  return out;
197
197
  }
198
198
 
199
- /** Draw-node twin of chat(): the model answers with images in message.images[]. */
200
- async chatImage(messages, model, opts = {}, { onCost, signal } = {}) {
201
- const body = { model, messages };
202
- body.temperature = opts.temperature != null && opts.temperature !== "" ? +opts.temperature : 0.8;
203
- const r = await this._postJson("/api/v1/chat/completions", body, signal);
204
- if (!r.ok) throw httpError(r.status, await r.text());
205
- const j = await r.json();
206
- if (onCost) onCost(costWithHeaders(j, r));
207
- const msg = (j.choices && j.choices[0] && j.choices[0].message) || {};
208
- const images = (msg.images || [])
209
- .map((im) => (im && im.image_url && im.image_url.url) || (im && im.url) || (typeof im === "string" ? im : null))
210
- .filter(Boolean);
211
- const text = typeof msg.content === "string" ? msg.content
212
- : Array.isArray(msg.content) ? msg.content.map((p) => p.text || "").join("") : "";
213
- if (!images.length) {
214
- throw new NanoodleError(text ? "this model replied with text, not an image — pick an image-output model" : "no image in response");
215
- }
216
- return { images, text, reasoning: msg.reasoning || "" };
217
- }
218
-
219
199
  /** POST /v1/images/generations (NOTE: not /api/v1). Returns data: / https URL(s). */
220
200
  async image({ prompt, model, size, imageDataUrl, maskDataUrl, extra, n = 1, multi = false }, { onCost, signal } = {}) {
221
201
  const body = { model, size: size || "1024x1024", n, response_format: "b64_json" };
@@ -0,0 +1,262 @@
1
+ // Up-front run-cost estimate for a graph — a USD forecast computed from the
2
+ // public NanoGPT catalog BEFORE anything runs. Pure: it never fetches. The
3
+ // caller supplies the raw catalog arrays (the same ones the /api/v1/*-models
4
+ // endpoints return); this module walks the graph's billable nodes, prices each
5
+ // against its chosen model, and sums.
6
+ //
7
+ // This is the twin of the editor/play "~$X to run" chip (index.html /
8
+ // play.html): the resolver math is ported node-for-node so a hosted server and
9
+ // the app forecast the same number. Image is exact; chat/video/audio are
10
+ // estimates (marked `exact:false`) because their true cost depends on how many
11
+ // tokens/seconds the run actually produces. `unpriced` counts billable nodes we
12
+ // could not price (model missing from the catalog, or a pricing shape we don't
13
+ // recognise) — a nonzero count means the sum is a LOWER bound.
14
+ //
15
+ // Cost is only ever KNOWN after a run (the API reports it); this is the forecast
16
+ // that lets a paid server quote a deposit that actually covers the call on the
17
+ // very first request, instead of a flat guess.
18
+
19
+ import { REF_PORT_RE } from "./graph.mjs";
20
+
21
+ // node type → pricing "kind" == which catalog it's priced from + which unit fn.
22
+ // Mirrors the app's SETTING_MODEL_KIND. This set is exactly the billable
23
+ // (network) node types; a type absent here is a free local node and costs $0.
24
+ const PRICE_KIND = {
25
+ llm: "chat", vision: "chat", draw: "chat",
26
+ image: "image", edit: "image", inpaint: "image",
27
+ tvideo: "video", ivideo: "video", vedit: "video", lipsync: "video",
28
+ music: "audio", remix: "audio", tts: "audio", transcribe: "audio",
29
+ };
30
+
31
+ // Fallback assumptions when a run's real quantity isn't knowable up front.
32
+ const EST = { llmInTokens: 1000, llmOutTokens: 500, ttsChars: 600, audioSeconds: 30, sttMinutes: 1, videoFps: 30 };
33
+
34
+ const _num = (x) => (x != null && isFinite(+x)) ? +x : null;
35
+
36
+ function pickByRes(map, reqRes, defRes) {
37
+ if (!map || typeof map !== "object") return null;
38
+ if (reqRes != null && _num(map[reqRes]) != null) return _num(map[reqRes]);
39
+ if (defRes != null && _num(map[defRes]) != null) return _num(map[defRes]);
40
+ const vals = Object.values(map).map(_num).filter((v) => v != null);
41
+ return vals.length ? vals[0] : null;
42
+ }
43
+ function pickObjByRes(map, reqRes, defRes) {
44
+ if (!map || typeof map !== "object") return null;
45
+ if (reqRes != null && map[reqRes] && typeof map[reqRes] === "object") return map[reqRes];
46
+ if (defRes != null && map[defRes] && typeof map[defRes] === "object") return map[defRes];
47
+ const objs = Object.values(map).filter((v) => v && typeof v === "object");
48
+ return objs.length ? objs[0] : null;
49
+ }
50
+ function pickDur(p, raw, fields) {
51
+ const f = parseFloat(fields && fields.duration);
52
+ if (isFinite(f) && f > 0) return f;
53
+ const d = _num(p.default_duration) ?? _num(raw.defaultDuration);
54
+ if (d != null && d > 0) return d;
55
+ if (p.per_duration) { const k = Object.keys(p.per_duration)[0]; if (k && isFinite(+k)) return +k; }
56
+ if (Array.isArray(p.supported_durations) && p.supported_durations.length) return +p.supported_durations[0];
57
+ if (p.fixed_duration_seconds != null) return _num(p.fixed_duration_seconds) || 5;
58
+ return 5;
59
+ }
60
+
61
+ // A video run bills a HIGHER tier when reference images are wired or the model's
62
+ // audio switch is on. refWired comes from the graph wiring; the audio switch /
63
+ // reference mode ride in fields.modelOpts.
64
+ function videoUnitUsd(pricing, fields, refWired) {
65
+ const p = pricing || {};
66
+ const f = fields || {};
67
+ const opts = (f.modelOpts && typeof f.modelOpts === "object") ? f.modelOpts : {};
68
+ let audioOn = false;
69
+ for (const k in opts) { if (/audio/i.test(k) && !/^(no|disable|without|mute)/i.test(k)) { const val = opts[k]; if (val === true || val === "true" || val === 1 || val === "1" || val === "on" || val === "yes") { audioOn = true; break; } } }
70
+ const refOn = !!refWired || /reference/i.test(String(opts.mode || ""));
71
+ const usd = videoBaseUsd(p, f, audioOn, refOn);
72
+ if (usd != null && isFinite(usd) && audioOn && p.audio_multiplier != null) return usd * (_num(p.audio_multiplier) ?? 1);
73
+ return usd;
74
+ }
75
+ function videoBaseUsd(pricing, fields, audioOn, refOn) {
76
+ const p = pricing || {}, raw = (p.raw && typeof p.raw === "object") ? p.raw : {};
77
+ const f = fields || {};
78
+ const res = f.resolution, defRes = p.default_resolution ?? raw.defaultResolution;
79
+ const dur = pickDur(p, raw, f);
80
+ const rp = (m) => pickByRes(m, res, defRes);
81
+ let v;
82
+ if ((v = rp(p.per_second_by_resolution)) != null) return v * dur;
83
+ if ((v = rp(p.standard_prices_per_second)) != null) return v * dur;
84
+ if (p.per_second_by_mode) {
85
+ const mm = p.per_second_by_mode;
86
+ v = refOn ? (_num(mm.reference_to_video_image) ?? _num(mm.reference_to_video_video)) : null;
87
+ if (v == null) v = _num(mm.text_to_video) ?? pickByRes(mm);
88
+ if (v != null) return v * dur;
89
+ }
90
+ if (audioOn) {
91
+ for (const k of ["text_image_with_audio_per_second", "image_to_video_with_audio_per_second", "text_to_video_with_audio_per_second"]) {
92
+ if (p[k] != null) { v = (typeof p[k] === "object") ? rp(p[k]) : _num(p[k]); if (v != null) return v * dur; }
93
+ }
94
+ }
95
+ for (const k of ["text_to_video_per_second", "text_image_without_audio_per_second", "image_to_video_without_audio_per_second"]) {
96
+ if (p[k] != null) { v = (typeof p[k] === "object") ? rp(p[k]) : _num(p[k]); if (v != null) return v * dur; }
97
+ }
98
+ 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; }
99
+ if (p.per_second != null) { v = _num(p.per_second); if (v != null) return v * dur; }
100
+ if (p.per_duration) { const dk = String(Math.round(dur)); v = _num(p.per_duration[dk]) ?? _num(p.per_duration[String(dur)]) ?? pickByRes(p.per_duration); if (v != null) return v; }
101
+ if (p.without_audio != null || p.with_audio != null) { v = audioOn ? (_num(p.with_audio) ?? _num(p.without_audio)) : (_num(p.without_audio) ?? _num(p.with_audio)); if (v != null) return v; }
102
+ if (p.base_prices_by_resolution) {
103
+ const dk = String(Math.round(dur));
104
+ if (p.duration_overrides && p.duration_overrides[dk]) { v = rp(p.duration_overrides[dk]); if (v != null) return v; }
105
+ const base = rp(p.base_prices_by_resolution);
106
+ let mult = 1;
107
+ if (p.duration_multiplier != null) mult = _num(p.duration_multiplier) ?? 1;
108
+ else if (p.duration_multipliers) mult = _num(p.duration_multipliers[dk]) ?? pickByRes(p.duration_multipliers) ?? 1;
109
+ if (base != null) return base * mult;
110
+ }
111
+ if ((v = rp(p.per_resolution)) != null) return v;
112
+ if (p.base_price != null && p.per_extra_second != null) { const bd = _num(p.base_duration) || 0; return _num(p.base_price) + Math.max(0, dur - bd) * _num(p.per_extra_second); }
113
+ if (p.per_video != null) { v = _num(p.per_video); if (v != null) return v; }
114
+ if (p.per_target_megapixel_second != null) { const mp = _num(p.default_target_megapixels) || 1; v = _num(p.per_target_megapixel_second) * mp * dur; return Math.max(v, _num(p.minimum_price) || 0); }
115
+ if (p.per_frame_unit != null) { const fpu = _num(p.frames_per_unit) || 1; return (dur * EST.videoFps / fpu) * _num(p.per_frame_unit); }
116
+ if (p.base_price != null) { v = _num(p.base_price); if (v != null) return v; }
117
+ if (Object.keys(raw).length) {
118
+ if (refOn) {
119
+ if (raw.referenceToVideoPrices) { const inner = pickObjByRes(raw.referenceToVideoPrices, res, defRes); if (inner) { const dk = String(Math.round(dur)); v = _num(inner[dk]) ?? pickByRes(inner); if (v != null) return v; } }
120
+ for (const k of ["textToVideoWithReferenceVideoPricesPerSecond", "standardTextToVideoWithReferenceVideoPricesPerSecond", "turboTextToVideoWithReferenceVideoPricesPerSecond",
121
+ "standardReferenceVideoPricesPerSecond", "fastReferenceVideoPricesPerSecond"]) {
122
+ if (raw[k]) { v = pickByRes(raw[k], res, defRes); if (v != null) return v * dur; }
123
+ }
124
+ }
125
+ if (audioOn) {
126
+ if (raw.withAudioPricesPerSecond) { v = pickByRes(raw.withAudioPricesPerSecond, res, defRes); if (v != null) return v * dur; }
127
+ if (raw.withAudioPrices) { const inner = pickObjByRes(raw.withAudioPrices, res, defRes); if (inner) { const dk = String(Math.round(dur)); v = _num(inner[dk]) ?? pickByRes(inner); if (v != null) return v; } }
128
+ }
129
+ for (const k of ["pricesPerSecond", "textToVideoPricesPerSecond", "withoutAudioPricesPerSecond",
130
+ "standardPricesPerSecond", "standardTextToVideoPricesPerSecond", "outputPricesPerSecond", "fastPricesPerSecond"]) {
131
+ if (raw[k]) { v = pickByRes(raw[k], res, defRes); if (v != null) return v * dur; }
132
+ }
133
+ for (const k of ["withoutAudioPrices", "withAudioPrices", "referenceToVideoPrices"]) {
134
+ if (raw[k]) { const inner = pickObjByRes(raw[k], res, defRes); if (inner) { const dk = String(Math.round(dur)); v = _num(inner[dk]) ?? pickByRes(inner); if (v != null) return v; } }
135
+ }
136
+ if (raw.pricePerMegapixel != null && raw.megapixelsByResolution) {
137
+ const mp = _num(raw.megapixelsByResolution[res]) ?? _num(raw.megapixelsByResolution[defRes]) ?? pickByRes(raw.megapixelsByResolution);
138
+ const nf = _num(raw.defaultNumFrames) || (dur * (_num(raw.defaultFramesPerSecond) || 24));
139
+ if (mp != null) return _num(raw.pricePerMegapixel) * mp * nf;
140
+ }
141
+ }
142
+ return genericScanUsd(p, dur);
143
+ }
144
+ // Last resort so a never-seen pricing shape estimates SOMETHING rather than
145
+ // blanking: the smallest per-second number scaled by duration, else the
146
+ // smallest flat number.
147
+ function genericScanUsd(p, dur) {
148
+ let perSec = null, flat = null;
149
+ (function walk(o, key) {
150
+ if (o == null) return;
151
+ if (typeof o === "number") { if (o > 0 && o < 500) { if (/second|persec/i.test(key)) perSec = Math.min(perSec ?? Infinity, o); else flat = Math.min(flat ?? Infinity, o); } return; }
152
+ if (typeof o === "object") for (const k of Object.keys(o)) walk(o[k], k);
153
+ })(p, "");
154
+ if (perSec != null) return perSec * dur;
155
+ if (flat != null) return flat;
156
+ return null;
157
+ }
158
+ function chatUnitUsd(pricing, inTok, outTok) {
159
+ if (!pricing) return null;
160
+ const pin = _num(pricing.prompt), pout = _num(pricing.completion); // $ per 1M tokens
161
+ if (pin == null && pout == null) return null; // omni "varies_by_modality" → unknown
162
+ return ((pin || 0) * (inTok ?? EST.llmInTokens) + (pout || 0) * (outTok ?? EST.llmOutTokens)) / 1e6;
163
+ }
164
+ function audioUnitUsd(pricing, chars, seconds) {
165
+ const p = pricing || {}, c = chars ?? EST.ttsChars;
166
+ const secs = (seconds != null && isFinite(seconds)) ? seconds : EST.audioSeconds;
167
+ if (p.per_thousand_chars != null) { let cost = _num(p.per_thousand_chars) * (c / 1000); if (p.per_generation != null) cost += _num(p.per_generation); return Math.max(cost, _num(p.minimum) || 0); }
168
+ if (p.per_prompt_char_block != null) { const bs = _num(p.prompt_char_block_size) || 1; return Math.max(Math.ceil(c / bs) * _num(p.per_prompt_char_block), _num(p.minimum) || 0); }
169
+ if (p.per_generation != null) return _num(p.per_generation);
170
+ if (p.per_second != null) return Math.max(_num(p.per_second) * secs, _num(p.minimum) || 0);
171
+ if (p.per_minute != null) return _num(p.per_minute) * EST.sttMinutes;
172
+ return null;
173
+ }
174
+ // Seconds a per_second audio model is billed for: the node's duration clamped to
175
+ // the model's advertised min/max_duration. null → audioUnitUsd uses EST.audioSeconds.
176
+ function audioBilledSeconds(sp, fields) {
177
+ const p = sp || {};
178
+ if (p.min_duration == null || p.max_duration == null) return null;
179
+ const d = parseFloat(fields && fields.duration);
180
+ if (!isFinite(d)) return null;
181
+ const lo = _num(p.min_duration), hi = _num(p.max_duration);
182
+ return Math.min(hi != null ? hi : d, Math.max(lo != null ? lo : d, d));
183
+ }
184
+ function imageUsd(pricing, size, count) {
185
+ const per = (pricing && pricing.per_image) || {};
186
+ const v = per[size] ?? per.square ?? per.square_hd ?? Object.values(per)[0];
187
+ return (v != null && isFinite(+v)) ? +v * (count || 1) : null;
188
+ }
189
+
190
+ /** Which pricing kinds a graph touches — so a caller fetches only the catalogs it needs. */
191
+ export function graphModelKinds(graph) {
192
+ const kinds = new Set();
193
+ for (const n of (graph && graph.nodes) || []) { const k = PRICE_KIND[n.type]; if (k) kinds.add(k); }
194
+ return kinds;
195
+ }
196
+
197
+ // One node's USD/run from its chosen model + settings. `catItem` is the raw
198
+ // catalog entry for node.fields.model (null → unpriceable). `graph` is needed
199
+ // only to detect wired reference-image ports (video ref tier).
200
+ function nodeUnitUsd(node, catItem, graph) {
201
+ const kind = PRICE_KIND[node.type]; if (!kind) return null;
202
+ const id = node.fields && node.fields.model; if (!id) return null;
203
+ const m = catItem; if (!m) return null;
204
+ const pricing = m.pricing, f = node.fields || {};
205
+ if (kind === "image") {
206
+ const sp = m.supported_parameters || {}, maxOut = sp.max_output_images || 1, fixed = sp.fixed_image_count || 0;
207
+ const count = fixed > 0 ? fixed : Math.min(maxOut, Math.max(1, parseInt(f.variations, 10) || 1));
208
+ return imageUsd(pricing, f.size, count);
209
+ }
210
+ if (kind === "video") {
211
+ const sp = m.supported_parameters || {}, pp = sp.parameters || sp;
212
+ const modelHasRefs = ["reference_images", "reference_image_urls", "referenceImages"].some((k) => k in pp);
213
+ const refWired = !!(modelHasRefs && graph && Array.isArray(graph.links) &&
214
+ graph.links.some((l) => l.to && l.to.node === node.id && REF_PORT_RE.test(l.to.port)));
215
+ const u = videoUnitUsd(pricing, f, refWired);
216
+ return (u != null && isFinite(u)) ? u : null;
217
+ }
218
+ if (kind === "chat") {
219
+ const inTok = Math.max(200, Math.round(((f.system || "").length + (f.prompt || "").length) / 4) + 200);
220
+ const outTok = f.maxTokens ? +f.maxTokens : EST.llmOutTokens;
221
+ return chatUnitUsd(pricing, inTok, outTok);
222
+ }
223
+ if (kind === "audio") {
224
+ const chars = node.type === "transcribe" ? undefined : ((f.prompt || "").length || EST.ttsChars);
225
+ const secs = audioBilledSeconds(m.supported_parameters, f);
226
+ const u = audioUnitUsd(pricing, chars, secs);
227
+ return (u != null && isFinite(u)) ? u : null; // one track — the sent song count is clamped to 1 at run
228
+ }
229
+ return null;
230
+ }
231
+
232
+ /**
233
+ * Forecast a graph's per-run cost from the public catalog.
234
+ *
235
+ * @param {{nodes:Array, links?:Array}} graph a materialized graph (Workflow#graph)
236
+ * @param {{chat?:Array, image?:Array, video?:Array, audio?:Array}} catalogs
237
+ * raw catalog arrays (as /api/v1/*-models return them, `.data`), indexed here by model id
238
+ * @returns {{usd:number, exact:boolean, priced:number, unpriced:number}}
239
+ * usd = sum over priced billable nodes; exact = every priced node was image
240
+ * (deterministic); priced/unpriced = billable node counts. unpriced>0 ⇒ usd is a lower bound.
241
+ */
242
+ export function estimateGraphCost(graph, catalogs = {}) {
243
+ const nodes = (graph && Array.isArray(graph.nodes)) ? graph.nodes : [];
244
+ const byKind = {};
245
+ for (const kind of ["chat", "image", "video", "audio"]) {
246
+ const arr = Array.isArray(catalogs[kind]) ? catalogs[kind] : [];
247
+ const map = new Map();
248
+ for (const m of arr) if (m && m.id != null) map.set(String(m.id), m);
249
+ byKind[kind] = map;
250
+ }
251
+ let usd = 0, priced = 0, unpriced = 0, exact = true;
252
+ for (const n of nodes) {
253
+ const kind = PRICE_KIND[n.type]; if (!kind) continue; // free/local node
254
+ const id = n.fields && n.fields.model;
255
+ const m = id != null ? byKind[kind].get(String(id)) : null;
256
+ const u = m ? nodeUnitUsd(n, m, graph) : null;
257
+ if (u == null || !isFinite(u)) { unpriced++; continue; }
258
+ usd += u; priced++;
259
+ if (kind !== "image") exact = false;
260
+ }
261
+ return { usd, exact, priced, unpriced };
262
+ }
package/src/graph.mjs CHANGED
@@ -3,7 +3,7 @@ import { NanoodleError } from "./errors.mjs";
3
3
  /* Dynamic input-port families (mirrors the nanoodle app's runGraph). A wire landing on one of
4
4
  these ports — or on a port declared in NODE_TYPES[type].inputs — is a data input; a wire
5
5
  landing on ANY other port is a field override (wired prompt/system/lyrics/q/...). */
6
- export const IMG_PORT_RE = /^img\d+$/; // llm / draw vision references
6
+ export const IMG_PORT_RE = /^img\d+$/; // llm vision references
7
7
  export const EDIT_IMG_RE = /^image\d*$/; // edit multi-reference: image, image2, ...
8
8
  export const VID_PORT_RE = /^vid\d+$/;
9
9
  export const CLIP_PORT_RE = /^clip\d+$/; // combine clips
@@ -44,7 +44,6 @@ export const NODE_TYPES = {
44
44
  join: { title: "Join", inputs: ["a", "b"], outputs: [{ name: "text", type: "text" }], local: true },
45
45
  llm: { title: "LLM", inputs: [], outputs: [{ name: "text", type: "text" }], network: true },
46
46
  image: { title: "Image", inputs: [], outputs: [{ name: "image", type: "image" }], network: true },
47
- draw: { title: "Draw", inputs: [], outputs: [{ name: "image", type: "image" }, { name: "text", type: "text" }], network: true },
48
47
  edit: { title: "Edit", inputs: [], outputs: [{ name: "image", type: "image" }], network: true },
49
48
  inpaint: { title: "Inpaint", inputs: ["image", "mask"], outputs: [{ name: "image", type: "image" }], network: true },
50
49
  resize: { title: "Resize / crop", inputs: ["image"], outputs: [{ name: "image", type: "image" }], local: true },
@@ -92,10 +91,39 @@ export function isInputPort(node, port) {
92
91
  return DYNAMIC_INPUT_RES.some((re) => re.test(port));
93
92
  }
94
93
 
94
+ /**
95
+ * Media fields (upload image, inpaint image/mask, audio/video clips) hold a data: or
96
+ * http(s) URL — the editor writes data: URLs, hand-authored graphs may inline either.
97
+ * Agents authoring graphs sometimes leave a prose placeholder instead ("[image will be
98
+ * provided at run time]") or a bare file path: those LOOK filled (inspect prints a
99
+ * default, run() skips the required-input check) but post garbage to the API. Anything
100
+ * that isn't a real media URL is treated as EMPTY at load, with a warning that says how
101
+ * to actually supply the media.
102
+ */
103
+ const MEDIA_FIELD_KEYS = ["image", "mask", "audio", "video"];
104
+ const MEDIA_URL_RE = /^(data:|https?:)/i;
105
+
106
+ function scrubMediaPlaceholders(n, warnings) {
107
+ for (const k of MEDIA_FIELD_KEYS) {
108
+ const v = n.fields[k];
109
+ if (v == null || v === "" || (typeof v === "string" && MEDIA_URL_RE.test(v.trim()))) continue;
110
+ const shown = typeof v === "string"
111
+ ? `"${v.length > 60 ? v.slice(0, 57) + "…" : v}"`
112
+ : Array.isArray(v) ? "an array" : typeof v === "object" ? "an object" : `a ${typeof v}`;
113
+ n.fields[k] = "";
114
+ warnings.push(
115
+ `node ${n.id} (${displayName(n)}): fields.${k} held ${shown} — not a data: or http(s) URL, so it was ` +
116
+ `treated as empty. Leave media fields "" in the graph and supply the ${k} at run time ` +
117
+ `(CLI: --input "<key>=@file", library: run({ "<key>": mediaFromFile(path) }), key from inspect/wf.inputs), ` +
118
+ `or inline a data: URL.`);
119
+ }
120
+ }
121
+
95
122
  /**
96
123
  * Load raw parsed graph JSON into an executable graph (mirrors the app's applyGraphData):
97
124
  * - `audio` type aliases to `tts` (legacy saves)
98
125
  * - unknown node types are KEPT but flagged (`unknown: true`) + a warning; run() fails fast on them
126
+ * - media fields that aren't a data:/http(s) URL (prose placeholders, file paths) are blanked + a warning
99
127
  * - links are kept only when both endpoints exist
100
128
  * - links into music/tts port "text" migrate to "prompt"
101
129
  * @returns {{ nodes, links, warnings: string[] }}
@@ -113,6 +141,8 @@ export function materialize(data) {
113
141
  if (!NODE_TYPES[type]) {
114
142
  n.unknown = true;
115
143
  warnings.push(`unknown node type "${raw.type}" (node ${n.id}) — kept, but running this workflow will fail; you may need a newer nanoodle library`);
144
+ } else {
145
+ scrubMediaPlaceholders(n, warnings);
116
146
  }
117
147
  nodes.push(n);
118
148
  }
package/src/index.mjs CHANGED
@@ -7,6 +7,7 @@ export {
7
7
  export { NanoClient } from "./client.mjs";
8
8
  export { NODE_TYPES, displayName, materialize, topoSort, wiredFramesFloor, MAX_FRAMES } from "./graph.mjs";
9
9
  export { deriveInputs, deriveOutputs, deriveSettings, INPUT_SPECS, SETTING_SPECS } from "./io.mjs";
10
+ export { estimateGraphCost, graphModelKinds } from "./estimate.mjs";
10
11
  export { decodeShareUrl, decodeShareFragment, isShareRef } from "./share.mjs";
11
12
  export { parseNanoInvoice } from "./x402.mjs";
12
13
  export { qrTerminal, qrModules } from "./qr.mjs";
package/src/io.mjs CHANGED
@@ -12,8 +12,6 @@ export const INPUT_SPECS = {
12
12
  llm: [{ f: "prompt", label: "Prompt", kind: "textarea" },
13
13
  { f: "system", label: "System prompt", kind: "textarea", optional: true, def: "You are a helpful, concise assistant." }],
14
14
  image: [{ f: "prompt", label: "Image prompt", kind: "textarea" }],
15
- draw: [{ f: "prompt", label: "Prompt", kind: "textarea" },
16
- { f: "system", label: "System prompt", kind: "textarea", optional: true }],
17
15
  tvideo: [{ f: "prompt", label: "Video prompt", kind: "textarea" }],
18
16
  music: [{ f: "prompt", label: "Style / prompt", kind: "textarea" }],
19
17
  remix: [{ f: "prompt", label: "Style / direction", kind: "textarea" }],
@@ -201,10 +199,6 @@ export const SETTING_SPECS = {
201
199
  { f: "size", label: "Image size", kind: "select", options: SIZES, def: "1024x1024" },
202
200
  { f: "seed", label: "Seed", kind: "number" },
203
201
  ],
204
- draw: [
205
- { f: "model", label: "Model", kind: "model" },
206
- { f: "showThinking", label: "Show thinking", kind: "boolean", def: true },
207
- ],
208
202
  tvideo: [
209
203
  { f: "model", label: "Model", kind: "model" },
210
204
  { f: "resolution", label: "Resolution", kind: "select", def: "" },
package/src/nodes.mjs CHANGED
@@ -396,7 +396,7 @@ function guardRefsSize(imgs) {
396
396
  /**
397
397
  * Per-node executors. Each: async run(node, inp, ctx) → out map keyed by output port name.
398
398
  * `node.fields` already carries wired field overrides + user inputs + settings.
399
- * ctx = { chat, chatImage, image, video, audio, transcribe, progress } (cost/poll wired by the engine).
399
+ * ctx = { chat, image, video, audio, transcribe, progress } (cost/poll wired by the engine).
400
400
  */
401
401
  export const RUNNERS = {
402
402
  async text(n) { return { text: n.fields.text || "" }; },
@@ -570,20 +570,6 @@ export const RUNNERS = {
570
570
  return { image: await ctx.image({ prompt, model: mdl(n), size: n.fields.size || "1024x1024", imageDataUrl: src, extra: imgExtra(n) }) };
571
571
  },
572
572
 
573
- async draw(n, inp, ctx) {
574
- const prompt = promptOf(n, inp, "no prompt");
575
- const imgs = await Promise.all(collectPorts(inp, IMG_PORT_RE).map((u) => fitImage(u, ctx, "wired image")));
576
- guardRefsSize(imgs);
577
- const messages = chatMessages(n, prompt, imgs, null);
578
- const res = await ctx.chatImage(messages, mdl(n), {});
579
- const sel = Math.min(Math.max(0, parseInt(n.fields.sel, 10) || 0), res.images.length - 1);
580
- const showThinking = n.fields.showThinking !== false && n.fields.showThinking !== "false";
581
- const text = showThinking && res.reasoning
582
- ? "```thinking\n" + res.reasoning + "\n```\n\n" + (res.text || "")
583
- : res.text;
584
- return { image: res.images[sel], images: res.images, text };
585
- },
586
-
587
573
  async inpaint(n, inp, ctx) {
588
574
  const source = inp.image != null ? inp.image : n.fields.image;
589
575
  const rawMask = inp.mask != null ? inp.mask : n.fields.mask;
package/src/workflow.mjs CHANGED
@@ -259,7 +259,6 @@ export class Workflow {
259
259
  const io = { onCost, onPoll, signal: ac.signal };
260
260
  return {
261
261
  chat: (messages, model, opts) => this.client.chat(messages, model, opts, io),
262
- chatImage: (messages, model, opts) => this.client.chatImage(messages, model, opts, io),
263
262
  image: (args) => this.client.image(args, io),
264
263
  video: (model, prompt, opts, imageDataUrl) => this.client.video(model, prompt, opts, imageDataUrl, io),
265
264
  audio: (model, input, extra) => this.client.audio(model, input, extra, io),