@nodaro/shared 3.16.0 → 3.19.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/dist/index.cjs +427 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +397 -35
- package/dist/index.d.ts +397 -35
- package/dist/index.js +397 -44
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/apply-edl-credit-id.test.ts +25 -0
- package/src/__tests__/caption-plan.test.ts +27 -0
- package/src/__tests__/exposed-field-keys.test.ts +78 -0
- package/src/__tests__/instagram-scrape.test.ts +62 -0
- package/src/__tests__/node-preset-extract.test.ts +62 -0
- package/src/__tests__/node-runtime-keys.test.ts +1 -0
- package/src/__tests__/studio-sequence-owner.test.ts +356 -0
- package/src/__tests__/studio-transient.test.ts +34 -0
- package/src/__tests__/text-to-audio-pricing.test.ts +71 -0
- package/src/__tests__/tts-capabilities.test.ts +237 -0
- package/src/caption-plan.ts +27 -0
- package/src/credit-estimators/index.ts +7 -0
- package/src/credit-estimators/text-to-audio.ts +58 -0
- package/src/credit-identifiers.ts +12 -0
- package/src/exposed-field-keys.ts +49 -0
- package/src/index.ts +36 -1
- package/src/instagram-scrape.ts +91 -16
- package/src/model-catalog.ts +121 -2
- package/src/model-constants.ts +26 -16
- package/src/node-preset-extract.ts +33 -1
- package/src/node-runtime-keys.ts +12 -0
- package/src/presentation-utils.ts +5 -1
- package/src/social-search.ts +3 -3
- package/src/studio-transient.ts +337 -36
- package/src/tts-capabilities.ts +75 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest"
|
|
2
|
+
import { MODEL_CATALOG } from "../model-catalog.js"
|
|
3
|
+
import { TTS_PROVIDERS, MAX_TTS_CHARS_BY_PROVIDER, getMaxTtsChars, TTS_TEXT_MAX } from "../model-constants.js"
|
|
4
|
+
import {
|
|
5
|
+
TTS_PROVIDER_ALIASES,
|
|
6
|
+
TTS_FALLBACK_PROVIDER,
|
|
7
|
+
canonicalTtsProvider,
|
|
8
|
+
findTtsCapabilities,
|
|
9
|
+
getTtsCapabilities,
|
|
10
|
+
ttsSupportsAudioTags,
|
|
11
|
+
ttsSupportsSsmlBreaks,
|
|
12
|
+
ttsHasLever,
|
|
13
|
+
ttsLanguageCodes,
|
|
14
|
+
} from "../tts-capabilities.js"
|
|
15
|
+
|
|
16
|
+
describe("speech-model capability sheets — totality", () => {
|
|
17
|
+
it("every text-to-speech provider id resolves to a catalog model with a sheet and a price", () => {
|
|
18
|
+
for (const id of TTS_PROVIDERS) {
|
|
19
|
+
const entry = MODEL_CATALOG[canonicalTtsProvider(id)]
|
|
20
|
+
expect(entry, `${id} has no catalog entry`).toBeDefined()
|
|
21
|
+
expect(entry!.tts, `${id} has no capability sheet`).toBeDefined()
|
|
22
|
+
expect(entry!.pricing.length, `${id} has no pricing row`).toBeGreaterThan(0)
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it("every catalog model that speaks (tts or dialogue mode) carries a sheet, and nothing else does", () => {
|
|
27
|
+
for (const m of Object.values(MODEL_CATALOG)) {
|
|
28
|
+
const speaks = m.modes.includes("tts") || m.modes.includes("dialogue")
|
|
29
|
+
expect(m.tts !== undefined, `${m.id}: sheet presence must match its modes`).toBe(speaks)
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it("every non-alias provider id IS a catalog id, and every alias points at a real speech model", () => {
|
|
34
|
+
for (const id of TTS_PROVIDERS) {
|
|
35
|
+
if (id in TTS_PROVIDER_ALIASES) continue
|
|
36
|
+
expect(MODEL_CATALOG[id]?.modes).toContain("tts")
|
|
37
|
+
}
|
|
38
|
+
for (const [alias, target] of Object.entries(TTS_PROVIDER_ALIASES)) {
|
|
39
|
+
expect(MODEL_CATALOG[alias], `${alias} is an alias and must not have its own entry`).toBeUndefined()
|
|
40
|
+
expect(MODEL_CATALOG[target]?.tts).toBeDefined()
|
|
41
|
+
}
|
|
42
|
+
expect(MODEL_CATALOG[TTS_FALLBACK_PROVIDER]?.tts).toBeDefined()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it("each sheet is internally consistent", () => {
|
|
46
|
+
for (const m of Object.values(MODEL_CATALOG)) {
|
|
47
|
+
if (!m.tts) continue
|
|
48
|
+
expect(Number.isInteger(m.tts.maxChars) && m.tts.maxChars > 0, `${m.id} maxChars`).toBe(true)
|
|
49
|
+
expect(m.tts.levers, `${m.id} must honour stability`).toContain("stability")
|
|
50
|
+
expect(new Set(m.tts.levers).size, `${m.id} duplicate lever`).toBe(m.tts.levers.length)
|
|
51
|
+
expect(m.tts.languages.length, `${m.id} languages`).toBeGreaterThan(0)
|
|
52
|
+
expect(new Set(m.tts.languages).size, `${m.id} duplicate language`).toBe(m.tts.languages.length)
|
|
53
|
+
// The `features` flag other packages already read must agree with the sheet.
|
|
54
|
+
expect(m.features?.includes("audio-tags") ?? false, `${m.id} audio-tags feature`).toBe(m.tts.audioTags)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
describe("speech-model capability sheets — what each model does today", () => {
|
|
60
|
+
it("v3: tags, no SSML, stability only, 5,000 characters, 46 languages", () => {
|
|
61
|
+
const c = getTtsCapabilities("elevenlabs-v3")
|
|
62
|
+
expect(c.audioTags).toBe(true)
|
|
63
|
+
expect(c.ssmlBreaks).toBe(false)
|
|
64
|
+
expect(c.levers).toEqual(["stability"])
|
|
65
|
+
expect(c.languageCode).toBe(true)
|
|
66
|
+
expect(c.maxChars).toBe(5000)
|
|
67
|
+
expect(c.languages).toHaveLength(46)
|
|
68
|
+
expect(c.languages).toContain("he")
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it("turbo: no tags, SSML, all five levers, 40,000 characters, 32 languages", () => {
|
|
72
|
+
const c = getTtsCapabilities("elevenlabs-turbo")
|
|
73
|
+
expect(c.audioTags).toBe(false)
|
|
74
|
+
expect(c.ssmlBreaks).toBe(true)
|
|
75
|
+
expect(c.levers).toEqual(["stability", "similarity", "style", "speed", "speakerBoost"])
|
|
76
|
+
expect(c.languageCode).toBe(true)
|
|
77
|
+
expect(c.maxChars).toBe(40000)
|
|
78
|
+
expect(c.languages).toHaveLength(32)
|
|
79
|
+
expect(c.languages).not.toContain("he")
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it("multilingual: no tags, SSML, all five levers, no language code, 10,000 characters, 29 languages", () => {
|
|
83
|
+
const c = getTtsCapabilities("elevenlabs-multilingual")
|
|
84
|
+
expect(c.audioTags).toBe(false)
|
|
85
|
+
expect(c.ssmlBreaks).toBe(true)
|
|
86
|
+
expect(c.levers).toEqual(["stability", "similarity", "style", "speed", "speakerBoost"])
|
|
87
|
+
expect(c.languageCode).toBe(false)
|
|
88
|
+
expect(c.maxChars).toBe(10000)
|
|
89
|
+
expect(c.languages).toHaveLength(29)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it("dialogue (read from its catalog entry — its own lane): tags, stability only, 5,000 characters in total", () => {
|
|
93
|
+
const c = MODEL_CATALOG["elevenlabs-dialogue"]!.tts!
|
|
94
|
+
expect(c.audioTags).toBe(true)
|
|
95
|
+
expect(c.levers).toEqual(["stability"])
|
|
96
|
+
expect(c.maxChars).toBe(5000)
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
describe("speech-model capability lookups", () => {
|
|
101
|
+
it("the legacy alias reads as the model it runs on", () => {
|
|
102
|
+
expect(canonicalTtsProvider("elevenlabs")).toBe("elevenlabs-turbo")
|
|
103
|
+
expect(canonicalTtsProvider("elevenlabs-v3")).toBe("elevenlabs-v3")
|
|
104
|
+
expect(findTtsCapabilities("elevenlabs")).toBe(getTtsCapabilities("elevenlabs-turbo"))
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it("a missing or unknown id gets the fallback model's sheet, and `find` says it is unknown", () => {
|
|
108
|
+
expect(findTtsCapabilities(undefined)).toBeUndefined()
|
|
109
|
+
expect(findTtsCapabilities("")).toBeUndefined()
|
|
110
|
+
expect(findTtsCapabilities("not-a-model")).toBeUndefined()
|
|
111
|
+
expect(findTtsCapabilities("nano-banana-pro")).toBeUndefined() // a real model, not a speech model
|
|
112
|
+
expect(getTtsCapabilities(undefined)).toBe(getTtsCapabilities("elevenlabs-turbo"))
|
|
113
|
+
expect(getTtsCapabilities("not-a-model")).toBe(getTtsCapabilities("elevenlabs-turbo"))
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it("an id that is the name of an inherited object member is an unknown id, never a function", () => {
|
|
117
|
+
for (const id of ["constructor", "__proto__", "toString", "hasOwnProperty", "valueOf"]) {
|
|
118
|
+
expect(canonicalTtsProvider(id), id).toBe(id)
|
|
119
|
+
expect(findTtsCapabilities(id), id).toBeUndefined()
|
|
120
|
+
expect(getTtsCapabilities(id), id).toBe(getTtsCapabilities("elevenlabs-turbo"))
|
|
121
|
+
expect(ttsSupportsAudioTags(id), id).toBe(false)
|
|
122
|
+
expect(getMaxTtsChars(id), id).toBe(TTS_TEXT_MAX)
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it("a non-string id (node data can be written straight into workflow JSON) is an unknown id — an array is not coerced into the model it spells", () => {
|
|
127
|
+
for (const id of [["elevenlabs-v3"], ["elevenlabs-multilingual"], ["elevenlabs"], 3, {}, true, null] as unknown as string[]) {
|
|
128
|
+
expect(findTtsCapabilities(id), JSON.stringify(id)).toBeUndefined()
|
|
129
|
+
expect(getTtsCapabilities(id), JSON.stringify(id)).toBe(getTtsCapabilities("elevenlabs-turbo"))
|
|
130
|
+
expect(ttsSupportsAudioTags(id), JSON.stringify(id)).toBe(false)
|
|
131
|
+
expect(ttsHasLever(id, "style"), JSON.stringify(id)).toBe(true)
|
|
132
|
+
expect(canonicalTtsProvider(id), JSON.stringify(id)).toBe(id)
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it("the dialogue model has a sheet for its own lane but is not a text-to-speech model: a speech request naming it runs as the fallback", () => {
|
|
137
|
+
expect(MODEL_CATALOG["elevenlabs-dialogue"]!.tts).toBeDefined()
|
|
138
|
+
expect(findTtsCapabilities("elevenlabs-dialogue")).toBeUndefined()
|
|
139
|
+
expect(getTtsCapabilities("elevenlabs-dialogue")).toBe(getTtsCapabilities("elevenlabs-turbo"))
|
|
140
|
+
expect(ttsSupportsAudioTags("elevenlabs-dialogue")).toBe(false)
|
|
141
|
+
expect(ttsHasLever("elevenlabs-dialogue", "style")).toBe(true)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it("audio tags: kept on v3, stripped everywhere else (alias, unknown and missing included)", () => {
|
|
145
|
+
expect(ttsSupportsAudioTags("elevenlabs-v3")).toBe(true)
|
|
146
|
+
expect(ttsSupportsAudioTags("elevenlabs-turbo")).toBe(false)
|
|
147
|
+
expect(ttsSupportsAudioTags("elevenlabs-multilingual")).toBe(false)
|
|
148
|
+
expect(ttsSupportsAudioTags("elevenlabs")).toBe(false)
|
|
149
|
+
expect(ttsSupportsAudioTags(undefined)).toBe(false)
|
|
150
|
+
expect(ttsSupportsAudioTags("not-a-model")).toBe(false)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it("SSML breaks are the mirror image", () => {
|
|
154
|
+
expect(ttsSupportsSsmlBreaks("elevenlabs-turbo")).toBe(true)
|
|
155
|
+
expect(ttsSupportsSsmlBreaks("elevenlabs-multilingual")).toBe(true)
|
|
156
|
+
expect(ttsSupportsSsmlBreaks("elevenlabs-v3")).toBe(false)
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it("levers", () => {
|
|
160
|
+
expect(ttsHasLever("elevenlabs-v3", "stability")).toBe(true)
|
|
161
|
+
expect(ttsHasLever("elevenlabs-v3", "similarity")).toBe(false)
|
|
162
|
+
expect(ttsHasLever("elevenlabs-v3", "speed")).toBe(false)
|
|
163
|
+
expect(ttsHasLever("elevenlabs-turbo", "similarity")).toBe(true)
|
|
164
|
+
expect(ttsHasLever("elevenlabs-turbo", "speed")).toBe(true)
|
|
165
|
+
expect(ttsHasLever("elevenlabs-turbo", "speakerBoost")).toBe(true)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it("languages nest: multilingual ⊂ turbo ⊂ v3", () => {
|
|
169
|
+
const multi = ttsLanguageCodes("elevenlabs-multilingual")
|
|
170
|
+
const turbo = ttsLanguageCodes("elevenlabs-turbo")
|
|
171
|
+
const v3 = ttsLanguageCodes("elevenlabs-v3")
|
|
172
|
+
expect(multi.every((c) => turbo.includes(c))).toBe(true)
|
|
173
|
+
expect(turbo.every((c) => v3.includes(c))).toBe(true)
|
|
174
|
+
expect(turbo.filter((c) => !multi.includes(c))).toEqual(["hu", "no", "vi"])
|
|
175
|
+
})
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
describe("character caps derive from the sheets", () => {
|
|
179
|
+
it("MAX_TTS_CHARS_BY_PROVIDER has exactly the catalog's speech models", () => {
|
|
180
|
+
const speaking = Object.values(MODEL_CATALOG).filter((m) => m.tts).map((m) => m.id).sort()
|
|
181
|
+
expect(Object.keys(MAX_TTS_CHARS_BY_PROVIDER).sort()).toEqual(speaking)
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
it("keeps every cap it had before the sheets existed; the alias and unknown ids keep the default", () => {
|
|
185
|
+
expect(getMaxTtsChars("elevenlabs-turbo")).toBe(40000)
|
|
186
|
+
expect(getMaxTtsChars("elevenlabs-multilingual")).toBe(10000)
|
|
187
|
+
expect(getMaxTtsChars("elevenlabs-v3")).toBe(5000)
|
|
188
|
+
expect(getMaxTtsChars("elevenlabs-dialogue")).toBe(5000)
|
|
189
|
+
expect(getMaxTtsChars("elevenlabs")).toBe(TTS_TEXT_MAX)
|
|
190
|
+
expect(getMaxTtsChars(undefined)).toBe(TTS_TEXT_MAX)
|
|
191
|
+
})
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
describe("elevenlabs-v4 — added beside v3", () => {
|
|
195
|
+
it("is a text-to-speech provider, in the catalog, with the sheet below", () => {
|
|
196
|
+
expect(TTS_PROVIDERS).toContain("elevenlabs-v4")
|
|
197
|
+
expect(MODEL_CATALOG["elevenlabs-v4"]?.modes).toContain("tts")
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
it("tags, no SSML, stability + similarity, 10,000 characters, the same 46 languages as v3", () => {
|
|
201
|
+
const c = getTtsCapabilities("elevenlabs-v4")
|
|
202
|
+
expect(c.audioTags).toBe(true)
|
|
203
|
+
expect(c.ssmlBreaks).toBe(false)
|
|
204
|
+
expect(c.levers).toEqual(["stability", "similarity"])
|
|
205
|
+
expect(c.languageCode).toBe(true)
|
|
206
|
+
expect(c.maxChars).toBe(10000)
|
|
207
|
+
expect(c.languages).toEqual(getTtsCapabilities("elevenlabs-v3").languages)
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
it("keeps [audio tags] and has no SSML breaks", () => {
|
|
211
|
+
expect(ttsSupportsAudioTags("elevenlabs-v4")).toBe(true)
|
|
212
|
+
expect(ttsSupportsSsmlBreaks("elevenlabs-v4")).toBe(false)
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it("honours similarity but not speed, style or speaker boost", () => {
|
|
216
|
+
expect(ttsHasLever("elevenlabs-v4", "similarity")).toBe(true)
|
|
217
|
+
expect(ttsHasLever("elevenlabs-v4", "speed")).toBe(false)
|
|
218
|
+
expect(ttsHasLever("elevenlabs-v4", "style")).toBe(false)
|
|
219
|
+
expect(ttsHasLever("elevenlabs-v4", "speakerBoost")).toBe(false)
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it("is capped at 10,000 characters; v3 stays at 5,000", () => {
|
|
223
|
+
expect(getMaxTtsChars("elevenlabs-v4")).toBe(10000)
|
|
224
|
+
expect(getMaxTtsChars("elevenlabs-v3")).toBe(5000)
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
it("costs a flat 30 credits with no per-length note, and is not the featured model — v3 stays the default", () => {
|
|
228
|
+
const v4 = MODEL_CATALOG["elevenlabs-v4"]!
|
|
229
|
+
expect(v4.pricing).toEqual([{ identifier: "elevenlabs-v4", credits: 30 }])
|
|
230
|
+
expect(v4.featured).toBeUndefined()
|
|
231
|
+
expect(MODEL_CATALOG["elevenlabs-v3"]!.featured).toBe(true)
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
it("does not call v3 the latest model any more", () => {
|
|
235
|
+
expect(MODEL_CATALOG["elevenlabs-v3"]!.description).not.toMatch(/latest/i)
|
|
236
|
+
})
|
|
237
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface CaptionWordTiming {
|
|
2
|
+
readonly text: string
|
|
3
|
+
readonly startMs: number
|
|
4
|
+
readonly endMs: number
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A caption plan: the opening line, where it ends, and the timed words that
|
|
9
|
+
* follow it. Times and words only — no styling travels on a plan; whoever
|
|
10
|
+
* renders it applies the look. Times are milliseconds from the video's start.
|
|
11
|
+
*/
|
|
12
|
+
/** The opening line and the body's words, timed. No styling. */
|
|
13
|
+
export interface CaptionPlan {
|
|
14
|
+
readonly v: 1
|
|
15
|
+
/** The opening line as written; sent as is, never trimmed. */
|
|
16
|
+
readonly hookText: string
|
|
17
|
+
/** Where the opening line ends; the body starts here. */
|
|
18
|
+
readonly hookEndMs: number
|
|
19
|
+
/** Where the body captions end, any tail included (the producer decides it). */
|
|
20
|
+
readonly bodyEndMs: number
|
|
21
|
+
/** The body's words, in milliseconds. */
|
|
22
|
+
readonly captions: readonly CaptionWordTiming[]
|
|
23
|
+
/** When known, the opening line and the body are clamped to it. */
|
|
24
|
+
readonly videoDurationMs?: number
|
|
25
|
+
/** Primary language tag: "en", "he", … */
|
|
26
|
+
readonly language?: string
|
|
27
|
+
}
|
|
@@ -16,6 +16,13 @@ export {
|
|
|
16
16
|
|
|
17
17
|
export { VIDEO_SFX_PRICING, videoSfxCreditId } from "./video-sfx.js"
|
|
18
18
|
|
|
19
|
+
export {
|
|
20
|
+
TEXT_TO_AUDIO_PRICING,
|
|
21
|
+
TEXT_TO_AUDIO_SFX_CREDIT_IDS,
|
|
22
|
+
textToAudioBilledSeconds,
|
|
23
|
+
textToAudioCreditId,
|
|
24
|
+
} from "./text-to-audio.js"
|
|
25
|
+
|
|
19
26
|
export {
|
|
20
27
|
LTX_EXTEND_PER_SECOND_CREDIT_ID,
|
|
21
28
|
LTX_EXTEND_DURATION,
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text to Audio (sound effects) pricing — which price row a run is charged
|
|
3
|
+
* from, by the length of the clip it asks for. One mapping for every place
|
|
4
|
+
* that names the row: the route (`POST /v1/text-to-audio`), the workflow run's
|
|
5
|
+
* reservation, the node's Run button and the workflow estimates.
|
|
6
|
+
*
|
|
7
|
+
* `elevenlabs-sfx` is priced per second: one `model_pricing` row per whole
|
|
8
|
+
* second (`elevenlabs-sfx:1s` … `elevenlabs-sfx:30s`); the credit amounts live
|
|
9
|
+
* there, never here. The requested length is rounded UP to whole seconds, and
|
|
10
|
+
* a request that names no length is priced as 5 seconds. Worked examples
|
|
11
|
+
* (repeated in docs/nodes/ai-audio/text-to-audio.md):
|
|
12
|
+
* 0.5 s → `:1s`, 6 s → `:6s`, 22.3 s → `:23s`, no duration → `:5s`.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { DEFAULT_TEXT_TO_AUDIO_PROVIDER } from "../model-constants.js"
|
|
16
|
+
|
|
17
|
+
export const TEXT_TO_AUDIO_PRICING = {
|
|
18
|
+
/** The engine priced per second of requested audio. */
|
|
19
|
+
PER_SECOND_PROVIDER: "elevenlabs-sfx",
|
|
20
|
+
/** The longest clip a request may ask for, in seconds. */
|
|
21
|
+
MAX_DURATION_SEC: 30,
|
|
22
|
+
/** The length priced when a request names none (the model picks the length). */
|
|
23
|
+
DEFAULT_BILLED_SEC: 5,
|
|
24
|
+
} as const
|
|
25
|
+
|
|
26
|
+
/** Every per-second price row, shortest first: `elevenlabs-sfx:1s` … `:30s`. */
|
|
27
|
+
export const TEXT_TO_AUDIO_SFX_CREDIT_IDS: readonly string[] = Array.from(
|
|
28
|
+
{ length: TEXT_TO_AUDIO_PRICING.MAX_DURATION_SEC },
|
|
29
|
+
(_, i) => `${TEXT_TO_AUDIO_PRICING.PER_SECOND_PROVIDER}:${i + 1}s`,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The whole seconds a request of `duration` seconds is billed for: rounded up,
|
|
34
|
+
* at most the 30 s cap. No usable length (absent, empty, non-numeric, zero or
|
|
35
|
+
* negative) bills the 5 s default. A numeric string counts — a field mapping
|
|
36
|
+
* can deliver the length as text.
|
|
37
|
+
*/
|
|
38
|
+
export function textToAudioBilledSeconds(duration: unknown): number {
|
|
39
|
+
const seconds =
|
|
40
|
+
typeof duration === "number"
|
|
41
|
+
? duration
|
|
42
|
+
: typeof duration === "string" && duration.trim() !== ""
|
|
43
|
+
? Number(duration)
|
|
44
|
+
: Number.NaN
|
|
45
|
+
if (!Number.isFinite(seconds) || seconds <= 0) return TEXT_TO_AUDIO_PRICING.DEFAULT_BILLED_SEC
|
|
46
|
+
return Math.min(Math.ceil(seconds), TEXT_TO_AUDIO_PRICING.MAX_DURATION_SEC)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The price row for a Text to Audio request. A request with no provider runs
|
|
51
|
+
* (and is priced as) the default engine. An engine that is not priced per
|
|
52
|
+
* second keeps its own flat row.
|
|
53
|
+
*/
|
|
54
|
+
export function textToAudioCreditId(provider: string | null | undefined, duration: unknown): string {
|
|
55
|
+
const engine = provider || DEFAULT_TEXT_TO_AUDIO_PROVIDER
|
|
56
|
+
if (engine !== TEXT_TO_AUDIO_PRICING.PER_SECOND_PROVIDER) return engine
|
|
57
|
+
return `${engine}:${textToAudioBilledSeconds(duration)}s`
|
|
58
|
+
}
|
|
@@ -662,6 +662,18 @@ export function speedRampCreditId(quality: unknown): "speed-ramp" | "speed-ramp:
|
|
|
662
662
|
return quality === "smooth" ? "speed-ramp:smooth" : "speed-ramp"
|
|
663
663
|
}
|
|
664
664
|
|
|
665
|
+
/**
|
|
666
|
+
* Apply EDL's price id: a `proxy` render (the 720p preview) is its own,
|
|
667
|
+
* cheaper per-output-minute row; a `final` render keeps the bare id. One id per
|
|
668
|
+
* QUALITY, for a video and an audio output alike (decided 2026-10-04). Anything
|
|
669
|
+
* that is not exactly "proxy" is the final, as the route and the node default
|
|
670
|
+
* it. The route, the workflow run, and the editor's badge and run estimate all
|
|
671
|
+
* price through this; the job itself is always named `apply-edl`.
|
|
672
|
+
*/
|
|
673
|
+
export function applyEdlCreditId(quality: unknown): "apply-edl" | "apply-edl:proxy" {
|
|
674
|
+
return quality === "proxy" ? "apply-edl:proxy" : "apply-edl"
|
|
675
|
+
}
|
|
676
|
+
|
|
665
677
|
/**
|
|
666
678
|
* OUR Nodaro credit key for a Suno operation, given the model version and the
|
|
667
679
|
* operation (which is also the node type and the BullMQ job name).
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exposed-field keys that were renamed to the node's real data field.
|
|
3
|
+
*
|
|
4
|
+
* A published app stores which fields it exposes as `{ type: "field", nodeId, field }` items in its
|
|
5
|
+
* immutable snapshot settings, and external callers send `inputOverrides[nodeId][field]` with that same
|
|
6
|
+
* string — it is part of the public wire contract (docs/embed-app-guide.md). Renaming a descriptor's key
|
|
7
|
+
* must not strand the apps already published with the old spelling: they keep that string forever, so every
|
|
8
|
+
* place that turns a stored key into a node-data key — or compares it with a descriptor key — goes through
|
|
9
|
+
* `canonicalExposedFieldKey`.
|
|
10
|
+
*
|
|
11
|
+
* CLOSED LIST. A row needs a spelling that was published (a card that existed in apps) and a target the
|
|
12
|
+
* node's descriptor now declares (the frontend guard `exposable-field-keys.test.ts` checks both). Only list a
|
|
13
|
+
* field whose card cannot carry `allowedValues` (slider / toggle / text / color): the server validates
|
|
14
|
+
* `allowedValues` against the stored key (backend routes/app-runner.ts `validateRestrictedFields`). Never list
|
|
15
|
+
* a field of an outbound node type: the run-request override lock (backend lib/input-override-lock.ts) reads
|
|
16
|
+
* the stored key, before this table renames it.
|
|
17
|
+
*/
|
|
18
|
+
export const LEGACY_EXPOSED_FIELD_KEYS: Readonly<Record<string, Readonly<Record<string, string>>>> = {
|
|
19
|
+
// Published as the Text to Speech slider's key. The node's data field, and every runner, route and config
|
|
20
|
+
// panel, has always been `similarityBoost` — so the slider moved nothing.
|
|
21
|
+
"text-to-speech": { similarity: "similarityBoost" },
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The node-data key an exposed field's stored key stands for. Unknown node types and keys pass through. */
|
|
25
|
+
export function canonicalExposedFieldKey(nodeType: string | undefined, key: string): string {
|
|
26
|
+
if (typeof nodeType !== "string" || !Object.hasOwn(LEGACY_EXPOSED_FIELD_KEYS, nodeType)) return key
|
|
27
|
+
const renames = LEGACY_EXPOSED_FIELD_KEYS[nodeType]!
|
|
28
|
+
return Object.hasOwn(renames, key) ? renames[key]! : key
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The override map with every legacy spelling replaced by its current key. When the caller sent both
|
|
33
|
+
* spellings the current one wins (it is their current intent) and the legacy key is dropped — a dead key
|
|
34
|
+
* is never written to node data. Returns the same object when nothing renames; never mutates.
|
|
35
|
+
*/
|
|
36
|
+
export function canonicalizeOverrideKeys(
|
|
37
|
+
nodeType: string | undefined,
|
|
38
|
+
overrides: Record<string, unknown>,
|
|
39
|
+
): Record<string, unknown> {
|
|
40
|
+
let out: Record<string, unknown> | undefined
|
|
41
|
+
for (const key of Object.keys(overrides)) {
|
|
42
|
+
const current = canonicalExposedFieldKey(nodeType, key)
|
|
43
|
+
if (current === key) continue
|
|
44
|
+
out ??= { ...overrides }
|
|
45
|
+
delete out[key]
|
|
46
|
+
if (!Object.hasOwn(overrides, current)) out[current] = overrides[key]
|
|
47
|
+
}
|
|
48
|
+
return out ?? overrides
|
|
49
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -87,6 +87,7 @@ export {
|
|
|
87
87
|
MOTION_TRANSFER_PROVIDERS,
|
|
88
88
|
TTS_PROVIDERS,
|
|
89
89
|
TEXT_TO_AUDIO_PROVIDERS,
|
|
90
|
+
DEFAULT_TEXT_TO_AUDIO_PROVIDER,
|
|
90
91
|
MUSIC_PROVIDERS,
|
|
91
92
|
DEFAULT_MUSIC_PROVIDER,
|
|
92
93
|
MUSIC_PROVIDER_LABELS,
|
|
@@ -274,6 +275,7 @@ export {
|
|
|
274
275
|
pricedVideoSelection,
|
|
275
276
|
buildMotionCreditModelIdentifier,
|
|
276
277
|
speedRampCreditId,
|
|
278
|
+
applyEdlCreditId,
|
|
277
279
|
sunoCreditType,
|
|
278
280
|
SUNO_VERSION_CREDIT_KEYS,
|
|
279
281
|
SUNO_VERSION_PRICED_OPERATIONS,
|
|
@@ -315,6 +317,12 @@ export {
|
|
|
315
317
|
type InputFieldSchema,
|
|
316
318
|
} from "./presentation-utils.js"
|
|
317
319
|
|
|
320
|
+
export {
|
|
321
|
+
LEGACY_EXPOSED_FIELD_KEYS,
|
|
322
|
+
canonicalExposedFieldKey,
|
|
323
|
+
canonicalizeOverrideKeys,
|
|
324
|
+
} from "./exposed-field-keys.js"
|
|
325
|
+
|
|
318
326
|
export {
|
|
319
327
|
ITER_CLONE_PATTERN,
|
|
320
328
|
isExpandedClone,
|
|
@@ -833,6 +841,8 @@ export {
|
|
|
833
841
|
resolveInstagramScrapeCreditId,
|
|
834
842
|
instagramScrapeSources,
|
|
835
843
|
instagramScrapeCreditIdFromNode,
|
|
844
|
+
instagramRequestedCount,
|
|
845
|
+
instagramPostLink,
|
|
836
846
|
splitInstagramTargets,
|
|
837
847
|
clampInstagramFeaturedIndex,
|
|
838
848
|
featuredInstagramOutputs,
|
|
@@ -1115,8 +1125,22 @@ export type {
|
|
|
1115
1125
|
ModelMenuOption,
|
|
1116
1126
|
ModelInputAdjustment,
|
|
1117
1127
|
NormalizedModelInput,
|
|
1128
|
+
TtsCapabilities,
|
|
1129
|
+
TtsSettingLever,
|
|
1118
1130
|
} from "./model-catalog.js"
|
|
1119
1131
|
|
|
1132
|
+
// Speech-model capability lookups (derive from `ModelCatalogEntry.tts` above).
|
|
1133
|
+
export {
|
|
1134
|
+
TTS_PROVIDER_ALIASES,
|
|
1135
|
+
TTS_FALLBACK_PROVIDER,
|
|
1136
|
+
canonicalTtsProvider,
|
|
1137
|
+
getTtsCapabilities,
|
|
1138
|
+
ttsSupportsAudioTags,
|
|
1139
|
+
ttsSupportsSsmlBreaks,
|
|
1140
|
+
ttsHasLever,
|
|
1141
|
+
ttsLanguageCodes,
|
|
1142
|
+
} from "./tts-capabilities.js"
|
|
1143
|
+
|
|
1120
1144
|
// Per-model safety-filter retry/fallback policy (derives from
|
|
1121
1145
|
// `ModelCatalogEntry.safetyFilter` above).
|
|
1122
1146
|
export { safetyRetryPolicy } from "./safety-retry-policy.js"
|
|
@@ -1142,6 +1166,7 @@ export {
|
|
|
1142
1166
|
resolveCaptionLevers,
|
|
1143
1167
|
} from "./caption-styles.js"
|
|
1144
1168
|
export type { StaticCaptionStyle, KineticCaptionStyle, CaptionStyle, CaptionLookId, CaptionLookLevers, KineticOnlyCaptionLeverKey } from "./caption-styles.js"
|
|
1169
|
+
export type { CaptionPlan, CaptionWordTiming } from "./caption-plan.js"
|
|
1145
1170
|
|
|
1146
1171
|
export {
|
|
1147
1172
|
transcribeWordTimestampsRefusal,
|
|
@@ -1385,7 +1410,7 @@ export {
|
|
|
1385
1410
|
describeNodeAdjustments,
|
|
1386
1411
|
} from "./normalize-node-params.js"
|
|
1387
1412
|
export type { NodeParamAdjustment, NormalizedNodes } from "./normalize-node-params.js"
|
|
1388
|
-
export { extractPresetData, PRESET_EXCLUDED_KEYS, PRESET_APPLY_CLEAR_KEYS, presetApplyClearKeys, presetDataMatches } from "./node-preset-extract.js"
|
|
1413
|
+
export { extractPresetData, PRESET_EXCLUDED_KEYS, PRESET_APPLY_CLEAR_KEYS, PRESET_LEVER_GROUPS, presetApplyClearKeys, presetLeverClearKeys, presetDataMatches } from "./node-preset-extract.js"
|
|
1389
1414
|
export { PROMPT_PREFIX_KEY, PROMPT_SUFFIX_KEY, readPromptAffixes } from "./prompt-affixes.js"
|
|
1390
1415
|
export type { PromptAffixFields, PromptAffixes } from "./prompt-affixes.js"
|
|
1391
1416
|
|
|
@@ -1495,10 +1520,20 @@ export {
|
|
|
1495
1520
|
STUDIO_SHOT_TRANSIENT_KEYS,
|
|
1496
1521
|
STUDIO_SHOT_DRAFT_KEYS,
|
|
1497
1522
|
STUDIO_TAKE_VOICE_KEYS,
|
|
1523
|
+
STUDIO_PREVIZ_RUN_STATE_KEYS,
|
|
1498
1524
|
stripStudioTransientSettings,
|
|
1499
1525
|
stripStudioDraftSettings,
|
|
1500
1526
|
stripStudioDraftWorkflow,
|
|
1501
1527
|
stripStudioTakeVoiceRecords,
|
|
1528
|
+
STUDIO_TAKE_SEQUENCE_KEYS,
|
|
1529
|
+
STUDIO_SEQUENCE_PLANNING_KEYS,
|
|
1530
|
+
STUDIO_SEQUENCE_UNIT_REVIEW_KEYS,
|
|
1531
|
+
STUDIO_SEQUENCE_POLICY_KEYS,
|
|
1532
|
+
STUDIO_SEQUENCE_UNIT_MANIFEST_KEYS,
|
|
1533
|
+
STUDIO_KEYFRAME_NODE_TRANSIENT_KEYS,
|
|
1534
|
+
STUDIO_KEYFRAME_TRANSIENT_KEYS,
|
|
1535
|
+
STUDIO_KEYFRAME_REVIEW_KEYS,
|
|
1536
|
+
STUDIO_KEYFRAME_ACCEPTANCE_PRIVATE_KEYS,
|
|
1502
1537
|
} from "./studio-transient.js"
|
|
1503
1538
|
|
|
1504
1539
|
export * from "./scene3d-v2-edit.js"
|
package/src/instagram-scrape.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Instagram scraper node — shared vocabulary + credit identifiers.
|
|
3
3
|
*
|
|
4
|
-
* Pulls PUBLIC Instagram posts (feed images, carousels, reels) by profile
|
|
5
|
-
* by
|
|
4
|
+
* Pulls PUBLIC Instagram posts (feed images, carousels, reels) by profile, by
|
|
5
|
+
* hashtag or by post link and emits a normalized JSON array. Same shape of contract as the
|
|
6
6
|
* Meta Ads node: everything the backend guard/reservation, the frontend credit
|
|
7
7
|
* badge and the docs formula must agree on lives here.
|
|
8
8
|
*
|
|
9
9
|
* Pricing: 1 credit per REQUESTED post, rounded UP to a fixed tier of
|
|
10
|
-
* `count × sources` (a profile / hashtag is one source, up to 5
|
|
10
|
+
* `count × sources` (a profile / hashtag / post link is one source, up to 5;
|
|
11
|
+
* a post link is always ONE post — see `instagramRequestedCount`). Optional
|
|
11
12
|
* per-post AI analysis folds into the same identifier, priced by the model's
|
|
12
13
|
* tier — reusing the Meta analysis per-item values so the two nodes stay in
|
|
13
14
|
* lockstep.
|
|
@@ -22,7 +23,12 @@ import { classifyCreativeFormat, type MetaAdsFormat } from "./meta-ads-scrape.js
|
|
|
22
23
|
|
|
23
24
|
export const INSTAGRAM_SCRAPE_NODE_TYPE = "instagram-scrape" as const
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
/**
|
|
27
|
+
* `profile` = recent posts of an account, `hashtag` = recent posts under a tag,
|
|
28
|
+
* `post` = exactly the posts whose links are given (one post per link — the
|
|
29
|
+
* "remake this post" entry point, where a full run must land on THAT post).
|
|
30
|
+
*/
|
|
31
|
+
export const INSTAGRAM_SCRAPE_MODES = ["profile", "hashtag", "post"] as const
|
|
26
32
|
export type InstagramScrapeMode = (typeof INSTAGRAM_SCRAPE_MODES)[number]
|
|
27
33
|
|
|
28
34
|
export function isInstagramScrapeMode(value: unknown): value is InstagramScrapeMode {
|
|
@@ -103,17 +109,70 @@ export function isInstagramScrapeCount(value: unknown): value is number {
|
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
112
|
+
* A post link: instagram.com (any subdomain, an optional username segment
|
|
113
|
+
* before the kind) or instagr.am, `/p/`, `/reel/`, `/reels/` or `/tv/`, with or
|
|
114
|
+
* without scheme, query string or trailing slash. Group 1 = the kind, group 2 =
|
|
115
|
+
* the shortcode. The shortcode is CASE-SENSITIVE — two codes that differ only
|
|
116
|
+
* in case are two different posts — so the `i` flag only relaxes the host and
|
|
117
|
+
* the kind; the captured code keeps its case.
|
|
118
|
+
*
|
|
119
|
+
* Instagram's own path words are never a username: `/share/p/<token>/` (the
|
|
120
|
+
* token of a share redirect, not a shortcode), `/stories/…`, `/explore/…` and
|
|
121
|
+
* the kinds themselves would otherwise turn into a wrong post that still bills.
|
|
122
|
+
* `/reels/audio/<id>/` is an audio page, not a reel.
|
|
123
|
+
*/
|
|
124
|
+
const INSTAGRAM_POST_LINK_RE =
|
|
125
|
+
/^(?:https?:\/\/)?(?:[a-z0-9-]+\.)*(?:instagram\.com|instagr\.am)\/(?:(?!(?:share|stories|explore|accounts|direct|p|reels?|tv)\/)[A-Za-z0-9._]+\/)?(p|reels?|tv)\/(?!audio(?:[/?#]|$))([A-Za-z0-9_-]+)/i
|
|
126
|
+
|
|
127
|
+
function parseInstagramPostLink(value: string): { readonly link: string; readonly shortcode: string } | null {
|
|
128
|
+
const match = INSTAGRAM_POST_LINK_RE.exec(value.trim())
|
|
129
|
+
if (!match) return null
|
|
130
|
+
const kind = match[1].toLowerCase()
|
|
131
|
+
const segment = kind === "p" ? "p" : kind === "tv" ? "tv" : "reel"
|
|
132
|
+
return { link: `https://www.instagram.com/${segment}/${match[2]}/`, shortcode: match[2] }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The canonical link of the post a value points at, or null when it is not an Instagram post link. */
|
|
136
|
+
export function instagramPostLink(value: string): string | null {
|
|
137
|
+
return parseInstagramPostLink(value)?.link ?? null
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Post links, canonicalised, deduped by shortcode (`/p/X` and `/reel/X` are
|
|
142
|
+
* one post), capped at MAX_SOURCES. An item holding several links (an API
|
|
143
|
+
* caller's array entry) is split like typed text.
|
|
144
|
+
*/
|
|
145
|
+
function splitInstagramPostLinks(raw: readonly string[]): string[] {
|
|
146
|
+
const seen = new Set<string>()
|
|
147
|
+
const out: string[] = []
|
|
148
|
+
for (const item of raw.flatMap((entry) => entry.split(/[\s,]+/))) {
|
|
149
|
+
const parsed = parseInstagramPostLink(item)
|
|
150
|
+
if (!parsed || seen.has(parsed.shortcode)) continue
|
|
151
|
+
seen.add(parsed.shortcode)
|
|
152
|
+
out.push(parsed.link)
|
|
153
|
+
if (out.length >= INSTAGRAM_SCRAPE_MAX_SOURCES) break
|
|
154
|
+
}
|
|
155
|
+
return out
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Targets are typed one per line; the route wants an array.
|
|
160
|
+
*
|
|
161
|
+
* - `profile` / `hashtag` (the default — the signature predates post mode):
|
|
162
|
+
* a target can be a bare username / `#tag`, so split on lines / commas only
|
|
163
|
+
* (never whitespace), strip a leading `@` or `#`, dedupe, cap at MAX_SOURCES.
|
|
164
|
+
* - `post`: only Instagram post links count; each is canonicalised (see
|
|
165
|
+
* `instagramPostLink`) and anything else is dropped, so the guard, the
|
|
166
|
+
* reservation and the scrape all see the same set of posts.
|
|
110
167
|
*/
|
|
111
|
-
export function splitInstagramTargets(value: unknown): string[] {
|
|
168
|
+
export function splitInstagramTargets(value: unknown, mode: InstagramScrapeMode = "profile"): string[] {
|
|
169
|
+
const separator = mode === "post" ? /[\s,]+/ : /[\n,]+/
|
|
112
170
|
const raw = Array.isArray(value)
|
|
113
171
|
? value.filter((v): v is string => typeof v === "string")
|
|
114
172
|
: typeof value === "string"
|
|
115
|
-
? value.split(
|
|
173
|
+
? value.split(separator)
|
|
116
174
|
: []
|
|
175
|
+
if (mode === "post") return splitInstagramPostLinks(raw)
|
|
117
176
|
const seen = new Set<string>()
|
|
118
177
|
const out: string[] = []
|
|
119
178
|
for (const item of raw) {
|
|
@@ -171,15 +230,29 @@ export interface InstagramNodeQuoteFields {
|
|
|
171
230
|
readonly analysisModel?: unknown
|
|
172
231
|
}
|
|
173
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Posts requested PER SOURCE: the `count` setting, except in post mode, where
|
|
235
|
+
* every source is one link and so one post (the count setting does not apply).
|
|
236
|
+
* Every price computation goes through this, so the guard, the reservation,
|
|
237
|
+
* the settlement and the node's badge cannot disagree on a post-mode run.
|
|
238
|
+
*/
|
|
239
|
+
export function instagramRequestedCount(mode: InstagramScrapeMode, count: number): number {
|
|
240
|
+
return mode === "post" ? 1 : count
|
|
241
|
+
}
|
|
242
|
+
|
|
174
243
|
/** Billable source count: number of targets (min 1). */
|
|
175
244
|
export function instagramScrapeSources(data: InstagramNodeQuoteFields): number {
|
|
176
|
-
return Math.max(1, Math.min(splitInstagramTargets(data.targets).length, INSTAGRAM_SCRAPE_MAX_SOURCES))
|
|
245
|
+
return Math.max(1, Math.min(splitInstagramTargets(data.targets, instagramScrapeMode(data.mode)).length, INSTAGRAM_SCRAPE_MAX_SOURCES))
|
|
177
246
|
}
|
|
178
247
|
|
|
179
248
|
/** The ONE credit identifier for a node's current settings. */
|
|
180
249
|
export function instagramScrapeCreditIdFromNode(data: InstagramNodeQuoteFields): string {
|
|
181
250
|
const count = typeof data.count === "number" ? data.count : INSTAGRAM_SCRAPE_DEFAULT_COUNT
|
|
182
|
-
return buildInstagramScrapeCreditId({
|
|
251
|
+
return buildInstagramScrapeCreditId({
|
|
252
|
+
count: instagramRequestedCount(instagramScrapeMode(data.mode), count),
|
|
253
|
+
sources: instagramScrapeSources(data),
|
|
254
|
+
analysis: instagramAnalysisTierFrom(data),
|
|
255
|
+
})
|
|
183
256
|
}
|
|
184
257
|
|
|
185
258
|
/**
|
|
@@ -187,16 +260,18 @@ export function instagramScrapeCreditIdFromNode(data: InstagramNodeQuoteFields):
|
|
|
187
260
|
* runs before Zod). Lands on the SAME tier the reservation computes.
|
|
188
261
|
*/
|
|
189
262
|
export function resolveInstagramScrapeCreditId(body: unknown): string {
|
|
190
|
-
const raw = body as { count?: unknown; targets?: unknown; analyze?: unknown; analysisModel?: unknown } | null | undefined
|
|
263
|
+
const raw = body as { mode?: unknown; count?: unknown; targets?: unknown; analyze?: unknown; analysisModel?: unknown } | null | undefined
|
|
191
264
|
if (!raw || typeof raw !== "object") return INSTAGRAM_SCRAPE_FALLBACK_CREDIT_ID
|
|
192
265
|
const count = raw.count === undefined ? INSTAGRAM_SCRAPE_DEFAULT_COUNT : raw.count
|
|
193
266
|
if (!isInstagramScrapeCount(count)) return INSTAGRAM_SCRAPE_FALLBACK_CREDIT_ID
|
|
194
|
-
// Same
|
|
267
|
+
// Same mode resolution as the route's Zod default (absent → profile) and the
|
|
268
|
+
// same splitter the handler uses for `sources` (dedupes, caps at MAX), so the
|
|
195
269
|
// pre-Zod guard and the post-Zod reservation always land on the same tier —
|
|
196
270
|
// a duplicate target bills once, not per copy.
|
|
197
|
-
const
|
|
271
|
+
const mode = instagramScrapeMode(raw.mode)
|
|
272
|
+
const sources = splitInstagramTargets(raw.targets, mode).length
|
|
198
273
|
if (sources < 1) return INSTAGRAM_SCRAPE_FALLBACK_CREDIT_ID
|
|
199
|
-
return buildInstagramScrapeCreditId({ count, sources, analysis: instagramAnalysisTierFrom(raw) })
|
|
274
|
+
return buildInstagramScrapeCreditId({ count: instagramRequestedCount(mode, count), sources, analysis: instagramAnalysisTierFrom(raw) })
|
|
200
275
|
}
|
|
201
276
|
|
|
202
277
|
// Re-export the shared creative-format vocabulary so the node imports one place.
|