diff --git a/dist/copilot_web/App-B_5DJBtC.js b/dist/copilot_web/App-Bbre7oqJ.js similarity index 95% rename from dist/copilot_web/App-B_5DJBtC.js rename to dist/copilot_web/App-Bbre7oqJ.js index ef93826..4eca186 100644 --- a/dist/copilot_web/App-B_5DJBtC.js +++ b/dist/copilot_web/App-Bbre7oqJ.js @@ -1,6 +1,6 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/workflowChat-m824ZHEN.js","copilot_web/input.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-D3rPBq8S.js","copilot_web/assets/input-CeTzrUyG.css"].map(path => { +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/workflowChat-DVyLdfeb.js","copilot_web/input.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-D3rPBq8S.js","copilot_web/assets/input-CeTzrUyG.css"].map(path => { const apiBase = window.comfyAPI?.api?.api?.api_base; const prefix = apiBase ? `${apiBase.substring(1)}/` : ''; return `${prefix}${path}`; }))))=>i.map(i=>d[i]); -import{_ as E}from"./input.js";import{j as s}from"./vendor-markdown-Dek94WS0.js";import{r as n,R as w}from"./vendor-react-V04_Axys.js";import{C as v}from"./message-components-D3rPBq8S.js";const y=9999999,x={EXPLAIN_NODE:"copilot:explain-node"},D="/copilot_web/assets/logo-BTZhX0BN.png";function _(e={}){const[u,l]=n.useState({x:e.initialX??window.innerWidth-160,y:e.initialY??20}),[o,r]=n.useState(!1),[a,m]=n.useState({x:0,y:0}),[d,c]=n.useState(0),[g,b]=n.useState({x:0,y:0}),f=n.useCallback(t=>{if(o){const i=Math.min(Math.max(0,t.clientX-g.x),window.innerWidth-(e.boundaryPadding?.right??100)),p=Math.min(Math.max(0,t.clientY-g.y),window.innerHeight-(e.boundaryPadding?.bottom??40));l({x:i,y:p})}},[o,g,e.boundaryPadding]),h=n.useCallback(t=>{if(o){const i=Math.sqrt(Math.pow(t.clientX-a.x,2)+Math.pow(t.clientY-a.y,2)),p=Date.now()-d;i<5&&p<200&&e.onClick?.()}r(!1)},[o,a,d,e.onClick]);return n.useEffect(()=>(o&&(document.addEventListener("mousemove",f),document.addEventListener("mouseup",h)),()=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",h)}),[o,f,h]),{position:u,isDragging:o,handleMouseDown:t=>{t.preventDefault(),r(!0),c(Date.now()),m({x:t.clientX,y:t.clientY});const i=t.currentTarget.getBoundingClientRect();b({x:t.clientX-i.left,y:t.clientY-i.top})}}}const C=w.lazy(()=>E(()=>import("./workflowChat-m824ZHEN.js").then(e=>e.w),__vite__mapDeps([0,1,2,3,4,5])).then(e=>({default:e.default})));function M(){const e=n.useRef(null),[u,l]=n.useState(!1),[o,r]=n.useState(!1),{position:a,isDragging:m,handleMouseDown:d}=_({boundaryPadding:{right:100,bottom:40},onClick:()=>l(!0)});return n.useEffect(()=>{const c=()=>{l(!0),r(!0)};return window.addEventListener(x.EXPLAIN_NODE,c),()=>window.removeEventListener(x.EXPLAIN_NODE,c)},[]),a?s.jsx(v,{children:s.jsx("div",{ref:e,children:s.jsxs("div",{className:"fixed",style:{zIndex:y,left:a.x,top:a.y,cursor:m?"grabbing":"grab"},children:[s.jsxs("button",{onMouseDown:d,className:"px-2 py-1 border border-gray-300 rounded-md bg-white text-black hover:bg-blue-300 hover:font-bold transition-colors select-none w-40 flex items-center space-x-1",style:{marginLeft:"-40px"},children:[s.jsx("img",{src:D,alt:"ComfyUI-Copilot Logo",className:"h-8 w-8"}),s.jsx("span",{className:"text-[14px] font-medium text-gray-800",children:"ComfyUI-Copilot"})]}),s.jsx(w.Suspense,{fallback:s.jsx("div",{children:"Loading..."}),children:s.jsx(C,{onClose:()=>{l(!1),r(!1)},visible:u,triggerUsage:o,onUsageTriggered:()=>r(!1)})})]})})}):null}const I=Object.freeze(Object.defineProperty({__proto__:null,default:M},Symbol.toStringTag,{value:"Module"}));export{I as A,D as l}; +import{_ as E}from"./input.js";import{j as s}from"./vendor-markdown-Dek94WS0.js";import{r as n,R as w}from"./vendor-react-V04_Axys.js";import{C as v}from"./message-components-D3rPBq8S.js";const y=9999999,x={EXPLAIN_NODE:"copilot:explain-node"},D="/copilot_web/assets/logo-BTZhX0BN.png";function _(e={}){const[u,l]=n.useState({x:e.initialX??window.innerWidth-160,y:e.initialY??20}),[o,r]=n.useState(!1),[a,m]=n.useState({x:0,y:0}),[d,c]=n.useState(0),[g,b]=n.useState({x:0,y:0}),f=n.useCallback(t=>{if(o){const i=Math.min(Math.max(0,t.clientX-g.x),window.innerWidth-(e.boundaryPadding?.right??100)),p=Math.min(Math.max(0,t.clientY-g.y),window.innerHeight-(e.boundaryPadding?.bottom??40));l({x:i,y:p})}},[o,g,e.boundaryPadding]),h=n.useCallback(t=>{if(o){const i=Math.sqrt(Math.pow(t.clientX-a.x,2)+Math.pow(t.clientY-a.y,2)),p=Date.now()-d;i<5&&p<200&&e.onClick?.()}r(!1)},[o,a,d,e.onClick]);return n.useEffect(()=>(o&&(document.addEventListener("mousemove",f),document.addEventListener("mouseup",h)),()=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",h)}),[o,f,h]),{position:u,isDragging:o,handleMouseDown:t=>{t.preventDefault(),r(!0),c(Date.now()),m({x:t.clientX,y:t.clientY});const i=t.currentTarget.getBoundingClientRect();b({x:t.clientX-i.left,y:t.clientY-i.top})}}}const C=w.lazy(()=>E(()=>import("./workflowChat-DVyLdfeb.js").then(e=>e.w),__vite__mapDeps([0,1,2,3,4,5])).then(e=>({default:e.default})));function M(){const e=n.useRef(null),[u,l]=n.useState(!1),[o,r]=n.useState(!1),{position:a,isDragging:m,handleMouseDown:d}=_({boundaryPadding:{right:100,bottom:40},onClick:()=>l(!0)});return n.useEffect(()=>{const c=()=>{l(!0),r(!0)};return window.addEventListener(x.EXPLAIN_NODE,c),()=>window.removeEventListener(x.EXPLAIN_NODE,c)},[]),a?s.jsx(v,{children:s.jsx("div",{ref:e,children:s.jsxs("div",{className:"fixed",style:{zIndex:y,left:a.x,top:a.y,cursor:m?"grabbing":"grab"},children:[s.jsxs("button",{onMouseDown:d,className:"px-2 py-1 border border-gray-300 rounded-md bg-white text-black hover:bg-blue-300 hover:font-bold transition-colors select-none w-40 flex items-center space-x-1",style:{marginLeft:"-40px"},children:[s.jsx("img",{src:D,alt:"ComfyUI-Copilot Logo",className:"h-8 w-8"}),s.jsx("span",{className:"text-[14px] font-medium text-gray-800",children:"ComfyUI-Copilot"})]}),s.jsx(w.Suspense,{fallback:s.jsx("div",{children:"Loading..."}),children:s.jsx(C,{onClose:()=>{l(!1),r(!1)},visible:u,triggerUsage:o,onUsageTriggered:()=>r(!1)})})]})})}):null}const I=Object.freeze(Object.defineProperty({__proto__:null,default:M},Symbol.toStringTag,{value:"Module"}));export{I as A,D as l}; diff --git a/dist/copilot_web/ParameterDebugInterfaceNew-gJw0-dqN.js b/dist/copilot_web/ParameterDebugInterfaceNew-StQHp9mW.js similarity index 57% rename from dist/copilot_web/ParameterDebugInterfaceNew-gJw0-dqN.js rename to dist/copilot_web/ParameterDebugInterfaceNew-StQHp9mW.js index 26c3c19..a72bc2b 100644 --- a/dist/copilot_web/ParameterDebugInterfaceNew-gJw0-dqN.js +++ b/dist/copilot_web/ParameterDebugInterfaceNew-StQHp9mW.js @@ -1,4 +1,4 @@ -import{j as e}from"./vendor-markdown-Dek94WS0.js";import{r as b}from"./vendor-react-V04_Axys.js";import{r as Qe,g as Xe,m as Ze,i as et}from"./workflowChat-m824ZHEN.js";import{a as Z,u as Ie,W as Pe,g as tt}from"./message-components-D3rPBq8S.js";import"./input.js";import"./App-B_5DJBtC.js";function st(l,n){try{if(!l)return console.error("Invalid prompt_output: ",l),l;for(const r of n){if(!l[r.nodeId]){console.error(`Node with ID ${r.nodeId} not found`);continue}if(!l[r.nodeId].inputs){console.error(`Inputs not found for node with ID ${r.nodeId}`);continue}l[r.nodeId].inputs[r.paramName]=r.paramValue}return l}catch(r){return console.error("Error updating prompt:",r),l}}async function rt(l){const n=await Z.graphToPrompt(),r=st(n.output,l);console.log("queuePrompt updated_prompt:",r);const x={prompt:r,client_id:Z.api.clientId,extra_data:{extra_pageinfo:{workflow:n.workflow}}};console.debug("queuePrompt request_body.prompt:",r);const g=await Qe(x);return console.debug("queuePrompt response:",g),g}function Me(l){const n=document.createElement("canvas"),r=n.getContext("2d");if(n.width=512,n.height=512,r){r.fillStyle="#f8d7da",r.fillRect(0,0,n.width,n.height),r.strokeStyle="#dc3545",r.lineWidth=4,r.strokeRect(10,10,n.width-20,n.height-20),r.fillStyle="#dc3545",r.beginPath(),r.arc(n.width/2,150,50,0,2*Math.PI),r.fill(),r.fillStyle="white",r.font="bold 80px Arial",r.textAlign="center",r.textBaseline="middle",r.fillText("!",n.width/2,150),r.fillStyle="#721c24",r.font="20px Arial",r.textAlign="center",r.textBaseline="middle";const x=n.width-60,g=30,u=l.split(" ");let c="",m=250;for(let f=0;fx&&f>0?(r.fillText(c,n.width/2,m),c=u[f]+" ",m+=g):c=P}r.fillText(c,n.width/2,m)}return n.toDataURL("image/png")}async function nt(l){try{if(!l||l==="")return console.log("No prompt ID provided"),{1:[Me("Fail to generate prompt ID")]};const n=await Xe(l);if(!n||!n[l])return console.log("Not finished for prompt ID:",l),{};const r=n[l];if(r.status&&r.status.status_str==="error"){console.error("Error for prompt ID:",l);const g=r.status.messages;if(g&&g.length>0){const u=g[g.length-1];if(u&&u.length>0){const c=u[0];return{1:[Me(c)]}}}}const x={};if(r.outputs)for(const g in r.outputs){const u=r.outputs[g];if(u&&u.images){x[g]=[];for(const c of u.images)if(c&&c.filename&&c.type){const m=Z.graph._nodes_by_id[g].imgs[0].currentSrc.split("?")[0];x[g].push(m+"?filename="+encodeURIComponent(c.filename)+"&type="+encodeURIComponent(c.type)+(c.subfolder?"&subfolder="+encodeURIComponent(c.subfolder):""))}console.log("outputImages for nodeId:",g,x[g])}}return x}catch(n){throw console.error("Error getting output images from prompt:",n),n}}function ot(){const l=Object.values(Z.graph._nodes_by_id),n=[],r=[];for(const x of l)x.type==="SaveImage"?n.push(x.id):x.type==="PreviewImage"&&r.push(x.id);if(console.log("saveNodeIds:",n),console.log("previewNodeIds:",r),n.length===0&&r.length===0)throw new Error("No SaveImage or PreviewImage node found, please add one to the graph");return n.length===1?n[0]:n.length==0&&r.length===1?r[0]:null}async function at(l,n){const r=await nt(l);return Object.keys(r).length===0?null:r[n.toString()]&&r[n.toString()].length>0?r[n.toString()][0]:null}const lt=({selectedNodes:l,handleParamSelect:n,selectedParams:r,handleNext:x,handleClose:g})=>{const c=l.flatMap(m=>(m.widgets||[]).map(f=>f.name)).some(m=>r[m]===!0);return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Select Parameters for Testing"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Choose the parameters you want to include in your batch test"})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:g,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),l.map((m,f)=>{const P=m.title||"Unknown Node",L=m.widgets||[];return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsx("div",{className:"bg-gray-50 px-3 py-2 text-sm font-medium text-gray-700 border-b",children:P}),e.jsx("div",{className:"p-4 space-y-3",children:e.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:L.map(($,D)=>{const V=$.name;return e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:`w-5 h-5 rounded-full border flex items-center justify-center ${r[V]?"border-red-500 bg-red-100":"border-gray-300"}`,onClick:A=>n(V,A),children:r[V]&&e.jsx("div",{className:"w-3 h-3 rounded-full bg-red-500"})}),e.jsx("span",{className:"ml-2 text-gray-700 text-xs",children:V})]},`widget-${D}`)})})})]},`node-${f}`)}),e.jsx("div",{className:"mt-6 flex justify-center",children:e.jsx("button",{onClick:m=>x(m),disabled:!c,className:`px-3 py-1.5 text-xs ${c?"bg-pink-200 text-pink-700 hover:bg-pink-300":"bg-gray-200 text-gray-500 cursor-not-allowed"} rounded-md transition-colors`,children:"Next"})})]})},it=({selectedNodes:l,paramTestValues:n,selectedParams:r,updateParamTestValues:x,toggleDropdown:g,openDropdowns:u,handleTestValueSelect:c,searchTerms:m,handleSearch:f,handleSelectAll:P,handleNext:L,handlePrevious:$,handleClose:D,inputValues:V,setInputValues:A,textInputs:T,handleTextInputChange:_,handleAddTextInput:R,handleRemoveTextInput:j,openAiWritingModal:k})=>{const S=(w,M,q,J=0)=>{if(w=isNaN(w)?0:w,M=isNaN(M)?100:M,q=isNaN(q)||q<=0?1:q,M{!l||l.length===0||l.forEach(w=>{const M=w.id.toString(),q=w.widgets||{};Object.values(q).forEach(h=>{const I=h.name;if(!r[I])return;if(!(n[M]?.[I]?.length>0)&&h.type==="number"){const d=h.options?.min||0,G=h.options?.max||100,O=(h.options?.step||10)/10,N=h.options?.precision||0,B=S(d,G,O,N);if(B.length>0){x(M,I,B);const H=`${M}_${I}`;A(p=>({...p,[H]:{min:d.toString(),max:G.toString(),step:O.toString()}}))}}if(h.type==="customtext"||h.type.toLowerCase().includes("text")){const d=`${M}_${I}`,G=T[d]||[""];JSON.stringify(G)!==JSON.stringify(n[M]?.[I]||[""])&&x(M,I,G)}})})},[l,r,n,T,x,A,S]),e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Parameter Options"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Configure the test values for each parameter"})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:D,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),l.length>0?l.map((w,M)=>{const q=w.widgets||{},J=Object.values(q),h=w.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b flex justify-between items-center",children:[e.jsxs("span",{children:[w.type," (ID: ",h,")"]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:I=>D(I,M),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"p-4 space-y-4",children:J.map((I,Y)=>{const d=I.name;if(!r[d])return null;const G=`${h}_${d}`;if(I.type==="customtext"||I.type.toLowerCase().includes("text")){const O=T[G]||[""];return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("label",{className:"text-xs font-medium text-gray-700",children:[d,":"]}),e.jsxs("button",{className:"px-2 py-1 bg-blue-100 text-blue-700 rounded text-xs flex items-center hover:bg-blue-200 transition-colors",onClick:()=>k(h,d),children:[e.jsx("svg",{className:"w-3 h-3 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})}),"AI Writing"]})]}),e.jsx("div",{className:"space-y-2",children:O.map((N,B)=>e.jsxs("div",{className:"flex items-start",children:[e.jsx("textarea",{className:`flex-1 border ${N?"border-gray-300":"border-red-500"} rounded p-2 text-xs resize-y`,rows:2,placeholder:"Enter text...",value:N,onChange:H=>_(h,d,B,H.target.value),required:!0}),e.jsx("button",{className:"ml-2 text-red-500 hover:text-red-700",onClick:()=>j(h,d,B),title:"Remove",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},B))}),e.jsxs("button",{className:"mt-2 px-2 py-1 border border-dashed border-gray-300 rounded text-xs text-gray-600 hover:bg-gray-50 flex items-center",onClick:()=>R(h,d),children:[e.jsx("svg",{className:"w-3 h-3 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),"Add Text"]})]},Y)}if(I.type==="number"){const O=I.options?.min||0,N=I.options?.max||100,B=(I.options?.step||10)/10,H=I.options?.precision||0,p=S(O,N,B,H),U=V[G]||{min:O.toString(),max:N.toString(),step:B.toString()};return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("label",{className:"text-xs font-medium text-gray-700",children:[d,":"]}),e.jsx("div",{className:"w-4"})]}),e.jsxs("div",{className:"flex space-x-2 items-center",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Min"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:U.min,required:!0,onClick:y=>{y.preventDefault(),y.stopPropagation()},onChange:y=>{y.preventDefault(),y.stopPropagation();const E=y.target.value;if(A(W=>({...W,[G]:{...W[G],min:E}})),E===""||!isNaN(parseFloat(E))){const W=E===""?0:parseFloat(E),z=parseFloat(U.max||N.toString()),Q=parseFloat(U.step||B.toString()),K=S(W,z,Q,H);x(h,d,K)}}}),e.jsx("label",{className:"text-xs text-gray-600",children:"Max"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:U.max,onClick:y=>{y.preventDefault(),y.stopPropagation()},required:!0,onChange:y=>{y.preventDefault(),y.stopPropagation();const E=y.target.value;if(A(W=>({...W,[G]:{...W[G],max:E}})),E===""||!isNaN(parseFloat(E))){const W=parseFloat(U.min||O.toString()),z=E===""?W:parseFloat(E),Q=parseFloat(U.step||B.toString()),K=S(W,z,Q,H);x(h,d,K)}}}),e.jsx("label",{className:"text-xs text-gray-600",children:"Step"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:U.step,required:!0,onClick:y=>{y.preventDefault(),y.stopPropagation()},onChange:y=>{y.preventDefault(),y.stopPropagation();const E=y.target.value;if(A(W=>({...W,[G]:{...W[G],step:E}})),E===""||!isNaN(parseFloat(E))&&parseFloat(E)>0){const W=parseFloat(U.min||O.toString()),z=parseFloat(U.max||N.toString()),Q=E===""?1:parseFloat(E),K=S(W,z,Q,H);x(h,d,K)}}})]}),e.jsxs("div",{className:"mt-1",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:(()=>{const y=n[h]?.[d]||p;if(y.length<=10)return y.map((E,W)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:z=>{z.stopPropagation(),c(h,d,E,z)},children:[e.jsx("span",{children:E}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},W));{const E=y.slice(0,5),W=y.slice(y.length-5);return e.jsxs(e.Fragment,{children:[E.map((z,Q)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:K=>{K.stopPropagation(),c(h,d,z,K)},children:[e.jsx("span",{children:z}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},`first-${Q}`)),e.jsx("div",{className:"px-2 py-0.5 bg-gray-100 text-gray-600 rounded-md flex items-center text-xs",children:"..."}),W.map((z,Q)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:K=>{K.stopPropagation(),c(h,d,z,K)},children:[e.jsx("span",{children:z}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},`last-${Q}`))]})}})()})]}),e.jsx("div",{className:"mt-1",children:e.jsx("p",{className:"text-xs text-gray-500",children:"Values are distributed evenly between Min and Max"})})]},Y)}else if(I.type==="combo"){const O=I.options?.values||[],N=`${h}_${d}`,B=p=>typeof p=="string"?p:p&&typeof p=="object"&&"name"in p?p.name:String(p),H=p=>typeof p=="object"&&p!==null&&"name"in p?p.name:p;return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("label",{className:"text-xs font-medium text-gray-700",children:d}),e.jsxs("div",{className:"relative dropdown-container",children:[e.jsxs("button",{className:`appearance-none border ${(n[h]?.[d]||[]).length===0?"border-red-500":"border-gray-300"} rounded px-2 py-0.5 pr-6 text-xs flex items-center bg-white text-gray-700`,onClick:p=>{p.preventDefault(),p.stopPropagation(),g(h,d,p)},"data-dropdown":N,children:[e.jsx("span",{children:(n[h]?.[d]||[]).length>0?`${d}: ${(n[h]?.[d]||[]).length} selected`:`Select ${d}`}),e.jsx("div",{className:"ml-2",children:e.jsx("svg",{className:"fill-current h-4 w-4",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",children:e.jsx("path",{d:"M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"})})})]}),u[N]&&e.jsxs("div",{className:"absolute z-[9999] mt-1 w-64 bg-white border border-gray-300 rounded-md shadow-lg dropdown-menu",style:{position:"fixed",top:typeof u[N]=="object"?`${u[N].y}px`:"0px",left:typeof u[N]=="object"?`${u[N].x}px`:"0px",maxHeight:"300px",overflowY:"auto"},children:[e.jsx("div",{className:"p-2 border-b sticky top-0 bg-white",children:e.jsx("input",{type:"text",className:"w-full px-2 py-0.5 text-xs border border-gray-300 rounded",placeholder:"Search...",value:m[N]||"",onChange:p=>{p.preventDefault(),p.stopPropagation(),f(h,d,p.target.value)},onClick:p=>{p.preventDefault(),p.stopPropagation()},autoFocus:!0})}),e.jsxs("div",{className:"px-3 py-1.5 bg-gray-50 border-b cursor-pointer text-xs flex items-center text-gray-700 hover:bg-gray-100",onClick:p=>{p.preventDefault(),p.stopPropagation();const y=O.filter(E=>!m[N]||B(E).toLowerCase().includes((m[N]||"").toLowerCase())).map(H);P(h,d,y)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${O.length>0&&(n[h]?.[d]||[]).length===O.length?"bg-blue-500 border-blue-500":(n[h]?.[d]||[]).length>0?"bg-blue-500 border-blue-500 opacity-50":"border-gray-300"}`,children:(n[h]?.[d]||[]).length>0&&e.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("span",{className:"font-medium",children:O.length>0&&(n[h]?.[d]||[]).length===O.length?"Deselect All":"Select All"})]}),e.jsxs("div",{className:"max-h-60 overflow-y-auto",children:[O.filter(p=>!m[N]||B(p).toLowerCase().includes((m[N]||"").toLowerCase())).map((p,U)=>e.jsxs("div",{className:"px-3 py-1.5 hover:bg-gray-100 cursor-pointer text-xs flex items-center text-gray-700",onClick:y=>{y.preventDefault(),y.stopPropagation(),c(h,d,H(p),y)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${(n[h]?.[d]||[]).includes(H(p))?"bg-blue-500 border-blue-500":"border-gray-300"}`,children:(n[h]?.[d]||[]).includes(H(p))&&e.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("span",{className:"whitespace-normal overflow-hidden text-ellipsis",children:B(p)})]},U)),O.filter(p=>!m[N]||B(p).toLowerCase().includes((m[N]||"").toLowerCase())).length===0&&e.jsx("div",{className:"px-3 py-4 text-sm text-gray-500 text-center",children:"No matching options"})]})]})]})]}),e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),(n[h]?.[d]||[]).length===0&&e.jsx("div",{className:"text-xs text-red-500 mt-1",children:"Please select at least one value"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:(n[h]?.[d]||[]).map((p,U)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs",children:[e.jsx("span",{children:p}),e.jsx("svg",{className:"w-4 h-4 ml-1 cursor-pointer hover:text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",onClick:y=>{y.preventDefault(),y.stopPropagation(),c(h,d,p,y)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},U))})]})]},Y)}else return e.jsxs("div",{className:"border-b pb-3",children:[e.jsx("div",{className:"flex justify-between items-center",children:e.jsx("label",{className:"text-xs font-medium text-gray-700",children:d})}),e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",children:[(n[h]?.[d]||[]).map((O,N)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs",children:[e.jsx("span",{children:O}),e.jsx("svg",{className:"w-4 h-4 ml-1 cursor-pointer hover:text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",onClick:B=>{B.preventDefault(),B.stopPropagation(),c(h,d,O,B)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},N)),e.jsxs("button",{className:"px-2 py-0.5 border border-dashed border-blue-300 text-blue-600 rounded-md text-xs flex items-center hover:bg-blue-50",onClick:O=>{O.preventDefault(),O.stopPropagation();const N=`${d}${(n[h]?.[d]||[]).length+1}`;x(h,d,[...n[h]?.[d]||[],N])},children:[e.jsx("svg",{className:"w-4 h-4 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),e.jsx("span",{children:"Add"})]})]})]})]},Y)})})]},M)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500",children:"No nodes selected. Please select a node in the workflow to configure parameters."}),e.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:w=>$(w),className:"px-3 py-1.5 text-xs bg-gray-100 text-gray-800 rounded-md hover:bg-gray-200 transition-colors",children:"Previous"}),e.jsx("button",{onClick:w=>L(w),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",children:"Next"})]})]})},ct=({selectedNodes:l,paramTestValues:n,selectedParams:r,totalCount:x,errorMessage:g,handlePrevious:u,handleStartGeneration:c,handleClose:m})=>{const[f,P]=b.useState([]),[L,$]=b.useState(null),[D,V]=b.useState(!1);Ie();const A=()=>{const _=Object.values(Z.graph._nodes_by_id),R=[],j=[];for(const S of _)S.type==="SaveImage"?R.push(S.id):S.type==="PreviewImage"&&j.push(S.id);const k=[...R,...j];P(k),k.length===1?$(k[0]):k.length>1&&(V(!0),$(null))};b.useEffect(()=>{A()},[]),b.useEffect(()=>{const _=()=>{if(!Z.canvas.selected_nodes)return;const R=Object.values(Z.canvas.selected_nodes);if(R.length===0)return;const j=R[0];j&&(j.type==="SaveImage"||j.type==="PreviewImage")&&(console.log("Selected image node:",j.id),$(j.id))};return document.addEventListener("click",_),()=>{document.removeEventListener("click",_)}},[]);const T=_=>{if(_&&(_.preventDefault(),_.stopPropagation()),f.length>1&&!L){V(!0);return}c(_,L||void 0)};return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Confirm Test Configuration"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["In the selected parameter combinations, there are ",x," total runs. Each run will generate a separate image."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:m,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),D&&f.length>1&&e.jsx("div",{className:"mb-4 p-3 bg-yellow-50 border border-yellow-200 rounded-md text-amber-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:L===null?`Multiple SaveImage and PreviewImage nodes detected with IDs ${f.join(",")}. Please click the node on canvas.`:`Current node ID is ${L}, please click Start Generation again`})]})}),g&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:g})]})}),l.length>0?l.map((_,R)=>{const j=_.type||"Unknown Node",k=_.widgets||[],S=_.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b",children:[j," (ID: ",S,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:k.map((w,M)=>{const q=w.name;if(!r[q])return null;const J=n[S]?.[q]||[],h=Array.isArray(J)?`[${J.join(", ")}]`:JSON.stringify(J);return e.jsxs("div",{className:MI.preventDefault()})})]},M)})})]},R)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500 text-xs",children:"No nodes selected. Please select a node in the workflow to configure parameters."}),e.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:_=>u(_),className:"px-3 py-1.5 text-xs bg-gray-100 text-gray-800 rounded-md hover:bg-gray-200 transition-colors",children:"Previous"}),e.jsx("button",{onClick:_=>T(_),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${f.length>1&&!L?"bg-gray-200 text-gray-500 cursor-not-allowed":"bg-pink-200 text-pink-700 hover:bg-pink-300"}`,disabled:f.length>1&&!L,children:"Start Generation"})]})]})},dt=({selectedNodes:l,paramTestValues:n,selectedParams:r,totalCount:x,completedCount:g,errorMessage:u,handleClose:c,setIsProcessing:m,setCurrentScreen:f,cleanupPolling:P})=>{const L=$=>{$.preventDefault(),$.stopPropagation(),Ze({clear:!0}),et(),P&&P(),m(!1),f(2)};return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4 relative",children:[e.jsx("div",{className:"absolute inset-0 bg-gray-500 bg-opacity-30 flex flex-col items-center justify-center z-10",children:e.jsxs("div",{className:"text-center text-gray-800 bg-white p-4 rounded-lg shadow-lg",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:"Processing..."}),e.jsxs("div",{className:"text-xs mb-3",children:["Completed ",g," of ",x," runs"]}),e.jsx("div",{className:"w-48 h-2 bg-gray-200 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-pink-500 transition-all duration-200",style:{width:`${g/x*100}%`}})}),e.jsxs("div",{className:"mt-2 text-xs text-gray-600",children:["Already generated ",g," images"]}),e.jsx("button",{onClick:L,className:"mt-4 px-3 py-1.5 text-xs bg-gray-200 text-gray-800 rounded-md hover:bg-gray-300 transition-colors",children:"Cancel"})]})}),e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Confirm Test Configuration"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["In the selected parameter combinations, there are ",x," total runs. Each run will generate a separate image."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:c,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),u&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:u})]})}),l.length>0?l.map(($,D)=>{const V=$.type||"Unknown Node",A=$.widgets||[],T=$.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b",children:[V," (ID: ",T,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:A.map((_,R)=>{const j=_.name;if(!r[j])return null;const k=n[T]?.[j]||[],S=Array.isArray(k)?`[${k.join(", ")}]`:JSON.stringify(k);return e.jsxs("div",{className:Rw.preventDefault()})})]},R)})})]},D)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500",children:"No nodes selected. Please select a node in the workflow to configure parameters."})]})},xt=({generatedImages:l,selectedImageIndex:n,handleSelectImage:r,handleApplySelected:x,handlePrevious:g,handleClose:u,currentPage:c,handlePageChange:m,imagesPerPage:f,notificationVisible:P,modalVisible:L,modalImageUrl:$,openImageModal:D,closeImageModal:V})=>{const A=Math.ceil(l.length/f),T=(c-1)*f,_=Math.min(T+f,l.length),R=l.slice(T,_);return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Generation Complete"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["All ",l.length," images have been generated."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:u,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),P&&e.jsx("div",{className:"fixed top-4 right-4 bg-green-100 border-l-4 border-green-500 text-green-700 p-3 shadow-md rounded animate-fade-in-out z-50",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"py-1",children:e.jsx("svg",{className:"h-4 w-4 text-green-500 mr-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("p",{className:"text-xs",children:"Parameters has been applied."})]})}),L&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50",onClick:V,children:e.jsxs("div",{className:"bg-white rounded-lg p-2 max-w-4xl max-h-[90vh] relative",onClick:j=>j.stopPropagation(),children:[e.jsx("button",{className:"absolute top-2 right-2 text-gray-700 hover:text-gray-900 rounded-full hover:bg-gray-200 p-1",onClick:V,children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),e.jsx("div",{className:"overflow-auto max-h-[calc(90vh-4rem)]",children:e.jsx("img",{src:$,alt:"Enlarged image",className:"max-w-full h-auto"})})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-4 mb-6",children:R.map((j,k)=>{const S=T+k;return e.jsxs("div",{className:`relative rounded-lg overflow-hidden border ${n===S?"border-pink-500 ring-2 ring-pink-300":"border-gray-200"}`,onClick:w=>r(S,w),children:[e.jsx("button",{className:"absolute top-2 right-2 bg-white bg-opacity-75 rounded-full p-0.5 text-gray-600 hover:text-gray-900 shadow-sm z-10",onClick:w=>D(j.url,w),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5v-4m0 4h-4m4 0l-5-5"})})}),e.jsx("div",{className:"aspect-square",children:e.jsx("img",{src:j.url,alt:`Generated image ${S+1}`,className:"w-full h-full object-cover"})}),e.jsx("div",{className:"p-2 text-xs text-gray-600 bg-white max-h-16 overflow-y-auto",children:Object.entries(j.params).filter(([w,M])=>w!=="nodeParams"&&typeof M!="object").map(([w,M])=>e.jsxs("div",{children:[w,": ",String(M)]},w))})]},S)})}),A>1&&e.jsxs("div",{className:"flex justify-center items-center space-x-2 mt-4 mb-4",children:[e.jsx("button",{onClick:j=>m(1,j),disabled:c===1,className:`px-2 py-1 rounded ${c===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M15.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M8.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L4.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"})]})}),e.jsx("button",{onClick:j=>m(c-1,j),disabled:c===1,className:`px-2 py-1 rounded ${c===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"px-2 py-1 text-xs text-gray-800",children:["Page ",c," of ",A]}),e.jsx("button",{onClick:j=>m(c+1,j),disabled:c===A,className:`px-2 py-1 rounded ${c===A?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",clipRule:"evenodd"})})}),e.jsx("button",{onClick:j=>m(A,j),disabled:c===A,className:`px-2 py-1 rounded ${c===A?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M4.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L8.586 10 4.293 14.293a1 1 0 000 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M11.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L15.586 10l-4.293 4.293a1 1 0 000 1.414z",clipRule:"evenodd"})]})})]}),e.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:j=>g(j),className:"px-3 py-1.5 text-xs bg-gray-100 text-gray-800 rounded-md hover:bg-gray-200 transition-colors",children:"Previous"}),e.jsx("button",{onClick:j=>x(j),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",disabled:n===null,children:"Apply Selected"})]})]})},ut=({visible:l,aiWritingModalText:n,setAiWritingModalText:r,aiGeneratedTexts:x,aiSelectedTexts:g,aiWritingLoading:u,aiWritingError:c,handleAiWriting:m,toggleTextSelection:f,addSelectedTexts:P,onClose:L})=>l?e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-medium",children:"AI Writing Assistant"}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:L,children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"p-4 overflow-y-auto flex-1",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm text-gray-600 mb-2",children:"Enter text and AI will generate variations"}),e.jsx("textarea",{className:"w-full border border-gray-300 rounded-md p-2 text-sm",rows:3,placeholder:"Enter some text here...",value:n,onChange:$=>r($.target.value)}),e.jsx("button",{className:"mt-2 px-4 py-2 bg-blue-100 text-blue-700 rounded-md text-sm flex items-center hover:bg-blue-200 transition-colors",onClick:m,disabled:u,children:u?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-blue-700",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Generating..."]}):e.jsx(e.Fragment,{children:"Generate"})})]}),c&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-sm",children:c}),x.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Generated variations (select items to add):"}),e.jsx("div",{className:"space-y-2 max-h-[40vh] overflow-y-auto p-2",children:x.map(($,D)=>e.jsxs("div",{className:"flex items-start border border-gray-200 rounded-md p-2",children:[e.jsx("div",{className:"mr-2 mt-1",children:e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"checkbox",id:`text${D+1}`,checked:!!g[`text${D+1}`],onChange:()=>f(`text${D+1}`),className:"sr-only"}),e.jsx("div",{className:`h-4 w-4 rounded border ${g[`text${D+1}`]?"bg-blue-600 border-blue-600":"bg-white border-gray-300"} flex items-center justify-center`,onClick:()=>f(`text${D+1}`),children:g[`text${D+1}`]&&e.jsx("svg",{className:"h-3 w-3 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})})]})}),e.jsx("label",{htmlFor:`text${D+1}`,className:"text-sm text-gray-700 cursor-pointer flex-1",children:$})]},D))})]})]}),e.jsxs("div",{className:"p-4 border-t flex justify-end flex-shrink-0",children:[e.jsx("button",{className:"px-4 py-2 bg-gray-100 text-gray-700 rounded-md text-sm mr-2 hover:bg-gray-200 transition-colors",onClick:L,children:"Cancel"}),e.jsx("button",{className:"px-4 py-2 bg-blue-500 text-white rounded-md text-sm hover:bg-blue-600 transition-colors",onClick:P,disabled:Object.values(g).every($=>!$),children:"Add Selected"})]})]})}):null,ye=l=>{const n=[],r={};if(Object.keys(l).forEach(u=>{const c=parseInt(u),m=l[u]||{},f=Object.keys(m).filter(L=>m[L]&&m[L].length>0);if(f.length===0)return;const P=[[]];f.forEach(L=>{const $=m[L],D=[];P.forEach(V=>{$.forEach(A=>{const T=[...V,{nodeId:c,paramName:L,paramValue:String(A)}];D.push(T)})}),P.length=0,P.push(...D)}),r[u]=P}),Object.keys(r).length===0)return n;if(Object.keys(r).length===1){const u=Object.keys(r)[0];return r[u]}const x=Object.keys(r);let g=r[x[0]];for(let u=1;u{c.forEach(P=>{m.push([...f,...P])})}),g=m}return g},mt=(l,n)=>{const r={};r.nodeParams={};const x=ye(l);return n{const c=u.nodeId.toString(),m=u.paramName,f=u.paramValue;r.nodeParams[c]||(r.nodeParams[c]={}),r.nodeParams[c][m]=f,r[m]=f}),r},ht=` +import{j as e}from"./vendor-markdown-Dek94WS0.js";import{r as y}from"./vendor-react-V04_Axys.js";import{r as Qe,g as Xe,m as Ze,i as et}from"./workflowChat-DVyLdfeb.js";import{a as Z,u as Ie,W as Pe,g as tt}from"./message-components-D3rPBq8S.js";import"./input.js";import"./App-Bbre7oqJ.js";function st(l,o){try{if(!l)return console.error("Invalid prompt_output: ",l),l;for(const r of o){if(!l[r.nodeId]){console.error(`Node with ID ${r.nodeId} not found`);continue}if(!l[r.nodeId].inputs){console.error(`Inputs not found for node with ID ${r.nodeId}`);continue}l[r.nodeId].inputs[r.paramName]=r.paramValue}return l}catch(r){return console.error("Error updating prompt:",r),l}}async function rt(l){const o=await Z.graphToPrompt(),r=st(o.output,l);console.log("queuePrompt updated_prompt:",r);const x={prompt:r,client_id:Z.api.clientId,extra_data:{extra_pageinfo:{workflow:o.workflow}}};console.debug("queuePrompt request_body.prompt:",r);const g=await Qe(x);return console.debug("queuePrompt response:",g),g}function Me(l){const o=document.createElement("canvas"),r=o.getContext("2d");if(o.width=512,o.height=512,r){r.fillStyle="#f8d7da",r.fillRect(0,0,o.width,o.height),r.strokeStyle="#dc3545",r.lineWidth=4,r.strokeRect(10,10,o.width-20,o.height-20),r.fillStyle="#dc3545",r.beginPath(),r.arc(o.width/2,150,50,0,2*Math.PI),r.fill(),r.fillStyle="white",r.font="bold 80px Arial",r.textAlign="center",r.textBaseline="middle",r.fillText("!",o.width/2,150),r.fillStyle="#721c24",r.font="20px Arial",r.textAlign="center",r.textBaseline="middle";const x=o.width-60,g=30,u=l.split(" ");let c="",m=250;for(let f=0;fx&&f>0?(r.fillText(c,o.width/2,m),c=u[f]+" ",m+=g):c=P}r.fillText(c,o.width/2,m)}return o.toDataURL("image/png")}async function nt(l){try{if(!l||l==="")return console.log("No prompt ID provided"),{1:[Me("Fail to generate prompt ID")]};const o=await Xe(l);if(!o||!o[l])return console.log("Not finished for prompt ID:",l),{};const r=o[l];if(r.status&&r.status.status_str==="error"){console.error("Error for prompt ID:",l);const g=r.status.messages;if(g&&g.length>0){const u=g[g.length-1];if(u&&u.length>0){const c=u[0];return{1:[Me(c)]}}}}const x={};if(r.outputs)for(const g in r.outputs){const u=r.outputs[g];if(u&&u.images){x[g]=[];for(const c of u.images)if(c&&c.filename&&c.type){const m=Z.graph._nodes_by_id[g].imgs[0].currentSrc.split("?")[0];x[g].push(m+"?filename="+encodeURIComponent(c.filename)+"&type="+encodeURIComponent(c.type)+(c.subfolder?"&subfolder="+encodeURIComponent(c.subfolder):""))}console.log("outputImages for nodeId:",g,x[g])}}return x}catch(o){throw console.error("Error getting output images from prompt:",o),o}}function ot(){const l=Object.values(Z.graph._nodes_by_id),o=[],r=[];for(const x of l)x.type==="SaveImage"?o.push(x.id):x.type==="PreviewImage"&&r.push(x.id);if(console.log("saveNodeIds:",o),console.log("previewNodeIds:",r),o.length===0&&r.length===0)throw new Error("No SaveImage or PreviewImage node found, please add one to the graph");return o.length===1?o[0]:o.length==0&&r.length===1?r[0]:null}async function at(l,o){const r=await nt(l);return Object.keys(r).length===0?null:r[o.toString()]&&r[o.toString()].length>0?r[o.toString()][0]:null}const lt=({selectedNodes:l,handleParamSelect:o,selectedParams:r,handleNext:x,handleClose:g})=>{const c=l.flatMap(m=>(m.widgets||[]).map(f=>f.name)).some(m=>r[m]===!0);return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Select Parameters for Testing"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Choose the parameters you want to include in your batch test"})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:g,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),l.map((m,f)=>{const P=m.title||"Unknown Node",L=m.widgets||[];return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsx("div",{className:"bg-gray-50 px-3 py-2 text-sm font-medium text-gray-700 border-b",children:P}),e.jsx("div",{className:"p-4 space-y-3",children:e.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:L.map(($,_)=>{const F=$.name;return e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:`w-5 h-5 rounded-full border flex items-center justify-center ${r[F]?"border-red-500 bg-red-100":"border-gray-300"}`,onClick:A=>o(F,A),children:r[F]&&e.jsx("div",{className:"w-3 h-3 rounded-full bg-red-500"})}),e.jsx("span",{className:"ml-2 text-gray-700 text-xs",children:F})]},`widget-${_}`)})})})]},`node-${f}`)}),e.jsx("div",{className:"mt-6 flex justify-center",children:e.jsx("button",{onClick:m=>x(m),disabled:!c,className:`px-3 py-1.5 text-xs ${c?"bg-pink-200 text-pink-700 hover:bg-pink-300":"bg-gray-200 text-gray-500 cursor-not-allowed"} rounded-md transition-colors`,children:"Next"})})]})},it=({selectedNodes:l,paramTestValues:o,selectedParams:r,updateParamTestValues:x,toggleDropdown:g,openDropdowns:u,handleTestValueSelect:c,searchTerms:m,handleSearch:f,handleSelectAll:P,handleNext:L,handlePrevious:$,handleClose:_,inputValues:F,setInputValues:A,textInputs:T,handleTextInputChange:D,handleAddTextInput:R,handleRemoveTextInput:v,openAiWritingModal:b})=>{const S=(k,M,q,J=0)=>{if(k=isNaN(k)?0:k,M=isNaN(M)?100:M,q=isNaN(q)||q<=0?1:q,M{!l||l.length===0||l.forEach(k=>{const M=k.id.toString(),q=k.widgets||{};Object.values(q).forEach(h=>{const I=h.name;if(!r[I])return;if(!(o[M]?.[I]?.length>0)&&h.type==="number"){const d=h.options?.min||0,V=h.options?.max||100,O=(h.options?.step||10)/10,C=h.options?.precision||0,B=S(d,V,O,C);if(B.length>0){x(M,I,B);const H=`${M}_${I}`;A(p=>({...p,[H]:{min:d.toString(),max:V.toString(),step:O.toString()}}))}}if(h.type==="customtext"||h.type.toLowerCase().includes("text")){const d=`${M}_${I}`,V=T[d]||[""];JSON.stringify(V)!==JSON.stringify(o[M]?.[I]||[""])&&x(M,I,V)}})})},[l,r,o,T,x,A,S]),e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Parameter Options"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Configure the test values for each parameter"})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:_,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),l.length>0?l.map((k,M)=>{const q=k.widgets||{},J=Object.values(q),h=k.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b flex justify-between items-center",children:[e.jsxs("span",{children:[k.type," (ID: ",h,")"]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:I=>_(I,M),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx("div",{className:"p-4 space-y-4",children:J.map((I,Y)=>{const d=I.name;if(!r[d])return null;const V=`${h}_${d}`;if(I.type==="customtext"||I.type.toLowerCase().includes("text")){const O=T[V]||[""];return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("label",{className:"text-xs font-medium text-gray-700",children:[d,":"]}),e.jsxs("button",{className:"px-2 py-1 bg-blue-100 text-blue-700 rounded text-xs flex items-center hover:bg-blue-200 transition-colors",onClick:()=>b(h,d),children:[e.jsx("svg",{className:"w-3 h-3 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})}),"AI Writing"]})]}),e.jsx("div",{className:"space-y-2",children:O.map((C,B)=>e.jsxs("div",{className:"flex items-start",children:[e.jsx("textarea",{className:`flex-1 border ${C?"border-gray-300":"border-red-500"} rounded p-2 text-xs resize-y`,rows:2,placeholder:"Enter text...",value:C,onChange:H=>D(h,d,B,H.target.value),required:!0}),e.jsx("button",{className:"ml-2 text-red-500 hover:text-red-700",onClick:()=>v(h,d,B),title:"Remove",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]},B))}),e.jsxs("button",{className:"mt-2 px-2 py-1 border border-dashed border-gray-300 rounded text-xs text-gray-600 hover:bg-gray-50 flex items-center",onClick:()=>R(h,d),children:[e.jsx("svg",{className:"w-3 h-3 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),"Add Text"]})]},Y)}if(I.type==="number"){const O=I.options?.min||0,C=I.options?.max||100,B=(I.options?.step||10)/10,H=I.options?.precision||0,p=S(O,C,B,H),U=F[V]||{min:O.toString(),max:C.toString(),step:B.toString()};return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("label",{className:"text-xs font-medium text-gray-700",children:[d,":"]}),e.jsx("div",{className:"w-4"})]}),e.jsxs("div",{className:"flex space-x-2 items-center",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Min"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:U.min,required:!0,onClick:w=>{w.preventDefault(),w.stopPropagation()},onChange:w=>{w.preventDefault(),w.stopPropagation();const E=w.target.value;if(A(W=>({...W,[V]:{...W[V],min:E}})),E===""||!isNaN(parseFloat(E))){const W=E===""?0:parseFloat(E),z=parseFloat(U.max||C.toString()),Q=parseFloat(U.step||B.toString()),K=S(W,z,Q,H);x(h,d,K)}}}),e.jsx("label",{className:"text-xs text-gray-600",children:"Max"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:U.max,onClick:w=>{w.preventDefault(),w.stopPropagation()},required:!0,onChange:w=>{w.preventDefault(),w.stopPropagation();const E=w.target.value;if(A(W=>({...W,[V]:{...W[V],max:E}})),E===""||!isNaN(parseFloat(E))){const W=parseFloat(U.min||O.toString()),z=E===""?W:parseFloat(E),Q=parseFloat(U.step||B.toString()),K=S(W,z,Q,H);x(h,d,K)}}}),e.jsx("label",{className:"text-xs text-gray-600",children:"Step"}),e.jsx("input",{type:"text",className:"w-12 h-6 border border-gray-300 rounded text-xs px-2",value:U.step,required:!0,onClick:w=>{w.preventDefault(),w.stopPropagation()},onChange:w=>{w.preventDefault(),w.stopPropagation();const E=w.target.value;if(A(W=>({...W,[V]:{...W[V],step:E}})),E===""||!isNaN(parseFloat(E))&&parseFloat(E)>0){const W=parseFloat(U.min||O.toString()),z=parseFloat(U.max||C.toString()),Q=E===""?1:parseFloat(E),K=S(W,z,Q,H);x(h,d,K)}}})]}),e.jsxs("div",{className:"mt-1",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:(()=>{const w=o[h]?.[d]||p;if(w.length<=10)return w.map((E,W)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:z=>{z.stopPropagation(),c(h,d,E,z)},children:[e.jsx("span",{children:E}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},W));{const E=w.slice(0,5),W=w.slice(w.length-5);return e.jsxs(e.Fragment,{children:[E.map((z,Q)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:K=>{K.stopPropagation(),c(h,d,z,K)},children:[e.jsx("span",{children:z}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},`first-${Q}`)),e.jsx("div",{className:"px-2 py-0.5 bg-gray-100 text-gray-600 rounded-md flex items-center text-xs",children:"..."}),W.map((z,Q)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs cursor-pointer hover:bg-blue-200",onClick:K=>{K.stopPropagation(),c(h,d,z,K)},children:[e.jsx("span",{children:z}),e.jsx("svg",{className:"w-4 h-4 ml-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},`last-${Q}`))]})}})()})]}),e.jsx("div",{className:"mt-1",children:e.jsx("p",{className:"text-xs text-gray-500",children:"Values are distributed evenly between Min and Max"})})]},Y)}else if(I.type==="combo"){const O=I.options?.values||[],C=`${h}_${d}`,B=p=>typeof p=="string"?p:p&&typeof p=="object"&&"name"in p?p.name:String(p),H=p=>typeof p=="object"&&p!==null&&"name"in p?p.name:p;return e.jsxs("div",{className:"border-b pb-3",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("label",{className:"text-xs font-medium text-gray-700",children:d}),e.jsxs("div",{className:"relative dropdown-container",children:[e.jsxs("button",{className:`appearance-none border ${(o[h]?.[d]||[]).length===0?"border-red-500":"border-gray-300"} rounded px-2 py-0.5 pr-6 text-xs flex items-center bg-white text-gray-700`,onClick:p=>{p.preventDefault(),p.stopPropagation(),g(h,d,p)},"data-dropdown":C,children:[e.jsx("span",{children:(o[h]?.[d]||[]).length>0?`${d}: ${(o[h]?.[d]||[]).length} selected`:`Select ${d}`}),e.jsx("div",{className:"ml-2",children:e.jsx("svg",{className:"fill-current h-4 w-4",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",children:e.jsx("path",{d:"M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"})})})]}),u[C]&&e.jsxs("div",{className:"absolute z-[9999] mt-1 w-64 bg-white border border-gray-300 rounded-md shadow-lg dropdown-menu",style:{position:"fixed",top:typeof u[C]=="object"?`${u[C].y}px`:"0px",left:typeof u[C]=="object"?`${u[C].x}px`:"0px",maxHeight:"300px",overflowY:"auto"},children:[e.jsx("div",{className:"p-2 border-b sticky top-0 bg-white",children:e.jsx("input",{type:"text",className:"w-full px-2 py-0.5 text-xs border border-gray-300 rounded",placeholder:"Search...",value:m[C]||"",onChange:p=>{p.preventDefault(),p.stopPropagation(),f(h,d,p.target.value)},onClick:p=>{p.preventDefault(),p.stopPropagation()},autoFocus:!0})}),e.jsxs("div",{className:"px-3 py-1.5 bg-gray-50 border-b cursor-pointer text-xs flex items-center text-gray-700 hover:bg-gray-100",onClick:p=>{p.preventDefault(),p.stopPropagation();const w=O.filter(E=>!m[C]||B(E).toLowerCase().includes((m[C]||"").toLowerCase())).map(H);P(h,d,w)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${O.length>0&&(o[h]?.[d]||[]).length===O.length?"bg-blue-500 border-blue-500":(o[h]?.[d]||[]).length>0?"bg-blue-500 border-blue-500 opacity-50":"border-gray-300"}`,children:(o[h]?.[d]||[]).length>0&&e.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("span",{className:"font-medium",children:O.length>0&&(o[h]?.[d]||[]).length===O.length?"Deselect All":"Select All"})]}),e.jsxs("div",{className:"max-h-60 overflow-y-auto",children:[O.filter(p=>!m[C]||B(p).toLowerCase().includes((m[C]||"").toLowerCase())).map((p,U)=>e.jsxs("div",{className:"px-3 py-1.5 hover:bg-gray-100 cursor-pointer text-xs flex items-center text-gray-700",onClick:w=>{w.preventDefault(),w.stopPropagation(),c(h,d,H(p),w)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${(o[h]?.[d]||[]).includes(H(p))?"bg-blue-500 border-blue-500":"border-gray-300"}`,children:(o[h]?.[d]||[]).includes(H(p))&&e.jsx("svg",{className:"w-3 h-3 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("span",{className:"whitespace-normal overflow-hidden text-ellipsis",children:B(p)})]},U)),O.filter(p=>!m[C]||B(p).toLowerCase().includes((m[C]||"").toLowerCase())).length===0&&e.jsx("div",{className:"px-3 py-4 text-sm text-gray-500 text-center",children:"No matching options"})]})]})]})]}),e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),(o[h]?.[d]||[]).length===0&&e.jsx("div",{className:"text-xs text-red-500 mt-1",children:"Please select at least one value"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:(o[h]?.[d]||[]).map((p,U)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs",children:[e.jsx("span",{children:p}),e.jsx("svg",{className:"w-4 h-4 ml-1 cursor-pointer hover:text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",onClick:w=>{w.preventDefault(),w.stopPropagation(),c(h,d,p,w)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},U))})]})]},Y)}else return e.jsxs("div",{className:"border-b pb-3",children:[e.jsx("div",{className:"flex justify-between items-center",children:e.jsx("label",{className:"text-xs font-medium text-gray-700",children:d})}),e.jsxs("div",{className:"mt-2",children:[e.jsx("label",{className:"text-xs text-gray-600",children:"Test values"}),e.jsxs("div",{className:"mt-1 flex flex-wrap gap-1",children:[(o[h]?.[d]||[]).map((O,C)=>e.jsxs("div",{className:"px-2 py-0.5 bg-blue-100 text-blue-800 rounded-md flex items-center text-xs",children:[e.jsx("span",{children:O}),e.jsx("svg",{className:"w-4 h-4 ml-1 cursor-pointer hover:text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",onClick:B=>{B.preventDefault(),B.stopPropagation(),c(h,d,O,B)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},C)),e.jsxs("button",{className:"px-2 py-0.5 border border-dashed border-blue-300 text-blue-600 rounded-md text-xs flex items-center hover:bg-blue-50",onClick:O=>{O.preventDefault(),O.stopPropagation();const C=`${d}${(o[h]?.[d]||[]).length+1}`;x(h,d,[...o[h]?.[d]||[],C])},children:[e.jsx("svg",{className:"w-4 h-4 mr-1",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),e.jsx("span",{children:"Add"})]})]})]})]},Y)})})]},M)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500",children:"No nodes selected. Please select a node in the workflow to configure parameters."}),e.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:k=>$(k),className:"px-3 py-1.5 text-xs bg-gray-100 text-gray-800 rounded-md hover:bg-gray-200 transition-colors",children:"Previous"}),e.jsx("button",{onClick:k=>L(k),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",children:"Next"})]})]})},ct=({selectedNodes:l,paramTestValues:o,selectedParams:r,totalCount:x,errorMessage:g,handlePrevious:u,handleStartGeneration:c,handleClose:m})=>{const[f,P]=y.useState([]),[L,$]=y.useState(null),[_,F]=y.useState(!1);Ie();const A=()=>{const D=Object.values(Z.graph._nodes_by_id),R=[],v=[];for(const S of D)S.type==="SaveImage"?R.push(S.id):S.type==="PreviewImage"&&v.push(S.id);const b=[...R,...v];P(b),b.length===1?$(b[0]):b.length>1&&(F(!0),$(null))};y.useEffect(()=>{A()},[]),y.useEffect(()=>{const D=()=>{if(!Z.canvas.selected_nodes)return;const R=Object.values(Z.canvas.selected_nodes);if(R.length===0)return;const v=R[0];v&&(v.type==="SaveImage"||v.type==="PreviewImage")&&(console.log("Selected image node:",v.id),$(v.id))};return document.addEventListener("click",D),()=>{document.removeEventListener("click",D)}},[]);const T=D=>{if(D&&(D.preventDefault(),D.stopPropagation()),f.length>1&&!L){F(!0);return}c(D,L||void 0)};return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Confirm Test Configuration"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["In the selected parameter combinations, there are ",x," total runs. Each run will generate a separate image."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:m,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),_&&f.length>1&&e.jsx("div",{className:"mb-4 p-3 bg-yellow-50 border border-yellow-200 rounded-md text-amber-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:L===null?`Multiple SaveImage and PreviewImage nodes detected with IDs ${f.join(",")}. Please click the node on canvas.`:`Current node ID is ${L}, please click Start Generation again`})]})}),g&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:g})]})}),l.length>0?l.map((D,R)=>{const v=D.type||"Unknown Node",b=D.widgets||[],S=D.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b",children:[v," (ID: ",S,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:b.map((k,M)=>{const q=k.name;if(!r[q])return null;const J=o[S]?.[q]||[],h=Array.isArray(J)?`[${J.join(", ")}]`:JSON.stringify(J);return e.jsxs("div",{className:MI.preventDefault()})})]},M)})})]},R)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500 text-xs",children:"No nodes selected. Please select a node in the workflow to configure parameters."}),e.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:D=>u(D),className:"px-3 py-1.5 text-xs bg-gray-100 text-gray-800 rounded-md hover:bg-gray-200 transition-colors",children:"Previous"}),e.jsx("button",{onClick:D=>T(D),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${f.length>1&&!L?"bg-gray-200 text-gray-500 cursor-not-allowed":"bg-pink-200 text-pink-700 hover:bg-pink-300"}`,disabled:f.length>1&&!L,children:"Start Generation"})]})]})},dt=({selectedNodes:l,paramTestValues:o,selectedParams:r,totalCount:x,completedCount:g,errorMessage:u,handleClose:c,setIsProcessing:m,setCurrentScreen:f,cleanupPolling:P})=>{const L=$=>{$.preventDefault(),$.stopPropagation(),Ze({clear:!0}),et(),P&&P(),m(!1),f(2)};return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4 relative",children:[e.jsx("div",{className:"absolute inset-0 bg-gray-500 bg-opacity-30 flex flex-col items-center justify-center z-10",children:e.jsxs("div",{className:"text-center text-gray-800 bg-white p-4 rounded-lg shadow-lg",children:[e.jsx("div",{className:"mb-2 text-sm font-medium",children:"Processing..."}),e.jsxs("div",{className:"text-xs mb-3",children:["Completed ",g," of ",x," runs"]}),e.jsx("div",{className:"w-48 h-2 bg-gray-200 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-pink-500 transition-all duration-200",style:{width:`${g/x*100}%`}})}),e.jsxs("div",{className:"mt-2 text-xs text-gray-600",children:["Already generated ",g," images"]}),e.jsx("button",{onClick:L,className:"mt-4 px-3 py-1.5 text-xs bg-gray-200 text-gray-800 rounded-md hover:bg-gray-300 transition-colors",children:"Cancel"})]})}),e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Confirm Test Configuration"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["In the selected parameter combinations, there are ",x," total runs. Each run will generate a separate image."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:c,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),u&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-xs",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"flex-shrink-0 mt-0.5",children:e.jsx("svg",{className:"h-3 w-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),e.jsx("div",{className:"ml-2",children:u})]})}),l.length>0?l.map(($,_)=>{const F=$.type||"Unknown Node",A=$.widgets||[],T=$.id;return e.jsxs("div",{className:"border rounded-md mb-4 overflow-hidden",children:[e.jsxs("div",{className:"bg-gray-50 px-3 py-2 text-xs font-medium text-gray-700 border-b",children:[F," (ID: ",T,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:A.map((D,R)=>{const v=D.name;if(!r[v])return null;const b=o[T]?.[v]||[],S=Array.isArray(b)?`[${b.join(", ")}]`:JSON.stringify(b);return e.jsxs("div",{className:Rk.preventDefault()})})]},R)})})]},_)}):e.jsx("div",{className:"border rounded-md mb-4 p-4 text-center text-gray-500",children:"No nodes selected. Please select a node in the workflow to configure parameters."})]})},xt=({generatedImages:l,selectedImageIndex:o,handleSelectImage:r,handleApplySelected:x,handlePrevious:g,handleClose:u,currentPage:c,handlePageChange:m,imagesPerPage:f,notificationVisible:P,modalVisible:L,modalImageUrl:$,openImageModal:_,closeImageModal:F})=>{const A=Math.ceil(l.length/f),T=(c-1)*f,D=Math.min(T+f,l.length),R=l.slice(T,D);return e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border border-gray-200 p-4",children:[e.jsxs("div",{className:"mb-4 border-b pb-2 flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-medium text-gray-800",children:"Generation Complete"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["All ",l.length," images have been generated."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:u,children:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),P&&e.jsx("div",{className:"fixed top-4 right-4 bg-green-100 border-l-4 border-green-500 text-green-700 p-3 shadow-md rounded animate-fade-in-out z-50",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"py-1",children:e.jsx("svg",{className:"h-4 w-4 text-green-500 mr-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),e.jsx("p",{className:"text-xs",children:"Parameters has been applied."})]})}),L&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50",onClick:F,children:e.jsxs("div",{className:"bg-white rounded-lg p-2 max-w-4xl max-h-[90vh] relative",onClick:v=>v.stopPropagation(),children:[e.jsx("button",{className:"absolute top-2 right-2 text-gray-700 hover:text-gray-900 rounded-full hover:bg-gray-200 p-1",onClick:F,children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}),e.jsx("div",{className:"overflow-auto max-h-[calc(90vh-4rem)]",children:e.jsx("img",{src:$,alt:"Enlarged image",className:"max-w-full h-auto"})})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-4 mb-6",children:R.map((v,b)=>{const S=T+b;return e.jsxs("div",{className:`relative rounded-lg overflow-hidden border ${o===S?"border-pink-500 ring-2 ring-pink-300":"border-gray-200"}`,onClick:k=>r(S,k),children:[e.jsx("button",{className:"absolute top-2 right-2 bg-white bg-opacity-75 rounded-full p-0.5 text-gray-600 hover:text-gray-900 shadow-sm z-10",onClick:k=>_(v.url,k),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5v-4m0 4h-4m4 0l-5-5"})})}),e.jsx("div",{className:"aspect-square",children:e.jsx("img",{src:v.url,alt:`Generated image ${S+1}`,className:"w-full h-full object-cover"})}),e.jsx("div",{className:"p-2 text-xs text-gray-600 bg-white max-h-16 overflow-y-auto",children:Object.entries(v.params).filter(([k,M])=>k!=="nodeParams"&&typeof M!="object").map(([k,M])=>e.jsxs("div",{children:[k,": ",String(M)]},k))})]},S)})}),A>1&&e.jsxs("div",{className:"flex justify-center items-center space-x-2 mt-4 mb-4",children:[e.jsx("button",{onClick:v=>m(1,v),disabled:c===1,className:`px-2 py-1 rounded ${c===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M15.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M8.707 15.707a1 1 0 01-1.414 0l-5-5a1 1 0 010-1.414l5-5a1 1 0 111.414 1.414L4.414 10l4.293 4.293a1 1 0 010 1.414z",clipRule:"evenodd"})]})}),e.jsx("button",{onClick:v=>m(c-1,v),disabled:c===1,className:`px-2 py-1 rounded ${c===1?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"px-2 py-1 text-xs text-gray-800",children:["Page ",c," of ",A]}),e.jsx("button",{onClick:v=>m(c+1,v),disabled:c===A,className:`px-2 py-1 rounded ${c===A?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",clipRule:"evenodd"})})}),e.jsx("button",{onClick:v=>m(A,v),disabled:c===A,className:`px-2 py-1 rounded ${c===A?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-100"}`,children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{fillRule:"evenodd",d:"M4.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L8.586 10 4.293 14.293a1 1 0 000 1.414z",clipRule:"evenodd"}),e.jsx("path",{fillRule:"evenodd",d:"M11.293 15.707a1 1 0 001.414 0l5-5a1 1 0 000-1.414l-5-5a1 1 0 00-1.414 1.414L15.586 10l-4.293 4.293a1 1 0 000 1.414z",clipRule:"evenodd"})]})})]}),e.jsxs("div",{className:"mt-6 flex justify-between",children:[e.jsx("button",{onClick:v=>g(v),className:"px-3 py-1.5 text-xs bg-gray-100 text-gray-800 rounded-md hover:bg-gray-200 transition-colors",children:"Previous"}),e.jsx("button",{onClick:v=>x(v),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",disabled:o===null,children:"Apply Selected"})]})]})},ut=({visible:l,aiWritingModalText:o,setAiWritingModalText:r,aiGeneratedTexts:x,aiSelectedTexts:g,aiWritingLoading:u,aiWritingError:c,handleAiWriting:m,toggleTextSelection:f,addSelectedTexts:P,onClose:L})=>l?e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b flex justify-between items-center",children:[e.jsx("h3",{className:"text-lg font-medium",children:"AI Writing Assistant"}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:L,children:e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"p-4 overflow-y-auto flex-1",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm text-gray-600 mb-2",children:"Enter text and AI will generate variations"}),e.jsx("textarea",{className:"w-full border border-gray-300 rounded-md p-2 text-sm",rows:3,placeholder:"Enter some text here...",value:o,onChange:$=>r($.target.value)}),e.jsx("button",{className:"mt-2 px-4 py-2 bg-blue-100 text-blue-700 rounded-md text-sm flex items-center hover:bg-blue-200 transition-colors",onClick:m,disabled:u,children:u?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-blue-700",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Generating..."]}):e.jsx(e.Fragment,{children:"Generate"})})]}),c&&e.jsx("div",{className:"mb-4 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-sm",children:c}),x.length>0&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Generated variations (select items to add):"}),e.jsx("div",{className:"space-y-2 max-h-[40vh] overflow-y-auto p-2",children:x.map(($,_)=>e.jsxs("div",{className:"flex items-start border border-gray-200 rounded-md p-2",children:[e.jsx("div",{className:"mr-2 mt-1",children:e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"checkbox",id:`text${_+1}`,checked:!!g[`text${_+1}`],onChange:()=>f(`text${_+1}`),className:"sr-only"}),e.jsx("div",{className:`h-4 w-4 rounded border ${g[`text${_+1}`]?"bg-blue-600 border-blue-600":"bg-white border-gray-300"} flex items-center justify-center`,onClick:()=>f(`text${_+1}`),children:g[`text${_+1}`]&&e.jsx("svg",{className:"h-3 w-3 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})})]})}),e.jsx("label",{htmlFor:`text${_+1}`,className:"text-sm text-gray-700 cursor-pointer flex-1",children:$})]},_))})]})]}),e.jsxs("div",{className:"p-4 border-t flex justify-end flex-shrink-0",children:[e.jsx("button",{className:"px-4 py-2 bg-gray-100 text-gray-700 rounded-md text-sm mr-2 hover:bg-gray-200 transition-colors",onClick:L,children:"Cancel"}),e.jsx("button",{className:"px-4 py-2 bg-blue-500 text-white rounded-md text-sm hover:bg-blue-600 transition-colors",onClick:P,disabled:Object.values(g).every($=>!$),children:"Add Selected"})]})]})}):null,ye=l=>{const o=[],r={};if(Object.keys(l).forEach(u=>{const c=parseInt(u),m=l[u]||{},f=Object.keys(m).filter(L=>m[L]&&m[L].length>0);if(f.length===0)return;const P=[[]];f.forEach(L=>{const $=m[L],_=[];P.forEach(F=>{$.forEach(A=>{const T=[...F,{nodeId:c,paramName:L,paramValue:String(A)}];_.push(T)})}),P.length=0,P.push(..._)}),r[u]=P}),Object.keys(r).length===0)return o;if(Object.keys(r).length===1){const u=Object.keys(r)[0];return r[u]}const x=Object.keys(r);let g=r[x[0]];for(let u=1;u{c.forEach(P=>{m.push([...f,...P])})}),g=m}return g},mt=(l,o)=>{const r={};r.nodeParams={};const x=ye(l);return o{const c=u.nodeId.toString(),m=u.paramName,f=u.paramValue;r.nodeParams[c]||(r.nodeParams[c]={}),r.nodeParams[c][m]=f,r[m]=f}),r},ht=` @keyframes highlight-pulse { 0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5); @@ -26,4 +26,4 @@ import{j as e}from"./vendor-markdown-Dek94WS0.js";import{r as b}from"./vendor-re .animate-fade-in-out { animation: fade-in-out 3s forwards; } -`,vt=({selectedNodes:l,visible:n,onClose:r})=>{const[x,g]=b.useState(0),[u,c]=b.useState({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),[m,f]=b.useState(!1),[P,L]=b.useState(!1),[$,D]=b.useState(0),[V,A]=b.useState(12),[T,_]=b.useState(null),[R,j]=b.useState(()=>Array(12).fill(null).map((t,s)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:s%3===0?5:s%3===1?10:15,sampler_name:"euler",cfg:1}}))),[k,S]=b.useState({}),[w,M]=b.useState({}),[q,J]=b.useState({}),[h,I]=b.useState({}),[Y,d]=b.useState(1),G=6,[O,N]=b.useState(null),[B,H]=b.useState(!1),[p,U]=b.useState(!1),[y,E]=b.useState(""),[W,z]=b.useState({}),[Q,K]=b.useState(!1),[pe,ge]=b.useState(""),[ve,de]=b.useState([]),[Ee,xe]=b.useState(!1),[we,Ne]=b.useState(""),[ke,Ce]=b.useState(""),[$e,ne]=b.useState(null),[Se,oe]=b.useState({}),{dispatch:ae}=Ie(),ue=b.useRef(null),le=b.useRef(null),We=async()=>{if(!pe.trim()){ne("Please enter some text to generate variations");return}xe(!0),ne(null),de([]),oe({});try{const t=await Pe.generateSDPrompts(pe);de(t);const s={};t.forEach((i,o)=>{s[`text${o+1}`]=!1}),oe(s)}catch(t){console.error("Error generating text:",t),ne("Failed to generate text variations. Please try again.")}finally{xe(!1)}},De=(t,s,i,o)=>{const a=`${t}_${s}`;z(v=>{const F=[...v[a]||[]];return F[i]=o,{...v,[a]:F}});const C=[...W[a]||[]];C[i]=o,ee(t,s,C)},_e=(t,s)=>{const i=`${t}_${s}`;z(a=>{const C=[...a[i]||[]];return C.push(""),{...a,[i]:C}});const o=[...W[i]||[],""];ee(t,s,o)},Oe=(t,s,i)=>{const o=`${t}_${s}`;z(C=>{const v=[...C[o]||[]];return v.splice(i,1),{...C,[o]:v}});const a=[...W[o]||[]];a.splice(i,1),ee(t,s,a)},Ae=t=>{oe(s=>({...s,[t]:!s[t]}))},Be=()=>{const t=`${we}_${ke}`,s=Object.entries(Se).filter(([o,a])=>a).map(([o])=>{const a=parseInt(o.replace("text",""))-1;return ve[a]});if(s.length===0)return;z(o=>{const a=[...o[t]||[]];return{...o,[t]:[...a,...s]}});const i=[...W[t]||[],...s];ee(we,ke,i),K(!1)},Te=(t,s)=>{K(!0),Ne(t),Ce(s),ge(""),de([]),oe({}),xe(!1),ne(null)};b.useEffect(()=>{if(!l||l.length===0)return;const t={...k},s=l.map(o=>o.id.toString());Object.keys(t).forEach(o=>{s.includes(o)||delete t[o]}),l.forEach(o=>{const a=o.id.toString();t[a]||(t[a]={})}),JSON.stringify(t)!==JSON.stringify(k)&&S(t)},[l,k]),b.useEffect(()=>{ae({type:"SET_SCREEN_STATE",payload:{currentScreen:x,isProcessing:m,isCompleted:P}})},[x,m,P,ae]),b.useEffect(()=>{const t=document.createElement("style");return t.textContent=ht,document.head.appendChild(t),()=>{document.head.removeChild(t)}},[]),b.useEffect(()=>{const t=s=>{if(Object.values(w).some(i=>i)){const i=s.target,o=!!i.closest(".dropdown-menu"),a=!!i.closest("[data-dropdown]");!o&&!a&&M({})}};return document.addEventListener("mousedown",t),()=>{document.removeEventListener("mousedown",t)}},[w]);const Le=t=>{if(t&&(t.preventDefault(),t.stopPropagation()),x===0){const s={...k};Object.keys(s).forEach(i=>{const o=s[i];Object.keys(o).forEach(a=>{u[a]||delete o[a]})}),S(s)}if(x===1){const s={...k};l.forEach(o=>{const a=o.id.toString(),C=o.widgets||{};Object.values(C).forEach(v=>{const F=v.name;if(u[F]&&(v.type==="customtext"||v.type.toLowerCase().includes("text"))){const te=`${a}_${F}`,se=W[te]||[""];s[a]=s[a]||{},s[a][F]=se}})}),S(s);const i=ye(s);A(i.length)}N(null),g(s=>Math.min(s+1,2))},fe=t=>{if(t&&(t.preventDefault(),t.stopPropagation()),N(null),P&&L(!1),x===1){const s=l.map(a=>a.id.toString()),i=Object.keys(k),o={...k};i.forEach(a=>{s.includes(a)||delete o[a]}),S(o)}if(x===2||P){const s={...k};Object.entries(W).forEach(([i,o])=>{if(!o||o.length===0)return;const[a,C]=i.split("_");l.some(v=>v.id.toString()===a)&&(s[a]=s[a]||{},JSON.stringify(s[a][C])!==JSON.stringify(o)&&(s[a][C]=o))}),S(s)}g(s=>Math.max(s-1,0))},Re=(t,s)=>{s&&(s.preventDefault(),s.stopPropagation());const i=u[t];if(c(o=>({...o,[t]:!i})),i){const o={...k};Object.keys(o).forEach(a=>{o[a][t]&&delete o[a][t]}),S(o)}},ze=(t,s,i)=>{i.preventDefault(),i.stopPropagation();const o=`${t}_${s}`;M(a=>{if(a[o]&&typeof a[o]=="object"?a[o].isOpen:!!a[o])return{...a,[o]:!1};{let v=0,F=0;if(i.currentTarget){const ce=i.currentTarget.getBoundingClientRect();v=ce.left,F=ce.bottom}else v=i.clientX,F=i.clientY+20;const te=window.innerWidth,se=250;return v+se>te&&(v=te-se-10),v<0&&(v=10),{...a,[o]:{isOpen:!0,x:v,y:F}}}})},ee=(t,s,i)=>{S(o=>{const a={...o};return a[t]||(a[t]={}),a[t][s]=i,a})},Fe=(t,s,i,o)=>{o&&(o.preventDefault(),o.stopPropagation()),S(a=>{const C={...a};C[t]||(C[t]={}),C[t][s]||(C[t][s]=[]);const v=C[t][s];return v.includes(i)?C[t][s]=v.filter(F=>F!==i):C[t][s]=[...v,i],C})},Ve=(t,s,i)=>{const o=`${t}_${s}`;J(a=>({...a,[o]:i}))},Ge=(t,s,i)=>{if(!k[t]){ee(t,s,i);return}const o=k[t][s]||[];i.length===o.length?ee(t,s,[]):ee(t,s,[...i])},Ue=(t,s)=>{s&&(s.preventDefault(),s.stopPropagation()),d(Math.max(1,Math.min(t,Math.ceil(R.length/G))))},me=()=>{ue.current&&(clearTimeout(ue.current),ue.current=null),le.current=null};b.useEffect(()=>()=>{me()},[]);const He=async(t,s)=>{t&&(t.preventDefault(),t.stopPropagation()),me();const i=ye(k),o=i.length;if(o>100){N(`Cannot generate more than 100 images at once (currently: ${o} images)`);return}if(N(null),f(!0),D(0),console.log("Generated parameter combinations:",i),i.length===0){N("No valid parameter combinations found. Please check your parameter selections."),f(!1);return}let a=s||null;if(a===null){const v=ot();v!==null&&(a=v)}if(a===null){N("Please select a SaveImage or PreviewImage node first."),f(!1);return}const C=[];try{const v=Date.now().toString();le.current=v;for(const re of i){const X=await rt(re);X.prompt_id?C.push(X.prompt_id):(console.error("Failed to get prompt_id from response:",X),C.push(""))}const F=Array(i.length).fill(null).map((re,X)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:mt(k,X)}));j(F);const te=Date.now(),se=5*60*1e3,ce=async()=>{if(le.current!==v){console.log("Another polling session has started, stopping this one");return}if(Date.now()-te>se){console.log("Timeout reached while waiting for images"),le.current===v&&(f(!1),L(!0),d(1));return}let re=0;for(let X=0;X{s&&(s.preventDefault(),s.stopPropagation()),_(t)},Ke=(t,s)=>{s.preventDefault(),s.stopPropagation(),E(t),U(!0)},Je=t=>{t&&(t.preventDefault(),t.stopPropagation()),U(!1)},Ye=async t=>{if(t&&(t.preventDefault(),t.stopPropagation()),T!==null){console.log(`Applied image ${T+1} with parameters:`,R[T].params),Pe.trackEvent({event_type:"parameter_debug_apply",message_type:"parameter_debug",message_id:tt(),data:{workflow:(await Z.graphToPrompt()).output,selected_params:R[T].params,all_params:k,count:Object.keys(k).length}});const s=R[T].params;s.nodeParams&&(Object.entries(s.nodeParams).forEach(([i,o])=>{const a=Z.graph._nodes_by_id[i];!a||!a.widgets||Object.entries(o).forEach(([C,v])=>{for(const F of a.widgets)if(F.name===C){F.value=v;break}})}),Z.graph.setDirtyCanvas(!1,!0),H(!0),setTimeout(()=>{H(!1)},3e3))}},ie=(t,s)=>{if(t&&(t.preventDefault(),t.stopPropagation()),x===1&&s!==void 0){const i=[...l],o=i[s];if(i.splice(s,1),o){const a=o.id.toString();S(C=>{const v={...C};return delete v[a],v})}i.length===0?r&&(ae({type:"SET_SCREEN_STATE",payload:null}),be(),r()):ae({type:"SET_SELECTED_NODE",payload:i});return}r?(ae({type:"SET_SCREEN_STATE",payload:null}),be(),r()):be()},be=()=>{g(0),c({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),me(),f(!1),L(!1),D(0),A(12),_(null),j(Array(12).fill(null).map((t,s)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:s%3===0?5:s%3===1?10:15,sampler_name:"euler",cfg:1}}))),S({}),M({}),J({}),I({}),d(1),N(null),H(!1),U(!1),E(""),z({}),K(!1),ge(""),de([]),xe(!1),Ne(""),Ce(""),ne(null),oe({})};return!n||l.length===0?e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center p-8 bg-gray-50 overflow-y-auto",onClick:t=>t.stopPropagation(),children:e.jsxs("div",{className:"max-w-lg p-8 bg-white rounded-lg shadow-sm border border-blue-100 relative",children:[e.jsxs("div",{className:"mb-6 text-center",children:[e.jsx("h3",{className:"text-base font-bold text-blue-800 mb-2",children:"GenLab"}),e.jsx("div",{className:"h-1 w-16 bg-blue-500 mx-auto rounded-full mb-4"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx("div",{className:"bg-blue-100 p-2 rounded-full text-blue-600",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{d:"M5 3a2 2 0 00-2 2v2a2 2 0 002 2h2a2 2 0 002-2V5a2 2 0 00-2-2H5zM5 11a2 2 0 00-2 2v2a2 2 0 002 2h2a2 2 0 002-2v-2a2 2 0 00-2-2H5zM11 5a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V5zM11 13a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"})})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-800",children:"Batch Test Parameter Pairs"}),e.jsx("p",{className:"text-xs text-gray-600",children:"Select a node to batch test parameter pairs"})]})]}),e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx("div",{className:"bg-indigo-100 p-2 rounded-full text-indigo-600",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-800",children:"How To Use"}),e.jsx("p",{className:"text-xs text-gray-600",children:"Click on any node in your workflow to start the parameter testing process"})]})]}),e.jsx("div",{className:"mt-6 text-center",children:e.jsx("p",{className:"text-xs text-gray-600 mb-3",children:"No node is currently selected"})})]})]})}):P?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(xt,{generatedImages:R,selectedImageIndex:T,handleSelectImage:qe,handleApplySelected:Ye,handlePrevious:fe,handleClose:ie,currentPage:Y,handlePageChange:Ue,imagesPerPage:G,notificationVisible:B,modalVisible:p,modalImageUrl:y,openImageModal:Ke,closeImageModal:Je})}):m?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(dt,{selectedNodes:l,paramTestValues:k,selectedParams:u,totalCount:V,completedCount:$,errorMessage:O,handleClose:ie,setIsProcessing:f,setCurrentScreen:g,cleanupPolling:me})}):x===0?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:t=>t.stopPropagation(),children:e.jsx(lt,{selectedNodes:l,handleParamSelect:Re,selectedParams:u,handleNext:Le,handleClose:ie})}):x===1?e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:t=>t.stopPropagation(),children:[e.jsx(it,{selectedNodes:l,paramTestValues:k,selectedParams:u,updateParamTestValues:ee,toggleDropdown:ze,openDropdowns:w,handleTestValueSelect:Fe,searchTerms:q,handleSearch:Ve,handleSelectAll:Ge,handleNext:Le,handlePrevious:fe,handleClose:ie,inputValues:h,setInputValues:I,textInputs:W,handleTextInputChange:De,handleAddTextInput:_e,handleRemoveTextInput:Oe,openAiWritingModal:Te}),e.jsx(ut,{visible:Q,aiWritingModalText:pe,setAiWritingModalText:ge,aiGeneratedTexts:ve,aiSelectedTexts:Se,aiWritingLoading:Ee,aiWritingError:$e,handleAiWriting:We,toggleTextSelection:Ae,addSelectedTexts:Be,onClose:()=>K(!1)})]}):e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:t=>t.stopPropagation(),children:e.jsx(ct,{selectedNodes:l,paramTestValues:k,selectedParams:u,totalCount:V,errorMessage:O,handlePrevious:fe,handleStartGeneration:He,handleClose:ie})})};export{vt as ParameterDebugInterface}; +`,vt=({selectedNodes:l,visible:o,onClose:r})=>{const[x,g]=y.useState(0),[u,c]=y.useState({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),[m,f]=y.useState(!1),[P,L]=y.useState(!1),[$,_]=y.useState(0),[F,A]=y.useState(12),[T,D]=y.useState(null),[R,v]=y.useState(()=>Array(12).fill(null).map((t,s)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:s%3===0?5:s%3===1?10:15,sampler_name:"euler",cfg:1}}))),[b,S]=y.useState({}),[k,M]=y.useState({}),[q,J]=y.useState({}),[h,I]=y.useState({}),[Y,d]=y.useState(1),V=6,[O,C]=y.useState(null),[B,H]=y.useState(!1),[p,U]=y.useState(!1),[w,E]=y.useState(""),[W,z]=y.useState({}),[Q,K]=y.useState(!1),[pe,ge]=y.useState(""),[ve,de]=y.useState([]),[Ee,xe]=y.useState(!1),[we,Ne]=y.useState(""),[ke,Ce]=y.useState(""),[$e,ne]=y.useState(null),[Se,oe]=y.useState({}),{dispatch:ae}=Ie(),ue=y.useRef(null),le=y.useRef(null),We=async()=>{if(!pe.trim()){ne("Please enter some text to generate variations");return}xe(!0),ne(null),de([]),oe({});try{const t=await Pe.generateSDPrompts(pe);de(t);const s={};t.forEach((i,n)=>{s[`text${n+1}`]=!1}),oe(s)}catch(t){console.error("Error generating text:",t),ne("Failed to generate text variations. Please try again.")}finally{xe(!1)}},_e=(t,s,i,n)=>{const a=`${t}_${s}`;z(N=>{const G=[...N[a]||[]];return G[i]=n,{...N,[a]:G}});const j=[...W[a]||[]];j[i]=n,te(t,s,j)},De=(t,s)=>{const i=`${t}_${s}`;z(a=>{const j=[...a[i]||[]];return j.push(""),{...a,[i]:j}});const n=[...W[i]||[],""];te(t,s,n)},Oe=(t,s,i)=>{const n=`${t}_${s}`;z(j=>{const N=[...j[n]||[]];return N.splice(i,1),{...j,[n]:N}});const a=[...W[n]||[]];a.splice(i,1),te(t,s,a)},Ae=t=>{oe(s=>({...s,[t]:!s[t]}))},Be=()=>{const t=`${we}_${ke}`,s=Object.entries(Se).filter(([n,a])=>a).map(([n])=>{const a=parseInt(n.replace("text",""))-1;return ve[a]});if(s.length===0)return;z(n=>{const a=[...n[t]||[]];return{...n,[t]:[...a,...s]}});const i=[...W[t]||[],...s];te(we,ke,i),K(!1)},Te=(t,s)=>{K(!0),Ne(t),Ce(s),ge(""),de([]),oe({}),xe(!1),ne(null)};y.useEffect(()=>{if(!l||l.length===0)return;const t={...b},s=l.map(n=>n.id.toString());Object.keys(t).forEach(n=>{s.includes(n)||delete t[n]}),l.forEach(n=>{const a=n.id.toString();t[a]||(t[a]={})}),JSON.stringify(t)!==JSON.stringify(b)&&S(t)},[l,b]),y.useEffect(()=>{ae({type:"SET_SCREEN_STATE",payload:{currentScreen:x,isProcessing:m,isCompleted:P}})},[x,m,P,ae]),y.useEffect(()=>{const t=document.createElement("style");return t.textContent=ht,document.head.appendChild(t),()=>{document.head.removeChild(t)}},[]),y.useEffect(()=>{const t=s=>{if(Object.values(k).some(i=>i)){const i=s.target,n=!!i.closest(".dropdown-menu"),a=!!i.closest("[data-dropdown]");!n&&!a&&M({})}};return document.addEventListener("mousedown",t),()=>{document.removeEventListener("mousedown",t)}},[k]);const Le=t=>{if(t&&(t.preventDefault(),t.stopPropagation()),x===0){const s={...b};Object.keys(s).forEach(i=>{const n=s[i];Object.keys(n).forEach(a=>{u[a]||delete n[a]})}),S(s)}if(x===1){const s={...b};l.forEach(n=>{const a=n.id.toString(),j=n.widgets||{};Object.values(j).forEach(N=>{const G=N.name;if(u[G]&&(N.type==="customtext"||N.type.toLowerCase().includes("text"))){const ee=`${a}_${G}`,se=W[ee]||[""];s[a]=s[a]||{},s[a][G]=se}})}),S(s);const i=ye(s);A(i.length)}C(null),g(s=>Math.min(s+1,2))},fe=t=>{if(t&&(t.preventDefault(),t.stopPropagation()),C(null),P&&L(!1),x===1){const s=l.map(a=>a.id.toString()),i=Object.keys(b),n={...b};i.forEach(a=>{s.includes(a)||delete n[a]}),S(n)}if(x===2||P){const s={...b};Object.entries(W).forEach(([i,n])=>{if(!n||n.length===0)return;const[a,j]=i.split("_");l.some(N=>N.id.toString()===a)&&(s[a]=s[a]||{},JSON.stringify(s[a][j])!==JSON.stringify(n)&&(s[a][j]=n))}),S(s)}g(s=>Math.max(s-1,0))},Re=(t,s)=>{s&&(s.preventDefault(),s.stopPropagation());const i=u[t];if(c(n=>({...n,[t]:!i})),i){const n={...b};Object.keys(n).forEach(a=>{n[a][t]&&delete n[a][t]}),S(n)}},ze=(t,s,i)=>{i.preventDefault(),i.stopPropagation();const n=`${t}_${s}`;M(a=>{if(a[n]&&typeof a[n]=="object"?a[n].isOpen:!!a[n])return{...a,[n]:!1};{let N=0,G=0;if(i.currentTarget){const ce=i.currentTarget.getBoundingClientRect();N=ce.left,G=ce.bottom}else N=i.clientX,G=i.clientY+20;const ee=window.innerWidth,se=250;return N+se>ee&&(N=ee-se-10),N<0&&(N=10),{...a,[n]:{isOpen:!0,x:N,y:G}}}})},te=(t,s,i)=>{S(n=>{const a={...n};return a[t]||(a[t]={}),a[t][s]=i,a})},Fe=(t,s,i,n)=>{n&&(n.preventDefault(),n.stopPropagation()),S(a=>{const j={...a};j[t]||(j[t]={}),j[t][s]||(j[t][s]=[]);const N=j[t][s];return N.includes(i)?j[t][s]=N.filter(G=>G!==i):j[t][s]=[...N,i],j})},Ve=(t,s,i)=>{const n=`${t}_${s}`;J(a=>({...a,[n]:i}))},Ge=(t,s,i)=>{if(!b[t]){te(t,s,i);return}const n=b[t][s]||[];i.length===n.length?te(t,s,[]):te(t,s,[...i])},Ue=(t,s)=>{s&&(s.preventDefault(),s.stopPropagation()),d(Math.max(1,Math.min(t,Math.ceil(R.length/V))))},me=()=>{ue.current&&(clearTimeout(ue.current),ue.current=null),le.current=null};y.useEffect(()=>()=>{me()},[]);const He=async(t,s)=>{t&&(t.preventDefault(),t.stopPropagation()),me();const i=ye(b),n=i.length;if(n>100){C(`Cannot generate more than 100 images at once (currently: ${n} images)`);return}if(C(null),f(!0),_(0),console.log("Generated parameter combinations:",i),i.length===0){C("No valid parameter combinations found. Please check your parameter selections."),f(!1);return}let a=s||null;if(a===null){const N=ot();N!==null&&(a=N)}if(a===null){C("Please select a SaveImage or PreviewImage node first."),f(!1);return}const j=[];try{const N=Date.now().toString();le.current=N;for(const re of i){const X=await rt(re);X.prompt_id?j.push(X.prompt_id):(console.error("Failed to get prompt_id from response:",X),j.push(""))}const G=Array(i.length).fill(null).map((re,X)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:mt(b,X)}));v(G);const ee=Date.now(),se=5*60*1e3,ce=async()=>{if(le.current!==N){console.log("Another polling session has started, stopping this one");return}if(Date.now()-ee>se){console.log("Timeout reached while waiting for images"),le.current===N&&(f(!1),L(!0),d(1));return}let re=0;for(let X=0;X{s&&(s.preventDefault(),s.stopPropagation()),D(t)},Ke=(t,s)=>{s.preventDefault(),s.stopPropagation(),E(t),U(!0)},Je=t=>{t&&(t.preventDefault(),t.stopPropagation()),U(!1)},Ye=async t=>{if(t&&(t.preventDefault(),t.stopPropagation()),T!==null){console.log(`Applied image ${T+1} with parameters:`,R[T].params);let s=1;if(b){for(const n in b)if(b[n]&&b[n].values)for(const a in b[n].values){const j=b[n].values[a];Array.isArray(j)&&j.length>0&&(s=s*j.length)}}Pe.trackEvent({event_type:"parameter_debug_apply",message_type:"parameter_debug",message_id:tt(),data:{workflow:(await Z.graphToPrompt()).output,selected_params:R[T].params,all_params:b,count:s}});const i=R[T].params;i.nodeParams&&(Object.entries(i.nodeParams).forEach(([n,a])=>{const j=Z.graph._nodes_by_id[n];!j||!j.widgets||Object.entries(a).forEach(([N,G])=>{for(const ee of j.widgets)if(ee.name===N){ee.value=G;break}})}),Z.graph.setDirtyCanvas(!1,!0),H(!0),setTimeout(()=>{H(!1)},3e3))}},ie=(t,s)=>{if(t&&(t.preventDefault(),t.stopPropagation()),x===1&&s!==void 0){const i=[...l],n=i[s];if(i.splice(s,1),n){const a=n.id.toString();S(j=>{const N={...j};return delete N[a],N})}i.length===0?r&&(ae({type:"SET_SCREEN_STATE",payload:null}),be(),r()):ae({type:"SET_SELECTED_NODE",payload:i});return}r?(ae({type:"SET_SCREEN_STATE",payload:null}),be(),r()):be()},be=()=>{g(0),c({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),me(),f(!1),L(!1),_(0),A(12),D(null),v(Array(12).fill(null).map((t,s)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:s%3===0?5:s%3===1?10:15,sampler_name:"euler",cfg:1}}))),S({}),M({}),J({}),I({}),d(1),C(null),H(!1),U(!1),E(""),z({}),K(!1),ge(""),de([]),xe(!1),Ne(""),Ce(""),ne(null),oe({})};return!o||l.length===0?e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center p-8 bg-gray-50 overflow-y-auto",onClick:t=>t.stopPropagation(),children:e.jsxs("div",{className:"max-w-lg p-8 bg-white rounded-lg shadow-sm border border-blue-100 relative",children:[e.jsxs("div",{className:"mb-6 text-center",children:[e.jsx("h3",{className:"text-base font-bold text-blue-800 mb-2",children:"GenLab"}),e.jsx("div",{className:"h-1 w-16 bg-blue-500 mx-auto rounded-full mb-4"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx("div",{className:"bg-blue-100 p-2 rounded-full text-blue-600",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{d:"M5 3a2 2 0 00-2 2v2a2 2 0 002 2h2a2 2 0 002-2V5a2 2 0 00-2-2H5zM5 11a2 2 0 00-2 2v2a2 2 0 002 2h2a2 2 0 002-2v-2a2 2 0 00-2-2H5zM11 5a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V5zM11 13a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z"})})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-800",children:"Batch Test Parameter Pairs"}),e.jsx("p",{className:"text-xs text-gray-600",children:"Select a node to batch test parameter pairs"})]})]}),e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx("div",{className:"bg-indigo-100 p-2 rounded-full text-indigo-600",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-gray-800",children:"How To Use"}),e.jsx("p",{className:"text-xs text-gray-600",children:"Click on any node in your workflow to start the parameter testing process"})]})]}),e.jsx("div",{className:"mt-6 text-center",children:e.jsx("p",{className:"text-xs text-gray-600 mb-3",children:"No node is currently selected"})})]})]})}):P?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(xt,{generatedImages:R,selectedImageIndex:T,handleSelectImage:qe,handleApplySelected:Ye,handlePrevious:fe,handleClose:ie,currentPage:Y,handlePageChange:Ue,imagesPerPage:V,notificationVisible:B,modalVisible:p,modalImageUrl:w,openImageModal:Ke,closeImageModal:Je})}):m?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(dt,{selectedNodes:l,paramTestValues:b,selectedParams:u,totalCount:F,completedCount:$,errorMessage:O,handleClose:ie,setIsProcessing:f,setCurrentScreen:g,cleanupPolling:me})}):x===0?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:t=>t.stopPropagation(),children:e.jsx(lt,{selectedNodes:l,handleParamSelect:Re,selectedParams:u,handleNext:Le,handleClose:ie})}):x===1?e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:t=>t.stopPropagation(),children:[e.jsx(it,{selectedNodes:l,paramTestValues:b,selectedParams:u,updateParamTestValues:te,toggleDropdown:ze,openDropdowns:k,handleTestValueSelect:Fe,searchTerms:q,handleSearch:Ve,handleSelectAll:Ge,handleNext:Le,handlePrevious:fe,handleClose:ie,inputValues:h,setInputValues:I,textInputs:W,handleTextInputChange:_e,handleAddTextInput:De,handleRemoveTextInput:Oe,openAiWritingModal:Te}),e.jsx(ut,{visible:Q,aiWritingModalText:pe,setAiWritingModalText:ge,aiGeneratedTexts:ve,aiSelectedTexts:Se,aiWritingLoading:Ee,aiWritingError:$e,handleAiWriting:We,toggleTextSelection:Ae,addSelectedTexts:Be,onClose:()=>K(!1)})]}):e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4 flex flex-col h-full max-h-[80vh]",onClick:t=>t.stopPropagation(),children:e.jsx(ct,{selectedNodes:l,paramTestValues:b,selectedParams:u,totalCount:F,errorMessage:O,handlePrevious:fe,handleStartGeneration:He,handleClose:ie})})};export{vt as ParameterDebugInterface}; diff --git a/dist/copilot_web/input.js b/dist/copilot_web/input.js index c0ab0cd..956b03c 100644 --- a/dist/copilot_web/input.js +++ b/dist/copilot_web/input.js @@ -1,2 +1,2 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/App-B_5DJBtC.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-D3rPBq8S.js"])))=>i.map(i=>d[i]); -import{j as u}from"./vendor-markdown-Dek94WS0.js";import{a as v,R as p}from"./vendor-react-V04_Axys.js";import{w}from"./message-components-D3rPBq8S.js";const R="modulepreload",b=function(e){return"/"+e},m={},P=function(a,s,S){let d=Promise.resolve();if(s&&s.length>0){document.getElementsByTagName("link");const r=document.querySelector("meta[property=csp-nonce]"),t=r?.nonce||r?.getAttribute("nonce");d=Promise.allSettled(s.map(o=>{if(o=b(o),o in m)return;m[o]=!0;const c=o.endsWith(".css"),h=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${o}"]${h}`))return;const n=document.createElement("link");if(n.rel=c?"stylesheet":R,c||(n.as="script"),n.crossOrigin="",n.href=o,t&&n.setAttribute("nonce",t),document.head.appendChild(n),c)return new Promise((y,E)=>{n.addEventListener("load",y),n.addEventListener("error",()=>E(new Error(`Unable to preload CSS for ${o}`)))})}))}function l(r){const t=new Event("vite:preloadError",{cancelable:!0});if(t.payload=r,window.dispatchEvent(t),!t.defaultPrevented)throw r}return d.then(r=>{for(const t of r||[])t.status==="rejected"&&l(t.reason);return a().catch(l)})};var i={},f=v;i.createRoot=f.createRoot,i.hydrateRoot=f.hydrateRoot;const _=p.lazy(()=>P(async()=>{const{default:e}=await import("./App-B_5DJBtC.js").then(a=>a.A);return{default:e}},__vite__mapDeps([0,1,2,3])).then(({default:e})=>({default:e})));function A(){return new Promise(e=>{if(document.body)return e(document.body);document.addEventListener("DOMContentLoaded",()=>{e(document.body)})})}A().then(()=>w()).then(()=>{const e=document.createElement("div");e.id="comfyui-copilot-plugin",document.body.append(e),i.createRoot(e).render(u.jsx(p.StrictMode,{children:u.jsx(_,{})}))});export{P as _}; +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/App-Bbre7oqJ.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-D3rPBq8S.js"])))=>i.map(i=>d[i]); +import{j as u}from"./vendor-markdown-Dek94WS0.js";import{a as v,R as p}from"./vendor-react-V04_Axys.js";import{w}from"./message-components-D3rPBq8S.js";const R="modulepreload",b=function(e){return"/"+e},m={},P=function(a,s,S){let d=Promise.resolve();if(s&&s.length>0){document.getElementsByTagName("link");const r=document.querySelector("meta[property=csp-nonce]"),t=r?.nonce||r?.getAttribute("nonce");d=Promise.allSettled(s.map(o=>{if(o=b(o),o in m)return;m[o]=!0;const c=o.endsWith(".css"),h=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${o}"]${h}`))return;const n=document.createElement("link");if(n.rel=c?"stylesheet":R,c||(n.as="script"),n.crossOrigin="",n.href=o,t&&n.setAttribute("nonce",t),document.head.appendChild(n),c)return new Promise((y,E)=>{n.addEventListener("load",y),n.addEventListener("error",()=>E(new Error(`Unable to preload CSS for ${o}`)))})}))}function l(r){const t=new Event("vite:preloadError",{cancelable:!0});if(t.payload=r,window.dispatchEvent(t),!t.defaultPrevented)throw r}return d.then(r=>{for(const t of r||[])t.status==="rejected"&&l(t.reason);return a().catch(l)})};var i={},f=v;i.createRoot=f.createRoot,i.hydrateRoot=f.hydrateRoot;const _=p.lazy(()=>P(async()=>{const{default:e}=await import("./App-Bbre7oqJ.js").then(a=>a.A);return{default:e}},__vite__mapDeps([0,1,2,3])).then(({default:e})=>({default:e})));function A(){return new Promise(e=>{if(document.body)return e(document.body);document.addEventListener("DOMContentLoaded",()=>{e(document.body)})})}A().then(()=>w()).then(()=>{const e=document.createElement("div");e.id="comfyui-copilot-plugin",document.body.append(e),i.createRoot(e).render(u.jsx(p.StrictMode,{children:u.jsx(_,{})}))});export{P as _}; diff --git a/dist/copilot_web/workflowChat-m824ZHEN.js b/dist/copilot_web/workflowChat-DVyLdfeb.js similarity index 99% rename from dist/copilot_web/workflowChat-m824ZHEN.js rename to dist/copilot_web/workflowChat-DVyLdfeb.js index 7e5c2da..22044e7 100644 --- a/dist/copilot_web/workflowChat-m824ZHEN.js +++ b/dist/copilot_web/workflowChat-DVyLdfeb.js @@ -1,5 +1,5 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/WorkflowOption-DWEyFLfP.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-D3rPBq8S.js","copilot_web/ParameterDebugInterfaceNew-gJw0-dqN.js","copilot_web/input.js","copilot_web/assets/input-CeTzrUyG.css","copilot_web/App-B_5DJBtC.js"])))=>i.map(i=>d[i]); -import{_ as Dt}from"./input.js";import{j as h,r as yg,b as wg}from"./vendor-markdown-Dek94WS0.js";import{r as I,R as wn,c as Mt}from"./vendor-react-V04_Axys.js";import{f as bg,v as Sg,a as sn,B as Ag,U as Eg,A as Ir,b as Ig,g as Ve,c as Pt,u as is,M as Cg,W as Ot}from"./message-components-D3rPBq8S.js";import{l as Ng}from"./App-B_5DJBtC.js";/** +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/WorkflowOption-DWEyFLfP.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-D3rPBq8S.js","copilot_web/ParameterDebugInterfaceNew-StQHp9mW.js","copilot_web/input.js","copilot_web/assets/input-CeTzrUyG.css","copilot_web/App-Bbre7oqJ.js"])))=>i.map(i=>d[i]); +import{_ as Dt}from"./input.js";import{j as h,r as yg,b as wg}from"./vendor-markdown-Dek94WS0.js";import{r as I,R as wn,c as Mt}from"./vendor-react-V04_Axys.js";import{f as bg,v as Sg,a as sn,B as Ag,U as Eg,A as Ir,b as Ig,g as Ve,c as Pt,u as is,M as Cg,W as Ot}from"./message-components-D3rPBq8S.js";import{l as Ng}from"./App-Bbre7oqJ.js";/** * @license lucide-react v0.475.0 - ISC * * This source code is licensed under the ISC license. @@ -128,4 +128,4 @@ __p += '`),K&&(v+=`' + function print() { __p += __j.call(arguments, '') } `:`; `)+v+`return __p -}`;var U=Oo(function(){return X(u,S+"return "+v).apply(o,a)});if(U.source=v,Hi(U))throw U;return U}function C0(e){return J(e).toLowerCase()}function N0(e){return J(e).toUpperCase()}function L0(e,n,t){if(e=J(e),e&&(t||n===o))return js(e);if(!e||!(n=Fe(n)))return e;var r=en(e),i=en(n),u=zs(r,i),a=Gs(r,i)+1;return Mn(r,u,a).join("")}function R0(e,n,t){if(e=J(e),e&&(t||n===o))return e.slice(0,$s(e)+1);if(!e||!(n=Fe(n)))return e;var r=en(e),i=Gs(r,en(n))+1;return Mn(r,0,i).join("")}function T0(e,n,t){if(e=J(e),e&&(t||n===o))return e.replace(Hr,"");if(!e||!(n=Fe(n)))return e;var r=en(e),i=zs(r,en(n));return Mn(r,i).join("")}function M0(e,n){var t=bn,r=Rr;if(ae(n)){var i="separator"in n?n.separator:i;t="length"in n?P(n.length):t,r="omission"in n?Fe(n.omission):r}e=J(e);var u=e.length;if(et(e)){var a=en(e);u=a.length}if(t>=u)return e;var l=t-nt(r);if(l<1)return r;var c=a?Mn(a,0,l).join(""):e.slice(0,l);if(i===o)return c+r;if(a&&(l+=c.length-l),qi(i)){if(e.slice(l).search(i)){var p,_=c;for(i.global||(i=li(i.source,J(ls.exec(i))+"g")),i.lastIndex=0;p=i.exec(_);)var v=p.index;c=c.slice(0,v===o?l:v)}}else if(e.indexOf(Fe(i),l)!=l){var y=c.lastIndexOf(i);y>-1&&(c=c.slice(0,y))}return c+r}function O0(e){return e=J(e),e&&Go.test(e)?e.replace(us,ol):e}var D0=at(function(e,n,t){return e+(t?" ":"")+n.toUpperCase()}),Xi=Ou("toUpperCase");function Mo(e,n,t){return e=J(e),n=t?o:n,n===o?tl(e)?fl(e):qa(e):e.match(n)||[]}var Oo=j(function(e,n){try{return Ue(e,o,n)}catch(t){return Hi(t)?t:new T(t)}}),P0=_n(function(e,n){return He(n,function(t){t=ln(t),gn(e,t,Ki(e[t],e))}),e});function k0(e){var n=e==null?0:e.length,t=C();return e=n?ue(e,function(r){if(typeof r[1]!="function")throw new qe(M);return[t(r[0]),r[1]]}):[],j(function(r){for(var i=-1;++ifn)return[];var t=ke,r=Ie(e,ke);n=C(n),e-=ke;for(var i=ui(r,n);++t0||n<0)?new G(t):(e<0?t=t.takeRight(-e):e&&(t=t.drop(e)),n!==o&&(n=P(n),t=n<0?t.dropRight(-n):t.take(n-e)),t)},G.prototype.takeRightWhile=function(e){return this.reverse().takeWhile(e).reverse()},G.prototype.toArray=function(){return this.take(ke)},on(G.prototype,function(e,n){var t=/^(?:filter|find|map|reject)|While$/.test(n),r=/^(?:head|last)$/.test(n),i=s[r?"take"+(n=="last"?"Right":""):n],u=r||/^find/.test(n);i&&(s.prototype[n]=function(){var a=this.__wrapped__,l=r?[1]:arguments,c=a instanceof G,p=l[0],_=c||O(a),v=function(z){var K=i.apply(s,In([z],l));return r&&y?K[0]:K};_&&t&&typeof p=="function"&&p.length!=1&&(c=_=!1);var y=this.__chain__,S=!!this.__actions__.length,N=u&&!y,U=c&&!S;if(!u&&_){a=U?a:new G(this);var L=e.apply(a,l);return L.__actions__.push({func:mr,args:[v],thisArg:o}),new Ze(L,y)}return N&&U?e.apply(this,l):(L=this.thru(v),N?r?L.value()[0]:L.value():L)})}),He(["pop","push","shift","sort","splice","unshift"],function(e){var n=Kt[e],t=/^(?:push|sort|unshift)$/.test(e)?"tap":"thru",r=/^(?:pop|shift)$/.test(e);s.prototype[e]=function(){var i=arguments;if(r&&!this.__chain__){var u=this.value();return n.apply(O(u)?u:[],i)}return this[t](function(a){return n.apply(O(a)?a:[],i)})}}),on(G.prototype,function(e,n){var t=s[n];if(t){var r=t.name+"";Q.call(st,r)||(st[r]=[]),st[r].push({name:n,func:t})}}),st[cr(o,le).name]=[{name:"wrapper",func:o}],G.prototype.clone=Ml,G.prototype.reverse=Ol,G.prototype.value=Dl,s.prototype.at=fh,s.prototype.chain=ch,s.prototype.commit=hh,s.prototype.next=dh,s.prototype.plant=ph,s.prototype.reverse=_h,s.prototype.toJSON=s.prototype.valueOf=s.prototype.value=vh,s.prototype.first=s.prototype.head,mt&&(s.prototype[mt]=gh),s},tt=cl();kn?((kn.exports=tt)._=tt,Qr._=tt):we._=tt}).call(Mt)})(Nr,Nr.exports);var Lr=Nr.exports;function ip(m=!0){I.useEffect(()=>{if(!m)return;const w=Lr.debounce(o=>{document.documentElement.style.setProperty("--mouse-x",`${o.clientX}px`),document.documentElement.style.setProperty("--mouse-y",`${o.clientY}px`)},16);return document.addEventListener("mousemove",w),()=>{w.cancel(),document.removeEventListener("mousemove",w)}},[m])}function sp(m={},w=!0){const[o,D]=I.useState(!1),[B,E]=I.useState({width:window.innerWidth/3,height:window.innerHeight,top:0});I.useCallback(Lr.debounce(q=>{o&&E(x=>{const $=window.innerWidth-q.clientX,k=Math.min(Math.max(m.minWidth||300,$),m.maxWidth||window.innerWidth*.8);return{...x,width:k}})},16),[o,m]);const M=I.useCallback(q=>{E(x=>{const $=x.height-q,k=x.top+q;return{...x,height:Math.min(Math.max(m.minHeight||300,$),m.maxHeight||window.innerHeight),top:Math.max(0,k)}})},[m]);return I.useEffect(()=>{if(!w||!o)return;const q=Lr.debounce($=>{E(k=>{const F=window.innerWidth-$.clientX,re=Math.min(Math.max(m.minWidth||300,F),m.maxWidth||window.innerWidth*.8);return{...k,width:re}})},16),x=()=>D(!1);return document.addEventListener("mousemove",q),document.addEventListener("mouseup",x),()=>{q.cancel(),document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",x)}},[o,m,w]),{isResizing:o,setIsResizing:D,dimensions:B,handleHeightResize:M}}function up(m=!0){const{state:w,dispatch:o}=is(),{activeTab:D,screenState:B}=w;I.useEffect(()=>{if(!m)return;const E=M=>{const q=D==="parameter-debug",x=D==="chat",$=!B||B.currentScreen===0;if(x||$&&q){const k=sn.canvas.selected_nodes;if(Object.keys(k??{}).length){const F=Object.values(k);o({type:"SET_SELECTED_NODE",payload:F})}else o({type:"SET_SELECTED_NODE",payload:null})}};return document.addEventListener("click",E),()=>{document.removeEventListener("click",E)}},[o,m,D,B])}const op=({message:m,onClose:w})=>m?h.jsxs("div",{className:"bg-gradient-to-r from-amber-50 to-amber-100 border-b border-amber-200 px-5 py-2 mt-2 relative shadow-sm",children:[h.jsxs("div",{className:"flex items-center",children:[h.jsx("div",{className:"flex-shrink-0 mr-2",children:h.jsx("svg",{className:"w-3.5 h-3.5 text-amber-600",fill:"currentColor",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",children:h.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})})}),h.jsx("div",{className:"text-amber-800 font-medium leading-relaxed pr-6 markdown-content",style:{fontSize:"11px"},children:h.jsx(Cg,{rehypePlugins:[[yg,{target:"_blank",rel:["noopener","noreferrer"]}]],remarkPlugins:[wg],className:"prose !text-[11px] prose-a:text-amber-700 prose-a:underline prose-a:font-medium hover:prose-a:text-amber-800",components:{a:({node:o,...D})=>h.jsx("a",{...D,className:"text-amber-700 underline hover:text-amber-800 transition-colors",style:{fontSize:"11px"}}),p:({children:o})=>h.jsx("span",{className:"inline",style:{fontSize:"11px"},children:o}),span:({children:o})=>h.jsx("span",{style:{fontSize:"11px"},children:o}),li:({children:o})=>h.jsx("li",{style:{fontSize:"11px"},children:o}),ul:({children:o})=>h.jsx("ul",{style:{fontSize:"11px"},children:o}),ol:({children:o})=>h.jsx("ol",{style:{fontSize:"11px"},children:o})},children:m})})]}),h.jsx("button",{onClick:w,className:"absolute right-2 top-1/2 -translate-y-1/2 text-amber-500 hover:text-amber-700 transition-colors p-1 rounded-full hover:bg-amber-200/50","aria-label":"Close announcement",children:h.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:h.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}):null,ap=()=>{const{state:m,dispatch:w}=is(),{selectedNode:o,screenState:D}=m,B=o||[],E=wn.lazy(()=>Dt(()=>import("./ParameterDebugInterfaceNew-gJw0-dqN.js"),__vite__mapDeps([4,1,2,3,5,6,7])).then(q=>({default:q.ParameterDebugInterface}))),M=()=>{w({type:"SET_SELECTED_NODE",payload:null}),w({type:"SET_SCREEN_STATE",payload:null})};return h.jsx("div",{className:"flex-1 flex flex-col overflow-y-auto",children:h.jsx(wn.Suspense,{fallback:h.jsx("div",{children:"Loading..."}),children:h.jsx(E,{selectedNodes:B,visible:!0,onClose:M})})})},Wo=({active:m,onClick:w,children:o})=>h.jsx("button",{onClick:w,className:`px-4 py-2 font-medium text-sm transition-colors duration-200 ${m?"text-blue-600 border-b-2 border-blue-600":"text-gray-600 hover:text-blue-500 hover:border-b-2 hover:border-blue-300"}`,children:o});function lp({onClose:m,visible:w=!0,triggerUsage:o=!1,onUsageTriggered:D}){const{state:B,dispatch:E}=is(),{messages:M,installedNodes:q,loading:x,sessionId:$,selectedNode:k,activeTab:F}=B,re=I.useRef(null),[ie,pe]=I.useState(""),[R,W]=I.useState(""),[le,he]=I.useState(window.innerWidth/3),[oe,Pe]=I.useState(!1),[fe,H]=I.useState([]),[Z,Se]=I.useState("gpt-4o-mini");I.useState(window.innerHeight),I.useState(0);const[_e,bn]=I.useState(""),[Rr,kt]=I.useState(!1);ip(w&&F==="chat"),up(w);const{isResizing:ss,setIsResizing:Wt,dimensions:dt,handleHeightResize:Tr}=sp({minWidth:300,maxWidth:window.innerWidth*.8,minHeight:300,maxHeight:window.innerHeight},w);I.useEffect(()=>{re.current&&(re.current.scrollTop=re.current.scrollHeight)},[M]),I.useEffect(()=>{if(F!=="chat")return;(async()=>{const Y=await rp();console.log("[WorkflowChat] Received installed nodes:",Y.length),E({type:"SET_INSTALLED_NODES",payload:Y})})()},[F]);const $n=async A=>{try{const Y=await Ot.fetchMessages(A);E({type:"SET_MESSAGES",payload:Y})}catch(Y){console.error("Error fetching messages:",Y)}};I.useEffect(()=>{if(F!=="chat")return;let A=localStorage.getItem("sessionId");A?(E({type:"SET_SESSION_ID",payload:A}),$n(A)):(A=Ve(),E({type:"SET_SESSION_ID",payload:A}),localStorage.setItem("sessionId",A))},[F]);const fn=wn.useCallback(A=>{if(!oe)return;const Y=window.innerWidth-A.clientX,ee=Math.min(Math.max(300,Y),window.innerWidth*.8);he(ee)},[oe]),Hn=wn.useMemo(()=>Lr.debounce(fn,16),[fn]);I.useEffect(()=>(oe&&(document.addEventListener("mousemove",Hn),document.addEventListener("mouseup",An)),()=>{document.removeEventListener("mousemove",Hn),document.removeEventListener("mouseup",An),Hn.cancel()}),[oe,Hn]);const qn=A=>{pe(A.target.value)},ke=async()=>{if(E({type:"SET_LOADING",payload:!0}),ie.trim()===""&&!k||!$)return;W(ie);const A=Ve(),Y={id:Ve(),role:"user",content:ie,trace_id:A};E({type:"ADD_MESSAGE",payload:Y}),pe("");try{const ee={type:"model_select",data:[Z]};let Ae=Ve(),un=!0;for await(const Ee of Ot.streamInvokeServer($,ie,fe.map(V=>V.file),null,ee,A)){const V={id:Ae,role:"ai",content:JSON.stringify(Ee),format:Ee.format,finished:Ee.finished,name:"Assistant"};if(un)E({type:"ADD_MESSAGE",payload:V}),un=!1;else{E({type:"UPDATE_MESSAGE",payload:V});const ve=B.messages.map(Ke=>Ke.id===V.id&&!Ke.finished?V:Ke);Zn(ve)}Ee.finished&&E({type:"SET_LOADING",payload:!1})}}catch(ee){console.error("Error sending message:",ee),E({type:"SET_LOADING",payload:!1})}finally{H([])}},Mr=async A=>{if(!$)return;E({type:"SET_LOADING",payload:!0}),W(A);const Y=Ve(),ee={id:Ve(),role:"user",content:A,trace_id:Y};E({type:"ADD_MESSAGE",payload:ee});try{const Ae={type:"model_select",data:[Z]};let un=Ve(),Ee=!0;for await(const V of Ot.streamInvokeServer($,A,fe.map(ve=>ve.file),null,Ae,Y)){const ve={id:un,role:"ai",content:JSON.stringify(V),format:V.format,finished:V.finished,name:"Assistant"};if(Ee)E({type:"ADD_MESSAGE",payload:ve}),Ee=!1;else{E({type:"UPDATE_MESSAGE",payload:ve});const Ke=B.messages.map(cn=>cn.id===ve.id&&!cn.finished?ve:cn);Zn(Ke)}V.finished&&E({type:"SET_LOADING",payload:!1})}}catch(Ae){console.error("Error sending message:",Ae),E({type:"SET_LOADING",payload:!1})}finally{H([])}},Or=A=>{A.metaKey&&A.key==="Enter"&&ke()},Dr=()=>{E({type:"CLEAR_MESSAGES"});const A=B.sessionId;A&&localStorage.removeItem(`messages_${A}`),localStorage.removeItem("sessionId");const Y=Ve();E({type:"SET_SESSION_ID",payload:Y}),localStorage.setItem("sessionId",Y)},Sn=A=>{pe(A)},Dn=async(A,Y)=>{if(!$||!k)return;E({type:"SET_LOADING",payload:!0});const ee=Ve(),Ae={id:Ve(),role:"user",content:k.comfyClass||k.type,trace_id:ee};E({type:"ADD_MESSAGE",payload:Ae});try{let un=Ve(),Ee=!0;for await(const V of Ot.streamInvokeServer($,k.comfyClass||k.type,[],A,Y,ee)){const ve={id:un,role:"ai",content:JSON.stringify(V),format:V.format,finished:V.finished,name:"Assistant"};if(A&&A!==""&&(ve.metadata={intent:A}),Ee)E({type:"ADD_MESSAGE",payload:ve}),Ee=!1;else{E({type:"UPDATE_MESSAGE",payload:ve});const Ke=B.messages.map(cn=>cn.id===ve.id&&!cn.finished?ve:cn);Zn(Ke)}V.finished&&E({type:"SET_LOADING",payload:!1})}}catch(un){console.error("Error sending message:",un),E({type:"SET_LOADING",payload:!1})}},Zn=A=>{B.sessionId&&localStorage.setItem(`messages_${B.sessionId}`,JSON.stringify(A))},Pn=A=>{console.log("[WorkflowChat] Adding new message:",A);const Y=[...B.messages,A];E({type:"ADD_MESSAGE",payload:A}),Zn(Y)},An=()=>{Pe(!1)},Pr=A=>{const Y=Array.from(A).map(ee=>({id:Math.random().toString(36).substr(2,9),file:ee,preview:URL.createObjectURL(ee)}));H(ee=>[...ee,...Y])},Yn=A=>{H(Y=>Y.filter(Ae=>Ae.id!==A))};wn.useEffect(()=>()=>{fe.forEach(A=>URL.revokeObjectURL(A.preview))},[fe]),I.useEffect(()=>{o&&D&&F==="chat"&&(Dn("node_explain"),D())},[o,F]),I.useEffect(()=>{if(!w||F!=="chat")return;(async()=>{try{const Y=new Date().toDateString();if(localStorage.getItem("announcementLastShownDate")!==Y){const Ae=await Ot.fetchAnnouncement();Ae&&Ae.trim()!==""&&(bn(Ae),kt(!0),localStorage.setItem("announcementLastShownDate",Y))}}catch(Y){console.error("Error fetching announcement:",Y)}})()},[w,F]);const Xn=()=>{kt(!1)},gt=A=>{E({type:"SET_ACTIVE_TAB",payload:A})},We=wn.useMemo(()=>h.jsx(ap,{}),[]);return h.jsxs("div",{className:"fixed right-0 shadow-lg bg-white duration-200 ease-out",style:{display:w?"block":"none",width:`${dt.width}px`,height:`${dt.height}px`,top:`${dt.top}px`},children:[h.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-1 cursor-ew-resize hover:bg-gray-300",onMouseDown:A=>{Wt(!0),A.preventDefault()}}),h.jsxs("div",{className:"flex h-full flex-col",children:[h.jsx(Kg,{onClose:m,onClear:Dr,hasMessages:M.length>0,onHeightResize:Tr,title:"ComfyUI-Copilot"}),h.jsxs("div",{className:"flex border-b border-gray-200 mt-2",children:[h.jsx(Wo,{active:F==="chat",onClick:()=>gt("chat"),children:"Chat"}),h.jsx(Wo,{active:F==="parameter-debug",onClick:()=>gt("parameter-debug"),children:"GenLab"})]}),Rr&&_e&&F==="chat"&&h.jsx(op,{message:_e,onClose:Xn}),h.jsx("div",{className:"flex-1 overflow-y-auto p-4 scroll-smooth",style:{display:F==="chat"?"block":"none"},ref:re,children:h.jsx(np,{messages:M,latestInput:R,onOptionClick:Sn,installedNodes:q,onAddMessage:Pn,loading:x})}),h.jsxs("div",{className:"border-t px-4 py-3 border-gray-200 bg-white sticky bottom-0",style:{display:F==="chat"?"block":"none"},children:[k&&h.jsx(Zg,{nodeInfo:k,onSendWithIntent:Dn,loading:x,onSendWithContent:Mr}),h.jsx(Hg,{input:ie,loading:x,onChange:qn,onSend:ke,onKeyPress:Or,onUploadImages:Pr,uploadedImages:fe,onRemoveImage:Yn,selectedModel:Z,onModelChange:Se})]}),h.jsx("div",{className:"flex-1 flex flex-col",style:{display:F==="parameter-debug"?"flex":"none"},children:We})]})]})}const xp=Object.freeze(Object.defineProperty({__proto__:null,default:lp},Symbol.toStringTag,{value:"Module"}));export{mp as g,vp as i,_p as m,pp as r,xp as w}; +}`;var U=Oo(function(){return X(u,S+"return "+v).apply(o,a)});if(U.source=v,Hi(U))throw U;return U}function C0(e){return J(e).toLowerCase()}function N0(e){return J(e).toUpperCase()}function L0(e,n,t){if(e=J(e),e&&(t||n===o))return js(e);if(!e||!(n=Fe(n)))return e;var r=en(e),i=en(n),u=zs(r,i),a=Gs(r,i)+1;return Mn(r,u,a).join("")}function R0(e,n,t){if(e=J(e),e&&(t||n===o))return e.slice(0,$s(e)+1);if(!e||!(n=Fe(n)))return e;var r=en(e),i=Gs(r,en(n))+1;return Mn(r,0,i).join("")}function T0(e,n,t){if(e=J(e),e&&(t||n===o))return e.replace(Hr,"");if(!e||!(n=Fe(n)))return e;var r=en(e),i=zs(r,en(n));return Mn(r,i).join("")}function M0(e,n){var t=bn,r=Rr;if(ae(n)){var i="separator"in n?n.separator:i;t="length"in n?P(n.length):t,r="omission"in n?Fe(n.omission):r}e=J(e);var u=e.length;if(et(e)){var a=en(e);u=a.length}if(t>=u)return e;var l=t-nt(r);if(l<1)return r;var c=a?Mn(a,0,l).join(""):e.slice(0,l);if(i===o)return c+r;if(a&&(l+=c.length-l),qi(i)){if(e.slice(l).search(i)){var p,_=c;for(i.global||(i=li(i.source,J(ls.exec(i))+"g")),i.lastIndex=0;p=i.exec(_);)var v=p.index;c=c.slice(0,v===o?l:v)}}else if(e.indexOf(Fe(i),l)!=l){var y=c.lastIndexOf(i);y>-1&&(c=c.slice(0,y))}return c+r}function O0(e){return e=J(e),e&&Go.test(e)?e.replace(us,ol):e}var D0=at(function(e,n,t){return e+(t?" ":"")+n.toUpperCase()}),Xi=Ou("toUpperCase");function Mo(e,n,t){return e=J(e),n=t?o:n,n===o?tl(e)?fl(e):qa(e):e.match(n)||[]}var Oo=j(function(e,n){try{return Ue(e,o,n)}catch(t){return Hi(t)?t:new T(t)}}),P0=_n(function(e,n){return He(n,function(t){t=ln(t),gn(e,t,Ki(e[t],e))}),e});function k0(e){var n=e==null?0:e.length,t=C();return e=n?ue(e,function(r){if(typeof r[1]!="function")throw new qe(M);return[t(r[0]),r[1]]}):[],j(function(r){for(var i=-1;++ifn)return[];var t=ke,r=Ie(e,ke);n=C(n),e-=ke;for(var i=ui(r,n);++t0||n<0)?new G(t):(e<0?t=t.takeRight(-e):e&&(t=t.drop(e)),n!==o&&(n=P(n),t=n<0?t.dropRight(-n):t.take(n-e)),t)},G.prototype.takeRightWhile=function(e){return this.reverse().takeWhile(e).reverse()},G.prototype.toArray=function(){return this.take(ke)},on(G.prototype,function(e,n){var t=/^(?:filter|find|map|reject)|While$/.test(n),r=/^(?:head|last)$/.test(n),i=s[r?"take"+(n=="last"?"Right":""):n],u=r||/^find/.test(n);i&&(s.prototype[n]=function(){var a=this.__wrapped__,l=r?[1]:arguments,c=a instanceof G,p=l[0],_=c||O(a),v=function(z){var K=i.apply(s,In([z],l));return r&&y?K[0]:K};_&&t&&typeof p=="function"&&p.length!=1&&(c=_=!1);var y=this.__chain__,S=!!this.__actions__.length,N=u&&!y,U=c&&!S;if(!u&&_){a=U?a:new G(this);var L=e.apply(a,l);return L.__actions__.push({func:mr,args:[v],thisArg:o}),new Ze(L,y)}return N&&U?e.apply(this,l):(L=this.thru(v),N?r?L.value()[0]:L.value():L)})}),He(["pop","push","shift","sort","splice","unshift"],function(e){var n=Kt[e],t=/^(?:push|sort|unshift)$/.test(e)?"tap":"thru",r=/^(?:pop|shift)$/.test(e);s.prototype[e]=function(){var i=arguments;if(r&&!this.__chain__){var u=this.value();return n.apply(O(u)?u:[],i)}return this[t](function(a){return n.apply(O(a)?a:[],i)})}}),on(G.prototype,function(e,n){var t=s[n];if(t){var r=t.name+"";Q.call(st,r)||(st[r]=[]),st[r].push({name:n,func:t})}}),st[cr(o,le).name]=[{name:"wrapper",func:o}],G.prototype.clone=Ml,G.prototype.reverse=Ol,G.prototype.value=Dl,s.prototype.at=fh,s.prototype.chain=ch,s.prototype.commit=hh,s.prototype.next=dh,s.prototype.plant=ph,s.prototype.reverse=_h,s.prototype.toJSON=s.prototype.valueOf=s.prototype.value=vh,s.prototype.first=s.prototype.head,mt&&(s.prototype[mt]=gh),s},tt=cl();kn?((kn.exports=tt)._=tt,Qr._=tt):we._=tt}).call(Mt)})(Nr,Nr.exports);var Lr=Nr.exports;function ip(m=!0){I.useEffect(()=>{if(!m)return;const w=Lr.debounce(o=>{document.documentElement.style.setProperty("--mouse-x",`${o.clientX}px`),document.documentElement.style.setProperty("--mouse-y",`${o.clientY}px`)},16);return document.addEventListener("mousemove",w),()=>{w.cancel(),document.removeEventListener("mousemove",w)}},[m])}function sp(m={},w=!0){const[o,D]=I.useState(!1),[B,E]=I.useState({width:window.innerWidth/3,height:window.innerHeight,top:0});I.useCallback(Lr.debounce(q=>{o&&E(x=>{const $=window.innerWidth-q.clientX,k=Math.min(Math.max(m.minWidth||300,$),m.maxWidth||window.innerWidth*.8);return{...x,width:k}})},16),[o,m]);const M=I.useCallback(q=>{E(x=>{const $=x.height-q,k=x.top+q;return{...x,height:Math.min(Math.max(m.minHeight||300,$),m.maxHeight||window.innerHeight),top:Math.max(0,k)}})},[m]);return I.useEffect(()=>{if(!w||!o)return;const q=Lr.debounce($=>{E(k=>{const F=window.innerWidth-$.clientX,re=Math.min(Math.max(m.minWidth||300,F),m.maxWidth||window.innerWidth*.8);return{...k,width:re}})},16),x=()=>D(!1);return document.addEventListener("mousemove",q),document.addEventListener("mouseup",x),()=>{q.cancel(),document.removeEventListener("mousemove",q),document.removeEventListener("mouseup",x)}},[o,m,w]),{isResizing:o,setIsResizing:D,dimensions:B,handleHeightResize:M}}function up(m=!0){const{state:w,dispatch:o}=is(),{activeTab:D,screenState:B}=w;I.useEffect(()=>{if(!m)return;const E=M=>{const q=D==="parameter-debug",x=D==="chat",$=!B||B.currentScreen===0;if(x||$&&q){const k=sn.canvas.selected_nodes;if(Object.keys(k??{}).length){const F=Object.values(k);o({type:"SET_SELECTED_NODE",payload:F})}else o({type:"SET_SELECTED_NODE",payload:null})}};return document.addEventListener("click",E),()=>{document.removeEventListener("click",E)}},[o,m,D,B])}const op=({message:m,onClose:w})=>m?h.jsxs("div",{className:"bg-gradient-to-r from-amber-50 to-amber-100 border-b border-amber-200 px-5 py-2 mt-2 relative shadow-sm",children:[h.jsxs("div",{className:"flex items-center",children:[h.jsx("div",{className:"flex-shrink-0 mr-2",children:h.jsx("svg",{className:"w-3.5 h-3.5 text-amber-600",fill:"currentColor",viewBox:"0 0 20 20",xmlns:"http://www.w3.org/2000/svg",children:h.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})})}),h.jsx("div",{className:"text-amber-800 font-medium leading-relaxed pr-6 markdown-content",style:{fontSize:"11px"},children:h.jsx(Cg,{rehypePlugins:[[yg,{target:"_blank",rel:["noopener","noreferrer"]}]],remarkPlugins:[wg],className:"prose !text-[11px] prose-a:text-amber-700 prose-a:underline prose-a:font-medium hover:prose-a:text-amber-800",components:{a:({node:o,...D})=>h.jsx("a",{...D,className:"text-amber-700 underline hover:text-amber-800 transition-colors",style:{fontSize:"11px"}}),p:({children:o})=>h.jsx("span",{className:"inline",style:{fontSize:"11px"},children:o}),span:({children:o})=>h.jsx("span",{style:{fontSize:"11px"},children:o}),li:({children:o})=>h.jsx("li",{style:{fontSize:"11px"},children:o}),ul:({children:o})=>h.jsx("ul",{style:{fontSize:"11px"},children:o}),ol:({children:o})=>h.jsx("ol",{style:{fontSize:"11px"},children:o})},children:m})})]}),h.jsx("button",{onClick:w,className:"absolute right-2 top-1/2 -translate-y-1/2 text-amber-500 hover:text-amber-700 transition-colors p-1 rounded-full hover:bg-amber-200/50","aria-label":"Close announcement",children:h.jsx("svg",{className:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:h.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}):null,ap=()=>{const{state:m,dispatch:w}=is(),{selectedNode:o,screenState:D}=m,B=o||[],E=wn.lazy(()=>Dt(()=>import("./ParameterDebugInterfaceNew-StQHp9mW.js"),__vite__mapDeps([4,1,2,3,5,6,7])).then(q=>({default:q.ParameterDebugInterface}))),M=()=>{w({type:"SET_SELECTED_NODE",payload:null}),w({type:"SET_SCREEN_STATE",payload:null})};return h.jsx("div",{className:"flex-1 flex flex-col overflow-y-auto",children:h.jsx(wn.Suspense,{fallback:h.jsx("div",{children:"Loading..."}),children:h.jsx(E,{selectedNodes:B,visible:!0,onClose:M})})})},Wo=({active:m,onClick:w,children:o})=>h.jsx("button",{onClick:w,className:`px-4 py-2 font-medium text-sm transition-colors duration-200 ${m?"text-blue-600 border-b-2 border-blue-600":"text-gray-600 hover:text-blue-500 hover:border-b-2 hover:border-blue-300"}`,children:o});function lp({onClose:m,visible:w=!0,triggerUsage:o=!1,onUsageTriggered:D}){const{state:B,dispatch:E}=is(),{messages:M,installedNodes:q,loading:x,sessionId:$,selectedNode:k,activeTab:F}=B,re=I.useRef(null),[ie,pe]=I.useState(""),[R,W]=I.useState(""),[le,he]=I.useState(window.innerWidth/3),[oe,Pe]=I.useState(!1),[fe,H]=I.useState([]),[Z,Se]=I.useState("gpt-4o-mini");I.useState(window.innerHeight),I.useState(0);const[_e,bn]=I.useState(""),[Rr,kt]=I.useState(!1);ip(w&&F==="chat"),up(w);const{isResizing:ss,setIsResizing:Wt,dimensions:dt,handleHeightResize:Tr}=sp({minWidth:300,maxWidth:window.innerWidth*.8,minHeight:300,maxHeight:window.innerHeight},w);I.useEffect(()=>{re.current&&(re.current.scrollTop=re.current.scrollHeight)},[M]),I.useEffect(()=>{if(F!=="chat")return;(async()=>{const Y=await rp();console.log("[WorkflowChat] Received installed nodes:",Y.length),E({type:"SET_INSTALLED_NODES",payload:Y})})()},[F]);const $n=async A=>{try{const Y=await Ot.fetchMessages(A);E({type:"SET_MESSAGES",payload:Y})}catch(Y){console.error("Error fetching messages:",Y)}};I.useEffect(()=>{if(F!=="chat")return;let A=localStorage.getItem("sessionId");A?(E({type:"SET_SESSION_ID",payload:A}),$n(A)):(A=Ve(),E({type:"SET_SESSION_ID",payload:A}),localStorage.setItem("sessionId",A))},[F]);const fn=wn.useCallback(A=>{if(!oe)return;const Y=window.innerWidth-A.clientX,ee=Math.min(Math.max(300,Y),window.innerWidth*.8);he(ee)},[oe]),Hn=wn.useMemo(()=>Lr.debounce(fn,16),[fn]);I.useEffect(()=>(oe&&(document.addEventListener("mousemove",Hn),document.addEventListener("mouseup",An)),()=>{document.removeEventListener("mousemove",Hn),document.removeEventListener("mouseup",An),Hn.cancel()}),[oe,Hn]);const qn=A=>{pe(A.target.value)},ke=async()=>{if(E({type:"SET_LOADING",payload:!0}),ie.trim()===""&&!k||!$)return;W(ie);const A=Ve(),Y={id:Ve(),role:"user",content:ie,trace_id:A};E({type:"ADD_MESSAGE",payload:Y}),pe("");try{const ee={type:"model_select",data:[Z]};let Ae=Ve(),un=!0;for await(const Ee of Ot.streamInvokeServer($,ie,fe.map(V=>V.file),null,ee,A)){const V={id:Ae,role:"ai",content:JSON.stringify(Ee),format:Ee.format,finished:Ee.finished,name:"Assistant"};if(un)E({type:"ADD_MESSAGE",payload:V}),un=!1;else{E({type:"UPDATE_MESSAGE",payload:V});const ve=B.messages.map(Ke=>Ke.id===V.id&&!Ke.finished?V:Ke);Zn(ve)}Ee.finished&&E({type:"SET_LOADING",payload:!1})}}catch(ee){console.error("Error sending message:",ee),E({type:"SET_LOADING",payload:!1})}finally{H([])}},Mr=async A=>{if(!$)return;E({type:"SET_LOADING",payload:!0}),W(A);const Y=Ve(),ee={id:Ve(),role:"user",content:A,trace_id:Y};E({type:"ADD_MESSAGE",payload:ee});try{const Ae={type:"model_select",data:[Z]};let un=Ve(),Ee=!0;for await(const V of Ot.streamInvokeServer($,A,fe.map(ve=>ve.file),null,Ae,Y)){const ve={id:un,role:"ai",content:JSON.stringify(V),format:V.format,finished:V.finished,name:"Assistant"};if(Ee)E({type:"ADD_MESSAGE",payload:ve}),Ee=!1;else{E({type:"UPDATE_MESSAGE",payload:ve});const Ke=B.messages.map(cn=>cn.id===ve.id&&!cn.finished?ve:cn);Zn(Ke)}V.finished&&E({type:"SET_LOADING",payload:!1})}}catch(Ae){console.error("Error sending message:",Ae),E({type:"SET_LOADING",payload:!1})}finally{H([])}},Or=A=>{A.metaKey&&A.key==="Enter"&&ke()},Dr=()=>{E({type:"CLEAR_MESSAGES"});const A=B.sessionId;A&&localStorage.removeItem(`messages_${A}`),localStorage.removeItem("sessionId");const Y=Ve();E({type:"SET_SESSION_ID",payload:Y}),localStorage.setItem("sessionId",Y)},Sn=A=>{pe(A)},Dn=async(A,Y)=>{if(!$||!k)return;E({type:"SET_LOADING",payload:!0});const ee=Ve(),Ae={id:Ve(),role:"user",content:k.comfyClass||k.type,trace_id:ee};E({type:"ADD_MESSAGE",payload:Ae});try{let un=Ve(),Ee=!0;for await(const V of Ot.streamInvokeServer($,k.comfyClass||k.type,[],A,Y,ee)){const ve={id:un,role:"ai",content:JSON.stringify(V),format:V.format,finished:V.finished,name:"Assistant"};if(A&&A!==""&&(ve.metadata={intent:A}),Ee)E({type:"ADD_MESSAGE",payload:ve}),Ee=!1;else{E({type:"UPDATE_MESSAGE",payload:ve});const Ke=B.messages.map(cn=>cn.id===ve.id&&!cn.finished?ve:cn);Zn(Ke)}V.finished&&E({type:"SET_LOADING",payload:!1})}}catch(un){console.error("Error sending message:",un),E({type:"SET_LOADING",payload:!1})}},Zn=A=>{B.sessionId&&localStorage.setItem(`messages_${B.sessionId}`,JSON.stringify(A))},Pn=A=>{console.log("[WorkflowChat] Adding new message:",A);const Y=[...B.messages,A];E({type:"ADD_MESSAGE",payload:A}),Zn(Y)},An=()=>{Pe(!1)},Pr=A=>{const Y=Array.from(A).map(ee=>({id:Math.random().toString(36).substr(2,9),file:ee,preview:URL.createObjectURL(ee)}));H(ee=>[...ee,...Y])},Yn=A=>{H(Y=>Y.filter(Ae=>Ae.id!==A))};wn.useEffect(()=>()=>{fe.forEach(A=>URL.revokeObjectURL(A.preview))},[fe]),I.useEffect(()=>{o&&D&&F==="chat"&&(Dn("node_explain"),D())},[o,F]),I.useEffect(()=>{if(!w||F!=="chat")return;(async()=>{try{const Y=new Date().toDateString();if(localStorage.getItem("announcementLastShownDate")!==Y){const Ae=await Ot.fetchAnnouncement();Ae&&Ae.trim()!==""&&(bn(Ae),kt(!0),localStorage.setItem("announcementLastShownDate",Y))}}catch(Y){console.error("Error fetching announcement:",Y)}})()},[w,F]);const Xn=()=>{kt(!1)},gt=A=>{E({type:"SET_ACTIVE_TAB",payload:A})},We=wn.useMemo(()=>h.jsx(ap,{}),[]);return h.jsxs("div",{className:"fixed right-0 shadow-lg bg-white duration-200 ease-out",style:{display:w?"block":"none",width:`${dt.width}px`,height:`${dt.height}px`,top:`${dt.top}px`},children:[h.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-1 cursor-ew-resize hover:bg-gray-300",onMouseDown:A=>{Wt(!0),A.preventDefault()}}),h.jsxs("div",{className:"flex h-full flex-col",children:[h.jsx(Kg,{onClose:m,onClear:Dr,hasMessages:M.length>0,onHeightResize:Tr,title:"ComfyUI-Copilot"}),h.jsxs("div",{className:"flex border-b border-gray-200 mt-2",children:[h.jsx(Wo,{active:F==="chat",onClick:()=>gt("chat"),children:"Chat"}),h.jsx(Wo,{active:F==="parameter-debug",onClick:()=>gt("parameter-debug"),children:"GenLab"})]}),Rr&&_e&&F==="chat"&&h.jsx(op,{message:_e,onClose:Xn}),h.jsx("div",{className:"flex-1 overflow-y-auto p-4 scroll-smooth",style:{display:F==="chat"?"block":"none"},ref:re,children:h.jsx(np,{messages:M,latestInput:R,onOptionClick:Sn,installedNodes:q,onAddMessage:Pn,loading:x})}),h.jsxs("div",{className:"border-t px-4 py-3 border-gray-200 bg-white sticky bottom-0",style:{display:F==="chat"?"block":"none"},children:[k&&h.jsx(Zg,{nodeInfo:k,onSendWithIntent:Dn,loading:x,onSendWithContent:Mr}),h.jsx(Hg,{input:ie,loading:x,onChange:qn,onSend:ke,onKeyPress:Or,onUploadImages:Pr,uploadedImages:fe,onRemoveImage:Yn,selectedModel:Z,onModelChange:Se})]}),h.jsx("div",{className:"flex-1 flex flex-col",style:{display:F==="parameter-debug"?"flex":"none"},children:We})]})]})}const xp=Object.freeze(Object.defineProperty({__proto__:null,default:lp},Symbol.toStringTag,{value:"Module"}));export{mp as g,vp as i,_p as m,pp as r,xp as w}; diff --git a/ui/src/components/debug/ParameterDebugInterfaceNew.tsx b/ui/src/components/debug/ParameterDebugInterfaceNew.tsx index 624ddcb..8c1dcf7 100644 --- a/ui/src/components/debug/ParameterDebugInterfaceNew.tsx +++ b/ui/src/components/debug/ParameterDebugInterfaceNew.tsx @@ -854,6 +854,21 @@ export const ParameterDebugInterface: React.FC = ( console.log(`Applied image ${selectedImageIndex + 1} with parameters:`, generatedImages[selectedImageIndex].params); // 发送埋点事件 + let count_temp = 1; + // Calculate total parameter combinations + if (paramTestValues) { + for (const nodeId in paramTestValues) { + if (paramTestValues[nodeId] && paramTestValues[nodeId].values) { + for (const paramName in paramTestValues[nodeId].values) { + const paramOptions = paramTestValues[nodeId].values[paramName]; + if (Array.isArray(paramOptions) && paramOptions.length > 0) { + count_temp = count_temp * paramOptions.length; + } + } + } + } + } + WorkflowChatAPI.trackEvent({ event_type: 'parameter_debug_apply', message_type: 'parameter_debug', @@ -862,7 +877,7 @@ export const ParameterDebugInterface: React.FC = ( workflow: (await app.graphToPrompt()).output, selected_params: generatedImages[selectedImageIndex].params, all_params: paramTestValues, - count: Object.keys(paramTestValues).length + count: count_temp } });