"use strict";exports.id=1961,exports.ids=[1961],exports.modules={61961:(a,b,c)=>{c.r(b),c.d(b,{generateWithCodex:()=>i});var d=c(73024),e=c(76760),f=c.n(e),g=c(59377),h=c(91388);async function i(a){await (0,g.dt)();let b=(0,g.He)(),c=await j(b),e=(0,g.Tf)().startThread({sandboxMode:"workspace-write",additionalDirectories:[b],approvalPolicy:"never",skipGitRepoCheck:!0}),i=[`$imagegen — generate one image.`,a.size?`Size: ${a.size}.`:"","After it is saved, print exactly one line:","RESULT_PATH=<absolute path to the saved file>","Then stop. Do not move the file; do not generate variants.","",`Image description: ${a.prompt}`].filter(Boolean).join("\n"),l="";try{l=(await e.run(i)).finalResponse??""}catch(b){let a=b instanceof Error?b.message:String(b);throw Error(`codex image-gen failed: ${a.slice(0,400)}`)}finally{await (0,g.Nb)(e.id)}let m=function(a){let b=/RESULT_PATH\s*=\s*([^\r\n]+?)\s*$/m.exec(a.trim());if(!b)return null;let c=b[1].trim().replace(/^['"]|['"]$/g,"");return c.length>0?c:null}(l);if(!m||!await k(m)){let a=function(a,b){let c=null;for(let[d,e]of b.files){let b=a.files.get(d);(void 0===b||e>b)&&(!c||e>c.mtime)&&(c={path:d,mtime:e})}return c?.path??null}(c,await j(b));a&&(m=a)}if(!m)throw Error(`Codex finished but no image file was found in ${b}. Last response: ${function(a,b){let c=a.trim();return c.length>200?"…"+c.slice(c.length-b):c}(l,200)}`);let n=await d.promises.readFile(m),o=f().extname(m).slice(1).toLowerCase()||"png",p=(0,h.tf)(o);return(0,h.YN)(a.rootId,n,p)}async function j(a){let b,c=new Map;try{b=await d.promises.readdir(a)}catch{return{files:c}}return await Promise.all(b.map(async b=>{let e=f().join(a,b);try{let a=await d.promises.stat(e);a.isFile()&&c.set(e,a.mtimeMs)}catch{}})),{files:c}}async function k(a){try{return(await d.promises.stat(a)).isFile()}catch{return!1}}}};