@nodaro/shared 3.14.0 → 3.16.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.
Files changed (142) hide show
  1. package/dist/index.cjs +1293 -55
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +1483 -30
  4. package/dist/index.d.ts +1483 -30
  5. package/dist/index.js +1134 -56
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/__tests__/camera-switch-contract.test.ts +98 -0
  9. package/src/__tests__/competitors.test.ts +49 -0
  10. package/src/__tests__/content-recipe-ideas.test.ts +96 -0
  11. package/src/__tests__/edl-multicam.test.ts +192 -0
  12. package/src/__tests__/llm-models.test.ts +5 -2
  13. package/src/__tests__/music-provider.test.ts +17 -0
  14. package/src/__tests__/node-runtime-keys.test.ts +10 -0
  15. package/src/__tests__/parameter-node-value.test.ts +2 -1
  16. package/src/__tests__/per-unit-video-pricing.test.ts +97 -0
  17. package/src/__tests__/producer-types.test.ts +35 -0
  18. package/src/__tests__/saved-posts.test.ts +37 -0
  19. package/src/__tests__/script-settings.test.ts +61 -0
  20. package/src/__tests__/settings-input.test.ts +252 -0
  21. package/src/__tests__/social-search.test.ts +243 -0
  22. package/src/__tests__/studio-take-voice.test.ts +200 -0
  23. package/src/__tests__/studio-transient.test.ts +37 -0
  24. package/src/__tests__/sub-gates.test.ts +21 -0
  25. package/src/__tests__/telegram-account-trigger.test.ts +120 -0
  26. package/src/__tests__/video-analysis-pricing.test.ts +27 -13
  27. package/src/__tests__/video-link.test.ts +2 -2
  28. package/src/__tests__/video-utils.test.ts +89 -83
  29. package/src/__tests__/workflow-export-strip.test.ts +37 -0
  30. package/src/camera-switch-contract.ts +166 -0
  31. package/src/catalog-projection.ts +7 -0
  32. package/src/competitors.ts +430 -0
  33. package/src/content-recipe-ideas.ts +69 -0
  34. package/src/credit-estimators/index.ts +14 -0
  35. package/src/credit-estimators/ltx-extend.ts +33 -0
  36. package/src/credit-estimators/ltx-retake.ts +30 -0
  37. package/src/credit-estimators/video-sfx.ts +41 -0
  38. package/src/credit-estimators/video-utils.ts +38 -24
  39. package/src/credit-identifiers.ts +10 -0
  40. package/src/edl-multicam.ts +220 -0
  41. package/src/fan-out-rows.ts +7 -2
  42. package/src/i18n/action-fx.ko.ts +18 -18
  43. package/src/i18n/action-fx.pt-BR.ts +66 -66
  44. package/src/i18n/aesthetic.ko.ts +49 -49
  45. package/src/i18n/aesthetic.pt-BR.ts +14 -14
  46. package/src/i18n/animals.ko.ts +126 -126
  47. package/src/i18n/animals.pt-BR.ts +33 -33
  48. package/src/i18n/atmosphere.ko.ts +37 -37
  49. package/src/i18n/atmosphere.pt-BR.ts +29 -29
  50. package/src/i18n/backdrop.ko.ts +40 -40
  51. package/src/i18n/backdrop.pt-BR.ts +38 -38
  52. package/src/i18n/camera-format.ko.ts +31 -31
  53. package/src/i18n/camera-format.pt-BR.ts +12 -12
  54. package/src/i18n/camera-motions.ko.ts +66 -66
  55. package/src/i18n/camera-motions.pt-BR.ts +51 -51
  56. package/src/i18n/character-fx.ko.ts +19 -19
  57. package/src/i18n/character-fx.pt-BR.ts +64 -52
  58. package/src/i18n/character-motion.ko.ts +164 -164
  59. package/src/i18n/character-motion.pt-BR.ts +867 -858
  60. package/src/i18n/color-look.ko.ts +41 -41
  61. package/src/i18n/color-look.pt-BR.ts +23 -23
  62. package/src/i18n/composition-effects.ko.ts +18 -18
  63. package/src/i18n/composition-effects.pt-BR.ts +17 -17
  64. package/src/i18n/era.ko.ts +28 -28
  65. package/src/i18n/era.pt-BR.ts +20 -20
  66. package/src/i18n/exposure-settings.ko.ts +20 -20
  67. package/src/i18n/exposure-settings.pt-BR.ts +3 -3
  68. package/src/i18n/framing.ko.ts +66 -66
  69. package/src/i18n/framing.pt-BR.ts +50 -50
  70. package/src/i18n/furniture.ko.ts +78 -78
  71. package/src/i18n/furniture.pt-BR.ts +46 -46
  72. package/src/i18n/held-prop.ko.ts +60 -60
  73. package/src/i18n/held-prop.pt-BR.ts +30 -30
  74. package/src/i18n/instrumentation.ko.ts +62 -62
  75. package/src/i18n/instrumentation.pt-BR.ts +64 -64
  76. package/src/i18n/lens.ko.ts +16 -16
  77. package/src/i18n/lens.pt-BR.ts +5 -5
  78. package/src/i18n/lighting.ko.ts +68 -68
  79. package/src/i18n/lighting.pt-BR.ts +43 -43
  80. package/src/i18n/loop-subject.ko.ts +1 -1
  81. package/src/i18n/loop-subject.pt-BR.ts +31 -31
  82. package/src/i18n/materials.ko.ts +66 -66
  83. package/src/i18n/materials.pt-BR.ts +22 -22
  84. package/src/i18n/mood.ko.ts +50 -50
  85. package/src/i18n/mood.pt-BR.ts +12 -12
  86. package/src/i18n/music-genre.ko.ts +28 -28
  87. package/src/i18n/music-genre.pt-BR.ts +50 -50
  88. package/src/i18n/music-mood.ko.ts +27 -27
  89. package/src/i18n/music-mood.pt-BR.ts +20 -20
  90. package/src/i18n/person.ko.ts +396 -396
  91. package/src/i18n/person.pt-BR.ts +237 -237
  92. package/src/i18n/photo-genre.ko.ts +46 -46
  93. package/src/i18n/photo-genre.pt-BR.ts +32 -32
  94. package/src/i18n/photographer.ko.ts +63 -63
  95. package/src/i18n/photographer.pt-BR.ts +15 -15
  96. package/src/i18n/pose.ko.ts +81 -81
  97. package/src/i18n/pose.pt-BR.ts +65 -65
  98. package/src/i18n/post-process-effects.ko.ts +18 -18
  99. package/src/i18n/post-process-effects.pt-BR.ts +18 -18
  100. package/src/i18n/render-quality.ko.ts +24 -24
  101. package/src/i18n/render-quality.pt-BR.ts +12 -12
  102. package/src/i18n/setting.ko.ts +64 -64
  103. package/src/i18n/setting.pt-BR.ts +41 -41
  104. package/src/i18n/style.ko.ts +49 -49
  105. package/src/i18n/style.pt-BR.ts +19 -19
  106. package/src/i18n/styling.ko.ts +265 -265
  107. package/src/i18n/styling.pt-BR.ts +141 -141
  108. package/src/i18n/temporal.ko.ts +18 -18
  109. package/src/i18n/temporal.pt-BR.ts +12 -12
  110. package/src/i18n/transitions.ko.ts +14 -14
  111. package/src/i18n/transitions.pt-BR.ts +83 -71
  112. package/src/i18n/vehicles.ko.ts +107 -107
  113. package/src/i18n/vehicles.pt-BR.ts +55 -55
  114. package/src/i18n/voice-character.ko.ts +19 -19
  115. package/src/i18n/voice-character.pt-BR.ts +19 -19
  116. package/src/i18n/voice-delivery.ko.ts +22 -22
  117. package/src/i18n/voice-delivery.pt-BR.ts +22 -22
  118. package/src/i18n/weapons.ko.ts +85 -85
  119. package/src/i18n/weapons.pt-BR.ts +46 -46
  120. package/src/index.ts +202 -1
  121. package/src/llm-models.ts +11 -0
  122. package/src/model-catalog.ts +30 -14
  123. package/src/model-constants.ts +28 -0
  124. package/src/node-mappable-fields.ts +21 -5
  125. package/src/node-runtime-keys.ts +33 -0
  126. package/src/oauth-scopes.ts +28 -0
  127. package/src/parameter-node-value.ts +13 -5
  128. package/src/pipeline-defaults.ts +14 -0
  129. package/src/pipeline-state-types.ts +14 -0
  130. package/src/producer-types.ts +85 -0
  131. package/src/recast-segment-packs.ts +13 -0
  132. package/src/resolve-field-mappings.ts +15 -5
  133. package/src/saved-posts.ts +106 -0
  134. package/src/script-settings.ts +70 -0
  135. package/src/settings-input.ts +366 -0
  136. package/src/social-search.ts +467 -0
  137. package/src/studio-transient.ts +176 -5
  138. package/src/telegram-account-send.ts +32 -0
  139. package/src/telegram-account-trigger.ts +108 -0
  140. package/src/video-analysis-pricing.ts +17 -6
  141. package/src/video-link.ts +16 -4
  142. package/src/workflow-export.ts +7 -0
