From aa2964c952bcb2559d4dbdfafe87cfeeaf8fd48b Mon Sep 17 00:00:00 2001 From: ai-business-hql Date: Tue, 11 Mar 2025 20:36:37 +0800 Subject: [PATCH] feat: delete apikey control. --- .../{App-PpJX3mvb.js => App-BjVABi7E.js} | 4 ++-- ...tion-CsptvFbJ.js => WorkflowOption-BSTBilSm.js} | 2 +- dist/copilot_web/input.js | 4 ++-- ...-cqAuXss9.js => message-components-B6pkQvDp.js} | 3 +-- ...owChat-CKaW90Rp.js => workflowChat-CnVi6gIQ.js} | 6 +++--- ui/src/apis/workflowChatApi.ts | 14 +++++++------- 6 files changed, 16 insertions(+), 17 deletions(-) rename dist/copilot_web/{App-PpJX3mvb.js => App-BjVABi7E.js} (91%) rename dist/copilot_web/{WorkflowOption-CsptvFbJ.js => WorkflowOption-BSTBilSm.js} (98%) rename dist/copilot_web/{message-components-cqAuXss9.js => message-components-B6pkQvDp.js} (99%) rename dist/copilot_web/{workflowChat-CKaW90Rp.js => workflowChat-CnVi6gIQ.js} (99%) diff --git a/dist/copilot_web/App-PpJX3mvb.js b/dist/copilot_web/App-BjVABi7E.js similarity index 91% rename from dist/copilot_web/App-PpJX3mvb.js rename to dist/copilot_web/App-BjVABi7E.js index a942f93..052b616 100644 --- a/dist/copilot_web/App-PpJX3mvb.js +++ b/dist/copilot_web/App-BjVABi7E.js @@ -1,6 +1,6 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/workflowChat-CKaW90Rp.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-cqAuXss9.js","copilot_web/input.js","copilot_web/assets/input-CJq8z6H1.css"].map(path => { +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/workflowChat-CnVi6gIQ.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-B6pkQvDp.js","copilot_web/input.js","copilot_web/assets/input-CJq8z6H1.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 t,R as w}from"./vendor-react-V04_Axys.js";import{C as v}from"./message-components-cqAuXss9.js";const y=9999999,x={EXPLAIN_NODE:"copilot:explain-node"},D="/copilot_web/assets/logo-BTZhX0BN.png";function _(n={}){const[u,l]=t.useState({x:n.initialX??window.innerWidth-160,y:n.initialY??20}),[o,r]=t.useState(!1),[a,m]=t.useState({x:0,y:0}),[d,c]=t.useState(0),[g,b]=t.useState({x:0,y:0}),f=t.useCallback(e=>{if(o){const i=Math.min(Math.max(0,e.clientX-g.x),window.innerWidth-(n.boundaryPadding?.right??100)),h=Math.min(Math.max(0,e.clientY-g.y),window.innerHeight-(n.boundaryPadding?.bottom??40));l({x:i,y:h})}},[o,g,n.boundaryPadding]),p=t.useCallback(e=>{if(o){const i=Math.sqrt(Math.pow(e.clientX-a.x,2)+Math.pow(e.clientY-a.y,2)),h=Date.now()-d;i<5&&h<200&&n.onClick?.()}r(!1)},[o,a,d,n.onClick]);return t.useEffect(()=>(o&&(document.addEventListener("mousemove",f),document.addEventListener("mouseup",p)),()=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",p)}),[o,f,p]),{position:u,isDragging:o,handleMouseDown:e=>{e.preventDefault(),r(!0),c(Date.now()),m({x:e.clientX,y:e.clientY});const i=e.currentTarget.getBoundingClientRect();b({x:e.clientX-i.left,y:e.clientY-i.top})}}}const C=w.lazy(()=>E(()=>import("./workflowChat-CKaW90Rp.js"),__vite__mapDeps([0,1,2,3,4,5])).then(n=>({default:n.default})));function M(){const n=t.useRef(null),[u,l]=t.useState(!1),[o,r]=t.useState(!1),{position:a,isDragging:m,handleMouseDown:d}=_({boundaryPadding:{right:100,bottom:40},onClick:()=>l(!0)});return t.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:n,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 t,R as w}from"./vendor-react-V04_Axys.js";import{C as v}from"./message-components-B6pkQvDp.js";const y=9999999,x={EXPLAIN_NODE:"copilot:explain-node"},D="/copilot_web/assets/logo-BTZhX0BN.png";function _(n={}){const[u,l]=t.useState({x:n.initialX??window.innerWidth-160,y:n.initialY??20}),[o,r]=t.useState(!1),[a,m]=t.useState({x:0,y:0}),[d,c]=t.useState(0),[g,b]=t.useState({x:0,y:0}),f=t.useCallback(e=>{if(o){const i=Math.min(Math.max(0,e.clientX-g.x),window.innerWidth-(n.boundaryPadding?.right??100)),h=Math.min(Math.max(0,e.clientY-g.y),window.innerHeight-(n.boundaryPadding?.bottom??40));l({x:i,y:h})}},[o,g,n.boundaryPadding]),p=t.useCallback(e=>{if(o){const i=Math.sqrt(Math.pow(e.clientX-a.x,2)+Math.pow(e.clientY-a.y,2)),h=Date.now()-d;i<5&&h<200&&n.onClick?.()}r(!1)},[o,a,d,n.onClick]);return t.useEffect(()=>(o&&(document.addEventListener("mousemove",f),document.addEventListener("mouseup",p)),()=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",p)}),[o,f,p]),{position:u,isDragging:o,handleMouseDown:e=>{e.preventDefault(),r(!0),c(Date.now()),m({x:e.clientX,y:e.clientY});const i=e.currentTarget.getBoundingClientRect();b({x:e.clientX-i.left,y:e.clientY-i.top})}}}const C=w.lazy(()=>E(()=>import("./workflowChat-CnVi6gIQ.js"),__vite__mapDeps([0,1,2,3,4,5])).then(n=>({default:n.default})));function M(){const n=t.useRef(null),[u,l]=t.useState(!1),[o,r]=t.useState(!1),{position:a,isDragging:m,handleMouseDown:d}=_({boundaryPadding:{right:100,bottom:40},onClick:()=>l(!0)});return t.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:n,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/WorkflowOption-CsptvFbJ.js b/dist/copilot_web/WorkflowOption-BSTBilSm.js similarity index 98% rename from dist/copilot_web/WorkflowOption-CsptvFbJ.js rename to dist/copilot_web/WorkflowOption-BSTBilSm.js index b24886d..6fdf63f 100644 --- a/dist/copilot_web/WorkflowOption-CsptvFbJ.js +++ b/dist/copilot_web/WorkflowOption-BSTBilSm.js @@ -1 +1 @@ -import{j as t}from"./vendor-markdown-Dek94WS0.js";import{W as f,g as u,a as p}from"./message-components-cqAuXss9.js";import{r as N}from"./vendor-react-V04_Axys.js";function z({content:v,name:C="Assistant",avatar:_,latestInput:y,installedNodes:k,onAddMessage:g}){const h=JSON.parse(v),w=h.ext?.find(e=>e.type==="workflow")?.data||[],[i,d]=N.useState({}),b=async e=>{if(!e.id){console.error("No workflow id provided");return}const r=String(e.id);if(!i[r]){d(o=>({...o,[r]:!0})),f.trackEvent({event_type:"workflow_accept",message_type:"workflow",message_id:h.message_id,data:{workflow_id:e.id,workflow_name:e.name}});try{const o=await f.getOptimizedWorkflow(e.id,y);if(o.workflow){const n=new Set;for(const s of o.workflow.nodes)n.add(s.type);const a=Array.from(n).filter(s=>!k.includes(s));if(console.log("[WorkflowOption] Missing node types:",a),a.length>0){try{console.log("[WorkflowOption] Fetching info for missing nodes");const s=await f.batchGetNodeInfo(a);console.log("[WorkflowOption] Received node infos:",s);const c={text:"",ext:[{type:"node_install_guide",data:s.map(l=>({name:l.name,repository_url:l.github_url}))}]},m={id:u(),role:"ai",content:JSON.stringify(c),format:"markdown",name:"Assistant",metadata:{pendingWorkflow:o.workflow,optimizedParams:o.optimized_params}};g?.(m)}catch(s){console.error("[WorkflowOption] Error fetching node info:",s),alert("Error checking required nodes. Please try again.")}finally{d(s=>({...s,[r]:!1}))}return}j(o.workflow,o.optimized_params)}}catch(o){console.error("Failed to optimize workflow:",o),alert("Failed to optimize workflow. Please try again.")}finally{d(o=>({...o,[r]:!1}))}}},j=(e,r)=>{p.loadGraphData(e);for(const[n,a,s,c,m]of r){const l=p.graph._nodes_by_id[n].widgets;for(const x of l)x.name===c&&(x.value=m)}p.graph.setDirtyCanvas(!1,!0);const o={id:u(),role:"tool",content:JSON.stringify({text:"The workflow has been successfully loaded to the canvas",ext:[]}),format:"markdown",name:"Assistant"};g?.(o)};return t.jsx("div",{className:"space-y-3",children:w.length>0&&t.jsx("div",{className:"flex flex-col space-y-4",children:w.map((e,r)=>{const o=e.id?String(e.id):"";return t.jsxs("div",{className:"flex items-center gap-4 p-4 rounded-lg border border-gray-200 hover:bg-gray-50",children:[e.image&&t.jsx("img",{src:e.image,alt:e.name,className:"w-14 h-14 object-cover rounded-lg",onError:n=>{const a=n.target;a.onerror=null,a.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.jsxs("div",{className:"flex-1 break-words flex flex-col h-[4.5rem] justify-between",children:[t.jsx("div",{children:t.jsx("h3",{className:"font-medium text-sm line-clamp-2 h-10 overflow-hidden",children:e.name})}),t.jsxs("div",{className:"flex justify-between items-center mt-1",children:[e.description&&t.jsxs("div",{className:"relative group",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:"absolute bottom-full left-0 mb-2 hidden group-hover:block",children: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})})]}),t.jsx("button",{onClick:()=>b(e),disabled:i[o],className:`px-3 py-1.5 ${i[o]?"bg-gray-400 cursor-not-allowed":"bg-blue-500 hover:bg-blue-600"} text-white rounded-md transition-colors text-xs`,children:i[o]?"Loading...":"Accept"})]})]})]},r)})})})}export{z as WorkflowOption}; +import{j as t}from"./vendor-markdown-Dek94WS0.js";import{W as f,g as u,a as p}from"./message-components-B6pkQvDp.js";import{r as N}from"./vendor-react-V04_Axys.js";function z({content:v,name:C="Assistant",avatar:_,latestInput:y,installedNodes:k,onAddMessage:g}){const h=JSON.parse(v),w=h.ext?.find(e=>e.type==="workflow")?.data||[],[i,d]=N.useState({}),b=async e=>{if(!e.id){console.error("No workflow id provided");return}const r=String(e.id);if(!i[r]){d(o=>({...o,[r]:!0})),f.trackEvent({event_type:"workflow_accept",message_type:"workflow",message_id:h.message_id,data:{workflow_id:e.id,workflow_name:e.name}});try{const o=await f.getOptimizedWorkflow(e.id,y);if(o.workflow){const n=new Set;for(const s of o.workflow.nodes)n.add(s.type);const a=Array.from(n).filter(s=>!k.includes(s));if(console.log("[WorkflowOption] Missing node types:",a),a.length>0){try{console.log("[WorkflowOption] Fetching info for missing nodes");const s=await f.batchGetNodeInfo(a);console.log("[WorkflowOption] Received node infos:",s);const c={text:"",ext:[{type:"node_install_guide",data:s.map(l=>({name:l.name,repository_url:l.github_url}))}]},m={id:u(),role:"ai",content:JSON.stringify(c),format:"markdown",name:"Assistant",metadata:{pendingWorkflow:o.workflow,optimizedParams:o.optimized_params}};g?.(m)}catch(s){console.error("[WorkflowOption] Error fetching node info:",s),alert("Error checking required nodes. Please try again.")}finally{d(s=>({...s,[r]:!1}))}return}j(o.workflow,o.optimized_params)}}catch(o){console.error("Failed to optimize workflow:",o),alert("Failed to optimize workflow. Please try again.")}finally{d(o=>({...o,[r]:!1}))}}},j=(e,r)=>{p.loadGraphData(e);for(const[n,a,s,c,m]of r){const l=p.graph._nodes_by_id[n].widgets;for(const x of l)x.name===c&&(x.value=m)}p.graph.setDirtyCanvas(!1,!0);const o={id:u(),role:"tool",content:JSON.stringify({text:"The workflow has been successfully loaded to the canvas",ext:[]}),format:"markdown",name:"Assistant"};g?.(o)};return t.jsx("div",{className:"space-y-3",children:w.length>0&&t.jsx("div",{className:"flex flex-col space-y-4",children:w.map((e,r)=>{const o=e.id?String(e.id):"";return t.jsxs("div",{className:"flex items-center gap-4 p-4 rounded-lg border border-gray-200 hover:bg-gray-50",children:[e.image&&t.jsx("img",{src:e.image,alt:e.name,className:"w-14 h-14 object-cover rounded-lg",onError:n=>{const a=n.target;a.onerror=null,a.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.jsxs("div",{className:"flex-1 break-words flex flex-col h-[4.5rem] justify-between",children:[t.jsx("div",{children:t.jsx("h3",{className:"font-medium text-sm line-clamp-2 h-10 overflow-hidden",children:e.name})}),t.jsxs("div",{className:"flex justify-between items-center mt-1",children:[e.description&&t.jsxs("div",{className:"relative group",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:"absolute bottom-full left-0 mb-2 hidden group-hover:block",children: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})})]}),t.jsx("button",{onClick:()=>b(e),disabled:i[o],className:`px-3 py-1.5 ${i[o]?"bg-gray-400 cursor-not-allowed":"bg-blue-500 hover:bg-blue-600"} text-white rounded-md transition-colors text-xs`,children:i[o]?"Loading...":"Accept"})]})]})]},r)})})})}export{z as WorkflowOption}; diff --git a/dist/copilot_web/input.js b/dist/copilot_web/input.js index f6db2e5..e6c4492 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-PpJX3mvb.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-cqAuXss9.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-cqAuXss9.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-PpJX3mvb.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-BjVABi7E.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-B6pkQvDp.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-B6pkQvDp.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-BjVABi7E.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/message-components-cqAuXss9.js b/dist/copilot_web/message-components-B6pkQvDp.js similarity index 99% rename from dist/copilot_web/message-components-cqAuXss9.js rename to dist/copilot_web/message-components-B6pkQvDp.js index 0e17769..05afd67 100644 --- a/dist/copilot_web/message-components-cqAuXss9.js +++ b/dist/copilot_web/message-components-B6pkQvDp.js @@ -23,8 +23,7 @@ version: 2.9.0 `;return e+=r.wordwrap(this.getPrivateBaseKeyB64())+` `,e+="-----END RSA PRIVATE KEY-----",e},r.prototype.getPublicKey=function(){var e=`-----BEGIN PUBLIC KEY----- `;return e+=r.wordwrap(this.getPublicBaseKeyB64())+` -`,e+="-----END PUBLIC KEY-----",e},r.hasPublicKeyProperty=function(e){return e=e||{},e.hasOwnProperty("n")&&e.hasOwnProperty("e")},r.hasPrivateKeyProperty=function(e){return e=e||{},e.hasOwnProperty("n")&&e.hasOwnProperty("e")&&e.hasOwnProperty("d")&&e.hasOwnProperty("p")&&e.hasOwnProperty("q")&&e.hasOwnProperty("dmp1")&&e.hasOwnProperty("dmq1")&&e.hasOwnProperty("coeff")},r.prototype.parsePropertiesFrom=function(e){this.n=e.n,this.e=e.e,e.hasOwnProperty("d")&&(this.d=e.d,this.p=e.p,this.q=e.q,this.dmp1=e.dmp1,this.dmq1=e.dmq1,this.coeff=e.coeff)},r}(OI),xI={},ah,CI=typeof process<"u"?(ah=xI)===null||ah===void 0?void 0:ah.npm_package_version:void 0,AI=function(){function i(r){r===void 0&&(r={}),r=r||{},this.default_key_size=r.default_key_size?parseInt(r.default_key_size,10):1024,this.default_public_exponent=r.default_public_exponent||"010001",this.log=r.log||!1,this.key=null}return i.prototype.setKey=function(r){this.log&&this.key&&console.warn("A key was already set, overriding existing."),this.key=new Ip(r)},i.prototype.setPrivateKey=function(r){this.setKey(r)},i.prototype.setPublicKey=function(r){this.setKey(r)},i.prototype.decrypt=function(r){try{return this.getKey().decrypt($p(r))}catch{return!1}},i.prototype.encrypt=function(r){try{return Tu(this.getKey().encrypt(r))}catch{return!1}},i.prototype.sign=function(r,e,t){try{return Tu(this.getKey().sign(r,e,t))}catch{return!1}},i.prototype.verify=function(r,e,t){try{return this.getKey().verify(r,$p(e),t)}catch{return!1}},i.prototype.getKey=function(r){if(!this.key){if(this.key=new Ip,r&&{}.toString.call(r)==="[object Function]"){this.key.generateAsync(this.default_key_size,this.default_public_exponent,r);return}this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},i.prototype.getPrivateKey=function(){return this.getKey().getPrivateKey()},i.prototype.getPrivateKeyB64=function(){return this.getKey().getPrivateBaseKeyB64()},i.prototype.getPublicKey=function(){return this.getKey().getPublicKey()},i.prototype.getPublicKeyB64=function(){return this.getKey().getPublicBaseKeyB64()},i.version=CI,i}();async function Bpe(){try{const r=await(await fetch(`${Bf.apiBaseUrl}/api/chat/rsa_public_key`)).json();if(!r.success)throw new Error(r.message||"Failed to fetch RSA public key");return r.data}catch(i){throw console.error("Error fetching RSA public key:",i),i}}async function Pn(i,r){try{if(window.crypto&&window.crypto.subtle){const e="-----BEGIN PUBLIC KEY-----",n=r.substring(r.indexOf(e)+e.length,r.indexOf("-----END PUBLIC KEY-----")).replace(/\s/g,""),a=window.atob(n),o=new ArrayBuffer(a.length),s=new Uint8Array(o);for(let c=0;clocalStorage.getItem("chatApiKey"),Ma=()=>{const i=localStorage.getItem("openaiApiKey"),r=localStorage.getItem("openaiBaseUrl")||"https://api.openai.com/v1",e=localStorage.getItem("rsaPublicKey");return{openaiApiKey:i||"",openaiBaseUrl:r,rsaPublicKey:e}},gn=()=>navigator.language||"zh-CN";var Li;(i=>{async function r(s){try{const u=pn(),l=gn();s.session_id=localStorage.getItem("sessionId")||null,fetch(`${vn}/api/chat/track_event`,{method:"POST",headers:{"Content-Type":"application/json",accept:"application/json","Access-Control-Allow-Origin":"*",Authorization:`Bearer ${u}`,"trace-id":Ur(),"Accept-Language":l},body:JSON.stringify(s)}).catch(h=>{console.warn("Track event failed:",h)})}catch(u){console.warn("Error preparing track event:",u)}return Promise.resolve()}i.trackEvent=r;async function*e(s,u,l=[],h=null,d=null,c){try{const f=pn(),v=gn(),{openaiApiKey:p,openaiBaseUrl:g,rsaPublicKey:y}=Ma(),m=Ur();if(!f){yield{text:`API key is required. Please set your API key first.⚙ -If you don't have an API key, please email us at ComfyUI-Copilot@service.alibaba.com and we will get back to you as soon as possible.`,finished:!0};return}const b=(l||[]).map(C=>new Promise((j,X)=>{const U=new FileReader;U.onloadend=()=>j(U.result),U.onerror=X,U.readAsDataURL(C)})),$=await Promise.all(b);let S=d?Array.isArray(d)?d:[d]:[];const _={"Content-Type":"application/json",accept:"application/json","Access-Control-Allow-Origin":"*",Authorization:`Bearer ${f}`,"trace-id":c||Ur(),"Accept-Language":v};if(p&&p.trim()!==""&&y)try{const C=await Pn(p,y);_["Encrypted-Openai-Api-Key"]=C,_["Openai-Base-Url"]=g}catch(C){console.error("Error encrypting OpenAI API key:",C)}const B=(await fetch(`${vn}/api/chat/invoke`,{method:"POST",headers:_,body:JSON.stringify({session_id:s,prompt:u,mock:!1,intent:h,ext:S,images:$.map((C,j)=>({filename:l[j].name,data:C}))})})).body.getReader();let I="";for(;;){const{done:C,value:j}=await B.read();if(C)break;I+=new TextDecoder().decode(j);const X=I.split(` +`,e+="-----END PUBLIC KEY-----",e},r.hasPublicKeyProperty=function(e){return e=e||{},e.hasOwnProperty("n")&&e.hasOwnProperty("e")},r.hasPrivateKeyProperty=function(e){return e=e||{},e.hasOwnProperty("n")&&e.hasOwnProperty("e")&&e.hasOwnProperty("d")&&e.hasOwnProperty("p")&&e.hasOwnProperty("q")&&e.hasOwnProperty("dmp1")&&e.hasOwnProperty("dmq1")&&e.hasOwnProperty("coeff")},r.prototype.parsePropertiesFrom=function(e){this.n=e.n,this.e=e.e,e.hasOwnProperty("d")&&(this.d=e.d,this.p=e.p,this.q=e.q,this.dmp1=e.dmp1,this.dmq1=e.dmq1,this.coeff=e.coeff)},r}(OI),xI={},ah,CI=typeof process<"u"?(ah=xI)===null||ah===void 0?void 0:ah.npm_package_version:void 0,AI=function(){function i(r){r===void 0&&(r={}),r=r||{},this.default_key_size=r.default_key_size?parseInt(r.default_key_size,10):1024,this.default_public_exponent=r.default_public_exponent||"010001",this.log=r.log||!1,this.key=null}return i.prototype.setKey=function(r){this.log&&this.key&&console.warn("A key was already set, overriding existing."),this.key=new Ip(r)},i.prototype.setPrivateKey=function(r){this.setKey(r)},i.prototype.setPublicKey=function(r){this.setKey(r)},i.prototype.decrypt=function(r){try{return this.getKey().decrypt($p(r))}catch{return!1}},i.prototype.encrypt=function(r){try{return Tu(this.getKey().encrypt(r))}catch{return!1}},i.prototype.sign=function(r,e,t){try{return Tu(this.getKey().sign(r,e,t))}catch{return!1}},i.prototype.verify=function(r,e,t){try{return this.getKey().verify(r,$p(e),t)}catch{return!1}},i.prototype.getKey=function(r){if(!this.key){if(this.key=new Ip,r&&{}.toString.call(r)==="[object Function]"){this.key.generateAsync(this.default_key_size,this.default_public_exponent,r);return}this.key.generate(this.default_key_size,this.default_public_exponent)}return this.key},i.prototype.getPrivateKey=function(){return this.getKey().getPrivateKey()},i.prototype.getPrivateKeyB64=function(){return this.getKey().getPrivateBaseKeyB64()},i.prototype.getPublicKey=function(){return this.getKey().getPublicKey()},i.prototype.getPublicKeyB64=function(){return this.getKey().getPublicBaseKeyB64()},i.version=CI,i}();async function Bpe(){try{const r=await(await fetch(`${Bf.apiBaseUrl}/api/chat/rsa_public_key`)).json();if(!r.success)throw new Error(r.message||"Failed to fetch RSA public key");return r.data}catch(i){throw console.error("Error fetching RSA public key:",i),i}}async function Pn(i,r){try{if(window.crypto&&window.crypto.subtle){const e="-----BEGIN PUBLIC KEY-----",n=r.substring(r.indexOf(e)+e.length,r.indexOf("-----END PUBLIC KEY-----")).replace(/\s/g,""),a=window.atob(n),o=new ArrayBuffer(a.length),s=new Uint8Array(o);for(let c=0;clocalStorage.getItem("chatApiKey"),Ma=()=>{const i=localStorage.getItem("openaiApiKey"),r=localStorage.getItem("openaiBaseUrl")||"https://api.openai.com/v1",e=localStorage.getItem("rsaPublicKey");return{openaiApiKey:i||"",openaiBaseUrl:r,rsaPublicKey:e}},gn=()=>navigator.language||"zh-CN";var Li;(i=>{async function r(s){try{const u=pn(),l=gn();s.session_id=localStorage.getItem("sessionId")||null,fetch(`${vn}/api/chat/track_event`,{method:"POST",headers:{"Content-Type":"application/json",accept:"application/json","Access-Control-Allow-Origin":"*",Authorization:`Bearer ${u}`,"trace-id":Ur(),"Accept-Language":l},body:JSON.stringify(s)}).catch(h=>{console.warn("Track event failed:",h)})}catch(u){console.warn("Error preparing track event:",u)}return Promise.resolve()}i.trackEvent=r;async function*e(s,u,l=[],h=null,d=null,c){try{const f=pn(),v=gn(),{openaiApiKey:p,openaiBaseUrl:g,rsaPublicKey:y}=Ma(),m=Ur(),b=(l||[]).map(C=>new Promise((j,X)=>{const U=new FileReader;U.onloadend=()=>j(U.result),U.onerror=X,U.readAsDataURL(C)})),$=await Promise.all(b);let S=d?Array.isArray(d)?d:[d]:[];const _={"Content-Type":"application/json",accept:"application/json","Access-Control-Allow-Origin":"*",Authorization:`Bearer ${f}`,"trace-id":c||Ur(),"Accept-Language":v};if(p&&p.trim()!==""&&y)try{const C=await Pn(p,y);_["Encrypted-Openai-Api-Key"]=C,_["Openai-Base-Url"]=g}catch(C){console.error("Error encrypting OpenAI API key:",C)}const B=(await fetch(`${vn}/api/chat/invoke`,{method:"POST",headers:_,body:JSON.stringify({session_id:s,prompt:u,mock:!1,intent:h,ext:S,images:$.map((C,j)=>({filename:l[j].name,data:C}))})})).body.getReader();let I="";for(;;){const{done:C,value:j}=await B.read();if(C)break;I+=new TextDecoder().decode(j);const X=I.split(` `);I=X.pop()||"";for(const U of X)U.trim()&&(yield{...JSON.parse(U),message_id:m})}I.trim()&&(yield{...JSON.parse(I),message_id:m})}catch(f){throw console.error("Error in streamInvokeServer:",f),alert(f instanceof Error?f.message:"An error occurred while streaming, please refresh the page and try again."),f}}i.streamInvokeServer=e;async function t(s,u){try{const l=pn(),h=gn(),{openaiApiKey:d,openaiBaseUrl:c,rsaPublicKey:f}=Ma(),v={"Content-Type":"application/json",accept:"application/json","Access-Control-Allow-Origin":"*",Authorization:`Bearer ${l}`,"trace-id":Ur(),"Accept-Language":h};if(d&&d.trim()!==""&&f)try{const y=await Pn(d,f);v["Encrypted-Openai-Api-Key"]=y,v["Openai-Base-Url"]=c}catch(y){console.error("Error encrypting OpenAI API key:",y)}const g=await(await fetch(`${vn}/api/chat/get_optimized_workflow`,{method:"POST",headers:v,body:JSON.stringify({workflow_id:s,prompt:u})})).json();if(!g.success){const y=g.message||"Failed to get optimized workflow";throw alert(y),new Error(y)}return g.data}catch(l){throw console.error("Error getting optimized workflow:",l),alert(l instanceof Error?l.message:"Failed to get optimized workflow"),l}}i.getOptimizedWorkflow=t;async function n(s){const u=pn(),l=gn(),{openaiApiKey:h,openaiBaseUrl:d,rsaPublicKey:c}=Ma(),f={"Content-Type":"application/json",Authorization:`Bearer ${u}`,"trace-id":Ur(),"Accept-Language":l};if(h&&h.trim()!==""&&c)try{const g=await Pn(h,c);f["Encrypted-Openai-Api-Key"]=g,f["Openai-Base-Url"]=d}catch(g){console.error("Error encrypting OpenAI API key:",g)}const p=await(await fetch(`${vn}/api/chat/get_node_info_by_types`,{method:"POST",headers:f,body:JSON.stringify({node_types:s})})).json();if(!p.success){const g=p.message||"Failed to get node info by types";throw alert(g),new Error(g)}return p.data}i.batchGetNodeInfo=n;async function a(s){try{const u=localStorage.getItem(`messages_${s}`);if(u)return console.log("Using cached messages from localStorage"),JSON.parse(u);const l=pn(),h=gn(),{openaiApiKey:d,openaiBaseUrl:c,rsaPublicKey:f}=Ma(),v={accept:"application/json",Authorization:`Bearer ${l}`,"trace-id":Ur(),"Accept-Language":h};if(d&&d.trim()!==""&&f)try{const m=await Pn(d,f);v["Encrypted-Openai-Api-Key"]=m,v["Openai-Base-Url"]=c}catch(m){console.error("Error encrypting OpenAI API key:",m)}const g=await(await fetch(`${vn}/api/chat/get_messages_by_session_id?session_id=${s}`,{method:"GET",headers:v})).json();if(!g.success){const m=g.message||"Failed to fetch messages";throw alert(m+", please refresh the page and try again."),new Error(m)}const y=g.data.map(m=>(console.log("msg.ext",m.ext),{id:m.id.toString(),content:m.role==="ai"?JSON.stringify({session_id:s,text:m.content,finished:m.finished||!1,format:m.format||"markdown",ext:m.ext}):m.content,role:m.role,name:m.role==="ai"?"Assistant":void 0,format:m.format||"markdown",finished:m.finished}));return localStorage.setItem(`messages_${s}`,JSON.stringify(y)),y}catch(u){throw console.error("Error fetching messages:",u),alert(u instanceof Error?u.message:"Failed to fetch messages, please refresh the page and try again."),u}}i.fetchMessages=a;async function o(){try{const s=pn(),u=gn(),{openaiApiKey:l,openaiBaseUrl:h,rsaPublicKey:d}=Ma(),c={accept:"application/json",Authorization:`Bearer ${s}`,"trace-id":Ur(),"Accept-Language":u};if(l&&l.trim()!==""&&d)try{const p=await Pn(l,d);c["Encrypted-Openai-Api-Key"]=p,c["Openai-Base-Url"]=h}catch(p){console.error("Error encrypting OpenAI API key:",p)}const v=await(await fetch(`${vn}/api/chat/announcement`,{method:"GET",headers:c})).json();if(!v.success){const p=v.message||"Failed to fetch announcement";return console.error(p),""}return v.data}catch(s){return console.error("Error fetching announcement:",s),""}}i.fetchAnnouncement=o})(Li||(Li={}));function q$({name:i,isUser:r=!1,children:e}){return O.jsx("div",{className:"flex flex-col w-full items-start gap-2 py-2 animate-fadeIn",children:O.jsx("div",{className:"w-full",children:e})})}function RI({title:i,titleId:r,...e},t){return We.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:t,"aria-labelledby":r},e),i?We.createElement("title",{id:r},i):null,We.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z"}))}const NI=We.forwardRef(RI);function jpe({content:i,trace_id:r}){const[e,t]=We.useState(!1),[n,a]=We.useState(!1),o=async()=>{r&&(await navigator.clipboard.writeText(r),a(!0),setTimeout(()=>a(!1),2e3))};return O.jsx(q$,{name:"User",isUser:!0,children:O.jsxs("div",{className:"w-full rounded-lg border border-gray-700 py-4 px-4 text-gray-700 text-sm break-words relative",children:[O.jsx("p",{className:"whitespace-pre-wrap leading-snug",children:i}),r&&O.jsxs("div",{className:"absolute bottom-1 right-1.5 cursor-pointer opacity-40 hover:opacity-100 transition-opacity",onMouseEnter:()=>t(!0),onMouseLeave:()=>t(!1),onClick:o,children:[O.jsx(NI,{className:"h-3.5 w-3.5 text-gray-500 hover:text-gray-700"}),e&&O.jsx("div",{className:"absolute right-0 -top-6 bg-gray-700 text-white text-[10px] py-0.5 px-1.5 rounded shadow-sm whitespace-nowrap",children:n?"Copied!":"Copy trace ID"})]})]})})}const MI=We.memo(eI,(i,r)=>i.children===r.children&&i.className===r.className),BI=({content:i})=>O.jsxs("div",{className:"rounded-lg border border-blue-200 bg-blue-50 p-1 shadow-sm",children:[O.jsxs("div",{className:"flex items-center mb-1",children:[O.jsx("div",{className:"bg-blue-100 rounded-full p-1 mr-1",children:O.jsx("svg",{className:"h-4 w-4 text-blue-700",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:O.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}),O.jsx("h3",{className:"text-sm font-medium text-blue-800",children:"Node Usage Guide"})]}),O.jsx("div",{className:"markdown-content text-blue-900",children:i})]}),FI=({content:i})=>O.jsxs("div",{className:"rounded-lg border border-green-200 bg-green-50 p-1 shadow-sm",children:[O.jsxs("div",{className:"flex items-center mb-1",children:[O.jsx("div",{className:"bg-green-100 rounded-full p-1 mr-1",children:O.jsxs("svg",{className:"h-4 w-4 text-green-700",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[O.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),O.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})}),O.jsx("h3",{className:"text-sm font-medium text-green-800",children:"Node Parameter Reference"})]}),O.jsx("div",{className:"markdown-content text-green-900",children:i})]});function Lpe({content:i,name:r="Assistant",avatar:e,format:t,onOptionClick:n,extComponent:a,metadata:o}){const s=We.useRef(),u=(h,d)=>O.jsx(MI,{rehypePlugins:[[tI,{target:"_blank"}],rI],remarkPlugins:[iI,nI],className:`prose prose-xs prose-neutral prose-a:text-accent-foreground/50 break-words [&>*]:!my-1 leading-relaxed text-xs prose-headings:font-semibold prose-h1:text-base diff --git a/dist/copilot_web/workflowChat-CKaW90Rp.js b/dist/copilot_web/workflowChat-CnVi6gIQ.js similarity index 99% rename from dist/copilot_web/workflowChat-CKaW90Rp.js rename to dist/copilot_web/workflowChat-CnVi6gIQ.js index a71a078..0852bdd 100644 --- a/dist/copilot_web/workflowChat-CKaW90Rp.js +++ b/dist/copilot_web/workflowChat-CnVi6gIQ.js @@ -1,5 +1,5 @@ -const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/WorkflowOption-CsptvFbJ.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-cqAuXss9.js"])))=>i.map(i=>d[i]); -import{j as h,r as vg,b as mg}from"./vendor-markdown-Dek94WS0.js";import{r as S,R as at,c as Lt}from"./vendor-react-V04_Axys.js";import{f as xg,v as yg,a as sn,B as wg,U as bg,A as yr,b as Ag,g as Ve,c as Sg,u as To,M as Ig,W as Nt}from"./message-components-cqAuXss9.js";import{l as Eg}from"./App-PpJX3mvb.js";import{_ as Sr}from"./input.js";/** +const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/WorkflowOption-BSTBilSm.js","copilot_web/vendor-markdown-Dek94WS0.js","copilot_web/vendor-react-V04_Axys.js","copilot_web/message-components-B6pkQvDp.js"])))=>i.map(i=>d[i]); +import{j as h,r as vg,b as mg}from"./vendor-markdown-Dek94WS0.js";import{r as S,R as at,c as Lt}from"./vendor-react-V04_Axys.js";import{f as xg,v as yg,a as sn,B as wg,U as bg,A as yr,b as Ag,g as Ve,c as Sg,u as To,M as Ig,W as Nt}from"./message-components-B6pkQvDp.js";import{l as Eg}from"./App-BjVABi7E.js";import{_ as Sr}from"./input.js";/** * @license lucide-react v0.475.0 - ISC * * This source code is licensed under the ISC license. @@ -101,7 +101,7 @@ ${U.join(` hover:bg-gray-50`,children:"Close"})})]})})]})}function Hg(){const y=Object.values(sn.canvas.selected_nodes)[0],L=new Set;function o(W,z){if(!(!W||z>=1)&&W.inputs)for(const N of Object.values(W.inputs)){const O=N.link;if(O&&sn.graph.links[O]){const V=sn.graph.links[O].origin_id,m=sn.graph._nodes_by_id[V];m&&(L.add(m.type),o(m,z+1))}}}return y?(o(y,0),[{type:"upstream_node_types",data:Array.from(L)}]):null}function $g({nodeInfo:y,onSendWithIntent:L,loading:o,onSendWithContent:W}){return h.jsx("div",{className:"mb-3 p-3 rounded-md bg-gray-50 border border-gray-200",children:h.jsxs("div",{className:"text-sm text-gray-700",children:[h.jsxs("p",{children:["Selected node: ",y.type]}),h.jsxs("div",{className:"flex gap-2 mt-2",children:[h.jsx("button",{className:`px-3 py-1 text-xs rounded-md bg-blue-50 text-blue-700 hover:bg-blue-100`,onClick:()=>W(`Reply in ${navigator.language} language: How does the ${y.type} node work? I need its official usage guide.`),disabled:o,children:"Usage"}),h.jsx("button",{className:`px-3 py-1 text-xs rounded-md bg-green-100 text-green-700 hover:bg-green-200`,onClick:()=>W(`Reply in ${navigator.language} language: Show me the technical specifications for the ${y.type} node's inputs and outputs.`),disabled:o,children:"Parameters"}),h.jsx("button",{className:`px-3 py-1 text-xs rounded-md bg-purple-100 - text-purple-700 hover:bg-purple-200`,onClick:()=>L("downstream_subgraph_search",Hg()),disabled:o,children:"Downstream Nodes"})]})]})})}function qg(){return h.jsx(wg,{name:"Assistant",children:h.jsxs("div",{className:"flex items-center space-x-2 p-4 bg-gray-50 rounded-lg",children:[h.jsxs("div",{className:"flex space-x-1",children:[h.jsx("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"0ms"}}),h.jsx("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"150ms"}}),h.jsx("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"300ms"}})]}),h.jsx("span",{className:"text-sm text-gray-500",children:"AI is thinking..."})]})})}const Zg=y=>`https://ui-avatars.com/api/?name=${y||"User"}&background=random`,Yg=S.lazy(()=>Sr(()=>import("./WorkflowOption-CsptvFbJ.js"),__vite__mapDeps([0,1,2,3])).then(y=>({default:y.WorkflowOption}))),Xg=S.lazy(()=>Sr(()=>import("./message-components-cqAuXss9.js").then(y=>y.N),__vite__mapDeps([3,2,1])).then(y=>({default:y.NodeSearch}))),Jg=S.lazy(()=>Sr(()=>import("./message-components-cqAuXss9.js").then(y=>y.D),__vite__mapDeps([3,2,1])).then(y=>({default:y.DownstreamSubgraphs}))),Qg=S.lazy(()=>Sr(()=>import("./message-components-cqAuXss9.js").then(y=>y.d),__vite__mapDeps([3,2,1])).then(y=>({default:y.NodeInstallGuide})));function Vg({messages:y,latestInput:L,onOptionClick:o,installedNodes:W,onAddMessage:z,loading:N}){const O=at.useMemo(()=>m=>{if(m.role==="user")return h.jsx(bg,{content:m.content,trace_id:m.trace_id},m.id);if(m.role==="ai"||m.role==="tool"){const H=Zg(m.role);try{const B=JSON.parse(m.content),$=B.ext?.find(U=>U.type==="workflow"),oe=B.ext?.find(U=>U.type==="node"),ae=B.ext?.find(U=>U.type==="downstream_subgraph_search"),we=B.ext?.find(U=>U.type==="node_install_guide");let k=null;if($)k=h.jsx(S.Suspense,{fallback:h.jsx("div",{children:"Loading..."}),children:h.jsx(Yg,{content:m.content,name:m.name,avatar:H,latestInput:L,installedNodes:W,onAddMessage:z})});else if(oe)k=h.jsx(S.Suspense,{fallback:h.jsx("div",{children:"Loading..."}),children:h.jsx(Xg,{content:m.content,name:m.name,avatar:H,installedNodes:W})});else if(ae){const U=h.jsx(S.Suspense,{fallback:h.jsx("div",{children:"Loading..."}),children:h.jsx(Jg,{content:m.content,name:m.name,avatar:H,onAddMessage:z})});if(m.metadata?.intent==="downstream_subgraph_search")return h.jsx(yr,{content:m.content,name:m.name,avatar:H,format:m.format,onOptionClick:o,extComponent:U,metadata:m.metadata},m.id);k=U}else we&&(k=h.jsx(S.Suspense,{fallback:h.jsx("div",{children:"Loading..."}),children:h.jsx(Qg,{content:m.content,onLoadSubgraph:()=>{if(m.metadata?.pendingSubgraph){const U=Object.values(sn.canvas.selected_nodes)[0];if(U){const ue=m.metadata.pendingSubgraph,re=ue.json.nodes,de=ue.json.links,Ae=re.find(X=>X.id===0),fe=Ae?.id,q={};fe&&(q[fe]=U),sn.canvas.emitBeforeChange();try{for(const X of re)if(X.id!==fe){const Se=Ae?.pos||[0,0],pe=U._pos||[0,0],bn=[X.pos[0]+pe[0]-Se[0],X.pos[1]+pe[1]-Se[1]];q[X.id]=Ag(X.type,{pos:bn})}}finally{sn.canvas.emitAfterChange()}for(const X of de){const Se=q[X.origin_id],pe=q[X.target_id];Se&&pe&&Se.connect(X.origin_slot,pe,X.target_slot)}}else alert("Please select a upstream node first before adding a subgraph.")}else if(m.metadata?.pendingWorkflow){const U=m.metadata.pendingWorkflow,ue=m.metadata.optimizedParams;sn.loadGraphData(U);for(const[de,Ae,fe,q,X]of ue){const Se=sn.graph._nodes_by_id[de].widgets;for(const pe of Se)pe.name===q&&(pe.value=X)}sn.graph.setDirtyCanvas(!1,!0);const re={id:Ve(),role:"tool",content:JSON.stringify({text:"The workflow has been successfully loaded to the canvas",ext:[]}),format:"markdown",name:"Assistant"};z?.(re)}}})}));return B.text||k?h.jsx(yr,{content:m.content,name:m.name,avatar:H,format:m.format,onOptionClick:o,extComponent:k,metadata:m.metadata},m.id):k||h.jsx(yr,{content:m.content,name:m.name,avatar:H,format:m.format,onOptionClick:o,metadata:m.metadata},m.id)}catch(B){return console.error("[MessageList] Error parsing message content:",B),console.error("解析JSON失败",m.content),h.jsx(yr,{content:m.content,name:m.name,avatar:H,format:m.format,onOptionClick:o,metadata:m.metadata},m.id)}}return null},[W,o,z,L]),V=at.useMemo(()=>y?.map(O),[y,O]);return h.jsxs("div",{className:"flex flex-col gap-4 w-full",children:[V,N&&h.jsx(qg,{})]})}async function ep(){try{return await(await Sg.fetchApi("/object_info",{method:"GET"})).json()}catch(y){throw console.error("Error fetching object info:",y),y}}async function np(){const y=await ep();return Object.keys(y)}var br={exports:{}};/** + text-purple-700 hover:bg-purple-200`,onClick:()=>L("downstream_subgraph_search",Hg()),disabled:o,children:"Downstream Nodes"})]})]})})}function qg(){return h.jsx(wg,{name:"Assistant",children:h.jsxs("div",{className:"flex items-center space-x-2 p-4 bg-gray-50 rounded-lg",children:[h.jsxs("div",{className:"flex space-x-1",children:[h.jsx("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"0ms"}}),h.jsx("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"150ms"}}),h.jsx("div",{className:"w-2 h-2 bg-gray-400 rounded-full animate-bounce",style:{animationDelay:"300ms"}})]}),h.jsx("span",{className:"text-sm text-gray-500",children:"AI is thinking..."})]})})}const Zg=y=>`https://ui-avatars.com/api/?name=${y||"User"}&background=random`,Yg=S.lazy(()=>Sr(()=>import("./WorkflowOption-BSTBilSm.js"),__vite__mapDeps([0,1,2,3])).then(y=>({default:y.WorkflowOption}))),Xg=S.lazy(()=>Sr(()=>import("./message-components-B6pkQvDp.js").then(y=>y.N),__vite__mapDeps([3,2,1])).then(y=>({default:y.NodeSearch}))),Jg=S.lazy(()=>Sr(()=>import("./message-components-B6pkQvDp.js").then(y=>y.D),__vite__mapDeps([3,2,1])).then(y=>({default:y.DownstreamSubgraphs}))),Qg=S.lazy(()=>Sr(()=>import("./message-components-B6pkQvDp.js").then(y=>y.d),__vite__mapDeps([3,2,1])).then(y=>({default:y.NodeInstallGuide})));function Vg({messages:y,latestInput:L,onOptionClick:o,installedNodes:W,onAddMessage:z,loading:N}){const O=at.useMemo(()=>m=>{if(m.role==="user")return h.jsx(bg,{content:m.content,trace_id:m.trace_id},m.id);if(m.role==="ai"||m.role==="tool"){const H=Zg(m.role);try{const B=JSON.parse(m.content),$=B.ext?.find(U=>U.type==="workflow"),oe=B.ext?.find(U=>U.type==="node"),ae=B.ext?.find(U=>U.type==="downstream_subgraph_search"),we=B.ext?.find(U=>U.type==="node_install_guide");let k=null;if($)k=h.jsx(S.Suspense,{fallback:h.jsx("div",{children:"Loading..."}),children:h.jsx(Yg,{content:m.content,name:m.name,avatar:H,latestInput:L,installedNodes:W,onAddMessage:z})});else if(oe)k=h.jsx(S.Suspense,{fallback:h.jsx("div",{children:"Loading..."}),children:h.jsx(Xg,{content:m.content,name:m.name,avatar:H,installedNodes:W})});else if(ae){const U=h.jsx(S.Suspense,{fallback:h.jsx("div",{children:"Loading..."}),children:h.jsx(Jg,{content:m.content,name:m.name,avatar:H,onAddMessage:z})});if(m.metadata?.intent==="downstream_subgraph_search")return h.jsx(yr,{content:m.content,name:m.name,avatar:H,format:m.format,onOptionClick:o,extComponent:U,metadata:m.metadata},m.id);k=U}else we&&(k=h.jsx(S.Suspense,{fallback:h.jsx("div",{children:"Loading..."}),children:h.jsx(Qg,{content:m.content,onLoadSubgraph:()=>{if(m.metadata?.pendingSubgraph){const U=Object.values(sn.canvas.selected_nodes)[0];if(U){const ue=m.metadata.pendingSubgraph,re=ue.json.nodes,de=ue.json.links,Ae=re.find(X=>X.id===0),fe=Ae?.id,q={};fe&&(q[fe]=U),sn.canvas.emitBeforeChange();try{for(const X of re)if(X.id!==fe){const Se=Ae?.pos||[0,0],pe=U._pos||[0,0],bn=[X.pos[0]+pe[0]-Se[0],X.pos[1]+pe[1]-Se[1]];q[X.id]=Ag(X.type,{pos:bn})}}finally{sn.canvas.emitAfterChange()}for(const X of de){const Se=q[X.origin_id],pe=q[X.target_id];Se&&pe&&Se.connect(X.origin_slot,pe,X.target_slot)}}else alert("Please select a upstream node first before adding a subgraph.")}else if(m.metadata?.pendingWorkflow){const U=m.metadata.pendingWorkflow,ue=m.metadata.optimizedParams;sn.loadGraphData(U);for(const[de,Ae,fe,q,X]of ue){const Se=sn.graph._nodes_by_id[de].widgets;for(const pe of Se)pe.name===q&&(pe.value=X)}sn.graph.setDirtyCanvas(!1,!0);const re={id:Ve(),role:"tool",content:JSON.stringify({text:"The workflow has been successfully loaded to the canvas",ext:[]}),format:"markdown",name:"Assistant"};z?.(re)}}})}));return B.text||k?h.jsx(yr,{content:m.content,name:m.name,avatar:H,format:m.format,onOptionClick:o,extComponent:k,metadata:m.metadata},m.id):k||h.jsx(yr,{content:m.content,name:m.name,avatar:H,format:m.format,onOptionClick:o,metadata:m.metadata},m.id)}catch(B){return console.error("[MessageList] Error parsing message content:",B),console.error("解析JSON失败",m.content),h.jsx(yr,{content:m.content,name:m.name,avatar:H,format:m.format,onOptionClick:o,metadata:m.metadata},m.id)}}return null},[W,o,z,L]),V=at.useMemo(()=>y?.map(O),[y,O]);return h.jsxs("div",{className:"flex flex-col gap-4 w-full",children:[V,N&&h.jsx(qg,{})]})}async function ep(){try{return await(await Sg.fetchApi("/object_info",{method:"GET"})).json()}catch(y){throw console.error("Error fetching object info:",y),y}}async function np(){const y=await ep();return Object.keys(y)}var br={exports:{}};/** * @license * Lodash * Copyright OpenJS Foundation and other contributors diff --git a/ui/src/apis/workflowChatApi.ts b/ui/src/apis/workflowChatApi.ts index b39192b..e4e1d3f 100644 --- a/ui/src/apis/workflowChatApi.ts +++ b/ui/src/apis/workflowChatApi.ts @@ -85,13 +85,13 @@ export namespace WorkflowChatAPI { // Generate a unique message ID for this chat request const messageId = generateUUID(); - if (!apiKey) { - yield { - text: 'API key is required. Please set your API key first.⚙\nIf you don\'t have an API key, please email us at ComfyUI-Copilot@service.alibaba.com and we will get back to you as soon as possible.', - finished: true - } as ChatResponse; - return; - } + // if (!apiKey) { + // yield { + // text: 'API key is required. Please set your API key first.⚙\nIf you don\'t have an API key, please email us at ComfyUI-Copilot@service.alibaba.com and we will get back to you as soon as possible.', + // finished: true + // } as ChatResponse; + // return; + // } // Convert images to base64 const imagePromises = (images || []).map(file =>