graview 0.1.59 → 0.1.60
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/README.md +4 -2
- package/dist/preview/chunk.2K4TT2BV.js +1 -0
- package/dist/preview/{chunk.J4HTSXUA.js → chunk.2USDHXB4.js} +1 -1
- package/dist/preview/{chunk.LHJWII6C.js → chunk.37TVS7CA.js} +1 -1
- package/dist/preview/chunk.3IZ3ABII.js +1 -0
- package/dist/preview/{chunk.E22DDEQI.js → chunk.3MOJF7BA.js} +1 -1
- package/dist/preview/{chunk.2XTCDFWU.js → chunk.3UOKUF5Z.js} +1 -1
- package/dist/preview/{chunk.MOAUE3N2.js → chunk.3V4WP7RY.js} +3 -3
- package/dist/preview/{chunk.IZ2ZTNEV.js → chunk.3XGA65Y3.js} +1 -1
- package/dist/preview/{chunk.TCPTVTFU.js → chunk.3ZT5WQYL.js} +1 -1
- package/dist/preview/{chunk.DWHPZBPZ.js → chunk.4LR64TPU.js} +1 -1
- package/dist/preview/{chunk.VNJKGSGZ.js → chunk.4MP72LPR.js} +1 -1
- package/dist/preview/{chunk.IPPZEGBX.js → chunk.4TCKEG6I.js} +1 -1
- package/dist/preview/{chunk.EZ3CRUBU.js → chunk.5DD62IOW.js} +2 -2
- package/dist/preview/{chunk.DGM3Y2FB.js → chunk.5YOLUDVO.js} +1 -1
- package/dist/preview/{chunk.VFRURRNI.js → chunk.67U6M7OV.js} +1 -1
- package/dist/preview/{chunk.2NJDT47T.js → chunk.6C2MHWSX.js} +1 -1
- package/dist/preview/{chunk.CYUMQPMH.js → chunk.6HF6POIX.js} +1 -1
- package/dist/preview/{chunk.KOGUYWHG.js → chunk.6WHAWOO7.js} +1 -1
- package/dist/preview/{chunk.N4LOI3YA.js → chunk.6ZQAR5ZA.js} +1 -1
- package/dist/preview/{chunk.2QESVWUW.js → chunk.7MHCGVGM.js} +1 -1
- package/dist/preview/{chunk.VNBEAF62.js → chunk.7N32AVIJ.js} +1 -1
- package/dist/preview/{chunk.CIB65YO6.js → chunk.7OPM55I2.js} +1 -1
- package/dist/preview/chunk.7TFLRR7D.js +1 -0
- package/dist/preview/{chunk.Q6LLURRM.js → chunk.7VKSXGTX.js} +1 -1
- package/dist/preview/{chunk.CLR6KAA3.js → chunk.A3ZXDG6V.js} +1 -1
- package/dist/preview/{chunk.2FOIJ5ID.js → chunk.A5PDXNY6.js} +1 -1
- package/dist/preview/{chunk.6O3YPUW3.js → chunk.AVBTPSQF.js} +1 -1
- package/dist/preview/{chunk.ZT3NEAFI.js → chunk.BF6S5UE4.js} +1 -1
- package/dist/preview/chunk.BLPYNNR4.js +1 -0
- package/dist/preview/{chunk.BDBLGGFJ.js → chunk.BQIHNT7C.js} +1 -1
- package/dist/preview/{chunk.B5HLA45D.js → chunk.BRT27WON.js} +1 -1
- package/dist/preview/{chunk.DO45KXLM.js → chunk.BXDM3UMN.js} +1 -1
- package/dist/preview/chunk.BYKD5RLA.js +1 -0
- package/dist/preview/chunk.C7OLSEWK.js +1 -0
- package/dist/preview/{chunk.WGTBQHHE.js → chunk.CC5BJH5A.js} +1 -1
- package/dist/preview/{chunk.HF5SNUTK.js → chunk.CFKZXLXS.js} +1 -1
- package/dist/preview/chunk.CMN6BBAD.js +1 -0
- package/dist/preview/{chunk.Z4CJJ4QP.js → chunk.CQT3W2SF.js} +1 -1
- package/dist/preview/{chunk.NOLGJFA4.js → chunk.D7YSL3NK.js} +2 -2
- package/dist/preview/{chunk.G2TCFWYX.js → chunk.DCHQHKSA.js} +1 -1
- package/dist/preview/{chunk.UFTAGUTU.js → chunk.EL5ICOOM.js} +1 -1
- package/dist/preview/{chunk.OVSZXILB.js → chunk.ENL2JJ47.js} +1 -1
- package/dist/preview/chunk.EQXB7LKI.js +1 -0
- package/dist/preview/{chunk.KE6ZRUMP.js → chunk.ERFT54HT.js} +1 -1
- package/dist/preview/{chunk.P6CHNBRR.js → chunk.F6V7RWDK.js} +1 -1
- package/dist/preview/{chunk.GDUM2UOM.js → chunk.FBJARKDT.js} +1 -1
- package/dist/preview/{chunk.QL555VQ2.js → chunk.FC6AF6CC.js} +1 -1
- package/dist/preview/{chunk.HVUUJQRE.js → chunk.FFTYMBBT.js} +1 -1
- package/dist/preview/chunk.FLUK3UXF.js +1 -0
- package/dist/preview/{chunk.UM5H2VVR.js → chunk.FRYBMS3W.js} +1 -1
- package/dist/preview/chunk.G3R4BTI7.js +1 -0
- package/dist/preview/{chunk.GQHFLOTZ.js → chunk.G4YJPKRG.js} +2 -2
- package/dist/preview/{chunk.MHILFBK6.js → chunk.GLWSVSQL.js} +1 -1
- package/dist/preview/{chunk.WTUB7W2D.js → chunk.GNBIVVL3.js} +1 -1
- package/dist/preview/{chunk.SU6WKQ73.js → chunk.GTKJJYQH.js} +1 -1
- package/dist/preview/{chunk.VS25R6R2.js → chunk.H45Q3O4F.js} +1 -1
- package/dist/preview/{chunk.6N7LNTB6.js → chunk.HDP3PS7N.js} +1 -1
- package/dist/preview/{chunk.QLTHHWBA.js → chunk.HDUO2USQ.js} +1 -1
- package/dist/preview/{chunk.2MFXP3FB.js → chunk.HUJ6YTWE.js} +1 -1
- package/dist/preview/{chunk.2FP4KEEG.js → chunk.I4XQBQRC.js} +1 -1
- package/dist/preview/chunk.IBOKXVWN.js +1 -0
- package/dist/preview/{chunk.4T5QIZKB.js → chunk.IGJZ4UH3.js} +2 -2
- package/dist/preview/{chunk.4QWTSI7V.js → chunk.IGVASEZU.js} +1 -1
- package/dist/preview/{chunk.CZH27V2R.js → chunk.IHBUBZQT.js} +1 -1
- package/dist/preview/chunk.IOK4GVJC.js +1 -0
- package/dist/preview/{chunk.ZUKYMU6C.js → chunk.JEYQBH33.js} +1 -1
- package/dist/preview/{chunk.S6VON4LU.js → chunk.JJGCTGWA.js} +1 -1
- package/dist/preview/{chunk.LKE2FBXL.js → chunk.JPONLMU7.js} +1 -1
- package/dist/preview/{chunk.Q3Y5EV5A.js → chunk.KBVTLNS5.js} +3 -3
- package/dist/preview/{chunk.YMRVKG6W.js → chunk.KDRLUBVF.js} +1 -1
- package/dist/preview/{chunk.YGZCESXY.js → chunk.KGW75Z5L.js} +1 -1
- package/dist/preview/{chunk.R4YDAJRL.js → chunk.KI37ZEV3.js} +1 -1
- package/dist/preview/chunk.L6AWE76F.js +1 -0
- package/dist/preview/{chunk.NIFQDN6R.js → chunk.LGEA5257.js} +1 -1
- package/dist/preview/{chunk.KKQXGN5U.js → chunk.LLYRFVIN.js} +1 -1
- package/dist/preview/{chunk.WEGPDJTB.js → chunk.LQVAABPS.js} +1 -1
- package/dist/preview/{chunk.4OMOP77U.js → chunk.LSY256J4.js} +1 -1
- package/dist/preview/{chunk.OLW44AP5.js → chunk.LZIBQ3VX.js} +1 -1
- package/dist/preview/{chunk.W2VOD6SD.js → chunk.M4UD4ARP.js} +1 -1
- package/dist/preview/chunk.MDJWK5W2.js +1 -0
- package/dist/preview/{chunk.QT6UV7HN.js → chunk.MJVYWLQQ.js} +1 -1
- package/dist/preview/{chunk.NSGQXCH6.js → chunk.MSWWWLEA.js} +1 -1
- package/dist/preview/{chunk.XOTES3PI.js → chunk.MVWC3VR3.js} +2 -2
- package/dist/preview/{chunk.V6EEDYYW.js → chunk.NC7FXY2H.js} +1 -1
- package/dist/preview/{chunk.MRYN42EQ.js → chunk.NGTRL5U4.js} +1 -1
- package/dist/preview/{chunk.ZLMI2NHC.js → chunk.NHUQ2N6J.js} +1 -1
- package/dist/preview/{chunk.LDYOQCY7.js → chunk.OLFJH4RK.js} +1 -1
- package/dist/preview/{chunk.3UTRR5YM.js → chunk.P6RORYOT.js} +1 -1
- package/dist/preview/{chunk.T227XQIO.js → chunk.PFSYXD6Q.js} +1 -1
- package/dist/preview/chunk.PHJ6WPWH.js +1 -0
- package/dist/preview/{chunk.HKINU7VO.js → chunk.PI44XMY2.js} +1 -1
- package/dist/preview/{chunk.P3CUCDHO.js → chunk.PNW5K7BW.js} +1 -1
- package/dist/preview/{chunk.6VNKGTLF.js → chunk.QBLKTFF4.js} +1 -1
- package/dist/preview/{chunk.ATVPAYS6.js → chunk.QDSEVPF3.js} +1 -1
- package/dist/preview/chunk.QFUMFQJU.js +1 -0
- package/dist/preview/{chunk.JPNBQFJ3.js → chunk.QHDCTAD7.js} +1 -1
- package/dist/preview/{chunk.P52UTBNO.js → chunk.QI4SLPQ4.js} +2 -2
- package/dist/preview/{chunk.ATSKKTUO.js → chunk.RQOX5YDW.js} +1 -1
- package/dist/preview/{chunk.VDGMFX5C.js → chunk.RXYNW5QB.js} +1 -1
- package/dist/preview/{chunk.ROHSF4WM.js → chunk.SB2PZKN5.js} +1 -1
- package/dist/preview/{chunk.3XIIJHQ6.js → chunk.SRVQJZRT.js} +1 -1
- package/dist/preview/{chunk.BPC4XQFZ.js → chunk.T7LQD67N.js} +2 -2
- package/dist/preview/{chunk.D3AISGQH.js → chunk.TAT2IQUR.js} +1 -1
- package/dist/preview/{chunk.E2REVMAG.js → chunk.TFWIG6LL.js} +1 -1
- package/dist/preview/{chunk.U5PX2ECA.js → chunk.TKVLNBRD.js} +1 -1
- package/dist/preview/{chunk.KSVJHSRH.js → chunk.TLJOZSDD.js} +1 -1
- package/dist/preview/{chunk.VGHZQEHS.js → chunk.TLWT67ON.js} +1 -1
- package/dist/preview/{chunk.AXXYJCSW.js → chunk.TY4GQJKC.js} +1 -1
- package/dist/preview/{chunk.SZG6HJWH.js → chunk.UITT6JWW.js} +1 -1
- package/dist/preview/{chunk.UHUBQ4EX.js → chunk.UJTE7UAP.js} +1 -1
- package/dist/preview/{chunk.GR2B7SKI.js → chunk.ULL6ZIJJ.js} +1 -1
- package/dist/preview/{chunk.HJOVOA52.js → chunk.UQWTZJBV.js} +1 -1
- package/dist/preview/{chunk.7JOG6XFC.js → chunk.URWAFZHF.js} +1 -1
- package/dist/preview/{chunk.BFN6B4C4.js → chunk.VADQ7ZGA.js} +1 -1
- package/dist/preview/chunk.VDMDPZ6U.js +1 -0
- package/dist/preview/{chunk.ZFH4SCCF.js → chunk.VFOON3Z3.js} +1 -1
- package/dist/preview/{chunk.QXMQUIQZ.js → chunk.VMV464JK.js} +1 -1
- package/dist/preview/{chunk.CUJX3IVA.js → chunk.VNDKKTED.js} +1 -1
- package/dist/preview/chunk.VSCIXAHN.js +5 -0
- package/dist/preview/{chunk.IIESMHXY.js → chunk.VUBNBTJP.js} +2 -2
- package/dist/preview/{chunk.MZJ3KTEU.js → chunk.VWJGQDCE.js} +1 -1
- package/dist/preview/{chunk.UITZ74YJ.js → chunk.VZJWJ5XM.js} +1 -1
- package/dist/preview/{chunk.RKZ4J3H2.js → chunk.W3W54DSX.js} +1 -1
- package/dist/preview/{chunk.6IUEGPCZ.js → chunk.WC3DENU4.js} +2 -2
- package/dist/preview/chunk.WQ6RCEUQ.js +1 -0
- package/dist/preview/{chunk.QC4YXFF7.js → chunk.WXUFATY5.js} +1 -1
- package/dist/preview/{chunk.QHU3KUZZ.js → chunk.X6A4VSSD.js} +1 -1
- package/dist/preview/{chunk.U7G56KXT.js → chunk.XGASJAV2.js} +1 -1
- package/dist/preview/{chunk.M3JIIF32.js → chunk.XR6YR6RV.js} +1 -1
- package/dist/preview/chunk.XZPKBHJT.js +1 -0
- package/dist/preview/{chunk.S7ZLGODY.js → chunk.Y5C4RXG7.js} +1 -1
- package/dist/preview/{chunk.L3K25NCS.js → chunk.Y7G3OGDE.js} +1 -1
- package/dist/preview/{chunk.E4SYOBGB.js → chunk.YEBGI6ED.js} +1 -1
- package/dist/preview/{chunk.G7HIAUEA.js → chunk.YFSBVZTG.js} +1 -1
- package/dist/preview/chunk.YFVJUHAK.js +1 -0
- package/dist/preview/{chunk.7XSDXX5Z.js → chunk.YH63KQ2G.js} +1 -1
- package/dist/preview/{chunk.F6P3WSMW.js → chunk.YZ7FUKAL.js} +1 -1
- package/dist/preview/{chunk.7AMBLGVB.js → chunk.Z2ERZ4S6.js} +1 -1
- package/dist/preview/{chunk.X2G4ZRB2.js → chunk.ZP5RT2EK.js} +1 -1
- package/dist/preview/{chunk.PS5SEND3.js → chunk.ZXOT3IXJ.js} +1 -1
- package/dist/preview/{chunk.EGJUFZD5.js → chunk.ZYM2SSGW.js} +1 -1
- package/dist/preview/index.html +50 -50
- package/dist/preview/page.js +2 -2
- package/package.json +6 -6
- package/dist/preview/chunk.3XLOFZRM.js +0 -1
- package/dist/preview/chunk.6BLNFVB4.js +0 -1
- package/dist/preview/chunk.6E36I2GC.js +0 -1
- package/dist/preview/chunk.CJUIJ6TL.js +0 -1
- package/dist/preview/chunk.FJTVY6AE.js +0 -1
- package/dist/preview/chunk.KHZA5F7A.js +0 -1
- package/dist/preview/chunk.LDLTQNJ2.js +0 -1
- package/dist/preview/chunk.MMWLLWFS.js +0 -1
- package/dist/preview/chunk.PCVPH5KM.js +0 -1
- package/dist/preview/chunk.QDZAITMN.js +0 -1
- package/dist/preview/chunk.U37WZMUO.js +0 -1
- package/dist/preview/chunk.U5JFW2YM.js +0 -1
- package/dist/preview/chunk.V5MOMBZG.js +0 -1
- package/dist/preview/chunk.VUSJ7HPC.js +0 -1
- package/dist/preview/chunk.VXRECLX6.js +0 -1
- package/dist/preview/chunk.W66VMALY.js +0 -1
- package/dist/preview/chunk.WGVIJDV5.js +0 -1
- package/dist/preview/chunk.X3MMJ3QC.js +0 -5
- package/dist/preview/chunk.X5YRNNHU.js +0 -1
- package/dist/preview/chunk.YMC2T2HN.js +0 -1
- package/dist/preview/chunk.YN6BXZHO.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
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 Ge}from"./chunk.BJUUSIQY.js";import{a as Ke}from"./chunk.
|
|
2
|
-
`),unknownWords:r,questions:f,toolMistakes:d}}var Sn=e=>/^(?:aggregate|kind):([^,]+)$/.exec(e)?.[1];function Xe(e,n){let t=e.about??[];if(e.field!==void 0&&e.on!==void 0&&n(e.on))return{on:"field",id:e.on,field:e.field};let i=t.filter(n);if(i.length>1)return{on:"selection",ids:i};if(e.on!==void 0&&n(e.on))return{on:"record",id:e.on};if(i.length===1)return{on:"record",id:i[0]};let o=[e.on,...t].map(r=>r===void 0?void 0:Sn(r)).find(r=>r!==void 0);return e.place!==void 0?{on:"lens",place:e.place,...o?{kind:o}:{}}:o!==void 0?{on:"list",kind:o}:{on:"place",place:"home"}}var Q=e=>e.on==="record"||e.on==="field"?[e.id]:e.on==="selection"?e.ids:e.on==="act"&&e.id!==void 0?[e.id]:[],ye=(e,n)=>e.tryDefinition(n)?.fields?.shape??{},Y=(e,n)=>e.tryDefinition(n)?.edges??{},ge=(e,n)=>new Set(e.tryDefinition(n)?.display?.hide??[]),L=(e,n)=>ce(e.tryDefinition(n.kind),n),$e=(e,n,t)=>Ne(e.tryDefinition(n),t)||B(t),Ce=e=>typeof e=="boolean"?e?"yes":"no":String(e);function me(e,n){let t=e.kindsKeptFrom(n);return new Set(e.schema.kinds.filter(i=>!t.has(i)))}function Re(e,n,t,i){if(!e.permits(n,t).ok)return!1;if(!i)return!0;try{return e.previewAll([n],{author:t}).ops.length>0}catch{return!1}}function he(e,n,t){let i=e,{principal:o}=t,r=t.each??8,f=ee(i)?.store??i,d=f.seenBy(o),c=f.schema,a=me(f,o),s=l=>{let h=d.graph.getNode(l);return h&&a.has(h.kind)?h:void 0},u=f.allMutations(),g=new Map(u.map(l=>[l.name,l])),b=[],C=new Set,A=l=>{C.has(l.id)||(C.add(l.id),b.push(l))},m=l=>l.slice(0,r),x=Q(n).filter(l=>s(l)!==void 0);if(Q(n).length>0&&x.length===0)return{target:n,candidates:[]};let O=x.length===1?s(x[0]):void 0,k=O?.kind??(n.on==="list"?n.kind:n.on==="lens"?n.kind??t.places?.find(l=>l.as===n.place)?.kind:void 0)??(n.on==="selection"?s(x[0])?.kind:void 0);if(k!==void 0&&!a.has(k))return{target:n,candidates:[]};let p=(l,h)=>`act:${l}${Object.keys(h).length>0?`:${Object.values(h).map(R=>String(R)).join(",")}`:""}`,w=(l,h,R,E,$)=>{l.destructive||Object.values(h).some(y=>typeof y=="string"&&f.graph.has(y)&&s(y)===void 0)||Re(f,{name:l.name,args:{...h}},o,E.length===0)&&A({type:"act",id:p(l.name,h),label:R,description:$??l.description??R,mutation:l.name,args:h,asks:E})};if(n.on!=="place"||t.acts)if(t.acts)for(let l of t.acts){let h=g.get(l.mutation);!h||l.destructive||n.on==="act"&&l.mutation!==n.act||w(h,l.args,l.label,(l.open??[]).filter(R=>!R.optional).map(R=>R.name),l.why)}else{let l=O?[O]:[];for(let h of u){if(n.on==="act"&&h.name!==n.act)continue;let R=h.input.shape??{},E=$=>Object.entries(R).filter(([y,v])=>y!==$&&v.safeParse?.(void 0).success===!1).map(([y])=>y);if(h.subject)for(let $ of l)fe(c,h).includes($.kind)&&w(h,{[h.subject.arg]:$.id},`${h.title??B(h.name)}: ${L(c,$)}`,E(h.subject.arg));else k!==void 0&&(h.creates??[]).includes(k)&&w(h,{},h.title??B(h.name),E(void 0))}}let T=b.filter(l=>l.type==="act");b.splice(0,b.length,...m(T));let F=(l,h)=>{let R=Le(c,u).get(l.kind),E=ye(c,l.kind),$=ge(c,l.kind),y=[];for(let[v,j]of Object.entries(E)){if(h!==void 0?v!==h:$.has(v)||l[v]!==void 0)continue;let D=pe(j),J=D?.type==="enum"?D.options??[]:D?.type==="boolean"?[!0,!1]:[];if(J.length===0)continue;let _=(R?.get(v)??[]).map(N=>g.get(N)).find(N=>N?.subject!==void 0&&Re(f,{name:N.name,args:{[N.subject.arg]:l.id,[v]:J.find(Se=>Se!==l[v])??J[0]}},o,!0));if(_?.subject)for(let N of J)l[v]!==N&&y.push({type:"fill",id:`fill:${l.id}:${v}:${Ce(N)}`,label:`${$e(c,l.kind,v)}: ${Ce(N)}`,description:`Set ${$e(c,l.kind,v).toLowerCase()} of ${L(c,l)} to ${Ce(N)}`,record:l.id,field:v,value:N,call:{name:_.name,args:{[_.subject.arg]:l.id,[v]:N}}})}for(let[v,j]of Object.entries(Y(c,l.kind))){if(h!==void 0&&v!==h)continue;let D=j.to==="*"?[...a]:j.to.filter(I=>a.has(I)),J=new Set(d.graph.out(l.id,v).map(I=>I.id)),_=u.find(I=>(I.connects??[]).includes(v)&&I.subject!==void 0&&fe(c,I).includes(l.kind));if(!_?.subject)continue;let N=De(_.input).find(I=>I.name!==_.subject.arg);if(!N)continue;let Se=D.flatMap(I=>N.kinds.length===0||N.kinds.includes(I)?d.graph.nodesOfKind(I):[]).filter(I=>I.id!==l.id&&!J.has(I.id)&&s(I.id)!==void 0);for(let I of m(Se)){let Me={name:_.name,args:{[_.subject.arg]:l.id,[N.name]:I.id}};Re(f,Me,o,!0)&&y.push({type:"fill",id:`fill:${l.id}:${v}:${I.id}`,label:`${B(v)}: ${L(c,I)}`,description:`Link ${L(c,l)} to ${L(c,I)}${j.description?` as ${j.description}`:""}`,record:l.id,field:v,value:I.id,call:Me})}}return y};if(n.on==="field"&&O)for(let l of F(O,n.field))A(l);else if(O&&n.on==="record")for(let l of m(F(O)))A(l);let q=l=>{let h=W(c,l).toLowerCase(),R=[{type:"panel",id:`panel:${l}:list`,label:`A list of ${h}`,description:`Every ${G(c.tryDefinition(l),l).toLowerCase()} this viewer may see, as a list`,panel:{lens:"blocks",kind:l}}],E=ge(c,l);for(let[$,y]of Object.entries(ye(c,l))){if(E.has($))continue;let v=pe(y),j=$e(c,l,$).toLowerCase();if(v?.type==="enum")R.push({type:"panel",id:`panel:${l}:group:${$}`,label:`${V(h)} by ${j}`,description:`A list of ${h} grouped by ${j}`,panel:{lens:"blocks",kind:l,group:$}}),R.push({type:"panel",id:`panel:${l}:columns:${$}`,label:`Columns of ${h} by ${j}`,description:`${V(h)} in a column for each ${j}`,panel:{lens:"columns",kind:l,column:$}});else if(v?.type==="number"||v?.type==="integer"||v?.type==="date"||v?.type==="datetime"){let D=v.type==="date"||v.type==="datetime";R.push({type:"panel",id:`panel:${l}:sort:${$}`,label:`${V(h)} by ${j}`,description:`A list of ${h}, the ${D?"latest":"highest"} ${j} first`,panel:{lens:"blocks",kind:l,sort:{by:$,direction:"desc"}}}),D&&R.push({type:"panel",id:`panel:${l}:calendar:${$}`,label:`A calendar of ${h}`,description:`${V(h)} on a calendar by ${j}`,panel:{lens:"calendar",kind:l,start:$}})}}return R},H=n.on==="place"?[...a]:k!==void 0?[k]:[];for(let l of H)for(let h of m(q(l)))A(h);for(let l of m((t.places??[]).filter(h=>h.kind===void 0?n.on==="place":a.has(h.kind)&&(n.on==="place"||h.kind===k))))n.on==="lens"&&l.as===n.place||A({type:"place",id:`place:${l.as}`,label:l.title,description:`Go to ${l.title}`,place:l.as});if(O){let l=[];for(let[h,R]of Object.entries(Y(c,O.kind)))for(let E of d.graph.out(O.id,h))s(E.id)&&l.push({type:"record",id:`record:${E.id}`,label:L(c,E),description:`${V(R.description??B(h))}: ${L(c,E)}`,record:E.id,relation:h});for(let h of c.kinds)for(let[R,E]of Object.entries(Y(c,h)))if(!(E.to!=="*"&&!E.to.includes(O.kind)))for(let $ of d.graph.in(O.id,R))$.kind===h&&s($.id)&&l.push({type:"record",id:`record:${$.id}`,label:L(c,$),description:`${V(E.inverse??B(R))}: ${L(c,$)}`,record:$.id,relation:R});for(let h of m(l))A(h)}else if(n.on==="list"||n.on==="lens")for(let l of m(k!==void 0?d.graph.nodesOfKind(k):[]))s(l.id)&&A({type:"record",id:`record:${l.id}`,label:L(c,l),description:`Open ${L(c,l)}`,record:l.id});else if(n.on==="selection")for(let l of x){let h=s(l);A({type:"record",id:`record:${l}`,label:L(c,h),description:`Open ${L(c,h)}`,record:l})}return{target:n,candidates:b}}var V=e=>e&&`${e[0].toUpperCase()}${e.slice(1)}`,xn={columns:["board","kanban","column","lane","pipeline","stage","funnel"],board:["board","map","floor","layout","seat","slot"],calendar:["calendar","schedule","date","due","month","week","agenda","deadline","day"],timeline:["timeline","gantt","schedule","roadmap","span"],coverage:["coverage","matrix","grid","gap"],plan:["plan","floor","map","region","area"],blocks:["list","table","summary","overview","dashboard","card"]},On=new Set(["a","an","the","of","for","my","our","me","us","to","with","and","in","on","by","that","which","i","we","want","need","show","open","go","draw","make","new","view","views","panel","panels","page","lens","please","all","every","some","see","can","could","would","like","one","what","is","are","do","does","here","there","how","it","this","these","those"]),te=e=>e.length>3&&e.endsWith("ies")?`${e.slice(0,-3)}y`:e.length>3&&e.endsWith("s")&&!e.endsWith("ss")?e.slice(0,-1):e,Te=e=>e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").split(/[^a-z0-9]+/).filter(Boolean);function Ze(e,n,t){let i=e,o=ee(i)?.store??i,r=o.schema,f=me(o,t.principal),d=o.seenBy(t.principal),c=Q(n),a=new Set;for(let p of c){let w=d.graph.getNode(p)?.kind;w!==void 0&&f.has(w)&&a.add(w)}if(c.length>0&&a.size===0)return[];if(n.on==="list"&&a.add(n.kind),n.on==="lens"){let p=n.kind??t.places.find(w=>w.as===n.place)?.kind;p!==void 0&&a.add(p)}let s=new Map;for(let p of r.kinds){if(!f.has(p))continue;let w=r.tryDefinition(p);for(let T of[p,G(w,p),W(r,p)])for(let F of Te(T))s.set(te(F),p)}let u=Te(t.said??"").filter(p=>!On.has(p)),g=new Set,b=[];for(let p of u){let w=s.get(te(p));w!==void 0?g.add(w):b.push(te(p))}let C=g.size>0?g:a;if((t.said??"").trim()!==""&&u.length===0)return[];if(C.size===0&&u.length===0)return[];let A=[];t.places.forEach((p,w)=>{if(p.hidden||n.on==="lens"&&p.as===n.place)return;let T=p.over??(p.kind!==void 0?[p.kind]:[]);if(T.length>0&&!T.some(H=>f.has(H)))return;let F=T.some(H=>C.has(H)),q=!F&&(p.reads??[]).some(H=>C.has(H));C.size>0&&!F&&!q||A.push({place:p,own:F,reads:q,at:w})});let m=p=>new Set(Te(p.title).map(te)),x=new Set(b.filter(p=>A.some(({place:w})=>m(w).has(p)))),O=[];for(let{place:p,own:w,reads:T,at:F}of A){let q=m(p),H=new Set((xn[p.lens??""]??[]).map(te)),l=b.filter($=>q.has($)||H.has($)&&!x.has($)).length,h=b.length-l;if(b.length>0&&l===0)continue;let R=!T&&h===0?"full":"partial",E=(w?4:T?2:1)+l*2-h+(R==="full"?1:0);O.push({view:{place:p.as,title:p.title,...p.kind!==void 0?{kind:p.kind}:{},fit:R},score:E,at:F})}return O.filter((p,w)=>!O.slice(0,w).some(T=>T.view.place===p.view.place&&T.view.title===p.view.title)).sort((p,w)=>w.score-p.score||p.at-w.at).slice(0,t.most??3).map(p=>p.view)}var Ee=new WeakMap;function vn(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619)>>>0;return n.toString(36)}function $n(e,n){let t=e,i=ee(t)?.store??t,o=i.schema,r=me(i,n),d=i.allMutations().filter(A=>!A.destructive&&i.permits({name:A.name,args:{}},n).ok!==!1),c=`${[...r].join(",")}|${d.map(A=>A.name).join(",")}`,a=Ee.get(o)?.get(c);if(a)return a;let s=[...r].map(A=>{let m=ge(o,A),x={};for(let[w,T]of Object.entries(ye(o,A))){if(m.has(w))continue;let F=pe(T);F&&(x[w]=F.type==="enum"?`enum:${(F.options??[]).join("|")}`:F.type)}let O={};for(let[w,T]of Object.entries(Y(o,A)))O[w]=T.to==="*"?[...r]:T.to.filter(F=>r.has(F));let k=o.tryDefinition(A),p=Object.entries(k?.fieldAliases??{}).filter(([w,T])=>w in x&&T.length>0);return{kind:A,noun:G(o.tryDefinition(A),A),plural:W(o,A),fields:x,relations:O,...k?.aliases&&k.aliases.length>0?{aliases:k.aliases}:{},...p.length>0?{fieldAliases:Object.fromEntries(p)}:{}}}),u=d.map(A=>({name:A.name,title:A.title??B(A.name),...A.subject?{on:fe(o,A).filter(m=>r.has(m))}:{}})),g={kinds:s,acts:u},b={version:vn(JSON.stringify(g)),...g},C=Ee.get(o)??new Map;return C.set(c,b),Ee.set(o,C),b}var Cn=e=>e.name??e.id??e.kind;function en(e,n,t){let i=e,{principal:o}=t,r=ee(i)?.store??i,f=r.seenBy(o),d=r.schema,c=me(r,o),a=p=>{let w=f.graph.getNode(p);return w&&c.has(w.kind)?w:void 0},s=p=>({id:p.id,kind:p.kind,label:L(d,p)}),u=Q(n),g=u.length===1?a(u[0]):void 0,b=g?Object.fromEntries(Object.keys(ye(d,g.kind)).filter(p=>!ge(d,g.kind).has(p)&&g[p]!==void 0&&p!=="label").map(p=>[p,g[p]])):{},C={on:n.on,...g?{record:{...s(g),fields:b}}:{},...n.on==="field"&&g?{field:n.field}:{},...n.on==="list"&&c.has(n.kind)?{kind:n.kind}:{},...n.on==="lens"?{place:n.place,...n.kind&&c.has(n.kind)?{kind:n.kind}:{}}:{},...n.on==="place"?{place:n.place}:{},...n.on==="act"?{act:n.act}:{}},A=[...new Set([...n.on==="selection"?n.ids:[],...t.selection??[]])].flatMap(p=>{let w=a(p);return w?[s(w)]:[]}),m=[];if(g){for(let p of Object.keys(Y(d,g.kind)))for(let w of f.graph.out(g.id,p))a(w.id)&&m.push({...s(w),relation:p,direction:"out"});for(let p of d.kinds)for(let w of Object.keys(Y(d,p)))for(let T of f.graph.in(g.id,w))T.kind===p&&a(T.id)&&m.push({...s(T),relation:w,direction:"in"})}let x=f.batches().filter(p=>!p.ops.every(je)).slice(-(t.recent??6)).reverse().map(p=>({intent:p.intent,at:p.at,by:Cn(p.author)})),O=(t.purpose?.jobs??[]).filter(p=>Ge(p,o.roles)&&c.has(p.kind)).map(p=>({name:p.name,ask:p.ask,kind:p.kind})),k=t.purpose&&(t.purpose.for!==void 0||O.length>0)?{...t.purpose.for!==void 0?{for:t.purpose.for}:{},jobs:O}:void 0;return{...t.place!==void 0?{place:t.place}:{},target:C,selection:A,neighbors:m.slice(0,24),recent:x,schema:$n(r,o),...k?{purpose:k}:{},...t.friction?{friction:Qe(t.friction,d,{reader:o})}:{}}}function ie(e){if(!e.off)return e.fast??(e.decide?{model:e.name??"decide",decide:e.decide}:void 0)}function U(e){if(e.off)return;if(e.thinking)return e.thinking;let n=e.name??"model";if(e.complete){let t=e.complete;return{model:n,think:({system:i,prompt:o})=>t({prompt:o,system:i})}}if(e.turn){let t=e.turn;return{model:n,think:async({system:i,prompt:o})=>({text:await t({system:i,messages:[{role:"user",content:o}],tools:[],call:async()=>({error:"No tools here."})})})}}}var Pe=(e,n,t)=>e?n/1e6*(e.inputPerMillion??0)+t/1e6*(e.outputPerMillion??0):void 0,Ie=()=>`ai-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;function Rn(e,n,t=[]){let i=o=>{let r=e.graph.getNode(o);return r?ce(e.schema.tryDefinition(r.kind),r):"a record"};switch(n.on){case"record":return i(n.id);case"field":return`${i(n.id)} \xB7 ${n.field}`;case"selection":return`${n.ids.length} records`;case"list":return e.schema.tryDefinition(n.kind)?W(e.schema,n.kind):n.kind;case"lens":case"place":return t.find(o=>o.as===n.place)?.title??(n.place==="home"?"Home":n.place);case"act":return n.act}}var nn=e=>e.type!=="act"||e.asks.length===0,be=(e,n)=>({id:e.id,type:e.type,label:e.label,...n!==void 0?{confidence:n}:{}});function X(e,n){let t=n.interaction??Ie(),i=he(n.store,n.target,{principal:n.principal,...n.acts?{acts:n.acts}:{},...n.places?{places:n.places}:{}}),o=en(n.store,n.target,{principal:n.principal,...n.place?{place:n.place}:{},...n.selection?{selection:n.selection}:{},...n.purpose?{purpose:n.purpose}:{}}),r=[];return{id:t,catalog:i,state:o,entry:{id:t,at:new Date().toISOString(),by:n.by??n.principal,target:n.target,targetLabel:Rn(n.store,n.target,n.places)},usage:r,meter:f=>{r.push(f),e.meter?.({...f,interaction:t})}}}async function oe(e,n,t,i){let o=await e.decide(n,t),{inputTokens:r,outputTokens:f}=o.usage,d=Pe(e.price,r,f);return i({tier:"fast",model:e.model,inputTokens:r,outputTokens:f,...d!==void 0?{costUsd:d}:{}}),o.answers}async function re(e,n,t,i,o){let r=await e.think({system:n,prompt:t,state:i.state,catalog:i.catalog}),f=r.usage?.inputTokens,d=r.usage?.outputTokens,c=r.usage?.costUsd??(f!==void 0?Pe(e.price,f,d??0):void 0);return o({tier:"thinking",model:e.model,...f!==void 0?{inputTokens:f}:{},...d!==void 0?{outputTokens:d}:{},...c!==void 0?{costUsd:c}:{}}),Ve(r.text)}function se(e,n){let t=new Map(e.map((i,o)=>[`c${o+1}`,i]));return{question:{type:"choice",instructions:n,criteria:Object.fromEntries([...t].map(([i,o])=>[i,`${o.label} \u2014 ${o.description}`]))},of:i=>t.get(i)}}function ae(e,n,t){if(e?.type!=="choice")return[];let i=e,o=Object.entries(i.probabilities).sort((r,f)=>f[1]-r[1]);return o.some(([r])=>r===i.choice)||o.unshift([i.choice,i.confidence]),o.flatMap(([r,f])=>{let d=n(r);return d?[{candidate:d,confidence:f}]:[]}).slice(0,t)}var M=(e,n,t,i)=>({interaction:{...e.entry,ask:{kind:t,said:n??""},offered:[],outcome:"failed",failed:i,usage:[...e.usage]},offers:[]}),Z="AI isn't on here.";async function tn(e,n,t=3){let i=X(e,n),o=n.said??"Suggest",r=i.catalog.candidates.filter(nn).slice(0,24);if(r.length===0)return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:[],outcome:"offered",usage:[]},offers:[]};let f=ie(e),d=U(e),c=[];try{if(f){let{question:a,of:s}=se(r,"Which of these would the person most likely want to do next, here?"),u=await oe(f,{...i.state,candidates:r.map(g=>({id:g.id,type:g.type,says:g.description}))},{next:a},i.meter);c=ae(u.next,s,t)}else if(d){let a=await re(d,'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:i.state,candidates:r.map(u=>({id:u.id,says:u.description}))}),i,i.meter);c=(Array.isArray(a?.pick)?a.pick.filter(u=>typeof u=="string"):[]).flatMap(u=>r.filter(g=>g.id===u)).slice(0,t).map(u=>({candidate:u}))}else return M(i,o,"suggest",Z)}catch(a){return M(i,o,"suggest",a instanceof Error?a.message:String(a))}return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:c.map(({candidate:a,confidence:s})=>be(a,s)),outcome:"offered",usage:[...i.usage]},offers:c.map(({candidate:a})=>a)}}var Tn=e=>`several:${e}`;async function it(e,n,t=2){let i=X(e,{...n,acts:[]}),o=n.said??"Suggest for the chosen",r=n.target.on==="selection"?n.target.ids.length:1,d=[...n.shared.map(s=>({type:"act",id:Tn(s.id),label:s.label,description:`${s.label}, for all ${r} chosen`,mutation:s.mutation,args:s.args,asks:[]})),...i.catalog.candidates.filter(s=>s.type==="panel"||s.type==="place")].slice(0,24),c=ie(e);if(!c)return M(i,o,"suggest",Z);if(d.length===0)return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:[],outcome:"offered",usage:[]},offers:[]};let a;try{let{question:s,of:u}=se(d,`Which of these would the person most likely want to do next with the ${r} records they chose together?`),g=await oe(c,{...i.state,candidates:d.map(b=>({id:b.id,type:b.type,says:b.description}))},{next:s},i.meter);a=ae(g.next,u,t).filter((b,C)=>C===0||b.confidence>=En)}catch(s){return M(i,o,"suggest",s instanceof Error?s.message:String(s))}return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:a.map(({candidate:s,confidence:u})=>be(s,u)),outcome:"offered",usage:[...i.usage]},offers:a.map(({candidate:s})=>s)}}var En=.25;async function on(e,n){let t=X(e,n),i=n.said??"Fill in",o=t.catalog.candidates.filter(u=>u.type==="fill"),r=new Map;for(let u of o)r.set(u.field,[...r.get(u.field)??[],u]);if(r.size===0)return{interaction:{...t.entry,ask:{kind:"fill",said:i},offered:[],outcome:"offered",usage:[]},offers:[]};let f=ie(e),d=U(e),c=[];try{if(f){let u=[...r].map(([b,C],A)=>({key:`f${A+1}`,field:b,...se(C,`Which value fits "${b}" best for this record?`)})),g=await oe(f,t.state,Object.fromEntries(u.map(b=>[b.key,b.question])),t.meter);for(let b of u){let C=!Pn(n.store,n.target,b.field)&&In(n.store,n.target,b.field)!=="one";c.push(...ae(g[b.key],b.of,C?3:1).filter((A,m)=>m===0||A.confidence>=.4))}}else if(d){let u=await re(d,`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:o.map(C=>({id:C.id,says:C.description}))}),t,t.meter),g=Array.isArray(u?.fills)?u.fills.filter(C=>typeof C=="string"):[],b=new Set;for(let C of g){let A=o.find(m=>m.id===C);A?.type==="fill"&&!b.has(A.field)&&(b.add(A.field),c.push({candidate:A}))}}else return M(t,i,"fill",Z)}catch(u){return M(t,i,"fill",u instanceof Error?u.message:String(u))}let a=t.usage.at(-1)?.model,s=de(n.store,{interaction:t.id,target:n.target,basis:i,...a?{model:a}:{},proposals:c.flatMap(({candidate:u,confidence:g})=>u.type==="fill"?[{id:u.id,label:u.label,said:u.description,call:u.call,record:u.record,field:u.field,...g!==void 0?{confidence:g}:{}}]:[])},n.principal);return{interaction:{...t.entry,ask:{kind:"fill",said:i},offered:s.proposals.map(u=>({id:u.id,type:"fill",label:u.label,...u.confidence!==void 0?{confidence:u.confidence}:{}})),outcome:"offered",usage:[...t.usage]},offers:[],...s.proposals.length>0?{ghost:s}:{}}}function Pn(e,n,t){let i=n.on==="record"||n.on==="field"?n.id:void 0,o=i?e.graph.getNode(i)?.kind:void 0,r=(o?e.schema.tryDefinition(o)?.fields?.shape:void 0)??{};return t in r}function In(e,n,t){let i=n.on==="record"||n.on==="field"?n.id:void 0,o=i?e.graph.getNode(i)?.kind:void 0;return o?e.schema.tryDefinition(o)?.edges?.[t]?.cardinality:void 0}async function rn(e,n){let t=X(e,n),i=n.said??"Add one",o=new Set(n.store.allMutations().filter(s=>(s.creates??[]).length>0).map(s=>s.name)),r=t.catalog.candidates.filter(s=>s.type==="act"&&s.asks.length>0&&o.has(s.mutation));if(r.length===0)return M(t,i,"record","Nothing here makes a record.");let f=U(e);if(!f)return M(t,i,"record",Z);let d;try{let s=await re(f,'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:i,state:t.state,candidates:r.map(b=>({id:b.id,says:b.description,asks:b.asks}))}),t,t.meter),u=r.find(b=>b.id===s?.act),g=typeof s?.args=="object"&&s.args!==null?s.args:{};u&&(d={act:u,args:Object.fromEntries(Object.entries(g).filter(([b])=>u.asks.includes(b)))})}catch(s){return M(t,i,"record",s instanceof Error?s.message:String(s))}if(!d)return M(t,i,"record","The model named no act this app has here.");let c=t.usage.at(-1)?.model,a=de(n.store,{interaction:t.id,target:n.target,basis:i,...c?{model:c}:{},proposals:[{id:d.act.id,label:d.act.label,said:d.act.description,call:{name:d.act.mutation,args:{...d.act.args,...d.args}}}]},n.principal);return a.proposals.length===0?M(t,i,"record","What the model proposed could not be made here."):{interaction:{...t.entry,ask:{kind:"record",said:i},offered:a.proposals.map(s=>({id:s.id,type:"act",label:s.said})),outcome:"offered",usage:[...t.usage]},offers:[d.act],ghost:a}}async function sn(e,n){let t=X(e,n),i=n.said??"Make a panel",o=t.catalog.candidates.filter(s=>s.type==="panel");if(o.length===0)return M(t,i,"panel","Nothing here can be drawn as a panel.");let r=ie(e),f=U(e),d;try{if(f){let s=await re(f,'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:i,state:t.state,candidates:o.map(g=>({id:g.id,says:g.description}))}),t,t.meter),u=o.find(g=>g.id===s?.panel);u&&(d={panel:u,...typeof s?.title=="string"&&s.title.trim()?{title:s.title.trim().slice(0,60)}:{}})}else if(r){let{question:s,of:u}=se(o,`Which panel answers this best: ${i}`),g=ae((await oe(r,t.state,{panel:s},t.meter)).panel,u,1)[0];g?.candidate.type==="panel"&&(d={panel:g.candidate,confidence:g.confidence})}else return M(t,i,"panel",Z)}catch(s){return M(t,i,"panel",s instanceof Error?s.message:String(s))}if(!d)return M(t,i,"panel","The model named no panel this app can draw.");let c=d.title??d.panel.label,a={title:c,recipe:{...d.panel.panel,title:c}};return{interaction:{...t.entry,ask:{kind:"panel",said:i},offered:[be(d.panel,d.confidence)],outcome:"drawn",panel:a,usage:[...t.usage]},offers:[d.panel],panel:a}}function Fn(e){return e.off?void 0:e.answer}var Mn=`You answer a person's question about what they are looking at in an app, from the state given and nothing else. Answer only JSON: {"answer": one to three short sentences, "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.`;async function ot(e,n){let t=X(e,n),i=n.said.trim(),o=t.catalog.candidates.filter(m=>nn(m)||m.type==="panel"||m.type==="place"||m.type==="record").slice(0,32),r=Fn(e),f=U(e),d=ie(e),c="",a=[],s=m=>m.flatMap(x=>o.filter(O=>O.id===x)).slice(0,3).map(x=>({candidate:x}));try{if(r){let m=await r.answer({said:i,target:n.target,targetLabel:t.entry.targetLabel,state:t.state,catalog:{target:t.catalog.target,candidates:o},...n.follows?{follows:n.follows}:{}}),x=m.usage?.inputTokens,O=m.usage?.outputTokens,k=m.usage?.costUsd??(x!==void 0?Pe(r.price,x,O??0):void 0);t.meter({tier:"thinking",model:r.model,...x!==void 0?{inputTokens:x}:{},...O!==void 0?{outputTokens:O}:{},...k!==void 0?{costUsd:k}:{}}),c=typeof m.text=="string"?m.text.trim():"",a=s(m.pick??[])}else if(f){let m=await re(f,Mn,JSON.stringify({ask:i,about:t.entry.targetLabel,...n.follows?{follows:n.follows}:{},state:t.state,candidates:o.map(x=>({id:x.id,says:x.description}))}),t,t.meter);c=typeof m?.answer=="string"?m.answer.trim():"",a=s(Array.isArray(m?.pick)?m.pick:[])}else if(d&&o.length>0){let{question:m,of:x}=se(o,`Which of these best answers, or acts on: ${i}`),O=await oe(d,{...t.state,asked:i,candidates:o.map(k=>({id:k.id,type:k.type,says:k.description}))},{answer:m},t.meter);a=ae(O.answer,x,3),c=a.length>0?`These fit \u201C${i}\u201D.`:""}else return M(t,i,"ask",Z)}catch(m){return M(t,i,"ask",m instanceof Error?m.message:String(m))}if(!c&&a.length===0){let m=n.target.on==="place"||n.target.on==="lens"?n.target.place:void 0,x=n.target.on==="list"||n.target.on==="lens"?n.target.kind:void 0;return Be(n.store,{type:"unanswered",question:i,...m?{place:m}:{},...x?{kind:x}:{}},n.principal),M(t,i,"ask","The AI had no answer to that here.")}let u=t.usage.at(-1)?.model,g=a.flatMap(({candidate:m,confidence:x})=>{let O=ke(m);return O?[{...O,...x!==void 0?{confidence:x}:{}}]:[]}),b=g.length>0?de(n.store,{interaction:t.id,target:n.target,basis:i,...u?{model:u}:{},proposals:g},n.principal):void 0,C=a.map(({candidate:m})=>m).filter(m=>ke(m)===void 0),A=[...C.map(m=>be(m,a.find(x=>x.candidate===m)?.confidence)),...(b?.proposals??[]).map(m=>({id:m.id,type:m.field!==void 0?"fill":"act",label:m.label,...m.confidence!==void 0?{confidence:m.confidence}:{}}))];return{interaction:{...t.entry,ask:{kind:"ask",said:i},offered:A,outcome:"offered",...c?{answer:c}:{},usage:[...t.usage]},offers:C,...b&&b.proposals.length>0?{ghost:b}:{},...c?{answer:c}:{}}}function de(e,n,t){let i=n.proposals.flatMap(o=>{try{let r=e.previewAll([o.call],{author:t}),f=r.ops.map(d=>d.intent).join("; ");return r.ops.length>0?[{...o,said:f||o.said}]:[]}catch{return[]}});return{...n,proposals:i}}function ke(e){if(e.type==="fill")return{id:e.id,label:e.label,said:e.description,call:e.call,record:e.record,field:e.field};if(e.type==="act"&&e.asks.length===0)return{id:e.id,label:e.label,said:e.description,call:{name:e.mutation,args:{...e.args}}}}function an(e,n,t){let i=n.proposals.filter(r=>t.ids===void 0||t.ids.includes(r.id));if(i.length===0)return{ok:!1,refused:"Nothing was chosen."};let o=i.flatMap(r=>r.confidence===void 0?[]:[r.confidence]);try{let f=e.applyAll(i.map(d=>d.call),{author:t.author,via:`ai:${n.interaction}`,intent:n.basis,lineage:{basis:`Asked \u201C${n.basis}\u201D`,...n.model?{model:n.model}:{},...o.length>0?{confidence:Math.min(...o)}:{},interaction:n.interaction}}).ops[0]?.batch;return f?{ok:!0,batch:f,accepted:i.map(d=>d.id)}:{ok:!1,refused:"That changes nothing now."}}catch(r){return{ok:!1,refused:r instanceof Error?r.message:String(r)}}}function dn(e,n,t){let i=e.ask.kind==="suggest"?n.length>0:e.offered.length>0&&e.offered.every(o=>n.includes(o.id));return{...e,outcome:i?"accepted":"partly",accepted:n,batches:[...e.batches??[],t]}}var ln=e=>({...e,outcome:"dismissed"});var P=xe(hn(),1);var S=xe(Ue(),1);function fn(e,n,t){let i=n.on==="selection"?n.ids:n.on==="record"||n.on==="field"?[n.id]:[],o=i.length>0?Ke(e.store,i,{principal:e.principal,...i.length===1?{focus:i[0]}:{}}).affordances.map(r=>({mutation:r.mutation,label:r.label,args:r.args,open:r.open,why:r.why,...r.destructive?{destructive:!0}:{}})):void 0;return{store:e.store,target:n,principal:e.principal,interaction:Ie(),places:e.places,selection:e.selection,...o?{acts:o}:{},...e.place?{place:e.place}:{},...t?{said:t}:{},...e.app.purpose?{purpose:e.app.purpose}:{}}}async function un(e,n,t){let i=await (__graviewPreload(import.meta.url,["./chunk.NIFQDN6R.js","./chunk.G4JJXA63.js","./chunk.LDYOQCY7.js","./chunk.VFRURRNI.js","./chunk.2NJDT47T.js","./chunk.XOZU4OFA.js","./chunk.MHILFBK6.js","./chunk.ZFH4SCCF.js","./chunk.WVUJXDXZ.js","./chunk.Q6LLURRM.js","./chunk.AXXYJCSW.js","./chunk.N4LOI3YA.js","./chunk.RKZ4J3H2.js","./chunk.HKINU7VO.js","./chunk.YGZCESXY.js","./chunk.NSGQXCH6.js","./chunk.SZG6HJWH.js","./chunk.2FOIJ5ID.js","./chunk.X3MMJ3QC.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.QDZAITMN.js")),o=i.recipeDraft(n.recipe,{app:e.app,sight:i.draftSight(e.app,e.principal)});if(i.isDraftFailure(o))return o.failed;t?.(),e.seatTalk.setDraft(o,null),e.goTo.draft?.(),pn()}function pn(e=180){if(typeof document>"u")return;let n=document.querySelector('[data-testid="draft-keep"]'),t=document.activeElement,i=!t||t===document.body||t.closest?.("[inert]")!==null;if(n){i&&n.focus();return}e>0&&requestAnimationFrame(()=>pn(e-1))}async function le(e,n,t,i,o){let r=fn(e,t,i),f=n==="suggest"?await tn(e.ai,r):n==="fill"?await on(e.ai,r):n==="record"?await rn(e.ai,r):await sn(e.ai,r);if(f.interaction.outcome==="failed")return n!=="suggest"&&e.desk.record(f.interaction),f;let d=c=>{let a={...f.interaction,outcome:"failed",failed:c};return e.desk.record(a),{...f,interaction:a}};if(n==="fill"||n==="record"){if(!f.ghost||f.ghost.proposals.length===0)return d("Nothing here could be filled in.");o?.(),e.desk.setGhost({ghost:f.ghost}),e.desk.record(f.interaction)}if(n==="panel"&&f.panel){let c=await un(e,f.panel,o);if(c)return d(c);e.desk.record(f.interaction)}return f}var Fe=new WeakMap,Nn=64,cn=new WeakMap;function jn(e){let n=cn.get(e);if(!n){let t=n={n:0};cn.set(e,t),e.subscribe(()=>void(t.n+=1))}return n.n}var yn=(e,n)=>{let t=Q(n);return t.length>0?t.map(i=>e.graph.getNode(i)):[jn(e)]},gn=(e,n,t)=>JSON.stringify({target:n,seat:e.principal,by:t}),mn=(e,n,t)=>{let i=yn(e.store,n);return t.schema===e.store.schema&&t.ai===e.ai&&i.length===t.depends.length&&i.every((o,r)=>o===t.depends[r])};function Dn(e,n,t="menu"){let i=Fe.get(e.store)?.get(gn(e,n,t));return i?.result!==void 0&&mn(e,n,i)?i.result:void 0}function Ln(e,n,t){let i=Fe.get(e.store);i||Fe.set(e.store,i=new Map);let o=gn(e,n,t?.by??"menu"),r=i.get(o);if(r&&mn(e,n,r))return r.result?Promise.resolve(r.result):r.asked;let f=t?t.ask():le(e,"suggest",n),d={schema:e.store.schema,ai:e.ai,depends:yn(e.store,n),asked:f};i.delete(o),i.set(o,d),i.size>Nn&&i.delete(i.keys().next().value);let c=i;return f.then(a=>{a.interaction.outcome!=="failed"?d.result=a:c.get(o)===d&&c.delete(o)}),f}async function Hn(e,n,t,i){let o=n.interaction,r=ke(t);if(r){let f=o.usage?.at(-1)?.model,d=o.offered.find(a=>a.id===t.id)?.confidence,c=de(e.store,{interaction:o.id,target:o.target,basis:`${o.ask.said}: ${t.label}`,...f?{model:f}:{},proposals:[{...r,...d!==void 0?{confidence:d}:{}}]},e.principal);if(c.proposals.length===0){let a="That can't be done now.";return e.desk.record({...o,outcome:"failed",failed:a}),a}i?.(),e.desk.setGhost({ghost:c}),e.desk.record(o);return}if(t.type==="panel"){let f=t.label,d={title:f,recipe:{...t.panel,title:f}},c=await un(e,d,i);return e.desk.record(c?{...o,outcome:"failed",failed:c}:{...o,outcome:"drawn",accepted:[t.id],panel:d}),c}i?.(),t.type==="place"?e.goTo.place(t.place):t.type==="record"&&e.goTo.record(t.record),e.desk.record({...o,outcome:"accepted",accepted:[t.id]})}async function yt(e,n){if(n.ask.kind==="ask")return ue(e.desk,{target:n.target,asked:n.ask.said}),null;let t=n.ask.kind==="panel"||n.ask.kind==="record"?n.ask.kind:"fill";return le(e,t,n.target,n.ask.said)}var z={padding:"5px 10px",fontSize:"0.875rem",borderRadius:8,width:"100%",textAlign:"left",borderWidth:1,borderStyle:"solid",borderColor:"transparent",background:"none",boxShadow:"none"},we={margin:0,padding:"4px 10px",fontSize:"0.8125rem",color:"var(--graview-ink-muted)"};function gt({target:e,close:n}){let t=Je(),i=(0,P.useMemo)(()=>Xe(e,y=>t.store.graph.has(y)),[e,t.store]),o=(0,P.useMemo)(()=>{let y=fn(t,i);return he(t.store,i,{principal:t.principal,places:t.places,...y.acts?{acts:y.acts}:{}})},[t,i]),r=o.candidates.some(y=>y.type==="fill"),f=o.candidates.some(y=>y.type==="panel"),d=(0,P.useMemo)(()=>f?Ze(t.store,i,{principal:t.principal,places:t.places,most:1}):[],[f,t,i]),c=(0,P.useMemo)(()=>new Set(t.store.allMutations().filter(y=>(y.creates??[]).length>0).map(y=>y.name)),[t.store]),a=U(t.ai)!==void 0&&o.candidates.some(y=>y.type==="act"&&y.asks.length>0&&c.has(y.mutation)),s=Oe(t.ai),u=Dn(t,i),g=JSON.stringify(i),[b,C]=(0,P.useState)(!1),[A,m]=(0,P.useState)(null),[x,O]=(0,P.useState)(s&&u===void 0);(0,P.useEffect)(()=>{if(u!==void 0||!(s||b))return;let y=!0;return O(!0),Ln(t,i).then(v=>{y&&(m(v),O(!1))}),()=>{y=!1}},[g,b]);let k=u??A,p=(k?.offers??[]).filter(y=>!(y.type==="place"&&d.some(v=>v.place===y.place))).slice(0,Math.max(0,3-d.length)),w=k?.interaction.outcome==="failed"?k.interaction.failed??"The AI could not suggest anything here.":null,T=(0,P.useRef)(!1),F=(0,P.useRef)(null);(0,P.useLayoutEffect)(()=>{k===null||!T.current||(T.current=!1,F.current?.querySelector("button")?.focus())},[k]);let q=(0,P.useRef)(!0);(0,P.useEffect)(()=>()=>{q.current=!1},[]);let[H,l]=(0,P.useState)(!1),[h,R]=(0,P.useState)(null),E=y=>{if(H)return;l(!0),R(null);let v=!1;y(()=>{v=!0,n()}).then(D=>{q.current&&(l(!1),D?R(D):v||n())},D=>{q.current&&(l(!1),R(D instanceof Error?D.message:String(D)))})},$=y=>y.interaction.outcome==="failed"?y.interaction.failed??"The AI could not do that here.":void 0;return(0,S.jsxs)("div",{ref:F,"data-testid":"inline-ai",style:{display:"grid",gap:2},children:[x&&!b?(0,S.jsx)("p",{role:"status","data-testid":"inline-ai-thinking",style:we,children:"Thinking\u2026"}):H?(0,S.jsx)("p",{role:"status","data-testid":"inline-ai-asking",style:we,children:"Asking\u2026"}):h?(0,S.jsx)("p",{role:"alert","data-testid":"inline-ai-failed",style:{...we,color:"var(--graview-warn)"},children:h}):w?(0,S.jsx)("p",{role:"status",style:we,children:w}):null,(0,S.jsxs)("ul",{style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:2},children:[p.map(y=>(0,S.jsx)("li",{children:(0,S.jsxs)("button",{type:"button","data-menu-item":`ai-offer:${y.id}`,"data-ai-offer":y.id,"data-ai-offer-type":y.type,onClick:()=>E(v=>Hn(t,k,y,v)),style:z,children:[y.label,(0,S.jsxs)("span",{style:{color:"var(--graview-ink-faint)"},children:[" \xB7 ",y.type==="panel"?"a panel":y.type==="place"?"go there":y.type==="record"?"open it":"suggested"]})]})},y.id)),!s&&k===null?(0,S.jsx)("li",{children:(0,S.jsx)("button",{type:"button","data-menu-item":"ai-suggest","aria-disabled":b||void 0,onClick:y=>{b||(T.current=document.activeElement===y.currentTarget,C(!0))},style:z,children:b?"Thinking\u2026":"Suggest\u2026"})}):null,r?(0,S.jsx)("li",{children:(0,S.jsx)("button",{type:"button","data-menu-item":"ai-fill",onClick:()=>E(async y=>$(await le(t,"fill",i,"Fill in",y))),style:z,children:"Fill in with AI"})}):null,a?(0,S.jsx)("li",{children:(0,S.jsx)("button",{type:"button","data-menu-item":"ai-record",onClick:()=>E(async y=>$(await le(t,"record",i,"Add one",y))),style:z,children:"Add one with AI"})}):null,d.map(y=>(0,S.jsx)("li",{children:(0,S.jsx)("button",{type:"button","data-menu-item":`ai-open:${y.place}`,"data-ai-existing":y.fit,onClick:()=>{n(),t.goTo.place(y.place),y.fit==="partial"&&ue(t.desk,{target:{on:"lens",place:y.place,...y.kind?{kind:y.kind}:{}}})},style:z,children:y.fit==="full"?`Open ${y.title}`:`Open and adjust ${y.title}`})},y.place)),f?(0,S.jsx)("li",{children:(0,S.jsx)("button",{type:"button","data-menu-item":"ai-panel",onClick:()=>E(async y=>$(await le(t,"panel",i,"Draw a panel",y))),style:z,children:d.length>0?"Draw a new view":"Draw a panel"})}):null,(0,S.jsx)("li",{children:(0,S.jsx)("button",{type:"button","data-menu-item":"ai-ask",onClick:()=>{let y=document.activeElement;n(),ue(t.desk,{target:i,returnTo:y instanceof HTMLElement&&y!==document.body?y:null})},style:z,children:"Ask about this\u2026"})})]})]})}var Ae={display:"inline-flex",alignItems:"center",minHeight:28,padding:"2px 10px",fontSize:"0.8125rem",borderRadius:8};function mt({placement:e="picture"}){let{store:n,principal:t,aiDesk:i}=ze(),o=We(n,t),{ghost:r,entries:f}=_e(i),[d,c]=(0,P.useState)(new Set);(0,P.useEffect)(()=>c(new Set),[r?.ghost.interaction]);let a=(0,P.useRef)(null),s=(0,P.useRef)(null),u=r?.batch;if((0,P.useEffect)(()=>{u!==void 0&&s.current?.focus()},[u]),!r)return null;let{ghost:g}=r,b=f.find(k=>k.id===g.interaction),C=()=>{let k=g.target.on==="record"||g.target.on==="field"?g.target.id:void 0,p=a.current?.closest("[data-graview-face], main")?.parentElement??document,w=(k?p.querySelector(`[data-graview-view="${CSS.escape(k)}"][tabindex]`):null)??document.querySelector("[data-graview-page-title]")??a.current?.closest("main")??document.querySelector("main");w&&!w.hasAttribute("tabindex")&&w.setAttribute("tabindex","-1"),w?.focus({preventScroll:!0}),i.setGhost(null)},A=g.proposals.filter(k=>!d.has(k.id)).map(k=>k.id),m=()=>{let k=an(o,g,{author:t,ids:A});if(!k.ok){i.setGhost({...r,refused:k.refused});return}b&&i.record(dn(b,k.accepted,k.batch)),i.setGhost({ghost:g,batch:k.batch,took:k.accepted.length,...r.onCard?{onCard:!0}:{}})},x=()=>{b&&r.batch===void 0&&i.record(ln(b)),C()},O=()=>{if(r.batch!==void 0)try{o.undo(r.batch,{author:t}),C()}catch(k){i.setGhost({...r,refused:k instanceof Error?k.message:String(k)})}};return(0,S.jsxs)("section",{ref:a,"data-testid":"ai-ghost","data-interaction":g.interaction,"aria-label":"Proposed by AI",style:{...e==="card"?{position:"static"}:{position:e==="page"?"fixed":"absolute",insetInline:"max(12px, calc(50% - 220px))",bottom:"calc(var(--graview-foot-room, 0px) + 72px)",zIndex:He("toast"),boxShadow:"var(--graview-lift-high)"},display:"grid",gap:8,padding:12,borderRadius:12,border:"1px dashed var(--graview-accent)",background:"var(--graview-float)",fontSize:"0.875rem"},children:[(0,S.jsx)("p",{style:{margin:0,color:"var(--graview-ink-muted)"},children:r.batch!==void 0?`Done: ${r.took===1?"one change":`${r.took} changes`}, as one.`:`Proposed by AI \xB7 ${g.basis}`}),r.batch===void 0?(0,S.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none",display:"grid",gap:4},children:g.proposals.map(k=>(0,S.jsx)("li",{"data-ghost-proposal":k.id,children:(0,S.jsxs)("label",{style:{display:"flex",alignItems:"baseline",gap:8,cursor:"pointer"},children:[(0,S.jsx)("input",{type:"checkbox",checked:!d.has(k.id),onChange:p=>{let w=new Set(d);p.target.checked?w.delete(k.id):w.add(k.id),c(w)}}),(0,S.jsx)("span",{style:{fontStyle:"italic",color:"var(--graview-ink)"},children:k.said}),k.confidence!==void 0?(0,S.jsxs)("span",{style:{color:"var(--graview-ink-faint)"},children:[Math.round(k.confidence*100),"% sure"]}):null]})},k.id))}):null,r.refused?(0,S.jsx)("p",{role:"alert",style:{margin:0,color:"var(--graview-warn)"},children:r.refused}):null,(0,S.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:r.batch===void 0?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("button",{type:"button","data-testid":"ghost-accept",disabled:A.length===0,onClick:m,style:Ae,children:A.length===g.proposals.length?"Accept":`Accept ${A.length} of ${g.proposals.length}`}),(0,S.jsx)("button",{type:"button","data-testid":"ghost-dismiss",onClick:x,style:Ae,children:"Dismiss"})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("button",{type:"button",ref:s,"data-testid":"ghost-undo",onClick:O,style:Ae,children:"Undo"}),(0,S.jsx)("button",{type:"button","data-testid":"ghost-close",onClick:C,style:Ae,children:"Close"})]})})]})}export{Xe as a,Q as b,he as c,Ze as d,ie as e,Ie as f,Rn as g,Tn as h,it as i,ot as j,fn as k,un as l,le as m,Dn as n,Ln as o,Hn as p,yt as q,gt as r,mt as s};
|
|
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 Ge}from"./chunk.BJUUSIQY.js";import{a as Ke}from"./chunk.ZP5RT2EK.js";import{a as Ve}from"./chunk.6C2MHWSX.js";import{a as Je}from"./chunk.HDUO2USQ.js";import{a as pe}from"./chunk.TY4GQJKC.js";import{c as ue}from"./chunk.WC3DENU4.js";import{E as Oe,G as hn,J as _e,P as We,T as Ue,ba as ze}from"./chunk.4MP72LPR.js";import{Xb as De,ad as He,da as B,fc as fe,ga as ce,hc as Le,ja as W,kd as qe,ma as Ne,md as Be,oa as G,zb as je}from"./chunk.VSCIXAHN.js";import{j as ee}from"./chunk.FQLNBIQ5.js";import{b as xe}from"./chunk.AJZBJBMO.js";var kn=["search-miss","unanswered","refused","tool-invalid"];var _n=new RegExp("[\\u0000-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2066-\\u2069]","g");var K=e=>e.onBehalfOf?K(e.onBehalfOf):e.id!==void 0?`${e.kind}:${e.id}`:`${e.kind}:?`,ve=e=>e.toLowerCase().replace(/\s+/g," ").replace(/^[\s\p{P}]+|[\s\p{P}]+$/gu,"");var bn=new Set("a an and are at be by can do does for from has have how i in is it me my of on or our the their there this to was we what when where which who why will with you your".split(" "));function ne(e,n,t,i,o){let r=new Map;for(let f of e){let d=n(f);if(d===void 0)continue;let c=r.get(d)??{first:f,people:new Set,times:0,last:f};c.people.add(K(f.by)),c.times+=1,c.last=f,r.set(d,c)}return[...r.entries()].filter(([,f])=>f.people.size>=i).sort(([f,d],[c,a])=>a.people.size-d.people.size||a.times-d.times||f.localeCompare(c)).slice(0,o).map(([f,d])=>({...t(d.last,f),people:d.people.size,times:d.times}))}function wn(e,n={}){let t=Math.max(1,n.minPeople??2),i=n.most??12,o=n.reader?K(n.reader):void 0,r=e.filter(a=>!qe(a.by)&&(o===void 0||K(a.by)!==o)),f=Object.fromEntries(kn.map(a=>{let s=r.filter(u=>u.type===a);return[a,{events:s.length,people:new Set(s.map(u=>K(u.by))).size}]})),d=[],c=new Map;for(let a of r){let s=a.type==="search-miss"?a.words:a.type==="unanswered"?a.question:void 0;if(s!==void 0)for(let u of new Set(ve(s).split(/[^\p{L}\p{N}]+/u))){if(u.length<3||bn.has(u))continue;let g={...a,id:`${a.id}:${u}`};d.push(g),c.set(g,u)}}return{events:r.length,people:new Set(r.map(a=>K(a.by))).size,byType:f,searches:ne(r,a=>a.type==="search-miss"&&ve(a.words)||void 0,(a,s)=>({words:s}),t,i),questions:ne(r,a=>a.type==="unanswered"&&ve(a.question)||void 0,(a,s)=>({question:s}),t,i),words:ne(d,a=>c.get(a),(a,s)=>({word:s}),t,i),refusals:ne(r,a=>a.type==="refused"?`${a.act}|${a.code}`:void 0,a=>({act:a.act,code:a.code}),t,i),tools:ne(r,a=>a.type==="tool-invalid"?`${a.tool}|${a.act??""}`:void 0,a=>{let s=a;return{tool:s.tool,...s.act?{act:s.act}:{},...s.then?{then:s.then}:{}}},1,i)}}var Ye=e=>e.length>3&&e.endsWith("s")&&!e.endsWith("ss")?e.slice(0,-1):e;function An(e){let n=new Set,t=i=>{for(let o of i.toLowerCase().split(/[^\p{L}\p{N}]+/u))o.length>0&&n.add(Ye(o))};for(let i of e.kinds){let o=e.tryDefinition(i);t(i),t(G(o,i)),t(W(e,i));for(let r of[...o?.aliases??[],...Object.values(o?.fieldAliases??{}).flat()])t(r);for(let r of Object.keys(o?.fields?.shape??{}))t(r),t(B(r))}return n}function Qe(e,n,t={}){let i=wn(e,{most:8,...t}),o=An(n),r=i.searches.filter(s=>!s.words.split(/[^\p{L}\p{N}]+/u).some(u=>u.length>0&&o.has(Ye(u)))).map(s=>({words:s.words,people:s.people})),f=i.questions.map(s=>({question:s.question,people:s.people})),d=i.tools.map(s=>({tool:s.tool,...s.act?{act:s.act}:{},...s.then?{then:s.then}:{},times:s.times})),c=s=>`${s} ${s===1?"person":"people"}`;return{said:[...r.length>0?[`Searched for, found nothing, and nothing here is called it: ${r.map(s=>`\u201C${s.words}\u201D (${c(s.people)})`).join(", ")}.`]:[],...f.length>0?[`Asked and not answered: ${f.map(s=>`\u201C${s.question}\u201D (${c(s.people)})`).join(", ")}.`]:[],...d.length>0?[`Tool calls refused as invalid: ${d.map(s=>`${s.tool}${s.act?` (${s.act})`:""} ${s.times===1?"once":`${s.times} times`}${s.then?`, then worked as ${s.then}`:""}`).join("; ")}.`]:[]].join(`
|
|
2
|
+
`),unknownWords:r,questions:f,toolMistakes:d}}var Sn=e=>/^(?:aggregate|kind):([^,]+)$/.exec(e)?.[1];function Xe(e,n){let t=e.about??[];if(e.field!==void 0&&e.on!==void 0&&n(e.on))return{on:"field",id:e.on,field:e.field};let i=t.filter(n);if(i.length>1)return{on:"selection",ids:i};if(e.on!==void 0&&n(e.on))return{on:"record",id:e.on};if(i.length===1)return{on:"record",id:i[0]};let o=[e.on,...t].map(r=>r===void 0?void 0:Sn(r)).find(r=>r!==void 0);return e.place!==void 0?{on:"lens",place:e.place,...o?{kind:o}:{}}:o!==void 0?{on:"list",kind:o}:{on:"place",place:"home"}}var Q=e=>e.on==="record"||e.on==="field"?[e.id]:e.on==="selection"?e.ids:e.on==="act"&&e.id!==void 0?[e.id]:[],ye=(e,n)=>e.tryDefinition(n)?.fields?.shape??{},Y=(e,n)=>e.tryDefinition(n)?.edges??{},ge=(e,n)=>new Set(e.tryDefinition(n)?.display?.hide??[]),L=(e,n)=>ce(e.tryDefinition(n.kind),n),$e=(e,n,t)=>Ne(e.tryDefinition(n),t)||B(t),Ce=e=>typeof e=="boolean"?e?"yes":"no":String(e);function me(e,n){let t=e.kindsKeptFrom(n);return new Set(e.schema.kinds.filter(i=>!t.has(i)))}function Re(e,n,t,i){if(!e.permits(n,t).ok)return!1;if(!i)return!0;try{return e.previewAll([n],{author:t}).ops.length>0}catch{return!1}}function he(e,n,t){let i=e,{principal:o}=t,r=t.each??8,f=ee(i)?.store??i,d=f.seenBy(o),c=f.schema,a=me(f,o),s=l=>{let h=d.graph.getNode(l);return h&&a.has(h.kind)?h:void 0},u=f.allMutations(),g=new Map(u.map(l=>[l.name,l])),b=[],C=new Set,A=l=>{C.has(l.id)||(C.add(l.id),b.push(l))},m=l=>l.slice(0,r),x=Q(n).filter(l=>s(l)!==void 0);if(Q(n).length>0&&x.length===0)return{target:n,candidates:[]};let O=x.length===1?s(x[0]):void 0,k=O?.kind??(n.on==="list"?n.kind:n.on==="lens"?n.kind??t.places?.find(l=>l.as===n.place)?.kind:void 0)??(n.on==="selection"?s(x[0])?.kind:void 0);if(k!==void 0&&!a.has(k))return{target:n,candidates:[]};let p=(l,h)=>`act:${l}${Object.keys(h).length>0?`:${Object.values(h).map(R=>String(R)).join(",")}`:""}`,w=(l,h,R,E,$)=>{l.destructive||Object.values(h).some(y=>typeof y=="string"&&f.graph.has(y)&&s(y)===void 0)||Re(f,{name:l.name,args:{...h}},o,E.length===0)&&A({type:"act",id:p(l.name,h),label:R,description:$??l.description??R,mutation:l.name,args:h,asks:E})};if(n.on!=="place"||t.acts)if(t.acts)for(let l of t.acts){let h=g.get(l.mutation);!h||l.destructive||n.on==="act"&&l.mutation!==n.act||w(h,l.args,l.label,(l.open??[]).filter(R=>!R.optional).map(R=>R.name),l.why)}else{let l=O?[O]:[];for(let h of u){if(n.on==="act"&&h.name!==n.act)continue;let R=h.input.shape??{},E=$=>Object.entries(R).filter(([y,v])=>y!==$&&v.safeParse?.(void 0).success===!1).map(([y])=>y);if(h.subject)for(let $ of l)fe(c,h).includes($.kind)&&w(h,{[h.subject.arg]:$.id},`${h.title??B(h.name)}: ${L(c,$)}`,E(h.subject.arg));else k!==void 0&&(h.creates??[]).includes(k)&&w(h,{},h.title??B(h.name),E(void 0))}}let T=b.filter(l=>l.type==="act");b.splice(0,b.length,...m(T));let F=(l,h)=>{let R=Le(c,u).get(l.kind),E=ye(c,l.kind),$=ge(c,l.kind),y=[];for(let[v,j]of Object.entries(E)){if(h!==void 0?v!==h:$.has(v)||l[v]!==void 0)continue;let D=pe(j),J=D?.type==="enum"?D.options??[]:D?.type==="boolean"?[!0,!1]:[];if(J.length===0)continue;let _=(R?.get(v)??[]).map(N=>g.get(N)).find(N=>N?.subject!==void 0&&Re(f,{name:N.name,args:{[N.subject.arg]:l.id,[v]:J.find(Se=>Se!==l[v])??J[0]}},o,!0));if(_?.subject)for(let N of J)l[v]!==N&&y.push({type:"fill",id:`fill:${l.id}:${v}:${Ce(N)}`,label:`${$e(c,l.kind,v)}: ${Ce(N)}`,description:`Set ${$e(c,l.kind,v).toLowerCase()} of ${L(c,l)} to ${Ce(N)}`,record:l.id,field:v,value:N,call:{name:_.name,args:{[_.subject.arg]:l.id,[v]:N}}})}for(let[v,j]of Object.entries(Y(c,l.kind))){if(h!==void 0&&v!==h)continue;let D=j.to==="*"?[...a]:j.to.filter(I=>a.has(I)),J=new Set(d.graph.out(l.id,v).map(I=>I.id)),_=u.find(I=>(I.connects??[]).includes(v)&&I.subject!==void 0&&fe(c,I).includes(l.kind));if(!_?.subject)continue;let N=De(_.input).find(I=>I.name!==_.subject.arg);if(!N)continue;let Se=D.flatMap(I=>N.kinds.length===0||N.kinds.includes(I)?d.graph.nodesOfKind(I):[]).filter(I=>I.id!==l.id&&!J.has(I.id)&&s(I.id)!==void 0);for(let I of m(Se)){let Me={name:_.name,args:{[_.subject.arg]:l.id,[N.name]:I.id}};Re(f,Me,o,!0)&&y.push({type:"fill",id:`fill:${l.id}:${v}:${I.id}`,label:`${B(v)}: ${L(c,I)}`,description:`Link ${L(c,l)} to ${L(c,I)}${j.description?` as ${j.description}`:""}`,record:l.id,field:v,value:I.id,call:Me})}}return y};if(n.on==="field"&&O)for(let l of F(O,n.field))A(l);else if(O&&n.on==="record")for(let l of m(F(O)))A(l);let q=l=>{let h=W(c,l).toLowerCase(),R=[{type:"panel",id:`panel:${l}:list`,label:`A list of ${h}`,description:`Every ${G(c.tryDefinition(l),l).toLowerCase()} this viewer may see, as a list`,panel:{lens:"blocks",kind:l}}],E=ge(c,l);for(let[$,y]of Object.entries(ye(c,l))){if(E.has($))continue;let v=pe(y),j=$e(c,l,$).toLowerCase();if(v?.type==="enum")R.push({type:"panel",id:`panel:${l}:group:${$}`,label:`${V(h)} by ${j}`,description:`A list of ${h} grouped by ${j}`,panel:{lens:"blocks",kind:l,group:$}}),R.push({type:"panel",id:`panel:${l}:columns:${$}`,label:`Columns of ${h} by ${j}`,description:`${V(h)} in a column for each ${j}`,panel:{lens:"columns",kind:l,column:$}});else if(v?.type==="number"||v?.type==="integer"||v?.type==="date"||v?.type==="datetime"){let D=v.type==="date"||v.type==="datetime";R.push({type:"panel",id:`panel:${l}:sort:${$}`,label:`${V(h)} by ${j}`,description:`A list of ${h}, the ${D?"latest":"highest"} ${j} first`,panel:{lens:"blocks",kind:l,sort:{by:$,direction:"desc"}}}),D&&R.push({type:"panel",id:`panel:${l}:calendar:${$}`,label:`A calendar of ${h}`,description:`${V(h)} on a calendar by ${j}`,panel:{lens:"calendar",kind:l,start:$}})}}return R},H=n.on==="place"?[...a]:k!==void 0?[k]:[];for(let l of H)for(let h of m(q(l)))A(h);for(let l of m((t.places??[]).filter(h=>h.kind===void 0?n.on==="place":a.has(h.kind)&&(n.on==="place"||h.kind===k))))n.on==="lens"&&l.as===n.place||A({type:"place",id:`place:${l.as}`,label:l.title,description:`Go to ${l.title}`,place:l.as});if(O){let l=[];for(let[h,R]of Object.entries(Y(c,O.kind)))for(let E of d.graph.out(O.id,h))s(E.id)&&l.push({type:"record",id:`record:${E.id}`,label:L(c,E),description:`${V(R.description??B(h))}: ${L(c,E)}`,record:E.id,relation:h});for(let h of c.kinds)for(let[R,E]of Object.entries(Y(c,h)))if(!(E.to!=="*"&&!E.to.includes(O.kind)))for(let $ of d.graph.in(O.id,R))$.kind===h&&s($.id)&&l.push({type:"record",id:`record:${$.id}`,label:L(c,$),description:`${V(E.inverse??B(R))}: ${L(c,$)}`,record:$.id,relation:R});for(let h of m(l))A(h)}else if(n.on==="list"||n.on==="lens")for(let l of m(k!==void 0?d.graph.nodesOfKind(k):[]))s(l.id)&&A({type:"record",id:`record:${l.id}`,label:L(c,l),description:`Open ${L(c,l)}`,record:l.id});else if(n.on==="selection")for(let l of x){let h=s(l);A({type:"record",id:`record:${l}`,label:L(c,h),description:`Open ${L(c,h)}`,record:l})}return{target:n,candidates:b}}var V=e=>e&&`${e[0].toUpperCase()}${e.slice(1)}`,xn={columns:["board","kanban","column","lane","pipeline","stage","funnel"],board:["board","map","floor","layout","seat","slot"],calendar:["calendar","schedule","date","due","month","week","agenda","deadline","day"],timeline:["timeline","gantt","schedule","roadmap","span"],coverage:["coverage","matrix","grid","gap"],plan:["plan","floor","map","region","area"],blocks:["list","table","summary","overview","dashboard","card"]},On=new Set(["a","an","the","of","for","my","our","me","us","to","with","and","in","on","by","that","which","i","we","want","need","show","open","go","draw","make","new","view","views","panel","panels","page","lens","please","all","every","some","see","can","could","would","like","one","what","is","are","do","does","here","there","how","it","this","these","those"]),te=e=>e.length>3&&e.endsWith("ies")?`${e.slice(0,-3)}y`:e.length>3&&e.endsWith("s")&&!e.endsWith("ss")?e.slice(0,-1):e,Te=e=>e.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").split(/[^a-z0-9]+/).filter(Boolean);function Ze(e,n,t){let i=e,o=ee(i)?.store??i,r=o.schema,f=me(o,t.principal),d=o.seenBy(t.principal),c=Q(n),a=new Set;for(let p of c){let w=d.graph.getNode(p)?.kind;w!==void 0&&f.has(w)&&a.add(w)}if(c.length>0&&a.size===0)return[];if(n.on==="list"&&a.add(n.kind),n.on==="lens"){let p=n.kind??t.places.find(w=>w.as===n.place)?.kind;p!==void 0&&a.add(p)}let s=new Map;for(let p of r.kinds){if(!f.has(p))continue;let w=r.tryDefinition(p);for(let T of[p,G(w,p),W(r,p)])for(let F of Te(T))s.set(te(F),p)}let u=Te(t.said??"").filter(p=>!On.has(p)),g=new Set,b=[];for(let p of u){let w=s.get(te(p));w!==void 0?g.add(w):b.push(te(p))}let C=g.size>0?g:a;if((t.said??"").trim()!==""&&u.length===0)return[];if(C.size===0&&u.length===0)return[];let A=[];t.places.forEach((p,w)=>{if(p.hidden||n.on==="lens"&&p.as===n.place)return;let T=p.over??(p.kind!==void 0?[p.kind]:[]);if(T.length>0&&!T.some(H=>f.has(H)))return;let F=T.some(H=>C.has(H)),q=!F&&(p.reads??[]).some(H=>C.has(H));C.size>0&&!F&&!q||A.push({place:p,own:F,reads:q,at:w})});let m=p=>new Set(Te(p.title).map(te)),x=new Set(b.filter(p=>A.some(({place:w})=>m(w).has(p)))),O=[];for(let{place:p,own:w,reads:T,at:F}of A){let q=m(p),H=new Set((xn[p.lens??""]??[]).map(te)),l=b.filter($=>q.has($)||H.has($)&&!x.has($)).length,h=b.length-l;if(b.length>0&&l===0)continue;let R=!T&&h===0?"full":"partial",E=(w?4:T?2:1)+l*2-h+(R==="full"?1:0);O.push({view:{place:p.as,title:p.title,...p.kind!==void 0?{kind:p.kind}:{},fit:R},score:E,at:F})}return O.filter((p,w)=>!O.slice(0,w).some(T=>T.view.place===p.view.place&&T.view.title===p.view.title)).sort((p,w)=>w.score-p.score||p.at-w.at).slice(0,t.most??3).map(p=>p.view)}var Ee=new WeakMap;function vn(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619)>>>0;return n.toString(36)}function $n(e,n){let t=e,i=ee(t)?.store??t,o=i.schema,r=me(i,n),d=i.allMutations().filter(A=>!A.destructive&&i.permits({name:A.name,args:{}},n).ok!==!1),c=`${[...r].join(",")}|${d.map(A=>A.name).join(",")}`,a=Ee.get(o)?.get(c);if(a)return a;let s=[...r].map(A=>{let m=ge(o,A),x={};for(let[w,T]of Object.entries(ye(o,A))){if(m.has(w))continue;let F=pe(T);F&&(x[w]=F.type==="enum"?`enum:${(F.options??[]).join("|")}`:F.type)}let O={};for(let[w,T]of Object.entries(Y(o,A)))O[w]=T.to==="*"?[...r]:T.to.filter(F=>r.has(F));let k=o.tryDefinition(A),p=Object.entries(k?.fieldAliases??{}).filter(([w,T])=>w in x&&T.length>0);return{kind:A,noun:G(o.tryDefinition(A),A),plural:W(o,A),fields:x,relations:O,...k?.aliases&&k.aliases.length>0?{aliases:k.aliases}:{},...p.length>0?{fieldAliases:Object.fromEntries(p)}:{}}}),u=d.map(A=>({name:A.name,title:A.title??B(A.name),...A.subject?{on:fe(o,A).filter(m=>r.has(m))}:{}})),g={kinds:s,acts:u},b={version:vn(JSON.stringify(g)),...g},C=Ee.get(o)??new Map;return C.set(c,b),Ee.set(o,C),b}var Cn=e=>e.name??e.id??e.kind;function en(e,n,t){let i=e,{principal:o}=t,r=ee(i)?.store??i,f=r.seenBy(o),d=r.schema,c=me(r,o),a=p=>{let w=f.graph.getNode(p);return w&&c.has(w.kind)?w:void 0},s=p=>({id:p.id,kind:p.kind,label:L(d,p)}),u=Q(n),g=u.length===1?a(u[0]):void 0,b=g?Object.fromEntries(Object.keys(ye(d,g.kind)).filter(p=>!ge(d,g.kind).has(p)&&g[p]!==void 0&&p!=="label").map(p=>[p,g[p]])):{},C={on:n.on,...g?{record:{...s(g),fields:b}}:{},...n.on==="field"&&g?{field:n.field}:{},...n.on==="list"&&c.has(n.kind)?{kind:n.kind}:{},...n.on==="lens"?{place:n.place,...n.kind&&c.has(n.kind)?{kind:n.kind}:{}}:{},...n.on==="place"?{place:n.place}:{},...n.on==="act"?{act:n.act}:{}},A=[...new Set([...n.on==="selection"?n.ids:[],...t.selection??[]])].flatMap(p=>{let w=a(p);return w?[s(w)]:[]}),m=[];if(g){for(let p of Object.keys(Y(d,g.kind)))for(let w of f.graph.out(g.id,p))a(w.id)&&m.push({...s(w),relation:p,direction:"out"});for(let p of d.kinds)for(let w of Object.keys(Y(d,p)))for(let T of f.graph.in(g.id,w))T.kind===p&&a(T.id)&&m.push({...s(T),relation:w,direction:"in"})}let x=f.batches().filter(p=>!p.ops.every(je)).slice(-(t.recent??6)).reverse().map(p=>({intent:p.intent,at:p.at,by:Cn(p.author)})),O=(t.purpose?.jobs??[]).filter(p=>Ge(p,o.roles)&&c.has(p.kind)).map(p=>({name:p.name,ask:p.ask,kind:p.kind})),k=t.purpose&&(t.purpose.for!==void 0||O.length>0)?{...t.purpose.for!==void 0?{for:t.purpose.for}:{},jobs:O}:void 0;return{...t.place!==void 0?{place:t.place}:{},target:C,selection:A,neighbors:m.slice(0,24),recent:x,schema:$n(r,o),...k?{purpose:k}:{},...t.friction?{friction:Qe(t.friction,d,{reader:o})}:{}}}function ie(e){if(!e.off)return e.fast??(e.decide?{model:e.name??"decide",decide:e.decide}:void 0)}function U(e){if(e.off)return;if(e.thinking)return e.thinking;let n=e.name??"model";if(e.complete){let t=e.complete;return{model:n,think:({system:i,prompt:o})=>t({prompt:o,system:i})}}if(e.turn){let t=e.turn;return{model:n,think:async({system:i,prompt:o})=>({text:await t({system:i,messages:[{role:"user",content:o}],tools:[],call:async()=>({error:"No tools here."})})})}}}var Pe=(e,n,t)=>e?n/1e6*(e.inputPerMillion??0)+t/1e6*(e.outputPerMillion??0):void 0,Ie=()=>`ai-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;function Rn(e,n,t=[]){let i=o=>{let r=e.graph.getNode(o);return r?ce(e.schema.tryDefinition(r.kind),r):"a record"};switch(n.on){case"record":return i(n.id);case"field":return`${i(n.id)} \xB7 ${n.field}`;case"selection":return`${n.ids.length} records`;case"list":return e.schema.tryDefinition(n.kind)?W(e.schema,n.kind):n.kind;case"lens":case"place":return t.find(o=>o.as===n.place)?.title??(n.place==="home"?"Home":n.place);case"act":return n.act}}var nn=e=>e.type!=="act"||e.asks.length===0,be=(e,n)=>({id:e.id,type:e.type,label:e.label,...n!==void 0?{confidence:n}:{}});function X(e,n){let t=n.interaction??Ie(),i=he(n.store,n.target,{principal:n.principal,...n.acts?{acts:n.acts}:{},...n.places?{places:n.places}:{}}),o=en(n.store,n.target,{principal:n.principal,...n.place?{place:n.place}:{},...n.selection?{selection:n.selection}:{},...n.purpose?{purpose:n.purpose}:{}}),r=[];return{id:t,catalog:i,state:o,entry:{id:t,at:new Date().toISOString(),by:n.by??n.principal,target:n.target,targetLabel:Rn(n.store,n.target,n.places)},usage:r,meter:f=>{r.push(f),e.meter?.({...f,interaction:t})}}}async function oe(e,n,t,i){let o=await e.decide(n,t),{inputTokens:r,outputTokens:f}=o.usage,d=Pe(e.price,r,f);return i({tier:"fast",model:e.model,inputTokens:r,outputTokens:f,...d!==void 0?{costUsd:d}:{}}),o.answers}async function re(e,n,t,i,o){let r=await e.think({system:n,prompt:t,state:i.state,catalog:i.catalog}),f=r.usage?.inputTokens,d=r.usage?.outputTokens,c=r.usage?.costUsd??(f!==void 0?Pe(e.price,f,d??0):void 0);return o({tier:"thinking",model:e.model,...f!==void 0?{inputTokens:f}:{},...d!==void 0?{outputTokens:d}:{},...c!==void 0?{costUsd:c}:{}}),Ve(r.text)}function se(e,n){let t=new Map(e.map((i,o)=>[`c${o+1}`,i]));return{question:{type:"choice",instructions:n,criteria:Object.fromEntries([...t].map(([i,o])=>[i,`${o.label} \u2014 ${o.description}`]))},of:i=>t.get(i)}}function ae(e,n,t){if(e?.type!=="choice")return[];let i=e,o=Object.entries(i.probabilities).sort((r,f)=>f[1]-r[1]);return o.some(([r])=>r===i.choice)||o.unshift([i.choice,i.confidence]),o.flatMap(([r,f])=>{let d=n(r);return d?[{candidate:d,confidence:f}]:[]}).slice(0,t)}var M=(e,n,t,i)=>({interaction:{...e.entry,ask:{kind:t,said:n??""},offered:[],outcome:"failed",failed:i,usage:[...e.usage]},offers:[]}),Z="AI isn't on here.";async function tn(e,n,t=3){let i=X(e,n),o=n.said??"Suggest",r=i.catalog.candidates.filter(nn).slice(0,24);if(r.length===0)return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:[],outcome:"offered",usage:[]},offers:[]};let f=ie(e),d=U(e),c=[];try{if(f){let{question:a,of:s}=se(r,"Which of these would the person most likely want to do next, here?"),u=await oe(f,{...i.state,candidates:r.map(g=>({id:g.id,type:g.type,says:g.description}))},{next:a},i.meter);c=ae(u.next,s,t)}else if(d){let a=await re(d,'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:i.state,candidates:r.map(u=>({id:u.id,says:u.description}))}),i,i.meter);c=(Array.isArray(a?.pick)?a.pick.filter(u=>typeof u=="string"):[]).flatMap(u=>r.filter(g=>g.id===u)).slice(0,t).map(u=>({candidate:u}))}else return M(i,o,"suggest",Z)}catch(a){return M(i,o,"suggest",a instanceof Error?a.message:String(a))}return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:c.map(({candidate:a,confidence:s})=>be(a,s)),outcome:"offered",usage:[...i.usage]},offers:c.map(({candidate:a})=>a)}}var Tn=e=>`several:${e}`;async function it(e,n,t=2){let i=X(e,{...n,acts:[]}),o=n.said??"Suggest for the chosen",r=n.target.on==="selection"?n.target.ids.length:1,d=[...n.shared.map(s=>({type:"act",id:Tn(s.id),label:s.label,description:`${s.label}, for all ${r} chosen`,mutation:s.mutation,args:s.args,asks:[]})),...i.catalog.candidates.filter(s=>s.type==="panel"||s.type==="place")].slice(0,24),c=ie(e);if(!c)return M(i,o,"suggest",Z);if(d.length===0)return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:[],outcome:"offered",usage:[]},offers:[]};let a;try{let{question:s,of:u}=se(d,`Which of these would the person most likely want to do next with the ${r} records they chose together?`),g=await oe(c,{...i.state,candidates:d.map(b=>({id:b.id,type:b.type,says:b.description}))},{next:s},i.meter);a=ae(g.next,u,t).filter((b,C)=>C===0||b.confidence>=En)}catch(s){return M(i,o,"suggest",s instanceof Error?s.message:String(s))}return{interaction:{...i.entry,ask:{kind:"suggest",said:o},offered:a.map(({candidate:s,confidence:u})=>be(s,u)),outcome:"offered",usage:[...i.usage]},offers:a.map(({candidate:s})=>s)}}var En=.25;async function on(e,n){let t=X(e,n),i=n.said??"Fill in",o=t.catalog.candidates.filter(u=>u.type==="fill"),r=new Map;for(let u of o)r.set(u.field,[...r.get(u.field)??[],u]);if(r.size===0)return{interaction:{...t.entry,ask:{kind:"fill",said:i},offered:[],outcome:"offered",usage:[]},offers:[]};let f=ie(e),d=U(e),c=[];try{if(f){let u=[...r].map(([b,C],A)=>({key:`f${A+1}`,field:b,...se(C,`Which value fits "${b}" best for this record?`)})),g=await oe(f,t.state,Object.fromEntries(u.map(b=>[b.key,b.question])),t.meter);for(let b of u){let C=!Pn(n.store,n.target,b.field)&&In(n.store,n.target,b.field)!=="one";c.push(...ae(g[b.key],b.of,C?3:1).filter((A,m)=>m===0||A.confidence>=.4))}}else if(d){let u=await re(d,`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:o.map(C=>({id:C.id,says:C.description}))}),t,t.meter),g=Array.isArray(u?.fills)?u.fills.filter(C=>typeof C=="string"):[],b=new Set;for(let C of g){let A=o.find(m=>m.id===C);A?.type==="fill"&&!b.has(A.field)&&(b.add(A.field),c.push({candidate:A}))}}else return M(t,i,"fill",Z)}catch(u){return M(t,i,"fill",u instanceof Error?u.message:String(u))}let a=t.usage.at(-1)?.model,s=de(n.store,{interaction:t.id,target:n.target,basis:i,...a?{model:a}:{},proposals:c.flatMap(({candidate:u,confidence:g})=>u.type==="fill"?[{id:u.id,label:u.label,said:u.description,call:u.call,record:u.record,field:u.field,...g!==void 0?{confidence:g}:{}}]:[])},n.principal);return{interaction:{...t.entry,ask:{kind:"fill",said:i},offered:s.proposals.map(u=>({id:u.id,type:"fill",label:u.label,...u.confidence!==void 0?{confidence:u.confidence}:{}})),outcome:"offered",usage:[...t.usage]},offers:[],...s.proposals.length>0?{ghost:s}:{}}}function Pn(e,n,t){let i=n.on==="record"||n.on==="field"?n.id:void 0,o=i?e.graph.getNode(i)?.kind:void 0,r=(o?e.schema.tryDefinition(o)?.fields?.shape:void 0)??{};return t in r}function In(e,n,t){let i=n.on==="record"||n.on==="field"?n.id:void 0,o=i?e.graph.getNode(i)?.kind:void 0;return o?e.schema.tryDefinition(o)?.edges?.[t]?.cardinality:void 0}async function rn(e,n){let t=X(e,n),i=n.said??"Add one",o=new Set(n.store.allMutations().filter(s=>(s.creates??[]).length>0).map(s=>s.name)),r=t.catalog.candidates.filter(s=>s.type==="act"&&s.asks.length>0&&o.has(s.mutation));if(r.length===0)return M(t,i,"record","Nothing here makes a record.");let f=U(e);if(!f)return M(t,i,"record",Z);let d;try{let s=await re(f,'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:i,state:t.state,candidates:r.map(b=>({id:b.id,says:b.description,asks:b.asks}))}),t,t.meter),u=r.find(b=>b.id===s?.act),g=typeof s?.args=="object"&&s.args!==null?s.args:{};u&&(d={act:u,args:Object.fromEntries(Object.entries(g).filter(([b])=>u.asks.includes(b)))})}catch(s){return M(t,i,"record",s instanceof Error?s.message:String(s))}if(!d)return M(t,i,"record","The model named no act this app has here.");let c=t.usage.at(-1)?.model,a=de(n.store,{interaction:t.id,target:n.target,basis:i,...c?{model:c}:{},proposals:[{id:d.act.id,label:d.act.label,said:d.act.description,call:{name:d.act.mutation,args:{...d.act.args,...d.args}}}]},n.principal);return a.proposals.length===0?M(t,i,"record","What the model proposed could not be made here."):{interaction:{...t.entry,ask:{kind:"record",said:i},offered:a.proposals.map(s=>({id:s.id,type:"act",label:s.said})),outcome:"offered",usage:[...t.usage]},offers:[d.act],ghost:a}}async function sn(e,n){let t=X(e,n),i=n.said??"Make a panel",o=t.catalog.candidates.filter(s=>s.type==="panel");if(o.length===0)return M(t,i,"panel","Nothing here can be drawn as a panel.");let r=ie(e),f=U(e),d;try{if(f){let s=await re(f,'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:i,state:t.state,candidates:o.map(g=>({id:g.id,says:g.description}))}),t,t.meter),u=o.find(g=>g.id===s?.panel);u&&(d={panel:u,...typeof s?.title=="string"&&s.title.trim()?{title:s.title.trim().slice(0,60)}:{}})}else if(r){let{question:s,of:u}=se(o,`Which panel answers this best: ${i}`),g=ae((await oe(r,t.state,{panel:s},t.meter)).panel,u,1)[0];g?.candidate.type==="panel"&&(d={panel:g.candidate,confidence:g.confidence})}else return M(t,i,"panel",Z)}catch(s){return M(t,i,"panel",s instanceof Error?s.message:String(s))}if(!d)return M(t,i,"panel","The model named no panel this app can draw.");let c=d.title??d.panel.label,a={title:c,recipe:{...d.panel.panel,title:c}};return{interaction:{...t.entry,ask:{kind:"panel",said:i},offered:[be(d.panel,d.confidence)],outcome:"drawn",panel:a,usage:[...t.usage]},offers:[d.panel],panel:a}}function Fn(e){return e.off?void 0:e.answer}var Mn=`You answer a person's question about what they are looking at in an app, from the state given and nothing else. Answer only JSON: {"answer": one to three short sentences, "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.`;async function ot(e,n){let t=X(e,n),i=n.said.trim(),o=t.catalog.candidates.filter(m=>nn(m)||m.type==="panel"||m.type==="place"||m.type==="record").slice(0,32),r=Fn(e),f=U(e),d=ie(e),c="",a=[],s=m=>m.flatMap(x=>o.filter(O=>O.id===x)).slice(0,3).map(x=>({candidate:x}));try{if(r){let m=await r.answer({said:i,target:n.target,targetLabel:t.entry.targetLabel,state:t.state,catalog:{target:t.catalog.target,candidates:o},...n.follows?{follows:n.follows}:{}}),x=m.usage?.inputTokens,O=m.usage?.outputTokens,k=m.usage?.costUsd??(x!==void 0?Pe(r.price,x,O??0):void 0);t.meter({tier:"thinking",model:r.model,...x!==void 0?{inputTokens:x}:{},...O!==void 0?{outputTokens:O}:{},...k!==void 0?{costUsd:k}:{}}),c=typeof m.text=="string"?m.text.trim():"",a=s(m.pick??[])}else if(f){let m=await re(f,Mn,JSON.stringify({ask:i,about:t.entry.targetLabel,...n.follows?{follows:n.follows}:{},state:t.state,candidates:o.map(x=>({id:x.id,says:x.description}))}),t,t.meter);c=typeof m?.answer=="string"?m.answer.trim():"",a=s(Array.isArray(m?.pick)?m.pick:[])}else if(d&&o.length>0){let{question:m,of:x}=se(o,`Which of these best answers, or acts on: ${i}`),O=await oe(d,{...t.state,asked:i,candidates:o.map(k=>({id:k.id,type:k.type,says:k.description}))},{answer:m},t.meter);a=ae(O.answer,x,3),c=a.length>0?`These fit \u201C${i}\u201D.`:""}else return M(t,i,"ask",Z)}catch(m){return M(t,i,"ask",m instanceof Error?m.message:String(m))}if(!c&&a.length===0){let m=n.target.on==="place"||n.target.on==="lens"?n.target.place:void 0,x=n.target.on==="list"||n.target.on==="lens"?n.target.kind:void 0;return Be(n.store,{type:"unanswered",question:i,...m?{place:m}:{},...x?{kind:x}:{}},n.principal),M(t,i,"ask","The AI had no answer to that here.")}let u=t.usage.at(-1)?.model,g=a.flatMap(({candidate:m,confidence:x})=>{let O=ke(m);return O?[{...O,...x!==void 0?{confidence:x}:{}}]:[]}),b=g.length>0?de(n.store,{interaction:t.id,target:n.target,basis:i,...u?{model:u}:{},proposals:g},n.principal):void 0,C=a.map(({candidate:m})=>m).filter(m=>ke(m)===void 0),A=[...C.map(m=>be(m,a.find(x=>x.candidate===m)?.confidence)),...(b?.proposals??[]).map(m=>({id:m.id,type:m.field!==void 0?"fill":"act",label:m.label,...m.confidence!==void 0?{confidence:m.confidence}:{}}))];return{interaction:{...t.entry,ask:{kind:"ask",said:i},offered:A,outcome:"offered",...c?{answer:c}:{},usage:[...t.usage]},offers:C,...b&&b.proposals.length>0?{ghost:b}:{},...c?{answer:c}:{}}}function de(e,n,t){let i=n.proposals.flatMap(o=>{try{let r=e.previewAll([o.call],{author:t}),f=r.ops.map(d=>d.intent).join("; ");return r.ops.length>0?[{...o,said:f||o.said}]:[]}catch{return[]}});return{...n,proposals:i}}function ke(e){if(e.type==="fill")return{id:e.id,label:e.label,said:e.description,call:e.call,record:e.record,field:e.field};if(e.type==="act"&&e.asks.length===0)return{id:e.id,label:e.label,said:e.description,call:{name:e.mutation,args:{...e.args}}}}function an(e,n,t){let i=n.proposals.filter(r=>t.ids===void 0||t.ids.includes(r.id));if(i.length===0)return{ok:!1,refused:"Nothing was chosen."};let o=i.flatMap(r=>r.confidence===void 0?[]:[r.confidence]);try{let f=e.applyAll(i.map(d=>d.call),{author:t.author,via:`ai:${n.interaction}`,intent:n.basis,lineage:{basis:`Asked \u201C${n.basis}\u201D`,...n.model?{model:n.model}:{},...o.length>0?{confidence:Math.min(...o)}:{},interaction:n.interaction}}).ops[0]?.batch;return f?{ok:!0,batch:f,accepted:i.map(d=>d.id)}:{ok:!1,refused:"That changes nothing now."}}catch(r){return{ok:!1,refused:r instanceof Error?r.message:String(r)}}}function dn(e,n,t){let i=e.ask.kind==="suggest"?n.length>0:e.offered.length>0&&e.offered.every(o=>n.includes(o.id));return{...e,outcome:i?"accepted":"partly",accepted:n,batches:[...e.batches??[],t]}}var ln=e=>({...e,outcome:"dismissed"});var P=xe(hn(),1);var S=xe(Ue(),1);function fn(e,n,t){let i=n.on==="selection"?n.ids:n.on==="record"||n.on==="field"?[n.id]:[],o=i.length>0?Ke(e.store,i,{principal:e.principal,...i.length===1?{focus:i[0]}:{}}).affordances.map(r=>({mutation:r.mutation,label:r.label,args:r.args,open:r.open,why:r.why,...r.destructive?{destructive:!0}:{}})):void 0;return{store:e.store,target:n,principal:e.principal,interaction:Ie(),places:e.places,selection:e.selection,...o?{acts:o}:{},...e.place?{place:e.place}:{},...t?{said:t}:{},...e.app.purpose?{purpose:e.app.purpose}:{}}}async function un(e,n,t){let i=await (__graviewPreload(import.meta.url,["./chunk.LGEA5257.js","./chunk.G4JJXA63.js","./chunk.OLFJH4RK.js","./chunk.67U6M7OV.js","./chunk.6C2MHWSX.js","./chunk.XOZU4OFA.js","./chunk.GLWSVSQL.js","./chunk.VFOON3Z3.js","./chunk.WVUJXDXZ.js","./chunk.7VKSXGTX.js","./chunk.TY4GQJKC.js","./chunk.6ZQAR5ZA.js","./chunk.W3W54DSX.js","./chunk.PI44XMY2.js","./chunk.KGW75Z5L.js","./chunk.MSWWWLEA.js","./chunk.UITT6JWW.js","./chunk.A5PDXNY6.js","./chunk.VSCIXAHN.js","./chunk.FQLNBIQ5.js","./chunk.AJZBJBMO.js"]),import("./chunk.QFUMFQJU.js")),o=i.recipeDraft(n.recipe,{app:e.app,sight:i.draftSight(e.app,e.principal)});if(i.isDraftFailure(o))return o.failed;t?.(),e.seatTalk.setDraft(o,null),e.goTo.draft?.(),pn()}function pn(e=180){if(typeof document>"u")return;let n=document.querySelector('[data-testid="draft-keep"]'),t=document.activeElement,i=!t||t===document.body||t.closest?.("[inert]")!==null;if(n){i&&n.focus();return}e>0&&requestAnimationFrame(()=>pn(e-1))}async function le(e,n,t,i,o){let r=fn(e,t,i),f=n==="suggest"?await tn(e.ai,r):n==="fill"?await on(e.ai,r):n==="record"?await rn(e.ai,r):await sn(e.ai,r);if(f.interaction.outcome==="failed")return n!=="suggest"&&e.desk.record(f.interaction),f;let d=c=>{let a={...f.interaction,outcome:"failed",failed:c};return e.desk.record(a),{...f,interaction:a}};if(n==="fill"||n==="record"){if(!f.ghost||f.ghost.proposals.length===0)return d("Nothing here could be filled in.");o?.(),e.desk.setGhost({ghost:f.ghost}),e.desk.record(f.interaction)}if(n==="panel"&&f.panel){let c=await un(e,f.panel,o);if(c)return d(c);e.desk.record(f.interaction)}return f}var Fe=new WeakMap,Nn=64,cn=new WeakMap;function jn(e){let n=cn.get(e);if(!n){let t=n={n:0};cn.set(e,t),e.subscribe(()=>void(t.n+=1))}return n.n}var yn=(e,n)=>{let t=Q(n);return t.length>0?t.map(i=>e.graph.getNode(i)):[jn(e)]},gn=(e,n,t)=>JSON.stringify({target:n,seat:e.principal,by:t}),mn=(e,n,t)=>{let i=yn(e.store,n);return t.schema===e.store.schema&&t.ai===e.ai&&i.length===t.depends.length&&i.every((o,r)=>o===t.depends[r])};function Dn(e,n,t="menu"){let i=Fe.get(e.store)?.get(gn(e,n,t));return i?.result!==void 0&&mn(e,n,i)?i.result:void 0}function Ln(e,n,t){let i=Fe.get(e.store);i||Fe.set(e.store,i=new Map);let o=gn(e,n,t?.by??"menu"),r=i.get(o);if(r&&mn(e,n,r))return r.result?Promise.resolve(r.result):r.asked;let f=t?t.ask():le(e,"suggest",n),d={schema:e.store.schema,ai:e.ai,depends:yn(e.store,n),asked:f};i.delete(o),i.set(o,d),i.size>Nn&&i.delete(i.keys().next().value);let c=i;return f.then(a=>{a.interaction.outcome!=="failed"?d.result=a:c.get(o)===d&&c.delete(o)}),f}async function Hn(e,n,t,i){let o=n.interaction,r=ke(t);if(r){let f=o.usage?.at(-1)?.model,d=o.offered.find(a=>a.id===t.id)?.confidence,c=de(e.store,{interaction:o.id,target:o.target,basis:`${o.ask.said}: ${t.label}`,...f?{model:f}:{},proposals:[{...r,...d!==void 0?{confidence:d}:{}}]},e.principal);if(c.proposals.length===0){let a="That can't be done now.";return e.desk.record({...o,outcome:"failed",failed:a}),a}i?.(),e.desk.setGhost({ghost:c}),e.desk.record(o);return}if(t.type==="panel"){let f=t.label,d={title:f,recipe:{...t.panel,title:f}},c=await un(e,d,i);return e.desk.record(c?{...o,outcome:"failed",failed:c}:{...o,outcome:"drawn",accepted:[t.id],panel:d}),c}i?.(),t.type==="place"?e.goTo.place(t.place):t.type==="record"&&e.goTo.record(t.record),e.desk.record({...o,outcome:"accepted",accepted:[t.id]})}async function yt(e,n){if(n.ask.kind==="ask")return ue(e.desk,{target:n.target,asked:n.ask.said}),null;let t=n.ask.kind==="panel"||n.ask.kind==="record"?n.ask.kind:"fill";return le(e,t,n.target,n.ask.said)}var z={padding:"5px 10px",fontSize:"0.875rem",borderRadius:8,width:"100%",textAlign:"left",borderWidth:1,borderStyle:"solid",borderColor:"transparent",background:"none",boxShadow:"none"},we={margin:0,padding:"4px 10px",fontSize:"0.8125rem",color:"var(--graview-ink-muted)"};function gt({target:e,close:n}){let t=Je(),i=(0,P.useMemo)(()=>Xe(e,y=>t.store.graph.has(y)),[e,t.store]),o=(0,P.useMemo)(()=>{let y=fn(t,i);return he(t.store,i,{principal:t.principal,places:t.places,...y.acts?{acts:y.acts}:{}})},[t,i]),r=o.candidates.some(y=>y.type==="fill"),f=o.candidates.some(y=>y.type==="panel"),d=(0,P.useMemo)(()=>f?Ze(t.store,i,{principal:t.principal,places:t.places,most:1}):[],[f,t,i]),c=(0,P.useMemo)(()=>new Set(t.store.allMutations().filter(y=>(y.creates??[]).length>0).map(y=>y.name)),[t.store]),a=U(t.ai)!==void 0&&o.candidates.some(y=>y.type==="act"&&y.asks.length>0&&c.has(y.mutation)),s=Oe(t.ai),u=Dn(t,i),g=JSON.stringify(i),[b,C]=(0,P.useState)(!1),[A,m]=(0,P.useState)(null),[x,O]=(0,P.useState)(s&&u===void 0);(0,P.useEffect)(()=>{if(u!==void 0||!(s||b))return;let y=!0;return O(!0),Ln(t,i).then(v=>{y&&(m(v),O(!1))}),()=>{y=!1}},[g,b]);let k=u??A,p=(k?.offers??[]).filter(y=>!(y.type==="place"&&d.some(v=>v.place===y.place))).slice(0,Math.max(0,3-d.length)),w=k?.interaction.outcome==="failed"?k.interaction.failed??"The AI could not suggest anything here.":null,T=(0,P.useRef)(!1),F=(0,P.useRef)(null);(0,P.useLayoutEffect)(()=>{k===null||!T.current||(T.current=!1,F.current?.querySelector("button")?.focus())},[k]);let q=(0,P.useRef)(!0);(0,P.useEffect)(()=>()=>{q.current=!1},[]);let[H,l]=(0,P.useState)(!1),[h,R]=(0,P.useState)(null),E=y=>{if(H)return;l(!0),R(null);let v=!1;y(()=>{v=!0,n()}).then(D=>{q.current&&(l(!1),D?R(D):v||n())},D=>{q.current&&(l(!1),R(D instanceof Error?D.message:String(D)))})},$=y=>y.interaction.outcome==="failed"?y.interaction.failed??"The AI could not do that here.":void 0;return(0,S.jsxs)("div",{ref:F,"data-testid":"inline-ai",style:{display:"grid",gap:2},children:[x&&!b?(0,S.jsx)("p",{role:"status","data-testid":"inline-ai-thinking",style:we,children:"Thinking\u2026"}):H?(0,S.jsx)("p",{role:"status","data-testid":"inline-ai-asking",style:we,children:"Asking\u2026"}):h?(0,S.jsx)("p",{role:"alert","data-testid":"inline-ai-failed",style:{...we,color:"var(--graview-warn)"},children:h}):w?(0,S.jsx)("p",{role:"status",style:we,children:w}):null,(0,S.jsxs)("ul",{style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:2},children:[p.map(y=>(0,S.jsx)("li",{children:(0,S.jsxs)("button",{type:"button","data-menu-item":`ai-offer:${y.id}`,"data-ai-offer":y.id,"data-ai-offer-type":y.type,onClick:()=>E(v=>Hn(t,k,y,v)),style:z,children:[y.label,(0,S.jsxs)("span",{style:{color:"var(--graview-ink-faint)"},children:[" \xB7 ",y.type==="panel"?"a panel":y.type==="place"?"go there":y.type==="record"?"open it":"suggested"]})]})},y.id)),!s&&k===null?(0,S.jsx)("li",{children:(0,S.jsx)("button",{type:"button","data-menu-item":"ai-suggest","aria-disabled":b||void 0,onClick:y=>{b||(T.current=document.activeElement===y.currentTarget,C(!0))},style:z,children:b?"Thinking\u2026":"Suggest\u2026"})}):null,r?(0,S.jsx)("li",{children:(0,S.jsx)("button",{type:"button","data-menu-item":"ai-fill",onClick:()=>E(async y=>$(await le(t,"fill",i,"Fill in",y))),style:z,children:"Fill in with AI"})}):null,a?(0,S.jsx)("li",{children:(0,S.jsx)("button",{type:"button","data-menu-item":"ai-record",onClick:()=>E(async y=>$(await le(t,"record",i,"Add one",y))),style:z,children:"Add one with AI"})}):null,d.map(y=>(0,S.jsx)("li",{children:(0,S.jsx)("button",{type:"button","data-menu-item":`ai-open:${y.place}`,"data-ai-existing":y.fit,onClick:()=>{n(),t.goTo.place(y.place),y.fit==="partial"&&ue(t.desk,{target:{on:"lens",place:y.place,...y.kind?{kind:y.kind}:{}}})},style:z,children:y.fit==="full"?`Open ${y.title}`:`Open and adjust ${y.title}`})},y.place)),f?(0,S.jsx)("li",{children:(0,S.jsx)("button",{type:"button","data-menu-item":"ai-panel",onClick:()=>E(async y=>$(await le(t,"panel",i,"Draw a panel",y))),style:z,children:d.length>0?"Draw a new view":"Draw a panel"})}):null,(0,S.jsx)("li",{children:(0,S.jsx)("button",{type:"button","data-menu-item":"ai-ask",onClick:()=>{let y=document.activeElement;n(),ue(t.desk,{target:i,returnTo:y instanceof HTMLElement&&y!==document.body?y:null})},style:z,children:"Ask about this\u2026"})})]})]})}var Ae={display:"inline-flex",alignItems:"center",minHeight:28,padding:"2px 10px",fontSize:"0.8125rem",borderRadius:8};function mt({placement:e="picture"}){let{store:n,principal:t,aiDesk:i}=ze(),o=We(n,t),{ghost:r,entries:f}=_e(i),[d,c]=(0,P.useState)(new Set);(0,P.useEffect)(()=>c(new Set),[r?.ghost.interaction]);let a=(0,P.useRef)(null),s=(0,P.useRef)(null),u=r?.batch;if((0,P.useEffect)(()=>{u!==void 0&&s.current?.focus()},[u]),!r)return null;let{ghost:g}=r,b=f.find(k=>k.id===g.interaction),C=()=>{let k=g.target.on==="record"||g.target.on==="field"?g.target.id:void 0,p=a.current?.closest("[data-graview-face], main")?.parentElement??document,w=(k?p.querySelector(`[data-graview-view="${CSS.escape(k)}"][tabindex]`):null)??document.querySelector("[data-graview-page-title]")??a.current?.closest("main")??document.querySelector("main");w&&!w.hasAttribute("tabindex")&&w.setAttribute("tabindex","-1"),w?.focus({preventScroll:!0}),i.setGhost(null)},A=g.proposals.filter(k=>!d.has(k.id)).map(k=>k.id),m=()=>{let k=an(o,g,{author:t,ids:A});if(!k.ok){i.setGhost({...r,refused:k.refused});return}b&&i.record(dn(b,k.accepted,k.batch)),i.setGhost({ghost:g,batch:k.batch,took:k.accepted.length,...r.onCard?{onCard:!0}:{}})},x=()=>{b&&r.batch===void 0&&i.record(ln(b)),C()},O=()=>{if(r.batch!==void 0)try{o.undo(r.batch,{author:t}),C()}catch(k){i.setGhost({...r,refused:k instanceof Error?k.message:String(k)})}};return(0,S.jsxs)("section",{ref:a,"data-testid":"ai-ghost","data-interaction":g.interaction,"aria-label":"Proposed by AI",style:{...e==="card"?{position:"static"}:{position:e==="page"?"fixed":"absolute",insetInline:"max(12px, calc(50% - 220px))",bottom:"calc(var(--graview-foot-room, 0px) + 72px)",zIndex:He("toast"),boxShadow:"var(--graview-lift-high)"},display:"grid",gap:8,padding:12,borderRadius:12,border:"1px dashed var(--graview-accent)",background:"var(--graview-float)",fontSize:"0.875rem"},children:[(0,S.jsx)("p",{style:{margin:0,color:"var(--graview-ink-muted)"},children:r.batch!==void 0?`Done: ${r.took===1?"one change":`${r.took} changes`}, as one.`:`Proposed by AI \xB7 ${g.basis}`}),r.batch===void 0?(0,S.jsx)("ul",{style:{margin:0,padding:0,listStyle:"none",display:"grid",gap:4},children:g.proposals.map(k=>(0,S.jsx)("li",{"data-ghost-proposal":k.id,children:(0,S.jsxs)("label",{style:{display:"flex",alignItems:"baseline",gap:8,cursor:"pointer"},children:[(0,S.jsx)("input",{type:"checkbox",checked:!d.has(k.id),onChange:p=>{let w=new Set(d);p.target.checked?w.delete(k.id):w.add(k.id),c(w)}}),(0,S.jsx)("span",{style:{fontStyle:"italic",color:"var(--graview-ink)"},children:k.said}),k.confidence!==void 0?(0,S.jsxs)("span",{style:{color:"var(--graview-ink-faint)"},children:[Math.round(k.confidence*100),"% sure"]}):null]})},k.id))}):null,r.refused?(0,S.jsx)("p",{role:"alert",style:{margin:0,color:"var(--graview-warn)"},children:r.refused}):null,(0,S.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:r.batch===void 0?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("button",{type:"button","data-testid":"ghost-accept",disabled:A.length===0,onClick:m,style:Ae,children:A.length===g.proposals.length?"Accept":`Accept ${A.length} of ${g.proposals.length}`}),(0,S.jsx)("button",{type:"button","data-testid":"ghost-dismiss",onClick:x,style:Ae,children:"Dismiss"})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("button",{type:"button",ref:s,"data-testid":"ghost-undo",onClick:O,style:Ae,children:"Undo"}),(0,S.jsx)("button",{type:"button","data-testid":"ghost-close",onClick:C,style:Ae,children:"Close"})]})})]})}export{Xe as a,Q as b,he as c,Ze as d,ie as e,Ie as f,Rn as g,Tn as h,it as i,ot as j,fn as k,un as l,le as m,Dn as n,Ln as o,Hn as p,yt as q,gt as r,mt as s};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as p}from"./chunk.
|
|
1
|
+
import{e as p}from"./chunk.RXYNW5QB.js";import{lc as g}from"./chunk.VSCIXAHN.js";function w(n){let r=n.policy?.sees??[];if(r.length===0)return!0;let t=o=>o.fields===void 0&&(o.hide?.length??0)===0;return n.schema.kinds.every(o=>r.some(s=>s.roles==="*"&&!s.own&&!s.via&&t(s)&&s.kinds.includes(o)))}function b(n){let r=n;for(let t=0;t<8&&r?._zod?.def;t+=1){let o=r._zod.def;if(o.type==="enum")return Object.values(o.entries);if(o.type==="literal")return o.values;if(!("innerType"in o))return;r=o.innerType}}var c=(n,r)=>({ok:!1,reason:n,message:r});function k(n,r){return p(n).find(t=>(t.as??t.act)===r)??p(n).find(t=>t.act===r&&t.as===void 0)}var m=n=>typeof n=="object"&&n!==null&&!Array.isArray(n)&&"href"in n;function S(n,r,t,o,s){let l=k(r,t);if(!l)return c("undeclared",`This view may not ask for \u201C${t}\u201D: its manifest does not name it.`);let u={},f=new Map;for(let[a,d]of Object.entries(o)){let y=i=>{if(!m(i))return i;let e=typeof i.href=="string"?s?.file(i.href):void 0;if(!e)throw c("malformed",`\u201C${a}\u201D is a file the host did not hand this view: a view hands an act a file the person dropped (event.files), or one a record it was shown holds, as it was handed.`);let h=s?.dropped(e.href);if(h){if(f.has(e.href))throw c("malformed",`\u201C${a}\u201D hands the act a dropped file it already carries: each file a person dropped goes in one act, once.`);f.set(e.href,h)}return e};try{u[a]=Array.isArray(d)?d.map(y):y(d)}catch(i){return i}}if(!w(n)){let a=new Set([...f.values()].map(e=>e.target)),d=a.size===1?[...a][0]:void 0,y=e=>m(e)&&typeof e.href=="string"&&f.has(e.href)||g(e)||d!==void 0&&e===d&&s?.shown.has(d)===!0;return f.size>0&&a.size===1&&Object.values(u).every(e=>Array.isArray(e)?e.every(y):y(e))?{ok:!0,name:l.act,args:{...u,...l.constants??{}},spent:[...f.keys()]}:c("press-only","In this app some members may not see some records, so a view's act applies only when you press it.")}return{ok:!0,name:l.act,args:{...u,...l.constants??{}}}}export{w as a,b,c,k as d,S as e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk.GZHZLJBF.js";import{n as P}from"./chunk.
|
|
1
|
+
import"./chunk.GZHZLJBF.js";import{n as P}from"./chunk.IOK4GVJC.js";import"./chunk.OJGHDWI6.js";import"./chunk.TLJOZSDD.js";import"./chunk.MSWWWLEA.js";import"./chunk.UITT6JWW.js";import"./chunk.A5PDXNY6.js";import"./chunk.WC3DENU4.js";import"./chunk.VNDKKTED.js";import{G as A,T as S,ca as b}from"./chunk.4MP72LPR.js";import"./chunk.SDO3U72B.js";import{$c as x,Da as w,qa as L}from"./chunk.VSCIXAHN.js";import"./chunk.FQLNBIQ5.js";import{b as R}from"./chunk.AJZBJBMO.js";var u=R(A(),1);var n=R(S(),1),C={kind:"human"},p={color:"var(--graview-ink-muted)"};function I(e){if(e){if(/^https?:\/\//i.test(e))try{return new URL(e).href}catch{return}return L(e)?e:void 0}}function z(e){let o=b(),t=o?.linkedReads,[i,a]=(0,u.useState)(()=>t?t.answered(e)??"asking":null);return(0,u.useEffect)(()=>{if(!t){a(o?.linkedRecords?"asking":null);return}let d=t.answered(e);if(a(d===void 0?"asking":d),d!==void 0)return;let s=!0;return t.ask(e).then(l=>s&&a(l)),()=>{s=!1}},[t,o?.linkedRecords,e.address,e.kind,e.id]),i}function V({reference:e,as:o}){let t=b(),i=z(e),a={position:"relative",zIndex:x.raised,overflowWrap:"anywhere",minWidth:0,maxWidth:"100%"};if(i==="asking")return(0,n.jsx)("span",{"data-graview-linked":"","data-graview-linked-state":"asking","aria-busy":"true",style:{...p,...a},children:"Linked record"});if(i&&"denied"in i)return(0,n.jsx)("span",{"data-graview-linked":"","data-graview-linked-state":"denied",style:{...p,fontStyle:"italic",...a},children:"linked record (no access)"});if(!i)return(0,n.jsx)("span",{"data-graview-linked":"","data-graview-linked-state":"missing",style:{...p,fontStyle:"italic",...a},children:"linked record (not found)"});let d=I(i.href),s=t?.linkedRecords,l=t?.principal??C,g=s?.open?c=>{c.metaKey||c.ctrlKey||(c.preventDefault(),s.open(e,l))}:void 0,k=(0,n.jsx)("a",{"data-graview-linked-title":"",...d?{href:d}:{role:"link",tabIndex:0},...g?{onClick:g,onKeyDown:c=>!d&&(c.key==="Enter"||c.key===" ")?g(c):void 0}:{},style:{fontWeight:600,color:"inherit",textUnderlineOffset:3,cursor:d||g?"pointer":"default"},children:i.label});return o==="chip"?(0,n.jsx)("span",{"data-graview-linked":"","data-graview-linked-state":"found",title:i.describe,style:{display:"inline-flex",alignItems:"center",minHeight:24,...a},children:k}):(0,n.jsx)(D,{record:i,title:k,base:a})}function D({record:e,title:o,base:t}){return(0,n.jsxs)("span",{"data-graview-linked":"","data-graview-linked-state":"found",style:{display:"grid",gap:2,padding:"8px 10px",border:"1px solid var(--graview-line)",borderRadius:"var(--graview-radius-sm, 6px)",background:"var(--graview-surface)",...t},children:[(0,n.jsxs)("span",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"2px 8px"},children:[o,e.app?(0,n.jsxs)("span",{"data-graview-linked-app":"",style:{...p,fontSize:"0.75rem"},children:["in ",e.app]}):null]}),e.describe?(0,n.jsx)("span",{"data-graview-linked-describe":"",style:{...p,fontSize:"0.8125rem"},children:e.describe}):null,e.card&&e.card.length>0?(0,n.jsx)("span",{"data-graview-linked-card":"",style:{display:"flex",flexWrap:"wrap",gap:"2px 12px",fontSize:"0.8125rem"},children:e.card.map(i=>(0,n.jsxs)("span",{children:[(0,n.jsx)("span",{style:p,children:i.label})," ",i.text]},i.label))}):null]})}function H({relation:e,refs:o,as:t="record",nodeId:i,field:a,style:d}){let s=(0,n.jsx)("span",{"data-graview-linked-list":"",style:{display:"grid",gap:6,minWidth:0,...d},children:o.map(l=>(0,n.jsx)(V,{reference:l,as:t},w(l)))});return i&&a?(0,n.jsx)(K,{nodeId:i,field:a,relation:e,refs:o,drawn:s}):s}function K({nodeId:e,field:o,relation:t,refs:i,drawn:a}){let{fields:d,commit:s}=P(e),l=d.find(f=>f.field===o),[g,k]=(0,u.useState)(!1);if(!l)return a;let c=t.cardinality==="one"?i[0]?w(i[0]):void 0:i.map(w);return(0,n.jsxs)("span",{style:{display:"grid",gap:6,minWidth:0},children:[a,g?(0,n.jsx)(N,{relation:t,value:c,label:"Link another record",onChange:f=>{s(l,f),k(!1)},onCancel:()=>k(!1)}):(0,n.jsx)("button",{type:"button","data-graview-linked-change":"",onClick:()=>k(!0),style:{justifySelf:"start",font:"inherit",fontSize:"0.8125rem",background:"none",border:0,padding:"4px 0",color:"var(--graview-accent)",cursor:"pointer",minHeight:24},children:"Change"})]})}function N({relation:e,value:o,onChange:t,onCancel:i,label:a}){let d=b(),s=d?.linkedRecords,l=d?.principal??C,g=(0,u.useId)(),[k,c]=(0,u.useState)(""),[f,m]=(0,u.useState)("asking");(0,u.useEffect)(()=>{if(!s)return;let r=!0;m("asking");let y=setTimeout(()=>{Promise.resolve().then(()=>s.find({address:e.address,kinds:e.kinds,query:k,limit:20},l)).then(h=>r&&m(Array.isArray(h)?h:"denied"),()=>r&&m([]))},150);return()=>{r=!1,clearTimeout(y)}},[s,e.address,e.kinds.join(","),k,l.kind,l.id]);let v=new Set([o].flat().filter(r=>typeof r=="string")),W=r=>{let y=w(r);if(e.cardinality==="one")return t(y);t(v.has(y)?[...v].filter(h=>h!==y):[...v,y])};return s?(0,n.jsxs)("span",{"data-graview-linked-picker":"",style:{display:"grid",gap:6,minWidth:0},children:[(0,n.jsx)("label",{htmlFor:g,style:{...p,fontSize:"0.8125rem"},children:a}),(0,n.jsx)("input",{id:g,type:"search",value:k,placeholder:`Find one in ${e.address}`,onChange:r=>c(r.target.value),style:{font:"inherit",minHeight:32,padding:"4px 8px",border:"1px solid var(--graview-line)",borderRadius:6,background:"var(--graview-surface)",color:"inherit",minWidth:0}}),f==="asking"?(0,n.jsx)("span",{"aria-busy":"true",style:p,children:"Looking\u2026"}):f==="denied"?(0,n.jsx)("span",{"data-graview-linked-state":"denied",style:{...p,fontStyle:"italic"},children:"linked record (no access)"}):f.length===0?(0,n.jsx)("span",{style:p,children:"Nothing there matches."}):(0,n.jsx)("ul",{role:"list",style:{listStyle:"none",margin:0,padding:0,display:"grid",gap:4},children:f.map(r=>{let y=v.has(w(r));return(0,n.jsx)("li",{children:(0,n.jsxs)("button",{type:"button","data-graview-linked-candidate":w(r),"aria-pressed":y,onClick:()=>W(r),style:{display:"grid",gap:2,width:"100%",textAlign:"start",font:"inherit",padding:"6px 8px",minHeight:32,border:"1px solid var(--graview-line)",borderRadius:6,background:y?"var(--graview-accent-soft, var(--graview-surface))":"var(--graview-surface)",color:"inherit",cursor:"pointer"},children:[(0,n.jsx)("span",{style:{fontWeight:600},children:r.label}),r.describe?(0,n.jsx)("span",{style:{...p,fontSize:"0.8125rem"},children:r.describe}):null]})},w(r))})}),i?(0,n.jsx)("button",{type:"button",onClick:i,style:{justifySelf:"start",font:"inherit",fontSize:"0.8125rem",background:"none",border:0,padding:"4px 0",color:"var(--graview-ink-muted)",cursor:"pointer",minHeight:24},children:"Keep it as it is"}):null]}):(0,n.jsxs)("span",{"data-graview-linked-picker":"","data-graview-linked-state":"no-host",style:p,children:["This page cannot read ",e.address,", so nothing there can be linked here."]})}var T=e=>(0,n.jsx)(H,{...e}),U=e=>(0,n.jsx)(N,{...e});export{N as LinkedPicker,H as LinkedRecordView,U as drawLinkedPicker,T as drawLinkedRecord};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as B,b as ve}from"./chunk.
|
|
1
|
+
import{a as B,b as ve}from"./chunk.BQIHNT7C.js";import{a as ye,c as he,d as be,f as we}from"./chunk.2K4TT2BV.js";import{b as S,c as fe,d as me,j as ce,k as ge}from"./chunk.MSWWWLEA.js";import{b as pe,k as q}from"./chunk.UITT6JWW.js";import{c as de,f as ue}from"./chunk.A5PDXNY6.js";import{G as Re,T as se,ca as le,h as ae,u as ie}from"./chunk.4MP72LPR.js";import{Ha as te,Sa as re,Ta as oe,da as Z,ga as ee,oa as ne}from"./chunk.VSCIXAHN.js";import{b as W}from"./chunk.AJZBJBMO.js";var l=W(Re(),1);var i=W(se(),1);function qe({affordance:n,onApply:a,onCancel:u,store:w}){let y=le(),s=w??y?.store,[x,_]=(0,l.useState)({}),[p,D]=(0,l.useState)(""),[I,F]=(0,l.useState)(G),[J,V]=(0,l.useState)(void 0),U=(0,l.useId)(),L=(0,l.useRef)(null),A=n.open.filter(e=>!(e.name in x)),o=A[0],v=s.allMutations().find(e=>e.name===n.mutation),P=(0,l.useMemo)(()=>De(v,s,n.args??{}),[v,s,n.args]),d=o?P[o.name]:void 0,E=ge(n.open.filter(e=>e.shape?.type==="date").map(e=>e.name)),Se=(()=>{if(!E||o?.name!==E.end||o.shape?.type!=="date")return;let e=x[E.start];if(typeof e!="string")return;let r=P[E.start];return ce(typeof r=="string"?r:void 0,e,typeof d=="string"?d:void 0,{time:o.shape.time===!0,instant:o.shape.instant===!0})})();(0,l.useEffect)(()=>{D(Se??ke(d,o?.shape)),F(Array.isArray(d)?d:G),V(d)},[o?.name]),(0,l.useEffect)(()=>{L.current?.scrollIntoView?.({block:"nearest",inline:"nearest"})},[o?.name]),(0,l.useLayoutEffect)(()=>{let e=L.current,r=typeof document>"u"?null:document.activeElement,f=r instanceof HTMLElement&&r.getAttribute("data-affordance")===n.id;if(!e||r&&r!==document.body&&!e.contains(r)&&!f)return;let b=e.querySelector('[data-testid="ask-filter"], form input, [role=group] button:not([disabled])');b&&b!==r&&b.focus()},[o?.name]);let Y=ve({flow:"both",letters:!0});if(!o)return null;let h=e=>{let r=d!==void 0&&JSON.stringify(e)===JSON.stringify(d)?void 0:e,f={...x,[o.name]:r};if(n.open.filter(R=>!(R.name in f)).length===0){let R=a(Object.fromEntries(Object.entries(f).filter(([,M])=>M!==void 0)));R&&R.length>0&&_(Object.fromEntries(Object.entries(f).filter(([M])=>!R.includes(M))))}else _(f)},O=o.optional?(0,i.jsx)("button",{type:"button",onClick:()=>h(void 0),style:{fontSize:"0.8125rem"},children:"Skip"}):null,t=o.shape??{type:"unknown"},c=t.type==="number"?t.amount:void 0,g=Ee(o,t),m=q(s.schema,v,o.name),Q=te((v?.input?.shape??{})[o.name]),xe=oe((v?.input?.shape??{})[o.name]),N=re(o.name),Ae=typeof d=="boolean"?d?"yes":"no":d,[T,Oe]=(0,l.useState)(""),X=(0,l.useMemo)(()=>{let e=g.map(r=>s.graph.getNode(r)).filter(r=>r!==void 0);return pe(e,r=>s.schema.tryDefinition(r))},[g,s]),j=e=>{let r=Ce(s,t,e),f=t.type==="choice"||t.type==="several"&&t.of.type==="choice"?m.option(e):r,b=X.get(e);return b?`${f} \xB7 ${b}`:f},$=(0,l.useMemo)(()=>{let e=T.trim().toLowerCase();return e===""?g:g.filter(r=>j(r).toLowerCase().includes(e))},[g,T,s,t,X]),k=t.type==="several",H=t.type==="file"?t:t.type==="several"&&t.of.type==="file"?t.of:void 0,K=k&&g.length===0,C=o.kinds&&o.kinds.length>0&&!o.kinds.includes("*")?o.kinds.map(e=>Z(ne(s.schema.tryDefinition(e),e))).join(" or "):m.label,Ne=n.open.length>1?`${C} \xB7 ${n.open.length-A.length+1} of ${n.open.length}`:C;return(0,i.jsxs)("div",{ref:L,"data-graview-asking":n.id,style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr)",gap:4,padding:"5px 0 2px"},children:[n.open.length>1||g.length>0?(0,i.jsx)("span",{id:U,style:{fontSize:"0.75rem",color:"var(--graview-ink-faint)"},children:Ne}):null,g.length>z?(0,i.jsx)("input",{type:"search",value:T,onChange:e=>Oe(e.target.value),placeholder:`Filter ${g.length}\u2026`,"aria-label":`Filter ${C}`,"data-testid":"ask-filter",onKeyDown:e=>{if(e.key!=="ArrowDown"||e.metaKey||e.ctrlKey||e.altKey)return;let r=Y.ref.current?.querySelector(`[${B}][tabindex="0"]`);r&&(e.preventDefault(),r.focus())},style:{font:"inherit",fontSize:"0.8125rem",minWidth:0,padding:"3px 7px"}}):null,xe?(0,i.jsxs)("form",{style:{display:"grid",gap:4},onSubmit:e=>{e.preventDefault(),h(J??(d===void 0?void 0:null))},children:[(0,i.jsx)(be,{value:J,onChange:V,start:N?x[N]??P[N]:void 0,label:`${N?q(s.schema,v,N).label:m.label} repeats`,name:o.name}),(0,i.jsxs)("span",{style:{display:"flex",gap:4},children:[(0,i.jsx)("button",{type:"submit",style:{fontSize:"0.8125rem"},children:A.length>1?"Next":"Apply"}),O]})]}):Q?(0,i.jsxs)("div",{style:{display:"grid",gap:4},children:[(0,i.jsx)(he,{relation:Q,value:d,onChange:h,label:m.label}),O]}):H?(0,i.jsxs)("div",{style:{display:"grid",gap:4},children:[(0,i.jsx)(ye,{as:"control",value:d,onChange:h,several:k,image:H.image===!0,video:H.video===!0,label:m.label}),O]}):g.length>0?(0,i.jsxs)("div",{...Y,role:"group","aria-labelledby":U,style:{display:"flex",flexWrap:"wrap",gap:4},children:[$.slice(0,z).map(e=>{let r=k?I.includes(e):e===Ae;return(0,i.jsx)("button",{type:"button",[B]:"","aria-label":`${C}: ${j(e)}`,...k?{"aria-pressed":r}:r?{"aria-current":!0}:{},style:{padding:"3px 9px",fontSize:"0.8125rem",...r?{borderColor:"var(--graview-accent)",color:"var(--graview-accent)"}:{}},onClick:()=>k?F(f=>f.includes(e)?f.filter(b=>b!==e):[...f,e]):h(t.type==="boolean"?e==="yes":e),children:j(e)},e)}),$.length>z?(0,i.jsxs)("span",{"data-testid":"ask-more",style:{alignSelf:"center",fontSize:"0.75rem",color:"var(--graview-ink-faint)"},children:[$.length-z," more \u2014 type to narrow"]}):null,$.length===0?(0,i.jsxs)("span",{"data-testid":"ask-none",style:{alignSelf:"center",fontSize:"0.75rem",color:"var(--graview-ink-faint)"},children:["None of the ",g.length," match that."]}):null,k?(0,i.jsx)("button",{type:"button",disabled:I.length===0,style:{fontSize:"0.8125rem"},onClick:()=>{let e=I;F(G),h(e)},children:A.length>1?"Next":"Apply"}):null,O]}):(0,i.jsxs)("form",{style:{display:"flex",flexWrap:"wrap",gap:4},onSubmit:e=>{if(e.preventDefault(),d!==void 0&&p===ke(d,t)){h(void 0);return}if(K){h(p.split(/[,\n]/).map(r=>r.trim()).filter(Boolean));return}if(p.trim().length!==0){if(c){let r=me(p,c);r!==void 0&&h(r);return}h(t.type==="number"?t.duration?ue(p)??p:Number(p):p)}},children:[t.type==="text"&&t.long?(0,i.jsx)("textarea",{autoFocus:!0,name:o.name,"aria-label":m.label,placeholder:m.label,value:p,rows:4,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key==="Escape"?u():e.key==="Enter"&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),e.currentTarget.form?.requestSubmit())},style:{flex:"1 1 100%",minWidth:0,font:"inherit",fontSize:"0.875rem",lineHeight:1.45,padding:"5px 8px",borderRadius:7,border:"1px solid var(--graview-edge)",background:"var(--graview-panel)",color:"var(--graview-ink)",resize:"vertical",fieldSizing:"content",minHeight:"5.5em",maxHeight:"40vh"}}):t.type==="date"?(0,i.jsx)(we,{autoFocus:!0,name:o.name,label:m.label,value:p===""?void 0:p,time:t.time===!0,instant:t.instant===!0,partial:t.partial===!0,onChange:e=>D(e??""),onCancel:u,boxStyle:{fontSize:"0.875rem",padding:"5px 8px",borderRadius:7,border:"1px solid var(--graview-edge)",background:"var(--graview-panel)",color:"var(--graview-ink)"}}):(0,i.jsx)("input",{autoFocus:!0,type:t.type==="number"&&!t.duration&&!c?"number":t.type==="text"&&t.holds==="phone"?"tel":"text",...c?{inputMode:"decimal","data-graview-amount":c.format??"unit"}:{},name:o.name,"aria-label":m.label,placeholder:K?`${m.label}, separated by commas`:c?`${m.label}, ${S(c).hint} \u2014 ${S(c).prefix??""}${S(c).placeholder}${S(c).suffix?` ${S(c).suffix}`:""}`:m.label,value:p,...t.type==="number"&&t.min!==void 0?{min:t.min}:{},...t.type==="number"&&t.max!==void 0?{max:t.max}:{},...t.type==="number"&&t.step!==void 0?{step:t.step}:{},onChange:e=>D(e.target.value),onKeyDown:e=>{e.key==="Escape"&&u()},style:{flex:1,minWidth:0,font:"inherit",fontSize:"0.875rem",padding:"5px 8px",borderRadius:7,border:"1px solid var(--graview-edge)",background:"var(--graview-panel)",color:"var(--graview-ink)"}}),(0,i.jsx)("button",{type:"submit",disabled:!K&&p.trim().length===0,style:{fontSize:"0.8125rem"},children:A.length>1?"Next":"Apply"}),O]})]})}var G=[];function De(n,a,u){let w=n?.derived?.act==="edit"&&n.subject?u[n.subject.arg]:void 0,y=typeof w=="string"?a.graph.getNode(w):void 0;return y?Object.fromEntries((n.writes??[]).filter(s=>y[s]!==void 0&&y[s]!==null).map(s=>[s,y[s]])):{}}function ke(n,a){return typeof n=="number"?a?.type==="number"&&a.amount?fe(n,a.amount):String(n):Array.isArray(n)?n.every(u=>typeof u=="string")?n.join(", "):"":typeof n!="string"?"":n}var z=10;function Ee(n,a){return n.candidates&&n.candidates.length>0?n.candidates:a.type==="choice"?a.options:a.type==="several"&&a.of.type==="choice"?a.of.options:a.type==="boolean"?$e:[]}var $e=["yes","no"];function Ce(n,a,u){return a.type==="boolean"||a.type==="choice"||a.type==="several"&&a.of.type==="choice"?u:ze(n,u)}function ze(n,a){let u=ae(a);if(u){let s=de(n.schema,n.graph.getNode(u.from)?.kind??"",u.kind,"out");return s.charAt(0).toUpperCase()+s.slice(1)}let w=ie(a);if(w.length>0)return w.map(s=>n.schema.tryDefinition(s)?.plural??`${s}s`).join(" + ");let y=n.graph.getNode(a);return y?ee(n.schema.tryDefinition(y.kind),y):a}export{qe as a,ze as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./chunk.WVUJXDXZ.js";import{k as m,m as i}from"./chunk.7VKSXGTX.js";import"./chunk.TY4GQJKC.js";import"./chunk.6ZQAR5ZA.js";import"./chunk.W3W54DSX.js";import"./chunk.PI44XMY2.js";import"./chunk.KGW75Z5L.js";import"./chunk.A5PDXNY6.js";import"./chunk.VSCIXAHN.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";function a(t){let r=new Map;return(s,o)=>{let e=o.kind,n=r.get(e);return n===void 0&&r.set(e,n=i(t,e).length),n===0?{}:m(t,s,o).values}}export{a as computedOn};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./chunk.KHRS2SKB.js";import"./chunk.
|
|
1
|
+
import"./chunk.KHRS2SKB.js";import"./chunk.YH63KQ2G.js";import"./chunk.25VJPUDH.js";import"./chunk.644FUGSX.js";import"./chunk.IGVASEZU.js";import{a as L,b as R,c as N}from"./chunk.UJTE7UAP.js";import{b as T}from"./chunk.JEYQBH33.js";import"./chunk.MVWC3VR3.js";import"./chunk.CC5BJH5A.js";import"./chunk.QI4SLPQ4.js";import"./chunk.CFKZXLXS.js";import"./chunk.Y5C4RXG7.js";import"./chunk.7MHCGVGM.js";import"./chunk.FRYBMS3W.js";import"./chunk.LQVAABPS.js";import"./chunk.NGTRL5U4.js";import"./chunk.3MOJF7BA.js";import"./chunk.LZIBQ3VX.js";import"./chunk.HJCQ6I3S.js";import"./chunk.QDSEVPF3.js";import"./chunk.7N32AVIJ.js";import"./chunk.IHBUBZQT.js";import"./chunk.PNW5K7BW.js";import"./chunk.ENL2JJ47.js";import"./chunk.BQIHNT7C.js";import"./chunk.TAT2IQUR.js";import"./chunk.3XGA65Y3.js";import"./chunk.BYKD5RLA.js";import"./chunk.2K4TT2BV.js";import"./chunk.VUBNBTJP.js";import"./chunk.OLFJH4RK.js";import"./chunk.67U6M7OV.js";import"./chunk.ZP5RT2EK.js";import"./chunk.VZJWJ5XM.js";import"./chunk.6C2MHWSX.js";import"./chunk.XOZU4OFA.js";import"./chunk.GLWSVSQL.js";import"./chunk.YFVJUHAK.js";import"./chunk.VFOON3Z3.js";import"./chunk.WVUJXDXZ.js";import"./chunk.7VKSXGTX.js";import"./chunk.TY4GQJKC.js";import"./chunk.6ZQAR5ZA.js";import"./chunk.W3W54DSX.js";import"./chunk.PI44XMY2.js";import"./chunk.KGW75Z5L.js";import"./chunk.GZHZLJBF.js";import{r as C}from"./chunk.IOK4GVJC.js";import"./chunk.OJGHDWI6.js";import"./chunk.TLJOZSDD.js";import"./chunk.MSWWWLEA.js";import"./chunk.UITT6JWW.js";import"./chunk.A5PDXNY6.js";import"./chunk.WC3DENU4.js";import"./chunk.VNDKKTED.js";import{G as S,I as $,T as p,ba as x,da as A}from"./chunk.4MP72LPR.js";import"./chunk.SDO3U72B.js";import{ad as k,fa as h}from"./chunk.VSCIXAHN.js";import"./chunk.FQLNBIQ5.js";import{b as i}from"./chunk.AJZBJBMO.js";var r=i(S(),1);var l=i(S(),1);var g=i(p(),1);var m={font:"inherit",fontSize:"0.875rem",minHeight:24,padding:0,border:0,borderRadius:2,background:"transparent",boxShadow:"none",color:"var(--graview-accent)",textDecoration:"underline",textUnderlineOffset:3,textAlign:"start",cursor:"pointer"};var e=i(p(),1);function Q({page:n=!1,go:E,onPick:y,onDiscard:D}){let{store:d,seatTalk:c}=x(),u=$(c),M=N(),b=E??M,{keep:P}=L(b),[H,f]=(0,r.useState)(!1);A();let t=u.draft;(0,r.useEffect)(()=>f(!1),[t]),(0,r.useEffect)(()=>{n||R(!1)},[n]);let v=(0,r.useRef)(null),w=t!==null&&!n;if((0,r.useLayoutEffect)(()=>{let s=v.current;if(!w||!s?.parentElement)return;let o=[];for(let a=s.previousElementSibling;a;a=a.previousElementSibling)a instanceof HTMLElement&&!a.inert&&a.tagName!=="STYLE"&&(a.inert=!0,o.push(a));return()=>{for(let a of o)a.inert=!1}},[w]),!t)return null;let G=T(t.drawn),F=d.schema.tryDefinition(t.kind),q=d.graph.nodesOfKind(t.kind).filter(s=>h(F,s)),z=()=>{c.setDraft(null),D?.()};return(0,e.jsxs)("section",{ref:v,"data-testid":"draft-frame","data-graview-draft-frame":n?"page":"scene","aria-label":`Draft: ${t.title}`,style:n?{display:"grid",gap:12,minWidth:0}:{position:"absolute",inset:12,zIndex:k("rail"),display:"grid",gridTemplateRows:"auto auto minmax(0, 1fr)",background:"var(--graview-panel)",border:"1px solid var(--graview-edge)",borderRadius:12,boxShadow:"var(--graview-lift-high)",overflow:"hidden",minHeight:0},children:[(0,e.jsxs)("p",{"data-testid":"draft-line",style:{...K,...n?{}:{padding:"10px 16px"}},children:[n?(0,e.jsx)("span",{children:"Draft"}):(0,e.jsxs)("span",{children:["Draft \u2014 ",(0,e.jsx)("span",{"data-testid":"draft-title",style:{color:"var(--graview-ink)",fontWeight:600},children:t.title})]}),(0,e.jsx)("span",{"aria-hidden":"true",children:"\xB7"}),(0,e.jsx)("button",{type:"button","data-testid":"draft-keep",disabled:H,title:`Keep \u201C${t.title}\u201D as a lens: a place of its own`,onClick:()=>{f(!0),P(t).finally(()=>f(!1))},style:m,children:"Keep as a lens"}),(0,e.jsx)("span",{"aria-hidden":"true",children:"\xB7"}),(0,e.jsx)("button",{type:"button","data-testid":"draft-discard",onClick:z,style:m,children:"Discard"})]}),u.draftNote?(0,e.jsx)("p",{"data-testid":"draft-note",role:"status",style:{margin:0,padding:n?0:"0 16px 8px",fontSize:"0.8125rem",color:"var(--graview-warn)"},children:u.draftNote}):(0,e.jsx)("span",{}),(0,e.jsx)("div",{"data-testid":"draft-lens","data-graview-draft":t.lens.name,role:"group","aria-label":t.title,tabIndex:0,style:n?{height:"min(72vh, 760px)",display:"grid",gridTemplateRows:"minmax(0, 1fr)",overflow:"auto",scrollbarGutter:"stable",border:"1px solid var(--graview-edge)",borderRadius:12,background:"var(--graview-panel)"}:{minHeight:0,overflow:"auto",scrollbarGutter:"stable",display:"grid",gridTemplateRows:"minmax(0, 1fr)"},onClick:s=>{let o=s.target?.closest("[data-graview-pick]")?.getAttribute("data-graview-pick");if(!o||!d.graph.getNode(o))return;s.preventDefault();let a=d.graph.getNode(o);y?(c.setDraft(null),y(o)):b({to:"record",id:o,kind:a.kind,label:o,address:"",said:""})},children:(0,e.jsx)(C,{kind:t.kind,view:t.title,children:(0,e.jsx)(G,{nodes:q,label:t.title,fidelity:"full",cardinality:"many",mode:"fullscreen",selected:!1})})})]})}var K={margin:0,display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"4px 8px",fontSize:"0.875rem",color:"var(--graview-ink-muted)",borderBottom:"1px solid var(--graview-edge)",paddingBottom:8};export{Q as DraftFrame};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as m}from"./chunk.
|
|
1
|
+
import{c as m}from"./chunk.PI44XMY2.js";import{da as c,ga as u,ha as p,ja as f,na as h,oa as l}from"./chunk.VSCIXAHN.js";function M(t,e){let n=t.schema.kinds,r="kind"in e?e.kind:void 0;if(r!==void 0&&!n.includes(r))return`There is no kind "${r}" in this app. Its kinds are: ${n.join(", ")}.`;if(e.on==="act"&&e.act!==void 0&&t.allMutations&&!t.allMutations().some(i=>i.name===e.act))return`There is no act "${e.act}" in this app.`;let o="record"in e?e.record:void 0;if(o!==void 0&&t.graph&&!t.graph.getNode(o))return`No record "${o}" is here to be told about.`;if(o!==void 0&&r!==void 0&&t.graph&&t.graph.getNode(o)?.kind!==r)return`\u201C${o}\u201D is not ${h(r)}.`;if(e.on==="changed"&&e.kind===void 0&&e.record===void 0)return"Say which kind, or which record, to be told about.";if(e.on==="reaches"){if(e.condition.trim()==="")return"Say what it should reach: a condition like done == true.";try{m(e.condition)}catch(i){return`The condition does not read: ${i instanceof Error?i.message:String(i)}.`}}}function d(t,e){let n=t.graph?.getNode(e);return n?u(t.schema.tryDefinition(n.kind),n):e}function g(t,e){let n=t.allMutations?.().find(r=>r.name===e);return n?p(n):c(e)}function v(t,e){let{when:n}=e,r=e.alsoMine?"anyone":"someone else",o=s=>l(t.schema.tryDefinition(s),s),i=s=>{let a=o(s);return`${/^[aeiou]/i.test(a)?"an":"a"} ${a}`};switch(n.on){case"act":{let s=n.act!==void 0?`\u201C${g(t,n.act)}\u201D`:"an act";return`When ${r} runs ${s}${n.record!==void 0?` on \u201C${d(t,n.record)}\u201D`:""}`}case"created":return`When ${r} adds ${i(n.kind)}`;case"changed":return n.record!==void 0?`When ${r} changes \u201C${d(t,n.record)}\u201D`:`When ${r} changes any of the ${f(t.schema,n.kind)}`;case"reaches":return`When ${n.record!==void 0?`\u201C${d(t,n.record)}\u201D`:i(n.kind)} reaches ${n.condition}${e.alsoMine?"":" (by someone else)"}`}}export{M as a,v as b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as ot}from"./chunk.644FUGSX.js";import"./chunk.E22DDEQI.js";import{e as V,l as ue,n as G,r as st}from"./chunk.OLW44AP5.js";import{a as ee}from"./chunk.G4JJXA63.js";import"./chunk.LDYOQCY7.js";import{b as nt}from"./chunk.VFRURRNI.js";import{d as tt}from"./chunk.2NJDT47T.js";import"./chunk.XOZU4OFA.js";import"./chunk.MHILFBK6.js";import"./chunk.ZFH4SCCF.js";import"./chunk.NSGQXCH6.js";import{d as et}from"./chunk.SZG6HJWH.js";import{c as Ze}from"./chunk.2FOIJ5ID.js";import{Bd as Ne,Cd as Xe,K as ze,X as Je,ga as Ye,ja as qe,na as Ae,oa as F,ob as Ve,pb as Qe}from"./chunk.X3MMJ3QC.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.644FUGSX.js";import"./chunk.3MOJF7BA.js";import{e as V,l as ue,n as G,r as st}from"./chunk.LZIBQ3VX.js";import{a as ee}from"./chunk.G4JJXA63.js";import"./chunk.OLFJH4RK.js";import{b as nt}from"./chunk.67U6M7OV.js";import{d as tt}from"./chunk.6C2MHWSX.js";import"./chunk.XOZU4OFA.js";import"./chunk.GLWSVSQL.js";import"./chunk.VFOON3Z3.js";import"./chunk.MSWWWLEA.js";import{d as et}from"./chunk.UITT6JWW.js";import{c as Ze}from"./chunk.A5PDXNY6.js";import{Dd as Ne,Ed as Xe,K as ze,X as Je,ga as Ye,ja as qe,na as Ae,oa as F,ob as Ve,pb as Qe}from"./chunk.VSCIXAHN.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
|
-
import{a,b,c,d,e,f,g}from"./chunk.
|
|
1
|
+
import{a,b,c,d,e,f,g}from"./chunk.YFVJUHAK.js";import"./chunk.FQLNBIQ5.js";import"./chunk.AJZBJBMO.js";export{e as askArchived,b as askDeclaration,a as declarationAt,f as keptOf,g as pastAt,d as pastOf,c as seqAt};
|