import{Y as e}from"./BW-sf0N4.js";async function t(e,t,n,r){let i=new FormData;i.append(`file`,r);let a=await fetch(`/api/repos/${encodeURIComponent(e)}/entities/${encodeURIComponent(t)}/${encodeURIComponent(n)}/assets`,{method:`POST`,body:i});if(!a.ok){let e=await a.json().catch(()=>({error:a.statusText}));throw Error(e.error??`Upload failed`)}return a.json()}async function n(e){let t=await fetch(`/api/workspace/assets`,{signal:e});if(!t.ok){let e=await t.json().catch(()=>({error:t.statusText}));throw Error(e.error??`Failed to list workspace assets`)}return t.json()}async function r(e,t,n,r){let i=await fetch(`/api/repos/${encodeURIComponent(e)}/entities/${encodeURIComponent(t)}/${encodeURIComponent(n)}/assets/${encodeURIComponent(r)}`,{method:`DELETE`});if(!i.ok){let e=await i.json().catch(()=>({error:i.statusText}));throw Error(e.error??`Delete failed`)}}async function i(t,n,r){await e(`/api/repos/${encodeURIComponent(t)}/assets/${encodeURIComponent(n)}/${encodeURIComponent(r)}`,{method:`DELETE`})}async function a(t,n,r){return(await e(`/api/repos/${encodeURIComponent(t)}/assets/${encodeURIComponent(n)}/create-entry`,{method:`POST`,body:JSON.stringify(r?{name:r}:{})})).entities??[]}async function o(t,n,r){await e(`/api/repos/${encodeURIComponent(t)}/assets/${encodeURIComponent(n)}/move`,{method:`POST`,body:JSON.stringify({targetRepo:r})})}async function s(e){let t=await fetch(`/api/workspace/assets/manager`,{signal:e});if(!t.ok){let e=await t.json().catch(()=>({error:t.statusText}));throw Error(e.error??`Failed to load assets`)}return t.json()}async function c(){let e=await fetch(`/api/workspace/assets/store`);if(!e.ok){let t=await e.json().catch(()=>({error:e.statusText}));throw Error(t.error??`Failed to resolve the Assets store`)}return(await e.json()).repo}async function l(e,t){let n=await fetch(`/api/repos/${encodeURIComponent(e)}/entities/asset/${encodeURIComponent(t)}`,{method:`DELETE`});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error??`Delete failed`)}}async function u(e,t){if(!e)return[];let n=await fetch(`/api/workspace/assets/${encodeURIComponent(e)}/references`,{signal:t});if(!n.ok){let e=await n.json().catch(()=>({error:n.statusText}));throw Error(e.error??`Failed to load references`)}return(await n.json()).references}async function d(e,t){let n=t??await c(),r=new FormData;r.append(`file`,e);let i=await fetch(`/api/repos/${encodeURIComponent(n)}/assets`,{method:`POST`,body:r});if(!i.ok){let e=await i.json().catch(()=>({error:i.statusText}));throw Error(e.error??`Upload failed`)}}async function f(e){let t=await c(),n=new FormData;n.append(`file`,e);let r=await fetch(`/api/repos/${encodeURIComponent(t)}/assets`,{method:`POST`,body:n});if(!r.ok){let e=await r.json().catch(()=>({error:r.statusText}));throw Error(e.error??`Upload failed`)}let i=await r.json();return{repo:t,assetId:i.assetId,filename:i.filename,asset_url:i.asset_url,asset_kind:i.asset_kind}}export{u as a,o as c,f as d,l as i,t as l,r as n,s as o,i as r,n as s,a as t,d as u};