Files
AIDC-AI-ComfyUI-Copilot/dist/copilot_web/DebugGuide-DLGkTPB4.js
T

6 lines
4.0 KiB
JavaScript

function getImportPath(filename) {
return `./${filename}`;
}
import{j as o}from"./vendor-markdown-CBmlBP6m.js";import{r as a}from"./vendor-react-Dixhfmvb.js";import{B as D,g as y,W as w,a as h}from"./message-components-wGrDwG40.js";const I=({checkpointId:l,onRestore:x})=>{const[u,p]=a.useState(!1),n=async()=>{if(!u){p(!0);try{const i=await w.restoreWorkflowCheckpoint(l),g=i.workflow_data_ui||i.workflow_data;g&&(i.workflow_data_ui?h.loadGraphData(g):h.loadApiJson(g),console.log(`Restored workflow checkpoint ${l}`),x())}catch(i){console.error("Failed to restore checkpoint:",i),alert("Failed to restore workflow checkpoint. Please try again.")}finally{p(!1)}}};return o.jsx("button",{onClick:n,disabled:u,className:`p-1 rounded transition-colors ${u?"text-gray-400 cursor-not-allowed":"text-gray-500 hover:text-blue-600 hover:bg-blue-50"}`,title:`Restore checkpoint ${l}`,children:o.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor",className:u?"animate-spin":"",children:[o.jsx("path",{d:"M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z"}),o.jsx("path",{d:"M8 4.466V2.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 6.658A.25.25 0 0 1 8 6.466z"})]})})};function M({content:l,name:x="Assistant",avatar:u,onAddMessage:p,onUpdateMessage:n,onFinishLoad:i,messageId:g}){const[f,_]=a.useState(!1),[E,O]=a.useState(""),[R,S]=a.useState(!1),[v,j]=a.useState(null);a.useEffect(()=>{i?.()},[]);const r=a.useMemo(()=>{try{return JSON.parse(l)}catch(e){return console.error("Failed to parse message content:",e),null}},[l]),b=a.useMemo(()=>{if(!r||!r.ext)return null;const e=r.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},[r])||v,C=async()=>{if(f)return;const e=y(),t={id:e,role:"ai",content:JSON.stringify({text:`🔍 Starting workflow analysis...
`,ext:[]}),format:"markdown",name:"Assistant",finished:!1,debugGuide:!0};p?.(t);try{await N(),await A(e)}finally{_(!1)}},N=async()=>{try{const e=await h.graphToPrompt(),t=localStorage.getItem("sessionId")||"";if(t&&e){const s=await w.saveWorkflowCheckpoint(t,e.output,e.workflow,"debug_start");if(j(s.version_id),console.log(`Saved debug start checkpoint: ${s.version_id}`),n&&r){const c=[...r.ext||[]].filter(m=>m.type!=="debug_start_checkpoint"&&!(m.type==="debug_checkpoint"&&m.data?.checkpoint_type==="debug_start"));c.push({type:"debug_start_checkpoint",data:{checkpoint_id:s.version_id,checkpoint_type:"debug_start"}});const k={id:g||y(),role:"ai",content:JSON.stringify({text:r.text,ext:c}),format:"debug_guide",name:"Assistant"};n(k)}}}catch(e){console.error("Failed to save checkpoint before debug:",e)}},A=async e=>{try{const t=await h.graphToPrompt();let s="",d=null;for await(const c of w.streamDebugAgent(t))if(c.text){s=c.text,c.ext&&(d=c.ext);const k={id:e,role:"ai",content:JSON.stringify({text:s,ext:d||[]}),format:"markdown",name:"Assistant",finished:!1,debugGuide:!0};n?.(k)}n?.({id:e,role:"ai",content:JSON.stringify({text:s,ext:d||[]}),format:"markdown",name:"Assistant",finished:!0,debugGuide:!0})}catch(t){console.error("Error calling debug agent:",t),S(!1);const d={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};n?.(d)}};return r?o.jsx(D,{name:x,children:o.jsxs("div",{className:"bg-gray-100 p-4 rounded-lg",children:[o.jsxs("div",{className:"flex justify-between items-start",children:[o.jsx("p",{className:"text-gray-700 text-sm flex-1",children:r.text}),b&&o.jsx("div",{className:"ml-2 flex-shrink-0",children:o.jsx(I,{checkpointId:b,onRestore:()=>{console.log("Workflow restored from checkpoint")}})})]}),o.jsx("div",{className:"flex mt-4",children:o.jsx("button",{onClick:C,disabled:f,className:`px-4 py-2 text-white text-sm rounded-md transition-colors ${f?"bg-gray-400 cursor-not-allowed":"bg-blue-500 hover:bg-blue-600"}`,children:f?"Analyzing...":"Debug Errors"})})]})}):null}export{M as DebugGuide};