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