graview 0.1.67 → 0.1.68

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 (189) hide show
  1. package/dist/preview/{chunk.YCD4JSXD.js → chunk.2BMZPALF.js} +1 -1
  2. package/dist/preview/{chunk.SNHKYH72.js → chunk.2KCDLCB2.js} +1 -1
  3. package/dist/preview/{chunk.O2OL6RQQ.js → chunk.2ME4DVBI.js} +1 -1
  4. package/dist/preview/chunk.2TUEBU7X.js +8 -0
  5. package/dist/preview/{chunk.LYEGRY77.js → chunk.2U6HB4XU.js} +1 -1
  6. package/dist/preview/{chunk.7S6ZRMW4.js → chunk.32JE2WS7.js} +1 -1
  7. package/dist/preview/{chunk.RG5G6YQD.js → chunk.3DEWQDP7.js} +1 -1
  8. package/dist/preview/{chunk.GVT4UUQA.js → chunk.3JMQKANL.js} +1 -1
  9. package/dist/preview/{chunk.A5PSEU3W.js → chunk.3VEZ5MOC.js} +1 -1
  10. package/dist/preview/chunk.3WPCS6KP.js +1 -0
  11. package/dist/preview/{chunk.5R744JGZ.js → chunk.42C3FIKK.js} +1 -1
  12. package/dist/preview/{chunk.IAEGJDF3.js → chunk.42KHFGN6.js} +1 -1
  13. package/dist/preview/{chunk.DZMIYEHQ.js → chunk.4DXPPM6T.js} +1 -1
  14. package/dist/preview/chunk.4GVKKBQL.js +1 -0
  15. package/dist/preview/{chunk.KX5ZBHMA.js → chunk.4TT3ZHSJ.js} +1 -1
  16. package/dist/preview/{chunk.QXLJGHMC.js → chunk.4YAO3A5Q.js} +3 -3
  17. package/dist/preview/{chunk.Z4TY44CD.js → chunk.5JKUT2OM.js} +1 -1
  18. package/dist/preview/chunk.5L4ADKTW.js +1 -0
  19. package/dist/preview/{chunk.BKYZSV2Y.js → chunk.64LCHHZB.js} +1 -1
  20. package/dist/preview/{chunk.ZEZUKRC6.js → chunk.6AANHELP.js} +1 -1
  21. package/dist/preview/{chunk.ZAQ4IDX6.js → chunk.6DMCEBSO.js} +1 -1
  22. package/dist/preview/{chunk.NKLPL7QD.js → chunk.6IR5LBJU.js} +1 -1
  23. package/dist/preview/{chunk.X226YATK.js → chunk.6WB2TYK7.js} +1 -1
  24. package/dist/preview/chunk.6ZENHSTQ.js +1 -0
  25. package/dist/preview/{chunk.EJ2EZL2G.js → chunk.7K2V5FUB.js} +1 -1
  26. package/dist/preview/chunk.7OL6H4LF.js +1 -0
  27. package/dist/preview/{chunk.4W57E7AX.js → chunk.7TDML5YU.js} +1 -1
  28. package/dist/preview/{chunk.AJMVRFYX.js → chunk.7WPVLEX2.js} +2 -2
  29. package/dist/preview/{chunk.XSWSBTUO.js → chunk.7ZTGB4O7.js} +1 -1
  30. package/dist/preview/{chunk.FRQSLWP4.js → chunk.ACNOP2IU.js} +1 -1
  31. package/dist/preview/{chunk.N4ZKZ4GM.js → chunk.AENP662H.js} +1 -1
  32. package/dist/preview/{chunk.SFBHPYRD.js → chunk.AQ2PI6MR.js} +1 -1
  33. package/dist/preview/chunk.ARS4HJD2.js +1 -0
  34. package/dist/preview/{chunk.STPA7HBK.js → chunk.AWV57UBJ.js} +1 -1
  35. package/dist/preview/{chunk.D7NWMXSX.js → chunk.AYZL3LCR.js} +3 -3
  36. package/dist/preview/{chunk.URQTF5SY.js → chunk.BHJRT57H.js} +1 -1
  37. package/dist/preview/{chunk.7UHPHEH5.js → chunk.BPNW5KCP.js} +1 -1
  38. package/dist/preview/{chunk.TTSGCNPT.js → chunk.BQAFFEOA.js} +1 -1
  39. package/dist/preview/chunk.C2QKA6XY.js +1 -0
  40. package/dist/preview/{chunk.6KJGRM7A.js → chunk.CE3NKAF7.js} +1 -1
  41. package/dist/preview/{chunk.QRQ5WPZI.js → chunk.CFE3MHWZ.js} +1 -1
  42. package/dist/preview/{chunk.H6KIEDZN.js → chunk.CGBOPPNL.js} +1 -1
  43. package/dist/preview/{chunk.LP2ZMAT2.js → chunk.CNN32262.js} +1 -1
  44. package/dist/preview/{chunk.HJUZMOW2.js → chunk.DCLF4WWZ.js} +1 -1
  45. package/dist/preview/{chunk.GMLONS5L.js → chunk.DGDW54KE.js} +1 -1
  46. package/dist/preview/{chunk.3GNT5MKP.js → chunk.DLSS56EU.js} +1 -1
  47. package/dist/preview/{chunk.QAM76AXV.js → chunk.DMZRFXH7.js} +1 -1
  48. package/dist/preview/{chunk.Z2XUVJAL.js → chunk.DPHH5ZVL.js} +1 -1
  49. package/dist/preview/{chunk.Z27NSSYL.js → chunk.DZ6UDZOB.js} +2 -2
  50. package/dist/preview/{chunk.6W6XMLSF.js → chunk.E423JCOS.js} +1 -1
  51. package/dist/preview/{chunk.35KMZHB7.js → chunk.EB7PZJEO.js} +1 -1
  52. package/dist/preview/{chunk.V7H4BUEB.js → chunk.ECNGVD25.js} +1 -1
  53. package/dist/preview/{chunk.B7KZBT27.js → chunk.EGSOHTZZ.js} +1 -1
  54. package/dist/preview/{chunk.OCXY5DCD.js → chunk.EGVM24ND.js} +1 -1
  55. package/dist/preview/{chunk.UDHPMVC4.js → chunk.ENLIIZF2.js} +1 -1
  56. package/dist/preview/{chunk.H3EGBDW2.js → chunk.EP5JS7ZH.js} +1 -1
  57. package/dist/preview/{chunk.TI5FR2QQ.js → chunk.F5GNNVSQ.js} +1 -1
  58. package/dist/preview/chunk.FHQ25SWY.js +1 -0
  59. package/dist/preview/{chunk.F464JKHZ.js → chunk.FSW535EA.js} +1 -1
  60. package/dist/preview/{chunk.G5GVT6JY.js → chunk.FZELUSK5.js} +1 -1
  61. package/dist/preview/{chunk.UWS4RMM3.js → chunk.G2BDEWJC.js} +1 -1
  62. package/dist/preview/chunk.GF3ZCX46.js +2 -0
  63. package/dist/preview/{chunk.UW52CMGJ.js → chunk.GJTEV6CK.js} +1 -1
  64. package/dist/preview/{chunk.A7GVTE5Y.js → chunk.GKTQ5CZA.js} +2 -2
  65. package/dist/preview/{chunk.ZG5VGP5U.js → chunk.GONZB3J3.js} +1 -1
  66. package/dist/preview/{chunk.FLJXYESX.js → chunk.GRBWXTST.js} +1 -1
  67. package/dist/preview/{chunk.Z3O2VZAJ.js → chunk.GRTBEA7O.js} +1 -1
  68. package/dist/preview/{chunk.QNP5OR3P.js → chunk.H3IGXHZR.js} +2 -2
  69. package/dist/preview/{chunk.ILJDLBPJ.js → chunk.H3W5C3XQ.js} +1 -1
  70. package/dist/preview/{chunk.O5VFKVZS.js → chunk.H4VNIAHN.js} +1 -1
  71. package/dist/preview/{chunk.7ARRVNUR.js → chunk.HH4D3JEI.js} +1 -1
  72. package/dist/preview/{chunk.MUSMNKE4.js → chunk.HWFJQ42Y.js} +1 -1
  73. package/dist/preview/{chunk.37RFCHSS.js → chunk.HXTKBISQ.js} +1 -1
  74. package/dist/preview/{chunk.J2OPIS3H.js → chunk.I34BWUB4.js} +1 -1
  75. package/dist/preview/{chunk.ZAPS4J6G.js → chunk.I63462I3.js} +1 -1
  76. package/dist/preview/{chunk.6UQFV53C.js → chunk.IKKKHHRN.js} +1 -1
  77. package/dist/preview/{chunk.GRFD42WM.js → chunk.IPGLITWA.js} +1 -1
  78. package/dist/preview/{chunk.3NSV3WKM.js → chunk.IT5DVKXY.js} +2 -2
  79. package/dist/preview/{chunk.JQ2WNKDW.js → chunk.IXMIU4D4.js} +1 -1
  80. package/dist/preview/{chunk.JVB5KDSG.js → chunk.JCETQQ7J.js} +1 -1
  81. package/dist/preview/{chunk.M7KXQGQL.js → chunk.JGRSUTPJ.js} +1 -1
  82. package/dist/preview/{chunk.KFT7JIEH.js → chunk.JLDJZET2.js} +1 -1
  83. package/dist/preview/{chunk.JQ63N4MZ.js → chunk.JULD4XFB.js} +1 -1
  84. package/dist/preview/{chunk.LVOTLGJB.js → chunk.JV432T4Q.js} +1 -1
  85. package/dist/preview/{chunk.6SJEZWH3.js → chunk.KAM73WVF.js} +1 -1
  86. package/dist/preview/{chunk.AKJS2NUM.js → chunk.KUCBNMIY.js} +1 -1
  87. package/dist/preview/{chunk.DWM7AR5Y.js → chunk.L7XKYGV7.js} +1 -1
  88. package/dist/preview/{chunk.EP6Q32WT.js → chunk.LFFJB6D3.js} +1 -1
  89. package/dist/preview/{chunk.264PB572.js → chunk.LMTG5NPG.js} +1 -1
  90. package/dist/preview/{chunk.EGPCVMDU.js → chunk.LOKGUALC.js} +1 -1
  91. package/dist/preview/{chunk.FPHRAO3R.js → chunk.LZ6MSQ5O.js} +1 -1
  92. package/dist/preview/chunk.MBTEOF4R.js +1 -0
  93. package/dist/preview/{chunk.RJY7VJBH.js → chunk.MIOLBZBS.js} +1 -1
  94. package/dist/preview/{chunk.G3GFDVO2.js → chunk.MK5RPEB2.js} +1 -1
  95. package/dist/preview/{chunk.NSOPYIT4.js → chunk.MKL4THIV.js} +1 -1
  96. package/dist/preview/{chunk.FVQKSN33.js → chunk.MPWLDQOG.js} +1 -1
  97. package/dist/preview/chunk.MSUZAJ2K.js +4 -0
  98. package/dist/preview/{chunk.MSAYU25L.js → chunk.N5Z34V7U.js} +1 -1
  99. package/dist/preview/chunk.N64RVSH3.js +1 -0
  100. package/dist/preview/{chunk.HAOB6O72.js → chunk.ND3DEDWB.js} +1 -1
  101. package/dist/preview/{chunk.GFLH7RCI.js → chunk.NFTPJAMJ.js} +1 -1
  102. package/dist/preview/{chunk.QZQCQWQG.js → chunk.NRCWMYLH.js} +1 -1
  103. package/dist/preview/{chunk.47XEJZ3O.js → chunk.O2VXTYUJ.js} +1 -1
  104. package/dist/preview/{chunk.6N4PE3U5.js → chunk.O32F6LGK.js} +1 -1
  105. package/dist/preview/{chunk.PZ7KY6XH.js → chunk.O5FTWXA2.js} +1 -1
  106. package/dist/preview/{chunk.T2OUHRAA.js → chunk.ODYJEDIW.js} +1 -1
  107. package/dist/preview/{chunk.DKEIEH2D.js → chunk.OQ4ZO3YY.js} +1 -1
  108. package/dist/preview/chunk.PI4RFOBU.js +1 -0
  109. package/dist/preview/{chunk.E5PYNAYT.js → chunk.PIMAG4WT.js} +2 -2
  110. package/dist/preview/{chunk.EFVSZKB5.js → chunk.PLIV3IQK.js} +1 -1
  111. package/dist/preview/{chunk.77C556NM.js → chunk.PPCDPYYU.js} +1 -1
  112. package/dist/preview/{chunk.MW7R5G3C.js → chunk.PZQ5P6WK.js} +1 -1
  113. package/dist/preview/chunk.Q42R2KW4.js +1 -0
  114. package/dist/preview/{chunk.WEMUKZKH.js → chunk.Q4VFLLUT.js} +1 -1
  115. package/dist/preview/{chunk.SY5ID44D.js → chunk.Q6H5HESF.js} +1 -1
  116. package/dist/preview/chunk.QM54TGU6.js +3 -0
  117. package/dist/preview/{chunk.HN4ZJ4B4.js → chunk.QOQ26NXM.js} +1 -1
  118. package/dist/preview/{chunk.SJQPTDAT.js → chunk.QUETLFBJ.js} +1 -1
  119. package/dist/preview/{chunk.P2EKKKK2.js → chunk.QWLK3GKG.js} +1 -1
  120. package/dist/preview/{chunk.JEC5FDKX.js → chunk.QYPU444Y.js} +1 -1
  121. package/dist/preview/{chunk.TXZQEJ5T.js → chunk.QZP3ARLH.js} +1 -1
  122. package/dist/preview/{chunk.WALVW3KJ.js → chunk.R3GE37OI.js} +1 -1
  123. package/dist/preview/chunk.R66ZVMWB.js +1 -0
  124. package/dist/preview/{chunk.YZPESGCP.js → chunk.RQG672MJ.js} +1 -1
  125. package/dist/preview/chunk.RYA7A4NA.js +1 -0
  126. package/dist/preview/{chunk.LRNFE3UK.js → chunk.SADR3MQI.js} +1 -1
  127. package/dist/preview/{chunk.MJY4SLWA.js → chunk.SS6KL5NT.js} +1 -1
  128. package/dist/preview/chunk.SUG6LIOX.js +1 -0
  129. package/dist/preview/{chunk.SO6NT5K7.js → chunk.TFJA4QV4.js} +1 -1
  130. package/dist/preview/{chunk.D4WJ7OM5.js → chunk.TOUSIUJF.js} +1 -1
  131. package/dist/preview/{chunk.ARWO4WOV.js → chunk.TR4YFVZN.js} +1 -1
  132. package/dist/preview/{chunk.XFLGSUYO.js → chunk.TRNJKHIA.js} +1 -1
  133. package/dist/preview/{chunk.5AKZROMR.js → chunk.TVWK3SGD.js} +1 -1
  134. package/dist/preview/chunk.U7PAFLUM.js +1 -0
  135. package/dist/preview/{chunk.NKYWIGC7.js → chunk.UAMPR4MD.js} +1 -1
  136. package/dist/preview/{chunk.UGQYMN4J.js → chunk.UD7VLXPM.js} +1 -1
  137. package/dist/preview/{chunk.UQIPEMJ5.js → chunk.UFURYU4R.js} +1 -1
  138. package/dist/preview/{chunk.R6JBA7UK.js → chunk.UODTUBQ7.js} +1 -1
  139. package/dist/preview/{chunk.NRURQGXV.js → chunk.VES4XMZX.js} +1 -1
  140. package/dist/preview/{chunk.QWGWOEBZ.js → chunk.VLXLBGMY.js} +1 -1
  141. package/dist/preview/{chunk.IDALEKIW.js → chunk.VTDOWXCP.js} +1 -1
  142. package/dist/preview/{chunk.4EMKCKDB.js → chunk.VV5JAM5W.js} +1 -1
  143. package/dist/preview/{chunk.JU6UFWS3.js → chunk.VW632VNJ.js} +1 -1
  144. package/dist/preview/{chunk.25QFDTCU.js → chunk.WC5WE34A.js} +1 -1
  145. package/dist/preview/chunk.WN7SAAH6.js +1 -0
  146. package/dist/preview/{chunk.4UUJHLHR.js → chunk.WV45KLXC.js} +1 -1
  147. package/dist/preview/{chunk.NAXOXBOF.js → chunk.XDZDNZ7B.js} +1 -1
  148. package/dist/preview/{chunk.MAKCZ6B6.js → chunk.XFH6GHBQ.js} +1 -1
  149. package/dist/preview/{chunk.2VUX54XH.js → chunk.XRE7SHLD.js} +1 -1
  150. package/dist/preview/{chunk.J6HF7IRQ.js → chunk.XXCHO2A5.js} +1 -1
  151. package/dist/preview/{chunk.A4EZAGG7.js → chunk.Y7OGJOPA.js} +1 -1
  152. package/dist/preview/{chunk.6NG76MDA.js → chunk.YBQ5GVAX.js} +2 -2
  153. package/dist/preview/{chunk.QF5QB5YR.js → chunk.YL2RBZFE.js} +1 -1
  154. package/dist/preview/{chunk.RSQ432QN.js → chunk.YM6SWEUI.js} +1 -1
  155. package/dist/preview/{chunk.7BJRHPE3.js → chunk.Z2X7BFCB.js} +2 -2
  156. package/dist/preview/{chunk.VBLQJVQ5.js → chunk.Z67LBSQO.js} +1 -1
  157. package/dist/preview/{chunk.OHAO6KKH.js → chunk.ZKXIZBCN.js} +1 -1
  158. package/dist/preview/{chunk.BDNQMKDG.js → chunk.ZLEBOR5T.js} +1 -1
  159. package/dist/preview/{chunk.CKDCTFLU.js → chunk.ZLNUZ6LR.js} +1 -1
  160. package/dist/preview/chunk.ZMADWPJO.js +1 -0
  161. package/dist/preview/chunk.ZO6VMEPP.js +1 -0
  162. package/dist/preview/chunk.ZUG7U7AT.js +1 -0
  163. package/dist/preview/index.html +55 -55
  164. package/dist/preview/page.js +2 -2
  165. package/package.json +6 -6
  166. package/dist/preview/chunk.2FHIINXG.js +0 -2
  167. package/dist/preview/chunk.3ENPWZBG.js +0 -1
  168. package/dist/preview/chunk.3ZODN6BW.js +0 -1
  169. package/dist/preview/chunk.55G4IPOO.js +0 -1
  170. package/dist/preview/chunk.5J6DVR7S.js +0 -1
  171. package/dist/preview/chunk.7WHQWLL6.js +0 -1
  172. package/dist/preview/chunk.B5SJMCTT.js +0 -7
  173. package/dist/preview/chunk.CTUJZ3IV.js +0 -1
  174. package/dist/preview/chunk.CY7FFKEZ.js +0 -1
  175. package/dist/preview/chunk.DEKRFTRN.js +0 -4
  176. package/dist/preview/chunk.EBKH3ILT.js +0 -1
  177. package/dist/preview/chunk.FOUBDGL3.js +0 -1
  178. package/dist/preview/chunk.HB5NWHFP.js +0 -3
  179. package/dist/preview/chunk.HVBKI5ZO.js +0 -1
  180. package/dist/preview/chunk.I3SDKMQS.js +0 -1
  181. package/dist/preview/chunk.J5OLYVZ4.js +0 -1
  182. package/dist/preview/chunk.JKFVNQY7.js +0 -1
  183. package/dist/preview/chunk.KGMSSXZL.js +0 -1
  184. package/dist/preview/chunk.NXZL5CA2.js +0 -1
  185. package/dist/preview/chunk.PSNMZBVS.js +0 -1
  186. package/dist/preview/chunk.R7CRBRD4.js +0 -1
  187. package/dist/preview/chunk.RR25BGWP.js +0 -1
  188. package/dist/preview/chunk.T27QKVKP.js +0 -1
  189. package/dist/preview/chunk.T3WCRS6M.js +0 -1
