@lobu/runtime-server 24.10.0 → 24.11.0

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 (172) hide show
  1. package/dist/catalogs/connectors.json +1 -1
  2. package/dist/component.json +1 -1
  3. package/dist/connectors/linkedin-inbox-adapter.js +13 -3
  4. package/dist/connectors/whatsapp-web-adapter.js +14 -13
  5. package/dist/connectors/whatsapp-web-helpers.ts +37 -1
  6. package/dist/connectors/whatsapp_web.ts +5 -5
  7. package/dist/connectors/x-dm-adapter.js +17 -3
  8. package/dist/db/migrations/20261113170000_member_sql_rls.sql +254 -0
  9. package/dist/db/migrations/20261113180000_member_sql_rls_parallel_plans.sql +192 -0
  10. package/dist/db/migrations/20261113190000_member_sql_schema_usage.sql +24 -0
  11. package/dist/db/migrations/20261114120000_events_owner_only_visibility.sql +39 -0
  12. package/dist/dependencies.bun.lock +10 -10
  13. package/dist/embeddings-server.mjs +1 -1
  14. package/dist/guest.bundle.js +1 -1
  15. package/dist/owletto/dist/assets/_-BDMUN9XZ.js +2 -0
  16. package/dist/owletto/dist/assets/_-CF5X4ANe.js +3 -0
  17. package/dist/owletto/dist/assets/{_agentId-DN0EwMAC.js → _agentId-CGScf8z_.js} +2 -2
  18. package/dist/owletto/dist/assets/_agentId-EQU2aUP0.js +2 -0
  19. package/dist/owletto/dist/assets/_automationId-PXZ33jsF.js +2 -0
  20. package/dist/owletto/dist/assets/{_connectorKey._connectionId-CVKfL9AG.js → _connectorKey._connectionId-DcI29kGy.js} +2 -2
  21. package/dist/owletto/dist/assets/_connectorKey.index-Cr2NDJWX.js +2 -0
  22. package/dist/owletto/dist/assets/{_conversationId-CPpNySjO.js → _conversationId-CnmLYlVS.js} +2 -2
  23. package/dist/owletto/dist/assets/_eventId-w5sDz5oa.js +2 -0
  24. package/dist/owletto/dist/assets/_owner-CkOZR4n0.js +3 -0
  25. package/dist/owletto/dist/assets/_shape-C_FmSf9G.js +2 -0
  26. package/dist/owletto/dist/assets/{_slug-DJx_8fsV.js → _slug-COPpRXLt.js} +2 -2
  27. package/dist/owletto/dist/assets/_viewKey-BVdJiilV.js +2 -0
  28. package/dist/owletto/dist/assets/_viewKey-mxxpqjtC.js +2 -0
  29. package/dist/owletto/dist/assets/{accept-invitation-Dwq1GAnG.js → accept-invitation-BKeIzZXE.js} +2 -2
  30. package/dist/owletto/dist/assets/{activity-route-location-C1jcXC7v.js → activity-route-location-sLvKaSCa.js} +2 -2
  31. package/dist/owletto/dist/assets/activity-route-view-msesKUwn.js +2 -0
  32. package/dist/owletto/dist/assets/{agent-connect-pages-DoI9UR0a.js → agent-connect-pages-DVq9nAR7.js} +3 -3
  33. package/dist/owletto/dist/assets/{agent-editor-form-DlavYg2q.js → agent-editor-form-DVFyyMyd.js} +2 -2
  34. package/dist/owletto/dist/assets/{agent-loading-shells-DYqQphN7.js → agent-loading-shells-BLNHIy-r.js} +2 -2
  35. package/dist/owletto/dist/assets/{agent-permissions-matrix-C1L8IcYR.js → agent-permissions-matrix-UBKRR5vs.js} +2 -2
  36. package/dist/owletto/dist/assets/{agent-skill-context-D1nMrVod.js → agent-skill-context-fqedKd0D.js} +2 -2
  37. package/dist/owletto/dist/assets/{agent-subpage-shell-2w7vTeXw.js → agent-subpage-shell-BUCoY2Nf.js} +2 -2
  38. package/dist/owletto/dist/assets/{agent-thread-BopD-2k1.js → agent-thread-Cqf9ITrT.js} +2 -2
  39. package/dist/owletto/dist/assets/app-bridge-B-L0rGz9.js +121 -0
  40. package/dist/owletto/dist/assets/{app._appId-BXeFXW1w.js → app._appId-ByIypCL9.js} +2 -2
  41. package/dist/owletto/dist/assets/{assist-composer-CL5x8pNt.js → assist-composer-kG_heHXo.js} +2 -2
  42. package/dist/owletto/dist/assets/{automation-run-now-MtxUTfzd.js → automation-run-now-C5XTS00o.js} +2 -2
  43. package/dist/owletto/dist/assets/{callback-BgfwP1Eo.js → callback-Pz5uS-k7.js} +2 -2
  44. package/dist/owletto/dist/assets/{card-DtLIFq7D.js → card-CAPpY9P5.js} +2 -2
  45. package/dist/owletto/dist/assets/{claim-CT3hYVMF.js → claim-DgWWK0KI.js} +2 -2
  46. package/dist/owletto/dist/assets/{client-activity-scopes-BPbRX-Pe.js → client-activity-scopes-Aqdo6Pdr.js} +2 -2
  47. package/dist/owletto/dist/assets/{client-rows-vrNA6FLs.js → client-rows-Dd5YV8vn.js} +2 -2
  48. package/dist/owletto/dist/assets/{clients-xnzZeEdZ.js → clients-Bf7ZgGro.js} +2 -2
  49. package/dist/owletto/dist/assets/{code-editor-mrKkAfcE.js → code-editor-z1Sy_hiX.js} +2 -2
  50. package/dist/owletto/dist/assets/connect-BFNp1y_s.js +2 -0
  51. package/dist/owletto/dist/assets/{connect-menu-C6iVtuSo.js → connect-menu-BWrAhMqO.js} +2 -2
  52. package/dist/owletto/dist/assets/connect._clientId-CSPfwYIN.js +2 -0
  53. package/dist/owletto/dist/assets/{connected._clientId-ROfVgp9h.js → connected._clientId-CuOeHafK.js} +2 -2
  54. package/dist/owletto/dist/assets/{connection-BMz740Wi.js → connection-CVeHmDLs.js} +2 -2
  55. package/dist/owletto/dist/assets/{connection-feed-detail-0VAJiZTP.js → connection-feed-detail-BYo7zdVD.js} +2 -2
  56. package/dist/owletto/dist/assets/{connector-page-shell-BFv21yuv.js → connector-page-shell-an3SYLim.js} +2 -2
  57. package/dist/owletto/dist/assets/{connector-provenance-b59RfBtk.js → connector-provenance-mSZCOud-.js} +2 -2
  58. package/dist/owletto/dist/assets/{connectors-nYS31lO2.js → connectors-DBEM9QQz.js} +2 -2
  59. package/dist/owletto/dist/assets/{consent-cPRF9JQv.js → consent-1ulwyJ3k.js} +2 -2
  60. package/dist/owletto/dist/assets/{copy-button-C3wMMv63.js → copy-button-Xhh7ZnjO.js} +2 -2
  61. package/dist/owletto/dist/assets/{core.esm-C9QlSrgK.js → core.esm-Ctg_pXLe.js} +2 -2
  62. package/dist/owletto/dist/assets/{create-CGOWfMk4.js → create-CGuoqPh8.js} +2 -2
  63. package/dist/owletto/dist/assets/create-Ccb5R-S4.js +2 -0
  64. package/dist/owletto/dist/assets/{create-ASRN3Obq.js → create-DmhbacIa.js} +2 -2
  65. package/dist/owletto/dist/assets/{create-automation-form-CLicoPH5.js → create-automation-form-CD6jSlWL.js} +2 -2
  66. package/dist/owletto/dist/assets/create._connectorKey-CZsAqj1p.js +2 -0
  67. package/dist/owletto/dist/assets/{custom-guardrail-edits-BUL7nmuO.js → custom-guardrail-edits-Ce_BwiwD.js} +2 -2
  68. package/dist/owletto/dist/assets/{definition-comparison-4UYMI6BK.js → definition-comparison-D_qP25jR.js} +2 -2
  69. package/dist/owletto/dist/assets/{detail-page-skeleton-C8v3rJXK.js → detail-page-skeleton-CPAfZLG0.js} +2 -2
  70. package/dist/owletto/dist/assets/{device-BBwsOi7q.js → device-DDl5XKvt.js} +2 -2
  71. package/dist/owletto/dist/assets/{device-pin-tombstone-Bcpe7nAA.js → device-pin-tombstone-Dkj7hrBE.js} +2 -2
  72. package/dist/owletto/dist/assets/{device._deviceId-DLT4jh0Z.js → device._deviceId-bNhTcops.js} +2 -2
  73. package/dist/owletto/dist/assets/{dynamic-schema-form-BDT8x0Vg.js → dynamic-schema-form-CRyUchXo.js} +2 -2
  74. package/dist/owletto/dist/assets/{entity-options-B9hm9V87.js → entity-options-D4t-NAcg.js} +2 -2
  75. package/dist/owletto/dist/assets/entity-page-BOOL_vy3.js +2 -0
  76. package/dist/owletto/dist/assets/{entity-pages-BWBpttz3.js → entity-pages-_nuesgnp.js} +2 -2
  77. package/dist/owletto/dist/assets/{entity-schema-graph-lMMx3HhR.js → entity-schema-graph-Cq96SJ3c.js} +2 -2
  78. package/dist/owletto/dist/assets/{entity-type-page-CkQm0yEu.js → entity-type-page-CkCSbkBx.js} +2 -2
  79. package/dist/owletto/dist/assets/event-detail-DUvlqn9b.js +2 -0
  80. package/dist/owletto/dist/assets/{events-feed-DmRzikZW.js → events-feed-DcKTkJVe.js} +2 -2
  81. package/dist/owletto/dist/assets/{filter-editors-CQoSj-20.js → filter-editors-DGVl9U4D.js} +3 -3
  82. package/dist/owletto/dist/assets/{full-page-spinner-CYyCnKve.js → full-page-spinner-CtVlF8GQ.js} +2 -2
  83. package/dist/owletto/dist/assets/index-BUlkNJzX.js +2 -0
  84. package/dist/owletto/dist/assets/{index-BS5Ty3tf.js → index-BifR-LE9.js} +2 -2
  85. package/dist/owletto/dist/assets/{index-DByaMzsG.js → index-BoqrvLHQ.js} +1383 -1383
  86. package/dist/owletto/dist/assets/index-CA9mW_ZM.js +2 -0
  87. package/dist/owletto/dist/assets/index-CH0GzG4i.js +2 -0
  88. package/dist/owletto/dist/assets/index-CK5GDX4B.js +2 -0
  89. package/dist/owletto/dist/assets/index-CtI5Eomq.js +2 -0
  90. package/dist/owletto/dist/assets/{index-CUndAH6o.js → index-DbjbHlDe.js} +2 -2
  91. package/dist/owletto/dist/assets/index-DmtQ0bds.js +2 -0
  92. package/dist/owletto/dist/assets/{index-CDyFQ32o.js → index-Du_J8hnx.js} +2 -2
  93. package/dist/owletto/dist/assets/{index-ittfA0k8.js → index-DvuJ_S_o.js} +2 -2
  94. package/dist/owletto/dist/assets/index-Pae_f9LM.css +1 -0
  95. package/dist/owletto/dist/assets/{index-C3hz9tzx.js → index-XETZnN7L.js} +2 -2
  96. package/dist/owletto/dist/assets/{json-diff-mcDgyct_.js → json-diff-OjtREegr.js} +2 -2
  97. package/dist/owletto/dist/assets/{list-skeleton-DsYGUHxi.js → list-skeleton-CH0qQBYk.js} +2 -2
  98. package/dist/owletto/dist/assets/{login-EoLq136v.js → login-DG0b9uSC.js} +2 -2
  99. package/dist/owletto/dist/assets/{logout-gLgEQOiX.js → logout-DfdgOLoM.js} +2 -2
  100. package/dist/owletto/dist/assets/{member-scope-gate-vvkgSAb2.js → member-scope-gate-Cxg2zGQT.js} +2 -2
  101. package/dist/owletto/dist/assets/memory-browse-page-qEDQ9Z18.js +74 -0
  102. package/dist/owletto/dist/assets/missing-view-xT0B-f5z.js +2 -0
  103. package/dist/owletto/dist/assets/{model-selector-D3vSMLO2.js → model-selector-D2OpDkwH.js} +2 -2
  104. package/dist/owletto/dist/assets/{needs-you-list-B5Bgd05M.js → needs-you-list-3uMsWcDv.js} +2 -2
  105. package/dist/owletto/dist/assets/{new-dLXsCHBd.js → new-AdGV6a8R.js} +2 -2
  106. package/dist/owletto/dist/assets/new-BdtIhBpo.js +2 -0
  107. package/dist/owletto/dist/assets/{new-Bk_flKQO.js → new-BjGwX6s6.js} +2 -2
  108. package/dist/owletto/dist/assets/{new-BPW3V0Y1.js → new-D-iMjV74.js} +2 -2
  109. package/dist/owletto/dist/assets/{organization-DBfgBkzq.js → organization-qaIpEiQg.js} +2 -2
  110. package/dist/owletto/dist/assets/peek-pane-content-CEsDVScl.js +2 -0
  111. package/dist/owletto/dist/assets/{pending-seed-CBhx2Ql-.js → pending-seed-BBACroge.js} +2 -2
  112. package/dist/owletto/dist/assets/{proposal-review-shell-B-jYcKfB.js → proposal-review-shell-C8ZfIAYn.js} +2 -2
  113. package/dist/owletto/dist/assets/public-shell-ready-K2R8iXSI.js +2 -0
  114. package/dist/owletto/dist/assets/{record-session-CAmGHMyM.js → record-session-BrM9cdXu.js} +2 -2
  115. package/dist/owletto/dist/assets/{renderer-olRv_HMI.js → renderer-CTKNMcXP.js} +4 -4
  116. package/dist/owletto/dist/assets/{reset-password-B9_xi8Pq.js → reset-password-DKBEneyR.js} +2 -2
  117. package/dist/owletto/dist/assets/{run-initiator-DhE5v4z0.js → run-initiator-BKSgI1o0.js} +2 -2
  118. package/dist/owletto/dist/assets/{runs-C8sZQr4o.js → runs-k2NpbZm8.js} +2 -2
  119. package/dist/owletto/dist/assets/runs-list-DUXRMkWN.js +2 -0
  120. package/dist/owletto/dist/assets/{schema-value-zTJGE4eh.js → schema-value-wjqGxXhv.js} +3 -3
  121. package/dist/owletto/dist/assets/{scoped-feed-bar-BKyJSa3_.js → scoped-feed-bar-DNFL0sYX.js} +2 -2
  122. package/dist/owletto/dist/assets/{settings-z02cvVS3.js → settings-V0m5Om5j.js} +2 -2
  123. package/dist/owletto/dist/assets/{source-record-panels-CGmKIJdN.js → source-record-panels-BMut9YIA.js} +2 -2
  124. package/dist/owletto/dist/assets/{status-variants-DyRCXBzM.js → status-variants-SzXYYedJ.js} +2 -2
  125. package/dist/owletto/dist/assets/subDays-9s9OEl5t.js +2 -0
  126. package/dist/owletto/dist/assets/{table-C637cQxG.js → table-ZuYMOjVR.js} +2 -2
  127. package/dist/owletto/dist/assets/{use-automations-CgWNoYio.js → use-automations-DfBtVzGa.js} +2 -2
  128. package/dist/owletto/dist/assets/{use-login-redirect-tDdhXTpt.js → use-login-redirect-BDiS3eyl.js} +2 -2
  129. package/dist/owletto/dist/assets/{use-mention-search-D-kIKchD.js → use-mention-search-khySpz_V.js} +2 -2
  130. package/dist/owletto/dist/assets/view-card-DiHWlypr.js +2 -0
  131. package/dist/owletto/dist/assets/view-param-filters-DGKxSr7r.js +2 -0
  132. package/dist/owletto/dist/assets/{views-access-required-C35Dyt91.js → views-access-required-HA-PiOwA.js} +2 -2
  133. package/dist/owletto/dist/index.html +2 -2
  134. package/dist/server-main.bundle.mjs +1052 -538
  135. package/npm-shrinkwrap.json +38 -38
  136. package/package.json +1 -1
  137. package/vendor/connector-sdk/package.json +1 -1
  138. package/vendor/core/package.json +1 -1
  139. package/vendor/views/package.json +1 -1
  140. package/dist/owletto/dist/assets/_-CYvj1y65.js +0 -3
  141. package/dist/owletto/dist/assets/_-CeLTSYYY.js +0 -2
  142. package/dist/owletto/dist/assets/_agentId-BB5E-L6T.js +0 -2
  143. package/dist/owletto/dist/assets/_automationId-DvUl9CSd.js +0 -2
  144. package/dist/owletto/dist/assets/_connectorKey.index-Cv6FzK1v.js +0 -2
  145. package/dist/owletto/dist/assets/_eventId-DZKicuq6.js +0 -2
  146. package/dist/owletto/dist/assets/_owner-Dauk3YuD.js +0 -3
  147. package/dist/owletto/dist/assets/_shape-cKrEID3T.js +0 -2
  148. package/dist/owletto/dist/assets/_viewKey-CPVzVKEf.js +0 -2
  149. package/dist/owletto/dist/assets/_viewKey-CW8gexOQ.js +0 -2
  150. package/dist/owletto/dist/assets/activity-route-view-D78Wj0RH.js +0 -2
  151. package/dist/owletto/dist/assets/app-bridge-C4nPtae3.js +0 -121
  152. package/dist/owletto/dist/assets/connect-NUCSay8X.js +0 -2
  153. package/dist/owletto/dist/assets/connect._clientId-Cp-d9Q5b.js +0 -2
  154. package/dist/owletto/dist/assets/create-CBcodaSO.js +0 -2
  155. package/dist/owletto/dist/assets/create._connectorKey-s4xkktTC.js +0 -2
  156. package/dist/owletto/dist/assets/entity-page-DZjzQ2V4.js +0 -2
  157. package/dist/owletto/dist/assets/event-detail-CkzfakTK.js +0 -2
  158. package/dist/owletto/dist/assets/index-BE7eb2kE.js +0 -2
  159. package/dist/owletto/dist/assets/index-BFR0uiKY.js +0 -2
  160. package/dist/owletto/dist/assets/index-C38OzBpB.js +0 -2
  161. package/dist/owletto/dist/assets/index-CiKysEhV.js +0 -2
  162. package/dist/owletto/dist/assets/index-DfdinB7B.js +0 -2
  163. package/dist/owletto/dist/assets/index-DgMM4Zt5.css +0 -1
  164. package/dist/owletto/dist/assets/index-Xk711gVC.js +0 -2
  165. package/dist/owletto/dist/assets/memory-browse-page-DvDtwrEI.js +0 -74
  166. package/dist/owletto/dist/assets/new-C5HtQdM_.js +0 -2
  167. package/dist/owletto/dist/assets/peek-pane-content-c2PG3TEX.js +0 -2
  168. package/dist/owletto/dist/assets/public-shell-ready-D8TijlRY.js +0 -2
  169. package/dist/owletto/dist/assets/record-activity-DnRVOrG2.js +0 -2
  170. package/dist/owletto/dist/assets/runs-list-CwtH-wmk.js +0 -2
  171. package/dist/owletto/dist/assets/subDays-D8nHthaS.js +0 -2
  172. package/dist/owletto/dist/assets/view-param-filters-CUCj9Df-.js +0 -2
