graview 0.1.69 → 0.1.71
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.
- package/dist/preview/chunk.23DATB5Y.js +1 -0
- package/dist/preview/chunk.2INDKSJI.js +1 -0
- package/dist/preview/chunk.3CLTABGP.js +1 -0
- package/dist/preview/chunk.3RRK6UTN.js +8 -0
- package/dist/preview/chunk.45HUV56Z.js +1 -0
- package/dist/preview/chunk.4HU2ILFY.js +1 -0
- package/dist/preview/{chunk.3VNOTHA5.js → chunk.4LWWXIM4.js} +1 -1
- package/dist/preview/chunk.4O64QV2Y.js +1 -0
- package/dist/preview/{chunk.PJL3I2IW.js → chunk.4QMAYVPU.js} +1 -1
- package/dist/preview/chunk.4UDST6IF.js +1 -0
- package/dist/preview/{chunk.6BNSDPZE.js → chunk.4YZ2A6SJ.js} +3 -3
- package/dist/preview/{chunk.523EFGHU.js → chunk.4ZEHLUXV.js} +1 -1
- package/dist/preview/{chunk.F4CDJBDS.js → chunk.5EQRIZ6I.js} +1 -1
- package/dist/preview/chunk.5OS4SYHE.js +1 -0
- package/dist/preview/{chunk.BO32A3W5.js → chunk.5PQV7GFE.js} +1 -1
- package/dist/preview/{chunk.PZ3KM3TY.js → chunk.5WCSQFS5.js} +1 -1
- package/dist/preview/{chunk.HU3KEWFO.js → chunk.64K5ELSQ.js} +1 -1
- package/dist/preview/{chunk.MKN7ADJB.js → chunk.67S2UWBT.js} +1 -1
- package/dist/preview/chunk.6A3KTD66.js +1 -0
- package/dist/preview/chunk.6BBUTKFC.js +23 -0
- package/dist/preview/chunk.6IMRCKB4.js +1 -0
- package/dist/preview/chunk.6L6RUOSF.js +5 -0
- package/dist/preview/{chunk.MH3AQO2R.js → chunk.6TBQV3NO.js} +1 -1
- package/dist/preview/chunk.6ZRVVRDQ.js +1 -0
- package/dist/preview/{chunk.YZKHTBTC.js → chunk.7FI75ZVE.js} +1 -1
- package/dist/preview/{chunk.IO5VFTXC.js → chunk.7KX36ENH.js} +1 -1
- package/dist/preview/chunk.7LPHWJB4.js +3 -0
- package/dist/preview/chunk.7MDGPTYF.js +1 -0
- package/dist/preview/{chunk.I4H2GS4O.js → chunk.7PWLRRUS.js} +2 -2
- package/dist/preview/{chunk.7T2P42VW.js → chunk.7TACFS7Q.js} +1 -1
- package/dist/preview/{chunk.KLEKC4ZX.js → chunk.7THS3DLZ.js} +1 -1
- package/dist/preview/{chunk.CSVDBDRZ.js → chunk.7XGU6KVF.js} +2 -2
- package/dist/preview/chunk.7ZLCA3WK.js +1 -0
- package/dist/preview/{chunk.RRCPEHM4.js → chunk.AIFT2HNP.js} +1 -1
- package/dist/preview/{chunk.LMZ2WMGH.js → chunk.ARGEGV5T.js} +1 -1
- package/dist/preview/{chunk.4FJ4OPSJ.js → chunk.BSWR5SGX.js} +1 -1
- package/dist/preview/{chunk.RNAL35ID.js → chunk.BWMPC7LK.js} +1 -1
- package/dist/preview/{chunk.KW7PHJYX.js → chunk.CEJIH3CN.js} +1 -1
- package/dist/preview/chunk.CEOQY5KS.js +5 -0
- package/dist/preview/{chunk.G43YUGNW.js → chunk.CGRX6SDE.js} +1 -1
- package/dist/preview/chunk.CPK6CYKN.js +111 -0
- package/dist/preview/{chunk.AZRICZKT.js → chunk.CVN2XFMF.js} +1 -1
- package/dist/preview/chunk.D4F6QX5L.js +1 -0
- package/dist/preview/{chunk.JPAE6K4E.js → chunk.D6ODKMOV.js} +1 -1
- package/dist/preview/{chunk.CCCONK73.js → chunk.DDSAFU3B.js} +1 -1
- package/dist/preview/{chunk.AHYMIVBX.js → chunk.DG3YNOH3.js} +1 -1
- package/dist/preview/chunk.DGYWNM5U.js +1 -0
- package/dist/preview/{chunk.ML5EHDZG.js → chunk.DHO3QZYK.js} +1 -1
- package/dist/preview/{chunk.EL7XXGQY.js → chunk.DJGZOPAS.js} +1 -1
- package/dist/preview/chunk.DOJCYXIJ.js +1 -0
- package/dist/preview/{chunk.CKSRW3LA.js → chunk.DX7RGK5G.js} +1 -1
- package/dist/preview/{chunk.QK7EUIPL.js → chunk.EA2KYBBR.js} +1 -1
- package/dist/preview/chunk.EEGVI266.js +1 -0
- package/dist/preview/{chunk.I7OFRF6N.js → chunk.EHLV3LND.js} +2 -2
- package/dist/preview/{chunk.QEBD7SC4.js → chunk.EJC7ACZT.js} +4 -2
- package/dist/preview/{chunk.QRNKGPAD.js → chunk.EJIQDMLU.js} +1 -1
- package/dist/preview/chunk.EOSN5DWW.js +1 -0
- package/dist/preview/{chunk.4RPKCW4J.js → chunk.EPSYX2SF.js} +1 -1
- package/dist/preview/chunk.EUXAIG73.js +1 -0
- package/dist/preview/chunk.EZQK23AB.js +1 -0
- package/dist/preview/{chunk.KKFKSJUN.js → chunk.F5O3HR7X.js} +1 -1
- package/dist/preview/chunk.F6MY6WJ4.js +1 -0
- package/dist/preview/{chunk.GTF6EMVE.js → chunk.F7KVEWFH.js} +1 -1
- package/dist/preview/{chunk.EEUCRZA3.js → chunk.FIUPDGUZ.js} +1 -1
- package/dist/preview/chunk.FNSVGSZI.js +1 -0
- package/dist/preview/chunk.FOHZPYUV.js +1 -0
- package/dist/preview/chunk.FW6M6GIU.js +32 -0
- package/dist/preview/{chunk.VXPEXUQF.js → chunk.G5AF5IXL.js} +1 -1
- package/dist/preview/chunk.G767NLBH.js +1 -0
- package/dist/preview/chunk.GFBE4VNT.js +1 -0
- package/dist/preview/{chunk.CDSHUWSK.js → chunk.GFOZVQBQ.js} +1 -1
- package/dist/preview/chunk.GKYJQE5A.js +1 -0
- package/dist/preview/chunk.GOVRX2YX.js +4 -0
- package/dist/preview/{chunk.T3PELB6I.js → chunk.H33XWGAY.js} +1 -1
- package/dist/preview/{chunk.2AL26ZPJ.js → chunk.H4BPTMED.js} +1 -1
- package/dist/preview/chunk.HLKDYI6J.js +1 -0
- package/dist/preview/{chunk.VEQIH7HR.js → chunk.HPFEYMGP.js} +1 -1
- package/dist/preview/chunk.HT35PAHI.js +21 -0
- package/dist/preview/{chunk.VR553M6J.js → chunk.HXRHEPPJ.js} +1 -1
- package/dist/preview/chunk.IPKODEOZ.js +1 -0
- package/dist/preview/{chunk.EP7YT7LT.js → chunk.IXYG65TM.js} +1 -1
- package/dist/preview/chunk.IZDB777E.js +1 -0
- package/dist/preview/{chunk.VBBH5R5T.js → chunk.JAPTTM6Y.js} +1 -1
- package/dist/preview/chunk.JCKIJSW7.js +25 -0
- package/dist/preview/{chunk.4R7H3GIL.js → chunk.JLNTE5CH.js} +2 -2
- package/dist/preview/chunk.JNK5WBSU.js +1 -0
- package/dist/preview/chunk.JREA2XDG.js +1 -0
- package/dist/preview/{chunk.WV6SP6IJ.js → chunk.KBJ3UUER.js} +1 -1
- package/dist/preview/{chunk.VBHV4TLG.js → chunk.KHRS2SKB.js} +1 -1
- package/dist/preview/{chunk.ISZFRLNJ.js → chunk.KJPLX72N.js} +1 -1
- package/dist/preview/chunk.KZUHXOZU.js +21 -0
- package/dist/preview/{chunk.6ZFYFT5A.js → chunk.L3MLGFIS.js} +1 -1
- package/dist/preview/{chunk.KEGL6NBD.js → chunk.L6P55HFW.js} +1 -1
- package/dist/preview/{chunk.N7A3T5QU.js → chunk.LDWWUKKX.js} +1 -1
- package/dist/preview/{chunk.CA2SYEYE.js → chunk.LHCGC3K6.js} +1 -1
- package/dist/preview/{chunk.BQORHDAH.js → chunk.LNKY6MT4.js} +1 -1
- package/dist/preview/chunk.LQ5J6YQW.js +1 -0
- package/dist/preview/{chunk.47VEV4BX.js → chunk.MEAUTBVM.js} +1 -1
- package/dist/preview/chunk.MEBKTW7H.js +17 -0
- package/dist/preview/{chunk.WQ7K5O2I.js → chunk.MFMC35ET.js} +1 -1
- package/dist/preview/chunk.MJ4T6YXI.js +1 -0
- package/dist/preview/chunk.MKJV3BM5.js +240 -0
- package/dist/preview/chunk.ML4X7VVK.js +1 -0
- package/dist/preview/chunk.MM7MLBGB.js +1 -0
- package/dist/preview/{chunk.5MOXQUZH.js → chunk.MQNW3O67.js} +1 -1
- package/dist/preview/{chunk.J2N7EKMX.js → chunk.MT252WP4.js} +1 -1
- package/dist/preview/chunk.MWWNKM3I.js +1 -0
- package/dist/preview/chunk.N3MXLORL.js +3 -0
- package/dist/preview/chunk.NH3VXTGX.js +1 -0
- package/dist/preview/{chunk.B422DSYN.js → chunk.NI4OPHTL.js} +1 -1
- package/dist/preview/chunk.NNGG7RCO.js +1 -0
- package/dist/preview/{chunk.LKM2R5UF.js → chunk.NXHEOHRR.js} +1 -1
- package/dist/preview/{chunk.TQQDUJLX.js → chunk.O5RPSUXV.js} +1 -1
- package/dist/preview/{chunk.FE3SINPK.js → chunk.OKHXXIMN.js} +1 -1
- package/dist/preview/chunk.ONAH6MC4.js +1 -0
- package/dist/preview/chunk.OOQG2AEF.js +1 -0
- package/dist/preview/{chunk.ZQYHNFRZ.js → chunk.OPMGQS5J.js} +1 -1
- package/dist/preview/{chunk.UHJSZ2XZ.js → chunk.OUF2QFZL.js} +1 -1
- package/dist/preview/{chunk.CUEIGKFG.js → chunk.OVSKPBPS.js} +1 -1
- package/dist/preview/chunk.OYMN3IFX.js +1 -0
- package/dist/preview/{chunk.QNC2OKLF.js → chunk.P43LPXXJ.js} +1 -1
- package/dist/preview/chunk.PGT4ZQDG.js +4 -0
- package/dist/preview/{chunk.WFJCC6G3.js → chunk.PQTXM4VY.js} +1 -1
- package/dist/preview/{chunk.KHKCTVHD.js → chunk.Q6GEPVQ7.js} +1 -1
- package/dist/preview/chunk.QDDDKEBH.js +1 -0
- package/dist/preview/{chunk.26RYER7Y.js → chunk.QJJWAYHB.js} +1 -1
- package/dist/preview/chunk.QK4QZVQG.js +1 -0
- package/dist/preview/{chunk.CLIC2QBA.js → chunk.QKRQPUCE.js} +1 -1
- package/dist/preview/{chunk.DU76ASS4.js → chunk.QNWGDG2Z.js} +2 -2
- package/dist/preview/{chunk.447RWLS7.js → chunk.QVBP4UZG.js} +2 -2
- package/dist/preview/chunk.RDUGUC7R.js +1 -0
- package/dist/preview/{chunk.EK3JXEZL.js → chunk.RHIP2UYE.js} +1 -1
- package/dist/preview/chunk.RJ7VSWTA.js +87 -0
- package/dist/preview/{chunk.JHAMSDAI.js → chunk.RO3D2RNP.js} +1 -1
- package/dist/preview/{chunk.C6CT6F4C.js → chunk.S2BMI23H.js} +1 -1
- package/dist/preview/{chunk.ZRBGYXAO.js → chunk.SGYZM6ZU.js} +1 -1
- package/dist/preview/{chunk.UPOYRCKI.js → chunk.SPJ34VHA.js} +1 -1
- package/dist/preview/{chunk.UAEOCWSG.js → chunk.T6KOL7TW.js} +1 -1
- package/dist/preview/{chunk.AUNQNTKY.js → chunk.T6UJEXFL.js} +3 -2
- package/dist/preview/chunk.TBEKEHFS.js +1 -0
- package/dist/preview/chunk.TO3ZKCA2.js +1 -0
- package/dist/preview/{chunk.FIY4RUK5.js → chunk.TQ3MNB6K.js} +1 -1
- package/dist/preview/{chunk.GG47EIKO.js → chunk.TRP66PHK.js} +1 -1
- package/dist/preview/{chunk.LGNGFG5V.js → chunk.TSZ2S3VG.js} +1 -1
- package/dist/preview/chunk.TTM5GQ2U.js +1 -0
- package/dist/preview/chunk.TUBY6SV3.js +1 -0
- package/dist/preview/{chunk.ZE5RSKXF.js → chunk.U5KJQFAP.js} +1 -1
- package/dist/preview/chunk.U6V4KZF5.js +1 -0
- package/dist/preview/chunk.UJ7RTNT4.js +1 -0
- package/dist/preview/{chunk.HCX6KPRF.js → chunk.UQZ2P6KD.js} +1 -1
- package/dist/preview/{chunk.CLZYNFFH.js → chunk.UZKBFI52.js} +1 -1
- package/dist/preview/{chunk.66TRDXYR.js → chunk.V5JB5UJS.js} +2 -2
- package/dist/preview/{chunk.3TKIZGC7.js → chunk.VDFQFLTU.js} +1 -1
- package/dist/preview/{chunk.IY3DV52G.js → chunk.VGYG2IBZ.js} +1 -1
- package/dist/preview/chunk.VICBF3MQ.js +2 -0
- package/dist/preview/{chunk.EQZPEOIW.js → chunk.VL3YDD7D.js} +1 -1
- package/dist/preview/{chunk.IYHY4VEC.js → chunk.VPFUOTY7.js} +1 -1
- package/dist/preview/chunk.VUDNQOOX.js +1 -0
- package/dist/preview/{chunk.P26ATAAI.js → chunk.VVIQSFM4.js} +1 -1
- package/dist/preview/{chunk.DO3FQM6R.js → chunk.W332P5T3.js} +6 -6
- package/dist/preview/{chunk.POKGLN4T.js → chunk.W3TJF4EH.js} +1 -1
- package/dist/preview/{chunk.D5JZQZ74.js → chunk.W5O5F4FT.js} +1 -1
- package/dist/preview/chunk.W6L2VAJG.js +2 -0
- package/dist/preview/{chunk.O7NYSO6F.js → chunk.WGH2P2YL.js} +1 -1
- package/dist/preview/{chunk.OD5QZHRC.js → chunk.WS5ORRGS.js} +1 -1
- package/dist/preview/{chunk.VQDL4EEP.js → chunk.WU6D3SPL.js} +1 -1
- package/dist/preview/{chunk.MV27WMNW.js → chunk.X2UYEA7H.js} +1 -1
- package/dist/preview/chunk.X45EITTK.js +18 -0
- package/dist/preview/{chunk.TAJBXG5U.js → chunk.X7U3JMBR.js} +1 -1
- package/dist/preview/chunk.XSM4OTF4.js +1 -0
- package/dist/preview/{chunk.DRAPVGQZ.js → chunk.XTHSPLZZ.js} +1 -1
- package/dist/preview/{chunk.VQOYFBEV.js → chunk.Y5WQD6KV.js} +1 -1
- package/dist/preview/chunk.YXVUJ3NB.js +1 -0
- package/dist/preview/{chunk.NRECR3NQ.js → chunk.Z22C2JJ4.js} +1 -1
- package/dist/preview/{chunk.TQRC5VAM.js → chunk.Z2BCOZDZ.js} +1 -1
- package/dist/preview/{chunk.S2NQRD6W.js → chunk.Z3TK2LJM.js} +1 -1
- package/dist/preview/chunk.ZGLOXN7O.js +1 -0
- package/dist/preview/{chunk.R7POSVUK.js → chunk.ZLQIGZXO.js} +2 -2
- package/dist/preview/{chunk.YJ4PFOPC.js → chunk.ZONRIOIA.js} +1 -1
- package/dist/preview/{chunk.QVCKTDG3.js → chunk.ZY3NAJDM.js} +1 -1
- package/dist/preview/index.html +55 -55
- package/dist/preview/page.js +2 -2
- package/package.json +7 -7
- package/dist/preview/chunk.2WFOKJB4.js +0 -1
- package/dist/preview/chunk.32SHA3EY.js +0 -1
- package/dist/preview/chunk.3D37E2G5.js +0 -1
- package/dist/preview/chunk.3PT3BU6K.js +0 -1
- package/dist/preview/chunk.3XTIYX6M.js +0 -1
- package/dist/preview/chunk.4O7WYLCK.js +0 -1
- package/dist/preview/chunk.5DU6FA5R.js +0 -1
- package/dist/preview/chunk.5TWRTGP6.js +0 -1
- package/dist/preview/chunk.6BR2SUAE.js +0 -1
- package/dist/preview/chunk.6TDVNWFU.js +0 -17
- package/dist/preview/chunk.6XBQDXT6.js +0 -3
- package/dist/preview/chunk.7L3I776Z.js +0 -1
- package/dist/preview/chunk.7OLKVOS6.js +0 -1
- package/dist/preview/chunk.AG7WJYM5.js +0 -3
- package/dist/preview/chunk.AMAOZVEO.js +0 -1
- package/dist/preview/chunk.AMV2ILR6.js +0 -1
- package/dist/preview/chunk.B5EFNTDA.js +0 -1
- package/dist/preview/chunk.BBLIT7S7.js +0 -1
- package/dist/preview/chunk.BSQI3KM2.js +0 -1
- package/dist/preview/chunk.CYEPHT7V.js +0 -1
- package/dist/preview/chunk.D3SWJ7OS.js +0 -1
- package/dist/preview/chunk.DHPXRDT5.js +0 -5
- package/dist/preview/chunk.DKUEZPGR.js +0 -1
- package/dist/preview/chunk.FWXW4T4I.js +0 -25
- package/dist/preview/chunk.GF5CZPZ7.js +0 -1
- package/dist/preview/chunk.GPBHUIZQ.js +0 -2
- package/dist/preview/chunk.GVFGS2HY.js +0 -1
- package/dist/preview/chunk.HGH27XZG.js +0 -23
- package/dist/preview/chunk.HMJXB6KC.js +0 -5
- package/dist/preview/chunk.HTEQCRVP.js +0 -1
- package/dist/preview/chunk.I7KN732Z.js +0 -2
- package/dist/preview/chunk.IAVIYJTL.js +0 -1
- package/dist/preview/chunk.IPKESOIU.js +0 -21
- package/dist/preview/chunk.IRNEWNUB.js +0 -1
- package/dist/preview/chunk.J7O23NKZ.js +0 -22
- package/dist/preview/chunk.JDUA5PH2.js +0 -1
- package/dist/preview/chunk.JN3WZGJY.js +0 -1
- package/dist/preview/chunk.JQEXH23N.js +0 -1
- package/dist/preview/chunk.KVQYOFDV.js +0 -1
- package/dist/preview/chunk.LAVLPYSC.js +0 -1
- package/dist/preview/chunk.MATUPDZ3.js +0 -1
- package/dist/preview/chunk.MD3N26BC.js +0 -23
- package/dist/preview/chunk.MHHNO3O2.js +0 -1
- package/dist/preview/chunk.MUWI54IP.js +0 -1
- package/dist/preview/chunk.NLZHNPDU.js +0 -93
- package/dist/preview/chunk.NSAGOOJW.js +0 -1
- package/dist/preview/chunk.NYLKG25K.js +0 -4
- package/dist/preview/chunk.OWO3OV62.js +0 -1
- package/dist/preview/chunk.ROYCJXPE.js +0 -1
- package/dist/preview/chunk.RZ73YG5K.js +0 -1
- package/dist/preview/chunk.SAWASNDO.js +0 -1
- package/dist/preview/chunk.SCVKHGO3.js +0 -1
- package/dist/preview/chunk.SM37MNS2.js +0 -1
- package/dist/preview/chunk.T2BZBR7S.js +0 -50
- package/dist/preview/chunk.TLPCYKLW.js +0 -3
- package/dist/preview/chunk.U563J5IM.js +0 -1
- package/dist/preview/chunk.U6QXLNHF.js +0 -15
- package/dist/preview/chunk.VBYJBW32.js +0 -1
- package/dist/preview/chunk.VHLL6VC6.js +0 -1
- package/dist/preview/chunk.W3WXI5B3.js +0 -1
- package/dist/preview/chunk.W43XWQRC.js +0 -1
- package/dist/preview/chunk.WJHLE73Y.js +0 -111
- package/dist/preview/chunk.ZT3ZG52B.js +0 -1
- package/dist/preview/chunk.ZU3RPI34.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk.WVUJXDXZ.js";import{b as P}from"./chunk.
|
|
1
|
+
import"./chunk.WVUJXDXZ.js";import{b as P}from"./chunk.NI4OPHTL.js";import"./chunk.U5KJQFAP.js";import"./chunk.FOHZPYUV.js";import"./chunk.IXYG65TM.js";import"./chunk.W6L2VAJG.js";import"./chunk.N3MXLORL.js";import"./chunk.TQ3MNB6K.js";import"./chunk.VGYG2IBZ.js";import{Aa as T,Ba as E,Ca as L,ya as M}from"./chunk.6L6RUOSF.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";function G(r,l,i){let g=r.getAttribute("data-record")??"",m=r.getAttribute("data-field")??"",c=Number(r.getAttribute("data-index")??"0"),e=[...l?.node?[l.node]:[],...l?.nodes??[]].find(p=>p.id===g);if(!g||!e)return{why:g?`names a record it was not shown ("${g.slice(0,80)}")`:"names no record (data-record)"};let h=m&&Object.hasOwn(e,m)?e[m]:void 0,f=(Array.isArray(h)?h:[h]).filter(M),o=Number.isInteger(c)&&c>=0?f[c]:void 0,v=e.label?`"${e.label}"`:"a record";return m?o?(i==="video"?!E(o):!E(o)&&!T(o))?{why:`names "${o.name}" on ${v}, which is not ${i==="video"?"a video":"a picture or a video"}`}:{file:o,on:e}:{why:f.length===0?`names "${m}" on ${v}, which holds no file it was shown`:`names file ${r.getAttribute("data-index")} of "${m}" on ${v}, which holds ${f.length}`}:{why:`names no field of ${v} (data-field)`}}var C=r=>`${r.caption?.trim()||r.name}, ${L(r)}`;function N(r,l,i,g,m,c={}){let e=r.createElement("video");e.setAttribute("data-graview-video",""),e.setAttribute("playsinline",""),e.setAttribute("aria-label",C(i)),c.autoplay?(e.setAttribute("data-graview-video-autoplay",""),e.setAttribute("muted",""),e.muted=!0,e.setAttribute("loop",""),e.setAttribute("preload",c.still?"metadata":"auto"),c.still?e.setAttribute("data-graview-video-still",""):e.setAttribute("autoplay","")):(e.setAttribute("controls",""),e.setAttribute("preload","metadata"));let h=i.poster?g(i.poster):void 0;h&&e.setAttribute("poster",h),i.width&&i.height?(e.setAttribute("width",String(i.width)),e.setAttribute("height",String(i.height)),e.style.aspectRatio=`${i.width} / ${i.height}`):e.style.aspectRatio="16 / 9",c.cover?(e.setAttribute("data-graview-video-cover",""),e.style.cssText+=";display:block;width:100%;height:100%;max-height:none;aspect-ratio:auto;object-fit:cover;background:#000"):e.style.cssText+=";display:block;width:100%;height:auto;max-height:80vh;background:#000;border-radius:var(--graview-radius, 8px)";let f=i.captions?g(i.captions):void 0;if(f){let o=r.createElement("track");o.setAttribute("kind","captions"),o.setAttribute("src",f),o.setAttribute("srclang","en"),o.setAttribute("label","Captions"),o.setAttribute("default",""),e.appendChild(o)}return i.duration===void 0&&e.addEventListener("loadedmetadata",()=>Number.isFinite(e.duration)&&e.duration>0&&e.setAttribute("aria-label",C({...i,duration:e.duration}))),e.setAttribute("src",m),l.appendChild(e),e}function S(r,l){let i=r.document,g=new Set,m=t=>{g.has(t)||(g.add(t),l.onProblem?.(t))},c=t=>{let a=l.file?l.file(t):t;if(a!==void 0)try{let s=new r.URL(a,i.baseURI);return s.origin===r.location.origin&&/^https?:$/.test(s.protocol)?a:void 0}catch{return}},e=new WeakMap,h=typeof r.matchMedia=="function"?r.matchMedia("(prefers-reduced-motion: reduce)"):void 0,f=new Set,o=(t,a)=>{a?(t.removeAttribute("autoplay"),t.setAttribute("data-graview-video-still",""),t.pause()):(t.removeAttribute("data-graview-video-still"),t.setAttribute("autoplay",""),t.setAttribute("preload","auto"),t.play?.()?.catch?.(()=>{}))},v=()=>{for(let t of f)t.isConnected?o(t,h?.matches===!0):f.delete(t)};h?.addEventListener?.("change",v);let p,k=t=>{if(typeof t.close=="function")return t.close();t.removeAttribute("open"),t.dispatchEvent(new r.Event("close"))},w=(t,a)=>m(`The ${t} in the view ${l.view} was not drawn: it ${a}.`);return{refresh(t){let a=l.shown();for(let s of Array.from(t.querySelectorAll("graview-video"))){let d=s.shadowRoot??s.attachShadow({mode:"open"});if(!l.pictures){e.delete(s),d.replaceChildren(),w("video",`asks for no pictures: a view places a record's video where its manifest says "pictures": true`);continue}let u=G(s,a,"video"),n={autoplay:s.hasAttribute("autoplay"),cover:s.hasAttribute("cover"),still:h?.matches===!0},b="file"in u?JSON.stringify([u.file,n.autoplay,n.cover]):"";if(e.get(s)===b&&d.childNodes.length>0)continue;if(e.set(s,b),d.replaceChildren(),"why"in u){w("video",u.why);continue}let A=c(u.file.href);if(!A){w("video",`names "${u.file.name}", which this host does not say it serves on this page`);continue}let $=i.createElement("style");$.textContent=":host { display: block; min-width: 0; }",d.appendChild($);let y=N(i,d,u.file,c,A,n);n.autoplay&&f.add(y)}},open(t){if(!l.pictures)return w("full-screen viewer",`asks for no pictures: a view opens a record's picture or video full screen where its manifest says "pictures": true`),!1;let a=G(t,l.shown(),"any");if("why"in a)return w("full-screen viewer",a.why),!1;let s=c(a.file.href);if(!s)return w("full-screen viewer",`names "${a.file.name}", which this host does not say it serves on this page`),!1;p&&k(p);let d=a.file,u=d.caption?.trim()||d.name,n=i.createElement("dialog");n.setAttribute("data-graview-lightbox",""),n.setAttribute("aria-label",E(d)?C(d):u),n.style.cssText="padding:0;border:0;border-radius:var(--graview-radius, 8px);max-width:min(96vw, 1600px);max-height:94vh;background:var(--graview-panel, Canvas);color:var(--graview-ink, CanvasText)";let b=i.createElement("figure");if(b.style.cssText="margin:0;display:grid;gap:8px;padding:10px",E(d))N(i,b,d,c,s);else{let x=i.createElement("img");x.setAttribute("src",s),x.setAttribute("alt",u),x.style.cssText="max-width:100%;max-height:80vh;object-fit:contain;display:block;margin:0 auto",b.appendChild(x)}let A=i.createElement("figcaption");A.style.cssText="display:flex;gap:12px;align-items:center;justify-content:space-between";let $=i.createElement("span");$.textContent=E(d)&&d.duration!==void 0?`${u} \xB7 ${P(d.duration)}`:u;let y=i.createElement("button");return y.type="button",y.textContent="Close",y.addEventListener("click",()=>k(n)),A.append($,y),b.appendChild(A),n.appendChild(b),n.addEventListener("click",x=>x.target===n&&k(n)),n.addEventListener("close",()=>{n.remove(),p===n&&(p=void 0),t.focus?.()}),i.body.appendChild(n),p=n,typeof n.showModal=="function"?n.showModal():n.setAttribute("open",""),y.focus(),!0},dispose(){p&&k(p),p?.remove(),p=void 0,h?.removeEventListener?.("change",v),f.clear()}}}export{S as createGuestMedia,G as namedFile};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as r,b as m,d as k,e as y}from"./chunk.Q355UPFG.js";import"./chunk.
|
|
1
|
+
import{a as r,b as m,d as k,e as y}from"./chunk.Q355UPFG.js";import"./chunk.RJ7VSWTA.js";import"./chunk.P43LPXXJ.js";import"./chunk.JCKIJSW7.js";import"./chunk.SDO3U72B.js";import"./chunk.6L6RUOSF.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";var i="way-back",b='[data-testid="notices-toasts"]';function g(t){let o=document.activeElement;o!==null&&o!==document.body&&!o.closest(b)||(t??document).querySelector('[data-graview-app-bar] [data-testid="app-home"]')?.focus({preventScroll:!0})}function E(t,o,a,d,h){if(t.past)return a?.dismiss(i),()=>{};let c=h?.closest("[data-graview-embed]"),s,f=e=>{if(e!==void 0&&r(t,o)?.batch!==e)return!1;try{let n=k(t,o);return n&&a?.notify({kind:"toast",id:i,sentence:`Took back \u201C${n.intent}\u201D`}),n!==void 0}catch(n){return a?.notify({kind:"toast",id:i,tone:"warn",sentence:n instanceof Error?n.message:String(n)}),!0}},u=()=>{let e=m(t,o,d);if(d=t.batches().length,e){let n=s=e.batch;a?.notify({kind:"toast",id:i,sentence:e.intent,timeout:1e4,action:{label:"Take back",keys:"Meta+Z Control+Z",onSelect:()=>(g(c),f(n))}})}else s&&r(t,o)?.batch!==s&&(s=void 0,a?.dismiss(i))},l=e=>{y(e)&&(!c||c.contains(e.target))&&f()&&e.preventDefault()};u();let p=t.subscribe(u);return document.addEventListener("keydown",l),(e=!1)=>{p(),document.removeEventListener("keydown",l),e&&s&&a?.dismiss(i)}}export{E as sceneWay};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i}from"./chunk.4LWWXIM4.js";import"./chunk.HXRHEPPJ.js";import"./chunk.QNWGDG2Z.js";import"./chunk.BJUUSIQY.js";import"./chunk.QDDDKEBH.js";import"./chunk.F7KVEWFH.js";import"./chunk.QKRQPUCE.js";import"./chunk.SPJ34VHA.js";import"./chunk.XOZU4OFA.js";import"./chunk.KBJ3UUER.js";import"./chunk.U5KJQFAP.js";import"./chunk.6TBQV3NO.js";import"./chunk.MT252WP4.js";import"./chunk.VVIQSFM4.js";import"./chunk.TQ3MNB6K.js";import"./chunk.VGYG2IBZ.js";import"./chunk.RJ7VSWTA.js";import"./chunk.P43LPXXJ.js";import"./chunk.JCKIJSW7.js";import"./chunk.SDO3U72B.js";import"./chunk.6L6RUOSF.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 +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.
|
|
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.QNWGDG2Z.js";import"./chunk.BJUUSIQY.js";import"./chunk.U5KJQFAP.js";import"./chunk.VGYG2IBZ.js";import{Wd as I,pa as O,va as j}from"./chunk.6L6RUOSF.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.VDFQFLTU.js","./chunk.TBY5IR7C.js","./chunk.BIDL7GQD.js","./chunk.Q5WEOX3Q.js","./chunk.4O64QV2Y.js","./chunk.OYMN3IFX.js","./chunk.FOHZPYUV.js","./chunk.IXYG65TM.js","./chunk.W6L2VAJG.js","./chunk.N3MXLORL.js","./chunk.6L6RUOSF.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.F6MY6WJ4.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,21 @@
|
|
|
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 Ct}from"./chunk.JO2X52D4.js";import{a as Nt,b as Bt,c as Ft,d as he,e as Ut,f as zt,g as qt}from"./chunk.VPFUOTY7.js";import{a as Ke,b as we}from"./chunk.SGYZM6ZU.js";import{a as ye}from"./chunk.CEQQIW7Z.js";import{a as Pe,d as _t,f as Lt}from"./chunk.ONAH6MC4.js";import{b as Pt,h as Gt,i as Vt,k as Kt}from"./chunk.Z2BCOZDZ.js";import"./chunk.WGH2P2YL.js";import{h as It}from"./chunk.TRP66PHK.js";import"./chunk.PGT4ZQDG.js";import{e as $t}from"./chunk.MFMC35ET.js";import{c as jt,h as Ht,i as Ge,j as Ve}from"./chunk.GKYJQE5A.js";import{b as me,e as ge}from"./chunk.EZQK23AB.js";import{d as Dt}from"./chunk.QDVGHI7R.js";import"./chunk.M5FP4Y4Q.js";import"./chunk.7KX36ENH.js";import{a as F}from"./chunk.SDO3U72B.js";import{fb as Rt,hb as Wt}from"./chunk.6L6RUOSF.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";var Yt=["good","warn","bad","neutral","accent"],Xt=["value","max","aria-label","placeholder","disabled"],Jt=["click","change"],_e=["_blank","_self"],Qt=["section","div","span","strong","p","hr","a","button","input","progress"],ve={type:{oneOf:Yt}},Le={"gv-card":{host:"section",properties:{tone:ve},events:{},children:"any"},"gv-group":{host:"div",properties:{direction:{type:{oneOf:["row","column"]}}},events:{},children:"any"},"gv-title":{host:"strong",properties:{},events:{},children:"text"},"gv-text":{host:"p",properties:{tone:ve},events:{},children:"text"},"gv-badge":{host:"span",properties:{tone:ve},events:{},children:"text"},"gv-field":{host:"div",properties:{label:{type:"string"}},events:{},children:"text"},"gv-progress":{host:"progress",properties:{value:{type:"number",as:"value"},max:{type:"number",as:"max"},label:{type:"string",as:"aria-label"}},events:{},children:"none"},"gv-divider":{host:"hr",properties:{},events:{},children:"none"},"gv-link":{host:"a",properties:{href:{type:"url"}},events:{},children:"text"},"gv-button":{host:"button",properties:{tone:ve,disabled:{type:"boolean",as:"disabled"}},events:{press:{from:"click"}},children:"text"},"gv-input":{host:"input",properties:{label:{type:"string",as:"aria-label"},value:{type:"string",as:"value"},placeholder:{type:"string",as:"placeholder"}},events:{change:{from:"change",detail:"value"}},children:"none"}},Ne=1e4;var _r=0,Lr=1,Nr=2,Ir=3,Zt=1,Cr=2,Dr=3,jr=1,Hr=3,$r=8,Ie="~",Ce=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),oe=t=>typeof t=="object"&&t!==null&&!Array.isArray(t);function er(t,e){return e.type==="url"?"href":e.as??`data-gv-${t.toLowerCase()}`}var Br=2e3;function tr(t,e){if(e==null)return{ok:!0,value:null};let s=t.type;if(s==="boolean")return typeof e=="boolean"?{ok:!0,value:e}:{ok:!1,reason:"value"};if(s==="number")return typeof e=="number"&&Number.isFinite(e)?{ok:!0,value:String(e)}:{ok:!1,reason:"value"};if(typeof e!="string"||e.length>Br)return{ok:!1,reason:s==="url"?"url":"value"};if(typeof s=="object")return s.oneOf.includes(e)?{ok:!0,value:e}:{ok:!1,reason:"value"};if(s==="url"){let d;try{d=new URL(e)}catch{return{ok:!1,reason:"url"}}return d.protocol!=="https:"||d.hostname===""||!/^https:\/\//i.test(e)?{ok:!1,reason:"url"}:{ok:!0,value:d.href}}return{ok:!0,value:e}}function Fr(t){let e=t.host==="a";return Qt.includes(t.host)&&(t.target===void 0||e&&_e.includes(t.target))&&Object.values(t.properties).every(s=>s.type!=="url"||e)&&Object.values(t.properties).every(s=>s.as===void 0||s.type!=="url"&&Xt.includes(s.as))&&Object.values(t.events).every(s=>Jt.includes(s.from))}function De(t,e){let s=e.kit??Le,d=e.maxNodes??2e3,r=t.ownerDocument,m=[],w=new Map,b={dom:t,name:Ie,component:{host:"div",properties:{},events:{},children:"any"},children:[],listeners:new Map,id:Ie};w.set(Ie,b);let T=e.links?new Set(e.links.origins.flatMap(o=>{try{let p=new URL(o);return p.protocol==="https:"&&p.hostname!==""?[p.origin]:[]}catch{return[]}})):void 0,O=0,g=0,K=!1,h=o=>{m.push(o),m.length>200&&m.shift()},k=()=>({dom:r.createComment(""),children:[],refused:!0,listeners:new Map}),S=(o,p,c)=>{let y=o.component;if(!Ce(y.properties,p))return h({reason:"property",element:o.name,name:p});let u=y.properties[p],a=tr(u,c),M=a.ok&&u.type==="url"&&T&&typeof a.value=="string"&&!T.has(new URL(a.value).origin)?{ok:!1,reason:"url"}:a,R=o.dom,V=er(p,u);if(!M.ok)return R.removeAttribute(V),h({reason:M.reason,element:o.name,name:p});let W=M.value;W===null||W===!1?R.removeAttribute(V):R.setAttribute(V,W===!0?"":W),V==="value"&&"value"in R&&(R.value=typeof W=="string"?W:""),V==="disabled"&&"disabled"in R&&(R.disabled=W!==null&&W!==!1)},v=(o,p,c)=>{let y=o.component;if(!Ce(y.events,p))return h({reason:"event",element:o.name,name:p});let u=o.listeners.get(p);if(u&&(u(),o.listeners.delete(p),g-=1),c==null)return;if(!oe(c)||typeof c.listener!="number")return h({reason:"value",element:o.name,name:p});let a=c.listener,M=y.events[p],R=o.dom,V=()=>e.onEvent(a,M.detail==="value"?String(R.value??""):void 0);R.addEventListener(M.from,V),o.listeners.set(p,()=>R.removeEventListener(M.from,V)),g+=1},G=o=>{if(!o.refused){O-=1,o.id!==void 0&&w.delete(o.id);for(let p of o.listeners.values())p();g-=o.listeners.size,o.listeners.clear();for(let p of o.children)G(p)}},x=(o,p)=>{if(!oe(o)||typeof o.id!="string"||w.has(o.id))return h({reason:"record"}),k();if(O>=d)return h({reason:"budget"}),K||(K=!0,e.onOverBudget?.()),k();let c=o.id,y=p.component.children;if(o.type===$r)return k();if(o.type===Hr){if(y==="none")return h({reason:"child",element:p.name}),k();let V={dom:r.createTextNode(String(o.data??"").slice(0,Ne)),children:[],text:!0,listeners:new Map,id:c};return w.set(c,V),O+=1,V}if(o.type!==jr)return h({reason:"record"}),k();let u=String(o.element);if(!Ce(s,u)||!Fr(s[u]))return h({reason:"element",element:u}),k();if(y!=="any")return h({reason:"child",element:u}),k();let a=s[u],M=r.createElement(a.host);M.setAttribute("data-gv",u.replace(/^gv-/,"")),M.className=`graview-guest-${u.replace(/^gv-/,"")}`,a.host==="a"&&(M.setAttribute("rel","noopener noreferrer"),M.setAttribute("target",a.target??"_blank"),M.setAttribute("referrerpolicy","no-referrer")),a.host==="button"&&M.setAttribute("type","button");let R={dom:M,name:u,component:a,children:[],listeners:new Map,id:c};if(w.set(c,R),O+=1,oe(o.properties))for(let[V,W]of Object.entries(o.properties))S(R,V,W);if(oe(o.attributes))for(let V of Object.keys(o.attributes))h({reason:"attribute",element:u,name:V});if(oe(o.eventListeners))for(let[V,W]of Object.entries(o.eventListeners))v(R,V,W);if(Array.isArray(o.children))for(let V of o.children){let W=x(V,R);R.children.push(W),M.appendChild(W.dom)}return R},A=o=>{if(!Array.isArray(o))return h({reason:"record"});let[p,c]=o,y=typeof c=="string"?w.get(c):void 0;if(!y)return h({reason:"record"});switch(p){case _r:{if(y.text)return h({reason:"record"});let u=Number(o[3]),a=Number.isInteger(u)&&u>=0&&u<=y.children.length?u:y.children.length,M=x(o[2],y);y.dom.insertBefore(M.dom,y.children[a]?.dom??null),y.children.splice(a,0,M);return}case Lr:{let u=Number(o[2]),a=y.children[u];if(!a)return h({reason:"record"});y.children.splice(u,1),a.dom.parentNode?.removeChild(a.dom),G(a);return}case Nr:if(!y.text)return h({reason:"record"});y.dom.data=String(o[2]??"").slice(0,Ne);return;case Ir:{if(y===b||y.text)return h({reason:"record"});let u=String(o[2]),a=o[4]??Zt;return a===Zt?S(y,u,o[3]):a===Dr?v(y,u,o[3]):h(a===Cr?{reason:"attribute",element:y.name,name:u}:{reason:"record"})}default:return h({reason:"record"})}};return{apply(o,p){if(!Array.isArray(o))return h({reason:"record"}),!0;for(let c=0;c<o.length;c+=1){if(p&&c%32===0&&p())return!1;A(o[c])}return!0},get refused(){return m},get size(){return O},get listening(){return g},dispose(){for(let o of b.children)G(o);b.children.length=0,t.replaceChildren()}}}var je=`
|
|
2
|
+
.graview-guest { display: flex; flex-direction: column; gap: 8px; min-width: 0; color: var(--graview-ink, inherit); font: inherit; }
|
|
3
|
+
.graview-guest-card { display: flex; flex-direction: column; gap: 6px; padding: 12px; border: 1px solid var(--graview-edge, #d0d0d0); border-radius: 10px; background: var(--graview-panel, transparent); }
|
|
4
|
+
.graview-guest-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
|
|
5
|
+
.graview-guest-group[data-gv-direction="row"] { flex-direction: row; flex-wrap: wrap; align-items: center; }
|
|
6
|
+
.graview-guest-title { font-weight: 600; font-size: 1rem; overflow-wrap: anywhere; }
|
|
7
|
+
.graview-guest-text { margin: 0; font-size: 0.875rem; line-height: 1.45; overflow-wrap: anywhere; }
|
|
8
|
+
.graview-guest-badge { align-self: flex-start; padding: 1px 8px; border: 1px solid currentColor; border-radius: 999px; font-size: 0.8125rem; font-weight: 600; }
|
|
9
|
+
.graview-guest-field { font-size: 0.875rem; overflow-wrap: anywhere; }
|
|
10
|
+
.graview-guest-field[data-gv-label]::before { content: attr(data-gv-label) " "; color: var(--graview-ink-muted, inherit); }
|
|
11
|
+
.graview-guest-progress { width: 100%; }
|
|
12
|
+
.graview-guest-divider { width: 100%; margin: 2px 0; border: 0; border-top: 1px solid var(--graview-edge, #d0d0d0); }
|
|
13
|
+
.graview-guest-link { color: var(--graview-accent, inherit); text-decoration: underline; }
|
|
14
|
+
.graview-guest-button { align-self: flex-start; font: inherit; padding: 4px 12px; border-radius: 8px; border: 1px solid var(--graview-edge, #d0d0d0); background: var(--graview-panel, transparent); color: inherit; cursor: pointer; }
|
|
15
|
+
.graview-guest-input { font: inherit; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--graview-edge, #d0d0d0); }
|
|
16
|
+
.graview-guest [data-gv-tone="good"] { color: var(--graview-good, inherit); }
|
|
17
|
+
.graview-guest [data-gv-tone="bad"] { color: var(--graview-bad, inherit); }
|
|
18
|
+
.graview-guest [data-gv-tone="warn"] { color: var(--graview-warn, inherit); }
|
|
19
|
+
.graview-guest [data-gv-tone="accent"] { color: var(--graview-accent, inherit); }
|
|
20
|
+
.graview-guest [data-gv-tone="neutral"] { color: var(--graview-ink-muted, inherit); }
|
|
21
|
+
`;var rr=new WeakSet;function Ur(t,e){if(t.startsWith("blob:"))return"blob:";try{return new URL(t,e.location.href).origin}catch{return t}}function nr(t,e,s){let d=Ur(e,t),r=`this page's Content-Security-Policy${s?` (${s})`:""} does not allow a worker from ${d}: it needs worker-src ${d}`;return rr.has(t)||(rr.add(t),t.console?.warn?.(`Graview: worker views cannot start on this page, because ${r}. A host that will not allow ${d} serves each view's whole script from its own origin and passes worker: { url } (the @graview/guest README, "What the host page allows").`)),r}function zr(t,e){return t===""?!0:e.startsWith("blob:")?t.startsWith("blob"):e.startsWith(t)||t.startsWith(e)}function ke(t,e){let s="script"in e.source?t.URL.createObjectURL(new t.Blob([e.source.script],{type:"text/javascript"})):void 0,d="script"in e.source?s:e.source.url,r,m,w=!1,b=!1,T=0,O=0,g="",K=0,h=0,k=t.performance,S=k.now(),v,G=u=>{let a=u,M=String(a.effectiveDirective||a.violatedDirective||"").split(" ")[0];/^(worker-src|script-src|script-src-elem|child-src|default-src)$/.test(M)&&zr(String(a.blockedURI??""),d)&&(v=M)},x=t.document;x?.addEventListener("securitypolicyviolation",G);let A=()=>x?.removeEventListener("securitypolicyviolation",G),o=()=>{b||(b=!0,m?.close(),r?.terminate(),r=void 0,t.clearTimeout(T),t.clearInterval(O),A(),s&&t.URL.revokeObjectURL(s))},p=(u,a)=>{b||(o(),e.onStop(u,a))},c=()=>{t.clearTimeout(T),A(),g=Nt();let u=new t.MessageChannel;m=u.port1;let a=Math.max(1,e.silentMs),M=Math.max(10,Math.min(1e3,Math.floor(a/4)));S=k.now();let R=S;O=t.setInterval(()=>{let W=k.now();if(W-R>M*2&&(S+=W-R-M),R=W,W-S>=a)return p("silent");K+=1,u.port1.postMessage({type:"heartbeat",beat:K})},M);let V={graview:"host-hello",protocol:1,nonce:g,view:e.name};r.postMessage(V,[u.port2]),e.onReady(g,u.port1,k.now()-y)},y=k.now();try{r=new t.Worker(d,{name:e.name})}catch(u){r=void 0;let a=u,M=a?.name==="SecurityError"?nr(t,d,v):`the worker could not be made: ${String(a?.message??u)}`;queueMicrotask(()=>p("start",M))}return r&&(T=t.setTimeout(()=>p("start",`it never said it was ready in ${e.readyMs.toLocaleString("en-US")} ms`),e.readyMs),r.onerror=u=>{let a=typeof u.message=="string"&&u.message!==""?u.message:void 0;if(w)return void e.onError?.(a??"an error");t.clearTimeout(T),t.setTimeout(()=>!w&&p("start",v?nr(t,d,v):a?`it failed before it said ready: ${a}`:"it failed before it said ready, and the engine gave no reason (a page policy that refuses it, or a script that does not load)"),0)},r.onmessage=u=>{if(!e.limiter.message()||w||!Lt(u.data)||u.data.protocol!==1){e.onDropped();return}w=!0,c()}),{get worker(){return r},answer(u){let a=u;return typeof a!="object"||a===null||a.type!=="heartbeat"||a.nonce!==g?!1:(typeof a.beat=="number"&&a.beat>h&&a.beat<=K&&(h=a.beat,S=k.now()),!0)},stop:o}}function be(t,e){let s=e(),d=0;return{draw(r){let m=e();m-s>=1e3&&(s=m,d=0);let w=t(),b=r(()=>d+(e()-m)>=w);return d+=e()-m,b&&d<w}}}var qr=200,Yr=64*1024,Xr=120,sr=t=>new TextEncoder().encode(t).length;function $e(){let t=new Map;return{read:async e=>Object.fromEntries(t.get(e)??[]),write:async(e,s,d)=>{let r=t.get(e)??new Map;if(t.set(e,r),d===null)return r.delete(s),{ok:!0};let m=sr(d);for(let[w,b]of r)w!==s&&(m+=sr(b));return m>Yr||!r.has(s)&&r.size>=qr?{ok:!1,sentence:"This view keeps as much as it can for this visit, so this value was not kept."}:(r.set(s,d),{ok:!0})}}}var or=new WeakMap;function dr(t,e){let s=or.get(t)??new Map;or.set(t,s);let d=s.get(e)??$e();return s.set(e,d),d}var Se="What this view keeps for you could not be read just now.",Jr="This value could not be kept just now.",He="The host has not answered yet, so this value is not kept yet.",Qr="This view asked to keep too many values at once, so this one was not kept.",Zr="The host has not answered for too many values, so this one was not kept.",en=200,ir=new WeakMap;function tn(t,e,s){let d=ir.get(t)??new Map;ir.set(t,d);let r=`${e}\0${s}`,m=d.get(r)??{writes:[],lines:new Map,drawings:new Set};return d.set(r,m),m}function lr({view:t,viewer:e="",state:s,onRefused:d,onLate:r,readMs:m=1500,writeMs:w=1e4,now:b=Date.now}){let T=new Map,O=!1,g=!1,K=new Map,h=(c,y)=>{y===null?T.delete(c):T.set(c,y)},k=tn(s,e,t),{writes:S,lines:v,drawings:G}=k,x={landed(c,y){O?h(c,y):K.set(c,y)},onRefused:d,onLate:r};G.add(x);let A=c=>(d?.(c),{ok:!1,sentence:c}),o=(async()=>{try{T=new Map(Object.entries(await s.read(t)).filter(([,c])=>typeof c=="string"));for(let[c,y]of K)h(c,y);O=!0,g&&r?.()}catch{d?.(Se)}})(),p=new Promise(c=>{let y=setTimeout(()=>{g=!0,O||d?.(Se),c()},m);o.then(()=>{clearTimeout(y),c()})});return{ready:p,values:()=>Object.fromEntries(T),get:c=>p.then(()=>new Promise(y=>{let u=()=>{if(!O)return y({ok:!1,sentence:Se});let a=v.get(c);if(!a)return y({ok:!0,value:T.get(c)??null});if(a.late)return y({ok:!1,sentence:He});a.gets.push(u)};u()})),set(c,y){let u=_t(c,y);if(u)return Promise.resolve(A(u));let a=c,M=y;return p.then(()=>new Promise(R=>{if(!O)return R(A(`${Se} So this value was not kept.`));let V={drawing:x,answer:R},W=v.get(a);if(!W){if(v.size>=en)return R(A(Zr));let Y=b();for(;S.length>0&&S[0]<=Y-6e4;)S.shift();if(S.length>=Xr)return R(A(Qr));S.push(Y);let H={late:!1,gets:[],moved:new Set};return v.set(a,H),ur(s,t,k,a,H,M,[V],w)}W.next={value:M,told:W.late?[]:[...W.next?.told??[],V],writeMs:w},W.late&&R(A(He))}))},dispose(){G.delete(x)}}}function ar(t,e){if(!e.ok)for(let s of new Set(t.map(d=>d.drawing)))s.onRefused?.(e.sentence);for(let s of t)s.answer(e)}function ur(t,e,s,d,r,m,w,b){let T=!1,O=setTimeout(()=>{T=!0,r.late=!0,ar([...w,...r.next?.told??[]],{ok:!1,sentence:He}),r.next&&(r.next.told=[]);for(let g of r.gets.splice(0))g()},b);Promise.resolve().then(()=>t.write(e,d,m)).catch(()=>{}).then(g=>{clearTimeout(O);let K=g?.ok===!0,h=g&&!g.ok&&typeof g.sentence=="string"&&g.sentence?g.sentence:Jr;if(K){let S=new Set(T?[]:w.map(v=>v.drawing));for(let v of s.drawings)v.landed(d,m),S.has(v)||r.moved.add(v)}if(!T)ar(w,K?{ok:!0}:{ok:!1,sentence:h});else if(!K)for(let S of s.drawings)S.onRefused?.(h);r.late=!1;let k=r.next;if(r.next=void 0,k)return ur(t,e,s,d,r,k.value,k.told,k.writeMs);s.lines.delete(d);for(let S of r.gets.splice(0))S();for(let S of r.moved)s.drawings.has(S)&&S.onLate?.()})}function fr(t){return!Number.isFinite(t)||t<=60?1:Math.min(4,Math.round(t/60*10)/10)}function pr(t,e){return{...t,pushMs:Math.round(t.pushMs*e),drawMs:Math.round(t.drawMs*e)}}var cr=new WeakMap;function mr(t,e){let s=cr.get(t);return s!==void 0?s:(cr.set(t,e),e)}var rn=F(()=>(__graviewPreload(import.meta.url,["./chunk.GOVRX2YX.js","./chunk.TRP66PHK.js","./chunk.PGT4ZQDG.js","./chunk.AJZBJBMO.js"]),import("./chunk.X45EITTK.js"))),nn=F(()=>(__graviewPreload(import.meta.url,["./chunk.UZKBFI52.js","./chunk.MFMC35ET.js","./chunk.GKYJQE5A.js","./chunk.EZQK23AB.js","./chunk.QDVGHI7R.js","./chunk.M5FP4Y4Q.js","./chunk.6L6RUOSF.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.2INDKSJI.js"))),sn=F(()=>(__graviewPreload(import.meta.url,["./chunk.RSMCTI2N.js","./chunk.AJZBJBMO.js"]),import("./chunk.UJPX3BUV.js"))),on=F(()=>(__graviewPreload(import.meta.url,["./chunk.WVUJXDXZ.js","./chunk.NI4OPHTL.js","./chunk.U5KJQFAP.js","./chunk.FOHZPYUV.js","./chunk.IXYG65TM.js","./chunk.W6L2VAJG.js","./chunk.N3MXLORL.js","./chunk.TQ3MNB6K.js","./chunk.VGYG2IBZ.js","./chunk.6L6RUOSF.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.H33XWGAY.js"))),an=F(()=>(__graviewPreload(import.meta.url,["./chunk.TRP66PHK.js","./chunk.PGT4ZQDG.js","./chunk.AJZBJBMO.js"]),import("./chunk.ZGLOXN7O.js"))),dn=F(()=>(__graviewPreload(import.meta.url,["./chunk.GKYJQE5A.js","./chunk.EZQK23AB.js","./chunk.QDVGHI7R.js","./chunk.6L6RUOSF.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.EJC7ACZT.js"))),ln=F(()=>(__graviewPreload(import.meta.url,["./chunk.ONAH6MC4.js","./chunk.AJZBJBMO.js"]),import("./chunk.AIFT2HNP.js"))),un=F(()=>(__graviewPreload(import.meta.url,["./chunk.WVUJXDXZ.js","./chunk.NI4OPHTL.js","./chunk.U5KJQFAP.js","./chunk.FOHZPYUV.js","./chunk.IXYG65TM.js","./chunk.W6L2VAJG.js","./chunk.N3MXLORL.js","./chunk.TQ3MNB6K.js","./chunk.VGYG2IBZ.js","./chunk.6L6RUOSF.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.23DATB5Y.js"))),cn=F(()=>(__graviewPreload(import.meta.url,["./chunk.QDVGHI7R.js","./chunk.AJZBJBMO.js"]),import("./chunk.EG7OOJH5.js"))),fn=F(()=>(__graviewPreload(import.meta.url,["./chunk.6L6RUOSF.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.Z3TK2LJM.js"))),pn='a[href^="#"], [data-sight], [data-file]';function mn(t,e,s){switch(t){case"manifest":return s??"Its manifest names something this app does not have.";case"source":return s??`Its code is longer than the ${e.maxSourceBytes.toLocaleString("en-US")} bytes a view may be.`;case"start":return`It could not start${s?`: ${s}.`:"."}`;case"error":return`It failed before it drew anything${s?`: ${s}`:"."}`;case"silent":return`It stopped answering for ${e.silentMs.toLocaleString("en-US")} ms.`;case"nodes":return`It drew more than the ${e.maxNodes.toLocaleString("en-US")} things a view may draw.`;case"flood":return`It sent more than ${e.messages} messages in ${e.messageWindowMs.toLocaleString("en-US")} ms.`;case"slow":return`It took longer than ${e.pushMs.toLocaleString("en-US")} ms to draw what it was shown.`}}function gn(t,e){let s=t.ownerDocument,d=s.defaultView,{manifest:r}=e,m=s.createElement("div");m.className="graview-worker-view",m.setAttribute("role","region"),m.setAttribute("aria-label",r.title??r.name),m.setAttribute("data-worker-view",r.name),m.style.cssText="display:block;position:relative;contain:layout paint style;isolation:isolate;overflow:clip;min-width:0",t.appendChild(m);let w=m.attachShadow({mode:"open"}),b=e.author?s.createElement("p"):void 0;b&&(b.className="graview-worker-view-author",b.setAttribute("data-worker-view-author",r.name),b.style.cssText="margin:4px 0 0;font-size:0.75rem;color:var(--graview-ink-muted, inherit)",b.textContent=e.author,t.appendChild(b));let T={applied:0,refused:0,dropped:0},O=me(e.limits),g={maxSourceBytes:e.limits?.maxSourceBytes??256e3,maxNodes:e.limits?.maxNodes??5e3,messages:e.limits?.messages??120,messageWindowMs:e.limits?.messageWindowMs??1e3,pushMs:e.limits?.pushMs??1e3,silentMs:e.limits?.silentMs??5e3,drawMs:e.limits?.drawMs??100},K={pushMs:g.pushMs,drawMs:g.drawMs},h,k,S,v,G,x,A=!1,o={applied:0,refused:0,dropped:0},p=[],c=()=>{if(!v)return;let n=v.stats;T.applied+=n.applied-o.applied,T.refused+=n.refused-o.refused,T.dropped+=n.dropped-o.dropped,o={...n}},y=()=>{},u,a,M=()=>{let n=w.querySelector("[data-graview-view-root]"),i=d.ResizeObserver;a||!n||typeof i!="function"||(a=new i(E=>{let _=E[E.length-1]?.borderBoxSize?.[0],N=Math.ceil(_?_.blockSize:n.offsetHeight);N!==u&&(u=N,m.setAttribute("data-graview-content-height",String(N)),e.onContentHeight?.(N))}),a.observe(n))},R=()=>{a&&(a.disconnect(),a=void 0,u=void 0,m.removeAttribute("data-graview-content-height"),e.onContentHeight?.(void 0))},V=0,W=()=>{},Y=()=>{},H,vr,X,Be=[],Fe=()=>{W(),W=()=>{},Y(),H?.dispose(),c(),v?.dispose(),v=void 0,G?.stop(),y(),d.clearInterval(V)},D=(n,i)=>{if(A)return;A=!0,Fe(),R(),x?.dispose();let E=mn(n,g,i);m.removeAttribute("data-worker-view-drawn"),m.setAttribute("data-worker-view-failed",n),e.fallback!==!1&&(e.fallback??kr)(m,n,E),e.onFailure?.(n,E)},kr=(n,i,E)=>{let _=k??(()=>{try{return Ve(e.store,e.principal,{manifest:r,...e.input?{input:e.input()}:{},...S?{computed:S}:{}})}catch{return}})(),N=s.createElement("div");N.setAttribute("data-graview-fallback",i),N.style.cssText="padding:12px;display:grid;gap:6px;color:var(--graview-ink, inherit);font-family:var(--graview-font-body, inherit)";let f=s.createElement("strong");f.textContent=r.title??r.name;let I=s.createElement("ul");I.style.cssText="margin:0;padding-left:1.2em";for(let B of[..._?.node?[_.node]:[],..._?.nodes??[]]){let fe=s.createElement("li");fe.textContent=B.label??B.id,I.appendChild(fe)}let C=s.createElement("p");C.style.cssText="margin:0;font-size:0.8125rem;color:var(--graview-ink-muted, inherit)",C.textContent=`This view was stopped. ${E}`,N.append(f,I,C),w.replaceChildren(N)},Ue=jt(r,e.store);if(Ue.length>0)return queueMicrotask(()=>D("manifest",Ue.join(" "))),Ae();for(let n of Ht(e.store,r))queueMicrotask(()=>e.onProblem?.(n));let ze=n=>{if(("source"in n?new TextEncoder().encode(n.source).length:"script"in n?new TextEncoder().encode(n.script).length:0)>g.maxSourceBytes)return["source"];let E="source"in n?ye(n.source):[];return E.length>0?["source",E.join(" ")]:void 0},J=e.worker,qe=typeof J=="function"?void 0:ze(J);if(qe)return queueMicrotask(()=>D(...qe)),Ae();let Ye=qt(d,()=>et(),"blob"),Te=()=>zt(()=>e.theme?.()??he(m),e.brand,Ye),Xe="[[],null]",Je="",ie=0,U,Qe=()=>{let n=e.brand?.()?.views;if(x&&!x.theme(n?.css)&&Je!==n?.css){Je=n?.css??"";let f="The app's stylesheet for its views draws nothing: the open kit leaves all of it out, so views are drawn without it. graview check says which part (brand-views-css).";j?.postMessage({type:"notice",text:f}),e.onProblem?.(f)}x?.motion(n?.motion??"none");let i=n?.fonts??[],E=e.brand?.()?.typography,_=JSON.stringify([i,E??null]);if(_===Xe)return;Xe=_,ie+=1;let N=ie;if(i.length===0){U?.(),U=void 0;return}an().then(({loadViewFonts:f})=>{N===ie&&(U=f(s,i,{...e.asset?{asset:e.asset}:{},...e.fonts?{origins:e.fonts.origins}:{},...E?{typography:E}:{}},I=>{j?.postMessage({type:"notice",text:I}),e.onProblem?.(I)},U))})},Ze="",xe=()=>{Ze=JSON.stringify(Te()),Qe(),v?.push()},et=()=>{v&&JSON.stringify(Te())!==Ze&&xe()},br=Ut(s,et),z,Sr=Ge(e.store,r)?un().then(({computedOn:n})=>{S=n(e.store.schema)}):Promise.resolve(),q,Tr=r.pictures?sn().then(({createGuestPictures:n})=>{A||(z=n(d,{as:"blob",view:`"${r.title??r.name}"`,pictures:r.pictures,...e.limits?{limits:e.limits}:{},...e.file?{file:e.file}:{},moved:()=>v?.push(),onLeft:i=>{j?.postMessage({type:"notice",text:i}),e.onProblem?.(i)}}))}):Promise.resolve();y=()=>{br(),Ye.dispose(),z?.dispose(),re?.dispose(),q?.dispose(),ue?.dispose(),ie+=1,U?.(),U=void 0};let j,Q=n=>j?.postMessage(n),tt=!1,rt=!1,ae=()=>m.toggleAttribute("data-worker-view-drawn",!A&&rt&&x!==void 0&&p.length===0&&ee.size===0&&!z?.waiting()&&!(q?.waiting??0)),Z=d.performance,ee=new Map,de=Z.now(),xr=()=>{if(V)return;let n=Math.max(10,Math.min(250,Math.floor(g.pushMs/4)));de=Z.now(),V=d.setInterval(()=>{let i=Z.now(),E=i-de>n*2?i-de-n:0;de=i;for(let[_,N]of ee){let f=N+E;if(ee.set(_,f),i-f>=g.pushMs)return D("slow")}},n)},Mr=be(()=>g.drawMs,()=>Z.now()),nt=()=>{},Me=n=>{if(A)return;if(!x)return void p.push(n);let i=x;if(!Mr.draw(_=>n[0]==="render"?i.apply(n[1],_):(i.style(n[1]),!0)))return D("slow");n[0]==="render"&&nt()},st=()=>new Set([...e.store.kindsKeptFrom(e.principal),...e.store.modules.disabledKinds]),ot=()=>Gt(e.store.schema,st()),Ee=()=>Vt(e.store.schema,e.places?.()??[],{kept:st(),...e.arrangement?{pages:e.arrangement()}:{}}),te=Kt({sees:n=>e.store.seenBy(e.principal).graph.has(n),places:Ee,lists:ot,schema:e.store.schema,...e.onNavigate?{onNavigate:e.onNavigate}:e.goTo?{onNavigate:n=>Bt(e.goTo(),n)}:{},...e.hrefOf?{hrefOf:e.hrefOf}:!e.onNavigate&&e.goTo?{hrefOf:n=>Ft(e.goTo(),n)}:{},onLost:n=>{j?.postMessage({type:"notice",text:n}),e.onProblem?.(n)}}),$=new Set,it=new Set,re,at=!1,dt=()=>{at||(at=!0,on().then(({createGuestMedia:n})=>{A||(re=n(d,{view:`"${r.title??r.name}"`,pictures:r.pictures!==void 0,shown:()=>k,...e.file?{file:e.file}:{},onProblem:i=>{j?.postMessage({type:"notice",text:i}),e.onProblem?.(i)}}),re.refresh(w))},()=>e.onProblem?.(`The view "${r.title??r.name}" places a video or a full-screen viewer, and the host's player could not be loaded.`)))},lt=!1,ut=!1,le=new Map,ct=()=>{lt||!r.accepts?.length||(lt=!0,dn().then(({createGuestDrops:n})=>{A||(q=n(d,{shadow:w,manifest:r,store:e.store,principal:e.principal,files:()=>e.files?.(),shown:()=>$,hears:()=>ut,idOf:i=>x?.renderer.idOf(i),send:Q,change:(i,E)=>{if(!v)return{ok:!1,reason:"refused",message:"The view has gone."};let _=v.change(i,E);return c(),_},handed:(i,E)=>le.set(i.href,{file:i,drop:E}),onProblem:i=>{j?.postMessage({type:"notice",text:i}),e.onProblem?.(i)},onBusy:()=>ae()}),q.refresh())},()=>e.onProblem?.(`The view "${r.title??r.name}" takes files, and the host's drop could not be loaded.`)))},ue,ft=[],pt=!1,Er=n=>{ft=n,ue?.bind(n),!(pt||n.length===0)&&(pt=!0,ln().then(({createGuestGestures:i,unheardWords:E})=>{if(!A){if(r.gestures!==!0){let _=E(r.title??r.name);return j?.postMessage({type:"notice",text:_}),e.onProblem?.(_)}ue=i(w,{root:()=>w.querySelector("[data-graview-view-root]")??void 0,idOf:_=>x?.renderer.idOf(_),send:Q}),ue.bind(ft)}},()=>{}))},Or=n=>{let i=e.store.seenBy(e.principal).graph;for(let E of $){let _=i.getNode(E);for(let N of Object.values(_??{}))for(let f of Dt(N))if(f.href===n)return f}},mt=()=>vr??=cn().then(({createGuestSections:n})=>{if(!A)return H=n(d,{shadow:w,idOf:i=>x?.renderer.idOf(i),send:Q,record:i=>$.has(i)?e.store.seenBy(e.principal).graph.getNode(i):void 0,...e.file?{file:e.file}:{},onProblem:i=>{j?.postMessage({type:"notice",text:i}),e.onProblem?.(i)}}),H.refresh(),H},()=>{e.onProblem?.(`The view "${r.title??r.name}" draws a jump or a file link, and the host's part of it could not be loaded.`)}),gt=n=>{if(n.localName==="graview-video")return dt();n.hasAttribute("data-lightbox")&&(n.setAttribute("aria-haspopup","dialog"),dt())};Promise.all([rn(),nn()]).then(([{createOpenDrawing:n,handedLinks:i,judgeLink:E,linkRefusedWords:_},{createPressReader:N,createSaver:f,fillPrefills:I,judgePress:C,markPresses:B,prefillOf:fe,quietPictures:Ar}])=>{if(A)return;let ne=N(),Rr=l=>Be.some(P=>{try{for(let L=l;L&&L.getRootNode()===w&&!L.hasAttribute("data-graview-view-root");L=L.parentElement)if(L.matches(P))return!0}catch{}return!1}),bt=(l,P)=>{let L=x?.renderer.idOf(l);if(L!==void 0&&Q({type:"dom-event",target:L,event:"acted",pressed:P}),P.ok)return X?.clear(l);Rr(l)||fn().then(({createRefusalNotes:se})=>{A||!l.isConnected||(X??=se(w),X.say(l,P.message??"That was not applied."))},()=>e.onProblem?.(`A press in the view "${r.title??r.name}" was refused: ${P.message??P.reason??"not applied"}`))},Re=f({reader:ne,save:(l,P)=>{if(!v)return;let L=v.pressed(C(e.store,r,$,l));c(),bt(P,{as:l.as,...L})}}),St=()=>Re.flush();d.addEventListener("pagehide",St),W=()=>{d.removeEventListener("pagehide",St),Re.flush()};let Wr=new WeakSet;nt=()=>{te.refresh(w),B(w),Ar(w),I(w,ne,Wr,l=>fe(e.store,e.principal,r,$,l)),re?.refresh(w),q?.refresh(),X?.refresh(),H?H.refresh():w.querySelector(pn)&&mt()};let Tt,xt=new Set,Pr=()=>(Tt!==k&&([Tt,xt]=[k,i(k)]),xt),Mt=new Set;x=n(w,{origin:e.origin??d.location.origin,link:l=>E(l,{handed:Pr(),...e.links?{origins:e.links.origins}:{}}),...e.asset?{asset:e.asset}:{},...e.images?{imageOrigins:e.images.origins}:{},...r.pictures?{picture:l=>z?.drawn(l)}:{},onRefused:l=>{if(l.reason==="url"&&l.element==="a"&&l.address!==void 0&&!Mt.has(l.address)){Mt.add(l.address);let L=_(l.address,e.links?.origins);return j?.postMessage({type:"notice",text:L}),e.onProblem?.(L)}if(l.reason!=="url"||l.element!=="img"||l.address===void 0||it.has(l.address))return;it.add(l.address);let P=It(l.address,{...e.images?{origins:e.images.origins}:{},assets:e.asset!==void 0},l.length);j?.postMessage({type:"notice",text:P}),e.onProblem?.(P)},...e.limits?.maxNodes!==void 0?{maxNodes:e.limits.maxNodes}:{},onOverBudget:()=>D("nodes"),send:Q,onFieldSet:l=>ne.filled(l),onAttribute:(l,P)=>{(P==="data-record"||P==="data-place")&&te.link(l),P==="data-lightbox"&>(l),P==="data-drop"&&ct()},decorate:l=>{(l.hasAttribute("data-record")||l.hasAttribute("data-place"))&&te.link(l),gt(l),l.hasAttribute("data-drop")&&ct()},before:(l,P,L)=>{ne.heard(l,P),Re.heard(l,P,L),te.pressed(l,P,L);let se=P.closest("a[href]");se&&L.contains(se)&&!se.hasAttribute("data-graview-link")&&l.type==="click"&&l.stopPropagation();let pe=P.closest("[data-lightbox]"),Et=l.type==="keydown"?l.key:void 0;if(pe&&L.contains(pe)&&l.isTrusted&&(l.type==="click"||(Et==="Enter"||Et===" ")&&pe.localName!=="button")&&(l.preventDefault(),l.stopPropagation(),re?.open(pe)),q?.before(l,P,L))return!1;let Ot=l.type==="click"&&l.isTrusted?P.closest('a[href^="#"]'):null;Ot&&L.contains(Ot)&&(l.preventDefault(),H?H.jump(P,L):mt().then(Kr=>Kr?.jump(P,L)));let We=ne.press(l,P,L);if(!We||!v)return;l.stopPropagation(),X?.clear(P.closest("[data-act]")),l.type==="keydown"&&l.preventDefault();let Gr=v.pressed(C(e.store,r,$,We));c();let At={as:We.as,...Gr},Vr=P.closest("[data-act]");return queueMicrotask(()=>bt(Vr,At)),{pressed:At}}}),Qe();for(let l of p.splice(0))Me(l);M(),ae()},()=>D("start","the view's drawing could not be loaded"));let yt=e.draft?void 0:e.viewerState?.(),ht=Wt(e.principal)??Rt(e.principal).id??e.principal.visitorKey??"",ce=lr({view:r.name,viewer:ht,state:yt??(e.draft?$e():dr(e.store,ht)),onRefused:n=>{e.onProblem?.(n),v&&j?.postMessage({type:"notice",text:n})},onLate:()=>v?.push()});Y=()=>ce.dispose();let Oe=n=>G=ke(d,{source:n,name:r.name,limiter:O,readyMs:e.limits?.readyMs??5e3,silentMs:e.limits?.silentMs??5e3,onDropped:()=>T.dropped+=1,onStop:(i,E)=>D(i,E),onError:i=>{tt||D("error",i)},onReady:(i,E,_)=>{j=E,h=fr(mr(d,_)),Object.assign(g,pr(K,h)),xr();let N=ge({store:e.store,principal:e.principal,view:r.name,nonce:i,send:f=>{f.type==="props"&&typeof f.push=="number"&&(ee.set(f.push,Z.now()),ae()),E.postMessage(f)},mine:ce,props:()=>{let f={...Ve(e.store,e.principal,{manifest:r,...e.input?{input:e.input()}:{},theme:Te(),places:Pt(Ee()),...S?{computed:S}:{}}),mine:ce.values()},I=$;return $=new Set([...f.node?[f.node.id]:[],...(f.nodes??[]).map(C=>C.id)]),k&&(I.size!==$.size||[...$].some(C=>!I.has(C)))&&x?.fade(),k=f,f},...z?{hand:z.hand}:{},judgeAct:(f,I)=>{let C=$t(e.store,r,f,I,{shown:$,file:B=>le.get(B)?.file??Or(B),dropped:B=>le.get(B)?.drop});if(C.ok)for(let B of C.spent??[])le.delete(B);return C},onHears:f=>{f.includes("drop")&&(ut=!0)},onGestures:Er,onClicks:(f,I)=>{Ct(m,f),Be=I},onRender:f=>{tt=!0,Me(["render",f])},onPushed:(f,I)=>{if(ee.delete(f),I>=g.pushMs)return D("slow");rt=!0,ae()},onFlood:()=>D("flood"),onStyle:f=>Me(["style",f]),places:()=>[...new Set([...Ee().map(f=>f.as),...ot().map(f=>f.slug)])],...e.limits?{limits:e.limits}:{},limiter:O});v=N,E.onmessage=({data:f})=>{if(!G?.answer(f)&&(N.receive(f),c(),!A&&f?.nonce===i&&f.type==="navigate")){let I={...f.where!==void 0?{where:f.where}:{},...f.section!==void 0?{section:f.section}:{}},C=typeof f.place=="string"?{place:f.place,...I}:typeof f.to=="string"&&{record:f.to,...I};C&&te.go(C)}},xe()}}),wt=r.pictures!==void 0||Ge(e.store,r)||yt!==void 0,vt=()=>Promise.all([ce.ready,Tr.catch(()=>Promise.reject(new Error("the view's pictures could not be loaded"))),Sr.catch(()=>Promise.reject(new Error("the view's computed values could not be worked out")))]),kt=n=>{"source"in n?(wt?Promise.all([Ke(n.source),vt()]).then(([i])=>i):Ke(n.source)).then(i=>{A||Oe({script:i})},i=>D("start",i instanceof Error&&i.message.startsWith("the view's")?i.message:"the view's runtime could not be loaded")):wt?vt().then(()=>{A||Oe(n)},i=>D("start",i instanceof Error?i.message:"the view's pictures could not be loaded")):Oe(n)};return typeof J=="function"?we(J).then(n=>{if(A)return;let i=ze(n);i?D(...i):kt(n)},n=>D("source",`Its code did not arrive${n instanceof Error&&n.message?`: ${n.message}`:""}.`)):kt(J),Ae();function Ae(){return{element:m,shadow:w,get worker(){return G?.worker},update:()=>{v&&xe()},get stats(){return c(),T},get refused(){return x?.refused??[]},get contentHeight(){return u},get css(){return x?.css??""},get pace(){return h},dispose(){A=!0,Fe(),a?.disconnect(),x?.dispose(),m.remove(),b?.remove()}}}}var gr=8e3,yr=t=>({root:t?.shadow.querySelector("[data-graview-view-root]")??void 0,css:t?.css??"",height:t?.contentHeight}),hr=t=>(t?.refused??[]).map(e=>`Refused ${e.reason==="css"?"a rule of the stylesheet":`${e.element?`<${e.element}>`:"something"}${e.name?` ${e.name}`:""}`} (${e.reason}).`);function yn({element:t,definition:e,mounted:s,optionsFor:d,draw:r,mount:m,pressing:w}){return{name:e.manifest.name,title:e.manifest.title??e.manifest.name,source:async()=>{let b=typeof e.worker=="function"?await we(e.worker):e.worker;return"source"in b?b.source:void 0},theme:async()=>{let b=s()?.element;return b?{...he(b)}:{}},drawing:()=>yr(s()),refused:()=>hr(s()),check:async b=>ye(b),presses:async b=>{let T=w?.();if(!T)throw new Error("This page cannot press a view's controls.");let{pressedHere:O}=await T(),g=d({source:b}),K=await O({manifest:g.manifest,source:b,store:g.store,principal:g.principal,...g.input?{input:g.input()}:{},...g.places?{places:g.places()}:{}});if(!K.ok){let k={control:"the view",element:"",does:"nothing",ok:!1,says:K.detail};return{ok:!1,controls:[k],problems:[k]}}let h=K.presses;return h?{ok:h.ok,controls:h.controls,problems:h.problems}:{ok:!0,controls:[],problems:[]}},draft:b=>{let T=s()?.element,O=t.ownerDocument.createElement("div");O.setAttribute("data-graview-section-draft",e.manifest.name),O.style.minWidth="0",t.appendChild(O),T&&(T.style.display="none");let g=()=>{},K=new Promise(S=>g=S),h=setTimeout(()=>g({failed:`It did not draw in ${gr/1e3} seconds.`}),gr),k=m(O,{...d({source:b}),draft:!0,fallback:!1,onFailure:(S,v)=>g({failed:v??`It failed (${S}).`}),onContentHeight:S=>{S!==void 0&&S>0&&g({})}});return K.then(()=>clearTimeout(h)),{drawn:K,drawing:()=>yr(k),refused:()=>hr(k),dispose:()=>{clearTimeout(h),k.dispose(),O.remove(),T&&(T.style.display="")}}},draw:r}}var wr="graview-guest-kit";function ts(t,e){let s=t.ownerDocument,d=s.defaultView;if(!s.getElementById(wr)){let G=s.createElement("style");G.id=wr,G.textContent=je,s.head.appendChild(G)}let r=s.createElement("div");r.className="graview-guest",r.setAttribute("role","group"),r.setAttribute("aria-label",e.title??e.view),r.setAttribute("data-guest-view",e.view),t.appendChild(r);let m={applied:0,refused:0,dropped:0},w=me(e.limits),b=be(()=>e.limits?.drawMs??100,()=>d.performance.now()),T,O,g,K=!1,h={applied:0,refused:0,dropped:0},k=()=>{if(!T)return;let G=T.stats;m.applied+=G.applied-h.applied,m.refused+=G.refused-h.refused,m.dropped+=G.dropped-h.dropped,h={...G}},S=()=>{k(),T?.dispose(),T=void 0,g?.stop()},v=(G,x)=>{K||(K=!0,S(),O?.dispose(),e.onFailure?.(G,x))};return g=ke(d,{source:e.worker,name:e.view,limiter:w,readyMs:e.limits?.readyMs??5e3,silentMs:e.limits?.silentMs??5e3,onDropped:()=>m.dropped+=1,onStop:(G,x)=>v(G,x),onReady:(G,x)=>{let A=De(r,{...e.kit?{kit:e.kit}:{},...e.links?{links:e.links}:{},onEvent:(p,c)=>x.postMessage({type:"event",listener:p,...c!==void 0?{detail:c}:{}}),...e.limits?.maxNodes!==void 0?{maxNodes:e.limits.maxNodes}:{},onOverBudget:()=>v("budget")});O=A;let o=ge({store:e.store,principal:e.principal,view:e.view,nonce:G,send:p=>x.postMessage(p),onRender:p=>{b.draw(c=>A.apply(p,c))||v("slow")},...e.input?{input:e.input}:{},...e.onNavigate?{onNavigate:e.onNavigate}:{},onSize:e.onSize??(p=>r.style.minHeight=`${p}px`),...e.limits?{limits:e.limits}:{},limiter:w});T=o,x.onmessage=p=>{g?.answer(p.data)||(o.receive(p.data),k())},o.push()}}),{element:r,get worker(){return g?.worker},update:()=>T?.push(),get stats(){return k(),m},get refused(){return O?.refused??[]},dispose(){K=!0,S(),O?.dispose(),r.remove()}}}export{Le as GUEST_KIT,je as GUEST_KIT_CSS,_e as KIT_LINK_TARGETS,Yt as KIT_TONES,De as createKitRenderer,er as hostAttribute,tr as kitValue,ts as mountGuestWorker,gn as mountWorkerView,yn as viewPlaceHandle};
|
|
@@ -1 +1 @@
|
|
|
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
|
+
import{d as pn,f as yn}from"./chunk.QNWGDG2Z.js";import{a as mn}from"./chunk.SPJ34VHA.js";import{Ld as qe,fc as ue,ha as Fe,ma as L,pa as K,pc as Z,ua as Le}from"./chunk.6L6RUOSF.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};
|