5 lines
7.5 KiB
JavaScript
5 lines
7.5 KiB
JavaScript
function getImportPath(filename) {
|
|
return `./${filename}`;
|
|
}
|
|
import{j as t}from"./vendor-markdown-B4Av9P7l.js";import{D as B,W as v,o as C,a as d}from"./message-components-BfFC5qK_.js";import{r as h}from"./vendor-react-ByKzdfMq.js";import{A as D}from"./workflowChat-G2xZMDxn.js";import"./input.js";/* empty css */import"./App-Bb0WElxf.js";function Y({content:_,name:G="Assistant",avatar:J,latestInput:z,installedNodes:N,onAddMessage:y}){const[f,g]=h.useState({}),[A,E]=h.useState(null),[b,W]=h.useState([]);h.useEffect(()=>{const e=JSON.parse(_);E(e),W(e.ext?.find(a=>a.type==="workflow")?.data||[])},[_]);const M=async e=>{if(!e.id){console.error("No workflow id provided");return}const a=String(e.id);if(!f[a]){g(o=>({...o,[a]:!0})),v.trackEvent({event_type:"workflow_accept",message_type:"workflow",message_id:A?.message_id,data:{workflow_id:e.id,workflow_name:e.name}}),window.dispatchEvent(new CustomEvent(D,{}));try{const o=await v.getOptimizedWorkflow(e.id,z);if(o.workflow){const i=new Set;if(o.workflow.nodes)for(const s of o.workflow.nodes)i.add(s.type);else for(const s of Object.values(o.workflow))i.add(s.class_type);const r=Array.from(i).filter(s=>!N.includes(s));if(console.log("[WorkflowOption] Missing node types:",r),r.length>0){try{console.log("[WorkflowOption] Fetching info for missing nodes");const s=await v.batchGetNodeInfo(r);console.log("[WorkflowOption] Received node infos:",s);const p={text:"",ext:[{type:"node_install_guide",data:s.map(l=>({name:l.name,repository_url:l.github_url}))}]},c={id:C(),role:"ai",content:JSON.stringify(p),format:"markdown",name:"Assistant",metadata:{pendingWorkflow:o.workflow,optimizedParams:o.optimized_params}};y?.(c)}catch(s){console.error("[WorkflowOption] Error fetching node info:",s),alert("Error checking required nodes. Please try again.")}finally{g(s=>({...s,[a]:!1}))}return}I(o.workflow,o.optimized_params)}}catch(o){console.error("Failed to optimize workflow:",o),alert("Failed to optimize workflow. Please try again.")}finally{g(o=>({...o,[a]:!1}))}}},I=(e,a)=>{if(e.nodes)d.loadGraphData(e);else{d.loadApiJson(e);const i=Object.keys(e),r=Object.keys(d.graph._nodes_by_id)[0],s=d.graph._nodes_by_id[r],p=s?s.pos[0]:0,c=s?s.pos[1]:0,l=250,m=60,S=20,F=60,j=50,H=1e3;let k=p,x=c,w=0;for(const T of i){const n=d.graph._nodes_by_id[T];if(n){w>H&&(k+=l+F,w=0,x=c);const V=n.inputs?n.inputs.length:0,q=n.outputs?n.outputs.length:0,L=n.widgets?n.widgets.length:0,P=Math.max(V,q)+L,u=S*P+m;n.size[0]=l,n.size[1]=u,n.pos[0]=k,n.pos[1]=x,w+=u+j,x+=u+j}}}for(const[i,r,s,p,c]of a){const l=d.graph._nodes_by_id[i].widgets;for(const m of l)m.name===p&&(m.value=c)}d.graph.setDirtyCanvas(!1,!0);const o={id:C(),role:"tool",content:JSON.stringify({text:"The workflow has been successfully loaded to the canvas",ext:[]}),format:"markdown",name:"Assistant"};y?.(o)},O=(e,a)=>{const o=e.id?String(e.id):"",i=e?.source==="AI Generated";return t.jsxs("div",{className:`relative flex flex-col items-center gap-4 p-2 rounded-lg border ${i?"shadow-[0_0_12px_2px_#3b82f6] shadow-[0_0_0_4px_rgba(59,130,246,0.15)]":"border-gray-200"} hover:bg-gray-50`,children:[i&&t.jsx("div",{className:"absolute left-1/2 top-[-12px] -translate-x-1/2 rounded-lg flex bg-white",children:t.jsxs("svg",{viewBox:"0 0 1024 1024",version:"1.1",xmlns:"http://www.w3.org/2000/svg","p-id":"25237",width:"24",height:"24",children:[t.jsx("path",{d:"M938.656 256A170.656 170.656 0 0 0 768 85.344H256A170.656 170.656 0 0 0 85.344 256v512A170.656 170.656 0 0 0 256 938.656h512A170.656 170.656 0 0 0 938.656 768V256zM256 170.656h512l6.368 0.256A85.344 85.344 0 0 1 853.312 256v512l-0.224 6.4A85.344 85.344 0 0 1 768 853.312H256l-6.336-0.256A85.344 85.344 0 0 1 170.656 768V256l0.224-6.368A85.344 85.344 0 0 1 256 170.656z","p-id":"25238",fill:"#1296db"}),t.jsx("path",{d:"M633.12 718.464h-95.392l-34.368-95.68h-160.288l-34.336 95.68H213.344l154.56-419.808h110.656l154.56 419.808z m-209.888-333.888l-61.056 177.696h120.192l-59.136-177.696z","p-id":"25239",fill:"#1296db"}),t.jsx("path",{d:"M682.656 298.656m0 0l85.344 0q0 0 0 0l0 426.656q0 0 0 0l-85.344 0q0 0 0 0l0-426.656q0 0 0 0Z","p-id":"25240",fill:"#1296db"})]})}),t.jsxs("div",{className:"flex flex-row",children:[t.jsx("h3",{className:"flex-1 font-medium text-sm line-clamp-2 break-all h-10 overflow-hidden",children:e.name}),t.jsx("div",{className:"flex items-start",children:e.description&&t.jsx(B,{arrow:!1,placement:"top",title:t.jsx("div",{className:"bg-gray-900 text-white text-xs rounded-md py-2 px-3 min-w-[400px] whitespace-normal break-words",children:e.description}),children:t.jsx("div",{className:"w-5 h-5 flex items-center justify-center text-gray-500 cursor-help",children:t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",className:"w-4 h-4",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9.879 7.519c1.171-1.025 3.071-1.025 4.242 0 1.172 1.025 1.172 2.687 0 3.712-.203.179-.43.326-.67.442-.745.361-1.45.999-1.45 1.827v.75M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9 5.25h.008v.008H12v-.008z"})})})})})]}),t.jsx("div",{className:"aspect-[3/4] rounded-lg overflow-hidden flex-1 w-full",children:e.image?t.jsx("img",{src:e.image,alt:e.name,className:"w-full h-full object-cover",onError:r=>{const s=r.target;s.onerror=null,s.src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56' fill='none'%3E%3Crect width='56' height='56' fill='%23F3F4F6'/%3E%3Cpath d='M28 28C30.2091 28 32 26.2091 32 24C32 21.7909 30.2091 20 28 20C25.7909 20 24 21.7909 24 24C24 26.2091 25.7909 28 28 28Z' fill='%239CA3AF'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M18.7253 37.6307C19.8278 35.1533 22.6897 33.6 26 33.6H30C33.3103 33.6 36.1722 35.1533 37.2747 37.6307C37.6419 38.4561 37.0611 39.2 36.1694 39.2H19.8306C18.9389 39.2 18.3581 38.4561 18.7253 37.6307Z' fill='%239CA3AF'/%3E%3C/svg%3E"}}):t.jsx("div",{className:"w-full h-full flex items-center justify-center",children:t.jsxs("svg",{viewBox:"0 0 1026 1024",version:"1.1",xmlns:"http://www.w3.org/2000/svg","p-id":"1875",width:"98",height:"98",children:[t.jsx("path",{d:"M0.003166 0v1024h1024V0H0.003166z m962.692789 61.286783v566.902743l-120.857537-118.426494-186.638683 137.466255-287.435012-237.138993L61.28995 705.410873V61.286783h901.406005zM61.28995 962.692788v-172.195431l309.661685-298.34406 282.164349 232.746773 183.104479-134.89221 126.49592 123.962734v248.722194H61.28995z",fill:"#8a8a8a","p-id":"1876"}),t.jsx("path",{d:"M757.03794 397.199641h0.960159c63.411392 0 118.263062-53.605506 119.733945-117.057756 1.470883-63.901686-51.337895-119.958663-115.321296-122.410134l-4.330933-0.081716c-31.011112 0-61.817935 13.1358-84.555332 36.016199-22.635252 22.819112-35.505476 53.666793-35.301187 84.616619 0.490294 63.942544 54.892529 118.406065 118.814644 118.916788z m-39.999841-160.346653a59.570753 59.570753 0 0 1 42.900748-17.875312h0.143003c30.214384 1.164449 57.098853 29.621945 56.38384 59.734184-0.694584 30.47996-28.00806 57.200998-58.447162 57.200998v30.643391l-0.449436-30.643391c-30.132668-0.245147-57.773007-27.926344-57.997726-58.079442-0.122574-14.749686 6.230823-29.683232 17.466733-40.980428z",fill:"#8a8a8a","p-id":"1877"})]})})}),t.jsx("button",{onClick:()=>M(e),disabled:f[o],className:`w-full px-3 py-1 ${f[o]?"bg-[#d2d2d2] cursor-not-allowed":"bg-[#ffffff] hover:bg-[#eee]"} text-black rounded-lg text-xs`,children:f[o]?"Loading...":"Accept"})]},a)};return t.jsx("div",{className:"space-y-3 flex justify-center",children:b.length>0&&t.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(120px,1fr))] gap-4",children:b.map((e,a)=>O(e,a))})})}export{Y as WorkflowOption};
|