@nodaro/prompts 1.30.0 → 1.33.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodaro/prompts",
3
- "version": "1.30.0",
3
+ "version": "1.33.0",
4
4
  "description": "Nodaro's prompt-engineering layer — person/picker catalogs with prompt hints, identity-lock clauses, entity prompt builders, brand presets, and prompt/reference assembly shared by the Nodaro platform and SDK.",
5
5
  "type": "module",
6
6
  "license": "FSL-1.1-Apache-2.0",
@@ -20,7 +20,7 @@
20
20
  "test": "vitest run"
21
21
  },
22
22
  "dependencies": {
23
- "@nodaro/shared": "^3.19.0"
23
+ "@nodaro/shared": "^3.24.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "tsup": "^8.5.0",
@@ -270,3 +270,35 @@ describe("targeted gap coverage: facial-geometry + brand camera/render entries",
270
270
  }
271
271
  })
272
272
  })
273
+
274
+ // ---------------------------------------------------------------------------
275
+ // Test 4 — the Camera Motion and Transition pickers carry a LABEL for every
276
+ // option in Japanese and Brazilian Portuguese. Fourteen camera motions (Dolly
277
+ // In, Zoom In, POV, …) had a translated description but no label in pt-BR, so
278
+ // the editor and the docs gallery (which syncs these sidecars) showed the
279
+ // English name. A rig or brand name keeps its canonical form as an explicit
280
+ // label (Steadicam, Snorricam) — a present label is the decision; a missing one
281
+ // is the bug. Scoped to the two locales whose docs pages are held to "no English
282
+ // apart from model names"; extend the list when another locale is held to it.
283
+ // ---------------------------------------------------------------------------
284
+
285
+ const FULL_LABEL_CATALOGS = ["camera-motions", "transitions"] as const
286
+ const FULL_LABEL_LOCALES: readonly LocaleId[] = ["ja", "pt-BR"]
287
+
288
+ describe("Camera Motion and Transition labels are complete in ja and pt-BR", () => {
289
+ const cases: Array<[string, LocaleId]> = []
290
+ for (const catalogId of FULL_LABEL_CATALOGS) {
291
+ for (const locale of FULL_LABEL_LOCALES) cases.push([catalogId, locale])
292
+ }
293
+
294
+ it.each(cases)("%s [%s] labels every entry", (catalogId, locale) => {
295
+ const catalog = CATALOGS.find((c) => c.catalogId === catalogId)
296
+ expect(catalog, `${catalogId} is not a registered picker catalog`).toBeDefined()
297
+ const map = mapFor(catalogId, locale)
298
+ const unlabelled = (catalog?.options ?? []).filter((o) => !has(map[o.id]?.label)).map((o) => o.id)
299
+ expect(
300
+ unlabelled,
301
+ `packages/shared/src/i18n/${catalogId}.${locale}.ts has no label for these ids, so the picker shows the English name`,
302
+ ).toEqual([])
303
+ })
304
+ })
@@ -0,0 +1,100 @@
1
+ import { describe, expect, it } from "vitest"
2
+ import { TEXT_REQUIRED_NODE_TYPES, computeAiWriterInput, computeNodeSendText } from "../node-send-text.js"
3
+
4
+ /**
5
+ * "What text would this node send?" — answered by the executor's own prompt
6
+ * rule per type, so the orchestrator's empty-input skip can never disagree
7
+ * with the request the node would make.
8
+ */
9
+ const none = new Map<string, string>()
10
+
11
+ describe("computeNodeSendText", () => {
12
+ it("answers for every text-requiring type and for no other (totality)", () => {
13
+ for (const type of TEXT_REQUIRED_NODE_TYPES) {
14
+ expect(typeof computeNodeSendText(type, {}, { refMap: none }), type).toBe("string")
15
+ }
16
+ // Video nodes and social posts stay out: an empty prompt on an image-to-video is a legal request, an empty caption the author's choice.
17
+ expect(computeNodeSendText("image-to-video", {}, { refMap: none })).toBeUndefined()
18
+ expect(computeNodeSendText("combine-text", { text: "x" }, { refMap: none })).toBeUndefined()
19
+ expect(computeNodeSendText("telegram-post", {}, { refMap: none })).toBeUndefined()
20
+ })
21
+
22
+ it("llm-chat: the wired text when the node typed none; nothing when both are empty; a typed prompt runs on its own", () => {
23
+ expect(computeNodeSendText("llm-chat", {}, { wired: "the posts", refMap: none })).toBe("the posts")
24
+ expect(computeNodeSendText("llm-chat", {}, { wired: "", refMap: none })).toBe("")
25
+ expect(computeNodeSendText("llm-chat", {}, { refMap: none })).toBe("")
26
+ expect(computeNodeSendText("llm-chat", { userInput: "Write a poem" }, { wired: "", refMap: none })).toContain("Write a poem")
27
+ })
28
+
29
+ it("llm-chat: a fan-out item outranks the wire", () => {
30
+ expect(computeNodeSendText("llm-chat", {}, { override: "item 1", wired: "all", refMap: none })).toBe("item 1")
31
+ })
32
+
33
+ it("llm-chat: a typed template whose {Ref} resolves to nothing is still a non-empty request (the stated residual)", () => {
34
+ const refMap = new Map([["Feed", ""]])
35
+ const text = computeNodeSendText("llm-chat", { userInput: "Summarize: {Feed}" }, { wired: "", refMap })
36
+ expect(text?.trim().length).toBeGreaterThan(0)
37
+ })
38
+
39
+ it("ai-writer: a fan-out item, else the wire, else the typed userInput, else the legacy prompt", () => {
40
+ expect(computeAiWriterInput({ userInput: "typed", prompt: "legacy" }, { override: "item", wired: "wire" })).toBe("item")
41
+ expect(computeAiWriterInput({ userInput: "typed", prompt: "legacy" }, { wired: "wire" })).toBe("wire")
42
+ expect(computeAiWriterInput({ userInput: "typed", prompt: "legacy" }, { wired: " " })).toBe("typed")
43
+ expect(computeAiWriterInput({ prompt: "legacy" }, {})).toBe("legacy")
44
+ expect(computeAiWriterInput({}, { wired: "" })).toBe("")
45
+ expect(computeNodeSendText("ai-writer", {}, { wired: "", refMap: none })).toBe("")
46
+ })
47
+
48
+ it("generate-script: the topic is the wire or the typed prompt", () => {
49
+ expect(computeNodeSendText("generate-script", { prompt: "a cat" }, { refMap: none })).toContain("a cat")
50
+ expect(computeNodeSendText("generate-script", {}, { wired: "", refMap: none })).toBe("")
51
+ })
52
+
53
+ it("generate-music: typed lyrics count as something to send when the prompt is empty", () => {
54
+ expect(computeNodeSendText("generate-music", { lyrics: "la la" }, { wired: "", refMap: none })).toBe("la la")
55
+ expect(computeNodeSendText("generate-music", {}, { wired: "", refMap: none })).toBe("")
56
+ })
57
+
58
+ it("collection-write: the item (a fan-out row, else the wire), else a typed title / text / link; nothing of those is nothing to save", () => {
59
+ const refMap = new Map<string, string>()
60
+ expect(computeNodeSendText("collection-write", {}, { wired: "", refMap })).toBe("")
61
+ expect(computeNodeSendText("collection-write", { title: " " }, { wired: "", refMap })).toBe("")
62
+ expect(computeNodeSendText("collection-write", { link: "https://news.example.test/daily" }, { wired: "", refMap })).toBe("https://news.example.test/daily")
63
+ expect(computeNodeSendText("collection-write", { title: "Daily" }, { wired: "the wire", refMap })).toBe("the wire")
64
+ expect(computeNodeSendText("collection-write", {}, { override: "row 3", wired: "the wire", refMap })).toBe("row 3")
65
+ })
66
+
67
+ it("collection-write: a typed field counts with its {Node} references resolved, as the engines send it (#1890)", () => {
68
+ const empty = new Map<string, string>()
69
+ // A feed with nothing new: an empty fallback is nothing to save, so the node skips.
70
+ expect(computeNodeSendText("collection-write", { title: "{Feed || }" }, { wired: "", refMap: empty })).toBe("")
71
+ expect(computeNodeSendText("collection-write", { title: "{Feed || untitled}" }, { wired: "", refMap: empty })).toBe("untitled")
72
+ expect(computeNodeSendText("collection-write", { title: "Breaking: {Feed}" }, { wired: "", refMap: new Map([["feed", "Telegram turns ten"]]) }))
73
+ .toBe("Breaking: Telegram turns ten")
74
+ })
75
+
76
+ it("prompt pre/post text never counts as something to send: an empty core with a prefix is nothing", () => {
77
+ const refMap = new Map<string, string>()
78
+ const affixed = { userInput: "", promptPrefix: "Write a news item about:", promptSuffix: "Keep it short." }
79
+ expect(computeNodeSendText("llm-chat", affixed, { wired: "", refMap })).toBe("")
80
+ expect(computeNodeSendText("generate-script", { prompt: "", promptPrefix: "Topic:" }, { wired: "", refMap })).toBe("")
81
+ expect(computeNodeSendText("text-to-speech", { promptPrefix: "Say:" }, { wired: "", refMap })).toBe("")
82
+ // With a core, the decision is on the core — non-empty either way.
83
+ expect(computeNodeSendText("llm-chat", affixed, { wired: "the posts", refMap })).not.toBe("")
84
+ })
85
+
86
+ it("generate-image: the prompt it would send (a fan-out row, else the wire, else the typed prompt); nothing of those is nothing", () => {
87
+ const refMap = new Map<string, string>()
88
+ expect(computeNodeSendText("generate-image", { prompt: "" }, { wired: "", refMap })).toBe("")
89
+ expect(computeNodeSendText("generate-image", { prompt: "a city at dusk" }, { wired: "", refMap })).toBe("a city at dusk")
90
+ expect(computeNodeSendText("generate-image", { prompt: "" }, { wired: "a cover for the story", refMap })).toBe("a cover for the story")
91
+ expect(computeNodeSendText("generate-image", { prompt: "", promptPrefix: "Photo of" }, { wired: "", refMap })).toBe("")
92
+ })
93
+
94
+ it("text-to-speech / text-to-audio: the wired text passes through; nothing wired and nothing typed is nothing", () => {
95
+ expect(computeNodeSendText("text-to-speech", {}, { wired: "read this", refMap: none })).toContain("read this")
96
+ expect(computeNodeSendText("text-to-speech", {}, { wired: "", refMap: none })).toBe("")
97
+ expect(computeNodeSendText("text-to-audio", {}, { wired: "rain", refMap: none })).toContain("rain")
98
+ expect(computeNodeSendText("text-to-audio", {}, { refMap: none })).toBe("")
99
+ })
100
+ })
@@ -321,5 +321,7 @@ describe("blended cut — the rule holds for every row and lever (self-consisten
321
321
  check([a, b], levers(position, duration, "natural"), "clip")
322
322
  }
