diff --git a/dist/copilot_web/App-BKUkXtap.js b/dist/copilot_web/App-CCFLr34u.js similarity index 95% rename from dist/copilot_web/App-BKUkXtap.js rename to dist/copilot_web/App-CCFLr34u.js index 2c6895d..f7c1a41 100644 --- a/dist/copilot_web/App-BKUkXtap.js +++ b/dist/copilot_web/App-CCFLr34u.js @@ -1,6 +1,6 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/workflowChat-QHF8s17w.js","copilot_web/input.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-B3k4U96-.js","copilot_web/assets/input-CbVoR7-h.css"].map(path => { +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/workflowChat-DFouB6P4.js","copilot_web/input.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-B3k4U96-.js","copilot_web/assets/input-CbVoR7-h.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-B3k4U96-.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-QHF8s17w.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-B3k4U96-.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-DFouB6P4.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--d3dp9od.js b/dist/copilot_web/ParameterDebugInterfaceNew--d3dp9od.js new file mode 100644 index 0000000..b32f231 --- /dev/null +++ b/dist/copilot_web/ParameterDebugInterfaceNew--d3dp9od.js @@ -0,0 +1,29 @@ +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-DFouB6P4.js";import{a as Z,u as Ie,W as Me,g as tt}from"./message-components-B3k4U96-.js";import"./input.js";import"./App-CCFLr34u.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 u={prompt:r,client_id:Z.api.clientId,extra_data:{extra_pageinfo:{workflow:n.workflow}}};console.debug("queuePrompt request_body.prompt:",r);const h=await Qe(u);return console.debug("queuePrompt response:",h),h}function Pe(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 u=n.width-60,h=30,d=l.split(" ");let c="",g=250;for(let f=0;fu&&f>0?(r.fillText(c,n.width/2,g),c=d[f]+" ",g+=h):c=M}r.fillText(c,n.width/2,g)}return n.toDataURL("image/png")}async function nt(l){try{if(!l||l==="")return console.log("No prompt ID provided"),{1:[Pe("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 h=r.status.messages;if(h&&h.length>0){const d=h[h.length-1];if(d&&d.length>0){const c=d[0];return{1:[Pe(c)]}}}}const u={};if(r.outputs)for(const h in r.outputs){const d=r.outputs[h];if(d&&d.images){u[h]=[];for(const c of d.images)if(c&&c.filename&&c.type){const g=Z.graph._nodes_by_id[h].imgs[0].currentSrc.split("?")[0];u[h].push(g+"?filename="+encodeURIComponent(c.filename)+"&type="+encodeURIComponent(c.type)+(c.subfolder?"&subfolder="+encodeURIComponent(c.subfolder):""))}console.log("outputImages for nodeId:",h,u[h])}}return u}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 u of l)u.type==="SaveImage"?n.push(u.id):u.type==="PreviewImage"&&r.push(u.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:u,handleClose:h})=>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:h,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((d,c)=>{const g=d.title||"Unknown Node",f=d.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:g}),e.jsx("div",{className:"p-4 space-y-3",children:e.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:f.map((M,L)=>{const S=M.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[S]?"border-red-500 bg-red-100":"border-gray-300"}`,onClick:W=>n(S,W),children:r[S]&&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:S})]},`widget-${L}`)})})})]},`node-${c}`)}),e.jsx("div",{className:"mt-6 flex justify-center",children:e.jsx("button",{onClick:d=>u(d),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",children:"Next"})})]}),it=({selectedNodes:l,paramTestValues:n,selectedParams:r,updateParamTestValues:u,toggleDropdown:h,openDropdowns:d,handleTestValueSelect:c,searchTerms:g,handleSearch:f,handleSelectAll:M,handleNext:L,handlePrevious:S,handleClose:W,inputValues:K,setInputValues:A,textInputs:B,handleTextInputChange:_,handleAddTextInput:T,handleRemoveTextInput:j,openAiWritingModal:w})=>{const C=(v,P,V,q=0)=>{if(v=isNaN(v)?0:v,P=isNaN(P)?100:P,V=isNaN(V)||V<=0?1:V,P{!l||l.length===0||l.forEach(v=>{const P=v.id.toString(),V=v.widgets||{};Object.values(V).forEach(m=>{const I=m.name;if(!r[I])return;if(!(n[P]?.[I]?.length>0)&&m.type==="number"){const x=m.options?.min||0,F=m.options?.max||100,D=(m.options?.step||10)/10,N=m.options?.precision||0,p=C(x,F,D,N);if(p.length>0){u(P,I,p);const G=`${P}_${I}`;A(H=>({...H,[G]:{min:x.toString(),max:F.toString(),step:D.toString()}}))}}if(m.type==="customtext"||m.type.toLowerCase().includes("text")){const x=`${P}_${I}`,F=B[x]||[""];JSON.stringify(F)!==JSON.stringify(n[P]?.[I]||[""])&&u(P,I,F)}})})},[l,r,n,B,u,A,C]),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:W,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((v,P)=>{const V=v.widgets||{},q=Object.values(V),m=v.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:[v.type," (ID: ",m,")"]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:I=>W(I,P),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:q.map((I,Y)=>{const x=I.name;if(!r[x])return null;const F=`${m}_${x}`;if(I.type==="customtext"||I.type.toLowerCase().includes("text")){const D=B[F]||[""];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:[x,":"]}),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:()=>w(m,x),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:D.map((N,p)=>e.jsxs("div",{className:"flex items-start",children:[e.jsx("textarea",{className:"flex-1 border border-gray-300 rounded p-2 text-xs resize-y",rows:2,placeholder:"Enter text...",value:N,onChange:G=>_(m,x,p,G.target.value)}),e.jsx("button",{className:"ml-2 text-red-500 hover:text-red-700",onClick:()=>j(m,x,p),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"})})})]},p))}),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:()=>T(m,x),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 D=I.options?.min||0,N=I.options?.max||100,p=(I.options?.step||10)/10,G=I.options?.precision||0,H=C(D,N,p,G),J=K[F]||{min:D.toString(),max:N.toString(),step:p.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:[x,":"]}),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:J.min,onClick:E=>{E.preventDefault(),E.stopPropagation()},onChange:E=>{E.preventDefault(),E.stopPropagation();const O=E.target.value;if(A($=>({...$,[F]:{...$[F],min:O}})),O===""||!isNaN(parseFloat(O))){const $=O===""?0:parseFloat(O),R=parseFloat(J.max||N.toString()),Q=parseFloat(J.step||p.toString()),U=C($,R,Q,G);u(m,x,U)}}}),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:J.max,onClick:E=>{E.preventDefault(),E.stopPropagation()},onChange:E=>{E.preventDefault(),E.stopPropagation();const O=E.target.value;if(A($=>({...$,[F]:{...$[F],max:O}})),O===""||!isNaN(parseFloat(O))){const $=parseFloat(J.min||D.toString()),R=O===""?$:parseFloat(O),Q=parseFloat(J.step||p.toString()),U=C($,R,Q,G);u(m,x,U)}}}),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:J.step,onClick:E=>{E.preventDefault(),E.stopPropagation()},onChange:E=>{E.preventDefault(),E.stopPropagation();const O=E.target.value;if(A($=>({...$,[F]:{...$[F],step:O}})),O===""||!isNaN(parseFloat(O))&&parseFloat(O)>0){const $=parseFloat(J.min||D.toString()),R=parseFloat(J.max||N.toString()),Q=O===""?1:parseFloat(O),U=C($,R,Q,G);u(m,x,U)}}})]}),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 E=n[m]?.[x]||H;if(E.length<=10)return E.map((O,$)=>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:R=>{R.stopPropagation(),c(m,x,O,R)},children:[e.jsx("span",{children:O}),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"})})]},$));{const O=E.slice(0,5),$=E.slice(E.length-5);return e.jsxs(e.Fragment,{children:[O.map((R,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:U=>{U.stopPropagation(),c(m,x,R,U)},children:[e.jsx("span",{children:R}),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:"..."}),$.map((R,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:U=>{U.stopPropagation(),c(m,x,R,U)},children:[e.jsx("span",{children:R}),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 D=I.options?.values||[],N=`${m}_${x}`;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:x}),e.jsxs("div",{className:"relative dropdown-container",children:[e.jsxs("button",{className:"appearance-none border 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(),h(m,x,p)},"data-dropdown":N,children:[e.jsx("span",{children:(n[m]?.[x]||[]).length>0?`${x}: ${(n[m]?.[x]||[]).length} selected`:`Select ${x}`}),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"})})})]}),d[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 d[N]=="object"?`${d[N].y}px`:"0px",left:typeof d[N]=="object"?`${d[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:g[N]||"",onChange:p=>{p.preventDefault(),p.stopPropagation(),f(m,x,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 G=D.filter(H=>!g[N]||H.toLowerCase().includes((g[N]||"").toLowerCase()));M(m,x,G)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${D.length>0&&(n[m]?.[x]||[]).length===D.length?"bg-blue-500 border-blue-500":(n[m]?.[x]||[]).length>0?"bg-blue-500 border-blue-500 opacity-50":"border-gray-300"}`,children:(n[m]?.[x]||[]).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:D.length>0&&(n[m]?.[x]||[]).length===D.length?"Deselect All":"Select All"})]}),e.jsxs("div",{className:"max-h-60 overflow-y-auto",children:[D.filter(p=>!g[N]||p.toLowerCase().includes((g[N]||"").toLowerCase())).map((p,G)=>e.jsxs("div",{className:"px-3 py-1.5 hover:bg-gray-100 cursor-pointer text-xs flex items-center text-gray-700",onClick:H=>{H.preventDefault(),H.stopPropagation(),c(m,x,p,H)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${(n[m]?.[x]||[]).includes(p)?"bg-blue-500 border-blue-500":"border-gray-300"}`,children:(n[m]?.[x]||[]).includes(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:p})]},G)),D.filter(p=>!g[N]||p.toLowerCase().includes((g[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"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:(n[m]?.[x]||[]).map((p,G)=>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:H=>{H.preventDefault(),H.stopPropagation(),c(m,x,p,H)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},G))})]})]},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:x})}),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[m]?.[x]||[]).map((D,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:D}),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:p=>{p.preventDefault(),p.stopPropagation(),c(m,x,D,p)},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:D=>{D.preventDefault(),D.stopPropagation();const N=`${x}${(n[m]?.[x]||[]).length+1}`;u(m,x,[...n[m]?.[x]||[],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)})})]},P)}):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:v=>S(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=>L(v),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:u,errorMessage:h,handlePrevious:d,handleStartGeneration:c,handleClose:g})=>{const[f,M]=b.useState([]),[L,S]=b.useState(null),[W,K]=b.useState(!1);Ie();const A=()=>{const _=Object.values(Z.graph._nodes_by_id),T=[],j=[];for(const C of _)C.type==="SaveImage"?T.push(C.id):C.type==="PreviewImage"&&j.push(C.id);const w=[...T,...j];M(w),w.length===1?S(w[0]):w.length>1&&(K(!0),S(null))};b.useEffect(()=>{A()},[]),b.useEffect(()=>{const _=()=>{if(!Z.canvas.selected_nodes)return;const T=Object.values(Z.canvas.selected_nodes);if(T.length===0)return;const j=T[0];j&&(j.type==="SaveImage"||j.type==="PreviewImage")&&(console.log("Selected image node:",j.id),S(j.id))};return document.addEventListener("click",_),()=>{document.removeEventListener("click",_)}},[]);const B=_=>{if(_&&(_.preventDefault(),_.stopPropagation()),f.length>1&&!L){K(!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 ",u," total runs. Each run will generate a separate image."]})]}),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"})})})]}),W&&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`})]})}),h&&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:h})]})}),l.length>0?l.map((_,T)=>{const j=_.type||"Unknown Node",w=_.widgets||[],C=_.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: ",C,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:w.map((v,P)=>{const V=v.name;if(!r[V])return null;const q=n[C]?.[V]||[],m=Array.isArray(q)?`[${q.join(", ")}]`:JSON.stringify(q);return e.jsxs("div",{className:PI.preventDefault()})})]},P)})})]},T)}):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(_),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:_=>B(_),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:u,completedCount:h,errorMessage:d,handleClose:c,setIsProcessing:g,setCurrentScreen:f,cleanupPolling:M})=>{const L=S=>{S.preventDefault(),S.stopPropagation(),Ze({clear:!0}),et(),M&&M(),g(!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 ",h," of ",u," 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:`${h/u*100}%`}})}),e.jsxs("div",{className:"mt-2 text-xs text-gray-600",children:["Already generated ",h," 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 ",u," 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"})})})]}),d&&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:d})]})}),l.length>0?l.map((S,W)=>{const K=S.type||"Unknown Node",A=S.widgets||[],B=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:[K," (ID: ",B,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:A.map((_,T)=>{const j=_.name;if(!r[j])return null;const w=n[B]?.[j]||[],C=Array.isArray(w)?`[${w.join(", ")}]`:JSON.stringify(w);return e.jsxs("div",{className:Tv.preventDefault()})})]},T)})})]},W)}):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:u,handlePrevious:h,handleClose:d,currentPage:c,handlePageChange:g,imagesPerPage:f,notificationVisible:M,modalVisible:L,modalImageUrl:S,openImageModal:W,closeImageModal:K})=>{const A=Math.ceil(l.length/f),B=(c-1)*f,_=Math.min(B+f,l.length),T=l.slice(B,_);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: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"})})})]}),M&&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:K,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:K,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:S,alt:"Enlarged image",className:"max-w-full h-auto"})})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-4 mb-6",children:T.map((j,w)=>{const C=B+w;return e.jsxs("div",{className:`relative rounded-lg overflow-hidden border ${n===C?"border-pink-500 ring-2 ring-pink-300":"border-gray-200"}`,onClick:v=>r(C,v),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:v=>W(j.url,v),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 ${C+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(([v,P])=>v!=="nodeParams"&&typeof P!="object").map(([v,P])=>e.jsxs("div",{children:[v,": ",String(P)]},v))})]},C)})}),A>1&&e.jsxs("div",{className:"flex justify-center items-center space-x-2 mt-4 mb-4",children:[e.jsx("button",{onClick:j=>g(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=>g(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=>g(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=>g(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=>h(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=>u(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:u,aiSelectedTexts:h,aiWritingLoading:d,aiWritingError:c,handleAiWriting:g,toggleTextSelection:f,addSelectedTexts:M,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:S=>r(S.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:g,disabled:d,children:d?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}),u.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:u.map((S,W)=>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${W+1}`,checked:!!h[`text${W+1}`],onChange:()=>f(`text${W+1}`),className:"sr-only"}),e.jsx("div",{className:`h-4 w-4 rounded border ${h[`text${W+1}`]?"bg-blue-600 border-blue-600":"bg-white border-gray-300"} flex items-center justify-center`,onClick:()=>f(`text${W+1}`),children:h[`text${W+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${W+1}`,className:"text-sm text-gray-700 cursor-pointer flex-1",children:S})]},W))})]})]}),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:M,disabled:Object.values(h).every(S=>!S),children:"Add Selected"})]})]})}):null,ye=l=>{const n=[],r={};if(Object.keys(l).forEach(d=>{const c=parseInt(d),g=l[d]||{},f=Object.keys(g).filter(L=>g[L]&&g[L].length>0);if(f.length===0)return;const M=[[]];f.forEach(L=>{const S=g[L],W=[];M.forEach(K=>{S.forEach(A=>{const B=[...K,{nodeId:c,paramName:L,paramValue:String(A)}];W.push(B)})}),M.length=0,M.push(...W)}),r[d]=M}),Object.keys(r).length===0)return n;if(Object.keys(r).length===1){const d=Object.keys(r)[0];return r[d]}const u=Object.keys(r);let h=r[u[0]];for(let d=1;d{c.forEach(M=>{g.push([...f,...M])})}),h=g}return h},mt=(l,n)=>{const r={};r.nodeParams={};const u=ye(l);return n{const c=d.nodeId.toString(),g=d.paramName,f=d.paramValue;r.nodeParams[c]||(r.nodeParams[c]={}),r.nodeParams[c][g]=f,r[g]=f}),r},ht=` + @keyframes highlight-pulse { + 0% { + box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5); + } + 70% { + box-shadow: 0 0 0 15px rgba(59, 130, 246, 0); + } + 100% { + box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); + } + } + + .highlight-pulse { + animation: highlight-pulse 1.5s infinite; + border: 2px solid #3b82f6; + } + + @keyframes fade-in-out { + 0% { opacity: 0; transform: translateY(-20px); } + 10% { opacity: 1; transform: translateY(0); } + 90% { opacity: 1; transform: translateY(0); } + 100% { opacity: 0; transform: translateY(-20px); } + } + + .animate-fade-in-out { + animation: fade-in-out 3s forwards; + } +`,vt=({selectedNodes:l,visible:n,onClose:r})=>{const[u,h]=b.useState(0),[d,c]=b.useState({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),[g,f]=b.useState(!1),[M,L]=b.useState(!1),[S,W]=b.useState(0),[K,A]=b.useState(12),[B,_]=b.useState(null),[T,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}}))),[w,C]=b.useState({}),[v,P]=b.useState({}),[V,q]=b.useState({}),[m,I]=b.useState({}),[Y,x]=b.useState(1),F=6,[D,N]=b.useState(null),[p,G]=b.useState(!1),[H,J]=b.useState(!1),[E,O]=b.useState(""),[$,R]=b.useState({}),[Q,U]=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 Me.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)}},_e=(t,s,i,o)=>{const a=`${t}_${s}`;R(y=>{const z=[...y[a]||[]];return z[i]=o,{...y,[a]:z}});const k=[...$[a]||[]];k[i]=o,ee(t,s,k)},De=(t,s)=>{const i=`${t}_${s}`;R(a=>{const k=[...a[i]||[]];return k.push(""),{...a,[i]:k}});const o=[...$[i]||[],""];ee(t,s,o)},Oe=(t,s,i)=>{const o=`${t}_${s}`;R(k=>{const y=[...k[o]||[]];return y.splice(i,1),{...k,[o]:y}});const a=[...$[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;R(o=>{const a=[...o[t]||[]];return{...o,[t]:[...a,...s]}});const i=[...$[t]||[],...s];ee(we,ke,i),U(!1)},Te=(t,s)=>{U(!0),Ne(t),Ce(s),ge(""),de([]),oe({}),xe(!1),ne(null)};b.useEffect(()=>{if(!l||l.length===0)return;const t={...w},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(w)&&C(t)},[l,w]),b.useEffect(()=>{ae({type:"SET_SCREEN_STATE",payload:{currentScreen:u,isProcessing:g,isCompleted:M}})},[u,g,M,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(v).some(i=>i)){const i=s.target,o=!!i.closest(".dropdown-menu"),a=!!i.closest("[data-dropdown]");!o&&!a&&P({})}};return document.addEventListener("mousedown",t),()=>{document.removeEventListener("mousedown",t)}},[v]);const Le=t=>{if(t&&(t.preventDefault(),t.stopPropagation()),u===0){const s={...w};Object.keys(s).forEach(i=>{const o=s[i];Object.keys(o).forEach(a=>{d[a]||delete o[a]})}),C(s)}if(u===1){const s={...w};l.forEach(o=>{const a=o.id.toString(),k=o.widgets||{};Object.values(k).forEach(y=>{const z=y.name;if(d[z]&&(y.type==="customtext"||y.type.toLowerCase().includes("text"))){const te=`${a}_${z}`,se=$[te]||[""];s[a]=s[a]||{},s[a][z]=se}})}),C(s);const i=ye(s);A(i.length)}N(null),h(s=>Math.min(s+1,2))},fe=t=>{if(t&&(t.preventDefault(),t.stopPropagation()),N(null),M&&L(!1),u===1){const s=l.map(a=>a.id.toString()),i=Object.keys(w),o={...w};i.forEach(a=>{s.includes(a)||delete o[a]}),C(o)}if(u===2||M){const s={...w};Object.entries($).forEach(([i,o])=>{if(!o||o.length===0)return;const[a,k]=i.split("_");l.some(y=>y.id.toString()===a)&&(s[a]=s[a]||{},JSON.stringify(s[a][k])!==JSON.stringify(o)&&(s[a][k]=o))}),C(s)}h(s=>Math.max(s-1,0))},Re=(t,s)=>{s&&(s.preventDefault(),s.stopPropagation());const i=d[t];if(c(o=>({...o,[t]:!i})),i){const o={...w};Object.keys(o).forEach(a=>{o[a][t]&&delete o[a][t]}),C(o)}},ze=(t,s,i)=>{i.preventDefault(),i.stopPropagation();const o=`${t}_${s}`;P(a=>{if(a[o]&&typeof a[o]=="object"?a[o].isOpen:!!a[o])return{...a,[o]:!1};{let y=0,z=0;if(i.currentTarget){const ce=i.currentTarget.getBoundingClientRect();y=ce.left,z=ce.bottom}else y=i.clientX,z=i.clientY+20;const te=window.innerWidth,se=250;return y+se>te&&(y=te-se-10),y<0&&(y=10),{...a,[o]:{isOpen:!0,x:y,y:z}}}})},ee=(t,s,i)=>{C(o=>{const a={...o};return a[t]||(a[t]={}),a[t][s]=i,a})},Fe=(t,s,i,o)=>{o&&(o.preventDefault(),o.stopPropagation()),C(a=>{const k={...a};k[t]||(k[t]={}),k[t][s]||(k[t][s]=[]);const y=k[t][s];return y.includes(i)?k[t][s]=y.filter(z=>z!==i):k[t][s]=[...y,i],k})},Ge=(t,s,i)=>{const o=`${t}_${s}`;q(a=>({...a,[o]:i}))},Ve=(t,s,i)=>{if(!w[t]){ee(t,s,i);return}const o=w[t][s]||[];i.length===o.length?ee(t,s,[]):ee(t,s,[...i])},Ue=(t,s)=>{s&&(s.preventDefault(),s.stopPropagation()),x(Math.max(1,Math.min(t,Math.ceil(T.length/F))))},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(w),o=i.length;if(o>100){N(`Cannot generate more than 100 images at once (currently: ${o} images)`);return}if(N(null),f(!0),W(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 y=ot();y!==null&&(a=y)}if(a===null){N("Please select a SaveImage or PreviewImage node first."),f(!1);return}const k=[];try{const y=Date.now().toString();le.current=y;for(const re of i){const X=await rt(re);X.prompt_id?k.push(X.prompt_id):(console.error("Failed to get prompt_id from response:",X),k.push(""))}const z=Array(i.length).fill(null).map((re,X)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:mt(w,X)}));j(z);const te=Date.now(),se=5*60*1e3,ce=async()=>{if(le.current!==y){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===y&&(f(!1),L(!0),x(1));return}let re=0;for(let X=0;X{s&&(s.preventDefault(),s.stopPropagation()),_(t)},Je=(t,s)=>{s.preventDefault(),s.stopPropagation(),O(t),J(!0)},qe=t=>{t&&(t.preventDefault(),t.stopPropagation()),J(!1)},Ye=async t=>{if(t&&(t.preventDefault(),t.stopPropagation()),B!==null){console.log(`Applied image ${B+1} with parameters:`,T[B].params),Me.trackEvent({event_type:"parameter_debug_apply",message_type:"parameter_debug",message_id:tt(),data:{workflow:(await Z.graphToPrompt()).output,selected_params:T[B].params,all_params:w,count:Object.keys(w).length}});const s=T[B].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(([k,y])=>{for(const z of a.widgets)if(z.name===k){z.value=y;break}})}),Z.graph.setDirtyCanvas(!1,!0),G(!0),setTimeout(()=>{G(!1)},3e3))}},ie=(t,s)=>{if(t&&(t.preventDefault(),t.stopPropagation()),u===1&&s!==void 0){const i=[...l],o=i[s];if(i.splice(s,1),o){const a=o.id.toString();C(k=>{const y={...k};return delete y[a],y})}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=()=>{h(0),c({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),me(),f(!1),L(!1),W(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}}))),C({}),P({}),q({}),I({}),x(1),N(null),G(!1),J(!1),O(""),R({}),U(!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"})})]})]})}):M?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(xt,{generatedImages:T,selectedImageIndex:B,handleSelectImage:Ke,handleApplySelected:Ye,handlePrevious:fe,handleClose:ie,currentPage:Y,handlePageChange:Ue,imagesPerPage:F,notificationVisible:p,modalVisible:H,modalImageUrl:E,openImageModal:Je,closeImageModal:qe})}):g?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:w,selectedParams:d,totalCount:K,completedCount:S,errorMessage:D,handleClose:ie,setIsProcessing:f,setCurrentScreen:h,cleanupPolling:me})}):u===0?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(lt,{selectedNodes:l,handleParamSelect:Re,selectedParams:d,handleNext:Le,handleClose:ie})}):u===1?e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:[e.jsx(it,{selectedNodes:l,paramTestValues:w,selectedParams:d,updateParamTestValues:ee,toggleDropdown:ze,openDropdowns:v,handleTestValueSelect:Fe,searchTerms:V,handleSearch:Ge,handleSelectAll:Ve,handleNext:Le,handlePrevious:fe,handleClose:ie,inputValues:m,setInputValues:I,textInputs:$,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:()=>U(!1)})]}):e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(ct,{selectedNodes:l,paramTestValues:w,selectedParams:d,totalCount:K,errorMessage:D,handlePrevious:fe,handleStartGeneration:He,handleClose:ie})})};export{vt as ParameterDebugInterface}; diff --git a/dist/copilot_web/ParameterDebugInterfaceNew-BavknXdE.js b/dist/copilot_web/ParameterDebugInterfaceNew-BavknXdE.js deleted file mode 100644 index 618fc85..0000000 --- a/dist/copilot_web/ParameterDebugInterfaceNew-BavknXdE.js +++ /dev/null @@ -1,29 +0,0 @@ -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-QHF8s17w.js";import{a as Z,u as Ie,W as Me,g as tt}from"./message-components-B3k4U96-.js";import"./input.js";import"./App-BKUkXtap.js";function st(o,n){try{if(!o)return console.error("Invalid prompt_output: ",o),o;for(const s of n){if(!o[s.nodeId]){console.error(`Node with ID ${s.nodeId} not found`);continue}if(!o[s.nodeId].inputs){console.error(`Inputs not found for node with ID ${s.nodeId}`);continue}o[s.nodeId].inputs[s.paramName]=s.paramValue}return o}catch(s){return console.error("Error updating prompt:",s),o}}async function rt(o){const n=await Z.graphToPrompt(),s=st(n.output,o);console.log("queuePrompt updated_prompt:",s);const u={prompt:s,client_id:Z.api.clientId,extra_data:{extra_pageinfo:{workflow:n.workflow}}};console.debug("queuePrompt request_body.prompt:",s);const h=await Qe(u);return console.debug("queuePrompt response:",h),h}function Pe(o){const n=document.createElement("canvas"),s=n.getContext("2d");if(n.width=512,n.height=512,s){s.fillStyle="#f8d7da",s.fillRect(0,0,n.width,n.height),s.strokeStyle="#dc3545",s.lineWidth=4,s.strokeRect(10,10,n.width-20,n.height-20),s.fillStyle="#dc3545",s.beginPath(),s.arc(n.width/2,150,50,0,2*Math.PI),s.fill(),s.fillStyle="white",s.font="bold 80px Arial",s.textAlign="center",s.textBaseline="middle",s.fillText("!",n.width/2,150),s.fillStyle="#721c24",s.font="20px Arial",s.textAlign="center",s.textBaseline="middle";const u=n.width-60,h=30,x=o.split(" ");let c="",g=250;for(let f=0;fu&&f>0?(s.fillText(c,n.width/2,g),c=x[f]+" ",g+=h):c=P}s.fillText(c,n.width/2,g)}return n.toDataURL("image/png")}async function nt(o){try{if(!o||o==="")return console.log("No prompt ID provided"),{1:[Pe("Fail to generate prompt ID")]};const n=await Xe(o);if(!n||!n[o])return console.log("Not finished for prompt ID:",o),{};const s=n[o];if(s.status&&s.status.status_str==="error"){console.error("Error for prompt ID:",o);const h=s.status.messages;if(h&&h.length>0){const x=h[h.length-1];if(x&&x.length>0){const c=x[0];return{1:[Pe(c)]}}}}const u={};if(s.outputs)for(const h in s.outputs){const x=s.outputs[h];if(x&&x.images){u[h]=[];for(const c of x.images)if(c&&c.filename&&c.type){const g=Z.graph._nodes_by_id[h].imgs[0].currentSrc.split("?")[0];u[h].push(g+"?filename="+encodeURIComponent(c.filename)+"&type="+encodeURIComponent(c.type)+(c.subfolder?"&subfolder="+encodeURIComponent(c.subfolder):""))}console.log("outputImages for nodeId:",h,u[h])}}return u}catch(n){throw console.error("Error getting output images from prompt:",n),n}}function ot(){const o=Object.values(Z.graph._nodes_by_id),n=[],s=[];for(const u of o)u.type==="SaveImage"?n.push(u.id):u.type==="PreviewImage"&&s.push(u.id);if(console.log("saveNodeIds:",n),console.log("previewNodeIds:",s),n.length===0&&s.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&&s.length===1?s[0]:null}async function at(o,n){const s=await nt(o);return Object.keys(s).length===0?null:s[n.toString()]&&s[n.toString()].length>0?s[n.toString()][0]:null}const lt=({selectedNodes:o,handleParamSelect:n,selectedParams:s,handleNext:u,handleClose:h})=>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:h,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"})})})]}),o.map((x,c)=>{const g=x.title||"Unknown Node",f=x.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:g}),e.jsx("div",{className:"p-4 space-y-3",children:e.jsx("div",{className:"flex items-center gap-3 flex-wrap",children:f.map((P,S)=>{const k=P.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 ${s[k]?"border-red-500 bg-red-100":"border-gray-300"}`,onClick:$=>n(k,$),children:s[k]&&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:k})]},`widget-${S}`)})})})]},`node-${c}`)}),e.jsx("div",{className:"mt-6 flex justify-center",children:e.jsx("button",{onClick:x=>u(x),className:"px-3 py-1.5 text-xs bg-pink-200 text-pink-700 rounded-md hover:bg-pink-300 transition-colors",children:"Next"})})]}),it=({selectedNodes:o,paramTestValues:n,selectedParams:s,updateParamTestValues:u,toggleDropdown:h,openDropdowns:x,handleTestValueSelect:c,searchTerms:g,handleSearch:f,handleSelectAll:P,handleNext:S,handlePrevious:k,handleClose:$,inputValues:K,setInputValues:O,textInputs:B,handleTextInputChange:W,handleAddTextInput:T,handleRemoveTextInput:j,openAiWritingModal:w})=>{const C=(y,I,F,J=0)=>{if(y=isNaN(y)?0:y,I=isNaN(I)?100:I,F=isNaN(F)||F<=0?1:F,I{!o||o.length===0||o.forEach(y=>{const I=y.id.toString(),F=y.widgets||{};Object.values(F).forEach(m=>{const E=m.name;if(!s[E])return;const q=n[I]?.[E]?.length>0;if(!q&&m.type==="number"){const d=m.options?.min||0,G=m.options?.max||100,D=(m.options?.step||10)/10,v=m.options?.precision||0,p=C(d,G,D,v);if(p.length>0){u(I,E,p);const z=`${I}_${E}`;O(H=>({...H,[z]:{min:d.toString(),max:G.toString(),step:D.toString()}}))}}if(!q&&(m.type==="customtext"||m.type.toLowerCase().includes("text"))){const d=`${I}_${E}`;(!B[d]||B[d].length===0)&&u(I,E,[""])}})})},[o,s,n,B,u,O,C]),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"})})})]}),o.length>0?o.map((y,I)=>{const F=y.widgets||{},J=Object.values(F),m=y.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:[y.type," (ID: ",m,")"]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:E=>$(E,I),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((E,q)=>{const d=E.name;if(!s[d])return null;const G=`${m}_${d}`;if(E.type==="customtext"||E.type.toLowerCase().includes("text")){const D=B[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:()=>w(m,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:D.map((v,p)=>e.jsxs("div",{className:"flex items-start",children:[e.jsx("textarea",{className:"flex-1 border border-gray-300 rounded p-2 text-xs resize-y",rows:2,placeholder:"Enter text...",value:v,onChange:z=>W(m,d,p,z.target.value)}),e.jsx("button",{className:"ml-2 text-red-500 hover:text-red-700",onClick:()=>j(m,d,p),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"})})})]},p))}),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:()=>T(m,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"]})]},q)}if(E.type==="number"){const D=E.options?.min||0,v=E.options?.max||100,p=(E.options?.step||10)/10,z=E.options?.precision||0,H=C(D,v,p,z),Y=K[G]||{min:D.toString(),max:v.toString(),step:p.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:Y.min,onClick:L=>{L.preventDefault(),L.stopPropagation()},onChange:L=>{L.preventDefault(),L.stopPropagation();const _=L.target.value;if(O(A=>({...A,[G]:{...A[G],min:_}})),_===""||!isNaN(parseFloat(_))){const A=_===""?0:parseFloat(_),R=parseFloat(Y.max||v.toString()),Q=parseFloat(Y.step||p.toString()),V=C(A,R,Q,z);u(m,d,V)}}}),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:Y.max,onClick:L=>{L.preventDefault(),L.stopPropagation()},onChange:L=>{L.preventDefault(),L.stopPropagation();const _=L.target.value;if(O(A=>({...A,[G]:{...A[G],max:_}})),_===""||!isNaN(parseFloat(_))){const A=parseFloat(Y.min||D.toString()),R=_===""?A:parseFloat(_),Q=parseFloat(Y.step||p.toString()),V=C(A,R,Q,z);u(m,d,V)}}}),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:Y.step,onClick:L=>{L.preventDefault(),L.stopPropagation()},onChange:L=>{L.preventDefault(),L.stopPropagation();const _=L.target.value;if(O(A=>({...A,[G]:{...A[G],step:_}})),_===""||!isNaN(parseFloat(_))&&parseFloat(_)>0){const A=parseFloat(Y.min||D.toString()),R=parseFloat(Y.max||v.toString()),Q=_===""?1:parseFloat(_),V=C(A,R,Q,z);u(m,d,V)}}})]}),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 L=n[m]?.[d]||H;if(L.length<=10)return L.map((_,A)=>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:R=>{R.stopPropagation(),c(m,d,_,R)},children:[e.jsx("span",{children:_}),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"})})]},A));{const _=L.slice(0,5),A=L.slice(L.length-5);return e.jsxs(e.Fragment,{children:[_.map((R,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:V=>{V.stopPropagation(),c(m,d,R,V)},children:[e.jsx("span",{children:R}),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:"..."}),A.map((R,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:V=>{V.stopPropagation(),c(m,d,R,V)},children:[e.jsx("span",{children:R}),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"})})]},q)}else if(E.type==="combo"){const D=E.options?.values||[],v=`${m}_${d}`;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 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(),h(m,d,p)},"data-dropdown":v,children:[e.jsx("span",{children:(n[m]?.[d]||[]).length>0?`${d}: ${(n[m]?.[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"})})})]}),x[v]&&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 x[v]=="object"?`${x[v].y}px`:"0px",left:typeof x[v]=="object"?`${x[v].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:g[v]||"",onChange:p=>{p.preventDefault(),p.stopPropagation(),f(m,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 z=D.filter(H=>!g[v]||H.toLowerCase().includes((g[v]||"").toLowerCase()));P(m,d,z)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${D.length>0&&(n[m]?.[d]||[]).length===D.length?"bg-blue-500 border-blue-500":(n[m]?.[d]||[]).length>0?"bg-blue-500 border-blue-500 opacity-50":"border-gray-300"}`,children:(n[m]?.[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:D.length>0&&(n[m]?.[d]||[]).length===D.length?"Deselect All":"Select All"})]}),e.jsxs("div",{className:"max-h-60 overflow-y-auto",children:[D.filter(p=>!g[v]||p.toLowerCase().includes((g[v]||"").toLowerCase())).map((p,z)=>e.jsxs("div",{className:"px-3 py-1.5 hover:bg-gray-100 cursor-pointer text-xs flex items-center text-gray-700",onClick:H=>{H.preventDefault(),H.stopPropagation(),c(m,d,p,H)},children:[e.jsx("div",{className:`w-4 h-4 mr-2 border rounded-sm flex items-center justify-center ${(n[m]?.[d]||[]).includes(p)?"bg-blue-500 border-blue-500":"border-gray-300"}`,children:(n[m]?.[d]||[]).includes(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:p})]},z)),D.filter(p=>!g[v]||p.toLowerCase().includes((g[v]||"").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"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:(n[m]?.[d]||[]).map((p,z)=>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:H=>{H.preventDefault(),H.stopPropagation(),c(m,d,p,H)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},z))})]})]},q)}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[m]?.[d]||[]).map((D,v)=>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:D}),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:p=>{p.preventDefault(),p.stopPropagation(),c(m,d,D,p)},children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})]},v)),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:D=>{D.preventDefault(),D.stopPropagation();const v=`${d}${(n[m]?.[d]||[]).length+1}`;u(m,d,[...n[m]?.[d]||[],v])},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"})]})]})]})]},q)})})]},I)}):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:y=>k(y),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:y=>S(y),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:o,paramTestValues:n,selectedParams:s,totalCount:u,errorMessage:h,handlePrevious:x,handleStartGeneration:c,handleClose:g})=>{const[f,P]=b.useState([]),[S,k]=b.useState(null),[$,K]=b.useState(!1);Ie();const O=()=>{const W=Object.values(Z.graph._nodes_by_id),T=[],j=[];for(const C of W)C.type==="SaveImage"?T.push(C.id):C.type==="PreviewImage"&&j.push(C.id);const w=[...T,...j];P(w),w.length===1?k(w[0]):w.length>1&&(K(!0),k(null))};b.useEffect(()=>{O()},[]),b.useEffect(()=>{const W=()=>{if(!Z.canvas.selected_nodes)return;const T=Object.values(Z.canvas.selected_nodes);if(T.length===0)return;const j=T[0];j&&(j.type==="SaveImage"||j.type==="PreviewImage")&&(console.log("Selected image node:",j.id),k(j.id))};return document.addEventListener("click",W),()=>{document.removeEventListener("click",W)}},[]);const B=W=>{if(W&&(W.preventDefault(),W.stopPropagation()),f.length>1&&!S){K(!0);return}c(W,S||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 ",u," total runs. Each run will generate a separate image."]})]}),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"})})})]}),$&&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:S===null?`Multiple SaveImage and PreviewImage nodes detected with IDs ${f.join(",")}. Please click the node on canvas.`:`Current node ID is ${S}, please click Start Generation again`})]})}),h&&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:h})]})}),o.length>0?o.map((W,T)=>{const j=W.type||"Unknown Node",w=W.widgets||[],C=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",children:[j," (ID: ",C,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:w.map((y,I)=>{const F=y.name;if(!s[F])return null;const J=n[C]?.[F]||[],m=Array.isArray(J)?`[${J.join(", ")}]`:JSON.stringify(J);return e.jsxs("div",{className:IE.preventDefault()})})]},I)})})]},T)}):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:W=>x(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=>B(W),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${f.length>1&&!S?"bg-gray-200 text-gray-500 cursor-not-allowed":"bg-pink-200 text-pink-700 hover:bg-pink-300"}`,disabled:f.length>1&&!S,children:"Start Generation"})]})]})},dt=({selectedNodes:o,paramTestValues:n,selectedParams:s,totalCount:u,completedCount:h,errorMessage:x,handleClose:c,setIsProcessing:g,setCurrentScreen:f,cleanupPolling:P})=>{const S=k=>{k.preventDefault(),k.stopPropagation(),Ze({clear:!0}),et(),P&&P(),g(!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 ",h," of ",u," 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:`${h/u*100}%`}})}),e.jsxs("div",{className:"mt-2 text-xs text-gray-600",children:["Already generated ",h," images"]}),e.jsx("button",{onClick:S,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 ",u," 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"})})})]}),x&&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:x})]})}),o.length>0?o.map((k,$)=>{const K=k.type||"Unknown Node",O=k.widgets||[],B=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",children:[K," (ID: ",B,")"]}),e.jsx("div",{className:"p-4 space-y-3",children:O.map((W,T)=>{const j=W.name;if(!s[j])return null;const w=n[B]?.[j]||[],C=Array.isArray(w)?`[${w.join(", ")}]`:JSON.stringify(w);return e.jsxs("div",{className:Ty.preventDefault()})})]},T)})})]},$)}):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:o,selectedImageIndex:n,handleSelectImage:s,handleApplySelected:u,handlePrevious:h,handleClose:x,currentPage:c,handlePageChange:g,imagesPerPage:f,notificationVisible:P,modalVisible:S,modalImageUrl:k,openImageModal:$,closeImageModal:K})=>{const O=Math.ceil(o.length/f),B=(c-1)*f,W=Math.min(B+f,o.length),T=o.slice(B,W);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 ",o.length," images have been generated."]})]}),e.jsx("button",{className:"text-gray-400 hover:text-gray-600",onClick:x,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."})]})}),S&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50",onClick:K,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:K,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:k,alt:"Enlarged image",className:"max-w-full h-auto"})})]})}),e.jsx("div",{className:"grid grid-cols-3 gap-4 mb-6",children:T.map((j,w)=>{const C=B+w;return e.jsxs("div",{className:`relative rounded-lg overflow-hidden border ${n===C?"border-pink-500 ring-2 ring-pink-300":"border-gray-200"}`,onClick:y=>s(C,y),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:y=>$(j.url,y),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 ${C+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(([y,I])=>y!=="nodeParams"&&typeof I!="object").map(([y,I])=>e.jsxs("div",{children:[y,": ",String(I)]},y))})]},C)})}),O>1&&e.jsxs("div",{className:"flex justify-center items-center space-x-2 mt-4 mb-4",children:[e.jsx("button",{onClick:j=>g(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=>g(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 ",O]}),e.jsx("button",{onClick:j=>g(c+1,j),disabled:c===O,className:`px-2 py-1 rounded ${c===O?"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=>g(O,j),disabled:c===O,className:`px-2 py-1 rounded ${c===O?"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=>h(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=>u(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:o,aiWritingModalText:n,setAiWritingModalText:s,aiGeneratedTexts:u,aiSelectedTexts:h,aiWritingLoading:x,aiWritingError:c,handleAiWriting:g,toggleTextSelection:f,addSelectedTexts:P,onClose:S})=>o?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:S,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:k=>s(k.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:g,disabled:x,children:x?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}),u.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:u.map((k,$)=>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:!!h[`text${$+1}`],onChange:()=>f(`text${$+1}`),className:"sr-only"}),e.jsx("div",{className:`h-4 w-4 rounded border ${h[`text${$+1}`]?"bg-blue-600 border-blue-600":"bg-white border-gray-300"} flex items-center justify-center`,onClick:()=>f(`text${$+1}`),children:h[`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:k})]},$))})]})]}),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:S,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(h).every(k=>!k),children:"Add Selected"})]})]})}):null,ye=o=>{const n=[],s={};if(Object.keys(o).forEach(x=>{const c=parseInt(x),g=o[x]||{},f=Object.keys(g).filter(S=>g[S]&&g[S].length>0);if(f.length===0)return;const P=[[]];f.forEach(S=>{const k=g[S],$=[];P.forEach(K=>{k.forEach(O=>{const B=[...K,{nodeId:c,paramName:S,paramValue:String(O)}];$.push(B)})}),P.length=0,P.push(...$)}),s[x]=P}),Object.keys(s).length===0)return n;if(Object.keys(s).length===1){const x=Object.keys(s)[0];return s[x]}const u=Object.keys(s);let h=s[u[0]];for(let x=1;x{c.forEach(P=>{g.push([...f,...P])})}),h=g}return h},mt=(o,n)=>{const s={};s.nodeParams={};const u=ye(o);return n{const c=x.nodeId.toString(),g=x.paramName,f=x.paramValue;s.nodeParams[c]||(s.nodeParams[c]={}),s.nodeParams[c][g]=f,s[g]=f}),s},ht=` - @keyframes highlight-pulse { - 0% { - box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.5); - } - 70% { - box-shadow: 0 0 0 15px rgba(59, 130, 246, 0); - } - 100% { - box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); - } - } - - .highlight-pulse { - animation: highlight-pulse 1.5s infinite; - border: 2px solid #3b82f6; - } - - @keyframes fade-in-out { - 0% { opacity: 0; transform: translateY(-20px); } - 10% { opacity: 1; transform: translateY(0); } - 90% { opacity: 1; transform: translateY(0); } - 100% { opacity: 0; transform: translateY(-20px); } - } - - .animate-fade-in-out { - animation: fade-in-out 3s forwards; - } -`,vt=({selectedNodes:o,visible:n,onClose:s})=>{const[u,h]=b.useState(0),[x,c]=b.useState({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),[g,f]=b.useState(!1),[P,S]=b.useState(!1),[k,$]=b.useState(0),[K,O]=b.useState(12),[B,W]=b.useState(null),[T,j]=b.useState(()=>Array(12).fill(null).map((t,r)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:r%3===0?5:r%3===1?10:15,sampler_name:"euler",cfg:1}}))),[w,C]=b.useState({}),[y,I]=b.useState({}),[F,J]=b.useState({}),[m,E]=b.useState({}),[q,d]=b.useState(1),G=6,[D,v]=b.useState(null),[p,z]=b.useState(!1),[H,Y]=b.useState(!1),[L,_]=b.useState(""),[A,R]=b.useState({}),[Q,V]=b.useState(!1),[pe,ge]=b.useState(""),[ve,ie]=b.useState([]),[Ee,ce]=b.useState(!1),[we,Ne]=b.useState(""),[ke,Ce]=b.useState(""),[$e,se]=b.useState(null),[Se,re]=b.useState({}),{dispatch:ne}=Ie(),de=b.useRef(null),oe=b.useRef(null),We=async()=>{if(!pe.trim()){se("Please enter some text to generate variations");return}ce(!0),se(null),ie([]),re({});try{const t=await Me.generateSDPrompts(pe);ie(t);const r={};t.forEach((i,a)=>{r[`text${a+1}`]=!1}),re(r)}catch(t){console.error("Error generating text:",t),se("Failed to generate text variations. Please try again.")}finally{ce(!1)}},De=(t,r,i,a)=>{const l=`${t}_${r}`;R(N=>{const U=[...N[l]||[]];return U[i]=a,{...N,[l]:U}});const M=[...A[l]||[]];M[i]=a,ee(t,r,M)},_e=(t,r)=>{const i=`${t}_${r}`;R(l=>{const M=[...l[i]||[]];return M.push(""),{...l,[i]:M}});const a=[...A[i]||[],""];ee(t,r,a)},Ae=(t,r,i)=>{const a=`${t}_${r}`;R(M=>{const N=[...M[a]||[]];return N.splice(i,1),{...M,[a]:N}});const l=[...A[a]||[]];l.splice(i,1),ee(t,r,l)},Oe=t=>{re(r=>({...r,[t]:!r[t]}))},Be=()=>{const t=`${we}_${ke}`,r=Object.entries(Se).filter(([a,l])=>l).map(([a])=>{const l=parseInt(a.replace("text",""))-1;return ve[l]});if(r.length===0)return;R(a=>{const l=[...a[t]||[]];return{...a,[t]:[...l,...r]}});const i=[...A[t]||[],...r];ee(we,ke,i),V(!1)},Te=(t,r)=>{V(!0),Ne(t),Ce(r),ge(""),ie([]),re({}),ce(!1),se(null)};b.useEffect(()=>{if(!o||o.length===0)return;const t={...w},r=o.map(a=>a.id.toString());Object.keys(t).forEach(a=>{r.includes(a)||delete t[a]}),o.forEach(a=>{const l=a.id.toString();t[l]||(t[l]={})}),JSON.stringify(t)!==JSON.stringify(w)&&C(t)},[o,w]),b.useEffect(()=>{ne({type:"SET_SCREEN_STATE",payload:{currentScreen:u,isProcessing:g,isCompleted:P}})},[u,g,P,ne]),b.useEffect(()=>{const t=document.createElement("style");return t.textContent=ht,document.head.appendChild(t),()=>{document.head.removeChild(t)}},[]),b.useEffect(()=>{const t=r=>{if(Object.values(y).some(i=>i)){const i=r.target,a=!!i.closest(".dropdown-menu"),l=!!i.closest("[data-dropdown]");!a&&!l&&I({})}};return document.addEventListener("mousedown",t),()=>{document.removeEventListener("mousedown",t)}},[y]);const Le=t=>{if(t&&(t.preventDefault(),t.stopPropagation()),u===0){const r={...w};Object.keys(r).forEach(i=>{const a=r[i];Object.keys(a).forEach(l=>{x[l]||delete a[l]})}),C(r)}if(u===1){const r=ye(w);O(r.length)}v(null),h(r=>Math.min(r+1,2))},fe=t=>{if(t&&(t.preventDefault(),t.stopPropagation()),v(null),P&&S(!1),u===1){const r=o.map(l=>l.id.toString()),i=Object.keys(w),a={...w};i.forEach(l=>{r.includes(l)||delete a[l]}),C(a)}h(r=>Math.max(r-1,0))},Re=(t,r)=>{r&&(r.preventDefault(),r.stopPropagation());const i=x[t];if(c(a=>({...a,[t]:!i})),i){const a={...w};Object.keys(a).forEach(l=>{a[l][t]&&delete a[l][t]}),C(a)}},ze=(t,r,i)=>{i.preventDefault(),i.stopPropagation();const a=`${t}_${r}`;I(l=>{if(l[a]&&typeof l[a]=="object"?l[a].isOpen:!!l[a])return{...l,[a]:!1};{let N=0,U=0;if(i.currentTarget){const le=i.currentTarget.getBoundingClientRect();N=le.left,U=le.bottom}else N=i.clientX,U=i.clientY+20;const ue=window.innerWidth,me=250;return N+me>ue&&(N=ue-me-10),N<0&&(N=10),{...l,[a]:{isOpen:!0,x:N,y:U}}}})},ee=(t,r,i)=>{C(a=>{const l={...a};return l[t]||(l[t]={}),l[t][r]=i,l})},Fe=(t,r,i,a)=>{a&&(a.preventDefault(),a.stopPropagation()),C(l=>{const M={...l};M[t]||(M[t]={}),M[t][r]||(M[t][r]=[]);const N=M[t][r];return N.includes(i)?M[t][r]=N.filter(U=>U!==i):M[t][r]=[...N,i],M})},Ge=(t,r,i)=>{const a=`${t}_${r}`;J(l=>({...l,[a]:i}))},Ve=(t,r,i)=>{if(!w[t]){ee(t,r,i);return}const a=w[t][r]||[];i.length===a.length?ee(t,r,[]):ee(t,r,[...i])},Ue=(t,r)=>{r&&(r.preventDefault(),r.stopPropagation()),d(Math.max(1,Math.min(t,Math.ceil(T.length/G))))},xe=()=>{de.current&&(clearTimeout(de.current),de.current=null),oe.current=null};b.useEffect(()=>()=>{xe()},[]);const He=async(t,r)=>{t&&(t.preventDefault(),t.stopPropagation()),xe();const i=ye(w),a=i.length;if(a>100){v(`Cannot generate more than 100 images at once (currently: ${a} images)`);return}if(v(null),f(!0),$(0),console.log("Generated parameter combinations:",i),i.length===0){v("No valid parameter combinations found. Please check your parameter selections."),f(!1);return}let l=r||null;if(l===null){const N=ot();N!==null&&(l=N)}if(l===null){v("Please select a SaveImage or PreviewImage node first."),f(!1);return}const M=[];try{const N=Date.now().toString();oe.current=N;for(const te of i){const X=await rt(te);X.prompt_id?M.push(X.prompt_id):(console.error("Failed to get prompt_id from response:",X),M.push(""))}const U=Array(i.length).fill(null).map((te,X)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:mt(w,X)}));j(U);const ue=Date.now(),me=5*60*1e3,le=async()=>{if(oe.current!==N){console.log("Another polling session has started, stopping this one");return}if(Date.now()-ue>me){console.log("Timeout reached while waiting for images"),oe.current===N&&(f(!1),S(!0),d(1));return}let te=0;for(let X=0;X{r&&(r.preventDefault(),r.stopPropagation()),W(t)},qe=(t,r)=>{r.preventDefault(),r.stopPropagation(),_(t),Y(!0)},Ye=t=>{t&&(t.preventDefault(),t.stopPropagation()),Y(!1)},Je=async t=>{if(t&&(t.preventDefault(),t.stopPropagation()),B!==null){console.log(`Applied image ${B+1} with parameters:`,T[B].params),Me.trackEvent({event_type:"parameter_debug_apply",message_type:"parameter_debug",message_id:tt(),data:{workflow:(await Z.graphToPrompt()).output,selected_params:T[B].params,all_params:w,count:Object.keys(w).length}});const r=T[B].params;r.nodeParams&&(Object.entries(r.nodeParams).forEach(([i,a])=>{const l=Z.graph._nodes_by_id[i];!l||!l.widgets||Object.entries(a).forEach(([M,N])=>{for(const U of l.widgets)if(U.name===M){U.value=N;break}})}),Z.graph.setDirtyCanvas(!1,!0),z(!0),setTimeout(()=>{z(!1)},3e3))}},ae=(t,r)=>{if(t&&(t.preventDefault(),t.stopPropagation()),u===1&&r!==void 0){const i=[...o],a=i[r];if(i.splice(r,1),a){const l=a.id.toString();C(M=>{const N={...M};return delete N[l],N})}i.length===0?s&&(ne({type:"SET_SCREEN_STATE",payload:null}),be(),s()):ne({type:"SET_SELECTED_NODE",payload:i});return}s?(ne({type:"SET_SCREEN_STATE",payload:null}),be(),s()):be()},be=()=>{h(0),c({Steps:!0,CFG:!0,sampler_name:!0,threshold:!1,prompt:!1}),xe(),f(!1),S(!1),$(0),O(12),W(null),j(Array(12).fill(null).map((t,r)=>({url:`https://source.unsplash.com/random/300x300?sig=${Math.random()}`,params:{step:r%3===0?5:r%3===1?10:15,sampler_name:"euler",cfg:1}}))),C({}),I({}),J({}),E({}),d(1),v(null),z(!1),Y(!1),_(""),R({}),V(!1),ge(""),ie([]),ce(!1),Ne(""),Ce(""),se(null),re({})};return!n||o.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:T,selectedImageIndex:B,handleSelectImage:Ke,handleApplySelected:Je,handlePrevious:fe,handleClose:ae,currentPage:q,handlePageChange:Ue,imagesPerPage:G,notificationVisible:p,modalVisible:H,modalImageUrl:L,openImageModal:qe,closeImageModal:Ye})}):g?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(dt,{selectedNodes:o,paramTestValues:w,selectedParams:x,totalCount:K,completedCount:k,errorMessage:D,handleClose:ae,setIsProcessing:f,setCurrentScreen:h,cleanupPolling:xe})}):u===0?e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(lt,{selectedNodes:o,handleParamSelect:Re,selectedParams:x,handleNext:Le,handleClose:ae})}):u===1?e.jsxs("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:[e.jsx(it,{selectedNodes:o,paramTestValues:w,selectedParams:x,updateParamTestValues:ee,toggleDropdown:ze,openDropdowns:y,handleTestValueSelect:Fe,searchTerms:F,handleSearch:Ge,handleSelectAll:Ve,handleNext:Le,handlePrevious:fe,handleClose:ae,inputValues:m,setInputValues:E,textInputs:A,handleTextInputChange:De,handleAddTextInput:_e,handleRemoveTextInput:Ae,openAiWritingModal:Te}),e.jsx(ut,{visible:Q,aiWritingModalText:pe,setAiWritingModalText:ge,aiGeneratedTexts:ve,aiSelectedTexts:Se,aiWritingLoading:Ee,aiWritingError:$e,handleAiWriting:We,toggleTextSelection:Oe,addSelectedTexts:Be,onClose:()=>V(!1)})]}):e.jsx("div",{className:"flex-1 overflow-y-auto bg-gray-50 p-4",onClick:t=>t.stopPropagation(),children:e.jsx(ct,{selectedNodes:o,paramTestValues:w,selectedParams:x,totalCount:K,errorMessage:D,handlePrevious:fe,handleStartGeneration:He,handleClose:ae})})};export{vt as ParameterDebugInterface}; diff --git a/dist/copilot_web/input.js b/dist/copilot_web/input.js index 6efde2c..745a1b7 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-BKUkXtap.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-B3k4U96-.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-B3k4U96-.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-BKUkXtap.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-CCFLr34u.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-B3k4U96-.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-B3k4U96-.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-CCFLr34u.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-QHF8s17w.js b/dist/copilot_web/workflowChat-DFouB6P4.js similarity index 99% rename from dist/copilot_web/workflowChat-QHF8s17w.js rename to dist/copilot_web/workflowChat-DFouB6P4.js index 06e66ad..4aeedcf 100644 --- a/dist/copilot_web/workflowChat-QHF8s17w.js +++ b/dist/copilot_web/workflowChat-DFouB6P4.js @@ -1,5 +1,5 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/WorkflowOption-DDjIxht6.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-B3k4U96-.js","copilot_web/ParameterDebugInterfaceNew-BavknXdE.js","copilot_web/input.js","copilot_web/assets/input-CbVoR7-h.css","copilot_web/App-BKUkXtap.js"])))=>i.map(i=>d[i]); -import{_ as Dt}from"./input.js";import{j as h,r as xg,b as yg}from"./vendor-markdown-Dek94WS0.js";import{r as I,R as wn,c as Mt}from"./vendor-react-V04_Axys.js";import{f as wg,v as bg,a as sn,B as Sg,U as Ag,A as Ir,b as Eg,g as Ve,c as Pt,u as rs,M as Ig,W as Ot}from"./message-components-B3k4U96-.js";import{l as Cg}from"./App-BKUkXtap.js";/** +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/WorkflowOption-DDjIxht6.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-B3k4U96-.js","copilot_web/ParameterDebugInterfaceNew--d3dp9od.js","copilot_web/input.js","copilot_web/assets/input-CbVoR7-h.css","copilot_web/App-CCFLr34u.js"])))=>i.map(i=>d[i]); +import{_ as Dt}from"./input.js";import{j as h,r as xg,b as yg}from"./vendor-markdown-Dek94WS0.js";import{r as I,R as wn,c as Mt}from"./vendor-react-V04_Axys.js";import{f as wg,v as bg,a as sn,B as Sg,U as Ag,A as Ir,b as Eg,g as Ve,c as Pt,u as rs,M as Ig,W as Ot}from"./message-components-B3k4U96-.js";import{l as Cg}from"./App-CCFLr34u.js";/** * @license lucide-react v0.475.0 - ISC * * This source code is licensed under the ISC license. @@ -127,4 +127,4 @@ __p += '`),K&&(v+=`' + function print() { __p += __j.call(arguments, '') } `:`; `)+v+`return __p -}`;var W=Mo(function(){return X(u,S+"return "+v).apply(o,a)});if(W.source=v,Hi(W))throw W;return W}function I0(e){return J(e).toLowerCase()}function C0(e){return J(e).toUpperCase()}function N0(e,n,t){if(e=J(e),e&&(t||n===o))return Fs(e);if(!e||!(n=Fe(n)))return e;var r=en(e),i=en(n),u=js(r,i),a=zs(r,i)+1;return Mn(r,u,a).join("")}function L0(e,n,t){if(e=J(e),e&&(t||n===o))return e.slice(0,Ks(e)+1);if(!e||!(n=Fe(n)))return e;var r=en(e),i=zs(r,en(n))+1;return Mn(r,0,i).join("")}function R0(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=js(r,en(n));return Mn(r,i).join("")}function T0(e,n){var t=bn,r=Rr;if(ae(n)){var i="separator"in n?n.separator:i;t="length"in n?D(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(as.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 M0(e){return e=J(e),e&&zo.test(e)?e.replace(ss,ul):e}var O0=at(function(e,n,t){return e+(t?" ":"")+n.toUpperCase()}),Xi=Mu("toUpperCase");function To(e,n,t){return e=J(e),n=t?o:n,n===o?nl(e)?ll(e):Ha(e):e.match(n)||[]}var Mo=j(function(e,n){try{return Ue(e,o,n)}catch(t){return Hi(t)?t:new R(t)}}),D0=_n(function(e,n){return He(n,function(t){t=ln(t),gn(e,t,Ki(e[t],e))}),e});function P0(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(T);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=D(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||M(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,W=c&&!S;if(!u&&_){a=W?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&&W?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(M(u)?u:[],i)}return this[t](function(a){return n.apply(M(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=Tl,G.prototype.reverse=Ml,G.prototype.value=Ol,s.prototype.at=lh,s.prototype.chain=fh,s.prototype.commit=ch,s.prototype.next=hh,s.prototype.plant=gh,s.prototype.reverse=ph,s.prototype.toJSON=s.prototype.valueOf=s.prototype.value=_h,s.prototype.first=s.prototype.head,mt&&(s.prototype[mt]=dh),s},tt=fl();kn?((kn.exports=tt)._=tt,Qr._=tt):we._=tt}).call(Mt)})(Nr,Nr.exports);var Lr=Nr.exports;function rp(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 ip(m={},w=!0){const[o,O]=I.useState(!1),[U,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,P=Math.min(Math.max(m.minWidth||300,$),m.maxWidth||window.innerWidth*.8);return{...x,width:P}})},16),[o,m]);const T=I.useCallback(q=>{E(x=>{const $=x.height-q,P=x.top+q;return{...x,height:Math.min(Math.max(m.minHeight||300,$),m.maxHeight||window.innerHeight),top:Math.max(0,P)}})},[m]);return I.useEffect(()=>{if(!w||!o)return;const q=Lr.debounce($=>{E(P=>{const B=window.innerWidth-$.clientX,re=Math.min(Math.max(m.minWidth||300,B),m.maxWidth||window.innerWidth*.8);return{...P,width:re}})},16),x=()=>O(!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:O,dimensions:U,handleHeightResize:T}}function sp(m=!0){const{state:w,dispatch:o}=rs(),{activeTab:O,screenState:U}=w;I.useEffect(()=>{if(!m)return;const E=T=>{const q=O==="parameter-debug",x=O==="chat",$=!U||U.currentScreen===0;if(x||$&&q){const P=sn.canvas.selected_nodes;if(Object.keys(P??{}).length){const B=Object.values(P);o({type:"SET_SELECTED_NODE",payload:B})}else o({type:"SET_SELECTED_NODE",payload:null})}};return document.addEventListener("click",E),()=>{document.removeEventListener("click",E)}},[o,m,O,U])}const up=({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(Ig,{rehypePlugins:[[xg,{target:"_blank",rel:["noopener","noreferrer"]}]],remarkPlugins:[yg],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,...O})=>h.jsx("a",{...O,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,op=()=>{const{state:m,dispatch:w}=rs(),{selectedNode:o,screenState:O}=m,U=o||[],E=wn.lazy(()=>Dt(()=>import("./ParameterDebugInterfaceNew-BavknXdE.js"),__vite__mapDeps([4,1,2,3,5,6,7])).then(q=>({default:q.ParameterDebugInterface}))),T=()=>{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:U,visible:!0,onClose:T})})})},ko=({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 ap({onClose:m,visible:w=!0,triggerUsage:o=!1,onUsageTriggered:O}){const{state:U,dispatch:E}=rs(),{messages:T,installedNodes:q,loading:x,sessionId:$,selectedNode:P,activeTab:B}=U,re=I.useRef(null),[ie,pe]=I.useState(""),[F,k]=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);rp(w&&B==="chat"),sp(w);const{isResizing:is,setIsResizing:Wt,dimensions:dt,handleHeightResize:Tr}=ip({minWidth:300,maxWidth:window.innerWidth*.8,minHeight:300,maxHeight:window.innerHeight},w);I.useEffect(()=>{re.current&&(re.current.scrollTop=re.current.scrollHeight)},[T]),I.useEffect(()=>{if(B!=="chat")return;(async()=>{const Y=await tp();console.log("[WorkflowChat] Received installed nodes:",Y.length),E({type:"SET_INSTALLED_NODES",payload:Y})})()},[B]);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(B!=="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))},[B]);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()===""&&!P||!$)return;k(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=U.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}),k(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=U.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=U.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(!$||!P)return;E({type:"SET_LOADING",payload:!0});const ee=Ve(),Ae={id:Ve(),role:"user",content:P.comfyClass||P.type,trace_id:ee};E({type:"ADD_MESSAGE",payload:Ae});try{let un=Ve(),Ee=!0;for await(const V of Ot.streamInvokeServer($,P.comfyClass||P.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=U.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=>{U.sessionId&&localStorage.setItem(`messages_${U.sessionId}`,JSON.stringify(A))},Pn=A=>{console.log("[WorkflowChat] Adding new message:",A);const Y=[...U.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&&O&&B==="chat"&&(Dn("node_explain"),O())},[o,B]),I.useEffect(()=>{if(!w||B!=="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,B]);const Xn=()=>{kt(!1)},gt=A=>{E({type:"SET_ACTIVE_TAB",payload:A})},We=wn.useMemo(()=>h.jsx(op,{}),[]);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(Gg,{onClose:m,onClear:Dr,hasMessages:T.length>0,onHeightResize:Tr,title:"ComfyUI-Copilot"}),h.jsxs("div",{className:"flex border-b border-gray-200 mt-2",children:[h.jsx(ko,{active:B==="chat",onClick:()=>gt("chat"),children:"Chat"}),h.jsx(ko,{active:B==="parameter-debug",onClick:()=>gt("parameter-debug"),children:"GenLab"})]}),Rr&&_e&&B==="chat"&&h.jsx(up,{message:_e,onClose:Xn}),h.jsx("div",{className:"flex-1 overflow-y-auto p-4 scroll-smooth",style:{display:B==="chat"?"block":"none"},ref:re,children:h.jsx(ep,{messages:T,latestInput:F,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:B==="chat"?"block":"none"},children:[P&&h.jsx(qg,{nodeInfo:P,onSendWithIntent:Dn,loading:x,onSendWithContent:Mr}),h.jsx($g,{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:B==="parameter-debug"?"flex":"none"},children:We})]})]})}const mp=Object.freeze(Object.defineProperty({__proto__:null,default:ap},Symbol.toStringTag,{value:"Module"}));export{vp as g,_p as i,pp as m,gp as r,mp as w}; +}`;var W=Mo(function(){return X(u,S+"return "+v).apply(o,a)});if(W.source=v,Hi(W))throw W;return W}function I0(e){return J(e).toLowerCase()}function C0(e){return J(e).toUpperCase()}function N0(e,n,t){if(e=J(e),e&&(t||n===o))return Fs(e);if(!e||!(n=Fe(n)))return e;var r=en(e),i=en(n),u=js(r,i),a=zs(r,i)+1;return Mn(r,u,a).join("")}function L0(e,n,t){if(e=J(e),e&&(t||n===o))return e.slice(0,Ks(e)+1);if(!e||!(n=Fe(n)))return e;var r=en(e),i=zs(r,en(n))+1;return Mn(r,0,i).join("")}function R0(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=js(r,en(n));return Mn(r,i).join("")}function T0(e,n){var t=bn,r=Rr;if(ae(n)){var i="separator"in n?n.separator:i;t="length"in n?D(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(as.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 M0(e){return e=J(e),e&&zo.test(e)?e.replace(ss,ul):e}var O0=at(function(e,n,t){return e+(t?" ":"")+n.toUpperCase()}),Xi=Mu("toUpperCase");function To(e,n,t){return e=J(e),n=t?o:n,n===o?nl(e)?ll(e):Ha(e):e.match(n)||[]}var Mo=j(function(e,n){try{return Ue(e,o,n)}catch(t){return Hi(t)?t:new R(t)}}),D0=_n(function(e,n){return He(n,function(t){t=ln(t),gn(e,t,Ki(e[t],e))}),e});function P0(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(T);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=D(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||M(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,W=c&&!S;if(!u&&_){a=W?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&&W?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(M(u)?u:[],i)}return this[t](function(a){return n.apply(M(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=Tl,G.prototype.reverse=Ml,G.prototype.value=Ol,s.prototype.at=lh,s.prototype.chain=fh,s.prototype.commit=ch,s.prototype.next=hh,s.prototype.plant=gh,s.prototype.reverse=ph,s.prototype.toJSON=s.prototype.valueOf=s.prototype.value=_h,s.prototype.first=s.prototype.head,mt&&(s.prototype[mt]=dh),s},tt=fl();kn?((kn.exports=tt)._=tt,Qr._=tt):we._=tt}).call(Mt)})(Nr,Nr.exports);var Lr=Nr.exports;function rp(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 ip(m={},w=!0){const[o,O]=I.useState(!1),[U,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,P=Math.min(Math.max(m.minWidth||300,$),m.maxWidth||window.innerWidth*.8);return{...x,width:P}})},16),[o,m]);const T=I.useCallback(q=>{E(x=>{const $=x.height-q,P=x.top+q;return{...x,height:Math.min(Math.max(m.minHeight||300,$),m.maxHeight||window.innerHeight),top:Math.max(0,P)}})},[m]);return I.useEffect(()=>{if(!w||!o)return;const q=Lr.debounce($=>{E(P=>{const B=window.innerWidth-$.clientX,re=Math.min(Math.max(m.minWidth||300,B),m.maxWidth||window.innerWidth*.8);return{...P,width:re}})},16),x=()=>O(!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:O,dimensions:U,handleHeightResize:T}}function sp(m=!0){const{state:w,dispatch:o}=rs(),{activeTab:O,screenState:U}=w;I.useEffect(()=>{if(!m)return;const E=T=>{const q=O==="parameter-debug",x=O==="chat",$=!U||U.currentScreen===0;if(x||$&&q){const P=sn.canvas.selected_nodes;if(Object.keys(P??{}).length){const B=Object.values(P);o({type:"SET_SELECTED_NODE",payload:B})}else o({type:"SET_SELECTED_NODE",payload:null})}};return document.addEventListener("click",E),()=>{document.removeEventListener("click",E)}},[o,m,O,U])}const up=({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(Ig,{rehypePlugins:[[xg,{target:"_blank",rel:["noopener","noreferrer"]}]],remarkPlugins:[yg],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,...O})=>h.jsx("a",{...O,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,op=()=>{const{state:m,dispatch:w}=rs(),{selectedNode:o,screenState:O}=m,U=o||[],E=wn.lazy(()=>Dt(()=>import("./ParameterDebugInterfaceNew--d3dp9od.js"),__vite__mapDeps([4,1,2,3,5,6,7])).then(q=>({default:q.ParameterDebugInterface}))),T=()=>{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:U,visible:!0,onClose:T})})})},ko=({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 ap({onClose:m,visible:w=!0,triggerUsage:o=!1,onUsageTriggered:O}){const{state:U,dispatch:E}=rs(),{messages:T,installedNodes:q,loading:x,sessionId:$,selectedNode:P,activeTab:B}=U,re=I.useRef(null),[ie,pe]=I.useState(""),[F,k]=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);rp(w&&B==="chat"),sp(w);const{isResizing:is,setIsResizing:Wt,dimensions:dt,handleHeightResize:Tr}=ip({minWidth:300,maxWidth:window.innerWidth*.8,minHeight:300,maxHeight:window.innerHeight},w);I.useEffect(()=>{re.current&&(re.current.scrollTop=re.current.scrollHeight)},[T]),I.useEffect(()=>{if(B!=="chat")return;(async()=>{const Y=await tp();console.log("[WorkflowChat] Received installed nodes:",Y.length),E({type:"SET_INSTALLED_NODES",payload:Y})})()},[B]);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(B!=="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))},[B]);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()===""&&!P||!$)return;k(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=U.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}),k(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=U.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=U.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(!$||!P)return;E({type:"SET_LOADING",payload:!0});const ee=Ve(),Ae={id:Ve(),role:"user",content:P.comfyClass||P.type,trace_id:ee};E({type:"ADD_MESSAGE",payload:Ae});try{let un=Ve(),Ee=!0;for await(const V of Ot.streamInvokeServer($,P.comfyClass||P.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=U.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=>{U.sessionId&&localStorage.setItem(`messages_${U.sessionId}`,JSON.stringify(A))},Pn=A=>{console.log("[WorkflowChat] Adding new message:",A);const Y=[...U.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&&O&&B==="chat"&&(Dn("node_explain"),O())},[o,B]),I.useEffect(()=>{if(!w||B!=="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,B]);const Xn=()=>{kt(!1)},gt=A=>{E({type:"SET_ACTIVE_TAB",payload:A})},We=wn.useMemo(()=>h.jsx(op,{}),[]);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(Gg,{onClose:m,onClear:Dr,hasMessages:T.length>0,onHeightResize:Tr,title:"ComfyUI-Copilot"}),h.jsxs("div",{className:"flex border-b border-gray-200 mt-2",children:[h.jsx(ko,{active:B==="chat",onClick:()=>gt("chat"),children:"Chat"}),h.jsx(ko,{active:B==="parameter-debug",onClick:()=>gt("parameter-debug"),children:"GenLab"})]}),Rr&&_e&&B==="chat"&&h.jsx(up,{message:_e,onClose:Xn}),h.jsx("div",{className:"flex-1 overflow-y-auto p-4 scroll-smooth",style:{display:B==="chat"?"block":"none"},ref:re,children:h.jsx(ep,{messages:T,latestInput:F,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:B==="chat"?"block":"none"},children:[P&&h.jsx(qg,{nodeInfo:P,onSendWithIntent:Dn,loading:x,onSendWithContent:Mr}),h.jsx($g,{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:B==="parameter-debug"?"flex":"none"},children:We})]})]})}const mp=Object.freeze(Object.defineProperty({__proto__:null,default:ap},Symbol.toStringTag,{value:"Module"}));export{vp as g,_p as i,pp as m,gp as r,mp as w}; diff --git a/ui/src/components/debug/ParameterDebugInterfaceNew.tsx b/ui/src/components/debug/ParameterDebugInterfaceNew.tsx index 364add6..ea3e141 100644 --- a/ui/src/components/debug/ParameterDebugInterfaceNew.tsx +++ b/ui/src/components/debug/ParameterDebugInterfaceNew.tsx @@ -380,9 +380,34 @@ export const ParameterDebugInterface: React.FC = ( setParamTestValues(updatedParamTestValues); } - // 如果要从屏幕 1 进入屏幕 2,更新 totalCount + // When moving to the confirmation screen, ensure all text values are properly synchronized if (currentScreen === 1) { - const combinations = generateParameterCombinations(paramTestValues); + // Ensure textInputs are synced to paramTestValues for all selected nodes + const updatedParamTestValues = { ...paramTestValues }; + selectedNodes.forEach(node => { + const nodeId = node.id.toString(); + const widgets = node.widgets || {}; + + Object.values(widgets).forEach((widget: any) => { + const paramName = widget.name; + + // Only process selected text parameters + if (selectedParams[paramName] && (widget.type === "customtext" || widget.type.toLowerCase().includes("text"))) { + const inputKey = `${nodeId}_${paramName}`; + const currentTexts = textInputs[inputKey] || ['']; + + // Update paramTestValues with the current text values + updatedParamTestValues[nodeId] = updatedParamTestValues[nodeId] || {}; + updatedParamTestValues[nodeId][paramName] = currentTexts; + } + }); + }); + + // Update the state with synchronized values + setParamTestValues(updatedParamTestValues); + + // Update totalCount with parameter combinations + const combinations = generateParameterCombinations(updatedParamTestValues); setTotalCount(combinations.length); } @@ -420,6 +445,32 @@ export const ParameterDebugInterface: React.FC = ( setParamTestValues(updatedParamTestValues); } + // If returning from the result gallery or confirmation screen, ensure text values are maintained + if (currentScreen === 2 || isCompleted) { + // Ensure paramTestValues are correctly synchronized with textInputs + const updatedParamTestValues = { ...paramTestValues }; + + // For each text input value, ensure it's properly synced to paramTestValues + Object.entries(textInputs).forEach(([key, texts]) => { + if (!texts || texts.length === 0) return; + + const [nodeId, paramName] = key.split('_'); + + // Skip if node doesn't exist in selected nodes + if (!selectedNodes.some(node => node.id.toString() === nodeId)) return; + + // Ensure the node and parameter exist in paramTestValues + updatedParamTestValues[nodeId] = updatedParamTestValues[nodeId] || {}; + + // Only update if the values are different to avoid unnecessary state updates + if (JSON.stringify(updatedParamTestValues[nodeId][paramName]) !== JSON.stringify(texts)) { + updatedParamTestValues[nodeId][paramName] = texts; + } + }); + + setParamTestValues(updatedParamTestValues); + } + setCurrentScreen(prev => Math.max(prev - 1, 0)); }; @@ -942,6 +993,7 @@ export const ParameterDebugInterface: React.FC = ( setNotificationVisible(false); setModalVisible(false); setModalImageUrl(''); + // Completely reset text inputs to ensure clean state on next run setTextInputs({}); setAiWritingModalVisible(false); setAiWritingModalText(''); diff --git a/ui/src/components/debug/screens/ConfigureParameterScreen.tsx b/ui/src/components/debug/screens/ConfigureParameterScreen.tsx index 510d665..f5a344a 100644 --- a/ui/src/components/debug/screens/ConfigureParameterScreen.tsx +++ b/ui/src/components/debug/screens/ConfigureParameterScreen.tsx @@ -125,11 +125,15 @@ export const ConfigureParameterScreen: React.FC = } } - // Initialize text inputs if they're empty - if (!hasValues && (widget.type === "customtext" || widget.type.toLowerCase().includes("text"))) { + // Handle text inputs - Always ensure paramTestValues are in sync with textInputs + if ((widget.type === "customtext" || widget.type.toLowerCase().includes("text"))) { const inputKey = `${nodeId}_${paramName}`; - if (!textInputs[inputKey] || textInputs[inputKey].length === 0) { - updateParamTestValues(nodeId, paramName, ['']); + const currentTexts = textInputs[inputKey] || ['']; + + // Always update paramTestValues with current textInputs to ensure they're in sync + // This ensures text values are maintained throughout the workflow + if (JSON.stringify(currentTexts) !== JSON.stringify(paramTestValues[nodeId]?.[paramName] || [''])) { + updateParamTestValues(nodeId, paramName, currentTexts); } } });