@rubytech/create-maxy-code 0.1.384 → 0.1.387

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/dist/__tests__/cron-heartbeat-registration.test.js +5 -0
  2. package/dist/cron-registration.js +1 -0
  3. package/dist/index.js +4 -0
  4. package/package.json +1 -1
  5. package/payload/platform/neo4j/schema.cypher +36 -1
  6. package/payload/platform/plugins/.claude-plugin/marketplace.json +5 -0
  7. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +73 -2
  8. package/payload/platform/plugins/docs/references/admin-ui.md +12 -1
  9. package/payload/platform/plugins/docs/references/graph.md +11 -0
  10. package/payload/platform/plugins/docs/references/plugins-guide.md +1 -0
  11. package/payload/platform/plugins/docs/references/sweep-guide.md +43 -0
  12. package/payload/platform/plugins/memory/references/schema-estate-agent.md +34 -0
  13. package/payload/platform/plugins/scheduling/PLUGIN.md +17 -1
  14. package/payload/platform/plugins/scheduling/mcp/dist/index.js +12 -0
  15. package/payload/platform/plugins/scheduling/mcp/dist/index.js.map +1 -1
  16. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/agent-dispatch.test.d.ts +2 -0
  17. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/agent-dispatch.test.d.ts.map +1 -0
  18. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/agent-dispatch.test.js +101 -0
  19. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/agent-dispatch.test.js.map +1 -0
  20. package/payload/platform/plugins/scheduling/mcp/dist/lib/agent-dispatch.d.ts +54 -0
  21. package/payload/platform/plugins/scheduling/mcp/dist/lib/agent-dispatch.d.ts.map +1 -0
  22. package/payload/platform/plugins/scheduling/mcp/dist/lib/agent-dispatch.js +117 -0
  23. package/payload/platform/plugins/scheduling/mcp/dist/lib/agent-dispatch.js.map +1 -0
  24. package/payload/platform/plugins/scheduling/mcp/dist/lib/schedule-classify.d.ts +7 -0
  25. package/payload/platform/plugins/scheduling/mcp/dist/lib/schedule-classify.d.ts.map +1 -1
  26. package/payload/platform/plugins/scheduling/mcp/dist/lib/schedule-classify.js +6 -3
  27. package/payload/platform/plugins/scheduling/mcp/dist/lib/schedule-classify.js.map +1 -1
  28. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/agent-turn-dispatch.test.d.ts +2 -0
  29. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/agent-turn-dispatch.test.d.ts.map +1 -0
  30. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/agent-turn-dispatch.test.js +88 -0
  31. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/agent-turn-dispatch.test.js.map +1 -0
  32. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/standing-audit.test.d.ts +2 -0
  33. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/standing-audit.test.d.ts.map +1 -0
  34. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/standing-audit.test.js +77 -0
  35. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/standing-audit.test.js.map +1 -0
  36. package/payload/platform/plugins/scheduling/mcp/dist/scripts/agent-turn-dispatch.d.ts +59 -0
  37. package/payload/platform/plugins/scheduling/mcp/dist/scripts/agent-turn-dispatch.d.ts.map +1 -0
  38. package/payload/platform/plugins/scheduling/mcp/dist/scripts/agent-turn-dispatch.js +131 -0
  39. package/payload/platform/plugins/scheduling/mcp/dist/scripts/agent-turn-dispatch.js.map +1 -0
  40. package/payload/platform/plugins/scheduling/mcp/dist/scripts/check-due-events.js +62 -15
  41. package/payload/platform/plugins/scheduling/mcp/dist/scripts/check-due-events.js.map +1 -1
  42. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-event-agent.test.d.ts +2 -0
  43. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-event-agent.test.d.ts.map +1 -0
  44. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-event-agent.test.js +110 -0
  45. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-event-agent.test.js.map +1 -0
  46. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-get-agent.test.d.ts +2 -0
  47. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-get-agent.test.d.ts.map +1 -0
  48. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-get-agent.test.js +35 -0
  49. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-get-agent.test.js.map +1 -0
  50. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-agent.test.d.ts +2 -0
  51. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-agent.test.d.ts.map +1 -0
  52. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-agent.test.js +81 -0
  53. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-agent.test.js.map +1 -0
  54. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-event.d.ts +7 -0
  55. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-event.d.ts.map +1 -1
  56. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-event.js +21 -4
  57. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-event.js.map +1 -1
  58. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-get.d.ts +4 -0
  59. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-get.d.ts.map +1 -1
  60. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-get.js +6 -0
  61. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-get.js.map +1 -1
  62. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-update.d.ts +2 -1
  63. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-update.d.ts.map +1 -1
  64. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-update.js +32 -1
  65. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-update.js.map +1 -1
  66. package/payload/platform/plugins/sweep/.claude-plugin/plugin.json +8 -0
  67. package/payload/platform/plugins/sweep/PLUGIN.md +15 -0
  68. package/payload/platform/plugins/sweep/skills/sweep-workflow/SKILL.md +113 -0
  69. package/payload/platform/plugins/whatsapp/PLUGIN.md +1 -1
  70. package/payload/platform/plugins/whatsapp/mcp/dist/index.js +19 -4
  71. package/payload/platform/plugins/whatsapp/mcp/dist/index.js.map +1 -1
  72. package/payload/platform/plugins/whatsapp/references/channels-whatsapp.md +7 -4
  73. package/payload/platform/plugins/whatsapp/skills/manage-whatsapp-config/SKILL.md +10 -0
  74. package/payload/platform/scripts/seed-neo4j.sh +38 -0
  75. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts +5 -0
  76. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts.map +1 -1
  77. package/payload/platform/services/whatsapp-channel/dist/notification.js.map +1 -1
  78. package/payload/platform/services/whatsapp-channel/dist/server.js +1 -1
  79. package/payload/platform/services/whatsapp-channel/dist/server.js.map +1 -1
  80. package/payload/server/public/assets/{AdminLoginScreens-C_h8V0Xs.js → AdminLoginScreens-BejIjbmU.js} +1 -1
  81. package/payload/server/public/assets/{AdminShell-Dqnxpn7U.js → AdminShell-D2-uBSB5.js} +1 -1
  82. package/payload/server/public/assets/{Checkbox-Bl1WRVGb.js → Checkbox-1F1tzqca.js} +1 -1
  83. package/payload/server/public/assets/Transcript-DkGa4CQH.js +2 -0
  84. package/payload/server/public/assets/{admin-ByoqNaSf.js → admin-DqQARkjy.js} +1 -1
  85. package/payload/server/public/assets/{browser-BXY1sNxv.js → browser-nDtEK6RC.js} +1 -1
  86. package/payload/server/public/assets/{calendar-CObRTPpU.js → calendar-CO4Bwmho.js} +1 -1
  87. package/payload/server/public/assets/chat-DeIge_bC.js +1 -0
  88. package/payload/server/public/assets/chevron-left-DhVdq0aN.js +1 -0
  89. package/payload/server/public/assets/data-B1GIdzHk.js +1 -0
  90. package/payload/server/public/assets/{graph-BCL0fVDH.js → graph-DFyicKd7.js} +1 -1
  91. package/payload/server/public/assets/{graph-labels-C0nn9nQi.js → graph-labels-D3BQdcpD.js} +1 -1
  92. package/payload/server/public/assets/{operator-B_1qYO7m.js → operator-BxrjWdT9.js} +1 -1
  93. package/payload/server/public/assets/{page-BQEl7aZO.js → page-ByDLq_o1.js} +1 -1
  94. package/payload/server/public/assets/page-D-Ep4bXd.js +32 -0
  95. package/payload/server/public/assets/{public-BzvwPHM0.js → public-DbdqfdYq.js} +1 -1
  96. package/payload/server/public/assets/{rotate-ccw-CHep9vl5.js → rotate-ccw-BkX8HODe.js} +1 -1
  97. package/payload/server/public/assets/{useSubAccountSwitcher-B1Kf32uG.js → useSubAccountSwitcher-DMbRhLPv.js} +1 -1
  98. package/payload/server/public/assets/{useSubAccountSwitcher-CfI3J2IX.css → useSubAccountSwitcher-DS0iqSkP.css} +1 -1
  99. package/payload/server/public/browser.html +4 -4
  100. package/payload/server/public/calendar.html +5 -5
  101. package/payload/server/public/chat.html +8 -8
  102. package/payload/server/public/data.html +8 -7
  103. package/payload/server/public/graph.html +8 -8
  104. package/payload/server/public/index.html +11 -10
  105. package/payload/server/public/operator.html +10 -10
  106. package/payload/server/public/public.html +8 -8
  107. package/payload/server/server.js +556 -273
  108. package/payload/server/public/assets/Transcript-C93Lifnb.js +0 -1
  109. package/payload/server/public/assets/chat-Dq-VHp7a.js +0 -1
  110. package/payload/server/public/assets/chevron-left-DjbK_wdQ.js +0 -1
  111. package/payload/server/public/assets/data-BXOoK8Ci.js +0 -1
  112. package/payload/server/public/assets/page-Dck23z9U.js +0 -32
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CAM3fms7.js";import{C as t,D as n,L as r,M as i,P as a,_ as o,a as s,c,d as ee,f as l,g as te,h as ne,i as u,m as d,n as f,o as p,r as re,t as ie,u as ae,v as oe,w as se,x as ce,y as m}from"./useSubAccountSwitcher-B1Kf32uG.js";import{t as h}from"./chevron-left-DjbK_wdQ.js";import{i as le}from"./Transcript-C93Lifnb.js";import{i as ue,t as de}from"./graph-labels-C0nn9nQi.js";var fe=n(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),pe=n(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),me=n(`folder`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),he=n(`layout-grid`,[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]),ge=n(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),_e=n(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),g=n(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),ve=n(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]);function ye(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||de.has(e)&&(t.add(e),n.push(e)));return n}var _=e(r(),1),v=i();function y(e){if(!e)return``;let t=new Date(e).getTime();return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function be({conversations:e,sessionKey:t,onBack:n}){let[r,i]=(0,_.useState)(null),a=s(e);return r?(0,v.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,v.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,v.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>i(null),"aria-label":`Back to conversations`,children:[(0,v.jsx)(h,{size:16}),` Back`]}),(0,v.jsx)(`span`,{className:`op-conv-title`,children:p(r)})]}),(0,v.jsx)(le,{sessionId:r.sessionId,projectDir:r.projectDir,sessionKey:t,forceDeliveredOnly:!0,suppressDirectives:r.source===`store`,store:r.source===`store`?{accountId:r.accountId,remoteJid:r.remoteJid}:void 0},c(r))]}):(0,v.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,v.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,v.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,v.jsx)(h,{size:16}),` Chat`]}),(0,v.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),a.map(e=>(0,v.jsxs)(`div`,{className:`op-conv-group`,children:[(0,v.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,v.jsx)(ae,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,v.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{console.info(`[operator-ui] op=reader-open channel=${e.channel} key=${c(e)} readonly=true source=${e.source}`),i(e)},children:[(0,v.jsx)(`span`,{className:`op-conv-name`,children:p(e)}),e.modelGated&&(0,v.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,v.jsx)(g,{size:13})}),(0,v.jsx)(`span`,{className:`op-conv-when`,children:y(e.lastMessageAt)})]},c(e)))]},e.channel))]})}var b=/\.(png|jpe?g|gif|webp|svg)$/i;function xe(e){return b.test(e)}var Se=`maxy-data-view`,Ce=95*1024*1024,we=48*1024*1024;function Te(){return typeof window>`u`?`list`:window.localStorage.getItem(Se)===`grid`?`grid`:`list`}function Ee(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(!1);return(0,_.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,v.jsx)(l,{cacheKey:e,surface:`data`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=data`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,v.jsx)(`div`,{className:`data-page data-page-full`,children:(0,v.jsx)(x,{cacheKey:e})})}):(0,v.jsx)(`div`,{className:`data-page`,children:(0,v.jsxs)(`div`,{className:`data-empty`,children:[(0,v.jsx)(`p`,{children:`You are not signed in.`}),(0,v.jsxs)(`p`,{children:[`Open the `,(0,v.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,v.jsx)(`div`,{className:`data-page`,children:(0,v.jsxs)(`div`,{className:`data-loading`,children:[(0,v.jsx)(m,{size:18,className:`spin`}),` Loading…`]})})}function x({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=a({initialCacheKey:e,surface:`data`});return(0,v.jsx)(w,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})}function De(){if(typeof window>`u`)return`.`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`.`}function Oe(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=e===`.`?``:`path=${encodeURIComponent(e)}`,window.history.replaceState(window.history.state,``,t.toString())}function ke(e){return new Promise((t,n)=>{let r=[],i=()=>e.readEntries(e=>{e.length===0?t(r):(r.push(...e),i())},n);i()})}function S(e){return new Promise((t,n)=>e.file(t,n))}async function Ae(e,t=``){let n=[];for(let r of e){if(!r)continue;let e=t?`${t}/${r.name}`:r.name;if(r.isFile)n.push({file:await S(r),relpath:e});else if(r.isDirectory){let t=await ke(r.createReader());n.push(...await Ae(t,e))}}return n}function je(e,t){if(e===422&&typeof t==`string`){if(/exceeds the .* limit/i.test(t))return`size`;if(/unsupported file type/i.test(t))return`mime`}return`http=${e}`}function C({adminFetch:e,cacheKey:n,sessionRefetchNonce:r}){let[i,a]=(0,_.useState)(``),s=(0,_.useRef)(null),[c,ee]=(0,_.useState)(``),[l,p]=(0,_.useState)(null),[ie,ae]=(0,_.useState)(`hybrid`),[h,le]=(0,_.useState)(!1),[de,g]=(0,_.useState)(null),[y,be]=(0,_.useState)(null),[b,Ee]=(0,_.useState)(0),[x,ke]=(0,_.useState)(!1),[S,C]=(0,_.useState)(()=>De()),[w,Me]=(0,_.useState)(null),[T,Fe]=(0,_.useState)(()=>Te()),[E,Re]=(0,_.useState)(null),[D,ze]=(0,_.useState)([]),[O,Be]=(0,_.useState)(!1),[Ve,He]=(0,_.useState)(null),[Ue,We]=(0,_.useState)(!1),[k,A]=(0,_.useState)(null),[Ge,j]=(0,_.useState)(null),[Ke,qe]=(0,_.useState)(null),[Je,Ye]=(0,_.useState)(!1),[Xe,Ze]=(0,_.useState)(null),M=(0,_.useRef)(null),[Qe,N]=(0,_.useState)(0),[$e,P]=(0,_.useState)(!1),[et,tt]=(0,_.useState)(``),[F,I]=(0,_.useState)(null),[nt,rt]=(0,_.useState)(``),[it,L]=(0,_.useState)(null),R=(()=>{let e=S===`.`?[]:S.split(`/`).filter(Boolean);return e.length>=2&&e[0]===`accounts`})(),[z,B]=(0,_.useState)(!1),at=(0,_.useRef)(null),[V,H]=(0,_.useState)(!1),ot=(0,_.useRef)(null);(0,_.useEffect)(()=>{let e=i.trim();if(!e){ee(``),p(null),g(null);return}ke(!1);let t=setTimeout(()=>ee(e),300);return()=>clearTimeout(t)},[i]),(0,_.useEffect)(()=>{if(!c){le(!1);return}let t=!1;return le(!0),g(null),e(`/api/admin/graph-search?q=${encodeURIComponent(c)}&labels=FileArtifact&limit=20${x?`&threshold=0`:``}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(p(e.results),ae(e.mode??`hybrid`),Ee(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||g(e instanceof Error?e.message:String(e))}).finally(()=>{t||le(!1)}),()=>{t=!0}},[c,e,r,x]);let st=(0,_.useMemo)(()=>l?ye(l):[],[l]),U=y&&st.includes(y)?y:null,W=(0,_.useMemo)(()=>l?U?l.filter(e=>e.labels.includes(U)):l:null,[l,U]),ct=(0,_.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let r=`/api/admin/files/download?session_key=${encodeURIComponent(n)}&path=${encodeURIComponent(t)}`,i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()},[n]);(0,_.useEffect)(()=>{if(!l)return;let e=l.filter(e=>{let t=e.properties.relativePath;return typeof t!=`string`||t.length===0});e.length>0&&console.warn(`[data-search] op=locate-link-missing nodeId=${e.map(e=>e.nodeId).join(`,`)}`)},[l]),(0,_.useEffect)(()=>{let t=!1;return Be(!0),He(null),e(`/api/admin/files?path=${encodeURIComponent(S===`.`?``:S)}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(Me(e.entries),ze(e.displayPath??[]))}).catch(e=>{t||(Me([]),ze([]),He(e instanceof Error?e.message:String(e)))}).finally(()=>{t||Be(!1)}),()=>{t=!0}},[e,S,Qe,r]),(0,_.useEffect)(()=>{Oe(S)},[S]);let lt=(0,_.useCallback)(()=>{N(e=>e+1)},[]),G=(0,_.useCallback)(e=>{B(!1),C(e)},[]),ut=(0,_.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let n=t.lastIndexOf(`/`),r=n===-1?`.`:t.slice(0,n);console.log(`[data-search] op=locate nodeId=${e.nodeId} folder=${r}`),a(``),g(null),be(null),G(r)},[G]),dt=(0,_.useCallback)(()=>{if(S===`.`||S===``)return;let e=S.split(`/`).filter(Boolean);e.pop(),C(e.length===0?`.`:e.join(`/`))},[S]),ft=(0,_.useCallback)(e=>{re(n,S===`.`?e.name:`${S}/${e.name}`)},[S,n]),[K,pt]=(0,_.useState)(!1),[q,mt]=(0,_.useState)(new Set),ht=(0,_.useRef)(null),J=(0,_.useRef)(!1),Y=typeof navigator<`u`&&typeof navigator.share==`function`&&typeof navigator.canShare==`function`,gt=(0,_.useCallback)(e=>{pt(!0),mt(new Set([e])),console.info(`[data-ui] op=select-enter count=1`)},[]),X=(0,_.useCallback)(e=>{pt(!1),mt(new Set),console.info(`[data-ui] op=select-exit reason=${e}`)},[]),Z=(0,_.useCallback)(e=>{mt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),_t=(0,_.useCallback)(e=>{J.current=!1,ht.current=setTimeout(()=>{J.current=!0,gt(e)},500)},[gt]),Q=(0,_.useCallback)(()=>{ht.current&&=(clearTimeout(ht.current),null)},[]),vt=(0,_.useCallback)(e=>{if(J.current){J.current=!1;return}if(K){Z(e.name);return}ft(e)},[K,Z,ft]),yt=(0,_.useCallback)(e=>{Fe(e),typeof window<`u`&&window.localStorage.setItem(Se,e),console.info(`[data] op=view-mode mode=${e}`)},[]),bt=(0,_.useCallback)(e=>{if(J.current){J.current=!1;return}if(K){Z(e.name);return}Re({src:f(n,S===`.`?e.name:`${S}/${e.name}`),alt:e.displayName??e.name})},[K,Z,S,n]),xt=(0,_.useCallback)(()=>(w??[]).filter(e=>e.kind===`file`&&q.has(e.name)),[w,q]),St=(0,_.useCallback)(()=>(w??[]).filter(e=>(e.kind===`file`||e.kind===`directory`)&&q.has(e.name)),[w,q]),Ct=(0,_.useCallback)(()=>{let e=St(),t=e.some(e=>e.kind===`directory`);e.length===1&&!t?ft(e[0]):e.length>=1&&u(n,e.map(e=>S===`.`?e.name:`${S}/${e.name}`)),X(`action`)},[St,ft,S,n,X]),wt=(0,_.useCallback)(async()=>{let t=xt(),n=t.filter(e=>!e.protected),r=t.length-n.length;Ze(r>0?`${r} protected file(s) kept`:null);for(let t of n){let n=S===`.`?t.name:`${S}/${t.name}`;try{let t=await e(`/api/admin/files?path=${encodeURIComponent(n)}`,{method:`DELETE`}),r=await t.json().catch(()=>({error:`HTTP ${t.status}`}));if(!t.ok)throw Error(r.error??`HTTP ${t.status}`)}catch(e){Ze(e instanceof Error?e.message:String(e))}}N(e=>e+1),X(`action`)},[xt,S,e,X]),Tt=(0,_.useCallback)(async()=>{let e=xt();if(console.info(`[data-ui] op=share supported=${Y} count=${e.length}`),Y)try{let t=await Promise.all(e.map(async e=>{let t=S===`.`?e.name:`${S}/${e.name}`,r=`/api/admin/files/download?session_key=${encodeURIComponent(n)}&path=${encodeURIComponent(t)}`,i=await(await fetch(r)).blob();return new File([i],e.name,{type:i.type||`application/octet-stream`})}));navigator.canShare({files:t})&&await navigator.share({files:t})}catch(e){console.warn(`[data-ui] op=share-failed err=${e instanceof Error?e.message:String(e)}`)}},[xt,Y,S,n]),Et=(0,_.useCallback)(()=>{M.current?.click()},[]),Dt=(0,_.useCallback)((e,t={})=>{let r=(r,i,a)=>{let o=new URLSearchParams({session_key:n,path:S===`.`?``:S,filename:e.name});t.relpath&&o.set(`relpath`,t.relpath),t.token&&o.set(`token`,t.token);for(let[e,t]of Object.entries(i))o.set(e,t);return new Promise(t=>{let n=new XMLHttpRequest;n.open(`POST`,`/api/admin/files/upload?${o.toString()}`),n.setRequestHeader(`Content-Type`,e.type||`application/octet-stream`),a&&(n.upload.onprogress=e=>{e.lengthComputable&&a(e.loaded)}),n.onload=()=>{let e={};try{e=JSON.parse(n.responseText)}catch{}t({status:n.status,data:e})},n.onerror=()=>t({status:0,data:{}}),n.onabort=()=>t({status:0,data:{error:`aborted`}}),n.send(r)})};if(e.size<=Ce)return r(e,{},n=>t.onProgress?.(n,e.size));let i=`${Date.now().toString(36)}-${Math.random().toString(16).slice(2,10)}`,a=Math.ceil(e.size/we);return(async()=>{let n={status:0,data:{}};for(let o=0;o<a;o++){let s=o*we;if(n=await r(e.slice(s,Math.min(s+we,e.size)),{uploadId:i,seq:String(o),total:String(a)},n=>t.onProgress?.(s+n,e.size)),!(n.status>=200&&n.status<300))return n}return n})()},[n,S]),Ot=(0,_.useCallback)(async e=>{j(null),We(!0),A({loaded:0,total:e.size});try{let{status:t,data:n}=await Dt(e,{onProgress:(e,t)=>A({loaded:e,total:t})});t>=200&&t<300&&n.path?(C(n.path.split(`/`).slice(0,-1).join(`/`)||`.`),N(e=>e+1)):j(t===0?`Network error during upload — the connection failed before the server responded.`:n.error??`Upload failed (HTTP ${t}).`)}finally{We(!1),A(null),M.current&&(M.current.value=``)}},[Dt]),kt=(0,_.useCallback)(e=>{R&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),Ye(!0))},[R]),At=(0,_.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||Ye(!1)},[]),jt=(0,_.useCallback)(async e=>{e.preventDefault(),Ye(!1);let t=Math.random().toString(16).slice(2,10),n=Array.from(e.dataTransfer.items);if(console.info(`[data-ui] op=drop-received token=${t} items=${n.length}`),n.length===0)return;if(!R){console.info(`[data-ui] op=drop-rejected token=${t} reason=no-write`),j(`Open a folder inside your account to upload`);return}let r=n.map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e);We(!0),j(null),qe(null);let i=performance.now();try{let e=await Ae(r),n=e.reduce((e,t)=>e+t.file.size,0),a=new Set(e.map(e=>e.relpath.split(`/`).slice(0,-1).join(`/`)).filter(Boolean)).size;console.info(`[data-ui] op=drop-walk token=${t} files=${e.length} dirs=${a} bytes=${n}`);let o=0,s=[];for(let n=0;n<e.length;n++){let{file:r,relpath:i}=e[n];console.info(`[data-ui] op=drop-file token=${t} rel="${i}" i=${n+1}/${e.length}`),A({loaded:0,total:r.size});let{status:a,data:c}=await Dt(r,{relpath:i,token:t,onProgress:(e,t)=>A({loaded:e,total:t})});if(a>=200&&a<300)o++,console.info(`[data-ui] op=drop-file-ok token=${t} rel="${i}"`);else{let e=a===0?`http=0`:je(a,c.error);s.push(`${i} (${e})`),console.info(`[data-ui] op=drop-file-skip token=${t} rel="${i}" reason=${e}`)}}let c=Math.round(performance.now()-i);console.info(`[data-ui] op=drop-done token=${t} uploaded=${o} skipped=${s.length} ms=${c}`),qe(`Uploaded ${o}, skipped ${s.length}${s.length?`: ${s.join(`, `)}`:``}`),N(e=>e+1)}catch(e){j(e instanceof Error?e.message:String(e))}finally{We(!1),A(null)}},[R,Dt]),Mt=(0,_.useCallback)(async()=>{let t=et.trim();if(t){L(null);try{let n=await e(`/api/admin/files/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:S===`.`?``:S,name:t})}),r=await n.json().catch(()=>({error:`HTTP ${n.status}`}));if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);P(!1),tt(``),N(e=>e+1)}catch(e){L(e instanceof Error?e.message:String(e))}}},[e,et,S]),Nt=(0,_.useCallback)(async()=>{if(!F)return;let t=nt.trim();if(!t)return;L(null);let n=S===`.`?F:`${S}/${F}`;try{let r=await e(`/api/admin/files/rename`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:n,newName:t})}),i=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(i.error??`HTTP ${r.status}`);I(null),rt(``),X(`action`),N(e=>e+1)}catch(e){L(e instanceof Error?e.message:String(e))}},[e,nt,F,S,X]);(0,_.useEffect)(()=>{if(!z)return;let e=e=>{at.current&&!at.current.contains(e.target)&&B(!1)},t=e=>{e.key===`Escape`&&B(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[z]),(0,_.useEffect)(()=>{if(!V)return;let e=e=>{ot.current&&!ot.current.contains(e.target)&&H(!1)},t=e=>{e.key===`Escape`&&H(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[V]);let $=(0,_.useCallback)(e=>D.slice(0,e+1).map(e=>e.name).join(`/`),[D]),Pt=D.length>=2,Ft=Pt?[{name:`.`,label:`data`},...D.slice(0,D.length-2).map((e,t)=>({name:$(t),label:e.displayName??e.name}))]:[];return(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(`div`,{className:`data-toolbar`,children:[K?(0,v.jsxs)(`button`,{type:`button`,className:`data-select-cancel`,onClick:()=>X(`cancel`),"aria-label":`Cancel selection`,children:[(0,v.jsx)(d,{size:14}),` Cancel`]}):(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(`div`,{className:`data-search-input`,children:[i===``&&(0,v.jsx)(ue,{size:14}),(0,v.jsx)(`input`,{ref:s,type:`text`,value:i,onChange:e=>a(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),h&&(0,v.jsx)(m,{size:14,className:`spin`}),i!==``&&(0,v.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{a(``),s.current?.focus()},title:`Clear search`,"aria-label":`Clear search`,children:(0,v.jsx)(d,{size:14})})]}),(0,v.jsxs)(`div`,{className:`data-toolbar-actions`,ref:ot,children:[(0,v.jsx)(`button`,{type:`button`,className:`data-action-overflow`,onClick:()=>H(e=>!e),"aria-haspopup":`menu`,"aria-expanded":V,"aria-label":`File actions`,title:`File actions`,children:(0,v.jsx)(t,{size:16})}),(0,v.jsxs)(`div`,{className:`data-action-group`,role:`group`,"aria-label":`File actions`,"data-open":V?`true`:void 0,children:[(0,v.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{lt(),H(!1)},disabled:O,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[O?(0,v.jsx)(m,{size:16,className:`spin`}):(0,v.jsx)(o,{size:16}),(0,v.jsx)(`span`,{className:`data-action-label`,children:`Refresh`})]}),(0,v.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Et(),H(!1)},disabled:Ue||!R,title:R?`Upload a file`:`Open a folder inside your account to upload`,"aria-label":`Upload a file`,children:[Ue?k&&k.total>0?(0,v.jsxs)(`span`,{className:`data-upload-pct`,children:[Math.round(k.loaded/k.total*100),`%`]}):(0,v.jsx)(m,{size:16,className:`spin`}):(0,v.jsx)(ve,{size:16}),(0,v.jsx)(`span`,{className:`data-action-label`,children:`Upload`})]}),(0,v.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{P(e=>!e),tt(``),L(null),H(!1)},disabled:Ue||!R,title:R?`New folder`:`Open a folder inside your account to create one`,"aria-label":`New folder`,children:[(0,v.jsx)(pe,{size:16}),(0,v.jsx)(`span`,{className:`data-action-label`,children:`New folder`})]}),(0,v.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{yt(T===`grid`?`list`:`grid`),H(!1)},title:T===`grid`?`List view`:`Grid view`,"aria-label":T===`grid`?`Switch to list view`:`Switch to grid view`,"aria-pressed":T===`grid`,children:[T===`grid`?(0,v.jsx)(ge,{size:16}):(0,v.jsx)(he,{size:16}),(0,v.jsx)(`span`,{className:`data-action-label`,children:T===`grid`?`List view`:`Grid view`})]})]})]})]}),(0,v.jsxs)(`div`,{className:`data-breadcrumbs`,children:[S!==`.`&&(0,v.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-back-btn`,onClick:dt,title:`Up one level`,"aria-label":`Up one level`,children:(0,v.jsx)(fe,{size:14})}),Pt?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(`span`,{className:`data-crumb-wrap`,ref:at,children:[(0,v.jsx)(`button`,{type:`button`,className:`data-crumb data-crumb-ellipsis`,onClick:()=>B(e=>!e),"aria-haspopup":`menu`,"aria-expanded":z,"aria-label":`Show parent folders`,title:`Show parent folders`,children:`…`}),z&&(0,v.jsx)(`div`,{className:`data-crumb-menu`,role:`menu`,children:Ft.map(e=>(0,v.jsx)(`button`,{type:`button`,role:`menuitem`,className:`data-crumb-menu-item`,onClick:()=>G(e.name),title:e.label,children:e.label},e.name))})]}),[D.length-2,D.length-1].map(e=>{let t=D[e];return(0,v.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,v.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,v.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>G($(e)),title:t.name,children:t.displayName??t.name})]},$(e))})]}):(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>G(`.`),children:`data`}),D.map((e,t)=>(0,v.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,v.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,v.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>G($(t)),title:e.name,children:e.displayName??e.name})]},$(t)))]})]}),$e&&(0,v.jsxs)(`div`,{className:`data-inline-form`,children:[(0,v.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`Folder name`,value:et,autoFocus:!0,onChange:e=>tt(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Mt(),e.key===`Escape`&&P(!1)}}),(0,v.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Mt,children:`Create`}),(0,v.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>P(!1),children:`Cancel`})]}),F&&(0,v.jsxs)(`div`,{className:`data-inline-form`,children:[(0,v.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`New name`,value:nt,autoFocus:!0,onChange:e=>rt(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Nt(),e.key===`Escape`&&I(null)}}),(0,v.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Nt,children:`Rename`}),(0,v.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>I(null),children:`Cancel`})]}),it&&(0,v.jsx)(`div`,{className:`data-error`,children:it}),(0,v.jsx)(`input`,{type:`file`,ref:M,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Ot(t)}})]}),(0,v.jsxs)(`div`,{className:`data-body`,"data-drag-active":Je?`true`:void 0,onDragEnter:kt,onDragOver:kt,onDragLeave:At,onDrop:jt,children:[(de!==null||l!==null)&&(0,v.jsxs)(`section`,{className:`data-panel`,children:[de&&(0,v.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,de]}),st.length>0&&(0,v.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:st.map(e=>{let t=e===U;return(0,v.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>be(t?null:e),children:Pe([e])??e},e)})}),l&&!h&&(0,v.jsxs)(`div`,{className:`data-results-meta`,children:[W.length,` of `,l.length,` result`,l.length===1?``:`s`]}),l&&!h&&!U&&b>0&&!x&&(0,v.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>ke(!0),children:[b,` low-confidence result`,b===1?``:`s`,` hidden — show all`]}),l&&!h&&!U&&x&&(0,v.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>ke(!1),children:`Showing all results — hide low-confidence`}),l&&l.length===0&&!h&&(0,v.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),W&&W.length>0&&(0,v.jsx)(`ul`,{className:`data-results`,children:W.map(e=>(0,v.jsx)(Ne,{hit:e,mode:ie,onDownload:ct,onLocate:ut},e.nodeId))})]}),(0,v.jsxs)(`section`,{className:`data-panel`,children:[k&&(0,v.jsxs)(`div`,{className:`data-upload-progress`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":k.total>0?Math.round(k.loaded/k.total*100):void 0,children:[(0,v.jsx)(`div`,{className:`data-upload-progress-track`,children:(0,v.jsx)(`div`,{className:`data-upload-progress-fill`,style:{width:`${k.total>0?Math.round(k.loaded/k.total*100):0}%`}})}),(0,v.jsxs)(`span`,{className:`data-upload-progress-label`,children:[`Uploading… `,k.total>0?`${Math.round(k.loaded/k.total*100)}%`:``]})]}),Ge&&(0,v.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,Ge]}),Ke&&(0,v.jsx)(`div`,{className:`data-status`,children:Ke}),Xe&&(0,v.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,Xe]}),Ve&&(0,v.jsx)(`div`,{className:`data-error`,children:Ve}),O&&(0,v.jsxs)(`div`,{className:`data-loading`,children:[(0,v.jsx)(m,{size:14,className:`spin`}),` Loading…`]}),!K&&!O&&w&&w.length>0&&(0,v.jsxs)(`div`,{className:`data-select-hint`,children:[(0,v.jsx)(_e,{size:13}),(0,v.jsx)(`span`,{children:`Press and hold a file to select, rename, or delete it.`})]}),!O&&w&&w.length===0&&!Ve&&(0,v.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!O&&w&&w.length>0&&T===`grid`&&(0,v.jsx)(`ul`,{className:`data-grid`,children:w.map(e=>{let t=e.displayName??e.name,r=K&&q.has(e.name);if(e.kind===`directory`)return(0,v.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,v.jsxs)(`button`,{type:`button`,className:`data-grid-tile`,onPointerDown:()=>_t(e.name),onPointerUp:Q,onPointerMove:Q,onPointerLeave:Q,onPointerCancel:Q,onClick:()=>{if(J.current){J.current=!1;return}if(K){Z(e.name);return}G(S===`.`?e.name:`${S}/${e.name}`)},children:[K&&(0,v.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,v.jsx)(me,{size:28,className:`data-grid-glyph`}),(0,v.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:t})]})},e.name);if(e.kind===`file`){let i=xe(e.name),a=S===`.`?e.name:`${S}/${e.name}`;return(0,v.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,v.jsxs)(`button`,{type:`button`,className:`data-grid-tile${i?` data-grid-tile-image`:``}`,onPointerDown:()=>_t(e.name),onPointerUp:Q,onPointerMove:Q,onPointerLeave:Q,onPointerCancel:Q,onClick:()=>i?bt(e):vt(e),title:K?void 0:i?`Preview ${t}`:`Download ${t}`,children:[K&&(0,v.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),i?(0,v.jsx)(`img`,{className:`data-grid-thumb`,src:f(n,a),alt:t,loading:`lazy`,onError:()=>console.warn(`[data] op=thumb-error path=${a}`)}):(0,v.jsx)(ce,{size:28,className:`data-grid-glyph`}),(0,v.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:t}),!i&&(0,v.jsx)(`span`,{className:`data-grid-sub`,children:Ie(e.sizeBytes)})]})},e.name)}return(0,v.jsx)(`li`,{className:`data-grid-cell`,children:(0,v.jsxs)(`div`,{className:`data-grid-tile data-entry-disabled`,children:[(0,v.jsx)(ce,{size:28,className:`data-grid-glyph`}),(0,v.jsx)(`span`,{className:`data-grid-label`,children:t}),(0,v.jsx)(`span`,{className:`data-grid-sub`,children:`special`})]})},e.name)})}),!O&&w&&w.length>0&&T===`list`&&(0,v.jsx)(`ul`,{className:`data-entries`,children:w.map(e=>{let t=e.displayName??e.name;if(e.kind===`directory`){let n=K&&q.has(e.name);return(0,v.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,v.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onPointerDown:()=>_t(e.name),onPointerUp:Q,onPointerMove:Q,onPointerLeave:Q,onPointerCancel:Q,onClick:()=>{if(J.current){J.current=!1;return}if(K){Z(e.name);return}G(S===`.`?e.name:`${S}/${e.name}`)},children:[K&&(0,v.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,v.jsx)(me,{size:14}),(0,v.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]})},e.name)}if(e.kind===`file`){let n=K&&q.has(e.name);return(0,v.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,v.jsxs)(`button`,{type:`button`,className:`data-entry-btn data-entry-file`,onPointerDown:()=>_t(e.name),onPointerUp:Q,onPointerMove:Q,onPointerLeave:Q,onPointerCancel:Q,onClick:()=>vt(e),title:K?void 0:`Download ${t}`,children:[K&&(0,v.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,v.jsxs)(`span`,{className:`data-entry-text`,children:[(0,v.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,v.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${Le(e.modifiedAt)}`,children:[Ie(e.sizeBytes),` · `,Le(e.modifiedAt)]})]})]})},e.name)}return(0,v.jsx)(`li`,{className:`data-entry`,children:(0,v.jsx)(`div`,{className:`data-entry-btn data-entry-file data-entry-disabled`,children:(0,v.jsxs)(`span`,{className:`data-entry-text`,children:[(0,v.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,v.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})})},e.name)})})]})]}),K&&(0,v.jsx)(`div`,{className:`data-select-bar`,role:`toolbar`,"aria-label":`Selection actions`,children:(0,v.jsxs)(`div`,{className:`data-select-bar-inner`,children:[(0,v.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Tt,disabled:!Y||q.size===0,title:Y?`Share selected files`:`Sharing is not supported on this device`,children:[(0,v.jsx)(te,{size:16}),` Share`]}),(0,v.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Ct,disabled:q.size===0,children:[(0,v.jsx)(se,{size:16}),` Download`]}),(0,v.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:()=>{let e=[...q][0];e&&(I(e),rt(e))},disabled:q.size!==1,children:[(0,v.jsx)(oe,{size:16}),` Rename`]}),(0,v.jsxs)(`button`,{type:`button`,className:`data-select-action data-select-delete`,onClick:wt,disabled:q.size===0,children:[(0,v.jsx)(ne,{size:16}),` Delete`]})]})}),E&&(0,v.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":E.alt,onClick:()=>Re(null),children:(0,v.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:E.src,alt:E.alt})})]})}function w({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){(0,_.useEffect)(()=>{console.info(`[data-ui] op=mount header=operator home=absent`)},[]);let r=(0,_.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),i=(0,_.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(`files`),{subAccounts:l,activeAccountId:te,switching:ne,switchAccount:u}=ie(t);return(0,_.useEffect)(()=>{if(!t)return;let e=!1;return fetch(`/api/whatsapp-reader/conversations?session_key=${encodeURIComponent(t)}`).then(e=>e.ok?e.json():{conversations:[]}).then(t=>{e||o(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[t]),(0,v.jsxs)(`main`,{className:`data-main`,children:[(0,v.jsx)(ee,{variant:`operator`,onNavigate:i,onOpenConversations:a.length>0?()=>c(`conversations`):void 0,onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:r,onDisconnect:async()=>!0,disconnecting:!1,subAccounts:l,activeAccountId:te,switchingAccount:ne,onSwitchAccount:u}),s===`conversations`?(0,v.jsx)(be,{conversations:a,sessionKey:t,onBack:()=>c(`files`)}):(0,v.jsx)(C,{adminFetch:e,cacheKey:t,sessionRefetchNonce:n})]})}function Me({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=a({initialCacheKey:e,surface:`data`});return(0,v.jsx)(`div`,{className:`data-page`,children:(0,v.jsx)(`main`,{className:`data-main`,children:(0,v.jsx)(C,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})})})}function Ne({hit:e,mode:t,onDownload:n,onLocate:r}){let i=T(e.properties),a=Fe(e.properties),o=Pe(e.labels),s=E(e.properties),[c,ee]=(0,_.useState)(!1),l=a&&a.length>280,te=c||!l?a:a?.slice(0,280)+`…`,ne=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`,u=e.properties.relativePath,d=typeof u==`string`&&u.length>0,f=d?u.lastIndexOf(`/`):-1,p=d?f===-1?`data`:u.slice(0,f):null;return(0,v.jsxs)(`li`,{className:`data-result`,children:[(0,v.jsxs)(`div`,{role:`button`,tabIndex:0,className:`data-result-open`,onClick:()=>n(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e))},"aria-label":`Download ${i??o??`file`}`,children:[o&&(0,v.jsx)(`div`,{className:`data-result-header`,children:(0,v.jsx)(`span`,{className:`data-result-labels`,children:o})}),i&&(0,v.jsx)(`div`,{className:`data-result-title`,children:i}),a&&(0,v.jsx)(`pre`,{className:`data-result-body`,children:te}),(0,v.jsxs)(`div`,{className:`data-result-scores`,children:[s&&(0,v.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,Le(s),` · `]}),ne]})]}),d&&(0,v.jsxs)(`button`,{type:`button`,className:`data-result-locate`,onClick:()=>r(e),title:`Locate in ${p}`,"aria-label":`Locate in ${p}`,children:[(0,v.jsx)(me,{size:12}),p]}),l&&(0,v.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>ee(e=>!e),children:c?`Show less`:`Show more`})]})}function Pe(e){if(e.length===0)return null;let t=e[0].replace(/([a-z])([A-Z])/g,`$1 $2`);return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}function T(e){for(let t of[`title`,`name`,`summary`,`headline`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n.length>140?n.slice(0,140)+`…`:n}return null}function Fe(e){for(let t of[`content`,`summary`,`body`,`description`,`text`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function E(e){for(let t of[`updatedAt`,`modifiedAt`,`fetchedAt`,`createdAt`,`lastModified`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function Ie(e){return e==null?``:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)} MB`:`${(e/1024/1024/1024).toFixed(1)} GB`}function Le(e){try{let t=new Date(e);if(isNaN(t.getTime()))return`—`;let n=typeof navigator<`u`?navigator.languages&&navigator.languages.length>0?[...navigator.languages]:[navigator.language]:void 0;return t.toLocaleString(n,{dateStyle:`medium`,timeStyle:`short`})}catch{return`—`}}export{Me as n,Ee as t};
1
+ import{o as e}from"./chunk-CAM3fms7.js";import{C as t,D as n,L as r,M as i,P as a,_ as o,a as s,c,d as ee,f as l,g as te,h as ne,i as u,m as d,n as f,o as p,r as re,t as ie,u as ae,v as oe,w as se,x as ce,y as m}from"./useSubAccountSwitcher-DMbRhLPv.js";import{t as h}from"./chevron-left-DhVdq0aN.js";import{i as le}from"./Transcript-DkGa4CQH.js";import{i as ue,t as de}from"./graph-labels-D3BQdcpD.js";var fe=n(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),pe=n(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),me=n(`folder`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),he=n(`layout-grid`,[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]),ge=n(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),_e=n(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),g=n(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),ve=n(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]);function ye(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||de.has(e)&&(t.add(e),n.push(e)));return n}var _=e(r(),1),v=i();function y(e){if(!e)return``;let t=new Date(e).getTime();return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function be({conversations:e,sessionKey:t,onBack:n}){let[r,i]=(0,_.useState)(null),a=s(e);return r?(0,v.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,v.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,v.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>i(null),"aria-label":`Back to conversations`,children:[(0,v.jsx)(h,{size:16}),` Back`]}),(0,v.jsx)(`span`,{className:`op-conv-title`,children:p(r)})]}),(0,v.jsx)(le,{sessionId:r.sessionId,projectDir:r.projectDir,sessionKey:t,forceDeliveredOnly:!0,suppressDirectives:r.source===`store`,store:r.source===`store`?{accountId:r.accountId,remoteJid:r.remoteJid}:void 0},c(r))]}):(0,v.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,v.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,v.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,v.jsx)(h,{size:16}),` Chat`]}),(0,v.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),a.map(e=>(0,v.jsxs)(`div`,{className:`op-conv-group`,children:[(0,v.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,v.jsx)(ae,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,v.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{console.info(`[operator-ui] op=reader-open channel=${e.channel} key=${c(e)} readonly=true source=${e.source}`),i(e)},children:[(0,v.jsx)(`span`,{className:`op-conv-name`,children:p(e)}),e.modelGated&&(0,v.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,v.jsx)(g,{size:13})}),(0,v.jsx)(`span`,{className:`op-conv-when`,children:y(e.lastMessageAt)})]},c(e)))]},e.channel))]})}var b=/\.(png|jpe?g|gif|webp|svg)$/i;function xe(e){return b.test(e)}var Se=`maxy-data-view`,Ce=95*1024*1024,we=48*1024*1024;function Te(){return typeof window>`u`?`list`:window.localStorage.getItem(Se)===`grid`?`grid`:`list`}function Ee(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(!1);return(0,_.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,v.jsx)(l,{cacheKey:e,surface:`data`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=data`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,v.jsx)(`div`,{className:`data-page data-page-full`,children:(0,v.jsx)(x,{cacheKey:e})})}):(0,v.jsx)(`div`,{className:`data-page`,children:(0,v.jsxs)(`div`,{className:`data-empty`,children:[(0,v.jsx)(`p`,{children:`You are not signed in.`}),(0,v.jsxs)(`p`,{children:[`Open the `,(0,v.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,v.jsx)(`div`,{className:`data-page`,children:(0,v.jsxs)(`div`,{className:`data-loading`,children:[(0,v.jsx)(m,{size:18,className:`spin`}),` Loading…`]})})}function x({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=a({initialCacheKey:e,surface:`data`});return(0,v.jsx)(w,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})}function De(){if(typeof window>`u`)return`.`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`.`}function Oe(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=e===`.`?``:`path=${encodeURIComponent(e)}`,window.history.replaceState(window.history.state,``,t.toString())}function ke(e){return new Promise((t,n)=>{let r=[],i=()=>e.readEntries(e=>{e.length===0?t(r):(r.push(...e),i())},n);i()})}function S(e){return new Promise((t,n)=>e.file(t,n))}async function Ae(e,t=``){let n=[];for(let r of e){if(!r)continue;let e=t?`${t}/${r.name}`:r.name;if(r.isFile)n.push({file:await S(r),relpath:e});else if(r.isDirectory){let t=await ke(r.createReader());n.push(...await Ae(t,e))}}return n}function je(e,t){if(e===422&&typeof t==`string`){if(/exceeds the .* limit/i.test(t))return`size`;if(/unsupported file type/i.test(t))return`mime`}return`http=${e}`}function C({adminFetch:e,cacheKey:n,sessionRefetchNonce:r}){let[i,a]=(0,_.useState)(``),s=(0,_.useRef)(null),[c,ee]=(0,_.useState)(``),[l,p]=(0,_.useState)(null),[ie,ae]=(0,_.useState)(`hybrid`),[h,le]=(0,_.useState)(!1),[de,g]=(0,_.useState)(null),[y,be]=(0,_.useState)(null),[b,Ee]=(0,_.useState)(0),[x,ke]=(0,_.useState)(!1),[S,C]=(0,_.useState)(()=>De()),[w,Me]=(0,_.useState)(null),[T,Fe]=(0,_.useState)(()=>Te()),[E,Re]=(0,_.useState)(null),[D,ze]=(0,_.useState)([]),[O,Be]=(0,_.useState)(!1),[Ve,He]=(0,_.useState)(null),[Ue,We]=(0,_.useState)(!1),[k,A]=(0,_.useState)(null),[Ge,j]=(0,_.useState)(null),[Ke,qe]=(0,_.useState)(null),[Je,Ye]=(0,_.useState)(!1),[Xe,Ze]=(0,_.useState)(null),M=(0,_.useRef)(null),[Qe,N]=(0,_.useState)(0),[$e,P]=(0,_.useState)(!1),[et,tt]=(0,_.useState)(``),[F,I]=(0,_.useState)(null),[nt,rt]=(0,_.useState)(``),[it,L]=(0,_.useState)(null),R=(()=>{let e=S===`.`?[]:S.split(`/`).filter(Boolean);return e.length>=2&&e[0]===`accounts`})(),[z,B]=(0,_.useState)(!1),at=(0,_.useRef)(null),[V,H]=(0,_.useState)(!1),ot=(0,_.useRef)(null);(0,_.useEffect)(()=>{let e=i.trim();if(!e){ee(``),p(null),g(null);return}ke(!1);let t=setTimeout(()=>ee(e),300);return()=>clearTimeout(t)},[i]),(0,_.useEffect)(()=>{if(!c){le(!1);return}let t=!1;return le(!0),g(null),e(`/api/admin/graph-search?q=${encodeURIComponent(c)}&labels=FileArtifact&limit=20${x?`&threshold=0`:``}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(p(e.results),ae(e.mode??`hybrid`),Ee(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||g(e instanceof Error?e.message:String(e))}).finally(()=>{t||le(!1)}),()=>{t=!0}},[c,e,r,x]);let st=(0,_.useMemo)(()=>l?ye(l):[],[l]),U=y&&st.includes(y)?y:null,W=(0,_.useMemo)(()=>l?U?l.filter(e=>e.labels.includes(U)):l:null,[l,U]),ct=(0,_.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let r=`/api/admin/files/download?session_key=${encodeURIComponent(n)}&path=${encodeURIComponent(t)}`,i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()},[n]);(0,_.useEffect)(()=>{if(!l)return;let e=l.filter(e=>{let t=e.properties.relativePath;return typeof t!=`string`||t.length===0});e.length>0&&console.warn(`[data-search] op=locate-link-missing nodeId=${e.map(e=>e.nodeId).join(`,`)}`)},[l]),(0,_.useEffect)(()=>{let t=!1;return Be(!0),He(null),e(`/api/admin/files?path=${encodeURIComponent(S===`.`?``:S)}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(Me(e.entries),ze(e.displayPath??[]))}).catch(e=>{t||(Me([]),ze([]),He(e instanceof Error?e.message:String(e)))}).finally(()=>{t||Be(!1)}),()=>{t=!0}},[e,S,Qe,r]),(0,_.useEffect)(()=>{Oe(S)},[S]);let lt=(0,_.useCallback)(()=>{N(e=>e+1)},[]),G=(0,_.useCallback)(e=>{B(!1),C(e)},[]),ut=(0,_.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let n=t.lastIndexOf(`/`),r=n===-1?`.`:t.slice(0,n);console.log(`[data-search] op=locate nodeId=${e.nodeId} folder=${r}`),a(``),g(null),be(null),G(r)},[G]),dt=(0,_.useCallback)(()=>{if(S===`.`||S===``)return;let e=S.split(`/`).filter(Boolean);e.pop(),C(e.length===0?`.`:e.join(`/`))},[S]),ft=(0,_.useCallback)(e=>{re(n,S===`.`?e.name:`${S}/${e.name}`)},[S,n]),[K,pt]=(0,_.useState)(!1),[q,mt]=(0,_.useState)(new Set),ht=(0,_.useRef)(null),J=(0,_.useRef)(!1),Y=typeof navigator<`u`&&typeof navigator.share==`function`&&typeof navigator.canShare==`function`,gt=(0,_.useCallback)(e=>{pt(!0),mt(new Set([e])),console.info(`[data-ui] op=select-enter count=1`)},[]),X=(0,_.useCallback)(e=>{pt(!1),mt(new Set),console.info(`[data-ui] op=select-exit reason=${e}`)},[]),Z=(0,_.useCallback)(e=>{mt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),_t=(0,_.useCallback)(e=>{J.current=!1,ht.current=setTimeout(()=>{J.current=!0,gt(e)},500)},[gt]),Q=(0,_.useCallback)(()=>{ht.current&&=(clearTimeout(ht.current),null)},[]),vt=(0,_.useCallback)(e=>{if(J.current){J.current=!1;return}if(K){Z(e.name);return}ft(e)},[K,Z,ft]),yt=(0,_.useCallback)(e=>{Fe(e),typeof window<`u`&&window.localStorage.setItem(Se,e),console.info(`[data] op=view-mode mode=${e}`)},[]),bt=(0,_.useCallback)(e=>{if(J.current){J.current=!1;return}if(K){Z(e.name);return}Re({src:f(n,S===`.`?e.name:`${S}/${e.name}`),alt:e.displayName??e.name})},[K,Z,S,n]),xt=(0,_.useCallback)(()=>(w??[]).filter(e=>e.kind===`file`&&q.has(e.name)),[w,q]),St=(0,_.useCallback)(()=>(w??[]).filter(e=>(e.kind===`file`||e.kind===`directory`)&&q.has(e.name)),[w,q]),Ct=(0,_.useCallback)(()=>{let e=St(),t=e.some(e=>e.kind===`directory`);e.length===1&&!t?ft(e[0]):e.length>=1&&u(n,e.map(e=>S===`.`?e.name:`${S}/${e.name}`)),X(`action`)},[St,ft,S,n,X]),wt=(0,_.useCallback)(async()=>{let t=xt(),n=t.filter(e=>!e.protected),r=t.length-n.length;Ze(r>0?`${r} protected file(s) kept`:null);for(let t of n){let n=S===`.`?t.name:`${S}/${t.name}`;try{let t=await e(`/api/admin/files?path=${encodeURIComponent(n)}`,{method:`DELETE`}),r=await t.json().catch(()=>({error:`HTTP ${t.status}`}));if(!t.ok)throw Error(r.error??`HTTP ${t.status}`)}catch(e){Ze(e instanceof Error?e.message:String(e))}}N(e=>e+1),X(`action`)},[xt,S,e,X]),Tt=(0,_.useCallback)(async()=>{let e=xt();if(console.info(`[data-ui] op=share supported=${Y} count=${e.length}`),Y)try{let t=await Promise.all(e.map(async e=>{let t=S===`.`?e.name:`${S}/${e.name}`,r=`/api/admin/files/download?session_key=${encodeURIComponent(n)}&path=${encodeURIComponent(t)}`,i=await(await fetch(r)).blob();return new File([i],e.name,{type:i.type||`application/octet-stream`})}));navigator.canShare({files:t})&&await navigator.share({files:t})}catch(e){console.warn(`[data-ui] op=share-failed err=${e instanceof Error?e.message:String(e)}`)}},[xt,Y,S,n]),Et=(0,_.useCallback)(()=>{M.current?.click()},[]),Dt=(0,_.useCallback)((e,t={})=>{let r=(r,i,a)=>{let o=new URLSearchParams({session_key:n,path:S===`.`?``:S,filename:e.name});t.relpath&&o.set(`relpath`,t.relpath),t.token&&o.set(`token`,t.token);for(let[e,t]of Object.entries(i))o.set(e,t);return new Promise(t=>{let n=new XMLHttpRequest;n.open(`POST`,`/api/admin/files/upload?${o.toString()}`),n.setRequestHeader(`Content-Type`,e.type||`application/octet-stream`),a&&(n.upload.onprogress=e=>{e.lengthComputable&&a(e.loaded)}),n.onload=()=>{let e={};try{e=JSON.parse(n.responseText)}catch{}t({status:n.status,data:e})},n.onerror=()=>t({status:0,data:{}}),n.onabort=()=>t({status:0,data:{error:`aborted`}}),n.send(r)})};if(e.size<=Ce)return r(e,{},n=>t.onProgress?.(n,e.size));let i=`${Date.now().toString(36)}-${Math.random().toString(16).slice(2,10)}`,a=Math.ceil(e.size/we);return(async()=>{let n={status:0,data:{}};for(let o=0;o<a;o++){let s=o*we;if(n=await r(e.slice(s,Math.min(s+we,e.size)),{uploadId:i,seq:String(o),total:String(a)},n=>t.onProgress?.(s+n,e.size)),!(n.status>=200&&n.status<300))return n}return n})()},[n,S]),Ot=(0,_.useCallback)(async e=>{j(null),We(!0),A({loaded:0,total:e.size});try{let{status:t,data:n}=await Dt(e,{onProgress:(e,t)=>A({loaded:e,total:t})});t>=200&&t<300&&n.path?(C(n.path.split(`/`).slice(0,-1).join(`/`)||`.`),N(e=>e+1)):j(t===0?`Network error during upload — the connection failed before the server responded.`:n.error??`Upload failed (HTTP ${t}).`)}finally{We(!1),A(null),M.current&&(M.current.value=``)}},[Dt]),kt=(0,_.useCallback)(e=>{R&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),Ye(!0))},[R]),At=(0,_.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||Ye(!1)},[]),jt=(0,_.useCallback)(async e=>{e.preventDefault(),Ye(!1);let t=Math.random().toString(16).slice(2,10),n=Array.from(e.dataTransfer.items);if(console.info(`[data-ui] op=drop-received token=${t} items=${n.length}`),n.length===0)return;if(!R){console.info(`[data-ui] op=drop-rejected token=${t} reason=no-write`),j(`Open a folder inside your account to upload`);return}let r=n.map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e);We(!0),j(null),qe(null);let i=performance.now();try{let e=await Ae(r),n=e.reduce((e,t)=>e+t.file.size,0),a=new Set(e.map(e=>e.relpath.split(`/`).slice(0,-1).join(`/`)).filter(Boolean)).size;console.info(`[data-ui] op=drop-walk token=${t} files=${e.length} dirs=${a} bytes=${n}`);let o=0,s=[];for(let n=0;n<e.length;n++){let{file:r,relpath:i}=e[n];console.info(`[data-ui] op=drop-file token=${t} rel="${i}" i=${n+1}/${e.length}`),A({loaded:0,total:r.size});let{status:a,data:c}=await Dt(r,{relpath:i,token:t,onProgress:(e,t)=>A({loaded:e,total:t})});if(a>=200&&a<300)o++,console.info(`[data-ui] op=drop-file-ok token=${t} rel="${i}"`);else{let e=a===0?`http=0`:je(a,c.error);s.push(`${i} (${e})`),console.info(`[data-ui] op=drop-file-skip token=${t} rel="${i}" reason=${e}`)}}let c=Math.round(performance.now()-i);console.info(`[data-ui] op=drop-done token=${t} uploaded=${o} skipped=${s.length} ms=${c}`),qe(`Uploaded ${o}, skipped ${s.length}${s.length?`: ${s.join(`, `)}`:``}`),N(e=>e+1)}catch(e){j(e instanceof Error?e.message:String(e))}finally{We(!1),A(null)}},[R,Dt]),Mt=(0,_.useCallback)(async()=>{let t=et.trim();if(t){L(null);try{let n=await e(`/api/admin/files/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:S===`.`?``:S,name:t})}),r=await n.json().catch(()=>({error:`HTTP ${n.status}`}));if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);P(!1),tt(``),N(e=>e+1)}catch(e){L(e instanceof Error?e.message:String(e))}}},[e,et,S]),Nt=(0,_.useCallback)(async()=>{if(!F)return;let t=nt.trim();if(!t)return;L(null);let n=S===`.`?F:`${S}/${F}`;try{let r=await e(`/api/admin/files/rename`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:n,newName:t})}),i=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(i.error??`HTTP ${r.status}`);I(null),rt(``),X(`action`),N(e=>e+1)}catch(e){L(e instanceof Error?e.message:String(e))}},[e,nt,F,S,X]);(0,_.useEffect)(()=>{if(!z)return;let e=e=>{at.current&&!at.current.contains(e.target)&&B(!1)},t=e=>{e.key===`Escape`&&B(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[z]),(0,_.useEffect)(()=>{if(!V)return;let e=e=>{ot.current&&!ot.current.contains(e.target)&&H(!1)},t=e=>{e.key===`Escape`&&H(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[V]);let $=(0,_.useCallback)(e=>D.slice(0,e+1).map(e=>e.name).join(`/`),[D]),Pt=D.length>=2,Ft=Pt?[{name:`.`,label:`data`},...D.slice(0,D.length-2).map((e,t)=>({name:$(t),label:e.displayName??e.name}))]:[];return(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(`div`,{className:`data-toolbar`,children:[K?(0,v.jsxs)(`button`,{type:`button`,className:`data-select-cancel`,onClick:()=>X(`cancel`),"aria-label":`Cancel selection`,children:[(0,v.jsx)(d,{size:14}),` Cancel`]}):(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(`div`,{className:`data-search-input`,children:[i===``&&(0,v.jsx)(ue,{size:14}),(0,v.jsx)(`input`,{ref:s,type:`text`,value:i,onChange:e=>a(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),h&&(0,v.jsx)(m,{size:14,className:`spin`}),i!==``&&(0,v.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{a(``),s.current?.focus()},title:`Clear search`,"aria-label":`Clear search`,children:(0,v.jsx)(d,{size:14})})]}),(0,v.jsxs)(`div`,{className:`data-toolbar-actions`,ref:ot,children:[(0,v.jsx)(`button`,{type:`button`,className:`data-action-overflow`,onClick:()=>H(e=>!e),"aria-haspopup":`menu`,"aria-expanded":V,"aria-label":`File actions`,title:`File actions`,children:(0,v.jsx)(t,{size:16})}),(0,v.jsxs)(`div`,{className:`data-action-group`,role:`group`,"aria-label":`File actions`,"data-open":V?`true`:void 0,children:[(0,v.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{lt(),H(!1)},disabled:O,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[O?(0,v.jsx)(m,{size:16,className:`spin`}):(0,v.jsx)(o,{size:16}),(0,v.jsx)(`span`,{className:`data-action-label`,children:`Refresh`})]}),(0,v.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Et(),H(!1)},disabled:Ue||!R,title:R?`Upload a file`:`Open a folder inside your account to upload`,"aria-label":`Upload a file`,children:[Ue?k&&k.total>0?(0,v.jsxs)(`span`,{className:`data-upload-pct`,children:[Math.round(k.loaded/k.total*100),`%`]}):(0,v.jsx)(m,{size:16,className:`spin`}):(0,v.jsx)(ve,{size:16}),(0,v.jsx)(`span`,{className:`data-action-label`,children:`Upload`})]}),(0,v.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{P(e=>!e),tt(``),L(null),H(!1)},disabled:Ue||!R,title:R?`New folder`:`Open a folder inside your account to create one`,"aria-label":`New folder`,children:[(0,v.jsx)(pe,{size:16}),(0,v.jsx)(`span`,{className:`data-action-label`,children:`New folder`})]}),(0,v.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{yt(T===`grid`?`list`:`grid`),H(!1)},title:T===`grid`?`List view`:`Grid view`,"aria-label":T===`grid`?`Switch to list view`:`Switch to grid view`,"aria-pressed":T===`grid`,children:[T===`grid`?(0,v.jsx)(ge,{size:16}):(0,v.jsx)(he,{size:16}),(0,v.jsx)(`span`,{className:`data-action-label`,children:T===`grid`?`List view`:`Grid view`})]})]})]})]}),(0,v.jsxs)(`div`,{className:`data-breadcrumbs`,children:[S!==`.`&&(0,v.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-back-btn`,onClick:dt,title:`Up one level`,"aria-label":`Up one level`,children:(0,v.jsx)(fe,{size:14})}),Pt?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(`span`,{className:`data-crumb-wrap`,ref:at,children:[(0,v.jsx)(`button`,{type:`button`,className:`data-crumb data-crumb-ellipsis`,onClick:()=>B(e=>!e),"aria-haspopup":`menu`,"aria-expanded":z,"aria-label":`Show parent folders`,title:`Show parent folders`,children:`…`}),z&&(0,v.jsx)(`div`,{className:`data-crumb-menu`,role:`menu`,children:Ft.map(e=>(0,v.jsx)(`button`,{type:`button`,role:`menuitem`,className:`data-crumb-menu-item`,onClick:()=>G(e.name),title:e.label,children:e.label},e.name))})]}),[D.length-2,D.length-1].map(e=>{let t=D[e];return(0,v.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,v.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,v.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>G($(e)),title:t.name,children:t.displayName??t.name})]},$(e))})]}):(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>G(`.`),children:`data`}),D.map((e,t)=>(0,v.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,v.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,v.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>G($(t)),title:e.name,children:e.displayName??e.name})]},$(t)))]})]}),$e&&(0,v.jsxs)(`div`,{className:`data-inline-form`,children:[(0,v.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`Folder name`,value:et,autoFocus:!0,onChange:e=>tt(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Mt(),e.key===`Escape`&&P(!1)}}),(0,v.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Mt,children:`Create`}),(0,v.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>P(!1),children:`Cancel`})]}),F&&(0,v.jsxs)(`div`,{className:`data-inline-form`,children:[(0,v.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`New name`,value:nt,autoFocus:!0,onChange:e=>rt(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Nt(),e.key===`Escape`&&I(null)}}),(0,v.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Nt,children:`Rename`}),(0,v.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>I(null),children:`Cancel`})]}),it&&(0,v.jsx)(`div`,{className:`data-error`,children:it}),(0,v.jsx)(`input`,{type:`file`,ref:M,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Ot(t)}})]}),(0,v.jsxs)(`div`,{className:`data-body`,"data-drag-active":Je?`true`:void 0,onDragEnter:kt,onDragOver:kt,onDragLeave:At,onDrop:jt,children:[(de!==null||l!==null)&&(0,v.jsxs)(`section`,{className:`data-panel`,children:[de&&(0,v.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,de]}),st.length>0&&(0,v.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:st.map(e=>{let t=e===U;return(0,v.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>be(t?null:e),children:Pe([e])??e},e)})}),l&&!h&&(0,v.jsxs)(`div`,{className:`data-results-meta`,children:[W.length,` of `,l.length,` result`,l.length===1?``:`s`]}),l&&!h&&!U&&b>0&&!x&&(0,v.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>ke(!0),children:[b,` low-confidence result`,b===1?``:`s`,` hidden — show all`]}),l&&!h&&!U&&x&&(0,v.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>ke(!1),children:`Showing all results — hide low-confidence`}),l&&l.length===0&&!h&&(0,v.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),W&&W.length>0&&(0,v.jsx)(`ul`,{className:`data-results`,children:W.map(e=>(0,v.jsx)(Ne,{hit:e,mode:ie,onDownload:ct,onLocate:ut},e.nodeId))})]}),(0,v.jsxs)(`section`,{className:`data-panel`,children:[k&&(0,v.jsxs)(`div`,{className:`data-upload-progress`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":k.total>0?Math.round(k.loaded/k.total*100):void 0,children:[(0,v.jsx)(`div`,{className:`data-upload-progress-track`,children:(0,v.jsx)(`div`,{className:`data-upload-progress-fill`,style:{width:`${k.total>0?Math.round(k.loaded/k.total*100):0}%`}})}),(0,v.jsxs)(`span`,{className:`data-upload-progress-label`,children:[`Uploading… `,k.total>0?`${Math.round(k.loaded/k.total*100)}%`:``]})]}),Ge&&(0,v.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,Ge]}),Ke&&(0,v.jsx)(`div`,{className:`data-status`,children:Ke}),Xe&&(0,v.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,Xe]}),Ve&&(0,v.jsx)(`div`,{className:`data-error`,children:Ve}),O&&(0,v.jsxs)(`div`,{className:`data-loading`,children:[(0,v.jsx)(m,{size:14,className:`spin`}),` Loading…`]}),!K&&!O&&w&&w.length>0&&(0,v.jsxs)(`div`,{className:`data-select-hint`,children:[(0,v.jsx)(_e,{size:13}),(0,v.jsx)(`span`,{children:`Press and hold a file to select, rename, or delete it.`})]}),!O&&w&&w.length===0&&!Ve&&(0,v.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!O&&w&&w.length>0&&T===`grid`&&(0,v.jsx)(`ul`,{className:`data-grid`,children:w.map(e=>{let t=e.displayName??e.name,r=K&&q.has(e.name);if(e.kind===`directory`)return(0,v.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,v.jsxs)(`button`,{type:`button`,className:`data-grid-tile`,onPointerDown:()=>_t(e.name),onPointerUp:Q,onPointerMove:Q,onPointerLeave:Q,onPointerCancel:Q,onClick:()=>{if(J.current){J.current=!1;return}if(K){Z(e.name);return}G(S===`.`?e.name:`${S}/${e.name}`)},children:[K&&(0,v.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,v.jsx)(me,{size:28,className:`data-grid-glyph`}),(0,v.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:t})]})},e.name);if(e.kind===`file`){let i=xe(e.name),a=S===`.`?e.name:`${S}/${e.name}`;return(0,v.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,v.jsxs)(`button`,{type:`button`,className:`data-grid-tile${i?` data-grid-tile-image`:``}`,onPointerDown:()=>_t(e.name),onPointerUp:Q,onPointerMove:Q,onPointerLeave:Q,onPointerCancel:Q,onClick:()=>i?bt(e):vt(e),title:K?void 0:i?`Preview ${t}`:`Download ${t}`,children:[K&&(0,v.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),i?(0,v.jsx)(`img`,{className:`data-grid-thumb`,src:f(n,a),alt:t,loading:`lazy`,onError:()=>console.warn(`[data] op=thumb-error path=${a}`)}):(0,v.jsx)(ce,{size:28,className:`data-grid-glyph`}),(0,v.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:t}),!i&&(0,v.jsx)(`span`,{className:`data-grid-sub`,children:Ie(e.sizeBytes)})]})},e.name)}return(0,v.jsx)(`li`,{className:`data-grid-cell`,children:(0,v.jsxs)(`div`,{className:`data-grid-tile data-entry-disabled`,children:[(0,v.jsx)(ce,{size:28,className:`data-grid-glyph`}),(0,v.jsx)(`span`,{className:`data-grid-label`,children:t}),(0,v.jsx)(`span`,{className:`data-grid-sub`,children:`special`})]})},e.name)})}),!O&&w&&w.length>0&&T===`list`&&(0,v.jsx)(`ul`,{className:`data-entries`,children:w.map(e=>{let t=e.displayName??e.name;if(e.kind===`directory`){let n=K&&q.has(e.name);return(0,v.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,v.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onPointerDown:()=>_t(e.name),onPointerUp:Q,onPointerMove:Q,onPointerLeave:Q,onPointerCancel:Q,onClick:()=>{if(J.current){J.current=!1;return}if(K){Z(e.name);return}G(S===`.`?e.name:`${S}/${e.name}`)},children:[K&&(0,v.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,v.jsx)(me,{size:14}),(0,v.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]})},e.name)}if(e.kind===`file`){let n=K&&q.has(e.name);return(0,v.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,v.jsxs)(`button`,{type:`button`,className:`data-entry-btn data-entry-file`,onPointerDown:()=>_t(e.name),onPointerUp:Q,onPointerMove:Q,onPointerLeave:Q,onPointerCancel:Q,onClick:()=>vt(e),title:K?void 0:`Download ${t}`,children:[K&&(0,v.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,v.jsxs)(`span`,{className:`data-entry-text`,children:[(0,v.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,v.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${Le(e.modifiedAt)}`,children:[Ie(e.sizeBytes),` · `,Le(e.modifiedAt)]})]})]})},e.name)}return(0,v.jsx)(`li`,{className:`data-entry`,children:(0,v.jsx)(`div`,{className:`data-entry-btn data-entry-file data-entry-disabled`,children:(0,v.jsxs)(`span`,{className:`data-entry-text`,children:[(0,v.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,v.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})})},e.name)})})]})]}),K&&(0,v.jsx)(`div`,{className:`data-select-bar`,role:`toolbar`,"aria-label":`Selection actions`,children:(0,v.jsxs)(`div`,{className:`data-select-bar-inner`,children:[(0,v.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Tt,disabled:!Y||q.size===0,title:Y?`Share selected files`:`Sharing is not supported on this device`,children:[(0,v.jsx)(te,{size:16}),` Share`]}),(0,v.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Ct,disabled:q.size===0,children:[(0,v.jsx)(se,{size:16}),` Download`]}),(0,v.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:()=>{let e=[...q][0];e&&(I(e),rt(e))},disabled:q.size!==1,children:[(0,v.jsx)(oe,{size:16}),` Rename`]}),(0,v.jsxs)(`button`,{type:`button`,className:`data-select-action data-select-delete`,onClick:wt,disabled:q.size===0,children:[(0,v.jsx)(ne,{size:16}),` Delete`]})]})}),E&&(0,v.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":E.alt,onClick:()=>Re(null),children:(0,v.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:E.src,alt:E.alt})})]})}function w({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){(0,_.useEffect)(()=>{console.info(`[data-ui] op=mount header=operator home=absent`)},[]);let r=(0,_.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),i=(0,_.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(`files`),{subAccounts:l,activeAccountId:te,switching:ne,switchAccount:u}=ie(t);return(0,_.useEffect)(()=>{if(!t)return;let e=!1;return fetch(`/api/whatsapp-reader/conversations?session_key=${encodeURIComponent(t)}`).then(e=>e.ok?e.json():{conversations:[]}).then(t=>{e||o(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[t]),(0,v.jsxs)(`main`,{className:`data-main`,children:[(0,v.jsx)(ee,{variant:`operator`,onNavigate:i,onOpenConversations:a.length>0?()=>c(`conversations`):void 0,onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:r,onDisconnect:async()=>!0,disconnecting:!1,subAccounts:l,activeAccountId:te,switchingAccount:ne,onSwitchAccount:u}),s===`conversations`?(0,v.jsx)(be,{conversations:a,sessionKey:t,onBack:()=>c(`files`)}):(0,v.jsx)(C,{adminFetch:e,cacheKey:t,sessionRefetchNonce:n})]})}function Me({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=a({initialCacheKey:e,surface:`data`});return(0,v.jsx)(`div`,{className:`data-page`,children:(0,v.jsx)(`main`,{className:`data-main`,children:(0,v.jsx)(C,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})})})}function Ne({hit:e,mode:t,onDownload:n,onLocate:r}){let i=T(e.properties),a=Fe(e.properties),o=Pe(e.labels),s=E(e.properties),[c,ee]=(0,_.useState)(!1),l=a&&a.length>280,te=c||!l?a:a?.slice(0,280)+`…`,ne=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`,u=e.properties.relativePath,d=typeof u==`string`&&u.length>0,f=d?u.lastIndexOf(`/`):-1,p=d?f===-1?`data`:u.slice(0,f):null;return(0,v.jsxs)(`li`,{className:`data-result`,children:[(0,v.jsxs)(`div`,{role:`button`,tabIndex:0,className:`data-result-open`,onClick:()=>n(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e))},"aria-label":`Download ${i??o??`file`}`,children:[o&&(0,v.jsx)(`div`,{className:`data-result-header`,children:(0,v.jsx)(`span`,{className:`data-result-labels`,children:o})}),i&&(0,v.jsx)(`div`,{className:`data-result-title`,children:i}),a&&(0,v.jsx)(`pre`,{className:`data-result-body`,children:te}),(0,v.jsxs)(`div`,{className:`data-result-scores`,children:[s&&(0,v.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,Le(s),` · `]}),ne]})]}),d&&(0,v.jsxs)(`button`,{type:`button`,className:`data-result-locate`,onClick:()=>r(e),title:`Locate in ${p}`,"aria-label":`Locate in ${p}`,children:[(0,v.jsx)(me,{size:12}),p]}),l&&(0,v.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>ee(e=>!e),children:c?`Show less`:`Show more`})]})}function Pe(e){if(e.length===0)return null;let t=e[0].replace(/([a-z])([A-Z])/g,`$1 $2`);return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}function T(e){for(let t of[`title`,`name`,`summary`,`headline`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n.length>140?n.slice(0,140)+`…`:n}return null}function Fe(e){for(let t of[`content`,`summary`,`body`,`description`,`text`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function E(e){for(let t of[`updatedAt`,`modifiedAt`,`fetchedAt`,`createdAt`,`lastModified`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function Ie(e){return e==null?``:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)} MB`:`${(e/1024/1024/1024).toFixed(1)} GB`}function Le(e){try{let t=new Date(e);if(isNaN(t.getTime()))return`—`;let n=typeof navigator<`u`?navigator.languages&&navigator.languages.length>0?[...navigator.languages]:[navigator.language]:void 0;return t.toLocaleString(n,{dateStyle:`medium`,timeStyle:`short`})}catch{return`—`}}export{Me as n,Ee as t};