@rubytech/create-maxy 1.0.876 → 1.0.878

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 (71) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/lib/graph-trash/dist/index.js +1 -1
  3. package/payload/platform/lib/graph-trash/dist/index.js.map +1 -1
  4. package/payload/platform/lib/graph-trash/src/index.ts +1 -1
  5. package/payload/platform/neo4j/edge-annotations.json +11 -3
  6. package/payload/platform/plugins/admin/hooks/__tests__/pre-tool-use-base64-guard.test.sh +204 -0
  7. package/payload/platform/plugins/admin/hooks/archive-ingest-surface-gate.sh +11 -5
  8. package/payload/platform/plugins/admin/hooks/pre-tool-use.sh +96 -0
  9. package/payload/platform/plugins/admin/skills/onboarding/SKILL.md +5 -1
  10. package/payload/platform/plugins/cloudflare/scripts/setup-tunnel.sh +88 -9
  11. package/payload/platform/plugins/cloudflare/skills/setup-tunnel/SKILL.md +1 -1
  12. package/payload/platform/plugins/docs/references/admin-session.md +80 -0
  13. package/payload/platform/plugins/docs/references/platform.md +3 -1
  14. package/payload/platform/plugins/docs/references/plugins-guide.md +1 -0
  15. package/payload/platform/plugins/memory/PLUGIN.md +4 -1
  16. package/payload/platform/plugins/memory/mcp/dist/index.js +127 -0
  17. package/payload/platform/plugins/memory/mcp/dist/index.js.map +1 -1
  18. package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-archive-derive-insights.test.d.ts +2 -0
  19. package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-archive-derive-insights.test.d.ts.map +1 -0
  20. package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-archive-derive-insights.test.js +97 -0
  21. package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-archive-derive-insights.test.js.map +1 -0
  22. package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-archive-enrich-rejection.test.d.ts +2 -0
  23. package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-archive-enrich-rejection.test.d.ts.map +1 -0
  24. package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-archive-enrich-rejection.test.js +184 -0
  25. package/payload/platform/plugins/memory/mcp/dist/tools/__tests__/conversation-archive-enrich-rejection.test.js.map +1 -0
  26. package/payload/platform/plugins/memory/mcp/dist/tools/conversation-archive-derive-insights.d.ts +89 -0
  27. package/payload/platform/plugins/memory/mcp/dist/tools/conversation-archive-derive-insights.d.ts.map +1 -0
  28. package/payload/platform/plugins/memory/mcp/dist/tools/conversation-archive-derive-insights.js +542 -0
  29. package/payload/platform/plugins/memory/mcp/dist/tools/conversation-archive-derive-insights.js.map +1 -0
  30. package/payload/platform/plugins/memory/mcp/dist/tools/conversation-archive-enrich-rejection.d.ts +41 -0
  31. package/payload/platform/plugins/memory/mcp/dist/tools/conversation-archive-enrich-rejection.d.ts.map +1 -0
  32. package/payload/platform/plugins/memory/mcp/dist/tools/conversation-archive-enrich-rejection.js +116 -0
  33. package/payload/platform/plugins/memory/mcp/dist/tools/conversation-archive-enrich-rejection.js.map +1 -0
  34. package/payload/platform/plugins/memory/skills/conversation-archive-enrich/SKILL.md +159 -0
  35. package/payload/platform/templates/agents/admin/IDENTITY.md +4 -0
  36. package/payload/platform/templates/specialists/agents/database-operator.md +3 -2
  37. package/payload/server/chunk-GOZP57CX.js +1373 -0
  38. package/payload/server/chunk-I4AQMEJA.js +11265 -0
  39. package/payload/server/chunk-INI2ED6U.js +2277 -0
  40. package/payload/server/chunk-JTZYXIUW.js +1373 -0
  41. package/payload/server/chunk-LQDUG4II.js +11336 -0
  42. package/payload/server/chunk-LU6TUP3E.js +2169 -0
  43. package/payload/server/chunk-RP25NRQY.js +660 -0
  44. package/payload/server/chunk-RRVBWC66.js +667 -0
  45. package/payload/server/client-pool-AIZ5QKFD.js +34 -0
  46. package/payload/server/client-pool-VYDOIFG7.js +34 -0
  47. package/payload/server/cloudflare-task-tracker-B6FXP3HI.js +20 -0
  48. package/payload/server/cloudflare-task-tracker-M7APAYEF.js +20 -0
  49. package/payload/server/maxy-edge.js +6 -5
  50. package/payload/server/public/assets/{Checkbox-BsqexMy3.js → Checkbox-CqsIsmEi.js} +1 -1
  51. package/payload/server/public/assets/admin-CZlNLb9T.js +352 -0
  52. package/payload/server/public/assets/data-CH-nQ7oX.js +1 -0
  53. package/payload/server/public/assets/graph-labels-D0qUVHtZ.js +1 -0
  54. package/payload/server/public/assets/graph-mpWDe4rf.js +1 -0
  55. package/payload/server/public/assets/{jsx-runtime-CGCRFPeX.css → jsx-runtime-Cy_HdZWV.css} +1 -1
  56. package/payload/server/public/assets/page-CnyySOZF.js +1 -0
  57. package/payload/server/public/assets/{page-qI0NJSs6.js → page-DcK36vDf.js} +2 -2
  58. package/payload/server/public/assets/public-SXA00FTv.js +5 -0
  59. package/payload/server/public/assets/{useVoiceRecorder-DVVSQc-9.js → useVoiceRecorder-DcByEBLy.js} +1 -1
  60. package/payload/server/public/data.html +5 -5
  61. package/payload/server/public/graph.html +6 -6
  62. package/payload/server/public/index.html +8 -8
  63. package/payload/server/public/public.html +5 -5
  64. package/payload/server/server.js +560 -448
  65. package/payload/server/public/assets/admin-pIeHRytz.js +0 -352
  66. package/payload/server/public/assets/data-rhAG7W2b.js +0 -1
  67. package/payload/server/public/assets/graph-DVAWZmkb.js +0 -1
  68. package/payload/server/public/assets/graph-labels-t_04n4zX.js +0 -1
  69. package/payload/server/public/assets/page-BM9O7QN8.js +0 -1
  70. package/payload/server/public/assets/public-oNo_2gt0.js +0 -5
  71. /package/payload/server/public/assets/{jsx-runtime-B8sGPXtT.js → jsx-runtime-BEjEWeaF.js} +0 -0
