@rubytech/create-maxy-code 0.1.429 → 0.1.432

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 (77) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +69 -3
  3. package/payload/platform/plugins/docs/PLUGIN.md +1 -0
  4. package/payload/platform/plugins/docs/references/internals.md +2 -2
  5. package/payload/platform/plugins/docs/references/workflows.md +61 -0
  6. package/payload/platform/plugins/whatsapp/mcp/dist/resolve-read-account.d.ts +8 -1
  7. package/payload/platform/plugins/whatsapp/mcp/dist/resolve-read-account.d.ts.map +1 -1
  8. package/payload/platform/plugins/whatsapp/mcp/dist/resolve-read-account.js +8 -1
  9. package/payload/platform/plugins/whatsapp/mcp/dist/resolve-read-account.js.map +1 -1
  10. package/payload/platform/plugins/workflows/PLUGIN.md +29 -9
  11. package/payload/platform/plugins/workflows/mcp/dist/index.js +34 -0
  12. package/payload/platform/plugins/workflows/mcp/dist/index.js.map +1 -1
  13. package/payload/platform/plugins/workflows/mcp/dist/lib/step-resolver.d.ts +2 -2
  14. package/payload/platform/plugins/workflows/mcp/dist/lib/step-resolver.d.ts.map +1 -1
  15. package/payload/platform/plugins/workflows/mcp/dist/lib/step-resolver.js.map +1 -1
  16. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-create.d.ts +25 -0
  17. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-create.d.ts.map +1 -1
  18. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-create.js +14 -1
  19. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-create.js.map +1 -1
  20. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-execute.d.ts +25 -1
  21. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-execute.d.ts.map +1 -1
  22. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-execute.js +79 -15
  23. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-execute.js.map +1 -1
  24. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-get.d.ts +2 -0
  25. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-get.d.ts.map +1 -1
  26. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-get.js +4 -0
  27. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-get.js.map +1 -1
  28. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-update.d.ts +3 -1
  29. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-update.d.ts.map +1 -1
  30. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-update.js +8 -1
  31. package/payload/platform/plugins/workflows/mcp/dist/tools/workflow-update.js.map +1 -1
  32. package/payload/platform/plugins/workflows/skills/workflow-manager/SKILL.md +24 -3
  33. package/payload/platform/services/telegram-channel/dist/instructions.js +1 -1
  34. package/payload/platform/services/telegram-channel/dist/instructions.js.map +1 -1
  35. package/payload/platform/services/telegram-channel/dist/notification.d.ts +10 -5
  36. package/payload/platform/services/telegram-channel/dist/notification.d.ts.map +1 -1
  37. package/payload/platform/services/telegram-channel/dist/notification.js +9 -6
  38. package/payload/platform/services/telegram-channel/dist/notification.js.map +1 -1
  39. package/payload/platform/services/telegram-channel/dist/server.d.ts.map +1 -1
  40. package/payload/platform/services/telegram-channel/dist/server.js +15 -5
  41. package/payload/platform/services/telegram-channel/dist/server.js.map +1 -1
  42. package/payload/platform/services/webchat-channel/dist/instructions.js +1 -1
  43. package/payload/platform/services/webchat-channel/dist/instructions.js.map +1 -1
  44. package/payload/platform/services/webchat-channel/dist/notification.d.ts +12 -10
  45. package/payload/platform/services/webchat-channel/dist/notification.d.ts.map +1 -1
  46. package/payload/platform/services/webchat-channel/dist/notification.js +12 -11
  47. package/payload/platform/services/webchat-channel/dist/notification.js.map +1 -1
  48. package/payload/platform/services/webchat-channel/dist/server.d.ts.map +1 -1
  49. package/payload/platform/services/webchat-channel/dist/server.js +12 -1
  50. package/payload/platform/services/webchat-channel/dist/server.js.map +1 -1
  51. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts +11 -6
  52. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts.map +1 -1
  53. package/payload/platform/services/whatsapp-channel/dist/notification.js +11 -8
  54. package/payload/platform/services/whatsapp-channel/dist/notification.js.map +1 -1
  55. package/payload/platform/services/whatsapp-channel/dist/server.d.ts.map +1 -1
  56. package/payload/platform/services/whatsapp-channel/dist/server.js +57 -14
  57. package/payload/platform/services/whatsapp-channel/dist/server.js.map +1 -1
  58. package/payload/platform/services/whatsapp-channel/dist/targets.d.ts +26 -2
  59. package/payload/platform/services/whatsapp-channel/dist/targets.d.ts.map +1 -1
  60. package/payload/platform/services/whatsapp-channel/dist/targets.js +50 -2
  61. package/payload/platform/services/whatsapp-channel/dist/targets.js.map +1 -1
  62. package/payload/server/public/assets/{AdminLoginScreens-C4AZT7cQ.js → AdminLoginScreens-BM45lL5G.js} +1 -1
  63. package/payload/server/public/assets/{admin-SaF1F4e-.js → admin-B8Eb9Wbj.js} +1 -1
  64. package/payload/server/public/assets/{audio-attachment-mime-BBW07eyG.js → audio-attachment-mime-Cx5d3Jls.js} +1 -1
  65. package/payload/server/public/assets/{chat-B9Qjt7C9.js → chat-LEEUAJOG.js} +1 -1
  66. package/payload/server/public/assets/data-CKojMQSz.js +1 -0
  67. package/payload/server/public/assets/{operator-CTJjI8te.js → operator-OwY_sWTH.js} +1 -1
  68. package/payload/server/public/assets/{page-CbI1wtef.js → page-B7nCws9K.js} +1 -1
  69. package/payload/server/public/assets/{page-JzxyFGle.js → page-C3L6-Ufk.js} +5 -5
  70. package/payload/server/public/assets/{public-DzeW3_eM.js → public-CSLXSSy5.js} +1 -1
  71. package/payload/server/public/chat.html +3 -3
  72. package/payload/server/public/data.html +3 -3
  73. package/payload/server/public/index.html +4 -4
  74. package/payload/server/public/operator.html +4 -4
  75. package/payload/server/public/public.html +3 -3
  76. package/payload/server/server.js +1647 -1470
  77. package/payload/server/public/assets/data-BKE6Sa-g.js +0 -1
