graview 0.1.66 → 0.1.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/preview/{chunk.OJY7VJ7D.js → chunk.2BMZPALF.js} +1 -1
- package/dist/preview/{chunk.OTV5XTBB.js → chunk.2KCDLCB2.js} +1 -1
- package/dist/preview/{chunk.WVLEGCRI.js → chunk.2ME4DVBI.js} +1 -1
- package/dist/preview/chunk.2TUEBU7X.js +8 -0
- package/dist/preview/{chunk.QHMHUL6B.js → chunk.2U6HB4XU.js} +1 -1
- package/dist/preview/{chunk.ZQR2SN65.js → chunk.32JE2WS7.js} +1 -1
- package/dist/preview/{chunk.OEIWIZCP.js → chunk.3DEWQDP7.js} +1 -1
- package/dist/preview/{chunk.2VR7YEJ6.js → chunk.3JMQKANL.js} +1 -1
- package/dist/preview/chunk.3VEZ5MOC.js +25 -0
- package/dist/preview/chunk.3WPCS6KP.js +1 -0
- package/dist/preview/{chunk.FXT5CN32.js → chunk.42C3FIKK.js} +1 -1
- package/dist/preview/{chunk.QQAZQDRW.js → chunk.42KHFGN6.js} +1 -1
- package/dist/preview/{chunk.ANS2IEEV.js → chunk.4DXPPM6T.js} +1 -1
- package/dist/preview/chunk.4GVKKBQL.js +1 -0
- package/dist/preview/{chunk.5CXIEYHY.js → chunk.4TT3ZHSJ.js} +2 -2
- package/dist/preview/{chunk.OMT4QUZY.js → chunk.4YAO3A5Q.js} +4 -4
- package/dist/preview/{chunk.M2JCFNHJ.js → chunk.5JKUT2OM.js} +1 -1
- package/dist/preview/chunk.5L4ADKTW.js +1 -0
- package/dist/preview/{chunk.YNEHJWJV.js → chunk.64LCHHZB.js} +1 -1
- package/dist/preview/{chunk.6HY6ZGEE.js → chunk.6AANHELP.js} +1 -1
- package/dist/preview/{chunk.6TLXFMX2.js → chunk.6DMCEBSO.js} +1 -1
- package/dist/preview/{chunk.IWYMKGZZ.js → chunk.6IR5LBJU.js} +1 -1
- package/dist/preview/{chunk.YIPXZUTT.js → chunk.6WB2TYK7.js} +1 -1
- package/dist/preview/chunk.6ZENHSTQ.js +1 -0
- package/dist/preview/{chunk.7ZKBYXUM.js → chunk.7K2V5FUB.js} +1 -1
- package/dist/preview/chunk.7OL6H4LF.js +1 -0
- package/dist/preview/{chunk.FBILPNGH.js → chunk.7TDML5YU.js} +1 -1
- package/dist/preview/{chunk.45JP6VGJ.js → chunk.7WPVLEX2.js} +2 -2
- package/dist/preview/{chunk.W4YDPHCQ.js → chunk.7ZTGB4O7.js} +1 -1
- package/dist/preview/{chunk.4FDVINRJ.js → chunk.ACNOP2IU.js} +1 -1
- package/dist/preview/{chunk.AK7NGFEX.js → chunk.AENP662H.js} +1 -1
- package/dist/preview/{chunk.MWGZKZD6.js → chunk.AQ2PI6MR.js} +1 -1
- package/dist/preview/chunk.ARS4HJD2.js +1 -0
- package/dist/preview/{chunk.FDZE5LTJ.js → chunk.AWV57UBJ.js} +2 -2
- package/dist/preview/{chunk.C2C3AXGI.js → chunk.AYZL3LCR.js} +3 -3
- package/dist/preview/{chunk.FIFUMX5X.js → chunk.BHJRT57H.js} +1 -1
- package/dist/preview/{chunk.IAEHUSQQ.js → chunk.BPNW5KCP.js} +1 -1
- package/dist/preview/{chunk.HOCD7KIR.js → chunk.BQAFFEOA.js} +1 -1
- package/dist/preview/chunk.C2QKA6XY.js +1 -0
- package/dist/preview/{chunk.NJRLJEJY.js → chunk.CE3NKAF7.js} +1 -1
- package/dist/preview/{chunk.5LJVOLKR.js → chunk.CFE3MHWZ.js} +1 -1
- package/dist/preview/{chunk.DQFHIJFN.js → chunk.CGBOPPNL.js} +1 -1
- package/dist/preview/{chunk.V7W5AQKL.js → chunk.CNN32262.js} +1 -1
- package/dist/preview/{chunk.6EHHMWPP.js → chunk.DCLF4WWZ.js} +1 -1
- package/dist/preview/{chunk.OO2OP76C.js → chunk.DGDW54KE.js} +1 -1
- package/dist/preview/{chunk.XMQG2PSM.js → chunk.DLSS56EU.js} +1 -1
- package/dist/preview/{chunk.WSO7JOW5.js → chunk.DMZRFXH7.js} +1 -1
- package/dist/preview/{chunk.DEHIR4EG.js → chunk.DPHH5ZVL.js} +1 -1
- package/dist/preview/{chunk.XOE4KNP2.js → chunk.DZ6UDZOB.js} +2 -2
- package/dist/preview/{chunk.WAB3L3ZI.js → chunk.E423JCOS.js} +1 -1
- package/dist/preview/{chunk.CTASTRQN.js → chunk.EB7PZJEO.js} +1 -1
- package/dist/preview/{chunk.QPF4KSAW.js → chunk.ECNGVD25.js} +1 -1
- package/dist/preview/{chunk.JXNVNFV4.js → chunk.EGSOHTZZ.js} +1 -1
- package/dist/preview/{chunk.CEVGND3Y.js → chunk.EGVM24ND.js} +3 -3
- package/dist/preview/{chunk.6LXIEM6B.js → chunk.ENLIIZF2.js} +1 -1
- package/dist/preview/{chunk.GME63ZHI.js → chunk.EP5JS7ZH.js} +1 -1
- package/dist/preview/{chunk.QGIM2WAY.js → chunk.F5GNNVSQ.js} +1 -1
- package/dist/preview/chunk.FHQ25SWY.js +1 -0
- package/dist/preview/{chunk.OOSIKCOS.js → chunk.FSW535EA.js} +1 -1
- package/dist/preview/{chunk.ZD7T234N.js → chunk.FZELUSK5.js} +1 -1
- package/dist/preview/{chunk.LINSO5PN.js → chunk.G2BDEWJC.js} +1 -1
- package/dist/preview/chunk.GF3ZCX46.js +2 -0
- package/dist/preview/{chunk.J7W2OFHY.js → chunk.GJTEV6CK.js} +1 -1
- package/dist/preview/{chunk.VKZIEZ5C.js → chunk.GKTQ5CZA.js} +2 -2
- package/dist/preview/{chunk.GEFXU4VO.js → chunk.GONZB3J3.js} +1 -1
- package/dist/preview/{chunk.VGHO3VCB.js → chunk.GRBWXTST.js} +1 -1
- package/dist/preview/{chunk.YXEO3Y65.js → chunk.GRTBEA7O.js} +1 -1
- package/dist/preview/chunk.H3IGXHZR.js +93 -0
- package/dist/preview/{chunk.QFHWG4LN.js → chunk.H3W5C3XQ.js} +1 -1
- package/dist/preview/{chunk.TGEL6EUA.js → chunk.H4VNIAHN.js} +1 -1
- package/dist/preview/{chunk.IGK7EZCX.js → chunk.HH4D3JEI.js} +1 -1
- package/dist/preview/{chunk.F4VB6Q2W.js → chunk.HWFJQ42Y.js} +1 -1
- package/dist/preview/{chunk.OWFS2YDQ.js → chunk.HXTKBISQ.js} +1 -1
- package/dist/preview/{chunk.ZR2TP3BF.js → chunk.I34BWUB4.js} +1 -1
- package/dist/preview/{chunk.EXYCN4WI.js → chunk.I63462I3.js} +1 -1
- package/dist/preview/{chunk.7VADSNPZ.js → chunk.IKKKHHRN.js} +1 -1
- package/dist/preview/{chunk.FK722SHI.js → chunk.IPGLITWA.js} +1 -1
- package/dist/preview/{chunk.BXBEGMPO.js → chunk.IT5DVKXY.js} +2 -2
- package/dist/preview/{chunk.LLIURXFP.js → chunk.IXMIU4D4.js} +1 -1
- package/dist/preview/{chunk.INHS3KTK.js → chunk.JCETQQ7J.js} +1 -1
- package/dist/preview/{chunk.PPSYUOH7.js → chunk.JGRSUTPJ.js} +1 -1
- package/dist/preview/{chunk.4U4D7WOI.js → chunk.JLDJZET2.js} +1 -1
- package/dist/preview/{chunk.Z7Y3R3YR.js → chunk.JULD4XFB.js} +1 -1
- package/dist/preview/{chunk.PAGEGBUD.js → chunk.JV432T4Q.js} +1 -1
- package/dist/preview/{chunk.4FCFNAA4.js → chunk.KAM73WVF.js} +1 -1
- package/dist/preview/{chunk.6P6NGZ6D.js → chunk.KUCBNMIY.js} +1 -1
- package/dist/preview/{chunk.I2737CPF.js → chunk.L7XKYGV7.js} +1 -1
- package/dist/preview/{chunk.7VP6Y6D2.js → chunk.LFFJB6D3.js} +1 -1
- package/dist/preview/{chunk.BFAFCVL4.js → chunk.LMTG5NPG.js} +1 -1
- package/dist/preview/{chunk.QOS5T46W.js → chunk.LOKGUALC.js} +1 -1
- package/dist/preview/chunk.LZ6MSQ5O.js +1 -0
- package/dist/preview/chunk.MBTEOF4R.js +1 -0
- package/dist/preview/{chunk.PFQBCHQA.js → chunk.MIOLBZBS.js} +1 -1
- package/dist/preview/{chunk.PDDIQ6PK.js → chunk.MK5RPEB2.js} +1 -1
- package/dist/preview/{chunk.FV72U33M.js → chunk.MKL4THIV.js} +1 -1
- package/dist/preview/{chunk.2MHNPBHC.js → chunk.MPWLDQOG.js} +1 -1
- package/dist/preview/chunk.MSUZAJ2K.js +4 -0
- package/dist/preview/{chunk.EMFOMSMI.js → chunk.N5Z34V7U.js} +1 -1
- package/dist/preview/chunk.N64RVSH3.js +1 -0
- package/dist/preview/{chunk.5B5SRTUK.js → chunk.ND3DEDWB.js} +1 -1
- package/dist/preview/{chunk.3L4JMM3P.js → chunk.NFTPJAMJ.js} +1 -1
- package/dist/preview/{chunk.J2MM6BUW.js → chunk.NRCWMYLH.js} +1 -1
- package/dist/preview/{chunk.OPTYYIGC.js → chunk.O2VXTYUJ.js} +1 -1
- package/dist/preview/{chunk.4AC2QM7T.js → chunk.O32F6LGK.js} +1 -1
- package/dist/preview/{chunk.W53YNBSM.js → chunk.O5FTWXA2.js} +1 -1
- package/dist/preview/{chunk.U6TEW6YD.js → chunk.ODYJEDIW.js} +1 -1
- package/dist/preview/{chunk.E7EWNWAN.js → chunk.OQ4ZO3YY.js} +1 -1
- package/dist/preview/chunk.PI4RFOBU.js +1 -0
- package/dist/preview/{chunk.BMENTGDC.js → chunk.PIMAG4WT.js} +2 -2
- package/dist/preview/{chunk.DTCAUPLC.js → chunk.PLIV3IQK.js} +1 -1
- package/dist/preview/{chunk.4JULYKGD.js → chunk.PPCDPYYU.js} +1 -1
- package/dist/preview/{chunk.BGAC3B7X.js → chunk.PZQ5P6WK.js} +1 -1
- package/dist/preview/chunk.Q42R2KW4.js +1 -0
- package/dist/preview/{chunk.2KFZHUAC.js → chunk.Q4VFLLUT.js} +1 -1
- package/dist/preview/{chunk.ONYBW45K.js → chunk.Q6H5HESF.js} +1 -1
- package/dist/preview/chunk.QM54TGU6.js +3 -0
- package/dist/preview/{chunk.6MQ5NT7S.js → chunk.QOQ26NXM.js} +1 -1
- package/dist/preview/{chunk.FFOD5B4B.js → chunk.QUETLFBJ.js} +1 -1
- package/dist/preview/{chunk.DSYP43NN.js → chunk.QWLK3GKG.js} +1 -1
- package/dist/preview/{chunk.RWIN3POV.js → chunk.QYPU444Y.js} +1 -1
- package/dist/preview/{chunk.ES63XSIM.js → chunk.QZP3ARLH.js} +1 -1
- package/dist/preview/{chunk.CVPMSPCH.js → chunk.R3GE37OI.js} +1 -1
- package/dist/preview/chunk.R66ZVMWB.js +1 -0
- package/dist/preview/chunk.RD2FSSLV.js +1 -0
- package/dist/preview/{chunk.72ZCLEQC.js → chunk.RQG672MJ.js} +1 -1
- package/dist/preview/chunk.RYA7A4NA.js +1 -0
- package/dist/preview/{chunk.BUVTUAB5.js → chunk.SADR3MQI.js} +1 -1
- package/dist/preview/{chunk.EQ4OODGO.js → chunk.SS6KL5NT.js} +1 -1
- package/dist/preview/chunk.SUG6LIOX.js +1 -0
- package/dist/preview/{chunk.WSDJPXJD.js → chunk.TFJA4QV4.js} +1 -1
- package/dist/preview/{chunk.3PBTN7RO.js → chunk.TOUSIUJF.js} +1 -1
- package/dist/preview/{chunk.CU2WCYMK.js → chunk.TR4YFVZN.js} +1 -1
- package/dist/preview/{chunk.GNEOSHQ6.js → chunk.TRNJKHIA.js} +1 -1
- package/dist/preview/{chunk.72XP2ARZ.js → chunk.TVWK3SGD.js} +1 -1
- package/dist/preview/chunk.U7PAFLUM.js +1 -0
- package/dist/preview/{chunk.QU52E5RG.js → chunk.UAMPR4MD.js} +1 -1
- package/dist/preview/{chunk.KBPJ7X7W.js → chunk.UD7VLXPM.js} +1 -1
- package/dist/preview/{chunk.M6ZN2KUO.js → chunk.UFURYU4R.js} +1 -1
- package/dist/preview/{chunk.6FQW6FNL.js → chunk.UODTUBQ7.js} +1 -1
- package/dist/preview/{chunk.KHRS2SKB.js → chunk.VBHV4TLG.js} +1 -1
- package/dist/preview/{chunk.KSIEO5W7.js → chunk.VES4XMZX.js} +1 -1
- package/dist/preview/chunk.VLXLBGMY.js +90 -0
- package/dist/preview/{chunk.QWNSHISU.js → chunk.VTDOWXCP.js} +1 -1
- package/dist/preview/{chunk.5FNFRVTL.js → chunk.VV5JAM5W.js} +1 -1
- package/dist/preview/{chunk.DZFM6GSY.js → chunk.VW632VNJ.js} +1 -1
- package/dist/preview/{chunk.LSN2IPAI.js → chunk.WC5WE34A.js} +1 -1
- package/dist/preview/chunk.WN7SAAH6.js +1 -0
- package/dist/preview/{chunk.B6JRTW3A.js → chunk.WV45KLXC.js} +1 -1
- package/dist/preview/{chunk.TXHYGFIZ.js → chunk.XDZDNZ7B.js} +1 -1
- package/dist/preview/{chunk.7BIPZTJB.js → chunk.XFH6GHBQ.js} +1 -1
- package/dist/preview/{chunk.HSSIMVVM.js → chunk.XRE7SHLD.js} +1 -1
- package/dist/preview/{chunk.LETAQTLJ.js → chunk.XXCHO2A5.js} +1 -1
- package/dist/preview/{chunk.KACSYPEV.js → chunk.Y7OGJOPA.js} +1 -1
- package/dist/preview/{chunk.LGRVEHXT.js → chunk.YBQ5GVAX.js} +2 -2
- package/dist/preview/{chunk.PSQYDCVM.js → chunk.YL2RBZFE.js} +1 -1
- package/dist/preview/{chunk.BZ7QWHAE.js → chunk.YM6SWEUI.js} +1 -1
- package/dist/preview/{chunk.CBXS23YH.js → chunk.Z2X7BFCB.js} +2 -2
- package/dist/preview/{chunk.U3ED7W2U.js → chunk.Z67LBSQO.js} +1 -1
- package/dist/preview/chunk.ZKXIZBCN.js +1 -0
- package/dist/preview/{chunk.E3UL4MCD.js → chunk.ZLEBOR5T.js} +1 -1
- package/dist/preview/{chunk.5BX66FBP.js → chunk.ZLNUZ6LR.js} +1 -1
- package/dist/preview/chunk.ZMADWPJO.js +1 -0
- package/dist/preview/chunk.ZO6VMEPP.js +1 -0
- package/dist/preview/chunk.ZUG7U7AT.js +1 -0
- package/dist/preview/index.html +56 -56
- package/dist/preview/page.js +2 -2
- package/package.json +6 -6
- package/dist/preview/chunk.4WGYUYWU.js +0 -2
- package/dist/preview/chunk.5EMIWORS.js +0 -1
- package/dist/preview/chunk.6EVMXBNB.js +0 -1
- package/dist/preview/chunk.BCQWAFGD.js +0 -1
- package/dist/preview/chunk.BOCVLC7X.js +0 -1
- package/dist/preview/chunk.DPJNGFEZ.js +0 -4
- package/dist/preview/chunk.E4VRRWFP.js +0 -1
- package/dist/preview/chunk.EUAO4QNV.js +0 -1
- package/dist/preview/chunk.F7672TKJ.js +0 -1
- package/dist/preview/chunk.FA42HCPW.js +0 -1
- package/dist/preview/chunk.FBJAQPZ6.js +0 -1
- package/dist/preview/chunk.GAFMWOME.js +0 -1
- package/dist/preview/chunk.I4Z7HVRT.js +0 -1
- package/dist/preview/chunk.JMXXA4YG.js +0 -1
- package/dist/preview/chunk.JMYUQNXN.js +0 -6
- package/dist/preview/chunk.K6DFXDPZ.js +0 -1
- package/dist/preview/chunk.KF27ME27.js +0 -1
- package/dist/preview/chunk.L25DCT5S.js +0 -1
- package/dist/preview/chunk.MODLZJD4.js +0 -25
- package/dist/preview/chunk.OJGHDWI6.js +0 -1
- package/dist/preview/chunk.SSF47GUY.js +0 -1
- package/dist/preview/chunk.T6DPWW2K.js +0 -3
- package/dist/preview/chunk.TA36WBHK.js +0 -1
- package/dist/preview/chunk.TTGKX7LT.js +0 -1
- package/dist/preview/chunk.U3HERHAI.js +0 -88
- package/dist/preview/chunk.V5I4GZEY.js +0 -1
- package/dist/preview/chunk.VT2YGDK2.js +0 -1
- package/dist/preview/chunk.XK65Y2KX.js +0 -1
- package/dist/preview/chunk.Z274CL7J.js +0 -1
- package/dist/preview/chunk.ZBVYD4OX.js +0 -90
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as pn,f as yn}from"./chunk.YIPXZUTT.js";import{a as mn}from"./chunk.PPSYUOH7.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.6HY6ZGEE.js";var xe="I couldn't work out how to do that \u2014 try saying it another way.";function oe(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 _n(n,e=xe){return n&&oe(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 Un=["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}, ${Un[new Date(i).getUTCDay()]}, ${u}`}function bn(n){return kn(n,n).replace(/, today$/,"")}var He=.6,Jn=.75,Wn=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"]),me=n=>n.charAt(0).toUpperCase()+n.slice(1),Fn={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&&Wn.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:me(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 Fn))return{called:"assigned to",...t?{who:me(t)}:{}}}var Sn=["done","completed","finished","closed"],qn=["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,m,$)=>`the ${a.length}${$?` ${$}`:""} ${a.length===1?b(m):g(m)}${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(m=>t.graph.getNode(a)?.[m]===!0),N=t.today?.()??new Date().toISOString().slice(0,10),A=a=>qn.map(m=>t.graph.getNode(a)?.[m]).find(m=>typeof m=="string"),J=[];if(f&&f.ids.length>1){let a=f.ids.filter(R),m=f.ids.filter(D=>!R(D)),$=m.filter(D=>(A(D)??"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}),m.length>0&&m.length<f.ids.length&&J.push({which:"held",part:"open",records:m,kind:f.kind,words:p(m,f.kind,"open"),close:!1}),$.length>0&&$.length<f.ids.length&&J.push({which:"held",part:"late",records:$,kind:f.kind,words:p($,f.kind,"late"),close:!1})}let M=v?r:[...r,...J],ve=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=>[ve(a),a.which==="itself"?`${me(a.words)} (the ${b(a.kind)})`:me(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(m=>m.subject&&(m.subject.kinds==="*"||m.subject.kinds.includes(a))),C=r.flatMap(a=>W(a.kind).slice(0,24).map(m=>({key:`${a.which}:${m.name}`,reading:a,mutation:m})));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}: ${et(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),j=new Set([...re,...C.flatMap(a=>Z(a.mutation.input).filter(m=>m.name!==a.mutation.subject.arg).flatMap(m=>m.kinds))]),F=t.graph.allNodes().filter(a=>j.has(a.kind)||j.has("*")),De=new Set(c.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(a=>a.length>=3).map(a=>a.slice(0,4))),ne=a=>L(o.tryDefinition(a.kind),a),$e=(F.length<=25?F:F.filter(a=>ne(a).toLowerCase().split(/[^\p{L}\p{N}]+/u).some(m=>m.length>=3&&De.has(m.slice(0,4))))).filter(a=>a.id!==u?.id&&!r.some(m=>m.records.includes(a.id))).slice(0,25),te=ze.test(i)?zn(t,e.principal,j):void 0,Q=ze.test(i)&&e.principal?Bn(t,e.principal.id):void 0,ge=Hn.exec(i),q=(ge?.[1]??ge?.[2])?.toLowerCase(),ce=q?Yn(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}`,ne(a)])),else:"Someone else"}}),$e.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($e.map(a=>[`r:${a.id}`,`${ne(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 x=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(x.answers.mood),d=Ge(i)?.owned===!0&&!/\?\s*$/.test(i)?!1:pe&&pe.chance>=.6?pe.key==="asks":Ze(i),S=de(x.answers.where);if(!d&&Ve(i)&&S?.key==="outside"&&S.chance>=.6)return{sure:!0,asks:!1,outside:Xe(t,i,u?.id),usage:x.usage};let l=de(x.answers.reading),T=M.length>1?M.find(a=>ve(a)===l?.key):M[0];if(!T){let a=de(x.answers.act),m=a&&a.key!=="none"?C.find($=>$.key===a.key):void 0;if(!d&&m&&Ie(m.mutation)&&f&&f.ids.length>1){let $=(m.mutation.title??m.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 ${$}? Say which, or \u201Call\u201D.`,usage:x.usage}}return{sure:!1,asks:d,usage:x.usage}}let O={...T,close:M.length>1&&(l?.chance??1)<Jn,chance:M.length>1?l?.chance??0:1},w=de(x.answers.act),P=de(x.answers.named),V=de(x.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:ne(z)}:void 0,H=te??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)?te?ne(te):Q:Gn.test(le.who)?z?ne(z):void 0:le.who),Ue=le?{called:le.called,...dn?{who:dn}:{},...le.owned?{owned:!0}:{}}:void 0,se=Ue&&v?{...Ue,called:v.toLowerCase()}:Ue,Mn=x.answers.reading?.type==="choice"?Object.entries(x.answers.reading.probabilities).filter(([a])=>a!==l?.key).reduce((a,[,m])=>Math.max(a,m),0):0;if(!(M.length===1||(l?.chance??0)>=.5||(l?.chance??0)>=.35&&(l?.chance??0)>=1.5*Mn))return{sure:!1,asks:d,reading:O,usage:x.usage};let je=(a,m)=>Z(a.input).some($=>$.name!==a.subject.arg&&($.kinds.includes("*")||$.kinds.some(D=>m.includes(D)))),cn=[...re,...H?[H.kind]:[]];if(d||en.test(i))return{sure:!1,asks:d,reading:O,usage:x.usage};let fe=Zn(x.answers.act),ie=a=>C.find(m=>m.mutation.name===a&&m.reading.which===O.which),ln=a=>!!(a&&(a.mutation.destructive||a.mutation.derived?.act==="remove")),_=w&&w.key!=="none"?w.key.slice(w.key.indexOf(":")+1):void 0,ae=w!==void 0&&w.key!=="none"&&w.chance>=He;if(!ae&&fe.length>1&&fe[0].chance+fe[1].chance>=.8&&ln(ie(fe[0].name))&&ln(ie(fe[1].name))&&(ae=!0),_&&H&&ie(_)&&!je(ie(_).mutation,[H.kind])){let a=ie(_).mutation,m=new Set(Z(a.input).map(E=>E.name)),$=Object.entries(a.input?.shape??{}).some(([E,G])=>!m.has(E)&&!G.safeParse(void 0).success&&!G.safeParse(Me(i)).success),D=P&&P.chance>=.9&&$?0:.05,U=fe.filter(E=>E.chance>=D).map(E=>ie(E.name)).find(E=>E&&E.mutation.derived?.act!=="merge"&&je(E.mutation,[H.kind]));U&&(_=U.mutation.name,ae=!0)}if(!ae&&H&&se?.who&&(X||te||se.owned)){let a=C.filter(m=>m.reading.which===O.which&&m.mutation.derived?.act!=="merge"&&Z(m.mutation.input).some($=>$.name!==m.mutation.subject.arg&&Be(t,H,$.kinds)!==void 0&&re.some(D=>$.kinds.includes(D))));a.length===1&&(_=a[0].mutation.name,ae=!0)}if(!ae&&H){let a=fe.filter(m=>m.chance>=.3).map(m=>ie(m.name)).find(m=>m&&m.mutation.derived?.act!=="merge"&&Z(m.mutation.input).some($=>$.name!==m.mutation.subject.arg&&Be(t,H,$.kinds)!==void 0));a&&(_=a.mutation.name,ae=!0)}let Je=v===void 0?Xn(i):void 0,fn=r.find(a=>a.which==="itself");if(Je&&fn){let a=["label","name","title"],m=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)))}),$=m?(ue(m.mutation)??[]).find(U=>U!==m.mutation.subject.arg):void 0,D=$?(m.mutation.input?.shape??{})[$]:void 0;if(m&&$&&D?.safeParse(Je).success)return{sure:!0,reading:{...fn,close:!1},each:{act:m.mutation.name,args:{[$]:Je}},usage:x.usage}}if(_&&!ie(_)){let a=C.find(D=>D.mutation.name===_),m=D=>{let U=a?.mutation?.derived?.act,E=D.mutation.derived?.act;return U!==void 0?U===E:(D.mutation.title??D.mutation.name).split(/\s+/)[0].toLowerCase()===(a?.mutation.title??_??"").split(/\s+/)[0].toLowerCase()},$=C.find(D=>D.reading.which===O.which&&m(D));$&&(_=$.mutation.name)}let B=_&&ae?ie(_):void 0;if(B&&!(se?.who&&!je(B.mutation,cn))){let a=(ue(B.mutation)??[]).filter(G=>G!==B.mutation.subject.arg),m=Z(B.mutation.input),$=B.mutation.input?.shape??{},D={},U=!0;for(let G of a){let ye=m.find(We=>We.name===G),hn=ye?ye.optional:$[G]?.safeParse(void 0).success??!0,gn=ye&&H?Be(t,H,ye.kinds):void 0;ye&&gn?D[G]=gn.id:!ye&&!hn&&a.filter(We=>!m.some(En=>En.name===We)).length===1&&Me(i)!==void 0&&$[G]?.safeParse(Me(i)).success?D[G]=Me(i):hn||(U=!1)}if(B.mutation.derived?.act==="edit"&&Object.keys(D).length===0&&(U=!1),!U)return{sure:!1,reading:O,...X?{taken:X}:{},act:B.mutation.name,usage:x.usage};let E=M.length===1||(l?.chance??0)>=Ke(B.mutation,i);return Ie(B.mutation)&&O.records.length>1&&(!E||Qe(i,O))?{sure:!0,reading:O,clarify:Qn(t,B.mutation.title??B.mutation.name,O),usage:x.usage}:{sure:!0,reading:O,...X?{taken:X}:{},each:{act:B.mutation.name,args:D},usage:x.usage}}let un=de(x.answers.need),In=C.some(a=>a.reading.which===O.which&&je(a.mutation,cn));if(se?.who&&!In&&(un?.key==="person"&&un.chance>=He||te!==void 0||Q!==void 0||X!==void 0||se.owned===!0)){let a=se.who??(H&&re.includes(H.kind)?ne(H):void 0);if(!a)return{sure:!1,reading:O,usage:x.usage};let m=v?`${me(g(O.kind))} have no ${se.called}.`:`${me(g(O.kind))} have no one ${se.called} them.`;return{sure:!0,reading:O,...X?{taken:X}:{},missing:{said:m,need:{link:{on:O.kind,called:se.called,to:"person"}},who:a},text:m,usage:x.usage}}return{sure:!1,reading:O,...X?{taken:X}:{},..._&&w&&w.chance>=.3?{act:_}:{},usage:x.usage}}var ze=/\b(me|my|mine|myself)\b/i,Hn=/\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,Gn=/^(her|him|them|they|that person|whoever)$/i;function zn(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 Bn(n,e){let t=n.graph.getNode(e);return t?L(n.schema.tryDefinition(t.kind),t):void 0}function Yn(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 Ie(n){return n.destructive===!0||n.derived?.act==="remove"||n.derived?.act==="archive"}function Qn(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 Kn=[[/\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=Kn.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 Vn(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 Vn(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 Xn(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 Zn(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 et(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 nt=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],tt=["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`${nt[t.getUTCDay()]}, ${tt[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 st=/\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(!st.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,it=()=>`ai-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;function ot(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 Pn=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 ke(n,e){let t=e.interaction??it(),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:ot(e.store,e.target,e.places)},usage:o,meter:c=>{o.push(c),n.meter?.({...c,interaction:t})}}}async function be(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 ee(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 Se(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 I=(n,e,t,s)=>({interaction:{...n.entry,ask:{kind:t,said:e??""},offered:[],outcome:"failed",failed:s,usage:[...n.usage]},offers:[]}),Ae="AI isn't on here.";async function It(n,e,t=3){let s=ke(n,e),i=e.said??"Suggest",o=s.catalog.candidates.filter(Pn).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}=Se(o,"Which of these would the person most likely want to do next, here?"),h=await be(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 ee(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 I(s,i,"suggest",Ae)}catch(k){return I(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 rt=n=>`several:${n}`;async function Et(n,e,t=2){let s=ke(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:rt(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 I(s,i,"suggest",Ae);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}=Se(u,`Which of these would the person most likely want to do next with the ${o} records they chose together?`),g=await be(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>=at)}catch(r){return I(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 at=.25;async function _t(n,e){let t=ke(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,...Se(f,`Which value fits "${b}" best for this record?`)})),g=await be(c,t.state,Object.fromEntries(h.map(b=>[b.key,b.question])),t.meter);for(let b of h){let f=!dt(e.store,e.target,b.field)&&ct(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 ee(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 I(t,s,"fill",Ae)}catch(h){return I(t,s,"fill",h instanceof Error?h.message:String(h))}let k=t.usage.at(-1)?.model,r=_e(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 dt(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 ct(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 Ut(n,e){let t=ke(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 I(t,s,"record","Nothing here makes a record.");let c=Re(n);if(!c)return I(t,s,"record",Ae);let u;try{let r=await ee(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 I(t,s,"record",r instanceof Error?r.message:String(r))}if(!u)return I(t,s,"record","The model named no act this app has here.");let y=t.usage.at(-1)?.model,k=_e(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?I(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 Jt(n,e){let t=ke(n,e),s=e.said??"Make a panel",i=t.catalog.candidates.filter(r=>r.type==="panel");if(i.length===0)return I(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 ee(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}=Se(i,`Which panel answers this best: ${s}`),g=Pe((await be(o,t.state,{panel:r},t.meter)).panel,h,1)[0];g?.candidate.type==="panel"&&(u={panel:g.candidate,confidence:g.confidence})}else return I(t,s,"panel",Ae)}catch(r){return I(t,s,"panel",r instanceof Error?r.message:String(r))}if(!u)return I(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 lt(n){return n.off?void 0:n.answer}var we=`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.`,ft='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 Wt(n,e){let t=ke(n,e),s=e.said.trim(),i=lt(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=O=>An(o,{store:e.store,target:e.target,said:O,...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 O=await u("fast",o.model,()=>Promise.all(S.map(d)));for(let w of O){let P=Ce(o.price,w.usage.inputTokens,w.usage.outputTokens);y.meter({tier:"fast",model:o.model,inputTokens:w.usage.inputTokens,outputTokens:w.usage.outputTokens,...P!==void 0?{costUsd:P}:{}})}if(O.every(w=>w.sure&&w.each&&!w.asks))return Tn(e,y,s,O,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 Tn(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=>Pn(d)||d.type==="panel"||d.type==="place"||d.type==="record").slice(0,32),N;try{N=o&&(i||v)&&s?await mt(o,s,y,R):Ln(y,R)}catch(d){return I(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),ve=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=>ve.has(T))))return[];let l=[...ve].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,j="",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}:{}}),S=d.usage?.inputTokens,l=d.usage?.outputTokens,T=d.usage?.costUsd??(S!==void 0?Ce(i.price,S,l??0):void 0);A.meter({tier:"thinking",model:i.model,...S!==void 0?{inputTokens:S}:{},...l!==void 0?{outputTokens:l}:{},...T!==void 0?{costUsd:T}:{}}),j=typeof d.text=="string"?d.text.trim():"",F=De(d.pick??[])}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(w=>({id:w.id,says:w.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(w=>w.id),...e.members??[]])],rn(e.store)),...M.length>0?{members:M.map(w=>({id:w.id,label:L(e.store.schema.tryDefinition(w.kind),w)})),member_acts:Y.map(w=>({name:w.name,title:w.title,does:w.does,asks:w.asks}))}:{},...r?{fast_leaned_to:r}:{},...g?{people:{[g.said]:g.as}}:{},everyone_in_the_app:he(e.store).flatMap(w=>e.store.graph.allNodes().filter(P=>P.kind===w)).slice(0,40).map(w=>L(e.store.schema.tryDefinition(w.kind),w)),...rn(e.store)?{today:bn(rn(e.store))}:{},...n.couldNotFind?{not_found:ft}:{}});re=d;let S=w=>!!(w&&(typeof w.answer=="string"&&w.answer.trim()||Array.isArray(w.pick)&&w.pick.length>0||w.each||w.lacks)),l=await u(f?"light":"thinking",v.model,()=>ee(v,we,d,A,A.meter));f&&p&&p!==f&&!S(l)&&(l=await u("thinking",p.model,()=>ee(p,we,d,A,A.meter)));let T=!b()&&!en.test(s)&&M.length>0,O=w=>Array.isArray(w)&&w.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&&!O(l.pick)){let w=await u(f?"light":"thinking",v.model,()=>ee(v,we,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(w&&(w.each||w.lacks))l=w;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(w=>{let P=J.find(V=>V.id===w);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()&&!oe(l.answer)&&!l.each&&!l.lacks){let w=await u(f?"light":"thinking",v.model,()=>ee(v,we,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));w&&typeof w.answer=="string"&&oe(w.answer)?l={...l,answer:w.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 w=await u(f?"light":"thinking",v.model,()=>ee(v,we,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));w&&typeof w.answer=="string"&&oe(w.answer)&&(l={...l,answer:w.answer})}if(j=typeof l?.answer=="string"?l.answer.trim():"",F=De(Array.isArray(l?.pick)?l.pick:[]),W=gt(l?.each),j&&!oe(j)&&(j=W?"":xe),typeof l?.lacks=="string"&&l.lacks.trim()){let w=ht(l.need),P=l.lacks.trim();C={said:oe(P)?P:w?ut(e.store.schema,w):xe,...w?{need:w}:{},...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}=Se(J,`Which of these best answers, or acts on: ${s}`),l=await be(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),j=F.length>0?`These fit \u201C${s}\u201D.`:""}else return I(A,s,"ask",Ae)}catch(d){return I(A,s,"ask",d instanceof Error?d.message:String(d))}for(let d of[j,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,()=>ee(v,we,JSON.stringify({...JSON.parse(re??"{}"),known:`These are in the app: ${l}. Never say they are not.`}),A,A.meter)),O=typeof T?.answer=="string"?T.answer.trim():"",w=O&&oe(O)&&on(e.store,O).length===0?O:`${S[0].name} is here, one of its ${K(e.store.schema,S[0].kind).toLowerCase()}. Try saying it another way.`;d!==j&&(C=void 0),j=w}if(!b()&&Ve(s)&&!/\b(field|link|column)\b/i.test(s)&&(C=void 0,W=void 0,F=[],j=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 ne=!!W||F.some(({candidate:d})=>Ne(d)!==void 0);if(!b()&&!ne&&!C&&j&&Cn(j)&&(j=Nn),!j&&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),I(A,s,"ask","The AI had no answer to that here.")}let $e=A.usage.at(-1)?.model,te=b(),Q=W?e.store.allMutations().find(d=>d.name===W.act):void 0;if(Q&&Ie(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=(te?[]: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),x=ce.length>0?_e(e.store,{interaction:A.id,target:e.target,basis:s,...$e?{model:$e}:{},proposals:ce},e.principal):void 0,pe=F.map(({candidate:d})=>d).filter(d=>te||Ne(d)===void 0);if(!W&&!te&&x&&x.proposals.length>0&&(j=x.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&&x){let d=M.map(S=>S.id).filter(S=>x.proposals.some(l=>l.id===`each:${Q.name}:${S}`));d.length>0&&(j=Dn(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)),...(x?.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",...j?{answer:j}:{},usage:[...A.usage],stages:c},offers:pe,...x&&x.proposals.length>0?{ghost:x}:{},...j?{answer:j}: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 Dn(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 ut(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 Tn(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?_e(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?Dn(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 ht(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 gt(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 _e(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 Ft(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 qt(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 Ht=n=>({...n,outcome:"dismissed"}),Rn={candidates:8,records:6},pt=.1,yt=12,jn=n=>{let e=new Set;return[...n.selection,...n.neighbors].filter(t=>!e.has(t.id)&&(e.add(t.id),!0))};function Ln(n,e){return{choices:e,state:n.state,context:{by:"default",candidates:e.map(t=>t.id),records:jn(n.state).map(t=>t.id)}}}async function mt(n,e,t,s){let i=jn(t.state),o={},c=s.length>0?Se(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,yt).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{...Ln(t,s),context:{by:"fast",model:n.model,candidates:[],records:[]}};let y=await be(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>=pt).flatMap(([N])=>{let A=p(N);return A===void 0?[]:[A]}).slice(0,v)})(y.candidates,c.of,Rn.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,Rn.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{_n as a,Te as b,Re as c,it as d,ot as e,It as f,rt as g,Et as h,_t as i,Ut as j,Jt as k,Wt as l,_e as m,Ne as n,Ft as o,qt as p,Ht as q};
|
|
1
|
+
import{d as pn,f as yn}from"./chunk.6WB2TYK7.js";import{a as mn}from"./chunk.JGRSUTPJ.js";import{Fd as qe,Xb as ue,fc as Z,ga as Fe,la as L,oa as K,ta as Le}from"./chunk.6AANHELP.js";var me="I couldn't work out how to do that \u2014 try saying it another way.";function ee(n){let e=n.trim();return e.length===0||!/^[\p{Lu}\p{N}"“‘'(]/u.test(e)||!/[.!?…][”’"')]*$/u.test(e)||e.split(/\s+/).filter(Boolean).length<3?!1:!/[{}[\]]|\b[a-z]+_[a-z_]+\b/.test(e)}function Jn(n,e=me){return n&&ee(n)?n.trim():e}function wn(n,e,t,s,i=40){let o=n.seenBy(e).graph,c=n.schema,u=y=>{let k=o.getNode(y);return k?L(c.tryDefinition(k.kind),k):void 0};return t.slice(0,i).flatMap(y=>{let k=o.getNode(y);if(!k)return[];let r=Object.fromEntries(Object.entries(k).filter(([g,b])=>!["id","kind","label"].includes(g)&&!g.startsWith("_")&&b!==void 0&&b!==null&&(typeof b!="object"||Array.isArray(b))&&JSON.stringify(b).length<=200).map(([g,b])=>[g,typeof b=="string"&&s?kn(b,s):b])),h=[...o.outEdges(y).flatMap(g=>{let b=u(g.to);return b?[`${Fe(g.kind).toLowerCase()} ${b}`]:[]}),...o.inEdges(y).flatMap(g=>{let b=u(g.from);return b?[`${Fe(g.kind).toLowerCase()} it: ${b}`]:[]})].slice(0,12);return[{id:y,kind:k.kind,label:u(y)??y,fields:r,links:h}]})}var Wn=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function kn(n,e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(n.slice(0,10)),s=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e.slice(0,10));if(!t||!s||n.length!==10)return n;let i=Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3])),o=Date.UTC(Number(s[1]),Number(s[2])-1,Number(s[3])),c=Math.round((i-o)/864e5),u=c===0?"today":c===1?"tomorrow":c===-1?"yesterday, already past":c>0?`in ${c} days`:`${-c} days ago, already past`;return`${n}, ${Wn[new Date(i).getUTCDay()]}, ${u}`}function bn(n){return kn(n,n).replace(/, today$/,"")}var He=.6,Fn=.75,qn=new Set(["person","people","user","users","member","members","volunteer","volunteers","staff","contact","contacts","employee","employees","client","clients","customer","customers","guest","guests","player","players","student","students"]),we=n=>n.charAt(0).toUpperCase()+n.slice(1),Hn={assign:!0,reassign:!0,give:!0,hand:!0,delegate:!0,allocate:!0};function Ye(n,e){let t=n.graph.getNode(e);if(!t)return;let s=new Map;for(let o of[...n.graph.in(e),...n.graph.out(e)])o.kind!==t.kind&&s.set(o.kind,[...new Set([...s.get(o.kind)??[],o.id])]);let i=[...s.entries()].sort((o,c)=>c[1].length-o[1].length)[0];return i&&i[1].length>1?{kind:i[0],ids:i[1]}:void 0}function he(n){let e=n.schema,t=e.definitions.filter(s=>s.people).map(s=>s.kind);return[...new Set([...t,...e.definitions.filter(s=>[s.kind,s.noun,K(e,s.kind)].some(i=>i!==void 0&&qn.has(i.toLowerCase()))).map(s=>s.kind)])]}function Ge(n){let e=/^\s*([\p{L}][\p{L}'’-]*)\s+(?:should|can|will|could|is going to|needs to)\s+(?:take care of|handle|own|do|look after|take|deal with|pick up|be on)\b/iu.exec(n)?.[1]??/\bmake\s+(?:this|these|it|them|this one)\s+([\p{L}][\p{L}-]*)['’]s\b/iu.exec(n)?.[1]??/\b(?:this|these|it|they)\s+(?:is|are)\s+([\p{L}][\p{L}-]*)['’]s\b/iu.exec(n)?.[1]??/\b([\p{L}][\p{L}-]*)['’]s\s+(?:job|task|responsibility|shift|now)\b/iu.exec(n)?.[1]??/^\s*([\p{L}][\p{L}-]*)['’]s\s+(?:on|got|doing|handling|taking|covering)\s+(?:this|it|these|that|them)\b/iu.exec(n)?.[1]??/^\s*([\p{L}][\p{L}-]*)\s+(?:has|has got|is on|is doing|is handling|is taking|is covering|takes|does|owns)\s+(?:this|it|these|that|them)(?:\s+one)?\b/iu.exec(n)?.[1];if(e&&!/^(it|this|that|these|those|they|we|you|i|he|she|everyone|someone|anyone|nobody|nothing|who|what|which|there|it's|that's|who's|what's)$/i.test(e))return{called:"assigned to",who:we(e),owned:!0};let t=/\bto\s+([\p{L}][\p{L}'’-]*)\s*[.!?]*\s*$/iu.exec(n)?.[1];if(n.toLowerCase().split(/[^a-z]+/).find(i=>i in Hn))return{called:"assigned to",...t?{who:we(t)}:{}}}var Sn=["done","completed","finished","closed"],Gn=["due","dueDate","dueOn","deadline"];function Qe(n,e){return e.which!=="held"||e.part?!1:/\b(that'?s|that is|that are|that were|that have|that has|which|whose|already|except|but not|only|apart from|other than)\b/i.test(n)||/\bones? (that|which|i|we|you|i'?ve|we'?ve|i'?m)\b/i.test(n)||xn(n)||Oe(n).open||Oe(n).finished}function de(n){if(n?.type!=="choice")return;let e=n.probabilities[n.choice]??n.confidence;return{key:n.choice,chance:e}}async function An(n,e){let{store:t,target:s,said:i}=e,o=t.schema,c=`${i} ${e.follows?.said??""}`.trim(),u=s.on==="record"?t.graph.getNode(s.id):void 0,y=u?Ye(t,u.id):void 0,k=(e.members??[]).filter(a=>t.graph.getNode(a)!==void 0),r=[],h=e.where?` in ${e.where}`:u?` in ${L(o.tryDefinition(u.kind),u)}`:"",g=a=>K(o,a).toLowerCase(),b=a=>(o.tryDefinition(a)?.noun??a).toLowerCase();u&&r.push({which:"itself",records:[u.id],kind:u.kind,words:`${L(o.tryDefinition(u.kind),u)} itself`,close:!1});let f=y??(k.length>0?{kind:t.graph.getNode(k[0]).kind,ids:k.filter(a=>t.graph.getNode(a).kind===t.graph.getNode(k[0]).kind)}:void 0),p=(a,w,x)=>`the ${a.length}${x?` ${x}`:""} ${a.length===1?b(w):g(w)}${h}`;f&&f.ids.length>0&&r.push({which:"held",records:f.ids,kind:f.kind,words:p(f.ids,f.kind),close:!1});let v=e.follows?/\bcall (?:it|that|the field)\s+["“']?([\p{L}][\p{L} ]*?)["”']?\s*[.!]*\s*$/iu.exec(i)?.[1]:void 0;if(v&&e.follows?.reading&&r.some(a=>a.which===e.follows.reading)&&r.splice(0,r.length,...r.filter(a=>a.which===e.follows.reading)),r.length===0)return{sure:!1,usage:{inputTokens:0,outputTokens:0}};let R=a=>Sn.some(w=>t.graph.getNode(a)?.[w]===!0),N=t.today?.()??new Date().toISOString().slice(0,10),A=a=>Gn.map(w=>t.graph.getNode(a)?.[w]).find(w=>typeof w=="string"),J=[];if(f&&f.ids.length>1){let a=f.ids.filter(R),w=f.ids.filter(j=>!R(j)),x=w.filter(j=>(A(j)??"9999")<N.slice(0,10));a.length>0&&a.length<f.ids.length&&J.push({which:"held",part:"done",records:a,kind:f.kind,words:p(a,f.kind,"done"),close:!1}),w.length>0&&w.length<f.ids.length&&J.push({which:"held",part:"open",records:w,kind:f.kind,words:p(w,f.kind,"open"),close:!1}),x.length>0&&x.length<f.ids.length&&J.push({which:"held",part:"late",records:x,kind:f.kind,words:p(x,f.kind,"late"),close:!1})}let M=v?r:[...r,...J],$e=a=>a.part??a.which,Y={};M.length>1&&(Y.reading={type:"choice",instructions:`Someone said \u201C${i}\u201D${e.follows?`, replying to \u201C${e.follows.said}\u201D${e.follows.reading?`, which was taken as ${e.follows.reading==="itself"?"the record itself":"the records it holds"}`:""}`:""}. Which records do they mean? "This", "it" or its name alone is the record itself; "these", "all", "them", "everything", "the lot" are never the record itself but every record it holds \u2014 unless more words say which of them: "the done ones", "that are finished", "already ticked off", "completed" mean the done ones; "outstanding", "remaining", "unfinished", "still to do", "except the done ones" mean the open ones; "late" or "overdue" the late ones. A word that says the change to make ("mark these done", "close these", "finish them") says what to do, not which records. If their words pick out some records in a way none of these says ("the old ones"), choose "something else".`,criteria:{...Object.fromEntries(M.map(a=>[$e(a),a.which==="itself"?`${we(a.words)} (the ${b(a.kind)})`:we(a.words)])),else:"Something else: some other part of them"}}),Y.where={type:"choice",instructions:`Does \u201C${i}\u201D want something done to the records of this app (or an answer about them), or something done outside the app \u2014 an email or a text sent, a call made, a payment, a booking, a post somewhere?`,criteria:{inside:"Inside the app: its records, or an answer about them",outside:"Outside the app: send, call, pay, book or post somewhere else"}},Y.mood={type:"choice",instructions:`Does \u201C${i}\u201D ask something, wanting an answer in words, or tell me to do something, wanting a change made? A question can come without a question mark ("has this been done yet"), an instruction can be polite ("could you close these"), and saying who has something ("Sam's on this", "Nora has this one") tells me to give it to them.`,criteria:{asks:"Asks something: wants an answer in words",tells:"Tells me to do something: wants a change made"}};let W=a=>t.allMutations().filter(w=>w.subject&&(w.subject.kinds==="*"||w.subject.kinds.includes(a))),C=r.flatMap(a=>W(a.kind).slice(0,24).map(w=>({key:`${a.which}:${w.name}`,reading:a,mutation:w})));Y.act={type:"choice",instructions:`Which of these acts does \u201C${c}\u201D ask to be done? Judge each by what it does, not only its title: people say "close", "complete", "check off", "tick" or "finish" for an act that marks something done, "delete" for one that removes, "push" or "move" for one that changes a date or a place. A question, or "undo that", is none of them. "none" only where no act here does it.`,criteria:{...Object.fromEntries(C.map(a=>[a.key,`${a.mutation.title??a.mutation.name}: ${tt(a.mutation.description)}${nn(a.mutation,o,a.reading.kind)} \u2014 on ${a.reading.which==="itself"?`the ${b(a.reading.kind)} itself`:`each of ${a.reading.words}`}`])),none:"None of these acts does it"}};let re=he(t),D=new Set([...re,...C.flatMap(a=>Z(a.mutation.input).filter(w=>w.name!==a.mutation.subject.arg).flatMap(w=>w.kinds))]),F=t.graph.allNodes().filter(a=>D.has(a.kind)||D.has("*")),De=new Set(c.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(a=>a.length>=3).map(a=>a.slice(0,4))),te=a=>L(o.tryDefinition(a.kind),a),xe=(F.length<=25?F:F.filter(a=>te(a).toLowerCase().split(/[^\p{L}\p{N}]+/u).some(w=>w.length>=3&&De.has(w.slice(0,4))))).filter(a=>a.id!==u?.id&&!r.some(w=>w.records.includes(a.id))).slice(0,25),se=ze.test(i)?Yn(t,e.principal,D):void 0,Q=ze.test(i)&&e.principal?Qn(t,e.principal.id):void 0,ge=zn.exec(i),q=(ge?.[1]??ge?.[2])?.toLowerCase(),ce=q?Kn(t,u?.id,e.follows?.said,re):[];q&&ce.length>1&&(Y.pronoun={type:"choice",instructions:`In \u201C${i}\u201D${e.follows?`, said after \u201C${e.follows.said}\u201D`:""}, whom does \u201C${q}\u201D mean?`,criteria:{...Object.fromEntries(ce.map(a=>[`r:${a.id}`,te(a)])),else:"Someone else"}}),xe.length>0&&(Y.named={type:"choice",instructions:`Which of these does \u201C${c}\u201D name, as the one to give it to, move it to, link it with or put it on?`,criteria:{...Object.fromEntries(xe.map(a=>[`r:${a.id}`,`${te(a)} (${Le(b(a.kind))})`])),new:"Someone or something not listed here",none:"None is named"}}),Y.need={type:"choice",instructions:`If no act here can do \u201C${c}\u201D, what would each record need?`,criteria:{person:"A link to the person it is given or assigned to",other:"Something else: a field, a date, a number, a note",none:"Nothing: an act here can do it"}};let O=await n.decide({said:i,...e.follows?{replyingTo:e.follows.said}:{},readings:M.map(a=>a.words),...e.examples&&e.examples.length>0?{workedBefore:e.examples}:{}},Y),pe=de(O.answers.mood),d=Ge(i)?.owned===!0&&!/\?\s*$/.test(i)?!1:pe&&pe.chance>=.6?pe.key==="asks":Ze(i),S=de(O.answers.where);if(!d&&Ve(i)&&S?.key==="outside"&&S.chance>=.6)return{sure:!0,asks:!1,outside:Xe(t,i,u?.id),usage:O.usage};let l=de(O.answers.reading),T=M.length>1?M.find(a=>$e(a)===l?.key):M[0];if(!T){let a=de(O.answers.act),w=a&&a.key!=="none"?C.find(x=>x.key===a.key):void 0;if(!d&&w&&_e(w.mutation)&&f&&f.ids.length>1){let x=(w.mutation.title??w.mutation.name).trim().split(/\s+/)[0].toLowerCase();return{sure:!0,asks:!1,clarify:`Which of the ${f.ids.length} ${g(f.kind)}${h} should I ${x}? Say which, or \u201Call\u201D.`,usage:O.usage}}return{sure:!1,asks:d,usage:O.usage}}let $={...T,close:M.length>1&&(l?.chance??1)<Fn,chance:M.length>1?l?.chance??0:1},m=de(O.answers.act),P=de(O.answers.named),V=de(O.answers.pronoun),z=q?ce.length===1?ce[0]:V?.key.startsWith("r:")?t.graph.getNode(V.key.slice(2)):void 0:void 0,X=q&&z?{said:q,as:te(z)}:void 0,H=se??z??(P?.key.startsWith("r:")&&P.chance>=He?t.graph.getNode(P.key.slice(2)):void 0),le=Ge(i)??Ge(c),dn=le?.who&&(ze.test(le.who)?se?te(se):Q:Bn.test(le.who)?z?te(z):void 0:le.who),Ue=le?{called:le.called,...dn?{who:dn}:{},...le.owned?{owned:!0}:{}}:void 0,ie=Ue&&v?{...Ue,called:v.toLowerCase()}:Ue,En=O.answers.reading?.type==="choice"?Object.entries(O.answers.reading.probabilities).filter(([a])=>a!==l?.key).reduce((a,[,w])=>Math.max(a,w),0):0;if(!(M.length===1||(l?.chance??0)>=.5||(l?.chance??0)>=.35&&(l?.chance??0)>=1.5*En))return{sure:!1,asks:d,reading:$,usage:O.usage};let je=(a,w)=>Z(a.input).some(x=>x.name!==a.subject.arg&&(x.kinds.includes("*")||x.kinds.some(j=>w.includes(j)))),cn=[...re,...H?[H.kind]:[]];if(d||en.test(i))return{sure:!1,asks:d,reading:$,usage:O.usage};let fe=nt(O.answers.act),oe=a=>C.find(w=>w.mutation.name===a&&w.reading.which===$.which),ln=a=>!!(a&&(a.mutation.destructive||a.mutation.derived?.act==="remove")),I=m&&m.key!=="none"?m.key.slice(m.key.indexOf(":")+1):void 0,ae=m!==void 0&&m.key!=="none"&&m.chance>=He;if(!ae&&fe.length>1&&fe[0].chance+fe[1].chance>=.8&&ln(oe(fe[0].name))&&ln(oe(fe[1].name))&&(ae=!0),I&&H&&oe(I)&&!je(oe(I).mutation,[H.kind])){let a=oe(I).mutation,w=new Set(Z(a.input).map(E=>E.name)),x=Object.entries(a.input?.shape??{}).some(([E,G])=>!w.has(E)&&!G.safeParse(void 0).success&&!G.safeParse(Me(i)).success),j=P&&P.chance>=.9&&x?0:.05,U=fe.filter(E=>E.chance>=j).map(E=>oe(E.name)).find(E=>E&&E.mutation.derived?.act!=="merge"&&je(E.mutation,[H.kind]));U&&(I=U.mutation.name,ae=!0)}if(!ae&&H&&ie?.who&&(X||se||ie.owned)){let a=C.filter(w=>w.reading.which===$.which&&w.mutation.derived?.act!=="merge"&&Z(w.mutation.input).some(x=>x.name!==w.mutation.subject.arg&&Be(t,H,x.kinds)!==void 0&&re.some(j=>x.kinds.includes(j))));a.length===1&&(I=a[0].mutation.name,ae=!0)}if(!ae&&H){let a=fe.filter(w=>w.chance>=.3).map(w=>oe(w.name)).find(w=>w&&w.mutation.derived?.act!=="merge"&&Z(w.mutation.input).some(x=>x.name!==w.mutation.subject.arg&&Be(t,H,x.kinds)!==void 0));a&&(I=a.mutation.name,ae=!0)}let Je=v===void 0?et(i):void 0,fn=r.find(a=>a.which==="itself");if(Je&&fn){let a=["label","name","title"],w=C.find(U=>{let E=(ue(U.mutation)??[]).filter(G=>G!==U.mutation.subject.arg);return U.reading.which==="itself"&&E.length===1&&(a.includes(E[0])||(U.mutation.writes??[]).some(G=>a.includes(G)))}),x=w?(ue(w.mutation)??[]).find(U=>U!==w.mutation.subject.arg):void 0,j=x?(w.mutation.input?.shape??{})[x]:void 0;if(w&&x&&j?.safeParse(Je).success)return{sure:!0,reading:{...fn,close:!1},each:{act:w.mutation.name,args:{[x]:Je}},usage:O.usage}}if(I&&!oe(I)){let a=C.find(j=>j.mutation.name===I),w=j=>{let U=a?.mutation?.derived?.act,E=j.mutation.derived?.act;return U!==void 0?U===E:(j.mutation.title??j.mutation.name).split(/\s+/)[0].toLowerCase()===(a?.mutation.title??I??"").split(/\s+/)[0].toLowerCase()},x=C.find(j=>j.reading.which===$.which&&w(j));x&&(I=x.mutation.name)}let B=I&&ae?oe(I):void 0;if(B&&!(ie?.who&&!je(B.mutation,cn))){let a=(ue(B.mutation)??[]).filter(G=>G!==B.mutation.subject.arg),w=Z(B.mutation.input),x=B.mutation.input?.shape??{},j={},U=!0;for(let G of a){let ye=w.find(We=>We.name===G),hn=ye?ye.optional:x[G]?.safeParse(void 0).success??!0,gn=ye&&H?Be(t,H,ye.kinds):void 0;ye&&gn?j[G]=gn.id:!ye&&!hn&&a.filter(We=>!w.some(Un=>Un.name===We)).length===1&&Me(i)!==void 0&&x[G]?.safeParse(Me(i)).success?j[G]=Me(i):hn||(U=!1)}if(B.mutation.derived?.act==="edit"&&Object.keys(j).length===0&&(U=!1),!U)return{sure:!1,reading:$,...X?{taken:X}:{},act:B.mutation.name,usage:O.usage};let E=M.length===1||(l?.chance??0)>=Ke(B.mutation,i);return _e(B.mutation)&&$.records.length>1&&(!E||Qe(i,$))?{sure:!0,reading:$,clarify:Vn(t,B.mutation.title??B.mutation.name,$),usage:O.usage}:{sure:!0,reading:$,...X?{taken:X}:{},each:{act:B.mutation.name,args:j},usage:O.usage}}let un=de(O.answers.need),In=C.some(a=>a.reading.which===$.which&&je(a.mutation,cn));if(ie?.who&&!In&&(un?.key==="person"&&un.chance>=He||se!==void 0||Q!==void 0||X!==void 0||ie.owned===!0)){let a=ie.who??(H&&re.includes(H.kind)?te(H):void 0);if(!a)return{sure:!1,reading:$,usage:O.usage};let w=v?`${we(g($.kind))} have no ${ie.called}.`:`${we(g($.kind))} have no one ${ie.called} them.`;return{sure:!0,reading:$,...X?{taken:X}:{},missing:{said:w,need:{link:{on:$.kind,called:ie.called,to:"person"}},who:a},text:w,usage:O.usage}}return{sure:!1,reading:$,...X?{taken:X}:{},...I&&m&&m.chance>=.3?{act:I}:{},usage:O.usage}}var ze=/\b(me|my|mine|myself)\b/i,zn=/\b(?:to|off|from|for|with)\s+(her|him|them|that person|whoever)\b|\b(?:take|put|move|swap|drop)\s+(her|him)\b/i,Bn=/^(her|him|them|they|that person|whoever)$/i;function Yn(n,e,t){if(!e)return;let s=n.graph.getNode(e.id),i=s?L(n.schema.tryDefinition(s.kind),s).toLowerCase():void 0;return(i?n.graph.allNodes().find(c=>c.id!==e.id&&t.has(c.kind)&&L(n.schema.tryDefinition(c.kind),c).toLowerCase()===i):void 0)??(s&&t.has(s.kind),s)}function Qn(n,e){let t=n.graph.getNode(e);return t?L(n.schema.tryDefinition(t.kind),t):void 0}function Kn(n,e,t,s){let i=n.schema,o=e?[...n.graph.in(e),...n.graph.out(e)].filter(r=>s.includes(r.kind)):[],c=(t??"").toLowerCase(),y=[...c?n.graph.allNodes().filter(r=>s.includes(r.kind)&&L(i.tryDefinition(r.kind),r).toLowerCase().split(/\s+/).some(h=>h.length>=3&&new RegExp(`\\b${h.replace(/[^\p{L}\p{N}]/gu,"")}\\b`,"u").test(c))):[],...o],k=r=>L(i.tryDefinition(r.kind),r).toLowerCase();return y.filter((r,h)=>y.findIndex(g=>k(g)===k(r))===h).slice(0,8)}function Be(n,e,t){if(t.includes("*")||t.includes(e.kind))return e;let s=n.schema,i=L(s.tryDefinition(e.kind),n.graph.getNode(e.id)).toLowerCase();return n.graph.allNodes().find(o=>t.includes(o.kind)&&L(s.tryDefinition(o.kind),o).toLowerCase()===i)}function vn(n){let e=n.split(/\s*(?:,\s*and then|,\s*then|\band then\b|;|\bthen\b|,?\s+and\s+)\s*/i).map(i=>i.trim()).filter(Boolean);if(e.length<2||e.length>3)return[n];let t=/^(the|a|an|my|our|your|this|these|that|those|all|every|each|some|it|them|they|he|she|i|we|you|to|for|with|on|in|at|by|of|from|tomorrow|today|tonight|monday|tuesday|wednesday|thursday|friday|saturday|sunday)$/i,s=i=>{let o=i.split(/\s+/);return o.length>=2&&/^[a-z]/.test(o[0])&&!t.test(o[0])};return e.every(s)?e:[n]}function Oe(n,e=!1){let t=n.toLowerCase(),s=/\b(done|finished|completed|complete|closed|ticked|checked)( off)? (ones?|tasks?|items?|stuff|things|bits)\b/.test(t)||/\b(ones?|tasks?|items?|things|stuff) (i'?ve|we'?ve|i have|we have|that are|that'?s|already) (done|finished|completed|closed|ticked off)\b/.test(t)||/\balready (done|finished|completed)\b/.test(t)||/\bthe (finished|completed)\b/.test(t),i=/\b(outstanding|remaining|unfinished|undone|incomplete|pending)\b/.test(t)||/\b(still to do|left to do|not done|not finished|not yet done)\b/.test(t)||/\b(open) (ones?|tasks?|items?|stuff|things)\b/.test(t)||e&&/\bopen\b/.test(t);return s&&i?{open:!1,finished:!1}:{open:i,finished:s}}function $n(n){let{open:e,finished:t}=Oe(n);return e||t?!0:xn(n)?!1:/\b(all|every|each|everything|the lot|the whole (list|lot)|every one|both|these|those)\b/i.test(n)}function xn(n){let e=/\bthe ([a-z]+) (ones?|tasks?|items?|stuff|things|shifts?|songs?)\b/i.exec(n)?.[1]?.toLowerCase();return e!==void 0&&!["other","rest","whole","same"].includes(e)&&!Oe(`the ${e} ones`).open&&!Oe(`the ${e} ones`).finished}function Ke(n,e){return n.derived?.act==="archive"&&n.destructive!==!0&&/\b(these|those|all|everything|every one|each|them|the lot|the whole (list|lot))\b/i.test(e)?.75:.9}function _e(n){return n.destructive===!0||n.derived?.act==="remove"||n.derived?.act==="archive"}function Vn(n,e,t){let s=n.schema,i=e.trim().split(/\s+/)[0].toLowerCase(),o=h=>Sn.some(g=>n.graph.getNode(h)?.[g]===!0),c=t.records.filter(o),u=(s.tryDefinition(t.kind)?.noun??t.kind).toLowerCase(),y=K(s,t.kind).toLowerCase(),k=/ (in .+)$/.exec(t.words)?.[1],r=`all ${t.records.length} ${y}${k?` ${k}`:""}`;return c.length>0&&c.length<t.records.length?`Should I ${i} the ${c.length} done ${c.length===1?u:y}, or ${r}?`:`Should I ${i} ${r}? Say \u201Call\u201D to go ahead, or say which.`}function Ve(n){let e=/^\s*(?:please\s+|pls\s+|could you\s+|can you\s+|would you\s+|can we\s+|let'?s\s+)?(e-?mail|mail|text|sms|message|whatsapp|call|phone|ring|dial|pay|venmo|book|reserve|post|tweet|share)\b(.*)$/i.exec(n);return e!==null&&!/^\s+(?:it|this|that|this one)\s+(?:[A-Z“"']|as\b|to\b)/.test(e[2]??"")}var Xn=[[/\b(e-?mail|mail)\b/i,"send email"],[/\b(text|sms|message|whatsapp|dm)\b/i,"send messages"],[/\b(call|phone|ring|dial)\b/i,"make calls"],[/\b(pay|venmo|transfer|invoice)\b/i,"make payments"],[/\b(book|reserve)\b/i,"book things"],[/\b(post|tweet|share)\b/i,"post outside this app"]];function Xe(n,e,t){let s=Xn.find(([c])=>c.test(e))?.[1]??"do things outside this app",i=t?n.graph.getNode(t):void 0,o=i?Object.values(i).find(c=>typeof c=="string"&&(/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(c)||/^https?:\/\//.test(c))):void 0;return o?`I can't ${s} from here, but its ${o.includes("@")&&!o.startsWith("http")?"email":"link"} is ${o} \u2014 open it to do that.`:`I can't ${s} from here: this app keeps your records, and doing that happens outside it.`}function Ze(n){return Zn(n)?!1:/\?\s*$/.test(n)||/^\s*(who|whom|whose|what|whats|what's|when|where|which|why|how|is|are|was|were|can|could|should|any|anything|tell me|show me|list)\b/i.test(n)||/^\s*(do|does|did)\s+(you|we|i|they|it|he|she|anyone|anybody|any)\b/i.test(n)}function Zn(n){let e=n.trim().toLowerCase();return!!(/^(please|pls|kindly)\b/.test(e)||/^(could|can|would|will) (you|we|u)\s+(please\s+)?(?!tell|say|explain|show me what|see)\w+/.test(e)&&!/^(could|can|would|will) (you|we) (be|have)\b/.test(e)||/^(i'?d like|i would like|i want|i need|let'?s|we should|we need to)\b/.test(e)||/^[\p{L}'’]+(\s[\p{L}'’]+)?\s+(should|needs to|need to|has to|have to|ought to)\s+(be\s+)?\w+/u.test(e)&&!/^(what|who|which|when|where|why|how|is|are|do|does)\b/.test(e))}function et(n){let e=n.trim().replace(/[.!]+$/,""),t=[/^(?:the\s+|its\s+|this\s+|list\s+|task\s+)*name\s+should\s+be\s+["“']?(.+?)["”']?$/i,/^(?:please\s+)?call\s+(?:this one|this list|this task|this shift|this song|it|this)\s+["“']?(.+?)["”']?$/i,/^["“']?(.+?)["”']?\s+is\s+a\s+better\s+name$/i,/^(?:please\s+)?(?:re)?name\s+(?:this one|this list|this task|this shift|this song|it|this)\s+(?:to\s+|as\s+)?["“']?(.+?)["”']?$/i,/^(?:let'?s\s+)?call\s+(?:it|this)\s+["“']?(.+?)["”']?$/i];for(let s of t){let i=s.exec(e)?.[1]?.trim();if(i)return i}}var en=/^\s*(undo|take (that|it) back|revert|go back)\b/i;function Me(n){let e=/\b(?:to|as)\s+["“']?(.+?)["”']?\s*[.!]?\s*$/i.exec(n)?.[1]?.trim();return e&&e.length>0?e:void 0}function nt(n){return n?.type!=="choice"?[]:Object.entries(n.probabilities).filter(([e])=>e!=="none").sort((e,t)=>t[1]-e[1]).map(([e,t])=>({name:e.slice(e.indexOf(":")+1),chance:t}))}function tt(n){let e=n?.trim();return e?`${e}${/[.!?]$/.test(e)?"":"."} `:""}function nn(n,e,t){let s=[],i=(ue(n)??[]).filter(r=>r!==n.subject?.arg),o=Z(n.input).filter(r=>r.name!==n.subject?.arg),c=e.tryDefinition(t)?.fields?.shape??{},u=r=>c[r]?._zod?.def?.type==="optional"?c[r]?._zod?.def?.innerType?._zod?.def?.type:c[r]?._zod?.def?.type,y=n.derived?.act;y==="remove"?s.push("removes it"):y==="archive"?s.push("sets it aside in the archive"):y==="unarchive"?s.push("brings it back from the archive"):y==="merge"?s.push("merges it into another"):y==="edit"&&s.push("changes any of its fields to values given");for(let r of n.writes??[])n.sets&&r in n.sets?s.push(`sets ${r} to ${String(n.sets[r])}`):i.includes(r)?s.push(`sets ${r} to a value given`):u(r)==="boolean"?s.push(`sets ${r} yes or no`):s.push(`changes ${r}`);for(let r of i)!(n.writes??[]).includes(r)&&!o.some(h=>h.name===r)&&y!=="edit"&&s.push(`takes ${r}`);let k=[...new Set(o.flatMap(r=>r.kinds))].filter(r=>r!=="*").join(" or ");return(n.connects?.length??0)>0&&(n.severs?.length??0)>0?s.push(`moves it to another ${k||"record"}`):(n.connects?.length??0)>0?s.push(`links it to ${Le(k||"record")}`):(n.severs?.length??0)>0&&s.push(`unlinks it from ${Le(k||"record")}`),n.destructive&&y!=="remove"&&s.push("removes it for good"),(n.creates?.length??0)>0&&s.push(`adds a new ${n.creates.join(" or ")}`),s.length>0?`(It ${s.join(", ")}.)`:""}var st=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],it=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function tn(n){let e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(n);if(!e)return;let t=new Date(Date.UTC(Number(e[1]),Number(e[2])-1,Number(e[3])));return`${st[t.getUTCDay()]}, ${it[t.getUTCMonth()]} ${t.getUTCDate()}`}function sn(n,e){let t=n.schema;if(e.records.length===1&&typeof e.act.describe=="function"&&e.act.subject)try{let f=e.act.describe({...e.args,[e.act.subject.arg]:e.records[0]},n.graph);if(typeof f=="string"&&f.trim()){let p=he(n),v=[e.records[0]].filter(A=>n.graph.getNode(A)!==void 0).map(A=>n.graph.getNode(A)).filter(A=>!p.includes(A.kind)).map(A=>L(t.tryDefinition(A.kind),A)).sort((A,J)=>J.length-A.length),R=f.trim().replace(/"([^"]*)"/g,"\u201C$1\u201D");for(let A of v)R.includes(`\u201C${A}\u201D`)||(R=R.replace(A,`\u201C${A}\u201D`));let N=R.replace(/\b(\d{4}-\d{2}-\d{2})\b/g,A=>tn(A)??A).replace(/[.!]+$/,"");return`${N.charAt(0).toUpperCase()}${N.slice(1)}.`}}catch{}let s=f=>{let p=n.graph.getNode(f);return p?L(t.tryDefinition(p.kind),p):void 0},i=Z(e.act.input),o=e.act.subject?.arg,c=Object.entries(e.args).filter(([f,p])=>f!==o&&p!==void 0&&p!==null&&p!=="").map(([f,p])=>{if(i.find(R=>R.name===f)&&typeof p=="string"){let R=n.graph.getNode(p),N=s(p)??p;return{arg:f,said:R?N:p,ref:!0}}return typeof p=="string"?{arg:f,said:tn(p)??`\u201C${p}\u201D`,ref:!1}:{arg:f,said:String(p),ref:!1}}),y=(e.records[0]?n.graph.getNode(e.records[0]):void 0)?.kind,k=y?(t.tryDefinition(y)?.noun??y).toLowerCase():"record",r=e.records.length,h=e.itself&&r===1&&e.records[0]?s(e.records[0])?`\u201C${s(e.records[0])}\u201D`:"it":`the ${r}${e.narrowed?` ${e.narrowed}`:""} ${r===1?k:y?K(t,y).toLowerCase():"records"}${e.where?` ${e.where}`:""}`,g=(e.act.title??e.act.name).trim().replace(/[.!]+$/,""),b=/\b(it|this|the (?:task|list|shift|record|song|item))\b/i;if(/^(they|it|this|she|he|somebody|someone)\b/i.test(g))return g=g.replace(/^(they|it|this|she|he|somebody|someone)\b/i,h).replace(/^(\S.*?)\s+\b(have|are)\b/i,(f,p,v)=>`${p} ${r===1?v.toLowerCase()==="have"?"has":"is":v}`),`${g.charAt(0).toUpperCase()}${g.slice(1)}.`;g=b.test(g)?g.replace(b,h):/^\S+ the \w+$/i.test(g)?`${g} of ${h}`:g.replace(/^(\S+)/,`$1 ${h}`);for(let f of c)/\b(?:to|into|on) another \w+/i.test(g)?g=g.replace(/\b(to|into|on) another \w+/i,`$1 ${f.said}`):/\banother \w+/i.test(g)?g=g.replace(/\banother \w+/i,f.said):g=`${g} ${f.ref&&!/\bto\b/i.test(g)&&/^(cover|assign|give)/i.test(g)?"with":"to"} ${f.said}`;return`${g.charAt(0).toUpperCase()}${g.slice(1)}.`}function On(n,e,t){let s=n.schema,i=he(n),o=h=>{let g=n.graph.getNode(h);if(!g)return h;let b=L(s.tryDefinition(g.kind),g);return i.includes(g.kind)?b:`\u201C${b}\u201D`},c=e.writes?.[0],u=t[0]?n.graph.getNode(t[0]):void 0,y=c&&u?u[c]:void 0,k=t.length===1?o(t[0]):`All ${t.length} of them`,r=t.length===1?"is":"are";return c&&typeof y=="boolean"?`Nothing to change: ${k} ${r} already ${y?"":"not "}${c.replace(/[A-Z]/g,h=>` ${h.toLowerCase()}`)}.`:c&&(typeof y=="string"||typeof y=="number")?`Nothing to change: ${t.length===1?`${k}'s`:"their"} ${c.replace(/[A-Z]/g,h=>` ${h.toLowerCase()}`)} ${r==="is"?"is":"are"} already ${tn(String(y))??y}.`:`Nothing to change: ${k} ${r} already as that would leave ${t.length===1?"it":"them"}.`}var Nn="I can't do that here: nothing in this app does what you asked. Try saying it another way.";function Cn(n){return/\b(can'?t|cannot|couldn'?t|won'?t|not|no|isn'?t|doesn'?t|don'?t|unable|nothing|never)\b/i.test(n)?!1:/\b(is|are|was|were|has been|have been|got|gets)\s+(now\s+)?(\w+ed|done|taken|set|put|given|made|gone|off|out|away|moved|removed)\b/i.test(n)||/^(i'?ve|i have|done|marked|moved|removed|archived|renamed|assigned|added|scheduled|deleted|dropped|finished|closed|updated|changed|set|put|took|taken)\b/i.test(n.trim())||/\b(i'?ve|i have)\s+\w+ed\b/i.test(n)}var ot=/\b(not in (this|the) app|isn'?t in (this|the) app|is not in (this|the) app|not (yet )?(a|one of the) (user|member|person|people|volunteer|record)s?|doesn'?t exist|does not exist|no one (called|named)|nobody (called|named)|not found|no such|there is no|there'?s no|no (user|person|member|volunteer|record|one) (called|named))\b/i;function on(n,e){if(!ot.test(e))return[];let t=n.schema,s=he(n),i=e.toLowerCase();return n.graph.allNodes().flatMap(o=>{let c=L(t.tryDefinition(o.kind),o),u=c.split(/\s+/)[0];return c.length>=3&&(i.includes(c.toLowerCase())||s.includes(o.kind)&&u.length>=3&&new RegExp(`\\b${u.toLowerCase().replace(/[^\p{L}\p{N}]/gu,"")}\\b`,"u").test(i))?[{id:o.id,name:c,kind:o.kind}]:[]}).slice(0,5)}function Te(n){if(!n.off)return n.fast??(n.decide?{model:n.name??"decide",decide:n.decide}:void 0)}function Re(n){if(n.off)return;if(n.thinking)return n.thinking;let e=n.name??"model";if(n.complete){let t=n.complete;return{model:e,think:({system:s,prompt:i})=>t({prompt:i,system:s})}}if(n.turn){let t=n.turn;return{model:e,think:async({system:s,prompt:i})=>({text:await t({system:s,messages:[{role:"user",content:i}],tools:[],call:async()=>({error:"No tools here."})})})}}}var Ce=(n,e,t)=>n?e/1e6*(n.inputPerMillion??0)+t/1e6*(n.outputPerMillion??0):void 0,rt=()=>`ai-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;function at(n,e,t=[]){let s=i=>{let o=n.graph.getNode(i);return o?L(n.schema.tryDefinition(o.kind),o):"a record"};switch(e.on){case"record":return s(e.id);case"field":return`${s(e.id)} \xB7 ${e.field}`;case"selection":return`${e.ids.length} records`;case"list":return n.schema.tryDefinition(e.kind)?K(n.schema,e.kind):e.kind;case"lens":case"place":return t.find(i=>i.as===e.place)?.title??(e.place==="home"?"Home":e.place);case"act":return e.act}}var jn=n=>n.type!=="act"||n.asks.length===0,Ee=(n,e)=>({id:n.id,type:n.type,label:n.label,...e!==void 0?{confidence:e}:{}});function be(n,e){let t=e.interaction??rt(),s=pn(e.store,e.target,{principal:e.principal,...e.acts?{acts:e.acts}:{},...e.places?{places:e.places}:{}}),i=yn(e.store,e.target,{principal:e.principal,...e.place?{place:e.place}:{},...e.selection?{selection:e.selection}:{},...e.purpose?{purpose:e.purpose}:{}}),o=[];return{id:t,catalog:s,state:i,entry:{id:t,at:new Date().toISOString(),by:e.by??e.principal,target:e.target,targetLabel:at(e.store,e.target,e.places)},usage:o,meter:c=>{o.push(c),n.meter?.({...c,interaction:t})}}}async function Se(n,e,t,s){let i=await n.decide(e,t),{inputTokens:o,outputTokens:c}=i.usage,u=Ce(n.price,o,c);return s({tier:"fast",model:n.model,inputTokens:o,outputTokens:c,...u!==void 0?{costUsd:u}:{}}),i.answers}async function ne(n,e,t,s,i){let o=await n.think({system:e,prompt:t,state:s.state,catalog:s.catalog}),c=o.usage?.inputTokens,u=o.usage?.outputTokens,y=o.usage?.costUsd??(c!==void 0?Ce(n.price,c,u??0):void 0);return i({tier:"thinking",model:n.model,...c!==void 0?{inputTokens:c}:{},...u!==void 0?{outputTokens:u}:{},...y!==void 0?{costUsd:y}:{}}),mn(o.text)}function Ae(n,e){let t=new Map(n.map((s,i)=>[`c${i+1}`,s]));return{question:{type:"choice",instructions:e,criteria:Object.fromEntries([...t].map(([s,i])=>[s,`${i.label} \u2014 ${i.description}`]))},of:s=>t.get(s)}}function Pe(n,e,t){if(n?.type!=="choice")return[];let s=n,i=Object.entries(s.probabilities).sort((o,c)=>c[1]-o[1]);return i.some(([o])=>o===s.choice)||i.unshift([s.choice,s.confidence]),i.flatMap(([o,c])=>{let u=e(o);return u?[{candidate:u,confidence:c}]:[]}).slice(0,t)}var _=(n,e,t,s)=>({interaction:{...n.entry,ask:{kind:t,said:e??""},offered:[],outcome:"failed",failed:s,usage:[...n.usage]},offers:[]}),ve="AI isn't on here.";async function Et(n,e,t=3){let s=be(n,e),i=e.said??"Suggest",o=s.catalog.candidates.filter(jn).slice(0,24);if(o.length===0)return{interaction:{...s.entry,ask:{kind:"suggest",said:i},offered:[],outcome:"offered",usage:[]},offers:[]};let c=Te(n),u=Re(n),y=[];try{if(c){let{question:k,of:r}=Ae(o,"Which of these would the person most likely want to do next, here?"),h=await Se(c,{...s.state,candidates:o.map(g=>({id:g.id,type:g.type,says:g.description}))},{next:k},s.meter);y=Pe(h.next,r,t)}else if(u){let k=await ne(u,'You suggest what a person most likely wants to do next in an app. Answer only JSON: {"pick": [candidate ids, best first]}. Pick only ids from the candidates.',JSON.stringify({state:s.state,candidates:o.map(h=>({id:h.id,says:h.description}))}),s,s.meter);y=(Array.isArray(k?.pick)?k.pick.filter(h=>typeof h=="string"):[]).flatMap(h=>o.filter(g=>g.id===h)).slice(0,t).map(h=>({candidate:h}))}else return _(s,i,"suggest",ve)}catch(k){return _(s,i,"suggest",k instanceof Error?k.message:String(k))}return{interaction:{...s.entry,ask:{kind:"suggest",said:i},offered:y.map(({candidate:k,confidence:r})=>Ee(k,r)),outcome:"offered",usage:[...s.usage]},offers:y.map(({candidate:k})=>k)}}var dt=n=>`several:${n}`;async function It(n,e,t=2){let s=be(n,{...e,acts:[]}),i=e.said??"Suggest for the chosen",o=e.target.on==="selection"?e.target.ids.length:1,u=[...e.shared.map(r=>({type:"act",id:dt(r.id),label:r.label,description:`${r.label}, for all ${o} chosen`,mutation:r.mutation,args:r.args,asks:[]})),...s.catalog.candidates.filter(r=>r.type==="panel"||r.type==="place")].slice(0,24),y=Te(n);if(!y)return _(s,i,"suggest",ve);if(u.length===0)return{interaction:{...s.entry,ask:{kind:"suggest",said:i},offered:[],outcome:"offered",usage:[]},offers:[]};let k;try{let{question:r,of:h}=Ae(u,`Which of these would the person most likely want to do next with the ${o} records they chose together?`),g=await Se(y,{...s.state,candidates:u.map(b=>({id:b.id,type:b.type,says:b.description}))},{next:r},s.meter);k=Pe(g.next,h,t).filter((b,f)=>f===0||b.confidence>=ct)}catch(r){return _(s,i,"suggest",r instanceof Error?r.message:String(r))}return{interaction:{...s.entry,ask:{kind:"suggest",said:i},offered:k.map(({candidate:r,confidence:h})=>Ee(r,h)),outcome:"offered",usage:[...s.usage]},offers:k.map(({candidate:r})=>r)}}var ct=.25;async function Ut(n,e){let t=be(n,e),s=e.said??"Fill in",i=t.catalog.candidates.filter(h=>h.type==="fill"),o=new Map;for(let h of i)o.set(h.field,[...o.get(h.field)??[],h]);if(o.size===0)return{interaction:{...t.entry,ask:{kind:"fill",said:s},offered:[],outcome:"offered",usage:[]},offers:[]};let c=Te(n),u=Re(n),y=[];try{if(c){let h=[...o].map(([b,f],p)=>({key:`f${p+1}`,field:b,...Ae(f,`Which value fits "${b}" best for this record?`)})),g=await Se(c,t.state,Object.fromEntries(h.map(b=>[b.key,b.question])),t.meter);for(let b of h){let f=!lt(e.store,e.target,b.field)&&ft(e.store,e.target,b.field)!=="one";y.push(...Pe(g[b.key],b.of,f?3:1).filter((p,v)=>v===0||p.confidence>=.4))}}else if(u){let h=await ne(u,`You fill in a record's fields in an app. Answer only JSON: {"fills": [candidate ids]}, at most one per field, only ids from the candidates.`,JSON.stringify({state:t.state,candidates:i.map(f=>({id:f.id,says:f.description}))}),t,t.meter),g=Array.isArray(h?.fills)?h.fills.filter(f=>typeof f=="string"):[],b=new Set;for(let f of g){let p=i.find(v=>v.id===f);p?.type==="fill"&&!b.has(p.field)&&(b.add(p.field),y.push({candidate:p}))}}else return _(t,s,"fill",ve)}catch(h){return _(t,s,"fill",h instanceof Error?h.message:String(h))}let k=t.usage.at(-1)?.model,r=Ie(e.store,{interaction:t.id,target:e.target,basis:s,...k?{model:k}:{},proposals:y.flatMap(({candidate:h,confidence:g})=>h.type==="fill"?[{id:h.id,label:h.label,said:h.description,call:h.call,record:h.record,field:h.field,...g!==void 0?{confidence:g}:{}}]:[])},e.principal);return{interaction:{...t.entry,ask:{kind:"fill",said:s},offered:r.proposals.map(h=>({id:h.id,type:"fill",label:h.label,...h.confidence!==void 0?{confidence:h.confidence}:{}})),outcome:"offered",usage:[...t.usage]},offers:[],...r.proposals.length>0?{ghost:r}:{}}}function lt(n,e,t){let s=e.on==="record"||e.on==="field"?e.id:void 0,i=s?n.graph.getNode(s)?.kind:void 0,o=(i?n.schema.tryDefinition(i)?.fields?.shape:void 0)??{};return t in o}function ft(n,e,t){let s=e.on==="record"||e.on==="field"?e.id:void 0,i=s?n.graph.getNode(s)?.kind:void 0;return i?n.schema.tryDefinition(i)?.edges?.[t]?.cardinality:void 0}async function Jt(n,e){let t=be(n,e),s=e.said??"Add one",i=new Set(e.store.allMutations().filter(r=>(r.creates??[]).length>0).map(r=>r.name)),o=t.catalog.candidates.filter(r=>r.type==="act"&&r.asks.length>0&&i.has(r.mutation));if(o.length===0)return _(t,s,"record","Nothing here makes a record.");let c=Re(n);if(!c)return _(t,s,"record",ve);let u;try{let r=await ne(c,'You propose one new record for an app by filling in an act. Answer only JSON: {"act": a candidate id, "args": {argument: value}}. Use only the candidates, and fill every argument the act asks for with a value that fits the state.',JSON.stringify({ask:s,state:t.state,candidates:o.map(b=>({id:b.id,says:b.description,asks:b.asks}))}),t,t.meter),h=o.find(b=>b.id===r?.act),g=typeof r?.args=="object"&&r.args!==null?r.args:{};h&&(u={act:h,args:Object.fromEntries(Object.entries(g).filter(([b])=>h.asks.includes(b)))})}catch(r){return _(t,s,"record",r instanceof Error?r.message:String(r))}if(!u)return _(t,s,"record","The model named no act this app has here.");let y=t.usage.at(-1)?.model,k=Ie(e.store,{interaction:t.id,target:e.target,basis:s,...y?{model:y}:{},proposals:[{id:u.act.id,label:u.act.label,said:u.act.description,call:{name:u.act.mutation,args:{...u.act.args,...u.args}}}]},e.principal);return k.proposals.length===0?_(t,s,"record","What the model proposed could not be made here."):{interaction:{...t.entry,ask:{kind:"record",said:s},offered:k.proposals.map(r=>({id:r.id,type:"act",label:r.said})),outcome:"offered",usage:[...t.usage]},offers:[u.act],ghost:k}}async function Wt(n,e){let t=be(n,e),s=e.said??"Make a panel",i=t.catalog.candidates.filter(r=>r.type==="panel");if(i.length===0)return _(t,s,"panel","Nothing here can be drawn as a panel.");let o=Te(n),c=Re(n),u;try{if(c){let r=await ne(c,'You choose a panel to draw in an app. Answer only JSON: {"panel": a candidate id, "title": a short title}. Choose only among the candidates.',JSON.stringify({ask:s,state:t.state,candidates:i.map(g=>({id:g.id,says:g.description}))}),t,t.meter),h=i.find(g=>g.id===r?.panel);h&&(u={panel:h,...typeof r?.title=="string"&&r.title.trim()?{title:r.title.trim().slice(0,60)}:{}})}else if(o){let{question:r,of:h}=Ae(i,`Which panel answers this best: ${s}`),g=Pe((await Se(o,t.state,{panel:r},t.meter)).panel,h,1)[0];g?.candidate.type==="panel"&&(u={panel:g.candidate,confidence:g.confidence})}else return _(t,s,"panel",ve)}catch(r){return _(t,s,"panel",r instanceof Error?r.message:String(r))}if(!u)return _(t,s,"panel","The model named no panel this app can draw.");let y=u.title??u.panel.label,k={title:y,recipe:{...u.panel.panel,title:y}};return{interaction:{...t.entry,ask:{kind:"panel",said:s},offered:[Ee(u.panel,u.confidence)],outcome:"drawn",panel:k,usage:[...t.usage]},offers:[u.panel],panel:k}}function ut(n){return n.off?void 0:n.answer}var ke=`You answer a person who typed words about what they are looking at in an app, from the state given and nothing else: "facts" says the fields and links of each record ("covered by Ada Nowak", "holds it: This week"), as they see them \u2014 answer from them, and never say a record has no link the facts show. Before answering, look through "facts" for the link or field the words are about \u2014 what it waits for, who covers it, what holds it, when it is due \u2014 and name it: "what is blocking this" is answered by its "waits for" links, by name. A link the facts do not show is not there: say plainly that there is none, never borrow one from another record, and answer what was asked \u2014 a count by counting, a day by its day. Answer only JSON: {"answer": one to three short, whole sentences written to the person, "pick": [candidate ids that act on the answer, best first, at most three]}. Pick only ids from the candidates, and none when nothing fits. Never say an id to the person. Where "members" are given and the person asks for something done to them, answer "each": {"act": the name of one of "member_acts", "args": every value it asks for, by name, dates as YYYY-MM-DD counted from "today"; the facts already say each day against today, so trust those} \u2014 one act over every member, as one change. Judge an act by what it does ("does"), not only its title: "close", "complete", "check off", "tick" and "finish" are an act that marks something done; "delete" one that removes; "push", "move" and "postpone" one that changes a date or a place. Where "fast_leaned_to" names an act, it is likely the one: fill its values. When the person tells it to do something, answer "each" (with a short "answer" saying what it will do): nothing is done until they accept, so never say in words that it is done, and never ask them to confirm ("Move it to Friday?"): the card asks them, so answer "each". Where "people" maps a word like "her" or "me" to a name, that is who they mean. Only where no act among "member_acts" or the candidates does what they ask, because the app has no field or link for it, answer "lacks": one whole sentence to the person saying what the app is missing (never an id, never a note to yourself), and "need": what it would need \u2014 {"link": {"on": the kind of the records, "called": what the link is called in their words, like "assigned to", "to": the kind it points to, or a noun for one the app lacks}} or {"field": {"on": the kind, "called": its name in their words, "type": "string", "number", "date" or "boolean"}} \u2014 with "who": the name of the record their words name (for a link) or "value": the value they give (for a field). When they ask for a change the app has no field or link for ("make these urgent", "give these a priority"), answer "lacks" and "need", never only "answer". A question is answered in "answer", never with "each" or "lacks"; so is "undo that", which the app's own Undo does.`,ht='Where nothing in the state or the catalog answers the words \u2014 the app keeps no such thing \u2014 do not answer only that you found nothing: reply with "lacks", one whole sentence to the person saying what this app does not keep ("This app keeps no budgets."), and "need" where one field or link on these records would hold it ({"field": {"on": kind, "called": name, "type": "string" | "number" | "date" | "boolean"}} or {"link": {"on": kind, "called": name, "to": kind}}). This holds for a question too.',gt='Where nothing in "facts" or "state" answers the words \u2014 the app keeps no such thing \u2014 do not answer only that you found nothing: answer "lacks", one whole sentence to the person saying what this app does not keep ("This app keeps no budgets."), and "need" where one field or link on these records would hold it. This holds for a question too.';async function Ft(n,e){let t=be(n,e),s=e.said.trim(),i=ut(n),o=Te(n),c=[],u=async(d,S,l)=>{let T=Date.now();try{return await l()}finally{c.push({stage:d,ms:Date.now()-T,model:S})}},y={...t,entry:t.entry},k,r,h,g;if(o&&s&&!i&&(e.target.on==="record"||e.target.on==="list"||e.target.on==="lens"||e.target.on==="selection"))try{let d=$=>An(o,{store:e.store,target:e.target,said:$,...e.principal.id?{principal:{id:e.principal.id}}:{},...e.members?{members:e.members}:{},...e.follows?{follows:e.follows}:{},...e.where?{where:e.where}:{},...e.examples?{examples:e.examples}:{}}),S=vn(s);if(S.length>1){let $=await u("fast",o.model,()=>Promise.all(S.map(d)));for(let m of $){let P=Ce(o.price,m.usage.inputTokens,m.usage.outputTokens);y.meter({tier:"fast",model:o.model,inputTokens:m.usage.inputTokens,outputTokens:m.usage.outputTokens,...P!==void 0?{costUsd:P}:{}})}if($.every(m=>m.sure&&m.each&&!m.asks))return Rn(e,y,s,$,c)}let l=await u("fast",o.model,()=>d(s)),T=Ce(o.price,l.usage.inputTokens,l.usage.outputTokens);if(y.meter({tier:"fast",model:o.model,inputTokens:l.usage.inputTokens,outputTokens:l.usage.outputTokens,...T!==void 0?{costUsd:T}:{}}),k=l.reading,r=l.act,h=l.asks,g=l.taken,l.sure&&(l.each||l.missing||l.clarify||l.outside))return Rn(e,y,s,l,c)}catch{}let b=()=>h??Ze(s),f=n.off?void 0:n.light,p=Re(n),v=f??p,R=y.catalog.candidates.filter(d=>jn(d)||d.type==="panel"||d.type==="place"||d.type==="record").slice(0,32),N;try{N=o&&(i||v)&&s?await wt(o,s,y,R):_n(y,R)}catch(d){return _(y,s,"ask",d instanceof Error?d.message:String(d))}let A={...y,state:N.state,catalog:{...y.catalog,candidates:N.choices},entry:{...y.entry,context:N.context}},J=N.choices,M=(k?.records??e.members??[]).flatMap(d=>{let S=e.store.graph.getNode(d);return S?[S]:[]}).slice(0,60),$e=new Set(M.map(d=>d.kind)),Y=e.store.allMutations().flatMap(d=>{let S=d.subject?.kinds;if(!d.subject||!(S==="*"||S.some(T=>$e.has(T))))return[];let l=[...$e].find(T=>S==="*"||S.includes(T));return[{name:d.name,title:d.title??d.name,does:`${d.description??""} ${nn(d,e.store.schema,l)}`.trim(),subjectArg:d.subject.arg,asks:(ue(d)??[]).filter(T=>T!==d.subject.arg)}]}),W,C,re,D="",F=[],De=d=>d.flatMap(S=>J.filter(l=>l.id===S)).slice(0,3).map(S=>({candidate:S}));try{if(i){let d=await i.answer({said:s,target:e.target,targetLabel:A.entry.targetLabel,state:A.state,catalog:{target:A.catalog.target,candidates:J},...e.follows?{follows:e.follows}:{},...n.couldNotFind?{couldNotFind:ht}:{}}),S=d.usage?.inputTokens,l=d.usage?.outputTokens,T=d.usage?.costUsd??(S!==void 0?Ce(i.price,S,l??0):void 0);if(A.meter({tier:"thinking",model:i.model,...S!==void 0?{inputTokens:S}:{},...l!==void 0?{outputTokens:l}:{},...T!==void 0?{costUsd:T}:{}}),D=typeof d.text=="string"?d.text.trim():"",F=De(d.pick??[]),typeof d.lacks=="string"&&d.lacks.trim()){let $=Pn(d.need),m=d.lacks.trim();C={said:ee(m)?m:$?Tn(e.store.schema,$):me,...$?{need:$}:{}},D=""}}else if(v){let d=JSON.stringify({ask:s,about:A.entry.targetLabel,...e.follows?{follows:e.follows}:{},...e.examples&&e.examples.length>0?{worked_before:e.examples,worked_before_is:"What people of this app asked before and what was done that they kept: where these words mean the same, do the same."}:{},state:A.state,candidates:J.map(m=>({id:m.id,says:m.description})),facts:wn(e.store,e.principal,[...new Set([...e.target.on==="record"?[e.target.id,...Ye(e.store,e.target.id)?.ids??[]]:[],...M.map(m=>m.id),...e.members??[]])],rn(e.store)),...M.length>0?{members:M.map(m=>({id:m.id,label:L(e.store.schema.tryDefinition(m.kind),m)})),member_acts:Y.map(m=>({name:m.name,title:m.title,does:m.does,asks:m.asks}))}:{},...r?{fast_leaned_to:r}:{},...g?{people:{[g.said]:g.as}}:{},everyone_in_the_app:he(e.store).flatMap(m=>e.store.graph.allNodes().filter(P=>P.kind===m)).slice(0,40).map(m=>L(e.store.schema.tryDefinition(m.kind),m)),...rn(e.store)?{today:bn(rn(e.store))}:{},...n.couldNotFind?{not_found:gt}:{}});re=d;let S=m=>!!(m&&(typeof m.answer=="string"&&m.answer.trim()||Array.isArray(m.pick)&&m.pick.length>0||m.each||m.lacks)),l=await u(f?"light":"thinking",v.model,()=>ne(v,ke,d,A,A.meter));f&&p&&p!==f&&!S(l)&&(l=await u("thinking",p.model,()=>ne(p,ke,d,A,A.meter)));let T=!b()&&!en.test(s)&&M.length>0,$=m=>Array.isArray(m)&&m.some(P=>{let V=J.find(z=>z.id===P);return V!==void 0&&Ne(V)!==void 0});if(T&&l&&!l.each&&!l.lacks&&!$(l.pick)){let m=await u(f?"light":"thinking",v.model,()=>ne(v,ke,JSON.stringify({...JSON.parse(d),told:'They told you to do this, not asked a question. Reply with exactly one of two shapes, never "answer" alone: "each" with an act from member_acts and its values, or "lacks" and "need" (and "value") where no act can \u2014 for example {"lacks": "Tasks have no priority yet.", "need": {"field": {"on": "task", "called": "priority", "type": "string"}}, "value": "high"}.'}),A,A.meter));if(m&&(m.each||m.lacks))l=m;else if(r){let P=Y.find(z=>z.name===r),V=P?e.store.allMutations().find(z=>z.name===P.name)?.input?.shape??{}:{};P&&P.asks.every(z=>V[z]?.safeParse(void 0).success??!0)&&(l={...l,answer:"",each:{act:P.name,args:{}}})}}if(!b()&&l?.each&&(l={...l,pick:Array.isArray(l.pick)?l.pick.filter(m=>{let P=J.find(V=>V.id===m);return P!==void 0&&Ne(P)===void 0}):l.pick}),b()&&l&&(l={...l,each:void 0}),l&&typeof l.answer=="string"&&l.answer.trim()&&!ee(l.answer)&&!l.each&&!l.lacks){let m=await u(f?"light":"thinking",v.model,()=>ne(v,ke,JSON.stringify({...JSON.parse(d),rewrite:`Your answer was not whole sentences: \u201C${String(l.answer).slice(0,300)}\u201D. Say it again in one to three whole sentences to the person, each begun with a capital and ended with a full stop.`}),A,A.meter));m&&typeof m.answer=="string"&&ee(m.answer)?l={...l,answer:m.answer}:b()&&/^[\p{L}\p{N}"“'(][^{}[\]]*$/u.test(String(l.answer).trim())&&String(l.answer).trim().split(/\s+/).length>=2&&(l={...l,answer:`${String(l.answer).trim().charAt(0).toUpperCase()}${String(l.answer).trim().slice(1).replace(/[\s,;:]+$/,"")}.`})}if(b()&&l&&!(typeof l.answer=="string"&&l.answer.trim())){let m=await u(f?"light":"thinking",v.model,()=>ne(v,ke,JSON.stringify({...JSON.parse(d),rewrite:'This is a question: answer it in "answer", in one to three whole sentences, from the facts.'}),A,A.meter));m&&typeof m.answer=="string"&&ee(m.answer)&&(l={...l,answer:m.answer})}if(D=typeof l?.answer=="string"?l.answer.trim():"",F=De(Array.isArray(l?.pick)?l.pick:[]),W=pt(l?.each),D&&!ee(D)&&(D=W?"":me),typeof l?.lacks=="string"&&l.lacks.trim()){let m=Pn(l.need),P=l.lacks.trim();C={said:ee(P)?P:m?Tn(e.store.schema,m):me,...m?{need:m}:{},...typeof l.who=="string"&&l.who.trim()?{who:l.who.trim()}:{},...typeof l.value=="string"||typeof l.value=="number"?{value:String(l.value)}:{}}}}else if(o&&J.length>0){let{question:d,of:S}=Ae(J,`Which of these best answers, or acts on: ${s}`),l=await Se(o,{...A.state,asked:s,candidates:J.map(T=>({id:T.id,type:T.type,says:T.description}))},{answer:d},A.meter);F=Pe(l.answer,S,3),D=F.length>0?`These fit \u201C${s}\u201D.`:""}else return _(A,s,"ask",ve)}catch(d){return _(A,s,"ask",d instanceof Error?d.message:String(d))}for(let d of[D,C?.said??""]){let S=d?on(e.store,d):[];if(S.length===0||!v)continue;let l=S.map(P=>`${P.name} (${K(e.store.schema,P.kind).toLowerCase()})`).join(", "),T=await u(f?"light":"thinking",v.model,()=>ne(v,ke,JSON.stringify({...JSON.parse(re??"{}"),known:`These are in the app: ${l}. Never say they are not.`}),A,A.meter)),$=typeof T?.answer=="string"?T.answer.trim():"",m=$&&ee($)&&on(e.store,$).length===0?$:`${S[0].name} is here, one of its ${K(e.store.schema,S[0].kind).toLowerCase()}. Try saying it another way.`;d!==D&&(C=void 0),D=m}if(!b()&&Ve(s)&&!/\b(field|link|column)\b/i.test(s)&&(C=void 0,W=void 0,F=[],D=Xe(e.store,s,e.target.on==="record"?e.target.id:void 0)),C&&n.couldNotFind){let d=e.target.on==="place"||e.target.on==="lens"?e.target.place:void 0,S=e.target.on==="list"||e.target.on==="lens"?e.target.kind:void 0;if(qe(e.store,{type:"unanswered",question:s,...d?{place:d}:{},...S?{kind:S}:{},lacks:C.said},e.principal),typeof n.couldNotFind=="function")try{n.couldNotFind({said:s,lacks:C.said,...C.need?{need:C.need}:{},...d?{place:d}:{},...S?{kind:S}:{}})}catch{}}let te=!!W||F.some(({candidate:d})=>Ne(d)!==void 0);if(!b()&&!te&&!C&&D&&Cn(D)&&(D=Nn),!D&&F.length===0&&!W&&!C){let d=e.target.on==="place"||e.target.on==="lens"?e.target.place:void 0,S=e.target.on==="list"||e.target.on==="lens"?e.target.kind:void 0;return qe(e.store,{type:"unanswered",question:s,...d?{place:d}:{},...S?{kind:S}:{}},e.principal),_(A,s,"ask","The AI had no answer to that here.")}let xe=A.usage.at(-1)?.model,se=b(),Q=W?e.store.allMutations().find(d=>d.name===W.act):void 0;if(Q&&_e(Q)&&M.length>1&&(k?(k.chance??1)<Ke(Q,s)||Qe(s,k):!$n(s))){let d=`Should I ${(Q.title??Q.name).trim().split(/\s+/)[0].toLowerCase()} all ${M.length} of them? Say \u201Call\u201D to go ahead, or say which.`;return{interaction:{...A.entry,ask:{kind:"ask",said:s},offered:[],outcome:"offered",answer:d,usage:[...A.usage],stages:c},offers:[],answer:d,...k?{reading:k}:{}}}let ge=(se?[]:F).flatMap(({candidate:d,confidence:S})=>{let l=Ne(d);return l?[{...l,...S!==void 0?{confidence:S}:{}}]:[]}),q=W?Y.find(d=>d.name===W.act):void 0;if(q)for(let d of M){let S=e.store.allMutations().find(T=>T.name===q.name),l=S?.subject?.kinds;!S||!(l==="*"||l.includes(d.kind))||ge.push({id:`each:${q.name}:${d.id}`,label:`${q.title}: ${L(e.store.schema.tryDefinition(d.kind),d)}`,said:q.title,call:{name:q.name,args:{...W.args,[q.subjectArg]:d.id}},record:d.id})}let ce=ge.filter((d,S)=>ge.findIndex(l=>l.call.name===d.call.name&&JSON.stringify(l.call.args)===JSON.stringify(d.call.args))===S),O=ce.length>0?Ie(e.store,{interaction:A.id,target:e.target,basis:s,...xe?{model:xe}:{},proposals:ce},e.principal):void 0,pe=F.map(({candidate:d})=>d).filter(d=>se||Ne(d)===void 0);if(!W&&!se&&O&&O.proposals.length>0&&(D=O.proposals.slice(0,3).flatMap(d=>{let S=e.store.allMutations().find(T=>T.name===d.call.name),l=S?.subject?d.call.args[S.subject.arg]:void 0;return S&&typeof l=="string"?[sn(e.store,{act:S,args:d.call.args,records:[l],itself:!0})]:[]}).join(" ")),W&&Q&&O){let d=M.map(S=>S.id).filter(S=>O.proposals.some(l=>l.id===`each:${Q.name}:${S}`));d.length>0&&(D=Ln(e.store,Q,W.args,d,k??(M.length===1&&e.target.on==="record"&&M[0].id===e.target.id?{which:"itself",records:d,kind:M[0].kind,words:"",close:!1}:void 0)))}let an=[...pe.map(d=>Ee(d,F.find(S=>S.candidate===d)?.confidence)),...(O?.proposals??[]).map(d=>({id:d.id,type:d.field!==void 0?"fill":"act",label:d.label,...d.confidence!==void 0?{confidence:d.confidence}:{}}))];return{interaction:{...A.entry,ask:{kind:"ask",said:s},offered:an,outcome:"offered",...D?{answer:D}:{},usage:[...A.usage],stages:c},offers:pe,...O&&O.proposals.length>0?{ghost:O}:{},...D?{answer:D}:C?{answer:C.said}:{},...C?{missing:C.need&&k&&"link"in C.need?{...C,need:{link:{...C.need.link,on:k.kind}}}:C}:{},...k?{reading:k}:{},...g?{taken:g}:{}}}function Ln(n,e,t,s,i){let o=i?.part,c=i?/ (in .+)$/.exec(i.words)?.[1]:void 0;return sn(n,{act:e,args:t,records:s,...o?{narrowed:o}:{},...c?{where:c}:{},itself:i?.which==="itself"})}function rn(n){try{let e=(typeof n.today=="function"?n.today():void 0)??new Date().toISOString();return/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(0,10):void 0}catch{return}}function Tn(n,e){let t=c=>K(n,c).toLowerCase(),s=c=>c.charAt(0).toUpperCase()+c.slice(1),{on:i,called:o}="link"in e?e.link:e.field;return`${s(t(i))} have no \u201C${s(o)}\u201D yet.`}function Rn(n,e,t,s,i){let o=Array.isArray(s)?s:[s],c=[];for(let p of o){if(!p.each||!p.reading)continue;let v=n.store.allMutations().find(R=>R.name===p.each.act);for(let R of p.reading.records){let N=n.store.graph.getNode(R);!N||!v?.subject||c.push({id:`each:${v.name}:${R}`,label:`${v.title??v.name}: ${L(n.store.schema.tryDefinition(N.kind),N)}`,said:v.title??v.name,call:{name:v.name,args:{...p.each.args,[v.subject.arg]:R}},record:R})}}let u=e.usage.at(-1)?.model,y=c.length>0?Ie(n.store,{interaction:e.id,target:n.target,basis:t,...u?{model:u}:{},proposals:c},n.principal):void 0,k=(y?.proposals??[]).map(p=>({id:p.id,type:"act",label:p.label})),r=new Set((y?.proposals??[]).map(p=>p.id)),h=o.map(p=>{if(p.clarify)return p.clarify;if(p.outside)return p.outside;if(p.each&&p.reading){let v=n.store.allMutations().find(N=>N.name===p.each.act),R=p.reading.records.filter(N=>r.has(`each:${p.each.act}:${N}`));return R.length>0&&v?Ln(n.store,v,p.each.args,R,p.reading):v?On(n.store,v,p.reading.records):"Nothing here would change."}return p.text??p.missing?.said??""}).filter(Boolean).join(" "),g=o[0],b=o.find(p=>p.missing)?.missing,f=o.find(p=>p.taken)?.taken;return{interaction:{...e.entry,ask:{kind:"ask",said:t},offered:k,outcome:"offered",...h?{answer:h}:{},usage:[...e.usage],stages:[...i]},offers:[],...y&&y.proposals.length>0?{ghost:y}:{},...h?{answer:h}:{},...b?{missing:b}:{},...g.reading&&o.length===1?{reading:g.reading}:{},...f?{taken:f}:{}}}function Pn(n){if(typeof n!="object"||n===null)return;let{link:e,field:t}=n,s=i=>typeof i=="string"&&i.trim()?i.trim():void 0;if(e&&s(e.on)&&s(e.called)&&s(e.to))return{link:{on:s(e.on),called:s(e.called),to:s(e.to)}};if(t&&s(t.on)&&s(t.called)){let i=["string","number","date","boolean"].includes(String(t.type))?t.type:"string";return{field:{on:s(t.on),called:s(t.called),type:i}}}}function pt(n){if(typeof n!="object"||n===null)return;let{act:e,args:t}=n;if(typeof e=="string")return{act:e,args:typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{}}}function Ie(n,e,t){let s=e.proposals.flatMap(i=>{try{let o=n.previewAll([i.call],{author:t}),c=o.ops.map(u=>u.intent).join("; ");return o.ops.length>0?[{...i,said:c||i.said}]:[]}catch{return[]}});return{...e,proposals:s}}function Ne(n){if(n.type==="fill")return{id:n.id,label:n.label,said:n.description,call:n.call,record:n.record,field:n.field};if(n.type==="act"&&n.asks.length===0)return{id:n.id,label:n.label,said:n.description,call:{name:n.mutation,args:{...n.args}}}}function qt(n,e,t){let s=e.proposals.filter(o=>t.ids===void 0||t.ids.includes(o.id));if(s.length===0)return{ok:!1,refused:"Nothing was chosen."};let i=s.flatMap(o=>o.confidence===void 0?[]:[o.confidence]);try{let c=n.applyAll(s.map(u=>u.call),{author:t.author,via:`ai:${e.interaction}`,intent:e.basis,lineage:{basis:`Asked \u201C${e.basis}\u201D`,...e.model?{model:e.model}:{},...i.length>0?{confidence:Math.min(...i)}:{},interaction:e.interaction}}).ops[0]?.batch;return c?{ok:!0,batch:c,accepted:s.map(u=>u.id)}:{ok:!1,refused:"That changes nothing now."}}catch(o){return{ok:!1,refused:o instanceof Error?o.message:String(o)}}}function Ht(n,e,t){let s=n.ask.kind==="suggest"?e.length>0:n.offered.length>0&&n.offered.every(i=>e.includes(i.id));return{...n,outcome:s?"accepted":"partly",accepted:e,batches:[...n.batches??[],t]}}var Gt=n=>({...n,outcome:"dismissed"}),Dn={candidates:8,records:6},yt=.1,mt=12,Mn=n=>{let e=new Set;return[...n.selection,...n.neighbors].filter(t=>!e.has(t.id)&&(e.add(t.id),!0))};function _n(n,e){return{choices:e,state:n.state,context:{by:"default",candidates:e.map(t=>t.id),records:Mn(n.state).map(t=>t.id)}}}async function wt(n,e,t,s){let i=Mn(t.state),o={},c=s.length>0?Ae(s,`Which of these could answer, or act on: ${e}`):void 0;c&&(o.candidates={...c.question,criteria:{...c.question.criteria,none:"None of these"}});let u=new Map(i.slice(0,mt).map((f,p)=>[`record-${p+1}`,f]));for(let[f,p]of u)o[f]={type:"noul",instructions:`Is \u201C${e}\u201D about ${p.label} (${p.kind})?`};if(Object.keys(o).length===0)return{..._n(t,s),context:{by:"fast",model:n.model,candidates:[],records:[]}};let y=await Se(n,{target:t.state.target,asked:e},o,t.meter),r=c?((f,p,v)=>{if(f?.type!=="choice"||f.choice==="none")return[];let R=Object.entries(f.probabilities).filter(([N])=>N!=="none").sort((N,A)=>A[1]-N[1]);return R.some(([N])=>N===f.choice)||R.unshift([f.choice,f.confidence]),R.filter(([,N],A)=>A===0||N>=yt).flatMap(([N])=>{let A=p(N);return A===void 0?[]:[A]}).slice(0,v)})(y.candidates,c.of,Dn.candidates):[],h=[...u].flatMap(([f,p])=>{let v=y[f];return v?.type==="noul"&&v.noul>.5?[{record:p,chance:v.noul}]:[]}).sort((f,p)=>p.chance-f.chance).slice(0,Dn.records).map(f=>f.record),g=new Set(h.map(f=>f.id)),b={...t.state,selection:t.state.selection.filter(f=>g.has(f.id)),neighbors:t.state.neighbors.filter(f=>g.has(f.id))};return{choices:r,state:b,context:{by:"fast",model:n.model,candidates:r.map(f=>f.id),records:h.map(f=>f.id)}}}export{Jn as a,Te as b,Re as c,rt as d,at as e,Et as f,dt as g,It as h,Ut as i,Jt as j,Wt as k,Ft as l,Ie as m,Ne as n,qt as o,Ht as p,Gt as q};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as ot}from"./chunk.T6PU3NKP.js";import"./chunk.LETAQTLJ.js";import{e as V,l as ue,n as G,r as st}from"./chunk.BUVTUAB5.js";import{a as ee}from"./chunk.G4JJXA63.js";import"./chunk.FIFUMX5X.js";import{c as nt}from"./chunk.V7W5AQKL.js";import{d as tt}from"./chunk.PPSYUOH7.js";import"./chunk.XOZU4OFA.js";import"./chunk.GME63ZHI.js";import"./chunk.JXNVNFV4.js";import"./chunk.WSDJPXJD.js";import"./chunk.F4VB6Q2W.js";import{d as et}from"./chunk.FFOD5B4B.js";import{b as Ze}from"./chunk.Z7Y3R3YR.js";import"./chunk.YXEO3Y65.js";import{L as ze,Zd as Ne,_ as Je,_d as Xe,la as Ye,oa as qe,ta as Ae,ua as F,vb as Ve,wb as Qe}from"./chunk.6HY6ZGEE.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";var At="Nothing by that name here.",$=o=>o.normalize("NFD").replace(/\p{M}+/gu,"").toLowerCase().replace(/[’']/g,"'").replace(/[^\p{L}\p{N}' ]+/gu," ").replace(/\s+/g," ").trim(),Nt=/^(?:(?:can you |could you |please )?(?:go|take me|bring me|head|jump|navigate|switch|get me)(?: back)? to|(?:please )?(?:open|show(?: me)?|bring up|let me see|view)) (.+)$/,St=/^(?:(?:can you |could you |please )?tell me (?:about|of)|what(?: is|'s| are) (?:in |on )?|describe|explain|who(?: is|'s)) (.+)$/,Ot=/^(?:what(?: is|'s| am i looking at| do i see)(?: (?:here|this|on (?:this|the) (?:page|screen)|in view|this place|this page))?|where am i|describe (?:this|here|this place|this page)|tell me about (?:this|here|this place|this page))$/,rt=new Set(["here","this","this place","this page","on this page","on the page","on this screen","in view"]),Ct=/^(?:date|day|when|on|at|the date|the day)$/,jt=/^(?:what(?: is|'s) (?:wrong|broken|the (?:problem|matter|trouble))|what needs (?:fixing|attention|doing)|any (?:problems|issues|trouble)|(?:show(?: me)? |go to |open )?(?:the )?(?:problems|issues|trouble|standing|what's wrong)|is (?:anything|something) (?:wrong|broken)|are there (?:any )?(?:problems|issues))(?: (?:with|about|on|in) (.+))?$/,z=o=>o.replace(/^(?:the|a|an|my|our) /,""),te=new Set(["the","a","an","my","our","all","any","of","that","which","who","are","is","be","what","whats","what's","with","me","show","list","every","there","do","i","have","we","due","for","please","were","was","by","from","in","on"]),ft=864e5,he=o=>Date.UTC(Number(o.slice(0,4)),Number(o.slice(5,7))-1,Number(o.slice(8,10))),xe=o=>new Date(o).toISOString().slice(0,10),C=(o,i)=>xe(he(o)+i*ft),xt=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],Mt=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Wt="(monday|tuesday|tues|wednesday|thursday|thurs|friday|saturday|sunday)",it="(january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sept|sep|oct|nov|dec)",at="(\\d{1,2})(?:st|nd|rd|th)?",Dt=o=>xt.findIndex(i=>i.startsWith(o.slice(0,3))),dt=o=>Mt.findIndex(i=>o.startsWith(i.toLowerCase()));function Rt(o,i){return Je(o,{year:o.slice(0,4)!==i.slice(0,4)})}function Se(o,i,y){if(o<0||i<1||i>31)return;let f=Number(y.slice(0,4)),c=k=>{let j=Date.UTC(k,o,i);return new Date(j).getUTCMonth()===o?xe(j):void 0},p=c(f);if(p)return he(p)<he(y)-183*ft?c(f+1):p}function Oe(o,i,y){let f=new Date(he(i)).getUTCDay(),c=u=>{let S=(f-y+7)%7,w=C(i,-S+u*7);return{from:w,to:C(w,6)}},p=()=>{let u=`${i.slice(0,8)}01`,S=new Date(Date.UTC(Number(i.slice(0,4)),Number(i.slice(5,7)),1));return{from:u,to:C(xe(S.getTime()),-1)}},k=u=>u?{from:u,to:u,day:Rt(u,i)}:void 0,j=(u,S)=>{let w=Dt(S);return k(u==="this"||u==="next"?C(c(u==="next"?1:0).from,(w-y+7)%7):u==="last"?C(i,-((f-w+6)%7+1)):C(i,(w-f+7)%7))},J=u=>{let S=C(i,f===0?-1:6-f);return{from:C(S,u*7),to:C(S,u*7+1)}},B="\\b(?:(?:due |for |on |by )(?:the )?)?",P=[[/\b(?:overdue|past due|late)\b/,()=>({overdue:!0,to:C(i,-1)})],[/\b(?:due |for |on )?today\b/,()=>({from:i,to:i})],[/\b(?:due |for |on )?tomorrow\b/,()=>k(C(i,1))],[/\b(?:due |for |on )?yesterday\b/,()=>k(C(i,-1))],[/\b(?:due |for |on )?this week\b/,()=>c(0)],[/\b(?:due |for |on )?next week\b/,()=>c(1)],[/\b(?:due |for |on )?(?:last|previous) week\b/,()=>c(-1)],[/\b(?:due |for |on )?next weekend\b/,()=>J(1)],[/\b(?:due |for |on )?(?:this |the )?weekend\b/,()=>J(0)],[/\b(?:due |for |on )?this month\b/,()=>p()],[new RegExp(`${B}(\\d{4}) (\\d{2}) (\\d{2})\\b`),u=>k(Se(Number(u[2])-1,Number(u[3]),`${u[1]}-01-01`))],[new RegExp(`${B}${at} (?:of )?${it}\\b`),u=>k(Se(dt(u[2]),Number(u[1]),i))],[new RegExp(`${B}${it} (?:the )?${at}\\b`),u=>k(Se(dt(u[1]),Number(u[2]),i))],[new RegExp(`${B}(?:(this|next|last|coming) )?${Wt}\\b`),u=>j(u[1],u[2])]];for(let[u,S]of P){let w=o.match(u);if(!w)continue;let N=S(w);if(N)return{ask:{words:w[0],...N},rest:o.replace(w[0]," ").replace(/\s+/g," ").trim()}}}function ht(o,i,y={}){let f=y.principal??{kind:"human"},c=o.seenBy(f),p=c.schema,k=y.today??o.today?.()??ze(),j=y.weekStartsOn??1,J=o.kindsKeptFrom(f),B=o.modules.disabledKinds,P=p.kinds.filter(e=>!J.has(e)&&!B.has(e)),u=new Set(P),S=(y.places??[]).filter(e=>e.kind===null||u.has(e.kind)),w=c.graph,N=$(i).replace(/[?.!]+$/,"").trim();if(N.length===0)return{unresolved:!0};let M=e=>p.tryDefinition(e),H=e=>Ye(M(e.kind),e),I=e=>qe(p,e),se=e=>S.find(t=>t.kind===e&&t.address===Ne(p,e))?.address??Ne(p,e),ge=e=>Xe(p,e.kind,e.id),Me=e=>({to:"record",id:e.id,kind:e.kind,label:H(e),address:ge(e),said:`Went to ${H(e)}.`}),We=e=>{let t=`Went to ${e.title}.`;return e.kind===null?{to:"place",slug:e.slug,title:e.title,address:e.address,...e.slug==="overview"?{face:"scene"}:{},said:t}:e.lens||e.address.startsWith("/places/")?{to:"picture",kind:e.kind,as:e.slug,title:e.title,address:e.address,said:t}:{to:"kind",kind:e.kind,title:e.title,address:e.address,said:t}},De=()=>({unresolved:!0,say:At}),oe=e=>{let t=M(e.kind),s=et(e,t,{limit:3,excerpt:!0}).map(r=>r.alone.startsWith(r.label)?r.alone:`${r.label.toLowerCase()} ${r.alone}`).join(", "),n=c.violations().filter(r=>r.nodeIds.includes(e.id));return[`${H(e)} \u2014 ${Ae(F(t,e.kind))}${s?` (${s})`:""}.`,n.length>0?`Trouble: ${n.map(r=>r.message).join("; ")}.`:""].filter(Boolean).join(" ")},re=e=>{let t=new Set([G(e),G(z(e))]);for(let n of[" page"," view"," lens"," place"," picture"," list"])e.endsWith(n)&&(t.add(G(e.slice(0,-n.length))),t.add(G(z(e.slice(0,-n.length)))));t.delete("");let s=n=>t.has(G(n.title))||t.has(G(z($(n.title))))||t.has(G(n.slug));return S.find(n=>n.kind!==null&&n.address.startsWith("/places/")&&s(n))??S.find(s)},pe=e=>{let t=st(o,e,{principal:f,today:k,limit:6,near:!1,...y.selection?{from:y.selection}:{}}),s=t.hits.filter(r=>r.about==="node"&&u.has(r.kind)&&w.getNode(r.id)!==void 0),n=s.filter(r=>r.why.field==="label"&&r.why.strength==="exact");return n.length===1?{one:w.getNode(n[0].id),picks:s}:n.length>1?{picks:n}:s.length===1&&t.total===1?{one:w.getNode(s[0].id),picks:s}:{picks:s}},Re=e=>{let t=e.map(s=>`${s.label} (${F(M(s.kind),s.kind)})`);return`${e.length===1?"One thing matches":`${e.length} things match`}: ${t.join("; ")}.`},Ee=(e,t)=>{if(rt.has(e))return Le();let s=t?pe(z(e)||e):void 0,n=s?.one&&$(H(s.one))===$(z(e)||e)?void 0:re(e);if(n){let l=We(n);return{about:"place",say:t?`${l.said} ${me(n)}`:l.said,moves:[l],subject:n.slug}}let r=pe(z(e)||e);if(r.one){let l=Me(r.one);return{about:t?"describe":"record",say:t?`${l.said} ${oe(r.one)}`:l.said,moves:[l],subject:r.one.id}}if(r.picks.length>0)return{about:"picks",say:Re(r.picks),moves:[],picks:r.picks};let h=ae(e);if(h)return h;let d=Pe(e);if(d){if(d.rest.split(" ").every(l=>l===""||te.has(l))){let l=I(d.kind),v={to:"kind",kind:d.kind,title:l,address:se(d.kind),said:`Went to the ${l.toLowerCase()}.`};return{about:"kind",say:v.said,moves:[v]}}return{unresolved:!0}}return De()},me=e=>{if(e.kind===null){let h=P.map(l=>({kind:l,count:w.nodesOfKind(l).length})).filter(l=>l.count>0).map(l=>`${l.count} ${(l.count===1?F(M(l.kind),l.kind):I(l.kind)).toLowerCase()}`),d=c.violations().length;return[h.length>0?`It holds ${fe(h)}.`:"It holds nothing yet.",d>0?`${d===1?"One problem":`${d} problems`} to see to.`:""].filter(Boolean).join(" ")}let t=w.nodesOfKind(e.kind).length,s=I(e.kind).toLowerCase(),n=new Set(c.violations().flatMap(h=>h.nodeIds)),r=w.nodesOfKind(e.kind).filter(h=>n.has(h.id)).length;return[e.lens?`It draws the ${s} as ${Ae(e.lens)}${t>0?` \u2014 ${t} of them`:""}.`:`${t===0?"No":t} ${t===1?F(M(e.kind),e.kind):s} ${t===1?"is":"are"} here.`,r>0?`${r} ${r===1?"has":"have"} a problem.`:""].filter(Boolean).join(" ")},Le=()=>{let e=(y.selection??[]).map(s=>w.getNode(s)).find(s=>s!==void 0);if(e)return{about:"here",say:oe(e),moves:[],subject:e.id};let t=S.find(s=>s.slug===y.place)??S.find(s=>s.slug==="home");return t?{about:"here",say:`${t.title}. ${me(t)}`,moves:[],subject:t.slug}:{about:"here",say:me({slug:"home",title:"Home",kind:null,cardinality:"many",address:"/",stop:"#"}),moves:[]}},Pe=e=>{let t=P.flatMap(s=>[I(s),F(M(s),s),s].map(n=>({kind:s,name:$(n)}))).filter(s=>s.name.length>0).sort((s,n)=>n.name.length-s.name.length);for(let{kind:s,name:n}of t)if(!(` ${e} `.indexOf(` ${n} `)<0))return{kind:s,rest:` ${e} `.replace(` ${n} `," ").replace(/\s+/g," ").trim()}},ie=(e,t)=>{let s=V(p,e).filters.filter(d=>d.about==="field"&&d.type==="date");if(s.length===0)return;let n=s.find(d=>t.some(l=>$(d.key)===l||$(d.label)===l));if(n)return n;let r=M(e)?.fieldRoles??{};for(let d of["due","deadline","date","when","start","end"]){let l=r[d],v=l?s.find(x=>x.key===l):void 0;if(v)return v}return s.find(d=>["due","deadline","date","when","on","at"].includes(d.key.toLowerCase()))??(s.length===1?s[0]:void 0)},He=e=>{let t=M(e),s=V(p,e).filters;if(t?.lifecycle)return{conditions:[{key:"is",value:"current"}],holds:d=>ue(be,d,{key:"is",value:"current"})};let r=s.find(d=>d.about==="field"&&d.type==="boolean"&&ne.has($(d.key)));if(r)return{conditions:[{key:r.key,value:"false"}],holds:d=>d[r.key]!==!0};let h=s.find(d=>d.about==="field"&&d.type==="choice"&&(d.options??[]).some(l=>ne.has($(l))));if(h){let d=new Set((h.options??[]).filter(v=>ne.has($(v)))),l=(h.options??[]).filter(v=>!d.has(v));return l.length===1?{conditions:[{key:h.key,value:l[0]}],holds:v=>v[h.key]===l[0]}:"unsayable"}return{conditions:[],holds:()=>!0}},Ie=(e,t)=>{let s=e.words.startsWith("due")||$(t.key)==="due",n=Ct.test($(t.label));if(e.day)return s?`due ${e.day}`:n?`on ${e.day}`:`${t.label.toLowerCase()} on ${e.day}`;let r=e.words.replace(/^(?:due|for|on|by) (?:the )?/,"");return s?`due ${r}`:n?r:`${t.label.toLowerCase()} ${r}`},ye=new Set(c.violations().flatMap(e=>e.nodeIds)),be={schema:p,graph:c.graph,flagged:ye,today:k},ae=e=>{let t=Oe(e,k,j),s=Pe(t?.rest??e),n=s?.kind,r=(s?.rest??t?.rest??e).split(" ").filter(Boolean);if(!n&&t){let g=e.split(" "),m=P.filter(L=>ie(L,g)!==void 0),E=m.filter(L=>{let b=ie(L,g);return g.some(O=>$(b.key)===O||$(b.label)===O)}),U=m.length===1?m:E;if(U.length!==1)return;n=U[0]}if(!n)return;let h=V(p,n).filters,d=[],l=[],v=[],x=[],q=!1,de=[];for(let g=0;g<r.length;g++){let m=r[g],E=g>0&&(r[g-1]==="not"||r[g-1]==="un"),U=h.find(b=>b.about==="field"&&b.type==="choice"&&(b.options??[]).some(O=>$(O)===m));if(U&&!E){let b=(U.options??[]).find(O=>$(O)===m);d.push({key:U.key,value:b}),l.push(b);continue}let L=h.find(b=>b.about==="field"&&b.type==="boolean"&&[$(b.key),$(b.label)].some(O=>O===m||O===m.replace(/^un/,"")));if(L){let b=!E&&!(m.startsWith("un")&&!$(L.key).startsWith("un"));d.push({key:L.key,value:String(b)}),l.push(b?m:`not ${m.replace(/^un/,"")}`);continue}if(Pt.has(m)&&!E){let b=He(n);b==="unsayable"?(q=!0,x.push(O=>!ut(p,O))):(d.push(...b.conditions),x.push(b.holds)),l.push(m);continue}m==="not"||m==="un"||t&&h.some(b=>b.type==="date"&&($(b.key)===m||$(b.label)===m))||de.push(m)}if(r=de,r.some(g=>!te.has(g))||!t&&d.length===0&&x.length===0)return;let T=I(n).toLowerCase(),Q=I(n);if(t){let g=ie(n,e.split(" "));if(!g){let m={to:"kind",kind:n,title:Q,address:se(n),said:`Went to the ${T}.`};return{about:"kind",say:`${ee(Q)} carry no date, so I can't tell which are ${/^(?:due|for|on|overdue|past due|late)\b/.test(t.ask.words)?t.ask.words:`due ${t.ask.words}`}. ${m.said}`,moves:[m]}}if(t.ask.from&&d.push({key:g.key,value:`after:${C(t.ask.from,-1)}`}),t.ask.to&&d.push({key:g.key,value:`before:${C(t.ask.to,1)}`}),t.ask.overdue){let m=He(n);m==="unsayable"?(q=!0,x.push(E=>!ut(p,E))):(d.push(...m.conditions),x.push(m.holds))}t.ask.overdue?l.push("overdue"):v.push(Ie(t.ask,g))}let R=w.nodesOfKind(n).filter(g=>d.every(m=>ue(be,g,m))&&x.every(m=>m(g))),K=[...l,...v].join(" and "),Y=[...l,T,...v].join(" "),W=R.slice(0,6).map(g=>({about:"node",id:g.id,kind:n,label:H(g),why:{field:d[0]?.key??"label",reading:d[0]?.key??"Name",fragment:K,strength:"field"},current:!0,flagged:ye.has(g.id),address:ge(g)})),X=R.length===0?`No ${T} are ${K}.`:`${R.length===1?`One ${F(M(n),n)} is`:`${R.length} ${T} are`} ${K}: ${fe(R.slice(0,6).map(H))}${R.length>6?`, and ${R.length-6} more`:""}.`;if(q)return{about:"kind",say:X,moves:[],picks:W,offer:{draft:Y,label:"Show as a view"}};let Z=d.map(g=>`${g.key}:${g.value}`).join(","),we=`${se(n)}?${new URLSearchParams({filter:Z}).toString()}`,_={to:"kind",kind:n,title:ee(Y),filter:Z,address:we,said:`Went to the ${Y}.`};return{about:"kind",say:`${_.said} ${X}`,moves:[_],picks:W}},Te=e=>M(e)?.figure==="person"?!0:[e,F(M(e),e),I(e)].some(s=>$(s).split(" ").some(n=>Et.has(n))),pt=e=>{let t=[],s=n=>M(n)?.edges??{};for(let[n,r]of Object.entries(s(e)))for(let h of r.to??[])u.has(h)&&t.push({key:n,direction:"out",far:h,words:ct(`${r.description??""} ${n}`)});for(let n of P)for(let[r,h]of Object.entries(s(n)))(h.to??[]).includes(e)&&t.push({key:r,direction:"in",far:n,words:ct(`${h.inverse??""} ${r}`)});return t},mt=e=>{let t=e.match(/^(who|which|what)\b/)?.[1];if(!t)return;let s=Oe(e,k,j);if(!s||s.ask.overdue)return;let n=s.rest.split(" ").filter(Boolean),r=P.flatMap(a=>[I(a),F(M(a),a),a].map(A=>({kind:a,name:$(A)}))).filter(a=>a.name.length>0).sort((a,A)=>A.name.length-a.name.length),h=` ${n.join(" ")} `,d=[];for(let{kind:a,name:A}of r)h.includes(` ${A} `)&&(h=h.replace(` ${A} `," "),d.includes(a)||d.push(a));let l=h.match(/\b(?:is|are|was|were)\b|'s\b/)?.[0],v=h.replace(/'s\b/g," ").split(" ").filter(a=>a.length>0&&!te.has(a)&&!Ce.has(a)),x=t==="who"?d.find(Te):d[0];if(!x&&t!=="who")return;let q=d.find(a=>a!==x),de=v.flatMap(a=>[je(a),...lt.has(je(a))?[...lt]:[]]),T=P.filter(a=>q?a===q:a!==x).flatMap(a=>{let A=ie(a,e.split(" "))??V(p,a).filters.find(D=>D.about==="field"&&D.type==="date");return A?pt(a).filter(D=>(x?D.far===x:Te(D.far))&&D.far!==a).map(D=>({kind:a,field:A,relation:D,said:v.length===0||de.some(ve=>D.words.some(vt=>Lt(vt,ve)))})):[]}).filter(a=>a.said);if(T.length===0)return;let Q=T.filter(a=>n.some(A=>$(a.field.key)===A||$(a.field.label)===A)),R=T.length===1?T[0]:Q.length===1?Q[0]:void 0;if(!R)return;let{kind:K,field:Y,relation:W}=R,X=[...s.ask.from?[{key:Y.key,value:`after:${C(s.ask.from,-1)}`}]:[],...s.ask.to?[{key:Y.key,value:`before:${C(s.ask.to,1)}`}]:[]],Z=w.nodesOfKind(K).filter(a=>X.every(A=>ue(be,a,A))),we=a=>(W.direction==="out"?c.graph.out(a.id,W.key):c.graph.in(a.id,W.key)).filter(A=>A.kind===W.far&&u.has(W.far)),_=[],g=[];for(let a of Z){let A=we(a);A.length===0&&g.push(a);for(let D of A)_.some(ve=>ve.id===D.id)||_.push(D)}let m=Ie(s.ask,Y),E=s.ask.day?`On ${s.ask.day}`:ee(s.ask.words.replace(/^(?:due|for|on|by) (?:the )?/,"")),U=I(K).toLowerCase(),L=X.map(a=>`${a.key}:${a.value}`).join(","),b=`${U} ${m}`,O={to:"kind",kind:K,title:ee(b),filter:L,address:`${se(K)}?${new URLSearchParams({filter:L}).toString()}`,said:`Went to the ${b}.`};if(Z.length===0)return{about:"related",say:`No ${b}. ${O.said}`,moves:[O]};let le=v.join(" "),yt=l==="was"||l==="were",Ge=a=>yt?a===1?"was":"were":a===1?"is":"are",ce=_.map(H),bt=ce.length>8?[...ce.slice(0,8),`${ce.length-8} more`]:ce,kt=_.length===0?`${E}: nobody ${Ge(1)}${le?` ${le}`:""}.`:`${E}: ${fe(bt)}${le?` ${Ge(_.length)} ${le}`:""}.`,$t=t==="who"&&g.length>0?`${fe(g.slice(0,4).map(H))}${g.length>4?` and ${g.length-4} more`:""} ${g.length===1?"has":"have"} nobody.`:"",wt=_.slice(0,8).map(a=>({about:"node",id:a.id,kind:a.kind,label:H(a),why:{field:W.key,reading:Ze(p,W.direction==="out"?K:W.far,W.key,W.direction==="out"?"out":"in"),fragment:m,strength:"field"},current:!0,flagged:ye.has(a.id),address:ge(a)}));return{about:"related",say:[kt,$t,O.said].filter(Boolean).join(" "),moves:[O],picks:wt}},Ke=N.match(jt);if(Ke){let e=Ke[1];if(e&&!rt.has(e)&&!/^(?:it|this|that)$/.test(e)){let n=re(e),r=n?void 0:pe(z(e)||e);if(r?.one){let h=Me(r.one);return{about:"describe",say:`${h.said} ${oe(r.one)}`,moves:[h],subject:r.one.id}}if(!n)return r&&r.picks.length>0?{about:"picks",say:Re(r.picks),moves:[],picks:r.picks}:De()}if(e&&/^(?:it|this|that)$|^(?:here|this place|this page)$/.test(e)){let n=(y.selection??[]).map(r=>w.getNode(r)).find(r=>r!==void 0);if(n)return{about:"describe",say:oe(n),moves:[],subject:n.id}}let t=c.violations();if(t.length===0)return{about:"problems",say:"Nothing is wrong \u2014 every rule holds.",moves:[]};let s={to:"problems",address:"/problems",said:"Went to the problems."};return{about:"problems",say:`${s.said} ${Qe(t)}: ${t.slice(0,4).map(n=>n.message).join("; ")}${t.length>4?"\u2026":"."}`,moves:[s]}}if(Ot.test(N))return Le();let _e=mt(N);if(_e)return _e;let ke=Oe(N,k,j);if(ke&&!re(z(ke.ask.words))&&ke.rest.replace(/'s\b/g,"").split(" ").every(e=>e===""||te.has(e)||Ce.has(e))){let e=ae(N);if(e)return e}if(/^open /.test(N)){let e=ae(N);if(e)return e}let Fe=N.match(Nt)??N.match(/^(?:go|take me|head|get me)(?: back)? (home)$/);if(Fe)return Ee(Fe[1].trim(),!1);let Be=N.match(St);if(Be){let e=Ee(Be[1].trim(),!0);return"unresolved"in e&&e.unresolved&&!/^tell me|^describe/.test(N)?{unresolved:!0}:e}let $e=re(N);if($e){let e=We($e);return{about:"place",say:e.said,moves:[e],subject:$e.slug}}let Ue=ae(N);return Ue||{unresolved:!0}}var Ce=new Set(["who","whom","whose","which","what","whats","what's","who's"]),Et=new Set(["person","people","user","users","member","members","volunteer","volunteers","gardener","gardeners","player","players","staff","worker","workers","employee","employees","owner","owners","assignee","assignees","helper","helpers","student","students","teacher","teachers","customer","customers","client","clients","contact","contacts","author","authors"]),lt=new Set(["work","cover","staff","assign","do","run","schedul","roster","book","duty","serv","help"]);function je(o){let i=o.toLowerCase().replace(/'s$/,"");for(let y of["ing","ed","es","s"])if(i.length>y.length+2&&i.endsWith(y)){let f=i.slice(0,-y.length);return f.length>3&&f[f.length-1]===f[f.length-2]?f.slice(0,-1):f}return i}function ct(o){return o.toLowerCase().split(/[^a-z']+/).filter(i=>i.length>1&&!te.has(i)&&!Ce.has(i)&&!["it","they","them","their","its","this","here","to","at"].includes(i)).map(je)}var Lt=(o,i)=>o===i||o.length>=4&&i.length>=4&&(o.startsWith(i)||i.startsWith(o)),ne=new Set(["done","finished","complete","completed","closed","resolved","agreed","canceled","archived","shipped","delivered"]),Pt=new Set(["open","unfinished","outstanding","pending","remaining","undone","incomplete"]);function ut(o,i){return V(o,i.kind).filters.some(f=>f.about==="field"&&(f.type==="boolean"&&ne.has(f.key.toLowerCase())&&i[f.key]===!0||f.type==="choice"&&typeof i[f.key]=="string"&&ne.has(String(i[f.key]).toLowerCase())))}function fe(o){return o.length<=1?o[0]??"":`${o.slice(0,-1).join(", ")} and ${o[o.length-1]}`}function zt(o,i,y={}){let f=y.scene!==void 0?{...y.pages,scene:y.scene}:y.pages;return[...nt(o,i,f?{pages:f}:{})].map(({first:c,hidden:p,lens:k,...j})=>j)}function gt(o,i){return{...o.principal?{principal:o.principal}:{},...o.places?{places:o.places}:{},...o.selection?{selection:o.selection}:{},...o.place?{place:o.place}:{},...i??o.today?{today:i??o.today}:{},...o.weekStartsOn!==void 0?{weekStartsOn:o.weekStartsOn}:{}}}function Jt(o,i,y,f){let c=ht(o,i,gt(y,f));if(c.unresolved)return c.say?{reply:{say:c.say,proposals:[],grounded:!0}}:{};if(c.about==="picks")return{};let p=c.moves.length>0?{moves:c.moves}:{},k=c.subject?o.graph.getNode(c.subject):void 0;if(c.about==="problems")return{...p,problems:!0};if(k&&(c.about==="describe"||c.about==="here"))return{...p,told:k.id};let j=k?tt(o,ot(Ve(o.violations(),[k.id])).slice(0,3)):[];return{reply:{say:c.say,proposals:j,grounded:!0,...p,...c.picks&&c.picks.length>0?{picks:c.picks}:{},...c.offer?{offer:c.offer}:{}}}}function Yt(o,i,y={}){let f=gt(y),c=[];for(let p of i){let k=typeof p=="string"?p:typeof p=="object"&&p!==null&&typeof p.to=="string"?p.to:void 0;if(!k||k.trim().length===0)continue;let j=ht(o,/^(?:go|take me|open|show)\b/i.test(k.trim())?k:`go to ${k}`,f);if("moves"in j)for(let J of j.moves)c.some(B=>B.address===J.address)||c.push(J)}return c}export{At as NOTHING_BY_THAT_NAME,gt as askContextOf,Jt as goingFrom,Yt as movesFromNames,zt as placesFromViews,ht as resolveAsk};
|
|
1
|
+
import{a as ot}from"./chunk.T6PU3NKP.js";import"./chunk.XXCHO2A5.js";import{e as V,l as ue,n as G,r as st}from"./chunk.SADR3MQI.js";import{a as ee}from"./chunk.G4JJXA63.js";import"./chunk.BHJRT57H.js";import{c as nt}from"./chunk.CNN32262.js";import{d as tt}from"./chunk.JGRSUTPJ.js";import"./chunk.XOZU4OFA.js";import"./chunk.EP5JS7ZH.js";import"./chunk.EGSOHTZZ.js";import"./chunk.TFJA4QV4.js";import"./chunk.HWFJQ42Y.js";import{d as et}from"./chunk.QUETLFBJ.js";import{b as Ze}from"./chunk.JULD4XFB.js";import"./chunk.GRTBEA7O.js";import{L as ze,Zd as Ne,_ as Je,_d as Xe,la as Ye,oa as qe,ta as Ae,ua as F,vb as Ve,wb as Qe}from"./chunk.6AANHELP.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";var At="Nothing by that name here.",$=o=>o.normalize("NFD").replace(/\p{M}+/gu,"").toLowerCase().replace(/[’']/g,"'").replace(/[^\p{L}\p{N}' ]+/gu," ").replace(/\s+/g," ").trim(),Nt=/^(?:(?:can you |could you |please )?(?:go|take me|bring me|head|jump|navigate|switch|get me)(?: back)? to|(?:please )?(?:open|show(?: me)?|bring up|let me see|view)) (.+)$/,St=/^(?:(?:can you |could you |please )?tell me (?:about|of)|what(?: is|'s| are) (?:in |on )?|describe|explain|who(?: is|'s)) (.+)$/,Ot=/^(?:what(?: is|'s| am i looking at| do i see)(?: (?:here|this|on (?:this|the) (?:page|screen)|in view|this place|this page))?|where am i|describe (?:this|here|this place|this page)|tell me about (?:this|here|this place|this page))$/,rt=new Set(["here","this","this place","this page","on this page","on the page","on this screen","in view"]),Ct=/^(?:date|day|when|on|at|the date|the day)$/,jt=/^(?:what(?: is|'s) (?:wrong|broken|the (?:problem|matter|trouble))|what needs (?:fixing|attention|doing)|any (?:problems|issues|trouble)|(?:show(?: me)? |go to |open )?(?:the )?(?:problems|issues|trouble|standing|what's wrong)|is (?:anything|something) (?:wrong|broken)|are there (?:any )?(?:problems|issues))(?: (?:with|about|on|in) (.+))?$/,z=o=>o.replace(/^(?:the|a|an|my|our) /,""),te=new Set(["the","a","an","my","our","all","any","of","that","which","who","are","is","be","what","whats","what's","with","me","show","list","every","there","do","i","have","we","due","for","please","were","was","by","from","in","on"]),ft=864e5,he=o=>Date.UTC(Number(o.slice(0,4)),Number(o.slice(5,7))-1,Number(o.slice(8,10))),xe=o=>new Date(o).toISOString().slice(0,10),C=(o,i)=>xe(he(o)+i*ft),xt=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],Mt=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Wt="(monday|tuesday|tues|wednesday|thursday|thurs|friday|saturday|sunday)",it="(january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sept|sep|oct|nov|dec)",at="(\\d{1,2})(?:st|nd|rd|th)?",Dt=o=>xt.findIndex(i=>i.startsWith(o.slice(0,3))),dt=o=>Mt.findIndex(i=>o.startsWith(i.toLowerCase()));function Rt(o,i){return Je(o,{year:o.slice(0,4)!==i.slice(0,4)})}function Se(o,i,y){if(o<0||i<1||i>31)return;let f=Number(y.slice(0,4)),c=k=>{let j=Date.UTC(k,o,i);return new Date(j).getUTCMonth()===o?xe(j):void 0},p=c(f);if(p)return he(p)<he(y)-183*ft?c(f+1):p}function Oe(o,i,y){let f=new Date(he(i)).getUTCDay(),c=u=>{let S=(f-y+7)%7,w=C(i,-S+u*7);return{from:w,to:C(w,6)}},p=()=>{let u=`${i.slice(0,8)}01`,S=new Date(Date.UTC(Number(i.slice(0,4)),Number(i.slice(5,7)),1));return{from:u,to:C(xe(S.getTime()),-1)}},k=u=>u?{from:u,to:u,day:Rt(u,i)}:void 0,j=(u,S)=>{let w=Dt(S);return k(u==="this"||u==="next"?C(c(u==="next"?1:0).from,(w-y+7)%7):u==="last"?C(i,-((f-w+6)%7+1)):C(i,(w-f+7)%7))},J=u=>{let S=C(i,f===0?-1:6-f);return{from:C(S,u*7),to:C(S,u*7+1)}},B="\\b(?:(?:due |for |on |by )(?:the )?)?",P=[[/\b(?:overdue|past due|late)\b/,()=>({overdue:!0,to:C(i,-1)})],[/\b(?:due |for |on )?today\b/,()=>({from:i,to:i})],[/\b(?:due |for |on )?tomorrow\b/,()=>k(C(i,1))],[/\b(?:due |for |on )?yesterday\b/,()=>k(C(i,-1))],[/\b(?:due |for |on )?this week\b/,()=>c(0)],[/\b(?:due |for |on )?next week\b/,()=>c(1)],[/\b(?:due |for |on )?(?:last|previous) week\b/,()=>c(-1)],[/\b(?:due |for |on )?next weekend\b/,()=>J(1)],[/\b(?:due |for |on )?(?:this |the )?weekend\b/,()=>J(0)],[/\b(?:due |for |on )?this month\b/,()=>p()],[new RegExp(`${B}(\\d{4}) (\\d{2}) (\\d{2})\\b`),u=>k(Se(Number(u[2])-1,Number(u[3]),`${u[1]}-01-01`))],[new RegExp(`${B}${at} (?:of )?${it}\\b`),u=>k(Se(dt(u[2]),Number(u[1]),i))],[new RegExp(`${B}${it} (?:the )?${at}\\b`),u=>k(Se(dt(u[1]),Number(u[2]),i))],[new RegExp(`${B}(?:(this|next|last|coming) )?${Wt}\\b`),u=>j(u[1],u[2])]];for(let[u,S]of P){let w=o.match(u);if(!w)continue;let N=S(w);if(N)return{ask:{words:w[0],...N},rest:o.replace(w[0]," ").replace(/\s+/g," ").trim()}}}function ht(o,i,y={}){let f=y.principal??{kind:"human"},c=o.seenBy(f),p=c.schema,k=y.today??o.today?.()??ze(),j=y.weekStartsOn??1,J=o.kindsKeptFrom(f),B=o.modules.disabledKinds,P=p.kinds.filter(e=>!J.has(e)&&!B.has(e)),u=new Set(P),S=(y.places??[]).filter(e=>e.kind===null||u.has(e.kind)),w=c.graph,N=$(i).replace(/[?.!]+$/,"").trim();if(N.length===0)return{unresolved:!0};let M=e=>p.tryDefinition(e),H=e=>Ye(M(e.kind),e),I=e=>qe(p,e),se=e=>S.find(t=>t.kind===e&&t.address===Ne(p,e))?.address??Ne(p,e),ge=e=>Xe(p,e.kind,e.id),Me=e=>({to:"record",id:e.id,kind:e.kind,label:H(e),address:ge(e),said:`Went to ${H(e)}.`}),We=e=>{let t=`Went to ${e.title}.`;return e.kind===null?{to:"place",slug:e.slug,title:e.title,address:e.address,...e.slug==="overview"?{face:"scene"}:{},said:t}:e.lens||e.address.startsWith("/places/")?{to:"picture",kind:e.kind,as:e.slug,title:e.title,address:e.address,said:t}:{to:"kind",kind:e.kind,title:e.title,address:e.address,said:t}},De=()=>({unresolved:!0,say:At}),oe=e=>{let t=M(e.kind),s=et(e,t,{limit:3,excerpt:!0}).map(r=>r.alone.startsWith(r.label)?r.alone:`${r.label.toLowerCase()} ${r.alone}`).join(", "),n=c.violations().filter(r=>r.nodeIds.includes(e.id));return[`${H(e)} \u2014 ${Ae(F(t,e.kind))}${s?` (${s})`:""}.`,n.length>0?`Trouble: ${n.map(r=>r.message).join("; ")}.`:""].filter(Boolean).join(" ")},re=e=>{let t=new Set([G(e),G(z(e))]);for(let n of[" page"," view"," lens"," place"," picture"," list"])e.endsWith(n)&&(t.add(G(e.slice(0,-n.length))),t.add(G(z(e.slice(0,-n.length)))));t.delete("");let s=n=>t.has(G(n.title))||t.has(G(z($(n.title))))||t.has(G(n.slug));return S.find(n=>n.kind!==null&&n.address.startsWith("/places/")&&s(n))??S.find(s)},pe=e=>{let t=st(o,e,{principal:f,today:k,limit:6,near:!1,...y.selection?{from:y.selection}:{}}),s=t.hits.filter(r=>r.about==="node"&&u.has(r.kind)&&w.getNode(r.id)!==void 0),n=s.filter(r=>r.why.field==="label"&&r.why.strength==="exact");return n.length===1?{one:w.getNode(n[0].id),picks:s}:n.length>1?{picks:n}:s.length===1&&t.total===1?{one:w.getNode(s[0].id),picks:s}:{picks:s}},Re=e=>{let t=e.map(s=>`${s.label} (${F(M(s.kind),s.kind)})`);return`${e.length===1?"One thing matches":`${e.length} things match`}: ${t.join("; ")}.`},Ee=(e,t)=>{if(rt.has(e))return Le();let s=t?pe(z(e)||e):void 0,n=s?.one&&$(H(s.one))===$(z(e)||e)?void 0:re(e);if(n){let l=We(n);return{about:"place",say:t?`${l.said} ${me(n)}`:l.said,moves:[l],subject:n.slug}}let r=pe(z(e)||e);if(r.one){let l=Me(r.one);return{about:t?"describe":"record",say:t?`${l.said} ${oe(r.one)}`:l.said,moves:[l],subject:r.one.id}}if(r.picks.length>0)return{about:"picks",say:Re(r.picks),moves:[],picks:r.picks};let h=ae(e);if(h)return h;let d=Pe(e);if(d){if(d.rest.split(" ").every(l=>l===""||te.has(l))){let l=I(d.kind),v={to:"kind",kind:d.kind,title:l,address:se(d.kind),said:`Went to the ${l.toLowerCase()}.`};return{about:"kind",say:v.said,moves:[v]}}return{unresolved:!0}}return De()},me=e=>{if(e.kind===null){let h=P.map(l=>({kind:l,count:w.nodesOfKind(l).length})).filter(l=>l.count>0).map(l=>`${l.count} ${(l.count===1?F(M(l.kind),l.kind):I(l.kind)).toLowerCase()}`),d=c.violations().length;return[h.length>0?`It holds ${fe(h)}.`:"It holds nothing yet.",d>0?`${d===1?"One problem":`${d} problems`} to see to.`:""].filter(Boolean).join(" ")}let t=w.nodesOfKind(e.kind).length,s=I(e.kind).toLowerCase(),n=new Set(c.violations().flatMap(h=>h.nodeIds)),r=w.nodesOfKind(e.kind).filter(h=>n.has(h.id)).length;return[e.lens?`It draws the ${s} as ${Ae(e.lens)}${t>0?` \u2014 ${t} of them`:""}.`:`${t===0?"No":t} ${t===1?F(M(e.kind),e.kind):s} ${t===1?"is":"are"} here.`,r>0?`${r} ${r===1?"has":"have"} a problem.`:""].filter(Boolean).join(" ")},Le=()=>{let e=(y.selection??[]).map(s=>w.getNode(s)).find(s=>s!==void 0);if(e)return{about:"here",say:oe(e),moves:[],subject:e.id};let t=S.find(s=>s.slug===y.place)??S.find(s=>s.slug==="home");return t?{about:"here",say:`${t.title}. ${me(t)}`,moves:[],subject:t.slug}:{about:"here",say:me({slug:"home",title:"Home",kind:null,cardinality:"many",address:"/",stop:"#"}),moves:[]}},Pe=e=>{let t=P.flatMap(s=>[I(s),F(M(s),s),s].map(n=>({kind:s,name:$(n)}))).filter(s=>s.name.length>0).sort((s,n)=>n.name.length-s.name.length);for(let{kind:s,name:n}of t)if(!(` ${e} `.indexOf(` ${n} `)<0))return{kind:s,rest:` ${e} `.replace(` ${n} `," ").replace(/\s+/g," ").trim()}},ie=(e,t)=>{let s=V(p,e).filters.filter(d=>d.about==="field"&&d.type==="date");if(s.length===0)return;let n=s.find(d=>t.some(l=>$(d.key)===l||$(d.label)===l));if(n)return n;let r=M(e)?.fieldRoles??{};for(let d of["due","deadline","date","when","start","end"]){let l=r[d],v=l?s.find(x=>x.key===l):void 0;if(v)return v}return s.find(d=>["due","deadline","date","when","on","at"].includes(d.key.toLowerCase()))??(s.length===1?s[0]:void 0)},He=e=>{let t=M(e),s=V(p,e).filters;if(t?.lifecycle)return{conditions:[{key:"is",value:"current"}],holds:d=>ue(be,d,{key:"is",value:"current"})};let r=s.find(d=>d.about==="field"&&d.type==="boolean"&&ne.has($(d.key)));if(r)return{conditions:[{key:r.key,value:"false"}],holds:d=>d[r.key]!==!0};let h=s.find(d=>d.about==="field"&&d.type==="choice"&&(d.options??[]).some(l=>ne.has($(l))));if(h){let d=new Set((h.options??[]).filter(v=>ne.has($(v)))),l=(h.options??[]).filter(v=>!d.has(v));return l.length===1?{conditions:[{key:h.key,value:l[0]}],holds:v=>v[h.key]===l[0]}:"unsayable"}return{conditions:[],holds:()=>!0}},Ie=(e,t)=>{let s=e.words.startsWith("due")||$(t.key)==="due",n=Ct.test($(t.label));if(e.day)return s?`due ${e.day}`:n?`on ${e.day}`:`${t.label.toLowerCase()} on ${e.day}`;let r=e.words.replace(/^(?:due|for|on|by) (?:the )?/,"");return s?`due ${r}`:n?r:`${t.label.toLowerCase()} ${r}`},ye=new Set(c.violations().flatMap(e=>e.nodeIds)),be={schema:p,graph:c.graph,flagged:ye,today:k},ae=e=>{let t=Oe(e,k,j),s=Pe(t?.rest??e),n=s?.kind,r=(s?.rest??t?.rest??e).split(" ").filter(Boolean);if(!n&&t){let g=e.split(" "),m=P.filter(L=>ie(L,g)!==void 0),E=m.filter(L=>{let b=ie(L,g);return g.some(O=>$(b.key)===O||$(b.label)===O)}),U=m.length===1?m:E;if(U.length!==1)return;n=U[0]}if(!n)return;let h=V(p,n).filters,d=[],l=[],v=[],x=[],q=!1,de=[];for(let g=0;g<r.length;g++){let m=r[g],E=g>0&&(r[g-1]==="not"||r[g-1]==="un"),U=h.find(b=>b.about==="field"&&b.type==="choice"&&(b.options??[]).some(O=>$(O)===m));if(U&&!E){let b=(U.options??[]).find(O=>$(O)===m);d.push({key:U.key,value:b}),l.push(b);continue}let L=h.find(b=>b.about==="field"&&b.type==="boolean"&&[$(b.key),$(b.label)].some(O=>O===m||O===m.replace(/^un/,"")));if(L){let b=!E&&!(m.startsWith("un")&&!$(L.key).startsWith("un"));d.push({key:L.key,value:String(b)}),l.push(b?m:`not ${m.replace(/^un/,"")}`);continue}if(Pt.has(m)&&!E){let b=He(n);b==="unsayable"?(q=!0,x.push(O=>!ut(p,O))):(d.push(...b.conditions),x.push(b.holds)),l.push(m);continue}m==="not"||m==="un"||t&&h.some(b=>b.type==="date"&&($(b.key)===m||$(b.label)===m))||de.push(m)}if(r=de,r.some(g=>!te.has(g))||!t&&d.length===0&&x.length===0)return;let T=I(n).toLowerCase(),Q=I(n);if(t){let g=ie(n,e.split(" "));if(!g){let m={to:"kind",kind:n,title:Q,address:se(n),said:`Went to the ${T}.`};return{about:"kind",say:`${ee(Q)} carry no date, so I can't tell which are ${/^(?:due|for|on|overdue|past due|late)\b/.test(t.ask.words)?t.ask.words:`due ${t.ask.words}`}. ${m.said}`,moves:[m]}}if(t.ask.from&&d.push({key:g.key,value:`after:${C(t.ask.from,-1)}`}),t.ask.to&&d.push({key:g.key,value:`before:${C(t.ask.to,1)}`}),t.ask.overdue){let m=He(n);m==="unsayable"?(q=!0,x.push(E=>!ut(p,E))):(d.push(...m.conditions),x.push(m.holds))}t.ask.overdue?l.push("overdue"):v.push(Ie(t.ask,g))}let R=w.nodesOfKind(n).filter(g=>d.every(m=>ue(be,g,m))&&x.every(m=>m(g))),K=[...l,...v].join(" and "),Y=[...l,T,...v].join(" "),W=R.slice(0,6).map(g=>({about:"node",id:g.id,kind:n,label:H(g),why:{field:d[0]?.key??"label",reading:d[0]?.key??"Name",fragment:K,strength:"field"},current:!0,flagged:ye.has(g.id),address:ge(g)})),X=R.length===0?`No ${T} are ${K}.`:`${R.length===1?`One ${F(M(n),n)} is`:`${R.length} ${T} are`} ${K}: ${fe(R.slice(0,6).map(H))}${R.length>6?`, and ${R.length-6} more`:""}.`;if(q)return{about:"kind",say:X,moves:[],picks:W,offer:{draft:Y,label:"Show as a view"}};let Z=d.map(g=>`${g.key}:${g.value}`).join(","),we=`${se(n)}?${new URLSearchParams({filter:Z}).toString()}`,_={to:"kind",kind:n,title:ee(Y),filter:Z,address:we,said:`Went to the ${Y}.`};return{about:"kind",say:`${_.said} ${X}`,moves:[_],picks:W}},Te=e=>M(e)?.figure==="person"?!0:[e,F(M(e),e),I(e)].some(s=>$(s).split(" ").some(n=>Et.has(n))),pt=e=>{let t=[],s=n=>M(n)?.edges??{};for(let[n,r]of Object.entries(s(e)))for(let h of r.to??[])u.has(h)&&t.push({key:n,direction:"out",far:h,words:ct(`${r.description??""} ${n}`)});for(let n of P)for(let[r,h]of Object.entries(s(n)))(h.to??[]).includes(e)&&t.push({key:r,direction:"in",far:n,words:ct(`${h.inverse??""} ${r}`)});return t},mt=e=>{let t=e.match(/^(who|which|what)\b/)?.[1];if(!t)return;let s=Oe(e,k,j);if(!s||s.ask.overdue)return;let n=s.rest.split(" ").filter(Boolean),r=P.flatMap(a=>[I(a),F(M(a),a),a].map(A=>({kind:a,name:$(A)}))).filter(a=>a.name.length>0).sort((a,A)=>A.name.length-a.name.length),h=` ${n.join(" ")} `,d=[];for(let{kind:a,name:A}of r)h.includes(` ${A} `)&&(h=h.replace(` ${A} `," "),d.includes(a)||d.push(a));let l=h.match(/\b(?:is|are|was|were)\b|'s\b/)?.[0],v=h.replace(/'s\b/g," ").split(" ").filter(a=>a.length>0&&!te.has(a)&&!Ce.has(a)),x=t==="who"?d.find(Te):d[0];if(!x&&t!=="who")return;let q=d.find(a=>a!==x),de=v.flatMap(a=>[je(a),...lt.has(je(a))?[...lt]:[]]),T=P.filter(a=>q?a===q:a!==x).flatMap(a=>{let A=ie(a,e.split(" "))??V(p,a).filters.find(D=>D.about==="field"&&D.type==="date");return A?pt(a).filter(D=>(x?D.far===x:Te(D.far))&&D.far!==a).map(D=>({kind:a,field:A,relation:D,said:v.length===0||de.some(ve=>D.words.some(vt=>Lt(vt,ve)))})):[]}).filter(a=>a.said);if(T.length===0)return;let Q=T.filter(a=>n.some(A=>$(a.field.key)===A||$(a.field.label)===A)),R=T.length===1?T[0]:Q.length===1?Q[0]:void 0;if(!R)return;let{kind:K,field:Y,relation:W}=R,X=[...s.ask.from?[{key:Y.key,value:`after:${C(s.ask.from,-1)}`}]:[],...s.ask.to?[{key:Y.key,value:`before:${C(s.ask.to,1)}`}]:[]],Z=w.nodesOfKind(K).filter(a=>X.every(A=>ue(be,a,A))),we=a=>(W.direction==="out"?c.graph.out(a.id,W.key):c.graph.in(a.id,W.key)).filter(A=>A.kind===W.far&&u.has(W.far)),_=[],g=[];for(let a of Z){let A=we(a);A.length===0&&g.push(a);for(let D of A)_.some(ve=>ve.id===D.id)||_.push(D)}let m=Ie(s.ask,Y),E=s.ask.day?`On ${s.ask.day}`:ee(s.ask.words.replace(/^(?:due|for|on|by) (?:the )?/,"")),U=I(K).toLowerCase(),L=X.map(a=>`${a.key}:${a.value}`).join(","),b=`${U} ${m}`,O={to:"kind",kind:K,title:ee(b),filter:L,address:`${se(K)}?${new URLSearchParams({filter:L}).toString()}`,said:`Went to the ${b}.`};if(Z.length===0)return{about:"related",say:`No ${b}. ${O.said}`,moves:[O]};let le=v.join(" "),yt=l==="was"||l==="were",Ge=a=>yt?a===1?"was":"were":a===1?"is":"are",ce=_.map(H),bt=ce.length>8?[...ce.slice(0,8),`${ce.length-8} more`]:ce,kt=_.length===0?`${E}: nobody ${Ge(1)}${le?` ${le}`:""}.`:`${E}: ${fe(bt)}${le?` ${Ge(_.length)} ${le}`:""}.`,$t=t==="who"&&g.length>0?`${fe(g.slice(0,4).map(H))}${g.length>4?` and ${g.length-4} more`:""} ${g.length===1?"has":"have"} nobody.`:"",wt=_.slice(0,8).map(a=>({about:"node",id:a.id,kind:a.kind,label:H(a),why:{field:W.key,reading:Ze(p,W.direction==="out"?K:W.far,W.key,W.direction==="out"?"out":"in"),fragment:m,strength:"field"},current:!0,flagged:ye.has(a.id),address:ge(a)}));return{about:"related",say:[kt,$t,O.said].filter(Boolean).join(" "),moves:[O],picks:wt}},Ke=N.match(jt);if(Ke){let e=Ke[1];if(e&&!rt.has(e)&&!/^(?:it|this|that)$/.test(e)){let n=re(e),r=n?void 0:pe(z(e)||e);if(r?.one){let h=Me(r.one);return{about:"describe",say:`${h.said} ${oe(r.one)}`,moves:[h],subject:r.one.id}}if(!n)return r&&r.picks.length>0?{about:"picks",say:Re(r.picks),moves:[],picks:r.picks}:De()}if(e&&/^(?:it|this|that)$|^(?:here|this place|this page)$/.test(e)){let n=(y.selection??[]).map(r=>w.getNode(r)).find(r=>r!==void 0);if(n)return{about:"describe",say:oe(n),moves:[],subject:n.id}}let t=c.violations();if(t.length===0)return{about:"problems",say:"Nothing is wrong \u2014 every rule holds.",moves:[]};let s={to:"problems",address:"/problems",said:"Went to the problems."};return{about:"problems",say:`${s.said} ${Qe(t)}: ${t.slice(0,4).map(n=>n.message).join("; ")}${t.length>4?"\u2026":"."}`,moves:[s]}}if(Ot.test(N))return Le();let _e=mt(N);if(_e)return _e;let ke=Oe(N,k,j);if(ke&&!re(z(ke.ask.words))&&ke.rest.replace(/'s\b/g,"").split(" ").every(e=>e===""||te.has(e)||Ce.has(e))){let e=ae(N);if(e)return e}if(/^open /.test(N)){let e=ae(N);if(e)return e}let Fe=N.match(Nt)??N.match(/^(?:go|take me|head|get me)(?: back)? (home)$/);if(Fe)return Ee(Fe[1].trim(),!1);let Be=N.match(St);if(Be){let e=Ee(Be[1].trim(),!0);return"unresolved"in e&&e.unresolved&&!/^tell me|^describe/.test(N)?{unresolved:!0}:e}let $e=re(N);if($e){let e=We($e);return{about:"place",say:e.said,moves:[e],subject:$e.slug}}let Ue=ae(N);return Ue||{unresolved:!0}}var Ce=new Set(["who","whom","whose","which","what","whats","what's","who's"]),Et=new Set(["person","people","user","users","member","members","volunteer","volunteers","gardener","gardeners","player","players","staff","worker","workers","employee","employees","owner","owners","assignee","assignees","helper","helpers","student","students","teacher","teachers","customer","customers","client","clients","contact","contacts","author","authors"]),lt=new Set(["work","cover","staff","assign","do","run","schedul","roster","book","duty","serv","help"]);function je(o){let i=o.toLowerCase().replace(/'s$/,"");for(let y of["ing","ed","es","s"])if(i.length>y.length+2&&i.endsWith(y)){let f=i.slice(0,-y.length);return f.length>3&&f[f.length-1]===f[f.length-2]?f.slice(0,-1):f}return i}function ct(o){return o.toLowerCase().split(/[^a-z']+/).filter(i=>i.length>1&&!te.has(i)&&!Ce.has(i)&&!["it","they","them","their","its","this","here","to","at"].includes(i)).map(je)}var Lt=(o,i)=>o===i||o.length>=4&&i.length>=4&&(o.startsWith(i)||i.startsWith(o)),ne=new Set(["done","finished","complete","completed","closed","resolved","agreed","canceled","archived","shipped","delivered"]),Pt=new Set(["open","unfinished","outstanding","pending","remaining","undone","incomplete"]);function ut(o,i){return V(o,i.kind).filters.some(f=>f.about==="field"&&(f.type==="boolean"&&ne.has(f.key.toLowerCase())&&i[f.key]===!0||f.type==="choice"&&typeof i[f.key]=="string"&&ne.has(String(i[f.key]).toLowerCase())))}function fe(o){return o.length<=1?o[0]??"":`${o.slice(0,-1).join(", ")} and ${o[o.length-1]}`}function zt(o,i,y={}){let f=y.scene!==void 0?{...y.pages,scene:y.scene}:y.pages;return[...nt(o,i,f?{pages:f}:{})].map(({first:c,hidden:p,lens:k,...j})=>j)}function gt(o,i){return{...o.principal?{principal:o.principal}:{},...o.places?{places:o.places}:{},...o.selection?{selection:o.selection}:{},...o.place?{place:o.place}:{},...i??o.today?{today:i??o.today}:{},...o.weekStartsOn!==void 0?{weekStartsOn:o.weekStartsOn}:{}}}function Jt(o,i,y,f){let c=ht(o,i,gt(y,f));if(c.unresolved)return c.say?{reply:{say:c.say,proposals:[],grounded:!0}}:{};if(c.about==="picks")return{};let p=c.moves.length>0?{moves:c.moves}:{},k=c.subject?o.graph.getNode(c.subject):void 0;if(c.about==="problems")return{...p,problems:!0};if(k&&(c.about==="describe"||c.about==="here"))return{...p,told:k.id};let j=k?tt(o,ot(Ve(o.violations(),[k.id])).slice(0,3)):[];return{reply:{say:c.say,proposals:j,grounded:!0,...p,...c.picks&&c.picks.length>0?{picks:c.picks}:{},...c.offer?{offer:c.offer}:{}}}}function Yt(o,i,y={}){let f=gt(y),c=[];for(let p of i){let k=typeof p=="string"?p:typeof p=="object"&&p!==null&&typeof p.to=="string"?p.to:void 0;if(!k||k.trim().length===0)continue;let j=ht(o,/^(?:go|take me|open|show)\b/i.test(k.trim())?k:`go to ${k}`,f);if("moves"in j)for(let J of j.moves)c.some(B=>B.address===J.address)||c.push(J)}return c}export{At as NOTHING_BY_THAT_NAME,gt as askContextOf,Jt as goingFrom,Yt as movesFromNames,zt as placesFromViews,ht as resolveAsk};
|
|
@@ -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.6WB2TYK7.js";import"./chunk.BJUUSIQY.js";import"./chunk.CE3NKAF7.js";import"./chunk.GRTBEA7O.js";import{Qd as I,oa as O,ua as j}from"./chunk.6AANHELP.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";var m=e=>e.charAt(0).toUpperCase()+e.slice(1),N=e=>/^(?:[aeio]|u(?![sn]i|se|ser))/i.test(e),q=e=>e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"one",D=(e,s)=>e===s?`step ${e}`:`steps ${e}\u2013${s}`;function G(e){let s=e.store.schema,t=Object.fromEntries(s.definitions.map(o=>[o.kind,{noun:j(o,o.kind),plural:O(s,o.kind),fields:Object.fromEntries(Object.keys(o.fields.shape??{}).map(c=>[c,{type:"string"}])),edges:o.edges??{}}]));return{name:e.app.name??"app",kinds:t,acts:{}}}function H(e){let s=(e.store.policy?.grants??[]).filter(o=>o.mutations==="*"&&!o.self&&o.roles!=="*").flatMap(o=>o.roles),t=[...new Set(s)];return t.length>0?`${N(t[0])?"an":"a"} ${t.join(" or ")}`:"whoever may change this app"}function K(e){let s=e.place?e.places.find(t=>t.as===e.place):void 0;return s?`in ${s.title}`:"here"}async function U(e,s){let{missing:t}=s;if(!t.need)return{refused:t.said};let o=await (__graviewPreload(import.meta.url,["./chunk.7ZTGB4O7.js","./chunk.TBY5IR7C.js","./chunk.BIDL7GQD.js","./chunk.Q5WEOX3Q.js","./chunk.KAM73WVF.js","./chunk.O32F6LGK.js","./chunk.R3GE37OI.js","./chunk.2KCDLCB2.js","./chunk.UD7VLXPM.js","./chunk.3DEWQDP7.js","./chunk.6AANHELP.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.ZMADWPJO.js")),c=o.documentOfApp(e.app),k=c??G(e),a=L(k,t.need);if("refused"in a)return{refused:`${t.said} ${a.refused}`};let i=a.steps.map(n=>({part:"app",said:n})),b=i.length,C=n=>n.filter(r=>e.store.graph.getNode(r)?.kind===a.on),x=n=>[...e.store.graph.in(n),...e.store.graph.out(n)].filter(r=>r.kind===a.on).map(r=>r.id),f=C(s.members).length>0?C(s.members):[...new Set(s.members.flatMap(x))],p=[],y=f.length,w=n=>k.kinds[n]??void 0,P=n=>(w(n)?.plural??`${w(n)?.noun??n}s`).toLowerCase(),R=n=>(w(n)?.noun??n).toLowerCase(),S=s.where?`in ${s.where}`:K(e);if(y===0)return{refused:`${t.said} There is nothing here to do it to.`};let $=y===1?`the ${R(a.on)} ${S}`:`the ${y} ${P(a.on)} ${S}`,v=m(a.called);if(a.relation&&a.to){let n=t.who;if(!n)return{refused:`${t.said} Say whom to give them to.`};let r=a.made?m(a.edits[0].plural??"people"):m(P(a.to)),h=(a.made?void 0:e.store.graph.allNodes().find(d=>d.kind===a.to&&Object.values(d).some(l=>typeof l=="string"&&l.toLowerCase()===n.toLowerCase())))?.id;if(!h){h=`${a.to}-${q(n)}`;let d=a.makes??e.store.allMutations().find(l=>l.creates?.includes(a.to))?.name;if(!d){let l=e.store.graph.allNodes().filter(g=>g.kind===a.to).slice(0,3).map(g=>String(g.label??g.name??"")).filter(Boolean);return{refused:`${t.said} There is nobody called ${n} among the ${r.toLowerCase()} here${l.length>0?` (${l.join(", ")})`:""}, and no way to add one from here.`}}p.push({name:d,args:{name:n},mintedHint:h}),i.push({part:"record",said:`Add ${n} to ${r}.`})}for(let d of f)p.push({name:a.act,args:{id:d,[a.arg]:h}});let M=/^(\w+?)ed to$/i.exec(a.called)?.[1];i.push({part:"record",said:M?`${m(M.toLowerCase())} ${n} to ${$}.`:`Set \u201C${v}\u201D to ${n} on ${$}.`})}else if(a.field){let n=t.value;if(n===void 0)return{refused:`${t.said} Say what to set it to.`};for(let r of f)p.push({name:a.act,args:{id:r,[a.arg]:n}});i.push({part:"record",said:`Set \u201C${v}\u201D to ${n} on ${$}.`})}let A=i.length;if(!(!!c&&s.host&&s.compose!==void 0&&o.mayChangeDeclaration(e.store,e.principal))){let n=c?!s.host||!s.compose?"whoever hosts this app":H(e):"whoever develops this app";return{question:`${t.said} ${m(n)} would add ${D(1,b)}; then I can do ${D(b+1,A)}.`,parts:i,whoMay:n}}let E=s.compose({document:c,edits:a.edits});if(!E.ok)return{refused:`${t.said} That change could not be made here.`};let u=E.app;try{new I({schema:u.schema,mutations:u.mutations??[],invariants:u.invariants??[],...u.policy?{policy:u.policy}:{},snapshot:e.store.graph.snapshot()}).previewAll(p,{author:e.principal})}catch{return{refused:`${t.said} I could not make that work here.`}}return{question:`${t.said} I can do it in ${A} steps. Should I?`,parts:i,proposal:{said:s.said,add:[],drop:[],card:{said:i.map(n=>n.said).join(" "),adds:[],keeps:[],drops:[],breaking:[]},edits:a.edits,records:p,via:`ai:${e.ai.name??"model"}`}}}export{U as planFor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{E as b,R as c,S as T,U as p,V as D}from"./chunk.
|
|
1
|
+
import{E as b,R as c,S as T,U as p,V as D}from"./chunk.6AANHELP.js";var S=864e5,N=/^(\d{4})-(\d{2})-(\d{2})/,s=n=>String(n).padStart(2,"0"),g=n=>new Date(n).toISOString().slice(0,10),m=n=>Date.UTC(+n.slice(0,4),+n.slice(5,7)-1,+n.slice(8,10)),W=(n,e)=>g(m(n)+e*S),M=n=>new Date(m(n)).getUTCDay();function A(n,e,t){if(!(e>=1&&e<=12&&t>=1&&t<=31))return;let r=`${String(n).padStart(4,"0")}-${s(e)}-${s(t)}`;return g(m(r))===r?r:void 0}function O(n=new Date){let e=c();return e?p(n.getTime(),e):{day:`${n.getFullYear()}-${s(n.getMonth()+1)}-${s(n.getDate())}`,minutes:n.getHours()*60+n.getMinutes()}}var $=n=>/T\d\d:\d\d(:[\d.]+)?(Z|[+-]\d\d:?\d\d)$/.test(n);function f(n){if(typeof n!="string")return;if($(n)){let r=new Date(n);return Number.isNaN(r.getTime())?void 0:O(r)}let e=/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2}))?/.exec(n);if(!e||!A(Number(e[1]),Number(e[2]),Number(e[3])))return;let t=n.slice(0,10);return e[4]===void 0?{day:t}:{day:t,minutes:Number(e[4])*60+Number(e[5])}}function x(n,e){if(!e.time)return n.day;let t=n.minutes??9*60;if(!e.instant)return`${n.day}T${s(Math.floor(t/60))}:${s(t%60)}`;let r=c(),[,i,a,d]=N.exec(n.day);return(r?new Date(D(n.day,t,r)):new Date(Number(i),Number(a)-1,Number(d),Math.floor(t/60),t%60)).toISOString().replace(/\.\d{3}Z$/,"Z")}function Z(n,e=new Date){let t=T(),r=t;try{r=new Intl.DateTimeFormat(n??b,{timeZoneName:"short",timeZone:t}).formatToParts(e).find(i=>i.type==="timeZoneName")?.value??t}catch{r=t}return{zone:t,short:r}}function z(n,e,t,r){let i=f(e);if(!i)return t;let a=n===void 0?void 0:f(n),d=t===void 0?void 0:f(t),o=u=>m(u.day)+(u.minutes??0)*6e4,l=(u,h)=>{let y=o(u)+h;return{day:g(y),...r.time?{minutes:Math.round(y%S/6e4)}:{}}};return a&&d?x(l(d,o(i)-o(a)),r):d&&o(d)>=o(i)?t:r.time?x(l(i,36e5),r):t}var _=/^(start|starts|startsAt|startsOn|startAt|begins|from|opens|checkIn)$/i,w=/^(end|ends|endsAt|endsOn|endAt|until|to|finish|finishes|closes|through|checkOut)$/i;function F(n,e={}){let t=(e.start&&n.includes(e.start)?e.start:void 0)??n.find(i=>_.test(i)),r=(e.end&&n.includes(e.end)?e.end:void 0)??n.find(i=>i!==t&&w.test(i));return t&&r?{start:t,end:r}:void 0}export{S as a,m as b,W as c,M as d,A as e,O as f,$ as g,f as h,x as i,Z as j,z as k,F as l};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{G as w,Qa as c,da as f,ea as h,ga as g}from"./chunk.
|
|
1
|
+
import{G as w,Qa as c,da as f,ea as h,ga as g}from"./chunk.3VEZ5MOC.js";import{b as m}from"./chunk.AJZBJBMO.js";var d=m(w(),1);function j(){let e=c();return(0,d.useMemo)(()=>[...new Set(e.flatMap(n=>n.nodeIds))],[e])}function x(){let e=I(),n=f();return(0,d.useMemo)(()=>{if(!n)return e;let t=n.matched;return t.length===0&&e.length===0?[k]:[...new Set([...e,...t])]},[n,e])}function I(){let{store:e,selection:n}=h(),t=g(),r=c();return(0,d.useMemo)(()=>{if(n.length===0)return v;let u=n.join(`
|
|
2
2
|
`),s=y.get(e);if(s&&s.violations===r&&s.key===u)return s.reached;let a=new Set(n),i=new Set(a);for(let o of e.graph.allEdges())a.has(o.from)&&i.add(o.to),a.has(o.to)&&i.add(o.from);for(let o of r)if(o.subjectId!==void 0&&a.has(o.subjectId))for(let p of o.nodeIds)i.add(p);let l=[...i];return y.set(e,{violations:r,key:u,reached:l}),l},[e,n,t,r])}var v=[],y=new WeakMap,k="search:nothing";export{j as a,x as b,I as c};
|