import{o as t}from"./rolldown-runtime-iuO8RvI4.js";import{Ay as r}from"./shared-0-C4kdVF7Y.js";import{Mi as e}from"./vendor-frame-CwiylG4Y.js";var o=t(e());function i(t){const[e,i]=(0,o.useState)({autoMemoryDir:null,isSupported:!1,isLoading:!0}),[n,s]=(0,o.useState)(t);return n!==t&&(s(t),i({autoMemoryDir:null,isSupported:!1,isLoading:!0})),(0,o.useEffect)(()=>{let e=!0;const o=r?.getAutoMemoryDir;if(o)return o(t).then(t=>{e&&i({autoMemoryDir:t??null,isSupported:!0,isLoading:!1})}).catch(()=>{e&&i({autoMemoryDir:null,isSupported:!0,isLoading:!1})}),()=>{e=!1};i({autoMemoryDir:null,isSupported:!1,isLoading:!1})},[t]),e}function n(t,e=!0){const[i,n]=(0,o.useState)([]),[s,u]=(0,o.useState)(!0);return(0,o.useEffect)(()=>{if(!e)return;const o=r?.getAutoMemoryDir,i=r?.listFolderContents;if(!o||!i)return n([]),void u(!1);let s=!1;return u(!0),(async()=>{try{const r=await o(t);if(s)return;if(!r)return n([]),void u(!1);const e=await i(t,r)??[];if(s)return;n(e.filter(t=>!t.isDirectory&&t.name.endsWith(".md")&&"MEMORY.md"!==t.name)),u(!1)}catch{if(s)return;n([]),u(!1)}})(),()=>{s=!0}},[t,e]),{files:i,isLoading:s}}export{n,i as t};