aitu-app 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/assets/{CanvasAudioPlayer-cp00LGgR.js → CanvasAudioPlayer-C_USx5uz.js} +1 -1
- package/assets/{ComicCreator-CAmJF3JX.js → ComicCreator-qGQaXp7h.js} +2 -2
- package/assets/DeferredAIInputBar-CPykEFYX.css +1 -0
- package/assets/DeferredAIInputBar-LmZGQCLT.js +107 -0
- package/assets/{DrawnixDeferredFeatures-DIznfzB7.js → DrawnixDeferredFeatures-Hy_-quZ1.js} +1 -1
- package/assets/{KnowledgeBaseContent-CxilHI-j.js → KnowledgeBaseContent-DSKNA70H.js} +8 -8
- package/assets/{MVCreator-ZrinzYPm.js → MVCreator-C3iClDLU.js} +12 -10
- package/assets/{ModelBenchmarkWorkbench-DbesnX6E.js → ModelBenchmarkWorkbench-BxwdcZ0q.js} +2 -2
- package/assets/{MusicAnalyzer-BzXD1qYH.js → MusicAnalyzer-f_T6_YPJ.js} +2 -2
- package/assets/{ParametersDropdown-DBQCDv3g.js → ParametersDropdown-CTSN3ClD.js} +1 -1
- package/assets/{PromptHistoryTool-CUCIE0Ld.js → PromptHistoryTool-DV-8RSdz.js} +2 -2
- package/assets/{ResizableDivider-CdfJF8GW.js → ResizableDivider-CUQBmPpx.js} +1 -1
- package/assets/TaskQueuePanel-CtjY1W4t.js +1 -0
- package/assets/{VideoAnalyzer-wtxorxD3.js → VideoAnalyzer-BBVBSONO.js} +3 -3
- package/assets/{VideoAnalyzer-C90c84gt.js → VideoAnalyzer-BmAjGvN8.js} +1 -1
- package/assets/{ai-chat-B5qFht2H.js → ai-chat-BO5vbKZW.js} +5 -5
- package/assets/{ai-generation-preferences-service-CvWbMxv3.js → ai-generation-preferences-service-ZmPTR-wz.js} +1 -1
- package/assets/{batch-image-generation-Bo3h_Eop.js → batch-image-generation-BLBSv-t6.js} +6 -6
- package/assets/{diagram-engines-C9ewAq_o.js → diagram-engines-CSzW_-6N.js} +2 -2
- package/assets/{editor-engines-CvxZrFyB.js → editor-engines-C573k8UM.js} +1 -1
- package/assets/{index-Dw6PsLbq.js → index-BT-rxxI3.js} +2 -2
- package/assets/{index-BCqdmg38.js → index-Dw_8lcIi.js} +1 -1
- package/assets/{index-BSlnQdcy.js → index-IHNaVKGH.js} +1 -1
- package/assets/{index-CjBeKr1R.js → index-N8asYyaz.js} +1 -1
- package/assets/{index-CylhK_f5.js → index-jxwTv7c1.js} +1 -1
- package/assets/{index.es-BKVY-J2g.js → index.es-BLXvmueB.js} +1 -1
- package/assets/{jspdf.es.min-BM9ML7Zw.js → jspdf.es.min-DxWvbkh4.js} +2 -2
- package/assets/{markdown-to-drawnix-COS1iVyq.js → markdown-to-drawnix-BVFYnimo.js} +2 -2
- package/assets/{mermaid-to-drawnix-oplawQO0.js → mermaid-to-drawnix-nGs2aeZ7.js} +2 -2
- package/assets/{model-benchmark-launcher-DD4vN0Ca.js → model-benchmark-launcher-DAWoSySc.js} +1 -1
- package/assets/{photo-wall-splitter-CbKqFOIV.js → photo-wall-splitter-CCUURzGk.js} +1 -1
- package/assets/{prompt-utils-7t-jk6n6.js → prompt-utils-MF_LILNU.js} +1 -1
- package/assets/{settings-dialog-D2yEWl8J.js → settings-dialog-Ac7R-_CG.js} +1 -1
- package/assets/{skill-dsl-parser-C-utRXFg.js → skill-dsl-parser-Do9iAYbB.js} +1 -1
- package/assets/{startup-app-DxX-P1pm.js → startup-app-eD_rQhSh.js} +531 -527
- package/assets/{task-sync-Dr7Nza2v.js → task-sync-BJVOunRa.js} +1 -1
- package/assets/{tool-windows-BIjc1zsU.js → tool-windows-CmgL3thd.js} +17 -17
- package/assets/ttd-dialog-B12v0SVY.js +6 -0
- package/assets/{ttd-dialog-submit-shortcut-yUk15rsg.js → ttd-dialog-submit-shortcut-C2lJygXA.js} +1 -1
- package/assets/useCharacters-BAKE4TeJ.js +2 -0
- package/assets/{useMediaViewer-CEvHYype.js → useMediaViewer-BGw5RkSR.js} +1 -1
- package/assets/{useWorkflowSubmission-Cxhdsl2b.js → useWorkflowSubmission-iAPmKke9.js} +6 -6
- package/assets/{video-recovery-service-CB8hyRf5.js → video-recovery-service-CW7bErP2.js} +1 -1
- package/assets/{workflow-generation-utils-JoRODaP7.js → workflow-generation-utils-DhIVnOHO.js} +2 -2
- package/assets/workflow-submission-service-Ce0cpj8E.js +4 -0
- package/changelog.json +18 -13
- package/idle-prefetch-manifest.json +306 -306
- package/manifest.json +3 -3
- package/package.json +1 -1
- package/precache-manifest.json +6 -6
- package/sw.js +1 -1
- package/version.json +6 -3
- package/assets/DeferredAIInputBar-CzMATNng.js +0 -107
- package/assets/DeferredAIInputBar-D_e6qG1y.css +0 -1
- package/assets/TaskQueuePanel-oLG4DAzJ.js +0 -1
- package/assets/ttd-dialog-CNSSc4wk.js +0 -6
- package/assets/useCharacters-DzXMuknh.js +0 -2
- package/assets/workflow-submission-service-BIGFW4s4.js +0 -4
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{_ as gt}from"./startup-runtime-DTmhLESk.js";import{ee as kt,
|
|
2
|
-
`)):""}function Ze(o){return o?"是":"否"}function _e(o){let i=0,r=0;return o.forEach(c=>{typeof c=="number"&&Number.isFinite(c)&&(i+=c,r+=1)}),r>0?Number((i/r).toFixed(2)):null}function Xt(o=new Date){const i=`${o.getFullYear()}${String(o.getMonth()+1).padStart(2,"0")}${String(o.getDate()).padStart(2,"0")}`,r=`${String(o.getHours()).padStart(2,"0")}${String(o.getMinutes()).padStart(2,"0")}${String(o.getSeconds()).padStart(2,"0")}`;return`model-benchmark-history_${i}_${r}.xlsx`}function Le(o){return o!==null}function Qt(o){return o.trim().toLowerCase().split(/\s+/).filter(Boolean)}function xe(o,i){const r=Qt(o);if(r.length===0)return!0;const c=i.filter(Boolean).join(" ").toLowerCase();return r.every(p=>c.includes(p))}function Ut(o){return o==="text"?"supportsText":o==="image"?"supportsImage":o==="video"?"supportsVideo":"supportsAudio"}function et(o,i){const r=Ut(i);return o.filter(c=>c.enabled&&(c.id===yt||c.capabilities[r]))}function Wt(){const[o,i]=l.useState(0);return l.useEffect(()=>Pe.subscribe(()=>{i(r=>r+1)}),[]),o}function Yt(){const[o,i]=l.useState(()=>ye.get());return l.useEffect(()=>{const r=c=>{i(c)};return ye.addListener(r),()=>{ye.removeListener(r)}},[]),o}function ve(o){return!o||o<0?"--":o<1e3?`${o}ms`:`${(o/1e3).toFixed(o>=1e4?1:2)}s`}function Ht(o){const i=new Map;o.entries.forEach(c=>{var ce,m;const p=(ce=c.modelId)==null?void 0:ce.trim(),h=(m=c.modelLabel)==null?void 0:m.trim();p&&h&&!i.has(p)&&i.set(p,{modelId:p,modelLabel:h})});const r=new Map;return i.forEach(({modelLabel:c})=>{r.set(c,(r.get(c)||0)+1)}),Array.from(i.values()).map(({modelId:c,modelLabel:p})=>(r.get(p)||0)>1?`${p} · ${c}`:p)}function tt(o){return o?o.entries.reduce((i,r)=>(i.total+=1,r.status==="completed"&&(i.completed+=1),r.status==="failed"&&(i.failed+=1),r.status==="running"&&(i.running+=1),i),{total:0,completed:0,failed:0,running:0}):{total:0,completed:0,failed:0,running:0}}function I(o,i){const r=Pe.getState(o).models.filter(p=>p.type===i),c=new Map;return r.forEach(p=>{c.has(p.id)||c.set(p.id,p)}),Array.from(c.values())}function nt(o){return o.shortLabel||o.label||o.id}function st(o){const i=nt(o);return i===o.id?i:`${i} · ${o.id}`}function Jt(o,i){return`${o}::${i}`}function rs({}){const{confirm:o,confirmDialog:i}=kt(),r=wt(Kt),c=Yt(),p=Wt(),[h,ce]=l.useState(()=>C.getState()),[m,De]=l.useState("text"),[u,Te]=l.useState("cross-provider"),[v,de]=l.useState(""),[R,me]=l.useState(""),[F,K]=l.useState([]),[z,Y]=l.useState([]),[q,H]=l.useState([]),[G,Zt]=l.useState(""),[X,es]=l.useState(!1),[rt,$e]=l.useState($("text").id),[ue,ke]=l.useState($("text").prompt),[Ke,lt]=l.useState([]),[Ve,at]=l.useState(2),[we,Oe]=l.useState(!1),[Se,Be]=l.useState(!1),[je,it]=l.useState("speed"),[Ne,ct]=l.useState(""),[pe,dt]=l.useState("all"),Fe=l.useRef(""),L=l.useRef(!1),Ce=l.useRef(!1),he=l.useRef(null);l.useRef({}),l.useEffect(()=>{const e=C.observe().subscribe(s=>{l.startTransition(()=>{ce(s)})});return()=>e.unsubscribe()},[]);const N=l.useMemo(()=>et(c,m),[m,c]),J=l.useMemo(()=>new Map(N.map(e=>[e.id,e])),[N]),y=v&&J.get(v)||null,mt=St.useCallback(async e=>{await o({title:"确认删除会话",description:`确定要删除会话「${e.title||"未命名会话"}」吗?此操作不可撤销。`,confirmText:"删除",cancelText:"取消",danger:!0})&&C.removeSession(e.id)},[o]),P=l.useMemo(()=>v?I(v,m):[],[p,m,v]),Ie=l.useMemo(()=>{const e=new Map;return N.forEach(s=>{I(s.id,m).forEach(d=>{e.has(d.id)||e.set(d.id,d)})}),Array.from(e.values())},[N,p,m]),D=l.useMemo(()=>N.flatMap(e=>I(e.id,m).map(s=>B(e.id,e.name,s))),[N,p,m]);l.useEffect(()=>{if(L.current)return;if(!N.length){de("");return}const e=$(m);$e(e.id),ke(s=>s===$("text").prompt||s===$("image").prompt||s===$("video").prompt||s===$("audio").prompt?e.prompt:s),(!v||!J.has(v))&&de(N[0].id)},[N,m,J,v]),l.useEffect(()=>{if(L.current)return;const e=P.map(s=>s.id);if(e.length===0){K([]);return}K(s=>Me(s,e,{fallback:"all"}))},[P]),l.useEffect(()=>{if(L.current)return;const e=Ie.map(s=>s.id);if(e.length===0){me("");return}e.includes(R)||me(e[0])},[Ie,R]);const V=l.useMemo(()=>R?N.map(e=>{const s=I(e.id,m).find(d=>d.id===R);return s?B(e.id,e.name,s):null}).filter(Le):[],[N,m,R]);l.useEffect(()=>{L.current||Y(e=>Me(e,V.map(s=>s.profileId),{fallback:"all"}))},[V]),l.useEffect(()=>{L.current||H(e=>Me(e,D.map(s=>s.selectionKey),{fallback:"first",limit:Ft}))},[D]);const b=l.useMemo(()=>h.sessions.find(e=>e.id===h.activeSessionId)||null,[h.activeSessionId,h.sessions]),ze=l.useMemo(()=>h.sessions.filter(e=>pe!=="all"&&e.modality!==pe?!1:xe(Ne,[e.title,e.prompt,...(e.knowledgeContextRefs||[]).map(s=>s.title),ae[e.compareMode],le[e.modality],...e.entries.flatMap(s=>[s.profileName,s.profileId,s.modelLabel,s.modelId,s.vendor])])),[pe,Ne,h.sessions]);l.useEffect(()=>{b&&it(b.rankingMode)},[b]);const ut=l.useMemo(()=>tt(b),[b]),pt=l.useMemo(()=>b?jt(b.entries,b.rankingMode):[],[b]),T=l.useMemo(()=>{if(u==="cross-provider")return V.filter(e=>z.includes(e.profileId));if(u==="cross-model"){if(!v)return[];const e=J.get(v);return e?P.filter(s=>F.includes(s.id)).map(s=>B(e.id,e.name,s)):[]}return D.filter(e=>q.includes(e.selectionKey))},[P,u,V,D,J,q,F,v,z]),qe=l.useMemo(()=>{if(!b||b.modality!==m||b.compareMode!==u)return!1;const e=T.map(d=>d.selectionKey);if(e.length===0||b.entries.length!==e.length)return!1;const s=new Set(e);return b.entries.every(d=>s.has(d.selectionKey))},[b,u,m,T]),Ge=l.useMemo(()=>b&&qe?b.entries.map(e=>({key:e.selectionKey,modelLabel:e.modelLabel,profileName:e.profileName,badgeLabel:be[e.status]||be.pending})):T.map(e=>({key:e.selectionKey,modelLabel:e.modelLabel,profileName:e.profileName,badgeLabel:be.pending})),[b,qe,T]),g=b,Z=g?ut:tt(null),Xe=g?pt:[];Ge.length,Ge.slice(0,zt);const M=Xe.find(e=>e.status==="completed")||null,Qe=l.useMemo(()=>P.filter(e=>{const s=F.includes(e.id);return X&&!s?!1:xe(G,[nt(e),e.id,y==null?void 0:y.name])}),[y==null?void 0:y.name,P,G,F,X]),Ue=l.useMemo(()=>V.filter(e=>{const s=z.includes(e.profileId);return X&&!s?!1:xe(G,[e.profileName,e.modelLabel,e.modelId,e.profileId])}),[V,G,z,X]),We=l.useMemo(()=>D.filter(e=>{const s=q.includes(e.selectionKey);return X&&!s?!1:xe(G,[e.profileName,e.modelLabel,e.modelId,e.profileId])}),[D,G,q,X]),fe=l.useMemo(()=>u==="cross-model"?Qe.map(e=>e.id):u==="cross-provider"?Ue.map(e=>e.profileId):We.map(e=>e.selectionKey),[u,Qe,Ue,We]);l.useEffect(()=>{if(fe.length===0){he.current=null;return}he.current&&fe.includes(he.current)||(he.current=fe[0])},[fe]),l.useEffect(()=>{var f;if(!r||!h.ready)return;const e=JSON.stringify(r);if(Fe.current===e)return;const s=r.modality||"text",d=et(c,s),k=r.profileId||"",Q=r.modelId||"",O=k?Pe.getState(k):null,ee=k&&Q?I(k,s):[],te=!Q||ee.some(_=>_.id===Q);if(O&&Q&&!te&&(O.status==="idle"||O.status==="loading"))return;L.current=!0,Fe.current=e;const se=r.compareMode||(r.modelId?"cross-provider":"cross-model");let S=se,U=[];const oe=r.profileId&&r.modelId?Jt(r.profileId,r.modelId):"";se==="cross-provider"&&r.modelId&&(U=d.filter(_=>I(_.id,s).some(ne=>ne.id===r.modelId)).map(_=>_.id),U.length<=1&&(S="custom"));const a=$(s);De(s),Te(S),$e(a.id),ke(a.prompt);const n=r.profileId||U[0]||((f=d[0])==null?void 0:f.id)||"";if(n&&de(n),S==="cross-provider"&&r.modelId)me(r.modelId),Y(U);else if(S==="cross-model"&&r.modelId)K([r.modelId]);else if(S==="cross-model"&&!r.modelId&&n){const _=I(n,s);K(_.map(ne=>ne.id))}else S==="custom"&&oe&&H([oe]);const E=window.setTimeout(()=>{let _;if(S==="cross-provider"&&r.modelId)_=d.map(x=>{const w=I(x.id,s).find(A=>A.id===r.modelId);return w?B(x.id,x.name,w):null}).filter(Le);else if(S==="cross-model"&&r.modelId){const x=d.find(w=>w.id===n);if(x){const w=I(x.id,s).find(A=>A.id===r.modelId);_=w?[B(x.id,x.name,w)]:[]}else _=[]}else if(S==="custom"){const x=d.find(w=>w.id===(r.profileId||n));if(x&&r.modelId){const w=I(x.id,s).find(A=>A.id===r.modelId);_=w?[B(x.id,x.name,w)]:[]}else _=[]}else{const x=n||v;x?_=I(x,s).map(w=>{const A=d.find(vt=>vt.id===x);return A?B(A.id,A.name,w):null}).filter(Le):_=[]}if(!_.length)return;if(!r.autoRun){requestAnimationFrame(()=>{setTimeout(()=>{L.current=!1},0)});return}const ne=C.createSession({modality:s,compareMode:S,promptPresetId:a.id,prompt:a.prompt,rankingMode:je,targets:_,source:"shortcut"});C.runSession(ne.id),requestAnimationFrame(()=>{setTimeout(()=>{L.current=!1},0)})},120);return()=>{window.clearTimeout(E)}},[p,r,c,je,v,h.ready]);const ht=async()=>{if(!(Ce.current||we)&&!(T.length===0||!ue.trim())){Ce.current=!0,Oe(!0);try{const e=C.createSession({modality:m,compareMode:u,promptPresetId:rt,prompt:ue,knowledgeContextRefs:Ke,rankingMode:je,targets:T,source:"manual"});await C.runSession(e.id,Ve)}finally{Ce.current=!1,Oe(!1)}}},ft=async()=>{if(Se)return;const e=h.sessions;if(e.length===0){Ae.warning("暂无历史会话可导出");return}const s=Date.now(),d=Gt(e);ge("model_benchmark_excel_export_started",{source:"workbench",...d}),Be(!0);try{const k=await gt(()=>import("./office-data-ByisqnCq.js").then(a=>a.x),[],import.meta.url),Q=e.flatMap(a=>a.entries.map(n=>{var E;return{会话标题:a.title,会话ID:a.id,会话创建时间:ie(a.createdAt),模态:le[a.modality],对比方式:ae[a.compareMode],会话状态:Re[a.status],提示词预设:a.promptPresetId,提示词:W(a.prompt),知识库上下文:Je((E=a.knowledgeContextRefs)==null?void 0:E.map(f=>f.title)),供应商配置:n.profileName,供应商ID:n.profileId,模型名称:n.modelLabel,模型ID:n.modelId,厂商:n.vendor,选择Key:n.selectionKey,结果ID:n.id,结果状态:be[n.status],开始时间:ie(n.startedAt),首响时间:ie(n.firstResponseAt),完成时间:ie(n.completedAt),首响ms:n.firstResponseMs,总耗时ms:n.totalDurationMs,预估成本:n.estimatedCost,用户评分:n.userScore,已收藏:Ze(n.favorite),已淘汰:Ze(n.rejected),错误摘要:W(n.errorSummary),预览文本:W(n.preview.text),预览链接:W(n.preview.url),预览链接列表:Je(n.preview.urls),预览格式:n.preview.format||"",预览时长:n.preview.duration??"",预览标题:W(n.preview.title)}})),O=new Map;e.forEach(a=>{a.entries.forEach(n=>{const E=`${a.modality}::${n.selectionKey}`,f=O.get(E)||{profileName:n.profileName,profileId:n.profileId,modelLabel:n.modelLabel,modelId:n.modelId,vendor:n.vendor,modality:le[a.modality],selectionKey:n.selectionKey,sessionIds:new Set,count:0,completedCount:0,failedCount:0,runningCount:0,pendingCount:0,favoriteCount:0,rejectedCount:0,firstResponseValues:[],totalDurationValues:[],costValues:[],scoreValues:[],latestAt:0};f.sessionIds.add(a.id),f.count+=1,n.status==="completed"&&(f.completedCount+=1),n.status==="failed"&&(f.failedCount+=1),n.status==="running"&&(f.runningCount+=1),n.status==="pending"&&(f.pendingCount+=1),n.favorite&&(f.favoriteCount+=1),n.rejected&&(f.rejectedCount+=1),typeof n.firstResponseMs=="number"&&f.firstResponseValues.push(n.firstResponseMs),typeof n.totalDurationMs=="number"&&f.totalDurationValues.push(n.totalDurationMs),typeof n.estimatedCost=="number"&&f.costValues.push(n.estimatedCost),typeof n.userScore=="number"&&f.scoreValues.push(n.userScore),f.latestAt=Math.max(f.latestAt,n.completedAt||n.startedAt||a.updatedAt||a.createdAt),O.set(E,f)})});const ee=Array.from(O.values()).map(a=>({供应商配置:a.profileName,供应商ID:a.profileId,模型名称:a.modelLabel,模型ID:a.modelId,厂商:a.vendor,模态:a.modality,选择Key:a.selectionKey,测试次数:a.count,涉及会话数:a.sessionIds.size,完成次数:a.completedCount,失败次数:a.failedCount,运行中次数:a.runningCount,待测次数:a.pendingCount,收藏次数:a.favoriteCount,淘汰次数:a.rejectedCount,平均首响ms:_e(a.firstResponseValues),最快首响ms:a.firstResponseValues.length>0?Math.min(...a.firstResponseValues):null,平均总耗时ms:_e(a.totalDurationValues),最快总耗时ms:a.totalDurationValues.length>0?Math.min(...a.totalDurationValues):null,平均成本:_e(a.costValues),平均评分:_e(a.scoreValues),最近测试时间:ie(a.latestAt)})).sort((a,n)=>{const E=(n.平均评分??-1)-(a.平均评分??-1);if(E!==0)return E;const f=(a.平均首响ms??Number.MAX_SAFE_INTEGER)-(n.平均首响ms??Number.MAX_SAFE_INTEGER);return f!==0?f:(a.平均成本??Number.MAX_SAFE_INTEGER)-(n.平均成本??Number.MAX_SAFE_INTEGER)}),te=k.utils.book_new(),se=k.utils.json_to_sheet(ee),S=k.utils.json_to_sheet(Q);se["!cols"]=[{wch:18},{wch:22},{wch:24},{wch:32},{wch:14},{wch:10},{wch:32},{wch:8},{wch:10},{wch:8},{wch:8},{wch:10},{wch:8},{wch:8},{wch:8},{wch:18},{wch:18},{wch:12},{wch:18},{wch:12},{wch:12},{wch:12},{wch:20}],S["!cols"]=[{wch:28},{wch:24},{wch:20},{wch:10},{wch:14},{wch:10},{wch:18},{wch:60},{wch:18},{wch:22},{wch:24},{wch:32},{wch:14},{wch:32},{wch:24},{wch:10},{wch:20},{wch:20},{wch:20},{wch:12},{wch:12},{wch:12},{wch:10},{wch:8},{wch:8},{wch:36},{wch:60},{wch:60},{wch:80},{wch:12},{wch:10},{wch:28}],k.utils.book_append_sheet(te,se,"模型汇总"),k.utils.book_append_sheet(te,S,"原始结果");const U=k.write(te,{bookType:"xlsx",type:"array"}),oe=new Blob([U],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});At(oe,Xt()),ge("model_benchmark_excel_export_completed",{source:"workbench",...d,modelSummaryRowCount:ee.length,durationMs:Date.now()-s,fileSize:oe.size}),Ae.success(`已导出 ${ee.length} 个模型结果`)}catch(k){console.error("[ModelBenchmark] Excel export failed:",k),ge("model_benchmark_excel_export_failed",{source:"workbench",...d,durationMs:Date.now()-s,errorMessage:qt(k)}),Ae.error("导出 Excel 失败,请稍后重试")}finally{Be(!1)}},bt=e=>{const s=e.preview.rawData?t.jsxs("details",{className:"model-benchmark__raw-data",children:[t.jsx("summary",{children:"原始数据 (JSON)"}),t.jsx("pre",{children:JSON.stringify(e.preview.rawData,null,2)})]}):null;return e.modality==="text"?t.jsxs("div",{className:"model-benchmark__preview-content",children:[t.jsx("pre",{className:"model-benchmark__preview-text",children:e.preview.text||"暂无返回"}),s]}):e.modality==="image"&&e.preview.url?t.jsxs("div",{className:"model-benchmark__preview-content",children:[t.jsx($t,{className:"model-benchmark__preview-image",src:e.preview.url,alt:e.modelLabel,showSkeleton:!1}),s]}):e.modality==="video"&&e.preview.url?t.jsxs("div",{className:"model-benchmark__preview-content",children:[t.jsx("video",{className:"model-benchmark__preview-video",src:e.preview.url,controls:!0,preload:"metadata"}),s]}):e.modality==="audio"&&e.preview.url?t.jsxs("div",{className:"model-benchmark__preview-content",children:[t.jsxs("div",{className:"model-benchmark__preview-audio-shell",children:[t.jsx("audio",{controls:!0,preload:"none",src:e.preview.url}),e.preview.text?t.jsx("pre",{className:"model-benchmark__preview-text",children:e.preview.text}):null]}),s]}):t.jsxs("div",{className:"model-benchmark__preview-empty",children:[e.status==="failed"?"加载失败":"暂无预览",s]})};u==="cross-model"?`${(y==null?void 0:y.name)||"未选择"}`:u==="cross-provider"&&`${R||"未选择"}`;const _t=Ie.map(e=>({label:st(e),value:e.id})),Ye=V.map(e=>({label:`${e.profileName} · ${e.modelLabel}`,value:e.profileId})),xt=[{label:"全部",value:"all",icon:t.jsx(Rt,{size:14})},{label:"图片",value:"image",icon:t.jsx(Lt,{size:"14px"})},{label:"视频",value:"video",icon:t.jsx(Pt,{size:"14px"})},{label:"音频",value:"audio",icon:t.jsx(Dt,{size:14,strokeWidth:1.9})},{label:"文本",value:"text",icon:t.jsx(Tt,{size:"14px"})}];return t.jsxs("div",{className:"model-benchmark",children:[t.jsxs("aside",{className:"model-benchmark__sidebar",children:[t.jsxs("div",{className:"model-benchmark__sidebar-head",children:[t.jsx("div",{className:"model-benchmark__panel-title",children:"历史会话"}),t.jsx("button",{type:"button",className:"model-benchmark__ghost-button",onClick:ft,disabled:h.sessions.length===0||Se,children:Se?"导出中...":"导出 Excel"})]}),t.jsxs("div",{className:"model-benchmark__sidebar-filters",children:[t.jsx(Nt,{value:Ne,onChange:ct,placeholder:"搜索会话 / 模型 / 供应商",prefixIcon:t.jsx(Ct,{}),size:"small",clearable:!0}),t.jsx("div",{className:"model-benchmark__sidebar-tabs",children:xt.map(e=>t.jsx(Ee,{content:e.label,children:t.jsx("button",{type:"button",className:pe===e.value?"model-benchmark__sidebar-tab model-benchmark__sidebar-tab--active":"model-benchmark__sidebar-tab",onClick:()=>dt(e.value),"aria-label":e.label,children:e.icon})},e.value))})]}),t.jsx("div",{className:"model-benchmark__session-list",children:ze.length>0?ze.map(e=>{const s=Ht(e);return t.jsxs("div",{className:"model-benchmark__session-row",children:[t.jsxs("button",{type:"button",className:`model-benchmark__session-item ${e.id===h.activeSessionId?"model-benchmark__session-item--active":""}`,onClick:()=>C.setActiveSession(e.id),children:[t.jsx("span",{className:"model-benchmark__session-title",children:e.title}),t.jsx("span",{className:"model-benchmark__session-models",children:s.length>0?s.join(" / "):"暂无模型信息"}),t.jsxs("span",{className:"model-benchmark__session-meta",children:[ae[e.compareMode]," ·"," ",e.entries.length," 个目标 ·"," ",Re[e.status]]})]}),t.jsx("button",{type:"button",className:"model-benchmark__session-delete",onClick:()=>void mt(e),"aria-label":`删除会话 ${e.title}`,children:t.jsx(Ee,{content:"删除会话",showArrow:!1,children:t.jsx("span",{children:t.jsx(It,{})})})})]},e.id)}):t.jsx("div",{className:"model-benchmark__session-empty",children:h.sessions.length===0?"暂无历史会话":"没有匹配的历史会话"})})]}),t.jsx("main",{className:"model-benchmark__main",children:t.jsxs("div",{className:"model-benchmark__main-shell",children:[t.jsxs("section",{className:"model-benchmark__config-dashboard",children:[t.jsxs("div",{className:"model-benchmark__config-row model-benchmark__config-row--top",children:[t.jsx("div",{className:"model-benchmark__modality-tabs",children:Object.keys(le).map(e=>t.jsx("button",{type:"button",className:m===e?"active":"",onClick:()=>{m!==e&&j("modality",{previousModality:m,modality:e}),De(e)},children:le[e]},e))}),t.jsx("div",{className:"model-benchmark__mode-selector",children:Object.entries(ae).map(([e,s])=>t.jsx(Ee,{content:Ot[e],placement:"top",children:t.jsx("button",{type:"button",className:u===e?"active":"",onClick:()=>{const d=e;u!==d&&j("compare_mode",{modality:m,previousCompareMode:u,compareMode:d}),Te(d)},children:s})},e))})]}),t.jsxs("div",{className:"model-benchmark__config-main",children:[t.jsxs("div",{className:"model-benchmark__config-controls",children:[t.jsxs("div",{className:"model-benchmark__primary-select-row",children:[u==="cross-model"?t.jsx(re,{className:"model-benchmark__select",label:"目标供应商: ",value:v,onChange:e=>{const s=e;j("target_profile",{modality:m,compareMode:u,previousProfileId:v,profileId:s}),de(s)},options:N.map(e=>({label:e.name,value:e.id}))}):null,u==="cross-provider"?t.jsx(re,{filterable:!0,className:"model-benchmark__select",label:"对比模型: ",value:R,options:_t,placeholder:"搜索并选择要横向对比的模型",onChange:e=>{const s=e||"";j("target_model",{modality:m,compareMode:u,previousModelId:R,modelId:s}),me(s)}}):null]}),t.jsxs("div",{className:"model-benchmark__secondary-select-row",children:[u==="cross-provider"?t.jsx(re,{multiple:!0,filterable:!0,minCollapsedNum:3,popupProps:{overlayClassName:"model-benchmark__select-popup"},panelTopContent:t.jsxs("div",{className:"model-benchmark__select-actions",children:[t.jsx("button",{type:"button",onClick:()=>{const e=Ye.map(s=>s.value);j("provider_selection",{modality:m,compareMode:u,selectionAction:"select_all",selectedCount:e.length}),Y(e)},children:"全选"}),t.jsx("button",{type:"button",onClick:()=>{j("provider_selection",{modality:m,compareMode:u,selectionAction:"clear",selectedCount:0}),Y([])},children:"清除"})]}),className:"model-benchmark__multi-select",label:"参测供应商: ",value:z,options:Ye,placeholder:"多选要参与对比的供应商 (已选即为批测队列)",onChange:e=>{const s=Array.isArray(e)?e:[];j("provider_selection",{modality:m,compareMode:u,selectionAction:"change",previousSelectedCount:z.length,selectedCount:s.length}),Y(s)}}):null,u==="cross-model"?t.jsx(re,{multiple:!0,filterable:!0,minCollapsedNum:3,popupProps:{overlayClassName:"model-benchmark__select-popup"},panelTopContent:t.jsxs("div",{className:"model-benchmark__select-actions",children:[t.jsx("button",{type:"button",onClick:()=>{const e=P.map(s=>s.id);j("model_selection",{modality:m,compareMode:u,selectionAction:"select_all",selectedCount:e.length}),K(e)},children:"全选"}),t.jsx("button",{type:"button",onClick:()=>{j("model_selection",{modality:m,compareMode:u,selectionAction:"clear",selectedCount:0}),K([])},children:"清除"})]}),className:"model-benchmark__multi-select",label:"参测模型: ",value:F,options:P.map(e=>({label:st(e),value:e.id})),placeholder:"多选要测试的模型 (已选即为批测队列)",onChange:e=>{const s=Array.isArray(e)?e:[];j("model_selection",{modality:m,compareMode:u,selectionAction:"change",previousSelectedCount:F.length,selectedCount:s.length}),K(s)}}):null,u==="custom"?t.jsx(re,{multiple:!0,filterable:!0,minCollapsedNum:3,popupProps:{overlayClassName:"model-benchmark__select-popup"},panelTopContent:t.jsxs("div",{className:"model-benchmark__select-actions",children:[t.jsx("button",{type:"button",onClick:()=>{const e=D.map(s=>s.selectionKey);j("custom_selection",{modality:m,compareMode:u,selectionAction:"select_all",selectedCount:e.length}),H(e)},children:"全选"}),t.jsx("button",{type:"button",onClick:()=>{j("custom_selection",{modality:m,compareMode:u,selectionAction:"clear",selectedCount:0}),H([])},children:"清除"})]}),className:"model-benchmark__multi-select",label:"目标组合: ",value:q,options:D.map(e=>({label:`${e.profileName} · ${e.modelLabel}`,value:e.selectionKey})),placeholder:"手动编排供应商与模型组合",onChange:e=>{const s=Array.isArray(e)?e:[];j("custom_selection",{modality:m,compareMode:u,selectionAction:"change",previousSelectedCount:q.length,selectedCount:s.length}),H(s)}}):null]})]}),t.jsxs("div",{className:"model-benchmark__config-actions",children:[t.jsxs("div",{className:"model-benchmark__prompt-area",children:[t.jsx("textarea",{value:ue,onChange:e=>ke(e.target.value),placeholder:"在此输入测试提示词..."}),t.jsx(Vt,{value:Ke,onChange:lt,className:"model-benchmark__knowledge-context"})]}),t.jsxs("div",{className:"model-benchmark__action-row-inline",children:[t.jsxs("div",{className:"model-benchmark__concurrency",children:[t.jsx("span",{children:"最大并发:"}),t.jsx("input",{type:"text",inputMode:"numeric","aria-label":"最大并发",value:Ve,onChange:e=>{const s=e.target.value.replace(/\D/g,""),d=Number(s);at(Math.min(Mt,Math.max(1,d||1)))}})]}),t.jsx("button",{type:"button",className:"model-benchmark__primary-button",onClick:ht,disabled:we||!h.ready||T.length===0||!ue.trim(),children:we?"测试中...":`开始测试 (${T.length})`})]})]})]})]}),t.jsx("div",{className:"model-benchmark__main-head",children:t.jsxs("div",{children:[t.jsx("div",{className:"model-benchmark__eyebrow",children:g?ae[g.compareMode]:"Result Board"}),t.jsx("h3",{children:g?g.title:"还没有测试结果"}),g?t.jsxs("p",{className:"model-benchmark__main-desc",children:[Z.total," 个目标",Z.completed>0?`,${Z.completed} 成功`:"",Z.failed>0?`,${Z.failed} 失败`:""," · ",Re[g.status]," · ",Bt[g.rankingMode]]}):t.jsx("p",{className:"model-benchmark__main-desc",children:"请先在上方明确范围,或点击历史会话查看以往结果。"})]})}),g?t.jsxs(t.Fragment,{children:[M?t.jsxs("section",{className:"model-benchmark__spotlight",children:[t.jsxs("div",{className:"model-benchmark__spotlight-copy",children:[t.jsx("div",{className:"model-benchmark__eyebrow",children:"当前第一名"}),t.jsx("h4",{children:g.compareMode==="cross-provider"?M.profileName:M.modelLabel}),t.jsxs("p",{children:[g.compareMode==="cross-provider"?`${M.modelLabel},`:`来自 ${M.profileName},`,"首响 ",ve(M.firstResponseMs),",总耗时 ",ve(M.totalDurationMs)]})]}),t.jsxs("div",{className:"model-benchmark__spotlight-meta",children:[M.userScore?t.jsxs("span",{children:[M.userScore," 分"]}):null,M.favorite?t.jsx("span",{children:"已收藏"}):null]})]}):null,t.jsx("div",{className:"model-benchmark__result-grid",children:Xe.map((e,s)=>t.jsxs("article",{className:`model-benchmark__result-card model-benchmark__result-card--${e.status}`,children:[t.jsxs("header",{className:"model-benchmark__result-head",children:[t.jsxs("div",{className:"model-benchmark__result-rank",children:["#",s+1]}),t.jsxs("div",{className:"model-benchmark__result-heading",children:[t.jsx("div",{className:"model-benchmark__result-title",children:e.modelLabel}),t.jsx("div",{className:"model-benchmark__result-subtitle",children:e.profileName})]}),t.jsx("span",{className:`model-benchmark__status model-benchmark__status--${e.status}`,children:e.status==="completed"?"完成":e.status==="failed"?"失败":e.status==="running"?"测试中":"等待中"})]}),t.jsxs("div",{className:"model-benchmark__result-metrics",children:[t.jsxs("span",{children:["首响 ",ve(e.firstResponseMs)]}),t.jsxs("span",{children:["总耗时 ",ve(e.totalDurationMs)]}),t.jsxs("span",{children:["成本"," ",e.estimatedCost===null?"未知":`¥${e.estimatedCost.toFixed(4)}`]}),t.jsxs("span",{children:["性价比"," ",(()=>{const d=Et(e);return d===null?"—":`${d}/10`})()]})]}),t.jsx("div",{className:"model-benchmark__preview",children:bt(e)}),e.errorSummary?t.jsx("div",{className:"model-benchmark__error",children:e.errorSummary}):null,t.jsxs("div",{className:"model-benchmark__feedback",children:[t.jsx("div",{className:"model-benchmark__score-row",children:[1,2,3,4,5].map(d=>t.jsxs("button",{type:"button",className:`model-benchmark__score-chip ${e.userScore===d?"model-benchmark__score-chip--active":""}`,onClick:()=>C.setEntryFeedback(g.id,e.id,{userScore:e.userScore===d?null:d}),children:[d,"分"]},d))}),t.jsxs("div",{className:"model-benchmark__action-row",children:[t.jsx("button",{type:"button",className:`model-benchmark__ghost-button ${e.favorite?"model-benchmark__ghost-button--active":""}`,onClick:()=>C.setEntryFeedback(g.id,e.id,{favorite:!e.favorite}),children:"收藏"}),t.jsx("button",{type:"button",className:`model-benchmark__ghost-button ${e.rejected?"model-benchmark__ghost-button--danger":""}`,onClick:()=>C.setEntryFeedback(g.id,e.id,{rejected:!e.rejected}),children:"淘汰"})]})]})]},e.id))})]}):t.jsx("div",{className:"model-benchmark__empty",children:"先在左侧选定“同供应商多模型”或“同模型跨供应商”,把批测目标编满后再开跑。"})]})}),i]})}export{rs as default};
|
|
1
|
+
import{_ as gt}from"./startup-runtime-DTmhLESk.js";import{ee as kt,lB as wt,r as l,jZ as C,lC as $,y as St,lD as B,lE as Me,lF as jt,j as t,c7 as Nt,c8 as Ct,E as Ee,b$ as It,hO as re,fW as Mt,lG as Et,ag as ye,a6 as yt,M as Ae,kZ as ge,lH as At,cn as Rt,cq as Lt,kp as Dt,p as Pt,lI as Tt,R as $t}from"./startup-app-eD_rQhSh.js";import{b as Kt}from"./model-benchmark-launcher-DAWoSySc.js";import{B as De,K as Vt}from"./ai-chat-BO5vbKZW.js";const le={text:"文本",image:"图片",video:"视频",audio:"音频"},ae={"cross-provider":"跨供应商对比","cross-model":"多模型批测",custom:"自定义测试"},Ot={"cross-provider":"锁定一个模型,横向比较不同供应商的稳定性、速度和效果差异。","cross-model":"锁定一个供应商,一次跑完同类模型,快速筛掉慢和差的型号。",custom:"手动编排供应商与模型组合,适合做定向复测和候选名单对比。"},Bt={speed:"速度优先",cost:"成本优先",balanced:"综合平衡","value-for-money":"性价比"},Re={draft:"待启动",running:"测试中",completed:"已完成",partial:"部分失败",failed:"全部失败"},be={pending:"待测",running:"测试中",completed:"已完成",failed:"失败"},Ft=6,zt=8,He=32e3;function qt(o){return o instanceof Error?o.message:"unknown_error"}function Gt(o){const i=new Set;return{...o.reduce((c,p)=>(p.entries.forEach(h=>{i.add(`${p.modality}::${h.selectionKey}`),c.detailRowCount+=1,h.status==="completed"&&(c.completedEntryCount+=1),h.status==="failed"&&(c.failedEntryCount+=1),h.status==="running"&&(c.runningEntryCount+=1),h.status==="pending"&&(c.pendingEntryCount+=1),h.favorite&&(c.favoriteEntryCount+=1),h.rejected&&(c.rejectedEntryCount+=1)}),c),{sessionCount:o.length,detailRowCount:0,completedEntryCount:0,failedEntryCount:0,runningEntryCount:0,pendingEntryCount:0,favoriteEntryCount:0,rejectedEntryCount:0}),modelSummaryRowCount:i.size}}function j(o,i){ge("model_benchmark_config_changed",{source:"workbench",control:o,...i})}function ie(o){return o?new Date(o).toLocaleString("zh-CN",{hour12:!1}):""}function ot(o){return o.length>He?`${o.slice(0,He-8)}...[截断]`:o}function W(o){return o?o.startsWith("data:")?"[内嵌数据已省略]":ot(o):""}function Je(o){return o!=null&&o.length?ot(o.map(i=>W(i)).join(`
|
|
2
|
+
`)):""}function Ze(o){return o?"是":"否"}function _e(o){let i=0,r=0;return o.forEach(c=>{typeof c=="number"&&Number.isFinite(c)&&(i+=c,r+=1)}),r>0?Number((i/r).toFixed(2)):null}function Xt(o=new Date){const i=`${o.getFullYear()}${String(o.getMonth()+1).padStart(2,"0")}${String(o.getDate()).padStart(2,"0")}`,r=`${String(o.getHours()).padStart(2,"0")}${String(o.getMinutes()).padStart(2,"0")}${String(o.getSeconds()).padStart(2,"0")}`;return`model-benchmark-history_${i}_${r}.xlsx`}function Le(o){return o!==null}function Qt(o){return o.trim().toLowerCase().split(/\s+/).filter(Boolean)}function xe(o,i){const r=Qt(o);if(r.length===0)return!0;const c=i.filter(Boolean).join(" ").toLowerCase();return r.every(p=>c.includes(p))}function Ut(o){return o==="text"?"supportsText":o==="image"?"supportsImage":o==="video"?"supportsVideo":"supportsAudio"}function et(o,i){const r=Ut(i);return o.filter(c=>c.enabled&&(c.id===yt||c.capabilities[r]))}function Wt(){const[o,i]=l.useState(0);return l.useEffect(()=>De.subscribe(()=>{i(r=>r+1)}),[]),o}function Yt(){const[o,i]=l.useState(()=>ye.get());return l.useEffect(()=>{const r=c=>{i(c)};return ye.addListener(r),()=>{ye.removeListener(r)}},[]),o}function ve(o){return!o||o<0?"--":o<1e3?`${o}ms`:`${(o/1e3).toFixed(o>=1e4?1:2)}s`}function Ht(o){const i=new Map;o.entries.forEach(c=>{var ce,m;const p=(ce=c.modelId)==null?void 0:ce.trim(),h=(m=c.modelLabel)==null?void 0:m.trim();p&&h&&!i.has(p)&&i.set(p,{modelId:p,modelLabel:h})});const r=new Map;return i.forEach(({modelLabel:c})=>{r.set(c,(r.get(c)||0)+1)}),Array.from(i.values()).map(({modelId:c,modelLabel:p})=>(r.get(p)||0)>1?`${p} · ${c}`:p)}function tt(o){return o?o.entries.reduce((i,r)=>(i.total+=1,r.status==="completed"&&(i.completed+=1),r.status==="failed"&&(i.failed+=1),r.status==="running"&&(i.running+=1),i),{total:0,completed:0,failed:0,running:0}):{total:0,completed:0,failed:0,running:0}}function I(o,i){const r=De.getState(o).models.filter(p=>p.type===i),c=new Map;return r.forEach(p=>{c.has(p.id)||c.set(p.id,p)}),Array.from(c.values())}function nt(o){return o.shortLabel||o.label||o.id}function st(o){const i=nt(o);return i===o.id?i:`${i} · ${o.id}`}function Jt(o,i){return`${o}::${i}`}function rs({}){const{confirm:o,confirmDialog:i}=kt(),r=wt(Kt),c=Yt(),p=Wt(),[h,ce]=l.useState(()=>C.getState()),[m,Pe]=l.useState("text"),[u,Te]=l.useState("cross-provider"),[v,de]=l.useState(""),[R,me]=l.useState(""),[F,K]=l.useState([]),[z,Y]=l.useState([]),[q,H]=l.useState([]),[G,Zt]=l.useState(""),[X,es]=l.useState(!1),[rt,$e]=l.useState($("text").id),[ue,ke]=l.useState($("text").prompt),[Ke,lt]=l.useState([]),[Ve,at]=l.useState(2),[we,Oe]=l.useState(!1),[Se,Be]=l.useState(!1),[je,it]=l.useState("speed"),[Ne,ct]=l.useState(""),[pe,dt]=l.useState("all"),Fe=l.useRef(""),L=l.useRef(!1),Ce=l.useRef(!1),he=l.useRef(null);l.useRef({}),l.useEffect(()=>{const e=C.observe().subscribe(s=>{l.startTransition(()=>{ce(s)})});return()=>e.unsubscribe()},[]);const N=l.useMemo(()=>et(c,m),[m,c]),J=l.useMemo(()=>new Map(N.map(e=>[e.id,e])),[N]),y=v&&J.get(v)||null,mt=St.useCallback(async e=>{await o({title:"确认删除会话",description:`确定要删除会话「${e.title||"未命名会话"}」吗?此操作不可撤销。`,confirmText:"删除",cancelText:"取消",danger:!0})&&C.removeSession(e.id)},[o]),D=l.useMemo(()=>v?I(v,m):[],[p,m,v]),Ie=l.useMemo(()=>{const e=new Map;return N.forEach(s=>{I(s.id,m).forEach(d=>{e.has(d.id)||e.set(d.id,d)})}),Array.from(e.values())},[N,p,m]),P=l.useMemo(()=>N.flatMap(e=>I(e.id,m).map(s=>B(e.id,e.name,s))),[N,p,m]);l.useEffect(()=>{if(L.current)return;if(!N.length){de("");return}const e=$(m);$e(e.id),ke(s=>s===$("text").prompt||s===$("image").prompt||s===$("video").prompt||s===$("audio").prompt?e.prompt:s),(!v||!J.has(v))&&de(N[0].id)},[N,m,J,v]),l.useEffect(()=>{if(L.current)return;const e=D.map(s=>s.id);if(e.length===0){K([]);return}K(s=>Me(s,e,{fallback:"all"}))},[D]),l.useEffect(()=>{if(L.current)return;const e=Ie.map(s=>s.id);if(e.length===0){me("");return}e.includes(R)||me(e[0])},[Ie,R]);const V=l.useMemo(()=>R?N.map(e=>{const s=I(e.id,m).find(d=>d.id===R);return s?B(e.id,e.name,s):null}).filter(Le):[],[N,m,R]);l.useEffect(()=>{L.current||Y(e=>Me(e,V.map(s=>s.profileId),{fallback:"all"}))},[V]),l.useEffect(()=>{L.current||H(e=>Me(e,P.map(s=>s.selectionKey),{fallback:"first",limit:Ft}))},[P]);const b=l.useMemo(()=>h.sessions.find(e=>e.id===h.activeSessionId)||null,[h.activeSessionId,h.sessions]),ze=l.useMemo(()=>h.sessions.filter(e=>pe!=="all"&&e.modality!==pe?!1:xe(Ne,[e.title,e.prompt,...(e.knowledgeContextRefs||[]).map(s=>s.title),ae[e.compareMode],le[e.modality],...e.entries.flatMap(s=>[s.profileName,s.profileId,s.modelLabel,s.modelId,s.vendor])])),[pe,Ne,h.sessions]);l.useEffect(()=>{b&&it(b.rankingMode)},[b]);const ut=l.useMemo(()=>tt(b),[b]),pt=l.useMemo(()=>b?jt(b.entries,b.rankingMode):[],[b]),T=l.useMemo(()=>{if(u==="cross-provider")return V.filter(e=>z.includes(e.profileId));if(u==="cross-model"){if(!v)return[];const e=J.get(v);return e?D.filter(s=>F.includes(s.id)).map(s=>B(e.id,e.name,s)):[]}return P.filter(e=>q.includes(e.selectionKey))},[D,u,V,P,J,q,F,v,z]),qe=l.useMemo(()=>{if(!b||b.modality!==m||b.compareMode!==u)return!1;const e=T.map(d=>d.selectionKey);if(e.length===0||b.entries.length!==e.length)return!1;const s=new Set(e);return b.entries.every(d=>s.has(d.selectionKey))},[b,u,m,T]),Ge=l.useMemo(()=>b&&qe?b.entries.map(e=>({key:e.selectionKey,modelLabel:e.modelLabel,profileName:e.profileName,badgeLabel:be[e.status]||be.pending})):T.map(e=>({key:e.selectionKey,modelLabel:e.modelLabel,profileName:e.profileName,badgeLabel:be.pending})),[b,qe,T]),g=b,Z=g?ut:tt(null),Xe=g?pt:[];Ge.length,Ge.slice(0,zt);const M=Xe.find(e=>e.status==="completed")||null,Qe=l.useMemo(()=>D.filter(e=>{const s=F.includes(e.id);return X&&!s?!1:xe(G,[nt(e),e.id,y==null?void 0:y.name])}),[y==null?void 0:y.name,D,G,F,X]),Ue=l.useMemo(()=>V.filter(e=>{const s=z.includes(e.profileId);return X&&!s?!1:xe(G,[e.profileName,e.modelLabel,e.modelId,e.profileId])}),[V,G,z,X]),We=l.useMemo(()=>P.filter(e=>{const s=q.includes(e.selectionKey);return X&&!s?!1:xe(G,[e.profileName,e.modelLabel,e.modelId,e.profileId])}),[P,G,q,X]),fe=l.useMemo(()=>u==="cross-model"?Qe.map(e=>e.id):u==="cross-provider"?Ue.map(e=>e.profileId):We.map(e=>e.selectionKey),[u,Qe,Ue,We]);l.useEffect(()=>{if(fe.length===0){he.current=null;return}he.current&&fe.includes(he.current)||(he.current=fe[0])},[fe]),l.useEffect(()=>{var f;if(!r||!h.ready)return;const e=JSON.stringify(r);if(Fe.current===e)return;const s=r.modality||"text",d=et(c,s),k=r.profileId||"",Q=r.modelId||"",O=k?De.getState(k):null,ee=k&&Q?I(k,s):[],te=!Q||ee.some(_=>_.id===Q);if(O&&Q&&!te&&(O.status==="idle"||O.status==="loading"))return;L.current=!0,Fe.current=e;const se=r.compareMode||(r.modelId?"cross-provider":"cross-model");let S=se,U=[];const oe=r.profileId&&r.modelId?Jt(r.profileId,r.modelId):"";se==="cross-provider"&&r.modelId&&(U=d.filter(_=>I(_.id,s).some(ne=>ne.id===r.modelId)).map(_=>_.id),U.length<=1&&(S="custom"));const a=$(s);Pe(s),Te(S),$e(a.id),ke(a.prompt);const n=r.profileId||U[0]||((f=d[0])==null?void 0:f.id)||"";if(n&&de(n),S==="cross-provider"&&r.modelId)me(r.modelId),Y(U);else if(S==="cross-model"&&r.modelId)K([r.modelId]);else if(S==="cross-model"&&!r.modelId&&n){const _=I(n,s);K(_.map(ne=>ne.id))}else S==="custom"&&oe&&H([oe]);const E=window.setTimeout(()=>{let _;if(S==="cross-provider"&&r.modelId)_=d.map(x=>{const w=I(x.id,s).find(A=>A.id===r.modelId);return w?B(x.id,x.name,w):null}).filter(Le);else if(S==="cross-model"&&r.modelId){const x=d.find(w=>w.id===n);if(x){const w=I(x.id,s).find(A=>A.id===r.modelId);_=w?[B(x.id,x.name,w)]:[]}else _=[]}else if(S==="custom"){const x=d.find(w=>w.id===(r.profileId||n));if(x&&r.modelId){const w=I(x.id,s).find(A=>A.id===r.modelId);_=w?[B(x.id,x.name,w)]:[]}else _=[]}else{const x=n||v;x?_=I(x,s).map(w=>{const A=d.find(vt=>vt.id===x);return A?B(A.id,A.name,w):null}).filter(Le):_=[]}if(!_.length)return;if(!r.autoRun){requestAnimationFrame(()=>{setTimeout(()=>{L.current=!1},0)});return}const ne=C.createSession({modality:s,compareMode:S,promptPresetId:a.id,prompt:a.prompt,rankingMode:je,targets:_,source:"shortcut"});C.runSession(ne.id),requestAnimationFrame(()=>{setTimeout(()=>{L.current=!1},0)})},120);return()=>{window.clearTimeout(E)}},[p,r,c,je,v,h.ready]);const ht=async()=>{if(!(Ce.current||we)&&!(T.length===0||!ue.trim())){Ce.current=!0,Oe(!0);try{const e=C.createSession({modality:m,compareMode:u,promptPresetId:rt,prompt:ue,knowledgeContextRefs:Ke,rankingMode:je,targets:T,source:"manual"});await C.runSession(e.id,Ve)}finally{Ce.current=!1,Oe(!1)}}},ft=async()=>{if(Se)return;const e=h.sessions;if(e.length===0){Ae.warning("暂无历史会话可导出");return}const s=Date.now(),d=Gt(e);ge("model_benchmark_excel_export_started",{source:"workbench",...d}),Be(!0);try{const k=await gt(()=>import("./office-data-ByisqnCq.js").then(a=>a.x),[],import.meta.url),Q=e.flatMap(a=>a.entries.map(n=>{var E;return{会话标题:a.title,会话ID:a.id,会话创建时间:ie(a.createdAt),模态:le[a.modality],对比方式:ae[a.compareMode],会话状态:Re[a.status],提示词预设:a.promptPresetId,提示词:W(a.prompt),知识库上下文:Je((E=a.knowledgeContextRefs)==null?void 0:E.map(f=>f.title)),供应商配置:n.profileName,供应商ID:n.profileId,模型名称:n.modelLabel,模型ID:n.modelId,厂商:n.vendor,选择Key:n.selectionKey,结果ID:n.id,结果状态:be[n.status],开始时间:ie(n.startedAt),首响时间:ie(n.firstResponseAt),完成时间:ie(n.completedAt),首响ms:n.firstResponseMs,总耗时ms:n.totalDurationMs,预估成本:n.estimatedCost,用户评分:n.userScore,已收藏:Ze(n.favorite),已淘汰:Ze(n.rejected),错误摘要:W(n.errorSummary),预览文本:W(n.preview.text),预览链接:W(n.preview.url),预览链接列表:Je(n.preview.urls),预览格式:n.preview.format||"",预览时长:n.preview.duration??"",预览标题:W(n.preview.title)}})),O=new Map;e.forEach(a=>{a.entries.forEach(n=>{const E=`${a.modality}::${n.selectionKey}`,f=O.get(E)||{profileName:n.profileName,profileId:n.profileId,modelLabel:n.modelLabel,modelId:n.modelId,vendor:n.vendor,modality:le[a.modality],selectionKey:n.selectionKey,sessionIds:new Set,count:0,completedCount:0,failedCount:0,runningCount:0,pendingCount:0,favoriteCount:0,rejectedCount:0,firstResponseValues:[],totalDurationValues:[],costValues:[],scoreValues:[],latestAt:0};f.sessionIds.add(a.id),f.count+=1,n.status==="completed"&&(f.completedCount+=1),n.status==="failed"&&(f.failedCount+=1),n.status==="running"&&(f.runningCount+=1),n.status==="pending"&&(f.pendingCount+=1),n.favorite&&(f.favoriteCount+=1),n.rejected&&(f.rejectedCount+=1),typeof n.firstResponseMs=="number"&&f.firstResponseValues.push(n.firstResponseMs),typeof n.totalDurationMs=="number"&&f.totalDurationValues.push(n.totalDurationMs),typeof n.estimatedCost=="number"&&f.costValues.push(n.estimatedCost),typeof n.userScore=="number"&&f.scoreValues.push(n.userScore),f.latestAt=Math.max(f.latestAt,n.completedAt||n.startedAt||a.updatedAt||a.createdAt),O.set(E,f)})});const ee=Array.from(O.values()).map(a=>({供应商配置:a.profileName,供应商ID:a.profileId,模型名称:a.modelLabel,模型ID:a.modelId,厂商:a.vendor,模态:a.modality,选择Key:a.selectionKey,测试次数:a.count,涉及会话数:a.sessionIds.size,完成次数:a.completedCount,失败次数:a.failedCount,运行中次数:a.runningCount,待测次数:a.pendingCount,收藏次数:a.favoriteCount,淘汰次数:a.rejectedCount,平均首响ms:_e(a.firstResponseValues),最快首响ms:a.firstResponseValues.length>0?Math.min(...a.firstResponseValues):null,平均总耗时ms:_e(a.totalDurationValues),最快总耗时ms:a.totalDurationValues.length>0?Math.min(...a.totalDurationValues):null,平均成本:_e(a.costValues),平均评分:_e(a.scoreValues),最近测试时间:ie(a.latestAt)})).sort((a,n)=>{const E=(n.平均评分??-1)-(a.平均评分??-1);if(E!==0)return E;const f=(a.平均首响ms??Number.MAX_SAFE_INTEGER)-(n.平均首响ms??Number.MAX_SAFE_INTEGER);return f!==0?f:(a.平均成本??Number.MAX_SAFE_INTEGER)-(n.平均成本??Number.MAX_SAFE_INTEGER)}),te=k.utils.book_new(),se=k.utils.json_to_sheet(ee),S=k.utils.json_to_sheet(Q);se["!cols"]=[{wch:18},{wch:22},{wch:24},{wch:32},{wch:14},{wch:10},{wch:32},{wch:8},{wch:10},{wch:8},{wch:8},{wch:10},{wch:8},{wch:8},{wch:8},{wch:18},{wch:18},{wch:12},{wch:18},{wch:12},{wch:12},{wch:12},{wch:20}],S["!cols"]=[{wch:28},{wch:24},{wch:20},{wch:10},{wch:14},{wch:10},{wch:18},{wch:60},{wch:18},{wch:22},{wch:24},{wch:32},{wch:14},{wch:32},{wch:24},{wch:10},{wch:20},{wch:20},{wch:20},{wch:12},{wch:12},{wch:12},{wch:10},{wch:8},{wch:8},{wch:36},{wch:60},{wch:60},{wch:80},{wch:12},{wch:10},{wch:28}],k.utils.book_append_sheet(te,se,"模型汇总"),k.utils.book_append_sheet(te,S,"原始结果");const U=k.write(te,{bookType:"xlsx",type:"array"}),oe=new Blob([U],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});At(oe,Xt()),ge("model_benchmark_excel_export_completed",{source:"workbench",...d,modelSummaryRowCount:ee.length,durationMs:Date.now()-s,fileSize:oe.size}),Ae.success(`已导出 ${ee.length} 个模型结果`)}catch(k){console.error("[ModelBenchmark] Excel export failed:",k),ge("model_benchmark_excel_export_failed",{source:"workbench",...d,durationMs:Date.now()-s,errorMessage:qt(k)}),Ae.error("导出 Excel 失败,请稍后重试")}finally{Be(!1)}},bt=e=>{const s=e.preview.rawData?t.jsxs("details",{className:"model-benchmark__raw-data",children:[t.jsx("summary",{children:"原始数据 (JSON)"}),t.jsx("pre",{children:JSON.stringify(e.preview.rawData,null,2)})]}):null;return e.modality==="text"?t.jsxs("div",{className:"model-benchmark__preview-content",children:[t.jsx("pre",{className:"model-benchmark__preview-text",children:e.preview.text||"暂无返回"}),s]}):e.modality==="image"&&e.preview.url?t.jsxs("div",{className:"model-benchmark__preview-content",children:[t.jsx($t,{className:"model-benchmark__preview-image",src:e.preview.url,alt:e.modelLabel,showSkeleton:!1}),s]}):e.modality==="video"&&e.preview.url?t.jsxs("div",{className:"model-benchmark__preview-content",children:[t.jsx("video",{className:"model-benchmark__preview-video",src:e.preview.url,controls:!0,preload:"metadata"}),s]}):e.modality==="audio"&&e.preview.url?t.jsxs("div",{className:"model-benchmark__preview-content",children:[t.jsxs("div",{className:"model-benchmark__preview-audio-shell",children:[t.jsx("audio",{controls:!0,preload:"none",src:e.preview.url}),e.preview.text?t.jsx("pre",{className:"model-benchmark__preview-text",children:e.preview.text}):null]}),s]}):t.jsxs("div",{className:"model-benchmark__preview-empty",children:[e.status==="failed"?"加载失败":"暂无预览",s]})};u==="cross-model"?`${(y==null?void 0:y.name)||"未选择"}`:u==="cross-provider"&&`${R||"未选择"}`;const _t=Ie.map(e=>({label:st(e),value:e.id})),Ye=V.map(e=>({label:`${e.profileName} · ${e.modelLabel}`,value:e.profileId})),xt=[{label:"全部",value:"all",icon:t.jsx(Rt,{size:14})},{label:"图片",value:"image",icon:t.jsx(Lt,{size:"14px"})},{label:"视频",value:"video",icon:t.jsx(Dt,{size:"14px"})},{label:"音频",value:"audio",icon:t.jsx(Pt,{size:14,strokeWidth:1.9})},{label:"文本",value:"text",icon:t.jsx(Tt,{size:"14px"})}];return t.jsxs("div",{className:"model-benchmark",children:[t.jsxs("aside",{className:"model-benchmark__sidebar",children:[t.jsxs("div",{className:"model-benchmark__sidebar-head",children:[t.jsx("div",{className:"model-benchmark__panel-title",children:"历史会话"}),t.jsx("button",{type:"button",className:"model-benchmark__ghost-button",onClick:ft,disabled:h.sessions.length===0||Se,children:Se?"导出中...":"导出 Excel"})]}),t.jsxs("div",{className:"model-benchmark__sidebar-filters",children:[t.jsx(Nt,{value:Ne,onChange:ct,placeholder:"搜索会话 / 模型 / 供应商",prefixIcon:t.jsx(Ct,{}),size:"small",clearable:!0}),t.jsx("div",{className:"model-benchmark__sidebar-tabs",children:xt.map(e=>t.jsx(Ee,{content:e.label,children:t.jsx("button",{type:"button",className:pe===e.value?"model-benchmark__sidebar-tab model-benchmark__sidebar-tab--active":"model-benchmark__sidebar-tab",onClick:()=>dt(e.value),"aria-label":e.label,children:e.icon})},e.value))})]}),t.jsx("div",{className:"model-benchmark__session-list",children:ze.length>0?ze.map(e=>{const s=Ht(e);return t.jsxs("div",{className:"model-benchmark__session-row",children:[t.jsxs("button",{type:"button",className:`model-benchmark__session-item ${e.id===h.activeSessionId?"model-benchmark__session-item--active":""}`,onClick:()=>C.setActiveSession(e.id),children:[t.jsx("span",{className:"model-benchmark__session-title",children:e.title}),t.jsx("span",{className:"model-benchmark__session-models",children:s.length>0?s.join(" / "):"暂无模型信息"}),t.jsxs("span",{className:"model-benchmark__session-meta",children:[ae[e.compareMode]," ·"," ",e.entries.length," 个目标 ·"," ",Re[e.status]]})]}),t.jsx("button",{type:"button",className:"model-benchmark__session-delete",onClick:()=>void mt(e),"aria-label":`删除会话 ${e.title}`,children:t.jsx(Ee,{content:"删除会话",showArrow:!1,children:t.jsx("span",{children:t.jsx(It,{})})})})]},e.id)}):t.jsx("div",{className:"model-benchmark__session-empty",children:h.sessions.length===0?"暂无历史会话":"没有匹配的历史会话"})})]}),t.jsx("main",{className:"model-benchmark__main",children:t.jsxs("div",{className:"model-benchmark__main-shell",children:[t.jsxs("section",{className:"model-benchmark__config-dashboard",children:[t.jsxs("div",{className:"model-benchmark__config-row model-benchmark__config-row--top",children:[t.jsx("div",{className:"model-benchmark__modality-tabs",children:Object.keys(le).map(e=>t.jsx("button",{type:"button",className:m===e?"active":"",onClick:()=>{m!==e&&j("modality",{previousModality:m,modality:e}),Pe(e)},children:le[e]},e))}),t.jsx("div",{className:"model-benchmark__mode-selector",children:Object.entries(ae).map(([e,s])=>t.jsx(Ee,{content:Ot[e],placement:"top",children:t.jsx("button",{type:"button",className:u===e?"active":"",onClick:()=>{const d=e;u!==d&&j("compare_mode",{modality:m,previousCompareMode:u,compareMode:d}),Te(d)},children:s})},e))})]}),t.jsxs("div",{className:"model-benchmark__config-main",children:[t.jsxs("div",{className:"model-benchmark__config-controls",children:[t.jsxs("div",{className:"model-benchmark__primary-select-row",children:[u==="cross-model"?t.jsx(re,{className:"model-benchmark__select",label:"目标供应商: ",value:v,onChange:e=>{const s=e;j("target_profile",{modality:m,compareMode:u,previousProfileId:v,profileId:s}),de(s)},options:N.map(e=>({label:e.name,value:e.id}))}):null,u==="cross-provider"?t.jsx(re,{filterable:!0,className:"model-benchmark__select",label:"对比模型: ",value:R,options:_t,placeholder:"搜索并选择要横向对比的模型",onChange:e=>{const s=e||"";j("target_model",{modality:m,compareMode:u,previousModelId:R,modelId:s}),me(s)}}):null]}),t.jsxs("div",{className:"model-benchmark__secondary-select-row",children:[u==="cross-provider"?t.jsx(re,{multiple:!0,filterable:!0,minCollapsedNum:3,popupProps:{overlayClassName:"model-benchmark__select-popup"},panelTopContent:t.jsxs("div",{className:"model-benchmark__select-actions",children:[t.jsx("button",{type:"button",onClick:()=>{const e=Ye.map(s=>s.value);j("provider_selection",{modality:m,compareMode:u,selectionAction:"select_all",selectedCount:e.length}),Y(e)},children:"全选"}),t.jsx("button",{type:"button",onClick:()=>{j("provider_selection",{modality:m,compareMode:u,selectionAction:"clear",selectedCount:0}),Y([])},children:"清除"})]}),className:"model-benchmark__multi-select",label:"参测供应商: ",value:z,options:Ye,placeholder:"多选要参与对比的供应商 (已选即为批测队列)",onChange:e=>{const s=Array.isArray(e)?e:[];j("provider_selection",{modality:m,compareMode:u,selectionAction:"change",previousSelectedCount:z.length,selectedCount:s.length}),Y(s)}}):null,u==="cross-model"?t.jsx(re,{multiple:!0,filterable:!0,minCollapsedNum:3,popupProps:{overlayClassName:"model-benchmark__select-popup"},panelTopContent:t.jsxs("div",{className:"model-benchmark__select-actions",children:[t.jsx("button",{type:"button",onClick:()=>{const e=D.map(s=>s.id);j("model_selection",{modality:m,compareMode:u,selectionAction:"select_all",selectedCount:e.length}),K(e)},children:"全选"}),t.jsx("button",{type:"button",onClick:()=>{j("model_selection",{modality:m,compareMode:u,selectionAction:"clear",selectedCount:0}),K([])},children:"清除"})]}),className:"model-benchmark__multi-select",label:"参测模型: ",value:F,options:D.map(e=>({label:st(e),value:e.id})),placeholder:"多选要测试的模型 (已选即为批测队列)",onChange:e=>{const s=Array.isArray(e)?e:[];j("model_selection",{modality:m,compareMode:u,selectionAction:"change",previousSelectedCount:F.length,selectedCount:s.length}),K(s)}}):null,u==="custom"?t.jsx(re,{multiple:!0,filterable:!0,minCollapsedNum:3,popupProps:{overlayClassName:"model-benchmark__select-popup"},panelTopContent:t.jsxs("div",{className:"model-benchmark__select-actions",children:[t.jsx("button",{type:"button",onClick:()=>{const e=P.map(s=>s.selectionKey);j("custom_selection",{modality:m,compareMode:u,selectionAction:"select_all",selectedCount:e.length}),H(e)},children:"全选"}),t.jsx("button",{type:"button",onClick:()=>{j("custom_selection",{modality:m,compareMode:u,selectionAction:"clear",selectedCount:0}),H([])},children:"清除"})]}),className:"model-benchmark__multi-select",label:"目标组合: ",value:q,options:P.map(e=>({label:`${e.profileName} · ${e.modelLabel}`,value:e.selectionKey})),placeholder:"手动编排供应商与模型组合",onChange:e=>{const s=Array.isArray(e)?e:[];j("custom_selection",{modality:m,compareMode:u,selectionAction:"change",previousSelectedCount:q.length,selectedCount:s.length}),H(s)}}):null]})]}),t.jsxs("div",{className:"model-benchmark__config-actions",children:[t.jsxs("div",{className:"model-benchmark__prompt-area",children:[t.jsx("textarea",{value:ue,onChange:e=>ke(e.target.value),placeholder:"在此输入测试提示词..."}),t.jsx(Vt,{value:Ke,onChange:lt,className:"model-benchmark__knowledge-context"})]}),t.jsxs("div",{className:"model-benchmark__action-row-inline",children:[t.jsxs("div",{className:"model-benchmark__concurrency",children:[t.jsx("span",{children:"最大并发:"}),t.jsx("input",{type:"text",inputMode:"numeric","aria-label":"最大并发",value:Ve,onChange:e=>{const s=e.target.value.replace(/\D/g,""),d=Number(s);at(Math.min(Mt,Math.max(1,d||1)))}})]}),t.jsx("button",{type:"button",className:"model-benchmark__primary-button",onClick:ht,disabled:we||!h.ready||T.length===0||!ue.trim(),children:we?"测试中...":`开始测试 (${T.length})`})]})]})]})]}),t.jsx("div",{className:"model-benchmark__main-head",children:t.jsxs("div",{children:[t.jsx("div",{className:"model-benchmark__eyebrow",children:g?ae[g.compareMode]:"Result Board"}),t.jsx("h3",{children:g?g.title:"还没有测试结果"}),g?t.jsxs("p",{className:"model-benchmark__main-desc",children:[Z.total," 个目标",Z.completed>0?`,${Z.completed} 成功`:"",Z.failed>0?`,${Z.failed} 失败`:""," · ",Re[g.status]," · ",Bt[g.rankingMode]]}):t.jsx("p",{className:"model-benchmark__main-desc",children:"请先在上方明确范围,或点击历史会话查看以往结果。"})]})}),g?t.jsxs(t.Fragment,{children:[M?t.jsxs("section",{className:"model-benchmark__spotlight",children:[t.jsxs("div",{className:"model-benchmark__spotlight-copy",children:[t.jsx("div",{className:"model-benchmark__eyebrow",children:"当前第一名"}),t.jsx("h4",{children:g.compareMode==="cross-provider"?M.profileName:M.modelLabel}),t.jsxs("p",{children:[g.compareMode==="cross-provider"?`${M.modelLabel},`:`来自 ${M.profileName},`,"首响 ",ve(M.firstResponseMs),",总耗时 ",ve(M.totalDurationMs)]})]}),t.jsxs("div",{className:"model-benchmark__spotlight-meta",children:[M.userScore?t.jsxs("span",{children:[M.userScore," 分"]}):null,M.favorite?t.jsx("span",{children:"已收藏"}):null]})]}):null,t.jsx("div",{className:"model-benchmark__result-grid",children:Xe.map((e,s)=>t.jsxs("article",{className:`model-benchmark__result-card model-benchmark__result-card--${e.status}`,children:[t.jsxs("header",{className:"model-benchmark__result-head",children:[t.jsxs("div",{className:"model-benchmark__result-rank",children:["#",s+1]}),t.jsxs("div",{className:"model-benchmark__result-heading",children:[t.jsx("div",{className:"model-benchmark__result-title",children:e.modelLabel}),t.jsx("div",{className:"model-benchmark__result-subtitle",children:e.profileName})]}),t.jsx("span",{className:`model-benchmark__status model-benchmark__status--${e.status}`,children:e.status==="completed"?"完成":e.status==="failed"?"失败":e.status==="running"?"测试中":"等待中"})]}),t.jsxs("div",{className:"model-benchmark__result-metrics",children:[t.jsxs("span",{children:["首响 ",ve(e.firstResponseMs)]}),t.jsxs("span",{children:["总耗时 ",ve(e.totalDurationMs)]}),t.jsxs("span",{children:["成本"," ",e.estimatedCost===null?"未知":`¥${e.estimatedCost.toFixed(4)}`]}),t.jsxs("span",{children:["性价比"," ",(()=>{const d=Et(e);return d===null?"—":`${d}/10`})()]})]}),t.jsx("div",{className:"model-benchmark__preview",children:bt(e)}),e.errorSummary?t.jsx("div",{className:"model-benchmark__error",children:e.errorSummary}):null,t.jsxs("div",{className:"model-benchmark__feedback",children:[t.jsx("div",{className:"model-benchmark__score-row",children:[1,2,3,4,5].map(d=>t.jsxs("button",{type:"button",className:`model-benchmark__score-chip ${e.userScore===d?"model-benchmark__score-chip--active":""}`,onClick:()=>C.setEntryFeedback(g.id,e.id,{userScore:e.userScore===d?null:d}),children:[d,"分"]},d))}),t.jsxs("div",{className:"model-benchmark__action-row",children:[t.jsx("button",{type:"button",className:`model-benchmark__ghost-button ${e.favorite?"model-benchmark__ghost-button--active":""}`,onClick:()=>C.setEntryFeedback(g.id,e.id,{favorite:!e.favorite}),children:"收藏"}),t.jsx("button",{type:"button",className:`model-benchmark__ghost-button ${e.rejected?"model-benchmark__ghost-button--danger":""}`,onClick:()=>C.setEntryFeedback(g.id,e.id,{rejected:!e.rejected}),children:"淘汰"})]})]})]},e.id))})]}):t.jsx("div",{className:"model-benchmark__empty",children:"先在左侧选定“同供应商多模型”或“同模型跨供应商”,把批测目标编满后再开跑。"})]})}),i]})}export{rs as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{e0 as qe,r as a,
|
|
2
|
-
`),O=X.createTask({prompt:`分析音频:${g.name||"本地音频"}`,model:L,modelRef:ee,mimeType:l.mimeType,audioCacheUrl:l.cacheUrl,musicAnalyzerAction:"analyze",musicAnalyzerPrompt:p,musicAnalyzerMusicBrief:U(v),musicAnalyzerSource:"upload",musicAnalyzerSourceLabel:l.fileName,musicAnalyzerSourceSnapshot:l,autoInsertToCanvas:!1},q.CHAT);h(O.id),K("音频分析中 0%")}catch(l){Y.current=!1,A(l.message||"音频分析失败")}}},[g,v,d,L,ee]),he=a.useCallback(async()=>{if(ne.current||y)return;if(!u.trim()){A("请先描述你想创作的歌曲");return}ne.current=!0;const l=Je(z);ge.trackUIInteraction({area:"popular_music_tool",action:"lyrics_generation_started",control:"generate_lyrics",source:"music_analyzer_create_page",metadata:{engine:l?"suno":"text_model",promptLength:u.trim().length,hasModelRef:!!se}}),A(""),m(l?"歌词生成中...":"歌词草稿生成中 0%");try{const f={id:ys(),createdAt:Date.now(),source:"scratch",sourceLabel:u.slice(0,30)||"从零创作",creationPrompt:u,musicBrief:U(v),styleTags:fs(v),starred:!1},p=l?X.createTask({prompt:Xe({userPrompt:u,musicBrief:v,mode:"create"}),model:z,modelRef:se,sunoAction:"lyrics",musicAnalyzerAction:"lyrics-gen",musicAnalyzerRecordId:f.id,musicAnalyzerMusicBrief:U(v),knowledgeContextRefs:T,autoInsertToCanvas:!1},q.AUDIO):X.createTask({prompt:`从零创作歌词:${f.sourceLabel}`,model:z,modelRef:se,musicAnalyzerAction:"lyrics-gen",musicAnalyzerPrompt:Ze({userPrompt:u,musicBrief:v,mode:"create"}),musicAnalyzerRecordId:f.id,musicAnalyzerMusicBrief:U(v),knowledgeContextRefs:T,autoInsertToCanvas:!1},q.CHAT);f.pendingLyricsGenTaskId=p.id;const O=await gs(f);i(O),n(f),Q(p.id)}catch(f){ne.current=!1,A(f.message||"歌词生成失败"),m("")}},[u,T,v,n,i,y,z,se]);a.useEffect(()=>{if(!d)return;const l=X.getTask(d);typeof(l==null?void 0:l.progress)=="number"&&K(`音频分析中 ${Math.round(l.progress)}%`);const f=X.observeTaskUpdates().subscribe(p=>{var O;if(p.task.id===d){if(p.task.status==="failed"){Y.current=!1,h(null),K(""),A(((O=p.task.error)==null?void 0:O.message)||"音频分析失败");return}if(p.task.status==="completed"){Ue(p.task).then(B=>{B&&(i(B.records),n(B.record))}).catch(B=>A(B.message||"分析结果同步失败")).finally(()=>{Y.current=!1,h(null),K("")});return}typeof p.task.progress=="number"&&K(`音频分析中 ${Math.round(p.task.progress)}%`)}});return()=>f.unsubscribe()},[d,n,i]),a.useEffect(()=>{if(!y)return;const l=X.getTask(y);if(typeof(l==null?void 0:l.progress)=="number"){const p=l.type===q.CHAT?"歌词草稿生成中":"歌词生成中";m(`${p} ${Math.round(l.progress)}%`)}const f=X.observeTaskUpdates().subscribe(p=>{var O;if(p.task.id===y){if(p.task.status==="failed"){const B=String(p.task.params.musicAnalyzerRecordId||"").trim();ne.current=!1,Q(null),m(""),A(((O=p.task.error)==null?void 0:O.message)||"歌词生成失败"),B&&oe(B,{pendingLyricsGenTaskId:null}).then(i);return}if(p.task.status==="completed"){ne.current=!1,Q(null),m(""),M==null||M();return}if(typeof p.task.progress=="number"){const B=p.task.type===q.CHAT?"歌词草稿生成中":"歌词生成中";m(`${B} ${Math.round(p.task.progress)}%`)}}});return()=>f.unsubscribe()},[M,i,y]);const Ce=a.useCallback(async()=>{E&&(await es("text",js(E)),ge.trackUIInteraction({area:"popular_music_tool",action:"analysis_inserted_to_canvas",control:"insert_analysis",source:"music_analyzer_create_page",metadata:{hasSunoTitle:!!E.sunoTitle,tagsCount:E.sunoStyleTags.length}}))},[E]);return e.jsxs("div",{className:"ma-create-page",children:[e.jsxs("div",{className:"ma-mode-toggle",children:[e.jsx("button",{className:`ma-mode-btn ${x==="scratch"?"active":""}`,onClick:()=>I("scratch"),children:"从零创作"}),e.jsx("button",{className:`ma-mode-btn ${x==="reference"?"active":""}`,onClick:()=>I("reference"),children:"参考音频"})]}),e.jsxs("div",{className:"va-page",children:[x==="scratch"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"ma-card",children:e.jsx(Le,{value:v,onChange:D})}),e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"描述你想创作的歌曲"}),e.jsx(zs,{className:"ma-icon-btn",originalPrompt:u,language:"zh",scenarioId:"music.create-song",onApply:P})]}),e.jsx("textarea",{className:"ma-textarea",value:u,onChange:l=>P(l.target.value),rows:6,placeholder:"例如:一首关于夏天海边的轻快流行歌,女声,带有吉他和电子节拍"}),e.jsx($e,{value:T,onChange:F,disabled:!!y,className:"ma-knowledge-context-selector",placement:"up"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"上传音频"}),g&&e.jsx("span",{className:"ma-muted",children:Fs(g.size)})]}),e.jsx("div",{className:"va-dropzone ma-dropzone",onClick:()=>{var l;return(l=te.current)==null?void 0:l.click()},onDragOver:l=>l.preventDefault(),onDrop:ve,children:g?e.jsxs("div",{className:"ma-audio-preview",children:[e.jsxs("div",{className:"ma-audio-preview__meta",children:[e.jsx("strong",{children:g.name}),e.jsx("button",{className:"va-nav-btn",onClick:l=>{l.stopPropagation(),j(null),A(""),te.current&&(te.current.value="")},children:"清空"})]}),w&&e.jsx("audio",{controls:!0,src:w})]}):e.jsxs("div",{className:"ma-dropzone__placeholder",children:[e.jsx("span",{children:"点击或拖拽上传本地音频"}),e.jsx("small",{children:"支持 mp3、wav、m4a 等常见格式"})]})}),e.jsx("input",{ref:te,type:"file",accept:"audio/*",hidden:!0,onChange:Te})]}),e.jsx("div",{className:"ma-card",children:e.jsx(Le,{value:v,onChange:D})}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"分析模型"})}),e.jsx(Ne,{selectedModel:L,selectedSelectionKey:Ie(L,ee),onSelect:N,models:ce,variant:"form",placement:"down",placeholder:"选择 Gemini 分析模型"})]})]}),E&&x==="reference"&&e.jsxs("div",{className:"ma-card",children:[e.jsxs("button",{className:"ma-section-toggle",onClick:()=>J(l=>!l),children:[e.jsx("span",{children:"分析摘要"}),e.jsx("span",{children:S?"收起":"展开"})]}),S&&e.jsxs("div",{className:"ma-analysis-summary",children:[e.jsx("p",{children:E.summary}),e.jsxs("div",{className:"ma-chip-row",children:[e.jsx("span",{className:"ma-chip",children:E.language||"未知语言"}),e.jsx("span",{className:"ma-chip",children:E.mood||"未知情绪"}),E.genreTags.map(l=>e.jsx("span",{className:"ma-chip ma-chip--accent",children:l},l))]}),e.jsx("div",{className:"ma-tag-row",children:E.structure.map(l=>e.jsx("code",{children:l},l))}),E.titleSuggestions.length>0&&e.jsxs("div",{className:"ma-suggestions",children:["推荐标题:",E.titleSuggestions.join(" / ")]}),(E.sunoTitle||E.sunoStyleTags.length>0||E.sunoLyricsDraft)&&e.jsxs("div",{className:"ma-suno-summary",children:[e.jsx("div",{className:"ma-suno-summary__title",children:"Suno 生成草稿"}),e.jsxs("div",{className:"ma-suno-summary__form",children:[e.jsxs("label",{className:"ma-suno-summary__field",children:[e.jsx("span",{children:"歌曲标题"}),e.jsx("input",{className:"ma-input",value:G,onChange:l=>de(l.target.value),placeholder:"可直接用于 Suno 的标题"})]}),e.jsxs("label",{className:"ma-suno-summary__field",children:[e.jsx("span",{children:"Suno 风格标签"}),e.jsx("input",{className:"ma-input",value:V,onChange:l=>Z(l.target.value),placeholder:"逗号分隔的风格标签"})]}),e.jsxs("label",{className:"ma-suno-summary__field",children:[e.jsx("span",{children:"带 Suno 标签的歌词草稿"}),e.jsx("textarea",{className:"ma-textarea",rows:12,value:re,onChange:l=>me(l.target.value),placeholder:"分析阶段整理出的可用歌词草稿"})]})]})]})]})]}),(ie||k||r)&&e.jsxs("div",{className:"ma-status-stack",children:[ie&&e.jsx("div",{className:"ma-error",children:ie}),k&&e.jsx("div",{className:"ma-progress",children:k}),r&&e.jsx("div",{className:"ma-progress",children:r})]}),e.jsx("div",{className:`va-page-actions ${x==="scratch"?"ma-lyrics-submit-row":""}`,children:x==="scratch"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"ma-lyrics-model-inline",children:[e.jsx("span",{className:"ma-inline-label",children:"歌词模型"}),e.jsx(Ne,{selectedModel:z,selectedSelectionKey:Ie(z,se),onSelect:t,models:ae,variant:"form",placement:"up",placeholder:"选择歌词模型"})]}),e.jsx("button",{className:"va-btn-primary",onClick:he,disabled:!u.trim()||!!y,children:"生成歌词"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:b,children:"新建"}),e.jsx("button",{onClick:Ce,disabled:!(s!=null&&s.analysis),children:"插入分析"}),e.jsx("button",{className:"va-btn-primary",onClick:ke,disabled:!g||!!d,children:"开始分析"}),e.jsx("button",{onClick:o,disabled:!s,children:"下一步"})]})})]})]})},Ee="music-analyzer:model",Ve="gemini-2.5-pro",Vs=({record:s,onRecordUpdate:n,onRecordsChange:i,onNext:b})=>{var $,z,H,se;const[o,M]=a.useState(()=>Fe(s)),[x,I]=a.useState([]),[u,P]=a.useState(s.lyricsDraft||""),[T,F]=a.useState(s.title||((z=($=s.analysis)==null?void 0:$.titleSuggestions)==null?void 0:z[0])||""),[v,D]=a.useState((s.styleTags||((H=s.analysis)==null?void 0:H.genreTags)||[]).join(", ")),[y,Q]=a.useState(()=>U(s.musicBrief)),[r,m]=a.useState(()=>s.pendingRewriteTaskId||null),[g,j]=a.useState(""),[d,h]=a.useState(""),[k,K]=a.useState(()=>s.analysisModel||pe(Ee,Ve).modelId),[S,J]=a.useState(()=>s.analysisModelRef||pe(Ee,Ve).modelRef),[G,de]=a.useState(!1),V=a.useRef(),Z=a.useRef(!1),re=a.useCallback((c,N)=>{K(c),J(N||null),Se(Ee,c,N)},[]);a.useEffect(()=>{var c,N,t;M(Fe(s)),P(s.lyricsDraft||""),F(s.title||((N=(c=s.analysis)==null?void 0:c.titleSuggestions)==null?void 0:N[0])||""),D((s.styleTags||((t=s.analysis)==null?void 0:t.genreTags)||[]).join(", ")),Q(w=>{const _=U(s.musicBrief);return xe(w,_)?w:_}),m(s.pendingRewriteTaskId||null)},[s]),a.useEffect(()=>(clearTimeout(V.current),V.current=setTimeout(async()=>{const c=v.split(",").map(t=>t.trim()).filter(Boolean),N=await oe(s.id,{rewritePrompt:o,lyricsDraft:u,title:T,styleTags:c,musicBrief:U(y),pendingRewriteTaskId:r});i(N),n({...s,rewritePrompt:o,lyricsDraft:u,title:T,styleTags:c,musicBrief:U(y),pendingRewriteTaskId:r})},400),()=>clearTimeout(V.current)),[u,y,n,i,r,s.id,o,v,T]);const me=je("text"),te=je("audio"),C=a.useMemo(()=>Qe(me,te),[me,te]),R=a.useMemo(()=>Je(k),[k]),Y=a.useMemo(()=>{const c=[{id:Ke,label:"原始版本"}];for(const N of s.lyricsVersions||[])c.push({id:N.id,label:N.label});return c},[s.lyricsVersions]),ne=s.activeVersionId||Ke,ie=Y.length>1,A=String(s.creationPrompt||"").trim(),L=a.useCallback(async c=>{const N=vs(s,c);if(!N)return;const t=await oe(s.id,N);i(t),n({...s,...N}),de(!1)},[n,i,s]),le=a.useCallback(async()=>{if(!(Z.current||r)){Z.current=!0,h(""),j(R?"歌词生成中...":"歌词改写中 0%"),ge.trackUIInteraction({area:"popular_music_tool",action:"lyrics_rewrite_started",control:"rewrite_lyrics",source:"music_analyzer_lyrics_page",metadata:{engine:R?"suno":"text_model",hasRewritePrompt:!!o.trim(),lyricsLength:u.trim().length}});try{let c;if(R){const t=Xe({userPrompt:o,originalPrompt:A,currentLyrics:u,musicBrief:y,mode:"rewrite"});c=X.createTask({prompt:t,model:k,modelRef:S||null,sunoAction:"lyrics",musicAnalyzerAction:"lyrics-gen",musicAnalyzerRecordId:s.id,musicAnalyzerMusicBrief:U(y),knowledgeContextRefs:x,autoInsertToCanvas:!1},q.AUDIO)}else c=X.createTask({prompt:`改写歌词:${s.sourceLabel}`,model:k,modelRef:S||null,musicAnalyzerAction:"rewrite",musicAnalyzerPrompt:Ze({analysis:s.analysis,userPrompt:o,originalPrompt:A,currentLyrics:u,musicBrief:y}),musicAnalyzerRecordId:s.id,musicAnalyzerMusicBrief:U(y),knowledgeContextRefs:x,autoInsertToCanvas:!1},q.CHAT);m(c.id);const N=await oe(s.id,{rewritePrompt:o,musicBrief:U(y),pendingRewriteTaskId:c.id});i(N),n({...s,rewritePrompt:o,musicBrief:U(y),pendingRewriteTaskId:c.id})}catch(c){Z.current=!1,h(c.message||"歌词改写失败"),j("")}}},[A,u,n,i,s,o,k,S,R,x,y,r]);a.useEffect(()=>{if(!r)return;const c=X.getTask(r);typeof(c==null?void 0:c.progress)=="number"&&j(`歌词改写中 ${Math.round(c.progress)}%`);const N=X.observeTaskUpdates().subscribe(t=>{var w;if(t.task.id===r){if(t.task.status==="failed"){Z.current=!1,m(null),j(""),h(((w=t.task.error)==null?void 0:w.message)||"歌词改写失败"),oe(s.id,{pendingRewriteTaskId:null}).then(i);return}if(t.task.status==="completed"){Ue(t.task).then(_=>{_&&(i(_.records),n(_.record),P(_.record.lyricsDraft||""),F(_.record.title||""),D((_.record.styleTags||[]).join(", ")))}).catch(_=>{h(_.message||"改写结果同步失败")}).finally(()=>{Z.current=!1,m(null),j("")});return}typeof t.task.progress=="number"&&j(`歌词改写中 ${Math.round(t.task.progress)}%`)}});return()=>N.unsubscribe()},[n,i,r,s.id]);const ee=a.useCallback(async()=>{const c=await es("text",xs({title:T,styleTags:v.split(",").map(N=>N.trim()).filter(Boolean),lyricsDraft:u}));if(!c.success){h(c.error||"插入失败,请确认画布已打开");return}ge.trackUIInteraction({area:"popular_music_tool",action:"lyrics_inserted_to_canvas",control:"insert_lyrics",source:"music_analyzer_lyrics_page",metadata:{lyricsLength:u.trim().length,tagsCount:v.split(",").filter(N=>N.trim()).length}})},[u,v,T]);return e.jsxs("div",{className:"va-page",children:[e.jsx("div",{className:"ma-card",children:e.jsx(Le,{value:y,onChange:Q})}),e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"改写要求"}),ie&&e.jsxs("div",{className:"ma-version-dropdown",children:[e.jsxs("button",{className:"ma-version-btn",onClick:()=>de(c=>!c),children:[((se=Y.find(c=>c.id===ne))==null?void 0:se.label)||"原始版本",e.jsx("span",{className:"ma-version-arrow",children:G?"▲":"▼"})]}),G&&e.jsx("div",{className:"ma-version-menu",children:Y.map(c=>e.jsx("button",{className:`ma-version-menu-item ${c.id===ne?"active":""}`,onClick:()=>L(c.id),children:c.label},c.id))})]})]}),e.jsx("textarea",{className:"ma-textarea",value:o,onChange:c=>M(c.target.value),rows:4,placeholder:"告诉 AI 要保留什么、强化什么、改成什么风格"}),e.jsx($e,{value:x,onChange:I,disabled:!!r,className:"ma-knowledge-context-selector",placement:"up"}),e.jsxs("div",{className:"ma-lyrics-submit-row ma-lyrics-submit-row--rewrite",children:[e.jsxs("div",{className:"ma-lyrics-model-inline",children:[e.jsx("span",{className:"ma-inline-label",children:"歌词模型"}),e.jsx(Ne,{selectedModel:k,selectedSelectionKey:Ie(k,S),onSelect:re,models:C,variant:"form",placement:"up",placeholder:"选择歌词模型"})]}),e.jsx("button",{className:"va-btn-primary ma-rewrite-submit",onClick:le,disabled:!!r,children:r?g||(R?"歌词生成中...":"歌词改写中..."):R?"Suno 生成歌词":"AI 改写"})]}),g&&e.jsx("div",{className:"ma-progress",children:g})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"歌曲标题"})}),e.jsx("input",{className:"ma-input",value:T,onChange:c=>F(c.target.value),placeholder:"歌曲标题"})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"Suno 风格标签"})}),e.jsx("input",{className:"ma-input",value:v,onChange:c=>D(c.target.value),placeholder:"例如 cinematic pop, female vocal, uplifting"})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"歌词草稿"})}),e.jsx("textarea",{className:"ma-textarea",value:u,onChange:c=>P(c.target.value),rows:14,placeholder:"AI 改写结果会出现在这里,可继续手改"})]}),d&&e.jsx("div",{className:"ma-error",children:d}),e.jsxs("div",{className:"va-page-actions",children:[e.jsx("button",{onClick:ee,disabled:!u.trim(),children:"插入歌词"}),e.jsx("button",{className:"va-btn-primary",onClick:b,disabled:!u.trim(),children:"下一步"})]})]})},ze="music-analyzer:audio-model",Be=[{id:"generate",label:"新生成",hint:"从零生成完整音乐"},{id:"continue",label:"续写",hint:"从已有片段继续创作"},{id:"infill",label:"Infill",hint:"局部重绘指定时间窗口"}];function fe(s){const n=s.trim();if(!n)return null;const i=Number(n);return Number.isFinite(i)?i:null}function ye(s){return typeof s=="number"&&Number.isFinite(s)?String(s):""}function Pe(s){return s.split(",").map(n=>n.trim()).filter(Boolean)}function Ye(s){var n;return((n=Be.find(i=>i.id===s))==null?void 0:n.label)||"新生成"}function Ys(s){return typeof s.duration=="number"&&Number.isFinite(s.duration)?String(Math.max(0,Math.round(s.duration))):""}function We(s){const n=s.title||"未命名片段",i=s.duration!=null?` · ${ss(s.duration)}`:"",b=s.clipId?` · ${s.clipId.slice(0,8)}`:"";return`${n}${i}${b}`}const Ws=({record:s,onRecordUpdate:n,onRecordsChange:i,onRestart:b})=>{var N;const[o,M]=a.useState(s.title||""),[x,I]=a.useState((s.styleTags||[]).join(", ")),[u,P]=a.useState(s.lyricsDraft||""),[T,F]=a.useState([]),[v,D]=a.useState("chirp-v5-5"),[y,Q]=a.useState(1),[r,m]=a.useState(()=>pe(ze,be()).modelId),[g,j]=a.useState(()=>pe(ze,be()).modelRef),[d,h]=a.useState(s.musicEditAction||"generate"),[k,K]=a.useState(s.continueFromClipId||""),[S,J]=a.useState(ye(s.continueAt)),[G,de]=a.useState(ye(s.infillStartS)),[V,Z]=a.useState(ye(s.infillEndS)),[re,me]=a.useState(!1),[te,C]=a.useState(""),R=a.useRef(),Y=a.useRef(!1),ne=a.useCallback((t,w)=>{m(t),j(w||null),Se(ze,t,w)},[]);a.useEffect(()=>{M(s.title||""),I((s.styleTags||[]).join(", ")),P(s.lyricsDraft||""),h(s.musicEditAction||"generate"),K(s.continueFromClipId||""),J(ye(s.continueAt)),de(ye(s.infillStartS)),Z(ye(s.infillEndS))},[s]),a.useEffect(()=>(clearTimeout(R.current),R.current=setTimeout(async()=>{const t=Pe(x),w=fe(S),_=fe(G),ce=fe(V),W={title:o,styleTags:t,lyricsDraft:u,musicEditAction:d,continueFromClipId:k||null,continueAt:w,infillStartS:_,infillEndS:ce},ae=await oe(s.id,W);i(ae),n({...s,...W})},400),()=>clearTimeout(R.current)),[d,S,k,V,G,n,i,u,s.id,x,o]);const ie=je("audio"),A=a.useMemo(()=>ie.filter(t=>{const w=Array.isArray(t.tags)?t.tags.join(" "):"";return/suno/i.test(t.id)||/suno/i.test(w)}),[ie]),L=a.useMemo(()=>Ss(r).find(t=>t.id==="mv"),[r]);a.useEffect(()=>{L!=null&&L.defaultValue&&D(t=>t||String(L.defaultValue))},[L==null?void 0:L.defaultValue]);const le=s.generatedClips||[],ee=a.useMemo(()=>le.filter(t=>!!String(t.clipId||"").trim()),[le]),$=a.useMemo(()=>ee.find(t=>t.clipId===k)||null,[k,ee]),z=d!=="generate",H=d==="infill",se=a.useCallback((t,w)=>{if(!t.clipId){C("该片段尚未拿到真实 clip_id,暂时不能继续创作");return}h(w),K(t.clipId),J(_=>_||Ys(t)),C(w==="continue"?`已带入片段「${t.title||t.clipId.slice(0,8)}」用于续写`:`已带入片段「${t.title||t.clipId.slice(0,8)}」用于 Infill`)},[]),c=a.useCallback(async()=>{const t=u.trim(),w=o.trim(),_=x.trim(),ce=fe(S),W=fe(G),ae=fe(V);if(!t){C("请先准备歌词或生成提示词");return}if(z&&!k){C("请先选择要续写的片段");return}if(z&&!($!=null&&$.taskId)){C("当前片段缺少来源 task_id,请先重新同步或重新生成一次片段");return}if(z&&ce==null){C("请填写续写起点秒数");return}if(ce!=null&&ce<0){C("续写起点秒数不能小于 0");return}if(H&&W==null){C("请填写 Infill 开始秒数");return}if(H&&ae==null){C("请填写 Infill 结束秒数");return}if(W!=null&&W<0){C("Infill 开始秒数不能小于 0");return}if(ae!=null&&ae<0){C("Infill 结束秒数不能小于 0");return}if(H&&W!=null&&ae!=null&&W>=ae){C("Infill 开始秒数必须小于结束秒数");return}if(!Y.current){Y.current=!0,ge.trackUIInteraction({area:"popular_music_tool",action:"music_generation_started",control:"generate_music",source:"music_analyzer_generate_page",metadata:{editAction:d,batchCount:y,promptLength:t.length,hasTitle:!!w,tagsCount:Pe(_).length,hasMv:!!v,hasModelRef:!!g}}),me(!0),C("");try{const E=[],Te=d==="generate"?"gen":d;for(let he=0;he<y;he+=1){const Ce=X.createTask({prompt:t,model:r,modelRef:g,sunoAction:"music",title:w,tags:_,mv:v,continueClipId:z?k:void 0,continueTaskId:z?$==null?void 0:$.taskId:void 0,continueAt:z?ce??void 0:void 0,infillStartS:H?W??void 0:void 0,infillEndS:H?ae??void 0:void 0,knowledgeContextRefs:T,batchId:`ma_${s.id}_${Te}_${he}`,batchIndex:he,batchTotal:y,autoInsertToCanvas:!0},q.AUDIO);E.push(Ce.id)}const ve={generateTaskIds:[...s.generateTaskIds||[],...E],title:w,styleTags:Pe(_),lyricsDraft:t,musicEditAction:d,continueFromClipId:k||null,continueAt:ce,infillStartS:W,infillEndS:ae},ke=await oe(s.id,ve);i(ke),n({...s,...ve}),C(`已提交 ${y} 次${Ye(d)}任务到 Suno 队列`)}catch(E){C(E.message||"提交生成任务失败")}finally{me(!1),Y.current=!1}}},[d,y,S,k,V,G,T,v,n,i,u,s,z,H,$==null?void 0:$.taskId,r,g,x,o]);return e.jsxs("div",{className:"va-page",children:[e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"创作动作"}),e.jsx("span",{className:"ma-muted",children:(N=Be.find(t=>t.id===d))==null?void 0:N.hint})]}),e.jsx("div",{className:"ma-action-toggle",children:Be.map(t=>e.jsx("button",{className:`ma-action-btn ${d===t.id?"active":""}`,onClick:()=>h(t.id),children:t.label},t.id))})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"Suno 模型"})}),e.jsx(Ne,{selectedModel:r,selectedSelectionKey:Ie(r,g),onSelect:ne,models:A.length>0?A:ie,variant:"form",placement:"down",placeholder:"选择音频生成模型"})]}),(L==null?void 0:L.options)&&L.options.length>0&&e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"Suno 版本"})}),e.jsx("select",{className:"ma-select",value:v,onChange:t=>D(t.target.value),children:L.options.map(t=>e.jsx("option",{value:String(t.value),children:t.label},t.value))})]}),z&&e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"目标片段"}),e.jsx("span",{className:"ma-muted",children:"自动使用轮询得到的真实 clip_id"})]}),ee.length>0?e.jsxs("select",{className:"ma-select",value:k,onChange:t=>K(t.target.value),children:[e.jsx("option",{value:"",children:"请选择已生成片段"}),ee.map(t=>e.jsx("option",{value:t.clipId,children:We(t)},t.clipId))]}):e.jsx("div",{className:"ma-hint",children:"先生成至少一个片段,才能使用续写或 Infill。"}),$&&e.jsxs("div",{className:"ma-hint",children:["当前片段:",We($)]})]}),z&&e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"编辑参数"})}),e.jsxs("div",{className:`ma-fields-grid ${H?"ma-fields-grid--triple":""}`,children:[e.jsxs("label",{className:"ma-field",children:[e.jsx("span",{children:"续写起点秒数"}),e.jsx("input",{className:"ma-input",type:"number",min:"0",step:"0.1",value:S,onChange:t=>J(t.target.value),placeholder:"例如 30"})]}),H&&e.jsxs("label",{className:"ma-field",children:[e.jsx("span",{children:"Infill 开始秒数"}),e.jsx("input",{className:"ma-input",type:"number",min:"0",step:"0.1",value:G,onChange:t=>de(t.target.value),placeholder:"例如 8"})]}),H&&e.jsxs("label",{className:"ma-field",children:[e.jsx("span",{children:"Infill 结束秒数"}),e.jsx("input",{className:"ma-input",type:"number",min:"0",step:"0.1",value:V,onChange:t=>Z(t.target.value),placeholder:"例如 16"})]})]})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"歌曲标题"})}),e.jsx("input",{className:"ma-input",value:o,onChange:t=>M(t.target.value),placeholder:"歌曲标题"})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"风格标签"})}),e.jsx("input",{className:"ma-input",value:x,onChange:t=>I(t.target.value),placeholder:"逗号分隔,例如 edm, intense, female vocal"})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"提交给 Suno 的歌词/提示词"})}),e.jsx("textarea",{className:"ma-textarea",rows:10,value:u,onChange:t=>P(t.target.value),placeholder:"这里的内容会直接作为 prompt 提交给 Suno"}),e.jsx($e,{value:T,onChange:F,disabled:re,className:"ma-knowledge-context-selector",placement:"up"})]}),e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"调用次数"}),e.jsx("span",{className:"ma-muted",children:"每次返回 2 首"})]}),e.jsx("div",{className:"ma-batch-selector",children:[1,2,3,4].map(t=>e.jsxs("button",{className:`ma-batch-btn ${y===t?"active":""}`,onClick:()=>Q(t),children:[t," 次"]},t))})]}),le.length>0&&e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsxs("span",{children:["已生成片段 (",le.length,")"]}),e.jsx("span",{className:"ma-muted",children:"可直接带入续写或 Infill"})]}),e.jsx("div",{className:"ma-clips-gallery",children:le.map(t=>e.jsx(qs,{clip:t,selected:z&&!!t.clipId&&k===t.clipId,onContinue:()=>se(t,"continue"),onInfill:()=>se(t,"infill")},`${t.taskId}:${t.clipId||t.audioUrl}`))})]}),te&&e.jsx("div",{className:"ma-progress",children:te}),e.jsxs("div",{className:"va-page-actions",children:[e.jsx("button",{onClick:b,children:"重新开始"}),e.jsxs("button",{className:"va-btn-primary",onClick:c,disabled:re,children:[Ye(d)," ",y," 次"]})]})]})},qs=({clip:s,selected:n,onContinue:i,onInfill:b})=>{const o=!!String(s.clipId||"").trim();return e.jsxs("div",{className:`ma-clip-row ${n?"is-selected":""}`,children:[s.imageUrl?e.jsx("img",{className:"ma-clip-thumb",src:s.imageUrl,alt:"",referrerPolicy:"no-referrer"}):e.jsx("div",{className:"ma-clip-thumb ma-clip-thumb--placeholder",children:"♪"}),e.jsxs("div",{className:"ma-clip-meta",children:[e.jsx("span",{className:"ma-clip-title",children:s.title||"未命名"}),s.duration!=null&&e.jsx("span",{className:"ma-clip-duration",children:ss(s.duration)})]}),e.jsx("audio",{controls:!0,src:s.audioUrl,className:"ma-clip-player",preload:"metadata"}),e.jsxs("div",{className:"ma-clip-actions",children:[e.jsx("button",{className:"ma-clip-action-btn",onClick:i,disabled:!o,children:"续写"}),e.jsx("button",{className:"ma-clip-action-btn",onClick:b,disabled:!o,children:"Infill"})]})]})};function ss(s){const n=Math.floor(s/60),i=Math.round(s%60);return`${n}:${String(i).padStart(2,"0")}`}function Qs(s){switch(s){case ue.COMPLETED:return"已完成";case ue.PROCESSING:return"进行中";case ue.PENDING:return"等待中";case ue.FAILED:return"失败";default:return""}}function Js(s){switch(s){case ue.COMPLETED:return"completed";case ue.PROCESSING:return"processing";case ue.PENDING:return"pending";case ue.FAILED:return"failed";default:return"pending"}}function Xs(s){const n=new Date(s);return`${n.getMonth()+1}/${n.getDate()} ${String(n.getHours()).padStart(2,"0")}:${String(n.getMinutes()).padStart(2,"0")}`}function Zs(s){var b,o,M,x;const n=s.params.musicAnalyzerAction;if(n==="rewrite"){const I=(b=s.result)!=null&&b.analysisData&&typeof s.result.analysisData=="object"?s.result.analysisData:null,u=typeof(I==null?void 0:I.title)=="string"&&I.title.trim()?I.title.trim():"";if(u)return u}if(n==="lyrics-gen"){const I=(o=s.result)!=null&&o.analysisData&&typeof s.result.analysisData=="object"?s.result.analysisData:null,u=typeof(I==null?void 0:I.title)=="string"&&I.title.trim()?I.title.trim():"";if(u)return u;const P=typeof((M=s.result)==null?void 0:M.lyricsTitle)=="string"&&s.result.lyricsTitle.trim()?s.result.lyricsTitle.trim():typeof((x=s.result)==null?void 0:x.title)=="string"&&s.result.title.trim()?s.result.title.trim():"";if(P)return P}const i=String(s.params.prompt||"");return i.length>40?`${i.slice(0,40)}…`:i}const ea=({records:s,onSelect:n,onRecordsChange:i,showStarredOnly:b=!1,onSelectLyrics:o})=>{const M=b?s.filter(r=>r.starred):s,[x,I]=a.useState(null),[u,P]=a.useState(null),{tasks:T}=Ns(),F=a.useMemo(()=>{const r=new Map,m=new Set(s.map(j=>j.id)),g=()=>({rewrite:[],lyricsGen:[],audio:[]});for(const j of T){const d=j.params;if(j.type===q.CHAT&&d.musicAnalyzerAction==="rewrite"&&typeof d.musicAnalyzerRecordId=="string"&&m.has(d.musicAnalyzerRecordId)){const h=d.musicAnalyzerRecordId;Me(r,h,"rewrite",j,g);continue}if((j.type===q.AUDIO||j.type===q.CHAT)&&d.musicAnalyzerAction==="lyrics-gen"&&typeof d.musicAnalyzerRecordId=="string"&&m.has(d.musicAnalyzerRecordId)){const h=d.musicAnalyzerRecordId;Me(r,h,"lyricsGen",j,g);continue}if(j.type===q.AUDIO&&typeof d.batchId=="string"&&d.batchId.startsWith("ma_")){const h=bs(d.batchId,"ma_",m);h&&Me(r,h,"audio",j,g)}}return Is(r)},[T,s]),v=a.useCallback(async(r,m)=>{r.stopPropagation();const g=await oe(m.id,{starred:!m.starred});i(g)},[i]),D=a.useCallback((r,m)=>{r.stopPropagation(),P(m)},[]),y=a.useCallback(async()=>{if(!u)return;const r=await Ts(u);i(r),P(null)},[i,u]),Q=a.useCallback((r,m)=>{r.stopPropagation(),I(g=>g===m?null:m)},[]);return M.length===0?e.jsx("div",{className:"va-page va-empty",children:e.jsx("span",{children:b?"暂无收藏":"暂无分析记录"})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"va-page",children:e.jsx("div",{className:"va-history-list",children:M.map(r=>{var d;const m=F.get(r.id),g=!!(m&&m.rewrite.length+m.lyricsGen.length+m.audio.length>0),j=x===r.id;return e.jsxs("div",{className:"va-history-item",onClick:()=>n(r),children:[e.jsxs("div",{className:"va-history-header",children:[e.jsxs("span",{className:"va-history-source",children:[e.jsx("span",{role:"img","aria-label":"audio",children:r.source==="scratch"?"✨":"🎵"})," ",r.sourceLabel]}),e.jsx("button",{className:`va-star-btn ${r.starred?"starred":""}`,onClick:h=>v(h,r),children:r.starred?"★":"☆"})]}),e.jsxs("div",{className:"va-history-meta",children:[g&&e.jsxs("button",{className:`va-history-expand-btn ${j?"expanded":""}`,onClick:h=>Q(h,r.id),children:[e.jsx(ks,{size:12}),e.jsx("span",{children:j?"收起":"关联任务"})]}),e.jsx("span",{children:new Date(r.createdAt).toLocaleString()}),e.jsx("span",{children:r.analysisModel||r.source}),e.jsx("button",{className:"va-history-delete",onClick:h=>D(h,r.id),children:"删除"})]}),e.jsx("div",{className:"ma-history-title",children:r.title||"未命名歌曲"}),e.jsx("div",{className:"ma-history-summary",children:((d=r.analysis)==null?void 0:d.summary)||r.creationPrompt||"暂无摘要"}),r.generatedClips&&r.generatedClips.length>0&&e.jsxs("div",{className:"ma-history-clips-count",children:[r.generatedClips.length," 首已生成"]}),j&&m&&e.jsxs("div",{className:"va-history-related",onClick:h=>h.stopPropagation(),children:[m.lyricsGen.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"va-history-related-group-title",children:["歌词生成 (",m.lyricsGen.length,")"]}),m.lyricsGen.map(h=>e.jsx(De,{task:h,onClick:()=>o==null?void 0:o(r)},h.id))]}),m.rewrite.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"va-history-related-group-title",children:["歌词改写 (",m.rewrite.length,")"]}),m.rewrite.map(h=>e.jsx(De,{task:h,onClick:()=>o==null?void 0:o(r)},h.id))]}),m.audio.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"va-history-related-group-title",children:["音乐生成 (",m.audio.length,")"]}),m.audio.map(h=>e.jsx(De,{task:h},h.id))]})]})]},r.id)})})}),e.jsx(Cs,{open:u!==null,title:"确认删除",description:"确定要删除这条音乐分析记录吗?此操作不可撤销。",confirmText:"删除",cancelText:"取消",danger:!0,onOpenChange:r=>{r||P(null)},onConfirm:y})]})},De=({task:s,onClick:n})=>{var o;const i=s.status===ue.COMPLETED,b=i&&((o=s.result)==null?void 0:o.url)||"";return e.jsx(Ms,{content:Qs(s.status),showArrow:!1,children:e.jsxs("div",{className:"va-history-related-task",onClick:n,style:n?{cursor:"pointer"}:void 0,children:[e.jsx("span",{className:`va-history-related-task-status ${Js(s.status)}`}),e.jsx("span",{className:"va-history-related-task-prompt",children:Zs(s)}),e.jsx("span",{className:"va-history-related-task-time",children:Xs(s.createdAt)}),i&&b&&s.type===q.AUDIO&&e.jsx("audio",{controls:!0,src:b,preload:"metadata",className:"ma-related-task-audio",onClick:M=>M.stopPropagation()})]})})},sa=[{id:"create",label:"创作"},{id:"lyrics",label:"歌词"},{id:"generate",label:"生成"}],ca=()=>{const{records:s,setRecords:n,currentRecord:i,showStarred:b,setShowStarred:o,starredCount:M,selectRecord:x,updateCurrentRecord:I,restart:u,applySyncedRecord:P}=As({loadRecords:Es,logPrefix:"[MusicAnalyzer]"}),{page:T,setPage:F,navigateToStep:v,goToDefaultPage:D,openHistory:y,openStarred:Q,toggleStarred:r}=_s({initialPage:"create",defaultPage:"create",historyPage:"history",setShowStarred:o}),m=a.useCallback(async S=>{if(Ps(S)){const G=await Ue(S);return G?{...G,selectWhenNoCurrent:!0}:null}const J=Ds(S);return J?Ls(S,J):null},[]);Os({syncTask:m,applySyncedRecord:P,logPrefix:"[MusicAnalyzer]"});const g=a.useMemo(()=>sa.map((S,J)=>({...S,disabled:!i&&J>0})),[i]),j=a.useCallback(S=>{I(S)},[I]),d=a.useCallback(S=>{x(S),D()},[D,x]),h=a.useCallback(S=>{x(S),F("lyrics")},[x,F]),k=a.useCallback(S=>{I(S)},[I]),K=a.useCallback(()=>{u(),D()},[D,u]);return e.jsxs("div",{className:"video-analyzer music-analyzer",children:[e.jsx(ws,{isHistoryPage:T==="history",showStarred:b,recordsCount:s.length,starredCount:M,currentStep:T,steps:g,onStepNavigate:v,onBackFromHistory:D,onOpenHistory:y,onOpenStarred:Q,onToggleStarred:r}),T==="create"&&e.jsx(Hs,{existingRecord:i,onComplete:j,onRecordsChange:n,onCreateNew:K,onNext:i?()=>F("lyrics"):void 0,onLyricsReady:()=>F("lyrics")}),T==="lyrics"&&i&&e.jsx(Vs,{record:i,onRecordUpdate:k,onRecordsChange:n,onNext:()=>F("generate")}),T==="generate"&&i&&e.jsx(Ws,{record:i,onRecordUpdate:k,onRecordsChange:n,onRestart:K}),T==="history"&&e.jsx(ea,{records:s,onSelect:d,onRecordsChange:n,showStarredOnly:b,onSelectLyrics:h})]})};export{ca as default};
|
|
1
|
+
import{e0 as qe,r as a,mj as U,j as e,mk as is,ml as cs,mm as os,mn as us,mo as ds,mp as ms,mq as pe,mr as Se,ms as xe,mt as oe,mu as Je,mv as Ge,am as ge,mw as ps,bY as hs,bz as X,bg as q,mx as fs,a1 as ys,my as Qe,mz as Xe,mA as Ze,mB as gs,mC as js,aA as Ne,bn as be,mD as Fe,mE as Ke,mF as vs,mG as xs,iV as Ss,gT as Ns,mH as Me,mI as bs,mJ as Is,mK as Ts,$ as ks,c1 as Cs,dB as ue,E as Ms,mL as As,mM as _s,mN as ws,mO as Es}from"./startup-app-eD_rQhSh.js";import{i as je,R as es,r as zs,K as $e,m as Ie}from"./ai-chat-BO5vbKZW.js";import{s as Ue,i as Ps,g as Ds,a as Ls}from"./task-sync-BJVOunRa.js";import{u as Os}from"./VideoAnalyzer-BmAjGvN8.js";/* empty css */import"./startup-runtime-DTmhLESk.js";function Re(s){return(s||"").trim().toLowerCase().replace(/[^a-z0-9]/g,"")||"mp3"}function Bs(s){const n=s.name.split(".").pop();return n&&n.length<=8?Re(n):Re(s.type.split("/")[1])}async function $s(s,n){const i=Bs(s),o=`/__aitu_cache__/audio/${`music-analyzer-source-${Date.now()}-${Math.random().toString(36).slice(2,8)}`}.${i}`;return await qe.cacheMediaFromBlob(o,s,"audio",{metadata:{source:"music-analyzer-input",fileName:s.name,mimeType:s.type||"audio/mpeg",size:s.size}}),{type:"upload",cacheUrl:o,fileName:s.name||`music-source.${i}`,mimeType:s.type||"audio/mpeg",size:s.size}}async function Us(s){if(!s||s.type!=="upload")return null;const n=await qe.getCachedBlob(s.cacheUrl);return n?new File([n],s.fileName||"music-source.mp3",{type:s.mimeType||n.type||"audio/mpeg",lastModified:Date.now()}):null}const Gs=[{key:"purpose",label:"音乐用途",placeholder:"普通歌曲创作 / 短视频爆点 / 广告歌",options:is},{key:"genreStyle",label:"核心曲风",placeholder:"Mozart Classical / Mandopop / R&B",options:cs},{key:"vocalStyle",label:"人声/唱法",placeholder:"female vocal(女声)/ rap vocal(说唱人声)",options:os},{key:"energyMood",label:"情绪能量",placeholder:"高能上扬 / 深夜情绪化 / 克制高级",options:us},{key:"lyricGoal",label:"歌词目标",placeholder:"副歌第一句要有记忆点",options:ds}],Le=({value:s,onChange:n})=>{const i=a.useMemo(()=>U(s),[s]),b=a.useCallback((o,M)=>{n(U({...i,[o]:M}))},[i,n]);return e.jsxs("div",{className:"ma-music-brief",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"歌曲定位"}),e.jsx("span",{className:"ma-muted",children:"用于约束歌词与 Suno 标签"})]}),e.jsx("div",{className:"ma-music-brief-grid",children:Gs.map(o=>e.jsxs("label",{className:"ma-field",children:[e.jsx("span",{children:o.label}),e.jsx(ms,{className:"ma-brief-combo",value:i[o.key]||"",onChange:M=>b(o.key,M),options:o.options,placeholder:o.placeholder})]},o.key))})]})},Ae="gemini-2.5-pro",_e="music-analyzer:model",we="music-analyzer:lyrics-model",Oe="music-analyzer:creation-prompt";function Fs(s){return`${(s/1024/1024).toFixed(1)}MB`}function Ks(){try{return sessionStorage.getItem(Oe)||""}catch{return""}}function He(s){try{if(s){sessionStorage.setItem(Oe,s);return}sessionStorage.removeItem(Oe)}catch{}}function Rs(s=[],n=[]){return s.length!==n.length?!1:s.every((i,b)=>i===n[b])}const Hs=({existingRecord:s,onComplete:n,onRecordsChange:i,onCreateNew:b,onNext:o,onLyricsReady:M})=>{const[x,I]=a.useState((s==null?void 0:s.source)==="upload"?"reference":"scratch"),[u,P]=a.useState(()=>(s==null?void 0:s.creationPrompt)||Ks()),[T,F]=a.useState([]),[v,D]=a.useState(()=>U(s==null?void 0:s.musicBrief)),[y,J]=a.useState(()=>(s==null?void 0:s.pendingLyricsGenTaskId)||null),[r,m]=a.useState(""),[g,j]=a.useState(null),[d,h]=a.useState(null),[k,K]=a.useState(""),[S,Q]=a.useState(!0),[G,de]=a.useState(""),[V,Z]=a.useState(""),[re,me]=a.useState(""),te=a.useRef(null),C=a.useRef(null),R=a.useRef(),Y=a.useRef(!1),ne=a.useRef(!1),[ie,A]=a.useState(""),[L,le]=a.useState(()=>(s==null?void 0:s.analysisModel)||pe(_e,Ae).modelId),[ee,$]=a.useState(()=>(s==null?void 0:s.analysisModelRef)||pe(_e,Ae).modelRef),[z,H]=a.useState(()=>pe(we,be()).modelId),[se,c]=a.useState(()=>pe(we,be()).modelRef),N=a.useCallback((l,f)=>{le(l),$(f||null),Se(_e,l,f)},[]),t=a.useCallback((l,f)=>{H(l),c(f||null),Se(we,l,f)},[]),w=a.useMemo(()=>{if(C.current&&URL.revokeObjectURL(C.current),!g)return C.current=null,null;const l=URL.createObjectURL(g);return C.current=l,l},[g]);a.useEffect(()=>()=>{C.current&&URL.revokeObjectURL(C.current)},[]),a.useEffect(()=>{let l=!1;return(async()=>{if(!s){!d&&!y&&(j(null),D({}),A(""));return}le(s.analysisModel||Ae),$(s.analysisModelRef||null),P(s.creationPrompt||""),D(O=>{const B=U(s.musicBrief);return xe(O,B)?O:B});const p=s.analysis?Ge(s.analysis):null;if(de(s.title||(p==null?void 0:p.sunoTitle)||""),Z((s.styleTags||(p==null?void 0:p.sunoStyleTags)||(p==null?void 0:p.genreTags)||[]).join(", ")),me(s.lyricsDraft||(p==null?void 0:p.sunoLyricsDraft)||""),A(""),s.source==="upload"){const O=await Us(s.sourceSnapshot);if(l)return;j(O),O||A("原上传音频缓存已失效,无法自动回填音频")}})(),()=>{l=!0}},[s,d,y]),a.useEffect(()=>{if((s==null?void 0:s.source)==="scratch"){He(s.creationPrompt||"");return}s||He(u)},[u,s]),a.useEffect(()=>{if(s)return clearTimeout(R.current),R.current=setTimeout(async()=>{const l=U(v),f={musicBrief:l};if(x==="reference"){const B=V.split(",").map(rs=>rs.trim()).filter(Boolean),as=s.title!==G.trim(),ts=!Rs(s.styleTags||[],B),ns=(s.lyricsDraft||"")!==re,ls=!xe(s.musicBrief,l);if(!as&&!ts&&!ns&&!ls)return;f.title=G.trim(),f.styleTags=B,f.lyricsDraft=re}else if(xe(s.musicBrief,l))return;const p=await oe(s.id,f);i(p);const O=p.find(B=>B.id===s.id);O&&n(O)},400),()=>clearTimeout(R.current)},[re,V,G,s,v,x,n,i]);const _=je("text"),ce=a.useMemo(()=>_.filter(l=>/^gemini/i.test(l.id)),[_]),W=je("audio"),ae=a.useMemo(()=>Je(_,W),[_,W]),E=a.useMemo(()=>s!=null&&s.analysis?Ge(s.analysis):null,[s==null?void 0:s.analysis]),Te=a.useCallback(l=>{var p;const f=(p=l.target.files)==null?void 0:p[0];f!=null&&f.type.startsWith("audio/")?(j(f),A("")):A("请选择音频文件")},[]),ve=a.useCallback(l=>{l.preventDefault();const f=l.dataTransfer.files[0];f!=null&&f.type.startsWith("audio/")?(j(f),A("")):A("请选择音频文件")},[]),ke=a.useCallback(async()=>{if(!(Y.current||d)){if(!g){A("请先上传音频");return}Y.current=!0,ge.trackUIInteraction({area:"popular_music_tool",action:"audio_analysis_started",control:"analyze_audio",source:"music_analyzer_create_page",metadata:{fileSizeBytes:g.size,hasModelRef:!!ee}}),A(""),K("缓存音频...");try{const l=await $s(g),f=ps(v),p=[hs,f].filter(Boolean).join(`
|
|
2
|
+
`),O=X.createTask({prompt:`分析音频:${g.name||"本地音频"}`,model:L,modelRef:ee,mimeType:l.mimeType,audioCacheUrl:l.cacheUrl,musicAnalyzerAction:"analyze",musicAnalyzerPrompt:p,musicAnalyzerMusicBrief:U(v),musicAnalyzerSource:"upload",musicAnalyzerSourceLabel:l.fileName,musicAnalyzerSourceSnapshot:l,autoInsertToCanvas:!1},q.CHAT);h(O.id),K("音频分析中 0%")}catch(l){Y.current=!1,A(l.message||"音频分析失败")}}},[g,v,d,L,ee]),he=a.useCallback(async()=>{if(ne.current||y)return;if(!u.trim()){A("请先描述你想创作的歌曲");return}ne.current=!0;const l=Qe(z);ge.trackUIInteraction({area:"popular_music_tool",action:"lyrics_generation_started",control:"generate_lyrics",source:"music_analyzer_create_page",metadata:{engine:l?"suno":"text_model",promptLength:u.trim().length,hasModelRef:!!se}}),A(""),m(l?"歌词生成中...":"歌词草稿生成中 0%");try{const f={id:ys(),createdAt:Date.now(),source:"scratch",sourceLabel:u.slice(0,30)||"从零创作",creationPrompt:u,musicBrief:U(v),styleTags:fs(v),starred:!1},p=l?X.createTask({prompt:Xe({userPrompt:u,musicBrief:v,mode:"create"}),model:z,modelRef:se,sunoAction:"lyrics",musicAnalyzerAction:"lyrics-gen",musicAnalyzerRecordId:f.id,musicAnalyzerMusicBrief:U(v),knowledgeContextRefs:T,autoInsertToCanvas:!1},q.AUDIO):X.createTask({prompt:`从零创作歌词:${f.sourceLabel}`,model:z,modelRef:se,musicAnalyzerAction:"lyrics-gen",musicAnalyzerPrompt:Ze({userPrompt:u,musicBrief:v,mode:"create"}),musicAnalyzerRecordId:f.id,musicAnalyzerMusicBrief:U(v),knowledgeContextRefs:T,autoInsertToCanvas:!1},q.CHAT);f.pendingLyricsGenTaskId=p.id;const O=await gs(f);i(O),n(f),J(p.id)}catch(f){ne.current=!1,A(f.message||"歌词生成失败"),m("")}},[u,T,v,n,i,y,z,se]);a.useEffect(()=>{if(!d)return;const l=X.getTask(d);typeof(l==null?void 0:l.progress)=="number"&&K(`音频分析中 ${Math.round(l.progress)}%`);const f=X.observeTaskUpdates().subscribe(p=>{var O;if(p.task.id===d){if(p.task.status==="failed"){Y.current=!1,h(null),K(""),A(((O=p.task.error)==null?void 0:O.message)||"音频分析失败");return}if(p.task.status==="completed"){Ue(p.task).then(B=>{B&&(i(B.records),n(B.record))}).catch(B=>A(B.message||"分析结果同步失败")).finally(()=>{Y.current=!1,h(null),K("")});return}typeof p.task.progress=="number"&&K(`音频分析中 ${Math.round(p.task.progress)}%`)}});return()=>f.unsubscribe()},[d,n,i]),a.useEffect(()=>{if(!y)return;const l=X.getTask(y);if(typeof(l==null?void 0:l.progress)=="number"){const p=l.type===q.CHAT?"歌词草稿生成中":"歌词生成中";m(`${p} ${Math.round(l.progress)}%`)}const f=X.observeTaskUpdates().subscribe(p=>{var O;if(p.task.id===y){if(p.task.status==="failed"){const B=String(p.task.params.musicAnalyzerRecordId||"").trim();ne.current=!1,J(null),m(""),A(((O=p.task.error)==null?void 0:O.message)||"歌词生成失败"),B&&oe(B,{pendingLyricsGenTaskId:null}).then(i);return}if(p.task.status==="completed"){ne.current=!1,J(null),m(""),M==null||M();return}if(typeof p.task.progress=="number"){const B=p.task.type===q.CHAT?"歌词草稿生成中":"歌词生成中";m(`${B} ${Math.round(p.task.progress)}%`)}}});return()=>f.unsubscribe()},[M,i,y]);const Ce=a.useCallback(async()=>{E&&(await es("text",js(E)),ge.trackUIInteraction({area:"popular_music_tool",action:"analysis_inserted_to_canvas",control:"insert_analysis",source:"music_analyzer_create_page",metadata:{hasSunoTitle:!!E.sunoTitle,tagsCount:E.sunoStyleTags.length}}))},[E]);return e.jsxs("div",{className:"ma-create-page",children:[e.jsxs("div",{className:"ma-mode-toggle",children:[e.jsx("button",{className:`ma-mode-btn ${x==="scratch"?"active":""}`,onClick:()=>I("scratch"),children:"从零创作"}),e.jsx("button",{className:`ma-mode-btn ${x==="reference"?"active":""}`,onClick:()=>I("reference"),children:"参考音频"})]}),e.jsxs("div",{className:"va-page",children:[x==="scratch"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"ma-card",children:e.jsx(Le,{value:v,onChange:D})}),e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"描述你想创作的歌曲"}),e.jsx(zs,{className:"ma-icon-btn",originalPrompt:u,language:"zh",scenarioId:"music.create-song",onApply:P})]}),e.jsx("textarea",{className:"ma-textarea",value:u,onChange:l=>P(l.target.value),rows:6,placeholder:"例如:一首关于夏天海边的轻快流行歌,女声,带有吉他和电子节拍"}),e.jsx($e,{value:T,onChange:F,disabled:!!y,className:"ma-knowledge-context-selector",placement:"up"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"上传音频"}),g&&e.jsx("span",{className:"ma-muted",children:Fs(g.size)})]}),e.jsx("div",{className:"va-dropzone ma-dropzone",onClick:()=>{var l;return(l=te.current)==null?void 0:l.click()},onDragOver:l=>l.preventDefault(),onDrop:ve,children:g?e.jsxs("div",{className:"ma-audio-preview",children:[e.jsxs("div",{className:"ma-audio-preview__meta",children:[e.jsx("strong",{children:g.name}),e.jsx("button",{className:"va-nav-btn",onClick:l=>{l.stopPropagation(),j(null),A(""),te.current&&(te.current.value="")},children:"清空"})]}),w&&e.jsx("audio",{controls:!0,src:w})]}):e.jsxs("div",{className:"ma-dropzone__placeholder",children:[e.jsx("span",{children:"点击或拖拽上传本地音频"}),e.jsx("small",{children:"支持 mp3、wav、m4a 等常见格式"})]})}),e.jsx("input",{ref:te,type:"file",accept:"audio/*",hidden:!0,onChange:Te})]}),e.jsx("div",{className:"ma-card",children:e.jsx(Le,{value:v,onChange:D})}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"分析模型"})}),e.jsx(Ne,{selectedModel:L,selectedSelectionKey:Ie(L,ee),onSelect:N,models:ce,variant:"form",placement:"down",placeholder:"选择 Gemini 分析模型"})]})]}),E&&x==="reference"&&e.jsxs("div",{className:"ma-card",children:[e.jsxs("button",{className:"ma-section-toggle",onClick:()=>Q(l=>!l),children:[e.jsx("span",{children:"分析摘要"}),e.jsx("span",{children:S?"收起":"展开"})]}),S&&e.jsxs("div",{className:"ma-analysis-summary",children:[e.jsx("p",{children:E.summary}),e.jsxs("div",{className:"ma-chip-row",children:[e.jsx("span",{className:"ma-chip",children:E.language||"未知语言"}),e.jsx("span",{className:"ma-chip",children:E.mood||"未知情绪"}),E.genreTags.map(l=>e.jsx("span",{className:"ma-chip ma-chip--accent",children:l},l))]}),e.jsx("div",{className:"ma-tag-row",children:E.structure.map(l=>e.jsx("code",{children:l},l))}),E.titleSuggestions.length>0&&e.jsxs("div",{className:"ma-suggestions",children:["推荐标题:",E.titleSuggestions.join(" / ")]}),(E.sunoTitle||E.sunoStyleTags.length>0||E.sunoLyricsDraft)&&e.jsxs("div",{className:"ma-suno-summary",children:[e.jsx("div",{className:"ma-suno-summary__title",children:"Suno 生成草稿"}),e.jsxs("div",{className:"ma-suno-summary__form",children:[e.jsxs("label",{className:"ma-suno-summary__field",children:[e.jsx("span",{children:"歌曲标题"}),e.jsx("input",{className:"ma-input",value:G,onChange:l=>de(l.target.value),placeholder:"可直接用于 Suno 的标题"})]}),e.jsxs("label",{className:"ma-suno-summary__field",children:[e.jsx("span",{children:"Suno 风格标签"}),e.jsx("input",{className:"ma-input",value:V,onChange:l=>Z(l.target.value),placeholder:"逗号分隔的风格标签"})]}),e.jsxs("label",{className:"ma-suno-summary__field",children:[e.jsx("span",{children:"带 Suno 标签的歌词草稿"}),e.jsx("textarea",{className:"ma-textarea",rows:12,value:re,onChange:l=>me(l.target.value),placeholder:"分析阶段整理出的可用歌词草稿"})]})]})]})]})]}),(ie||k||r)&&e.jsxs("div",{className:"ma-status-stack",children:[ie&&e.jsx("div",{className:"ma-error",children:ie}),k&&e.jsx("div",{className:"ma-progress",children:k}),r&&e.jsx("div",{className:"ma-progress",children:r})]}),e.jsx("div",{className:`va-page-actions ${x==="scratch"?"ma-lyrics-submit-row":""}`,children:x==="scratch"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"ma-lyrics-model-inline",children:[e.jsx("span",{className:"ma-inline-label",children:"歌词模型"}),e.jsx(Ne,{selectedModel:z,selectedSelectionKey:Ie(z,se),onSelect:t,models:ae,variant:"form",placement:"up",placeholder:"选择歌词模型"})]}),e.jsx("button",{className:"va-btn-primary",onClick:he,disabled:!u.trim()||!!y,children:"生成歌词"})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:b,children:"新建"}),e.jsx("button",{onClick:Ce,disabled:!(s!=null&&s.analysis),children:"插入分析"}),e.jsx("button",{className:"va-btn-primary",onClick:ke,disabled:!g||!!d,children:"开始分析"}),e.jsx("button",{onClick:o,disabled:!s,children:"下一步"})]})})]})]})},Ee="music-analyzer:model",Ve="gemini-2.5-pro",Vs=({record:s,onRecordUpdate:n,onRecordsChange:i,onNext:b})=>{var $,z,H,se;const[o,M]=a.useState(()=>Fe(s)),[x,I]=a.useState([]),[u,P]=a.useState(s.lyricsDraft||""),[T,F]=a.useState(s.title||((z=($=s.analysis)==null?void 0:$.titleSuggestions)==null?void 0:z[0])||""),[v,D]=a.useState((s.styleTags||((H=s.analysis)==null?void 0:H.genreTags)||[]).join(", ")),[y,J]=a.useState(()=>U(s.musicBrief)),[r,m]=a.useState(()=>s.pendingRewriteTaskId||null),[g,j]=a.useState(""),[d,h]=a.useState(""),[k,K]=a.useState(()=>s.analysisModel||pe(Ee,Ve).modelId),[S,Q]=a.useState(()=>s.analysisModelRef||pe(Ee,Ve).modelRef),[G,de]=a.useState(!1),V=a.useRef(),Z=a.useRef(!1),re=a.useCallback((c,N)=>{K(c),Q(N||null),Se(Ee,c,N)},[]);a.useEffect(()=>{var c,N,t;M(Fe(s)),P(s.lyricsDraft||""),F(s.title||((N=(c=s.analysis)==null?void 0:c.titleSuggestions)==null?void 0:N[0])||""),D((s.styleTags||((t=s.analysis)==null?void 0:t.genreTags)||[]).join(", ")),J(w=>{const _=U(s.musicBrief);return xe(w,_)?w:_}),m(s.pendingRewriteTaskId||null)},[s]),a.useEffect(()=>(clearTimeout(V.current),V.current=setTimeout(async()=>{const c=v.split(",").map(t=>t.trim()).filter(Boolean),N=await oe(s.id,{rewritePrompt:o,lyricsDraft:u,title:T,styleTags:c,musicBrief:U(y),pendingRewriteTaskId:r});i(N),n({...s,rewritePrompt:o,lyricsDraft:u,title:T,styleTags:c,musicBrief:U(y),pendingRewriteTaskId:r})},400),()=>clearTimeout(V.current)),[u,y,n,i,r,s.id,o,v,T]);const me=je("text"),te=je("audio"),C=a.useMemo(()=>Je(me,te),[me,te]),R=a.useMemo(()=>Qe(k),[k]),Y=a.useMemo(()=>{const c=[{id:Ke,label:"原始版本"}];for(const N of s.lyricsVersions||[])c.push({id:N.id,label:N.label});return c},[s.lyricsVersions]),ne=s.activeVersionId||Ke,ie=Y.length>1,A=String(s.creationPrompt||"").trim(),L=a.useCallback(async c=>{const N=vs(s,c);if(!N)return;const t=await oe(s.id,N);i(t),n({...s,...N}),de(!1)},[n,i,s]),le=a.useCallback(async()=>{if(!(Z.current||r)){Z.current=!0,h(""),j(R?"歌词生成中...":"歌词改写中 0%"),ge.trackUIInteraction({area:"popular_music_tool",action:"lyrics_rewrite_started",control:"rewrite_lyrics",source:"music_analyzer_lyrics_page",metadata:{engine:R?"suno":"text_model",hasRewritePrompt:!!o.trim(),lyricsLength:u.trim().length}});try{let c;if(R){const t=Xe({userPrompt:o,originalPrompt:A,currentLyrics:u,musicBrief:y,mode:"rewrite"});c=X.createTask({prompt:t,model:k,modelRef:S||null,sunoAction:"lyrics",musicAnalyzerAction:"lyrics-gen",musicAnalyzerRecordId:s.id,musicAnalyzerMusicBrief:U(y),knowledgeContextRefs:x,autoInsertToCanvas:!1},q.AUDIO)}else c=X.createTask({prompt:`改写歌词:${s.sourceLabel}`,model:k,modelRef:S||null,musicAnalyzerAction:"rewrite",musicAnalyzerPrompt:Ze({analysis:s.analysis,userPrompt:o,originalPrompt:A,currentLyrics:u,musicBrief:y}),musicAnalyzerRecordId:s.id,musicAnalyzerMusicBrief:U(y),knowledgeContextRefs:x,autoInsertToCanvas:!1},q.CHAT);m(c.id);const N=await oe(s.id,{rewritePrompt:o,musicBrief:U(y),pendingRewriteTaskId:c.id});i(N),n({...s,rewritePrompt:o,musicBrief:U(y),pendingRewriteTaskId:c.id})}catch(c){Z.current=!1,h(c.message||"歌词改写失败"),j("")}}},[A,u,n,i,s,o,k,S,R,x,y,r]);a.useEffect(()=>{if(!r)return;const c=X.getTask(r);typeof(c==null?void 0:c.progress)=="number"&&j(`歌词改写中 ${Math.round(c.progress)}%`);const N=X.observeTaskUpdates().subscribe(t=>{var w;if(t.task.id===r){if(t.task.status==="failed"){Z.current=!1,m(null),j(""),h(((w=t.task.error)==null?void 0:w.message)||"歌词改写失败"),oe(s.id,{pendingRewriteTaskId:null}).then(i);return}if(t.task.status==="completed"){Ue(t.task).then(_=>{_&&(i(_.records),n(_.record),P(_.record.lyricsDraft||""),F(_.record.title||""),D((_.record.styleTags||[]).join(", ")))}).catch(_=>{h(_.message||"改写结果同步失败")}).finally(()=>{Z.current=!1,m(null),j("")});return}typeof t.task.progress=="number"&&j(`歌词改写中 ${Math.round(t.task.progress)}%`)}});return()=>N.unsubscribe()},[n,i,r,s.id]);const ee=a.useCallback(async()=>{const c=await es("text",xs({title:T,styleTags:v.split(",").map(N=>N.trim()).filter(Boolean),lyricsDraft:u}));if(!c.success){h(c.error||"插入失败,请确认画布已打开");return}ge.trackUIInteraction({area:"popular_music_tool",action:"lyrics_inserted_to_canvas",control:"insert_lyrics",source:"music_analyzer_lyrics_page",metadata:{lyricsLength:u.trim().length,tagsCount:v.split(",").filter(N=>N.trim()).length}})},[u,v,T]);return e.jsxs("div",{className:"va-page",children:[e.jsx("div",{className:"ma-card",children:e.jsx(Le,{value:y,onChange:J})}),e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"改写要求"}),ie&&e.jsxs("div",{className:"ma-version-dropdown",children:[e.jsxs("button",{className:"ma-version-btn",onClick:()=>de(c=>!c),children:[((se=Y.find(c=>c.id===ne))==null?void 0:se.label)||"原始版本",e.jsx("span",{className:"ma-version-arrow",children:G?"▲":"▼"})]}),G&&e.jsx("div",{className:"ma-version-menu",children:Y.map(c=>e.jsx("button",{className:`ma-version-menu-item ${c.id===ne?"active":""}`,onClick:()=>L(c.id),children:c.label},c.id))})]})]}),e.jsx("textarea",{className:"ma-textarea",value:o,onChange:c=>M(c.target.value),rows:4,placeholder:"告诉 AI 要保留什么、强化什么、改成什么风格"}),e.jsx($e,{value:x,onChange:I,disabled:!!r,className:"ma-knowledge-context-selector",placement:"up"}),e.jsxs("div",{className:"ma-lyrics-submit-row ma-lyrics-submit-row--rewrite",children:[e.jsxs("div",{className:"ma-lyrics-model-inline",children:[e.jsx("span",{className:"ma-inline-label",children:"歌词模型"}),e.jsx(Ne,{selectedModel:k,selectedSelectionKey:Ie(k,S),onSelect:re,models:C,variant:"form",placement:"up",placeholder:"选择歌词模型"})]}),e.jsx("button",{className:"va-btn-primary ma-rewrite-submit",onClick:le,disabled:!!r,children:r?g||(R?"歌词生成中...":"歌词改写中..."):R?"Suno 生成歌词":"AI 改写"})]}),g&&e.jsx("div",{className:"ma-progress",children:g})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"歌曲标题"})}),e.jsx("input",{className:"ma-input",value:T,onChange:c=>F(c.target.value),placeholder:"歌曲标题"})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"Suno 风格标签"})}),e.jsx("input",{className:"ma-input",value:v,onChange:c=>D(c.target.value),placeholder:"例如 cinematic pop, female vocal, uplifting"})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"歌词草稿"})}),e.jsx("textarea",{className:"ma-textarea",value:u,onChange:c=>P(c.target.value),rows:14,placeholder:"AI 改写结果会出现在这里,可继续手改"})]}),d&&e.jsx("div",{className:"ma-error",children:d}),e.jsxs("div",{className:"va-page-actions",children:[e.jsx("button",{onClick:ee,disabled:!u.trim(),children:"插入歌词"}),e.jsx("button",{className:"va-btn-primary",onClick:b,disabled:!u.trim(),children:"下一步"})]})]})},ze="music-analyzer:audio-model",Be=[{id:"generate",label:"新生成",hint:"从零生成完整音乐"},{id:"continue",label:"续写",hint:"从已有片段继续创作"},{id:"infill",label:"Infill",hint:"局部重绘指定时间窗口"}];function fe(s){const n=s.trim();if(!n)return null;const i=Number(n);return Number.isFinite(i)?i:null}function ye(s){return typeof s=="number"&&Number.isFinite(s)?String(s):""}function Pe(s){return s.split(",").map(n=>n.trim()).filter(Boolean)}function Ye(s){var n;return((n=Be.find(i=>i.id===s))==null?void 0:n.label)||"新生成"}function Ys(s){return typeof s.duration=="number"&&Number.isFinite(s.duration)?String(Math.max(0,Math.round(s.duration))):""}function We(s){const n=s.title||"未命名片段",i=s.duration!=null?` · ${ss(s.duration)}`:"",b=s.clipId?` · ${s.clipId.slice(0,8)}`:"";return`${n}${i}${b}`}const Ws=({record:s,onRecordUpdate:n,onRecordsChange:i,onRestart:b})=>{var N;const[o,M]=a.useState(s.title||""),[x,I]=a.useState((s.styleTags||[]).join(", ")),[u,P]=a.useState(s.lyricsDraft||""),[T,F]=a.useState([]),[v,D]=a.useState("chirp-v5-5"),[y,J]=a.useState(1),[r,m]=a.useState(()=>pe(ze,be()).modelId),[g,j]=a.useState(()=>pe(ze,be()).modelRef),[d,h]=a.useState(s.musicEditAction||"generate"),[k,K]=a.useState(s.continueFromClipId||""),[S,Q]=a.useState(ye(s.continueAt)),[G,de]=a.useState(ye(s.infillStartS)),[V,Z]=a.useState(ye(s.infillEndS)),[re,me]=a.useState(!1),[te,C]=a.useState(""),R=a.useRef(),Y=a.useRef(!1),ne=a.useCallback((t,w)=>{m(t),j(w||null),Se(ze,t,w)},[]);a.useEffect(()=>{M(s.title||""),I((s.styleTags||[]).join(", ")),P(s.lyricsDraft||""),h(s.musicEditAction||"generate"),K(s.continueFromClipId||""),Q(ye(s.continueAt)),de(ye(s.infillStartS)),Z(ye(s.infillEndS))},[s]),a.useEffect(()=>(clearTimeout(R.current),R.current=setTimeout(async()=>{const t=Pe(x),w=fe(S),_=fe(G),ce=fe(V),W={title:o,styleTags:t,lyricsDraft:u,musicEditAction:d,continueFromClipId:k||null,continueAt:w,infillStartS:_,infillEndS:ce},ae=await oe(s.id,W);i(ae),n({...s,...W})},400),()=>clearTimeout(R.current)),[d,S,k,V,G,n,i,u,s.id,x,o]);const ie=je("audio"),A=a.useMemo(()=>ie.filter(t=>{const w=Array.isArray(t.tags)?t.tags.join(" "):"";return/suno/i.test(t.id)||/suno/i.test(w)}),[ie]),L=a.useMemo(()=>Ss(r).find(t=>t.id==="mv"),[r]);a.useEffect(()=>{L!=null&&L.defaultValue&&D(t=>t||String(L.defaultValue))},[L==null?void 0:L.defaultValue]);const le=s.generatedClips||[],ee=a.useMemo(()=>le.filter(t=>!!String(t.clipId||"").trim()),[le]),$=a.useMemo(()=>ee.find(t=>t.clipId===k)||null,[k,ee]),z=d!=="generate",H=d==="infill",se=a.useCallback((t,w)=>{if(!t.clipId){C("该片段尚未拿到真实 clip_id,暂时不能继续创作");return}h(w),K(t.clipId),Q(_=>_||Ys(t)),C(w==="continue"?`已带入片段「${t.title||t.clipId.slice(0,8)}」用于续写`:`已带入片段「${t.title||t.clipId.slice(0,8)}」用于 Infill`)},[]),c=a.useCallback(async()=>{const t=u.trim(),w=o.trim(),_=x.trim(),ce=fe(S),W=fe(G),ae=fe(V);if(!t){C("请先准备歌词或生成提示词");return}if(z&&!k){C("请先选择要续写的片段");return}if(z&&!($!=null&&$.taskId)){C("当前片段缺少来源 task_id,请先重新同步或重新生成一次片段");return}if(z&&ce==null){C("请填写续写起点秒数");return}if(ce!=null&&ce<0){C("续写起点秒数不能小于 0");return}if(H&&W==null){C("请填写 Infill 开始秒数");return}if(H&&ae==null){C("请填写 Infill 结束秒数");return}if(W!=null&&W<0){C("Infill 开始秒数不能小于 0");return}if(ae!=null&&ae<0){C("Infill 结束秒数不能小于 0");return}if(H&&W!=null&&ae!=null&&W>=ae){C("Infill 开始秒数必须小于结束秒数");return}if(!Y.current){Y.current=!0,ge.trackUIInteraction({area:"popular_music_tool",action:"music_generation_started",control:"generate_music",source:"music_analyzer_generate_page",metadata:{editAction:d,batchCount:y,promptLength:t.length,hasTitle:!!w,tagsCount:Pe(_).length,hasMv:!!v,hasModelRef:!!g}}),me(!0),C("");try{const E=[],Te=d==="generate"?"gen":d;for(let he=0;he<y;he+=1){const Ce=X.createTask({prompt:t,model:r,modelRef:g,sunoAction:"music",title:w,tags:_,mv:v,continueClipId:z?k:void 0,continueTaskId:z?$==null?void 0:$.taskId:void 0,continueAt:z?ce??void 0:void 0,infillStartS:H?W??void 0:void 0,infillEndS:H?ae??void 0:void 0,knowledgeContextRefs:T,batchId:`ma_${s.id}_${Te}_${he}`,batchIndex:he,batchTotal:y,autoInsertToCanvas:!0},q.AUDIO);E.push(Ce.id)}const ve={generateTaskIds:[...s.generateTaskIds||[],...E],title:w,styleTags:Pe(_),lyricsDraft:t,musicEditAction:d,continueFromClipId:k||null,continueAt:ce,infillStartS:W,infillEndS:ae},ke=await oe(s.id,ve);i(ke),n({...s,...ve}),C(`已提交 ${y} 次${Ye(d)}任务到 Suno 队列`)}catch(E){C(E.message||"提交生成任务失败")}finally{me(!1),Y.current=!1}}},[d,y,S,k,V,G,T,v,n,i,u,s,z,H,$==null?void 0:$.taskId,r,g,x,o]);return e.jsxs("div",{className:"va-page",children:[e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"创作动作"}),e.jsx("span",{className:"ma-muted",children:(N=Be.find(t=>t.id===d))==null?void 0:N.hint})]}),e.jsx("div",{className:"ma-action-toggle",children:Be.map(t=>e.jsx("button",{className:`ma-action-btn ${d===t.id?"active":""}`,onClick:()=>h(t.id),children:t.label},t.id))})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"Suno 模型"})}),e.jsx(Ne,{selectedModel:r,selectedSelectionKey:Ie(r,g),onSelect:ne,models:A.length>0?A:ie,variant:"form",placement:"down",placeholder:"选择音频生成模型"})]}),(L==null?void 0:L.options)&&L.options.length>0&&e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"Suno 版本"})}),e.jsx("select",{className:"ma-select",value:v,onChange:t=>D(t.target.value),children:L.options.map(t=>e.jsx("option",{value:String(t.value),children:t.label},t.value))})]}),z&&e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"目标片段"}),e.jsx("span",{className:"ma-muted",children:"自动使用轮询得到的真实 clip_id"})]}),ee.length>0?e.jsxs("select",{className:"ma-select",value:k,onChange:t=>K(t.target.value),children:[e.jsx("option",{value:"",children:"请选择已生成片段"}),ee.map(t=>e.jsx("option",{value:t.clipId,children:We(t)},t.clipId))]}):e.jsx("div",{className:"ma-hint",children:"先生成至少一个片段,才能使用续写或 Infill。"}),$&&e.jsxs("div",{className:"ma-hint",children:["当前片段:",We($)]})]}),z&&e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"编辑参数"})}),e.jsxs("div",{className:`ma-fields-grid ${H?"ma-fields-grid--triple":""}`,children:[e.jsxs("label",{className:"ma-field",children:[e.jsx("span",{children:"续写起点秒数"}),e.jsx("input",{className:"ma-input",type:"number",min:"0",step:"0.1",value:S,onChange:t=>Q(t.target.value),placeholder:"例如 30"})]}),H&&e.jsxs("label",{className:"ma-field",children:[e.jsx("span",{children:"Infill 开始秒数"}),e.jsx("input",{className:"ma-input",type:"number",min:"0",step:"0.1",value:G,onChange:t=>de(t.target.value),placeholder:"例如 8"})]}),H&&e.jsxs("label",{className:"ma-field",children:[e.jsx("span",{children:"Infill 结束秒数"}),e.jsx("input",{className:"ma-input",type:"number",min:"0",step:"0.1",value:V,onChange:t=>Z(t.target.value),placeholder:"例如 16"})]})]})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"歌曲标题"})}),e.jsx("input",{className:"ma-input",value:o,onChange:t=>M(t.target.value),placeholder:"歌曲标题"})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"风格标签"})}),e.jsx("input",{className:"ma-input",value:x,onChange:t=>I(t.target.value),placeholder:"逗号分隔,例如 edm, intense, female vocal"})]}),e.jsxs("div",{className:"ma-card",children:[e.jsx("div",{className:"ma-card-header",children:e.jsx("span",{children:"提交给 Suno 的歌词/提示词"})}),e.jsx("textarea",{className:"ma-textarea",rows:10,value:u,onChange:t=>P(t.target.value),placeholder:"这里的内容会直接作为 prompt 提交给 Suno"}),e.jsx($e,{value:T,onChange:F,disabled:re,className:"ma-knowledge-context-selector",placement:"up"})]}),e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsx("span",{children:"调用次数"}),e.jsx("span",{className:"ma-muted",children:"每次返回 2 首"})]}),e.jsx("div",{className:"ma-batch-selector",children:[1,2,3,4].map(t=>e.jsxs("button",{className:`ma-batch-btn ${y===t?"active":""}`,onClick:()=>J(t),children:[t," 次"]},t))})]}),le.length>0&&e.jsxs("div",{className:"ma-card",children:[e.jsxs("div",{className:"ma-card-header",children:[e.jsxs("span",{children:["已生成片段 (",le.length,")"]}),e.jsx("span",{className:"ma-muted",children:"可直接带入续写或 Infill"})]}),e.jsx("div",{className:"ma-clips-gallery",children:le.map(t=>e.jsx(qs,{clip:t,selected:z&&!!t.clipId&&k===t.clipId,onContinue:()=>se(t,"continue"),onInfill:()=>se(t,"infill")},`${t.taskId}:${t.clipId||t.audioUrl}`))})]}),te&&e.jsx("div",{className:"ma-progress",children:te}),e.jsxs("div",{className:"va-page-actions",children:[e.jsx("button",{onClick:b,children:"重新开始"}),e.jsxs("button",{className:"va-btn-primary",onClick:c,disabled:re,children:[Ye(d)," ",y," 次"]})]})]})},qs=({clip:s,selected:n,onContinue:i,onInfill:b})=>{const o=!!String(s.clipId||"").trim();return e.jsxs("div",{className:`ma-clip-row ${n?"is-selected":""}`,children:[s.imageUrl?e.jsx("img",{className:"ma-clip-thumb",src:s.imageUrl,alt:"",referrerPolicy:"no-referrer"}):e.jsx("div",{className:"ma-clip-thumb ma-clip-thumb--placeholder",children:"♪"}),e.jsxs("div",{className:"ma-clip-meta",children:[e.jsx("span",{className:"ma-clip-title",children:s.title||"未命名"}),s.duration!=null&&e.jsx("span",{className:"ma-clip-duration",children:ss(s.duration)})]}),e.jsx("audio",{controls:!0,src:s.audioUrl,className:"ma-clip-player",preload:"metadata"}),e.jsxs("div",{className:"ma-clip-actions",children:[e.jsx("button",{className:"ma-clip-action-btn",onClick:i,disabled:!o,children:"续写"}),e.jsx("button",{className:"ma-clip-action-btn",onClick:b,disabled:!o,children:"Infill"})]})]})};function ss(s){const n=Math.floor(s/60),i=Math.round(s%60);return`${n}:${String(i).padStart(2,"0")}`}function Js(s){switch(s){case ue.COMPLETED:return"已完成";case ue.PROCESSING:return"进行中";case ue.PENDING:return"等待中";case ue.FAILED:return"失败";default:return""}}function Qs(s){switch(s){case ue.COMPLETED:return"completed";case ue.PROCESSING:return"processing";case ue.PENDING:return"pending";case ue.FAILED:return"failed";default:return"pending"}}function Xs(s){const n=new Date(s);return`${n.getMonth()+1}/${n.getDate()} ${String(n.getHours()).padStart(2,"0")}:${String(n.getMinutes()).padStart(2,"0")}`}function Zs(s){var b,o,M,x;const n=s.params.musicAnalyzerAction;if(n==="rewrite"){const I=(b=s.result)!=null&&b.analysisData&&typeof s.result.analysisData=="object"?s.result.analysisData:null,u=typeof(I==null?void 0:I.title)=="string"&&I.title.trim()?I.title.trim():"";if(u)return u}if(n==="lyrics-gen"){const I=(o=s.result)!=null&&o.analysisData&&typeof s.result.analysisData=="object"?s.result.analysisData:null,u=typeof(I==null?void 0:I.title)=="string"&&I.title.trim()?I.title.trim():"";if(u)return u;const P=typeof((M=s.result)==null?void 0:M.lyricsTitle)=="string"&&s.result.lyricsTitle.trim()?s.result.lyricsTitle.trim():typeof((x=s.result)==null?void 0:x.title)=="string"&&s.result.title.trim()?s.result.title.trim():"";if(P)return P}const i=String(s.params.prompt||"");return i.length>40?`${i.slice(0,40)}…`:i}const ea=({records:s,onSelect:n,onRecordsChange:i,showStarredOnly:b=!1,onSelectLyrics:o})=>{const M=b?s.filter(r=>r.starred):s,[x,I]=a.useState(null),[u,P]=a.useState(null),{tasks:T}=Ns(),F=a.useMemo(()=>{const r=new Map,m=new Set(s.map(j=>j.id)),g=()=>({rewrite:[],lyricsGen:[],audio:[]});for(const j of T){const d=j.params;if(j.type===q.CHAT&&d.musicAnalyzerAction==="rewrite"&&typeof d.musicAnalyzerRecordId=="string"&&m.has(d.musicAnalyzerRecordId)){const h=d.musicAnalyzerRecordId;Me(r,h,"rewrite",j,g);continue}if((j.type===q.AUDIO||j.type===q.CHAT)&&d.musicAnalyzerAction==="lyrics-gen"&&typeof d.musicAnalyzerRecordId=="string"&&m.has(d.musicAnalyzerRecordId)){const h=d.musicAnalyzerRecordId;Me(r,h,"lyricsGen",j,g);continue}if(j.type===q.AUDIO&&typeof d.batchId=="string"&&d.batchId.startsWith("ma_")){const h=bs(d.batchId,"ma_",m);h&&Me(r,h,"audio",j,g)}}return Is(r)},[T,s]),v=a.useCallback(async(r,m)=>{r.stopPropagation();const g=await oe(m.id,{starred:!m.starred});i(g)},[i]),D=a.useCallback((r,m)=>{r.stopPropagation(),P(m)},[]),y=a.useCallback(async()=>{if(!u)return;const r=await Ts(u);i(r),P(null)},[i,u]),J=a.useCallback((r,m)=>{r.stopPropagation(),I(g=>g===m?null:m)},[]);return M.length===0?e.jsx("div",{className:"va-page va-empty",children:e.jsx("span",{children:b?"暂无收藏":"暂无分析记录"})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"va-page",children:e.jsx("div",{className:"va-history-list",children:M.map(r=>{var d;const m=F.get(r.id),g=!!(m&&m.rewrite.length+m.lyricsGen.length+m.audio.length>0),j=x===r.id;return e.jsxs("div",{className:"va-history-item",onClick:()=>n(r),children:[e.jsxs("div",{className:"va-history-header",children:[e.jsxs("span",{className:"va-history-source",children:[e.jsx("span",{role:"img","aria-label":"audio",children:r.source==="scratch"?"✨":"🎵"})," ",r.sourceLabel]}),e.jsx("button",{className:`va-star-btn ${r.starred?"starred":""}`,onClick:h=>v(h,r),children:r.starred?"★":"☆"})]}),e.jsxs("div",{className:"va-history-meta",children:[g&&e.jsxs("button",{className:`va-history-expand-btn ${j?"expanded":""}`,onClick:h=>J(h,r.id),children:[e.jsx(ks,{size:12}),e.jsx("span",{children:j?"收起":"关联任务"})]}),e.jsx("span",{children:new Date(r.createdAt).toLocaleString()}),e.jsx("span",{children:r.analysisModel||r.source}),e.jsx("button",{className:"va-history-delete",onClick:h=>D(h,r.id),children:"删除"})]}),e.jsx("div",{className:"ma-history-title",children:r.title||"未命名歌曲"}),e.jsx("div",{className:"ma-history-summary",children:((d=r.analysis)==null?void 0:d.summary)||r.creationPrompt||"暂无摘要"}),r.generatedClips&&r.generatedClips.length>0&&e.jsxs("div",{className:"ma-history-clips-count",children:[r.generatedClips.length," 首已生成"]}),j&&m&&e.jsxs("div",{className:"va-history-related",onClick:h=>h.stopPropagation(),children:[m.lyricsGen.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"va-history-related-group-title",children:["歌词生成 (",m.lyricsGen.length,")"]}),m.lyricsGen.map(h=>e.jsx(De,{task:h,onClick:()=>o==null?void 0:o(r)},h.id))]}),m.rewrite.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"va-history-related-group-title",children:["歌词改写 (",m.rewrite.length,")"]}),m.rewrite.map(h=>e.jsx(De,{task:h,onClick:()=>o==null?void 0:o(r)},h.id))]}),m.audio.length>0&&e.jsxs("div",{children:[e.jsxs("div",{className:"va-history-related-group-title",children:["音乐生成 (",m.audio.length,")"]}),m.audio.map(h=>e.jsx(De,{task:h},h.id))]})]})]},r.id)})})}),e.jsx(Cs,{open:u!==null,title:"确认删除",description:"确定要删除这条音乐分析记录吗?此操作不可撤销。",confirmText:"删除",cancelText:"取消",danger:!0,onOpenChange:r=>{r||P(null)},onConfirm:y})]})},De=({task:s,onClick:n})=>{var o;const i=s.status===ue.COMPLETED,b=i&&((o=s.result)==null?void 0:o.url)||"";return e.jsx(Ms,{content:Js(s.status),showArrow:!1,children:e.jsxs("div",{className:"va-history-related-task",onClick:n,style:n?{cursor:"pointer"}:void 0,children:[e.jsx("span",{className:`va-history-related-task-status ${Qs(s.status)}`}),e.jsx("span",{className:"va-history-related-task-prompt",children:Zs(s)}),e.jsx("span",{className:"va-history-related-task-time",children:Xs(s.createdAt)}),i&&b&&s.type===q.AUDIO&&e.jsx("audio",{controls:!0,src:b,preload:"metadata",className:"ma-related-task-audio",onClick:M=>M.stopPropagation()})]})})},sa=[{id:"create",label:"创作"},{id:"lyrics",label:"歌词"},{id:"generate",label:"生成"}],ca=()=>{const{records:s,setRecords:n,currentRecord:i,showStarred:b,setShowStarred:o,starredCount:M,selectRecord:x,updateCurrentRecord:I,restart:u,applySyncedRecord:P}=As({loadRecords:Es,logPrefix:"[MusicAnalyzer]"}),{page:T,setPage:F,navigateToStep:v,goToDefaultPage:D,openHistory:y,openStarred:J,toggleStarred:r}=_s({initialPage:"create",defaultPage:"create",historyPage:"history",setShowStarred:o}),m=a.useCallback(async S=>{if(Ps(S)){const G=await Ue(S);return G?{...G,selectWhenNoCurrent:!0}:null}const Q=Ds(S);return Q?Ls(S,Q):null},[]);Os({syncTask:m,applySyncedRecord:P,logPrefix:"[MusicAnalyzer]"});const g=a.useMemo(()=>sa.map((S,Q)=>({...S,disabled:!i&&Q>0})),[i]),j=a.useCallback(S=>{I(S)},[I]),d=a.useCallback(S=>{x(S),D()},[D,x]),h=a.useCallback(S=>{x(S),F("lyrics")},[x,F]),k=a.useCallback(S=>{I(S)},[I]),K=a.useCallback(()=>{u(),D()},[D,u]);return e.jsxs("div",{className:"video-analyzer music-analyzer",children:[e.jsx(ws,{isHistoryPage:T==="history",showStarred:b,recordsCount:s.length,starredCount:M,currentStep:T,steps:g,onStepNavigate:v,onBackFromHistory:D,onOpenHistory:y,onOpenStarred:J,onToggleStarred:r}),T==="create"&&e.jsx(Hs,{existingRecord:i,onComplete:j,onRecordsChange:n,onCreateNew:K,onNext:i?()=>F("lyrics"):void 0,onLyricsReady:()=>F("lyrics")}),T==="lyrics"&&i&&e.jsx(Vs,{record:i,onRecordUpdate:k,onRecordsChange:n,onNext:()=>F("generate")}),T==="generate"&&i&&e.jsx(Ws,{record:i,onRecordUpdate:k,onRecordsChange:n,onRestart:K}),T==="history"&&e.jsx(ea,{records:s,onSelect:d,onRecordsChange:n,showStarredOnly:b,onSelectLyrics:h})]})};export{ca as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{iR as K,r as c,iV as I,j as s,iJ as F,_ as P,E as S,aK as U,a0 as J,cl as W,kR as X,v as Z,kS as q}from"./startup-app-eD_rQhSh.js";function B(n,l,p){return n==="size"?p.split("(")[0].trim():n==="duration"?`${l}s`:n==="klingAction2"?l==="image2video"?"图生":"文生":n==="mode"?l:p}function z(n){return n.valueType==="number"&&n.id.toLowerCase().includes("seed")}function G(n){const l=Number.isFinite(n.min)?n.min:0,p=Number.isFinite(n.max)?n.max:2147483647,x=Math.min(l,p),h=Math.max(l,p);if(n.integer!==!1)return String(Math.floor(Math.random()*(h-x+1))+x);const g=Number.isFinite(n.step)&&n.step?n.step:1,E=Math.floor((h-x)/g);return String(x+Math.floor(Math.random()*(E+1))*g)}const Y=({selectedParams:n,onParamChange:l,compatibleParams:p,modelId:x,language:h="zh",disabled:g=!1,isOpen:E,onOpenChange:O,excludeParamIds:N,placement:C="auto"})=>{const{value:f,setValue:D}=K({controlledValue:E,defaultValue:!1,onChange:O}),[T,M]=c.useState(0),[y,b]=c.useState(0),a=c.useMemo(()=>{const t=p??I(x);return N&&N.length>0?t.filter(o=>!N.includes(o.id)):t},[p,x,N]);c.useEffect(()=>{var t;if(f&&a.length>0){M(0);const o=a[0],d=n[o.id],u=((t=o.options)==null?void 0:t.findIndex(e=>e.value===d))??0;b(u>=0?u:0)}},[f,a,n]);const A=c.useMemo(()=>{if(a.length===0)return h==="zh"?"参数":"Params";const t=[];return a.forEach(o=>{var u;const d=n[o.id];if(d)if(o.valueType==="enum"){const e=(u=o.options)==null?void 0:u.find(r=>r.value===d);e&&t.push(B(o.id,d,e.label))}else{const e=d.length>10?`${d.slice(0,10)}…`:d;t.push(`${o.shortLabel||o.label}:${e}`)}}),t.length===0?h==="zh"?"配置参数":"Settings":t.join(", ")},[a,n,h]),V=c.useCallback(t=>{t.preventDefault(),!g&&D(!f)},[g,f,D]),$=c.useCallback(t=>{var u,e;if(t==="Escape")return D(!1),!0;const o=a[T],d=((u=o==null?void 0:o.options)==null?void 0:u.length)??0;if(t==="ArrowDown")return M(r=>{var w;const m=r<a.length-1?r+1:0,_=a[m],v=n[_.id],i=((w=_.options)==null?void 0:w.findIndex(j=>j.value===v))??0;return b(i>=0?i:0),m}),!0;if(t==="ArrowUp")return M(r=>{var w;const m=r>0?r-1:a.length-1,_=a[m],v=n[_.id],i=((w=_.options)==null?void 0:w.findIndex(j=>j.value===v))??0;return b(i>=0?i:0),m}),!0;if(t==="ArrowRight")return b(r=>r<d-1?r+1:0),!0;if(t==="ArrowLeft")return b(r=>r>0?r-1:d-1),!0;if(t==="Enter"||t===" "||t==="Tab"){const r=(e=o==null?void 0:o.options)==null?void 0:e[y];return r&&l(o.id,r.value),!0}return!1},[a,T,y,n,l]),R=c.useCallback((t,o)=>{l(t,o)},[l]),k=c.useCallback((t,o)=>{l(t,o,{keepOpen:!0})},[l]),H=c.useCallback(t=>{l(t.id,G(t),{keepOpen:!0})},[l]);return a.length===0?null:s.jsx(F,{isOpen:f,setIsOpen:D,disabled:g,openKeys:["Enter"," ","ArrowDown","ArrowUp"],onOpenKey:$,placement:C,minMenuHeight:240,maxMenuHeight:420,children:({containerRef:t,menuRef:o,menuStyle:d,handleTriggerKeyDown:u})=>s.jsxs("div",{className:"parameters-dropdown",ref:t,children:[s.jsx(S,{content:`${A} (↑↓ Tab)`,showArrow:!1,children:s.jsxs("button",{className:`parameters-dropdown__trigger ${f?"parameters-dropdown__trigger--open":""}`,onMouseDown:V,onKeyDown:u,type:"button",disabled:g,children:[s.jsx("span",{className:"parameters-dropdown__label",children:A}),s.jsx(U,{size:14,className:`parameters-dropdown__icon ${f?"parameters-dropdown__icon--open":""}`})]})}),f&&P.createPortal(s.jsxs("div",{ref:o,className:`parameters-dropdown__menu parameters-dropdown__menu--flat ${W}`,style:{...d,zIndex:J.DROPDOWN_PORTAL},onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:[s.jsxs("div",{className:"parameters-dropdown__header",children:[s.jsx(X,{size:14}),s.jsx("span",{children:h==="zh"?"设置生成参数 (↑↓←→ Tab)":"Parameters (↑↓←→ Tab)"})]}),s.jsx("div",{className:"parameters-dropdown__sections",children:a.map((e,r)=>{var v;const m=n[e.id],_=r===T;return s.jsxs("div",{className:`parameters-dropdown__section ${_?"parameters-dropdown__section--highlighted":""}`,children:[s.jsx("div",{className:"parameters-dropdown__section-title",children:e.label}),e.valueType==="enum"?s.jsx("div",{className:"parameters-dropdown__options",children:(v=e.options)==null?void 0:v.map((i,w)=>{const j=m===i.value,L=_&&w===y;return s.jsxs("button",{type:"button",className:`parameters-dropdown__option ${j?"parameters-dropdown__option--selected":""} ${L?"parameters-dropdown__option--highlighted":""}`,onClick:()=>R(e.id,i.value),onMouseEnter:()=>{M(r),b(w)},children:[s.jsx("span",{className:"parameters-dropdown__option-label",children:i.label.split("(")[0].trim()}),j&&s.jsx(Z,{size:12,className:"parameters-dropdown__option-check"})]},i.value)})}):s.jsxs("div",{className:`parameters-dropdown__field ${z(e)?"parameters-dropdown__field--with-action":""}`,children:[s.jsx("input",{type:e.valueType==="number"?"number":"text",className:"parameters-dropdown__field-input",value:m||"",placeholder:e.description||e.label,min:e.valueType==="number"?e.min:void 0,max:e.valueType==="number"?e.max:void 0,step:e.valueType==="number"?e.step:void 0,onChange:i=>k(e.id,i.target.value),onMouseDown:i=>i.stopPropagation(),onKeyDown:i=>i.stopPropagation()}),z(e)&&s.jsx(S,{content:h==="zh"?"随机生成种子":"Randomize seed",showArrow:!1,children:s.jsx("button",{type:"button",className:"parameters-dropdown__field-action",onClick:()=>H(e),onMouseDown:i=>i.stopPropagation(),children:s.jsx(q,{size:14})})})]})]},e.id)})})]}),document.body)]})})};export{Y as P};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
`).toLowerCase();return o.split(/\s+/).every(y=>c.includes(y))}function ee(t,s){return!s.skillTag||s.skillTag==="all"||t.tags.includes(s.skillTag)}function se(t,s){return dt({...t,tags:t.tags},{...s,skillTag:"all"})}function oe(t){return t||"text"}function ut(t,s){return s.length>t.length?s:t}function Y(t){return t.kind!=="none"}function le(t){const s=f.resolveMetadata(t.content),o=x(s.sourceContent||t.content),n=x(s.content||t.content),c=oe(t.modelType||s.modelType),r=J([c,...s.tags||[]]);return{id:`prompt-history-manual-${t.id}`,taskId:t.id,taskIds:[],sourceSentPrompt:o,sourceSentPrompts:[o],category:c,status:E.COMPLETED,title:W(n,n,s.title),initialPrompt:n,sentPrompt:n,tags:r,createdAt:t.timestamp,resultPreview:{kind:"none",text:"暂无结果"},resultPreviews:[],resultCount:0,pinned:!!t.pinned||f.isContentPinned(n)}}function ne(t){const s=new Map;for(const o of t){const n=o.sentPrompt.trim(),c=o.sourceSentPrompt.trim();if(!n||f.isContentDeleted(n)||f.isContentDeleted(c))continue;const r=s.get(n);if(!r){s.set(n,{...o,id:`prompt-history-${n}`,resultPreviews:Y(o.resultPreview)?[o.resultPreview]:[],resultCount:Y(o.resultPreview)?1:0,pinned:f.isContentPinned(o.sentPrompt)});continue}r.taskIds.push(...o.taskIds),r.sourceSentPrompts=Array.from(new Set([...r.sourceSentPrompts,...o.sourceSentPrompts])),r.tags=Array.from(new Set([...r.tags,...o.tags])),r.title=ut(r.title,o.title),r.initialPrompt=ut(r.initialPrompt,o.initialPrompt),o.createdAt>r.createdAt&&(r.createdAt=o.createdAt,r.completedAt=o.completedAt,r.taskId=o.taskId,r.status=o.status,r.category=o.category,r.model=o.model||r.model),o.skillName&&!r.skillName&&(r.skillName=o.skillName),o.skillId&&!r.skillId&&(r.skillId=o.skillId),Y(o.resultPreview)&&(r.resultPreviews.push(o.resultPreview),r.resultCount=r.resultPreviews.length,r.resultPreview=r.resultPreviews[0])}return Array.from(s.values()).sort((o,n)=>o.pinned&&!n.pinned?-1:!o.pinned&&n.pinned?1:n.createdAt-o.createdAt)}async function re(t={}){const s=Math.min(Math.max(t.limit??Xt,1),80),o=Math.max(t.offset??0,0);let n=0;const c=[];let r=!0;for(f.getHistory().forEach(g=>c.push(le(g)));r;){const g=await Lt.getPromptHistoryTaskSummaries({offset:n,limit:Yt,statuses:[E.COMPLETED,E.FAILED,E.CANCELLED]});for(const m of g.items){const S=te(qt(m));c.push(S)}n=g.nextOffset,(!g.hasMore||g.items.length===0)&&(r=!1)}const y=ne(c),h=new Set;y.forEach(g=>{se(g,t)&&g.category==="agent"&&g.tags.filter(m=>m!=="agent").forEach(m=>h.add(m))});const j=y.filter(g=>dt(g,t)&&ee(g,t)),P=j.length;return{records:j.slice(o,o+s),nextOffset:o+Math.min(s,Math.max(P-o,0)),hasMore:o+s<P,total:P,skillTags:Array.from(h).sort((g,m)=>g.localeCompare(m,"zh-CN"))}}function ae(t,s,o){return f.setContentPinned(t,s,o)}function ie(t){f.deleteContents(t)}function ce(t){const s=t.content.trim();if(!s)return!1;const o=t.modelType||t.category;return f.addHistory(s,t.hasSelection,o),(t.title!==void 0||t.tags!==void 0||o)&&f.setHistoryOverride(s,{title:t.title,sentPrompt:s,tags:t.tags,modelType:o}),t.pinned!==void 0&&f.setContentPinned(s,t.pinned,o),!0}function pe(t){const s=Array.from(new Set((t.sourceSentPrompts||[t.sourceSentPrompt]).map(j=>j.trim()).filter(Boolean))),o=s[0]||"";if(!o)return!1;const n=f.resolveMetadata(o),c=t.sentPrompt.trim(),r=t.category?t.category:void 0,y=!!(t.allowSentPromptEdit&&c),h=y?c:n.content||c||o;return y&&h!==n.content&&f.setContentEdited(s,h,r),!!f.setHistoryOverride(o,{title:t.title,sentPrompt:h,tags:t.tags,modelType:r})}const Z=[{value:"all",label:"全部"},{value:"image",label:"图片"},{value:"video",label:"视频"},{value:"audio",label:"音频"},{value:"text",label:"文本"},{value:"agent",label:"Agent"},{value:"ppt-common",label:"PPT公共"},{value:"ppt-slide",label:"PPT页面"}];function ue(t){const s=[],o=new Set;return t.split(/[\n,,;;]+/).map(n=>n.trim()).filter(Boolean).forEach(n=>{const c=n.slice(0,60);o.has(c)||(o.add(c),s.push(c))}),s}function me(t){var s;return((s=Z.find(o=>o.value===t))==null?void 0:s.label)||t}function b(t){return t==="all"?void 0:t}function de(t){return new Intl.DateTimeFormat("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function he(t){return t.kind==="audio"?t.title||t.text||t.url||"音频结果":t.kind==="text"?t.title?`${t.title} ${t.text}`:t.text:t.kind==="image"||t.kind==="video"?"":t.text}function ge(t,s,o){return t.kind==="image"?{id:`${s.id}-result-${o}`,url:t.url,type:"image",title:t.title||s.title,prompt:s.sentPrompt}:t.kind==="video"?{id:`${s.id}-result-${o}`,url:t.url,type:"video",posterUrl:t.posterUrl,title:t.title||s.title,duration:t.duration,prompt:s.sentPrompt}:t.kind==="audio"&&t.url?{id:`${s.id}-result-${o}`,url:t.url,type:"audio",posterUrl:t.coverUrl,title:t.title||s.title,duration:t.duration,prompt:s.sentPrompt}:null}function fe(t){var o;return(((o=t.resultPreviews)==null?void 0:o.length)>0?t.resultPreviews:t.resultPreview?[t.resultPreview]:[]).map((n,c)=>ge(n,t,c)).filter(n=>!!n)}function mt(t){return!!(t&&t.resultCount===0)}const _e=({initialCategory:t})=>{const[s,o]=p.useState([]),[n,c]=p.useState(t||"all"),[r,y]=p.useState("all"),[h,j]=p.useState(""),[P,g]=p.useState(0),[m,S]=p.useState(!1),[U,z]=p.useState(0),[$,ht]=p.useState([]),[B,q]=p.useState(null),[M,F]=p.useState(new Set),[tt,gt]=p.useState([]),[ft,yt]=p.useState(0),[Pt,et]=p.useState(!1),[i,R]=p.useState(null),V=p.useRef(!1),D=p.useRef(0),K=p.useRef(null),st=p.useRef(0),H=B!==null;p.useEffect(()=>{k.trackPromptAction({action:"open_tool",surface:"prompt_history_tool",source:"toolbox",status:"success",metadata:{tool_id:"prompt-history"}})},[]),p.useEffect(()=>{t&&(c(t),y("all"),j(""))},[t]);const v=p.useCallback(async(e="reset",u=0)=>{if(e==="more"&&V.current)return;const a=D.current+1;D.current=a,V.current=!0,q(e);try{const d=await re({category:n,skillTag:r,search:h,offset:u,limit:30});if(a!==D.current)return;o(_=>e==="more"?[..._,...d.records]:d.records),g(d.nextOffset),S(d.hasMore),z(d.total),ht(d.skillTags),e==="reset"&&(F(new Set),K.current=null)}catch(d){if(a!==D.current)return;k.trackPromptAction({action:"load_history",surface:"prompt_history_tool",promptType:b(n),status:"failed",metadata:{mode:e,has_search:h.trim().length>0,has_skill_filter:r!=="all"}}),console.error("[PromptHistoryTool] 加载提示词历史失败:",d),T.error("我的提示词加载失败")}finally{a===D.current&&(V.current=!1,q(null))}},[n,h,r]);p.useEffect(()=>{v("reset")},[v]),p.useEffect(()=>{r!=="all"&&!$.includes(r)&&y("all")},[r,$]);const C=p.useMemo(()=>s.map(e=>e.id),[s]),N=p.useMemo(()=>s.filter(e=>M.has(e.id)),[s,M]),A=p.useMemo(()=>ue((i==null?void 0:i.tagsInput)||""),[i==null?void 0:i.tagsInput]),xt=p.useMemo(()=>`共 ${U} 条,已加载 ${s.length} 条`,[s.length,U]),_t=C.length>0&&C.every(e=>M.has(e)),jt=p.useCallback(()=>{k.trackPromptAction({action:"refresh",surface:"prompt_history_tool",promptType:b(n),metadata:{has_search:h.trim().length>0,has_skill_filter:r!=="all"}}),v("reset")},[n,v,h,r]),vt=p.useCallback(e=>{e!==n&&(k.trackPromptAction({action:"filter_category",surface:"prompt_history_tool",promptType:b(e),metadata:{category:e}}),c(e))},[n]),kt=p.useCallback(e=>{const u=e.target.value;k.trackPromptAction({action:"filter_skill",surface:"prompt_history_tool",promptType:b(n),metadata:{selection:u==="all"?"all":"custom"}}),y(u)},[n]),bt=p.useCallback(e=>{const u=e.target.value;j(u);const a=u.trim();if(!a)return;const d=Date.now();d-st.current<2e3||(st.current=d,k.trackPromptAction({action:"search",surface:"prompt_history_tool",promptType:b(n),prompt:a,metadata:{has_skill_filter:r!=="all"}}))},[n,r]),Ct=p.useCallback((e,u,a)=>{F(d=>{const _=new Set(d),O=K.current;if(a&&O){const w=C.indexOf(O),I=C.indexOf(e);if(w>=0&&I>=0){const[Dt,Ht]=w<I?[w,I]:[I,w];return C.slice(Dt,Ht+1).forEach(nt=>{u?_.add(nt):_.delete(nt)}),_}}return u?_.add(e):_.delete(e),K.current=e,_})},[C]),Tt=p.useCallback(e=>{F(u=>{const a=new Set(u);return C.forEach(d=>{e?a.add(d):a.delete(d)}),a})},[C]),St=p.useCallback(()=>{N.length!==0&&(ie(N.flatMap(e=>e.sourceSentPrompts)),k.trackPromptAction({action:"delete",surface:"prompt_history_tool",itemCount:N.length,status:"success"}),T.success(`已删除 ${N.length} 条提示词`),v("reset"))},[v,N]),Nt=p.useCallback(async(e,u)=>{u.stopPropagation();try{await Ot(e.sentPrompt),k.trackPromptAction({action:"copy",surface:"prompt_history_tool",promptType:b(e.category),prompt:e.sentPrompt,status:"success",metadata:{record_status:e.status,initial_differs_from_sent:e.initialPrompt!==e.sentPrompt}}),T.success("提示词已复制")}catch(a){console.error("[PromptHistoryTool] 复制提示词失败:",a),T.error("复制失败")}},[]),wt=p.useCallback(e=>{var u;e.shiftKey&&((u=window.getSelection())==null||u.removeAllRanges())},[]),It=p.useCallback((e,u)=>{u.stopPropagation();const a=!e.pinned;ae(e.sentPrompt,a,e.category),k.trackPromptAction({action:a?"pin":"unpin",surface:"prompt_history_tool",promptType:b(e.category),prompt:e.sentPrompt,status:"success"}),T.success(a?"已置顶提示词":"已取消置顶"),v("reset")},[v]),At=p.useCallback((e,u)=>{u.stopPropagation(),R({mode:"edit",record:e,title:e.title,sentPrompt:e.sentPrompt,tagsInput:e.tags.join(", "),category:e.category,pinned:e.pinned})},[]),ot=p.useCallback((e,u)=>{u==null||u.stopPropagation();const a=n==="all"?"text":n;R({mode:"create",record:e,title:(e==null?void 0:e.title)||"",sentPrompt:(e==null?void 0:e.sentPrompt)||"",tagsInput:(e==null?void 0:e.tags.join(", "))||"",category:(e==null?void 0:e.category)||a,pinned:(e==null?void 0:e.pinned)||!1})},[n]),G=p.useCallback(()=>{R(null)},[]),Et=p.useCallback(()=>{var a,d,_,O,w,I;if(!i)return;if(!i.sentPrompt.trim()){T.warning("发送提示词不能为空");return}const e=i.mode==="edit"&&mt(i.record);if(!(i.mode==="create"?ce({title:i.title,content:i.sentPrompt,tags:A,category:i.category,pinned:i.pinned}):pe({sourceSentPrompt:((a=i.record)==null?void 0:a.sourceSentPrompt)||"",sourceSentPrompts:(d=i.record)==null?void 0:d.sourceSentPrompts,title:i.title,sentPrompt:e?i.sentPrompt:((_=i.record)==null?void 0:_.sentPrompt)||i.sentPrompt,tags:A,category:(O=i.record)==null?void 0:O.category,...e?{allowSentPromptEdit:!0}:{}}))){T.error("保存失败");return}k.trackPromptAction({action:i.mode==="create"?"create":"edit",surface:"prompt_history_tool",promptType:b(i.category),prompt:i.sentPrompt,status:"success",metadata:{tag_count:A.length,title_changed:i.mode==="edit"?i.title.trim()!==((w=i.record)==null?void 0:w.title):!!i.title.trim(),prompt_changed:i.mode==="create"||e&&i.sentPrompt.trim()!==((I=i.record)==null?void 0:I.sentPrompt)}}),T.success(i.mode==="create"?"提示词已创建":"提示词已更新"),R(null),v("reset")},[i,A,v]),L=p.useCallback(e=>{R(u=>u&&{...u,...e})},[]),Mt=p.useCallback((e,u,a)=>{e.stopPropagation(),u.length!==0&&(gt(u),yt(a),et(!0))},[]),Rt=p.useCallback(e=>{const u=e.currentTarget;u.scrollHeight-u.scrollTop-u.clientHeight<180&&m&&!H&&(k.trackPromptAction({action:"load_more",surface:"prompt_history_tool",promptType:b(n),itemCount:s.length,metadata:{has_search:h.trim().length>0,has_skill_filter:r!=="all",next_offset:P}}),v("more",P))},[n,m,v,H,P,s.length,h,r]),lt=(i==null?void 0:i.mode)==="create"||mt(i==null?void 0:i.record);return l.jsxs("div",{className:"prompt-history-tool",children:[l.jsxs("div",{className:"prompt-history-tool__toolbar",children:[l.jsxs("div",{className:"prompt-history-tool__search",children:[l.jsx(Ut,{size:14}),l.jsx("input",{value:h,onChange:bt,placeholder:"搜索标题、提示词、标签"})]}),l.jsx("button",{type:"button",className:"prompt-history-tool__icon-btn",onClick:()=>ot(),"aria-label":"新建提示词",children:l.jsx(at,{size:16})}),l.jsx("button",{type:"button",className:"prompt-history-tool__icon-btn",onClick:jt,disabled:H,"aria-label":"刷新",children:H?l.jsx(X,{size:16}):l.jsx($t,{size:16})})]}),l.jsx("div",{className:"prompt-history-tool__filters",children:Z.map(e=>l.jsx("button",{type:"button",className:n===e.value?"is-active":"",onClick:()=>vt(e.value),children:e.label},e.value))}),$.length>0&&l.jsx("div",{className:"prompt-history-tool__skill-filter",children:l.jsxs("select",{value:r,onChange:kt,children:[l.jsx("option",{value:"all",children:"全部 Skill"}),$.map(e=>l.jsx("option",{value:e,children:e},e))]})}),l.jsxs("div",{className:"prompt-history-tool__summary",children:[l.jsx("span",{children:xt}),N.length>0&&l.jsxs("button",{type:"button",className:"prompt-history-tool__delete-btn",onClick:St,children:[l.jsx(zt,{size:14}),"删除 ",N.length," 条"]}),B==="reset"&&l.jsx(X,{size:14,className:"prompt-history-tool__summary-loading"})]}),l.jsxs("div",{className:"prompt-history-tool__table-wrap",onScroll:Rt,children:[l.jsxs("table",{className:"prompt-history-tool__table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{className:"prompt-history-tool__col-select",children:l.jsx("input",{type:"checkbox","aria-label":"选择已加载提示词",checked:_t,onChange:e=>Tt(e.target.checked)})}),l.jsx("th",{className:"prompt-history-tool__col-type",children:"类型"}),l.jsx("th",{className:"prompt-history-tool__col-title",children:"标题"}),l.jsx("th",{children:"发送提示词"}),l.jsx("th",{className:"prompt-history-tool__col-tags",children:"标签"}),l.jsx("th",{className:"prompt-history-tool__col-result",children:"结果"}),l.jsx("th",{className:"prompt-history-tool__col-time",children:"时间"}),l.jsx("th",{className:"prompt-history-tool__col-actions",children:"操作"})]})}),l.jsx("tbody",{children:s.map(e=>{const u=fe(e);return l.jsxs("tr",{className:M.has(e.id)?"is-selected":"",children:[l.jsx("td",{children:l.jsx("input",{type:"checkbox","aria-label":`选择 ${e.title}`,checked:M.has(e.id),onMouseDown:wt,onClick:a=>a.stopPropagation(),onChange:a=>Ct(e.id,a.target.checked,a.nativeEvent instanceof MouseEvent?a.nativeEvent.shiftKey:!1)})}),l.jsx("td",{children:l.jsx("span",{className:`prompt-history-tool__type prompt-history-tool__type--${e.category}`,children:me(e.category)})}),l.jsxs("td",{children:[l.jsx("div",{className:"prompt-history-tool__title",children:e.title}),e.initialPrompt!==e.sentPrompt&&l.jsxs("div",{className:"prompt-history-tool__subtext",children:["初始:",e.initialPrompt]}),e.sourceSentPrompt!==e.sentPrompt&&l.jsxs("div",{className:"prompt-history-tool__subtext",children:["原始:",e.sourceSentPrompt]})]}),l.jsx("td",{children:l.jsx(it,{placement:"left",delay:120,overlayClassName:"prompt-history-tool__prompt-popover",content:l.jsx("div",{className:"prompt-history-tool__prompt-full",children:e.sentPrompt}),children:l.jsx("button",{type:"button",className:"prompt-history-tool__prompt",onClick:a=>Nt(e,a),"aria-label":`复制提示词:${e.title}`,children:e.sentPrompt})})}),l.jsx("td",{children:l.jsx("div",{className:"prompt-history-tool__tags",children:e.tags.map(a=>l.jsx("span",{children:a},a))})}),l.jsx("td",{children:u.length>0?l.jsxs("div",{className:"prompt-history-tool__media-grid",children:[u.slice(0,4).map((a,d)=>l.jsx(it,{placement:"left",delay:80,overlayClassName:"prompt-history-tool__media-popover",content:a.type==="video"?l.jsx("video",{src:a.url,poster:a.posterUrl,controls:!0,muted:!0,preload:"metadata"}):l.jsx(ct,{src:a.posterUrl||a.url,alt:a.title||e.title,showSkeleton:!1,eager:!0}),children:l.jsx("button",{type:"button",className:"prompt-history-tool__media-thumb",onClick:_=>Mt(_,u,d),children:a.type==="video"?l.jsx(Gt,{src:a.url,poster:a.posterUrl,alt:a.title||e.title,thumbnailSize:"small",activateVideoOnClick:!1}):l.jsx(ct,{src:a.posterUrl||a.url,alt:a.title||e.title,showSkeleton:!1,eager:!0})})},a.id||a.url)),e.resultCount>4&&l.jsxs("span",{className:"prompt-history-tool__media-count",children:["+",e.resultCount-4]})]}):l.jsx("div",{className:"prompt-history-tool__result-text",children:he(e.resultPreview)})}),l.jsx("td",{children:de(e.createdAt)}),l.jsx("td",{children:l.jsxs("div",{className:"prompt-history-tool__actions",children:[l.jsx("button",{type:"button",className:"prompt-history-tool__create-btn",onClick:a=>ot(e,a),"aria-label":`基于 ${e.title} 创建`,children:l.jsx(at,{size:15})}),l.jsx("button",{type:"button",className:"prompt-history-tool__edit-btn",onClick:a=>At(e,a),"aria-label":`编辑 ${e.title}`,children:l.jsx(Bt,{size:15})}),l.jsx("button",{type:"button",className:`prompt-history-tool__pin-btn ${e.pinned?"is-pinned":""}`,onClick:a=>It(e,a),"aria-label":e.pinned?"取消置顶":"置顶",children:e.pinned?l.jsx(Ft,{size:15}):l.jsx(Vt,{size:15})})]})})]},e.id)})})]}),!H&&s.length===0&&l.jsx("div",{className:"prompt-history-tool__empty",children:"暂无我的提示词"}),B==="more"&&l.jsxs("div",{className:"prompt-history-tool__loading-more",children:[l.jsx(X,{size:14}),"加载中..."]}),!m&&s.length>0&&l.jsx("div",{className:"prompt-history-tool__done",children:"已加载全部"})]}),l.jsxs("div",{className:"prompt-history-tool__footer",children:[l.jsxs("div",{className:"prompt-history-tool__hint",children:[l.jsx(Kt,{size:13}),"点击提示词复制,勾选列选择,Shift 连选"]}),l.jsx("span",{children:m?"向下滚动自动加载":"没有更多了"})]}),l.jsx(Qt,{visible:Pt,items:tt,initialIndex:ft,onClose:()=>et(!1),showThumbnails:tt.length>1,videoAutoPlay:!0}),i&&l.jsx("div",{className:"prompt-history-tool__edit-mask",role:"presentation",onMouseDown:G,children:l.jsxs("form",{className:"prompt-history-tool__edit-dialog",onMouseDown:e=>e.stopPropagation(),onSubmit:e=>{e.preventDefault(),Et()},children:[l.jsxs("div",{className:"prompt-history-tool__edit-header",children:[l.jsxs("div",{children:[l.jsx("h3",{children:i.mode==="create"?"创建提示词":"编辑提示词"}),l.jsx("p",{children:i.mode==="create"?"填写类型、置顶、标题、发送提示词和标签":lt?"修改标题、发送提示词和标签":"修改标题和标签,发送提示词保持不变"})]}),l.jsx("button",{type:"button",className:"prompt-history-tool__edit-close",onClick:G,"aria-label":"关闭编辑弹窗",children:"×"})]}),i.mode==="create"&&l.jsxs("div",{className:"prompt-history-tool__field-row",children:[l.jsxs("label",{className:"prompt-history-tool__field",children:[l.jsx("span",{children:"类型"}),l.jsx("select",{value:i.category,onChange:e=>L({category:e.target.value}),children:Z.filter(e=>e.value!=="all").map(e=>l.jsx("option",{value:e.value,children:e.label},e.value))})]}),l.jsxs("label",{className:"prompt-history-tool__switch-field",children:[l.jsx("input",{type:"checkbox",checked:i.pinned,onChange:e=>L({pinned:e.target.checked})}),l.jsx("span",{children:"置顶"})]})]}),l.jsxs("label",{className:"prompt-history-tool__field",children:[l.jsx("span",{children:"标题"}),l.jsx("input",{value:i.title,onChange:e=>L({title:e.target.value}),maxLength:80,placeholder:"输入标题"})]}),l.jsxs("label",{className:"prompt-history-tool__field",children:[l.jsx("span",{children:"发送提示词"}),l.jsx("textarea",{value:i.sentPrompt,onChange:e=>L({sentPrompt:e.target.value}),readOnly:!lt,rows:8,maxLength:2e3,placeholder:"输入发送提示词"})]}),l.jsxs("label",{className:"prompt-history-tool__field",children:[l.jsx("span",{children:"标签"}),l.jsx("textarea",{className:"prompt-history-tool__tags-input",value:i.tagsInput,onChange:e=>L({tagsInput:e.target.value}),rows:2,placeholder:"多个标签用逗号或换行分隔"})]}),A.length>0&&l.jsx("div",{className:"prompt-history-tool__edit-tags",children:A.map(e=>l.jsx("span",{children:e},e))}),l.jsxs("div",{className:"prompt-history-tool__edit-footer",children:[l.jsx("button",{type:"button",onClick:G,children:"取消"}),l.jsx("button",{type:"submit",className:"is-primary",children:"保存"})]})]})})]})};export{_e as PromptHistoryTool,_e as default};
|
|
1
|
+
import{iz as f,dA as Lt,dB as E,lJ as rt,bg as Q,r as p,am as k,M as C,ba as Ot,j as l,aH as Ut,l as at,jV as J,f as $t,dq as zt,E as it,R as ct,lK as Bt,a5 as Vt,a3 as Ft,lL as Kt}from"./startup-app-eD_rQhSh.js";import{V as Gt,U as Qt}from"./ai-chat-BO5vbKZW.js";import"./startup-runtime-DTmhLESk.js";const Jt=30,Xt=80,Yt=20,Zt=2e3;function x(t,s=Zt){return typeof t!="string"?"":t.trim().slice(0,s)}function Z(t){const s=[],o=new Set;return t.forEach(n=>{const c=x(n,60);!c||o.has(c)||(o.add(c),s.push(c))}),s}function W(t,s,o){const n=x(o,80);if(n)return n;const c=x(t,120),r=x(s,120);return c&&r&&c!==r?c:(r||c||"未命名提示词").slice(0,Yt)}function Wt(t){var o,n,c,r;const s=(o=t.params.promptMeta)==null?void 0:o.category;return s||(t.params.pptSlideImage||(n=t.params.pptSlidePrompt)!=null&&n.trim()?"ppt-slide":t.type===Q.IMAGE?"image":t.type===Q.VIDEO?"video":t.type===Q.AUDIO?"audio":(c=t.params.promptMeta)!=null&&c.skillName||(r=t.params.promptMeta)!=null&&r.skillId?"agent":"text")}function pt(t,s){var c,r,y,h,j,P,g;if(t.status===E.FAILED)return{kind:"error",text:((c=t.error)==null?void 0:c.message)||"任务失败"};if(t.status===E.CANCELLED)return{kind:"error",text:"任务已取消"};const o=t.result;if(!o)return{kind:"none",text:"暂无结果"};if(s==="image"||s==="ppt-slide"){const m=((r=o.thumbnailUrls)==null?void 0:r[0])||o.thumbnailUrl||((y=o.urls)==null?void 0:y[0])||o.url;return m?{kind:"image",url:m,title:o.title}:{kind:"none",text:"暂无图片预览"}}if(s==="video"){const m=o.url||((h=o.urls)==null?void 0:h[0]),S=o.thumbnailUrl||((j=o.thumbnailUrls)==null?void 0:j[0])||o.previewImageUrl;return m?{kind:"video",url:m,posterUrl:S,title:o.title,duration:o.duration}:{kind:"none",text:"暂无视频预览"}}if(s==="audio"){const m=(P=o.clips)==null?void 0:P[0],S=(m==null?void 0:m.audioUrl)||((g=o.urls)==null?void 0:g[0])||o.url,U=(m==null?void 0:m.imageLargeUrl)||(m==null?void 0:m.imageUrl)||o.previewImageUrl||o.thumbnailUrl,z=o.title||(m==null?void 0:m.title)||t.params.title;return{kind:"audio",url:S,coverUrl:U,title:z,text:o.lyricsText||o.lyricsTitle,duration:(m==null?void 0:m.duration)??o.duration}}const n=o.chatResponse||o.lyricsText||o.title||(o.url?"结果已生成":"");return n?{kind:"text",text:n.slice(0,500),title:o.title||o.lyricsTitle}:{kind:"none",text:"暂无文本预览"}}function qt(t){const s=t.params.promptMeta,o=Wt(t),n=x(rt((s==null?void 0:s.sentPrompt)||(o==="ppt-slide"?t.params.pptSlidePrompt:void 0)||t.params.prompt)),c=x(rt((s==null?void 0:s.initialPrompt)||t.params.sourcePrompt||t.params.rawInput||n)),r=x(s==null?void 0:s.skillName,80),y=x(s==null?void 0:s.skillId,120),h=((s==null?void 0:s.knowledgeContextRefs)||t.params.knowledgeContextRefs||[]).map(P=>P!=null&&P.title?`知识库:${x(P.title,40)}`:void 0),j=Z([o,r||void 0,...(s==null?void 0:s.tags)||[],...h]);return{id:`prompt-history-${t.id}`,taskId:t.id,taskIds:[t.id],sourceSentPrompt:n,sourceSentPrompts:[n],category:o,status:t.status,title:W(c,n,s==null?void 0:s.title),initialPrompt:c,sentPrompt:n,tags:j,skillId:y||void 0,skillName:r||void 0,model:x(t.params.model,120)||void 0,createdAt:t.completedAt||t.createdAt,completedAt:t.completedAt,resultPreview:pt(t,o),resultPreviews:[pt(t,o)],resultCount:1,pinned:f.isContentPinned(n)}}function te(t){const s=f.getHistoryOverride(t.sourceSentPrompt),o=x((s==null?void 0:s.content)||(s==null?void 0:s.sentPrompt)||f.resolveContent(t.sourceSentPrompt)||t.sentPrompt),n=x(s==null?void 0:s.title,80)||(o===t.sentPrompt?t.title:W(t.initialPrompt,o)),c=(s==null?void 0:s.tags)!==void 0?Z(s.tags):t.tags;return{...t,sentPrompt:o,title:n,tags:c,pinned:f.isContentPinned(o)}}function dt(t,s){var r;if(s.category&&s.category!=="all"&&t.category!==s.category||s.skillTag&&s.skillTag!=="all"&&!t.tags.includes(s.skillTag))return!1;const o=(r=s.search)==null?void 0:r.trim().toLowerCase();if(!o)return!0;const n=t.resultPreview.kind==="text"||t.resultPreview.kind==="error"||t.resultPreview.kind==="none"?t.resultPreview.text:t.resultPreview.title,c=[t.title,t.initialPrompt,t.sentPrompt,t.sourceSentPrompts.join(" "),t.tags.join(" "),t.skillName,t.model,n].filter(Boolean).join(`
|
|
2
|
+
`).toLowerCase();return o.split(/\s+/).every(y=>c.includes(y))}function ee(t,s){return!s.skillTag||s.skillTag==="all"||t.tags.includes(s.skillTag)}function se(t,s){return dt({...t,tags:t.tags},{...s,skillTag:"all"})}function oe(t){return t||"text"}function ut(t,s){return s.length>t.length?s:t}function X(t){return t.kind!=="none"}function le(t){const s=f.resolveMetadata(t.content),o=x(s.sourceContent||t.content),n=x(s.content||t.content),c=oe(t.modelType||s.modelType),r=Z([c,...s.tags||[]]);return{id:`prompt-history-manual-${t.id}`,taskId:t.id,taskIds:[],sourceSentPrompt:o,sourceSentPrompts:[o],category:c,status:E.COMPLETED,title:W(n,n,s.title),initialPrompt:n,sentPrompt:n,tags:r,createdAt:t.timestamp,resultPreview:{kind:"none",text:"暂无结果"},resultPreviews:[],resultCount:0,pinned:!!t.pinned||f.isContentPinned(n)}}function ne(t){const s=new Map;for(const o of t){const n=o.sentPrompt.trim(),c=o.sourceSentPrompt.trim();if(!n||f.isContentDeleted(n)||f.isContentDeleted(c))continue;const r=s.get(n);if(!r){s.set(n,{...o,id:`prompt-history-${n}`,resultPreviews:X(o.resultPreview)?[o.resultPreview]:[],resultCount:X(o.resultPreview)?1:0,pinned:f.isContentPinned(o.sentPrompt)});continue}r.taskIds.push(...o.taskIds),r.sourceSentPrompts=Array.from(new Set([...r.sourceSentPrompts,...o.sourceSentPrompts])),r.tags=Array.from(new Set([...r.tags,...o.tags])),r.title=ut(r.title,o.title),r.initialPrompt=ut(r.initialPrompt,o.initialPrompt),o.createdAt>r.createdAt&&(r.createdAt=o.createdAt,r.completedAt=o.completedAt,r.taskId=o.taskId,r.status=o.status,r.category=o.category,r.model=o.model||r.model),o.skillName&&!r.skillName&&(r.skillName=o.skillName),o.skillId&&!r.skillId&&(r.skillId=o.skillId),X(o.resultPreview)&&(r.resultPreviews.push(o.resultPreview),r.resultCount=r.resultPreviews.length,r.resultPreview=r.resultPreviews[0])}return Array.from(s.values()).sort((o,n)=>o.pinned&&!n.pinned?-1:!o.pinned&&n.pinned?1:n.createdAt-o.createdAt)}async function re(t={}){const s=Math.min(Math.max(t.limit??Jt,1),80),o=Math.max(t.offset??0,0);let n=0;const c=[];let r=!0;for(f.getHistory().forEach(g=>c.push(le(g)));r;){const g=await Lt.getPromptHistoryTaskSummaries({offset:n,limit:Xt,statuses:[E.COMPLETED,E.FAILED,E.CANCELLED]});for(const m of g.items){const S=te(qt(m));c.push(S)}n=g.nextOffset,(!g.hasMore||g.items.length===0)&&(r=!1)}const y=ne(c),h=new Set;y.forEach(g=>{se(g,t)&&g.category==="agent"&&g.tags.filter(m=>m!=="agent").forEach(m=>h.add(m))});const j=y.filter(g=>dt(g,t)&&ee(g,t)),P=j.length;return{records:j.slice(o,o+s),nextOffset:o+Math.min(s,Math.max(P-o,0)),hasMore:o+s<P,total:P,skillTags:Array.from(h).sort((g,m)=>g.localeCompare(m,"zh-CN"))}}function ae(t,s,o){return f.setContentPinned(t,s,o)}function ie(t){f.deleteContents(t)}function ce(t){const s=t.content.trim();if(!s)return!1;const o=t.modelType||t.category;return f.addHistory(s,t.hasSelection,o),(t.title!==void 0||t.tags!==void 0||o)&&f.setHistoryOverride(s,{title:t.title,sentPrompt:s,tags:t.tags,modelType:o}),t.pinned!==void 0&&f.setContentPinned(s,t.pinned,o),!0}function pe(t){const s=Array.from(new Set((t.sourceSentPrompts||[t.sourceSentPrompt]).map(j=>j.trim()).filter(Boolean))),o=s[0]||"";if(!o)return!1;const n=f.resolveMetadata(o),c=t.sentPrompt.trim(),r=t.category?t.category:void 0,y=!!(t.allowSentPromptEdit&&c),h=y?c:n.content||c||o;return y&&h!==n.content&&f.setContentEdited(s,h,r),!!f.setHistoryOverride(o,{title:t.title,sentPrompt:h,tags:t.tags,modelType:r})}const Y=[{value:"all",label:"全部"},{value:"image",label:"图片"},{value:"video",label:"视频"},{value:"audio",label:"音频"},{value:"text",label:"文本"},{value:"agent",label:"Agent"},{value:"ppt-common",label:"PPT公共"},{value:"ppt-slide",label:"PPT页面"}];function ue(t){const s=[],o=new Set;return t.split(/[\n,,;;]+/).map(n=>n.trim()).filter(Boolean).forEach(n=>{const c=n.slice(0,60);o.has(c)||(o.add(c),s.push(c))}),s}function me(t){var s;return((s=Y.find(o=>o.value===t))==null?void 0:s.label)||t}function b(t){return t==="all"?void 0:t}function de(t){return new Intl.DateTimeFormat("zh-CN",{month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function he(t){return t.kind==="audio"?t.title||t.text||t.url||"音频结果":t.kind==="text"?t.title?`${t.title} ${t.text}`:t.text:t.kind==="image"||t.kind==="video"?"":t.text}function ge(t,s,o){return t.kind==="image"?{id:`${s.id}-result-${o}`,url:t.url,type:"image",title:t.title||s.title,prompt:s.sentPrompt}:t.kind==="video"?{id:`${s.id}-result-${o}`,url:t.url,type:"video",posterUrl:t.posterUrl,title:t.title||s.title,duration:t.duration,prompt:s.sentPrompt}:t.kind==="audio"&&t.url?{id:`${s.id}-result-${o}`,url:t.url,type:"audio",posterUrl:t.coverUrl,title:t.title||s.title,duration:t.duration,prompt:s.sentPrompt}:null}function fe(t){var o;return(((o=t.resultPreviews)==null?void 0:o.length)>0?t.resultPreviews:t.resultPreview?[t.resultPreview]:[]).map((n,c)=>ge(n,t,c)).filter(n=>!!n)}function mt(t){return!!(t&&t.resultCount===0)}const _e=({initialCategory:t})=>{const[s,o]=p.useState([]),[n,c]=p.useState(t||"all"),[r,y]=p.useState("all"),[h,j]=p.useState(""),[P,g]=p.useState(0),[m,S]=p.useState(!1),[U,z]=p.useState(0),[$,ht]=p.useState([]),[B,q]=p.useState(null),[M,V]=p.useState(new Set),[tt,gt]=p.useState([]),[ft,yt]=p.useState(0),[Pt,et]=p.useState(!1),[i,R]=p.useState(null),F=p.useRef(!1),H=p.useRef(0),K=p.useRef(null),st=p.useRef(0),D=B!==null;p.useEffect(()=>{k.trackPromptAction({action:"open_tool",surface:"prompt_history_tool",source:"toolbox",status:"success",metadata:{tool_id:"prompt-history"}})},[]),p.useEffect(()=>{t&&(c(t),y("all"),j(""))},[t]);const v=p.useCallback(async(e="reset",u=0)=>{if(e==="more"&&F.current)return;const a=H.current+1;H.current=a,F.current=!0,q(e);try{const d=await re({category:n,skillTag:r,search:h,offset:u,limit:30});if(a!==H.current)return;o(_=>e==="more"?[..._,...d.records]:d.records),g(d.nextOffset),S(d.hasMore),z(d.total),ht(d.skillTags),e==="reset"&&(V(new Set),K.current=null)}catch(d){if(a!==H.current)return;k.trackPromptAction({action:"load_history",surface:"prompt_history_tool",promptType:b(n),status:"failed",metadata:{mode:e,has_search:h.trim().length>0,has_skill_filter:r!=="all"}}),console.error("[PromptHistoryTool] 加载提示词历史失败:",d),C.error("我的提示词加载失败")}finally{a===H.current&&(F.current=!1,q(null))}},[n,h,r]);p.useEffect(()=>{v("reset")},[v]),p.useEffect(()=>{r!=="all"&&!$.includes(r)&&y("all")},[r,$]);const T=p.useMemo(()=>s.map(e=>e.id),[s]),N=p.useMemo(()=>s.filter(e=>M.has(e.id)),[s,M]),A=p.useMemo(()=>ue((i==null?void 0:i.tagsInput)||""),[i==null?void 0:i.tagsInput]),xt=p.useMemo(()=>`共 ${U} 条,已加载 ${s.length} 条`,[s.length,U]),_t=T.length>0&&T.every(e=>M.has(e)),jt=p.useCallback(()=>{k.trackPromptAction({action:"refresh",surface:"prompt_history_tool",promptType:b(n),metadata:{has_search:h.trim().length>0,has_skill_filter:r!=="all"}}),v("reset")},[n,v,h,r]),vt=p.useCallback(e=>{e!==n&&(k.trackPromptAction({action:"filter_category",surface:"prompt_history_tool",promptType:b(e),metadata:{category:e}}),c(e))},[n]),kt=p.useCallback(e=>{const u=e.target.value;k.trackPromptAction({action:"filter_skill",surface:"prompt_history_tool",promptType:b(n),metadata:{selection:u==="all"?"all":"custom"}}),y(u)},[n]),bt=p.useCallback(e=>{const u=e.target.value;j(u);const a=u.trim();if(!a)return;const d=Date.now();d-st.current<2e3||(st.current=d,k.trackPromptAction({action:"search",surface:"prompt_history_tool",promptType:b(n),prompt:a,metadata:{has_skill_filter:r!=="all"}}))},[n,r]),Tt=p.useCallback((e,u,a)=>{V(d=>{const _=new Set(d),O=K.current;if(a&&O){const w=T.indexOf(O),I=T.indexOf(e);if(w>=0&&I>=0){const[Ht,Dt]=w<I?[w,I]:[I,w];return T.slice(Ht,Dt+1).forEach(nt=>{u?_.add(nt):_.delete(nt)}),_}}return u?_.add(e):_.delete(e),K.current=e,_})},[T]),Ct=p.useCallback(e=>{V(u=>{const a=new Set(u);return T.forEach(d=>{e?a.add(d):a.delete(d)}),a})},[T]),St=p.useCallback(()=>{N.length!==0&&(ie(N.flatMap(e=>e.sourceSentPrompts)),k.trackPromptAction({action:"delete",surface:"prompt_history_tool",itemCount:N.length,status:"success"}),C.success(`已删除 ${N.length} 条提示词`),v("reset"))},[v,N]),Nt=p.useCallback(async(e,u)=>{u.stopPropagation();try{await Ot(e.sentPrompt),k.trackPromptAction({action:"copy",surface:"prompt_history_tool",promptType:b(e.category),prompt:e.sentPrompt,status:"success",metadata:{record_status:e.status,initial_differs_from_sent:e.initialPrompt!==e.sentPrompt}}),C.success("提示词已复制")}catch(a){console.error("[PromptHistoryTool] 复制提示词失败:",a),C.error("复制失败")}},[]),wt=p.useCallback(e=>{var u;e.shiftKey&&((u=window.getSelection())==null||u.removeAllRanges())},[]),It=p.useCallback((e,u)=>{u.stopPropagation();const a=!e.pinned;ae(e.sentPrompt,a,e.category),k.trackPromptAction({action:a?"pin":"unpin",surface:"prompt_history_tool",promptType:b(e.category),prompt:e.sentPrompt,status:"success"}),C.success(a?"已置顶提示词":"已取消置顶"),v("reset")},[v]),At=p.useCallback((e,u)=>{u.stopPropagation(),R({mode:"edit",record:e,title:e.title,sentPrompt:e.sentPrompt,tagsInput:e.tags.join(", "),category:e.category,pinned:e.pinned})},[]),ot=p.useCallback((e,u)=>{u==null||u.stopPropagation();const a=n==="all"?"text":n;R({mode:"create",record:e,title:(e==null?void 0:e.title)||"",sentPrompt:(e==null?void 0:e.sentPrompt)||"",tagsInput:(e==null?void 0:e.tags.join(", "))||"",category:(e==null?void 0:e.category)||a,pinned:(e==null?void 0:e.pinned)||!1})},[n]),G=p.useCallback(()=>{R(null)},[]),Et=p.useCallback(()=>{var a,d,_,O,w,I;if(!i)return;if(!i.sentPrompt.trim()){C.warning("发送提示词不能为空");return}const e=i.mode==="edit"&&mt(i.record);if(!(i.mode==="create"?ce({title:i.title,content:i.sentPrompt,tags:A,category:i.category,pinned:i.pinned}):pe({sourceSentPrompt:((a=i.record)==null?void 0:a.sourceSentPrompt)||"",sourceSentPrompts:(d=i.record)==null?void 0:d.sourceSentPrompts,title:i.title,sentPrompt:e?i.sentPrompt:((_=i.record)==null?void 0:_.sentPrompt)||i.sentPrompt,tags:A,category:(O=i.record)==null?void 0:O.category,...e?{allowSentPromptEdit:!0}:{}}))){C.error("保存失败");return}k.trackPromptAction({action:i.mode==="create"?"create":"edit",surface:"prompt_history_tool",promptType:b(i.category),prompt:i.sentPrompt,status:"success",metadata:{tag_count:A.length,title_changed:i.mode==="edit"?i.title.trim()!==((w=i.record)==null?void 0:w.title):!!i.title.trim(),prompt_changed:i.mode==="create"||e&&i.sentPrompt.trim()!==((I=i.record)==null?void 0:I.sentPrompt)}}),C.success(i.mode==="create"?"提示词已创建":"提示词已更新"),R(null),v("reset")},[i,A,v]),L=p.useCallback(e=>{R(u=>u&&{...u,...e})},[]),Mt=p.useCallback((e,u,a)=>{e.stopPropagation(),u.length!==0&&(gt(u),yt(a),et(!0))},[]),Rt=p.useCallback(e=>{const u=e.currentTarget;u.scrollHeight-u.scrollTop-u.clientHeight<180&&m&&!D&&(k.trackPromptAction({action:"load_more",surface:"prompt_history_tool",promptType:b(n),itemCount:s.length,metadata:{has_search:h.trim().length>0,has_skill_filter:r!=="all",next_offset:P}}),v("more",P))},[n,m,v,D,P,s.length,h,r]),lt=(i==null?void 0:i.mode)==="create"||mt(i==null?void 0:i.record);return l.jsxs("div",{className:"prompt-history-tool",children:[l.jsxs("div",{className:"prompt-history-tool__toolbar",children:[l.jsxs("div",{className:"prompt-history-tool__search",children:[l.jsx(Ut,{size:14}),l.jsx("input",{value:h,onChange:bt,placeholder:"搜索标题、提示词、标签"})]}),l.jsx("button",{type:"button",className:"prompt-history-tool__icon-btn",onClick:()=>ot(),"aria-label":"新建提示词",children:l.jsx(at,{size:16})}),l.jsx("button",{type:"button",className:"prompt-history-tool__icon-btn",onClick:jt,disabled:D,"aria-label":"刷新",children:D?l.jsx(J,{size:16}):l.jsx($t,{size:16})})]}),l.jsx("div",{className:"prompt-history-tool__filters",children:Y.map(e=>l.jsx("button",{type:"button",className:n===e.value?"is-active":"",onClick:()=>vt(e.value),children:e.label},e.value))}),$.length>0&&l.jsx("div",{className:"prompt-history-tool__skill-filter",children:l.jsxs("select",{value:r,onChange:kt,children:[l.jsx("option",{value:"all",children:"全部 Skill"}),$.map(e=>l.jsx("option",{value:e,children:e},e))]})}),l.jsxs("div",{className:"prompt-history-tool__summary",children:[l.jsx("span",{children:xt}),N.length>0&&l.jsxs("button",{type:"button",className:"prompt-history-tool__delete-btn",onClick:St,children:[l.jsx(zt,{size:14}),"删除 ",N.length," 条"]}),B==="reset"&&l.jsx(J,{size:14,className:"prompt-history-tool__summary-loading"})]}),l.jsxs("div",{className:"prompt-history-tool__table-wrap",onScroll:Rt,children:[l.jsxs("table",{className:"prompt-history-tool__table",children:[l.jsx("thead",{children:l.jsxs("tr",{children:[l.jsx("th",{className:"prompt-history-tool__col-select",children:l.jsx("input",{type:"checkbox","aria-label":"选择已加载提示词",checked:_t,onChange:e=>Ct(e.target.checked)})}),l.jsx("th",{className:"prompt-history-tool__col-type",children:"类型"}),l.jsx("th",{className:"prompt-history-tool__col-title",children:"标题"}),l.jsx("th",{children:"发送提示词"}),l.jsx("th",{className:"prompt-history-tool__col-tags",children:"标签"}),l.jsx("th",{className:"prompt-history-tool__col-result",children:"结果"}),l.jsx("th",{className:"prompt-history-tool__col-time",children:"时间"}),l.jsx("th",{className:"prompt-history-tool__col-actions",children:"操作"})]})}),l.jsx("tbody",{children:s.map(e=>{const u=fe(e);return l.jsxs("tr",{className:M.has(e.id)?"is-selected":"",children:[l.jsx("td",{children:l.jsx("input",{type:"checkbox","aria-label":`选择 ${e.title}`,checked:M.has(e.id),onMouseDown:wt,onClick:a=>a.stopPropagation(),onChange:a=>Tt(e.id,a.target.checked,a.nativeEvent instanceof MouseEvent?a.nativeEvent.shiftKey:!1)})}),l.jsx("td",{children:l.jsx("span",{className:`prompt-history-tool__type prompt-history-tool__type--${e.category}`,children:me(e.category)})}),l.jsxs("td",{children:[l.jsx("div",{className:"prompt-history-tool__title",children:e.title}),e.initialPrompt!==e.sentPrompt&&l.jsxs("div",{className:"prompt-history-tool__subtext",children:["初始:",e.initialPrompt]}),e.sourceSentPrompt!==e.sentPrompt&&l.jsxs("div",{className:"prompt-history-tool__subtext",children:["原始:",e.sourceSentPrompt]})]}),l.jsx("td",{children:l.jsx(it,{placement:"left",delay:120,overlayClassName:"prompt-history-tool__prompt-popover",content:l.jsx("div",{className:"prompt-history-tool__prompt-full",children:e.sentPrompt}),children:l.jsx("button",{type:"button",className:"prompt-history-tool__prompt",onClick:a=>Nt(e,a),"aria-label":`复制提示词:${e.title}`,children:e.sentPrompt})})}),l.jsx("td",{children:l.jsx("div",{className:"prompt-history-tool__tags",children:e.tags.map(a=>l.jsx("span",{children:a},a))})}),l.jsx("td",{children:u.length>0?l.jsxs("div",{className:"prompt-history-tool__media-grid",children:[u.slice(0,4).map((a,d)=>l.jsx(it,{placement:"left",delay:80,overlayClassName:"prompt-history-tool__media-popover",content:a.type==="video"?l.jsx("video",{src:a.url,poster:a.posterUrl,controls:!0,muted:!0,preload:"metadata"}):l.jsx(ct,{src:a.posterUrl||a.url,alt:a.title||e.title,showSkeleton:!1,eager:!0}),children:l.jsx("button",{type:"button",className:"prompt-history-tool__media-thumb",onClick:_=>Mt(_,u,d),children:a.type==="video"?l.jsx(Gt,{src:a.url,poster:a.posterUrl,alt:a.title||e.title,thumbnailSize:"small",activateVideoOnClick:!1}):l.jsx(ct,{src:a.posterUrl||a.url,alt:a.title||e.title,showSkeleton:!1,eager:!0})})},a.id||a.url)),e.resultCount>4&&l.jsxs("span",{className:"prompt-history-tool__media-count",children:["+",e.resultCount-4]})]}):l.jsx("div",{className:"prompt-history-tool__result-text",children:he(e.resultPreview)})}),l.jsx("td",{children:de(e.createdAt)}),l.jsx("td",{children:l.jsxs("div",{className:"prompt-history-tool__actions",children:[l.jsx("button",{type:"button",className:"prompt-history-tool__create-btn",onClick:a=>ot(e,a),"aria-label":`基于 ${e.title} 创建`,children:l.jsx(at,{size:15})}),l.jsx("button",{type:"button",className:"prompt-history-tool__edit-btn",onClick:a=>At(e,a),"aria-label":`编辑 ${e.title}`,children:l.jsx(Bt,{size:15})}),l.jsx("button",{type:"button",className:`prompt-history-tool__pin-btn ${e.pinned?"is-pinned":""}`,onClick:a=>It(e,a),"aria-label":e.pinned?"取消置顶":"置顶",children:e.pinned?l.jsx(Vt,{size:15}):l.jsx(Ft,{size:15})})]})})]},e.id)})})]}),!D&&s.length===0&&l.jsx("div",{className:"prompt-history-tool__empty",children:"暂无我的提示词"}),B==="more"&&l.jsxs("div",{className:"prompt-history-tool__loading-more",children:[l.jsx(J,{size:14}),"加载中..."]}),!m&&s.length>0&&l.jsx("div",{className:"prompt-history-tool__done",children:"已加载全部"})]}),l.jsxs("div",{className:"prompt-history-tool__footer",children:[l.jsxs("div",{className:"prompt-history-tool__hint",children:[l.jsx(Kt,{size:13}),"点击提示词复制,勾选列选择,Shift 连选"]}),l.jsx("span",{children:m?"向下滚动自动加载":"没有更多了"})]}),l.jsx(Qt,{visible:Pt,items:tt,initialIndex:ft,onClose:()=>et(!1),showThumbnails:tt.length>1,videoAutoPlay:!0}),i&&l.jsx("div",{className:"prompt-history-tool__edit-mask",role:"presentation",onMouseDown:G,children:l.jsxs("form",{className:"prompt-history-tool__edit-dialog",onMouseDown:e=>e.stopPropagation(),onSubmit:e=>{e.preventDefault(),Et()},children:[l.jsxs("div",{className:"prompt-history-tool__edit-header",children:[l.jsxs("div",{children:[l.jsx("h3",{children:i.mode==="create"?"创建提示词":"编辑提示词"}),l.jsx("p",{children:i.mode==="create"?"填写类型、置顶、标题、发送提示词和标签":lt?"修改标题、发送提示词和标签":"修改标题和标签,发送提示词保持不变"})]}),l.jsx("button",{type:"button",className:"prompt-history-tool__edit-close",onClick:G,"aria-label":"关闭编辑弹窗",children:"×"})]}),i.mode==="create"&&l.jsxs("div",{className:"prompt-history-tool__field-row",children:[l.jsxs("label",{className:"prompt-history-tool__field",children:[l.jsx("span",{children:"类型"}),l.jsx("select",{value:i.category,onChange:e=>L({category:e.target.value}),children:Y.filter(e=>e.value!=="all").map(e=>l.jsx("option",{value:e.value,children:e.label},e.value))})]}),l.jsxs("label",{className:"prompt-history-tool__switch-field",children:[l.jsx("input",{type:"checkbox",checked:i.pinned,onChange:e=>L({pinned:e.target.checked})}),l.jsx("span",{children:"置顶"})]})]}),l.jsxs("label",{className:"prompt-history-tool__field",children:[l.jsx("span",{children:"标题"}),l.jsx("input",{value:i.title,onChange:e=>L({title:e.target.value}),maxLength:80,placeholder:"输入标题"})]}),l.jsxs("label",{className:"prompt-history-tool__field",children:[l.jsx("span",{children:"发送提示词"}),l.jsx("textarea",{value:i.sentPrompt,onChange:e=>L({sentPrompt:e.target.value}),readOnly:!lt,rows:8,maxLength:2e3,placeholder:"输入发送提示词"})]}),l.jsxs("label",{className:"prompt-history-tool__field",children:[l.jsx("span",{children:"标签"}),l.jsx("textarea",{className:"prompt-history-tool__tags-input",value:i.tagsInput,onChange:e=>L({tagsInput:e.target.value}),rows:2,placeholder:"多个标签用逗号或换行分隔"})]}),A.length>0&&l.jsx("div",{className:"prompt-history-tool__edit-tags",children:A.map(e=>l.jsx("span",{children:e},e))}),l.jsxs("div",{className:"prompt-history-tool__edit-footer",children:[l.jsx("button",{type:"button",onClick:G,children:"取消"}),l.jsx("button",{type:"submit",className:"is-primary",children:"保存"})]})]})})]})};export{_e as PromptHistoryTool,_e as default};
|