"use strict";exports.id=3295,exports.ids=[3295],exports.modules={13295:(a,b,c)=>{c.d(b,{bp:()=>o,listWorkflows:()=>l,lq:()=>q,ni:()=>k,r$:()=>n,readWorkflow:()=>m,v:()=>p});var d=c(73024),e=c(76760),f=c.n(e),g=c(13474);function h(a){return f().join((0,g.FF)(a),"workflows")}function i(a,b){return f().join(h(a),`${k(b)}.json`)}function j(a,b){return f().join(h(a),"runs",k(b))}function k(a){return a.replace(/[^A-Za-z0-9_-]/g,"-").slice(0,80)}async function l(a){let b,c=h(a);try{b=await d.promises.readdir(c,{withFileTypes:!0})}catch{return[]}let e=[];for(let a of b)if(a.isFile()&&a.name.toLowerCase().endsWith(".json"))try{let b=await d.promises.readFile(f().join(c,a.name),"utf8"),g=JSON.parse(b);r(g)&&e.push(g)}catch{}return e.sort((a,b)=>a.updatedAt<b.updatedAt?1:-1),e}async function m(a,b){try{let c=await d.promises.readFile(i(a,b),"utf8"),e=JSON.parse(c);return r(e)?e:null}catch{return null}}async function n(a,b){if(!r(b))throw Error(`Invalid workflow (id=${b.id})`);await d.promises.mkdir(h(a),{recursive:!0}),await d.promises.writeFile(i(a,b.id),JSON.stringify(b,null,2)+"\n","utf8")}async function o(a,b){var c,e;await d.promises.mkdir(j(a,b.workflowId),{recursive:!0}),await d.promises.writeFile((c=b.workflowId,e=b.id,f().join(j(a,c),`${k(e)}.json`)),JSON.stringify(b,null,2)+"\n","utf8")}async function p(a,b,c=20){let e,g=j(a,b);try{e=await d.promises.readdir(g,{withFileTypes:!0})}catch{return[]}let h=(await Promise.all(e.filter(a=>a.isFile()&&a.name.toLowerCase().endsWith(".json")).map(async a=>{let b=f().join(g,a.name);try{let a=await d.promises.stat(b);return{abs:b,mtime:a.mtimeMs}}catch{return null}}))).filter(a=>null!==a).sort((a,b)=>b.mtime-a.mtime).slice(0,c),i=[];for(let a of h)try{let b=await d.promises.readFile(a.abs,"utf8");i.push(JSON.parse(b))}catch{}return i}async function q(a,b){let c,e=j(a,b);try{c=await d.promises.readdir(e,{withFileTypes:!0})}catch{return}for(let a of(await Promise.all(c.filter(a=>a.isFile()&&a.name.toLowerCase().endsWith(".json")).map(async a=>{let b=f().join(e,a.name);try{let a=await d.promises.stat(b);return{abs:b,mtime:a.mtimeMs}}catch{return null}}))).filter(a=>null!==a).sort((a,b)=>b.mtime-a.mtime).slice(50))await d.promises.unlink(a.abs).catch(()=>void 0)}function r(a){return!!a&&"object"==typeof a&&"string"==typeof a.id&&!!a.id&&"string"==typeof a.label&&!!Array.isArray(a.steps)&&"string"==typeof a.createdAt&&"string"==typeof a.updatedAt}}};