@@ -1,4 +1,4 @@
1
- var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=globalThis.__graviewPreloaded??=new Set;for(const file of files){const href=new URL(file,base).href;if(asked.has(href))continue;asked.add(href);const link=document.createElement("link");link.rel="modulepreload";link.href=href;document.head.append(link)}};import{c as Ar}from"./chunk.4W57E7AX.js";import{G as O,La as R,P as On,Pa as Vn,Qa as $n,Ra as Dn,Ua as D,W as x,Ya as I,a as ke,e as xe,ea as Se,fa as te,j as Tn,l as De,m as Ie,qa as Rn,s as Hn,v as de,x as Cn,ya as Fn,z as Mn}from"./chunk.A5PSEU3W.js";import{a as M}from"./chunk.SDO3U72B.js";import{$d as xn,Oc as mn,Rc as hn,Vd as ve,Wd as le,Xd as kn,Yc as G,Zc as yn,Zd as $e,_c as wn,ad as vn,ae as Sn,be as re,cd as bn,dd as Ve,eb as gn,ie as Pn,je as Ln,ke as En,la as ye,le as An,ne as Nn,oe as be,pa as we,qa as un,se as Bn,wb as fn}from"./chunk.ZEZUKRC6.js";import{b as w}from"./chunk.AJZBJBMO.js";var We=w(O(),1),Ut=e=>{let n=e??null;for(;n?.parentElement?.closest('[data-testid="context-menu"]');)n=n.parentElement.closest('[data-testid="context-menu"]');let r=n?.getBoundingClientRect();return r&&r.width>0?{left:r.left,top:r.top}:void 0},_e=new WeakMap,Pe=e=>{let n=_e.get(e);return n||_e.set(e,n={open:null,drawn:0,listeners:new Set}),n},Jt=e=>{let n=_e.get(e);n?.preload&&(typeof performance<"u"&&typeof performance.mark=="function"&&performance.mark("graview:quick-ask-preload"),n.preload(),n.preload=void 0)},Nr=e=>{for(let n of[...e.listeners])n()},Br=0;function Xt(e,n){let r=Pe(e);r.open=n?{...n,at:++Br}:null,Nr(r)}var In=e=>n=>{let r=Pe(e);return r.listeners.add(n),()=>void r.listeners.delete(n)};function _n(e){let n=()=>e?Pe(e).drawn>0:!1;return(0,We.useSyncExternalStore)(e?In(e):Tr,n,n)}var Tr=()=>()=>{};function Zt(e){let n=()=>Pe(e).open;return(0,We.useSyncExternalStore)(In(e),n,n)}var _=w(O(),1),Wn=w(Ar(),1);function Hr(e){let[n,r]=(0,_.useState)(null),[t,o]=(0,_.useState)(null);return(0,_.useLayoutEffect)(()=>{e.current!==t&&o(e.current)}),(0,_.useLayoutEffect)(()=>{if(!t||typeof ResizeObserver>"u")return;let i=()=>Math.round(t.getBoundingClientRect().width),s=i();r(s);let p=new ResizeObserver(()=>{let l=i();l!==s&&(s=l,(0,Wn.flushSync)(()=>r(l)))});return p.observe(t),()=>p.disconnect()},[t]),n}function Cr(e=!0){let[n,r]=(0,_.useState)();return(0,_.useEffect)(()=>{if(!e)return r(void 0);let t=0,o=()=>r(innerHeight),i=()=>{o(),clearTimeout(t),t=window.setTimeout(o,300)},s=p=>{for(let[l,d]of[[window,"resize"],[window,"orientationchange"],[window.visualViewport,"resize"]])l?.[p](d,i)};return s("addEventListener"),o(),()=>{clearTimeout(t),s("removeEventListener")}},[e]),n}var Le={position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(50%)",whiteSpace:"nowrap"};var L=w(O(),1);var N=w(x(),1),zn=6e3;function Mr(e){return{...e,notify:n=>e.notify({...n,from:"framework"})}}var Or=e=>({place:"overview",...e&&!/^(aggregate|kind):/.test(e)?{record:e}:{}});function Rr(){let e=[],n=0,r=new Set,t=new Map,o,i=()=>{for(let d of[...r])d()},s=d=>{if(clearTimeout(t.get(d.id)),t.delete(d.id),d.kind!=="toast")return;let u=(d.actions?.length??0)+(d.action?1:0),g=d.timeout??(u>0?!1:zn);g!==!1&&t.set(d.id,setTimeout(()=>o?.()?s(d):p(d.id),g))},p=d=>{clearTimeout(t.get(d)),t.delete(d),e.some(u=>u.id===d)&&(e=e.filter(u=>u.id!==d),i())},l=d=>{e=e.some(u=>u.id===d.id)?e.map(u=>u.id===d.id?d:u):[...e,d],s(d),i()};return{notify(d){let u=d.id??`notice-${++n}`;return l({...d,id:u,said:++n}),{id:u,dismiss:()=>p(u),update:g=>{let c=e.find(y=>y.id===u);c&&l({...c,...g,id:u,kind:c.kind,said:g.sentence!==void 0&&g.sentence!==c.sentence?++n:c.said})}}},dismiss:p,hold(d){o=d},list:()=>e,subscribe(d){return r.add(d),()=>r.delete(d)}}}function Fr({notices:e}){let n=e.reduce((p,l)=>!p||l.said>p.said?l:p,void 0),[r,t]=(0,L.useState)(""),[o,i]=(0,L.useState)(""),s=(0,L.useRef)(0);return(0,L.useEffect)(()=>{if(!n||n.said===s.current)return;s.current=n.said;let p=n.tone==="bad";(p?i:t)("");let l=setTimeout(()=>(p?i:t)(n.sentence),50);return()=>clearTimeout(l)},[n]),(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)("div",{role:"status","aria-live":"polite","data-testid":"notices-said",style:Le,children:r}),(0,N.jsx)("div",{role:"alert","data-testid":"notices-alarm",style:Le,children:o})]})}var Vr=(0,L.createContext)(null);function $r({board:e,anchor:n,report:r}){let t=(0,L.useSyncExternalStore)(e.subscribe,e.list,e.list);return(0,L.useEffect)(()=>_r(ze.prefetch),[]),(0,N.jsxs)(N.Fragment,{children:[t.length>0?(0,N.jsx)(L.Suspense,{fallback:null,children:(0,N.jsx)(Ir,{notices:t,anchor:n,board:e,...r?{report:r}:{}})}):null,(0,N.jsx)(Fr,{notices:t})]})}var ze=R(M(()=>(__graviewPreload(import.meta.url,["./chunk.MB7LKKUD.js","./chunk.QNP5OR3P.js","./chunk.4W57E7AX.js","./chunk.A5PSEU3W.js","./chunk.SDO3U72B.js","./chunk.ZEZUKRC6.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.JU6UFWS3.js")))),Dr=()=>ze.load().then(()=>{},()=>{}),Ir=ze.part((e,n)=>(0,N.jsx)(e.NoticeStacks,{...n}),{quiet:!0});function _r(e){let n=()=>{(typeof navigator>"u"||navigator.onLine!==!1)&&e()},r=globalThis;if(r.requestIdleCallback){let o=r.requestIdleCallback(n,{timeout:5e3});return()=>r.cancelIdleCallback?.(o)}let t=setTimeout(n,2500);return()=>clearTimeout(t)}var E=R(M(()=>(__graviewPreload(import.meta.url,["./chunk.NKYWIGC7.js","./chunk.6UQFV53C.js","./chunk.T2OUHRAA.js","./chunk.GRFD42WM.js","./chunk.EP6Q32WT.js","./chunk.U5P23GO7.js","./chunk.HJUZMOW2.js","./chunk.NAXOXBOF.js","./chunk.6W6XMLSF.js","./chunk.PZ7KY6XH.js","./chunk.WEMUKZKH.js","./chunk.T27QKVKP.js","./chunk.EGPCVMDU.js","./chunk.MIE4TJRW.js","./chunk.QRQ5WPZI.js","./chunk.RD2FSSLV.js","./chunk.37RFCHSS.js","./chunk.SO6NT5K7.js","./chunk.MUSMNKE4.js","./chunk.SJQPTDAT.js","./chunk.JQ63N4MZ.js","./chunk.Z3O2VZAJ.js","./chunk.QNP5OR3P.js","./chunk.4W57E7AX.js","./chunk.A5PSEU3W.js","./chunk.SDO3U72B.js","./chunk.ZEZUKRC6.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.7BJRHPE3.js"))));var h=w(O(),1);var Ke=e=>Math.round(e).toString(16).padStart(2,"0");function Kn(e){let n=r=>{let t=e?.schemes?.[r]?.ground,o=t?mn(t)[0]:void 0;return o?`#${Ke(o.r)}${Ke(o.g)}${Ke(o.b)}`:void 0};if(e?.scheme==="light"||e?.scheme==="dark"){let r=n(e.scheme);return r?[{color:r}]:[]}return["light","dark"].flatMap(r=>{let t=n(r);return t?[{color:t,media:`(prefers-color-scheme: ${r})`}]:[]})}var je=w(O(),1);var jn=w(O(),1);function ce(e){return(0,jn.useMemo)(()=>e===void 0||e===""?void 0:{__html:e},[e])}var q=w(x(),1);function Ge({brand:e,size:n=22}){let r=On(),t=vn(e),o=Gn(t?.light),i=o?Gn(t?.dark):void 0,s=ce(o!==void 0&&G(o)?o:void 0),p=ce(i!==void 0&&G(i)?i:void 0),l={display:"inline-flex",flex:"0 0 auto",height:n,color:"var(--graview-accent)"},d=bn(e);if(d)return(0,q.jsx)("span",{className:"graview-logo graview-emoji-mark","data-testid":"app-mark","aria-hidden":!0,style:{...l,alignItems:"center",fontSize:`${n*.86/16}rem`,lineHeight:1},children:d});if(!o)return null;let u=e?.logoAlt??e?.name??"",g=u!==""&&u!==e?.name,c=g?{role:"img","aria-label":u}:{"aria-hidden":!0};if(i){let b=(S,v,T)=>G(S)?(0,q.jsx)("span",{className:"graview-logo-face","data-graview-scheme-only":T,dangerouslySetInnerHTML:v}):(0,q.jsx)("img",{className:"graview-logo-face","data-graview-scheme-only":T,src:Ve(r,S),alt:""});return(0,q.jsxs)("span",{className:"graview-logo","data-testid":"app-mark",style:l,...c,children:[b(o,s,"light"),b(i,p,"dark")]})}let y=t?.darkFallback==="invert"?{"data-graview-logo-fallback":"invert"}:{};return G(o)?(0,q.jsx)("span",{className:"graview-logo","data-testid":"app-mark",style:l,...y,...c,dangerouslySetInnerHTML:s}):(0,q.jsx)("img",{className:"graview-logo","data-testid":"app-mark",src:Ve(r,o),alt:g?u:"",...y,style:{...l,width:"auto"}})}function Gn(e){if(!(!e||!wn(e)))return G(e)&&yn(e)!==null?void 0:e}function Wr(e){(0,je.useEffect)(()=>{if(!e||typeof document>"u")return;let n=[...document.querySelectorAll('link[rel~="icon"]')],r=n.map(o=>o.getAttribute("href")),t;n.length===0&&(t=document.createElement("link"),t.rel="icon",t.setAttribute("data-graview-favicon",""),document.head.appendChild(t),n.push(t));for(let o of n)o.href=e;return()=>{t&&t.remove(),n.forEach((o,i)=>{o!==t&&r[i]!==null&&r[i]!==void 0&&o.setAttribute("href",r[i])})}},[e])}function zr(e){let n=e?JSON.stringify(Kn(e)):"[]";(0,je.useEffect)(()=>{let r=JSON.parse(n);if(r.length===0||typeof document>"u")return;let t=[...document.head.querySelectorAll('meta[name="theme-color"]:not([data-graview-theme-color])')];t.forEach(i=>i.setAttribute("name","graview-theme-color-held"));let o=r.map(({color:i,media:s})=>{let p=document.createElement("meta");return p.name="theme-color",p.content=i,s&&(p.media=s),p.setAttribute("data-graview-theme-color",""),document.head.appendChild(p),p});return()=>{o.forEach(i=>i.remove()),t.forEach(i=>i.setAttribute("name","theme-color"))}},[n])}var a=w(x(),1),Kr=E.part((e,n)=>(0,a.jsx)(e.TidyFoot,{...n}),{quiet:!0}),jr=E.part((e,n)=>(0,a.jsx)(e.AppMenuPane,{...n}),{what:"The app menu"}),Gr=E.part((e,n)=>(0,a.jsx)(e.Here,{...n}),{quiet:!0});function qr(){let e=te(),[n,r]=(0,h.useState)("");return(0,h.useEffect)(()=>e?.store.subscribe((t,o)=>{o.some(i=>i.author.id!==e.principal.id)&&E.load().then(i=>i.sayTheirChange(o,e,r),String)}),[e]),(0,a.jsx)("span",{role:"status",className:"graview-bar-said",children:n})}var Qn="home",Un="/",Z="scene:whole";function Yr(e){let{store:n,principal:r,views:t}=e,o=n.kindsKeptFrom(r),i=n.schema.kinds.filter(f=>!n.modules.disabledKinds.has(f)&&!o.has(f)),s=t?.arrangement?.(),p=t?.places()??[],l=An(s,n.schema,p),d=En(n.schema,s,[...n.modules.administered.values()].flatMap(f=>f.kinds??[])),u=(f,P)=>(!n.graph.size.nodes||n.graph.count(f)>0)&&(l?P?l.places.has(`${f}|${P}`):l.kinds.has(f):!d.has(f)),g=[{key:Qn,label:"Home",path:Un,group:"home",primary:!0}],c=p.filter(f=>i.includes(f.kind)&&f.as!==Nn),y=c.filter(f=>!f.hidden),b=new Set(le(y).map(f=>re(f,p,n.schema).toLowerCase())),S=f=>xn(f.as,Sn(f,p)?$e(n.schema,f.kind).slice(1):void 0),v=new Set(s?.hide??[]),T=Bn(i,s?.order,y);for(let{kind:f,view:P}of T){if(P){g.push({key:`place:${P.kind}:${P.as}`,label:re(P,p,n.schema),path:S(P),group:"lists",kind:f,primary:l?l.places.has(`${f}|${P.as}`):!0});continue}let z=we(n.schema,f),B=b.has(z.toLowerCase());g.push({key:`kind:${f}`,label:B?un(n.schema,f):z,path:$e(n.schema,f),group:"lists",kind:f,primary:B||v.has(f)?!1:u(f),...v.has(f)?{hidden:!0}:{}})}for(let f of le(c)){if(T.some(B=>B.view&&ve(B.view,f)))continue;let P=S(f),z=[f.kind,...f.over??[]].some(B=>i.includes(B)&&u(B,f.as));g.some(B=>B.path===P)||g.push({key:`place:${f.kind}:${f.as}`,label:re(f,p,n.schema),path:P,group:"pictures",kind:f.kind,primary:z,hidden:f.hidden})}return i.some(f=>Object.keys(n.schema.tryDefinition(f)?.edges??{}).length>0)&&g.push({key:"connections",label:"Connections",path:"/map",group:"pictures",primary:!1}),g}function Qr(e,n){let[r="/",t=""]=n.split("?"),o=e.find(s=>s.path===(t?`${r}?${t}`:r))??e.find(s=>s.path===r);if(o)return o.key;let i=`/${r.split("/").filter(Boolean)[0]??""}`;return e.find(s=>s.group==="lists"&&s.path===i)?.key??null}var Jn=(0,h.createContext)(null),Ur=()=>(0,h.useContext)(Jn),V=30,Xn=48,pe=640,Zn=900,Qe=4,qe=2;function er(e){let{widths:n,current:r,room:t,more:o,gap:i=Qe,primary:s,most:p=Ln}=e;if(n.length===0||!(t>0)||!(o>0)||n.some(g=>!(g>0)))return null;let l=(g,c)=>g.reduce((y,b)=>y+n[b],0)+i*Math.max(0,g.length-1)+(c?i+o:0),d=(g,c)=>r<0||!g.includes(r)||g.slice(0,c).includes(r)?g.slice(0,c):[...g.filter(y=>y!==r).slice(0,c-1),r].sort((y,b)=>y-b),u=d(n.map((g,c)=>c).filter(g=>s?.[g]!==!1||g===r),p);if(l(u,u.length<n.length)<=t)return u.length>=qe?u:null;for(let g=u.length-1;g>=qe;g--){let c=d(u,g);if(l(c,!0)<=t)return c}return null}var Jr=`
1
+ var __graviewPreload=(base,files)=>{if(typeof document>"u")return;const asked=globalThis.__graviewPreloaded??=new Set;for(const file of files){const href=new URL(file,base).href;if(asked.has(href))continue;asked.add(href);const link=document.createElement("link");link.rel="modulepreload";link.href=href;document.head.append(link)}};import{c as Ar}from"./chunk.7TDML5YU.js";import{G as O,La as R,P as On,Pa as Vn,Qa as $n,Ra as Dn,Ua as D,W as x,Ya as I,a as ke,e as xe,ea as Se,fa as te,j as Tn,l as De,m as Ie,qa as Rn,s as Hn,v as de,x as Cn,ya as Fn,z as Mn}from"./chunk.3VEZ5MOC.js";import{a as M}from"./chunk.SDO3U72B.js";import{$d as xn,Oc as mn,Rc as hn,Vd as ve,Wd as le,Xd as kn,Yc as G,Zc as yn,Zd as $e,_c as wn,ad as vn,ae as Sn,be as re,cd as bn,dd as Ve,eb as gn,ie as Pn,je as Ln,ke as En,la as ye,le as An,ne as Nn,oe as be,pa as we,qa as un,se as Bn,wb as fn}from"./chunk.6AANHELP.js";import{b as w}from"./chunk.AJZBJBMO.js";var We=w(O(),1),Ut=e=>{let n=e??null;for(;n?.parentElement?.closest('[data-testid="context-menu"]');)n=n.parentElement.closest('[data-testid="context-menu"]');let r=n?.getBoundingClientRect();return r&&r.width>0?{left:r.left,top:r.top}:void 0},_e=new WeakMap,Pe=e=>{let n=_e.get(e);return n||_e.set(e,n={open:null,drawn:0,listeners:new Set}),n},Jt=e=>{let n=_e.get(e);n?.preload&&(typeof performance<"u"&&typeof performance.mark=="function"&&performance.mark("graview:quick-ask-preload"),n.preload(),n.preload=void 0)},Nr=e=>{for(let n of[...e.listeners])n()},Br=0;function Xt(e,n){let r=Pe(e);r.open=n?{...n,at:++Br}:null,Nr(r)}var In=e=>n=>{let r=Pe(e);return r.listeners.add(n),()=>void r.listeners.delete(n)};function _n(e){let n=()=>e?Pe(e).drawn>0:!1;return(0,We.useSyncExternalStore)(e?In(e):Tr,n,n)}var Tr=()=>()=>{};function Zt(e){let n=()=>Pe(e).open;return(0,We.useSyncExternalStore)(In(e),n,n)}var _=w(O(),1),Wn=w(Ar(),1);function Hr(e){let[n,r]=(0,_.useState)(null),[t,o]=(0,_.useState)(null);return(0,_.useLayoutEffect)(()=>{e.current!==t&&o(e.current)}),(0,_.useLayoutEffect)(()=>{if(!t||typeof ResizeObserver>"u")return;let i=()=>Math.round(t.getBoundingClientRect().width),s=i();r(s);let p=new ResizeObserver(()=>{let l=i();l!==s&&(s=l,(0,Wn.flushSync)(()=>r(l)))});return p.observe(t),()=>p.disconnect()},[t]),n}function Cr(e=!0){let[n,r]=(0,_.useState)();return(0,_.useEffect)(()=>{if(!e)return r(void 0);let t=0,o=()=>r(innerHeight),i=()=>{o(),clearTimeout(t),t=window.setTimeout(o,300)},s=p=>{for(let[l,d]of[[window,"resize"],[window,"orientationchange"],[window.visualViewport,"resize"]])l?.[p](d,i)};return s("addEventListener"),o(),()=>{clearTimeout(t),s("removeEventListener")}},[e]),n}var Le={position:"absolute",width:1,height:1,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(50%)",whiteSpace:"nowrap"};var L=w(O(),1);var N=w(x(),1),zn=6e3;function Mr(e){return{...e,notify:n=>e.notify({...n,from:"framework"})}}var Or=e=>({place:"overview",...e&&!/^(aggregate|kind):/.test(e)?{record:e}:{}});function Rr(){let e=[],n=0,r=new Set,t=new Map,o,i=()=>{for(let d of[...r])d()},s=d=>{if(clearTimeout(t.get(d.id)),t.delete(d.id),d.kind!=="toast")return;let u=(d.actions?.length??0)+(d.action?1:0),g=d.timeout??(u>0?!1:zn);g!==!1&&t.set(d.id,setTimeout(()=>o?.()?s(d):p(d.id),g))},p=d=>{clearTimeout(t.get(d)),t.delete(d),e.some(u=>u.id===d)&&(e=e.filter(u=>u.id!==d),i())},l=d=>{e=e.some(u=>u.id===d.id)?e.map(u=>u.id===d.id?d:u):[...e,d],s(d),i()};return{notify(d){let u=d.id??`notice-${++n}`;return l({...d,id:u,said:++n}),{id:u,dismiss:()=>p(u),update:g=>{let c=e.find(y=>y.id===u);c&&l({...c,...g,id:u,kind:c.kind,said:g.sentence!==void 0&&g.sentence!==c.sentence?++n:c.said})}}},dismiss:p,hold(d){o=d},list:()=>e,subscribe(d){return r.add(d),()=>r.delete(d)}}}function Fr({notices:e}){let n=e.reduce((p,l)=>!p||l.said>p.said?l:p,void 0),[r,t]=(0,L.useState)(""),[o,i]=(0,L.useState)(""),s=(0,L.useRef)(0);return(0,L.useEffect)(()=>{if(!n||n.said===s.current)return;s.current=n.said;let p=n.tone==="bad";(p?i:t)("");let l=setTimeout(()=>(p?i:t)(n.sentence),50);return()=>clearTimeout(l)},[n]),(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)("div",{role:"status","aria-live":"polite","data-testid":"notices-said",style:Le,children:r}),(0,N.jsx)("div",{role:"alert","data-testid":"notices-alarm",style:Le,children:o})]})}var Vr=(0,L.createContext)(null);function $r({board:e,anchor:n,report:r}){let t=(0,L.useSyncExternalStore)(e.subscribe,e.list,e.list);return(0,L.useEffect)(()=>_r(ze.prefetch),[]),(0,N.jsxs)(N.Fragment,{children:[t.length>0?(0,N.jsx)(L.Suspense,{fallback:null,children:(0,N.jsx)(Ir,{notices:t,anchor:n,board:e,...r?{report:r}:{}})}):null,(0,N.jsx)(Fr,{notices:t})]})}var ze=R(M(()=>(__graviewPreload(import.meta.url,["./chunk.MB7LKKUD.js","./chunk.H3IGXHZR.js","./chunk.7TDML5YU.js","./chunk.3VEZ5MOC.js","./chunk.SDO3U72B.js","./chunk.6AANHELP.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.VW632VNJ.js")))),Dr=()=>ze.load().then(()=>{},()=>{}),Ir=ze.part((e,n)=>(0,N.jsx)(e.NoticeStacks,{...n}),{quiet:!0});function _r(e){let n=()=>{(typeof navigator>"u"||navigator.onLine!==!1)&&e()},r=globalThis;if(r.requestIdleCallback){let o=r.requestIdleCallback(n,{timeout:5e3});return()=>r.cancelIdleCallback?.(o)}let t=setTimeout(n,2500);return()=>clearTimeout(t)}var E=R(M(()=>(__graviewPreload(import.meta.url,["./chunk.UAMPR4MD.js","./chunk.IKKKHHRN.js","./chunk.ODYJEDIW.js","./chunk.IPGLITWA.js","./chunk.LFFJB6D3.js","./chunk.U5P23GO7.js","./chunk.DCLF4WWZ.js","./chunk.XDZDNZ7B.js","./chunk.E423JCOS.js","./chunk.O5FTWXA2.js","./chunk.Q4VFLLUT.js","./chunk.6ZENHSTQ.js","./chunk.LOKGUALC.js","./chunk.MIE4TJRW.js","./chunk.CFE3MHWZ.js","./chunk.RD2FSSLV.js","./chunk.HXTKBISQ.js","./chunk.TFJA4QV4.js","./chunk.HWFJQ42Y.js","./chunk.QUETLFBJ.js","./chunk.JULD4XFB.js","./chunk.GRTBEA7O.js","./chunk.H3IGXHZR.js","./chunk.7TDML5YU.js","./chunk.3VEZ5MOC.js","./chunk.SDO3U72B.js","./chunk.6AANHELP.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.Z2X7BFCB.js"))));var h=w(O(),1);var Ke=e=>Math.round(e).toString(16).padStart(2,"0");function Kn(e){let n=r=>{let t=e?.schemes?.[r]?.ground,o=t?mn(t)[0]:void 0;return o?`#${Ke(o.r)}${Ke(o.g)}${Ke(o.b)}`:void 0};if(e?.scheme==="light"||e?.scheme==="dark"){let r=n(e.scheme);return r?[{color:r}]:[]}return["light","dark"].flatMap(r=>{let t=n(r);return t?[{color:t,media:`(prefers-color-scheme: ${r})`}]:[]})}var je=w(O(),1);var jn=w(O(),1);function ce(e){return(0,jn.useMemo)(()=>e===void 0||e===""?void 0:{__html:e},[e])}var q=w(x(),1);function Ge({brand:e,size:n=22}){let r=On(),t=vn(e),o=Gn(t?.light),i=o?Gn(t?.dark):void 0,s=ce(o!==void 0&&G(o)?o:void 0),p=ce(i!==void 0&&G(i)?i:void 0),l={display:"inline-flex",flex:"0 0 auto",height:n,color:"var(--graview-accent)"},d=bn(e);if(d)return(0,q.jsx)("span",{className:"graview-logo graview-emoji-mark","data-testid":"app-mark","aria-hidden":!0,style:{...l,alignItems:"center",fontSize:`${n*.86/16}rem`,lineHeight:1},children:d});if(!o)return null;let u=e?.logoAlt??e?.name??"",g=u!==""&&u!==e?.name,c=g?{role:"img","aria-label":u}:{"aria-hidden":!0};if(i){let b=(S,v,T)=>G(S)?(0,q.jsx)("span",{className:"graview-logo-face","data-graview-scheme-only":T,dangerouslySetInnerHTML:v}):(0,q.jsx)("img",{className:"graview-logo-face","data-graview-scheme-only":T,src:Ve(r,S),alt:""});return(0,q.jsxs)("span",{className:"graview-logo","data-testid":"app-mark",style:l,...c,children:[b(o,s,"light"),b(i,p,"dark")]})}let y=t?.darkFallback==="invert"?{"data-graview-logo-fallback":"invert"}:{};return G(o)?(0,q.jsx)("span",{className:"graview-logo","data-testid":"app-mark",style:l,...y,...c,dangerouslySetInnerHTML:s}):(0,q.jsx)("img",{className:"graview-logo","data-testid":"app-mark",src:Ve(r,o),alt:g?u:"",...y,style:{...l,width:"auto"}})}function Gn(e){if(!(!e||!wn(e)))return G(e)&&yn(e)!==null?void 0:e}function Wr(e){(0,je.useEffect)(()=>{if(!e||typeof document>"u")return;let n=[...document.querySelectorAll('link[rel~="icon"]')],r=n.map(o=>o.getAttribute("href")),t;n.length===0&&(t=document.createElement("link"),t.rel="icon",t.setAttribute("data-graview-favicon",""),document.head.appendChild(t),n.push(t));for(let o of n)o.href=e;return()=>{t&&t.remove(),n.forEach((o,i)=>{o!==t&&r[i]!==null&&r[i]!==void 0&&o.setAttribute("href",r[i])})}},[e])}function zr(e){let n=e?JSON.stringify(Kn(e)):"[]";(0,je.useEffect)(()=>{let r=JSON.parse(n);if(r.length===0||typeof document>"u")return;let t=[...document.head.querySelectorAll('meta[name="theme-color"]:not([data-graview-theme-color])')];t.forEach(i=>i.setAttribute("name","graview-theme-color-held"));let o=r.map(({color:i,media:s})=>{let p=document.createElement("meta");return p.name="theme-color",p.content=i,s&&(p.media=s),p.setAttribute("data-graview-theme-color",""),document.head.appendChild(p),p});return()=>{o.forEach(i=>i.remove()),t.forEach(i=>i.setAttribute("name","theme-color"))}},[n])}var a=w(x(),1),Kr=E.part((e,n)=>(0,a.jsx)(e.TidyFoot,{...n}),{quiet:!0}),jr=E.part((e,n)=>(0,a.jsx)(e.AppMenuPane,{...n}),{what:"The app menu"}),Gr=E.part((e,n)=>(0,a.jsx)(e.Here,{...n}),{quiet:!0});function qr(){let e=te(),[n,r]=(0,h.useState)("");return(0,h.useEffect)(()=>e?.store.subscribe((t,o)=>{o.some(i=>i.author.id!==e.principal.id)&&E.load().then(i=>i.sayTheirChange(o,e,r),String)}),[e]),(0,a.jsx)("span",{role:"status",className:"graview-bar-said",children:n})}var Qn="home",Un="/",Z="scene:whole";function Yr(e){let{store:n,principal:r,views:t}=e,o=n.kindsKeptFrom(r),i=n.schema.kinds.filter(f=>!n.modules.disabledKinds.has(f)&&!o.has(f)),s=t?.arrangement?.(),p=t?.places()??[],l=An(s,n.schema,p),d=En(n.schema,s,[...n.modules.administered.values()].flatMap(f=>f.kinds??[])),u=(f,P)=>(!n.graph.size.nodes||n.graph.count(f)>0)&&(l?P?l.places.has(`${f}|${P}`):l.kinds.has(f):!d.has(f)),g=[{key:Qn,label:"Home",path:Un,group:"home",primary:!0}],c=p.filter(f=>i.includes(f.kind)&&f.as!==Nn),y=c.filter(f=>!f.hidden),b=new Set(le(y).map(f=>re(f,p,n.schema).toLowerCase())),S=f=>xn(f.as,Sn(f,p)?$e(n.schema,f.kind).slice(1):void 0),v=new Set(s?.hide??[]),T=Bn(i,s?.order,y);for(let{kind:f,view:P}of T){if(P){g.push({key:`place:${P.kind}:${P.as}`,label:re(P,p,n.schema),path:S(P),group:"lists",kind:f,primary:l?l.places.has(`${f}|${P.as}`):!0});continue}let z=we(n.schema,f),B=b.has(z.toLowerCase());g.push({key:`kind:${f}`,label:B?un(n.schema,f):z,path:$e(n.schema,f),group:"lists",kind:f,primary:B||v.has(f)?!1:u(f),...v.has(f)?{hidden:!0}:{}})}for(let f of le(c)){if(T.some(B=>B.view&&ve(B.view,f)))continue;let P=S(f),z=[f.kind,...f.over??[]].some(B=>i.includes(B)&&u(B,f.as));g.some(B=>B.path===P)||g.push({key:`place:${f.kind}:${f.as}`,label:re(f,p,n.schema),path:P,group:"pictures",kind:f.kind,primary:z,hidden:f.hidden})}return i.some(f=>Object.keys(n.schema.tryDefinition(f)?.edges??{}).length>0)&&g.push({key:"connections",label:"Connections",path:"/map",group:"pictures",primary:!1}),g}function Qr(e,n){let[r="/",t=""]=n.split("?"),o=e.find(s=>s.path===(t?`${r}?${t}`:r))??e.find(s=>s.path===r);if(o)return o.key;let i=`/${r.split("/").filter(Boolean)[0]??""}`;return e.find(s=>s.group==="lists"&&s.path===i)?.key??null}var Jn=(0,h.createContext)(null),Ur=()=>(0,h.useContext)(Jn),V=30,Xn=48,pe=640,Zn=900,Qe=4,qe=2;function er(e){let{widths:n,current:r,room:t,more:o,gap:i=Qe,primary:s,most:p=Ln}=e;if(n.length===0||!(t>0)||!(o>0)||n.some(g=>!(g>0)))return null;let l=(g,c)=>g.reduce((y,b)=>y+n[b],0)+i*Math.max(0,g.length-1)+(c?i+o:0),d=(g,c)=>r<0||!g.includes(r)||g.slice(0,c).includes(r)?g.slice(0,c):[...g.filter(y=>y!==r).slice(0,c-1),r].sort((y,b)=>y-b),u=d(n.map((g,c)=>c).filter(g=>s?.[g]!==!1||g===r),p);if(l(u,u.length<n.length)<=t)return u.length>=qe?u:null;for(let g=u.length-1;g>=qe;g--){let c=d(u,g);if(l(c,!0)<=t)return c}return null}var Jr=`
2
2
  .graview-bar{display:block;margin:0;padding:0;container:graview-bar/inline-size;flex:0 0 auto;position:relative;background:var(--graview-bar);border-bottom:1px solid var(--graview-edge);color:var(--graview-ink);font-family:var(--graview-font-body,system-ui)}
3
3
  .graview-bar-row{display:flex;flex-wrap:nowrap;align-items:center;gap:16px;height:${Xn-1}px;margin:0;padding:0 16px}
4
4
  .graview-bar-home,.graview-bar-place,.graview-bar-item,.graview-bar-at{display:inline-flex;align-items:center;box-sizing:border-box;min-width:0;margin:0;border:0;background:none;box-shadow:none;font:inherit;letter-spacing:normal;text-transform:none;text-decoration:none;color:var(--graview-ink);cursor:pointer;text-align:left}
@@ -90,4 +90,4 @@ a.graview-bar-status{cursor:pointer}
90
90
  @container graview-bar (max-width: 300px){
91
91
  .graview-bar-row{gap:4px;padding:0 10px}
92
92
  }`,ae={display:"inline-flex",alignItems:"center",justifyContent:"center",gap:6,minWidth:V,height:V,padding:0,borderRadius:8,border:"1px solid transparent",background:"none",boxShadow:"none",color:"var(--graview-ink-muted)",font:"inherit",fontSize:"0.875rem",cursor:"pointer",flex:"0 0 auto"};function Xr({brand:e,name:n,heading:r=1,home:t,faces:o,places:i,current:s,reach:p,tools:l,find:d=!0,description:u,findBox:g,onFind:c,scenePlaces:y,skips:b,named:S=!0,actions:v,appMenu:T=Zr,scheme:ge,share:f,status:P}){let z=(0,h.useRef)(null),B=te()?.who.size,[ie,ur]=(0,h.useState)(null),[tn,gr]=(0,h.useState)(null),[K,fr]=(0,h.useState)(!1),[ee,mr]=(0,h.useState)(!1),[hr,an]=(0,h.useState)(!1),[on,yr]=(0,h.useState)(null),[wr,vr]=(0,h.useState)(!0),fe=o?o.pages.current:!y,se=fe?{places:i,current:s,reach:p}:y,Me=se&&{...se,places:kn(se.places),here:se.places.find(m=>m.key===se.current)?.label},k=Me&&Me.places.length>0?Me:null,Oe=k?k.places.findIndex(m=>m.key===k.current):-1,sn=k?k.places.map(m=>m.primary===!1?"0":"1").join(""):"",j=(0,h.useCallback)(()=>{let m=z.current;if(!m)return;let H=ft(m,Oe,sn);H!==void 0&&yr(H)},[Oe,sn]);(0,h.useLayoutEffect)(()=>{let m=z.current;if(!m)return;let H=()=>{let C=m.getBoundingClientRect().width;fr(C<pe),mr(C<Zn);let Er=m.querySelector("[data-graview-bar-host-ruler]");vr(C>=pe+(Er?.getBoundingClientRect().width??0)),m.style.setProperty("--graview-bar-width",`${Math.round(C)}px`),j()};H();let J=typeof document>"u"?void 0:document.fonts;if(J?.ready.then(j),J?.addEventListener?.("loadingdone",j),typeof ResizeObserver>"u")return()=>J?.removeEventListener?.("loadingdone",j);let X=new ResizeObserver(H);X.observe(m);for(let C of m.querySelectorAll(".graview-bar-tools > *"))X.observe(C);let ne=m.querySelector(".graview-bar-tools"),$=typeof MutationObserver>"u"||!ne?null:new MutationObserver(()=>{for(let C of ne.children)X.observe(C)});return $?.observe(ne,{childList:!0}),()=>{$?.disconnect(),X.disconnect(),J?.removeEventListener?.("loadingdone",j)}},[j]);let Re=(0,h.useRef)(c);Re.current=c,(0,h.useLayoutEffect)(()=>{Re.current?.(d&&ie?{slot:ie,compact:ee,own:tn}:null)},[d,ie,ee,tn]),(0,h.useLayoutEffect)(()=>()=>Re.current?.(null),[]);let br=(0,h.useCallback)(()=>{an(!0),requestAnimationFrame(()=>ie?.querySelector("input")?.focus())},[ie]),ln=(0,h.useRef)(null),me=(0,h.useRef)(!1),Fe=(0,h.useCallback)(()=>{an(!1),me.current&&(me.current=!1,requestAnimationFrame(()=>ln.current?.focus()))},[]),dn=(0,h.useRef)(null);(0,h.useEffect)(()=>{let m=dn.current;if(!m||!ee)return;let H=()=>!!m.querySelector("input")?.value,J=$=>{let C=$.relatedTarget;C instanceof Node&&m.contains(C)||H()||Fe()},X=$=>{$.key==="Escape"&&(me.current=!0)},ne=$=>{$.key==="Escape"&&queueMicrotask(()=>{!$.defaultPrevented||!H()?Fe():me.current=!1})};return m.addEventListener("focusout",J),m.addEventListener("keydown",X,!0),m.addEventListener("keydown",ne),()=>{m.removeEventListener("focusout",J),m.removeEventListener("keydown",X,!0),m.removeEventListener("keydown",ne)}},[ee,Fe]);let kr=r===!1?"span":`h${r}`,xr=t.href!==void 0?"a":"button",Sr=m=>H=>{!m||!rr(H)||(H.preventDefault(),m())},Pr=!fe,cn=k&&!K&&on!==null&&!(Oe<0&&k.here)?on.split(",").map(Number).filter(m=>m<k.places.length):null,he=k?(0,a.jsx)(ut,{places:k.places,current:k.current,here:k.here,reach:k.reach,scene:Pr,stands:cn}):null,Lr=k?k.places.map(m=>m.label).join(`
93
- `):"";(0,h.useLayoutEffect)(j,[j,n,e,Lr,k?.current,fe,K,ee,d]);let pn=!!o||T.length>0||!!ge;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("header",{ref:z,className:"graview-bar","data-testid":"app-bar","data-graview-app-bar":"",...hr&&ee?{"data-finding":""}:{},children:[(0,a.jsx)("style",{children:Jr}),b,(0,a.jsxs)("div",{className:"graview-bar-row",children:[S?(0,a.jsxs)("div",{className:"graview-bar-app",children:[(0,a.jsx)(kr,{className:"graview-bar-name",children:(0,a.jsxs)(xr,{...t.href!==void 0?{href:t.href,onClick:Sr(t.go)}:{type:"button",onClick:t.go},"data-testid":"app-home",...t.current?{"aria-current":"page"}:{},title:u?`${n} \u2014 ${u}`:`${n} \u2014 home`,className:"graview-bar-home",children:[(0,a.jsx)(Ge,{brand:e,size:20}),(0,a.jsx)("span",{className:"graview-bar-app-name","data-testid":"app-name",children:n})]})}),pn?(0,a.jsx)(qn,{name:n,faces:o,rows:T,scheme:ge}):null]}):pn?(0,a.jsx)(qn,{name:n,faces:o,rows:T,scheme:ge}):null,(0,a.jsx)("div",{className:"graview-bar-mid",...cn?{"data-places":"standing"}:!K&&he?{"data-place":""}:{},children:K?null:he}),!K&&k&&k.places.length>1?(0,a.jsxs)("span",{className:"graview-bar-ruler","aria-hidden":"true","data-graview-bar-ruler":"",children:[k.places.map(m=>(0,a.jsx)("span",{className:"graview-bar-at",children:m.label},m.key)),(0,a.jsxs)("span",{className:"graview-bar-at",children:[Ee,(0,a.jsx)(Ue,{})]})]}):null,v&&v.length>0?(0,a.jsx)("span",{className:"graview-bar-ruler","aria-hidden":"true","data-graview-bar-host-ruler":"",children:(0,a.jsx)("span",{className:"graview-bar-host",children:v.map(m=>(0,a.jsxs)("span",{className:"graview-bar-host-action",...m.iconOnly&&m.icon?{"data-icon-only":""}:{},children:[m.icon?(0,a.jsx)(Je,{icon:m.icon}):null,(0,a.jsx)("span",{className:"graview-bar-host-words",children:m.label})]},m.label))})}):null,S?(0,a.jsx)("span",{className:"graview-bar-ruler","aria-hidden":"true",children:(0,a.jsx)("span",{className:"graview-bar-name",children:n})}):null,(0,a.jsxs)("div",{className:"graview-bar-tools",children:[d?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"graview-bar-find-open",ref:ln,"data-testid":"app-find-open","aria-label":"Find",title:"Find",onClick:br,style:{...ae,display:void 0},children:(0,a.jsx)(st,{})}),(0,a.jsxs)("div",{ref:dn,className:"graview-bar-find","data-testid":"app-find",children:[(0,a.jsx)("div",{ref:ur,className:"graview-bar-find-slot",children:g}),(0,a.jsx)(ot,{})]})]}):null,(0,a.jsx)("div",{ref:gr,className:"graview-bar-own","data-graview-bar-own":""}),v&&v.length>0?(0,a.jsx)(ct,{actions:v,folded:!(v.length<=2&&v.every(m=>m.iconOnly&&m.icon))&&(K||!wr)}):null,P?(0,a.jsx)(nt,{status:P}):null,B?(0,a.jsx)(h.Suspense,{fallback:null,children:(0,a.jsx)(Gr,{scene:!fe,compact:K})}):null,f?(0,a.jsx)(et,{share:f}):null,(0,a.jsx)(qr,{}),l]})]})]}),K&&he?(0,a.jsx)("div",{className:"graview-bar-line","data-graview-place-line":"","data-testid":"app-place-line",children:he}):null]})}var Zr=[],Ye="graview:go-to-face";function qn({name:e,faces:n,rows:r,scheme:t}){let o=I("app-menu",{align:"start"}),i=()=>E.prefetch(),s=(0,h.useRef)(null),p=(0,h.useRef)(n);return p.current=n,(0,h.useEffect)(()=>{let l=s.current;if(!l)return;let d=u=>{let g=p.current?.[u.detail];!g||g.current||(g.reach?.(),g.go())};return l.addEventListener(Ye,d),()=>l.removeEventListener(Ye,d)},[]),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"graview-bar-menu-open","data-testid":"app-menu-open",...o.trigger,ref:l=>{o.trigger.ref(l),s.current=l},onClick:o.toggle,onPointerEnter:i,onFocus:i,"aria-label":`${e} \u2014 app menu`,title:"App menu",...n?{"data-scene":n.scene.label,"data-pages":n.pages.label}:{},children:(0,a.jsx)(Ue,{})}),(0,a.jsx)("div",{...o.pane,"data-testid":"app-menu",hidden:!o.open,className:"graview-bar-list graview-app-menu",style:D,"aria-label":`${e} \u2014 app menu`,role:"group",children:o.open?(0,a.jsx)(h.Suspense,{fallback:null,children:(0,a.jsx)(jr,{faces:n,rows:r,scheme:t,close:()=>o.setOpen(!1)})}):null})]})}function nr({mark:e="lock"}){return e==="lock"?(0,a.jsxs)(Y,{size:14,children:[(0,a.jsx)("rect",{x:"2.75",y:"6.25",width:"8.5",height:"6",rx:"1.25",fill:"none",stroke:"currentColor",strokeWidth:"1.3"}),(0,a.jsx)("path",{d:"M4.75 6.25 V4.5 a2.25 2.25 0 0 1 4.5 0 V6.25",fill:"none",stroke:"currentColor",strokeWidth:"1.3"})]}):e==="globe"?(0,a.jsxs)(Y,{size:14,children:[(0,a.jsx)("circle",{cx:"7",cy:"7",r:"5.25",fill:"none",stroke:"currentColor",strokeWidth:"1.3"}),(0,a.jsx)("path",{d:"M1.75 7 H12.25 M7 1.75 C4.75 4.5 4.75 9.5 7 12.25 M7 1.75 C9.25 4.5 9.25 9.5 7 12.25",fill:"none",stroke:"currentColor",strokeWidth:"1.1"})]}):e==="people"?(0,a.jsxs)(Y,{size:14,children:[(0,a.jsx)("circle",{cx:"5",cy:"5",r:"2",fill:"none",stroke:"currentColor",strokeWidth:"1.3"}),(0,a.jsx)("path",{d:"M1.5 12 a3.5 3.5 0 0 1 7 0",fill:"none",stroke:"currentColor",strokeWidth:"1.3"}),(0,a.jsx)("circle",{cx:"10",cy:"5.5",r:"1.6",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),(0,a.jsx)("path",{d:"M9.5 9 a3 3 0 0 1 3.5 3",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]}):(0,a.jsx)(Je,{icon:e})}function et({share:e}){let n=I("share"),r=`graview-share-said-${(0,h.useId)().replace(/:/g,"")}`,t=e.label??"Share",o=e.link;return(0,a.jsxs)("div",{className:"graview-bar-share-at",children:[(0,a.jsxs)("button",{type:"button",className:"graview-bar-tool graview-bar-share","data-testid":"app-share-open",...n.trigger,onClick:n.toggle,"aria-describedby":r,title:e.description,children:[(0,a.jsx)(nr,{mark:e.mark}),(0,a.jsx)("span",{className:"graview-bar-share-words",children:t})]}),(0,a.jsx)("span",{id:r,className:"graview-bar-said",children:e.description}),(0,a.jsxs)("div",{...n.pane,"data-testid":"app-share",hidden:!n.open,className:"graview-bar-share-pane",style:D,role:"group","aria-label":t,children:[(0,a.jsx)("p",{"data-testid":"app-share-said",children:e.description}),o||e.secondLink?(0,a.jsxs)("div",{className:"graview-bar-share-links",children:[o?(0,a.jsx)(Yn,{link:o,testId:"app-share-link",close:()=>n.setOpen(!1)}):null,e.secondLink?(0,a.jsx)(Yn,{link:e.secondLink,testId:"app-share-second-link",close:()=>n.setOpen(!1)}):null]}):null]})]})}function nt({status:e}){let n=`graview-status-said-${(0,h.useId)().replace(/:/g,"")}`,r=(0,a.jsxs)(a.Fragment,{children:[e.icon?(0,a.jsx)(nr,{mark:e.icon}):null,(0,a.jsx)("span",{className:"graview-bar-status-words",children:e.label})]}),t={className:"graview-bar-tool graview-bar-status","data-testid":"app-status",title:e.description,"aria-describedby":n,...e.icon?{"data-icon":""}:{}};return(0,a.jsxs)(a.Fragment,{children:[e.href!==void 0?(0,a.jsx)("a",{...t,href:e.href,...e.target?{target:e.target,rel:"noopener"}:{},children:r}):(0,a.jsx)("span",{...t,tabIndex:0,children:r}),(0,a.jsx)("span",{id:n,className:"graview-bar-said",children:e.description})]})}function Yn({link:e,testId:n,close:r}){return e.href!==void 0?(0,a.jsx)("a",{href:e.href,"data-testid":n,...e.target?{target:e.target,rel:"noopener"}:{},onClick:()=>{e.onSelect?.(),r()},children:e.label}):(0,a.jsx)("button",{type:"button","data-testid":n,onClick:()=>{r(),e.onSelect?.()},children:e.label})}function rt(e){let n=e.querySelector(".graview-bar-row"),r=e.getBoundingClientRect();if(!n||!(r.width>0))return 0;let t=r.right-(parseFloat(getComputedStyle(n).paddingRight)||0),o=t;for(let i of n.querySelectorAll(":scope > *, .graview-bar-tools > *")){if(i.classList.contains("graview-bar-tools")||i.classList.contains("graview-bar-ruler")||i.classList.contains("graview-bar-said"))continue;let s=i.getBoundingClientRect();s.width>0&&(o=Math.max(o,s.right))}return Math.max(0,o-t)}function tt(e){let n=e.querySelector(".graview-bar-app"),r=e.querySelector(".graview-bar-ruler>.graview-bar-name");if(!n||!r)return 0;let t=s=>s?.getBoundingClientRect().width??0,o=t(n.firstElementChild)-t(e.querySelector(".graview-bar-app-name"))+t(r)+2,i=parseFloat(getComputedStyle(n).maxWidth)/100*(n.parentElement.clientWidth-2*n.offsetLeft)||1/0;return o>i+.5?null:Math.max(0,o-t(n))}var rr=e=>e.button===0&&!(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey);function at(){let e=globalThis.navigator?.platform??"";return/Mac|iPhone|iPad|iPod/.test(e)?"\u2318K":"Ctrl K"}function ot(){let e=_n(te()?.aiDesk);return(0,a.jsx)("span",{className:"graview-bar-find-keys","data-testid":"app-find-keys","aria-hidden":"true",children:e?"/":at()})}function Y({size:e,box:n=e,children:r}){return(0,a.jsx)("svg",{width:e,height:e,viewBox:`0 0 ${n} ${n}`,"aria-hidden":"true",focusable:"false",style:{flex:"0 0 auto"},children:r})}function it(){return(0,a.jsxs)(Y,{size:14,children:[(0,a.jsx)("path",{d:"M7 1.5 L12.5 4.5 L7 7.5 L1.5 4.5 Z",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round"}),(0,a.jsx)("path",{d:"M1.5 7.5 L7 10.5 L12.5 7.5",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round",strokeLinecap:"round"})]})}function Ue(){return(0,a.jsx)(Y,{size:10,children:(0,a.jsx)("path",{d:"M2 3.5 L5 6.5 L8 3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}function st(){return(0,a.jsxs)(Y,{size:16,children:[(0,a.jsx)("circle",{cx:"7",cy:"7",r:"4.75",fill:"none",stroke:"currentColor",strokeWidth:"1.5"}),(0,a.jsx)("path",{d:"M10.5 10.5 L14 14",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}function lt({place:e}){if(e.key===Z)return(0,a.jsx)(it,{});if(e.group==="home")return(0,a.jsx)(Y,{size:13,box:14,children:(0,a.jsx)("path",{d:"M2 6.5 L7 2 L12 6.5 V12 H2 Z",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round"})});let n=e.kind?`hsl(${Math.round(hn(e.kind))} 55% 52%`:"rgb(128 128 128";return(0,a.jsx)("span",{"aria-hidden":"true",style:{display:"inline-block",width:12,height:8,clipPath:"polygon(50% 0, 100% 50%, 50% 100%, 0 50%)",background:e.group==="lists"?`${n})`:`linear-gradient(${n}), ${n})) center / 6px 4px no-repeat, ${n} / 0.35)`}})}var dt=[{group:"home"},{group:"lists",heading:"Lists"},{group:"pictures",heading:"Pictures"}],Ee="More";function ct({actions:e,folded:n}){let r=I("host-actions",{popover:n}),t=e.map(i=>i.label).join(", "),o=i=>e.map(s=>(0,a.jsxs)("button",{type:"button",className:n?"graview-bar-host-action graview-bar-item":"graview-bar-host-action","data-testid":"host-bar-action",...!n&&s.iconOnly&&s.icon?{"data-icon-only":"",title:s.label}:{},onClick:()=>{i(),s.onSelect()},children:[s.icon?(0,a.jsx)(Je,{icon:s.icon}):null,(0,a.jsx)("span",{className:"graview-bar-host-words",children:s.label})]},s.label));return n?(0,a.jsxs)("div",{className:"graview-bar-host",children:[(0,a.jsx)("button",{type:"button",className:"graview-bar-host-action","data-testid":"host-bar-actions-open","data-folded":"",...r.trigger,onClick:r.toggle,"aria-label":`${Ee} \u2014 ${t}`,title:t,children:(0,a.jsxs)(Y,{size:16,children:[(0,a.jsx)("circle",{cx:"3",cy:"8",r:"1.4",fill:"currentColor"}),(0,a.jsx)("circle",{cx:"8",cy:"8",r:"1.4",fill:"currentColor"}),(0,a.jsx)("circle",{cx:"13",cy:"8",r:"1.4",fill:"currentColor"})]})}),(0,a.jsx)("div",{...r.pane,"data-testid":"host-bar-actions",hidden:!r.open,className:"graview-bar-list",style:D,"aria-label":"From the host",children:o(()=>r.setOpen(!1))})]}):(0,a.jsx)("div",{className:"graview-bar-host","data-testid":"host-bar-actions-standing",role:"group","aria-label":"From the host",children:o(()=>{})})}function Je({icon:e}){let n=ce(G(e)?e:void 0);return n?(0,a.jsx)("span",{className:"graview-bar-host-mark","aria-hidden":"true",dangerouslySetInnerHTML:n}):(0,a.jsx)("span",{className:"graview-bar-host-mark","aria-hidden":"true",children:e})}function tr({place:e,current:n,reach:r,standing:t,done:o}){let i=e.key===n,s=r.href?.(e.path);return(0,a.jsxs)(s!==void 0?"a":"button",{className:t?"graview-bar-at":"graview-bar-item","data-testid":`app-place-${e.key}`,"data-place-path":e.path,...i?{"aria-current":"page"}:{},...s!==void 0?{href:s}:{type:"button"},onClick:l=>{o(),r.go&&(s!==void 0&&!rr(l)||(l.preventDefault(),r.go(e)))},children:[t?null:(0,a.jsx)("span",{className:"graview-bar-mark",children:(0,a.jsx)(lt,{place:e})}),t&&i?(0,a.jsx)("span",{"data-testid":"app-place-current",children:e.label}):(0,a.jsx)("span",{children:e.label})]})}function pt({places:e,current:n,reach:r,id:t,done:o}){return(0,a.jsx)(a.Fragment,{children:dt.map(({group:i,heading:s})=>{let p=e.filter(d=>d.group===i);if(p.length===0)return null;let l=`${t}-${i}`;return(0,a.jsxs)("div",{role:"group",...s?{"aria-labelledby":l}:{"aria-label":p[0].label},"data-place-group":i,children:[s?(0,a.jsx)("p",{id:l,children:s}):null,(0,a.jsx)("ul",{children:p.map(d=>(0,a.jsx)("li",{children:(0,a.jsx)(tr,{place:d,current:n,reach:r,standing:!1,done:o})},d.key))})]},i)})})}function ut({places:e,current:n,here:r,reach:t,scene:o,stands:i}){let s=I("places"),p=(0,h.useRef)(i);s.open||(p.current=i);let l=p.current,u=e.find(v=>v.key===n)?.label??r??"Places",g=l?e.filter((v,T)=>!l.includes(T)):e,c=gt(e,n,o),y=te(),b=y?.keptViews?.current(),S=!!(b&&(b.removed.length>0||y.views.places().some(v=>v.hidden)||b.may.lenses&&(y.views.arrangement?.()?.hide?.length??0)>0));return(0,a.jsxs)("nav",{className:l?"graview-bar-places":"graview-bar-place-at","aria-label":o?"What the scene shows":"The app\u2019s places",...l?{"data-testid":"app-places-standing"}:{},...c,children:[l?.map(v=>(0,a.jsx)(tr,{place:e[v],current:n,reach:t,standing:!0,done:()=>{}},e[v].key)),g.length>0||S?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{type:"button",className:l?"graview-bar-at":"graview-bar-place","data-testid":"app-places-open",...s.trigger,onClick:s.toggle,"aria-label":l?`${Ee} \u2014 ${g.length} more ${o?"pictures":"places"}`:`${u} \u2014 ${o?"what the scene shows":"every place"}`,title:l?g.map(v=>v.label).join(", "):u,children:[l?Ee:(0,a.jsx)("span",{className:"graview-bar-place-words","data-testid":"app-place-current",children:u}),(0,a.jsx)(Ue,{})]}),(0,a.jsxs)("div",{...s.pane,"data-testid":"app-places",hidden:!s.open,className:"graview-bar-list",style:D,children:[(0,a.jsx)(pt,{places:g,current:n,reach:t,id:s.pane.id,done:()=>s.setOpen(!1)}),S&&s.open?(0,a.jsx)(h.Suspense,{fallback:null,children:(0,a.jsx)(Kr,{id:s.pane.id,scene:o,reach:t,done:()=>s.setOpen(!1)})}):null]})]}):null]})}function gt(e,n,r){let t=te()?.setMenuAt,o=i=>{let s=i.target.closest?.("[data-place-path],[data-testid=app-places-open]");if(!s||!t)return;let p={at:0};i.type==="pointerdown"?document.addEventListener("pointerup",()=>p.at||=Date.now(),{once:!0}):i.preventDefault();let l=i.nativeEvent;E.load().then(d=>d.placeGesture(l,s,e,n,r,t,p),String)};return{onContextMenu:i=>i.shiftKey||o(i),onKeyDown:i=>(i.key==="ContextMenu"||i.key==="F10"&&i.shiftKey)&&o(i),onPointerDown:i=>i.pointerType!=="mouse"&&i.isPrimary&&o(i)}}function ft(e,n,r){let t=e.querySelector("[data-graview-bar-ruler]"),o=e.querySelector(".graview-bar-mid");if(!t||!o)return null;let i=e.querySelector(".graview-bar-find");if(i?.matches(":focus-within"))return;if(e.getBoundingClientRect().width<pe)return null;let s=tt(e);if(s===null)return null;let p=[...t.children].map(y=>y.getBoundingClientRect().width),l=p.pop()??0,d=o.getBoundingClientRect().left+s,u=i&&getComputedStyle(i).display!=="none"?i.getBoundingClientRect():void 0,g=(u&&u.width>0?u.right-d-(parseFloat(getComputedStyle(i).minWidth)||0)-16:o.getBoundingClientRect().width-s)-rt(e),c=[...r].map(y=>y!=="0");return er({widths:p,current:n,room:Math.floor(g),more:l,primary:c})?.join(",")??null}var mt=e=>`graview:lenses:${e}`,ht=(e,n)=>e?.name??n.kinds.join(",");function Xe(e){try{let n=JSON.parse(localStorage.getItem(mt(e))??"[]");return Array.isArray(n)?n.filter(r=>typeof r?.title=="string"&&typeof r.lens=="string"):[]}catch{return[]}}var Q=w(O(),1);var A=w(x(),1);function yt({profileHref:e,keeping:n,hostActions:r=wt,signature:t=!1}){let{store:o,principal:i,seats:s,people:p}=Se(),l=I("profile"),d=l.open,[u,g]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>kt(Ae),[]),d&&!u&&g(!0),(0,Q.useEffect)(()=>{d&&Ae()},[d]);let c=i.id===void 0?void 0:o.graph.getNode(i.id),y=c===void 0?i.id===void 0?"Nobody in particular":gn(i,{graph:o.graph,schema:o.schema,seats:s,people:p}):ye(o.schema.tryDefinition(c.kind),c);return(0,A.jsxs)("div",{style:{position:"relative"},children:[(0,A.jsx)("button",{type:"button","data-testid":"profile-button",...l.trigger,onClick:l.toggle,onPointerEnter:Ae,onFocus:Ae,"aria-label":`${y} \u2014 you, your seat and your settings`,title:`${y} \u2014 you, your seat and your settings`,style:{...ae,borderRadius:999},children:(0,A.jsx)("span",{"aria-hidden":"true","data-testid":"profile-mark",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:V-4,height:V-4,borderRadius:999,fontSize:"0.8125rem",fontWeight:600,background:"var(--graview-panel-muted)",color:"var(--graview-ink)",border:"1px solid var(--graview-edge)"},children:xt(y)})}),(0,A.jsxs)("section",{...l.pane,"aria-label":"Profile","data-testid":"profile","data-graview-offstage":"",hidden:!d,style:{...D,width:280,maxWidth:"calc(100vw - 32px)",maxHeight:"min(62cqh, 520px)",overflowY:"auto",overflowX:"hidden",display:d?"grid":"none",gap:12,padding:12,borderRadius:10,border:"1px solid var(--graview-edge)",background:"var(--graview-float)",boxShadow:"var(--graview-lift-high)"},children:[u?(0,A.jsx)(Q.Suspense,{fallback:null,children:(0,A.jsx)(vt,{part:"top",name:y,me:c,profileHref:e,hostActions:r,close:()=>l.setOpen(!1)})}):null,(0,A.jsxs)("div",{className:"graview-profile-keeping","data-testid":"profile-keeping",style:Pt,children:[(0,A.jsx)("span",{style:St,children:"Keeping this app"}),n]}),u?(0,A.jsx)(Q.Suspense,{fallback:null,children:(0,A.jsx)(bt,{part:"rest",name:y,me:c,hostActions:r,signature:t,close:()=>l.setOpen(!1)})}):null]})]})}var wt=[],Ae=()=>E.prefetch(),vt=E.part((e,n)=>(0,A.jsx)(e.ProfilePane,{...n}),{what:"The rest of your menu"}),bt=E.part((e,n)=>(0,A.jsx)(e.ProfilePane,{...n}),{quiet:!0});function kt(e){let n=()=>{(typeof navigator>"u"||navigator.onLine!==!1)&&e()},r=globalThis;if(r.requestIdleCallback){let o=r.requestIdleCallback(n,{timeout:5e3});return()=>r.cancelIdleCallback?.(o)}let t=setTimeout(n,2500);return()=>clearTimeout(t)}function xt(e){return(e.trim()[0]??"?").toUpperCase()}var St={fontSize:"0.75rem",letterSpacing:"0.14em",textTransform:"uppercase",color:"var(--graview-ink-faint)"},Pt={paddingTop:10,borderTop:"1px solid var(--graview-edge)"};function Lt(e){return!(e==="hidden"||e===!1)}var ue=w(O(),1);var ar="Everything",Be="scene:district:",Ne=e=>`scene:${e.kind}:${e.as}`;function or(e){let{view:n}=e,r=e.places.filter(c=>!e.hidden.has(c.kind)),t=le(r),o=(c,y)=>{if(c===Z)return De(Ie(y,!0),"view",null);if(c.startsWith(Be))return Tn(De(Ie(y,!1),"view",null),c.slice(Be.length));let b=t.find(S=>Ne(S)===c);return b?Mn(y,b.over?.find(S=>y.focusId===de(S))??b.kind,b.as):null},i=n.within?.view,s=c=>n.focusId===de(c.kind)&&(i===void 0?r.filter(y=>y.kind===c.kind).at(-1)===c:i===c.as),p=r.find(c=>s(c)&&(i!==void 0||!n.overview)),l=p?t.find(c=>ve(c,p)):void 0,d=t.filter(c=>!c.hidden||c===l),u=l||n.overview||!n.focusId?void 0:Et(n.focusId,e);return{places:[{key:Z,label:ar,path:`${be}${xe(o(Z,ke))}`,group:"home"},...d.map(c=>({key:Ne(c),label:re(c,r,e.schema),path:`${be}${xe(o(Ne(c),ke))}`,group:"pictures",kind:c.kind,hidden:c.hidden})),...u?[{...u,path:`${be}${xe(o(u.key,ke))}`}]:[]],current:l?Ne(l):u?.key??Z,to:o}}function Et(e,n){let r=Cn(e);if(r.length>0)return r.some(o=>n.hidden.has(o))?void 0:{key:`${Be}${e}`,label:r.map(o=>we(n.schema,o)).join(" and "),group:"lists",kind:r[0],hidden:!0};let t=n.nameOf?.(e);return t?{key:`${Be}${e}`,label:t,group:"lists",hidden:!0}:void 0}function At(){let{store:e,views:n,hiddenKinds:r,principal:t}=Se(),{view:o,go:i}=Dn(),s=n.places(),p=(0,ue.useMemo)(()=>e.kindsKeptFrom(t),[e,t]),l=(0,ue.useMemo)(()=>g=>{let c=e.graph.getNode(g);if(!(!c||r.has(c.kind)||p.has(c.kind)))return ye(e.schema.tryDefinition(c.kind),c)},[e,r,p]),d=(0,ue.useMemo)(()=>or({places:s,hidden:r,view:o,schema:e.schema,nameOf:l}),[s,r,o,e.schema,l]),u=(0,ue.useMemo)(()=>({go:g=>{let c=d.to(g.key,o);c&&i(c)}}),[d,o,i]);return{places:d.places,current:d.current,reach:u}}var oe=w(O(),1);var F=w(x(),1),Nt=E.part((e,n)=>(0,F.jsx)(e.ProblemRows,{...n}),{what:"The problems",as:"li"}),Ze=()=>E.prefetch();function Bt({clean:e="All rules hold"}){let n=$n(),{set:r}=Vn(),t=n.length,[o,i]=(0,oe.useState)(!1),s=I("problems",{open:o&&t>0,onOpenChange:i}),p=s.open,l=ir(n,e);return(0,oe.useEffect)(()=>{if(t===0)return;let d=setTimeout(Ze,1500);return()=>clearTimeout(d)},[t>0]),(0,F.jsxs)("div",{style:{position:"relative",display:"inline-flex"},children:[(0,F.jsxs)("button",{type:"button","data-testid":"standing",...s.trigger,"aria-disabled":t===0?!0:void 0,"aria-label":l,onClick:t===0?void 0:s.toggle,onPointerEnter:t===0?void 0:Ze,onFocus:t===0?void 0:Ze,title:l,style:{...ae,position:"relative",cursor:t===0?"default":"pointer",color:t===0?"var(--graview-ink-muted)":en(n)},children:[(0,F.jsx)(sr,{tone:t===0?"var(--graview-good)":en(n)}),t>0?(0,F.jsx)("span",{className:"graview-bar-badge","data-testid":"standing-count","aria-hidden":"true",style:{background:en(n)},children:t>99?"99+":t}):null]}),p?(0,F.jsx)("ol",{...s.pane,"data-testid":"problems",style:{...D,width:300,maxHeight:"min(48cqh, 420px)",overflow:"auto",margin:0,padding:4,listStyle:"none",display:"grid",borderRadius:10,border:"1px solid var(--graview-edge)",background:"var(--graview-float)",boxShadow:"var(--graview-lift-high)"},children:(0,F.jsx)(oe.Suspense,{fallback:null,children:(0,F.jsx)(Nt,{violations:n,pick:d=>{r(d.nodeIds),s.setOpen(!1)}})})}):null]})}function ir(e,n){return e.length===0?n:`${fn(e)} \u2014 open what is broken, and what would fix it`}var en=e=>e.some(n=>n.status==="could-not-judge"||n.status==="over-budget")?"var(--graview-bad)":"var(--graview-warn)";function sr({tone:e}){return(0,F.jsx)("span",{"aria-hidden":"true",style:{width:8,height:8,borderRadius:999,flex:"0 0 auto",background:e}})}function Tt(e,n,r=[]){if(e.focusId)return e.focusId;let o=(e.selection??[]).map(Hn).find(i=>i!==null)??r.find(i=>n.includes(i))??n[0]??null;return o===null?null:de(o)}var He=w(x(),1),Te=R(M(()=>(__graviewPreload(import.meta.url,["./chunk.IAEGJDF3.js","./chunk.YZPESGCP.js","./chunk.SY5ID44D.js","./chunk.GVT4UUQA.js","./chunk.O2OL6RQQ.js","./chunk.J6HF7IRQ.js","./chunk.LRNFE3UK.js","./chunk.EP6Q32WT.js","./chunk.QAM76AXV.js","./chunk.Z27NSSYL.js","./chunk.WEMUKZKH.js","./chunk.T27QKVKP.js","./chunk.WVUJXDXZ.js","./chunk.DWM7AR5Y.js","./chunk.6KJGRM7A.js","./chunk.WALVW3KJ.js","./chunk.SNHKYH72.js","./chunk.UGQYMN4J.js","./chunk.RG5G6YQD.js","./chunk.MIE4TJRW.js","./chunk.QRQ5WPZI.js","./chunk.RD2FSSLV.js","./chunk.37RFCHSS.js","./chunk.SO6NT5K7.js","./chunk.MUSMNKE4.js","./chunk.SJQPTDAT.js","./chunk.JQ63N4MZ.js","./chunk.Z3O2VZAJ.js","./chunk.QNP5OR3P.js","./chunk.4W57E7AX.js","./chunk.A5PSEU3W.js","./chunk.SDO3U72B.js","./chunk.ZEZUKRC6.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.JKFVNQY7.js"))));function Ht(){return Te.load().then(()=>{})}var Ct=[{cardinality:"one",fidelity:"full",slot:"page"},{cardinality:"one",fidelity:"summary",slot:"card"},{cardinality:"one",fidelity:"glyph",slot:"row"},{cardinality:"many",fidelity:"full"},{cardinality:"many",fidelity:"summary"},{cardinality:"many",fidelity:"glyph"}];function Mt({schema:e,specs:n,kind:r,view:t}){let o=Te.current.frameworkViews(e,n).lookup(r,{cardinality:t.cardinality,fidelity:t.fidelity});return o?(0,He.jsx)(o,{...t}):null}var Ot=Te.part((e,n)=>(0,He.jsx)(Mt,{...n}),{what:"This view"});function lr(e,n,r){for(let t of n.kinds){let o=r?.[t];for(let i of Ct){let s=l=>(0,He.jsx)(Ot,{schema:n,specs:r,kind:t,view:l}),p=i.slot!==void 0&&o?.[i.slot]!==void 0;p&&(s.says=(l,d)=>Te.current?.frameworkViews(n,r).lookup(t,{cardinality:i.cardinality,fidelity:i.fidelity})?.says?.(l,d)),e.register(t,{cardinality:i.cardinality,fidelity:i.fidelity},p?s:Rn(s))}}return e}function Rt(e,n){return lr(Fn(e),e,n)}var nn=w(O(),1);var W=w(x(),1),dr=R(M(()=>(__graviewPreload(import.meta.url,["./chunk.STPA7HBK.js","./chunk.6NG76MDA.js","./chunk.35KMZHB7.js","./chunk.DEKRFTRN.js","./chunk.BKYZSV2Y.js","./chunk.IAEGJDF3.js","./chunk.YZPESGCP.js","./chunk.SY5ID44D.js","./chunk.GVT4UUQA.js","./chunk.5R744JGZ.js","./chunk.O2OL6RQQ.js","./chunk.J6HF7IRQ.js","./chunk.LRNFE3UK.js","./chunk.HJCQ6I3S.js","./chunk.YCD4JSXD.js","./chunk.ZG5VGP5U.js","./chunk.EP6Q32WT.js","./chunk.QAM76AXV.js","./chunk.Z27NSSYL.js","./chunk.WEMUKZKH.js","./chunk.T27QKVKP.js","./chunk.URQTF5SY.js","./chunk.BIDL7GQD.js","./chunk.LP2ZMAT2.js","./chunk.MSAYU25L.js","./chunk.EGPCVMDU.js","./chunk.H3EGBDW2.js","./chunk.Q5WEOX3Q.js","./chunk.6SJEZWH3.js","./chunk.6N4PE3U5.js","./chunk.B7KZBT27.js","./chunk.WVUJXDXZ.js","./chunk.DWM7AR5Y.js","./chunk.6KJGRM7A.js","./chunk.WALVW3KJ.js","./chunk.SNHKYH72.js","./chunk.UGQYMN4J.js","./chunk.RG5G6YQD.js","./chunk.MIE4TJRW.js","./chunk.QRQ5WPZI.js","./chunk.RD2FSSLV.js","./chunk.37RFCHSS.js","./chunk.SO6NT5K7.js","./chunk.MUSMNKE4.js","./chunk.SJQPTDAT.js","./chunk.JQ63N4MZ.js","./chunk.Z3O2VZAJ.js","./chunk.QNP5OR3P.js","./chunk.4W57E7AX.js","./chunk.A5PSEU3W.js","./chunk.SDO3U72B.js","./chunk.ZEZUKRC6.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.NXZL5CA2.js"))));function Ft({lens:e,view:n}){let r=dr.current.declaredLensView(e);return(0,W.jsx)(r,{...n})}var Vt=dr.part((e,n)=>(0,W.jsx)(Ft,{...n}),{what:"This picture"});function $t(e){let n=t=>(0,W.jsx)(nn.Suspense,{fallback:null,children:(0,W.jsx)(Vt,{lens:e,view:t})});e.lens==="blocks"&&(n.flows=!0);let r=e.lens==="blocks"?e.options.blocks?.[0]:void 0;return typeof r?.headline=="string"&&(n.lede=r),e.create===!1&&(n.creates=!1),n}var cr=R(M(()=>(__graviewPreload(import.meta.url,["./chunk.IAEGJDF3.js","./chunk.YZPESGCP.js","./chunk.SY5ID44D.js","./chunk.GVT4UUQA.js","./chunk.O2OL6RQQ.js","./chunk.J6HF7IRQ.js","./chunk.LRNFE3UK.js","./chunk.EP6Q32WT.js","./chunk.QAM76AXV.js","./chunk.Z27NSSYL.js","./chunk.WEMUKZKH.js","./chunk.T27QKVKP.js","./chunk.WVUJXDXZ.js","./chunk.DWM7AR5Y.js","./chunk.6KJGRM7A.js","./chunk.WALVW3KJ.js","./chunk.SNHKYH72.js","./chunk.UGQYMN4J.js","./chunk.RG5G6YQD.js","./chunk.MIE4TJRW.js","./chunk.QRQ5WPZI.js","./chunk.RD2FSSLV.js","./chunk.37RFCHSS.js","./chunk.SO6NT5K7.js","./chunk.MUSMNKE4.js","./chunk.SJQPTDAT.js","./chunk.JQ63N4MZ.js","./chunk.Z3O2VZAJ.js","./chunk.QNP5OR3P.js","./chunk.4W57E7AX.js","./chunk.A5PSEU3W.js","./chunk.SDO3U72B.js","./chunk.ZEZUKRC6.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.3ZODN6BW.js"))));function Dt({blocks:e,view:n}){let r=cr.current.homeView(e);return(0,W.jsx)(r,{...n})}var It=cr.part((e,n)=>(0,W.jsx)(Dt,{...n}),{what:"The home"});function _t(e){let n=r=>(0,W.jsx)(nn.Suspense,{fallback:null,children:(0,W.jsx)(It,{blocks:e,view:r})});return Object.defineProperty(n,Symbol.for("graview.home-blocks"),{value:!0}),n}function Wt(e,n){return n.home&&n.home.length>0&&e.home?.(_t(n.home)),pr(e,n),e.arrange?.(n.pages),e}function pr(e,n,r){for(let t of Pn(n).drawn){if(r&&e.places().some(s=>s.title===t.title))continue;let o=$t(t),i={title:t.title,lens:t.lens,...t.across?{across:t.across}:{},...r?{beside:r}:{},...t.hidden?{hidden:!0}:{},over:t.kinds,...r?{}:{declared:!0}};for(let s of t.kinds)e.register(s,{cardinality:"many",fidelity:"full"},o,i),e.register(s,{cardinality:"many",fidelity:"summary"},o,i)}}function zt(e,n,r){r.length>0&&pr(e,{schema:n,lenses:r.map(({lens:t,...o})=>({...o,name:t}))},!0)}function Kt(e,n,r){zt(e,n,Xe(r))}var U=w(O(),1),Ce=w(x(),1);var rn=e=>`graview:first-look:${e}`;function jt(e,n){if(e.seen!==void 0)try{return typeof e.seen=="function"?e.seen():e.seen}catch{return!0}try{return window.localStorage.getItem(rn(n))!==null}catch{return!1}}function Gt(e,n){if(e.seen===void 0)try{window.localStorage.setItem(rn(n),"seen")}catch{}}var qt=R(M(()=>(__graviewPreload(import.meta.url,["./chunk.A5PSEU3W.js","./chunk.SDO3U72B.js","./chunk.ZEZUKRC6.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.P2EKKKK2.js")))),Yt=qt.part((e,n)=>{let r=e.FirstLookHints;return(0,Ce.jsx)(r,{...n})},{quiet:!0});function Qt({firstLook:e,root:n,app:r}){let t=(0,U.useRef)(null);t.current=e===!0?{}:e||null;let[o,i]=(0,U.useState)(()=>t.current!==null&&typeof window<"u"&&!jt(t.current,r)),s=(0,U.useCallback)(p=>{if(i(!1),p===null)return;let l=t.current??{};Gt(l,r),l.onDone?.(p)},[r]);return!o||t.current===null?null:(0,Ce.jsx)(U.Suspense,{fallback:null,children:(0,Ce.jsx)(Yt,{root:n,steps:t.current.steps??[],onEnd:s})})}export{Ut as a,Pe as b,Jt as c,Nr as d,Xt as e,_n as f,Zt as g,ce as h,Wr as i,zr as j,Hr as k,Cr as l,Le as m,Mr as n,Or as o,Rr as p,Vr as q,$r as r,Dr as s,E as t,Yr as u,Qr as v,Jn as w,Ur as x,ae as y,Xr as z,Ye as A,yt as B,Lt as C,At as D,mt as E,ht as F,Xe as G,Bt as H,ir as I,sr as J,Tt as K,Wt as L,zt as M,Kt as N,Ht as O,Rt as P,Qt as Q};
93
+ `):"";(0,h.useLayoutEffect)(j,[j,n,e,Lr,k?.current,fe,K,ee,d]);let pn=!!o||T.length>0||!!ge;return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("header",{ref:z,className:"graview-bar","data-testid":"app-bar","data-graview-app-bar":"",...hr&&ee?{"data-finding":""}:{},children:[(0,a.jsx)("style",{children:Jr}),b,(0,a.jsxs)("div",{className:"graview-bar-row",children:[S?(0,a.jsxs)("div",{className:"graview-bar-app",children:[(0,a.jsx)(kr,{className:"graview-bar-name",children:(0,a.jsxs)(xr,{...t.href!==void 0?{href:t.href,onClick:Sr(t.go)}:{type:"button",onClick:t.go},"data-testid":"app-home",...t.current?{"aria-current":"page"}:{},title:u?`${n} \u2014 ${u}`:`${n} \u2014 home`,className:"graview-bar-home",children:[(0,a.jsx)(Ge,{brand:e,size:20}),(0,a.jsx)("span",{className:"graview-bar-app-name","data-testid":"app-name",children:n})]})}),pn?(0,a.jsx)(qn,{name:n,faces:o,rows:T,scheme:ge}):null]}):pn?(0,a.jsx)(qn,{name:n,faces:o,rows:T,scheme:ge}):null,(0,a.jsx)("div",{className:"graview-bar-mid",...cn?{"data-places":"standing"}:!K&&he?{"data-place":""}:{},children:K?null:he}),!K&&k&&k.places.length>1?(0,a.jsxs)("span",{className:"graview-bar-ruler","aria-hidden":"true","data-graview-bar-ruler":"",children:[k.places.map(m=>(0,a.jsx)("span",{className:"graview-bar-at",children:m.label},m.key)),(0,a.jsxs)("span",{className:"graview-bar-at",children:[Ee,(0,a.jsx)(Ue,{})]})]}):null,v&&v.length>0?(0,a.jsx)("span",{className:"graview-bar-ruler","aria-hidden":"true","data-graview-bar-host-ruler":"",children:(0,a.jsx)("span",{className:"graview-bar-host",children:v.map(m=>(0,a.jsxs)("span",{className:"graview-bar-host-action",...m.iconOnly&&m.icon?{"data-icon-only":""}:{},children:[m.icon?(0,a.jsx)(Je,{icon:m.icon}):null,(0,a.jsx)("span",{className:"graview-bar-host-words",children:m.label})]},m.label))})}):null,S?(0,a.jsx)("span",{className:"graview-bar-ruler","aria-hidden":"true",children:(0,a.jsx)("span",{className:"graview-bar-name",children:n})}):null,(0,a.jsxs)("div",{className:"graview-bar-tools",children:[d?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"graview-bar-find-open",ref:ln,"data-testid":"app-find-open","aria-label":"Find",title:"Find",onClick:br,style:{...ae,display:void 0},children:(0,a.jsx)(st,{})}),(0,a.jsxs)("div",{ref:dn,className:"graview-bar-find","data-testid":"app-find",children:[(0,a.jsx)("div",{ref:ur,className:"graview-bar-find-slot",children:g}),(0,a.jsx)(ot,{})]})]}):null,(0,a.jsx)("div",{ref:gr,className:"graview-bar-own","data-graview-bar-own":""}),v&&v.length>0?(0,a.jsx)(ct,{actions:v,folded:!(v.length<=2&&v.every(m=>m.iconOnly&&m.icon))&&(K||!wr)}):null,P?(0,a.jsx)(nt,{status:P}):null,B?(0,a.jsx)(h.Suspense,{fallback:null,children:(0,a.jsx)(Gr,{scene:!fe,compact:K})}):null,f?(0,a.jsx)(et,{share:f}):null,(0,a.jsx)(qr,{}),l]})]})]}),K&&he?(0,a.jsx)("div",{className:"graview-bar-line","data-graview-place-line":"","data-testid":"app-place-line",children:he}):null]})}var Zr=[],Ye="graview:go-to-face";function qn({name:e,faces:n,rows:r,scheme:t}){let o=I("app-menu",{align:"start"}),i=()=>E.prefetch(),s=(0,h.useRef)(null),p=(0,h.useRef)(n);return p.current=n,(0,h.useEffect)(()=>{let l=s.current;if(!l)return;let d=u=>{let g=p.current?.[u.detail];!g||g.current||(g.reach?.(),g.go())};return l.addEventListener(Ye,d),()=>l.removeEventListener(Ye,d)},[]),(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{type:"button",className:"graview-bar-menu-open","data-testid":"app-menu-open",...o.trigger,ref:l=>{o.trigger.ref(l),s.current=l},onClick:o.toggle,onPointerEnter:i,onFocus:i,"aria-label":`${e} \u2014 app menu`,title:"App menu",...n?{"data-scene":n.scene.label,"data-pages":n.pages.label}:{},children:(0,a.jsx)(Ue,{})}),(0,a.jsx)("div",{...o.pane,"data-testid":"app-menu",hidden:!o.open,className:"graview-bar-list graview-app-menu",style:D,"aria-label":`${e} \u2014 app menu`,role:"group",children:o.open?(0,a.jsx)(h.Suspense,{fallback:null,children:(0,a.jsx)(jr,{faces:n,rows:r,scheme:t,close:()=>o.setOpen(!1)})}):null})]})}function nr({mark:e="lock"}){return e==="lock"?(0,a.jsxs)(Y,{size:14,children:[(0,a.jsx)("rect",{x:"2.75",y:"6.25",width:"8.5",height:"6",rx:"1.25",fill:"none",stroke:"currentColor",strokeWidth:"1.3"}),(0,a.jsx)("path",{d:"M4.75 6.25 V4.5 a2.25 2.25 0 0 1 4.5 0 V6.25",fill:"none",stroke:"currentColor",strokeWidth:"1.3"})]}):e==="globe"?(0,a.jsxs)(Y,{size:14,children:[(0,a.jsx)("circle",{cx:"7",cy:"7",r:"5.25",fill:"none",stroke:"currentColor",strokeWidth:"1.3"}),(0,a.jsx)("path",{d:"M1.75 7 H12.25 M7 1.75 C4.75 4.5 4.75 9.5 7 12.25 M7 1.75 C9.25 4.5 9.25 9.5 7 12.25",fill:"none",stroke:"currentColor",strokeWidth:"1.1"})]}):e==="people"?(0,a.jsxs)(Y,{size:14,children:[(0,a.jsx)("circle",{cx:"5",cy:"5",r:"2",fill:"none",stroke:"currentColor",strokeWidth:"1.3"}),(0,a.jsx)("path",{d:"M1.5 12 a3.5 3.5 0 0 1 7 0",fill:"none",stroke:"currentColor",strokeWidth:"1.3"}),(0,a.jsx)("circle",{cx:"10",cy:"5.5",r:"1.6",fill:"none",stroke:"currentColor",strokeWidth:"1.2"}),(0,a.jsx)("path",{d:"M9.5 9 a3 3 0 0 1 3.5 3",fill:"none",stroke:"currentColor",strokeWidth:"1.2"})]}):(0,a.jsx)(Je,{icon:e})}function et({share:e}){let n=I("share"),r=`graview-share-said-${(0,h.useId)().replace(/:/g,"")}`,t=e.label??"Share",o=e.link;return(0,a.jsxs)("div",{className:"graview-bar-share-at",children:[(0,a.jsxs)("button",{type:"button",className:"graview-bar-tool graview-bar-share","data-testid":"app-share-open",...n.trigger,onClick:n.toggle,"aria-describedby":r,title:e.description,children:[(0,a.jsx)(nr,{mark:e.mark}),(0,a.jsx)("span",{className:"graview-bar-share-words",children:t})]}),(0,a.jsx)("span",{id:r,className:"graview-bar-said",children:e.description}),(0,a.jsxs)("div",{...n.pane,"data-testid":"app-share",hidden:!n.open,className:"graview-bar-share-pane",style:D,role:"group","aria-label":t,children:[(0,a.jsx)("p",{"data-testid":"app-share-said",children:e.description}),o||e.secondLink?(0,a.jsxs)("div",{className:"graview-bar-share-links",children:[o?(0,a.jsx)(Yn,{link:o,testId:"app-share-link",close:()=>n.setOpen(!1)}):null,e.secondLink?(0,a.jsx)(Yn,{link:e.secondLink,testId:"app-share-second-link",close:()=>n.setOpen(!1)}):null]}):null]})]})}function nt({status:e}){let n=`graview-status-said-${(0,h.useId)().replace(/:/g,"")}`,r=(0,a.jsxs)(a.Fragment,{children:[e.icon?(0,a.jsx)(nr,{mark:e.icon}):null,(0,a.jsx)("span",{className:"graview-bar-status-words",children:e.label})]}),t={className:"graview-bar-tool graview-bar-status","data-testid":"app-status",title:e.description,"aria-describedby":n,...e.icon?{"data-icon":""}:{}};return(0,a.jsxs)(a.Fragment,{children:[e.href!==void 0?(0,a.jsx)("a",{...t,href:e.href,...e.target?{target:e.target,rel:"noopener"}:{},children:r}):(0,a.jsx)("span",{...t,tabIndex:0,children:r}),(0,a.jsx)("span",{id:n,className:"graview-bar-said",children:e.description})]})}function Yn({link:e,testId:n,close:r}){return e.href!==void 0?(0,a.jsx)("a",{href:e.href,"data-testid":n,...e.target?{target:e.target,rel:"noopener"}:{},onClick:()=>{e.onSelect?.(),r()},children:e.label}):(0,a.jsx)("button",{type:"button","data-testid":n,onClick:()=>{r(),e.onSelect?.()},children:e.label})}function rt(e){let n=e.querySelector(".graview-bar-row"),r=e.getBoundingClientRect();if(!n||!(r.width>0))return 0;let t=r.right-(parseFloat(getComputedStyle(n).paddingRight)||0),o=t;for(let i of n.querySelectorAll(":scope > *, .graview-bar-tools > *")){if(i.classList.contains("graview-bar-tools")||i.classList.contains("graview-bar-ruler")||i.classList.contains("graview-bar-said"))continue;let s=i.getBoundingClientRect();s.width>0&&(o=Math.max(o,s.right))}return Math.max(0,o-t)}function tt(e){let n=e.querySelector(".graview-bar-app"),r=e.querySelector(".graview-bar-ruler>.graview-bar-name");if(!n||!r)return 0;let t=s=>s?.getBoundingClientRect().width??0,o=t(n.firstElementChild)-t(e.querySelector(".graview-bar-app-name"))+t(r)+2,i=parseFloat(getComputedStyle(n).maxWidth)/100*(n.parentElement.clientWidth-2*n.offsetLeft)||1/0;return o>i+.5?null:Math.max(0,o-t(n))}var rr=e=>e.button===0&&!(e.metaKey||e.ctrlKey||e.shiftKey||e.altKey);function at(){let e=globalThis.navigator?.platform??"";return/Mac|iPhone|iPad|iPod/.test(e)?"\u2318K":"Ctrl K"}function ot(){let e=_n(te()?.aiDesk);return(0,a.jsx)("span",{className:"graview-bar-find-keys","data-testid":"app-find-keys","aria-hidden":"true",children:e?"/":at()})}function Y({size:e,box:n=e,children:r}){return(0,a.jsx)("svg",{width:e,height:e,viewBox:`0 0 ${n} ${n}`,"aria-hidden":"true",focusable:"false",style:{flex:"0 0 auto"},children:r})}function it(){return(0,a.jsxs)(Y,{size:14,children:[(0,a.jsx)("path",{d:"M7 1.5 L12.5 4.5 L7 7.5 L1.5 4.5 Z",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round"}),(0,a.jsx)("path",{d:"M1.5 7.5 L7 10.5 L12.5 7.5",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round",strokeLinecap:"round"})]})}function Ue(){return(0,a.jsx)(Y,{size:10,children:(0,a.jsx)("path",{d:"M2 3.5 L5 6.5 L8 3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}function st(){return(0,a.jsxs)(Y,{size:16,children:[(0,a.jsx)("circle",{cx:"7",cy:"7",r:"4.75",fill:"none",stroke:"currentColor",strokeWidth:"1.5"}),(0,a.jsx)("path",{d:"M10.5 10.5 L14 14",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})}function lt({place:e}){if(e.key===Z)return(0,a.jsx)(it,{});if(e.group==="home")return(0,a.jsx)(Y,{size:13,box:14,children:(0,a.jsx)("path",{d:"M2 6.5 L7 2 L12 6.5 V12 H2 Z",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinejoin:"round"})});let n=e.kind?`hsl(${Math.round(hn(e.kind))} 55% 52%`:"rgb(128 128 128";return(0,a.jsx)("span",{"aria-hidden":"true",style:{display:"inline-block",width:12,height:8,clipPath:"polygon(50% 0, 100% 50%, 50% 100%, 0 50%)",background:e.group==="lists"?`${n})`:`linear-gradient(${n}), ${n})) center / 6px 4px no-repeat, ${n} / 0.35)`}})}var dt=[{group:"home"},{group:"lists",heading:"Lists"},{group:"pictures",heading:"Pictures"}],Ee="More";function ct({actions:e,folded:n}){let r=I("host-actions",{popover:n}),t=e.map(i=>i.label).join(", "),o=i=>e.map(s=>(0,a.jsxs)("button",{type:"button",className:n?"graview-bar-host-action graview-bar-item":"graview-bar-host-action","data-testid":"host-bar-action",...!n&&s.iconOnly&&s.icon?{"data-icon-only":"",title:s.label}:{},onClick:()=>{i(),s.onSelect()},children:[s.icon?(0,a.jsx)(Je,{icon:s.icon}):null,(0,a.jsx)("span",{className:"graview-bar-host-words",children:s.label})]},s.label));return n?(0,a.jsxs)("div",{className:"graview-bar-host",children:[(0,a.jsx)("button",{type:"button",className:"graview-bar-host-action","data-testid":"host-bar-actions-open","data-folded":"",...r.trigger,onClick:r.toggle,"aria-label":`${Ee} \u2014 ${t}`,title:t,children:(0,a.jsxs)(Y,{size:16,children:[(0,a.jsx)("circle",{cx:"3",cy:"8",r:"1.4",fill:"currentColor"}),(0,a.jsx)("circle",{cx:"8",cy:"8",r:"1.4",fill:"currentColor"}),(0,a.jsx)("circle",{cx:"13",cy:"8",r:"1.4",fill:"currentColor"})]})}),(0,a.jsx)("div",{...r.pane,"data-testid":"host-bar-actions",hidden:!r.open,className:"graview-bar-list",style:D,"aria-label":"From the host",children:o(()=>r.setOpen(!1))})]}):(0,a.jsx)("div",{className:"graview-bar-host","data-testid":"host-bar-actions-standing",role:"group","aria-label":"From the host",children:o(()=>{})})}function Je({icon:e}){let n=ce(G(e)?e:void 0);return n?(0,a.jsx)("span",{className:"graview-bar-host-mark","aria-hidden":"true",dangerouslySetInnerHTML:n}):(0,a.jsx)("span",{className:"graview-bar-host-mark","aria-hidden":"true",children:e})}function tr({place:e,current:n,reach:r,standing:t,done:o}){let i=e.key===n,s=r.href?.(e.path);return(0,a.jsxs)(s!==void 0?"a":"button",{className:t?"graview-bar-at":"graview-bar-item","data-testid":`app-place-${e.key}`,"data-place-path":e.path,...i?{"aria-current":"page"}:{},...s!==void 0?{href:s}:{type:"button"},onClick:l=>{o(),r.go&&(s!==void 0&&!rr(l)||(l.preventDefault(),r.go(e)))},children:[t?null:(0,a.jsx)("span",{className:"graview-bar-mark",children:(0,a.jsx)(lt,{place:e})}),t&&i?(0,a.jsx)("span",{"data-testid":"app-place-current",children:e.label}):(0,a.jsx)("span",{children:e.label})]})}function pt({places:e,current:n,reach:r,id:t,done:o}){return(0,a.jsx)(a.Fragment,{children:dt.map(({group:i,heading:s})=>{let p=e.filter(d=>d.group===i);if(p.length===0)return null;let l=`${t}-${i}`;return(0,a.jsxs)("div",{role:"group",...s?{"aria-labelledby":l}:{"aria-label":p[0].label},"data-place-group":i,children:[s?(0,a.jsx)("p",{id:l,children:s}):null,(0,a.jsx)("ul",{children:p.map(d=>(0,a.jsx)("li",{children:(0,a.jsx)(tr,{place:d,current:n,reach:r,standing:!1,done:o})},d.key))})]},i)})})}function ut({places:e,current:n,here:r,reach:t,scene:o,stands:i}){let s=I("places"),p=(0,h.useRef)(i);s.open||(p.current=i);let l=p.current,u=e.find(v=>v.key===n)?.label??r??"Places",g=l?e.filter((v,T)=>!l.includes(T)):e,c=gt(e,n,o),y=te(),b=y?.keptViews?.current(),S=!!(b&&(b.removed.length>0||y.views.places().some(v=>v.hidden)||b.may.lenses&&(y.views.arrangement?.()?.hide?.length??0)>0));return(0,a.jsxs)("nav",{className:l?"graview-bar-places":"graview-bar-place-at","aria-label":o?"What the scene shows":"The app\u2019s places",...l?{"data-testid":"app-places-standing"}:{},...c,children:[l?.map(v=>(0,a.jsx)(tr,{place:e[v],current:n,reach:t,standing:!0,done:()=>{}},e[v].key)),g.length>0||S?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("button",{type:"button",className:l?"graview-bar-at":"graview-bar-place","data-testid":"app-places-open",...s.trigger,onClick:s.toggle,"aria-label":l?`${Ee} \u2014 ${g.length} more ${o?"pictures":"places"}`:`${u} \u2014 ${o?"what the scene shows":"every place"}`,title:l?g.map(v=>v.label).join(", "):u,children:[l?Ee:(0,a.jsx)("span",{className:"graview-bar-place-words","data-testid":"app-place-current",children:u}),(0,a.jsx)(Ue,{})]}),(0,a.jsxs)("div",{...s.pane,"data-testid":"app-places",hidden:!s.open,className:"graview-bar-list",style:D,children:[(0,a.jsx)(pt,{places:g,current:n,reach:t,id:s.pane.id,done:()=>s.setOpen(!1)}),S&&s.open?(0,a.jsx)(h.Suspense,{fallback:null,children:(0,a.jsx)(Kr,{id:s.pane.id,scene:o,reach:t,done:()=>s.setOpen(!1)})}):null]})]}):null]})}function gt(e,n,r){let t=te()?.setMenuAt,o=i=>{let s=i.target.closest?.("[data-place-path],[data-testid=app-places-open]");if(!s||!t)return;let p={at:0};i.type==="pointerdown"?document.addEventListener("pointerup",()=>p.at||=Date.now(),{once:!0}):i.preventDefault();let l=i.nativeEvent;E.load().then(d=>d.placeGesture(l,s,e,n,r,t,p),String)};return{onContextMenu:i=>i.shiftKey||o(i),onKeyDown:i=>(i.key==="ContextMenu"||i.key==="F10"&&i.shiftKey)&&o(i),onPointerDown:i=>i.pointerType!=="mouse"&&i.isPrimary&&o(i)}}function ft(e,n,r){let t=e.querySelector("[data-graview-bar-ruler]"),o=e.querySelector(".graview-bar-mid");if(!t||!o)return null;let i=e.querySelector(".graview-bar-find");if(i?.matches(":focus-within"))return;if(e.getBoundingClientRect().width<pe)return null;let s=tt(e);if(s===null)return null;let p=[...t.children].map(y=>y.getBoundingClientRect().width),l=p.pop()??0,d=o.getBoundingClientRect().left+s,u=i&&getComputedStyle(i).display!=="none"?i.getBoundingClientRect():void 0,g=(u&&u.width>0?u.right-d-(parseFloat(getComputedStyle(i).minWidth)||0)-16:o.getBoundingClientRect().width-s)-rt(e),c=[...r].map(y=>y!=="0");return er({widths:p,current:n,room:Math.floor(g),more:l,primary:c})?.join(",")??null}var mt=e=>`graview:lenses:${e}`,ht=(e,n)=>e?.name??n.kinds.join(",");function Xe(e){try{let n=JSON.parse(localStorage.getItem(mt(e))??"[]");return Array.isArray(n)?n.filter(r=>typeof r?.title=="string"&&typeof r.lens=="string"):[]}catch{return[]}}var Q=w(O(),1);var A=w(x(),1);function yt({profileHref:e,keeping:n,hostActions:r=wt,signature:t=!1}){let{store:o,principal:i,seats:s,people:p}=Se(),l=I("profile"),d=l.open,[u,g]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>kt(Ae),[]),d&&!u&&g(!0),(0,Q.useEffect)(()=>{d&&Ae()},[d]);let c=i.id===void 0?void 0:o.graph.getNode(i.id),y=c===void 0?i.id===void 0?"Nobody in particular":gn(i,{graph:o.graph,schema:o.schema,seats:s,people:p}):ye(o.schema.tryDefinition(c.kind),c);return(0,A.jsxs)("div",{style:{position:"relative"},children:[(0,A.jsx)("button",{type:"button","data-testid":"profile-button",...l.trigger,onClick:l.toggle,onPointerEnter:Ae,onFocus:Ae,"aria-label":`${y} \u2014 you, your seat and your settings`,title:`${y} \u2014 you, your seat and your settings`,style:{...ae,borderRadius:999},children:(0,A.jsx)("span",{"aria-hidden":"true","data-testid":"profile-mark",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",width:V-4,height:V-4,borderRadius:999,fontSize:"0.8125rem",fontWeight:600,background:"var(--graview-panel-muted)",color:"var(--graview-ink)",border:"1px solid var(--graview-edge)"},children:xt(y)})}),(0,A.jsxs)("section",{...l.pane,"aria-label":"Profile","data-testid":"profile","data-graview-offstage":"",hidden:!d,style:{...D,width:280,maxWidth:"calc(100vw - 32px)",maxHeight:"min(62cqh, 520px)",overflowY:"auto",overflowX:"hidden",display:d?"grid":"none",gap:12,padding:12,borderRadius:10,border:"1px solid var(--graview-edge)",background:"var(--graview-float)",boxShadow:"var(--graview-lift-high)"},children:[u?(0,A.jsx)(Q.Suspense,{fallback:null,children:(0,A.jsx)(vt,{part:"top",name:y,me:c,profileHref:e,hostActions:r,close:()=>l.setOpen(!1)})}):null,(0,A.jsxs)("div",{className:"graview-profile-keeping","data-testid":"profile-keeping",style:Pt,children:[(0,A.jsx)("span",{style:St,children:"Keeping this app"}),n]}),u?(0,A.jsx)(Q.Suspense,{fallback:null,children:(0,A.jsx)(bt,{part:"rest",name:y,me:c,hostActions:r,signature:t,close:()=>l.setOpen(!1)})}):null]})]})}var wt=[],Ae=()=>E.prefetch(),vt=E.part((e,n)=>(0,A.jsx)(e.ProfilePane,{...n}),{what:"The rest of your menu"}),bt=E.part((e,n)=>(0,A.jsx)(e.ProfilePane,{...n}),{quiet:!0});function kt(e){let n=()=>{(typeof navigator>"u"||navigator.onLine!==!1)&&e()},r=globalThis;if(r.requestIdleCallback){let o=r.requestIdleCallback(n,{timeout:5e3});return()=>r.cancelIdleCallback?.(o)}let t=setTimeout(n,2500);return()=>clearTimeout(t)}function xt(e){return(e.trim()[0]??"?").toUpperCase()}var St={fontSize:"0.75rem",letterSpacing:"0.14em",textTransform:"uppercase",color:"var(--graview-ink-faint)"},Pt={paddingTop:10,borderTop:"1px solid var(--graview-edge)"};function Lt(e){return!(e==="hidden"||e===!1)}var ue=w(O(),1);var ar="Everything",Be="scene:district:",Ne=e=>`scene:${e.kind}:${e.as}`;function or(e){let{view:n}=e,r=e.places.filter(c=>!e.hidden.has(c.kind)),t=le(r),o=(c,y)=>{if(c===Z)return De(Ie(y,!0),"view",null);if(c.startsWith(Be))return Tn(De(Ie(y,!1),"view",null),c.slice(Be.length));let b=t.find(S=>Ne(S)===c);return b?Mn(y,b.over?.find(S=>y.focusId===de(S))??b.kind,b.as):null},i=n.within?.view,s=c=>n.focusId===de(c.kind)&&(i===void 0?r.filter(y=>y.kind===c.kind).at(-1)===c:i===c.as),p=r.find(c=>s(c)&&(i!==void 0||!n.overview)),l=p?t.find(c=>ve(c,p)):void 0,d=t.filter(c=>!c.hidden||c===l),u=l||n.overview||!n.focusId?void 0:Et(n.focusId,e);return{places:[{key:Z,label:ar,path:`${be}${xe(o(Z,ke))}`,group:"home"},...d.map(c=>({key:Ne(c),label:re(c,r,e.schema),path:`${be}${xe(o(Ne(c),ke))}`,group:"pictures",kind:c.kind,hidden:c.hidden})),...u?[{...u,path:`${be}${xe(o(u.key,ke))}`}]:[]],current:l?Ne(l):u?.key??Z,to:o}}function Et(e,n){let r=Cn(e);if(r.length>0)return r.some(o=>n.hidden.has(o))?void 0:{key:`${Be}${e}`,label:r.map(o=>we(n.schema,o)).join(" and "),group:"lists",kind:r[0],hidden:!0};let t=n.nameOf?.(e);return t?{key:`${Be}${e}`,label:t,group:"lists",hidden:!0}:void 0}function At(){let{store:e,views:n,hiddenKinds:r,principal:t}=Se(),{view:o,go:i}=Dn(),s=n.places(),p=(0,ue.useMemo)(()=>e.kindsKeptFrom(t),[e,t]),l=(0,ue.useMemo)(()=>g=>{let c=e.graph.getNode(g);if(!(!c||r.has(c.kind)||p.has(c.kind)))return ye(e.schema.tryDefinition(c.kind),c)},[e,r,p]),d=(0,ue.useMemo)(()=>or({places:s,hidden:r,view:o,schema:e.schema,nameOf:l}),[s,r,o,e.schema,l]),u=(0,ue.useMemo)(()=>({go:g=>{let c=d.to(g.key,o);c&&i(c)}}),[d,o,i]);return{places:d.places,current:d.current,reach:u}}var oe=w(O(),1);var F=w(x(),1),Nt=E.part((e,n)=>(0,F.jsx)(e.ProblemRows,{...n}),{what:"The problems",as:"li"}),Ze=()=>E.prefetch();function Bt({clean:e="All rules hold"}){let n=$n(),{set:r}=Vn(),t=n.length,[o,i]=(0,oe.useState)(!1),s=I("problems",{open:o&&t>0,onOpenChange:i}),p=s.open,l=ir(n,e);return(0,oe.useEffect)(()=>{if(t===0)return;let d=setTimeout(Ze,1500);return()=>clearTimeout(d)},[t>0]),(0,F.jsxs)("div",{style:{position:"relative",display:"inline-flex"},children:[(0,F.jsxs)("button",{type:"button","data-testid":"standing",...s.trigger,"aria-disabled":t===0?!0:void 0,"aria-label":l,onClick:t===0?void 0:s.toggle,onPointerEnter:t===0?void 0:Ze,onFocus:t===0?void 0:Ze,title:l,style:{...ae,position:"relative",cursor:t===0?"default":"pointer",color:t===0?"var(--graview-ink-muted)":en(n)},children:[(0,F.jsx)(sr,{tone:t===0?"var(--graview-good)":en(n)}),t>0?(0,F.jsx)("span",{className:"graview-bar-badge","data-testid":"standing-count","aria-hidden":"true",style:{background:en(n)},children:t>99?"99+":t}):null]}),p?(0,F.jsx)("ol",{...s.pane,"data-testid":"problems",style:{...D,width:300,maxHeight:"min(48cqh, 420px)",overflow:"auto",margin:0,padding:4,listStyle:"none",display:"grid",borderRadius:10,border:"1px solid var(--graview-edge)",background:"var(--graview-float)",boxShadow:"var(--graview-lift-high)"},children:(0,F.jsx)(oe.Suspense,{fallback:null,children:(0,F.jsx)(Nt,{violations:n,pick:d=>{r(d.nodeIds),s.setOpen(!1)}})})}):null]})}function ir(e,n){return e.length===0?n:`${fn(e)} \u2014 open what is broken, and what would fix it`}var en=e=>e.some(n=>n.status==="could-not-judge"||n.status==="over-budget")?"var(--graview-bad)":"var(--graview-warn)";function sr({tone:e}){return(0,F.jsx)("span",{"aria-hidden":"true",style:{width:8,height:8,borderRadius:999,flex:"0 0 auto",background:e}})}function Tt(e,n,r=[]){if(e.focusId)return e.focusId;let o=(e.selection??[]).map(Hn).find(i=>i!==null)??r.find(i=>n.includes(i))??n[0]??null;return o===null?null:de(o)}var He=w(x(),1),Te=R(M(()=>(__graviewPreload(import.meta.url,["./chunk.42KHFGN6.js","./chunk.RQG672MJ.js","./chunk.Q6H5HESF.js","./chunk.3JMQKANL.js","./chunk.2ME4DVBI.js","./chunk.XXCHO2A5.js","./chunk.SADR3MQI.js","./chunk.LFFJB6D3.js","./chunk.DMZRFXH7.js","./chunk.DZ6UDZOB.js","./chunk.Q4VFLLUT.js","./chunk.6ZENHSTQ.js","./chunk.WVUJXDXZ.js","./chunk.L7XKYGV7.js","./chunk.CE3NKAF7.js","./chunk.R3GE37OI.js","./chunk.2KCDLCB2.js","./chunk.UD7VLXPM.js","./chunk.3DEWQDP7.js","./chunk.MIE4TJRW.js","./chunk.CFE3MHWZ.js","./chunk.RD2FSSLV.js","./chunk.HXTKBISQ.js","./chunk.TFJA4QV4.js","./chunk.HWFJQ42Y.js","./chunk.QUETLFBJ.js","./chunk.JULD4XFB.js","./chunk.GRTBEA7O.js","./chunk.H3IGXHZR.js","./chunk.7TDML5YU.js","./chunk.3VEZ5MOC.js","./chunk.SDO3U72B.js","./chunk.6AANHELP.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.WN7SAAH6.js"))));function Ht(){return Te.load().then(()=>{})}var Ct=[{cardinality:"one",fidelity:"full",slot:"page"},{cardinality:"one",fidelity:"summary",slot:"card"},{cardinality:"one",fidelity:"glyph",slot:"row"},{cardinality:"many",fidelity:"full"},{cardinality:"many",fidelity:"summary"},{cardinality:"many",fidelity:"glyph"}];function Mt({schema:e,specs:n,kind:r,view:t}){let o=Te.current.frameworkViews(e,n).lookup(r,{cardinality:t.cardinality,fidelity:t.fidelity});return o?(0,He.jsx)(o,{...t}):null}var Ot=Te.part((e,n)=>(0,He.jsx)(Mt,{...n}),{what:"This view"});function lr(e,n,r){for(let t of n.kinds){let o=r?.[t];for(let i of Ct){let s=l=>(0,He.jsx)(Ot,{schema:n,specs:r,kind:t,view:l}),p=i.slot!==void 0&&o?.[i.slot]!==void 0;p&&(s.says=(l,d)=>Te.current?.frameworkViews(n,r).lookup(t,{cardinality:i.cardinality,fidelity:i.fidelity})?.says?.(l,d)),e.register(t,{cardinality:i.cardinality,fidelity:i.fidelity},p?s:Rn(s))}}return e}function Rt(e,n){return lr(Fn(e),e,n)}var nn=w(O(),1);var W=w(x(),1),dr=R(M(()=>(__graviewPreload(import.meta.url,["./chunk.AWV57UBJ.js","./chunk.YBQ5GVAX.js","./chunk.EB7PZJEO.js","./chunk.MSUZAJ2K.js","./chunk.64LCHHZB.js","./chunk.42KHFGN6.js","./chunk.RQG672MJ.js","./chunk.Q6H5HESF.js","./chunk.3JMQKANL.js","./chunk.42C3FIKK.js","./chunk.2ME4DVBI.js","./chunk.XXCHO2A5.js","./chunk.SADR3MQI.js","./chunk.HJCQ6I3S.js","./chunk.2BMZPALF.js","./chunk.GONZB3J3.js","./chunk.LFFJB6D3.js","./chunk.DMZRFXH7.js","./chunk.DZ6UDZOB.js","./chunk.Q4VFLLUT.js","./chunk.6ZENHSTQ.js","./chunk.BHJRT57H.js","./chunk.BIDL7GQD.js","./chunk.CNN32262.js","./chunk.N5Z34V7U.js","./chunk.LOKGUALC.js","./chunk.EP5JS7ZH.js","./chunk.Q5WEOX3Q.js","./chunk.KAM73WVF.js","./chunk.O32F6LGK.js","./chunk.EGSOHTZZ.js","./chunk.WVUJXDXZ.js","./chunk.L7XKYGV7.js","./chunk.CE3NKAF7.js","./chunk.R3GE37OI.js","./chunk.2KCDLCB2.js","./chunk.UD7VLXPM.js","./chunk.3DEWQDP7.js","./chunk.MIE4TJRW.js","./chunk.CFE3MHWZ.js","./chunk.RD2FSSLV.js","./chunk.HXTKBISQ.js","./chunk.TFJA4QV4.js","./chunk.HWFJQ42Y.js","./chunk.QUETLFBJ.js","./chunk.JULD4XFB.js","./chunk.GRTBEA7O.js","./chunk.H3IGXHZR.js","./chunk.7TDML5YU.js","./chunk.3VEZ5MOC.js","./chunk.SDO3U72B.js","./chunk.6AANHELP.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.7OL6H4LF.js"))));function Ft({lens:e,view:n}){let r=dr.current.declaredLensView(e);return(0,W.jsx)(r,{...n})}var Vt=dr.part((e,n)=>(0,W.jsx)(Ft,{...n}),{what:"This picture"});function $t(e){let n=t=>(0,W.jsx)(nn.Suspense,{fallback:null,children:(0,W.jsx)(Vt,{lens:e,view:t})});e.lens==="blocks"&&(n.flows=!0);let r=e.lens==="blocks"?e.options.blocks?.[0]:void 0;return typeof r?.headline=="string"&&(n.lede=r),e.create===!1&&(n.creates=!1),n}var cr=R(M(()=>(__graviewPreload(import.meta.url,["./chunk.42KHFGN6.js","./chunk.RQG672MJ.js","./chunk.Q6H5HESF.js","./chunk.3JMQKANL.js","./chunk.2ME4DVBI.js","./chunk.XXCHO2A5.js","./chunk.SADR3MQI.js","./chunk.LFFJB6D3.js","./chunk.DMZRFXH7.js","./chunk.DZ6UDZOB.js","./chunk.Q4VFLLUT.js","./chunk.6ZENHSTQ.js","./chunk.WVUJXDXZ.js","./chunk.L7XKYGV7.js","./chunk.CE3NKAF7.js","./chunk.R3GE37OI.js","./chunk.2KCDLCB2.js","./chunk.UD7VLXPM.js","./chunk.3DEWQDP7.js","./chunk.MIE4TJRW.js","./chunk.CFE3MHWZ.js","./chunk.RD2FSSLV.js","./chunk.HXTKBISQ.js","./chunk.TFJA4QV4.js","./chunk.HWFJQ42Y.js","./chunk.QUETLFBJ.js","./chunk.JULD4XFB.js","./chunk.GRTBEA7O.js","./chunk.H3IGXHZR.js","./chunk.7TDML5YU.js","./chunk.3VEZ5MOC.js","./chunk.SDO3U72B.js","./chunk.6AANHELP.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.ZUG7U7AT.js"))));function Dt({blocks:e,view:n}){let r=cr.current.homeView(e);return(0,W.jsx)(r,{...n})}var It=cr.part((e,n)=>(0,W.jsx)(Dt,{...n}),{what:"The home"});function _t(e){let n=r=>(0,W.jsx)(nn.Suspense,{fallback:null,children:(0,W.jsx)(It,{blocks:e,view:r})});return Object.defineProperty(n,Symbol.for("graview.home-blocks"),{value:!0}),n}function Wt(e,n){return n.home&&n.home.length>0&&e.home?.(_t(n.home)),pr(e,n),e.arrange?.(n.pages),e}function pr(e,n,r){for(let t of Pn(n).drawn){if(r&&e.places().some(s=>s.title===t.title))continue;let o=$t(t),i={title:t.title,lens:t.lens,...t.across?{across:t.across}:{},...r?{beside:r}:{},...t.hidden?{hidden:!0}:{},over:t.kinds,...r?{}:{declared:!0}};for(let s of t.kinds)e.register(s,{cardinality:"many",fidelity:"full"},o,i),e.register(s,{cardinality:"many",fidelity:"summary"},o,i)}}function zt(e,n,r){r.length>0&&pr(e,{schema:n,lenses:r.map(({lens:t,...o})=>({...o,name:t}))},!0)}function Kt(e,n,r){zt(e,n,Xe(r))}var U=w(O(),1),Ce=w(x(),1);var rn=e=>`graview:first-look:${e}`;function jt(e,n){if(e.seen!==void 0)try{return typeof e.seen=="function"?e.seen():e.seen}catch{return!0}try{return window.localStorage.getItem(rn(n))!==null}catch{return!1}}function Gt(e,n){if(e.seen===void 0)try{window.localStorage.setItem(rn(n),"seen")}catch{}}var qt=R(M(()=>(__graviewPreload(import.meta.url,["./chunk.3VEZ5MOC.js","./chunk.SDO3U72B.js","./chunk.6AANHELP.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.QWLK3GKG.js")))),Yt=qt.part((e,n)=>{let r=e.FirstLookHints;return(0,Ce.jsx)(r,{...n})},{quiet:!0});function Qt({firstLook:e,root:n,app:r}){let t=(0,U.useRef)(null);t.current=e===!0?{}:e||null;let[o,i]=(0,U.useState)(()=>t.current!==null&&typeof window<"u"&&!jt(t.current,r)),s=(0,U.useCallback)(p=>{if(i(!1),p===null)return;let l=t.current??{};Gt(l,r),l.onDone?.(p)},[r]);return!o||t.current===null?null:(0,Ce.jsx)(U.Suspense,{fallback:null,children:(0,Ce.jsx)(Yt,{root:n,steps:t.current.steps??[],onEnd:s})})}export{Ut as a,Pe as b,Jt as c,Nr as d,Xt as e,_n as f,Zt as g,ce as h,Wr as i,zr as j,Hr as k,Cr as l,Le as m,Mr as n,Or as o,Rr as p,Vr as q,$r as r,Dr as s,E as t,Yr as u,Qr as v,Jn as w,Ur as x,ae as y,Xr as z,Ye as A,yt as B,Lt as C,At as D,mt as E,ht as F,Xe as G,Bt as H,ir as I,sr as J,Tt as K,Wt as L,zt as M,Kt as N,Ht as O,Rt as P,Qt as Q};
@@ -1 +1 @@
1
- import{d as pn,f as yn}from"./chunk.X226YATK.js";import{a as mn}from"./chunk.M7KXQGQL.js";import{Fd as qe,Xb as ue,fc as Z,ga as Fe,la as L,oa as K,ta as Le}from"./chunk.ZEZUKRC6.js";var me="I couldn't work out how to do that \u2014 try saying it another way.";function ee(n){let e=n.trim();return e.length===0||!/^[\p{Lu}\p{N}"“‘'(]/u.test(e)||!/[.!?…][”’"')]*$/u.test(e)||e.split(/\s+/).filter(Boolean).length<3?!1:!/[{}[\]]|\b[a-z]+_[a-z_]+\b/.test(e)}function Jn(n,e=me){return n&&ee(n)?n.trim():e}function wn(n,e,t,s,i=40){let o=n.seenBy(e).graph,c=n.schema,u=y=>{let k=o.getNode(y);return k?L(c.tryDefinition(k.kind),k):void 0};return t.slice(0,i).flatMap(y=>{let k=o.getNode(y);if(!k)return[];let r=Object.fromEntries(Object.entries(k).filter(([g,b])=>!["id","kind","label"].includes(g)&&!g.startsWith("_")&&b!==void 0&&b!==null&&(typeof b!="object"||Array.isArray(b))&&JSON.stringify(b).length<=200).map(([g,b])=>[g,typeof b=="string"&&s?kn(b,s):b])),h=[...o.outEdges(y).flatMap(g=>{let b=u(g.to);return b?[`${Fe(g.kind).toLowerCase()} ${b}`]:[]}),...o.inEdges(y).flatMap(g=>{let b=u(g.from);return b?[`${Fe(g.kind).toLowerCase()} it: ${b}`]:[]})].slice(0,12);return[{id:y,kind:k.kind,label:u(y)??y,fields:r,links:h}]})}var Wn=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function kn(n,e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(n.slice(0,10)),s=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e.slice(0,10));if(!t||!s||n.length!==10)return n;let i=Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3])),o=Date.UTC(Number(s[1]),Number(s[2])-1,Number(s[3])),c=Math.round((i-o)/864e5),u=c===0?"today":c===1?"tomorrow":c===-1?"yesterday, already past":c>0?`in ${c} days`:`${-c} days ago, already past`;return`${n}, ${Wn[new Date(i).getUTCDay()]}, ${u}`}function bn(n){return kn(n,n).replace(/, today$/,"")}var He=.6,Fn=.75,qn=new Set(["person","people","user","users","member","members","volunteer","volunteers","staff","contact","contacts","employee","employees","client","clients","customer","customers","guest","guests","player","players","student","students"]),we=n=>n.charAt(0).toUpperCase()+n.slice(1),Hn={assign:!0,reassign:!0,give:!0,hand:!0,delegate:!0,allocate:!0};function Ye(n,e){let t=n.graph.getNode(e);if(!t)return;let s=new Map;for(let o of[...n.graph.in(e),...n.graph.out(e)])o.kind!==t.kind&&s.set(o.kind,[...new Set([...s.get(o.kind)??[],o.id])]);let i=[...s.entries()].sort((o,c)=>c[1].length-o[1].length)[0];return i&&i[1].length>1?{kind:i[0],ids:i[1]}:void 0}function he(n){let e=n.schema,t=e.definitions.filter(s=>s.people).map(s=>s.kind);return[...new Set([...t,...e.definitions.filter(s=>[s.kind,s.noun,K(e,s.kind)].some(i=>i!==void 0&&qn.has(i.toLowerCase()))).map(s=>s.kind)])]}function Ge(n){let e=/^\s*([\p{L}][\p{L}'’-]*)\s+(?:should|can|will|could|is going to|needs to)\s+(?:take care of|handle|own|do|look after|take|deal with|pick up|be on)\b/iu.exec(n)?.[1]??/\bmake\s+(?:this|these|it|them|this one)\s+([\p{L}][\p{L}-]*)['’]s\b/iu.exec(n)?.[1]??/\b(?:this|these|it|they)\s+(?:is|are)\s+([\p{L}][\p{L}-]*)['’]s\b/iu.exec(n)?.[1]??/\b([\p{L}][\p{L}-]*)['’]s\s+(?:job|task|responsibility|shift|now)\b/iu.exec(n)?.[1]??/^\s*([\p{L}][\p{L}-]*)['’]s\s+(?:on|got|doing|handling|taking|covering)\s+(?:this|it|these|that|them)\b/iu.exec(n)?.[1]??/^\s*([\p{L}][\p{L}-]*)\s+(?:has|has got|is on|is doing|is handling|is taking|is covering|takes|does|owns)\s+(?:this|it|these|that|them)(?:\s+one)?\b/iu.exec(n)?.[1];if(e&&!/^(it|this|that|these|those|they|we|you|i|he|she|everyone|someone|anyone|nobody|nothing|who|what|which|there|it's|that's|who's|what's)$/i.test(e))return{called:"assigned to",who:we(e),owned:!0};let t=/\bto\s+([\p{L}][\p{L}'’-]*)\s*[.!?]*\s*$/iu.exec(n)?.[1];if(n.toLowerCase().split(/[^a-z]+/).find(i=>i in Hn))return{called:"assigned to",...t?{who:we(t)}:{}}}var Sn=["done","completed","finished","closed"],Gn=["due","dueDate","dueOn","deadline"];function Qe(n,e){return e.which!=="held"||e.part?!1:/\b(that'?s|that is|that are|that were|that have|that has|which|whose|already|except|but not|only|apart from|other than)\b/i.test(n)||/\bones? (that|which|i|we|you|i'?ve|we'?ve|i'?m)\b/i.test(n)||xn(n)||Oe(n).open||Oe(n).finished}function de(n){if(n?.type!=="choice")return;let e=n.probabilities[n.choice]??n.confidence;return{key:n.choice,chance:e}}async function An(n,e){let{store:t,target:s,said:i}=e,o=t.schema,c=`${i} ${e.follows?.said??""}`.trim(),u=s.on==="record"?t.graph.getNode(s.id):void 0,y=u?Ye(t,u.id):void 0,k=(e.members??[]).filter(a=>t.graph.getNode(a)!==void 0),r=[],h=e.where?` in ${e.where}`:u?` in ${L(o.tryDefinition(u.kind),u)}`:"",g=a=>K(o,a).toLowerCase(),b=a=>(o.tryDefinition(a)?.noun??a).toLowerCase();u&&r.push({which:"itself",records:[u.id],kind:u.kind,words:`${L(o.tryDefinition(u.kind),u)} itself`,close:!1});let f=y??(k.length>0?{kind:t.graph.getNode(k[0]).kind,ids:k.filter(a=>t.graph.getNode(a).kind===t.graph.getNode(k[0]).kind)}:void 0),p=(a,w,x)=>`the ${a.length}${x?` ${x}`:""} ${a.length===1?b(w):g(w)}${h}`;f&&f.ids.length>0&&r.push({which:"held",records:f.ids,kind:f.kind,words:p(f.ids,f.kind),close:!1});let v=e.follows?/\bcall (?:it|that|the field)\s+["“']?([\p{L}][\p{L} ]*?)["”']?\s*[.!]*\s*$/iu.exec(i)?.[1]:void 0;if(v&&e.follows?.reading&&r.some(a=>a.which===e.follows.reading)&&r.splice(0,r.length,...r.filter(a=>a.which===e.follows.reading)),r.length===0)return{sure:!1,usage:{inputTokens:0,outputTokens:0}};let R=a=>Sn.some(w=>t.graph.getNode(a)?.[w]===!0),N=t.today?.()??new Date().toISOString().slice(0,10),A=a=>Gn.map(w=>t.graph.getNode(a)?.[w]).find(w=>typeof w=="string"),J=[];if(f&&f.ids.length>1){let a=f.ids.filter(R),w=f.ids.filter(j=>!R(j)),x=w.filter(j=>(A(j)??"9999")<N.slice(0,10));a.length>0&&a.length<f.ids.length&&J.push({which:"held",part:"done",records:a,kind:f.kind,words:p(a,f.kind,"done"),close:!1}),w.length>0&&w.length<f.ids.length&&J.push({which:"held",part:"open",records:w,kind:f.kind,words:p(w,f.kind,"open"),close:!1}),x.length>0&&x.length<f.ids.length&&J.push({which:"held",part:"late",records:x,kind:f.kind,words:p(x,f.kind,"late"),close:!1})}let M=v?r:[...r,...J],$e=a=>a.part??a.which,Y={};M.length>1&&(Y.reading={type:"choice",instructions:`Someone said \u201C${i}\u201D${e.follows?`, replying to \u201C${e.follows.said}\u201D${e.follows.reading?`, which was taken as ${e.follows.reading==="itself"?"the record itself":"the records it holds"}`:""}`:""}. Which records do they mean? "This", "it" or its name alone is the record itself; "these", "all", "them", "everything", "the lot" are never the record itself but every record it holds \u2014 unless more words say which of them: "the done ones", "that are finished", "already ticked off", "completed" mean the done ones; "outstanding", "remaining", "unfinished", "still to do", "except the done ones" mean the open ones; "late" or "overdue" the late ones. A word that says the change to make ("mark these done", "close these", "finish them") says what to do, not which records. If their words pick out some records in a way none of these says ("the old ones"), choose "something else".`,criteria:{...Object.fromEntries(M.map(a=>[$e(a),a.which==="itself"?`${we(a.words)} (the ${b(a.kind)})`:we(a.words)])),else:"Something else: some other part of them"}}),Y.where={type:"choice",instructions:`Does \u201C${i}\u201D want something done to the records of this app (or an answer about them), or something done outside the app \u2014 an email or a text sent, a call made, a payment, a booking, a post somewhere?`,criteria:{inside:"Inside the app: its records, or an answer about them",outside:"Outside the app: send, call, pay, book or post somewhere else"}},Y.mood={type:"choice",instructions:`Does \u201C${i}\u201D ask something, wanting an answer in words, or tell me to do something, wanting a change made? A question can come without a question mark ("has this been done yet"), an instruction can be polite ("could you close these"), and saying who has something ("Sam's on this", "Nora has this one") tells me to give it to them.`,criteria:{asks:"Asks something: wants an answer in words",tells:"Tells me to do something: wants a change made"}};let W=a=>t.allMutations().filter(w=>w.subject&&(w.subject.kinds==="*"||w.subject.kinds.includes(a))),C=r.flatMap(a=>W(a.kind).slice(0,24).map(w=>({key:`${a.which}:${w.name}`,reading:a,mutation:w})));Y.act={type:"choice",instructions:`Which of these acts does \u201C${c}\u201D ask to be done? Judge each by what it does, not only its title: people say "close", "complete", "check off", "tick" or "finish" for an act that marks something done, "delete" for one that removes, "push" or "move" for one that changes a date or a place. A question, or "undo that", is none of them. "none" only where no act here does it.`,criteria:{...Object.fromEntries(C.map(a=>[a.key,`${a.mutation.title??a.mutation.name}: ${tt(a.mutation.description)}${nn(a.mutation,o,a.reading.kind)} \u2014 on ${a.reading.which==="itself"?`the ${b(a.reading.kind)} itself`:`each of ${a.reading.words}`}`])),none:"None of these acts does it"}};let re=he(t),D=new Set([...re,...C.flatMap(a=>Z(a.mutation.input).filter(w=>w.name!==a.mutation.subject.arg).flatMap(w=>w.kinds))]),F=t.graph.allNodes().filter(a=>D.has(a.kind)||D.has("*")),De=new Set(c.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(a=>a.length>=3).map(a=>a.slice(0,4))),te=a=>L(o.tryDefinition(a.kind),a),xe=(F.length<=25?F:F.filter(a=>te(a).toLowerCase().split(/[^\p{L}\p{N}]+/u).some(w=>w.length>=3&&De.has(w.slice(0,4))))).filter(a=>a.id!==u?.id&&!r.some(w=>w.records.includes(a.id))).slice(0,25),se=ze.test(i)?Yn(t,e.principal,D):void 0,Q=ze.test(i)&&e.principal?Qn(t,e.principal.id):void 0,ge=zn.exec(i),q=(ge?.[1]??ge?.[2])?.toLowerCase(),ce=q?Kn(t,u?.id,e.follows?.said,re):[];q&&ce.length>1&&(Y.pronoun={type:"choice",instructions:`In \u201C${i}\u201D${e.follows?`, said after \u201C${e.follows.said}\u201D`:""}, whom does \u201C${q}\u201D mean?`,criteria:{...Object.fromEntries(ce.map(a=>[`r:${a.id}`,te(a)])),else:"Someone else"}}),xe.length>0&&(Y.named={type:"choice",instructions:`Which of these does \u201C${c}\u201D name, as the one to give it to, move it to, link it with or put it on?`,criteria:{...Object.fromEntries(xe.map(a=>[`r:${a.id}`,`${te(a)} (${Le(b(a.kind))})`])),new:"Someone or something not listed here",none:"None is named"}}),Y.need={type:"choice",instructions:`If no act here can do \u201C${c}\u201D, what would each record need?`,criteria:{person:"A link to the person it is given or assigned to",other:"Something else: a field, a date, a number, a note",none:"Nothing: an act here can do it"}};let O=await n.decide({said:i,...e.follows?{replyingTo:e.follows.said}:{},readings:M.map(a=>a.words),...e.examples&&e.examples.length>0?{workedBefore:e.examples}:{}},Y),pe=de(O.answers.mood),d=Ge(i)?.owned===!0&&!/\?\s*$/.test(i)?!1:pe&&pe.chance>=.6?pe.key==="asks":Ze(i),S=de(O.answers.where);if(!d&&Ve(i)&&S?.key==="outside"&&S.chance>=.6)return{sure:!0,asks:!1,outside:Xe(t,i,u?.id),usage:O.usage};let l=de(O.answers.reading),T=M.length>1?M.find(a=>$e(a)===l?.key):M[0];if(!T){let a=de(O.answers.act),w=a&&a.key!=="none"?C.find(x=>x.key===a.key):void 0;if(!d&&w&&_e(w.mutation)&&f&&f.ids.length>1){let x=(w.mutation.title??w.mutation.name).trim().split(/\s+/)[0].toLowerCase();return{sure:!0,asks:!1,clarify:`Which of the ${f.ids.length} ${g(f.kind)}${h} should I ${x}? Say which, or \u201Call\u201D.`,usage:O.usage}}return{sure:!1,asks:d,usage:O.usage}}let $={...T,close:M.length>1&&(l?.chance??1)<Fn,chance:M.length>1?l?.chance??0:1},m=de(O.answers.act),P=de(O.answers.named),V=de(O.answers.pronoun),z=q?ce.length===1?ce[0]:V?.key.startsWith("r:")?t.graph.getNode(V.key.slice(2)):void 0:void 0,X=q&&z?{said:q,as:te(z)}:void 0,H=se??z??(P?.key.startsWith("r:")&&P.chance>=He?t.graph.getNode(P.key.slice(2)):void 0),le=Ge(i)??Ge(c),dn=le?.who&&(ze.test(le.who)?se?te(se):Q:Bn.test(le.who)?z?te(z):void 0:le.who),Ue=le?{called:le.called,...dn?{who:dn}:{},...le.owned?{owned:!0}:{}}:void 0,ie=Ue&&v?{...Ue,called:v.toLowerCase()}:Ue,En=O.answers.reading?.type==="choice"?Object.entries(O.answers.reading.probabilities).filter(([a])=>a!==l?.key).reduce((a,[,w])=>Math.max(a,w),0):0;if(!(M.length===1||(l?.chance??0)>=.5||(l?.chance??0)>=.35&&(l?.chance??0)>=1.5*En))return{sure:!1,asks:d,reading:$,usage:O.usage};let je=(a,w)=>Z(a.input).some(x=>x.name!==a.subject.arg&&(x.kinds.includes("*")||x.kinds.some(j=>w.includes(j)))),cn=[...re,...H?[H.kind]:[]];if(d||en.test(i))return{sure:!1,asks:d,reading:$,usage:O.usage};let fe=nt(O.answers.act),oe=a=>C.find(w=>w.mutation.name===a&&w.reading.which===$.which),ln=a=>!!(a&&(a.mutation.destructive||a.mutation.derived?.act==="remove")),I=m&&m.key!=="none"?m.key.slice(m.key.indexOf(":")+1):void 0,ae=m!==void 0&&m.key!=="none"&&m.chance>=He;if(!ae&&fe.length>1&&fe[0].chance+fe[1].chance>=.8&&ln(oe(fe[0].name))&&ln(oe(fe[1].name))&&(ae=!0),I&&H&&oe(I)&&!je(oe(I).mutation,[H.kind])){let a=oe(I).mutation,w=new Set(Z(a.input).map(E=>E.name)),x=Object.entries(a.input?.shape??{}).some(([E,G])=>!w.has(E)&&!G.safeParse(void 0).success&&!G.safeParse(Me(i)).success),j=P&&P.chance>=.9&&x?0:.05,U=fe.filter(E=>E.chance>=j).map(E=>oe(E.name)).find(E=>E&&E.mutation.derived?.act!=="merge"&&je(E.mutation,[H.kind]));U&&(I=U.mutation.name,ae=!0)}if(!ae&&H&&ie?.who&&(X||se||ie.owned)){let a=C.filter(w=>w.reading.which===$.which&&w.mutation.derived?.act!=="merge"&&Z(w.mutation.input).some(x=>x.name!==w.mutation.subject.arg&&Be(t,H,x.kinds)!==void 0&&re.some(j=>x.kinds.includes(j))));a.length===1&&(I=a[0].mutation.name,ae=!0)}if(!ae&&H){let a=fe.filter(w=>w.chance>=.3).map(w=>oe(w.name)).find(w=>w&&w.mutation.derived?.act!=="merge"&&Z(w.mutation.input).some(x=>x.name!==w.mutation.subject.arg&&Be(t,H,x.kinds)!==void 0));a&&(I=a.mutation.name,ae=!0)}let Je=v===void 0?et(i):void 0,fn=r.find(a=>a.which==="itself");if(Je&&fn){let a=["label","name","title"],w=C.find(U=>{let E=(ue(U.mutation)??[]).filter(G=>G!==U.mutation.subject.arg);return U.reading.which==="itself"&&E.length===1&&(a.includes(E[0])||(U.mutation.writes??[]).some(G=>a.includes(G)))}),x=w?(ue(w.mutation)??[]).find(U=>U!==w.mutation.subject.arg):void 0,j=x?(w.mutation.input?.shape??{})[x]:void 0;if(w&&x&&j?.safeParse(Je).success)return{sure:!0,reading:{...fn,close:!1},each:{act:w.mutation.name,args:{[x]:Je}},usage:O.usage}}if(I&&!oe(I)){let a=C.find(j=>j.mutation.name===I),w=j=>{let U=a?.mutation?.derived?.act,E=j.mutation.derived?.act;return U!==void 0?U===E:(j.mutation.title??j.mutation.name).split(/\s+/)[0].toLowerCase()===(a?.mutation.title??I??"").split(/\s+/)[0].toLowerCase()},x=C.find(j=>j.reading.which===$.which&&w(j));x&&(I=x.mutation.name)}let B=I&&ae?oe(I):void 0;if(B&&!(ie?.who&&!je(B.mutation,cn))){let a=(ue(B.mutation)??[]).filter(G=>G!==B.mutation.subject.arg),w=Z(B.mutation.input),x=B.mutation.input?.shape??{},j={},U=!0;for(let G of a){let ye=w.find(We=>We.name===G),hn=ye?ye.optional:x[G]?.safeParse(void 0).success??!0,gn=ye&&H?Be(t,H,ye.kinds):void 0;ye&&gn?j[G]=gn.id:!ye&&!hn&&a.filter(We=>!w.some(Un=>Un.name===We)).length===1&&Me(i)!==void 0&&x[G]?.safeParse(Me(i)).success?j[G]=Me(i):hn||(U=!1)}if(B.mutation.derived?.act==="edit"&&Object.keys(j).length===0&&(U=!1),!U)return{sure:!1,reading:$,...X?{taken:X}:{},act:B.mutation.name,usage:O.usage};let E=M.length===1||(l?.chance??0)>=Ke(B.mutation,i);return _e(B.mutation)&&$.records.length>1&&(!E||Qe(i,$))?{sure:!0,reading:$,clarify:Vn(t,B.mutation.title??B.mutation.name,$),usage:O.usage}:{sure:!0,reading:$,...X?{taken:X}:{},each:{act:B.mutation.name,args:j},usage:O.usage}}let un=de(O.answers.need),In=C.some(a=>a.reading.which===$.which&&je(a.mutation,cn));if(ie?.who&&!In&&(un?.key==="person"&&un.chance>=He||se!==void 0||Q!==void 0||X!==void 0||ie.owned===!0)){let a=ie.who??(H&&re.includes(H.kind)?te(H):void 0);if(!a)return{sure:!1,reading:$,usage:O.usage};let w=v?`${we(g($.kind))} have no ${ie.called}.`:`${we(g($.kind))} have no one ${ie.called} them.`;return{sure:!0,reading:$,...X?{taken:X}:{},missing:{said:w,need:{link:{on:$.kind,called:ie.called,to:"person"}},who:a},text:w,usage:O.usage}}return{sure:!1,reading:$,...X?{taken:X}:{},...I&&m&&m.chance>=.3?{act:I}:{},usage:O.usage}}var ze=/\b(me|my|mine|myself)\b/i,zn=/\b(?:to|off|from|for|with)\s+(her|him|them|that person|whoever)\b|\b(?:take|put|move|swap|drop)\s+(her|him)\b/i,Bn=/^(her|him|them|they|that person|whoever)$/i;function Yn(n,e,t){if(!e)return;let s=n.graph.getNode(e.id),i=s?L(n.schema.tryDefinition(s.kind),s).toLowerCase():void 0;return(i?n.graph.allNodes().find(c=>c.id!==e.id&&t.has(c.kind)&&L(n.schema.tryDefinition(c.kind),c).toLowerCase()===i):void 0)??(s&&t.has(s.kind),s)}function Qn(n,e){let t=n.graph.getNode(e);return t?L(n.schema.tryDefinition(t.kind),t):void 0}function Kn(n,e,t,s){let i=n.schema,o=e?[...n.graph.in(e),...n.graph.out(e)].filter(r=>s.includes(r.kind)):[],c=(t??"").toLowerCase(),y=[...c?n.graph.allNodes().filter(r=>s.includes(r.kind)&&L(i.tryDefinition(r.kind),r).toLowerCase().split(/\s+/).some(h=>h.length>=3&&new RegExp(`\\b${h.replace(/[^\p{L}\p{N}]/gu,"")}\\b`,"u").test(c))):[],...o],k=r=>L(i.tryDefinition(r.kind),r).toLowerCase();return y.filter((r,h)=>y.findIndex(g=>k(g)===k(r))===h).slice(0,8)}function Be(n,e,t){if(t.includes("*")||t.includes(e.kind))return e;let s=n.schema,i=L(s.tryDefinition(e.kind),n.graph.getNode(e.id)).toLowerCase();return n.graph.allNodes().find(o=>t.includes(o.kind)&&L(s.tryDefinition(o.kind),o).toLowerCase()===i)}function vn(n){let e=n.split(/\s*(?:,\s*and then|,\s*then|\band then\b|;|\bthen\b|,?\s+and\s+)\s*/i).map(i=>i.trim()).filter(Boolean);if(e.length<2||e.length>3)return[n];let t=/^(the|a|an|my|our|your|this|these|that|those|all|every|each|some|it|them|they|he|she|i|we|you|to|for|with|on|in|at|by|of|from|tomorrow|today|tonight|monday|tuesday|wednesday|thursday|friday|saturday|sunday)$/i,s=i=>{let o=i.split(/\s+/);return o.length>=2&&/^[a-z]/.test(o[0])&&!t.test(o[0])};return e.every(s)?e:[n]}function Oe(n,e=!1){let t=n.toLowerCase(),s=/\b(done|finished|completed|complete|closed|ticked|checked)( off)? (ones?|tasks?|items?|stuff|things|bits)\b/.test(t)||/\b(ones?|tasks?|items?|things|stuff) (i'?ve|we'?ve|i have|we have|that are|that'?s|already) (done|finished|completed|closed|ticked off)\b/.test(t)||/\balready (done|finished|completed)\b/.test(t)||/\bthe (finished|completed)\b/.test(t),i=/\b(outstanding|remaining|unfinished|undone|incomplete|pending)\b/.test(t)||/\b(still to do|left to do|not done|not finished|not yet done)\b/.test(t)||/\b(open) (ones?|tasks?|items?|stuff|things)\b/.test(t)||e&&/\bopen\b/.test(t);return s&&i?{open:!1,finished:!1}:{open:i,finished:s}}function $n(n){let{open:e,finished:t}=Oe(n);return e||t?!0:xn(n)?!1:/\b(all|every|each|everything|the lot|the whole (list|lot)|every one|both|these|those)\b/i.test(n)}function xn(n){let e=/\bthe ([a-z]+) (ones?|tasks?|items?|stuff|things|shifts?|songs?)\b/i.exec(n)?.[1]?.toLowerCase();return e!==void 0&&!["other","rest","whole","same"].includes(e)&&!Oe(`the ${e} ones`).open&&!Oe(`the ${e} ones`).finished}function Ke(n,e){return n.derived?.act==="archive"&&n.destructive!==!0&&/\b(these|those|all|everything|every one|each|them|the lot|the whole (list|lot))\b/i.test(e)?.75:.9}function _e(n){return n.destructive===!0||n.derived?.act==="remove"||n.derived?.act==="archive"}function Vn(n,e,t){let s=n.schema,i=e.trim().split(/\s+/)[0].toLowerCase(),o=h=>Sn.some(g=>n.graph.getNode(h)?.[g]===!0),c=t.records.filter(o),u=(s.tryDefinition(t.kind)?.noun??t.kind).toLowerCase(),y=K(s,t.kind).toLowerCase(),k=/ (in .+)$/.exec(t.words)?.[1],r=`all ${t.records.length} ${y}${k?` ${k}`:""}`;return c.length>0&&c.length<t.records.length?`Should I ${i} the ${c.length} done ${c.length===1?u:y}, or ${r}?`:`Should I ${i} ${r}? Say \u201Call\u201D to go ahead, or say which.`}function Ve(n){let e=/^\s*(?:please\s+|pls\s+|could you\s+|can you\s+|would you\s+|can we\s+|let'?s\s+)?(e-?mail|mail|text|sms|message|whatsapp|call|phone|ring|dial|pay|venmo|book|reserve|post|tweet|share)\b(.*)$/i.exec(n);return e!==null&&!/^\s+(?:it|this|that|this one)\s+(?:[A-Z“"']|as\b|to\b)/.test(e[2]??"")}var Xn=[[/\b(e-?mail|mail)\b/i,"send email"],[/\b(text|sms|message|whatsapp|dm)\b/i,"send messages"],[/\b(call|phone|ring|dial)\b/i,"make calls"],[/\b(pay|venmo|transfer|invoice)\b/i,"make payments"],[/\b(book|reserve)\b/i,"book things"],[/\b(post|tweet|share)\b/i,"post outside this app"]];function Xe(n,e,t){let s=Xn.find(([c])=>c.test(e))?.[1]??"do things outside this app",i=t?n.graph.getNode(t):void 0,o=i?Object.values(i).find(c=>typeof c=="string"&&(/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(c)||/^https?:\/\//.test(c))):void 0;return o?`I can't ${s} from here, but its ${o.includes("@")&&!o.startsWith("http")?"email":"link"} is ${o} \u2014 open it to do that.`:`I can't ${s} from here: this app keeps your records, and doing that happens outside it.`}function Ze(n){return Zn(n)?!1:/\?\s*$/.test(n)||/^\s*(who|whom|whose|what|whats|what's|when|where|which|why|how|is|are|was|were|can|could|should|any|anything|tell me|show me|list)\b/i.test(n)||/^\s*(do|does|did)\s+(you|we|i|they|it|he|she|anyone|anybody|any)\b/i.test(n)}function Zn(n){let e=n.trim().toLowerCase();return!!(/^(please|pls|kindly)\b/.test(e)||/^(could|can|would|will) (you|we|u)\s+(please\s+)?(?!tell|say|explain|show me what|see)\w+/.test(e)&&!/^(could|can|would|will) (you|we) (be|have)\b/.test(e)||/^(i'?d like|i would like|i want|i need|let'?s|we should|we need to)\b/.test(e)||/^[\p{L}'’]+(\s[\p{L}'’]+)?\s+(should|needs to|need to|has to|have to|ought to)\s+(be\s+)?\w+/u.test(e)&&!/^(what|who|which|when|where|why|how|is|are|do|does)\b/.test(e))}function et(n){let e=n.trim().replace(/[.!]+$/,""),t=[/^(?:the\s+|its\s+|this\s+|list\s+|task\s+)*name\s+should\s+be\s+["“']?(.+?)["”']?$/i,/^(?:please\s+)?call\s+(?:this one|this list|this task|this shift|this song|it|this)\s+["“']?(.+?)["”']?$/i,/^["“']?(.+?)["”']?\s+is\s+a\s+better\s+name$/i,/^(?:please\s+)?(?:re)?name\s+(?:this one|this list|this task|this shift|this song|it|this)\s+(?:to\s+|as\s+)?["“']?(.+?)["”']?$/i,/^(?:let'?s\s+)?call\s+(?:it|this)\s+["“']?(.+?)["”']?$/i];for(let s of t){let i=s.exec(e)?.[1]?.trim();if(i)return i}}var en=/^\s*(undo|take (that|it) back|revert|go back)\b/i;function Me(n){let e=/\b(?:to|as)\s+["“']?(.+?)["”']?\s*[.!]?\s*$/i.exec(n)?.[1]?.trim();return e&&e.length>0?e:void 0}function nt(n){return n?.type!=="choice"?[]:Object.entries(n.probabilities).filter(([e])=>e!=="none").sort((e,t)=>t[1]-e[1]).map(([e,t])=>({name:e.slice(e.indexOf(":")+1),chance:t}))}function tt(n){let e=n?.trim();return e?`${e}${/[.!?]$/.test(e)?"":"."} `:""}function nn(n,e,t){let s=[],i=(ue(n)??[]).filter(r=>r!==n.subject?.arg),o=Z(n.input).filter(r=>r.name!==n.subject?.arg),c=e.tryDefinition(t)?.fields?.shape??{},u=r=>c[r]?._zod?.def?.type==="optional"?c[r]?._zod?.def?.innerType?._zod?.def?.type:c[r]?._zod?.def?.type,y=n.derived?.act;y==="remove"?s.push("removes it"):y==="archive"?s.push("sets it aside in the archive"):y==="unarchive"?s.push("brings it back from the archive"):y==="merge"?s.push("merges it into another"):y==="edit"&&s.push("changes any of its fields to values given");for(let r of n.writes??[])n.sets&&r in n.sets?s.push(`sets ${r} to ${String(n.sets[r])}`):i.includes(r)?s.push(`sets ${r} to a value given`):u(r)==="boolean"?s.push(`sets ${r} yes or no`):s.push(`changes ${r}`);for(let r of i)!(n.writes??[]).includes(r)&&!o.some(h=>h.name===r)&&y!=="edit"&&s.push(`takes ${r}`);let k=[...new Set(o.flatMap(r=>r.kinds))].filter(r=>r!=="*").join(" or ");return(n.connects?.length??0)>0&&(n.severs?.length??0)>0?s.push(`moves it to another ${k||"record"}`):(n.connects?.length??0)>0?s.push(`links it to ${Le(k||"record")}`):(n.severs?.length??0)>0&&s.push(`unlinks it from ${Le(k||"record")}`),n.destructive&&y!=="remove"&&s.push("removes it for good"),(n.creates?.length??0)>0&&s.push(`adds a new ${n.creates.join(" or ")}`),s.length>0?`(It ${s.join(", ")}.)`:""}var st=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],it=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function tn(n){let e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(n);if(!e)return;let t=new Date(Date.UTC(Number(e[1]),Number(e[2])-1,Number(e[3])));return`${st[t.getUTCDay()]}, ${it[t.getUTCMonth()]} ${t.getUTCDate()}`}function sn(n,e){let t=n.schema;if(e.records.length===1&&typeof e.act.describe=="function"&&e.act.subject)try{let f=e.act.describe({...e.args,[e.act.subject.arg]:e.records[0]},n.graph);if(typeof f=="string"&&f.trim()){let p=he(n),v=[e.records[0]].filter(A=>n.graph.getNode(A)!==void 0).map(A=>n.graph.getNode(A)).filter(A=>!p.includes(A.kind)).map(A=>L(t.tryDefinition(A.kind),A)).sort((A,J)=>J.length-A.length),R=f.trim().replace(/"([^"]*)"/g,"\u201C$1\u201D");for(let A of v)R.includes(`\u201C${A}\u201D`)||(R=R.replace(A,`\u201C${A}\u201D`));let N=R.replace(/\b(\d{4}-\d{2}-\d{2})\b/g,A=>tn(A)??A).replace(/[.!]+$/,"");return`${N.charAt(0).toUpperCase()}${N.slice(1)}.`}}catch{}let s=f=>{let p=n.graph.getNode(f);return p?L(t.tryDefinition(p.kind),p):void 0},i=Z(e.act.input),o=e.act.subject?.arg,c=Object.entries(e.args).filter(([f,p])=>f!==o&&p!==void 0&&p!==null&&p!=="").map(([f,p])=>{if(i.find(R=>R.name===f)&&typeof p=="string"){let R=n.graph.getNode(p),N=s(p)??p;return{arg:f,said:R?N:p,ref:!0}}return typeof p=="string"?{arg:f,said:tn(p)??`\u201C${p}\u201D`,ref:!1}:{arg:f,said:String(p),ref:!1}}),y=(e.records[0]?n.graph.getNode(e.records[0]):void 0)?.kind,k=y?(t.tryDefinition(y)?.noun??y).toLowerCase():"record",r=e.records.length,h=e.itself&&r===1&&e.records[0]?s(e.records[0])?`\u201C${s(e.records[0])}\u201D`:"it":`the ${r}${e.narrowed?` ${e.narrowed}`:""} ${r===1?k:y?K(t,y).toLowerCase():"records"}${e.where?` ${e.where}`:""}`,g=(e.act.title??e.act.name).trim().replace(/[.!]+$/,""),b=/\b(it|this|the (?:task|list|shift|record|song|item))\b/i;if(/^(they|it|this|she|he|somebody|someone)\b/i.test(g))return g=g.replace(/^(they|it|this|she|he|somebody|someone)\b/i,h).replace(/^(\S.*?)\s+\b(have|are)\b/i,(f,p,v)=>`${p} ${r===1?v.toLowerCase()==="have"?"has":"is":v}`),`${g.charAt(0).toUpperCase()}${g.slice(1)}.`;g=b.test(g)?g.replace(b,h):/^\S+ the \w+$/i.test(g)?`${g} of ${h}`:g.replace(/^(\S+)/,`$1 ${h}`);for(let f of c)/\b(?:to|into|on) another \w+/i.test(g)?g=g.replace(/\b(to|into|on) another \w+/i,`$1 ${f.said}`):/\banother \w+/i.test(g)?g=g.replace(/\banother \w+/i,f.said):g=`${g} ${f.ref&&!/\bto\b/i.test(g)&&/^(cover|assign|give)/i.test(g)?"with":"to"} ${f.said}`;return`${g.charAt(0).toUpperCase()}${g.slice(1)}.`}function On(n,e,t){let s=n.schema,i=he(n),o=h=>{let g=n.graph.getNode(h);if(!g)return h;let b=L(s.tryDefinition(g.kind),g);return i.includes(g.kind)?b:`\u201C${b}\u201D`},c=e.writes?.[0],u=t[0]?n.graph.getNode(t[0]):void 0,y=c&&u?u[c]:void 0,k=t.length===1?o(t[0]):`All ${t.length} of them`,r=t.length===1?"is":"are";return c&&typeof y=="boolean"?`Nothing to change: ${k} ${r} already ${y?"":"not "}${c.replace(/[A-Z]/g,h=>` ${h.toLowerCase()}`)}.`:c&&(typeof y=="string"||typeof y=="number")?`Nothing to change: ${t.length===1?`${k}'s`:"their"} ${c.replace(/[A-Z]/g,h=>` ${h.toLowerCase()}`)} ${r==="is"?"is":"are"} already ${tn(String(y))??y}.`:`Nothing to change: ${k} ${r} already as that would leave ${t.length===1?"it":"them"}.`}var Nn="I can't do that here: nothing in this app does what you asked. Try saying it another way.";function Cn(n){return/\b(can'?t|cannot|couldn'?t|won'?t|not|no|isn'?t|doesn'?t|don'?t|unable|nothing|never)\b/i.test(n)?!1:/\b(is|are|was|were|has been|have been|got|gets)\s+(now\s+)?(\w+ed|done|taken|set|put|given|made|gone|off|out|away|moved|removed)\b/i.test(n)||/^(i'?ve|i have|done|marked|moved|removed|archived|renamed|assigned|added|scheduled|deleted|dropped|finished|closed|updated|changed|set|put|took|taken)\b/i.test(n.trim())||/\b(i'?ve|i have)\s+\w+ed\b/i.test(n)}var ot=/\b(not in (this|the) app|isn'?t in (this|the) app|is not in (this|the) app|not (yet )?(a|one of the) (user|member|person|people|volunteer|record)s?|doesn'?t exist|does not exist|no one (called|named)|nobody (called|named)|not found|no such|there is no|there'?s no|no (user|person|member|volunteer|record|one) (called|named))\b/i;function on(n,e){if(!ot.test(e))return[];let t=n.schema,s=he(n),i=e.toLowerCase();return n.graph.allNodes().flatMap(o=>{let c=L(t.tryDefinition(o.kind),o),u=c.split(/\s+/)[0];return c.length>=3&&(i.includes(c.toLowerCase())||s.includes(o.kind)&&u.length>=3&&new RegExp(`\\b${u.toLowerCase().replace(/[^\p{L}\p{N}]/gu,"")}\\b`,"u").test(i))?[{id:o.id,name:c,kind:o.kind}]:[]}).slice(0,5)}function Te(n){if(!n.off)return n.fast??(n.decide?{model:n.name??"decide",decide:n.decide}:void 0)}function Re(n){if(n.off)return;if(n.thinking)return n.thinking;let e=n.name??"model";if(n.complete){let t=n.complete;return{model:e,think:({system:s,prompt:i})=>t({prompt:i,system:s})}}if(n.turn){let t=n.turn;return{model:e,think:async({system:s,prompt:i})=>({text:await t({system:s,messages:[{role:"user",content:i}],tools:[],call:async()=>({error:"No tools here."})})})}}}var Ce=(n,e,t)=>n?e/1e6*(n.inputPerMillion??0)+t/1e6*(n.outputPerMillion??0):void 0,rt=()=>`ai-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;function at(n,e,t=[]){let s=i=>{let o=n.graph.getNode(i);return o?L(n.schema.tryDefinition(o.kind),o):"a record"};switch(e.on){case"record":return s(e.id);case"field":return`${s(e.id)} \xB7 ${e.field}`;case"selection":return`${e.ids.length} records`;case"list":return n.schema.tryDefinition(e.kind)?K(n.schema,e.kind):e.kind;case"lens":case"place":return t.find(i=>i.as===e.place)?.title??(e.place==="home"?"Home":e.place);case"act":return e.act}}var jn=n=>n.type!=="act"||n.asks.length===0,Ee=(n,e)=>({id:n.id,type:n.type,label:n.label,...e!==void 0?{confidence:e}:{}});function be(n,e){let t=e.interaction??rt(),s=pn(e.store,e.target,{principal:e.principal,...e.acts?{acts:e.acts}:{},...e.places?{places:e.places}:{}}),i=yn(e.store,e.target,{principal:e.principal,...e.place?{place:e.place}:{},...e.selection?{selection:e.selection}:{},...e.purpose?{purpose:e.purpose}:{}}),o=[];return{id:t,catalog:s,state:i,entry:{id:t,at:new Date().toISOString(),by:e.by??e.principal,target:e.target,targetLabel:at(e.store,e.target,e.places)},usage:o,meter:c=>{o.push(c),n.meter?.({...c,interaction:t})}}}async function Se(n,e,t,s){let i=await n.decide(e,t),{inputTokens:o,outputTokens:c}=i.usage,u=Ce(n.price,o,c);return s({tier:"fast",model:n.model,inputTokens:o,outputTokens:c,...u!==void 0?{costUsd:u}:{}}),i.answers}async function ne(n,e,t,s,i){let o=await n.think({system:e,prompt:t,state:s.state,catalog:s.catalog}),c=o.usage?.inputTokens,u=o.usage?.outputTokens,y=o.usage?.costUsd??(c!==void 0?Ce(n.price,c,u??0):void 0);return i({tier:"thinking",model:n.model,...c!==void 0?{inputTokens:c}:{},...u!==void 0?{outputTokens:u}:{},...y!==void 0?{costUsd:y}:{}}),mn(o.text)}function Ae(n,e){let t=new Map(n.map((s,i)=>[`c${i+1}`,s]));return{question:{type:"choice",instructions:e,criteria:Object.fromEntries([...t].map(([s,i])=>[s,`${i.label} \u2014 ${i.description}`]))},of:s=>t.get(s)}}function Pe(n,e,t){if(n?.type!=="choice")return[];let s=n,i=Object.entries(s.probabilities).sort((o,c)=>c[1]-o[1]);return i.some(([o])=>o===s.choice)||i.unshift([s.choice,s.confidence]),i.flatMap(([o,c])=>{let u=e(o);return u?[{candidate:u,confidence:c}]:[]}).slice(0,t)}var _=(n,e,t,s)=>({interaction:{...n.entry,ask:{kind:t,said:e??""},offered:[],outcome:"failed",failed:s,usage:[...n.usage]},offers:[]}),ve="AI isn't on here.";async function Et(n,e,t=3){let s=be(n,e),i=e.said??"Suggest",o=s.catalog.candidates.filter(jn).slice(0,24);if(o.length===0)return{interaction:{...s.entry,ask:{kind:"suggest",said:i},offered:[],outcome:"offered",usage:[]},offers:[]};let c=Te(n),u=Re(n),y=[];try{if(c){let{question:k,of:r}=Ae(o,"Which of these would the person most likely want to do next, here?"),h=await Se(c,{...s.state,candidates:o.map(g=>({id:g.id,type:g.type,says:g.description}))},{next:k},s.meter);y=Pe(h.next,r,t)}else if(u){let k=await ne(u,'You suggest what a person most likely wants to do next in an app. Answer only JSON: {"pick": [candidate ids, best first]}. Pick only ids from the candidates.',JSON.stringify({state:s.state,candidates:o.map(h=>({id:h.id,says:h.description}))}),s,s.meter);y=(Array.isArray(k?.pick)?k.pick.filter(h=>typeof h=="string"):[]).flatMap(h=>o.filter(g=>g.id===h)).slice(0,t).map(h=>({candidate:h}))}else return _(s,i,"suggest",ve)}catch(k){return _(s,i,"suggest",k instanceof Error?k.message:String(k))}return{interaction:{...s.entry,ask:{kind:"suggest",said:i},offered:y.map(({candidate:k,confidence:r})=>Ee(k,r)),outcome:"offered",usage:[...s.usage]},offers:y.map(({candidate:k})=>k)}}var dt=n=>`several:${n}`;async function It(n,e,t=2){let s=be(n,{...e,acts:[]}),i=e.said??"Suggest for the chosen",o=e.target.on==="selection"?e.target.ids.length:1,u=[...e.shared.map(r=>({type:"act",id:dt(r.id),label:r.label,description:`${r.label}, for all ${o} chosen`,mutation:r.mutation,args:r.args,asks:[]})),...s.catalog.candidates.filter(r=>r.type==="panel"||r.type==="place")].slice(0,24),y=Te(n);if(!y)return _(s,i,"suggest",ve);if(u.length===0)return{interaction:{...s.entry,ask:{kind:"suggest",said:i},offered:[],outcome:"offered",usage:[]},offers:[]};let k;try{let{question:r,of:h}=Ae(u,`Which of these would the person most likely want to do next with the ${o} records they chose together?`),g=await Se(y,{...s.state,candidates:u.map(b=>({id:b.id,type:b.type,says:b.description}))},{next:r},s.meter);k=Pe(g.next,h,t).filter((b,f)=>f===0||b.confidence>=ct)}catch(r){return _(s,i,"suggest",r instanceof Error?r.message:String(r))}return{interaction:{...s.entry,ask:{kind:"suggest",said:i},offered:k.map(({candidate:r,confidence:h})=>Ee(r,h)),outcome:"offered",usage:[...s.usage]},offers:k.map(({candidate:r})=>r)}}var ct=.25;async function Ut(n,e){let t=be(n,e),s=e.said??"Fill in",i=t.catalog.candidates.filter(h=>h.type==="fill"),o=new Map;for(let h of i)o.set(h.field,[...o.get(h.field)??[],h]);if(o.size===0)return{interaction:{...t.entry,ask:{kind:"fill",said:s},offered:[],outcome:"offered",usage:[]},offers:[]};let c=Te(n),u=Re(n),y=[];try{if(c){let h=[...o].map(([b,f],p)=>({key:`f${p+1}`,field:b,...Ae(f,`Which value fits "${b}" best for this record?`)})),g=await Se(c,t.state,Object.fromEntries(h.map(b=>[b.key,b.question])),t.meter);for(let b of h){let f=!lt(e.store,e.target,b.field)&&ft(e.store,e.target,b.field)!=="one";y.push(...Pe(g[b.key],b.of,f?3:1).filter((p,v)=>v===0||p.confidence>=.4))}}else if(u){let h=await ne(u,`You fill in a record's fields in an app. Answer only JSON: {"fills": [candidate ids]}, at most one per field, only ids from the candidates.`,JSON.stringify({state:t.state,candidates:i.map(f=>({id:f.id,says:f.description}))}),t,t.meter),g=Array.isArray(h?.fills)?h.fills.filter(f=>typeof f=="string"):[],b=new Set;for(let f of g){let p=i.find(v=>v.id===f);p?.type==="fill"&&!b.has(p.field)&&(b.add(p.field),y.push({candidate:p}))}}else return _(t,s,"fill",ve)}catch(h){return _(t,s,"fill",h instanceof Error?h.message:String(h))}let k=t.usage.at(-1)?.model,r=Ie(e.store,{interaction:t.id,target:e.target,basis:s,...k?{model:k}:{},proposals:y.flatMap(({candidate:h,confidence:g})=>h.type==="fill"?[{id:h.id,label:h.label,said:h.description,call:h.call,record:h.record,field:h.field,...g!==void 0?{confidence:g}:{}}]:[])},e.principal);return{interaction:{...t.entry,ask:{kind:"fill",said:s},offered:r.proposals.map(h=>({id:h.id,type:"fill",label:h.label,...h.confidence!==void 0?{confidence:h.confidence}:{}})),outcome:"offered",usage:[...t.usage]},offers:[],...r.proposals.length>0?{ghost:r}:{}}}function lt(n,e,t){let s=e.on==="record"||e.on==="field"?e.id:void 0,i=s?n.graph.getNode(s)?.kind:void 0,o=(i?n.schema.tryDefinition(i)?.fields?.shape:void 0)??{};return t in o}function ft(n,e,t){let s=e.on==="record"||e.on==="field"?e.id:void 0,i=s?n.graph.getNode(s)?.kind:void 0;return i?n.schema.tryDefinition(i)?.edges?.[t]?.cardinality:void 0}async function Jt(n,e){let t=be(n,e),s=e.said??"Add one",i=new Set(e.store.allMutations().filter(r=>(r.creates??[]).length>0).map(r=>r.name)),o=t.catalog.candidates.filter(r=>r.type==="act"&&r.asks.length>0&&i.has(r.mutation));if(o.length===0)return _(t,s,"record","Nothing here makes a record.");let c=Re(n);if(!c)return _(t,s,"record",ve);let u;try{let r=await ne(c,'You propose one new record for an app by filling in an act. Answer only JSON: {"act": a candidate id, "args": {argument: value}}. Use only the candidates, and fill every argument the act asks for with a value that fits the state.',JSON.stringify({ask:s,state:t.state,candidates:o.map(b=>({id:b.id,says:b.description,asks:b.asks}))}),t,t.meter),h=o.find(b=>b.id===r?.act),g=typeof r?.args=="object"&&r.args!==null?r.args:{};h&&(u={act:h,args:Object.fromEntries(Object.entries(g).filter(([b])=>h.asks.includes(b)))})}catch(r){return _(t,s,"record",r instanceof Error?r.message:String(r))}if(!u)return _(t,s,"record","The model named no act this app has here.");let y=t.usage.at(-1)?.model,k=Ie(e.store,{interaction:t.id,target:e.target,basis:s,...y?{model:y}:{},proposals:[{id:u.act.id,label:u.act.label,said:u.act.description,call:{name:u.act.mutation,args:{...u.act.args,...u.args}}}]},e.principal);return k.proposals.length===0?_(t,s,"record","What the model proposed could not be made here."):{interaction:{...t.entry,ask:{kind:"record",said:s},offered:k.proposals.map(r=>({id:r.id,type:"act",label:r.said})),outcome:"offered",usage:[...t.usage]},offers:[u.act],ghost:k}}async function Wt(n,e){let t=be(n,e),s=e.said??"Make a panel",i=t.catalog.candidates.filter(r=>r.type==="panel");if(i.length===0)return _(t,s,"panel","Nothing here can be drawn as a panel.");let o=Te(n),c=Re(n),u;try{if(c){let r=await ne(c,'You choose a panel to draw in an app. Answer only JSON: {"panel": a candidate id, "title": a short title}. Choose only among the candidates.',JSON.stringify({ask:s,state:t.state,candidates:i.map(g=>({id:g.id,says:g.description}))}),t,t.meter),h=i.find(g=>g.id===r?.panel);h&&(u={panel:h,...typeof r?.title=="string"&&r.title.trim()?{title:r.title.trim().slice(0,60)}:{}})}else if(o){let{question:r,of:h}=Ae(i,`Which panel answers this best: ${s}`),g=Pe((await Se(o,t.state,{panel:r},t.meter)).panel,h,1)[0];g?.candidate.type==="panel"&&(u={panel:g.candidate,confidence:g.confidence})}else return _(t,s,"panel",ve)}catch(r){return _(t,s,"panel",r instanceof Error?r.message:String(r))}if(!u)return _(t,s,"panel","The model named no panel this app can draw.");let y=u.title??u.panel.label,k={title:y,recipe:{...u.panel.panel,title:y}};return{interaction:{...t.entry,ask:{kind:"panel",said:s},offered:[Ee(u.panel,u.confidence)],outcome:"drawn",panel:k,usage:[...t.usage]},offers:[u.panel],panel:k}}function ut(n){return n.off?void 0:n.answer}var ke=`You answer a person who typed words about what they are looking at in an app, from the state given and nothing else: "facts" says the fields and links of each record ("covered by Ada Nowak", "holds it: This week"), as they see them \u2014 answer from them, and never say a record has no link the facts show. Before answering, look through "facts" for the link or field the words are about \u2014 what it waits for, who covers it, what holds it, when it is due \u2014 and name it: "what is blocking this" is answered by its "waits for" links, by name. A link the facts do not show is not there: say plainly that there is none, never borrow one from another record, and answer what was asked \u2014 a count by counting, a day by its day. Answer only JSON: {"answer": one to three short, whole sentences written to the person, "pick": [candidate ids that act on the answer, best first, at most three]}. Pick only ids from the candidates, and none when nothing fits. Never say an id to the person. Where "members" are given and the person asks for something done to them, answer "each": {"act": the name of one of "member_acts", "args": every value it asks for, by name, dates as YYYY-MM-DD counted from "today"; the facts already say each day against today, so trust those} \u2014 one act over every member, as one change. Judge an act by what it does ("does"), not only its title: "close", "complete", "check off", "tick" and "finish" are an act that marks something done; "delete" one that removes; "push", "move" and "postpone" one that changes a date or a place. Where "fast_leaned_to" names an act, it is likely the one: fill its values. When the person tells it to do something, answer "each" (with a short "answer" saying what it will do): nothing is done until they accept, so never say in words that it is done, and never ask them to confirm ("Move it to Friday?"): the card asks them, so answer "each". Where "people" maps a word like "her" or "me" to a name, that is who they mean. Only where no act among "member_acts" or the candidates does what they ask, because the app has no field or link for it, answer "lacks": one whole sentence to the person saying what the app is missing (never an id, never a note to yourself), and "need": what it would need \u2014 {"link": {"on": the kind of the records, "called": what the link is called in their words, like "assigned to", "to": the kind it points to, or a noun for one the app lacks}} or {"field": {"on": the kind, "called": its name in their words, "type": "string", "number", "date" or "boolean"}} \u2014 with "who": the name of the record their words name (for a link) or "value": the value they give (for a field). When they ask for a change the app has no field or link for ("make these urgent", "give these a priority"), answer "lacks" and "need", never only "answer". A question is answered in "answer", never with "each" or "lacks"; so is "undo that", which the app's own Undo does.`,ht='Where nothing in the state or the catalog answers the words \u2014 the app keeps no such thing \u2014 do not answer only that you found nothing: reply with "lacks", one whole sentence to the person saying what this app does not keep ("This app keeps no budgets."), and "need" where one field or link on these records would hold it ({"field": {"on": kind, "called": name, "type": "string" | "number" | "date" | "boolean"}} or {"link": {"on": kind, "called": name, "to": kind}}). This holds for a question too.',gt='Where nothing in "facts" or "state" answers the words \u2014 the app keeps no such thing \u2014 do not answer only that you found nothing: answer "lacks", one whole sentence to the person saying what this app does not keep ("This app keeps no budgets."), and "need" where one field or link on these records would hold it. This holds for a question too.';async function Ft(n,e){let t=be(n,e),s=e.said.trim(),i=ut(n),o=Te(n),c=[],u=async(d,S,l)=>{let T=Date.now();try{return await l()}finally{c.push({stage:d,ms:Date.now()-T,model:S})}},y={...t,entry:t.entry},k,r,h,g;if(o&&s&&!i&&(e.target.on==="record"||e.target.on==="list"||e.target.on==="lens"||e.target.on==="selection"))try{let d=$=>An(o,{store:e.store,target:e.target,said:$,...e.principal.id?{principal:{id:e.principal.id}}:{},...e.members?{members:e.members}:{},...e.follows?{follows:e.follows}:{},...e.where?{where:e.where}:{},...e.examples?{examples:e.examples}:{}}),S=vn(s);if(S.length>1){let $=await u("fast",o.model,()=>Promise.all(S.map(d)));for(let m of $){let P=Ce(o.price,m.usage.inputTokens,m.usage.outputTokens);y.meter({tier:"fast",model:o.model,inputTokens:m.usage.inputTokens,outputTokens:m.usage.outputTokens,...P!==void 0?{costUsd:P}:{}})}if($.every(m=>m.sure&&m.each&&!m.asks))return Rn(e,y,s,$,c)}let l=await u("fast",o.model,()=>d(s)),T=Ce(o.price,l.usage.inputTokens,l.usage.outputTokens);if(y.meter({tier:"fast",model:o.model,inputTokens:l.usage.inputTokens,outputTokens:l.usage.outputTokens,...T!==void 0?{costUsd:T}:{}}),k=l.reading,r=l.act,h=l.asks,g=l.taken,l.sure&&(l.each||l.missing||l.clarify||l.outside))return Rn(e,y,s,l,c)}catch{}let b=()=>h??Ze(s),f=n.off?void 0:n.light,p=Re(n),v=f??p,R=y.catalog.candidates.filter(d=>jn(d)||d.type==="panel"||d.type==="place"||d.type==="record").slice(0,32),N;try{N=o&&(i||v)&&s?await wt(o,s,y,R):_n(y,R)}catch(d){return _(y,s,"ask",d instanceof Error?d.message:String(d))}let A={...y,state:N.state,catalog:{...y.catalog,candidates:N.choices},entry:{...y.entry,context:N.context}},J=N.choices,M=(k?.records??e.members??[]).flatMap(d=>{let S=e.store.graph.getNode(d);return S?[S]:[]}).slice(0,60),$e=new Set(M.map(d=>d.kind)),Y=e.store.allMutations().flatMap(d=>{let S=d.subject?.kinds;if(!d.subject||!(S==="*"||S.some(T=>$e.has(T))))return[];let l=[...$e].find(T=>S==="*"||S.includes(T));return[{name:d.name,title:d.title??d.name,does:`${d.description??""} ${nn(d,e.store.schema,l)}`.trim(),subjectArg:d.subject.arg,asks:(ue(d)??[]).filter(T=>T!==d.subject.arg)}]}),W,C,re,D="",F=[],De=d=>d.flatMap(S=>J.filter(l=>l.id===S)).slice(0,3).map(S=>({candidate:S}));try{if(i){let d=await i.answer({said:s,target:e.target,targetLabel:A.entry.targetLabel,state:A.state,catalog:{target:A.catalog.target,candidates:J},...e.follows?{follows:e.follows}:{},...n.couldNotFind?{couldNotFind:ht}:{}}),S=d.usage?.inputTokens,l=d.usage?.outputTokens,T=d.usage?.costUsd??(S!==void 0?Ce(i.price,S,l??0):void 0);if(A.meter({tier:"thinking",model:i.model,...S!==void 0?{inputTokens:S}:{},...l!==void 0?{outputTokens:l}:{},...T!==void 0?{costUsd:T}:{}}),D=typeof d.text=="string"?d.text.trim():"",F=De(d.pick??[]),typeof d.lacks=="string"&&d.lacks.trim()){let $=Pn(d.need),m=d.lacks.trim();C={said:ee(m)?m:$?Tn(e.store.schema,$):me,...$?{need:$}:{}},D=""}}else if(v){let d=JSON.stringify({ask:s,about:A.entry.targetLabel,...e.follows?{follows:e.follows}:{},...e.examples&&e.examples.length>0?{worked_before:e.examples,worked_before_is:"What people of this app asked before and what was done that they kept: where these words mean the same, do the same."}:{},state:A.state,candidates:J.map(m=>({id:m.id,says:m.description})),facts:wn(e.store,e.principal,[...new Set([...e.target.on==="record"?[e.target.id,...Ye(e.store,e.target.id)?.ids??[]]:[],...M.map(m=>m.id),...e.members??[]])],rn(e.store)),...M.length>0?{members:M.map(m=>({id:m.id,label:L(e.store.schema.tryDefinition(m.kind),m)})),member_acts:Y.map(m=>({name:m.name,title:m.title,does:m.does,asks:m.asks}))}:{},...r?{fast_leaned_to:r}:{},...g?{people:{[g.said]:g.as}}:{},everyone_in_the_app:he(e.store).flatMap(m=>e.store.graph.allNodes().filter(P=>P.kind===m)).slice(0,40).map(m=>L(e.store.schema.tryDefinition(m.kind),m)),...rn(e.store)?{today:bn(rn(e.store))}:{},...n.couldNotFind?{not_found:gt}:{}});re=d;let S=m=>!!(m&&(typeof m.answer=="string"&&m.answer.trim()||Array.isArray(m.pick)&&m.pick.length>0||m.each||m.lacks)),l=await u(f?"light":"thinking",v.model,()=>ne(v,ke,d,A,A.meter));f&&p&&p!==f&&!S(l)&&(l=await u("thinking",p.model,()=>ne(p,ke,d,A,A.meter)));let T=!b()&&!en.test(s)&&M.length>0,$=m=>Array.isArray(m)&&m.some(P=>{let V=J.find(z=>z.id===P);return V!==void 0&&Ne(V)!==void 0});if(T&&l&&!l.each&&!l.lacks&&!$(l.pick)){let m=await u(f?"light":"thinking",v.model,()=>ne(v,ke,JSON.stringify({...JSON.parse(d),told:'They told you to do this, not asked a question. Reply with exactly one of two shapes, never "answer" alone: "each" with an act from member_acts and its values, or "lacks" and "need" (and "value") where no act can \u2014 for example {"lacks": "Tasks have no priority yet.", "need": {"field": {"on": "task", "called": "priority", "type": "string"}}, "value": "high"}.'}),A,A.meter));if(m&&(m.each||m.lacks))l=m;else if(r){let P=Y.find(z=>z.name===r),V=P?e.store.allMutations().find(z=>z.name===P.name)?.input?.shape??{}:{};P&&P.asks.every(z=>V[z]?.safeParse(void 0).success??!0)&&(l={...l,answer:"",each:{act:P.name,args:{}}})}}if(!b()&&l?.each&&(l={...l,pick:Array.isArray(l.pick)?l.pick.filter(m=>{let P=J.find(V=>V.id===m);return P!==void 0&&Ne(P)===void 0}):l.pick}),b()&&l&&(l={...l,each:void 0}),l&&typeof l.answer=="string"&&l.answer.trim()&&!ee(l.answer)&&!l.each&&!l.lacks){let m=await u(f?"light":"thinking",v.model,()=>ne(v,ke,JSON.stringify({...JSON.parse(d),rewrite:`Your answer was not whole sentences: \u201C${String(l.answer).slice(0,300)}\u201D. Say it again in one to three whole sentences to the person, each begun with a capital and ended with a full stop.`}),A,A.meter));m&&typeof m.answer=="string"&&ee(m.answer)?l={...l,answer:m.answer}:b()&&/^[\p{L}\p{N}"“'(][^{}[\]]*$/u.test(String(l.answer).trim())&&String(l.answer).trim().split(/\s+/).length>=2&&(l={...l,answer:`${String(l.answer).trim().charAt(0).toUpperCase()}${String(l.answer).trim().slice(1).replace(/[\s,;:]+$/,"")}.`})}if(b()&&l&&!(typeof l.answer=="string"&&l.answer.trim())){let m=await u(f?"light":"thinking",v.model,()=>ne(v,ke,JSON.stringify({...JSON.parse(d),rewrite:'This is a question: answer it in "answer", in one to three whole sentences, from the facts.'}),A,A.meter));m&&typeof m.answer=="string"&&ee(m.answer)&&(l={...l,answer:m.answer})}if(D=typeof l?.answer=="string"?l.answer.trim():"",F=De(Array.isArray(l?.pick)?l.pick:[]),W=pt(l?.each),D&&!ee(D)&&(D=W?"":me),typeof l?.lacks=="string"&&l.lacks.trim()){let m=Pn(l.need),P=l.lacks.trim();C={said:ee(P)?P:m?Tn(e.store.schema,m):me,...m?{need:m}:{},...typeof l.who=="string"&&l.who.trim()?{who:l.who.trim()}:{},...typeof l.value=="string"||typeof l.value=="number"?{value:String(l.value)}:{}}}}else if(o&&J.length>0){let{question:d,of:S}=Ae(J,`Which of these best answers, or acts on: ${s}`),l=await Se(o,{...A.state,asked:s,candidates:J.map(T=>({id:T.id,type:T.type,says:T.description}))},{answer:d},A.meter);F=Pe(l.answer,S,3),D=F.length>0?`These fit \u201C${s}\u201D.`:""}else return _(A,s,"ask",ve)}catch(d){return _(A,s,"ask",d instanceof Error?d.message:String(d))}for(let d of[D,C?.said??""]){let S=d?on(e.store,d):[];if(S.length===0||!v)continue;let l=S.map(P=>`${P.name} (${K(e.store.schema,P.kind).toLowerCase()})`).join(", "),T=await u(f?"light":"thinking",v.model,()=>ne(v,ke,JSON.stringify({...JSON.parse(re??"{}"),known:`These are in the app: ${l}. Never say they are not.`}),A,A.meter)),$=typeof T?.answer=="string"?T.answer.trim():"",m=$&&ee($)&&on(e.store,$).length===0?$:`${S[0].name} is here, one of its ${K(e.store.schema,S[0].kind).toLowerCase()}. Try saying it another way.`;d!==D&&(C=void 0),D=m}if(!b()&&Ve(s)&&!/\b(field|link|column)\b/i.test(s)&&(C=void 0,W=void 0,F=[],D=Xe(e.store,s,e.target.on==="record"?e.target.id:void 0)),C&&n.couldNotFind){let d=e.target.on==="place"||e.target.on==="lens"?e.target.place:void 0,S=e.target.on==="list"||e.target.on==="lens"?e.target.kind:void 0;if(qe(e.store,{type:"unanswered",question:s,...d?{place:d}:{},...S?{kind:S}:{},lacks:C.said},e.principal),typeof n.couldNotFind=="function")try{n.couldNotFind({said:s,lacks:C.said,...C.need?{need:C.need}:{},...d?{place:d}:{},...S?{kind:S}:{}})}catch{}}let te=!!W||F.some(({candidate:d})=>Ne(d)!==void 0);if(!b()&&!te&&!C&&D&&Cn(D)&&(D=Nn),!D&&F.length===0&&!W&&!C){let d=e.target.on==="place"||e.target.on==="lens"?e.target.place:void 0,S=e.target.on==="list"||e.target.on==="lens"?e.target.kind:void 0;return qe(e.store,{type:"unanswered",question:s,...d?{place:d}:{},...S?{kind:S}:{}},e.principal),_(A,s,"ask","The AI had no answer to that here.")}let xe=A.usage.at(-1)?.model,se=b(),Q=W?e.store.allMutations().find(d=>d.name===W.act):void 0;if(Q&&_e(Q)&&M.length>1&&(k?(k.chance??1)<Ke(Q,s)||Qe(s,k):!$n(s))){let d=`Should I ${(Q.title??Q.name).trim().split(/\s+/)[0].toLowerCase()} all ${M.length} of them? Say \u201Call\u201D to go ahead, or say which.`;return{interaction:{...A.entry,ask:{kind:"ask",said:s},offered:[],outcome:"offered",answer:d,usage:[...A.usage],stages:c},offers:[],answer:d,...k?{reading:k}:{}}}let ge=(se?[]:F).flatMap(({candidate:d,confidence:S})=>{let l=Ne(d);return l?[{...l,...S!==void 0?{confidence:S}:{}}]:[]}),q=W?Y.find(d=>d.name===W.act):void 0;if(q)for(let d of M){let S=e.store.allMutations().find(T=>T.name===q.name),l=S?.subject?.kinds;!S||!(l==="*"||l.includes(d.kind))||ge.push({id:`each:${q.name}:${d.id}`,label:`${q.title}: ${L(e.store.schema.tryDefinition(d.kind),d)}`,said:q.title,call:{name:q.name,args:{...W.args,[q.subjectArg]:d.id}},record:d.id})}let ce=ge.filter((d,S)=>ge.findIndex(l=>l.call.name===d.call.name&&JSON.stringify(l.call.args)===JSON.stringify(d.call.args))===S),O=ce.length>0?Ie(e.store,{interaction:A.id,target:e.target,basis:s,...xe?{model:xe}:{},proposals:ce},e.principal):void 0,pe=F.map(({candidate:d})=>d).filter(d=>se||Ne(d)===void 0);if(!W&&!se&&O&&O.proposals.length>0&&(D=O.proposals.slice(0,3).flatMap(d=>{let S=e.store.allMutations().find(T=>T.name===d.call.name),l=S?.subject?d.call.args[S.subject.arg]:void 0;return S&&typeof l=="string"?[sn(e.store,{act:S,args:d.call.args,records:[l],itself:!0})]:[]}).join(" ")),W&&Q&&O){let d=M.map(S=>S.id).filter(S=>O.proposals.some(l=>l.id===`each:${Q.name}:${S}`));d.length>0&&(D=Ln(e.store,Q,W.args,d,k??(M.length===1&&e.target.on==="record"&&M[0].id===e.target.id?{which:"itself",records:d,kind:M[0].kind,words:"",close:!1}:void 0)))}let an=[...pe.map(d=>Ee(d,F.find(S=>S.candidate===d)?.confidence)),...(O?.proposals??[]).map(d=>({id:d.id,type:d.field!==void 0?"fill":"act",label:d.label,...d.confidence!==void 0?{confidence:d.confidence}:{}}))];return{interaction:{...A.entry,ask:{kind:"ask",said:s},offered:an,outcome:"offered",...D?{answer:D}:{},usage:[...A.usage],stages:c},offers:pe,...O&&O.proposals.length>0?{ghost:O}:{},...D?{answer:D}:C?{answer:C.said}:{},...C?{missing:C.need&&k&&"link"in C.need?{...C,need:{link:{...C.need.link,on:k.kind}}}:C}:{},...k?{reading:k}:{},...g?{taken:g}:{}}}function Ln(n,e,t,s,i){let o=i?.part,c=i?/ (in .+)$/.exec(i.words)?.[1]:void 0;return sn(n,{act:e,args:t,records:s,...o?{narrowed:o}:{},...c?{where:c}:{},itself:i?.which==="itself"})}function rn(n){try{let e=(typeof n.today=="function"?n.today():void 0)??new Date().toISOString();return/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(0,10):void 0}catch{return}}function Tn(n,e){let t=c=>K(n,c).toLowerCase(),s=c=>c.charAt(0).toUpperCase()+c.slice(1),{on:i,called:o}="link"in e?e.link:e.field;return`${s(t(i))} have no \u201C${s(o)}\u201D yet.`}function Rn(n,e,t,s,i){let o=Array.isArray(s)?s:[s],c=[];for(let p of o){if(!p.each||!p.reading)continue;let v=n.store.allMutations().find(R=>R.name===p.each.act);for(let R of p.reading.records){let N=n.store.graph.getNode(R);!N||!v?.subject||c.push({id:`each:${v.name}:${R}`,label:`${v.title??v.name}: ${L(n.store.schema.tryDefinition(N.kind),N)}`,said:v.title??v.name,call:{name:v.name,args:{...p.each.args,[v.subject.arg]:R}},record:R})}}let u=e.usage.at(-1)?.model,y=c.length>0?Ie(n.store,{interaction:e.id,target:n.target,basis:t,...u?{model:u}:{},proposals:c},n.principal):void 0,k=(y?.proposals??[]).map(p=>({id:p.id,type:"act",label:p.label})),r=new Set((y?.proposals??[]).map(p=>p.id)),h=o.map(p=>{if(p.clarify)return p.clarify;if(p.outside)return p.outside;if(p.each&&p.reading){let v=n.store.allMutations().find(N=>N.name===p.each.act),R=p.reading.records.filter(N=>r.has(`each:${p.each.act}:${N}`));return R.length>0&&v?Ln(n.store,v,p.each.args,R,p.reading):v?On(n.store,v,p.reading.records):"Nothing here would change."}return p.text??p.missing?.said??""}).filter(Boolean).join(" "),g=o[0],b=o.find(p=>p.missing)?.missing,f=o.find(p=>p.taken)?.taken;return{interaction:{...e.entry,ask:{kind:"ask",said:t},offered:k,outcome:"offered",...h?{answer:h}:{},usage:[...e.usage],stages:[...i]},offers:[],...y&&y.proposals.length>0?{ghost:y}:{},...h?{answer:h}:{},...b?{missing:b}:{},...g.reading&&o.length===1?{reading:g.reading}:{},...f?{taken:f}:{}}}function Pn(n){if(typeof n!="object"||n===null)return;let{link:e,field:t}=n,s=i=>typeof i=="string"&&i.trim()?i.trim():void 0;if(e&&s(e.on)&&s(e.called)&&s(e.to))return{link:{on:s(e.on),called:s(e.called),to:s(e.to)}};if(t&&s(t.on)&&s(t.called)){let i=["string","number","date","boolean"].includes(String(t.type))?t.type:"string";return{field:{on:s(t.on),called:s(t.called),type:i}}}}function pt(n){if(typeof n!="object"||n===null)return;let{act:e,args:t}=n;if(typeof e=="string")return{act:e,args:typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{}}}function Ie(n,e,t){let s=e.proposals.flatMap(i=>{try{let o=n.previewAll([i.call],{author:t}),c=o.ops.map(u=>u.intent).join("; ");return o.ops.length>0?[{...i,said:c||i.said}]:[]}catch{return[]}});return{...e,proposals:s}}function Ne(n){if(n.type==="fill")return{id:n.id,label:n.label,said:n.description,call:n.call,record:n.record,field:n.field};if(n.type==="act"&&n.asks.length===0)return{id:n.id,label:n.label,said:n.description,call:{name:n.mutation,args:{...n.args}}}}function qt(n,e,t){let s=e.proposals.filter(o=>t.ids===void 0||t.ids.includes(o.id));if(s.length===0)return{ok:!1,refused:"Nothing was chosen."};let i=s.flatMap(o=>o.confidence===void 0?[]:[o.confidence]);try{let c=n.applyAll(s.map(u=>u.call),{author:t.author,via:`ai:${e.interaction}`,intent:e.basis,lineage:{basis:`Asked \u201C${e.basis}\u201D`,...e.model?{model:e.model}:{},...i.length>0?{confidence:Math.min(...i)}:{},interaction:e.interaction}}).ops[0]?.batch;return c?{ok:!0,batch:c,accepted:s.map(u=>u.id)}:{ok:!1,refused:"That changes nothing now."}}catch(o){return{ok:!1,refused:o instanceof Error?o.message:String(o)}}}function Ht(n,e,t){let s=n.ask.kind==="suggest"?e.length>0:n.offered.length>0&&n.offered.every(i=>e.includes(i.id));return{...n,outcome:s?"accepted":"partly",accepted:e,batches:[...n.batches??[],t]}}var Gt=n=>({...n,outcome:"dismissed"}),Dn={candidates:8,records:6},yt=.1,mt=12,Mn=n=>{let e=new Set;return[...n.selection,...n.neighbors].filter(t=>!e.has(t.id)&&(e.add(t.id),!0))};function _n(n,e){return{choices:e,state:n.state,context:{by:"default",candidates:e.map(t=>t.id),records:Mn(n.state).map(t=>t.id)}}}async function wt(n,e,t,s){let i=Mn(t.state),o={},c=s.length>0?Ae(s,`Which of these could answer, or act on: ${e}`):void 0;c&&(o.candidates={...c.question,criteria:{...c.question.criteria,none:"None of these"}});let u=new Map(i.slice(0,mt).map((f,p)=>[`record-${p+1}`,f]));for(let[f,p]of u)o[f]={type:"noul",instructions:`Is \u201C${e}\u201D about ${p.label} (${p.kind})?`};if(Object.keys(o).length===0)return{..._n(t,s),context:{by:"fast",model:n.model,candidates:[],records:[]}};let y=await Se(n,{target:t.state.target,asked:e},o,t.meter),r=c?((f,p,v)=>{if(f?.type!=="choice"||f.choice==="none")return[];let R=Object.entries(f.probabilities).filter(([N])=>N!=="none").sort((N,A)=>A[1]-N[1]);return R.some(([N])=>N===f.choice)||R.unshift([f.choice,f.confidence]),R.filter(([,N],A)=>A===0||N>=yt).flatMap(([N])=>{let A=p(N);return A===void 0?[]:[A]}).slice(0,v)})(y.candidates,c.of,Dn.candidates):[],h=[...u].flatMap(([f,p])=>{let v=y[f];return v?.type==="noul"&&v.noul>.5?[{record:p,chance:v.noul}]:[]}).sort((f,p)=>p.chance-f.chance).slice(0,Dn.records).map(f=>f.record),g=new Set(h.map(f=>f.id)),b={...t.state,selection:t.state.selection.filter(f=>g.has(f.id)),neighbors:t.state.neighbors.filter(f=>g.has(f.id))};return{choices:r,state:b,context:{by:"fast",model:n.model,candidates:r.map(f=>f.id),records:h.map(f=>f.id)}}}export{Jn as a,Te as b,Re as c,rt as d,at as e,Et as f,dt as g,It as h,Ut as i,Jt as j,Wt as k,Ft as l,Ie as m,Ne as n,qt as o,Ht as p,Gt as q};
1
+ import{d as pn,f as yn}from"./chunk.6WB2TYK7.js";import{a as mn}from"./chunk.JGRSUTPJ.js";import{Fd as qe,Xb as ue,fc as Z,ga as Fe,la as L,oa as K,ta as Le}from"./chunk.6AANHELP.js";var me="I couldn't work out how to do that \u2014 try saying it another way.";function ee(n){let e=n.trim();return e.length===0||!/^[\p{Lu}\p{N}"“‘'(]/u.test(e)||!/[.!?…][”’"')]*$/u.test(e)||e.split(/\s+/).filter(Boolean).length<3?!1:!/[{}[\]]|\b[a-z]+_[a-z_]+\b/.test(e)}function Jn(n,e=me){return n&&ee(n)?n.trim():e}function wn(n,e,t,s,i=40){let o=n.seenBy(e).graph,c=n.schema,u=y=>{let k=o.getNode(y);return k?L(c.tryDefinition(k.kind),k):void 0};return t.slice(0,i).flatMap(y=>{let k=o.getNode(y);if(!k)return[];let r=Object.fromEntries(Object.entries(k).filter(([g,b])=>!["id","kind","label"].includes(g)&&!g.startsWith("_")&&b!==void 0&&b!==null&&(typeof b!="object"||Array.isArray(b))&&JSON.stringify(b).length<=200).map(([g,b])=>[g,typeof b=="string"&&s?kn(b,s):b])),h=[...o.outEdges(y).flatMap(g=>{let b=u(g.to);return b?[`${Fe(g.kind).toLowerCase()} ${b}`]:[]}),...o.inEdges(y).flatMap(g=>{let b=u(g.from);return b?[`${Fe(g.kind).toLowerCase()} it: ${b}`]:[]})].slice(0,12);return[{id:y,kind:k.kind,label:u(y)??y,fields:r,links:h}]})}var Wn=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function kn(n,e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(n.slice(0,10)),s=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e.slice(0,10));if(!t||!s||n.length!==10)return n;let i=Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3])),o=Date.UTC(Number(s[1]),Number(s[2])-1,Number(s[3])),c=Math.round((i-o)/864e5),u=c===0?"today":c===1?"tomorrow":c===-1?"yesterday, already past":c>0?`in ${c} days`:`${-c} days ago, already past`;return`${n}, ${Wn[new Date(i).getUTCDay()]}, ${u}`}function bn(n){return kn(n,n).replace(/, today$/,"")}var He=.6,Fn=.75,qn=new Set(["person","people","user","users","member","members","volunteer","volunteers","staff","contact","contacts","employee","employees","client","clients","customer","customers","guest","guests","player","players","student","students"]),we=n=>n.charAt(0).toUpperCase()+n.slice(1),Hn={assign:!0,reassign:!0,give:!0,hand:!0,delegate:!0,allocate:!0};function Ye(n,e){let t=n.graph.getNode(e);if(!t)return;let s=new Map;for(let o of[...n.graph.in(e),...n.graph.out(e)])o.kind!==t.kind&&s.set(o.kind,[...new Set([...s.get(o.kind)??[],o.id])]);let i=[...s.entries()].sort((o,c)=>c[1].length-o[1].length)[0];return i&&i[1].length>1?{kind:i[0],ids:i[1]}:void 0}function he(n){let e=n.schema,t=e.definitions.filter(s=>s.people).map(s=>s.kind);return[...new Set([...t,...e.definitions.filter(s=>[s.kind,s.noun,K(e,s.kind)].some(i=>i!==void 0&&qn.has(i.toLowerCase()))).map(s=>s.kind)])]}function Ge(n){let e=/^\s*([\p{L}][\p{L}'’-]*)\s+(?:should|can|will|could|is going to|needs to)\s+(?:take care of|handle|own|do|look after|take|deal with|pick up|be on)\b/iu.exec(n)?.[1]??/\bmake\s+(?:this|these|it|them|this one)\s+([\p{L}][\p{L}-]*)['’]s\b/iu.exec(n)?.[1]??/\b(?:this|these|it|they)\s+(?:is|are)\s+([\p{L}][\p{L}-]*)['’]s\b/iu.exec(n)?.[1]??/\b([\p{L}][\p{L}-]*)['’]s\s+(?:job|task|responsibility|shift|now)\b/iu.exec(n)?.[1]??/^\s*([\p{L}][\p{L}-]*)['’]s\s+(?:on|got|doing|handling|taking|covering)\s+(?:this|it|these|that|them)\b/iu.exec(n)?.[1]??/^\s*([\p{L}][\p{L}-]*)\s+(?:has|has got|is on|is doing|is handling|is taking|is covering|takes|does|owns)\s+(?:this|it|these|that|them)(?:\s+one)?\b/iu.exec(n)?.[1];if(e&&!/^(it|this|that|these|those|they|we|you|i|he|she|everyone|someone|anyone|nobody|nothing|who|what|which|there|it's|that's|who's|what's)$/i.test(e))return{called:"assigned to",who:we(e),owned:!0};let t=/\bto\s+([\p{L}][\p{L}'’-]*)\s*[.!?]*\s*$/iu.exec(n)?.[1];if(n.toLowerCase().split(/[^a-z]+/).find(i=>i in Hn))return{called:"assigned to",...t?{who:we(t)}:{}}}var Sn=["done","completed","finished","closed"],Gn=["due","dueDate","dueOn","deadline"];function Qe(n,e){return e.which!=="held"||e.part?!1:/\b(that'?s|that is|that are|that were|that have|that has|which|whose|already|except|but not|only|apart from|other than)\b/i.test(n)||/\bones? (that|which|i|we|you|i'?ve|we'?ve|i'?m)\b/i.test(n)||xn(n)||Oe(n).open||Oe(n).finished}function de(n){if(n?.type!=="choice")return;let e=n.probabilities[n.choice]??n.confidence;return{key:n.choice,chance:e}}async function An(n,e){let{store:t,target:s,said:i}=e,o=t.schema,c=`${i} ${e.follows?.said??""}`.trim(),u=s.on==="record"?t.graph.getNode(s.id):void 0,y=u?Ye(t,u.id):void 0,k=(e.members??[]).filter(a=>t.graph.getNode(a)!==void 0),r=[],h=e.where?` in ${e.where}`:u?` in ${L(o.tryDefinition(u.kind),u)}`:"",g=a=>K(o,a).toLowerCase(),b=a=>(o.tryDefinition(a)?.noun??a).toLowerCase();u&&r.push({which:"itself",records:[u.id],kind:u.kind,words:`${L(o.tryDefinition(u.kind),u)} itself`,close:!1});let f=y??(k.length>0?{kind:t.graph.getNode(k[0]).kind,ids:k.filter(a=>t.graph.getNode(a).kind===t.graph.getNode(k[0]).kind)}:void 0),p=(a,w,x)=>`the ${a.length}${x?` ${x}`:""} ${a.length===1?b(w):g(w)}${h}`;f&&f.ids.length>0&&r.push({which:"held",records:f.ids,kind:f.kind,words:p(f.ids,f.kind),close:!1});let v=e.follows?/\bcall (?:it|that|the field)\s+["“']?([\p{L}][\p{L} ]*?)["”']?\s*[.!]*\s*$/iu.exec(i)?.[1]:void 0;if(v&&e.follows?.reading&&r.some(a=>a.which===e.follows.reading)&&r.splice(0,r.length,...r.filter(a=>a.which===e.follows.reading)),r.length===0)return{sure:!1,usage:{inputTokens:0,outputTokens:0}};let R=a=>Sn.some(w=>t.graph.getNode(a)?.[w]===!0),N=t.today?.()??new Date().toISOString().slice(0,10),A=a=>Gn.map(w=>t.graph.getNode(a)?.[w]).find(w=>typeof w=="string"),J=[];if(f&&f.ids.length>1){let a=f.ids.filter(R),w=f.ids.filter(j=>!R(j)),x=w.filter(j=>(A(j)??"9999")<N.slice(0,10));a.length>0&&a.length<f.ids.length&&J.push({which:"held",part:"done",records:a,kind:f.kind,words:p(a,f.kind,"done"),close:!1}),w.length>0&&w.length<f.ids.length&&J.push({which:"held",part:"open",records:w,kind:f.kind,words:p(w,f.kind,"open"),close:!1}),x.length>0&&x.length<f.ids.length&&J.push({which:"held",part:"late",records:x,kind:f.kind,words:p(x,f.kind,"late"),close:!1})}let M=v?r:[...r,...J],$e=a=>a.part??a.which,Y={};M.length>1&&(Y.reading={type:"choice",instructions:`Someone said \u201C${i}\u201D${e.follows?`, replying to \u201C${e.follows.said}\u201D${e.follows.reading?`, which was taken as ${e.follows.reading==="itself"?"the record itself":"the records it holds"}`:""}`:""}. Which records do they mean? "This", "it" or its name alone is the record itself; "these", "all", "them", "everything", "the lot" are never the record itself but every record it holds \u2014 unless more words say which of them: "the done ones", "that are finished", "already ticked off", "completed" mean the done ones; "outstanding", "remaining", "unfinished", "still to do", "except the done ones" mean the open ones; "late" or "overdue" the late ones. A word that says the change to make ("mark these done", "close these", "finish them") says what to do, not which records. If their words pick out some records in a way none of these says ("the old ones"), choose "something else".`,criteria:{...Object.fromEntries(M.map(a=>[$e(a),a.which==="itself"?`${we(a.words)} (the ${b(a.kind)})`:we(a.words)])),else:"Something else: some other part of them"}}),Y.where={type:"choice",instructions:`Does \u201C${i}\u201D want something done to the records of this app (or an answer about them), or something done outside the app \u2014 an email or a text sent, a call made, a payment, a booking, a post somewhere?`,criteria:{inside:"Inside the app: its records, or an answer about them",outside:"Outside the app: send, call, pay, book or post somewhere else"}},Y.mood={type:"choice",instructions:`Does \u201C${i}\u201D ask something, wanting an answer in words, or tell me to do something, wanting a change made? A question can come without a question mark ("has this been done yet"), an instruction can be polite ("could you close these"), and saying who has something ("Sam's on this", "Nora has this one") tells me to give it to them.`,criteria:{asks:"Asks something: wants an answer in words",tells:"Tells me to do something: wants a change made"}};let W=a=>t.allMutations().filter(w=>w.subject&&(w.subject.kinds==="*"||w.subject.kinds.includes(a))),C=r.flatMap(a=>W(a.kind).slice(0,24).map(w=>({key:`${a.which}:${w.name}`,reading:a,mutation:w})));Y.act={type:"choice",instructions:`Which of these acts does \u201C${c}\u201D ask to be done? Judge each by what it does, not only its title: people say "close", "complete", "check off", "tick" or "finish" for an act that marks something done, "delete" for one that removes, "push" or "move" for one that changes a date or a place. A question, or "undo that", is none of them. "none" only where no act here does it.`,criteria:{...Object.fromEntries(C.map(a=>[a.key,`${a.mutation.title??a.mutation.name}: ${tt(a.mutation.description)}${nn(a.mutation,o,a.reading.kind)} \u2014 on ${a.reading.which==="itself"?`the ${b(a.reading.kind)} itself`:`each of ${a.reading.words}`}`])),none:"None of these acts does it"}};let re=he(t),D=new Set([...re,...C.flatMap(a=>Z(a.mutation.input).filter(w=>w.name!==a.mutation.subject.arg).flatMap(w=>w.kinds))]),F=t.graph.allNodes().filter(a=>D.has(a.kind)||D.has("*")),De=new Set(c.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(a=>a.length>=3).map(a=>a.slice(0,4))),te=a=>L(o.tryDefinition(a.kind),a),xe=(F.length<=25?F:F.filter(a=>te(a).toLowerCase().split(/[^\p{L}\p{N}]+/u).some(w=>w.length>=3&&De.has(w.slice(0,4))))).filter(a=>a.id!==u?.id&&!r.some(w=>w.records.includes(a.id))).slice(0,25),se=ze.test(i)?Yn(t,e.principal,D):void 0,Q=ze.test(i)&&e.principal?Qn(t,e.principal.id):void 0,ge=zn.exec(i),q=(ge?.[1]??ge?.[2])?.toLowerCase(),ce=q?Kn(t,u?.id,e.follows?.said,re):[];q&&ce.length>1&&(Y.pronoun={type:"choice",instructions:`In \u201C${i}\u201D${e.follows?`, said after \u201C${e.follows.said}\u201D`:""}, whom does \u201C${q}\u201D mean?`,criteria:{...Object.fromEntries(ce.map(a=>[`r:${a.id}`,te(a)])),else:"Someone else"}}),xe.length>0&&(Y.named={type:"choice",instructions:`Which of these does \u201C${c}\u201D name, as the one to give it to, move it to, link it with or put it on?`,criteria:{...Object.fromEntries(xe.map(a=>[`r:${a.id}`,`${te(a)} (${Le(b(a.kind))})`])),new:"Someone or something not listed here",none:"None is named"}}),Y.need={type:"choice",instructions:`If no act here can do \u201C${c}\u201D, what would each record need?`,criteria:{person:"A link to the person it is given or assigned to",other:"Something else: a field, a date, a number, a note",none:"Nothing: an act here can do it"}};let O=await n.decide({said:i,...e.follows?{replyingTo:e.follows.said}:{},readings:M.map(a=>a.words),...e.examples&&e.examples.length>0?{workedBefore:e.examples}:{}},Y),pe=de(O.answers.mood),d=Ge(i)?.owned===!0&&!/\?\s*$/.test(i)?!1:pe&&pe.chance>=.6?pe.key==="asks":Ze(i),S=de(O.answers.where);if(!d&&Ve(i)&&S?.key==="outside"&&S.chance>=.6)return{sure:!0,asks:!1,outside:Xe(t,i,u?.id),usage:O.usage};let l=de(O.answers.reading),T=M.length>1?M.find(a=>$e(a)===l?.key):M[0];if(!T){let a=de(O.answers.act),w=a&&a.key!=="none"?C.find(x=>x.key===a.key):void 0;if(!d&&w&&_e(w.mutation)&&f&&f.ids.length>1){let x=(w.mutation.title??w.mutation.name).trim().split(/\s+/)[0].toLowerCase();return{sure:!0,asks:!1,clarify:`Which of the ${f.ids.length} ${g(f.kind)}${h} should I ${x}? Say which, or \u201Call\u201D.`,usage:O.usage}}return{sure:!1,asks:d,usage:O.usage}}let $={...T,close:M.length>1&&(l?.chance??1)<Fn,chance:M.length>1?l?.chance??0:1},m=de(O.answers.act),P=de(O.answers.named),V=de(O.answers.pronoun),z=q?ce.length===1?ce[0]:V?.key.startsWith("r:")?t.graph.getNode(V.key.slice(2)):void 0:void 0,X=q&&z?{said:q,as:te(z)}:void 0,H=se??z??(P?.key.startsWith("r:")&&P.chance>=He?t.graph.getNode(P.key.slice(2)):void 0),le=Ge(i)??Ge(c),dn=le?.who&&(ze.test(le.who)?se?te(se):Q:Bn.test(le.who)?z?te(z):void 0:le.who),Ue=le?{called:le.called,...dn?{who:dn}:{},...le.owned?{owned:!0}:{}}:void 0,ie=Ue&&v?{...Ue,called:v.toLowerCase()}:Ue,En=O.answers.reading?.type==="choice"?Object.entries(O.answers.reading.probabilities).filter(([a])=>a!==l?.key).reduce((a,[,w])=>Math.max(a,w),0):0;if(!(M.length===1||(l?.chance??0)>=.5||(l?.chance??0)>=.35&&(l?.chance??0)>=1.5*En))return{sure:!1,asks:d,reading:$,usage:O.usage};let je=(a,w)=>Z(a.input).some(x=>x.name!==a.subject.arg&&(x.kinds.includes("*")||x.kinds.some(j=>w.includes(j)))),cn=[...re,...H?[H.kind]:[]];if(d||en.test(i))return{sure:!1,asks:d,reading:$,usage:O.usage};let fe=nt(O.answers.act),oe=a=>C.find(w=>w.mutation.name===a&&w.reading.which===$.which),ln=a=>!!(a&&(a.mutation.destructive||a.mutation.derived?.act==="remove")),I=m&&m.key!=="none"?m.key.slice(m.key.indexOf(":")+1):void 0,ae=m!==void 0&&m.key!=="none"&&m.chance>=He;if(!ae&&fe.length>1&&fe[0].chance+fe[1].chance>=.8&&ln(oe(fe[0].name))&&ln(oe(fe[1].name))&&(ae=!0),I&&H&&oe(I)&&!je(oe(I).mutation,[H.kind])){let a=oe(I).mutation,w=new Set(Z(a.input).map(E=>E.name)),x=Object.entries(a.input?.shape??{}).some(([E,G])=>!w.has(E)&&!G.safeParse(void 0).success&&!G.safeParse(Me(i)).success),j=P&&P.chance>=.9&&x?0:.05,U=fe.filter(E=>E.chance>=j).map(E=>oe(E.name)).find(E=>E&&E.mutation.derived?.act!=="merge"&&je(E.mutation,[H.kind]));U&&(I=U.mutation.name,ae=!0)}if(!ae&&H&&ie?.who&&(X||se||ie.owned)){let a=C.filter(w=>w.reading.which===$.which&&w.mutation.derived?.act!=="merge"&&Z(w.mutation.input).some(x=>x.name!==w.mutation.subject.arg&&Be(t,H,x.kinds)!==void 0&&re.some(j=>x.kinds.includes(j))));a.length===1&&(I=a[0].mutation.name,ae=!0)}if(!ae&&H){let a=fe.filter(w=>w.chance>=.3).map(w=>oe(w.name)).find(w=>w&&w.mutation.derived?.act!=="merge"&&Z(w.mutation.input).some(x=>x.name!==w.mutation.subject.arg&&Be(t,H,x.kinds)!==void 0));a&&(I=a.mutation.name,ae=!0)}let Je=v===void 0?et(i):void 0,fn=r.find(a=>a.which==="itself");if(Je&&fn){let a=["label","name","title"],w=C.find(U=>{let E=(ue(U.mutation)??[]).filter(G=>G!==U.mutation.subject.arg);return U.reading.which==="itself"&&E.length===1&&(a.includes(E[0])||(U.mutation.writes??[]).some(G=>a.includes(G)))}),x=w?(ue(w.mutation)??[]).find(U=>U!==w.mutation.subject.arg):void 0,j=x?(w.mutation.input?.shape??{})[x]:void 0;if(w&&x&&j?.safeParse(Je).success)return{sure:!0,reading:{...fn,close:!1},each:{act:w.mutation.name,args:{[x]:Je}},usage:O.usage}}if(I&&!oe(I)){let a=C.find(j=>j.mutation.name===I),w=j=>{let U=a?.mutation?.derived?.act,E=j.mutation.derived?.act;return U!==void 0?U===E:(j.mutation.title??j.mutation.name).split(/\s+/)[0].toLowerCase()===(a?.mutation.title??I??"").split(/\s+/)[0].toLowerCase()},x=C.find(j=>j.reading.which===$.which&&w(j));x&&(I=x.mutation.name)}let B=I&&ae?oe(I):void 0;if(B&&!(ie?.who&&!je(B.mutation,cn))){let a=(ue(B.mutation)??[]).filter(G=>G!==B.mutation.subject.arg),w=Z(B.mutation.input),x=B.mutation.input?.shape??{},j={},U=!0;for(let G of a){let ye=w.find(We=>We.name===G),hn=ye?ye.optional:x[G]?.safeParse(void 0).success??!0,gn=ye&&H?Be(t,H,ye.kinds):void 0;ye&&gn?j[G]=gn.id:!ye&&!hn&&a.filter(We=>!w.some(Un=>Un.name===We)).length===1&&Me(i)!==void 0&&x[G]?.safeParse(Me(i)).success?j[G]=Me(i):hn||(U=!1)}if(B.mutation.derived?.act==="edit"&&Object.keys(j).length===0&&(U=!1),!U)return{sure:!1,reading:$,...X?{taken:X}:{},act:B.mutation.name,usage:O.usage};let E=M.length===1||(l?.chance??0)>=Ke(B.mutation,i);return _e(B.mutation)&&$.records.length>1&&(!E||Qe(i,$))?{sure:!0,reading:$,clarify:Vn(t,B.mutation.title??B.mutation.name,$),usage:O.usage}:{sure:!0,reading:$,...X?{taken:X}:{},each:{act:B.mutation.name,args:j},usage:O.usage}}let un=de(O.answers.need),In=C.some(a=>a.reading.which===$.which&&je(a.mutation,cn));if(ie?.who&&!In&&(un?.key==="person"&&un.chance>=He||se!==void 0||Q!==void 0||X!==void 0||ie.owned===!0)){let a=ie.who??(H&&re.includes(H.kind)?te(H):void 0);if(!a)return{sure:!1,reading:$,usage:O.usage};let w=v?`${we(g($.kind))} have no ${ie.called}.`:`${we(g($.kind))} have no one ${ie.called} them.`;return{sure:!0,reading:$,...X?{taken:X}:{},missing:{said:w,need:{link:{on:$.kind,called:ie.called,to:"person"}},who:a},text:w,usage:O.usage}}return{sure:!1,reading:$,...X?{taken:X}:{},...I&&m&&m.chance>=.3?{act:I}:{},usage:O.usage}}var ze=/\b(me|my|mine|myself)\b/i,zn=/\b(?:to|off|from|for|with)\s+(her|him|them|that person|whoever)\b|\b(?:take|put|move|swap|drop)\s+(her|him)\b/i,Bn=/^(her|him|them|they|that person|whoever)$/i;function Yn(n,e,t){if(!e)return;let s=n.graph.getNode(e.id),i=s?L(n.schema.tryDefinition(s.kind),s).toLowerCase():void 0;return(i?n.graph.allNodes().find(c=>c.id!==e.id&&t.has(c.kind)&&L(n.schema.tryDefinition(c.kind),c).toLowerCase()===i):void 0)??(s&&t.has(s.kind),s)}function Qn(n,e){let t=n.graph.getNode(e);return t?L(n.schema.tryDefinition(t.kind),t):void 0}function Kn(n,e,t,s){let i=n.schema,o=e?[...n.graph.in(e),...n.graph.out(e)].filter(r=>s.includes(r.kind)):[],c=(t??"").toLowerCase(),y=[...c?n.graph.allNodes().filter(r=>s.includes(r.kind)&&L(i.tryDefinition(r.kind),r).toLowerCase().split(/\s+/).some(h=>h.length>=3&&new RegExp(`\\b${h.replace(/[^\p{L}\p{N}]/gu,"")}\\b`,"u").test(c))):[],...o],k=r=>L(i.tryDefinition(r.kind),r).toLowerCase();return y.filter((r,h)=>y.findIndex(g=>k(g)===k(r))===h).slice(0,8)}function Be(n,e,t){if(t.includes("*")||t.includes(e.kind))return e;let s=n.schema,i=L(s.tryDefinition(e.kind),n.graph.getNode(e.id)).toLowerCase();return n.graph.allNodes().find(o=>t.includes(o.kind)&&L(s.tryDefinition(o.kind),o).toLowerCase()===i)}function vn(n){let e=n.split(/\s*(?:,\s*and then|,\s*then|\band then\b|;|\bthen\b|,?\s+and\s+)\s*/i).map(i=>i.trim()).filter(Boolean);if(e.length<2||e.length>3)return[n];let t=/^(the|a|an|my|our|your|this|these|that|those|all|every|each|some|it|them|they|he|she|i|we|you|to|for|with|on|in|at|by|of|from|tomorrow|today|tonight|monday|tuesday|wednesday|thursday|friday|saturday|sunday)$/i,s=i=>{let o=i.split(/\s+/);return o.length>=2&&/^[a-z]/.test(o[0])&&!t.test(o[0])};return e.every(s)?e:[n]}function Oe(n,e=!1){let t=n.toLowerCase(),s=/\b(done|finished|completed|complete|closed|ticked|checked)( off)? (ones?|tasks?|items?|stuff|things|bits)\b/.test(t)||/\b(ones?|tasks?|items?|things|stuff) (i'?ve|we'?ve|i have|we have|that are|that'?s|already) (done|finished|completed|closed|ticked off)\b/.test(t)||/\balready (done|finished|completed)\b/.test(t)||/\bthe (finished|completed)\b/.test(t),i=/\b(outstanding|remaining|unfinished|undone|incomplete|pending)\b/.test(t)||/\b(still to do|left to do|not done|not finished|not yet done)\b/.test(t)||/\b(open) (ones?|tasks?|items?|stuff|things)\b/.test(t)||e&&/\bopen\b/.test(t);return s&&i?{open:!1,finished:!1}:{open:i,finished:s}}function $n(n){let{open:e,finished:t}=Oe(n);return e||t?!0:xn(n)?!1:/\b(all|every|each|everything|the lot|the whole (list|lot)|every one|both|these|those)\b/i.test(n)}function xn(n){let e=/\bthe ([a-z]+) (ones?|tasks?|items?|stuff|things|shifts?|songs?)\b/i.exec(n)?.[1]?.toLowerCase();return e!==void 0&&!["other","rest","whole","same"].includes(e)&&!Oe(`the ${e} ones`).open&&!Oe(`the ${e} ones`).finished}function Ke(n,e){return n.derived?.act==="archive"&&n.destructive!==!0&&/\b(these|those|all|everything|every one|each|them|the lot|the whole (list|lot))\b/i.test(e)?.75:.9}function _e(n){return n.destructive===!0||n.derived?.act==="remove"||n.derived?.act==="archive"}function Vn(n,e,t){let s=n.schema,i=e.trim().split(/\s+/)[0].toLowerCase(),o=h=>Sn.some(g=>n.graph.getNode(h)?.[g]===!0),c=t.records.filter(o),u=(s.tryDefinition(t.kind)?.noun??t.kind).toLowerCase(),y=K(s,t.kind).toLowerCase(),k=/ (in .+)$/.exec(t.words)?.[1],r=`all ${t.records.length} ${y}${k?` ${k}`:""}`;return c.length>0&&c.length<t.records.length?`Should I ${i} the ${c.length} done ${c.length===1?u:y}, or ${r}?`:`Should I ${i} ${r}? Say \u201Call\u201D to go ahead, or say which.`}function Ve(n){let e=/^\s*(?:please\s+|pls\s+|could you\s+|can you\s+|would you\s+|can we\s+|let'?s\s+)?(e-?mail|mail|text|sms|message|whatsapp|call|phone|ring|dial|pay|venmo|book|reserve|post|tweet|share)\b(.*)$/i.exec(n);return e!==null&&!/^\s+(?:it|this|that|this one)\s+(?:[A-Z“"']|as\b|to\b)/.test(e[2]??"")}var Xn=[[/\b(e-?mail|mail)\b/i,"send email"],[/\b(text|sms|message|whatsapp|dm)\b/i,"send messages"],[/\b(call|phone|ring|dial)\b/i,"make calls"],[/\b(pay|venmo|transfer|invoice)\b/i,"make payments"],[/\b(book|reserve)\b/i,"book things"],[/\b(post|tweet|share)\b/i,"post outside this app"]];function Xe(n,e,t){let s=Xn.find(([c])=>c.test(e))?.[1]??"do things outside this app",i=t?n.graph.getNode(t):void 0,o=i?Object.values(i).find(c=>typeof c=="string"&&(/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(c)||/^https?:\/\//.test(c))):void 0;return o?`I can't ${s} from here, but its ${o.includes("@")&&!o.startsWith("http")?"email":"link"} is ${o} \u2014 open it to do that.`:`I can't ${s} from here: this app keeps your records, and doing that happens outside it.`}function Ze(n){return Zn(n)?!1:/\?\s*$/.test(n)||/^\s*(who|whom|whose|what|whats|what's|when|where|which|why|how|is|are|was|were|can|could|should|any|anything|tell me|show me|list)\b/i.test(n)||/^\s*(do|does|did)\s+(you|we|i|they|it|he|she|anyone|anybody|any)\b/i.test(n)}function Zn(n){let e=n.trim().toLowerCase();return!!(/^(please|pls|kindly)\b/.test(e)||/^(could|can|would|will) (you|we|u)\s+(please\s+)?(?!tell|say|explain|show me what|see)\w+/.test(e)&&!/^(could|can|would|will) (you|we) (be|have)\b/.test(e)||/^(i'?d like|i would like|i want|i need|let'?s|we should|we need to)\b/.test(e)||/^[\p{L}'’]+(\s[\p{L}'’]+)?\s+(should|needs to|need to|has to|have to|ought to)\s+(be\s+)?\w+/u.test(e)&&!/^(what|who|which|when|where|why|how|is|are|do|does)\b/.test(e))}function et(n){let e=n.trim().replace(/[.!]+$/,""),t=[/^(?:the\s+|its\s+|this\s+|list\s+|task\s+)*name\s+should\s+be\s+["“']?(.+?)["”']?$/i,/^(?:please\s+)?call\s+(?:this one|this list|this task|this shift|this song|it|this)\s+["“']?(.+?)["”']?$/i,/^["“']?(.+?)["”']?\s+is\s+a\s+better\s+name$/i,/^(?:please\s+)?(?:re)?name\s+(?:this one|this list|this task|this shift|this song|it|this)\s+(?:to\s+|as\s+)?["“']?(.+?)["”']?$/i,/^(?:let'?s\s+)?call\s+(?:it|this)\s+["“']?(.+?)["”']?$/i];for(let s of t){let i=s.exec(e)?.[1]?.trim();if(i)return i}}var en=/^\s*(undo|take (that|it) back|revert|go back)\b/i;function Me(n){let e=/\b(?:to|as)\s+["“']?(.+?)["”']?\s*[.!]?\s*$/i.exec(n)?.[1]?.trim();return e&&e.length>0?e:void 0}function nt(n){return n?.type!=="choice"?[]:Object.entries(n.probabilities).filter(([e])=>e!=="none").sort((e,t)=>t[1]-e[1]).map(([e,t])=>({name:e.slice(e.indexOf(":")+1),chance:t}))}function tt(n){let e=n?.trim();return e?`${e}${/[.!?]$/.test(e)?"":"."} `:""}function nn(n,e,t){let s=[],i=(ue(n)??[]).filter(r=>r!==n.subject?.arg),o=Z(n.input).filter(r=>r.name!==n.subject?.arg),c=e.tryDefinition(t)?.fields?.shape??{},u=r=>c[r]?._zod?.def?.type==="optional"?c[r]?._zod?.def?.innerType?._zod?.def?.type:c[r]?._zod?.def?.type,y=n.derived?.act;y==="remove"?s.push("removes it"):y==="archive"?s.push("sets it aside in the archive"):y==="unarchive"?s.push("brings it back from the archive"):y==="merge"?s.push("merges it into another"):y==="edit"&&s.push("changes any of its fields to values given");for(let r of n.writes??[])n.sets&&r in n.sets?s.push(`sets ${r} to ${String(n.sets[r])}`):i.includes(r)?s.push(`sets ${r} to a value given`):u(r)==="boolean"?s.push(`sets ${r} yes or no`):s.push(`changes ${r}`);for(let r of i)!(n.writes??[]).includes(r)&&!o.some(h=>h.name===r)&&y!=="edit"&&s.push(`takes ${r}`);let k=[...new Set(o.flatMap(r=>r.kinds))].filter(r=>r!=="*").join(" or ");return(n.connects?.length??0)>0&&(n.severs?.length??0)>0?s.push(`moves it to another ${k||"record"}`):(n.connects?.length??0)>0?s.push(`links it to ${Le(k||"record")}`):(n.severs?.length??0)>0&&s.push(`unlinks it from ${Le(k||"record")}`),n.destructive&&y!=="remove"&&s.push("removes it for good"),(n.creates?.length??0)>0&&s.push(`adds a new ${n.creates.join(" or ")}`),s.length>0?`(It ${s.join(", ")}.)`:""}var st=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],it=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function tn(n){let e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(n);if(!e)return;let t=new Date(Date.UTC(Number(e[1]),Number(e[2])-1,Number(e[3])));return`${st[t.getUTCDay()]}, ${it[t.getUTCMonth()]} ${t.getUTCDate()}`}function sn(n,e){let t=n.schema;if(e.records.length===1&&typeof e.act.describe=="function"&&e.act.subject)try{let f=e.act.describe({...e.args,[e.act.subject.arg]:e.records[0]},n.graph);if(typeof f=="string"&&f.trim()){let p=he(n),v=[e.records[0]].filter(A=>n.graph.getNode(A)!==void 0).map(A=>n.graph.getNode(A)).filter(A=>!p.includes(A.kind)).map(A=>L(t.tryDefinition(A.kind),A)).sort((A,J)=>J.length-A.length),R=f.trim().replace(/"([^"]*)"/g,"\u201C$1\u201D");for(let A of v)R.includes(`\u201C${A}\u201D`)||(R=R.replace(A,`\u201C${A}\u201D`));let N=R.replace(/\b(\d{4}-\d{2}-\d{2})\b/g,A=>tn(A)??A).replace(/[.!]+$/,"");return`${N.charAt(0).toUpperCase()}${N.slice(1)}.`}}catch{}let s=f=>{let p=n.graph.getNode(f);return p?L(t.tryDefinition(p.kind),p):void 0},i=Z(e.act.input),o=e.act.subject?.arg,c=Object.entries(e.args).filter(([f,p])=>f!==o&&p!==void 0&&p!==null&&p!=="").map(([f,p])=>{if(i.find(R=>R.name===f)&&typeof p=="string"){let R=n.graph.getNode(p),N=s(p)??p;return{arg:f,said:R?N:p,ref:!0}}return typeof p=="string"?{arg:f,said:tn(p)??`\u201C${p}\u201D`,ref:!1}:{arg:f,said:String(p),ref:!1}}),y=(e.records[0]?n.graph.getNode(e.records[0]):void 0)?.kind,k=y?(t.tryDefinition(y)?.noun??y).toLowerCase():"record",r=e.records.length,h=e.itself&&r===1&&e.records[0]?s(e.records[0])?`\u201C${s(e.records[0])}\u201D`:"it":`the ${r}${e.narrowed?` ${e.narrowed}`:""} ${r===1?k:y?K(t,y).toLowerCase():"records"}${e.where?` ${e.where}`:""}`,g=(e.act.title??e.act.name).trim().replace(/[.!]+$/,""),b=/\b(it|this|the (?:task|list|shift|record|song|item))\b/i;if(/^(they|it|this|she|he|somebody|someone)\b/i.test(g))return g=g.replace(/^(they|it|this|she|he|somebody|someone)\b/i,h).replace(/^(\S.*?)\s+\b(have|are)\b/i,(f,p,v)=>`${p} ${r===1?v.toLowerCase()==="have"?"has":"is":v}`),`${g.charAt(0).toUpperCase()}${g.slice(1)}.`;g=b.test(g)?g.replace(b,h):/^\S+ the \w+$/i.test(g)?`${g} of ${h}`:g.replace(/^(\S+)/,`$1 ${h}`);for(let f of c)/\b(?:to|into|on) another \w+/i.test(g)?g=g.replace(/\b(to|into|on) another \w+/i,`$1 ${f.said}`):/\banother \w+/i.test(g)?g=g.replace(/\banother \w+/i,f.said):g=`${g} ${f.ref&&!/\bto\b/i.test(g)&&/^(cover|assign|give)/i.test(g)?"with":"to"} ${f.said}`;return`${g.charAt(0).toUpperCase()}${g.slice(1)}.`}function On(n,e,t){let s=n.schema,i=he(n),o=h=>{let g=n.graph.getNode(h);if(!g)return h;let b=L(s.tryDefinition(g.kind),g);return i.includes(g.kind)?b:`\u201C${b}\u201D`},c=e.writes?.[0],u=t[0]?n.graph.getNode(t[0]):void 0,y=c&&u?u[c]:void 0,k=t.length===1?o(t[0]):`All ${t.length} of them`,r=t.length===1?"is":"are";return c&&typeof y=="boolean"?`Nothing to change: ${k} ${r} already ${y?"":"not "}${c.replace(/[A-Z]/g,h=>` ${h.toLowerCase()}`)}.`:c&&(typeof y=="string"||typeof y=="number")?`Nothing to change: ${t.length===1?`${k}'s`:"their"} ${c.replace(/[A-Z]/g,h=>` ${h.toLowerCase()}`)} ${r==="is"?"is":"are"} already ${tn(String(y))??y}.`:`Nothing to change: ${k} ${r} already as that would leave ${t.length===1?"it":"them"}.`}var Nn="I can't do that here: nothing in this app does what you asked. Try saying it another way.";function Cn(n){return/\b(can'?t|cannot|couldn'?t|won'?t|not|no|isn'?t|doesn'?t|don'?t|unable|nothing|never)\b/i.test(n)?!1:/\b(is|are|was|were|has been|have been|got|gets)\s+(now\s+)?(\w+ed|done|taken|set|put|given|made|gone|off|out|away|moved|removed)\b/i.test(n)||/^(i'?ve|i have|done|marked|moved|removed|archived|renamed|assigned|added|scheduled|deleted|dropped|finished|closed|updated|changed|set|put|took|taken)\b/i.test(n.trim())||/\b(i'?ve|i have)\s+\w+ed\b/i.test(n)}var ot=/\b(not in (this|the) app|isn'?t in (this|the) app|is not in (this|the) app|not (yet )?(a|one of the) (user|member|person|people|volunteer|record)s?|doesn'?t exist|does not exist|no one (called|named)|nobody (called|named)|not found|no such|there is no|there'?s no|no (user|person|member|volunteer|record|one) (called|named))\b/i;function on(n,e){if(!ot.test(e))return[];let t=n.schema,s=he(n),i=e.toLowerCase();return n.graph.allNodes().flatMap(o=>{let c=L(t.tryDefinition(o.kind),o),u=c.split(/\s+/)[0];return c.length>=3&&(i.includes(c.toLowerCase())||s.includes(o.kind)&&u.length>=3&&new RegExp(`\\b${u.toLowerCase().replace(/[^\p{L}\p{N}]/gu,"")}\\b`,"u").test(i))?[{id:o.id,name:c,kind:o.kind}]:[]}).slice(0,5)}function Te(n){if(!n.off)return n.fast??(n.decide?{model:n.name??"decide",decide:n.decide}:void 0)}function Re(n){if(n.off)return;if(n.thinking)return n.thinking;let e=n.name??"model";if(n.complete){let t=n.complete;return{model:e,think:({system:s,prompt:i})=>t({prompt:i,system:s})}}if(n.turn){let t=n.turn;return{model:e,think:async({system:s,prompt:i})=>({text:await t({system:s,messages:[{role:"user",content:i}],tools:[],call:async()=>({error:"No tools here."})})})}}}var Ce=(n,e,t)=>n?e/1e6*(n.inputPerMillion??0)+t/1e6*(n.outputPerMillion??0):void 0,rt=()=>`ai-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;function at(n,e,t=[]){let s=i=>{let o=n.graph.getNode(i);return o?L(n.schema.tryDefinition(o.kind),o):"a record"};switch(e.on){case"record":return s(e.id);case"field":return`${s(e.id)} \xB7 ${e.field}`;case"selection":return`${e.ids.length} records`;case"list":return n.schema.tryDefinition(e.kind)?K(n.schema,e.kind):e.kind;case"lens":case"place":return t.find(i=>i.as===e.place)?.title??(e.place==="home"?"Home":e.place);case"act":return e.act}}var jn=n=>n.type!=="act"||n.asks.length===0,Ee=(n,e)=>({id:n.id,type:n.type,label:n.label,...e!==void 0?{confidence:e}:{}});function be(n,e){let t=e.interaction??rt(),s=pn(e.store,e.target,{principal:e.principal,...e.acts?{acts:e.acts}:{},...e.places?{places:e.places}:{}}),i=yn(e.store,e.target,{principal:e.principal,...e.place?{place:e.place}:{},...e.selection?{selection:e.selection}:{},...e.purpose?{purpose:e.purpose}:{}}),o=[];return{id:t,catalog:s,state:i,entry:{id:t,at:new Date().toISOString(),by:e.by??e.principal,target:e.target,targetLabel:at(e.store,e.target,e.places)},usage:o,meter:c=>{o.push(c),n.meter?.({...c,interaction:t})}}}async function Se(n,e,t,s){let i=await n.decide(e,t),{inputTokens:o,outputTokens:c}=i.usage,u=Ce(n.price,o,c);return s({tier:"fast",model:n.model,inputTokens:o,outputTokens:c,...u!==void 0?{costUsd:u}:{}}),i.answers}async function ne(n,e,t,s,i){let o=await n.think({system:e,prompt:t,state:s.state,catalog:s.catalog}),c=o.usage?.inputTokens,u=o.usage?.outputTokens,y=o.usage?.costUsd??(c!==void 0?Ce(n.price,c,u??0):void 0);return i({tier:"thinking",model:n.model,...c!==void 0?{inputTokens:c}:{},...u!==void 0?{outputTokens:u}:{},...y!==void 0?{costUsd:y}:{}}),mn(o.text)}function Ae(n,e){let t=new Map(n.map((s,i)=>[`c${i+1}`,s]));return{question:{type:"choice",instructions:e,criteria:Object.fromEntries([...t].map(([s,i])=>[s,`${i.label} \u2014 ${i.description}`]))},of:s=>t.get(s)}}function Pe(n,e,t){if(n?.type!=="choice")return[];let s=n,i=Object.entries(s.probabilities).sort((o,c)=>c[1]-o[1]);return i.some(([o])=>o===s.choice)||i.unshift([s.choice,s.confidence]),i.flatMap(([o,c])=>{let u=e(o);return u?[{candidate:u,confidence:c}]:[]}).slice(0,t)}var _=(n,e,t,s)=>({interaction:{...n.entry,ask:{kind:t,said:e??""},offered:[],outcome:"failed",failed:s,usage:[...n.usage]},offers:[]}),ve="AI isn't on here.";async function Et(n,e,t=3){let s=be(n,e),i=e.said??"Suggest",o=s.catalog.candidates.filter(jn).slice(0,24);if(o.length===0)return{interaction:{...s.entry,ask:{kind:"suggest",said:i},offered:[],outcome:"offered",usage:[]},offers:[]};let c=Te(n),u=Re(n),y=[];try{if(c){let{question:k,of:r}=Ae(o,"Which of these would the person most likely want to do next, here?"),h=await Se(c,{...s.state,candidates:o.map(g=>({id:g.id,type:g.type,says:g.description}))},{next:k},s.meter);y=Pe(h.next,r,t)}else if(u){let k=await ne(u,'You suggest what a person most likely wants to do next in an app. Answer only JSON: {"pick": [candidate ids, best first]}. Pick only ids from the candidates.',JSON.stringify({state:s.state,candidates:o.map(h=>({id:h.id,says:h.description}))}),s,s.meter);y=(Array.isArray(k?.pick)?k.pick.filter(h=>typeof h=="string"):[]).flatMap(h=>o.filter(g=>g.id===h)).slice(0,t).map(h=>({candidate:h}))}else return _(s,i,"suggest",ve)}catch(k){return _(s,i,"suggest",k instanceof Error?k.message:String(k))}return{interaction:{...s.entry,ask:{kind:"suggest",said:i},offered:y.map(({candidate:k,confidence:r})=>Ee(k,r)),outcome:"offered",usage:[...s.usage]},offers:y.map(({candidate:k})=>k)}}var dt=n=>`several:${n}`;async function It(n,e,t=2){let s=be(n,{...e,acts:[]}),i=e.said??"Suggest for the chosen",o=e.target.on==="selection"?e.target.ids.length:1,u=[...e.shared.map(r=>({type:"act",id:dt(r.id),label:r.label,description:`${r.label}, for all ${o} chosen`,mutation:r.mutation,args:r.args,asks:[]})),...s.catalog.candidates.filter(r=>r.type==="panel"||r.type==="place")].slice(0,24),y=Te(n);if(!y)return _(s,i,"suggest",ve);if(u.length===0)return{interaction:{...s.entry,ask:{kind:"suggest",said:i},offered:[],outcome:"offered",usage:[]},offers:[]};let k;try{let{question:r,of:h}=Ae(u,`Which of these would the person most likely want to do next with the ${o} records they chose together?`),g=await Se(y,{...s.state,candidates:u.map(b=>({id:b.id,type:b.type,says:b.description}))},{next:r},s.meter);k=Pe(g.next,h,t).filter((b,f)=>f===0||b.confidence>=ct)}catch(r){return _(s,i,"suggest",r instanceof Error?r.message:String(r))}return{interaction:{...s.entry,ask:{kind:"suggest",said:i},offered:k.map(({candidate:r,confidence:h})=>Ee(r,h)),outcome:"offered",usage:[...s.usage]},offers:k.map(({candidate:r})=>r)}}var ct=.25;async function Ut(n,e){let t=be(n,e),s=e.said??"Fill in",i=t.catalog.candidates.filter(h=>h.type==="fill"),o=new Map;for(let h of i)o.set(h.field,[...o.get(h.field)??[],h]);if(o.size===0)return{interaction:{...t.entry,ask:{kind:"fill",said:s},offered:[],outcome:"offered",usage:[]},offers:[]};let c=Te(n),u=Re(n),y=[];try{if(c){let h=[...o].map(([b,f],p)=>({key:`f${p+1}`,field:b,...Ae(f,`Which value fits "${b}" best for this record?`)})),g=await Se(c,t.state,Object.fromEntries(h.map(b=>[b.key,b.question])),t.meter);for(let b of h){let f=!lt(e.store,e.target,b.field)&&ft(e.store,e.target,b.field)!=="one";y.push(...Pe(g[b.key],b.of,f?3:1).filter((p,v)=>v===0||p.confidence>=.4))}}else if(u){let h=await ne(u,`You fill in a record's fields in an app. Answer only JSON: {"fills": [candidate ids]}, at most one per field, only ids from the candidates.`,JSON.stringify({state:t.state,candidates:i.map(f=>({id:f.id,says:f.description}))}),t,t.meter),g=Array.isArray(h?.fills)?h.fills.filter(f=>typeof f=="string"):[],b=new Set;for(let f of g){let p=i.find(v=>v.id===f);p?.type==="fill"&&!b.has(p.field)&&(b.add(p.field),y.push({candidate:p}))}}else return _(t,s,"fill",ve)}catch(h){return _(t,s,"fill",h instanceof Error?h.message:String(h))}let k=t.usage.at(-1)?.model,r=Ie(e.store,{interaction:t.id,target:e.target,basis:s,...k?{model:k}:{},proposals:y.flatMap(({candidate:h,confidence:g})=>h.type==="fill"?[{id:h.id,label:h.label,said:h.description,call:h.call,record:h.record,field:h.field,...g!==void 0?{confidence:g}:{}}]:[])},e.principal);return{interaction:{...t.entry,ask:{kind:"fill",said:s},offered:r.proposals.map(h=>({id:h.id,type:"fill",label:h.label,...h.confidence!==void 0?{confidence:h.confidence}:{}})),outcome:"offered",usage:[...t.usage]},offers:[],...r.proposals.length>0?{ghost:r}:{}}}function lt(n,e,t){let s=e.on==="record"||e.on==="field"?e.id:void 0,i=s?n.graph.getNode(s)?.kind:void 0,o=(i?n.schema.tryDefinition(i)?.fields?.shape:void 0)??{};return t in o}function ft(n,e,t){let s=e.on==="record"||e.on==="field"?e.id:void 0,i=s?n.graph.getNode(s)?.kind:void 0;return i?n.schema.tryDefinition(i)?.edges?.[t]?.cardinality:void 0}async function Jt(n,e){let t=be(n,e),s=e.said??"Add one",i=new Set(e.store.allMutations().filter(r=>(r.creates??[]).length>0).map(r=>r.name)),o=t.catalog.candidates.filter(r=>r.type==="act"&&r.asks.length>0&&i.has(r.mutation));if(o.length===0)return _(t,s,"record","Nothing here makes a record.");let c=Re(n);if(!c)return _(t,s,"record",ve);let u;try{let r=await ne(c,'You propose one new record for an app by filling in an act. Answer only JSON: {"act": a candidate id, "args": {argument: value}}. Use only the candidates, and fill every argument the act asks for with a value that fits the state.',JSON.stringify({ask:s,state:t.state,candidates:o.map(b=>({id:b.id,says:b.description,asks:b.asks}))}),t,t.meter),h=o.find(b=>b.id===r?.act),g=typeof r?.args=="object"&&r.args!==null?r.args:{};h&&(u={act:h,args:Object.fromEntries(Object.entries(g).filter(([b])=>h.asks.includes(b)))})}catch(r){return _(t,s,"record",r instanceof Error?r.message:String(r))}if(!u)return _(t,s,"record","The model named no act this app has here.");let y=t.usage.at(-1)?.model,k=Ie(e.store,{interaction:t.id,target:e.target,basis:s,...y?{model:y}:{},proposals:[{id:u.act.id,label:u.act.label,said:u.act.description,call:{name:u.act.mutation,args:{...u.act.args,...u.args}}}]},e.principal);return k.proposals.length===0?_(t,s,"record","What the model proposed could not be made here."):{interaction:{...t.entry,ask:{kind:"record",said:s},offered:k.proposals.map(r=>({id:r.id,type:"act",label:r.said})),outcome:"offered",usage:[...t.usage]},offers:[u.act],ghost:k}}async function Wt(n,e){let t=be(n,e),s=e.said??"Make a panel",i=t.catalog.candidates.filter(r=>r.type==="panel");if(i.length===0)return _(t,s,"panel","Nothing here can be drawn as a panel.");let o=Te(n),c=Re(n),u;try{if(c){let r=await ne(c,'You choose a panel to draw in an app. Answer only JSON: {"panel": a candidate id, "title": a short title}. Choose only among the candidates.',JSON.stringify({ask:s,state:t.state,candidates:i.map(g=>({id:g.id,says:g.description}))}),t,t.meter),h=i.find(g=>g.id===r?.panel);h&&(u={panel:h,...typeof r?.title=="string"&&r.title.trim()?{title:r.title.trim().slice(0,60)}:{}})}else if(o){let{question:r,of:h}=Ae(i,`Which panel answers this best: ${s}`),g=Pe((await Se(o,t.state,{panel:r},t.meter)).panel,h,1)[0];g?.candidate.type==="panel"&&(u={panel:g.candidate,confidence:g.confidence})}else return _(t,s,"panel",ve)}catch(r){return _(t,s,"panel",r instanceof Error?r.message:String(r))}if(!u)return _(t,s,"panel","The model named no panel this app can draw.");let y=u.title??u.panel.label,k={title:y,recipe:{...u.panel.panel,title:y}};return{interaction:{...t.entry,ask:{kind:"panel",said:s},offered:[Ee(u.panel,u.confidence)],outcome:"drawn",panel:k,usage:[...t.usage]},offers:[u.panel],panel:k}}function ut(n){return n.off?void 0:n.answer}var ke=`You answer a person who typed words about what they are looking at in an app, from the state given and nothing else: "facts" says the fields and links of each record ("covered by Ada Nowak", "holds it: This week"), as they see them \u2014 answer from them, and never say a record has no link the facts show. Before answering, look through "facts" for the link or field the words are about \u2014 what it waits for, who covers it, what holds it, when it is due \u2014 and name it: "what is blocking this" is answered by its "waits for" links, by name. A link the facts do not show is not there: say plainly that there is none, never borrow one from another record, and answer what was asked \u2014 a count by counting, a day by its day. Answer only JSON: {"answer": one to three short, whole sentences written to the person, "pick": [candidate ids that act on the answer, best first, at most three]}. Pick only ids from the candidates, and none when nothing fits. Never say an id to the person. Where "members" are given and the person asks for something done to them, answer "each": {"act": the name of one of "member_acts", "args": every value it asks for, by name, dates as YYYY-MM-DD counted from "today"; the facts already say each day against today, so trust those} \u2014 one act over every member, as one change. Judge an act by what it does ("does"), not only its title: "close", "complete", "check off", "tick" and "finish" are an act that marks something done; "delete" one that removes; "push", "move" and "postpone" one that changes a date or a place. Where "fast_leaned_to" names an act, it is likely the one: fill its values. When the person tells it to do something, answer "each" (with a short "answer" saying what it will do): nothing is done until they accept, so never say in words that it is done, and never ask them to confirm ("Move it to Friday?"): the card asks them, so answer "each". Where "people" maps a word like "her" or "me" to a name, that is who they mean. Only where no act among "member_acts" or the candidates does what they ask, because the app has no field or link for it, answer "lacks": one whole sentence to the person saying what the app is missing (never an id, never a note to yourself), and "need": what it would need \u2014 {"link": {"on": the kind of the records, "called": what the link is called in their words, like "assigned to", "to": the kind it points to, or a noun for one the app lacks}} or {"field": {"on": the kind, "called": its name in their words, "type": "string", "number", "date" or "boolean"}} \u2014 with "who": the name of the record their words name (for a link) or "value": the value they give (for a field). When they ask for a change the app has no field or link for ("make these urgent", "give these a priority"), answer "lacks" and "need", never only "answer". A question is answered in "answer", never with "each" or "lacks"; so is "undo that", which the app's own Undo does.`,ht='Where nothing in the state or the catalog answers the words \u2014 the app keeps no such thing \u2014 do not answer only that you found nothing: reply with "lacks", one whole sentence to the person saying what this app does not keep ("This app keeps no budgets."), and "need" where one field or link on these records would hold it ({"field": {"on": kind, "called": name, "type": "string" | "number" | "date" | "boolean"}} or {"link": {"on": kind, "called": name, "to": kind}}). This holds for a question too.',gt='Where nothing in "facts" or "state" answers the words \u2014 the app keeps no such thing \u2014 do not answer only that you found nothing: answer "lacks", one whole sentence to the person saying what this app does not keep ("This app keeps no budgets."), and "need" where one field or link on these records would hold it. This holds for a question too.';async function Ft(n,e){let t=be(n,e),s=e.said.trim(),i=ut(n),o=Te(n),c=[],u=async(d,S,l)=>{let T=Date.now();try{return await l()}finally{c.push({stage:d,ms:Date.now()-T,model:S})}},y={...t,entry:t.entry},k,r,h,g;if(o&&s&&!i&&(e.target.on==="record"||e.target.on==="list"||e.target.on==="lens"||e.target.on==="selection"))try{let d=$=>An(o,{store:e.store,target:e.target,said:$,...e.principal.id?{principal:{id:e.principal.id}}:{},...e.members?{members:e.members}:{},...e.follows?{follows:e.follows}:{},...e.where?{where:e.where}:{},...e.examples?{examples:e.examples}:{}}),S=vn(s);if(S.length>1){let $=await u("fast",o.model,()=>Promise.all(S.map(d)));for(let m of $){let P=Ce(o.price,m.usage.inputTokens,m.usage.outputTokens);y.meter({tier:"fast",model:o.model,inputTokens:m.usage.inputTokens,outputTokens:m.usage.outputTokens,...P!==void 0?{costUsd:P}:{}})}if($.every(m=>m.sure&&m.each&&!m.asks))return Rn(e,y,s,$,c)}let l=await u("fast",o.model,()=>d(s)),T=Ce(o.price,l.usage.inputTokens,l.usage.outputTokens);if(y.meter({tier:"fast",model:o.model,inputTokens:l.usage.inputTokens,outputTokens:l.usage.outputTokens,...T!==void 0?{costUsd:T}:{}}),k=l.reading,r=l.act,h=l.asks,g=l.taken,l.sure&&(l.each||l.missing||l.clarify||l.outside))return Rn(e,y,s,l,c)}catch{}let b=()=>h??Ze(s),f=n.off?void 0:n.light,p=Re(n),v=f??p,R=y.catalog.candidates.filter(d=>jn(d)||d.type==="panel"||d.type==="place"||d.type==="record").slice(0,32),N;try{N=o&&(i||v)&&s?await wt(o,s,y,R):_n(y,R)}catch(d){return _(y,s,"ask",d instanceof Error?d.message:String(d))}let A={...y,state:N.state,catalog:{...y.catalog,candidates:N.choices},entry:{...y.entry,context:N.context}},J=N.choices,M=(k?.records??e.members??[]).flatMap(d=>{let S=e.store.graph.getNode(d);return S?[S]:[]}).slice(0,60),$e=new Set(M.map(d=>d.kind)),Y=e.store.allMutations().flatMap(d=>{let S=d.subject?.kinds;if(!d.subject||!(S==="*"||S.some(T=>$e.has(T))))return[];let l=[...$e].find(T=>S==="*"||S.includes(T));return[{name:d.name,title:d.title??d.name,does:`${d.description??""} ${nn(d,e.store.schema,l)}`.trim(),subjectArg:d.subject.arg,asks:(ue(d)??[]).filter(T=>T!==d.subject.arg)}]}),W,C,re,D="",F=[],De=d=>d.flatMap(S=>J.filter(l=>l.id===S)).slice(0,3).map(S=>({candidate:S}));try{if(i){let d=await i.answer({said:s,target:e.target,targetLabel:A.entry.targetLabel,state:A.state,catalog:{target:A.catalog.target,candidates:J},...e.follows?{follows:e.follows}:{},...n.couldNotFind?{couldNotFind:ht}:{}}),S=d.usage?.inputTokens,l=d.usage?.outputTokens,T=d.usage?.costUsd??(S!==void 0?Ce(i.price,S,l??0):void 0);if(A.meter({tier:"thinking",model:i.model,...S!==void 0?{inputTokens:S}:{},...l!==void 0?{outputTokens:l}:{},...T!==void 0?{costUsd:T}:{}}),D=typeof d.text=="string"?d.text.trim():"",F=De(d.pick??[]),typeof d.lacks=="string"&&d.lacks.trim()){let $=Pn(d.need),m=d.lacks.trim();C={said:ee(m)?m:$?Tn(e.store.schema,$):me,...$?{need:$}:{}},D=""}}else if(v){let d=JSON.stringify({ask:s,about:A.entry.targetLabel,...e.follows?{follows:e.follows}:{},...e.examples&&e.examples.length>0?{worked_before:e.examples,worked_before_is:"What people of this app asked before and what was done that they kept: where these words mean the same, do the same."}:{},state:A.state,candidates:J.map(m=>({id:m.id,says:m.description})),facts:wn(e.store,e.principal,[...new Set([...e.target.on==="record"?[e.target.id,...Ye(e.store,e.target.id)?.ids??[]]:[],...M.map(m=>m.id),...e.members??[]])],rn(e.store)),...M.length>0?{members:M.map(m=>({id:m.id,label:L(e.store.schema.tryDefinition(m.kind),m)})),member_acts:Y.map(m=>({name:m.name,title:m.title,does:m.does,asks:m.asks}))}:{},...r?{fast_leaned_to:r}:{},...g?{people:{[g.said]:g.as}}:{},everyone_in_the_app:he(e.store).flatMap(m=>e.store.graph.allNodes().filter(P=>P.kind===m)).slice(0,40).map(m=>L(e.store.schema.tryDefinition(m.kind),m)),...rn(e.store)?{today:bn(rn(e.store))}:{},...n.couldNotFind?{not_found:gt}:{}});re=d;let S=m=>!!(m&&(typeof m.answer=="string"&&m.answer.trim()||Array.isArray(m.pick)&&m.pick.length>0||m.each||m.lacks)),l=await u(f?"light":"thinking",v.model,()=>ne(v,ke,d,A,A.meter));f&&p&&p!==f&&!S(l)&&(l=await u("thinking",p.model,()=>ne(p,ke,d,A,A.meter)));let T=!b()&&!en.test(s)&&M.length>0,$=m=>Array.isArray(m)&&m.some(P=>{let V=J.find(z=>z.id===P);return V!==void 0&&Ne(V)!==void 0});if(T&&l&&!l.each&&!l.lacks&&!$(l.pick)){let m=await u(f?"light":"thinking",v.model,()=>ne(v,ke,JSON.stringify({...JSON.parse(d),told:'They told you to do this, not asked a question. Reply with exactly one of two shapes, never "answer" alone: "each" with an act from member_acts and its values, or "lacks" and "need" (and "value") where no act can \u2014 for example {"lacks": "Tasks have no priority yet.", "need": {"field": {"on": "task", "called": "priority", "type": "string"}}, "value": "high"}.'}),A,A.meter));if(m&&(m.each||m.lacks))l=m;else if(r){let P=Y.find(z=>z.name===r),V=P?e.store.allMutations().find(z=>z.name===P.name)?.input?.shape??{}:{};P&&P.asks.every(z=>V[z]?.safeParse(void 0).success??!0)&&(l={...l,answer:"",each:{act:P.name,args:{}}})}}if(!b()&&l?.each&&(l={...l,pick:Array.isArray(l.pick)?l.pick.filter(m=>{let P=J.find(V=>V.id===m);return P!==void 0&&Ne(P)===void 0}):l.pick}),b()&&l&&(l={...l,each:void 0}),l&&typeof l.answer=="string"&&l.answer.trim()&&!ee(l.answer)&&!l.each&&!l.lacks){let m=await u(f?"light":"thinking",v.model,()=>ne(v,ke,JSON.stringify({...JSON.parse(d),rewrite:`Your answer was not whole sentences: \u201C${String(l.answer).slice(0,300)}\u201D. Say it again in one to three whole sentences to the person, each begun with a capital and ended with a full stop.`}),A,A.meter));m&&typeof m.answer=="string"&&ee(m.answer)?l={...l,answer:m.answer}:b()&&/^[\p{L}\p{N}"“'(][^{}[\]]*$/u.test(String(l.answer).trim())&&String(l.answer).trim().split(/\s+/).length>=2&&(l={...l,answer:`${String(l.answer).trim().charAt(0).toUpperCase()}${String(l.answer).trim().slice(1).replace(/[\s,;:]+$/,"")}.`})}if(b()&&l&&!(typeof l.answer=="string"&&l.answer.trim())){let m=await u(f?"light":"thinking",v.model,()=>ne(v,ke,JSON.stringify({...JSON.parse(d),rewrite:'This is a question: answer it in "answer", in one to three whole sentences, from the facts.'}),A,A.meter));m&&typeof m.answer=="string"&&ee(m.answer)&&(l={...l,answer:m.answer})}if(D=typeof l?.answer=="string"?l.answer.trim():"",F=De(Array.isArray(l?.pick)?l.pick:[]),W=pt(l?.each),D&&!ee(D)&&(D=W?"":me),typeof l?.lacks=="string"&&l.lacks.trim()){let m=Pn(l.need),P=l.lacks.trim();C={said:ee(P)?P:m?Tn(e.store.schema,m):me,...m?{need:m}:{},...typeof l.who=="string"&&l.who.trim()?{who:l.who.trim()}:{},...typeof l.value=="string"||typeof l.value=="number"?{value:String(l.value)}:{}}}}else if(o&&J.length>0){let{question:d,of:S}=Ae(J,`Which of these best answers, or acts on: ${s}`),l=await Se(o,{...A.state,asked:s,candidates:J.map(T=>({id:T.id,type:T.type,says:T.description}))},{answer:d},A.meter);F=Pe(l.answer,S,3),D=F.length>0?`These fit \u201C${s}\u201D.`:""}else return _(A,s,"ask",ve)}catch(d){return _(A,s,"ask",d instanceof Error?d.message:String(d))}for(let d of[D,C?.said??""]){let S=d?on(e.store,d):[];if(S.length===0||!v)continue;let l=S.map(P=>`${P.name} (${K(e.store.schema,P.kind).toLowerCase()})`).join(", "),T=await u(f?"light":"thinking",v.model,()=>ne(v,ke,JSON.stringify({...JSON.parse(re??"{}"),known:`These are in the app: ${l}. Never say they are not.`}),A,A.meter)),$=typeof T?.answer=="string"?T.answer.trim():"",m=$&&ee($)&&on(e.store,$).length===0?$:`${S[0].name} is here, one of its ${K(e.store.schema,S[0].kind).toLowerCase()}. Try saying it another way.`;d!==D&&(C=void 0),D=m}if(!b()&&Ve(s)&&!/\b(field|link|column)\b/i.test(s)&&(C=void 0,W=void 0,F=[],D=Xe(e.store,s,e.target.on==="record"?e.target.id:void 0)),C&&n.couldNotFind){let d=e.target.on==="place"||e.target.on==="lens"?e.target.place:void 0,S=e.target.on==="list"||e.target.on==="lens"?e.target.kind:void 0;if(qe(e.store,{type:"unanswered",question:s,...d?{place:d}:{},...S?{kind:S}:{},lacks:C.said},e.principal),typeof n.couldNotFind=="function")try{n.couldNotFind({said:s,lacks:C.said,...C.need?{need:C.need}:{},...d?{place:d}:{},...S?{kind:S}:{}})}catch{}}let te=!!W||F.some(({candidate:d})=>Ne(d)!==void 0);if(!b()&&!te&&!C&&D&&Cn(D)&&(D=Nn),!D&&F.length===0&&!W&&!C){let d=e.target.on==="place"||e.target.on==="lens"?e.target.place:void 0,S=e.target.on==="list"||e.target.on==="lens"?e.target.kind:void 0;return qe(e.store,{type:"unanswered",question:s,...d?{place:d}:{},...S?{kind:S}:{}},e.principal),_(A,s,"ask","The AI had no answer to that here.")}let xe=A.usage.at(-1)?.model,se=b(),Q=W?e.store.allMutations().find(d=>d.name===W.act):void 0;if(Q&&_e(Q)&&M.length>1&&(k?(k.chance??1)<Ke(Q,s)||Qe(s,k):!$n(s))){let d=`Should I ${(Q.title??Q.name).trim().split(/\s+/)[0].toLowerCase()} all ${M.length} of them? Say \u201Call\u201D to go ahead, or say which.`;return{interaction:{...A.entry,ask:{kind:"ask",said:s},offered:[],outcome:"offered",answer:d,usage:[...A.usage],stages:c},offers:[],answer:d,...k?{reading:k}:{}}}let ge=(se?[]:F).flatMap(({candidate:d,confidence:S})=>{let l=Ne(d);return l?[{...l,...S!==void 0?{confidence:S}:{}}]:[]}),q=W?Y.find(d=>d.name===W.act):void 0;if(q)for(let d of M){let S=e.store.allMutations().find(T=>T.name===q.name),l=S?.subject?.kinds;!S||!(l==="*"||l.includes(d.kind))||ge.push({id:`each:${q.name}:${d.id}`,label:`${q.title}: ${L(e.store.schema.tryDefinition(d.kind),d)}`,said:q.title,call:{name:q.name,args:{...W.args,[q.subjectArg]:d.id}},record:d.id})}let ce=ge.filter((d,S)=>ge.findIndex(l=>l.call.name===d.call.name&&JSON.stringify(l.call.args)===JSON.stringify(d.call.args))===S),O=ce.length>0?Ie(e.store,{interaction:A.id,target:e.target,basis:s,...xe?{model:xe}:{},proposals:ce},e.principal):void 0,pe=F.map(({candidate:d})=>d).filter(d=>se||Ne(d)===void 0);if(!W&&!se&&O&&O.proposals.length>0&&(D=O.proposals.slice(0,3).flatMap(d=>{let S=e.store.allMutations().find(T=>T.name===d.call.name),l=S?.subject?d.call.args[S.subject.arg]:void 0;return S&&typeof l=="string"?[sn(e.store,{act:S,args:d.call.args,records:[l],itself:!0})]:[]}).join(" ")),W&&Q&&O){let d=M.map(S=>S.id).filter(S=>O.proposals.some(l=>l.id===`each:${Q.name}:${S}`));d.length>0&&(D=Ln(e.store,Q,W.args,d,k??(M.length===1&&e.target.on==="record"&&M[0].id===e.target.id?{which:"itself",records:d,kind:M[0].kind,words:"",close:!1}:void 0)))}let an=[...pe.map(d=>Ee(d,F.find(S=>S.candidate===d)?.confidence)),...(O?.proposals??[]).map(d=>({id:d.id,type:d.field!==void 0?"fill":"act",label:d.label,...d.confidence!==void 0?{confidence:d.confidence}:{}}))];return{interaction:{...A.entry,ask:{kind:"ask",said:s},offered:an,outcome:"offered",...D?{answer:D}:{},usage:[...A.usage],stages:c},offers:pe,...O&&O.proposals.length>0?{ghost:O}:{},...D?{answer:D}:C?{answer:C.said}:{},...C?{missing:C.need&&k&&"link"in C.need?{...C,need:{link:{...C.need.link,on:k.kind}}}:C}:{},...k?{reading:k}:{},...g?{taken:g}:{}}}function Ln(n,e,t,s,i){let o=i?.part,c=i?/ (in .+)$/.exec(i.words)?.[1]:void 0;return sn(n,{act:e,args:t,records:s,...o?{narrowed:o}:{},...c?{where:c}:{},itself:i?.which==="itself"})}function rn(n){try{let e=(typeof n.today=="function"?n.today():void 0)??new Date().toISOString();return/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(0,10):void 0}catch{return}}function Tn(n,e){let t=c=>K(n,c).toLowerCase(),s=c=>c.charAt(0).toUpperCase()+c.slice(1),{on:i,called:o}="link"in e?e.link:e.field;return`${s(t(i))} have no \u201C${s(o)}\u201D yet.`}function Rn(n,e,t,s,i){let o=Array.isArray(s)?s:[s],c=[];for(let p of o){if(!p.each||!p.reading)continue;let v=n.store.allMutations().find(R=>R.name===p.each.act);for(let R of p.reading.records){let N=n.store.graph.getNode(R);!N||!v?.subject||c.push({id:`each:${v.name}:${R}`,label:`${v.title??v.name}: ${L(n.store.schema.tryDefinition(N.kind),N)}`,said:v.title??v.name,call:{name:v.name,args:{...p.each.args,[v.subject.arg]:R}},record:R})}}let u=e.usage.at(-1)?.model,y=c.length>0?Ie(n.store,{interaction:e.id,target:n.target,basis:t,...u?{model:u}:{},proposals:c},n.principal):void 0,k=(y?.proposals??[]).map(p=>({id:p.id,type:"act",label:p.label})),r=new Set((y?.proposals??[]).map(p=>p.id)),h=o.map(p=>{if(p.clarify)return p.clarify;if(p.outside)return p.outside;if(p.each&&p.reading){let v=n.store.allMutations().find(N=>N.name===p.each.act),R=p.reading.records.filter(N=>r.has(`each:${p.each.act}:${N}`));return R.length>0&&v?Ln(n.store,v,p.each.args,R,p.reading):v?On(n.store,v,p.reading.records):"Nothing here would change."}return p.text??p.missing?.said??""}).filter(Boolean).join(" "),g=o[0],b=o.find(p=>p.missing)?.missing,f=o.find(p=>p.taken)?.taken;return{interaction:{...e.entry,ask:{kind:"ask",said:t},offered:k,outcome:"offered",...h?{answer:h}:{},usage:[...e.usage],stages:[...i]},offers:[],...y&&y.proposals.length>0?{ghost:y}:{},...h?{answer:h}:{},...b?{missing:b}:{},...g.reading&&o.length===1?{reading:g.reading}:{},...f?{taken:f}:{}}}function Pn(n){if(typeof n!="object"||n===null)return;let{link:e,field:t}=n,s=i=>typeof i=="string"&&i.trim()?i.trim():void 0;if(e&&s(e.on)&&s(e.called)&&s(e.to))return{link:{on:s(e.on),called:s(e.called),to:s(e.to)}};if(t&&s(t.on)&&s(t.called)){let i=["string","number","date","boolean"].includes(String(t.type))?t.type:"string";return{field:{on:s(t.on),called:s(t.called),type:i}}}}function pt(n){if(typeof n!="object"||n===null)return;let{act:e,args:t}=n;if(typeof e=="string")return{act:e,args:typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{}}}function Ie(n,e,t){let s=e.proposals.flatMap(i=>{try{let o=n.previewAll([i.call],{author:t}),c=o.ops.map(u=>u.intent).join("; ");return o.ops.length>0?[{...i,said:c||i.said}]:[]}catch{return[]}});return{...e,proposals:s}}function Ne(n){if(n.type==="fill")return{id:n.id,label:n.label,said:n.description,call:n.call,record:n.record,field:n.field};if(n.type==="act"&&n.asks.length===0)return{id:n.id,label:n.label,said:n.description,call:{name:n.mutation,args:{...n.args}}}}function qt(n,e,t){let s=e.proposals.filter(o=>t.ids===void 0||t.ids.includes(o.id));if(s.length===0)return{ok:!1,refused:"Nothing was chosen."};let i=s.flatMap(o=>o.confidence===void 0?[]:[o.confidence]);try{let c=n.applyAll(s.map(u=>u.call),{author:t.author,via:`ai:${e.interaction}`,intent:e.basis,lineage:{basis:`Asked \u201C${e.basis}\u201D`,...e.model?{model:e.model}:{},...i.length>0?{confidence:Math.min(...i)}:{},interaction:e.interaction}}).ops[0]?.batch;return c?{ok:!0,batch:c,accepted:s.map(u=>u.id)}:{ok:!1,refused:"That changes nothing now."}}catch(o){return{ok:!1,refused:o instanceof Error?o.message:String(o)}}}function Ht(n,e,t){let s=n.ask.kind==="suggest"?e.length>0:n.offered.length>0&&n.offered.every(i=>e.includes(i.id));return{...n,outcome:s?"accepted":"partly",accepted:e,batches:[...n.batches??[],t]}}var Gt=n=>({...n,outcome:"dismissed"}),Dn={candidates:8,records:6},yt=.1,mt=12,Mn=n=>{let e=new Set;return[...n.selection,...n.neighbors].filter(t=>!e.has(t.id)&&(e.add(t.id),!0))};function _n(n,e){return{choices:e,state:n.state,context:{by:"default",candidates:e.map(t=>t.id),records:Mn(n.state).map(t=>t.id)}}}async function wt(n,e,t,s){let i=Mn(t.state),o={},c=s.length>0?Ae(s,`Which of these could answer, or act on: ${e}`):void 0;c&&(o.candidates={...c.question,criteria:{...c.question.criteria,none:"None of these"}});let u=new Map(i.slice(0,mt).map((f,p)=>[`record-${p+1}`,f]));for(let[f,p]of u)o[f]={type:"noul",instructions:`Is \u201C${e}\u201D about ${p.label} (${p.kind})?`};if(Object.keys(o).length===0)return{..._n(t,s),context:{by:"fast",model:n.model,candidates:[],records:[]}};let y=await Se(n,{target:t.state.target,asked:e},o,t.meter),r=c?((f,p,v)=>{if(f?.type!=="choice"||f.choice==="none")return[];let R=Object.entries(f.probabilities).filter(([N])=>N!=="none").sort((N,A)=>A[1]-N[1]);return R.some(([N])=>N===f.choice)||R.unshift([f.choice,f.confidence]),R.filter(([,N],A)=>A===0||N>=yt).flatMap(([N])=>{let A=p(N);return A===void 0?[]:[A]}).slice(0,v)})(y.candidates,c.of,Dn.candidates):[],h=[...u].flatMap(([f,p])=>{let v=y[f];return v?.type==="noul"&&v.noul>.5?[{record:p,chance:v.noul}]:[]}).sort((f,p)=>p.chance-f.chance).slice(0,Dn.records).map(f=>f.record),g=new Set(h.map(f=>f.id)),b={...t.state,selection:t.state.selection.filter(f=>g.has(f.id)),neighbors:t.state.neighbors.filter(f=>g.has(f.id))};return{choices:r,state:b,context:{by:"fast",model:n.model,candidates:r.map(f=>f.id),records:h.map(f=>f.id)}}}export{Jn as a,Te as b,Re as c,rt as d,at as e,Et as f,dt as g,It as h,Ut as i,Jt as j,Wt as k,Ft as l,Ie as m,Ne as n,qt as o,Ht as p,Gt as q};