Files
2026-11-13 11:46:25 +08:00

35 lines
1.5 KiB
JavaScript

// Resolve the effective per-shot model, never the episode default by accident.
export function referenceImageLimit(model = '', provider = '') {
if (['LTX-2.3', 'LTX-2.3-Text-Preserve', 'Wan2.2-I2V'].includes(model)) return 1
return provider === 'aliyun' || model.startsWith('wan3.0-video') ? 10 : 9
}
export function usesComposedFirstFrame(model = '') {
return ['LTX-2.3', 'LTX-2.3-Text-Preserve', 'Wan2.2-I2V'].includes(model)
}
export function selectVideoReferences(assets, limit) {
const seen = new Set()
const selected = []
for (const asset of assets) {
if (!asset.url || seen.has(asset.url) || selected.length >= limit) continue
seen.add(asset.url)
selected.push(asset)
}
return selected
}
export function resolveReferenceMentions(prompt, assets, boundAssets = assets) {
const names = [...new Set(boundAssets.map(x => x.name).filter(Boolean))].sort((a,b) => b.length - a.length)
const escape = s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
// Match the known name before stripping a stale index: 404宿舍 starts with digits.
return prompt.replace(/@([^\s@#]+)/g, (match, raw) => {
for (const name of names) {
const numbered = raw.match(new RegExp(`^图片\\d+?${escape(name)}`))
if (!raw.startsWith(name) && !numbered) continue
const index = assets.findIndex(x => x.name === name)
return `@${index >= 0 ? `图片${index + 1}` : ''}${name}${raw.slice(numbered ? numbered[0].length : name.length)}`
}
return match
})
}