5 lines
3.1 KiB
JavaScript
5 lines
3.1 KiB
JavaScript
function getImportPath(filename) {
|
|
return `./${filename}`;
|
|
}
|
|
import{r as g,g as f}from"./workflowChat-CQWc5SUC.js";import{a as c}from"./message-components-CP6ZQyhw.js";function p(o,t){try{if(!o)return console.error("Invalid prompt_output: ",o),o;for(const e of t){if(!o[e.nodeId]){console.error(`Node with ID ${e.nodeId} not found`);continue}if(!o[e.nodeId].inputs){console.error(`Inputs not found for node with ID ${e.nodeId}`);continue}o[e.nodeId].inputs[e.paramName]=e.paramValue}return o}catch(e){return console.error("Error updating prompt:",e),o}}async function x(o){const t=await c.graphToPrompt(),e=p(t.output,o);console.log("queuePrompt updated_prompt:",e);const s={prompt:e,client_id:c.api.clientId,extra_data:{extra_pageinfo:{workflow:t.workflow}}};console.debug("queuePrompt request_body.prompt:",e);const n=await g(s);return console.debug("queuePrompt response:",n),n}function u(o){const t=document.createElement("canvas"),e=t.getContext("2d");if(t.width=512,t.height=512,e){e.fillStyle="#f8d7da",e.fillRect(0,0,t.width,t.height),e.strokeStyle="#dc3545",e.lineWidth=4,e.strokeRect(10,10,t.width-20,t.height-20),e.fillStyle="#dc3545",e.beginPath(),e.arc(t.width/2,150,50,0,2*Math.PI),e.fill(),e.fillStyle="white",e.font="bold 80px Arial",e.textAlign="center",e.textBaseline="middle",e.fillText("!",t.width/2,150),e.fillStyle="#721c24",e.font="20px Arial",e.textAlign="center",e.textBaseline="middle";const s=t.width-60,n=30,i=o.split(" ");let r="",a=250;for(let l=0;l<i.length;l++){const d=r+i[l]+" ";e.measureText(d).width>s&&l>0?(e.fillText(r,t.width/2,a),r=i[l]+" ",a+=n):r=d}e.fillText(r,t.width/2,a)}return t.toDataURL("image/png")}async function m(o){try{if(!o||o==="")return console.log("No prompt ID provided"),{1:[u("Fail to generate prompt ID")]};const t=await f(o);if(!t||!t[o])return console.log("Not finished for prompt ID:",o),{};const e=t[o];if(e.status&&e.status.status_str==="error"){console.error("Error for prompt ID:",o);const n=e.status.messages;if(n&&n.length>0){const i=n[n.length-1];if(i&&i.length>0){const r=i[0];return{1:[u(r)]}}}}const s={};if(e.outputs)for(const n in e.outputs){const i=e.outputs[n];if(i&&i.images){s[n]=[];for(const r of i.images)if(r&&r.filename&&r.type){const a=c.graph._nodes_by_id[n].imgs[0].currentSrc.split("?")[0];s[n].push(a+"?filename="+encodeURIComponent(r.filename)+"&type="+encodeURIComponent(r.type)+(r.subfolder?"&subfolder="+encodeURIComponent(r.subfolder):""))}console.log("outputImages for nodeId:",n,s[n])}}return s}catch(t){throw console.error("Error getting output images from prompt:",t),t}}function b(){const o=Object.values(c.graph._nodes_by_id),t=[],e=[];for(const s of o)s.type==="SaveImage"?t.push(s.id):s.type==="PreviewImage"&&e.push(s.id);if(console.log("saveNodeIds:",t),console.log("previewNodeIds:",e),t.length===0&&e.length===0)throw new Error("No SaveImage or PreviewImage node found, please add one to the graph");return t.length===1?t[0]:t.length==0&&e.length===1?e[0]:null}async function v(o,t){const e=await m(o);return Object.keys(e).length===0?null:e[t.toString()]&&e[t.toString()].length>0?e[t.toString()][0]:null}export{v as a,b as g,x as q};
|