@@ -0,0 +1,366 @@
1
+ /**
2
+ * The "Settings" input: ONE input handle on a generation node that takes the
3
+ * Generation Settings nodes. Aspect Ratio, Duration and Provider set the
4
+ * consumer's own field; Motion adds a clause to its prompt. The editor shows it
5
+ * as a single pip, with the connected values listed inside the node.
6
+ *
7
+ * Every reader goes through this module, so they cannot disagree about what a
8
+ * node runs with: both run engines (their field-mapping wrappers ask
9
+ * `settingsSourceForField` which wired node sets a field, then
10
+ * `applySettingsInput` fits the values to the model), and the readers that
11
+ * run before any resolver — the workflow estimate, the node's chips and its
12
+ * settings panel — through `resolveWiredSettings`. A new setting or consumer
13
+ * is one row here.
14
+ */
15
+
16
+ import { MODEL_CATALOG, fitAspectRatioToModel } from "./model-catalog.js"
17
+ import { DEFAULT_VIDEO_PROVIDER, GVP_DEFAULT_PROVIDER, GVP_SUPPORTED_PROVIDERS, IMAGE_GEN_PROVIDERS, VIDEO_GEN_PROVIDERS } from "./model-constants.js"
18
+ import { getParameterValue } from "./parameter-node-value.js"
19
+ import { isAutoVideoDuration } from "./video-duration-auto.js"
20
+
21
+ /** The handle id of the Settings input. */
22
+ export const SETTINGS_INPUT_HANDLE = "settings"
23
+
24
+ /** A Generation Settings node type → the consumer data field it sets. */
25
+ export const SETTINGS_SOURCE_FIELDS = {
26
+ "aspect-ratio": "aspectRatio",
27
+ duration: "duration",
28
+ provider: "provider",
29
+ } as const
30
+
31
+ /**
32
+ * Generation Settings nodes a Settings input takes as a prompt CLAUSE rather
33
+ * than a field: Motion (how much the shot moves). Each engine's hint collector
34
+ * adds its clause beside the Look family's, under the same Inject Look switch
35
+ * (`isSettingsHintEdge`).
36
+ */
37
+ export const SETTINGS_HINT_SOURCES = ["motion"] as const
38
+
39
+ export type SettingsFieldSourceType = keyof typeof SETTINGS_SOURCE_FIELDS
40
+ export type SettingsHintSourceType = (typeof SETTINGS_HINT_SOURCES)[number]
41
+ export type SettingsSourceType = SettingsFieldSourceType | SettingsHintSourceType
42
+ export type SettingsField = (typeof SETTINGS_SOURCE_FIELDS)[SettingsFieldSourceType]
43
+
44
+ /** Every Generation Settings node type a Settings input can take. */
45
+ export const SETTINGS_SOURCE_TYPES: readonly SettingsSourceType[] = [
46
+ ...(Object.keys(SETTINGS_SOURCE_FIELDS) as SettingsFieldSourceType[]),
47
+ ...SETTINGS_HINT_SOURCES,
48
+ ]
49
+
50
+ /** The consumer field a setting sets; none for a prompt-clause setting. */
51
+ function fieldOf(sourceType: SettingsSourceType): SettingsField | undefined {
52
+ return Object.prototype.hasOwnProperty.call(SETTINGS_SOURCE_FIELDS, sourceType)
53
+ ? SETTINGS_SOURCE_FIELDS[sourceType as SettingsFieldSourceType]
54
+ : undefined
55
+ }
56
+
57
+ /**
58
+ * A node with a Settings input:
59
+ * - `accepts`: the settings it takes, in the order its chips show them;
60
+ * - `models`: the models a wired Provider may name — a Provider node can hold
61
+ * any category's model, and this node runs only these;
62
+ * - `defaultModel`: the model it renders with when its data names none;
63
+ * - `duration` (when it takes one): how it takes a wired Duration. "model"
64
+ * fits the length to one the model renders (a Duration node holds a
65
+ * script's length, 60 s by default, while one clip is 4–30 s). "total"
66
+ * keeps it: Generate Video Pro stitches segments to reach the requested
67
+ * total, and its engine clamps that total to the range the model's segment
68
+ * lengths allow;
69
+ * - `modelList`: the field holding the node's several models, when it can run
70
+ * more than one per run (Generate Image's `providers`, one image each). A
71
+ * wired Provider sets THE model, so the list becomes that one model.
72
+ *
73
+ * A wired Aspect Ratio is fitted to the model by `fitAspectRatioToModel`, the
74
+ * rule the video lane's normalizer applies (and a still-valid ratio passes
75
+ * every later normalizer unchanged), so the node shows the ratio it runs with.
76
+ */
77
+ interface SettingsConsumer {
78
+ readonly accepts: readonly SettingsSourceType[]
79
+ readonly models: readonly string[]
80
+ readonly defaultModel: string
81
+ readonly duration?: "model" | "total"
82
+ readonly modelList?: string
83
+ }
84
+
85
+ // Motion is a video-only clause (VIDEO_ONLY_PARAMETER_NODE_TYPES).
86
+ const VIDEO_SETTINGS: readonly SettingsSourceType[] = ["aspect-ratio", "duration", "provider", "motion"]
87
+
88
+ const SETTINGS_CONSUMERS: Readonly<Record<string, SettingsConsumer>> = {
89
+ "generate-video": {
90
+ accepts: VIDEO_SETTINGS,
91
+ models: VIDEO_GEN_PROVIDERS,
92
+ defaultModel: DEFAULT_VIDEO_PROVIDER,
93
+ duration: "model",
94
+ },
95
+ // Generate Video Pro has Generate Video's handles by construction
96
+ // (generate-video-pro-handles.ts re-exports them), so it takes the same
97
+ // settings; its own models and its own duration rule.
98
+ "generate-video-pro": {
99
+ accepts: VIDEO_SETTINGS,
100
+ models: GVP_SUPPORTED_PROVIDERS,
101
+ defaultModel: GVP_DEFAULT_PROVIDER,
102
+ duration: "total",
103
+ },
104
+ // A still image has no length, so no Duration.
105
+ "generate-image": {
106
+ accepts: ["aspect-ratio", "provider"],
107
+ models: IMAGE_GEN_PROVIDERS,
108
+ // The node's own default (NODE_DEFINITIONS) — only used to fit a wired
109
+ // ratio when the node names no model.
110
+ defaultModel: "nano-banana-pro",
111
+ modelList: "providers",
112
+ },
113
+ }
114
+
115
+ /** The consumers that have a Settings input, and the settings each accepts. */
116
+ export const SETTINGS_INPUT_CONSUMERS: Readonly<Record<string, readonly SettingsSourceType[]>> = Object.fromEntries(
117
+ Object.entries(SETTINGS_CONSUMERS).map(([type, consumer]) => [type, consumer.accepts]),
118
+ )
119
+
120
+ export function isSettingsSourceType(type: string | undefined | null): type is SettingsSourceType {
121
+ return typeof type === "string" && (SETTINGS_SOURCE_TYPES as readonly string[]).includes(type)
122
+ }
123
+
124
+ /** Whether a Generation Settings node adds a prompt clause rather than setting a field. */
125
+ export function isSettingsHintSource(type: string | undefined | null): type is SettingsHintSourceType {
126
+ return typeof type === "string" && (SETTINGS_HINT_SOURCES as readonly string[]).includes(type)
127
+ }
128
+
129
+ /** Whether `consumerType`'s Settings input takes a `sourceType` node. */
130
+ export function settingsInputAccepts(consumerType: string, sourceType: string): boolean {
131
+ return (SETTINGS_INPUT_CONSUMERS[consumerType] ?? []).some((t) => t === sourceType)
132
+ }
133
+
134
+ /** The consumer fields a Settings input can set, for `NODE_MAPPABLE_FIELDS`. */
135
+ export function settingsInputFields(consumerType: string): SettingsField[] {
136
+ return (SETTINGS_INPUT_CONSUMERS[consumerType] ?? []).flatMap((t) => {
137
+ const field = fieldOf(t)
138
+ return field ? [field] : []
139
+ })
140
+ }
141
+
142
+ /** The models a wired Provider may name on `consumerType` (empty for a non-consumer). */
143
+ export function settingsProviderModels(consumerType: string): readonly string[] {
144
+ return SETTINGS_CONSUMERS[consumerType]?.models ?? []
145
+ }
146
+
147
+ interface SettingsEdge {
148
+ readonly source: string
149
+ readonly target: string
150
+ readonly targetHandle?: string | null
151
+ }
152
+
153
+ /**
154
+ * The `sourceType` node wired into `consumerId`'s Settings input, or
155
+ * undefined. When two nodes of one kind are wired, the LAST edge wins — the
156
+ * same rule as every other single-value input.
157
+ */
158
+ export function settingsSourceForType(
159
+ consumerId: string,
160
+ consumerType: string,
161
+ sourceType: SettingsSourceType,
162
+ edges: ReadonlyArray<SettingsEdge>,
163
+ typeOf: (nodeId: string) => string | undefined | null,
164
+ ): string | undefined {
165
+ if (!settingsInputAccepts(consumerType, sourceType)) return undefined
166
+ let found: string | undefined
167
+ for (const edge of edges) {
168
+ if (edge.target !== consumerId || edge.targetHandle !== SETTINGS_INPUT_HANDLE) continue
169
+ if (typeOf(edge.source) === sourceType) found = edge.source
170
+ }
171
+ return found
172
+ }
173
+
174
+ /** The node wired into `consumerId`'s Settings input that sets `field`, or undefined (last edge wins). */
175
+ export function settingsSourceForField(
176
+ consumerId: string,
177
+ consumerType: string,
178
+ field: string,
179
+ edges: ReadonlyArray<SettingsEdge>,
180
+ typeOf: (nodeId: string) => string | undefined | null,
181
+ ): string | undefined {
182
+ const sourceType = (SETTINGS_INPUT_CONSUMERS[consumerType] ?? []).find((t) => fieldOf(t) === field)
183
+ return sourceType ? settingsSourceForType(consumerId, consumerType, sourceType, edges, typeOf) : undefined
184
+ }
185
+
186
+ /**
187
+ * Whether `edge` brings a prompt-clause setting (Motion) into its target's
188
+ * Settings input and is the one of its kind that applies (the last edge). The
189
+ * hint collectors of both engines ask this, so the clause a run gets is the
190
+ * one the node's chips show.
191
+ */
192
+ export function isSettingsHintEdge(
193
+ edge: SettingsEdge,
194
+ consumerType: string,
195
+ edges: ReadonlyArray<SettingsEdge>,
196
+ typeOf: (nodeId: string) => string | undefined | null,
197
+ ): boolean {
198
+ if (edge.targetHandle !== SETTINGS_INPUT_HANDLE) return false
199
+ const sourceType = typeOf(edge.source)
200
+ if (!isSettingsHintSource(sourceType)) return false
201
+ return settingsSourceForType(edge.target, consumerType, sourceType, edges, typeOf) === edge.source
202
+ }
203
+
204
+ /**
205
+ * Every setting wired into `consumerId`'s Settings input, one per kind (the
206
+ * last edge of a kind wins), in the order of `SETTINGS_INPUT_CONSUMERS`.
207
+ */
208
+ export function connectedSettingsSources(
209
+ consumerId: string,
210
+ consumerType: string,
211
+ edges: ReadonlyArray<SettingsEdge>,
212
+ typeOf: (nodeId: string) => string | undefined | null,
213
+ ): Array<{ sourceType: SettingsSourceType; field?: SettingsField; sourceId: string }> {
214
+ const out: Array<{ sourceType: SettingsSourceType; field?: SettingsField; sourceId: string }> = []
215
+ for (const sourceType of SETTINGS_INPUT_CONSUMERS[consumerType] ?? []) {
216
+ const sourceId = settingsSourceForType(consumerId, consumerType, sourceType, edges, typeOf)
217
+ if (!sourceId) continue
218
+ const field = fieldOf(sourceType)
219
+ out.push(field ? { sourceType, field, sourceId } : { sourceType, sourceId })
220
+ }
221
+ return out
222
+ }
223
+
224
+ /**
225
+ * `seconds` as `model` renders it: the nearest duration the catalog lists for
226
+ * the model, a tie going to the shorter one — the rule the provider layer
227
+ * applies when it renders (`snapToAllowedDuration`, KIE), so the length the
228
+ * run is priced at is the length it renders. Not `normalizeModelInput`'s
229
+ * duration snap, which replaces an invalid value with the model's FIRST
230
+ * length: right for a typo, wrong for a wired length (a 60 s Duration would
231
+ * become the model's shortest clip instead of its longest). A model without a
232
+ * duration list, and the "auto" duration, keep the value.
233
+ */
234
+ export function snapToModelDuration(model: string, seconds: number): number {
235
+ const durations = MODEL_CATALOG[model]?.durations
236
+ if (!durations || durations.length === 0 || isAutoVideoDuration(seconds)) return seconds
237
+ let best = durations[0]!
238
+ for (const d of durations) {
239
+ const closer = Math.abs(d - seconds) < Math.abs(best - seconds)
240
+ const tieShorter = Math.abs(d - seconds) === Math.abs(best - seconds) && d < best
241
+ if (closer || tieShorter) best = d
242
+ }
243
+ return best
244
+ }
245
+
246
+ export type SettingsInputProblem = { readonly kind: "provider-not-accepted"; readonly sourceId: string; readonly value: string }
247
+
248
+ /**
249
+ * The consumer's data once its Settings input has been read (after the field
250
+ * mapping resolver wrote each wired value into its field):
251
+ * - a wired Provider must name a model this consumer runs: a Provider node set
252
+ * to an image model cannot drive Generate Video, and the run refuses with
253
+ * `problem` rather than sending an image model to the video provider;
254
+ * - a wired Provider on a node that runs several models per run replaces the
255
+ * list with its one model (see `SettingsConsumer.modelList`);
256
+ * - a wired Duration is fitted to the model (see `SettingsConsumer.duration`);
257
+ * - a wired Aspect Ratio is fitted to the model (`fitAspectRatioToModel`).
258
+ */
259
+ export function applySettingsInput(
260
+ consumerType: string,
261
+ consumerId: string,
262
+ data: Readonly<Record<string, unknown>>,
263
+ edges: ReadonlyArray<SettingsEdge>,
264
+ typeOf: (nodeId: string) => string | undefined | null,
265
+ ): { data: Record<string, unknown>; problem?: SettingsInputProblem } {
266
+ const consumer = SETTINGS_CONSUMERS[consumerType]
267
+ const connected = connectedSettingsSources(consumerId, consumerType, edges, typeOf)
268
+ if (!consumer || connected.length === 0) return { data: { ...data } }
269
+ let next: Record<string, unknown> = { ...data }
270
+
271
+ const providerSource = connected.find((c) => c.sourceType === "provider")
272
+ if (providerSource) {
273
+ const value = typeof next.provider === "string" ? next.provider : ""
274
+ if (!consumer.models.includes(value)) {
275
+ return { data: next, problem: { kind: "provider-not-accepted", sourceId: providerSource.sourceId, value } }
276
+ }
277
+ if (consumer.modelList) next = { ...next, [consumer.modelList]: [value] }
278
+ }
279
+
280
+ const model = (typeof next.provider === "string" && next.provider) || consumer.defaultModel
281
+ if (consumer.duration === "model" && connected.some((c) => c.sourceType === "duration")) {
282
+ const raw = next.duration
283
+ const seconds = typeof raw === "number" ? raw : typeof raw === "string" ? Number.parseInt(raw, 10) : Number.NaN
284
+ if (Number.isFinite(seconds)) next = { ...next, duration: snapToModelDuration(model, seconds) }
285
+ }
286
+ if (connected.some((c) => c.sourceType === "aspect-ratio") && typeof next.aspectRatio === "string") {
287
+ next = { ...next, aspectRatio: fitAspectRatioToModel(model, next.aspectRatio) }
288
+ }
289
+ return { data: next }
290
+ }
291
+
292
+ interface SettingsGraphNode {
293
+ readonly id: string
294
+ readonly type?: string | null
295
+ readonly data?: unknown
296
+ }
297
+
298
+ /** One setting wired into a node's Settings input. */
299
+ export interface WiredSetting {
300
+ readonly sourceType: SettingsSourceType
301
+ /** The field it sets; none for a prompt-clause setting (Motion). */
302
+ readonly field?: SettingsField
303
+ readonly sourceId: string
304
+ /** The value the wired node holds, read the way the run engines read it. */
305
+ readonly value: string | undefined
306
+ }
307
+
308
+ /**
309
+ * What `consumerId` runs with once its Settings input is read: its data with
310
+ * each wired setting written into its field and fitted to the model — the
311
+ * steps the run engines take (field-mapping resolver, then
312
+ * `applySettingsInput`), for the readers that run before any resolver: the
313
+ * workflow estimate, the node's chips and its settings panel.
314
+ */
315
+ export function resolveWiredSettings(
316
+ consumerId: string,
317
+ consumerType: string,
318
+ data: Readonly<Record<string, unknown>>,
319
+ nodes: ReadonlyArray<SettingsGraphNode>,
320
+ edges: ReadonlyArray<SettingsEdge>,
321
+ ): { data: Record<string, unknown>; wired: WiredSetting[]; problem?: SettingsInputProblem } {
322
+ const byId = new Map(nodes.map((n) => [n.id, n]))
323
+ const typeOf = (id: string) => byId.get(id)?.type
324
+ const wired: WiredSetting[] = connectedSettingsSources(consumerId, consumerType, edges, typeOf).map((c) => ({
325
+ ...c,
326
+ value: getParameterValue((byId.get(c.sourceId)?.data ?? {}) as Record<string, unknown>, c.sourceType),
327
+ }))
328
+ if (wired.length === 0) return { data: { ...data }, wired }
329
+ let next: Record<string, unknown> = { ...data }
330
+ for (const w of wired) {
331
+ if (w.field && w.value != null) next = { ...next, [w.field]: w.value }
332
+ }
333
+ const applied = applySettingsInput(consumerType, consumerId, next, edges, typeOf)
334
+ return applied.problem ? { data: applied.data, wired, problem: applied.problem } : { data: applied.data, wired }
335
+ }
336
+
337
+ interface SettingsNodeLike {
338
+ readonly id?: string
339
+ readonly type?: string | null
340
+ readonly data?: unknown
341
+ }
342
+
343
+ interface SettingsEdgeLike {
344
+ readonly source?: string
345
+ readonly target: string
346
+ readonly targetHandle?: string | null
347
+ }
348
+
349
+ /**
350
+ * `node` as it runs, for the readers that plan or price a run before any
351
+ * resolver: the workflow estimates, the Run price, and the fan-out plan (a
352
+ * wired Provider turns a several-model image run into one). A node with no
353
+ * Settings input — or a caller without the graph — gets `node` back as is.
354
+ */
355
+ export function withWiredSettings<T extends SettingsNodeLike>(
356
+ node: T,
357
+ nodes?: ReadonlyArray<SettingsNodeLike>,
358
+ edges?: ReadonlyArray<SettingsEdgeLike>,
359
+ ): T {
360
+ const type = node.type ?? ""
361
+ if (!nodes || !edges || !node.id || !SETTINGS_CONSUMERS[type]) return node
362
+ const graphNodes = nodes.flatMap((n) => (n.id ? [{ id: n.id, type: n.type, data: n.data }] : []))
363
+ const graphEdges = edges.map((e) => ({ source: e.source ?? "", target: e.target, targetHandle: e.targetHandle }))
364
+ const { data } = resolveWiredSettings(node.id, type, (node.data ?? {}) as Record<string, unknown>, graphNodes, graphEdges)
365
+ return { ...node, data }
366
+ }