379
server-node/src/prompts/characterAssetPrompts.ts
Normal file
379
server-node/src/prompts/characterAssetPrompts.ts
Normal file
@@ -0,0 +1,379 @@
|
||||
import {
|
||||
buildMasterPrompt,
|
||||
buildVideoActionPrompt,
|
||||
getActionTemplateById,
|
||||
} from '../../../packages/shared/src/prompts/qwenSprite.js';
|
||||
|
||||
function clampPromptSeedText(value: unknown, maxLength: number) {
|
||||
if (typeof value !== 'string') {
|
||||
return '';
|
||||
}
|
||||
|
||||
return value.replace(/\s+/gu, ' ').trim().slice(0, maxLength);
|
||||
}
|
||||
|
||||
export const CHARACTER_PROMPT_BUNDLE_SYSTEM_PROMPT = `你是 RPG 角色资产提示词编译器。
|
||||
你会收到一个角色设定摘要,请为当前项目生成 3 段可直接交给资产生成模型的中文提示词。
|
||||
你必须只输出一个 JSON 对象,不要输出 Markdown、代码块、注释或解释。
|
||||
输出格式必须严格为:
|
||||
{
|
||||
"visualPromptText": "角色主图提示词",
|
||||
"animationPromptText": "角色动作提示词",
|
||||
"scenePromptText": "角色关联场景提示词"
|
||||
}
|
||||
|
||||
硬性约束:
|
||||
- 所有字段都必须是自然中文。
|
||||
- visualPromptText 用于角色主图候选,必须是角色标准设定图而不是场景海报,突出单人全身、右向斜侧身站姿、脚底完整可见、服装武器轮廓稳定、纯绿色绿幕背景、1:1 画幅。
|
||||
- visualPromptText 里的主题词只能落在角色自身的服装、发型、材质、纹样、饰品、武器和发光细节上,不要自动补出建筑、风景、漂浮物、烟雾或其他角色以外的场景元素。
|
||||
- visualPromptText 要明确“身体整体朝右,但保留少量正面信息”,避免生成完全 90 度纯右视图。
|
||||
- animationPromptText 用于角色动作试片,必须突出发力方式、动作气质、连贯性、同一角色一致性,不要写镜头切换。
|
||||
- scenePromptText 用于该角色关联的场景背景,必须突出角色首次登场或主活动区域的环境气质与空间结构,适配横版 RPG 场景。
|
||||
- 三段提示词都要可直接使用,不要编号,不要加字段名解释,不要输出负面提示词。`;
|
||||
|
||||
export type CharacterPromptBundle = {
|
||||
visualPromptText: string;
|
||||
animationPromptText: string;
|
||||
scenePromptText: string;
|
||||
source: 'llm' | 'fallback';
|
||||
model: string | null;
|
||||
};
|
||||
|
||||
export function buildFallbackCharacterPromptBundle(params: {
|
||||
characterName: string;
|
||||
roleKind: string;
|
||||
roleTitle: string;
|
||||
roleLabel: string;
|
||||
description: string;
|
||||
backstory: string;
|
||||
personality: string;
|
||||
motivation: string;
|
||||
combatStyle: string;
|
||||
tags: string[];
|
||||
}) {
|
||||
const roleAnchor =
|
||||
[params.roleTitle, params.roleLabel].filter(Boolean).join(' / ') ||
|
||||
(params.roleKind === 'playable' ? '可扮演角色' : '场景角色');
|
||||
const characterAnchor = params.characterName || '该角色';
|
||||
const descriptionAnchor =
|
||||
params.description || params.backstory || params.personality || '气质鲜明';
|
||||
const combatAnchor =
|
||||
params.combatStyle || params.motivation || '动作发力清晰';
|
||||
const tagAnchor =
|
||||
params.tags.length > 0 ? `保留 ${params.tags.join('、')} 的识别点。` : '';
|
||||
|
||||
return {
|
||||
visualPromptText: [
|
||||
`${characterAnchor},${roleAnchor}。`,
|
||||
'单人全身,2D 横版 RPG 角色标准设定图,1:1 正方形画幅,头身比控制在 2 到 2.5 头身,偏大头身,靠头部、发型、服装、配饰表现角色记忆点,躯干与四肢短而紧凑,五官简化,深色粗轮廓配合清晰大色块,右向斜侧身站立,身体整体朝右但保留少量正面信息,服装、发型、轮廓稳定清楚。',
|
||||
`外观气质围绕:${descriptionAnchor}。`,
|
||||
combatAnchor ? `战斗识别点:${combatAnchor}。` : '',
|
||||
tagAnchor,
|
||||
'背景固定为纯绿色绿幕,不带建筑、风景、漂浮物和其他场景元素,方便自动抠像,不做正面立绘,不做完全 90 度纯右视图,不做夸张透视。',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' '),
|
||||
animationPromptText: [
|
||||
`${characterAnchor}的核心动作试片。`,
|
||||
'保持同一角色的服装、发型、体型一致,镜头稳定,侧身朝右,动作连贯。',
|
||||
combatAnchor ? `动作气质参考:${combatAnchor}。` : '',
|
||||
params.personality ? `角色气质补充:${params.personality}。` : '',
|
||||
'发力起手明确,过程干净,收招利落,避免漂移和变形。',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' '),
|
||||
scenePromptText: [
|
||||
`${characterAnchor}关联主场景,适合作为首次登场区域或常驻活动空间。`,
|
||||
'16:9 横版 RPG 场景背景,上下分区清楚,上半部分表现中远景氛围,下半部分是可站立地面。',
|
||||
`场景叙事气质围绕:${descriptionAnchor}。`,
|
||||
params.backstory ? `背景线索可参考:${params.backstory}。` : '',
|
||||
params.motivation
|
||||
? `环境中可埋入与当前目标相关的暗示:${params.motivation}。`
|
||||
: '',
|
||||
'整体风格克制统一,适合剧情探索与战斗底图。',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' '),
|
||||
source: 'fallback' as const,
|
||||
model: null,
|
||||
};
|
||||
}
|
||||
|
||||
function sanitizePromptBundleValue(
|
||||
value: unknown,
|
||||
fallback: string,
|
||||
maxLength: number,
|
||||
) {
|
||||
const normalized = clampPromptSeedText(value, maxLength);
|
||||
return normalized || fallback;
|
||||
}
|
||||
|
||||
export function sanitizeCharacterPromptBundle(
|
||||
value: unknown,
|
||||
fallback: CharacterPromptBundle,
|
||||
model: string,
|
||||
) {
|
||||
const record = isRecordValue(value) ? value : {};
|
||||
|
||||
return {
|
||||
visualPromptText: sanitizePromptBundleValue(
|
||||
record.visualPromptText,
|
||||
fallback.visualPromptText,
|
||||
280,
|
||||
),
|
||||
animationPromptText: sanitizePromptBundleValue(
|
||||
record.animationPromptText,
|
||||
fallback.animationPromptText,
|
||||
280,
|
||||
),
|
||||
scenePromptText: sanitizePromptBundleValue(
|
||||
record.scenePromptText,
|
||||
fallback.scenePromptText,
|
||||
320,
|
||||
),
|
||||
source: 'llm' as const,
|
||||
model: model.trim() || null,
|
||||
};
|
||||
}
|
||||
|
||||
function sanitizeAnimationPromptText(value: string, maxLength: number) {
|
||||
return value
|
||||
.replace(/\s+/gu, ' ')
|
||||
.replace(/血浆|喷血|鲜血|断肢|斩首|裸体|裸露|色情|性交/gu, '')
|
||||
.replace(/死亡|死去|击杀/gu, '倒地结束')
|
||||
.replace(/受击|受伤/gu, '失衡')
|
||||
.replace(/砍杀|斩击/gu, '挥击')
|
||||
.trim()
|
||||
.slice(0, maxLength);
|
||||
}
|
||||
|
||||
function buildCompactAnimationCharacterBrief(value: string) {
|
||||
const normalized = sanitizeAnimationPromptText(value, 160);
|
||||
if (!normalized) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return normalized
|
||||
.split(/[/|\n,,。;;]+/u)
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean)
|
||||
.slice(0, 4)
|
||||
.join(',');
|
||||
}
|
||||
|
||||
export function buildCharacterPromptBundleUserPrompt(params: {
|
||||
roleKind: string;
|
||||
characterBriefText: string;
|
||||
characterName: string;
|
||||
roleTitle: string;
|
||||
roleLabel: string;
|
||||
description: string;
|
||||
backstory: string;
|
||||
personality: string;
|
||||
motivation: string;
|
||||
combatStyle: string;
|
||||
tags: string[];
|
||||
}) {
|
||||
return [
|
||||
'请根据下面的角色卡摘要,编译一组默认资产提示词。',
|
||||
'提示词用于当前项目的角色主图、动作试片和角色关联场景背景。',
|
||||
'请保留该角色的身份识别点、气质、战斗方式与世界感,不要空泛套模板。',
|
||||
'',
|
||||
`角色类型:${params.roleKind === 'playable' ? '可扮演角色' : '场景角色'}`,
|
||||
params.characterName ? `角色名称:${params.characterName}` : '',
|
||||
params.roleTitle ? `角色头衔:${params.roleTitle}` : '',
|
||||
params.roleLabel ? `世界身份:${params.roleLabel}` : '',
|
||||
params.description ? `角色描述:${params.description}` : '',
|
||||
params.backstory ? `角色背景:${params.backstory}` : '',
|
||||
params.personality ? `角色性格:${params.personality}` : '',
|
||||
params.motivation ? `角色动机:${params.motivation}` : '',
|
||||
params.combatStyle ? `战斗风格:${params.combatStyle}` : '',
|
||||
params.tags.length > 0 ? `角色标签:${params.tags.join('、')}` : '',
|
||||
'',
|
||||
'角色卡全文:',
|
||||
params.characterBriefText,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
export function buildNpcVisualPrompt(promptText: string, characterBriefText = '') {
|
||||
const mergedBrief = [characterBriefText.trim(), promptText.trim()]
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
|
||||
return buildMasterPrompt(
|
||||
mergedBrief || '自定义世界角色,服装完整,姿态自然。',
|
||||
);
|
||||
}
|
||||
|
||||
export function buildNpcVisualNegativePrompt() {
|
||||
return [
|
||||
'正面视角',
|
||||
'左朝向',
|
||||
'完全 90 度纯右视图',
|
||||
'镜头透视',
|
||||
'半身像',
|
||||
'脚被裁切',
|
||||
'头顶被裁切',
|
||||
'多角色',
|
||||
'复杂背景',
|
||||
'建筑场景',
|
||||
'漂浮物',
|
||||
'烟雾环境',
|
||||
'武器消失',
|
||||
'武器换手',
|
||||
'额外手臂',
|
||||
'额外腿',
|
||||
'服装变化',
|
||||
'脸部变化',
|
||||
'模糊',
|
||||
'运动模糊',
|
||||
'文字',
|
||||
'水印',
|
||||
'UI 元素',
|
||||
'软萌 Q版大头贴',
|
||||
'儿童绘本风',
|
||||
'厚涂插画感',
|
||||
'低对比柔边',
|
||||
].join(',');
|
||||
}
|
||||
|
||||
export function buildImageSequencePrompt(
|
||||
animation: string,
|
||||
promptText: string,
|
||||
frameCount: number,
|
||||
useChromaKey: boolean,
|
||||
) {
|
||||
return [
|
||||
`同一角色连续 ${frameCount} 帧动作序列,动作主题是 ${animation}。`,
|
||||
'固定机位,单人,全身,侧身朝右,保持同一套服装、发型、武器和体型。',
|
||||
'帧间动作连续,姿态逐步推进,不要换人,不要跳变,不要多余物体。',
|
||||
useChromaKey
|
||||
? '纯绿色背景,无地面装饰,方便后期抠像。'
|
||||
: '背景尽量纯净,避免复杂场景。',
|
||||
promptText.trim(),
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
export function buildNpcAnimationPrompt(options: {
|
||||
animation: string;
|
||||
promptText: string;
|
||||
useChromaKey: boolean;
|
||||
loop: boolean;
|
||||
characterBriefText?: string;
|
||||
actionTemplateId?: string;
|
||||
}) {
|
||||
const characterBrief = buildCompactAnimationCharacterBrief(
|
||||
options.characterBriefText ?? '',
|
||||
);
|
||||
const actionDetailText = sanitizeAnimationPromptText(options.promptText, 140);
|
||||
const loopRule = options.loop
|
||||
? '这是循环动作,直接进入动作循环中段,不要开场静止站桩,不要把主参考图原样作为第一帧。'
|
||||
: options.animation === 'die'
|
||||
? '这是死亡终结动作,首帧参考主图角色形象即可,尾帧停在死亡结束姿态,不要回到主图形象。'
|
||||
: '这是非循环动作,首帧和尾帧都要回到参考主图角色形象,中段完成动作变化。';
|
||||
|
||||
if (options.actionTemplateId) {
|
||||
return [
|
||||
buildVideoActionPrompt({
|
||||
actionTemplate: getActionTemplateById(
|
||||
options.actionTemplateId as Parameters<
|
||||
typeof getActionTemplateById
|
||||
>[0],
|
||||
),
|
||||
actionDetailText,
|
||||
useChromaKey: options.useChromaKey,
|
||||
characterBrief: characterBrief || `${options.animation} 动作角色`,
|
||||
}),
|
||||
loopRule,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
return [
|
||||
`单人 NPC 全身动作视频,动作主题是 ${options.animation}。`,
|
||||
'角色固定为同一人,侧身朝右,镜头稳定,轮廓清晰,武器不可丢失。',
|
||||
'动作连贯,避免服装、发型、面部、武器随机漂移。',
|
||||
options.useChromaKey
|
||||
? '背景为纯绿色绿幕,无其他人物和场景元素,方便后期抠像。'
|
||||
: '背景简洁纯净,无复杂场景。',
|
||||
characterBrief ? `角色设定:${characterBrief}` : '',
|
||||
actionDetailText,
|
||||
loopRule,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
export function buildArkCharacterAnimationPrompt(options: {
|
||||
animation: string;
|
||||
promptText: string;
|
||||
useChromaKey: boolean;
|
||||
loop: boolean;
|
||||
characterBriefText?: string;
|
||||
actionTemplateId?: string;
|
||||
}) {
|
||||
const normalizedAnimationName =
|
||||
options.animation.trim().replace(/\s+/gu, '_') || 'idle';
|
||||
const characterBrief = buildCompactAnimationCharacterBrief(
|
||||
options.characterBriefText ?? '',
|
||||
);
|
||||
const actionDetailText = sanitizeAnimationPromptText(options.promptText, 140);
|
||||
const frameRule = options.loop
|
||||
? '首帧严格使用图片1,尾帧严格使用图片2,循环动作必须自然闭环,不要静止开场。'
|
||||
: '首帧严格使用图片1,尾帧严格使用图片2,中段完成完整动作变化,收束干净。';
|
||||
|
||||
if (options.actionTemplateId) {
|
||||
return [
|
||||
buildVideoActionPrompt({
|
||||
actionTemplate: getActionTemplateById(
|
||||
options.actionTemplateId as Parameters<typeof getActionTemplateById>[0],
|
||||
),
|
||||
actionDetailText,
|
||||
useChromaKey: options.useChromaKey,
|
||||
characterBrief: characterBrief || `${normalizedAnimationName} action role`,
|
||||
}),
|
||||
`动作英文名:${normalizedAnimationName}。`,
|
||||
frameRule,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
return [
|
||||
`单人 NPC 全身动作视频,动作英文名是 ${normalizedAnimationName}。`,
|
||||
'角色固定为图片1和图片2中的同一人,侧身朝右,镜头稳定,轮廓清晰,武器不可丢失。',
|
||||
'动作连贯,避免服装、发型、面部、武器随机漂移,不要多角色,不要镜头切换。',
|
||||
options.useChromaKey
|
||||
? '背景为纯绿色绿幕,无其他人物和场景元素,方便后期抠像。'
|
||||
: '背景简洁纯净,无复杂场景。',
|
||||
characterBrief ? `角色设定:${characterBrief}` : '',
|
||||
actionDetailText ? `动作细节:${actionDetailText}` : '',
|
||||
frameRule,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
}
|
||||
|
||||
export function buildFallbackModerationSafeAnimationPrompt(options: {
|
||||
animation: string;
|
||||
loop: boolean;
|
||||
useChromaKey: boolean;
|
||||
}) {
|
||||
return [
|
||||
`单人全身角色动作视频,动作主题是 ${options.animation}。`,
|
||||
'角色固定为同一人,右向斜侧身,镜头稳定,轮廓清楚。',
|
||||
options.loop
|
||||
? '循环动作直接进入稳定循环,不要静止开场,不要定格首帧。'
|
||||
: '非循环动作首尾回到角色标准站姿,中段完成动作变化。',
|
||||
options.useChromaKey
|
||||
? '背景为纯绿色绿幕,无其他人物和场景元素。'
|
||||
: '背景简洁纯净。',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
}
|
||||
645
server-node/src/prompts/customWorldPrompts.ts
Normal file
645
server-node/src/prompts/customWorldPrompts.ts
Normal file
@@ -0,0 +1,645 @@
|
||||
import type {
|
||||
CustomWorldGenerationFramework,
|
||||
CustomWorldGenerationLandmarkOutline,
|
||||
CustomWorldGenerationRoleBatchStage,
|
||||
CustomWorldGenerationRoleBatchType,
|
||||
CustomWorldGenerationRoleOutline,
|
||||
CustomWorldLandmark,
|
||||
CustomWorldProfile,
|
||||
} from '../modules/custom-world/runtimeTypes.js';
|
||||
|
||||
const MIN_CUSTOM_WORLD_LANDMARK_COUNT = 10;
|
||||
const CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES = [15, 30, 60, 90] as const;
|
||||
const CUSTOM_WORLD_SCENE_RELATIVE_POSITION_OPTIONS = [
|
||||
'forward',
|
||||
'back',
|
||||
'left',
|
||||
'right',
|
||||
'north',
|
||||
'south',
|
||||
'east',
|
||||
'west',
|
||||
'up',
|
||||
'down',
|
||||
'inside',
|
||||
'outside',
|
||||
'portal',
|
||||
] as const;
|
||||
|
||||
function buildFrameworkSummaryText(
|
||||
framework: CustomWorldGenerationFramework,
|
||||
options: {
|
||||
maxLandmarks?: number;
|
||||
} = {},
|
||||
) {
|
||||
const maxLandmarks = options.maxLandmarks ?? MIN_CUSTOM_WORLD_LANDMARK_COUNT;
|
||||
const landmarkText = framework.landmarks
|
||||
.slice(0, maxLandmarks)
|
||||
.map(
|
||||
(landmark) =>
|
||||
`${landmark.name}(${landmark.dangerLevel},${landmark.description})`,
|
||||
)
|
||||
.join('、');
|
||||
|
||||
return [
|
||||
`世界:${framework.name}`,
|
||||
`副标题:${framework.subtitle}`,
|
||||
`世界概述:${framework.summary}`,
|
||||
`世界基调:${framework.tone}`,
|
||||
`玩家核心目标:${framework.playerGoal}`,
|
||||
framework.majorFactions.length > 0
|
||||
? `主要势力:${framework.majorFactions.join('、')}`
|
||||
: '',
|
||||
framework.coreConflicts.length > 0
|
||||
? `核心冲突:${framework.coreConflicts.join('、')}`
|
||||
: '',
|
||||
`开局归处:${framework.camp.name}(${framework.camp.description})`,
|
||||
landmarkText ? `关键场景:${landmarkText}` : '',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
function buildLandmarkAppearanceLookup(
|
||||
framework: CustomWorldGenerationFramework,
|
||||
) {
|
||||
const lookup = new Map<string, string[]>();
|
||||
|
||||
framework.landmarks.forEach((landmark) => {
|
||||
landmark.sceneNpcNames.forEach((npcName) => {
|
||||
const key = npcName.trim();
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
const current = lookup.get(key) ?? [];
|
||||
if (!current.includes(landmark.name)) {
|
||||
current.push(landmark.name);
|
||||
}
|
||||
lookup.set(key, current);
|
||||
});
|
||||
});
|
||||
|
||||
return lookup;
|
||||
}
|
||||
|
||||
function buildRoleOutlinePromptLines(
|
||||
roleBatch: CustomWorldGenerationRoleOutline[],
|
||||
options: {
|
||||
framework: CustomWorldGenerationFramework;
|
||||
roleType: CustomWorldGenerationRoleBatchType;
|
||||
},
|
||||
) {
|
||||
const appearanceLookup =
|
||||
options.roleType === 'story'
|
||||
? buildLandmarkAppearanceLookup(options.framework)
|
||||
: new Map<string, string[]>();
|
||||
|
||||
return roleBatch
|
||||
.map((role) => {
|
||||
const appearanceText =
|
||||
options.roleType === 'story'
|
||||
? (appearanceLookup.get(role.name)?.join('、') ?? '未指定')
|
||||
: '';
|
||||
return [
|
||||
`- ${role.name} / ${role.title}`,
|
||||
`身份:${role.role}`,
|
||||
`框架描述:${role.description}`,
|
||||
`预设好感:${role.initialAffinity}`,
|
||||
role.relationshipHooks.length > 0
|
||||
? `关系切入口:${role.relationshipHooks.join('、')}`
|
||||
: '',
|
||||
role.tags.length > 0 ? `标签:${role.tags.join('、')}` : '',
|
||||
appearanceText ? `出现场景:${appearanceText}` : '',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(';');
|
||||
})
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
export function buildCustomWorldFrameworkPrompt(settingText: string) {
|
||||
return [
|
||||
'请先根据下面的玩家设定创建一份“世界核心骨架”,后续我会分步骤生成角色名单、场景名单和详细档案。',
|
||||
'你必须只输出一个能被 JSON.parse 直接解析的 JSON 对象,不要输出 Markdown、代码块、注释或解释。',
|
||||
'这一步只保留世界顶层信息与一个开局归处场景,不要输出 playableNpcs、storyNpcs、landmarks,也不要展开人物和地图细节。',
|
||||
'玩家设定:',
|
||||
settingText.trim(),
|
||||
'',
|
||||
'输出 JSON 模板:',
|
||||
'{',
|
||||
' "name": "世界名称",',
|
||||
' "subtitle": "世界副标题",',
|
||||
' "summary": "世界概述",',
|
||||
' "tone": "世界基调",',
|
||||
' "playerGoal": "玩家核心目标",',
|
||||
' "templateWorldType": "WUXIA|XIANXIA",',
|
||||
' "majorFactions": ["势力甲", "势力乙"],',
|
||||
' "coreConflicts": ["冲突甲", "冲突乙"],',
|
||||
' "camp": {',
|
||||
' "name": "开局归处名称",',
|
||||
' "description": "这是玩家进入世界后的第一处落脚点描述",',
|
||||
' "dangerLevel": "low|medium|high|extreme"',
|
||||
' }',
|
||||
'}',
|
||||
'',
|
||||
'要求:',
|
||||
'- 所有生成文本都必须使用中文。',
|
||||
'- 这一步只输出顶层 9 个字段:name、subtitle、summary、tone、playerGoal、templateWorldType、majorFactions、coreConflicts、camp。',
|
||||
'- 这是一个完全独立的自定义世界;不要在任何正文里直接写出“武侠世界”“仙侠世界”等现成世界名。',
|
||||
'- templateWorldType 只是系统兼容字段,不代表正文应当引用的世界名称。',
|
||||
'- camp 必须表示玩家开局时的落脚处,名字不要直接写成“某某营地”,更接近归舍、住处、栖居、前哨居所这类“家/归处”的概念。',
|
||||
'- 不要输出 playableNpcs、storyNpcs、landmarks、items,也不要输出任何角色和地图细节。',
|
||||
'- majorFactions 保持 2 到 3 个,coreConflicts 保持 2 到 3 个。',
|
||||
'- 世界设定必须直接源自玩家输入,不要脱离主题乱扩写。',
|
||||
'- 每个字符串尽量简洁:subtitle 控制在 8 到 18 个汉字内,summary 控制在 16 到 32 个汉字内,tone 控制在 6 到 16 个汉字内,playerGoal 控制在 16 到 32 个汉字内,camp.description 控制在 18 到 40 个汉字内。',
|
||||
'- 返回前自检:必须是一个能被 JSON.parse 直接解析的单个 JSON 对象。',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
export function buildCustomWorldFrameworkJsonRepairPrompt(
|
||||
responseText: string,
|
||||
) {
|
||||
return [
|
||||
'下面这段文本本应是自定义世界核心骨架的单个 JSON 对象,但当前不能被 JSON.parse 直接解析。',
|
||||
'请只输出修复后的 JSON 对象。',
|
||||
'顶层必须只包含:name、subtitle、summary、tone、playerGoal、templateWorldType、majorFactions、coreConflicts、camp。',
|
||||
'不要输出 playableNpcs、storyNpcs、landmarks、items 或任何其他字段。',
|
||||
'majorFactions 与 coreConflicts 必须是字符串数组。',
|
||||
'camp 必须是对象,且包含:name、description、dangerLevel。',
|
||||
'原始文本:',
|
||||
responseText.trim(),
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
export function buildCustomWorldRoleOutlineBatchPrompt(params: {
|
||||
framework: CustomWorldGenerationFramework;
|
||||
roleType: CustomWorldGenerationRoleBatchType;
|
||||
batchCount: number;
|
||||
forbiddenNames?: string[];
|
||||
}) {
|
||||
const { framework, roleType, batchCount, forbiddenNames = [] } = params;
|
||||
const key = roleType === 'playable' ? 'playableNpcs' : 'storyNpcs';
|
||||
const label = roleType === 'playable' ? '可扮演角色' : '场景角色';
|
||||
|
||||
return [
|
||||
`请根据下面的世界核心信息,生成一批${label}框架名单。`,
|
||||
'后续我会继续补全人物档案,所以这一步每个角色只保留最少字段。',
|
||||
'你必须只输出一个能被 JSON.parse 直接解析的 JSON 对象,不要输出 Markdown、代码块、注释或解释。',
|
||||
'世界核心信息:',
|
||||
buildFrameworkSummaryText(framework, { maxLandmarks: 0 }),
|
||||
forbiddenNames.length > 0
|
||||
? `这些名字已经生成,禁止重复:${forbiddenNames.join('、')}`
|
||||
: '',
|
||||
'',
|
||||
'输出 JSON 模板:',
|
||||
'{',
|
||||
` "${key}": [`,
|
||||
' {',
|
||||
' "name": "角色名称",',
|
||||
' "title": "称号",',
|
||||
' "role": "身份",',
|
||||
' "description": "极简定位描述",',
|
||||
' "initialAffinity": 18,',
|
||||
' "relationshipHooks": ["一个关系切入口"],',
|
||||
' "tags": ["标签1", "标签2"]',
|
||||
' }',
|
||||
' ]',
|
||||
'}',
|
||||
'',
|
||||
'要求:',
|
||||
`- 必须生成恰好 ${batchCount} 个${label}。`,
|
||||
'- 这是一个完全独立的自定义世界;不要把角色写成来自“武侠世界”“仙侠世界”等现成世界。',
|
||||
'- 名称必须具体且互不重复,不要使用 角色1、NPC1、场景角色1 之类的占位名。',
|
||||
'- 只保留:name、title、role、description、initialAffinity、relationshipHooks、tags。',
|
||||
'- relationshipHooks 最多 1 条;tags 保持 1 到 2 个。',
|
||||
'- description 控制在 8 到 18 个汉字内,title 和 role 也尽量短。',
|
||||
'- initialAffinity 必须是 -40 到 90 的整数。',
|
||||
roleType === 'playable'
|
||||
? '- 可扮演角色的定位必须明显不同,通常使用 18 到 40 的初始好感。'
|
||||
: '- 场景角色要覆盖势力成员、居民、异类或怪物,不要全是同一种身份;敌对或怪物型角色可以使用负好感。',
|
||||
'- 所有生成文本都必须使用中文。',
|
||||
'- 返回前自检:必须是一个能被 JSON.parse 直接解析的单个 JSON 对象。',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
export function buildCustomWorldRoleOutlineBatchJsonRepairPrompt(params: {
|
||||
responseText: string;
|
||||
roleType: CustomWorldGenerationRoleBatchType;
|
||||
expectedCount: number;
|
||||
forbiddenNames?: string[];
|
||||
}) {
|
||||
const { responseText, roleType, expectedCount, forbiddenNames = [] } = params;
|
||||
const key = roleType === 'playable' ? 'playableNpcs' : 'storyNpcs';
|
||||
|
||||
return [
|
||||
`下面这段文本本应是自定义世界${roleType === 'playable' ? '可扮演角色' : '场景角色'}框架名单批次的单个 JSON 对象,但当前不能被 JSON.parse 直接解析。`,
|
||||
'请只输出修复后的 JSON 对象。',
|
||||
`顶层必须只包含一个 ${key} 数组。`,
|
||||
`必须保留恰好 ${expectedCount} 个角色对象。`,
|
||||
forbiddenNames.length > 0
|
||||
? `禁止使用这些重复名:${forbiddenNames.join('、')}。`
|
||||
: '',
|
||||
'每个角色只包含:name、title、role、description、initialAffinity、relationshipHooks、tags。',
|
||||
'如果缺少字段:字符串补空字符串,relationshipHooks 和 tags 补空数组,initialAffinity 补默认整数。',
|
||||
'不要输出 backstory、skills、landmarks 或任何其他字段。',
|
||||
'原始文本:',
|
||||
responseText.trim(),
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
export function buildCustomWorldLandmarkSeedBatchPrompt(params: {
|
||||
framework: CustomWorldGenerationFramework;
|
||||
batchCount: number;
|
||||
forbiddenNames?: string[];
|
||||
}) {
|
||||
const { framework, batchCount, forbiddenNames = [] } = params;
|
||||
|
||||
return [
|
||||
'请根据下面的世界核心信息,生成一批场景地标骨架。',
|
||||
'后续我会继续补全场景角色分布和连接关系,所以这一步只保留最少字段。',
|
||||
'你必须只输出一个能被 JSON.parse 直接解析的 JSON 对象,不要输出 Markdown、代码块、注释或解释。',
|
||||
'世界核心信息:',
|
||||
buildFrameworkSummaryText(framework, { maxLandmarks: 0 }),
|
||||
forbiddenNames.length > 0
|
||||
? `这些场景名已经生成,禁止重复:${forbiddenNames.join('、')}`
|
||||
: '',
|
||||
'',
|
||||
'输出 JSON 模板:',
|
||||
'{',
|
||||
' "landmarks": [',
|
||||
' {',
|
||||
' "name": "场景名称",',
|
||||
' "description": "极简场景描述",',
|
||||
' "dangerLevel": "low|medium|high|extreme"',
|
||||
' }',
|
||||
' ]',
|
||||
'}',
|
||||
'',
|
||||
'要求:',
|
||||
`- 必须生成恰好 ${batchCount} 个 landmarks。`,
|
||||
'- 这是一个完全独立的自定义世界;不要在场景描述里直接写“武侠世界”“仙侠世界”等现成世界名。',
|
||||
'- 这一步只保留:name、description、dangerLevel。',
|
||||
'- 不要输出 sceneNpcNames、connections、imageSrc 或其他字段。',
|
||||
'- 名称必须具体且互不重复,不要使用 场景1、地点1 之类的占位名。',
|
||||
'- description 控制在 8 到 18 个汉字内。',
|
||||
'- 所有生成文本都必须使用中文。',
|
||||
'- 返回前自检:必须是一个能被 JSON.parse 直接解析的单个 JSON 对象。',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
export function buildCustomWorldLandmarkSeedBatchJsonRepairPrompt(params: {
|
||||
responseText: string;
|
||||
expectedCount: number;
|
||||
forbiddenNames?: string[];
|
||||
}) {
|
||||
const { responseText, expectedCount, forbiddenNames = [] } = params;
|
||||
|
||||
return [
|
||||
'下面这段文本本应是自定义世界场景地标骨架批次的单个 JSON 对象,但当前不能被 JSON.parse 直接解析。',
|
||||
'请只输出修复后的 JSON 对象。',
|
||||
'顶层必须只包含一个 landmarks 数组。',
|
||||
`必须保留恰好 ${expectedCount} 个地标对象。`,
|
||||
forbiddenNames.length > 0
|
||||
? `禁止使用这些重复场景名:${forbiddenNames.join('、')}。`
|
||||
: '',
|
||||
'每个地标只包含:name、description、dangerLevel。',
|
||||
'不要输出 sceneNpcNames、connections 或其他字段。',
|
||||
'原始文本:',
|
||||
responseText.trim(),
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
export function buildCustomWorldLandmarkNetworkBatchPrompt(params: {
|
||||
framework: CustomWorldGenerationFramework;
|
||||
landmarkBatch: CustomWorldGenerationLandmarkOutline[];
|
||||
storyNpcs: CustomWorldGenerationRoleOutline[];
|
||||
}) {
|
||||
const { framework, landmarkBatch, storyNpcs } = params;
|
||||
const relativePositionValues =
|
||||
CUSTOM_WORLD_SCENE_RELATIVE_POSITION_OPTIONS.join('|');
|
||||
const allLandmarkNames = framework.landmarks.map((landmark) => landmark.name);
|
||||
const storyNpcNames = storyNpcs.map((npc) => npc.name);
|
||||
|
||||
return [
|
||||
'请根据下面的世界信息,为这一批场景补全“出现场景角色”和“地图连接关系”。',
|
||||
'你必须只输出一个能被 JSON.parse 直接解析的 JSON 对象,不要输出 Markdown、代码块、注释或解释。',
|
||||
'世界核心信息:',
|
||||
buildFrameworkSummaryText(framework, { maxLandmarks: 0 }),
|
||||
`全部场景名:${allLandmarkNames.join('、')}`,
|
||||
`可用场景角色名:${storyNpcNames.join('、')}`,
|
||||
'本批次场景骨架:',
|
||||
landmarkBatch
|
||||
.map(
|
||||
(landmark) =>
|
||||
`- ${landmark.name} / 危险度:${landmark.dangerLevel} / 描述:${landmark.description}`,
|
||||
)
|
||||
.join('\n'),
|
||||
'',
|
||||
'输出 JSON 模板:',
|
||||
'{',
|
||||
' "landmarks": [',
|
||||
' {',
|
||||
' "name": "场景名称",',
|
||||
' "sceneNpcNames": ["场景角色1", "场景角色2", "场景角色3"],',
|
||||
' "connections": [',
|
||||
' {',
|
||||
' "targetLandmarkName": "其他场景名称",',
|
||||
` "relativePosition": "${CUSTOM_WORLD_SCENE_RELATIVE_POSITION_OPTIONS[0] ?? 'forward'}",`,
|
||||
' "summary": "极简通路说明"',
|
||||
' }',
|
||||
' ]',
|
||||
' }',
|
||||
' ]',
|
||||
'}',
|
||||
'',
|
||||
'要求:',
|
||||
`- 只输出这批 ${landmarkBatch.length} 个场景,不要输出其他场景。`,
|
||||
'- 这是一个完全独立的自定义世界;summary 不要带入“武侠”“仙侠”等现成世界名称。',
|
||||
'- 名称必须与本批次场景骨架完全一致,不得改名。',
|
||||
'- 每个场景必须提供恰好 3 个唯一 sceneNpcNames,且只能从可用场景角色名里选择。',
|
||||
`- 每个场景必须提供恰好 2 条 connections;relativePosition 只能使用:${relativePositionValues}。`,
|
||||
'- targetLandmarkName 必须来自全部场景名,且不能连接自己,两个目标场景不能重复。',
|
||||
'- summary 控制在 4 到 10 个汉字内。',
|
||||
'- 不要输出 description、dangerLevel、backstory 或其他字段。',
|
||||
'- 所有生成文本都必须使用中文。',
|
||||
'- 返回前自检:必须是一个能被 JSON.parse 直接解析的单个 JSON 对象。',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
export function buildCustomWorldLandmarkNetworkBatchJsonRepairPrompt(params: {
|
||||
responseText: string;
|
||||
expectedNames: string[];
|
||||
}) {
|
||||
const { responseText, expectedNames } = params;
|
||||
|
||||
return [
|
||||
'下面这段文本本应是自定义世界场景连接补全批次的单个 JSON 对象,但当前不能被 JSON.parse 直接解析。',
|
||||
'请只输出修复后的 JSON 对象。',
|
||||
'顶层必须只包含一个 landmarks 数组。',
|
||||
`landmarks 里只能保留这些场景名:${expectedNames.join('、')}。`,
|
||||
'每个场景对象只包含:name、sceneNpcNames、connections。',
|
||||
'connections 里的每个对象必须包含:targetLandmarkName、relativePosition、summary。',
|
||||
'不要输出 description、dangerLevel 或其他字段。',
|
||||
'原始文本:',
|
||||
responseText.trim(),
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
export function buildCustomWorldRoleBatchPrompt(params: {
|
||||
framework: CustomWorldGenerationFramework;
|
||||
roleType: CustomWorldGenerationRoleBatchType;
|
||||
roleBatch: CustomWorldGenerationRoleOutline[];
|
||||
stage: CustomWorldGenerationRoleBatchStage;
|
||||
}) {
|
||||
const { framework, roleType, roleBatch, stage } = params;
|
||||
const key = roleType === 'playable' ? 'playableNpcs' : 'storyNpcs';
|
||||
const label = roleType === 'playable' ? '可扮演角色' : '场景角色';
|
||||
const roleOutlineText = buildRoleOutlinePromptLines(roleBatch, {
|
||||
framework,
|
||||
roleType,
|
||||
});
|
||||
|
||||
if (stage === 'narrative') {
|
||||
return [
|
||||
`请根据下面的世界框架,补全这一批${label}的叙事基础设定。`,
|
||||
'你必须只输出一个能被 JSON.parse 直接解析的 JSON 对象,不要输出 Markdown、代码块、注释或解释。',
|
||||
'玩家原始设定:',
|
||||
framework.settingText,
|
||||
'',
|
||||
'世界框架摘要:',
|
||||
buildFrameworkSummaryText(framework, { maxLandmarks: 8 }),
|
||||
'',
|
||||
`本批次需要补全的${label}(名称必须原样保留):`,
|
||||
roleOutlineText,
|
||||
'',
|
||||
'输出 JSON 模板:',
|
||||
'{',
|
||||
` "${key}": [`,
|
||||
' {',
|
||||
' "name": "角色名称",',
|
||||
' "backstory": "背景经历",',
|
||||
' "personality": "性格特点",',
|
||||
' "motivation": "当前动机",',
|
||||
' "combatStyle": "战斗风格"',
|
||||
' }',
|
||||
' ]',
|
||||
'}',
|
||||
'',
|
||||
'要求:',
|
||||
`- 只输出这批${label},不要输出其他角色、场景或额外顶层字段。`,
|
||||
'- 这是一个完全独立的自定义世界;不要在角色背景、性格、动机或战斗风格里直接写“武侠世界”“仙侠世界”等现成世界名。',
|
||||
`- ${key} 的数量必须与本批次名单完全一致。`,
|
||||
'- 名称必须与批次名单完全一致,不得增删改名。',
|
||||
'- 只补全 backstory、personality、motivation、combatStyle 这 4 个字段,不要输出 backstoryReveal、skills、initialItems。',
|
||||
'- 必须严格沿用框架中的 title、role、description、initialAffinity、relationshipHooks、tags 所表达的角色定位,不要改名,不要改阵营。',
|
||||
'- backstory 必须写出角色和当前世界的具体关系,至少落到一个势力、一个地点、一个正在发生的局势变化,不要只写抽象气质或泛泛成长史。',
|
||||
'- personality 不能只写单个形容词,要体现角色在这个世界里的处事习惯、应对压力的方式和与人相处的锋面。',
|
||||
'- motivation 必须是“此刻正在推动角色行动”的现实目标,而不是空泛理想;它要和玩家目标、核心冲突或开局处境形成直接拉扯。',
|
||||
'- combatStyle 要体现角色为什么会这样战斗,它最好能反映其身份、经历、所属势力或长期栖身的场景环境。',
|
||||
roleType === 'story'
|
||||
? '- 怪物型场景角色要在 backstory 或 combatStyle 中直接写出怪物特征、栖息环境或攻击方式。'
|
||||
: '- 可扮演角色要体现成长空间、协作价值和明确的入队理由。',
|
||||
'- 所有生成文本都必须使用中文。',
|
||||
'- 每个字符串尽量简洁但不能空泛:backstory/personality/motivation/combatStyle 控制在 18 到 56 个汉字内。',
|
||||
'- 返回前自检:必须是一个能被 JSON.parse 直接解析的单个 JSON 对象。',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
return [
|
||||
`请根据下面的世界框架,补全这一批${label}的背景章节、技能和初始物品。`,
|
||||
'你必须只输出一个能被 JSON.parse 直接解析的 JSON 对象,不要输出 Markdown、代码块、注释或解释。',
|
||||
'玩家原始设定:',
|
||||
framework.settingText,
|
||||
'',
|
||||
'世界框架摘要:',
|
||||
buildFrameworkSummaryText(framework, { maxLandmarks: 8 }),
|
||||
'',
|
||||
`本批次需要补全的${label}(名称必须原样保留):`,
|
||||
roleOutlineText,
|
||||
'',
|
||||
'输出 JSON 模板:',
|
||||
'{',
|
||||
` "${key}": [`,
|
||||
' {',
|
||||
' "name": "角色名称",',
|
||||
' "backstoryReveal": {',
|
||||
' "publicSummary": "公开可见的背景摘要",',
|
||||
' "chapters": [',
|
||||
` { "id": "surface", "title": "表层来意", "affinityRequired": ${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES[0]}, "teaser": "${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES[0]}好感可见的提示", "content": "${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES[0]}好感时解锁的背景内容", "contextSnippet": "可供后续剧情引用的摘要" },`,
|
||||
` { "id": "scar", "title": "旧事裂痕", "affinityRequired": ${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES[1]}, "teaser": "${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES[1]}好感可见的提示", "content": "${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES[1]}好感时解锁的背景内容", "contextSnippet": "可供后续剧情引用的摘要" },`,
|
||||
` { "id": "hidden", "title": "隐藏执念", "affinityRequired": ${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES[2]}, "teaser": "${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES[2]}好感可见的提示", "content": "${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES[2]}好感时解锁的背景内容", "contextSnippet": "可供后续剧情引用的摘要" },`,
|
||||
` { "id": "final", "title": "最终底牌", "affinityRequired": ${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES[3]}, "teaser": "${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES[3]}好感可见的提示", "content": "${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES[3]}好感时解锁的背景内容", "contextSnippet": "可供后续剧情引用的摘要" }`,
|
||||
' ]',
|
||||
' },',
|
||||
' "skills": [',
|
||||
' { "name": "技能1", "summary": "技能说明", "style": "起手压制" },',
|
||||
' { "name": "技能2", "summary": "技能说明", "style": "机动周旋" },',
|
||||
' { "name": "技能3", "summary": "技能说明", "style": "爆发终结" }',
|
||||
' ],',
|
||||
' "initialItems": [',
|
||||
' { "name": "初始物品1", "category": "武器", "quantity": 1, "rarity": "rare", "description": "物品说明", "tags": ["标签1", "标签2"] },',
|
||||
' { "name": "初始物品2", "category": "消耗品", "quantity": 2, "rarity": "uncommon", "description": "物品说明", "tags": ["标签1", "标签2"] },',
|
||||
' { "name": "初始物品3", "category": "专属物品", "quantity": 1, "rarity": "rare", "description": "物品说明", "tags": ["标签1", "标签2"] }',
|
||||
' ]',
|
||||
' }',
|
||||
' ]',
|
||||
'}',
|
||||
'',
|
||||
'要求:',
|
||||
`- 只输出这批${label},不要输出其他角色、场景或额外顶层字段。`,
|
||||
'- 这是一个完全独立的自定义世界;不要在公开背景、技能名、物品名或说明里直接带入“武侠”“仙侠”等现成世界名。',
|
||||
`- ${key} 的数量必须与本批次名单完全一致。`,
|
||||
'- 名称必须与批次名单完全一致,不得增删改名。',
|
||||
'- 这一阶段只补全 backstoryReveal、skills、initialItems,不要重复输出 title、role、description、backstory、personality、motivation、combatStyle、initialAffinity、relationshipHooks、tags。',
|
||||
'- 背景章节、技能和初始物品必须严格围绕框架中的角色定位来写,不要改变阵营、身份或出现场景。',
|
||||
'- backstoryReveal 的 4 章必须形成明显递进:第 1 章写表层来意与第一印象,第 2 章写旧伤或代价,第 3 章写角色真正隐瞒的线索,第 4 章写最终底牌或不可回避的真相。',
|
||||
'- 每一章都必须紧贴当前世界设定,至少落到具体势力、地点、事件、制度、禁忌或关系链中的一项,不要写成可套用到任何世界的空泛心情。',
|
||||
'- teaser 必须像“继续相处后能戳到的钩子”,content 必须像“真正解锁后得到的新信息”,contextSnippet 必须可直接被后续剧情复用,三者不要只是同一句话改写。',
|
||||
'- skills 不只是职业标签,要体现角色的个人经历、所属阵营、地理环境或禁忌系统影响,尽量写出这个世界独有的招式语感。',
|
||||
'- initialItems 不只是常规装备清单,至少要有一件能反映角色背景、关系或任务压力的私人物件。',
|
||||
`- backstoryReveal.chapters 必须恰好 4 章,affinityRequired 固定使用 ${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES.join('、')}。`,
|
||||
'- 每个角色必须提供恰好 3 个 skills 和恰好 3 个 initialItems。',
|
||||
'- initialItems.category 只能使用:武器、护甲、饰品、消耗品、材料、稀有品、专属物品。',
|
||||
roleType === 'story'
|
||||
? '- 怪物型角色仍然放进 storyNpcs,并在 role、description、backstory、combatStyle、tags、backstoryReveal、skills 或 initialItems 中明确写出怪物特征、栖息环境、攻击方式或异形外观。'
|
||||
: '- 可扮演角色要保持明确的成长空间、协作价值和入队理由。',
|
||||
'- 所有生成文本都必须使用中文。',
|
||||
'- 每个字符串尽量简洁但要有信息量:backstoryReveal.publicSummary 控制在 14 到 36 个汉字内,backstoryReveal.teaser 控制在 12 到 28 个汉字内,backstoryReveal.content 控制在 20 到 64 个汉字内,contextSnippet 控制在 12 到 36 个汉字内,skills.summary 和 initialItems.description 控制在 12 到 32 个汉字内。',
|
||||
'- 返回前自检:必须是一个能被 JSON.parse 直接解析的单个 JSON 对象。',
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
export function buildCustomWorldRoleBatchJsonRepairPrompt(params: {
|
||||
responseText: string;
|
||||
roleType: CustomWorldGenerationRoleBatchType;
|
||||
expectedNames: string[];
|
||||
stage: CustomWorldGenerationRoleBatchStage;
|
||||
}) {
|
||||
const { responseText, roleType, expectedNames, stage } = params;
|
||||
const key = roleType === 'playable' ? 'playableNpcs' : 'storyNpcs';
|
||||
|
||||
if (stage === 'narrative') {
|
||||
return [
|
||||
`下面这段文本本应是自定义世界${roleType === 'playable' ? '可扮演角色' : '场景角色'}叙事设定批次的单个 JSON 对象,但当前不能被 JSON.parse 直接解析。`,
|
||||
'请只输出修复后的 JSON 对象。',
|
||||
`顶层必须只包含一个 ${key} 数组。`,
|
||||
`这个数组里只能保留这些角色名:${expectedNames.join('、')}。`,
|
||||
'名称必须与名单完全一致,不得增删改名;如果原文遗漏,可按名单顺序补齐占位对象。',
|
||||
'每个角色都必须包含:name、backstory、personality、motivation、combatStyle。',
|
||||
'如果缺少字段:字符串补空字符串。',
|
||||
'不要输出 backstoryReveal、skills、initialItems,也不要新增名单外的角色。',
|
||||
'原始文本:',
|
||||
responseText.trim(),
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
return [
|
||||
`下面这段文本本应是自定义世界${roleType === 'playable' ? '可扮演角色' : '场景角色'}档案补全批次的单个 JSON 对象,但当前不能被 JSON.parse 直接解析。`,
|
||||
'请只输出修复后的 JSON 对象。',
|
||||
`顶层必须只包含一个 ${key} 数组。`,
|
||||
`这个数组里只能保留这些角色名:${expectedNames.join('、')}。`,
|
||||
'名称必须与名单完全一致,不得增删改名;如果原文遗漏,可按名单顺序补齐占位对象。',
|
||||
'每个角色都必须包含:name、backstoryReveal、skills、initialItems。',
|
||||
`backstoryReveal 必须包含 publicSummary 和 4 个 chapters,chapters.affinityRequired 固定为 ${CUSTOM_WORLD_BACKSTORY_CHAPTER_AFFINITIES.join('、')}。`,
|
||||
'skills 默认补成 3 个对象,每个对象包含 name、summary、style;initialItems 默认补成 3 个对象,每个对象包含 name、category、quantity、rarity、description、tags。',
|
||||
'不要输出 backstory、personality、motivation、combatStyle、landmarks,也不要新增名单外的角色。',
|
||||
'原始文本:',
|
||||
responseText.trim(),
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function clampSceneImageText(value: string, maxLength: number) {
|
||||
const normalized = value.trim().replace(/\s+/g, ' ');
|
||||
if (!normalized) {
|
||||
return '';
|
||||
}
|
||||
if (normalized.length <= maxLength) {
|
||||
return normalized;
|
||||
}
|
||||
return `${normalized.slice(0, Math.max(0, maxLength - 1)).trim()}…`;
|
||||
}
|
||||
|
||||
function describeDangerLevel(dangerLevel: string) {
|
||||
const normalized = dangerLevel.trim().toLowerCase();
|
||||
if (normalized === 'low' || normalized === '低')
|
||||
return '气氛相对平静,但暗藏细节张力';
|
||||
if (normalized === 'medium' || normalized === '中')
|
||||
return '带有明确的探索压力与潜在威胁';
|
||||
if (normalized === 'high' || normalized === '高')
|
||||
return '危险感强烈,空间中有明显压迫感';
|
||||
if (normalized === 'extreme' || normalized === '极高')
|
||||
return '极端危险,环境本身就像会吞没闯入者';
|
||||
return dangerLevel.trim()
|
||||
? `危险氛围:${dangerLevel.trim()}`
|
||||
: '危险气质保持克制但不可忽视';
|
||||
}
|
||||
|
||||
export const DEFAULT_CUSTOM_WORLD_SCENE_IMAGE_NEGATIVE_PROMPT = [
|
||||
'文字',
|
||||
'水印',
|
||||
'logo',
|
||||
'UI界面',
|
||||
'对话框',
|
||||
'边框',
|
||||
'人物近景特写',
|
||||
'多人合照',
|
||||
'模糊',
|
||||
'低清晰度',
|
||||
'畸形建筑',
|
||||
'现代车辆',
|
||||
'监控摄像头',
|
||||
].join(',');
|
||||
|
||||
export function buildCustomWorldSceneImagePrompt(
|
||||
profile: Pick<
|
||||
CustomWorldProfile,
|
||||
'name' | 'subtitle' | 'summary' | 'tone' | 'playerGoal' | 'settingText'
|
||||
>,
|
||||
landmark: Pick<CustomWorldLandmark, 'name' | 'description' | 'dangerLevel'>,
|
||||
userPrompt = '',
|
||||
options: {
|
||||
hasReferenceImage?: boolean;
|
||||
} = {},
|
||||
) {
|
||||
const worldName = clampSceneImageText(profile.name, 18) || '未命名世界';
|
||||
const worldSubtitle = clampSceneImageText(profile.subtitle, 18);
|
||||
const worldTone = clampSceneImageText(profile.tone, 48);
|
||||
const worldGoal = clampSceneImageText(profile.playerGoal, 48);
|
||||
const worldSummary = clampSceneImageText(profile.summary, 72);
|
||||
const worldSetting = clampSceneImageText(profile.settingText, 72);
|
||||
const landmarkName = clampSceneImageText(landmark.name, 18) || '未命名场景';
|
||||
const landmarkDescription = clampSceneImageText(landmark.description, 96);
|
||||
const requestedVisual = clampSceneImageText(userPrompt, 120);
|
||||
const dangerMood = describeDangerLevel(landmark.dangerLevel);
|
||||
|
||||
return [
|
||||
'为横版 16:9 2D RPG 生成高完成度像素风场景背景,适合作为剧情探索与战斗底图。',
|
||||
'画面构图必须严格按上下 1:1 分区:上半部分严格控制在整张图的 1/2 高度内,只描绘场景远景与中远景轮廓,不要让背景内容向下侵占超过半屏。',
|
||||
'下半部分严格占据整张图的 1/2 高度,用于玩家角色站位与展示,必须是模拟 3D 游戏视角的地面近景,有明确的透视延伸和近大远小关系,不是平铺的 2D 侧视地面。',
|
||||
'下半部分的内容必须是明确可站立的地面本体,例如道路、石板、平台、广场、甲板、沙地或草地,要有连续、稳定、可落脚的站位逻辑,不能只是装饰性前景、坑洞、障碍堆、栏杆带或不可通行的景物。',
|
||||
'下半部分地面近景要保持相对简洁、低细节、轮廓清楚、便于角色站立,不要堆满道具、植被、碎石、栏杆或复杂装饰。',
|
||||
options.hasReferenceImage
|
||||
? '已提供一张自定义参考图,请沿用其构图、镜头或氛围线索,同时继续满足本次场景需求。'
|
||||
: '',
|
||||
`世界:${worldName}${worldSubtitle ? `,${worldSubtitle}` : ''}。`,
|
||||
worldSetting ? `玩家设定:${worldSetting}。` : '',
|
||||
worldSummary ? `世界概述:${worldSummary}。` : '',
|
||||
worldTone ? `整体基调:${worldTone}。` : '',
|
||||
worldGoal ? `玩家目标关联:${worldGoal}。` : '',
|
||||
`场景名称:${landmarkName}。`,
|
||||
landmarkDescription ? `场景描述:${landmarkDescription}。` : '',
|
||||
requestedVisual ? `本次想要生成的画面内容:${requestedVisual}。` : '',
|
||||
`${dangerMood}。`,
|
||||
'不要出现 UI、字幕、文字、水印、logo 或装饰边框,人物仅可作为很小的远景剪影,画面重点放在场景本身,不要遮挡下半部分的角色展示区域。',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('');
|
||||
}
|
||||
784
server-node/src/prompts/eightAnchorPrompts.ts
Normal file
784
server-node/src/prompts/eightAnchorPrompts.ts
Normal file
@@ -0,0 +1,784 @@
|
||||
import type {
|
||||
EightAnchorContent,
|
||||
HiddenLineValue,
|
||||
IconicElementValue,
|
||||
KeyRelationshipValue,
|
||||
ThemeBoundaryValue,
|
||||
} from '../../../packages/shared/src/contracts/customWorldAgent.js';
|
||||
import {
|
||||
createEmptyEightAnchorContent,
|
||||
normalizeEightAnchorContent,
|
||||
} from '../services/eightAnchorCompatibilityService.js';
|
||||
|
||||
export type PromptUserInputSignal =
|
||||
| 'rich'
|
||||
| 'normal'
|
||||
| 'sparse'
|
||||
| 'correction'
|
||||
| 'delegate';
|
||||
|
||||
export type PromptDriftRisk = 'low' | 'medium' | 'high';
|
||||
|
||||
export type PromptConversationMode =
|
||||
| 'bootstrap'
|
||||
| 'expand'
|
||||
| 'compress'
|
||||
| 'repair_direction'
|
||||
| 'force_complete'
|
||||
| 'closing';
|
||||
|
||||
export type PromptDynamicState = {
|
||||
currentTurn: number;
|
||||
progressPercent: number;
|
||||
userInputSignal: PromptUserInputSignal;
|
||||
driftRisk: PromptDriftRisk;
|
||||
quickFillRequested: boolean;
|
||||
conversationMode: PromptConversationMode;
|
||||
judgementSummary: string;
|
||||
};
|
||||
|
||||
export type PromptDynamicStateInference = {
|
||||
userInputSignal?: unknown;
|
||||
driftRisk?: unknown;
|
||||
conversationMode?: unknown;
|
||||
judgementSummary?: unknown;
|
||||
};
|
||||
|
||||
const BASE_SYSTEM_PROMPT = `你是一个负责共创游戏世界设定的专业策划。
|
||||
|
||||
你正在和用户一起共创一个游戏世界。每一轮你都必须读取:
|
||||
1. 当前完整设定结构
|
||||
2. 用户聊天记录
|
||||
|
||||
然后输出:
|
||||
1. 一版新的完整设定结构
|
||||
2. 当前 progress 百分比
|
||||
3. 一段直接回复用户的话
|
||||
|
||||
你必须把“新的完整设定结构”视为下一轮的唯一有效版本。
|
||||
你的输出会直接覆盖上一版设定结构。
|
||||
|
||||
你不是在做局部 patch。
|
||||
你不是在做解释报告。
|
||||
你不是在给开发者写分析。
|
||||
你是在同时完成:
|
||||
1. 世界设定更新
|
||||
2. 当前推进程度判断
|
||||
3. 对用户的共创回复`;
|
||||
|
||||
const GLOBAL_HARD_RULES = `全局硬约束:
|
||||
|
||||
1. 必须输出完整的设定结构,而不是只输出变化部分。
|
||||
2. 新的设定结构会直接覆盖旧内容,因此不得随意丢失仍然成立的重要信息。
|
||||
3. 如果用户明确修正旧设定,必须在新的设定结构中直接体现修正结果。
|
||||
4. 如果用户输入信息不足,可以保留上一版中仍然成立的内容。
|
||||
5. progressPercent 最低为 0,不允许为负数。
|
||||
6. replyText 会直接发送给用户,因此要自然、直接、可继续聊天。
|
||||
7. 不要输出额外解释,不要输出 markdown 代码块,不要输出开发备注。
|
||||
8. replyText 不要写成长篇策划文,不要展开大段世界观百科。
|
||||
9. replyText 默认只推进当前最关键的一步,不要同时抛出很多话题。
|
||||
10. replyText 不要提及“八锚点”“锚点”“结构字段”“框架字段”等内部概念词。
|
||||
11. 你输出的 JSON 必须可以被直接解析。
|
||||
12. 输出字段顺序必须固定为:replyText、progressPercent、nextAnchorContent。`;
|
||||
|
||||
const MODE_RULES: Record<PromptConversationMode, string> = {
|
||||
bootstrap: `当前模式:bootstrap
|
||||
|
||||
目标:
|
||||
1. 先把世界的基本方向抓住
|
||||
2. 不要一次塞太多新设定
|
||||
3. 回复要降低用户开口压力
|
||||
|
||||
本轮行为要求:
|
||||
1. 优先从用户输入里抓世界方向、玩家视角、主题边界的线索
|
||||
2. 如果用户信息很少,不要强行把整套结构一次补满
|
||||
3. replyText 要像共创搭档,而不是像审问
|
||||
4. 默认只推进一个最关键的问题方向
|
||||
5. 如果用户刚开口,优先给“被理解感”,再轻轻推进下一步
|
||||
6. 可以用一句很短的话先确认你抓到的核心方向,再提一个最好回答的问题
|
||||
7. 不要把问题问得像表单采集,不要一口气追问多个维度
|
||||
|
||||
用户体验要求:
|
||||
1. 让用户觉得“现在很容易继续往下说”
|
||||
2. 不要制造被考试、被拷问、被策划问卷追着跑的感觉
|
||||
3. replyText 最好短、稳、可接话
|
||||
4. 如果用户信息很少,也不要显得冷淡或机械`,
|
||||
expand: `当前模式:expand
|
||||
|
||||
目标:
|
||||
1. 在保持现有方向的前提下,把设定结构逐步补全
|
||||
2. 尽量让一轮输入覆盖多个关键维度
|
||||
|
||||
本轮行为要求:
|
||||
1. 继续保留上一版里仍成立的设定
|
||||
2. 优先把用户本轮输入映射进多个关键维度,而不是只更新一个字段
|
||||
3. replyText 要明确体现“你已经理解了哪些内容”
|
||||
4. 不要突然大幅改写已经成形的世界
|
||||
5. 如果用户这一轮给了多条有效信息,replyText 应先把这些信息自然串起来,再决定下一步
|
||||
6. 可以适度替用户整理,但不要把回复写成总结报告
|
||||
7. 默认继续往前推一步,不要在还没必要时突然收束或突然跳到成稿感
|
||||
|
||||
用户体验要求:
|
||||
1. 让用户感到“我刚说的内容都被接住了”
|
||||
2. 回复里可以带一点顺势整理感,但不要太像会议纪要
|
||||
3. 不要无视用户刚提供的高价值细节
|
||||
4. 不要让用户觉得系统在自顾自重写世界`,
|
||||
compress: `当前模式:compress
|
||||
|
||||
目标:
|
||||
1. 开始收束当前设定
|
||||
2. 减少无效发散
|
||||
3. 让 progress 更接近可进入下一阶段
|
||||
|
||||
本轮行为要求:
|
||||
1. 新的设定结构优先保留稳定内容,不要无端重写
|
||||
2. 对用户本轮输入做高密度吸收
|
||||
3. replyText 要更聚焦,不要绕圈
|
||||
4. 默认只推进当前最影响 completion 的一步
|
||||
5. 如果用户还在补细节,优先把细节挂回现有骨架,而不是继续开新分支
|
||||
6. 可以适度提醒“还差哪类关键空位”,但不要把回复写成 checklist
|
||||
7. 如果已有信息足够,replyText 可以更像“确认并收束”,少一点继续发散式追问
|
||||
|
||||
用户体验要求:
|
||||
1. 让用户感觉世界正在变得更稳,而不是越来越散
|
||||
2. 让推进感更明确,但不要显得催促
|
||||
3. 回复语气应更笃定一些,减少反复横跳
|
||||
4. 不要把用户刚补进来的细节又冲淡掉`,
|
||||
repair_direction: `当前模式:repair_direction
|
||||
|
||||
目标:
|
||||
1. 处理用户对既有设定的修正
|
||||
2. 避免世界方向飘散或自相矛盾
|
||||
|
||||
本轮行为要求:
|
||||
1. 如果用户明确改口,新的设定结构必须体现修正后的方向
|
||||
2. 对已经不再成立的旧设定,不要机械保留
|
||||
3. progressPercent 可以停滞,也可以小幅回落,但不能为负
|
||||
4. replyText 要承认用户的修正,并顺着修正后的方向继续聊
|
||||
5. 先处理“改掉什么”,再决定“往哪里继续推”
|
||||
6. 不要一边口头承认用户修正,一边在设定结构里偷偷留住旧方向
|
||||
7. 如果修正幅度很大,replyText 可以帮助用户确认新方向已经接管当前语境
|
||||
|
||||
用户体验要求:
|
||||
1. 让用户感到“我刚刚的纠偏真的生效了”
|
||||
2. 不要和用户辩论旧方案为什么也行
|
||||
3. 不要表现出对修正的不情愿
|
||||
4. 回复要体现重心已经切到新方向,而不是停留在旧世界观惯性里`,
|
||||
force_complete: `当前模式:force_complete
|
||||
|
||||
目标:
|
||||
1. 基于当前方向直接补齐剩余设定
|
||||
2. 生成一版尽量完整、可进入下一阶段的设定结构
|
||||
3. 结束当前收集阶段
|
||||
|
||||
本轮行为要求:
|
||||
1. 尽量保留已经形成的世界方向
|
||||
2. 对明显缺失的关键维度进行合理补全
|
||||
3. 不要继续拉长聊天,不要再追问用户
|
||||
4. progressPercent 直接输出为 100
|
||||
5. replyText 要自然引导用户点击“生成游戏设定草稿”
|
||||
6. 补全时要优先做“顺着已有方向补齐”,而不是突然换题材、换气质、换主冲突
|
||||
7. 可以让结果更完整,但不要补得过满、过死、过像定稿圣经
|
||||
8. replyText 更像阶段完成提示,不再像继续采集信息的对话
|
||||
|
||||
用户体验要求:
|
||||
1. 让用户感到“系统已经帮我把能补的补好了”
|
||||
2. 不要在这一步突然冒出很多陌生设定把用户吓出戏
|
||||
3. 回复要有完成感,但不要太官话
|
||||
4. 清楚告诉用户下一步可以做什么`,
|
||||
closing: `当前模式:closing
|
||||
|
||||
目标:
|
||||
1. 尽量形成一版可用的设定底子
|
||||
2. 不再继续发散新世界观
|
||||
|
||||
本轮行为要求:
|
||||
1. 优先收束,而不是扩写
|
||||
2. 不要大改已经成形的核心设定
|
||||
3. progressPercent 接近完成时,replyText 要更像确认与推进
|
||||
4. 如果用户没有大改方向,尽量让下一版内容更稳定
|
||||
5. 可以轻微补足缺口,但不要再大开新支线
|
||||
6. replyText 应减少探索式措辞,增加“已经基本成形”的稳定感
|
||||
7. 如果只差少量空位,优先把这些空位自然补平,而不是重新打开大话题
|
||||
|
||||
用户体验要求:
|
||||
1. 让用户感觉作品已经快成了,而不是还在无穷试探
|
||||
2. 回复可以更像确认和轻推,不要继续像前期那样频繁试探
|
||||
3. 保持留白感,不要把所有东西都一次说死
|
||||
4. 让用户自然过渡到下一阶段,而不是突然被切断对话`,
|
||||
};
|
||||
|
||||
const USER_SIGNAL_RULES: Record<PromptUserInputSignal, string> = {
|
||||
rich: `本轮用户输入信息密度高。
|
||||
请尽量从这一轮里提取多个锚点,不要只更新单一方向。
|
||||
如果一条输入同时影响世界方向、冲突和关系,请在新的完整设定结构中一起体现。`,
|
||||
normal: `本轮用户输入为正常补充。
|
||||
请优先顺着当前方向稳定更新,不要主动扩写太多新设定。`,
|
||||
sparse: `本轮用户输入较少或较虚。
|
||||
请保留上一版中仍然成立的内容,不要为了凑完整度而强行发明过多新设定。
|
||||
replyText 要让用户容易继续往下说。`,
|
||||
correction: `本轮用户在修正或推翻旧设定。
|
||||
请优先吸收修正,不要机械复读旧版本。
|
||||
新的完整设定结构必须以修正后的方向为准。`,
|
||||
delegate: `本轮用户把部分决定权交给你。
|
||||
你可以在 replyText 中给出有限度的建议,但不要突然补满整套设定。
|
||||
新的完整设定结构仍应尽量建立在已有世界方向上,而不是完全重做。`,
|
||||
};
|
||||
|
||||
const QUICK_FILL_EXTRA_RULES = `用户刚刚主动要求你自动补全剩余设定。
|
||||
|
||||
这表示用户接受你基于当前方向自动补完剩余设定。
|
||||
|
||||
本轮要求:
|
||||
1. 不要再继续提问
|
||||
2. 直接输出一版尽量完整的设定结构
|
||||
3. progressPercent 直接输出为 100
|
||||
4. replyText 要告诉用户现在可以进入“生成游戏设定草稿”`;
|
||||
|
||||
const STATE_INFERENCE_SYSTEM_PROMPT = `你是正式生成世界设定前的一步“创作状态识别器”。
|
||||
你的职责不是直接生成新设定,而是先判断:下一轮正式生成应该用什么推进策略,尤其要判断 replyText 应该更偏确认、吸收、收束、纠偏,还是启发式提问。
|
||||
|
||||
你必须综合以下信息判断:
|
||||
1. 当前轮次 currentTurn
|
||||
2. 当前完成度 progressPercent
|
||||
3. 用户是否要求自动补全 quickFillRequested
|
||||
4. 当前完整设定结构
|
||||
5. 最近聊天记录,尤其是最近 1 到 3 轮用户消息
|
||||
|
||||
你需要输出 4 个字段:
|
||||
1. userInputSignal:只能是 rich / normal / sparse / correction / delegate
|
||||
2. driftRisk:只能是 low / medium / high
|
||||
3. conversationMode:只能是 bootstrap / expand / compress / repair_direction / force_complete / closing
|
||||
4. judgementSummary:1 到 2 句中文,概括你为什么这样判断,以及正式生成时最该注意什么
|
||||
|
||||
请按下面的语义判断。
|
||||
|
||||
一、userInputSignal 定义
|
||||
1. rich
|
||||
- 用户这一轮给了多条可直接落地的有效信息
|
||||
- 这些信息可能同时覆盖世界方向、玩家处境、开局事件、冲突、关系、标志元素中的多个
|
||||
- 正式生成时应优先高密度吸收,不要只更新一个点
|
||||
|
||||
2. normal
|
||||
- 用户在顺着当前方向做正常补充
|
||||
- 信息量中等,有明确新增内容,但没有明显推翻旧方向,也没有把决定权交给系统
|
||||
- 正式生成时应稳定推进并自然接住用户内容
|
||||
|
||||
3. sparse
|
||||
- 用户输入很短、很虚、很笼统,或几乎没有新增有效事实
|
||||
- 例如只有一个题材词、一个气质词、一句很概括的话、一个很短的倾向表达
|
||||
- 这种情况下,正式生成阶段的 replyText 应优先采用启发式提问
|
||||
- 启发式提问的要求是:只问一个最容易回答、最能推动落地设计的问题
|
||||
|
||||
4. correction
|
||||
- 用户这轮核心动作是在修正、替换、推翻、重定向旧设定
|
||||
- 即使文字不长,只要主意图是“之前那个不对,现在改成这个”,也应优先判为 correction
|
||||
- correction 的优先级高于 rich 和 normal
|
||||
|
||||
5. delegate
|
||||
- 用户把部分决定权交给系统
|
||||
- 例如“你来定”“你帮我补”“按你觉得合理的来”“先给我一个默认方案”
|
||||
- delegate 关注的是授权关系,不只是信息多寡
|
||||
|
||||
二、driftRisk 定义
|
||||
1. low
|
||||
- 当前轮输入与已有方向基本一致
|
||||
- 没有明显改口或冲突
|
||||
|
||||
2. medium
|
||||
- 当前轮带来一定方向变化或扩张
|
||||
- 还没有明显推翻旧方向,但如果处理不好,容易让设定开始发散
|
||||
|
||||
3. high
|
||||
- 用户明确纠偏、改口、替换方向,或最近多轮反复修正
|
||||
- 这时最重要的是防止旧方向重新回流到正式生成结果里
|
||||
|
||||
三、conversationMode 选择原则
|
||||
1. bootstrap
|
||||
- 适用于前期、信息少、核心方向未稳定
|
||||
- replyText 更适合低压力确认和单点启发
|
||||
|
||||
2. expand
|
||||
- 适用于方向已成形,正在顺着现有路线继续补充
|
||||
- replyText 更适合总结已接住的内容并往前推一步
|
||||
|
||||
3. compress
|
||||
- 适用于中后段,已有骨架,需要开始收束
|
||||
- replyText 更适合聚焦最关键缺口,而不是继续开支线
|
||||
|
||||
4. repair_direction
|
||||
- 适用于用户正在纠偏
|
||||
- replyText 更适合先承认修正,再沿修正后的方向继续推进
|
||||
|
||||
5. force_complete
|
||||
- 适用于用户明确要求自动补全
|
||||
- replyText 不再提问,而应给出完成感和下一步引导
|
||||
|
||||
6. closing
|
||||
- 适用于接近完成但并非强制一键补全
|
||||
- replyText 更像确认与收束,而不是前期式探索
|
||||
|
||||
四、优先级规则
|
||||
1. 如果 quickFillRequested 为 true,conversationMode 必须优先判为 force_complete
|
||||
2. 如果用户核心意图是修正旧方向,userInputSignal 优先判为 correction,conversationMode 通常优先考虑 repair_direction
|
||||
3. 如果用户核心意图是授权系统替他补完,userInputSignal 优先判为 delegate
|
||||
4. 只有在没有明显纠偏、也没有明确自动补全要求时,才主要依据 currentTurn、progressPercent 和信息密度,在 bootstrap / expand / compress / closing 之间选择
|
||||
|
||||
五、关于 replyText 风格的专门判断要求
|
||||
1. 如果用户输入较少、较虚或不够落地,正式生成阶段的 replyText 应采用启发式提问
|
||||
2. 启发式提问一次最多只能提 1 个问题,不能连问两个或更多
|
||||
3. 启发式提问必须问“最能推动当前设计落地”的那个问题,而不是泛泛而谈
|
||||
4. 如果用户输入已经足够 rich,就不要再机械提问,优先吸收和推进
|
||||
5. 如果用户在 correction 或 delegate 状态下,replyText 是否提问要服从更高目标:纠偏生效或代为补全,不要机械套 sparse 的问法
|
||||
|
||||
六、关于 replyText 用语的硬约束
|
||||
1. replyText 禁止提及内部结构名、锚点名、字段名、schema 名、框架词
|
||||
2. 禁止出现这类内部表达:世界承诺、玩家幻想、主题边界、玩家入口、核心冲突、关键关系、隐藏线、标志元素、字段、结构、模块、八锚点
|
||||
3. replyText 只能用通俗、直接、面向创作沟通的语言回应用户
|
||||
4. replyText 应该围绕用户正在讨论的具体内容来落地,比如身份、开场处境、冲突、人物关系、地点、规则、气质,而不是抽象谈结构
|
||||
5. judgementSummary 可以简洁提到“这轮更适合启发式提问”或“这轮应优先吸收修正”,但也不要堆内部术语
|
||||
|
||||
七、关于 judgementSummary 的写法
|
||||
1. 必须简洁,不要写成长篇分析
|
||||
2. 必须直接服务于下一轮正式生成
|
||||
3. 最好同时包含两层信息:
|
||||
- 为什么这么判断
|
||||
- 正式生成时最该优先做什么,或最该避免什么
|
||||
|
||||
八、硬性约束
|
||||
1. 只能输出 JSON,不能输出解释、代码块或额外说明
|
||||
2. 不能发明上下文里不存在的设定事实
|
||||
3. 你的任务是“判断生成策略”,不是“代替正式生成直接写新设定”
|
||||
4. 即使信息不完全,也必须在给定枚举里选出最合理的一组状态
|
||||
5. judgementSummary 必须是中文
|
||||
6. 输出值必须严格落在给定枚举中`;
|
||||
|
||||
const STATE_INFERENCE_OUTPUT_CONTRACT = `请严格按以下 JSON 结构输出,不要输出其他文字:
|
||||
{
|
||||
"userInputSignal": "normal",
|
||||
"driftRisk": "low",
|
||||
"conversationMode": "expand",
|
||||
"judgementSummary": ""
|
||||
}`;
|
||||
|
||||
const OUTPUT_CONTRACT_REMINDER = `请严格按以下 JSON 结构输出,不要输出其他文字:
|
||||
{
|
||||
"replyText": "",
|
||||
"progressPercent": 0,
|
||||
"nextAnchorContent": {
|
||||
"worldPromise": {
|
||||
"hook": "",
|
||||
"differentiator": "",
|
||||
"desiredExperience": ""
|
||||
},
|
||||
"playerFantasy": {
|
||||
"playerRole": "",
|
||||
"corePursuit": "",
|
||||
"fearOfLoss": ""
|
||||
},
|
||||
"themeBoundary": {
|
||||
"toneKeywords": [],
|
||||
"aestheticDirectives": [],
|
||||
"forbiddenDirectives": []
|
||||
},
|
||||
"playerEntryPoint": {
|
||||
"openingIdentity": "",
|
||||
"openingProblem": "",
|
||||
"entryMotivation": ""
|
||||
},
|
||||
"coreConflict": {
|
||||
"surfaceConflicts": [],
|
||||
"hiddenCrisis": "",
|
||||
"firstTouchedConflict": ""
|
||||
},
|
||||
"keyRelationships": [
|
||||
{
|
||||
"pairs": "",
|
||||
"relationshipType": "",
|
||||
"secretOrCost": ""
|
||||
}
|
||||
],
|
||||
"hiddenLines": {
|
||||
"hiddenTruths": [],
|
||||
"misdirectionHints": [],
|
||||
"revealPacing": ""
|
||||
},
|
||||
"iconicElements": {
|
||||
"iconicMotifs": [],
|
||||
"institutionsOrArtifacts": [],
|
||||
"hardRules": []
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
||||
function toJson(value: unknown) {
|
||||
return JSON.stringify(value, null, 2);
|
||||
}
|
||||
|
||||
function toText(value: unknown) {
|
||||
return typeof value === 'string' ? value.trim() : '';
|
||||
}
|
||||
|
||||
function getLatestUserText(
|
||||
chatHistory: Array<{ role: 'user' | 'assistant'; content: string }>,
|
||||
) {
|
||||
return (
|
||||
[...chatHistory]
|
||||
.reverse()
|
||||
.find((entry) => entry.role === 'user' && entry.content.trim())?.content ??
|
||||
''
|
||||
);
|
||||
}
|
||||
|
||||
function includesAny(text: string, patterns: RegExp[]) {
|
||||
return patterns.some((pattern) => pattern.test(text));
|
||||
}
|
||||
|
||||
function isPromptUserInputSignal(
|
||||
value: unknown,
|
||||
): value is PromptUserInputSignal {
|
||||
return (
|
||||
value === 'rich' ||
|
||||
value === 'normal' ||
|
||||
value === 'sparse' ||
|
||||
value === 'correction' ||
|
||||
value === 'delegate'
|
||||
);
|
||||
}
|
||||
|
||||
function isPromptDriftRisk(value: unknown): value is PromptDriftRisk {
|
||||
return value === 'low' || value === 'medium' || value === 'high';
|
||||
}
|
||||
|
||||
function isPromptConversationMode(
|
||||
value: unknown,
|
||||
): value is PromptConversationMode {
|
||||
return (
|
||||
value === 'bootstrap' ||
|
||||
value === 'expand' ||
|
||||
value === 'compress' ||
|
||||
value === 'repair_direction' ||
|
||||
value === 'force_complete' ||
|
||||
value === 'closing'
|
||||
);
|
||||
}
|
||||
|
||||
export function detectUserInputSignal(
|
||||
chatHistory: Array<{ role: 'user' | 'assistant'; content: string }>,
|
||||
): PromptUserInputSignal {
|
||||
const latestUserText = getLatestUserText(chatHistory).trim();
|
||||
|
||||
if (!latestUserText) {
|
||||
return 'sparse';
|
||||
}
|
||||
|
||||
if (includesAny(latestUserText, [/(不是|改成|改为|换成|重来|推翻|修正)/u])) {
|
||||
return 'correction';
|
||||
}
|
||||
|
||||
if (includesAny(latestUserText, [/(你帮我想|你来定|你决定|你补完)/u])) {
|
||||
return 'delegate';
|
||||
}
|
||||
|
||||
const segments = latestUserText
|
||||
.split(/[。!?;\n]/u)
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
if (latestUserText.length <= 10 || segments.length <= 1) {
|
||||
return 'sparse';
|
||||
}
|
||||
|
||||
if (segments.length >= 3 || latestUserText.length >= 60) {
|
||||
return 'rich';
|
||||
}
|
||||
|
||||
return 'normal';
|
||||
}
|
||||
|
||||
function summarizeDynamicState(
|
||||
state: Pick<
|
||||
PromptDynamicState,
|
||||
'userInputSignal' | 'driftRisk' | 'conversationMode'
|
||||
>,
|
||||
) {
|
||||
return `输入信号=${state.userInputSignal},漂移风险=${state.driftRisk},本轮模式=${state.conversationMode}。正式生成时按这组状态执行。`;
|
||||
}
|
||||
|
||||
function isThemeBoundaryFilled(value: ThemeBoundaryValue | null) {
|
||||
return Boolean(
|
||||
value &&
|
||||
(value.toneKeywords.length > 0 ||
|
||||
value.aestheticDirectives.length > 0 ||
|
||||
value.forbiddenDirectives.length > 0),
|
||||
);
|
||||
}
|
||||
|
||||
function isRelationshipsFilled(value: KeyRelationshipValue[]) {
|
||||
return value.length > 0;
|
||||
}
|
||||
|
||||
function isHiddenLinesFilled(value: HiddenLineValue | null) {
|
||||
return Boolean(
|
||||
value &&
|
||||
(value.hiddenTruths.length > 0 ||
|
||||
value.misdirectionHints.length > 0 ||
|
||||
value.revealPacing),
|
||||
);
|
||||
}
|
||||
|
||||
function isIconicElementsFilled(value: IconicElementValue | null) {
|
||||
return Boolean(
|
||||
value &&
|
||||
(value.iconicMotifs.length > 0 ||
|
||||
value.institutionsOrArtifacts.length > 0 ||
|
||||
value.hardRules.length > 0),
|
||||
);
|
||||
}
|
||||
|
||||
export function detectDriftRisk(params: {
|
||||
chatHistory: Array<{ role: 'user' | 'assistant'; content: string }>;
|
||||
anchorContent: EightAnchorContent;
|
||||
progressPercent: number;
|
||||
}) {
|
||||
const latestUserText = getLatestUserText(params.chatHistory).trim();
|
||||
const recentUserMessages = params.chatHistory
|
||||
.filter((entry) => entry.role === 'user')
|
||||
.slice(-3)
|
||||
.map((entry) => entry.content.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
const correctionCount = recentUserMessages.filter((entry) =>
|
||||
/(不是|改成|改为|换成|推翻|重来|修正)/u.test(entry),
|
||||
).length;
|
||||
|
||||
if (
|
||||
correctionCount >= 2 ||
|
||||
(params.progressPercent >= 65 &&
|
||||
/(不是|改成|改为|换成|重来|推翻)/u.test(latestUserText))
|
||||
) {
|
||||
return 'high' as const;
|
||||
}
|
||||
|
||||
const normalizedContent = normalizeEightAnchorContent(params.anchorContent);
|
||||
const filledCount = [
|
||||
Boolean(normalizedContent.worldPromise),
|
||||
Boolean(normalizedContent.playerFantasy),
|
||||
isThemeBoundaryFilled(normalizedContent.themeBoundary),
|
||||
Boolean(normalizedContent.playerEntryPoint),
|
||||
Boolean(normalizedContent.coreConflict),
|
||||
isRelationshipsFilled(normalizedContent.keyRelationships),
|
||||
isHiddenLinesFilled(normalizedContent.hiddenLines),
|
||||
isIconicElementsFilled(normalizedContent.iconicElements),
|
||||
].filter(Boolean).length;
|
||||
|
||||
if (filledCount >= 3 && latestUserText.length >= 40) {
|
||||
return 'medium' as const;
|
||||
}
|
||||
|
||||
return 'low' as const;
|
||||
}
|
||||
|
||||
export function pickConversationMode(params: {
|
||||
currentTurn: number;
|
||||
progressPercent: number;
|
||||
userInputSignal: PromptUserInputSignal;
|
||||
driftRisk: PromptDriftRisk;
|
||||
quickFillRequested: boolean;
|
||||
}) {
|
||||
if (params.quickFillRequested) {
|
||||
return 'force_complete' as const;
|
||||
}
|
||||
|
||||
if (
|
||||
params.userInputSignal === 'correction' ||
|
||||
params.driftRisk === 'high'
|
||||
) {
|
||||
return 'repair_direction' as const;
|
||||
}
|
||||
|
||||
if (params.progressPercent >= 85 || params.currentTurn >= 15) {
|
||||
return 'closing' as const;
|
||||
}
|
||||
|
||||
if (params.currentTurn > 10 || params.progressPercent >= 65) {
|
||||
return 'compress' as const;
|
||||
}
|
||||
|
||||
if (params.currentTurn <= 10 && params.progressPercent < 65) {
|
||||
return 'expand' as const;
|
||||
}
|
||||
|
||||
return 'bootstrap' as const;
|
||||
}
|
||||
|
||||
function buildRuleBasedPromptDynamicState(input: {
|
||||
currentTurn: number;
|
||||
progressPercent: number;
|
||||
quickFillRequested: boolean;
|
||||
currentAnchorContent: EightAnchorContent;
|
||||
chatHistory: Array<{ role: 'user' | 'assistant'; content: string }>;
|
||||
}): PromptDynamicState {
|
||||
const userInputSignal = detectUserInputSignal(input.chatHistory);
|
||||
const driftRisk = detectDriftRisk({
|
||||
chatHistory: input.chatHistory,
|
||||
anchorContent: input.currentAnchorContent,
|
||||
progressPercent: input.progressPercent,
|
||||
});
|
||||
|
||||
const conversationMode = pickConversationMode({
|
||||
currentTurn: input.currentTurn,
|
||||
progressPercent: input.progressPercent,
|
||||
userInputSignal,
|
||||
driftRisk,
|
||||
quickFillRequested: input.quickFillRequested,
|
||||
});
|
||||
|
||||
return {
|
||||
currentTurn: input.currentTurn,
|
||||
progressPercent: input.progressPercent,
|
||||
userInputSignal,
|
||||
driftRisk,
|
||||
quickFillRequested: input.quickFillRequested,
|
||||
conversationMode,
|
||||
judgementSummary: summarizeDynamicState({
|
||||
userInputSignal,
|
||||
driftRisk,
|
||||
conversationMode,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildPromptDynamicState(input: {
|
||||
currentTurn: number;
|
||||
progressPercent: number;
|
||||
quickFillRequested: boolean;
|
||||
currentAnchorContent: EightAnchorContent;
|
||||
chatHistory: Array<{ role: 'user' | 'assistant'; content: string }>;
|
||||
}, inference?: PromptDynamicStateInference | null): PromptDynamicState {
|
||||
const fallbackState = buildRuleBasedPromptDynamicState(input);
|
||||
|
||||
if (!inference) {
|
||||
return fallbackState;
|
||||
}
|
||||
|
||||
const userInputSignal = isPromptUserInputSignal(inference.userInputSignal)
|
||||
? inference.userInputSignal
|
||||
: fallbackState.userInputSignal;
|
||||
const driftRisk = isPromptDriftRisk(inference.driftRisk)
|
||||
? inference.driftRisk
|
||||
: fallbackState.driftRisk;
|
||||
const conversationMode = isPromptConversationMode(inference.conversationMode)
|
||||
? inference.conversationMode
|
||||
: fallbackState.conversationMode;
|
||||
const judgementSummary =
|
||||
toText(inference.judgementSummary) ||
|
||||
summarizeDynamicState({
|
||||
userInputSignal,
|
||||
driftRisk,
|
||||
conversationMode,
|
||||
});
|
||||
|
||||
return {
|
||||
currentTurn: input.currentTurn,
|
||||
progressPercent: input.progressPercent,
|
||||
userInputSignal,
|
||||
driftRisk,
|
||||
quickFillRequested: input.quickFillRequested,
|
||||
conversationMode,
|
||||
judgementSummary,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildPromptDynamicStateInferencePrompt(input: {
|
||||
currentTurn: number;
|
||||
progressPercent: number;
|
||||
quickFillRequested: boolean;
|
||||
currentAnchorContent: EightAnchorContent;
|
||||
chatHistory: Array<{ role: 'user' | 'assistant'; content: string }>;
|
||||
}) {
|
||||
const currentAnchorContent =
|
||||
normalizeEightAnchorContent(input.currentAnchorContent) ??
|
||||
createEmptyEightAnchorContent();
|
||||
|
||||
return {
|
||||
systemPrompt: [
|
||||
STATE_INFERENCE_SYSTEM_PROMPT,
|
||||
STATE_INFERENCE_OUTPUT_CONTRACT,
|
||||
].join('\n\n'),
|
||||
userPrompt: [
|
||||
`当前轮次:${input.currentTurn}`,
|
||||
`当前完成度:${input.progressPercent}`,
|
||||
`是否要求自动补全:${input.quickFillRequested ? '是' : '否'}`,
|
||||
renderCurrentAnchorContext(currentAnchorContent),
|
||||
renderChatHistoryContext(input.chatHistory),
|
||||
].join('\n\n'),
|
||||
};
|
||||
}
|
||||
|
||||
function renderDynamicStateContext(dynamicState: PromptDynamicState) {
|
||||
return `上一轮预判得到的创作状态如下。
|
||||
正式生成时必须把它作为本轮策略输入直接执行,不要重新另起一套判断。
|
||||
|
||||
创作状态:
|
||||
- userInputSignal: ${dynamicState.userInputSignal}
|
||||
- driftRisk: ${dynamicState.driftRisk}
|
||||
- conversationMode: ${dynamicState.conversationMode}
|
||||
- judgementSummary: ${dynamicState.judgementSummary}`;
|
||||
}
|
||||
|
||||
function renderCurrentAnchorContext(anchorContent: EightAnchorContent) {
|
||||
return `当前完整设定结构如下。
|
||||
你必须把它视为上一版有效世界底子。
|
||||
|
||||
如果用户没有否定其中某部分内容,且该部分仍然成立,可以继续保留。
|
||||
如果用户明确修正了某部分内容,新的完整设定结构必须体现修正后的版本。
|
||||
|
||||
当前完整设定结构:
|
||||
${toJson(normalizeEightAnchorContent(anchorContent))}`;
|
||||
}
|
||||
|
||||
function renderChatHistoryContext(
|
||||
chatHistory: Array<{ role: 'user' | 'assistant'; content: string }>,
|
||||
) {
|
||||
return `以下是用户聊天记录。
|
||||
请重点理解最近几轮里用户新增、修正、强调的设定信息。
|
||||
不要把早期已经被用户否定的内容继续当成最终结论。
|
||||
|
||||
用户聊天记录:
|
||||
${toJson(chatHistory)}`;
|
||||
}
|
||||
|
||||
export function buildEightAnchorSingleTurnPrompt(input: {
|
||||
currentTurn: number;
|
||||
progressPercent: number;
|
||||
quickFillRequested: boolean;
|
||||
currentAnchorContent: EightAnchorContent;
|
||||
chatHistory: Array<{ role: 'user' | 'assistant'; content: string }>;
|
||||
dynamicState?: PromptDynamicStateInference | PromptDynamicState | null;
|
||||
}) {
|
||||
const currentAnchorContent =
|
||||
normalizeEightAnchorContent(input.currentAnchorContent) ??
|
||||
createEmptyEightAnchorContent();
|
||||
const dynamicState = buildPromptDynamicState({
|
||||
...input,
|
||||
currentAnchorContent,
|
||||
}, input.dynamicState);
|
||||
|
||||
return {
|
||||
prompt: [
|
||||
BASE_SYSTEM_PROMPT,
|
||||
GLOBAL_HARD_RULES,
|
||||
MODE_RULES[dynamicState.conversationMode],
|
||||
USER_SIGNAL_RULES[dynamicState.userInputSignal],
|
||||
dynamicState.quickFillRequested ? QUICK_FILL_EXTRA_RULES : null,
|
||||
renderDynamicStateContext(dynamicState),
|
||||
renderCurrentAnchorContext(currentAnchorContent),
|
||||
renderChatHistoryContext(input.chatHistory),
|
||||
OUTPUT_CONTRACT_REMINDER,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join('\n\n'),
|
||||
dynamicState,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user