Fix Prompt Builder Nitro build by inlining sequence helpers in utils.
The relative re-export of shared/prompt-sequences.mjs left an unresolved import in the SSR bundle.
This commit is contained in:
+82
-14
@@ -25,21 +25,89 @@ export const PROMPT_SEQUENCE_NAME_MAX = 80
|
||||
export const PROMPT_SEQUENCE_FIELD_MAX = 50_000
|
||||
export const PROMPT_SEQUENCE_TITLE_MAX = 60
|
||||
|
||||
export {
|
||||
newId,
|
||||
emptyCharacter,
|
||||
emptyScene,
|
||||
cloneSceneForNext,
|
||||
formatCharacterLine,
|
||||
assembleSceneText,
|
||||
assembleSequenceText
|
||||
} from '../shared/prompt-sequences.mjs'
|
||||
export function newId() {
|
||||
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
||||
return crypto.randomUUID()
|
||||
}
|
||||
return `ps-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`
|
||||
}
|
||||
|
||||
import {
|
||||
newId,
|
||||
emptyCharacter,
|
||||
emptyScene
|
||||
} from '../shared/prompt-sequences.mjs'
|
||||
export function emptyCharacter(): PromptSequenceCharacter {
|
||||
return { id: newId(), name: '', description: '' }
|
||||
}
|
||||
|
||||
export function emptyScene(index = 1): PromptSequenceScene {
|
||||
return {
|
||||
id: newId(),
|
||||
title: `Scene ${Math.max(1, index)}`,
|
||||
style: '',
|
||||
settings: '',
|
||||
characters: [emptyCharacter()],
|
||||
prompt: ''
|
||||
}
|
||||
}
|
||||
|
||||
export function cloneSceneForNext(previous: PromptSequenceScene, nextIndex: number): PromptSequenceScene {
|
||||
return {
|
||||
id: newId(),
|
||||
title: `Scene ${nextIndex}`,
|
||||
style: previous.style,
|
||||
settings: previous.settings,
|
||||
characters: (previous.characters || []).map(character => ({
|
||||
id: newId(),
|
||||
name: character.name,
|
||||
description: character.description
|
||||
})),
|
||||
prompt: previous.prompt
|
||||
}
|
||||
}
|
||||
|
||||
/** Character line: "Name: description", or name-only, or description-only. */
|
||||
export function formatCharacterLine(character: { name?: string; description?: string }) {
|
||||
const name = String(character?.name || '').trim()
|
||||
const description = String(character?.description || '').trim()
|
||||
if (!name && !description) return ''
|
||||
if (name && description) return `${name}: ${description}`
|
||||
return name || description
|
||||
}
|
||||
|
||||
export function assembleSceneText(scene: {
|
||||
style?: string
|
||||
settings?: string
|
||||
characters?: Array<{ name?: string; description?: string }>
|
||||
prompt?: string
|
||||
}) {
|
||||
const characterBlock = (scene.characters || [])
|
||||
.map(formatCharacterLine)
|
||||
.filter(Boolean)
|
||||
.join('\n')
|
||||
const parts = [
|
||||
String(scene.style || '').trim(),
|
||||
String(scene.settings || '').trim(),
|
||||
characterBlock,
|
||||
String(scene.prompt || '').trim()
|
||||
].filter(Boolean)
|
||||
return parts.join('\n\n')
|
||||
}
|
||||
|
||||
/**
|
||||
* Whole sequence as one copyable block.
|
||||
* Scenes join with a double blank line (\n\n\n) — same separator desktop Batch uses.
|
||||
* Sequence name is never included.
|
||||
*/
|
||||
export function assembleSequenceText(sequence: {
|
||||
scenes?: Array<{
|
||||
style?: string
|
||||
settings?: string
|
||||
characters?: Array<{ name?: string; description?: string }>
|
||||
prompt?: string
|
||||
}>
|
||||
}) {
|
||||
return (sequence.scenes || [])
|
||||
.map(assembleSceneText)
|
||||
.filter(Boolean)
|
||||
.join('\n\n\n')
|
||||
}
|
||||
|
||||
export function normalizePromptSequenceName(raw: unknown) {
|
||||
return String(raw || '').trim().replace(/\s+/g, ' ').slice(0, PROMPT_SEQUENCE_NAME_MAX)
|
||||
|
||||
Reference in New Issue
Block a user