graview 0.1.68 → 0.1.69

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 (184) hide show
  1. package/dist/preview/{chunk.ODYJEDIW.js → chunk.26RYER7Y.js} +1 -1
  2. package/dist/preview/{chunk.TRNJKHIA.js → chunk.2AL26ZPJ.js} +1 -1
  3. package/dist/preview/chunk.2WFOKJB4.js +1 -0
  4. package/dist/preview/chunk.3D37E2G5.js +1 -0
  5. package/dist/preview/chunk.3PT3BU6K.js +1 -0
  6. package/dist/preview/{chunk.7ZTGB4O7.js → chunk.3TKIZGC7.js} +1 -1
  7. package/dist/preview/{chunk.AQ2PI6MR.js → chunk.3VNOTHA5.js} +1 -1
  8. package/dist/preview/{chunk.QWLK3GKG.js → chunk.3XTIYX6M.js} +1 -1
  9. package/dist/preview/{chunk.GF3ZCX46.js → chunk.447RWLS7.js} +2 -2
  10. package/dist/preview/{chunk.E423JCOS.js → chunk.47VEV4BX.js} +1 -1
  11. package/dist/preview/{chunk.NRCWMYLH.js → chunk.4FJ4OPSJ.js} +1 -1
  12. package/dist/preview/{chunk.XFH6GHBQ.js → chunk.4O7WYLCK.js} +1 -1
  13. package/dist/preview/{chunk.MSUZAJ2K.js → chunk.4R7H3GIL.js} +2 -2
  14. package/dist/preview/{chunk.EB7PZJEO.js → chunk.4RPKCW4J.js} +1 -1
  15. package/dist/preview/{chunk.YM6SWEUI.js → chunk.523EFGHU.js} +1 -1
  16. package/dist/preview/chunk.5DU6FA5R.js +1 -0
  17. package/dist/preview/{chunk.LFFJB6D3.js → chunk.5MOXQUZH.js} +1 -1
  18. package/dist/preview/chunk.5TWRTGP6.js +1 -0
  19. package/dist/preview/{chunk.AWV57UBJ.js → chunk.66TRDXYR.js} +1 -1
  20. package/dist/preview/{chunk.AYZL3LCR.js → chunk.6BNSDPZE.js} +3 -3
  21. package/dist/preview/chunk.6BR2SUAE.js +1 -0
  22. package/dist/preview/{chunk.32JE2WS7.js → chunk.6TDVNWFU.js} +1 -1
  23. package/dist/preview/{chunk.UAMPR4MD.js → chunk.6XBQDXT6.js} +1 -1
  24. package/dist/preview/{chunk.TVWK3SGD.js → chunk.6ZFYFT5A.js} +1 -1
  25. package/dist/preview/{chunk.N5Z34V7U.js → chunk.7L3I776Z.js} +1 -1
  26. package/dist/preview/chunk.7OLKVOS6.js +1 -0
  27. package/dist/preview/{chunk.MKL4THIV.js → chunk.7T2P42VW.js} +1 -1
  28. package/dist/preview/{chunk.QM54TGU6.js → chunk.AG7WJYM5.js} +2 -2
  29. package/dist/preview/{chunk.ECNGVD25.js → chunk.AHYMIVBX.js} +1 -1
  30. package/dist/preview/chunk.AMAOZVEO.js +1 -0
  31. package/dist/preview/chunk.AMV2ILR6.js +1 -0
  32. package/dist/preview/{chunk.RQG672MJ.js → chunk.AUNQNTKY.js} +1 -1
  33. package/dist/preview/{chunk.HXTKBISQ.js → chunk.AZRICZKT.js} +1 -1
  34. package/dist/preview/{chunk.L7XKYGV7.js → chunk.B422DSYN.js} +1 -1
  35. package/dist/preview/{chunk.XDZDNZ7B.js → chunk.B5EFNTDA.js} +1 -1
  36. package/dist/preview/{chunk.F5GNNVSQ.js → chunk.BO32A3W5.js} +1 -1
  37. package/dist/preview/{chunk.ZLEBOR5T.js → chunk.BQORHDAH.js} +1 -1
  38. package/dist/preview/{chunk.4GVKKBQL.js → chunk.BSQI3KM2.js} +1 -1
  39. package/dist/preview/{chunk.BPNW5KCP.js → chunk.C6CT6F4C.js} +1 -1
  40. package/dist/preview/{chunk.JV432T4Q.js → chunk.CA2SYEYE.js} +1 -1
  41. package/dist/preview/{chunk.64LCHHZB.js → chunk.CCCONK73.js} +1 -1
  42. package/dist/preview/{chunk.GONZB3J3.js → chunk.CDSHUWSK.js} +1 -1
  43. package/dist/preview/{chunk.NFTPJAMJ.js → chunk.CKSRW3LA.js} +1 -1
  44. package/dist/preview/{chunk.LOKGUALC.js → chunk.CLIC2QBA.js} +1 -1
  45. package/dist/preview/{chunk.PLIV3IQK.js → chunk.CLZYNFFH.js} +1 -1
  46. package/dist/preview/{chunk.GKTQ5CZA.js → chunk.CSVDBDRZ.js} +2 -2
  47. package/dist/preview/{chunk.GJTEV6CK.js → chunk.CUEIGKFG.js} +1 -1
  48. package/dist/preview/{chunk.IPGLITWA.js → chunk.CYEPHT7V.js} +1 -1
  49. package/dist/preview/{chunk.BQAFFEOA.js → chunk.D3SWJ7OS.js} +1 -1
  50. package/dist/preview/{chunk.ACNOP2IU.js → chunk.D5JZQZ74.js} +1 -1
  51. package/dist/preview/{chunk.6AANHELP.js → chunk.DHPXRDT5.js} +5 -5
  52. package/dist/preview/{chunk.R3GE37OI.js → chunk.DKUEZPGR.js} +1 -1
  53. package/dist/preview/{chunk.2TUEBU7X.js → chunk.DO3FQM6R.js} +1 -1
  54. package/dist/preview/{chunk.G2BDEWJC.js → chunk.DRAPVGQZ.js} +1 -1
  55. package/dist/preview/{chunk.6WB2TYK7.js → chunk.DU76ASS4.js} +1 -1
  56. package/dist/preview/{chunk.AENP662H.js → chunk.EEUCRZA3.js} +1 -1
  57. package/dist/preview/{chunk.WC5WE34A.js → chunk.EK3JXEZL.js} +1 -1
  58. package/dist/preview/{chunk.2BMZPALF.js → chunk.EL7XXGQY.js} +1 -1
  59. package/dist/preview/{chunk.2KCDLCB2.js → chunk.EP7YT7LT.js} +1 -1
  60. package/dist/preview/{chunk.SS6KL5NT.js → chunk.EQZPEOIW.js} +1 -1
  61. package/dist/preview/{chunk.VW632VNJ.js → chunk.F4CDJBDS.js} +1 -1
  62. package/dist/preview/{chunk.O5FTWXA2.js → chunk.FE3SINPK.js} +1 -1
  63. package/dist/preview/{chunk.JULD4XFB.js → chunk.FIY4RUK5.js} +1 -1
  64. package/dist/preview/{chunk.3VEZ5MOC.js → chunk.FWXW4T4I.js} +1 -1
  65. package/dist/preview/{chunk.FSW535EA.js → chunk.G43YUGNW.js} +1 -1
  66. package/dist/preview/{chunk.QYPU444Y.js → chunk.GF5CZPZ7.js} +1 -1
  67. package/dist/preview/{chunk.4TT3ZHSJ.js → chunk.GPBHUIZQ.js} +1 -1
  68. package/dist/preview/{chunk.YL2RBZFE.js → chunk.GTF6EMVE.js} +1 -1
  69. package/dist/preview/chunk.GVFGS2HY.js +1 -0
  70. package/dist/preview/{chunk.EGSOHTZZ.js → chunk.HCX6KPRF.js} +1 -1
  71. package/dist/preview/{chunk.4YAO3A5Q.js → chunk.HGH27XZG.js} +3 -3
  72. package/dist/preview/{chunk.7WPVLEX2.js → chunk.HMJXB6KC.js} +2 -2
  73. package/dist/preview/chunk.HTEQCRVP.js +1 -0
  74. package/dist/preview/{chunk.VTDOWXCP.js → chunk.HU3KEWFO.js} +1 -1
  75. package/dist/preview/{chunk.DZ6UDZOB.js → chunk.I4H2GS4O.js} +2 -2
  76. package/dist/preview/{chunk.UD7VLXPM.js → chunk.I7KN732Z.js} +1 -1
  77. package/dist/preview/{chunk.YBQ5GVAX.js → chunk.I7OFRF6N.js} +2 -2
  78. package/dist/preview/{chunk.ZKXIZBCN.js → chunk.IAVIYJTL.js} +1 -1
  79. package/dist/preview/{chunk.CNN32262.js → chunk.IO5VFTXC.js} +1 -1
  80. package/dist/preview/{chunk.PIMAG4WT.js → chunk.IPKESOIU.js} +2 -2
  81. package/dist/preview/{chunk.42KHFGN6.js → chunk.IRNEWNUB.js} +1 -1
  82. package/dist/preview/{chunk.XRE7SHLD.js → chunk.ISZFRLNJ.js} +1 -1
  83. package/dist/preview/{chunk.GRTBEA7O.js → chunk.IY3DV52G.js} +1 -1
  84. package/dist/preview/{chunk.VES4XMZX.js → chunk.IYHY4VEC.js} +1 -1
  85. package/dist/preview/{chunk.HWFJQ42Y.js → chunk.J2N7EKMX.js} +1 -1
  86. package/dist/preview/{chunk.IT5DVKXY.js → chunk.J7O23NKZ.js} +2 -2
  87. package/dist/preview/chunk.JDUA5PH2.js +1 -0
  88. package/dist/preview/{chunk.DCLF4WWZ.js → chunk.JHAMSDAI.js} +1 -1
  89. package/dist/preview/{chunk.IKKKHHRN.js → chunk.JN3WZGJY.js} +1 -1
  90. package/dist/preview/{chunk.H4VNIAHN.js → chunk.JPAE6K4E.js} +1 -1
  91. package/dist/preview/{chunk.DGDW54KE.js → chunk.JQEXH23N.js} +1 -1
  92. package/dist/preview/{chunk.MPWLDQOG.js → chunk.KEGL6NBD.js} +1 -1
  93. package/dist/preview/{chunk.EGVM24ND.js → chunk.KHKCTVHD.js} +1 -1
  94. package/dist/preview/{chunk.VV5JAM5W.js → chunk.KKFKSJUN.js} +1 -1
  95. package/dist/preview/{chunk.Q6H5HESF.js → chunk.KLEKC4ZX.js} +1 -1
  96. package/dist/preview/chunk.KVQYOFDV.js +1 -0
  97. package/dist/preview/{chunk.ZLNUZ6LR.js → chunk.KW7PHJYX.js} +1 -1
  98. package/dist/preview/{chunk.PPCDPYYU.js → chunk.LAVLPYSC.js} +1 -1
  99. package/dist/preview/{chunk.FZELUSK5.js → chunk.LGNGFG5V.js} +1 -1
  100. package/dist/preview/{chunk.SADR3MQI.js → chunk.LKM2R5UF.js} +1 -1
  101. package/dist/preview/{chunk.42C3FIKK.js → chunk.LMZ2WMGH.js} +1 -1
  102. package/dist/preview/{chunk.KAM73WVF.js → chunk.MATUPDZ3.js} +1 -1
  103. package/dist/preview/{chunk.Z2X7BFCB.js → chunk.MD3N26BC.js} +2 -2
  104. package/dist/preview/{chunk.TFJA4QV4.js → chunk.MH3AQO2R.js} +1 -1
  105. package/dist/preview/chunk.MHHNO3O2.js +1 -0
  106. package/dist/preview/{chunk.DMZRFXH7.js → chunk.MKN7ADJB.js} +1 -1
  107. package/dist/preview/{chunk.ND3DEDWB.js → chunk.ML5EHDZG.js} +1 -1
  108. package/dist/preview/{chunk.Q4VFLLUT.js → chunk.MUWI54IP.js} +1 -1
  109. package/dist/preview/{chunk.PZQ5P6WK.js → chunk.MV27WMNW.js} +1 -1
  110. package/dist/preview/{chunk.6DMCEBSO.js → chunk.N7A3T5QU.js} +1 -1
  111. package/dist/preview/{chunk.H3IGXHZR.js → chunk.NLZHNPDU.js} +2 -2
  112. package/dist/preview/{chunk.4DXPPM6T.js → chunk.NRECR3NQ.js} +1 -1
  113. package/dist/preview/{chunk.LZ6MSQ5O.js → chunk.NSAGOOJW.js} +1 -1
  114. package/dist/preview/{chunk.LMTG5NPG.js → chunk.O7NYSO6F.js} +1 -1
  115. package/dist/preview/{chunk.2ME4DVBI.js → chunk.OD5QZHRC.js} +1 -1
  116. package/dist/preview/{chunk.QUETLFBJ.js → chunk.P26ATAAI.js} +1 -1
  117. package/dist/preview/{chunk.3JMQKANL.js → chunk.PJL3I2IW.js} +1 -1
  118. package/dist/preview/{chunk.6IR5LBJU.js → chunk.POKGLN4T.js} +1 -1
  119. package/dist/preview/{chunk.IXMIU4D4.js → chunk.PZ3KM3TY.js} +1 -1
  120. package/dist/preview/{chunk.MIOLBZBS.js → chunk.QEBD7SC4.js} +1 -1
  121. package/dist/preview/{chunk.DPHH5ZVL.js → chunk.QK7EUIPL.js} +1 -1
  122. package/dist/preview/{chunk.7TDML5YU.js → chunk.QNC2OKLF.js} +1 -1
  123. package/dist/preview/{chunk.QOQ26NXM.js → chunk.QRNKGPAD.js} +1 -1
  124. package/dist/preview/{chunk.QZP3ARLH.js → chunk.QVCKTDG3.js} +1 -1
  125. package/dist/preview/{chunk.2U6HB4XU.js → chunk.R7POSVUK.js} +1 -1
  126. package/dist/preview/{chunk.UFURYU4R.js → chunk.RNAL35ID.js} +1 -1
  127. package/dist/preview/{chunk.KUCBNMIY.js → chunk.ROYCJXPE.js} +1 -1
  128. package/dist/preview/chunk.RZ73YG5K.js +1 -0
  129. package/dist/preview/{chunk.JLDJZET2.js → chunk.S2NQRD6W.js} +1 -1
  130. package/dist/preview/{chunk.O32F6LGK.js → chunk.SAWASNDO.js} +1 -1
  131. package/dist/preview/{chunk.CFE3MHWZ.js → chunk.SCVKHGO3.js} +1 -1
  132. package/dist/preview/chunk.SM37MNS2.js +1 -0
  133. package/dist/preview/{chunk.DLSS56EU.js → chunk.T2BZBR7S.js} +1 -1
  134. package/dist/preview/{chunk.OQ4ZO3YY.js → chunk.T3PELB6I.js} +1 -1
  135. package/dist/preview/{chunk.TR4YFVZN.js → chunk.TAJBXG5U.js} +1 -1
  136. package/dist/preview/{chunk.3DEWQDP7.js → chunk.TLPCYKLW.js} +1 -1
  137. package/dist/preview/{chunk.7K2V5FUB.js → chunk.TQQDUJLX.js} +1 -1
  138. package/dist/preview/{chunk.CGBOPPNL.js → chunk.TQRC5VAM.js} +1 -1
  139. package/dist/preview/chunk.U563J5IM.js +1 -0
  140. package/dist/preview/{chunk.GRBWXTST.js → chunk.UAEOCWSG.js} +1 -1
  141. package/dist/preview/{chunk.Y7OGJOPA.js → chunk.UHJSZ2XZ.js} +1 -1
  142. package/dist/preview/{chunk.JGRSUTPJ.js → chunk.UPOYRCKI.js} +1 -1
  143. package/dist/preview/{chunk.I63462I3.js → chunk.VBBH5R5T.js} +1 -1
  144. package/dist/preview/chunk.VBYJBW32.js +1 -0
  145. package/dist/preview/{chunk.HH4D3JEI.js → chunk.VEQIH7HR.js} +1 -1
  146. package/dist/preview/chunk.VHLL6VC6.js +1 -0
  147. package/dist/preview/{chunk.VLXLBGMY.js → chunk.VQDL4EEP.js} +1 -1
  148. package/dist/preview/{chunk.UODTUBQ7.js → chunk.VQOYFBEV.js} +1 -1
  149. package/dist/preview/{chunk.H3W5C3XQ.js → chunk.VR553M6J.js} +1 -1
  150. package/dist/preview/{chunk.ENLIIZF2.js → chunk.VXPEXUQF.js} +1 -1
  151. package/dist/preview/{chunk.Z67LBSQO.js → chunk.W3WXI5B3.js} +1 -1
  152. package/dist/preview/{chunk.5JKUT2OM.js → chunk.W43XWQRC.js} +1 -1
  153. package/dist/preview/{chunk.BHJRT57H.js → chunk.WFJCC6G3.js} +1 -1
  154. package/dist/preview/{chunk.I34BWUB4.js → chunk.WJHLE73Y.js} +1 -1
  155. package/dist/preview/{chunk.MK5RPEB2.js → chunk.WQ7K5O2I.js} +1 -1
  156. package/dist/preview/{chunk.EP5JS7ZH.js → chunk.WV6SP6IJ.js} +1 -1
  157. package/dist/preview/{chunk.XXCHO2A5.js → chunk.YJ4PFOPC.js} +1 -1
  158. package/dist/preview/{chunk.JCETQQ7J.js → chunk.YZKHTBTC.js} +1 -1
  159. package/dist/preview/{chunk.CE3NKAF7.js → chunk.ZE5RSKXF.js} +1 -1
  160. package/dist/preview/{chunk.WV45KLXC.js → chunk.ZQYHNFRZ.js} +1 -1
  161. package/dist/preview/{chunk.TOUSIUJF.js → chunk.ZT3ZG52B.js} +1 -1
  162. package/dist/preview/{chunk.O2VXTYUJ.js → chunk.ZU3RPI34.js} +1 -1
  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.3WPCS6KP.js +0 -1
  167. package/dist/preview/chunk.5L4ADKTW.js +0 -1
  168. package/dist/preview/chunk.6ZENHSTQ.js +0 -1
  169. package/dist/preview/chunk.7OL6H4LF.js +0 -1
  170. package/dist/preview/chunk.ARS4HJD2.js +0 -1
  171. package/dist/preview/chunk.C2QKA6XY.js +0 -1
  172. package/dist/preview/chunk.FHQ25SWY.js +0 -1
  173. package/dist/preview/chunk.MBTEOF4R.js +0 -1
  174. package/dist/preview/chunk.N64RVSH3.js +0 -1
  175. package/dist/preview/chunk.PI4RFOBU.js +0 -1
  176. package/dist/preview/chunk.Q42R2KW4.js +0 -1
  177. package/dist/preview/chunk.R66ZVMWB.js +0 -1
  178. package/dist/preview/chunk.RYA7A4NA.js +0 -1
  179. package/dist/preview/chunk.SUG6LIOX.js +0 -1
  180. package/dist/preview/chunk.U7PAFLUM.js +0 -1
  181. package/dist/preview/chunk.WN7SAAH6.js +0 -1
  182. package/dist/preview/chunk.ZMADWPJO.js +0 -1
  183. package/dist/preview/chunk.ZO6VMEPP.js +0 -1
  184. package/dist/preview/chunk.ZUG7U7AT.js +0 -1