323
323
  }
324
- })
324
+ // An exhaustive sweep: under a second locally, but past vitest's 5 s default
325
+ // on a loaded 2-vCPU CI runner (it timed out there three times on 2026-10-05).
326
+ }, 60_000)
325
327
  })
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Remove inline `[audio tags]` from speech text, for a model that does not
3
+ * perform them (it would read them aloud). Pure, dependency-free: the
4
+ * backend's credit counter (lib/speech-credits.ts), its payload builder and
5
+ * the editor's estimate (frontend/src/lib/speech-estimate.ts) all read it, so
6
+ * the two engines count exactly the same characters.
7
+ *
8
+ * A tag is `[`, one or more characters that are not `]`, then `]` — what
9
+ * `/\[[^\]]+\]/g` matches. That pattern is quadratic on an unclosed run of `[`
10
+ * (every `[` rescans to the end of the text), and the credit counter runs this
11
+ * on raw request text on the API and orchestrator event loops, so the scan is
12
+ * written by hand: one `indexOf` per `[`, and when no `]` is left no later `[`
13
+ * can match either, so the rest of the text is kept in one slice.
14
+ */
15
+ function removeBracketTags(text: string): string {
16
+ let out = ""
17
+ let from = 0
18
+ let open = text.indexOf("[")
19
+ while (open !== -1) {
20
+ const close = text.indexOf("]", open + 1)
21
+ if (close === -1) break
22
+ if (close === open + 1) {
23
+ // "[]" is not a tag (needs 1+ characters); the "[" stays and the scan moves on.
24
+ open = text.indexOf("[", open + 1)
25
+ continue
26
+ }
27
+ out += text.slice(from, open)
28
+ from = close + 1
29
+ open = text.indexOf("[", from)
30
+ }
31
+ return out + text.slice(from)
32
+ }
33
+
34
+ export function stripAudioTags(text: string): string {
35
+ return removeBracketTags(text).replace(/\s{2,}/g, " ").trim()
36
+ }
package/src/index.ts CHANGED
@@ -86,6 +86,7 @@ export * from "./image-reference-doctrine.js"
86
86
  export * from "./scene3d-reference-doctrine.js"
