graview 0.1.24 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/preview/{chunk.47GRZWQN.js → chunk.2AJMM7JG.js} +1 -1
- package/dist/preview/{chunk.2VX6H2LL.js → chunk.2WFEFZAW.js} +1 -1
- package/dist/preview/chunk.2YVXTTC2.js +1 -0
- package/dist/preview/{chunk.AKOC43TV.js → chunk.6DU4XN2F.js} +1 -1
- package/dist/preview/{chunk.RT3XFR6E.js → chunk.6OBXKKB5.js} +2 -2
- package/dist/preview/{chunk.7EN53F4Q.js → chunk.6UL2JUEH.js} +1 -1
- package/dist/preview/chunk.6WFN4C46.js +107 -0
- package/dist/preview/{chunk.Y4R77MKX.js → chunk.7BAUPTMY.js} +1 -1
- package/dist/preview/chunk.A4SJ7EEY.js +1 -0
- package/dist/preview/{chunk.BNSY25SG.js → chunk.ACKTGTOT.js} +1 -1
- package/dist/preview/{chunk.7U7Q3HIS.js → chunk.B57EIGTS.js} +1 -1
- package/dist/preview/{chunk.ISAMJ7AK.js → chunk.BJ2Y5F66.js} +1 -1
- package/dist/preview/{chunk.3O2QU7LU.js → chunk.BYUQOV3O.js} +1 -1
- package/dist/preview/chunk.C5N4RTPF.js +1 -0
- package/dist/preview/{chunk.XDPRWUCJ.js → chunk.CFL2B2Z5.js} +1 -1
- package/dist/preview/{chunk.UM5IPM22.js → chunk.DEZEXD24.js} +1 -1
- package/dist/preview/{chunk.6MCK7K3M.js → chunk.DJ72CUS7.js} +1 -1
- package/dist/preview/{chunk.WOTNMTIY.js → chunk.DSZ3I557.js} +1 -1
- package/dist/preview/chunk.EA4BZKPG.js +1 -0
- package/dist/preview/{chunk.GDIRDJF3.js → chunk.EKZWX6NG.js} +1 -1
- package/dist/preview/{chunk.RGXNZ7PN.js → chunk.F26676IW.js} +1 -1
- package/dist/preview/{chunk.NRWJ6PLU.js → chunk.F2KDFGHR.js} +1 -1
- package/dist/preview/chunk.FWV4XAZA.js +1 -0
- package/dist/preview/chunk.G3BOZHKR.js +1 -0
- package/dist/preview/{chunk.HH6WIUK3.js → chunk.H4LHHT56.js} +6 -6
- package/dist/preview/{chunk.FKQTQ3FV.js → chunk.HQX5FGYT.js} +1 -1
- package/dist/preview/{chunk.TWFYXD3P.js → chunk.I5ELK6JF.js} +1 -1
- package/dist/preview/{chunk.WEGBBWWK.js → chunk.I6T3FDQS.js} +1 -1
- package/dist/preview/{chunk.DQL3WKR3.js → chunk.IB6PGEU7.js} +1 -1
- package/dist/preview/{chunk.LW7KV5SL.js → chunk.JCZH55RX.js} +1 -1
- package/dist/preview/{chunk.XUXCDUKC.js → chunk.JEMQBV6K.js} +1 -1
- package/dist/preview/{chunk.AXACXB4D.js → chunk.JIXW4WIO.js} +1 -1
- package/dist/preview/chunk.JW3E4SAC.js +1 -0
- package/dist/preview/{chunk.HDEQXJWX.js → chunk.KUTTVYOB.js} +1 -1
- package/dist/preview/{chunk.53RZI5PM.js → chunk.LHFEOEYY.js} +1 -1
- package/dist/preview/{chunk.D3CYTXNZ.js → chunk.MJ67MK4R.js} +1 -1
- package/dist/preview/{chunk.BLAODPYJ.js → chunk.ORJ3T4IW.js} +1 -1
- package/dist/preview/{chunk.TDW6QEG4.js → chunk.PY42PBMB.js} +1 -1
- package/dist/preview/{chunk.VTBAKTFP.js → chunk.QOYC424P.js} +2 -2
- package/dist/preview/{chunk.OXODTBOP.js → chunk.R6F3YMRK.js} +1 -1
- package/dist/preview/chunk.RAE4M3KQ.js +8 -0
- package/dist/preview/chunk.RUFAVEXB.js +1 -0
- package/dist/preview/chunk.RVEMN5WU.js +1 -0
- package/dist/preview/{chunk.XDVKD6VX.js → chunk.S24R4MRK.js} +3 -3
- package/dist/preview/{chunk.S4FO7Y2Q.js → chunk.S56LSUHV.js} +1 -1
- package/dist/preview/{chunk.HAQ4KHRY.js → chunk.SSOTDXRS.js} +1 -1
- package/dist/preview/{chunk.TWGB347L.js → chunk.T6KID3WO.js} +1 -1
- package/dist/preview/chunk.TAOT74FR.js +1 -0
- package/dist/preview/chunk.TTODVIXW.js +1 -0
- package/dist/preview/{chunk.XJNXSQT4.js → chunk.U6BWYBPM.js} +1 -1
- package/dist/preview/{chunk.KKTHQJ6F.js → chunk.UOYH2DFX.js} +1 -1
- package/dist/preview/{chunk.MYCTNK6D.js → chunk.US4KIJSW.js} +1 -1
- package/dist/preview/{chunk.42U4UBDE.js → chunk.WX5CJ7PI.js} +1 -1
- package/dist/preview/chunk.WXO3XUNW.js +1 -0
- package/dist/preview/{chunk.6XBLDV4A.js → chunk.YZZGD5OY.js} +1 -1
- package/dist/preview/{chunk.C7KLA2MW.js → chunk.ZJVIH6IF.js} +1 -1
- package/dist/preview/{chunk.PRXKRG6O.js → chunk.ZRVDIVYY.js} +1 -1
- package/dist/preview/chunk.ZV7ZFH2S.js +1 -0
- package/dist/preview/page.js +2 -2
- package/package.json +6 -6
- package/dist/preview/chunk.2STFOAXA.js +0 -1
- package/dist/preview/chunk.33C6VZAD.js +0 -1
- package/dist/preview/chunk.3TNQPFIK.js +0 -1
- package/dist/preview/chunk.54NSG7BX.js +0 -1
- package/dist/preview/chunk.6O67NOZR.js +0 -1
- package/dist/preview/chunk.7Q7S7YCA.js +0 -1
- package/dist/preview/chunk.EUCXNNCZ.js +0 -107
- package/dist/preview/chunk.FRNIWOKD.js +0 -1
- package/dist/preview/chunk.H3HRTEW7.js +0 -1
- package/dist/preview/chunk.KWSXL3A2.js +0 -1
- package/dist/preview/chunk.UEBBASQW.js +0 -1
- package/dist/preview/chunk.UIZWVBJ7.js +0 -1
- package/dist/preview/chunk.VLNI5U6H.js +0 -1
- package/dist/preview/chunk.XCOPECOJ.js +0 -1
- package/dist/preview/chunk.ZQ4HFIIS.js +0 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as R}from"./chunk.
|
|
1
|
+
import{d as R}from"./chunk.WX5CJ7PI.js";import{I as Q,J as V,M as z,P as Y,Sa as nn,T as A,U as D,V as X,Va as B,Xb as q,ea as L,fa as Z}from"./chunk.RAE4M3KQ.js";var E=c=>c.filter(Boolean).join(" "),en=new Set(["tell","me","about","what","how","show","describe","the","a","an","and","please"]),an=new Set([...en,"where","is","are","was","find","any","anything","something","things","called","named","which","who","of","for","with","to","in","on","i","my","do","does","have","has","can","you","it","that","this","there","we","our","got","be"]),dn=c=>c.length<=1?A(c[0]??"something"):`${c.slice(0,-1).map(A).join(", ")} and ${A(c[c.length-1])}`;function wn(c={}){return async(t,u,g={})=>{let w=u.toLowerCase(),h=n=>V(t.schema.tryDefinition(n.kind),n),p=(await import("./chunk.ACKTGTOT.js")).goingFrom(t,u,g,c.today);if(p.reply)return p.reply;let v=p.told,S=n=>p.moves?{...n,moves:p.moves}:n,y=[],C=w.split(/[^a-z0-9]+/).filter(Boolean),I=new Set;for(let n=0;n<C.length;n++){let e="";for(let s=n;s<Math.min(C.length,n+6);s++)e+=C[s],I.add(e)}let T=n=>n.toLowerCase().replace(/[^a-z0-9]+/g,""),H=[...t.graph.allNodes()].map(n=>({node:n,label:T(h(n))})).filter(({label:n})=>n.length>=2&&I.has(n)).sort((n,e)=>e.label.length-n.label.length),N=new Map;for(let{label:n}of H)N.set(n,(N.get(n)??0)+1);for(let{node:n,label:e}of H)(N.get(e)??0)>1||y.some(s=>s.id===n.id)||y.push(n);for(let n of g.selection??[]){let e=t.graph.getNode(n);e&&!y.some(s=>s.id===e.id)&&y.push(e)}let M=v&&t.graph.getNode(v);if(M){let n=y.findIndex(e=>e.id===M.id);n>=0&&y.splice(n,1),y.unshift(M)}let b=t.violations(),O=(n=b)=>ln(n);if(p.problems||!v&&/\b(wrong|broken|problem|violat|standing)\b/.test(w)){if(b.length===0)return S({say:"Nothing is wrong: every rule holds.",proposals:[],grounded:!0});let n=R(t,O().slice(0,4)),e=(i,r)=>{let d=t.allMutations().find(l=>l.name===i),a=d?q(d.input).find(l=>l.name===r):void 0;return a?.control==="node"&&!a.kinds.includes("*")?a.kinds.map(l=>D(t.schema.tryDefinition(l),l)).join(" or "):B(t.schema,d,r).label},s=[...new Set(b.flatMap(i=>i.repairs).filter(i=>(i.missing??[]).length>0).map(i=>`\u201C${i.label}\u201D (${(i.missing??[]).map(r=>e(i.mutation,r)).join(", ")})`))];return S({say:E([p.moves?.[0]?.said??"",`${Z(b)}:`,b.slice(0,4).map(i=>i.message).join("; ")+(b.length>4?"\u2026":"."),n.length>0?"The repairs below come from the rules themselves.":s.length>0?`Each way to fix ${b.length===1?"it":"these"} asks something first \u2014 ${s.slice(0,4).join(" or ")} \u2014 select the record and its own actions will ask.`:"No rule here names a way to fix it."]),proposals:n,grounded:!0})}let K=/\?\s*$/.test(u)||/^\s*(what|who|whom|whose|which|when|where|why|how|is|are|was|were|does|do|did|can|could|should|would|will|has|have)\b/.test(w),$=K?void 0:t.allMutations().find(n=>{let e=(n.title??n.name).toLowerCase();return e.length>3&&w.includes(e)});if($){let n={},e=[],s=u.slice(u.toLowerCase().indexOf(($.title??$.name).toLowerCase())+($.title??$.name).length),i=y.reduce((a,l)=>{let f=h(l).toLowerCase(),m=a.toLowerCase().indexOf(f);return m<0?a:`${a.slice(0,m)} it${a.slice(m+f.length)}`},s),r=u.match(/"([^"]+)"/)?.[1]??i.match(/^(?:\s+(?:it|this|that|them))?\s+(?:to|as)\s+(.+?)\s*[.!]?$/i)?.[1],d=[...y];for(let a of q($.input)){let l=un(a,d,r,c.today??g.today,w);if(l!==void 0){n[a.name]=l;let f=d.findIndex(m=>m.id===l);f>=0&&d.splice(f,1)}else a.optional||e.push(B(t.schema,$,a.name).label.toLowerCase())}return e.length===0?{say:"I can do that. Review it below.",proposals:R(t,[{mutation:$.name,args:n,why:"you asked in words"}])}:{say:`\u201C${$.title??z($.name)}\u201D needs ${dn(e)} \u2014 say ${e.length===1?"it":"them"} (or select ${e.length===1?"it":"them"}) and ask again.`,proposals:[]}}let tn={mon:"mon",monday:"mon",tue:"tue",tues:"tue",tuesday:"tue",wed:"wed",wednesday:"wed",thu:"thu",thur:"thu",thurs:"thu",thursday:"thu",fri:"fri",friday:"fri",sat:"sat",saturday:"sat",sun:"sun",sunday:"sun"},x=C.map(n=>tn[n]).find(Boolean),_=(n,e,s)=>{let i=t.schema.tryDefinition(n)?.display?.format?.[e];return i?i(s):String(s)},F=n=>{let e=t.schema.tryDefinition(n.kind)?.fieldRoles;if(!e?.start)return null;let s=n[e.start],i=e.end?n[e.end]:void 0,r=e.day?n[e.day]:e.days?n[e.days]:void 0;return s===void 0&&i===void 0?null:[s!==void 0?_(n.kind,e.start,s):null,i!==void 0&&e.end?`\u2013${_(n.kind,e.end,i)}`:null,Array.isArray(r)?` on ${r.join(", ")}`:r!==void 0?` on ${String(r)}`:null].filter(Boolean).join("")||null},sn=n=>{let e=[];for(let s of t.graph.allEdges()){let i=s.from===n?s.to:s.to===n?s.from:null;if(!i)continue;let r=t.graph.getNode(i);r&&!e.some(d=>d.id===r.id)&&e.push(r)}return e},G=n=>{let e=y[0];if(!e)return[];let s=[];for(let r of sn(e.id)){let d=0,a=T(h(r));for(let l of C)l.length>2&&a.includes(l)&&(d+=1);if(x){let l=t.schema.tryDefinition(r.kind)?.fieldRoles,f=l?.day?r[l.day]:void 0,m=l?.days?r[l.days]:void 0;f===x?d+=4:Array.isArray(m)&&m.includes(x)&&(d+=1)}n&&!F(r)||d>0&&s.push({node:r,score:d})}let i=s.sort((r,d)=>d.score-r.score).map(r=>r.node);return n&&F(e)?i.unshift(e):n||i.push(e),i};if(y.length>0&&/\bwhen\b/.test(w)){let n=G(!0)[0]??null,e=n?F(n):null;if(n&&e)return S({say:`${h(n)} runs ${e}.`,proposals:R(t,O(L(b,[n.id])).slice(0,3)),grounded:!0})}if(y.length>0&&/\bwho(m|se)?\b/.test(w))for(let n of G(!1)){let e=[],s=new Set;for(let i of t.schema.definitions)for(let[r,d]of Object.entries(i.edges)){let a=/\bwho\b/i.test(d.description??""),l=/\bwho\b/i.test(d.inverse??"");if(!a&&!l||s.has(r))continue;s.add(r);let f=[...t.graph.in(n.id,r),...t.graph.out(n.id,r)];if(f.length===0)continue;let m=a?d.description:d.inverse;e.push(`${m}: ${f.map(o=>h(o)).join(", ")}`)}if(e.length>0)return S({say:`${h(n)} \u2014 ${e.join("; ")}.`,proposals:R(t,O(L(b,[n.id])).slice(0,3)),grounded:!0})}if(y.length>0){let n=y[0],e=new Set(h(n).toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)),s=C.every(o=>e.has(o)||en.has(o)),i=K||s,r=t.schema.tryDefinition(n.kind),d=o=>o===o.toUpperCase()?o:o.charAt(0).toLowerCase()+o.slice(1),a=X(n,r,{limit:3}).map(o=>{let k=n[o.key];return typeof k=="boolean"&&!/\s/.test(o.label)?k?d(o.label):`not ${d(o.label)}`:typeof k=="string"&&hn.test(k)?`${d(o.label)} ${yn(k)}`:o.alone.startsWith(o.label)?d(o.label)+o.alone.slice(o.label.length):`${d(o.label)} ${o.alone}`}).join(", "),l=L(b,[n.id]),f=new Map;for(let o of[...t.graph.allEdges()]){let k=o.from===n.id?"out":o.to===n.id?"in":null;if(!k)continue;let J=t.graph.getNode(k==="out"?o.to:o.from);if(!J)continue;let P=`${o.kind}|${k}`;if(!f.has(P)){let W;for(let rn of t.schema.definitions){let j=rn.edges[o.kind];if(j&&(W=k==="out"?j.description:j.inverse??j.description,W))break}f.set(P,{sentence:W??z(o.kind).toLowerCase(),names:[]})}let U=f.get(P);U.names.length<6&&U.names.push(h(J))}let m=[...f.values()].slice(0,4).map(o=>`${o.sentence.charAt(0).toUpperCase()}${o.sentence.slice(1)}: ${o.names.join(", ")}`).join(". ");return S({say:E([p.moves?.[0]?.said??"",`${h(n)} \u2014 ${A(D(t.schema.tryDefinition(n.kind),n.kind))}${a?` (${a})`:""}.`,m?`${m}.`:"Connected to nothing yet.",l.length>0?`Trouble: ${l.map(o=>o.message).join("; ")}.`:"Nothing about it is broken."]),proposals:R(t,O(l).slice(0,3)),...i||v?{grounded:!0}:{}})}{let n=w.split(/[^\p{L}\p{N}]+/u).filter(e=>e.length>0&&!an.has(e));if(n.length>0){let e=nn(t,n.join(" "),{...g.principal?{principal:g.principal}:{},...g.selection?{from:g.selection}:{},...c.today??g.today?{today:c.today??g.today}:{},limit:6}),s=e.hits.filter(i=>i.about==="node");if(s.length>0){let i=Q(s.flatMap(a=>{let l=t.graph.getNode(a.id);return l?[l]:[]}),a=>t.schema.tryDefinition(a)),r=s.map(a=>`${a.label}${i.has(a.id)?` \xB7 ${i.get(a.id)}`:""} (${D(t.schema.tryDefinition(a.kind),a.kind)}${a.why.field==="label"?"":`, ${a.why.reading.toLowerCase()}: ${a.why.fragment}`})`);return{say:`${e.total===1?"One thing is":`${gn(e.total)} things are`} called \u201C${e.words}\u201D \u2014 ${r.join("; ")}${e.total>s.length?`; and ${e.total-s.length} more`:""}.`,proposals:[],picks:s}}}}let on=t.schema.kinds.filter(n=>!t.modules.disabledKinds.has(n)).map(n=>{let e=Y(t.schema,n);return`${t.graph.nodesOfKind(n).length} ${e}`}).join(", ");return{say:E([`This graph holds ${on}.`,"Ask about anything by name, ask what's wrong, or say a change in its own words \u2014",`like "${t.allMutations()[0]?.title??"an action"}".`]),proposals:[],unsure:!0}}}function ln(c){return c.flatMap(t=>{let u=t.repairs.find(g=>!g.missing?.length);return u?[{mutation:u.mutation,args:{...u.args},why:t.message}]:[]})}var cn=["No","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten"],gn=c=>cn[c]??String(c);function un(c,t,u,g,w=""){switch(c.control){case"node":return t.find(p=>c.kinds.includes("*")||c.kinds.includes(p.kind))?.id;case"text":return u;case"date":{let h=g??new Date().toISOString().slice(0,10);return c.time?`${h}T09:00`:h}case"choice":{let h=new Set(w.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)),p=(c.options??[]).filter(v=>v.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean).every(S=>h.has(S)));return p.length===1?p[0]:void 0}default:return}}function bn(c){return async(t,u,g={})=>(await import("./chunk.6OBXKKB5.js")).answerWithModel(c,t,u,g)}var hn=/^\d{4}-\d{2}-\d{2}$/,fn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function yn(c){let[t,u,g]=c.split("-").map(Number);return`${g} ${fn[u-1]??""} ${t}`}export{wn as a,ln as b,bn as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as H,b as N,c as C,d as de,e as le}from"./chunk.YZZGD5OY.js";import{g as l}from"./chunk.DSZ3I557.js";import{C as ce,a as G,b as K,d as te,e as ie,f as O,h as p,k as j,l as oe,m as R,n as re,o as E,p as b,r as g,s as se,t as w,u as m,v as _,w as v,x as i,y as F,z as ae}from"./chunk.RAE4M3KQ.js";var Oe="graview-document",je=1,sn=256*1024,X=64*1024,ue=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,J=/^[a-z][A-Za-z0-9]*$/,Re=new Set(["id","kind"]),Ee=e=>e in Object.prototype,fe=F(e=>!Ee(e),"every object already has this name \u2014 choose another"),pe=(e,n)=>[...e===void 0?[]:[ie(e)],...n===void 0?[]:[te(n)]],f=(e,n)=>p().check(...pe(e,n)),h=(e,n,s)=>b(e).check(...pe(n,s)),z=e=>p().check(O(ue,`${e} names are lower-case words joined by hyphens, like "booked-vendor"`)),Ae=/^(?:[a-z][a-z0-9]*(?:-[a-z0-9]+)*|[a-z][A-Za-z0-9]*)$/,I=p().check(O(Ae,'relation names are one camelCase word, like "tendedBy"'),fe),x=p().check(O(J,'field names are one word or camelCase, like "dueDate" \u2014 rules say them bare'),F(e=>!Re.has(e),'a field cannot be called "id" or "kind" \u2014 the framework keeps those; try "type" or "category"'),fe),A=f(1,500),M=f(1,2e3),q=f(1,300),Fe=["string","text","number","integer","boolean","date","datetime","enum","list","url","email"],ge=g({type:_(Fe),required:i(R()),description:i(A),label:i(f(1,60)),options:i(h(f(1,80),1,100)),of:i(_(["string","number","date"])),default:i(E()),unit:i(f(void 0,12)),format:i(_(["money","percent","duration"])),min:i(j()),max:i(j()),step:i(j()),renamedFrom:i(p().check(O(J)))}).check(ae((e,n)=>{e.type==="enum"&&!e.options&&n.addIssue({code:"custom",message:'an enum field lists its "options"',path:["options"]}),e.type!=="enum"&&e.options&&n.addIssue({code:"custom",message:'"options" belongs only on an enum field',path:["options"]}),e.type!=="list"&&e.of&&n.addIssue({code:"custom",message:'"of" belongs only on a list field',path:["of"]})})),Ve=g({to:w([h(z("kind"),1),v("*")]),cardinality:i(_(["one","many"])),description:i(A),inverse:i(f(1,80)),appendOnly:i(R()),renamedFrom:i(p())}),ye=w([M,g({expr:M,label:i(f(1,60)),description:i(A)})]),Te=g({noun:i(f(1,40)),plural:i(f(1,40)),description:i(A),fields:m(x,ge).check(F(e=>Object.keys(e).length>0,"a kind has at least one field")),label:i(q),describe:i(q),lifecycle:i(g({field:x,retired:h(w([p(),j(),R()]),1)})),figure:i(f(void 0,2e4)),glance:i(h(x,1,20)),page:i(g({fields:i(h(x,1,40)),groups:i(h(g({title:f(1,60),fields:h(x,1,40)}),1,12))})),edges:i(m(I,Ve)),computed:i(m(p(),ye).check(F(e=>Object.keys(e).length<=20,"a kind works out at most 20 computed fields"))),fieldRoles:i(m(p(),p())),renamedFrom:i(p().check(O(ue)))}),B=w([p(),j(),R(),re(),b(E()),g({expr:M})]),D=p().check(O(/^\$[A-Za-z][A-Za-z0-9]*$/,'a reference is "$" and a name, like "$subject" or "$new"')),_e=w([g({create:z("kind"),as:i(p().check(O(J))),set:i(m(x,B))}),g({set:m(x,B),target:i(D)}),g({connect:I,from:D,to:D}),g({sever:I,from:D,to:D}),g({remove:D})]),De=g({title:i(f(1,80)),description:i(A),fromTheOtherEnd:i(f(1,80)),on:i(w([z("kind"),h(z("kind"),1)])),creates:i(z("kind")),sets:i(m(x,B)),writes:i(h(x,1)),connects:i(I),severs:i(I),setsOther:i(m(x,B)),replaces:i(w([v(!0),h(I,1,10)])),removes:i(v(!0)),args:i(m(x,ge)),effects:i(h(_e,1,20)),allowedWhen:i(M),refusal:i(q),destructive:i(R())}),Ie=g({act:z("act"),label:i(f(1,80)),args:i(m(p(),B))}),Me=g({title:i(f(1,120)),description:i(A),over:w([v("graph"),z("kind")]),when:i(M),require:M,says:i(q),repairs:i(h(Ie,void 0,10))}),Le=g({roles:w([h(z("role"),1),v("*")]),mutations:w([h(z("act"),1),v("*")]),kinds:i(w([b(z("kind")),v("*")])),describe:i(A),self:i(R())}),Ke=g({roles:w([h(z("role"),1),v("*")]),kinds:h(z("kind"),1),own:i(R())}),Be=g({grants:b(Le),sees:i(b(Ke))}),Ge=g({accent:i(p().check(O(/^#[0-9a-fA-F]{6}$/,'an accent is a color like "#c2577a"'))),name:i(f(1,60)),currency:i(p().check(O(/^[A-Z]{3}$/,'a currency is its three-letter code, like "USD" or "EUR"'))),locale:i(f(2,35)),logo:i(w([f(1,X),g({src:f(1,X),alt:i(f(1,120))})])),favicon:i(f(1,X)),typography:i(g({display:i(f(1,200)),body:i(f(1,200)),mono:i(f(1,200))})),shape:i(g({radius:i(j().check(K(0),G(32))),density:i(j().check(K(.75),G(1.5)))})),accents:i(m(p(),j().check(K(0),G(360)))),scheme:i(_(["light","dark","auto"]))}),P=m(p(),E()),Ne=g({card:i(b(E())),row:i(b(E())),page:i(b(E()))}),Ce=se({order:i(b(p())),hide:i(b(p())),first:i(p()),primary:i(h(f(1,80),void 0,40)),scene:i(f(1,40)),pages:i(f(1,40))}),an=g({$schema:i(p()),format:v(Oe),formatVersion:v(je),name:f(1,80),description:i(A),version:i(j().check(oe(),K(1))),kinds:m(z("kind"),Te).check(F(e=>Object.keys(e).length>0,"a document declares at least one kind"),F(e=>Object.keys(e).length<=40,"a document declares at most 40 kinds")),computed:i(m(p(),ye)),acts:i(m(z("act"),De)),rules:i(m(z("rule"),Me)),roles:i(b(z("role"))),policy:i(Be),modules:i(P),lenses:i(b(P)),pages:i(Ce),views:i(m(p(),w([Ne,b(E())]))),brand:i(Ge),settings:i(b(P)),migrations:i(b(P))});var W=e=>e?._zod?.def,Pe=/^\^\\d\{4\}-\\d\{2\}-\\d\{2\}\$$/;function qe(e){let n=W(e),s=!0,r;for(let t=0;n&&t<4;t++){if(n.type==="optional"||n.type==="nullable")s=!1;else if(n.type==="default")s=!1,r=n.defaultValue;else break;n=W(n.innerType)}if(!n)return{why:"it is not a zod field"};let c=ce(e),d={...s?{required:!0}:{},...r!==void 0?{default:r}:{},...c?{description:c}:{}},a=(n.checks??[]).map(t=>W(t));switch(n.type){case"string":{let t=n.format;return t==="email"?{spec:{type:"email",...d}}:t==="url"?{spec:{type:"url",...d}}:t==="date"?{spec:{type:"date",...d}}:t==="datetime"?{spec:{type:"datetime",...d}}:a.some(o=>o?.format==="regex"&&Pe.test(String(o?.pattern?.source??"")))?{spec:{type:"date",...d}}:{spec:{type:"string",...d}}}case"number":{let t={};for(let o of a){let u=o?.value;typeof u=="number"&&(o?.check==="greater_than"&&o.inclusive?t.min=Math.max(t.min??u,u):o?.check==="less_than"&&o.inclusive?t.max=Math.min(t.max??u,u):o?.check==="multiple_of"&&(t.step=u))}return{spec:{type:a.some(o=>o?.format==="safeint"||o?.format==="int")?"integer":"number",...t,...d}}}case"boolean":return{spec:{type:"boolean",...d}};case"enum":{let t=Object.keys(n.entries??{});return t.length>0?{spec:{type:"enum",options:t,...d}}:{why:"it is an enum with no options"}}case"array":{let t=W(n.element),o=t?.type==="number"?"number":t?.type==="string"?"string":void 0;return o?{spec:{type:"list",of:o,...d}}:{why:`it is a list of ${String(t?.type??"something")}, and a document lists words, numbers or dates`}}default:return{why:`it is a ${String(n.type)}, which a document has no field type for`}}}function ln(e){let n=qe(e);return"spec"in n?n.spec:void 0}var Q=["card","row","page"],ee=["good","warn","bad","neutral","accent"],me=["money","percent","date","relative","count"],he=4,U=40,be=["number","money","percent"],We=["card","row"],ze=100,Z={title:[],headline:[],list:["sort","limit","group","empty","as"],text:["tone"],badge:["tone"],field:["as","currency","label"],progress:["label"],group:["direction"],when:["show"],divider:[],figure:["as","currency","label"]},Ze=Object.keys(Z),ke=`{"title": "{name}"}, {"headline": "{count(all('offer'))} offers"}, {"figure": expr, "as"?: "number"|"money"|"percent", "currency"?, "label"?}, {"list": expr, "sort"?, "limit"?, "group"?, "empty"?, "as"?: "card"|"row"}, {"text": "\u2026", "tone"?}, {"badge": "{status}", "tone"?}, {"field": "quote", "as"?, "currency"?, "label"?}, {"progress": {"value": expr, "max": expr}, "label"?}, {"group": [blocks], "direction"?: "row"|"column"}, {"when": expr, "show": [blocks]}, {"divider": true}, {"figure": true}`;function hn(e){return Object.fromEntries(Object.entries(e.views??{}).filter(([,n])=>!Array.isArray(n)))}function bn(e){let n=e.views?.home;return Array.isArray(n)?n:void 0}var Ue={field:()=>!1,relation:()=>!1,figure:!1},Ye=e=>e.kind??"the home",V=(e,n)=>e!==void 0&&Object.hasOwn(e,n),S=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function $e(e,n,s){let r=H(e);for(let c of r.unknownFunctions)s.findings.push(l("unknown-function",n,`"${c}" is not a function the rule language knows`,"see docs/declaration-document.md#expression-language"));for(let c of r.names){if(s.kind===null){s.findings.push(l("view-name",n,`"${c}" names nothing here: these blocks are about no one record`,"reach records with all('<kind>'), like count(all('offer')) or first(all('party') where role == 'client').name"));continue}c==="id"||s.spec.field(c)||s.spec.relation(c)||s.findings.push(l("view-name",n,`${s.kind} has no field or relation called "${c}"`))}for(let c of r.edges)s.edges.has(c)||s.findings.push(l("view-edge",n,`"${c}" is not a relation any kind declares`));for(let c of r.sweeps)s.kinds.has(c)||s.findings.push(l("view-kind",n,`"${c}" is not a kind this document declares`))}function L(e,n,s){if(typeof e!="string"||e.length===0||e.length>2e3){s.findings.push(l("view-expression",n,`an expression is a line of the rule language, like "status == 'booked'"`));return}try{$e(C(e),n,s)}catch(r){if(!(r instanceof N))throw r;s.findings.push(l("expression",n,`${r.sentence} (at character ${r.at+1})`))}}function ne(e,n,s){if(typeof e!="string"||e.length===0||e.length>300){s.findings.push(l("view-template",n,'a template is words with {field} in braces, like "{name}" or "{quote|money}", at most 300 characters'));return}let r;try{r=le(e)}catch(c){if(c instanceof de||c instanceof N){s.findings.push(l("template",n,c.sentence));return}throw c}for(let c of r)c.expr&&$e(c.expr,n,s)}function He(e,n,s){if(typeof e=="string"){ee.includes(e)||s.findings.push(l("view-tone",n,`"${e}" is not a tone`,`use one of ${ee.join(", ")}, or {"expr": "if(status == 'booked', 'good', 'neutral')"}`));return}if(S(e)&&Object.keys(e).length===1&&"expr"in e){L(e.expr,`${n}.expr`,s);return}s.findings.push(l("view-tone",n,'a tone is a word or {"expr": \u2026}',`one of ${ee.join(", ")}`))}function Y(e,n,s,r){if(!Array.isArray(e)){r.findings.push(l("view-shape",n,"a view is a list of blocks"));return}if(s>he){r.findings.push(l("view-depth",n,`blocks nest at most ${he} deep`,"flatten a group or a condition"));return}e.forEach((c,d)=>Xe(c,`${n}.${d}`,s,r))}function Xe(e,n,s,r){if(r.count++,!S(e)){r.findings.push(l("view-block",n,"a block is an object naming what it shows",`one of ${ke}`));return}let c=Object.keys(e),d=c.filter(o=>Ze.includes(o)&&!(o==="group"&&c.includes("list")));if(d.length===0){r.findings.push(l("view-block",n,`${c.length>0?c.map(o=>`"${o}"`).join(", "):"an empty object"} is not a block Graview knows`,`one of ${ke}`));return}if(d.length>1){r.findings.push(l("view-block",n,`a block is one thing, and this says ${d.map(o=>`"${o}"`).join(" and ")}`,"split it into two blocks"));return}let a=d[0];for(let o of c)o!==a&&o!="key"&&!Z[a].includes(o)&&r.findings.push(l("unknown-key",`${n}.${o}`,`"${o}" is not part of a ${a} block`,Z[a].length>0?`a ${a} block may also say ${Z[a].map(u=>`"${u}"`).join(", ")}`:`a ${a} block says nothing else`));let t=e[a];switch(a){case"title":case"headline":case"text":case"badge":ne(t,`${n}.${a}`,r),"tone"in e&&He(e.tone,`${n}.tone`,r);return;case"field":{if(typeof t!="string"||!r.spec.field(t)){let o=typeof t=="string"&&r.spec.relation(t);r.findings.push(l("view-field",`${n}.field`,`${r.kind} has no field ${typeof t=="string"?`"${t}"`:"by that name"}`,o?`"${t}" is a relation; show it with {"text": "{${t}.name}"}`:void 0))}"as"in e&&!me.includes(e.as)&&r.findings.push(l("view-format",`${n}.as`,`"${String(e.as)}" is not a way to show a field`,`use one of ${me.join(", ")}`)),Se(e,n,r,"field"),"label"in e&&nn(e.label,`${n}.label`,r);return}case"progress":{!S(t)||Object.keys(t).some(o=>o!=="value"&&o!=="max")||!("value"in t)||!("max"in t)?r.findings.push(l("view-progress",`${n}.progress`,'progress is {"value": expression, "max": expression}')):(L(t.value,`${n}.progress.value`,r),L(t.max,`${n}.progress.max`,r)),"label"in e&&ne(e.label,`${n}.label`,r);return}case"group":"direction"in e&&e.direction!=="row"&&e.direction!=="column"&&r.findings.push(l("view-direction",`${n}.direction`,`a group runs "row" or "column", not "${String(e.direction)}"`)),Y(t,`${n}.group`,s+1,r);return;case"when":L(t,`${n}.when`,r),"show"in e?Y(e.show,`${n}.show`,s+1,r):r.findings.push(l("view-when",n,'a condition says what it shows: {"when": expr, "show": [blocks]}'));return;case"figure":if(typeof t=="string")return Je(e,n,r);for(let o of["as","currency","label"])o in e&&r.findings.push(l("unknown-key",`${n}.${o}`,`"${o}" belongs to a figure that works a number out; {"figure": true} is the kind's picture`,`write {"figure": "count(all('offer'))", "as": "number"}`));t!==!0?r.findings.push(l("view-block",`${n}.figure`,`a figure is a number worked out, {"figure": "sum(all('offer'), net)", "as": "money"}, or the kind's picture, {"figure": true}`)):r.spec.figure||r.findings.push(l("view-figure",`${n}.figure`,`${Ye(r)} has no figure to show`,r.kind===null?`work a number out: {"figure": "count(all('offer'))"}`:'give the kind a "figure", or leave this block out'));return;case"list":return en(e,n,r);case"divider":t!==!0&&r.findings.push(l("view-block",`${n}.${a}`,`write {"${a}": true}`));return}}function Je(e,n,s){L(e.figure,`${n}.figure`,s),"as"in e&&!be.includes(e.as)&&s.findings.push(l("view-format",`${n}.as`,`"${String(e.as)}" is not a way to say a figure`,`use one of ${be.join(", ")}`)),Se(e,n,s,"figure"),"label"in e&&ne(e.label,`${n}.label`,s)}function Se(e,n,s,r){"currency"in e&&(typeof e.currency!="string"||!/^[A-Z]{3}$/.test(e.currency)?s.findings.push(l("view-currency",`${n}.currency`,'a currency is its three-letter code, like "USD" or "EUR"')):e.as!=="money"&&s.findings.push(l("view-currency",`${n}.currency`,`a currency belongs on a ${r} shown as money`,'add "as": "money"')))}function Qe(e,n){let s=[...n.kinds],r=(d,a)=>{let t=new Set;for(let o of d){let u=n.vocabulary.namesOf(o)?.targets?.(a);if(u==="*")return s;for(let y of u??[])t.add(y)}return t.size>0?[...t]:void 0},c=d=>{switch(d.t){case"ident":return n.kind!==null&&n.spec.relation(d.name)?r([n.kind],d.name):void 0;case"member":{let a=c(d.object);return a?r(a,d.name):void 0}case"where":return c(d.set);case"call":{let a=d.args[0],t=a?.t==="lit"&&typeof a.value=="string"?a.value:void 0;if(d.fn==="all")return t!==void 0&&n.kinds.has(t)?[t]:void 0;let o=d.args.length===2&&d.args[1]?.t==="lit"&&typeof d.args[1].value=="string"?d.args[1].value:void 0;if(d.fn==="out"&&o!==void 0){let u=c(a);return u?r(u,o):void 0}if(d.fn==="out")return t!==void 0&&n.kind!==null?r([n.kind],t):void 0;if(d.fn==="in"){let u=o??t,y=o!==void 0?c(a):n.kind!==null?[n.kind]:void 0,k=u!==void 0?n.vocabulary.sources(u).filter($=>{let T=n.vocabulary.namesOf($)?.targets?.(u);return!y||T==="*"||y.some(xe=>T?.includes(xe))}):[];return k.length>0?k:void 0}if((d.fn==="sort"||d.fn==="first")&&a)return c(a);if(d.fn==="either"){let u=d.args.map(c);return u.every(y=>y!==void 0)?[...new Set(u.flatMap(y=>y??[]))]:void 0}return}default:return}};return c(e)}function we(e,n,s,r){let c;try{c=C(e)}catch(a){if(!(a instanceof N))throw a;r.findings.push(l("expression",n,`${a.sentence} (at character ${a.at+1})`));return}let d=H(c);for(let a of d.unknownFunctions)r.findings.push(l("unknown-function",n,`"${a}" is not a function the rule language knows`,"see docs/declaration-document.md#expression-language"));for(let a of d.edges)r.edges.has(a)||r.findings.push(l("view-edge",n,`"${a}" is not a relation any kind declares`));if(s)for(let a of d.names)a==="id"||s.some(t=>r.vocabulary.namesOf(t)?.field(a)||r.vocabulary.namesOf(t)?.relation(a))||r.findings.push(l("view-name",n,`${s.join(" and ")} ${s.length===1?"has":"have"} no field or relation called "${a}"`))}function en(e,n,s){let r=e.list;L(r,`${n}.list`,s);let c;if(typeof r=="string")try{c=Qe(C(r),s)}catch{c=void 0}let d=t=>{if(!c)return[...s.kinds].map(u=>s.vocabulary.namesOf(u)?.choices?.(t)).find(u=>u!==void 0);let o=c.map(u=>s.vocabulary.namesOf(u)?.choices?.(t));return o.every(u=>u!==void 0)?[...new Set(o.flatMap(u=>u??[]))]:void 0},a=c?c.join(" and "):"any kind";if("sort"in e){let t=e.sort;if(typeof t=="string")we(t,`${n}.sort`,c,s);else if(S(t)&&typeof t.by=="string"&&Object.keys(t).every(o=>o==="by"||o==="direction")){let o=t.direction;o!==void 0&&o!=="asc"&&o!=="desc"&&o!=="choices"?s.findings.push(l("list-sort",`${n}.sort.direction`,`a list is sorted "asc", "desc" or "choices", not "${String(o)}"`,'"choices" puts a choice field in the order its choices are declared')):o==="choices"?d(t.by)===void 0&&s.findings.push(l("list-sort",`${n}.sort.by`,`"${t.by}" is not a choice field of ${a}, so it has no declared order`,'sort by a choice field, or say "asc" or "desc"')):we(t.by,`${n}.sort.by`,c,s)}else s.findings.push(l("list-sort",`${n}.sort`,'a sort is a key, like "net", or {"by": key, "direction": "asc" | "desc" | "choices"}'))}if("limit"in e){let t=e.limit;(typeof t!="number"||!Number.isInteger(t)||t<1||t>ze)&&s.findings.push(l("list-limit",`${n}.limit`,`a limit is a whole number from 1 to ${ze}`))}if("group"in e){let t=e.group,o=typeof t=="string"?t:S(t)&&typeof t.by=="string"?t.by:void 0;if(!(typeof t=="string"||S(t)&&Object.keys(t).every(y=>y==="by"||y==="headings"))||o===void 0)s.findings.push(l("list-group",`${n}.group`,'a group is a choice field, like "type", or {"by": "type", "headings": {"pain": "What hurts"}}'));else{let y=d(o);if(y===void 0&&s.findings.push(l("list-group",`${n}.group`,`"${o}" is not a choice field of ${a}, so it has no choices to group by`,"group by a field whose type is enum")),S(t)&&"headings"in t){let k=t.headings;if(!S(k)||Object.values(k).some($=>typeof $!="string"||$.length===0||$.length>80))s.findings.push(l("list-group",`${n}.group.headings`,'headings are words per choice, like {"pain": "What hurts"}, at most 80 characters each'));else if(y)for(let $ of Object.keys(k))y.includes($)||s.findings.push(l("list-group",`${n}.group.headings.${$}`,`"${$}" is not one of ${o}'s choices`,`use ${y.join(", ")}`))}}}"empty"in e&&(typeof e.empty!="string"||e.empty.length===0||e.empty.length>200)&&s.findings.push(l("list-empty",`${n}.empty`,"what an empty list says is a sentence, at most 200 characters")),"as"in e&&!We.includes(e.as)&&s.findings.push(l("list-as",`${n}.as`,`a list draws each record as its "card" or its "row", not "${String(e.as)}"`))}function nn(e,n,s){(typeof e!="string"||e.length===0||e.length>60)&&s.findings.push(l("view-label",n,"a label is a few words, at most 60 characters"))}function ve(e,n,s,r,c,d,a){let t={kind:null,spec:Ue,kinds:r,edges:c,vocabulary:s,findings:d,count:0};Array.isArray(e)&&e.length===0&&d.push(l("view-shape",n,`${a} has no blocks`,'give it one: {"headline": "\u2026"}')),Y(e,n,1,t),t.count>U&&d.push(l("view-size",n,`${a} has ${t.count} blocks; a view has at most ${U}`,"show less"))}function tn(e,n,s,r,c){Array.isArray(e)&&e.forEach((d,a)=>{if(!S(d)||d.name!=="blocks"||!S(d.options)||!("blocks"in d.options))return;let t=[];ve(d.options.blocks,`lenses.${a}.options.blocks`,n,s,r,t,`the lens "${String(d.title??a)}"`);for(let o of t)c.push({...o,severity:"warning"})})}function on(e,n,s,r,c,d,a){let t=[];if(e===void 0)return t;if(!S(e))return t.push(l("view-shape",n,'views are an object of kinds, each with a "card", a "row" or a "page"')),t;for(let[o,u]of Object.entries(e)){if(o==="home"&&Array.isArray(u)){ve(u,`${n}.home`,a,r,c,t,"the home");continue}let y=s(o);if(!y){t.push(l("view-kind",`${n}.${o}`,`"${o}" is not a kind this ${d} declares`));continue}if(!S(u)){t.push(l("view-shape",`${n}.${o}`,`a kind's views are {"card": [blocks], "row": [blocks], "page": [blocks]}`));continue}for(let k of Object.keys(u))Q.includes(k)||t.push(l("view-slot",`${n}.${o}.${k}`,`"${k}" is not a place a view is drawn`,`use ${Q.map($=>`"${$}"`).join(", ")}`));for(let k of Q){let $=u[k];if($===void 0)continue;let T={kind:o,spec:y,kinds:r,edges:c,vocabulary:a,findings:t,count:0};Y($,`${n}.${o}.${k}`,1,T),T.count>U&&t.push(l("view-size",`${n}.${o}.${k}`,`this ${k} has ${T.count} blocks; a view has at most ${U}`,"show less, or move detail to the page"))}}return t}function zn(e){let n=new Set(Object.keys(e.kinds)),s=new Set(Object.values(e.kinds).flatMap(a=>Object.keys(a.edges??{}))),r=a=>{let t=V(e.kinds,a)?e.kinds[a]:void 0;return t?{field:o=>V(t.fields,o)||V(t.computed,o),relation:o=>V(t.edges,o),figure:t.figure!==void 0,choices:o=>V(t.fields,o)&&t.fields[o].type==="enum"?t.fields[o].options:void 0,targets:o=>V(t.edges,o)?t.edges[o].to:void 0}:void 0},c={namesOf:r,sources:a=>Object.keys(e.kinds).filter(t=>V(e.kinds[t].edges,a))},d=on(e.views,"views",r,n,s,"document",c);return tn(e.lenses,c,n,s,d),d}export{Oe as a,je as b,sn as c,an as d,ln as e,ee as f,me as g,be as h,ze as i,hn as j,bn as k,zn as l};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as ee}from"./chunk.G4JJXA63.js";import{b as nt}from"./chunk.Y4R77MKX.js";import{d as tt}from"./chunk.42U4UBDE.js";import"./chunk.LW7KV5SL.js";import{Ea as V,I as Ye,Ka as fe,O as ze,Oa as Se,Pa as Xe,Q as Je,S as Ae,T as F,Ta as G,U as qe,Ub as et,Xa as Ze,oa as Ve,pa as Qe}from"./chunk.ZQ4HFIIS.js";import"./chunk.AJZBJBMO.js";var vt="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(),At=/^(?:(?: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)) (.+)$/,Nt=/^(?: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))$/,st=new Set(["here","this","this place","this page","on this page","on the page","on this screen","in view"]),Ot=/^(?:date|day|when|on|at|the date|the day)$/,Ct=/^(?: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) (.+))?$/,Y=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"]),ct=864e5,se=o=>Date.UTC(Number(o.slice(0,4)),Number(o.slice(5,7))-1,Number(o.slice(8,10))),Me=o=>new Date(o).toISOString().slice(0,10),C=(o,i)=>Me(se(o)+i*ct),jt=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],Mt=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ut=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Dt="(monday|tuesday|tues|wednesday|thursday|thurs|friday|saturday|sunday)",ot="(january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sept|sep|oct|nov|dec)",rt="(\\d{1,2})(?:st|nd|rd|th)?",Wt=o=>jt.findIndex(i=>i.startsWith(o.slice(0,3))),it=o=>ut.findIndex(i=>o.startsWith(i.toLowerCase()));function xt(o,i){let p=new Date(se(o)),u=o.slice(0,4)===i.slice(0,4)?"":` ${o.slice(0,4)}`;return`${Mt[p.getUTCDay()]} ${p.getUTCDate()} ${ut[p.getUTCMonth()]}${u}`}function Ne(o,i,p){if(o<0||i<1||i>31)return;let u=Number(p.slice(0,4)),c=k=>{let j=Date.UTC(k,o,i);return new Date(j).getUTCMonth()===o?Me(j):void 0},y=c(u);if(y)return se(y)<se(p)-183*ct?c(u+1):y}function Oe(o,i,p){let u=new Date(se(i)).getUTCDay(),c=f=>{let N=(u-p+7)%7,w=C(i,-N+f*7);return{from:w,to:C(w,6)}},y=()=>{let f=`${i.slice(0,8)}01`,N=new Date(Date.UTC(Number(i.slice(0,4)),Number(i.slice(5,7)),1));return{from:f,to:C(Me(N.getTime()),-1)}},k=f=>f?{from:f,to:f,day:xt(f,i)}:void 0,j=(f,N)=>{let w=Wt(N);return k(f==="this"||f==="next"?C(c(f==="next"?1:0).from,(w-p+7)%7):f==="last"?C(i,-((u-w+6)%7+1)):C(i,(w-u+7)%7))},z=f=>{let N=C(i,u===0?-1:6-u);return{from:C(N,f*7),to:C(N,f*7+1)}},U="\\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/,()=>z(1)],[/\b(?:due |for |on )?(?:this |the )?weekend\b/,()=>z(0)],[/\b(?:due |for |on )?this month\b/,()=>y()],[new RegExp(`${U}(\\d{4}) (\\d{2}) (\\d{2})\\b`),f=>k(Ne(Number(f[2])-1,Number(f[3]),`${f[1]}-01-01`))],[new RegExp(`${U}${rt} (?:of )?${ot}\\b`),f=>k(Ne(it(f[2]),Number(f[1]),i))],[new RegExp(`${U}${ot} (?:the )?${rt}\\b`),f=>k(Ne(it(f[1]),Number(f[2]),i))],[new RegExp(`${U}(?:(this|next|last|coming) )?${Dt}\\b`),f=>j(f[1],f[2])]];for(let[f,N]of P){let w=o.match(f);if(!w)continue;let S=N(w);if(S)return{ask:{words:w[0],...S},rest:o.replace(w[0]," ").replace(/\s+/g," ").trim()}}}function ft(o,i,p={}){let u=p.principal??{kind:"human"},c=o.seenBy(u),y=c.schema,k=p.today??o.today?.()??new Date().toISOString().slice(0,10),j=p.weekStartsOn??1,z=o.kindsKeptFrom(u),U=o.modules.disabledKinds,P=y.kinds.filter(e=>!z.has(e)&&!U.has(e)),f=new Set(P),N=(p.places??[]).filter(e=>e.kind===null||f.has(e.kind)),w=c.graph,S=$(i).replace(/[?.!]+$/,"").trim();if(S.length===0)return{unresolved:!0};let D=e=>y.tryDefinition(e),T=e=>Ye(D(e.kind),e),H=e=>ze(y,e),oe=e=>N.find(t=>t.kind===e&&t.address===Se(y,e))?.address??Se(y,e),ge=e=>Xe(y,e.kind,e.id),De=e=>({to:"record",id:e.id,kind:e.kind,label:T(e),address:ge(e),said:`Went to ${T(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}},xe=()=>({unresolved:!0,say:vt}),re=e=>{let t=D(e.kind),s=qe(e,t,{limit:3}).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[`${T(e)} \u2014 ${Ae(F(t,e.kind))}${s?` (${s})`:""}.`,n.length>0?`Trouble: ${n.map(r=>r.message).join("; ")}.`:""].filter(Boolean).join(" ")},ie=e=>{let t=new Set([G(e),G(Y(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(Y(e.slice(0,-n.length)))));t.delete("");let s=n=>t.has(G(n.title))||t.has(G(Y($(n.title))))||t.has(G(n.slug));return N.find(n=>n.kind!==null&&n.address.startsWith("/places/")&&s(n))??N.find(s)},pe=e=>{let t=Ze(o,e,{principal:u,today:k,limit:6,...p.selection?{from:p.selection}:{}}),s=t.hits.filter(r=>r.about==="node"&&f.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}},Ee=e=>{let t=e.map(s=>`${s.label} (${F(D(s.kind),s.kind)})`);return`${e.length===1?"One thing matches":`${e.length} things match`}: ${t.join("; ")}.`},Re=(e,t)=>{if(st.has(e))return Le();let s=t?pe(Y(e)||e):void 0,n=s?.one&&$(T(s.one))===$(Y(e)||e)?void 0:ie(e);if(n){let l=We(n);return{about:"place",say:t?`${l.said} ${ye(n)}`:l.said,moves:[l],subject:n.slug}}let r=pe(Y(e)||e);if(r.one){let l=De(r.one);return{about:t?"describe":"record",say:t?`${l.said} ${re(r.one)}`:l.said,moves:[l],subject:r.one.id}}if(r.picks.length>0)return{about:"picks",say:Ee(r.picks),moves:[],picks:r.picks};let h=de(e);if(h)return h;let d=Pe(e);if(d){if(d.rest.split(" ").every(l=>l===""||te.has(l))){let l=H(d.kind),v={to:"kind",kind:d.kind,title:l,address:oe(d.kind),said:`Went to the ${l.toLowerCase()}.`};return{about:"kind",say:v.said,moves:[v]}}return{unresolved:!0}}return xe()},ye=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(D(l.kind),l.kind):H(l.kind)).toLowerCase()}`),d=c.violations().length;return[h.length>0?`It holds ${he(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=H(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(D(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=(p.selection??[]).map(s=>w.getNode(s)).find(s=>s!==void 0);if(e)return{about:"here",say:re(e),moves:[],subject:e.id};let t=N.find(s=>s.slug===p.place)??N.find(s=>s.slug==="home");return t?{about:"here",say:`${t.title}. ${ye(t)}`,moves:[],subject:t.slug}:{about:"here",say:ye({slug:"home",title:"Home",kind:null,cardinality:"many",address:"/",stop:"#"}),moves:[]}},Pe=e=>{let t=P.flatMap(s=>[H(s),F(D(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()}},ae=(e,t)=>{let s=V(y,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=D(e)?.fieldRoles??{};for(let d of["due","deadline","date","when","start","end"]){let l=r[d],v=l?s.find(M=>M.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)},Te=e=>{let t=D(e),s=V(y,e).filters;if(t?.lifecycle)return{conditions:[{key:"is",value:"current"}],holds:d=>fe(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}},He=(e,t)=>{let s=e.words.startsWith("due")||$(t.key)==="due",n=Ot.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}`},me=new Set(c.violations().flatMap(e=>e.nodeIds)),be={schema:y,graph:c.graph,flagged:me,today:k},de=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=>ae(L,g)!==void 0),R=m.filter(L=>{let b=ae(L,g);return g.some(O=>$(b.key)===O||$(b.label)===O)}),B=m.length===1?m:R;if(B.length!==1)return;n=B[0]}if(!n)return;let h=V(y,n).filters,d=[],l=[],v=[],M=[],q=!1,le=[];for(let g=0;g<r.length;g++){let m=r[g],R=g>0&&(r[g-1]==="not"||r[g-1]==="un"),B=h.find(b=>b.about==="field"&&b.type==="choice"&&(b.options??[]).some(O=>$(O)===m));if(B&&!R){let b=(B.options??[]).find(O=>$(O)===m);d.push({key:B.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=!R&&!(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(Lt.has(m)&&!R){let b=Te(n);b==="unsayable"?(q=!0,M.push(O=>!lt(y,O))):(d.push(...b.conditions),M.push(b.holds)),l.push(m);continue}m==="not"||m==="un"||t&&h.some(b=>b.type==="date"&&($(b.key)===m||$(b.label)===m))||le.push(m)}if(r=le,r.some(g=>!te.has(g))||!t&&d.length===0&&M.length===0)return;let I=H(n).toLowerCase(),Q=H(n);if(t){let g=ae(n,e.split(" "));if(!g){let m={to:"kind",kind:n,title:Q,address:oe(n),said:`Went to the ${I}.`};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=Te(n);m==="unsayable"?(q=!0,M.push(R=>!lt(y,R))):(d.push(...m.conditions),M.push(m.holds))}t.ask.overdue?l.push("overdue"):v.push(He(t.ask,g))}let E=w.nodesOfKind(n).filter(g=>d.every(m=>fe(be,g,m))&&M.every(m=>m(g))),K=[...l,...v].join(" and "),J=[...l,I,...v].join(" "),W=E.slice(0,6).map(g=>({about:"node",id:g.id,kind:n,label:T(g),why:{field:d[0]?.key??"label",reading:d[0]?.key??"Name",fragment:K,strength:"field"},current:!0,flagged:me.has(g.id),address:ge(g)})),X=E.length===0?`No ${I} are ${K}.`:`${E.length===1?`One ${F(D(n),n)} is`:`${E.length} ${I} are`} ${K}: ${he(E.slice(0,6).map(T))}${E.length>6?`, and ${E.length-6} more`:""}.`;if(q)return{about:"kind",say:X,moves:[],picks:W,offer:{draft:J,label:"Show as a view"}};let Z=d.map(g=>`${g.key}:${g.value}`).join(","),we=`${oe(n)}?${new URLSearchParams({filter:Z}).toString()}`,_={to:"kind",kind:n,title:ee(J),filter:Z,address:we,said:`Went to the ${J}.`};return{about:"kind",say:`${_.said} ${X}`,moves:[_],picks:W}},Ie=e=>D(e)?.figure==="person"?!0:[e,F(D(e),e),H(e)].some(s=>$(s).split(" ").some(n=>Et.has(n))),gt=e=>{let t=[],s=n=>D(n)?.edges??{};for(let[n,r]of Object.entries(s(e)))for(let h of r.to??[])f.has(h)&&t.push({key:n,direction:"out",far:h,words:dt(`${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:dt(`${h.inverse??""} ${r}`)});return t},pt=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=>[H(a),F(D(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)),M=t==="who"?d.find(Ie):d[0];if(!M&&t!=="who")return;let q=d.find(a=>a!==M),le=v.flatMap(a=>[je(a),...at.has(je(a))?[...at]:[]]),I=P.filter(a=>q?a===q:a!==M).flatMap(a=>{let A=ae(a,e.split(" "))??V(y,a).filters.find(x=>x.about==="field"&&x.type==="date");return A?gt(a).filter(x=>(M?x.far===M:Ie(x.far))&&x.far!==a).map(x=>({kind:a,field:A,relation:x,said:v.length===0||le.some(ve=>x.words.some(wt=>Rt(wt,ve)))})):[]}).filter(a=>a.said);if(I.length===0)return;let Q=I.filter(a=>n.some(A=>$(a.field.key)===A||$(a.field.label)===A)),E=I.length===1?I[0]:Q.length===1?Q[0]:void 0;if(!E)return;let{kind:K,field:J,relation:W}=E,X=[...s.ask.from?[{key:J.key,value:`after:${C(s.ask.from,-1)}`}]:[],...s.ask.to?[{key:J.key,value:`before:${C(s.ask.to,1)}`}]:[]],Z=w.nodesOfKind(K).filter(a=>X.every(A=>fe(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&&f.has(W.far)),_=[],g=[];for(let a of Z){let A=we(a);A.length===0&&g.push(a);for(let x of A)_.some(ve=>ve.id===x.id)||_.push(x)}let m=He(s.ask,J),R=s.ask.day?`On ${s.ask.day}`:ee(s.ask.words.replace(/^(?:due|for|on|by) (?:the )?/,"")),B=H(K).toLowerCase(),L=X.map(a=>`${a.key}:${a.value}`).join(","),b=`${B} ${m}`,O={to:"kind",kind:K,title:ee(b),filter:L,address:`${oe(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 ce=v.join(" "),yt=l==="was"||l==="were",Ge=a=>yt?a===1?"was":"were":a===1?"is":"are",ue=_.map(T),mt=ue.length>8?[...ue.slice(0,8),`${ue.length-8} more`]:ue,bt=_.length===0?`${R}: nobody ${Ge(1)}${ce?` ${ce}`:""}.`:`${R}: ${he(mt)}${ce?` ${Ge(_.length)} ${ce}`:""}.`,kt=t==="who"&&g.length>0?`${he(g.slice(0,4).map(T))}${g.length>4?` and ${g.length-4} more`:""} ${g.length===1?"has":"have"} nobody.`:"",$t=_.slice(0,8).map(a=>({about:"node",id:a.id,kind:a.kind,label:T(a),why:{field:W.key,reading:Je(y,W.direction==="out"?K:W.far,W.key,W.direction==="out"?"out":"in"),fragment:m,strength:"field"},current:!0,flagged:me.has(a.id),address:ge(a)}));return{about:"related",say:[bt,kt,O.said].filter(Boolean).join(" "),moves:[O],picks:$t}},Ke=S.match(Ct);if(Ke){let e=Ke[1];if(e&&!st.has(e)&&!/^(?:it|this|that)$/.test(e)){let n=ie(e),r=n?void 0:pe(Y(e)||e);if(r?.one){let h=De(r.one);return{about:"describe",say:`${h.said} ${re(r.one)}`,moves:[h],subject:r.one.id}}if(!n)return r&&r.picks.length>0?{about:"picks",say:Ee(r.picks),moves:[],picks:r.picks}:xe()}if(e&&/^(?:it|this|that)$|^(?:here|this place|this page)$/.test(e)){let n=(p.selection??[]).map(r=>w.getNode(r)).find(r=>r!==void 0);if(n)return{about:"describe",say:re(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(Nt.test(S))return Le();let _e=pt(S);if(_e)return _e;let ke=Oe(S,k,j);if(ke&&!ie(Y(ke.ask.words))&&ke.rest.replace(/'s\b/g,"").split(" ").every(e=>e===""||te.has(e)||Ce.has(e))){let e=de(S);if(e)return e}if(/^open /.test(S)){let e=de(S);if(e)return e}let Fe=S.match(At)??S.match(/^(?:go|take me|head|get me)(?: back)? (home)$/);if(Fe)return Re(Fe[1].trim(),!1);let Ue=S.match(St);if(Ue){let e=Re(Ue[1].trim(),!0);return"unresolved"in e&&e.unresolved&&!/^tell me|^describe/.test(S)?{unresolved:!0}:e}let $e=ie(S);if($e){let e=We($e);return{about:"place",say:e.said,moves:[e],subject:$e.slug}}let Be=de(S);return Be||{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"]),at=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 p of["ing","ed","es","s"])if(i.length>p.length+2&&i.endsWith(p)){let u=i.slice(0,-p.length);return u.length>3&&u[u.length-1]===u[u.length-2]?u.slice(0,-1):u}return i}function dt(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 Rt=(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"]),Lt=new Set(["open","unfinished","outstanding","pending","remaining","undone","incomplete"]);function lt(o,i){return V(o,i.kind).filters.some(u=>u.about==="field"&&(u.type==="boolean"&&ne.has(u.key.toLowerCase())&&i[u.key]===!0||u.type==="choice"&&typeof i[u.key]=="string"&&ne.has(String(i[u.key]).toLowerCase())))}function he(o){return o.length<=1?o[0]??"":`${o.slice(0,-1).join(", ")} and ${o[o.length-1]}`}function _t(o,i,p={}){let u=p.scene!==void 0?{...p.pages,scene:p.scene}:p.pages;return[...et(o,i,u?{pages:u}:{})].map(({first:c,hidden:y,lens:k,...j})=>j)}function ht(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 Ft(o,i,p,u){let c=ft(o,i,ht(p,u));if(c.unresolved)return c.say?{reply:{say:c.say,proposals:[],grounded:!0}}:{};if(c.about==="picks")return{};let y=c.moves.length>0?{moves:c.moves}:{},k=c.subject?o.graph.getNode(c.subject):void 0;if(c.about==="problems")return{...y,problems:!0};if(k&&(c.about==="describe"||c.about==="here"))return{...y,told:k.id};let j=k?tt(o,nt(Ve(o.violations(),[k.id])).slice(0,3)):[];return{reply:{say:c.say,proposals:j,grounded:!0,...y,...c.picks&&c.picks.length>0?{picks:c.picks}:{},...c.offer?{offer:c.offer}:{}}}}function Ut(o,i,p={}){let u=ht(p),c=[];for(let y of i){let k=typeof y=="string"?y:typeof y=="object"&&y!==null&&typeof y.to=="string"?y.to:void 0;if(!k||k.trim().length===0)continue;let j=ft(o,/^(?:go|take me|open|show)\b/i.test(k.trim())?k:`go to ${k}`,u);if("moves"in j)for(let z of j.moves)c.some(U=>U.address===z.address)||c.push(z)}return c}export{vt as NOTHING_BY_THAT_NAME,ht as askContextOf,Ft as goingFrom,Ut as movesFromNames,_t as placesFromViews,ft as resolveAsk};
|
|
1
|
+
import{a as ee}from"./chunk.G4JJXA63.js";import{b as nt}from"./chunk.7BAUPTMY.js";import{d as tt}from"./chunk.WX5CJ7PI.js";import"./chunk.JCZH55RX.js";import{Fa as fe,J as Ye,Ja as Se,Ka as Xe,Oa as G,P as ze,R as Je,Sa as Ze,T as Ae,U as F,V as qe,Wb as et,ea as Ve,fa as Qe,za as V}from"./chunk.RAE4M3KQ.js";import"./chunk.AJZBJBMO.js";var vt="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(),At=/^(?:(?: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)) (.+)$/,Nt=/^(?: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))$/,st=new Set(["here","this","this place","this page","on this page","on the page","on this screen","in view"]),Ot=/^(?:date|day|when|on|at|the date|the day)$/,Ct=/^(?: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) (.+))?$/,Y=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"]),ct=864e5,se=o=>Date.UTC(Number(o.slice(0,4)),Number(o.slice(5,7))-1,Number(o.slice(8,10))),Me=o=>new Date(o).toISOString().slice(0,10),C=(o,i)=>Me(se(o)+i*ct),jt=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],Mt=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],ut=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Dt="(monday|tuesday|tues|wednesday|thursday|thurs|friday|saturday|sunday)",ot="(january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sept|sep|oct|nov|dec)",rt="(\\d{1,2})(?:st|nd|rd|th)?",Wt=o=>jt.findIndex(i=>i.startsWith(o.slice(0,3))),it=o=>ut.findIndex(i=>o.startsWith(i.toLowerCase()));function xt(o,i){let p=new Date(se(o)),u=o.slice(0,4)===i.slice(0,4)?"":` ${o.slice(0,4)}`;return`${Mt[p.getUTCDay()]} ${p.getUTCDate()} ${ut[p.getUTCMonth()]}${u}`}function Ne(o,i,p){if(o<0||i<1||i>31)return;let u=Number(p.slice(0,4)),c=k=>{let j=Date.UTC(k,o,i);return new Date(j).getUTCMonth()===o?Me(j):void 0},y=c(u);if(y)return se(y)<se(p)-183*ct?c(u+1):y}function Oe(o,i,p){let u=new Date(se(i)).getUTCDay(),c=f=>{let N=(u-p+7)%7,w=C(i,-N+f*7);return{from:w,to:C(w,6)}},y=()=>{let f=`${i.slice(0,8)}01`,N=new Date(Date.UTC(Number(i.slice(0,4)),Number(i.slice(5,7)),1));return{from:f,to:C(Me(N.getTime()),-1)}},k=f=>f?{from:f,to:f,day:xt(f,i)}:void 0,j=(f,N)=>{let w=Wt(N);return k(f==="this"||f==="next"?C(c(f==="next"?1:0).from,(w-p+7)%7):f==="last"?C(i,-((u-w+6)%7+1)):C(i,(w-u+7)%7))},z=f=>{let N=C(i,u===0?-1:6-u);return{from:C(N,f*7),to:C(N,f*7+1)}},U="\\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/,()=>z(1)],[/\b(?:due |for |on )?(?:this |the )?weekend\b/,()=>z(0)],[/\b(?:due |for |on )?this month\b/,()=>y()],[new RegExp(`${U}(\\d{4}) (\\d{2}) (\\d{2})\\b`),f=>k(Ne(Number(f[2])-1,Number(f[3]),`${f[1]}-01-01`))],[new RegExp(`${U}${rt} (?:of )?${ot}\\b`),f=>k(Ne(it(f[2]),Number(f[1]),i))],[new RegExp(`${U}${ot} (?:the )?${rt}\\b`),f=>k(Ne(it(f[1]),Number(f[2]),i))],[new RegExp(`${U}(?:(this|next|last|coming) )?${Dt}\\b`),f=>j(f[1],f[2])]];for(let[f,N]of P){let w=o.match(f);if(!w)continue;let S=N(w);if(S)return{ask:{words:w[0],...S},rest:o.replace(w[0]," ").replace(/\s+/g," ").trim()}}}function ft(o,i,p={}){let u=p.principal??{kind:"human"},c=o.seenBy(u),y=c.schema,k=p.today??o.today?.()??new Date().toISOString().slice(0,10),j=p.weekStartsOn??1,z=o.kindsKeptFrom(u),U=o.modules.disabledKinds,P=y.kinds.filter(e=>!z.has(e)&&!U.has(e)),f=new Set(P),N=(p.places??[]).filter(e=>e.kind===null||f.has(e.kind)),w=c.graph,S=$(i).replace(/[?.!]+$/,"").trim();if(S.length===0)return{unresolved:!0};let D=e=>y.tryDefinition(e),T=e=>Ye(D(e.kind),e),H=e=>ze(y,e),oe=e=>N.find(t=>t.kind===e&&t.address===Se(y,e))?.address??Se(y,e),ge=e=>Xe(y,e.kind,e.id),De=e=>({to:"record",id:e.id,kind:e.kind,label:T(e),address:ge(e),said:`Went to ${T(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}},xe=()=>({unresolved:!0,say:vt}),re=e=>{let t=D(e.kind),s=qe(e,t,{limit:3}).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[`${T(e)} \u2014 ${Ae(F(t,e.kind))}${s?` (${s})`:""}.`,n.length>0?`Trouble: ${n.map(r=>r.message).join("; ")}.`:""].filter(Boolean).join(" ")},ie=e=>{let t=new Set([G(e),G(Y(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(Y(e.slice(0,-n.length)))));t.delete("");let s=n=>t.has(G(n.title))||t.has(G(Y($(n.title))))||t.has(G(n.slug));return N.find(n=>n.kind!==null&&n.address.startsWith("/places/")&&s(n))??N.find(s)},pe=e=>{let t=Ze(o,e,{principal:u,today:k,limit:6,...p.selection?{from:p.selection}:{}}),s=t.hits.filter(r=>r.about==="node"&&f.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}},Ee=e=>{let t=e.map(s=>`${s.label} (${F(D(s.kind),s.kind)})`);return`${e.length===1?"One thing matches":`${e.length} things match`}: ${t.join("; ")}.`},Re=(e,t)=>{if(st.has(e))return Le();let s=t?pe(Y(e)||e):void 0,n=s?.one&&$(T(s.one))===$(Y(e)||e)?void 0:ie(e);if(n){let l=We(n);return{about:"place",say:t?`${l.said} ${ye(n)}`:l.said,moves:[l],subject:n.slug}}let r=pe(Y(e)||e);if(r.one){let l=De(r.one);return{about:t?"describe":"record",say:t?`${l.said} ${re(r.one)}`:l.said,moves:[l],subject:r.one.id}}if(r.picks.length>0)return{about:"picks",say:Ee(r.picks),moves:[],picks:r.picks};let h=de(e);if(h)return h;let d=Pe(e);if(d){if(d.rest.split(" ").every(l=>l===""||te.has(l))){let l=H(d.kind),v={to:"kind",kind:d.kind,title:l,address:oe(d.kind),said:`Went to the ${l.toLowerCase()}.`};return{about:"kind",say:v.said,moves:[v]}}return{unresolved:!0}}return xe()},ye=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(D(l.kind),l.kind):H(l.kind)).toLowerCase()}`),d=c.violations().length;return[h.length>0?`It holds ${he(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=H(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(D(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=(p.selection??[]).map(s=>w.getNode(s)).find(s=>s!==void 0);if(e)return{about:"here",say:re(e),moves:[],subject:e.id};let t=N.find(s=>s.slug===p.place)??N.find(s=>s.slug==="home");return t?{about:"here",say:`${t.title}. ${ye(t)}`,moves:[],subject:t.slug}:{about:"here",say:ye({slug:"home",title:"Home",kind:null,cardinality:"many",address:"/",stop:"#"}),moves:[]}},Pe=e=>{let t=P.flatMap(s=>[H(s),F(D(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()}},ae=(e,t)=>{let s=V(y,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=D(e)?.fieldRoles??{};for(let d of["due","deadline","date","when","start","end"]){let l=r[d],v=l?s.find(M=>M.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)},Te=e=>{let t=D(e),s=V(y,e).filters;if(t?.lifecycle)return{conditions:[{key:"is",value:"current"}],holds:d=>fe(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}},He=(e,t)=>{let s=e.words.startsWith("due")||$(t.key)==="due",n=Ot.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}`},me=new Set(c.violations().flatMap(e=>e.nodeIds)),be={schema:y,graph:c.graph,flagged:me,today:k},de=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=>ae(L,g)!==void 0),R=m.filter(L=>{let b=ae(L,g);return g.some(O=>$(b.key)===O||$(b.label)===O)}),B=m.length===1?m:R;if(B.length!==1)return;n=B[0]}if(!n)return;let h=V(y,n).filters,d=[],l=[],v=[],M=[],q=!1,le=[];for(let g=0;g<r.length;g++){let m=r[g],R=g>0&&(r[g-1]==="not"||r[g-1]==="un"),B=h.find(b=>b.about==="field"&&b.type==="choice"&&(b.options??[]).some(O=>$(O)===m));if(B&&!R){let b=(B.options??[]).find(O=>$(O)===m);d.push({key:B.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=!R&&!(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(Lt.has(m)&&!R){let b=Te(n);b==="unsayable"?(q=!0,M.push(O=>!lt(y,O))):(d.push(...b.conditions),M.push(b.holds)),l.push(m);continue}m==="not"||m==="un"||t&&h.some(b=>b.type==="date"&&($(b.key)===m||$(b.label)===m))||le.push(m)}if(r=le,r.some(g=>!te.has(g))||!t&&d.length===0&&M.length===0)return;let I=H(n).toLowerCase(),Q=H(n);if(t){let g=ae(n,e.split(" "));if(!g){let m={to:"kind",kind:n,title:Q,address:oe(n),said:`Went to the ${I}.`};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=Te(n);m==="unsayable"?(q=!0,M.push(R=>!lt(y,R))):(d.push(...m.conditions),M.push(m.holds))}t.ask.overdue?l.push("overdue"):v.push(He(t.ask,g))}let E=w.nodesOfKind(n).filter(g=>d.every(m=>fe(be,g,m))&&M.every(m=>m(g))),K=[...l,...v].join(" and "),J=[...l,I,...v].join(" "),W=E.slice(0,6).map(g=>({about:"node",id:g.id,kind:n,label:T(g),why:{field:d[0]?.key??"label",reading:d[0]?.key??"Name",fragment:K,strength:"field"},current:!0,flagged:me.has(g.id),address:ge(g)})),X=E.length===0?`No ${I} are ${K}.`:`${E.length===1?`One ${F(D(n),n)} is`:`${E.length} ${I} are`} ${K}: ${he(E.slice(0,6).map(T))}${E.length>6?`, and ${E.length-6} more`:""}.`;if(q)return{about:"kind",say:X,moves:[],picks:W,offer:{draft:J,label:"Show as a view"}};let Z=d.map(g=>`${g.key}:${g.value}`).join(","),we=`${oe(n)}?${new URLSearchParams({filter:Z}).toString()}`,_={to:"kind",kind:n,title:ee(J),filter:Z,address:we,said:`Went to the ${J}.`};return{about:"kind",say:`${_.said} ${X}`,moves:[_],picks:W}},Ie=e=>D(e)?.figure==="person"?!0:[e,F(D(e),e),H(e)].some(s=>$(s).split(" ").some(n=>Et.has(n))),gt=e=>{let t=[],s=n=>D(n)?.edges??{};for(let[n,r]of Object.entries(s(e)))for(let h of r.to??[])f.has(h)&&t.push({key:n,direction:"out",far:h,words:dt(`${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:dt(`${h.inverse??""} ${r}`)});return t},pt=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=>[H(a),F(D(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)),M=t==="who"?d.find(Ie):d[0];if(!M&&t!=="who")return;let q=d.find(a=>a!==M),le=v.flatMap(a=>[je(a),...at.has(je(a))?[...at]:[]]),I=P.filter(a=>q?a===q:a!==M).flatMap(a=>{let A=ae(a,e.split(" "))??V(y,a).filters.find(x=>x.about==="field"&&x.type==="date");return A?gt(a).filter(x=>(M?x.far===M:Ie(x.far))&&x.far!==a).map(x=>({kind:a,field:A,relation:x,said:v.length===0||le.some(ve=>x.words.some(wt=>Rt(wt,ve)))})):[]}).filter(a=>a.said);if(I.length===0)return;let Q=I.filter(a=>n.some(A=>$(a.field.key)===A||$(a.field.label)===A)),E=I.length===1?I[0]:Q.length===1?Q[0]:void 0;if(!E)return;let{kind:K,field:J,relation:W}=E,X=[...s.ask.from?[{key:J.key,value:`after:${C(s.ask.from,-1)}`}]:[],...s.ask.to?[{key:J.key,value:`before:${C(s.ask.to,1)}`}]:[]],Z=w.nodesOfKind(K).filter(a=>X.every(A=>fe(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&&f.has(W.far)),_=[],g=[];for(let a of Z){let A=we(a);A.length===0&&g.push(a);for(let x of A)_.some(ve=>ve.id===x.id)||_.push(x)}let m=He(s.ask,J),R=s.ask.day?`On ${s.ask.day}`:ee(s.ask.words.replace(/^(?:due|for|on|by) (?:the )?/,"")),B=H(K).toLowerCase(),L=X.map(a=>`${a.key}:${a.value}`).join(","),b=`${B} ${m}`,O={to:"kind",kind:K,title:ee(b),filter:L,address:`${oe(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 ce=v.join(" "),yt=l==="was"||l==="were",Ge=a=>yt?a===1?"was":"were":a===1?"is":"are",ue=_.map(T),mt=ue.length>8?[...ue.slice(0,8),`${ue.length-8} more`]:ue,bt=_.length===0?`${R}: nobody ${Ge(1)}${ce?` ${ce}`:""}.`:`${R}: ${he(mt)}${ce?` ${Ge(_.length)} ${ce}`:""}.`,kt=t==="who"&&g.length>0?`${he(g.slice(0,4).map(T))}${g.length>4?` and ${g.length-4} more`:""} ${g.length===1?"has":"have"} nobody.`:"",$t=_.slice(0,8).map(a=>({about:"node",id:a.id,kind:a.kind,label:T(a),why:{field:W.key,reading:Je(y,W.direction==="out"?K:W.far,W.key,W.direction==="out"?"out":"in"),fragment:m,strength:"field"},current:!0,flagged:me.has(a.id),address:ge(a)}));return{about:"related",say:[bt,kt,O.said].filter(Boolean).join(" "),moves:[O],picks:$t}},Ke=S.match(Ct);if(Ke){let e=Ke[1];if(e&&!st.has(e)&&!/^(?:it|this|that)$/.test(e)){let n=ie(e),r=n?void 0:pe(Y(e)||e);if(r?.one){let h=De(r.one);return{about:"describe",say:`${h.said} ${re(r.one)}`,moves:[h],subject:r.one.id}}if(!n)return r&&r.picks.length>0?{about:"picks",say:Ee(r.picks),moves:[],picks:r.picks}:xe()}if(e&&/^(?:it|this|that)$|^(?:here|this place|this page)$/.test(e)){let n=(p.selection??[]).map(r=>w.getNode(r)).find(r=>r!==void 0);if(n)return{about:"describe",say:re(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(Nt.test(S))return Le();let _e=pt(S);if(_e)return _e;let ke=Oe(S,k,j);if(ke&&!ie(Y(ke.ask.words))&&ke.rest.replace(/'s\b/g,"").split(" ").every(e=>e===""||te.has(e)||Ce.has(e))){let e=de(S);if(e)return e}if(/^open /.test(S)){let e=de(S);if(e)return e}let Fe=S.match(At)??S.match(/^(?:go|take me|head|get me)(?: back)? (home)$/);if(Fe)return Re(Fe[1].trim(),!1);let Ue=S.match(St);if(Ue){let e=Re(Ue[1].trim(),!0);return"unresolved"in e&&e.unresolved&&!/^tell me|^describe/.test(S)?{unresolved:!0}:e}let $e=ie(S);if($e){let e=We($e);return{about:"place",say:e.said,moves:[e],subject:$e.slug}}let Be=de(S);return Be||{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"]),at=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 p of["ing","ed","es","s"])if(i.length>p.length+2&&i.endsWith(p)){let u=i.slice(0,-p.length);return u.length>3&&u[u.length-1]===u[u.length-2]?u.slice(0,-1):u}return i}function dt(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 Rt=(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"]),Lt=new Set(["open","unfinished","outstanding","pending","remaining","undone","incomplete"]);function lt(o,i){return V(o,i.kind).filters.some(u=>u.about==="field"&&(u.type==="boolean"&&ne.has(u.key.toLowerCase())&&i[u.key]===!0||u.type==="choice"&&typeof i[u.key]=="string"&&ne.has(String(i[u.key]).toLowerCase())))}function he(o){return o.length<=1?o[0]??"":`${o.slice(0,-1).join(", ")} and ${o[o.length-1]}`}function _t(o,i,p={}){let u=p.scene!==void 0?{...p.pages,scene:p.scene}:p.pages;return[...et(o,i,u?{pages:u}:{})].map(({first:c,hidden:y,lens:k,...j})=>j)}function ht(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 Ft(o,i,p,u){let c=ft(o,i,ht(p,u));if(c.unresolved)return c.say?{reply:{say:c.say,proposals:[],grounded:!0}}:{};if(c.about==="picks")return{};let y=c.moves.length>0?{moves:c.moves}:{},k=c.subject?o.graph.getNode(c.subject):void 0;if(c.about==="problems")return{...y,problems:!0};if(k&&(c.about==="describe"||c.about==="here"))return{...y,told:k.id};let j=k?tt(o,nt(Ve(o.violations(),[k.id])).slice(0,3)):[];return{reply:{say:c.say,proposals:j,grounded:!0,...y,...c.picks&&c.picks.length>0?{picks:c.picks}:{},...c.offer?{offer:c.offer}:{}}}}function Ut(o,i,p={}){let u=ht(p),c=[];for(let y of i){let k=typeof y=="string"?y:typeof y=="object"&&y!==null&&typeof y.to=="string"?y.to:void 0;if(!k||k.trim().length===0)continue;let j=ft(o,/^(?:go|take me|open|show)\b/i.test(k.trim())?k:`go to ${k}`,u);if("moves"in j)for(let z of j.moves)c.some(U=>U.address===z.address)||c.push(z)}return c}export{vt as NOTHING_BY_THAT_NAME,ht as askContextOf,Ft as goingFrom,Ut as movesFromNames,_t as placesFromViews,ft as resolveAsk};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{yb as e}from"./chunk.RAE4M3KQ.js";var a=`
|
|
2
2
|
.graview-spec { display: flex; flex-direction: column; gap: 6px; min-width: 0; color: var(--graview-ink); }
|
|
3
3
|
|
|
4
4
|
.graview-spec-row { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px 10px; box-sizing: border-box; max-width: 100%; padding: 5px 10px; border: 1px solid var(--graview-edge); border-radius: var(--graview-radius-sm, 8px); background: var(--graview-panel); font-size: 0.875rem; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as T,f as I,g as L,h as D,i as E}from"./chunk.54NSG7BX.js";import{a as U}from"./chunk.UM5IPM22.js";import{c as w,e as _}from"./chunk.6XBLDV4A.js";import{a as A,b as N,c as C,e as R,l as M,m,n as V}from"./chunk.WOTNMTIY.js";import{E as O,I as G,M as k,R as F}from"./chunk.ZQ4HFIIS.js";var S=e=>{try{return e()}catch{return null}},X=e=>typeof e=="string"&&I.includes(e);function q(e){if(e!==void 0)return X(e)?e:e&&typeof e=="object"&&typeof e.expr=="string"?{expr:S(()=>w(e.expr))}:"neutral"}var Q=4;function ee(e){let n=typeof e.list=="string"?S(()=>w(e.list)):null,a=e.sort,r=typeof a=="string"?a:a&&typeof a=="object"&&typeof a.by=="string"?a.by:void 0,t=a&&typeof a=="object"?a.direction:void 0,o=n,i;if(n&&r!==void 0)if(t==="choices")i=r;else{let f=S(()=>w(r));o=f?{t:"call",fn:"sort",args:[n,f,{t:"lit",value:t==="desc"?"desc":"asc",at:0}],at:0}:null}let l=typeof e.limit=="number"&&Number.isInteger(e.limit)&&e.limit>=1?Math.min(e.limit,E):void 0,s=e.group,d=typeof s=="string"?s:s&&typeof s=="object"&&typeof s.by=="string"?s.by:void 0,y=s&&typeof s=="object"&&s.headings&&typeof s.headings=="object"?s.headings:{};return{t:"list",source:o,...i?{choiceOrder:i}:{},...l?{limit:l}:{},...d?{group:{by:d,headings:Object.fromEntries(Object.entries(y).filter(f=>typeof f[1]=="string"))}}:{},...typeof e.empty=="string"?{empty:e.empty}:{},as:e.as==="card"?"card":"row"}}function W(e,n=1,a=""){if(!Array.isArray(e)||n>Q)return[];let r={};return e.flatMap(t=>{if(!t||typeof t!="object"||Array.isArray(t))return[];let o=t,i=p=>typeof p=="string"?S(()=>_(p)):null,l=p=>typeof p=="string"?S(()=>w(p)):null,s=q(o.tone),d=typeof o.label=="string"?o.label:void 0,y=p=>Object.hasOwn(o,p),f=typeof o.currency=="string"&&/^[A-Z]{3}$/.test(o.currency)?o.currency:void 0,u=y("list")?"list":y("headline")?"headline":typeof o.figure=="string"?"number":ne.find(y);if(!u)return[];let x=r[u]=(r[u]??0)+1,j=o.key,B=typeof j=="string"&&j?j:`${a}${u}.${x}`;return[{...(()=>{switch(u){case"list":return ee(o);case"number":{let p=D.includes(o.as)?o.as:void 0;return{t:u,value:l(o.figure),...p?{as:p}:{},...f?{currency:f}:{},...d?{label:i(d)}:{}}}case"headline":case"title":return{t:u,parts:i(o[u])};case"text":case"badge":return{t:u,parts:i(o[u]),...s?{tone:s}:{}};case"field":{let p=L.includes(o.as)?o.as:void 0;return{t:u,field:String(o.field),...p?{as:p}:{},...f?{currency:f}:{},...d?{label:d}:{}}}case"progress":{let p=o.progress??{};return{t:u,value:l(p.value),max:l(p.max),...d?{label:i(d)}:{}}}case"group":return{t:u,blocks:W(o.group,n+1,`${B}.`),direction:o.direction==="row"?"row":"column"};case"when":return{t:u,when:l(o.when),show:W(o.show,n+1,`${B}.`)};default:return{t:u}}})(),key:B}]})}var ne=["title","text","badge","field","progress","group","when","divider","figure"],h="\u2014",re=500;function g(e,n){if(!e)return{ok:!1,problem:"an expression that does not parse"};try{return{ok:!0,value:R(e,{graph:n.graph??M,subject:n.node,kinds:n.kinds,today:n.today,budget:n.budget??re})}}catch(a){return{ok:!1,problem:a instanceof Error?a.message:String(a)}}}function b(e,n){if(!e)return{text:h,problem:"a template that does not parse"};let a,r=e.map(t=>{if(t.text!==void 0)return t.text;let o=g(t.expr??null,n);return o.ok?m(o.value,t.format,n.today,t.formatArgs,n.money):(a??=`{${t.source??""}}: ${o.problem}`,h)}).join("");return a?{text:r,problem:a}:{text:r}}function $(e,n){if(e===void 0)return;if(typeof e=="string")return e;let a=g(e.expr,n);return a.ok&&X(a.value)?a.value:"neutral"}function te(e){if(typeof e=="string")try{let n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"?n.href:void 0}catch{return}}function oe(e,n,a,r,t){if(n==null||n==="")return h;if(typeof n=="boolean")return n?"yes":"no";if(r)return m(n,r,a.today,[],t?{...a.money,currency:t}:a.money);let o=a.fields[e];return a.definition?.display?.format?.[e]?k(a.definition,e,n):o?.type==="date"?m(n,"date",a.today):o?.type==="enum"&&typeof n=="string"?k(a.definition,e,n):typeof n=="number"?n.toLocaleString("en-US"):Array.isArray(n)?n.map(i=>String(i)).join(", "):typeof n=="object"?h:String(n)}function ae(e,n,a,r,t){return typeof e!="number"?String(e):n==="money"?V(e,a?{...t,currency:a}:t):n==="percent"?m(e,n,r):e.toLocaleString("en-US",{maximumFractionDigits:2})}var c=(e,n)=>n?{...e,problem:n}:e;function se(e,n,a){switch(e.t){case"title":{let r=b(e.parts,n);return c({t:"title",text:r.text},r.problem)}case"text":{let r=b(e.parts,n),t=$(e.tone,n);return c({t:"text",text:r.text,...t?{tone:t}:{}},r.problem)}case"badge":{let r=b(e.parts,n);return c({t:"badge",text:r.text,tone:$(e.tone,n)??"neutral"},r.problem)}case"field":{let r=e.label??F(n.definition,e.field);if(!n.node)return{t:"field",field:e.field,label:r,text:h,problem:`"${e.field}" names a field, and these blocks are about no one record`};let t=n.kinds.get(n.node.kind)?.computed?.has(e.field),o,i;if(t){let d=g({t:"ident",name:e.field,at:0},n);d.ok?o=d.value!==null&&typeof d.value=="object"?m(d.value,void 0,n.today):d.value:i=d.problem}else o=Object.hasOwn(n.node,e.field)?n.node[e.field]:void 0;let l=n.fields[e.field]?.type==="url"&&e.as===void 0?te(o):void 0,s=S(()=>oe(e.field,o,n,e.as,e.currency))??h;return c({t:"field",field:e.field,label:r,text:s,...l?{href:l}:{}},i)}case"progress":{let r=g(e.value,n),t=g(e.max,n),o=e.label?b(e.label,n):{text:"Progress"},i=o.text,l=r.ok?t.ok?o.problem:t.problem:r.problem;return r.ok&&t.ok&&typeof r.value=="number"&&typeof t.value=="number"&&Number.isFinite(r.value)&&Number.isFinite(t.value)&&t.value>0?c({t:"progress",label:i,value:r.value,max:t.value,text:`${m(r.value,void 0,n.today)} of ${m(t.value,void 0,n.today)}`},l):c({t:"progress",label:i,text:h},l)}case"group":return{t:"group",direction:e.direction,blocks:H(e.blocks,n)};case"when":{let r=g(e.when,n),t=r.ok&&r.value===!0;return c({t:"when",shown:t,blocks:t?H(e.show,n):[]},r.ok?void 0:r.problem)}case"divider":return{t:"divider"};case"figure":return{t:"figure"};case"headline":{let r=b(e.parts,n),t=Math.min(6,Math.max(1,(a?n.firstHeading:void 0)??n.heading??3));return c({t:"headline",level:t,text:r.text},r.problem)}case"number":{let r=g(e.value,n),t=!r.ok||r.value===null||typeof r.value=="object"?h:ae(r.value,e.as,e.currency,n.today,n.money),o=e.label?b(e.label,n):void 0;return c({t:"number",text:t,...o?{label:o.text}:{}},r.ok?o?.problem:r.problem)}case"list":return de(e,n)}}function H(e,n){let a=e.findIndex(r=>r.t==="headline");return e.map((r,t)=>({...se(r,n,t===a),key:r.key}))}var ie=new Set(["every","some","sum","min","max","sort"]);function je(e,n){let a=new Set,r=new Set,t=s=>{if(s)switch(s.t){case"ident":a.add(s.name);return;case"list":s.items.forEach(t);return;case"member":return t(s.object);case"unary":return t(s.operand);case"binary":return t(s.left),t(s.right);case"where":return t(s.set);case"call":s.args.forEach((d,y)=>{y===1&&ie.has(s.fn)||t(d)});return;default:return}},o=s=>{for(let d of s??[])t(d.expr)},i=(s,d)=>{s.forEach((y,f)=>{let u=d[f];if(u)switch(y.t){case"field":a.add(y.field);return;case"title":case"text":case"badge":case"headline":o(y.parts);return;case"number":t(y.value),o(y.label);return;case"progress":t(y.value),t(y.max);return;case"group":u.t==="group"&&i(y.blocks,u.blocks);return;case"when":u.t==="when"&&u.shown&&i(y.show,u.blocks);return;case"list":if(u.t==="list")for(let x of u.members)r.add(x.id);return;default:return}})};i(e,n);let l=n[0];return{fields:a,records:r,...e[0]?.t==="title"&&l?.t==="title"?{title:l.text}:{}}}function de(e,n){let a=Math.min(6,(n.heading??3)+1),r=g(e.source,n);if(!r.ok)return{t:"list",as:e.as,failed:!0,members:[],headingLevel:a,more:0,problem:r.problem};let t=r.value,o=t instanceof A?t.nodes:t!==null&&typeof t=="object"&&!Array.isArray(t)?[t]:[];e.choiceOrder&&n.schema&&(o=le(o,e.choiceOrder,n.schema));let i=o.length;o=o.slice(0,e.limit??E);let l=e.limit===void 0?i-o.length:0;return{t:"list",as:e.as,failed:!1,members:o,...e.group&&n.schema&&o.length>0?{groups:ue(o,e.group,n.schema)}:{},headingLevel:a,...o.length===0&&e.empty?{empty:e.empty}:{},more:l}}function J(e,n,a){let r=e.tryDefinition(n)?.fields?.shape,t=r&&Object.hasOwn(r,a)?T(r[a]):void 0;return t?.type==="enum"?t.options??[]:[]}var P=(e,n)=>Object.hasOwn(e,n)?e[n]:void 0;function le(e,n,a){let r=t=>{let o=J(a,t.kind,n).indexOf(String(P(t,n)));return o<0?Number.MAX_SAFE_INTEGER:o};return e.map((t,o)=>({node:t,i:o,rank:r(t)})).sort((t,o)=>t.rank-o.rank||t.i-o.i).map(t=>t.node)}function ue(e,n,a){let r=[];for(let i of e)for(let l of J(a,i.kind,n.by))r.includes(l)||r.push(l);let t=[];for(let i of r){let l=e.filter(d=>P(d,n.by)===i);if(l.length===0)continue;let s=a.tryDefinition(l[0].kind);t.push({value:i,heading:n.headings[i]??O(k(s,n.by,i)),members:l})}let o=e.filter(i=>!r.includes(String(P(i,n.by))));return o.length>0&&t.push({value:null,members:o}),t}function K(e){return e.t==="list"||e.t==="headline"||e.t==="number"?!0:e.t==="group"?e.blocks.some(K):e.t==="when"?e.show.some(K):!1}function z(e,n){let a=e.tryDefinition(n)?.fields?.shape??{},r={};for(let[t,o]of Object.entries(a)){let i=T(o);i&&(r[t]=i)}return r}var Y=new WeakMap;function v(e){let n=Y.get(e);return n||Y.set(e,n=U(e)),n}function ye(e,n,a,r={}){let t=v(e),o={},i={},l=s=>{if(s instanceof A)return s.nodes.map(d=>l(d));if(Array.isArray(s))return s.map(d=>l(d));if(s!==null&&typeof s=="object"){let d=s;return{id:d.id,kind:d.kind,label:G(e.tryDefinition(d.kind),d)}}return s};for(let[s,d]of t.get(a?a.kind:N)?.computed??[])try{o[s]=l(R(d,{graph:n,subject:a,kinds:t,...r.today?{today:r.today}:{},...r.budget?{budget:r.budget}:{}}))}catch(y){if(!(y instanceof C))throw y;i[s]=y.sentence}return{values:o,refused:i}}function ve(e,n,a){let{values:r}=ye(e,n,a);if(Object.keys(r).length===0)return a;let t=o=>Array.isArray(o)?o.map(t):o!==null&&typeof o=="object"?o.label:o;return{...a,...Object.fromEntries(Object.entries(r).map(([o,i])=>[o,t(i)]))}}var pe=500,fe=2e4,Z=new WeakMap;function ce(e,n){let a=Z.get(e);a||Z.set(e,a=new Map);let r=a.get(n);return r||a.set(n,r=z(e,n)),r}function Ne(e,n,a,r={}){if(n&&typeof e.seenBy!="function")throw new TypeError("blockContextFor: a seat is read from a store (its `seenBy`); a bare { graph, schema } is read as it is handed, with no principal");let t=n?e.seenBy(n):e,o=n&&a?t.graph.getNode(a.id)??null:a,i=t.schema,l=o&&i.tryDefinition(o.kind),s=!o||(r.slot??"page")==="page",{money:d,firstHeading:y}=r;return{node:o,graph:t.graph,schema:i,kinds:v(i),fields:o?ce(i,o.kind):{},definition:l||void 0,today:r.today??t.today?.()??new Date().toISOString().slice(0,10),money:d,heading:r.heading??(s?2:3),firstHeading:y,budget:r.budget??(s?fe:pe)}}export{W as a,H as b,je as c,K as d,ye as e,ve as f,Ne as g};
|
|
1
|
+
import{e as T,f as I,g as L,h as D,i as E}from"./chunk.A4SJ7EEY.js";import{a as U}from"./chunk.DEZEXD24.js";import{c as w,e as _}from"./chunk.YZZGD5OY.js";import{a as A,b as N,c as C,e as R,l as M,m,n as V}from"./chunk.DSZ3I557.js";import{F as O,J as G,N as k,S as F}from"./chunk.RAE4M3KQ.js";var S=e=>{try{return e()}catch{return null}},X=e=>typeof e=="string"&&I.includes(e);function q(e){if(e!==void 0)return X(e)?e:e&&typeof e=="object"&&typeof e.expr=="string"?{expr:S(()=>w(e.expr))}:"neutral"}var Q=4;function ee(e){let n=typeof e.list=="string"?S(()=>w(e.list)):null,a=e.sort,r=typeof a=="string"?a:a&&typeof a=="object"&&typeof a.by=="string"?a.by:void 0,t=a&&typeof a=="object"?a.direction:void 0,o=n,i;if(n&&r!==void 0)if(t==="choices")i=r;else{let f=S(()=>w(r));o=f?{t:"call",fn:"sort",args:[n,f,{t:"lit",value:t==="desc"?"desc":"asc",at:0}],at:0}:null}let l=typeof e.limit=="number"&&Number.isInteger(e.limit)&&e.limit>=1?Math.min(e.limit,E):void 0,s=e.group,d=typeof s=="string"?s:s&&typeof s=="object"&&typeof s.by=="string"?s.by:void 0,y=s&&typeof s=="object"&&s.headings&&typeof s.headings=="object"?s.headings:{};return{t:"list",source:o,...i?{choiceOrder:i}:{},...l?{limit:l}:{},...d?{group:{by:d,headings:Object.fromEntries(Object.entries(y).filter(f=>typeof f[1]=="string"))}}:{},...typeof e.empty=="string"?{empty:e.empty}:{},as:e.as==="card"?"card":"row"}}function W(e,n=1,a=""){if(!Array.isArray(e)||n>Q)return[];let r={};return e.flatMap(t=>{if(!t||typeof t!="object"||Array.isArray(t))return[];let o=t,i=p=>typeof p=="string"?S(()=>_(p)):null,l=p=>typeof p=="string"?S(()=>w(p)):null,s=q(o.tone),d=typeof o.label=="string"?o.label:void 0,y=p=>Object.hasOwn(o,p),f=typeof o.currency=="string"&&/^[A-Z]{3}$/.test(o.currency)?o.currency:void 0,u=y("list")?"list":y("headline")?"headline":typeof o.figure=="string"?"number":ne.find(y);if(!u)return[];let x=r[u]=(r[u]??0)+1,j=o.key,B=typeof j=="string"&&j?j:`${a}${u}.${x}`;return[{...(()=>{switch(u){case"list":return ee(o);case"number":{let p=D.includes(o.as)?o.as:void 0;return{t:u,value:l(o.figure),...p?{as:p}:{},...f?{currency:f}:{},...d?{label:i(d)}:{}}}case"headline":case"title":return{t:u,parts:i(o[u])};case"text":case"badge":return{t:u,parts:i(o[u]),...s?{tone:s}:{}};case"field":{let p=L.includes(o.as)?o.as:void 0;return{t:u,field:String(o.field),...p?{as:p}:{},...f?{currency:f}:{},...d?{label:d}:{}}}case"progress":{let p=o.progress??{};return{t:u,value:l(p.value),max:l(p.max),...d?{label:i(d)}:{}}}case"group":return{t:u,blocks:W(o.group,n+1,`${B}.`),direction:o.direction==="row"?"row":"column"};case"when":return{t:u,when:l(o.when),show:W(o.show,n+1,`${B}.`)};default:return{t:u}}})(),key:B}]})}var ne=["title","text","badge","field","progress","group","when","divider","figure"],h="\u2014",re=500;function g(e,n){if(!e)return{ok:!1,problem:"an expression that does not parse"};try{return{ok:!0,value:R(e,{graph:n.graph??M,subject:n.node,kinds:n.kinds,today:n.today,budget:n.budget??re})}}catch(a){return{ok:!1,problem:a instanceof Error?a.message:String(a)}}}function b(e,n){if(!e)return{text:h,problem:"a template that does not parse"};let a,r=e.map(t=>{if(t.text!==void 0)return t.text;let o=g(t.expr??null,n);return o.ok?m(o.value,t.format,n.today,t.formatArgs,n.money):(a??=`{${t.source??""}}: ${o.problem}`,h)}).join("");return a?{text:r,problem:a}:{text:r}}function $(e,n){if(e===void 0)return;if(typeof e=="string")return e;let a=g(e.expr,n);return a.ok&&X(a.value)?a.value:"neutral"}function te(e){if(typeof e=="string")try{let n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"?n.href:void 0}catch{return}}function oe(e,n,a,r,t){if(n==null||n==="")return h;if(typeof n=="boolean")return n?"yes":"no";if(r)return m(n,r,a.today,[],t?{...a.money,currency:t}:a.money);let o=a.fields[e];return a.definition?.display?.format?.[e]?k(a.definition,e,n):o?.type==="date"?m(n,"date",a.today):o?.type==="enum"&&typeof n=="string"?k(a.definition,e,n):typeof n=="number"?n.toLocaleString("en-US"):Array.isArray(n)?n.map(i=>String(i)).join(", "):typeof n=="object"?h:String(n)}function ae(e,n,a,r,t){return typeof e!="number"?String(e):n==="money"?V(e,a?{...t,currency:a}:t):n==="percent"?m(e,n,r):e.toLocaleString("en-US",{maximumFractionDigits:2})}var c=(e,n)=>n?{...e,problem:n}:e;function se(e,n,a){switch(e.t){case"title":{let r=b(e.parts,n);return c({t:"title",text:r.text},r.problem)}case"text":{let r=b(e.parts,n),t=$(e.tone,n);return c({t:"text",text:r.text,...t?{tone:t}:{}},r.problem)}case"badge":{let r=b(e.parts,n);return c({t:"badge",text:r.text,tone:$(e.tone,n)??"neutral"},r.problem)}case"field":{let r=e.label??F(n.definition,e.field);if(!n.node)return{t:"field",field:e.field,label:r,text:h,problem:`"${e.field}" names a field, and these blocks are about no one record`};let t=n.kinds.get(n.node.kind)?.computed?.has(e.field),o,i;if(t){let d=g({t:"ident",name:e.field,at:0},n);d.ok?o=d.value!==null&&typeof d.value=="object"?m(d.value,void 0,n.today):d.value:i=d.problem}else o=Object.hasOwn(n.node,e.field)?n.node[e.field]:void 0;let l=n.fields[e.field]?.type==="url"&&e.as===void 0?te(o):void 0,s=S(()=>oe(e.field,o,n,e.as,e.currency))??h;return c({t:"field",field:e.field,label:r,text:s,...l?{href:l}:{}},i)}case"progress":{let r=g(e.value,n),t=g(e.max,n),o=e.label?b(e.label,n):{text:"Progress"},i=o.text,l=r.ok?t.ok?o.problem:t.problem:r.problem;return r.ok&&t.ok&&typeof r.value=="number"&&typeof t.value=="number"&&Number.isFinite(r.value)&&Number.isFinite(t.value)&&t.value>0?c({t:"progress",label:i,value:r.value,max:t.value,text:`${m(r.value,void 0,n.today)} of ${m(t.value,void 0,n.today)}`},l):c({t:"progress",label:i,text:h},l)}case"group":return{t:"group",direction:e.direction,blocks:H(e.blocks,n)};case"when":{let r=g(e.when,n),t=r.ok&&r.value===!0;return c({t:"when",shown:t,blocks:t?H(e.show,n):[]},r.ok?void 0:r.problem)}case"divider":return{t:"divider"};case"figure":return{t:"figure"};case"headline":{let r=b(e.parts,n),t=Math.min(6,Math.max(1,(a?n.firstHeading:void 0)??n.heading??3));return c({t:"headline",level:t,text:r.text},r.problem)}case"number":{let r=g(e.value,n),t=!r.ok||r.value===null||typeof r.value=="object"?h:ae(r.value,e.as,e.currency,n.today,n.money),o=e.label?b(e.label,n):void 0;return c({t:"number",text:t,...o?{label:o.text}:{}},r.ok?o?.problem:r.problem)}case"list":return de(e,n)}}function H(e,n){let a=e.findIndex(r=>r.t==="headline");return e.map((r,t)=>({...se(r,n,t===a),key:r.key}))}var ie=new Set(["every","some","sum","min","max","sort"]);function je(e,n){let a=new Set,r=new Set,t=s=>{if(s)switch(s.t){case"ident":a.add(s.name);return;case"list":s.items.forEach(t);return;case"member":return t(s.object);case"unary":return t(s.operand);case"binary":return t(s.left),t(s.right);case"where":return t(s.set);case"call":s.args.forEach((d,y)=>{y===1&&ie.has(s.fn)||t(d)});return;default:return}},o=s=>{for(let d of s??[])t(d.expr)},i=(s,d)=>{s.forEach((y,f)=>{let u=d[f];if(u)switch(y.t){case"field":a.add(y.field);return;case"title":case"text":case"badge":case"headline":o(y.parts);return;case"number":t(y.value),o(y.label);return;case"progress":t(y.value),t(y.max);return;case"group":u.t==="group"&&i(y.blocks,u.blocks);return;case"when":u.t==="when"&&u.shown&&i(y.show,u.blocks);return;case"list":if(u.t==="list")for(let x of u.members)r.add(x.id);return;default:return}})};i(e,n);let l=n[0];return{fields:a,records:r,...e[0]?.t==="title"&&l?.t==="title"?{title:l.text}:{}}}function de(e,n){let a=Math.min(6,(n.heading??3)+1),r=g(e.source,n);if(!r.ok)return{t:"list",as:e.as,failed:!0,members:[],headingLevel:a,more:0,problem:r.problem};let t=r.value,o=t instanceof A?t.nodes:t!==null&&typeof t=="object"&&!Array.isArray(t)?[t]:[];e.choiceOrder&&n.schema&&(o=le(o,e.choiceOrder,n.schema));let i=o.length;o=o.slice(0,e.limit??E);let l=e.limit===void 0?i-o.length:0;return{t:"list",as:e.as,failed:!1,members:o,...e.group&&n.schema&&o.length>0?{groups:ue(o,e.group,n.schema)}:{},headingLevel:a,...o.length===0&&e.empty?{empty:e.empty}:{},more:l}}function J(e,n,a){let r=e.tryDefinition(n)?.fields?.shape,t=r&&Object.hasOwn(r,a)?T(r[a]):void 0;return t?.type==="enum"?t.options??[]:[]}var P=(e,n)=>Object.hasOwn(e,n)?e[n]:void 0;function le(e,n,a){let r=t=>{let o=J(a,t.kind,n).indexOf(String(P(t,n)));return o<0?Number.MAX_SAFE_INTEGER:o};return e.map((t,o)=>({node:t,i:o,rank:r(t)})).sort((t,o)=>t.rank-o.rank||t.i-o.i).map(t=>t.node)}function ue(e,n,a){let r=[];for(let i of e)for(let l of J(a,i.kind,n.by))r.includes(l)||r.push(l);let t=[];for(let i of r){let l=e.filter(d=>P(d,n.by)===i);if(l.length===0)continue;let s=a.tryDefinition(l[0].kind);t.push({value:i,heading:n.headings[i]??O(k(s,n.by,i)),members:l})}let o=e.filter(i=>!r.includes(String(P(i,n.by))));return o.length>0&&t.push({value:null,members:o}),t}function K(e){return e.t==="list"||e.t==="headline"||e.t==="number"?!0:e.t==="group"?e.blocks.some(K):e.t==="when"?e.show.some(K):!1}function z(e,n){let a=e.tryDefinition(n)?.fields?.shape??{},r={};for(let[t,o]of Object.entries(a)){let i=T(o);i&&(r[t]=i)}return r}var Y=new WeakMap;function v(e){let n=Y.get(e);return n||Y.set(e,n=U(e)),n}function ye(e,n,a,r={}){let t=v(e),o={},i={},l=s=>{if(s instanceof A)return s.nodes.map(d=>l(d));if(Array.isArray(s))return s.map(d=>l(d));if(s!==null&&typeof s=="object"){let d=s;return{id:d.id,kind:d.kind,label:G(e.tryDefinition(d.kind),d)}}return s};for(let[s,d]of t.get(a?a.kind:N)?.computed??[])try{o[s]=l(R(d,{graph:n,subject:a,kinds:t,...r.today?{today:r.today}:{},...r.budget?{budget:r.budget}:{}}))}catch(y){if(!(y instanceof C))throw y;i[s]=y.sentence}return{values:o,refused:i}}function ve(e,n,a){let{values:r}=ye(e,n,a);if(Object.keys(r).length===0)return a;let t=o=>Array.isArray(o)?o.map(t):o!==null&&typeof o=="object"?o.label:o;return{...a,...Object.fromEntries(Object.entries(r).map(([o,i])=>[o,t(i)]))}}var pe=500,fe=2e4,Z=new WeakMap;function ce(e,n){let a=Z.get(e);a||Z.set(e,a=new Map);let r=a.get(n);return r||a.set(n,r=z(e,n)),r}function Ne(e,n,a,r={}){if(n&&typeof e.seenBy!="function")throw new TypeError("blockContextFor: a seat is read from a store (its `seenBy`); a bare { graph, schema } is read as it is handed, with no principal");let t=n?e.seenBy(n):e,o=n&&a?t.graph.getNode(a.id)??null:a,i=t.schema,l=o&&i.tryDefinition(o.kind),s=!o||(r.slot??"page")==="page",{money:d,firstHeading:y}=r;return{node:o,graph:t.graph,schema:i,kinds:v(i),fields:o?ce(i,o.kind):{},definition:l||void 0,today:r.today??t.today?.()??new Date().toISOString().slice(0,10),money:d,heading:r.heading??(s?2:3),firstHeading:y,budget:r.budget??(s?fe:pe)}}export{W as a,H as b,je as c,K as d,ye as e,ve as f,Ne as g};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as m}from"./chunk.
|
|
1
|
+
import{b as m}from"./chunk.F2KDFGHR.js";import{j as f}from"./chunk.ZRVDIVYY.js";import{Ba as T,ca as c,ea as b,ua as L,xa as R}from"./chunk.2WFEFZAW.js";import{M as A,X as I,Y as k,ka as x}from"./chunk.RAE4M3KQ.js";import{a as W,b as C}from"./chunk.MRK6QJV5.js";import{b as w}from"./chunk.AJZBJBMO.js";var u=w(W(),1);var e=w(C(),1);function z(i=4){let{store:n}=c(),p=b();return(0,u.useMemo)(()=>[...n.batches()].reverse().slice(0,i).map(a=>({intent:a.intent,author:a.author.kind,...a.author.id?{authorId:a.author.id}:{},by:a.author,...a.ops[0]?.via?{via:a.ops[0].via}:{},touched:[...new Set(a.ops.filter(o=>!x(o)).flatMap(o=>o.writes))],batch:a.id,...a.ops.every(x)?{withheld:!0}:{}})),[n,p,i])}function H({batch:i}){let{store:n,principal:p,noteSeat:a}=c(),o=b(),[h,y]=(0,u.useState)(null),l=(0,u.useMemo)(()=>n.canUndo(i),[n,i,o]);if(!l.ok&&l.ops.length===0)return null;let s=!l.ok,g=s?l.includeBatches:[];return(0,e.jsxs)("span",{style:{marginLeft:"auto",flex:"0 0 auto",display:"grid",justifyItems:"end",gap:2},children:[(0,e.jsx)("button",{type:"button","data-testid":"undo-turn",title:s?`${l.message} \u2014 undo those too`:"Take this back, keeping everything since",onClick:()=>{y(null);try{let d=n.log.all().find(t=>t.batch===i&&t.author.kind==="agent");n.undo(s?[i,...g]:i,{author:p}),d&&a({type:"home",author:d.author})}catch(d){y(d instanceof Error?d.message:String(d))}},style:{display:"inline-flex",alignItems:"center",minHeight:24,minWidth:24,padding:"1px 8px",fontSize:"0.75rem",...s?{borderColor:"var(--graview-warn)",color:"var(--graview-warn)"}:{}},children:s?`undo +${g.length}`:"undo"}),h?(0,e.jsx)("span",{"data-testid":"undo-refused",role:"alert",style:{fontSize:"0.75rem",lineHeight:1.4,color:"var(--graview-warn)",maxWidth:260,textAlign:"right"},children:h}):null]})}function O(){let i=()=>{let n=new URL(window.location.href);return n.searchParams.set("fresh","1"),n.toString()};return(0,e.jsx)("a",{href:"#fresh","data-testid":"start-fresh",title:"Forget every edit made in this browser and return to the example",onClick:n=>{n.preventDefault(),window.location.assign(i())},style:{display:"inline-flex",alignItems:"center",minHeight:24,minWidth:24,fontSize:"0.8125rem",color:"var(--graview-ink-muted)",textDecoration:"underline",textDecorationColor:"var(--graview-edge-bright)",textUnderlineOffset:3},children:"Start fresh"})}function N({calls:i,seat:n,remembers:p=!1}){let a=z(),{store:o,principal:h,seats:y,people:l}=c(),s=i.some(t=>t.phase==="running"),g=R("activity"),d=g.open;return n===void 0&&i.length===0&&a.length===0&&!p?null:(0,e.jsxs)("div",{style:{position:"relative"},children:[(0,e.jsxs)("button",{type:"button","data-testid":"activity-button",...g.trigger,onClick:g.toggle,title:s?"An agent is working":"What has happened",style:{display:"inline-flex",alignItems:"center",gap:6,minHeight:30,padding:"0 8px",borderRadius:8,border:"1px solid transparent",background:"transparent",boxShadow:"none",fontSize:"0.875rem",whiteSpace:"nowrap",color:s?"var(--graview-accent)":"var(--graview-ink-muted)"},children:[s?(0,e.jsx)("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:999,background:"var(--graview-accent)"}}):null,a.length>0?a.length:"",(0,e.jsxs)("svg",{className:"graview-activity-mark",width:"15",height:"15",viewBox:"0 0 16 16","aria-hidden":"true",focusable:"false",style:{display:"var(--graview-activity-mark, none)"},children:[(0,e.jsx)("circle",{cx:"8",cy:"8",r:"5.75",fill:"none",stroke:"currentColor",strokeWidth:"1.4"}),(0,e.jsx)("path",{d:"M8 4.75 V8 L10.25 9.5",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})]}),(0,e.jsx)("span",{className:"graview-activity-word",children:" Activity"})]}),!d&&n!==void 0?(0,e.jsx)("div",{hidden:!0,"data-testid":"agent-seat-seated",children:n}):null,d?(0,e.jsxs)("section",{...g.pane,"aria-label":"Activity","data-testid":"activity","data-graview-offstage":"",style:{...L,width:300,maxHeight:"min(52cqh, 460px)",overflow:"auto",display:"flex",flexDirection:"column",gap:9,padding:12,borderRadius:10,border:"1px solid var(--graview-edge)",background:"var(--graview-float)",boxShadow:"var(--graview-lift-high)"},children:[(0,e.jsx)("h2",{style:{...T,margin:0},children:"Activity"}),n!==void 0?(0,e.jsxs)("div",{"data-testid":"agent-seat-row",style:{display:"grid",gap:5,paddingBottom:i.length>0||a.length>0?9:0,...i.length>0||a.length>0?{borderBottom:"1px solid var(--graview-edge)"}:{}},children:[(0,e.jsx)("span",{style:{fontSize:"0.75rem",letterSpacing:"0.14em",textTransform:"uppercase",color:"var(--graview-ink-faint)"},children:"The agent's seat"}),n]}):null,i.length>0?(0,e.jsx)("ol",{style:{margin:0,padding:0,listStyle:"none",display:"grid",gap:7},children:i.slice(0,6).map((t,v)=>(0,e.jsxs)("li",{style:{display:"grid",gap:2,fontSize:"0.8125rem",lineHeight:1.45},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:6},children:[(0,e.jsx)("span",{"aria-hidden":"true",style:{width:6,height:6,borderRadius:999,flex:"0 0 auto",background:t.phase==="running"?"var(--graview-accent)":t.phase==="failed"?"var(--graview-warn)":"var(--graview-edge-bright)"}}),(0,e.jsxs)("span",{style:{color:"var(--graview-ink)"},children:[t.mutating?"changed":"read"," \xB7"," ",o.allMutations().find(r=>r.name===t.name)?.title??A(t.name)]})]}),!t.mutating&&t.reads&&t.reads.length>0?(0,e.jsxs)("div",{"data-testid":"activity-reads",style:{display:"flex",flexWrap:"wrap",gap:4,paddingLeft:12},children:[[...new Set(t.reads)].slice(0,3).map(r=>(0,e.jsx)(f,{label:m(o,r),pickId:r},r)),new Set(t.reads).size>3?(0,e.jsxs)("span",{style:{color:"var(--graview-ink-muted)"},children:["+",new Set(t.reads).size-3]}):null]}):Object.values(t.args).some(r=>typeof r=="string")?(0,e.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4,paddingLeft:12},children:Object.entries(t.args).filter(r=>typeof r[1]=="string").slice(0,3).map(([r,S])=>(0,e.jsx)(f,{label:m(o,S),pickId:S},r))}):null,t.error?(0,e.jsx)("div",{style:{paddingLeft:12,color:"var(--graview-warn)"},children:t.error}):null]},`${t.at}:${v}`))}):null,a.length>0?(0,e.jsx)("ol",{"data-testid":"diff-log",style:{margin:0,padding:0,listStyle:"none",display:"grid",gap:6,fontSize:"0.8125rem"},children:a.map((t,v)=>t.withheld?(0,e.jsx)("li",{"data-testid":"withheld-change",style:{display:"grid",gap:3,lineHeight:1.45},children:(0,e.jsx)("span",{"data-touched":"",style:{color:"var(--graview-ink-muted)",fontStyle:"italic"},children:t.intent})},`change:${v}`):(0,e.jsxs)("li",{style:{display:"grid",gap:3,lineHeight:1.45},children:[(0,e.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:6},children:[(0,e.jsxs)("span",{style:{minWidth:0},children:[(0,e.jsxs)("strong",{style:{fontWeight:600},children:[t.author==="human"&&t.by?.onBehalfOf===void 0&&(t.authorId===void 0||h.id===void 0||t.authorId===h.id)?"you":I(t.by??{kind:t.author,id:t.authorId},{graph:o.graph,schema:o.schema,seats:y,people:l}),k(t.via)?(0,e.jsxs)("span",{style:{fontWeight:400,color:"var(--graview-ink-muted)"},children:[", ",k(t.via)]}):null]})," ",(0,e.jsx)("span",{style:{color:"var(--graview-ink-muted)"},children:t.intent})]}),t.batch?(0,e.jsx)(H,{batch:t.batch}):null]}),(0,e.jsx)("div",{"data-touched":t.touched.join(" "),style:{display:"flex",flexWrap:"wrap",gap:4},children:t.touched.slice(0,4).map(r=>(0,e.jsx)(f,{label:m(o,r),pickId:r},r))})]},`change:${v}`))}):null,p?(0,e.jsxs)("div",{"data-testid":"remembered",style:{display:"flex",alignItems:"baseline",justifyContent:"space-between",gap:10,paddingTop:8,borderTop:"1px solid var(--graview-edge)",fontSize:"0.8125rem",color:"var(--graview-ink-faint)"},children:[(0,e.jsx)("span",{children:"Remembered in this browser"}),(0,e.jsx)(O,{})]}):null]}):null]})}export{N as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as U}from"./chunk.T6KID3WO.js";import{a as T,c as K,f as W,g as D,k as _,l as j,m as X}from"./chunk.6DU4XN2F.js";import{c as J}from"./chunk.MJ67MK4R.js";import{e as Q,g as Y,i as Z}from"./chunk.US4KIJSW.js";import{Aa as z,ca as G,ea as I,ma as V,ta as q}from"./chunk.2WFEFZAW.js";import{Hb as N,gb as H,qb as M,rb as O}from"./chunk.RAE4M3KQ.js";import{a as ae,b as $}from"./chunk.MRK6QJV5.js";import{b as F}from"./chunk.AJZBJBMO.js";var o=F(ae(),1);function se(e){let t=[e?.typography?.body,e?.typography?.display,e?.typography?.mono],n=[];for(let a of t){let r=a?.split(",")[0]?.trim().replace(/^["']|["']$/g,"");!r||O(r)||r.toLowerCase()!==H.toLowerCase()&&(n.includes(r)||n.push(r))}return n}function ee(e){let t=se(e);return t.length===0?null:`https://fonts.googleapis.com/css2?${t.map(a=>`family=${encodeURIComponent(a).replace(/%20/g,"+")}:wght@400;500;600;700`).join("&")}&display=swap`}var u=F($(),1);function ge(e,t){let{app:n}=e;return(0,o.useMemo)(()=>{let a=Y(t(n.schema,n.viewSpecs),n),r=e.views?V(a,e.views(n.schema,a)):a;return Z(r,n.schema,Q(e.brand??n.brand,n.schema)),r},[e.views,n.schema,n.viewSpecs,n.lenses,n.pages,n.home])}function ie(e,t){return new N({schema:e.schema,mutations:e.mutations??[],invariants:e.invariants??[],...t?{snapshot:t}:{},...e.policy?{policy:e.policy}:{},...e.intelligence?{intelligence:e.intelligence}:{}})}function ne(e){if(typeof document>"u")return e==="dark"?"dark":"light";let t=document.documentElement.dataset.theme;return t==="dark"||t==="light"?t:e==="dark"||e==="light"?e:typeof matchMedia=="function"&&matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function ce(e,t){let[n,a]=(0,o.useState)(()=>ne(t));return(0,o.useEffect)(()=>{if(!e||typeof document>"u")return;let r=()=>a(ne(t));r();let i=new MutationObserver(r);i.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});let d=typeof matchMedia=="function"?matchMedia("(prefers-color-scheme: dark)"):null;return d?.addEventListener?.("change",r),()=>{i.disconnect(),d?.removeEventListener?.("change",r)}},[e,t]),n}var A=e=>e?e.getBoundingClientRect().height:0;function be(e,t,n){let a=(0,o.useRef)(n);a.current=n;let r=n!==void 0;(0,o.useLayoutEffect)(()=>{let i=e.current;if(!i||!r)return;let d=()=>{let l=[...i.children],b=l.find(v=>v.hasAttribute("data-graview-app-bar")),p=l.find(v=>v.hasAttribute("data-embed-content")),f=p?.querySelector("[data-embed-measure]")??null,c=l.find(v=>v.hasAttribute("data-graview-place-line"));return{strip:b,line:c,content:p,measure:f}},s=-1,h=()=>{let{strip:l,line:b,content:p,measure:f}=d(),c=Math.ceil(A(l)+A(b)+A(f||p));c!==s&&(s=c,a.current?.(c))};if(h(),typeof ResizeObserver>"u")return;let m=new ResizeObserver(h),E=()=>{m.disconnect();let{strip:l,line:b,content:p,measure:f}=d();for(let c of[i,l,b,p,f])c&&m.observe(c)};E();let g=new MutationObserver(()=>{E(),h()});return g.observe(i,{childList:!0}),()=>{m.disconnect(),g.disconnect()}},[e,t,r])}var ve=480,de=0;function Se(e){let{app:t,seed:n,scheme:a="auto",brand:r=t.brand,fonts:i=!0,height:d="100%",label:s}=e,h=(0,o.useRef)(null);q(h);let m=d==="viewport"?"100dvh":d,E=z(typeof m=="string"&&/vh\b/.test(m)),g=(0,o.useMemo)(()=>`graview-embed-${++de}`,[]),l=(0,o.useMemo)(()=>e.store??e.remote?.store??ie(t,n),[e.store,e.remote,t,n]),b=e.presence??e.remote?.presence,p=e.hostContext?.theme,f=ce(a==="auto"&&p===void 0,r?.scheme),c=a==="auto"?p??f:a,v=(0,o.useMemo)(()=>T(c,r,{scope:`.${g}`}),[c,r,g]);K(e.favicon?M(r):void 0),(0,o.useEffect)(()=>{if(!i||typeof document>"u")return;let w=ee(r);if(!w||document.querySelector(`link[href="${w}"]`))return;let y=document.createElement("link");y.rel="stylesheet",y.href=w,document.head.appendChild(y)},[r,i]);let C=(0,o.useRef)(void 0);(0,o.useLayoutEffect)(()=>{let w=h.current,y=C.current;if(C.current=s,!w||!s)return;let oe=S=>{let x=S.getAttribute("aria-label")??"",R=y&&y!==s?x.startsWith(`${y} \xB7 `)?x.slice(y.length+3):x===y?"":x:x;R===s&&(S.getAttribute("role")==="region"||S.tagName==="SECTION"&&!S.hasAttribute("role"))&&S.setAttribute("role","group");let L=R.startsWith(`${s} \xB7 `)||R===s?R:R?`${s} \xB7 ${R}`:s;L!==x&&S.setAttribute("aria-label",L)},B=()=>w.querySelectorAll("aside, nav, main, header, footer, section[aria-label]:not([role]), [role=region], [role=complementary], [role=navigation], [role=search]").forEach(S=>{S.hasAttribute("data-graview-named-by-lens")||oe(S)});B();let P=new MutationObserver(B);return P.observe(w,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["aria-label"]}),()=>P.disconnect()},[s]);let re=E?`${m}`.replace(/([\d.]+)[sdl]?vh\b/g,(w,y)=>`${+y*E/100}px`):m;return{rootRef:h,scope:g,css:v,scheme:c,store:l,presence:b,brand:r,auto:d==="auto",height:re}}function we({rootRef:e,board:t}){let n=(0,o.useCallback)(()=>e.current?.querySelector("[data-embed-content]")??e.current,[e]);return(0,u.jsx)(J,{board:t,anchor:n})}function Ee(e,t,n){return{brand:n,principal:e.principal,seats:e.seats,presence:t,people:e.people,memory:e.memory,presenceTtlMs:e.presenceTtlMs,onKeepLens:e.onKeepLens,ai:e.ai,app:e.app}}function xe({name:e,heading:t,faces:n,at:a,without:r,home:i,reach:d,standing:s,hostActions:h,keeping:m,onFind:E,switch:g}){let{brand:l,store:b,principal:p,views:f}=G();I();let c=r?.has("places")?[]:W({store:b,principal:p,views:f}),v=U();return(0,u.jsx)(_,{brand:l,name:e,description:l?.subtitle,heading:t,faces:n,home:i,places:c,current:a===null?null:D(c,a),reach:d,onFind:E,...g?{switch:g}:{},...n?{scenePlaces:v}:{},tools:(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(X,{clean:s}),(0,u.jsx)(j,{...h?{hostActions:h}:{},...m?{keeping:m}:{}})]})})}var Re=e=>e===!1?2:Math.min(e+1,6);function Ae(e){let[t,n]=(0,o.useState)(e),a=(0,o.useRef)(void 0),r=(0,o.useRef)(void 0),i=(0,o.useMemo)(()=>({go:a,at:n,pending:r}),[]),d=(0,o.useCallback)(s=>{if(a.current){a.current(s);return}r.current=s,n(s)},[]);return{at:t,setAt:n,steering:i,steer:d}}function le(e){let t=typeof e=="object"&&e!==null?e.name:void 0;return{name:typeof t=="string"&&t.length>0?t:typeof e=="object"?"Error":typeof e}}var k=()=>typeof performance<"u"?performance.now():Date.now();function Fe(e,t){let n=(0,o.useRef)({onError:e,face:t});return n.current={onError:e,face:t},(0,o.useCallback)((a,r)=>n.current.onError?.(le(a),{module:r.module,face:n.current.face}),[])}function ke(e,t){let n=(0,o.useRef)(null);n.current===null&&(n.current=k());let a=(0,o.useRef)({onReady:e,face:t});a.current={onReady:e,face:t};let r=(0,o.useRef)(!1);return(0,o.useCallback)(i=>{r.current||(r.current=!0,a.current.onReady?.({ms:Math.max(0,k()-(n.current??k())),face:i}))},[])}var te=class extends o.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(t,n){console.error(`[graview] ${this.props.module} threw while rendering`,t,n.componentStack),this.props.report(t,{module:this.props.module})}render(){return this.state.failed?(0,u.jsxs)("div",{role:"alert","data-graview-face-error":this.props.module,...this.props.content?{"data-embed-content":""}:{},style:this.props.content?{flex:"1 1 auto",display:"grid",alignContent:"center",justifyItems:"center",gap:8,padding:24,background:"var(--graview-ground)",color:"var(--graview-ink)",fontSize:"0.9375rem"}:{display:"inline-flex",alignItems:"center",gap:6,fontSize:"0.8125rem",color:"var(--graview-ink-muted)"},children:[(0,u.jsx)("span",{children:this.props.content?"This part of the app could not draw.":"Could not draw."}),(0,u.jsx)("button",{type:"button",onClick:()=>this.setState({failed:!1}),style:{padding:"3px 11px",fontSize:"0.8125rem"},children:"Try again"})]}):this.props.children}};export{ge as a,ie as b,be as c,ve as d,Se as e,we as f,Ee as g,xe as h,Re as i,Ae as j,Fe as k,ke as l,te as m};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as je}from"./chunk.HH6WIUK3.js";import{a as Ve,c as Fe,d as Ie}from"./chunk.GDIRDJF3.js";import{d as Be}from"./chunk.FRNIWOKD.js";import{b as Ge,e as G,f as ve}from"./chunk.42U4UBDE.js";import{b as ze}from"./chunk.D3CYTXNZ.js";import{d as ge,e as qe,f as ye,h as _e}from"./chunk.MYCTNK6D.js";import{a as De}from"./chunk.NRWJ6PLU.js";import{b as We}from"./chunk.6O67NOZR.js";import{C as Ee,E as Ne,G as He,T as Ke,U as Oe,W as oe,ca as q,d as Le,j as I,l as W,m as _,pa as re,r as j,s as Re,y as Pe,z as Me}from"./chunk.2VX6H2LL.js";import{I as $e,Na as ne,O as Te,Oa as me,P as te,Qa as Ae,Ra as Ce}from"./chunk.ZQ4HFIIS.js";import{a as U,b as ae}from"./chunk.MRK6QJV5.js";import{b as O}from"./chunk.AJZBJBMO.js";var Je=O(U(),1);function Qe(e,t){try{t.length===0?localStorage.removeItem(ge(e)):localStorage.setItem(ge(e),JSON.stringify(t))}catch{}}function ct(e,t){Qe(e,[...ye(e).filter(r=>r.title!==t.title),t])}function pt(e,t){Qe(e,ye(e).filter(r=>r.title!==t))}function ut(e,t){for(let r of e.places().filter(a=>a.title===t))e.forget?.(r.kind,r.as)}var ft=e=>e===!0?{written:!0}:typeof e=="object"&&e!==null?{written:e.kept===!0,...e.said?{said:e.said}:{}}:{written:!1},Ue=e=>({title:e.title,lens:e.lens,on:e.on,...e.bindings?{bindings:e.bindings}:{},...e.options?{options:e.options}:{}});function mt(e,t){let r=a=>t.some(s=>s.title===a||s.as===ne(a));if(!r(e))return e;for(let a=2;;a++)if(!r(`${e} ${a}`))return`${e} ${a}`}function Ye(e){let{store:t,views:r,brand:a,seatTalk:s,onKeepLens:y}=q(),k=(0,Je.useContext)(ze),S=qe(a,t.schema),M=async c=>{let{edit:p}=c;if(c.written&&y)try{await y({op:"remove-lens",title:p.title,on:p.on})}catch{}pt(S,p.title),ut(r,p.title),k?.dismiss(`kept:${p.title}`),s.setTurns(g=>[...g.map(i=>i.kept&&i.kept.edit.title===p.title&&!i.kept.taken?{...i,kept:{...i.kept,taken:!0}}:i),{role:"seat",text:`Took \u201C${p.title}\u201D back out of the places.`}]);let l=te(t.schema,p.on);e({to:"kind",kind:p.on,title:l,address:me(t.schema,p.on),said:`Went to ${l}.`})};return{keep:async c=>{let p=mt(c.edit.title,r.places()),l={...c.edit,title:p},g=!1,i;if(y)try{({written:g,said:i}=ft(await y(l)))}catch{g=!1}g||ct(S,Ue(l)),_e(r,t.schema,[Ue(l)]);let f=r.places(),h=f.find(w=>w.title===p),x=i??(g?`Kept \u201C${p}\u201D as a lens: it is in the places now.`:y?`Kept \u201C${p}\u201D as your own lens. Ask the owner to keep it for everyone.`:`Kept \u201C${p}\u201D as your own lens.`),T={edit:l,written:g};s.setDraft(null),s.setTurns(w=>[...w,{role:"seat",text:x,kept:T}]),s.get().open||k?.notify({kind:"toast",id:`kept:${p}`,sentence:x,timeout:1e4,action:{label:"Take back",onSelect:()=>void M(T)}}),h&&e({to:"picture",kind:h.kind,as:h.as,title:p,address:Ae(h.as,Ce(h,f)?me(t.schema,h.kind).slice(1):void 0),said:`Went to ${p}.`})},takeBack:M}}var Ze=O(U(),1);function gt(e,t){switch(t.to){case"place":return{view:Le("#")};case"picture":return{view:j(He(W(e,"filter",null),t.kind,t.as),[])};case"kind":{let r=Re(_({...I(e,Ee(t.kind)),relation:null},!1),!0);return{view:j(W(W(r,"view",null),"filter",t.filter??null),[])}}case"record":return{view:j(I(_(W(W(e,"view",null),"filter",null),!1),t.id),[t.id])};case"problems":return{pane:"problems"}}}function yt(e){let t=typeof document>"u"?null:document.querySelector('[data-testid="standing"]');t&&t.getAttribute("aria-expanded")==="true"!==e&&t.click()}function Xe(){let{setView:e,seatTalk:t}=q();return(0,Ze.useCallback)(r=>{t.get().draft&&t.setDraft(null),yt(r.to==="problems"),r.to!=="problems"&&e(a=>{let s=gt(a,r);return"view"in s?s.view:a})},[e,t])}var se=O(U(),1),vt=220;function ht(e,t){if(!e||!t||typeof document>"u")return null;let r=e.getBoundingClientRect(),a=document.elementFromPoint(r.left+t.x,r.top+t.y),s=a?.closest("[data-graview-pick]")?.getAttribute("data-graview-pick");return s||(a?.closest("[data-graview-view]")?.getAttribute("data-graview-view")??null)}function et({hover:e=!0}={}){let{store:t,view:r,views:a,pointer:s}=q(),{selection:y}=re(),[k,S]=(0,se.useState)(null);(0,se.useEffect)(()=>{if(!e)return;let l=null,g=!1,i=()=>typeof document<"u"&&document.querySelector("[data-graview-reach]")!==null?document.querySelector("[data-graview-settled]")===null:!1,f=()=>{if(l&&clearTimeout(l),g)return;let w=s.snapshot();if(!w){S(R=>R===null?R:null);return}l=setTimeout(()=>{if(g||i()){f();return}let R=typeof document>"u"?null:document.querySelector("[data-graview-stage]"),C=ht(R,w);S(P=>P===C?P:C)},vt)},h=()=>{g=!0,l&&clearTimeout(l)},x=()=>{g=!1,f()},T=s.subscribe(f);return document.addEventListener("pointerdown",h,!0),document.addEventListener("pointerup",x,!0),document.addEventListener("pointercancel",x,!0),f(),()=>{T(),document.removeEventListener("pointerdown",h,!0),document.removeEventListener("pointerup",x,!0),document.removeEventListener("pointercancel",x,!0),l&&clearTimeout(l)}},[s,e]);let M=l=>{let g=t.graph.getNode(l);if(g)return $e(t.schema.tryDefinition(g.kind),g);let i=je(l,t.schema);if(i)return i;let f=Me(l);if(f)return te(t.schema,f);let h=Ne(l);if(h.length>0){let x=h.map(w=>Te(t.schema,w)),T=x.length===1?x[0]:`${x.slice(0,-1).join(", ")} and ${x.at(-1)}`;return T.charAt(0).toUpperCase()+T.slice(1)}return null},E=y[y.length-1];if(E!==void 0){let l=M(E);if(l)return{id:E,name:y.length>1?`${l} and ${y.length-1} more`:l,because:"selection"}}if(k!=null){let l=M(k);if(l)return{id:k,name:l,because:"hover"}}let c=r.within?.view,p=c?a.places().find(l=>l.as===c||ne(l.title)===c):void 0;if(p)return{id:null,name:p.title,because:"place"};if(r.focusId){let l=M(r.focusId);if(l)return{id:r.focusId,name:l,because:"place"}}return{id:null,name:"the whole thing",because:"place"}}var L=O(U(),1);var D=O(U(),1),$=O(ae(),1),B=(e,t)=>`${e}:${t}`;function tt({answer:e,onReply:t,talk:r}){let[a]=(0,D.useState)(()=>Oe(null)),s=r??a,{turns:y,outcomes:k,busy:S}=oe(s),M=(0,D.useCallback)((c,p)=>s.settle(c,p),[s]);return{turns:y,outcomes:k,busy:S,send:async c=>{let p=c.trim();if(!p||s.get().busy)return;s.setBusy(!0);let l=s.get();s.setTurns(f=>[...f,{role:"person",text:p}]);let g=l.turns.map((f,h)=>{let x=(f.proposals??[]).flatMap((T,w)=>{let R=l.outcomes.get(B(h,w));return R?.state==="applied"?[R.said]:[]});return{role:f.role,text:x.length>0?`${f.text} [applied: ${x.join("; ")}]`:f.text}}),i;try{i=await e(p,{history:g})}catch(f){i={say:`That couldn't be answered: ${f instanceof Error?f.message:String(f)}`,proposals:[]}}s.setTurns(f=>[...f,{role:"seat",text:i.say,proposals:i.proposals,...i.questions?{questions:i.questions}:{},...i.picks?.length?{picks:i.picks}:{},...i.moves?.length?{moves:i.moves}:{},...i.offer?{offer:i.offer}:{},...i.unsure?{unsure:!0}:{},...i.via?{via:i.via}:{}}]),t?.(i),s.setBusy(!1)},settle:M}}var wt=e=>{let t=/^([\s\S]*?)\s*(\((?:[^()]|\([^()]*\))*\))\s*$/.exec(e);return t&&t[1]?{said:t[1],aside:t[2]}:{said:e}};function nt({turns:e,outcomes:t,busy:r,testId:a,empty:s,minHeight:y=64,maxHeight:k="min(46cqh, 400px)",renderProposal:S,renderAfter:M,renderSaid:E,ready:c=()=>!0,onApplyAll:p,applyAllLabel:l="Apply all"}){let g=(0,D.useRef)(null);return(0,D.useEffect)(()=>{g.current?.scrollTo?.({top:g.current.scrollHeight})},[e]),e.length===0&&s===null&&!r?null:(0,$.jsxs)("ol",{ref:g,style:{margin:0,padding:10,listStyle:"none",display:"grid",gap:8,alignContent:"start",maxHeight:k,minHeight:y,overflowY:"auto"},children:[e.length===0?s===null?null:(0,$.jsx)("li",{style:{fontSize:"0.8125rem",color:"var(--graview-ink-muted)",lineHeight:1.5},children:s}):null,e.map((i,f)=>{let h=i.proposals??[],x=h.filter((w,R)=>{let C=B(f,R),P=t.get(C);return P?.state!=="applied"&&P?.state!=="declined"&&c(w,C)}),T=wt(i.text);return(0,$.jsxs)("li",{style:{display:"grid",gap:6,justifyItems:i.role==="person"?"end":"start"},children:[i.role==="person"?(0,$.jsx)("p",{style:{margin:0,maxWidth:"85%",padding:"6px 10px",borderRadius:"12px 12px 4px 12px",fontSize:"0.875rem",lineHeight:1.45,background:"var(--graview-panel-muted)",color:"var(--graview-ink)"},children:i.text}):(0,$.jsxs)("p",{style:{margin:0,fontSize:"0.875rem",lineHeight:1.5,color:"var(--graview-ink)"},children:[E?E(i,T.said):T.said,T.aside?(0,$.jsx)("span",{style:{display:"block",marginTop:2,fontSize:"0.75rem",color:"var(--graview-ink-faint)"},children:T.aside}):null,i.via?(0,$.jsx)("span",{"data-testid":`${a}-answered-with-ai`,style:{display:"block",marginTop:2,fontSize:"0.75rem",color:"var(--graview-ink-faint)"},children:Ke}):null]}),M?.(i,f),h.map((w,R)=>{let C=B(f,R),P=t.get(C);return P?.state==="applied"||P?.state==="declined"?(0,$.jsx)(ie,{outcome:P,testId:a},C):(0,$.jsxs)("span",{style:{display:"grid",gap:4,justifySelf:"stretch",justifyItems:"start"},children:[S(w,{key:C,turn:f,at:R}),P?(0,$.jsx)(ie,{outcome:P,testId:a}):null]},C)}),p&&x.length>=2?(0,$.jsxs)("button",{type:"button","data-testid":`${a}-apply-all`,onClick:()=>p(f,h),title:"Take these in order; anything still missing is asked for",style:{fontSize:"0.8125rem",justifySelf:"start",fontWeight:600},children:[l," ",x.length]}):null]},f)}),r?(0,$.jsx)("li",{style:{fontSize:"0.8125rem",color:"var(--graview-ink-faint)"},children:"thinking\u2026"}):null]})}function ie({outcome:e,testId:t}){if(e.state==="refused")return(0,$.jsxs)("span",{"data-testid":`${t}-refused`,style:{fontSize:"0.8125rem",color:"var(--graview-warn)"},children:["Refused: ",e.error]});let r=e.state==="applied";return(0,$.jsxs)("span",{"data-testid":`${t}-${e.state}`,style:{fontSize:"0.8125rem",color:r?"var(--graview-ink-muted)":"var(--graview-ink-faint)"},children:[r?(0,$.jsx)("span",{"aria-hidden":"true",style:{color:"var(--graview-accent)"},children:"\u2713 "}):null,r?e.said:(0,$.jsx)("s",{children:e.said})]})}function ot({busy:e,placeholder:t,ariaLabel:r,testId:a,onSend:s}){let[y,k]=(0,D.useState)("");return(0,$.jsxs)("form",{onSubmit:S=>{S.preventDefault(),!(e||y.trim().length===0)&&(s(y),k(""))},style:{display:"flex",gap:6,padding:8,borderTop:"1px solid var(--graview-edge)"},children:[(0,$.jsx)("input",{value:y,onChange:S=>k(S.target.value),placeholder:t,"aria-label":r,"data-testid":`${a}-draft`,style:{flex:1,minWidth:0,font:"inherit",fontSize:"0.875rem",padding:"6px 9px",borderRadius:8,border:"1px solid var(--graview-edge)",background:"var(--graview-panel)",color:"var(--graview-ink)"}}),(0,$.jsx)("button",{type:"submit","data-testid":`${a}-send`,disabled:e||y.trim().length===0,style:{fontSize:"0.875rem"},children:"Send"})]})}var v=O(ae(),1),bt=/\b(?:board|kanban|timeline|calendar|gantt|who covers|covers what|coverage|floor plan|layout|draw|chart|(?:list|table) of|as an? (?:list|table|board|calendar|timeline|grid))\b/i,kt=/\b(?:group(?:ed)? by|split by|sort(?:ed)? by|order(?:ed)? by|only|call it|name it|as an? (?:board|kanban|calendar|timeline|list|table|cards|rows|grid|plan|layout)|show all|all of them|clear the filter|no filter)\b/i,St=e=>e.charAt(0).toLowerCase()+e.slice(1),xt=e=>e.to==="record"?e.label:e.to==="problems"?"problems":e.title;function $t(e,t,r){let a=[],s=e;for(let y of t){let k=xt(y),S=k?s.toLowerCase().indexOf(k.toLowerCase()):-1;S<0||(a.push(s.slice(0,S),r(y,s.slice(S,S+k.length))),s=s.slice(S+k.length))}return a.length===0?e:[...a,s]}function Qt({respond:e,onCall:t,onPick:r,testId:a="chat",empty:s,shared:y=!1,composer:k=!0,onMove:S,place:M,onDraft:E}){let{store:c,views:p,view:l,principal:g,setView:i,seatWho:f,noteSeat:h,session:x,ai:T,seatTalk:w,brand:R,app:C}=q(),P=Xe(),le=S??P,{takeBack:rt}=Ye(le),{selection:de}=re(),he=et(),we=f??"chat",z=(0,L.useMemo)(()=>({kind:"agent",id:we,session:x}),[we,x]),ce=(0,L.useRef)(void 0),V=(0,L.useMemo)(()=>Be(c,{author:{...z,...g.roles?{roles:g.roles}:{}},derive:()=>({pins:Ve()}),places:()=>p.places(),via:()=>ce.current,...C?{app:C}:{}}),[c,g,z,p,C]),st=(0,L.useMemo)(()=>e??Ie(T),[e,T]);(0,L.useEffect)(()=>t?V.onCall(t):void 0,[V,t]),We(V);let be=(0,L.useMemo)(()=>({name:R?.name??"app",schema:c.schema,...c.policy?{policy:c.policy}:{}}),[c,R]),it=async o=>{let d=w.get().draft,n=d!==null&&kt.test(o);if(!n&&!bt.test(o))return;let u=await import("./chunk.OXODTBOP.js"),b=e?void 0:Fe(T),m={app:be,sight:u.draftSight(be,Y),...b?{complete:b}:{},...d?{lastGood:d}:{}},A=n&&d?await u.refineDraft(d,o,m):await u.draftView(o,m);if(u.isDraftFailure(A)){let K=A.lastGood??d;return K?(w.setDraft(K,A.failed),E?.(),{say:`${A.failed} The last view stays.`,proposals:[],grounded:!0}):{say:A.failed,proposals:[],grounded:!0}}return w.setDraft(A,null),E?.(),{say:`Here is ${St(A.said)} Ask to change it, or keep it as a lens.`,proposals:[],grounded:!0}},N=tt({...y?{talk:w}:{},answer:async(o,d)=>{let n=await it(o);if(n)return n;let{placesFromViews:u}=await import("./chunk.BNSY25SG.js"),b=M??l.within?.view,m=p.arrangement?.(),A=c.today();return st(c,o,{...d,selection:he.id?[he.id]:de,principal:{...z,...g.roles?{roles:g.roles}:{}},places:u(c.schema,p.places(),m?{pages:m}:{}),...b?{place:b}:{},...A?{today:A}:{},...C?{app:C}:{}})},onReply:o=>{let d=o.moves?.[0];d&&le(d);let n=o.questions?.[0];h(n?{type:"asking",author:z,where:n.nodeId??null,say:`${n.nodeLabel?`${n.nodeLabel}: `:""}${n.asks}`,confidence:n.confidence}:{type:"said",author:z,say:o.say});let u=o.proposals.find(b=>!ue(b));if(u){let b=c.permits({name:u.mutation,args:{...u.args}},Y);b.ok||h({type:"refused",author:z,where:Se(u.mutation),say:b.refusal.message})}}}),{outcomes:Q,settle:pe}=N,ke=oe(w);(0,L.useEffect)(()=>{if(!y||ke.pending===null||N.busy)return;let o=w.takePending();o&&N.send(o)},[y,ke.pending,N.busy]);let Y={...z,...g.roles?{roles:g.roles}:{}},ue=o=>c.permits({name:o.mutation,args:{...o.args}},Y).ok,Se=o=>{let d=c.allMutations().find(n=>n.name===o)?.subject?.kinds;return Array.isArray(d)&&d[0]?Pe(d[0]):null},[H,Z]=(0,L.useState)(null),X=async(o,d)=>{let n=Ge(c,o),u=G(c,n),b=V.definitions.find(A=>A.act===n.mutation)?.name??n.mutation;ce.current=N.turns[Number(d.split(":")[0])]?.via;let m=await V.call(b,{...n.args}).finally(()=>{ce.current=void 0});return m.ok?(pe(d,{state:"applied",said:u}),!0):(pe(d,{state:"refused",error:m.error}),h({type:"refused",author:z,where:Se(n.mutation),say:m.error}),!1)},lt=async(o,d)=>{for(let[n,u]of d.entries()){let b=B(o,n);if(Q.get(b)?.state==="applied"||!ue(u))continue;let m=ve(c,u);if(m.length>0){Z({proposal:u,open:m,key:b});return}if(!await X(u,b))return}},ee=(0,L.useRef)(null),fe=(0,L.useRef)(null);(0,L.useLayoutEffect)(()=>{let o=fe.current;if(!o||o.isConnected||document.activeElement!==document.body)return;fe.current=null,(ee.current?.querySelector(`[data-testid="${a}-apply"]:not([disabled])`)??ee.current?.querySelector(`[data-testid="${a}-draft"]`)??ee.current?.closest("[data-testid='seat']")?.querySelector("[data-testid='seat-field']"))?.focus()});let dt=(o,d,n,u)=>{let b=c.permits({name:n.mutation,args:{...n.args}},Y);if(!b.ok)return(0,v.jsxs)("span",{"data-testid":`${a}-withheld`,style:{fontSize:"0.8125rem",color:"var(--graview-ink-muted)"},children:[(0,v.jsx)("s",{children:G(c,n)})," \u2014 ",b.refusal.message]});let m=ve(c,n),A=(N.turns[o]?.proposals??[]).slice(0,d).filter((xe,F)=>Q.get(B(o,F))?.state!=="applied").find(xe=>m.some(F=>F.kinds&&typeof n.args[F.name]=="string"&&xe.args.label===n.args[F.name])),K=G(c,n);return(0,v.jsxs)("span",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"4px 10px"},children:[(0,v.jsxs)("span",{style:{fontSize:"0.875rem",color:"var(--graview-ink)"},title:n.why,children:[K,m.length>0&&!A?" \u2026":""]}),(0,v.jsxs)("span",{style:{display:"inline-flex",gap:6},children:[(0,v.jsx)("button",{type:"button","data-testid":`${a}-apply`,"data-graview-asks":m.length>0?m.length:void 0,disabled:A!==void 0,"aria-label":`Do it: ${K}`,onClick:()=>m.length>0?Z({proposal:n,open:m,key:u}):void X(n,u),title:A?`After \u201C${G(c,A)}\u201D`:m.length>0?`${K} \u2014 it asks for ${m.length===1?"one more thing":`${m.length} more things`}`:K,style:J,children:"Do it"}),(0,v.jsx)("button",{type:"button","data-testid":`${a}-decline`,"aria-label":`Not now: ${K}`,onClick:()=>pe(u,{state:"declined",said:K}),style:{...J,color:"var(--graview-ink-muted)"},children:"Not now"})]})]})};return(0,v.jsxs)("div",{"data-testid":`${a}-panel`,ref:ee,onFocus:o=>{fe.current=o.target},style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr)",alignContent:"start",gap:8,minWidth:0,minHeight:0},children:[N.turns.length===0?s??null:null,(0,v.jsx)(nt,{turns:N.turns,outcomes:Q,busy:N.busy,testId:a,minHeight:0,maxHeight:"none",empty:s!==void 0?null:(0,v.jsxs)(v.Fragment,{children:["Ask what's wrong, ask about anything by name, or say a change in its own words.",de.length>0?" \u201CThis\u201D means what you have selected.":""]}),renderProposal:(o,{key:d,turn:n,at:u})=>dt(n,u,o,d),ready:o=>ue(o),onApplyAll:(o,d)=>void lt(o,d),applyAllLabel:"Do all",renderSaid:(o,d)=>o.moves?.length?$t(d,o.moves,(n,u)=>(0,v.jsx)("button",{type:"button","data-testid":`${a}-went`,title:`Go to ${u}`,onClick:()=>le(n),style:{...at,fontSize:"inherit"},children:u},`${n.address}:${u}`)):d,renderAfter:(o,d)=>[...o.offer?[(0,v.jsx)("button",{type:"button","data-testid":`${a}-offer`,onClick:()=>w.ask(`a list of ${o.offer.draft}`),style:{...J,justifySelf:"start"},children:o.offer.label},`${d}:offer`)]:[],...o.kept&&!o.kept.taken?[(0,v.jsx)("button",{type:"button","data-testid":`${a}-take-back`,onClick:()=>void rt(o.kept),style:{...J,justifySelf:"start"},children:"Take back"},`${d}:take-back`)]:[],...o.picks?.length?[(0,v.jsx)("p",{"data-testid":`${a}-picks`,style:{margin:0,display:"flex",flexWrap:"wrap",gap:"2px 12px"},children:o.picks.map(n=>(0,v.jsx)("button",{type:"button","data-testid":`${a}-pick`,"data-chat-pick":n.id,title:n.why.field==="label"?`Go to ${n.label}`:`${n.why.reading}: ${n.why.fragment}`,onClick:()=>r?r(n.id):i(u=>j(I(_(u,!1),n.id),[n.id])),style:at,children:n.label},n.id))},`${d}:picks`)]:[],...(o.questions??[]).map(n=>{let u=`${d}:q:${n.id}`,b=Q.get(u);return(0,v.jsxs)("div",{"data-testid":`${a}-question`,"data-chat-question-node":n.nodeId,style:{display:"grid",gap:4,justifySelf:"start"},children:[(0,v.jsxs)("span",{style:{fontSize:"0.8125rem",color:"var(--graview-ink-muted)"},children:[n.nodeLabel?(0,v.jsxs)("strong",{children:[n.nodeLabel,": "]}):null,n.asks,n.because==="split"?" (it could be either)":" (it was not sure)"]}),(0,v.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:n.options.map(m=>(0,v.jsxs)("button",{type:"button","data-testid":`${a}-option`,disabled:!m.call,title:m.call?m.call.why??"Take this answer":"Nothing to do for this answer",onClick:()=>m.call?void X(m.call,u):void 0,style:J,children:[m.value," ",Math.round(m.probability*100),"%"]},m.value))}),b?(0,v.jsx)(ie,{outcome:b,testId:a}):null]},n.id)})]}),H?(0,v.jsx)("div",{"data-testid":`${a}-asking`,children:(0,v.jsx)(De,{affordance:{id:`chat:${H.proposal.mutation}`,mutation:H.proposal.mutation,label:G(c,H.proposal),provider:"llm",why:H.proposal.why??"Suggested in the conversation.",nodeIds:[],args:H.proposal.args,open:H.open,score:0},onApply:o=>{let d={...H.proposal,args:{...H.proposal.args,...o}};Z(null),X(d,H.key)},onCancel:()=>Z(null)})}):null,k?(0,v.jsx)(ot,{busy:N.busy,placeholder:de.length>0?"Ask about this\u2026":"Ask, or say a change\u2026",ariaLabel:"Ask",testId:a,onSend:o=>y?w.ask(o):void N.send(o)}):null]})}var J={font:"inherit",fontSize:"0.8125rem",minHeight:26,padding:"0 9px",borderRadius:6,border:"1px solid var(--graview-edge)",background:"var(--graview-panel)",boxShadow:"none",color:"var(--graview-ink)",cursor:"pointer"},at={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"};export{Ye as a,yt as b,Xe as c,et as d,Qt as e,J as f,at as g};
|
|
1
|
+
import{a as je}from"./chunk.H4LHHT56.js";import{a as Ve,c as Fe,d as Ie}from"./chunk.EKZWX6NG.js";import{d as Be}from"./chunk.TTODVIXW.js";import{b as Ge,e as G,f as ve}from"./chunk.WX5CJ7PI.js";import{b as ze}from"./chunk.MJ67MK4R.js";import{d as ge,e as qe,f as ye,h as _e}from"./chunk.US4KIJSW.js";import{a as De}from"./chunk.F2KDFGHR.js";import{b as We}from"./chunk.2YVXTTC2.js";import{C as Ee,E as Ne,G as He,T as Ke,U as Oe,W as oe,ca as q,d as Le,j as I,l as W,m as _,pa as re,r as j,s as Re,y as Pe,z as Me}from"./chunk.2WFEFZAW.js";import{Ia as ne,J as $e,Ja as me,La as Ae,Ma as Ce,P as Te,Q as te}from"./chunk.RAE4M3KQ.js";import{a as U,b as ae}from"./chunk.MRK6QJV5.js";import{b as O}from"./chunk.AJZBJBMO.js";var Je=O(U(),1);function Qe(e,t){try{t.length===0?localStorage.removeItem(ge(e)):localStorage.setItem(ge(e),JSON.stringify(t))}catch{}}function ct(e,t){Qe(e,[...ye(e).filter(r=>r.title!==t.title),t])}function pt(e,t){Qe(e,ye(e).filter(r=>r.title!==t))}function ut(e,t){for(let r of e.places().filter(a=>a.title===t))e.forget?.(r.kind,r.as)}var ft=e=>e===!0?{written:!0}:typeof e=="object"&&e!==null?{written:e.kept===!0,...e.said?{said:e.said}:{}}:{written:!1},Ue=e=>({title:e.title,lens:e.lens,on:e.on,...e.bindings?{bindings:e.bindings}:{},...e.options?{options:e.options}:{}});function mt(e,t){let r=a=>t.some(s=>s.title===a||s.as===ne(a));if(!r(e))return e;for(let a=2;;a++)if(!r(`${e} ${a}`))return`${e} ${a}`}function Ye(e){let{store:t,views:r,brand:a,seatTalk:s,onKeepLens:y}=q(),k=(0,Je.useContext)(ze),S=qe(a,t.schema),M=async c=>{let{edit:p}=c;if(c.written&&y)try{await y({op:"remove-lens",title:p.title,on:p.on})}catch{}pt(S,p.title),ut(r,p.title),k?.dismiss(`kept:${p.title}`),s.setTurns(g=>[...g.map(i=>i.kept&&i.kept.edit.title===p.title&&!i.kept.taken?{...i,kept:{...i.kept,taken:!0}}:i),{role:"seat",text:`Took \u201C${p.title}\u201D back out of the places.`}]);let l=te(t.schema,p.on);e({to:"kind",kind:p.on,title:l,address:me(t.schema,p.on),said:`Went to ${l}.`})};return{keep:async c=>{let p=mt(c.edit.title,r.places()),l={...c.edit,title:p},g=!1,i;if(y)try{({written:g,said:i}=ft(await y(l)))}catch{g=!1}g||ct(S,Ue(l)),_e(r,t.schema,[Ue(l)]);let f=r.places(),h=f.find(w=>w.title===p),x=i??(g?`Kept \u201C${p}\u201D as a lens: it is in the places now.`:y?`Kept \u201C${p}\u201D as your own lens. Ask the owner to keep it for everyone.`:`Kept \u201C${p}\u201D as your own lens.`),T={edit:l,written:g};s.setDraft(null),s.setTurns(w=>[...w,{role:"seat",text:x,kept:T}]),s.get().open||k?.notify({kind:"toast",id:`kept:${p}`,sentence:x,timeout:1e4,action:{label:"Take back",onSelect:()=>void M(T)}}),h&&e({to:"picture",kind:h.kind,as:h.as,title:p,address:Ae(h.as,Ce(h,f)?me(t.schema,h.kind).slice(1):void 0),said:`Went to ${p}.`})},takeBack:M}}var Ze=O(U(),1);function gt(e,t){switch(t.to){case"place":return{view:Le("#")};case"picture":return{view:j(He(W(e,"filter",null),t.kind,t.as),[])};case"kind":{let r=Re(_({...I(e,Ee(t.kind)),relation:null},!1),!0);return{view:j(W(W(r,"view",null),"filter",t.filter??null),[])}}case"record":return{view:j(I(_(W(W(e,"view",null),"filter",null),!1),t.id),[t.id])};case"problems":return{pane:"problems"}}}function yt(e){let t=typeof document>"u"?null:document.querySelector('[data-testid="standing"]');t&&t.getAttribute("aria-expanded")==="true"!==e&&t.click()}function Xe(){let{setView:e,seatTalk:t}=q();return(0,Ze.useCallback)(r=>{t.get().draft&&t.setDraft(null),yt(r.to==="problems"),r.to!=="problems"&&e(a=>{let s=gt(a,r);return"view"in s?s.view:a})},[e,t])}var se=O(U(),1),vt=220;function ht(e,t){if(!e||!t||typeof document>"u")return null;let r=e.getBoundingClientRect(),a=document.elementFromPoint(r.left+t.x,r.top+t.y),s=a?.closest("[data-graview-pick]")?.getAttribute("data-graview-pick");return s||(a?.closest("[data-graview-view]")?.getAttribute("data-graview-view")??null)}function et({hover:e=!0}={}){let{store:t,view:r,views:a,pointer:s}=q(),{selection:y}=re(),[k,S]=(0,se.useState)(null);(0,se.useEffect)(()=>{if(!e)return;let l=null,g=!1,i=()=>typeof document<"u"&&document.querySelector("[data-graview-reach]")!==null?document.querySelector("[data-graview-settled]")===null:!1,f=()=>{if(l&&clearTimeout(l),g)return;let w=s.snapshot();if(!w){S(R=>R===null?R:null);return}l=setTimeout(()=>{if(g||i()){f();return}let R=typeof document>"u"?null:document.querySelector("[data-graview-stage]"),C=ht(R,w);S(P=>P===C?P:C)},vt)},h=()=>{g=!0,l&&clearTimeout(l)},x=()=>{g=!1,f()},T=s.subscribe(f);return document.addEventListener("pointerdown",h,!0),document.addEventListener("pointerup",x,!0),document.addEventListener("pointercancel",x,!0),f(),()=>{T(),document.removeEventListener("pointerdown",h,!0),document.removeEventListener("pointerup",x,!0),document.removeEventListener("pointercancel",x,!0),l&&clearTimeout(l)}},[s,e]);let M=l=>{let g=t.graph.getNode(l);if(g)return $e(t.schema.tryDefinition(g.kind),g);let i=je(l,t.schema);if(i)return i;let f=Me(l);if(f)return te(t.schema,f);let h=Ne(l);if(h.length>0){let x=h.map(w=>Te(t.schema,w)),T=x.length===1?x[0]:`${x.slice(0,-1).join(", ")} and ${x.at(-1)}`;return T.charAt(0).toUpperCase()+T.slice(1)}return null},E=y[y.length-1];if(E!==void 0){let l=M(E);if(l)return{id:E,name:y.length>1?`${l} and ${y.length-1} more`:l,because:"selection"}}if(k!=null){let l=M(k);if(l)return{id:k,name:l,because:"hover"}}let c=r.within?.view,p=c?a.places().find(l=>l.as===c||ne(l.title)===c):void 0;if(p)return{id:null,name:p.title,because:"place"};if(r.focusId){let l=M(r.focusId);if(l)return{id:r.focusId,name:l,because:"place"}}return{id:null,name:"the whole thing",because:"place"}}var L=O(U(),1);var D=O(U(),1),$=O(ae(),1),B=(e,t)=>`${e}:${t}`;function tt({answer:e,onReply:t,talk:r}){let[a]=(0,D.useState)(()=>Oe(null)),s=r??a,{turns:y,outcomes:k,busy:S}=oe(s),M=(0,D.useCallback)((c,p)=>s.settle(c,p),[s]);return{turns:y,outcomes:k,busy:S,send:async c=>{let p=c.trim();if(!p||s.get().busy)return;s.setBusy(!0);let l=s.get();s.setTurns(f=>[...f,{role:"person",text:p}]);let g=l.turns.map((f,h)=>{let x=(f.proposals??[]).flatMap((T,w)=>{let R=l.outcomes.get(B(h,w));return R?.state==="applied"?[R.said]:[]});return{role:f.role,text:x.length>0?`${f.text} [applied: ${x.join("; ")}]`:f.text}}),i;try{i=await e(p,{history:g})}catch(f){i={say:`That couldn't be answered: ${f instanceof Error?f.message:String(f)}`,proposals:[]}}s.setTurns(f=>[...f,{role:"seat",text:i.say,proposals:i.proposals,...i.questions?{questions:i.questions}:{},...i.picks?.length?{picks:i.picks}:{},...i.moves?.length?{moves:i.moves}:{},...i.offer?{offer:i.offer}:{},...i.unsure?{unsure:!0}:{},...i.via?{via:i.via}:{}}]),t?.(i),s.setBusy(!1)},settle:M}}var wt=e=>{let t=/^([\s\S]*?)\s*(\((?:[^()]|\([^()]*\))*\))\s*$/.exec(e);return t&&t[1]?{said:t[1],aside:t[2]}:{said:e}};function nt({turns:e,outcomes:t,busy:r,testId:a,empty:s,minHeight:y=64,maxHeight:k="min(46cqh, 400px)",renderProposal:S,renderAfter:M,renderSaid:E,ready:c=()=>!0,onApplyAll:p,applyAllLabel:l="Apply all"}){let g=(0,D.useRef)(null);return(0,D.useEffect)(()=>{g.current?.scrollTo?.({top:g.current.scrollHeight})},[e]),e.length===0&&s===null&&!r?null:(0,$.jsxs)("ol",{ref:g,style:{margin:0,padding:10,listStyle:"none",display:"grid",gap:8,alignContent:"start",maxHeight:k,minHeight:y,overflowY:"auto"},children:[e.length===0?s===null?null:(0,$.jsx)("li",{style:{fontSize:"0.8125rem",color:"var(--graview-ink-muted)",lineHeight:1.5},children:s}):null,e.map((i,f)=>{let h=i.proposals??[],x=h.filter((w,R)=>{let C=B(f,R),P=t.get(C);return P?.state!=="applied"&&P?.state!=="declined"&&c(w,C)}),T=wt(i.text);return(0,$.jsxs)("li",{style:{display:"grid",gap:6,justifyItems:i.role==="person"?"end":"start"},children:[i.role==="person"?(0,$.jsx)("p",{style:{margin:0,maxWidth:"85%",padding:"6px 10px",borderRadius:"12px 12px 4px 12px",fontSize:"0.875rem",lineHeight:1.45,background:"var(--graview-panel-muted)",color:"var(--graview-ink)"},children:i.text}):(0,$.jsxs)("p",{style:{margin:0,fontSize:"0.875rem",lineHeight:1.5,color:"var(--graview-ink)"},children:[E?E(i,T.said):T.said,T.aside?(0,$.jsx)("span",{style:{display:"block",marginTop:2,fontSize:"0.75rem",color:"var(--graview-ink-faint)"},children:T.aside}):null,i.via?(0,$.jsx)("span",{"data-testid":`${a}-answered-with-ai`,style:{display:"block",marginTop:2,fontSize:"0.75rem",color:"var(--graview-ink-faint)"},children:Ke}):null]}),M?.(i,f),h.map((w,R)=>{let C=B(f,R),P=t.get(C);return P?.state==="applied"||P?.state==="declined"?(0,$.jsx)(ie,{outcome:P,testId:a},C):(0,$.jsxs)("span",{style:{display:"grid",gap:4,justifySelf:"stretch",justifyItems:"start"},children:[S(w,{key:C,turn:f,at:R}),P?(0,$.jsx)(ie,{outcome:P,testId:a}):null]},C)}),p&&x.length>=2?(0,$.jsxs)("button",{type:"button","data-testid":`${a}-apply-all`,onClick:()=>p(f,h),title:"Take these in order; anything still missing is asked for",style:{fontSize:"0.8125rem",justifySelf:"start",fontWeight:600},children:[l," ",x.length]}):null]},f)}),r?(0,$.jsx)("li",{style:{fontSize:"0.8125rem",color:"var(--graview-ink-faint)"},children:"thinking\u2026"}):null]})}function ie({outcome:e,testId:t}){if(e.state==="refused")return(0,$.jsxs)("span",{"data-testid":`${t}-refused`,style:{fontSize:"0.8125rem",color:"var(--graview-warn)"},children:["Refused: ",e.error]});let r=e.state==="applied";return(0,$.jsxs)("span",{"data-testid":`${t}-${e.state}`,style:{fontSize:"0.8125rem",color:r?"var(--graview-ink-muted)":"var(--graview-ink-faint)"},children:[r?(0,$.jsx)("span",{"aria-hidden":"true",style:{color:"var(--graview-accent)"},children:"\u2713 "}):null,r?e.said:(0,$.jsx)("s",{children:e.said})]})}function ot({busy:e,placeholder:t,ariaLabel:r,testId:a,onSend:s}){let[y,k]=(0,D.useState)("");return(0,$.jsxs)("form",{onSubmit:S=>{S.preventDefault(),!(e||y.trim().length===0)&&(s(y),k(""))},style:{display:"flex",gap:6,padding:8,borderTop:"1px solid var(--graview-edge)"},children:[(0,$.jsx)("input",{value:y,onChange:S=>k(S.target.value),placeholder:t,"aria-label":r,"data-testid":`${a}-draft`,style:{flex:1,minWidth:0,font:"inherit",fontSize:"0.875rem",padding:"6px 9px",borderRadius:8,border:"1px solid var(--graview-edge)",background:"var(--graview-panel)",color:"var(--graview-ink)"}}),(0,$.jsx)("button",{type:"submit","data-testid":`${a}-send`,disabled:e||y.trim().length===0,style:{fontSize:"0.875rem"},children:"Send"})]})}var v=O(ae(),1),bt=/\b(?:board|kanban|timeline|calendar|gantt|who covers|covers what|coverage|floor plan|layout|draw|chart|(?:list|table) of|as an? (?:list|table|board|calendar|timeline|grid))\b/i,kt=/\b(?:group(?:ed)? by|split by|sort(?:ed)? by|order(?:ed)? by|only|call it|name it|as an? (?:board|kanban|calendar|timeline|list|table|cards|rows|grid|plan|layout)|show all|all of them|clear the filter|no filter)\b/i,St=e=>e.charAt(0).toLowerCase()+e.slice(1),xt=e=>e.to==="record"?e.label:e.to==="problems"?"problems":e.title;function $t(e,t,r){let a=[],s=e;for(let y of t){let k=xt(y),S=k?s.toLowerCase().indexOf(k.toLowerCase()):-1;S<0||(a.push(s.slice(0,S),r(y,s.slice(S,S+k.length))),s=s.slice(S+k.length))}return a.length===0?e:[...a,s]}function Qt({respond:e,onCall:t,onPick:r,testId:a="chat",empty:s,shared:y=!1,composer:k=!0,onMove:S,place:M,onDraft:E}){let{store:c,views:p,view:l,principal:g,setView:i,seatWho:f,noteSeat:h,session:x,ai:T,seatTalk:w,brand:R,app:C}=q(),P=Xe(),le=S??P,{takeBack:rt}=Ye(le),{selection:de}=re(),he=et(),we=f??"chat",z=(0,L.useMemo)(()=>({kind:"agent",id:we,session:x}),[we,x]),ce=(0,L.useRef)(void 0),V=(0,L.useMemo)(()=>Be(c,{author:{...z,...g.roles?{roles:g.roles}:{}},derive:()=>({pins:Ve()}),places:()=>p.places(),via:()=>ce.current,...C?{app:C}:{}}),[c,g,z,p,C]),st=(0,L.useMemo)(()=>e??Ie(T),[e,T]);(0,L.useEffect)(()=>t?V.onCall(t):void 0,[V,t]),We(V);let be=(0,L.useMemo)(()=>({name:R?.name??"app",schema:c.schema,...c.policy?{policy:c.policy}:{}}),[c,R]),it=async o=>{let d=w.get().draft,n=d!==null&&kt.test(o);if(!n&&!bt.test(o))return;let u=await import("./chunk.R6F3YMRK.js"),b=e?void 0:Fe(T),m={app:be,sight:u.draftSight(be,Y),...b?{complete:b}:{},...d?{lastGood:d}:{}},A=n&&d?await u.refineDraft(d,o,m):await u.draftView(o,m);if(u.isDraftFailure(A)){let K=A.lastGood??d;return K?(w.setDraft(K,A.failed),E?.(),{say:`${A.failed} The last view stays.`,proposals:[],grounded:!0}):{say:A.failed,proposals:[],grounded:!0}}return w.setDraft(A,null),E?.(),{say:`Here is ${St(A.said)} Ask to change it, or keep it as a lens.`,proposals:[],grounded:!0}},N=tt({...y?{talk:w}:{},answer:async(o,d)=>{let n=await it(o);if(n)return n;let{placesFromViews:u}=await import("./chunk.ACKTGTOT.js"),b=M??l.within?.view,m=p.arrangement?.(),A=c.today();return st(c,o,{...d,selection:he.id?[he.id]:de,principal:{...z,...g.roles?{roles:g.roles}:{}},places:u(c.schema,p.places(),m?{pages:m}:{}),...b?{place:b}:{},...A?{today:A}:{},...C?{app:C}:{}})},onReply:o=>{let d=o.moves?.[0];d&&le(d);let n=o.questions?.[0];h(n?{type:"asking",author:z,where:n.nodeId??null,say:`${n.nodeLabel?`${n.nodeLabel}: `:""}${n.asks}`,confidence:n.confidence}:{type:"said",author:z,say:o.say});let u=o.proposals.find(b=>!ue(b));if(u){let b=c.permits({name:u.mutation,args:{...u.args}},Y);b.ok||h({type:"refused",author:z,where:Se(u.mutation),say:b.refusal.message})}}}),{outcomes:Q,settle:pe}=N,ke=oe(w);(0,L.useEffect)(()=>{if(!y||ke.pending===null||N.busy)return;let o=w.takePending();o&&N.send(o)},[y,ke.pending,N.busy]);let Y={...z,...g.roles?{roles:g.roles}:{}},ue=o=>c.permits({name:o.mutation,args:{...o.args}},Y).ok,Se=o=>{let d=c.allMutations().find(n=>n.name===o)?.subject?.kinds;return Array.isArray(d)&&d[0]?Pe(d[0]):null},[H,Z]=(0,L.useState)(null),X=async(o,d)=>{let n=Ge(c,o),u=G(c,n),b=V.definitions.find(A=>A.act===n.mutation)?.name??n.mutation;ce.current=N.turns[Number(d.split(":")[0])]?.via;let m=await V.call(b,{...n.args}).finally(()=>{ce.current=void 0});return m.ok?(pe(d,{state:"applied",said:u}),!0):(pe(d,{state:"refused",error:m.error}),h({type:"refused",author:z,where:Se(n.mutation),say:m.error}),!1)},lt=async(o,d)=>{for(let[n,u]of d.entries()){let b=B(o,n);if(Q.get(b)?.state==="applied"||!ue(u))continue;let m=ve(c,u);if(m.length>0){Z({proposal:u,open:m,key:b});return}if(!await X(u,b))return}},ee=(0,L.useRef)(null),fe=(0,L.useRef)(null);(0,L.useLayoutEffect)(()=>{let o=fe.current;if(!o||o.isConnected||document.activeElement!==document.body)return;fe.current=null,(ee.current?.querySelector(`[data-testid="${a}-apply"]:not([disabled])`)??ee.current?.querySelector(`[data-testid="${a}-draft"]`)??ee.current?.closest("[data-testid='seat']")?.querySelector("[data-testid='seat-field']"))?.focus()});let dt=(o,d,n,u)=>{let b=c.permits({name:n.mutation,args:{...n.args}},Y);if(!b.ok)return(0,v.jsxs)("span",{"data-testid":`${a}-withheld`,style:{fontSize:"0.8125rem",color:"var(--graview-ink-muted)"},children:[(0,v.jsx)("s",{children:G(c,n)})," \u2014 ",b.refusal.message]});let m=ve(c,n),A=(N.turns[o]?.proposals??[]).slice(0,d).filter((xe,F)=>Q.get(B(o,F))?.state!=="applied").find(xe=>m.some(F=>F.kinds&&typeof n.args[F.name]=="string"&&xe.args.label===n.args[F.name])),K=G(c,n);return(0,v.jsxs)("span",{style:{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"4px 10px"},children:[(0,v.jsxs)("span",{style:{fontSize:"0.875rem",color:"var(--graview-ink)"},title:n.why,children:[K,m.length>0&&!A?" \u2026":""]}),(0,v.jsxs)("span",{style:{display:"inline-flex",gap:6},children:[(0,v.jsx)("button",{type:"button","data-testid":`${a}-apply`,"data-graview-asks":m.length>0?m.length:void 0,disabled:A!==void 0,"aria-label":`Do it: ${K}`,onClick:()=>m.length>0?Z({proposal:n,open:m,key:u}):void X(n,u),title:A?`After \u201C${G(c,A)}\u201D`:m.length>0?`${K} \u2014 it asks for ${m.length===1?"one more thing":`${m.length} more things`}`:K,style:J,children:"Do it"}),(0,v.jsx)("button",{type:"button","data-testid":`${a}-decline`,"aria-label":`Not now: ${K}`,onClick:()=>pe(u,{state:"declined",said:K}),style:{...J,color:"var(--graview-ink-muted)"},children:"Not now"})]})]})};return(0,v.jsxs)("div",{"data-testid":`${a}-panel`,ref:ee,onFocus:o=>{fe.current=o.target},style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr)",alignContent:"start",gap:8,minWidth:0,minHeight:0},children:[N.turns.length===0?s??null:null,(0,v.jsx)(nt,{turns:N.turns,outcomes:Q,busy:N.busy,testId:a,minHeight:0,maxHeight:"none",empty:s!==void 0?null:(0,v.jsxs)(v.Fragment,{children:["Ask what's wrong, ask about anything by name, or say a change in its own words.",de.length>0?" \u201CThis\u201D means what you have selected.":""]}),renderProposal:(o,{key:d,turn:n,at:u})=>dt(n,u,o,d),ready:o=>ue(o),onApplyAll:(o,d)=>void lt(o,d),applyAllLabel:"Do all",renderSaid:(o,d)=>o.moves?.length?$t(d,o.moves,(n,u)=>(0,v.jsx)("button",{type:"button","data-testid":`${a}-went`,title:`Go to ${u}`,onClick:()=>le(n),style:{...at,fontSize:"inherit"},children:u},`${n.address}:${u}`)):d,renderAfter:(o,d)=>[...o.offer?[(0,v.jsx)("button",{type:"button","data-testid":`${a}-offer`,onClick:()=>w.ask(`a list of ${o.offer.draft}`),style:{...J,justifySelf:"start"},children:o.offer.label},`${d}:offer`)]:[],...o.kept&&!o.kept.taken?[(0,v.jsx)("button",{type:"button","data-testid":`${a}-take-back`,onClick:()=>void rt(o.kept),style:{...J,justifySelf:"start"},children:"Take back"},`${d}:take-back`)]:[],...o.picks?.length?[(0,v.jsx)("p",{"data-testid":`${a}-picks`,style:{margin:0,display:"flex",flexWrap:"wrap",gap:"2px 12px"},children:o.picks.map(n=>(0,v.jsx)("button",{type:"button","data-testid":`${a}-pick`,"data-chat-pick":n.id,title:n.why.field==="label"?`Go to ${n.label}`:`${n.why.reading}: ${n.why.fragment}`,onClick:()=>r?r(n.id):i(u=>j(I(_(u,!1),n.id),[n.id])),style:at,children:n.label},n.id))},`${d}:picks`)]:[],...(o.questions??[]).map(n=>{let u=`${d}:q:${n.id}`,b=Q.get(u);return(0,v.jsxs)("div",{"data-testid":`${a}-question`,"data-chat-question-node":n.nodeId,style:{display:"grid",gap:4,justifySelf:"start"},children:[(0,v.jsxs)("span",{style:{fontSize:"0.8125rem",color:"var(--graview-ink-muted)"},children:[n.nodeLabel?(0,v.jsxs)("strong",{children:[n.nodeLabel,": "]}):null,n.asks,n.because==="split"?" (it could be either)":" (it was not sure)"]}),(0,v.jsx)("div",{style:{display:"flex",flexWrap:"wrap",gap:4},children:n.options.map(m=>(0,v.jsxs)("button",{type:"button","data-testid":`${a}-option`,disabled:!m.call,title:m.call?m.call.why??"Take this answer":"Nothing to do for this answer",onClick:()=>m.call?void X(m.call,u):void 0,style:J,children:[m.value," ",Math.round(m.probability*100),"%"]},m.value))}),b?(0,v.jsx)(ie,{outcome:b,testId:a}):null]},n.id)})]}),H?(0,v.jsx)("div",{"data-testid":`${a}-asking`,children:(0,v.jsx)(De,{affordance:{id:`chat:${H.proposal.mutation}`,mutation:H.proposal.mutation,label:G(c,H.proposal),provider:"llm",why:H.proposal.why??"Suggested in the conversation.",nodeIds:[],args:H.proposal.args,open:H.open,score:0},onApply:o=>{let d={...H.proposal,args:{...H.proposal.args,...o}};Z(null),X(d,H.key)},onCancel:()=>Z(null)})}):null,k?(0,v.jsx)(ot,{busy:N.busy,placeholder:de.length>0?"Ask about this\u2026":"Ask, or say a change\u2026",ariaLabel:"Ask",testId:a,onSend:o=>y?w.ask(o):void N.send(o)}):null]})}var J={font:"inherit",fontSize:"0.8125rem",minHeight:26,padding:"0 9px",borderRadius:6,border:"1px solid var(--graview-edge)",background:"var(--graview-panel)",boxShadow:"none",color:"var(--graview-ink)",cursor:"pointer"},at={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"};export{Ye as a,yt as b,Xe as c,et as d,Qt as e,J as f,at as g};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{g as a}from"./chunk.
|
|
1
|
+
import{g as a}from"./chunk.YZZGD5OY.js";import{b as s}from"./chunk.DSZ3I557.js";function f(e){let r=new Map;for(let i of e.kinds){let n=e.tryDefinition(i),o=a(n);r.set(i,{fields:new Set(Object.keys(n?.fields?.shape??{})),edges:new Map(Object.entries(n?.edges??{}).map(([d,p])=>[d,p.cardinality??"many"])),...o?{computed:o}:{}})}let t=a(e);return t&&r.set(s,{computed:t}),r}export{f as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as Ve}from"./chunk.6KJSFIO7.js";import{b as Ce,c as te,d as Ie,e as W,g as le,h as Ke,o as J}from"./chunk.WOTNMTIY.js";import{F as Ee,S as ze,Y as De,Z as $e,a as me,b as he,c as we,d as H,da as Pe,f as se,fa as Ge,g as C,gb as Te,h as ke,i as be,j as ne,k as ve,l as Oe,la as ce,ma as Me,n as Ae,o as Re,p as ae,qb as Fe,rb as Ne,u as je,va as Z,w as de,x as xe,z as Se}from"./chunk.ZQ4HFIIS.js";function tn(n,c){let e=n.brand??{},i=e.accent?Ne(e.accent):void 0;i&&!i.ok&&c.push(Ke("brand","brand.accent",`that accent cannot make a readable brand, so the app keeps Graview's colors: ${i.why}`,"pick a color further from orange-red, or a darker one"));let l=typeof e.logo=="string"?{src:e.logo}:e.logo,d=e.name??n.name,O=e.typography?Object.fromEntries(Object.entries(e.typography).filter(([,R])=>typeof R=="string"&&!/url\(|@import|[;{}<>\\]/i.test(R)).map(([R,E])=>[R,Fe(E)])):void 0;return{name:d,schemes:i?.ok?i.schemes:Te,...e.currency?{currency:e.currency}:{},...e.locale?{locale:e.locale}:{},...l?{logo:l.src,logoAlt:l.alt??d}:{},...e.favicon?{favicon:e.favicon}:{},...n.description?{subtitle:n.description}:{},...O?{typography:O}:{},...e.shape?{shape:e.shape}:{},...e.accents?{accents:e.accents}:{},...e.scheme?{scheme:e.scheme}:{}}}function Le(n){let{currency:c,locale:e}=n.brand??{};return{...c?{currency:c}:{},...e?{locale:e}:{}}}var He=[{where:"settings[]",was:"honoured",now:"honored",since:"0.1.16"},{where:"pages",was:"overview",now:"scene",since:"0.1.17"}],pe=n=>typeof n=="object"&&n!==null&&!Array.isArray(n);function qe(n,c=He){if(!pe(n))return{document:n,respelled:[]};let e=[],i=n;for(let l of c)i=fe(i,l.where.split("."),l,"",e);return{document:i,respelled:e}}function fe(n,c,e,i,l){if(c.length===0){if(!pe(n)||!Object.hasOwn(n,e.was))return n;l.push(`${i}${e.was}`);let{[e.was]:G,...z}=n;return Object.hasOwn(n,e.now)?z:{...z,[e.now]:G}}if(!pe(n))return n;let[d,...O]=c,R=d.endsWith("[]"),E=R?d.slice(0,-2):d,j=n[E],P=j;if(!R)P=fe(j,O,e,`${i}${E}.`,l);else if(Array.isArray(j)){let G=j.map((z,M)=>fe(z,O,e,`${i}${E}.${M}.`,l));P=G.some((z,M)=>z!==j[M])?G:j}return P===j?n:{...n,[E]:P}}var Be="graview-compiled@1",I="id",Ze=n=>typeof n=="string"&&/^\$[A-Za-z][A-Za-z0-9]*$/.test(n)?n.slice(1):void 0;function We(n){let c=Object.entries(n.fields);return c.find(([,e])=>e.required&&(e.type==="string"||e.type==="text"))?.[0]??c.find(([,e])=>e.type==="string")?.[0]}function _e(n,c){let e;switch(n.type){case"string":e=C().check(H(500));break;case"text":e=C().check(H(2e4));break;case"number":case"integer":{let i=[...n.type==="integer"?[ve()]:[],...n.min===void 0?[]:[he(n.min)],...n.max===void 0?[]:[me(n.max)],...n.step===void 0?[]:[we(n.step)]];e=i.length>0?ne().check(...i):ne();break}case"boolean":e=Oe();break;case"date":e=C().check(se(/^\d{4}-\d{2}-\d{2}$/,"a date like 2026-10-02"));break;case"datetime":e=C().check(xe(i=>!Number.isNaN(Date.parse(i)),"a date and time like 2026-10-02T14:30:00Z"));break;case"enum":e=je(n.options);break;case"list":e=Re(n.of==="number"?ne():n.of==="date"?C().check(se(/^\d{4}-\d{2}-\d{2}$/)):C().check(H(500))).check(H(200));break;case"url":e=be();break;case"email":e=ke();break}return n.description&&(e=e.check(Se(n.description))),c?de(e):e}var U=n=>{throw new Z(`there is no record "${n}"`,"invalid")},Je=n=>"field"in n?_e(n.field,n.optional):"ref"in n?Ge(n.ref):de(Ae()),Ue=new WeakMap;var re=n=>typeof n=="object"&&n!==null&&!Array.isArray(n),ye=(n,c)=>re(c)&&Object.keys(n??{}).length===Object.keys(c).length&&Object.keys(n??{}).every(e=>Object.hasOwn(c,e));function mn(n,c={}){let e=re(n)?n.format:void 0;if(e!==Be)return{ok:!1,findings:[le("compiled-format","format",e===void 0?"this is not a compiled Graview app":`this compiled app is ${JSON.stringify(e)}, and this build reads ${Be}`,"compile the document instead")]};let i=n,l=qe(i.document).document,d=l===i.document?i:{...i,document:l},O=re(l)&&typeof l.name=="string"&&re(l.kinds)&&ye(l.kinds,d.kinds)&&ye(l.acts,d.acts)&&ye(l.rules,d.rules)&&Array.isArray(d.edges)&&Array.isArray(d.findings),R={ok:!1,findings:[le("compiled-shape","","this compiled app's parts do not match its document","compile the document instead")]};if(!O)return R;try{return Qe(d,c)}catch{return R}}function Qe(n,c={}){let{document:e}=n,i=c.today??(()=>new Date().toISOString().slice(0,10)),l=new Map(n.edges.map(([f,r])=>[f,r])),d=new Map;for(let[f,r]of Object.entries(e.kinds)){let k=n.kinds[f]?.computed;d.set(f,{fields:new Set(Object.keys(r.fields)),edges:new Map(Object.entries(r.edges??{}).map(([w,x])=>[w,x.cardinality??"many"])),...k?{computed:new Map(k)}:{}})}n.facts&&d.set(Ce,{computed:new Map(n.facts)});let O=Le(e),R=Object.entries(e.kinds).map(([f,r])=>{let k={};for(let[o,y]of Object.entries(r.fields))k[o]=_e(y,!y.required);let{label:w,describe:x}=n.kinds[f]??{},D=Object.entries(r.computed??{}).map(([o,y])=>[o,typeof y=="string"?{expr:y}:y]),S=Object.fromEntries([...Object.entries(r.fields).filter(([,o])=>o.label).map(([o,y])=>[o,y.label]),...D.filter(([,o])=>o.label).map(([o,y])=>[o,y.label])]),T=Object.fromEntries(Object.entries(r.fields).filter(([,o])=>o.default!==void 0).map(([o,y])=>[o,y.default])),K=Object.fromEntries(Object.entries(r.edges??{}).map(([o,{renamedFrom:y,...V}])=>[o,V])),g=o=>r[o]?{[o]:r[o]}:{};return Ee(f,{fields:ae(k),edges:K,...g("plural"),...g("noun"),...g("description"),...w?{label:o=>J(w,{node:o,kinds:d,today:i(),money:O})||o.id}:{},...x?{describe:o=>J(x,{node:o,kinds:d,today:i(),money:O})}:{},...g("lifecycle"),...g("figure"),...g("fieldRoles"),...r.computed&&Object.keys(r.computed).length>0?{computed:r.computed}:{},...Object.keys(S).length>0||r.glance||r.page?{display:{...Object.keys(S).length>0?{labels:S}:{},...r.glance?{glance:[...r.glance]}:{},...r.page?{page:r.page}:{}}}:{},...Object.keys(T).length>0?{defaults:T}:{}})}),E=De(R,e.computed);function j(f){return E.tryDefinition(f.kind)?.label?.(f)??f.id}let P=[];for(let[f,r]of Object.entries(e.acts??{})){let k=n.acts[f],{title:w,effects:x,guard:D,refusal:S,destructive:T,idempotent:K,creates:g,connects:o,severs:y,writes:V,writesOther:Q,sets:h}=k,L=new Map(k.args),F={};for(let[u,b]of L)F[u]=Je(b);let q=r.on===void 0?[]:Array.isArray(r.on)?r.on:[r.on],X=new Map(k.exprs);P.push(Pe(f,{input:ae(F),title:w,...r.description?{description:r.description}:{},...r.fromTheOtherEnd?{fromTheOtherEnd:r.fromTheOtherEnd}:{},...L.has(I)?{subject:{kinds:q.length>0?q:"*",arg:I}}:{},...T?{destructive:!0}:{},...K?{idempotent:!0}:{},...g.length>0?{creates:g}:{},...o.length>0?{connects:o}:{},...y.length>0?{severs:y}:{},writes:V,...Object.keys(Q).length>0?{writesOther:Q}:{},...Object.keys(h).length>0?{sets:h}:{},describe:(u,b)=>{let v=typeof u[I]=="string"?b.getNode(u[I]):void 0,$=v?j(v):Object.values(u).find(m=>typeof m=="string");return $?`${w}: ${String($)}`:w},apply(u,b){let v=u.graph,$=typeof b[I]=="string"?b[I]:void 0,m=$?v.getNode($):void 0;if($&&!m&&U($),m&&q.length>0&&!q.includes(m.kind))throw new Z(`"${w}" acts on ${q.join(" or ")}, not on ${ze(m.kind)}`,"invalid");let Y={};for(let[t,s]of Object.entries(b))s!==void 0&&(Y[t]=s);if(D&&m){let t;try{t=W(D,{graph:v,subject:m,kinds:d,bindings:Y,today:i()})}catch(s){throw s instanceof te?new Z(`"${w}" could not be judged: ${s.sentence}`):s}if(t!==!0)throw new Z(S?J(S,{node:m,kinds:d,graph:v,bindings:Y,today:i(),money:O}):`"${w}" is not allowed for ${j(m)} right now`)}let ee=new Map,oe=t=>v.has(t)||[...ee.values()].includes(t),ue=new Set,ie=t=>{let s=$e(t);ue.has(s)||(ue.add(s),u.removeEdge(t))},B=(t,s)=>{if(t&&typeof t=="object"&&!Array.isArray(t)&&"expr"in t)try{return W(X.get(t.expr),{graph:v,subject:s??m??null,kinds:d,bindings:Y,today:i()})}catch(p){throw p instanceof te?new Z(`"${w}" could not work out a value: ${p.sentence}`):p}let a=Ze(t);return a===void 0?typeof t=="string"&&t.startsWith("$$")?t.slice(1):t:a==="subject"?$:a==="now"?new Date().toISOString():a==="today"?i():ee.has(a)?ee.get(a):b[a]};for(let t of x)if("create"in t){let s=e.kinds[t.create],a={kind:t.create};for(let[_,N]of Object.entries(s.fields))N.default!==void 0&&(a[_]=N.default);for(let[_,N]of Object.entries(t.set??{})){let ge=B(N,void 0);ge!==void 0&&(a[_]=ge)}let p=We(s),A=u.freshId(String((p&&a[p])??t.create),t.create);u.addNode({id:A,...a}),t.as&&ee.set(t.as,A)}else if("connect"in t||"sever"in t){let s="connect"in t?t.connect:t.sever,a=String(B(t.from,void 0)??""),p=String(B(t.to,void 0)??"");if(oe(a)||U(a),oe(p)||U(p),"connect"in t){if(l.get(s)?.cardinality==="one")for(let A of v.out(a,s))A.id!==p&&ie({kind:s,from:a,to:A.id});v.out(a,s).some(A=>A.id===p)||u.addEdge({kind:s,from:a,to:p})}else ie({kind:s,from:a,to:p})}else if("set"in t){let s=String(B(t.target??"$subject",void 0)??""),a=v.getNode(s);!a&&!oe(s)&&U(s);let p={};for(let[A,_]of Object.entries(t.set)){let N=B(_,a);N!==void 0&&(p[A]=N)}Object.keys(p).length>0&&u.patchNode(s,p)}else if("remove"in t){let s=String(B(t.remove,void 0)??"");v.has(s)||U(s),u.removeNode(s)}else if("replace"in t&&m){let s=b.to;for(let a of t.replace){let p=l.get(a)?.from.includes(m.kind)??!0;for(let A of p?v.out(m.id,a):v.in(m.id,a))a===t.keep&&A.id===s||ie(p?{kind:a,from:m.id,to:A.id}:{kind:a,from:A.id,to:m.id})}}}}))}let G=[];for(let[f,r]of Object.entries(e.rules??{})){let{title:k,require:w,when:x,says:D}=n.rules[f],S=r.repairs??[],T=(g,o)=>{let y={graph:g,subject:o,kinds:d,today:i()},V;try{if(x&&W(x,y)!==!0)return[];V=W(w,y)===!0}catch(h){throw h instanceof Ie?new Me(h.sentence):h instanceof te?new Error(h.sentence):h}if(V)return[];let Q=S.flatMap(h=>{let L=e.acts?.[h.act],F={};o&&(L?.on||/^(edit|remove)-/.test(h.act))&&(F[I]=o.id);for(let[u,b]of Object.entries(h.args??{}))F[u]=Ze(b)==="subject"?o?.id:b;let X=(L?n.acts[h.act].args:[]).filter(([u,b])=>b.required&&F[u]===void 0).map(([u])=>u);return[{mutation:h.act,label:h.label??L?.title??h.act.replace(/-/g," "),args:F,...X.length>0?{missing:X}:{}}]});return[{invariant:f,...o?{subjectId:o.id}:{},label:k,message:D?J(D,{node:o,kinds:d,graph:g,today:i(),money:O}):o?`${j(o)}: ${k}`:k,nodeIds:o?[o.id]:[],repairs:Q}]},K={label:k,shape:{over:r.over,require:w,when:x,says:D,declared:e.kinds,money:O,kinds:d,today:i},judgment:{require:r.require,...r.when?{when:r.when}:{},...r.says?{says:r.says}:{}},...r.description?{description:r.description}:{},...S.length>0?{repairs:S.map(g=>g.act)}:{}};G.push(r.over==="graph"?ce(f,{scope:"graph",...K,evaluate:({graph:g})=>T(g,null)}):ce(f,{scope:{kind:r.over},...K,evaluate:({graph:g,subject:o})=>T(g,o)}))}let z=e.policy?{grants:e.policy.grants,...e.policy.sees?{sees:e.policy.sees}:{},...e.roles?{roles:e.roles}:{}}:void 0,M={name:e.name,schema:E,mutations:P,invariants:G,...z?{policy:z}:{},...n.brand?{brand:n.brand}:{},...e.modules?{modules:e.modules}:{},...e.lenses?{lenses:e.lenses}:{},...e.pages?{pages:e.pages}:{},...e.settings?{settings:e.settings}:{},...n.viewSpecs?{viewSpecs:n.viewSpecs}:{},...n.home?{home:n.home}:{},version:e.version??1};return Ve(M,e),Ue.set(M,n),{ok:!0,app:M,document:e,findings:n.findings,sights:e.policy?.sees,kinds:d}}export{qe as a,tn as b,Be as c,I as d,Ze as e,We as f,mn as g,Qe as h};
|
|
1
|
+
import{a as Ve}from"./chunk.6KJSFIO7.js";import{b as Ce,c as te,d as Ie,e as W,g as le,h as Ke,o as J}from"./chunk.DSZ3I557.js";import{A as Se,G as Ee,T as ze,Ya as Me,Z as De,_ as $e,a as me,b as he,ba as ce,c as we,ca as Pe,d as H,f as se,h as C,i as ke,ib as Te,j as be,k as ne,l as ve,la as Z,m as Oe,o as Ae,p as Re,q as ae,qa as Ge,sb as Fe,tb as Ne,v as je,x as de,y as xe}from"./chunk.RAE4M3KQ.js";function tn(n,c){let e=n.brand??{},i=e.accent?Ne(e.accent):void 0;i&&!i.ok&&c.push(Ke("brand","brand.accent",`that accent cannot make a readable brand, so the app keeps Graview's colors: ${i.why}`,"pick a color further from orange-red, or a darker one"));let l=typeof e.logo=="string"?{src:e.logo}:e.logo,d=e.name??n.name,O=e.typography?Object.fromEntries(Object.entries(e.typography).filter(([,R])=>typeof R=="string"&&!/url\(|@import|[;{}<>\\]/i.test(R)).map(([R,E])=>[R,Fe(E)])):void 0;return{name:d,schemes:i?.ok?i.schemes:Te,...e.currency?{currency:e.currency}:{},...e.locale?{locale:e.locale}:{},...l?{logo:l.src,logoAlt:l.alt??d}:{},...e.favicon?{favicon:e.favicon}:{},...n.description?{subtitle:n.description}:{},...O?{typography:O}:{},...e.shape?{shape:e.shape}:{},...e.accents?{accents:e.accents}:{},...e.scheme?{scheme:e.scheme}:{}}}function Le(n){let{currency:c,locale:e}=n.brand??{};return{...c?{currency:c}:{},...e?{locale:e}:{}}}var He=[{where:"settings[]",was:"honoured",now:"honored",since:"0.1.16"},{where:"pages",was:"overview",now:"scene",since:"0.1.17"}],pe=n=>typeof n=="object"&&n!==null&&!Array.isArray(n);function qe(n,c=He){if(!pe(n))return{document:n,respelled:[]};let e=[],i=n;for(let l of c)i=fe(i,l.where.split("."),l,"",e);return{document:i,respelled:e}}function fe(n,c,e,i,l){if(c.length===0){if(!pe(n)||!Object.hasOwn(n,e.was))return n;l.push(`${i}${e.was}`);let{[e.was]:G,...z}=n;return Object.hasOwn(n,e.now)?z:{...z,[e.now]:G}}if(!pe(n))return n;let[d,...O]=c,R=d.endsWith("[]"),E=R?d.slice(0,-2):d,j=n[E],P=j;if(!R)P=fe(j,O,e,`${i}${E}.`,l);else if(Array.isArray(j)){let G=j.map((z,M)=>fe(z,O,e,`${i}${E}.${M}.`,l));P=G.some((z,M)=>z!==j[M])?G:j}return P===j?n:{...n,[E]:P}}var Be="graview-compiled@1",I="id",Ze=n=>typeof n=="string"&&/^\$[A-Za-z][A-Za-z0-9]*$/.test(n)?n.slice(1):void 0;function We(n){let c=Object.entries(n.fields);return c.find(([,e])=>e.required&&(e.type==="string"||e.type==="text"))?.[0]??c.find(([,e])=>e.type==="string")?.[0]}function _e(n,c){let e;switch(n.type){case"string":e=C().check(H(500));break;case"text":e=C().check(H(2e4));break;case"number":case"integer":{let i=[...n.type==="integer"?[ve()]:[],...n.min===void 0?[]:[he(n.min)],...n.max===void 0?[]:[me(n.max)],...n.step===void 0?[]:[we(n.step)]];e=i.length>0?ne().check(...i):ne();break}case"boolean":e=Oe();break;case"date":e=C().check(se(/^\d{4}-\d{2}-\d{2}$/,"a date like 2026-10-02"));break;case"datetime":e=C().check(xe(i=>!Number.isNaN(Date.parse(i)),"a date and time like 2026-10-02T14:30:00Z"));break;case"enum":e=je(n.options);break;case"list":e=Re(n.of==="number"?ne():n.of==="date"?C().check(se(/^\d{4}-\d{2}-\d{2}$/)):C().check(H(500))).check(H(200));break;case"url":e=be();break;case"email":e=ke();break}return n.description&&(e=e.check(Se(n.description))),c?de(e):e}var U=n=>{throw new Z(`there is no record "${n}"`,"invalid")},Je=n=>"field"in n?_e(n.field,n.optional):"ref"in n?Ge(n.ref):de(Ae()),Ue=new WeakMap;var re=n=>typeof n=="object"&&n!==null&&!Array.isArray(n),ye=(n,c)=>re(c)&&Object.keys(n??{}).length===Object.keys(c).length&&Object.keys(n??{}).every(e=>Object.hasOwn(c,e));function mn(n,c={}){let e=re(n)?n.format:void 0;if(e!==Be)return{ok:!1,findings:[le("compiled-format","format",e===void 0?"this is not a compiled Graview app":`this compiled app is ${JSON.stringify(e)}, and this build reads ${Be}`,"compile the document instead")]};let i=n,l=qe(i.document).document,d=l===i.document?i:{...i,document:l},O=re(l)&&typeof l.name=="string"&&re(l.kinds)&&ye(l.kinds,d.kinds)&&ye(l.acts,d.acts)&&ye(l.rules,d.rules)&&Array.isArray(d.edges)&&Array.isArray(d.findings),R={ok:!1,findings:[le("compiled-shape","","this compiled app's parts do not match its document","compile the document instead")]};if(!O)return R;try{return Qe(d,c)}catch{return R}}function Qe(n,c={}){let{document:e}=n,i=c.today??(()=>new Date().toISOString().slice(0,10)),l=new Map(n.edges.map(([f,r])=>[f,r])),d=new Map;for(let[f,r]of Object.entries(e.kinds)){let k=n.kinds[f]?.computed;d.set(f,{fields:new Set(Object.keys(r.fields)),edges:new Map(Object.entries(r.edges??{}).map(([w,x])=>[w,x.cardinality??"many"])),...k?{computed:new Map(k)}:{}})}n.facts&&d.set(Ce,{computed:new Map(n.facts)});let O=Le(e),R=Object.entries(e.kinds).map(([f,r])=>{let k={};for(let[o,y]of Object.entries(r.fields))k[o]=_e(y,!y.required);let{label:w,describe:x}=n.kinds[f]??{},D=Object.entries(r.computed??{}).map(([o,y])=>[o,typeof y=="string"?{expr:y}:y]),S=Object.fromEntries([...Object.entries(r.fields).filter(([,o])=>o.label).map(([o,y])=>[o,y.label]),...D.filter(([,o])=>o.label).map(([o,y])=>[o,y.label])]),T=Object.fromEntries(Object.entries(r.fields).filter(([,o])=>o.default!==void 0).map(([o,y])=>[o,y.default])),K=Object.fromEntries(Object.entries(r.edges??{}).map(([o,{renamedFrom:y,...V}])=>[o,V])),g=o=>r[o]?{[o]:r[o]}:{};return Ee(f,{fields:ae(k),edges:K,...g("plural"),...g("noun"),...g("description"),...w?{label:o=>J(w,{node:o,kinds:d,today:i(),money:O})||o.id}:{},...x?{describe:o=>J(x,{node:o,kinds:d,today:i(),money:O})}:{},...g("lifecycle"),...g("figure"),...g("fieldRoles"),...r.computed&&Object.keys(r.computed).length>0?{computed:r.computed}:{},...Object.keys(S).length>0||r.glance||r.page?{display:{...Object.keys(S).length>0?{labels:S}:{},...r.glance?{glance:[...r.glance]}:{},...r.page?{page:r.page}:{}}}:{},...Object.keys(T).length>0?{defaults:T}:{}})}),E=De(R,e.computed);function j(f){return E.tryDefinition(f.kind)?.label?.(f)??f.id}let P=[];for(let[f,r]of Object.entries(e.acts??{})){let k=n.acts[f],{title:w,effects:x,guard:D,refusal:S,destructive:T,idempotent:K,creates:g,connects:o,severs:y,writes:V,writesOther:Q,sets:h}=k,L=new Map(k.args),F={};for(let[u,b]of L)F[u]=Je(b);let q=r.on===void 0?[]:Array.isArray(r.on)?r.on:[r.on],X=new Map(k.exprs);P.push(Me(f,{input:ae(F),title:w,...r.description?{description:r.description}:{},...r.fromTheOtherEnd?{fromTheOtherEnd:r.fromTheOtherEnd}:{},...L.has(I)?{subject:{kinds:q.length>0?q:"*",arg:I}}:{},...T?{destructive:!0}:{},...K?{idempotent:!0}:{},...g.length>0?{creates:g}:{},...o.length>0?{connects:o}:{},...y.length>0?{severs:y}:{},writes:V,...Object.keys(Q).length>0?{writesOther:Q}:{},...Object.keys(h).length>0?{sets:h}:{},describe:(u,b)=>{let v=typeof u[I]=="string"?b.getNode(u[I]):void 0,$=v?j(v):Object.values(u).find(m=>typeof m=="string");return $?`${w}: ${String($)}`:w},apply(u,b){let v=u.graph,$=typeof b[I]=="string"?b[I]:void 0,m=$?v.getNode($):void 0;if($&&!m&&U($),m&&q.length>0&&!q.includes(m.kind))throw new Z(`"${w}" acts on ${q.join(" or ")}, not on ${ze(m.kind)}`,"invalid");let Y={};for(let[t,s]of Object.entries(b))s!==void 0&&(Y[t]=s);if(D&&m){let t;try{t=W(D,{graph:v,subject:m,kinds:d,bindings:Y,today:i()})}catch(s){throw s instanceof te?new Z(`"${w}" could not be judged: ${s.sentence}`):s}if(t!==!0)throw new Z(S?J(S,{node:m,kinds:d,graph:v,bindings:Y,today:i(),money:O}):`"${w}" is not allowed for ${j(m)} right now`)}let ee=new Map,oe=t=>v.has(t)||[...ee.values()].includes(t),ue=new Set,ie=t=>{let s=$e(t);ue.has(s)||(ue.add(s),u.removeEdge(t))},B=(t,s)=>{if(t&&typeof t=="object"&&!Array.isArray(t)&&"expr"in t)try{return W(X.get(t.expr),{graph:v,subject:s??m??null,kinds:d,bindings:Y,today:i()})}catch(p){throw p instanceof te?new Z(`"${w}" could not work out a value: ${p.sentence}`):p}let a=Ze(t);return a===void 0?typeof t=="string"&&t.startsWith("$$")?t.slice(1):t:a==="subject"?$:a==="now"?new Date().toISOString():a==="today"?i():ee.has(a)?ee.get(a):b[a]};for(let t of x)if("create"in t){let s=e.kinds[t.create],a={kind:t.create};for(let[_,N]of Object.entries(s.fields))N.default!==void 0&&(a[_]=N.default);for(let[_,N]of Object.entries(t.set??{})){let ge=B(N,void 0);ge!==void 0&&(a[_]=ge)}let p=We(s),A=u.freshId(String((p&&a[p])??t.create),t.create);u.addNode({id:A,...a}),t.as&&ee.set(t.as,A)}else if("connect"in t||"sever"in t){let s="connect"in t?t.connect:t.sever,a=String(B(t.from,void 0)??""),p=String(B(t.to,void 0)??"");if(oe(a)||U(a),oe(p)||U(p),"connect"in t){if(l.get(s)?.cardinality==="one")for(let A of v.out(a,s))A.id!==p&&ie({kind:s,from:a,to:A.id});v.out(a,s).some(A=>A.id===p)||u.addEdge({kind:s,from:a,to:p})}else ie({kind:s,from:a,to:p})}else if("set"in t){let s=String(B(t.target??"$subject",void 0)??""),a=v.getNode(s);!a&&!oe(s)&&U(s);let p={};for(let[A,_]of Object.entries(t.set)){let N=B(_,a);N!==void 0&&(p[A]=N)}Object.keys(p).length>0&&u.patchNode(s,p)}else if("remove"in t){let s=String(B(t.remove,void 0)??"");v.has(s)||U(s),u.removeNode(s)}else if("replace"in t&&m){let s=b.to;for(let a of t.replace){let p=l.get(a)?.from.includes(m.kind)??!0;for(let A of p?v.out(m.id,a):v.in(m.id,a))a===t.keep&&A.id===s||ie(p?{kind:a,from:m.id,to:A.id}:{kind:a,from:A.id,to:m.id})}}}}))}let G=[];for(let[f,r]of Object.entries(e.rules??{})){let{title:k,require:w,when:x,says:D}=n.rules[f],S=r.repairs??[],T=(g,o)=>{let y={graph:g,subject:o,kinds:d,today:i()},V;try{if(x&&W(x,y)!==!0)return[];V=W(w,y)===!0}catch(h){throw h instanceof Ie?new Pe(h.sentence):h instanceof te?new Error(h.sentence):h}if(V)return[];let Q=S.flatMap(h=>{let L=e.acts?.[h.act],F={};o&&(L?.on||/^(edit|remove)-/.test(h.act))&&(F[I]=o.id);for(let[u,b]of Object.entries(h.args??{}))F[u]=Ze(b)==="subject"?o?.id:b;let X=(L?n.acts[h.act].args:[]).filter(([u,b])=>b.required&&F[u]===void 0).map(([u])=>u);return[{mutation:h.act,label:h.label??L?.title??h.act.replace(/-/g," "),args:F,...X.length>0?{missing:X}:{}}]});return[{invariant:f,...o?{subjectId:o.id}:{},label:k,message:D?J(D,{node:o,kinds:d,graph:g,today:i(),money:O}):o?`${j(o)}: ${k}`:k,nodeIds:o?[o.id]:[],repairs:Q}]},K={label:k,shape:{over:r.over,require:w,when:x,says:D,declared:e.kinds,money:O,kinds:d,today:i},judgment:{require:r.require,...r.when?{when:r.when}:{},...r.says?{says:r.says}:{}},...r.description?{description:r.description}:{},...S.length>0?{repairs:S.map(g=>g.act)}:{}};G.push(r.over==="graph"?ce(f,{scope:"graph",...K,evaluate:({graph:g})=>T(g,null)}):ce(f,{scope:{kind:r.over},...K,evaluate:({graph:g,subject:o})=>T(g,o)}))}let z=e.policy?{grants:e.policy.grants,...e.policy.sees?{sees:e.policy.sees}:{},...e.roles?{roles:e.roles}:{}}:void 0,M={name:e.name,schema:E,mutations:P,invariants:G,...z?{policy:z}:{},...n.brand?{brand:n.brand}:{},...e.modules?{modules:e.modules}:{},...e.lenses?{lenses:e.lenses}:{},...e.pages?{pages:e.pages}:{},...e.settings?{settings:e.settings}:{},...n.viewSpecs?{viewSpecs:n.viewSpecs}:{},...n.home?{home:n.home}:{},version:e.version??1};return Ve(M,e),Ue.set(M,n),{ok:!0,app:M,document:e,findings:n.findings,sights:e.policy?.sees,kinds:d}}export{qe as a,tn as b,Be as c,I as d,Ze as e,We as f,mn as g,Qe as h};
|