1import{r as o}from"./react-vendor-Dc5dhXQW.js";import{u as W,y as Y,Q as f,p as M}from"./index-DuU_YjY9.js";import{u as B}from"./i18n-vendor-CyU1p4Oa.js";import"./ui-vendor-CrBP-qRZ.js";import"./utils-vendor-DBzSxgRl.js";import"./markdown-vendor-elH94dlU.js";import"./dnd-vendor-zA92mhJ9.js";const z=c=>{const h=c.match(/^(.*)[/\\]/);return h?h[1]:c},te=()=>{const{t:c}=B(),{selectedAgent:h}=W(),[F,b]=o.useState([]),[n,g]=o.useState(null),[L,O]=o.useState([]),[T,C]=o.useState(!1),[y,u]=o.useState(""),[_,w]=o.useState(""),[I,d]=o.useState(!1),[U,S]=o.useState(null),[i,A]=o.useState([]),{message:r}=Y();o.useEffect(()=>{(async()=>{const t=n==null?void 0:n.filename;u(""),w(""),C(!1);const s=await k(),a=await f.listFiles(),l=D(a,s);if(b(l),await m(),a.length>0?S(z(a[0].path)):S(""),t){const p=l.find(E=>E.filename===t);p?await v(p):g(null)}else g(null)})()},[h]),o.useEffect(()=>{if(F.length>0&&i.length>=0){const e=D(F,i);e.some((s,a)=>{var l;return s.filename!==((l=F[a])==null?void 0:l.filename)})&&b(e)}},[i]);const k=async()=>{try{const e=await f.getSystemPromptFiles(),t=Array.isArray(e)?e:[];return A(t),t}catch(e){return console.error("Failed to fetch enabled files",e),[]}},D=(e,t)=>{const s=Array.isArray(t)?t:[];return[...e].sort((a,l)=>{const p=s.indexOf(a.filename),E=s.indexOf(l.filename),R=p!==-1,P=E!==-1;return R&&P?p-E:R?-1:P?1:a.filename.localeCompare(l.filename)})},x=async e=>{try{const t=Array.isArray(e)?e:await k(),s=await f.listFiles(),a=D(s,t);b(a),await m(),s.length>0?S(z(s[0].path)):S("")}catch(t){console.error("Failed to fetch files",t),r.error("Failed to load file list")}},m=async()=>{try{const e=await M.listDailyMemory();O(e)}catch(e){console.error("Failed to fetch daily memories",e),r.error("Failed to load memory list")}},v=async e=>{e.filename==="MEMORY.md"&&C(t=>(t||m(),!t)),g(e),d(!0);try{const t=await f.loadFile(e.filename);u(t.content),w(t.content)}catch(t){console.error("Failed to load file",t),r.error("Failed to load file")}finally{d(!1)}};return{files:F,selectedFile:n,dailyMemories:L,expandedMemory:T,fileContent:y,loading:I,workspacePath:U,hasChanges:y!==_,enabledFiles:i,setFileContent:u,fetchFiles:x,fetchDailyMemories:m,handleFileClick:v,handleDailyMemoryClick:async e=>{g({filename:e.filename,path:e.path,size:e.size,created_time:e.created_time,modified_time:e.modified_time,updated_at:e.updated_at,memory_path:e.filename}),d(!0);try{const t=await M.loadDailyMemory(e.filename);u(t.content),w(t.content)}catch(t){console.error("Failed to load daily memory",t),r.error("Failed to load daily memory")}finally{d(!1)}},toggleExpandedMemory:()=>{C(e=>(e||m(),!e))},handleSave:async()=>{if(n){d(!0);try{n.memory_path?await M.saveDailyMemory(n.memory_path,y):await M.saveFile(n.filename,y),w(y),r.success("Saved successfully"),n.memory_path?m():x()}catch(e){console.error("Failed to save file",e),r.error("Failed to save")}finally{d(!1)}}},handleReset:()=>{u(_)},handleToggleFileEnabled:async e=>{!i.includes(e)&&e==="MEMORY.md"&&r.warning({content:c("workspace.memoryFileWarning"),duration:5});const s=i.includes(e)?i.filter(a=>a!==e):[...i,e];try{await f.setSystemPromptFiles(s),A(s),r.success(c("workspace.configUpdated")||"System prompt configuration updated")}catch(a){console.error("Failed to update system prompt files",a),r.error(c("workspace.configUpdateFailed")||"Failed to update system prompt configuration")}},handleReorderFiles:async e=>{try{await f.setSystemPromptFiles(e),A(e)}catch(t){console.error("Failed to reorder files",t),r.error("Failed to update file order")}}}};export{te as useAgentsData};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.