import{A as b,a as l,b as f,c as w,d as h,e as u,f as y,g as m,h as A}from"./contracts.generated-CTgVTh-H.js";import{z as d}from"./jwt-decode.esm-BYfS37aG.js";(function(){try{var o=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(o._sentryDebugIds=o._sentryDebugIds||{},o._sentryDebugIds[t]="a765b6a1-17bf-4a05-873d-2250a556c4b1",o._sentryDebugIdIdentifier="sentry-dbid-a765b6a1-17bf-4a05-873d-2250a556c4b1")}catch{}})();const S=d.object({valid:d.boolean(),error:d.string().nullable()});class E{async list(t,e){const a=new URLSearchParams;t&&a.append("path",t),e&&a.append("mode",e);const r=await(await fetch(`/_editor/api/codebase/files?${a.toString()}`)).json();return b.parse(r)}async create(t,e,a){const s=new URLSearchParams;a&&s.append("overwrite","true");const r=s.toString(),n=r?`/_editor/api/codebase/files/${t}?${r}`:`/_editor/api/codebase/files/${t}`,i=await fetch(n,{method:"POST",body:e?new Uint8Array(e).buffer:void 0});if(!i.ok){const p=await i.text();throw new Error(`Failed to create file: ${p} (status: ${i.status})`)}const c=await i.json();return l.parse(c)}async delete(t){const e=await fetch(`/_editor/api/codebase/files/${t}`,{method:"DELETE",headers:{"Content-Type":"application/json"}});if(!e.ok){const s=await e.text();throw new Error(`Failed to delete file: ${s} (status: ${e.status})`)}const a=await e.json();return f.parse(a)}async edit(t,e){const s=await(await fetch(`/_editor/api/codebase/files/${t}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e})})).json();return w.parse(s)}async retrieve(t){const e=await fetch(`/_editor/api/codebase/files/${t}`);if(!e.ok)throw new Error(`Failed to retrieve file: ${e.status}`);const a=await e.arrayBuffer();return new Uint8Array(a)}async downloadFolder(t){const e=await fetch(`/_editor/api/codebase/files-zip/${t}`);if(!e.ok){const a=await e.text();throw new Error(`Failed to download folder: ${a} (status: ${e.status})`)}return await e.blob()}async rename(t,e){const a=h.parse({pathParts:t,newPathParts:e}),s=await fetch("/_editor/api/codebase/files",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!s.ok){const n=await s.text();throw new Error(`Failed to rename file: ${n} (status: ${s.status})`)}const r=await s.json();return u.parse(r)}async mkdir(t){const e=await fetch(`/_editor/api/codebase/dir/${t}`,{method:"POST",headers:{"Content-Type":"application/json"}});if(!e.ok){const s=await e.text();throw new Error(`Failed to create directory: ${s} (status: ${e.status})`)}const a=await e.json();return y.parse(a)}async settings(){const e=await(await fetch("/_editor/api/codebase/settings")).json();return m.parse(e)}async typeCheck(t){const a=await(await fetch(`/_editor/api/codebase/type-check/${t}`,{method:"POST"})).json();return A.parse(a)}async validateAbstraJson(t){try{const e=await fetch("/_editor/api/codebase/validate-abstra-json",{method:"POST",headers:{"Content-Type":"application/json"},body:t});if(!e.ok)return{valid:!1,error:`Validation request failed: ${e.status}`};const a=await e.json();return S.parse(a)}catch{return{valid:!0,error:null}}}}export{E as C};
//# sourceMappingURL=files-CCeYtlN6.js.map