@@ -1,2 +1,2 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-render-jAQU0nXt.js","assets/preload-helper-ClBMtM1g.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./chunk-Ck5AOu5v.js";import{a as t,m as n,w as r,y as i}from"./useSubAccountSwitcher-DyjTbzQR.js";import{h as a}from"./file-download-B2B2DTar.js";import{t as o}from"./maximize-2-DKx6OBKv.js";import{t as s}from"./preload-helper-ClBMtM1g.js";var c=`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,application/zip,application/x-zip-compressed,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.oasis.opendocument.text,text/rtf,application/rtf,audio/ogg,audio/opus,audio/mp4,audio/x-m4a,audio/mpeg,audio/webm,audio/wav,video/mp4,.docx,.odt,.rtf,.opus,.ogg,.m4a,.mp4,.mp3,.wav,.webm`,l=new Set(c.split(`,`).filter(e=>!e.startsWith(`.`))),u=50*1024*1024;function d(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}var f=n(`check-check`,[[`path`,{d:`M18 6 7 17l-5-5`,key:`116fxf`}],[`path`,{d:`m22 10-7.5 7.5L13 16`,key:`ke71qq`}]]),p=n(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),m=n(`file-code`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 12.5 8 15l2 2.5`,key:`1tg20x`}],[`path`,{d:`m14 12.5 2 2.5-2 2.5`,key:`yinavb`}]]),h=n(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),g=e(r(),1),_=i();function v({children:e,tail:t=null,repinSignals:n}){let r=(0,g.useRef)(null),i=(0,g.useRef)(null),a=(0,g.useRef)(!0),[o,s]=(0,g.useState)(!0),c=(0,g.useRef)(0),l=(0,g.useRef)(0),u=()=>{let e=r.current;if(!e)return;let t=e.clientHeight,n=e.scrollHeight,i=t!==c.current||n!==l.current;if(c.current=t,l.current=n,i){a.current&&(e.scrollTop=e.scrollHeight);return}let o=n-e.scrollTop-t<=32;a.current=o,s(e=>e===o?e:o)},d=()=>{let e=r.current;e&&(e.scrollTop=e.scrollHeight,l.current=e.scrollHeight,c.current=e.clientHeight,a.current=!0,s(!0))},f=t!=null;return(0,g.useLayoutEffect)(()=>{let e=r.current;e&&a.current&&(e.scrollTop=e.scrollHeight),e&&(l.current=e.scrollHeight,c.current=e.clientHeight)},[...n,f]),(0,g.useLayoutEffect)(()=>{if(typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>u());return r.current&&e.observe(r.current),i.current&&e.observe(i.current),()=>e.disconnect()},[]),(0,_.jsxs)(`div`,{className:`wa-reader`,children:[(0,_.jsx)(`div`,{className:`wa-reader-thread`,ref:r,onScroll:u,children:(0,_.jsxs)(`div`,{className:`wa-thread-scroll`,ref:i,children:[e,t]})}),!o&&(0,_.jsx)(`button`,{type:`button`,className:`wa-jump`,onClick:d,"aria-label":`Jump to latest message`,title:`Jump to latest message`,children:`↓`})]})}var y={auth_expired:`Your session has expired. Please sign in again.`,claude_down:`Claude is currently experiencing an outage. Please try again in a few minutes.`,claude_overloaded:`Claude is overloaded right now. Please try again shortly.`,model_unavailable:`The selected model is currently unavailable. Switch to a different model from the model picker to continue.`,agent_error:`Something went wrong. Please try again.`},b={auth_expired:`I'm not available right now. Please try again later.`,claude_down:`I'm not available right now. Please try again later.`,claude_overloaded:`I'm not available right now. Please try again shortly.`,model_unavailable:`I'm not available right now. Please try again later.`,agent_error:`I'm not available right now. Please try again later.`};function x(e,t=`admin`){return t===`public`?b[e]:y[e]}function S(e){return e===`whatsapp`?` · via WhatsApp`:e===`webchat`?` · via web`:``}var C=/\.(png|jpe?g|gif|webp|svg|bmp)$/i,w=/\.pdf$/i;function T(e,t){return(t?t.startsWith(`image/`):C.test(e))?`image`:t&&t.startsWith(`audio/`)?`audio`:(t?t===`application/pdf`:w.test(e))?`pdf`:`file`}function E(e,t,n,r){let i=encodeURIComponent(e.path),a=encodeURIComponent(n),o=r?`&disposition=${r}`:``;return e.root===`scratchpad`?`/api/admin/files/download?path=${i}&root=scratchpad&sessionId=${encodeURIComponent(t)}&session_key=${a}${o}`:`/api/admin/files/download?path=${i}&root=data&session_key=${a}${o}`}function D(e,t,n,r){return t===`public`?`/api/public-reader/attachment/${e}?sessionId=${encodeURIComponent(n)}`:`/api/admin/attachment/${e}?session_key=${encodeURIComponent(r)}`}function O(e){if(e<1024)return`${e} B`;let t=e/1024;if(t<1024)return`${t<10?t.toFixed(1):Math.round(t)} KB`;let n=t/1024;return`${n<10?n.toFixed(1):Math.round(n)} MB`}function k({href:e,filename:t,label:n}){return(0,_.jsxs)(`a`,{className:`chat-attachment-chip`,href:e,download:t,children:[(0,_.jsx)(h,{size:14,"aria-hidden":!0}),n]})}function A({href:e,filename:t,className:n,size:r=14,onClick:i}){return(0,_.jsx)(`a`,{className:n,href:e,download:t,"aria-label":`Download ${t}`,onClick:i,children:(0,_.jsx)(a,{size:r,"aria-hidden":!0})})}function j({src:e,filename:t,sizeBytes:n,expandable:r,onFail:i}){let[a,o]=(0,g.useState)(!1),[s,c]=(0,g.useState)(!1),l=n==null?t:`${t} · ${O(n)}`;return s?(0,_.jsx)(k,{href:e,filename:t,label:l}):(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)(`span`,{className:`chat-attachment-image-wrap`,children:[(0,_.jsx)(`img`,{className:`chat-attachment-image`,src:e,alt:t,onClick:r?()=>o(!0):void 0,onError:()=>{c(!0),i?.(`fetch`)}}),(0,_.jsx)(A,{href:e,filename:t,className:`chat-attachment-download`})]}),r&&a&&(0,_.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":t,onClick:()=>o(!1),children:(0,_.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:e,alt:t})})]})}var M=280,ee=360,N=16;function P({src:e,filename:t,sizeBytes:n,onFail:r}){let[i,a]=(0,g.useState)(!1),[c,l]=(0,g.useState)(!1),u=(0,g.useRef)(null),d=n==null?t:`${t} · ${O(n)}`;return(0,g.useEffect)(()=>{let t=!1,n=null;return(async()=>{try{let{loadPdf:r,renderPageToFit:i}=await s(async()=>{let{loadPdf:e,renderPageToFit:t}=await import(`./pdf-render-jAQU0nXt.js`);return{loadPdf:e,renderPageToFit:t}},__vite__mapDeps([0,1])),a=await r(e);n=a;let o=u.current;if(t||!o)return;await i(a,1,o,M,ee)}catch{t||(l(!0),r?.(`render`))}})(),()=>{t=!0;try{n?.destroy()}catch{}}},[e]),c?(0,_.jsx)(k,{href:e,filename:t,label:d}):(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)(`div`,{className:`chat-attachment-pdf`,children:[(0,_.jsx)(`canvas`,{ref:u,className:`chat-attachment-pdf-canvas`,"aria-label":t}),(0,_.jsx)(A,{href:e,filename:t,className:`chat-attachment-download`}),(0,_.jsx)(`button`,{type:`button`,className:`chat-attachment-pdf-expand`,"aria-label":`Expand ${t}`,onClick:()=>a(!0),children:(0,_.jsx)(o,{size:14,"aria-hidden":!0})})]}),i&&(0,_.jsx)(F,{src:e,filename:t,label:d,onClose:()=>a(!1),onFail:r})]})}function F({src:e,filename:n,label:r,onClose:i,onFail:a}){let o=(0,g.useRef)(null),c=(0,g.useRef)(null),[l,u]=(0,g.useState)(null),[d,f]=(0,g.useState)(!1);return(0,g.useEffect)(()=>{let t=!1;return(async()=>{try{let{loadPdf:n}=await s(async()=>{let{loadPdf:e}=await import(`./pdf-render-jAQU0nXt.js`);return{loadPdf:e}},__vite__mapDeps([0,1])),r=await n(e);if(t){try{r.destroy()}catch{}return}c.current=r,u(r.numPages)}catch{t||(f(!0),a?.(`render`))}})(),()=>{t=!0;try{c.current?.destroy()}catch{}}},[e]),(0,g.useEffect)(()=>{if(l==null)return;let e=o.current,t=c.current;if(!e||!t)return;let n=!1;return(async()=>{try{let{renderPageToWidth:r}=await s(async()=>{let{renderPageToWidth:e}=await import(`./pdf-render-jAQU0nXt.js`);return{renderPageToWidth:e}},__vite__mapDeps([0,1])),i=Array.from(e.querySelectorAll(`canvas.chat-attachment-overlay-page`)),a=Math.max(e.clientWidth-N*2,1);for(let e=0;e<i.length;e++){if(n)return;await r(t,e+1,i[e],a)}}catch{n||(f(!0),a?.(`render`))}})(),()=>{n=!0}},[l]),(0,_.jsxs)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":n,onClick:i,children:[(0,_.jsx)(`div`,{ref:o,className:`chat-attachment-overlay-pdf`,onClick:e=>e.stopPropagation(),children:d?(0,_.jsx)(k,{href:e,filename:n,label:r}):Array.from({length:l??0},(e,t)=>(0,_.jsx)(`canvas`,{className:`chat-attachment-overlay-page`,"aria-label":`${n} page ${t+1}`},t))}),(0,_.jsx)(A,{href:e,filename:n,className:`chat-attachment-overlay-download`,size:20,onClick:e=>e.stopPropagation()}),(0,_.jsx)(`button`,{type:`button`,className:`chat-attachment-overlay-close`,"aria-label":`Close`,onClick:i,children:(0,_.jsx)(t,{size:20,"aria-hidden":!0})})]})}function I({filename:e,href:t,mimeType:n,sizeBytes:r,expandable:i,telemetry:a}){let o=T(e,n);(0,g.useEffect)(()=>{a?.onRender?.({kind:o,mime:n,served:!!t})},[]);let s=a?.onFail?e=>a.onFail({kind:o===`pdf`?`pdf`:`image`,mime:n,reason:e}):void 0;if(o===`image`&&t)return(0,_.jsx)(j,{src:t,filename:e,sizeBytes:r,expandable:i,onFail:s});if(o===`audio`&&t)return(0,_.jsx)(`audio`,{className:`chat-attachment-audio`,controls:!0,preload:`metadata`,src:t});if(o===`pdf`&&t)return(0,_.jsx)(P,{src:t,filename:e,sizeBytes:r,onFail:s});let c=r==null?e:`${e} · ${O(r)}`;return t?(0,_.jsx)(k,{href:t,filename:e,label:c}):(0,_.jsxs)(`p`,{className:`chat-doc`,children:[(0,_.jsx)(h,{size:14,"aria-hidden":!0,style:{verticalAlign:`text-bottom`}}),` `,c]})}function L(e,t,n,r=`/api/whatsapp-reader/stream`,i=e,a=!0){let[o,s]=(0,g.useState)([]),[c,l]=(0,g.useState)(`open`),[u,d]=(0,g.useState)(null),f=(0,g.useRef)([]);return(0,g.useEffect)(()=>{f.current=o},[o]),(0,g.useEffect)(()=>{s([]),f.current=[],d(null)},[i,t,n,r]),(0,g.useEffect)(()=>{if(l(`open`),!a)return;let i=f.current.slice(),o=i.map(R),c=0,u=i.length>0,p=`${r}?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,m=new EventSource(p);return m.onopen=()=>{console.info(`[admin-ui] wa-stream onopen sessionId=${e}`),l(`open`)},m.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(u){if(c<o.length&&R(t)===o[c]){c+=1;return}u=!1}s(e=>[...e,t])},m.addEventListener(`activity`,e=>{try{d(JSON.parse(e.data))}catch{}}),m.addEventListener(`activity-clear`,()=>d(null)),m.onerror=()=>{m.readyState===2&&(console.error(`[admin-ui] wa-stream onerror readyState=${m.readyState}`),l(`error`))},()=>m.close()},[e,t,n,r,i,a]),{turns:o,status:c,subagentActivity:u}}function R(e){return JSON.stringify(e)}function te(e,t,n,r=!0){let[i,a]=(0,g.useState)([]),[o,s]=(0,g.useState)(`open`);return(0,g.useEffect)(()=>{if(a([]),s(`open`),!r||!e||!t)return;let i=`/api/whatsapp-reader/store-stream?accountId=${encodeURIComponent(e)}&remoteJid=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,o=new EventSource(i);return o.onopen=()=>s(`open`),o.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}a(e=>[...e,t])},o.onerror=()=>{o.readyState===2&&s(`error`)},()=>o.close()},[e,t,n,r]),{turns:i,status:o}}var z=e=>{if(!e)return 1/0;let t=new Date(e).getTime();return Number.isNaN(t)?1/0:t};function ne(e,t){let n=[],r=0;return e.forEach((e,t)=>n.push({sort:z(e.ts),sub:1,ins:r++,item:{kind:`turn`,turn:e,idx:t}})),t.forEach(e=>n.push({sort:z(e.ts),sub:0,ins:r++,item:{kind:`directive`,entry:e}})),n.sort((e,t)=>e.sort===t.sort?e.sort===1/0?e.ins-t.ins:e.sub-t.sub||e.ins-t.ins:e.sort<t.sort?-1:1).map(e=>e.item)}function re(e,t,n=!0){let[r,i]=(0,g.useState)([]);return(0,g.useEffect)(()=>{if(!n||typeof fetch!=`function`)return;let r=!0,a=`/api/whatsapp-reader/directives?sessionId=${encodeURIComponent(e)}&session_key=${encodeURIComponent(t)}`;return fetch(a).then(e=>e.ok?e.json():{entries:[]}).then(e=>{r&&i(Array.isArray(e.entries)?e.entries:[])}).catch(()=>{r&&i([])}),()=>{r=!1}},[e,t,n]),r}var ie=new Set([`operator-inbound`,`operator-typed`,`agent-reply`,`agent-reply-document`,`agent-file`,`agent-error`,`whatsapp-persisted`]);function B(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function V(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}var H=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],U=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function W(e){let t=String(e.getMonth()+1).padStart(2,`0`),n=String(e.getDate()).padStart(2,`0`);return`${e.getFullYear()}-${t}-${n}`}function G(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:W(t)}function K(e,t=new Date){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=W(n);if(r===W(t))return`Today`;let i=new Date(t);return i.setDate(i.getDate()-1),r===W(i)?`Yesterday`:`${H[n.getDay()]} ${n.getDate()} ${U[n.getMonth()]} ${n.getFullYear()}`}function q(e){return e.kind===`turn`?e.turn.ts:e.entry.ts}function J({ts:e}){return(0,_.jsx)(`div`,{className:`day-divider`,role:`separator`,children:(0,_.jsx)(`span`,{className:`day-divider-label`,children:K(e)})})}function Y(){return(0,_.jsx)(`div`,{className:`session-divider`,role:`separator`,children:(0,_.jsx)(`span`,{className:`session-divider-label`,children:`Conversation continued`})})}function X({label:e,ts:t}){return(0,_.jsxs)(`div`,{className:`wa-turn-head`,children:[(0,_.jsx)(`span`,{className:`wa-who`,children:e}),(0,_.jsx)(`time`,{className:`wa-time`,children:B(t)})]})}function ae({turn:e}){let[t,n]=(0,g.useState)(!1),r=e.kind===`tool-result`,i=r?`wa-turn wa-turn-result${e.isError?` is-error`:``}`:`wa-turn wa-turn-tool`,a=r?e.isError?`result (error)`:`result`:`↳ ${e.name}`,o=r?e.text:JSON.stringify(e.input,null,2);return(0,_.jsxs)(`div`,{className:i,children:[(0,_.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,_.jsx)(`span`,{className:`wa-chevron`,children:t?`▾`:`▸`}),(0,_.jsx)(`span`,{className:`wa-who`,children:a}),(0,_.jsx)(`time`,{className:`wa-time`,children:B(e.ts)})]}),t&&(0,_.jsx)(`pre`,{className:`wa-code`,children:o})]})}function Z({entry:e,sessionId:t,sessionKey:n}){let[r,i]=(0,g.useState)(!1),[a,o]=(0,g.useState)(null),s=()=>{let s=!r;if(i(s),s&&a===null&&typeof fetch==`function`){let r=`/api/whatsapp-reader/directive?sessionId=${encodeURIComponent(t)}&name=${encodeURIComponent(e.name)}&session_key=${encodeURIComponent(n)}`;fetch(r).then(e=>e.ok?e.text():`(directive unavailable)`).then(o).catch(()=>o(`(directive unavailable)`))}};return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-directive`,children:[(0,_.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":r,onClick:s,children:[(0,_.jsx)(`span`,{className:`wa-chevron`,children:r?`▾`:`▸`}),(0,_.jsxs)(`span`,{className:`wa-who`,children:[`⚙ directive injected (`,e.len,` B)`]}),(0,_.jsx)(`time`,{className:`wa-time`,children:B(e.ts)})]}),r&&(0,_.jsx)(`pre`,{className:`wa-code`,children:a??`Loading…`})]})}var Q={onRender:({kind:e,mime:t,served:n})=>console.info(`[operator-ui] op=reader-attachment kind=${e} mime=${t??``} served=${n}`),onFail:({kind:e,mime:t,reason:n})=>console.info(`[operator-ui] op=reader-attachment-fail kind=${e} mime=${t??``} reason=${n}`)};function oe(e,t,n){switch(e.kind){case`operator-inbound`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,_.jsx)(X,{label:`Operator${S(e.source)}`,ts:e.ts}),e.text&&(0,_.jsx)(`p`,{className:`wa-body`,children:e.text}),e.attachments&&e.attachments.length>0&&(0,_.jsx)(`div`,{className:`chat-attachment-list`,children:e.attachments.map((e,t)=>(0,_.jsx)(I,{expandable:!0,filename:e.filename,mimeType:e.mimeType,sizeBytes:e.sizeBytes,href:D(e.attachmentId,n.audience,n.sessionId,n.sessionKey),telemetry:Q},t))})]},t);case`operator-typed`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,_.jsx)(X,{label:`Operator (web)`,ts:e.ts}),(0,_.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-text`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-think`,children:[(0,_.jsx)(X,{label:`Agent`,ts:e.ts}),(0,_.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,_.jsx)(X,{label:`Agent`,ts:e.ts}),(0,_.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply-document`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,_.jsx)(X,{label:`Agent`,ts:e.ts}),(0,_.jsxs)(`p`,{className:`wa-doc`,children:[(0,_.jsx)(h,{size:14,"aria-hidden":!0,style:{verticalAlign:`text-bottom`}}),` `,`sent document(s): `,e.files.map(V).join(`, `)]}),e.caption&&(0,_.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`agent-file`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,_.jsx)(X,{label:`Agent`,ts:e.ts}),e.files.map((t,r)=>{let i=V(t),a=e.downloads?.[r];return(0,_.jsx)(I,{expandable:!0,filename:i,href:a?E(a,n.sessionId,n.sessionKey,w.test(i)?`inline`:void 0):void 0,telemetry:Q},r)}),e.caption&&(0,_.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`whatsapp-persisted`:{let n=e.origin===`operator-manual`,r=e.fromMe?n?`You`:`Sent`:e.senderName??`Contact`;return(0,_.jsxs)(`div`,{className:`wa-turn ${e.fromMe?`wa-turn-out`:`wa-turn-in`}${n?` wa-op-manual`:``}`,children:[(0,_.jsx)(X,{label:r,ts:e.ts}),(0,_.jsx)(`p`,{className:`wa-body`,children:e.text}),(0,_.jsxs)(`span`,{className:`wa-bubble-meta`,children:[n&&(0,_.jsx)(`span`,{className:`wa-op-tag`,children:`You`}),(0,_.jsx)(`time`,{className:`wa-bubble-time`,children:B(e.ts)}),e.fromMe&&(0,_.jsx)(f,{size:14,className:`wa-bubble-tick`,"aria-hidden":!0})]})]},t)}case`session-continued`:return(0,_.jsx)(Y,{},t);case`harness-internal`:return null;case`tool-call`:case`tool-result`:return(0,_.jsx)(ae,{turn:e},t);case`agent-error`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-error`,role:`alert`,children:[(0,_.jsx)(X,{label:`Agent`,ts:e.ts}),(0,_.jsx)(`p`,{className:`wa-body wa-error-body`,children:x(e.code,`admin`)}),e.code===`agent_error`&&e.raw&&(0,_.jsx)(`pre`,{className:`wa-code`,children:e.raw})]},t)}}function $(e,t,n,r=`admin`){let i={sessionId:t,sessionKey:n,audience:r},a=[],o=null;return e.forEach((e,r)=>{let s=q(e),c=G(s);c!==null&&c!==o&&(a.push((0,_.jsx)(J,{ts:s},`day-${r}`)),o=c),a.push(e.kind===`turn`?oe(e.turn,r,i):(0,_.jsx)(Z,{entry:e.entry,sessionId:t,sessionKey:n},r))}),a}function se(e){return e.filter(e=>e.kind===`turn`&&ie.has(e.turn.kind))}function ce({sessionId:e,projectDir:t,sessionKey:n,renderItems:r=$,clean:i,onToggleClean:a,forceDeliveredOnly:o=!1,streamEndpoint:s=`/api/whatsapp-reader/stream`,suppressDirectives:c=!1,tail:l=null,resetKey:u,onTurnsChange:d,onActivityChange:f,store:p}){let m=!!p,h=L(e,t,n,s,u,!m),y=te(p?.accountId??``,p?.remoteJid??``,n,m),{turns:b,status:x}=m?{turns:y.turns,status:y.status}:{turns:h.turns,status:h.status},S=m?null:h.subagentActivity;(0,g.useEffect)(()=>{f?.(S)},[S,f]),(0,g.useEffect)(()=>{d?.(b.length)},[b.length,d]);let C=ne(b,re(e,n,!c)),w=a==null?!1:!!i,T=o||w?se(C):C;return(0,_.jsxs)(v,{repinSignals:[b,w],tail:l,children:[x===`error`&&(0,_.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),b.length===0&&x===`open`&&(0,_.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),r(T,e,n)]})}function le(e,t){let n=e.split(`;`)[0].trim().toLowerCase();return t.has(n)}export{d as C,l as S,h as _,ce as a,c as b,B as c,P as d,C as f,x as g,E as h,Y as i,q as l,D as m,J as n,V as o,w as p,Z as r,G as s,le as t,I as u,m as v,u as x,p as y};
2
+ import{o as e}from"./chunk-Ck5AOu5v.js";import{a as t,m as n,w as r,y as i}from"./useSubAccountSwitcher-DyjTbzQR.js";import{h as a}from"./file-download-B2B2DTar.js";import{t as o}from"./maximize-2-DKx6OBKv.js";import{t as s}from"./preload-helper-ClBMtM1g.js";var c=`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,application/zip,application/x-zip-compressed,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.oasis.opendocument.text,text/rtf,application/rtf,audio/ogg,audio/opus,audio/mp4,audio/x-m4a,audio/mpeg,audio/webm,audio/wav,video/mp4,.docx,.odt,.rtf,.opus,.ogg,.m4a,.mp4,.mp3,.wav,.webm`,l=new Set(c.split(`,`).filter(e=>!e.startsWith(`.`))),u=50*1024*1024;function d(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}var f=n(`check-check`,[[`path`,{d:`M18 6 7 17l-5-5`,key:`116fxf`}],[`path`,{d:`m22 10-7.5 7.5L13 16`,key:`ke71qq`}]]),p=n(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),m=n(`file-code`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 12.5 8 15l2 2.5`,key:`1tg20x`}],[`path`,{d:`m14 12.5 2 2.5-2 2.5`,key:`yinavb`}]]),h=n(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),g=e(r(),1),_=i();function v({children:e,tail:t=null,repinSignals:n}){let r=(0,g.useRef)(null),i=(0,g.useRef)(null),a=(0,g.useRef)(!0),[o,s]=(0,g.useState)(!0),c=(0,g.useRef)(0),l=(0,g.useRef)(0),u=()=>{let e=r.current;if(!e)return;let t=e.clientHeight,n=e.scrollHeight,i=t!==c.current||n!==l.current;if(c.current=t,l.current=n,i){a.current&&(e.scrollTop=e.scrollHeight);return}let o=n-e.scrollTop-t<=32;a.current=o,s(e=>e===o?e:o)},d=()=>{let e=r.current;e&&(e.scrollTop=e.scrollHeight,l.current=e.scrollHeight,c.current=e.clientHeight,a.current=!0,s(!0))},f=t!=null;return(0,g.useLayoutEffect)(()=>{let e=r.current;e&&a.current&&(e.scrollTop=e.scrollHeight),e&&(l.current=e.scrollHeight,c.current=e.clientHeight)},[...n,f]),(0,g.useLayoutEffect)(()=>{if(typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>u());return r.current&&e.observe(r.current),i.current&&e.observe(i.current),()=>e.disconnect()},[]),(0,_.jsxs)(`div`,{className:`wa-reader`,children:[(0,_.jsx)(`div`,{className:`wa-reader-thread`,ref:r,onScroll:u,children:(0,_.jsxs)(`div`,{className:`wa-thread-scroll`,ref:i,children:[e,t]})}),!o&&(0,_.jsx)(`button`,{type:`button`,className:`wa-jump`,onClick:d,"aria-label":`Jump to latest message`,title:`Jump to latest message`,children:`↓`})]})}var y={auth_expired:`Your session has expired. Please sign in again.`,claude_down:`Claude is currently experiencing an outage. Please try again in a few minutes.`,claude_overloaded:`Claude is overloaded right now. Please try again shortly.`,model_unavailable:`The selected model is currently unavailable. Switch to a different model from the model picker to continue.`,agent_error:`Something went wrong. Please try again.`},b={auth_expired:`I'm not available right now. Please try again later.`,claude_down:`I'm not available right now. Please try again later.`,claude_overloaded:`I'm not available right now. Please try again shortly.`,model_unavailable:`I'm not available right now. Please try again later.`,agent_error:`I'm not available right now. Please try again later.`};function x(e,t=`admin`){return t===`public`?b[e]:y[e]}function S(e){return e===`whatsapp`?` · via WhatsApp`:e===`webchat`?` · via web`:``}var C=/\.(png|jpe?g|gif|webp|svg|bmp)$/i,w=/\.pdf$/i;function T(e,t){return(t?t.startsWith(`image/`):C.test(e))?`image`:t&&t.startsWith(`audio/`)?`audio`:(t?t===`application/pdf`:w.test(e))?`pdf`:`file`}function E(e,t,n,r){let i=encodeURIComponent(e.path),a=encodeURIComponent(n),o=r?`&disposition=${r}`:``;return e.root===`scratchpad`?`/api/admin/files/download?path=${i}&root=scratchpad&sessionId=${encodeURIComponent(t)}&session_key=${a}${o}`:`/api/admin/files/download?path=${i}&root=data&session_key=${a}${o}`}function D(e,t,n,r){return t===`public`?`/api/public-reader/attachment/${e}?sessionId=${encodeURIComponent(n)}`:`/api/admin/attachment/${e}?session_key=${encodeURIComponent(r)}`}function O(e){if(e<1024)return`${e} B`;let t=e/1024;if(t<1024)return`${t<10?t.toFixed(1):Math.round(t)} KB`;let n=t/1024;return`${n<10?n.toFixed(1):Math.round(n)} MB`}function k({href:e,filename:t,label:n}){return(0,_.jsxs)(`a`,{className:`chat-attachment-chip`,href:e,download:t,children:[(0,_.jsx)(h,{size:14,"aria-hidden":!0}),n]})}function A({href:e,filename:t,className:n,size:r=14,onClick:i}){return(0,_.jsx)(`a`,{className:n,href:e,download:t,"aria-label":`Download ${t}`,onClick:i,children:(0,_.jsx)(a,{size:r,"aria-hidden":!0})})}function j({src:e,filename:t,sizeBytes:n,expandable:r,onFail:i}){let[a,o]=(0,g.useState)(!1),[s,c]=(0,g.useState)(!1),l=n==null?t:`${t} · ${O(n)}`;return s?(0,_.jsx)(k,{href:e,filename:t,label:l}):(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)(`span`,{className:`chat-attachment-image-wrap`,children:[(0,_.jsx)(`img`,{className:`chat-attachment-image`,src:e,alt:t,onClick:r?()=>o(!0):void 0,onError:()=>{c(!0),i?.(`fetch`)}}),(0,_.jsx)(A,{href:e,filename:t,className:`chat-attachment-download`})]}),r&&a&&(0,_.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":t,onClick:()=>o(!1),children:(0,_.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:e,alt:t})})]})}var M=280,ee=360,N=16;function P({src:e,filename:t,sizeBytes:n,onFail:r}){let[i,a]=(0,g.useState)(!1),[c,l]=(0,g.useState)(!1),u=(0,g.useRef)(null),d=n==null?t:`${t} · ${O(n)}`;return(0,g.useEffect)(()=>{let t=!1,n=null;return(async()=>{try{let{loadPdf:r,renderPageToFit:i}=await s(async()=>{let{loadPdf:e,renderPageToFit:t}=await import(`./pdf-render-jAQU0nXt.js`);return{loadPdf:e,renderPageToFit:t}},__vite__mapDeps([0,1])),a=await r(e);n=a;let o=u.current;if(t||!o)return;await i(a,1,o,M,ee)}catch{t||(l(!0),r?.(`render`))}})(),()=>{t=!0;try{n?.destroy()}catch{}}},[e]),c?(0,_.jsx)(k,{href:e,filename:t,label:d}):(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)(`div`,{className:`chat-attachment-pdf`,children:[(0,_.jsx)(`canvas`,{ref:u,className:`chat-attachment-pdf-canvas`,"aria-label":t}),(0,_.jsx)(A,{href:e,filename:t,className:`chat-attachment-download`}),(0,_.jsx)(`button`,{type:`button`,className:`chat-attachment-pdf-expand`,"aria-label":`Expand ${t}`,onClick:()=>a(!0),children:(0,_.jsx)(o,{size:14,"aria-hidden":!0})})]}),i&&(0,_.jsx)(F,{src:e,filename:t,label:d,onClose:()=>a(!1),onFail:r})]})}function F({src:e,filename:n,label:r,onClose:i,onFail:a}){let o=(0,g.useRef)(null),c=(0,g.useRef)(null),[l,u]=(0,g.useState)(null),[d,f]=(0,g.useState)(!1);return(0,g.useEffect)(()=>{let t=!1;return(async()=>{try{let{loadPdf:n}=await s(async()=>{let{loadPdf:e}=await import(`./pdf-render-jAQU0nXt.js`);return{loadPdf:e}},__vite__mapDeps([0,1])),r=await n(e);if(t){try{r.destroy()}catch{}return}c.current=r,u(r.numPages)}catch{t||(f(!0),a?.(`render`))}})(),()=>{t=!0;try{c.current?.destroy()}catch{}}},[e]),(0,g.useEffect)(()=>{if(l==null)return;let e=o.current,t=c.current;if(!e||!t)return;let n=!1;return(async()=>{try{let{renderPageToWidth:r}=await s(async()=>{let{renderPageToWidth:e}=await import(`./pdf-render-jAQU0nXt.js`);return{renderPageToWidth:e}},__vite__mapDeps([0,1])),i=Array.from(e.querySelectorAll(`canvas.chat-attachment-overlay-page`)),a=Math.max(e.clientWidth-N*2,1);for(let e=0;e<i.length;e++){if(n)return;await r(t,e+1,i[e],a)}}catch{n||(f(!0),a?.(`render`))}})(),()=>{n=!0}},[l]),(0,_.jsxs)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":n,onClick:i,children:[(0,_.jsx)(`div`,{ref:o,className:`chat-attachment-overlay-pdf`,onClick:e=>e.stopPropagation(),children:d?(0,_.jsx)(k,{href:e,filename:n,label:r}):Array.from({length:l??0},(e,t)=>(0,_.jsx)(`canvas`,{className:`chat-attachment-overlay-page`,"aria-label":`${n} page ${t+1}`},t))}),(0,_.jsx)(A,{href:e,filename:n,className:`chat-attachment-overlay-download`,size:20,onClick:e=>e.stopPropagation()}),(0,_.jsx)(`button`,{type:`button`,className:`chat-attachment-overlay-close`,"aria-label":`Close`,onClick:i,children:(0,_.jsx)(t,{size:20,"aria-hidden":!0})})]})}function I({filename:e,href:t,mimeType:n,sizeBytes:r,expandable:i,telemetry:a}){let o=T(e,n);(0,g.useEffect)(()=>{a?.onRender?.({kind:o,mime:n,served:!!t})},[]);let s=a?.onFail?e=>a.onFail({kind:o===`pdf`?`pdf`:`image`,mime:n,reason:e}):void 0;if(o===`image`&&t)return(0,_.jsx)(j,{src:t,filename:e,sizeBytes:r,expandable:i,onFail:s});if(o===`audio`&&t)return(0,_.jsx)(`audio`,{className:`chat-attachment-audio`,controls:!0,preload:`metadata`,src:t});if(o===`pdf`&&t)return(0,_.jsx)(P,{src:t,filename:e,sizeBytes:r,onFail:s});let c=r==null?e:`${e} · ${O(r)}`;return t?(0,_.jsx)(k,{href:t,filename:e,label:c}):(0,_.jsxs)(`p`,{className:`chat-doc`,children:[(0,_.jsx)(h,{size:14,"aria-hidden":!0,style:{verticalAlign:`text-bottom`}}),` `,c]})}function L(e,t,n,r=`/api/whatsapp-reader/stream`,i=e,a=!0){let[o,s]=(0,g.useState)([]),[c,l]=(0,g.useState)(`open`),[u,d]=(0,g.useState)(null),f=(0,g.useRef)([]);return(0,g.useEffect)(()=>{f.current=o},[o]),(0,g.useEffect)(()=>{s([]),f.current=[],d(null)},[i,t,n,r]),(0,g.useEffect)(()=>{if(l(`open`),!a)return;let i=f.current.slice(),o=i.map(R),c=0,u=i.length>0,p=`${r}?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,m=new EventSource(p);return m.onopen=()=>{console.info(`[admin-ui] wa-stream onopen sessionId=${e}`),l(`open`)},m.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(u){if(c<o.length&&R(t)===o[c]){c+=1;return}u=!1}s(e=>[...e,t])},m.addEventListener(`activity`,e=>{try{d(JSON.parse(e.data))}catch{}}),m.addEventListener(`activity-clear`,()=>d(null)),m.onerror=()=>{m.readyState===2&&(console.error(`[admin-ui] wa-stream onerror readyState=${m.readyState}`),l(`error`))},()=>m.close()},[e,t,n,r,i,a]),{turns:o,status:c,subagentActivity:u}}function R(e){return JSON.stringify(e)}function te(e,t,n,r=!0){let[i,a]=(0,g.useState)([]),[o,s]=(0,g.useState)(`open`);return(0,g.useEffect)(()=>{if(a([]),s(`open`),!r||!e||!t)return;let i=`/api/whatsapp-reader/store-stream?accountId=${encodeURIComponent(e)}&remoteJid=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,o=new EventSource(i);return o.onopen=()=>s(`open`),o.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}a(e=>[...e,t])},o.onerror=()=>{o.readyState===2&&s(`error`)},()=>o.close()},[e,t,n,r]),{turns:i,status:o}}var z=e=>{if(!e)return 1/0;let t=new Date(e).getTime();return Number.isNaN(t)?1/0:t};function ne(e,t){let n=[],r=0;return e.forEach((e,t)=>n.push({sort:z(e.ts),sub:1,ins:r++,item:{kind:`turn`,turn:e,idx:t}})),t.forEach(e=>n.push({sort:z(e.ts),sub:0,ins:r++,item:{kind:`directive`,entry:e}})),n.sort((e,t)=>e.sort===t.sort?e.sort===1/0?e.ins-t.ins:e.sub-t.sub||e.ins-t.ins:e.sort<t.sort?-1:1).map(e=>e.item)}function re(e,t,n=!0){let[r,i]=(0,g.useState)([]);return(0,g.useEffect)(()=>{if(!n||typeof fetch!=`function`)return;let r=!0,a=`/api/whatsapp-reader/directives?sessionId=${encodeURIComponent(e)}&session_key=${encodeURIComponent(t)}`;return fetch(a).then(e=>e.ok?e.json():{entries:[]}).then(e=>{r&&i(Array.isArray(e.entries)?e.entries:[])}).catch(()=>{r&&i([])}),()=>{r=!1}},[e,t,n]),r}var ie=new Set([`operator-inbound`,`operator-typed`,`agent-reply`,`agent-reply-document`,`agent-file`,`agent-error`,`agent-webchat-final`,`whatsapp-persisted`]);function B(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function V(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}var H=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],U=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function W(e){let t=String(e.getMonth()+1).padStart(2,`0`),n=String(e.getDate()).padStart(2,`0`);return`${e.getFullYear()}-${t}-${n}`}function G(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:W(t)}function K(e,t=new Date){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=W(n);if(r===W(t))return`Today`;let i=new Date(t);return i.setDate(i.getDate()-1),r===W(i)?`Yesterday`:`${H[n.getDay()]} ${n.getDate()} ${U[n.getMonth()]} ${n.getFullYear()}`}function q(e){return e.kind===`turn`?e.turn.ts:e.entry.ts}function J({ts:e}){return(0,_.jsx)(`div`,{className:`day-divider`,role:`separator`,children:(0,_.jsx)(`span`,{className:`day-divider-label`,children:K(e)})})}function Y(){return(0,_.jsx)(`div`,{className:`session-divider`,role:`separator`,children:(0,_.jsx)(`span`,{className:`session-divider-label`,children:`Conversation continued`})})}function X({label:e,ts:t}){return(0,_.jsxs)(`div`,{className:`wa-turn-head`,children:[(0,_.jsx)(`span`,{className:`wa-who`,children:e}),(0,_.jsx)(`time`,{className:`wa-time`,children:B(t)})]})}function ae({turn:e}){let[t,n]=(0,g.useState)(!1),r=e.kind===`tool-result`,i=r?`wa-turn wa-turn-result${e.isError?` is-error`:``}`:`wa-turn wa-turn-tool`,a=r?e.isError?`result (error)`:`result`:`↳ ${e.name}`,o=r?e.text:JSON.stringify(e.input,null,2);return(0,_.jsxs)(`div`,{className:i,children:[(0,_.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,_.jsx)(`span`,{className:`wa-chevron`,children:t?`▾`:`▸`}),(0,_.jsx)(`span`,{className:`wa-who`,children:a}),(0,_.jsx)(`time`,{className:`wa-time`,children:B(e.ts)})]}),t&&(0,_.jsx)(`pre`,{className:`wa-code`,children:o})]})}function Z({entry:e,sessionId:t,sessionKey:n}){let[r,i]=(0,g.useState)(!1),[a,o]=(0,g.useState)(null),s=()=>{let s=!r;if(i(s),s&&a===null&&typeof fetch==`function`){let r=`/api/whatsapp-reader/directive?sessionId=${encodeURIComponent(t)}&name=${encodeURIComponent(e.name)}&session_key=${encodeURIComponent(n)}`;fetch(r).then(e=>e.ok?e.text():`(directive unavailable)`).then(o).catch(()=>o(`(directive unavailable)`))}};return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-directive`,children:[(0,_.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":r,onClick:s,children:[(0,_.jsx)(`span`,{className:`wa-chevron`,children:r?`▾`:`▸`}),(0,_.jsxs)(`span`,{className:`wa-who`,children:[`⚙ directive injected (`,e.len,` B)`]}),(0,_.jsx)(`time`,{className:`wa-time`,children:B(e.ts)})]}),r&&(0,_.jsx)(`pre`,{className:`wa-code`,children:a??`Loading…`})]})}var Q={onRender:({kind:e,mime:t,served:n})=>console.info(`[operator-ui] op=reader-attachment kind=${e} mime=${t??``} served=${n}`),onFail:({kind:e,mime:t,reason:n})=>console.info(`[operator-ui] op=reader-attachment-fail kind=${e} mime=${t??``} reason=${n}`)};function oe(e,t,n){switch(e.kind){case`operator-inbound`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,_.jsx)(X,{label:`Operator${S(e.source)}`,ts:e.ts}),e.text&&(0,_.jsx)(`p`,{className:`wa-body`,children:e.text}),e.attachments&&e.attachments.length>0&&(0,_.jsx)(`div`,{className:`chat-attachment-list`,children:e.attachments.map((e,t)=>(0,_.jsx)(I,{expandable:!0,filename:e.filename,mimeType:e.mimeType,sizeBytes:e.sizeBytes,href:D(e.attachmentId,n.audience,n.sessionId,n.sessionKey),telemetry:Q},t))})]},t);case`operator-typed`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,_.jsx)(X,{label:`Operator (web)`,ts:e.ts}),(0,_.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-text`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-think`,children:[(0,_.jsx)(X,{label:`Agent`,ts:e.ts}),(0,_.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,_.jsx)(X,{label:`Agent`,ts:e.ts}),(0,_.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply-document`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,_.jsx)(X,{label:`Agent`,ts:e.ts}),(0,_.jsxs)(`p`,{className:`wa-doc`,children:[(0,_.jsx)(h,{size:14,"aria-hidden":!0,style:{verticalAlign:`text-bottom`}}),` `,`sent document(s): `,e.files.map(V).join(`, `)]}),e.caption&&(0,_.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`agent-file`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,_.jsx)(X,{label:`Agent`,ts:e.ts}),e.files.map((t,r)=>{let i=V(t),a=e.downloads?.[r];return(0,_.jsx)(I,{expandable:!0,filename:i,href:a?E(a,n.sessionId,n.sessionKey,w.test(i)?`inline`:void 0):void 0,telemetry:Q},r)}),e.caption&&(0,_.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`whatsapp-persisted`:{let r=e.origin===`operator-manual`,i=e.fromMe?r?`You`:`Sent`:e.senderName??`Contact`;return(0,_.jsxs)(`div`,{className:`wa-turn ${e.fromMe?`wa-turn-out`:`wa-turn-in`}${r?` wa-op-manual`:``}`,children:[(0,_.jsx)(X,{label:i,ts:e.ts}),e.text&&(0,_.jsx)(`p`,{className:`wa-body`,children:e.text}),e.attachments&&e.attachments.length>0&&(0,_.jsx)(`div`,{className:`chat-attachment-list`,children:e.attachments.map((e,t)=>(0,_.jsx)(I,{expandable:!0,filename:e.filename,mimeType:e.mimeType,sizeBytes:e.sizeBytes,href:D(e.attachmentId,n.audience,n.sessionId,n.sessionKey),telemetry:Q},t))}),(0,_.jsxs)(`span`,{className:`wa-bubble-meta`,children:[r&&(0,_.jsx)(`span`,{className:`wa-op-tag`,children:`You`}),(0,_.jsx)(`time`,{className:`wa-bubble-time`,children:B(e.ts)}),e.fromMe&&(0,_.jsx)(f,{size:14,className:`wa-bubble-tick`,"aria-hidden":!0})]})]},t)}case`session-continued`:return(0,_.jsx)(Y,{},t);case`harness-internal`:return null;case`tool-call`:case`tool-result`:return(0,_.jsx)(ae,{turn:e},t);case`agent-error`:return(0,_.jsxs)(`div`,{className:`wa-turn wa-turn-error`,role:`alert`,children:[(0,_.jsx)(X,{label:`Agent`,ts:e.ts}),(0,_.jsx)(`p`,{className:`wa-body wa-error-body`,children:x(e.code,`admin`)}),e.code===`agent_error`&&e.raw&&(0,_.jsx)(`pre`,{className:`wa-code`,children:e.raw})]},t)}}function $(e,t,n,r=`admin`){let i={sessionId:t,sessionKey:n,audience:r},a=[],o=null;return e.forEach((e,r)=>{let s=q(e),c=G(s);c!==null&&c!==o&&(a.push((0,_.jsx)(J,{ts:s},`day-${r}`)),o=c),a.push(e.kind===`turn`?oe(e.turn,r,i):(0,_.jsx)(Z,{entry:e.entry,sessionId:t,sessionKey:n},r))}),a}function se(e){return e.filter(e=>e.kind===`turn`&&ie.has(e.turn.kind))}function ce({sessionId:e,projectDir:t,sessionKey:n,renderItems:r=$,clean:i,onToggleClean:a,forceDeliveredOnly:o=!1,streamEndpoint:s=`/api/whatsapp-reader/stream`,suppressDirectives:c=!1,tail:l=null,resetKey:u,onTurnsChange:d,onActivityChange:f,store:p}){let m=!!p,h=L(e,t,n,s,u,!m),y=te(p?.accountId??``,p?.remoteJid??``,n,m),{turns:b,status:x}=m?{turns:y.turns,status:y.status}:{turns:h.turns,status:h.status},S=m?null:h.subagentActivity;(0,g.useEffect)(()=>{f?.(S)},[S,f]),(0,g.useEffect)(()=>{d?.(b.length)},[b.length,d]);let C=ne(b,re(e,n,!c)),w=a==null?!1:!!i,T=o||w?se(C):C;return(0,_.jsxs)(v,{repinSignals:[b,w],tail:l,children:[x===`error`&&(0,_.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),b.length===0&&x===`open`&&(0,_.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),r(T,e,n)]})}function le(e,t){let n=e.split(`;`)[0].trim().toLowerCase();return t.has(n)}export{d as C,l as S,h as _,ce as a,c as b,B as c,P as d,C as f,x as g,E as h,Y as i,q as l,D as m,J as n,V as o,w as p,Z as r,G as s,le as t,I as u,m as v,u as x,p as y};
@@ -1 +1 @@
1
- import{S as e,y as t}from"./useSubAccountSwitcher-DyjTbzQR.js";import"./audio-attachment-mime-BBW07eyG.js";import"./AdminShell-BfLQQ27Z.js";import{n}from"./page-JzxyFGle.js";import"./useCopyFeedback-CPEOUSGU.js";import"./file-download-B2B2DTar.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
1
+ import{S as e,y as t}from"./useSubAccountSwitcher-DyjTbzQR.js";import"./audio-attachment-mime-Cx5d3Jls.js";import"./AdminShell-BfLQQ27Z.js";import{n}from"./page-C3L6-Ufk.js";import"./useCopyFeedback-CPEOUSGU.js";import"./file-download-B2B2DTar.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
@@ -0,0 +1 @@
1
+ import{S as e,y as t}from"./useSubAccountSwitcher-DyjTbzQR.js";import"./audio-attachment-mime-Cx5d3Jls.js";import{t as n}from"./page-B7nCws9K.js";import"./file-download-B2B2DTar.js";import"./graph-labels-DxqDdO7G.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-Ck5AOu5v.js";import{S as t,w as n,y as r}from"./useSubAccountSwitcher-DyjTbzQR.js";import{n as i,t as a}from"./AdminLoginScreens-C4AZT7cQ.js";import"./audio-attachment-mime-BBW07eyG.js";import"./AdminShell-BfLQQ27Z.js";import"./Checkbox-BC0c_gbn.js";import{t as o}from"./page-JzxyFGle.js";import"./useCopyFeedback-CPEOUSGU.js";import"./file-download-B2B2DTar.js";var s=t(),c=e(n(),1),l=r();function u(){let e=i(`operator`),t=(0,c.useRef)(null);return(0,c.useEffect)(()=>{e.appState!==`chat`&&t.current!==e.appState&&(t.current=e.appState,console.info(`[operator-ui] op=auth-gate state=${e.appState}`))},[e.appState]),e.appState===`chat`?(0,l.jsx)(o,{variant:`operator`,forceCanonicalSession:window.location.pathname!==`/chat`}):(0,l.jsx)(a,{auth:e})}(0,s.createRoot)(document.getElementById(`root`)).render((0,l.jsx)(u,{}));
1
+ import{o as e}from"./chunk-Ck5AOu5v.js";import{S as t,w as n,y as r}from"./useSubAccountSwitcher-DyjTbzQR.js";import{n as i,t as a}from"./AdminLoginScreens-BM45lL5G.js";import"./audio-attachment-mime-Cx5d3Jls.js";import"./AdminShell-BfLQQ27Z.js";import"./Checkbox-BC0c_gbn.js";import{t as o}from"./page-C3L6-Ufk.js";import"./useCopyFeedback-CPEOUSGU.js";import"./file-download-B2B2DTar.js";var s=t(),c=e(n(),1),l=r();function u(){let e=i(`operator`),t=(0,c.useRef)(null);return(0,c.useEffect)(()=>{e.appState!==`chat`&&t.current!==e.appState&&(t.current=e.appState,console.info(`[operator-ui] op=auth-gate state=${e.appState}`))},[e.appState]),e.appState===`chat`?(0,l.jsx)(o,{variant:`operator`,forceCanonicalSession:window.location.pathname!==`/chat`}):(0,l.jsx)(a,{auth:e})}(0,s.createRoot)(document.getElementById(`root`)).render((0,l.jsx)(u,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-Ck5AOu5v.js";import{a as t,l as n,m as r,n as i,o as a,r as o,s,t as c,w as l,x as u,y as d}from"./useSubAccountSwitcher-DyjTbzQR.js";import{S as f,a as p,b as m,t as h,v as g,x as _,y as v}from"./audio-attachment-mime-BBW07eyG.js";import{t as y}from"./chevron-left-CLPxfjDV.js";import{a as b,c as x,d as ee,f as te,h as ne,i as re,m as ie,n as ae,p as oe,r as se,s as S,t as ce,u as le}from"./file-download-B2B2DTar.js";import{i as ue,t as C}from"./graph-labels-DxqDdO7G.js";var de=r(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),fe=r(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),pe=r(`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=r(`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=r(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),ge=r(`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`}]]),_e=r(`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`}]]),ve=r(`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`}]]),w=r(`phone`,[[`path`,{d:`M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384`,key:`9njp5v`}]]),ye=r(`send-horizontal`,[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]]),T=r(`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`}]]),be=r(`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`}]]),xe=r(`user`,[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]),E=r(`video`,[[`path`,{d:`m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5`,key:`ftymec`}],[`rect`,{x:`2`,y:`6`,width:`14`,height:`12`,rx:`2`,key:`158x01`}]]),D=e(l(),1);function Se(){let[e,t]=(0,D.useState)([]),[n,r]=(0,D.useState)(!1),[i,a]=(0,D.useState)(null),o=(0,D.useRef)(null),s=(0,D.useCallback)(e=>{a(null);let n=e.find(e=>!h(e.type,f));if(n){a(`Unsupported file type: "${n.type}". Supported: images, PDF, plain text, markdown, CSV, calendar, zip, voice notes.`);return}let r=e.find(e=>e.size>_);if(r){a(`"${r.name}" exceeds the 50 MB limit.`);return}t(t=>[...t,...e].slice(0,5))},[]);return{pendingFiles:e,setPendingFiles:t,isDragOver:n,attachError:i,setAttachError:a,fileInputRef:o,addFiles:s,clearFiles:(0,D.useCallback)(()=>{t([]),a(null)},[]),removeFile:(0,D.useCallback)(e=>{t(t=>t.filter((t,n)=>n!==e))},[]),onDragOver:(0,D.useCallback)(e=>{e.preventDefault(),r(!0)},[]),onDragLeave:(0,D.useCallback)(()=>{r(!1)},[]),onDrop:(0,D.useCallback)(e=>{e.preventDefault(),r(!1),s([...e.dataTransfer.files])},[s])}}var O=d();function k({accountId:e,remoteJid:n,sessionKey:r}){let[i,a]=(0,D.useState)(``),[o,s]=(0,D.useState)(!1),[c,l]=(0,D.useState)(null),{pendingFiles:u,attachError:d,fileInputRef:f,addFiles:p,removeFile:h,clearFiles:_}=Se(),v=(0,D.useRef)(!1),y=(i.trim().length>0||u.length>0)&&!o,b=(0,D.useCallback)(async()=>{if(!v.current&&!(i.trim().length===0&&u.length===0)){v.current=!0,s(!0),l(null);try{let t=`/api/whatsapp-reader/reply?session_key=${encodeURIComponent(r)}`,o;if(u.length>0){let r=new FormData;r.append(`accountId`,e),r.append(`remoteJid`,n),i.trim()&&r.append(`text`,i);for(let e of u)r.append(`files`,e);o=await fetch(t,{method:`POST`,body:r})}else o=await fetch(t,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({accountId:e,remoteJid:n,text:i})});let s=await o.json().catch(()=>({}));if(!o.ok){l(s.error??`Send failed.`),console.info(`[operator-ui] op=reply-fail remoteJid=${n} error=${s.error??`unknown`}`);return}a(``),_(),console.info(`[operator-ui] op=reply-sent remoteJid=${n} sent=${s.sent??0}`)}catch(e){l(`Could not reach the server. Try again.`),console.info(`[operator-ui] op=reply-fail remoteJid=${n} error=${String(e)}`)}finally{v.current=!1,s(!1)}}},[i,u,e,n,r,_]),x=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),y&&b())},ee=e=>e.startsWith(`image/`)?(0,O.jsx)(he,{size:14}):e===`application/pdf`?(0,O.jsx)(ie,{size:14}):(0,O.jsx)(g,{size:14});return(0,O.jsxs)(`div`,{className:`wa-reply`,children:[c&&(0,O.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:c}),d&&(0,O.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:d}),u.length>0&&(0,O.jsx)(`div`,{className:`wa-reply-attachments`,children:u.map((e,n)=>(0,O.jsxs)(`div`,{className:`wa-reply-chip`,children:[ee(e.type),(0,O.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>h(n),"aria-label":`Remove ${e.name}`,children:(0,O.jsx)(t,{size:12})})]},n))}),(0,O.jsxs)(`div`,{className:`wa-reply-row`,children:[(0,O.jsx)(`input`,{ref:f,type:`file`,multiple:!0,accept:m,style:{display:`none`},onChange:e=>{e.target.files&&p([...e.target.files]),e.target.value=``}}),(0,O.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:()=>f.current?.click(),disabled:o,"aria-label":`Attach files`,children:(0,O.jsx)(te,{size:22})}),(0,O.jsx)(`textarea`,{className:`wa-reply-input`,value:i,rows:1,placeholder:`Type a message`,disabled:o,onChange:e=>a(e.target.value),onKeyDown:x}),(0,O.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void b(),disabled:!y,"aria-label":`Send`,children:(0,O.jsx)(ye,{size:20})})]})]})}function A({accountId:e,remoteJid:t,contactName:n,sessionKey:r,onBack:i}){let a=x(t),o=t.split(`@`)[0],s=a?`Group`:n===`+${o}`?void 0:`+${o}`;return(0,O.jsxs)(`div`,{className:`wa-web`,children:[(0,O.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,O.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,O.jsx)(y,{size:20})}),(0,O.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,O.jsx)(xe,{size:20})}),(0,O.jsxs)(`div`,{className:`wa-web-titles`,children:[(0,O.jsx)(`span`,{className:`wa-web-name`,children:n}),s&&(0,O.jsx)(`span`,{className:`wa-web-subtitle`,children:s})]}),(0,O.jsxs)(`div`,{className:`wa-web-actions`,"aria-hidden":!0,children:[(0,O.jsx)(E,{size:20}),(0,O.jsx)(w,{size:20}),(0,O.jsx)(ue,{size:20}),(0,O.jsx)(v,{size:20})]})]}),(0,O.jsx)(`div`,{className:`wa-web-body`,children:(0,O.jsx)(p,{sessionId:``,projectDir:``,sessionKey:r,forceDeliveredOnly:!0,suppressDirectives:!0,store:{accountId:e,remoteJid:t}})}),a?(0,O.jsx)(`p`,{className:`wa-reply wa-reply-readonly`,children:`Group messages are read-only.`}):(0,O.jsx)(k,{accountId:e,remoteJid:t,sessionKey:r})]})}function Ce(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||C.has(e)&&(t.add(e),n.push(e)));return n}function j(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 we({conversations:e,sessionKey:t,onBack:n}){let[r,i]=(0,D.useState)(null),a=re(e);return r?r.source===`store`&&r.accountId&&r.remoteJid?(0,O.jsx)(A,{accountId:r.accountId,remoteJid:r.remoteJid,contactName:b(r),sessionKey:t,onBack:()=>i(null)},S(r)):(0,O.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,O.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,O.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>i(null),"aria-label":`Back to conversations`,children:[(0,O.jsx)(y,{size:16}),` Back`]}),(0,O.jsx)(`span`,{className:`op-conv-title`,children:b(r)})]}),(0,O.jsx)(p,{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},S(r))]}):(0,O.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,O.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,O.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,O.jsx)(y,{size:16}),` Chat`]}),(0,O.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),a.map(e=>(0,O.jsxs)(`div`,{className:`op-conv-group`,children:[(0,O.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,O.jsx)(le,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{console.info(`[operator-ui] op=reader-open channel=${e.channel} key=${S(e)} readonly=true source=${e.source}`),i(e)},children:[(0,O.jsx)(`span`,{className:`op-conv-name`,children:b(e)}),e.modelGated&&(0,O.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,O.jsx)(T,{size:13})}),(0,O.jsx)(`span`,{className:`op-conv-when`,children:j(e.lastMessageAt)})]},S(e)))]},e.channel))]})}var Te=/\.(png|jpe?g|gif|webp|svg)$/i;function Ee(e){return Te.test(e)}var De=`maxy-data-view`,Oe=95*1024*1024,ke=48*1024*1024;function Ae(){return typeof window>`u`?`list`:window.localStorage.getItem(De)===`grid`?`grid`:`list`}function je(){let[e,t]=(0,D.useState)(null),[r,i]=(0,D.useState)(!1);return(0,D.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]),r?e?(0,O.jsx)(o,{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,O.jsx)(`div`,{className:`data-page data-page-full`,children:(0,O.jsx)(Me,{cacheKey:e})})}):(0,O.jsx)(`div`,{className:`data-page`,children:(0,O.jsxs)(`div`,{className:`data-empty`,children:[(0,O.jsx)(`p`,{children:`You are not signed in.`}),(0,O.jsxs)(`p`,{children:[`Open the `,(0,O.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,O.jsx)(`div`,{className:`data-page`,children:(0,O.jsxs)(`div`,{className:`data-loading`,children:[(0,O.jsx)(n,{size:18,className:`spin`}),` Loading…`]})})}function Me({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=u({initialCacheKey:e,surface:`data`});return(0,O.jsx)(Le,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})}function Ne(){if(typeof window>`u`)return`.`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`.`}function Pe(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 M(e){return new Promise((t,n)=>{let r=[],i=()=>e.readEntries(e=>{e.length===0?t(r):(r.push(...e),i())},n);i()})}function N(e){return new Promise((t,n)=>e.file(t,n))}async function Fe(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 N(r),relpath:e});else if(r.isDirectory){let t=await M(r.createReader());n.push(...await Fe(t,e))}}return n}function Ie(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 P({adminFetch:e,cacheKey:r,sessionRefetchNonce:i}){let[o,c]=(0,D.useState)(``),l=(0,D.useRef)(null),[u,d]=(0,D.useState)(``),[f,p]=(0,D.useState)(null),[m,h]=(0,D.useState)(`hybrid`),[g,_]=(0,D.useState)(!1),[v,y]=(0,D.useState)(null),[b,x]=(0,D.useState)(null),[te,re]=(0,D.useState)(0),[S,le]=(0,D.useState)(!1),[C,he]=(0,D.useState)(()=>Ne()),[w,ye]=(0,D.useState)(null),[T,xe]=(0,D.useState)(()=>Ae()),[E,Se]=(0,D.useState)(null),[k,A]=(0,D.useState)([]),[j,we]=(0,D.useState)(!1),[Te,je]=(0,D.useState)(null),[Me,M]=(0,D.useState)(!1),[N,P]=(0,D.useState)(null),[Le,F]=(0,D.useState)(null),[Be,Ve]=(0,D.useState)(null),[He,Ge]=(0,D.useState)(!1),[Ke,qe]=(0,D.useState)(null),I=(0,D.useRef)(null),[Je,L]=(0,D.useState)(0),[Ye,R]=(0,D.useState)(!1),[Xe,Ze]=(0,D.useState)(``),[z,B]=(0,D.useState)(null),[Qe,$e]=(0,D.useState)(``),[et,V]=(0,D.useState)(null),H=(()=>{let e=C===`.`?[]:C.split(`/`).filter(Boolean);return e.length>=2&&e[0]===`accounts`})(),[tt,nt]=(0,D.useState)(!1),rt=(0,D.useRef)(null),[it,U]=(0,D.useState)(!1),at=(0,D.useRef)(null);(0,D.useEffect)(()=>{let e=o.trim();if(!e){d(``),p(null),y(null);return}le(!1);let t=setTimeout(()=>d(e),300);return()=>clearTimeout(t)},[o]),(0,D.useEffect)(()=>{if(!u){_(!1);return}let t=!1;return _(!0),y(null),e(`/api/admin/graph-search?q=${encodeURIComponent(u)}&labels=FileArtifact&limit=20${S?`&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),h(e.mode??`hybrid`),re(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||y(e instanceof Error?e.message:String(e))}).finally(()=>{t||_(!1)}),()=>{t=!0}},[u,e,i,S]);let ot=(0,D.useMemo)(()=>f?Ce(f):[],[f]),W=b&&ot.includes(b)?b:null,st=(0,D.useMemo)(()=>f?W?f.filter(e=>e.labels.includes(W)):f:null,[f,W]),ct=(0,D.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let n=`/api/admin/files/download?session_key=${encodeURIComponent(r)}&path=${encodeURIComponent(t)}`,i=document.createElement(`a`);i.href=n,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()},[r]);(0,D.useEffect)(()=>{if(!f)return;let e=f.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(`,`)}`)},[f]),(0,D.useEffect)(()=>{let t=!1;return we(!0),je(null),e(`/api/admin/files?path=${encodeURIComponent(C===`.`?``:C)}`).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||(ye(e.entries),A(e.displayPath??[]))}).catch(e=>{t||(ye([]),A([]),je(e instanceof Error?e.message:String(e)))}).finally(()=>{t||we(!1)}),()=>{t=!0}},[e,C,Je,i]),(0,D.useEffect)(()=>{Pe(C)},[C]);let lt=(0,D.useCallback)(()=>{L(e=>e+1)},[]),G=(0,D.useCallback)(e=>{nt(!1),he(e)},[]),ut=(0,D.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}`),c(``),y(null),x(null),G(r)},[G]),dt=(0,D.useCallback)(()=>{if(C===`.`||C===``)return;let e=C.split(`/`).filter(Boolean);e.pop(),he(e.length===0?`.`:e.join(`/`))},[C]),ft=(0,D.useCallback)(e=>{ae(r,C===`.`?e.name:`${C}/${e.name}`)},[C,r]),[K,pt]=(0,D.useState)(!1),[q,mt]=(0,D.useState)(new Set),ht=(0,D.useRef)(null),J=(0,D.useRef)(!1),Y=typeof navigator<`u`&&typeof navigator.share==`function`&&typeof navigator.canShare==`function`,gt=(0,D.useCallback)(e=>{pt(!0),mt(new Set([e])),console.info(`[data-ui] op=select-enter count=1`)},[]),X=(0,D.useCallback)(e=>{pt(!1),mt(new Set),console.info(`[data-ui] op=select-exit reason=${e}`)},[]),Z=(0,D.useCallback)(e=>{mt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),_t=(0,D.useCallback)(e=>{J.current=!1,ht.current=setTimeout(()=>{J.current=!0,gt(e)},500)},[gt]),Q=(0,D.useCallback)(()=>{ht.current&&=(clearTimeout(ht.current),null)},[]),vt=(0,D.useCallback)(e=>{if(J.current){J.current=!1;return}if(K){Z(e.name);return}ft(e)},[K,Z,ft]),yt=(0,D.useCallback)(e=>{xe(e),typeof window<`u`&&window.localStorage.setItem(De,e),console.info(`[data] op=view-mode mode=${e}`)},[]),bt=(0,D.useCallback)(e=>{if(J.current){J.current=!1;return}if(K){Z(e.name);return}Se({src:ce(r,C===`.`?e.name:`${C}/${e.name}`),alt:e.displayName??e.name})},[K,Z,C,r]),xt=(0,D.useCallback)(()=>(w??[]).filter(e=>e.kind===`file`&&q.has(e.name)),[w,q]),St=(0,D.useCallback)(()=>(w??[]).filter(e=>(e.kind===`file`||e.kind===`directory`)&&q.has(e.name)),[w,q]),Ct=(0,D.useCallback)(()=>{let e=St(),t=e.some(e=>e.kind===`directory`);e.length===1&&!t?ft(e[0]):e.length>=1&&se(r,e.map(e=>C===`.`?e.name:`${C}/${e.name}`)),X(`action`)},[St,ft,C,r,X]),wt=(0,D.useCallback)(async()=>{let t=xt(),n=t.filter(e=>!e.protected),r=t.length-n.length;qe(r>0?`${r} protected file(s) kept`:null);for(let t of n){let n=C===`.`?t.name:`${C}/${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){qe(e instanceof Error?e.message:String(e))}}L(e=>e+1),X(`action`)},[xt,C,e,X]),Tt=(0,D.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=C===`.`?e.name:`${C}/${e.name}`,n=`/api/admin/files/download?session_key=${encodeURIComponent(r)}&path=${encodeURIComponent(t)}`,i=await(await fetch(n)).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,C,r]),Et=(0,D.useCallback)(()=>{I.current?.click()},[]),Dt=(0,D.useCallback)((e,t={})=>{let n=(n,i,a)=>{let o=new URLSearchParams({session_key:r,path:C===`.`?``:C,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 r=new XMLHttpRequest;r.open(`POST`,`/api/admin/files/upload?${o.toString()}`),r.setRequestHeader(`Content-Type`,e.type||`application/octet-stream`),a&&(r.upload.onprogress=e=>{e.lengthComputable&&a(e.loaded)}),r.onload=()=>{let e={};try{e=JSON.parse(r.responseText)}catch{}t({status:r.status,data:e})},r.onerror=()=>t({status:0,data:{}}),r.onabort=()=>t({status:0,data:{error:`aborted`}}),r.send(n)})};if(e.size<=Oe)return n(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/ke);return(async()=>{let r={status:0,data:{}};for(let o=0;o<a;o++){let s=o*ke;if(r=await n(e.slice(s,Math.min(s+ke,e.size)),{uploadId:i,seq:String(o),total:String(a)},n=>t.onProgress?.(s+n,e.size)),!(r.status>=200&&r.status<300))return r}return r})()},[r,C]),Ot=(0,D.useCallback)(async e=>{F(null),M(!0),P({loaded:0,total:e.size});try{let{status:t,data:n}=await Dt(e,{onProgress:(e,t)=>P({loaded:e,total:t})});t>=200&&t<300&&n.path?(he(n.path.split(`/`).slice(0,-1).join(`/`)||`.`),L(e=>e+1)):F(t===0?`Network error during upload — the connection failed before the server responded.`:n.error??`Upload failed (HTTP ${t}).`)}finally{M(!1),P(null),I.current&&(I.current.value=``)}},[Dt]),kt=(0,D.useCallback)(e=>{H&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),Ge(!0))},[H]),At=(0,D.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||Ge(!1)},[]),jt=(0,D.useCallback)(async e=>{e.preventDefault(),Ge(!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(!H){console.info(`[data-ui] op=drop-rejected token=${t} reason=no-write`),F(`Open a folder inside your account to upload`);return}let r=n.map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e);M(!0),F(null),Ve(null);let i=performance.now();try{let e=await Fe(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}`),P({loaded:0,total:r.size});let{status:a,data:c}=await Dt(r,{relpath:i,token:t,onProgress:(e,t)=>P({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`:Ie(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}`),Ve(`Uploaded ${o}, skipped ${s.length}${s.length?`: ${s.join(`, `)}`:``}`),L(e=>e+1)}catch(e){F(e instanceof Error?e.message:String(e))}finally{M(!1),P(null)}},[H,Dt]),Mt=(0,D.useCallback)(async()=>{let t=Xe.trim();if(t){V(null);try{let n=await e(`/api/admin/files/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:C===`.`?``:C,name:t})}),r=await n.json().catch(()=>({error:`HTTP ${n.status}`}));if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);R(!1),Ze(``),L(e=>e+1)}catch(e){V(e instanceof Error?e.message:String(e))}}},[e,Xe,C]),Nt=(0,D.useCallback)(async()=>{if(!z)return;let t=Qe.trim();if(!t)return;V(null);let n=C===`.`?z:`${C}/${z}`;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}`);B(null),$e(``),X(`action`),L(e=>e+1)}catch(e){V(e instanceof Error?e.message:String(e))}},[e,Qe,z,C,X]);(0,D.useEffect)(()=>{if(!tt)return;let e=e=>{rt.current&&!rt.current.contains(e.target)&&nt(!1)},t=e=>{e.key===`Escape`&&nt(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[tt]),(0,D.useEffect)(()=>{if(!it)return;let e=e=>{at.current&&!at.current.contains(e.target)&&U(!1)},t=e=>{e.key===`Escape`&&U(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[it]);let $=(0,D.useCallback)(e=>k.slice(0,e+1).map(e=>e.name).join(`/`),[k]),Pt=k.length>=2,Ft=Pt?[{name:`.`,label:`data`},...k.slice(0,k.length-2).map((e,t)=>({name:$(t),label:e.displayName??e.name}))]:[];return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`data-toolbar`,children:[K?(0,O.jsxs)(`button`,{type:`button`,className:`data-select-cancel`,onClick:()=>X(`cancel`),"aria-label":`Cancel selection`,children:[(0,O.jsx)(t,{size:14}),` Cancel`]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`data-search-input`,children:[o===``&&(0,O.jsx)(ue,{size:14}),(0,O.jsx)(`input`,{ref:l,type:`text`,value:o,onChange:e=>c(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),g&&(0,O.jsx)(n,{size:14,className:`spin`}),o!==``&&(0,O.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{c(``),l.current?.focus()},title:`Clear search`,"aria-label":`Clear search`,children:(0,O.jsx)(t,{size:14})})]}),(0,O.jsxs)(`div`,{className:`data-toolbar-actions`,ref:at,children:[(0,O.jsx)(`button`,{type:`button`,className:`data-action-overflow`,onClick:()=>U(e=>!e),"aria-haspopup":`menu`,"aria-expanded":it,"aria-label":`File actions`,title:`File actions`,children:(0,O.jsx)(fe,{size:16})}),(0,O.jsxs)(`div`,{className:`data-action-group`,role:`group`,"aria-label":`File actions`,"data-open":it?`true`:void 0,children:[(0,O.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{lt(),U(!1)},disabled:j,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[j?(0,O.jsx)(n,{size:16,className:`spin`}):(0,O.jsx)(ee,{size:16}),(0,O.jsx)(`span`,{className:`data-action-label`,children:`Refresh`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Et(),U(!1)},disabled:Me||!H,title:H?`Upload a file`:`Open a folder inside your account to upload`,"aria-label":`Upload a file`,children:[Me?N&&N.total>0?(0,O.jsxs)(`span`,{className:`data-upload-pct`,children:[Math.round(N.loaded/N.total*100),`%`]}):(0,O.jsx)(n,{size:16,className:`spin`}):(0,O.jsx)(be,{size:16}),(0,O.jsx)(`span`,{className:`data-action-label`,children:`Upload`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{R(e=>!e),Ze(``),V(null),U(!1)},disabled:Me||!H,title:H?`New folder`:`Open a folder inside your account to create one`,"aria-label":`New folder`,children:[(0,O.jsx)(pe,{size:16}),(0,O.jsx)(`span`,{className:`data-action-label`,children:`New folder`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{yt(T===`grid`?`list`:`grid`),U(!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,O.jsx)(_e,{size:16}):(0,O.jsx)(ge,{size:16}),(0,O.jsx)(`span`,{className:`data-action-label`,children:T===`grid`?`List view`:`Grid view`})]})]})]})]}),(0,O.jsxs)(`div`,{className:`data-breadcrumbs`,children:[C!==`.`&&(0,O.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,O.jsx)(de,{size:14})}),Pt?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`span`,{className:`data-crumb-wrap`,ref:rt,children:[(0,O.jsx)(`button`,{type:`button`,className:`data-crumb data-crumb-ellipsis`,onClick:()=>nt(e=>!e),"aria-haspopup":`menu`,"aria-expanded":tt,"aria-label":`Show parent folders`,title:`Show parent folders`,children:`…`}),tt&&(0,O.jsx)(`div`,{className:`data-crumb-menu`,role:`menu`,children:Ft.map(e=>(0,O.jsx)(`button`,{type:`button`,role:`menuitem`,className:`data-crumb-menu-item`,onClick:()=>G(e.name),title:e.label,children:e.label},e.name))})]}),[k.length-2,k.length-1].map(e=>{let t=k[e];return(0,O.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,O.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,O.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>G($(e)),title:t.name,children:t.displayName??t.name})]},$(e))})]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>G(`.`),children:`data`}),k.map((e,t)=>(0,O.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,O.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,O.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>G($(t)),title:e.name,children:e.displayName??e.name})]},$(t)))]})]}),Ye&&(0,O.jsxs)(`div`,{className:`data-inline-form`,children:[(0,O.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`Folder name`,value:Xe,autoFocus:!0,onChange:e=>Ze(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Mt(),e.key===`Escape`&&R(!1)}}),(0,O.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Mt,children:`Create`}),(0,O.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>R(!1),children:`Cancel`})]}),z&&(0,O.jsxs)(`div`,{className:`data-inline-form`,children:[(0,O.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`New name`,value:Qe,autoFocus:!0,onChange:e=>$e(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Nt(),e.key===`Escape`&&B(null)}}),(0,O.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Nt,children:`Rename`}),(0,O.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>B(null),children:`Cancel`})]}),et&&(0,O.jsx)(`div`,{className:`data-error`,children:et}),(0,O.jsx)(`input`,{type:`file`,ref:I,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Ot(t)}})]}),(0,O.jsxs)(`div`,{className:`data-body`,"data-drag-active":He?`true`:void 0,onDragEnter:kt,onDragOver:kt,onDragLeave:At,onDrop:jt,children:[(v!==null||f!==null)&&(0,O.jsxs)(`section`,{className:`data-panel`,children:[v&&(0,O.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,v]}),ot.length>0&&(0,O.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:ot.map(e=>{let t=e===W;return(0,O.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>x(t?null:e),children:ze([e])??e},e)})}),f&&!g&&(0,O.jsxs)(`div`,{className:`data-results-meta`,children:[st.length,` of `,f.length,` result`,f.length===1?``:`s`]}),f&&!g&&!W&&te>0&&!S&&(0,O.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>le(!0),children:[te,` low-confidence result`,te===1?``:`s`,` hidden — show all`]}),f&&!g&&!W&&S&&(0,O.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>le(!1),children:`Showing all results — hide low-confidence`}),f&&f.length===0&&!g&&(0,O.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),st&&st.length>0&&(0,O.jsx)(`ul`,{className:`data-results`,children:st.map(e=>(0,O.jsx)(Re,{hit:e,mode:m,onDownload:ct,onLocate:ut},e.nodeId))})]}),(0,O.jsxs)(`section`,{className:`data-panel`,children:[N&&(0,O.jsxs)(`div`,{className:`data-upload-progress`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":N.total>0?Math.round(N.loaded/N.total*100):void 0,children:[(0,O.jsx)(`div`,{className:`data-upload-progress-track`,children:(0,O.jsx)(`div`,{className:`data-upload-progress-fill`,style:{width:`${N.total>0?Math.round(N.loaded/N.total*100):0}%`}})}),(0,O.jsxs)(`span`,{className:`data-upload-progress-label`,children:[`Uploading… `,N.total>0?`${Math.round(N.loaded/N.total*100)}%`:``]})]}),Le&&(0,O.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,Le]}),Be&&(0,O.jsx)(`div`,{className:`data-status`,children:Be}),Ke&&(0,O.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,Ke]}),Te&&(0,O.jsx)(`div`,{className:`data-error`,children:Te}),j&&(0,O.jsxs)(`div`,{className:`data-loading`,children:[(0,O.jsx)(n,{size:14,className:`spin`}),` Loading…`]}),!K&&!j&&w&&w.length>0&&(0,O.jsxs)(`div`,{className:`data-select-hint`,children:[(0,O.jsx)(ve,{size:13}),(0,O.jsx)(`span`,{children:`Press and hold a file to select, rename, or delete it.`})]}),!j&&w&&w.length===0&&!Te&&(0,O.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!j&&w&&w.length>0&&T===`grid`&&(0,O.jsx)(`ul`,{className:`data-grid`,children:w.map(e=>{let t=e.displayName??e.name,n=K&&q.has(e.name);if(e.kind===`directory`)return(0,O.jsx)(`li`,{className:`data-grid-cell`,"data-selected":n?`true`:void 0,children:(0,O.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(C===`.`?e.name:`${C}/${e.name}`)},children:[K&&(0,O.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,O.jsx)(me,{size:28,className:`data-grid-glyph`}),(0,O.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:t})]})},e.name);if(e.kind===`file`){let i=Ee(e.name),a=C===`.`?e.name:`${C}/${e.name}`;return(0,O.jsx)(`li`,{className:`data-grid-cell`,"data-selected":n?`true`:void 0,children:(0,O.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,O.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),i?(0,O.jsx)(`img`,{className:`data-grid-thumb`,src:ce(r,a),alt:t,loading:`lazy`,onError:()=>console.warn(`[data] op=thumb-error path=${a}`)}):(0,O.jsx)(ie,{size:28,className:`data-grid-glyph`}),(0,O.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:t}),!i&&(0,O.jsx)(`span`,{className:`data-grid-sub`,children:Ue(e.sizeBytes)})]})},e.name)}return(0,O.jsx)(`li`,{className:`data-grid-cell`,children:(0,O.jsxs)(`div`,{className:`data-grid-tile data-entry-disabled`,children:[(0,O.jsx)(ie,{size:28,className:`data-grid-glyph`}),(0,O.jsx)(`span`,{className:`data-grid-label`,children:t}),(0,O.jsx)(`span`,{className:`data-grid-sub`,children:`special`})]})},e.name)})}),!j&&w&&w.length>0&&T===`list`&&(0,O.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,O.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,O.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(C===`.`?e.name:`${C}/${e.name}`)},children:[K&&(0,O.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,O.jsx)(me,{size:14}),(0,O.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,O.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,O.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,O.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,O.jsxs)(`span`,{className:`data-entry-text`,children:[(0,O.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,O.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${We(e.modifiedAt)}`,children:[Ue(e.sizeBytes),` · `,We(e.modifiedAt)]})]})]})},e.name)}return(0,O.jsx)(`li`,{className:`data-entry`,children:(0,O.jsx)(`div`,{className:`data-entry-btn data-entry-file data-entry-disabled`,children:(0,O.jsxs)(`span`,{className:`data-entry-text`,children:[(0,O.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,O.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})})},e.name)})})]})]}),K&&(0,O.jsx)(`div`,{className:`data-select-bar`,role:`toolbar`,"aria-label":`Selection actions`,children:(0,O.jsxs)(`div`,{className:`data-select-bar-inner`,children:[(0,O.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,O.jsx)(s,{size:16}),` Share`]}),(0,O.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Ct,disabled:q.size===0,children:[(0,O.jsx)(ne,{size:16}),` Download`]}),(0,O.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:()=>{let e=[...q][0];e&&(B(e),$e(e))},disabled:q.size!==1,children:[(0,O.jsx)(oe,{size:16}),` Rename`]}),(0,O.jsxs)(`button`,{type:`button`,className:`data-select-action data-select-delete`,onClick:wt,disabled:q.size===0,children:[(0,O.jsx)(a,{size:16}),` Delete`]})]})}),E&&(0,O.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":E.alt,onClick:()=>Se(null),children:(0,O.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:E.src,alt:E.alt})})]})}function Le({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){(0,D.useEffect)(()=>{console.info(`[data-ui] op=mount header=operator home=absent`)},[]);let r=(0,D.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),a=(0,D.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),[o,s]=(0,D.useState)([]),[l,u]=(0,D.useState)(`files`),{subAccounts:d,activeAccountId:f,switching:p,switchAccount:m}=c(t);return(0,D.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||s(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[t]),(0,O.jsxs)(`main`,{className:`data-main`,children:[(0,O.jsx)(i,{variant:`operator`,onNavigate:a,onOpenConversations:o.length>0?()=>u(`conversations`):void 0,onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:r,onDisconnect:async()=>!0,disconnecting:!1,subAccounts:d,activeAccountId:f,switchingAccount:p,onSwitchAccount:m}),l===`conversations`?(0,O.jsx)(we,{conversations:o,sessionKey:t,onBack:()=>u(`files`)}):(0,O.jsx)(P,{adminFetch:e,cacheKey:t,sessionRefetchNonce:n})]})}function F({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=u({initialCacheKey:e,surface:`data`});return(0,O.jsx)(`div`,{className:`data-page`,children:(0,O.jsx)(`main`,{className:`data-main`,children:(0,O.jsx)(P,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})})})}function Re({hit:e,mode:t,onDownload:n,onLocate:r}){let i=Be(e.properties),a=Ve(e.properties),o=ze(e.labels),s=He(e.properties),[c,l]=(0,D.useState)(!1),u=a&&a.length>280,d=c||!u?a:a?.slice(0,280)+`…`,f=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`,p=e.properties.relativePath,m=typeof p==`string`&&p.length>0,h=m?p.lastIndexOf(`/`):-1,g=m?h===-1?`data`:p.slice(0,h):null;return(0,O.jsxs)(`li`,{className:`data-result`,children:[(0,O.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,O.jsx)(`div`,{className:`data-result-header`,children:(0,O.jsx)(`span`,{className:`data-result-labels`,children:o})}),i&&(0,O.jsx)(`div`,{className:`data-result-title`,children:i}),a&&(0,O.jsx)(`pre`,{className:`data-result-body`,children:d}),(0,O.jsxs)(`div`,{className:`data-result-scores`,children:[s&&(0,O.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,We(s),` · `]}),f]})]}),m&&(0,O.jsxs)(`button`,{type:`button`,className:`data-result-locate`,onClick:()=>r(e),title:`Locate in ${g}`,"aria-label":`Locate in ${g}`,children:[(0,O.jsx)(me,{size:12}),g]}),u&&(0,O.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>l(e=>!e),children:c?`Show less`:`Show more`})]})}function ze(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 Be(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 Ve(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 He(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 Ue(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 We(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{F as n,A as r,je as t};
1
+ import{o as e}from"./chunk-Ck5AOu5v.js";import{a as t,l as n,m as r,n as i,o as a,r as o,s,t as c,w as l,x as u,y as d}from"./useSubAccountSwitcher-DyjTbzQR.js";import{S as f,a as p,b as m,t as h,v as g,x as _,y as v}from"./audio-attachment-mime-Cx5d3Jls.js";import{t as y}from"./chevron-left-CLPxfjDV.js";import{a as b,c as x,d as ee,f as te,h as ne,i as re,m as ie,n as ae,p as oe,r as se,s as S,t as ce,u as le}from"./file-download-B2B2DTar.js";import{i as ue,t as C}from"./graph-labels-DxqDdO7G.js";var de=r(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),fe=r(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),pe=r(`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=r(`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=r(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),ge=r(`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`}]]),_e=r(`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`}]]),ve=r(`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`}]]),w=r(`phone`,[[`path`,{d:`M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384`,key:`9njp5v`}]]),ye=r(`send-horizontal`,[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]]),T=r(`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`}]]),be=r(`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`}]]),xe=r(`user`,[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]),E=r(`video`,[[`path`,{d:`m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5`,key:`ftymec`}],[`rect`,{x:`2`,y:`6`,width:`14`,height:`12`,rx:`2`,key:`158x01`}]]),D=e(l(),1);function Se(){let[e,t]=(0,D.useState)([]),[n,r]=(0,D.useState)(!1),[i,a]=(0,D.useState)(null),o=(0,D.useRef)(null),s=(0,D.useCallback)(e=>{a(null);let n=e.find(e=>!h(e.type,f));if(n){a(`Unsupported file type: "${n.type}". Supported: images, PDF, plain text, markdown, CSV, calendar, zip, voice notes.`);return}let r=e.find(e=>e.size>_);if(r){a(`"${r.name}" exceeds the 50 MB limit.`);return}t(t=>[...t,...e].slice(0,5))},[]);return{pendingFiles:e,setPendingFiles:t,isDragOver:n,attachError:i,setAttachError:a,fileInputRef:o,addFiles:s,clearFiles:(0,D.useCallback)(()=>{t([]),a(null)},[]),removeFile:(0,D.useCallback)(e=>{t(t=>t.filter((t,n)=>n!==e))},[]),onDragOver:(0,D.useCallback)(e=>{e.preventDefault(),r(!0)},[]),onDragLeave:(0,D.useCallback)(()=>{r(!1)},[]),onDrop:(0,D.useCallback)(e=>{e.preventDefault(),r(!1),s([...e.dataTransfer.files])},[s])}}var O=d();function k({accountId:e,remoteJid:n,sessionKey:r}){let[i,a]=(0,D.useState)(``),[o,s]=(0,D.useState)(!1),[c,l]=(0,D.useState)(null),{pendingFiles:u,attachError:d,fileInputRef:f,addFiles:p,removeFile:h,clearFiles:_}=Se(),v=(0,D.useRef)(!1),y=(i.trim().length>0||u.length>0)&&!o,b=(0,D.useCallback)(async()=>{if(!v.current&&!(i.trim().length===0&&u.length===0)){v.current=!0,s(!0),l(null);try{let t=`/api/whatsapp-reader/reply?session_key=${encodeURIComponent(r)}`,o;if(u.length>0){let r=new FormData;r.append(`accountId`,e),r.append(`remoteJid`,n),i.trim()&&r.append(`text`,i);for(let e of u)r.append(`files`,e);o=await fetch(t,{method:`POST`,body:r})}else o=await fetch(t,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({accountId:e,remoteJid:n,text:i})});let s=await o.json().catch(()=>({}));if(!o.ok){l(s.error??`Send failed.`),console.info(`[operator-ui] op=reply-fail remoteJid=${n} error=${s.error??`unknown`}`);return}a(``),_(),console.info(`[operator-ui] op=reply-sent remoteJid=${n} sent=${s.sent??0}`)}catch(e){l(`Could not reach the server. Try again.`),console.info(`[operator-ui] op=reply-fail remoteJid=${n} error=${String(e)}`)}finally{v.current=!1,s(!1)}}},[i,u,e,n,r,_]),x=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),y&&b())},ee=e=>e.startsWith(`image/`)?(0,O.jsx)(he,{size:14}):e===`application/pdf`?(0,O.jsx)(ie,{size:14}):(0,O.jsx)(g,{size:14});return(0,O.jsxs)(`div`,{className:`wa-reply`,children:[c&&(0,O.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:c}),d&&(0,O.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:d}),u.length>0&&(0,O.jsx)(`div`,{className:`wa-reply-attachments`,children:u.map((e,n)=>(0,O.jsxs)(`div`,{className:`wa-reply-chip`,children:[ee(e.type),(0,O.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,O.jsx)(`button`,{type:`button`,onClick:()=>h(n),"aria-label":`Remove ${e.name}`,children:(0,O.jsx)(t,{size:12})})]},n))}),(0,O.jsxs)(`div`,{className:`wa-reply-row`,children:[(0,O.jsx)(`input`,{ref:f,type:`file`,multiple:!0,accept:m,style:{display:`none`},onChange:e=>{e.target.files&&p([...e.target.files]),e.target.value=``}}),(0,O.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:()=>f.current?.click(),disabled:o,"aria-label":`Attach files`,children:(0,O.jsx)(te,{size:22})}),(0,O.jsx)(`textarea`,{className:`wa-reply-input`,value:i,rows:1,placeholder:`Type a message`,disabled:o,onChange:e=>a(e.target.value),onKeyDown:x}),(0,O.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void b(),disabled:!y,"aria-label":`Send`,children:(0,O.jsx)(ye,{size:20})})]})]})}function A({accountId:e,remoteJid:t,contactName:n,sessionKey:r,onBack:i}){let a=x(t),o=t.split(`@`)[0],s=a?`Group`:n===`+${o}`?void 0:`+${o}`;return(0,O.jsxs)(`div`,{className:`wa-web`,children:[(0,O.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,O.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,O.jsx)(y,{size:20})}),(0,O.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,O.jsx)(xe,{size:20})}),(0,O.jsxs)(`div`,{className:`wa-web-titles`,children:[(0,O.jsx)(`span`,{className:`wa-web-name`,children:n}),s&&(0,O.jsx)(`span`,{className:`wa-web-subtitle`,children:s})]}),(0,O.jsxs)(`div`,{className:`wa-web-actions`,"aria-hidden":!0,children:[(0,O.jsx)(E,{size:20}),(0,O.jsx)(w,{size:20}),(0,O.jsx)(ue,{size:20}),(0,O.jsx)(v,{size:20})]})]}),(0,O.jsx)(`div`,{className:`wa-web-body`,children:(0,O.jsx)(p,{sessionId:``,projectDir:``,sessionKey:r,forceDeliveredOnly:!0,suppressDirectives:!0,store:{accountId:e,remoteJid:t}})}),a?(0,O.jsx)(`p`,{className:`wa-reply wa-reply-readonly`,children:`Group messages are read-only.`}):(0,O.jsx)(k,{accountId:e,remoteJid:t,sessionKey:r})]})}function Ce(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||C.has(e)&&(t.add(e),n.push(e)));return n}function j(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 we({conversations:e,sessionKey:t,onBack:n}){let[r,i]=(0,D.useState)(null),a=re(e);return r?r.source===`store`&&r.accountId&&r.remoteJid?(0,O.jsx)(A,{accountId:r.accountId,remoteJid:r.remoteJid,contactName:b(r),sessionKey:t,onBack:()=>i(null)},S(r)):(0,O.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,O.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,O.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>i(null),"aria-label":`Back to conversations`,children:[(0,O.jsx)(y,{size:16}),` Back`]}),(0,O.jsx)(`span`,{className:`op-conv-title`,children:b(r)})]}),(0,O.jsx)(p,{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},S(r))]}):(0,O.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,O.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,O.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,O.jsx)(y,{size:16}),` Chat`]}),(0,O.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),a.map(e=>(0,O.jsxs)(`div`,{className:`op-conv-group`,children:[(0,O.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,O.jsx)(le,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{console.info(`[operator-ui] op=reader-open channel=${e.channel} key=${S(e)} readonly=true source=${e.source}`),i(e)},children:[(0,O.jsx)(`span`,{className:`op-conv-name`,children:b(e)}),e.modelGated&&(0,O.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,O.jsx)(T,{size:13})}),(0,O.jsx)(`span`,{className:`op-conv-when`,children:j(e.lastMessageAt)})]},S(e)))]},e.channel))]})}var Te=/\.(png|jpe?g|gif|webp|svg)$/i;function Ee(e){return Te.test(e)}var De=`maxy-data-view`,Oe=95*1024*1024,ke=48*1024*1024;function Ae(){return typeof window>`u`?`list`:window.localStorage.getItem(De)===`grid`?`grid`:`list`}function je(){let[e,t]=(0,D.useState)(null),[r,i]=(0,D.useState)(!1);return(0,D.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]),r?e?(0,O.jsx)(o,{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,O.jsx)(`div`,{className:`data-page data-page-full`,children:(0,O.jsx)(Me,{cacheKey:e})})}):(0,O.jsx)(`div`,{className:`data-page`,children:(0,O.jsxs)(`div`,{className:`data-empty`,children:[(0,O.jsx)(`p`,{children:`You are not signed in.`}),(0,O.jsxs)(`p`,{children:[`Open the `,(0,O.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,O.jsx)(`div`,{className:`data-page`,children:(0,O.jsxs)(`div`,{className:`data-loading`,children:[(0,O.jsx)(n,{size:18,className:`spin`}),` Loading…`]})})}function Me({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=u({initialCacheKey:e,surface:`data`});return(0,O.jsx)(Le,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})}function Ne(){if(typeof window>`u`)return`.`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`.`}function Pe(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 M(e){return new Promise((t,n)=>{let r=[],i=()=>e.readEntries(e=>{e.length===0?t(r):(r.push(...e),i())},n);i()})}function N(e){return new Promise((t,n)=>e.file(t,n))}async function Fe(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 N(r),relpath:e});else if(r.isDirectory){let t=await M(r.createReader());n.push(...await Fe(t,e))}}return n}function Ie(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 P({adminFetch:e,cacheKey:r,sessionRefetchNonce:i}){let[o,c]=(0,D.useState)(``),l=(0,D.useRef)(null),[u,d]=(0,D.useState)(``),[f,p]=(0,D.useState)(null),[m,h]=(0,D.useState)(`hybrid`),[g,_]=(0,D.useState)(!1),[v,y]=(0,D.useState)(null),[b,x]=(0,D.useState)(null),[te,re]=(0,D.useState)(0),[S,le]=(0,D.useState)(!1),[C,he]=(0,D.useState)(()=>Ne()),[w,ye]=(0,D.useState)(null),[T,xe]=(0,D.useState)(()=>Ae()),[E,Se]=(0,D.useState)(null),[k,A]=(0,D.useState)([]),[j,we]=(0,D.useState)(!1),[Te,je]=(0,D.useState)(null),[Me,M]=(0,D.useState)(!1),[N,P]=(0,D.useState)(null),[Le,F]=(0,D.useState)(null),[Be,Ve]=(0,D.useState)(null),[He,Ge]=(0,D.useState)(!1),[Ke,qe]=(0,D.useState)(null),I=(0,D.useRef)(null),[Je,L]=(0,D.useState)(0),[Ye,R]=(0,D.useState)(!1),[Xe,Ze]=(0,D.useState)(``),[z,B]=(0,D.useState)(null),[Qe,$e]=(0,D.useState)(``),[et,V]=(0,D.useState)(null),H=(()=>{let e=C===`.`?[]:C.split(`/`).filter(Boolean);return e.length>=2&&e[0]===`accounts`})(),[tt,nt]=(0,D.useState)(!1),rt=(0,D.useRef)(null),[it,U]=(0,D.useState)(!1),at=(0,D.useRef)(null);(0,D.useEffect)(()=>{let e=o.trim();if(!e){d(``),p(null),y(null);return}le(!1);let t=setTimeout(()=>d(e),300);return()=>clearTimeout(t)},[o]),(0,D.useEffect)(()=>{if(!u){_(!1);return}let t=!1;return _(!0),y(null),e(`/api/admin/graph-search?q=${encodeURIComponent(u)}&labels=FileArtifact&limit=20${S?`&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),h(e.mode??`hybrid`),re(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||y(e instanceof Error?e.message:String(e))}).finally(()=>{t||_(!1)}),()=>{t=!0}},[u,e,i,S]);let ot=(0,D.useMemo)(()=>f?Ce(f):[],[f]),W=b&&ot.includes(b)?b:null,st=(0,D.useMemo)(()=>f?W?f.filter(e=>e.labels.includes(W)):f:null,[f,W]),ct=(0,D.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let n=`/api/admin/files/download?session_key=${encodeURIComponent(r)}&path=${encodeURIComponent(t)}`,i=document.createElement(`a`);i.href=n,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()},[r]);(0,D.useEffect)(()=>{if(!f)return;let e=f.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(`,`)}`)},[f]),(0,D.useEffect)(()=>{let t=!1;return we(!0),je(null),e(`/api/admin/files?path=${encodeURIComponent(C===`.`?``:C)}`).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||(ye(e.entries),A(e.displayPath??[]))}).catch(e=>{t||(ye([]),A([]),je(e instanceof Error?e.message:String(e)))}).finally(()=>{t||we(!1)}),()=>{t=!0}},[e,C,Je,i]),(0,D.useEffect)(()=>{Pe(C)},[C]);let lt=(0,D.useCallback)(()=>{L(e=>e+1)},[]),G=(0,D.useCallback)(e=>{nt(!1),he(e)},[]),ut=(0,D.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}`),c(``),y(null),x(null),G(r)},[G]),dt=(0,D.useCallback)(()=>{if(C===`.`||C===``)return;let e=C.split(`/`).filter(Boolean);e.pop(),he(e.length===0?`.`:e.join(`/`))},[C]),ft=(0,D.useCallback)(e=>{ae(r,C===`.`?e.name:`${C}/${e.name}`)},[C,r]),[K,pt]=(0,D.useState)(!1),[q,mt]=(0,D.useState)(new Set),ht=(0,D.useRef)(null),J=(0,D.useRef)(!1),Y=typeof navigator<`u`&&typeof navigator.share==`function`&&typeof navigator.canShare==`function`,gt=(0,D.useCallback)(e=>{pt(!0),mt(new Set([e])),console.info(`[data-ui] op=select-enter count=1`)},[]),X=(0,D.useCallback)(e=>{pt(!1),mt(new Set),console.info(`[data-ui] op=select-exit reason=${e}`)},[]),Z=(0,D.useCallback)(e=>{mt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),_t=(0,D.useCallback)(e=>{J.current=!1,ht.current=setTimeout(()=>{J.current=!0,gt(e)},500)},[gt]),Q=(0,D.useCallback)(()=>{ht.current&&=(clearTimeout(ht.current),null)},[]),vt=(0,D.useCallback)(e=>{if(J.current){J.current=!1;return}if(K){Z(e.name);return}ft(e)},[K,Z,ft]),yt=(0,D.useCallback)(e=>{xe(e),typeof window<`u`&&window.localStorage.setItem(De,e),console.info(`[data] op=view-mode mode=${e}`)},[]),bt=(0,D.useCallback)(e=>{if(J.current){J.current=!1;return}if(K){Z(e.name);return}Se({src:ce(r,C===`.`?e.name:`${C}/${e.name}`),alt:e.displayName??e.name})},[K,Z,C,r]),xt=(0,D.useCallback)(()=>(w??[]).filter(e=>e.kind===`file`&&q.has(e.name)),[w,q]),St=(0,D.useCallback)(()=>(w??[]).filter(e=>(e.kind===`file`||e.kind===`directory`)&&q.has(e.name)),[w,q]),Ct=(0,D.useCallback)(()=>{let e=St(),t=e.some(e=>e.kind===`directory`);e.length===1&&!t?ft(e[0]):e.length>=1&&se(r,e.map(e=>C===`.`?e.name:`${C}/${e.name}`)),X(`action`)},[St,ft,C,r,X]),wt=(0,D.useCallback)(async()=>{let t=xt(),n=t.filter(e=>!e.protected),r=t.length-n.length;qe(r>0?`${r} protected file(s) kept`:null);for(let t of n){let n=C===`.`?t.name:`${C}/${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){qe(e instanceof Error?e.message:String(e))}}L(e=>e+1),X(`action`)},[xt,C,e,X]),Tt=(0,D.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=C===`.`?e.name:`${C}/${e.name}`,n=`/api/admin/files/download?session_key=${encodeURIComponent(r)}&path=${encodeURIComponent(t)}`,i=await(await fetch(n)).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,C,r]),Et=(0,D.useCallback)(()=>{I.current?.click()},[]),Dt=(0,D.useCallback)((e,t={})=>{let n=(n,i,a)=>{let o=new URLSearchParams({session_key:r,path:C===`.`?``:C,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 r=new XMLHttpRequest;r.open(`POST`,`/api/admin/files/upload?${o.toString()}`),r.setRequestHeader(`Content-Type`,e.type||`application/octet-stream`),a&&(r.upload.onprogress=e=>{e.lengthComputable&&a(e.loaded)}),r.onload=()=>{let e={};try{e=JSON.parse(r.responseText)}catch{}t({status:r.status,data:e})},r.onerror=()=>t({status:0,data:{}}),r.onabort=()=>t({status:0,data:{error:`aborted`}}),r.send(n)})};if(e.size<=Oe)return n(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/ke);return(async()=>{let r={status:0,data:{}};for(let o=0;o<a;o++){let s=o*ke;if(r=await n(e.slice(s,Math.min(s+ke,e.size)),{uploadId:i,seq:String(o),total:String(a)},n=>t.onProgress?.(s+n,e.size)),!(r.status>=200&&r.status<300))return r}return r})()},[r,C]),Ot=(0,D.useCallback)(async e=>{F(null),M(!0),P({loaded:0,total:e.size});try{let{status:t,data:n}=await Dt(e,{onProgress:(e,t)=>P({loaded:e,total:t})});t>=200&&t<300&&n.path?(he(n.path.split(`/`).slice(0,-1).join(`/`)||`.`),L(e=>e+1)):F(t===0?`Network error during upload — the connection failed before the server responded.`:n.error??`Upload failed (HTTP ${t}).`)}finally{M(!1),P(null),I.current&&(I.current.value=``)}},[Dt]),kt=(0,D.useCallback)(e=>{H&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),Ge(!0))},[H]),At=(0,D.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||Ge(!1)},[]),jt=(0,D.useCallback)(async e=>{e.preventDefault(),Ge(!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(!H){console.info(`[data-ui] op=drop-rejected token=${t} reason=no-write`),F(`Open a folder inside your account to upload`);return}let r=n.map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e);M(!0),F(null),Ve(null);let i=performance.now();try{let e=await Fe(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}`),P({loaded:0,total:r.size});let{status:a,data:c}=await Dt(r,{relpath:i,token:t,onProgress:(e,t)=>P({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`:Ie(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}`),Ve(`Uploaded ${o}, skipped ${s.length}${s.length?`: ${s.join(`, `)}`:``}`),L(e=>e+1)}catch(e){F(e instanceof Error?e.message:String(e))}finally{M(!1),P(null)}},[H,Dt]),Mt=(0,D.useCallback)(async()=>{let t=Xe.trim();if(t){V(null);try{let n=await e(`/api/admin/files/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:C===`.`?``:C,name:t})}),r=await n.json().catch(()=>({error:`HTTP ${n.status}`}));if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);R(!1),Ze(``),L(e=>e+1)}catch(e){V(e instanceof Error?e.message:String(e))}}},[e,Xe,C]),Nt=(0,D.useCallback)(async()=>{if(!z)return;let t=Qe.trim();if(!t)return;V(null);let n=C===`.`?z:`${C}/${z}`;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}`);B(null),$e(``),X(`action`),L(e=>e+1)}catch(e){V(e instanceof Error?e.message:String(e))}},[e,Qe,z,C,X]);(0,D.useEffect)(()=>{if(!tt)return;let e=e=>{rt.current&&!rt.current.contains(e.target)&&nt(!1)},t=e=>{e.key===`Escape`&&nt(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[tt]),(0,D.useEffect)(()=>{if(!it)return;let e=e=>{at.current&&!at.current.contains(e.target)&&U(!1)},t=e=>{e.key===`Escape`&&U(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[it]);let $=(0,D.useCallback)(e=>k.slice(0,e+1).map(e=>e.name).join(`/`),[k]),Pt=k.length>=2,Ft=Pt?[{name:`.`,label:`data`},...k.slice(0,k.length-2).map((e,t)=>({name:$(t),label:e.displayName??e.name}))]:[];return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`data-toolbar`,children:[K?(0,O.jsxs)(`button`,{type:`button`,className:`data-select-cancel`,onClick:()=>X(`cancel`),"aria-label":`Cancel selection`,children:[(0,O.jsx)(t,{size:14}),` Cancel`]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`data-search-input`,children:[o===``&&(0,O.jsx)(ue,{size:14}),(0,O.jsx)(`input`,{ref:l,type:`text`,value:o,onChange:e=>c(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),g&&(0,O.jsx)(n,{size:14,className:`spin`}),o!==``&&(0,O.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{c(``),l.current?.focus()},title:`Clear search`,"aria-label":`Clear search`,children:(0,O.jsx)(t,{size:14})})]}),(0,O.jsxs)(`div`,{className:`data-toolbar-actions`,ref:at,children:[(0,O.jsx)(`button`,{type:`button`,className:`data-action-overflow`,onClick:()=>U(e=>!e),"aria-haspopup":`menu`,"aria-expanded":it,"aria-label":`File actions`,title:`File actions`,children:(0,O.jsx)(fe,{size:16})}),(0,O.jsxs)(`div`,{className:`data-action-group`,role:`group`,"aria-label":`File actions`,"data-open":it?`true`:void 0,children:[(0,O.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{lt(),U(!1)},disabled:j,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[j?(0,O.jsx)(n,{size:16,className:`spin`}):(0,O.jsx)(ee,{size:16}),(0,O.jsx)(`span`,{className:`data-action-label`,children:`Refresh`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Et(),U(!1)},disabled:Me||!H,title:H?`Upload a file`:`Open a folder inside your account to upload`,"aria-label":`Upload a file`,children:[Me?N&&N.total>0?(0,O.jsxs)(`span`,{className:`data-upload-pct`,children:[Math.round(N.loaded/N.total*100),`%`]}):(0,O.jsx)(n,{size:16,className:`spin`}):(0,O.jsx)(be,{size:16}),(0,O.jsx)(`span`,{className:`data-action-label`,children:`Upload`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{R(e=>!e),Ze(``),V(null),U(!1)},disabled:Me||!H,title:H?`New folder`:`Open a folder inside your account to create one`,"aria-label":`New folder`,children:[(0,O.jsx)(pe,{size:16}),(0,O.jsx)(`span`,{className:`data-action-label`,children:`New folder`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{yt(T===`grid`?`list`:`grid`),U(!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,O.jsx)(_e,{size:16}):(0,O.jsx)(ge,{size:16}),(0,O.jsx)(`span`,{className:`data-action-label`,children:T===`grid`?`List view`:`Grid view`})]})]})]})]}),(0,O.jsxs)(`div`,{className:`data-breadcrumbs`,children:[C!==`.`&&(0,O.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,O.jsx)(de,{size:14})}),Pt?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`span`,{className:`data-crumb-wrap`,ref:rt,children:[(0,O.jsx)(`button`,{type:`button`,className:`data-crumb data-crumb-ellipsis`,onClick:()=>nt(e=>!e),"aria-haspopup":`menu`,"aria-expanded":tt,"aria-label":`Show parent folders`,title:`Show parent folders`,children:`…`}),tt&&(0,O.jsx)(`div`,{className:`data-crumb-menu`,role:`menu`,children:Ft.map(e=>(0,O.jsx)(`button`,{type:`button`,role:`menuitem`,className:`data-crumb-menu-item`,onClick:()=>G(e.name),title:e.label,children:e.label},e.name))})]}),[k.length-2,k.length-1].map(e=>{let t=k[e];return(0,O.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,O.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,O.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>G($(e)),title:t.name,children:t.displayName??t.name})]},$(e))})]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>G(`.`),children:`data`}),k.map((e,t)=>(0,O.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,O.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,O.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>G($(t)),title:e.name,children:e.displayName??e.name})]},$(t)))]})]}),Ye&&(0,O.jsxs)(`div`,{className:`data-inline-form`,children:[(0,O.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`Folder name`,value:Xe,autoFocus:!0,onChange:e=>Ze(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Mt(),e.key===`Escape`&&R(!1)}}),(0,O.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Mt,children:`Create`}),(0,O.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>R(!1),children:`Cancel`})]}),z&&(0,O.jsxs)(`div`,{className:`data-inline-form`,children:[(0,O.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`New name`,value:Qe,autoFocus:!0,onChange:e=>$e(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Nt(),e.key===`Escape`&&B(null)}}),(0,O.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Nt,children:`Rename`}),(0,O.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>B(null),children:`Cancel`})]}),et&&(0,O.jsx)(`div`,{className:`data-error`,children:et}),(0,O.jsx)(`input`,{type:`file`,ref:I,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Ot(t)}})]}),(0,O.jsxs)(`div`,{className:`data-body`,"data-drag-active":He?`true`:void 0,onDragEnter:kt,onDragOver:kt,onDragLeave:At,onDrop:jt,children:[(v!==null||f!==null)&&(0,O.jsxs)(`section`,{className:`data-panel`,children:[v&&(0,O.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,v]}),ot.length>0&&(0,O.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:ot.map(e=>{let t=e===W;return(0,O.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>x(t?null:e),children:ze([e])??e},e)})}),f&&!g&&(0,O.jsxs)(`div`,{className:`data-results-meta`,children:[st.length,` of `,f.length,` result`,f.length===1?``:`s`]}),f&&!g&&!W&&te>0&&!S&&(0,O.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>le(!0),children:[te,` low-confidence result`,te===1?``:`s`,` hidden — show all`]}),f&&!g&&!W&&S&&(0,O.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>le(!1),children:`Showing all results — hide low-confidence`}),f&&f.length===0&&!g&&(0,O.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),st&&st.length>0&&(0,O.jsx)(`ul`,{className:`data-results`,children:st.map(e=>(0,O.jsx)(Re,{hit:e,mode:m,onDownload:ct,onLocate:ut},e.nodeId))})]}),(0,O.jsxs)(`section`,{className:`data-panel`,children:[N&&(0,O.jsxs)(`div`,{className:`data-upload-progress`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":N.total>0?Math.round(N.loaded/N.total*100):void 0,children:[(0,O.jsx)(`div`,{className:`data-upload-progress-track`,children:(0,O.jsx)(`div`,{className:`data-upload-progress-fill`,style:{width:`${N.total>0?Math.round(N.loaded/N.total*100):0}%`}})}),(0,O.jsxs)(`span`,{className:`data-upload-progress-label`,children:[`Uploading… `,N.total>0?`${Math.round(N.loaded/N.total*100)}%`:``]})]}),Le&&(0,O.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,Le]}),Be&&(0,O.jsx)(`div`,{className:`data-status`,children:Be}),Ke&&(0,O.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,Ke]}),Te&&(0,O.jsx)(`div`,{className:`data-error`,children:Te}),j&&(0,O.jsxs)(`div`,{className:`data-loading`,children:[(0,O.jsx)(n,{size:14,className:`spin`}),` Loading…`]}),!K&&!j&&w&&w.length>0&&(0,O.jsxs)(`div`,{className:`data-select-hint`,children:[(0,O.jsx)(ve,{size:13}),(0,O.jsx)(`span`,{children:`Press and hold a file to select, rename, or delete it.`})]}),!j&&w&&w.length===0&&!Te&&(0,O.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!j&&w&&w.length>0&&T===`grid`&&(0,O.jsx)(`ul`,{className:`data-grid`,children:w.map(e=>{let t=e.displayName??e.name,n=K&&q.has(e.name);if(e.kind===`directory`)return(0,O.jsx)(`li`,{className:`data-grid-cell`,"data-selected":n?`true`:void 0,children:(0,O.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(C===`.`?e.name:`${C}/${e.name}`)},children:[K&&(0,O.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,O.jsx)(me,{size:28,className:`data-grid-glyph`}),(0,O.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:t})]})},e.name);if(e.kind===`file`){let i=Ee(e.name),a=C===`.`?e.name:`${C}/${e.name}`;return(0,O.jsx)(`li`,{className:`data-grid-cell`,"data-selected":n?`true`:void 0,children:(0,O.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,O.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),i?(0,O.jsx)(`img`,{className:`data-grid-thumb`,src:ce(r,a),alt:t,loading:`lazy`,onError:()=>console.warn(`[data] op=thumb-error path=${a}`)}):(0,O.jsx)(ie,{size:28,className:`data-grid-glyph`}),(0,O.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:t}),!i&&(0,O.jsx)(`span`,{className:`data-grid-sub`,children:Ue(e.sizeBytes)})]})},e.name)}return(0,O.jsx)(`li`,{className:`data-grid-cell`,children:(0,O.jsxs)(`div`,{className:`data-grid-tile data-entry-disabled`,children:[(0,O.jsx)(ie,{size:28,className:`data-grid-glyph`}),(0,O.jsx)(`span`,{className:`data-grid-label`,children:t}),(0,O.jsx)(`span`,{className:`data-grid-sub`,children:`special`})]})},e.name)})}),!j&&w&&w.length>0&&T===`list`&&(0,O.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,O.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,O.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(C===`.`?e.name:`${C}/${e.name}`)},children:[K&&(0,O.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,O.jsx)(me,{size:14}),(0,O.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,O.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,O.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,O.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,O.jsxs)(`span`,{className:`data-entry-text`,children:[(0,O.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,O.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${We(e.modifiedAt)}`,children:[Ue(e.sizeBytes),` · `,We(e.modifiedAt)]})]})]})},e.name)}return(0,O.jsx)(`li`,{className:`data-entry`,children:(0,O.jsx)(`div`,{className:`data-entry-btn data-entry-file data-entry-disabled`,children:(0,O.jsxs)(`span`,{className:`data-entry-text`,children:[(0,O.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,O.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})})},e.name)})})]})]}),K&&(0,O.jsx)(`div`,{className:`data-select-bar`,role:`toolbar`,"aria-label":`Selection actions`,children:(0,O.jsxs)(`div`,{className:`data-select-bar-inner`,children:[(0,O.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,O.jsx)(s,{size:16}),` Share`]}),(0,O.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Ct,disabled:q.size===0,children:[(0,O.jsx)(ne,{size:16}),` Download`]}),(0,O.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:()=>{let e=[...q][0];e&&(B(e),$e(e))},disabled:q.size!==1,children:[(0,O.jsx)(oe,{size:16}),` Rename`]}),(0,O.jsxs)(`button`,{type:`button`,className:`data-select-action data-select-delete`,onClick:wt,disabled:q.size===0,children:[(0,O.jsx)(a,{size:16}),` Delete`]})]})}),E&&(0,O.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":E.alt,onClick:()=>Se(null),children:(0,O.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:E.src,alt:E.alt})})]})}function Le({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){(0,D.useEffect)(()=>{console.info(`[data-ui] op=mount header=operator home=absent`)},[]);let r=(0,D.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),a=(0,D.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),[o,s]=(0,D.useState)([]),[l,u]=(0,D.useState)(`files`),{subAccounts:d,activeAccountId:f,switching:p,switchAccount:m}=c(t);return(0,D.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||s(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[t]),(0,O.jsxs)(`main`,{className:`data-main`,children:[(0,O.jsx)(i,{variant:`operator`,onNavigate:a,onOpenConversations:o.length>0?()=>u(`conversations`):void 0,onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:r,onDisconnect:async()=>!0,disconnecting:!1,subAccounts:d,activeAccountId:f,switchingAccount:p,onSwitchAccount:m}),l===`conversations`?(0,O.jsx)(we,{conversations:o,sessionKey:t,onBack:()=>u(`files`)}):(0,O.jsx)(P,{adminFetch:e,cacheKey:t,sessionRefetchNonce:n})]})}function F({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=u({initialCacheKey:e,surface:`data`});return(0,O.jsx)(`div`,{className:`data-page`,children:(0,O.jsx)(`main`,{className:`data-main`,children:(0,O.jsx)(P,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})})})}function Re({hit:e,mode:t,onDownload:n,onLocate:r}){let i=Be(e.properties),a=Ve(e.properties),o=ze(e.labels),s=He(e.properties),[c,l]=(0,D.useState)(!1),u=a&&a.length>280,d=c||!u?a:a?.slice(0,280)+`…`,f=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`,p=e.properties.relativePath,m=typeof p==`string`&&p.length>0,h=m?p.lastIndexOf(`/`):-1,g=m?h===-1?`data`:p.slice(0,h):null;return(0,O.jsxs)(`li`,{className:`data-result`,children:[(0,O.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,O.jsx)(`div`,{className:`data-result-header`,children:(0,O.jsx)(`span`,{className:`data-result-labels`,children:o})}),i&&(0,O.jsx)(`div`,{className:`data-result-title`,children:i}),a&&(0,O.jsx)(`pre`,{className:`data-result-body`,children:d}),(0,O.jsxs)(`div`,{className:`data-result-scores`,children:[s&&(0,O.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,We(s),` · `]}),f]})]}),m&&(0,O.jsxs)(`button`,{type:`button`,className:`data-result-locate`,onClick:()=>r(e),title:`Locate in ${g}`,"aria-label":`Locate in ${g}`,children:[(0,O.jsx)(me,{size:12}),g]}),u&&(0,O.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>l(e=>!e),children:c?`Show less`:`Show more`})]})}function ze(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 Be(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 Ve(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 He(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 Ue(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 We(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{F as n,A as r,je as t};