@@ -1 +1 @@
1
- import{a as y,b as h}from"./chunk.SS6KL5NT.js";import"./chunk.WV45KLXC.js";import"./chunk.2KCDLCB2.js";import"./chunk.UD7VLXPM.js";import"./chunk.3DEWQDP7.js";import{Bd as b}from"./chunk.6AANHELP.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";var k=(d,i)=>({id:i.id,said:h(d,i),when:i.when,...i.alsoMine?{alsoMine:!0}:{}});async function A(d,i,t){let a=b(t.principal);if(a.id===void 0)return{ok:!1,error:"This seat acts for nobody the app knows by id, so there is nobody to tell. Nothing was kept."};let r=t.store.seenBy(a),p=async()=>(await t.subscriptions.list(a.id)).filter(n=>n.app===t.app);if(d==="list_subscriptions")return{ok:!0,data:{subscriptions:(await p()).map(n=>k(r,n))}};if(d==="unsubscribe"){let n=String(i.id??"");return(await p()).some(g=>g.id===n)?(await t.subscriptions.remove(n),{ok:!0,data:{removed:n}}):{ok:!1,error:`No subscription "${n}" of yours. list_subscriptions says which there are.`}}let o=String(i.on??""),c=n=>typeof i[n]=="string"&&i[n].trim()!==""?i[n].trim():void 0,e=c("record");if(e!==void 0&&!r.graph.getNode(e)){let n=t.store.resolveRef({name:"record",kinds:["*"]},e,a);if(!n.ok)return{ok:!1,error:`${n.message} Nothing was kept.`};e=n.id}let s=c("kind")??(e!==void 0&&o!=="act"?r.graph.getNode(e)?.kind:void 0),f=c("act"),m=c("condition"),u=o==="act"?{on:o,...f!==void 0?{act:f}:{},...e!==void 0?{record:e}:{}}:o==="created"&&s!==void 0?{on:o,kind:s}:o==="changed"?{on:o,...s!==void 0&&e===void 0?{kind:s}:{},...e!==void 0?{record:e}:{}}:o==="reaches"&&s!==void 0?{on:o,kind:s,condition:m??"",...e!==void 0?{record:e}:{}}:void 0;if(!u)return{ok:!1,error:'Say what to be told of: on is "act", "created", "changed" or "reaches", with a kind (or a record) for all but act. Nothing was kept.'};let l=y({schema:r.schema,allMutations:()=>t.store.allMutations(),graph:r.graph},u);if(l)return{ok:!1,error:`${l} Nothing was kept.`};let S=await t.subscriptions.add({who:a,app:t.app,when:u,...i.alsoMine===!0?{alsoMine:!0}:{}});return{ok:!0,data:{subscription:k(r,S)}}}export{A as runSubscriptionTool};
1
+ import{a as y,b as h}from"./chunk.EQZPEOIW.js";import"./chunk.ZQYHNFRZ.js";import"./chunk.EP7YT7LT.js";import"./chunk.I7KN732Z.js";import"./chunk.TLPCYKLW.js";import{Bd as b}from"./chunk.DHPXRDT5.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";var k=(d,i)=>({id:i.id,said:h(d,i),when:i.when,...i.alsoMine?{alsoMine:!0}:{}});async function A(d,i,t){let a=b(t.principal);if(a.id===void 0)return{ok:!1,error:"This seat acts for nobody the app knows by id, so there is nobody to tell. Nothing was kept."};let r=t.store.seenBy(a),p=async()=>(await t.subscriptions.list(a.id)).filter(n=>n.app===t.app);if(d==="list_subscriptions")return{ok:!0,data:{subscriptions:(await p()).map(n=>k(r,n))}};if(d==="unsubscribe"){let n=String(i.id??"");return(await p()).some(g=>g.id===n)?(await t.subscriptions.remove(n),{ok:!0,data:{removed:n}}):{ok:!1,error:`No subscription "${n}" of yours. list_subscriptions says which there are.`}}let o=String(i.on??""),c=n=>typeof i[n]=="string"&&i[n].trim()!==""?i[n].trim():void 0,e=c("record");if(e!==void 0&&!r.graph.getNode(e)){let n=t.store.resolveRef({name:"record",kinds:["*"]},e,a);if(!n.ok)return{ok:!1,error:`${n.message} Nothing was kept.`};e=n.id}let s=c("kind")??(e!==void 0&&o!=="act"?r.graph.getNode(e)?.kind:void 0),f=c("act"),m=c("condition"),u=o==="act"?{on:o,...f!==void 0?{act:f}:{},...e!==void 0?{record:e}:{}}:o==="created"&&s!==void 0?{on:o,kind:s}:o==="changed"?{on:o,...s!==void 0&&e===void 0?{kind:s}:{},...e!==void 0?{record:e}:{}}:o==="reaches"&&s!==void 0?{on:o,kind:s,condition:m??"",...e!==void 0?{record:e}:{}}:void 0;if(!u)return{ok:!1,error:'Say what to be told of: on is "act", "created", "changed" or "reaches", with a kind (or a record) for all but act. Nothing was kept.'};let l=y({schema:r.schema,allMutations:()=>t.store.allMutations(),graph:r.graph},u);if(l)return{ok:!1,error:`${l} Nothing was kept.`};let S=await t.subscriptions.add({who:a,app:t.app,when:u,...i.alsoMine===!0?{alsoMine:!0}:{}});return{ok:!0,data:{subscription:k(r,S)}}}export{A as runSubscriptionTool};
@@ -1 +1 @@
1
- import{a as D,c as L}from"./chunk.LMTG5NPG.js";import{a as R,g as T,h as W,i as I,j as K}from"./chunk.M5FP4Y4Q.js";import{Zd as N,ne as j}from"./chunk.6AANHELP.js";var J=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),G=e=>e?._zod?.def;function S(e){let t=G(e);for(;t&&(t.type==="optional"||t.type==="default"||t.type==="nullable"||t.type==="prefault");)t=G(t.innerType);return t}function q(e){if(e?.type==="boolean")return["true","false"];if(e?.type==="array"&&(e=S(e.element)),e?.type==="enum")return(e.entries?Object.values(e.entries):e.values??[]).filter(t=>typeof t=="string")}var A=e=>e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[-_]/g," ").replace(/^./,t=>t.toUpperCase());function _(e,t,s){let d=e.tryDefinition(t);if(!d)return[];let c=new Set(d.display?.hide??[]),a=[];for(let[l,o]of Object.entries(d.fields.shape??{})){if(l==="id"||l==="kind"||l==="label"||c.has(l))continue;let i=S(o);if(i?.type==="array"||i?.type==="object"||i?.type==="record")continue;let f=q(i);a.push({key:l,label:A(l),...f?{options:f}:{}})}let g=new Map;for(let[l,o]of Object.entries(d.edges??{}))g.set(l,o.to==="*"?[]:[...o.to]);for(let l of e.definitions)if(l.kind!==t)for(let[o,i]of Object.entries(l.edges??{}))!g.has(o)&&(i.to==="*"||i.to.includes(t))&&g.set(o,[l.kind]);let u=[];for(let[l,o]of g){a.push({key:l,label:A(l)});let i=s&&o.length===1&&o[0]!==t?e.tryDefinition(o[0]):void 0;for(let[f,p]of Object.entries(i?.fields.shape??{})){let y=S(p);y?.type==="enum"&&!i?.display?.hide?.includes(f)&&u.push({key:`${l}.${f}`,label:`${A(l)} \xB7 ${A(f)}`,options:q(y)})}}return a.push(...u),a.push({key:"is",label:"Is",options:d.lifecycle?["current","past","any","flagged","clear"]:["flagged","clear"]}),a}var C=e=>e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`;function F(e,t,s,d={}){if(s==null)return{ok:!0};if(!J(s))return{ok:!1,says:'A filter is an object of a field and the value it keeps, like { where: { stage: "building" } }.'};let c=Object.entries(s);if(c.length===0)return{ok:!0};let a=[];for(let o of t)for(let i of _(e,o,d.through===!0))a.some(f=>f.key===i.key)||a.push(i);let g=t[0]?e.tryDefinition(t[0]):void 0,u=g?g.plural??`${A(g.kind)}s`:"These",l=[];for(let[o,i]of c){let f=a.find(y=>y.key===o);if(!f)return{ok:!1,says:`${u.replace(/^./,y=>y.toUpperCase())} have no field "${o}" to filter by${a.length>0?`; they filter by ${C(a.map(y=>y.key))}`:""}.`};if(typeof i!="string"&&typeof i!="number"&&typeof i!="boolean")return{ok:!1,says:`The filter on "${o}" is ${Array.isArray(i)?"a list":i===null?"null":`a ${typeof i}`}; it keeps one value: a word, a number, or true or false.`};let p=String(i);if(p.trim().length===0)return{ok:!1,says:`The filter on "${o}" keeps nothing; give it a value, or leave "${o}" out.`};if(p.includes(","))return{ok:!1,says:`The filter on "${o}" holds a comma, which an address reads as a second filter; keep one value.`};if(f.options&&f.options.length>0&&!f.options.includes(p))return{ok:!1,says:`${f.label} has no choice "${p}"; its choices are ${C(f.options.map(y=>`"${y}"`))}.`};l.push(`${o}:${p}`)}return{ok:!0,filter:l.join(",")}}var U=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");function V(e,t){let s=e.find(a=>a.as===t);if(s)return s;let d=t.trim().toLowerCase(),c=U(t);return e.find(a=>a.title!==void 0&&a.title.trim().toLowerCase()===d)??(c?e.find(a=>a.as===c||a.title!==void 0&&U(a.title)===c):void 0)}function ee(e){let t=[];for(let s of e){if(typeof s!="object"||s===null)continue;let{as:d,slug:c,title:a,kind:g}=s,u=typeof d=="string"&&d.length>0?d:typeof c=="string"&&c.length>0?c:void 0;!u||t.some(l=>l.as===u)||t.push({as:u,title:typeof a=="string"?a:u,kind:typeof g=="string"?g:""})}return t}var M=e=>` Its places: ${e.map(t=>typeof t=="string"?`"${t}"`:t.title&&t.title!==t.as?`"${t.as}" (${t.title})`:`"${t.as}"`).join(", ")||"none"}.`,ne=" This run was not handed the views the host keeps, so a titled view's place is not among these: if it names one, the link goes there.",m=e=>`"${e.length>80?`${e.slice(0,79)}\u2026`:e}"`,O=(e,t)=>`${"place"in e?`The place ${m(e.place)}`:`${m(e.record)} is no record this viewer may see and`} is no place of this app: it goes nowhere.${M(t)}`;function E(e){let t={};for(let s of e.split(",")){let d=s.indexOf(":");d>0&&(t[s.slice(0,d).trim()]=s.slice(d+1).trim())}return t}function le(e,t=new Set){return e.kinds.filter(s=>!t.has(s)).map(s=>({slug:N(e,s).slice(1),kind:s}))}function de(e,t,s={}){let d=[],c;for(let g of t){if(typeof g!="object"||g===null)continue;let{as:u,slug:l,title:o,kind:i,over:f,hidden:p,name:y}=g,h=typeof u=="string"&&u.length>0?u:typeof l=="string"&&l.length>0?l:void 0;if(h){if(typeof i!="string"||i.length===0){h===j&&typeof o=="string"&&o.length>0&&(c=o);continue}d.push({kind:i,title:typeof o=="string"&&o.length>0?o:h,as:h,...Array.isArray(f)&&f.every(n=>typeof n=="string")?{over:f}:{},...p===!0?{hidden:!0}:{},...typeof y=="string"?{name:y}:{}})}}let a=s.pages??(c!==void 0?{scene:c}:void 0);return L(e,d,{...a?{pages:a}:{},...s.kept?{kept:s.kept}:{}})}var H=(e,t)=>e.find(s=>s.is==="list"&&(s.as===t||s.kind===t));function Z(e,t){let s=t.places.filter((r,k,w)=>r.is!=="list"&&w.findIndex(b=>b.as===r.as)===k),d=[...new Set(t.places.map(r=>r.as))],c=[...new Set([...t.places.filter(r=>r.is==="list").map(r=>r.as),...t.lists.map(r=>r.slug).filter(r=>!d.includes(r))])],a;if(e.section!==void 0&&e.section!==null){if(typeof e.section!="string"||D(e.section).length===0||e.section.length>120)return{ok:!1,says:`The section ${typeof e.section=="string"?m(e.section):"asked for"} names nothing on a page: a section is a heading's words or an element's id, like "shipping-soon". It goes nowhere.`};a=e.section}let g=a!==void 0?{section:a}:{};if("record"in e&&t.sees(e.record))return e.where!==void 0&&e.where!==null?{ok:!1,says:`${m(e.record)} is one record, and a filter narrows a list or a place: it goes nowhere. Go to { place, where } for a list narrowed.`}:{ok:!0,arrival:{record:e.record,...g}};let u="place"in e?e.place:e.record,l=V(t.places,u),o=l?.is==="list"?void 0:l,i=o?void 0:l?.is==="list"?l:H(t.places,u),f=o||i?void 0:t.lists.find(r=>r.slug===u||r.kind===u),p=i?i.kind??void 0:f?.kind;if(!o&&p===void 0)return{ok:!1,says:`${O(e,s)}${B(c)}`};let y=o?o.kind?[o.kind]:[]:[p],h;if(e.where!==void 0&&e.where!==null){if(!t.schema||y.length===0)return{ok:!1,says:`The place ${m(u)} cannot be narrowed here: it goes nowhere.`};let r=F(t.schema,y,e.where,{through:p!==void 0});if(!r.ok)return{ok:!1,says:`The filter on ${m(u)} goes nowhere: ${r.says}`};h=r.filter}let n=h?{filter:h}:{};return{ok:!0,arrival:o?{place:o.as,...n,...g}:{list:p,...n,...g}}}var B=e=>e.length===0?"":` Its lists: ${e.slice(0,8).map(t=>`"${t}"`).join(", ")}${e.length>8?` and ${e.length-8} more`:""}.`,z="http://www.w3.org/1999/xhtml",Q="http://www.w3.org/2000/svg",X=e=>{let t=e;return t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||e.type==="click"&&typeof t.button=="number"&&t.button!==0};function fe(e){let t=new WeakSet,s=new WeakSet,d=new WeakMap,c=new WeakMap,a=n=>Z(n,{sees:e.sees,places:e.places(),lists:e.lists?.()??[],...e.schema?{schema:e.schema}:{}}),g=n=>{let r=a(n);return r.ok?e.onNavigate?.(r.arrival):e.onLost?.(r.says),r.ok},u=n=>{let r=n.getAttribute("data-record"),k=n.getAttribute("data-place"),w=n.getAttribute("data-filter"),b=n.getAttribute("data-section"),v={...w?{where:E(w)}:{},...b?{section:b}:{}};if(r)return{record:r,...v};if(k)return{place:k,...v}},l=n=>{if(!e.hrefOf)return;let r=u(n),k=r?a(r):void 0;return k?.ok?e.hrefOf(k.arrival):void 0},o=n=>n.hasAttribute("tabindex")?!1:(n.setAttribute("tabindex","0"),t.add(n),!0),i=n=>{t.delete(n)&&n.removeAttribute("tabindex")},f=n=>{s.delete(n)&&n.getAttribute("role")==="link"&&n.removeAttribute("role")},p=n=>{let r=d.get(n);r&&(d.delete(n),n.getAttribute("href")===r.href&&n.removeAttribute("href"),r.target!==null&&!n.hasAttribute("target")&&n.setAttribute("target",r.target))},y=n=>{let r=c.get(n);r&&(c.delete(n),i(r))},h={link(n){if(!W(n,[...n.querySelectorAll("input, select, textarea")].some(R))){if(!n.hasAttribute("data-graview-link"))return;n.removeAttribute("data-graview-link"),f(n),i(n),p(n),y(n);return}n.hasAttribute("data-graview-link")||n.setAttribute("data-graview-link","");let k=n.localName==="a"&&(n.namespaceURI===z||n.namespaceURI===Q),w=n.getAttribute("href"),b=d.get(n),v=w!==null&&b?.href!==w,$=k&&!v?l(n):void 0;if($!==void 0){w!==$&&n.setAttribute("href",$),d.set(n,{href:$,target:b?b.target:n.getAttribute("target")}),n.removeAttribute("target"),f(n),i(n);return}if(v?d.delete(n):p(n),I(n,n.querySelectorAll("a"))){f(n),i(n),y(n);return}if(!n.hasAttribute("role")&&(k||T(n))&&(n.setAttribute("role","link"),s.add(n)),n.localName==="tr"&&n.namespaceURI===z){i(n);let x=[...n.children].find(P=>P.localName==="td"||P.localName==="th");c.get(n)!==x&&y(n),x&&!c.has(n)&&o(x)&&c.set(n,x);return}n.localName!=="button"&&o(n)},refresh(n){for(let r of n.querySelectorAll("[data-record], [data-place], [data-graview-link]"))h.link(r)},pressed(n,r,k){if(n.type!=="click"&&!(n.type==="keydown"&&n.key==="Enter"))return!1;let w=K(r,k,b=>b.hasAttribute("data-graview-link"));return w?(n.stopPropagation(),d.has(w)&&X(n)||(n.preventDefault(),h.follow(w)),!0):!1},follow(n){let r=u(n);r&&g(r)},go:g};return h}export{V as a,ee as b,M as c,ne as d,m as e,O as f,E as g,le as h,de as i,Z as j,fe as k};
1
+ import{a as D,c as L}from"./chunk.O7NYSO6F.js";import{a as R,g as T,h as W,i as I,j as K}from"./chunk.M5FP4Y4Q.js";import{Zd as N,ne as j}from"./chunk.DHPXRDT5.js";var J=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),G=e=>e?._zod?.def;function S(e){let t=G(e);for(;t&&(t.type==="optional"||t.type==="default"||t.type==="nullable"||t.type==="prefault");)t=G(t.innerType);return t}function q(e){if(e?.type==="boolean")return["true","false"];if(e?.type==="array"&&(e=S(e.element)),e?.type==="enum")return(e.entries?Object.values(e.entries):e.values??[]).filter(t=>typeof t=="string")}var A=e=>e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[-_]/g," ").replace(/^./,t=>t.toUpperCase());function _(e,t,s){let d=e.tryDefinition(t);if(!d)return[];let c=new Set(d.display?.hide??[]),a=[];for(let[l,o]of Object.entries(d.fields.shape??{})){if(l==="id"||l==="kind"||l==="label"||c.has(l))continue;let i=S(o);if(i?.type==="array"||i?.type==="object"||i?.type==="record")continue;let f=q(i);a.push({key:l,label:A(l),...f?{options:f}:{}})}let g=new Map;for(let[l,o]of Object.entries(d.edges??{}))g.set(l,o.to==="*"?[]:[...o.to]);for(let l of e.definitions)if(l.kind!==t)for(let[o,i]of Object.entries(l.edges??{}))!g.has(o)&&(i.to==="*"||i.to.includes(t))&&g.set(o,[l.kind]);let u=[];for(let[l,o]of g){a.push({key:l,label:A(l)});let i=s&&o.length===1&&o[0]!==t?e.tryDefinition(o[0]):void 0;for(let[f,p]of Object.entries(i?.fields.shape??{})){let y=S(p);y?.type==="enum"&&!i?.display?.hide?.includes(f)&&u.push({key:`${l}.${f}`,label:`${A(l)} \xB7 ${A(f)}`,options:q(y)})}}return a.push(...u),a.push({key:"is",label:"Is",options:d.lifecycle?["current","past","any","flagged","clear"]:["flagged","clear"]}),a}var C=e=>e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e.at(-1)}`;function F(e,t,s,d={}){if(s==null)return{ok:!0};if(!J(s))return{ok:!1,says:'A filter is an object of a field and the value it keeps, like { where: { stage: "building" } }.'};let c=Object.entries(s);if(c.length===0)return{ok:!0};let a=[];for(let o of t)for(let i of _(e,o,d.through===!0))a.some(f=>f.key===i.key)||a.push(i);let g=t[0]?e.tryDefinition(t[0]):void 0,u=g?g.plural??`${A(g.kind)}s`:"These",l=[];for(let[o,i]of c){let f=a.find(y=>y.key===o);if(!f)return{ok:!1,says:`${u.replace(/^./,y=>y.toUpperCase())} have no field "${o}" to filter by${a.length>0?`; they filter by ${C(a.map(y=>y.key))}`:""}.`};if(typeof i!="string"&&typeof i!="number"&&typeof i!="boolean")return{ok:!1,says:`The filter on "${o}" is ${Array.isArray(i)?"a list":i===null?"null":`a ${typeof i}`}; it keeps one value: a word, a number, or true or false.`};let p=String(i);if(p.trim().length===0)return{ok:!1,says:`The filter on "${o}" keeps nothing; give it a value, or leave "${o}" out.`};if(p.includes(","))return{ok:!1,says:`The filter on "${o}" holds a comma, which an address reads as a second filter; keep one value.`};if(f.options&&f.options.length>0&&!f.options.includes(p))return{ok:!1,says:`${f.label} has no choice "${p}"; its choices are ${C(f.options.map(y=>`"${y}"`))}.`};l.push(`${o}:${p}`)}return{ok:!0,filter:l.join(",")}}var U=e=>e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");function V(e,t){let s=e.find(a=>a.as===t);if(s)return s;let d=t.trim().toLowerCase(),c=U(t);return e.find(a=>a.title!==void 0&&a.title.trim().toLowerCase()===d)??(c?e.find(a=>a.as===c||a.title!==void 0&&U(a.title)===c):void 0)}function ee(e){let t=[];for(let s of e){if(typeof s!="object"||s===null)continue;let{as:d,slug:c,title:a,kind:g}=s,u=typeof d=="string"&&d.length>0?d:typeof c=="string"&&c.length>0?c:void 0;!u||t.some(l=>l.as===u)||t.push({as:u,title:typeof a=="string"?a:u,kind:typeof g=="string"?g:""})}return t}var M=e=>` Its places: ${e.map(t=>typeof t=="string"?`"${t}"`:t.title&&t.title!==t.as?`"${t.as}" (${t.title})`:`"${t.as}"`).join(", ")||"none"}.`,ne=" This run was not handed the views the host keeps, so a titled view's place is not among these: if it names one, the link goes there.",m=e=>`"${e.length>80?`${e.slice(0,79)}\u2026`:e}"`,O=(e,t)=>`${"place"in e?`The place ${m(e.place)}`:`${m(e.record)} is no record this viewer may see and`} is no place of this app: it goes nowhere.${M(t)}`;function E(e){let t={};for(let s of e.split(",")){let d=s.indexOf(":");d>0&&(t[s.slice(0,d).trim()]=s.slice(d+1).trim())}return t}function le(e,t=new Set){return e.kinds.filter(s=>!t.has(s)).map(s=>({slug:N(e,s).slice(1),kind:s}))}function de(e,t,s={}){let d=[],c;for(let g of t){if(typeof g!="object"||g===null)continue;let{as:u,slug:l,title:o,kind:i,over:f,hidden:p,name:y}=g,h=typeof u=="string"&&u.length>0?u:typeof l=="string"&&l.length>0?l:void 0;if(h){if(typeof i!="string"||i.length===0){h===j&&typeof o=="string"&&o.length>0&&(c=o);continue}d.push({kind:i,title:typeof o=="string"&&o.length>0?o:h,as:h,...Array.isArray(f)&&f.every(n=>typeof n=="string")?{over:f}:{},...p===!0?{hidden:!0}:{},...typeof y=="string"?{name:y}:{}})}}let a=s.pages??(c!==void 0?{scene:c}:void 0);return L(e,d,{...a?{pages:a}:{},...s.kept?{kept:s.kept}:{}})}var H=(e,t)=>e.find(s=>s.is==="list"&&(s.as===t||s.kind===t));function Z(e,t){let s=t.places.filter((r,k,w)=>r.is!=="list"&&w.findIndex(b=>b.as===r.as)===k),d=[...new Set(t.places.map(r=>r.as))],c=[...new Set([...t.places.filter(r=>r.is==="list").map(r=>r.as),...t.lists.map(r=>r.slug).filter(r=>!d.includes(r))])],a;if(e.section!==void 0&&e.section!==null){if(typeof e.section!="string"||D(e.section).length===0||e.section.length>120)return{ok:!1,says:`The section ${typeof e.section=="string"?m(e.section):"asked for"} names nothing on a page: a section is a heading's words or an element's id, like "shipping-soon". It goes nowhere.`};a=e.section}let g=a!==void 0?{section:a}:{};if("record"in e&&t.sees(e.record))return e.where!==void 0&&e.where!==null?{ok:!1,says:`${m(e.record)} is one record, and a filter narrows a list or a place: it goes nowhere. Go to { place, where } for a list narrowed.`}:{ok:!0,arrival:{record:e.record,...g}};let u="place"in e?e.place:e.record,l=V(t.places,u),o=l?.is==="list"?void 0:l,i=o?void 0:l?.is==="list"?l:H(t.places,u),f=o||i?void 0:t.lists.find(r=>r.slug===u||r.kind===u),p=i?i.kind??void 0:f?.kind;if(!o&&p===void 0)return{ok:!1,says:`${O(e,s)}${B(c)}`};let y=o?o.kind?[o.kind]:[]:[p],h;if(e.where!==void 0&&e.where!==null){if(!t.schema||y.length===0)return{ok:!1,says:`The place ${m(u)} cannot be narrowed here: it goes nowhere.`};let r=F(t.schema,y,e.where,{through:p!==void 0});if(!r.ok)return{ok:!1,says:`The filter on ${m(u)} goes nowhere: ${r.says}`};h=r.filter}let n=h?{filter:h}:{};return{ok:!0,arrival:o?{place:o.as,...n,...g}:{list:p,...n,...g}}}var B=e=>e.length===0?"":` Its lists: ${e.slice(0,8).map(t=>`"${t}"`).join(", ")}${e.length>8?` and ${e.length-8} more`:""}.`,z="http://www.w3.org/1999/xhtml",Q="http://www.w3.org/2000/svg",X=e=>{let t=e;return t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||e.type==="click"&&typeof t.button=="number"&&t.button!==0};function fe(e){let t=new WeakSet,s=new WeakSet,d=new WeakMap,c=new WeakMap,a=n=>Z(n,{sees:e.sees,places:e.places(),lists:e.lists?.()??[],...e.schema?{schema:e.schema}:{}}),g=n=>{let r=a(n);return r.ok?e.onNavigate?.(r.arrival):e.onLost?.(r.says),r.ok},u=n=>{let r=n.getAttribute("data-record"),k=n.getAttribute("data-place"),w=n.getAttribute("data-filter"),b=n.getAttribute("data-section"),v={...w?{where:E(w)}:{},...b?{section:b}:{}};if(r)return{record:r,...v};if(k)return{place:k,...v}},l=n=>{if(!e.hrefOf)return;let r=u(n),k=r?a(r):void 0;return k?.ok?e.hrefOf(k.arrival):void 0},o=n=>n.hasAttribute("tabindex")?!1:(n.setAttribute("tabindex","0"),t.add(n),!0),i=n=>{t.delete(n)&&n.removeAttribute("tabindex")},f=n=>{s.delete(n)&&n.getAttribute("role")==="link"&&n.removeAttribute("role")},p=n=>{let r=d.get(n);r&&(d.delete(n),n.getAttribute("href")===r.href&&n.removeAttribute("href"),r.target!==null&&!n.hasAttribute("target")&&n.setAttribute("target",r.target))},y=n=>{let r=c.get(n);r&&(c.delete(n),i(r))},h={link(n){if(!W(n,[...n.querySelectorAll("input, select, textarea")].some(R))){if(!n.hasAttribute("data-graview-link"))return;n.removeAttribute("data-graview-link"),f(n),i(n),p(n),y(n);return}n.hasAttribute("data-graview-link")||n.setAttribute("data-graview-link","");let k=n.localName==="a"&&(n.namespaceURI===z||n.namespaceURI===Q),w=n.getAttribute("href"),b=d.get(n),v=w!==null&&b?.href!==w,$=k&&!v?l(n):void 0;if($!==void 0){w!==$&&n.setAttribute("href",$),d.set(n,{href:$,target:b?b.target:n.getAttribute("target")}),n.removeAttribute("target"),f(n),i(n);return}if(v?d.delete(n):p(n),I(n,n.querySelectorAll("a"))){f(n),i(n),y(n);return}if(!n.hasAttribute("role")&&(k||T(n))&&(n.setAttribute("role","link"),s.add(n)),n.localName==="tr"&&n.namespaceURI===z){i(n);let x=[...n.children].find(P=>P.localName==="td"||P.localName==="th");c.get(n)!==x&&y(n),x&&!c.has(n)&&o(x)&&c.set(n,x);return}n.localName!=="button"&&o(n)},refresh(n){for(let r of n.querySelectorAll("[data-record], [data-place], [data-graview-link]"))h.link(r)},pressed(n,r,k){if(n.type!=="click"&&!(n.type==="keydown"&&n.key==="Enter"))return!1;let w=K(r,k,b=>b.hasAttribute("data-graview-link"));return w?(n.stopPropagation(),d.has(w)&&X(n)||(n.preventDefault(),h.follow(w)),!0):!1},follow(n){let r=u(n);r&&g(r)},go:g};return h}export{V as a,ee as b,M as c,ne as d,m as e,O as f,E as g,le as h,de as i,Z as j,fe as k};
@@ -0,0 +1 @@
1
+ import{T as k,V as y,c,h as l,o as p}from"./chunk.T2BZBR7S.js";import"./chunk.HMJXB6KC.js";import"./chunk.Q355UPFG.js";import{b as m}from"./chunk.JQEXH23N.js";import"./chunk.I7OFRF6N.js";import"./chunk.4RPKCW4J.js";import"./chunk.IRNEWNUB.js";import"./chunk.AUNQNTKY.js";import"./chunk.KLEKC4ZX.js";import"./chunk.PJL3I2IW.js";import"./chunk.LMZ2WMGH.js";import"./chunk.OD5QZHRC.js";import"./chunk.YJ4PFOPC.js";import"./chunk.LKM2R5UF.js";import"./chunk.MB7LKKUD.js";import"./chunk.26RYER7Y.js";import"./chunk.CYEPHT7V.js";import"./chunk.5MOXQUZH.js";import"./chunk.MKN7ADJB.js";import"./chunk.I4H2GS4O.js";import"./chunk.FE3SINPK.js";import"./chunk.MUWI54IP.js";import"./chunk.3D37E2G5.js";import"./chunk.WVUJXDXZ.js";import"./chunk.B422DSYN.js";import"./chunk.ZE5RSKXF.js";import"./chunk.DKUEZPGR.js";import"./chunk.EP7YT7LT.js";import"./chunk.I7KN732Z.js";import"./chunk.TLPCYKLW.js";import"./chunk.MIE4TJRW.js";import"./chunk.SCVKHGO3.js";import"./chunk.RD2FSSLV.js";import"./chunk.AZRICZKT.js";import"./chunk.MH3AQO2R.js";import"./chunk.J2N7EKMX.js";import"./chunk.P26ATAAI.js";import"./chunk.FIY4RUK5.js";import"./chunk.IY3DV52G.js";import"./chunk.NLZHNPDU.js";import"./chunk.QNC2OKLF.js";import{G as S,H as s,I as d,W as f,fa as g}from"./chunk.FWXW4T4I.js";import"./chunk.SDO3U72B.js";import"./chunk.DHPXRDT5.js";import"./chunk.FQLNBIQ5.js";import{b as n}from"./chunk.AJZBJBMO.js";var u=n(S(),1);var t=n(f(),1);function D({context:a}){let r=l(),h=g(),[w]=(0,u.useState)(()=>s(null)),o=d(h?.seatTalk??w),P=()=>{(window.history.state?.idx??0)>0?r(-1):r("/")};return(0,t.jsxs)(k,{context:a,"data-testid":"draft-page",children:[(0,t.jsx)(y,{context:a,...o.draft?{"data-testid":"draft-title"}:{},children:o.draft?o.draft.title:"Nothing drawn"}),o.draft?(0,t.jsx)(m,{page:!0,go:e=>r(e.address),onPick:e=>{let i=a.store.graph.getNode(e);i&&r(c(a.store.schema,i.kind,e))},onDiscard:P}):(0,t.jsxs)("p",{style:{margin:0,color:"var(--graview-ink-muted)"},children:["Ask for a way of seeing \u2014 \u201Ca board of tasks by status\u201D \u2014 and it is drawn here."," ",(0,t.jsx)(p,{to:"/",style:{color:"var(--graview-accent)"},children:"Home \u2192"})]})]})}export{D as DraftPage};
@@ -1,4 +1,4 @@
1
- import{a as Ee,b as Re,c as Le,d as we,e as U,f as ue,g as pe,h as fe}from"./chunk.Y7OGJOPA.js";import{c as j,e as ce}from"./chunk.GONZB3J3.js";import{a as ge}from"./chunk.HXTKBISQ.js";import{G as H,W as z,ea as le,ga as de}from"./chunk.3VEZ5MOC.js";import"./chunk.SDO3U72B.js";import{Z as q,la as ae,oa as se,rd as _}from"./chunk.6AANHELP.js";import"./chunk.FQLNBIQ5.js";import{b as C}from"./chunk.AJZBJBMO.js";var b=C(H(),1);var I=C(H(),1),Ae=(e,t)=>`graview:last-visit:${t??"anyone"}:${e.join(",")}`;function Oe(e,t,o){let n=new Set;for(let r of e)if(!(r.author.id!==void 0&&r.author.id===o)&&Date.parse(r.at)>t)for(let i of r.writes)n.add(i);return n}function ye(e,t,o){let n=Ae(t,o?.id),[r]=(0,I.useState)(()=>{try{let i=globalThis.localStorage?.getItem(n);return i?Number(i):null}catch{return null}});return(0,I.useEffect)(()=>{let i=()=>{if(document.visibilityState==="hidden")try{globalThis.localStorage?.setItem(n,String(Date.now()))}catch{}};return document.addEventListener("visibilitychange",i),window.addEventListener("pagehide",i),()=>{document.removeEventListener("visibilitychange",i),window.removeEventListener("pagehide",i)}},[n]),(0,I.useMemo)(()=>r===null?new Set:Oe(e,r,o?.id),[e,r,o?.id])}function me(e,t,o){let n=new Set;if(o===void 0)return n;n.add(o);for(let r of[...e.out(o),...e.in(o)])n.add(r.id);for(let r of t)if(r.author.id===o)for(let i of r.primitives)i.op==="add-node"&&n.add(i.node.id);return n}var J=C(H(),1);var v=C(z(),1),Ce=`.graview-workflows{position:absolute;left:0;top:0;pointer-events:none;z-index:${_.plots};opacity:var(--graview-altitude);transition:opacity 640ms cubic-bezier(.33,0,.2,1)}
1
+ import{a as Ee,b as Re,c as Le,d as we,e as U,f as ue,g as pe,h as fe}from"./chunk.UHJSZ2XZ.js";import{c as j,e as ce}from"./chunk.CDSHUWSK.js";import{a as ge}from"./chunk.AZRICZKT.js";import{G as H,W as z,ea as le,ga as de}from"./chunk.FWXW4T4I.js";import"./chunk.SDO3U72B.js";import{Z as q,la as ae,oa as se,rd as _}from"./chunk.DHPXRDT5.js";import"./chunk.FQLNBIQ5.js";import{b as C}from"./chunk.AJZBJBMO.js";var b=C(H(),1);var I=C(H(),1),Ae=(e,t)=>`graview:last-visit:${t??"anyone"}:${e.join(",")}`;function Oe(e,t,o){let n=new Set;for(let r of e)if(!(r.author.id!==void 0&&r.author.id===o)&&Date.parse(r.at)>t)for(let i of r.writes)n.add(i);return n}function ye(e,t,o){let n=Ae(t,o?.id),[r]=(0,I.useState)(()=>{try{let i=globalThis.localStorage?.getItem(n);return i?Number(i):null}catch{return null}});return(0,I.useEffect)(()=>{let i=()=>{if(document.visibilityState==="hidden")try{globalThis.localStorage?.setItem(n,String(Date.now()))}catch{}};return document.addEventListener("visibilitychange",i),window.addEventListener("pagehide",i),()=>{document.removeEventListener("visibilitychange",i),window.removeEventListener("pagehide",i)}},[n]),(0,I.useMemo)(()=>r===null?new Set:Oe(e,r,o?.id),[e,r,o?.id])}function me(e,t,o){let n=new Set;if(o===void 0)return n;n.add(o);for(let r of[...e.out(o),...e.in(o)])n.add(r.id);for(let r of t)if(r.author.id===o)for(let i of r.primitives)i.op==="add-node"&&n.add(i.node.id);return n}var J=C(H(),1);var v=C(z(),1),Ce=`.graview-workflows{position:absolute;left:0;top:0;pointer-events:none;z-index:${_.plots};opacity:var(--graview-altitude);transition:opacity 640ms cubic-bezier(.33,0,.2,1)}
2
2
  .graview-workflow-wire{fill:none;stroke:var(--graview-accent);stroke-width:1.5;stroke-opacity:.7;stroke-linecap:round}