@@ -1,2 +1,2 @@
1
- import{c as Ne,y as Ce,H as Se,ai as Ee,V as Le,r as s,aj as Fe,ak as Ue,j as e,al as b,am as ce,an as $,ao as Pe,ap as Ie,F as Me,af as ze,a4 as Ae,ag as Re,aq as oe}from"./index-DByaMzsG.js";import{s as qe}from"./index-BS5Ty3tf.js";import{C as $e,c as Be}from"./card-DtLIFq7D.js";function B(l){if(!l||typeof l!="object")return null;const f=l.error;if(typeof f=="string")return f;if(f&&typeof f=="object"){const y=f.message;if(typeof y=="string"&&y.length>0)return y}const m=l.message;return typeof m=="string"&&m.length>0?m:null}async function le(l,f){if(typeof window>"u")return;const m=window.PasswordCredential;if(!(!m||!navigator.credentials?.store))try{const y=new m({id:l,password:f});await navigator.credentials.store(y)}catch{}}function Oe({domain:l}){const[f,m]=s.useState(!1);return!(l.length>0&&l.length<=253&&/^[A-Za-z0-9.-]+$/.test(l))||f?e.jsx(ce,{className:"w-4 h-4"}):e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${encodeURIComponent(l)}&sz=32`,alt:"",width:16,height:16,className:"h-4 w-4",onError:()=>m(!0)})}function E(l){return l?l.toLowerCase().replaceAll("_"," ").trim().includes("account not linked")?"This social account matches an existing Lobu user. Sign in with a magic link to verify ownership, then continue.":l:null}function He(){const l=Ne(),f=Ce(),{session:m,isReady:y}=Se(),{data:a,isLoading:L,error:O}=Ee(),i=Le({from:"/auth/login"}),de=i.invitationOrg,[p,j]=s.useState("social"),[d,P]=s.useState(i.intent??"sign-in"),[T,ue]=s.useState(""),[o,W]=s.useState(()=>i.loginHint??""),[k,me]=s.useState(""),[N,ge]=s.useState(""),[I,_]=s.useState(""),[fe,J]=s.useState(!1),[c,u]=s.useState(null),[M,r]=s.useState(null),[Q,G]=s.useState(!1),[pe,K]=s.useState(!1),[Z,he]=s.useState(!1),X=s.useRef(!1),F=i.callbackUrl?Fe(i.callbackUrl):void 0,z=Ue(de,i.loginHint),Y=i.mode==="extension",D=i.error==="account_not_linked",ee=E(i.errorDescription||i.error),A=Object.values(a?.social??{}).some(Boolean),w=!!a?.magicLink,R=!!a?.phone,h=!!a?.emailPassword,te=!!a?.passkey,x=!!a?.singleUserMode,ne=!!a?.hasUser,H=x,U=p==="magic-link"&&w&&Q,v=s.useMemo(()=>{const t=[];return h&&t.push("email-password"),A&&t.push("social"),w&&t.push("magic-link"),R&&t.push("whatsapp"),t},[h,w,A,R]),xe=s.useMemo(()=>h?v.filter(t=>t!=="magic-link"&&t!=="social"):v,[v,h]),V=O instanceof Error?O.message:O?"Unable to load sign-in options.":null;s.useEffect(()=>{m&&(F?window.location.href=F:l({to:"/"}))},[m,l,F]),s.useEffect(()=>{!a||v.length===0||v.includes(p)||j(v[0])},[a,p,v]),s.useEffect(()=>{!w||!D||(j("magic-link"),i.loginHint&&!o&&W(i.loginHint))},[w,D,i.loginHint,o]),s.useEffect(()=>{i.intent&&P(i.intent)},[i.intent]),s.useEffect(()=>{if(!x||!a)return;const t=ne?"sign-in":"sign-up";d!==t&&P(t)},[x,ne,a,d]);const se=t=>new URL(t,window.location.origin).href,C=()=>se(F??"/"),re=async(t,{quiet:n=!1}={})=>{u(t),r(null);try{const g=await $.social({provider:t,callbackURL:C(),newUserCallbackURL:F?C():se(`/?onboard_provider=${encodeURIComponent(t)}`)}),S=B(g);if(S&&!n){const q=E(S);q?.toLowerCase().includes("magic link")&&j("magic-link"),r(q)}}catch(g){if(n)return;r(E(g instanceof Error?g.message:`Failed to sign in with ${t}`))}finally{u(null)}};s.useEffect(()=>{if(X.current||!y||m||L||!a||i.error)return;const t=i.provider;if(!t)return;X.current=!0;const n=Object.hasOwn(a.social??{},t)&&!!a.social?.[t];re(t,{quiet:!n})},[a,L,m,y,i.provider,i.error]);const ie=async()=>{if(o){u("magic-link"),r(null);try{return await $.magicLink({email:o,callbackURL:C()}),G(!0),!0}catch(t){return r(t instanceof Error?t.message:"Failed to send magic link"),!1}finally{u(null)}}},be=async t=>{t.preventDefault(),await ie()},ye=async t=>{if(t.preventDefault(),!(!o||!k)){u("email-password"),r(null);try{if(d==="sign-up"){const n=await Ie.email({email:o,password:k,name:T||o.split("@")[0]||"User",callbackURL:C()}),g=B(n);if(g){r(E(g));return}if(await le(o,k),await f.invalidateQueries({queryKey:["organizations"]}),x&&te)try{await Me.passkey.addPasskey({name:T||`${navigator.platform||"This device"}`})}catch{}}else{const n=await $.email({email:o,password:k,callbackURL:C()}),g=B(n);if(g){r(E(g));return}if(!n?.data){r("Invalid email or password");return}await le(o,k)}}catch(n){const g=n instanceof Error?n.message:typeof n=="string"?n:B(n);r(g||"Authentication failed")}finally{u(null)}}},ae=async()=>{r(null),he(!0),u("local");try{const t=await Pe();if(!t.ok){const n=await t.json().catch(()=>null);r(n?.error_description??"Could not sign in to your local install.");return}window.location.href=C()}catch(t){r(t instanceof Error?t.message:"Could not sign in to your local install.")}finally{u(null)}};s.useEffect(()=>{H&&a&&!m&&!Z&&ae()},[H,a,m,Z]);const je=async()=>{if(!o){r("Enter your email address first to reset your password.");return}u("reset-password-request"),r(null);try{const t=`${window.location.origin}/auth/reset-password`,n=await ze(`${Ae}/api/auth/request-password-reset`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({email:o,redirectTo:t})});if(!n.ok)throw await Re(n);K(!0)}catch(t){r(t instanceof Error?t.message:"Failed to send password reset email")}finally{u(null)}},we=async t=>{if(t.preventDefault(),!!N){u("phone"),r(null);try{await oe.sendOtp({phoneNumber:N}),J(!0)}catch(n){r(n instanceof Error?n.message:"Failed to send verification code")}finally{u(null)}}},ve=async t=>{if(t.preventDefault(),!(!N||!I)){u("verify"),r(null);try{await oe.verify({phoneNumber:N,code:I})}catch(n){r(n instanceof Error?n.message:"Invalid verification code"),u(null)}}};return e.jsx("div",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center",children:e.jsxs("div",{className:"w-full max-w-md p-8",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("img",{src:"/lobu-logo.svg",alt:"Lobu",className:"mx-auto mb-6 h-8 w-auto"}),e.jsx("h1",{className:"text-2xl font-bold",children:z?z.title:x&&d==="sign-up"?"Set up your local install":x?"Welcome back":d==="sign-up"?"Create your account":"Sign in"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:z?z.detail:x&&d==="sign-up"?"This account stays on this machine. Email is just an identifier — pick anything you’ll remember.":x?"Sign in to your local install.":Y?"Sign in to connect the browser extension":d==="sign-up"?"Choose a sign-up method":"Choose your preferred sign-in method"}),x&&e.jsxs("div",{className:"mt-3 inline-flex items-center gap-2 px-3 py-1.5 bg-muted text-muted-foreground rounded-full text-xs",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})}),"Local install · nothing sent to lobu.ai"]}),Y&&e.jsxs("div",{className:"mt-3 inline-flex items-center gap-2 px-3 py-1.5 bg-primary/10 text-primary rounded-full text-sm",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"})}),"Browser Extension"]})]}),e.jsx($e,{children:e.jsx(Be,{children:H?e.jsx("div",{className:"space-y-4",children:M?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:M}),e.jsx("button",{type:"button",disabled:c!==null,onClick:ae,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:"Try again"})]}):e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(b,{size:"lg"}),e.jsx("span",{children:"Signing you into your local install…"})]})}):e.jsxs(e.Fragment,{children:[L&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(b,{size:"lg"}),e.jsx("span",{children:"Loading sign-in options…"})]}),!L&&V&&e.jsxs("div",{className:"text-sm text-destructive",children:["Failed to load sign-in options. ",V]}),!L&&!V&&v.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"No sign-in methods are configured. Contact support for access."}),h&&!U&&e.jsxs("div",{className:"mb-4 flex rounded-lg border p-1",children:[e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${d==="sign-in"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>P("sign-in"),children:"Sign In"}),e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${d==="sign-up"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>P("sign-up"),children:"Sign Up"})]}),!U&&xe.length>1&&e.jsxs("div",{className:"mb-6 flex rounded-lg border p-1",children:[h&&e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${p==="email-password"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>j("email-password"),children:"Email + Password"}),A&&e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${p==="social"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>j("social"),children:"Social"}),!h&&w&&e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${p==="magic-link"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>j("magic-link"),children:"Magic Link"}),R&&e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${p==="whatsapp"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>j("whatsapp"),children:"WhatsApp"})]}),D&&e.jsx("div",{className:"mb-4 rounded-lg border border-amber-300 bg-amber-50 p-3 text-sm text-amber-900",children:"We found an existing account for this identity. To protect the account, verify with a magic link before linking social sign-in."}),ee&&e.jsx("div",{className:"mb-4 p-3 text-sm text-destructive bg-destructive/10 rounded-lg",children:ee}),M&&e.jsx("div",{className:"mb-4 p-3 text-sm text-destructive bg-destructive/10 rounded-lg",children:M}),!U&&(h||p==="social")&&A&&e.jsxs("div",{className:"space-y-3",children:[Object.entries(a?.social??{}).filter(([,t])=>t).map(([t])=>{const n=qe.find(ke=>ke.provider===t),g=n?.icon,S=a?.socialMeta?.[t],q=n?.name??S?.name??t.charAt(0).toUpperCase()+t.slice(1);return e.jsxs("button",{type:"button",onClick:()=>re(t),disabled:c!==null,className:"w-full flex items-center justify-center gap-3 h-10 px-4 border border-input rounded-lg bg-background hover:bg-accent hover:text-accent-foreground transition-colors disabled:opacity-50",children:[c===t?e.jsx(b,{size:"lg"}):g?e.jsx(g,{className:"w-4 h-4"}):S?.faviconDomain?e.jsx(Oe,{domain:S.faviconDomain},S.faviconDomain):e.jsx(ce,{className:"w-4 h-4"}),"Continue with ",q]},t)}),h&&e.jsxs("div",{className:"relative my-2",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-card px-2 text-muted-foreground",children:"or"})})]})]}),!U&&h&&e.jsxs("form",{onSubmit:ye,className:"space-y-4",children:[d==="sign-up"&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:"full-name",className:"block text-sm font-medium",children:"Full name"}),e.jsx("input",{id:"full-name",type:"text",value:T,onChange:t=>ue(t.target.value),placeholder:"Jane Doe",className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email-password-email",className:"block text-sm font-medium",children:"Email address"}),e.jsx("input",{id:"email-password-email",type:"email",value:o,onChange:t=>{W(t.target.value),K(!1)},placeholder:"you@example.com",required:!0,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email-password-password",className:"block text-sm font-medium",children:"Password"}),e.jsx("input",{id:"email-password-password",type:"password",value:k,onChange:t=>me(t.target.value),placeholder:"Enter a password",required:!0,minLength:8,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsx("button",{type:"submit",disabled:c!==null||!o||!k,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:c==="email-password"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:d==="sign-up"?"Creating account...":"Signing in..."})]}):d==="sign-up"?x?"Create local account":"Create Account":"Sign In"}),d==="sign-in"&&te&&e.jsx("button",{type:"button",disabled:c!==null,onClick:async()=>{r(null),u("passkey");try{const t=await $.passkey();if(t?.error){const n=t.error.message??"Passkey sign-in failed.";r(E(n)??n);return}window.location.href=C()}catch(t){const n=t instanceof Error?t.message:String(t);r(E(n)??n)}finally{u(null)}},className:"flex h-10 w-full items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:opacity-50",children:c==="passkey"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Waiting for passkey…"})]}):"Sign in with passkey"}),d==="sign-in"&&w&&e.jsx("button",{type:"button",disabled:c!==null||!o,onClick:async()=>{await ie()&&j("magic-link")},className:"flex h-10 w-full items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:opacity-50",children:c==="magic-link"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Sending magic link..."})]}):"Send me a magic link instead"}),d==="sign-in"&&e.jsx("button",{type:"button",disabled:c!==null||!o,onClick:je,className:"flex h-10 w-full items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:opacity-50",children:c==="reset-password-request"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Sending reset email..."})]}):"Forgot password?"}),d==="sign-in"&&pe&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"If this email exists, we sent a password reset link."})]}),p==="magic-link"&&w&&(Q?e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"mb-4 flex justify-center",children:e.jsx("svg",{className:"h-12 w-12 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})})}),e.jsx("h2",{className:"text-lg font-medium",children:"Check your email"}),e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["We sent a magic link to ",e.jsx("strong",{children:o}),".",e.jsx("br",{}),"Click the link in the email to sign in."]}),e.jsx("button",{type:"button",className:"mt-4 text-sm text-primary hover:underline",onClick:()=>G(!1),children:"Use a different email"})]}):e.jsxs("form",{onSubmit:be,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium",children:"Email address"}),e.jsx("input",{id:"email",type:"email",value:o,onChange:t=>W(t.target.value),placeholder:"you@example.com",required:!0,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsx("button",{type:"submit",disabled:c!==null||!o,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:c==="magic-link"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Sending..."})]}):"Send Magic Link"})]})),!U&&p==="whatsapp"&&R&&(fe?e.jsxs("form",{onSubmit:ve,className:"space-y-4",children:[e.jsxs("div",{className:"text-center text-sm text-muted-foreground",children:["Enter the 6-digit code sent to ",e.jsx("strong",{children:N})]}),e.jsx("div",{children:e.jsx("input",{type:"text",value:I,onChange:t=>_(t.target.value),placeholder:"000000",maxLength:6,pattern:"[0-9]{6}",required:!0,className:"block h-12 w-full rounded-md border border-input bg-background px-3 py-2 text-center text-xl tracking-widest placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})}),e.jsx("button",{type:"submit",disabled:c!==null||I.length!==6,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:c==="verify"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Verifying..."})]}):"Verify & Sign In"}),e.jsx("button",{type:"button",className:"w-full text-sm text-primary hover:underline",onClick:()=>{J(!1),_("")},children:"Use a different number"})]}):e.jsxs("form",{onSubmit:we,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"phone",className:"block text-sm font-medium",children:"WhatsApp Number"}),e.jsx("input",{id:"phone",type:"tel",value:N,onChange:t=>ge(t.target.value),placeholder:"+1234567890",required:!0,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Include country code (e.g., +1 for US)"})]}),e.jsx("button",{type:"submit",disabled:c!==null||!N,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:c==="phone"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Sending..."})]}):"Send Code via WhatsApp"})]}))]})})})]})})}export{He as component};
2
- //# sourceMappingURL=login-EoLq136v.js.map
1
+ import{c as Ne,y as Ce,H as Se,ai as Ee,V as Le,r as s,aj as Fe,ak as Ue,j as e,al as b,am as ce,an as $,ao as Pe,ap as Ie,F as Me,af as ze,a4 as Ae,ag as Re,aq as oe}from"./index-BoqrvLHQ.js";import{s as qe}from"./index-BifR-LE9.js";import{C as $e,c as Be}from"./card-CAPpY9P5.js";function B(l){if(!l||typeof l!="object")return null;const f=l.error;if(typeof f=="string")return f;if(f&&typeof f=="object"){const y=f.message;if(typeof y=="string"&&y.length>0)return y}const m=l.message;return typeof m=="string"&&m.length>0?m:null}async function le(l,f){if(typeof window>"u")return;const m=window.PasswordCredential;if(!(!m||!navigator.credentials?.store))try{const y=new m({id:l,password:f});await navigator.credentials.store(y)}catch{}}function Oe({domain:l}){const[f,m]=s.useState(!1);return!(l.length>0&&l.length<=253&&/^[A-Za-z0-9.-]+$/.test(l))||f?e.jsx(ce,{className:"w-4 h-4"}):e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${encodeURIComponent(l)}&sz=32`,alt:"",width:16,height:16,className:"h-4 w-4",onError:()=>m(!0)})}function E(l){return l?l.toLowerCase().replaceAll("_"," ").trim().includes("account not linked")?"This social account matches an existing Lobu user. Sign in with a magic link to verify ownership, then continue.":l:null}function He(){const l=Ne(),f=Ce(),{session:m,isReady:y}=Se(),{data:a,isLoading:L,error:O}=Ee(),i=Le({from:"/auth/login"}),de=i.invitationOrg,[p,j]=s.useState("social"),[d,P]=s.useState(i.intent??"sign-in"),[T,ue]=s.useState(""),[o,W]=s.useState(()=>i.loginHint??""),[k,me]=s.useState(""),[N,ge]=s.useState(""),[I,_]=s.useState(""),[fe,J]=s.useState(!1),[c,u]=s.useState(null),[M,r]=s.useState(null),[Q,G]=s.useState(!1),[pe,K]=s.useState(!1),[Z,he]=s.useState(!1),X=s.useRef(!1),F=i.callbackUrl?Fe(i.callbackUrl):void 0,z=Ue(de,i.loginHint),Y=i.mode==="extension",D=i.error==="account_not_linked",ee=E(i.errorDescription||i.error),A=Object.values(a?.social??{}).some(Boolean),w=!!a?.magicLink,R=!!a?.phone,h=!!a?.emailPassword,te=!!a?.passkey,x=!!a?.singleUserMode,ne=!!a?.hasUser,H=x,U=p==="magic-link"&&w&&Q,v=s.useMemo(()=>{const t=[];return h&&t.push("email-password"),A&&t.push("social"),w&&t.push("magic-link"),R&&t.push("whatsapp"),t},[h,w,A,R]),xe=s.useMemo(()=>h?v.filter(t=>t!=="magic-link"&&t!=="social"):v,[v,h]),V=O instanceof Error?O.message:O?"Unable to load sign-in options.":null;s.useEffect(()=>{m&&(F?window.location.href=F:l({to:"/"}))},[m,l,F]),s.useEffect(()=>{!a||v.length===0||v.includes(p)||j(v[0])},[a,p,v]),s.useEffect(()=>{!w||!D||(j("magic-link"),i.loginHint&&!o&&W(i.loginHint))},[w,D,i.loginHint,o]),s.useEffect(()=>{i.intent&&P(i.intent)},[i.intent]),s.useEffect(()=>{if(!x||!a)return;const t=ne?"sign-in":"sign-up";d!==t&&P(t)},[x,ne,a,d]);const se=t=>new URL(t,window.location.origin).href,C=()=>se(F??"/"),re=async(t,{quiet:n=!1}={})=>{u(t),r(null);try{const g=await $.social({provider:t,callbackURL:C(),newUserCallbackURL:F?C():se(`/?onboard_provider=${encodeURIComponent(t)}`)}),S=B(g);if(S&&!n){const q=E(S);q?.toLowerCase().includes("magic link")&&j("magic-link"),r(q)}}catch(g){if(n)return;r(E(g instanceof Error?g.message:`Failed to sign in with ${t}`))}finally{u(null)}};s.useEffect(()=>{if(X.current||!y||m||L||!a||i.error)return;const t=i.provider;if(!t)return;X.current=!0;const n=Object.hasOwn(a.social??{},t)&&!!a.social?.[t];re(t,{quiet:!n})},[a,L,m,y,i.provider,i.error]);const ie=async()=>{if(o){u("magic-link"),r(null);try{return await $.magicLink({email:o,callbackURL:C()}),G(!0),!0}catch(t){return r(t instanceof Error?t.message:"Failed to send magic link"),!1}finally{u(null)}}},be=async t=>{t.preventDefault(),await ie()},ye=async t=>{if(t.preventDefault(),!(!o||!k)){u("email-password"),r(null);try{if(d==="sign-up"){const n=await Ie.email({email:o,password:k,name:T||o.split("@")[0]||"User",callbackURL:C()}),g=B(n);if(g){r(E(g));return}if(await le(o,k),await f.invalidateQueries({queryKey:["organizations"]}),x&&te)try{await Me.passkey.addPasskey({name:T||`${navigator.platform||"This device"}`})}catch{}}else{const n=await $.email({email:o,password:k,callbackURL:C()}),g=B(n);if(g){r(E(g));return}if(!n?.data){r("Invalid email or password");return}await le(o,k)}}catch(n){const g=n instanceof Error?n.message:typeof n=="string"?n:B(n);r(g||"Authentication failed")}finally{u(null)}}},ae=async()=>{r(null),he(!0),u("local");try{const t=await Pe();if(!t.ok){const n=await t.json().catch(()=>null);r(n?.error_description??"Could not sign in to your local install.");return}window.location.href=C()}catch(t){r(t instanceof Error?t.message:"Could not sign in to your local install.")}finally{u(null)}};s.useEffect(()=>{H&&a&&!m&&!Z&&ae()},[H,a,m,Z]);const je=async()=>{if(!o){r("Enter your email address first to reset your password.");return}u("reset-password-request"),r(null);try{const t=`${window.location.origin}/auth/reset-password`,n=await ze(`${Ae}/api/auth/request-password-reset`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({email:o,redirectTo:t})});if(!n.ok)throw await Re(n);K(!0)}catch(t){r(t instanceof Error?t.message:"Failed to send password reset email")}finally{u(null)}},we=async t=>{if(t.preventDefault(),!!N){u("phone"),r(null);try{await oe.sendOtp({phoneNumber:N}),J(!0)}catch(n){r(n instanceof Error?n.message:"Failed to send verification code")}finally{u(null)}}},ve=async t=>{if(t.preventDefault(),!(!N||!I)){u("verify"),r(null);try{await oe.verify({phoneNumber:N,code:I})}catch(n){r(n instanceof Error?n.message:"Invalid verification code"),u(null)}}};return e.jsx("div",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center",children:e.jsxs("div",{className:"w-full max-w-md p-8",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("img",{src:"/lobu-logo.svg",alt:"Lobu",className:"mx-auto mb-6 h-8 w-auto"}),e.jsx("h1",{className:"text-2xl font-bold",children:z?z.title:x&&d==="sign-up"?"Set up your local install":x?"Welcome back":d==="sign-up"?"Create your account":"Sign in"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:z?z.detail:x&&d==="sign-up"?"This account stays on this machine. Email is just an identifier — pick anything you’ll remember.":x?"Sign in to your local install.":Y?"Sign in to connect the browser extension":d==="sign-up"?"Choose a sign-up method":"Choose your preferred sign-in method"}),x&&e.jsxs("div",{className:"mt-3 inline-flex items-center gap-2 px-3 py-1.5 bg-muted text-muted-foreground rounded-full text-xs",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})}),"Local install · nothing sent to lobu.ai"]}),Y&&e.jsxs("div",{className:"mt-3 inline-flex items-center gap-2 px-3 py-1.5 bg-primary/10 text-primary rounded-full text-sm",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"})}),"Browser Extension"]})]}),e.jsx($e,{children:e.jsx(Be,{children:H?e.jsx("div",{className:"space-y-4",children:M?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:M}),e.jsx("button",{type:"button",disabled:c!==null,onClick:ae,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:"Try again"})]}):e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(b,{size:"lg"}),e.jsx("span",{children:"Signing you into your local install…"})]})}):e.jsxs(e.Fragment,{children:[L&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(b,{size:"lg"}),e.jsx("span",{children:"Loading sign-in options…"})]}),!L&&V&&e.jsxs("div",{className:"text-sm text-destructive",children:["Failed to load sign-in options. ",V]}),!L&&!V&&v.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"No sign-in methods are configured. Contact support for access."}),h&&!U&&e.jsxs("div",{className:"mb-4 flex rounded-lg border p-1",children:[e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${d==="sign-in"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>P("sign-in"),children:"Sign In"}),e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${d==="sign-up"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>P("sign-up"),children:"Sign Up"})]}),!U&&xe.length>1&&e.jsxs("div",{className:"mb-6 flex rounded-lg border p-1",children:[h&&e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${p==="email-password"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>j("email-password"),children:"Email + Password"}),A&&e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${p==="social"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>j("social"),children:"Social"}),!h&&w&&e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${p==="magic-link"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>j("magic-link"),children:"Magic Link"}),R&&e.jsx("button",{type:"button",className:`flex-1 rounded-md px-3 py-2 text-sm font-medium transition-colors ${p==="whatsapp"?"bg-primary text-primary-foreground":"text-muted-foreground hover:text-foreground"}`,onClick:()=>j("whatsapp"),children:"WhatsApp"})]}),D&&e.jsx("div",{className:"mb-4 rounded-lg border border-amber-300 bg-amber-50 p-3 text-sm text-amber-900",children:"We found an existing account for this identity. To protect the account, verify with a magic link before linking social sign-in."}),ee&&e.jsx("div",{className:"mb-4 p-3 text-sm text-destructive bg-destructive/10 rounded-lg",children:ee}),M&&e.jsx("div",{className:"mb-4 p-3 text-sm text-destructive bg-destructive/10 rounded-lg",children:M}),!U&&(h||p==="social")&&A&&e.jsxs("div",{className:"space-y-3",children:[Object.entries(a?.social??{}).filter(([,t])=>t).map(([t])=>{const n=qe.find(ke=>ke.provider===t),g=n?.icon,S=a?.socialMeta?.[t],q=n?.name??S?.name??t.charAt(0).toUpperCase()+t.slice(1);return e.jsxs("button",{type:"button",onClick:()=>re(t),disabled:c!==null,className:"w-full flex items-center justify-center gap-3 h-10 px-4 border border-input rounded-lg bg-background hover:bg-accent hover:text-accent-foreground transition-colors disabled:opacity-50",children:[c===t?e.jsx(b,{size:"lg"}):g?e.jsx(g,{className:"w-4 h-4"}):S?.faviconDomain?e.jsx(Oe,{domain:S.faviconDomain},S.faviconDomain):e.jsx(ce,{className:"w-4 h-4"}),"Continue with ",q]},t)}),h&&e.jsxs("div",{className:"relative my-2",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-card px-2 text-muted-foreground",children:"or"})})]})]}),!U&&h&&e.jsxs("form",{onSubmit:ye,className:"space-y-4",children:[d==="sign-up"&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:"full-name",className:"block text-sm font-medium",children:"Full name"}),e.jsx("input",{id:"full-name",type:"text",value:T,onChange:t=>ue(t.target.value),placeholder:"Jane Doe",className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email-password-email",className:"block text-sm font-medium",children:"Email address"}),e.jsx("input",{id:"email-password-email",type:"email",value:o,onChange:t=>{W(t.target.value),K(!1)},placeholder:"you@example.com",required:!0,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email-password-password",className:"block text-sm font-medium",children:"Password"}),e.jsx("input",{id:"email-password-password",type:"password",value:k,onChange:t=>me(t.target.value),placeholder:"Enter a password",required:!0,minLength:8,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsx("button",{type:"submit",disabled:c!==null||!o||!k,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:c==="email-password"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:d==="sign-up"?"Creating account...":"Signing in..."})]}):d==="sign-up"?x?"Create local account":"Create Account":"Sign In"}),d==="sign-in"&&te&&e.jsx("button",{type:"button",disabled:c!==null,onClick:async()=>{r(null),u("passkey");try{const t=await $.passkey();if(t?.error){const n=t.error.message??"Passkey sign-in failed.";r(E(n)??n);return}window.location.href=C()}catch(t){const n=t instanceof Error?t.message:String(t);r(E(n)??n)}finally{u(null)}},className:"flex h-10 w-full items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:opacity-50",children:c==="passkey"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Waiting for passkey…"})]}):"Sign in with passkey"}),d==="sign-in"&&w&&e.jsx("button",{type:"button",disabled:c!==null||!o,onClick:async()=>{await ie()&&j("magic-link")},className:"flex h-10 w-full items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:opacity-50",children:c==="magic-link"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Sending magic link..."})]}):"Send me a magic link instead"}),d==="sign-in"&&e.jsx("button",{type:"button",disabled:c!==null||!o,onClick:je,className:"flex h-10 w-full items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground disabled:opacity-50",children:c==="reset-password-request"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Sending reset email..."})]}):"Forgot password?"}),d==="sign-in"&&pe&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"If this email exists, we sent a password reset link."})]}),p==="magic-link"&&w&&(Q?e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"mb-4 flex justify-center",children:e.jsx("svg",{className:"h-12 w-12 text-primary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})})}),e.jsx("h2",{className:"text-lg font-medium",children:"Check your email"}),e.jsxs("p",{className:"mt-2 text-sm text-muted-foreground",children:["We sent a magic link to ",e.jsx("strong",{children:o}),".",e.jsx("br",{}),"Click the link in the email to sign in."]}),e.jsx("button",{type:"button",className:"mt-4 text-sm text-primary hover:underline",onClick:()=>G(!1),children:"Use a different email"})]}):e.jsxs("form",{onSubmit:be,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium",children:"Email address"}),e.jsx("input",{id:"email",type:"email",value:o,onChange:t=>W(t.target.value),placeholder:"you@example.com",required:!0,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsx("button",{type:"submit",disabled:c!==null||!o,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:c==="magic-link"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Sending..."})]}):"Send Magic Link"})]})),!U&&p==="whatsapp"&&R&&(fe?e.jsxs("form",{onSubmit:ve,className:"space-y-4",children:[e.jsxs("div",{className:"text-center text-sm text-muted-foreground",children:["Enter the 6-digit code sent to ",e.jsx("strong",{children:N})]}),e.jsx("div",{children:e.jsx("input",{type:"text",value:I,onChange:t=>_(t.target.value),placeholder:"000000",maxLength:6,pattern:"[0-9]{6}",required:!0,className:"block h-12 w-full rounded-md border border-input bg-background px-3 py-2 text-center text-xl tracking-widest placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"})}),e.jsx("button",{type:"submit",disabled:c!==null||I.length!==6,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:c==="verify"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Verifying..."})]}):"Verify & Sign In"}),e.jsx("button",{type:"button",className:"w-full text-sm text-primary hover:underline",onClick:()=>{J(!1),_("")},children:"Use a different number"})]}):e.jsxs("form",{onSubmit:we,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"phone",className:"block text-sm font-medium",children:"WhatsApp Number"}),e.jsx("input",{id:"phone",type:"tel",value:N,onChange:t=>ge(t.target.value),placeholder:"+1234567890",required:!0,className:"mt-1 block h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Include country code (e.g., +1 for US)"})]}),e.jsx("button",{type:"submit",disabled:c!==null||!N,className:"flex h-10 w-full items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90 disabled:opacity-50",children:c==="phone"?e.jsxs(e.Fragment,{children:[e.jsx(b,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Sending..."})]}):"Send Code via WhatsApp"})]}))]})})})]})})}export{He as component};
2
+ //# sourceMappingURL=login-DG0b9uSC.js.map
@@ -1,2 +1,2 @@
1
- import{r as n,ah as o,j as e}from"./index-DByaMzsG.js";function s(){return n.useEffect(()=>{o().catch(t=>console.error("Sign out failed:",t)).finally(()=>{window.location.href="/"})},[]),e.jsx("div",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center",children:e.jsx("p",{className:"text-muted-foreground",children:"Signing out..."})})}export{s as component};
2
- //# sourceMappingURL=logout-gLgEQOiX.js.map
1
+ import{r as n,ah as o,j as e}from"./index-BoqrvLHQ.js";function s(){return n.useEffect(()=>{o().catch(t=>console.error("Sign out failed:",t)).finally(()=>{window.location.href="/"})},[]),e.jsx("div",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center",children:e.jsx("p",{className:"text-muted-foreground",children:"Signing out..."})})}export{s as component};
2
+ //# sourceMappingURL=logout-DfdgOLoM.js.map
@@ -1,2 +1,2 @@
1
- import{j as e,m as o,H as c,n as u,P as d,bc as h,cU as b,B as p,L as x,T as g}from"./index-DByaMzsG.js";function j({rows:t=5}){return e.jsx("div",{className:"space-y-2",role:"status","aria-label":"Loading members",children:Array.from({length:t}).map((n,s)=>e.jsxs("div",{className:"flex items-center gap-3 rounded-lg px-3 py-2",children:[e.jsx(o,{className:"h-8 w-8 shrink-0 rounded-full"}),e.jsx(o,{className:"h-4 w-40"})]},s))})}function l({title:t,body:n,ctaLabel:s,showCta:r,callbackUrl:a}){return e.jsx(h,{icon:b,title:t,description:n,children:s&&r?e.jsx(p,{asChild:!0,className:"mt-4",children:e.jsx(x,{to:"/auth/login",search:g({callbackUrl:a,intent:"sign-in"}),children:s})}):null})}function y({children:t}){const{isAuthenticated:n,isReady:s}=c(),{isMember:r,isLoading:a}=u(),i=d({select:m=>m.href});return!s||a?e.jsx(j,{}):n?r?e.jsx(e.Fragment,{children:t}):e.jsx(l,{title:"Join to see members",body:"Emails and member details are only visible to members of this workspace. Use the banner above to join.",callbackUrl:i}):e.jsx(l,{title:"Sign in to see members",body:"The members of this workspace are only visible to people who have signed in.",ctaLabel:"Sign in",showCta:!0,callbackUrl:i})}export{y as M};
2
- //# sourceMappingURL=member-scope-gate-vvkgSAb2.js.map
1
+ import{j as e,m as o,H as c,n as u,P as d,bc as h,cU as b,B as p,L as x,T as g}from"./index-BoqrvLHQ.js";function j({rows:t=5}){return e.jsx("div",{className:"space-y-2",role:"status","aria-label":"Loading members",children:Array.from({length:t}).map((n,s)=>e.jsxs("div",{className:"flex items-center gap-3 rounded-lg px-3 py-2",children:[e.jsx(o,{className:"h-8 w-8 shrink-0 rounded-full"}),e.jsx(o,{className:"h-4 w-40"})]},s))})}function l({title:t,body:n,ctaLabel:s,showCta:r,callbackUrl:a}){return e.jsx(h,{icon:b,title:t,description:n,children:s&&r?e.jsx(p,{asChild:!0,className:"mt-4",children:e.jsx(x,{to:"/auth/login",search:g({callbackUrl:a,intent:"sign-in"}),children:s})}):null})}function y({children:t}){const{isAuthenticated:n,isReady:s}=c(),{isMember:r,isLoading:a}=u(),i=d({select:m=>m.href});return!s||a?e.jsx(j,{}):n?r?e.jsx(e.Fragment,{children:t}):e.jsx(l,{title:"Join to see members",body:"Emails and member details are only visible to members of this workspace. Use the banner above to join.",callbackUrl:i}):e.jsx(l,{title:"Sign in to see members",body:"The members of this workspace are only visible to people who have signed in.",ctaLabel:"Sign in",showCta:!0,callbackUrl:i})}export{y as M};
2
+ //# sourceMappingURL=member-scope-gate-Cxg2zGQT.js.map
@@ -0,0 +1,74 @@
1
+ import{eW as Tt,c3 as Ts,c4 as Is,gg as Fs,gh as Ps,j as s,dx as Ds,c8 as Vs,Z as Be,$ as oe,bR as Bs,B as R,by as It,gi as Ft,eG as te,gj as Se,gk as qs,gl as Hs,gm as Xe,gn as Us,go as Ue,gp as ze,gq as zs,gr as Gs,eC as Js,z as Pt,dL as je,r as y,d9 as Ws,eM as Ys,K as Qs,eT as Xs,M as ke,x as Dt,cz as Zs,ge as Ks,c as ie,u as Vt,fu as en,b$ as tn,bc as Bt,d8 as qt,fU as sn,gc as nn,fe as an,a7 as Ge,i as Ne,dO as Ht,gs as rn,L as _e,e9 as on,c_ as ln,aE as Ut,aF as zt,dh as Gt,aH as Jt,aI as cn,aJ as dn,aK as un,aL as mn,aM as wt,aQ as pn,cT as fn,aO as hn,cP as Wt,a9 as gn,gt as Yt,gu as Qt,aw as yn,gv as bn,V as Xt,H as xn,gw as vn,dz as re,ci as X,w as Zt,eF as qe,cJ as Sn,gx as jn,gy as Nn,dX as kt,gz as He,gA as Cn,gB as En,d7 as wn,dg as kn,cF as _n,cG as $n,cg as Je,dH as Rn,gC as Ln,dm as On,bo as Mn,gD as An,cO as Tn,at as In,aS as Fn}from"./index-BoqrvLHQ.js";import{P as Pn}from"./public-shell-ready-K2R8iXSI.js";import{D as Dn,c as Vn}from"./dynamic-schema-form-CRyUchXo.js";import{S as Bn,E as Kt,a as qn,e as Hn,b as Un,c as zn}from"./entity-pages-_nuesgnp.js";import{b as Gn,F as Jn}from"./filter-editors-DGVl9U4D.js";import{l as Wn,H as Yn,n as Qn,G as es,c as Xn}from"./entity-schema-graph-Cq96SJ3c.js";import{l as Zn,p as $e,e as ts,a as Kn,S as ea,J as ta}from"./renderer-CTKNMcXP.js";import{u as sa,a as na,D as aa,P as ra,b as ss,c as oa,C as ia}from"./core.esm-Ctg_pXLe.js";import{V as We,M as ns,a as as}from"./missing-view-xT0B-f5z.js";import{v as la,w as ca,V as da}from"./view-param-filters-DGKxSr7r.js";import{M as ua}from"./member-scope-gate-Cxg2zGQT.js";function ma({onClose:e,entityTypeSlug:t,orgContext:o,onSuccess:i}){const{data:n,isLoading:c}=Tt(t,o),l=`${o.organizationId??o.slug}:${t}`,r=Ts(l,{name:"",customSlug:"",useCustomSlug:!1,metadata:{}},n?.metadata_schema),[d,a]=r.field("name"),[u,m]=r.field("customSlug"),[p,f]=r.field("useCustomSlug"),[b,N]=r.field("metadata"),[x,E]=Is(l,null),S=Fs(),C=p?u:Ps(d),v=async L=>{if(L.preventDefault(),!r.canSubmit)return;if(E(null),!d.trim()){E("Name is required");return}const M=Vn(b),Z={entityType:t,name:d.trim(),slug:p?u:void 0,metadata:Object.keys(M).length>0?M:void 0};try{const $=await S.mutateAsync(Z);if(e(),$.approval_queued||!$.entity){It.info("Create queued for approval");return}typeof $.entity.id=="number"&&i?.($.entity.id)}catch($){E($ instanceof Error?$.message:"Failed to create entity")}},j=n?.name||t,g=r.revision,w=`Create ${j}`,k=`Add a new ${j.toLowerCase()} to your workspace.`;return c?s.jsx(Ds,{rows:6}):s.jsxs("form",{onSubmit:v,children:[s.jsx(Vs,{visible:r.hasConflict,onReload:r.reset}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("h1",{className:"text-2xl font-semibold leading-tight",children:w}),s.jsx("p",{className:"text-sm text-muted-foreground",children:k})]}),s.jsxs("div",{className:"grid gap-4 py-4",children:[s.jsxs("div",{className:"grid gap-2",children:[s.jsxs(Be,{htmlFor:"name",children:["Name ",s.jsx("span",{className:"text-destructive",children:"*"})]}),s.jsx(oe,{id:"name",value:d,onChange:L=>a(L.target.value),placeholder:`Enter ${j.toLowerCase()} name`,autoFocus:!0})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx(Be,{htmlFor:"slug",children:"URL Slug"}),s.jsx("button",{type:"button",onClick:()=>f(!p),className:"text-xs text-muted-foreground hover:text-foreground",children:p?"Auto-generate":"Customize"})]}),p?s.jsx(oe,{id:"slug",value:u,onChange:L=>m(L.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:"custom-slug"}):s.jsx("div",{className:"flex h-9 items-center rounded-md border border-input bg-muted px-3 text-sm text-muted-foreground",children:C||"slug-preview"})]}),g&&Object.keys(g).length>0?s.jsxs(s.Fragment,{children:[s.jsx(Bn,{className:"my-2"}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx(Be,{className:"text-sm font-medium",children:"Additional Fields"}),s.jsx(Dn,{schema:r.revision,values:b,onValuesChange:N,orgContext:o})]})]}):null,x&&s.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:x})]}),s.jsx(Bs,{onCancel:e,cancelDisabled:S.isPending,className:"mt-2",children:s.jsx(R,{type:"submit",disabled:!r.canSubmit||S.isPending||!d.trim(),children:S.isPending?"Creating...":`Create ${j}`})})]})}function pa(e){const t=e?.properties??{},o=zs(e);return Object.entries(t).flatMap(([i,n])=>{const c=o.find(m=>m.field===i);if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(i)||!n||n.const!==void 0||n["x-table-column"]!==!0&&n["x-facet"]!==!0&&!c)return[];const l=[n,...Array.isArray(n.anyOf)?n.anyOf:[]],r=c?.options??Gs(n),d=r.find(m=>m.value!==null)?.value,a=l.find(m=>["string","number","integer","boolean"].includes(String(m.type)))??(d===void 0?void 0:{type:typeof d});if(!a)return[];const u=n.format==="date-time"||a.format==="date-time"?"datetime-local":n.format==="date"||a.format==="date"?"date":a.type==="number"||a.type==="integer"?"number":a.type==="boolean"?"boolean":"string";return[{field:i,label:String(n["x-table-label"]??n.title??i.replaceAll("_"," ")),type:u,options:u==="boolean"&&!r.some(m=>typeof m.value=="boolean")?[{value:!0,label:"Yes"},{value:!1,label:"No"},...r]:r}]})}const _t={eq:"is",neq:"is not",lt:"<",lte:"≤",gt:">",gte:"≥"};function fa(e,t){return e.value===null&&e.op==="neq"?{op:_t.eq,value:"set"}:{op:_t[e.op],value:t?.options.find(o=>o.value===e.value)?.label??String(e.value)}}function ha(e){const t=e?.[ze];return t===void 0?{}:Xe(t)}function ga(e,t){return(e.presets??[]).filter(o=>!o.viewer||!!t?.email)}function ya(e,t,o,i){try{const n=ha(t),c=ga(n,i),l=e[Ft],r=l===void 0?void 0:c.find(p=>p.key===l);if(l!==void 0&&!r)throw new Error("This saved filter is unavailable. Choose another filter.");if(r&&!o&&typeof e.segment=="string"&&e.segment)throw new Error("A saved filter and an explicit selection cannot be combined.");const d=r&&e[te]===void 0?{collection:Se(r,void 0,i)}:qs(e,o);if(d.error)throw d.error;const a=e[Hs],u=a===void 0?r?.table??n.table??{}:Xe({table:typeof a=="string"?JSON.parse(a):a}).table??{},m=!!r&&($t(d.collection)!==$t(Se(r,void 0,i))||Ce(u)!==Ce(r.table??n.table??{}));return{...d,presentation:n,presets:c,preset:r,table:u,edited:m}}catch(n){return{collection:{},presentation:{},presets:[],table:{},edited:!1,error:n instanceof Error?n:new Error("Invalid collection configuration")}}}function $t(e){return JSON.stringify([e.search??"",e.segment??"",(e.filters??[]).map(Q)])}function Q(e){return JSON.stringify([e.field,e.op,e.value])}function Ce(e){return JSON.stringify([e.columns??null,e.sort?.field??null,e.sort?.order??null])}function ba(e,t){return t?{[Ft]:t,[te]:Ue(e)[te]??"{}"}:Ue(e)}function xa(e,t,o,i,n=new Date,c){let l=t.filters??[],r=e.viewer;if(r){const a=c?.email?Q({field:r.field,op:"eq",value:c.email.toLowerCase()}):void 0;a&&l.some(u=>Q(u)===a)?l=l.filter(u=>Q(u)!==a):r=void 0}let d=e.relativeDate;if(d){const a=(Se({...e,viewer:void 0,selection:{}},n).filters??[]).map(Q),u=l.map(Q);a.every(m=>u.includes(m))?l=l.filter(m=>!a.includes(Q(m))):d=void 0}return{key:e.key,label:e.label,selection:{...t.search?{search:t.search}:{},...l.length?{filters:l}:{},...t.segment?{segment:t.segment}:{}},...Ce(o)!==Ce(i.table??{})?{table:o}:{},...d?{relativeDate:d}:{},...r?{viewer:r}:{}}}function va(e,t,o){const i=[...e.filters??[]],n=o??(t.length===1&&t[0].op==="eq"?i.findIndex(l=>l.field===t[0].field&&l.op==="eq"):-1),c=n>=0?[...i.slice(0,n),...t,...i.slice(n+1)]:[...i,...t];return{...e,filters:Js({filters:c}).filters}}function Sa(e,t){return{...e,filters:e.filters?.filter((o,i)=>i!==t)}}function ja(e,t){return{...typeof e.$preset=="string"?e[te]===void 0?{$preset:e.$preset}:{$preset:e.$preset,[te]:String(Us(e[te]))}:Ue(t),...e.$table===void 0?{}:{$table:typeof e.$table=="string"?e.$table:JSON.stringify(e.$table)}}}const Na=[{field:"name",label:"Name"},{field:"created_at",label:"Created"},{field:"total_content",label:"Activity count"},{field:"active_connections",label:"Connections"},{field:"automations_count",label:"Automations"},{field:"children_count",label:"Children"}];function Ca(e){return e.sort&&Na.some(t=>t.field===e.sort?.field)?e.sort:{field:"created_at",order:"desc"}}function Ea(e,t,o,i,n){const c={...i,filters:i.filters?.filter(l=>l.field!==o)};return Pt({queryKey:["collection-facets",e,t,o,c],enabled:!!t&&!!o,staleTime:3e4,retry:!1,queryFn:async({signal:l})=>{const r=await je("query_sdk",{title:`Value counts query for ${o}`,script:`const input = ${JSON.stringify({field:o,collection:c})};
2
+ ${t}`},e,{signal:l}),d=r.return_value;if(!r.success||typeof d?.connection!="string"||typeof d.sql!="string")throw new Error(r.error?.message??"Value distribution is unavailable");if(l.aborted)throw new DOMException("Aborted","AbortError");const a=await je("query_sql",{title:`Value counts for ${o}`,connection:d.connection,sql:d.sql,limit:51},e,{signal:l});if(a.error)throw new Error(a.error);if(!Array.isArray(a.rows))throw new Error("Source did not return value counts");const u=a.rows.map(m=>{const p=m,f=typeof p.count=="string"&&/^\d+$/.test(p.count)?Number(p.count):p.count;if(!(p.value===null||["string","number","boolean"].includes(typeof p.value))||typeof f!="number"||!Number.isSafeInteger(f)||f<0)throw new Error("Source returned an invalid value distribution");return{value:p.value,count:f}});return{values:u.slice(0,50),truncated:u.length>50||a.truncated===!0}}})}const wa=300;function ka({label:e,search:t,onSearch:o,className:i}){const n=t??"",[c,l]=y.useState(n),r=y.useRef({search:t,onSearch:o});r.current={search:t,onSearch:o};const d=y.useRef(void 0);y.useEffect(()=>{const u=()=>{clearTimeout(d.current),l(r.current.search??"")};return window.addEventListener("popstate",u),()=>window.removeEventListener("popstate",u)},[]);const a=y.useRef(n);return y.useEffect(()=>{n!==a.current&&(a.current=n,l(n))},[n]),y.useEffect(()=>{if(c===(r.current.search??""))return;const u=setTimeout(()=>{const m=r.current.onSearch;a.current=c,m(c||void 0,!0)},wa);return d.current=u,()=>clearTimeout(u)},[c]),s.jsxs("div",{className:`relative${i?` ${i}`:""}`,children:[s.jsx(Ws,{"aria-hidden":"true",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(oe,{type:"search","aria-label":`Search ${e.toLowerCase()}`,placeholder:`Search ${e.toLowerCase()}...`,maxLength:512,value:c,onChange:u=>l(u.target.value),className:"pl-9"})]})}function _a({field:e,initial:t,org:o,facetQuery:i,collection:n,onApply:c,close:l}){const[r,d]=y.useState(t?.op??"eq"),[a,u]=y.useState(t?.value==null?"":String(t.value)),[m,p]=y.useState(""),[f,b]=y.useState(!1),[N,x]=y.useState(),E=e.type==="date"||e.type==="datetime-local"||e.type==="number"?e.type:"text",S=Ea(o,i,e.field,n),C=g=>{try{const w=f?[{field:e.field,op:"gte",value:e.type==="number"?Number(a):a},{field:e.field,op:"lte",value:e.type==="number"?Number(m):m}]:[{field:e.field,op:r,value:g}];if(e.type==="datetime-local")for(const M of w)typeof M.value=="string"&&(M.value=new Date(M.value).toISOString());if(w.some(M=>typeof M.value=="number"&&!Number.isFinite(M.value)))throw new Error("Enter a valid number.");const k=w[0].value,L=w[1]?.value;if(f&&k!=null&&L!=null&&k>L)throw new Error("The lower bound must be before the upper bound.");c(w),l()}catch(w){x(w instanceof Error?w.message:"Could not apply filter")}},v=[...e.options];for(const g of S.data?.values??[])v.some(w=>w.value===g.value)||v.push({value:g.value,label:g.value===null?"Not supplied":String(g.value)});const j=Math.max(1,...S.data?.values.map(g=>g.count)??[]);return s.jsxs("div",{className:"min-w-0 space-y-3 p-3",children:[s.jsxs("select",{"aria-label":"Filter operator",className:"h-8 w-full rounded-md border bg-background px-2 text-sm",value:f?"range":r,onChange:g=>{b(g.target.value==="range"),g.target.value!=="range"&&d(g.target.value)},children:[s.jsx("option",{value:"eq",children:"is"}),s.jsx("option",{value:"neq",children:"is not"}),(e.type==="number"||e.type==="date"||e.type==="datetime-local")&&s.jsxs(s.Fragment,{children:[s.jsx("option",{value:"lt",children:"less than / before"}),s.jsx("option",{value:"lte",children:"at most / on or before"}),s.jsx("option",{value:"gt",children:"greater than / after"}),s.jsx("option",{value:"gte",children:"at least / on or after"}),t?null:s.jsx("option",{value:"range",children:"between"})]})]}),e.type!=="boolean"&&s.jsxs("form",{className:"space-y-2",onSubmit:g=>{g.preventDefault(),C(e.type==="number"?Number(a):a)},children:[s.jsx(oe,{required:!0,"aria-label":f?"From value":"Filter value",type:E,step:e.type==="number"?"any":void 0,value:a,onChange:g=>u(g.target.value),placeholder:"Enter a value…"}),f&&s.jsx(oe,{required:!0,"aria-label":"To value",type:E,step:e.type==="number"?"any":void 0,value:m,onChange:g=>p(g.target.value)}),s.jsx(R,{size:"sm",type:"submit",className:"w-full",children:"Apply filter"})]}),!f&&(r==="eq"||r==="neq")&&s.jsx("div",{className:"max-h-48 space-y-1 overflow-y-auto",children:v.filter(g=>!a||g.label.toLowerCase().includes(a.toLowerCase())).map(g=>{const w=S.data?.values.find(k=>k.value===g.value)?.count;return s.jsxs("button",{type:"button","aria-label":g.label,onClick:()=>C(g.value),className:"relative flex w-full items-center justify-between gap-3 overflow-hidden rounded px-2 py-1.5 text-left text-sm hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[w!==void 0&&s.jsx("span",{"aria-hidden":"true",className:"absolute inset-y-0 left-0 bg-primary/10",style:{width:`${w/j*100}%`}}),s.jsx("span",{className:"relative truncate",children:g.label}),s.jsx("span",{className:"relative text-xs tabular-nums text-muted-foreground",children:w?.toLocaleString()})]},JSON.stringify(g.value))})}),i&&S.isFetching&&s.jsx("p",{role:"status",className:"text-xs text-muted-foreground",children:"Loading distribution…"}),S.isError&&s.jsx("p",{role:"status",className:"text-xs text-muted-foreground",children:"Counts unavailable. You can still enter a value."}),S.data?.truncated&&s.jsx("p",{className:"text-xs text-muted-foreground",children:"Top 50 values. Enter any other value above."}),N&&s.jsx("p",{role:"alert",className:"text-xs text-destructive",children:N})]})}function rs({collection:e,schema:t,label:o,onChange:i,org:n,facetQuery:c,segmentChip:l,viewFilters:r,onClearAll:d}){const a=pa(t),u=(b,N)=>({kind:"custom",className:"w-80",render:x=>s.jsx(_a,{field:b,initial:N==null?void 0:e.filters?.[N],org:n,facetQuery:c,collection:e,onApply:E=>i(va(e,E,N)),close:x})}),m=a.map(b=>({key:b.field,label:b.label,icon:s.jsx(Ys,{className:"h-4 w-4"}),editor:u(b)})),p=new Map,f=(e.filters??[]).map((b,N)=>{const x=`${b.field}:${b.op}:${JSON.stringify(b.value)}`,E=p.get(x)??0;p.set(x,E+1);const S=a.find(C=>C.field===b.field);return{id:`${x}:${E}`,label:S?.label??b.field,...fa(b,S),editor:S?u(S,N):void 0,onRemove:()=>i(Sa(e,N))}});if(l&&f.unshift(l),r?.fields.length){for(const b of m)b.group=o;m.push(...r.fields),f.push(...r.chips)}return!m.length&&!f.length?{fields:m,chips:f,clearAll:()=>{}}:{fields:m,chips:f,clearAll:d??(()=>i({...e,filters:[],segment:void 0}))}}function $a(e){const{fields:t}=rs(e);return t.length?s.jsx(Gn,{fields:t}):null}function Ra(e){const{chips:t,clearAll:o}=rs(e);return t.length?s.jsx(Jn,{label:`${e.label} filters`,fields:[],chips:t,onClearAll:o,className:"mb-4"}):null}const Ee=120,H=12;function Rt(e,t){return typeof e.linkId=="number"&&typeof t.linkId=="number"?e.linkId-t.linkId:String(e.linkId).localeCompare(String(t.linkId))}function La(e){const t=e.records.slice(0,Ee),o=a=>e.types.get(a)??{label:a},i=new Map;for(const a of t)i.set(String(a.id),{source:a.source,entityType:e.typeSlug,slug:a.slug,name:a.name,isFocus:!0,hasMoreLinks:!1});const n=new Map;for(const a of e.links){if(!i.has(String(a.recordId)))continue;const u=n.get(a.recordId)??new Map;u.set(a.linkId,a),n.set(a.recordId,u)}const c=new Map;for(const[a,u]of n){const m=[...u.values()].sort(Rt),p=i.get(String(a));p&&m.length>H&&(p.hasMoreLinks=!0);for(const f of m.slice(0,H)){c.set(f.linkId,f);const b=String(f.peer.id);i.has(b)||i.set(b,{source:f.peer.source,...f.peer.remote?{remote:f.peer.remote}:{},entityType:f.peer.type,slug:f.peer.slug,name:f.peer.name,isFocus:!1,hasMoreLinks:!1})}}const l=[];for(const[a,u]of i){const m=u.remote?{label:u.entityType}:o(u.entityType),p=u.name||u.slug,f=u.hasMoreLinks?`${m.label} · ${H}+ links`:m.label;l.push({id:a,data:{slug:u.slug,label:p,icon:m.icon,isSystem:!1,metaLabel:f},width:Qn(p,f),height:Yn})}const r=new Map;for(const a of[...c.values()].sort(Rt)){const u=String(a.fromId),m=String(a.toId),p=JSON.stringify([u,m]),f=r.get(p)??{source:u,target:m,rels:new Map,symmetric:!0};f.symmetric&&=a.isSymmetric,f.rels.has(a.relSlug)||f.rels.set(a.relSlug,{slug:a.relSlug,label:a.relName,ruleCount:1}),r.set(p,f)}const d=[...r.entries()].map(([a,u])=>({id:`link:${a}`,source:u.source,target:u.target,data:{relationships:[...u.rels.values()],isSymmetric:u.symmetric}}));return{nodes:l,edges:d,records:i,hasMoreRecords:e.hasMore===!0||e.records.length>Ee,listedCount:t.length,focusCount:t.length}}async function Oa(e,t){const o=La(e);return{...await Wn({nodes:o.nodes,edges:o.edges},t),records:o.records,hasMoreRecords:o.hasMoreRecords,listedCount:o.listedCount,focusCount:o.focusCount}}const Ma=8,Aa=3,Ta=4;function ve(e){return`source:${JSON.stringify([e.type,e.key])}`}function Ia(e,t){return t.map(o=>{const i={type:e,key:o.slug};return{...o,id:ve(i),source:i}})}function Lt(e){return JSON.stringify([e.relationship_type,e.direction,e.entity_type,e.key])}async function Fa(e,t,o){const i=e.slice(0,Ma),n=[];let c=0;return await Promise.all(Array.from({length:Math.min(Aa,i.length)},async()=>{for(;c<i.length;){const l=c++,r=i[l];try{if(o?.aborted)throw o.reason;const d=await t(r),a=new Map(r.links.map(x=>[Lt(x),x]));for(const x of d.record_links){const E=Lt(x),S=a.get(E);(!S||S.occurred_at<x.occurred_at)&&a.set(E,x)}const u=new Map((r.relationships??[]).map(x=>[x.id,x]));for(const x of d.relationships??[])u.set(x.id,x);const m=[...u.values()].slice(0,H+1),p=[...a.values()].slice(0,H+1),f=(r.pagesRead??0)+1,b=!!d.next_cursor&&f>=Ta,N=d.record_failures.some(x=>x.code!=="withheld")||!!d.relationship_failures?.length||b;n[l]={read:{record:r.record,links:p,failed:N,entityId:r.entityId,relationships:m},...!b&&(N||d.next_cursor&&p.length+m.length<=H)?{next:{record:r.record,entityId:r.entityId,relationships:m,pagesRead:f,cursor:d.next_cursor??r.cursor,links:p}}:{}}}catch(d){if(o?.aborted)throw d;n[l]={read:{record:r.record,links:r.links,failed:!0,entityId:r.entityId,relationships:r.relationships},next:{...r,cursor:d instanceof Qs&&d.status===400?null:r.cursor}}}}})),{reads:n.map(l=>l.read),pending:[...n.flatMap(l=>l.next?[l.next]:[]),...e.slice(i.length)]}}function Pa(e,t){const o=new Map;for(const c of e)for(const l of c.reads)o.set(String(l.entityId??ve(l.record)),l);const i=new Map(t.map(c=>[c.slug,c])),n=[];for(const[c,l]of o){for(const r of l.relationships??[]){const d=(x,E,S)=>S?`remote:${S}`:typeof x=="number"?x:ve({type:E,key:x}),a=d(r.from_entity_id,r.from_entity_type,r.from_entity_url),u=d(r.to_entity_id,r.to_entity_type,r.to_entity_url),m=String(a)===c,p=m?u:a,f=m?r.to_entity_id:r.from_entity_id,b=m?r.to_entity_url:r.from_entity_url,N=(m?r.to_entity_type:r.from_entity_type)??"";n.push({recordId:c,linkId:r.id,fromId:a,toId:u,relSlug:r.relationship_type_slug,relName:r.relationship_type_name,isSymmetric:r.is_symmetric,peer:{id:p,name:(m?r.to_entity_name:r.from_entity_name)??String(f),slug:(m?r.to_entity_slug:r.from_entity_slug)??String(f),type:N,...b?{remote:{url:Xs(b)}}:typeof f=="string"?{source:{type:N,key:f}}:{}}})}for(const r of l.links){const d={type:r.entity_type,key:r.key},a=ve(d),u=i.get(r.relationship_type);let m=r.direction==="incoming"?a:c,p=r.direction==="incoming"?c:a;u?.is_symmetric&&m>p&&([m,p]=[p,m]),n.push({recordId:c,linkId:JSON.stringify([m,p,r.relationship_type]),fromId:m,toId:p,relSlug:r.relationship_type,relName:u?.name||r.relationship_type.replaceAll("_"," "),isSymmetric:u?.is_symmetric??!1,peer:{id:a,name:r.name||r.key,slug:r.key,type:r.entity_type,source:d}})}}return{links:n,checked:o.size,failed:[...o.values()].filter(c=>c.failed).length}}function Da(e,t,o,i,n,c=!1){const{orgContext:l}=ke(),r=Dt(l),d=Zs(l),a=y.useMemo(()=>c?Ia(t,o):o,[c,t,o]),u=y.useMemo(()=>a.slice(0,Ee).flatMap(v=>v.source?[{record:v.source,cursor:null,links:[]}]:typeof v.id=="number"?[{entityId:v.id,record:{type:t,key:v.slug},cursor:null,links:[]}]:[]),[a,t]),m=Ks({queryKey:["source-records-graph",l.organizationId,e,t,u.map(v=>[v.record,v.entityId])],enabled:!0,initialPageParam:u,queryFn:({pageParam:v,signal:j})=>Fa(v,async g=>{const w=await je("manage_entity",{action:"list_links",...g.entityId===void 0?{record:g.record,cursor:g.cursor}:{entity_id:g.entityId,offset:Number(g.cursor??0)},limit:H+1},e,{signal:j});return{...w,record_links:w.record_links??[],record_failures:w.record_failures??[],next_cursor:g.entityId===void 0?w.next_cursor:w.metadata?.has_more?String(Number(g.cursor??0)+H+1):null}},j),getNextPageParam:v=>v.pending.length?v.pending:void 0,staleTime:3e4,retry:!1}),p=y.useMemo(()=>m.data?Pa(m.data.pages,d.data??[]):void 0,[m.data,d.data]),f=p?.links,b=m.isError,N=JSON.stringify([l.organizationId,e,t,c,a.map(v=>[v.id,v.name,v.slug]),i]),x=y.useMemo(()=>new Map((r.data??[]).map(v=>[v.slug,{label:v.name||v.slug,icon:v.icon}])),[r.data]),[E,S]=y.useState(null);y.useEffect(()=>{if(!f)return;let v=!1;return Oa({typeSlug:t,records:a,hasMore:i,links:f,types:x},{targetAspect:n}).then(j=>{v||S({graph:j,key:N,isError:!1})}).catch(()=>{v||S({graph:null,key:N,isError:!0})}),()=>{v=!0}},[f,t,a,i,x,n,N]);const C=E?.key===N?E:null;return{graph:C?.graph??null,isLoading:!b&&!C,isError:b||C?.isError===!0,sourceProgress:{checked:p?.checked??0,total:Math.min(o.length,Ee),failed:p?.failed??0,hasMore:!!m.hasNextPage,isFetching:m.isFetching,loadMore:()=>{m.isFetching||m.fetchNextPage()}}}}function Va(e){const t=new Map(e.nodes.map(n=>[n.id,n.data.label])),o=e.nodes.map(n=>({id:n.id,x:n.position.x+n.width/2,y:n.position.y+n.height/2,w:n.width,h:n.height,title:n.data.label,meta:n.data.metaLabel,icon:n.data.icon,muted:e.records.get(n.id)?.isFocus===!1})),i=e.edges.map(n=>{const{relationships:c,isSymmetric:l}=n.data,r=c.map(d=>d.label);return{id:n.id,source:n.source,target:n.target,route:n.route??null,summary:r.length===1?r[0]:`${r.length} relationships`,details:r,directed:!l,ariaLabel:`${t.get(n.source)??n.source} ${l?"and":"to"} ${t.get(n.target)??n.target}: ${r.join(", ")}`}});return{boxes:o,edges:i}}function Ba({ownerSlug:e,typeSlug:t,records:o,hasMore:i,sourceBacked:n=!1}){const c=ie(),l=Vt(),{orgContext:r}=ke(),{data:d=[]}=Dt(r),a=d.find(j=>j.slug===t)?.name??t,[u,m]=y.useState(),p=y.useRef(null),f=y.useCallback(j=>{if(p.current?.disconnect(),p.current=null,!j||typeof ResizeObserver>"u")return;const g=()=>{if(!j.clientWidth||!j.clientHeight)return;const k=Math.round(j.clientHeight/j.clientWidth*10)/10;m(L=>L===k?L:k)};g();const w=new ResizeObserver(g);w.observe(j),p.current=w},[]),{graph:b,isLoading:N,isError:x,sourceProgress:E}=Da(e,t,o,i,u,n),S=y.useMemo(()=>b?Va(b):null,[b]),C=y.useCallback(j=>{const g=b?.records.get(j);if(g){if(g.remote){g.remote.url&&window.open(g.remote.url,"_blank","noopener,noreferrer");return}if(l){l.open(Zn({...g.source?{record:g.source}:{entityId:Number(j)},ownerSlug:e,orgContext:r,name:g.name||g.slug}));return}c({to:en(e,[{entity_type:g.entityType,slug:g.slug}])})}},[b,e,r,l,c]);if(x)return s.jsx(tn,{label:`${a} graph`});if(N||!b||!S)return s.jsx(es,{label:`Loading ${a} graph`});const v=E?s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{className:"text-sm text-muted-foreground",role:"status",children:[s.jsxs("p",{children:["Checked ",E.checked," of ",E.total," records. Up to ",H," relationships per record."]}),E.failed>0?s.jsx("p",{role:"alert",children:"Some sources could not be read. These relationships are incomplete."}):null]}),E.hasMore?s.jsx(R,{variant:"outline",size:"sm",disabled:E.isFetching,onClick:E.loadMore,children:E.isFetching?"Loading…":E.failed>0?"Retry sources":"Load more relationships"}):null]}):null;return b.focusCount===0?s.jsxs("div",{className:"space-y-3",children:[v,s.jsx(Bt,{icon:qt,title:`No ${a} records match`,description:"Change the search or filters to see records here."})]}):s.jsxs("div",{className:"flex flex-col gap-2",children:[v,s.jsxs("p",{className:"text-sm text-muted-foreground",children:["Showing ",b.hasMoreRecords?"the first ":"",b.focusCount," ",a," record",b.focusCount===1?"":"s",". Click a record to see it."]}),s.jsx("div",{ref:f,className:"h-[70vh] min-h-[420px] min-w-0 overflow-hidden",children:s.jsx(Xn,{boxes:S.boxes,edges:S.edges,label:`${a} records`,onOpenBox:C,openLabel:j=>`Show ${j.title}`})})]})}function qa(e){return String(e??"").replace(/[_-]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function os(e){return e["x-lobu"]?.role||e["x-lobu-role"]}function Ze(e){const t=e?.properties;if(!t)return null;const n=sn(t).find(([,a])=>os(a)==="workflowState");if(!n)return null;const[c,l]=n,r=l["x-lobu"]?.states,d=Array.isArray(r)&&r.length>0?r:(l.enum??[]).map(a=>({value:a}));return d.length===0||d.some(a=>typeof a.value!="string")?null:{field:c,states:d.map(a=>({...a,label:a.label||nn(l,a.value)||qa(a.value),terminal:a.terminal??["done","complete","completed","closed","archived"].includes(a.value.toLowerCase())}))}}function Ha(e){const t=e?.properties;if(!t)return null;const o=Object.entries(t),i=o.find(([,l])=>os(l)==="sortRank"),n=o.find(([l])=>["rank","sort_rank","order"].includes(l)),c=i??n;return c?{field:c[0]}:null}function Ua(e,{isDerived:t}){const o=e?.["x-lobu"]?.defaultView;return(o==="table"||o==="board")&&!(t&&o!=="table")?o:t?"table":Ze(e)?"board":"table"}const is={version:1,root:{type:"entity-table",props:{state:"{{tableState}}"}}},za={version:1,root:{type:"entity-board",props:{state:"{{boardState}}",onUpdate:"@updateEntity"}}};function Ga(e){const{canShowBoard:t,builtinData:o,builtInLabels:i}=e,n=["table",...t?["board"]:[]],c={table:is,board:za};return n.map(l=>({id:l,label:i[l],builtInMode:l,template:c[l],data:o}))}function Ye(e){return e.replace(/[_-]+/g," ").replace(/\b\w/g,t=>t.toUpperCase())}function we(e,t){if(!t)return e.created_at??String(e.id);const o=$e(e.metadata);return String(o[t.field]??e.created_at??e.id)}function Ja(e,t){const o=e?Number(e):Number.NaN,i=t?Number(t):Number.NaN;return Number.isFinite(o)&&Number.isFinite(i)&&o<i?String((o+i)/2):Number.isFinite(o)?String(o+1):Number.isFinite(i)?String(i-1):String(Date.now())}function Qe(e,t){const o=$e(e.metadata);return String(o[t]??"")}function ls(e,t){return[...e].sort((o,i)=>we(o,t).localeCompare(we(i,t)))}function Wa(e,t,o,i,n){if(!t.startsWith("card:")||!o)return null;const c=Number(t.slice(5)),l=e.find(S=>S.id===c);if(!l)return null;const r=o.startsWith("column:")?o.slice(7):Qe(e.find(S=>`card:${S.id}`===o)??l,i.field);if(!r)return null;const d=ls(e.filter(S=>S.id!==c&&Qe(S,i.field)===r),n),a=o.startsWith("card:")?d.findIndex(S=>`card:${S.id}`===o):d.length,u=a>=0?a:d.length,m=u>0?d[u-1]:void 0,p=d[u],f=n?Ja(m?we(m,n):void 0,p?we(p,n):void 0):void 0,b=$e(l.metadata),N={[i.field]:r,...n&&f?{[n.field]:f}:{}};i.states.find(S=>S.value===r)?.terminal&&!b.completed_at&&(N.completed_at=new Date().toISOString());const E={...b,...N};return{entityId:c,changedMetadata:N,nextMetadata:E}}function Ot(e,t,o){return e.map(i=>i.id===t?{...i,metadata:o}:i)}function Ya({id:e,children:t,className:o}){const{setNodeRef:i,isOver:n}=ss({id:`column:${e}`});return s.jsx("div",{ref:i,className:Ne("min-h-[220px] rounded-lg bg-card p-2 transition-colors",n?"bg-accent/50":"",o),children:t})}function Qa({entity:e,owner:t,statusField:o,entityTypeIcon:i,schema:n,didDragRef:c}){const l=$e(e.metadata),{attributes:r,listeners:d,setNodeRef:a,transform:u,isDragging:m}=oa({id:`card:${e.id}`}),{setNodeRef:p,isOver:f}=ss({id:`card:${e.id}`}),b=Ht(t,ts(e)),N=x=>{c.current&&(x.preventDefault(),x.stopPropagation())};return s.jsx("div",{ref:x=>{a(x),p(x)},style:{transform:ia.Translate.toString(u)},className:Ne(on,"p-3 text-sm text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",m?"opacity-60":"",f?"ring-1 ring-ring":""),children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx("button",{type:"button",className:"mt-0.5 shrink-0 cursor-grab touch-none text-muted-foreground/60 hover:text-foreground active:cursor-grabbing","aria-label":`Drag ${e.name}`,...r,...d,children:s.jsx(rn,{className:"h-4 w-4"})}),s.jsx(Kt,{metadata:l,metadataSchema:n,name:e.name,typeIcon:i,className:"mt-0.5 h-6 w-6 shrink-0",initialsFallback:!0}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx(_e,{to:b,className:"font-medium text-foreground hover:underline",onClick:N,children:e.name}),s.jsxs("div",{className:"mt-1 flex flex-wrap gap-1.5",children:[typeof l.priority=="string"&&l.priority?s.jsx(Ge,{variant:"outline",className:"text-xs",children:Ye(l.priority)}):null,typeof l[o]=="string"&&l[o]?s.jsx(Ge,{variant:"secondary",className:"text-xs",children:Ye(String(l[o]))}):null]})]})]})})}function Xa({owner:e,entities:t,totalCount:o,schema:i,entityTypeIcon:n,onUpdate:c}){const l=y.useMemo(()=>Ze(i),[i]),r=y.useMemo(()=>Ha(i),[i]),[d,a]=y.useState(t),[u,m]=y.useState(()=>new Set),p=y.useRef(!1),f=sa(na(ra,{activationConstraint:{distance:6}})),b=y.useCallback(()=>{window.setTimeout(()=>{p.current=!1},0)},[]);y.useEffect(()=>{a(t)},[t]);const N=y.useMemo(()=>{if(!l)return new Map;const C=new Map(l.states.map(v=>[v.value,[]]));for(const v of d){const j=Qe(v,l.field),g=C.has(j)?j:l.states[0]?.value;g&&C.get(g)?.push(v)}for(const[v,j]of C)C.set(v,ls(j,r));return C},[d,r,l]);if(!l)return null;const x=C=>{m(v=>{const j=new Set(v);return j.has(C)?j.delete(C):j.add(C),j})},E=()=>{p.current=!0},S=C=>{const v=String(C.active.id),j=C.over?String(C.over.id):null,g=Wa(d,v,j,l,r);if(!g){b();return}const{entityId:w,changedMetadata:k,nextMetadata:L}=g,Z=d.find($=>$.id===w)?.metadata;a($=>Ot($,w,L)),c(w,k).catch(()=>{a($=>Ot($,w,Z))}),b()};return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-base font-semibold",children:"Board"}),s.jsxs("p",{className:"text-sm text-muted-foreground",children:["Grouped by ",Ye(l.field),typeof o=="number"&&o>d.length?s.jsxs(s.Fragment,{children:[" · ",s.jsxs("span",{className:"text-amber-600 dark:text-amber-500",children:["showing first ",d.length," of ",o," — narrow with search"]})]}):null]})]}),s.jsx(aa,{sensors:f,onDragStart:E,onDragEnd:S,children:s.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-4",children:l.states.map(C=>{const v=N.get(C.value)??[],j=C.collapsed??C.terminal,g=j&&!u.has(C.value);return s.jsxs(Ya,{id:C.value,children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2 px-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[C.terminal?s.jsx(an,{className:"h-4 w-4 text-muted-foreground"}):null,s.jsx("h3",{className:"text-sm font-medium",children:C.label})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Ge,{variant:"secondary",className:"text-xs",children:v.length}),j?s.jsx(R,{type:"button",variant:"ghost",size:"sm",className:"h-6 px-1.5 text-xs",onClick:()=>x(C.value),children:g?"Show":"Hide"}):null]})]}),g?s.jsxs("p",{className:"py-4 text-center text-xs text-muted-foreground/60",children:[v.length," hidden ",C.label?.toLowerCase()," item",v.length===1?"":"s"]}):s.jsx("div",{className:"space-y-2",children:v.length>0?v.map(w=>s.jsx(Qa,{entity:w,owner:e,statusField:l.field,entityTypeIcon:n,schema:i,didDragRef:p},w.id)):s.jsxs("p",{className:"py-4 text-center text-xs text-muted-foreground/60",children:["No ",C.label?.toLowerCase()," items"]})})]},C.value)})})})]})}const Za=y.memo(Xa);function Ka(e){let t=0;for(let o=0;o<e.length;o++)t=(t<<5)-t+e.charCodeAt(o),t|=0;return t.toString(36)}function cs(e,t){return{queryKey:["metric_series",e,Ka(t)],queryFn:()=>je("metric_series",{sql:t},{slug:e}),staleTime:6e4}}function ds(e,t){const o=!!e&&!!t,i=cs(e??"",t??"");return Pt({...i,enabled:o})}ds.queryOptions=(e,t)=>cs(e,t);function er(e,t){if(!e?.columns?.length||!e.rows)return[];const o=e.columns.indexOf(t);return o<0?[]:e.rows.map(i=>Number(i[o])||0)}const Mt=/^[a-z][a-z0-9_]*$/;function tr(e){const t=Object.entries(e);for(const[n,c]of t){if(!Mt.test(n))throw new Error(`lifecycleCumulativeStatsSql: unsafe column name '${n}'`);if(!Mt.test(c))throw new Error(`lifecycleCumulativeStatsSql: unsafe entity_type '${c}'`)}const o=t.flatMap(([n,c])=>[`COUNT(*) FILTER (
3
+ WHERE semantic_type = 'change'
4
+ AND metadata->>'category' = 'lifecycle'
5
+ AND metadata->>'entity_type' = '${c}'
6
+ AND metadata->>'op' = 'created'
7
+ ) AS ${n}_added`,`COUNT(*) FILTER (
8
+ WHERE semantic_type = 'change'
9
+ AND metadata->>'category' = 'lifecycle'
10
+ AND metadata->>'entity_type' = '${c}'
11
+ AND metadata->>'op' = 'deleted'
12
+ ) AS ${n}_removed`]).join(`,
13
+ `),i=t.map(([n])=>` SUM(COALESCE(b.${n}_added, 0) - COALESCE(b.${n}_removed, 0))
14
+ OVER (ORDER BY d.bucket) AS ${n}`).join(`,
15
+ `);return`
16
+ WITH days AS (
17
+ SELECT generate_series(
18
+ date_trunc('day', now() - interval '13 days'),
19
+ date_trunc('day', now()),
20
+ interval '1 day'
21
+ ) AS bucket
22
+ ),
23
+ buckets AS (
24
+ SELECT
25
+ date_trunc('day', created_at) AS bucket,
26
+ ${o}
27
+ FROM events
28
+ WHERE created_at > now() - interval '14 days'
29
+ GROUP BY 1
30
+ )
31
+ SELECT d.bucket,
32
+ ${i}
33
+ FROM days d
34
+ LEFT JOIN buckets b ON b.bucket = d.bucket
35
+ ORDER BY d.bucket
36
+ `}const sr={"memory-activity":`
37
+ WITH days AS (
38
+ SELECT generate_series(
39
+ date_trunc('day', now() - interval '13 days'),
40
+ date_trunc('day', now()),
41
+ interval '1 day'
42
+ ) AS bucket
43
+ ),
44
+ buckets AS (
45
+ SELECT
46
+ date_trunc('day', created_at) AS bucket,
47
+ COUNT(*) FILTER (
48
+ WHERE semantic_type NOT IN ('change', 'audit', 'operation')
49
+ ) AS events_count,
50
+ COUNT(*) FILTER (
51
+ WHERE semantic_type = 'change'
52
+ AND metadata->>'category' = 'lifecycle'
53
+ AND metadata->>'entity_type' = 'connection'
54
+ AND metadata->>'op' = 'created'
55
+ ) AS connections_added,
56
+ COUNT(*) FILTER (
57
+ WHERE semantic_type = 'change'
58
+ AND metadata->>'category' = 'lifecycle'
59
+ AND metadata->>'entity_type' = 'connection'
60
+ AND metadata->>'op' = 'deleted'
61
+ ) AS connections_removed
62
+ FROM events
63
+ WHERE created_at > now() - interval '14 days'
64
+ GROUP BY 1
65
+ )
66
+ SELECT d.bucket,
67
+ COALESCE(b.events_count, 0)::int AS events,
68
+ SUM(COALESCE(b.connections_added, 0) - COALESCE(b.connections_removed, 0))
69
+ OVER (ORDER BY d.bucket) AS connections
70
+ FROM days d
71
+ LEFT JOIN buckets b ON b.bucket = d.bucket
72
+ ORDER BY d.bucket
73
+ `};function nr(e){if(typeof e.sql=="string"&&e.sql.trim())return e.sql;if(e.lifecycle&&typeof e.lifecycle=="object"){const t=Object.fromEntries(Object.entries(e.lifecycle).map(([o,i])=>[o,String(i)]));if(Object.keys(t).length>0)try{return tr(t)}catch{return null}}return typeof e.preset=="string"?sr[e.preset]??null:null}function ar({owner:e,sql:t,lifecycle:o,preset:i,column:n,chart:c,height:l,width:r,color:d,label:a,className:u}){const m=y.useMemo(()=>nr({sql:t,lifecycle:o,preset:i}),[t,o,i]),p=typeof e=="string"&&e?e:null,{data:f}=ds(p,m),b=String(n??""),N=y.useMemo(()=>er(f,b),[f,b]),x=y.useMemo(()=>!f?.columns?.length||!f.rows?[]:f.rows.map((S,C)=>({label:String(S[0]??"").slice(0,10),value:N[C]??0})),[f,N]);if(!p||!m||!b)return null;const E=c==="line"?s.jsx(Kn,{data:x,height:typeof l=="number"?l:void 0}):s.jsx(ea,{data:N,height:typeof l=="number"?l:void 0,width:typeof r=="number"?r:void 0,color:typeof d=="string"?d:void 0});return a==null?s.jsx("div",{className:u,children:E}):s.jsxs("div",{className:u,children:[s.jsx("p",{className:"text-sm text-muted-foreground",children:String(a)}),E]})}function rr({metadata:e,metadataSchema:t,name:o,typeIcon:i,initialsFallback:n,className:c}){return s.jsx(Kt,{metadata:e,metadataSchema:t,name:String(o??""),typeIcon:i,initialsFallback:!!n,className:c})}function or({entity:e,owner:t,className:o,onClick:i,children:n}){const c=e;if(!c)return s.jsx(s.Fragment,{children:n});const l=Ht(String(t??""),ts(c));return s.jsx(_e,{to:l,className:o,onClick:i,children:n})}function ir({state:e}){return e?s.jsx(qn,{...e}):null}function lr({state:e,onUpdate:t}){return e?s.jsx(Za,{...e,onUpdate:t}):null}const cr={"entity-avatar":rr,"entity-link":or,"entity-table":ir,"entity-board":lr,"metric-series":ar};function dr({ownerSlug:e,typeSlug:t,title:o,shape:i}){const[n,c]=y.useState(!1),l=ie(),{visible:r,system:d,isTypesLoading:a}=ln(e),u=p=>{c(!1);const f=`/${e}/${Yt(p)}`;l({to:i?`${f}/${Qt}/${i}`:f})},m=p=>s.jsxs(hn,{value:`${p.name} ${p.slug}`,onSelect:()=>u(p.slug),children:[s.jsx(Wt,{icon:p.icon,className:"mr-2 h-4 w-4 shrink-0"}),s.jsx("span",{className:"flex-1 truncate",children:p.name||p.slug}),p.slug===t?s.jsx(gn,{className:"ml-2 h-3.5 w-3.5 shrink-0","aria-label":"Current"}):null,p.entity_count!=null?s.jsx("span",{className:"ml-2 shrink-0 text-xs tabular-nums text-muted-foreground",children:p.entity_count.toLocaleString()}):null]},p.slug);return s.jsxs(Ut,{open:n,onOpenChange:c,children:[s.jsx("h1",{className:"flex min-w-0 items-center text-lg font-semibold tracking-tight @sm:text-2xl",children:s.jsx(zt,{asChild:!0,children:s.jsxs(R,{type:"button",variant:"ghost",title:o,className:"-ml-2 h-auto min-w-0 gap-1 px-2 py-1 text-lg font-semibold tracking-tight @sm:gap-1.5 @sm:text-2xl",children:[s.jsx("span",{className:"truncate",children:o}),s.jsx(Gt,{className:"h-5 w-5 shrink-0 text-muted-foreground"})]})})}),s.jsx(Jt,{align:"start",className:"w-72 p-0",children:s.jsxs(cn,{children:[s.jsx(dn,{autoFocus:!0,placeholder:"Find a type…"}),s.jsxs(un,{children:[s.jsx(mn,{children:a?"Loading types…":"No type matches."}),r.length>0?s.jsx(wt,{heading:"Types",children:r.map(m)}):null,d.length>0?s.jsx(wt,{heading:"System",children:d.map(m)}):null]}),s.jsx(pn,{}),s.jsxs(_e,{to:"/$owner",params:{owner:e},search:{layout:"graph"},onClick:()=>c(!1),className:"flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground hover:text-foreground",children:[s.jsx(fn,{className:"h-4 w-4"}),"Data map"]})]})})]})}function ur(e){return Object.entries(e?.metrics_config?.segments??{}).filter(([,t])=>t.on==="entity").map(([t,o])=>({name:t,description:o.description}))}const xe={table:{label:"Table",icon:wn},board:{label:"Board",icon:En},graph:{label:"Graph",icon:qt}},us=(e,t)=>`lobu.record-shape:v1:${e}/${t}`,mr=new Set(["table","board","graph"]);function pr(e,t){const o=_n(us(e,t));return o&&mr.has(o)?o:void 0}function fr(e,t,o){$n(us(e,t),o)}const At=":records";function hr({ownerSlug:e,entityTypeSlug:t,create:o,onCreateChange:i,viewKey:n,shape:c}){const{orgContext:l,hasOrgContext:r}=ke(),d=Tt(t,l),{data:a,isLoading:u,error:m}=d;yn(`/${e}`,l);const p=bn(),[f,b]=y.useState({key:"",page:0}),N=Xt({strict:!1}),x=ie(),E=Vt(),S=`/${e}/${Yt(t)}`,{session:C,isReady:v}=xn(),j=v&&!u&&a?.slug===t,g=C?.user?.email,w=y.useMemo(()=>g?{email:g}:void 0,[g]),{collection:k,error:L,presentation:M,presets:Z,preset:$,edited:le,table:T}=y.useMemo(()=>ya(N,a?.metadata_schema,!!n,w),[N,a?.metadata_schema,n,w]),z=j?L:void 0,G=y.useMemo(()=>ja(N,k),[N,k]),[ms,Ke]=y.useState(!1),[Re,ps]=y.useState(0),Le=k.search??"",K=k.segment,fs=JSON.stringify(k),se=K?ur(a).find(h=>h.name===K)??{name:K,description:""}:null,hs=h=>void x({...re,search:_=>({...Je(_,X(h)),...G}),replace:!0}),J=vn(d.data),et=J?T.sort:Ca(T),Oe=et?.field,tt=et?.order,W=y.useMemo(()=>Oe?[{id:Oe,desc:tt==="desc"}]:[],[Oe,tt]),ce=y.useCallback(h=>void x({...re,search:{...n?X(N):{},...G,$table:JSON.stringify(h)},replace:!0}),[x,n,N,G]),st=y.useCallback(h=>{const _=typeof h=="function"?h(W):h;_[0]&&ce({...T,sort:{field:_[0].id,order:_[0].desc?"desc":"asc"}})},[W,ce,T]),de=o===!0,nt=()=>i(!0),gs=()=>i(!1),ys=W[0]?.id,bs=W[0]?W[0].desc?"desc":"asc":void 0,Me=d.data?.metadata_schema,ue=!!Ze(Me)&&!J,xs=Ua(Me,{isDerived:J}),F=Zt(l),vs=qe(F.data??[],t,k),ne=(h,_=!1,I=X(N))=>{const A=!n||!F.data||qe(F.data,t,h).some(ye=>ye.key===n);x({to:A?".":S,search:{...A&&n?I:{},...ba(h,$?.key),$table:JSON.stringify(T)},replace:_})},me=h=>{const _=h?Se(h,void 0,w):{},I=!n||qe(F.data??[],t,_).some(A=>A.key===n);Ke(!1),ps(A=>A+1),x({to:I?".":S,search:h?{$preset:h.key}:{}})},{isAdmin:Ss}=Sn(l.organizationId),Ae=jn(l),js=Ss&&!!a&&!d.isPlaceholderData,at=y.useRef(N);at.current=N;const Ns=async()=>{if(!$)return;const h=JSON.stringify(N),{data:_}=await d.refetch(),I=_?.metadata_schema,A=I?Xe(I[ze]??{}):void 0,ye=A?.presets?.find(be=>be.key===$.key);if(!_||!I||!A||!ye){It.error("This saved filter changed. Reload and try again.");return}const Ve=xa(ye,k,T,A,void 0,w);await Ae.mutateAsync({slug:_.slug,metadata_schema:{...I,[ze]:{...A,presets:A.presets?.map(be=>be.key===Ve.key?Ve:be)}}}).then(()=>!0,()=>!1)&&(await d.refetch(),JSON.stringify(at.current)===h&&me(Ve))},Cs=y.useMemo(()=>pr(e,t),[e,t]),D=Nn(F.data??[],t,{viewKey:n,shape:c??(n?void 0:Cs)},xs,k),V=D.kind==="builtin"?D.mode==="board"&&!ue?"table":D.mode:null,rt=V==="graph";y.useEffect(()=>{c&&j&&V&&fr(e,t,V)},[c,j,V,e,t]);const ot=["table",...ue?["board"]:[],"graph"],Y=D.kind==="view"?D.view:null,it=D.kind==="missing"?D.key:null,Te=D.kind==="inapplicable"?D:null,ae=V==="table"?50:200,pe=`${t}?${fs}&sort=${JSON.stringify(T.sort)}&size=${ae}`,fe=f.key===pe?f.page:0,Ie=y.useCallback(h=>b(_=>({key:pe,page:h(_.key===pe?_.page:0)})),[pe]),he=kt(t,l,{limit:ae,offset:fe*ae,search:Le.trim()||void 0,sortBy:ys,sortOrder:bs,segment:K,filters:k.filters,enabled:j&&!n&&!z}),lt=kt(t,l,{limit:1,offset:0,parentId:null,search:Le.trim()||void 0,segment:K,filters:k.filters,enabled:j&&!n&&!z&&!J}),{data:ge,error:Es}=he,ws=he.isLoading||he.isPending&&he.fetchStatus==="paused",ct=z||m||(n?null:Es),ks=!!n&&F.data===void 0&&F.isError,B=ge?.entities??[],Fe=ge?.metadata?.has_more??!1,P=ge?.metadata?.total_count??0,dt=B.length>0||Le.trim().length>0||fe>0||!!K||!!k.filters?.length,O=a?.name?.trim()||He(t),ee=a?.icon||void 0,q=J,U=Me,_s=!z&&(!r||!j||(n?F.data===void 0&&!F.isError:ws||!J&&lt.isLoading)),ut=ge?.linked_entities??{},mt=lt.data?.metadata?.total_count,pt=P>0&&typeof mt=="number"?mt<P:!1,ft=y.useMemo(()=>a?.measure_columns??[],[a?.measure_columns]),ht=y.useCallback(h=>ce({...T,columns:h}),[ce,T]),gt=y.useMemo(()=>({entities:B,owner:e,schema:U,entityTypeIcon:ee,isDerived:q,measureColumns:ft,linkedEntityLookups:ut,hasAnyParents:pt,sorting:W,onSortingChange:st,visibleColumns:T.columns,columnChoices:Hn(U,q,B),onVisibleColumnsChange:ht,page:fe,pageSize:ae,totalCount:P,hasMore:Fe,pageTitle:O,onPrevPage:()=>Ie(h=>Math.max(0,h-1)),onNextPage:()=>Ie(h=>h+1)}),[B,e,U,ee,q,ft,ut,pt,W,T.columns,ht,st,Ie,fe,ae,P,Fe,O]),yt=P>B.length,bt=`showing first ${B.length} of ${P} — narrow with search`,xt=y.useMemo(()=>({owner:e,entityType:a,entities:B,totalCount:P,schema:U,entityTypeIcon:ee}),[e,a,B,P,U,ee]),Pe=y.useMemo(()=>({tableState:gt,boardState:xt,owner:e,schema:U,entityType:a,entityTypeIcon:ee,totalCount:P,isTruncated:yt,truncationNotice:bt,canCreate:!q,addLabel:`Add ${a?.name||He(t)}`}),[gt,xt,e,U,a,ee,P,yt,bt,q,t]),$s=y.useMemo(()=>Ga({canShowBoard:ue,builtinData:Pe,builtInLabels:{table:xe.table.label,board:xe.board.label}}),[ue,Pe]),vt=V?$s.find(h=>h.id===V)??null:null,Rs=vt?.template??is,Ls=vt?.data??Pe,St=h=>void x({to:h===At?S:`${S}${On(h)}`,search:G}),De=X(N),Os=la(Y?.params,De,h=>void x({...re,search:{...X(h),...G}})),Ms=()=>ne({...k,filters:[],segment:void 0},!1,ca(Y?.params,De)),jt={collection:k,schema:U,label:O,org:l??"",facetQuery:M.facetQuery,onChange:ne,viewFilters:Os,onClearAll:Ms,segmentChip:se?{id:"segment",label:"Segment",op:"is",value:He(se.name),title:se.description||void 0,editor:se.description?{kind:"custom",render:()=>s.jsx("p",{className:"p-3 text-sm text-muted-foreground",children:se.description})}:void 0,onRemove:()=>ne({...k,segment:void 0})}:void 0},Nt=`Moved on ${a?.name||a?.slug||t} board`,Ct=y.useMemo(()=>(h,_)=>p.mutateAsync({entityId:h,metadata:_,field_note:Nt}),[p,Nt]),As=y.useMemo(()=>({updateEntity:Ct,openCreate:()=>i(!0)}),[Ct,i]),Et=h=>E?s.jsx("span",{className:h,children:s.jsx(R,{type:"button",variant:"ghost",size:"icon",className:"size-8 shrink-0 text-muted-foreground hover:text-foreground","aria-label":"Edit type",title:"Edit type",onClick:()=>E.open({href:Ln(e,t),title:O}),children:s.jsx(Rn,{className:"h-4 w-4"})})}):null;return s.jsx(Un,{title:s.jsx(dr,{ownerSlug:e,typeSlug:t,title:O,shape:n?null:V}),actions:Et("hidden @sm:contents"),controls:s.jsxs(s.Fragment,{children:[de?s.jsx("div",{className:"max-w-3xl",children:s.jsx(ma,{onClose:gs,entityTypeSlug:t,orgContext:l})}):null,!de&&j&&s.jsxs("nav",{className:"mb-4 flex flex-wrap items-center gap-x-3 gap-y-2","aria-label":`${O} views`,children:[Et("-mr-1 @sm:hidden"),!n&&ot.length>1&&s.jsx("fieldset",{className:"flex items-center rounded-md border p-0.5","aria-label":"Record layout",children:ot.map(h=>{const _=xe[h].icon,I=V===h;return s.jsx(R,{type:"button",variant:"ghost",size:"sm","aria-pressed":I,title:xe[h].label,"data-testid":`shape-${h}`,className:Ne("h-7 px-2",I&&"bg-accent text-accent-foreground"),onClick:()=>void x({to:`${S}/${Qt}/${h}`,search:G,replace:!0}),children:s.jsx(_,{className:"h-4 w-4"})},h)})}),n&&s.jsx(R,{variant:"ghost",onClick:()=>St(At),children:"Records"}),!!Z.length&&s.jsxs(Ut,{open:ms,onOpenChange:Ke,children:[s.jsx(zt,{asChild:!0,children:s.jsxs(R,{variant:"outline",className:Ne("gap-2",le&&"border-dashed border-primary"),"data-edited":le||void 0,title:"Choose saved filter",children:[$?.label??(k.filters?.length||k.search?"Custom filter":"All records"),le?s.jsx("span",{className:"text-xs font-normal text-primary",children:"Edited"}):null,s.jsx(Gt,{className:"h-4 w-4 text-muted-foreground"})]})}),s.jsxs(Jt,{align:"start",className:"w-60 p-1",children:[s.jsx(R,{variant:$?"ghost":"secondary",className:"w-full justify-start",onClick:()=>me(),children:"All records"}),Z.map(h=>s.jsx(R,{variant:$?.key===h.key?"secondary":"ghost",className:"w-full justify-start",onClick:()=>me(h),children:h.label},h.key))]})]}),$&&le?s.jsxs("div",{className:"-ml-2 mr-2 inline-flex items-center gap-1",children:[s.jsx(R,{variant:"ghost",size:"sm",onClick:()=>me($),children:"Reset"}),js?s.jsx(R,{size:"sm",disabled:Ae.isPending,onClick:()=>void Ns(),children:Ae.isPending?"Saving…":"Save"}):null]}):null,vs.map(h=>s.jsx(R,{"data-testid":`tab-${h.key}`,variant:n===h.key?"secondary":"ghost","aria-pressed":n===h.key,onClick:()=>St(h.key),children:h.name},h.key)),!z&&s.jsx($a,{...jt},`filters:${t}:${Re}`),s.jsxs("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-x-3 gap-y-2",children:[s.jsx(ka,{label:O,search:k.search,onSearch:(h,_)=>ne({...k,search:h},_),className:"w-64 max-w-full"},`search:${t}:${Re}`),!q&&!n?s.jsxs(R,{size:"sm","aria-label":`Add ${O||"entity"}`,onClick:()=>nt(),children:[s.jsx(kn,{className:"mr-2 h-4 w-4"}),"Add"]}):null]})]}),!de&&j&&!z?s.jsx(Ra,{...jt},`applied:${t}:${Re}`):null]}),children:de?null:_s?rt?s.jsx(es,{label:`Loading ${O} graph`}):s.jsx(zn,{}):ct?s.jsxs("div",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-6 text-sm text-destructive",children:[ct.message||`Failed to load ${O.toLowerCase()}.`,z&&s.jsx(R,{variant:"outline",size:"sm",className:"ml-3",onClick:()=>ne({}),children:"Clear filters"})]}):ks?s.jsx(We,{onRetry:()=>void F.refetch()}):Te?s.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center","data-testid":"inapplicable-view",children:[s.jsxs("h2",{className:"text-lg font-semibold",children:["“",Te.view.name,"” doesn’t apply to the current filters"]}),s.jsxs("p",{className:"text-muted-foreground mt-2 text-sm",children:["It appears when the selection includes"," ",Object.entries(Te.when).map(([h,_])=>`${h} is ${_===null?"not supplied":String(_)}`).join(" and "),"."]}),s.jsx(_e,{to:S,search:G,className:"mt-4 text-sm font-medium underline underline-offset-4",children:`Back to ${O}`})]}):it?s.jsx(ns,{viewKey:it,backTo:S,backLabel:`Back to ${O}`}):Y?s.jsx(as,{orgSlug:e,viewKey:Y.key,scope:{type:t,collection:k},params:De,onParamsChange:hs,paramDecls:Y.params,contentHash:Y.content_hash,title:Y.name,minHeight:320}):rt&&dt?s.jsx(Ba,{ownerSlug:e,typeSlug:t,sourceBacked:J,records:B.map(h=>({...h,id:h.id??JSON.stringify([h.entity_type,h.slug])})),hasMore:Fe}):dt?s.jsx(ta,{template:Rs,data:Ls,actions:As,components:cr}):s.jsx(Bt,{icon:Cn,iconElement:s.jsx(Wt,{icon:a?.icon,className:"mb-4 h-12 w-12 opacity-50"}),title:`No ${O.toLowerCase()} yet`,description:q?"This view has no rows yet. They appear as the underlying data arrives.":`Get started by creating your first ${a?.name?.toLowerCase()||"entity"}.`,actionLabel:q?void 0:`Add ${a?.name||"Entity"}`,onAction:q?void 0:()=>nt()})})}function gr({ownerSlug:e,typeScope:t,create:o,viewKey:i,shape:n}){const c=ie(),l=Xt({strict:!1}),r=t?Mn(t):void 0,d=r==="$member",a=m=>{if(!r)return;const p=Tn(e,r);c({to:p.to,params:p.params,search:m?{create:!0}:{},replace:!0})},u=r?s.jsx(hr,{ownerSlug:e,entityTypeSlug:r,create:o,onCreateChange:a,viewKey:i,shape:n}):i?s.jsx(yr,{ownerSlug:e,viewKey:i,search:l}):null;return s.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4",children:d?s.jsx(ua,{children:u}):u})}function yr({ownerSlug:e,viewKey:t,search:o}){const i=ie(),{orgContext:n}=ke(),{data:c,isError:l,error:r,refetch:d}=Zt(n),a=An(c??[],t);return c===void 0?l?s.jsx(We,{error:r,onRetry:()=>void d()}):null:a.kind==="missing"?s.jsx(ns,{viewKey:a.key,backTo:`/${e}`,backLabel:"Back to Home"}):s.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col gap-4",children:[l?s.jsx(We,{error:r,onRetry:()=>void d()}):null,s.jsx(da,{decls:a.view.params,params:X(o),onParamsChange:u=>void i({...re,search:m=>Je(m,u)})}),s.jsx(as,{orgSlug:e,viewKey:a.view.key,scope:{},params:X(o),onParamsChange:u=>void i({...re,search:m=>Je(m,u),replace:!0}),paramDecls:a.view.params,contentHash:a.view.content_hash,title:a.view.name,minHeight:400})]})}function Rr({ownerSlug:e,typeScope:t,create:o,viewKey:i,shape:n}){return s.jsxs(In,{inset:i?"flush":"page",className:i?"gap-0 pt-0 pb-0":"gap-6 pt-2.5 pb-8",children:[s.jsx(Pn,{}),s.jsx(Fn,{owner:e,children:c=>s.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:s.jsx(gr,{ownerSlug:c.ownerSlug,typeScope:t,create:o,viewKey:i,shape:n})})})]})}export{Rr as M};
74
+ //# sourceMappingURL=memory-browse-page-qEDQ9Z18.js.map
@@ -0,0 +1,2 @@
1
+ import{eA as h,eB as mn,c as Ht,r as w,j as S,ac as yn,eC as gn,w as vn,z as St,eD as _n,dm as xn,eE as bn,eF as kn,dl as wn,eG as Sn,dL as En,K as Tn,u as On,H as Cn,af as Oe,a4 as Ce,eH as Nn,eI as Rn,p as In,eJ as jn,i as An,eK as $n,eL as Zn,L as Mn}from"./index-BoqrvLHQ.js";import{D as Ln,E as Vn}from"./app-bridge-B-L0rGz9.js";import{l as Pn}from"./renderer-CTKNMcXP.js";var x;(function(n){n.assertEqual=s=>{};function e(s){}n.assertIs=e;function t(s){throw new Error}n.assertNever=t,n.arrayToEnum=s=>{const a={};for(const i of s)a[i]=i;return a},n.getValidEnumValues=s=>{const a=n.objectKeys(s).filter(o=>typeof s[s[o]]!="number"),i={};for(const o of a)i[o]=s[o];return n.objectValues(i)},n.objectValues=s=>n.objectKeys(s).map(function(a){return s[a]}),n.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const a=[];for(const i in s)Object.prototype.hasOwnProperty.call(s,i)&&a.push(i);return a},n.find=(s,a)=>{for(const i of s)if(a(i))return i},n.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function r(s,a=" | "){return s.map(i=>typeof i=="string"?`'${i}'`:i).join(a)}n.joinValues=r,n.jsonStringifyReplacer=(s,a)=>typeof a=="bigint"?a.toString():a})(x||(x={}));var Et;(function(n){n.mergeShapes=(e,t)=>({...e,...t})})(Et||(Et={}));const f=x.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Y=n=>{switch(typeof n){case"undefined":return f.undefined;case"string":return f.string;case"number":return Number.isNaN(n)?f.nan:f.number;case"boolean":return f.boolean;case"function":return f.function;case"bigint":return f.bigint;case"symbol":return f.symbol;case"object":return Array.isArray(n)?f.array:n===null?f.null:n.then&&typeof n.then=="function"&&n.catch&&typeof n.catch=="function"?f.promise:typeof Map<"u"&&n instanceof Map?f.map:typeof Set<"u"&&n instanceof Set?f.set:typeof Date<"u"&&n instanceof Date?f.date:f.object;default:return f.unknown}},d=x.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class J extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(a){return a.message},r={_errors:[]},s=a=>{for(const i of a.issues)if(i.code==="invalid_union")i.unionErrors.map(s);else if(i.code==="invalid_return_type")s(i.returnTypeError);else if(i.code==="invalid_arguments")s(i.argumentsError);else if(i.path.length===0)r._errors.push(t(i));else{let o=r,u=0;for(;u<i.path.length;){const c=i.path[u];u===i.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(t(i))):o[c]=o[c]||{_errors:[]},o=o[c],u++}}};return s(this),r}static assert(e){if(!(e instanceof J))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,x.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},r=[];for(const s of this.issues)if(s.path.length>0){const a=s.path[0];t[a]=t[a]||[],t[a].push(e(s))}else r.push(e(s));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}J.create=n=>new J(n);const tt=(n,e)=>{let t;switch(n.code){case d.invalid_type:n.received===f.undefined?t="Required":t=`Expected ${n.expected}, received ${n.received}`;break;case d.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(n.expected,x.jsonStringifyReplacer)}`;break;case d.unrecognized_keys:t=`Unrecognized key(s) in object: ${x.joinValues(n.keys,", ")}`;break;case d.invalid_union:t="Invalid input";break;case d.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${x.joinValues(n.options)}`;break;case d.invalid_enum_value:t=`Invalid enum value. Expected ${x.joinValues(n.options)}, received '${n.received}'`;break;case d.invalid_arguments:t="Invalid function arguments";break;case d.invalid_return_type:t="Invalid function return type";break;case d.invalid_date:t="Invalid date";break;case d.invalid_string:typeof n.validation=="object"?"includes"in n.validation?(t=`Invalid input: must include "${n.validation.includes}"`,typeof n.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${n.validation.position}`)):"startsWith"in n.validation?t=`Invalid input: must start with "${n.validation.startsWith}"`:"endsWith"in n.validation?t=`Invalid input: must end with "${n.validation.endsWith}"`:x.assertNever(n.validation):n.validation!=="regex"?t=`Invalid ${n.validation}`:t="Invalid";break;case d.too_small:n.type==="array"?t=`Array must contain ${n.exact?"exactly":n.inclusive?"at least":"more than"} ${n.minimum} element(s)`:n.type==="string"?t=`String must contain ${n.exact?"exactly":n.inclusive?"at least":"over"} ${n.minimum} character(s)`:n.type==="number"?t=`Number must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${n.minimum}`:n.type==="bigint"?t=`Number must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${n.minimum}`:n.type==="date"?t=`Date must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(n.minimum))}`:t="Invalid input";break;case d.too_big:n.type==="array"?t=`Array must contain ${n.exact?"exactly":n.inclusive?"at most":"less than"} ${n.maximum} element(s)`:n.type==="string"?t=`String must contain ${n.exact?"exactly":n.inclusive?"at most":"under"} ${n.maximum} character(s)`:n.type==="number"?t=`Number must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="bigint"?t=`BigInt must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="date"?t=`Date must be ${n.exact?"exactly":n.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(n.maximum))}`:t="Invalid input";break;case d.custom:t="Invalid input";break;case d.invalid_intersection_types:t="Intersection results could not be merged";break;case d.not_multiple_of:t=`Number must be a multiple of ${n.multipleOf}`;break;case d.not_finite:t="Number must be finite";break;default:t=e.defaultError,x.assertNever(n)}return{message:t}};let Dn=tt;function zn(){return Dn}const Un=n=>{const{data:e,path:t,errorMaps:r,issueData:s}=n,a=[...t,...s.path||[]],i={...s,path:a};if(s.message!==void 0)return{...s,path:a,message:s.message};let o="";const u=r.filter(c=>!!c).slice().reverse();for(const c of u)o=c(i,{data:e,defaultError:o}).message;return{...s,path:a,message:o}};function l(n,e){const t=zn(),r=Un({issueData:e,data:n.data,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,t,t===tt?void 0:tt].filter(s=>!!s)});n.common.issues.push(r)}class A{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const r=[];for(const s of t){if(s.status==="aborted")return y;s.status==="dirty"&&e.dirty(),r.push(s.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){const r=[];for(const s of t){const a=await s.key,i=await s.value;r.push({key:a,value:i})}return A.mergeObjectSync(e,r)}static mergeObjectSync(e,t){const r={};for(const s of t){const{key:a,value:i}=s;if(a.status==="aborted"||i.status==="aborted")return y;a.status==="dirty"&&e.dirty(),i.status==="dirty"&&e.dirty(),a.value!=="__proto__"&&(typeof i.value<"u"||s.alwaysSet)&&(r[a.value]=i.value)}return{status:e.value,value:r}}}const y=Object.freeze({status:"aborted"}),Ee=n=>({status:"dirty",value:n}),V=n=>({status:"valid",value:n}),Tt=n=>n.status==="aborted",Ot=n=>n.status==="dirty",me=n=>n.status==="valid",Ve=n=>typeof Promise<"u"&&n instanceof Promise;var p;(function(n){n.errToObj=e=>typeof e=="string"?{message:e}:e||{},n.toString=e=>typeof e=="string"?e:e?.message})(p||(p={}));class W{constructor(e,t,r,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=s}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Ct=(n,e)=>{if(me(e))return{success:!0,data:e.value};if(!n.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new J(n.common.issues);return this._error=t,this._error}}};function v(n){if(!n)return{};const{errorMap:e,invalid_type_error:t,required_error:r,description:s}=n;if(e&&(t||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(i,o)=>{const{message:u}=n;return i.code==="invalid_enum_value"?{message:u??o.defaultError}:typeof o.data>"u"?{message:u??r??o.defaultError}:i.code!=="invalid_type"?{message:o.defaultError}:{message:u??t??o.defaultError}},description:s}}class _{get description(){return this._def.description}_getType(e){return Y(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:Y(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new A,ctx:{common:e.parent.common,data:e.data,parsedType:Y(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(Ve(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){const r={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Y(e)},s=this._parseSync({data:e,path:r.path,parent:r});return Ct(r,s)}"~validate"(e){const t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Y(e)};if(!this["~standard"].async)try{const r=this._parseSync({data:e,path:[],parent:t});return me(r)?{value:r.value}:{issues:t.common.issues}}catch(r){r?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then(r=>me(r)?{value:r.value}:{issues:t.common.issues})}async parseAsync(e,t){const r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){const r={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Y(e)},s=this._parse({data:e,path:r.path,parent:r}),a=await(Ve(s)?s:Promise.resolve(s));return Ct(r,a)}refine(e,t){const r=s=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(s):t;return this._refinement((s,a)=>{const i=e(s),o=()=>a.addIssue({code:d.custom,...r(s)});return typeof Promise<"u"&&i instanceof Promise?i.then(u=>u?!0:(o(),!1)):i?!0:(o(),!1)})}refinement(e,t){return this._refinement((r,s)=>e(r)?!0:(s.addIssue(typeof t=="function"?t(r,s):t),!1))}_refinement(e){return new ve({schema:this,typeName:g.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:t=>this["~validate"](t)}}optional(){return Q.create(this,this._def)}nullable(){return _e.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return B.create(this)}promise(){return Fe.create(this,this._def)}or(e){return De.create([this,e],this._def)}and(e){return ze.create(this,e,this._def)}transform(e){return new ve({...v(this._def),schema:this,typeName:g.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new it({...v(this._def),innerType:this,defaultValue:t,typeName:g.ZodDefault})}brand(){return new lr({typeName:g.ZodBranded,type:this,...v(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new ot({...v(this._def),innerType:this,catchValue:t,typeName:g.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return dt.create(this,e)}readonly(){return ct.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Fn=/^c[^\s-]{8,}$/i,Bn=/^[0-9a-z]+$/,qn=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Wn=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,Hn=/^[a-z0-9_-]{21}$/i,Jn=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Xn=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,Kn=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Yn="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let Ke;const Gn=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Qn=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,er=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,tr=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,nr=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,rr=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Jt="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",sr=new RegExp(`^${Jt}$`);function Xt(n){let e="[0-5]\\d";n.precision?e=`${e}\\.\\d{${n.precision}}`:n.precision==null&&(e=`${e}(\\.\\d+)?`);const t=n.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${e})${t}`}function ar(n){return new RegExp(`^${Xt(n)}$`)}function ir(n){let e=`${Jt}T${Xt(n)}`;const t=[];return t.push(n.local?"Z?":"Z"),n.offset&&t.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${t.join("|")})`,new RegExp(`^${e}$`)}function or(n,e){return!!((e==="v4"||!e)&&Gn.test(n)||(e==="v6"||!e)&&er.test(n))}function cr(n,e){if(!Jn.test(n))return!1;try{const[t]=n.split(".");if(!t)return!1;const r=t.replace(/-/g,"+").replace(/_/g,"/").padEnd(t.length+(4-t.length%4)%4,"="),s=JSON.parse(atob(r));return!(typeof s!="object"||s===null||"typ"in s&&s?.typ!=="JWT"||!s.alg||e&&s.alg!==e)}catch{return!1}}function dr(n,e){return!!((e==="v4"||!e)&&Qn.test(n)||(e==="v6"||!e)&&tr.test(n))}class H extends _{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==f.string){const a=this._getOrReturnCtx(e);return l(a,{code:d.invalid_type,expected:f.string,received:a.parsedType}),y}const r=new A;let s;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(s=this._getOrReturnCtx(e,s),l(s,{code:d.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),r.dirty());else if(a.kind==="max")e.data.length>a.value&&(s=this._getOrReturnCtx(e,s),l(s,{code:d.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),r.dirty());else if(a.kind==="length"){const i=e.data.length>a.value,o=e.data.length<a.value;(i||o)&&(s=this._getOrReturnCtx(e,s),i?l(s,{code:d.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):o&&l(s,{code:d.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),r.dirty())}else if(a.kind==="email")Kn.test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"email",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="emoji")Ke||(Ke=new RegExp(Yn,"u")),Ke.test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"emoji",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="uuid")Wn.test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"uuid",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="nanoid")Hn.test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"nanoid",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="cuid")Fn.test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"cuid",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="cuid2")Bn.test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"cuid2",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="ulid")qn.test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"ulid",code:d.invalid_string,message:a.message}),r.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),l(s,{validation:"url",code:d.invalid_string,message:a.message}),r.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"regex",code:d.invalid_string,message:a.message}),r.dirty())):a.kind==="trim"?e.data=e.data.trim():a.kind==="includes"?e.data.includes(a.value,a.position)||(s=this._getOrReturnCtx(e,s),l(s,{code:d.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),r.dirty()):a.kind==="toLowerCase"?e.data=e.data.toLowerCase():a.kind==="toUpperCase"?e.data=e.data.toUpperCase():a.kind==="startsWith"?e.data.startsWith(a.value)||(s=this._getOrReturnCtx(e,s),l(s,{code:d.invalid_string,validation:{startsWith:a.value},message:a.message}),r.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(s=this._getOrReturnCtx(e,s),l(s,{code:d.invalid_string,validation:{endsWith:a.value},message:a.message}),r.dirty()):a.kind==="datetime"?ir(a).test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{code:d.invalid_string,validation:"datetime",message:a.message}),r.dirty()):a.kind==="date"?sr.test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{code:d.invalid_string,validation:"date",message:a.message}),r.dirty()):a.kind==="time"?ar(a).test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{code:d.invalid_string,validation:"time",message:a.message}),r.dirty()):a.kind==="duration"?Xn.test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"duration",code:d.invalid_string,message:a.message}),r.dirty()):a.kind==="ip"?or(e.data,a.version)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"ip",code:d.invalid_string,message:a.message}),r.dirty()):a.kind==="jwt"?cr(e.data,a.alg)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"jwt",code:d.invalid_string,message:a.message}),r.dirty()):a.kind==="cidr"?dr(e.data,a.version)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"cidr",code:d.invalid_string,message:a.message}),r.dirty()):a.kind==="base64"?nr.test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"base64",code:d.invalid_string,message:a.message}),r.dirty()):a.kind==="base64url"?rr.test(e.data)||(s=this._getOrReturnCtx(e,s),l(s,{validation:"base64url",code:d.invalid_string,message:a.message}),r.dirty()):x.assertNever(a);return{status:r.value,value:e.data}}_regex(e,t,r){return this.refinement(s=>e.test(s),{validation:t,code:d.invalid_string,...p.errToObj(r)})}_addCheck(e){return new H({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...p.errToObj(e)})}url(e){return this._addCheck({kind:"url",...p.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...p.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...p.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...p.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...p.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...p.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...p.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...p.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...p.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...p.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...p.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...p.errToObj(e)})}datetime(e){return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...p.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...p.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...p.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...p.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...p.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...p.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...p.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...p.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...p.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...p.errToObj(t)})}nonempty(e){return this.min(1,p.errToObj(e))}trim(){return new H({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new H({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new H({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isCIDR(){return!!this._def.checks.find(e=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find(e=>e.kind==="base64url")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}H.create=n=>new H({checks:[],typeName:g.ZodString,coerce:n?.coerce??!1,...v(n)});function ur(n,e){const t=(n.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,s=t>r?t:r,a=Number.parseInt(n.toFixed(s).replace(".","")),i=Number.parseInt(e.toFixed(s).replace(".",""));return a%i/10**s}class ye extends _{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==f.number){const a=this._getOrReturnCtx(e);return l(a,{code:d.invalid_type,expected:f.number,received:a.parsedType}),y}let r;const s=new A;for(const a of this._def.checks)a.kind==="int"?x.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:d.invalid_type,expected:"integer",received:"float",message:a.message}),s.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:d.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:d.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty()):a.kind==="multipleOf"?ur(e.data,a.value)!==0&&(r=this._getOrReturnCtx(e,r),l(r,{code:d.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),l(r,{code:d.not_finite,message:a.message}),s.dirty()):x.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,p.toString(t))}gt(e,t){return this.setLimit("min",e,!1,p.toString(t))}lte(e,t){return this.setLimit("max",e,!0,p.toString(t))}lt(e,t){return this.setLimit("max",e,!1,p.toString(t))}setLimit(e,t,r,s){return new ye({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:p.toString(s)}]})}_addCheck(e){return new ye({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:p.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:p.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:p.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:p.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:p.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:p.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:p.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:p.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:p.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&x.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(t===null||r.value>t)&&(t=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(t)&&Number.isFinite(e)}}ye.create=n=>new ye({checks:[],typeName:g.ZodNumber,coerce:n?.coerce||!1,...v(n)});class Ne extends _{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==f.bigint)return this._getInvalidInput(e);let r;const s=new A;for(const a of this._def.checks)a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:d.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(r=this._getOrReturnCtx(e,r),l(r,{code:d.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty()):a.kind==="multipleOf"?e.data%a.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),l(r,{code:d.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):x.assertNever(a);return{status:s.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return l(t,{code:d.invalid_type,expected:f.bigint,received:t.parsedType}),y}gte(e,t){return this.setLimit("min",e,!0,p.toString(t))}gt(e,t){return this.setLimit("min",e,!1,p.toString(t))}lte(e,t){return this.setLimit("max",e,!0,p.toString(t))}lt(e,t){return this.setLimit("max",e,!1,p.toString(t))}setLimit(e,t,r,s){return new Ne({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:p.toString(s)}]})}_addCheck(e){return new Ne({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:p.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:p.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:p.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:p.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:p.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}Ne.create=n=>new Ne({checks:[],typeName:g.ZodBigInt,coerce:n?.coerce??!1,...v(n)});class nt extends _{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==f.boolean){const r=this._getOrReturnCtx(e);return l(r,{code:d.invalid_type,expected:f.boolean,received:r.parsedType}),y}return V(e.data)}}nt.create=n=>new nt({typeName:g.ZodBoolean,coerce:n?.coerce||!1,...v(n)});class Pe extends _{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==f.date){const a=this._getOrReturnCtx(e);return l(a,{code:d.invalid_type,expected:f.date,received:a.parsedType}),y}if(Number.isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return l(a,{code:d.invalid_date}),y}const r=new A;let s;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(s=this._getOrReturnCtx(e,s),l(s,{code:d.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),r.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(s=this._getOrReturnCtx(e,s),l(s,{code:d.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),r.dirty()):x.assertNever(a);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new Pe({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:p.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:p.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}Pe.create=n=>new Pe({checks:[],coerce:n?.coerce||!1,typeName:g.ZodDate,...v(n)});class Nt extends _{_parse(e){if(this._getType(e)!==f.symbol){const r=this._getOrReturnCtx(e);return l(r,{code:d.invalid_type,expected:f.symbol,received:r.parsedType}),y}return V(e.data)}}Nt.create=n=>new Nt({typeName:g.ZodSymbol,...v(n)});class Rt extends _{_parse(e){if(this._getType(e)!==f.undefined){const r=this._getOrReturnCtx(e);return l(r,{code:d.invalid_type,expected:f.undefined,received:r.parsedType}),y}return V(e.data)}}Rt.create=n=>new Rt({typeName:g.ZodUndefined,...v(n)});class It extends _{_parse(e){if(this._getType(e)!==f.null){const r=this._getOrReturnCtx(e);return l(r,{code:d.invalid_type,expected:f.null,received:r.parsedType}),y}return V(e.data)}}It.create=n=>new It({typeName:g.ZodNull,...v(n)});class jt extends _{constructor(){super(...arguments),this._any=!0}_parse(e){return V(e.data)}}jt.create=n=>new jt({typeName:g.ZodAny,...v(n)});class rt extends _{constructor(){super(...arguments),this._unknown=!0}_parse(e){return V(e.data)}}rt.create=n=>new rt({typeName:g.ZodUnknown,...v(n)});class ee extends _{_parse(e){const t=this._getOrReturnCtx(e);return l(t,{code:d.invalid_type,expected:f.never,received:t.parsedType}),y}}ee.create=n=>new ee({typeName:g.ZodNever,...v(n)});class At extends _{_parse(e){if(this._getType(e)!==f.undefined){const r=this._getOrReturnCtx(e);return l(r,{code:d.invalid_type,expected:f.void,received:r.parsedType}),y}return V(e.data)}}At.create=n=>new At({typeName:g.ZodVoid,...v(n)});class B extends _{_parse(e){const{ctx:t,status:r}=this._processInputParams(e),s=this._def;if(t.parsedType!==f.array)return l(t,{code:d.invalid_type,expected:f.array,received:t.parsedType}),y;if(s.exactLength!==null){const i=t.data.length>s.exactLength.value,o=t.data.length<s.exactLength.value;(i||o)&&(l(t,{code:i?d.too_big:d.too_small,minimum:o?s.exactLength.value:void 0,maximum:i?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&t.data.length<s.minLength.value&&(l(t,{code:d.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&t.data.length>s.maxLength.value&&(l(t,{code:d.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),t.common.async)return Promise.all([...t.data].map((i,o)=>s.type._parseAsync(new W(t,i,t.path,o)))).then(i=>A.mergeArray(r,i));const a=[...t.data].map((i,o)=>s.type._parseSync(new W(t,i,t.path,o)));return A.mergeArray(r,a)}get element(){return this._def.type}min(e,t){return new B({...this._def,minLength:{value:e,message:p.toString(t)}})}max(e,t){return new B({...this._def,maxLength:{value:e,message:p.toString(t)}})}length(e,t){return new B({...this._def,exactLength:{value:e,message:p.toString(t)}})}nonempty(e){return this.min(1,e)}}B.create=(n,e)=>new B({type:n,minLength:null,maxLength:null,exactLength:null,typeName:g.ZodArray,...v(e)});function he(n){if(n instanceof I){const e={};for(const t in n.shape){const r=n.shape[t];e[t]=Q.create(he(r))}return new I({...n._def,shape:()=>e})}else return n instanceof B?new B({...n._def,type:he(n.element)}):n instanceof Q?Q.create(he(n.unwrap())):n instanceof _e?_e.create(he(n.unwrap())):n instanceof ae?ae.create(n.items.map(e=>he(e))):n}class I extends _{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=x.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==f.object){const c=this._getOrReturnCtx(e);return l(c,{code:d.invalid_type,expected:f.object,received:c.parsedType}),y}const{status:r,ctx:s}=this._processInputParams(e),{shape:a,keys:i}=this._getCached(),o=[];if(!(this._def.catchall instanceof ee&&this._def.unknownKeys==="strip"))for(const c in s.data)i.includes(c)||o.push(c);const u=[];for(const c of i){const m=a[c],N=s.data[c];u.push({key:{status:"valid",value:c},value:m._parse(new W(s,N,s.path,c)),alwaysSet:c in s.data})}if(this._def.catchall instanceof ee){const c=this._def.unknownKeys;if(c==="passthrough")for(const m of o)u.push({key:{status:"valid",value:m},value:{status:"valid",value:s.data[m]}});else if(c==="strict")o.length>0&&(l(s,{code:d.unrecognized_keys,keys:o}),r.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const c=this._def.catchall;for(const m of o){const N=s.data[m];u.push({key:{status:"valid",value:m},value:c._parse(new W(s,N,s.path,m)),alwaysSet:m in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const c=[];for(const m of u){const N=await m.key,j=await m.value;c.push({key:N,value:j,alwaysSet:m.alwaysSet})}return c}).then(c=>A.mergeObjectSync(r,c)):A.mergeObjectSync(r,u)}get shape(){return this._def.shape()}strict(e){return p.errToObj,new I({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,r)=>{const s=this._def.errorMap?.(t,r).message??r.defaultError;return t.code==="unrecognized_keys"?{message:p.errToObj(e).message??s}:{message:s}}}:{}})}strip(){return new I({...this._def,unknownKeys:"strip"})}passthrough(){return new I({...this._def,unknownKeys:"passthrough"})}extend(e){return new I({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new I({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:g.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new I({...this._def,catchall:e})}pick(e){const t={};for(const r of x.objectKeys(e))e[r]&&this.shape[r]&&(t[r]=this.shape[r]);return new I({...this._def,shape:()=>t})}omit(e){const t={};for(const r of x.objectKeys(this.shape))e[r]||(t[r]=this.shape[r]);return new I({...this._def,shape:()=>t})}deepPartial(){return he(this)}partial(e){const t={};for(const r of x.objectKeys(this.shape)){const s=this.shape[r];e&&!e[r]?t[r]=s:t[r]=s.optional()}return new I({...this._def,shape:()=>t})}required(e){const t={};for(const r of x.objectKeys(this.shape))if(e&&!e[r])t[r]=this.shape[r];else{let a=this.shape[r];for(;a instanceof Q;)a=a._def.innerType;t[r]=a}return new I({...this._def,shape:()=>t})}keyof(){return Kt(x.objectKeys(this.shape))}}I.create=(n,e)=>new I({shape:()=>n,unknownKeys:"strip",catchall:ee.create(),typeName:g.ZodObject,...v(e)});I.strictCreate=(n,e)=>new I({shape:()=>n,unknownKeys:"strict",catchall:ee.create(),typeName:g.ZodObject,...v(e)});I.lazycreate=(n,e)=>new I({shape:n,unknownKeys:"strip",catchall:ee.create(),typeName:g.ZodObject,...v(e)});class De extends _{_parse(e){const{ctx:t}=this._processInputParams(e),r=this._def.options;function s(a){for(const o of a)if(o.result.status==="valid")return o.result;for(const o of a)if(o.result.status==="dirty")return t.common.issues.push(...o.ctx.common.issues),o.result;const i=a.map(o=>new J(o.ctx.common.issues));return l(t,{code:d.invalid_union,unionErrors:i}),y}if(t.common.async)return Promise.all(r.map(async a=>{const i={...t,common:{...t.common,issues:[]},parent:null};return{result:await a._parseAsync({data:t.data,path:t.path,parent:i}),ctx:i}})).then(s);{let a;const i=[];for(const u of r){const c={...t,common:{...t.common,issues:[]},parent:null},m=u._parseSync({data:t.data,path:t.path,parent:c});if(m.status==="valid")return m;m.status==="dirty"&&!a&&(a={result:m,ctx:c}),c.common.issues.length&&i.push(c.common.issues)}if(a)return t.common.issues.push(...a.ctx.common.issues),a.result;const o=i.map(u=>new J(u));return l(t,{code:d.invalid_union,unionErrors:o}),y}}get options(){return this._def.options}}De.create=(n,e)=>new De({options:n,typeName:g.ZodUnion,...v(e)});function st(n,e){const t=Y(n),r=Y(e);if(n===e)return{valid:!0,data:n};if(t===f.object&&r===f.object){const s=x.objectKeys(e),a=x.objectKeys(n).filter(o=>s.indexOf(o)!==-1),i={...n,...e};for(const o of a){const u=st(n[o],e[o]);if(!u.valid)return{valid:!1};i[o]=u.data}return{valid:!0,data:i}}else if(t===f.array&&r===f.array){if(n.length!==e.length)return{valid:!1};const s=[];for(let a=0;a<n.length;a++){const i=n[a],o=e[a],u=st(i,o);if(!u.valid)return{valid:!1};s.push(u.data)}return{valid:!0,data:s}}else return t===f.date&&r===f.date&&+n==+e?{valid:!0,data:n}:{valid:!1}}class ze extends _{_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=(a,i)=>{if(Tt(a)||Tt(i))return y;const o=st(a.value,i.value);return o.valid?((Ot(a)||Ot(i))&&t.dirty(),{status:t.value,value:o.data}):(l(r,{code:d.invalid_intersection_types}),y)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([a,i])=>s(a,i)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}ze.create=(n,e,t)=>new ze({left:n,right:e,typeName:g.ZodIntersection,...v(t)});class ae extends _{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==f.array)return l(r,{code:d.invalid_type,expected:f.array,received:r.parsedType}),y;if(r.data.length<this._def.items.length)return l(r,{code:d.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),y;!this._def.rest&&r.data.length>this._def.items.length&&(l(r,{code:d.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const a=[...r.data].map((i,o)=>{const u=this._def.items[o]||this._def.rest;return u?u._parse(new W(r,i,r.path,o)):null}).filter(i=>!!i);return r.common.async?Promise.all(a).then(i=>A.mergeArray(t,i)):A.mergeArray(t,a)}get items(){return this._def.items}rest(e){return new ae({...this._def,rest:e})}}ae.create=(n,e)=>{if(!Array.isArray(n))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ae({items:n,typeName:g.ZodTuple,rest:null,...v(e)})};class Ue extends _{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==f.object)return l(r,{code:d.invalid_type,expected:f.object,received:r.parsedType}),y;const s=[],a=this._def.keyType,i=this._def.valueType;for(const o in r.data)s.push({key:a._parse(new W(r,o,r.path,o)),value:i._parse(new W(r,r.data[o],r.path,o)),alwaysSet:o in r.data});return r.common.async?A.mergeObjectAsync(t,s):A.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,r){return t instanceof _?new Ue({keyType:e,valueType:t,typeName:g.ZodRecord,...v(r)}):new Ue({keyType:H.create(),valueType:e,typeName:g.ZodRecord,...v(t)})}}class $t extends _{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==f.map)return l(r,{code:d.invalid_type,expected:f.map,received:r.parsedType}),y;const s=this._def.keyType,a=this._def.valueType,i=[...r.data.entries()].map(([o,u],c)=>({key:s._parse(new W(r,o,r.path,[c,"key"])),value:a._parse(new W(r,u,r.path,[c,"value"]))}));if(r.common.async){const o=new Map;return Promise.resolve().then(async()=>{for(const u of i){const c=await u.key,m=await u.value;if(c.status==="aborted"||m.status==="aborted")return y;(c.status==="dirty"||m.status==="dirty")&&t.dirty(),o.set(c.value,m.value)}return{status:t.value,value:o}})}else{const o=new Map;for(const u of i){const c=u.key,m=u.value;if(c.status==="aborted"||m.status==="aborted")return y;(c.status==="dirty"||m.status==="dirty")&&t.dirty(),o.set(c.value,m.value)}return{status:t.value,value:o}}}}$t.create=(n,e,t)=>new $t({valueType:e,keyType:n,typeName:g.ZodMap,...v(t)});class Re extends _{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==f.set)return l(r,{code:d.invalid_type,expected:f.set,received:r.parsedType}),y;const s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(l(r,{code:d.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),t.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(l(r,{code:d.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),t.dirty());const a=this._def.valueType;function i(u){const c=new Set;for(const m of u){if(m.status==="aborted")return y;m.status==="dirty"&&t.dirty(),c.add(m.value)}return{status:t.value,value:c}}const o=[...r.data.values()].map((u,c)=>a._parse(new W(r,u,r.path,c)));return r.common.async?Promise.all(o).then(u=>i(u)):i(o)}min(e,t){return new Re({...this._def,minSize:{value:e,message:p.toString(t)}})}max(e,t){return new Re({...this._def,maxSize:{value:e,message:p.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}Re.create=(n,e)=>new Re({valueType:n,minSize:null,maxSize:null,typeName:g.ZodSet,...v(e)});class Zt extends _{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}Zt.create=(n,e)=>new Zt({getter:n,typeName:g.ZodLazy,...v(e)});class at extends _{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return l(t,{received:t.data,code:d.invalid_literal,expected:this._def.value}),y}return{status:"valid",value:e.data}}get value(){return this._def.value}}at.create=(n,e)=>new at({value:n,typeName:g.ZodLiteral,...v(e)});function Kt(n,e){return new ge({values:n,typeName:g.ZodEnum,...v(e)})}class ge extends _{_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),r=this._def.values;return l(t,{expected:x.joinValues(r),received:t.parsedType,code:d.invalid_type}),y}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(e.data)){const t=this._getOrReturnCtx(e),r=this._def.values;return l(t,{received:t.data,code:d.invalid_enum_value,options:r}),y}return V(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return ge.create(e,{...this._def,...t})}exclude(e,t=this._def){return ge.create(this.options.filter(r=>!e.includes(r)),{...this._def,...t})}}ge.create=Kt;class Mt extends _{_parse(e){const t=x.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==f.string&&r.parsedType!==f.number){const s=x.objectValues(t);return l(r,{expected:x.joinValues(s),received:r.parsedType,code:d.invalid_type}),y}if(this._cache||(this._cache=new Set(x.getValidEnumValues(this._def.values))),!this._cache.has(e.data)){const s=x.objectValues(t);return l(r,{received:r.data,code:d.invalid_enum_value,options:s}),y}return V(e.data)}get enum(){return this._def.values}}Mt.create=(n,e)=>new Mt({values:n,typeName:g.ZodNativeEnum,...v(e)});class Fe extends _{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==f.promise&&t.common.async===!1)return l(t,{code:d.invalid_type,expected:f.promise,received:t.parsedType}),y;const r=t.parsedType===f.promise?t.data:Promise.resolve(t.data);return V(r.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}Fe.create=(n,e)=>new Fe({type:n,typeName:g.ZodPromise,...v(e)});class ve extends _{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===g.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=this._def.effect||null,a={addIssue:i=>{l(r,i),i.fatal?t.abort():t.dirty()},get path(){return r.path}};if(a.addIssue=a.addIssue.bind(a),s.type==="preprocess"){const i=s.transform(r.data,a);if(r.common.async)return Promise.resolve(i).then(async o=>{if(t.value==="aborted")return y;const u=await this._def.schema._parseAsync({data:o,path:r.path,parent:r});return u.status==="aborted"?y:u.status==="dirty"||t.value==="dirty"?Ee(u.value):u});{if(t.value==="aborted")return y;const o=this._def.schema._parseSync({data:i,path:r.path,parent:r});return o.status==="aborted"?y:o.status==="dirty"||t.value==="dirty"?Ee(o.value):o}}if(s.type==="refinement"){const i=o=>{const u=s.refinement(o,a);if(r.common.async)return Promise.resolve(u);if(u instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return o};if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return o.status==="aborted"?y:(o.status==="dirty"&&t.dirty(),i(o.value),{status:t.value,value:o.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>o.status==="aborted"?y:(o.status==="dirty"&&t.dirty(),i(o.value).then(()=>({status:t.value,value:o.value}))))}if(s.type==="transform")if(r.common.async===!1){const i=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!me(i))return y;const o=s.transform(i.value,a);if(o instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:o}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(i=>me(i)?Promise.resolve(s.transform(i.value,a)).then(o=>({status:t.value,value:o})):y);x.assertNever(s)}}ve.create=(n,e,t)=>new ve({schema:n,typeName:g.ZodEffects,effect:e,...v(t)});ve.createWithPreprocess=(n,e,t)=>new ve({schema:e,effect:{type:"preprocess",transform:n},typeName:g.ZodEffects,...v(t)});class Q extends _{_parse(e){return this._getType(e)===f.undefined?V(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Q.create=(n,e)=>new Q({innerType:n,typeName:g.ZodOptional,...v(e)});class _e extends _{_parse(e){return this._getType(e)===f.null?V(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}_e.create=(n,e)=>new _e({innerType:n,typeName:g.ZodNullable,...v(e)});class it extends _{_parse(e){const{ctx:t}=this._processInputParams(e);let r=t.data;return t.parsedType===f.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}it.create=(n,e)=>new it({innerType:n,typeName:g.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...v(e)});class ot extends _{_parse(e){const{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Ve(s)?s.then(a=>({status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new J(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new J(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}ot.create=(n,e)=>new ot({innerType:n,typeName:g.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...v(e)});class Lt extends _{_parse(e){if(this._getType(e)!==f.nan){const r=this._getOrReturnCtx(e);return l(r,{code:d.invalid_type,expected:f.nan,received:r.parsedType}),y}return{status:"valid",value:e.data}}}Lt.create=n=>new Lt({typeName:g.ZodNaN,...v(n)});class lr extends _{_parse(e){const{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class dt extends _{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const a=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?y:a.status==="dirty"?(t.dirty(),Ee(a.value)):this._def.out._parseAsync({data:a.value,path:r.path,parent:r})})();{const s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?y:s.status==="dirty"?(t.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(e,t){return new dt({in:e,out:t,typeName:g.ZodPipeline})}}class ct extends _{_parse(e){const t=this._def.innerType._parse(e),r=s=>(me(s)&&(s.value=Object.freeze(s.value)),s);return Ve(t)?t.then(s=>r(s)):r(t)}unwrap(){return this._def.innerType}}ct.create=(n,e)=>new ct({innerType:n,typeName:g.ZodReadonly,...v(e)});var g;(function(n){n.ZodString="ZodString",n.ZodNumber="ZodNumber",n.ZodNaN="ZodNaN",n.ZodBigInt="ZodBigInt",n.ZodBoolean="ZodBoolean",n.ZodDate="ZodDate",n.ZodSymbol="ZodSymbol",n.ZodUndefined="ZodUndefined",n.ZodNull="ZodNull",n.ZodAny="ZodAny",n.ZodUnknown="ZodUnknown",n.ZodNever="ZodNever",n.ZodVoid="ZodVoid",n.ZodArray="ZodArray",n.ZodObject="ZodObject",n.ZodUnion="ZodUnion",n.ZodDiscriminatedUnion="ZodDiscriminatedUnion",n.ZodIntersection="ZodIntersection",n.ZodTuple="ZodTuple",n.ZodRecord="ZodRecord",n.ZodMap="ZodMap",n.ZodSet="ZodSet",n.ZodFunction="ZodFunction",n.ZodLazy="ZodLazy",n.ZodLiteral="ZodLiteral",n.ZodEnum="ZodEnum",n.ZodEffects="ZodEffects",n.ZodNativeEnum="ZodNativeEnum",n.ZodOptional="ZodOptional",n.ZodNullable="ZodNullable",n.ZodDefault="ZodDefault",n.ZodCatch="ZodCatch",n.ZodPromise="ZodPromise",n.ZodBranded="ZodBranded",n.ZodPipeline="ZodPipeline",n.ZodReadonly="ZodReadonly"})(g||(g={}));const G=H.create,Ie=ye.create,fr=nt.create,Yt=rt.create;ee.create;const hr=B.create,q=I.create,Be=De.create;ze.create;ae.create;const pr=Ue.create,ut=at.create,Gt=ge.create;Fe.create;Q.create;_e.create;const Ye=y,mr=h.String({pattern:"^[a-z0-9][a-z0-9-]{0,63}$",minLength:1,maxLength:64,description:"View key, e.g. 'pipeline'."}),yr=h.Object({collection:h.Optional(mn),type:h.Optional(h.String({minLength:1,description:"Entity-type slug the view opens for."})),entity:h.Optional(h.Integer({description:"Entity id the view opens for."})),event:h.Optional(h.Integer({description:"Event id the view opens for. It names the event's supersede lineage, so the view shows the current version, and it opens at /events/<id>/-/views/<key>."}))},{description:"Required unless the view is attached to the workspace. Pass scope.type, scope.entity, or scope.event to select its subject."});function gr(n){return n.collection!==void 0&&(!n.type||n.entity!==void 0||n.event!==void 0)?"Collection selection requires scope.type without entity or event":n.event!==void 0&&(n.type!==void 0||n.entity!==void 0)?"scope.event names the view's subject on its own; drop scope.type and scope.entity":null}const vr=100,Qt=h.String({pattern:"^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$",description:"Stable id, unique across the whole document (sections and items). It names the menu entry, not its destination: two entries may open the same page."}),en=h.String({minLength:1,maxLength:80}),_r=h.String({pattern:"^[a-z0-9-]{1,40}$",description:"A Lucide icon name in kebab-case (https://lucide.dev/icons), e.g. 'building-2'; former Lucide names resolve too. Unknown names render the default icon."}),xr=h.Union([h.String({maxLength:500}),h.Number(),h.Boolean()]),br=h.Union([h.Object({kind:h.Literal("view"),key:mr,scope:h.Optional(h.Object(yr.properties,{additionalProperties:!1})),params:h.Optional(h.Record(h.String({maxLength:64}),xr,{maxProperties:20,description:"Declared view params; validated against the view when resolved."}))},{additionalProperties:!1}),h.Object({kind:h.Literal("collection"),entityType:h.String({minLength:1,maxLength:120})},{additionalProperties:!1}),h.Object({kind:h.Literal("record"),entityId:h.Integer({minimum:1})},{additionalProperties:!1}),h.Object({kind:h.Literal("link"),href:h.String({minLength:1,maxLength:2048,description:"Workspace-root-relative path (e.g. 'deal?stage=won', resolved under /<workspace>/) or an absolute https:// URL."})},{additionalProperties:!1})],{description:"{ kind: 'view', key, scope?, params? } | { kind: 'collection', entityType } | { kind: 'record', entityId } | { kind: 'link', href }"}),kr=h.Object({id:Qt,label:h.Optional(en),icon:h.Optional(_r),target:h.Optional(br),children:h.Optional(h.Array(h.Unknown(),{description:"Nested items, each the same shape as this one."}))},{additionalProperties:!1}),wr=h.Object({id:Qt,label:h.Optional(en),items:h.Array(kr)},{additionalProperties:!1});h.Object({schemaVersion:h.Literal(1),sections:h.Array(wr,{maxItems:vr})},{additionalProperties:!1,description:"{ schemaVersion: 1, sections: [{ id, label?, items: [{ id, label?, icon?, target?, children? }] }] }. An item without a target is a labeled group; with both, the label opens the target and a separate control expands the children."});const Sr=h.Object({id:h.String(),label:h.String(),icon:h.Optional(h.String()),href:h.Optional(h.String()),external:h.Optional(h.Boolean()),children:h.Array(h.Unknown(),{description:"Nested items, each the same shape as this one."})});h.Object({id:h.String(),label:h.Optional(h.String()),items:h.Array(Sr)});function Er(n,e,t){let r;try{r=new URL(n,`${e}/${encodeURIComponent(t)}/`)}catch{return null}if(r.username||r.password)return null;if(r.origin===e){const s=`/${encodeURIComponent(t)}`;return r.pathname!==s&&!r.pathname.startsWith(`${s}/`)?null:{kind:"internal",path:r.pathname+r.search+r.hash}}return r.protocol!=="https:"?null:{kind:"external",href:r.href}}const Tr="lobu/open-record";function Or(n,e){return n==="read_knowledge"?!0:n==="manage_entity"?e?.action==="list"||e?.action==="get"||e?.action==="list_links":n==="manage_automations"?e?.action==="list":n==="manage_agents"?e?.action==="get":n==="manage_connections"?e?.action==="list":n==="manage_catalog"?e?.action==="list_installed":n==="manage_entity_schema"&&e?.schema_type==="entity_type"&&(e.action==="list"||e.action==="get")}const Cr="lobu/embeds/sync",Nr="lobu/embeds/focus",Rr="lobu/notifications/embed-size",Ir="lobu/notifications/embed-focus",jr="lobu/notifications/focus-enter",Ar=8,$r=2,Zr=20,Vt=q({method:ut(Cr),params:q({embeds:hr(Yt()).max(64)})}),Pt=q({method:ut(Nr),params:q({id:G().min(1).max(64),direction:Gt(["forward","backward"]).optional()})}),Ge="lobu:embed-focus-enter",Te=Ie().finite(),Dt=q({x:Te,y:Te,width:Te.nonnegative(),height:Te.nonnegative()}),Mr=q({id:G().regex(/^[A-Za-z0-9_-]{1,64}$/),view:G().regex(/^[a-z0-9][a-z0-9-]{0,63}$/),scope:q({type:G().min(1).max(128).optional(),entity:Be([Ie().int().positive(),G().min(1).max(1024)]).optional(),event:Ie().int().positive().optional(),collection:Yt().optional()}).strict().transform((n,e)=>{const t=gr(n);if(t)return e.addIssue({code:d.custom,message:t}),Ye;if(typeof n.entity=="string"&&!n.type)return e.addIssue({code:d.custom,message:"type"}),Ye;if(n.collection===void 0)return n;try{return{...n,collection:gn(n.collection)}}catch(r){return e.addIssue({code:d.custom,message:String(r)}),Ye}}),params:pr(Be([G().max(2e3),Te,fr()])).refine(n=>Object.keys(n).length<=Zr),rect:Dt.extend({clip:Dt.optional()})});function Lr(n){const{clip:e}=n;if(!e)return{};if(e.width<=0||e.height<=0)return{visibility:"hidden",pointerEvents:"none"};const t=Math.max(0,e.y-n.y),r=Math.max(0,e.x-n.x),s=Math.max(0,n.y+n.height-(e.y+e.height)),a=Math.max(0,n.x+n.width-(e.x+e.width));return t||r||s||a?{clipPath:`inset(${t}px ${a}px ${s}px ${r}px)`}:{}}function Vr(n,e){const t=[],r=[],s=new Set;for(const a of n){const i=Mr.safeParse(a),o=i.success?i.data.id:typeof a?.id=="string"?a.id.slice(0,64):null;if(o===null)continue;if(!i.success||s.has(o)){r.push({id:o,status:"refused",reason:"invalid"});continue}s.add(o);const u=i.data;e.includes(u.view)?r.push({id:o,status:"refused",reason:"cycle"}):e.length>$r?r.push({id:o,status:"refused",reason:"depth"}):t.length>=Ar?r.push({id:o,status:"refused",reason:"limit"}):(t.push(u),r.push({id:o,status:"mounted"}))}return{instances:t,statuses:r}}function tn(n){return JSON.stringify([n.id,n.view,n.scope])}const Pr=n=>n instanceof Tn&&[400,401,403,404].includes(n.status);function Dr(n,e,t){const r=vn({slug:n}),s=r.data?.find(c=>c.key===t.view),{scope:a}=t,i=St({queryKey:["embed-record",e,n,a.type??null,a.entity??null],enabled:!!s&&a.entity!==void 0,staleTime:6e4,retry:!1,queryFn:async()=>{try{const m=(await En("manage_entity",{action:"get",entity_id:a.entity,...typeof a.entity=="string"?{entity_type:a.type}:{}},{slug:n})).entity;return typeof m?.entity_type!="string"||typeof m.view_url!="string"||typeof m.id!="number"&&typeof m.id!="string"?null:{type:m.entity_type,id:m.id,path:new URL(m.view_url,window.location.origin).pathname}}catch(c){if(Pr(c))return null;throw c}}}),o=St({..._n(n,s??{key:t.view,content_hash:null},a.event??0),enabled:!!s&&a.event!==void 0,retry:!1});if(!r.data)return r.isError?{kind:"failed",retry:()=>void r.refetch()}:{kind:"pending"};if(!s)return{kind:"missing"};const u=xn(s.key);if(a.event!==void 0)return o.isError?{kind:"failed",retry:()=>void o.refetch()}:o.data===void 0?{kind:"pending"}:o.data===null?{kind:"unattached"}:{kind:"ready",view:s,scope:{event:o.data},path:`/${n}/events/${o.data}${u}`};if(a.entity!==void 0){if(i.isError)return{kind:"failed",retry:()=>void i.refetch()};if(i.data===void 0)return{kind:"pending"};const c=i.data;return c===null?{kind:"unavailable"}:a.type!==void 0&&c.type!==a.type?{kind:"unattached"}:bn([s],{type:c.type,id:c.id}).length===0?{kind:"unattached"}:{kind:"ready",view:s,scope:{type:c.type,entity:a.entity},path:`${c.path}${u}`}}return a.type!==void 0?kn([s],a.type,a.collection).length===0?{kind:"unattached"}:{kind:"ready",view:s,scope:{type:a.type,...a.collection===void 0?{}:{collection:a.collection}},path:`/${n}/${encodeURIComponent(a.type)}${u}`}:wn([s]).length===0?{kind:"unattached"}:{kind:"ready",view:s,scope:{},path:`/${n}/data${u}`}}function zr(n,e){const t=new URLSearchParams;n.scope.collection!==void 0&&t.set(Sn,JSON.stringify(n.scope.collection));for(const[s,a]of Object.entries(e))n.view.params?.[s]?.default!==a&&t.set(s,String(a));const r=t.toString();return`${n.path}${r?`?${r}`:""}`}const Ur={pending:"Loading…",failed:"This view could not be loaded.",missing:"This view is no longer available.",unattached:"This view cannot be shown for what this slot names.",unavailable:"What this view shows is not available to you."},zt=28,Fr=64,pe=new Map;function Br(n,e){if(pe.delete(n),pe.set(n,e),pe.size>Fr){const t=pe.keys().next().value;t!==void 0&&pe.delete(t)}}const qr=({org:n,principal:e,home:t,ancestry:r,instance:s,onHeight:a,onFocusExit:i,renderFrame:o})=>{const u=Ht(),c=Dr(n,e,s),m=JSON.stringify(s.params),N=JSON.stringify([t,tn(s)]),[j,$]=w.useState(()=>{const E=pe.get(N);return E?.seed===m?E:{seed:m,params:s.params}}),P=E=>{Br(N,E),$(E)},je=j.seed===m?j.params:s.params;j.seed!==m&&P({seed:m,params:s.params});const te=c.kind==="ready"?zr(c,je):null,[qe,xe]=w.useState(!1),ie=qe?0:-1,X=E=>{te&&(E&&(E.defaultPrevented||E.button!==0||E.metaKey||E.ctrlKey||E.shiftKey||E.altKey)||(E?.preventDefault(),u({href:te})))},oe=(c.kind==="ready"?c.view.name:null)??s.view;return S.jsxs("section",{"aria-label":oe,"aria-busy":c.kind==="pending"||void 0,"data-embed-id":s.id,"data-embed-state":c.kind,className:"pointer-events-auto absolute flex flex-col overflow-hidden rounded-md border border-border bg-background",style:{left:s.rect.x,top:s.rect.y,width:s.rect.width,height:s.rect.height,...Lr(s.rect)},onFocus:()=>xe(!0),onBlur:E=>{E.currentTarget.contains(E.relatedTarget)||xe(!1)},children:[S.jsx("span",{tabIndex:ie,"data-embed-trap":"start",onFocus:()=>i(s.id,"backward")}),S.jsx("div",{className:"min-h-0 flex-1",children:c.kind==="ready"?o({viewKey:s.view,scope:c.scope,params:je,onParamsChange:E=>P({seed:m,params:E}),view:c.view,ancestry:r,onHeightChange:E=>a(s.id,E+zt),onRequestDisplayMode:E=>{E==="fullscreen"&&X()}}):S.jsxs("div",{role:c.kind==="pending"?void 0:"note",className:"flex h-full min-h-16 flex-col items-center justify-center gap-2 p-3 text-center text-xs text-muted-foreground",children:[S.jsx("span",{children:Ur[c.kind]}),c.kind==="failed"?S.jsx("button",{type:"button",onClick:c.retry,className:"rounded border border-border px-2 py-0.5 hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",children:"Retry"}):null]})}),S.jsxs("div",{className:"order-first flex shrink-0 items-center justify-between gap-2 border-b border-border px-2 text-xs text-muted-foreground",style:{height:zt},children:[S.jsx("span",{className:"truncate",children:oe}),te?S.jsxs("a",{href:te,tabIndex:ie,onClick:X,className:"inline-flex items-center gap-1 rounded px-1 hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",children:["Open",S.jsx(yn,{"aria-hidden":!0,className:"h-3 w-3"})]}):null]}),S.jsx("span",{tabIndex:ie,"data-embed-trap":"end",onFocus:()=>i(s.id,"forward")})]})},Wr=64,Hr=2e6,Jr=10*6e4,re=new Map;let Ut=null;function Xr(n,e,t,r){const{title:s,...a}=r&&typeof r=="object"?r:{};return[n,e,t,JSON.stringify(a)].join("\0")}function Ft(n){return JSON.stringify(n.result)}function Bt(n,e,t){if(re.delete(n),!(!e.ok||t===void 0||t.length>Hr))for(re.set(n,{text:t,result:e.result,at:Date.now()});re.size>Wr;){const r=re.keys().next().value;if(r===void 0)break;re.delete(r)}}function Kr(n){return{ok:!1,result:{content:[{type:"text",text:String(n)}],isError:!0}}}function Yr(n,e){Ut!==n&&(re.clear(),Ut=n);let t=0;const r=new Set,s=new Map;return{invalidate(){t+=1,s.clear()},async read(a,i){const o=s.get(a);if(o)return s.delete(a),o;const u=!r.has(a);r.add(a);const c=re.get(a);if(u&&c&&Date.now()-c.at<=Jr){const N=t,j=$=>{if(t!==N)return;const P=Ft($);Bt(a,$,P),!($.ok&&P===c.text)&&(s.set(a,$),e())};return i().then(j,$=>j(Kr($))),{ok:!0,result:c.result}}const m=await i();return Bt(a,m,Ft(m)),m}}}const qt=q({method:ut(Tr),params:q({record:q({entity_id:Be([Ie().int().positive().max(Number.MAX_SAFE_INTEGER),G().min(1).max(1024)]),entity_type:Be([G().min(1),Ie().int().positive()]).optional()}),mode:Gt(["peek","page"])})}),Gr=new Set(["query_sql","query_sdk"]),Qr=200;function es(n,e){const t=n?.title;return typeof t=="string"&&t.trim()?n??{}:{...n,title:e.slice(0,Qr)}}const Qe=new Map;function ts(n,e){const t=`${e}\0${n}`,r=Qe.get(t);if(r)return r;const s=Oe(`${Ce}/api/${n}/tools`,{method:"GET",credentials:"include",timeoutMs:15e3}).then(async a=>{if(!a.ok)throw new Error(`tool list failed: ${a.status}`);const i=await a.json();return new Set((i.tools??[]).flatMap(o=>typeof o.name=="string"&&o.annotations?.readOnlyHint===!0?[o.name]:[]))});return Qe.set(t,s),s.catch(()=>Qe.delete(t)),s}const ns=[["--color-background-primary","--background"],["--color-background-secondary","--card"],["--color-background-tertiary","--muted"],["--color-background-inverse","--foreground"],["--color-text-primary","--foreground"],["--color-text-secondary","--muted-foreground"],["--color-text-inverse","--background"],["--color-text-info","--primary"],["--color-text-danger","--destructive"],["--color-border-primary","--border"],["--color-border-secondary","--input"],["--color-border-danger","--destructive"],["--color-ring-primary","--ring"],["--font-mono","--font-mono"],["--border-radius-sm","--radius-sm"],["--border-radius-md","--radius-md"],["--border-radius-lg","--radius-lg"],["--border-radius-xl","--radius-xl"]];function et(n){const e=document.documentElement,t=getComputedStyle(e),r={};for(const[a,i]of ns){const o=t.getPropertyValue(i).trim();o&&(r[a]=o)}const s=document.body?getComputedStyle(document.body).fontFamily:"";return s&&(r["--font-sans"]=s),{theme:e.classList.contains("dark")?"dark":"light",displayMode:n.displayMode,availableDisplayModes:n.expandable?["inline","fullscreen"]:[n.displayMode],containerDimensions:{...n.width?{width:n.width}:{},...n.maxHeight?{maxHeight:n.maxHeight}:{}},platform:"web",styles:{variables:r}}}async function rs(n,e,t,r,s,a,i,o){if(i!=="invoke_view_action"){const P=Gr.has(i);return!P&&!Or(i,o)&&!(await ts(n,e)).has(i)?{error:`Views can only call read tools and their declared actions; "${i}" is neither`}:{url:`${Ce}/api/${n}/${encodeURIComponent(i)}`,body:P?es(o,s):o??{}}}const{view:u,action:c,value:m,interaction_id:N,scope:j,expected:$}=o??{};return j!==void 0&&(typeof j!="object"||j===null||j.event!==a.event)?{error:"The event context changed. Reopen the event before submitting."}:u!==t?{error:`This frame hosts "${t}", not "${String(u)}"`}:typeof c!="string"||!c?{error:"action is required"}:{url:`${Ce}/api/${n}/views/${encodeURIComponent(t)}/actions/${encodeURIComponent(c)}`,body:{value:m??null,interaction_id:N,...$===void 0?{}:{expected:$},...r===null?{}:{expected_content_hash:r},...a.event===void 0?{}:{scope:{event:a.event}}}}}const Wt=24,F=new Map,se=new Map;function ss(n,e){const t=`${n}\0${e}`,r=F.get(t);return r!==void 0&&(F.delete(t),F.set(t,r)),r}function as(n,e,t){se.delete(n),se.set(n,{hash:e,html:t});for(const s of se.keys()){if(se.size<=Wt)break;se.delete(s)}if(e===null)return;const r=`${n}\0${e}`;F.delete(r),F.set(r,t);for(const s of F.keys()){if(F.size<=Wt)break;F.delete(s)}}const Le=new Map;function is(n,e,t,r){const s=Le.get(n);if(s)return s;const a=Oe(e,{credentials:"include"}).then(async i=>r&&(i.status===401||i.status===403)?Oe(t,{credentials:"include"}):i).then(async i=>{if(!i.ok)throw new nn(i.status);return{html:await i.text(),hash:i.headers.get("X-Lobu-View-Hash")}});return Le.set(n,a),a.then(()=>Le.delete(n),()=>Le.delete(n)),a}class nn extends Error{constructor(e){super(`shell ${e}`),this.status=e}}function os(n){se.delete(n);for(const e of F.keys())e.startsWith(`${n}\0`)&&F.delete(e)}const cs=({orgSlug:n,viewKey:e,scope:t,params:r,onParamsChange:s,paramDecls:a,contentHash:i,title:o,minHeight:u=96,fixedHeight:c,displayMode:m="fullscreen",maxHeight:N,onRequestDisplayMode:j,className:$,onLoadError:P,embedAncestry:je,onHeightChange:te,frameTabIndex:qe})=>{const xe=Ht(),ie=On(),X=w.useRef(ie);X.current=ie;const oe=w.useRef(xe);oe.current=xe;const{session:E,isReady:rn}=Cn(),We=rn&&!E,be=E?.user.id??"anonymous",Ae=w.useRef(null),$e=w.useRef(null),[ce,He]=w.useState(null),[Ze,Je]=w.useState(null),[Xe,sn]=w.useState(u),de=w.useRef(null),ue=w.useRef(null),lt=w.useRef(u);lt.current=u;const ft=w.useRef(c);ft.current=c;const L=w.useRef({scope:t,params:r,paramDecls:a,onParamsChange:s,onLoadError:P,onRequestDisplayMode:j,onHeightChange:te,title:o});L.current={scope:t,params:r,paramDecls:a,onParamsChange:s,onLoadError:P,onRequestDisplayMode:j,onHeightChange:te,title:o};const[ht,pt]=w.useState([]),ke=w.useRef(null),we=[...je??[],e],an=we.join("\0"),on=JSON.stringify([be,n,we,t]),mt=w.useRef(we);mt.current=we;const yt=w.useRef(null),cn=w.useCallback((C,b)=>{ke.current?.(Rr,{id:C,height:b})},[]),dn=w.useCallback((C,b)=>{Ae.current?.focus(),ke.current?.(Ir,{id:C,direction:b})},[]),[gt,un]=w.useState(void 0),Se=w.useRef({displayMode:m,expandable:!1});Se.current={displayMode:m,maxHeight:N,width:gt,expandable:j!==void 0};const D=`${be}\0${$n(n,e)}`;w.useEffect(()=>{let C=!1;if(D!==ue.current&&(He(null),ue.current=null,de.current=null),Je(null),i!=null&&i===de.current&&D===ue.current)return()=>{C=!0};const b=i==null?se.get(D):(()=>{const R=ss(D,i);return R===void 0?void 0:{hash:i,html:R}})();if(b!==void 0)return de.current=b.hash??i??null,ue.current=D,He(b.html),()=>{C=!0};const ne=R=>`${Ce}/api/${n}${R?"/public":""}/views/${encodeURIComponent(e)}/shell`;return is(D,ne(We),ne(!0),!We).then(({html:R,hash:le})=>{as(D,le,R),!C&&(le!==null&&le===de.current&&D===ue.current||(de.current=le,ue.current=D,Je(null),He(R)))}).catch(R=>{R instanceof nn&&[401,403,404,410].includes(R.status)&&os(D),C||(Je(R instanceof Error?R.message:String(R)),L.current.onLoadError?.())}),()=>{C=!0}},[D,n,e,i,We]);const ln=j!==void 0;w.useEffect(()=>{$e.current?.setHostContext(et(Se.current))},[m,N,gt,ln]),w.useEffect(()=>{const C=Ae.current;if(!C||typeof ResizeObserver>"u")return;const b=new ResizeObserver(([ne])=>{const R=Math.round(ne.contentRect.width);R>0&&un(R)});return b.observe(C),()=>b.disconnect()},[ce]);const fn=JSON.stringify(r),hn=JSON.stringify(t);if(w.useEffect(()=>{$e.current?.sendToolInput({arguments:{scope:L.current.scope,params:L.current.params}})},[hn,fn]),w.useEffect(()=>{if(!ce||Ze)return;const C=Ae.current;if(!C?.contentWindow)return;const b=n,ne=e,R=be,le=de.current;let Z=!1;const _t=Yr(R,()=>{Z||bt()}),M=new Ln(null,{name:"Lobu",version:"1.0.0"},{openLinks:{},serverTools:{},updateModelContext:{structuredContent:{}}},{hostContext:et(Se.current)});M.addEventListener("sizechange",({height:k})=>{ft.current||typeof k=="number"&&(sn(Math.max(lt.current,Math.ceil(k))),L.current.onHeightChange?.(Math.ceil(k)))}),M.setRequestHandler(qt,async k=>{const{params:T}=qt.parse(k);if(Z)throw new Error("View unmounted");if(typeof T.record.entity_id=="string"&&!T.record.entity_type)throw new Error("String record keys require entity_type");const O=await Oe(`${Ce}/api/${b}/manage_entity`,{method:"POST",credentials:"include",timeoutMs:15e3,headers:{"Content-Type":"application/json"},body:JSON.stringify({...T.record,action:"get"})});if(!O.ok)throw new Error(`Could not open record (${O.status})`);const z=(await O.json()).entity;if(Z)throw new Error("View unmounted");if(!z?.view_url)throw new Error("Record is unavailable");if(T.mode==="peek"&&X.current){const K={ownerSlug:b,orgContext:{slug:b},name:z.name};return X.current.open(Pn(typeof z.id=="number"?{...K,entityId:z.id}:{...K,record:{type:z.entity_type,key:z.slug}})),{mode:"peek"}}return await oe.current({href:z.view_url}),{mode:"page"}}),M.setRequestHandler(Vt,async k=>{const{params:T}=Vt.parse(k);if(Z)throw new Error("View unmounted");const O=Vr(T.embeds,mt.current);return pt(O.instances),{embeds:O.statuses}}),M.setRequestHandler(Pt,async k=>{const{params:T}=Pt.parse(k);if(Z)throw new Error("View unmounted");const U=[...yt.current?.querySelectorAll("[data-embed-id]")??[]].find(z=>z.dataset.embedId===T.id)?.querySelector("iframe");if(!U)throw new Error("No such embedded view");return U.focus(),U.dispatchEvent(new CustomEvent(Ge,{detail:T.direction??"forward"})),{}}),M.oncalltool=async({name:k,arguments:T})=>{if(Z)return{content:[{type:"text",text:"view unmounted"}],isError:!0};let O;try{O=await rs(b,R,ne,le,L.current.title??ne,L.current.scope,k,T)}catch(K){return{content:[{type:"text",text:String(K)}],isError:!0}}if(Z)return{content:[{type:"text",text:"view unmounted"}],isError:!0};if("error"in O)return{content:[{type:"text",text:O.error}],isError:!0};const U=async()=>{const K=await Oe(O.url,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(O.body),timeoutMs:3e4}),fe=await K.json().catch(()=>null);if(!K.ok){const wt=fe&&typeof fe.error=="string"&&fe.error||`API error: ${K.status}`;return{ok:!1,result:{content:[{type:"text",text:wt}],isError:!0,structuredContent:{error:{message:wt,code:fe?.code}}}}}return{ok:!0,result:{content:[{type:"text",text:JSON.stringify(fe)}],structuredContent:fe??{}}}};return(k==="invoke_view_action"?await U():await _t.read(Xr(R,b,k,T),U)).result},M.onupdatemodelcontext=async({structuredContent:k})=>{if(Z)return{};const T=Nn(k?.params,L.current.paramDecls);return T&&L.current.onParamsChange(T),{}},M.onopenlink=async({url:k})=>{if(Z)return{};const T=Er(k,window.location.origin,b);if(!T)return{isError:!0};if(T.kind==="external")return window.open(T.href,"_blank","noopener,noreferrer"),{};const O=new URL(T.path,window.location.origin);O.pathname=Rn(O.pathname);const U=O.pathname+O.search+O.hash;return In(O.href)?.owner===b&&X.current?X.current.open({href:U,title:"Details"}):await oe.current({href:U}),{}},M.onrequestdisplaymode=async({mode:k})=>{const T=Se.current.displayMode,O=L.current.onRequestDisplayMode;return!Z&&O&&k!==T&&(k==="inline"||k==="fullscreen")&&O(k),{mode:T}},M.addEventListener("initialized",()=>{M.sendToolInput({arguments:{scope:L.current.scope,params:L.current.params}})});const Me=new Vn(C.contentWindow,C.contentWindow);ke.current=(k,T)=>{Z||Me.send({jsonrpc:"2.0",method:k,params:T}).catch(()=>{})};const xt=k=>{ke.current?.(jr,{direction:k.detail==="backward"?"backward":"forward"})};C.addEventListener(Ge,xt),M.connect(Me).catch(k=>{console.error("[view-frame] failed to initialize",k)}),$e.current=M;const bt=()=>{Me.send({jsonrpc:"2.0",method:"lobu/notifications/data-changed",params:{}}).catch(()=>{})},pn=jn(()=>{Z||(_t.invalidate(),bt())}),kt=new MutationObserver(()=>{M.setHostContext(et(Se.current))});return kt.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{Z=!0,ke.current=null,C.removeEventListener(Ge,xt),pt([]),pn(),kt.disconnect(),$e.current=null,Me.close()}},[ce,Ze,n,e,be]),Ze)return S.jsxs("div",{"data-testid":"view-frame-error",className:"text-sm text-destructive",children:["View failed to load: ",Ze]});const vt=!c&&N!==void 0&&Xe>N;return S.jsxs("div",{className:An("relative",N!==void 0&&"overflow-hidden",$),style:N!==void 0?{maxHeight:N}:void 0,"data-testid":"view-frame","data-view":e,"data-clipped":vt||void 0,children:[ce?S.jsx("iframe",{ref:Ae,title:o??e,srcDoc:ce,sandbox:"allow-scripts",tabIndex:qe,style:{width:"100%",height:c??Xe,border:"none",display:"block"}}):S.jsx("div",{className:"animate-pulse rounded-md bg-muted/40",style:{height:u}}),ht.length>0&&ce?S.jsx("div",{ref:yt,"data-testid":"view-embeds",className:"pointer-events-none absolute inset-x-0 top-0 overflow-hidden",style:{height:c??Xe},children:ht.map(C=>S.jsx(qr,{org:n,principal:be,home:on,ancestry:we,instance:C,onHeight:cn,onFocusExit:dn,renderFrame:b=>S.jsx(cs,{orgSlug:n,viewKey:b.viewKey,scope:b.scope,params:b.params,onParamsChange:b.onParamsChange,paramDecls:b.view.params,contentHash:b.view.content_hash,title:b.view.name,displayMode:"inline",minHeight:64,onRequestDisplayMode:b.onRequestDisplayMode,embedAncestry:b.ancestry,onHeightChange:b.onHeightChange,frameTabIndex:-1})},tn(C)))},an):null,vt?S.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-x-0 bottom-0 h-12 bg-gradient-to-t from-background to-transparent"}):null]})};function fs({viewKey:n,backTo:e,backLabel:t}){return S.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center","data-testid":"missing-view",children:[S.jsxs("h2",{className:"text-lg font-semibold",children:["No view named “",n,"” here"]}),S.jsx("p",{className:"text-muted-foreground mt-2 text-sm",children:"It may have been renamed or detached from this page."}),S.jsx(Mn,{to:e,className:"mt-4 text-sm font-medium underline underline-offset-4",children:t})]})}function hs({error:n,onRetry:e}){const t=Zn(n,{subject:"Views"});return S.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center","data-testid":"views-unavailable",children:[S.jsx("h2",{className:"text-lg font-semibold",children:t.title}),S.jsx("p",{className:"text-muted-foreground mt-2 max-w-md text-sm",children:t.body}),t.retryable?S.jsx("button",{type:"button",onClick:e,className:"mt-4 text-sm font-medium underline underline-offset-4",children:"Try again"}):null]})}export{fs as M,hs as V,cs as a};
2
+ //# sourceMappingURL=missing-view-xT0B-f5z.js.map
@@ -1,2 +1,2 @@
1
- import{aW as v,aX as N,j as s,gO as y,aO as m,a9 as p,i as f,B as w,gQ as b}from"./index-DByaMzsG.js";function M(o,r){const l=new Map(r.map(e=>[e.slug,e])),i=new Map,d=e=>{const a=e.model?.trim();if(!a)return;const t=`${e.slug}/${a}`;i.has(t)||i.set(t,{value:t,provider:e.provider,model:a,isDefault:e.isDefault})};for(const e of o){const a=l.get(e.kind)??l.get(e.slug),t={slug:e.slug,provider:e.displayName||e.slug,isDefault:e.isDefault};d({...t,model:e.capabilities.text?.model}),d({...t,model:a?.defaultModel});for(const x of a?.models??[])d({...t,model:x})}for(const e of r){if(!e.systemAvailable)continue;const a={slug:e.slug,provider:e.displayName||e.slug,isDefault:!1};d({...a,model:e.defaultModel});for(const t of e.models)d({...a,model:t})}return[...i.values()]}function _(o,r){const l=o.trim();return l.length>0&&l!=="auto"&&!r.some(i=>i.value===l)}function S({value:o,onChange:r,placeholder:l,disabled:i,className:d}){const{data:e=[]}=v(),{data:a=[]}=N(),t=M(e,a),x=t.find(c=>c.value===o),h=o==="auto"?"auto":x?.value??o;return s.jsx(y,{contentClassName:"w-[--radix-popover-trigger-width] min-w-[280px]",searchPlaceholder:"Search or type a model ref…",emptyText:"Type a full provider/model ref to use it.",trigger:c=>s.jsxs(w,{type:"button",variant:"outline",role:"combobox","aria-expanded":c,disabled:i,className:f("w-full justify-between font-normal",o?"":"text-muted-foreground",d),children:[s.jsx("span",{className:"truncate",children:o?h:l}),s.jsx(b,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(c,j)=>{const u=j.trim(),g=_(u,t);return s.jsxs(s.Fragment,{children:[s.jsxs(m,{value:"__inherit__ use default inherit",onSelect:()=>{r(""),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o===""?"opacity-100":"opacity-0")}),s.jsx("span",{className:"text-muted-foreground",children:l})]}),s.jsxs(m,{value:"auto newest latest",onSelect:()=>{r("auto"),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o==="auto"?"opacity-100":"opacity-0")}),s.jsxs("span",{children:["auto"," ",s.jsx("span",{className:"text-muted-foreground text-xs",children:"(newest for the provider)"})]})]}),t.map(n=>s.jsxs(m,{value:`${n.provider} ${n.model} ${n.value}`,onSelect:()=>{r(n.value),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o===n.value?"opacity-100":"opacity-0")}),s.jsxs("span",{className:"truncate",children:[n.provider," ",s.jsx("span",{className:"text-muted-foreground text-xs",children:n.model}),n.isDefault?s.jsx("span",{className:"ml-1.5 text-muted-foreground text-xs",children:"· org default"}):null]})]},n.value)),g?s.jsxs(m,{value:`__custom__ ${u}`,onSelect:()=>{r(u),c()},className:"cursor-pointer",children:[s.jsx(p,{className:"mr-2 h-4 w-4 opacity-0"}),s.jsxs("span",{children:["Use ",s.jsx("span",{className:"font-mono text-xs",children:u})]})]}):null]})}})}export{S as M,M as b,_ as s};
2
- //# sourceMappingURL=model-selector-D3vSMLO2.js.map
1
+ import{aW as v,aX as N,j as s,gL as y,aO as m,a9 as p,i as f,B as w,gN as b}from"./index-BoqrvLHQ.js";function M(o,r){const l=new Map(r.map(e=>[e.slug,e])),i=new Map,d=e=>{const a=e.model?.trim();if(!a)return;const t=`${e.slug}/${a}`;i.has(t)||i.set(t,{value:t,provider:e.provider,model:a,isDefault:e.isDefault})};for(const e of o){const a=l.get(e.kind)??l.get(e.slug),t={slug:e.slug,provider:e.displayName||e.slug,isDefault:e.isDefault};d({...t,model:e.capabilities.text?.model}),d({...t,model:a?.defaultModel});for(const x of a?.models??[])d({...t,model:x})}for(const e of r){if(!e.systemAvailable)continue;const a={slug:e.slug,provider:e.displayName||e.slug,isDefault:!1};d({...a,model:e.defaultModel});for(const t of e.models)d({...a,model:t})}return[...i.values()]}function _(o,r){const l=o.trim();return l.length>0&&l!=="auto"&&!r.some(i=>i.value===l)}function S({value:o,onChange:r,placeholder:l,disabled:i,className:d}){const{data:e=[]}=v(),{data:a=[]}=N(),t=M(e,a),x=t.find(c=>c.value===o),h=o==="auto"?"auto":x?.value??o;return s.jsx(y,{contentClassName:"w-[--radix-popover-trigger-width] min-w-[280px]",searchPlaceholder:"Search or type a model ref…",emptyText:"Type a full provider/model ref to use it.",trigger:c=>s.jsxs(w,{type:"button",variant:"outline",role:"combobox","aria-expanded":c,disabled:i,className:f("w-full justify-between font-normal",o?"":"text-muted-foreground",d),children:[s.jsx("span",{className:"truncate",children:o?h:l}),s.jsx(b,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(c,j)=>{const u=j.trim(),g=_(u,t);return s.jsxs(s.Fragment,{children:[s.jsxs(m,{value:"__inherit__ use default inherit",onSelect:()=>{r(""),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o===""?"opacity-100":"opacity-0")}),s.jsx("span",{className:"text-muted-foreground",children:l})]}),s.jsxs(m,{value:"auto newest latest",onSelect:()=>{r("auto"),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o==="auto"?"opacity-100":"opacity-0")}),s.jsxs("span",{children:["auto"," ",s.jsx("span",{className:"text-muted-foreground text-xs",children:"(newest for the provider)"})]})]}),t.map(n=>s.jsxs(m,{value:`${n.provider} ${n.model} ${n.value}`,onSelect:()=>{r(n.value),c()},className:"cursor-pointer",children:[s.jsx(p,{className:f("mr-2 h-4 w-4",o===n.value?"opacity-100":"opacity-0")}),s.jsxs("span",{className:"truncate",children:[n.provider," ",s.jsx("span",{className:"text-muted-foreground text-xs",children:n.model}),n.isDefault?s.jsx("span",{className:"ml-1.5 text-muted-foreground text-xs",children:"· org default"}):null]})]},n.value)),g?s.jsxs(m,{value:`__custom__ ${u}`,onSelect:()=>{r(u),c()},className:"cursor-pointer",children:[s.jsx(p,{className:"mr-2 h-4 w-4 opacity-0"}),s.jsxs("span",{children:["Use ",s.jsx("span",{className:"font-mono text-xs",children:u})]})]}):null]})}})}export{S as M,M as b,_ as s};
2
+ //# sourceMappingURL=model-selector-D2OpDkwH.js.map
@@ -1,2 +1,2 @@
1
- import{r as N,j as e,ep as I,eq as $,er as B,es as b,M as S,et as E,eu as _,ev as f,B as O,a9 as P,by as j}from"./index-DByaMzsG.js";const T=5,Y=5;function D({entries:s,onMarkRead:t,disabled:o=!1}){const n=s.filter(r=>r.unreadIds.length>0);return n.length===0?null:e.jsxs("button",{type:"button",disabled:o,className:"ml-auto inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:()=>t(n.flatMap(r=>r.unreadIds)),children:[e.jsx($,{"aria-hidden":"true",className:"h-3.5 w-3.5"}),"Mark ",n.length," read"]})}function q({owner:s,entries:t,pageIds:o,onMarkRead:n,markPending:r}){const[u,x]=N.useState(!1);if(t.length===0)return null;const a=u?t:t.slice(0,Y),d=t.length-a.length,p=i=>{const c=o.has(i.item.id)?"This page":w(i);return c?`Needs you · ${c}`:"Needs you"};return e.jsxs("ul",{"aria-label":"Needs you",className:"mb-4 divide-y overflow-hidden rounded-lg border",children:[t.length>1?e.jsxs("li",{className:"flex flex-wrap items-center gap-2 px-3 py-1.5",children:[e.jsxs("span",{className:"text-xs text-muted-foreground tabular-nums",children:[t.length," need you"]}),e.jsx(D,{entries:t,onMarkRead:n,disabled:r}),e.jsx(I,{owner:s,showMarkRead:!1})]}):null,e.jsx(y,{owner:s,entries:a,tag:p}),d>0?e.jsx("li",{children:e.jsxs("button",{type:"button",className:"w-full px-3 py-2 text-left text-xs text-muted-foreground hover:bg-muted/40 hover:text-foreground",onClick:()=>x(!0),children:["Show all ",t.length]})}):null]})}function F({owner:s,entries:t}){return t.length===0?null:e.jsx("ul",{className:"divide-y overflow-hidden rounded-lg border",children:e.jsx(y,{owner:s,entries:t,tag:w})})}const w=s=>s.repeats>1?`${s.repeats}×`:void 0;function y({owner:s,entries:t,tag:o}){return B(t).map(n=>e.jsx("li",{children:n.entries.length>1?e.jsx(z,{owner:s,group:n}):e.jsx(b,{owner:s,item:n.entries[0].item,variant:"row",tag:o(n.entries[0])})},n.key))}function z({owner:s,group:t}){const[o,n]=N.useState(!1),{orgContext:r}=S(),u=E(),x=_(r),{entries:a}=t,d=a[0],p=a[a.length-1],i=new Set(a.map(({card:l})=>l.run_id)).size,c=o?a:a.slice(0,T),g=a.length-c.length,m=a.flatMap(({item:l})=>l.approvalRunId!=null?[l.approvalRunId]:[]),k=u.isPending||x.isPending,R=d.card.automation_name?.trim(),A=d.card.at===p.card.at?f(d.card.at):`${f(p.card.at)} – ${f(d.card.at)}`,M=async()=>{const l=await u.mutateAsync({decision:"approve",runIds:m}),C=new Set(l.failedRunIds),v=a.flatMap(({item:h})=>h.approvalRunId!=null&&!C.has(h.approvalRunId)&&h.notificationId!=null?[h.notificationId]:[]);v.length>0&&await x.mutateAsync(v),l.failed>0?j.error(`${l.succeeded} approved; ${l.failed} failed.`):j.success(`${l.succeeded} approved.`)};return e.jsxs("section",{"aria-label":`${a.length} approvals`,className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5 px-3 pt-2.5 pb-1.5",children:[e.jsxs("h3",{className:"text-sm font-medium",children:[a.length," approvals waiting"]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Proposed by ",R??"this Automation"," ·"," ",i===1?"1 run":`${i} runs`," · ",A]})]}),e.jsx("ul",{className:"divide-y border-t",children:c.map(l=>e.jsx("li",{children:e.jsx(b,{owner:s,item:l.item,variant:"row",showMark:!1})},l.item.id))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t px-3 py-2 text-xs",children:[g>0?e.jsxs("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>n(!0),children:[g," more · Review all"]}):null,m.length>1?e.jsxs(O,{type:"button",size:"sm",className:"ml-auto h-7 text-xs",disabled:k,onClick:()=>void M(),children:[e.jsx(P,{className:"mr-1 h-3 w-3"}),"Approve all ",m.length]}):null]})]})}export{D as M,q as N,F as a};
2
- //# sourceMappingURL=needs-you-list-B5Bgd05M.js.map
1
+ import{r as N,j as e,et as I,eu as $,ev as B,ew as b,M as S,ex as E,ey as _,ez as f,B as O,a9 as P,by as j}from"./index-BoqrvLHQ.js";const T=5,Y=5;function z({entries:s,onMarkRead:t,disabled:o=!1}){const n=s.filter(r=>r.unreadIds.length>0);return n.length===0?null:e.jsxs("button",{type:"button",disabled:o,className:"ml-auto inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",onClick:()=>t(n.flatMap(r=>r.unreadIds)),children:[e.jsx($,{"aria-hidden":"true",className:"h-3.5 w-3.5"}),"Mark ",n.length," read"]})}function F({owner:s,entries:t,pageIds:o,onMarkRead:n,markPending:r}){const[u,x]=N.useState(!1);if(t.length===0)return null;const a=u?t:t.slice(0,Y),d=t.length-a.length,p=i=>{const c=o.has(i.item.id)?"This page":w(i);return c?`Needs you · ${c}`:"Needs you"};return e.jsxs("ul",{"aria-label":"Needs you",className:"mb-4 divide-y overflow-hidden rounded-lg border",children:[t.length>1?e.jsxs("li",{className:"flex flex-wrap items-center gap-2 px-3 py-1.5",children:[e.jsxs("span",{className:"text-xs text-muted-foreground tabular-nums",children:[t.length," need you"]}),e.jsx(z,{entries:t,onMarkRead:n,disabled:r}),e.jsx(I,{owner:s,showMarkRead:!1})]}):null,e.jsx(y,{owner:s,entries:a,tag:p}),d>0?e.jsx("li",{children:e.jsxs("button",{type:"button",className:"w-full px-3 py-2 text-left text-xs text-muted-foreground hover:bg-muted/40 hover:text-foreground",onClick:()=>x(!0),children:["Show all ",t.length]})}):null]})}function G({owner:s,entries:t}){return t.length===0?null:e.jsx("ul",{className:"divide-y overflow-hidden rounded-lg border",children:e.jsx(y,{owner:s,entries:t,tag:w})})}const w=s=>s.repeats>1?`${s.repeats}×`:void 0;function y({owner:s,entries:t,tag:o}){return B(t).map(n=>e.jsx("li",{children:n.entries.length>1?e.jsx(D,{owner:s,group:n}):e.jsx(b,{owner:s,item:n.entries[0].item,variant:"row",tag:o(n.entries[0])})},n.key))}function D({owner:s,group:t}){const[o,n]=N.useState(!1),{orgContext:r}=S(),u=E(),x=_(r),{entries:a}=t,d=a[0],p=a[a.length-1],i=new Set(a.map(({card:l})=>l.run_id)).size,c=o?a:a.slice(0,T),g=a.length-c.length,m=a.flatMap(({item:l})=>l.approvalRunId!=null?[l.approvalRunId]:[]),k=u.isPending||x.isPending,R=d.card.automation_name?.trim(),A=d.card.at===p.card.at?f(d.card.at):`${f(p.card.at)} – ${f(d.card.at)}`,M=async()=>{const l=await u.mutateAsync({decision:"approve",runIds:m}),C=new Set(l.failedRunIds),v=a.flatMap(({item:h})=>h.approvalRunId!=null&&!C.has(h.approvalRunId)&&h.notificationId!=null?[h.notificationId]:[]);v.length>0&&await x.mutateAsync(v),l.failed>0?j.error(`${l.succeeded} approved; ${l.failed} failed.`):j.success(`${l.succeeded} approved.`)};return e.jsxs("section",{"aria-label":`${a.length} approvals`,className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-0.5 px-3 pt-2.5 pb-1.5",children:[e.jsxs("h3",{className:"text-sm font-medium",children:[a.length," approvals waiting"]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Proposed by ",R??"this Automation"," ·"," ",i===1?"1 run":`${i} runs`," · ",A]})]}),e.jsx("ul",{className:"divide-y border-t",children:c.map(l=>e.jsx("li",{children:e.jsx(b,{owner:s,item:l.item,variant:"row",showMark:!1})},l.item.id))}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t px-3 py-2 text-xs",children:[g>0?e.jsxs("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>n(!0),children:[g," more · Review all"]}):null,m.length>1?e.jsxs(O,{type:"button",size:"sm",className:"ml-auto h-7 text-xs",disabled:k,onClick:()=>void M(),children:[e.jsx(P,{className:"mr-1 h-3 w-3"}),"Approve all ",m.length]}):null]})]})}export{z as M,F as N,G as a};
2
+ //# sourceMappingURL=needs-you-list-3uMsWcDv.js.map