nanoodle 0.1.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/src/nodes.mjs ADDED
@@ -0,0 +1,441 @@
1
+ import { NanoodleError, UnsupportedNodeError } from "./errors.mjs";
2
+ import { IMG_PORT_RE, EDIT_IMG_RE, REF_PORT_RE, displayName } from "./graph.mjs";
3
+ import { MEDIA_INLINE_MAX } from "./media.mjs";
4
+
5
+ /** Message for browser-only media nodes (exact wording is part of the contract). */
6
+ export function unsupportedNodeError(node) {
7
+ return new UnsupportedNodeError(
8
+ `node "${displayName(node)}" (${node.id}): node type '${node.type}' does local media processing that requires ` +
9
+ "the nanoodle browser app; not supported by this library yet",
10
+ { nodeId: node.id, nodeType: node.type });
11
+ }
12
+
13
+ function mdl(n) {
14
+ const m = String((n.fields && n.fields.model) || "").trim();
15
+ if (!m) throw new NanoodleError(`pick a model first (node ${n.id})`);
16
+ return m; // model strings pass through VERBATIM — endpoint choice is by node TYPE
17
+ }
18
+
19
+ function portIdx(name) {
20
+ const m = /(\d+)$/.exec(name);
21
+ return m ? +m[1] : 1;
22
+ }
23
+
24
+ function collectPorts(inp, re) {
25
+ return Object.keys(inp)
26
+ .filter((k) => re.test(k))
27
+ .sort((a, b) => portIdx(a) - portIdx(b))
28
+ .map((k) => inp[k])
29
+ .filter(Boolean);
30
+ }
31
+
32
+ function promptOf(n, inp, errMsg) {
33
+ const raw = inp.prompt != null ? inp.prompt : n.fields.prompt != null ? n.fields.prompt : "";
34
+ const p = String(raw).trim();
35
+ if (!p && errMsg) throw new NanoodleError(errMsg);
36
+ return p;
37
+ }
38
+
39
+ /**
40
+ * Wired audio data: URL → OpenAI-style inline input_audio part (base64 body, no data: prefix).
41
+ * Callers must inline https URLs first (ctx.fetchMedia) — the spec mandates base64 bytes, and
42
+ * shipping a raw URL string as "base64 data" makes a paid call with garbage audio.
43
+ */
44
+ function audioInputPart(url) {
45
+ if (typeof url !== "string" || !url) return null;
46
+ if (!/^data:/i.test(url)) {
47
+ throw new NanoodleError("audio input must be a data: URL — download the clip and inline it before building the chat part");
48
+ }
49
+ if (url.length > MEDIA_INLINE_MAX) {
50
+ throw new NanoodleError("audio clip is too large to inline (~4 MB send limit) — use a shorter clip");
51
+ }
52
+ const comma = url.indexOf(",");
53
+ const head = comma >= 0 ? url.slice(0, comma) : "";
54
+ const data = comma >= 0 ? url.slice(comma + 1) : url;
55
+ const mt = head.match(/data:([^;]+)/);
56
+ let fmt = ((mt && mt[1] ? mt[1].split("/")[1] : "") || "wav").toLowerCase();
57
+ if (fmt === "mpeg" || fmt === "mp3") fmt = "mp3";
58
+ else if (fmt === "x-wav" || fmt === "wave") fmt = "wav";
59
+ return { type: "input_audio", input_audio: { data, format: fmt } };
60
+ }
61
+
62
+ function llmOpts(n) {
63
+ const f = n.fields, o = {};
64
+ if (f.temperature != null && f.temperature !== "") o.temperature = +f.temperature;
65
+ if (f.maxTokens) o.max_tokens = +f.maxTokens;
66
+ if (f.format === "JSON") o.response_format = { type: "json_object" };
67
+ if (f.reasoningEffort && f.reasoningEffort !== "default") o.reasoning_effort = f.reasoningEffort;
68
+ if (f.showThinking === true || f.showThinking === "true") o.showThinking = true;
69
+ return o;
70
+ }
71
+
72
+ /* ---------- LoRA (image/video style adapters) — verbatim behavior from the app runtime ----------
73
+ HuggingFace + any direct .safetensors URL; the URL is forwarded to NanoGPT and pulled
74
+ server-side. CivitAI links are signed/login-gated, so we reject them with guidance BEFORE
75
+ the paid call instead of eating a charged 422. */
76
+ function normalizeLoraUrl(raw) {
77
+ let u = String(raw || "").trim();
78
+ if (!u) return "";
79
+ if (/\b(civitai\.com|civitai\.red|civit\.ai)\b/i.test(u)) {
80
+ throw new NanoodleError("CivitAI links can't be fetched directly — download the .safetensors and re-host it (e.g. on HuggingFace), then paste that URL.");
81
+ }
82
+ if (/(^|\/\/|\.)huggingface\.co\//i.test(u)) {
83
+ u = u.replace("/blob/", "/resolve/");
84
+ if (!/\/resolve\/.+\.safetensors(\?|$)/i.test(u)) {
85
+ throw new NanoodleError("Link the .safetensors file on HuggingFace: open it and use Copy download link (…/resolve/main/your-lora.safetensors).");
86
+ }
87
+ return u;
88
+ }
89
+ if (/^[\w.-]+\/[\w.-]+$/.test(u)) {
90
+ throw new NanoodleError("That looks like a HuggingFace repo id — open the .safetensors file and copy its download link (…/resolve/main/your-lora.safetensors).");
91
+ }
92
+ if (!/^https?:\/\//i.test(u)) {
93
+ throw new NanoodleError("LoRA must be a direct https URL to a .safetensors file (HuggingFace or any host).");
94
+ }
95
+ return u;
96
+ }
97
+
98
+ function loraFamily(model) {
99
+ const m = String(model || "");
100
+ if (/spicy/i.test(m)) return null;
101
+ if (/p-image/i.test(m)) return "pimage";
102
+ if (/klein/i.test(m)) return "flux2klein";
103
+ if (/flux-2/i.test(m)) return "flux2dev";
104
+ if (/z-image/i.test(m)) return "zimage";
105
+ if (/ltx/i.test(m)) return "ltx";
106
+ if (/lora/i.test(m)) return "flux";
107
+ return null;
108
+ }
109
+
110
+ function loraKind(type) { return (type === "image" || type === "edit" || type === "inpaint") ? "image" : "video"; }
111
+
112
+ function imageTakesLora(id) {
113
+ id = String(id || "");
114
+ if (/inpaint/i.test(id)) return false;
115
+ if (/klein/i.test(id)) return true;
116
+ return /(^|[-\/])lora($|[-\/])/i.test(id);
117
+ }
118
+
119
+ // name-based check (video by family, image by allow-list) — the editor already gated LoRA
120
+ // input to truly lora-capable models, so this stays in lockstep without a live catalog
121
+ function modelTakesLora(kind, id) {
122
+ if (!id || loraFamily(id) == null) return false;
123
+ return kind === "video" ? true : imageTakesLora(id);
124
+ }
125
+
126
+ function loraCap(model) {
127
+ switch (loraFamily(model)) {
128
+ case "flux2dev": return 4;
129
+ case "flux2klein": case "zimage": case "ltx": return 3;
130
+ default: return 1; // flux-lora, pimage — single slot
131
+ }
132
+ }
133
+
134
+ function nodeLoras(n) {
135
+ if (Array.isArray(n.fields.loras)) return n.fields.loras;
136
+ if ((n.fields.loraUrl || "").trim() || (n.fields.loraStrength || "") !== "") {
137
+ return [{ url: n.fields.loraUrl || "", strength: n.fields.loraStrength || "" }]; // legacy single-slot fields
138
+ }
139
+ return [];
140
+ }
141
+
142
+ function loraBodyFor(model, items) {
143
+ const fam = loraFamily(model), sc = (v) => (isNaN(v) ? 1 : v);
144
+ if (fam === "pimage") return { lora_weights: items[0].url, lora_scale: sc(items[0].scale) };
145
+ if (fam === "flux2dev" || fam === "flux2klein" || fam === "zimage" || fam === "ltx") {
146
+ const b = {};
147
+ items.forEach((it, i) => { b["lora_url_" + (i + 1)] = it.url; b["lora_scale_" + (i + 1)] = sc(it.scale); });
148
+ return b;
149
+ }
150
+ if (items.length === 1) return { lora_url: items[0].url, lora_strength: sc(items[0].scale) };
151
+ return { loras: items.map((it) => ({ path: it.url, scale: sc(it.scale) })) };
152
+ }
153
+
154
+ /** LoRA body params for a node (SPEC-engine "+ LoRA params"): {} when the model takes none. */
155
+ export function loraParams(n) {
156
+ if (!modelTakesLora(loraKind(n.type), n.fields.model)) return {};
157
+ const rows = nodeLoras(n).filter((r) => r && (r.url || "").trim());
158
+ if (!rows.length) return {};
159
+ const items = rows.slice(0, loraCap(n.fields.model)).map((r) => ({
160
+ url: normalizeLoraUrl(r.url),
161
+ scale: (r.strength == null || r.strength === "") ? 1 : Number(r.strength),
162
+ }));
163
+ return loraBodyFor(n.fields.model, items);
164
+ }
165
+
166
+ /* ---------- custom-civitai AIR normalization/validation (pre-charge, mirrors the app) ---------- */
167
+ function normalizeCustomCivitaiAir(raw) {
168
+ const s = String(raw || "").trim();
169
+ if (!s) return "";
170
+ if (/^civitai:\d+@\d+/i.test(s)) return s.replace(/^civitai:/i, "civitai:");
171
+ if (/^persona:\d+@\d+/i.test(s)) return s.replace(/^persona:/i, "persona:");
172
+ if (/^runware:[^\s@]+@[^\s@]+$/i.test(s)) return s.replace(/^runware:/i, "runware:");
173
+ const bare = /^(\d+)@(\d+)$/.exec(s);
174
+ if (bare) return "civitai:" + bare[1] + "@" + bare[2];
175
+ const mid = /civitai\.com\/models\/(\d+)/i.exec(s);
176
+ const vid = /[?&]modelVersionId=(\d+)/i.exec(s);
177
+ if (mid && vid) return "civitai:" + mid[1] + "@" + vid[1];
178
+ return s;
179
+ }
180
+
181
+ function isValidCustomAir(air) {
182
+ return /^(civitai:\d+@\d+|persona:\d+@\d+|runware:[^\s@]+@[^\s@]+)$/i.test(air);
183
+ }
184
+
185
+ /** Per-call image extras: LoRA params + fixed seed (when numeric) + custom-civitai AIR. */
186
+ function imgExtra(n) {
187
+ const e = loraParams(n);
188
+ const s = n.fields.seed;
189
+ if (s != null && String(s).trim() !== "" && !isNaN(Number(s))) e.seed = Number(s);
190
+ if (n.fields.model === "custom-civitai") {
191
+ const air = normalizeCustomCivitaiAir(n.fields.customCivitaiAir);
192
+ if (!air) throw new NanoodleError("select a CivitAI model — pick a preset or paste an AIR (civitai:/runware:/persona:…)");
193
+ if (!isValidCustomAir(air)) {
194
+ throw new NanoodleError("AIR must look like civitai:MODEL@VERSION, runware:id@rev, or persona:MODEL@VERSION");
195
+ }
196
+ e.customCivitaiAir = air;
197
+ }
198
+ return e;
199
+ }
200
+
201
+ /** Video dims under the standard wire names (no catalog in v1 → no per-model renames). */
202
+ function videoDims(n) {
203
+ const out = {};
204
+ const f = n.fields;
205
+ if (f.resolution != null && f.resolution !== "") out.resolution = f.resolution;
206
+ if (f.aspect != null && f.aspect !== "") out.aspect_ratio = f.aspect;
207
+ if (f.duration != null && f.duration !== "") out.duration = f.duration;
208
+ return out;
209
+ }
210
+
211
+ function videoSourceOpts(url) {
212
+ return /^https?:/i.test(url) ? { videoUrl: url } : { videoDataUrl: url };
213
+ }
214
+
215
+ function audioSourceOpts(url) {
216
+ return /^https?:/i.test(url) ? { audioUrl: url } : { audioDataUrl: url };
217
+ }
218
+
219
+ const nonEmpty = (v) => v != null && String(v).trim() !== "";
220
+
221
+ /**
222
+ * Faithful to the app's collectAudioParams: only-when-nonempty, defaults omitted,
223
+ * then fields.extraJson merged verbatim last. (Catalog gating: skipped in v1.)
224
+ */
225
+ function audioParams(n) {
226
+ const f = n.fields, body = {};
227
+ const num = (v) => { const x = Number(v); return isNaN(x) ? null : x; };
228
+ if (n.type === "music") {
229
+ if (nonEmpty(f.lyrics)) body.lyrics = f.lyrics;
230
+ if (f.instrumental === true || f.instrumental === "true") body.instrumental = true;
231
+ if (nonEmpty(f.duration) && num(f.duration) != null) body.duration = num(f.duration);
232
+ if (nonEmpty(f.negative_prompt)) body.negative_prompt = f.negative_prompt;
233
+ if (nonEmpty(f.seed) && num(f.seed) != null) body.seed = num(f.seed);
234
+ if (nonEmpty(f.response_format) && f.response_format !== "mp3") body.response_format = f.response_format;
235
+ } else if (n.type === "tts") {
236
+ if (nonEmpty(f.voice)) body.voice = f.voice;
237
+ if (nonEmpty(f.speed) && num(f.speed) != null && num(f.speed) !== 1) body.speed = num(f.speed); // omit when 1
238
+ if (nonEmpty(f.instructions)) body.instructions = f.instructions;
239
+ if (nonEmpty(f.response_format) && f.response_format !== "mp3") body.response_format = f.response_format;
240
+ } else if (n.type === "remix") {
241
+ if (nonEmpty(f.lyrics)) body.lyrics = f.lyrics;
242
+ if (nonEmpty(f.duration) && num(f.duration) != null) body.duration = num(f.duration);
243
+ if (nonEmpty(f.response_format) && f.response_format !== "mp3") body.response_format = f.response_format;
244
+ }
245
+ if ((f.extraJson || "").trim()) {
246
+ try { Object.assign(body, JSON.parse(f.extraJson)); }
247
+ catch { throw new NanoodleError("advanced params: invalid JSON in extraJson"); }
248
+ }
249
+ // Re-enforce the surface-one-track contract AFTER extraJson (twin of the app runtime): advanced
250
+ // params can reintroduce number_of_songs / generation_count / n and bill N songs while the runner
251
+ // only keeps the single returned URL. Drop every song-count key (omit = one track at the model
252
+ // default). remix shares the extraJson escape hatch and surfaces one URL too — same clamp.
253
+ if (n.type === "music" || n.type === "remix") {
254
+ for (const k of Object.keys(body)) {
255
+ if (/^(number_of_songs|n|num_songs|song_count|generation_count|generation_count_parameter)$/i.test(k)
256
+ || /generation_count|num_?songs|song_?count/i.test(k)) delete body[k];
257
+ }
258
+ }
259
+ return body;
260
+ }
261
+
262
+ function chatMessages(n, prompt, imgs, audioPart) {
263
+ const messages = [];
264
+ if ((n.fields.system || "").trim()) messages.push({ role: "system", content: n.fields.system.trim() });
265
+ messages.push(imgs.length || audioPart
266
+ ? {
267
+ role: "user",
268
+ content: [
269
+ { type: "text", text: prompt },
270
+ ...imgs.map((url) => ({ type: "image_url", image_url: { url } })),
271
+ ...(audioPart ? [audioPart] : []),
272
+ ],
273
+ }
274
+ : { role: "user", content: prompt });
275
+ return messages;
276
+ }
277
+
278
+ function guardRefsSize(imgs) {
279
+ if (imgs.reduce((s, u) => s + (u ? u.length : 0), 0) > MEDIA_INLINE_MAX) {
280
+ throw new NanoodleError("reference images too large (~4 MB combined limit) — use fewer or smaller images");
281
+ }
282
+ }
283
+
284
+ /**
285
+ * Per-node executors. Each: async run(node, inp, ctx) → out map keyed by output port name.
286
+ * `node.fields` already carries wired field overrides + user inputs + settings.
287
+ * ctx = { chat, chatImage, image, video, audio, transcribe, progress } (cost/poll wired by the engine).
288
+ */
289
+ export const RUNNERS = {
290
+ async text(n) { return { text: n.fields.text || "" }; },
291
+
292
+ async upload(n) {
293
+ if (!n.fields.image) throw new NanoodleError("no image — this Image input has no image");
294
+ return { image: n.fields.image };
295
+ },
296
+ async aupload(n) {
297
+ if (!n.fields.audio) throw new NanoodleError("no audio — this Audio input has no clip");
298
+ return { audio: n.fields.audio };
299
+ },
300
+ async vupload(n) {
301
+ if (!n.fields.video) throw new NanoodleError("no video — this Video input has no clip");
302
+ return { video: n.fields.video };
303
+ },
304
+
305
+ async choice(n) {
306
+ const opts = String(n.fields.options || "").split("\n").map((s) => s.trim()).filter(Boolean);
307
+ const sel = n.fields.selected;
308
+ const val = sel != null && opts.indexOf(sel) >= 0 ? sel : opts[0] || "";
309
+ if (!val) throw new NanoodleError("no options — this Choice has no options to pick from");
310
+ return { text: val };
311
+ },
312
+
313
+ async join(n, inp) {
314
+ const sep = (n.fields.sep != null ? n.fields.sep : " ").replace(/\\n/g, "\n");
315
+ return { text: [inp.a, inp.b].filter((v) => v != null && v !== "").join(sep) };
316
+ },
317
+
318
+ async llm(n, inp, ctx) {
319
+ const prompt = promptOf(n, inp, "no prompt");
320
+ const imgs = collectPorts(inp, IMG_PORT_RE);
321
+ // hosted audio (music/tts nodes return https CDN URLs verbatim) → download + inline as base64:
322
+ // the chat input_audio part carries bytes, never a URL
323
+ const audioSrc = inp.audio && /^https?:/i.test(inp.audio) ? await ctx.fetchMedia(inp.audio) : inp.audio;
324
+ const audioPart = audioSrc ? audioInputPart(audioSrc) : null;
325
+ const messages = chatMessages(n, prompt, imgs, audioPart);
326
+ return { text: await ctx.chat(messages, mdl(n), llmOpts(n)) };
327
+ },
328
+
329
+ async vision(n, inp, ctx) {
330
+ if (!inp.image) throw new NanoodleError("no image input");
331
+ const q = (n.fields.q || "Describe this image.").trim();
332
+ const messages = [{
333
+ role: "user",
334
+ content: [{ type: "text", text: q }, { type: "image_url", image_url: { url: inp.image } }],
335
+ }];
336
+ return { text: await ctx.chat(messages, mdl(n), {}) };
337
+ },
338
+
339
+ async image(n, inp, ctx) {
340
+ const prompt = promptOf(n, inp, "no prompt");
341
+ const want = Math.max(1, parseInt(n.fields.variations, 10) || 1);
342
+ const urls = await ctx.image({ prompt, model: mdl(n), size: n.fields.size || "1024x1024", extra: imgExtra(n), n: want, multi: true });
343
+ const sel = Math.min(Math.max(0, parseInt(n.fields.sel, 10) || 0), urls.length - 1);
344
+ return { image: urls[sel], images: urls };
345
+ },
346
+
347
+ async edit(n, inp, ctx) {
348
+ const imgs = collectPorts(inp, EDIT_IMG_RE);
349
+ if (!imgs.length) throw new NanoodleError("no image input");
350
+ const prompt = promptOf(n, inp);
351
+ if (!prompt && !/upscal/i.test(n.fields.model || "")) throw new NanoodleError("no edit instruction");
352
+ guardRefsSize(imgs);
353
+ const src = imgs.length > 1 ? imgs : imgs[0]; // array → multi-image composite; string → single edit
354
+ return { image: await ctx.image({ prompt, model: mdl(n), size: n.fields.size || "1024x1024", imageDataUrl: src, extra: imgExtra(n) }) };
355
+ },
356
+
357
+ async draw(n, inp, ctx) {
358
+ const prompt = promptOf(n, inp, "no prompt");
359
+ const imgs = collectPorts(inp, IMG_PORT_RE);
360
+ guardRefsSize(imgs);
361
+ const messages = chatMessages(n, prompt, imgs, null);
362
+ const res = await ctx.chatImage(messages, mdl(n), {});
363
+ const sel = Math.min(Math.max(0, parseInt(n.fields.sel, 10) || 0), res.images.length - 1);
364
+ const showThinking = n.fields.showThinking !== false && n.fields.showThinking !== "false";
365
+ const text = showThinking && res.reasoning
366
+ ? "```thinking\n" + res.reasoning + "\n```\n\n" + (res.text || "")
367
+ : res.text;
368
+ return { image: res.images[sel], images: res.images, text };
369
+ },
370
+
371
+ async inpaint(n, inp, ctx) {
372
+ const source = inp.image != null ? inp.image : n.fields.image;
373
+ const mask = inp.mask != null ? inp.mask : n.fields.mask;
374
+ if (!source) throw new NanoodleError("no image — supply the image to repaint");
375
+ if (!mask) throw new NanoodleError("no mask — supply a B/W mask (white = repaint)");
376
+ const prompt = promptOf(n, inp, "no prompt — say what to paint into the masked area");
377
+ // v1 caveat: the browser app composites the mask onto black at source size; here it passes through verbatim
378
+ return { image: await ctx.image({ prompt, model: mdl(n), size: n.fields.size || "1024x1024", imageDataUrl: source, maskDataUrl: mask, extra: imgExtra(n) }) };
379
+ },
380
+
381
+ async tvideo(n, inp, ctx) {
382
+ const prompt = promptOf(n, inp, "no prompt");
383
+ const opts = { ...videoDims(n), lora: loraParams(n), extra: n.fields.modelOpts || {} };
384
+ const refs = collectPorts(inp, REF_PORT_RE);
385
+ if (refs.length) { opts.refImages = refs; opts.refKey = "reference_images"; }
386
+ return { video: await ctx.video(mdl(n), prompt, opts, null) };
387
+ },
388
+
389
+ async ivideo(n, inp, ctx) {
390
+ if (!inp.image) throw new NanoodleError("no image input");
391
+ const prompt = promptOf(n, inp);
392
+ const opts = { ...videoDims(n), lora: loraParams(n), extra: n.fields.modelOpts || {} };
393
+ if (inp.endframe) opts.last_image = inp.endframe;
394
+ return { video: await ctx.video(mdl(n), prompt, opts, inp.image) };
395
+ },
396
+
397
+ async vedit(n, inp, ctx) {
398
+ if (!inp.video) throw new NanoodleError("no video input");
399
+ const prompt = promptOf(n, inp);
400
+ const opts = { ...videoSourceOpts(inp.video), ...videoDims(n), lora: loraParams(n), extra: n.fields.modelOpts || {} };
401
+ return { video: await ctx.video(mdl(n), prompt, opts, null) };
402
+ },
403
+
404
+ async lipsync(n, inp, ctx) {
405
+ if (!inp.image) throw new NanoodleError("no image input");
406
+ if (!inp.audio) throw new NanoodleError("no audio input");
407
+ const prompt = promptOf(n, inp);
408
+ const opts = { ...audioSourceOpts(inp.audio), ...videoDims(n), extra: n.fields.modelOpts || {} };
409
+ return { video: await ctx.video(mdl(n), prompt, opts, inp.image) };
410
+ },
411
+
412
+ async music(n, inp, ctx) {
413
+ const text = promptOf(n, inp, "no prompt — describe the track");
414
+ return { audio: await ctx.audio(mdl(n), text, audioParams(n)) };
415
+ },
416
+
417
+ async tts(n, inp, ctx) {
418
+ const text = promptOf(n, inp, "no text — give the Speech node something to say");
419
+ return { audio: await ctx.audio(mdl(n), text, audioParams(n)) };
420
+ },
421
+
422
+ async remix(n, inp, ctx) {
423
+ if (!inp.audio) throw new NanoodleError("no audio — wire a source track into the audio port");
424
+ const text = promptOf(n, inp, "no prompt — describe the cover / extension first");
425
+ const params = audioParams(n);
426
+ // https source rides as-is (providers take hosted URLs); local data: is inlined
427
+ if (/^https?:/i.test(inp.audio)) params.audio = inp.audio;
428
+ else {
429
+ if (inp.audio.length > MEDIA_INLINE_MAX) {
430
+ throw new NanoodleError("source audio is too large to inline (~4 MB send limit) — use a shorter clip");
431
+ }
432
+ params.audio = inp.audio;
433
+ }
434
+ return { audio: await ctx.audio(mdl(n), text, params) };
435
+ },
436
+
437
+ async transcribe(n, inp, ctx) {
438
+ if (!inp.audio) throw new NanoodleError("no audio input");
439
+ return { text: await ctx.transcribe(mdl(n), inp.audio, (n.fields.language || "auto").trim()) };
440
+ },
441
+ };