3
3
  .graview-workflow-wire[data-wire=reads]{stroke-dasharray:3 4;stroke-opacity:.55}
4
4
  .graview-workflow-spot{fill:var(--graview-accent);stroke:var(--graview-panel);stroke-width:1.5}
@@ -1 +1 @@
1
- import{pc as k}from"./chunk.6AANHELP.js";function C(e){let o=e+1;return o*o-x(o).length}function x(e){if(e<3)return[];if(e%2===1){let s=(e-1)/2;return[[s,s]]}let o=e/2-1,t=e/2;return[[o,o],[t,o],[o,t],[t,t]]}function M(e){let o=2166136261;for(let t=0;t<e.length;t++)o=Math.imul(o^e.charCodeAt(t),16777619);return(o>>>0)%1e3/1e3}function O(e,o){let t=e.side+1,s=new Set(x(t).map(([r,d])=>`${r},${d}`)),a=e.side/t,l=[];for(let r=0;r<t;r++)for(let d=0;d<t;d++)s.has(`${d},${r}`)||l.push([d,r]);l.sort((r,d)=>r[0]+r[1]-(d[0]+d[1])||r[0]-d[0]);let i=o.slice(0,l.length);return{buildings:i.map((r,d)=>{let[m,y]=l[d];return{id:r,col:e.col+(m+.5)*a,row:e.row+(y+.5)*a,footprint:a*.62,height:.55+M(r)*.7}}),rest:Math.max(0,o.length-i.length)}}var S={done:.12,waiting:.55,active:1.05};function T(e,o,t=[]){let s=e.side,a=s/Math.max(1,o.length),l=Math.max(1,...o.map(n=>n.length)),i=a;for(let n=1;a/n>=s/8-1e-9&&(i=a/n,!(n*Math.floor(s/i+1e-9)>=l));n++);let c=Math.max(1,Math.floor(a/i+1e-9)),r=Math.max(1,Math.floor(s/i+1e-9)),d=s/r,m=[],y=[];return o.forEach((n,u)=>{let g=n.slice(0,c*r);if(g.forEach((j,b)=>{m.push({id:j,lane:u,col:e.col+(b%r+.5)*d,row:e.row+u*a+(Math.floor(b/r)+.5)*i,footprint:Math.min(d,i)*.66,height:t[u]??S.waiting})}),n.length<=g.length)return;let p=y[0],w=n.length-g.length;p?y[0]={...p,count:p.count+w,rows:p.rows+1}:y.push({lane:u,count:w,rows:1,col:e.col-.15,row:e.row+(u+.5)*a})}),m.sort((n,u)=>n.col+n.row-(u.col+u.row)||n.col-u.col),{blocks:m,rests:y}}var R=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),f=e=>typeof e=="string"?[e]:Array.isArray(e)?e.filter(o=>typeof o=="string"):[];function $(e,o,t){let s=Object.entries(o??{});if(s.length===0)return[];let a=new Set(e.schema.kinds),l=new Map(t.map(c=>[c.name,c])),i=c=>{let r=l.get(c);return r?[...k(e.schema,r),...r.creates??[]]:[]};return s.map(([c,r])=>{let d=[],m=[];for(let n of r.when??[])d.push(...f(n.made),...f(n.changed));for(let n of r.steps??[]){let u=R(n.over)?f(n.over.kind):[],g=Array.isArray(n.from)?n.from.flatMap(p=>R(p)?f(p.kind):[]):[];d.push(...u,...f(n.reads),...g,...f(n.archive),...f(n.classify)),m.push(...[...f(n.act),...f(n.acts)].flatMap(i),...f(n.generate),...f(n.archive),...f(n.classify))}let y=n=>[...new Set(n)].filter(u=>a.has(u));return{name:c,title:r.title,status:r.status==="paused"?"paused":"active",reads:y(d),writes:y(m)}})}function v(e,o){let t=new Map,s=[];for(let a of e){let l=[...a.writes,...a.reads].find(r=>o.has(r));if(l===void 0)continue;let i=o.get(l),c=t.get(l)??0;t.set(l,c+1),s.push({name:a.name,beside:l,col:i.col+i.side+1,row:i.row+.5+c})}return s}var h=e=>typeof e=="number"?Number.isFinite(e)&&e>0?Math.floor(e):0:Array.isArray(e)?e.length:0;function A(e,o=Date.now()){let t=Math.floor((new Date(o).getTime()-new Date(e).getTime())/6e4);if(!Number.isFinite(t)||t<1)return"just now";if(t<60)return t===1?"a minute ago":`${t} minutes ago`;let s=Math.floor(t/60);if(s<24)return s===1?"an hour ago":`${s} hours ago`;let a=Math.floor(s/24);return a===1?"yesterday":`${a} days ago`}function D(e,o=Date.now()){if(!e)return"Has not run yet";let t=`Last ran ${A(e.finished,o)}`;if(e.outcome==="failed")return`${t} and failed`;if(e.outcome==="held")return`${t}: held back`;let a=[[h(e.made),e.dry?"would make":"made"],[h(e.changed),e.dry?"would change":"changed"],[h(e.archived),e.dry?"would set aside":"set aside"],[h(e.suggested),e.dry?"would suggest":"suggested"]].filter(([i])=>i>0).map(([i,c])=>`${c} ${i}`),l=a.length>0?a.join(", "):"nothing new";return`${t}${e.dry?", as a dry run":""}: ${l}${e.outcome==="partial"?" (part of it did not run)":""}`}export{C as a,M as b,O as c,S as d,T as e,$ as f,v as g,D as h};
1
+ import{pc as k}from"./chunk.DHPXRDT5.js";function C(e){let o=e+1;return o*o-x(o).length}function x(e){if(e<3)return[];if(e%2===1){let s=(e-1)/2;return[[s,s]]}let o=e/2-1,t=e/2;return[[o,o],[t,o],[o,t],[t,t]]}function M(e){let o=2166136261;for(let t=0;t<e.length;t++)o=Math.imul(o^e.charCodeAt(t),16777619);return(o>>>0)%1e3/1e3}function O(e,o){let t=e.side+1,s=new Set(x(t).map(([r,d])=>`${r},${d}`)),a=e.side/t,l=[];for(let r=0;r<t;r++)for(let d=0;d<t;d++)s.has(`${d},${r}`)||l.push([d,r]);l.sort((r,d)=>r[0]+r[1]-(d[0]+d[1])||r[0]-d[0]);let i=o.slice(0,l.length);return{buildings:i.map((r,d)=>{let[m,y]=l[d];return{id:r,col:e.col+(m+.5)*a,row:e.row+(y+.5)*a,footprint:a*.62,height:.55+M(r)*.7}}),rest:Math.max(0,o.length-i.length)}}var S={done:.12,waiting:.55,active:1.05};function T(e,o,t=[]){let s=e.side,a=s/Math.max(1,o.length),l=Math.max(1,...o.map(n=>n.length)),i=a;for(let n=1;a/n>=s/8-1e-9&&(i=a/n,!(n*Math.floor(s/i+1e-9)>=l));n++);let c=Math.max(1,Math.floor(a/i+1e-9)),r=Math.max(1,Math.floor(s/i+1e-9)),d=s/r,m=[],y=[];return o.forEach((n,u)=>{let g=n.slice(0,c*r);if(g.forEach((j,b)=>{m.push({id:j,lane:u,col:e.col+(b%r+.5)*d,row:e.row+u*a+(Math.floor(b/r)+.5)*i,footprint:Math.min(d,i)*.66,height:t[u]??S.waiting})}),n.length<=g.length)return;let p=y[0],w=n.length-g.length;p?y[0]={...p,count:p.count+w,rows:p.rows+1}:y.push({lane:u,count:w,rows:1,col:e.col-.15,row:e.row+(u+.5)*a})}),m.sort((n,u)=>n.col+n.row-(u.col+u.row)||n.col-u.col),{blocks:m,rests:y}}var R=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),f=e=>typeof e=="string"?[e]:Array.isArray(e)?e.filter(o=>typeof o=="string"):[];function $(e,o,t){let s=Object.entries(o??{});if(s.length===0)return[];let a=new Set(e.schema.kinds),l=new Map(t.map(c=>[c.name,c])),i=c=>{let r=l.get(c);return r?[...k(e.schema,r),...r.creates??[]]:[]};return s.map(([c,r])=>{let d=[],m=[];for(let n of r.when??[])d.push(...f(n.made),...f(n.changed));for(let n of r.steps??[]){let u=R(n.over)?f(n.over.kind):[],g=Array.isArray(n.from)?n.from.flatMap(p=>R(p)?f(p.kind):[]):[];d.push(...u,...f(n.reads),...g,...f(n.archive),...f(n.classify)),m.push(...[...f(n.act),...f(n.acts)].flatMap(i),...f(n.generate),...f(n.archive),...f(n.classify))}let y=n=>[...new Set(n)].filter(u=>a.has(u));return{name:c,title:r.title,status:r.status==="paused"?"paused":"active",reads:y(d),writes:y(m)}})}function v(e,o){let t=new Map,s=[];for(let a of e){let l=[...a.writes,...a.reads].find(r=>o.has(r));if(l===void 0)continue;let i=o.get(l),c=t.get(l)??0;t.set(l,c+1),s.push({name:a.name,beside:l,col:i.col+i.side+1,row:i.row+.5+c})}return s}var h=e=>typeof e=="number"?Number.isFinite(e)&&e>0?Math.floor(e):0:Array.isArray(e)?e.length:0;function A(e,o=Date.now()){let t=Math.floor((new Date(o).getTime()-new Date(e).getTime())/6e4);if(!Number.isFinite(t)||t<1)return"just now";if(t<60)return t===1?"a minute ago":`${t} minutes ago`;let s=Math.floor(t/60);if(s<24)return s===1?"an hour ago":`${s} hours ago`;let a=Math.floor(s/24);return a===1?"yesterday":`${a} days ago`}function D(e,o=Date.now()){if(!e)return"Has not run yet";let t=`Last ran ${A(e.finished,o)}`;if(e.outcome==="failed")return`${t} and failed`;if(e.outcome==="held")return`${t}: held back`;let a=[[h(e.made),e.dry?"would make":"made"],[h(e.changed),e.dry?"would change":"changed"],[h(e.archived),e.dry?"would set aside":"set aside"],[h(e.suggested),e.dry?"would suggest":"suggested"]].filter(([i])=>i>0).map(([i,c])=>`${c} ${i}`),l=a.length>0?a.join(", "):"nothing new";return`${t}${e.dry?", as a dry run":""}: ${l}${e.outcome==="partial"?" (part of it did not run)":""}`}export{C as a,M as b,O as c,S as d,T as e,$ as f,v as g,D as h};
@@ -1 +1 @@
1
- import{a as f}from"./chunk.EP5JS7ZH.js";import{la as d}from"./chunk.6AANHELP.js";function S(e){let o=e.indexOf("{"),a=e.indexOf("["),t=a!==-1&&(o===-1||a<o)?a:o;if(t===-1)return;let n=e[t],r=n==="["?"]":"}",i=0,u=!1,l=!1;for(let s=t;s<e.length;s++){let c=e[s];if(u){l?l=!1:c==="\\"?l=!0:c==='"'&&(u=!1);continue}if(c==='"')u=!0;else if(c===n)i+=1;else if(c===r&&(i-=1,i===0))try{return JSON.parse(e.slice(t,s+1))}catch{return}}}function w(e,o){let a;try{a=e.mutation(o.mutation)}catch{return o}let t={...o.args},n=!1;for(let r of f(a.input)){if(r.control!=="node")continue;let i=t[r.name];if(typeof i!="string"||i.length===0||e.graph.getNode(i))continue;let u=i.trim().toLowerCase(),l=[...e.graph.allNodes()].filter(s=>(r.kinds.includes("*")||r.kinds.includes(s.kind))&&d(e.schema.tryDefinition(s.kind),s).trim().toLowerCase()===u);l.length===1&&(t[r.name]=l[0].id,n=!0)}return n?{...o,args:t}:o}function x(e,o,a){let t=a===void 0?null:new Set(a),n=[];for(let r of o){if(typeof r.mutation!="string")continue;let i=!0;try{e.mutation(r.mutation)}catch{i=!1}i?t&&!t.has(r.mutation)&&n.push({proposal:r,why:"not-allowed"}):n.push({proposal:r,why:"unknown"})}return n}function v(e,o,a){let t=a===void 0?null:new Set(a);return o.filter(n=>{if(typeof n.mutation!="string"||t&&!t.has(n.mutation))return!1;try{e.mutation(n.mutation)}catch{return!1}return n.args!==null&&typeof n.args=="object"})}export{S as a,w as b,x as c,v as d};
1
+ import{a as f}from"./chunk.WV6SP6IJ.js";import{la as d}from"./chunk.DHPXRDT5.js";function S(e){let o=e.indexOf("{"),a=e.indexOf("["),t=a!==-1&&(o===-1||a<o)?a:o;if(t===-1)return;let n=e[t],r=n==="["?"]":"}",i=0,u=!1,l=!1;for(let s=t;s<e.length;s++){let c=e[s];if(u){l?l=!1:c==="\\"?l=!0:c==='"'&&(u=!1);continue}if(c==='"')u=!0;else if(c===n)i+=1;else if(c===r&&(i-=1,i===0))try{return JSON.parse(e.slice(t,s+1))}catch{return}}}function w(e,o){let a;try{a=e.mutation(o.mutation)}catch{return o}let t={...o.args},n=!1;for(let r of f(a.input)){if(r.control!=="node")continue;let i=t[r.name];if(typeof i!="string"||i.length===0||e.graph.getNode(i))continue;let u=i.trim().toLowerCase(),l=[...e.graph.allNodes()].filter(s=>(r.kinds.includes("*")||r.kinds.includes(s.kind))&&d(e.schema.tryDefinition(s.kind),s).trim().toLowerCase()===u);l.length===1&&(t[r.name]=l[0].id,n=!0)}return n?{...o,args:t}:o}function x(e,o,a){let t=a===void 0?null:new Set(a),n=[];for(let r of o){if(typeof r.mutation!="string")continue;let i=!0;try{e.mutation(r.mutation)}catch{i=!1}i?t&&!t.has(r.mutation)&&n.push({proposal:r,why:"not-allowed"}):n.push({proposal:r,why:"unknown"})}return n}function v(e,o,a){let t=a===void 0?null:new Set(a);return o.filter(n=>{if(typeof n.mutation!="string"||t&&!t.has(n.mutation))return!1;try{e.mutation(n.mutation)}catch{return!1}return n.args!==null&&typeof n.args=="object"})}export{S as a,w as b,x as c,v as d};
@@ -1,2 +1,2 @@
1
- import{d as S,e as w,f as I}from"./chunk.AQ2PI6MR.js";import{d as k,g as h,h as b}from"./chunk.H3W5C3XQ.js";import"./chunk.6WB2TYK7.js";import"./chunk.BJUUSIQY.js";import"./chunk.N5Z34V7U.js";import{a as A}from"./chunk.YL2RBZFE.js";import"./chunk.LOKGUALC.js";import"./chunk.JGRSUTPJ.js";import"./chunk.XOZU4OFA.js";import"./chunk.EP5JS7ZH.js";import"./chunk.CE3NKAF7.js";import"./chunk.TFJA4QV4.js";import"./chunk.HWFJQ42Y.js";import"./chunk.QUETLFBJ.js";import"./chunk.JULD4XFB.js";import"./chunk.GRTBEA7O.js";import"./chunk.H3IGXHZR.js";import"./chunk.7TDML5YU.js";import{G as M,W as f}from"./chunk.3VEZ5MOC.js";import"./chunk.SDO3U72B.js";import"./chunk.6AANHELP.js";import"./chunk.FQLNBIQ5.js";import{b as d}from"./chunk.AJZBJBMO.js";var n=d(M(),1);var r=d(f(),1),C="several";function T({chosen:c,acts:p,onAct:N}){let t=A(),u=(0,n.useMemo)(()=>[...c].sort(),[c]),i=u.join(`
1
+ import{d as S,e as w,f as I}from"./chunk.3VNOTHA5.js";import{d as k,g as h,h as b}from"./chunk.VR553M6J.js";import"./chunk.DU76ASS4.js";import"./chunk.BJUUSIQY.js";import"./chunk.7L3I776Z.js";import{a as A}from"./chunk.GTF6EMVE.js";import"./chunk.CLIC2QBA.js";import"./chunk.UPOYRCKI.js";import"./chunk.XOZU4OFA.js";import"./chunk.WV6SP6IJ.js";import"./chunk.ZE5RSKXF.js";import"./chunk.MH3AQO2R.js";import"./chunk.J2N7EKMX.js";import"./chunk.P26ATAAI.js";import"./chunk.FIY4RUK5.js";import"./chunk.IY3DV52G.js";import"./chunk.NLZHNPDU.js";import"./chunk.QNC2OKLF.js";import{G as M,W as f}from"./chunk.FWXW4T4I.js";import"./chunk.SDO3U72B.js";import"./chunk.DHPXRDT5.js";import"./chunk.FQLNBIQ5.js";import{b as d}from"./chunk.AJZBJBMO.js";var n=d(M(),1);var r=d(f(),1),C="several";function T({chosen:c,acts:p,onAct:N}){let t=A(),u=(0,n.useMemo)(()=>[...c].sort(),[c]),i=u.join(`
2
2
  `),o=(0,n.useMemo)(()=>({on:"selection",ids:u}),[i]),l=(0,n.useMemo)(()=>p.filter(e=>e.open.length===0&&!e.more&&!e.destructive),[p]),g=(0,n.useMemo)(()=>new Map(l.map(e=>[h(e.id),e])),[l]),v=S(t,o,C),[y,x]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(v!==void 0)return;let e=!0;return w(t,o,{by:C,ask:()=>b(t.ai,{store:t.store,target:o,principal:t.principal,interaction:k(),places:t.places,selection:t.selection,...t.place?{place:t.place}:{},shared:l.map(a=>({id:a.id,label:a.label,mutation:a.mutation,args:a.args}))})}).then(a=>{e&&x({key:i,result:a})}),()=>{e=!1}},[i]);let s=v??(y?.key===i?y.result:void 0);if(s===void 0)return(0,r.jsx)("span",{role:"status",className:"graview-several-quiet","data-testid":"several-ai-thinking",style:{textDecoration:"none"},children:"AI: thinking\u2026"});let m=s.offers.filter(e=>e.type!=="act"||g.has(e.id));if(m.length===0)return null;let E=e=>{let a=g.get(e.id);if(a){t.desk.record({...s.interaction,outcome:"accepted",accepted:[e.id]}),N(a);return}I(t,s,e)};return(0,r.jsx)("div",{role:"group","aria-label":"Suggested by AI",className:"graview-several-acts","data-testid":"several-ai",children:m.map(e=>(0,r.jsxs)("button",{type:"button",className:"graview-several-act","data-testid":"several-ai-offer","data-ai-offer":e.id,"data-ai-offer-type":e.type,onClick:()=>E(e),children:[e.label,(0,r.jsx)("span",{style:{color:"var(--graview-ink-faint)",fontWeight:400},children:" \xB7 suggested"})]},e.id))})}export{T as SeveralAi};
@@ -0,0 +1 @@
1
+ import{a as b,b as c,c as d,d as e,e as f,f as g}from"./chunk.3TKIZGC7.js";import{a}from"./chunk.TBY5IR7C.js";import"./chunk.BIDL7GQD.js";import"./chunk.Q5WEOX3Q.js";import"./chunk.MATUPDZ3.js";import"./chunk.SAWASNDO.js";import"./chunk.DKUEZPGR.js";import"./chunk.EP7YT7LT.js";import"./chunk.I7KN732Z.js";import"./chunk.TLPCYKLW.js";import"./chunk.DHPXRDT5.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";export{b as PROPOSE_CHANGE,c as documentOfApp,a as mayChangeDeclaration,g as proposeReshape,e as readReshape,f as reshapeCard,d as reshapeQuestions};
@@ -1 +1 @@
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{a as L}from"./chunk.6WB2TYK7.js";import"./chunk.BJUUSIQY.js";import"./chunk.CE3NKAF7.js";import"./chunk.GRTBEA7O.js";import{Qd as I,oa as O,ua as j}from"./chunk.6AANHELP.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";var m=e=>e.charAt(0).toUpperCase()+e.slice(1),N=e=>/^(?:[aeio]|u(?![sn]i|se|ser))/i.test(e),q=e=>e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"one",D=(e,s)=>e===s?`step ${e}`:`steps ${e}\u2013${s}`;function G(e){let s=e.store.schema,t=Object.fromEntries(s.definitions.map(o=>[o.kind,{noun:j(o,o.kind),plural:O(s,o.kind),fields:Object.fromEntries(Object.keys(o.fields.shape??{}).map(c=>[c,{type:"string"}])),edges:o.edges??{}}]));return{name:e.app.name??"app",kinds:t,acts:{}}}function H(e){let s=(e.store.policy?.grants??[]).filter(o=>o.mutations==="*"&&!o.self&&o.roles!=="*").flatMap(o=>o.roles),t=[...new Set(s)];return t.length>0?`${N(t[0])?"an":"a"} ${t.join(" or ")}`:"whoever may change this app"}function K(e){let s=e.place?e.places.find(t=>t.as===e.place):void 0;return s?`in ${s.title}`:"here"}async function U(e,s){let{missing:t}=s;if(!t.need)return{refused:t.said};let o=await (__graviewPreload(import.meta.url,["./chunk.7ZTGB4O7.js","./chunk.TBY5IR7C.js","./chunk.BIDL7GQD.js","./chunk.Q5WEOX3Q.js","./chunk.KAM73WVF.js","./chunk.O32F6LGK.js","./chunk.R3GE37OI.js","./chunk.2KCDLCB2.js","./chunk.UD7VLXPM.js","./chunk.3DEWQDP7.js","./chunk.6AANHELP.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.ZMADWPJO.js")),c=o.documentOfApp(e.app),k=c??G(e),a=L(k,t.need);if("refused"in a)return{refused:`${t.said} ${a.refused}`};let i=a.steps.map(n=>({part:"app",said:n})),b=i.length,C=n=>n.filter(r=>e.store.graph.getNode(r)?.kind===a.on),x=n=>[...e.store.graph.in(n),...e.store.graph.out(n)].filter(r=>r.kind===a.on).map(r=>r.id),f=C(s.members).length>0?C(s.members):[...new Set(s.members.flatMap(x))],p=[],y=f.length,w=n=>k.kinds[n]??void 0,P=n=>(w(n)?.plural??`${w(n)?.noun??n}s`).toLowerCase(),R=n=>(w(n)?.noun??n).toLowerCase(),S=s.where?`in ${s.where}`:K(e);if(y===0)return{refused:`${t.said} There is nothing here to do it to.`};let $=y===1?`the ${R(a.on)} ${S}`:`the ${y} ${P(a.on)} ${S}`,v=m(a.called);if(a.relation&&a.to){let n=t.who;if(!n)return{refused:`${t.said} Say whom to give them to.`};let r=a.made?m(a.edits[0].plural??"people"):m(P(a.to)),h=(a.made?void 0:e.store.graph.allNodes().find(d=>d.kind===a.to&&Object.values(d).some(l=>typeof l=="string"&&l.toLowerCase()===n.toLowerCase())))?.id;if(!h){h=`${a.to}-${q(n)}`;let d=a.makes??e.store.allMutations().find(l=>l.creates?.includes(a.to))?.name;if(!d){let l=e.store.graph.allNodes().filter(g=>g.kind===a.to).slice(0,3).map(g=>String(g.label??g.name??"")).filter(Boolean);return{refused:`${t.said} There is nobody called ${n} among the ${r.toLowerCase()} here${l.length>0?` (${l.join(", ")})`:""}, and no way to add one from here.`}}p.push({name:d,args:{name:n},mintedHint:h}),i.push({part:"record",said:`Add ${n} to ${r}.`})}for(let d of f)p.push({name:a.act,args:{id:d,[a.arg]:h}});let M=/^(\w+?)ed to$/i.exec(a.called)?.[1];i.push({part:"record",said:M?`${m(M.toLowerCase())} ${n} to ${$}.`:`Set \u201C${v}\u201D to ${n} on ${$}.`})}else if(a.field){let n=t.value;if(n===void 0)return{refused:`${t.said} Say what to set it to.`};for(let r of f)p.push({name:a.act,args:{id:r,[a.arg]:n}});i.push({part:"record",said:`Set \u201C${v}\u201D to ${n} on ${$}.`})}let A=i.length;if(!(!!c&&s.host&&s.compose!==void 0&&o.mayChangeDeclaration(e.store,e.principal))){let n=c?!s.host||!s.compose?"whoever hosts this app":H(e):"whoever develops this app";return{question:`${t.said} ${m(n)} would add ${D(1,b)}; then I can do ${D(b+1,A)}.`,parts:i,whoMay:n}}let E=s.compose({document:c,edits:a.edits});if(!E.ok)return{refused:`${t.said} That change could not be made here.`};let u=E.app;try{new I({schema:u.schema,mutations:u.mutations??[],invariants:u.invariants??[],...u.policy?{policy:u.policy}:{},snapshot:e.store.graph.snapshot()}).previewAll(p,{author:e.principal})}catch{return{refused:`${t.said} I could not make that work here.`}}return{question:`${t.said} I can do it in ${A} steps. Should I?`,parts:i,proposal:{said:s.said,add:[],drop:[],card:{said:i.map(n=>n.said).join(" "),adds:[],keeps:[],drops:[],breaking:[]},edits:a.edits,records:p,via:`ai:${e.ai.name??"model"}`}}}export{U as planFor};
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{a as L}from"./chunk.DU76ASS4.js";import"./chunk.BJUUSIQY.js";import"./chunk.ZE5RSKXF.js";import"./chunk.IY3DV52G.js";import{Qd as I,oa as O,ua as j}from"./chunk.DHPXRDT5.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";var m=e=>e.charAt(0).toUpperCase()+e.slice(1),N=e=>/^(?:[aeio]|u(?![sn]i|se|ser))/i.test(e),q=e=>e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"one",D=(e,s)=>e===s?`step ${e}`:`steps ${e}\u2013${s}`;function G(e){let s=e.store.schema,t=Object.fromEntries(s.definitions.map(o=>[o.kind,{noun:j(o,o.kind),plural:O(s,o.kind),fields:Object.fromEntries(Object.keys(o.fields.shape??{}).map(c=>[c,{type:"string"}])),edges:o.edges??{}}]));return{name:e.app.name??"app",kinds:t,acts:{}}}function H(e){let s=(e.store.policy?.grants??[]).filter(o=>o.mutations==="*"&&!o.self&&o.roles!=="*").flatMap(o=>o.roles),t=[...new Set(s)];return t.length>0?`${N(t[0])?"an":"a"} ${t.join(" or ")}`:"whoever may change this app"}function K(e){let s=e.place?e.places.find(t=>t.as===e.place):void 0;return s?`in ${s.title}`:"here"}async function U(e,s){let{missing:t}=s;if(!t.need)return{refused:t.said};let o=await (__graviewPreload(import.meta.url,["./chunk.3TKIZGC7.js","./chunk.TBY5IR7C.js","./chunk.BIDL7GQD.js","./chunk.Q5WEOX3Q.js","./chunk.MATUPDZ3.js","./chunk.SAWASNDO.js","./chunk.DKUEZPGR.js","./chunk.EP7YT7LT.js","./chunk.I7KN732Z.js","./chunk.TLPCYKLW.js","./chunk.DHPXRDT5.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.VBYJBW32.js")),c=o.documentOfApp(e.app),k=c??G(e),a=L(k,t.need);if("refused"in a)return{refused:`${t.said} ${a.refused}`};let i=a.steps.map(n=>({part:"app",said:n})),b=i.length,C=n=>n.filter(r=>e.store.graph.getNode(r)?.kind===a.on),x=n=>[...e.store.graph.in(n),...e.store.graph.out(n)].filter(r=>r.kind===a.on).map(r=>r.id),f=C(s.members).length>0?C(s.members):[...new Set(s.members.flatMap(x))],p=[],y=f.length,w=n=>k.kinds[n]??void 0,P=n=>(w(n)?.plural??`${w(n)?.noun??n}s`).toLowerCase(),R=n=>(w(n)?.noun??n).toLowerCase(),S=s.where?`in ${s.where}`:K(e);if(y===0)return{refused:`${t.said} There is nothing here to do it to.`};let $=y===1?`the ${R(a.on)} ${S}`:`the ${y} ${P(a.on)} ${S}`,v=m(a.called);if(a.relation&&a.to){let n=t.who;if(!n)return{refused:`${t.said} Say whom to give them to.`};let r=a.made?m(a.edits[0].plural??"people"):m(P(a.to)),h=(a.made?void 0:e.store.graph.allNodes().find(d=>d.kind===a.to&&Object.values(d).some(l=>typeof l=="string"&&l.toLowerCase()===n.toLowerCase())))?.id;if(!h){h=`${a.to}-${q(n)}`;let d=a.makes??e.store.allMutations().find(l=>l.creates?.includes(a.to))?.name;if(!d){let l=e.store.graph.allNodes().filter(g=>g.kind===a.to).slice(0,3).map(g=>String(g.label??g.name??"")).filter(Boolean);return{refused:`${t.said} There is nobody called ${n} among the ${r.toLowerCase()} here${l.length>0?` (${l.join(", ")})`:""}, and no way to add one from here.`}}p.push({name:d,args:{name:n},mintedHint:h}),i.push({part:"record",said:`Add ${n} to ${r}.`})}for(let d of f)p.push({name:a.act,args:{id:d,[a.arg]:h}});let M=/^(\w+?)ed to$/i.exec(a.called)?.[1];i.push({part:"record",said:M?`${m(M.toLowerCase())} ${n} to ${$}.`:`Set \u201C${v}\u201D to ${n} on ${$}.`})}else if(a.field){let n=t.value;if(n===void 0)return{refused:`${t.said} Say what to set it to.`};for(let r of f)p.push({name:a.act,args:{id:r,[a.arg]:n}});i.push({part:"record",said:`Set \u201C${v}\u201D to ${n} on ${$}.`})}let A=i.length;if(!(!!c&&s.host&&s.compose!==void 0&&o.mayChangeDeclaration(e.store,e.principal))){let n=c?!s.host||!s.compose?"whoever hosts this app":H(e):"whoever develops this app";return{question:`${t.said} ${m(n)} would add ${D(1,b)}; then I can do ${D(b+1,A)}.`,parts:i,whoMay:n}}let E=s.compose({document:c,edits:a.edits});if(!E.ok)return{refused:`${t.said} That change could not be made here.`};let u=E.app;try{new I({schema:u.schema,mutations:u.mutations??[],invariants:u.invariants??[],...u.policy?{policy:u.policy}:{},snapshot:e.store.graph.snapshot()}).previewAll(p,{author:e.principal})}catch{return{refused:`${t.said} I could not make that work here.`}}return{question:`${t.said} I can do it in ${A} steps. Should I?`,parts:i,proposal:{said:s.said,add:[],drop:[],card:{said:i.map(n=>n.said).join(" "),adds:[],keeps:[],drops:[],breaking:[]},edits:a.edits,records:p,via:`ai:${e.ai.name??"model"}`}}}export{U as planFor};
@@ -0,0 +1 @@
1
+ import{a,b,c,d,e,f,g,h,i}from"./chunk.3VNOTHA5.js";import"./chunk.VR553M6J.js";import"./chunk.DU76ASS4.js";import"./chunk.BJUUSIQY.js";import"./chunk.7L3I776Z.js";import"./chunk.GTF6EMVE.js";import"./chunk.CLIC2QBA.js";import"./chunk.UPOYRCKI.js";import"./chunk.XOZU4OFA.js";import"./chunk.WV6SP6IJ.js";import"./chunk.ZE5RSKXF.js";import"./chunk.MH3AQO2R.js";import"./chunk.J2N7EKMX.js";import"./chunk.P26ATAAI.js";import"./chunk.FIY4RUK5.js";import"./chunk.IY3DV52G.js";import"./chunk.NLZHNPDU.js";import"./chunk.QNC2OKLF.js";import"./chunk.FWXW4T4I.js";import"./chunk.SDO3U72B.js";import"./chunk.DHPXRDT5.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";export{i as GhostTray,h as InlineAiMenu,g as askAgain,c as askInline,a as askOf,b as drawPanel,d as heldSuggestion,e as suggestOnce,f as takeOffer};
@@ -1,4 +1,4 @@
1
- import{a as L,b as _,c as B,d as V,e as E,r as G,t as H,u as S,v as N,w as q,x as W,y as z,z as Q}from"./chunk.RD2FSSLV.js";import"./chunk.6AANHELP.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";var j=["drawElementImageToTexture","copyElementImageToTexture"],T=null,M=(r,e)=>r==="texture"?{texture:e}:{destination:{texture:e}};function ne(){return typeof globalThis>"u"?void 0:globalThis}function v(r,e){let t=[],n=ne(),s=!!(n?.navigator&&"gpu"in n.navigator);s||t.push("navigator.gpu is absent \u2014 WebGPU is unavailable.");let o=r??n?.GPUQueue?.prototype??void 0,i=null;if(o){for(let d of j)if(typeof o[d]=="function"){i=d;break}}i||t.push("No element-capture method on GPUQueue. Run Chromium 147+ with --enable-blink-features=CanvasDrawElement.");let c=e??n?.HTMLCanvasElement?.prototype??void 0,l=typeof c?.updateElementGeometry=="function";l||t.push("canvas.updateElementGeometry is absent \u2014 geometry cannot be reported.");let p=typeof c?.requestPaint=="function";p||t.push("canvas.requestPaint is absent \u2014 there is no capture-safe moment to hook.");let y=!1,h="unknown";if(typeof document<"u"){let d=document.createElement("canvas");y="layoutSubtree"in d||typeof d.captureElementImage=="function","layoutSubtree"in d?h="no":typeof d.captureElementImage=="function"&&(h="yes")}return{available:i!==null,captureMethod:i,geometrySync:l,hitTestFollowsGeometry:l?h:"no",layoutSubtree:y,paintEvents:p,webgpu:s,usable:s&&i!==null,notes:t}}var w=class extends Error{constructor(t){super(`HTML-in-Canvas is unavailable:
1
+ import{a as L,b as _,c as B,d as V,e as E,r as G,t as H,u as S,v as N,w as q,x as W,y as z,z as Q}from"./chunk.RD2FSSLV.js";import"./chunk.DHPXRDT5.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";var j=["drawElementImageToTexture","copyElementImageToTexture"],T=null,M=(r,e)=>r==="texture"?{texture:e}:{destination:{texture:e}};function ne(){return typeof globalThis>"u"?void 0:globalThis}function v(r,e){let t=[],n=ne(),s=!!(n?.navigator&&"gpu"in n.navigator);s||t.push("navigator.gpu is absent \u2014 WebGPU is unavailable.");let o=r??n?.GPUQueue?.prototype??void 0,i=null;if(o){for(let d of j)if(typeof o[d]=="function"){i=d;break}}i||t.push("No element-capture method on GPUQueue. Run Chromium 147+ with --enable-blink-features=CanvasDrawElement.");let c=e??n?.HTMLCanvasElement?.prototype??void 0,l=typeof c?.updateElementGeometry=="function";l||t.push("canvas.updateElementGeometry is absent \u2014 geometry cannot be reported.");let p=typeof c?.requestPaint=="function";p||t.push("canvas.requestPaint is absent \u2014 there is no capture-safe moment to hook.");let y=!1,h="unknown";if(typeof document<"u"){let d=document.createElement("canvas");y="layoutSubtree"in d||typeof d.captureElementImage=="function","layoutSubtree"in d?h="no":typeof d.captureElementImage=="function"&&(h="yes")}return{available:i!==null,captureMethod:i,geometrySync:l,hitTestFollowsGeometry:l?h:"no",layoutSubtree:y,paintEvents:p,webgpu:s,usable:s&&i!==null,notes:t}}var w=class extends Error{constructor(t){super(`HTML-in-Canvas is unavailable:
2
2
  ${t.notes.join(`
3
3
  `)}`);this.capabilities=t;this.name="PlatformUnavailableError"}};function O(r,e,t){let n=r;for(let s of j){let o=n[s];if(typeof o=="function"){if(T){o.call(n,{source:e},M(T,t));return}try{o.call(n,{source:e},M("texture",t)),T="texture"}catch(i){if(!(i instanceof TypeError)||!/texture/i.test(i.message))throw i;o.call(n,{source:e},M("destination",t)),T="destination"}return}}throw new w(v(r))}function F(r,e=!0){e?r.setAttribute("drawable",""):r.removeAttribute("drawable")}function D(r){let e=r.changedElements;return e?new Set(Array.from(e)):null}function re(r,e){let t=r;if(typeof t.captureElementImage!="function")throw new w(v(void 0,r));return t.captureElementImage(e)}function U(r,e,t){let n=r;if(typeof n.updateElementGeometry!="function")throw new w(v(void 0,r));n.updateElementGeometry(e,t)}function ie(r,e){r.clearElementGeometry?.(e)}function m(r){r.requestPaint?.()}function I(r,e=!0){let t=r;e?t.setAttribute("content","drawable"):t.removeAttribute("content"),"layoutSubtree"in t?t.layoutSubtree=e:e?t.setAttribute("layoutsubtree",""):t.removeAttribute("layoutsubtree")}var R=`
4
4
  struct Plane {
@@ -1 +1 @@
1
- import"./chunk.TFJA4QV4.js";import"./chunk.HWFJQ42Y.js";import"./chunk.QUETLFBJ.js";import{a as m}from"./chunk.JULD4XFB.js";import"./chunk.GRTBEA7O.js";import"./chunk.H3IGXHZR.js";import"./chunk.7TDML5YU.js";import{W as p}from"./chunk.3VEZ5MOC.js";import"./chunk.SDO3U72B.js";import{Z as l}from"./chunk.6AANHELP.js";import"./chunk.FQLNBIQ5.js";import{b as f}from"./chunk.AJZBJBMO.js";var a=f(p(),1);function A({states:e,definition:v}){let s=e.values.reduce((t,n)=>t+n.count,0),u=t=>t===null?"with none":m(v,e.field,t).toLowerCase(),c=e.values.filter(t=>t.count>0).map(t=>`${l(t.count)} ${u(t.value)}`).join(", ");return s===0?null:(0,a.jsx)("div",{className:"graview-district-states",role:"img","aria-label":c,title:c,children:e.values.map((t,n)=>{if(t.count===0)return null;let y=e.values.filter(r=>r.count>0).length,w=t.count/s*(168-(y-1)),o=l(t.count),i=`${o} ${u(t.value)}`,d=r=>r.length*6.2+8<=w;return(0,a.jsx)("span",{"data-graview-tier":t.tier,style:{flexGrow:t.count},title:i,children:d(i)?i:d(o)?o:""},n)})})}export{A as StatesBar};
1
+ import"./chunk.MH3AQO2R.js";import"./chunk.J2N7EKMX.js";import"./chunk.P26ATAAI.js";import{a as m}from"./chunk.FIY4RUK5.js";import"./chunk.IY3DV52G.js";import"./chunk.NLZHNPDU.js";import"./chunk.QNC2OKLF.js";import{W as p}from"./chunk.FWXW4T4I.js";import"./chunk.SDO3U72B.js";import{Z as l}from"./chunk.DHPXRDT5.js";import"./chunk.FQLNBIQ5.js";import{b as f}from"./chunk.AJZBJBMO.js";var a=f(p(),1);function A({states:e,definition:v}){let s=e.values.reduce((t,n)=>t+n.count,0),u=t=>t===null?"with none":m(v,e.field,t).toLowerCase(),c=e.values.filter(t=>t.count>0).map(t=>`${l(t.count)} ${u(t.value)}`).join(", ");return s===0?null:(0,a.jsx)("div",{className:"graview-district-states",role:"img","aria-label":c,title:c,children:e.values.map((t,n)=>{if(t.count===0)return null;let y=e.values.filter(r=>r.count>0).length,w=t.count/s*(168-(y-1)),o=l(t.count),i=`${o} ${u(t.value)}`,d=r=>r.length*6.2+8<=w;return(0,a.jsx)("span",{"data-graview-tier":t.tier,style:{flexGrow:t.count},title:i,children:d(i)?i:d(o)?o:""},n)})})}export{A as StatesBar};
@@ -1 +1 @@
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};
1
+ import{d as pn,f as yn}from"./chunk.DU76ASS4.js";import{a as mn}from"./chunk.UPOYRCKI.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.DHPXRDT5.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 +1 @@
1
- import{K as $}from"./chunk.H3IGXHZR.js";import{G as L,Ra as U,a as I,b as R,c as E,d as f,e as k,j as W,m as F,v as j}from"./chunk.3VEZ5MOC.js";import{oe as s,ve as b,we as r}from"./chunk.6AANHELP.js";import{b as H}from"./chunk.AJZBJBMO.js";var u=H(L(),1),_=e=>typeof e=="object"&&e!==null&&"idx"in e;function S(e){let n=r(window.location.pathname,e);return n===null?null:n!==s&&n!=="/"?"pages":n===s||window.location.href.includes("#")?f(window.location.hash).overview?"graview":"scene":_(window.history.state)?"pages":null}function K(e){let n=e.face??(e.stop&&E(e.stop).overview?"graview":"scene");return e.routing!=="address"||typeof window>"u"?n:S(e.basePath)??n}function Q(e){return e.routing!=="address"||typeof window>"u"?!1:r(window.location.pathname,e.basePath)==="/"&&S(e.basePath)===null}function X(e){if(typeof window>"u")return;let n=r(window.location.pathname,e);return n===s||n==="/"&&window.location.href.includes("#")?R(f(window.location.hash)):void 0}function Z({basePath:e,pagesWere:n,shown:t,onFace:i,toggle:l,kinds:N,places:w,opens:B,landed:V}){let{view:O,go:p}=U(),g=(0,u.useRef)({shown:t,view:O,onFace:i,landed:V});g.current={shown:t,view:O,onFace:i,landed:V};let m=(0,u.useRef)(n??"/"),P=()=>{m.current=`${r(window.location.pathname,e)??"/"}${window.location.search}`};return l.current=(o,c,a)=>{let{shown:d,view:h,onFace:A}=g.current;if(o==="pages"&&d!=="pages")window.history.pushState(null,"",b(c??m.current,{basePath:e}));else if(o!=="pages"&&d==="pages"){P();let y=a===void 0?h:M(E(a),w),v=q(y)?z(B):y,T=v!==y&&v.overview?"graview":o,x=Y(T,v,N);p(x),window.history.pushState(null,"",`${b(s,{basePath:e})}${k(x)}`),A?.(T);return}A?.(o)},(0,u.useEffect)(()=>{let o=()=>{if(r(window.location.pathname,e)===null)return;let c=S(e)??"pages",{shown:a,onFace:d,landed:h}=g.current;if(c==="pages"){P(),h?.(m.current),a!=="pages"&&d?.("pages");return}a==="pages"&&(p(M(f(window.location.hash),w)),d?.(c))};return window.addEventListener("popstate",o),()=>window.removeEventListener("popstate",o)},[e,p,w]),null}function M(e,n){let t=e.within?.view,i=t!==void 0&&!e.focusId?n.find(l=>l.as===t):void 0;return i?{...e,focusId:j(i.kind)}:e}function Y(e,n,t){return e==="graview"?F(n,!0):n.overview?W(F(n,!1),$(n,t)):n}function q(e){return e.focusId===null&&e.overview!==!0}function z(e){return e??{...I,overview:!0}}export{K as a,Q as b,X as c,Z as d,M as e,Y as f,q as g,z as h};
1
+ import{K as $}from"./chunk.NLZHNPDU.js";import{G as L,Ra as U,a as I,b as R,c as E,d as f,e as k,j as W,m as F,v as j}from"./chunk.FWXW4T4I.js";import{oe as s,ve as b,we as r}from"./chunk.DHPXRDT5.js";import{b as H}from"./chunk.AJZBJBMO.js";var u=H(L(),1),_=e=>typeof e=="object"&&e!==null&&"idx"in e;function S(e){let n=r(window.location.pathname,e);return n===null?null:n!==s&&n!=="/"?"pages":n===s||window.location.href.includes("#")?f(window.location.hash).overview?"graview":"scene":_(window.history.state)?"pages":null}function K(e){let n=e.face??(e.stop&&E(e.stop).overview?"graview":"scene");return e.routing!=="address"||typeof window>"u"?n:S(e.basePath)??n}function Q(e){return e.routing!=="address"||typeof window>"u"?!1:r(window.location.pathname,e.basePath)==="/"&&S(e.basePath)===null}function X(e){if(typeof window>"u")return;let n=r(window.location.pathname,e);return n===s||n==="/"&&window.location.href.includes("#")?R(f(window.location.hash)):void 0}function Z({basePath:e,pagesWere:n,shown:t,onFace:i,toggle:l,kinds:N,places:w,opens:B,landed:V}){let{view:O,go:p}=U(),g=(0,u.useRef)({shown:t,view:O,onFace:i,landed:V});g.current={shown:t,view:O,onFace:i,landed:V};let m=(0,u.useRef)(n??"/"),P=()=>{m.current=`${r(window.location.pathname,e)??"/"}${window.location.search}`};return l.current=(o,c,a)=>{let{shown:d,view:h,onFace:A}=g.current;if(o==="pages"&&d!=="pages")window.history.pushState(null,"",b(c??m.current,{basePath:e}));else if(o!=="pages"&&d==="pages"){P();let y=a===void 0?h:M(E(a),w),v=q(y)?z(B):y,T=v!==y&&v.overview?"graview":o,x=Y(T,v,N);p(x),window.history.pushState(null,"",`${b(s,{basePath:e})}${k(x)}`),A?.(T);return}A?.(o)},(0,u.useEffect)(()=>{let o=()=>{if(r(window.location.pathname,e)===null)return;let c=S(e)??"pages",{shown:a,onFace:d,landed:h}=g.current;if(c==="pages"){P(),h?.(m.current),a!=="pages"&&d?.("pages");return}a==="pages"&&(p(M(f(window.location.hash),w)),d?.(c))};return window.addEventListener("popstate",o),()=>window.removeEventListener("popstate",o)},[e,p,w]),null}function M(e,n){let t=e.within?.view,i=t!==void 0&&!e.focusId?n.find(l=>l.as===t):void 0;return i?{...e,focusId:j(i.kind)}:e}function Y(e,n,t){return e==="graview"?F(n,!0):n.overview?W(F(n,!1),$(n,t)):n}function q(e){return e.focusId===null&&e.overview!==!0}function z(e){return e??{...I,overview:!0}}export{K as a,Q as b,X as c,Z as d,M as e,Y as f,q as g,z as h};