fix(ai): 新建模式下规划数据不再携带旧时间轴

实测 V2 规划失败:fresh 模式提示词要求先 remove 重建,但数据里
仍带着旧时间轴(含重复片段),模型把注意力放在旧片段的
「重复与逻辑混乱」上,最终返回空方案。
新建模式下 clips 置空、timelineDuration 归零,模型只看到素材与
新要求;应用侧仍会自动补上 remove 全部旧片段的操作。
新增测试:fresh 数据无旧片段、modify 数据保留旧片段。
This commit is contained in:
xhgit committed 2026-11-14 18:01:52 +08:00
1 parent 2aa0e50f73
commit 90502dc27e
2 files changed
+10 -4

No files matched your search

+4 -4
View File
@@ -88,7 +88,7 @@ const PLACEHOLDER=/尚未|等待|采样窗口|时间采样|语义或动作/;
const TITLE_CARD=/标题画面|演职员|职员表|片头|片尾|字幕卡|制作人员/;
const SEG_CAP=60,PER_MEDIA_CAP=8,DESC_MAX=90;
const round2=n=>Math.round(n*100)/100;
function buildProjectData(p,budget){
function buildProjectData(p,budget,fresh){
const media=p.media.map(m=>{
const seen=new Set();
const all=(m.analysis?.segments||[]).filter(s=>s&&Number.isFinite(s.score)&&s.score!==null&&typeof s.description==='string'&&s.description&&!PLACEHOLDER.test(s.description)&&!TITLE_CARD.test(s.description)&&!seen.has(s.description)&&(seen.add(s.description),true))
@@ -99,10 +99,10 @@ function buildProjectData(p,budget){
media.sort((a,b)=>(b.segments[0]?.score??-1)-(a.segments[0]?.score??-1));
const kept=new Map();let cap=SEG_CAP;
for(const m of media){const out=[];for(const s of m.segments){const n=kept.get(m.id)||0;if(n>=PER_MEDIA_CAP||!cap)break;kept.set(m.id,n+1);cap--;out.push(s);}m.segments=out;}
const clips=p.clips.map(c=>({id:c.id,...(c.mediaId?{mediaId:c.mediaId}:{}),track:c.track,start:round2(c.start),in:round2(c.in),out:round2(c.out),speed:c.speed??1,volume:c.volume??1,
const clips=fresh?[]:p.clips.map(c=>({id:c.id,...(c.mediaId?{mediaId:c.mediaId}:{}),track:c.track,start:round2(c.start),in:round2(c.in),out:round2(c.out),speed:c.speed??1,volume:c.volume??1,
...(c.fade!==undefined?{fade:c.fade}:{}),...(c.text?{text:c.text.slice(0,200)}:{}),...(c.color?{color:c.color}:{}),...(c.fontSize?{fontSize:c.fontSize}:{}),
...(c.brightness!==undefined?{brightness:c.brightness}:{}),...(c.contrast!==undefined?{contrast:c.contrast}:{}),...(c.saturation!==undefined?{saturation:c.saturation}:{}),...(c.fit?{fit:c.fit}:{})}));
const data={settings:p.settings,timelineDuration:round2(Math.max(0,...p.clips.map(c=>c.start+(c.out-c.in)/(c.speed||1)))),media,clips};
const data={settings:p.settings,timelineDuration:fresh?0:round2(Math.max(0,...p.clips.map(c=>c.start+(c.out-c.in)/(c.speed||1)))),media,clips};
const steps=[
d=>{for(const m of d.media)m.segments=m.segments.slice(0,6);},
d=>{for(const m of d.media)for(const s of m.segments)s.description=s.description.slice(0,60);},
@@ -138,7 +138,7 @@ function buildHistoryBlock(history,budget){
}
export function plannerPrompt(p,instruction,{fresh=false,target=0,style=null,budget=9000,history=[]}={}){
const historyBlock=buildHistoryBlock(history,Math.max(400,Math.round(budget*.35)));
const data=buildProjectData(p,Math.max(1200,budget-historyBlock.length));
const data=buildProjectData(p,Math.max(1200,budget-historyBlock.length),fresh);
const hasSegments=data.media.some(m=>m.segments.length);
const mode=fresh?'用户要求创作新的时间轴:先 remove 现有全部片段,再按新要求重新 add;内容全部重新编排,不要保留旧镜头。':'时间轴需要保留:只修改用户明确提到的片段与字段,其余片段保持原样;不要删除未提及的片段,不要重建整个时间轴。';
const styleBlock=style?`风格参数(仅用于新添加的片段,不要改动现有片段):${JSON.stringify(style)}`:'';