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:
Towsty
2026-10-02 08:11:09 -05:00
parent 1bf97568bf
commit 790c33fcf0
3 changed files with 100 additions and 84 deletions
-68
View File
@@ -1,68 +0,0 @@
/** Pure prompt-sequence helpers (shared by page + tests). */
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)}`
}
export function emptyCharacter() {
return { id: newId(), name: '', description: '' }
}
export function emptyScene(index = 1) {
return {
id: newId(),
title: `Scene ${Math.max(1, index)}`,
style: '',
settings: '',
characters: [emptyCharacter()],
prompt: ''
}
}
export function cloneSceneForNext(previous, nextIndex) {
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
}
}
export function formatCharacterLine(character) {
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) {
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')
}
/** Scenes join with \\n\\n\\n (desktop Batch double blank). Name is never included. */
export function assembleSequenceText(sequence) {
return (sequence?.scenes || [])
.map(assembleSceneText)
.filter(Boolean)
.join('\n\n\n')
}
+18 -2
View File
@@ -1,12 +1,28 @@
import test from 'node:test' import test from 'node:test'
import assert from 'node:assert/strict' import assert from 'node:assert/strict'
import { import { readFileSync, writeFileSync, unlinkSync } from 'node:fs'
import { join } from 'node:path'
import { tmpdir } from 'node:os'
import { pathToFileURL } from 'node:url'
import ts from 'typescript'
const src = readFileSync(new URL('../utils/promptSequences.ts', import.meta.url), 'utf8')
const js = ts.transpileModule(src, {
compilerOptions: {
target: ts.ScriptTarget.ES2022,
module: ts.ModuleKind.ESNext
}
}).outputText
const tmp = join(tmpdir(), `prompt-sequences-${process.pid}.mjs`)
writeFileSync(tmp, js)
const {
assembleSceneText, assembleSceneText,
assembleSequenceText, assembleSequenceText,
formatCharacterLine, formatCharacterLine,
emptyScene, emptyScene,
cloneSceneForNext cloneSceneForNext
} from '../shared/prompt-sequences.mjs' } = await import(pathToFileURL(tmp).href)
unlinkSync(tmp)
test('formatCharacterLine covers name/description cases', () => { test('formatCharacterLine covers name/description cases', () => {
assert.equal(formatCharacterLine({ name: 'Ada', description: 'tall' }), 'Ada: tall') assert.equal(formatCharacterLine({ name: 'Ada', description: 'tall' }), 'Ada: tall')
+82 -14
View File
@@ -25,21 +25,89 @@ export const PROMPT_SEQUENCE_NAME_MAX = 80
export const PROMPT_SEQUENCE_FIELD_MAX = 50_000 export const PROMPT_SEQUENCE_FIELD_MAX = 50_000
export const PROMPT_SEQUENCE_TITLE_MAX = 60 export const PROMPT_SEQUENCE_TITLE_MAX = 60
export { export function newId() {
newId, if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
emptyCharacter, return crypto.randomUUID()
emptyScene, }
cloneSceneForNext, return `ps-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`
formatCharacterLine, }
assembleSceneText,
assembleSequenceText
} from '../shared/prompt-sequences.mjs'
import { export function emptyCharacter(): PromptSequenceCharacter {
newId, return { id: newId(), name: '', description: '' }
emptyCharacter, }
emptyScene
} from '../shared/prompt-sequences.mjs' 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) { export function normalizePromptSequenceName(raw: unknown) {
return String(raw || '').trim().replace(/\s+/g, ' ').slice(0, PROMPT_SEQUENCE_NAME_MAX) return String(raw || '').trim().replace(/\s+/g, ' ').slice(0, PROMPT_SEQUENCE_NAME_MAX)