@rubytech/create-realagent-code 0.1.281 → 0.1.283

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 (59) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/plugins/admin/PLUGIN.md +2 -1
  3. package/payload/platform/plugins/admin/hooks/__tests__/prompt-optimiser-compliance.test.sh +154 -0
  4. package/payload/platform/plugins/admin/hooks/__tests__/prompt-optimiser-directive.test.sh +24 -0
  5. package/payload/platform/plugins/admin/hooks/prompt-optimiser-compliance.sh +174 -0
  6. package/payload/platform/plugins/admin/hooks/prompt-optimiser-directive.sh +22 -2
  7. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +5 -5
  8. package/payload/platform/plugins/business-assistant/skills/e-sign/SKILL.md +378 -56
  9. package/payload/platform/plugins/cloudflare/.claude-plugin/plugin.json +1 -1
  10. package/payload/platform/plugins/cloudflare/PLUGIN.md +5 -5
  11. package/payload/platform/plugins/cloudflare/references/api.md +107 -34
  12. package/payload/platform/plugins/cloudflare/references/d1-data-capture.md +29 -21
  13. package/payload/platform/plugins/cloudflare/references/dashboard-guide.md +3 -2
  14. package/payload/platform/plugins/cloudflare/references/hosting-sites.md +7 -5
  15. package/payload/platform/plugins/cloudflare/references/manual-setup.md +3 -2
  16. package/payload/platform/plugins/cloudflare/skills/cloudflare/SKILL.md +6 -6
  17. package/payload/platform/plugins/docs/references/cloudflare.md +1 -1
  18. package/payload/platform/plugins/docs/references/telegram-guide.md +3 -3
  19. package/payload/platform/plugins/email/mcp/dist/__tests__/attachment-resolve.test.js +25 -1
  20. package/payload/platform/plugins/email/mcp/dist/__tests__/attachment-resolve.test.js.map +1 -1
  21. package/payload/platform/plugins/email/mcp/dist/lib/attachment-resolve.d.ts +7 -0
  22. package/payload/platform/plugins/email/mcp/dist/lib/attachment-resolve.d.ts.map +1 -1
  23. package/payload/platform/plugins/email/mcp/dist/lib/attachment-resolve.js +9 -0
  24. package/payload/platform/plugins/email/mcp/dist/lib/attachment-resolve.js.map +1 -1
  25. package/payload/platform/plugins/email/mcp/dist/tools/email-ingest.d.ts.map +1 -1
  26. package/payload/platform/plugins/email/mcp/dist/tools/email-ingest.js +6 -2
  27. package/payload/platform/plugins/email/mcp/dist/tools/email-ingest.js.map +1 -1
  28. package/payload/platform/plugins/prompt-optimiser/skills/prompt-optimiser/SKILL.md +1 -0
  29. package/payload/platform/plugins/whatsapp/.claude-plugin/plugin.json +1 -1
  30. package/payload/platform/plugins/whatsapp/PLUGIN.md +7 -11
  31. package/payload/platform/plugins/whatsapp/mcp/dist/index.js +10 -56
  32. package/payload/platform/plugins/whatsapp/mcp/dist/index.js.map +1 -1
  33. package/payload/platform/plugins/whatsapp/references/channels-whatsapp.md +26 -2
  34. package/payload/platform/plugins/whatsapp/skills/manage-whatsapp-config/SKILL.md +9 -14
  35. package/payload/platform/scripts/setup-account.sh +7 -0
  36. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
  37. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +0 -2
  38. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
  39. package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
  40. package/payload/platform/services/claude-session-manager/dist/http-server.js +80 -3
  41. package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
  42. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts +6 -0
  43. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts.map +1 -1
  44. package/payload/platform/services/whatsapp-channel/dist/notification.js +14 -0
  45. package/payload/platform/services/whatsapp-channel/dist/notification.js.map +1 -1
  46. package/payload/platform/services/whatsapp-channel/dist/server.js +5 -3
  47. package/payload/platform/services/whatsapp-channel/dist/server.js.map +1 -1
  48. package/payload/platform/templates/specialists/agents/personal-assistant.md +1 -1
  49. package/payload/server/public/assets/AdminShell-8Y7-maNi.js +1 -0
  50. package/payload/server/public/assets/{admin-0_VxffD5.js → admin-DyuZ4NT5.js} +1 -1
  51. package/payload/server/public/assets/{browser-Cxjkhtsk.js → browser-XrVAUQdG.js} +1 -1
  52. package/payload/server/public/assets/{data-BOgwOWnw.js → data-tcu3MXmK.js} +1 -1
  53. package/payload/server/public/assets/{graph-BqD2GjQd.js → graph-I4GyC2MW.js} +1 -1
  54. package/payload/server/public/browser.html +2 -2
  55. package/payload/server/public/data.html +2 -2
  56. package/payload/server/public/graph.html +2 -2
  57. package/payload/server/public/index.html +2 -2
  58. package/payload/server/server.js +882 -767
  59. package/payload/server/public/assets/AdminShell-FO766lOW.js +0 -1
@@ -3,7 +3,7 @@ name: personal-assistant
3
3
  description: "Scheduling, platform settings, messaging channels (Telegram, WhatsApp, email, Outlook), tunnel and domain setup, and browser automation. Delegate when the work is on your calendar, configuring the platform, sending or reading messages, or driving a browser."
4
4
  summary: "Handles the operational tasks you'd give a personal assistant: scheduling meetings, managing your platform settings, connecting messaging channels, and completing browser-based tasks on your behalf."
5
5
  model: claude-sonnet-4-6
6
- tools: Skill, mcp__plugin_admin_admin__system-status, mcp__plugin_admin_admin__brand-settings, mcp__plugin_admin_admin__account-manage, mcp__plugin_admin_admin__account-update, mcp__plugin_admin_admin__logs-read, mcp__plugin_admin_admin__plugin-read, mcp__plugin_admin_admin__wifi, mcp__plugin_contacts_contacts__contact-create, mcp__plugin_contacts_contacts__contact-lookup, mcp__plugin_contacts_contacts__contact-update, mcp__plugin_contacts_contacts__contact-delete, mcp__plugin_contacts_contacts__contact-list, mcp__plugin_contacts_contacts__contact-export, mcp__plugin_contacts_contacts__contact-erase, mcp__plugin_contacts_contacts__group-create, mcp__plugin_contacts_contacts__group-manage, mcp__plugin_telegram_telegram__message, mcp__plugin_telegram_telegram__message-history, mcp__plugin_telegram_telegram__telegram-webhook-register, mcp__plugin_whatsapp_whatsapp__whatsapp-login-start, mcp__plugin_whatsapp_whatsapp__whatsapp-login-wait, mcp__plugin_whatsapp_whatsapp__whatsapp-status, mcp__plugin_whatsapp_whatsapp__whatsapp-disconnect, mcp__plugin_whatsapp_whatsapp__whatsapp-send, mcp__plugin_whatsapp_whatsapp__whatsapp-send-document, mcp__plugin_whatsapp_whatsapp__whatsapp-config, mcp__plugin_whatsapp_whatsapp__whatsapp-activity, mcp__plugin_whatsapp_whatsapp__whatsapp-conversations, mcp__plugin_whatsapp_whatsapp__whatsapp-messages, mcp__plugin_whatsapp_whatsapp__whatsapp-conversation-graph-state, mcp__plugin_whatsapp_whatsapp__whatsapp-group-info, mcp__plugin_email_email__email-provider-info, mcp__plugin_email_email__email-setup, mcp__plugin_email_email__email-read, mcp__plugin_email_email__email-send, mcp__plugin_email_email__email-reply, mcp__plugin_email_email__email-search, mcp__plugin_email_email__email-graph-query, mcp__plugin_email_email__email-otp-extract, mcp__plugin_email_email__email-status, mcp__plugin_email_email__email-fetch, mcp__plugin_email_email__email-ingest, mcp__plugin_outlook_outlook__outlook-account-register, mcp__plugin_outlook_outlook__outlook-mail-list, mcp__plugin_outlook_outlook__outlook-mail-search, mcp__plugin_outlook_outlook__outlook-calendar-list, mcp__plugin_outlook_outlook__outlook-calendar-event, mcp__plugin_outlook_outlook__outlook-contacts-list, mcp__plugin_outlook_outlook__outlook-mailbox-info, mcp__plugin_scheduling_scheduling__schedule-event, mcp__plugin_scheduling_scheduling__schedule-list, mcp__plugin_scheduling_scheduling__schedule-get, mcp__plugin_scheduling_scheduling__schedule-update, mcp__plugin_scheduling_scheduling__schedule-cancel, mcp__plugin_scheduling_scheduling__schedule-export-ics, mcp__plugin_scheduling_scheduling__schedule-import-ics, mcp__plugin_scheduling_scheduling__time-resolve, mcp__plugin_memory_memory__memory-search, mcp__plugin_memory_memory__profile-update, mcp__plugin_url-get_url-get__url-get, mcp__plugin_browser_browser__browser-render, mcp__plugin_browser_browser__browser-navigate, mcp__plugin_browser_browser__browser-snapshot, mcp__plugin_browser_browser__browser-click, mcp__plugin_browser_browser__browser-fill, mcp__plugin_browser_browser__browser-fill-form, mcp__plugin_browser_browser__browser-type, mcp__plugin_browser_browser__browser-press-key, mcp__plugin_browser_browser__browser-hover, mcp__plugin_browser_browser__browser-select-option, mcp__plugin_browser_browser__browser-wait-for, mcp__plugin_browser_browser__browser-handle-dialog, mcp__plugin_browser_browser__browser-evaluate, mcp__plugin_browser_browser__browser-console-messages, mcp__plugin_browser_browser__browser-tabs, mcp__plugin_browser_browser__browser-pdf-save, mcp__plugin_browser_browser__browser-screenshot, mcp__plugin_browser_browser__browser-resize
6
+ tools: Skill, mcp__plugin_admin_admin__system-status, mcp__plugin_admin_admin__brand-settings, mcp__plugin_admin_admin__account-manage, mcp__plugin_admin_admin__account-update, mcp__plugin_admin_admin__logs-read, mcp__plugin_admin_admin__plugin-read, mcp__plugin_admin_admin__wifi, mcp__plugin_contacts_contacts__contact-create, mcp__plugin_contacts_contacts__contact-lookup, mcp__plugin_contacts_contacts__contact-update, mcp__plugin_contacts_contacts__contact-delete, mcp__plugin_contacts_contacts__contact-list, mcp__plugin_contacts_contacts__contact-export, mcp__plugin_contacts_contacts__contact-erase, mcp__plugin_contacts_contacts__group-create, mcp__plugin_contacts_contacts__group-manage, mcp__plugin_telegram_telegram__message, mcp__plugin_telegram_telegram__message-history, mcp__plugin_telegram_telegram__telegram-webhook-register, mcp__plugin_whatsapp_whatsapp__whatsapp-login-start, mcp__plugin_whatsapp_whatsapp__whatsapp-login-wait, mcp__plugin_whatsapp_whatsapp__whatsapp-status, mcp__plugin_whatsapp_whatsapp__whatsapp-disconnect, mcp__plugin_whatsapp_whatsapp__whatsapp-config, mcp__plugin_whatsapp_whatsapp__whatsapp-activity, mcp__plugin_whatsapp_whatsapp__whatsapp-conversations, mcp__plugin_whatsapp_whatsapp__whatsapp-messages, mcp__plugin_whatsapp_whatsapp__whatsapp-conversation-graph-state, mcp__plugin_whatsapp_whatsapp__whatsapp-group-info, mcp__plugin_email_email__email-provider-info, mcp__plugin_email_email__email-setup, mcp__plugin_email_email__email-read, mcp__plugin_email_email__email-send, mcp__plugin_email_email__email-reply, mcp__plugin_email_email__email-search, mcp__plugin_email_email__email-graph-query, mcp__plugin_email_email__email-otp-extract, mcp__plugin_email_email__email-status, mcp__plugin_email_email__email-fetch, mcp__plugin_email_email__email-ingest, mcp__plugin_outlook_outlook__outlook-account-register, mcp__plugin_outlook_outlook__outlook-mail-list, mcp__plugin_outlook_outlook__outlook-mail-search, mcp__plugin_outlook_outlook__outlook-calendar-list, mcp__plugin_outlook_outlook__outlook-calendar-event, mcp__plugin_outlook_outlook__outlook-contacts-list, mcp__plugin_outlook_outlook__outlook-mailbox-info, mcp__plugin_scheduling_scheduling__schedule-event, mcp__plugin_scheduling_scheduling__schedule-list, mcp__plugin_scheduling_scheduling__schedule-get, mcp__plugin_scheduling_scheduling__schedule-update, mcp__plugin_scheduling_scheduling__schedule-cancel, mcp__plugin_scheduling_scheduling__schedule-export-ics, mcp__plugin_scheduling_scheduling__schedule-import-ics, mcp__plugin_scheduling_scheduling__time-resolve, mcp__plugin_memory_memory__memory-search, mcp__plugin_memory_memory__profile-update, mcp__plugin_url-get_url-get__url-get, mcp__plugin_browser_browser__browser-render, mcp__plugin_browser_browser__browser-navigate, mcp__plugin_browser_browser__browser-snapshot, mcp__plugin_browser_browser__browser-click, mcp__plugin_browser_browser__browser-fill, mcp__plugin_browser_browser__browser-fill-form, mcp__plugin_browser_browser__browser-type, mcp__plugin_browser_browser__browser-press-key, mcp__plugin_browser_browser__browser-hover, mcp__plugin_browser_browser__browser-select-option, mcp__plugin_browser_browser__browser-wait-for, mcp__plugin_browser_browser__browser-handle-dialog, mcp__plugin_browser_browser__browser-evaluate, mcp__plugin_browser_browser__browser-console-messages, mcp__plugin_browser_browser__browser-tabs, mcp__plugin_browser_browser__browser-pdf-save, mcp__plugin_browser_browser__browser-screenshot, mcp__plugin_browser_browser__browser-resize
7
7
  ---
8
8
 
9
9
  # Personal Assistant
