fix(ai): 规划请求带上聊天历史;素材未分析时明确拦截;模型不存在提示修复办法

- 规划提示词携带最近 6 轮对话记录:解决用户说「把刚才这个删掉/重新剪」时
  模型看不到上下文、反复返回「未收到具体要求」空方案的问题
- 明确规则:有对话记录时不得以未收到要求为由返回空方案;指代必须结合记录理解
- 素材全部未分析时返回空方案并在摘要提示先执行「AI 分析」,
  禁止凭空假设内容或把整段素材放上时间轴
- 扩充新建意图识别:重新/重做/重剪/全部删掉/清空时间轴 均触发先清空再重建
- 模型不存在(404 not found)等常见错误附带下载/检查提示
- 新增 2 个测试:对话历史注入、未分析素材拦截、模型不存在提示
This commit is contained in:
xhgit committed 2026-11-14 12:22:17 +08:00
1 parent b2c40b7df5
commit 6221828da2
3 files changed
+29 -5

No files matched your search

+3 -2
View File
@@ -71,14 +71,15 @@ async function init(){
signal.throwIfAborted();sameProject(pid);m.analysis=analysis;m.tags=[...new Set([...(m.tags||[]),...analysis.segments.flatMap(s=>s.tags||[])])];changed();progress((i+1)/selected.length,`已分析 ${i+1}/${selected.length}`);}return {count:selected.length};});});
handle('plan',(instruction,options={})=>{const snapshot=structuredClone(project),c=forTask('text');if(!c.model)throw Error('请先在模型管理中为剪辑规划选择模型');return task('AI 规划时间轴',async(signal,progress)=>{progress(.1,'读取项目和片段分析,调用规划模型');
const hasVideo=snapshot.clips.some(x=>x.track==='video');
const createIntent=/(制作|创建|新建|生成|剪一?个|做一?个|重新[剪做]|从头).{0,12}(视频|短片|vlog|混剪|宣传片|片子|作品|成片)/i.test(instruction)||/(^|[^a-z])(make|create|build)[^a-z].{0,15}video/i.test(instruction);
const createIntent=/(制作|创建|新建|生成|剪一?个|做一?个|重新[剪做]|从头).{0,12}(视频|短片|vlog|混剪|宣传片|片子|作品|成片)/i.test(instruction)||/(重新|重做|重剪|重来|全[部都]?删|清空.{0,4}(时间轴|时间线|片段)|删掉.{0,4}重[新做剪])/.test(instruction)||/(^|[^a-z])(make|create|build)[^a-z].{0,15}video/i.test(instruction);
const fresh=!hasVideo||createIntent;
const style=styleModule.getStyle(options.style),target=Number(options.target);
const budget=providers.isLocal(c.baseUrl)?3800:9000;
const history=project.messages.filter(m=>(m.role==='user'||m.role==='assistant')&&!m.error).slice(-6);
let r,ops,lastError='';
for(let attempt=0;attempt<3;attempt++){
try{
const prompt=providers.plannerPrompt(snapshot,String(instruction).slice(0,3000),{fresh,target,style,budget})+(lastError?'\n上一次方案被校验拒绝:'+lastError+'。请只修正被拒绝的部分,重新返回完整 JSON。':'');
const prompt=providers.plannerPrompt(snapshot,String(instruction).slice(0,3000),{fresh,target,style,budget,history})+(lastError?'\n上一次方案被校验拒绝:'+lastError+'。请只修正被拒绝的部分,重新返回完整 JSON。':'');
r=await providers.complete(c,prompt,[],signal);
if(!Array.isArray(r.data.operations))throw Error('模型返回缺少 operations 数组');
ops=r.data.operations.filter(op=>op&&typeof op==='object'&&['add','update','remove'].includes(op.type));