@@ -1 +0,0 @@
1
- import{i as e,t}from"./jsx-runtime-B8sGPXtT.js";import{t as n}from"./page-BM9O7QN8.js";import"./graph-labels-t_04n4zX.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
@@ -1 +0,0 @@
1
- import{i as e,t}from"./jsx-runtime-B8sGPXtT.js";import{n}from"./page-qI0NJSs6.js";import"./graph-labels-t_04n4zX.js";import"./Checkbox-BsqexMy3.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-DD-I1_y5.js";import{o as t,r as n}from"./jsx-runtime-B8sGPXtT.js";var r=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`}]]),i=n(`house`,[[`path`,{d:`M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8`,key:`5wwlr5`}],[`path`,{d:`M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`,key:`r6nss1`}]]),a=n(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),o=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`}]]),s=n(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),c=n(`search`,[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]),l=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`}]]),u=`maxy-admin-session`,d=typeof BroadcastChannel<`u`;function f(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`)&&typeof t.ts==`number`}function p(e,t){if(!d){console.log(`[admin-session-broadcast] outcome=skipped reason=broadcastchannel-unavailable surface=${t}`);return}let n=new BroadcastChannel(u);try{let r={type:`rotation`,newKey:e,surface:t,ts:Date.now()};n.postMessage(r),console.log(`[admin-session-broadcast] outcome=sent newKey=${e.slice(0,8)} surface=${t}`)}finally{n.close()}}function m(e){if(!d)return()=>{};let t=new BroadcastChannel(u),n=t=>{if(!f(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 h=e(t(),1),g=`maxy-admin-session-key`;function _(e,t){return`${e}${e.includes(`?`)?`&`:`?`}session_key=${encodeURIComponent(t)}`}async function v(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 y(){try{return sessionStorage.getItem(g)}catch{return null}}function b(e){let{initialSessionKey:t,surface:n}=e,[r,i]=(0,h.useState)(t),a=(0,h.useRef)(t);(0,h.useEffect)(()=>{a.current=r},[r]),(0,h.useEffect)(()=>{t!==a.current&&(i(t),a.current=t,s(e=>e+1))},[t]);let[o,s]=(0,h.useState)(0),[c,l]=(0,h.useState)(null);(0,h.useEffect)(()=>m(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),l(null))}),[n]);let u=(0,h.useCallback)(()=>{try{sessionStorage.removeItem(g)}catch{}window.location.href=`/`},[]);return{adminFetch:(0,h.useCallback)(async(e,t)=>{let r=a.current,o=_(e,r),c=await fetch(o,t);if(c.status!==401)return c;let d=await v(c);if(d===`session-missing`)return console.warn(`[useAdminFetch] outcome=redirect-to-login reason=${d} surface=${n} path=${e}`),u(),c;if(d!==`session-not-registered`)return console.warn(`[useAdminFetch] outcome=redirect-to-login reason=${d} surface=${n} path=${e}`),l({message:`Your admin session has expired. Click to reload and sign in.`,reason:d}),c;let f=y();if(!f||f===r)return console.warn(`[useAdminFetch] outcome=redirect-to-login reason=session-not-registered-no-fresh-key surface=${n} path=${e}`),l({message:`Your admin session was renewed in another tab. Click to reload.`,reason:`session-not-registered`}),c;i(f),a.current=f,s(e=>e+1),console.log(`[useAdminFetch] outcome=retry-after-rotation oldKey=${r.slice(0,8)} newKey=${f.slice(0,8)} surface=${n} path=${e}`);let p=_(e,f),m=await fetch(p,t);return m.status===401&&(console.warn(`[useAdminFetch] outcome=redirect-to-login reason=second-401-after-retry surface=${n} path=${e}`),l({message:`Your admin session has expired. Click to reload and sign in.`,reason:`session-not-registered`})),m},[u,n]),sessionKey:r,sessionRefetchNonce:o,banner:c,reloadToLogin:u}}var x={LocalBusiness:`#4F6B8A`,Service:`#6B85A0`,PriceSpecification:`#8AA0B8`,OpeningHoursSpecification:`#A8BACE`,Organization:`#8A6B47`,Person:`#B86E4A`,UserProfile:`#D08960`,Preference:`#DFA67A`,AdminUser:`#8C5230`,AccessGrant:`#66381F`,KnowledgeDocument:`#6E8A5A`,ConversationArchive:`#82A06A`,Section:`#8AA876`,Chunk:`#A6C194`,DigitalDocument:`#5A7548`,CreativeWork:`#B5C9A2`,Question:`#C7D6B5`,FAQPage:`#95B385`,DefinedTerm:`#76906A`,Review:`#3F5A2E`,ImageObject:`#A0BB8C`,Conversation:`#6B5A85`,AdminConversation:`#4F4070`,PublicConversation:`#8A75A8`,Message:`#6B7280`,UserMessage:`#DFA67A`,AssistantMessage:`#C9A876`,ToolCall:`#B5ABCB`,Task:`#B0617A`,Project:`#8E4A60`,Event:`#C68095`,Workflow:`#3A6F77`,WorkflowStep:`#5A8E96`,WorkflowRun:`#7AAAB2`,StepResult:`#9CC4CB`,OnboardingState:`#7A5A8A`,Email:`#6F7F4A`,EmailAccount:`#91A063`,Agent:`#B8893D`},S=`#94A3B8`;Object.freeze(Object.keys(x)),Object.freeze(new Set([`Chunk`,`GraphPreference`]));var C=Object.freeze(new Set(`LocalBusiness.Service.PriceSpecification.OpeningHoursSpecification.Organization.Person.UserProfile.Preference.AdminUser.AccessGrant.KnowledgeDocument.DigitalDocument.CreativeWork.Question.FAQPage.DefinedTerm.Review.ImageObject.AdminConversation.PublicConversation.Task.Project.Event.Workflow.OnboardingState.Email.EmailAccount.Agent`.split(`.`)));Object.freeze(new Set([`ToolCall`,`StepResult`,`WorkflowStep`,`WorkflowRun`])),Object.freeze(new Set([`HAS_TOOL_CALL`,`RUN_OF`,`HAS_STEP`,`HAS_RESULT`]));function w(e){for(let t=1;t<e.length;t++)if(Object.prototype.hasOwnProperty.call(x,e[t]))return e[t];return e[0]??null}function T(e){return x[e]??`#94A3B8`}function E(e){let t=w(e),n=t?T(t):S,r=0;for(let t=1;t<e.length;t++)Object.prototype.hasOwnProperty.call(x,e[t])&&r++;return{displayLabel:t,colour:n,driftCandidates:r}}export{b as a,c,a as d,i as f,E as i,s as l,T as n,p as o,r as p,w as r,l as s,C as t,o as u};
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-DD-I1_y5.js";import{n as t,o as n,r,t as i}from"./jsx-runtime-B8sGPXtT.js";import{a,c as o,d as s,f as c,l,p as u,s as d,t as f,u as p}from"./graph-labels-t_04n4zX.js";var m=r(`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`}]]),h=r(`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=r(`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`}]]),_=r(`folder`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),v=r(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]);function y(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||f.has(e)&&(t.add(e),n.push(e)));return n}var b=80;function x(e){let t=S(e.properties)??e.labels[0]??``,n=t.length>b?t.slice(0,b):t;return`/graph?${new URLSearchParams({nodeId:e.nodeId,label:n}).toString()}`}function S(e){for(let t of[`title`,`name`,`summary`,`headline`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}var C=e(n(),1),w=i();function T(){let[e,t]=(0,C.useState)(null),[n,r]=(0,C.useState)(!1);return(0,C.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,w.jsxs)(`div`,{className:`data-page`,children:[(0,w.jsxs)(`header`,{className:`data-header`,children:[(0,w.jsxs)(`h1`,{className:`data-title`,children:[(0,w.jsx)(u,{size:18}),` Data`]}),(0,w.jsx)(D,{})]}),(0,w.jsx)(E,{sessionKey: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)(u,{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)(s,{size:18,className:`spin`}),` Loading…`]})})}function E({sessionKey:e,onOpenInGraph:t}){let{adminFetch:n,sessionKey:r,sessionRefetchNonce:i,banner:o,reloadToLogin:s}=a({initialSessionKey:e,surface:`data`});return(0,w.jsxs)(`main`,{className:`data-main`,children:[o&&(0,w.jsx)(`button`,{type:`button`,className:`data-session-banner`,onClick:s,"data-reason":o.reason,children:o.message}),(0,w.jsx)(O,{adminFetch:n,sessionRefetchNonce:i,onOpenInGraph:t}),(0,w.jsx)(N,{adminFetch:n,sessionKey:r,sessionRefetchNonce:i})]})}function D(){let[e,t]=(0,C.useState)(!1),n=(0,C.useRef)(null);(0,C.useEffect)(()=>{if(!e)return;let r=e=>{n.current&&(n.current.contains(e.target)||t(!1))},i=e=>{e.key===`Escape`&&t(!1)};return document.addEventListener(`mousedown`,r),document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`mousedown`,r),document.removeEventListener(`keydown`,i)}},[e]);let r=(0,C.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]);return(0,w.jsxs)(`div`,{className:`chat-burger-wrap`,ref:n,children:[(0,w.jsx)(`button`,{type:`button`,className:`chat-burger`,onClick:()=>t(e=>!e),"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":e,children:(0,w.jsx)(l,{size:20})}),e&&(0,w.jsxs)(`div`,{className:`chat-menu`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),window.location.href=`/`},children:[(0,w.jsx)(c,{size:14}),` Chat`]}),(0,w.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),window.location.href=`/graph`},children:[(0,w.jsx)(d,{size:14}),` Graph`]}),(0,w.jsx)(`div`,{className:`chat-menu-divider`}),(0,w.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{t(!1),r()},children:[(0,w.jsx)(p,{size:14}),` Log out`]})]})]})}function O({adminFetch:e,sessionRefetchNonce:t,onOpenInGraph:n}){let[r,i]=(0,C.useState)(``),[a,c]=(0,C.useState)(``),[l,u]=(0,C.useState)(null),[d,f]=(0,C.useState)(`hybrid`),[p,m]=(0,C.useState)(!1),[h,g]=(0,C.useState)(null),[_,v]=(0,C.useState)(null),[b,S]=(0,C.useState)(0),[T,E]=(0,C.useState)(!1);(0,C.useEffect)(()=>{let e=r.trim();if(!e){c(``),u(null);return}E(!1);let t=setTimeout(()=>c(e),300);return()=>clearTimeout(t)},[r]),(0,C.useEffect)(()=>{if(!a)return;let t=!1;return m(!0),g(null),e(`/api/admin/graph-search?q=${encodeURIComponent(a)}&labels=*&limit=20${T?`&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||(u(e.results),f(e.mode??`hybrid`),S(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||g(e instanceof Error?e.message:String(e))}).finally(()=>{t||m(!1)}),()=>{t=!0}},[a,e,t,T]);let D=(0,C.useMemo)(()=>l?y(l):[],[l]),O=_&&D.includes(_)?_:null,j=(0,C.useMemo)(()=>l?O?l.filter(e=>e.labels.includes(O)):l:null,[l,O]),M=(0,C.useCallback)(e=>{if(n){n(e);return}window.location.href=x(e)},[n]);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)(o,{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}),p&&(0,w.jsx)(s,{size:14,className:`spin`})]}),h&&(0,w.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,h]}),D.length>0&&(0,w.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:D.map(e=>{let t=e===O;return(0,w.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>v(t?null:e),children:A([e])??e},e)})}),l&&!p&&(0,w.jsxs)(`div`,{className:`data-results-meta`,children:[j.length,` of `,l.length,` result`,l.length===1?``:`s`]}),l&&!p&&!O&&b>0&&!T&&(0,w.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>E(!0),children:[b,` low-confidence result`,b===1?``:`s`,` hidden — show all`]}),l&&!p&&!O&&T&&(0,w.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>E(!1),children:`Showing all results — hide low-confidence`}),l&&l.length===0&&!p&&(0,w.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),j&&j.length>0&&(0,w.jsx)(`ul`,{className:`data-results`,children:j.map(e=>(0,w.jsx)(k,{hit:e,mode:d,onOpenInGraph:M},e.nodeId))})]})}function k({hit:e,mode:t,onOpenInGraph:n}){let r=j(e.properties),i=M(e.properties),a=A(e.labels),[o,s]=(0,C.useState)(!1),c=i&&i.length>280,l=o||!c?i:i?.slice(0,280)+`…`,u=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":`Open ${r??a??`node`} in graph`,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:l}),(0,w.jsx)(`div`,{className:`data-result-scores`,children:u})]}),c&&(0,w.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>s(e=>!e),children:o?`Show less`:`Show more`})]})}function A(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 j(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 M(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 N({adminFetch:e,sessionKey:n,sessionRefetchNonce:r}){let[i,a]=(0,C.useState)(`.`),[o,c]=(0,C.useState)(null),[l,u]=(0,C.useState)([]),[d,f]=(0,C.useState)(!1),[p,y]=(0,C.useState)(null),[b,x]=(0,C.useState)(!1),[S,T]=(0,C.useState)(null),[E,D]=(0,C.useState)(null),[O,k]=(0,C.useState)(null),[A,j]=(0,C.useState)(null),M=(0,C.useRef)(null),[N,I]=(0,C.useState)(0);(0,C.useEffect)(()=>{let t=!1;return f(!0),y(null),e(`/api/admin/files?path=${encodeURIComponent(i===`.`?``:i)}`).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||(c(e.entries),u(e.displayPath??[]))}).catch(e=>{t||(c([]),u([]),y(e instanceof Error?e.message:String(e)))}).finally(()=>{t||f(!1)}),()=>{t=!0}},[e,i,N,r]);let L=(0,C.useCallback)(e=>{a(e)},[]),R=(0,C.useCallback)(()=>{if(i===`.`||i===``)return;let e=i.split(`/`).filter(Boolean);e.pop(),a(e.length===0?`.`:e.join(`/`))},[i]),z=(0,C.useCallback)(e=>{let t=i===`.`?e.name:`${i}/${e.name}`,r=`/api/admin/files/download?session_key=${encodeURIComponent(n)}&path=${encodeURIComponent(t)}`,a=document.createElement(`a`);a.href=r,a.rel=`noopener noreferrer`,document.body.appendChild(a),a.click(),a.remove()},[i,n]),B=(0,C.useCallback)(()=>{M.current?.click()},[]),V=(0,C.useCallback)(e=>{D(null),j(e.name)},[]),H=(0,C.useCallback)(()=>{j(null)},[]),U=(0,C.useCallback)(async t=>{let n=i===`.`?t.name:`${i}/${t.name}`;D(null),j(null),k(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}`);I(e=>e+1)}catch(e){D(e instanceof Error?e.message:String(e))}finally{k(null)}},[i,e]);(0,C.useEffect)(()=>{if(!A)return;let e=e=>{e.key===`Escape`&&j(null)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[A]);let W=(0,C.useCallback)(async e=>{T(null),x(!0);try{let t=new FormData;t.append(`session_key`,n),t.append(`file`,e);let r=await fetch(`/api/admin/files/upload`,{method:`POST`,body:t}),i=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(i.error??`HTTP ${r.status}`);a(i.path.split(`/`).slice(0,-1).join(`/`)||`.`),I(e=>e+1)}catch(e){T(e instanceof Error?e.message:String(e))}finally{x(!1),M.current&&(M.current.value=``)}},[n]);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:B,disabled:b,children:[b?(0,w.jsx)(s,{size:14,className:`spin`}):(0,w.jsx)(v,{size:14}),` Upload`]}),(0,w.jsx)(`input`,{type:`file`,ref:M,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&W(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:()=>L(`.`),children:`data`}),l.map((e,t)=>{let n=l.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:()=>L(n),title:e.name,children:e.displayName??e.name})]},n)}),i!==`.`&&(0,w.jsxs)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-up-btn`,onClick:R,children:[(0,w.jsx)(m,{size:14}),` Up`]})]}),S&&(0,w.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,S]}),E&&(0,w.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,E]}),p&&(0,w.jsx)(`div`,{className:`data-error`,children:p}),d&&(0,w.jsxs)(`div`,{className:`data-loading`,children:[(0,w.jsx)(s,{size:14,className:`spin`}),` Loading…`]}),!d&&o&&o.length===0&&!p&&(0,w.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!d&&o&&o.length>0&&(0,w.jsx)(`ul`,{className:`data-entries`,children:o.map(e=>{let n=e.displayName??e.name,r=O===e.name,a=A===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:()=>L(i===`.`?e.name:`${i}/${e.name}`),children:[(0,w.jsx)(_,{size:14}),(0,w.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:n})]}):e.kind===`file`?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onClick:()=>z(e),title:`Download ${n}`,disabled:a,children:[(0,w.jsx)(g,{size:14}),(0,w.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:n}),(0,w.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${F(e.modifiedAt)}`,children:[P(e.sizeBytes),` · `,F(e.modifiedAt)]}),(0,w.jsx)(h,{size:12,className:`data-entry-download-icon`})]}),a?(0,w.jsxs)(`div`,{className:`data-entry-confirm`,role:`group`,"aria-label":`Confirm delete ${n}`,children:[(0,w.jsx)(`span`,{className:`data-entry-confirm-label`,children:`Delete?`}),(0,w.jsx)(`button`,{type:`button`,className:`data-entry-confirm-yes`,onClick:()=>U(e),autoFocus:!0,children:`Yes`}),(0,w.jsx)(`button`,{type:`button`,className:`data-entry-confirm-no`,onClick:H,children:`No`})]}):(0,w.jsx)(`button`,{type:`button`,className:`data-entry-delete`,onClick:()=>V(e),disabled:r,title:`Delete ${n}`,"aria-label":`Delete ${n}`,children:r?(0,w.jsx)(s,{size:14,className:`spin`}):(0,w.jsx)(t,{size:14})})]}):(0,w.jsxs)(`div`,{className:`data-entry-btn data-entry-disabled`,children:[(0,w.jsx)(g,{size:14}),(0,w.jsx)(`span`,{className:`data-entry-name`,children:n}),(0,w.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})},e.name)})})]})}function P(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 F(e){try{let t=new Date(e);if(isNaN(t.getTime()))return`—`;let n=typeof navigator<`u`?navigator.languages&&navigator.languages.length>0?[...navigator.languages]:[navigator.language]:void 0;return t.toLocaleString(n,{dateStyle:`medium`,timeStyle:`short`})}catch{return`—`}}export{h as a,g as i,E as n,S as r,T as t};
@@ -1,5 +0,0 @@
1
- import{o as e}from"./chunk-DD-I1_y5.js";import{i as t,o as n,r,t as i}from"./jsx-runtime-B8sGPXtT.js";import{A as a,C as o,D as s,F as c,I as l,N as u,P as d,T as f,_ as p,a as m,b as h,c as g,g as _,i as v,j as y,n as b,o as x,r as S,s as C,t as w,u as T,v as E,w as D,x as O,y as k}from"./useVoiceRecorder-DVVSQc-9.js";import{t as A}from"./Checkbox-BsqexMy3.js";var j=r(`square-plus`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]]),M=t(),N=e(n(),1),P=`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`,F=new Set(P.split(`,`).filter(e=>!e.startsWith(`.`))),I=50*1024*1024,L=typeof window<`u`&&/^(localhost|127\.0\.0\.1|[a-z0-9-]+\.local)(:|$)/.test(window.location.hostname);function R(){let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function z(){let e=window.location.pathname;if(e.startsWith(`/g/`))return;let t=e.match(/^\/([a-z][a-z0-9-]{2,49})$/);return t?t[1]:void 0}function B(){let e=window.location.pathname.match(/^\/g\/([a-z0-9][a-z0-9-]{0,49})$/);return e?e[1]:void 0}function V(e){return[{key:`length`,label:`At least 8 characters`,met:e.length>=8},{key:`number`,label:`Contains a number`,met:/\d/.test(e)},{key:`special`,label:`Contains a special character`,met:/[^A-Za-z0-9]/.test(e)},{key:`whitespace`,label:`No spaces`,met:e.length>0&&!/\s/.test(e)}]}function H(e,t){if(t===`phone`)return e.length>4?e.slice(0,e.length-4).replace(/\d/g,`•`)+` `+e.slice(-4):e;let n=e.indexOf(`@`);return n<=2?e:e.slice(0,2)+`•••`+e.slice(n)}function ee(e){let[t,n]=(0,N.useState)(null),[r,i]=(0,N.useState)(null),[a,o]=(0,N.useState)(`loading`),[s,c]=(0,N.useState)(``),[l,u]=(0,N.useState)(null),[d,f]=(0,N.useState)(null),[p,m]=(0,N.useState)(!1),[h,g]=(0,N.useState)(null),_=(0,N.useMemo)(()=>z(),[]),v=(0,N.useMemo)(()=>B(),[]),[y,b]=(0,N.useState)(null),x=(0,N.useRef)(_||``),S=(0,N.useRef)(null),C=(0,N.useRef)(null),w=(0,N.useRef)(!1),T=(0,N.useRef)(null),[E,D]=(0,N.useState)(`sign-in`),[O,k]=(0,N.useState)(null),A=(0,N.useRef)(null),j=(0,N.useRef)(null);(0,N.useEffect)(()=>{try{let e=sessionStorage.getItem(`maxy_session`);e&&(j.current=e)}catch{}},[]);let M=(0,N.useCallback)(t=>{S.current=t,n(t);try{sessionStorage.setItem(`maxy_session`,t)}catch{}o(`chat`),e(t)},[e]),P=(0,N.useCallback)(()=>{S.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}n(null),o(`auth-required`),D(`sign-in`)},[]),F=(0,N.useCallback)(async e=>{try{let t=x.current,n=await fetch(`/api/access/verify-token`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:e,agentSlug:t})}),r=await n.json();n.ok?(A.current=r.session_key,k(r.grant),D(`set-password`),window.history.replaceState({},``,window.location.pathname)):D(`link-expired`)}catch{D(`sign-in`)}},[]),I=(0,N.useCallback)(async()=>{if(S.current)return S.current;if(C.current)return C.current;let e=(async()=>{try{let e=j.current,t=await fetch(`/api/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_id:R(),..._?{agent:_}:{},...v?{group_slug:v}:{},...e?{session_key:e}:{}})});if(!t.ok){let e=await t.json().catch(()=>({error:``}));return L&&console.error(`[session] POST /api/session failed: ${t.status} ${t.statusText}`,e),t.status===404?i(e.error||`Agent not found`):t.status===503&&i(e.error||`Service unavailable`),null}let r=await t.json();if(r.auth_required){r.agent_id&&(x.current=r.agent_id),c(r.displayName||``),r.agentImage&&u(r.agentImage),r.agentImageShape&&f(r.agentImageShape),r.showAgentName&&m(r.showAgentName),r.branding&&g(r.branding),o(`auth-required`);let e=new URLSearchParams(window.location.search).get(`token`);return e?F(e):D(`sign-in`),null}S.current=r.session_key,n(r.session_key),r.displayName&&c(r.displayName),r.agentImage&&u(r.agentImage),r.agentImageShape&&f(r.agentImageShape),r.showAgentName&&m(r.showAgentName),r.branding&&g(r.branding),o(`chat`),r.resumed&&r.messages&&(w.current=!0,T.current=r.messages),r.group&&b({groupSlug:r.groupSlug,groupName:r.groupName,participants:r.participants??[]});try{sessionStorage.setItem(`maxy_session`,r.session_key)}catch{}return r.session_key}catch(e){return L&&console.error(`[session] fetch /api/session threw:`,e),i(`Unable to connect. Please check your connection and try again.`),null}finally{C.current=null}})();return C.current=e,e},[_,v,F]);return{sessionId:t,sessionKeyRef:S,sessionError:r,pageState:a,setPageState:o,agentDisplayName:s,agentImage:l,agentImageShape:d,showAgentName:p,agentSlug:_,branding:h,resolvedSlugRef:x,ensureSession:I,startNewSession:(0,N.useCallback)(async()=>{S.current=null,C.current=null,j.current=null,w.current=!1,T.current=null,n(null),i(null);try{sessionStorage.removeItem(`maxy_session`)}catch{}let t=await I();t&&e(t)},[I,e]),enterChat:M,enterGate:P,resumedRef:w,resumeMessagesRef:T,gateState:E,setGateState:D,grantInfo:O,setGrantInfo:k,gateSessionKeyRef:A,groupContext:y,groupSlug:v}}function te({sessionKeyRef:e,ensureSession:t,sessionError:n,pageState:r,inputRef:i}){let[a,s]=(0,N.useState)([]),[c,l]=(0,N.useState)(!1),u=(0,N.useRef)(!1),d=e=>{u.current=e,l(e)},f=(0,N.useCallback)(async a=>{if(!u.current){d(!0),s([{role:`maxy`,content:``,timestamp:Date.now()}]);try{let n=await fetch(`/api/chat`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({greeting:!0,session_key:a})});if(n.status===401){e.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}L&&console.warn(`[greeting] stale session, retrying with fresh session`);let r=await t();if(!r)return;n=await fetch(`/api/chat`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({greeting:!0,session_key:r})})}if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error||`Something went wrong`)}let r=``,i=``,c=()=>{i&&(r+=i,i=``,s(e=>{let t=[...e];return t[0]={...t[0],content:r},t}))},l=setInterval(c,60);try{for await(let e of o(n)){if(e.error)throw Object.assign(Error(e.error),{fromSSE:!0});e.text&&(i+=e.text),e.type===`component`&&(c(),s(t=>{let n=[...t],r={...n[0]},i=[...r.components||[]];return i.push({name:e.name,data:e.data,submitted:!1}),n[0]={...r,components:i},n}))}}finally{clearInterval(l),c()}}catch(e){if(L&&console.error(`[chat] greeting failed:`,e),r===`auth-required`)return;let t=e instanceof Error?e.message:String(e);s([{role:`maxy`,content:e instanceof Error&&e.fromSSE?t:n??`I'm having trouble connecting right now. Try refreshing the page.`,timestamp:Date.now()}])}finally{d(!1),r===`chat`&&i.current?.focus()}}},[e,t,n,r,i]),p=(0,N.useCallback)(async(a,c)=>{let l=c?.hidden??!1,f=c?.files??[];if(!a&&f.length===0||u.current)return;d(!0);let p=f.map(e=>({filename:e.name,mimeType:e.type})),m={role:`visitor`,content:a,attachments:p.length>0?p:void 0,timestamp:Date.now(),hidden:l},h;s(e=>{let t=[...e,m,{role:`maxy`,content:``,timestamp:Date.now()}];return h=t.length-1,t});try{let n=await t();if(!n)throw Error(`session`);let r=e=>{if(f.length>0){let t=new FormData;t.append(`message`,a),t.append(`session_key`,e);for(let e of f)t.append(`attachments`,e);return{body:t,headers:{}}}return{body:JSON.stringify({message:a,session_key:e}),headers:{"Content-Type":`application/json`}}},{body:i,headers:c}=r(n),l=await fetch(`/api/chat`,{method:`POST`,headers:c,body:i});if(l.status===401){e.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}L&&console.warn(`[session-expired] stale key cleared, retrying with fresh session`);let n=await t();if(!n)throw Error(`session`);({body:i,headers:c}=r(n)),l=await fetch(`/api/chat`,{method:`POST`,headers:c,body:i})}if(!l.ok){let e=await l.json().catch(()=>({}));throw Error(e.error||`Something went wrong`)}let u=``,d=``,p=()=>{d&&(u+=d,d=``,s(e=>{let t=[...e];return t[h]={...t[h],content:u},t}))},m=setInterval(p,60);try{for await(let e of o(l)){if(e.error)throw Object.assign(Error(e.error),{fromSSE:!0});e.text&&(d+=e.text),e.type===`component`&&(p(),s(t=>{let n=[...t],r={...n[h]},i=[...r.components||[]];return i.push({name:e.name,data:e.data,submitted:!1}),n[h]={...r,components:i},n}))}}finally{clearInterval(m),p()}}catch(e){if(L&&console.error(`[chat] sendMessage failed:`,e),r===`auth-required`)return;let t=e instanceof Error?e.message:String(e),i=e instanceof Error&&e.fromSSE;s(e=>{let r=[...e];return r[h]={...r[h],content:i?t:t===`session`?n??`I'm having trouble connecting right now. Try refreshing the page.`:`Sorry, I hit a snag. Try again in a moment.`},r})}finally{d(!1),r===`chat`&&i.current?.focus()}},[e,t,n,r,i]);return{messages:a,setMessages:s,isStreaming:c,sendMessage:p,sendGreeting:f,handleComponentSubmit:(0,N.useCallback)((e,t,n)=>{s(n=>{let r=[...n],i={...r[e]},a=[...i.components||[]];return a[t]={...a[t],submitted:!0},r[e]={...i,components:a},r}),p(n,{hidden:!0})},[p])}}function ne({sessionKeyRef:e,groupSlug:t,isStreaming:n,setMessages:r}){let i=(0,N.useRef)(new Date().toISOString()),a=(0,N.useRef)(!0);(0,N.useEffect)(()=>{let e=()=>{a.current=document.visibilityState===`visible`};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]);let o=(0,N.useCallback)(async()=>{let n=e.current;if(!(!n||!t))try{let e=await fetch(`/api/group/messages?session_key=${encodeURIComponent(n)}&since=${encodeURIComponent(i.current)}`);if(!e.ok)return;let t=await e.json();if(!t.messages||t.messages.length===0)return;let a=t.messages[t.messages.length-1];a.timestamp&&(i.current=new Date(a.timestamp).toISOString()),r(e=>{let n=new Set(e.filter(e=>e.messageId).map(e=>e.messageId)),r=t.messages.filter(e=>!n.has(e.messageId)).map(e=>({role:e.role,content:e.content,timestamp:e.timestamp,senderName:e.senderName??void 0,senderVisitorId:e.senderVisitorId??void 0,messageId:e.messageId}));if(r.length===0)return e;let i=[...e,...r];return i.sort((e,t)=>e.timestamp-t.timestamp),i})}catch(e){console.error(`[group-poll] failed: ${e instanceof Error?e.message:String(e)}`)}},[e,t,r]);(0,N.useEffect)(()=>{if(!t)return;let e,r=!1;function i(){if(r)return;let t=a.current?3e3:3e4;e=setTimeout(async()=>{n||await o(),i()},t)}return i(),()=>{r=!0,clearTimeout(e)}},[t,n,o])}var U=i();function W({value:e,onChange:t,onComplete:n,disabled:r}){let i=(0,N.useRef)([]);function a(n,r){r.key===`Backspace`?(r.preventDefault(),e[n]?t(e.slice(0,n)+e.slice(n+1)):n>0&&(t(e.slice(0,n-1)+e.slice(n)),i.current[n-1]?.focus())):r.key===`ArrowLeft`&&n>0?i.current[n-1]?.focus():r.key===`ArrowRight`&&n<5&&i.current[n+1]?.focus()}function o(r,a){let o=a.nativeEvent.data;if(!o||!/^\d$/.test(o))return;let s=e.split(``);for(s[r]=o;s.length<r;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);t(c),c.length===6?n(c):r<5&&i.current[r+1]?.focus()}function s(e){e.preventDefault();let r=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);r&&(t(r),r.length===6?n(r):i.current[r.length]?.focus())}return(0,U.jsx)(`div`,{className:`gate-otp-field`,children:Array.from({length:6}).map((t,n)=>(0,U.jsx)(`input`,{ref:e=>{i.current[n]=e},type:`text`,inputMode:`numeric`,className:`pin-box${e[n]?` pin-box-filled`:``}`,value:e[n]||``,onKeyDown:e=>a(n,e),onInput:e=>o(n,e),onPaste:s,onFocus:e=>e.target.select(),autoFocus:n===0,autoComplete:`off`,maxLength:1,disabled:r,"aria-label":`Code digit ${n+1}`},n))})}function re({gateState:e,setGateState:t,grantInfo:n,setGrantInfo:r,gateSessionKeyRef:i,resolvedSlugRef:a,onAuthenticated:o}){let[s,c]=(0,N.useState)(``),[l,u]=(0,N.useState)(``),[d,f]=(0,N.useState)(``),[p,m]=(0,N.useState)(!1),[h,g]=(0,N.useState)(``),[v,y]=(0,N.useState)(``),[b,x]=(0,N.useState)(!1),[S,C]=(0,N.useState)(null),[w,T]=(0,N.useState)(null),[E,D]=(0,N.useState)(!1);async function O(e){if(e.preventDefault(),!E){C(null),D(!0);try{let e=a.current,n=await fetch(`/api/access/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({contact:s,password:l,agentSlug:e})}),i=await n.json();n.ok?o(i.session_key):n.status===401?i.error?.includes(`setup not complete`)||i.error?.includes(`invitation link`)?(t(`private-agent`),C(null)):C(i.error||`Invalid credentials`):n.status===403?(t(`access-expired`),i.expiresAt&&r(e=>e?{...e,expiresAt:i.expiresAt}:{displayName:null,contactValue:s,contactMethod:`email`,expiresAt:i.expiresAt,status:`expired`})):n.status===429?C(i.error||`Too many attempts. Please try again later.`):C(i.error||`Something went wrong`)}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}async function k(e){if(!E){C(null),D(!0);try{let n=a.current,o=await fetch(`/api/access/verify-otp`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({phone:v,code:e,agentSlug:n})}),s=await o.json();o.ok?(i.current=s.session_key,r(s.grant),t(`set-password`)):o.status===429?t(`otp-failed`):(C(s.error||`Invalid code`),g(``))}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}async function j(e){if(e.preventDefault(),!E){if(C(null),l!==d){C(`Passwords do not match`);return}if(!V(l).every(e=>e.met)){C(`Password does not meet requirements`);return}D(!0);try{let e=i.current;if(!e){C(`Session expired. Please use your invitation link again.`);return}let t=await fetch(`/api/access/create-credentials`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_key:e,password:l})}),n=await t.json();t.ok?o(n.session_key):t.status===400&&n.requirements?C(n.requirements.filter(e=>!e.met).map(e=>e.label).join(`, `)):C(n.error||`Something went wrong`)}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}async function M(e){if(e.preventDefault(),!(E||!s)){C(null),D(!0);try{let e=a.current,t=await fetch(`/api/access/forgot-password`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({contact:s,agentSlug:e})});t.status===429?C((await t.json()).error||`Too many attempts. Please try again later.`):(T(`If an account exists, a reset link has been sent.`),setTimeout(()=>{x(!1),T(null)},4e3))}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}switch(e){case`set-password`:{let e=V(l),t=e.every(e=>e.met),r=l===d,i=t&&r&&d.length>0;return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[n?.expiresAt&&(0,U.jsxs)(`div`,{className:`gate-expiry-badge`,children:[`Access until `,new Date(n.expiresAt).toLocaleDateString(`en-GB`,{day:`numeric`,month:`short`,year:`numeric`})]}),(0,U.jsxs)(`h2`,{className:`gate-title`,children:[`Welcome, `,n?.displayName||`there`]}),(0,U.jsx)(`p`,{className:`gate-subtitle`,children:`Create a password to access this agent in the future.`}),(0,U.jsxs)(`form`,{className:`gate-form`,onSubmit:j,children:[(0,U.jsxs)(`div`,{className:`gate-field`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-display-name`,children:`Display name`}),(0,U.jsx)(`input`,{id:`gate-display-name`,type:`text`,value:n?.displayName||``,disabled:!0})]}),(0,U.jsxs)(`div`,{className:`gate-field gate-pw-row`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-pw`,children:`Password`}),(0,U.jsx)(`div`,{className:`gate-pw-toggle`,children:(0,U.jsx)(A,{checked:p,onChange:m,label:`Show`})}),(0,U.jsx)(`input`,{id:`gate-pw`,type:p?`text`:`password`,value:l,onChange:e=>u(e.target.value),placeholder:`Your password`,autoFocus:!0,autoComplete:`new-password`}),l.length>0&&(0,U.jsx)(`div`,{className:`gate-strength`,children:e.map(e=>(0,U.jsxs)(`span`,{className:`gate-strength-item${e.met?` met`:``}`,children:[e.met?`✓`:`○`,` `,e.label]},e.key))})]}),(0,U.jsxs)(`div`,{className:`gate-field`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-pw-confirm`,children:`Confirm password`}),(0,U.jsx)(`input`,{id:`gate-pw-confirm`,type:p?`text`:`password`,value:d,onChange:e=>f(e.target.value),placeholder:`Confirm your password`,autoComplete:`new-password`}),d.length>0&&!r&&(0,U.jsx)(`div`,{className:`gate-error`,children:`Passwords do not match`})]}),S&&(0,U.jsx)(`div`,{className:`gate-error`,children:S}),(0,U.jsx)(`div`,{className:`gate-submit`,children:(0,U.jsx)(_,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!i||E,loading:E,children:`Create account & enter chat`})})]})]})})}case`enter-otp`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`h2`,{className:`gate-title`,children:`Enter your code`}),(0,U.jsxs)(`p`,{className:`gate-subtitle`,children:[`Enter the 6-digit code sent to `,H(v,`phone`)]}),(0,U.jsx)(W,{value:h,onChange:g,onComplete:k,disabled:E}),S&&(0,U.jsx)(`div`,{className:`gate-error`,children:S}),E&&(0,U.jsxs)(`div`,{className:`gate-loading`,children:[(0,U.jsx)(`span`,{className:`spinner`}),`Verifying...`]}),(0,U.jsx)(`div`,{className:`gate-resend`,children:(0,U.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{t(`sign-in`),g(``),C(null)},children:`Use a different number`})})]})});case`sign-in`:case`private-agent`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`h2`,{className:`gate-title`,children:e===`private-agent`?`Private Agent`:`Welcome back`}),(0,U.jsx)(`p`,{className:`gate-subtitle`,children:e===`private-agent`?`This agent is invitation-only. If you have an account, sign in below.`:`Sign in to continue your conversation.`}),b?(0,U.jsxs)(`form`,{className:`gate-form`,onSubmit:M,children:[(0,U.jsxs)(`div`,{className:`gate-field`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-forgot-contact`,children:`Email or phone`}),(0,U.jsx)(`input`,{id:`gate-forgot-contact`,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`you@example.com`,autoFocus:!0,autoComplete:`email`})]}),S&&(0,U.jsx)(`div`,{className:`gate-error`,children:S}),w&&(0,U.jsx)(`div`,{className:`gate-success`,children:w}),(0,U.jsx)(`div`,{className:`gate-submit`,children:(0,U.jsx)(_,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!s.trim()||E,loading:E,children:`Send reset link`})}),(0,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{x(!1),C(null),T(null)},children:`Back to sign in`})})]}):(0,U.jsxs)(`form`,{className:`gate-form`,onSubmit:O,children:[(0,U.jsxs)(`div`,{className:`gate-field`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-contact`,children:`Email or phone`}),(0,U.jsx)(`input`,{id:`gate-contact`,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`you@example.com`,autoFocus:!0,autoComplete:`email`})]}),(0,U.jsxs)(`div`,{className:`gate-field gate-pw-row`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-login-pw`,children:`Password`}),(0,U.jsx)(`div`,{className:`gate-pw-toggle`,children:(0,U.jsx)(A,{checked:p,onChange:m,label:`Show`})}),(0,U.jsx)(`input`,{id:`gate-login-pw`,type:p?`text`:`password`,value:l,onChange:e=>u(e.target.value),placeholder:`Your password`,autoComplete:`current-password`})]}),S&&(0,U.jsx)(`div`,{className:`gate-error`,children:S}),(0,U.jsx)(`div`,{className:`gate-submit`,children:(0,U.jsx)(_,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!s.trim()||!l||E,loading:E,children:`Sign in`})}),(0,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{x(!0),C(null)},children:`Forgot password?`})})]}),e===`private-agent`&&(0,U.jsx)(`p`,{className:`gate-hint`,children:`No account? You need an invitation from the agent owner.`})]})});case`access-expired`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`div`,{className:`gate-icon`,children:`⏰`}),(0,U.jsx)(`h2`,{className:`gate-title`,children:`Access expired`}),(0,U.jsxs)(`p`,{className:`gate-subtitle`,children:[n?.expiresAt?`Your access expired on ${new Date(n.expiresAt).toLocaleDateString(`en-GB`,{day:`numeric`,month:`long`,year:`numeric`})}.`:`Your access to this agent has expired.`,` `,`Contact the agent owner to renew.`]}),(0,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(_,{variant:`secondary`,onClick:()=>{t(`sign-in`),C(null),u(``)},children:`Sign in with a different account`})})]})});case`link-expired`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`div`,{className:`gate-icon`,children:`⚠️`}),(0,U.jsx)(`h2`,{className:`gate-title`,children:`Link expired`}),(0,U.jsx)(`p`,{className:`gate-subtitle`,children:`This invitation link has expired or has already been used. If you already set your password, sign in below. Otherwise, ask the agent owner to send a new invitation.`}),(0,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(_,{variant:`primary`,onClick:()=>{t(`sign-in`),C(null)},children:`Go to sign in`})})]})});case`otp-failed`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`div`,{className:`gate-icon`,children:`⛔`}),(0,U.jsx)(`h2`,{className:`gate-title`,children:`Too many attempts`}),(0,U.jsx)(`p`,{className:`gate-subtitle`,children:`You've entered the wrong code too many times. Ask the agent owner to send a new code.`}),(0,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(_,{variant:`secondary`,onClick:()=>{t(`sign-in`),C(null),g(``)},children:`Back to sign in`})})]})})}}var G={"single-select":g,"multi-select":C,"action-buttons":x};function K({name:e,data:t,onSubmit:n,submitted:r}){let i=G[e];return i?(0,U.jsx)(i,{data:t,onSubmit:n,submitted:r}):(console.warn(`[PublicComponentRenderer] Unknown component: "${e}". Registered: ${Object.keys(G).join(`, `)}`),(0,U.jsx)(`div`,{className:`component-card component-card--error`,children:(0,U.jsxs)(`p`,{style:{fontFamily:`var(--font-body)`,fontSize:12,color:`var(--text-secondary)`},children:[`Component “`,e,`” is not available. This may require a platform update.`]})}))}function ie({messages:e,isStreaming:t,sessionError:n,selectionMode:r,selectedItems:i,toggleSelectItem:a,onComponentSubmit:o,remainingSuggestions:s,onSuggestionClick:c,isAtBottom:f,setIsAtBottom:p,isGroup:h,sessionId:g}){let[v,y]=(0,N.useState)(new Set),[b,x]=(0,N.useState)(new Set),S=(0,N.useRef)(null),C=(0,N.useRef)(null),w=(0,N.useRef)(null),E=(0,N.useRef)(!1),D=(0,N.useRef)(!1),O=(0,N.useRef)(!1),k=(0,N.useRef)(0),j=(0,N.useRef)(!1),M=(0,N.useRef)(new Map);j.current=t,(0,N.useEffect)(()=>{t&&!E.current&&f&&(D.current=!0)},[t,f]),(0,N.useEffect)(()=>{if(!D.current&&!f){E.current=t,O.current=!1;return}if(E.current&&!t&&w.current&&C.current){let e=w.current;if(e.offsetHeight>C.current.clientHeight){D.current=!1,O.current=!0,e.scrollIntoView({behavior:`smooth`,block:`start`}),E.current=t;return}}(f||D.current)&&!O.current&&S.current?.scrollIntoView({behavior:`smooth`}),E.current&&!t&&(D.current=!1),E.current=t},[e,f,t]),(0,N.useEffect)(()=>{let e=C.current;if(!e)return;let t=()=>{let t=e.scrollTop;j.current&&t<k.current&&(D.current=!1),k.current=t,p(e.scrollHeight-e.scrollTop-e.clientHeight<80)};return e.addEventListener(`scroll`,t,{passive:!0}),t(),()=>e.removeEventListener(`scroll`,t)},[p]),(0,N.useEffect)(()=>{function e(){x(e=>{let t=new Set;return M.current.forEach((n,r)=>{n.isConnected&&(v.has(r)?e.has(r)&&t.add(r):n.scrollHeight>n.clientHeight+2&&t.add(r))}),e.size===t.size&&[...e].every(e=>t.has(e))?e:t})}e();let t=new ResizeObserver(e);return M.current.forEach(e=>t.observe(e)),()=>t.disconnect()},[e.length,v]);let P=[...e].sort((e,t)=>e.timestamp-t.timestamp);(0,N.useEffect)(()=>{r&&console.log(`[selection] entered`,{conversationId:g??`unknown`,order:P.map(e=>({ts:e.timestamp,role:e.role,id:e.messageId}))})},[r]);let F=P.reduce((e,t,n)=>t.role===`maxy`&&!t.hidden?n:e,-1);return(0,U.jsxs)(`div`,{className:`chat-messages-wrap`,children:[r&&(0,U.jsx)(`div`,{className:`selection-overlay-band`}),(0,U.jsxs)(`div`,{className:`chat-messages`,ref:C,children:[n&&e.length===0&&(0,U.jsx)(`div`,{className:`session-error`,children:(0,U.jsx)(`p`,{children:n})}),P.map((e,n)=>{if(e.hidden)return null;let s=t&&n===P.length-1,c=`${e.timestamp}_${e.role}`,f=i.has(c);return(0,U.jsxs)(`div`,{ref:n===F?w:void 0,className:`message ${e.role}${f?` selected`:``}`,children:[r&&!s&&(0,U.jsx)(`div`,{className:`message-select-check`,children:(0,U.jsx)(A,{checked:f,onChange:()=>a(c)})}),(0,U.jsxs)(`div`,{className:`bubble`,children:[h&&e.role===`visitor`&&e.senderName&&(0,U.jsx)(`span`,{className:`bubble-sender`,children:e.senderName}),e.role===`visitor`&&e.content?(()=>{let t=v.has(n),r=b.has(n);return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`div`,{ref:e=>{e?M.current.set(n,e):M.current.delete(n)},className:t?`bubble-content`:`bubble-content clamped${r?` overflowing`:``}`,children:e.content}),r&&(0,U.jsx)(`div`,{className:`bubble-expand`,children:(0,U.jsx)(_,{variant:`icon`,className:t?`expanded`:``,onClick:()=>y(e=>{let t=new Set(e);return t.has(n)?t.delete(n):t.add(n),t}),"aria-label":t?`Collapse message`:`Expand message`,children:(0,U.jsx)(l,{size:14})})})]})})():e.content?(0,U.jsx)(T,{content:e.content,timestamp:m(e.timestamp)}):(0,U.jsxs)(`span`,{className:`typing-indicator`,children:[(0,U.jsx)(`span`,{className:`typing-dot`}),(0,U.jsx)(`span`,{className:`typing-dot`}),(0,U.jsx)(`span`,{className:`typing-dot`})]}),e.attachments&&e.attachments.length>0&&(0,U.jsx)(`div`,{className:`message-attachments`,children:e.attachments.map((e,t)=>(0,U.jsxs)(`span`,{className:`message-attachment-chip no-action`,children:[e.mimeType===`application/pdf`?(0,U.jsx)(u,{size:12}):e.mimeType.startsWith(`text/`)?(0,U.jsx)(d,{size:12}):null,(0,U.jsx)(`span`,{children:e.filename})]},t))}),e.role===`visitor`&&(0,U.jsx)(`span`,{className:`message-timestamp`,children:m(e.timestamp)})]}),e.role===`maxy`&&e.components&&e.components.length>0&&(0,U.jsx)(`div`,{className:`public-components`,children:e.components.map((e,t)=>(0,U.jsx)(`div`,{className:`public-component-enter`,children:(0,U.jsx)(K,{name:e.name,data:e.data,onSubmit:e=>o(n,t,e),submitted:e.submitted})},t))})]},n)}),!t&&s.length>0&&(0,U.jsx)(`div`,{className:`chat-suggestions`,children:s.map(e=>(0,U.jsx)(_,{variant:`suggestion`,onClick:()=>c(e),children:e},e))}),(0,U.jsx)(`div`,{ref:S})]}),!f&&(0,U.jsx)(`button`,{className:`scroll-to-bottom`,onClick:()=>S.current?.scrollIntoView({behavior:`smooth`}),"aria-label":`Scroll to bottom`,children:(0,U.jsx)(l,{size:18})})]})}function ae({selectedItems:e,messages:t,isStreaming:n,copySelected:r,selectAll:i,exitSelection:a,showCopyToast:o}){let[l,u]=(0,N.useState)(!1),d=(0,N.useRef)(null),f=(0,N.useRef)(!1);function p(e){let n=e.lastIndexOf(`_`),r=e.slice(0,n),i=e.slice(n+1),a=parseInt(r,10);return t.find(e=>e.timestamp===a&&e.role===i)?.content??``}function m(e,t){return parseInt(e.slice(0,e.lastIndexOf(`_`)),10)-parseInt(t.slice(0,t.lastIndexOf(`_`)),10)}function h(){let e=[...t].sort((e,t)=>e.timestamp-t.timestamp),n=[];for(let t of e){if(t.hidden||!t.content)continue;let e=t.role===`visitor`?`Visitor`:`Maxy`;n.push(`${e}:\n${t.content}`)}return n.join(`
2
-
3
- ---
4
-
5
- `)}N.useEffect(()=>{if(!l)return;let e=e=>{e.target.closest(`.selection-copy-wrap`)||u(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[l]);function g(){d.current!==null&&(clearTimeout(d.current),d.current=null)}let _=[...t].sort((e,t)=>e.timestamp-t.timestamp),v=_.reduce((e,t,r)=>(t.hidden||n&&r===_.length-1||e.push(`${t.timestamp}_${t.role}`),e),[]),y=v.length>0&&v.every(t=>e.has(t));return(0,U.jsx)(`div`,{className:`chat-input-area`,children:(0,U.jsxs)(`div`,{className:`selection-bar`,children:[(0,U.jsxs)(`div`,{className:`selection-bar-left`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`selection-select-all`,onClick:()=>i(v),disabled:v.length===0,"aria-label":y?`Deselect all`:`Select all`,title:y?`Deselect all`:`Select all`,children:[(0,U.jsx)(s,{size:16}),(0,U.jsx)(`span`,{children:y?`Deselect all`:`Select all`})]}),(0,U.jsxs)(`span`,{className:`selection-count`,children:[e.size,` Selected`]})]}),(0,U.jsxs)(`div`,{className:`selection-copy-wrap`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`selection-copy`,onPointerDown:()=>{if(l){u(!1);return}f.current=!1,d.current=setTimeout(()=>{f.current=!0,u(!0),d.current=null},500)},onPointerUp:g,onPointerLeave:g,onPointerCancel:g,onClick:async()=>{f.current||await r(p,m)},children:[(0,U.jsx)(c,{size:18}),(0,U.jsx)(`span`,{children:`Copy`})]}),l&&(0,U.jsx)(`div`,{className:`copy-menu`,children:(0,U.jsx)(`button`,{type:`button`,className:`copy-menu-item`,onClick:async()=>{let e=h();e&&o(await D(e)),a()},children:`Copy all`})})]}),(0,U.jsx)(`button`,{type:`button`,className:`selection-cancel`,onClick:a,children:`Cancel`})]})})}function oe({input:e,setInput:t,isStreaming:n,pendingFiles:r,setPendingFiles:i,attachError:o,setAttachError:s,isDragOver:c,setIsDragOver:l,inputRef:f,onSubmit:m,onSendVoiceNote:h}){let g=(0,N.useRef)(null),x=w(),C=x.state===`recording`||x.state===`paused`||x.state===`sending`,T=!C&&!n&&!e.trim()&&r.length===0;async function D(){let e=await x.send();if(!e)return;let t=e.type===`audio/ogg`?`.ogg`:e.type===`audio/mp4`?`.m4a`:`.webm`;h(new File([e],`voice-note${t}`,{type:e.type}))}function O(e){s(null);let t=e.map(p),n=t.find(e=>!E(e.type,F));if(n){s(`Unsupported file type: "${n.type}". Supported: images, PDF, plain text, markdown, CSV, calendar, voice notes.`);return}let r=t.find(e=>e.size>I);if(r){s(`"${r.name}" exceeds the 50 MB limit.`);return}i(e=>[...e,...t].slice(0,5))}function k(e){e.preventDefault(),l(!0)}function A(){l(!1)}function j(e){e.preventDefault(),l(!1),O([...e.dataTransfer.files])}return(0,U.jsxs)(`div`,{className:`chat-input-area`,children:[(0,U.jsx)(`input`,{ref:g,type:`file`,multiple:!0,accept:P,style:{display:`none`},onChange:e=>{e.target.files&&O([...e.target.files]),e.target.value=``}}),r.length>0&&(0,U.jsx)(`div`,{className:`attachment-strip`,children:r.map((e,t)=>(0,U.jsxs)(`div`,{className:`attachment-chip`,children:[e.type.startsWith(`image/`)?(0,U.jsx)(`img`,{src:URL.createObjectURL(e),alt:e.name,className:`attachment-chip-thumb`}):e.type.startsWith(`audio/`)?(0,U.jsx)(y,{size:14}):e.type===`application/pdf`?(0,U.jsx)(u,{size:14}):(0,U.jsx)(d,{size:14}),(0,U.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,U.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>i(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),o&&(0,U.jsx)(`p`,{className:`attach-error`,children:o}),x.state===`error`&&x.errorMessage&&(0,U.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,U.jsx)(y,{size:14}),x.errorMessage]}),(0,U.jsx)(v,{inputRef:f}),C?(0,U.jsx)(`div`,{className:`chat-form voice-active`,children:(0,U.jsx)(b,{state:x.state,elapsedSeconds:x.elapsedSeconds,waveform:x.waveform,onTogglePause:x.togglePause,onDiscard:x.discard,onSend:D})}):(0,U.jsxs)(`form`,{className:`chat-form${c?` drag-over`:``}`,onSubmit:m,onDragOver:k,onDragLeave:A,onDrop:j,onPaste:e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t){if(e.kind!==`file`)continue;let t=e.getAsFile();if(!t)continue;let r=t.type.split(`/`)[1]?.replace(`jpeg`,`jpg`)||`png`;n.push(new File([t],`pasted-image-${Date.now()}.${r}`,{type:t.type}))}n.length>0&&O(n)},children:[(0,U.jsx)(_,{variant:`icon`,type:`button`,onClick:()=>g.current?.click(),disabled:n,"aria-label":`Attach file`,children:(0,U.jsx)(a,{size:14})}),(0,U.jsx)(S,{ref:f,value:e,onChange:t}),T?(0,U.jsx)(_,{variant:`send`,type:`button`,onClick:x.start,disabled:n,"aria-label":`Record voice note`,children:(0,U.jsx)(y,{size:14})}):(0,U.jsx)(_,{variant:`send`,type:`submit`,disabled:n||!e.trim()&&r.length===0,"aria-label":`Send message`,children:(0,U.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,U.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,U.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]})]})}var q=[];function J(){let[e,t]=(0,N.useState)(``),[n,r]=(0,N.useState)([]),[i,a]=(0,N.useState)(!1),[o,c]=(0,N.useState)(null),[l,u]=(0,N.useState)(q),[d,p]=(0,N.useState)(!0),m=(0,N.useRef)(null),{selectionMode:g,selectedItems:_,copyToast:v,exitSelection:y,enterSelection:b,toggleSelectItem:x,selectAll:S,copySelected:C,showCopyToast:w}=f(),T=(0,N.useRef)(()=>{}),E=ee((0,N.useCallback)(e=>{T.current(e)},[])),{sessionId:D,sessionKeyRef:A,sessionError:M,pageState:P,agentDisplayName:F,agentImage:I,agentImageShape:L,showAgentName:R,branding:z,ensureSession:B,startNewSession:V,resumedRef:H,resumeMessagesRef:W,groupContext:G,groupSlug:K}=E,{messages:J,setMessages:Y,isStreaming:X,sendMessage:Z,sendGreeting:Q,handleComponentSubmit:se}=te({sessionKeyRef:A,ensureSession:B,sessionError:M,pageState:P,inputRef:m});(0,N.useEffect)(()=>{T.current=Q},[Q]),ne({sessionKeyRef:A,groupSlug:K,isStreaming:X,setMessages:Y}),(0,N.useEffect)(()=>{let e=!1;return(async()=>{let t=await B();if(!e&&t){if(H.current&&W.current&&W.current.length>0){let e=W.current.map(e=>({role:e.role,content:e.content,timestamp:e.timestamp}));e.sort((e,t)=>e.timestamp-t.timestamp),Y(e),W.current=null;return}Q(t)}})(),()=>{e=!0}},[]),(0,N.useEffect)(()=>{P===`chat`&&m.current?.focus()},[P]),(0,N.useEffect)(()=>{if(P!==`chat`)return;history.pushState({maxyChat:!0},``);function e(){history.pushState({maxyChat:!0},``)}return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[P]),(0,N.useEffect)(()=>{if(!z)return;let e=document.documentElement;if(z.primaryColor&&(e.style.setProperty(`--sage`,z.primaryColor),e.style.setProperty(`--sage-hover`,z.primaryColor),e.style.setProperty(`--sage-subtle`,z.primaryColor+`14`),e.style.setProperty(`--sage-glow`,z.primaryColor+`26`)),z.accentColor&&e.style.setProperty(`--visitor-bubble`,z.accentColor),z.backgroundColor&&e.style.setProperty(`--bg`,z.backgroundColor),document.title=z.name,z.primaryColor){let e=document.querySelector(`meta[name="theme-color"]`);e||(e=document.createElement(`meta`),e.name=`theme-color`,document.head.appendChild(e)),e.content=z.primaryColor}if(z.faviconUrl){let e=document.querySelector(`link[rel="icon"]`);e||(e=document.createElement(`link`),e.rel=`icon`,document.head.appendChild(e)),e.href=z.faviconUrl}},[z]),(0,N.useEffect)(()=>{function e(e){e.key===`Escape`&&g&&y()}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g,y]);function ce(){X||(Y([]),u(q),V())}function $(e){if(!e&&n.length===0||X)return;Y(e=>e.map(e=>e.components?.some(e=>!e.submitted)?{...e,components:e.components.map(e=>e.submitted?e:{...e,submitted:!0})}:e)),u(t=>t.filter(t=>t!==e)),p(!0);let i=[...n];t(``),r([]),c(null),Z(e,{files:i})}function le(t){t.preventDefault(),$(e.trim()),m.current?.resetHeight()}return(0,U.jsxs)(`div`,{className:`chat-page`,children:[(0,U.jsxs)(`header`,{className:`chat-header`,children:[(0,U.jsx)(`img`,{src:I||z?.logoUrl||O,alt:z?.name||k.productName,className:`chat-logo${I&&L===`circle`?` chat-logo--circle`:``}${I&&L===`rounded`?` chat-logo--rounded`:``}`,onError:e=>{e.target.src=z?.logoUrl||O}}),(0,U.jsxs)(`div`,{className:`chat-header-text`,children:[R!==`none`&&(0,U.jsx)(`h1`,{className:`chat-tagline`,children:G?.groupName||R&&F||z?.name||k.productName}),(0,U.jsx)(`p`,{className:`chat-intro`,children:G?`${G.participants.length} participants`:z?.tagline||``}),(0,U.jsx)(`p`,{className:`chat-ai-indicator`,children:`AI assistant`})]}),P===`chat`&&!g&&(0,U.jsxs)(`div`,{className:`chat-header-actions`,children:[(0,U.jsx)(`button`,{className:`chat-header-action`,onClick:ce,disabled:X,title:`New conversation`,"aria-label":`New conversation`,children:(0,U.jsx)(j,{size:16})}),(0,U.jsx)(`button`,{className:`chat-header-action`,onClick:b,title:`Select messages`,"aria-label":`Select messages`,children:(0,U.jsx)(s,{size:16})})]})]}),P===`loading`&&(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsx)(`div`,{className:`gate-loading`,children:(0,U.jsx)(`span`,{className:`spinner`})})}),P===`auth-required`&&(0,U.jsx)(re,{gateState:E.gateState,setGateState:E.setGateState,grantInfo:E.grantInfo,setGrantInfo:E.setGrantInfo,gateSessionKeyRef:E.gateSessionKeyRef,resolvedSlugRef:E.resolvedSlugRef,onAuthenticated:E.enterChat}),P===`chat`&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(ie,{messages:J,isStreaming:X,sessionError:M,selectionMode:g,selectedItems:_,toggleSelectItem:x,onComponentSubmit:se,remainingSuggestions:l,onSuggestionClick:$,isAtBottom:d,setIsAtBottom:p,isGroup:!!G,sessionId:D}),g?(0,U.jsx)(ae,{selectedItems:_,messages:J,isStreaming:X,copySelected:C,selectAll:S,exitSelection:y,showCopyToast:w}):(0,U.jsx)(oe,{input:e,setInput:t,isStreaming:X,pendingFiles:n,setPendingFiles:r,attachError:o,setAttachError:c,isDragOver:i,setIsDragOver:a,inputRef:m,onSubmit:le,onSendVoiceNote:e=>{t(``),r([]),c(null),Z(`[Voice note]`,{files:[e]})}})]}),v&&(0,U.jsx)(`span`,{className:`copy-toast${v===`failed`?` copy-toast-failed`:``}`,children:v===`copied`?`Copied`:`Copy failed`}),(0,U.jsxs)(`footer`,{className:`chat-footer`,children:[(0,U.jsxs)(`a`,{href:h,children:[k.domain,` `,`↗`]}),D&&(0,U.jsxs)(`span`,{style:{opacity:.35,fontSize:`10px`,fontFamily:`monospace`,marginLeft:`1rem`},children:[`Conversation · `,D.slice(0,8)]})]})]})}(0,M.createRoot)(document.getElementById(`root`)).render((0,U.jsx)(J,{}));