87
87
  export * from "./prompt-wizard-categories.js"
88
88
  export * from "./resolve-prompt.js"
89
+ export { stripAudioTags } from "./audio-tags.js"
89
90
  export * from "./node-prompt-fields.js"
90
91
  export * from "./factory-presets.js"
91
92
  export * from "./caption-treatments.js"
@@ -104,3 +105,6 @@ export * from "./ad-creative-analysis.js"
104
105
 
105
106
  // --- Picker art: option pictures + topic icons (editor and API) ---
106
107
  export * from "./picker-art/index.js"
108
+
109
+ // --- What a text-requiring node would send (the orchestrator's empty-input skip reads it) ---
110
+ export * from "./node-send-text.js"
@@ -0,0 +1,125 @@
1
+ import { resolveNodeRefs, SOCIAL_POST_NODE_TYPES } from "@nodaro/shared"
2
+ import { computeLlmChatFields, computeNodePrompt, computeScriptTopic } from "./resolve-prompt.js"
3
+
4
+ /**
5
+ * Output nodes that send exactly what is WIRED into them — a webhook's
6
+ * parameters, a social post's caption and media. When every wire produced
7
+ * nothing in this run (a Filter List that kept no row, a node that was itself
8
+ * skipped), there is nothing to send: the node is skipped with
9
+ * `skipReason: "empty_input"` instead of posting an empty payload (a site that
10
+ * validates its input answers 400 and alerts its owner) or failing the run
11
+ * (a publish route refuses a post with no text and no media). A typed caption
12
+ * with no wire at all is the author's choice and still runs, as before. ONE
13
+ * list, read by the orchestrator's skip rule (`empty-input-skips.ts`).
14
+ */
15
+ export const WIRED_OUTPUT_NODE_TYPES: ReadonlySet<string> = new Set(["webhook-output", ...SOCIAL_POST_NODE_TYPES])
16
+
17
+ /**
18
+ * Node types that send TEXT to a model or a voice and fail on an empty one —
19
+ * `userInput: Too small` (llm-chat), "no text found" (text-to-speech) — so a
20
+ * run with nothing upstream can skip them instead of failing. Never an image
21
+ * or video node (an empty prompt is a legal request there) and never a social
22
+ * post (an empty caption is the author's choice). ONE list, read by the
23
+ * orchestrator's skip rule (`empty-input-skips.ts`); the engine never names a
24
+ * type on its own.
25
+ */
26
+ export const TEXT_REQUIRED_NODE_TYPES: ReadonlySet<string> = new Set([
27
+ "llm-chat",
28
+ "ai-writer",
29
+ "generate-script",
30
+ "text-to-speech",
31
+ "generate-music",
32
+ "text-to-audio",
33
+ // Save to Collection refuses an empty record ("nothing to save"): a feed
34
+ // with nothing new wired straight into it must skip it, not fail the run.
35
+ "collection-write",
36
+ // Generate Image: an empty prompt is a legal request in general (references
37
+ // alone), but when the text it was WIRED produced nothing this run — the skip
38
+ // rule's precondition — an empty prompt is a paid picture of nothing.
39
+ "generate-image",
40
+ ])
41
+
42
+ /**
43
+ * The node's data without its prompt pre/post text: the skip decision is about
44
+ * the CORE text. A prefix alone ("Write a news item about:") is not something
45
+ * to send — with the affixes applied, an empty core read as non-empty and an
46
+ * idle tick paid for a model call on the prefix.
47
+ */
48
+ const withoutAffixes = (data: Record<string, unknown>): Record<string, unknown> => ({ ...data, promptPrefix: undefined, promptSuffix: undefined })
49
+
50
+ export interface NodeSendTextArgs {
51
+ /** A list fan-out item (highest precedence). */
52
+ override?: string
53
+ /** The text wired into the node's main text input. */
54
+ wired?: string
55
+ /** llm-chat only: the text wired into `system-prompt`. */
56
+ wiredSystemPrompt?: string
57
+ refMap: ReadonlyMap<string, string>
58
+ }
59
+
60
+ const present = (s?: string): s is string => typeof s === "string" && s.trim().length > 0
61
+
62
+ /**
63
+ * ai-writer's user input — the rule its sync-HTTP body applies: a fan-out
64
+ * item, else the wired text, else the typed `userInput`, else the legacy
65
+ * `prompt`. (ai-writer is renamed to llm-chat on load; saved graphs that
66
+ * never reloaded still run it.)
67
+ */
68
+ export function computeAiWriterInput(
69
+ data: Record<string, unknown>,
70
+ { override, wired }: Pick<NodeSendTextArgs, "override" | "wired">,
71
+ ): string {
72
+ return [override, wired, data.userInput as string | undefined, data.prompt as string | undefined].find(present) ?? ""
73
+ }
74
+
75
+ /**
76
+ * The text a text-requiring node would send, by the SAME rule its executor
77
+ * uses (`computeLlmChatFields`, `computeScriptTopic`, `computeNodePrompt`,
78
+ * `computeAiWriterInput`) — so "would this node run on nothing?" is answered
79
+ * by the function that decides what it sends, not by a second reading of it.
80
+ * Undefined for any other node type.
81
+ */
82
+ export function computeNodeSendText(
83
+ nodeType: string,
84
+ data: Record<string, unknown>,
85
+ args: NodeSendTextArgs,
86
+ ): string | undefined {
87
+ const bare = withoutAffixes(data)
88
+ switch (nodeType) {
89
+ case "llm-chat":
90
+ return computeLlmChatFields(bare, {
91
+ override: args.override,
92
+ wiredUserInput: args.wired,
93
+ wiredSystemPrompt: args.wiredSystemPrompt,
94
+ refMap: args.refMap,
95
+ }).userInput
96
+ case "ai-writer":
97
+ return computeAiWriterInput(bare, args)
98
+ case "generate-script":
99
+ return computeScriptTopic(bare, { override: args.override, wired: args.wired, refMap: args.refMap })
100
+ case "generate-music": {
101
+ // A music node sings typed lyrics with no prompt; only both empty is nothing to send.
102
+ const prompt = computeNodePrompt(nodeType, bare, { override: args.override, wired: args.wired, refMap: args.refMap })
103
+ return present(prompt) ? prompt : present(data.lyrics as string | undefined) ? (data.lyrics as string) : ""
104
+ }
105
+ case "text-to-speech":
106
+ case "text-to-audio":
107
+ case "generate-image":
108
+ return computeNodePrompt(nodeType, bare, { override: args.override, wired: args.wired, refMap: args.refMap })
109
+ case "collection-write": {
110
+ // The record's content: the item (a fan-out row, else what reached `in`),
111
+ // else a title, text or link typed on the node. A picture alone is a
112
+ // record too, but it never starves the node: only a wired TEXT input that
113
+ // produced nothing can (the skip rule's precondition).
114
+ // A typed field counts as the engines send it, its `{Node}` references
115
+ // resolved: `{Feed || }` over a feed with nothing new is empty, so the
116
+ // node skips instead of failing with an empty record (#1890).
117
+ const typed = [data.title, data.text, data.link]
118
+ .map((v) => (typeof v === "string" ? resolveNodeRefs(v, args.refMap) : v))
119
+ .find((v): v is string => present(v as string | undefined))
120
+ return [args.override, args.wired, typed].find(present) ?? ""
121
+ }
122
+ default:
123
+ return undefined
124
+ }
125
+ }