feat: 图片本地存储一份

This commit is contained in:
ai-business-hql
2025-08-02 11:35:00 +08:00
parent be4adb52e0
commit c75bc792fe
10 changed files with 289 additions and 252 deletions
@@ -1,7 +1,7 @@
function getImportPath(filename) {
return `./${filename}`;
}
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/workflowChat-BjMKy0bJ.js","copilot_web/vendor-markdown-CBmlBP6m.js","copilot_web/vendor-react-Dixhfmvb.js","copilot_web/message-components-9chzfzs4.js","copilot_web/input.js","copilot_web/assets/input-CRBDhXDN.css","copilot_web/fonts.css"].map(path => {
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["copilot_web/workflowChat-DcTitn2I.js","copilot_web/vendor-markdown-CBmlBP6m.js","copilot_web/vendor-react-Dixhfmvb.js","copilot_web/message-components-DmxYkzGi.js","copilot_web/input.js","copilot_web/assets/input-CRBDhXDN.css","copilot_web/fonts.css"].map(path => {
const apiBase = window.comfyAPI?.api?.api?.api_base;
if (apiBase) {
// 有 API base 时,使用完整路径
@@ -11,4 +11,4 @@ function getImportPath(filename) {
return `./${path}`;
}
}))))=>i.map(i=>d[i]);
import{_ as a}from"./input.js";import{j as e}from"./vendor-markdown-CBmlBP6m.js";import{r as t,R as i}from"./vendor-react-Dixhfmvb.js";import{C as n}from"./message-components-9chzfzs4.js";const s={EXPLAIN_NODE:"copilot:explain-node",TOOLBOX_USAGE:"copilot:toolbox-usage",TOOLBOX_PARAMETERS:"copilot:toolbox-parameters",TOOLBOX_DOWNSTREAMNODES:"copilot:toolbox-downstreamnodes"},d=i.lazy(()=>a(()=>import(getImportPath("workflowChat-BjMKy0bJ.js")),__vite__mapDeps([0,1,2,3,4,5,6])).then(o=>({default:o.default})));function c(){const[o,r]=t.useState(!1);return t.useEffect(()=>{const l=()=>{r(!0)};return window.addEventListener(s.EXPLAIN_NODE,l),()=>window.removeEventListener(s.EXPLAIN_NODE,l)},[]),e.jsx(n,{children:e.jsx("div",{className:"h-full w-full flex flex-col",children:e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"h-full w-full flex items-center justify-center",children:"Loading..."}),children:e.jsx(d,{visible:!0,triggerUsage:o,onUsageTriggered:()=>r(!1)})})})})}const O=Object.freeze(Object.defineProperty({__proto__:null,default:c},Symbol.toStringTag,{value:"Module"}));export{O as A,s as C};
import{_ as a}from"./input.js";import{j as e}from"./vendor-markdown-CBmlBP6m.js";import{r as t,R as i}from"./vendor-react-Dixhfmvb.js";import{C as n}from"./message-components-DmxYkzGi.js";const s={EXPLAIN_NODE:"copilot:explain-node",TOOLBOX_USAGE:"copilot:toolbox-usage",TOOLBOX_PARAMETERS:"copilot:toolbox-parameters",TOOLBOX_DOWNSTREAMNODES:"copilot:toolbox-downstreamnodes"},d=i.lazy(()=>a(()=>import(getImportPath("workflowChat-DcTitn2I.js")),__vite__mapDeps([0,1,2,3,4,5,6])).then(o=>({default:o.default})));function c(){const[o,r]=t.useState(!1);return t.useEffect(()=>{const l=()=>{r(!0)};return window.addEventListener(s.EXPLAIN_NODE,l),()=>window.removeEventListener(s.EXPLAIN_NODE,l)},[]),e.jsx(n,{children:e.jsx("div",{className:"h-full w-full flex flex-col",children:e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"h-full w-full flex items-center justify-center",children:"Loading..."}),children:e.jsx(d,{visible:!0,triggerUsage:o,onUsageTriggered:()=>r(!1)})})})})}const O=Object.freeze(Object.defineProperty({__proto__:null,default:c},Symbol.toStringTag,{value:"Module"}));export{O as A,s as C};
@@ -1,5 +1,5 @@
function getImportPath(filename) {
return `./${filename}`;
}
import{j as r}from"./vendor-markdown-CBmlBP6m.js";import{r as a}from"./vendor-react-Dixhfmvb.js";import{B as I,R as E,h as f,a as h,W as x}from"./message-components-9chzfzs4.js";function B({content:g,name:m="Assistant",avatar:A,onAddMessage:b,onUpdateMessage:c,onFinishLoad:k,messageId:y}){const[d,_]=a.useState(!1),[D,O]=a.useState(""),[J,w]=a.useState(!1),[S,v]=a.useState(null);a.useEffect(()=>{k?.()},[]);const s=a.useMemo(()=>{try{return JSON.parse(g)}catch(e){return console.error("Failed to parse message content:",e),null}},[g]),p=a.useMemo(()=>{if(!s||!s.ext)return null;const e=s.ext.find(t=>t.type==="debug_start_checkpoint"||t.type==="debug_checkpoint"&&t.data?.checkpoint_type==="debug_start");return e&&e.data&&e.data.checkpoint_id?e.data.checkpoint_id:null},[s])||S,j=async()=>{if(d)return;const e=f(),t={id:e,role:"ai",content:JSON.stringify({text:`🔍 Starting workflow analysis...
import{j as r}from"./vendor-markdown-CBmlBP6m.js";import{r as a}from"./vendor-react-Dixhfmvb.js";import{B as I,R as E,h as f,a as h,W as x}from"./message-components-DmxYkzGi.js";function B({content:g,name:m="Assistant",avatar:A,onAddMessage:b,onUpdateMessage:c,onFinishLoad:k,messageId:y}){const[d,_]=a.useState(!1),[D,O]=a.useState(""),[J,w]=a.useState(!1),[S,v]=a.useState(null);a.useEffect(()=>{k?.()},[]);const s=a.useMemo(()=>{try{return JSON.parse(g)}catch(e){return console.error("Failed to parse message content:",e),null}},[g]),p=a.useMemo(()=>{if(!s||!s.ext)return null;const e=s.ext.find(t=>t.type==="debug_start_checkpoint"||t.type==="debug_checkpoint"&&t.data?.checkpoint_type==="debug_start");return e&&e.data&&e.data.checkpoint_id?e.data.checkpoint_id:null},[s])||S,j=async()=>{if(d)return;const e=f(),t={id:e,role:"ai",content:JSON.stringify({text:`🔍 Starting workflow analysis...
`,ext:[]}),format:"markdown",name:"Assistant",finished:!1,debugGuide:!0};b?.(t);try{await N(),await C(e)}finally{_(!1)}},N=async()=>{try{const e=await h.graphToPrompt(),t=localStorage.getItem("sessionId")||"";if(t&&e){const o=await x.saveWorkflowCheckpoint(t,e.output,e.workflow,"debug_start");if(v(o.version_id),console.log(`Saved debug start checkpoint: ${o.version_id}`),c&&s){const n=[...s.ext||[]].filter(u=>u.type!=="debug_start_checkpoint"&&!(u.type==="debug_checkpoint"&&u.data?.checkpoint_type==="debug_start"));n.push({type:"debug_start_checkpoint",data:{checkpoint_id:o.version_id,checkpoint_type:"debug_start"}});const l={id:y||f(),role:"ai",content:JSON.stringify({text:s.text,ext:n}),format:"debug_guide",name:"Assistant"};c(l)}}}catch(e){console.error("Failed to save checkpoint before debug:",e)}},C=async e=>{try{const t=await h.graphToPrompt();let o="",i=null;for await(const n of x.streamDebugAgent(t))if(n.text){o=n.text,n.ext&&(i=n.ext);const l={id:e,role:"ai",content:JSON.stringify({text:o,ext:i||[]}),format:"markdown",name:"Assistant",finished:!1,debugGuide:!0};c?.(l)}c?.({id:e,role:"ai",content:JSON.stringify({text:o,ext:i||[]}),format:"markdown",name:"Assistant",finished:!0,debugGuide:!0})}catch(t){console.error("Error calling debug agent:",t),w(!1);const i={id:e,role:"ai",content:JSON.stringify({text:`I encountered an error while analyzing your workflow: ${t.message||"Unknown error"}`,ext:[]}),format:"markdown",name:"Assistant",finished:!0};c?.(i)}};return s?r.jsx(I,{name:m,children:r.jsxs("div",{className:"bg-gray-100 pt-4 px-4 pb-3 rounded-lg",children:[r.jsx("div",{className:"flex justify-between items-start",children:r.jsx("p",{className:"text-gray-700 text-sm flex-1",children:s.text})}),r.jsx("div",{className:"flex justify-end mt-4",children:r.jsx("button",{onClick:j,disabled:d,className:`px-4 py-2 text-[#fff] text-sm rounded-md shadow-[0_2px_8px_rbga(79, 140, 255, 0.15)] hover:!shadow-[0_4px_16px_rbga(79, 140, 255, 0.25)] hover:!scale-[1.05] transition-colors ${d?"bg-gray-400 cursor-not-allowed":"bg-debug-btn hover:!bg-debug-btn-hover"}`,children:d?"Analyzing...":"Debug Errors"})}),r.jsx("div",{className:"flex justify-end mt-2",children:!!p&&r.jsx("div",{className:"ml-2 flex-shrink-0",children:r.jsx(E,{checkpointId:p,onRestore:()=>{console.log("Workflow restored from checkpoint")}})})})]})}):null}export{B as DebugGuide};
@@ -1,4 +1,4 @@
function getImportPath(filename) {
return `./${filename}`;
}
import{j as e}from"./vendor-markdown-CBmlBP6m.js";import{r as o}from"./vendor-react-Dixhfmvb.js";import{b as j,c as b,B as y,R as N}from"./message-components-9chzfzs4.js";const _=c=>{const{title:i="",isWorkflowUpdate:h=!1,className:d="",children:x}=c,[a,u]=o.useState(!1),l=h?"#166534":"#E5E7EB";return e.jsxs("div",{className:`relative shadow-gray-200 dark:shadow-gray-600 rounded-lg p-2 overflow-hidden ${d} ${a?"h-auto":"h-[200px]"}`,children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("div",{children:typeof i=="string"?e.jsx("h3",{className:"text-sm text-gray-900 dark:text-white font-medium",children:i}):i}),e.jsx("button",{onClick:()=>{console.log("setOpen--->"),u(!a)},children:a?e.jsx(j,{color:l}):e.jsx(b,{color:l})})]}),e.jsx("div",{className:"dark:border-gray-700",children:x}),!a&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-40 w-full z-5 bg-gradient-to-t from-[#fff] to-transparent pointer-events-none"})]})};function D({content:c,name:i="Assistant",avatar:h,format:d="markdown",onFinishLoad:x}){o.useEffect(()=>{x?.()},[]);const[a,u]=o.useState(null),[l,f]=o.useState(null),[s,p]=o.useState(!1);o.useEffect(()=>{try{const r=JSON.parse(c);if(u(r),r.ext){let t=r.ext.find(n=>n.type==="workflow_rewrite_checkpoint"||n.type==="debug_checkpoint"&&n.data?.checkpoint_type==="workflow_rewrite_start");t&&t.data&&t.data.checkpoint_id?(f(t.data.checkpoint_id),p(!0)):(t=r.ext.find(n=>n.type==="workflow_rewrite_complete"),t&&t.data&&t.data.version_id?(f(t.data.version_id),p(!0)):(t=r.ext.find(n=>n.type==="debug_checkpoint"),t&&t.data&&t.data.checkpoint_id&&(f(t.data.checkpoint_id),p(!1)))),r.ext.find(n=>n.type==="workflow_update")&&p(!0)}}catch(r){console.error("Failed to parse DebugResult content:",r)}},[c]);const g=r=>d==="markdown"?r.replace(/\*\*(.*?)\*\*/g,"<strong>$1</strong>").replace(/\*(.*?)\*/g,"<em>$1</em>").replace(/`(.*?)`/g,'<code class="bg-gray-100 px-1 rounded">$1</code>').replace(/\n/g,"<br/>"):r,w=o.useMemo(()=>s?"bg-green-50 border border-green-200":"bg-gray-100",[s]),m=o.useMemo(()=>s?"text-green-700 text-sm leading-relaxed":"text-gray-700 text-sm leading-relaxed",[s]),k=o.useMemo(()=>s?e.jsxs("div",{className:"flex items-center",children:[e.jsx("svg",{className:"w-5 h-5 text-green-600 mr-2",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),e.jsx("h4",{className:"text-green-800 font-medium",children:"Workflow Updated Successfully"})]}):null,[s]),v=o.useMemo(()=>s?e.jsx("div",{className:"mt-3 text-xs text-green-600",children:"💡 If you're not satisfied with the changes, click the restore button to revert to the previous version."}):null,[s]);return console.log("responseData-",a),a?e.jsx(y,{name:i,children:e.jsxs("div",{className:"bg-gray-100 p-4 rounded-lg",children:[e.jsx(_,{title:k,isWorkflowUpdate:s,className:w,children:e.jsxs("div",{className:"flex-1 prose prose-sm max-w-none",children:[d==="markdown"?e.jsx("div",{className:m,dangerouslySetInnerHTML:{__html:g(a.text||"")}}):e.jsx("pre",{className:`whitespace-pre-wrap ${m}`,children:a.text||""}),v]})}),e.jsx("div",{className:"flex justify-end mt-2",children:!!l&&e.jsx("div",{className:"ml-2 flex-shrink-0",children:e.jsx(N,{checkpointId:l,onRestore:()=>{console.log(`Workflow restored from ${s?"workflow update":"debug"} checkpoint`)},title:s?`Restore to this version (Version ${l})`:`Restore checkpoint ${l}`})})})]})}):null}export{D as DebugResult};
import{j as e}from"./vendor-markdown-CBmlBP6m.js";import{r as o}from"./vendor-react-Dixhfmvb.js";import{b as j,c as b,B as y,R as N}from"./message-components-DmxYkzGi.js";const _=c=>{const{title:i="",isWorkflowUpdate:h=!1,className:d="",children:x}=c,[a,u]=o.useState(!1),l=h?"#166534":"#E5E7EB";return e.jsxs("div",{className:`relative shadow-gray-200 dark:shadow-gray-600 rounded-lg p-2 overflow-hidden ${d} ${a?"h-auto":"h-[200px]"}`,children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("div",{children:typeof i=="string"?e.jsx("h3",{className:"text-sm text-gray-900 dark:text-white font-medium",children:i}):i}),e.jsx("button",{onClick:()=>{console.log("setOpen--->"),u(!a)},children:a?e.jsx(j,{color:l}):e.jsx(b,{color:l})})]}),e.jsx("div",{className:"dark:border-gray-700",children:x}),!a&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 h-40 w-full z-5 bg-gradient-to-t from-[#fff] to-transparent pointer-events-none"})]})};function D({content:c,name:i="Assistant",avatar:h,format:d="markdown",onFinishLoad:x}){o.useEffect(()=>{x?.()},[]);const[a,u]=o.useState(null),[l,f]=o.useState(null),[s,p]=o.useState(!1);o.useEffect(()=>{try{const r=JSON.parse(c);if(u(r),r.ext){let t=r.ext.find(n=>n.type==="workflow_rewrite_checkpoint"||n.type==="debug_checkpoint"&&n.data?.checkpoint_type==="workflow_rewrite_start");t&&t.data&&t.data.checkpoint_id?(f(t.data.checkpoint_id),p(!0)):(t=r.ext.find(n=>n.type==="workflow_rewrite_complete"),t&&t.data&&t.data.version_id?(f(t.data.version_id),p(!0)):(t=r.ext.find(n=>n.type==="debug_checkpoint"),t&&t.data&&t.data.checkpoint_id&&(f(t.data.checkpoint_id),p(!1)))),r.ext.find(n=>n.type==="workflow_update")&&p(!0)}}catch(r){console.error("Failed to parse DebugResult content:",r)}},[c]);const g=r=>d==="markdown"?r.replace(/\*\*(.*?)\*\*/g,"<strong>$1</strong>").replace(/\*(.*?)\*/g,"<em>$1</em>").replace(/`(.*?)`/g,'<code class="bg-gray-100 px-1 rounded">$1</code>').replace(/\n/g,"<br/>"):r,w=o.useMemo(()=>s?"bg-green-50 border border-green-200":"bg-gray-100",[s]),m=o.useMemo(()=>s?"text-green-700 text-sm leading-relaxed":"text-gray-700 text-sm leading-relaxed",[s]),k=o.useMemo(()=>s?e.jsxs("div",{className:"flex items-center",children:[e.jsx("svg",{className:"w-5 h-5 text-green-600 mr-2",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),e.jsx("h4",{className:"text-green-800 font-medium",children:"Workflow Updated Successfully"})]}):null,[s]),v=o.useMemo(()=>s?e.jsx("div",{className:"mt-3 text-xs text-green-600",children:"💡 If you're not satisfied with the changes, click the restore button to revert to the previous version."}):null,[s]);return console.log("responseData-",a),a?e.jsx(y,{name:i,children:e.jsxs("div",{className:"bg-gray-100 p-4 rounded-lg",children:[e.jsx(_,{title:k,isWorkflowUpdate:s,className:w,children:e.jsxs("div",{className:"flex-1 prose prose-sm max-w-none",children:[d==="markdown"?e.jsx("div",{className:m,dangerouslySetInnerHTML:{__html:g(a.text||"")}}):e.jsx("pre",{className:`whitespace-pre-wrap ${m}`,children:a.text||""}),v]})}),e.jsx("div",{className:"flex justify-end mt-2",children:!!l&&e.jsx("div",{className:"ml-2 flex-shrink-0",children:e.jsx(N,{checkpointId:l,onRestore:()=>{console.log(`Workflow restored from ${s?"workflow update":"debug"} checkpoint`)},title:s?`Restore to this version (Version ${l})`:`Restore checkpoint ${l}`})})})]})}):null}export{D as DebugResult};
@@ -1,7 +1,7 @@
function getImportPath(filename) {
return `./${filename}`;
}
import{j as ue}from"./vendor-markdown-CBmlBP6m.js";import{W as Si,h as Ba,a as Bt}from"./message-components-9chzfzs4.js";import{g as _u,R as Oe,b as Wa,r as g,d as Ca,a as Ou}from"./vendor-react-Dixhfmvb.js";var ns={exports:{}};/*!
import{j as ue}from"./vendor-markdown-CBmlBP6m.js";import{W as Si,h as Ba,a as Bt}from"./message-components-DmxYkzGi.js";import{g as _u,R as Oe,b as Wa,r as g,d as Ca,a as Ou}from"./vendor-react-Dixhfmvb.js";var ns={exports:{}};/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
+3 -3
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+36 -2
View File
@@ -2,7 +2,7 @@
* @Author: ai-business-hql qingli.hql@alibaba-inc.com
* @Date: 2025-06-24 16:29:05
* @LastEditors: ai-business-hql qingli.hql@alibaba-inc.com
* @LastEditTime: 2025-08-01 22:58:28
* @LastEditTime: 2025-08-02 11:33:35
* @FilePath: /comfyui_copilot/ui/src/apis/workflowChatApi.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
@@ -91,7 +91,41 @@ export namespace WorkflowChatAPI {
return Promise.resolve();
}
// 把img文件存储到comfyUI本地
export async function uploadImage(imageFile: File): Promise<{ name: string }> {
try {
const formData = new FormData();
formData.append('image', imageFile);
formData.append('type', 'input');
const response = await fetchApi(`/upload/image`, {
method: 'POST',
headers: {
'Accept': '*/*',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
'Cache-Control': 'max-age=0',
'Comfy-User': '',
'Origin': BASE_URL,
'Referer': `${BASE_URL}/`,
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
},
body: formData,
});
if (!response.ok) {
throw new Error(`Upload failed: ${response.status} ${response.statusText}`);
}
const result = await response.json();
return result;
} catch (error) {
console.error('Error uploading image:', error);
throw error;
}
}
export async function* streamInvokeServer(
sessionId: string,
@@ -149,7 +183,7 @@ export namespace WorkflowChatAPI {
const content: any[] = [
{
type: 'input_text',
text: prompt
text: prompt + ' Current image filenames: ' + images.map(image => image.name).join(', ')
}
];
+5 -2
View File
@@ -406,7 +406,8 @@ export default function WorkflowChat({ onClose, visible = true, triggerUsage = f
sessionId,
input,
uploadedImages.map(img => ({
url: img.url
url: img.url,
name: img.file.name
})),
null,
modelExt,
@@ -482,7 +483,8 @@ export default function WorkflowChat({ onClose, visible = true, triggerUsage = f
sessionId,
content,
uploadedImages.map(img => ({
url: img.url
url: img.url,
name: img.file.name
})),
null,
modelExt,
@@ -743,6 +745,7 @@ export default function WorkflowChat({ onClose, visible = true, triggerUsage = f
body: formData
});
const data = await response.json();
await WorkflowChatAPI.uploadImage(file);
return data.success ? {
url: data.data,
file,