@@ -0,0 +1 @@
1
+ import{o as e}from"./chunk-CnGqDkHZ.js";import{d as t,f as n,l as r,m as i,o as a,r as o,t as s,u as c}from"./useSelectionMode-BPzPjKP_.js";var l=n(`archive-restore`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]]),u=n(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),d=n(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),f=n(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),p=n(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),m=n(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),h=n(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),g=n(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),_=n(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),v=n(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),ee=n(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),y=n(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),b=n(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),x=n(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),te=n(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),ne=n(`message-circle`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}]]),S=n(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),C=n(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),re=n(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),w=n(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),ie=n(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),ae=n(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),oe=n(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),T=n(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),E=e(i(),1),D=r(),O=`maxy-shell-side-px`;function k(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function A(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-k());return Math.min(Math.max(e,248),n)}function j(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(O);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=248)return A(t)}catch{}return 264}function se({targetSelector:e=`.platform`}){let t=(0,E.useRef)(null),[n,r]=(0,E.useState)(()=>j()),i=(0,E.useRef)(n);(0,E.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,E.useCallback)(()=>{r(e=>{let t=A(e);return t===e?e:t})},[]);(0,E.useEffect)(()=>{a(),window.addEventListener(`resize`,a);let t=document.querySelector(e),n=null;return t instanceof HTMLElement&&(n=new MutationObserver(a),n.observe(t,{attributes:!0,attributeFilter:[`data-artefact`,`class`]})),()=>{window.removeEventListener(`resize`,a),n?.disconnect()}},[a,e]);let o=e=>{e.preventDefault();let n=t.current;if(!n)return;n.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=!1,o=e=>{a=!0,r(A(Math.round(e.clientX)))},s=()=>{if(n.releasePointerCapture(e.pointerId),n.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),!a)return;let t=i.current;try{window.localStorage.setItem(O,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=A(264);r(e);try{window.localStorage.removeItem(O)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,D.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var M=`maxy-admin-session`,N=typeof BroadcastChannel<`u`;function P(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`rotation`&&typeof t.newKey==`string`&&t.newKey.length>0&&(t.surface===`chat`||t.surface===`graph`||t.surface===`data`||t.surface===`sessions`)&&typeof t.ts==`number`}function F(e){if(!N)return()=>{};let t=new BroadcastChannel(M),n=t=>{if(!P(t.data)){console.warn(`[admin-session-broadcast] outcome=received-malformed payload=${JSON.stringify(t.data)}`);return}e(t.data)};return t.addEventListener(`message`,n),()=>{t.removeEventListener(`message`,n),t.close()}}var I=`maxy-admin-session-key`;function L(e,t){return`${e}${e.includes(`?`)?`&`:`?`}session_key=${encodeURIComponent(t)}`}async function R(e){let t;try{t=await e.clone().json()}catch{return`parse-failed`}if(typeof t!=`object`||!t)return`unknown-401`;let n=t.code;return n===`session-missing`||n===`session-not-registered`||n===`session-expired-age`||n===`grant-expired`?n:`unknown-401`}function ce(){try{return sessionStorage.getItem(I)}catch{return null}}function z(e){let{initialCacheKey:t,surface:n}=e,[r,i]=(0,E.useState)(t),a=(0,E.useRef)(t);(0,E.useEffect)(()=>{a.current=r},[r]),(0,E.useEffect)(()=>{t!==a.current&&(i(t),a.current=t,s(e=>e+1))},[t]);let[o,s]=(0,E.useState)(0);(0,E.useEffect)(()=>F(e=>{let t=a.current.slice(0,8),r=e.newKey.slice(0,8);e.newKey!==a.current&&(console.log(`[admin-session-broadcast] outcome=received oldKey=${t} newKey=${r} surface=${n} senderSurface=${e.surface}`),i(e.newKey),s(e=>e+1))}),[n]);let c=(0,E.useCallback)(()=>{try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`},[]);return{adminFetch:(0,E.useCallback)(async(e,t)=>{let r=a.current,o=L(e,r),l=await fetch(o,t);if(l.status!==401)return l;let u=await R(l);if(u===`session-missing`||u!==`session-not-registered`)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=${u} surface=${n} path=${e}`),c(),l;let d=ce();if(!d||d===r)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=session-not-registered-no-fresh-key surface=${n} path=${e}`),c(),l;i(d),a.current=d,s(e=>e+1),console.log(`[useAdminFetch] outcome=retry-after-rotation oldKey=${r.slice(0,8)} newKey=${d.slice(0,8)} surface=${n} path=${e}`);let f=L(e,d),p=await fetch(f,t);return p.status===401&&(console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=second-401-after-retry surface=${n} path=${e}`),c()),p},[c,n]),cacheKey:r,sessionRefetchNonce:o}}var B=(0,E.createContext)(null);function le({cacheKey:e,onSessionExpired:t,surface:n,children:r}){let i=(0,E.useCallback)(async(r,i)=>{if(!e)return fetch(r,i);let a=L(r,e),o=await fetch(a,i);if(o.status!==401)return o;let s=await R(o),c=e.slice(-8);if(s===`session-not-registered`){let a=ce();if(a&&a!==e){let e=L(r,a),o=await fetch(e,i);return o.status===401?(console.warn(`[admin-auth] outcome=session-expired-redirect code=second-401-after-retry path=${r} cacheKey=${c} surface=${n}`),t({code:`second-401-after-retry`,path:r}),o):o}}return console.warn(`[admin-auth] outcome=session-expired-redirect code=${s} path=${r} cacheKey=${c} surface=${n}`),t({code:s,path:r}),o},[e,t,n]);return(0,D.jsx)(B.Provider,{value:i,children:r})}function V(){return(0,E.useContext)(B)}function ue(e){let t=V();return(0,E.useMemo)(()=>t||(async(t,n)=>fetch(e?L(t,e):t,n)),[t,e])}function H(e){let{businessName:t,onNavigate:n,onToggleSidebar:r,sidebarOpen:i,onLogout:s}=e,[l,u]=(0,E.useState)(!1),d=(0,E.useRef)(null),f=(0,E.useRef)(null),h=ue(null),[v,y]=(0,E.useState)(null),[ne,re]=(0,E.useState)(!1),[w,ae]=(0,E.useState)(null),[oe,O]=(0,E.useState)(null),[k,A]=(0,E.useState)(null),[j,se]=(0,E.useState)(``);(0,E.useEffect)(()=>{se(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,E.useEffect)(()=>{if(!l)return;let e=e=>{d.current&&!d.current.contains(e.target)&&u(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[l]),(0,E.useEffect)(()=>{if(!l)return;let e=e=>{e.key===`Escape`&&u(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[l]),(0,E.useEffect)(()=>{l&&f.current?.focus()},[l]),(0,E.useEffect)(()=>{if(!l)return;let e=!1;return h(`/api/admin/version`).then(e=>e.json()).then(t=>{e||A(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[l,h]);let M=(0,E.useCallback)(()=>{u(e=>{let t=!e;return t&&console.info(`[admin-ui] header-menu-open`),t})},[]),N=(0,E.useCallback)(e=>{u(!1),n(e)},[n]),P=(0,E.useCallback)(async()=>{if(v!==null){y(null),O(null);return}re(!0),ae(null);try{let e=await h(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);y((await e.json()).agents??[])}catch(e){console.error(`[admin/agents] list failed:`,e),ae(e instanceof Error?e.message:String(e)),y([])}finally{re(!1)}},[v,h]),F=(0,E.useCallback)(e=>{O(null),y(t=>t?.filter(t=>t.slug!==e)??null),h(`/api/admin/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},[h]),I=(0,E.useCallback)(()=>{u(!1),s()},[s]),L=t||o.productName;return(0,D.jsxs)(`header`,{className:`admin-header`,children:[(0,D.jsx)(`button`,{type:`button`,className:`admin-sidebar-toggle`,"aria-label":i?`Hide sidebar`:`Show sidebar`,title:i?`Hide sidebar`:`Show sidebar`,"aria-expanded":i,onClick:r,children:i?(0,D.jsx)(S,{size:20,strokeWidth:1.5}):(0,D.jsx)(C,{size:20,strokeWidth:1.5})}),(0,D.jsxs)(`div`,{className:`chat-header-label`,children:[(0,D.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,D.jsx)(`img`,{src:a,alt:``,className:`chat-logo`})}),(0,D.jsx)(`h1`,{className:`chat-tagline`,children:L})]}),(0,D.jsxs)(`div`,{className:`chat-burger-wrap`,ref:d,children:[(0,D.jsx)(`button`,{type:`button`,className:`admin-burger`,onClick:M,"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":l,children:(0,D.jsx)(te,{size:20})}),l&&(0,D.jsxs)(`div`,{className:`admin-menu`,role:`menu`,children:[(0,D.jsxs)(`button`,{ref:f,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>N(`data`),children:[(0,D.jsx)(m,{size:14}),` Data`]}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>N(`graph`),children:[(0,D.jsx)(ie,{size:14}),` Graph`]}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>N(`browser`),children:[(0,D.jsx)(_,{size:14}),` Browser`]}),(0,D.jsx)(`div`,{className:`chat-menu-divider`}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:P,children:[(0,D.jsx)(g,{size:14}),` Public`,ne&&(0,D.jsx)(b,{size:12,className:`spin`})]}),v!==null&&(0,D.jsxs)(`div`,{className:`chat-menu-agents`,children:[w&&(0,D.jsx)(`span`,{className:`chat-menu-agent-error`,children:w}),v.length===0&&!w&&(0,D.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),v.map(e=>(0,D.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,D.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,D.jsxs)(`span`,{className:`agent-text`,children:[(0,D.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,D.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),oe===e.slug?(0,D.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>F(e.slug),children:(0,D.jsx)(p,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>O(null),children:(0,D.jsx)(T,{size:12})})]}):(0,D.jsxs)(`span`,{className:`agent-actions`,children:[(0,D.jsx)(`a`,{href:`${j}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>u(!1),children:(0,D.jsx)(g,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>O(e.slug),children:(0,D.jsx)(c,{size:12})})]})]},e.slug))]}),(0,D.jsx)(`div`,{className:`chat-menu-divider`}),(0,D.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,D.jsx)(ee,{size:14}),(0,D.jsxs)(`span`,{className:`version-installed`,children:[k?`v${k.installed}`:`…`,k&&!k.updateAvailable&&(0,D.jsx)(`span`,{className:`version-uptodate-dot`}),k?.updateAvailable&&(0,D.jsx)(`span`,{className:`version-update-dot`})]})]}),(0,D.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:I,children:[(0,D.jsx)(x,{size:14}),` Log out`]})]})]})]})}function de(e,t,n=`data`){let r=`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`+(n===`data`?``:`&root=${encodeURIComponent(n)}`),i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()}function fe(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function U(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}var pe=`auth-refresh-failed`;function me({error:e,onClose:t}){if(!e)return null;let n=e.reason===pe,r=n?`Claude sign-in expired`:`Session didn’t open`,i=n?`Your claude.ai login has expired. Re-authenticate to resume sessions.`:`The session did not bind within 60 seconds, so there is no live conversation to open.`;return(0,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`span`,{children:r}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,D.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function W(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:c}=e,[l,u]=(0,E.useState)(null);if(!t)return null;let d=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),f=d.at(-1),p=f?.peak_request_pct==null?f?.context_window?Math.round((f.input_tokens+f.cache_creation_tokens+f.cache_read_tokens)/f.context_window*100):0:Math.round(f.peak_request_pct*100),m=d.reduce((e,t)=>e+t.input_tokens+t.cache_creation_tokens+t.cache_read_tokens+t.output_tokens,0),h=i.flatMap(e=>e.events?.filter(e=>e.type===`rate_limit`)??[]).at(-1),g=d.reduce((e,t)=>e+(t.total_cost_usd??0),0),_=r?.account?.subscriptionType,v=e=>{let t=e*1e3-Date.now();if(t<=0)return`now`;let n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4);return n>0?`${n}h ${r}m`:`${r}m`};return(0,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,D.jsx)(`span`,{children:`Claude Code`}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(_||h||g>0)&&(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[_&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,D.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:_})]}),h&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(h.utilization*100),`%`]})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:v(h.resetsAt)})]}),h.isUsingOverage&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),g>0&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,g<.01?g.toFixed(4):g.toFixed(2)]})]})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:p>0?`${p}%`:`—`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:m>0?U(m):`—`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:fe(a)})]}),(o||c)&&(()=>{let e=o??c??``;return(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsx)(`button`,{type:`button`,className:`claude-info-value claude-info-id-copy`,title:`${e} (${o?`flushed`:`pre-flush`}) — click to copy`,onClick:async()=>{u(await s(e)?`copied`:`failed`),setTimeout(()=>u(null),1200)},children:l===`copied`?`copied ✓`:l===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}var he=`https://claude.ai/code`,ge=[500,1e3,1500,2e3,2500,3e3,3e3];function _e(e,t,n){let r=n.slug??n.bridgeSessionId??null;if(e&&r)return{kind:`navigate`,url:`${he}/${r}`};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function G(e){let{businessName:n,cacheKey:r,role:i,userName:a,userAvatar:s,onSelectProjects:p,onSelectPeople:m,onSelectTasks:_,onSelectAgents:ee,onCloseMobileDrawer:b,collapsed:x,selectedWhatsappId:te,onSelectWhatsappConversation:S}=e,C=ue(r),ie=o.productName,T=typeof a==`string`?a:a===null?`name unavailable`:n||ie,O=(T.trim().charAt(0)||`?`).toUpperCase(),[k,A]=(0,E.useState)(`sessions`),[j,se]=(0,E.useState)([]),[M,N]=(0,E.useState)(!1),[P,F]=(0,E.useState)(null),[I,L]=(0,E.useState)(!1),[R,ce]=(0,E.useState)(`file`),[z,B]=(0,E.useState)(null),[le,V]=(0,E.useState)(null),[H,fe]=(0,E.useState)([]),[U,pe]=(0,E.useState)(!1),[W,he]=(0,E.useState)(null),[G,ve]=(0,E.useState)(!1),[K,q]=(0,E.useState)(!1),[J,be]=(0,E.useState)(!1),[xe,Se]=(0,E.useState)(null),[Y,Ce]=(0,E.useState)(new Set),[we,Te]=(0,E.useState)(new Set),[Ee,De]=(0,E.useState)(new Set),[Oe,ke]=(0,E.useState)(new Set),[X,Ae]=(0,E.useState)(!1),[Z,je]=(0,E.useState)([]),[Me,Ne]=(0,E.useState)(!1),[Pe,Fe]=(0,E.useState)(null),[Ie,Le]=(0,E.useState)(!1),Re=(0,E.useCallback)(e=>{if(b(),!r){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=no-cache-key`),B({message:`Session not ready — try again`,failed:!0});return}if(!e.downloadPath){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=not-downloadable`),B({message:`${e.name} can’t be downloaded`,failed:!0});return}console.info(`[admin-ui] artefact-download id=${e.id} root=${e.downloadRoot??`data`} path=${e.downloadPath}`),de(r,e.downloadPath,e.downloadRoot??`data`),B({message:`Downloading ${e.name}`,failed:!1})},[r,b]);(0,E.useEffect)(()=>{if(!z)return;let e=setTimeout(()=>B(null),2500);return()=>clearTimeout(e)},[z]);let ze=(0,E.useCallback)(async()=>{if(r){L(!0),F(null);try{let e=await C(`/api/admin/sidebar-artefacts`);if(!e.ok)throw Error(`status ${e.status}`);se((await e.json()).artefacts??[]),N(!0)}catch(e){let t=e instanceof Error?e.message:String(e);F(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{L(!1)}}},[r,C]),Q=(0,E.useCallback)(async()=>{if(!r)return null;ve(!0),he(null);try{let e=await C(`/api/admin/sidebar-sessions`);if(!e.ok)throw Error(`status ${e.status}`);let t=await e.json(),n=t.sessions??[];return fe(n),Se(t.accountId??null),pe(!0),n}catch(e){let t=e instanceof Error?e.message:String(e);return he(`Failed to load sessions: ${t}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${t}`),null}finally{ve(!1)}},[r,C]),Be=(0,E.useCallback)(async()=>{if(r){Le(!0),Fe(null);try{let e=await C(`/api/whatsapp-reader/conversations`);if(!e.ok)throw Error(`status ${e.status}`);je((await e.json()).conversations??[]),Ne(!0)}catch(e){let t=e instanceof Error?e.message:String(e);Fe(`Failed to load WhatsApp conversations: ${t}`),console.error(`[admin-ui] whatsapp-conversations fetch failed: ${t}`)}finally{Le(!1)}}},[r,C]);(0,E.useEffect)(()=>{!r||U||Q()},[r,U,Q]);let Ve=()=>{S(null),A(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${M?j.length:0} collapsed=${x}`),ze()},$=1.5,He=()=>{console.info(`[admin-ui] sidebar-refresh surface=artefacts`),ze()},Ue=()=>{S(null),A(`sessions`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${U?H.length:0} collapsed=${x}`),U||Q()},We=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions`),Q()},Ge=()=>{A(`whatsapp`),console.info(`[admin-ui] sidebar-nav surface=whatsapp count=${Me?Z.length:0} collapsed=${x}`),Me||Be()},Ke=()=>{console.info(`[admin-ui] sidebar-refresh surface=whatsapp`),Be()},qe=(0,E.useCallback)(async e=>{if(e.resumable===!1||we.has(e.sessionId))return;Te(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await C(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId})}),r=await n.json().catch(()=>({})),i=_e(n.ok,n.status,{...r,sessionId:r.sessionId??e.sessionId});console.info(`[admin-ui] sidebar-session-resume sessionId=${e.sessionId} status=${n.status} outcome=${i.kind} slug=${r.slug??r.bridgeSessionId??`none`}`),i.kind===`navigate`?(b(),t?t.location.href=i.url:window.open(i.url,`_blank`)):(t?.close(),console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} status=${n.status} reason=${i.reason}`),V(i))}catch(n){t?.close();let r=n instanceof Error?n.message:String(n);console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} error=${r}`),V({sessionId:e.sessionId,reason:r})}finally{Te(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[C,b,we]),Je=(0,E.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=ge.length;n++){await new Promise(e=>setTimeout(e,ge[n-1]));let r=await Q();if(r&&r.some(t=>t.sessionId===e)){console.info(`[admin-ui] sidebar-new-session-converged sessionId=${t} via=retry attempts=${n}`);return}}console.error(`[admin-ui] sidebar-new-session-converge-timeout sessionId=${t}`)},[Q]),Ye=(0,E.useCallback)(async()=>{if(X)return;Ae(!0);let e=window.open(``,`_blank`);try{let t=await C(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}),n=await t.json().catch(()=>({})),r=_e(t.ok,t.status,n);console.info(`[admin-ui] sidebar-new-session-spawned status=${t.status} outcome=${r.kind} slug=${n.slug??n.bridgeSessionId??`none`}`),r.kind===`navigate`?(e?e.location.href=r.url:window.open(r.url,`_blank`),n.sessionId?Je(n.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):(e?.close(),console.error(`[admin-ui] sidebar-new-session-failed status=${t.status} reason=${r.reason}`),V(r))}catch(t){e?.close();let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-new-session-failed error=${n}`),V({sessionId:null,reason:n})}finally{Ae(!1)}},[C,X,Je]),Xe=(0,E.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Y.has(t.sessionId)){Ce(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await C(`/api/admin/session-delete`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),B({message:`Delete failed: ${n.error??`status ${e.status}`}`,failed:!0});return}let n=await e.json();console.info(`[admin-ui] sidebar-session-delete sessionId=${t.sessionId} pidKilled=${n.pidKilled??`?`} deleted=${n.deleted??`?`}`),fe(e=>e.filter(e=>e.sessionId!==t.sessionId)),Q()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} error=${n}`),B({message:`Delete failed: ${n}`,failed:!0})}finally{Ce(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[C,Y,Q]),Ze=(0,E.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Ee.has(t.sessionId)){De(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await C(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),B({message:`Stop failed: ${n.error??`status ${e.status}`}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-stop sessionId=${t.sessionId}`),Q()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} error=${n}`),B({message:`Stop failed: ${n}`,failed:!0})}finally{De(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[C,Ee,Q]),Qe=(0,E.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!Oe.has(t.sessionId)){ke(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await C(`/api/admin/session-archive`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId,mode:n})});if(!e.ok){let r=await e.json().catch(()=>({})),i=r.detail??r.error??`status ${e.status}`;console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} status=${e.status} error=${r.error??`unknown`}`),B({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${i}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-archive sessionId=${t.sessionId} mode=${n}`),Q()}catch(e){let r=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} error=${r}`),B({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{ke(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[C,Oe,Q]);return(0,D.jsxs)(`aside`,{className:`side`,children:[(0,D.jsx)(`div`,{className:`side-new-session-row`,children:(0,D.jsxs)(`button`,{type:`button`,className:`side-new-session`,onClick:Ye,disabled:X,"aria-busy":X,children:[(0,D.jsx)(re,{size:14}),(0,D.jsx)(`span`,{children:X?`Spawning…`:`New session`})]})}),(0,D.jsxs)(`nav`,{className:`side-nav`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),m(),b()},children:[(0,D.jsx)(oe,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`People`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),ee(),b()},children:[(0,D.jsx)(d,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Agents`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),p(),b()},children:[(0,D.jsx)(f,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Projects`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),_(),b()},children:[(0,D.jsx)(y,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row${k===`artefacts`?` active`:``}`,onClick:Ve,children:[(0,D.jsx)(t,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row${k===`sessions`?` active`:``}`,onClick:Ue,children:[(0,D.jsx)(v,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,D.jsx)(`span`,{className:`kbd`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`nav-row${k===`whatsapp`?` active`:``}`,onClick:Ge,children:[(0,D.jsx)(ne,{size:20,strokeWidth:$}),(0,D.jsx)(`span`,{className:`label`,children:`WhatsApp`}),(0,D.jsx)(`span`,{className:`kbd`})]})]}),k===`artefacts`&&(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:`Artefacts`}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh artefacts`,"aria-label":`Refresh artefacts`,onClick:He,disabled:I,children:(0,D.jsx)(w,{size:12,className:I?`spinning`:void 0})}),(0,D.jsx)(`span`,{children:I?`…`:String(j.length)})]})]}),P&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:P}),M&&!P&&j.length>0&&(()=>{let e=j.filter(e=>e.kind===`agent-template`).length,t=j.length-e;return(0,D.jsx)(`div`,{className:`artefact-filter-chips`,children:[{key:`all`,label:`All`,count:j.length},{key:`agent`,label:`Agents`,count:e},{key:`file`,label:`Files`,count:t}].map(e=>(0,D.jsxs)(`button`,{type:`button`,className:`artefact-filter-chip${R===e.key?` active`:``}`,onClick:()=>ce(e.key),disabled:e.count===0&&e.key!==`all`,children:[e.label,(0,D.jsx)(`span`,{className:`artefact-filter-chip-count`,children:e.count})]},e.key))})})(),M&&!P&&j.length===0&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),j.filter(e=>R===`all`?!0:R===`agent`?e.kind===`agent-template`:e.kind!==`agent-template`).map(e=>{let n=e.kind===`agent-template`,r=n?d:t,i=Date.parse(e.updatedAt),a=Number.isFinite(i)?new Date(i).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``,o=e.downloadPath!==null;return(0,D.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>Re(e),disabled:!o,style:o?void 0:{cursor:`default`},title:o?`Download ${e.name}`:`${e.name} can’t be downloaded`,children:[(0,D.jsx)(r,{size:14,className:`conv-icon`,"data-kind":n?`agent`:`file`,"aria-label":n?`agent template`:`file`}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsx)(`span`,{className:`conv-name-line`,children:(0,D.jsx)(`span`,{className:`conv-name`,children:e.name})}),a&&(0,D.jsx)(`span`,{className:`conv-timestamp`,children:a})]}),o&&(0,D.jsx)(h,{size:12,className:`conv-rc-icon`,"aria-hidden":`true`})]},e.id)})]}),k===`sessions`&&(()=>{let e=H.filter(e=>K?!0:!e.isSubagent).filter(e=>J?!0:!e.archived),t=H.some(e=>e.isSubagent),n=H.some(e=>e.archived);return(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:`Sessions`}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:We,disabled:G,children:(0,D.jsx)(w,{size:12,className:G?`spinning`:void 0})}),(0,D.jsx)(`span`,{children:G?`…`:String(e.length)})]})]}),xe&&(0,D.jsx)(`div`,{className:`side-account-id`,title:`This install's accountId. The first 8 characters match the truncated UUID label on the live Remote Control daemon entry in claude.ai/code.`,children:(0,D.jsx)(`code`,{children:xe})}),(t||n)&&(0,D.jsxs)(`div`,{className:`artefact-filter-chips`,children:[t&&(0,D.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${K?` active`:``}`,onClick:()=>q(e=>!e),title:K?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),n&&(0,D.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${J?` active`:``}`,onClick:()=>be(e=>!e),title:J?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),W&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:W}),U&&!W&&e.length===0&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=Date.parse(e.startedAt),n=Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``,r=we.has(e.sessionId),i=Y.has(e.sessionId),a=Ee.has(e.sessionId),o=Oe.has(e.sessionId);return(0,D.jsxs)(`div`,{className:`conv conv-with-actions`,children:[(0,D.jsxs)(`div`,{className:`conv-main-static`,children:[(0,D.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsx)(`span`,{className:`conv-name-line`,children:(0,D.jsx)(`span`,{className:`conv-name`,title:e.title,children:e.title})}),(0,D.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,D.jsx)(`code`,{className:`conv-session-id`,title:`First 8 characters of this session's id — distinguishes rows with identical auto-titles. The resume/delete buttons act on the full id.`,children:e.sessionId.slice(0,8)}),n&&(0,D.jsxs)(`span`,{children:[` · `,n]})]})]})]}),(0,D.jsxs)(`div`,{className:`conv-actions`,children:[e.resumable===!1?(0,D.jsx)(`span`,{className:`conv-ephemeral`,title:`Public webchat session — ephemeral, not resumable`,"aria-label":`Ephemeral public session (not resumable)`,children:(0,D.jsx)(v,{size:12})}):(0,D.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:()=>{qe(e)},disabled:r||i||a||o,"aria-busy":r,"aria-label":`Resume session ${e.title} in claude.ai/code`,title:`Resume in a fresh local Remote Control PTY`,children:(0,D.jsx)(g,{size:12})}),e.live?(0,D.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{Ze(t,e)},disabled:r||i||a||o,"aria-busy":a,"aria-label":`Stop session ${e.title}`,title:`Stop session process (keeps the conversation, can resume later)`,children:(0,D.jsx)(ae,{size:12})}):null,e.archived?(0,D.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{Qe(t,e,`unarchive`)},disabled:r||i||a||o,"aria-busy":o,"aria-label":`Unarchive session ${e.title}`,title:`Unarchive (move back to the active list)`,children:(0,D.jsx)(l,{size:12})}):(0,D.jsx)(`button`,{type:`button`,className:`conv-action`,onClick:t=>{Qe(t,e,`archive`)},disabled:r||i||a||o,"aria-busy":o,"aria-label":`Archive session ${e.title}`,title:`Archive (hide from the list, keeps the conversation resumable)`,children:(0,D.jsx)(u,{size:12})}),(0,D.jsx)(`button`,{type:`button`,className:`conv-action conv-action-danger`,onClick:t=>{Xe(t,e)},disabled:r||i||a||o,"aria-busy":i,"aria-label":`Delete session ${e.title}`,title:`Delete session (stops the process, removes the conversation)`,children:(0,D.jsx)(c,{size:12})})]})]},e.sessionId)})]})})(),k===`whatsapp`&&(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:`WhatsApp`}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh WhatsApp conversations`,"aria-label":`Refresh WhatsApp conversations`,onClick:Ke,disabled:Ie,children:(0,D.jsx)(w,{size:12,className:Ie?`spinning`:void 0})}),(0,D.jsx)(`span`,{children:Ie?`…`:String(Z.length)})]})]}),Pe&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:Pe}),Me&&!Pe&&Z.length===0&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No WhatsApp conversations`}),Z.map(e=>(0,D.jsxs)(`button`,{type:`button`,className:`conv${te===e.sessionId?` active`:``}`,onClick:()=>{S(e),b()},title:e.title,children:[(0,D.jsx)(ne,{size:14,className:`conv-icon`,"aria-hidden":`true`}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsx)(`span`,{className:`conv-name-line`,children:(0,D.jsx)(`span`,{className:`conv-name`,children:e.senderId??e.title})}),(0,D.jsx)(`span`,{className:`conv-timestamp`,children:e.title})]})]},e.sessionId))]}),(0,D.jsx)(ye,{}),(0,D.jsxs)(`div`,{className:`side-foot`,children:[(0,D.jsx)(`div`,{className:`avatar`,children:s?(0,D.jsx)(`img`,{src:s,alt:T}):O}),(0,D.jsxs)(`div`,{className:`who`,children:[(0,D.jsx)(`span`,{className:`name`,children:T}),(0,D.jsx)(`span`,{className:`role`,children:i??`operator`})]})]}),z&&(0,D.jsx)(`div`,{className:`copy-toast${z.failed?` copy-toast-failed`:``}`,role:`status`,children:z.message}),(0,D.jsx)(me,{error:le,onClose:()=>V(null)})]})}var ve=5e3;function ye(){let[e,t]=(0,E.useState)(null);if((0,E.useEffect)(()=>{let e=!1,n=null;async function r(){try{let n=await fetch(`/api/admin/system-stats`);if(!n.ok){console.error(`[admin-ui] system-stats-fetch-failed status=${n.status}`);return}let r=await n.json();e||t(r)}catch(e){console.error(`[admin-ui] system-stats-fetch-failed reason=${e instanceof Error?e.message:String(e)}`)}}function i(){n===null&&(r(),n=setInterval(()=>{r()},ve))}function a(){n!==null&&(clearInterval(n),n=null)}function o(){document.hidden?a():i()}return document.hidden||i(),document.addEventListener(`visibilitychange`,o),()=>{e=!0,a(),document.removeEventListener(`visibilitychange`,o)}},[]),!e||e.platform===`darwin`)return null;let n=e.cpuPct,r=e.memUsedPct,i=n!==null&&n>=.9,a=n!==null&&n>=.98,o=r!==null&&r>=.9,s=r!==null&&r>=.98,c=i||o,l=a||s,u=e=>e===null?`—`:`${Math.round(e*100)}%`,d=e=>{if(e===null)return{width:`0%`,background:`var(--text-tertiary)`};let t=Math.min(1,Math.max(0,e)),n=Math.round(140*(1-t));return{width:`${Math.round(t*100)}%`,background:`hsl(${n}, 65%, 45%)`}},f=[`system-stats`];return c&&f.push(`system-stats--warn`),l&&f.push(`system-stats--crit`),(0,D.jsxs)(`div`,{className:f.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,D.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,D.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),(0,D.jsx)(`div`,{className:`system-stats__bar`,children:(0,D.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(n)})})]}),(0,D.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,D.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]}),(0,D.jsx)(`div`,{className:`system-stats__bar`,children:(0,D.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(r)})})]})]})}var K=`admin-sidebar-collapsed`,q=`admin-sidebar-drawer-open`;function J(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(K)===`1`}catch{return!1}}function be(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(K,`1`):window.sessionStorage.removeItem(K)}catch{}}function xe(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(q)===`1`}catch{return!1}}function Se(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(q,`1`):window.sessionStorage.removeItem(q)}catch{}}var Y=720;function Ce(e){let{cacheKey:t,businessName:n,onLogout:r,userName:i,userAvatar:a,role:o,children:s,footer:c}=e,[l,u]=(0,E.useState)(()=>J()),[d,f]=(0,E.useState)(()=>xe()),[p,m]=(0,E.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: ${Y}px)`).matches),[h,g]=(0,E.useState)(null);(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: ${Y}px)`),t=e=>m(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let _=(0,E.useCallback)(e=>{be(e),u(e)},[]),v=(0,E.useCallback)(e=>{Se(e),f(e)},[]);(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} collapsed=${l} drawer=${d}`)},[]);let ee=p?d:!l,y=(0,E.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${Y}px)`).matches){let e=d;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),v(!e)}else{let e=l;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),_(!e)}},[l,d,_,v]),b=(0,E.useCallback)(e=>{console.info(`[admin-ui] header-menu-nav target=${e}`);let t=e===`data`?`/data`:e===`graph`?`/graph`:`/browser`;window.location.href=t},[]),x={collapsed:l,mobileDrawerOpen:d,sidebarOpen:ee,onToggleSidebar:y,setMobileDrawerOpen:v,selectedWhatsapp:h,onClearWhatsapp:()=>g(null)};return(0,D.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,D.jsx)(H,{businessName:n,onNavigate:b,onToggleSidebar:y,sidebarOpen:ee,onLogout:r}),(0,D.jsxs)(`div`,{className:`platform${d?` menu-open`:``}${l?` sidebar-collapsed`:``}`,"data-artefact":`closed`,children:[(0,D.jsx)(G,{businessName:n,cacheKey:t,role:o??null,userName:i,userAvatar:a??null,onSelectProjects:()=>{window.location.href=`/graph?label=Project`},onSelectPeople:()=>{window.location.href=`/graph?label=Person`},onSelectTasks:()=>{window.location.href=`/graph?label=Task`},onSelectAgents:()=>{window.location.href=`/graph?label=Agent`},onCloseMobileDrawer:()=>v(!1),collapsed:l,mobileDrawerOpen:d,selectedWhatsappId:h?.sessionId??null,onSelectWhatsappConversation:g}),typeof s==`function`?s(x):s]}),d&&(0,D.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>v(!1)}),c]})}export{ue as a,T as c,re as d,b as f,m as g,h,le as i,ie as l,g as m,W as n,z as o,_ as p,de as r,se as s,Ce as t,w as u};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CnGqDkHZ.js";import{c as t,l as n,m as r,p as i,r as a,s as o}from"./useSelectionMode-BPzPjKP_.js";import{f as s,i as c,n as l,s as u,t as d}from"./AdminShell-FO766lOW.js";import{t as f}from"./Checkbox-syHoU9nY.js";var p=i(),m=e(r(),1);new Set(`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,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`.split(`,`).filter(e=>!e.startsWith(`.`)));function h(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}var g=`admin-landing-redirected`,_=`/graph`;function v(e){return e.appState===`chat`&&!e.alreadyRedirected}function y(){let[e,t]=(0,m.useState)(`loading`),[n,r]=(0,m.useState)(``),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),[D,O]=(0,m.useState)(void 0),[k,A]=(0,m.useState)(null),[j,M]=(0,m.useState)(void 0),[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(null),[L,R]=(0,m.useState)([]),[z,B]=(0,m.useState)(!1),[V,H]=(0,m.useState)(void 0),U=(0,m.useRef)(void 0),[W,G]=(0,m.useState)(!1);(0,m.useEffect)(()=>{typeof window>`u`||fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&G(!0)}).catch(()=>{})},[]);let K=(0,m.useRef)(null),q=(0,m.useRef)(null);(0,m.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let n=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(n.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!n.ok)return!1;let r=await n.json();w(r.session_key),I(r.sessionId??null),O(r.businessName),A(r.role??null),M(r.userName===void 0?null:r.userName),P(r.avatar??null);let i=h(r.thinkingView);return U.current=i,H(i),t(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function n(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check returned ${i.status} after retries`),t(`set-pin`);return}let a=await i.json();if(!a.pin_configured){t(`set-pin`);return}if(!a.claude_authenticated){t(`connect-claude`);return}if(await e())return;t(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check failed:`,e),t(`set-pin`)}}n()},[]),(0,m.useEffect)(()=>{e===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&E(e)}).catch(()=>{})},[e]),(0,m.useEffect)(()=>{if(typeof window>`u`)return;let t=!1;try{t=sessionStorage.getItem(g)===`1`}catch{}if(v({appState:e,alreadyRedirected:t})){try{sessionStorage.setItem(g,`1`)}catch{}console.info(`[admin-ui] landing-redirect target=${_}`),window.location.replace(_)}},[e]);let J=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(e!==`chat`)return;let n=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let n=await e.json();if(n.auth_status===`dead`||n.auth_status===`missing`){t(`connect-claude`);return}}}catch{}if(C)try{let e=await fetch(`/api/admin/session?session_key=${encodeURIComponent(C)}`);if(e.status!==401)return;let t=(await e.clone().json().catch(()=>null))?.code??`unknown-401`;console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),J.current?.()}catch{}},300*1e3);return()=>clearInterval(n)},[e,C]),(0,m.useEffect)(()=>{e===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&t(`enter-pin`)}).catch(()=>{})},[e]);async function Y(e,n){d(!0);try{let i=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...n?{accountId:n}:{}})});if(!i.ok){s((await i.json().catch(()=>({}))).error||`Invalid PIN`);return}let a=await i.json();if(a.accounts&&!a.session_key){console.log(`[admin] account picker shown: userId=${a.userId} accountCount=${a.accounts.length}`),R(a.accounts),t(`account-picker`);return}w(a.session_key),I(a.sessionId??null),O(a.businessName),A(a.role??null),M(a.userName===void 0?null:a.userName),P(a.avatar??null);let o=h(a.thinkingView);if(U.current=o,H(o),n)try{sessionStorage.setItem(`maxy-account-id`,n)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,a.session_key)}catch{}r(``),t(`chat`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1),B(!1)}}let X=(0,m.useCallback)(async e=>{if(e.preventDefault(),u)return;s(``);let a=i.trim();if(!a){s(`Please enter your name.`);return}if(n.length<4){s(`PIN must be at least 4 characters.`);return}let o=n;d(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:o,name:a})});if(!e.ok){let n=await e.json().catch(()=>({}));if(e.status===409){console.log(`[admin] PIN already configured — re-checking health`);try{let e=await fetch(`/api/health`);if(e.ok){let r=await e.json();r.pin_configured&&r.claude_authenticated?t(`enter-pin`):r.pin_configured?t(`connect-claude`):s(n.error||`Failed to set PIN.`)}else t(`enter-pin`)}catch{t(`enter-pin`)}return}s(n.error||`Failed to set PIN.`);return}let n=await fetch(`/api/health`);if((n.ok?await n.json():null)?.claude_authenticated){await Y(o);return}r(``),t(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1)}},[n,u,i]),Z=(0,m.useCallback)(async e=>{e.preventDefault(),s(``),await Y(n)},[n]),Q=(0,m.useCallback)(async()=>{S(!0);try{await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})}),w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}t(`connect-claude`)}finally{S(!1)}},[]),$=(0,m.useCallback)(()=>{w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(g)}catch{}r(``),s(``),t(`enter-pin`)},[]);return(0,m.useEffect)(()=>{J.current=$},[$]),{appState:e,setAppState:t,pin:n,setPin:r,operatorName:i,setOperatorName:a,pinError:o,setPinError:s,showPin:c,setShowPin:l,pinLoading:u,authPolling:f,setAuthPolling:p,authLoading:y,setAuthLoading:b,disconnecting:x,cacheKey:C,setCacheKey:w,claudeInfo:T,setClaudeInfo:E,businessName:D,role:k,userName:j,userAvatar:N,sessionId:F,setSessionId:I,accounts:L,accountPickerLoading:z,expandAll:V,setExpandAll:H,expandAllDefaultRef:U,remoteAuthEnabled:W,pinInputRef:K,setPinFormRef:q,handleSetPin:X,handleLogin:Z,handleAccountSelect:(0,m.useCallback)(async e=>{B(!0),s(``),await Y(n,e)},[n]),handleDisconnect:Q,handleLogout:$,handleChangePin:(0,m.useCallback)(async()=>{if(!n){s(`Enter your current PIN first.`);return}d(!0),s(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:n})});if(!e.ok){s((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}r(``),s(``),t(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),s(e instanceof Error?e.message:String(e))}finally{d(!1)}},[n])}}var b=n();function x({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,m.useRef)([]);function s(e,r){r.key===`Backspace`?(r.preventDefault(),t[e]?n(t.slice(0,e)+t.slice(e+1)):e>0&&(n(t.slice(0,e-1)+t.slice(e)),o.current[e-1]?.focus())):r.key===`ArrowLeft`&&e>0?o.current[e-1]?.focus():r.key===`ArrowRight`&&e<5?o.current[e+1]?.focus():r.key===`Enter`&&(r.preventDefault(),r.currentTarget.form?.requestSubmit())}function c(e,i){let a=i.nativeEvent.data;if(!a||!/^\d$/.test(a))return;let s=t.split(``);for(s[e]=a;s.length<e;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);n(c),c.length===6?r?.(c):e<5&&o.current[e+1]?.focus()}function l(e){e.preventDefault();let t=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);t&&(n(t),t.length===6?r?.(t):o.current[t.length]?.focus())}return(0,b.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,b.jsx)(`input`,{ref:t=>{o.current[r]=t,r===0&&e&&(e.current=t)},type:`text`,inputMode:`numeric`,className:`pin-box${t[r]?` pin-box-filled`:``}`,value:t[r]?i?t[r]:`•`:``,onKeyDown:e=>s(r,e),onInput:e=>c(r,e),onPaste:l,onFocus:e=>e.target.select(),autoFocus:a&&r===0,autoComplete:`off`,maxLength:1,"aria-label":`PIN digit ${r+1}`},r))})}function S(e){let{pin:n,setPin:r,showPin:i,setShowPin:s,pinLoading:c,pinError:l,pinInputRef:u,setPinFormRef:d,onSubmit:p,operatorName:m,setOperatorName:h}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,a.productName]}),(0,b.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,a.productName,` who you are, then choose a PIN.`]}),(0,b.jsxs)(`form`,{ref:d,onSubmit:p,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:m,onChange:e=>h(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,b.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:u,value:n,onChange:r,onComplete:()=>{},showPin:i}),(0,b.jsx)(t,{variant:`send`,type:`submit`,disabled:!n||!m.trim(),loading:c,"aria-label":`Set PIN`,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsx)(f,{checked:i,onChange:()=>s(e=>!e),label:`Show PIN`})]}),l&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:l})]})})}function C(e){let{pin:n,setPin:r,showPin:i,setShowPin:s,pinLoading:c,pinError:l,pinInputRef:u,onSubmit:d,onChangePin:p,remoteAuthEnabled:m,onSignOutRemote:h}=e;return(0,b.jsxs)(`div`,{className:`connect-page`,children:[m&&h&&(0,b.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:a.productName}),(0,b.jsxs)(`form`,{onSubmit:d,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:u,value:n,onChange:r,onComplete:()=>{},showPin:i,autoFocus:!0}),(0,b.jsx)(t,{variant:`send`,type:`submit`,disabled:!n,loading:c,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsxs)(`div`,{className:`pin-options`,children:[(0,b.jsx)(f,{checked:i,onChange:()=>s(e=>!e),label:`Show PIN`}),(0,b.jsx)(t,{type:`button`,variant:`ghost`,onClick:p,children:`Change PIN`})]})]}),l&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:l})]})]})}function w(e){let{accounts:t,loading:n,error:r,onSelect:i}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:a.productName}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,b.jsx)(`div`,{className:`account-picker-list`,children:t.map(e=>(0,b.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>i(e.accountId),disabled:n,type:`button`,children:[(0,b.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,b.jsx)(`span`,{className:`account-picker-role`,children:e.role}),n&&(0,b.jsx)(s,{className:`account-picker-spinner`,size:16})]},e.accountId))}),r&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:r})]})})}function T(e){let{authPolling:n,setAuthPolling:r,authLoading:i,setAuthLoading:s,pinError:c,setPinError:l,setAppState:u}=e,[d,f]=(0,m.useState)(!1),[p,h]=(0,m.useState)(!1);async function g(){h(!0),l(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`launch-browser`})})).json();e.launched?f(!0):e.error&&l(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),l(`Could not launch browser.`)}h(!1)}async function _(){s(!0),l(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){r(!0),f(!0),s(!1);for(let e=0;e<120;e++)if(await new Promise(e=>setTimeout(e,2e3)),(await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`wait`})})).json()).authenticated){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),u(`enter-pin`);return}l(`Timed out waiting for sign-in. Try again.`),r(!1)}else e.error&&l(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),l(`Could not start auth flow.`)}s(!1)}async function v(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),r(!1),l(``)}return n||d?(0,b.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,b.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[n?(0,b.jsx)(`button`,{onClick:v,style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Cancel`,children:`✕`}):(0,b.jsx)(`button`,{onClick:()=>f(!1),style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Close browser`,children:`✕`}),(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,b.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,b.jsx)(`p`,{className:`chat-intro`,children:n?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!n&&(0,b.jsx)(`div`,{style:{marginTop:`12px`},children:(0,b.jsx)(t,{variant:`primary`,onClick:_,disabled:i,children:i?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,b.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,b.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:c})]}):(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsxs)(`div`,{className:`connect-logos`,children:[(0,b.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,b.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,b.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,b.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`span`,{className:`connect-logo-label`,children:a.productName})]})]}),(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,a.productName]}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,b.jsx)(t,{variant:`primary`,onClick:_,disabled:i,children:i?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,b.jsx)(`p`,{style:{marginTop:`6px`,fontSize:`11px`,color:`#999`,maxWidth:`300px`,textAlign:`center`,lineHeight:`1.4`},children:`First time? You may need to sign into your email and Anthropic account in the browser before connecting.`}),(0,b.jsx)(`button`,{onClick:g,disabled:p,style:{marginTop:`12px`,background:`none`,border:`none`,color:`var(--color-primary, #666)`,fontSize:`13px`,cursor:`pointer`,textDecoration:`underline`,textUnderlineOffset:`3px`},children:p?`Launching…`:`Open browser first`}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:c})]})})}function E({onOpen:e}){return(0,b.jsx)(`footer`,{className:`admin-footer`,children:(0,b.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,b.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function D(e,t,n){let[r,i]=(0,m.useState)([]),[a,o]=(0,m.useState)(`open`);return(0,m.useEffect)(()=>{i([]),o(`open`);let r=`/api/whatsapp-reader/stream?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,a=new EventSource(r);return a.onmessage=e=>{try{i(t=>[...t,JSON.parse(e.data)])}catch{}},a.onerror=()=>o(`error`),()=>a.close()},[e,t,n]),{turns:r,status:a}}function O(e){return e.map((e,t)=>{switch(e.kind){case`operator-inbound`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:`Operator`}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`operator-typed`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:`Operator (web)`}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-text`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:`Agent`}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`tool-call`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-tool`,children:[(0,b.jsxs)(`span`,{className:`wa-who`,children:[`↳ `,e.name]}),(0,b.jsx)(`pre`,{className:`wa-code`,children:JSON.stringify(e.input,null,2)})]},t);case`tool-result`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-result${e.isError?` is-error`:``}`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:`result`}),(0,b.jsx)(`pre`,{className:`wa-code`,children:e.text})]},t)}})}function k({sessionId:e,projectDir:t,sessionKey:n}){let{turns:r,status:i}=D(e,t,n);return(0,b.jsxs)(`div`,{className:`wa-thread-scroll`,children:[i===`error`&&(0,b.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),r.length===0&&i===`open`&&(0,b.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),O(r)]})}function A(){let e=y(),[t,n]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,m.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();try{let t=await fetch(`/api/admin/claude-info`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,m.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`loading`?(0,b.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,b.jsx)(S,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`connect-claude`?(0,b.jsx)(T,{authPolling:e.authPolling,setAuthPolling:e.setAuthPolling,authLoading:e.authLoading,setAuthLoading:e.setAuthLoading,pinError:e.pinError,setPinError:e.setPinError,setAppState:e.setAppState}):e.appState===`enter-pin`?(0,b.jsx)(C,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,onSubmit:e.handleLogin,onChangePin:e.handleChangePin,remoteAuthEnabled:e.remoteAuthEnabled,onSignOutRemote:e.handleLogout}):e.appState===`account-picker`?(0,b.jsx)(w,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):(0,b.jsx)(c,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,b.jsx)(d,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(E,{onOpen:r}),(0,b.jsx)(l,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(u,{}),t.selectedWhatsapp&&e.cacheKey?(0,b.jsx)(k,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey},t.selectedWhatsapp.sessionId):(0,b.jsx)(`main`,{})]})})})}(0,p.createRoot)(document.getElementById(`root`)).render((0,b.jsx)(A,{}));
1
+ import{o as e}from"./chunk-CnGqDkHZ.js";import{c as t,l as n,m as r,p as i,r as a,s as o}from"./useSelectionMode-BPzPjKP_.js";import{f as s,i as c,n as l,s as u,t as d}from"./AdminShell-8Y7-maNi.js";import{t as f}from"./Checkbox-syHoU9nY.js";var p=i(),m=e(r(),1);new Set(`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,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`.split(`,`).filter(e=>!e.startsWith(`.`)));function h(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}var g=`admin-landing-redirected`,_=`/graph`;function v(e){return e.appState===`chat`&&!e.alreadyRedirected}function y(){let[e,t]=(0,m.useState)(`loading`),[n,r]=(0,m.useState)(``),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),[D,O]=(0,m.useState)(void 0),[k,A]=(0,m.useState)(null),[j,M]=(0,m.useState)(void 0),[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(null),[L,R]=(0,m.useState)([]),[z,B]=(0,m.useState)(!1),[V,H]=(0,m.useState)(void 0),U=(0,m.useRef)(void 0),[W,G]=(0,m.useState)(!1);(0,m.useEffect)(()=>{typeof window>`u`||fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&G(!0)}).catch(()=>{})},[]);let K=(0,m.useRef)(null),q=(0,m.useRef)(null);(0,m.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let n=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(n.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!n.ok)return!1;let r=await n.json();w(r.session_key),I(r.sessionId??null),O(r.businessName),A(r.role??null),M(r.userName===void 0?null:r.userName),P(r.avatar??null);let i=h(r.thinkingView);return U.current=i,H(i),t(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function n(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check returned ${i.status} after retries`),t(`set-pin`);return}let a=await i.json();if(!a.pin_configured){t(`set-pin`);return}if(!a.claude_authenticated){t(`connect-claude`);return}if(await e())return;t(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check failed:`,e),t(`set-pin`)}}n()},[]),(0,m.useEffect)(()=>{e===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&E(e)}).catch(()=>{})},[e]),(0,m.useEffect)(()=>{if(typeof window>`u`)return;let t=!1;try{t=sessionStorage.getItem(g)===`1`}catch{}if(v({appState:e,alreadyRedirected:t})){try{sessionStorage.setItem(g,`1`)}catch{}console.info(`[admin-ui] landing-redirect target=${_}`),window.location.replace(_)}},[e]);let J=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(e!==`chat`)return;let n=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let n=await e.json();if(n.auth_status===`dead`||n.auth_status===`missing`){t(`connect-claude`);return}}}catch{}if(C)try{let e=await fetch(`/api/admin/session?session_key=${encodeURIComponent(C)}`);if(e.status!==401)return;let t=(await e.clone().json().catch(()=>null))?.code??`unknown-401`;console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),J.current?.()}catch{}},300*1e3);return()=>clearInterval(n)},[e,C]),(0,m.useEffect)(()=>{e===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&t(`enter-pin`)}).catch(()=>{})},[e]);async function Y(e,n){d(!0);try{let i=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...n?{accountId:n}:{}})});if(!i.ok){s((await i.json().catch(()=>({}))).error||`Invalid PIN`);return}let a=await i.json();if(a.accounts&&!a.session_key){console.log(`[admin] account picker shown: userId=${a.userId} accountCount=${a.accounts.length}`),R(a.accounts),t(`account-picker`);return}w(a.session_key),I(a.sessionId??null),O(a.businessName),A(a.role??null),M(a.userName===void 0?null:a.userName),P(a.avatar??null);let o=h(a.thinkingView);if(U.current=o,H(o),n)try{sessionStorage.setItem(`maxy-account-id`,n)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,a.session_key)}catch{}r(``),t(`chat`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1),B(!1)}}let X=(0,m.useCallback)(async e=>{if(e.preventDefault(),u)return;s(``);let a=i.trim();if(!a){s(`Please enter your name.`);return}if(n.length<4){s(`PIN must be at least 4 characters.`);return}let o=n;d(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:o,name:a})});if(!e.ok){let n=await e.json().catch(()=>({}));if(e.status===409){console.log(`[admin] PIN already configured — re-checking health`);try{let e=await fetch(`/api/health`);if(e.ok){let r=await e.json();r.pin_configured&&r.claude_authenticated?t(`enter-pin`):r.pin_configured?t(`connect-claude`):s(n.error||`Failed to set PIN.`)}else t(`enter-pin`)}catch{t(`enter-pin`)}return}s(n.error||`Failed to set PIN.`);return}let n=await fetch(`/api/health`);if((n.ok?await n.json():null)?.claude_authenticated){await Y(o);return}r(``),t(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1)}},[n,u,i]),Z=(0,m.useCallback)(async e=>{e.preventDefault(),s(``),await Y(n)},[n]),Q=(0,m.useCallback)(async()=>{S(!0);try{await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})}),w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}t(`connect-claude`)}finally{S(!1)}},[]),$=(0,m.useCallback)(()=>{w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(g)}catch{}r(``),s(``),t(`enter-pin`)},[]);return(0,m.useEffect)(()=>{J.current=$},[$]),{appState:e,setAppState:t,pin:n,setPin:r,operatorName:i,setOperatorName:a,pinError:o,setPinError:s,showPin:c,setShowPin:l,pinLoading:u,authPolling:f,setAuthPolling:p,authLoading:y,setAuthLoading:b,disconnecting:x,cacheKey:C,setCacheKey:w,claudeInfo:T,setClaudeInfo:E,businessName:D,role:k,userName:j,userAvatar:N,sessionId:F,setSessionId:I,accounts:L,accountPickerLoading:z,expandAll:V,setExpandAll:H,expandAllDefaultRef:U,remoteAuthEnabled:W,pinInputRef:K,setPinFormRef:q,handleSetPin:X,handleLogin:Z,handleAccountSelect:(0,m.useCallback)(async e=>{B(!0),s(``),await Y(n,e)},[n]),handleDisconnect:Q,handleLogout:$,handleChangePin:(0,m.useCallback)(async()=>{if(!n){s(`Enter your current PIN first.`);return}d(!0),s(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:n})});if(!e.ok){s((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}r(``),s(``),t(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),s(e instanceof Error?e.message:String(e))}finally{d(!1)}},[n])}}var b=n();function x({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,m.useRef)([]);function s(e,r){r.key===`Backspace`?(r.preventDefault(),t[e]?n(t.slice(0,e)+t.slice(e+1)):e>0&&(n(t.slice(0,e-1)+t.slice(e)),o.current[e-1]?.focus())):r.key===`ArrowLeft`&&e>0?o.current[e-1]?.focus():r.key===`ArrowRight`&&e<5?o.current[e+1]?.focus():r.key===`Enter`&&(r.preventDefault(),r.currentTarget.form?.requestSubmit())}function c(e,i){let a=i.nativeEvent.data;if(!a||!/^\d$/.test(a))return;let s=t.split(``);for(s[e]=a;s.length<e;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);n(c),c.length===6?r?.(c):e<5&&o.current[e+1]?.focus()}function l(e){e.preventDefault();let t=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);t&&(n(t),t.length===6?r?.(t):o.current[t.length]?.focus())}return(0,b.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,b.jsx)(`input`,{ref:t=>{o.current[r]=t,r===0&&e&&(e.current=t)},type:`text`,inputMode:`numeric`,className:`pin-box${t[r]?` pin-box-filled`:``}`,value:t[r]?i?t[r]:`•`:``,onKeyDown:e=>s(r,e),onInput:e=>c(r,e),onPaste:l,onFocus:e=>e.target.select(),autoFocus:a&&r===0,autoComplete:`off`,maxLength:1,"aria-label":`PIN digit ${r+1}`},r))})}function S(e){let{pin:n,setPin:r,showPin:i,setShowPin:s,pinLoading:c,pinError:l,pinInputRef:u,setPinFormRef:d,onSubmit:p,operatorName:m,setOperatorName:h}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,a.productName]}),(0,b.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,a.productName,` who you are, then choose a PIN.`]}),(0,b.jsxs)(`form`,{ref:d,onSubmit:p,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:m,onChange:e=>h(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,b.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:u,value:n,onChange:r,onComplete:()=>{},showPin:i}),(0,b.jsx)(t,{variant:`send`,type:`submit`,disabled:!n||!m.trim(),loading:c,"aria-label":`Set PIN`,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsx)(f,{checked:i,onChange:()=>s(e=>!e),label:`Show PIN`})]}),l&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:l})]})})}function C(e){let{pin:n,setPin:r,showPin:i,setShowPin:s,pinLoading:c,pinError:l,pinInputRef:u,onSubmit:d,onChangePin:p,remoteAuthEnabled:m,onSignOutRemote:h}=e;return(0,b.jsxs)(`div`,{className:`connect-page`,children:[m&&h&&(0,b.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:a.productName}),(0,b.jsxs)(`form`,{onSubmit:d,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:u,value:n,onChange:r,onComplete:()=>{},showPin:i,autoFocus:!0}),(0,b.jsx)(t,{variant:`send`,type:`submit`,disabled:!n,loading:c,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsxs)(`div`,{className:`pin-options`,children:[(0,b.jsx)(f,{checked:i,onChange:()=>s(e=>!e),label:`Show PIN`}),(0,b.jsx)(t,{type:`button`,variant:`ghost`,onClick:p,children:`Change PIN`})]})]}),l&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:l})]})]})}function w(e){let{accounts:t,loading:n,error:r,onSelect:i}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:a.productName}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,b.jsx)(`div`,{className:`account-picker-list`,children:t.map(e=>(0,b.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>i(e.accountId),disabled:n,type:`button`,children:[(0,b.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,b.jsx)(`span`,{className:`account-picker-role`,children:e.role}),n&&(0,b.jsx)(s,{className:`account-picker-spinner`,size:16})]},e.accountId))}),r&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:r})]})})}function T(e){let{authPolling:n,setAuthPolling:r,authLoading:i,setAuthLoading:s,pinError:c,setPinError:l,setAppState:u}=e,[d,f]=(0,m.useState)(!1),[p,h]=(0,m.useState)(!1);async function g(){h(!0),l(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`launch-browser`})})).json();e.launched?f(!0):e.error&&l(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),l(`Could not launch browser.`)}h(!1)}async function _(){s(!0),l(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){r(!0),f(!0),s(!1);for(let e=0;e<120;e++)if(await new Promise(e=>setTimeout(e,2e3)),(await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`wait`})})).json()).authenticated){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),u(`enter-pin`);return}l(`Timed out waiting for sign-in. Try again.`),r(!1)}else e.error&&l(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),l(`Could not start auth flow.`)}s(!1)}async function v(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),r(!1),l(``)}return n||d?(0,b.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,b.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[n?(0,b.jsx)(`button`,{onClick:v,style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Cancel`,children:`✕`}):(0,b.jsx)(`button`,{onClick:()=>f(!1),style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Close browser`,children:`✕`}),(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,b.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,b.jsx)(`p`,{className:`chat-intro`,children:n?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!n&&(0,b.jsx)(`div`,{style:{marginTop:`12px`},children:(0,b.jsx)(t,{variant:`primary`,onClick:_,disabled:i,children:i?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,b.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,b.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:c})]}):(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsxs)(`div`,{className:`connect-logos`,children:[(0,b.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,b.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,b.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,b.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,b.jsx)(`img`,{src:o,alt:a.productName,className:`connect-logo connect-logo--maxy`}),!a.logoContainsName&&(0,b.jsx)(`span`,{className:`connect-logo-label`,children:a.productName})]})]}),(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,a.productName]}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,b.jsx)(t,{variant:`primary`,onClick:_,disabled:i,children:i?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,b.jsx)(`p`,{style:{marginTop:`6px`,fontSize:`11px`,color:`#999`,maxWidth:`300px`,textAlign:`center`,lineHeight:`1.4`},children:`First time? You may need to sign into your email and Anthropic account in the browser before connecting.`}),(0,b.jsx)(`button`,{onClick:g,disabled:p,style:{marginTop:`12px`,background:`none`,border:`none`,color:`var(--color-primary, #666)`,fontSize:`13px`,cursor:`pointer`,textDecoration:`underline`,textUnderlineOffset:`3px`},children:p?`Launching…`:`Open browser first`}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:c})]})})}function E({onOpen:e}){return(0,b.jsx)(`footer`,{className:`admin-footer`,children:(0,b.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,b.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function D(e,t,n){let[r,i]=(0,m.useState)([]),[a,o]=(0,m.useState)(`open`);return(0,m.useEffect)(()=>{i([]),o(`open`);let r=`/api/whatsapp-reader/stream?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,a=new EventSource(r);return a.onmessage=e=>{try{i(t=>[...t,JSON.parse(e.data)])}catch{}},a.onerror=()=>o(`error`),()=>a.close()},[e,t,n]),{turns:r,status:a}}function O(e){return e.map((e,t)=>{switch(e.kind){case`operator-inbound`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:`Operator`}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`operator-typed`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:`Operator (web)`}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-text`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:`Agent`}),(0,b.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`tool-call`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-tool`,children:[(0,b.jsxs)(`span`,{className:`wa-who`,children:[`↳ `,e.name]}),(0,b.jsx)(`pre`,{className:`wa-code`,children:JSON.stringify(e.input,null,2)})]},t);case`tool-result`:return(0,b.jsxs)(`div`,{className:`wa-turn wa-turn-result${e.isError?` is-error`:``}`,children:[(0,b.jsx)(`span`,{className:`wa-who`,children:`result`}),(0,b.jsx)(`pre`,{className:`wa-code`,children:e.text})]},t)}})}function k({sessionId:e,projectDir:t,sessionKey:n}){let{turns:r,status:i}=D(e,t,n);return(0,b.jsxs)(`div`,{className:`wa-thread-scroll`,children:[i===`error`&&(0,b.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),r.length===0&&i===`open`&&(0,b.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),O(r)]})}function A(){let e=y(),[t,n]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,m.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();try{let t=await fetch(`/api/admin/claude-info`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,m.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`loading`?(0,b.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,b.jsx)(S,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`connect-claude`?(0,b.jsx)(T,{authPolling:e.authPolling,setAuthPolling:e.setAuthPolling,authLoading:e.authLoading,setAuthLoading:e.setAuthLoading,pinError:e.pinError,setPinError:e.setPinError,setAppState:e.setAppState}):e.appState===`enter-pin`?(0,b.jsx)(C,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,onSubmit:e.handleLogin,onChangePin:e.handleChangePin,remoteAuthEnabled:e.remoteAuthEnabled,onSignOutRemote:e.handleLogout}):e.appState===`account-picker`?(0,b.jsx)(w,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):(0,b.jsx)(c,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,b.jsx)(d,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(E,{onOpen:r}),(0,b.jsx)(l,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(u,{}),t.selectedWhatsapp&&e.cacheKey?(0,b.jsx)(k,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey},t.selectedWhatsapp.sessionId):(0,b.jsx)(`main`,{})]})})})}(0,p.createRoot)(document.getElementById(`root`)).render((0,b.jsx)(A,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CnGqDkHZ.js";import{f as t,l as n,m as r,p as i,r as a}from"./useSelectionMode-BPzPjKP_.js";import{a as o,f as s,i as c,m as l,p as u,s as d,t as f}from"./AdminShell-FO766lOW.js";var p=t(`monitor-play`,[[`path`,{d:`M15.033 9.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56V7.648a.645.645 0 0 1 .967-.56z`,key:`vbtd3f`}],[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}],[`rect`,{x:`2`,y:`3`,width:`20`,height:`14`,rx:`2`,key:`x3v2xh`}]]),m=i(),h=e(r(),1),g=n(),_=`maxy-vnc-popout`;function v(){let[e,t]=(0,h.useState)(null),[n,r]=(0,h.useState)(!1),[i,c]=(0,h.useState)(null),d=o(null);(0,h.useEffect)(()=>{let e=!1;return fetch(`/vnc-viewer.html`,{method:`HEAD`}).then(n=>{e||(console.info(`[browser-page] op=viewer-probe available=${n.ok}`),t(n.ok))}).catch(()=>{e||(console.info(`[browser-page] op=viewer-probe available=false`),t(!1))}),()=>{e=!0}},[]);let f=(0,h.useCallback)(()=>{window.open(`/vnc-popout.html?title=${encodeURIComponent(a.productName)}`,_,`width=1024,height=768`)},[]),m=(0,h.useCallback)(async()=>{r(!0),c(null);try{let e=await d(`/api/admin/browser/launch`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Launch failed (${e.status})`)}}catch(e){c(e instanceof Error?e.message:String(e))}finally{r(!1)}},[d]);return e===null?(0,g.jsx)(`div`,{className:`vnc-surface`,children:(0,g.jsxs)(`div`,{className:`data-loading`,children:[(0,g.jsx)(s,{size:18,className:`spin`}),` Checking viewer…`]})}):e?(0,g.jsxs)(`div`,{className:`vnc-surface`,children:[(0,g.jsxs)(`div`,{className:`vnc-surface__toolbar`,children:[(0,g.jsxs)(`button`,{type:`button`,className:`vnc-surface__btn`,onClick:m,disabled:n,children:[n?(0,g.jsx)(s,{size:14,className:`spin`}):(0,g.jsx)(u,{size:14}),` Launch browser`]}),(0,g.jsxs)(`button`,{type:`button`,className:`vnc-surface__btn`,onClick:f,children:[(0,g.jsx)(l,{size:14}),` Pop out`]}),i&&(0,g.jsx)(`span`,{className:`vnc-surface__error`,children:i})]}),(0,g.jsx)(`iframe`,{className:`vnc-surface__iframe`,src:`/vnc-viewer.html`,title:`VNC viewer`})]}):(0,g.jsx)(`div`,{className:`vnc-surface`,children:(0,g.jsxs)(`div`,{className:`vnc-surface__unavailable`,children:[(0,g.jsx)(p,{size:20}),(0,g.jsx)(`p`,{children:`VNC surface not available on this platform.`})]})})}function y(){let[e,t]=(0,h.useState)(null),[n,r]=(0,h.useState)(!1),[i,a]=(0,h.useState)(void 0),[o,l]=(0,h.useState)(null),[p,m]=(0,h.useState)(void 0),[_,y]=(0,h.useState)(null),[b,x]=(0,h.useState)(null);(0,h.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),x(e.role??null),m(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let S=(0,h.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]);return n?e?(0,g.jsx)(c,{cacheKey:e,surface:`browser`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=browser`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,g.jsxs)(f,{cacheKey:e,businessName:i,sessionId:o,onLogout:S,userName:p,userAvatar:_,role:b,children:[(0,g.jsx)(d,{}),(0,g.jsxs)(`div`,{className:`data-page`,children:[(0,g.jsx)(`header`,{className:`data-header`,children:(0,g.jsxs)(`h1`,{className:`data-title`,children:[(0,g.jsx)(u,{size:18}),` Browser`]})}),(0,g.jsx)(v,{})]})]})}):(0,g.jsxs)(`div`,{className:`data-page`,children:[(0,g.jsx)(`header`,{className:`data-header`,children:(0,g.jsxs)(`h1`,{className:`data-title`,children:[(0,g.jsx)(u,{size:18}),` Browser`]})}),(0,g.jsxs)(`div`,{className:`data-empty`,children:[(0,g.jsx)(`p`,{children:`You are not signed in.`}),(0,g.jsxs)(`p`,{children:[`Open the `,(0,g.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,g.jsx)(`div`,{className:`data-page`,children:(0,g.jsxs)(`div`,{className:`data-loading`,children:[(0,g.jsx)(s,{size:18,className:`spin`}),` Loading…`]})})}(0,m.createRoot)(document.getElementById(`root`)).render((0,g.jsx)(y,{}));
1
+ import{o as e}from"./chunk-CnGqDkHZ.js";import{f as t,l as n,m as r,p as i,r as a}from"./useSelectionMode-BPzPjKP_.js";import{a as o,f as s,i as c,m as l,p as u,s as d,t as f}from"./AdminShell-8Y7-maNi.js";var p=t(`monitor-play`,[[`path`,{d:`M15.033 9.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56V7.648a.645.645 0 0 1 .967-.56z`,key:`vbtd3f`}],[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}],[`rect`,{x:`2`,y:`3`,width:`20`,height:`14`,rx:`2`,key:`x3v2xh`}]]),m=i(),h=e(r(),1),g=n(),_=`maxy-vnc-popout`;function v(){let[e,t]=(0,h.useState)(null),[n,r]=(0,h.useState)(!1),[i,c]=(0,h.useState)(null),d=o(null);(0,h.useEffect)(()=>{let e=!1;return fetch(`/vnc-viewer.html`,{method:`HEAD`}).then(n=>{e||(console.info(`[browser-page] op=viewer-probe available=${n.ok}`),t(n.ok))}).catch(()=>{e||(console.info(`[browser-page] op=viewer-probe available=false`),t(!1))}),()=>{e=!0}},[]);let f=(0,h.useCallback)(()=>{window.open(`/vnc-popout.html?title=${encodeURIComponent(a.productName)}`,_,`width=1024,height=768`)},[]),m=(0,h.useCallback)(async()=>{r(!0),c(null);try{let e=await d(`/api/admin/browser/launch`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Launch failed (${e.status})`)}}catch(e){c(e instanceof Error?e.message:String(e))}finally{r(!1)}},[d]);return e===null?(0,g.jsx)(`div`,{className:`vnc-surface`,children:(0,g.jsxs)(`div`,{className:`data-loading`,children:[(0,g.jsx)(s,{size:18,className:`spin`}),` Checking viewer…`]})}):e?(0,g.jsxs)(`div`,{className:`vnc-surface`,children:[(0,g.jsxs)(`div`,{className:`vnc-surface__toolbar`,children:[(0,g.jsxs)(`button`,{type:`button`,className:`vnc-surface__btn`,onClick:m,disabled:n,children:[n?(0,g.jsx)(s,{size:14,className:`spin`}):(0,g.jsx)(u,{size:14}),` Launch browser`]}),(0,g.jsxs)(`button`,{type:`button`,className:`vnc-surface__btn`,onClick:f,children:[(0,g.jsx)(l,{size:14}),` Pop out`]}),i&&(0,g.jsx)(`span`,{className:`vnc-surface__error`,children:i})]}),(0,g.jsx)(`iframe`,{className:`vnc-surface__iframe`,src:`/vnc-viewer.html`,title:`VNC viewer`})]}):(0,g.jsx)(`div`,{className:`vnc-surface`,children:(0,g.jsxs)(`div`,{className:`vnc-surface__unavailable`,children:[(0,g.jsx)(p,{size:20}),(0,g.jsx)(`p`,{children:`VNC surface not available on this platform.`})]})})}function y(){let[e,t]=(0,h.useState)(null),[n,r]=(0,h.useState)(!1),[i,a]=(0,h.useState)(void 0),[o,l]=(0,h.useState)(null),[p,m]=(0,h.useState)(void 0),[_,y]=(0,h.useState)(null),[b,x]=(0,h.useState)(null);(0,h.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),x(e.role??null),m(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let S=(0,h.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]);return n?e?(0,g.jsx)(c,{cacheKey:e,surface:`browser`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=browser`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,g.jsxs)(f,{cacheKey:e,businessName:i,sessionId:o,onLogout:S,userName:p,userAvatar:_,role:b,children:[(0,g.jsx)(d,{}),(0,g.jsxs)(`div`,{className:`data-page`,children:[(0,g.jsx)(`header`,{className:`data-header`,children:(0,g.jsxs)(`h1`,{className:`data-title`,children:[(0,g.jsx)(u,{size:18}),` Browser`]})}),(0,g.jsx)(v,{})]})]})}):(0,g.jsxs)(`div`,{className:`data-page`,children:[(0,g.jsx)(`header`,{className:`data-header`,children:(0,g.jsxs)(`h1`,{className:`data-title`,children:[(0,g.jsx)(u,{size:18}),` Browser`]})}),(0,g.jsxs)(`div`,{className:`data-empty`,children:[(0,g.jsx)(`p`,{children:`You are not signed in.`}),(0,g.jsxs)(`p`,{children:[`Open the `,(0,g.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,g.jsx)(`div`,{className:`data-page`,children:(0,g.jsxs)(`div`,{className:`data-loading`,children:[(0,g.jsx)(s,{size:18,className:`spin`}),` Loading…`]})})}(0,m.createRoot)(document.getElementById(`root`)).render((0,g.jsx)(y,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CnGqDkHZ.js";import{f as t,l as n,m as r,p as i,u as a}from"./useSelectionMode-BPzPjKP_.js";import{f as o,g as s,h as c,i as l,o as u,r as d,s as f,t as p,u as m}from"./AdminShell-FO766lOW.js";import{i as h,t as g}from"./graph-labels-DSDTSBfM.js";var _=t(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]),v=t(`file`,[[`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`}]]),y=t(`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`}]]),b=t(`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`}]]),x=i(),S=e(r(),1);function C(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||g.has(e)&&(t.add(e),n.push(e)));return n}var w=n();function T(){let[e,t]=(0,S.useState)(null),[n,r]=(0,S.useState)(!1),[i,a]=(0,S.useState)(void 0),[c,u]=(0,S.useState)(null),[d,m]=(0,S.useState)(void 0),[h,g]=(0,S.useState)(null),[_,v]=(0,S.useState)(null);(0,S.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&u(e.sessionId??null),v(e.role??null),m(e.userName===void 0?null:e.userName),g(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let y=(0,S.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]);return n?e?(0,w.jsx)(l,{cacheKey:e,surface:`data`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=data`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,w.jsxs)(p,{cacheKey:e,businessName:i,sessionId:c,onLogout:y,userName:d,userAvatar:h,role:_,children:[(0,w.jsx)(f,{}),(0,w.jsxs)(`div`,{className:`data-page`,children:[(0,w.jsx)(`header`,{className:`data-header`,children:(0,w.jsxs)(`h1`,{className:`data-title`,children:[(0,w.jsx)(s,{size:18}),` Data`]})}),(0,w.jsx)(E,{cacheKey:e})]})]})}):(0,w.jsxs)(`div`,{className:`data-page`,children:[(0,w.jsx)(`header`,{className:`data-header`,children:(0,w.jsxs)(`h1`,{className:`data-title`,children:[(0,w.jsx)(s,{size:18}),` Data`]})}),(0,w.jsxs)(`div`,{className:`data-empty`,children:[(0,w.jsx)(`p`,{children:`You are not signed in.`}),(0,w.jsxs)(`p`,{children:[`Open the `,(0,w.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,w.jsx)(`div`,{className:`data-page`,children:(0,w.jsxs)(`div`,{className:`data-loading`,children:[(0,w.jsx)(o,{size:18,className:`spin`}),` Loading…`]})})}function E({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=u({initialCacheKey:e,surface:`data`});return(0,w.jsxs)(`main`,{className:`data-main`,children:[(0,w.jsx)(D,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}),(0,w.jsx)(F,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})]})}function D({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let[r,i]=(0,S.useState)(``),[a,s]=(0,S.useState)(``),[c,l]=(0,S.useState)(null),[u,d]=(0,S.useState)(`hybrid`),[f,p]=(0,S.useState)(!1),[m,g]=(0,S.useState)(null),[_,v]=(0,S.useState)(null),[y,b]=(0,S.useState)(0),[x,T]=(0,S.useState)(!1);(0,S.useEffect)(()=>{let e=r.trim();if(!e){s(``),l(null);return}T(!1);let t=setTimeout(()=>s(e),300);return()=>clearTimeout(t)},[r]),(0,S.useEffect)(()=>{if(!a)return;let t=!1;return p(!0),g(null),e(`/api/admin/graph-search?q=${encodeURIComponent(a)}&labels=FileArtifact&limit=20${x?`&threshold=0`:``}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(l(e.results),d(e.mode??`hybrid`),b(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||g(e instanceof Error?e.message:String(e))}).finally(()=>{t||p(!1)}),()=>{t=!0}},[a,e,n,x]);let E=(0,S.useMemo)(()=>c?C(c):[],[c]),D=_&&E.includes(_)?_:null,A=(0,S.useMemo)(()=>c?D?c.filter(e=>e.labels.includes(D)):c:null,[c,D]),j=(0,S.useCallback)(e=>{let n=e.properties.relativePath;if(typeof n!=`string`||n.length===0)return;let r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()},[t]);return(0,w.jsxs)(`section`,{className:`data-panel`,children:[(0,w.jsx)(`h2`,{className:`data-panel-title`,children:`Search`}),(0,w.jsx)(`p`,{className:`data-panel-subtitle`,children:`Find anything in your knowledge base by keyword.`}),(0,w.jsxs)(`div`,{className:`data-search-input`,children:[(0,w.jsx)(h,{size:14}),(0,w.jsx)(`input`,{type:`text`,placeholder:`Search your knowledge…`,value:r,onChange:e=>i(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),f&&(0,w.jsx)(o,{size:14,className:`spin`})]}),m&&(0,w.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,m]}),E.length>0&&(0,w.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:E.map(e=>{let t=e===D;return(0,w.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>v(t?null:e),children:k([e])??e},e)})}),c&&!f&&(0,w.jsxs)(`div`,{className:`data-results-meta`,children:[A.length,` of `,c.length,` result`,c.length===1?``:`s`]}),c&&!f&&!D&&y>0&&!x&&(0,w.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>T(!0),children:[y,` low-confidence result`,y===1?``:`s`,` hidden — show all`]}),c&&!f&&!D&&x&&(0,w.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>T(!1),children:`Showing all results — hide low-confidence`}),c&&c.length===0&&!f&&(0,w.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),A&&A.length>0&&(0,w.jsx)(`ul`,{className:`data-results`,children:A.map(e=>(0,w.jsx)(O,{hit:e,mode:u,onDownload:j},e.nodeId))})]})}function O({hit:e,mode:t,onDownload:n}){let r=A(e.properties),i=j(e.properties),a=k(e.labels),o=M(e.properties),[s,c]=(0,S.useState)(!1),l=i&&i.length>280,u=s||!l?i:i?.slice(0,280)+`…`,d=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`;return(0,w.jsxs)(`li`,{className:`data-result`,children:[(0,w.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 ${r??a??`file`}`,children:[a&&(0,w.jsx)(`div`,{className:`data-result-header`,children:(0,w.jsx)(`span`,{className:`data-result-labels`,children:a})}),r&&(0,w.jsx)(`div`,{className:`data-result-title`,children:r}),i&&(0,w.jsx)(`pre`,{className:`data-result-body`,children:u}),(0,w.jsxs)(`div`,{className:`data-result-scores`,children:[o&&(0,w.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,L(o),` · `]}),d]})]}),l&&(0,w.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>c(e=>!e),children:s?`Show less`:`Show more`})]})}function k(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 A(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 j(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 M(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 N(){if(typeof window>`u`)return`.`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`.`}function P(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 F({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let[r,i]=(0,S.useState)(()=>N()),[s,l]=(0,S.useState)(null),[u,f]=(0,S.useState)([]),[p,h]=(0,S.useState)(!1),[g,x]=(0,S.useState)(null),[C,T]=(0,S.useState)(!1),[E,D]=(0,S.useState)(null),[O,k]=(0,S.useState)(null),[A,j]=(0,S.useState)(null),[M,F]=(0,S.useState)(null),R=(0,S.useRef)(null),[z,B]=(0,S.useState)(0);(0,S.useEffect)(()=>{let t=!1;return h(!0),x(null),e(`/api/admin/files?path=${encodeURIComponent(r===`.`?``:r)}`).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||(l(e.entries),f(e.displayPath??[]))}).catch(e=>{t||(l([]),f([]),x(e instanceof Error?e.message:String(e)))}).finally(()=>{t||h(!1)}),()=>{t=!0}},[e,r,z,n]),(0,S.useEffect)(()=>{P(r)},[r]);let V=(0,S.useCallback)(()=>{B(e=>e+1)},[]),H=(0,S.useCallback)(e=>{i(e)},[]),U=(0,S.useCallback)(()=>{if(r===`.`||r===``)return;let e=r.split(`/`).filter(Boolean);e.pop(),i(e.length===0?`.`:e.join(`/`))},[r]),W=(0,S.useCallback)(e=>{d(t,r===`.`?e.name:`${r}/${e.name}`)},[r,t]),G=(0,S.useCallback)(()=>{R.current?.click()},[]),K=(0,S.useCallback)(e=>{k(null),F(e.name)},[]),q=(0,S.useCallback)(()=>{F(null)},[]),J=(0,S.useCallback)(async t=>{let n=r===`.`?t.name:`${r}/${t.name}`;k(null),F(null),j(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}`);B(e=>e+1)}catch(e){k(e instanceof Error?e.message:String(e))}finally{j(null)}},[r,e]);(0,S.useEffect)(()=>{if(!M)return;let e=e=>{e.key===`Escape`&&F(null)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[M]);let Y=(0,S.useCallback)(async e=>{D(null),T(!0);try{let n=new FormData;n.append(`session_key`,t),n.append(`file`,e);let r=await fetch(`/api/admin/files/upload`,{method:`POST`,body:n}),a=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(a.error??`HTTP ${r.status}`);i(a.path.split(`/`).slice(0,-1).join(`/`)||`.`),B(e=>e+1)}catch(e){D(e instanceof Error?e.message:String(e))}finally{T(!1),R.current&&(R.current.value=``)}},[t]);return(0,w.jsxs)(`section`,{className:`data-panel`,children:[(0,w.jsxs)(`div`,{className:`data-panel-heading`,children:[(0,w.jsx)(`h2`,{className:`data-panel-title`,children:`Files`}),(0,w.jsxs)(`div`,{className:`data-file-actions`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`data-btn`,onClick:V,disabled:p,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[p?(0,w.jsx)(o,{size:14,className:`spin`}):(0,w.jsx)(m,{size:14}),` Refresh`]}),(0,w.jsxs)(`button`,{type:`button`,className:`data-btn`,onClick:G,disabled:C,children:[C?(0,w.jsx)(o,{size:14,className:`spin`}):(0,w.jsx)(b,{size:14}),` Upload`]}),(0,w.jsx)(`input`,{type:`file`,ref:R,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Y(t)}})]})]}),(0,w.jsxs)(`p`,{className:`data-panel-subtitle`,children:[`Everything under your install's `,(0,w.jsx)(`code`,{children:`data/`}),` directory. Click a folder to open it, a file to download it. Uploads go to `,(0,w.jsx)(`code`,{children:`data/uploads/`}),`.`]}),(0,w.jsxs)(`div`,{className:`data-breadcrumbs`,children:[(0,w.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>H(`.`),children:`data`}),u.map((e,t)=>{let n=u.slice(0,t+1).map(e=>e.name).join(`/`);return(0,w.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,w.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,w.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>H(n),title:e.name,children:e.displayName??e.name})]},n)}),r!==`.`&&(0,w.jsxs)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-up-btn`,onClick:U,children:[(0,w.jsx)(_,{size:14}),` Up`]})]}),E&&(0,w.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,E]}),O&&(0,w.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,O]}),g&&(0,w.jsx)(`div`,{className:`data-error`,children:g}),p&&(0,w.jsxs)(`div`,{className:`data-loading`,children:[(0,w.jsx)(o,{size:14,className:`spin`}),` Loading…`]}),!p&&s&&s.length===0&&!g&&(0,w.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!p&&s&&s.length>0&&(0,w.jsx)(`ul`,{className:`data-entries`,children:s.map(e=>{let t=e.displayName??e.name,n=A===e.name,i=M===e.name;return(0,w.jsx)(`li`,{className:`data-entry`,children:e.kind===`directory`?(0,w.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onClick:()=>H(r===`.`?e.name:`${r}/${e.name}`),children:[(0,w.jsx)(y,{size:14}),(0,w.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]}):e.kind===`file`?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onClick:()=>W(e),title:`Download ${t}`,disabled:i,children:[(0,w.jsx)(v,{size:14}),(0,w.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,w.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${L(e.modifiedAt)}`,children:[I(e.sizeBytes),` · `,L(e.modifiedAt)]}),(0,w.jsx)(c,{size:12,className:`data-entry-download-icon`})]}),i?(0,w.jsxs)(`div`,{className:`data-entry-confirm`,role:`group`,"aria-label":`Confirm delete ${t}`,children:[(0,w.jsx)(`span`,{className:`data-entry-confirm-label`,children:`Delete?`}),(0,w.jsx)(`button`,{type:`button`,className:`data-entry-confirm-yes`,onClick:()=>J(e),autoFocus:!0,children:`Yes`}),(0,w.jsx)(`button`,{type:`button`,className:`data-entry-confirm-no`,onClick:q,children:`No`})]}):(0,w.jsx)(`button`,{type:`button`,className:`data-entry-delete`,onClick:()=>K(e),disabled:n,title:`Delete ${t}`,"aria-label":`Delete ${t}`,children:n?(0,w.jsx)(o,{size:14,className:`spin`}):(0,w.jsx)(a,{size:14})})]}):(0,w.jsxs)(`div`,{className:`data-entry-btn data-entry-disabled`,children:[(0,w.jsx)(v,{size:14}),(0,w.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,w.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})},e.name)})})]})}function I(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 L(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`—`}}(0,x.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(T,{}));
1
+ import{o as e}from"./chunk-CnGqDkHZ.js";import{f as t,l as n,m as r,p as i,u as a}from"./useSelectionMode-BPzPjKP_.js";import{f as o,g as s,h as c,i as l,o as u,r as d,s as f,t as p,u as m}from"./AdminShell-8Y7-maNi.js";import{i as h,t as g}from"./graph-labels-DSDTSBfM.js";var _=t(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]),v=t(`file`,[[`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`}]]),y=t(`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`}]]),b=t(`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`}]]),x=i(),S=e(r(),1);function C(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||g.has(e)&&(t.add(e),n.push(e)));return n}var w=n();function T(){let[e,t]=(0,S.useState)(null),[n,r]=(0,S.useState)(!1),[i,a]=(0,S.useState)(void 0),[c,u]=(0,S.useState)(null),[d,m]=(0,S.useState)(void 0),[h,g]=(0,S.useState)(null),[_,v]=(0,S.useState)(null);(0,S.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&u(e.sessionId??null),v(e.role??null),m(e.userName===void 0?null:e.userName),g(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let y=(0,S.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]);return n?e?(0,w.jsx)(l,{cacheKey:e,surface:`data`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=data`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,w.jsxs)(p,{cacheKey:e,businessName:i,sessionId:c,onLogout:y,userName:d,userAvatar:h,role:_,children:[(0,w.jsx)(f,{}),(0,w.jsxs)(`div`,{className:`data-page`,children:[(0,w.jsx)(`header`,{className:`data-header`,children:(0,w.jsxs)(`h1`,{className:`data-title`,children:[(0,w.jsx)(s,{size:18}),` Data`]})}),(0,w.jsx)(E,{cacheKey:e})]})]})}):(0,w.jsxs)(`div`,{className:`data-page`,children:[(0,w.jsx)(`header`,{className:`data-header`,children:(0,w.jsxs)(`h1`,{className:`data-title`,children:[(0,w.jsx)(s,{size:18}),` Data`]})}),(0,w.jsxs)(`div`,{className:`data-empty`,children:[(0,w.jsx)(`p`,{children:`You are not signed in.`}),(0,w.jsxs)(`p`,{children:[`Open the `,(0,w.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,w.jsx)(`div`,{className:`data-page`,children:(0,w.jsxs)(`div`,{className:`data-loading`,children:[(0,w.jsx)(o,{size:18,className:`spin`}),` Loading…`]})})}function E({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=u({initialCacheKey:e,surface:`data`});return(0,w.jsxs)(`main`,{className:`data-main`,children:[(0,w.jsx)(D,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}),(0,w.jsx)(F,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})]})}function D({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let[r,i]=(0,S.useState)(``),[a,s]=(0,S.useState)(``),[c,l]=(0,S.useState)(null),[u,d]=(0,S.useState)(`hybrid`),[f,p]=(0,S.useState)(!1),[m,g]=(0,S.useState)(null),[_,v]=(0,S.useState)(null),[y,b]=(0,S.useState)(0),[x,T]=(0,S.useState)(!1);(0,S.useEffect)(()=>{let e=r.trim();if(!e){s(``),l(null);return}T(!1);let t=setTimeout(()=>s(e),300);return()=>clearTimeout(t)},[r]),(0,S.useEffect)(()=>{if(!a)return;let t=!1;return p(!0),g(null),e(`/api/admin/graph-search?q=${encodeURIComponent(a)}&labels=FileArtifact&limit=20${x?`&threshold=0`:``}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(l(e.results),d(e.mode??`hybrid`),b(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||g(e instanceof Error?e.message:String(e))}).finally(()=>{t||p(!1)}),()=>{t=!0}},[a,e,n,x]);let E=(0,S.useMemo)(()=>c?C(c):[],[c]),D=_&&E.includes(_)?_:null,A=(0,S.useMemo)(()=>c?D?c.filter(e=>e.labels.includes(D)):c:null,[c,D]),j=(0,S.useCallback)(e=>{let n=e.properties.relativePath;if(typeof n!=`string`||n.length===0)return;let r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()},[t]);return(0,w.jsxs)(`section`,{className:`data-panel`,children:[(0,w.jsx)(`h2`,{className:`data-panel-title`,children:`Search`}),(0,w.jsx)(`p`,{className:`data-panel-subtitle`,children:`Find anything in your knowledge base by keyword.`}),(0,w.jsxs)(`div`,{className:`data-search-input`,children:[(0,w.jsx)(h,{size:14}),(0,w.jsx)(`input`,{type:`text`,placeholder:`Search your knowledge…`,value:r,onChange:e=>i(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),f&&(0,w.jsx)(o,{size:14,className:`spin`})]}),m&&(0,w.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,m]}),E.length>0&&(0,w.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:E.map(e=>{let t=e===D;return(0,w.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>v(t?null:e),children:k([e])??e},e)})}),c&&!f&&(0,w.jsxs)(`div`,{className:`data-results-meta`,children:[A.length,` of `,c.length,` result`,c.length===1?``:`s`]}),c&&!f&&!D&&y>0&&!x&&(0,w.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>T(!0),children:[y,` low-confidence result`,y===1?``:`s`,` hidden — show all`]}),c&&!f&&!D&&x&&(0,w.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>T(!1),children:`Showing all results — hide low-confidence`}),c&&c.length===0&&!f&&(0,w.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),A&&A.length>0&&(0,w.jsx)(`ul`,{className:`data-results`,children:A.map(e=>(0,w.jsx)(O,{hit:e,mode:u,onDownload:j},e.nodeId))})]})}function O({hit:e,mode:t,onDownload:n}){let r=A(e.properties),i=j(e.properties),a=k(e.labels),o=M(e.properties),[s,c]=(0,S.useState)(!1),l=i&&i.length>280,u=s||!l?i:i?.slice(0,280)+`…`,d=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`;return(0,w.jsxs)(`li`,{className:`data-result`,children:[(0,w.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 ${r??a??`file`}`,children:[a&&(0,w.jsx)(`div`,{className:`data-result-header`,children:(0,w.jsx)(`span`,{className:`data-result-labels`,children:a})}),r&&(0,w.jsx)(`div`,{className:`data-result-title`,children:r}),i&&(0,w.jsx)(`pre`,{className:`data-result-body`,children:u}),(0,w.jsxs)(`div`,{className:`data-result-scores`,children:[o&&(0,w.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,L(o),` · `]}),d]})]}),l&&(0,w.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>c(e=>!e),children:s?`Show less`:`Show more`})]})}function k(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 A(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 j(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 M(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 N(){if(typeof window>`u`)return`.`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`.`}function P(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 F({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let[r,i]=(0,S.useState)(()=>N()),[s,l]=(0,S.useState)(null),[u,f]=(0,S.useState)([]),[p,h]=(0,S.useState)(!1),[g,x]=(0,S.useState)(null),[C,T]=(0,S.useState)(!1),[E,D]=(0,S.useState)(null),[O,k]=(0,S.useState)(null),[A,j]=(0,S.useState)(null),[M,F]=(0,S.useState)(null),R=(0,S.useRef)(null),[z,B]=(0,S.useState)(0);(0,S.useEffect)(()=>{let t=!1;return h(!0),x(null),e(`/api/admin/files?path=${encodeURIComponent(r===`.`?``:r)}`).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||(l(e.entries),f(e.displayPath??[]))}).catch(e=>{t||(l([]),f([]),x(e instanceof Error?e.message:String(e)))}).finally(()=>{t||h(!1)}),()=>{t=!0}},[e,r,z,n]),(0,S.useEffect)(()=>{P(r)},[r]);let V=(0,S.useCallback)(()=>{B(e=>e+1)},[]),H=(0,S.useCallback)(e=>{i(e)},[]),U=(0,S.useCallback)(()=>{if(r===`.`||r===``)return;let e=r.split(`/`).filter(Boolean);e.pop(),i(e.length===0?`.`:e.join(`/`))},[r]),W=(0,S.useCallback)(e=>{d(t,r===`.`?e.name:`${r}/${e.name}`)},[r,t]),G=(0,S.useCallback)(()=>{R.current?.click()},[]),K=(0,S.useCallback)(e=>{k(null),F(e.name)},[]),q=(0,S.useCallback)(()=>{F(null)},[]),J=(0,S.useCallback)(async t=>{let n=r===`.`?t.name:`${r}/${t.name}`;k(null),F(null),j(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}`);B(e=>e+1)}catch(e){k(e instanceof Error?e.message:String(e))}finally{j(null)}},[r,e]);(0,S.useEffect)(()=>{if(!M)return;let e=e=>{e.key===`Escape`&&F(null)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[M]);let Y=(0,S.useCallback)(async e=>{D(null),T(!0);try{let n=new FormData;n.append(`session_key`,t),n.append(`file`,e);let r=await fetch(`/api/admin/files/upload`,{method:`POST`,body:n}),a=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(a.error??`HTTP ${r.status}`);i(a.path.split(`/`).slice(0,-1).join(`/`)||`.`),B(e=>e+1)}catch(e){D(e instanceof Error?e.message:String(e))}finally{T(!1),R.current&&(R.current.value=``)}},[t]);return(0,w.jsxs)(`section`,{className:`data-panel`,children:[(0,w.jsxs)(`div`,{className:`data-panel-heading`,children:[(0,w.jsx)(`h2`,{className:`data-panel-title`,children:`Files`}),(0,w.jsxs)(`div`,{className:`data-file-actions`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`data-btn`,onClick:V,disabled:p,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[p?(0,w.jsx)(o,{size:14,className:`spin`}):(0,w.jsx)(m,{size:14}),` Refresh`]}),(0,w.jsxs)(`button`,{type:`button`,className:`data-btn`,onClick:G,disabled:C,children:[C?(0,w.jsx)(o,{size:14,className:`spin`}):(0,w.jsx)(b,{size:14}),` Upload`]}),(0,w.jsx)(`input`,{type:`file`,ref:R,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Y(t)}})]})]}),(0,w.jsxs)(`p`,{className:`data-panel-subtitle`,children:[`Everything under your install's `,(0,w.jsx)(`code`,{children:`data/`}),` directory. Click a folder to open it, a file to download it. Uploads go to `,(0,w.jsx)(`code`,{children:`data/uploads/`}),`.`]}),(0,w.jsxs)(`div`,{className:`data-breadcrumbs`,children:[(0,w.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>H(`.`),children:`data`}),u.map((e,t)=>{let n=u.slice(0,t+1).map(e=>e.name).join(`/`);return(0,w.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,w.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,w.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>H(n),title:e.name,children:e.displayName??e.name})]},n)}),r!==`.`&&(0,w.jsxs)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-up-btn`,onClick:U,children:[(0,w.jsx)(_,{size:14}),` Up`]})]}),E&&(0,w.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,E]}),O&&(0,w.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,O]}),g&&(0,w.jsx)(`div`,{className:`data-error`,children:g}),p&&(0,w.jsxs)(`div`,{className:`data-loading`,children:[(0,w.jsx)(o,{size:14,className:`spin`}),` Loading…`]}),!p&&s&&s.length===0&&!g&&(0,w.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!p&&s&&s.length>0&&(0,w.jsx)(`ul`,{className:`data-entries`,children:s.map(e=>{let t=e.displayName??e.name,n=A===e.name,i=M===e.name;return(0,w.jsx)(`li`,{className:`data-entry`,children:e.kind===`directory`?(0,w.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onClick:()=>H(r===`.`?e.name:`${r}/${e.name}`),children:[(0,w.jsx)(y,{size:14}),(0,w.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]}):e.kind===`file`?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onClick:()=>W(e),title:`Download ${t}`,disabled:i,children:[(0,w.jsx)(v,{size:14}),(0,w.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,w.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${L(e.modifiedAt)}`,children:[I(e.sizeBytes),` · `,L(e.modifiedAt)]}),(0,w.jsx)(c,{size:12,className:`data-entry-download-icon`})]}),i?(0,w.jsxs)(`div`,{className:`data-entry-confirm`,role:`group`,"aria-label":`Confirm delete ${t}`,children:[(0,w.jsx)(`span`,{className:`data-entry-confirm-label`,children:`Delete?`}),(0,w.jsx)(`button`,{type:`button`,className:`data-entry-confirm-yes`,onClick:()=>J(e),autoFocus:!0,children:`Yes`}),(0,w.jsx)(`button`,{type:`button`,className:`data-entry-confirm-no`,onClick:q,children:`No`})]}):(0,w.jsx)(`button`,{type:`button`,className:`data-entry-delete`,onClick:()=>K(e),disabled:n,title:`Delete ${t}`,"aria-label":`Delete ${t}`,children:n?(0,w.jsx)(o,{size:14,className:`spin`}):(0,w.jsx)(a,{size:14})})]}):(0,w.jsxs)(`div`,{className:`data-entry-btn data-entry-disabled`,children:[(0,w.jsx)(v,{size:14}),(0,w.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,w.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})},e.name)})})]})}function I(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 L(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`—`}}(0,x.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(T,{}));