Files
AIDC-AI-ComfyUI-Copilot/dist/copilot_web/DebugGuide-DP0AcToc.js
T
2025-07-30 19:12:40 +08:00

6 lines
3.3 KiB
JavaScript

function getImportPath(filename) {
return `./${filename}`;
}
import{j as s}from"./vendor-markdown-CBmlBP6m.js";import{r as a}from"./vendor-react-Dixhfmvb.js";import{B as I,g as f,a as m,W as h}from"./message-components-wGrDwG40.js";import{R as E}from"./RestoreCheckpoint-BrtKNi_a.js";import"./workflowChat-RYPHa_zg.js";import"./input.js";/* empty css */import"./App-g1ugXgXg.js";function F({content:p,name:x="Assistant",avatar:A,onAddMessage:k,onUpdateMessage:c,onFinishLoad:b,messageId:y}){const[l,w]=a.useState(!1),[D,O]=a.useState(""),[J,_]=a.useState(!1),[S,j]=a.useState(null);a.useEffect(()=>{b?.()},[]);const r=a.useMemo(()=>{try{return JSON.parse(p)}catch(e){return console.error("Failed to parse message content:",e),null}},[p]),g=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])||S,v=async()=>{if(l)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};k?.(t);try{await N(),await C(e)}finally{w(!1)}},N=async()=>{try{const e=await m.graphToPrompt(),t=localStorage.getItem("sessionId")||"";if(t&&e){const o=await h.saveWorkflowCheckpoint(t,e.output,e.workflow,"debug_start");if(j(o.version_id),console.log(`Saved debug start checkpoint: ${o.version_id}`),c&&r){const n=[...r.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 d={id:y||f(),role:"ai",content:JSON.stringify({text:r.text,ext:n}),format:"debug_guide",name:"Assistant"};c(d)}}}catch(e){console.error("Failed to save checkpoint before debug:",e)}},C=async e=>{try{const t=await m.graphToPrompt();let o="",i=null;for await(const n of h.streamDebugAgent(t))if(n.text){o=n.text,n.ext&&(i=n.ext);const d={id:e,role:"ai",content:JSON.stringify({text:o,ext:i||[]}),format:"markdown",name:"Assistant",finished:!1,debugGuide:!0};c?.(d)}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),_(!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 r?s.jsx(I,{name:x,children:s.jsxs("div",{className:"bg-gray-100 pt-4 px-4 pb-3 rounded-lg",children:[s.jsx("div",{className:"flex justify-between items-start",children:s.jsx("p",{className:"text-gray-700 text-sm flex-1",children:r.text})}),s.jsx("div",{className:"flex mt-4",children:s.jsx("button",{onClick:v,disabled:l,className:`px-4 py-2 text-white text-sm rounded-md transition-colors ${l?"bg-gray-400 cursor-not-allowed":"bg-blue-500 hover:bg-blue-600"}`,children:l?"Analyzing...":"Debug Errors"})}),s.jsx("div",{className:"flex justify-end mt-2",children:!!g&&s.jsx("div",{className:"ml-2 flex-shrink-0",children:s.jsx(E,{checkpointId:g,onRestore:()=>{console.log("Workflow restored from checkpoint")}})})})]})}):null}export{F as DebugGuide};